@glasshome/ui 1.41.0 → 1.42.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 (98) hide show
  1. package/SPEC.md +5 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +3 -3
  4. package/dist/lib/anchor-placement.d.ts +30 -0
  5. package/dist/lib/behavior/anchored.d.ts +12 -0
  6. package/dist/lib/behavior/collection.d.ts +24 -0
  7. package/dist/lib/behavior/controllable.d.ts +8 -0
  8. package/dist/lib/behavior/dismiss.d.ts +11 -0
  9. package/dist/lib/behavior/focus-scope.d.ts +18 -0
  10. package/dist/lib/behavior/hide-outside.d.ts +7 -0
  11. package/dist/lib/behavior/layer-stack.d.ts +33 -0
  12. package/dist/lib/behavior/modal-root.d.ts +66 -0
  13. package/dist/lib/behavior/polymorphic.d.ts +6 -0
  14. package/dist/lib/behavior/presence.d.ts +18 -0
  15. package/dist/lib/behavior/solid.d.ts +13 -0
  16. package/dist/lib/motion-classes.d.ts +5 -2
  17. package/dist/lib/overlay-classes.d.ts +3 -0
  18. package/dist/lib/page-cover.d.ts +8 -0
  19. package/dist/lib/shadow-layer.d.ts +8 -6
  20. package/dist/solid/alert-dialog.d.ts +5 -8
  21. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
  22. package/dist/solid/bottom-sheet/constants.d.ts +1 -1
  23. package/dist/solid/dialog-parts.d.ts +51 -14
  24. package/dist/solid/dialog.d.ts +7 -10
  25. package/dist/solid/index.d.ts +4 -1
  26. package/dist/solid/index.js +7797 -7710
  27. package/dist/solid/responsive-dialog.d.ts +2 -0
  28. package/dist/solid/sheet.d.ts +5 -8
  29. package/dist/solid/stale-veil.d.ts +7 -0
  30. package/dist/solid/tabs.d.ts +28 -9
  31. package/dist/solid/toggle-group.d.ts +30 -5
  32. package/dist/solid/tooltip.d.ts +71 -9
  33. package/dist/{utils-CGN4X-2O.js → utils-CxAii-e9.js} +606 -414
  34. package/package.json +4 -2
  35. package/src/index.ts +1 -0
  36. package/src/lib/anchor-placement.ts +68 -2
  37. package/src/lib/behavior/anchored.ts +88 -0
  38. package/src/lib/behavior/collection.ts +181 -0
  39. package/src/lib/behavior/controllable.ts +22 -0
  40. package/src/lib/behavior/dismiss.ts +145 -0
  41. package/src/lib/behavior/focus-scope.ts +202 -0
  42. package/src/lib/behavior/hide-outside.ts +85 -0
  43. package/src/lib/behavior/layer-stack.ts +125 -0
  44. package/src/lib/behavior/modal-root.tsx +446 -0
  45. package/src/lib/behavior/polymorphic.tsx +30 -0
  46. package/src/lib/behavior/presence.ts +89 -0
  47. package/src/lib/behavior/solid.ts +30 -0
  48. package/src/lib/clipboard.ts +3 -2
  49. package/src/lib/motion-classes.ts +27 -2
  50. package/src/lib/overlay-classes.ts +7 -0
  51. package/src/lib/page-cover.ts +47 -0
  52. package/src/lib/shadow-layer.ts +48 -66
  53. package/src/solid/alert-dialog.tsx +36 -85
  54. package/src/solid/area-picker.tsx +2 -1
  55. package/src/solid/badge.tsx +5 -5
  56. package/src/solid/bottom-sheet/bottom-sheet.tsx +72 -128
  57. package/src/solid/bottom-sheet/constants.ts +3 -1
  58. package/src/solid/bottom-sheet/drag-controller.ts +11 -0
  59. package/src/solid/breadcrumb.tsx +4 -4
  60. package/src/solid/button-group.tsx +4 -4
  61. package/src/solid/card.tsx +5 -4
  62. package/src/solid/context-menu.tsx +12 -2
  63. package/src/solid/dialog-parts.tsx +132 -43
  64. package/src/solid/dialog.tsx +44 -76
  65. package/src/solid/dock-edit.tsx +5 -4
  66. package/src/solid/dock.tsx +3 -3
  67. package/src/solid/dropdown-menu.tsx +15 -7
  68. package/src/solid/entity-selector.tsx +2 -1
  69. package/src/solid/form.tsx +4 -3
  70. package/src/solid/hover-card.tsx +7 -2
  71. package/src/solid/icon-picker.tsx +2 -1
  72. package/src/solid/image-picker.tsx +5 -4
  73. package/src/solid/index.ts +4 -1
  74. package/src/solid/input-group.tsx +5 -3
  75. package/src/solid/input-otp.tsx +2 -1
  76. package/src/solid/item.tsx +4 -4
  77. package/src/solid/logo.tsx +5 -4
  78. package/src/solid/picker-row.tsx +5 -4
  79. package/src/solid/picker-search.tsx +2 -1
  80. package/src/solid/popover.tsx +18 -10
  81. package/src/solid/responsive-dialog.tsx +9 -9
  82. package/src/solid/sheet.tsx +47 -79
  83. package/src/solid/spotlight.tsx +23 -11
  84. package/src/solid/stale-veil.tsx +20 -0
  85. package/src/solid/switch.tsx +8 -6
  86. package/src/solid/tabs.tsx +368 -49
  87. package/src/solid/toggle-group.tsx +305 -93
  88. package/src/solid/tooltip.tsx +285 -26
  89. package/src/styles/globals.css +3 -3
  90. package/src/styles/theme.css +5 -0
  91. package/dist/lib/when-animations-settle.d.ts +0 -4
  92. package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
  93. package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
  94. package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
  95. package/src/lib/when-animations-settle.ts +0 -12
  96. package/src/solid/bottom-sheet/focus-trap.ts +0 -63
  97. package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
  98. package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
@@ -1,48 +1,307 @@
1
- import { Tooltip as TooltipPrimitive } from "@kobalte/core/tooltip";
2
- import { usePortalMount } from "./portal-mount.js";
3
- import { type Component, type ComponentProps, createSignal, splitProps } from "solid-js";
4
- import { OVERLAY_MOTION } from "../lib/motion-classes.js";
5
- import { shadowLayer } from "../lib/shadow-layer.js";
1
+ import {
2
+ type Accessor,
3
+ type Component,
4
+ type ComponentProps,
5
+ createContext,
6
+ createSignal,
7
+ createUniqueId,
8
+ type JSX,
9
+ onCleanup,
10
+ Show,
11
+ splitProps,
12
+ untrack,
13
+ useContext,
14
+ type ValidComponent,
15
+ } from "solid-js";
16
+ import { Portal } from "solid-js/web";
17
+ import { createAnchored } from "../lib/behavior/anchored.js";
18
+ import { createControllableSignal } from "../lib/behavior/controllable.js";
19
+ import { createDismiss } from "../lib/behavior/dismiss.js";
20
+ import { registerLayer } from "../lib/behavior/layer-stack.js";
21
+ import { Polymorphic } from "../lib/behavior/polymorphic.js";
22
+ import { createPresence } from "../lib/behavior/presence.js";
23
+ import { effect, merge } from "../lib/behavior/solid.js";
24
+ import type { Align, Side } from "../lib/anchor-placement.js";
25
+ import { MOTION_EXIT_MS, OVERLAY_MOTION } from "../lib/motion-classes.js";
6
26
  import { FLOATING_PANEL } from "../lib/overlay-classes.js";
7
27
  import { cn } from "../lib/utils.js";
28
+ import { usePortalMount } from "./portal-mount.js";
8
29
 
9
- /* Kobalte takes the popper options on the root, not on the content, so the
10
- * gutter that keeps the panel off its trigger has to default here. */
11
- const TooltipRoot: Component<ComponentProps<typeof TooltipPrimitive>> = (props) => (
12
- <TooltipPrimitive gutter={6} {...props} />
13
- );
30
+ type Placement = Side | `${Side}-${Exclude<Align, "center">}`;
14
31
 
15
- /* Object.assign, not a bare wrapper: Kobalte ships Tooltip as a callable
16
- * namespace and Tooltip.Trigger/.Content/.Portal/.Arrow are part of the
17
- * published surface. */
18
- const Tooltip = Object.assign(TooltipRoot, TooltipPrimitive);
32
+ interface TooltipRootProps {
33
+ open?: boolean;
34
+ defaultOpen?: boolean;
35
+ onOpenChange?: (open: boolean) => void;
36
+ placement?: Placement;
37
+ gutter?: number;
38
+ openDelay?: number;
39
+ closeDelay?: number;
40
+ children?: JSX.Element;
41
+ /** @deprecated Ignored. */
42
+ id?: string;
43
+ /** @deprecated Ignored. */
44
+ disabled?: boolean;
45
+ /** @deprecated Ignored. */
46
+ skipDelayDuration?: number;
47
+ /** @deprecated Ignored. */
48
+ triggerOnFocusOnly?: boolean;
49
+ /** @deprecated Ignored. */
50
+ ignoreSafeArea?: boolean;
51
+ /** @deprecated Ignored. */
52
+ forceMount?: boolean;
53
+ /** @deprecated Ignored. */
54
+ getAnchorRect?: (anchor?: HTMLElement) => unknown;
55
+ /** @deprecated Ignored. */
56
+ shift?: number;
57
+ /** @deprecated Ignored. */
58
+ flip?: boolean | string;
59
+ /** @deprecated Ignored. */
60
+ slide?: boolean;
61
+ /** @deprecated Ignored. */
62
+ overlap?: boolean;
63
+ /** @deprecated Ignored. */
64
+ sameWidth?: boolean;
65
+ /** @deprecated Ignored. */
66
+ fitViewport?: boolean;
67
+ /** @deprecated Ignored. */
68
+ hideWhenDetached?: boolean;
69
+ /** @deprecated Ignored. */
70
+ detachedPadding?: number;
71
+ /** @deprecated Ignored. */
72
+ arrowPadding?: number;
73
+ /** @deprecated Ignored. */
74
+ overflowPadding?: number;
75
+ }
19
76
 
20
- const TooltipTrigger = TooltipPrimitive.Trigger;
77
+ interface TooltipContentProps extends ComponentProps<"div"> {
78
+ /** @deprecated Ignored. */
79
+ forceMount?: boolean;
80
+ /** @deprecated Ignored. */
81
+ onEscapeKeyDown?: (event: Event) => void;
82
+ /** @deprecated Ignored. */
83
+ onPointerDownOutside?: (event: Event) => void;
84
+ /** @deprecated Ignored. */
85
+ onFocusOutside?: (event: Event) => void;
86
+ /** @deprecated Ignored. */
87
+ onInteractOutside?: (event: Event) => void;
88
+ }
89
+
90
+ interface TooltipContextValue {
91
+ id: string;
92
+ open: Accessor<boolean>;
93
+ trigger: Accessor<HTMLElement | undefined>;
94
+ setTrigger: (el: HTMLElement | undefined) => void;
95
+ side: Accessor<Side>;
96
+ align: Accessor<Align>;
97
+ gutter: number;
98
+ show: (delayed: boolean) => void;
99
+ hide: (delayed: boolean) => void;
100
+ hold: () => void;
101
+ }
102
+
103
+ const TooltipContext = createContext<TooltipContextValue>();
104
+
105
+ const useTooltip = (): TooltipContextValue => {
106
+ const ctx = useContext(TooltipContext);
107
+ if (!ctx) throw new Error("Tooltip parts render inside a Tooltip");
108
+ return ctx;
109
+ };
110
+
111
+ const OPEN_DELAY_MS = 700;
112
+ const CLOSE_DELAY_MS = 100;
113
+
114
+ const ORIGIN_BY_SIDE =
115
+ "data-[side=bottom]:origin-top data-[side=top]:origin-bottom data-[side=left]:origin-right data-[side=right]:origin-left";
116
+
117
+ const TooltipRoot: Component<TooltipRootProps> = (props) => {
118
+ const [open, setOpen] = createControllableSignal<boolean>({
119
+ value: () => props.open,
120
+ defaultValue: () => props.defaultOpen ?? false,
121
+ onChange: (next) => props.onOpenChange?.(next),
122
+ });
123
+ const [trigger, setTrigger] = createSignal<HTMLElement>();
124
+ const placement = () => (props.placement ?? "bottom").split("-") as [Side, Align?];
125
+ let timer: ReturnType<typeof setTimeout> | undefined;
126
+ const hold = () => clearTimeout(timer);
127
+ const schedule = (next: boolean, delay: number) => {
128
+ hold();
129
+ if (delay <= 0) setOpen(next);
130
+ else timer = setTimeout(() => setOpen(next), delay);
131
+ };
132
+ onCleanup(hold);
133
+
134
+ const value: TooltipContextValue = {
135
+ id: createUniqueId(),
136
+ open,
137
+ trigger,
138
+ setTrigger,
139
+ side: () => placement()[0],
140
+ align: () => placement()[1] ?? "center",
141
+ gutter: untrack(() => props.gutter ?? 6),
142
+ show: (delayed) => schedule(true, delayed ? (props.openDelay ?? OPEN_DELAY_MS) : 0),
143
+ hide: (delayed) => schedule(false, delayed ? (props.closeDelay ?? CLOSE_DELAY_MS) : 0),
144
+ hold,
145
+ };
146
+ return <TooltipContext.Provider value={value}>{props.children}</TooltipContext.Provider>;
147
+ };
148
+
149
+ type TooltipTriggerProps<T extends ValidComponent> = { as?: T } & Omit<ComponentProps<T>, "as">;
150
+
151
+ function TooltipTrigger<T extends ValidComponent = "button">(
152
+ props: TooltipTriggerProps<T>,
153
+ ): JSX.Element {
154
+ const ctx = useTooltip();
155
+ const [local, rest] = splitProps(props as TooltipTriggerProps<ValidComponent>, [
156
+ "as",
157
+ "ref",
158
+ "aria-describedby",
159
+ ]);
160
+ let pressed = false;
161
+
162
+ onCleanup(() => {
163
+ ctx.setTrigger(undefined);
164
+ ctx.hide(false);
165
+ });
166
+
167
+ effect(ctx.trigger, (el) => {
168
+ if (!el) return;
169
+ const mouseLike = (e: PointerEvent) => e.pointerType !== "touch";
170
+ const enter = (e: PointerEvent) => mouseLike(e) && ctx.show(true);
171
+ const leave = (e: PointerEvent) => mouseLike(e) && ctx.hide(true);
172
+ const press = () => {
173
+ pressed = true;
174
+ ctx.hide(false);
175
+ };
176
+ const focus = () => {
177
+ if (!pressed) ctx.show(false);
178
+ };
179
+ const blur = () => {
180
+ pressed = false;
181
+ ctx.hide(false);
182
+ };
183
+ const key = () => {
184
+ pressed = false;
185
+ };
186
+ el.addEventListener("pointerenter", enter);
187
+ el.addEventListener("pointerleave", leave);
188
+ el.addEventListener("pointerdown", press);
189
+ el.addEventListener("focus", focus);
190
+ el.addEventListener("blur", blur);
191
+ el.addEventListener("keydown", key);
192
+ return () => {
193
+ el.removeEventListener("pointerenter", enter);
194
+ el.removeEventListener("pointerleave", leave);
195
+ el.removeEventListener("pointerdown", press);
196
+ el.removeEventListener("focus", focus);
197
+ el.removeEventListener("blur", blur);
198
+ el.removeEventListener("keydown", key);
199
+ };
200
+ });
21
201
 
22
- const TooltipContent: Component<ComponentProps<typeof TooltipPrimitive.Content>> = (props) => {
23
- const [local, others] = splitProps(props, ["class", "ref", "onInteractOutside"]);
24
- const [panel, setPanel] = createSignal<HTMLElement>();
25
- // A tooltip closes as the pointer leaves; inside a shadow root it only must not close on its own presses.
26
- const { onInteractOutside } = shadowLayer({ content: panel, open: () => true, consumer: local });
27
202
  return (
28
- <TooltipPrimitive.Portal mount={usePortalMount()}>
29
- <TooltipPrimitive.Content
30
- ref={(el: HTMLElement) => {
203
+ <Polymorphic
204
+ {...merge({ "data-slot": "tooltip-trigger" }, rest, {
205
+ as: local.as,
206
+ defaultAs: "button" as ValidComponent,
207
+ ref: (el: HTMLElement) => {
208
+ ctx.setTrigger(el);
209
+ if (typeof local.ref === "function") local.ref(el);
210
+ },
211
+ get "aria-describedby"() {
212
+ return (
213
+ [local["aria-describedby"], ctx.open() ? ctx.id : undefined]
214
+ .filter(Boolean)
215
+ .join(" ") || undefined
216
+ );
217
+ },
218
+ })}
219
+ />
220
+ );
221
+ }
222
+
223
+ const TooltipContent: Component<TooltipContentProps> = (props) => {
224
+ const ctx = useTooltip();
225
+ const [local, others] = splitProps(props, [
226
+ "class",
227
+ "ref",
228
+ "forceMount",
229
+ "onEscapeKeyDown",
230
+ "onPointerDownOutside",
231
+ "onFocusOutside",
232
+ "onInteractOutside",
233
+ ]);
234
+ const [panel, setPanel] = createSignal<HTMLElement>();
235
+ const presence = createPresence({
236
+ present: ctx.open,
237
+ element: panel,
238
+ exitMs: MOTION_EXIT_MS.overlay,
239
+ });
240
+
241
+ const layer = registerLayer({
242
+ element: panel,
243
+ open: presence.mounted,
244
+ kind: "tooltip",
245
+ escape: () => true,
246
+ topLayer: "manual",
247
+ });
248
+ createDismiss({ layer, outsidePress: () => false, onDismiss: () => ctx.hide(false) });
249
+ createAnchored({
250
+ anchor: ctx.trigger,
251
+ floating: panel,
252
+ open: ctx.open,
253
+ side: ctx.side,
254
+ align: ctx.align,
255
+ offset: ctx.gutter,
256
+ });
257
+
258
+ const Panel: Component = () => {
259
+ onCleanup(() => setPanel(undefined));
260
+ return (
261
+ <div
262
+ {...others}
263
+ ref={(el) => {
31
264
  setPanel(el);
32
265
  if (typeof local.ref === "function") local.ref(el);
33
266
  }}
34
- onInteractOutside={onInteractOutside}
267
+ id={ctx.id}
268
+ role="tooltip"
35
269
  data-slot="tooltip-content"
270
+ data-expanded={ctx.open() ? "" : undefined}
271
+ data-closed={ctx.open() ? undefined : ""}
272
+ on:pointerenter={ctx.hold}
273
+ on:pointerleave={() => ctx.hide(true)}
36
274
  class={cn(
37
275
  FLOATING_PANEL,
38
276
  OVERLAY_MOTION,
277
+ ORIGIN_BY_SIDE,
39
278
  "overflow-hidden px-3 py-1.5 text-xs",
40
279
  local.class,
41
280
  )}
42
- {...others}
43
281
  />
44
- </TooltipPrimitive.Portal>
282
+ );
283
+ };
284
+
285
+ return (
286
+ <Show when={presence.mounted()}>
287
+ <Portal mount={usePortalMount()}>
288
+ <Panel />
289
+ </Portal>
290
+ </Show>
45
291
  );
46
292
  };
47
293
 
294
+ /** @deprecated TooltipContent portals itself; this renders its children in place. */
295
+ const TooltipPortal: Component<{ children?: JSX.Element }> = (props) => <>{props.children}</>;
296
+
297
+ /** @deprecated Renders nothing. */
298
+ const TooltipArrow: Component = () => null;
299
+
300
+ const Tooltip = Object.assign(TooltipRoot, {
301
+ Trigger: TooltipTrigger,
302
+ Content: TooltipContent,
303
+ Portal: TooltipPortal,
304
+ Arrow: TooltipArrow,
305
+ });
306
+
48
307
  export { Tooltip, TooltipContent, TooltipTrigger };
@@ -671,11 +671,11 @@
671
671
  animation: none;
672
672
  }
673
673
  }
674
- /* Ambient loops under a modal's scrim re-blur the page every frame; each selector ends in a class, as a trailing * restyles the whole document. */
675
- :root[data-page-covered] .glass-edge-orbit {
674
+ /* Ambient loops under an open modal re-blur its glass every frame (page-cover.ts); each selector ends in a class or attribute, as a trailing * restyles the whole page. */
675
+ [data-page][data-covered] .glass-edge-orbit {
676
676
  --_orbit-play: paused;
677
677
  }
678
- :root[data-page-covered] :is(.animate-spin-slow, .animate-float) {
678
+ [data-page][data-covered] :is(.animate-spin-slow, .animate-float) {
679
679
  animation-play-state: paused;
680
680
  }
681
681
 
@@ -334,6 +334,11 @@ html[data-motion="live"] [data-motion-reader] {
334
334
  --motion-play: running;
335
335
  }
336
336
 
337
+ [data-page][data-covered] [data-motion-reader] {
338
+ --motion-ambient: 0;
339
+ --motion-play: paused;
340
+ }
341
+
337
342
  .dark {
338
343
  --background: oklch(0.12 0.01 250);
339
344
  --foreground: oklch(0.9551 0 0);
@@ -1,4 +0,0 @@
1
- export declare function whenAnimationsSettle(el: Element, options?: {
2
- subtree?: boolean;
3
- filter?: (animation: Animation) => boolean;
4
- }): Promise<void>;
@@ -1,6 +0,0 @@
1
- export type InitialFocus = "container" | "first" | ((root: HTMLElement) => HTMLElement | null);
2
- interface TrapHandle {
3
- release: () => void;
4
- }
5
- export declare function trapFocus(root: HTMLElement, initial?: InitialFocus): TrapHandle;
6
- export {};
@@ -1,2 +0,0 @@
1
- export declare function acquireScrollLock(): void;
2
- export declare function releaseScrollLock(): void;
@@ -1 +0,0 @@
1
- export declare const isSheetMotion: (a: Animation) => boolean;
@@ -1,12 +0,0 @@
1
- export async function whenAnimationsSettle(
2
- el: Element,
3
- options: { subtree?: boolean; filter?: (animation: Animation) => boolean } = {},
4
- ): Promise<void> {
5
- // One microtask so styles written in the same tick start their animations first.
6
- await Promise.resolve();
7
- if (typeof el.getAnimations !== "function") return;
8
- const all = el.getAnimations({ subtree: options.subtree ?? false });
9
- const running = options.filter ? all.filter(options.filter) : all;
10
- if (running.length === 0) return;
11
- await Promise.allSettled(running.map((animation) => animation.finished));
12
- }
@@ -1,63 +0,0 @@
1
- import { untrack } from "solid-js";
2
-
3
- const FOCUSABLE_SELECTOR =
4
- 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
5
-
6
- export type InitialFocus = "container" | "first" | ((root: HTMLElement) => HTMLElement | null);
7
-
8
- interface TrapHandle {
9
- release: () => void;
10
- }
11
-
12
- export function trapFocus(root: HTMLElement, initial: InitialFocus = "container"): TrapHandle {
13
- // Inside a shadow root the document's active element is the root's host; the root knows which node has focus.
14
- const scope = root.getRootNode() as Document | ShadowRoot;
15
- const previouslyFocused = (scope.activeElement as HTMLElement | null) ?? null;
16
-
17
- // focus() runs focus and blur handlers synchronously; a caller's effect must not track their reads.
18
- untrack(() => {
19
- const focusTarget: HTMLElement | null =
20
- initial === "container"
21
- ? root
22
- : initial === "first"
23
- ? (root.querySelector<HTMLElement>(FOCUSABLE_SELECTOR) ?? root)
24
- : initial(root);
25
- focusTarget?.focus({ preventScroll: true });
26
- });
27
-
28
- const onKeyDown = (event: Event) => {
29
- const e = event as KeyboardEvent;
30
- if (e.key !== "Tab") return;
31
- const focusable = Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(
32
- (el) => !el.hasAttribute("disabled") && el.offsetParent !== null,
33
- );
34
- if (focusable.length === 0) {
35
- e.preventDefault();
36
- root.focus({ preventScroll: true });
37
- return;
38
- }
39
- const first = focusable[0];
40
- const last = focusable[focusable.length - 1];
41
- const active = scope.activeElement as HTMLElement | null;
42
- if (e.shiftKey) {
43
- if (active === first || active === root || !root.contains(active)) {
44
- e.preventDefault();
45
- last?.focus({ preventScroll: true });
46
- }
47
- } else {
48
- if (active === last) {
49
- e.preventDefault();
50
- first?.focus({ preventScroll: true });
51
- }
52
- }
53
- };
54
-
55
- scope.addEventListener("keydown", onKeyDown);
56
-
57
- return {
58
- release() {
59
- scope.removeEventListener("keydown", onKeyDown);
60
- untrack(() => previouslyFocused?.focus?.({ preventScroll: true }));
61
- },
62
- };
63
- }
@@ -1,66 +0,0 @@
1
- let refcount = 0;
2
- let savedScrollY = 0;
3
- let savedBodyStyles: {
4
- position: string;
5
- top: string;
6
- left: string;
7
- right: string;
8
- width: string;
9
- overflow: string;
10
- } | null = null;
11
-
12
- function isIOS(): boolean {
13
- if (typeof navigator === "undefined") return false;
14
- const ua = navigator.userAgent;
15
- return /iP(ad|hone|od)/.test(ua) || (ua.includes("Mac") && "ontouchend" in document);
16
- }
17
-
18
- export function acquireScrollLock(): void {
19
- refcount++;
20
- if (refcount > 1) return;
21
- if (typeof document === "undefined") return;
22
-
23
- document.documentElement.setAttribute("data-page-covered", "");
24
- const body = document.body;
25
- savedBodyStyles = {
26
- position: body.style.position,
27
- top: body.style.top,
28
- left: body.style.left,
29
- right: body.style.right,
30
- width: body.style.width,
31
- overflow: body.style.overflow,
32
- };
33
-
34
- if (isIOS()) {
35
- savedScrollY = window.scrollY;
36
- body.style.position = "fixed";
37
- body.style.top = `-${savedScrollY}px`;
38
- body.style.left = "0";
39
- body.style.right = "0";
40
- body.style.width = "100%";
41
- } else {
42
- body.style.overflow = "hidden";
43
- }
44
- }
45
-
46
- export function releaseScrollLock(): void {
47
- refcount = Math.max(0, refcount - 1);
48
- if (refcount > 0) return;
49
- if (typeof document === "undefined" || !savedBodyStyles) return;
50
-
51
- document.documentElement.removeAttribute("data-page-covered");
52
- const body = document.body;
53
- const wasIOS = body.style.position === "fixed";
54
-
55
- body.style.position = savedBodyStyles.position;
56
- body.style.top = savedBodyStyles.top;
57
- body.style.left = savedBodyStyles.left;
58
- body.style.right = savedBodyStyles.right;
59
- body.style.width = savedBodyStyles.width;
60
- body.style.overflow = savedBodyStyles.overflow;
61
- savedBodyStyles = null;
62
-
63
- if (wasIOS) {
64
- window.scrollTo(0, savedScrollY);
65
- }
66
- }
@@ -1,4 +0,0 @@
1
- export const isSheetMotion = (a: Animation) =>
2
- "animationName" in a
3
- ? a.animationName === "bs-slide-up" || a.animationName === "bs-slide-down"
4
- : "transitionProperty" in a && a.transitionProperty === "transform";