@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.
Files changed (141) hide show
  1. package/README.md +14 -0
  2. package/dist/NOTICE.txt +33 -11
  3. package/dist/browser/actiongroup/create-action-group.js +2 -1
  4. package/dist/browser/actiongroup/create-action-group.js.map +1 -1
  5. package/dist/browser/combobox/create-combo-box.js +2 -2
  6. package/dist/browser/combobox/create-combo-box.js.map +1 -1
  7. package/dist/browser/dnd/drag-preview.js +7 -8
  8. package/dist/browser/dnd/drag-preview.js.map +1 -1
  9. package/dist/browser/focus/focus-scope.js +2 -2
  10. package/dist/browser/focus/focus-scope.js.map +1 -1
  11. package/dist/browser/focus/virtual-focus.d.ts +1 -0
  12. package/dist/browser/focus/virtual-focus.js +20 -5
  13. package/dist/browser/focus/virtual-focus.js.map +1 -1
  14. package/dist/browser/grid/create-grid-cell.js +4 -4
  15. package/dist/browser/grid/create-grid-cell.js.map +1 -1
  16. package/dist/browser/gridlist/create-grid-list-item.js +3 -3
  17. package/dist/browser/gridlist/create-grid-list-item.js.map +1 -1
  18. package/dist/browser/interactions/create-hover.js +6 -3
  19. package/dist/browser/interactions/create-hover.js.map +1 -1
  20. package/dist/browser/interactions/create-press.js +5 -4
  21. package/dist/browser/interactions/create-press.js.map +1 -1
  22. package/dist/browser/interactions/utils.js +4 -3
  23. package/dist/browser/interactions/utils.js.map +1 -1
  24. package/dist/browser/landmark/create-landmark.js +2 -2
  25. package/dist/browser/landmark/create-landmark.js.map +1 -1
  26. package/dist/browser/overlays/aria-hide-outside.js +5 -3
  27. package/dist/browser/overlays/aria-hide-outside.js.map +1 -1
  28. package/dist/browser/overlays/calculate-position.js +3 -3
  29. package/dist/browser/overlays/calculate-position.js.map +1 -1
  30. package/dist/browser/overlays/create-modal.js +15 -18
  31. package/dist/browser/overlays/create-modal.js.map +1 -1
  32. package/dist/browser/overlays/create-prevent-scroll.js +3 -3
  33. package/dist/browser/overlays/create-prevent-scroll.js.map +1 -1
  34. package/dist/browser/overlays/overlay.js +7 -8
  35. package/dist/browser/overlays/overlay.js.map +1 -1
  36. package/dist/browser/select/create-select.js +1 -1
  37. package/dist/browser/select/create-select.js.map +1 -1
  38. package/dist/browser/select/hidden-select.js +61 -64
  39. package/dist/browser/select/hidden-select.js.map +1 -1
  40. package/dist/browser/selection/create-selectable-item.js +2 -2
  41. package/dist/browser/selection/create-selectable-item.js.map +1 -1
  42. package/dist/browser/selection/create-type-select.js +11 -3
  43. package/dist/browser/selection/create-type-select.js.map +1 -1
  44. package/dist/browser/selection/list-keyboard-delegate.js +1 -1
  45. package/dist/browser/selection/list-keyboard-delegate.js.map +1 -1
  46. package/dist/browser/tokenfield/create-token-field.js +3 -3
  47. package/dist/browser/tokenfield/create-token-field.js.map +1 -1
  48. package/dist/browser/tokenfield/create-token.js +2 -1
  49. package/dist/browser/tokenfield/create-token.js.map +1 -1
  50. package/dist/browser/toolbar/create-toolbar.js +2 -2
  51. package/dist/browser/toolbar/create-toolbar.js.map +1 -1
  52. package/dist/browser/utils/dom-helpers.d.ts +2 -15
  53. package/dist/browser/utils/dom-helpers.js +1 -28
  54. package/dist/browser/utils/dom-helpers.js.map +1 -1
  55. package/dist/browser/utils/dom-value.js +2 -1
  56. package/dist/browser/utils/dom-value.js.map +1 -1
  57. package/dist/browser/utils/get-scroll-parent.js +3 -2
  58. package/dist/browser/utils/get-scroll-parent.js.map +1 -1
  59. package/dist/browser/utils/get-scroll-parents.js +2 -1
  60. package/dist/browser/utils/get-scroll-parents.js.map +1 -1
  61. package/dist/browser/utils/is-element-visible.js +3 -1
  62. package/dist/browser/utils/is-element-visible.js.map +1 -1
  63. package/dist/browser/utils/is-focusable.js +2 -1
  64. package/dist/browser/utils/is-focusable.js.map +1 -1
  65. package/dist/browser/utils/shadowdom/dom-functions.d.ts +8 -0
  66. package/dist/browser/utils/shadowdom/dom-functions.js +26 -7
  67. package/dist/browser/utils/shadowdom/dom-functions.js.map +1 -1
  68. package/dist/browser/utils/shadowdom/shadow-tree-walker.js +1 -1
  69. package/dist/browser/utils/shadowdom/shadow-tree-walker.js.map +1 -1
  70. package/dist/browser/utils/type-helpers.d.ts +42 -0
  71. package/dist/browser/utils/type-helpers.js +55 -0
  72. package/dist/browser/utils/type-helpers.js.map +1 -0
  73. package/dist/server/actiongroup/create-action-group.js +2 -1
  74. package/dist/server/actiongroup/create-action-group.js.map +1 -1
  75. package/dist/server/combobox/create-combo-box.js +2 -2
  76. package/dist/server/combobox/create-combo-box.js.map +1 -1
  77. package/dist/server/dnd/drag-preview.js +9 -12
  78. package/dist/server/dnd/drag-preview.js.map +1 -1
  79. package/dist/server/focus/focus-scope.js +2 -2
  80. package/dist/server/focus/focus-scope.js.map +1 -1
  81. package/dist/server/focus/virtual-focus.js +20 -5
  82. package/dist/server/focus/virtual-focus.js.map +1 -1
  83. package/dist/server/grid/create-grid-cell.js +4 -4
  84. package/dist/server/grid/create-grid-cell.js.map +1 -1
  85. package/dist/server/gridlist/create-grid-list-item.js +3 -3
  86. package/dist/server/gridlist/create-grid-list-item.js.map +1 -1
  87. package/dist/server/interactions/create-hover.js +6 -3
  88. package/dist/server/interactions/create-hover.js.map +1 -1
  89. package/dist/server/interactions/create-press.js +5 -4
  90. package/dist/server/interactions/create-press.js.map +1 -1
  91. package/dist/server/interactions/utils.js +4 -3
  92. package/dist/server/interactions/utils.js.map +1 -1
  93. package/dist/server/landmark/create-landmark.js +2 -2
  94. package/dist/server/landmark/create-landmark.js.map +1 -1
  95. package/dist/server/overlays/aria-hide-outside.js +5 -3
  96. package/dist/server/overlays/aria-hide-outside.js.map +1 -1
  97. package/dist/server/overlays/calculate-position.js +3 -3
  98. package/dist/server/overlays/calculate-position.js.map +1 -1
  99. package/dist/server/overlays/create-modal.js +7 -27
  100. package/dist/server/overlays/create-modal.js.map +1 -1
  101. package/dist/server/overlays/create-prevent-scroll.js +3 -3
  102. package/dist/server/overlays/create-prevent-scroll.js.map +1 -1
  103. package/dist/server/overlays/overlay.js +8 -18
  104. package/dist/server/overlays/overlay.js.map +1 -1
  105. package/dist/server/select/create-select.js +1 -1
  106. package/dist/server/select/create-select.js.map +1 -1
  107. package/dist/server/select/hidden-select.js +85 -138
  108. package/dist/server/select/hidden-select.js.map +1 -1
  109. package/dist/server/selection/create-selectable-item.js +2 -2
  110. package/dist/server/selection/create-selectable-item.js.map +1 -1
  111. package/dist/server/selection/create-type-select.js +11 -3
  112. package/dist/server/selection/create-type-select.js.map +1 -1
  113. package/dist/server/selection/list-keyboard-delegate.js +1 -1
  114. package/dist/server/selection/list-keyboard-delegate.js.map +1 -1
  115. package/dist/server/tokenfield/create-token-field.js +3 -3
  116. package/dist/server/tokenfield/create-token-field.js.map +1 -1
  117. package/dist/server/tokenfield/create-token.js +2 -1
  118. package/dist/server/tokenfield/create-token.js.map +1 -1
  119. package/dist/server/toolbar/create-toolbar.js +2 -2
  120. package/dist/server/toolbar/create-toolbar.js.map +1 -1
  121. package/dist/server/utils/dom-helpers.js +1 -28
  122. package/dist/server/utils/dom-helpers.js.map +1 -1
  123. package/dist/server/utils/dom-value.js +2 -1
  124. package/dist/server/utils/dom-value.js.map +1 -1
  125. package/dist/server/utils/get-scroll-parent.js +3 -2
  126. package/dist/server/utils/get-scroll-parent.js.map +1 -1
  127. package/dist/server/utils/get-scroll-parents.js +2 -1
  128. package/dist/server/utils/get-scroll-parents.js.map +1 -1
  129. package/dist/server/utils/is-element-visible.js +3 -1
  130. package/dist/server/utils/is-element-visible.js.map +1 -1
  131. package/dist/server/utils/is-focusable.js +2 -1
  132. package/dist/server/utils/is-focusable.js.map +1 -1
  133. package/dist/server/utils/shadowdom/dom-functions.js +26 -7
  134. package/dist/server/utils/shadowdom/dom-functions.js.map +1 -1
  135. package/dist/server/utils/shadowdom/shadow-tree-walker.js +1 -1
  136. package/dist/server/utils/shadowdom/shadow-tree-walker.js.map +1 -1
  137. package/dist/server/utils/type-helpers.js +55 -0
  138. package/dist/server/utils/type-helpers.js.map +1 -0
  139. package/dist/server/virtualizer/scroll-view.js +3 -1
  140. package/dist/server/virtualizer/scroll-view.js.map +1 -1
  141. package/package.json +16 -10
@@ -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,sBAAsB,KAAA;AAEvC;AASA,MAAM,8BAAc,IAAI,QAAyB;AASjD,MAAM,gBAAmC,CAAC;;;;;;;;;;AAY1C,SAAgB,gBACd,SACA,SACA;CACA,MAAM,YAAY,eAAe,UAAU,EAAE;CAE7C,MAAM,OACJ,mBAAmB,UAAU,UAAU,EAAE,MAAM,QAAQ,IAAI;CAE7D,MAAM,OAAO,MAAM,QAAQ,SAAS;CAEpC,MAAM,iBAAiB,WAAW,MAAM,sBAAsB,aAAa;CAE3E,MAAM,eAAe,IAAI,IAAa,OAAO;CAC7C,MAAM,8BAAc,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AS,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,8BAAc,IAAI,QAAyB;AASjD,MAAM,gBAAmC,CAAC;;;;;;;;;;AAY1C,SAAgB,gBACd,SACA,SACA;CACA,MAAM,YAAY,eAAe,UAAU,EAAE;CAE7C,MAAM,OACJ,mBAAmB,UAAU,UAAU,EAAE,MAAM,QAAQ,IAAI;CAE7D,MAAM,OAAO,MAAM,QAAQ,SAAS;CAEpC,MAAM,iBAAiB,WAAW,MAAM,sBAAsB,aAAa;CAE3E,MAAM,eAAe,IAAI,IAAa,OAAO;CAC7C,MAAM,8BAAc,IAAI,IAAa;CAErC,MAAM,aAAa,YACjB,SAA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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.parentElement;
320
- while (offsetParent && !isContainingBlock(offsetParent)) offsetParent = offsetParent.parentElement;
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":";;;;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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;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,gBAAgB;EAC9B,QAAQ,gBAAgB,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F;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"}
@@ -17,8 +17,8 @@
17
17
  import { isTruthy } from "../utils/truthy.js";
18
18
  import { requireValue } from "../utils/require-value.js";
19
19
  import { createUNSAFE_PortalContext } from "./portal-provider.js";
20
- import { Portal, mergeProps, ssrElement } from "@solidjs/web";
21
- import { Show, createContext, createEffect, createMemo, createSignal, omit, onSettled, useContext } from "solid-js";
20
+ import { Portal, memo, mergeProps, ssrElement } from "@solidjs/web";
21
+ import { createContext, createEffect, createMemo, createSignal, omit, onSettled, useContext } from "solid-js";
22
22
  // src/overlays/create-modal.tsx
23
23
  var _m$ = Symbol();
24
24
  var _m$2 = Symbol();
@@ -73,30 +73,6 @@ function _P$3(_p4, _p5) {
73
73
  Object.defineProperty(this, "children", _d$4);
74
74
  }
75
75
  _P$3.prototype = Object.prototype;
76
- var _d$5 = {
77
- get() {
78
- const container = this[_m$];
79
- return container();
80
- },
81
- enumerable: true,
82
- configurable: true
83
- };
84
- var _d$6 = {
85
- get() {
86
- const container = this[_m$];
87
- const props = this[_m$2];
88
- return Portal(new _P$3(container, props));
89
- },
90
- enumerable: true,
91
- configurable: true
92
- };
93
- function _P$4(_p6, _p7) {
94
- this[_m$] = _p6;
95
- this[_m$2] = _p7;
96
- Object.defineProperty(this, "when", _d$5);
97
- Object.defineProperty(this, "children", _d$6);
98
- }
99
- _P$4.prototype = Object.prototype;
100
76
  const Context = createContext(null);
101
77
  function ModalProvider(props) {
102
78
  const parent = useContext(Context);
@@ -145,7 +121,11 @@ function OverlayContainer(props) {
145
121
  createEffect(container, (element) => {
146
122
  if (element?.closest("[data-overlay-container]")) throw new Error("An OverlayContainer must not be inside another container. Please change the portalContainer prop.");
147
123
  }, { ssrSource: "client" });
148
- return Show(new _P$4(container, props));
124
+ return memo(() => {
125
+ return memo(() => {
126
+ return !!container();
127
+ })() ? Portal(new _P$3(container, props)) : void 0;
128
+ });
149
129
  }
150
130
  function createModal(options = {}) {
151
131
  const context = useContext(Context);
@@ -1 +1 @@
1
- {"version":3,"file":"create-modal.js","names":["<div data-overlay-container {...props} {...aria.modalProviderProps} />","_$mergeProps","_$ssrElement"],"sources":["../../../src/overlays/create-modal.tsx"],"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/useModal.tsx.\n * Modified for Solid Aria: adapted components, imports, and reactive lifecycle 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 { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { Portal } from \"@solidjs/web\";\nimport {\n createContext,\n createEffect,\n createMemo,\n createSignal,\n onSettled,\n omit,\n useContext,\n Show,\n} from \"solid-js\";\nimport type { Element as SolidElement } from \"solid-js\";\n\nimport type { AriaAttributes } from \"../types\";\nimport { requireValue } from \"../utils/require-value\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { createUNSAFE_PortalContext } from \"./portal-provider\";\n\nexport interface ModalProviderProps extends DOMAttributes {\n children?: SolidElement;\n}\n\ninterface ModalContextValue {\n parent: ModalContextValue | null;\n modalCount: number;\n addModal: () => void;\n removeModal: () => void;\n}\n\nconst Context = createContext<ModalContextValue | null>(null);\n\nexport function ModalProvider(props: ModalProviderProps): SolidElement {\n const parent = useContext(Context);\n const [modalCount, setModalCount] = createSignal(0);\n\n const context = {\n addModal() {\n setModalCount((count) => count + 1);\n parent?.addModal();\n },\n get modalCount() {\n return modalCount();\n },\n parent,\n removeModal() {\n setModalCount((count) => count - 1);\n parent?.removeModal();\n },\n };\n\n return <Context value={context}>{props.children}</Context>;\n}\n\nexport interface ModalProviderAria {\n modalProviderProps: AriaAttributes;\n}\n\nexport function createModalProvider(): ModalProviderAria {\n const context = useContext(Context);\n\n return {\n modalProviderProps: {\n get \"aria-hidden\"() {\n return context && context.modalCount > 0 ? \"true\" : undefined;\n },\n },\n };\n}\n\nfunction OverlayContainerDOM(props: ModalProviderProps): SolidElement {\n const aria = createModalProvider();\n\n return <div data-overlay-container {...props} {...aria.modalProviderProps} />;\n}\n\nexport function OverlayProvider(props: ModalProviderProps): SolidElement {\n return (\n <ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>\n );\n}\n\nexport interface OverlayContainerProps extends ModalProviderProps {\n portalContainer?: Element;\n}\n\nexport function OverlayContainer(props: OverlayContainerProps): SolidElement {\n const [mounted, setMounted] = createSignal(false);\n onSettled(() => {\n setMounted(true);\n });\n const portal = createUNSAFE_PortalContext();\n\n const container = createMemo(\n () =>\n props.portalContainer ??\n portal.getContainer?.() ??\n (mounted() ? document.body : null)\n );\n\n createEffect(\n container,\n (element) => {\n if (element?.closest(\"[data-overlay-container]\")) {\n throw new Error(\n \"An OverlayContainer must not be inside another container. Please change the portalContainer prop.\"\n );\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>\n );\n}\n\ninterface ModalAriaProps extends DOMAttributes {\n \"data-ismodal\": boolean;\n}\n\nexport interface AriaModalOptions {\n isDisabled?: boolean;\n}\n\nexport interface ModalAria {\n modalProps: ModalAriaProps;\n}\n\nexport function createModal(options: AriaModalOptions = {}): ModalAria {\n const context = useContext(Context);\n\n if (!context) {\n throw new Error(\"Modal is not contained within a provider\");\n }\n\n createEffect(\n () => options.isDisabled,\n (disabled): undefined | (() => void) => {\n if (isTruthy(disabled) || !context.parent) {\n return undefined;\n }\n\n context.parent.addModal();\n\n return () => context.parent?.removeModal();\n },\n { ssrSource: \"client\" }\n );\n\n return {\n modalProps: {\n get \"data-ismodal\"() {\n return !isTruthy(options.isDisabled);\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAoEkC,O,SAAC,CAAM;;;;;;;;;;;;;;EA4BnC,OAAA,oBAAyB,KAAQ;;;;;;;;;;;;;EAqCzB,OAAO,aAAa,UAAU,GAAG,sBAAsB;;;;;;;;EAC7D,OAAA,gBAAAC,iBACE;GAEK,OAAA,KAAK,OAAO,iBAAiB;EAElC,CACD,CAAA;;;;;;;;;;;;;;;EARC,OAAM,UAAU;;;;;;;;;EACpB,OAAA,OAAA,IAAA,KAA4B,WAId,KAIN,CAAA;;;;;;;;;;;;AA9Fd,MAAM,UAAU,cAAwC,IAAI;AAE5D,SAAgB,cAAc,OAAyC;CACrE,MAAM,SAAS,WAAW,OAAO;CACjC,MAAM,CAAC,YAAY,iBAAiB,aAAa,CAAC;CAiBlD,OAAA,QAAO,IAAA,IAA0B,OAAV;EAdrB,WAAW;GACT,eAAe,UAAU,QAAQ,CAAC;GAClC,QAAQ,SAAS;EACnB;EACA,IAAI,aAAa;GACf,OAAO,WAAW;EACpB;EACA;EACA,cAAc;GACZ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Y,EACV,IAAI,iBAAiB;EACnB,OAAO,CAAC,SAAS,QAAQ,UAAU;CACrC,EACF,EACF;AACF"}
1
+ {"version":3,"file":"create-modal.js","names":["<div data-overlay-container {...props} {...aria.modalProviderProps} />","<Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>","_$mergeProps","_$ssrElement","_$memo"],"sources":["../../../src/overlays/create-modal.tsx"],"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/useModal.tsx.\n * Modified for Solid Aria: adapted components, imports, and reactive lifecycle 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 { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport { Portal } from \"@solidjs/web\";\nimport {\n createContext,\n createEffect,\n createMemo,\n createSignal,\n onSettled,\n omit,\n useContext,\n Show,\n} from \"solid-js\";\nimport type { Element as SolidElement } from \"solid-js\";\n\nimport type { AriaAttributes } from \"../types\";\nimport { requireValue } from \"../utils/require-value\";\nimport { isTruthy } from \"../utils/truthy\";\nimport { createUNSAFE_PortalContext } from \"./portal-provider\";\n\nexport interface ModalProviderProps extends DOMAttributes {\n children?: SolidElement;\n}\n\ninterface ModalContextValue {\n parent: ModalContextValue | null;\n modalCount: number;\n addModal: () => void;\n removeModal: () => void;\n}\n\nconst Context = createContext<ModalContextValue | null>(null);\n\nexport function ModalProvider(props: ModalProviderProps): SolidElement {\n const parent = useContext(Context);\n const [modalCount, setModalCount] = createSignal(0);\n\n const context = {\n addModal() {\n setModalCount((count) => count + 1);\n parent?.addModal();\n },\n get modalCount() {\n return modalCount();\n },\n parent,\n removeModal() {\n setModalCount((count) => count - 1);\n parent?.removeModal();\n },\n };\n\n return <Context value={context}>{props.children}</Context>;\n}\n\nexport interface ModalProviderAria {\n modalProviderProps: AriaAttributes;\n}\n\nexport function createModalProvider(): ModalProviderAria {\n const context = useContext(Context);\n\n return {\n modalProviderProps: {\n get \"aria-hidden\"() {\n return context && context.modalCount > 0 ? \"true\" : undefined;\n },\n },\n };\n}\n\nfunction OverlayContainerDOM(props: ModalProviderProps): SolidElement {\n const aria = createModalProvider();\n\n return <div data-overlay-container {...props} {...aria.modalProviderProps} />;\n}\n\nexport function OverlayProvider(props: ModalProviderProps): SolidElement {\n return (\n <ModalProvider>\n <OverlayContainerDOM {...props} />\n </ModalProvider>\n );\n}\n\nexport interface OverlayContainerProps extends ModalProviderProps {\n portalContainer?: Element;\n}\n\nexport function OverlayContainer(props: OverlayContainerProps): SolidElement {\n const [mounted, setMounted] = createSignal(false);\n onSettled(() => {\n setMounted(true);\n });\n const portal = createUNSAFE_PortalContext();\n\n const container = createMemo(\n () =>\n props.portalContainer ??\n portal.getContainer?.() ??\n (mounted() ? document.body : null)\n );\n\n createEffect(\n container,\n (element) => {\n if (element?.closest(\"[data-overlay-container]\")) {\n throw new Error(\n \"An OverlayContainer must not be inside another container. Please change the portalContainer prop.\"\n );\n }\n },\n { ssrSource: \"client\" }\n );\n\n return (\n <Show when={container()}>\n <Portal mount={requireValue(container(), \"Expected container()\")}>\n <OverlayProvider\n {\n // oxlint-disable solid/reactivity -- Keep prop filtering in the renderer's lazy evaluation.\n ...omit(props, \"portalContainer\")\n // oxlint-enable solid/reactivity\n }\n />\n </Portal>\n </Show>\n );\n}\n\ninterface ModalAriaProps extends DOMAttributes {\n \"data-ismodal\": boolean;\n}\n\nexport interface AriaModalOptions {\n isDisabled?: boolean;\n}\n\nexport interface ModalAria {\n modalProps: ModalAriaProps;\n}\n\nexport function createModal(options: AriaModalOptions = {}): ModalAria {\n const context = useContext(Context);\n\n if (!context) {\n throw new Error(\"Modal is not contained within a provider\");\n }\n\n createEffect(\n () => options.isDisabled,\n (disabled): undefined | (() => void) => {\n if (isTruthy(disabled) || !context.parent) {\n return undefined;\n }\n\n context.parent.addModal();\n\n return () => context.parent?.removeModal();\n },\n { ssrSource: \"client\" }\n );\n\n return {\n modalProps: {\n get \"data-ismodal\"() {\n return !isTruthy(options.isDisabled);\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAoEkC,O,SAAC,CAAM;;;;;;;;;;;;;;EA4BnC,OAAA,oBAAyB,KAAQ;;;;;;;;;;;;;EAqCzB,OAAO,aAAa,UAAU,GAAG,sBAAsB;;;;;;;;EAC7D,OAAA,gBAAAE,iBACE;GAEK,OAAA,KAAK,OAAO,iBAAiB;EAElC,CACD,CAAA;;;;;;;;;;;;AA7FT,MAAM,UAAU,cAAwC,IAAI;AAE5D,SAAgB,cAAc,OAAyC;CACrE,MAAM,SAAS,WAAW,OAAO;CACjC,MAAM,CAAC,YAAY,iBAAiB,aAAa,CAAC;CAiBlD,OAAA,QAAO,IAAA,IAA0B,OAAV;EAdrB,WAAW;GACT,eAAe,UAAU,QAAQ,CAAC;GAClC,QAAQ,SAAS;EACnB;EACA,IAAI,aAAa;GACf,OAAO,WAAW;EACpB;EACA;EACA,cAAc;GACZ,eAAe,UAAU,QAAQ,CAAC;GAClC,QAAQ,YAAY;EACtB;CAGqB,CAAkC,CAAA;AAC3D;AAMA,SAAgB,sBAAyC;CACvD,MAAM,UAAU,WAAW,OAAO;CAElC,OAAO,EACL,oBAAoB,EAClB,IAAI,gBAAgB;EAClB,OAAO,WAAW,QAAQ,aAAa,IAAI,SAAS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, whenTruthy } from "../utils/truthy.js";
18
18
  import { chain } from "../utils/chain.js";
19
19
  import { addEvent, setStyle } from "../utils/dom-helpers.js";
20
- import { getActiveElement, getEventTarget } from "../utils/shadowdom/dom-functions.js";
20
+ import { getActiveElement, getEventTarget, getParentElement } from "../utils/shadowdom/dom-functions.js";
21
21
  import { htmlElementOrNull, requireElement, requireHTMLElement } from "../utils/dom-value.js";
22
22
  import { requireValue } from "../utils/require-value.js";
23
23
  import { isIOS, isWebKit } from "../utils/platform.js";
@@ -104,7 +104,7 @@ const onBlur = (e) => {
104
104
  const target = requireHTMLElement(getEventTarget(e));
105
105
  const relatedTarget = htmlElementOrNull(e.relatedTarget);
106
106
  if (relatedTarget && willOpenKeyboard(relatedTarget)) relatedTarget.focus();
107
- else if (!relatedTarget) htmlElementOrNull(target.parentElement?.closest("[tabindex]"))?.focus({ preventScroll: true });
107
+ else if (!relatedTarget) htmlElementOrNull(getParentElement(target)?.closest("[tabindex]"))?.focus({ preventScroll: true });
108
108
  };
109
109
  function handleBlur() {
110
110
  return addEvent(document, "blur", onBlur, true);
@@ -156,7 +156,7 @@ function scrollIntoView(target) {
156
156
  });
157
157
  }
158
158
  }
159
- nextTarget = scrollable.parentElement;
159
+ nextTarget = getParentElement(scrollable);
160
160
  }
161
161
  }
162
162
  export { createPreventScroll };
@@ -1 +1 @@
1
- {"version":3,"file":"create-prevent-scroll.js","names":[],"sources":["../../../src/overlays/create-prevent-scroll.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/usePreventScroll.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 { createEffect } from \"solid-js\";\n\nimport { chain } from \"../utils/chain\";\nimport { addEvent, setStyle } from \"../utils/dom-helpers\";\nimport {\n htmlElementOrNull,\n requireElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { supportsKeyboard, willOpenKeyboard } from \"../utils/keyboard\";\nimport { isIOS, isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n runAfterKeyboard,\n runAfterKeyboardTransition,\n} from \"../utils/run-after-keyboard\";\nimport {\n getActiveElement,\n getEventTarget,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n /**\n * Whether to override the `focus()` method so it does not scroll the page.\n * This is temporary and will be removed after fully testing all overlays.\n *\n * @private\n */\n UNSTABLE_overrideFocus?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: (() => void) | undefined;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function createPreventScroll(options: PreventScrollOptions = {}): void {\n createEffect(\n () => ({\n disabled: options.isDisabled,\n overrideFocus: options.UNSTABLE_overrideFocus,\n }),\n ({\n disabled,\n overrideFocus: shouldOverrideFocus,\n }): undefined | (() => void) => {\n if (isTruthy(disabled)) {\n return undefined;\n }\n\n preventScrollCount += 1;\n\n if (preventScrollCount === 1) {\n restore =\n isIOS() && isWebKit()\n ? preventScrollMobileWebKit()\n : preventScrollStandard(shouldOverrideFocus);\n }\n\n return () => {\n preventScrollCount -= 1;\n\n if (preventScrollCount === 0) {\n restore?.();\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard(UNSTABLE_overrideFocus?: boolean) {\n const scrollbarWidth =\n window.innerWidth - document.documentElement.clientWidth;\n\n return chain(\n scrollbarWidth > 0 &&\n // Use scrollbar-gutter when supported because it also works for fixed positioned elements.\n (\"scrollbarGutter\" in document.documentElement.style\n ? setStyle(document.documentElement, \"scrollbar-gutter\", \"stable\")\n : setStyle(\n document.documentElement,\n \"padding-right\",\n `${scrollbarWidth}px`\n )),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n whenTruthy(UNSTABLE_overrideFocus, () => overrideFocus()),\n whenTruthy(\n whenTruthy(UNSTABLE_overrideFocus, () => supportsKeyboard()),\n () => handleBlur()\n )\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch\n// zooming or when an element contains text selection, which may allow scrolling in some cases.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\nfunction preventScrollMobileWebKit() {\n // Set overflow hidden so scrollIntoViewport() (useSelectableCollection) sees isScrollPrevented and\n // scrolls only scroll parents instead of calling native scrollIntoView() which moves the window.\n const restoreOverflow = setStyle(\n document.documentElement,\n \"overflow\",\n \"hidden\"\n );\n\n let scrollable: Element;\n let allowTouchMove = false;\n\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n const target = requireElement(getEventTarget(e));\n scrollable = isScrollable(target, true)\n ? target\n : getScrollParent(target, true);\n allowTouchMove = false;\n\n // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.\n const selection = requireValue(\n target.ownerDocument.defaultView,\n \"Expected target.ownerDocument.defaultView\"\n ).getSelection();\n\n if (\n selection &&\n !selection.isCollapsed &&\n selection.containsNode(target, true)\n ) {\n allowTouchMove = true;\n }\n\n // If this is a range input, allow touch move to allow user to adjust the slider value\n if (\n e\n .composedPath()\n .some((el) => el instanceof HTMLInputElement && el.type === \"range\")\n ) {\n allowTouchMove = true;\n }\n\n // If this is a focused input element with a selected range, allow user to drag the selection handles.\n if (\n \"selectionStart\" in target &&\n \"selectionEnd\" in target &&\n typeof target.selectionStart === \"number\" &&\n typeof target.selectionEnd === \"number\" &&\n target.selectionStart < target.selectionEnd &&\n target.ownerDocument.activeElement === target\n ) {\n allowTouchMove = true;\n }\n };\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.\n const style = document.createElement(\"style\");\n const nonce = getNonce();\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n style.textContent = `\n@layer {\n * {\n overscroll-behavior: contain;\n }\n}`.trim();\n document.head.prepend(style);\n\n const onTouchMove = (e: TouchEvent) => {\n // Allow pinch-zooming.\n if (e.touches.length === 2 || allowTouchMove) {\n return;\n }\n\n // Prevent scrolling the window.\n if (\n !isTruthy(scrollable) ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const restoreFocus = overrideFocus();\n\n const removeEvents = chain(\n addEvent(document, \"touchstart\", onTouchStart, {\n capture: true,\n passive: false,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n capture: true,\n passive: false,\n }),\n handleBlur()\n );\n\n return () => {\n restoreOverflow();\n removeEvents();\n style.remove();\n restoreFocus();\n };\n}\n\nconst onBlur = (e: FocusEvent) => {\n const target = requireHTMLElement(getEventTarget(e));\n const relatedTarget = htmlElementOrNull(e.relatedTarget);\n\n if (relatedTarget && willOpenKeyboard(relatedTarget)) {\n // Re-focus programmatically to have the override below perform the scroll.\n relatedTarget.focus();\n } else if (!relatedTarget) {\n // When tapping the Done button on the keyboard, focus moves to the body.\n // FocusScope will then restore focus back to the input. Later when tapping\n // the same input again, it is already focused, so no blur event will fire,\n // resulting in the flow above never running and Safari's native scrolling occurring.\n // Instead, move focus to the parent focusable element (e.g. the dialog).\n const focusable = htmlElementOrNull(\n target.parentElement?.closest(\"[tabindex]\")\n );\n\n focusable?.focus({ preventScroll: true });\n }\n};\n\nfunction handleBlur() {\n return addEvent(document, \"blur\", onBlur, true);\n}\n\nfunction overrideFocus() {\n // Override programmatic focus to scroll into view without scrolling the whole page.\n // oxlint-disable-next-line typescript/unbound-method -- Preserve the original method identity and invoke it with an explicit receiver.\n const { focus } = HTMLElement.prototype;\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value(opts?: FocusOptions) {\n // Focus the element without scrolling the page.\n focus.call(this, { ...opts, preventScroll: true });\n\n if (!opts || !isTruthy(opts.preventScroll)) {\n const scroll = () => {\n const activeElement = getActiveElement();\n\n if (activeElement === this) {\n scrollIntoView(requireElement(this));\n }\n };\n\n runAfterKeyboard((isOpen) => {\n if (isOpen) {\n scroll();\n } else {\n runAfterKeyboardTransition(scroll);\n }\n });\n }\n },\n writable: true,\n });\n\n return () => {\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value: focus,\n writable: true,\n });\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root =\n getTruthyValue(document.scrollingElement) ?? document.documentElement;\n\n let nextTarget: Element | null = target;\n\n while (nextTarget && nextTarget !== root && nextTarget.isConnected) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableRect = scrollable.getBoundingClientRect();\n const targetRect = nextTarget.getBoundingClientRect();\n\n if (\n targetRect.top < scrollableRect.top ||\n targetRect.bottom > scrollableRect.top + nextTarget.clientHeight\n ) {\n let { bottom } = scrollableRect;\n\n if (isTruthy(visualViewport)) {\n bottom = Math.min(\n bottom,\n visualViewport.offsetTop + visualViewport.height\n );\n }\n\n // Center within the viewport.\n const adjustment =\n targetRect.top -\n scrollableRect.top -\n ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);\n\n scrollable.scrollTo({\n behavior: \"smooth\",\n // Clamp to the valid range to prevent over-scrolling.\n top: Math.max(\n 0,\n Math.min(\n scrollable.scrollHeight - scrollable.clientHeight,\n scrollable.scrollTop + adjustment\n )\n ),\n });\n }\n }\n\n nextTarget = scrollable.parentElement;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACzB,CACF;IACF,CAAC;GACH;EACF;EAEA,aAAa,WAAW;CAC1B;AACF"}
1
+ {"version":3,"file":"create-prevent-scroll.js","names":[],"sources":["../../../src/overlays/create-prevent-scroll.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/usePreventScroll.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 { createEffect } from \"solid-js\";\n\nimport { chain } from \"../utils/chain\";\nimport { addEvent, setStyle } from \"../utils/dom-helpers\";\nimport {\n htmlElementOrNull,\n requireElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { getScrollParent } from \"../utils/get-scroll-parent\";\nimport { isScrollable } from \"../utils/is-scrollable\";\nimport { supportsKeyboard, willOpenKeyboard } from \"../utils/keyboard\";\nimport { isIOS, isWebKit } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n runAfterKeyboard,\n runAfterKeyboardTransition,\n} from \"../utils/run-after-keyboard\";\nimport {\n getActiveElement,\n getEventTarget,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy, whenTruthy } from \"../utils/truthy\";\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n /**\n * Whether to override the `focus()` method so it does not scroll the page.\n * This is temporary and will be removed after fully testing all overlays.\n *\n * @private\n */\n UNSTABLE_overrideFocus?: boolean;\n}\n\nconst visualViewport = typeof document !== \"undefined\" && window.visualViewport;\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: (() => void) | undefined;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function createPreventScroll(options: PreventScrollOptions = {}): void {\n createEffect(\n () => ({\n disabled: options.isDisabled,\n overrideFocus: options.UNSTABLE_overrideFocus,\n }),\n ({\n disabled,\n overrideFocus: shouldOverrideFocus,\n }): undefined | (() => void) => {\n if (isTruthy(disabled)) {\n return undefined;\n }\n\n preventScrollCount += 1;\n\n if (preventScrollCount === 1) {\n restore =\n isIOS() && isWebKit()\n ? preventScrollMobileWebKit()\n : preventScrollStandard(shouldOverrideFocus);\n }\n\n return () => {\n preventScrollCount -= 1;\n\n if (preventScrollCount === 0) {\n restore?.();\n }\n };\n },\n { ssrSource: \"client\" }\n );\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard(UNSTABLE_overrideFocus?: boolean) {\n const scrollbarWidth =\n window.innerWidth - document.documentElement.clientWidth;\n\n return chain(\n scrollbarWidth > 0 &&\n // Use scrollbar-gutter when supported because it also works for fixed positioned elements.\n (\"scrollbarGutter\" in document.documentElement.style\n ? setStyle(document.documentElement, \"scrollbar-gutter\", \"stable\")\n : setStyle(\n document.documentElement,\n \"padding-right\",\n `${scrollbarWidth}px`\n )),\n setStyle(document.documentElement, \"overflow\", \"hidden\"),\n whenTruthy(UNSTABLE_overrideFocus, () => overrideFocus()),\n whenTruthy(\n whenTruthy(UNSTABLE_overrideFocus, () => supportsKeyboard()),\n () => handleBlur()\n )\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event. This is best effort: we can't prevent default when pinch\n// zooming or when an element contains text selection, which may allow scrolling in some cases.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\nfunction preventScrollMobileWebKit() {\n // Set overflow hidden so scrollIntoViewport() (useSelectableCollection) sees isScrollPrevented and\n // scrolls only scroll parents instead of calling native scrollIntoView() which moves the window.\n const restoreOverflow = setStyle(\n document.documentElement,\n \"overflow\",\n \"hidden\"\n );\n\n let scrollable: Element;\n let allowTouchMove = false;\n\n const onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n const target = requireElement(getEventTarget(e));\n scrollable = isScrollable(target, true)\n ? target\n : getScrollParent(target, true);\n allowTouchMove = false;\n\n // If the target is selected, don't preventDefault in touchmove to allow user to adjust selection.\n const selection = requireValue(\n target.ownerDocument.defaultView,\n \"Expected target.ownerDocument.defaultView\"\n ).getSelection();\n\n if (\n selection &&\n !selection.isCollapsed &&\n selection.containsNode(target, true)\n ) {\n allowTouchMove = true;\n }\n\n // If this is a range input, allow touch move to allow user to adjust the slider value\n if (\n e\n .composedPath()\n .some((el) => el instanceof HTMLInputElement && el.type === \"range\")\n ) {\n allowTouchMove = true;\n }\n\n // If this is a focused input element with a selected range, allow user to drag the selection handles.\n if (\n \"selectionStart\" in target &&\n \"selectionEnd\" in target &&\n typeof target.selectionStart === \"number\" &&\n typeof target.selectionEnd === \"number\" &&\n target.selectionStart < target.selectionEnd &&\n target.ownerDocument.activeElement === target\n ) {\n allowTouchMove = true;\n }\n };\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n // This must be applied before the touchstart event as of iOS 26, so inject it as a <style> element.\n const style = document.createElement(\"style\");\n const nonce = getNonce();\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n style.textContent = `\n@layer {\n * {\n overscroll-behavior: contain;\n }\n}`.trim();\n document.head.prepend(style);\n\n const onTouchMove = (e: TouchEvent) => {\n // Allow pinch-zooming.\n if (e.touches.length === 2 || allowTouchMove) {\n return;\n }\n\n // Prevent scrolling the window.\n if (\n !isTruthy(scrollable) ||\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (\n scrollable.scrollHeight === scrollable.clientHeight &&\n scrollable.scrollWidth === scrollable.clientWidth\n ) {\n e.preventDefault();\n }\n };\n\n const restoreFocus = overrideFocus();\n\n const removeEvents = chain(\n addEvent(document, \"touchstart\", onTouchStart, {\n capture: true,\n passive: false,\n }),\n addEvent(document, \"touchmove\", onTouchMove, {\n capture: true,\n passive: false,\n }),\n handleBlur()\n );\n\n return () => {\n restoreOverflow();\n removeEvents();\n style.remove();\n restoreFocus();\n };\n}\n\nconst onBlur = (e: FocusEvent) => {\n const target = requireHTMLElement(getEventTarget(e));\n const relatedTarget = htmlElementOrNull(e.relatedTarget);\n\n if (relatedTarget && willOpenKeyboard(relatedTarget)) {\n // Re-focus programmatically to have the override below perform the scroll.\n relatedTarget.focus();\n } else if (!relatedTarget) {\n // When tapping the Done button on the keyboard, focus moves to the body.\n // FocusScope will then restore focus back to the input. Later when tapping\n // the same input again, it is already focused, so no blur event will fire,\n // resulting in the flow above never running and Safari's native scrolling occurring.\n // Instead, move focus to the parent focusable element (e.g. the dialog).\n const focusable = htmlElementOrNull(\n getParentElement(target)?.closest(\"[tabindex]\")\n );\n\n focusable?.focus({ preventScroll: true });\n }\n};\n\nfunction handleBlur() {\n return addEvent(document, \"blur\", onBlur, true);\n}\n\nfunction overrideFocus() {\n // Override programmatic focus to scroll into view without scrolling the whole page.\n // oxlint-disable-next-line typescript/unbound-method -- Preserve the original method identity and invoke it with an explicit receiver.\n const { focus } = HTMLElement.prototype;\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value(opts?: FocusOptions) {\n // Focus the element without scrolling the page.\n focus.call(this, { ...opts, preventScroll: true });\n\n if (!opts || !isTruthy(opts.preventScroll)) {\n const scroll = () => {\n const activeElement = getActiveElement();\n\n if (activeElement === this) {\n scrollIntoView(requireElement(this));\n }\n };\n\n runAfterKeyboard((isOpen) => {\n if (isOpen) {\n scroll();\n } else {\n runAfterKeyboardTransition(scroll);\n }\n });\n }\n },\n writable: true,\n });\n\n return () => {\n Reflect.defineProperty(HTMLElement.prototype, \"focus\", {\n configurable: true,\n value: focus,\n writable: true,\n });\n };\n}\n\nfunction scrollIntoView(target: Element) {\n const root =\n getTruthyValue(document.scrollingElement) ?? document.documentElement;\n\n let nextTarget: Element | null = target;\n\n while (nextTarget && nextTarget !== root && nextTarget.isConnected) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n const scrollable = getScrollParent(nextTarget);\n\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== nextTarget\n ) {\n const scrollableRect = scrollable.getBoundingClientRect();\n const targetRect = nextTarget.getBoundingClientRect();\n\n if (\n targetRect.top < scrollableRect.top ||\n targetRect.bottom > scrollableRect.top + nextTarget.clientHeight\n ) {\n let { bottom } = scrollableRect;\n\n if (isTruthy(visualViewport)) {\n bottom = Math.min(\n bottom,\n visualViewport.offsetTop + visualViewport.height\n );\n }\n\n // Center within the viewport.\n const adjustment =\n targetRect.top -\n scrollableRect.top -\n ((bottom - scrollableRect.top) / 2 - targetRect.height / 2);\n\n scrollable.scrollTo({\n behavior: \"smooth\",\n // Clamp to the valid range to prevent over-scrolling.\n top: Math.max(\n 0,\n Math.min(\n scrollable.scrollHeight - scrollable.clientHeight,\n scrollable.scrollTop + adjustment\n )\n ),\n });\n }\n }\n\n nextTarget = getParentElement(scrollable);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,iBAAiB,OAAO,aAAa,eAAe,OAAO;AAGjE,IAAI,qBAAqB;AACzB,IAAI;;;;;;AAOJ,SAAgB,oBAAoB,UAAgC,CAAC,GAAS;CAC5E,oBACS;EACL,UAAU,QAAQ;EAClB,eAAe,QAAQ;CACzB,KACC,EACC,UACA,eAAe,0BACe;EAC9B,IAAI,SAAS,QAAQ,GACnB;EAGF,sBAAsB;EAEtB,IAAI,uBAAuB,GACzB,UACE,MAAM,KAAK,SAAS,IAChB,0BAA0B,IAC1B,sBAAsB,mBAAmB;EAGjD,aAAa;GACX,sBAAsB;GAEtB,IAAI,uBAAuB,GACzB,UAAU;EAEd;CACF,GACA,EAAE,WAAW,SAAS,CACxB;AACF;AAIA,SAAS,sBAAsB,wBAAkC;CAC/D,MAAM,iBACJ,OAAO,aAAa,SAAS,gBAAgB;CAE/C,OAAO,MACL,iBAAiB,MAEd,qBAAqB,SAAS,gBAAgB,QAC3C,SAAS,SAAS,iBAAiB,oBAAoB,QAAQ,IAC/D,SACE,SAAS,iBACT,iBACA,GAAG,eAAe,GACpB,IACN,SAAS,SAAS,iBAAiB,YAAY,QAAQ,GACvD,WAAW,8BAA8B,cAAc,CAAC,GACxD,WACE,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UAAU;EAE7C,IACE,eAAe,SAAS,mBACxB,eAAe,SAAS,QACxB,eAAe,YACf;GACA,MAAM,iBAAiB,WAAW,sBAAsB;GACxD,MAAM,aAAa,WAAW,sBAAsB;GAEpD,IACE,WAAW,MAAM,eAAe,OAChC,WAAW,SAAS,eAAe,MAAM,WAAW,cACpD;IACA,IAAI,EAAE,WAAW;IAEjB,IAAI,SAAS,cAAc,GACzB,SAAS,KAAK,IACZ,QACA,eAAe,YAAY,eAAe,MAC5C;IAIF,MAAM,aACJ,WAAW,MACX,eAAe,QACb,SAAS,eAAe,OAAO,IAAI,WAAW,SAAS;IAE3D,WAAW,SAAS;KAClB,UAAU;KAEV,KAAK,KAAK,IACR,GACA,KAAK,IACH,WAAW,eAAe,WAAW,cACrC,WAAW,YAAY,UACzB,CACF;IACF,CAAC;GACH;EACF;EAEA,aAAa,iBAAiB,UAAU;CAC1C;AACF"}
@@ -20,7 +20,7 @@ import { FocusScope } from "../focus/focus-scope.js";
20
20
  import { ClearPressResponder } from "../interactions/press-responder.js";
21
21
  import { createUNSAFE_PortalContext } from "./portal-provider.js";
22
22
  import { Portal, memo } from "@solidjs/web";
23
- import { Show, createContext, createMemo, createSignal, onSettled, useContext } from "solid-js";
23
+ import { createContext, createMemo, createSignal, onSettled, useContext } from "solid-js";
24
24
  // src/overlays/overlay.tsx
25
25
  var _m$ = Symbol();
26
26
  var _m$2 = Symbol();
@@ -101,8 +101,8 @@ function _P$4(_p9, _p0, _p1) {
101
101
  _P$4.prototype = Object.prototype;
102
102
  var _d$6 = {
103
103
  get() {
104
- const mount = this[_m$];
105
- return mount();
104
+ const container = this[_m$];
105
+ return container();
106
106
  },
107
107
  enumerable: true,
108
108
  configurable: true
@@ -126,20 +126,6 @@ function _P$5(_p10, _p11, _p12, _p13) {
126
126
  Object.defineProperty(this, "children", _d$7);
127
127
  }
128
128
  _P$5.prototype = Object.prototype;
129
- var _d$8 = {
130
- get() {
131
- const container = this[_m$];
132
- return container();
133
- },
134
- enumerable: true,
135
- configurable: true
136
- };
137
- function _P$6(_p14, _p15) {
138
- this[_m$] = _p14;
139
- Object.defineProperty(this, "when", _d$8);
140
- this.children = _p15;
141
- }
142
- _P$6.prototype = Object.prototype;
143
129
  const OverlayContext = createContext(null);
144
130
  function Overlay(props) {
145
131
  const [mounted, setMounted] = createSignal(false);
@@ -155,7 +141,11 @@ function Overlay(props) {
155
141
  setContain
156
142
  };
157
143
  const container = createMemo(() => props.portalContainer ?? portal.getContainer?.() ?? (mounted() ? document.body : null));
158
- return Show(new _P$6(container, (mount) => Portal(new _P$5(mount, props, contain, value))));
144
+ return memo(() => {
145
+ return memo(() => {
146
+ return !!container();
147
+ })() ? Portal(new _P$5(container, props, contain, value)) : void 0;
148
+ });
159
149
  }
160
150
  function createOverlayFocusContain() {
161
151
  const context = useContext(OverlayContext);