@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":"create-press.js","names":[],"sources":["../../../src/interactions/create-press.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/usePress.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; register the initial press responder in an explicit untracked lifecycle scope.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n FocusableElement,\n PressEvent as IPressEvent,\n PointerType,\n PressEvents,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n omit,\n untrack,\n useContext,\n createEffect,\n createSignal,\n flush,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type {\n MouseEvent as TargetedMouseEvent,\n TouchEvent as TargetedTouchEvent,\n} from \"../types\";\nimport { chain } from \"../utils/chain\";\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n requireElement,\n requireFocusableElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n isVirtualClick,\n isVirtualPointerEvent,\n} from \"../utils/is-virtual-event\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink } from \"../utils/open-link\";\nimport { isMac } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { PressResponderContext } from \"./context\";\nimport { disableTextSelection, restoreTextSelection } from \"./text-selection\";\nimport { preventFocus, setEventTarget } from \"./utils\";\n\nexport interface PressProps extends PressEvents {\n /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */\n isPressed?: boolean;\n /** Whether the press events should be disabled. */\n isDisabled?: boolean;\n /** Whether the target should not receive focus on press. */\n preventFocusOnPress?: boolean;\n /**\n * Whether press events should be canceled when the pointer leaves the target while pressed.\n * By default, this is `false`, which means if the pointer returns back over the target while\n * still pressed, onPressStart will be fired again. If set to `true`, the press is canceled\n * when the pointer leaves the target and onPressStart will not be fired if the pointer returns.\n */\n shouldCancelOnPointerExit?: boolean;\n /** Whether text selection should be enabled on the pressable element. */\n allowTextSelectionOnPress?: boolean;\n}\n\nexport interface PressHookProps extends PressProps {\n /** A ref to the target element. */\n ref?: Accessor<Element | null>;\n}\n\ninterface PressState {\n isPressed: boolean;\n ignoreEmulatedMouseEvents: boolean;\n didFirePressStart: boolean;\n isTriggeringEvent: boolean;\n activePointerId: number | null;\n target: FocusableElement | null;\n isOverTarget: boolean;\n pointerType: PointerType | null;\n userSelect?: string;\n metaKeyEvents?: Map<string, globalThis.KeyboardEvent>;\n disposables: (() => void)[];\n}\n\ninterface EventBase {\n currentTarget: EventTarget | null;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n clientX?: number;\n clientY?: number;\n targetTouches?: {\n clientX?: number;\n clientY?: number;\n }[];\n key?: string;\n}\n\nexport interface PressResult {\n /** Whether the target is currently pressed. */\n isPressed: boolean;\n /** Props to spread on the target element. */\n pressProps: DOMAttributes;\n}\n\nfunction createPressResponderContext(props: PressHookProps): PressHookProps {\n const context = useContext(PressResponderContext);\n const currentProps = mergeProps(omit(context, \"register\", \"ref\"), props);\n untrack(() => {\n context.register();\n });\n\n createEffect(\n () => ({ element: currentProps.ref?.(), setRef: context.ref }),\n ({ element, setRef }) => {\n if (element instanceof HTMLElement || element instanceof SVGElement) {\n setRef?.(element);\n }\n },\n { ssrSource: \"client\" }\n );\n\n return currentProps;\n}\n\nclass PressEvent implements IPressEvent {\n type: IPressEvent[\"type\"];\n pointerType: PointerType;\n target: Element;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n x: number;\n y: number;\n key: string | undefined;\n #shouldStopPropagation = true;\n constructor(\n type: IPressEvent[\"type\"],\n pointerType: PointerType,\n originalEvent: EventBase,\n state?: PressState\n ) {\n const currentTarget = state?.target ?? originalEvent.currentTarget;\n\n const rect: DOMRect | undefined =\n requireElement(currentTarget)?.getBoundingClientRect();\n\n let x = 0;\n let y = 0;\n\n let clientX;\n let clientY: number | null = null;\n\n if (\n isPresent(originalEvent.clientX) &&\n originalEvent.clientY !== null &&\n originalEvent.clientY !== undefined\n ) {\n ({ clientX } = originalEvent);\n ({ clientY } = originalEvent);\n }\n\n if (isTruthy(rect)) {\n if (isPresent(clientX) && clientY !== null && clientY !== undefined) {\n x = clientX - rect.left;\n y = clientY - rect.top;\n } else {\n x = rect.width / 2;\n y = rect.height / 2;\n }\n }\n\n this.type = type;\n this.pointerType = pointerType;\n this.target = requireElement(originalEvent.currentTarget);\n this.shiftKey = originalEvent.shiftKey;\n this.metaKey = originalEvent.metaKey;\n this.ctrlKey = originalEvent.ctrlKey;\n this.altKey = originalEvent.altKey;\n this.x = x;\n this.y = y;\n this.key = originalEvent.key;\n }\n continuePropagation() {\n this.#shouldStopPropagation = false;\n }\n get shouldStopPropagation() {\n return this.#shouldStopPropagation;\n }\n}\n\nconst linkedEvents = new WeakSet<Event>();\n\nfunction parsePointerType(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Validate optional native event extensions before storing their pointer type.\n value: unknown\n): PointerType {\n return value === \"touch\" ||\n value === \"pen\" ||\n value === \"keyboard\" ||\n value === \"virtual\"\n ? value\n : \"mouse\";\n}\n\nconst STYLE_ID = \"react-aria-pressable-style\";\nconst PRESSABLE_ATTRIBUTE = \"data-react-aria-pressable\";\n\n/**\n * Handles press interactions across mouse, touch, keyboard, and screen readers.\n * It normalizes behavior across browsers and platforms, and handles many nuances\n * of dealing with pointer and keyboard events.\n */\nexport function createPress(props: PressHookProps): PressResult {\n const _result0 = createPressResponderContext(props);\n const [isPressed, setPressed] = createSignal(false, { ownedWrite: true });\n\n const ref: PressState = {\n activePointerId: null,\n didFirePressStart: false,\n disposables: [],\n ignoreEmulatedMouseEvents: false,\n isOverTarget: false,\n isPressed: false,\n isTriggeringEvent: false,\n pointerType: null,\n target: null,\n };\n\n const _result1 = createGlobalListeners();\n\n const triggerPressStart = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled) || state.didFirePressStart) {\n return false;\n }\n\n let shouldStopPropagation = true;\n state.isTriggeringEvent = true;\n\n if (_result0.onPressStart) {\n const event = new PressEvent(\"pressstart\", pointerType, originalEvent);\n _result0.onPressStart(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(true);\n }\n\n state.isTriggeringEvent = false;\n state.didFirePressStart = true;\n setPressed(true);\n\n return shouldStopPropagation;\n };\n\n const triggerPressEnd = (\n originalEvent: EventBase,\n pointerType: PointerType,\n wasPressed = true\n ) => {\n const state = ref;\n\n if (!state.didFirePressStart) {\n return false;\n }\n\n state.didFirePressStart = false;\n state.isTriggeringEvent = true;\n let shouldStopPropagation = true;\n\n if (_result0.onPressEnd) {\n const event = new PressEvent(\"pressend\", pointerType, originalEvent);\n _result0.onPressEnd(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(false);\n }\n\n setPressed(false);\n\n if (_result0.onPress && wasPressed && !isTruthy(_result0.isDisabled)) {\n const event = new PressEvent(\"press\", pointerType, originalEvent);\n _result0.onPress(event);\n shouldStopPropagation &&= event.shouldStopPropagation;\n }\n\n state.isTriggeringEvent = false;\n\n return shouldStopPropagation;\n };\n\n const triggerPressEndEvent = triggerPressEnd;\n\n const triggerPressUp = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled)) {\n return false;\n }\n\n if (_result0.onPressUp) {\n state.isTriggeringEvent = true;\n const event = new PressEvent(\"pressup\", pointerType, originalEvent);\n _result0.onPressUp(event);\n state.isTriggeringEvent = false;\n\n return event.shouldStopPropagation;\n }\n\n return true;\n };\n\n const triggerPressUpEvent = triggerPressUp;\n\n const cancel = (e: EventBase) => {\n const state = ref;\n\n if (state.isPressed && state.target) {\n if (\n state.didFirePressStart &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressEnd(createEvent(state.target, e), state.pointerType, false);\n }\n\n state.isPressed = false;\n state.isOverTarget = false;\n state.activePointerId = null;\n state.pointerType = null;\n _result1.removeAllGlobalListeners();\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n }\n };\n\n const cancelEvent = cancel;\n createEffect(\n () => _result0.isDisabled,\n (disabled) => {\n if (disabled === true && ref.isPressed) {\n untrack(() => {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: ref.target,\n metaKey: false,\n shiftKey: false,\n });\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n const cancelOnPointerExit = (e: EventBase) => {\n if (isTruthy(_result0.shouldCancelOnPointerExit)) {\n cancel(e);\n }\n };\n\n const triggerClick = (e: TargetedMouseEvent<FocusableElement>) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n _result0.onClick?.(e);\n };\n\n const triggerActivationClick = (\n e: KeyboardEvent | TouchEvent,\n target: FocusableElement\n ) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n // Some third-party libraries pass in onClick instead of onPress.\n // Create a fake mouse event and trigger onClick as well.\n // This matches the browser's native activation behavior for certain elements (e.g. button).\n // https://html.spec.whatwg.org/#activation\n // https://html.spec.whatwg.org/#fire-a-synthetic-pointer-event\n if (_result0.onClick) {\n const event = new MouseEvent(\"click\", e);\n setEventTarget(event, target);\n _result0.onClick(event);\n }\n };\n\n function onScroll(e: Event) {\n const state = ref;\n\n if (\n state.isPressed &&\n nodeContains(requireElement(getEventTarget(e)), state.target)\n ) {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: state.target,\n metaKey: false,\n shiftKey: false,\n });\n }\n }\n\n function onMouseUp(e: MouseEvent) {\n const state = ref;\n\n // Only handle left clicks\n if (e.button !== 0) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n\n return;\n }\n\n if (\n state.target &&\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onMouseUp and onClick, and is more compatible with third party libraries.\n } else {\n cancelEvent(e);\n }\n\n state.isOverTarget = false;\n }\n\n function onPointerCancel(e: PointerEvent) {\n cancelEvent(e);\n }\n\n function onPointerUp(e: PointerEvent) {\n const state = ref;\n\n if (\n e.pointerId === state.activePointerId &&\n state.isPressed &&\n e.button === 0 &&\n state.target\n ) {\n if (\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onPointerUp and onClick, and is more compatible with third party libraries.\n // https://github.com/adobe/react-spectrum/issues/1513\n // https://issues.chromium.org/issues/40732224\n // However, iOS and Android do not focus or fire onClick after a long press.\n // We work around this by triggering a click ourselves after a timeout.\n // This timeout is canceled during the click event in case the real one fires first.\n // The timeout must be at least 32ms, because Safari on iOS delays the click event on\n // non-form elements without certain ARIA roles (for hover emulation).\n // https://github.com/WebKit/WebKit/blob/dccfae42bb29bd4bdef052e469f604a9387241c0/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm#L875-L892\n let clicked = false;\n\n const timeout = setTimeout(() => {\n if (state.isPressed && state.target instanceof HTMLElement) {\n if (clicked) {\n cancelEvent(e);\n } else {\n focusWithoutScrolling(state.target);\n state.target.click();\n }\n }\n }, 80);\n\n // Use a capturing listener to track if a click occurred.\n // If stopPropagation is called it may never reach our handler.\n _result1.addGlobalListener(\n requireValue(e.currentTarget, \"Expected the click listener target\"),\n \"click\",\n () => {\n clicked = true;\n },\n true\n );\n state.disposables.push(() => {\n clearTimeout(timeout);\n });\n } else {\n cancelEvent(e);\n }\n\n // Ignore subsequent onPointerLeave event before onClick on touch devices.\n state.isOverTarget = false;\n }\n }\n\n const state = ref;\n\n const pressPropsValue: DOMAttributes = {\n onClick(e) {\n if (!isTruthy(e)) {\n return;\n }\n\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n e.button === 0 &&\n !state.isTriggeringEvent &&\n !isTruthy(openLink.isOpening)\n ) {\n let shouldStopPropagation = true;\n\n if (isTruthy(_result0.isDisabled)) {\n e.preventDefault();\n }\n\n // If triggered from a screen reader or by using element.click(),\n // trigger as if it were a keyboard click.\n if (\n !state.ignoreEmulatedMouseEvents &&\n !state.isPressed &&\n (state.pointerType === \"virtual\" || isVirtualClick(e))\n ) {\n const stopPressStart = triggerPressStart(e, \"virtual\");\n const stopPressUp = triggerPressUpEvent(e, \"virtual\");\n const stopPressEnd = triggerPressEndEvent(e, \"virtual\");\n triggerClick(e);\n shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;\n } else if (state.isPressed && state.pointerType !== \"keyboard\") {\n const pointerType =\n getTruthyValue(\n state.pointerType ??\n (\"pointerType\" in e\n ? parsePointerType(e.pointerType)\n : undefined)\n ) ?? \"virtual\";\n\n const stopPressUp = triggerPressUpEvent(\n createEvent(e.currentTarget, e),\n pointerType\n );\n\n const stopPressEnd = triggerPressEndEvent(\n createEvent(e.currentTarget, e),\n pointerType,\n true\n );\n\n shouldStopPropagation = stopPressUp && stopPressEnd;\n state.isOverTarget = false;\n triggerClick(e);\n\n cancelEvent(e);\n }\n\n state.ignoreEmulatedMouseEvents = false;\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n }\n },\n onKeyDown(e) {\n if (\n isValidKeyboardEvent(e, e.currentTarget) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n if (shouldPreventDefaultKeyboard(getEventTarget(e), e.key)) {\n e.preventDefault();\n }\n\n // If the event is repeating, it may have started on a different element\n // after which focus moved to the current element. Ignore these events and\n // only handle the first key down event.\n let shouldStopPropagation = true;\n\n if (!state.isPressed && !e.repeat) {\n state.target = e.currentTarget;\n state.isPressed = true;\n state.pointerType = \"keyboard\";\n shouldStopPropagation = triggerPressStart(e, \"keyboard\");\n }\n\n // Focus may move before the key up event, so register the event on the document\n // instead of the same element where the key down event occurred. Make it capturing so that it will trigger\n // before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.\n const originalTarget = e.currentTarget;\n\n const pressUp = (eValue: globalThis.KeyboardEvent) => {\n if (\n isValidKeyboardEvent(eValue, originalTarget) &&\n !eValue.repeat &&\n nodeContains(\n originalTarget,\n requireElement(getEventTarget(eValue))\n ) &&\n state.target\n ) {\n triggerPressUpEvent(createEvent(state.target, eValue), \"keyboard\");\n }\n };\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"keyup\",\n chain(pressUp, onKeyUp),\n true\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n // Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.\n // macOS has a bug where keyup events are not fired while the Meta key is down.\n // When the Meta key itself is released we will get an event for that, and we'll act as if\n // all of these other keys were released as well.\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1393524\n // https://bugs.webkit.org/show_bug.cgi?id=55291\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1299553\n if (e.metaKey && isMac()) {\n state.metaKeyEvents?.set(e.key, e);\n }\n } else if (e.key === \"Meta\") {\n state.metaKeyEvents = new Map();\n }\n },\n };\n\n function onKeyUp(e: KeyboardEvent) {\n if (\n state.isPressed &&\n state.target &&\n isValidKeyboardEvent(e, state.target)\n ) {\n if (\n shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e.key)\n ) {\n e.preventDefault();\n }\n\n const target = getEventTarget(e);\n const wasPressed = nodeContains(state.target, requireElement(target));\n triggerPressEndEvent(\n createEvent(state.target, e),\n \"keyboard\",\n wasPressed\n );\n\n if (wasPressed) {\n triggerActivationClick(e, state.target);\n }\n\n _result1.removeAllGlobalListeners();\n\n // If a link was triggered with a key other than Enter, open the URL ourselves.\n // This means the link has a role override, and the default browser behavior\n // only applies when using the Enter key.\n if (\n e.key !== \"Enter\" &&\n isHTMLAnchorLink(state.target) &&\n nodeContains(state.target, requireElement(target)) &&\n !linkedEvents.has(e)\n ) {\n // Store a hidden property on the event so we only trigger link click once,\n // even if there are multiple usePress instances attached to the element.\n linkedEvents.add(e);\n openLink(state.target, e, false);\n }\n\n state.isPressed = false;\n state.metaKeyEvents?.delete(e.key);\n } else if (e.key === \"Meta\" && isTruthy(state.metaKeyEvents?.size)) {\n // If we recorded keydown events that occurred while the Meta key was pressed,\n // and those haven't received keyup events already, fire keyup events ourselves.\n // See comment above for more info about the macOS bug causing this.\n const events = state.metaKeyEvents;\n state.metaKeyEvents = undefined;\n\n for (const event of events.values()) {\n state.target?.dispatchEvent(new KeyboardEvent(\"keyup\", event));\n }\n }\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n pressPropsValue.onPointerDown = (e) => {\n // Only handle left clicks, and ignore events that bubbled through portals.\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.\n // Ignore and let the onClick handler take care of it instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n if (isVirtualPointerEvent(e)) {\n state.pointerType = \"virtual\";\n\n return;\n }\n\n state.pointerType = parsePointerType(e.pointerType);\n let shouldStopPropagation = true;\n\n if (!state.isPressed) {\n state.isPressed = true;\n state.isOverTarget = true;\n state.activePointerId = e.pointerId;\n state.target = e.currentTarget;\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n // Release pointer capture so that touch interactions can leave the original target.\n // This enables onPointerLeave and onPointerEnter to fire.\n const target = getEventTarget(e);\n\n if (\"releasePointerCapture\" in target) {\n if (\"hasPointerCapture\" in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n requireElement(target).releasePointerCapture(e.pointerId);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointerup\",\n onPointerUp,\n false\n );\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointercancel\",\n onPointerCancel,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseDown = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (e.button === 0) {\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onPointerUp = (e) => {\n // iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.pointerType === \"virtual\"\n ) {\n return;\n }\n\n // Only handle left clicks. If isPressed is true, delay until onClick.\n if (e.button === 0 && !state.isPressed) {\n triggerPressUpEvent(\n e,\n getTruthyValue(state.pointerType) ?? parsePointerType(e.pointerType)\n );\n }\n };\n\n pressPropsValue.onPointerEnter = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n triggerPressStart(createEvent(state.target, e), state.pointerType);\n }\n };\n\n pressPropsValue.onPointerLeave = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n triggerPressEndEvent(\n createEvent(state.target, e),\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.\n cancelEvent(e);\n };\n } else if (process.env.NODE_ENV === \"test\") {\n // NOTE: this fallback branch is entirely used by unit tests.\n // All browsers now support pointer events, but JSDOM still does not.\n pressPropsValue.onMouseDown = (e) => {\n // Only handle left clicks\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n e.stopPropagation();\n\n return;\n }\n\n state.isPressed = true;\n state.isOverTarget = true;\n state.target = e.currentTarget;\n state.pointerType = isVirtualClick(e) ? \"virtual\" : \"mouse\";\n\n // Flush sync so that focus moved during react re-renders occurs before we yield back to the browser.\n const shouldStopPropagation = (() => {\n const result = (() =>\n triggerPressStart(\n e,\n requireValue(state.pointerType, \"Expected state.pointerType\")\n ))();\n\n flush();\n\n return result;\n })();\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"mouseup\",\n onMouseUp,\n false\n );\n };\n\n pressPropsValue.onMouseEnter = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseLeave = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n e,\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseUp = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n !state.ignoreEmulatedMouseEvents &&\n e.button === 0 &&\n !state.isPressed\n ) {\n triggerPressUpEvent(e, getTruthyValue(state.pointerType) ?? \"mouse\");\n }\n };\n\n pressPropsValue.onTouchStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n const touch = getTouchFromEvent(e);\n\n if (!touch) {\n return;\n }\n\n state.activePointerId = touch.identifier;\n state.ignoreEmulatedMouseEvents = true;\n state.isOverTarget = true;\n state.isPressed = true;\n state.target = e.currentTarget;\n state.pointerType = \"touch\";\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n const shouldStopPropagation = triggerPressStart(\n createTouchEvent(state.target, e),\n state.pointerType\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n _result1.addGlobalListener(\n getOwnerWindow(e.currentTarget),\n \"scroll\",\n onScroll,\n true\n );\n };\n\n pressPropsValue.onTouchMove = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (touch && isOverTarget(touch, e.currentTarget)) {\n if (\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n }\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n cancelOnPointerExit(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onTouchEnd = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (\n touch &&\n isOverTarget(touch, e.currentTarget) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressUpEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n triggerActivationClick(\n e,\n requireValue(state.target, \"Expected state.target\")\n );\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n state.isPressed = false;\n state.activePointerId = null;\n state.isOverTarget = false;\n state.ignoreEmulatedMouseEvents = true;\n\n if (state.target && !isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n _result1.removeAllGlobalListeners();\n };\n\n pressPropsValue.onTouchCancel = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n e.stopPropagation();\n\n if (state.isPressed) {\n cancelEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n cancelEvent(e);\n };\n }\n\n // Avoid onClick delay for double tap to zoom by default.\n createEffect(\n () => _result0.ref?.(),\n (element) => {\n if (!element || process.env.NODE_ENV === \"test\") {\n return;\n }\n\n const ownerDocument = getOwnerDocument(element);\n\n if (\n !isTruthy(ownerDocument) ||\n !isTruthy(ownerDocument.head) ||\n ownerDocument.querySelector(`#${STYLE_ID}`)\n ) {\n return;\n }\n\n const style = ownerDocument.createElement(\"style\");\n style.id = STYLE_ID;\n const nonce = getNonce(ownerDocument);\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n // touchAction: 'manipulation' is supposed to be equivalent, but in\n // Safari it causes onPointerCancel not to fire on scroll.\n // https://bugs.webkit.org/show_bug.cgi?id=240917\n style.textContent = `\n@layer {\n [${PRESSABLE_ATTRIBUTE}] {\n touch-action: pan-x pan-y pinch-zoom;\n }\n}\n `.trim();\n ownerDocument.head.prepend(style);\n },\n { ssrSource: \"client\" }\n );\n // Remove user-select: none in case component unmounts immediately after pressStart\n createEffect(\n () => _result0.allowTextSelectionOnPress,\n (allowTextSelection) => () => {\n if (allowTextSelection !== true) {\n restoreTextSelection(state.target ?? undefined);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get isPressed() {\n return getTruthyValue(_result0.isPressed) ?? isPressed();\n },\n get pressProps() {\n return mergeProps(\n omit(\n _result0,\n \"onPress\",\n \"onPressChange\",\n \"onPressStart\",\n \"onPressEnd\",\n \"onPressUp\",\n \"onClick\",\n \"isDisabled\",\n \"isPressed\",\n \"preventFocusOnPress\",\n \"shouldCancelOnPointerExit\",\n \"allowTextSelectionOnPress\",\n \"ref\"\n ),\n pressPropsValue,\n { [PRESSABLE_ATTRIBUTE]: true }\n );\n },\n };\n}\n\nfunction isHTMLAnchorLink(target: Element): target is HTMLAnchorElement {\n return target.tagName === \"A\" && target.hasAttribute(\"href\");\n}\n\nfunction isValidKeyboardEvent(\n event: KeyboardEvent,\n currentTarget: Element\n): boolean {\n const { key, code } = event;\n const element = requireHTMLElement(currentTarget);\n const role = element.getAttribute(\"role\");\n\n // Accessibility for keyboards. Space and Enter only.\n // \"Spacebar\" is for IE 11\n return (\n (key === \"Enter\" ||\n key === \" \" ||\n key === \"Spacebar\" ||\n code === \"Space\") &&\n (!(element instanceof getOwnerWindow(element).HTMLInputElement) ||\n isValidInputKey(element, key)) &&\n !(element instanceof getOwnerWindow(element).HTMLTextAreaElement) &&\n !element.isContentEditable &&\n // Links should only trigger with Enter key\n ((role !== \"link\" && (isTruthy(role) || !isHTMLAnchorLink(element))) ||\n key === \"Enter\")\n );\n}\n\nfunction getTouchFromEvent(event: TouchEvent): Touch | null {\n const { targetTouches } = event;\n\n if (targetTouches.length > 0) {\n return targetTouches[0] ?? null;\n }\n\n return null;\n}\n\nfunction getTouchById(\n event: TouchEvent,\n pointerId: null | number\n): null | Touch {\n const { changedTouches } = event;\n\n for (const touch of changedTouches) {\n if (touch.identifier === pointerId) {\n return touch;\n }\n }\n\n return null;\n}\n\nfunction createTouchEvent(\n target: FocusableElement,\n e: TargetedTouchEvent<FocusableElement>\n): EventBase {\n let clientX = 0;\n let clientY = 0;\n\n if (isTruthy(e.targetTouches) && e.targetTouches.length === 1) {\n ({ clientX } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n ({ clientY } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n }\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\nfunction createEvent(target: FocusableElement, e: EventBase): EventBase {\n const { clientX } = e;\n const { clientY } = e;\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n key: e.key,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\ninterface Rect {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\ninterface EventPoint {\n clientX: number;\n clientY: number;\n width?: number;\n height?: number;\n radiusX?: number;\n radiusY?: number;\n}\n\nfunction getPointClientRect(point: EventPoint): Rect {\n let offsetX = 0;\n let offsetY = 0;\n\n if (point.width !== undefined) {\n offsetX = point.width / 2;\n } else if (point.radiusX !== undefined) {\n offsetX = point.radiusX;\n }\n\n if (point.height !== undefined) {\n offsetY = point.height / 2;\n } else if (point.radiusY !== undefined) {\n offsetY = point.radiusY;\n }\n\n return {\n bottom: point.clientY + offsetY,\n left: point.clientX - offsetX,\n right: point.clientX + offsetX,\n top: point.clientY - offsetY,\n };\n}\n\nfunction areRectanglesOverlapping(a: Rect, b: Rect) {\n // check if they cannot overlap on x axis\n if (a.left > b.right || b.left > a.right) {\n return false;\n }\n\n // check if they cannot overlap on y axis\n if (a.top > b.bottom || b.top > a.bottom) {\n return false;\n }\n\n return true;\n}\n\nfunction isOverTarget(point: EventPoint, target: Element) {\n const rect = target.getBoundingClientRect();\n const pointRect = getPointClientRect(point);\n\n return areRectanglesOverlapping(rect, pointRect);\n}\n\nfunction shouldPreventDefaultUp(target: Element) {\n if (target instanceof HTMLInputElement) {\n return false;\n }\n\n if (target instanceof HTMLButtonElement) {\n return target.type !== \"submit\" && target.type !== \"reset\";\n }\n\n if (isHTMLAnchorLink(target)) {\n return false;\n }\n\n return true;\n}\n\nfunction shouldPreventDefaultKeyboard(target: Element, key: string) {\n // Don't prevent the contextmenu shortcut on mac.\n if (isMac() && key === \"Enter\") {\n return false;\n }\n\n if (target instanceof HTMLInputElement) {\n if (\n key === \"Enter\" &&\n (target.type === \"checkbox\" || target.type === \"radio\")\n ) {\n // Enter on a checkbox or radio should do an implicit form submission, but not toggle the input.\n return false;\n }\n\n return !isValidInputKey(target, key);\n }\n\n return shouldPreventDefaultUp(target);\n}\n\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\nfunction isValidInputKey(target: HTMLInputElement, key: string) {\n // Only space should toggle checkboxes and radios, not enter.\n return target.type === \"checkbox\" || target.type === \"radio\"\n ? key === \" \"\n : nonTextInputTypes.has(target.type);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAS,4BAA4B,OAAuC;CAC1E,MAAM,UAAU,WAAW,qBAAqB;CAChD,MAAM,eAAe,WAAW,KAAK,SAAS,YAAY,KAAK,GAAG,KAAK;CACvE,cAAc;EACZ,QAAQ,SAAS;CACnB,CAAC;CAED,oBACS;EAAE,SAAS,aAAa,MAAM;EAAG,QAAQ,QAAQ;CAAI,KAC3D,EAAE,SAAS,aAAa;EACvB,IAAI,mBAAmB,eAAe,mBAAmB,YACvD,SAAS,OAAO;CAEpB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO;AACT;AAEA,IAAM,aAAN,MAAwC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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AM,EAAE,UAAU,EAAE,MAAM,EAAE,QAChC,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,aAAa,OAAmB,QAAiB;CAIxD,OAAO,yBAHM,OAAO,sBAGe,GAFjB,mBAAmB,KAES,CAAC;AACjD;AAEA,SAAS,uBAAuB,QAAiB;CAC/C,IAAI,kBAAkB,kBACpB,OAAO;CAGT,IAAI,kBAAkB,mBACpB,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS;CAGrD,IAAI,iBAAiB,MAAM,GACzB,OAAO;CAGT,OAAO;AACT;AAEA,SAAS,6BAA6B,QAAiB,KAAa;CAElE,IAAI,MAAM,KAAK,QAAQ,SACrB,OAAO;CAGT,IAAI,kBAAkB,kBAAkB;EACtC,IACE,QAAQ,YACP,OAAO,SAAS,cAAc,OAAO,SAAS,UAG/C,OAAO;EAGT,OAAO,CAAC,gBAAgB,QAAQ,GAAG;CACrC;CAEA,OAAO,uBAAuB,MAAM;AACtC;AAEA,MAAM,oCAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,QAA0B,KAAa;CAE9D,OAAO,OAAO,SAAS,cAAc,OAAO,SAAS,UACjD,QAAQ,MACR,kBAAkB,IAAI,OAAO,IAAI;AACvC"}
1
+ {"version":3,"file":"create-press.js","names":[],"sources":["../../../src/interactions/create-press.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/usePress.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2; register the initial press responder in an explicit untracked lifecycle scope.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n FocusableElement,\n PressEvent as IPressEvent,\n PointerType,\n PressEvents,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n omit,\n untrack,\n useContext,\n createEffect,\n createSignal,\n flush,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport type {\n MouseEvent as TargetedMouseEvent,\n TouchEvent as TargetedTouchEvent,\n} from \"../types\";\nimport { chain } from \"../utils/chain\";\nimport { createGlobalListeners } from \"../utils/create-global-listeners\";\nimport { getOwnerDocument, getOwnerWindow } from \"../utils/dom-helpers\";\nimport {\n requireElement,\n requireFocusableElement,\n requireHTMLElement,\n} from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { getNonce } from \"../utils/get-nonce\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n isVirtualClick,\n isVirtualPointerEvent,\n} from \"../utils/is-virtual-event\";\nimport { mergeProps } from \"../utils/merge-props\";\nimport { openLink } from \"../utils/open-link\";\nimport { isMac } from \"../utils/platform\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\nimport { PressResponderContext } from \"./context\";\nimport { disableTextSelection, restoreTextSelection } from \"./text-selection\";\nimport { preventFocus, setEventTarget } from \"./utils\";\n\nexport interface PressProps extends PressEvents {\n /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */\n isPressed?: boolean;\n /** Whether the press events should be disabled. */\n isDisabled?: boolean;\n /** Whether the target should not receive focus on press. */\n preventFocusOnPress?: boolean;\n /**\n * Whether press events should be canceled when the pointer leaves the target while pressed.\n * By default, this is `false`, which means if the pointer returns back over the target while\n * still pressed, onPressStart will be fired again. If set to `true`, the press is canceled\n * when the pointer leaves the target and onPressStart will not be fired if the pointer returns.\n */\n shouldCancelOnPointerExit?: boolean;\n /** Whether text selection should be enabled on the pressable element. */\n allowTextSelectionOnPress?: boolean;\n}\n\nexport interface PressHookProps extends PressProps {\n /** A ref to the target element. */\n ref?: Accessor<Element | null>;\n}\n\ninterface PressState {\n isPressed: boolean;\n ignoreEmulatedMouseEvents: boolean;\n didFirePressStart: boolean;\n isTriggeringEvent: boolean;\n activePointerId: number | null;\n target: FocusableElement | null;\n isOverTarget: boolean;\n pointerType: PointerType | null;\n userSelect?: string;\n metaKeyEvents?: Map<string, globalThis.KeyboardEvent>;\n disposables: (() => void)[];\n}\n\ninterface EventBase {\n currentTarget: EventTarget | null;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n clientX?: number;\n clientY?: number;\n targetTouches?: {\n clientX?: number;\n clientY?: number;\n }[];\n key?: string;\n}\n\nexport interface PressResult {\n /** Whether the target is currently pressed. */\n isPressed: boolean;\n /** Props to spread on the target element. */\n pressProps: DOMAttributes;\n}\n\nfunction createPressResponderContext(props: PressHookProps): PressHookProps {\n const context = useContext(PressResponderContext);\n const currentProps = mergeProps(omit(context, \"register\", \"ref\"), props);\n untrack(() => {\n context.register();\n });\n\n createEffect(\n () => ({ element: currentProps.ref?.(), setRef: context.ref }),\n ({ element, setRef }) => {\n if (element instanceof HTMLElement || element instanceof SVGElement) {\n setRef?.(element);\n }\n },\n { ssrSource: \"client\" }\n );\n\n return currentProps;\n}\n\nclass PressEvent implements IPressEvent {\n type: IPressEvent[\"type\"];\n pointerType: PointerType;\n target: Element;\n shiftKey: boolean;\n ctrlKey: boolean;\n metaKey: boolean;\n altKey: boolean;\n x: number;\n y: number;\n key: string | undefined;\n #shouldStopPropagation = true;\n constructor(\n type: IPressEvent[\"type\"],\n pointerType: PointerType,\n originalEvent: EventBase,\n state?: PressState\n ) {\n const currentTarget = state?.target ?? originalEvent.currentTarget;\n\n const rect: DOMRect | undefined =\n requireElement(currentTarget)?.getBoundingClientRect();\n\n let x = 0;\n let y = 0;\n\n let clientX;\n let clientY: number | null = null;\n\n if (\n isPresent(originalEvent.clientX) &&\n originalEvent.clientY !== null &&\n originalEvent.clientY !== undefined\n ) {\n ({ clientX } = originalEvent);\n ({ clientY } = originalEvent);\n }\n\n if (isTruthy(rect)) {\n if (isPresent(clientX) && clientY !== null && clientY !== undefined) {\n x = clientX - rect.left;\n y = clientY - rect.top;\n } else {\n x = rect.width / 2;\n y = rect.height / 2;\n }\n }\n\n this.type = type;\n this.pointerType = pointerType;\n this.target = requireElement(originalEvent.currentTarget);\n this.shiftKey = originalEvent.shiftKey;\n this.metaKey = originalEvent.metaKey;\n this.ctrlKey = originalEvent.ctrlKey;\n this.altKey = originalEvent.altKey;\n this.x = x;\n this.y = y;\n this.key = originalEvent.key;\n }\n continuePropagation() {\n this.#shouldStopPropagation = false;\n }\n get shouldStopPropagation() {\n return this.#shouldStopPropagation;\n }\n}\n\nconst linkedEvents = new WeakSet<Event>();\n\nfunction parsePointerType(\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Validate optional native event extensions before storing their pointer type.\n value: unknown\n): PointerType {\n return value === \"touch\" ||\n value === \"pen\" ||\n value === \"keyboard\" ||\n value === \"virtual\"\n ? value\n : \"mouse\";\n}\n\nconst STYLE_ID = \"react-aria-pressable-style\";\nconst PRESSABLE_ATTRIBUTE = \"data-react-aria-pressable\";\n\n/**\n * Handles press interactions across mouse, touch, keyboard, and screen readers.\n * It normalizes behavior across browsers and platforms, and handles many nuances\n * of dealing with pointer and keyboard events.\n */\nexport function createPress(props: PressHookProps): PressResult {\n const _result0 = createPressResponderContext(props);\n const [isPressed, setPressed] = createSignal(false, { ownedWrite: true });\n\n const ref: PressState = {\n activePointerId: null,\n didFirePressStart: false,\n disposables: [],\n ignoreEmulatedMouseEvents: false,\n isOverTarget: false,\n isPressed: false,\n isTriggeringEvent: false,\n pointerType: null,\n target: null,\n };\n\n const _result1 = createGlobalListeners();\n\n const triggerPressStart = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled) || state.didFirePressStart) {\n return false;\n }\n\n let shouldStopPropagation = true;\n state.isTriggeringEvent = true;\n\n if (_result0.onPressStart) {\n const event = new PressEvent(\"pressstart\", pointerType, originalEvent);\n _result0.onPressStart(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(true);\n }\n\n state.isTriggeringEvent = false;\n state.didFirePressStart = true;\n setPressed(true);\n\n return shouldStopPropagation;\n };\n\n const triggerPressEnd = (\n originalEvent: EventBase,\n pointerType: PointerType,\n wasPressed = true\n ) => {\n const state = ref;\n\n if (!state.didFirePressStart) {\n return false;\n }\n\n state.didFirePressStart = false;\n state.isTriggeringEvent = true;\n let shouldStopPropagation = true;\n\n if (_result0.onPressEnd) {\n const event = new PressEvent(\"pressend\", pointerType, originalEvent);\n _result0.onPressEnd(event);\n ({ shouldStopPropagation } = event);\n }\n\n if (_result0.onPressChange) {\n _result0.onPressChange(false);\n }\n\n setPressed(false);\n\n if (_result0.onPress && wasPressed && !isTruthy(_result0.isDisabled)) {\n const event = new PressEvent(\"press\", pointerType, originalEvent);\n _result0.onPress(event);\n shouldStopPropagation &&= event.shouldStopPropagation;\n }\n\n state.isTriggeringEvent = false;\n\n return shouldStopPropagation;\n };\n\n const triggerPressEndEvent = triggerPressEnd;\n\n const triggerPressUp = (\n originalEvent: EventBase,\n pointerType: PointerType\n ) => {\n const state = ref;\n\n if (isTruthy(_result0.isDisabled)) {\n return false;\n }\n\n if (_result0.onPressUp) {\n state.isTriggeringEvent = true;\n const event = new PressEvent(\"pressup\", pointerType, originalEvent);\n _result0.onPressUp(event);\n state.isTriggeringEvent = false;\n\n return event.shouldStopPropagation;\n }\n\n return true;\n };\n\n const triggerPressUpEvent = triggerPressUp;\n\n const cancel = (e: EventBase) => {\n const state = ref;\n\n if (state.isPressed && state.target) {\n if (\n state.didFirePressStart &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressEnd(createEvent(state.target, e), state.pointerType, false);\n }\n\n state.isPressed = false;\n state.isOverTarget = false;\n state.activePointerId = null;\n state.pointerType = null;\n _result1.removeAllGlobalListeners();\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n }\n };\n\n const cancelEvent = cancel;\n createEffect(\n () => _result0.isDisabled,\n (disabled) => {\n if (disabled === true && ref.isPressed) {\n untrack(() => {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: ref.target,\n metaKey: false,\n shiftKey: false,\n });\n });\n }\n },\n { ssrSource: \"client\" }\n );\n\n const cancelOnPointerExit = (e: EventBase) => {\n if (isTruthy(_result0.shouldCancelOnPointerExit)) {\n cancel(e);\n }\n };\n\n const triggerClick = (e: TargetedMouseEvent<FocusableElement>) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n _result0.onClick?.(e);\n };\n\n const triggerActivationClick = (\n e: KeyboardEvent | TouchEvent,\n target: FocusableElement\n ) => {\n if (isTruthy(_result0.isDisabled)) {\n return;\n }\n\n // Some third-party libraries pass in onClick instead of onPress.\n // Create a fake mouse event and trigger onClick as well.\n // This matches the browser's native activation behavior for certain elements (e.g. button).\n // https://html.spec.whatwg.org/#activation\n // https://html.spec.whatwg.org/#fire-a-synthetic-pointer-event\n if (_result0.onClick) {\n const event = new MouseEvent(\"click\", e);\n setEventTarget(event, target);\n _result0.onClick(event);\n }\n };\n\n function onScroll(e: Event) {\n const state = ref;\n\n if (\n state.isPressed &&\n nodeContains(requireElement(getEventTarget(e)), state.target)\n ) {\n cancelEvent({\n altKey: false,\n ctrlKey: false,\n currentTarget: state.target,\n metaKey: false,\n shiftKey: false,\n });\n }\n }\n\n function onMouseUp(e: MouseEvent) {\n const state = ref;\n\n // Only handle left clicks\n if (e.button !== 0) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n\n return;\n }\n\n if (\n state.target &&\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onMouseUp and onClick, and is more compatible with third party libraries.\n } else {\n cancelEvent(e);\n }\n\n state.isOverTarget = false;\n }\n\n function onPointerCancel(e: PointerEvent) {\n cancelEvent(e);\n }\n\n function onPointerUp(e: PointerEvent) {\n const state = ref;\n\n if (\n e.pointerId === state.activePointerId &&\n state.isPressed &&\n e.button === 0 &&\n state.target\n ) {\n if (\n nodeContains(state.target, requireElement(getEventTarget(e))) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n // Wait for onClick to fire onPress. This avoids browser issues when the DOM\n // is mutated between onPointerUp and onClick, and is more compatible with third party libraries.\n // https://github.com/adobe/react-spectrum/issues/1513\n // https://issues.chromium.org/issues/40732224\n // However, iOS and Android do not focus or fire onClick after a long press.\n // We work around this by triggering a click ourselves after a timeout.\n // This timeout is canceled during the click event in case the real one fires first.\n // The timeout must be at least 32ms, because Safari on iOS delays the click event on\n // non-form elements without certain ARIA roles (for hover emulation).\n // https://github.com/WebKit/WebKit/blob/dccfae42bb29bd4bdef052e469f604a9387241c0/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm#L875-L892\n let clicked = false;\n\n const timeout = setTimeout(() => {\n if (state.isPressed && state.target instanceof HTMLElement) {\n if (clicked) {\n cancelEvent(e);\n } else {\n focusWithoutScrolling(state.target);\n state.target.click();\n }\n }\n }, 80);\n\n // Use a capturing listener to track if a click occurred.\n // If stopPropagation is called it may never reach our handler.\n _result1.addGlobalListener(\n requireValue(e.currentTarget, \"Expected the click listener target\"),\n \"click\",\n () => {\n clicked = true;\n },\n true\n );\n state.disposables.push(() => {\n clearTimeout(timeout);\n });\n } else {\n cancelEvent(e);\n }\n\n // Ignore subsequent onPointerLeave event before onClick on touch devices.\n state.isOverTarget = false;\n }\n }\n\n const state = ref;\n\n const pressPropsValue: DOMAttributes = {\n onClick(e) {\n if (!isTruthy(e)) {\n return;\n }\n\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n e.button === 0 &&\n !state.isTriggeringEvent &&\n !isTruthy(openLink.isOpening)\n ) {\n let shouldStopPropagation = true;\n\n if (isTruthy(_result0.isDisabled)) {\n e.preventDefault();\n }\n\n // If triggered from a screen reader or by using element.click(),\n // trigger as if it were a keyboard click.\n if (\n !state.ignoreEmulatedMouseEvents &&\n !state.isPressed &&\n (state.pointerType === \"virtual\" || isVirtualClick(e))\n ) {\n const stopPressStart = triggerPressStart(e, \"virtual\");\n const stopPressUp = triggerPressUpEvent(e, \"virtual\");\n const stopPressEnd = triggerPressEndEvent(e, \"virtual\");\n triggerClick(e);\n shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;\n } else if (state.isPressed && state.pointerType !== \"keyboard\") {\n const pointerType =\n getTruthyValue(\n state.pointerType ??\n (\"pointerType\" in e\n ? parsePointerType(e.pointerType)\n : undefined)\n ) ?? \"virtual\";\n\n const stopPressUp = triggerPressUpEvent(\n createEvent(e.currentTarget, e),\n pointerType\n );\n\n const stopPressEnd = triggerPressEndEvent(\n createEvent(e.currentTarget, e),\n pointerType,\n true\n );\n\n shouldStopPropagation = stopPressUp && stopPressEnd;\n state.isOverTarget = false;\n triggerClick(e);\n\n cancelEvent(e);\n }\n\n state.ignoreEmulatedMouseEvents = false;\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n }\n },\n onKeyDown(e) {\n if (\n isValidKeyboardEvent(e, e.currentTarget) &&\n nodeContains(e.currentTarget, getEventTarget(e))\n ) {\n if (shouldPreventDefaultKeyboard(getEventTarget(e), e)) {\n e.preventDefault();\n }\n\n // If the event is repeating, it may have started on a different element\n // after which focus moved to the current element. Ignore these events and\n // only handle the first key down event.\n let shouldStopPropagation = true;\n\n if (!state.isPressed && !e.repeat) {\n state.target = e.currentTarget;\n state.isPressed = true;\n state.pointerType = \"keyboard\";\n shouldStopPropagation = triggerPressStart(e, \"keyboard\");\n }\n\n // Focus may move before the key up event, so register the event on the document\n // instead of the same element where the key down event occurred. Make it capturing so that it will trigger\n // before stopPropagation from useKeyboard on a child element may happen and thus we can still call triggerPress for the parent element.\n const originalTarget = e.currentTarget;\n\n const pressUp = (eValue: globalThis.KeyboardEvent) => {\n if (\n isValidKeyboardEvent(eValue, originalTarget) &&\n !eValue.repeat &&\n nodeContains(\n originalTarget,\n requireElement(getEventTarget(eValue))\n ) &&\n state.target\n ) {\n triggerPressUpEvent(createEvent(state.target, eValue), \"keyboard\");\n }\n };\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"keyup\",\n chain(pressUp, onKeyUp),\n true\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n // Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.\n // macOS has a bug where keyup events are not fired while the Meta key is down.\n // When the Meta key itself is released we will get an event for that, and we'll act as if\n // all of these other keys were released as well.\n // https://bugs.chromium.org/p/chromium/issues/detail?id=1393524\n // https://bugs.webkit.org/show_bug.cgi?id=55291\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1299553\n if (e.metaKey && isMac()) {\n state.metaKeyEvents?.set(e.key, e);\n }\n } else if (e.key === \"Meta\") {\n state.metaKeyEvents = new Map();\n }\n },\n };\n\n function onKeyUp(e: KeyboardEvent) {\n if (\n state.isPressed &&\n state.target &&\n isValidKeyboardEvent(e, state.target)\n ) {\n if (shouldPreventDefaultKeyboard(requireElement(getEventTarget(e)), e)) {\n e.preventDefault();\n }\n\n const target = getEventTarget(e);\n const wasPressed = nodeContains(state.target, requireElement(target));\n triggerPressEndEvent(\n createEvent(state.target, e),\n \"keyboard\",\n wasPressed\n );\n\n if (wasPressed) {\n triggerActivationClick(e, state.target);\n }\n\n _result1.removeAllGlobalListeners();\n\n // If a link was triggered with a key other than Enter, open the URL ourselves.\n // This means the link has a role override, and the default browser behavior\n // only applies when using the Enter key.\n if (\n e.key !== \"Enter\" &&\n isHTMLAnchorLink(state.target) &&\n nodeContains(state.target, requireElement(target)) &&\n !linkedEvents.has(e)\n ) {\n // Store a hidden property on the event so we only trigger link click once,\n // even if there are multiple usePress instances attached to the element.\n linkedEvents.add(e);\n openLink(state.target, e, false);\n }\n\n state.isPressed = false;\n state.metaKeyEvents?.delete(e.key);\n } else if (e.key === \"Meta\" && isTruthy(state.metaKeyEvents?.size)) {\n // If we recorded keydown events that occurred while the Meta key was pressed,\n // and those haven't received keyup events already, fire keyup events ourselves.\n // See comment above for more info about the macOS bug causing this.\n const events = state.metaKeyEvents;\n state.metaKeyEvents = undefined;\n\n for (const event of events.values()) {\n state.target?.dispatchEvent(new KeyboardEvent(\"keyup\", event));\n }\n }\n }\n\n if (typeof PointerEvent !== \"undefined\") {\n pressPropsValue.onPointerDown = (e) => {\n // Only handle left clicks, and ignore events that bubbled through portals.\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.\n // Ignore and let the onClick handler take care of it instead.\n // https://bugs.webkit.org/show_bug.cgi?id=222627\n // https://bugs.webkit.org/show_bug.cgi?id=223202\n if (isVirtualPointerEvent(e)) {\n state.pointerType = \"virtual\";\n\n return;\n }\n\n state.pointerType = parsePointerType(e.pointerType);\n let shouldStopPropagation = true;\n\n if (!state.isPressed) {\n state.isPressed = true;\n state.isOverTarget = true;\n state.activePointerId = e.pointerId;\n state.target = e.currentTarget;\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n // Release pointer capture so that touch interactions can leave the original target.\n // This enables onPointerLeave and onPointerEnter to fire.\n const target = getEventTarget(e);\n\n if (\"releasePointerCapture\" in target) {\n if (\"hasPointerCapture\" in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n requireElement(target).releasePointerCapture(e.pointerId);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointerup\",\n onPointerUp,\n false\n );\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"pointercancel\",\n onPointerCancel,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseDown = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (e.button === 0) {\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onPointerUp = (e) => {\n // iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.\n if (\n !nodeContains(e.currentTarget, getEventTarget(e)) ||\n state.pointerType === \"virtual\"\n ) {\n return;\n }\n\n // Only handle left clicks. If isPressed is true, delay until onClick.\n if (e.button === 0 && !state.isPressed) {\n triggerPressUpEvent(\n e,\n getTruthyValue(state.pointerType) ?? parsePointerType(e.pointerType)\n );\n }\n };\n\n pressPropsValue.onPointerEnter = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n triggerPressStart(createEvent(state.target, e), state.pointerType);\n }\n };\n\n pressPropsValue.onPointerLeave = (e) => {\n if (\n e.pointerId === state.activePointerId &&\n state.target &&\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n triggerPressEndEvent(\n createEvent(state.target, e),\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.\n cancelEvent(e);\n };\n } else if (process.env.NODE_ENV === \"test\") {\n // NOTE: this fallback branch is entirely used by unit tests.\n // All browsers now support pointer events, but JSDOM still does not.\n pressPropsValue.onMouseDown = (e) => {\n // Only handle left clicks\n if (e.button !== 0 || !nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (state.ignoreEmulatedMouseEvents) {\n e.stopPropagation();\n\n return;\n }\n\n state.isPressed = true;\n state.isOverTarget = true;\n state.target = e.currentTarget;\n state.pointerType = isVirtualClick(e) ? \"virtual\" : \"mouse\";\n\n // Flush sync so that focus moved during react re-renders occurs before we yield back to the browser.\n const shouldStopPropagation = (() => {\n const result = (() =>\n triggerPressStart(\n e,\n requireValue(state.pointerType, \"Expected state.pointerType\")\n ))();\n\n flush();\n\n return result;\n })();\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n if (isTruthy(_result0.preventFocusOnPress)) {\n const dispose = preventFocus(requireFocusableElement(e.target));\n\n if (dispose) {\n state.disposables.push(dispose);\n }\n }\n\n _result1.addGlobalListener(\n getOwnerDocument(e.currentTarget),\n \"mouseup\",\n onMouseUp,\n false\n );\n };\n\n pressPropsValue.onMouseEnter = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(e, state.pointerType);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseLeave = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n let shouldStopPropagation = true;\n\n if (\n state.isPressed &&\n !state.ignoreEmulatedMouseEvents &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n e,\n state.pointerType,\n false\n );\n cancelOnPointerExit(e);\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onMouseUp = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (\n !state.ignoreEmulatedMouseEvents &&\n e.button === 0 &&\n !state.isPressed\n ) {\n triggerPressUpEvent(e, getTruthyValue(state.pointerType) ?? \"mouse\");\n }\n };\n\n pressPropsValue.onTouchStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n const touch = getTouchFromEvent(e);\n\n if (!touch) {\n return;\n }\n\n state.activePointerId = touch.identifier;\n state.ignoreEmulatedMouseEvents = true;\n state.isOverTarget = true;\n state.isPressed = true;\n state.target = e.currentTarget;\n state.pointerType = \"touch\";\n\n if (!isTruthy(_result0.allowTextSelectionOnPress)) {\n disableTextSelection(state.target);\n }\n\n const shouldStopPropagation = triggerPressStart(\n createTouchEvent(state.target, e),\n state.pointerType\n );\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n _result1.addGlobalListener(\n getOwnerWindow(e.currentTarget),\n \"scroll\",\n onScroll,\n true\n );\n };\n\n pressPropsValue.onTouchMove = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (touch && isOverTarget(touch, e.currentTarget)) {\n if (\n !state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = true;\n shouldStopPropagation = triggerPressStart(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n }\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n state.isOverTarget = false;\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n cancelOnPointerExit(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n };\n\n pressPropsValue.onTouchEnd = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n if (!state.isPressed) {\n e.stopPropagation();\n\n return;\n }\n\n const touch = getTouchById(e, state.activePointerId);\n let shouldStopPropagation = true;\n\n if (\n touch &&\n isOverTarget(touch, e.currentTarget) &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n triggerPressUpEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType\n );\n triggerActivationClick(\n e,\n requireValue(state.target, \"Expected state.target\")\n );\n } else if (\n state.isOverTarget &&\n state.pointerType !== null &&\n state.pointerType !== undefined\n ) {\n shouldStopPropagation = triggerPressEndEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n ),\n state.pointerType,\n false\n );\n }\n\n if (shouldStopPropagation) {\n e.stopPropagation();\n }\n\n state.isPressed = false;\n state.activePointerId = null;\n state.isOverTarget = false;\n state.ignoreEmulatedMouseEvents = true;\n\n if (state.target && !isTruthy(_result0.allowTextSelectionOnPress)) {\n restoreTextSelection(state.target);\n }\n\n _result1.removeAllGlobalListeners();\n };\n\n pressPropsValue.onTouchCancel = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n e.stopPropagation();\n\n if (state.isPressed) {\n cancelEvent(\n createTouchEvent(\n requireValue(state.target, \"Expected state.target\"),\n e\n )\n );\n }\n };\n\n pressPropsValue.onDragStart = (e) => {\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n cancelEvent(e);\n };\n }\n\n // Avoid onClick delay for double tap to zoom by default.\n createEffect(\n () => _result0.ref?.(),\n (element) => {\n if (!element || process.env.NODE_ENV === \"test\") {\n return;\n }\n\n const ownerDocument = getOwnerDocument(element);\n\n if (\n !isTruthy(ownerDocument) ||\n !isTruthy(ownerDocument.head) ||\n ownerDocument.querySelector(`#${STYLE_ID}`)\n ) {\n return;\n }\n\n const style = ownerDocument.createElement(\"style\");\n style.id = STYLE_ID;\n const nonce = getNonce(ownerDocument);\n\n if (isTruthy(nonce)) {\n style.nonce = nonce;\n }\n\n // touchAction: 'manipulation' is supposed to be equivalent, but in\n // Safari it causes onPointerCancel not to fire on scroll.\n // https://bugs.webkit.org/show_bug.cgi?id=240917\n style.textContent = `\n@layer {\n [${PRESSABLE_ATTRIBUTE}] {\n touch-action: pan-x pan-y pinch-zoom;\n }\n}\n `.trim();\n ownerDocument.head.prepend(style);\n },\n { ssrSource: \"client\" }\n );\n // Remove user-select: none in case component unmounts immediately after pressStart\n createEffect(\n () => _result0.allowTextSelectionOnPress,\n (allowTextSelection) => () => {\n if (allowTextSelection !== true) {\n restoreTextSelection(state.target ?? undefined);\n }\n\n for (const dispose of state.disposables) {\n dispose();\n }\n\n state.disposables = [];\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get isPressed() {\n return getTruthyValue(_result0.isPressed) ?? isPressed();\n },\n get pressProps() {\n return mergeProps(\n omit(\n _result0,\n \"onPress\",\n \"onPressChange\",\n \"onPressStart\",\n \"onPressEnd\",\n \"onPressUp\",\n \"onClick\",\n \"isDisabled\",\n \"isPressed\",\n \"preventFocusOnPress\",\n \"shouldCancelOnPointerExit\",\n \"allowTextSelectionOnPress\",\n \"ref\"\n ),\n pressPropsValue,\n { [PRESSABLE_ATTRIBUTE]: true }\n );\n },\n };\n}\n\nfunction isHTMLAnchorLink(target: Element): target is HTMLAnchorElement {\n return target.tagName === \"A\" && target.hasAttribute(\"href\");\n}\n\nfunction isValidKeyboardEvent(\n event: KeyboardEvent,\n currentTarget: Element\n): boolean {\n const { key, code } = event;\n const element = requireHTMLElement(currentTarget);\n const role = element.getAttribute(\"role\");\n\n // Accessibility for keyboards. Space and Enter only.\n // \"Spacebar\" is for IE 11\n return (\n (key === \"Enter\" ||\n key === \" \" ||\n key === \"Spacebar\" ||\n code === \"Space\") &&\n (!(element instanceof getOwnerWindow(element).HTMLInputElement) ||\n isValidInputKey(element, key)) &&\n !(element instanceof getOwnerWindow(element).HTMLTextAreaElement) &&\n !element.isContentEditable &&\n // Links should only trigger with Enter key\n ((role !== \"link\" && (isTruthy(role) || !isHTMLAnchorLink(element))) ||\n key === \"Enter\")\n );\n}\n\nfunction getTouchFromEvent(event: TouchEvent): Touch | null {\n const { targetTouches } = event;\n\n if (targetTouches.length > 0) {\n return targetTouches[0] ?? null;\n }\n\n return null;\n}\n\nfunction getTouchById(\n event: TouchEvent,\n pointerId: null | number\n): null | Touch {\n const { changedTouches } = event;\n\n for (const touch of changedTouches) {\n if (touch.identifier === pointerId) {\n return touch;\n }\n }\n\n return null;\n}\n\nfunction createTouchEvent(\n target: FocusableElement,\n e: TargetedTouchEvent<FocusableElement>\n): EventBase {\n let clientX = 0;\n let clientY = 0;\n\n if (isTruthy(e.targetTouches) && e.targetTouches.length === 1) {\n ({ clientX } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n ({ clientY } = requireValue(\n e.targetTouches[0],\n \"Expected e.targetTouches[0]\"\n ));\n }\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\nfunction createEvent(target: FocusableElement, e: EventBase): EventBase {\n const { clientX } = e;\n const { clientY } = e;\n\n return {\n altKey: e.altKey,\n clientX,\n clientY,\n ctrlKey: e.ctrlKey,\n currentTarget: target,\n key: e.key,\n metaKey: e.metaKey,\n shiftKey: e.shiftKey,\n };\n}\n\ninterface Rect {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\ninterface EventPoint {\n clientX: number;\n clientY: number;\n width?: number;\n height?: number;\n radiusX?: number;\n radiusY?: number;\n}\n\nfunction getPointClientRect(point: EventPoint): Rect {\n let offsetX = 0;\n let offsetY = 0;\n\n if (point.width !== undefined) {\n offsetX = point.width / 2;\n } else if (point.radiusX !== undefined) {\n offsetX = point.radiusX;\n }\n\n if (point.height !== undefined) {\n offsetY = point.height / 2;\n } else if (point.radiusY !== undefined) {\n offsetY = point.radiusY;\n }\n\n return {\n bottom: point.clientY + offsetY,\n left: point.clientX - offsetX,\n right: point.clientX + offsetX,\n top: point.clientY - offsetY,\n };\n}\n\nfunction areRectanglesOverlapping(a: Rect, b: Rect) {\n // check if they cannot overlap on x axis\n if (a.left > b.right || b.left > a.right) {\n return false;\n }\n\n // check if they cannot overlap on y axis\n if (a.top > b.bottom || b.top > a.bottom) {\n return false;\n }\n\n return true;\n}\n\nfunction isOverTarget(point: EventPoint, target: Element) {\n const rect = target.getBoundingClientRect();\n const pointRect = getPointClientRect(point);\n\n return areRectanglesOverlapping(rect, pointRect);\n}\n\nfunction shouldPreventDefaultUp(target: Element) {\n if (target instanceof HTMLInputElement) {\n return false;\n }\n\n if (target instanceof HTMLButtonElement) {\n return target.type !== \"submit\" && target.type !== \"reset\";\n }\n\n if (isHTMLAnchorLink(target)) {\n return false;\n }\n\n return true;\n}\n\nfunction shouldPreventDefaultKeyboard(\n target: Element,\n event: Pick<KeyboardEvent, \"key\" | \"ctrlKey\">\n) {\n const { key } = event;\n\n // Don't prevent the contextmenu shortcut (Control + Enter) on mac.\n if (isMac() && key === \"Enter\" && event.ctrlKey) {\n return false;\n }\n\n if (target instanceof HTMLInputElement) {\n if (\n key === \"Enter\" &&\n (target.type === \"checkbox\" || target.type === \"radio\")\n ) {\n // Enter on a checkbox or radio should do an implicit form submission, but not toggle the input.\n return false;\n }\n\n return !isValidInputKey(target, key);\n }\n\n return shouldPreventDefaultUp(target);\n}\n\nconst nonTextInputTypes = new Set([\n \"checkbox\",\n \"radio\",\n \"range\",\n \"color\",\n \"file\",\n \"image\",\n \"button\",\n \"submit\",\n \"reset\",\n]);\n\nfunction isValidInputKey(target: HTMLInputElement, key: string) {\n // Only space should toggle checkboxes and radios, not enter.\n return target.type === \"checkbox\" || target.type === \"radio\"\n ? key === \" \"\n : nonTextInputTypes.has(target.type);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,SAAS,4BAA4B,OAAuC;CAC1E,MAAM,UAAU,WAAW,qBAAqB;CAChD,MAAM,eAAe,WAAW,KAAK,SAAS,YAAY,KAAK,GAAG,KAAK;CACvE,cAAc;EACZ,QAAQ,SAAS;CACnB,CAAC;CAED,oBACS;EAAE,SAAS,aAAa,MAAM;EAAG,QAAQ,QAAQ;CAAI,KAC3D,EAAE,SAAS,aAAa;EACvB,IAAI,mBAAmB,eAAe,mBAAmB,YACvD,SAAS,OAAO;CAEpB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO;AACT;AAEA,IAAM,aAAN,MAAwC;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,yBAAyB;CACzB,YACE,MACA,aACA,eACA,OACA;EACA,MAAM,gBAAgB,OAAO,UAAU,cAAc;EAErD,MAAM,OACJ,eAAe,aAAa,CAAC,EAAE,sBAAsB;EAEvD,IAAI,IAAI;EACR,IAAI,IAAI;EAER,IAAI;EACJ,IAAI,UAAyB;EAE7B,IACE,UAAU,cAAc,OAAO,KAC/B,cAAc,YAAY,QAC1B,cAAc,YAAY,KAAA,GAC1B;GACA,CAAC,CAAE,WAAY;GACf,CAAC,CAAE,WAAY;EACjB;EAEA,IAAI,SAAS,IAAI,GAAG;GAClB,IAAI,UAAU,OAAO,KAAK,YAAY,QAAQ,YAAY,KAAA,GAAW;IACnE,IAAI,UAAU,KAAK;IACnB,IAAI,UAAU,KAAK;GACrB,OAAO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,QAAQ,YACP,OAAO,SAAS,cAAc,OAAO,SAAS,UAG/C,OAAO;EAGT,OAAO,CAAC,gBAAgB,QAAQ,GAAG;CACrC;CAEA,OAAO,uBAAuB,MAAM;AACtC;AAEA,MAAM,oCAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,QAA0B,KAAa;CAE9D,OAAO,OAAO,SAAS,cAAc,OAAO,SAAS,UACjD,QAAQ,MACR,kBAAkB,IAAI,OAAO,IAAI;AACvC"}
@@ -15,8 +15,9 @@
15
15
  * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
16
16
  */
17
17
  import { isPresent } from "../utils/is-present.js";
18
- import { getOwnerWindow, isNode, isShadowRoot } from "../utils/dom-helpers.js";
19
- import { getActiveElement, getEventTarget, nodeContains } from "../utils/shadowdom/dom-functions.js";
18
+ import { isNode, isShadowRoot } from "../utils/type-helpers.js";
19
+ import { getOwnerWindow } from "../utils/dom-helpers.js";
20
+ import { getActiveElement, getEventTarget, getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
20
21
  import { focusableElementOrNull, requireElement } from "../utils/dom-value.js";
21
22
  import { focusWithoutScrolling } from "../utils/focus-without-scrolling.js";
22
23
  import { isFocusable } from "../utils/is-focusable.js";
@@ -69,7 +70,7 @@ let ignoreFocusEvent = false;
69
70
  */
70
71
  function preventFocus(target) {
71
72
  let currentTarget = target;
72
- while (currentTarget && !isFocusable(currentTarget, { skipVisibilityCheck: true })) currentTarget = currentTarget.parentElement;
73
+ while (currentTarget && !isFocusable(currentTarget, { skipVisibilityCheck: true })) currentTarget = focusableElementOrNull(getParentElement(currentTarget));
73
74
  const ownerWindow = getOwnerWindow(currentTarget);
74
75
  const activeElement = focusableElementOrNull(getActiveElement(ownerWindow.document));
75
76
  if (!activeElement || activeElement === currentTarget) return;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":[],"sources":["../../../src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/utils.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport { onCleanup } from \"solid-js\";\n\nimport { getOwnerWindow, isNode, isShadowRoot } from \"../utils/dom-helpers\";\nimport { focusableElementOrNull, requireElement } from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { isFocusable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n getActiveElement,\n getEventTarget,\n nodeContains,\n} from \"../utils/shadowdom/dom-functions\";\n\nexport function setEventTarget<E extends Event, T extends Element>(\n event: E,\n target: T\n): asserts event is E & { readonly target: T; readonly currentTarget: T } {\n Object.defineProperty(event, \"target\", { value: target });\n Object.defineProperty(event, \"currentTarget\", { value: target });\n}\n\n/** Dispatch native blur events when a focused control becomes disabled. */\nexport function createBlurObserver(): (event: Event) => void {\n let cleanup: (() => void) | undefined;\n onCleanup(() => {\n cleanup?.();\n });\n\n return (event) => {\n cleanup?.();\n const target = getEventTarget(event);\n\n if (\n !(target instanceof HTMLButtonElement) &&\n !(target instanceof HTMLInputElement) &&\n !(target instanceof HTMLTextAreaElement) &&\n !(target instanceof HTMLSelectElement)\n ) {\n return;\n }\n\n const ownerWindow = getOwnerWindow(target);\n\n const observer = new ownerWindow.MutationObserver(() => {\n if (!target.disabled) {\n return;\n }\n\n observer.disconnect();\n const activeElement = getActiveElement(target.ownerDocument);\n const relatedTarget = target === activeElement ? null : activeElement;\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"blur\", { relatedTarget })\n );\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"focusout\", { bubbles: true, relatedTarget })\n );\n });\n\n const onBlur = () => {\n observer.disconnect();\n target.removeEventListener(\"focusout\", onBlur);\n };\n\n target.addEventListener(\"focusout\", onBlur, { once: true });\n observer.observe(target, {\n attributeFilter: [\"disabled\"],\n attributes: true,\n });\n cleanup = onBlur;\n };\n}\n\n// oxlint-disable-next-line import/no-mutable-exports -- Focus adapters observe this existing ESM live binding while native focus is being restored.\nexport let ignoreFocusEvent = false;\n\n/**\n * This function prevents the next focus event fired on `target`, without using\n * `event.preventDefault()`. It works by waiting for the series of focus events to occur, and\n * reverts focus back to where it was before. It also makes these events mostly non-observable by\n * using a capturing listener on the window and stopping propagation.\n */\nexport function preventFocus(\n target: FocusableElement | null\n): (() => void) | undefined {\n let currentTarget = target;\n\n // The browser will focus the nearest focusable ancestor of our target.\n while (\n currentTarget &&\n !isFocusable(currentTarget, { skipVisibilityCheck: true })\n ) {\n currentTarget = currentTarget.parentElement;\n }\n\n const ownerWindow = getOwnerWindow(currentTarget);\n\n const activeElement = focusableElementOrNull(\n getActiveElement(ownerWindow.document)\n );\n\n if (!activeElement || activeElement === currentTarget) {\n return undefined;\n }\n\n // Listen on the target's root (document or shadow root) so we catch focus events inside\n // shadow DOM; they do not reach the main window.\n const targetRoot = currentTarget?.getRootNode();\n\n const root =\n isPresent(targetRoot) && isShadowRoot(targetRoot)\n ? targetRoot\n : getOwnerWindow(currentTarget);\n\n // Focus is \"moving to target\" when it moves to the button or to a descendant of the button\n // (e.g. SVG icon)\n const isFocusMovingToTarget = (focusTarget: Element | null) =>\n focusTarget === currentTarget ||\n (isNode(focusTarget) && nodeContains(currentTarget, focusTarget));\n\n // Blur/focusout events have their target as the element losing focus. Stop propagation when\n // that is the previously focused element (activeElement) or a descendant (e.g. in shadow DOM).\n const isBlurFromActiveElement = (eventTarget: Element | null) =>\n eventTarget === activeElement ||\n (isPresent(activeElement) &&\n isNode(eventTarget) &&\n nodeContains(activeElement, eventTarget));\n\n ignoreFocusEvent = true;\n let isRefocusing = false;\n\n const onBlur: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusOut: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n // If there was no focusable ancestor, we don't expect a focus event.\n // Re-focus the original active element here.\n if (!currentTarget && !isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n const onFocus: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusIn: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n if (!isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n root.addEventListener(\"blur\", onBlur, true);\n root.addEventListener(\"focusout\", onFocusOut, true);\n root.addEventListener(\"focusin\", onFocusIn, true);\n root.addEventListener(\"focus\", onFocus, true);\n\n const raf = requestAnimationFrame(cleanup);\n\n function cleanup() {\n cancelAnimationFrame(raf);\n root.removeEventListener(\"blur\", onBlur, true);\n root.removeEventListener(\"focusout\", onFocusOut, true);\n root.removeEventListener(\"focusin\", onFocusIn, true);\n root.removeEventListener(\"focus\", onFocus, true);\n ignoreFocusEvent = false;\n isRefocusing = false;\n }\n\n return cleanup;\n}\n"],"mappings":";;;;;;;;;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IAAI;EAC7C,KAAK,oBAAoB,YAAY,YAAY,IAAI;EACrD,KAAK,oBAAoB,WAAW,WAAW,IAAI;EACnD,KAAK,oBAAoB,SAAS,SAAS,IAAI;EAC/C,mBAAmB;EACnB,eAAe;CACjB;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../../src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/interactions/utils.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type { FocusableElement } from \"@solid2-aria/types-shared\";\nimport { onCleanup } from \"solid-js\";\n\nimport { getOwnerWindow } from \"../utils/dom-helpers\";\nimport { focusableElementOrNull, requireElement } from \"../utils/dom-value\";\nimport { focusWithoutScrolling } from \"../utils/focus-without-scrolling\";\nimport { isFocusable } from \"../utils/is-focusable\";\nimport { isPresent } from \"../utils/is-present\";\nimport {\n getActiveElement,\n getEventTarget,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { isNode, isShadowRoot } from \"../utils/type-helpers\";\n\nexport function setEventTarget<E extends Event, T extends Element>(\n event: E,\n target: T\n): asserts event is E & { readonly target: T; readonly currentTarget: T } {\n Object.defineProperty(event, \"target\", { value: target });\n Object.defineProperty(event, \"currentTarget\", { value: target });\n}\n\n/** Dispatch native blur events when a focused control becomes disabled. */\nexport function createBlurObserver(): (event: Event) => void {\n let cleanup: (() => void) | undefined;\n onCleanup(() => {\n cleanup?.();\n });\n\n return (event) => {\n cleanup?.();\n const target = getEventTarget(event);\n\n if (\n !(target instanceof HTMLButtonElement) &&\n !(target instanceof HTMLInputElement) &&\n !(target instanceof HTMLTextAreaElement) &&\n !(target instanceof HTMLSelectElement)\n ) {\n return;\n }\n\n const ownerWindow = getOwnerWindow(target);\n\n const observer = new ownerWindow.MutationObserver(() => {\n if (!target.disabled) {\n return;\n }\n\n observer.disconnect();\n const activeElement = getActiveElement(target.ownerDocument);\n const relatedTarget = target === activeElement ? null : activeElement;\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"blur\", { relatedTarget })\n );\n target.dispatchEvent(\n new ownerWindow.FocusEvent(\"focusout\", { bubbles: true, relatedTarget })\n );\n });\n\n const onBlur = () => {\n observer.disconnect();\n target.removeEventListener(\"focusout\", onBlur);\n };\n\n target.addEventListener(\"focusout\", onBlur, { once: true });\n observer.observe(target, {\n attributeFilter: [\"disabled\"],\n attributes: true,\n });\n cleanup = onBlur;\n };\n}\n\n// oxlint-disable-next-line import/no-mutable-exports -- Focus adapters observe this existing ESM live binding while native focus is being restored.\nexport let ignoreFocusEvent = false;\n\n/**\n * This function prevents the next focus event fired on `target`, without using\n * `event.preventDefault()`. It works by waiting for the series of focus events to occur, and\n * reverts focus back to where it was before. It also makes these events mostly non-observable by\n * using a capturing listener on the window and stopping propagation.\n */\nexport function preventFocus(\n target: FocusableElement | null\n): (() => void) | undefined {\n let currentTarget = target;\n\n // The browser will focus the nearest focusable ancestor of our target.\n while (\n currentTarget &&\n !isFocusable(currentTarget, { skipVisibilityCheck: true })\n ) {\n currentTarget = focusableElementOrNull(getParentElement(currentTarget));\n }\n\n const ownerWindow = getOwnerWindow(currentTarget);\n\n const activeElement = focusableElementOrNull(\n getActiveElement(ownerWindow.document)\n );\n\n if (!activeElement || activeElement === currentTarget) {\n return undefined;\n }\n\n // Listen on the target's root (document or shadow root) so we catch focus events inside\n // shadow DOM; they do not reach the main window.\n const targetRoot = currentTarget?.getRootNode();\n\n const root =\n isPresent(targetRoot) && isShadowRoot(targetRoot)\n ? targetRoot\n : getOwnerWindow(currentTarget);\n\n // Focus is \"moving to target\" when it moves to the button or to a descendant of the button\n // (e.g. SVG icon)\n const isFocusMovingToTarget = (focusTarget: Element | null) =>\n focusTarget === currentTarget ||\n (isNode(focusTarget) && nodeContains(currentTarget, focusTarget));\n\n // Blur/focusout events have their target as the element losing focus. Stop propagation when\n // that is the previously focused element (activeElement) or a descendant (e.g. in shadow DOM).\n const isBlurFromActiveElement = (eventTarget: Element | null) =>\n eventTarget === activeElement ||\n (isPresent(activeElement) &&\n isNode(eventTarget) &&\n nodeContains(activeElement, eventTarget));\n\n ignoreFocusEvent = true;\n let isRefocusing = false;\n\n const onBlur: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusOut: EventListener = (e) => {\n if (\n isBlurFromActiveElement(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n // If there was no focusable ancestor, we don't expect a focus event.\n // Re-focus the original active element here.\n if (!currentTarget && !isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n const onFocus: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n }\n };\n\n const onFocusIn: EventListener = (e) => {\n if (\n isFocusMovingToTarget(requireElement(getEventTarget(e))) ||\n isRefocusing\n ) {\n e.stopImmediatePropagation();\n\n if (!isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n root.addEventListener(\"blur\", onBlur, true);\n root.addEventListener(\"focusout\", onFocusOut, true);\n root.addEventListener(\"focusin\", onFocusIn, true);\n root.addEventListener(\"focus\", onFocus, true);\n\n const raf = requestAnimationFrame(cleanup);\n\n function cleanup() {\n cancelAnimationFrame(raf);\n root.removeEventListener(\"blur\", onBlur, true);\n root.removeEventListener(\"focusout\", onFocusOut, true);\n root.removeEventListener(\"focusin\", onFocusIn, true);\n root.removeEventListener(\"focus\", onFocus, true);\n ignoreFocusEvent = false;\n isRefocusing = false;\n }\n\n return cleanup;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,eACd,OACA,QACwE;CACxE,OAAO,eAAe,OAAO,UAAU,EAAE,OAAO,OAAO,CAAC;CACxD,OAAO,eAAe,OAAO,iBAAiB,EAAE,OAAO,OAAO,CAAC;AACjE;;AAGA,SAAgB,qBAA6C;CAC3D,IAAI;CACJ,gBAAgB;EACd,UAAU;CACZ,CAAC;CAED,QAAQ,UAAU;EAChB,UAAU;EACV,MAAM,SAAS,eAAe,KAAK;EAEnC,IACE,EAAE,kBAAkB,sBACpB,EAAE,kBAAkB,qBACpB,EAAE,kBAAkB,wBACpB,EAAE,kBAAkB,oBAEpB;EAGF,MAAM,cAAc,eAAe,MAAM;EAEzC,MAAM,WAAW,IAAI,YAAY,uBAAuB;GACtD,IAAI,CAAC,OAAO,UACV;GAGF,SAAS,WAAW;GACpB,MAAM,gBAAgB,iBAAiB,OAAO,aAAa;GAC3D,MAAM,gBAAgB,WAAW,gBAAgB,OAAO;GACxD,OAAO,cACL,IAAI,YAAY,WAAW,QAAQ,EAAE,cAAc,CAAC,CACtD;GACA,OAAO,cACL,IAAI,YAAY,WAAW,YAAY;IAAE,SAAS;IAAM;GAAc,CAAC,CACzE;EACF,CAAC;EAED,MAAM,eAAe;GACnB,SAAS,WAAW;GACpB,OAAO,oBAAoB,YAAY,MAAM;EAC/C;EAEA,OAAO,iBAAiB,YAAY,QAAQ,EAAE,MAAM,KAAK,CAAC;EAC1D,SAAS,QAAQ,QAAQ;GACvB,iBAAiB,CAAC,UAAU;GAC5B,YAAY;EACd,CAAC;EACD,UAAU;CACZ;A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;EACF;CACF;CAEA,KAAK,iBAAiB,QAAQ,QAAQ,IAAI;CAC1C,KAAK,iBAAiB,YAAY,YAAY,IAAI;CAClD,KAAK,iBAAiB,WAAW,WAAW,IAAI;CAChD,KAAK,iBAAiB,SAAS,SAAS,IAAI;CAE5C,MAAM,MAAM,sBAAsB,OAAO;CAEzC,SAAS,UAAU;EACjB,qBAAqB,GAAG;EACxB,KAAK,oBAAoB,QAAQ,QAAQ,IAAI;EAC7C,KAAK,oBAAoB,YAAY,YAAY,IAAI;EACrD,KAAK,oBAAoB,WAAW,WAAW,IAAI;EACnD,KAAK,oBAAoB,SAAS,SAAS,IAAI;EAC/C,mBAAmB;EACnB,eAAe;CACjB;CAEA,OAAO;AACT"}
@@ -15,7 +15,7 @@
15
15
  * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.
16
16
  */
17
17
  import { getTruthyValue, isTruthy } from "../utils/truthy.js";
18
- import { getEventTarget, nodeContains } from "../utils/shadowdom/dom-functions.js";
18
+ import { getEventTarget, getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
19
19
  import { focusableElementOrNull, requireFocusableElement } from "../utils/dom-value.js";
20
20
  import { requireValue } from "../utils/require-value.js";
21
21
  import { ariaValue } from "../utils/aria-value.js";
@@ -148,7 +148,7 @@ var LandmarkManager = class {
148
148
  closestLandmark(element) {
149
149
  const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));
150
150
  let currentElement = element;
151
- while (isTruthy(currentElement) && !landmarkMap.has(currentElement) && currentElement !== document.body && currentElement.parentElement) currentElement = currentElement.parentElement;
151
+ while (isTruthy(currentElement) && !landmarkMap.has(currentElement) && currentElement !== document.body && getParentElement(currentElement)) currentElement = focusableElementOrNull(getParentElement(currentElement));
152
152
  return landmarkMap.get(currentElement);
153
153
  }
154
154
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"create-landmark.js","names":[],"sources":["../../../src/landmark/create-landmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/landmark/useLandmark.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n AriaLabelingProps,\n FocusableElement,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n untrack,\n onSettled,\n createMemo,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { ariaValue } from \"../utils/aria-value\";\nimport { hasAnyBit } from \"../utils/bit-mask\";\nimport {\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { requireValue } from \"../utils/require-value\";\nimport { getEventTarget, nodeContains } from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport type AriaLandmarkRole =\n | \"main\"\n | \"region\"\n | \"search\"\n | \"navigation\"\n | \"form\"\n | \"banner\"\n | \"contentinfo\"\n | \"complementary\";\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole;\n focus?: (direction: \"forward\" | \"backward\") => void;\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes;\n}\n\n// Increment this version number whenever the\n// LandmarkManagerApi or Landmark interfaces change.\nconst LANDMARK_API_VERSION = 1;\n\n// Minimal API for LandmarkManager that must continue to work between versions.\n// Changes to this interface are considered breaking. New methods/properties are\n// safe to add, but changes or removals are not allowed (same as public APIs).\ninterface LandmarkManagerApi {\n version: number;\n createLandmarkController: () => LandmarkController;\n registerLandmark: (landmark: Landmark) => () => void;\n}\n\n// Changes to this interface are considered breaking.\n// New properties MUST be optional so that registering a landmark\n// from an older version of useLandmark against a newer version of\n// LandmarkManager does not crash.\ninterface Landmark {\n ref: Accessor<FocusableElement | null>;\n role: AriaLandmarkRole;\n label?: string;\n lastFocused?: FocusableElement;\n focus: (direction: \"forward\" | \"backward\") => void;\n blur: () => void;\n}\n\nexport interface LandmarkControllerOptions {\n /**\n * The element from which to start navigating.\n *\n * @default document.activeElement\n */\n from?: FocusableElement;\n}\n\n/** A LandmarkController allows programmatic navigation of landmarks. */\nexport interface LandmarkController {\n /** Moves focus to the next landmark. */\n focusNext: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the previous landmark. */\n focusPrevious: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the main landmark. */\n focusMain: () => boolean;\n /** Moves focus either forward or backward in the landmark sequence. */\n navigate: (\n direction: \"forward\" | \"backward\",\n opts?: LandmarkControllerOptions\n ) => boolean;\n /**\n * Disposes the landmark controller. When no landmarks are registered, and no\n * controllers are active, the landmark keyboard listeners are removed from the page.\n */\n dispose: () => void;\n}\n\n// Symbol under which the singleton landmark manager instance is attached to the document.\nconst landmarkSymbol = Symbol.for(\"react-aria-landmark-manager\");\n\ndeclare global {\n interface Document {\n [landmarkSymbol]?: LandmarkManagerApi;\n }\n}\n\nfunction subscribe(fn: () => void) {\n document.addEventListener(\"react-aria-landmark-manager-change\", fn);\n\n return () => {\n document.removeEventListener(\"react-aria-landmark-manager-change\", fn);\n };\n}\n\nfunction getLandmarkManager(): LandmarkManagerApi | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n\n // Reuse an existing instance if it has the same or greater version.\n const instance = document[landmarkSymbol];\n\n if (instance && instance.version >= LANDMARK_API_VERSION) {\n return instance;\n }\n\n // Otherwise, create a new instance and dispatch an event so anything using the existing\n // instance updates and re-registers their landmarks with the new one.\n document[landmarkSymbol] = new LandmarkManager();\n document.dispatchEvent(new CustomEvent(\"react-aria-landmark-manager-change\"));\n\n return document[landmarkSymbol];\n}\n\n// Tracks the current landmark manager and releases its subscription with the owner.\nfunction createLandmarkManager() {\n const [manager, setManager] = createSignal(untrack(getLandmarkManager));\n\n const update = () => {\n setManager(getLandmarkManager());\n };\n\n onSettled(() => {\n const unsubscribe = subscribe(update);\n update();\n\n return unsubscribe;\n });\n\n return manager;\n}\n\nclass LandmarkManager implements LandmarkManagerApi {\n private landmarks: Landmark[] = [];\n private isListening = false;\n private refCount = 0;\n public version = LANDMARK_API_VERSION;\n\n private setupIfNeeded() {\n if (this.isListening) {\n return;\n }\n\n document.addEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.addEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.addEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = true;\n }\n private teardownIfNeeded() {\n if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) {\n return;\n }\n\n document.removeEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.removeEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.removeEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = false;\n }\n private focusLandmark(\n landmark: FocusableElement,\n direction: \"forward\" | \"backward\"\n ) {\n this.landmarks.find((l) => l.ref() === landmark)?.focus?.(direction);\n }\n /**\n * Return set of landmarks with a specific role.\n */\n private getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter((l) => l.role === role));\n }\n /**\n * Return first landmark with a specific role.\n */\n private getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find((l) => l.role === role);\n }\n private addLandmark(newLandmark: Landmark) {\n const newLandmarkrefElement = newLandmark.ref();\n this.setupIfNeeded();\n\n if (\n this.landmarks.some((landmark) => landmark.ref === newLandmark.ref) ||\n !newLandmarkrefElement\n ) {\n return;\n }\n\n if (\n this.landmarks.filter((landmark) => landmark.role === \"main\").length >\n 1 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.error(\n 'Page can contain no more than one landmark with the role \"main\".'\n );\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n this.checkLabels(newLandmark.role);\n\n return;\n }\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const existing = this.landmarks[mid]?.ref();\n\n if (!existing) {\n break;\n }\n\n const comparedPosition =\n newLandmarkrefElement.compareDocumentPosition(existing);\n\n const isNewAfterExisting =\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_PRECEDING) ||\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_CONTAINS);\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n this.checkLabels(newLandmark.role);\n }\n private updateLandmark(landmark: Pick<Landmark, \"ref\"> & Partial<Landmark>) {\n const index = this.landmarks.findIndex((l) => l.ref === landmark.ref);\n const existing = this.landmarks[index];\n\n if (existing) {\n const updated = { ...existing, ...landmark };\n this.landmarks[index] = updated;\n this.checkLabels(updated.role);\n }\n }\n private removeLandmark(ref: Accessor<Element | null>) {\n this.landmarks = this.landmarks.filter((landmark) => landmark.ref !== ref);\n this.teardownIfNeeded();\n }\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n const landmarksWithRole = this.getLandmarksByRole(role);\n\n if (landmarksWithRole.size > 1) {\n const duplicatesWithoutLabel = [...landmarksWithRole].filter(\n (landmark) => !isTruthy(landmark.label)\n );\n\n if (\n duplicatesWithoutLabel.length > 0 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute:`,\n duplicatesWithoutLabel.map((landmark) => landmark.ref())\n );\n } else if (process.env.NODE_ENV !== \"production\") {\n const labels = [...landmarksWithRole].map((landmark) => landmark.label);\n\n const duplicateLabels = labels.filter(\n (item, index) => labels.indexOf(item) !== index\n );\n\n for (const label of duplicateLabels) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels:`,\n [...landmarksWithRole].flatMap((landmark) =>\n landmark.label === label ? [landmark.ref()] : []\n )\n );\n }\n }\n }\n }\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: FocusableElement) {\n const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));\n let currentElement = element;\n\n while (\n isTruthy(currentElement) &&\n !landmarkMap.has(currentElement) &&\n currentElement !== document.body &&\n currentElement.parentElement\n ) {\n currentElement = currentElement.parentElement;\n }\n\n return landmarkMap.get(currentElement);\n }\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n private getNextLandmark(\n element: FocusableElement,\n {\n backward,\n }: {\n backward?: boolean;\n }\n ): undefined | Landmark {\n const currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = isTruthy(backward) ? this.landmarks.length - 1 : 0;\n\n if (currentLandmark) {\n nextLandmarkIndex =\n this.landmarks.indexOf(currentLandmark) + (isTruthy(backward) ? -1 : 1);\n }\n\n const wrapIfNeeded = () => {\n // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.\n // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.\n if (nextLandmarkIndex < 0) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"backward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"forward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = 0;\n }\n\n if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) {\n return true;\n }\n\n return false;\n };\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n // Skip over hidden landmarks.\n const i = nextLandmarkIndex;\n\n while (\n this.landmarks[nextLandmarkIndex]?.ref()?.closest(\"[aria-hidden=true]\")\n ) {\n nextLandmarkIndex += isTruthy(backward) ? -1 : 1;\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n if (nextLandmarkIndex === i) {\n break;\n }\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n private readonly f6Handler = (e: KeyboardEvent) => {\n if (e.key === \"F6\") {\n // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.\n const handled = e.altKey\n ? this.focusMain()\n : this.navigate(requireFocusableElement(getEventTarget(e)), e.shiftKey);\n\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n };\n private focusMain() {\n const main = this.getLandmarkByRole(\"main\");\n\n const mainElement = main?.ref();\n\n if (mainElement?.isConnected === true) {\n this.focusLandmark(mainElement, \"forward\");\n\n return true;\n }\n\n return false;\n }\n private navigate(from: FocusableElement, backward: boolean) {\n const nextLandmark = this.getNextLandmark(from, {\n backward,\n });\n\n if (!nextLandmark) {\n return false;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n const { lastFocused } = nextLandmark;\n\n if (nodeContains(document.body, lastFocused)) {\n lastFocused.focus();\n\n return true;\n }\n }\n\n // Otherwise, focus the landmark itself\n const nextElement = nextLandmark.ref();\n\n if (nextElement?.isConnected === true) {\n this.focusLandmark(nextElement, backward ? \"backward\" : \"forward\");\n\n return true;\n }\n\n return false;\n }\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n private readonly focusinHandler = (e: FocusEvent) => {\n const currentLandmark = this.closestLandmark(\n requireFocusableElement(getEventTarget(e))\n );\n\n if (currentLandmark && currentLandmark.ref() !== getEventTarget(e)) {\n this.updateLandmark({\n lastFocused: requireFocusableElement(getEventTarget(e)),\n ref: currentLandmark.ref,\n });\n }\n\n const previousFocusedElement = focusableElementOrNull(e.relatedTarget);\n\n if (isTruthy(previousFocusedElement)) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had\n * focus.\n */\n private readonly focusoutHandler = (e: FocusEvent) => {\n const previousFocusedElement = requireFocusableElement(getEventTarget(e));\n const nextFocusedElement = e.relatedTarget;\n\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n public createLandmarkController(): LandmarkController {\n // oxlint-disable-next-line typescript/no-this-alias, unicorn/no-this-assignment -- Controllers retain the manager until disposal and then release that reference.\n let instance: LandmarkManager | null = this;\n instance.refCount += 1;\n instance.setupIfNeeded();\n\n return {\n dispose() {\n if (instance) {\n instance.refCount -= 1;\n instance.teardownIfNeeded();\n instance = null;\n }\n },\n focusMain() {\n return requireValue(instance, \"Expected instance\").focusMain();\n },\n focusNext(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n false\n );\n },\n focusPrevious(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(element, true);\n },\n navigate(direction, opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n direction === \"backward\"\n );\n },\n };\n }\n public registerLandmark(landmark: Landmark): () => void {\n if (this.landmarks.some((l) => l.ref === landmark.ref)) {\n this.updateLandmark(landmark);\n } else {\n this.addLandmark(landmark);\n }\n\n return () => {\n this.removeLandmark(landmark.ref);\n };\n }\n}\n\n/** Creates a LandmarkController, which allows programmatic navigation of landmarks. */\nexport function UNSTABLE_createLandmarkController(): LandmarkController {\n // Get the current landmark manager and create a controller using it.\n let instance: LandmarkManagerApi | null = getLandmarkManager();\n let controller = instance?.createLandmarkController();\n\n const unsubscribe = subscribe(() => {\n // If the landmark manager changes, dispose the old\n // controller and create a new one.\n controller?.dispose();\n instance = getLandmarkManager();\n controller = instance?.createLandmarkController();\n });\n\n // Return a wrapper that proxies requests to the current controller instance.\n return {\n dispose() {\n controller?.dispose();\n unsubscribe();\n controller = undefined;\n instance = null;\n },\n focusMain() {\n return requireValue(controller, \"Expected controller\").focusMain();\n },\n focusNext(opts) {\n return requireValue(controller, \"Expected controller\").focusNext(opts);\n },\n focusPrevious(opts) {\n return requireValue(controller, \"Expected controller\").focusPrevious(\n opts\n );\n },\n navigate(direction, opts) {\n return requireValue(controller, \"Expected controller\").navigate(\n direction,\n opts\n );\n },\n };\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a\n * landmark navigable with F6.\n *\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function createLandmark(\n props: AriaLandmarkProps,\n ref: Accessor<FocusableElement | null>\n): LandmarkAria {\n const _result0 = props;\n const manager = createLandmarkManager();\n\n const label = createMemo(\n () => getTruthyValue(_result0[\"aria-label\"]) ?? _result0[\"aria-labelledby\"]\n );\n\n const [isLandmarkFocused, setIsLandmarkFocused] = createSignal(false, {\n ownedWrite: true,\n });\n\n const defaultFocus = () => {\n setIsLandmarkFocused(true);\n };\n\n const blur = () => {\n setIsLandmarkFocused(false);\n };\n\n createEffect(\n () => ({\n input2: ref(),\n input5: defaultFocus,\n input6: blur,\n manager: manager(),\n observedFocus: _result0.focus,\n observedLabel: label(),\n observedRole: _result0.role,\n }),\n ({\n input2: element,\n observedRole,\n observedLabel,\n input5,\n observedFocus,\n input6,\n manager: currentManager,\n }): undefined | (() => void) => {\n const instance = currentManager;\n\n if (instance) {\n return instance.registerLandmark({\n blur: input6,\n focus: getTruthyValue(observedFocus) ?? input5,\n label: observedLabel,\n ref: () => element,\n role: observedRole,\n });\n }\n\n return undefined;\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ element: ref(), isLandmarkFocused: isLandmarkFocused() }),\n ({ element, isLandmarkFocused: currentIsLandmarkFocused }) => {\n if (currentIsLandmarkFocused) {\n element?.focus();\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get landmarkProps() {\n return {\n get \"aria-label\"() {\n return ariaValue(ariaValue(_result0[\"aria-label\"]));\n },\n get \"aria-labelledby\"() {\n return ariaValue(ariaValue(_result0[\"aria-labelledby\"]));\n },\n get role() {\n return _result0.role;\n },\n get tabindex() {\n return isLandmarkFocused() ? -1 : undefined;\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8DA,MAAM,uBAAuB;AAsD7B,MAAM,iBAAiB,OAAO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GACA,IAAI,oBAAoB;IACtB,OAAO,UAAU,UAAU,SAAS,kBAAkB,CAAC;GACzD;GACA,IAAI,OAAO;IACT,OAAO,SAAS;GAClB;GACA,IAAI,WAAW;IACb,OAAO,kBAAkB,IAAI,KAAK,KAAA;GACpC;EACF;CACF,EACF;AACF"}
1
+ {"version":3,"file":"create-landmark.js","names":[],"sources":["../../../src/landmark/create-landmark.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n/*\n * Derived from Adobe React Spectrum: packages/react-aria/src/landmark/useLandmark.ts.\n * Modified for Solid Aria: adapted hooks, reactive getters, DOM types, and imports for Solid 2.\n * Licensed under Apache-2.0. See LICENSES/Apache-2.0.txt and NOTICE.txt at the repository root.\n */\n\nimport type {\n AriaLabelingProps,\n FocusableElement,\n} from \"@solid2-aria/types-shared\";\nimport type { DOMAttributes } from \"@solid2-aria/types-shared-web\";\nimport {\n untrack,\n onSettled,\n createMemo,\n createEffect,\n createSignal,\n} from \"solid-js\";\nimport type { Accessor } from \"solid-js\";\n\nimport { ariaValue } from \"../utils/aria-value\";\nimport { hasAnyBit } from \"../utils/bit-mask\";\nimport {\n focusableElementOrNull,\n requireFocusableElement,\n} from \"../utils/dom-value\";\nimport { requireValue } from \"../utils/require-value\";\nimport {\n getEventTarget,\n nodeContains,\n getParentElement,\n} from \"../utils/shadowdom/dom-functions\";\nimport { getTruthyValue, isTruthy } from \"../utils/truthy\";\n\nexport type AriaLandmarkRole =\n | \"main\"\n | \"region\"\n | \"search\"\n | \"navigation\"\n | \"form\"\n | \"banner\"\n | \"contentinfo\"\n | \"complementary\";\n\nexport interface AriaLandmarkProps extends AriaLabelingProps {\n role: AriaLandmarkRole;\n focus?: (direction: \"forward\" | \"backward\") => void;\n}\n\nexport interface LandmarkAria {\n landmarkProps: DOMAttributes;\n}\n\n// Increment this version number whenever the\n// LandmarkManagerApi or Landmark interfaces change.\nconst LANDMARK_API_VERSION = 1;\n\n// Minimal API for LandmarkManager that must continue to work between versions.\n// Changes to this interface are considered breaking. New methods/properties are\n// safe to add, but changes or removals are not allowed (same as public APIs).\ninterface LandmarkManagerApi {\n version: number;\n createLandmarkController: () => LandmarkController;\n registerLandmark: (landmark: Landmark) => () => void;\n}\n\n// Changes to this interface are considered breaking.\n// New properties MUST be optional so that registering a landmark\n// from an older version of useLandmark against a newer version of\n// LandmarkManager does not crash.\ninterface Landmark {\n ref: Accessor<FocusableElement | null>;\n role: AriaLandmarkRole;\n label?: string;\n lastFocused?: FocusableElement;\n focus: (direction: \"forward\" | \"backward\") => void;\n blur: () => void;\n}\n\nexport interface LandmarkControllerOptions {\n /**\n * The element from which to start navigating.\n *\n * @default document.activeElement\n */\n from?: FocusableElement;\n}\n\n/** A LandmarkController allows programmatic navigation of landmarks. */\nexport interface LandmarkController {\n /** Moves focus to the next landmark. */\n focusNext: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the previous landmark. */\n focusPrevious: (opts?: LandmarkControllerOptions) => boolean;\n /** Moves focus to the main landmark. */\n focusMain: () => boolean;\n /** Moves focus either forward or backward in the landmark sequence. */\n navigate: (\n direction: \"forward\" | \"backward\",\n opts?: LandmarkControllerOptions\n ) => boolean;\n /**\n * Disposes the landmark controller. When no landmarks are registered, and no\n * controllers are active, the landmark keyboard listeners are removed from the page.\n */\n dispose: () => void;\n}\n\n// Symbol under which the singleton landmark manager instance is attached to the document.\nconst landmarkSymbol = Symbol.for(\"react-aria-landmark-manager\");\n\ndeclare global {\n interface Document {\n [landmarkSymbol]?: LandmarkManagerApi;\n }\n}\n\nfunction subscribe(fn: () => void) {\n document.addEventListener(\"react-aria-landmark-manager-change\", fn);\n\n return () => {\n document.removeEventListener(\"react-aria-landmark-manager-change\", fn);\n };\n}\n\nfunction getLandmarkManager(): LandmarkManagerApi | null {\n if (typeof document === \"undefined\") {\n return null;\n }\n\n // Reuse an existing instance if it has the same or greater version.\n const instance = document[landmarkSymbol];\n\n if (instance && instance.version >= LANDMARK_API_VERSION) {\n return instance;\n }\n\n // Otherwise, create a new instance and dispatch an event so anything using the existing\n // instance updates and re-registers their landmarks with the new one.\n document[landmarkSymbol] = new LandmarkManager();\n document.dispatchEvent(new CustomEvent(\"react-aria-landmark-manager-change\"));\n\n return document[landmarkSymbol];\n}\n\n// Tracks the current landmark manager and releases its subscription with the owner.\nfunction createLandmarkManager() {\n const [manager, setManager] = createSignal(untrack(getLandmarkManager));\n\n const update = () => {\n setManager(getLandmarkManager());\n };\n\n onSettled(() => {\n const unsubscribe = subscribe(update);\n update();\n\n return unsubscribe;\n });\n\n return manager;\n}\n\nclass LandmarkManager implements LandmarkManagerApi {\n private landmarks: Landmark[] = [];\n private isListening = false;\n private refCount = 0;\n public version = LANDMARK_API_VERSION;\n\n private setupIfNeeded() {\n if (this.isListening) {\n return;\n }\n\n document.addEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.addEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.addEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = true;\n }\n private teardownIfNeeded() {\n if (!this.isListening || this.landmarks.length > 0 || this.refCount > 0) {\n return;\n }\n\n document.removeEventListener(\"keydown\", this.f6Handler, { capture: true });\n document.removeEventListener(\"focusin\", this.focusinHandler, {\n capture: true,\n });\n document.removeEventListener(\"focusout\", this.focusoutHandler, {\n capture: true,\n });\n this.isListening = false;\n }\n private focusLandmark(\n landmark: FocusableElement,\n direction: \"forward\" | \"backward\"\n ) {\n this.landmarks.find((l) => l.ref() === landmark)?.focus?.(direction);\n }\n /**\n * Return set of landmarks with a specific role.\n */\n private getLandmarksByRole(role: AriaLandmarkRole) {\n return new Set(this.landmarks.filter((l) => l.role === role));\n }\n /**\n * Return first landmark with a specific role.\n */\n private getLandmarkByRole(role: AriaLandmarkRole) {\n return this.landmarks.find((l) => l.role === role);\n }\n private addLandmark(newLandmark: Landmark) {\n const newLandmarkrefElement = newLandmark.ref();\n this.setupIfNeeded();\n\n if (\n this.landmarks.some((landmark) => landmark.ref === newLandmark.ref) ||\n !newLandmarkrefElement\n ) {\n return;\n }\n\n if (\n this.landmarks.filter((landmark) => landmark.role === \"main\").length >\n 1 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.error(\n 'Page can contain no more than one landmark with the role \"main\".'\n );\n }\n\n if (this.landmarks.length === 0) {\n this.landmarks = [newLandmark];\n this.checkLabels(newLandmark.role);\n\n return;\n }\n\n // Binary search to insert new landmark based on position in document relative to existing landmarks.\n // https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n let start = 0;\n let end = this.landmarks.length - 1;\n\n while (start <= end) {\n const mid = Math.floor((start + end) / 2);\n const existing = this.landmarks[mid]?.ref();\n\n if (!existing) {\n break;\n }\n\n const comparedPosition =\n newLandmarkrefElement.compareDocumentPosition(existing);\n\n const isNewAfterExisting =\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_PRECEDING) ||\n hasAnyBit(comparedPosition, Node.DOCUMENT_POSITION_CONTAINS);\n\n if (isNewAfterExisting) {\n start = mid + 1;\n } else {\n end = mid - 1;\n }\n }\n\n this.landmarks.splice(start, 0, newLandmark);\n this.checkLabels(newLandmark.role);\n }\n private updateLandmark(landmark: Pick<Landmark, \"ref\"> & Partial<Landmark>) {\n const index = this.landmarks.findIndex((l) => l.ref === landmark.ref);\n const existing = this.landmarks[index];\n\n if (existing) {\n const updated = { ...existing, ...landmark };\n this.landmarks[index] = updated;\n this.checkLabels(updated.role);\n }\n }\n private removeLandmark(ref: Accessor<Element | null>) {\n this.landmarks = this.landmarks.filter((landmark) => landmark.ref !== ref);\n this.teardownIfNeeded();\n }\n /**\n * Warn if there are 2+ landmarks with the same role but no label.\n * Labels for landmarks with the same role must also be unique.\n *\n * See https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/.\n */\n private checkLabels(role: AriaLandmarkRole) {\n const landmarksWithRole = this.getLandmarksByRole(role);\n\n if (landmarksWithRole.size > 1) {\n const duplicatesWithoutLabel = [...landmarksWithRole].filter(\n (landmark) => !isTruthy(landmark.label)\n );\n\n if (\n duplicatesWithoutLabel.length > 0 &&\n process.env.NODE_ENV !== \"production\"\n ) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute:`,\n duplicatesWithoutLabel.map((landmark) => landmark.ref())\n );\n } else if (process.env.NODE_ENV !== \"production\") {\n const labels = [...landmarksWithRole].map((landmark) => landmark.label);\n\n const duplicateLabels = labels.filter(\n (item, index) => labels.indexOf(item) !== index\n );\n\n for (const label of duplicateLabels) {\n console.warn(\n `Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels:`,\n [...landmarksWithRole].flatMap((landmark) =>\n landmark.label === label ? [landmark.ref()] : []\n )\n );\n }\n }\n }\n }\n /**\n * Get the landmark that is the closest parent in the DOM.\n * Returns undefined if no parent is a landmark.\n */\n private closestLandmark(element: FocusableElement) {\n const landmarkMap = new Map(this.landmarks.map((l) => [l.ref(), l]));\n let currentElement: FocusableElement | null = element;\n\n while (\n isTruthy(currentElement) &&\n !landmarkMap.has(currentElement) &&\n currentElement !== document.body &&\n getParentElement(currentElement)\n ) {\n currentElement = focusableElementOrNull(getParentElement(currentElement));\n }\n\n return landmarkMap.get(currentElement);\n }\n /**\n * Gets the next landmark, in DOM focus order, or previous if backwards is specified.\n * If last landmark, next should be the first landmark.\n * If not inside a landmark, will return first landmark.\n * Returns undefined if there are no landmarks.\n */\n private getNextLandmark(\n element: FocusableElement,\n {\n backward,\n }: {\n backward?: boolean;\n }\n ): undefined | Landmark {\n const currentLandmark = this.closestLandmark(element);\n let nextLandmarkIndex = isTruthy(backward) ? this.landmarks.length - 1 : 0;\n\n if (currentLandmark) {\n nextLandmarkIndex =\n this.landmarks.indexOf(currentLandmark) + (isTruthy(backward) ? -1 : 1);\n }\n\n const wrapIfNeeded = () => {\n // When we reach the end of the landmark sequence, fire a custom event that can be listened for by applications.\n // If this event is canceled, we return immediately. This can be used to implement landmark navigation across iframes.\n if (nextLandmarkIndex < 0) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"backward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = this.landmarks.length - 1;\n } else if (nextLandmarkIndex >= this.landmarks.length) {\n if (\n !element.dispatchEvent(\n new CustomEvent(\"react-aria-landmark-navigation\", {\n bubbles: true,\n cancelable: true,\n detail: { direction: \"forward\" },\n })\n )\n ) {\n return true;\n }\n\n nextLandmarkIndex = 0;\n }\n\n if (nextLandmarkIndex < 0 || nextLandmarkIndex >= this.landmarks.length) {\n return true;\n }\n\n return false;\n };\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n // Skip over hidden landmarks.\n const i = nextLandmarkIndex;\n\n while (\n this.landmarks[nextLandmarkIndex]?.ref()?.closest(\"[aria-hidden=true]\")\n ) {\n nextLandmarkIndex += isTruthy(backward) ? -1 : 1;\n\n if (wrapIfNeeded()) {\n return undefined;\n }\n\n if (nextLandmarkIndex === i) {\n break;\n }\n }\n\n return this.landmarks[nextLandmarkIndex];\n }\n /**\n * Look at next landmark. If an element was previously focused inside, restore focus there.\n * If not, focus the landmark itself.\n * If no landmarks at all, or none with focusable elements, don't move focus.\n */\n private readonly f6Handler = (e: KeyboardEvent) => {\n if (e.key === \"F6\") {\n // If alt key pressed, focus main landmark, otherwise navigate forward or backward based on shift key.\n const handled = e.altKey\n ? this.focusMain()\n : this.navigate(requireFocusableElement(getEventTarget(e)), e.shiftKey);\n\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n };\n private focusMain() {\n const main = this.getLandmarkByRole(\"main\");\n\n const mainElement = main?.ref();\n\n if (mainElement?.isConnected === true) {\n this.focusLandmark(mainElement, \"forward\");\n\n return true;\n }\n\n return false;\n }\n private navigate(from: FocusableElement, backward: boolean) {\n const nextLandmark = this.getNextLandmark(from, {\n backward,\n });\n\n if (!nextLandmark) {\n return false;\n }\n\n // If something was previously focused in the next landmark, then return focus to it\n if (nextLandmark.lastFocused) {\n const { lastFocused } = nextLandmark;\n\n if (nodeContains(document.body, lastFocused)) {\n lastFocused.focus();\n\n return true;\n }\n }\n\n // Otherwise, focus the landmark itself\n const nextElement = nextLandmark.ref();\n\n if (nextElement?.isConnected === true) {\n this.focusLandmark(nextElement, backward ? \"backward\" : \"forward\");\n\n return true;\n }\n\n return false;\n }\n /**\n * Sets lastFocused for a landmark, if focus is moved within that landmark.\n * Lets the last focused landmark know it was blurred if something else is focused.\n */\n private readonly focusinHandler = (e: FocusEvent) => {\n const currentLandmark = this.closestLandmark(\n requireFocusableElement(getEventTarget(e))\n );\n\n if (currentLandmark && currentLandmark.ref() !== getEventTarget(e)) {\n this.updateLandmark({\n lastFocused: requireFocusableElement(getEventTarget(e)),\n ref: currentLandmark.ref,\n });\n }\n\n const previousFocusedElement = focusableElementOrNull(e.relatedTarget);\n\n if (isTruthy(previousFocusedElement)) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n /**\n * Track if the focus is lost to the body. If it is, do cleanup on the landmark that last had\n * focus.\n */\n private readonly focusoutHandler = (e: FocusEvent) => {\n const previousFocusedElement = requireFocusableElement(getEventTarget(e));\n const nextFocusedElement = e.relatedTarget;\n\n // the === document seems to be a jest thing for focus to go there on generic blur event such as landmark.blur();\n // browsers appear to send focus instead to document.body and the relatedTarget is null when that happens\n if (!nextFocusedElement || nextFocusedElement === document) {\n const closestPreviousLandmark = this.closestLandmark(\n previousFocusedElement\n );\n\n if (\n closestPreviousLandmark &&\n closestPreviousLandmark.ref() === previousFocusedElement\n ) {\n closestPreviousLandmark.blur();\n }\n }\n };\n public createLandmarkController(): LandmarkController {\n // oxlint-disable-next-line typescript/no-this-alias, unicorn/no-this-assignment -- Controllers retain the manager until disposal and then release that reference.\n let instance: LandmarkManager | null = this;\n instance.refCount += 1;\n instance.setupIfNeeded();\n\n return {\n dispose() {\n if (instance) {\n instance.refCount -= 1;\n instance.teardownIfNeeded();\n instance = null;\n }\n },\n focusMain() {\n return requireValue(instance, \"Expected instance\").focusMain();\n },\n focusNext(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n false\n );\n },\n focusPrevious(opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(element, true);\n },\n navigate(direction, opts) {\n const element =\n getTruthyValue(opts?.from) ??\n focusableElementOrNull(document.activeElement);\n\n return element === null\n ? false\n : requireValue(instance, \"Expected instance\").navigate(\n element,\n direction === \"backward\"\n );\n },\n };\n }\n public registerLandmark(landmark: Landmark): () => void {\n if (this.landmarks.some((l) => l.ref === landmark.ref)) {\n this.updateLandmark(landmark);\n } else {\n this.addLandmark(landmark);\n }\n\n return () => {\n this.removeLandmark(landmark.ref);\n };\n }\n}\n\n/** Creates a LandmarkController, which allows programmatic navigation of landmarks. */\nexport function UNSTABLE_createLandmarkController(): LandmarkController {\n // Get the current landmark manager and create a controller using it.\n let instance: LandmarkManagerApi | null = getLandmarkManager();\n let controller = instance?.createLandmarkController();\n\n const unsubscribe = subscribe(() => {\n // If the landmark manager changes, dispose the old\n // controller and create a new one.\n controller?.dispose();\n instance = getLandmarkManager();\n controller = instance?.createLandmarkController();\n });\n\n // Return a wrapper that proxies requests to the current controller instance.\n return {\n dispose() {\n controller?.dispose();\n unsubscribe();\n controller = undefined;\n instance = null;\n },\n focusMain() {\n return requireValue(controller, \"Expected controller\").focusMain();\n },\n focusNext(opts) {\n return requireValue(controller, \"Expected controller\").focusNext(opts);\n },\n focusPrevious(opts) {\n return requireValue(controller, \"Expected controller\").focusPrevious(\n opts\n );\n },\n navigate(direction, opts) {\n return requireValue(controller, \"Expected controller\").navigate(\n direction,\n opts\n );\n },\n };\n}\n\n/**\n * Provides landmark navigation in an application. Call this with a role and label to register a\n * landmark navigable with F6.\n *\n * @param props - Props for the landmark.\n * @param ref - Ref to the landmark.\n */\nexport function createLandmark(\n props: AriaLandmarkProps,\n ref: Accessor<FocusableElement | null>\n): LandmarkAria {\n const _result0 = props;\n const manager = createLandmarkManager();\n\n const label = createMemo(\n () => getTruthyValue(_result0[\"aria-label\"]) ?? _result0[\"aria-labelledby\"]\n );\n\n const [isLandmarkFocused, setIsLandmarkFocused] = createSignal(false, {\n ownedWrite: true,\n });\n\n const defaultFocus = () => {\n setIsLandmarkFocused(true);\n };\n\n const blur = () => {\n setIsLandmarkFocused(false);\n };\n\n createEffect(\n () => ({\n input2: ref(),\n input5: defaultFocus,\n input6: blur,\n manager: manager(),\n observedFocus: _result0.focus,\n observedLabel: label(),\n observedRole: _result0.role,\n }),\n ({\n input2: element,\n observedRole,\n observedLabel,\n input5,\n observedFocus,\n input6,\n manager: currentManager,\n }): undefined | (() => void) => {\n const instance = currentManager;\n\n if (instance) {\n return instance.registerLandmark({\n blur: input6,\n focus: getTruthyValue(observedFocus) ?? input5,\n label: observedLabel,\n ref: () => element,\n role: observedRole,\n });\n }\n\n return undefined;\n },\n { ssrSource: \"client\" }\n );\n createEffect(\n () => ({ element: ref(), isLandmarkFocused: isLandmarkFocused() }),\n ({ element, isLandmarkFocused: currentIsLandmarkFocused }) => {\n if (currentIsLandmarkFocused) {\n element?.focus();\n }\n },\n { ssrSource: \"client\" }\n );\n\n return {\n get landmarkProps() {\n return {\n get \"aria-label\"() {\n return ariaValue(ariaValue(_result0[\"aria-label\"]));\n },\n get \"aria-labelledby\"() {\n return ariaValue(ariaValue(_result0[\"aria-labelledby\"]));\n },\n get role() {\n return _result0.role;\n },\n get tabindex() {\n return isLandmarkFocused() ? -1 : undefined;\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAM,uBAAuB;AAsD7B,MAAM,iBAAiB,OAAO,IAAI,6BAA6B;AAQ/D,SAAS,UAAU,IAAgB;CACjC,SAAS,iBAAiB,sCAAsC,EAAE;CAElE,aAAa;EACX,SAAS,oBAAoB,sCAAsC,EAAE;CACvE;AACF;AAEA,SAAS,qBAAgD;CACvD,IAAI,OAAO,aAAa,aACtB,OAAO;CAIT,MAAM,WAAW,SAAS;CAE1B,IAAI,YAAY,SAAS,WAAW,sBAClC,OAAO;CAKT,SAAS,kBAAkB,IAAI,gBAAgB;CAC/C,SAAS,cAAc,IAAI,YAAY,oCAAoC,CAAC;CAE5E,OAAO,SAAS;AAClB;AAGA,SAAS,wBAAwB;CAC/B,MAAM,CAAC,SAAS,cAAc,aAAa,QAAQ,kBAAkB,CAAC;CAEtE,MAAM,eAAe;EACnB,WAAW,mBAAmB,CAAC;CACjC;CAEA,gBAAgB;EACd,MAAM,cAAc,UAAU,MAAM;EACpC,OAAO;EAEP,OAAO;CACT,CAAC;CAED,OAAO;AACT;AAEA,IAAM,kBAAN,MAAoD;CAClD,YAAgC,CAAC;CACjC,cAAsB;CACtB,WAAmB;CACnB,UAAiB;CAEjB,gBAAwB;EACtB,IAAI,KAAK,aACP;EAGF,SAAS,iBAAiB,WAAW,KAAK,WAAW,EAAE,SAAS,KAAK,CAAC;EACtE,SAAS,iBAAiB,WAAW,KAAK,gBAAgB,EACxD,SAAS,KACX,CAAC;EACD,SAAS,iBAAiB,YAAY,KAAK,iBAAiB,EAC1D,SAAS,KACX,CAAC;EACD,KAAK,cA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ACxC,OAAO;GACP,WAAW;GACX,MAAM;EACR,CAAC;CAIL,GACA,EAAE,WAAW,SAAS,CACxB;CACA,oBACS;EAAE,SAAS,IAAI;EAAG,mBAAmB,kBAAkB;CAAE,KAC/D,EAAE,SAAS,mBAAmB,+BAA+B;EAC5D,IAAI,0BACF,SAAS,MAAM;CAEnB,GACA,EAAE,WAAW,SAAS,CACxB;CAEA,OAAO,EACL,IAAI,gBAAgB;EAClB,OAAO;GACL,IAAI,eAAe;IACjB,OAAO,UAAU,UAAU,SAAS,aAAa,CAAC;GACpD;GACA,IAAI,oBAAoB;IACtB,OAAO,UAAU,UAAU,SAAS,kBAAkB,CAAC;GACzD;GACA,IAAI,OAAO;IACT,OAAO,SAAS;GAClB;GACA,IAAI,WAAW;IACb,OAAO,kBAAkB,IAAI,KAAK,KAAA;GACpC;EACF;CACF,EACF;AACF"}
@@ -16,8 +16,9 @@
16
16
  */
17
17
  import { isTruthy, whenTruthy } from "../utils/truthy.js";
18
18
  import { isPresent } from "../utils/is-present.js";
19
- import { getOwnerDocument, getOwnerWindow, isShadowRoot } from "../utils/dom-helpers.js";
20
- import { nodeContains } from "../utils/shadowdom/dom-functions.js";
19
+ import { isShadowRoot } from "../utils/type-helpers.js";
20
+ import { getOwnerDocument, getOwnerWindow } from "../utils/dom-helpers.js";
21
+ import { getParentElement, nodeContains } from "../utils/shadowdom/dom-functions.js";
21
22
  import { elementOrNull } from "../utils/dom-value.js";
22
23
  import { createShadowTreeWalker } from "../utils/shadowdom/shadow-tree-walker.js";
23
24
  import { shadowDOM } from "@solid2-aria/stately/flags/flags";
@@ -65,7 +66,8 @@ function ariaHideOutside(targets, options) {
65
66
  }
66
67
  }
67
68
  const acceptNode = (node) => {
68
- if (hiddenNodes.has(node) || visibleNodes.has(node) || node.parentElement && hiddenNodes.has(node.parentElement) && node.parentElement.getAttribute("role") !== "row") return NodeFilter.FILTER_REJECT;
69
+ const parentElement = getParentElement(node);
70
+ if (hiddenNodes.has(node) || visibleNodes.has(node) || parentElement && hiddenNodes.has(parentElement) && parentElement.getAttribute("role") !== "row") return NodeFilter.FILTER_REJECT;
69
71
  for (const target of visibleNodes) if (nodeContains(node, target)) return NodeFilter.FILTER_SKIP;
70
72
  return NodeFilter.FILTER_ACCEPT;
71
73
  };