@glasshome/ui 1.21.0 → 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 (154) 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/alert-dialog.d.ts +7 -1
  5. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +7 -1
  6. package/dist/solid/dialog-parts.d.ts +3 -2
  7. package/dist/solid/dialog.d.ts +7 -1
  8. package/dist/solid/docked-panel.d.ts +7 -1
  9. package/dist/solid/index.d.ts +9 -9
  10. package/dist/solid/index.js +5456 -5447
  11. package/dist/solid/media-store.d.ts +4 -1
  12. package/dist/solid/option-card.d.ts +4 -1
  13. package/dist/solid/responsive-dialog.d.ts +7 -1
  14. package/dist/solid/sheet.d.ts +7 -1
  15. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  16. package/package.json +128 -126
  17. package/scripts/check-gallery.ts +142 -142
  18. package/scripts/check-pack.ts +13 -13
  19. package/scripts/check-structural-classes.ts +20 -20
  20. package/scripts/check-tokens.ts +27 -27
  21. package/scripts/check-ui-drift.mjs +103 -103
  22. package/src/index.ts +75 -80
  23. package/src/lib/alert-tones.ts +41 -41
  24. package/src/lib/anchor-placement.ts +21 -21
  25. package/src/lib/button-variants.ts +28 -28
  26. package/src/lib/card-classes.ts +9 -9
  27. package/src/lib/carousel-classes.ts +14 -14
  28. package/src/lib/glass-tone.ts +11 -11
  29. package/src/lib/input-classes.ts +6 -6
  30. package/src/lib/layers.ts +4 -4
  31. package/src/lib/logo-lockup.ts +8 -8
  32. package/src/lib/menu-classes.ts +2 -2
  33. package/src/lib/motion-classes.ts +8 -8
  34. package/src/lib/motion-window.ts +24 -24
  35. package/src/lib/overlay-classes.ts +6 -6
  36. package/src/lib/pill-classes.ts +3 -3
  37. package/src/lib/position-bar-classes.ts +1 -1
  38. package/src/lib/spotlight-geometry.ts +67 -67
  39. package/src/lib/thumb-classes.ts +2 -2
  40. package/src/lib/tier-badge.ts +16 -16
  41. package/src/lib/use-is-mobile.ts +17 -14
  42. package/src/lib/utils.ts +1 -1
  43. package/src/solid/accordion.tsx +41 -41
  44. package/src/solid/alert-dialog.tsx +95 -95
  45. package/src/solid/alert.tsx +88 -88
  46. package/src/solid/area-picker.tsx +204 -204
  47. package/src/solid/aspect-ratio.tsx +13 -13
  48. package/src/solid/avatar.tsx +27 -27
  49. package/src/solid/badge.tsx +49 -49
  50. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  51. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  52. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  53. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  54. package/src/solid/bottom-sheet/index.ts +12 -12
  55. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  56. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  57. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  58. package/src/solid/bottom-sheet/velocity.ts +29 -29
  59. package/src/solid/breadcrumb.tsx +76 -76
  60. package/src/solid/button-group.tsx +46 -46
  61. package/src/solid/button.tsx +19 -19
  62. package/src/solid/card.tsx +67 -67
  63. package/src/solid/carousel.tsx +246 -246
  64. package/src/solid/charts.tsx +253 -253
  65. package/src/solid/checkbox.tsx +51 -51
  66. package/src/solid/collapsible.tsx +22 -22
  67. package/src/solid/color-disc.tsx +213 -213
  68. package/src/solid/color-slider.tsx +81 -81
  69. package/src/solid/color-wheel.tsx +61 -61
  70. package/src/solid/context-menu.tsx +63 -63
  71. package/src/solid/copy-button.tsx +31 -31
  72. package/src/solid/count-pill.tsx +11 -11
  73. package/src/solid/dashboard-preview.tsx +104 -104
  74. package/src/solid/data-table.tsx +228 -228
  75. package/src/solid/dialog-parts.tsx +129 -129
  76. package/src/solid/dialog.tsx +113 -113
  77. package/src/solid/dock-paging.ts +9 -9
  78. package/src/solid/dock.tsx +339 -338
  79. package/src/solid/docked-panel.tsx +35 -35
  80. package/src/solid/dropdown-menu.tsx +77 -77
  81. package/src/solid/empty.tsx +70 -70
  82. package/src/solid/entity-data.ts +38 -38
  83. package/src/solid/entity-selector.tsx +634 -634
  84. package/src/solid/field.tsx +205 -205
  85. package/src/solid/form.tsx +159 -159
  86. package/src/solid/hero-action.tsx +85 -85
  87. package/src/solid/hover-card.tsx +11 -11
  88. package/src/solid/icon-picker.tsx +401 -401
  89. package/src/solid/icon.tsx +101 -78
  90. package/src/solid/image-picker.tsx +416 -414
  91. package/src/solid/index.ts +265 -304
  92. package/src/solid/input-group.tsx +123 -123
  93. package/src/solid/input-otp.tsx +143 -143
  94. package/src/solid/input.tsx +4 -4
  95. package/src/solid/item.tsx +130 -130
  96. package/src/solid/kbd.tsx +20 -20
  97. package/src/solid/label.tsx +12 -12
  98. package/src/solid/list-reorder.ts +122 -122
  99. package/src/solid/logo.tsx +60 -60
  100. package/src/solid/media-copy.ts +21 -21
  101. package/src/solid/media-store.ts +60 -57
  102. package/src/solid/media-tile.tsx +85 -85
  103. package/src/solid/menu-parts.tsx +164 -164
  104. package/src/solid/number-field.tsx +56 -56
  105. package/src/solid/option-card.tsx +168 -165
  106. package/src/solid/ornament.tsx +43 -43
  107. package/src/solid/overlay.tsx +4 -4
  108. package/src/solid/page-header.tsx +75 -75
  109. package/src/solid/pagination.tsx +80 -80
  110. package/src/solid/password-input.tsx +51 -51
  111. package/src/solid/picker-row.tsx +83 -83
  112. package/src/solid/picker-search.tsx +65 -63
  113. package/src/solid/picker-trigger.tsx +59 -57
  114. package/src/solid/popover.tsx +54 -54
  115. package/src/solid/preview-tile.tsx +67 -67
  116. package/src/solid/progress.tsx +21 -21
  117. package/src/solid/radio-group.tsx +51 -51
  118. package/src/solid/resizable.tsx +128 -128
  119. package/src/solid/responsive-dialog.tsx +134 -134
  120. package/src/solid/schema-form.tsx +746 -739
  121. package/src/solid/scope-indicator.tsx +5 -5
  122. package/src/solid/scroll-area.tsx +16 -16
  123. package/src/solid/section-card.tsx +281 -281
  124. package/src/solid/select.tsx +101 -101
  125. package/src/solid/separator.tsx +25 -25
  126. package/src/solid/settings-row.tsx +122 -122
  127. package/src/solid/sheet.tsx +96 -96
  128. package/src/solid/skeleton.tsx +8 -8
  129. package/src/solid/slider.tsx +132 -132
  130. package/src/solid/sliding-indicator.tsx +280 -265
  131. package/src/solid/sonner.tsx +164 -164
  132. package/src/solid/spinner.tsx +12 -12
  133. package/src/solid/spotlight.tsx +140 -140
  134. package/src/solid/step-indicator.tsx +18 -18
  135. package/src/solid/swatch-picker.tsx +38 -38
  136. package/src/solid/switch.tsx +52 -52
  137. package/src/solid/table.tsx +63 -63
  138. package/src/solid/tabs.tsx +93 -93
  139. package/src/solid/textarea.tsx +8 -8
  140. package/src/solid/toggle-group.tsx +83 -83
  141. package/src/solid/toggle.tsx +33 -33
  142. package/src/solid/tooltip.tsx +16 -16
  143. package/src/solid/widget-card.tsx +90 -90
  144. package/src/solid/widget-identity.tsx +99 -99
  145. package/src/solid/widget-trust-badge.tsx +20 -20
  146. package/src/styles/globals.css +316 -319
  147. package/src/styles/theme.css +448 -448
  148. package/src/tokens/hex.ts +29 -29
  149. package/src/tokens/material.ts +75 -75
  150. package/src/tokens/presets.ts +303 -303
  151. package/src/tokens/readability.ts +32 -32
  152. package/src/tokens/theme-colors.ts +95 -95
  153. package/src/tokens/theme-css.ts +22 -22
  154. package/src/tokens/theme-recipe.ts +106 -106
@@ -1,15 +1,16 @@
1
1
  import {
2
- type Component,
3
- type ComponentProps,
4
- createEffect,
5
- createMemo,
6
- createSignal,
7
- Index,
8
- type JSX,
9
- onCleanup,
10
- onMount,
11
- Show,
12
- splitProps,
2
+ type Component,
3
+ type ComponentProps,
4
+ createEffect,
5
+ createMemo,
6
+ createSignal,
7
+ Index,
8
+ type JSX,
9
+ on,
10
+ onCleanup,
11
+ onMount,
12
+ Show,
13
+ splitProps,
13
14
  } from "solid-js";
14
15
  import { Dynamic } from "solid-js/web";
15
16
  import { CARD_SURFACE } from "../lib/card-classes.js";
@@ -21,357 +22,357 @@ import { SlidingIndicator } from "./sliding-indicator.js";
21
22
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
22
23
 
23
24
  interface DockItem {
24
- id: string;
25
- icon: Component<{ class?: string }> | JSX.Element;
26
- label: string;
27
- onClick?: () => void;
28
- isActive?: boolean;
29
- /** Optional count badge on the item (e.g. pending updates). */
30
- badge?: number;
31
- /** Something dragged is held over this item and will land here on release. */
32
- isDropTarget?: boolean;
25
+ id: string;
26
+ icon: Component<{ class?: string }> | JSX.Element;
27
+ label: string;
28
+ onClick?: () => void;
29
+ isActive?: boolean;
30
+ /** Optional count badge on the item (e.g. pending updates). */
31
+ badge?: number;
32
+ /** Something dragged is held over this item and will land here on release. */
33
+ isDropTarget?: boolean;
33
34
  }
34
35
 
35
36
  interface DockProps extends ComponentProps<"div"> {
36
- items: DockItem[];
37
- dockMode?: "floating" | "docked";
38
- /** Where a hold started, relative to the surface; `fired` once it has triggered. */
39
- hold?: { x: number; y: number; fired: boolean } | null;
40
- /** A rim light that orbits for as long as a mode is on. */
41
- glow?: boolean;
42
- /** Where a drag from outside the dock is pointing, in client coordinates. */
43
- dragPoint?: { x: number; y: number } | null;
37
+ items: DockItem[];
38
+ dockMode?: "floating" | "docked";
39
+ /** Where a hold started, relative to the surface; `fired` once it has triggered. */
40
+ hold?: { x: number; y: number; fired: boolean } | null;
41
+ /** A rim light that orbits for as long as a mode is on. */
42
+ glow?: boolean;
43
+ /** Where a drag from outside the dock is pointing, in client coordinates. */
44
+ dragPoint?: { x: number; y: number } | null;
44
45
  }
45
46
 
46
47
  interface DockIconButtonProps extends ComponentProps<"button"> {
47
- icon: Component<{ class?: string }> | JSX.Element;
48
- label: string;
49
- isActive?: boolean;
50
- /** Sits on the sliding pill: the active item, or the one a drag would land on. */
51
- lit?: boolean;
52
- badge?: number;
48
+ icon: Component<{ class?: string }> | JSX.Element;
49
+ label: string;
50
+ isActive?: boolean;
51
+ /** Sits on the sliding pill: the active item, or the one a drag would land on. */
52
+ lit?: boolean;
53
+ badge?: number;
53
54
  }
54
55
 
55
56
  const DockIconButton: Component<DockIconButtonProps> = (props) => {
56
- // Kobalte's button root narrows `type`; Solid's ComponentProps<"button"> also
57
- // admits "menu", so it is split off rather than spread.
58
- const [local, rest] = splitProps(props, [
59
- "icon",
60
- "label",
61
- "class",
62
- "isActive",
63
- "badge",
64
- "type",
65
- "lit",
66
- ]);
67
- const isElement = () => typeof local.icon !== "function";
57
+ // Kobalte's button root narrows `type`; Solid's ComponentProps<"button"> also
58
+ // admits "menu", so it is split off rather than spread.
59
+ const [local, rest] = splitProps(props, [
60
+ "icon",
61
+ "label",
62
+ "class",
63
+ "isActive",
64
+ "badge",
65
+ "type",
66
+ "lit",
67
+ ]);
68
+ const isElement = () => typeof local.icon !== "function";
68
69
 
69
- return (
70
- <Tooltip openDelay={150} placement="top">
71
- <TooltipTrigger
72
- type="button"
73
- data-slot="dock-item"
74
- class={cn(
75
- "group relative flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
76
- PRESS_DIP,
77
- local.class,
78
- )}
79
- aria-label={local.label}
80
- aria-current={local.isActive ? "page" : undefined}
81
- {...rest}
82
- >
83
- <div
84
- data-slot="dock-item-icon"
85
- class={cn(
86
- "flex items-center justify-center transition-colors duration-(--duration-state)",
87
- local.lit ? "text-primary" : "text-foreground group-hover:text-primary/80",
88
- )}
89
- >
90
- {isElement() ? (
91
- (local.icon as JSX.Element)
92
- ) : (
93
- <Dynamic
94
- component={local.icon as Component<{ class?: string }>}
95
- class="h-5 w-5 sm:h-6 sm:w-6"
96
- />
97
- )}
98
- </div>
99
- <Show when={typeof local.badge === "number" && local.badge > 0}>
100
- {/* Inside the item box: an overhanging badge inflates the bar's
101
- * scrollWidth and trips the overflow-to-scroll check below. */}
102
- <Badge
103
- role="status"
104
- tone="var(--primary)"
105
- class="absolute top-0 right-0 h-4 min-w-4 justify-center px-1 pt-0.5 pb-0 font-medium font-mono text-[9px] tabular-nums leading-none"
106
- aria-label={`${local.badge} pending`}
107
- >
108
- {local.badge != null && local.badge > 9 ? "9+" : local.badge}
109
- </Badge>
110
- </Show>
111
- </TooltipTrigger>
112
- <TooltipContent class="hidden sm:block">{local.label}</TooltipContent>
113
- </Tooltip>
114
- );
70
+ return (
71
+ <Tooltip openDelay={150} placement="top">
72
+ <TooltipTrigger
73
+ type="button"
74
+ data-slot="dock-item"
75
+ class={cn(
76
+ "group relative flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
77
+ PRESS_DIP,
78
+ local.class,
79
+ )}
80
+ aria-label={local.label}
81
+ aria-current={local.isActive ? "page" : undefined}
82
+ {...rest}
83
+ >
84
+ <div
85
+ data-slot="dock-item-icon"
86
+ class={cn(
87
+ "flex items-center justify-center transition-colors duration-(--duration-state)",
88
+ local.lit ? "text-primary" : "text-foreground group-hover:text-primary/80",
89
+ )}
90
+ >
91
+ {isElement() ? (
92
+ (local.icon as JSX.Element)
93
+ ) : (
94
+ <Dynamic
95
+ component={local.icon as Component<{ class?: string }>}
96
+ class="h-5 w-5 sm:h-6 sm:w-6"
97
+ />
98
+ )}
99
+ </div>
100
+ <Show when={typeof local.badge === "number" && local.badge > 0}>
101
+ {/* Inside the item box: an overhanging badge inflates the bar's
102
+ * scrollWidth and trips the overflow-to-scroll check below. */}
103
+ <Badge
104
+ role="status"
105
+ tone="var(--primary)"
106
+ class="absolute top-0 right-0 h-4 min-w-4 justify-center px-1 pt-0.5 pb-0 font-mono text-[9px] leading-none font-medium tabular-nums"
107
+ aria-label={`${local.badge} pending`}
108
+ >
109
+ {local.badge != null && local.badge > 9 ? "9+" : local.badge}
110
+ </Badge>
111
+ </Show>
112
+ </TooltipTrigger>
113
+ <TooltipContent class="hidden sm:block">{local.label}</TooltipContent>
114
+ </Tooltip>
115
+ );
115
116
  };
116
117
 
117
118
  const Dock: Component<DockProps> = (props) => {
118
- const [local, rest] = splitProps(props, [
119
- "items",
120
- "class",
121
- "dockMode",
122
- "hold",
123
- "glow",
124
- "dragPoint",
125
- ]);
126
- // The drain plays where the fill grew, so the point outlives the hold.
127
- const [holdPoint, setHoldPoint] = createSignal({ x: 0, y: 0, r: 0 });
128
- let surfaceRef: HTMLDivElement | undefined;
129
- createEffect(() => {
130
- const h = local.hold;
131
- if (!h) return;
132
- const w = surfaceRef?.clientWidth ?? 0;
133
- const ht = surfaceRef?.clientHeight ?? 0;
134
- // Reaches the farthest corner exactly at full scale, so the fill ends as the hold does.
135
- setHoldPoint({
136
- x: h.x,
137
- y: h.y,
138
- r: Math.hypot(Math.max(h.x, w - h.x), Math.max(h.y, ht - h.y)),
139
- });
140
- });
141
- const dockMode = () => local.dockMode ?? "floating";
142
- let containerRef!: HTMLDivElement;
143
- const [needsScroll, setNeedsScroll] = createSignal(false);
144
- const [pages, setPages] = createSignal(1);
145
- const [page, setPage] = createSignal(0);
146
- const [viewportWidth, setViewportWidth] = createSignal(0);
119
+ const [local, rest] = splitProps(props, [
120
+ "items",
121
+ "class",
122
+ "dockMode",
123
+ "hold",
124
+ "glow",
125
+ "dragPoint",
126
+ ]);
127
+ // The drain plays where the fill grew, so the point outlives the hold.
128
+ const [holdPoint, setHoldPoint] = createSignal({ x: 0, y: 0, r: 0 });
129
+ let surfaceRef: HTMLDivElement | undefined;
130
+ createEffect(() => {
131
+ const h = local.hold;
132
+ if (!h) return;
133
+ const w = surfaceRef?.clientWidth ?? 0;
134
+ const ht = surfaceRef?.clientHeight ?? 0;
135
+ // Reaches the farthest corner exactly at full scale, so the fill ends as the hold does.
136
+ setHoldPoint({
137
+ x: h.x,
138
+ y: h.y,
139
+ r: Math.hypot(Math.max(h.x, w - h.x), Math.max(h.y, ht - h.y)),
140
+ });
141
+ });
142
+ const dockMode = () => local.dockMode ?? "floating";
143
+ let containerRef!: HTMLDivElement;
144
+ const [needsScroll, setNeedsScroll] = createSignal(false);
145
+ const [pages, setPages] = createSignal(1);
146
+ const [page, setPage] = createSignal(0);
147
+ const [viewportWidth, setViewportWidth] = createSignal(0);
147
148
 
148
- // The moving background: the shared SlidingIndicator tracks the active item.
149
- // A memo: the items list is rebuilt on every hover change, and only a new active item may scroll the strip.
150
- const activeIndex = createMemo(() => {
151
- const i = local.items.findIndex((it) => it.isActive);
152
- return i < 0 ? null : i;
153
- });
154
- // A drag borrows the pill: it slides to where the drop would land and back when the drag leaves.
155
- const pillIndex = createMemo(() => {
156
- const i = local.items.findIndex((it) => it.isDropTarget);
157
- return i < 0 ? activeIndex() : i;
158
- });
149
+ // The moving background: the shared SlidingIndicator tracks the active item.
150
+ // A memo: the items list is rebuilt on every hover change, and only a new active item may scroll the strip.
151
+ const activeIndex = createMemo(() => {
152
+ const i = local.items.findIndex((it) => it.isActive);
153
+ return i < 0 ? null : i;
154
+ });
155
+ // A drag borrows the pill: it slides to where the drop would land and back when the drag leaves.
156
+ const pillIndex = createMemo(() => {
157
+ const i = local.items.findIndex((it) => it.isDropTarget);
158
+ return i < 0 ? activeIndex() : i;
159
+ });
159
160
 
160
- const gapWidth = () =>
161
- containerRef ? Number.parseFloat(getComputedStyle(containerRef).columnGap) || 0 : 0;
162
- const itemWidth = () =>
163
- containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect().width ?? 0;
161
+ const gapWidth = () =>
162
+ containerRef ? Number.parseFloat(getComputedStyle(containerRef).columnGap) || 0 : 0;
163
+ const itemWidth = () =>
164
+ containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect().width ?? 0;
164
165
 
165
- const padX = (el: Element) => {
166
- const style = getComputedStyle(el);
167
- return (
168
- (Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0)
169
- );
170
- };
166
+ const padX = (el: Element) => {
167
+ const style = getComputedStyle(el);
168
+ return (
169
+ (Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0)
170
+ );
171
+ };
171
172
 
172
- // The width the app gave the dock. Never the surface: it shrink-wraps this strip,
173
- // so measuring it asks the strip how wide the strip is.
174
- const availableWidth = () => {
175
- const box = containerRef?.closest<HTMLElement>('[data-slot="dock"]');
176
- if (!box || !surfaceRef) return 0;
177
- return box.clientWidth - padX(box) - padX(surfaceRef);
178
- };
173
+ // The width the app gave the dock. Never the surface: it shrink-wraps this strip,
174
+ // so measuring it asks the strip how wide the strip is.
175
+ const availableWidth = () => {
176
+ const box = containerRef?.closest<HTMLElement>('[data-slot="dock"]');
177
+ if (!box || !surfaceRef) return 0;
178
+ return box.clientWidth - padX(box) - padX(surfaceRef);
179
+ };
179
180
 
180
- const checkOverflow = () => {
181
- if (!containerRef) return;
182
- const available = availableWidth();
183
- const overflowing = available > 0 && containerRef.scrollWidth > available + 1;
184
- if (overflowing) {
185
- const trimmed = stripWidth(available, itemWidth(), gapWidth());
186
- if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
187
- } else if (containerRef.style.width) {
188
- containerRef.style.width = "";
189
- }
190
- setNeedsScroll(overflowing);
191
- const viewport = containerRef.clientWidth;
192
- setViewportWidth(viewport);
193
- setPages(pageCount(containerRef.scrollWidth, viewport));
194
- setPage(pageOf(containerRef.scrollLeft, viewport));
195
- };
181
+ const checkOverflow = () => {
182
+ if (!containerRef) return;
183
+ const available = availableWidth();
184
+ const overflowing = available > 0 && containerRef.scrollWidth > available + 1;
185
+ if (overflowing) {
186
+ const trimmed = stripWidth(available, itemWidth(), gapWidth());
187
+ if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
188
+ } else if (containerRef.style.width) {
189
+ containerRef.style.width = "";
190
+ }
191
+ setNeedsScroll(overflowing);
192
+ const viewport = containerRef.clientWidth;
193
+ setViewportWidth(viewport);
194
+ setPages(pageCount(containerRef.scrollWidth, viewport));
195
+ setPage(pageOf(containerRef.scrollLeft, viewport));
196
+ };
196
197
 
197
- const goToPage = (next: number) => {
198
- if (!containerRef) return;
199
- containerRef.scrollTo({
200
- left: pageOffset(next, viewportWidth(), containerRef.scrollWidth),
201
- behavior: "smooth",
202
- });
203
- };
198
+ const goToPage = (next: number) => {
199
+ if (!containerRef) return;
200
+ containerRef.scrollTo({
201
+ left: pageOffset(next, viewportWidth(), containerRef.scrollWidth),
202
+ behavior: "smooth",
203
+ });
204
+ };
204
205
 
205
- // A drag cannot click a page dot, so resting on the dot row turns to the page under it.
206
- createEffect(() => {
207
- const point = local.dragPoint;
208
- if (!point || pages() < 2 || !surfaceRef || !containerRef) return;
209
- const strip = containerRef.getBoundingClientRect();
210
- const surface = surfaceRef.getBoundingClientRect();
211
- const onDotRow =
212
- point.y > strip.bottom &&
213
- point.y <= surface.bottom &&
214
- point.x >= surface.left &&
215
- point.x <= surface.right;
216
- if (!onDotRow) return;
217
- const target = Math.min(
218
- pages() - 1,
219
- Math.floor(((point.x - surface.left) / surface.width) * pages()),
220
- );
221
- if (target === page()) return;
222
- const timer = setTimeout(() => goToPage(target), 300);
223
- onCleanup(() => clearTimeout(timer));
224
- });
206
+ // A drag cannot click a page dot, so resting on the dot row turns to the page under it.
207
+ createEffect(() => {
208
+ const point = local.dragPoint;
209
+ if (!point || pages() < 2 || !surfaceRef || !containerRef) return;
210
+ const strip = containerRef.getBoundingClientRect();
211
+ const surface = surfaceRef.getBoundingClientRect();
212
+ const onDotRow =
213
+ point.y > strip.bottom &&
214
+ point.y <= surface.bottom &&
215
+ point.x >= surface.left &&
216
+ point.x <= surface.right;
217
+ if (!onDotRow) return;
218
+ const target = Math.min(
219
+ pages() - 1,
220
+ Math.floor(((point.x - surface.left) / surface.width) * pages()),
221
+ );
222
+ if (target === page()) return;
223
+ const timer = setTimeout(() => goToPage(target), 300);
224
+ onCleanup(() => clearTimeout(timer));
225
+ });
225
226
 
226
- // The active dashboard may sit on another page after a switch elsewhere.
227
- createEffect(() => {
228
- const i = activeIndex();
229
- if (i === null || !containerRef || !needsScroll()) return;
230
- const item = containerRef.querySelectorAll('[data-slot="dock-item"]')[i];
231
- if (!item || viewportWidth() <= 0) return;
232
- // The strip only: scrollIntoView would also scroll the page and any frame embedding it.
233
- const left =
234
- item.getBoundingClientRect().left -
235
- containerRef.getBoundingClientRect().left +
236
- containerRef.scrollLeft;
237
- goToPage(Math.floor(left / viewportWidth()));
238
- });
227
+ // The active dashboard may sit on another page after a switch elsewhere.
228
+ createEffect(() => {
229
+ const i = activeIndex();
230
+ if (i === null || !containerRef || !needsScroll()) return;
231
+ const item = containerRef.querySelectorAll('[data-slot="dock-item"]')[i];
232
+ if (!item || viewportWidth() <= 0) return;
233
+ // The strip only: scrollIntoView would also scroll the page and any frame embedding it.
234
+ const left =
235
+ item.getBoundingClientRect().left -
236
+ containerRef.getBoundingClientRect().left +
237
+ containerRef.scrollLeft;
238
+ goToPage(Math.floor(left / viewportWidth()));
239
+ });
239
240
 
240
- onMount(() => {
241
- const timeoutId = setTimeout(checkOverflow, 100);
242
- let resizeTimeoutId: ReturnType<typeof setTimeout> | undefined;
243
- const onResize = () => {
244
- clearTimeout(resizeTimeoutId);
245
- resizeTimeoutId = setTimeout(checkOverflow, 50);
246
- };
247
- window.addEventListener("resize", onResize);
248
- onCleanup(() => {
249
- clearTimeout(timeoutId);
250
- clearTimeout(resizeTimeoutId);
251
- window.removeEventListener("resize", onResize);
252
- });
253
- });
241
+ // Measured in the next frame's callbacks, which run before it paints: the first
242
+ // dock anyone sees already has its pages, so the dot row never shifts it later.
243
+ onMount(() => {
244
+ let resizeFrame = 0;
245
+ const onResize = () => {
246
+ cancelAnimationFrame(resizeFrame);
247
+ resizeFrame = requestAnimationFrame(checkOverflow);
248
+ };
249
+ window.addEventListener("resize", onResize);
250
+ onCleanup(() => {
251
+ cancelAnimationFrame(resizeFrame);
252
+ window.removeEventListener("resize", onResize);
253
+ });
254
+ });
254
255
 
255
- createEffect(() => {
256
- local.items.length;
257
- // The box pads by mode, so switching it changes the room the strip has.
258
- dockMode();
259
- const timeoutId = setTimeout(checkOverflow, 150);
260
- onCleanup(() => clearTimeout(timeoutId));
261
- });
256
+ // The box pads by mode, so switching it changes the room the strip has.
257
+ createEffect(
258
+ on([() => local.items.length, dockMode], () => {
259
+ const frame = requestAnimationFrame(checkOverflow);
260
+ onCleanup(() => cancelAnimationFrame(frame));
261
+ }),
262
+ );
262
263
 
263
- return (
264
- <div
265
- data-slot="dock"
266
- class={cn(
267
- "flex max-w-full items-center justify-center",
268
- dockMode() === "floating" ? "p-1 sm:p-2" : "",
269
- local.class,
270
- )}
271
- {...rest}
272
- >
273
- <div
274
- ref={surfaceRef}
275
- data-slot="dock-surface"
276
- class={cn(
277
- // isolate: the layers behind the icons stay inside the dock even with blur off.
278
- "pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
279
- // Room for the page dots inside the glass; outside it they sit on
280
- // the screen edge and get clipped.
281
- pages() > 1 && "pb-4 sm:pb-5",
282
- CARD_SURFACE,
283
- "[--glass-lift:0.55]",
284
- dockMode() === "floating" ? "rounded-xl" : "rounded-t-xl",
285
- )}
286
- >
287
- <div
288
- aria-hidden="true"
289
- class="pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-[inherit]"
290
- >
291
- <span
292
- data-slot="dock-flood"
293
- data-hold={local.hold && !local.hold.fired ? "" : undefined}
294
- data-fired={local.hold?.fired ? "" : undefined}
295
- class={cn(
296
- "absolute -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary/45",
297
- HOLD_MOTION,
298
- )}
299
- style={{
300
- left: `${holdPoint().x}px`,
301
- top: `${holdPoint().y}px`,
302
- width: `${holdPoint().r * 2}px`,
303
- height: `${holdPoint().r * 2}px`,
304
- }}
305
- />
306
- </div>
307
- <Show when={local.glow}>
308
- <div
309
- data-slot="dock-glow"
310
- aria-hidden="true"
311
- class="glass-edge-orbit fade-in-0 animate-in duration-(--duration-state)"
312
- >
313
- <div />
314
- </div>
315
- </Show>
316
- <div
317
- ref={containerRef}
318
- data-slot="dock-bar"
319
- onScroll={() => {
320
- if (containerRef) setPage(pageOf(containerRef.scrollLeft, viewportWidth()));
321
- }}
322
- class={cn(
323
- "flex items-center gap-0.5 sm:gap-1",
324
- needsScroll()
325
- ? "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth"
326
- : "overflow-visible",
327
- !needsScroll() && "justify-center",
328
- )}
329
- style={{
330
- "min-width": needsScroll() ? "auto" : "fit-content",
331
- }}
332
- >
333
- <SlidingIndicator active={pillIndex()} class="flex items-center gap-0.5 sm:gap-1">
334
- <Index each={local.items}>
335
- {(item, i) => (
336
- <DockIconButton
337
- class={needsScroll() ? "snap-start" : undefined}
338
- icon={item().icon}
339
- label={item().label}
340
- onClick={item().onClick}
341
- isActive={item().isActive}
342
- lit={i === pillIndex()}
343
- badge={item().badge}
344
- data-drop-target={item().isDropTarget ? "" : undefined}
345
- data-dock-id={item().id}
346
- />
347
- )}
348
- </Index>
349
- </SlidingIndicator>
350
- </div>
351
- <Show when={pages() > 1}>
352
- <div
353
- data-slot="dock-pages"
354
- class="pointer-events-auto absolute inset-x-0 bottom-1.5 flex justify-center gap-1.5"
355
- >
356
- <Index each={Array.from({ length: pages() })}>
357
- {(_, i) => (
358
- <button
359
- type="button"
360
- aria-label={`Page ${i + 1}`}
361
- aria-current={page() === i ? "true" : undefined}
362
- onClick={() => goToPage(i)}
363
- class={cn(
364
- "h-1.5 rounded-full transition-glass",
365
- page() === i ? "w-4 bg-foreground/70" : "w-1.5 bg-foreground/25",
366
- )}
367
- />
368
- )}
369
- </Index>
370
- </div>
371
- </Show>
372
- </div>
373
- </div>
374
- );
264
+ return (
265
+ <div
266
+ data-slot="dock"
267
+ class={cn(
268
+ "flex max-w-full items-center justify-center",
269
+ dockMode() === "floating" ? "p-1 sm:p-2" : "",
270
+ local.class,
271
+ )}
272
+ {...rest}
273
+ >
274
+ <div
275
+ ref={surfaceRef}
276
+ data-slot="dock-surface"
277
+ class={cn(
278
+ // isolate: the layers behind the icons stay inside the dock even with blur off.
279
+ "pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
280
+ // Room for the page dots inside the glass; outside it they sit on
281
+ // the screen edge and get clipped.
282
+ pages() > 1 && "pb-4 sm:pb-5",
283
+ CARD_SURFACE,
284
+ "[--glass-lift:0.55]",
285
+ dockMode() === "floating" ? "rounded-xl" : "rounded-t-xl",
286
+ )}
287
+ >
288
+ <div
289
+ aria-hidden="true"
290
+ class="pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-[inherit]"
291
+ >
292
+ <span
293
+ data-slot="dock-flood"
294
+ data-hold={local.hold && !local.hold.fired ? "" : undefined}
295
+ data-fired={local.hold?.fired ? "" : undefined}
296
+ class={cn(
297
+ "bg-primary/45 absolute -translate-x-1/2 -translate-y-1/2 rounded-full",
298
+ HOLD_MOTION,
299
+ )}
300
+ style={{
301
+ left: `${holdPoint().x}px`,
302
+ top: `${holdPoint().y}px`,
303
+ width: `${holdPoint().r * 2}px`,
304
+ height: `${holdPoint().r * 2}px`,
305
+ }}
306
+ />
307
+ </div>
308
+ <Show when={local.glow}>
309
+ <div
310
+ data-slot="dock-glow"
311
+ aria-hidden="true"
312
+ class="glass-edge-orbit fade-in-0 animate-in duration-(--duration-state)"
313
+ >
314
+ <div />
315
+ </div>
316
+ </Show>
317
+ <div
318
+ ref={containerRef}
319
+ data-slot="dock-bar"
320
+ onScroll={() => {
321
+ if (containerRef) setPage(pageOf(containerRef.scrollLeft, viewportWidth()));
322
+ }}
323
+ class={cn(
324
+ "flex items-center gap-0.5 sm:gap-1",
325
+ needsScroll()
326
+ ? "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth"
327
+ : "overflow-visible",
328
+ !needsScroll() && "justify-center",
329
+ )}
330
+ style={{
331
+ "min-width": needsScroll() ? "auto" : "fit-content",
332
+ }}
333
+ >
334
+ <SlidingIndicator active={pillIndex()} class="flex items-center gap-0.5 sm:gap-1">
335
+ <Index each={local.items}>
336
+ {(item, i) => (
337
+ <DockIconButton
338
+ class={needsScroll() ? "snap-start" : undefined}
339
+ icon={item().icon}
340
+ label={item().label}
341
+ onClick={item().onClick}
342
+ isActive={item().isActive}
343
+ lit={i === pillIndex()}
344
+ badge={item().badge}
345
+ data-drop-target={item().isDropTarget ? "" : undefined}
346
+ data-dock-id={item().id}
347
+ />
348
+ )}
349
+ </Index>
350
+ </SlidingIndicator>
351
+ </div>
352
+ <Show when={pages() > 1}>
353
+ <div
354
+ data-slot="dock-pages"
355
+ class="pointer-events-auto absolute inset-x-0 bottom-1.5 flex justify-center gap-1.5"
356
+ >
357
+ <Index each={Array.from({ length: pages() })}>
358
+ {(_, i) => (
359
+ <button
360
+ type="button"
361
+ aria-label={`Page ${i + 1}`}
362
+ aria-current={page() === i ? "true" : undefined}
363
+ onClick={() => goToPage(i)}
364
+ class={cn(
365
+ "transition-glass h-1.5 rounded-full",
366
+ page() === i ? "bg-foreground/70 w-4" : "bg-foreground/25 w-1.5",
367
+ )}
368
+ />
369
+ )}
370
+ </Index>
371
+ </div>
372
+ </Show>
373
+ </div>
374
+ </div>
375
+ );
375
376
  };
376
377
 
377
378
  export type { DockIconButtonProps, DockItem, DockProps };