/* eslint-disable */ // @ts-nocheck // Copied from https://github.com/medialize/ally.js // License: MIT // Copyright (c) 2015 Rodney Rehm // // Entrypoint: ally.js/maintain/tab-focus "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _interop_require_default = require("@swc/helpers/_/_interop_require_default"); const _platform = /*#__PURE__*/ _interop_require_default._(require("next/dist/compiled/platform")); const _cssescape = /*#__PURE__*/ _interop_require_default._(require("next/dist/compiled/css.escape")); // input may be undefined, selector-tring, Node, NodeList, HTMLCollection, array of Nodes // yes, to some extent this is a bad replica of jQuery's constructor function function nodeArray(input) { if (!input) { return []; } if (Array.isArray(input)) { return input; } // instanceof Node - does not work with iframes if (input.nodeType !== undefined) { return [ input ]; } if (typeof input === "string") { input = document.querySelectorAll(input); } if (input.length !== undefined) { return [].slice.call(input, 0); } throw new TypeError("unexpected input " + String(input)); } function contextToElement(_ref) { var context = _ref.context, _ref$label = _ref.label, label = _ref$label === undefined ? "context-to-element" : _ref$label, resolveDocument = _ref.resolveDocument, defaultToDocument = _ref.defaultToDocument; var element = nodeArray(context)[0]; if (resolveDocument && element && element.nodeType === Node.DOCUMENT_NODE) { element = element.documentElement; } if (!element && defaultToDocument) { return document.documentElement; } if (!element) { throw new TypeError(label + " requires valid options.context"); } if (element.nodeType !== Node.ELEMENT_NODE && element.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) { throw new TypeError(label + " requires options.context to be an Element"); } return element; } function getShadowHost() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, context = _ref.context; var element = contextToElement({ label: "get/shadow-host", context: context }); // walk up to the root var container = null; while(element){ container = element; element = element.parentNode; } // https://developer.mozilla.org/docs/Web/API/Node.nodeType // NOTE: Firefox 34 does not expose ShadowRoot.host (but 37 does) if (container.nodeType === container.DOCUMENT_FRAGMENT_NODE && container.host) { // the root is attached to a fragment node that has a host return container.host; } return null; } function getDocument(node) { if (!node) { return document; } if (node.nodeType === Node.DOCUMENT_NODE) { return node; } return node.ownerDocument || document; } function isActiveElement(context) { var element = contextToElement({ label: "is/active-element", resolveDocument: true, context: context }); var _document = getDocument(element); if (_document.activeElement === element) { return true; } var shadowHost = getShadowHost({ context: element }); if (shadowHost && shadowHost.shadowRoot.activeElement === element) { return true; } return false; } // [elem, elem.parent, elem.parent.parent, …, html] // will not contain the shadowRoot (DOCUMENT_FRAGMENT_NODE) and shadowHost function getParents() { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, context = _ref.context; var list = []; var element = contextToElement({ label: "get/parents", context: context }); while(element){ list.push(element); // IE does know support parentElement on SVGElement element = element.parentNode; if (element && element.nodeType !== Node.ELEMENT_NODE) { element = null; } } return list; } // Element.prototype.matches may be available at a different name // https://developer.mozilla.org/en/docs/Web/API/Element/matches var names = [ "matches", "webkitMatchesSelector", "mozMatchesSelector", "msMatchesSelector" ]; var name = null; function findMethodName(element) { names.some(function(_name) { if (!element[_name]) { return false; } name = _name; return true; }); } function elementMatches(element, selector) { if (!name) { findMethodName(element); } return element[name](selector); } // deep clone of original platform var platform = JSON.parse(JSON.stringify(_platform.default)); // operating system var os = platform.os.family || ""; var ANDROID = os === "Android"; var WINDOWS = os.slice(0, 7) === "Windows"; var OSX = os === "OS X"; var IOS = os === "iOS"; // layout var BLINK = platform.layout === "Blink"; var GECKO = platform.layout === "Gecko"; var TRIDENT = platform.layout === "Trident"; var EDGE = platform.layout === "EdgeHTML"; var WEBKIT = platform.layout === "WebKit"; // browser version (not layout engine version!) var version = parseFloat(platform.version); var majorVersion = Math.floor(version); platform.majorVersion = majorVersion; platform.is = { // operating system ANDROID: ANDROID, WINDOWS: WINDOWS, OSX: OSX, IOS: IOS, // layout BLINK: BLINK, GECKO: GECKO, TRIDENT: TRIDENT, EDGE: EDGE, WEBKIT: WEBKIT, // INTERNET EXPLORERS IE9: TRIDENT && majorVersion === 9, IE10: TRIDENT && majorVersion === 10, IE11: TRIDENT && majorVersion === 11 }; function before() { var data = { // remember what had focus to restore after test activeElement: document.activeElement, // remember scroll positions to restore after test windowScrollTop: window.scrollTop, windowScrollLeft: window.scrollLeft, bodyScrollTop: document.body.scrollTop, bodyScrollLeft: document.body.scrollLeft }; // wrap tests in an element hidden from screen readers to prevent them // from announcing focus, which can be quite irritating to the user var iframe = document.createElement("iframe"); iframe.setAttribute("style", "position:absolute; position:fixed; top:0; left:-2px; width:1px; height:1px; overflow:hidden;"); iframe.setAttribute("aria-live", "off"); iframe.setAttribute("aria-busy", "true"); iframe.setAttribute("aria-hidden", "true"); document.body.appendChild(iframe); var _window = iframe.contentWindow; var _document = _window.document; _document.open(); _document.close(); var wrapper = _document.createElement("div"); _document.body.appendChild(wrapper); data.iframe = iframe; data.wrapper = wrapper; data.window = _window; data.document = _document; return data; } // options.element: // {string} element name // {function} callback(wrapper, document) to generate an element // options.mutate: (optional) // {function} callback(element, wrapper, document) to manipulate element prior to focus-test. // Can return DOMElement to define focus target (default: element) // options.validate: (optional) // {function} callback(element, focusTarget, document) to manipulate test-result function test(data, options) { // make sure we operate on a clean slate data.wrapper.innerHTML = ""; // create dummy element to test focusability of var element = typeof options.element === "string" ? data.document.createElement(options.element) : options.element(data.wrapper, data.document); // allow callback to further specify dummy element // and optionally define element to focus var focus = options.mutate && options.mutate(element, data.wrapper, data.document); if (!focus && focus !== false) { focus = element; } // element needs to be part of the DOM to be focusable !element.parentNode && data.wrapper.appendChild(element); // test if the element with invalid tabindex can be focused focus && focus.focus && focus.focus(); // validate test's result return options.validate ? options.validate(element, focus, data.document) : data.document.activeElement === focus; } function after(data) { // restore focus to what it was before test and cleanup if (data.activeElement === document.body) { document.activeElement && document.activeElement.blur && document.activeElement.blur(); if (platform.is.IE10) { // IE10 does not redirect focus to
when the activeElement is removed document.body.focus(); } } else { data.activeElement && data.activeElement.focus && data.activeElement.focus(); } document.body.removeChild(data.iframe); // restore scroll position window.scrollTop = data.windowScrollTop; window.scrollLeft = data.windowScrollLeft; document.body.scrollTop = data.bodyScrollTop; document.body.scrollLeft = data.bodyScrollLeft; } function detectFocus(tests) { var data = before(); var results = {}; Object.keys(tests).map(function(key) { results[key] = test(data, tests[key]); }); after(data); return results; } // this file is overwritten by `npm run build:pre` var version$1 = "1.4.1"; /* Facility to cache test results in localStorage. USAGE: cache.get('key'); cache.set('key', 'value'); */ function readLocalStorage(key) { // allow reading from storage to retrieve previous support results // even while the document does not have focus var data = void 0; try { data = window.localStorage && window.localStorage.getItem(key); data = data ? JSON.parse(data) : {}; } catch (e) { data = {}; } return data; } function writeLocalStorage(key, value) { if (!document.hasFocus()) { // if the document does not have focus when tests are executed, focus() may // not be handled properly and events may not be dispatched immediately. // This can happen when a document is reloaded while Developer Tools have focus. try { window.localStorage && window.localStorage.removeItem(key); } catch (e) { // ignore } return; } try { window.localStorage && window.localStorage.setItem(key, JSON.stringify(value)); } catch (e) { // ignore } } var userAgent = typeof window !== "undefined" && window.navigator.userAgent || ""; var cacheKey = "ally-supports-cache"; var cache = readLocalStorage(cacheKey); // update the cache if ally or the user agent changed (newer version, etc) if (cache.userAgent !== userAgent || cache.version !== version$1) { cache = {}; } cache.userAgent = userAgent; cache.version = version$1; var cache$1 = { get: function get() { return cache; }, set: function set(values) { Object.keys(values).forEach(function(key) { cache[key] = values[key]; }); cache.time = new Date().toISOString(); writeLocalStorage(cacheKey, cache); } }; function cssShadowPiercingDeepCombinator() { var combinator = void 0; // see https://dev.w3.org/csswg/css-scoping-1/#deep-combinator // https://bugzilla.mozilla.org/show_bug.cgi?id=1117572 // https://code.google.com/p/chromium/issues/detail?id=446051 try { document.querySelector("html >>> :first-child"); combinator = ">>>"; } catch (noArrowArrowArrow) { try { // old syntax supported at least up to Chrome 41 // https://code.google.com/p/chromium/issues/detail?id=446051 document.querySelector("html /deep/ :first-child"); combinator = "/deep/"; } catch (noDeep) { combinator = ""; } } return combinator; } var gif = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; // https://developer.mozilla.org/docs/Web/HTML/Element/img#attr-usemap var focusAreaImgTabindex = { element: "div", mutate: function mutate(element) { element.innerHTML = '' + 'content
"; } }; // elements with display:flex are focusable in IE10-11 var focusFlexboxContainer = { element: "span", mutate: function mutate(element) { element.setAttribute("style", "display: -webkit-flex; display: -ms-flexbox; display: flex;"); element.innerHTML = 'hello'; } }; // form[tabindex=0][disabled] should be focusable as the // specification doesn't know the disabled attribute on the form element // @specification https://www.w3.org/TR/html5/forms.html#the-form-element var focusFormDisabled = { element: "form", mutate: function mutate(element) { element.setAttribute("tabindex", 0); element.setAttribute("disabled", "disabled"); } }; // NOTE: https://github.com/medialize/ally.js/issues/35 // fixes https://github.com/medialize/ally.js/issues/20 // https://developer.mozilla.org/docs/Web/HTML/Element/img#attr-ismap var focusImgIsmap = { element: "a", mutate: function mutate(element) { element.href = "#void"; element.innerHTML = '