You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
9.3 KiB

1 month ago
  1. {"ast":null,"code":"const FOCUSABLE_ELEMENT_SELECTORS = `a[href],button:not([disabled]),button:not([hidden]),:not([tabindex=\"-1\"]),input:not([disabled]),input:not([type=\"hidden\"]),select:not([disabled]),textarea:not([disabled])`;\nconst isVisible = element => {\n if (process.env.NODE_ENV === \"test\") return true;\n const computed = getComputedStyle(element);\n return computed.position === \"fixed\" ? false : element.offsetParent !== null;\n};\nconst obtainAllFocusableElements = element => {\n return Array.from(element.querySelectorAll(FOCUSABLE_ELEMENT_SELECTORS)).filter(item => isFocusable(item) && isVisible(item));\n};\nconst isFocusable = element => {\n if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute(\"tabIndex\") !== null) {\n return true;\n }\n if (element.tabIndex < 0 || element.hasAttribute(\"disabled\") || element.getAttribute(\"aria-disabled\") === \"true\") {\n return false;\n }\n switch (element.nodeName) {\n case \"A\":\n {\n return !!element.href && element.rel !== \"ignore\";\n }\n case \"INPUT\":\n {\n return !(element.type === \"hidden\" || element.type === \"file\");\n }\n case \"BUTTON\":\n case \"SELECT\":\n case \"TEXTAREA\":\n {\n return true;\n }\n default:\n {\n return false;\n }\n }\n};\nconst attemptFocus = element => {\n var _a;\n if (!isFocusable(element)) {\n return false;\n }\n (_a = element.focus) == null ? void 0 : _a.call(element);\n return document.activeElement === element;\n};\nconst triggerEvent = function (elm, name, ...opts) {\n let eventName;\n if (name.includes(\"mouse\") || name.includes(\"click\")) {\n eventName = \"MouseEvents\";\n } else if (name.includes(\"key\")) {\n eventName = \"KeyboardEvent\";\n } else {\n eventName = \"HTMLEvents\";\n }\n const evt = document.createEvent(eventName);\n evt.initEvent(name, ...opts);\n elm.dispatchEvent(evt);\n return elm;\n};\nconst isLeaf = el => !el.getAttribute(\"aria-owns\");\nconst getSibling = (el, distance, elClass) => {\n const {\n parentNode\n } = el;\n if (!parentNode) return null;\n const siblings = parentNode.querySelectorAll(elClass);\n const index = Array.prototype.indexOf.call(siblings, el);\n return siblings[index + distance] || null;\n};\nconst focusNode = el => {\n if (!el) return;\n el.focus();\n !isLeaf(el) && el.click();\n};\nexport { attemptFocus, focusNode, getSibling, isFocusable, isLeaf, isVisible, obtainAllFocusableElements, triggerEvent };","map":{"version":3,"names":["FOCUSABLE_ELEMENT_SELECTORS","isVisible","element","process","env","NODE_ENV","computed","getComputedStyle","position","offsetParent","obtainAllFocusableElements","Array","from","querySelectorAll","filter","item","isFocusable","tabIndex","getAttribute","hasAttribute","nodeName","href","rel","type","attemptFocus","_a","focus","call","document","activeElement","triggerEvent","elm","name","opts","eventName","includes","evt","createEvent","initEvent","dispatchEvent","isLeaf","el","getSibling","distance","elClass","parentNode","siblings","index","prototype","indexOf","focusNode","click"],"sources":["../../../../../packages/utils/dom/aria.ts"],"sourcesContent":["const FOCUSABLE_ELEMENT_SELECTORS = `a[href],button:not([disabled]),button:not([hidden]),:not([tabindex=\"-1\"]),input:not([disabled]),input:not([type=\"hidden\"]),select:not([disabled]),textarea:not([disabled])`\n\n/**\n * Determine if the testing element is visible on screen no matter if its on the viewport or not\n */\nexport const isVisible = (element: HTMLElement) => {\n if (process.env.NODE_ENV === 'test') return true\n const computed = getComputedStyle(element)\n // element.offsetParent won't work on fix positioned\n // WARNING: potential issue here, going to need some expert advices on this issue\n return computed.position === 'fixed' ? false : element.offsetParent !== null\n}\n\nexport const obtainAllFocusableElements = (\n element: HTMLElement\n): HTMLElement[] => {\n return Array.from(\n element.querySelec