{"version":3,"sources":["Shared/Static/js/lib/polyfill-focus-visible.js"],"names":["applyFocusVisiblePolyfill","scope","hadKeyboardEvent","hadFocusVisibleRecently","hadFocusVisibleRecentlyTimeout","inputTypesWhitelist","text","search","url","tel","email","password","number","date","month","week","time","datetime","datetime-local","isValidFocusTarget","el","document","nodeName","classList","addFocusVisibleClass","contains","add","setAttribute","onPointerDown","e","addInitialPointerMoveListeners","addEventListener","onInitialPointerMove","target","toLowerCase","removeEventListener","removeInitialPointerMoveListeners","metaKey","altKey","ctrlKey","activeElement","visibilityState","type","tagName","readOnly","isContentEditable","focusTriggersKeyboardModality","hasAttribute","window","clearTimeout","setTimeout","remove","removeAttribute","removeFocusVisibleClass","nodeType","Node","DOCUMENT_FRAGMENT_NODE","host","DOCUMENT_NODE","documentElement","event","CustomEvent","error","createEvent","initCustomEvent","dispatchEvent"],"mappings":"AAQA,SAASA,0BAA0BC,GAClC,IAAIC,GAAmB,EACnBC,GAA0B,EAC1BC,EAAiC,KAEjCC,GACHC,MAAM,EACNC,QAAQ,EACRC,KAAK,EACLC,KAAK,EACLC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,UAAU,EACVC,kBAAkB,GAQnB,SAASC,EAAmBC,GAC3B,SACCA,GACAA,IAAOC,UACS,SAAhBD,EAAGE,UACa,SAAhBF,EAAGE,UACH,cAAeF,GACf,aAAcA,EAAGG,WAsCnB,SAASC,EAAqBJ,GACzBA,EAAGG,UAAUE,SAAS,mBAG1BL,EAAGG,UAAUG,IAAI,iBACjBN,EAAGO,aAAa,2BAA4B,KA4C7C,SAASC,EAAcC,GACtB3B,GAAmB,EAuEpB,SAAS4B,IACRT,SAASU,iBAAiB,YAAaC,GACvCX,SAASU,iBAAiB,YAAaC,GACvCX,SAASU,iBAAiB,UAAWC,GACrCX,SAASU,iBAAiB,cAAeC,GACzCX,SAASU,iBAAiB,cAAeC,GACzCX,SAASU,iBAAiB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KzBJ,EAAEI,OAAOV,UAAUE,SAAS,kBAC5BI,EAAEI,OAAOc,aAAa,+BAMtB5C,GAA0B,EAC1B6C,OAAOC,aAAa7C,GACpBA,EAAiC4C,OAAOE,WAAW,WAClD/C,GAA0B,GACxB,KA/EL,SAAiCiB,GAC3BA,EAAG2B,aAAa,8BAGrB3B,EAAGG,UAAU4B,OAAO,iBACpB/B,EAAGgC,gBAAgB,6BA2ElBC,CAAwBxB,EAAEI,WAsFW,GAOnChC,EAAMqD,WAAaC,KAAKC,wBAA0BvD,EAAMwD,KAI3DxD,EAAMwD,KAAK9B,aAAa,wBAAyB,IACvC1B,EAAMqD,WAAaC,KAAKG,gBAClCrC,SAASsC,gBAAgBpC,UAAUG,IAAI,oBACvCL,SAASsC,gBAAgBhC,aAAa,wBAAyB,KAOjE,GAAsB,oBAAXqB,QAA8C,oBAAb3B,SAA0B,CAQrE,IAAIuC,MAJJZ,OAAOhD,0BAA4BA,0BAMnC,IACC4D,MAAQ,IAAIC,YAAY,gCACvB,MAAOC,IAERF,MAAQvC,SAAS0C,YAAY,gBACvBC,gBAAgB,gCAAgC,GAAO,MAG9DhB,OAAOiB,cAAcL,OAGE,oBAAbvC,UAGVrB,0BAA0BqB","file":"polyfill-focus-visible.js","sourcesContent":["/**\r\n * Applies the :focus-visible polyfill at the given scope.\r\n * A scope in this case is either the top-level Document or a Shadow Root.\r\n * v5.1.0\r\n * @param {(Document|ShadowRoot)} scope\r\n * @see https://github.com/WICG/focus-visible\r\n */\r\n\r\nfunction applyFocusVisiblePolyfill(scope) {\r\n\tvar hadKeyboardEvent = true;\r\n\tvar hadFocusVisibleRecently = false;\r\n\tvar hadFocusVisibleRecentlyTimeout = null;\r\n\r\n\tvar inputTypesWhitelist = {\r\n\t\ttext: true,\r\n\t\tsearch: true,\r\n\t\turl: true,\r\n\t\ttel: true,\r\n\t\temail: true,\r\n\t\tpassword: true,\r\n\t\tnumber: true,\r\n\t\tdate: true,\r\n\t\tmonth: true,\r\n\t\tweek: true,\r\n\t\ttime: true,\r\n\t\tdatetime: true,\r\n\t\t'datetime-local': true\r\n\t};\r\n\r\n\t/**\r\n\t * Helper function for legacy browsers and iframes which sometimes focus\r\n\t * elements like document, body, and non-interactive SVG.\r\n\t * @param {Element} el\r\n\t */\r\n\tfunction isValidFocusTarget(el) {\r\n\t\tif (\r\n\t\t\tel &&\r\n\t\t\tel !== document &&\r\n\t\t\tel.nodeName !== 'HTML' &&\r\n\t\t\tel.nodeName !== 'BODY' &&\r\n\t\t\t'classList' in el &&\r\n\t\t\t'contains' in el.classList\r\n\t\t) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Computes whether the given element should automatically trigger the\r\n\t * `focus-visible` class being added, i.e. whether it should always match\r\n\t * `:focus-visible` when focused.\r\n\t * @param {Element} el\r\n\t * @return {boolean}\r\n\t */\r\n\tfunction focusTriggersKeyboardModality(el) {\r\n\t\tvar type = el.type;\r\n\t\tvar tagName = el.tagName;\r\n\r\n\t\tif (tagName === 'INPUT' && inputTypesWhitelist[type] && !el.readOnly) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tif (tagName === 'TEXTAREA' && !el.readOnly) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\tif (el.isContentEditable) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\t/**\r\n\t * Add the `focus-visible` class to the given element if it was not added by\r\n\t * the author.\r\n\t * @param {Element} el\r\n\t */\r\n\tfunction addFocusVisibleClass(el) {\r\n\t\tif (el.classList.contains('focus-visible')) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tel.classList.add('focus-visible');\r\n\t\tel.setAttribute('data-focus-visible-added', '');\r\n\t}\r\n\r\n\t/**\r\n\t * Remove the `focus-visible` class from the given element if it was not\r\n\t * originally added by the author.\r\n\t * @param {Element} el\r\n\t */\r\n\tfunction removeFocusVisibleClass(el) {\r\n\t\tif (!el.hasAttribute('data-focus-visible-added')) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tel.classList.remove('focus-visible');\r\n\t\tel.removeAttribute('data-focus-visible-added');\r\n\t}\r\n\r\n\t/**\r\n\t * If the most recent user interaction was via the keyboard;\r\n\t * and the key press did not include a meta, alt/option, or control key;\r\n\t * then the modality is keyboard. Otherwise, the modality is not keyboard.\r\n\t * Apply `focus-visible` to any current active element and keep track\r\n\t * of our keyboard modality state with `hadKeyboardEvent`.\r\n\t * @param {KeyboardEvent} e\r\n\t */\r\n\tfunction onKeyDown(e) {\r\n\t\tif (e.metaKey || e.altKey || e.ctrlKey) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (isValidFocusTarget(scope.activeElement)) {\r\n\t\t\taddFocusVisibleClass(scope.activeElement);\r\n\t\t}\r\n\r\n\t\thadKeyboardEvent = true;\r\n\t}\r\n\r\n\t/**\r\n\t * If at any point a user clicks with a pointing device, ensure that we change\r\n\t * the modality away from keyboard.\r\n\t * This avoids the situation where a user presses a key on an already focused\r\n\t * element, and then clicks on a different element, focusing it with a\r\n\t * pointing device, while we still think we're in keyboard modality.\r\n\t * @param {Event} e\r\n\t */\r\n\tfunction onPointerDown(e) {\r\n\t\thadKeyboardEvent = false;\r\n\t}\r\n\r\n\t/**\r\n\t * On `focus`, add the `focus-visible` class to the target if:\r\n\t * - the target received focus as a result of keyboard navigation, or\r\n\t * - the event target is an element that will likely require interaction\r\n\t * via the keyboard (e.g. a text box)\r\n\t * @param {Event} e\r\n\t */\r\n\tfunction onFocus(e) {\r\n\t\t// Prevent IE from focusing the document or HTML element.\r\n\t\tif (!isValidFocusTarget(e.target)) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {\r\n\t\t\taddFocusVisibleClass(e.target);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * On `blur`, remove the `focus-visible` class from the target.\r\n\t * @param {Event} e\r\n\t */\r\n\tfunction onBlur(e) {\r\n\t\tif (!isValidFocusTarget(e.target)) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\te.target.classList.contains('focus-visible') ||\r\n\t\t\te.target.hasAttribute('data-focus-visible-added')\r\n\t\t) {\r\n\t\t\t// To detect a tab/window switch, we look for a blur event followed\r\n\t\t\t// rapidly by a visibility change.\r\n\t\t\t// If we don't see a visibility change within 100ms, it's probably a\r\n\t\t\t// regular focus change.\r\n\t\t\thadFocusVisibleRecently = true;\r\n\t\t\twindow.clearTimeout(hadFocusVisibleRecentlyTimeout);\r\n\t\t\thadFocusVisibleRecentlyTimeout = window.setTimeout(function () {\r\n\t\t\t\thadFocusVisibleRecently = false;\r\n\t\t\t}, 100);\r\n\t\t\tremoveFocusVisibleClass(e.target);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * If the user changes tabs, keep track of whether or not the previously\r\n\t * focused element had .focus-visible.\r\n\t * @param {Event} e\r\n\t */\r\n\tfunction onVisibilityChange(e) {\r\n\t\tif (document.visibilityState === 'hidden') {\r\n\t\t\t// If the tab becomes active again, the browser will handle calling focus\r\n\t\t\t// on the element (Safari actually calls it twice).\r\n\t\t\t// If this tab change caused a blur on an element with focus-visible,\r\n\t\t\t// re-apply the class when the user switches back to the tab.\r\n\t\t\tif (hadFocusVisibleRecently) {\r\n\t\t\t\thadKeyboardEvent = true;\r\n\t\t\t}\r\n\t\t\taddInitialPointerMoveListeners();\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Add a group of listeners to detect usage of any pointing devices.\r\n\t * These listeners will be added when the polyfill first loads, and anytime\r\n\t * the window is blurred, so that they are active when the window regains\r\n\t * focus.\r\n\t */\r\n\tfunction addInitialPointerMoveListeners() {\r\n\t\tdocument.addEventListener('mousemove', onInitialPointerMove);\r\n\t\tdocument.addEventListener('mousedown', onInitialPointerMove);\r\n\t\tdocument.addEventListener('mouseup', onInitialPointerMove);\r\n\t\tdocument.addEventListener('pointermove', onInitialPointerMove);\r\n\t\tdocument.addEventListener('pointerdown', onInitialPointerMove);\r\n\t\tdocument.addEventListener('pointerup', onInitialPointerMove);\r\n\t\tdocument.addEventListener('touchmove', onInitialPointerMove);\r\n\t\tdocument.addEventListener('touchstart', onInitialPointerMove);\r\n\t\tdocument.addEventListener('touchend', onInitialPointerMove);\r\n\t}\r\n\r\n\tfunction removeInitialPointerMoveListeners() {\r\n\t\tdocument.removeEventListener('mousemove', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('mousedown', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('mouseup', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('pointermove', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('pointerdown', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('pointerup', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('touchmove', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('touchstart', onInitialPointerMove);\r\n\t\tdocument.removeEventListener('touchend', onInitialPointerMove);\r\n\t}\r\n\r\n\t/**\r\n\t * When the polfyill first loads, assume the user is in keyboard modality.\r\n\t * If any event is received from a pointing device (e.g. mouse, pointer,\r\n\t * touch), turn off keyboard modality.\r\n\t * This accounts for situations where focus enters the page from the URL bar.\r\n\t * @param {Event} e\r\n\t */\r\n\tfunction onInitialPointerMove(e) {\r\n\t\t// Work around a Safari quirk that fires a mousemove on whenever the\r\n\t\t// window blurs, even if you're tabbing out of the page. ¯\\_(ツ)_/¯\r\n\t\tif (e.target.nodeName && e.target.nodeName.toLowerCase() === 'html') {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\thadKeyboardEvent = false;\r\n\t\tremoveInitialPointerMoveListeners();\r\n\t}\r\n\r\n\t// For some kinds of state, we are interested in changes at the global scope\r\n\t// only. For example, global pointer input, global key presses and global\r\n\t// visibility change should affect the state at every scope:\r\n\tdocument.addEventListener('keydown', onKeyDown, true);\r\n\tdocument.addEventListener('mousedown', onPointerDown, true);\r\n\tdocument.addEventListener('pointerdown', onPointerDown, true);\r\n\tdocument.addEventListener('touchstart', onPointerDown, true);\r\n\tdocument.addEventListener('visibilitychange', onVisibilityChange, true);\r\n\r\n\taddInitialPointerMoveListeners();\r\n\r\n\t// For focus and blur, we specifically care about state changes in the local\r\n\t// scope. This is because focus / blur events that originate from within a\r\n\t// shadow root are not re-dispatched from the host element if it was already\r\n\t// the active element in its own scope:\r\n\tscope.addEventListener('focus', onFocus, true);\r\n\tscope.addEventListener('blur', onBlur, true);\r\n\r\n\t// We detect that a node is a ShadowRoot by ensuring that it is a\r\n\t// DocumentFragment and also has a host property. This check covers native\r\n\t// implementation and polyfill implementation transparently. If we only cared\r\n\t// about the native implementation, we could just check if the scope was\r\n\t// an instance of a ShadowRoot.\r\n\tif (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {\r\n\t\t// Since a ShadowRoot is a special kind of DocumentFragment, it does not\r\n\t\t// have a root element to add a class to. So, we add this attribute to the\r\n\t\t// host element instead:\r\n\t\tscope.host.setAttribute('data-js-focus-visible', '');\r\n\t} else if (scope.nodeType === Node.DOCUMENT_NODE) {\r\n\t\tdocument.documentElement.classList.add('js-focus-visible');\r\n\t\tdocument.documentElement.setAttribute('data-js-focus-visible', '');\r\n\t}\r\n}\r\n\r\n// It is important to wrap all references to global window and document in\r\n// these checks to support server-side rendering use cases\r\n// @see https://github.com/WICG/focus-visible/issues/199\r\nif (typeof window !== 'undefined' && typeof document !== 'undefined') {\r\n\t// Make the polyfill helper globally available. This can be used as a signal\r\n\t// to interested libraries that wish to coordinate with the polyfill for e.g.,\r\n\t// applying the polyfill to a shadow root:\r\n\twindow.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;\r\n\r\n\t// Notify interested libraries of the polyfill's presence, in case the\r\n\t// polyfill was loaded lazily:\r\n\tvar event;\r\n\r\n\ttry {\r\n\t\tevent = new CustomEvent('focus-visible-polyfill-ready');\r\n\t} catch (error) {\r\n\t\t// IE11 does not support using CustomEvent as a constructor directly:\r\n\t\tevent = document.createEvent('CustomEvent');\r\n\t\tevent.initCustomEvent('focus-visible-polyfill-ready', false, false, {});\r\n\t}\r\n\r\n\twindow.dispatchEvent(event);\r\n}\r\n\r\nif (typeof document !== 'undefined') {\r\n\t// Apply the polyfill to the global document, so that no JavaScript\r\n\t// coordination is required to use the polyfill in the top-level document:\r\n\tapplyFocusVisiblePolyfill(document);\r\n}\r\n"]}