menhir 0.1.1 → 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 (176) 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/positioning/arrow.js +21 -0
  31. package/dist/floating/positioning/createPosition.js +122 -0
  32. package/dist/floating/positioning/flip.js +1 -0
  33. package/dist/floating/positioning/hide.js +14 -0
  34. package/dist/floating/positioning/offset.js +1 -0
  35. package/dist/floating/positioning/shift.js +1 -0
  36. package/dist/floating/positioning/size.js +39 -0
  37. package/dist/floating/presence/presence.js +57 -0
  38. package/dist/floating/scroll-lock/scrollLock.js +125 -0
  39. package/dist/popover/arrow/PopoverArrow.js +39 -0
  40. package/dist/popover/close/PopoverClose.js +33 -0
  41. package/dist/popover/description/PopoverDescription.js +27 -0
  42. package/dist/popover/index.js +2 -0
  43. package/dist/popover/index.parts.js +8 -0
  44. package/dist/popover/popup/PopoverPopup.js +116 -0
  45. package/dist/popover/popup/PopoverPopupContext.js +10 -0
  46. package/dist/popover/root/PopoverRoot.js +50 -0
  47. package/dist/popover/root/PopoverRootContext.js +10 -0
  48. package/dist/popover/title/PopoverTitle.js +27 -0
  49. package/dist/popover/trigger/PopoverTrigger.js +44 -0
  50. package/dist/source/alert-dialog/index.d.ts +1 -0
  51. package/dist/source/alert-dialog/index.js +1 -0
  52. package/dist/source/alert-dialog/index.parts.d.ts +6 -0
  53. package/dist/source/alert-dialog/index.parts.js +7 -0
  54. package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
  55. package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
  56. package/dist/source/core/createControllableSignal.d.ts +5 -4
  57. package/dist/source/core/createControllableSignal.js +4 -3
  58. package/dist/source/core/slot.d.ts +21 -0
  59. package/dist/source/core/slot.js +28 -0
  60. package/dist/source/dialog/close/DialogClose.d.ts +11 -0
  61. package/dist/source/dialog/close/DialogClose.jsx +25 -0
  62. package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
  63. package/dist/source/dialog/description/DialogDescription.jsx +26 -0
  64. package/dist/source/dialog/index.d.ts +1 -0
  65. package/dist/source/dialog/index.js +1 -0
  66. package/dist/source/dialog/index.parts.d.ts +6 -0
  67. package/dist/source/dialog/index.parts.js +6 -0
  68. package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
  69. package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
  70. package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
  71. package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
  72. package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
  73. package/dist/source/dialog/root/DialogRoot.jsx +39 -0
  74. package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
  75. package/dist/source/dialog/root/DialogRootContext.js +14 -0
  76. package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
  77. package/dist/source/dialog/title/DialogTitle.jsx +26 -0
  78. package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
  79. package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
  80. package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
  81. package/dist/source/floating/dismissal/dialogClose.js +69 -0
  82. package/dist/source/floating/dismissal/escape.d.ts +23 -0
  83. package/dist/source/floating/dismissal/escape.js +47 -0
  84. package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
  85. package/dist/source/floating/dismissal/outsidePress.js +50 -0
  86. package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
  87. package/dist/source/floating/dismissal/popoverClose.js +82 -0
  88. package/dist/source/floating/dismissal/reason.d.ts +30 -0
  89. package/dist/source/floating/dismissal/reason.js +1 -0
  90. package/dist/source/floating/focus/initialFocus.d.ts +24 -0
  91. package/dist/source/floating/focus/initialFocus.js +38 -0
  92. package/dist/source/floating/focus/returnFocus.d.ts +27 -0
  93. package/dist/source/floating/focus/returnFocus.js +81 -0
  94. package/dist/source/floating/focus/tabWrap.d.ts +21 -0
  95. package/dist/source/floating/focus/tabWrap.js +69 -0
  96. package/dist/source/floating/focus/tabbable.d.ts +16 -0
  97. package/dist/source/floating/focus/tabbable.js +69 -0
  98. package/dist/source/floating/focus/target.d.ts +8 -0
  99. package/dist/source/floating/focus/target.js +1 -0
  100. package/dist/source/floating/hover/group.d.ts +39 -0
  101. package/dist/source/floating/hover/group.js +38 -0
  102. package/dist/source/floating/hover/hover.d.ts +35 -0
  103. package/dist/source/floating/hover/hover.js +130 -0
  104. package/dist/source/floating/hover/safeArea.d.ts +23 -0
  105. package/dist/source/floating/hover/safeArea.js +67 -0
  106. package/dist/source/floating/positioning/arrow.d.ts +13 -0
  107. package/dist/source/floating/positioning/arrow.js +20 -0
  108. package/dist/source/floating/positioning/createPosition.d.ts +53 -0
  109. package/dist/source/floating/positioning/createPosition.js +138 -0
  110. package/dist/source/floating/positioning/flip.d.ts +1 -0
  111. package/dist/source/floating/positioning/flip.js +3 -0
  112. package/dist/source/floating/positioning/hide.d.ts +8 -0
  113. package/dist/source/floating/positioning/hide.js +12 -0
  114. package/dist/source/floating/positioning/offset.d.ts +1 -0
  115. package/dist/source/floating/positioning/offset.js +3 -0
  116. package/dist/source/floating/positioning/shift.d.ts +1 -0
  117. package/dist/source/floating/positioning/shift.js +2 -0
  118. package/dist/source/floating/positioning/size.d.ts +12 -0
  119. package/dist/source/floating/positioning/size.js +35 -0
  120. package/dist/source/floating/presence/presence.d.ts +24 -0
  121. package/dist/source/floating/presence/presence.js +73 -0
  122. package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
  123. package/dist/source/floating/scroll-lock/scrollLock.js +151 -0
  124. package/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
  125. package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
  126. package/dist/source/popover/close/PopoverClose.d.ts +11 -0
  127. package/dist/source/popover/close/PopoverClose.jsx +25 -0
  128. package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
  129. package/dist/source/popover/description/PopoverDescription.jsx +26 -0
  130. package/dist/source/popover/index.d.ts +1 -0
  131. package/dist/source/popover/index.js +1 -0
  132. package/dist/source/popover/index.parts.d.ts +7 -0
  133. package/dist/source/popover/index.parts.js +7 -0
  134. package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
  135. package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
  136. package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
  137. package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
  138. package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
  139. package/dist/source/popover/root/PopoverRoot.jsx +42 -0
  140. package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
  141. package/dist/source/popover/root/PopoverRootContext.js +13 -0
  142. package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
  143. package/dist/source/popover/title/PopoverTitle.jsx +26 -0
  144. package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
  145. package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
  146. package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
  147. package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
  148. package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
  149. package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
  150. package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
  151. package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
  152. package/dist/source/tooltip/index.d.ts +1 -0
  153. package/dist/source/tooltip/index.js +1 -0
  154. package/dist/source/tooltip/index.parts.d.ts +5 -0
  155. package/dist/source/tooltip/index.parts.js +5 -0
  156. package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
  157. package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
  158. package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
  159. package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
  160. package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
  161. package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
  162. package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
  163. package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
  164. package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
  165. package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
  166. package/dist/tooltip/arrow/TooltipArrow.js +39 -0
  167. package/dist/tooltip/group/TooltipGroup.js +26 -0
  168. package/dist/tooltip/group/TooltipGroupContext.js +4 -0
  169. package/dist/tooltip/index.js +2 -0
  170. package/dist/tooltip/index.parts.js +6 -0
  171. package/dist/tooltip/popup/TooltipPopup.js +86 -0
  172. package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
  173. package/dist/tooltip/root/TooltipRoot.js +79 -0
  174. package/dist/tooltip/root/TooltipRootContext.js +10 -0
  175. package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
  176. package/package.json +24 -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,21 @@
1
+ import { arrow as arrow$1 } from "@floating-ui/dom";
2
+ // src/floating/positioning/arrow.ts
3
+ /**
4
+ * Places `element`, an absolutely positioned child of the popup, so that it
5
+ * points at the anchor's center: its `left` on the top and bottom sides,
6
+ * its `top` on the left and right. `padding` keeps it that far from the
7
+ * popup's corners. The other offset, out of the popup's edge, is the
8
+ * consumer's CSS, by `data-side`. Goes after `shift`.
9
+ */
10
+ function arrow(options) {
11
+ return {
12
+ ...arrow$1(options),
13
+ write(_popup, data) {
14
+ const { x, y } = data.arrow;
15
+ const style = options.element.style;
16
+ style.left = x == null ? "" : `${x}px`;
17
+ style.top = y == null ? "" : `${y}px`;
18
+ }
19
+ };
20
+ }
21
+ export { arrow };
@@ -0,0 +1,122 @@
1
+ import { createEffect, createSignal, onSettled } from "solid-js";
2
+ import { autoUpdate, computePosition } from "@floating-ui/dom";
3
+ // src/floating/positioning/createPosition.ts
4
+ /**
5
+ * Places `popup` against `anchor` while `open`, with the strategy `fixed` of
6
+ * a popover in the top layer. Pass the options as getters, so a change to
7
+ * one restarts the placement:
8
+ *
9
+ * ```ts
10
+ * const position = createPosition({
11
+ * get anchor() { return trigger; },
12
+ * get popup() { return popup; },
13
+ * get open() { return open(); },
14
+ * get side() { return props.side; },
15
+ * get middleware() { return [offset(8), flip(), shift()]; },
16
+ * });
17
+ * ```
18
+ *
19
+ * Show the popup before placing it: create the effect that calls
20
+ * `showPopover()` before calling this, so that the popup can be measured,
21
+ * and is placed before the browser paints it. Writes on the popup its
22
+ * `inset`, rounded to device pixels, `data-side`, `data-align`,
23
+ * `--anchor-width`, `--anchor-height` and `--transform-origin`, then what
24
+ * each middleware writes. Returns the last placement written. Nothing runs
25
+ * on the server.
26
+ */
27
+ function createPosition(options) {
28
+ const [position, setPosition] = createSignal();
29
+ const [mounted, setMounted] = createSignal(false);
30
+ onSettled(() => {
31
+ setMounted(true);
32
+ });
33
+ let generation = 0;
34
+ let written;
35
+ const update = (run) => {
36
+ const current = ++generation;
37
+ computePosition(run.anchor, run.popup, {
38
+ placement: run.placement,
39
+ strategy: "fixed",
40
+ middleware: [...run.middleware, anchorBox]
41
+ }).then((result) => {
42
+ if (current !== generation) {
43
+ if (written && written.generation > current) written.write();
44
+ return;
45
+ }
46
+ const [side, align = "center"] = result.placement.split("-");
47
+ const x = roundToDevicePixels(result.x);
48
+ const y = roundToDevicePixels(result.y);
49
+ const popup = run.popup;
50
+ const anchor = result.middlewareData.anchor;
51
+ const write = () => {
52
+ popup.style.inset = `${y}px auto auto ${x}px`;
53
+ popup.setAttribute("data-side", side);
54
+ popup.setAttribute("data-align", align);
55
+ popup.style.setProperty("--anchor-width", `${anchor.width}px`);
56
+ popup.style.setProperty("--anchor-height", `${anchor.height}px`);
57
+ popup.style.setProperty("--transform-origin", anchor.origin);
58
+ for (const middleware of run.middleware) middleware.write?.(popup, result.middlewareData);
59
+ };
60
+ write();
61
+ written = {
62
+ generation: current,
63
+ write
64
+ };
65
+ setPosition({
66
+ side,
67
+ align,
68
+ x,
69
+ y,
70
+ middlewareData: result.middlewareData
71
+ });
72
+ });
73
+ };
74
+ createEffect(() => {
75
+ if (!mounted() || !options.open) return void 0;
76
+ const { anchor, popup } = options;
77
+ if (!anchor || !popup) return void 0;
78
+ const side = options.side ?? "bottom";
79
+ const align = options.align ?? "center";
80
+ return {
81
+ anchor,
82
+ popup,
83
+ placement: align === "center" ? side : `${side}-${align}`,
84
+ middleware: options.middleware ?? []
85
+ };
86
+ }, (run) => {
87
+ if (!run) return;
88
+ const stop = autoUpdate(run.anchor, run.popup, () => update(run));
89
+ return () => {
90
+ generation++;
91
+ written = void 0;
92
+ stop();
93
+ };
94
+ });
95
+ return position;
96
+ }
97
+ /**
98
+ * Runs last, after every middleware has moved the popup: the anchor's size,
99
+ * and the point of the popup nearest the anchor's center, on the edge that
100
+ * faces the anchor, for `transform-origin`.
101
+ */
102
+ var anchorBox = {
103
+ name: "anchor",
104
+ fn({ x, y, placement, rects: { reference, floating } }) {
105
+ const side = placement.split("-")[0];
106
+ const clamp = (value, max) => Math.min(Math.max(value, 0), max);
107
+ const centerX = clamp(reference.x + reference.width / 2 - x, floating.width);
108
+ const centerY = clamp(reference.y + reference.height / 2 - y, floating.height);
109
+ const [originX, originY] = side === "top" ? [centerX, floating.height] : side === "bottom" ? [centerX, 0] : side === "left" ? [floating.width, centerY] : [0, centerY];
110
+ return { data: {
111
+ width: reference.width,
112
+ height: reference.height,
113
+ origin: `${originX}px ${originY}px`
114
+ } };
115
+ }
116
+ };
117
+ /** Snaps to the device's pixel grid, so the popup's edges stay sharp. */
118
+ function roundToDevicePixels(value) {
119
+ const ratio = window.devicePixelRatio || 1;
120
+ return Math.round(value * ratio) / ratio;
121
+ }
122
+ export { createPosition };
@@ -0,0 +1 @@
1
+ export { flip } from "@floating-ui/dom";
@@ -0,0 +1,14 @@
1
+ import { hide as hide$1 } from "@floating-ui/dom";
2
+ // src/floating/positioning/hide.ts
3
+ /**
4
+ * Sets `data-anchor-hidden` on the popup while its anchor is scrolled out
5
+ * of view, clipped by a scrolling ancestor, so that the consumer's CSS can
6
+ * hide the popup too. Goes last.
7
+ */
8
+ function hide(options = {}) {
9
+ return {
10
+ ...hide$1(options),
11
+ write: (popup, data) => popup.toggleAttribute("data-anchor-hidden", !!data.hide?.referenceHidden)
12
+ };
13
+ }
14
+ export { hide };
@@ -0,0 +1 @@
1
+ export { offset } from "@floating-ui/dom";
@@ -0,0 +1 @@
1
+ export { shift } from "@floating-ui/dom";
@@ -0,0 +1,39 @@
1
+ import { size as size$1 } from "@floating-ui/dom";
2
+ // src/floating/positioning/size.ts
3
+ function writeAvailable(popup, available) {
4
+ popup.style.setProperty("--available-width", `${available.width}px`);
5
+ popup.style.setProperty("--available-height", `${available.height}px`);
6
+ }
7
+ /**
8
+ * Writes the space between the anchor and the viewport's edges, less
9
+ * `padding`, as `--available-width` and `--available-height`, for the
10
+ * popup's `max-width` and `max-height`. Goes after `flip` and `shift`.
11
+ *
12
+ * It writes them while it measures as well, so that a popup they limit is
13
+ * measured at its limited size in the same placement. If that placement
14
+ * turns out stale, `createPosition` writes the newest one again.
15
+ */
16
+ function size(options = {}) {
17
+ return {
18
+ name: "size",
19
+ options,
20
+ async fn(state) {
21
+ let available;
22
+ return {
23
+ ...await size$1({
24
+ ...options,
25
+ apply({ elements, availableWidth, availableHeight }) {
26
+ available = {
27
+ width: Math.max(0, availableWidth),
28
+ height: Math.max(0, availableHeight)
29
+ };
30
+ writeAvailable(elements.floating, available);
31
+ }
32
+ }).fn(state),
33
+ data: available
34
+ };
35
+ },
36
+ write: (popup, data) => writeAvailable(popup, data.size)
37
+ };
38
+ }
39
+ export { size };
@@ -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 };