1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
{"version":3,"file":"index.umd.min.js","sources":["../src/index.js"],"sourcesContent":["const candidateSelectors = [\n 'input',\n 'select',\n 'textarea',\n 'a[href]',\n 'button',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n 'details>summary:first-of-type',\n 'details',\n];\nconst candidateSelector = /* #__PURE__ */ candidateSelectors.join(',');\n\nconst matches =\n typeof Element === 'undefined'\n ? function () {}\n : Element.prototype.matches ||\n Element.prototype.msMatchesSelector ||\n Element.prototype.webkitMatchesSelector;\n\nconst getCandidates = function (el, includeContainer, filter) {\n let candidates = Array.prototype.slice.apply(\n el.querySelectorAll(candidateSelector)\n );\n if (includeContainer && matches.call(el, candidateSelector)) {\n candidates.unshift(el);\n }\n candidates = candidates.filter(filter);\n return candidates;\n};\n\nconst isContentEditable = function (node) {\n return node.contentEditable === 'true';\n};\n\nconst getTabindex = function (node) {\n const tabindexAttr = parseInt(node.getAttribute('tabindex'), 10);\n\n if (!isNaN(tabindexAttr)) {\n return tabindexAttr;\n }\n\n // Browsers do not return `tabIndex` correctly for contentEditable nodes;\n // so if they don't have a tabindex attribute specifically set, assume it's 0.\n if (isContentEditable(node)) {\n return 0;\n }\n\n // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default\n // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,\n // yet they are still part of the regular tab order; in FF, they get a default\n // `tabIndex` of 0; since Chrome still puts those elements in the regular tab\n // order, consider their tab index to be 0.\n if (\n (node.nodeName === 'AUDIO' ||\n node.nodeName === 'VIDEO' ||\n node.nodeName === 'DETAILS') &&\n node.getAttribute('tabindex') === null\n ) {\n return 0;\n }\n\n return node.tabIndex;\n};\n\nconst sortOrderedTabbables = function (a, b) {\n return a.tabIndex === b.tabIndex\n ? a.documentOrder - b.documentOrder\n : a.tabIndex - b.tabIndex;\n};\n\nconst isInput = function (node) {\n return node.tagName === 'INPUT';\n};\n\nconst isHiddenInput = function (node) {\n return isInput(node) && node.type === 'hidden';\n};\n\nconst isDetailsWithSummary = function (node) {\n const r =\n node.tagName === 'DETAILS' &&\n Array.prototype.slice\n .apply(node.children)\n .some((child) => child.tagName === 'SUMMARY');\n return r;\n};\n\nconst getCheckedRadio = function (nodes, form) {\n for (let i = 0; i < nodes.length; i++) {\n if (nodes[i].checked && nodes[i].form === form) {\n return nodes[i];\n }\n }\n};\n\nconst isTabbableRadio = function (node) {\n if (!node.name) {\n return true;\n }\n const radioScope = node.form || node.ownerDocument;\n\n const queryRadios = function (name) {\n return radioScope.querySelectorAll(\n 'input[type=\"radio\"][name=\"' + name + '\"]'\n );\n };\n\n let radioSet;\n if (\n typeof window !== 'undefined' &&\n typeof window.CSS !== 'undefined' &&\n typeof window.CSS.escape === 'function'\n ) {\n radioSet = queryRadios(window.CSS.escape(node.name));\n } else {\n try {\n radioSet = queryRadios(node.name);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(\n 'Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s',\n err.message\n );\n return false;\n }\n }\n\n const checked = getCheckedRadio(radioSet, node.form);\n return !checked || checked === node;\n};\n\nconst isRadio = function (node) {\n return isInput(node) && node.type === 'radio';\n};\n\nconst isNonTabbableRadio = function (node) {\n return isRadio(node) && !isTabbableRadio(node);\n};\n\nconst isHidden = function (node, displayCheck) {\n if (getComputedStyle(node).visibility === 'hidden') {\n return true;\n }\n\n const isDirectSummary = matches.call(node, 'details>summary:first-of-type');\n const nodeUnderDetails = isDirectSummary ? node.parentElement : node;\n if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {\n return true;\n }\n if (!displayCheck || displayCheck === 'full') {\n while (node) {\n if (getComputedStyle(node).display === 'none') {\n return true;\n }\n node = node.parentElement;\n }\n } else if (displayCheck === 'non-zero-area') {\n const { width, height } = node.getBoundingClientRect();\n return width === 0 && height === 0;\n }\n\n return false;\n};\n\nconst isNodeMatchingSelectorFocusable = function (options, node) {\n if (\n node.disabled ||\n isHiddenInput(node) ||\n isHidden(node, options.displayCheck) ||\n /* For a details element with a summary, the summary element gets the focused */\n isDetailsWithSummary(node)\n ) {\n return false;\n }\n return true;\n};\n\nconst isNodeMatchingSelectorTabbable = function (options, node) {\n if (\n !isNodeMatchingSelectorFocusable(options, node) ||\n isNonTabbableRadio(node) ||\n getTabindex(node) < 0\n ) {\n return false;\n }\n return true;\n};\n\nconst tabbable = function (el, options) {\n options = options || {};\n\n const regularTabbables = [];\n const orderedTabbables = [];\n\n const candidates = getCandidates(\n el,\n options.includeContainer,\n isNodeMatchingSelectorTabbable.bind(null, options)\n );\n\n candidates.forEach(function (candidate, i) {\n const candidateTabindex = getTabindex(candidate);\n if (candidateTabindex === 0) {\n regularTabbables.push(candidate);\n } else {\n orderedTabbables.push({\n documentOrder: i,\n tabIndex: candidateTabindex,\n node: candidate,\n });\n }\n });\n\n const tabbableNodes = orderedTabbables\n .sort(sortOrderedTabbables)\n .map((a) => a.node)\n .concat(regularTabbables);\n\n return tabbableNodes;\n};\n\nconst focusable = function (el, options) {\n options = options || {};\n\n const candidates = getCandidates(\n el,\n options.includeContainer,\n isNodeMatchingSelectorFocusable.bind(null, options)\n );\n\n return candidates;\n};\n\nconst isTabbable = function (node, options) {\n options = options || {};\n if (!node) {\n throw new Error('No node provided');\n }\n if (matches.call(node, candidateSelector) === false) {\n return false;\n }\n return isNodeMatchingSelectorTabbable(options, node);\n};\n\nconst focusableCandidateSelector = /* #__PURE__ */ candidateSelectors\n .concat('iframe')\n .join(',');\n\nconst isFocusable = function (node, options) {\n options = options || {};\n if (!node) {\n throw new Error('No node provided');\n }\n if (matches.call(node, focusableCandidateSelector) === false) {\n return false;\n }\n return isNodeMatchingSelectorFocusable(options, node);\n};\n\nexport { tabbable, focusable, isTabbable, isFocusable };\n"],"names":["candidateSelectors","candidateSelector","join","matches","Element","prototype","msMatchesSelector","webkitMatchesSelector","getCandidates","el","includeContainer","filter","candidates","Array","slice","apply","querySelectorAll","call","unshift","getTabindex","node","tabindexAttr","parseInt","getAttribute","isNaN","contentEditable","isContentEditable","nodeName","tabIndex","sortOrderedTabbables","a","b","documentOrder","isInput","tagName","isNonTabbableRadio","type","isRadio","name","radioSet","radioScope","form","ownerDocument","queryRadios","window","CSS","escape","err","console","error","message","checked","nodes","i","length","getCheckedRadio","isTabbableRadio","isNodeMatchingSelectorFocusable","options","disabled","isHiddenInput","displayCheck","getComputedStyle","visibility","nodeUnderDetails","parentElement","getBoundingClientRect","width","height","display","isHidden","children","some","child","isDetailsWithSummary","isNodeMatchingSelectorTabbable","focusableCandidateSelector","concat","bind","Error","regularTabbables","orderedTabbables","forEach","candidate","candidateTabindex","push","sort","map"],"mappings":";;;;oUAAA,IAAMA,EAAqB,CACzB,QACA,SACA,WACA,UACA,SACA,aACA,kBACA,kBACA,mDACA,gCACA,WAEIC,EAAoCD,EAAmBE,KAAK,KAE5DC,EACe,oBAAZC,QACH,aACAA,QAAQC,UAAUF,SAClBC,QAAQC,UAAUC,mBAClBF,QAAQC,UAAUE,sBAElBC,EAAgB,SAAUC,EAAIC,EAAkBC,OAChDC,EAAaC,MAAMR,UAAUS,MAAMC,MACrCN,EAAGO,iBAAiBf,WAElBS,GAAoBP,EAAQc,KAAKR,EAAIR,IACvCW,EAAWM,QAAQT,GAErBG,EAAaA,EAAWD,OAAOA,IAQ3BQ,EAAc,SAAUC,OACtBC,EAAeC,SAASF,EAAKG,aAAa,YAAa,WAExDC,MAAMH,GAPa,SAAUD,SACF,SAAzBA,EAAKK,gBAYRC,CAAkBN,GACb,EASY,UAAlBA,EAAKO,UACc,UAAlBP,EAAKO,UACa,YAAlBP,EAAKO,UAC2B,OAAlCP,EAAKG,aAAa,YAKbH,EAAKQ,SAHH,EApBAP,GA0BLQ,EAAuB,SAAUC,EAAGC,UACjCD,EAAEF,WAAaG,EAAEH,SACpBE,EAAEE,cAAgBD,EAAEC,cACpBF,EAAEF,SAAWG,EAAEH,UAGfK,E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