@glasshome/ui 1.21.1 → 1.21.2

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 (145) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/use-is-mobile.d.ts +3 -1
  4. package/dist/solid/index.d.ts +9 -9
  5. package/dist/solid/index.js +5431 -5424
  6. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  7. package/package.json +128 -126
  8. package/scripts/check-gallery.ts +142 -142
  9. package/scripts/check-pack.ts +13 -13
  10. package/scripts/check-structural-classes.ts +20 -20
  11. package/scripts/check-tokens.ts +27 -27
  12. package/scripts/check-ui-drift.mjs +103 -103
  13. package/src/index.ts +75 -80
  14. package/src/lib/alert-tones.ts +41 -41
  15. package/src/lib/anchor-placement.ts +21 -21
  16. package/src/lib/button-variants.ts +28 -28
  17. package/src/lib/card-classes.ts +9 -9
  18. package/src/lib/carousel-classes.ts +14 -14
  19. package/src/lib/glass-tone.ts +11 -11
  20. package/src/lib/input-classes.ts +6 -6
  21. package/src/lib/layers.ts +4 -4
  22. package/src/lib/logo-lockup.ts +8 -8
  23. package/src/lib/menu-classes.ts +2 -2
  24. package/src/lib/motion-classes.ts +8 -8
  25. package/src/lib/motion-window.ts +24 -24
  26. package/src/lib/overlay-classes.ts +6 -6
  27. package/src/lib/pill-classes.ts +3 -3
  28. package/src/lib/position-bar-classes.ts +1 -1
  29. package/src/lib/spotlight-geometry.ts +67 -67
  30. package/src/lib/thumb-classes.ts +2 -2
  31. package/src/lib/tier-badge.ts +16 -16
  32. package/src/lib/use-is-mobile.ts +17 -14
  33. package/src/lib/utils.ts +1 -1
  34. package/src/solid/accordion.tsx +41 -41
  35. package/src/solid/alert-dialog.tsx +95 -95
  36. package/src/solid/alert.tsx +88 -88
  37. package/src/solid/area-picker.tsx +204 -204
  38. package/src/solid/aspect-ratio.tsx +13 -13
  39. package/src/solid/avatar.tsx +27 -27
  40. package/src/solid/badge.tsx +49 -49
  41. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  42. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  43. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  44. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  45. package/src/solid/bottom-sheet/index.ts +12 -12
  46. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  47. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  48. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  49. package/src/solid/bottom-sheet/velocity.ts +29 -29
  50. package/src/solid/breadcrumb.tsx +76 -76
  51. package/src/solid/button-group.tsx +46 -46
  52. package/src/solid/button.tsx +19 -19
  53. package/src/solid/card.tsx +67 -67
  54. package/src/solid/carousel.tsx +246 -246
  55. package/src/solid/charts.tsx +253 -253
  56. package/src/solid/checkbox.tsx +51 -51
  57. package/src/solid/collapsible.tsx +22 -22
  58. package/src/solid/color-disc.tsx +213 -213
  59. package/src/solid/color-slider.tsx +81 -81
  60. package/src/solid/color-wheel.tsx +61 -61
  61. package/src/solid/context-menu.tsx +63 -63
  62. package/src/solid/copy-button.tsx +31 -31
  63. package/src/solid/count-pill.tsx +11 -11
  64. package/src/solid/dashboard-preview.tsx +104 -104
  65. package/src/solid/data-table.tsx +228 -228
  66. package/src/solid/dialog-parts.tsx +127 -127
  67. package/src/solid/dialog.tsx +113 -113
  68. package/src/solid/dock-paging.ts +9 -9
  69. package/src/solid/dock.tsx +339 -339
  70. package/src/solid/docked-panel.tsx +35 -35
  71. package/src/solid/dropdown-menu.tsx +77 -77
  72. package/src/solid/empty.tsx +70 -70
  73. package/src/solid/entity-data.ts +38 -38
  74. package/src/solid/entity-selector.tsx +634 -634
  75. package/src/solid/field.tsx +205 -205
  76. package/src/solid/form.tsx +159 -159
  77. package/src/solid/hero-action.tsx +85 -85
  78. package/src/solid/hover-card.tsx +11 -11
  79. package/src/solid/icon-picker.tsx +401 -401
  80. package/src/solid/icon.tsx +101 -78
  81. package/src/solid/image-picker.tsx +416 -414
  82. package/src/solid/index.ts +265 -304
  83. package/src/solid/input-group.tsx +123 -123
  84. package/src/solid/input-otp.tsx +143 -143
  85. package/src/solid/input.tsx +4 -4
  86. package/src/solid/item.tsx +130 -130
  87. package/src/solid/kbd.tsx +20 -20
  88. package/src/solid/label.tsx +12 -12
  89. package/src/solid/list-reorder.ts +122 -122
  90. package/src/solid/logo.tsx +60 -60
  91. package/src/solid/media-copy.ts +21 -21
  92. package/src/solid/media-store.ts +56 -56
  93. package/src/solid/media-tile.tsx +85 -85
  94. package/src/solid/menu-parts.tsx +164 -164
  95. package/src/solid/number-field.tsx +56 -56
  96. package/src/solid/option-card.tsx +164 -164
  97. package/src/solid/ornament.tsx +43 -43
  98. package/src/solid/overlay.tsx +4 -4
  99. package/src/solid/page-header.tsx +75 -75
  100. package/src/solid/pagination.tsx +80 -80
  101. package/src/solid/password-input.tsx +51 -51
  102. package/src/solid/picker-row.tsx +83 -83
  103. package/src/solid/picker-search.tsx +65 -63
  104. package/src/solid/picker-trigger.tsx +59 -57
  105. package/src/solid/popover.tsx +54 -54
  106. package/src/solid/preview-tile.tsx +67 -67
  107. package/src/solid/progress.tsx +21 -21
  108. package/src/solid/radio-group.tsx +51 -51
  109. package/src/solid/resizable.tsx +128 -128
  110. package/src/solid/responsive-dialog.tsx +134 -134
  111. package/src/solid/schema-form.tsx +743 -743
  112. package/src/solid/scope-indicator.tsx +5 -5
  113. package/src/solid/scroll-area.tsx +16 -16
  114. package/src/solid/section-card.tsx +281 -281
  115. package/src/solid/select.tsx +101 -101
  116. package/src/solid/separator.tsx +25 -25
  117. package/src/solid/settings-row.tsx +122 -122
  118. package/src/solid/sheet.tsx +96 -96
  119. package/src/solid/skeleton.tsx +8 -8
  120. package/src/solid/slider.tsx +132 -132
  121. package/src/solid/sliding-indicator.tsx +280 -265
  122. package/src/solid/sonner.tsx +164 -164
  123. package/src/solid/spinner.tsx +12 -12
  124. package/src/solid/spotlight.tsx +140 -140
  125. package/src/solid/step-indicator.tsx +18 -18
  126. package/src/solid/swatch-picker.tsx +38 -38
  127. package/src/solid/switch.tsx +52 -52
  128. package/src/solid/table.tsx +63 -63
  129. package/src/solid/tabs.tsx +93 -93
  130. package/src/solid/textarea.tsx +8 -8
  131. package/src/solid/toggle-group.tsx +83 -83
  132. package/src/solid/toggle.tsx +33 -33
  133. package/src/solid/tooltip.tsx +16 -16
  134. package/src/solid/widget-card.tsx +90 -90
  135. package/src/solid/widget-identity.tsx +99 -99
  136. package/src/solid/widget-trust-badge.tsx +20 -20
  137. package/src/styles/globals.css +316 -319
  138. package/src/styles/theme.css +448 -448
  139. package/src/tokens/hex.ts +29 -29
  140. package/src/tokens/material.ts +75 -75
  141. package/src/tokens/presets.ts +303 -303
  142. package/src/tokens/readability.ts +32 -32
  143. package/src/tokens/theme-colors.ts +95 -95
  144. package/src/tokens/theme-css.ts +22 -22
  145. package/src/tokens/theme-recipe.ts +106 -106
@@ -1,11 +1,11 @@
1
1
  import { hasNoDragAncestor, shouldDrag } from "./arbitration.js";
2
2
  import {
3
- CLOSE_DISTANCE_RATIO,
4
- CLOSE_VELOCITY_PX_PER_MS,
5
- DEAD_ZONE_PX,
6
- EASE,
7
- TRANSITION_MS,
8
- VELOCITY_PROJECTION_MS,
3
+ CLOSE_DISTANCE_RATIO,
4
+ CLOSE_VELOCITY_PX_PER_MS,
5
+ DEAD_ZONE_PX,
6
+ EASE,
7
+ TRANSITION_MS,
8
+ VELOCITY_PROJECTION_MS,
9
9
  } from "./constants.js";
10
10
  import type { SheetState } from "./state-machine.js";
11
11
  import { VelocityTracker } from "./velocity.js";
@@ -13,209 +13,209 @@ import { VelocityTracker } from "./velocity.js";
13
13
  const TRANSITION_CSS = `transform ${TRANSITION_MS}ms ${EASE}`;
14
14
 
15
15
  interface DragHandle {
16
- destroy: () => void;
16
+ destroy: () => void;
17
17
  }
18
18
 
19
19
  interface DragOptions {
20
- el: HTMLDivElement;
21
- getState: () => SheetState;
22
- setState: (s: SheetState) => void;
23
- requestClose: () => void;
20
+ el: HTMLDivElement;
21
+ getState: () => SheetState;
22
+ setState: (s: SheetState) => void;
23
+ requestClose: () => void;
24
24
  }
25
25
 
26
26
  // Rubber-band dampening past the top snap. Vaul recipe.
27
27
  function dampen(v: number): number {
28
- return 8 * (Math.log(v + 1) - 2);
28
+ return 8 * (Math.log(v + 1) - 2);
29
29
  }
30
30
 
31
31
  export function attachDrag(opts: DragOptions): DragHandle {
32
- const { el, getState, setState, requestClose } = opts;
33
- const tracker = new VelocityTracker();
34
-
35
- let pointerId: number | null = null;
36
- let startY = 0;
37
- let startX = 0;
38
- let pointerTarget: Element | null = null;
39
- let dy = 0;
40
- let raf = 0;
41
- let pendingDy: number | null = null;
42
- let movedPastDeadZone = false;
43
- let dragAborted = false;
44
- let height = 0;
45
- let lastTotalDy = 0;
46
-
47
- const isDraggableState = (): boolean => {
48
- const s = getState();
49
- return s === "open" || s === "pressing";
50
- };
51
-
52
- const flushFrame = () => {
53
- raf = 0;
54
- if (pendingDy === null) return;
55
- const value = pendingDy;
56
- pendingDy = null;
57
- const applied = value < 0 ? dampen(-value) * -1 : value;
58
- el.style.transform = `translate3d(0, ${applied}px, 0)`;
59
- };
60
-
61
- const schedule = (newDy: number) => {
62
- pendingDy = newDy;
63
- if (raf === 0) raf = requestAnimationFrame(flushFrame);
64
- };
65
-
66
- const onPointerDown = (e: PointerEvent) => {
67
- if (e.button !== 0 && e.pointerType !== "touch") return;
68
- if (!isDraggableState()) return;
69
- if (pointerId !== null) return; // ignore secondary pointers
70
-
71
- const target = e.target instanceof Element ? e.target : null;
72
- if (hasNoDragAncestor(target, el)) return;
73
- if (target && target.closest("[data-sheet-content]") !== el) return;
74
-
75
- pointerId = e.pointerId;
76
- startY = e.clientY;
77
- startX = e.clientX;
78
- pointerTarget = target;
79
- dy = 0;
80
- lastTotalDy = 0;
81
- movedPastDeadZone = false;
82
- dragAborted = false;
83
- tracker.reset();
84
- tracker.add(0, e.timeStamp);
85
- height = el.offsetHeight || el.getBoundingClientRect().height;
86
- setState("pressing");
87
- };
88
-
89
- const commitDrag = () => {
90
- movedPastDeadZone = true;
91
- if (pointerId !== null) {
92
- try {
93
- el.setPointerCapture(pointerId);
94
- } catch {
95
- /* pointer already released */
96
- }
97
- }
98
- el.style.transition = "none";
99
- el.style.animation = "none";
100
- setState("dragging");
101
- };
102
-
103
- const onPointerMove = (e: PointerEvent) => {
104
- if (e.pointerId !== pointerId) return;
105
- if (dragAborted) return;
106
- const totalDy = e.clientY - startY;
107
- const totalDx = e.clientX - startX;
108
- lastTotalDy = totalDy;
109
-
110
- if (!movedPastDeadZone) {
111
- if (Math.abs(totalDy) + Math.abs(totalDx) < DEAD_ZONE_PX) return;
112
- if (!shouldDrag(pointerTarget, el, totalDy, totalDx)) {
113
- dragAborted = true;
114
- if (getState() === "pressing") setState("open");
115
- return;
116
- }
117
- commitDrag();
118
- }
119
- tracker.add(totalDy, e.timeStamp);
120
- dy = totalDy;
121
- schedule(dy);
122
- };
123
-
124
- const cleanupDrag = () => {
125
- if (raf !== 0) {
126
- cancelAnimationFrame(raf);
127
- raf = 0;
128
- }
129
- pendingDy = null;
130
- pointerId = null;
131
- pointerTarget = null;
132
- dragAborted = false;
133
- };
134
-
135
- const settleClose = () => {
136
- el.style.transition = TRANSITION_CSS;
137
- el.style.animation = "none";
138
- el.style.transform = "translate3d(0, 100%, 0)";
139
- requestClose();
140
- };
141
-
142
- const settleSnap = () => {
143
- setState("snapping");
144
- el.style.transition = TRANSITION_CSS;
145
- el.style.animation = "";
146
- el.style.transform = "translate3d(0, 0, 0)";
147
- };
148
-
149
- const suppressNextClick = () => {
150
- const onClick = (e: MouseEvent) => {
151
- e.preventDefault();
152
- e.stopPropagation();
153
- document.removeEventListener("click", onClick, true);
154
- };
155
- document.addEventListener("click", onClick, true);
156
- setTimeout(() => document.removeEventListener("click", onClick, true), 100);
157
- };
158
-
159
- const safeReleaseCapture = () => {
160
- if (pointerId === null) return;
161
- try {
162
- if (el.hasPointerCapture(pointerId)) el.releasePointerCapture(pointerId);
163
- } catch {
164
- /* pointer already gone */
165
- }
166
- };
167
-
168
- const onPointerUp = (e: PointerEvent) => {
169
- if (e.pointerId !== pointerId) return;
170
- const wasDragging = movedPastDeadZone;
171
- safeReleaseCapture();
172
-
173
- if (!wasDragging) {
174
- cleanupDrag();
175
- setState("open");
176
- return;
177
- }
178
-
179
- const velocity = tracker.compute(e.timeStamp);
180
- const projectedDy = dy + velocity * VELOCITY_PROJECTION_MS;
181
- const shouldClose =
182
- projectedDy > height * CLOSE_DISTANCE_RATIO || velocity > CLOSE_VELOCITY_PX_PER_MS;
183
-
184
- if (Math.abs(lastTotalDy) > DEAD_ZONE_PX) suppressNextClick();
185
-
186
- cleanupDrag();
187
- if (shouldClose) settleClose();
188
- else settleSnap();
189
- };
190
-
191
- const onPointerCancel = (e: PointerEvent) => {
192
- if (e.pointerId !== pointerId) return;
193
- safeReleaseCapture();
194
- const wasDragging = movedPastDeadZone;
195
- cleanupDrag();
196
- if (wasDragging) settleSnap();
197
- else setState("open");
198
- };
199
-
200
- // preventDefault while drag committed — stops browser converting to scroll.
201
- const onTouchMove = (e: TouchEvent) => {
202
- if (movedPastDeadZone) e.preventDefault();
203
- };
204
-
205
- el.addEventListener("pointerdown", onPointerDown);
206
- el.addEventListener("pointermove", onPointerMove);
207
- el.addEventListener("pointerup", onPointerUp);
208
- el.addEventListener("pointercancel", onPointerCancel);
209
- el.addEventListener("touchmove", onTouchMove, { passive: false });
210
-
211
- return {
212
- destroy() {
213
- el.removeEventListener("pointerdown", onPointerDown);
214
- el.removeEventListener("pointermove", onPointerMove);
215
- el.removeEventListener("pointerup", onPointerUp);
216
- el.removeEventListener("pointercancel", onPointerCancel);
217
- el.removeEventListener("touchmove", onTouchMove);
218
- cleanupDrag();
219
- },
220
- };
32
+ const { el, getState, setState, requestClose } = opts;
33
+ const tracker = new VelocityTracker();
34
+
35
+ let pointerId: number | null = null;
36
+ let startY = 0;
37
+ let startX = 0;
38
+ let pointerTarget: Element | null = null;
39
+ let dy = 0;
40
+ let raf = 0;
41
+ let pendingDy: number | null = null;
42
+ let movedPastDeadZone = false;
43
+ let dragAborted = false;
44
+ let height = 0;
45
+ let lastTotalDy = 0;
46
+
47
+ const isDraggableState = (): boolean => {
48
+ const s = getState();
49
+ return s === "open" || s === "pressing";
50
+ };
51
+
52
+ const flushFrame = () => {
53
+ raf = 0;
54
+ if (pendingDy === null) return;
55
+ const value = pendingDy;
56
+ pendingDy = null;
57
+ const applied = value < 0 ? dampen(-value) * -1 : value;
58
+ el.style.transform = `translate3d(0, ${applied}px, 0)`;
59
+ };
60
+
61
+ const schedule = (newDy: number) => {
62
+ pendingDy = newDy;
63
+ if (raf === 0) raf = requestAnimationFrame(flushFrame);
64
+ };
65
+
66
+ const onPointerDown = (e: PointerEvent) => {
67
+ if (e.button !== 0 && e.pointerType !== "touch") return;
68
+ if (!isDraggableState()) return;
69
+ if (pointerId !== null) return; // ignore secondary pointers
70
+
71
+ const target = e.target instanceof Element ? e.target : null;
72
+ if (hasNoDragAncestor(target, el)) return;
73
+ if (target && target.closest("[data-sheet-content]") !== el) return;
74
+
75
+ pointerId = e.pointerId;
76
+ startY = e.clientY;
77
+ startX = e.clientX;
78
+ pointerTarget = target;
79
+ dy = 0;
80
+ lastTotalDy = 0;
81
+ movedPastDeadZone = false;
82
+ dragAborted = false;
83
+ tracker.reset();
84
+ tracker.add(0, e.timeStamp);
85
+ height = el.offsetHeight || el.getBoundingClientRect().height;
86
+ setState("pressing");
87
+ };
88
+
89
+ const commitDrag = () => {
90
+ movedPastDeadZone = true;
91
+ if (pointerId !== null) {
92
+ try {
93
+ el.setPointerCapture(pointerId);
94
+ } catch {
95
+ /* pointer already released */
96
+ }
97
+ }
98
+ el.style.transition = "none";
99
+ el.style.animation = "none";
100
+ setState("dragging");
101
+ };
102
+
103
+ const onPointerMove = (e: PointerEvent) => {
104
+ if (e.pointerId !== pointerId) return;
105
+ if (dragAborted) return;
106
+ const totalDy = e.clientY - startY;
107
+ const totalDx = e.clientX - startX;
108
+ lastTotalDy = totalDy;
109
+
110
+ if (!movedPastDeadZone) {
111
+ if (Math.abs(totalDy) + Math.abs(totalDx) < DEAD_ZONE_PX) return;
112
+ if (!shouldDrag(pointerTarget, el, totalDy, totalDx)) {
113
+ dragAborted = true;
114
+ if (getState() === "pressing") setState("open");
115
+ return;
116
+ }
117
+ commitDrag();
118
+ }
119
+ tracker.add(totalDy, e.timeStamp);
120
+ dy = totalDy;
121
+ schedule(dy);
122
+ };
123
+
124
+ const cleanupDrag = () => {
125
+ if (raf !== 0) {
126
+ cancelAnimationFrame(raf);
127
+ raf = 0;
128
+ }
129
+ pendingDy = null;
130
+ pointerId = null;
131
+ pointerTarget = null;
132
+ dragAborted = false;
133
+ };
134
+
135
+ const settleClose = () => {
136
+ el.style.transition = TRANSITION_CSS;
137
+ el.style.animation = "none";
138
+ el.style.transform = "translate3d(0, 100%, 0)";
139
+ requestClose();
140
+ };
141
+
142
+ const settleSnap = () => {
143
+ setState("snapping");
144
+ el.style.transition = TRANSITION_CSS;
145
+ el.style.animation = "";
146
+ el.style.transform = "translate3d(0, 0, 0)";
147
+ };
148
+
149
+ const suppressNextClick = () => {
150
+ const onClick = (e: MouseEvent) => {
151
+ e.preventDefault();
152
+ e.stopPropagation();
153
+ document.removeEventListener("click", onClick, true);
154
+ };
155
+ document.addEventListener("click", onClick, true);
156
+ setTimeout(() => document.removeEventListener("click", onClick, true), 100);
157
+ };
158
+
159
+ const safeReleaseCapture = () => {
160
+ if (pointerId === null) return;
161
+ try {
162
+ if (el.hasPointerCapture(pointerId)) el.releasePointerCapture(pointerId);
163
+ } catch {
164
+ /* pointer already gone */
165
+ }
166
+ };
167
+
168
+ const onPointerUp = (e: PointerEvent) => {
169
+ if (e.pointerId !== pointerId) return;
170
+ const wasDragging = movedPastDeadZone;
171
+ safeReleaseCapture();
172
+
173
+ if (!wasDragging) {
174
+ cleanupDrag();
175
+ setState("open");
176
+ return;
177
+ }
178
+
179
+ const velocity = tracker.compute(e.timeStamp);
180
+ const projectedDy = dy + velocity * VELOCITY_PROJECTION_MS;
181
+ const shouldClose =
182
+ projectedDy > height * CLOSE_DISTANCE_RATIO || velocity > CLOSE_VELOCITY_PX_PER_MS;
183
+
184
+ if (Math.abs(lastTotalDy) > DEAD_ZONE_PX) suppressNextClick();
185
+
186
+ cleanupDrag();
187
+ if (shouldClose) settleClose();
188
+ else settleSnap();
189
+ };
190
+
191
+ const onPointerCancel = (e: PointerEvent) => {
192
+ if (e.pointerId !== pointerId) return;
193
+ safeReleaseCapture();
194
+ const wasDragging = movedPastDeadZone;
195
+ cleanupDrag();
196
+ if (wasDragging) settleSnap();
197
+ else setState("open");
198
+ };
199
+
200
+ // preventDefault while drag committed — stops browser converting to scroll.
201
+ const onTouchMove = (e: TouchEvent) => {
202
+ if (movedPastDeadZone) e.preventDefault();
203
+ };
204
+
205
+ el.addEventListener("pointerdown", onPointerDown);
206
+ el.addEventListener("pointermove", onPointerMove);
207
+ el.addEventListener("pointerup", onPointerUp);
208
+ el.addEventListener("pointercancel", onPointerCancel);
209
+ el.addEventListener("touchmove", onTouchMove, { passive: false });
210
+
211
+ return {
212
+ destroy() {
213
+ el.removeEventListener("pointerdown", onPointerDown);
214
+ el.removeEventListener("pointermove", onPointerMove);
215
+ el.removeEventListener("pointerup", onPointerUp);
216
+ el.removeEventListener("pointercancel", onPointerCancel);
217
+ el.removeEventListener("touchmove", onTouchMove);
218
+ cleanupDrag();
219
+ },
220
+ };
221
221
  }
@@ -1,56 +1,60 @@
1
+ import { untrack } from "solid-js";
2
+
1
3
  const FOCUSABLE_SELECTOR =
2
- 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
4
+ 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
3
5
 
4
6
  export type InitialFocus = "container" | "first" | ((root: HTMLElement) => HTMLElement | null);
5
7
 
6
8
  interface TrapHandle {
7
- release: () => void;
9
+ release: () => void;
8
10
  }
9
11
 
10
12
  export function trapFocus(root: HTMLElement, initial: InitialFocus = "container"): TrapHandle {
11
- const previouslyFocused = (document.activeElement as HTMLElement | null) ?? null;
12
-
13
- const focusTarget: HTMLElement | null =
14
- initial === "container"
15
- ? root
16
- : initial === "first"
17
- ? (root.querySelector<HTMLElement>(FOCUSABLE_SELECTOR) ?? root)
18
- : initial(root);
19
-
20
- focusTarget?.focus({ preventScroll: true });
21
-
22
- const onKeyDown = (e: KeyboardEvent) => {
23
- if (e.key !== "Tab") return;
24
- const focusable = Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(
25
- (el) => !el.hasAttribute("disabled") && el.offsetParent !== null,
26
- );
27
- if (focusable.length === 0) {
28
- e.preventDefault();
29
- root.focus({ preventScroll: true });
30
- return;
31
- }
32
- const first = focusable[0];
33
- const last = focusable[focusable.length - 1];
34
- const active = document.activeElement as HTMLElement | null;
35
- if (e.shiftKey) {
36
- if (active === first || active === root || !root.contains(active)) {
37
- e.preventDefault();
38
- last?.focus({ preventScroll: true });
39
- }
40
- } else {
41
- if (active === last) {
42
- e.preventDefault();
43
- first?.focus({ preventScroll: true });
44
- }
45
- }
46
- };
47
-
48
- document.addEventListener("keydown", onKeyDown);
49
-
50
- return {
51
- release() {
52
- document.removeEventListener("keydown", onKeyDown);
53
- previouslyFocused?.focus?.({ preventScroll: true });
54
- },
55
- };
13
+ const previouslyFocused = (document.activeElement as HTMLElement | null) ?? null;
14
+
15
+ // focus() runs focus and blur handlers synchronously; a caller's effect must not track their reads.
16
+ untrack(() => {
17
+ const focusTarget: HTMLElement | null =
18
+ initial === "container"
19
+ ? root
20
+ : initial === "first"
21
+ ? (root.querySelector<HTMLElement>(FOCUSABLE_SELECTOR) ?? root)
22
+ : initial(root);
23
+ focusTarget?.focus({ preventScroll: true });
24
+ });
25
+
26
+ const onKeyDown = (e: KeyboardEvent) => {
27
+ if (e.key !== "Tab") return;
28
+ const focusable = Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(
29
+ (el) => !el.hasAttribute("disabled") && el.offsetParent !== null,
30
+ );
31
+ if (focusable.length === 0) {
32
+ e.preventDefault();
33
+ root.focus({ preventScroll: true });
34
+ return;
35
+ }
36
+ const first = focusable[0];
37
+ const last = focusable[focusable.length - 1];
38
+ const active = document.activeElement as HTMLElement | null;
39
+ if (e.shiftKey) {
40
+ if (active === first || active === root || !root.contains(active)) {
41
+ e.preventDefault();
42
+ last?.focus({ preventScroll: true });
43
+ }
44
+ } else {
45
+ if (active === last) {
46
+ e.preventDefault();
47
+ first?.focus({ preventScroll: true });
48
+ }
49
+ }
50
+ };
51
+
52
+ document.addEventListener("keydown", onKeyDown);
53
+
54
+ return {
55
+ release() {
56
+ document.removeEventListener("keydown", onKeyDown);
57
+ untrack(() => previouslyFocused?.focus?.({ preventScroll: true }));
58
+ },
59
+ };
56
60
  }
@@ -1,14 +1,14 @@
1
1
  export {
2
- BottomSheet,
3
- BottomSheetBody,
4
- BottomSheetClose,
5
- BottomSheetContent,
6
- BottomSheetDescription,
7
- BottomSheetFooter,
8
- BottomSheetHandle,
9
- BottomSheetHeader,
10
- BottomSheetOverlay,
11
- BottomSheetPortal,
12
- BottomSheetTitle,
13
- BottomSheetTrigger,
2
+ BottomSheet,
3
+ BottomSheetBody,
4
+ BottomSheetClose,
5
+ BottomSheetContent,
6
+ BottomSheetDescription,
7
+ BottomSheetFooter,
8
+ BottomSheetHandle,
9
+ BottomSheetHeader,
10
+ BottomSheetOverlay,
11
+ BottomSheetPortal,
12
+ BottomSheetTitle,
13
+ BottomSheetTrigger,
14
14
  } from "./bottom-sheet.js";
@@ -1,35 +1,35 @@
1
1
  const KEYBOARD_THRESHOLD_PX = 100;
2
2
 
3
3
  export interface KeyboardWatchHandle {
4
- destroy: () => void;
4
+ destroy: () => void;
5
5
  }
6
6
 
7
7
  export function watchKeyboard(el: HTMLElement): KeyboardWatchHandle {
8
- if (typeof window === "undefined") return { destroy: () => {} };
9
- const vv = window.visualViewport;
10
- if (!vv) return { destroy: () => {} };
8
+ if (typeof window === "undefined") return { destroy: () => {} };
9
+ const vv = window.visualViewport;
10
+ if (!vv) return { destroy: () => {} };
11
11
 
12
- const update = () => {
13
- const offset = Math.max(0, window.innerHeight - vv.height - vv.offsetTop);
14
- if (offset > KEYBOARD_THRESHOLD_PX) {
15
- el.style.setProperty("--bs-keyboard-offset", `${offset}px`);
16
- el.setAttribute("data-keyboard-open", "");
17
- } else {
18
- el.style.removeProperty("--bs-keyboard-offset");
19
- el.removeAttribute("data-keyboard-open");
20
- }
21
- };
12
+ const update = () => {
13
+ const offset = Math.max(0, window.innerHeight - vv.height - vv.offsetTop);
14
+ if (offset > KEYBOARD_THRESHOLD_PX) {
15
+ el.style.setProperty("--bs-keyboard-offset", `${offset}px`);
16
+ el.setAttribute("data-keyboard-open", "");
17
+ } else {
18
+ el.style.removeProperty("--bs-keyboard-offset");
19
+ el.removeAttribute("data-keyboard-open");
20
+ }
21
+ };
22
22
 
23
- vv.addEventListener("resize", update);
24
- vv.addEventListener("scroll", update);
25
- update();
23
+ vv.addEventListener("resize", update);
24
+ vv.addEventListener("scroll", update);
25
+ update();
26
26
 
27
- return {
28
- destroy() {
29
- vv.removeEventListener("resize", update);
30
- vv.removeEventListener("scroll", update);
31
- el.style.removeProperty("--bs-keyboard-offset");
32
- el.removeAttribute("data-keyboard-open");
33
- },
34
- };
27
+ return {
28
+ destroy() {
29
+ vv.removeEventListener("resize", update);
30
+ vv.removeEventListener("scroll", update);
31
+ el.style.removeProperty("--bs-keyboard-offset");
32
+ el.removeAttribute("data-keyboard-open");
33
+ },
34
+ };
35
35
  }