js.foresight 3.0.1 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +120 -5
- package/dist/{src/types/types.d.ts → index.d.mts} +156 -67
- package/dist/index.d.ts +61 -47
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -12
- package/dist/Manager/ForesightManager.d.ts +0 -89
- package/dist/Manager/ForesightManager.d.ts.map +0 -1
- package/dist/Manager/ForesightManager.js +0 -639
- package/dist/Manager/ForesightManager.js.map +0 -1
- package/dist/Manager/constants.d.ts +0 -23
- package/dist/Manager/constants.d.ts.map +0 -1
- package/dist/Manager/constants.js +0 -24
- package/dist/Manager/constants.js.map +0 -1
- package/dist/Manager/helpers/clampNumber.d.ts +0 -2
- package/dist/Manager/helpers/clampNumber.d.ts.map +0 -1
- package/dist/Manager/helpers/clampNumber.js +0 -10
- package/dist/Manager/helpers/clampNumber.js.map +0 -1
- package/dist/Manager/helpers/getFocusedElementIndex.d.ts +0 -15
- package/dist/Manager/helpers/getFocusedElementIndex.d.ts.map +0 -1
- package/dist/Manager/helpers/getFocusedElementIndex.js +0 -27
- package/dist/Manager/helpers/getFocusedElementIndex.js.map +0 -1
- package/dist/Manager/helpers/getScrollDirection.d.ts +0 -3
- package/dist/Manager/helpers/getScrollDirection.d.ts.map +0 -1
- package/dist/Manager/helpers/getScrollDirection.js +0 -21
- package/dist/Manager/helpers/getScrollDirection.js.map +0 -1
- package/dist/Manager/helpers/lineSigmentIntersectsRect.d.ts +0 -12
- package/dist/Manager/helpers/lineSigmentIntersectsRect.d.ts.map +0 -1
- package/dist/Manager/helpers/lineSigmentIntersectsRect.js +0 -52
- package/dist/Manager/helpers/lineSigmentIntersectsRect.js.map +0 -1
- package/dist/Manager/helpers/predictNextMousePosition.d.ts +0 -19
- package/dist/Manager/helpers/predictNextMousePosition.d.ts.map +0 -1
- package/dist/Manager/helpers/predictNextMousePosition.js +0 -43
- package/dist/Manager/helpers/predictNextMousePosition.js.map +0 -1
- package/dist/Manager/helpers/predictNextScrollPosition.d.ts +0 -6
- package/dist/Manager/helpers/predictNextScrollPosition.d.ts.map +0 -1
- package/dist/Manager/helpers/predictNextScrollPosition.js +0 -20
- package/dist/Manager/helpers/predictNextScrollPosition.js.map +0 -1
- package/dist/Manager/helpers/rectAndHitSlop.d.ts +0 -33
- package/dist/Manager/helpers/rectAndHitSlop.d.ts.map +0 -1
- package/dist/Manager/helpers/rectAndHitSlop.js +0 -66
- package/dist/Manager/helpers/rectAndHitSlop.js.map +0 -1
- package/dist/Manager/helpers/shouldUpdateSetting.d.ts +0 -11
- package/dist/Manager/helpers/shouldUpdateSetting.d.ts.map +0 -1
- package/dist/Manager/helpers/shouldUpdateSetting.js +0 -16
- package/dist/Manager/helpers/shouldUpdateSetting.js.map +0 -1
- package/dist/helpers/shouldRegister.d.ts +0 -8
- package/dist/helpers/shouldRegister.d.ts.map +0 -1
- package/dist/helpers/shouldRegister.js +0 -31
- package/dist/helpers/shouldRegister.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/src/Manager/ForesightManager.d.ts +0 -89
- package/dist/src/Manager/ForesightManager.d.ts.map +0 -1
- package/dist/src/Manager/ForesightManager.test.d.ts +0 -2
- package/dist/src/Manager/ForesightManager.test.d.ts.map +0 -1
- package/dist/src/Manager/constants.d.ts +0 -23
- package/dist/src/Manager/constants.d.ts.map +0 -1
- package/dist/src/Manager/helpers/clampNumber.d.ts +0 -2
- package/dist/src/Manager/helpers/clampNumber.d.ts.map +0 -1
- package/dist/src/Manager/helpers/clampNumber.test.d.ts +0 -2
- package/dist/src/Manager/helpers/clampNumber.test.d.ts.map +0 -1
- package/dist/src/Manager/helpers/getFocusedElementIndex.d.ts +0 -15
- package/dist/src/Manager/helpers/getFocusedElementIndex.d.ts.map +0 -1
- package/dist/src/Manager/helpers/getFocusedElementIndex.test.d.ts +0 -2
- package/dist/src/Manager/helpers/getFocusedElementIndex.test.d.ts.map +0 -1
- package/dist/src/Manager/helpers/getScrollDirection.d.ts +0 -3
- package/dist/src/Manager/helpers/getScrollDirection.d.ts.map +0 -1
- package/dist/src/Manager/helpers/lineSegmentIntersectsRect.test.d.ts +0 -2
- package/dist/src/Manager/helpers/lineSegmentIntersectsRect.test.d.ts.map +0 -1
- package/dist/src/Manager/helpers/lineSigmentIntersectsRect.d.ts +0 -12
- package/dist/src/Manager/helpers/lineSigmentIntersectsRect.d.ts.map +0 -1
- package/dist/src/Manager/helpers/predictNextMousePosition.d.ts +0 -19
- package/dist/src/Manager/helpers/predictNextMousePosition.d.ts.map +0 -1
- package/dist/src/Manager/helpers/predictNextMousePosition.test.d.ts +0 -2
- package/dist/src/Manager/helpers/predictNextMousePosition.test.d.ts.map +0 -1
- package/dist/src/Manager/helpers/predictNextScrollPosition.d.ts +0 -6
- package/dist/src/Manager/helpers/predictNextScrollPosition.d.ts.map +0 -1
- package/dist/src/Manager/helpers/rectAndHitSlop.d.ts +0 -33
- package/dist/src/Manager/helpers/rectAndHitSlop.d.ts.map +0 -1
- package/dist/src/Manager/helpers/rectAndHitSlop.test.d.ts +0 -2
- package/dist/src/Manager/helpers/rectAndHitSlop.test.d.ts.map +0 -1
- package/dist/src/Manager/helpers/shouldUpdateSetting.d.ts +0 -11
- package/dist/src/Manager/helpers/shouldUpdateSetting.d.ts.map +0 -1
- package/dist/src/helpers/shouldRegister.d.ts +0 -8
- package/dist/src/helpers/shouldRegister.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/types/types.d.ts.map +0 -1
- package/dist/test-setup.d.ts +0 -17
- package/dist/test-setup.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/types.d.ts +0 -312
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js +0 -2
- package/dist/types/types.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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","blockSize","borderBoxSize","addEventListener","event","capture","passive","signal","controller","viewport","visualViewport","getWindowRect","handleResize","AbortController","abort","window2","innerWidth","innerHeight","VisibilityObserver","changedEntries","previousIntersection","intersections","get","set","observers","Map","WeakMap","document2","unobserve","delete","values","clear","PositionObserver","rootBoundsObserver","onRootBoundsChange","visibilityObserver","onVisibilityChange","onResize","positionObservers","positions","positionObserver","notify","records","isEntryEqual","observePosition","PositionObserverEntry","onPositionChange","intersection","previous","first","second","ForesightManager","isSetup","_globalCallbackHits","mouse","hover","trajectory","tab","forwards","reverse","scroll","down","up","total","_globalSettings","debug","enableMousePrediction","enableScrollPrediction","positionHistorySize","trajectoryPredictionTime","scrollMargin","defaultHitSlop","enableTabPrediction","tabOffset","onAnyCallbackFired","_elementData","_managerData","trajectoryPositions","currentPoint","predictedPoint","tabbableElementsCache","lastFocusedIndex","predictedScrollPoint","scrollDirection","domObserver","lastKeyDown","globalListenersController","eventListeners","handleMouseMove","e","updatePointerState","currentData","isIntersectingWithViewport","handleCallbackInteraction","emit","predictionEnabled","timestamp","Date","now","handleDomMutations","mutationsList","mutation","removedNodes","keys","isConnected","unregister","handleKeyDown","key","handleFocusIn","targetElement","HTMLElement","documentElement","isReversed","shiftKey","currentIndex","predictedIndex","findIndex","getFocusedElementIndex","elementsToPredict","has","callCallback","kind","subType","handlePositionChange","elementData","wasPreviouslyIntersecting","isNowIntersecting","updatedProp","updateElementBounds","handleScrollPrefetch","initialize","props","isInitiated","manager","alterGlobalSettings","eventType","listener","aborted","removeEventListener","listeners","index","indexOf","splice","logSubscribers","log","eventTypes","groupCollapsed","groupEnd","getManagerData","registeredElements","globalSettings","globalCallbackHits","instance","register","isRegistered","initializeGlobalListeners","normalizedHitSlop","elementBounds","originalRect","expandedRect","isHovering","trajectoryHitData","isTrajectoryHit","trajectoryHitTime","trajectoryHitExpirationTimeoutId","id","unregisterReason","foresightElementData","clearTimeout","size","removeGlobalListeners","updateNumericSettings","setting","updateBooleanSetting","oldPositionHistorySize","positionHistoryChanged","trajectoryTimeChanged","scrollMarginChanged","tabOffsetChanged","mousePredictionChanged","scrollPredictionChanged","tabPredictionChanged","hitSlopChanged","normalizedNewHitSlop","forceUpdateAllElementBounds","managerData","forceUpdateElementBounds","clientX","clientY","history","trajectoryPredictionTimeInMs","currentPosition","time","performance","last","dt","trajectoryPredictionTimeInSeconds","predictNextMousePosition","updateHitCounters","hitType","newOriginalRect","updatedElementData","newRect","oldRect","deltaY","deltaX","getScrollDirection","direction","predictNextScrollPosition","MutationObserver","childList","subtree","attributes"],"mappings":";;;;EASA,IACIA,EADqB,CAAC,qBAAsB,sBAAuB,wBAAyB,uBAAwB,sBAAuB,oCAAqC,+BAAgC,+BAAgC,gEAAiE,6CAA8C,wBACzSC,KAAK,KAC3DC,EAA+B,oBAAZC,QACnBC,EAAUF,EAAY,WAAY,EAAKC,QAAQE,UAAUD,SAAWD,QAAQE,UAAUC,mBAAqBH,QAAQE,UAAUE,sBAC7HC,GAAeN,GAAaC,QAAQE,UAAUG,YAAc,SAAUC,GACxE,IAAIC,EACJ,OAAOD,SAAmG,QAAhDC,EAAuBD,EAAQD,mBAAkD,IAAzBE,OAAlE,EAA6GA,EAAqBC,KAAKF,EACzL,EAAI,SAAUA,GACZ,OAAOA,aAAyC,EAASA,EAAQG,aACnE,EAUIC,EAAU,SAASA,EAAQC,EAAMC,GACnC,IAAIC,OACW,IAAXD,IACFA,GAAS,GAKX,IAAIE,EAAWH,SAAyF,QAA5CE,EAAqBF,EAAKI,oBAAiD,IAAvBF,OAA9D,EAAuGA,EAAmBL,KAAKG,EAAM,SAUvL,MATyB,KAAbG,GAAgC,SAAbA,GAOTF,GAAUD,GAAQD,EAAQC,EAAKK,WAGvD,EAsEIC,EAA2B,SAASA,EAAyBC,EAAUC,EAAkBC,GAG3F,IAFA,IAAIC,EAAa,GACbC,EAAkBC,MAAMC,KAAKN,GAC1BI,EAAgBG,QAAQ,CAC7B,IAAInB,EAAUgB,EAAgBI,QAC9B,IAAIhB,EAAQJ,GAAS,GAKrB,GAAwB,SAApBA,EAAQqB,QAAoB,CAE9B,IAAIC,EAAWtB,EAAQuB,mBAEnBC,EAAmBb,EADTW,EAASH,OAASG,EAAWtB,EAAQyB,UACM,EAAMX,GAC3DA,EAAQY,QACVX,EAAWY,KAAKC,MAAMb,EAAYS,GAElCT,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A2BxE,QAChChD,KAAKwH,0BAA4B,KAEjCxH,KAAKsH,aAAa9G,aAClBR,KAAKsH,YAAc,KACnBtH,KAAK0E,kBAAkBlE,aACvBR,KAAK0E,iBAAmB","x_google_ignoreList":[0,7]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/manager/ForesightManager.ts","../src/helpers/shouldRegister.ts","../src/helpers/clampNumber.ts","../src/helpers/lineSigmentIntersectsRect.ts","../src/helpers/predictNextMousePosition.ts","../src/helpers/rectAndHitSlop.ts","../src/helpers/shouldUpdateSetting.ts","../src/helpers/getFocusedElementIndex.ts","../src/helpers/getScrollDirection.ts","../src/helpers/predictNextScrollPosition.ts","../src/helpers/initialViewportState.ts"],"sourcesContent":["export { ForesightManager } from \"./manager/ForesightManager\"\r\nexport type {\r\n Rect as ForesightRect,\r\n ForesightElement,\r\n ForesightRegisterResult,\r\n UpdateForsightManagerSettings,\r\n ForesightManagerSettings,\r\n ForesightRegisterOptions,\r\n ForesightRegisterOptionsWithoutElement,\r\n ForesightElementData,\r\n ForesightEvent,\r\n ElementRegisteredEvent,\r\n ElementUnregisteredEvent,\r\n ElementDataUpdatedEvent,\r\n CallbackInvokedEvent,\r\n CallbackCompletedEvent,\r\n MouseTrajectoryUpdateEvent,\r\n ScrollTrajectoryUpdateEvent,\r\n ManagerSettingsChangedEvent,\r\n UpdatedManagerSetting,\r\n HitSlop,\r\n CallbackHitType,\r\n CallbackHits,\r\n} from \"./types/types\"\r\n","import { tabbable, type FocusableElement } from \"tabbable\"\r\nimport { evaluateRegistrationConditions } from \"../helpers/shouldRegister\"\r\nimport type {\r\n CallbackHits,\r\n ElementUnregisteredReason,\r\n ForesightElement,\r\n ForesightElementData,\r\n ForesightEventMap,\r\n ForesightEvent,\r\n ForesightManagerData,\r\n ForesightManagerSettings,\r\n ForesightRegisterOptions,\r\n ForesightRegisterResult,\r\n CallbackHitType,\r\n ManagerBooleanSettingKeys,\r\n NumericSettingKeys,\r\n Point,\r\n ScrollDirection,\r\n TrajectoryPositions,\r\n UpdateForsightManagerSettings,\r\n ForesightEventListener,\r\n UpdatedDataPropertyNames,\r\n UpdatedManagerSetting,\r\n NumericSettingConfig,\r\n} from \"../types/types\"\r\nimport {\r\n DEFAULT_ENABLE_MOUSE_PREDICTION,\r\n DEFAULT_ENABLE_SCROLL_PREDICTION,\r\n DEFAULT_ENABLE_TAB_PREDICTION,\r\n DEFAULT_HITSLOP,\r\n DEFAULT_POSITION_HISTORY_SIZE,\r\n DEFAULT_SCROLL_MARGIN,\r\n DEFAULT_TAB_OFFSET,\r\n DEFAULT_TRAJECTORY_PREDICTION_TIME,\r\n MAX_POSITION_HISTORY_SIZE,\r\n MAX_SCROLL_MARGIN,\r\n MAX_TAB_OFFSET,\r\n MAX_TRAJECTORY_PREDICTION_TIME,\r\n MIN_POSITION_HISTORY_SIZE,\r\n MIN_SCROLL_MARGIN,\r\n MIN_TAB_OFFSET,\r\n MIN_TRAJECTORY_PREDICTION_TIME,\r\n} from \"../constants\"\r\nimport { clampNumber } from \"../helpers/clampNumber\"\r\nimport { lineSegmentIntersectsRect } from \"../helpers/lineSigmentIntersectsRect\"\r\nimport { predictNextMousePosition } from \"../helpers/predictNextMousePosition\"\r\nimport {\r\n areRectsEqual,\r\n getExpandedRect,\r\n isPointInRectangle,\r\n normalizeHitSlop,\r\n} from \"../helpers/rectAndHitSlop\"\r\nimport { shouldUpdateSetting } from \"../helpers/shouldUpdateSetting\"\r\nimport { getFocusedElementIndex } from \"../helpers/getFocusedElementIndex\"\r\nimport { getScrollDirection } from \"../helpers/getScrollDirection\"\r\nimport { predictNextScrollPosition } from \"../helpers/predictNextScrollPosition\"\r\nimport { PositionObserver, PositionObserverEntry } from \"position-observer\"\r\nimport { initialViewportState } from \"../helpers/initialViewportState\"\r\n\r\n/**\r\n * Manages the prediction of user intent based on mouse trajectory and element interactions.\r\n *\r\n * ForesightManager is a singleton class responsible for:\r\n * - Registering HTML elements to monitor.\r\n * - Tracking mouse movements and predicting future cursor positions.\r\n * - Detecting when a predicted trajectory intersects with a registered element's bounds.\r\n * - Invoking callbacks associated with elements upon predicted or actual interaction.\r\n * - Optionally unregistering elements after their callback is triggered.\r\n * - Handling global settings for prediction behavior (e.g., history size, prediction time).\r\n * - Automatically updating element bounds on resize using {@link ResizeObserver}.\r\n * - Automatically unregistering elements removed from the DOM using {@link MutationObserver}.\r\n * - Detecting broader layout shifts via {@link MutationObserver} to update element positions.\r\n *\r\n * It should be initialized once using {@link ForesightManager.initialize} and then\r\n * accessed via the static getter {@link ForesightManager.instance}.\r\n */\r\n\r\nexport class ForesightManager {\r\n private static manager: ForesightManager\r\n private elements: Map<ForesightElement, ForesightElementData> = new Map()\r\n\r\n private isSetup: boolean = false\r\n private _globalCallbackHits: CallbackHits = {\r\n mouse: {\r\n hover: 0,\r\n trajectory: 0,\r\n },\r\n tab: {\r\n forwards: 0,\r\n reverse: 0,\r\n },\r\n scroll: {\r\n down: 0,\r\n left: 0,\r\n right: 0,\r\n up: 0,\r\n },\r\n total: 0,\r\n }\r\n private _globalSettings: ForesightManagerSettings = {\r\n debug: false,\r\n enableMousePrediction: DEFAULT_ENABLE_MOUSE_PREDICTION,\r\n enableScrollPrediction: DEFAULT_ENABLE_SCROLL_PREDICTION,\r\n positionHistorySize: DEFAULT_POSITION_HISTORY_SIZE,\r\n trajectoryPredictionTime: DEFAULT_TRAJECTORY_PREDICTION_TIME,\r\n scrollMargin: DEFAULT_SCROLL_MARGIN,\r\n defaultHitSlop: {\r\n top: DEFAULT_HITSLOP,\r\n left: DEFAULT_HITSLOP,\r\n right: DEFAULT_HITSLOP,\r\n bottom: DEFAULT_HITSLOP,\r\n },\r\n enableTabPrediction: DEFAULT_ENABLE_TAB_PREDICTION,\r\n tabOffset: DEFAULT_TAB_OFFSET,\r\n }\r\n private trajectoryPositions: TrajectoryPositions = {\r\n positions: [],\r\n currentPoint: { x: 0, y: 0 },\r\n predictedPoint: { x: 0, y: 0 },\r\n }\r\n\r\n private tabbableElementsCache: FocusableElement[] = []\r\n private lastFocusedIndex: number | null = null\r\n\r\n private predictedScrollPoint: Point | null = null\r\n private scrollDirection: ScrollDirection | null = null\r\n private domObserver: MutationObserver | null = null\r\n private positionObserver: PositionObserver | null = null\r\n // Track the last keydown event to determine if focus change was due to Tab\r\n private lastKeyDown: KeyboardEvent | null = null\r\n\r\n // AbortController for managing global event listeners\r\n private globalListenersController: AbortController = new AbortController()\r\n\r\n // RequestAnimationFrame throttling for mouse events\r\n private rafId: number | null = null\r\n private pendingMouseEvent: MouseEvent | null = null\r\n\r\n private eventListeners: Map<ForesightEvent, ForesightEventListener[]> = new Map()\r\n\r\n // Never put something in the constructor, use initialize instead\r\n private constructor() {}\r\n\r\n public static initialize(props?: Partial<UpdateForsightManagerSettings>): ForesightManager {\r\n if (!this.isInitiated) {\r\n ForesightManager.manager = new ForesightManager()\r\n }\r\n if (props !== undefined) {\r\n ForesightManager.manager.alterGlobalSettings(props)\r\n }\r\n return ForesightManager.manager\r\n }\r\n\r\n public addEventListener<K extends ForesightEvent>(\r\n eventType: K,\r\n listener: ForesightEventListener<K>,\r\n options?: { signal?: AbortSignal }\r\n ) {\r\n if (options?.signal?.aborted) {\r\n return () => {}\r\n }\r\n const listeners = this.eventListeners.get(eventType) ?? []\r\n listeners.push(listener as ForesightEventListener)\r\n this.eventListeners.set(eventType, listeners)\r\n options?.signal?.addEventListener(\"abort\", () => this.removeEventListener(eventType, listener))\r\n }\r\n\r\n public removeEventListener<K extends ForesightEvent>(\r\n eventType: K,\r\n listener: ForesightEventListener<K>\r\n ): void {\r\n const listeners = this.eventListeners.get(eventType)\r\n if (!listeners) {\r\n return\r\n }\r\n const index = listeners.indexOf(listener as ForesightEventListener)\r\n if (index > -1) {\r\n listeners.splice(index, 1)\r\n }\r\n }\r\n\r\n private emit<K extends ForesightEvent>(event: ForesightEventMap[K]): void {\r\n const listeners = this.eventListeners.get(event.type)\r\n if (!listeners) {\r\n return\r\n }\r\n listeners.forEach(listener => {\r\n try {\r\n listener(event)\r\n } catch (error) {\r\n console.error(`Error in ForesightManager event listener for ${event.type}:`, error)\r\n }\r\n })\r\n }\r\n\r\n public get getManagerData(): Readonly<ForesightManagerData> {\r\n return {\r\n registeredElements: this.elements,\r\n globalSettings: this._globalSettings,\r\n globalCallbackHits: this._globalCallbackHits,\r\n eventListeners: this.eventListeners,\r\n }\r\n }\r\n\r\n public static get isInitiated(): Readonly<boolean> {\r\n return !!ForesightManager.manager\r\n }\r\n\r\n public static get instance(): ForesightManager {\r\n return this.initialize()\r\n }\r\n\r\n public get registeredElements(): ReadonlyMap<ForesightElement, ForesightElementData> {\r\n return this.elements\r\n }\r\n\r\n public register({\r\n element,\r\n callback,\r\n hitSlop,\r\n name,\r\n }: ForesightRegisterOptions): ForesightRegisterResult {\r\n const { shouldRegister, isTouchDevice, isLimitedConnection } = evaluateRegistrationConditions()\r\n if (!shouldRegister) {\r\n return {\r\n isLimitedConnection,\r\n isTouchDevice,\r\n isRegistered: false,\r\n unregister: () => {},\r\n }\r\n }\r\n\r\n // Setup global listeners on every first element added to the manager. It gets removed again when the map is emptied\r\n if (!this.isSetup) {\r\n this.initializeGlobalListeners()\r\n }\r\n\r\n const initialRect = element.getBoundingClientRect()\r\n\r\n const normalizedHitSlop = hitSlop\r\n ? normalizeHitSlop(hitSlop)\r\n : this._globalSettings.defaultHitSlop\r\n\r\n const elementData: ForesightElementData = {\r\n element: element,\r\n callback,\r\n elementBounds: {\r\n originalRect: initialRect,\r\n expandedRect: getExpandedRect(initialRect, normalizedHitSlop),\r\n hitSlop: normalizedHitSlop,\r\n },\r\n isHovering: false,\r\n trajectoryHitData: {\r\n isTrajectoryHit: false,\r\n trajectoryHitTime: 0,\r\n trajectoryHitExpirationTimeoutId: undefined,\r\n },\r\n name: name || element.id || \"unnamed\",\r\n isIntersectingWithViewport: initialViewportState(initialRect),\r\n isRunningCallback: false,\r\n registerCount: (this.registeredElements.get(element)?.registerCount ?? 0) + 1,\r\n }\r\n\r\n this.elements.set(element, elementData)\r\n\r\n this.positionObserver?.observe(element)\r\n\r\n this.emit({\r\n type: \"elementRegistered\",\r\n timestamp: Date.now(),\r\n elementData,\r\n })\r\n\r\n return {\r\n isTouchDevice,\r\n isLimitedConnection,\r\n isRegistered: true,\r\n unregister: () => this.unregister(element, \"apiCall\"),\r\n }\r\n }\r\n\r\n private unregister(element: ForesightElement, unregisterReason: ElementUnregisteredReason) {\r\n if (!this.elements.has(element)) {\r\n return\r\n }\r\n\r\n const elementData = this.elements.get(element)\r\n\r\n // Clear any pending trajectory expiration timeout\r\n if (elementData?.trajectoryHitData.trajectoryHitExpirationTimeoutId) {\r\n clearTimeout(elementData.trajectoryHitData.trajectoryHitExpirationTimeoutId)\r\n }\r\n\r\n this.positionObserver?.unobserve(element)\r\n this.elements.delete(element)\r\n\r\n if (this.elements.size === 0 && this.isSetup) {\r\n this.removeGlobalListeners()\r\n }\r\n\r\n if (elementData) {\r\n this.emit({\r\n type: \"elementUnregistered\",\r\n elementData: elementData,\r\n timestamp: Date.now(),\r\n unregisterReason: unregisterReason,\r\n })\r\n }\r\n }\r\n\r\n private updateNumericSettings(\r\n newValue: number | undefined,\r\n setting: NumericSettingKeys,\r\n min: number,\r\n max: number\r\n ) {\r\n if (!shouldUpdateSetting(newValue, this._globalSettings[setting])) {\r\n return false\r\n }\r\n\r\n this._globalSettings[setting] = clampNumber(newValue, min, max, setting)\r\n\r\n return true\r\n }\r\n\r\n private updateBooleanSetting(\r\n newValue: boolean | undefined,\r\n setting: ManagerBooleanSettingKeys\r\n ): boolean {\r\n if (!shouldUpdateSetting(newValue, this._globalSettings[setting])) {\r\n return false\r\n }\r\n this._globalSettings[setting] = newValue\r\n return true\r\n }\r\n\r\n public alterGlobalSettings(props?: Partial<UpdateForsightManagerSettings>): void {\r\n const changedSettings: UpdatedManagerSetting[] = []\r\n const NUMERIC_SETTING_CONFIGS: readonly NumericSettingConfig[] = [\r\n {\r\n setting: \"positionHistorySize\",\r\n min: MIN_POSITION_HISTORY_SIZE,\r\n max: MAX_POSITION_HISTORY_SIZE,\r\n },\r\n {\r\n setting: \"trajectoryPredictionTime\",\r\n min: MIN_TRAJECTORY_PREDICTION_TIME,\r\n max: MAX_TRAJECTORY_PREDICTION_TIME,\r\n },\r\n {\r\n setting: \"scrollMargin\",\r\n min: MIN_SCROLL_MARGIN,\r\n max: MAX_SCROLL_MARGIN,\r\n },\r\n {\r\n setting: \"tabOffset\",\r\n min: MIN_TAB_OFFSET,\r\n max: MAX_TAB_OFFSET,\r\n },\r\n ]\r\n\r\n NUMERIC_SETTING_CONFIGS.forEach(({ setting, min, max }) => {\r\n const newValue = props?.[setting]\r\n if (newValue === undefined) return\r\n\r\n const oldValue = this._globalSettings[setting]\r\n const changed = this.updateNumericSettings(newValue, setting, min, max)\r\n\r\n if (changed) {\r\n changedSettings.push({\r\n setting,\r\n oldValue,\r\n newValue: this._globalSettings[setting],\r\n })\r\n\r\n if (\r\n setting === \"positionHistorySize\" &&\r\n this._globalSettings.positionHistorySize < oldValue\r\n ) {\r\n const newSize = this._globalSettings.positionHistorySize\r\n if (this.trajectoryPositions.positions.length > newSize) {\r\n this.trajectoryPositions.positions = this.trajectoryPositions.positions.slice(-newSize)\r\n }\r\n }\r\n }\r\n })\r\n\r\n const booleanSettings: ManagerBooleanSettingKeys[] = [\r\n \"enableMousePrediction\",\r\n \"enableScrollPrediction\",\r\n \"enableTabPrediction\",\r\n ]\r\n\r\n booleanSettings.forEach(setting => {\r\n const newValue = props?.[setting]\r\n if (newValue === undefined) return\r\n\r\n const oldValue = this._globalSettings[setting]\r\n const changed = this.updateBooleanSetting(newValue, setting)\r\n\r\n if (changed) {\r\n changedSettings.push({ setting, oldValue, newValue: this._globalSettings[setting] })\r\n }\r\n })\r\n\r\n if (props?.defaultHitSlop !== undefined) {\r\n const oldHitSlop = this._globalSettings.defaultHitSlop\r\n const normalizedNewHitSlop = normalizeHitSlop(props.defaultHitSlop)\r\n\r\n if (!areRectsEqual(oldHitSlop, normalizedNewHitSlop)) {\r\n this._globalSettings.defaultHitSlop = normalizedNewHitSlop\r\n changedSettings.push({\r\n setting: \"defaultHitSlop\",\r\n oldValue: oldHitSlop,\r\n newValue: normalizedNewHitSlop,\r\n })\r\n this.forceUpdateAllElementBounds()\r\n }\r\n }\r\n\r\n if (changedSettings.length > 0) {\r\n this.emit({\r\n type: \"managerSettingsChanged\",\r\n timestamp: Date.now(),\r\n managerData: this.getManagerData,\r\n updatedSettings: changedSettings,\r\n })\r\n }\r\n }\r\n\r\n private forceUpdateAllElementBounds() {\r\n for (const [_, elementData] of this.elements) {\r\n if (elementData.isIntersectingWithViewport) {\r\n this.forceUpdateElementBounds(elementData)\r\n }\r\n }\r\n }\r\n\r\n private updatePointerState(e: MouseEvent): void {\r\n const currentPoint = { x: e.clientX, y: e.clientY }\r\n this.trajectoryPositions.currentPoint = currentPoint\r\n\r\n if (this._globalSettings.enableMousePrediction) {\r\n this.trajectoryPositions.predictedPoint = predictNextMousePosition(\r\n currentPoint,\r\n this.trajectoryPositions.positions,\r\n this._globalSettings.positionHistorySize,\r\n this._globalSettings.trajectoryPredictionTime\r\n )\r\n } else {\r\n this.trajectoryPositions.predictedPoint = currentPoint\r\n }\r\n }\r\n\r\n private handleMouseMove = (e: MouseEvent) => {\r\n this.pendingMouseEvent = e\r\n // Throttle processing to animation frames for better performance\r\n if (this.rafId) return\r\n\r\n this.rafId = requestAnimationFrame(() => {\r\n if (this.pendingMouseEvent) {\r\n this.processMouseMovement(this.pendingMouseEvent)\r\n this.pendingMouseEvent = null\r\n }\r\n this.rafId = null\r\n })\r\n }\r\n\r\n private processMouseMovement(e: MouseEvent) {\r\n this.updatePointerState(e)\r\n\r\n // Use for...of instead of forEach for better performance in hot code path\r\n // Avoids function call overhead and iterator creation on every mouse move\r\n for (const currentData of this.elements.values()) {\r\n if (!currentData.isIntersectingWithViewport) {\r\n continue\r\n }\r\n const expandedRect = currentData.elementBounds.expandedRect\r\n\r\n if (!this._globalSettings.enableMousePrediction) {\r\n if (isPointInRectangle(this.trajectoryPositions.currentPoint, expandedRect)) {\r\n this.callCallback(currentData, { kind: \"mouse\", subType: \"hover\" })\r\n return\r\n }\r\n // when enable mouse prediction is off, we only check if the mouse is physically hovering over the element\r\n } else if (\r\n lineSegmentIntersectsRect(\r\n this.trajectoryPositions.currentPoint,\r\n this.trajectoryPositions.predictedPoint,\r\n expandedRect\r\n )\r\n ) {\r\n this.callCallback(currentData, { kind: \"mouse\", subType: \"trajectory\" })\r\n }\r\n }\r\n\r\n this.emit({\r\n type: \"mouseTrajectoryUpdate\",\r\n predictionEnabled: this._globalSettings.enableMousePrediction,\r\n trajectoryPositions: this.trajectoryPositions,\r\n })\r\n }\r\n\r\n /**\r\n * Detects when registered elements are removed from the DOM and automatically unregisters them to prevent stale references.\r\n *\r\n * @param mutationsList - Array of MutationRecord objects describing the DOM changes\r\n *\r\n */\r\n private handleDomMutations = (mutationsList: MutationRecord[]) => {\r\n // Invalidate tabbale elements cache\r\n if (mutationsList.length) {\r\n this.tabbableElementsCache = []\r\n this.lastFocusedIndex = null\r\n }\r\n for (const mutation of mutationsList) {\r\n if (mutation.type === \"childList\" && mutation.removedNodes.length > 0) {\r\n for (const element of this.elements.keys()) {\r\n if (!element.isConnected) {\r\n this.unregister(element, \"disconnected\")\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // We store the last key for the FocusIn event, meaning we know if the user is tabbing around the page.\r\n // We dont use handleKeyDown for the full event because of 2 main reasons:\r\n // 1: handleKeyDown e.target returns the target on which the keydown is pressed (meaning we dont know which target got the focus)\r\n // 2: handleKeyUp does return the correct e.target however when holding tab the event doesnt repeat (handleKeyDown does)\r\n private handleKeyDown = (e: KeyboardEvent) => {\r\n if (e.key === \"Tab\") {\r\n this.lastKeyDown = e\r\n }\r\n }\r\n\r\n private handleFocusIn = (e: FocusEvent) => {\r\n if (!this.lastKeyDown || !this._globalSettings.enableTabPrediction) {\r\n return\r\n }\r\n const targetElement = e.target\r\n if (!(targetElement instanceof HTMLElement)) {\r\n return\r\n }\r\n\r\n // tabbable uses element.GetBoundingClientRect under the hood, to avoid alot of computations we cache its values\r\n if (!this.tabbableElementsCache.length) {\r\n this.tabbableElementsCache = tabbable(document.documentElement)\r\n }\r\n\r\n // Determine the range of elements to check based on the tab direction and offset\r\n const isReversed = this.lastKeyDown.shiftKey\r\n\r\n const currentIndex: number = getFocusedElementIndex(\r\n isReversed,\r\n this.lastFocusedIndex,\r\n this.tabbableElementsCache,\r\n targetElement\r\n )\r\n\r\n this.lastFocusedIndex = currentIndex\r\n\r\n this.lastKeyDown = null\r\n const elementsToPredict: ForesightElement[] = []\r\n for (let i = 0; i <= this._globalSettings.tabOffset; i++) {\r\n if (isReversed) {\r\n const element = this.tabbableElementsCache[currentIndex - i]\r\n if (this.elements.has(element as ForesightElement)) {\r\n elementsToPredict.push(element as ForesightElement)\r\n }\r\n } else {\r\n const element = this.tabbableElementsCache[currentIndex + i]\r\n if (this.elements.has(element as ForesightElement)) {\r\n elementsToPredict.push(element as ForesightElement)\r\n }\r\n }\r\n }\r\n\r\n elementsToPredict.forEach(element => {\r\n const foresightElement = this.elements.get(element)\r\n if (foresightElement) {\r\n this.callCallback(foresightElement, {\r\n kind: \"tab\",\r\n subType: isReversed ? \"reverse\" : \"forwards\",\r\n })\r\n }\r\n })\r\n }\r\n\r\n private updateHitCounters(callbackHitType: CallbackHitType, elementData: ForesightElementData) {\r\n switch (callbackHitType.kind) {\r\n case \"mouse\":\r\n this._globalCallbackHits.mouse[callbackHitType.subType]++\r\n break\r\n case \"tab\":\r\n this._globalCallbackHits.tab[callbackHitType.subType]++\r\n break\r\n case \"scroll\":\r\n this._globalCallbackHits.scroll[callbackHitType.subType]++\r\n break\r\n default:\r\n callbackHitType satisfies never\r\n }\r\n this._globalCallbackHits.total++\r\n }\r\n\r\n private callCallback(elementData: ForesightElementData, callbackHitType: CallbackHitType) {\r\n if (elementData.isRunningCallback) {\r\n return\r\n }\r\n // We have this async wrapper so we can time exactly how long the callback takes\r\n elementData.isRunningCallback = true\r\n const asyncCallbackWrapper = async () => {\r\n this.updateHitCounters(callbackHitType, elementData)\r\n this.emit({\r\n type: \"callbackInvoked\",\r\n timestamp: Date.now(),\r\n elementData,\r\n hitType: callbackHitType,\r\n })\r\n const start = performance.now()\r\n try {\r\n await elementData.callback()\r\n this.emit({\r\n type: \"callbackCompleted\",\r\n timestamp: Date.now(),\r\n elementData,\r\n hitType: callbackHitType,\r\n elapsed: performance.now() - start,\r\n status: \"success\",\r\n })\r\n } catch (error) {\r\n const errorMessage = error instanceof Error ? error.message : String(error)\r\n console.error(\r\n `Error in callback for element ${elementData.name} (${elementData.element.tagName}):`,\r\n error\r\n )\r\n this.emit({\r\n type: \"callbackCompleted\",\r\n timestamp: Date.now(),\r\n elementData,\r\n hitType: callbackHitType,\r\n elapsed: performance.now() - start,\r\n status: \"error\",\r\n errorMessage,\r\n })\r\n }\r\n this.unregister(elementData.element, \"callbackHit\")\r\n }\r\n asyncCallbackWrapper()\r\n }\r\n\r\n /**\r\n * ONLY use this function when you want to change the rect bounds via code, if the rects are changing because of updates in the DOM do not use this function.\r\n * We need an observer for that\r\n */\r\n private forceUpdateElementBounds(elementData: ForesightElementData) {\r\n const newOriginalRect = elementData.element.getBoundingClientRect()\r\n const expandedRect = getExpandedRect(newOriginalRect, elementData.elementBounds.hitSlop)\r\n\r\n if (!areRectsEqual(expandedRect, elementData.elementBounds.expandedRect)) {\r\n const updatedElementData = {\r\n ...elementData,\r\n elementBounds: {\r\n ...elementData.elementBounds,\r\n originalRect: newOriginalRect,\r\n expandedRect,\r\n },\r\n }\r\n this.elements.set(elementData.element, updatedElementData)\r\n\r\n this.emit({\r\n type: \"elementDataUpdated\",\r\n elementData: updatedElementData,\r\n updatedProps: [\"bounds\"],\r\n })\r\n }\r\n }\r\n\r\n private handlePositionChange = (entries: PositionObserverEntry[]) => {\r\n for (const entry of entries) {\r\n const elementData = this.elements.get(entry.target)\r\n if (!elementData) {\r\n continue\r\n }\r\n\r\n // Always call handlePositionChangeDataUpdates before handleScrollPrefetch\r\n this.handlePositionChangeDataUpdates(elementData, entry)\r\n this.handleScrollPrefetch(elementData, entry.boundingClientRect)\r\n }\r\n // Reset scroll prefetch\r\n this.scrollDirection = null\r\n this.predictedScrollPoint = null\r\n }\r\n\r\n private handlePositionChangeDataUpdates = (\r\n elementData: ForesightElementData,\r\n entry: PositionObserverEntry\r\n ) => {\r\n const updatedProps: UpdatedDataPropertyNames[] = []\r\n const isNowIntersecting = entry.isIntersecting\r\n\r\n // Create updated element data with new intersection state\r\n let updatedElementData = {\r\n ...elementData,\r\n isIntersectingWithViewport: isNowIntersecting,\r\n }\r\n\r\n // Track visibility changes\r\n if (elementData.isIntersectingWithViewport !== isNowIntersecting) {\r\n updatedProps.push(\"visibility\")\r\n }\r\n\r\n // Handle bounds updates for intersecting elements\r\n if (isNowIntersecting) {\r\n updatedProps.push(\"bounds\")\r\n this.handleScrollPrefetch(updatedElementData, entry.boundingClientRect)\r\n updatedElementData = {\r\n ...updatedElementData,\r\n elementBounds: {\r\n hitSlop: elementData.elementBounds.hitSlop,\r\n originalRect: entry.boundingClientRect,\r\n expandedRect: getExpandedRect(\r\n entry.boundingClientRect,\r\n elementData.elementBounds.hitSlop\r\n ),\r\n },\r\n }\r\n }\r\n\r\n // Update state and emit once\r\n this.elements.set(elementData.element, updatedElementData)\r\n if (updatedProps.length) {\r\n this.emit({\r\n type: \"elementDataUpdated\",\r\n elementData: updatedElementData,\r\n updatedProps,\r\n })\r\n }\r\n }\r\n\r\n private handleScrollPrefetch(elementData: ForesightElementData, newRect: DOMRect) {\r\n if (!elementData.isIntersectingWithViewport) {\r\n return\r\n }\r\n if (!this._globalSettings.enableScrollPrediction) {\r\n // If we dont check for scroll prediction, check if the user is hovering over the element during a scroll instead\r\n if (\r\n isPointInRectangle(\r\n this.trajectoryPositions.currentPoint,\r\n elementData.elementBounds.expandedRect\r\n )\r\n ) {\r\n this.callCallback(elementData, {\r\n kind: \"mouse\",\r\n subType: \"hover\",\r\n })\r\n }\r\n } else {\r\n // ONCE per handlePositionChange batch we decide what the scroll direction is\r\n this.scrollDirection =\r\n this.scrollDirection ?? getScrollDirection(elementData.elementBounds.originalRect, newRect)\r\n if (this.scrollDirection === \"none\") {\r\n return\r\n }\r\n // ONCE per handlePositionChange batch we decide the predicted scroll point\r\n this.predictedScrollPoint =\r\n this.predictedScrollPoint ??\r\n predictNextScrollPosition(\r\n this.trajectoryPositions.currentPoint,\r\n this.scrollDirection,\r\n this._globalSettings.scrollMargin\r\n )\r\n\r\n // Check if the scroll is going to intersect with an registered element\r\n if (\r\n lineSegmentIntersectsRect(\r\n this.trajectoryPositions.currentPoint,\r\n this.predictedScrollPoint,\r\n elementData.elementBounds.expandedRect\r\n )\r\n ) {\r\n this.callCallback(elementData, {\r\n kind: \"scroll\",\r\n subType: this.scrollDirection,\r\n })\r\n }\r\n this.emit({\r\n type: \"scrollTrajectoryUpdate\",\r\n currentPoint: this.trajectoryPositions.currentPoint,\r\n predictedPoint: this.predictedScrollPoint,\r\n scrollDirection: this.scrollDirection,\r\n })\r\n }\r\n }\r\n\r\n private initializeGlobalListeners() {\r\n if (this.isSetup) {\r\n return\r\n }\r\n // To avoid setting up listeners while ssr\r\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\r\n return\r\n }\r\n\r\n const { signal } = this.globalListenersController\r\n //TODO only add event listeners when the events are enabled (mouse/tab)\r\n document.addEventListener(\"mousemove\", this.handleMouseMove) // Dont add signal we still need to emit events even without elements\r\n document.addEventListener(\"keydown\", this.handleKeyDown, { signal })\r\n document.addEventListener(\"focusin\", this.handleFocusIn, { signal })\r\n\r\n //Mutation observer is to automatically unregister elements when they leave the DOM. Its a fail-safe for if the user forgets to do it.\r\n this.domObserver = new MutationObserver(this.handleDomMutations)\r\n this.domObserver.observe(document.documentElement, {\r\n childList: true,\r\n subtree: true,\r\n attributes: false,\r\n })\r\n\r\n // Handles all position based changes and update the rects of the elements. completely async to avoid dirtying the main thread.\r\n // Handles resize of elements\r\n // Handles resize of viewport\r\n // Handles scrolling\r\n this.positionObserver = new PositionObserver(this.handlePositionChange)\r\n\r\n this.isSetup = true\r\n }\r\n\r\n private removeGlobalListeners() {\r\n this.isSetup = false\r\n\r\n this.globalListenersController?.abort() // Remove all event listeners only in non debug mode\r\n this.tabbableElementsCache = []\r\n this.lastFocusedIndex = null\r\n this.domObserver?.disconnect()\r\n this.domObserver = null\r\n this.positionObserver?.disconnect()\r\n this.positionObserver = null\r\n\r\n // Cancel any pending RAF and clean up mouse event throttling\r\n if (this.rafId) {\r\n cancelAnimationFrame(this.rafId)\r\n this.rafId = null\r\n }\r\n this.pendingMouseEvent = null\r\n }\r\n}\r\n","type ShouldRegister = {\r\n shouldRegister: boolean\r\n isTouchDevice: boolean\r\n isLimitedConnection: boolean\r\n}\r\n\r\nexport function evaluateRegistrationConditions(): ShouldRegister {\r\n const isTouchDevice = userUsesTouchDevice()\r\n const isLimitedConnection = hasConnectionLimitations()\r\n const shouldRegister = !isTouchDevice && !isLimitedConnection\r\n return { isTouchDevice, isLimitedConnection, shouldRegister }\r\n}\r\n\r\n/**\r\n * Detects if the current device is likely a touch-enabled device.\r\n * It checks for coarse pointer media query and the presence of touch points.\r\n *\r\n * @returns `true` if the device is likely touch-enabled, `false` otherwise.\r\n */\r\nfunction userUsesTouchDevice(): boolean {\r\n return window.matchMedia(\"(pointer: coarse)\").matches && navigator.maxTouchPoints > 0\r\n}\r\n\r\n/**\r\n * Checks if the user has connection limitations (slow network or data saver enabled).\r\n *\r\n * @returns {boolean} True if connection is limited, false if safe to prefetch\r\n * @example\r\n * if (!hasConnectionLimitations()) {\r\n * prefetchResource('/api/data');\r\n * }\r\n */\r\nfunction hasConnectionLimitations(): boolean {\r\n const connection = (navigator as any).connection\r\n if (!connection) return false\r\n\r\n return /2g/.test(connection.effectiveType) || connection.saveData\r\n}\r\n","export function clampNumber(\r\n number: number,\r\n lowerBound: number,\r\n upperBound: number,\r\n settingName: string\r\n) {\r\n if (number < lowerBound) {\r\n console.warn(\r\n `ForesightJS: \"${settingName}\" value ${number} is below minimum bound ${lowerBound}, clamping to ${lowerBound}`\r\n )\r\n } else if (number > upperBound) {\r\n console.warn(\r\n `ForesightJS: \"${settingName}\" value ${number} is above maximum bound ${upperBound}, clamping to ${upperBound}`\r\n )\r\n }\r\n\r\n return Math.min(Math.max(number, lowerBound), upperBound)\r\n}\r\n","import type { Point, Rect } from \"../types/types\"\r\n\r\n/**\r\n * Determines if a line segment intersects with a given rectangle.\r\n * This function implements the Liang-Barsky line clipping algorithm.\r\n *\r\n * @param p1 - The starting {@link Point} of the line segment.\r\n * @param p2 - The ending {@link Point} of the line segment.\r\n * @param rect - The {@link Rect} to check for intersection.\r\n * @returns `true` if the line segment intersects the rectangle, `false` otherwise.\r\n */\r\nexport function lineSegmentIntersectsRect(p1: Point, p2: Point, rect: Rect): boolean {\r\n let t0 = 0.0\r\n let t1 = 1.0\r\n const dx = p2.x - p1.x\r\n const dy = p2.y - p1.y\r\n\r\n const clipTest = (p: number, q: number): boolean => {\r\n if (p === 0) {\r\n // Line is parallel to this clipping edge\r\n if (q < 0) return false // Line is outside the clipping edge\r\n } else {\r\n const r = q / p\r\n if (p < 0) {\r\n // Line proceeds from outside to inside\r\n if (r > t1) return false // Line segment ends before crossing edge\r\n if (r > t0) t0 = r // Update entry point\r\n } else {\r\n // Line proceeds from inside to outside\r\n if (r < t0) return false // Line segment starts after crossing edge\r\n if (r < t1) t1 = r // Update exit point\r\n }\r\n }\r\n return true\r\n }\r\n\r\n // Clip against all four edges of the rectangle\r\n if (!clipTest(-dx, p1.x - rect.left)) return false // Left edge\r\n if (!clipTest(dx, rect.right - p1.x)) return false // Right edge\r\n if (!clipTest(-dy, p1.y - rect.top)) return false // Top edge\r\n if (!clipTest(dy, rect.bottom - p1.y)) return false // Bottom edge\r\n\r\n // If t0 <= t1, the line segment intersects the rectangle (or lies within it)\r\n return t0 <= t1\r\n}\r\n","import type { MousePosition, Point } from \"../types/types\"\r\n\r\n/**\r\n * Predicts the next mouse position based on a history of recent movements.\r\n * It calculates velocity from the historical data and extrapolates a future point.\r\n * The `history` array is mutated by this function: the new `currentPoint` is added,\r\n * and if the history exceeds `positionHistorySize`, the oldest entry is removed.\r\n *\r\n * @param currentPoint - The current actual mouse coordinates.\r\n * @param history - An array of previous mouse positions with timestamps.\r\n * This array will be modified by this function.\r\n * @param positionHistorySize - The maximum number of past positions to store and consider\r\n * for the prediction.\r\n * @param trajectoryPredictionTimeInMs - How far into the future (in milliseconds)\r\n * to predict the mouse position.\r\n * @returns The predicted {@link Point} (x, y coordinates). If history is insufficient\r\n * (less than 2 points) or time delta is zero, returns the `currentPoint`.\r\n */\r\nexport function predictNextMousePosition(\r\n currentPoint: Point,\r\n history: MousePosition[],\r\n positionHistorySize: number,\r\n trajectoryPredictionTimeInMs: number\r\n): Point {\r\n const now = performance.now()\r\n const currentPosition: MousePosition = { point: currentPoint, time: now }\r\n const { x, y } = currentPoint\r\n\r\n history.push(currentPosition)\r\n if (history.length > positionHistorySize) {\r\n history.shift()\r\n }\r\n\r\n if (history.length < 2) {\r\n return { x, y }\r\n }\r\n\r\n const first = history[0]\r\n const last = history[history.length - 1]\r\n const dt = (last.time - first.time) / 1000\r\n\r\n if (dt === 0) {\r\n return { x, y }\r\n }\r\n\r\n const dx = last.point.x - first.point.x\r\n const dy = last.point.y - first.point.y\r\n const vx = dx / dt\r\n const vy = dy / dt\r\n\r\n const trajectoryPredictionTimeInSeconds = trajectoryPredictionTimeInMs / 1000\r\n const predictedX = x + vx * trajectoryPredictionTimeInSeconds\r\n const predictedY = y + vy * trajectoryPredictionTimeInSeconds\r\n\r\n return { x: predictedX, y: predictedY }\r\n}\r\n","import type { HitSlop, Point, Rect } from \"../types/types\"\r\nimport { MAX_HITSLOP, MIN_HITSLOP } from \"../constants\"\r\nimport { clampNumber } from \"./clampNumber\"\r\n\r\n/**\r\n * Normalizes a `hitSlop` value into a {@link Rect} object.\r\n * If `hitSlop` is a number, it's applied uniformly to all sides (top, left, right, bottom).\r\n * If `hitSlop` is already a `Rect` object, it's returned as is.\r\n *\r\n * @param hitSlop - A number for uniform slop, or a {@link Rect} object for specific slop per side.\r\n * @returns A {@link Rect} object with `top`, `left`, `right`, and `bottom` properties.\r\n */\r\nexport function normalizeHitSlop(hitSlop: HitSlop): Rect {\r\n if (typeof hitSlop === \"number\") {\r\n const clampedValue = clampNumber(hitSlop, MIN_HITSLOP, MAX_HITSLOP, \"hitslop\")\r\n return {\r\n top: clampedValue,\r\n left: clampedValue,\r\n right: clampedValue,\r\n bottom: clampedValue,\r\n }\r\n }\r\n\r\n return {\r\n top: clampNumber(hitSlop.top, MIN_HITSLOP, MAX_HITSLOP, \"hitslop - top\"),\r\n left: clampNumber(hitSlop.left, MIN_HITSLOP, MAX_HITSLOP, \"hitslop - left\"),\r\n right: clampNumber(hitSlop.right, MIN_HITSLOP, MAX_HITSLOP, \"hitslop - right\"),\r\n bottom: clampNumber(hitSlop.bottom, MIN_HITSLOP, MAX_HITSLOP, \"hitslop - bottom\"),\r\n }\r\n}\r\n\r\n/**\r\n * Calculates an expanded rectangle by applying a `hitSlop` to a base rectangle.\r\n * The `hitSlop` values define how much to extend each side of the `baseRect` outwards.\r\n *\r\n * @param baseRect - The original {@link Rect} or `DOMRect` to expand.\r\n * @param hitSlop - A {@link Rect} object defining how much to expand each side\r\n * (e.g., `hitSlop.left` expands the left boundary further to the left).\r\n * @returns A new {@link Rect} object representing the expanded area.\r\n */\r\nexport function getExpandedRect(baseRect: Rect | DOMRect, hitSlop: Rect): Rect {\r\n return {\r\n left: baseRect.left - hitSlop.left,\r\n right: baseRect.right + hitSlop.right,\r\n top: baseRect.top - hitSlop.top,\r\n bottom: baseRect.bottom + hitSlop.bottom,\r\n }\r\n}\r\n\r\n/**\r\n * Checks if two rectangle objects are equal by comparing their respective\r\n * `top`, `left`, `right`, and `bottom` properties.\r\n * Handles cases where one or both rects might be null or undefined.\r\n *\r\n * @param rect1 - The first {@link Rect} object to compare.\r\n * @param rect2 - The second {@link Rect} object to compare.\r\n * @returns `true` if the rectangles have identical dimensions or if both are null/undefined,\r\n * `false` otherwise.\r\n */\r\nexport function areRectsEqual(rect1: Rect, rect2: Rect): boolean {\r\n if (!rect1 || !rect2) return rect1 === rect2\r\n return (\r\n rect1.left === rect2.left &&\r\n rect1.right === rect2.right &&\r\n rect1.top === rect2.top &&\r\n rect1.bottom === rect2.bottom\r\n )\r\n}\r\n\r\nexport function isPointInRectangle(point: Point, rect: Rect): boolean {\r\n return (\r\n point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom\r\n )\r\n}\r\n","/**\r\n * Checks if a setting should be updated.\r\n * Returns true if the newValue is defined and different from the currentValue.\r\n * Uses a type predicate to narrow the type of newValue in the calling scope.\r\n *\r\n * @param newValue The potentially new value for the setting (can be undefined).\r\n * @param currentValue The current value of the setting.\r\n * @returns True if the setting should be updated, false otherwise.\r\n */\r\nexport function shouldUpdateSetting<T>(\r\n newValue: T | undefined,\r\n currentValue: T\r\n): newValue is NonNullable<T> {\r\n // NonNullable<T> ensures that if T itself could be undefined (e.g. T = number | undefined),\r\n // the predicate narrows to the non-undefined part (e.g. number).\r\n // If T is already non-nullable (e.g. T = number), it remains T (e.g. number).\r\n return newValue !== undefined && currentValue !== newValue\r\n}\r\n","import type { FocusableElement } from \"tabbable\"\r\n\r\n/**\r\n * Finds the index of a focused element within a cache of tabbable elements.\r\n * It uses a predictive search for O(1) performance in the common case of\r\n * sequential tabbing, and falls back to a linear search O(n) if the\r\n * prediction fails.\r\n *\r\n * @param isReversed - True if the user is tabbing backward (Shift+Tab).\r\n * @param lastFocusedIndex - The index of the previously focused element, or null if none.\r\n * @param tabbableElementsCache - The array of all tabbable elements.\r\n * @param targetElement - The new HTML element that has received focus.\r\n * @returns The index of the targetElement in the cache, or -1 if not found.\r\n */\r\nexport function getFocusedElementIndex(\r\n isReversed: boolean,\r\n lastFocusedIndex: number | null,\r\n tabbableElementsCache: FocusableElement[],\r\n targetElement: HTMLElement\r\n): number {\r\n // First, try to predict the next index based on the last known position.\r\n if (lastFocusedIndex !== null) {\r\n const predictedIndex = isReversed ? lastFocusedIndex - 1 : lastFocusedIndex + 1\r\n\r\n // Check if the prediction is valid and correct.\r\n if (\r\n predictedIndex >= 0 &&\r\n predictedIndex < tabbableElementsCache.length &&\r\n tabbableElementsCache[predictedIndex] === targetElement\r\n ) {\r\n return predictedIndex\r\n }\r\n }\r\n\r\n // Slow way if we dont find it\r\n return tabbableElementsCache.findIndex((element) => element === targetElement)\r\n}\r\n","import type { Rect, ScrollDirection } from \"../types/types\"\r\n\r\nexport function getScrollDirection(oldRect: Rect, newRect: Rect): ScrollDirection {\r\n const scrollThreshold = 1\r\n const deltaY = newRect.top - oldRect.top\r\n const deltaX = newRect.left - oldRect.left\r\n\r\n // Check vertical scroll first (most common)\r\n if (deltaY < -scrollThreshold) {\r\n return \"down\" // Element moved up in viewport = scrolled down\r\n } else if (deltaY > scrollThreshold) {\r\n return \"up\" // Element moved down in viewport = scrolled up\r\n }\r\n\r\n // Check horizontal scroll\r\n if (deltaX < -scrollThreshold) {\r\n return \"right\" // Element moved left in viewport = scrolled right\r\n } else if (deltaX > scrollThreshold) {\r\n return \"left\" // Element moved right in viewport = scrolled left\r\n }\r\n\r\n return \"none\" // No significant movement detected\r\n}\r\n","import type { Point, ScrollDirection } from \"../types/types\"\r\n\r\nexport function predictNextScrollPosition(\r\n currentPoint: Point,\r\n direction: ScrollDirection,\r\n scrollMargin: number\r\n) {\r\n const { x, y } = currentPoint\r\n const predictedPoint = { x, y }\r\n\r\n switch (direction) {\r\n case \"down\":\r\n predictedPoint.y += scrollMargin\r\n break\r\n case \"up\":\r\n predictedPoint.y -= scrollMargin\r\n break\r\n case \"left\":\r\n predictedPoint.x -= scrollMargin\r\n break\r\n case \"right\":\r\n predictedPoint.x += scrollMargin\r\n break\r\n case \"none\":\r\n break\r\n default:\r\n direction satisfies never\r\n }\r\n return predictedPoint\r\n}\r\n","export function initialViewportState(rect: DOMRect) {\r\n const viewportWidth = window.innerWidth || document.documentElement.clientWidth\r\n const viewportHeight = window.innerHeight || document.documentElement.clientHeight\r\n\r\n return rect.top < viewportHeight && rect.bottom > 0 && rect.left < viewportWidth && rect.right > 0\r\n}\r\n"],"mappings":"yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,sBAAAE,IAAA,eAAAC,EAAAH,ICAA,IAAAI,EAAgD,oBCMzC,SAASC,GAAiD,CAC/D,IAAMC,EAAgBC,EAAoB,EACpCC,EAAsBC,EAAyB,EAErD,MAAO,CAAE,cAAAH,EAAe,oBAAAE,EAAqB,eADtB,CAACF,GAAiB,CAACE,CACkB,CAC9D,CAQA,SAASD,GAA+B,CACtC,OAAO,OAAO,WAAW,mBAAmB,EAAE,SAAW,UAAU,eAAiB,CACtF,CAWA,SAASE,GAAoC,CAC3C,IAAMC,EAAc,UAAkB,WACtC,OAAKA,EAEE,KAAK,KAAKA,EAAW,aAAa,GAAKA,EAAW,SAFjC,EAG1B,CCrCO,SAASC,EACdC,EACAC,EACAC,EACAC,EACA,CACA,OAAIH,EAASC,EACX,QAAQ,KACN,iBAAiBE,CAAW,WAAWH,CAAM,2BAA2BC,CAAU,iBAAiBA,CAAU,EAC/G,EACSD,EAASE,GAClB,QAAQ,KACN,iBAAiBC,CAAW,WAAWH,CAAM,2BAA2BE,CAAU,iBAAiBA,CAAU,EAC/G,EAGK,KAAK,IAAI,KAAK,IAAIF,EAAQC,CAAU,EAAGC,CAAU,CAC1D,CCNO,SAASE,EAA0BC,EAAWC,EAAWC,EAAqB,CACnF,IAAIC,EAAK,EACLC,EAAK,EACHC,EAAKJ,EAAG,EAAID,EAAG,EACfM,EAAKL,EAAG,EAAID,EAAG,EAEfO,EAAW,CAACC,EAAWC,IAAuB,CAClD,GAAID,IAAM,GAER,GAAIC,EAAI,EAAG,MAAO,OACb,CACL,IAAMC,EAAID,EAAID,EACd,GAAIA,EAAI,EAAG,CAET,GAA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,aAAc,KAAK,oBAAoB,aACvC,eAAgB,KAAK,qBACrB,gBAAiB,KAAK,eACxB,CAAC,CACH,CACF,CAEQ,2BAA4B,CAKlC,GAJI,KAAK,SAIL,OAAO,OAAW,KAAe,OAAO,SAAa,IACvD,OAGF,GAAM,CAAE,OAAAmD,CAAO,EAAI,KAAK,0BAExB,SAAS,iBAAiB,YAAa,KAAK,eAAe,EAC3D,SAAS,iBAAiB,UAAW,KAAK,cAAe,CAAE,OAAAA,CAAO,CAAC,EACnE,SAAS,iBAAiB,UAAW,KAAK,cAAe,CAAE,OAAAA,CAAO,CAAC,EAGnE,KAAK,YAAc,IAAI,iBAAiB,KAAK,kBAAkB,EAC/D,KAAK,YAAY,QAAQ,SAAS,gBAAiB,CACjD,UAAW,GACX,QAAS,GACT,WAAY,EACd,CAAC,EAMD,KAAK,iBAAmB,IAAI,mBAAiB,KAAK,oBAAoB,EAEtE,KAAK,QAAU,EACjB,CAEQ,uBAAwB,CAC9B,KAAK,QAAU,GAEf,KAAK,2BAA2B,MAAM,EACtC,KAAK,sBAAwB,CAAC,EAC9B,KAAK,iBAAmB,KACxB,KAAK,aAAa,WAAW,EAC7B,KAAK,YAAc,KACnB,KAAK,kBAAkB,WAAW,EAClC,KAAK,iBAAmB,KAGpB,KAAK,QACP,qBAAqB,KAAK,KAAK,EAC/B,KAAK,MAAQ,MAEf,KAAK,kBAAoB,IAC3B,CACF","names":["index_exports","__export","ForesightManager","__toCommonJS","import_tabbable","evaluateRegistrationConditions","isTouchDevice","userUsesTouchDevice","isLimitedConnection","hasConnectionLimitations","connection","clampNumber","number","lowerBound","upperBound","settingName","lineSegmentIntersectsRect","p1","p2","rect","t0","t1","dx","dy","clipTest","p","q","r","predictNextMousePosition","currentPoint","history","positionHistorySize","trajectoryPredictionTimeInMs","now","currentPosition","x","y","first","last","dt","dx","dy","vx","vy","trajectoryPredictionTimeInSeconds","predictedX","predictedY","normalizeHitSlop","hitSlop","clampedValue","clampNumber","getExpandedRect","baseRect","areRectsEqual","rect1","rect2","isPointInRectangle","point","rect","shouldUpdateSetting","newValue","currentValue","getFocusedElementIndex","isReversed","lastFocusedIndex","tabbableElementsCache","targetElement","predictedIndex","element","getScrollDirection","oldRect","newRect","deltaY","deltaX","predictNextScrollPosition","currentPoint","direction","scrollMargin","x","y","predictedPoint","import_position_observer","initialViewportState","rect","viewportWidth","viewportHeight","ForesightManager","_ForesightManager","mutationsList","mutation","element","targetElement","isReversed","currentIndex","getFocusedElementIndex","elementsToPredict","i","foresightElement","entries","entry","elementData","updatedProps","isNowIntersecting","updatedElementData","getExpandedRect","props","eventType","listener","options","listeners","index","event","error","callback","hitSlop","name","shouldRegister","isTouchDevice","isLimitedConnection","evaluateRegistrationConditions","initialRect","normalizedHitSlop","normalizeHitSlop","initialViewportState","unregisterReason","newValue","setting","min","max","shouldUpdateSetting","clampNumber","changedSettings","oldValue","newSize","oldHitSlop","normalizedNewHitSlop","areRectsEqual","_","currentPoint","predictNextMousePosition","currentData","expandedRect","lineSegmentIntersectsRect","isPointInRectangle","callbackHitType","start","errorMessage","newOriginalRect","newRect","getScrollDirection","predictNextScrollPosition","signal"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
|
|
3
|
-
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
4
|
-
*/
|
|
5
|
-
var t=["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])"].join(","),e="undefined"==typeof Element,i=e?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,n=!e&&Element.prototype.getRootNode?function(t){var e;return null==t||null===(e=t.getRootNode)||void 0===e?void 0:e.call(t)}:function(t){return null==t?void 0:t.ownerDocument},o=function t(e,i){var n;void 0===i&&(i=!0);var o=null==e||null===(n=e.getAttribute)||void 0===n?void 0:n.call(e,"inert");return""===o||"true"===o||i&&e&&t(e.parentNode)},s=function e(n,s,r){for(var l=[],a=Array.from(n);a.length;){var c=a.shift();if(!o(c,!1))if("SLOT"===c.tagName){var h=c.assignedElements(),u=e(h.length?h:c.children,!0,r);r.flatten?l.push.apply(l,u):l.push({scopeParent:c,candidates:u})}else{i.call(c,t)&&r.filter(c)&&(s||!n.includes(c))&&l.push(c);var d=c.shadowRoot||"function"==typeof r.getShadowRoot&&r.getShadowRoot(c),g=!o(d,!1)&&(!r.shadowRootFilter||r.shadowRootFilter(c));if(d&&g){var b=e(!0===d?c.children:d.children,!0,r);r.flatten?l.push.apply(l,b):l.push({scopeParent:c,candidates:b})}else a.unshift.apply(a,c.children)}}return l},r=function(t){return!isNaN(parseInt(t.getAttribute("tabindex"),10))},l=function(t){if(!t)throw new Error("No node provided");return t.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(t.tagName)||function(t){var e,i=null==t||null===(e=t.getAttribute)||void 0===e?void 0:e.call(t,"contenteditable");return""===i||"true"===i}(t))&&!r(t)?0:t.tabIndex},a=function(t,e){return t.tabIndex===e.tabIndex?t.documentOrder-e.documentOrder:t.tabIndex-e.tabIndex},c=function(t){return"INPUT"===t.tagName},h=function(t){return function(t){return c(t)&&"radio"===t.type}(t)&&!function(t){if(!t.name)return!0;var e,i=t.form||n(t),o=function(t){return i.querySelectorAll('input[type="radio"][name="'+t+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)e=o(window.CSS.escape(t.name));else try{e=o(t.name)}catch(t){return 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",t.message),!1}var s=function(t,e){for(var i=0;i<t.length;i++)if(t[i].checked&&t[i].form===e)return t[i]}(e,t.form);return!s||s===t}(t)},u=function(t){var e=t.getBoundingClientRect(),i=e.width,n=e.height;return 0===i&&0===n},d=function(t,e){var o=e.displayCheck,s=e.getShadowRoot;if("hidden"===getComputedStyle(t).visibility)return!0;var r=i.call(t,"details>summary:first-of-type")?t.parentElement:t;if(i.call(r,"details:not([open]) *"))return!0;if(o&&"full"!==o&&"legacy-full"!==o){if("non-zero-area"===o)return u(t)}else{if("function"==typeof s){for(var l=t;t;){var a=t.parentElement,c=n(t);if(a&&!a.shadowRoot&&!0===s(a))return u(t);t=t.assignedSlot?t.assignedSlot:a||c===t.ownerDocument?a:c.host}t=l}if(function(t){var e,i,o,s,r=t&&n(t),l=null===(e=r)||void 0===e?void 0:e.host,a=!1;if(r&&r!==t)for(a=!!(null!==(i=l)&&void 0!==i&&null!==(o=i.ownerDocument)&&void 0!==o&&o.contains(l)||null!=t&&null!==(s=t.ownerDocument)&&void 0!==s&&s.contains(t));!a&&l;){var c,h,u;a=!(null===(h=l=null===(c=r=n(l))||void 0===c?void 0:c.host)||void 0===h||null===(u=h.ownerDocument)||void 0===u||!u.contains(l))}return a}(t))return!t.getClientRects().length;if("legacy-full"!==o)return!0}return!1},g=function(t,e){return!(e.disabled||o(e)||function(t){return c(t)&&"hidden"===t.type}(e)||d(e,t)||function(t){return"DETAILS"===t.tagName&&Array.prototype.slice.apply(t.children).some(function(t){return"SUMMARY"===t.tagName})}(e)||function(t){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(t.tagName))for(var e=t.parentElement;e;){if("FIELDSET"===e.tagName&&e.disabled){for(var n=0;n<e.children.length;n++){var o=e.children.item(n);if("LEGEND"===o.tagName)return!!i.call(e,"fieldset[disabled] *")||!o.contains(t)}return!0}e=e.parentElement}return!1}(e))},b=function(t,e){return!(h(e)||l(e)<0||!g(t,e))},p=function(t){var e=parseInt(t.getAttribute("tabindex"),10);return!!(isNaN(e)||e>=0)},f=function t(e){var i=[],n=[];return e.forEach(function(e,o){var s=!!e.scopeParent,a=s?e.scopeParent:e,c=function(t,e){var i=l(t);return i<0&&e&&!r(t)?0:i}(a,s),h=s?t(e.candidates):a;0===c?s?i.push.apply(i,h):i.push(a):n.push({documentOrder:o,tabIndex:c,item:e,isScope:s,content:h})}),n.sort(a).reduce(function(t,e){return e.isScope?t.push.apply(t,e.content):t.push(e.content),t},[]).concat(i)},m=function(e,n){var r;return r=(n=n||{}).getShadowRoot?s([e],n.includeContainer,{filter:b.bind(null,n),flatten:!1,getShadowRoot:n.getShadowRoot,shadowRootFilter:p}):function(e,n,s){if(o(e))return[];var r=Array.prototype.slice.apply(e.querySelectorAll(t));return n&&i.call(e,t)&&r.unshift(e),r.filter(s)}(e,n.includeContainer,b.bind(null,n)),f(r)};function v(){const t=window.matchMedia("(pointer: coarse)").matches&&navigator.maxTouchPoints>0,e=function(){const t=navigator.connection;return!!t&&(/2g/.test(t.effectiveType)||t.saveData)}();return{isTouchDevice:t,isLimitedConnection:e,shouldRegister:!t&&!e}}const y=2e3;function S(t,e,i,n){return t<e?console.warn(`ForesightJS: "${n}" value ${t} is below minimum bound ${e}, clamping to ${e}`):t>i&&console.warn(`ForesightJS: "${n}" value ${t} is above maximum bound ${i}, clamping to ${i}`),Math.min(Math.max(t,e),i)}function w(t,e,i){let n=0,o=1;const s=e.x-t.x,r=e.y-t.y,l=(t,e)=>{if(0===t){if(e<0)return!1}else{const i=e/t;if(t<0){if(i>o)return!1;i>n&&(n=i)}else{if(i<n)return!1;i<o&&(o=i)}}return!0};return!!l(-s,t.x-i.left)&&(!!l(s,i.right-t.x)&&(!!l(-r,t.y-i.top)&&(!!l(r,i.bottom-t.y)&&n<=o)))}function R(t){if("number"==typeof t){const e=S(t,0,y,"hitslop");return{top:e,left:e,right:e,bottom:e}}return{top:S(t.top,0,y,"hitslop - top"),left:S(t.left,0,y,"hitslop - left"),right:S(t.right,0,y,"hitslop - right"),bottom:S(t.bottom,0,y,"hitslop - bottom")}}function C(t,e){return{left:t.left-e.left,right:t.right+e.right,top:t.top-e.top,bottom:t.bottom+e.bottom}}function P(t,e){return t&&e?t.left===e.left&&t.right===e.right&&t.top===e.top&&t.bottom===e.bottom:t===e}function E(t,e){return t.x>=e.left&&t.x<=e.right&&t.y>=e.top&&t.y<=e.bottom}function O(t,e){return void 0!==t&&e!==t}var D=class{static intersect(t,e){const i=Math.max(t.left,e.left),n=Math.min(t.right,e.right),o=Math.max(t.top,e.top),s=Math.min(t.bottom,e.bottom),r=Math.max(0,n-i),l=Math.max(0,s-o);return new DOMRect(i,o,r,l)}static clip(t,e){const i={...t.toJSON(),top:t.top+e.top,left:t.left+e.left,bottom:t.bottom-e.bottom,right:t.right-e.right};return i.width=i.right-i.left,i.height=i.bottom-i.top,i}static clipOffsets(t,e){return{top:e.top-t.top,left:e.left-t.left,bottom:t.bottom-e.bottom,right:t.right-e.right}}static equals(t,e){return null==t||null==e?t===e:t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}static sizeEqual(t,e){return Math.round(t.width)===Math.round(e.width)&&Math.round(t.height)===Math.round(e.height)}};function x(t,e){const i=Math.max(t.width,3),n=Math.max(t.height,3),o=t.top-e.top- -1,s=t.left-e.left- -1,r=e.right-t.left-i- -1,l=e.bottom-t.top-n- -1;return`${-Math.round(o)}px ${-Math.round(r)}px ${-Math.round(l)}px ${-Math.round(s)}px`}var B=[...Array.from({length:1e3},(t,e)=>e/1e3),1],k=class{constructor(t,e,i){this.#t=e,this.#e=i,this.#i=i.clientRect,this.#n(t)}#t;#o=void 0;#e;#i;#s=void 0;get visibleRect(){const t=this.#e.clip;return t?D.clip(this.#i,t):this.#i}get isIntersecting(){const{width:t,height:e}=this.visibleRect;return t>0&&e>0}#n(t){const{root:e,rootBounds:i}=this.#e,{visibleRect:n}=this;this.#o?.disconnect(),this.#o=new IntersectionObserver(this.#r,{root:e,rootMargin:x(n,i),threshold:B}),this.#o.observe(t)}#r=t=>{if(!this.#o)return;const e=t[t.length-1];if(e){const{intersectionRatio:t,boundingClientRect:i}=e,n=this.#i;this.#i=i;const o=this.#s,s=!D.equals(i,n);if(t!==this.#s||s){const n=this.#e.rootBounds,r=D.intersect(i,n),l=r.width>0&&r.height>0;if(!l)return;this.#s=t,(null!=o||s)&&(this.#t(new M(e.target,i,e.intersectionRect,l,n),this),this.#n(e.target))}}};disconnect(){this.#o?.disconnect()}},M=class{constructor(t,e,i,n,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=i,this.isIntersecting=n,this.rootBounds=o}},I=class{constructor(t,e){const i=function(t){return!t||function(t){return t.nodeType===Node.DOCUMENT_NODE}(t)?t?.defaultView??window:t}(t);if(function(t){return L(t)&&t.nodeType===Node.ELEMENT_NODE}(i)){const t=i.ownerDocument??document;this.rootBounds=i.getBoundingClientRect(),this.#l=new ResizeObserver(t=>{for(const i of t){const[{inlineSize:t,blockSize:n}]=i.borderBoxSize;if(D.sizeEqual(this.rootBounds,{width:t,height:n}))continue;const o=i.target.getBoundingClientRect();this.rootBounds=o,e(o,this)}}),this.#l.observe(i),t.addEventListener("scroll",t=>{t.target&&t.target!==i&&L(t.target)&&t.target.contains(i)&&(this.rootBounds=i.getBoundingClientRect(),e(this.rootBounds,this))},{capture:!0,passive:!0,signal:this.#a.signal})}else{const t=i.visualViewport??i;this.rootBounds=T(i);const n=()=>{const t=T(i);D.equals(this.rootBounds,t)||(this.rootBounds=t,e(t,this))};t.addEventListener("resize",n,{signal:this.#a.signal})}}#l;#a=new AbortController;rootBounds;disconnect(){this.#l?.disconnect(),this.#a.abort()}};function T(t){const e=t.visualViewport?.width??t.innerWidth,i=t.visualViewport?.height??t.innerHeight;return new DOMRect(0,0,e,i)}function L(t){return"nodeType"in t}var z=class{constructor(t,e){this.#e=e,this.#t=e=>{const i=[];for(const t of e){const e=this.intersections.get(t.target);this.intersections.set(t.target,t),e?.isIntersecting===t.isIntersecting&&D.equals(e?.intersectionRect,t.intersectionRect)||i.push(t)}i.length>0&&t(i,this)}}#t;#c=new Map;#e;intersections=new WeakMap;observe(t){const e=t.ownerDocument;if(!e)return;let i=this.#c.get(e);i||(i=new IntersectionObserver(this.#t,{...this.#e,threshold:B}),this.#c.set(e,i)),i.observe(t)}unobserve(t){const e=t.ownerDocument;if(!e)return;const i=this.#c.get(e);i&&(i.unobserve(t),this.intersections.delete(t))}disconnect(){for(const t of this.#c.values())t.disconnect();this.#c.clear()}},j=class{constructor(t,e){this.#t=t,this.#e=e,this.#h=new I(e?.root,this.#u),this.#d=new z(this.#g,e),this.#l=new ResizeObserver(this.#b)}#t;#e;#p=new Map;#l;#f=new WeakMap;#h;#d;observe(t){this.#d.observe(t)}unobserve(t){t?(this.#p.get(t)?.disconnect(),this.#d.unobserve(t)):this.disconnect()}disconnect(){for(const t of this.#p.values())t.disconnect();this.#l.disconnect(),this.#h.disconnect(),this.#d.disconnect()}#m(t){const e=[];for(const i of t){const{target:t}=i;N(i,this.#f.get(t))||(this.#f.set(t,i),e.push(i))}e.length>0&&this.#t(e)}#u=t=>{const e=[];for(const[i]of this.#p){const n=i.getBoundingClientRect(),o=this.#v(i,n);e.push(new H(i,n,o.visibleRect,o.isIntersecting,t))}this.#m(e)};#v(t,e){const i=this.#d;this.#p.get(t)?.disconnect();const n=new k(t,this.#y,{clientRect:e,root:this.#e?.root,rootBounds:this.#h.rootBounds,get clip(){const e=i.intersections.get(t);if(!e)return;const{intersectionRect:n,boundingClientRect:o}=e;return D.clipOffsets(o,n)}});return this.#p.set(t,n),n}#g=t=>{const e=[];for(const i of t){const{target:t,isIntersecting:n,boundingClientRect:o}=i;n?(this.#v(t,o),this.#l.observe(t)):(this.#p.get(t)?.disconnect(),this.#p.delete(t),this.#l.unobserve(t));const s=this.#p.get(t);e.push(new H(t,o,s?.visibleRect??i.intersectionRect,n,this.#h.rootBounds))}this.#m(e)};#y=(t,e)=>{this.#m([new H(t.target,t.boundingClientRect,e.visibleRect,t.isIntersecting,this.#h.rootBounds)])};#b=t=>{const e=[];for(const i of t){const{target:t,borderBoxSize:n}=i,o=this.#f.get(t);if(o){const[{inlineSize:t,blockSize:e}]=n;if(D.sizeEqual(o.boundingClientRect,{width:t,height:e}))continue}const s=t.getBoundingClientRect(),r=this.#v(t,s);e.push(new H(t,s,r.visibleRect,this.#d.intersections.get(t)?.isIntersecting??!1,this.#h.rootBounds))}this.#m(e)}},H=class{constructor(t,e,i,n,o){this.target=t,this.boundingClientRect=e,this.intersectionRect=i,this.isIntersecting=n,this.rootBounds=o}};function N(t,e){return null!=e&&(t.target===e.target&&t.isIntersecting===e.isIntersecting&&D.equals(t.boundingClientRect,e.boundingClientRect)&&D.equals(t.intersectionRect,e.intersectionRect))}class _{constructor(){this.elements=new Map,this.isSetup=!1,this._globalCallbackHits={mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0},this._globalSettings={debug:!1,enableMousePrediction:true,enableScrollPrediction:true,positionHistorySize:8,trajectoryPredictionTime:120,scrollMargin:150,defaultHitSlop:{top:0,left:0,right:0,bottom:0},enableTabPrediction:true,tabOffset:2,onAnyCallbackFired:(t,e)=>{}},this.trajectoryPositions={positions:[],currentPoint:{x:0,y:0},predictedPoint:{x:0,y:0}},this.tabbableElementsCache=[],this.lastFocusedIndex=null,this.predictedScrollPoint=null,this.scrollDirection=null,this.domObserver=null,this.positionObserver=null,this.lastKeyDown=null,this.globalListenersController=null,this.eventListeners=new Map,this.handleMouseMove=t=>{this.updatePointerState(t),this.elements.forEach(t=>{t.isIntersectingWithViewport&&this.handleCallbackInteraction(t)}),this.emit({type:"mouseTrajectoryUpdate",predictionEnabled:this._globalSettings.enableMousePrediction,timestamp:Date.now(),trajectoryPositions:this.trajectoryPositions})},this.handleDomMutations=t=>{t.length&&(this.tabbableElementsCache=[],this.lastFocusedIndex=null);for(const e of t)if("childList"===e.type&&e.removedNodes.length>0)for(const t of Array.from(this.elements.keys()))t.isConnected||this.unregister(t,"disconnected")},this.handleKeyDown=t=>{"Tab"===t.key&&(this.lastKeyDown=t)},this.handleFocusIn=t=>{if(!this.lastKeyDown||!this._globalSettings.enableTabPrediction)return;const e=t.target;if(!(e instanceof HTMLElement))return;this.tabbableElementsCache.length||(this.tabbableElementsCache=m(document.documentElement));const i=this.lastKeyDown.shiftKey,n=function(t,e,i,n){if(null!==e){const o=t?e-1:e+1;if(o>=0&&o<i.length&&i[o]===n)return o}return i.findIndex(t=>t===n)}(i,this.lastFocusedIndex,this.tabbableElementsCache,e);this.lastFocusedIndex=n,this.lastKeyDown=null;const o=[];for(let t=0;t<=this._globalSettings.tabOffset;t++)if(i){const e=this.tabbableElementsCache[n-t];this.elements.has(e)&&o.push(e)}else{const e=this.tabbableElementsCache[n+t];this.elements.has(e)&&o.push(e)}o.forEach(t=>{this.callCallback(this.elements.get(t),{kind:"tab",subType:i?"reverse":"forwards"})})},this.handlePositionChange=t=>{for(const e of t){const t=this.elements.get(e.target);if(!t)continue;const i=t.isIntersectingWithViewport,n=e.isIntersecting;t.isIntersectingWithViewport=n,i!==n&&this.emit({type:"elementDataUpdated",elementData:t,timestamp:Date.now(),updatedProp:"visibility"}),n&&(this.updateElementBounds(e.boundingClientRect,t),this.handleScrollPrefetch(t,e.boundingClientRect))}this.scrollDirection=null,this.predictedScrollPoint=null}}static initialize(t){return this.isInitiated||(_.manager=new _),void 0!==t&&_.manager.alterGlobalSettings(t),_.manager}addEventListener(t,e,i){if(i?.signal?.aborted)return()=>{};this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e),i?.signal?.addEventListener("abort",()=>this.removeEventListener(t,e))}removeEventListener(t,e){const i=this.eventListeners.get(t);if(i){const t=i.indexOf(e);t>-1&&i.splice(t,1)}}logSubscribers(){console.log("%c[ForesightManager] Current Subscribers:","font-weight: bold; color: #3b82f6;");const t=Array.from(this.eventListeners.keys());0!==t.length?t.forEach(t=>{const e=this.eventListeners.get(t);e&&e.length>0&&(console.groupCollapsed(`Event: %c${t}`,"font-weight: bold;",`(${e.length} listener${e.length>1?"s":""})`),e.forEach((t,e)=>{console.log(`[${e}]:`,t)}),console.groupEnd())}):console.log(" No active subscribers.")}emit(t){const e=this.eventListeners.get(t.type);e&&e.forEach(e=>{try{e(t)}catch(e){console.error(`Error in ForesightManager event listener for ${t.type}:`,e)}})}get getManagerData(){return{registeredElements:this.elements,globalSettings:this._globalSettings,globalCallbackHits:this._globalCallbackHits}}static get isInitiated(){return!!_.manager}static get instance(){return this.initialize()}get registeredElements(){return this.elements}register({element:t,callback:e,hitSlop:i,name:n}){const{shouldRegister:o,isTouchDevice:s,isLimitedConnection:r}=v();if(!o)return{isLimitedConnection:r,isTouchDevice:s,isRegistered:!1,unregister:()=>{}};this.isSetup||this.initializeGlobalListeners();const l=i?R(i):this._globalSettings.defaultHitSlop,a={element:t,callback:e,elementBounds:{originalRect:void 0,expandedRect:{top:0,left:0,right:0,bottom:0},hitSlop:l},isHovering:!1,trajectoryHitData:{isTrajectoryHit:!1,trajectoryHitTime:0,trajectoryHitExpirationTimeoutId:void 0},name:n??t.id??"",isIntersectingWithViewport:!0};return this.elements.set(t,a),this.positionObserver?.observe(t),this.emit({type:"elementRegistered",timestamp:Date.now(),elementData:a}),{isTouchDevice:s,isLimitedConnection:r,isRegistered:!0,unregister:()=>this.unregister(t,"apiCall")}}unregister(t,e){if(!this.elements.has(t))return;const i=this.elements.get(t);i&&this.emit({type:"elementUnregistered",elementData:i,timestamp:Date.now(),unregisterReason:e}),i?.trajectoryHitData.trajectoryHitExpirationTimeoutId&&clearTimeout(i.trajectoryHitData.trajectoryHitExpirationTimeoutId),this.positionObserver?.unobserve(t),this.elements.delete(t),0===this.elements.size&&this.isSetup&&this.removeGlobalListeners()}updateNumericSettings(t,e,i,n){return!!O(t,this._globalSettings[e])&&(this._globalSettings[e]=S(t,i,n,e),!0)}updateBooleanSetting(t,e){return!!O(t,this._globalSettings[e])&&(this._globalSettings[e]=t,!0)}alterGlobalSettings(t){const e=this._globalSettings.positionHistorySize,i=this.updateNumericSettings(t?.positionHistorySize,"positionHistorySize",2,30);i&&this._globalSettings.positionHistorySize<e&&this.trajectoryPositions.positions.length>this._globalSettings.positionHistorySize&&(this.trajectoryPositions.positions=this.trajectoryPositions.positions.slice(this.trajectoryPositions.positions.length-this._globalSettings.positionHistorySize));const n=this.updateNumericSettings(t?.trajectoryPredictionTime,"trajectoryPredictionTime",10,200),o=this.updateNumericSettings(t?.scrollMargin,"scrollMargin",30,300),s=this.updateNumericSettings(t?.tabOffset,"tabOffset",0,20),r=this.updateBooleanSetting(t?.enableMousePrediction,"enableMousePrediction"),l=this.updateBooleanSetting(t?.enableScrollPrediction,"enableScrollPrediction"),a=this.updateBooleanSetting(t?.enableTabPrediction,"enableTabPrediction");void 0!==t?.onAnyCallbackFired&&(this._globalSettings.onAnyCallbackFired=t.onAnyCallbackFired);let c=!1;if(void 0!==t?.defaultHitSlop){const e=R(t.defaultHitSlop);P(this._globalSettings.defaultHitSlop,e)||(this._globalSettings.defaultHitSlop=e,c=!0,this.forceUpdateAllElementBounds())}(i||n||s||r||a||l||c||o)&&this.emit({type:"managerSettingsChanged",timestamp:Date.now(),managerData:this.getManagerData})}forceUpdateAllElementBounds(){this.elements.forEach((t,e)=>{const i=this.elements.get(e);i&&i.isIntersectingWithViewport&&this.forceUpdateElementBounds(i)})}updatePointerState(t){this.trajectoryPositions.currentPoint={x:t.clientX,y:t.clientY},this.trajectoryPositions.predictedPoint=this._globalSettings.enableMousePrediction?function(t,e,i,n){const o={point:t,time:performance.now()},{x:s,y:r}=t;if(e.push(o),e.length>i&&e.shift(),e.length<2)return{x:s,y:r};const l=e[0],a=e[e.length-1],c=(a.time-l.time)/1e3;if(0===c)return{x:s,y:r};const h=n/1e3;return{x:s+(a.point.x-l.point.x)/c*h,y:r+(a.point.y-l.point.y)/c*h}}(this.trajectoryPositions.currentPoint,this.trajectoryPositions.positions,this._globalSettings.positionHistorySize,this._globalSettings.trajectoryPredictionTime):{...this.trajectoryPositions.currentPoint}}handleCallbackInteraction(t){const{expandedRect:e}=t.elementBounds;if(this._globalSettings.enableMousePrediction)w(this.trajectoryPositions.currentPoint,this.trajectoryPositions.predictedPoint,e)&&this.callCallback(t,{kind:"mouse",subType:"trajectory"});else if(E(this.trajectoryPositions.currentPoint,e))return void this.callCallback(t,{kind:"mouse",subType:"hover"})}updateHitCounters(t,e){switch(e.kind){case"mouse":this._globalCallbackHits.mouse[e.subType]++;break;case"tab":this._globalCallbackHits.tab[e.subType]++;break;case"scroll":this._globalCallbackHits.scroll[e.subType]++}this._globalCallbackHits.total++}callCallback(t,e){t&&(this.updateHitCounters(t,e),t.callback(),this._globalSettings.onAnyCallbackFired(t,this.getManagerData),this.emit({type:"callbackFired",timestamp:Date.now(),elementData:t,hitType:e,managerData:this.getManagerData}),this.unregister(t.element,"callbackHit"))}forceUpdateElementBounds(t){const e=t.element.getBoundingClientRect(),i=C(e,t.elementBounds.hitSlop);if(!P(i,t.elementBounds.expandedRect)){const n={...t,elementBounds:{...t.elementBounds,originalRect:e,expandedRect:i}};this.elements.set(t.element,n),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:n,updatedProp:"bounds"})}}updateElementBounds(t,e){const i={...e,elementBounds:{...e.elementBounds,originalRect:t,expandedRect:C(t,e.elementBounds.hitSlop)}};this.elements.set(e.element,i),this.emit({type:"elementDataUpdated",timestamp:Date.now(),elementData:i,updatedProp:"bounds"})}handleScrollPrefetch(t,e){if(this._globalSettings.enableScrollPrediction){if(!t.elementBounds.originalRect)return;if(this.scrollDirection=this.scrollDirection??function(t,e){const i=e.top-t.top,n=e.left-t.left;return i<-1?"down":i>1?"up":n<-1?"right":n>1?"left":"none"}(t.elementBounds.originalRect,e),"none"===this.scrollDirection)return;this.predictedScrollPoint=this.predictedScrollPoint??function(t,e,i){const{x:n,y:o}=t,s={x:n,y:o};switch(e){case"down":s.y+=i;break;case"up":s.y-=i;break;case"left":s.x-=i;break;case"right":s.x+=i}return s}(this.trajectoryPositions.currentPoint,this.scrollDirection,this._globalSettings.scrollMargin),w(this.trajectoryPositions.currentPoint,this.predictedScrollPoint,t?.elementBounds.expandedRect)&&this.callCallback(t,{kind:"scroll",subType:this.scrollDirection}),this.emit({type:"scrollTrajectoryUpdate",timestamp:Date.now(),currentPoint:this.trajectoryPositions.currentPoint,predictedPoint:this.predictedScrollPoint})}else E(this.trajectoryPositions.currentPoint,t.elementBounds.expandedRect)&&this.callCallback(t,{kind:"mouse",subType:"hover"})}initializeGlobalListeners(){if(this.isSetup)return;if("undefined"==typeof window||"undefined"==typeof document)return;this.globalListenersController=new AbortController;const{signal:t}=this.globalListenersController;document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("keydown",this.handleKeyDown,{signal:t}),document.addEventListener("focusin",this.handleFocusIn,{signal:t}),this.domObserver=new MutationObserver(this.handleDomMutations),this.domObserver.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1}),this.positionObserver=new j(this.handlePositionChange),this.isSetup=!0}removeGlobalListeners(){this.isSetup=!1,this.globalListenersController?.abort(),this.globalListenersController=null,this.domObserver?.disconnect(),this.domObserver=null,this.positionObserver?.disconnect(),this.positionObserver=null}}export{_ as ForesightManager};
|
|
6
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{tabbable as q}from"tabbable";function R(){let i=A(),e=H();return{isTouchDevice:i,isLimitedConnection:e,shouldRegister:!i&&!e}}function A(){return window.matchMedia("(pointer: coarse)").matches&&navigator.maxTouchPoints>0}function H(){let i=navigator.connection;return i?/2g/.test(i.effectiveType)||i.saveData:!1}function d(i,e,t,n){return i<e?console.warn(`ForesightJS: "${n}" value ${i} is below minimum bound ${e}, clamping to ${e}`):i>t&&console.warn(`ForesightJS: "${n}" value ${i} is above maximum bound ${t}, clamping to ${t}`),Math.min(Math.max(i,e),t)}function f(i,e,t){let n=0,o=1,s=e.x-i.x,r=e.y-i.y,a=(l,u)=>{if(l===0){if(u<0)return!1}else{let c=u/l;if(l<0){if(c>o)return!1;c>n&&(n=c)}else{if(c<n)return!1;c<o&&(o=c)}}return!0};return!a(-s,i.x-t.left)||!a(s,t.right-i.x)||!a(-r,i.y-t.top)||!a(r,t.bottom-i.y)?!1:n<=o}function P(i,e,t,n){let o=performance.now(),s={point:i,time:o},{x:r,y:a}=i;if(e.push(s),e.length>t&&e.shift(),e.length<2)return{x:r,y:a};let l=e[0],u=e[e.length-1],c=(u.time-l.time)/1e3;if(c===0)return{x:r,y:a};let g=u.point.x-l.point.x,O=u.point.y-l.point.y,x=g/c,D=O/c,I=n/1e3,L=r+x*I,N=a+D*I;return{x:L,y:N}}function E(i){if(typeof i=="number"){let e=d(i,0,2e3,"hitslop");return{top:e,left:e,right:e,bottom:e}}return{top:d(i.top,0,2e3,"hitslop - top"),left:d(i.left,0,2e3,"hitslop - left"),right:d(i.right,0,2e3,"hitslop - right"),bottom:d(i.bottom,0,2e3,"hitslop - bottom")}}function m(i,e){return{left:i.left-e.left,right:i.right+e.right,top:i.top-e.top,bottom:i.bottom+e.bottom}}function S(i,e){return!i||!e?i===e:i.left===e.left&&i.right===e.right&&i.top===e.top&&i.bottom===e.bottom}function v(i,e){return i.x>=e.left&&i.x<=e.right&&i.y>=e.top&&i.y<=e.bottom}function T(i,e){return i!==void 0&&e!==i}function _(i,e,t,n){if(e!==null){let o=i?e-1:e+1;if(o>=0&&o<t.length&&t[o]===n)return o}return t.findIndex(o=>o===n)}function M(i,e){let n=e.top-i.top,o=e.left-i.left;return n<-1?"down":n>1?"up":o<-1?"right":o>1?"left":"none"}function F(i,e,t){let{x:n,y:o}=i,s={x:n,y:o};switch(e){case"down":s.y+=t;break;case"up":s.y-=t;break;case"left":s.x-=t;break;case"right":s.x+=t;break;case"none":break;default:}return s}import{PositionObserver as Q}from"position-observer";function C(i){let e=window.innerWidth||document.documentElement.clientWidth,t=window.innerHeight||document.documentElement.clientHeight;return i.top<t&&i.bottom>0&&i.left<e&&i.right>0}var y=class i{constructor(){this.elements=new Map;this.isSetup=!1;this._globalCallbackHits={mouse:{hover:0,trajectory:0},tab:{forwards:0,reverse:0},scroll:{down:0,left:0,right:0,up:0},total:0};this._globalSettings={debug:!1,enableMousePrediction:!0,enableScrollPrediction:!0,positionHistorySize:8,trajectoryPredictionTime:120,scrollMargin:150,defaultHitSlop:{top:0,left:0,right:0,bottom:0},enableTabPrediction:!0,tabOffset:2};this.trajectoryPositions={positions:[],currentPoint:{x:0,y:0},predictedPoint:{x:0,y:0}};this.tabbableElementsCache=[];this.lastFocusedIndex=null;this.predictedScrollPoint=null;this.scrollDirection=null;this.domObserver=null;this.positionObserver=null;this.lastKeyDown=null;this.globalListenersController=new AbortController;this.rafId=null;this.pendingMouseEvent=null;this.eventListeners=new Map;this.handleMouseMove=e=>{this.pendingMouseEvent=e,!this.rafId&&(this.rafId=requestAnimationFrame(()=>{this.pendingMouseEvent&&(this.processMouseMovement(this.pendingMouseEvent),this.pendingMouseEvent=null),this.rafId=null}))};this.handleDomMutations=e=>{e.length&&(this.tabbableElementsCache=[],this.lastFocusedIndex=null);for(let t of e)if(t.type==="childList"&&t.removedNodes.length>0)for(let n of this.elements.keys())n.isConnected||this.unregister(n,"disconnected")};this.handleKeyDown=e=>{e.key==="Tab"&&(this.lastKeyDown=e)};this.handleFocusIn=e=>{if(!this.lastKeyDown||!this._globalSettings.enableTabPrediction)return;let t=e.target;if(!(t instanceof HTMLElement))return;this.tabbableElementsCache.length||(this.tabbableElementsCache=q(document.documentElement));let n=this.lastKeyDown.shiftKey,o=_(n,this.lastFocusedIndex,this.tabbableElementsCache,t);this.lastFocusedIndex=o,this.lastKeyDown=null;let s=[];for(let r=0;r<=this._globalSettings.tabOffset;r++)if(n){let a=this.tabbableElementsCache[o-r];this.elements.has(a)&&s.push(a)}else{let a=this.tabbableElementsCache[o+r];this.elements.has(a)&&s.push(a)}s.forEach(r=>{let a=this.elements.get(r);a&&this.callCallback(a,{kind:"tab",subType:n?"reverse":"forwards"})})};this.handlePositionChange=e=>{for(let t of e){let n=this.elements.get(t.target);n&&(this.handlePositionChangeDataUpdates(n,t),this.handleScrollPrefetch(n,t.boundingClientRect))}this.scrollDirection=null,this.predictedScrollPoint=null};this.handlePositionChangeDataUpdates=(e,t)=>{let n=[],o=t.isIntersecting,s={...e,isIntersectingWithViewport:o};e.isIntersectingWithViewport!==o&&n.push("visibility"),o&&(n.push("bounds"),this.handleScrollPrefetch(s,t.boundingClientRect),s={...s,elementBounds:{hitSlop:e.elementBounds.hitSlop,originalRect:t.boundingClientRect,expandedRect:m(t.boundingClientRect,e.elementBounds.hitSlop)}}),this.elements.set(e.element,s),n.length&&this.emit({type:"elementDataUpdated",elementData:s,updatedProps:n})}}static initialize(e){return this.isInitiated||(i.manager=new i),e!==void 0&&i.manager.alterGlobalSettings(e),i.manager}addEventListener(e,t,n){if(n?.signal?.aborted)return()=>{};let o=this.eventListeners.get(e)??[];o.push(t),this.eventListeners.set(e,o),n?.signal?.addEventListener("abort",()=>this.removeEventListener(e,t))}removeEventListener(e,t){let n=this.eventListeners.get(e);if(!n)return;let o=n.indexOf(t);o>-1&&n.splice(o,1)}emit(e){let t=this.eventListeners.get(e.type);t&&t.forEach(n=>{try{n(e)}catch(o){console.error(`Error in ForesightManager event listener for ${e.type}:`,o)}})}get getManagerData(){return{registeredElements:this.elements,globalSettings:this._globalSettings,globalCallbackHits:this._globalCallbackHits,eventListeners:this.eventListeners}}static get isInitiated(){return!!i.manager}static get instance(){return this.initialize()}get registeredElements(){return this.elements}register({element:e,callback:t,hitSlop:n,name:o}){let{shouldRegister:s,isTouchDevice:r,isLimitedConnection:a}=R();if(!s)return{isLimitedConnection:a,isTouchDevice:r,isRegistered:!1,unregister:()=>{}};this.isSetup||this.initializeGlobalListeners();let l=e.getBoundingClientRect(),u=n?E(n):this._globalSettings.defaultHitSlop,c={element:e,callback:t,elementBounds:{originalRect:l,expandedRect:m(l,u),hitSlop:u},isHovering:!1,trajectoryHitData:{isTrajectoryHit:!1,trajectoryHitTime:0,trajectoryHitExpirationTimeoutId:void 0},name:o||e.id||"unnamed",isIntersectingWithViewport:C(l),isRunningCallback:!1,registerCount:(this.registeredElements.get(e)?.registerCount??0)+1};return this.elements.set(e,c),this.positionObserver?.observe(e),this.emit({type:"elementRegistered",timestamp:Date.now(),elementData:c}),{isTouchDevice:r,isLimitedConnection:a,isRegistered:!0,unregister:()=>this.unregister(e,"apiCall")}}unregister(e,t){if(!this.elements.has(e))return;let n=this.elements.get(e);n?.trajectoryHitData.trajectoryHitExpirationTimeoutId&&clearTimeout(n.trajectoryHitData.trajectoryHitExpirationTimeoutId),this.positionObserver?.unobserve(e),this.elements.delete(e),this.elements.size===0&&this.isSetup&&this.removeGlobalListeners(),n&&this.emit({type:"elementUnregistered",elementData:n,timestamp:Date.now(),unregisterReason:t})}updateNumericSettings(e,t,n,o){return T(e,this._globalSettings[t])?(this._globalSettings[t]=d(e,n,o,t),!0):!1}updateBooleanSetting(e,t){return T(e,this._globalSettings[t])?(this._globalSettings[t]=e,!0):!1}alterGlobalSettings(e){let t=[];if([{setting:"positionHistorySize",min:2,max:30},{setting:"trajectoryPredictionTime",min:10,max:200},{setting:"scrollMargin",min:30,max:300},{setting:"tabOffset",min:0,max:20}].forEach(({setting:s,min:r,max:a})=>{let l=e?.[s];if(l===void 0)return;let u=this._globalSettings[s];if(this.updateNumericSettings(l,s,r,a)&&(t.push({setting:s,oldValue:u,newValue:this._globalSettings[s]}),s==="positionHistorySize"&&this._globalSettings.positionHistorySize<u)){let g=this._globalSettings.positionHistorySize;this.trajectoryPositions.positions.length>g&&(this.trajectoryPositions.positions=this.trajectoryPositions.positions.slice(-g))}}),["enableMousePrediction","enableScrollPrediction","enableTabPrediction"].forEach(s=>{let r=e?.[s];if(r===void 0)return;let a=this._globalSettings[s];this.updateBooleanSetting(r,s)&&t.push({setting:s,oldValue:a,newValue:this._globalSettings[s]})}),e?.defaultHitSlop!==void 0){let s=this._globalSettings.defaultHitSlop,r=E(e.defaultHitSlop);S(s,r)||(this._globalSettings.defaultHitSlop=r,t.push({setting:"defaultHitSlop",oldValue:s,newValue:r}),this.forceUpdateAllElementBounds())}t.length>0&&this.emit({type:"managerSettingsChanged",timestamp:Date.now(),managerData:this.getManagerData,updatedSettings:t})}forceUpdateAllElementBounds(){for(let[e,t]of this.elements)t.isIntersectingWithViewport&&this.forceUpdateElementBounds(t)}updatePointerState(e){let t={x:e.clientX,y:e.clientY};this.trajectoryPositions.currentPoint=t,this._globalSettings.enableMousePrediction?this.trajectoryPositions.predictedPoint=P(t,this.trajectoryPositions.positions,this._globalSettings.positionHistorySize,this._globalSettings.trajectoryPredictionTime):this.trajectoryPositions.predictedPoint=t}processMouseMovement(e){this.updatePointerState(e);for(let t of this.elements.values()){if(!t.isIntersectingWithViewport)continue;let n=t.elementBounds.expandedRect;if(this._globalSettings.enableMousePrediction)f(this.trajectoryPositions.currentPoint,this.trajectoryPositions.predictedPoint,n)&&this.callCallback(t,{kind:"mouse",subType:"trajectory"});else if(v(this.trajectoryPositions.currentPoint,n)){this.callCallback(t,{kind:"mouse",subType:"hover"});return}}this.emit({type:"mouseTrajectoryUpdate",predictionEnabled:this._globalSettings.enableMousePrediction,trajectoryPositions:this.trajectoryPositions})}updateHitCounters(e,t){switch(e.kind){case"mouse":this._globalCallbackHits.mouse[e.subType]++;break;case"tab":this._globalCallbackHits.tab[e.subType]++;break;case"scroll":this._globalCallbackHits.scroll[e.subType]++;break;default:}this._globalCallbackHits.total++}callCallback(e,t){if(e.isRunningCallback)return;e.isRunningCallback=!0,(async()=>{this.updateHitCounters(t,e),this.emit({type:"callbackInvoked",timestamp:Date.now(),elementData:e,hitType:t});let o=performance.now();try{await e.callback(),this.emit({type:"callbackCompleted",timestamp:Date.now(),elementData:e,hitType:t,elapsed:performance.now()-o,status:"success"})}catch(s){let r=s instanceof Error?s.message:String(s);console.error(`Error in callback for element ${e.name} (${e.element.tagName}):`,s),this.emit({type:"callbackCompleted",timestamp:Date.now(),elementData:e,hitType:t,elapsed:performance.now()-o,status:"error",errorMessage:r})}this.unregister(e.element,"callbackHit")})()}forceUpdateElementBounds(e){let t=e.element.getBoundingClientRect(),n=m(t,e.elementBounds.hitSlop);if(!S(n,e.elementBounds.expandedRect)){let o={...e,elementBounds:{...e.elementBounds,originalRect:t,expandedRect:n}};this.elements.set(e.element,o),this.emit({type:"elementDataUpdated",elementData:o,updatedProps:["bounds"]})}}handleScrollPrefetch(e,t){if(e.isIntersectingWithViewport)if(!this._globalSettings.enableScrollPrediction)v(this.trajectoryPositions.currentPoint,e.elementBounds.expandedRect)&&this.callCallback(e,{kind:"mouse",subType:"hover"});else{if(this.scrollDirection=this.scrollDirection??M(e.elementBounds.originalRect,t),this.scrollDirection==="none")return;this.predictedScrollPoint=this.predictedScrollPoint??F(this.trajectoryPositions.currentPoint,this.scrollDirection,this._globalSettings.scrollMargin),f(this.trajectoryPositions.currentPoint,this.predictedScrollPoint,e.elementBounds.expandedRect)&&this.callCallback(e,{kind:"scroll",subType:this.scrollDirection}),this.emit({type:"scrollTrajectoryUpdate",currentPoint:this.trajectoryPositions.currentPoint,predictedPoint:this.predictedScrollPoint,scrollDirection:this.scrollDirection})}}initializeGlobalListeners(){if(this.isSetup||typeof window>"u"||typeof document>"u")return;let{signal:e}=this.globalListenersController;document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("keydown",this.handleKeyDown,{signal:e}),document.addEventListener("focusin",this.handleFocusIn,{signal:e}),this.domObserver=new MutationObserver(this.handleDomMutations),this.domObserver.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!1}),this.positionObserver=new Q(this.handlePositionChange),this.isSetup=!0}removeGlobalListeners(){this.isSetup=!1,this.globalListenersController?.abort(),this.tabbableElementsCache=[],this.lastFocusedIndex=null,this.domObserver?.disconnect(),this.domObserver=null,this.positionObserver?.disconnect(),this.positionObserver=null,this.rafId&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.pendingMouseEvent=null}};export{y as ForesightManager};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|