UNPKG

js.foresight

Version:

Predicts mouse trajectory to trigger actions as users approach elements, enabling anticipatory UI updates or pre-loading. Made with vanilla javascript and usable in every framework.

1 lines 79.6 kB
{"version":3,"file":"index.mjs","sources":["../../../node_modules/.pnpm/tabbable@6.2.0/node_modules/tabbable/dist/index.esm.js","../../src/helpers/shouldRegister.ts","../../src/Manager/constants.ts","../../src/Manager/helpers/clampNumber.ts","../../src/Manager/helpers/lineSigmentIntersectsRect.ts","../../src/Manager/helpers/rectAndHitSlop.ts","../../src/Manager/helpers/shouldUpdateSetting.ts","../../../node_modules/.pnpm/position-observer@1.0.0/node_modules/position-observer/dist/index.js","../../src/Manager/ForesightManager.ts","../../src/Manager/helpers/getFocusedElementIndex.ts","../../src/Manager/helpers/predictNextMousePosition.ts","../../src/Manager/helpers/getScrollDirection.ts","../../src/Manager/helpers/predictNextScrollPosition.ts"],"sourcesContent":["/*!\n* tabbable 6.2.0\n* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE\n*/\n// NOTE: separate `:not()` selectors has broader browser support than the newer\n// `:not([inert], [inert] *)` (Feb 2023)\n// CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes\n// the entire query to fail, resulting in no nodes found, which will break a lot\n// of things... so we have to rely on JS to identify nodes inside an inert container\nvar candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable=\"false\"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];\nvar candidateSelector = /* #__PURE__ */candidateSelectors.join(',');\nvar NoElement = typeof Element === 'undefined';\nvar matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;\nvar getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {\n var _element$getRootNode;\n return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);\n} : function (element) {\n return element === null || element === void 0 ? void 0 : element.ownerDocument;\n};\n\n/**\n * Determines if a node is inert or in an inert ancestor.\n * @param {Element} [node]\n * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to\n * see if any of them are inert. If false, only `node` itself is considered.\n * @returns {boolean} True if inert itself or by way of being in an inert ancestor.\n * False if `node` is falsy.\n */\nvar isInert = function isInert(node, lookUp) {\n var _node$getAttribute;\n if (lookUp === void 0) {\n lookUp = true;\n }\n // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`\n // JS API property; we have to check the attribute, which can either be empty or 'true';\n // if it's `null` (not specified) or 'false', it's an active element\n var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');\n var inert = inertAtt === '' || inertAtt === 'true';\n\n // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`\n // if it weren't for `matches()` not being a function on shadow roots; the following\n // code works for any kind of node\n // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`\n // so it likely would not support `:is([inert] *)` either...\n var result = inert || lookUp && node && isInert(node.parentNode); // recursive\n\n return result;\n};\n\n/**\n * Determines if a node's content is editable.\n * @param {Element} [node]\n * @returns True if it's content-editable; false if it's not or `node` is falsy.\n */\nvar isContentEditable = function isContentEditable(node) {\n var _node$getAttribute2;\n // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have\n // to use the attribute directly to check for this, which can either be empty or 'true';\n // if it's `null` (not specified) or 'false', it's a non-editable element\n var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');\n return attValue === '' || attValue === 'true';\n};\n\n/**\n * @param {Element} el container to check in\n * @param {boolean} includeContainer add container to check\n * @param {(node: Element) => boolean} filter filter candidates\n * @returns {Element[]}\n */\nvar getCandidates = function getCandidates(el, includeContainer, filter) {\n // even if `includeContainer=false`, we still have to check it for inertness because\n // if it's inert, all its children are inert\n if (isInert(el)) {\n return [];\n }\n var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));\n if (includeContainer && matches.call(el, candidateSelector)) {\n candidates.unshift(el);\n }\n candidates = candidates.filter(filter);\n return candidates;\n};\n\n/**\n * @callback GetShadowRoot\n * @param {Element} element to check for shadow root\n * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.\n */\n\n/**\n * @callback ShadowRootFilter\n * @param {Element} shadowHostNode the element which contains shadow content\n * @returns {boolean} true if a shadow root could potentially contain valid candidates.\n */\n\n/**\n * @typedef {Object} CandidateScope\n * @property {Element} scopeParent contains inner candidates\n * @property {Element[]} candidates list of candidates found in the scope parent\n */\n\n/**\n * @typedef {Object} IterativeOptions\n * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;\n * if a function, implies shadow support is enabled and either returns the shadow root of an element\n * or a boolean stating if it has an undisclosed shadow root\n * @property {(node: Element) => boolean} filter filter candidates\n * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list\n * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;\n */\n\n/**\n * @param {Element[]} elements list of element containers to match candidates from\n * @param {boolean} includeContainer add container list to check\n * @param {IterativeOptions} options\n * @returns {Array.<Element|CandidateScope>}\n */\nvar getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {\n var candidates = [];\n var elementsToCheck = Array.from(elements);\n while (elementsToCheck.length) {\n var element = elementsToCheck.shift();\n if (isInert(element, false)) {\n // no need to look up since we're drilling down\n // anything inside this container will also be inert\n continue;\n }\n if (element.tagName === 'SLOT') {\n // add shadow dom slot scope (slot itself cannot be focusable)\n var assigned = element.assignedElements();\n var content = assigned.length ? assigned : element.children;\n var nestedCandidates = getCandidatesIteratively(content, true, options);\n if (options.flatten) {\n candidates.push.apply(candidates, nestedCandidates);\n } else {\n candidates.push({\n scopeParent: element,\n candidates: nestedCandidates\n });\n }\n } else {\n // check candidate element\n var validCandidate = matches.call(element, candidateSelector);\n if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {\n candidates.push(element);\n }\n\n // iterate over shadow content if possible\n var shadowRoot = element.shadowRoot ||\n // check for an undisclosed shadow\n typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);\n\n // no inert look up because we're already drilling down and checking for inertness\n // on the way down, so all containers to this root node should have already been\n // vetted as non-inert\n var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));\n if (shadowRoot && validShadowRoot) {\n // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed\n // shadow exists, so look at light dom children as fallback BUT create a scope for any\n // child candidates found because they're likely slotted elements (elements that are\n // children of the web component element (which has the shadow), in the light dom, but\n // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,\n // _after_ we return from this recursive call\n var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);\n if (options.flatten) {\n candidates.push.apply(candidates, _nestedCandidates);\n } else {\n candidates.push({\n scopeParent: element,\n candidates: _nestedCandidates\n });\n }\n } else {\n // there's not shadow so just dig into the element's (light dom) children\n // __without__ giving the element special scope treatment\n elementsToCheck.unshift.apply(elementsToCheck, element.children);\n }\n }\n }\n return candidates;\n};\n\n/**\n * @private\n * Determines if the node has an explicitly specified `tabindex` attribute.\n * @param {HTMLElement} node\n * @returns {boolean} True if so; false if not.\n */\nvar hasTabIndex = function hasTabIndex(node) {\n return !isNaN(parseInt(node.getAttribute('tabindex'), 10));\n};\n\n/**\n * Determine the tab index of a given node.\n * @param {HTMLElement} node\n * @returns {number} Tab order (negative, 0, or positive number).\n * @throws {Error} If `node` is falsy.\n */\nvar getTabIndex = function getTabIndex(node) {\n if (!node) {\n throw new Error('No node provided');\n }\n if (node.tabIndex < 0) {\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 // Also 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 ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {\n return 0;\n }\n }\n return node.tabIndex;\n};\n\n/**\n * Determine the tab index of a given node __for sort order purposes__.\n * @param {HTMLElement} node\n * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,\n * has tabIndex -1, but needs to be sorted by document order in order for its content to be\n * inserted into the correct sort position.\n * @returns {number} Tab order (negative, 0, or positive number).\n */\nvar getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {\n var tabIndex = getTabIndex(node);\n if (tabIndex < 0 && isScope && !hasTabIndex(node)) {\n return 0;\n }\n return tabIndex;\n};\nvar sortOrderedTabbables = function sortOrderedTabbables(a, b) {\n return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;\n};\nvar isInput = function isInput(node) {\n return node.tagName === 'INPUT';\n};\nvar isHiddenInput = function isHiddenInput(node) {\n return isInput(node) && node.type === 'hidden';\n};\nvar isDetailsWithSummary = function isDetailsWithSummary(node) {\n var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {\n return child.tagName === 'SUMMARY';\n });\n return r;\n};\nvar getCheckedRadio = function getCheckedRadio(nodes, form) {\n for (var i = 0; i < nodes.length; i++) {\n if (nodes[i].checked && nodes[i].form === form) {\n return nodes[i];\n }\n }\n};\nvar isTabbableRadio = function isTabbableRadio(node) {\n if (!node.name) {\n return true;\n }\n var radioScope = node.form || getRootNode(node);\n var queryRadios = function queryRadios(name) {\n return radioScope.querySelectorAll('input[type=\"radio\"][name=\"' + name + '\"]');\n };\n var radioSet;\n if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {\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('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);\n return false;\n }\n }\n var checked = getCheckedRadio(radioSet, node.form);\n return !checked || checked === node;\n};\nvar isRadio = function isRadio(node) {\n return isInput(node) && node.type === 'radio';\n};\nvar isNonTabbableRadio = function isNonTabbableRadio(node) {\n return isRadio(node) && !isTabbableRadio(node);\n};\n\n// determines if a node is ultimately attached to the window's document\nvar isNodeAttached = function isNodeAttached(node) {\n var _nodeRoot;\n // The root node is the shadow root if the node is in a shadow DOM; some document otherwise\n // (but NOT _the_ document; see second 'If' comment below for more).\n // If rootNode is shadow root, it'll have a host, which is the element to which the shadow\n // is attached, and the one we need to check if it's in the document or not (because the\n // shadow, and all nodes it contains, is never considered in the document since shadows\n // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,\n // is hidden, or is not in the document itself but is detached, it will affect the shadow's\n // visibility, including all the nodes it contains). The host could be any normal node,\n // or a custom element (i.e. web component). Either way, that's the one that is considered\n // part of the document, not the shadow root, nor any of its children (i.e. the node being\n // tested).\n // To further complicate things, we have to look all the way up until we find a shadow HOST\n // that is attached (or find none) because the node might be in nested shadows...\n // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the\n // document (per the docs) and while it's a Document-type object, that document does not\n // appear to be the same as the node's `ownerDocument` for some reason, so it's safer\n // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,\n // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when\n // node is actually detached.\n // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible\n // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed\n // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then\n // `ownerDocument` will be `null`, hence the optional chaining on it.\n var nodeRoot = node && getRootNode(node);\n var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;\n\n // in some cases, a detached node will return itself as the root instead of a document or\n // shadow root object, in which case, we shouldn't try to look further up the host chain\n var attached = false;\n if (nodeRoot && nodeRoot !== node) {\n var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;\n attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));\n while (!attached && nodeRootHost) {\n var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;\n // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,\n // which means we need to get the host's host and check if that parent host is contained\n // in (i.e. attached to) the document\n nodeRoot = getRootNode(nodeRootHost);\n nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;\n attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));\n }\n }\n return attached;\n};\nvar isZeroArea = function isZeroArea(node) {\n var _node$getBoundingClie = node.getBoundingClientRect(),\n width = _node$getBoundingClie.width,\n height = _node$getBoundingClie.height;\n return width === 0 && height === 0;\n};\nvar isHidden = function isHidden(node, _ref) {\n var displayCheck = _ref.displayCheck,\n getShadowRoot = _ref.getShadowRoot;\n // NOTE: visibility will be `undefined` if node is detached from the document\n // (see notes about this further down), which means we will consider it visible\n // (this is legacy behavior from a very long way back)\n // NOTE: we check this regardless of `displayCheck=\"none\"` because this is a\n // _visibility_ check, not a _display_ check\n if (getComputedStyle(node).visibility === 'hidden') {\n return true;\n }\n var isDirectSummary = matches.call(node, 'details>summary:first-of-type');\n var nodeUnderDetails = isDirectSummary ? node.parentElement : node;\n if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {\n return true;\n }\n if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {\n if (typeof getShadowRoot === 'function') {\n // figure out if we should consider the node to be in an undisclosed shadow and use the\n // 'non-zero-area' fallback\n var originalNode = node;\n while (node) {\n var parentElement = node.parentElement;\n var rootNode = getRootNode(node);\n if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow\n ) {\n // node has an undisclosed shadow which means we can only treat it as a black box, so we\n // fall back to a non-zero-area test\n return isZeroArea(node);\n } else if (node.assignedSlot) {\n // iterate up slot\n node = node.assignedSlot;\n } else if (!parentElement && rootNode !== node.ownerDocument) {\n // cross shadow boundary\n node = rootNode.host;\n } else {\n // iterate up normal dom\n node = parentElement;\n }\n }\n node = originalNode;\n }\n // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support\n // (i.e. it does not also presume that all nodes might have undisclosed shadows); or\n // it might be a falsy value, which means shadow DOM support is disabled\n\n // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)\n // now we can just test to see if it would normally be visible or not, provided it's\n // attached to the main document.\n // NOTE: We must consider case where node is inside a shadow DOM and given directly to\n // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.\n\n if (isNodeAttached(node)) {\n // this works wherever the node is: if there's at least one client rect, it's\n // somehow displayed; it also covers the CSS 'display: contents' case where the\n // node itself is hidden in place of its contents; and there's no need to search\n // up the hierarchy either\n return !node.getClientRects().length;\n }\n\n // Else, the node isn't attached to the document, which means the `getClientRects()`\n // API will __always__ return zero rects (this can happen, for example, if React\n // is used to render nodes onto a detached tree, as confirmed in this thread:\n // https://github.com/facebook/react/issues/9117#issuecomment-284228870)\n //\n // It also means that even window.getComputedStyle(node).display will return `undefined`\n // because styles are only computed for nodes that are in the document.\n //\n // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable\n // somehow. Though it was never stated officially, anyone who has ever used tabbable\n // APIs on nodes in detached containers has actually implicitly used tabbable in what\n // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck=\"none\"` mode -- essentially\n // considering __everything__ to be visible because of the innability to determine styles.\n //\n // v6.0.0: As of this major release, the default 'full' option __no longer treats detached\n // nodes as visible with the 'none' fallback.__\n if (displayCheck !== 'legacy-full') {\n return true; // hidden\n }\n // else, fallback to 'none' mode and consider the node visible\n } else if (displayCheck === 'non-zero-area') {\n // NOTE: Even though this tests that the node's client rect is non-zero to determine\n // whether it's displayed, and that a detached node will __always__ have a zero-area\n // client rect, we don't special-case for whether the node is attached or not. In\n // this mode, we do want to consider nodes that have a zero area to be hidden at all\n // times, and that includes attached or not.\n return isZeroArea(node);\n }\n\n // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume\n // it's visible\n return false;\n};\n\n// form fields (nested) inside a disabled fieldset are not focusable/tabbable\n// unless they are in the _first_ <legend> element of the top-most disabled\n// fieldset\nvar isDisabledFromFieldset = function isDisabledFromFieldset(node) {\n if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {\n var parentNode = node.parentElement;\n // check if `node` is contained in a disabled <fieldset>\n while (parentNode) {\n if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {\n // look for the first <legend> among the children of the disabled <fieldset>\n for (var i = 0; i < parentNode.children.length; i++) {\n var child = parentNode.children.item(i);\n // when the first <legend> (in document order) is found\n if (child.tagName === 'LEGEND') {\n // if its parent <fieldset> is not nested in another disabled <fieldset>,\n // return whether `node` is a descendant of its first <legend>\n return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);\n }\n }\n // the disabled <fieldset> containing `node` has no <legend>\n return true;\n }\n parentNode = parentNode.parentElement;\n }\n }\n\n // else, node's tabbable/focusable state should not be affected by a fieldset's\n // enabled/disabled state\n return false;\n};\nvar isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {\n if (node.disabled ||\n // we must do an inert look up to filter out any elements inside an inert ancestor\n // because we're limited in the type of selectors we can use in JSDom (see related\n // note related to `candidateSelectors`)\n isInert(node) || isHiddenInput(node) || isHidden(node, options) ||\n // For a details element with a summary, the summary element gets the focus\n isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {\n return false;\n }\n return true;\n};\nvar isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {\n if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {\n return false;\n }\n return true;\n};\nvar isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {\n var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);\n if (isNaN(tabIndex) || tabIndex >= 0) {\n return true;\n }\n // If a custom element has an explicit negative tabindex,\n // browsers will not allow tab targeting said element's children.\n return false;\n};\n\n/**\n * @param {Array.<Element|CandidateScope>} candidates\n * @returns Element[]\n */\nvar sortByOrder = function sortByOrder(candidates) {\n var regularTabbables = [];\n var orderedTabbables = [];\n candidates.forEach(function (item, i) {\n var isScope = !!item.scopeParent;\n var element = isScope ? item.scopeParent : item;\n var candidateTabindex = getSortOrderTabIndex(element, isScope);\n var elements = isScope ? sortByOrder(item.candidates) : element;\n if (candidateTabindex === 0) {\n isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);\n } else {\n orderedTabbables.push({\n documentOrder: i,\n tabIndex: candidateTabindex,\n item: item,\n isScope: isScope,\n content: elements\n });\n }\n });\n return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {\n sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);\n return acc;\n }, []).concat(regularTabbables);\n};\nvar tabbable = function tabbable(container, options) {\n options = options || {};\n var candidates;\n if (options.getShadowRoot) {\n candidates = getCandidatesIteratively([container], options.includeContainer, {\n filter: isNodeMatchingSelectorTabbable.bind(null, options),\n flatten: false,\n getShadowRoot: options.getShadowRoot,\n shadowRootFilter: isValidShadowRootTabbable\n });\n } else {\n candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));\n }\n return sortByOrder(candidates);\n};\nvar focusable = function focusable(container, options) {\n options = options || {};\n var candidates;\n if (options.getShadowRoot) {\n candidates = getCandidatesIteratively([container], options.includeContainer, {\n filter: isNodeMatchingSelectorFocusable.bind(null, options),\n flatten: true,\n getShadowRoot: options.getShadowRoot\n });\n } else {\n candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));\n }\n return candidates;\n};\nvar isTabbable = function isTabbable(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};\nvar focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');\nvar isFocusable = function isFocusable(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 { focusable, getTabIndex, isFocusable, isTabbable, tabbable };\n//# sourceMappingURL=index.esm.js.map\n",null,null,null,null,null,null,"// src/utilities/Rect.ts\nvar Rect = class {\n /**\n * Intersects two DOMRects.\n *\n * @param rect1 - The first DOMRect.\n * @param rect2 - The second DOMRect.\n * @returns The intersection of the two DOMRects.\n */\n static intersect(rect1, rect2) {\n const left = Math.max(rect1.left, rect2.left);\n const right = Math.min(rect1.right, rect2.right);\n const top = Math.max(rect1.top, rect2.top);\n const bottom = Math.min(rect1.bottom, rect2.bottom);\n const width = Math.max(0, right - left);\n const height = Math.max(0, bottom - top);\n return new DOMRect(left, top, width, height);\n }\n /**\n * Clips a DOMRect to a given rectangle.\n *\n * @param rect - The DOMRect to clip.\n * @param clip - The rectangle to clip the DOMRect to.\n * @returns The clipped DOMRect.\n */\n static clip(rect, clip) {\n const updatedRect = {\n ...rect.toJSON(),\n top: rect.top + clip.top,\n left: rect.left + clip.left,\n bottom: rect.bottom - clip.bottom,\n right: rect.right - clip.right\n };\n updatedRect.width = updatedRect.right - updatedRect.left;\n updatedRect.height = updatedRect.bottom - updatedRect.top;\n return updatedRect;\n }\n /**\n * Calculates the offsets of a clipped DOMRect.\n *\n * @param rect - The DOMRect to calculate the offsets for.\n * @param clippedRect - The clipped DOMRect.\n * @returns The offsets of the clipped DOMRect.\n */\n static clipOffsets(rect, clippedRect) {\n return {\n top: clippedRect.top - rect.top,\n left: clippedRect.left - rect.left,\n bottom: rect.bottom - clippedRect.bottom,\n right: rect.right - clippedRect.right\n };\n }\n /**\n * Checks if two DOMRects are equal.\n *\n * @param rect1 - The first DOMRect.\n * @param rect2 - The second DOMRect.\n * @returns True if the DOMRects are equal, false otherwise.\n */\n static equals(rect1, rect2) {\n if (rect1 == null || rect2 == null) return rect1 === rect2;\n return rect1.x === rect2.x && rect1.y === rect2.y && rect1.width === rect2.width && rect1.height === rect2.height;\n }\n static sizeEqual(rect1, rect2) {\n return Math.round(rect1.width) === Math.round(rect2.width) && Math.round(rect1.height) === Math.round(rect2.height);\n }\n};\n\n// src/utilities/rootMargin.ts\nvar INSET = -1;\nvar MIN_SIZE = 1 - INSET * 2;\nfunction rootMargin(rect, rootBounds) {\n const width = Math.max(rect.width, MIN_SIZE);\n const height = Math.max(rect.height, MIN_SIZE);\n const top = rect.top - rootBounds.top - INSET;\n const left = rect.left - rootBounds.left - INSET;\n const right = rootBounds.right - rect.left - width - INSET;\n const bottom = rootBounds.bottom - rect.top - height - INSET;\n return `${-Math.round(top)}px ${-Math.round(right)}px ${-Math.round(bottom)}px ${-Math.round(left)}px`;\n}\n\n// src/utilities/threshold.ts\nvar threshold = [\n ...Array.from({ length: 1e3 }, (_, i) => i / 1e3),\n 1\n];\n\n// src/observers/PositionIntersectionObserver.ts\nvar PositionIntersectionObserver = class {\n constructor(element, callback, options) {\n this.#callback = callback;\n this.#options = options;\n this.#clientRect = options.clientRect;\n this.#observe(element);\n }\n #callback;\n #observer = void 0;\n #options;\n #clientRect;\n #previousIntersectionRatio = void 0;\n /**\n * The visible rectangle of the element within the root.\n *\n * @returns The visible rectangle of the element within the root.\n */\n get visibleRect() {\n const clip = this.#options.clip;\n return clip ? Rect.clip(this.#clientRect, clip) : this.#clientRect;\n }\n /**\n * Whether the element is intersecting with the root.\n *\n * @returns Whether the element is intersecting with the root.\n */\n get isIntersecting() {\n const { width, height } = this.visibleRect;\n return width > 0 && height > 0;\n }\n /**\n * Observes the element.\n */\n #observe(element) {\n const { root, rootBounds } = this.#options;\n const { visibleRect } = this;\n this.#observer?.disconnect();\n this.#observer = new IntersectionObserver(this.#onIntersection, {\n root,\n rootMargin: rootMargin(visibleRect, rootBounds),\n threshold\n });\n this.#observer.observe(element);\n }\n /**\n * The callback function for the intersection observer.\n */\n #onIntersection = (entries) => {\n if (!this.#observer) return;\n const entry = entries[entries.length - 1];\n if (entry) {\n const { intersectionRatio, boundingClientRect } = entry;\n const previousClientRect = this.#clientRect;\n this.#clientRect = boundingClientRect;\n const previousIntersectionRatio = this.#previousIntersectionRatio;\n const clientRectChanged = !Rect.equals(\n boundingClientRect,\n previousClientRect\n );\n if (intersectionRatio !== this.#previousIntersectionRatio || clientRectChanged) {\n const rootBounds = this.#options.rootBounds;\n const rootIntersection = Rect.intersect(boundingClientRect, rootBounds);\n const isIntersecting = rootIntersection.width > 0 && rootIntersection.height > 0;\n if (!isIntersecting) {\n return;\n }\n this.#previousIntersectionRatio = intersectionRatio;\n if (previousIntersectionRatio != null || clientRectChanged) {\n this.#callback(\n new PositionIntersectionObserverEntry(\n entry.target,\n boundingClientRect,\n entry.intersectionRect,\n isIntersecting,\n rootBounds\n ),\n this\n );\n this.#observe(entry.target);\n }\n }\n }\n };\n /**\n * Disconnects the position intersection observer.\n */\n disconnect() {\n this.#observer?.disconnect();\n }\n};\nvar PositionIntersectionObserverEntry = class {\n constructor(target, boundingClientRect, intersectionRect, isIntersecting, rootBounds) {\n this.target = target;\n this.boundingClientRect = boundingClientRect;\n this.intersectionRect = intersectionRect;\n this.isIntersecting = isIntersecting;\n this.rootBounds = rootBounds;\n }\n};\n\n// src/observers/RootBoundsObserver.ts\nvar RootBoundsObserver = class {\n /**\n * Creates a new root bounds observer.\n *\n * @param root - The root element to observe.\n * @param callback - The callback function to call when the root bounds change.\n */\n constructor(target, callback) {\n const root = getRoot(target);\n if (isElement(root)) {\n const ownerDocument = root.ownerDocument ?? document;\n this.rootBounds = root.getBoundingClientRect();\n this.#resizeObserver = new ResizeObserver((entries) => {\n for (const entry of entries) {\n const [{ inlineSize: width, blockSize: height }] = entry.borderBoxSize;\n if (Rect.sizeEqual(this.rootBounds, { width, height })) {\n continue;\n }\n const rect = entry.target.getBoundingClientRect();\n this.rootBounds = rect;\n callback(rect, this);\n }\n });\n this.#resizeObserver.observe(root);\n ownerDocument.addEventListener(\n \"scroll\",\n (event) => {\n if (event.target && event.target !== root && isNode(event.target) && event.target.contains(root)) {\n this.rootBounds = root.getBoundingClientRect();\n callback(this.rootBounds, this);\n }\n },\n { capture: true, passive: true, signal: this.#controller.signal }\n );\n } else {\n const viewport = root.visualViewport ?? root;\n this.rootBounds = getWindowRect(root);\n const handleResize = () => {\n const rect = getWindowRect(root);\n if (Rect.equals(this.rootBounds, rect)) return;\n this.rootBounds = rect;\n callback(rect, this);\n };\n viewport.addEventListener(\"resize\", handleResize, {\n signal: this.#controller.signal\n });\n }\n }\n /**\n * The resize observer if the root is an element.\n */\n #resizeObserver;\n /**\n * The controller to disconnect the root bounds resize and scroll listeners.\n */\n #controller = new AbortController();\n /**\n * The bounds of the root element.\n */\n rootBounds;\n /**\n * Disconnects the root bounds observer.\n */\n disconnect() {\n this.#resizeObserver?.disconnect();\n this.#controller.abort();\n }\n};\nfunction getWindowRect(window2) {\n const width = window2.visualViewport?.width ?? window2.innerWidth;\n const height = window2.visualViewport?.height ?? window2.innerHeight;\n return new DOMRect(0, 0, width, height);\n}\nfunction isNode(target) {\n return \"nodeType\" in target;\n}\nfunction isElement(target) {\n return isNode(target) && target.nodeType === Node.ELEMENT_NODE;\n}\nfunction isDocument(root) {\n return root.nodeType === Node.DOCUMENT_NODE;\n}\nfunction getRoot(target) {\n return !target || isDocument(target) ? target?.defaultView ?? window : target;\n}\n\n// src/observers/VisibilityObserver.ts\nvar VisibilityObserver = class {\n constructor(callback, options) {\n this.#options = options;\n this.#callback = (entries) => {\n const changedEntries = [];\n for (const entry of entries) {\n const previousIntersection = this.intersections.get(entry.target);\n this.intersections.set(entry.target, entry);\n if (previousIntersection?.isIntersecting !== entry.isIntersecting || !Rect.equals(\n previousIntersection?.intersectionRect,\n entry.intersectionRect\n )) {\n changedEntries.push(entry);\n }\n }\n if (changedEntries.length > 0) {\n callback(changedEntries, this);\n }\n };\n }\n /**\n * The callback function to be invoked when the intersection entries change.\n */\n #callback;\n /**\n * The visibility observer for each document.\n */\n #observers = /* @__PURE__ */ new Map();\n /**\n * The options for the visibility observer.\n */\n #options;\n /**\n * The latest intersection entries for the observed elements.\n */\n intersections = /* @__PURE__ */ new WeakMap();\n /**\n * Observes an element.\n *\n * @param element - The element to observe.\n */\n observe(element) {\n const document2 = element.ownerDocument;\n if (!document2) return;\n let observer = this.#observers.get(document2);\n if (!observer) {\n observer = new IntersectionObserver(this.#callback, {\n ...this.#options,\n threshold\n });\n this.#observers.set(document2, observer);\n }\n observer.observe(element);\n }\n /**\n * Unobserves an element.\n *\n * @param element - The element to unobserve.\n */\n unobserve(element) {\n const document2 = element.ownerDocument;\n if (!document2) return;\n const observer = this.#observers.get(document2);\n if (!observer) return;\n observer.unobserve(element);\n this.intersections.delete(element);\n }\n /**\n * Disconnects the visibility observer.\n */\n disconnect() {\n for (const observer of this.#observers.values()) {\n observer.disconnect();\n }\n this.#observers.clear();\n }\n};\n\n// src/PositionObserver.ts\nvar PositionObserver = class {\n constructor(callback, options) {\n this.#callback = callback;\n this.#options = options;\n this.#rootBoundsObserver = new RootBoundsObserver(\n options?.root,\n this.#onRootBoundsChange\n );\n this.#visibilityObserver = new VisibilityObserver(\n this.#onVisibilityChange,\n options\n );\n this.#resizeObserver = new ResizeObserver(this.#onResize);\n }\n /**\n * The callback function to be invoked when the position changes.\n */\n #callback;\n /**\n * The options for the position observer.\n */\n #options;\n /**\n * The position observers for the observed elements.\n */\n #positionObservers = /* @__PURE__ */ new Map();\n /**\n * The resize observer for the observed elements.\n */\n #resizeObserver;\n /**\n * The positions of the observed elements.\n */\n #positions = /* @__PURE__ */ new WeakMap();\n /**\n * The root bounds observer for the observed elements.\n */\n #rootBoundsObserver;\n /**\n * The visibility observer for the observed elements.\n */\n #visibilityObserver;\n /**\n * Observes an element.\n *\n * @param element - The element to observe.\n */\n observe(element) {\n this.#visibilityObserver.observe(element);\n }\n /**\n * Unobserves an element.\n *\n * @param element - The element to unobserve. If not provided, the position observer is disconnected.\n */\n unobserve(element) {\n if (element) {\n this.#positionObservers.get(element)?.disconnect();\n this.#visibilityObserver.unobserve(element);\n } else {\n this.disconnect();\n }\n }\n /**\n * Disconnects the observer.\n */\n disconnect() {\n for (const positionObserver of this.#positionObservers.values()) {\n positionObserver.disconnect();\n }\n this.#resizeObserver.disconnect();\n this.#rootBoundsObserver.disconnect();\n this.#visibilityObserver.disconnect();\n }\n /**\n * Notifies the position observer of the changes.\n *\n * @param entries - The entries to notify.\n */\n #notify(entries) {\n const records = [];\n for (const entry of entries) {\n const { target } = entry;\n const previousEntry = this.#positions.get(target);\n if (isEntryEqual(entry, previousEntry)) continue;\n this.#positions.set(target, entry);\n records.push(entry);\n }\n if (records.length > 0) {\n this.#callback(records);\n }\n }\n /**\n * The callback function to be invoked when the root bounds change.\n */\n #onRootBoundsChange = (rootBounds) => {\n const entries = [];\n for (const [element] of this.#positionObservers) {\n const boundingClientRect = element.getBoundingClientRect();\n const observer = this.#observePosition(element, boundingClientRect);\n entries.push(\n new PositionObserverEntry(\n element,\n boundingClientRect,\n observer.visibleRect,\n observer.isIntersecting,\n rootBounds\n )\n );\n }\n this.#notify(entries);\n };\n /**\n * Observes the position of an element.\n *\n * @param element - The element to observe.\n * @param clientRect - The client rect of the element.\n */\n #observePosition(element, clientRect) {\n const visibilityObserver = this.#visibilityObserver;\n this.#positionObservers.get(element)?.disconnect();\n const positionObserver = new PositionIntersectionObserver(\n element,\n this.#onPositionChange,\n {\n clientRect,\n root: this.#options?.root,\n rootBounds: this.#rootBoundsObserver.rootBounds,\n get clip() {\n const intersection = visibilityObserver.intersections.get(element);\n if (!intersection) return;\n const { intersectionRect, boundingClientRect } = intersection;\n return Rect.clipOffsets(boundingClientRect, intersectionRect);\n }\n }\n );\n this.#positionObservers.set(element, positionObserver);\n return positionObserver;\n }\n /**\n * The callback function to be invoked when the visibility changes.\n */\n #onVisibilityChange = (entries) => {\n const records = [];\n for (const entry of entries) {\n const { target, isIntersecting, boundingClientRect } = entry;\n if (isIntersecting) {\n this.#observePosition(target, boundingClientRect);\n this.#resizeObserver.observe(target);\n } else {\n this.#positionObservers.get(target)?.disconnect();\n this.#positionObservers.delete(target);\n this.#resizeObserver.unobserve(target);\n }\n const observer = this.#positionObservers.get(target);\n records.push(\n new PositionObserverEntry(\n target,\n boundingClientRect,\n observer?.visibleRect ?? entry.intersectionRect,\n isIntersecting,\n this.#rootBoundsObserver.rootBounds\n )\n );\n }\n this.#notify(records);\n };\n /**\n * The callback function to be invoked when the position changes.\n */\n #onPositionChange = (entry, observer) => {\n this.#notify([\n new PositionObserverEntry(\n entry.target,\n entry.boundingClientRect,\n observer.visibleRect,\n entry.isIntersecting,\n this.#rootBoundsObserver.rootBounds\n )\n ]);\n };\n /**\n * The callback function to be invoked when the resize observer entries change.\n */\n #onResize = (entries) => {\n const records = [];\n for (const entry of entries) {\n const { target, borderBoxSize } = entry;\n const previous = this.#positions.get(target);\n if (previous) {\n const [{ inlineSize: width, blockSize: height }] = borderBoxSize;\n if (Rect.sizeEqual(previous.boundingClientRect, { width, height })) {\n continue;\n }\n }\n const boundingClientRect = target.getBoundingClientRect();\n const observer = this.#observePosition(target, boundingClientRect);\n records.push(\n new PositionObserverEntry(\n target,\n boundingClientRect,\n observer.visibleRect,\n this.#visibilityObserver.intersections.get(target)?.isIntersecting ?? false,\n this.#rootBoundsObserver.rootBounds\n )\n );\n }\n this.#notify(records);\n };\n};\nvar PositionObserverEntry = class {\n constructor(target, boundingClientRect, intersectionRect, isIntersecting, rootBounds) {\n this.target = target;\n this.boundingClientRect = boundingClientRect;\n this.intersectionRect = intersectionRect;\n this.isIntersecting = isIntersecting;\n this.rootBounds = rootBounds;\n }\n};\nfunction isEntryEqual(first, second) {\n if (second == null) return false;\n return first.target === second.target && first.isIntersecting === second.isIntersecting && Rect.equals(first.boundingClientRect, second.boundingClientRect) && Rect.equals(first.intersectionRect, second.intersectionRect);\n}\nexport {\n PositionObserver,\n PositionObserverEntry\n};\n//# sourceMappingURL=index.js.map",null,null,null,null,null],"names":["candidateSelector","join","NoElement","Element","matches","prototype","msMatchesSelector","webkitMatchesSelector","getRootNode","element","_element$getRootNode","call","ownerDocument","isInert","node","lookUp","_node$getAttribute","inertAtt","getAttribute","parentNode","getCandidatesIteratively","elements","includeContainer","options","candidates","elementsToCheck","Array","from","length","shift","tagName","assigned","assignedElements","nestedCandidates","children","flatten","push","apply","scopeParent","filter","includes","shadowRoot","getShadowRoot","validShadowRoot","shadowRootFilter","_nestedCandidates","unshift","hasTabIndex","isNaN","parseInt","getTabIndex","Error","tabIndex","test","_node$getAttribute2","attValue","isContentEditable","sortOrderedTabbables","a","b","documentOrder","isInput","isNonTabbableRadio","type","isRadio","name","radioSet","radioScope","form","queryRadios","querySelectorAll","window","CSS","escape","err","console","error","message","checked","nodes","i","getCheckedRadio","isTabbableRadio","isZeroArea","_node$getBoundingClie","getBoundingClientRect","width","height","isHidden","_ref","displayCheck","getComputedStyle","visibility","nodeUnderDetails","parentElement","originalNode","rootNode","assignedSlot","host","_nodeRoot","_nodeRootHost","_nodeRootHost$ownerDo","_node$ownerDocument","nodeRoot","nodeRootHost","attached","contains","_nodeRoot2","_nodeRootHost2","_nodeRootHost2$ownerD","isNodeAttached","getClientRects","isNodeMatchingSelectorFocusable","disabled","isHiddenInput","slice","some","child","isDetailsWithSummary","item","isDisabledFromFieldset","isNodeMatchingSelectorTabbable","isValidShadowRootTabbable","shadowHostNode","sortByOrder","regularTabbables","orderedTabbables","forEach","isScope","candidateTabindex","getSortOrderTabIndex","content","sort","reduce","acc","sortable","concat","tabbable","container","bind","el","getCandidates","evaluateRegistrationConditions","isTouchDevice","matchMedia","navigator","maxTouchPoints","isLimitedConnection","connection","effectiveType","saveData","hasConnectionLimitations","shouldRegister","MAX_HITSLOP","clampNumber","number","lowerBound","upperBound","settingName","warn","Math","min","max","lineSegmentIntersectsRect","p1","p2","rect","t0","t1","dx","x","dy","y","clipTest","p","q","r","left","right","top","bottom","normalizeHitSlop","hitSlop","clampedValue","getExpandedRect","baseRect","areRectsEqual","rect1","rect2","isPointInRectangle","point","shouldUpdateSetting","newValue","currentValue","undefined","Rect","intersect","DOMRect","clip","updatedRect","toJSON","clipOffsets","clippedRect","equals","sizeEqual","round","rootMargin","rootBounds","threshold","_","PositionIntersectionObserver","constructor","callback","this","clientRect","observe","observer","previousIntersectionRatio","visibleRect","isIntersecting","root","disconnect","IntersectionObserver","onIntersection","entries","entry","intersectionRatio","boundingClientRect","previousClientRect","clientRectChanged","rootIntersection","PositionIntersectionObserverEntry","target","intersectionRect","RootBoundsObserver","nodeType","Node","DOCUMENT_NODE","isDocument","defaultView","getRoot","isNode","ELEMENT_NODE","isElement","document","resizeObserver","ResizeObserver","inlineSize","bl