menhir 0.1.2 → 0.1.3

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 (155) hide show
  1. package/README.md +2 -2
  2. package/dist/alert-dialog/index.js +2 -0
  3. package/dist/alert-dialog/index.parts.js +7 -0
  4. package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
  5. package/dist/core/createControllableSignal.js +4 -3
  6. package/dist/core/slot.js +30 -0
  7. package/dist/dialog/close/DialogClose.js +33 -0
  8. package/dist/dialog/description/DialogDescription.js +27 -0
  9. package/dist/dialog/index.js +2 -0
  10. package/dist/dialog/index.parts.js +7 -0
  11. package/dist/dialog/popup/DialogPopup.js +13 -0
  12. package/dist/dialog/popup/renderDialogPopup.js +71 -0
  13. package/dist/dialog/root/DialogRoot.js +46 -0
  14. package/dist/dialog/root/DialogRootContext.js +10 -0
  15. package/dist/dialog/title/DialogTitle.js +27 -0
  16. package/dist/dialog/trigger/DialogTrigger.js +33 -0
  17. package/dist/floating/dismissal/dialogClose.js +67 -0
  18. package/dist/floating/dismissal/escape.js +43 -0
  19. package/dist/floating/dismissal/outsidePress.js +52 -0
  20. package/dist/floating/dismissal/popoverClose.js +74 -0
  21. package/dist/floating/dismissal/reason.js +0 -0
  22. package/dist/floating/focus/initialFocus.js +33 -0
  23. package/dist/floating/focus/returnFocus.js +65 -0
  24. package/dist/floating/focus/tabWrap.js +55 -0
  25. package/dist/floating/focus/tabbable.js +50 -0
  26. package/dist/floating/focus/target.js +0 -0
  27. package/dist/floating/hover/group.js +36 -0
  28. package/dist/floating/hover/hover.js +105 -0
  29. package/dist/floating/hover/safeArea.js +64 -0
  30. package/dist/floating/presence/presence.js +57 -0
  31. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  32. package/dist/popover/arrow/PopoverArrow.js +39 -0
  33. package/dist/popover/close/PopoverClose.js +33 -0
  34. package/dist/popover/description/PopoverDescription.js +27 -0
  35. package/dist/popover/index.js +2 -0
  36. package/dist/popover/index.parts.js +8 -0
  37. package/dist/popover/popup/PopoverPopup.js +116 -0
  38. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  39. package/dist/popover/root/PopoverRoot.js +50 -0
  40. package/dist/popover/root/PopoverRootContext.js +10 -0
  41. package/dist/popover/title/PopoverTitle.js +27 -0
  42. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  43. package/dist/source/alert-dialog/index.d.ts +1 -0
  44. package/dist/source/alert-dialog/index.js +1 -0
  45. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  46. package/dist/source/alert-dialog/index.parts.js +7 -0
  47. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  48. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  49. package/dist/source/core/createControllableSignal.d.ts +5 -4
  50. package/dist/source/core/createControllableSignal.js +4 -3
  51. package/dist/source/core/slot.d.ts +21 -0
  52. package/dist/source/core/slot.js +28 -0
  53. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  54. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  55. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  56. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  57. package/dist/source/dialog/index.d.ts +1 -0
  58. package/dist/source/dialog/index.js +1 -0
  59. package/dist/source/dialog/index.parts.d.ts +6 -0
  60. package/dist/source/dialog/index.parts.js +6 -0
  61. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  62. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  63. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  64. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  65. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  66. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  67. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  68. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  69. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  70. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  71. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  72. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  73. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  74. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  75. package/dist/source/floating/dismissal/escape.d.ts +23 -0
  76. package/dist/source/floating/dismissal/escape.js +47 -0
  77. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  78. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  79. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  80. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  81. package/dist/source/floating/dismissal/reason.d.ts +30 -0
  82. package/dist/source/floating/dismissal/reason.js +1 -0
  83. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  84. package/dist/source/floating/focus/initialFocus.js +38 -0
  85. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  86. package/dist/source/floating/focus/returnFocus.js +81 -0
  87. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  88. package/dist/source/floating/focus/tabWrap.js +69 -0
  89. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  90. package/dist/source/floating/focus/tabbable.js +69 -0
  91. package/dist/source/floating/focus/target.d.ts +8 -0
  92. package/dist/source/floating/focus/target.js +1 -0
  93. package/dist/source/floating/hover/group.d.ts +39 -0
  94. package/dist/source/floating/hover/group.js +38 -0
  95. package/dist/source/floating/hover/hover.d.ts +35 -0
  96. package/dist/source/floating/hover/hover.js +130 -0
  97. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  98. package/dist/source/floating/hover/safeArea.js +67 -0
  99. package/dist/source/floating/presence/presence.d.ts +24 -0
  100. package/dist/source/floating/presence/presence.js +73 -0
  101. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  102. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  103. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  104. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  105. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  106. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  107. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  108. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  109. package/dist/source/popover/index.d.ts +1 -0
  110. package/dist/source/popover/index.js +1 -0
  111. package/dist/source/popover/index.parts.d.ts +7 -0
  112. package/dist/source/popover/index.parts.js +7 -0
  113. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  114. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  115. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  116. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  117. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  118. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  119. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  120. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  121. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  122. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  123. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  124. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  125. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  126. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  127. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  128. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  129. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  130. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  131. package/dist/source/tooltip/index.d.ts +1 -0
  132. package/dist/source/tooltip/index.js +1 -0
  133. package/dist/source/tooltip/index.parts.d.ts +5 -0
  134. package/dist/source/tooltip/index.parts.js +5 -0
  135. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  136. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  137. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  138. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  139. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  140. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  141. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  142. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  143. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  144. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  145. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  146. package/dist/tooltip/group/TooltipGroup.js +26 -0
  147. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  148. package/dist/tooltip/index.js +2 -0
  149. package/dist/tooltip/index.parts.js +6 -0
  150. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  151. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  152. package/dist/tooltip/root/TooltipRoot.js +79 -0
  153. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  154. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  155. package/package.json +21 -1
@@ -0,0 +1,65 @@
1
+ import { createEffect, onCleanup } from "solid-js";
2
+ // src/floating/focus/returnFocus.ts
3
+ /**
4
+ * Moves focus to `returnFocus` once the popup has closed, instead of where
5
+ * the browser puts it: the element focused before a dialog opened, or a
6
+ * popover's trigger when focus was inside it. Without `returnFocus` the
7
+ * browser decides.
8
+ *
9
+ * ```ts
10
+ * createReturnFocus({
11
+ * get popup() { return dialog; },
12
+ * get open() { return open(); },
13
+ * get returnFocus() { return props.returnFocus; },
14
+ * });
15
+ * ```
16
+ *
17
+ * A focus the user moved out of the popup while it was shown, such as a
18
+ * press on another button that closed a popover, stays where it is. Focus
19
+ * returns once the popup is closed, not when its state turns false: after
20
+ * the flush that closed it, or on its `close` or `toggle` event if it is
21
+ * still shown then, as while an exit animation runs. A popup disposed while
22
+ * open moves no focus.
23
+ */
24
+ function createReturnFocus(options) {
25
+ let stop;
26
+ onCleanup(() => stop?.());
27
+ createEffect(() => options.open, (open) => {
28
+ const popup = options.popup;
29
+ if (!open || !popup) return;
30
+ stop?.();
31
+ let movedOut = false;
32
+ const focusin = (event) => {
33
+ if (isShown(popup)) movedOut = !popup.contains(event.target);
34
+ };
35
+ const finish = () => {
36
+ stop();
37
+ if (movedOut) return;
38
+ const active = document.activeElement;
39
+ const focused = active === document.body || popup.contains(active) ? null : active;
40
+ const target = options.returnFocus;
41
+ (typeof target === "function" ? target(focused) : target)?.focus();
42
+ };
43
+ const closed = (event) => {
44
+ if (event.newState !== "open") finish();
45
+ };
46
+ stop = () => {
47
+ stop = void 0;
48
+ document.removeEventListener("focusin", focusin);
49
+ popup.removeEventListener("close", closed);
50
+ popup.removeEventListener("toggle", closed);
51
+ };
52
+ document.addEventListener("focusin", focusin);
53
+ popup.addEventListener("close", closed);
54
+ popup.addEventListener("toggle", closed);
55
+ return () => {
56
+ queueMicrotask(() => {
57
+ if (stop && !isShown(popup)) finish();
58
+ });
59
+ };
60
+ });
61
+ }
62
+ function isShown(popup) {
63
+ return popup.matches("[open], :popover-open");
64
+ }
65
+ export { createReturnFocus };
@@ -0,0 +1,55 @@
1
+ import { isSameStop, tabStops } from "./tabbable.js";
2
+ import { createEffect } from "solid-js";
3
+ // src/floating/focus/tabWrap.ts
4
+ /**
5
+ * Tab and Shift+Tab cycle inside a modal `<dialog>` while `open`, as the
6
+ * WAI-ARIA modal dialog pattern asks. The browser lets them leave for its
7
+ * own UI.
8
+ *
9
+ * ```ts
10
+ * createTabWrap({
11
+ * get dialog() { return dialog; },
12
+ * get open() { return open(); },
13
+ * });
14
+ * ```
15
+ *
16
+ * Tab from the last tab stop, or from an element after it, moves to the
17
+ * first; Shift+Tab from the first, from an element before it or from the
18
+ * dialog itself, to the last. Elsewhere the browser moves focus. Only the
19
+ * topmost dialog wraps, and a key already handled does not.
20
+ */
21
+ function createTabWrap(options) {
22
+ createEffect(() => options.open, (open) => {
23
+ const dialog = options.dialog;
24
+ if (!open || !dialog) return;
25
+ const keydown = (event) => {
26
+ if (event.key !== "Tab" || event.defaultPrevented || dialogOf(event) !== dialog) return;
27
+ const stops = tabStops(dialog);
28
+ const forward = !event.shiftKey;
29
+ const edge = forward ? stops.at(-1) : stops[0];
30
+ let active = document.activeElement;
31
+ while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
32
+ if (!edge || isSameStop(active, edge) || !stops.some((stop) => isSameStop(active, stop)) && edge.compareDocumentPosition(active) & (forward ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING)) {
33
+ event.preventDefault();
34
+ (forward ? stops[0] : stops.at(-1))?.focus();
35
+ }
36
+ };
37
+ window.addEventListener("keydown", keydown);
38
+ return () => window.removeEventListener("keydown", keydown);
39
+ });
40
+ }
41
+ /**
42
+ * The nearest `<dialog>` around the key's target, across shadow roots: at
43
+ * the window, `target` is retargeted to the outermost shadow host.
44
+ */
45
+ function dialogOf(event) {
46
+ let node = event.composedPath()[0];
47
+ let dialog;
48
+ while (!(dialog = node.closest("dialog"))) {
49
+ const root = node.getRootNode();
50
+ if (!(root instanceof ShadowRoot)) break;
51
+ node = root.host;
52
+ }
53
+ return dialog;
54
+ }
55
+ export { createTabWrap };
@@ -0,0 +1,50 @@
1
+ // src/floating/focus/tabbable.ts
2
+ /**
3
+ * The tab stops inside `root`, in the order Tab visits them. Framework-free;
4
+ * reads layout, so call it in the browser, not on the server.
5
+ *
6
+ * A stop is an element whose `tabIndex` is 0 or more, or a `contenteditable`
7
+ * editing host with no `tabindex`, that is not `:disabled`, is visible and
8
+ * is not in an `inert` subtree. A radio group is one stop: its checked
9
+ * radio, else its first. An open shadow root is searched in place of its
10
+ * host's children, and a slot by what is assigned to it, else its fallback.
11
+ * Positive `tabindex` values come first, in ascending order.
12
+ */
13
+ function tabStops(root) {
14
+ const found = [];
15
+ const search = (parent) => {
16
+ const assigned = parent instanceof HTMLSlotElement ? parent.assignedElements() : [];
17
+ for (const element of parent.shadowRoot?.children ?? (assigned.length ? assigned : parent.children)) {
18
+ if (element.hasAttribute("inert")) continue;
19
+ if (isStop(element)) addStop(found, element);
20
+ search(element);
21
+ }
22
+ };
23
+ search(root);
24
+ return found.sort((a, b) => order(a) - order(b));
25
+ }
26
+ /** Whether Tab stops at `element`, leaving radio groups aside. */
27
+ function isStop(element) {
28
+ const { tabIndex, isContentEditable } = element;
29
+ return (tabIndex >= 0 ? element.localName !== "a" || element.hasAttribute("href") : isContentEditable && !element.parentElement?.isContentEditable && !element.hasAttribute("tabindex")) && !element.matches(":disabled") && element.checkVisibility({ visibilityProperty: true });
30
+ }
31
+ /** Adds a stop, keeping one radio per group: the checked one, else the first. */
32
+ function addStop(found, element) {
33
+ const index = found.findIndex((stop) => isSameStop(stop, element));
34
+ if (index < 0) found.push(element);
35
+ else if (element.checked) found[index] = element;
36
+ }
37
+ /** Whether `a` and `b` are one tab stop: the same element, or one radio group. */
38
+ function isSameStop(a, b) {
39
+ return a === b || isGroupedRadio(a) && isGroupedRadio(b) && a.name === b.name && a.form === b.form;
40
+ }
41
+ function isGroupedRadio(element) {
42
+ return element instanceof HTMLInputElement && element.type === "radio" && element.name !== "";
43
+ }
44
+ /** Above any positive `tabindex`, for the stops in tree order. */
45
+ var IN_TREE_ORDER = 2 ** 31;
46
+ /** Positive `tabindex` values first, then the rest. */
47
+ function order(element) {
48
+ return element.tabIndex > 0 ? element.tabIndex : IN_TREE_ORDER;
49
+ }
50
+ export { isSameStop, tabStops };
File without changes
@@ -0,0 +1,36 @@
1
+ // src/floating/hover/group.ts
2
+ /**
3
+ * A group of hover popups, such as the tooltips of a toolbar: once one is
4
+ * open, hovering another opens it at once and closes the first. Created by
5
+ * the part that groups triggers, provided through its context, and passed
6
+ * to each popup's `createHover` as `group`:
7
+ *
8
+ * ```ts
9
+ * const group = createHoverGroup({
10
+ * get delay() { return props.delay; },
11
+ * get timeout() { return props.timeout; },
12
+ * });
13
+ * ```
14
+ *
15
+ * The next member still opens at once within `timeout` milliseconds
16
+ * (default 400) of the last one closing. `delay` is the delay of members
17
+ * that set none. Only popups opened by hover count. It keeps the time of
18
+ * the last closing, not a timer, so it has nothing to clear.
19
+ */
20
+ function createHoverGroup(options = {}) {
21
+ let current;
22
+ let closedAt = -Infinity;
23
+ return {
24
+ delay: (own) => current || Date.now() - closedAt < (options.timeout ?? 400) ? 0 : own ?? options.delay,
25
+ opened(member, event) {
26
+ if (current !== member) current?.close(event);
27
+ current = member;
28
+ },
29
+ closed(member) {
30
+ if (current !== member) return;
31
+ current = void 0;
32
+ closedAt = Date.now();
33
+ }
34
+ };
35
+ }
36
+ export { createHoverGroup };
@@ -0,0 +1,105 @@
1
+ import { trackSafeArea } from "./safeArea.js";
2
+ import { createEffect, createSignal, onCleanup, onSettled } from "solid-js";
3
+ // src/floating/hover/hover.ts
4
+ /**
5
+ * Opens a popup when the pointer rests on its trigger for `delay`
6
+ * milliseconds (default 600), and closes it `closeDelay` milliseconds
7
+ * (default 0) after the pointer has left both the trigger and the popup:
8
+ *
9
+ * ```ts
10
+ * createHover({
11
+ * get trigger() { return trigger; },
12
+ * get popup() { return popup; },
13
+ * get open() { return open(); },
14
+ * get delay() { return props.delay; },
15
+ * onOpenChange: (open, details) => setOpen(open, details),
16
+ * });
17
+ * ```
18
+ *
19
+ * Both report `trigger-hover`. The pointer may cross from the trigger to the
20
+ * popup, and back, through the safe area between them (`trackSafeArea`).
21
+ * A mouse or a pen opens it; a touch does not. While `disabled`, hovering
22
+ * opens nothing. In a `group` (`createHoverGroup`), it opens at once while
23
+ * another member is open, and closes that one. A change of `open`, from
24
+ * here or elsewhere, and disposal clear a pending delay; disposal also
25
+ * takes the popup out of its group. Nothing runs on the server.
26
+ */
27
+ function createHover(options) {
28
+ let timer;
29
+ let stopSafeArea;
30
+ let last;
31
+ const cancel = () => {
32
+ clearTimeout(timer);
33
+ timer = void 0;
34
+ stopSafeArea?.();
35
+ stopSafeArea = void 0;
36
+ };
37
+ /** Opens or closes after `delay`, or now if it is 0. */
38
+ const schedule = (open, event, delay) => {
39
+ cancel();
40
+ const set = () => {
41
+ timer = void 0;
42
+ if (open && (options.disabled || !options.trigger?.isConnected)) return;
43
+ if (open) options.group?.opened(member, event);
44
+ options.onOpenChange(open, {
45
+ reason: "trigger-hover",
46
+ event
47
+ });
48
+ };
49
+ if (delay > 0) timer = setTimeout(set, delay);
50
+ else set();
51
+ };
52
+ const close = (event) => schedule(false, event, options.closeDelay ?? 0);
53
+ const member = { close: (event) => schedule(false, event, 0) };
54
+ onCleanup(() => {
55
+ cancel();
56
+ options.group?.closed(member);
57
+ });
58
+ const listen = (element, other, onEnter) => {
59
+ const enter = (event) => {
60
+ if (event.pointerType === "touch") return;
61
+ move(event);
62
+ cancel();
63
+ onEnter(event);
64
+ };
65
+ const move = (event) => {
66
+ if (event.pointerType !== "touch") last = event;
67
+ };
68
+ const leave = (event) => {
69
+ if (event.pointerType === "touch") return;
70
+ cancel();
71
+ if (!options.open) return;
72
+ const to = other();
73
+ if (to && event.relatedTarget && (event.clientX !== last?.clientX || event.clientY !== last.clientY)) stopSafeArea = trackSafeArea(event, to, close);
74
+ else close(event);
75
+ };
76
+ element.addEventListener("pointerenter", enter);
77
+ element.addEventListener("pointermove", move);
78
+ element.addEventListener("pointerleave", leave);
79
+ return () => {
80
+ element.removeEventListener("pointerenter", enter);
81
+ element.removeEventListener("pointermove", move);
82
+ element.removeEventListener("pointerleave", leave);
83
+ };
84
+ };
85
+ const [mounted, setMounted] = createSignal(false);
86
+ onSettled(() => {
87
+ setMounted(true);
88
+ });
89
+ createEffect(() => mounted() && options.trigger, (trigger) => {
90
+ if (!trigger) return;
91
+ return listen(trigger, () => options.popup, (event) => {
92
+ if (options.open || options.disabled) return;
93
+ const group = options.group;
94
+ schedule(true, event, (group ? group.delay(options.delay) : options.delay) ?? 600);
95
+ });
96
+ });
97
+ createEffect(() => options.open, (open) => {
98
+ cancel();
99
+ if (!open) options.group?.closed(member);
100
+ const popup = options.popup;
101
+ if (!open || !popup) return;
102
+ return listen(popup, () => options.trigger, () => {});
103
+ });
104
+ }
105
+ export { createHover };
@@ -0,0 +1,64 @@
1
+ // src/floating/hover/safeArea.ts
2
+ /**
3
+ * Follows the pointer once it has left one element on its way to another,
4
+ * such as from a trigger to its popup across the gap between them, and
5
+ * calls `onLeave` with the event once it moves out of the way:
6
+ *
7
+ * ```ts
8
+ * trigger.addEventListener("pointerleave", (event) => {
9
+ * stop = trackSafeArea(event, popup, () => close());
10
+ * });
11
+ * ```
12
+ *
13
+ * The safe area is every point on a line from `exit`, where the pointer
14
+ * left, to the box of `element`, read again on each move. A move outside
15
+ * it, or past the element, ends it, and so does the pointer leaving the
16
+ * window. A touch is ignored. Returns what stops following; call it when
17
+ * the pointer reaches the element. Plain DOM, with no timers and no Solid.
18
+ */
19
+ function trackSafeArea(exit, element, onLeave) {
20
+ const check = (event) => {
21
+ if (event.pointerType === "touch" || (event.type === "pointerout" ? event.relatedTarget : inSafeArea(exit, event, element.getBoundingClientRect()))) return;
22
+ stop();
23
+ onLeave(event);
24
+ };
25
+ const stop = () => {
26
+ document.removeEventListener("pointermove", check);
27
+ document.removeEventListener("pointerout", check);
28
+ };
29
+ document.addEventListener("pointermove", check);
30
+ document.addEventListener("pointerout", check);
31
+ return stop;
32
+ }
33
+ /**
34
+ * Whether `point` is on a line from `exit` to `box`: whether the ray from
35
+ * `exit` through `point` meets the box at or beyond `point`. Each axis
36
+ * gives the stretch of the ray, in multiples of `exit` to `point`, that is
37
+ * within the box's extent on it; the point is inside if the stretches of
38
+ * both axes overlap beyond 1.
39
+ */
40
+ function inSafeArea(exit, point, box) {
41
+ let from = 1;
42
+ let to = Infinity;
43
+ for (const [start, end, min, max] of [[
44
+ exit.clientX,
45
+ point.clientX,
46
+ box.left,
47
+ box.right
48
+ ], [
49
+ exit.clientY,
50
+ point.clientY,
51
+ box.top,
52
+ box.bottom
53
+ ]]) {
54
+ const step = end - start;
55
+ if (step) {
56
+ const a = (min - start) / step;
57
+ const b = (max - start) / step;
58
+ from = Math.max(from, Math.min(a, b));
59
+ to = Math.min(to, Math.max(a, b));
60
+ } else if (start < min || start > max) return point.clientX === exit.clientX && point.clientY === exit.clientY;
61
+ }
62
+ return from <= to;
63
+ }
64
+ export { trackSafeArea };
@@ -0,0 +1,57 @@
1
+ import { createEffect } from "solid-js";
2
+ // src/floating/presence/presence.ts
3
+ /**
4
+ * Shows a popup when `open` turns true, and hides it once its exit
5
+ * animations have ended after `open` turns false:
6
+ *
7
+ * ```ts
8
+ * createPresence({
9
+ * get popup() { return dialog; },
10
+ * get open() { return open(); },
11
+ * });
12
+ * ```
13
+ *
14
+ * A `<dialog>` is shown with `showModal()` and hidden with `close()`; any
15
+ * other element is a popover, shown with `showPopover()` and hidden with
16
+ * `hidePopover()`. On closing it waits for the animations and transitions
17
+ * running in the popup, its descendants and its `::backdrop`, the ones its
18
+ * `data-closed` starts, and hides it at once if none is running; infinite
19
+ * and paused ones do not count. Meanwhile the popup is `inert`, unless it is
20
+ * a popover that holds focus, which only returns focus to its trigger from
21
+ * inside. Opening again cancels the exit. Nothing runs on the server.
22
+ */
23
+ function createPresence(options) {
24
+ let stopLeaving;
25
+ createEffect(() => options.open, (open) => {
26
+ const popup = options.popup;
27
+ if (!popup) return;
28
+ const dialog = popup instanceof HTMLDialogElement ? popup : void 0;
29
+ stopLeaving?.();
30
+ if (open) {
31
+ if (dialog) {
32
+ if (!dialog.open) dialog.showModal();
33
+ } else if (!popup.matches(":popover-open")) popup.showPopover();
34
+ return;
35
+ }
36
+ if (!popup.matches("[open], :popover-open")) return;
37
+ const inert = popup.inert;
38
+ if (dialog || !popup.contains(document.activeElement)) popup.inert = true;
39
+ const stop = stopLeaving = () => {
40
+ stopLeaving = void 0;
41
+ popup.inert = inert;
42
+ };
43
+ const wait = () => {
44
+ if (stopLeaving !== stop) return;
45
+ const running = popup.getAnimations({ subtree: true }).filter((animation) => animation.playState === "running" && animation.effect?.getComputedTiming().endTime !== Infinity);
46
+ if (running.length) {
47
+ Promise.allSettled(running.map((animation) => animation.finished)).then(wait);
48
+ return;
49
+ }
50
+ stop();
51
+ if (dialog) dialog.close();
52
+ else if (popup.matches(":popover-open")) popup.hidePopover();
53
+ };
54
+ wait();
55
+ });
56
+ }
57
+ export { createPresence };
@@ -0,0 +1,125 @@
1
+ import { createEffect, onCleanup } from "solid-js";
2
+ // src/floating/scroll-lock/scrollLock.ts
3
+ var locks = 0;
4
+ var restoreStyles;
5
+ /**
6
+ * Keeps the page from scrolling while a modal popup is open: `overflow:
7
+ * hidden` on `<html>`, as `showModal()` leaves the page scrolling.
8
+ *
9
+ * ```ts
10
+ * createScrollLock({
11
+ * get popup() { return dialog; },
12
+ * get open() { return open(); },
13
+ * });
14
+ * ```
15
+ *
16
+ * Counted, so nested popups unlock the page when the last one closes. A
17
+ * page with a scrollbar gets its width as padding on `<html>`, so nothing
18
+ * moves, and as `--hidden-scrollbar-width` for `position: fixed` elements;
19
+ * a page with `scrollbar-gutter: stable` gets neither. Unlocking puts back
20
+ * the page's own inline styles. The page unlocks once the popup has
21
+ * closed, not when its state turns false: after the flush that closed it,
22
+ * or on its `close` or `toggle` event if it is still shown then, as while
23
+ * an exit animation runs. A popup disposed while open unlocks it at once.
24
+ * While open, the popup gets `overscroll-behavior: contain` and, if it
25
+ * does not scroll itself, `touch-action: pinch-zoom`, without which iOS
26
+ * Safari scrolls the page from a drag on it or on its backdrop.
27
+ */
28
+ function createScrollLock(options) {
29
+ let held;
30
+ let stopWaiting;
31
+ const release = () => {
32
+ stopWaiting?.();
33
+ held?.();
34
+ held = void 0;
35
+ };
36
+ onCleanup(release);
37
+ createEffect(() => options.open, (open) => {
38
+ const popup = options.popup;
39
+ if (!open || !popup) return;
40
+ stopWaiting?.();
41
+ if (!held) {
42
+ lock();
43
+ const unlockTouch = lockTouch(popup);
44
+ held = () => {
45
+ unlockTouch();
46
+ unlock();
47
+ };
48
+ }
49
+ return () => {
50
+ queueMicrotask(() => {
51
+ if (!held || stopWaiting) return;
52
+ if (!popup.matches("[open], :popover-open")) return release();
53
+ const closed = (event) => {
54
+ if (event.newState !== "open") release();
55
+ };
56
+ stopWaiting = () => {
57
+ stopWaiting = void 0;
58
+ popup.removeEventListener("close", closed);
59
+ popup.removeEventListener("toggle", closed);
60
+ };
61
+ popup.addEventListener("close", closed);
62
+ popup.addEventListener("toggle", closed);
63
+ });
64
+ };
65
+ });
66
+ }
67
+ function lock() {
68
+ if (locks++) return;
69
+ const html = document.documentElement;
70
+ const style = html.style;
71
+ const lockStyles = {
72
+ "overflow-x": "hidden",
73
+ "overflow-y": "hidden"
74
+ };
75
+ const scrollbarWidth = innerWidth - html.clientWidth;
76
+ const computed = getComputedStyle(html);
77
+ if (scrollbarWidth > 0 && !computed.getPropertyValue("scrollbar-gutter").startsWith("stable")) {
78
+ lockStyles["padding-right"] = `${parseFloat(computed.paddingRight) + scrollbarWidth}px`;
79
+ lockStyles["--hidden-scrollbar-width"] = `${scrollbarWidth}px`;
80
+ }
81
+ restoreStyles = saveStyles(style, Object.keys(lockStyles));
82
+ for (const name in lockStyles) style.setProperty(name, lockStyles[name]);
83
+ }
84
+ function unlock() {
85
+ if (!--locks) restoreStyles();
86
+ }
87
+ /**
88
+ * What keeps iOS Safari from scrolling the page through the popup, whatever
89
+ * the page's `overflow`: `overscroll-behavior: contain`, so a popup that
90
+ * scrolls stops at its end, and `touch-action: pinch-zoom` on a popup that
91
+ * does not scroll itself, so that a drag on it, or on its backdrop, which
92
+ * hits the popup, pans nothing. Checked again as the popup or its content
93
+ * changes size. A popup that scrolls keeps its own `touch-action`, since
94
+ * Chromium would no longer scroll it by touch.
95
+ */
96
+ function lockTouch(popup) {
97
+ const style = popup.style;
98
+ const restoreContain = saveStyles(style, ["overscroll-behavior"]);
99
+ const restoreTouch = saveStyles(style, ["touch-action"]);
100
+ style.setProperty("overscroll-behavior", "contain");
101
+ const observer = new ResizeObserver(() => {
102
+ for (const child of popup.children) observer.observe(child);
103
+ if (popup.scrollHeight > popup.clientHeight || popup.scrollWidth > popup.clientWidth) restoreTouch();
104
+ else style.setProperty("touch-action", "pinch-zoom");
105
+ });
106
+ observer.observe(popup);
107
+ return () => {
108
+ observer.disconnect();
109
+ restoreTouch();
110
+ restoreContain();
111
+ };
112
+ }
113
+ /** Saves the inline values of `names`, and returns what puts them back. */
114
+ function saveStyles(style, names) {
115
+ const saved = names.map((name) => [
116
+ name,
117
+ style.getPropertyValue(name),
118
+ style.getPropertyPriority(name)
119
+ ]);
120
+ return () => {
121
+ for (const [name, value, priority] of saved) if (value) style.setProperty(name, value, priority);
122
+ else style.removeProperty(name);
123
+ };
124
+ }
125
+ export { createScrollLock };
@@ -0,0 +1,39 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { arrow } from "../../floating/positioning/arrow.js";
4
+ import { usePopoverPopupContext } from "../popup/PopoverPopupContext.js";
5
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
6
+ import { spread, template } from "@solidjs/web";
7
+ import { merge, omit, onSettled } from "solid-js";
8
+ // src/popover/arrow/PopoverArrow.tsx
9
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
10
+ /**
11
+ * An arrow that points at the anchor's center: an `aria-hidden` `<div>`
12
+ * whose `left` or `top` the Popup writes. Position it absolutely on the
13
+ * Popup's edge by its `data-side`. Place it inside `Popover.Popup`.
14
+ */
15
+ function PopoverArrow(props) {
16
+ const root = usePopoverRootContext();
17
+ const popup = usePopoverPopupContext();
18
+ let element;
19
+ onSettled(() => popup.registerArrow(() => arrow({ element })));
20
+ const ownProps = merge(root.attributes, {
21
+ "aria-hidden": "true",
22
+ get "data-side"() {
23
+ return popup.position()?.side;
24
+ },
25
+ get "data-align"() {
26
+ return popup.position()?.align;
27
+ },
28
+ ref: (el) => {
29
+ element = el;
30
+ }
31
+ });
32
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
33
+ return renderElement(props, elementProps, (p) => (() => {
34
+ var _el$ = _tmpl$();
35
+ spread(_el$, p, false);
36
+ return _el$;
37
+ })());
38
+ }
39
+ export { PopoverArrow };
@@ -0,0 +1,33 @@
1
+ import { warnUnlessButton } from "../../core/button.js";
2
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
3
+ import { renderElement } from "../../core/renderElement.js";
4
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
5
+ import { isDev, spread, template } from "@solidjs/web";
6
+ import { merge, omit } from "solid-js";
7
+ // src/popover/close/PopoverClose.tsx
8
+ var _tmpl$ = /* @__PURE__ */ template(`<button>`);
9
+ /**
10
+ * A button that closes the popover: a `<button type="button">`, such as
11
+ * "Cancel" or a close icon with an `aria-label`. Place it inside
12
+ * `Popover.Popup`.
13
+ */
14
+ function PopoverClose(props) {
15
+ const root = usePopoverRootContext();
16
+ const ownProps = merge(root.attributes, {
17
+ type: "button",
18
+ onClick: (event) => root.setOpen(false, {
19
+ reason: "close-press",
20
+ event
21
+ }),
22
+ ref: (element) => {
23
+ if (isDev) warnUnlessButton(element, "Popover.Close");
24
+ }
25
+ });
26
+ const elementProps = mergeElementProps(ownProps, omit(props, "render"));
27
+ return renderElement(props, elementProps, (p) => (() => {
28
+ var _el$ = _tmpl$();
29
+ spread(_el$, p, false);
30
+ return _el$;
31
+ })());
32
+ }
33
+ export { PopoverClose };
@@ -0,0 +1,27 @@
1
+ import { mergeElementProps } from "../../core/mergeElementProps.js";
2
+ import { renderElement } from "../../core/renderElement.js";
3
+ import { usePopoverRootContext } from "../root/PopoverRootContext.js";
4
+ import { spread, template } from "@solidjs/web";
5
+ import { createUniqueId, merge, omit, onSettled } from "solid-js";
6
+ // src/popover/description/PopoverDescription.tsx
7
+ var _tmpl$ = /* @__PURE__ */ template(`<p>`);
8
+ /**
9
+ * What the popover is for, which describes the Popup in
10
+ * `aria-describedby`: a `<p>`. Place it inside `Popover.Popup`.
11
+ */
12
+ function PopoverDescription(props) {
13
+ const root = usePopoverRootContext();
14
+ const generated = createUniqueId();
15
+ const id = () => props.id ?? generated;
16
+ onSettled(() => root.registerDescriptionId(id));
17
+ const ownProps = merge(root.attributes, { get id() {
18
+ return id();
19
+ } });
20
+ const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
21
+ return renderElement(props, elementProps, (p) => (() => {
22
+ var _el$ = _tmpl$();
23
+ spread(_el$, p, false);
24
+ return _el$;
25
+ })());
26
+ }
27
+ export { PopoverDescription };
@@ -0,0 +1,2 @@
1
+ import * as Popover from "./index.parts.js";
2
+ export { Popover };
@@ -0,0 +1,8 @@
1
+ import { PopoverRoot } from "./root/PopoverRoot.js";
2
+ import { PopoverTrigger } from "./trigger/PopoverTrigger.js";
3
+ import { PopoverPopup } from "./popup/PopoverPopup.js";
4
+ import { PopoverArrow } from "./arrow/PopoverArrow.js";
5
+ import { PopoverTitle } from "./title/PopoverTitle.js";
6
+ import { PopoverDescription } from "./description/PopoverDescription.js";
7
+ import { PopoverClose } from "./close/PopoverClose.js";
8
+ export { PopoverArrow as Arrow, PopoverClose as Close, PopoverDescription as Description, PopoverPopup as Popup, PopoverRoot as Root, PopoverTitle as Title, PopoverTrigger as Trigger };