@solid2-aria/core 0.0.1 → 0.1.0
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 +14 -0
- package/dist/NOTICE.txt +33 -11
- package/dist/browser/actiongroup/create-action-group.js +2 -1
- package/dist/browser/actiongroup/create-action-group.js.map +1 -1
- package/dist/browser/combobox/create-combo-box.js +2 -2
- package/dist/browser/combobox/create-combo-box.js.map +1 -1
- package/dist/browser/dnd/drag-preview.js +7 -8
- package/dist/browser/dnd/drag-preview.js.map +1 -1
- package/dist/browser/focus/focus-scope.js +2 -2
- package/dist/browser/focus/focus-scope.js.map +1 -1
- package/dist/browser/focus/virtual-focus.d.ts +1 -0
- package/dist/browser/focus/virtual-focus.js +20 -5
- package/dist/browser/focus/virtual-focus.js.map +1 -1
- package/dist/browser/grid/create-grid-cell.js +4 -4
- package/dist/browser/grid/create-grid-cell.js.map +1 -1
- package/dist/browser/gridlist/create-grid-list-item.js +3 -3
- package/dist/browser/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/browser/interactions/create-hover.js +6 -3
- package/dist/browser/interactions/create-hover.js.map +1 -1
- package/dist/browser/interactions/create-press.js +5 -4
- package/dist/browser/interactions/create-press.js.map +1 -1
- package/dist/browser/interactions/utils.js +4 -3
- package/dist/browser/interactions/utils.js.map +1 -1
- package/dist/browser/landmark/create-landmark.js +2 -2
- package/dist/browser/landmark/create-landmark.js.map +1 -1
- package/dist/browser/overlays/aria-hide-outside.js +5 -3
- package/dist/browser/overlays/aria-hide-outside.js.map +1 -1
- package/dist/browser/overlays/calculate-position.js +3 -3
- package/dist/browser/overlays/calculate-position.js.map +1 -1
- package/dist/browser/overlays/create-modal.js +15 -18
- package/dist/browser/overlays/create-modal.js.map +1 -1
- package/dist/browser/overlays/create-prevent-scroll.js +3 -3
- package/dist/browser/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/browser/overlays/overlay.js +7 -8
- package/dist/browser/overlays/overlay.js.map +1 -1
- package/dist/browser/select/create-select.js +1 -1
- package/dist/browser/select/create-select.js.map +1 -1
- package/dist/browser/select/hidden-select.js +61 -64
- package/dist/browser/select/hidden-select.js.map +1 -1
- package/dist/browser/selection/create-selectable-item.js +2 -2
- package/dist/browser/selection/create-selectable-item.js.map +1 -1
- package/dist/browser/selection/create-type-select.js +11 -3
- package/dist/browser/selection/create-type-select.js.map +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js +1 -1
- package/dist/browser/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/browser/tokenfield/create-token-field.js +3 -3
- package/dist/browser/tokenfield/create-token-field.js.map +1 -1
- package/dist/browser/tokenfield/create-token.js +2 -1
- package/dist/browser/tokenfield/create-token.js.map +1 -1
- package/dist/browser/toolbar/create-toolbar.js +2 -2
- package/dist/browser/toolbar/create-toolbar.js.map +1 -1
- package/dist/browser/utils/dom-helpers.d.ts +2 -15
- package/dist/browser/utils/dom-helpers.js +1 -28
- package/dist/browser/utils/dom-helpers.js.map +1 -1
- package/dist/browser/utils/dom-value.js +2 -1
- package/dist/browser/utils/dom-value.js.map +1 -1
- package/dist/browser/utils/get-scroll-parent.js +3 -2
- package/dist/browser/utils/get-scroll-parent.js.map +1 -1
- package/dist/browser/utils/get-scroll-parents.js +2 -1
- package/dist/browser/utils/get-scroll-parents.js.map +1 -1
- package/dist/browser/utils/is-element-visible.js +3 -1
- package/dist/browser/utils/is-element-visible.js.map +1 -1
- package/dist/browser/utils/is-focusable.js +2 -1
- package/dist/browser/utils/is-focusable.js.map +1 -1
- package/dist/browser/utils/shadowdom/dom-functions.d.ts +8 -0
- package/dist/browser/utils/shadowdom/dom-functions.js +26 -7
- package/dist/browser/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/browser/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/browser/utils/type-helpers.d.ts +42 -0
- package/dist/browser/utils/type-helpers.js +55 -0
- package/dist/browser/utils/type-helpers.js.map +1 -0
- package/dist/server/actiongroup/create-action-group.js +2 -1
- package/dist/server/actiongroup/create-action-group.js.map +1 -1
- package/dist/server/combobox/create-combo-box.js +2 -2
- package/dist/server/combobox/create-combo-box.js.map +1 -1
- package/dist/server/dnd/drag-preview.js +9 -12
- package/dist/server/dnd/drag-preview.js.map +1 -1
- package/dist/server/focus/focus-scope.js +2 -2
- package/dist/server/focus/focus-scope.js.map +1 -1
- package/dist/server/focus/virtual-focus.js +20 -5
- package/dist/server/focus/virtual-focus.js.map +1 -1
- package/dist/server/grid/create-grid-cell.js +4 -4
- package/dist/server/grid/create-grid-cell.js.map +1 -1
- package/dist/server/gridlist/create-grid-list-item.js +3 -3
- package/dist/server/gridlist/create-grid-list-item.js.map +1 -1
- package/dist/server/interactions/create-hover.js +6 -3
- package/dist/server/interactions/create-hover.js.map +1 -1
- package/dist/server/interactions/create-press.js +5 -4
- package/dist/server/interactions/create-press.js.map +1 -1
- package/dist/server/interactions/utils.js +4 -3
- package/dist/server/interactions/utils.js.map +1 -1
- package/dist/server/landmark/create-landmark.js +2 -2
- package/dist/server/landmark/create-landmark.js.map +1 -1
- package/dist/server/overlays/aria-hide-outside.js +5 -3
- package/dist/server/overlays/aria-hide-outside.js.map +1 -1
- package/dist/server/overlays/calculate-position.js +3 -3
- package/dist/server/overlays/calculate-position.js.map +1 -1
- package/dist/server/overlays/create-modal.js +7 -27
- package/dist/server/overlays/create-modal.js.map +1 -1
- package/dist/server/overlays/create-prevent-scroll.js +3 -3
- package/dist/server/overlays/create-prevent-scroll.js.map +1 -1
- package/dist/server/overlays/overlay.js +8 -18
- package/dist/server/overlays/overlay.js.map +1 -1
- package/dist/server/select/create-select.js +1 -1
- package/dist/server/select/create-select.js.map +1 -1
- package/dist/server/select/hidden-select.js +85 -138
- package/dist/server/select/hidden-select.js.map +1 -1
- package/dist/server/selection/create-selectable-item.js +2 -2
- package/dist/server/selection/create-selectable-item.js.map +1 -1
- package/dist/server/selection/create-type-select.js +11 -3
- package/dist/server/selection/create-type-select.js.map +1 -1
- package/dist/server/selection/list-keyboard-delegate.js +1 -1
- package/dist/server/selection/list-keyboard-delegate.js.map +1 -1
- package/dist/server/tokenfield/create-token-field.js +3 -3
- package/dist/server/tokenfield/create-token-field.js.map +1 -1
- package/dist/server/tokenfield/create-token.js +2 -1
- package/dist/server/tokenfield/create-token.js.map +1 -1
- package/dist/server/toolbar/create-toolbar.js +2 -2
- package/dist/server/toolbar/create-toolbar.js.map +1 -1
- package/dist/server/utils/dom-helpers.js +1 -28
- package/dist/server/utils/dom-helpers.js.map +1 -1
- package/dist/server/utils/dom-value.js +2 -1
- package/dist/server/utils/dom-value.js.map +1 -1
- package/dist/server/utils/get-scroll-parent.js +3 -2
- package/dist/server/utils/get-scroll-parent.js.map +1 -1
- package/dist/server/utils/get-scroll-parents.js +2 -1
- package/dist/server/utils/get-scroll-parents.js.map +1 -1
- package/dist/server/utils/is-element-visible.js +3 -1
- package/dist/server/utils/is-element-visible.js.map +1 -1
- package/dist/server/utils/is-focusable.js +2 -1
- package/dist/server/utils/is-focusable.js.map +1 -1
- package/dist/server/utils/shadowdom/dom-functions.js +26 -7
- package/dist/server/utils/shadowdom/dom-functions.js.map +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js +1 -1
- package/dist/server/utils/shadowdom/shadow-tree-walker.js.map +1 -1
- package/dist/server/utils/type-helpers.js +55 -0
- package/dist/server/utils/type-helpers.js.map +1 -0
- package/dist/server/virtualizer/scroll-view.js +3 -1
- package/dist/server/virtualizer/scroll-view.js.map +1 -1
- package/package.json +16 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/utils.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport { onCleanup } from \"solid-js\";\n\nimport { getOwnerWindow
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/utils.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport { onCleanup } from \"solid-js\";\n\nimport { getOwnerWindow } from \"../utils/dom-helpers\";\nimport { focusableElementOrNull, requireElement } from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { isFocusable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n getActiveElement,\n getEventTarget,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { isNode, isShadowRoot } from \"../utils/type-helpers\";\n\nexport function setEventTarget<E extends Event, T extends Element>(\n event: E,\n target: T\n): asserts event is E & { readonly target: T; readonly currentTarget: T } {\n Object.defineProperty(event, \"target\", { value: target });\n Object.defineProperty(event, \"currentTarget\", { value: target });\n}\n\n/** Dispatch native blur events when a focused control becomes disabled. */\nexport function createBlurObserver(): (event: Event) => void {\n let cleanup: (() => void) | undefined;\n onCleanup(() => {\n cleanup?.();\n });\n\n return (event) => {\n cleanup?.();\n const target = getEventTarget(event);\n\n if (\n !(target instanceof HTMLButtonElement) &&\n !(target instanceof HTMLInputElement) &&\n !(target instanceof HTMLTextAreaElement) &&\n !(target instanceof HTMLSelectElement)\n ) {\n return;\n }\n\n const ownerWindow = getOwnerWindow(target);\n\n const observer = new ownerWindow.MutationObserver(() => {\n if (!target.disabled) {\n return;\n }\n\n observer.disconnect();\n const activeElement = getActiveElement(target.ownerDocument);\n const relatedTarget = target === activeElement ? null : activeElement;\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"blur\", { relatedTarget })\n );\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"focusout\", { bubbles: true, relatedTarget })\n );\n });\n\n const onBlur = () => {\n observer.disconnect();\n target.removeEventListener(\"focusout\", onBlur);\n };\n\n target.addEventListener(\"focusout\", onBlur, { once: true });\n observer.observe(target, {\n attributeFilter: [\"disabled\"],\n attributes: true,\n });\n cleanup = onBlur;\n };\n}\n\n// oxlint-disable-next-line import/no-mutable-exports -- Focus adapters observe this existing ESM live binding while native focus is being restored.\nexport let ignoreFocusEvent = false;\n\n/**\n * This function prevents the next focus event fired on `target`, without using\n * `event.preventDefault()`. It works by waiting for the series of focus events to occur, and\n * reverts focus back to where it was before. It also makes these events mostly non-observable by\n * using a capturing listener on the window and stopping propagation.\n */\nexport function preventFocus(\n target: FocusableElement | null\n): (() => void) | undefined {\n let currentTarget = target;\n\n // The browser will focus the nearest focusable ancestor of our target.\n while (\n currentTarget &&\n !isFocusable(currentTarget, { skipVisibilityCheck: true })\n ) {\n currentTarget = focusableElementOrNull(getParentElement(currentTarget));\n }\n\n const ownerWindow = getOwnerWindow(currentTarget);\n\n const activeElement = focusableElementOrNull(\n getActiveElement(ownerWindow.document)\n );\n\n if (!activeElement || activeElement === currentTarget) {\n return undefined;\n }\n\n // Listen on the target's root (document or shadow root) so we catch focus events inside\n // shadow DOM; they do not reach the main window.\n const targetRoot = currentTarget?.getRootNode();\n\n const root =\n isPresent(targetRoot) && isShadowRoot(targetRoot)\n ? targetRoot\n : getOwnerWindow(currentTarget);\n\n // Focus is \"moving to target\" when it moves to the button or to a descendant of the button\n // (e.g. SVG icon)\n const isFocusMovingToTarget = (focusTarget: Element | null) =>\n focusTarget === currentTarget ||\n (isNode(focusTarget) && nodeContains(currentTarget, focusTarget));\n\n // Blur/focusout events have their target as the element losing focus. Stop propagation when\n // that is the previously focused element (activeElement) or a descendant (e.g. in shadow DOM).\n const isBlurFromActiveElement = (eventTarget: Element | null) =>\n eventTarget === activeElement ||\n (isPresent(activeElement) &&\n isNode(eventTarget) &&\n nodeContains(activeElement, eventTarget));\n\n ignoreFocusEvent = true;\n let isRefocusing = false;\n\n const onBlur: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusOut: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n // If there was no focusable ancestor, we don't expect a focus event.\n // Re-focus the original active element here.\n if (!currentTarget && !isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n const onFocus: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusIn: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n if (!isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n root.addEventListener(\"blur\", onBlur, true);\n root.addEventListener(\"focusout\", onFocusOut, true);\n root.addEventListener(\"focusin\", onFocusIn, true);\n root.addEventListener(\"focus\", onFocus, true);\n\n const raf = requestAnimationFrame(cleanup);\n\n function cleanup() {\n cancelAnimationFrame(raf);\n root.removeEventListener(\"blur\", onBlur, true);\n root.removeEventListener(\"focusout\", onFocusOut, true);\n root.removeEventListener(\"focusin\", onFocusIn, true);\n root.removeEventListener(\"focus\", onFocus, true);\n ignoreFocusEvent = false;\n isRefocusing = false;\n }\n\n return cleanup;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,eACd,OACA,QACwE;CACxE,OAAO,eAAe,OAAO,UAAU,EAAE,OAAO,OAAO,CAAC;CACxD,OAAO,eAAe,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;AACjE;;AAGA,SAAgB,qBAA6C;CAC3D,IAAI;CACJ,gBAAgB;EACd,UAAU;CACZ,CAAC;CAED,QAAQ,UAAU;EAChB,UAAU;EACV,MAAM,SAAS,eAAe,KAAK;EAEnC,IACE,EAAE,kBAAkB,sBACpB,EAAE,kBAAkB,qBACpB,EAAE,kBAAkB,wBACpB,EAAE,kBAAkB,oBAEpB;EAGF,MAAM,cAAc,eAAe,MAAM;EAEzC,MAAM,WAAW,IAAI,YAAY,uBAAuB;GACtD,IAAI,CAAC,OAAO,UACV;GAGF,SAAS,WAAW;GACpB,MAAM,gBAAgB,iBAAiB,OAAO,aAAa;GAC3D,MAAM,gBAAgB,WAAW,gBAAgB,OAAO;GACxD,OAAO,cACL,IAAI,YAAY,WAAW,QAAQ,EAAE,cAAc,CAAC,CACtD;GACA,OAAO,cACL,IAAI,YAAY,WAAW,YAAY;IAAE,SAAS;IAAM;GAAc,CAAC,CACzE;EACF,CAAC;EAED,MAAM,eAAe;GACnB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,cAEA,EAAE,yBAAyB;CAE/B;CAEA,MAAM,aAA4B,MAAM;EACtC,IACE,sBAAsB,eAAe,eAAe,CAAC,CAAC,CAAC,KACvD,cACA;GACA,EAAE,yBAAyB;GAE3B,IAAI,CAAC,cAAc;IACjB,eAAe;IACf,sBAAsB,aAAa;IACnC,QAAQ;GACV;EACF;CACF;CAEA,KAAK,iBAAiB,QAAQ,QAAQ,IAAI;CAC1C,KAAK,iBAAiB,YAAY,YAAY,IAAI;CAClD,KAAK,iBAAiB,WAAW,WAAW,IAAI;CAChD,KAAK,iBAAiB,SAAS,SAAS,IAAI;CAE5C,MAAM,MAAM,sBAAsB,OAAO;CAEzC,SAAS,UAAU;EACjB,qBAAqB,GAAG;EACxB,KAAK,oBAAoB,QAAQ,QAAQ,IAAI;EAC7C,KAAK,oBAAoB,YAAY,YAAY,IAAI;EACrD,KAAK,oBAAoB,WAAW,WAAW,IAAI;EACnD,KAAK,oBAAoB,SAAS,SAAS,IAAI;EAC/C,mBAAmB;EACnB,eAAe;CACjB;CAEA,OAAO;AACT"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
|
|
16
16
|
*/
|
|
17
17
|
import { getTruthyValue, isTruthy } from "../utils/truthy.js";
|
|
18
|
-
import { getEventTarget, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
18
|
+
import { getEventTarget, getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
19
19
|
import { focusableElementOrNull, requireFocusableElement } from "../utils/dom-value.js";
|
|
20
20
|
import { requireValue } from "../utils/require-value.js";
|
|
21
21
|
import { ariaValue } from "../utils/aria-value.js";
|
|
@@ -148,7 +148,7 @@ var LandmarkManager = class {
|
|
|
148
148
|
closestLandmark(element) {
|
|
149
149
|
const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));
|
|
150
150
|
let currentElement = element;
|
|
151
|
-
while (isTruthy(currentElement) && !landmarkMap.has(currentElement) && currentElement !== document.body && currentElement
|
|
151
|
+
while (isTruthy(currentElement) && !landmarkMap.has(currentElement) && currentElement !== document.body && getParentElement(currentElement)) currentElement = focusableElementOrNull(getParentElement(currentElement));
|
|
152
152
|
return landmarkMap.get(currentElement);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-landmark.js","names":[],"sources":["../../../src/landmark/create-landmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/landmark/useLandmark.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n AriaLabelingProps,\n FocusableElement,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n untrack,\n onSettled,\n createMemo,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { ariaValue } from \"../utils/aria-value\";\nimport { hasAnyBit } from \"../utils/bit-mask\";\nimport {\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport type AriaLandmarkRole =\n | \"main\"\n | \"region\"\n | \"search\"\n | \"navigation\"\n | \"form\"\n | \"banner\"\n | \"contentinfo\"\n | \"complementary\";\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole;\n focus?: (direction: \"forward\" | \"backward\") => void;\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes;\n}\n\n// Increment this version number whenever the\n// LandmarkManagerApi or Landmark interfaces change.\nconst LANDMARK_API_VERSION = 1;\n\n// Minimal API for LandmarkManager that must continue to work between versions.\n// Changes to this interface are considered breaking. New methods/properties are\n// safe to add, but changes or removals are not allowed (same as public APIs).\ninterface LandmarkManagerApi {\n version: number;\n createLandmarkController: () => LandmarkController;\n registerLandmark: (landmark: Landmark) => () => void;\n}\n\n// Changes to this interface are considered breaking.\n// New properties MUST be optional so that registering a landmark\n// from an older version of useLandmark against a newer version of\n// LandmarkManager does not crash.\ninterface Landmark {\n ref: Accessor<FocusableElement | null>;\n role: AriaLandmarkRole;\n label?: string;\n lastFocused?: FocusableElement;\n focus: (direction: \"forward\" | \"backward\") => void;\n blur: () => void;\n}\n\nexport interface LandmarkControllerOptions {\n /**\n * The element from which to start navigating.\n *\n * @default document.activeElement\n */\n from?: FocusableElement;\n}\n\n/** A LandmarkController allows programmatic navigation of landmarks. */\nexport interface LandmarkController {\n /** Moves focus to the next landmark. */\n focusNext: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the previous landmark. */\n focusPrevious: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the main landmark. */\n focusMain: () => boolean;\n /** Moves focus either forward or backward in the landmark sequence. */\n navigate: (\n direction: \"forward\" | \"backward\",\n opts?: LandmarkControllerOptions\n ) => boolean;\n /**\n * Disposes the landmark controller. When no landmarks are registered, and no\n * controllers are active, the landmark keyboard listeners are removed from the page.\n */\n dispose: () => void;\n}\n\n// Symbol under which the singleton landmark manager instance is attached to the document.\nconst landmarkSymbol = Symbol.for(\"react-aria-landmark-manager\");\n\ndeclare global {\n interface Document {\n [landmarkSymbol]?: LandmarkManagerApi;\n }\n}\n\nfunction subscribe(fn: () => void) {\n document.addEventListener(\"react-aria-landmark-manager-change\", fn);\n\n return () => {\n document.removeEventListener(\"react-aria-landmark-manager-change\", fn);\n };\n}\n\nfunction getLandmarkManager(): LandmarkManagerApi | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n\n // Reuse an existing instance if it has the same or greater version.\n const instance = document[landmarkSymbol];\n\n if (instance && instance.version >= LANDMARK_API_VERSION) {\n return instance;\n }\n\n // Otherwise, create a new instance and dispatch an event so anything using the existing\n // instance updates and re-registers their landmarks with the new one.\n document[landmarkSymbol] = new LandmarkManager();\n document.dispatchEvent(new CustomEvent(\"react-aria-landmark-manager-change\"));\n\n return document[landmarkSymbol];\n}\n\n// Tracks the current landmark manager and releases its subscription with the owner.\nfunction createLandmarkManager() {\n const [manager, setManager] = createSignal(untrack(getLandmarkManager));\n\n const update = () => {\n setManager(getLandmarkManager());\n };\n\n onSettled(() => {\n const unsubscribe = subscribe(update);\n update();\n\n return unsubscribe;\n });\n\n return manager;\n}\n\nclass LandmarkManager implements LandmarkManagerApi {\n private landmarks: Landmark[] = [];\n private isListening = false;\n private refCount = 0;\n public version = LANDMARK_API_VERSION;\n\n private setupIfNeeded() {\n if (this.isListening) {\n return;\n }\n\n document.addEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.addEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.addEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = true;\n }\n private teardownIfNeeded() {\n if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) {\n return;\n }\n\n document.removeEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.removeEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.removeEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = false;\n }\n private focusLandmark(\n landmark: FocusableElement,\n direction: \"forward\" | \"backward\"\n ) {\n this.landmarks.find((l) => l.ref() === landmark)?.focus?.(direction);\n }\n /**\n * Return set of landmarks with a specific role.\n */\n private getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter((l) => l.role === role));\n }\n /**\n * Return first landmark with a specific role.\n */\n private getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find((l) => l.role === role);\n }\n private addLandmark(newLandmark: Landmark) {\n const newLandmarkrefElement = newLandmark.ref();\n this.setupIfNeeded();\n\n if (\n this.landmarks.some((landmark) => landmark.ref === newLandmark.ref) ||\n !newLandmarkrefElement\n ) {\n return;\n }\n\n if (\n this.landmarks.filter((landmark) => landmark.role === \"main\").length >\n 1 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.error(\n 'Page can contain no more than one landmark with the role \"main\".'\n );\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n this.checkLabels(newLandmark.role);\n\n return;\n }\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const existing = this.landmarks[mid]?.ref();\n\n if (!existing) {\n break;\n }\n\n const comparedPosition =\n newLandmarkrefElement.compareDocumentPosition(existing);\n\n const isNewAfterExisting =\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_PRECEDING) ||\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_CONTAINS);\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n this.checkLabels(newLandmark.role);\n }\n private updateLandmark(landmark: Pick<Landmark, \"ref\"> & Partial<Landmark>) {\n const index = this.landmarks.findIndex((l) => l.ref === landmark.ref);\n const existing = this.landmarks[index];\n\n if (existing) {\n const updated = { ...existing, ...landmark };\n this.landmarks[index] = updated;\n this.checkLabels(updated.role);\n }\n }\n private removeLandmark(ref: Accessor<Element | null>) {\n this.landmarks = this.landmarks.filter((landmark) => landmark.ref !== ref);\n this.teardownIfNeeded();\n }\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n const landmarksWithRole = this.getLandmarksByRole(role);\n\n if (landmarksWithRole.size > 1) {\n const duplicatesWithoutLabel = [...landmarksWithRole].filter(\n (landmark) => !isTruthy(landmark.label)\n );\n\n if (\n duplicatesWithoutLabel.length > 0 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute:`,\n duplicatesWithoutLabel.map((landmark) => landmark.ref())\n );\n } else if (process.env.NODE_ENV !== \"production\") {\n const labels = [...landmarksWithRole].map((landmark) => landmark.label);\n\n const duplicateLabels = labels.filter(\n (item, index) => labels.indexOf(item) !== index\n );\n\n for (const label of duplicateLabels) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels:`,\n [...landmarksWithRole].flatMap((landmark) =>\n landmark.label === label ? [landmark.ref()] : []\n )\n );\n }\n }\n }\n }\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: FocusableElement) {\n const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));\n let currentElement = element;\n\n while (\n isTruthy(currentElement) &&\n !landmarkMap.has(currentElement) &&\n currentElement !== document.body &&\n currentElement.parentElement\n ) {\n currentElement = currentElement.parentElement;\n }\n\n return landmarkMap.get(currentElement);\n }\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n private getNextLandmark(\n element: FocusableElement,\n {\n backward,\n }: {\n backward?: boolean;\n }\n ): undefined | Landmark {\n const currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = isTruthy(backward) ? this.landmarks.length - 1 : 0;\n\n if (currentLandmark) {\n nextLandmarkIndex =\n this.landmarks.indexOf(currentLandmark) + (isTruthy(backward) ? -1 : 1);\n }\n\n const wrapIfNeeded = () => {\n // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.\n // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.\n if (nextLandmarkIndex < 0) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"backward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"forward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = 0;\n }\n\n if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) {\n return true;\n }\n\n return false;\n };\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n // Skip over hidden landmarks.\n const i = nextLandmarkIndex;\n\n while (\n this.landmarks[nextLandmarkIndex]?.ref()?.closest(\"[aria-hidden=true]\")\n ) {\n nextLandmarkIndex += isTruthy(backward) ? -1 : 1;\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n if (nextLandmarkIndex === i) {\n break;\n }\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n private readonly f6Handler = (e: KeyboardEvent) => {\n if (e.key === \"F6\") {\n // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.\n const handled = e.altKey\n ? this.focusMain()\n : this.navigate(requireFocusableElement(getEventTarget(e)), e.shiftKey);\n\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n };\n private focusMain() {\n const main = this.getLandmarkByRole(\"main\");\n\n const mainElement = main?.ref();\n\n if (mainElement?.isConnected === true) {\n this.focusLandmark(mainElement, \"forward\");\n\n return true;\n }\n\n return false;\n }\n private navigate(from: FocusableElement, backward: boolean) {\n const nextLandmark = this.getNextLandmark(from, {\n backward,\n });\n\n if (!nextLandmark) {\n return false;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n const { lastFocused } = nextLandmark;\n\n if (nodeContains(document.body, lastFocused)) {\n lastFocused.focus();\n\n return true;\n }\n }\n\n // Otherwise, focus the landmark itself\n const nextElement = nextLandmark.ref();\n\n if (nextElement?.isConnected === true) {\n this.focusLandmark(nextElement, backward ? \"backward\" : \"forward\");\n\n return true;\n }\n\n return false;\n }\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n private readonly focusinHandler = (e: FocusEvent) => {\n const currentLandmark = this.closestLandmark(\n requireFocusableElement(getEventTarget(e))\n );\n\n if (currentLandmark && currentLandmark.ref() !== getEventTarget(e)) {\n this.updateLandmark({\n lastFocused: requireFocusableElement(getEventTarget(e)),\n ref: currentLandmark.ref,\n });\n }\n\n const previousFocusedElement = focusableElementOrNull(e.relatedTarget);\n\n if (isTruthy(previousFocusedElement)) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had\n * focus.\n */\n private readonly focusoutHandler = (e: FocusEvent) => {\n const previousFocusedElement = requireFocusableElement(getEventTarget(e));\n const nextFocusedElement = e.relatedTarget;\n\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n public createLandmarkController(): LandmarkController {\n // oxlint-disable-next-line typescript/no-this-alias, unicorn/no-this-assignment -- Controllers retain the manager until disposal and then release that reference.\n let instance: LandmarkManager | null = this;\n instance.refCount += 1;\n instance.setupIfNeeded();\n\n return {\n dispose() {\n if (instance) {\n instance.refCount -= 1;\n instance.teardownIfNeeded();\n instance = null;\n }\n },\n focusMain() {\n return requireValue(instance, \"Expected instance\").focusMain();\n },\n focusNext(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n false\n );\n },\n focusPrevious(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(element, true);\n },\n navigate(direction, opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n direction === \"backward\"\n );\n },\n };\n }\n public registerLandmark(landmark: Landmark): () => void {\n if (this.landmarks.some((l) => l.ref === landmark.ref)) {\n this.updateLandmark(landmark);\n } else {\n this.addLandmark(landmark);\n }\n\n return () => {\n this.removeLandmark(landmark.ref);\n };\n }\n}\n\n/** Creates a LandmarkController, which allows programmatic navigation of landmarks. */\nexport function UNSTABLE_createLandmarkController(): LandmarkController {\n // Get the current landmark manager and create a controller using it.\n let instance: LandmarkManagerApi | null = getLandmarkManager();\n let controller = instance?.createLandmarkController();\n\n const unsubscribe = subscribe(() => {\n // If the landmark manager changes, dispose the old\n // controller and create a new one.\n controller?.dispose();\n instance = getLandmarkManager();\n controller = instance?.createLandmarkController();\n });\n\n // Return a wrapper that proxies requests to the current controller instance.\n return {\n dispose() {\n controller?.dispose();\n unsubscribe();\n controller = undefined;\n instance = null;\n },\n focusMain() {\n return requireValue(controller, \"Expected controller\").focusMain();\n },\n focusNext(opts) {\n return requireValue(controller, \"Expected controller\").focusNext(opts);\n },\n focusPrevious(opts) {\n return requireValue(controller, \"Expected controller\").focusPrevious(\n opts\n );\n },\n navigate(direction, opts) {\n return requireValue(controller, \"Expected controller\").navigate(\n direction,\n opts\n );\n },\n };\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a\n * landmark navigable with F6.\n *\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function createLandmark(\n props: AriaLandmarkProps,\n ref: Accessor<FocusableElement | null>\n): LandmarkAria {\n const _result0 = props;\n const manager = createLandmarkManager();\n\n const label = createMemo(\n () => getTruthyValue(_result0[\"aria-label\"]) ?? _result0[\"aria-labelledby\"]\n );\n\n const [isLandmarkFocused, setIsLandmarkFocused] = createSignal(false, {\n ownedWrite: true,\n });\n\n const defaultFocus = () => {\n setIsLandmarkFocused(true);\n };\n\n const blur = () => {\n setIsLandmarkFocused(false);\n };\n\n createEffect(\n () => ({\n input2: ref(),\n input5: defaultFocus,\n input6: blur,\n manager: manager(),\n observedFocus: _result0.focus,\n observedLabel: label(),\n observedRole: _result0.role,\n }),\n ({\n input2: element,\n observedRole,\n observedLabel,\n input5,\n observedFocus,\n input6,\n manager: currentManager,\n }): undefined | (() => void) => {\n const instance = currentManager;\n\n if (instance) {\n return instance.registerLandmark({\n blur: input6,\n focus: getTruthyValue(observedFocus) ?? input5,\n label: observedLabel,\n ref: () => element,\n role: observedRole,\n });\n }\n\n return undefined;\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ element: ref(), isLandmarkFocused: isLandmarkFocused() }),\n ({ element, isLandmarkFocused: currentIsLandmarkFocused }) => {\n if (currentIsLandmarkFocused) {\n element?.focus();\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get landmarkProps() {\n return {\n get \"aria-label\"() {\n return ariaValue(ariaValue(_result0[\"aria-label\"]));\n },\n get \"aria-labelledby\"() {\n return ariaValue(ariaValue(_result0[\"aria-labelledby\"]));\n },\n get role() {\n return _result0.role;\n },\n get tabindex() {\n return isLandmarkFocused() ? -1 : undefined;\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAM,uBAAuB;AAsD7B,MAAM,iBAAiB,OAAO,IAAI,6BAA6B;AAQ/D,SAAS,UAAU,IAAgB;CACjC,SAAS,iBAAiB,sCAAsC,EAAE;CAElE,aAAa;EACX,SAAS,oBAAoB,sCAAsC,EAAE;CACvE;AACF;AAEA,SAAS,qBAAgD;CACvD,IAAI,OAAO,aAAa,aACtB,OAAO;CAIT,MAAM,WAAW,SAAS;CAE1B,IAAI,YAAY,SAAS,WAAW,sBAClC,OAAO;CAKT,SAAS,kBAAkB,IAAI,gBAAgB;CAC/C,SAAS,cAAc,IAAI,YAAY,oCAAoC,CAAC;CAE5E,OAAO,SAAS;AAClB;AAGA,SAAS,wBAAwB;CAC/B,MAAM,CAAC,SAAS,cAAc,aAAa,QAAQ,kBAAkB,CAAC;CAEtE,MAAM,eAAe;EACnB,WAAW,mBAAmB,CAAC;CACjC;CAEA,gBAAgB;EACd,MAAM,cAAc,UAAU,MAAM;EACpC,OAAO;EAEP,OAAO;CACT,CAAC;CAED,OAAO;AACT;AAEA,IAAM,kBAAN,MAAoD;CAClD,YAAgC,CAAC;CACjC,cAAsB;CACtB,WAAmB;CACnB,UAAiB;CAEjB,gBAAwB;EACtB,IAAI,KAAK,aACP;EAGF,SAAS,iBAAiB,WAAW,KAAK,WAAW,EAAE,SAAS,KAAK,CAAC;EACtE,SAAS,iBAAiB,WAAW,KAAK,gBAAgB,EACxD,SAAS,KACX,CAAC;EACD,SAAS,iBAAiB,YAAY,KAAK,iBAAiB,EAC1D,SAAS,KACX,CAAC;EACD,KAAK,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;EACR,CAAC;CAIL,GACA,EAAE,WAAW,SAAS,CACxB;CACA,oBACS;EAAE,SAAS,IAAI;EAAG,mBAAmB,kBAAkB;CAAE,KAC/D,EAAE,SAAS,mBAAmB,+BAA+B;EAC5D,IAAI,0BACF,SAAS,MAAM;CAEnB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO,EACL,IAAI,gBAAgB;EAClB,OAAO;GACL,IAAI,eAAe;IACjB,OAAO,UAAU,UAAU,SAAS,aAAa,CAAC;GACpD;GACA,IAAI,oBAAoB;IACtB,OAAO,UAAU,UAAU,SAAS,kBAAkB,CAAC;GACzD;GACA,IAAI,OAAO;IACT,OAAO,SAAS;GAClB;GACA,IAAI,WAAW;IACb,OAAO,kBAAkB,IAAI,KAAK,KAAA;GACpC;EACF;CACF,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"create-landmark.js","names":[],"sources":["../../../src/landmark/create-landmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/landmark/useLandmark.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n AriaLabelingProps,\n FocusableElement,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n untrack,\n onSettled,\n createMemo,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { ariaValue } from \"../utils/aria-value\";\nimport { hasAnyBit } from \"../utils/bit-mask\";\nimport {\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getEventTarget,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport type AriaLandmarkRole =\n | \"main\"\n | \"region\"\n | \"search\"\n | \"navigation\"\n | \"form\"\n | \"banner\"\n | \"contentinfo\"\n | \"complementary\";\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole;\n focus?: (direction: \"forward\" | \"backward\") => void;\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes;\n}\n\n// Increment this version number whenever the\n// LandmarkManagerApi or Landmark interfaces change.\nconst LANDMARK_API_VERSION = 1;\n\n// Minimal API for LandmarkManager that must continue to work between versions.\n// Changes to this interface are considered breaking. New methods/properties are\n// safe to add, but changes or removals are not allowed (same as public APIs).\ninterface LandmarkManagerApi {\n version: number;\n createLandmarkController: () => LandmarkController;\n registerLandmark: (landmark: Landmark) => () => void;\n}\n\n// Changes to this interface are considered breaking.\n// New properties MUST be optional so that registering a landmark\n// from an older version of useLandmark against a newer version of\n// LandmarkManager does not crash.\ninterface Landmark {\n ref: Accessor<FocusableElement | null>;\n role: AriaLandmarkRole;\n label?: string;\n lastFocused?: FocusableElement;\n focus: (direction: \"forward\" | \"backward\") => void;\n blur: () => void;\n}\n\nexport interface LandmarkControllerOptions {\n /**\n * The element from which to start navigating.\n *\n * @default document.activeElement\n */\n from?: FocusableElement;\n}\n\n/** A LandmarkController allows programmatic navigation of landmarks. */\nexport interface LandmarkController {\n /** Moves focus to the next landmark. */\n focusNext: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the previous landmark. */\n focusPrevious: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the main landmark. */\n focusMain: () => boolean;\n /** Moves focus either forward or backward in the landmark sequence. */\n navigate: (\n direction: \"forward\" | \"backward\",\n opts?: LandmarkControllerOptions\n ) => boolean;\n /**\n * Disposes the landmark controller. When no landmarks are registered, and no\n * controllers are active, the landmark keyboard listeners are removed from the page.\n */\n dispose: () => void;\n}\n\n// Symbol under which the singleton landmark manager instance is attached to the document.\nconst landmarkSymbol = Symbol.for(\"react-aria-landmark-manager\");\n\ndeclare global {\n interface Document {\n [landmarkSymbol]?: LandmarkManagerApi;\n }\n}\n\nfunction subscribe(fn: () => void) {\n document.addEventListener(\"react-aria-landmark-manager-change\", fn);\n\n return () => {\n document.removeEventListener(\"react-aria-landmark-manager-change\", fn);\n };\n}\n\nfunction getLandmarkManager(): LandmarkManagerApi | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n\n // Reuse an existing instance if it has the same or greater version.\n const instance = document[landmarkSymbol];\n\n if (instance && instance.version >= LANDMARK_API_VERSION) {\n return instance;\n }\n\n // Otherwise, create a new instance and dispatch an event so anything using the existing\n // instance updates and re-registers their landmarks with the new one.\n document[landmarkSymbol] = new LandmarkManager();\n document.dispatchEvent(new CustomEvent(\"react-aria-landmark-manager-change\"));\n\n return document[landmarkSymbol];\n}\n\n// Tracks the current landmark manager and releases its subscription with the owner.\nfunction createLandmarkManager() {\n const [manager, setManager] = createSignal(untrack(getLandmarkManager));\n\n const update = () => {\n setManager(getLandmarkManager());\n };\n\n onSettled(() => {\n const unsubscribe = subscribe(update);\n update();\n\n return unsubscribe;\n });\n\n return manager;\n}\n\nclass LandmarkManager implements LandmarkManagerApi {\n private landmarks: Landmark[] = [];\n private isListening = false;\n private refCount = 0;\n public version = LANDMARK_API_VERSION;\n\n private setupIfNeeded() {\n if (this.isListening) {\n return;\n }\n\n document.addEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.addEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.addEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = true;\n }\n private teardownIfNeeded() {\n if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) {\n return;\n }\n\n document.removeEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.removeEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.removeEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = false;\n }\n private focusLandmark(\n landmark: FocusableElement,\n direction: \"forward\" | \"backward\"\n ) {\n this.landmarks.find((l) => l.ref() === landmark)?.focus?.(direction);\n }\n /**\n * Return set of landmarks with a specific role.\n */\n private getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter((l) => l.role === role));\n }\n /**\n * Return first landmark with a specific role.\n */\n private getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find((l) => l.role === role);\n }\n private addLandmark(newLandmark: Landmark) {\n const newLandmarkrefElement = newLandmark.ref();\n this.setupIfNeeded();\n\n if (\n this.landmarks.some((landmark) => landmark.ref === newLandmark.ref) ||\n !newLandmarkrefElement\n ) {\n return;\n }\n\n if (\n this.landmarks.filter((landmark) => landmark.role === \"main\").length >\n 1 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.error(\n 'Page can contain no more than one landmark with the role \"main\".'\n );\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n this.checkLabels(newLandmark.role);\n\n return;\n }\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const existing = this.landmarks[mid]?.ref();\n\n if (!existing) {\n break;\n }\n\n const comparedPosition =\n newLandmarkrefElement.compareDocumentPosition(existing);\n\n const isNewAfterExisting =\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_PRECEDING) ||\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_CONTAINS);\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n this.checkLabels(newLandmark.role);\n }\n private updateLandmark(landmark: Pick<Landmark, \"ref\"> & Partial<Landmark>) {\n const index = this.landmarks.findIndex((l) => l.ref === landmark.ref);\n const existing = this.landmarks[index];\n\n if (existing) {\n const updated = { ...existing, ...landmark };\n this.landmarks[index] = updated;\n this.checkLabels(updated.role);\n }\n }\n private removeLandmark(ref: Accessor<Element | null>) {\n this.landmarks = this.landmarks.filter((landmark) => landmark.ref !== ref);\n this.teardownIfNeeded();\n }\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n const landmarksWithRole = this.getLandmarksByRole(role);\n\n if (landmarksWithRole.size > 1) {\n const duplicatesWithoutLabel = [...landmarksWithRole].filter(\n (landmark) => !isTruthy(landmark.label)\n );\n\n if (\n duplicatesWithoutLabel.length > 0 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute:`,\n duplicatesWithoutLabel.map((landmark) => landmark.ref())\n );\n } else if (process.env.NODE_ENV !== \"production\") {\n const labels = [...landmarksWithRole].map((landmark) => landmark.label);\n\n const duplicateLabels = labels.filter(\n (item, index) => labels.indexOf(item) !== index\n );\n\n for (const label of duplicateLabels) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels:`,\n [...landmarksWithRole].flatMap((landmark) =>\n landmark.label === label ? [landmark.ref()] : []\n )\n );\n }\n }\n }\n }\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: FocusableElement) {\n const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));\n let currentElement: FocusableElement | null = element;\n\n while (\n isTruthy(currentElement) &&\n !landmarkMap.has(currentElement) &&\n currentElement !== document.body &&\n getParentElement(currentElement)\n ) {\n currentElement = focusableElementOrNull(getParentElement(currentElement));\n }\n\n return landmarkMap.get(currentElement);\n }\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n private getNextLandmark(\n element: FocusableElement,\n {\n backward,\n }: {\n backward?: boolean;\n }\n ): undefined | Landmark {\n const currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = isTruthy(backward) ? this.landmarks.length - 1 : 0;\n\n if (currentLandmark) {\n nextLandmarkIndex =\n this.landmarks.indexOf(currentLandmark) + (isTruthy(backward) ? -1 : 1);\n }\n\n const wrapIfNeeded = () => {\n // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.\n // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.\n if (nextLandmarkIndex < 0) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"backward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"forward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = 0;\n }\n\n if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) {\n return true;\n }\n\n return false;\n };\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n // Skip over hidden landmarks.\n const i = nextLandmarkIndex;\n\n while (\n this.landmarks[nextLandmarkIndex]?.ref()?.closest(\"[aria-hidden=true]\")\n ) {\n nextLandmarkIndex += isTruthy(backward) ? -1 : 1;\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n if (nextLandmarkIndex === i) {\n break;\n }\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n private readonly f6Handler = (e: KeyboardEvent) => {\n if (e.key === \"F6\") {\n // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.\n const handled = e.altKey\n ? this.focusMain()\n : this.navigate(requireFocusableElement(getEventTarget(e)), e.shiftKey);\n\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n };\n private focusMain() {\n const main = this.getLandmarkByRole(\"main\");\n\n const mainElement = main?.ref();\n\n if (mainElement?.isConnected === true) {\n this.focusLandmark(mainElement, \"forward\");\n\n return true;\n }\n\n return false;\n }\n private navigate(from: FocusableElement, backward: boolean) {\n const nextLandmark = this.getNextLandmark(from, {\n backward,\n });\n\n if (!nextLandmark) {\n return false;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n const { lastFocused } = nextLandmark;\n\n if (nodeContains(document.body, lastFocused)) {\n lastFocused.focus();\n\n return true;\n }\n }\n\n // Otherwise, focus the landmark itself\n const nextElement = nextLandmark.ref();\n\n if (nextElement?.isConnected === true) {\n this.focusLandmark(nextElement, backward ? \"backward\" : \"forward\");\n\n return true;\n }\n\n return false;\n }\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n private readonly focusinHandler = (e: FocusEvent) => {\n const currentLandmark = this.closestLandmark(\n requireFocusableElement(getEventTarget(e))\n );\n\n if (currentLandmark && currentLandmark.ref() !== getEventTarget(e)) {\n this.updateLandmark({\n lastFocused: requireFocusableElement(getEventTarget(e)),\n ref: currentLandmark.ref,\n });\n }\n\n const previousFocusedElement = focusableElementOrNull(e.relatedTarget);\n\n if (isTruthy(previousFocusedElement)) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had\n * focus.\n */\n private readonly focusoutHandler = (e: FocusEvent) => {\n const previousFocusedElement = requireFocusableElement(getEventTarget(e));\n const nextFocusedElement = e.relatedTarget;\n\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n public createLandmarkController(): LandmarkController {\n // oxlint-disable-next-line typescript/no-this-alias, unicorn/no-this-assignment -- Controllers retain the manager until disposal and then release that reference.\n let instance: LandmarkManager | null = this;\n instance.refCount += 1;\n instance.setupIfNeeded();\n\n return {\n dispose() {\n if (instance) {\n instance.refCount -= 1;\n instance.teardownIfNeeded();\n instance = null;\n }\n },\n focusMain() {\n return requireValue(instance, \"Expected instance\").focusMain();\n },\n focusNext(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n false\n );\n },\n focusPrevious(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(element, true);\n },\n navigate(direction, opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n direction === \"backward\"\n );\n },\n };\n }\n public registerLandmark(landmark: Landmark): () => void {\n if (this.landmarks.some((l) => l.ref === landmark.ref)) {\n this.updateLandmark(landmark);\n } else {\n this.addLandmark(landmark);\n }\n\n return () => {\n this.removeLandmark(landmark.ref);\n };\n }\n}\n\n/** Creates a LandmarkController, which allows programmatic navigation of landmarks. */\nexport function UNSTABLE_createLandmarkController(): LandmarkController {\n // Get the current landmark manager and create a controller using it.\n let instance: LandmarkManagerApi | null = getLandmarkManager();\n let controller = instance?.createLandmarkController();\n\n const unsubscribe = subscribe(() => {\n // If the landmark manager changes, dispose the old\n // controller and create a new one.\n controller?.dispose();\n instance = getLandmarkManager();\n controller = instance?.createLandmarkController();\n });\n\n // Return a wrapper that proxies requests to the current controller instance.\n return {\n dispose() {\n controller?.dispose();\n unsubscribe();\n controller = undefined;\n instance = null;\n },\n focusMain() {\n return requireValue(controller, \"Expected controller\").focusMain();\n },\n focusNext(opts) {\n return requireValue(controller, \"Expected controller\").focusNext(opts);\n },\n focusPrevious(opts) {\n return requireValue(controller, \"Expected controller\").focusPrevious(\n opts\n );\n },\n navigate(direction, opts) {\n return requireValue(controller, \"Expected controller\").navigate(\n direction,\n opts\n );\n },\n };\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a\n * landmark navigable with F6.\n *\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function createLandmark(\n props: AriaLandmarkProps,\n ref: Accessor<FocusableElement | null>\n): LandmarkAria {\n const _result0 = props;\n const manager = createLandmarkManager();\n\n const label = createMemo(\n () => getTruthyValue(_result0[\"aria-label\"]) ?? _result0[\"aria-labelledby\"]\n );\n\n const [isLandmarkFocused, setIsLandmarkFocused] = createSignal(false, {\n ownedWrite: true,\n });\n\n const defaultFocus = () => {\n setIsLandmarkFocused(true);\n };\n\n const blur = () => {\n setIsLandmarkFocused(false);\n };\n\n createEffect(\n () => ({\n input2: ref(),\n input5: defaultFocus,\n input6: blur,\n manager: manager(),\n observedFocus: _result0.focus,\n observedLabel: label(),\n observedRole: _result0.role,\n }),\n ({\n input2: element,\n observedRole,\n observedLabel,\n input5,\n observedFocus,\n input6,\n manager: currentManager,\n }): undefined | (() => void) => {\n const instance = currentManager;\n\n if (instance) {\n return instance.registerLandmark({\n blur: input6,\n focus: getTruthyValue(observedFocus) ?? input5,\n label: observedLabel,\n ref: () => element,\n role: observedRole,\n });\n }\n\n return undefined;\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ element: ref(), isLandmarkFocused: isLandmarkFocused() }),\n ({ element, isLandmarkFocused: currentIsLandmarkFocused }) => {\n if (currentIsLandmarkFocused) {\n element?.focus();\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get landmarkProps() {\n return {\n get \"aria-label\"() {\n return ariaValue(ariaValue(_result0[\"aria-label\"]));\n },\n get \"aria-labelledby\"() {\n return ariaValue(ariaValue(_result0[\"aria-labelledby\"]));\n },\n get role() {\n return _result0.role;\n },\n get tabindex() {\n return isLandmarkFocused() ? -1 : undefined;\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAM,uBAAuB;AAsD7B,MAAM,iBAAiB,OAAO,IAAI,6BAA6B;AAQ/D,SAAS,UAAU,IAAgB;CACjC,SAAS,iBAAiB,sCAAsC,EAAE;CAElE,aAAa;EACX,SAAS,oBAAoB,sCAAsC,EAAE;CACvE;AACF;AAEA,SAAS,qBAAgD;CACvD,IAAI,OAAO,aAAa,aACtB,OAAO;CAIT,MAAM,WAAW,SAAS;CAE1B,IAAI,YAAY,SAAS,WAAW,sBAClC,OAAO;CAKT,SAAS,kBAAkB,IAAI,gBAAgB;CAC/C,SAAS,cAAc,IAAI,YAAY,oCAAoC,CAAC;CAE5E,OAAO,SAAS;AAClB;AAGA,SAAS,wBAAwB;CAC/B,MAAM,CAAC,SAAS,cAAc,aAAa,QAAQ,kBAAkB,CAAC;CAEtE,MAAM,eAAe;EACnB,WAAW,mBAAmB,CAAC;CACjC;CAEA,gBAAgB;EACd,MAAM,cAAc,UAAU,MAAM;EACpC,OAAO;EAEP,OAAO;CACT,CAAC;CAED,OAAO;AACT;AAE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a;EACjB,qBAAqB,KAAK;CAC5B;CAEA,oBACS;EACL,QAAQ,IAAI;EACZ,QAAQ;EACR,QAAQ;EACR,SAAS,QAAQ;EACjB,eAAe,SAAS;EACxB,eAAe,MAAM;EACrB,cAAc,SAAS;CACzB,KACC,EACC,QAAQ,SACR,cACA,eACA,QACA,eACA,QACA,SAAS,qBACqB;EAC9B,MAAM,WAAW;EAEjB,IAAI,UACF,OAAO,SAAS,iBAAiB;GAC/B,MAAM;GACN,OAAO,eAAe,aAAa,KAAK;GACxC,OAAO;GACP,WAAW;GACX,MAAM;EACR,CAAC;CAIL,GACA,EAAE,WAAW,SAAS,CACxB;CACA,oBACS;EAAE,SAAS,IAAI;EAAG,mBAAmB,kBAAkB;CAAE,KAC/D,EAAE,SAAS,mBAAmB,+BAA+B;EAC5D,IAAI,0BACF,SAAS,MAAM;CAEnB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO,EACL,IAAI,gBAAgB;EAClB,OAAO;GACL,IAAI,eAAe;IACjB,OAAO,UAAU,UAAU,SAAS,aAAa,CAAC;GACpD;GACA,IAAI,oBAAoB;IACtB,OAAO,UAAU,UAAU,SAAS,kBAAkB,CAAC;GACzD;GACA,IAAI,OAAO;IACT,OAAO,SAAS;GAClB;GACA,IAAI,WAAW;IACb,OAAO,kBAAkB,IAAI,KAAK,KAAA;GACpC;EACF;CACF,EACF;AACF"}
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { isTruthy, whenTruthy } from "../utils/truthy.js";
|
|
18
18
|
import { isPresent } from "../utils/is-present.js";
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { isShadowRoot } from "../utils/type-helpers.js";
|
|
20
|
+
import { getOwnerDocument, getOwnerWindow } from "../utils/dom-helpers.js";
|
|
21
|
+
import { getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
21
22
|
import { elementOrNull } from "../utils/dom-value.js";
|
|
22
23
|
import { createShadowTreeWalker } from "../utils/shadowdom/shadow-tree-walker.js";
|
|
23
24
|
import { shadowDOM } from "@solid2-aria/stately/flags/flags";
|
|
@@ -65,7 +66,8 @@ function ariaHideOutside(targets, options) {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
const acceptNode = (node) => {
|
|
68
|
-
|
|
69
|
+
const parentElement = getParentElement(node);
|
|
70
|
+
if (hiddenNodes.has(node) || visibleNodes.has(node) || parentElement && hiddenNodes.has(parentElement) && parentElement.getAttribute("role") !== "row") return NodeFilter.FILTER_REJECT;
|
|
69
71
|
for (const target of visibleNodes) if (nodeContains(node, target)) return NodeFilter.FILTER_SKIP;
|
|
70
72
|
return NodeFilter.FILTER_ACCEPT;
|
|
71
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aria-hide-outside.js","names":[],"sources":["../../../src/overlays/aria-hide-outside.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/overlays/ariaHideOutside.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { shadowDOM } from \"@solid2-aria/stately/flags/flags\";\n\nimport {\n getOwnerDocument,\n getOwnerWindow,\n isShadowRoot,\n} from \"../utils/dom-helpers\";\nimport { elementOrNull } from \"../utils/dom-value\";\nimport { isPresent } from \"../utils/is-present\";\nimport { nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { createShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { isTruthy, whenTruthy } from \"../utils/truthy\";\n\nconst supportsInert =\n typeof HTMLElement !== \"undefined\" && \"inert\" in HTMLElement.prototype;\n\nfunction isAlwaysVisibleNode(node: HTMLElement | SVGElement): boolean {\n return (\n node.dataset.liveAnnouncer === \"true\" ||\n node.dataset.reactAriaTopLayer !== undefined\n );\n}\n\ninterface AriaHideOutsideOptions {\n root?: Element;\n shouldUseInert?: boolean;\n}\n\n// Keeps a ref count of all hidden elements. Added to when hiding an element, and\n// subtracted from when showing it again. When it reaches zero, aria-hidden is removed.\nconst refCountMap = new WeakMap<Element, number>();\n\ninterface ObserverWrapper {\n visibleNodes: Set<Element>;\n hiddenNodes: Set<Element>;\n observe: () => void;\n disconnect: () => void;\n}\n\nconst observerStack: ObserverWrapper[] = [];\n\n/**\n * Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,\n * and returns a function to revert these changes. In addition, changes to the DOM are watched\n * and new elements outside the targets are automatically hidden.\n *\n * @param targets - The elements that should remain visible.\n * @param root - Nothing will be hidden above this element.\n * @returns - A function to restore all hidden elements.\n */\n\nexport function ariaHideOutside(\n targets: Element[],\n options?: AriaHideOutsideOptions | Element\n) {\n const windowObj = getOwnerWindow(targets?.[0]);\n\n const opts =\n options instanceof windowObj.Element ? { root: options } : options;\n\n const root = opts?.root ?? document.body;\n\n const shouldUseInert = whenTruthy(opts?.shouldUseInert, () => supportsInert);\n\n const visibleNodes = new Set<Element>(targets);\n const hiddenNodes = new Set<Element>();\n\n const getHidden = (element: Element) =>\n isTruthy(shouldUseInert) && element instanceof windowObj.HTMLElement\n ? element.inert\n : element.getAttribute(\"aria-hidden\") === \"true\";\n\n const setHidden = (element: Element, hidden: boolean) => {\n if (isTruthy(shouldUseInert) && element instanceof windowObj.HTMLElement) {\n element.inert = hidden;\n } else if (hidden) {\n element.setAttribute(\"aria-hidden\", \"true\");\n } else {\n element.removeAttribute(\"aria-hidden\");\n\n if (element instanceof windowObj.HTMLElement) {\n // We only ever call setHidden with hidden = false when the nodeCount is 1 aka\n // we are trying to make the element visible to screen readers again, so remove inert as well\n element.inert = false;\n }\n }\n };\n\n const shadowRootsToWatch = new Set<ShadowRoot>();\n\n if (shadowDOM()) {\n // Find all shadow roots that enclose the targets, walking up the host chain\n // until we reach the tree that `root` lives in. Each enclosing ShadowRoot\n // needs its own MutationObserver because it does not cross shadow\n // boundaries, so the observer on `root` cannot see mutations inside them.\n const boundary = root.getRootNode();\n\n for (const target of targets) {\n let current = target.getRootNode();\n\n while (isShadowRoot(current) && current !== boundary) {\n shadowRootsToWatch.add(current);\n current = current.host.getRootNode();\n }\n }\n }\n\n const acceptNode = (node: Element) => {\n // Skip this node and its children if it is one of the target nodes, or a live announcer.\n // Also skip children of already hidden nodes, as aria-hidden is recursive. An exception is\n // made for elements with role=\"row\" since VoiceOver on iOS has issues hiding elements with role=\"row\".\n // For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).\n if (\n hiddenNodes.has(node) ||\n visibleNodes.has(node) ||\n (node.parentElement &&\n hiddenNodes.has(node.parentElement) &&\n node.parentElement.getAttribute(\"role\") !== \"row\")\n ) {\n return NodeFilter.FILTER_REJECT;\n }\n\n // Skip this node but continue to children if one of the targets is inside the node.\n for (const target of visibleNodes) {\n if (nodeContains(node, target)) {\n return NodeFilter.FILTER_SKIP;\n }\n }\n\n return NodeFilter.FILTER_ACCEPT;\n };\n\n const walk = (rootValue: Element) => {\n // Keep live announcer and top layer elements (e.g. toasts) visible.\n for (const element of rootValue.querySelectorAll(\n \"[data-live-announcer], [data-react-aria-top-layer]\"\n )) {\n visibleNodes.add(element);\n }\n\n const walker = createShadowTreeWalker(\n getOwnerDocument(rootValue),\n rootValue,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode,\n }\n );\n\n // TreeWalker does not include the root.\n const acceptRoot = acceptNode(rootValue);\n\n if (acceptRoot === NodeFilter.FILTER_ACCEPT) {\n hide(rootValue);\n }\n\n if (acceptRoot !== NodeFilter.FILTER_REJECT) {\n let node = elementOrNull(walker.nextNode());\n\n while (isPresent(node)) {\n hide(node);\n node = elementOrNull(walker.nextNode());\n }\n }\n };\n\n function hide(node: Element) {\n const refCount = refCountMap.get(node) ?? 0;\n\n // If already aria-hidden, and the ref count is zero, then this element\n // was already hidden and there's nothing for us to do.\n if (getHidden(node) && refCount === 0) {\n return;\n }\n\n if (refCount === 0) {\n setHidden(node, true);\n }\n\n hiddenNodes.add(node);\n refCountMap.set(node, refCount + 1);\n }\n\n // If there is already a MutationObserver listening from a previous call,\n // disconnect it so the new on takes over.\n if (observerStack.length) {\n observerStack.at(-1)?.disconnect();\n }\n\n walk(root);\n\n const observer = new MutationObserver((changes) => {\n for (const change of changes) {\n if (change.type !== \"childList\") {\n continue;\n }\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (\n change.target.isConnected &&\n ![...visibleNodes, ...hiddenNodes].some((node) =>\n nodeContains(node, change.target)\n )\n ) {\n for (const node of change.addedNodes) {\n if (\n (node instanceof HTMLElement || node instanceof SVGElement) &&\n isAlwaysVisibleNode(node)\n ) {\n visibleNodes.add(node);\n } else if (node instanceof Element) {\n walk(node);\n }\n }\n }\n\n if (shadowDOM()) {\n // if any of the observed shadow roots were removed, stop observing them\n for (const shadowRoot of shadowRootsToWatch) {\n if (!shadowRoot.isConnected) {\n observer.disconnect();\n break;\n }\n }\n }\n }\n });\n\n observer.observe(root, { childList: true, subtree: true });\n const shadowObservers = new Set<MutationObserver>();\n\n if (shadowDOM()) {\n for (const shadowRoot of shadowRootsToWatch) {\n // Disconnect single target instead of all https://github.com/whatwg/dom/issues/126\n const shadowObserver = new MutationObserver((changes) => {\n for (const change of changes) {\n if (change.type !== \"childList\") {\n continue;\n }\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (\n change.target.isConnected &&\n ![...visibleNodes, ...hiddenNodes].some((node) =>\n nodeContains(node, change.target)\n )\n ) {\n for (const node of change.addedNodes) {\n if (\n (node instanceof HTMLElement || node instanceof SVGElement) &&\n isAlwaysVisibleNode(node)\n ) {\n visibleNodes.add(node);\n } else if (node instanceof Element) {\n walk(node);\n }\n }\n }\n\n if (shadowDOM()) {\n // if any of the observed shadow roots were removed, stop observing them\n for (const shadowRootValue of shadowRootsToWatch) {\n if (!shadowRootValue.isConnected) {\n observer.disconnect();\n break;\n }\n }\n }\n }\n });\n\n shadowObserver.observe(shadowRoot, { childList: true, subtree: true });\n shadowObservers.add(shadowObserver);\n }\n }\n\n const observerWrapper: ObserverWrapper = {\n disconnect() {\n observer.disconnect();\n },\n hiddenNodes,\n observe() {\n observer.observe(root, { childList: true, subtree: true });\n },\n visibleNodes,\n };\n\n observerStack.push(observerWrapper);\n\n return (): void => {\n observer.disconnect();\n\n if (shadowDOM()) {\n for (const shadowObserver of shadowObservers) {\n shadowObserver.disconnect();\n }\n }\n\n for (const node of hiddenNodes) {\n const count = refCountMap.get(node);\n\n if (!isPresent(count)) {\n continue;\n }\n\n if (count === 1) {\n setHidden(node, false);\n refCountMap.delete(node);\n } else {\n refCountMap.set(node, count - 1);\n }\n }\n\n // Remove this observer from the stack, and start the previous one.\n if (observerWrapper === observerStack.at(-1)) {\n observerStack.pop();\n\n if (observerStack.length) {\n observerStack.at(-1)?.observe();\n }\n } else {\n observerStack.splice(observerStack.indexOf(observerWrapper), 1);\n }\n };\n}\n\nexport function keepVisible(element: Element): (() => void) | undefined {\n const observer = observerStack.at(-1);\n\n if (observer && !observer.visibleNodes.has(element)) {\n observer.visibleNodes.add(element);\n\n return () => {\n observer.visibleNodes.delete(element);\n };\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,gBACJ,OAAO,gBAAgB,eAAe,WAAW,YAAY;AAE/D,SAAS,oBAAoB,MAAyC;CACpE,OACE,KAAK,QAAQ,kBAAkB,UAC/B,KAAK,QAAQ,s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EnC;EAGA,IAAI,oBAAoB,cAAc,GAAG,EAAE,GAAG;GAC5C,cAAc,IAAI;GAElB,IAAI,cAAc,QAChB,cAAc,GAAG,EAAE,CAAC,EAAE,QAAQ;EAElC,OACE,cAAc,OAAO,cAAc,QAAQ,eAAe,GAAG,CAAC;CAElE;AACF;AAEA,SAAgB,YAAY,SAA4C;CACtE,MAAM,WAAW,cAAc,GAAG,EAAE;CAEpC,IAAI,YAAY,CAAC,SAAS,aAAa,IAAI,OAAO,GAAG;EACnD,SAAS,aAAa,IAAI,OAAO;EAEjC,aAAa;GACX,SAAS,aAAa,OAAO,OAAO;EACtC;CACF;AAGF"}
|
|
1
|
+
{"version":3,"file":"aria-hide-outside.js","names":[],"sources":["../../../src/overlays/aria-hide-outside.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/overlays/ariaHideOutside.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { shadowDOM } from \"@solid2-aria/stately/flags/flags\";\n\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport { elementOrNull } from \"../utils/dom-value\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { createShadowTreeWalker } from \"../utils/shadowdom/shadow-tree-walker\";\nimport { isTruthy, whenTruthy } from \"../utils/truthy\";\nimport { isShadowRoot } from \"../utils/type-helpers\";\n\nconst supportsInert =\n typeof HTMLElement !== \"undefined\" && \"inert\" in HTMLElement.prototype;\n\nfunction isAlwaysVisibleNode(node: HTMLElement | SVGElement): boolean {\n return (\n node.dataset.liveAnnouncer === \"true\" ||\n node.dataset.reactAriaTopLayer !== undefined\n );\n}\n\ninterface AriaHideOutsideOptions {\n root?: Element;\n shouldUseInert?: boolean;\n}\n\n// Keeps a ref count of all hidden elements. Added to when hiding an element, and\n// subtracted from when showing it again. When it reaches zero, aria-hidden is removed.\nconst refCountMap = new WeakMap<Element, number>();\n\ninterface ObserverWrapper {\n visibleNodes: Set<Element>;\n hiddenNodes: Set<Element>;\n observe: () => void;\n disconnect: () => void;\n}\n\nconst observerStack: ObserverWrapper[] = [];\n\n/**\n * Hides all elements in the DOM outside the given targets from screen readers using aria-hidden,\n * and returns a function to revert these changes. In addition, changes to the DOM are watched\n * and new elements outside the targets are automatically hidden.\n *\n * @param targets - The elements that should remain visible.\n * @param root - Nothing will be hidden above this element.\n * @returns - A function to restore all hidden elements.\n */\n\nexport function ariaHideOutside(\n targets: Element[],\n options?: AriaHideOutsideOptions | Element\n) {\n const windowObj = getOwnerWindow(targets?.[0]);\n\n const opts =\n options instanceof windowObj.Element ? { root: options } : options;\n\n const root = opts?.root ?? document.body;\n\n const shouldUseInert = whenTruthy(opts?.shouldUseInert, () => supportsInert);\n\n const visibleNodes = new Set<Element>(targets);\n const hiddenNodes = new Set<Element>();\n\n const getHidden = (element: Element) =>\n isTruthy(shouldUseInert) && element instanceof windowObj.HTMLElement\n ? element.inert\n : element.getAttribute(\"aria-hidden\") === \"true\";\n\n const setHidden = (element: Element, hidden: boolean) => {\n if (isTruthy(shouldUseInert) && element instanceof windowObj.HTMLElement) {\n element.inert = hidden;\n } else if (hidden) {\n element.setAttribute(\"aria-hidden\", \"true\");\n } else {\n element.removeAttribute(\"aria-hidden\");\n\n if (element instanceof windowObj.HTMLElement) {\n // We only ever call setHidden with hidden = false when the nodeCount is 1 aka\n // we are trying to make the element visible to screen readers again, so remove inert as well\n element.inert = false;\n }\n }\n };\n\n const shadowRootsToWatch = new Set<ShadowRoot>();\n\n if (shadowDOM()) {\n // Find all shadow roots that enclose the targets, walking up the host chain\n // until we reach the tree that `root` lives in. Each enclosing ShadowRoot\n // needs its own MutationObserver because it does not cross shadow\n // boundaries, so the observer on `root` cannot see mutations inside them.\n const boundary = root.getRootNode();\n\n for (const target of targets) {\n let current = target.getRootNode();\n\n while (isShadowRoot(current) && current !== boundary) {\n shadowRootsToWatch.add(current);\n current = current.host.getRootNode();\n }\n }\n }\n\n const acceptNode = (node: Element) => {\n // Skip this node and its children if it is one of the target nodes, or a live announcer.\n // Also skip children of already hidden nodes, as aria-hidden is recursive. An exception is\n // made for elements with role=\"row\" since VoiceOver on iOS has issues hiding elements with role=\"row\".\n // For that case we want to hide the cells inside as well (https://bugs.webkit.org/show_bug.cgi?id=222623).\n const parentElement = getParentElement(node);\n\n if (\n hiddenNodes.has(node) ||\n visibleNodes.has(node) ||\n (parentElement &&\n hiddenNodes.has(parentElement) &&\n parentElement.getAttribute(\"role\") !== \"row\")\n ) {\n return NodeFilter.FILTER_REJECT;\n }\n\n // Skip this node but continue to children if one of the targets is inside the node.\n for (const target of visibleNodes) {\n if (nodeContains(node, target)) {\n return NodeFilter.FILTER_SKIP;\n }\n }\n\n return NodeFilter.FILTER_ACCEPT;\n };\n\n const walk = (rootValue: Element) => {\n // Keep live announcer and top layer elements (e.g. toasts) visible.\n for (const element of rootValue.querySelectorAll(\n \"[data-live-announcer], [data-react-aria-top-layer]\"\n )) {\n visibleNodes.add(element);\n }\n\n const walker = createShadowTreeWalker(\n getOwnerDocument(rootValue),\n rootValue,\n NodeFilter.SHOW_ELEMENT,\n {\n acceptNode,\n }\n );\n\n // TreeWalker does not include the root.\n const acceptRoot = acceptNode(rootValue);\n\n if (acceptRoot === NodeFilter.FILTER_ACCEPT) {\n hide(rootValue);\n }\n\n if (acceptRoot !== NodeFilter.FILTER_REJECT) {\n let node = elementOrNull(walker.nextNode());\n\n while (isPresent(node)) {\n hide(node);\n node = elementOrNull(walker.nextNode());\n }\n }\n };\n\n function hide(node: Element) {\n const refCount = refCountMap.get(node) ?? 0;\n\n // If already aria-hidden, and the ref count is zero, then this element\n // was already hidden and there's nothing for us to do.\n if (getHidden(node) && refCount === 0) {\n return;\n }\n\n if (refCount === 0) {\n setHidden(node, true);\n }\n\n hiddenNodes.add(node);\n refCountMap.set(node, refCount + 1);\n }\n\n // If there is already a MutationObserver listening from a previous call,\n // disconnect it so the new on takes over.\n if (observerStack.length) {\n observerStack.at(-1)?.disconnect();\n }\n\n walk(root);\n\n const observer = new MutationObserver((changes) => {\n for (const change of changes) {\n if (change.type !== \"childList\") {\n continue;\n }\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (\n change.target.isConnected &&\n ![...visibleNodes, ...hiddenNodes].some((node) =>\n nodeContains(node, change.target)\n )\n ) {\n for (const node of change.addedNodes) {\n if (\n (node instanceof HTMLElement || node instanceof SVGElement) &&\n isAlwaysVisibleNode(node)\n ) {\n visibleNodes.add(node);\n } else if (node instanceof Element) {\n walk(node);\n }\n }\n }\n\n if (shadowDOM()) {\n // if any of the observed shadow roots were removed, stop observing them\n for (const shadowRoot of shadowRootsToWatch) {\n if (!shadowRoot.isConnected) {\n observer.disconnect();\n break;\n }\n }\n }\n }\n });\n\n observer.observe(root, { childList: true, subtree: true });\n const shadowObservers = new Set<MutationObserver>();\n\n if (shadowDOM()) {\n for (const shadowRoot of shadowRootsToWatch) {\n // Disconnect single target instead of all https://github.com/whatwg/dom/issues/126\n const shadowObserver = new MutationObserver((changes) => {\n for (const change of changes) {\n if (change.type !== \"childList\") {\n continue;\n }\n\n // If the parent element of the added nodes is not within one of the targets,\n // and not already inside a hidden node, hide all of the new children.\n if (\n change.target.isConnected &&\n ![...visibleNodes, ...hiddenNodes].some((node) =>\n nodeContains(node, change.target)\n )\n ) {\n for (const node of change.addedNodes) {\n if (\n (node instanceof HTMLElement || node instanceof SVGElement) &&\n isAlwaysVisibleNode(node)\n ) {\n visibleNodes.add(node);\n } else if (node instanceof Element) {\n walk(node);\n }\n }\n }\n\n if (shadowDOM()) {\n // if any of the observed shadow roots were removed, stop observing them\n for (const shadowRootValue of shadowRootsToWatch) {\n if (!shadowRootValue.isConnected) {\n observer.disconnect();\n break;\n }\n }\n }\n }\n });\n\n shadowObserver.observe(shadowRoot, { childList: true, subtree: true });\n shadowObservers.add(shadowObserver);\n }\n }\n\n const observerWrapper: ObserverWrapper = {\n disconnect() {\n observer.disconnect();\n },\n hiddenNodes,\n observe() {\n observer.observe(root, { childList: true, subtree: true });\n },\n visibleNodes,\n };\n\n observerStack.push(observerWrapper);\n\n return (): void => {\n observer.disconnect();\n\n if (shadowDOM()) {\n for (const shadowObserver of shadowObservers) {\n shadowObserver.disconnect();\n }\n }\n\n for (const node of hiddenNodes) {\n const count = refCountMap.get(node);\n\n if (!isPresent(count)) {\n continue;\n }\n\n if (count === 1) {\n setHidden(node, false);\n refCountMap.delete(node);\n } else {\n refCountMap.set(node, count - 1);\n }\n }\n\n // Remove this observer from the stack, and start the previous one.\n if (observerWrapper === observerStack.at(-1)) {\n observerStack.pop();\n\n if (observerStack.length) {\n observerStack.at(-1)?.observe();\n }\n } else {\n observerStack.splice(observerStack.indexOf(observerWrapper), 1);\n }\n };\n}\n\nexport function keepVisible(element: Element): (() => void) | undefined {\n const observer = observerStack.at(-1);\n\n if (observer && !observer.visibleNodes.has(element)) {\n observer.visibleNodes.add(element);\n\n return () => {\n observer.visibleNodes.delete(element);\n };\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,gBACJ,OAAO,gBAAgB,eAAe,WAAW,YAAY;AAE/D,SAAS,oBAAoB,MAAyC;CACpE,OACE,KAAK,QAAQ,kBAAkB,UAC/B,KAAK,QAAQ,sBAAsB,KAAA;AAEvC;AASA,MAAM,8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I,oBAAoB,cAAc,GAAG,EAAE,GAAG;GAC5C,cAAc,IAAI;GAElB,IAAI,cAAc,QAChB,cAAc,GAAG,EAAE,CAAC,EAAE,QAAQ;EAElC,OACE,cAAc,OAAO,cAAc,QAAQ,eAAe,GAAG,CAAC;CAElE;AACF;AAEA,SAAgB,YAAY,SAA4C;CACtE,MAAM,WAAW,cAAc,GAAG,EAAE;CAEpC,IAAI,YAAY,CAAC,SAAS,aAAa,IAAI,OAAO,GAAG;EACnD,SAAS,aAAa,IAAI,OAAO;EAEjC,aAAa;GACX,SAAS,aAAa,OAAO,OAAO;EACtC;CACF;AAGF"}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { getTruthyValue, isTruthy } from "../utils/truthy.js";
|
|
18
18
|
import { isPresent } from "../utils/is-present.js";
|
|
19
|
-
import { nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
19
|
+
import { getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
|
|
20
20
|
import { requireValue } from "../utils/require-value.js";
|
|
21
21
|
import { isWebKit } from "../utils/platform.js";
|
|
22
22
|
import { clamp } from "@solid2-aria/stately/utils/number";
|
|
@@ -316,8 +316,8 @@ function getContainingBlock(node) {
|
|
|
316
316
|
let { offsetParent } = node;
|
|
317
317
|
if (offsetParent && offsetParent === document.body && window.getComputedStyle(offsetParent).position === "static" && !isContainingBlock(offsetParent)) offsetParent = document.documentElement;
|
|
318
318
|
if (!isPresent(offsetParent)) {
|
|
319
|
-
offsetParent = node
|
|
320
|
-
while (offsetParent && !isContainingBlock(offsetParent)) offsetParent = offsetParent
|
|
319
|
+
offsetParent = getParentElement(node);
|
|
320
|
+
while (offsetParent && !isContainingBlock(offsetParent)) offsetParent = getParentElement(offsetParent);
|
|
321
321
|
}
|
|
322
322
|
return getTruthyValue(offsetParent) ?? document.documentElement;
|
|
323
323
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-position.js","names":[],"sources":["../../../src/overlays/calculate-position.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/overlays/calculatePosition.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { clamp } from \"@solid2-aria/stately/utils/number\";\n\nimport { isPresent } from \"../utils/is-present\";\nimport { isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport { nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport type {\n Placement,\n PlacementAxis,\n SizeAxis,\n} from \"./create-overlay-position\";\n\ninterface Position {\n top?: number;\n left?: number;\n bottom?: number;\n right?: number;\n}\n\ninterface Dimensions {\n width: number;\n height: number;\n totalWidth: number;\n totalHeight: number;\n top: number;\n left: number;\n scroll: Pick<Offset, \"top\" | \"left\">;\n}\n\ntype CoordinateAxis = \"top\" | \"left\";\n\ntype Side = Exclude<PlacementAxis, \"center\">;\n\ninterface ParsedPlacement {\n placement: Side;\n crossPlacement: PlacementAxis;\n axis: CoordinateAxis;\n crossAxis: CoordinateAxis;\n size: SizeAxis;\n crossSize: SizeAxis;\n}\n\ninterface Offset {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface PositionOpts {\n arrowSize: number;\n placement: Placement;\n targetNode: Element;\n overlayNode: Element;\n scrollNode: Element;\n padding: number;\n shouldFlip: boolean;\n boundaryElement: Element;\n offset: number;\n crossOffset: number;\n maxHeight?: number;\n arrowBoundaryOffset?: number;\n targetRect?: Readonly<Offset> | null | undefined;\n}\n\ntype HeightGrowthDirection = \"top\" | \"bottom\";\n\nexport interface PositionResult {\n position: Position;\n arrowOffsetLeft?: number;\n arrowOffsetTop?: number;\n triggerAnchorPoint: {\n x: number;\n y: number;\n };\n maxHeight: number;\n placement: PlacementAxis;\n}\n\nconst AXIS = {\n bottom: \"top\",\n left: \"left\",\n right: \"left\",\n top: \"top\",\n} as const satisfies Record<Side, CoordinateAxis>;\n\nconst FLIPPED_DIRECTION = {\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n top: \"bottom\",\n} as const satisfies Record<Side, Side>;\n\nconst CROSS_AXIS = {\n left: \"top\",\n top: \"left\",\n} as const satisfies Record<CoordinateAxis, CoordinateAxis>;\n\nconst AXIS_SIZE = {\n left: \"width\",\n top: \"height\",\n} as const satisfies Record<CoordinateAxis, SizeAxis>;\n\nconst TOTAL_SIZE = {\n height: \"totalHeight\",\n width: \"totalWidth\",\n} as const satisfies Record<SizeAxis, keyof Dimensions>;\n\nconst PARSED_PLACEMENT_CACHE = new Map<Placement, ParsedPlacement>();\n\nconst getVisualViewport = () =>\n typeof document === \"undefined\" ? null : window.visualViewport;\n\nfunction getContainerDimensions(\n containerNode: Element,\n visualViewport: VisualViewport | null\n): Dimensions {\n let height = 0;\n let left = 0;\n let top = 0;\n let totalHeight = 0;\n let totalWidth = 0;\n let width = 0;\n\n const scroll = { left: 0, top: 0 };\n const isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n // In the case where the container is `html` or `body` and the container doesn't have something like `position: relative`,\n // then position absolute will be positioned relative to the viewport, also known as the `initial containing block`.\n // That's why we use the visual viewport instead.\n if (containerNode.tagName === \"BODY\" || containerNode.tagName === \"HTML\") {\n const { documentElement } = document;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n // Uses pageTop/pageLeft instead of offsetTop/offsetLeft because WebKit misreports those during pans.\n if (visualViewport) {\n top = Math.max(0, visualViewport.pageTop - scroll.top);\n left = Math.max(0, visualViewport.pageLeft - scroll.left);\n }\n } else {\n ({ width, height, top, left } = getOffset(containerNode, false));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (\n isWebKit() &&\n (containerNode.tagName === \"BODY\" || containerNode.tagName === \"HTML\") &&\n isPinchZoomedIn\n ) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return { height, left, scroll, top, totalHeight, totalWidth, width };\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n height: node.scrollHeight,\n left: node.scrollLeft,\n top: node.scrollTop,\n width: node.scrollWidth,\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: CoordinateAxis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n const containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n const boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n const boundaryStartEdge =\n containerOffsetWithBoundary[axis] +\n boundaryDimensions.scroll[AXIS[axis]] +\n padding;\n\n const boundaryEndEdge =\n containerOffsetWithBoundary[axis] +\n boundaryDimensions.scroll[AXIS[axis]] +\n boundarySize -\n padding;\n\n // transformed value of the left edge of the overlay\n const startEdgeOffset =\n offset -\n containerScroll +\n boundaryDimensions.scroll[AXIS[axis]] +\n containerOffsetWithBoundary[axis] -\n boundaryDimensions[AXIS[axis]];\n\n // transformed value of the right edge of the overlay\n const endEdgeOffset =\n offset -\n containerScroll +\n size +\n boundaryDimensions.scroll[AXIS[axis]] +\n containerOffsetWithBoundary[axis] -\n boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(\n boundaryEndEdge - endEdgeOffset,\n boundaryStartEdge - startEdgeOffset\n );\n }\n\n return 0;\n}\n\nfunction getMargins(node: Element): Position {\n const style = window.getComputedStyle(node);\n\n return {\n bottom: Math.trunc(Number(style.marginBottom)) || 0,\n left: Math.trunc(Number(style.marginLeft)) || 0,\n right: Math.trunc(Number(style.marginRight)) || 0,\n top: Math.trunc(Number(style.marginTop)) || 0,\n };\n}\n\nfunction isSide(value: string | undefined): value is Side {\n return (\n value === \"top\" ||\n value === \"bottom\" ||\n value === \"left\" ||\n value === \"right\"\n );\n}\n\nfunction parsedPlacement(\n placement: Side,\n crossPlacement: PlacementAxis\n): ParsedPlacement {\n const axis = AXIS[placement];\n const crossAxis = CROSS_AXIS[axis];\n\n return {\n axis,\n crossAxis,\n crossPlacement,\n crossSize: AXIS_SIZE[crossAxis],\n placement,\n size: AXIS_SIZE[axis],\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n const cached = PARSED_PLACEMENT_CACHE.get(input);\n\n if (cached) {\n return cached;\n }\n\n const [placement, crossPlacement] = input.split(\" \");\n\n if (!isSide(placement)) {\n throw new Error(\n `Overlay positioning requires a physical placement: ${input}`\n );\n }\n\n const parsed = parsedPlacement(\n placement,\n isSide(crossPlacement) ? crossPlacement : \"center\"\n );\n\n PARSED_PLACEMENT_CACHE.set(input, parsed);\n\n return parsed;\n}\n\n/* else {\n the overlay top should match the button top\n } */\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number,\n containerDimensions: Dimensions\n) {\n const { placement, crossPlacement, axis, crossAxis, size, crossSize } =\n placementInfo;\n\n const position: Position = {};\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n\n if (crossPlacement === \"center\") {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis] +=\n ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis] +=\n (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }\n\n position[crossAxis] += crossOffset;\n\n // overlay top or left overlapping arrow with button bottom or right\n const minPosition =\n childOffset[crossAxis] -\n overlaySize[crossSize] +\n arrowSize +\n arrowBoundaryOffset;\n\n // overlay bottom or right overlapping arrow with button top or left\n const maxPosition =\n childOffset[crossAxis] +\n childOffset[crossSize] -\n arrowSize -\n arrowBoundaryOffset;\n\n position[crossAxis] = clamp(position[crossAxis], minPosition, maxPosition);\n\n // Floor these so the position isn't placed on a partial pixel, only whole pixels. Shouldn't matter if it was floored or ceiled, so chose one.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container.\n const containerHeight = isContainerPositioned\n ? containerDimensions[size]\n : containerDimensions[TOTAL_SIZE[size]];\n\n position[FLIPPED_DIRECTION[axis]] = Math.floor(\n containerHeight - childOffset[axis] + offset\n );\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection,\n containerDimensions: Dimensions,\n isContainerDescendentOfBoundary: boolean,\n visualViewport: VisualViewport | null\n) {\n // For cases where position is set via \"bottom\" instead of \"top\", we need to calculate the true overlay top\n // with respect to the container.\n const overlayTop =\n (position.top ??\n containerDimensions[TOTAL_SIZE.height] -\n (position.bottom ?? 0) -\n overlayHeight) - (containerDimensions.scroll.top ?? 0);\n\n // calculate the dimentions of the \"boundingRect\" which is most restrictive top/bottom of the boundaryRect and the visual view port\n const boundaryToContainerTransformOffset = isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary.top\n : 0;\n\n const boundingRect = {\n bottom: Math.min(\n boundaryDimensions.top +\n boundaryDimensions.height +\n boundaryToContainerTransformOffset,\n (visualViewport?.offsetTop ?? 0) + (visualViewport?.height ?? 0)\n ),\n // This should be boundary top in container coord system vs viewport top in container coord system\n // For the viewport top, there are several cases\n // 1. pinchzoom case where we want the viewports offset top as top here\n // 2. case where container is offset from the boundary and is contained by the boundary. In this case the top we want here is NOT 0, we want to take boundary's top even though is is a negative number OR the visual viewport, whichever is more restrictive\n top: Math.max(\n boundaryDimensions.top + boundaryToContainerTransformOffset,\n (visualViewport?.offsetTop ?? boundaryDimensions.top) +\n boundaryToContainerTransformOffset\n ),\n };\n\n // We want the distance between the bottom of the overlay to the top of the boundary\n // We want the distance between the top of the overlay to the bottom of the boundary\n const maxHeight =\n heightGrowthDirection === \"top\"\n ? Math.max(\n 0,\n overlayTop +\n // this is the bottom of the overlay\n overlayHeight -\n // this is the top of the boundary\n boundingRect.top -\n // save additional space for margin and padding\n ((margins.top ?? 0) + (margins.bottom ?? 0) + padding)\n )\n : Math.max(\n 0,\n // this is the bottom of the boundary\n boundingRect.bottom -\n // this is the top of the overlay\n overlayTop -\n // save additional space for margin and padding\n ((margins.top ?? 0) + (margins.bottom ?? 0) + padding)\n );\n\n return maxHeight;\n}\n\n// overlay <-> boundary\n// overlay\n// trigger, position based of container's non-viewport 0,0\n// boundary\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement,\n containerDimensions: Dimensions,\n isContainerDescendentOfBoundary: boolean\n) {\n const { placement, axis, size } = placementInfo;\n\n if (placement === axis) {\n // boundary start\n return Math.max(\n 0,\n // trigger start\n childOffset[axis] -\n // transform trigger position to be with respect to viewport 0,0\n (containerDimensions.scroll[axis] ?? 0) -\n (boundaryDimensions[axis] +\n (isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary[axis]\n : 0)) -\n // margins usually for arrows or other decorations\n (margins[axis] ?? 0) -\n (margins[FLIPPED_DIRECTION[axis]] ?? 0) -\n padding\n // padding between overlay and boundary\n );\n }\n\n return Math.max(\n 0,\n boundaryDimensions[size] +\n boundaryDimensions[axis] +\n (isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary[axis]\n : 0) -\n childOffset[axis] -\n childOffset[size] +\n (containerDimensions.scroll[axis] ?? 0) -\n (margins[axis] ?? 0) -\n (margins[FLIPPED_DIRECTION[axis]] ?? 0) -\n padding\n );\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number,\n isContainerDescendentOfBoundary: boolean,\n visualViewport: VisualViewport | null\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n const destructured0 = placementInfo;\n const { size, crossAxis, crossSize } = destructured0;\n const { placement, crossPlacement } = destructured0;\n\n let position = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n placementInfo,\n offset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n\n let normalizedOffset = offset;\n\n const space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo,\n containerDimensions,\n isContainerDescendentOfBoundary\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && overlaySize[size] > space) {\n const flippedPlacementInfo = parsedPlacement(\n FLIPPED_DIRECTION[placement],\n crossPlacement\n );\n\n const flippedPosition = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n flippedPlacementInfo,\n offset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n\n const flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo,\n containerDimensions,\n isContainerDescendentOfBoundary\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n const heightGrowthDirection = getHeightGrowthDirection(placementInfo);\n\n let delta = getDelta(\n crossAxis,\n requireValue(position[crossAxis], \"Expected position[crossAxis]\"),\n overlaySize[crossSize],\n boundaryDimensions,\n containerDimensions,\n padding,\n containerOffsetWithBoundary\n );\n\n position[crossAxis] =\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") + delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection,\n containerDimensions,\n isContainerDescendentOfBoundary,\n visualViewport\n );\n\n if (isTruthy(userSetMaxHeight) && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n position = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n placementInfo,\n normalizedOffset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n delta = getDelta(\n crossAxis,\n requireValue(position[crossAxis], \"Expected position[crossAxis]\"),\n overlaySize[crossSize],\n boundaryDimensions,\n containerDimensions,\n padding,\n containerOffsetWithBoundary\n );\n position[crossAxis] =\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") + delta;\n\n const arrow = getArrowGeometry({\n arrowBoundaryOffset,\n arrowSize,\n childOffset,\n margins,\n overlaySize,\n placementInfo,\n position,\n });\n\n return {\n arrowOffsetLeft: arrow.arrowOffsetLeft,\n arrowOffsetTop: arrow.arrowOffsetTop,\n maxHeight,\n placement: placementInfo.placement,\n position,\n triggerAnchorPoint: arrow.triggerAnchorPoint,\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional\n * indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n const {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset = 0,\n targetRect,\n } = opts;\n\n const visualViewport = getVisualViewport();\n\n const container =\n overlayNode instanceof HTMLElement\n ? getContainingBlock(overlayNode)\n : document.documentElement;\n\n const isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n\n const isContainerPositioned =\n !!containerPositionStyle && containerPositionStyle !== \"static\";\n\n const childOffset: Offset = isViewportContainer\n ? getOffset(targetNode, false, targetRect)\n : getPosition(targetNode, container, false, targetRect);\n\n if (!isViewportContainer) {\n const { marginTop, marginLeft } = window.getComputedStyle(targetNode);\n childOffset.top += Math.trunc(Number(marginTop)) || 0;\n childOffset.left += Math.trunc(Number(marginLeft)) || 0;\n }\n\n const overlaySize: Offset = getOffset(overlayNode, true);\n const margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n const scrollSize = getScroll(scrollNode);\n\n // Note that due to logic inside getContainerDimensions, for cases where the boundary element is the body, we will return\n // a height/width that matches the visual viewport size rather than the body's height/width (aka for zoom it will be zoom adjusted size)\n // and a top/left that is adjusted as well (will return the top/left of the zoomed in viewport, or 0,0 for a non-zoomed body)\n // Otherwise this returns the height/width of a arbitrary boundary element, and its top/left with respect to the viewport (NOTE THIS MEANS IT DOESNT INCLUDE SCROLL)\n const boundaryDimensions = getContainerDimensions(\n boundaryElement,\n visualViewport\n );\n\n const containerDimensions = getContainerDimensions(container, visualViewport);\n // There are several difference cases of how to calculate the containerOffsetWithBoundary:\n // - boundaryElement is body or HTML and the container is an arbitrary element in the boundary (aka submenu with parent menu as container in v3)\n // - boundaryElement and container are both body or HTML element (aka standard popover case)\n // - boundaryElement is customized by the user. Container can also be arbitrary (either body/HTML or some other element)\n // containerOffsetWithBoundary should always return a value that is the boundary's coordinate offset with respect to the container coord system (container is 0, 0)\n let containerOffsetWithBoundary: Offset;\n\n if (\n (boundaryElement.tagName === \"BODY\" ||\n boundaryElement.tagName === \"HTML\") &&\n !isViewportContainer\n ) {\n // Use getRect instead of getOffset because boundaryDimensions for BODY/HTML is in viewport coordinate space,\n // not document coordinate space\n const containerRect = getRect(container, false);\n // the offset should be negative because if container is at viewport position x,y, then viewport top (aka 0)\n // is at position -x,y in container-relative coordinates\n containerOffsetWithBoundary = {\n height: 0,\n left: -(containerRect.left - boundaryDimensions.left),\n top: -(containerRect.top - boundaryDimensions.top),\n width: 0,\n };\n } else if (\n (boundaryElement.tagName === \"BODY\" ||\n boundaryElement.tagName === \"HTML\") &&\n isViewportContainer\n ) {\n // both are the same viewport container, no offset needed\n containerOffsetWithBoundary = { height: 0, left: 0, top: 0, width: 0 };\n } else {\n // This returns the boundary's coordinate with respect to the container. This case captures cases such as when you provide a custom boundary\n // like in ScrollingBoundaryContainerExample in Popover.stories.\n containerOffsetWithBoundary = getPosition(\n boundaryElement,\n container,\n false\n );\n }\n\n const isContainerDescendentOfBoundary = nodeContains(\n boundaryElement,\n container\n );\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset,\n isContainerDescendentOfBoundary,\n visualViewport\n );\n}\n\nexport function getRect(node: Element, ignoreScale: boolean) {\n const destructured1 = node.getBoundingClientRect();\n const { top, left } = destructured1;\n let { width, height } = destructured1;\n\n // Use offsetWidth and offsetHeight if this is an HTML element, so that\n // the size is not affected by scale transforms.\n if (\n ignoreScale &&\n node instanceof\n requireValue(\n node.ownerDocument.defaultView,\n \"Expected node.ownerDocument.defaultView\"\n ).HTMLElement\n ) {\n width = node.offsetWidth;\n height = node.offsetHeight;\n }\n\n return { height, left, top, width };\n}\n\nfunction getOffset(\n node: Element,\n ignoreScale: boolean,\n overrideRect?: Readonly<Offset> | null\n): Offset {\n const { top, left, width, height } =\n getTruthyValue(overrideRect) ?? getRect(node, ignoreScale);\n\n const { scrollTop, scrollLeft, clientTop, clientLeft } =\n document.documentElement;\n\n return {\n height,\n left: left + scrollLeft - clientLeft,\n top: top + scrollTop - clientTop,\n width,\n };\n}\n\nfunction getPosition(\n node: Element,\n parent: Element,\n ignoreScale: boolean,\n overrideRect?: Readonly<Offset> | null\n): Offset {\n const style = window.getComputedStyle(node);\n let offset: Offset;\n\n if (style.position === \"fixed\") {\n const { top, left, width, height } =\n getTruthyValue(overrideRect) ?? getRect(node, ignoreScale);\n\n offset = { height, left, top, width };\n } else {\n offset = getOffset(node, ignoreScale, overrideRect);\n const parentOffset = getOffset(parent, ignoreScale);\n const parentStyle = window.getComputedStyle(parent);\n parentOffset.top +=\n (Math.trunc(Number(parentStyle.borderTopWidth)) || 0) - parent.scrollTop;\n parentOffset.left +=\n (Math.trunc(Number(parentStyle.borderLeftWidth)) || 0) -\n parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= Math.trunc(Number(style.marginTop)) || 0;\n offset.left -= Math.trunc(Number(style.marginLeft)) || 0;\n\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let { offsetParent } = node;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === \"static\" &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // Follow-up(later): handle table elements?\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (!isPresent(offsetParent)) {\n offsetParent = node.parentElement;\n\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = offsetParent.parentElement;\n }\n }\n\n // Fall back to the viewport.\n return getTruthyValue(offsetParent) ?? document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n const style = window.getComputedStyle(node);\n\n return (\n style.transform !== \"none\" ||\n /transform|perspective/u.test(style.willChange) ||\n style.filter !== \"none\" ||\n style.contain === \"paint\" ||\n (\"backdropFilter\" in style && style.backdropFilter !== \"none\") ||\n (\"WebkitBackdropFilter\" in style && style.WebkitBackdropFilter !== \"none\")\n );\n}\n\nfunction getHeightGrowthDirection(\n placementInfo: ParsedPlacement\n): HeightGrowthDirection {\n let heightGrowthDirection: HeightGrowthDirection = \"bottom\";\n\n if (placementInfo.axis === \"top\") {\n if (placementInfo.placement === \"top\") {\n heightGrowthDirection = \"top\";\n } else if (placementInfo.placement === \"bottom\") {\n heightGrowthDirection = \"bottom\";\n }\n } else if (placementInfo.crossAxis === \"top\") {\n if (placementInfo.crossPlacement === \"top\") {\n heightGrowthDirection = \"bottom\";\n } else if (placementInfo.crossPlacement === \"bottom\") {\n heightGrowthDirection = \"top\";\n }\n }\n\n return heightGrowthDirection;\n}\n\ninterface ArrowGeometryOptions {\n placementInfo: ParsedPlacement;\n childOffset: Offset;\n overlaySize: Offset;\n position: Position;\n margins: Position;\n arrowSize: number;\n arrowBoundaryOffset: number;\n}\n\nfunction getArrowGeometry(\n options: ArrowGeometryOptions\n): Pick<\n PositionResult,\n \"arrowOffsetLeft\" | \"arrowOffsetTop\" | \"triggerAnchorPoint\"\n> {\n const {\n placementInfo,\n childOffset,\n overlaySize,\n position,\n margins,\n arrowSize,\n arrowBoundaryOffset,\n } = options;\n\n const { placement, crossPlacement, size, crossAxis, crossSize } =\n placementInfo;\n\n const arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // childOffset[crossAxis] + .5 * childOffset[crossSize] = absolute position with respect to the trigger's coordinate system that would place the arrow in the center of the trigger\n // position[crossAxis] - (margins[AXIS[crossAxis]] ?? 0) = value use to transform the position to a value with respect to the overlay's coordinate system. A child element's (aka arrow) position absolute's \"0\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin =\n childOffset[crossAxis] -\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") -\n (margins[AXIS[crossAxis]] ?? 0);\n\n const preferredArrowPosition = origin + 0.5 * childOffset[crossSize];\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin =\n AXIS[crossAxis] === \"left\"\n ? (margins.left ?? 0) + (margins.right ?? 0)\n : (margins.top ?? 0) + (margins.bottom ?? 0);\n\n const arrowMaxPosition =\n overlaySize[crossSize] -\n overlayMargin -\n arrowSize / 2 -\n arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge =\n childOffset[crossAxis] +\n arrowSize / 2 -\n (requireValue(position[crossAxis], \"Expected position[crossAxis]\") +\n (margins[AXIS[crossAxis]] ?? 0));\n\n const arrowOverlappingChildMaxEdge =\n childOffset[crossAxis] +\n childOffset[crossSize] -\n arrowSize / 2 -\n (requireValue(position[crossAxis], \"Expected position[crossAxis]\") +\n (margins[AXIS[crossAxis]] ?? 0));\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(\n preferredArrowPosition,\n arrowOverlappingChildMinEdge,\n arrowOverlappingChildMaxEdge\n );\n\n arrowPosition[crossAxis] = clamp(\n arrowPositionOverlappingChild,\n arrowMinPosition,\n arrowMaxPosition\n );\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n\n if (arrowSize) {\n origin = requireValue(\n arrowPosition[crossAxis],\n \"Expected arrowPosition[crossAxis]\"\n );\n } else if (crossPlacement === \"right\") {\n origin += childOffset[crossSize];\n } else if (crossPlacement === \"center\") {\n origin += childOffset[crossSize] / 2;\n }\n\n const crossOrigin =\n placement === \"left\" || placement === \"top\" ? overlaySize[size] : 0;\n\n const triggerAnchorPoint = {\n x: placement === \"top\" || placement === \"bottom\" ? origin : crossOrigin,\n y: placement === \"left\" || placement === \"right\" ? origin : crossOrigin,\n };\n\n return {\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n triggerAnchorPoint,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiGA,MAAM,OAAO;CACX,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;AACP;AAEA,MAAM,oBAAoB;CACxB,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;AACP;AAEA,MAAM,aAAa;CACjB,MAAM;CACN,KAAK;AACP;AAEA,MAAM,YAAY;CAChB,MAAM;CACN,KAAK;AACP;AAEA,MAAM,aAAa;CACjB,QAAQ;CACR,OAAO;AACT;AAEA,MAAM,yCAAyB,IAAI,IAAgC;AAEnE,MAAM,0BACJ,OAAO,aAAa,cAAc,OAAO,OAAO;AAElD,SAAS,uBACP,eACA,gBACY;CACZ,IAAI,SAAS;CACb,IAAI,OAAO;CACX,IAAI,MAAM;CACV,IAAI,cAAc;CAClB,IAAI,aAAa;CACjB,IAAI,QAAQ;CAEZ,MAAM,SAAS;EAAE,MAAM;EAAG,KAAK;CAAE;CACjC,MAAM,mBAAmB,gBAAgB,SAAS,KAAK;CAKvD,IAAI,cAAc,YAAY,UAAU,cAAc,YAAY,QAAQ;EACxE,MAAM,EAAE,oBAAoB;EAC5B,aAAa,gBAAgB;EAC7B,cAAc,gBA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,8BACA,4BACF;CAEA,cAAc,aAAa,MACzB,+BACA,kBACA,gBACF;CAIA,IAAI,WACF,SAAS,aACP,cAAc,YACd,mCACF;MACK,IAAI,mBAAmB,SAC5B,UAAU,YAAY;MACjB,IAAI,mBAAmB,UAC5B,UAAU,YAAY,aAAa;CAGrC,MAAM,cACJ,cAAc,UAAU,cAAc,QAAQ,YAAY,QAAQ;CAEpE,MAAM,qBAAqB;EACzB,GAAG,cAAc,SAAS,cAAc,WAAW,SAAS;EAC5D,GAAG,cAAc,UAAU,cAAc,UAAU,SAAS;CAC9D;CAEA,OAAO;EACL,iBAAiB,cAAc;EAC/B,gBAAgB,cAAc;EAC9B;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"calculate-position.js","names":[],"sources":["../../../src/overlays/calculate-position.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/overlays/calculatePosition.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport { clamp } from \"@solid2-aria/stately/utils/number\";\n\nimport { isPresent } from \"../utils/is-present\";\nimport { isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport type {\n Placement,\n PlacementAxis,\n SizeAxis,\n} from \"./create-overlay-position\";\n\ninterface Position {\n top?: number;\n left?: number;\n bottom?: number;\n right?: number;\n}\n\ninterface Dimensions {\n width: number;\n height: number;\n totalWidth: number;\n totalHeight: number;\n top: number;\n left: number;\n scroll: Pick<Offset, \"top\" | \"left\">;\n}\n\ntype CoordinateAxis = \"top\" | \"left\";\n\ntype Side = Exclude<PlacementAxis, \"center\">;\n\ninterface ParsedPlacement {\n placement: Side;\n crossPlacement: PlacementAxis;\n axis: CoordinateAxis;\n crossAxis: CoordinateAxis;\n size: SizeAxis;\n crossSize: SizeAxis;\n}\n\ninterface Offset {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\ninterface PositionOpts {\n arrowSize: number;\n placement: Placement;\n targetNode: Element;\n overlayNode: Element;\n scrollNode: Element;\n padding: number;\n shouldFlip: boolean;\n boundaryElement: Element;\n offset: number;\n crossOffset: number;\n maxHeight?: number;\n arrowBoundaryOffset?: number;\n targetRect?: Readonly<Offset> | null | undefined;\n}\n\ntype HeightGrowthDirection = \"top\" | \"bottom\";\n\nexport interface PositionResult {\n position: Position;\n arrowOffsetLeft?: number;\n arrowOffsetTop?: number;\n triggerAnchorPoint: {\n x: number;\n y: number;\n };\n maxHeight: number;\n placement: PlacementAxis;\n}\n\nconst AXIS = {\n bottom: \"top\",\n left: \"left\",\n right: \"left\",\n top: \"top\",\n} as const satisfies Record<Side, CoordinateAxis>;\n\nconst FLIPPED_DIRECTION = {\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n top: \"bottom\",\n} as const satisfies Record<Side, Side>;\n\nconst CROSS_AXIS = {\n left: \"top\",\n top: \"left\",\n} as const satisfies Record<CoordinateAxis, CoordinateAxis>;\n\nconst AXIS_SIZE = {\n left: \"width\",\n top: \"height\",\n} as const satisfies Record<CoordinateAxis, SizeAxis>;\n\nconst TOTAL_SIZE = {\n height: \"totalHeight\",\n width: \"totalWidth\",\n} as const satisfies Record<SizeAxis, keyof Dimensions>;\n\nconst PARSED_PLACEMENT_CACHE = new Map<Placement, ParsedPlacement>();\n\nconst getVisualViewport = () =>\n typeof document === \"undefined\" ? null : window.visualViewport;\n\nfunction getContainerDimensions(\n containerNode: Element,\n visualViewport: VisualViewport | null\n): Dimensions {\n let height = 0;\n let left = 0;\n let top = 0;\n let totalHeight = 0;\n let totalWidth = 0;\n let width = 0;\n\n const scroll = { left: 0, top: 0 };\n const isPinchZoomedIn = (visualViewport?.scale ?? 1) > 1;\n\n // In the case where the container is `html` or `body` and the container doesn't have something like `position: relative`,\n // then position absolute will be positioned relative to the viewport, also known as the `initial containing block`.\n // That's why we use the visual viewport instead.\n if (containerNode.tagName === \"BODY\" || containerNode.tagName === \"HTML\") {\n const { documentElement } = document;\n totalWidth = documentElement.clientWidth;\n totalHeight = documentElement.clientHeight;\n width = visualViewport?.width ?? totalWidth;\n height = visualViewport?.height ?? totalHeight;\n scroll.top = documentElement.scrollTop || containerNode.scrollTop;\n scroll.left = documentElement.scrollLeft || containerNode.scrollLeft;\n\n // The goal of the below is to get a top/left value that represents the top/left of the visual viewport with\n // respect to the layout viewport origin. This combined with the scrollTop/scrollLeft will allow us to calculate\n // coordinates/values with respect to the visual viewport or with respect to the layout viewport.\n // Uses pageTop/pageLeft instead of offsetTop/offsetLeft because WebKit misreports those during pans.\n if (visualViewport) {\n top = Math.max(0, visualViewport.pageTop - scroll.top);\n left = Math.max(0, visualViewport.pageLeft - scroll.left);\n }\n } else {\n ({ width, height, top, left } = getOffset(containerNode, false));\n scroll.top = containerNode.scrollTop;\n scroll.left = containerNode.scrollLeft;\n totalWidth = width;\n totalHeight = height;\n }\n\n if (\n isWebKit() &&\n (containerNode.tagName === \"BODY\" || containerNode.tagName === \"HTML\") &&\n isPinchZoomedIn\n ) {\n // Safari will report a non-zero scrollTop/Left for the non-scrolling body/HTML element when pinch zoomed in unlike other browsers.\n // Set to zero for parity calculations so we get consistent positioning of overlays across all browsers.\n // Also switch to visualViewport.pageTop/pageLeft so that we still accomodate for scroll positioning for body/HTML elements that are actually scrollable\n // before pinch zoom happens\n scroll.top = 0;\n scroll.left = 0;\n top = visualViewport?.pageTop ?? 0;\n left = visualViewport?.pageLeft ?? 0;\n }\n\n return { height, left, scroll, top, totalHeight, totalWidth, width };\n}\n\nfunction getScroll(node: Element): Offset {\n return {\n height: node.scrollHeight,\n left: node.scrollLeft,\n top: node.scrollTop,\n width: node.scrollWidth,\n };\n}\n\n// Determines the amount of space required when moving the overlay to ensure it remains in the boundary\nfunction getDelta(\n axis: CoordinateAxis,\n offset: number,\n size: number,\n // The dimensions of the boundary element that the popover is\n // positioned within (most of the time this is the <body>).\n boundaryDimensions: Dimensions,\n // The dimensions of the containing block element that the popover is\n // positioned relative to (e.g. parent with position: relative).\n // Usually this is the same as the boundary element, but if the popover\n // is portaled somewhere other than the body and has an ancestor with\n // position: relative/absolute, it will be different.\n containerDimensions: Dimensions,\n padding: number,\n containerOffsetWithBoundary: Offset\n) {\n const containerScroll = containerDimensions.scroll[axis] ?? 0;\n // The height/width of the boundary. Matches the axis along which we are adjusting the overlay position\n const boundarySize = boundaryDimensions[AXIS_SIZE[axis]];\n\n // Calculate the edges of the boundary (accomodating for the boundary padding) and the edges of the overlay.\n // Note that these values are with respect to the visual viewport (aka 0,0 is the top left of the viewport)\n const boundaryStartEdge =\n containerOffsetWithBoundary[axis] +\n boundaryDimensions.scroll[AXIS[axis]] +\n padding;\n\n const boundaryEndEdge =\n containerOffsetWithBoundary[axis] +\n boundaryDimensions.scroll[AXIS[axis]] +\n boundarySize -\n padding;\n\n // transformed value of the left edge of the overlay\n const startEdgeOffset =\n offset -\n containerScroll +\n boundaryDimensions.scroll[AXIS[axis]] +\n containerOffsetWithBoundary[axis] -\n boundaryDimensions[AXIS[axis]];\n\n // transformed value of the right edge of the overlay\n const endEdgeOffset =\n offset -\n containerScroll +\n size +\n boundaryDimensions.scroll[AXIS[axis]] +\n containerOffsetWithBoundary[axis] -\n boundaryDimensions[AXIS[axis]];\n\n // If any of the overlay edges falls outside of the boundary, shift the overlay the required amount to align one of the overlay's\n // edges with the closest boundary edge.\n if (startEdgeOffset < boundaryStartEdge) {\n return boundaryStartEdge - startEdgeOffset;\n } else if (endEdgeOffset > boundaryEndEdge) {\n return Math.max(\n boundaryEndEdge - endEdgeOffset,\n boundaryStartEdge - startEdgeOffset\n );\n }\n\n return 0;\n}\n\nfunction getMargins(node: Element): Position {\n const style = window.getComputedStyle(node);\n\n return {\n bottom: Math.trunc(Number(style.marginBottom)) || 0,\n left: Math.trunc(Number(style.marginLeft)) || 0,\n right: Math.trunc(Number(style.marginRight)) || 0,\n top: Math.trunc(Number(style.marginTop)) || 0,\n };\n}\n\nfunction isSide(value: string | undefined): value is Side {\n return (\n value === \"top\" ||\n value === \"bottom\" ||\n value === \"left\" ||\n value === \"right\"\n );\n}\n\nfunction parsedPlacement(\n placement: Side,\n crossPlacement: PlacementAxis\n): ParsedPlacement {\n const axis = AXIS[placement];\n const crossAxis = CROSS_AXIS[axis];\n\n return {\n axis,\n crossAxis,\n crossPlacement,\n crossSize: AXIS_SIZE[crossAxis],\n placement,\n size: AXIS_SIZE[axis],\n };\n}\n\nfunction parsePlacement(input: Placement): ParsedPlacement {\n const cached = PARSED_PLACEMENT_CACHE.get(input);\n\n if (cached) {\n return cached;\n }\n\n const [placement, crossPlacement] = input.split(\" \");\n\n if (!isSide(placement)) {\n throw new Error(\n `Overlay positioning requires a physical placement: ${input}`\n );\n }\n\n const parsed = parsedPlacement(\n placement,\n isSide(crossPlacement) ? crossPlacement : \"center\"\n );\n\n PARSED_PLACEMENT_CACHE.set(input, parsed);\n\n return parsed;\n}\n\n/* else {\n the overlay top should match the button top\n } */\nfunction computePosition(\n childOffset: Offset,\n boundaryDimensions: Dimensions,\n overlaySize: Offset,\n placementInfo: ParsedPlacement,\n offset: number,\n crossOffset: number,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n arrowSize: number,\n arrowBoundaryOffset: number,\n containerDimensions: Dimensions\n) {\n const { placement, crossPlacement, axis, crossAxis, size, crossSize } =\n placementInfo;\n\n const position: Position = {};\n // button position\n position[crossAxis] = childOffset[crossAxis] ?? 0;\n\n if (crossPlacement === \"center\") {\n // + (button size / 2) - (overlay size / 2)\n // at this point the overlay center should match the button center\n position[crossAxis] +=\n ((childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0)) / 2;\n } else if (crossPlacement !== crossAxis) {\n // + (button size) - (overlay size)\n // at this point the overlay bottom should match the button bottom\n position[crossAxis] +=\n (childOffset[crossSize] ?? 0) - (overlaySize[crossSize] ?? 0);\n }\n\n position[crossAxis] += crossOffset;\n\n // overlay top or left overlapping arrow with button bottom or right\n const minPosition =\n childOffset[crossAxis] -\n overlaySize[crossSize] +\n arrowSize +\n arrowBoundaryOffset;\n\n // overlay bottom or right overlapping arrow with button top or left\n const maxPosition =\n childOffset[crossAxis] +\n childOffset[crossSize] -\n arrowSize -\n arrowBoundaryOffset;\n\n position[crossAxis] = clamp(position[crossAxis], minPosition, maxPosition);\n\n // Floor these so the position isn't placed on a partial pixel, only whole pixels. Shouldn't matter if it was floored or ceiled, so chose one.\n if (placement === axis) {\n // If the container is positioned (non-static), then we use the container's actual\n // height, as `bottom` will be relative to this height. But if the container is static,\n // then it can only be the `document.body`, and `bottom` will be relative to _its_\n // container.\n const containerHeight = isContainerPositioned\n ? containerDimensions[size]\n : containerDimensions[TOTAL_SIZE[size]];\n\n position[FLIPPED_DIRECTION[axis]] = Math.floor(\n containerHeight - childOffset[axis] + offset\n );\n } else {\n position[axis] = Math.floor(childOffset[axis] + childOffset[size] + offset);\n }\n\n return position;\n}\n\nfunction getMaxHeight(\n position: Position,\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n isContainerPositioned: boolean,\n margins: Position,\n padding: number,\n overlayHeight: number,\n heightGrowthDirection: HeightGrowthDirection,\n containerDimensions: Dimensions,\n isContainerDescendentOfBoundary: boolean,\n visualViewport: VisualViewport | null\n) {\n // For cases where position is set via \"bottom\" instead of \"top\", we need to calculate the true overlay top\n // with respect to the container.\n const overlayTop =\n (position.top ??\n containerDimensions[TOTAL_SIZE.height] -\n (position.bottom ?? 0) -\n overlayHeight) - (containerDimensions.scroll.top ?? 0);\n\n // calculate the dimentions of the \"boundingRect\" which is most restrictive top/bottom of the boundaryRect and the visual view port\n const boundaryToContainerTransformOffset = isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary.top\n : 0;\n\n const boundingRect = {\n bottom: Math.min(\n boundaryDimensions.top +\n boundaryDimensions.height +\n boundaryToContainerTransformOffset,\n (visualViewport?.offsetTop ?? 0) + (visualViewport?.height ?? 0)\n ),\n // This should be boundary top in container coord system vs viewport top in container coord system\n // For the viewport top, there are several cases\n // 1. pinchzoom case where we want the viewports offset top as top here\n // 2. case where container is offset from the boundary and is contained by the boundary. In this case the top we want here is NOT 0, we want to take boundary's top even though is is a negative number OR the visual viewport, whichever is more restrictive\n top: Math.max(\n boundaryDimensions.top + boundaryToContainerTransformOffset,\n (visualViewport?.offsetTop ?? boundaryDimensions.top) +\n boundaryToContainerTransformOffset\n ),\n };\n\n // We want the distance between the bottom of the overlay to the top of the boundary\n // We want the distance between the top of the overlay to the bottom of the boundary\n const maxHeight =\n heightGrowthDirection === \"top\"\n ? Math.max(\n 0,\n overlayTop +\n // this is the bottom of the overlay\n overlayHeight -\n // this is the top of the boundary\n boundingRect.top -\n // save additional space for margin and padding\n ((margins.top ?? 0) + (margins.bottom ?? 0) + padding)\n )\n : Math.max(\n 0,\n // this is the bottom of the boundary\n boundingRect.bottom -\n // this is the top of the overlay\n overlayTop -\n // save additional space for margin and padding\n ((margins.top ?? 0) + (margins.bottom ?? 0) + padding)\n );\n\n return maxHeight;\n}\n\n// overlay <-> boundary\n// overlay\n// trigger, position based of container's non-viewport 0,0\n// boundary\nfunction getAvailableSpace(\n boundaryDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n childOffset: Offset,\n margins: Position,\n padding: number,\n placementInfo: ParsedPlacement,\n containerDimensions: Dimensions,\n isContainerDescendentOfBoundary: boolean\n) {\n const { placement, axis, size } = placementInfo;\n\n if (placement === axis) {\n // boundary start\n return Math.max(\n 0,\n // trigger start\n childOffset[axis] -\n // transform trigger position to be with respect to viewport 0,0\n (containerDimensions.scroll[axis] ?? 0) -\n (boundaryDimensions[axis] +\n (isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary[axis]\n : 0)) -\n // margins usually for arrows or other decorations\n (margins[axis] ?? 0) -\n (margins[FLIPPED_DIRECTION[axis]] ?? 0) -\n padding\n // padding between overlay and boundary\n );\n }\n\n return Math.max(\n 0,\n boundaryDimensions[size] +\n boundaryDimensions[axis] +\n (isContainerDescendentOfBoundary\n ? containerOffsetWithBoundary[axis]\n : 0) -\n childOffset[axis] -\n childOffset[size] +\n (containerDimensions.scroll[axis] ?? 0) -\n (margins[axis] ?? 0) -\n (margins[FLIPPED_DIRECTION[axis]] ?? 0) -\n padding\n );\n}\n\nexport function calculatePositionInternal(\n placementInput: Placement,\n childOffset: Offset,\n overlaySize: Offset,\n scrollSize: Offset,\n margins: Position,\n padding: number,\n flip: boolean,\n boundaryDimensions: Dimensions,\n containerDimensions: Dimensions,\n containerOffsetWithBoundary: Offset,\n offset: number,\n crossOffset: number,\n isContainerPositioned: boolean,\n userSetMaxHeight: number | undefined,\n arrowSize: number,\n arrowBoundaryOffset: number,\n isContainerDescendentOfBoundary: boolean,\n visualViewport: VisualViewport | null\n): PositionResult {\n let placementInfo = parsePlacement(placementInput);\n const destructured0 = placementInfo;\n const { size, crossAxis, crossSize } = destructured0;\n const { placement, crossPlacement } = destructured0;\n\n let position = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n placementInfo,\n offset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n\n let normalizedOffset = offset;\n\n const space = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n placementInfo,\n containerDimensions,\n isContainerDescendentOfBoundary\n );\n\n // Check if the scroll size of the overlay is greater than the available space to determine if we need to flip\n if (flip && overlaySize[size] > space) {\n const flippedPlacementInfo = parsedPlacement(\n FLIPPED_DIRECTION[placement],\n crossPlacement\n );\n\n const flippedPosition = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n flippedPlacementInfo,\n offset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n\n const flippedSpace = getAvailableSpace(\n boundaryDimensions,\n containerOffsetWithBoundary,\n childOffset,\n margins,\n padding + offset,\n flippedPlacementInfo,\n containerDimensions,\n isContainerDescendentOfBoundary\n );\n\n // If the available space for the flipped position is greater than the original available space, flip.\n if (flippedSpace > space) {\n placementInfo = flippedPlacementInfo;\n position = flippedPosition;\n normalizedOffset = offset;\n }\n }\n\n // Determine the direction the height of the overlay can grow so that we can choose how to calculate the max height\n const heightGrowthDirection = getHeightGrowthDirection(placementInfo);\n\n let delta = getDelta(\n crossAxis,\n requireValue(position[crossAxis], \"Expected position[crossAxis]\"),\n overlaySize[crossSize],\n boundaryDimensions,\n containerDimensions,\n padding,\n containerOffsetWithBoundary\n );\n\n position[crossAxis] =\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") + delta;\n\n let maxHeight = getMaxHeight(\n position,\n boundaryDimensions,\n containerOffsetWithBoundary,\n isContainerPositioned,\n margins,\n padding,\n overlaySize.height,\n heightGrowthDirection,\n containerDimensions,\n isContainerDescendentOfBoundary,\n visualViewport\n );\n\n if (isTruthy(userSetMaxHeight) && userSetMaxHeight < maxHeight) {\n maxHeight = userSetMaxHeight;\n }\n\n overlaySize.height = Math.min(overlaySize.height, maxHeight);\n position = computePosition(\n childOffset,\n boundaryDimensions,\n overlaySize,\n placementInfo,\n normalizedOffset,\n crossOffset,\n containerOffsetWithBoundary,\n isContainerPositioned,\n arrowSize,\n arrowBoundaryOffset,\n containerDimensions\n );\n delta = getDelta(\n crossAxis,\n requireValue(position[crossAxis], \"Expected position[crossAxis]\"),\n overlaySize[crossSize],\n boundaryDimensions,\n containerDimensions,\n padding,\n containerOffsetWithBoundary\n );\n position[crossAxis] =\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") + delta;\n\n const arrow = getArrowGeometry({\n arrowBoundaryOffset,\n arrowSize,\n childOffset,\n margins,\n overlaySize,\n placementInfo,\n position,\n });\n\n return {\n arrowOffsetLeft: arrow.arrowOffsetLeft,\n arrowOffsetTop: arrow.arrowOffsetTop,\n maxHeight,\n placement: placementInfo.placement,\n position,\n triggerAnchorPoint: arrow.triggerAnchorPoint,\n };\n}\n\n/**\n * Determines where to place the overlay with regards to the target and the position of an optional\n * indicator.\n */\nexport function calculatePosition(opts: PositionOpts): PositionResult {\n const {\n placement,\n targetNode,\n overlayNode,\n scrollNode,\n padding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset = 0,\n targetRect,\n } = opts;\n\n const visualViewport = getVisualViewport();\n\n const container =\n overlayNode instanceof HTMLElement\n ? getContainingBlock(overlayNode)\n : document.documentElement;\n\n const isViewportContainer = container === document.documentElement;\n const containerPositionStyle = window.getComputedStyle(container).position;\n\n const isContainerPositioned =\n !!containerPositionStyle && containerPositionStyle !== \"static\";\n\n const childOffset: Offset = isViewportContainer\n ? getOffset(targetNode, false, targetRect)\n : getPosition(targetNode, container, false, targetRect);\n\n if (!isViewportContainer) {\n const { marginTop, marginLeft } = window.getComputedStyle(targetNode);\n childOffset.top += Math.trunc(Number(marginTop)) || 0;\n childOffset.left += Math.trunc(Number(marginLeft)) || 0;\n }\n\n const overlaySize: Offset = getOffset(overlayNode, true);\n const margins = getMargins(overlayNode);\n overlaySize.width += (margins.left ?? 0) + (margins.right ?? 0);\n overlaySize.height += (margins.top ?? 0) + (margins.bottom ?? 0);\n const scrollSize = getScroll(scrollNode);\n\n // Note that due to logic inside getContainerDimensions, for cases where the boundary element is the body, we will return\n // a height/width that matches the visual viewport size rather than the body's height/width (aka for zoom it will be zoom adjusted size)\n // and a top/left that is adjusted as well (will return the top/left of the zoomed in viewport, or 0,0 for a non-zoomed body)\n // Otherwise this returns the height/width of a arbitrary boundary element, and its top/left with respect to the viewport (NOTE THIS MEANS IT DOESNT INCLUDE SCROLL)\n const boundaryDimensions = getContainerDimensions(\n boundaryElement,\n visualViewport\n );\n\n const containerDimensions = getContainerDimensions(container, visualViewport);\n // There are several difference cases of how to calculate the containerOffsetWithBoundary:\n // - boundaryElement is body or HTML and the container is an arbitrary element in the boundary (aka submenu with parent menu as container in v3)\n // - boundaryElement and container are both body or HTML element (aka standard popover case)\n // - boundaryElement is customized by the user. Container can also be arbitrary (either body/HTML or some other element)\n // containerOffsetWithBoundary should always return a value that is the boundary's coordinate offset with respect to the container coord system (container is 0, 0)\n let containerOffsetWithBoundary: Offset;\n\n if (\n (boundaryElement.tagName === \"BODY\" ||\n boundaryElement.tagName === \"HTML\") &&\n !isViewportContainer\n ) {\n // Use getRect instead of getOffset because boundaryDimensions for BODY/HTML is in viewport coordinate space,\n // not document coordinate space\n const containerRect = getRect(container, false);\n // the offset should be negative because if container is at viewport position x,y, then viewport top (aka 0)\n // is at position -x,y in container-relative coordinates\n containerOffsetWithBoundary = {\n height: 0,\n left: -(containerRect.left - boundaryDimensions.left),\n top: -(containerRect.top - boundaryDimensions.top),\n width: 0,\n };\n } else if (\n (boundaryElement.tagName === \"BODY\" ||\n boundaryElement.tagName === \"HTML\") &&\n isViewportContainer\n ) {\n // both are the same viewport container, no offset needed\n containerOffsetWithBoundary = { height: 0, left: 0, top: 0, width: 0 };\n } else {\n // This returns the boundary's coordinate with respect to the container. This case captures cases such as when you provide a custom boundary\n // like in ScrollingBoundaryContainerExample in Popover.stories.\n containerOffsetWithBoundary = getPosition(\n boundaryElement,\n container,\n false\n );\n }\n\n const isContainerDescendentOfBoundary = nodeContains(\n boundaryElement,\n container\n );\n\n return calculatePositionInternal(\n placement,\n childOffset,\n overlaySize,\n scrollSize,\n margins,\n padding,\n shouldFlip,\n boundaryDimensions,\n containerDimensions,\n containerOffsetWithBoundary,\n offset,\n crossOffset,\n isContainerPositioned,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset,\n isContainerDescendentOfBoundary,\n visualViewport\n );\n}\n\nexport function getRect(node: Element, ignoreScale: boolean) {\n const destructured1 = node.getBoundingClientRect();\n const { top, left } = destructured1;\n let { width, height } = destructured1;\n\n // Use offsetWidth and offsetHeight if this is an HTML element, so that\n // the size is not affected by scale transforms.\n if (\n ignoreScale &&\n node instanceof\n requireValue(\n node.ownerDocument.defaultView,\n \"Expected node.ownerDocument.defaultView\"\n ).HTMLElement\n ) {\n width = node.offsetWidth;\n height = node.offsetHeight;\n }\n\n return { height, left, top, width };\n}\n\nfunction getOffset(\n node: Element,\n ignoreScale: boolean,\n overrideRect?: Readonly<Offset> | null\n): Offset {\n const { top, left, width, height } =\n getTruthyValue(overrideRect) ?? getRect(node, ignoreScale);\n\n const { scrollTop, scrollLeft, clientTop, clientLeft } =\n document.documentElement;\n\n return {\n height,\n left: left + scrollLeft - clientLeft,\n top: top + scrollTop - clientTop,\n width,\n };\n}\n\nfunction getPosition(\n node: Element,\n parent: Element,\n ignoreScale: boolean,\n overrideRect?: Readonly<Offset> | null\n): Offset {\n const style = window.getComputedStyle(node);\n let offset: Offset;\n\n if (style.position === \"fixed\") {\n const { top, left, width, height } =\n getTruthyValue(overrideRect) ?? getRect(node, ignoreScale);\n\n offset = { height, left, top, width };\n } else {\n offset = getOffset(node, ignoreScale, overrideRect);\n const parentOffset = getOffset(parent, ignoreScale);\n const parentStyle = window.getComputedStyle(parent);\n parentOffset.top +=\n (Math.trunc(Number(parentStyle.borderTopWidth)) || 0) - parent.scrollTop;\n parentOffset.left +=\n (Math.trunc(Number(parentStyle.borderLeftWidth)) || 0) -\n parent.scrollLeft;\n offset.top -= parentOffset.top;\n offset.left -= parentOffset.left;\n }\n\n offset.top -= Math.trunc(Number(style.marginTop)) || 0;\n offset.left -= Math.trunc(Number(style.marginLeft)) || 0;\n\n return offset;\n}\n\n// Returns the containing block of an element, which is the element that\n// this element will be positioned relative to.\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block\nfunction getContainingBlock(node: HTMLElement): Element {\n // The offsetParent of an element in most cases equals the containing block.\n // https://w3c.github.io/csswg-drafts/cssom-view/#dom-htmlelement-offsetparent\n let { offsetParent } = node;\n\n // The offsetParent algorithm terminates at the document body,\n // even if the body is not a containing block. Double check that\n // and use the documentElement if so.\n if (\n offsetParent &&\n offsetParent === document.body &&\n window.getComputedStyle(offsetParent).position === \"static\" &&\n !isContainingBlock(offsetParent)\n ) {\n offsetParent = document.documentElement;\n }\n\n // Follow-up(later): handle table elements?\n // The offsetParent can be null if the element has position: fixed, or a few other cases.\n // We have to walk up the tree manually in this case because fixed positioned elements\n // are still positioned relative to their containing block, which is not always the viewport.\n if (!isPresent(offsetParent)) {\n offsetParent = getParentElement(node);\n\n while (offsetParent && !isContainingBlock(offsetParent)) {\n offsetParent = getParentElement(offsetParent);\n }\n }\n\n // Fall back to the viewport.\n return getTruthyValue(offsetParent) ?? document.documentElement;\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\nfunction isContainingBlock(node: Element): boolean {\n const style = window.getComputedStyle(node);\n\n return (\n style.transform !== \"none\" ||\n /transform|perspective/u.test(style.willChange) ||\n style.filter !== \"none\" ||\n style.contain === \"paint\" ||\n (\"backdropFilter\" in style && style.backdropFilter !== \"none\") ||\n (\"WebkitBackdropFilter\" in style && style.WebkitBackdropFilter !== \"none\")\n );\n}\n\nfunction getHeightGrowthDirection(\n placementInfo: ParsedPlacement\n): HeightGrowthDirection {\n let heightGrowthDirection: HeightGrowthDirection = \"bottom\";\n\n if (placementInfo.axis === \"top\") {\n if (placementInfo.placement === \"top\") {\n heightGrowthDirection = \"top\";\n } else if (placementInfo.placement === \"bottom\") {\n heightGrowthDirection = \"bottom\";\n }\n } else if (placementInfo.crossAxis === \"top\") {\n if (placementInfo.crossPlacement === \"top\") {\n heightGrowthDirection = \"bottom\";\n } else if (placementInfo.crossPlacement === \"bottom\") {\n heightGrowthDirection = \"top\";\n }\n }\n\n return heightGrowthDirection;\n}\n\ninterface ArrowGeometryOptions {\n placementInfo: ParsedPlacement;\n childOffset: Offset;\n overlaySize: Offset;\n position: Position;\n margins: Position;\n arrowSize: number;\n arrowBoundaryOffset: number;\n}\n\nfunction getArrowGeometry(\n options: ArrowGeometryOptions\n): Pick<\n PositionResult,\n \"arrowOffsetLeft\" | \"arrowOffsetTop\" | \"triggerAnchorPoint\"\n> {\n const {\n placementInfo,\n childOffset,\n overlaySize,\n position,\n margins,\n arrowSize,\n arrowBoundaryOffset,\n } = options;\n\n const { placement, crossPlacement, size, crossAxis, crossSize } =\n placementInfo;\n\n const arrowPosition: Position = {};\n\n // All values are transformed so that 0 is at the top/left of the overlay depending on the orientation\n // Prefer the arrow being in the center of the trigger/overlay anchor element\n // childOffset[crossAxis] + .5 * childOffset[crossSize] = absolute position with respect to the trigger's coordinate system that would place the arrow in the center of the trigger\n // position[crossAxis] - (margins[AXIS[crossAxis]] ?? 0) = value use to transform the position to a value with respect to the overlay's coordinate system. A child element's (aka arrow) position absolute's \"0\"\n // is positioned after the margin of its parent (aka overlay) so we need to subtract it to get the proper coordinate transform\n let origin =\n childOffset[crossAxis] -\n requireValue(position[crossAxis], \"Expected position[crossAxis]\") -\n (margins[AXIS[crossAxis]] ?? 0);\n\n const preferredArrowPosition = origin + 0.5 * childOffset[crossSize];\n // Min/Max position limits for the arrow with respect to the overlay\n const arrowMinPosition = arrowSize / 2 + arrowBoundaryOffset;\n\n // overlaySize[crossSize] - margins = true size of the overlay\n const overlayMargin =\n AXIS[crossAxis] === \"left\"\n ? (margins.left ?? 0) + (margins.right ?? 0)\n : (margins.top ?? 0) + (margins.bottom ?? 0);\n\n const arrowMaxPosition =\n overlaySize[crossSize] -\n overlayMargin -\n arrowSize / 2 -\n arrowBoundaryOffset;\n\n // Min/Max position limits for the arrow with respect to the trigger/overlay anchor element\n // Same margin accomodation done here as well as for the preferredArrowPosition\n const arrowOverlappingChildMinEdge =\n childOffset[crossAxis] +\n arrowSize / 2 -\n (requireValue(position[crossAxis], \"Expected position[crossAxis]\") +\n (margins[AXIS[crossAxis]] ?? 0));\n\n const arrowOverlappingChildMaxEdge =\n childOffset[crossAxis] +\n childOffset[crossSize] -\n arrowSize / 2 -\n (requireValue(position[crossAxis], \"Expected position[crossAxis]\") +\n (margins[AXIS[crossAxis]] ?? 0));\n\n // Clamp the arrow positioning so that it always is within the bounds of the anchor and the overlay\n const arrowPositionOverlappingChild = clamp(\n preferredArrowPosition,\n arrowOverlappingChildMinEdge,\n arrowOverlappingChildMaxEdge\n );\n\n arrowPosition[crossAxis] = clamp(\n arrowPositionOverlappingChild,\n arrowMinPosition,\n arrowMaxPosition\n );\n // If there is an arrow, use that as the origin so that animations are smooth.\n // Otherwise use the target edge.\n\n if (arrowSize) {\n origin = requireValue(\n arrowPosition[crossAxis],\n \"Expected arrowPosition[crossAxis]\"\n );\n } else if (crossPlacement === \"right\") {\n origin += childOffset[crossSize];\n } else if (crossPlacement === \"center\") {\n origin += childOffset[crossSize] / 2;\n }\n\n const crossOrigin =\n placement === \"left\" || placement === \"top\" ? overlaySize[size] : 0;\n\n const triggerAnchorPoint = {\n x: placement === \"top\" || placement === \"bottom\" ? origin : crossOrigin,\n y: placement === \"left\" || placement === \"right\" ? origin : crossOrigin,\n };\n\n return {\n arrowOffsetLeft: arrowPosition.left,\n arrowOffsetTop: arrowPosition.top,\n triggerAnchorPoint,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoGA,MAAM,OAAO;CACX,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;AACP;AAEA,MAAM,oBAAoB;CACxB,QAAQ;CACR,MAAM;CACN,OAAO;CACP,KAAK;AACP;AAEA,MAAM,aAAa;CACjB,MAAM;CACN,KAAK;AACP;AAEA,MAAM,YAAY;CAChB,MAAM;C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