@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,21 +1,20 @@
1
1
  import {
2
- type ComponentProps,
3
- createEffect,
4
- createSignal,
5
- type JSX,
6
- on,
7
- onCleanup,
8
- onMount,
9
- Show,
10
- splitProps,
2
+ type ComponentProps,
3
+ createEffect,
4
+ createSignal,
5
+ type JSX,
6
+ onCleanup,
7
+ onMount,
8
+ Show,
9
+ splitProps,
11
10
  } from "solid-js";
12
11
  import { cn } from "../lib/utils.js";
13
12
 
14
13
  function readTranslate(el: HTMLElement): [number, number] {
15
- const t = getComputedStyle(el).translate;
16
- if (!t || t === "none") return [0, 0];
17
- const [x = "0", y = "0"] = t.split(" ");
18
- return [Number.parseFloat(x) || 0, Number.parseFloat(y) || 0];
14
+ const t = getComputedStyle(el).translate;
15
+ if (!t || t === "none") return [0, 0];
16
+ const [x = "0", y = "0"] = t.split(" ");
17
+ return [Number.parseFloat(x) || 0, Number.parseFloat(y) || 0];
19
18
  }
20
19
 
21
20
  /**
@@ -28,26 +27,26 @@ function readTranslate(el: HTMLElement): [number, number] {
28
27
  * its own indicator). Give it `indicatorClass` for the look and `orientation` for the axis.
29
28
  */
30
29
  interface SlidingIndicatorProps extends ComponentProps<"div"> {
31
- /** Index-based active item among the measured children, or null to hide.
32
- * Use this when you own the selection (e.g. Dock). */
33
- active?: number | null;
34
- /** Attribute-based active item: a selector for the currently-active child
35
- * (e.g. "[data-selected]"). Use this with libraries that mark the active item
36
- * in the DOM (Kobalte Tabs/ToggleGroup); a MutationObserver re-slides on change. */
37
- activeSelector?: string;
38
- orientation?: "horizontal" | "vertical";
39
- /** Extra classes for the sliding indicator — radius and any per-surface `--glass-*`
40
- * knob overrides. The trusted `.glass` material is ALWAYS applied underneath, so
41
- * this can't flatten the indicator; it only tunes it. Default radius: `rounded-lg`. */
42
- indicatorClass?: string;
43
- /** Glass tone that drives the `.glass` material (`--glass-tone`). Defaults to
44
- * `var(--primary)` — the one trusted look. Pass another CSS color to re-tint. */
45
- indicatorTone?: string;
46
- /** Selector for the measurable items. Default: direct children (minus the indicator). */
47
- itemSelector?: string;
48
- /** Items wrap onto rows: the indicator follows the active item's row as well as its place in it. */
49
- wrapped?: boolean;
50
- children: JSX.Element;
30
+ /** Index-based active item among the measured children, or null to hide.
31
+ * Use this when you own the selection (e.g. Dock). */
32
+ active?: number | null;
33
+ /** Attribute-based active item: a selector for the currently-active child
34
+ * (e.g. "[data-selected]"). Use this with libraries that mark the active item
35
+ * in the DOM (Kobalte Tabs/ToggleGroup); a MutationObserver re-slides on change. */
36
+ activeSelector?: string;
37
+ orientation?: "horizontal" | "vertical";
38
+ /** Extra classes for the sliding indicator — radius and any per-surface `--glass-*`
39
+ * knob overrides. The trusted `.glass` material is ALWAYS applied underneath, so
40
+ * this can't flatten the indicator; it only tunes it. Default radius: `rounded-lg`. */
41
+ indicatorClass?: string;
42
+ /** Glass tone that drives the `.glass` material (`--glass-tone`). Defaults to
43
+ * `var(--primary)` — the one trusted look. Pass another CSS color to re-tint. */
44
+ indicatorTone?: string;
45
+ /** Selector for the measurable items. Default: direct children (minus the indicator). */
46
+ itemSelector?: string;
47
+ /** Items wrap onto rows: the indicator follows the active item's row as well as its place in it. */
48
+ wrapped?: boolean;
49
+ children: JSX.Element;
51
50
  }
52
51
 
53
52
  type Pos = { offset: number; size: number; cross: number; crossOffset: number };
@@ -68,244 +67,260 @@ const SQUASH_PX = 6; // pinch perpendicular
68
67
  const DEFORM_MAX = 0.14;
69
68
 
70
69
  export function SlidingIndicator(props: SlidingIndicatorProps) {
71
- const [local, rest] = splitProps(props, [
72
- "active",
73
- "activeSelector",
74
- "orientation",
75
- "indicatorClass",
76
- "indicatorTone",
77
- "itemSelector",
78
- "wrapped",
79
- "class",
80
- "children",
81
- "ref",
82
- ]);
83
- const horizontal = () => (local.orientation ?? "horizontal") === "horizontal";
84
- let containerRef: HTMLDivElement | undefined;
85
- // A caller's ref goes through here, not through the spread: `spread()` would
86
- // hand its own ref to the element and leave containerRef unset, so nothing
87
- // would ever measure.
88
- const setContainerRef = (el: HTMLDivElement) => {
89
- containerRef = el;
90
- const forwarded = local.ref;
91
- if (typeof forwarded === "function") forwarded(el);
92
- };
93
- const [pos, setPos] = createSignal<Pos | null>(null);
70
+ const [local, rest] = splitProps(props, [
71
+ "active",
72
+ "activeSelector",
73
+ "orientation",
74
+ "indicatorClass",
75
+ "indicatorTone",
76
+ "itemSelector",
77
+ "wrapped",
78
+ "class",
79
+ "children",
80
+ "ref",
81
+ ]);
82
+ const horizontal = () => (local.orientation ?? "horizontal") === "horizontal";
83
+ let containerRef: HTMLDivElement | undefined;
84
+ // A caller's ref goes through here, not through the spread: `spread()` would
85
+ // hand its own ref to the element and leave containerRef unset, so nothing
86
+ // would ever measure.
87
+ const setContainerRef = (el: HTMLDivElement) => {
88
+ containerRef = el;
89
+ const forwarded = local.ref;
90
+ if (typeof forwarded === "function") forwarded(el);
91
+ };
92
+ const [pos, setPos] = createSignal<Pos | null>(null);
94
93
 
95
- // On a real move, play a symmetric squash-and-stretch (1 → peak → 1) over the
96
- // SAME duration as the slide, so the deform and the travel fully overlap: fastest
97
- // and most stretched at mid-flight, back to a square at both ends (accelerate in,
98
- // settle out). At the peak the indicator STRETCHES along the travel axis and
99
- // PINCHES perpendicular (the reciprocal, so volume is preserved) — the classic
100
- // speed cue. WAAPI on `scale` composes with the translate transition; it releases
101
- // back to the base (1) on its own, so nothing can get stuck deformed.
102
- let indicatorEl: HTMLDivElement | undefined;
103
- createEffect(
104
- on(
105
- pos,
106
- (p, prev) => {
107
- // pos is a fresh object on every re-measure (the Select's MutationObserver
108
- // fires often), so only animate on an actual travel.
109
- if (!p || !prev || Math.abs(p.offset - prev.offset) < 1 || !indicatorEl) return;
110
- const stretch = 1 + Math.min(DEFORM_MAX, STRETCH_PX / (p.size || 1));
111
- const squash = 1 - Math.min(DEFORM_MAX, SQUASH_PX / (p.cross || 1));
112
- const peak = horizontal() ? `${stretch} ${squash}` : `${squash} ${stretch}`;
113
- indicatorEl.animate([{ scale: "1 1" }, { scale: peak }, { scale: "1 1" }], {
114
- duration: SLIDE_MS,
115
- easing: "ease-in-out",
116
- });
117
- },
118
- { defer: true },
119
- ),
120
- );
94
+ // On a real move, play a symmetric squash-and-stretch (1 → peak → 1) over the
95
+ // SAME duration as the slide, so the deform and the travel fully overlap: fastest
96
+ // and most stretched at mid-flight, back to a square at both ends (accelerate in,
97
+ // settle out). At the peak the indicator STRETCHES along the travel axis and
98
+ // PINCHES perpendicular (the reciprocal, so volume is preserved) — the classic
99
+ // speed cue. WAAPI on `scale` composes with the translate transition; it releases
100
+ // back to the base (1) on its own, so nothing can get stuck deformed.
101
+ let indicatorEl: HTMLDivElement | undefined;
102
+ const squash = (p: Pos) => {
103
+ const stretch = 1 + Math.min(DEFORM_MAX, STRETCH_PX / (p.size || 1));
104
+ const pinch = 1 - Math.min(DEFORM_MAX, SQUASH_PX / (p.cross || 1));
105
+ const peak = horizontal() ? `${stretch} ${pinch}` : `${pinch} ${stretch}`;
106
+ indicatorEl?.animate([{ scale: "1 1" }, { scale: peak }, { scale: "1 1" }], {
107
+ duration: SLIDE_MS,
108
+ easing: "ease-in-out",
109
+ });
110
+ };
121
111
 
122
- // A zero-size pass is not a resting state, and nothing is guaranteed to fire
123
- // when it ends: an ancestor dialog's own open animation neither resizes this
124
- // container nor bubbles its animationend down here.
125
- const RETRY_FRAMES = 90;
126
- let retries = 0;
127
- let retryFrame: number | undefined;
128
- const remeasureNextFrame = () => {
129
- if (disposed || retryFrame !== undefined || retries >= RETRY_FRAMES) return;
130
- retries += 1;
131
- retryFrame = requestAnimationFrame(() => {
132
- retryFrame = undefined;
133
- if (!disposed) measure();
134
- });
135
- };
112
+ // Only a new active item slides. Every other re-measure (a resize, a late icon
113
+ // or font, an opening dialog settling) corrects geometry and lands at once:
114
+ // a size transition lays the page out on every frame it runs.
115
+ let measuredEl: HTMLElement | undefined;
116
+ const [sliding, setSliding] = createSignal(false);
117
+ let slideTimer: ReturnType<typeof setTimeout> | undefined;
118
+ const place = (el: HTMLElement, next: Pos) => {
119
+ const prev = pos();
120
+ const moved = measuredEl !== undefined && measuredEl !== el && prev !== null;
121
+ measuredEl = el;
122
+ if (moved) {
123
+ clearTimeout(slideTimer);
124
+ setSliding(true);
125
+ slideTimer = setTimeout(() => setSliding(false), SLIDE_MS);
126
+ }
127
+ setPos(next);
128
+ if (moved && Math.abs(next.offset - prev.offset) >= 1) squash(next);
129
+ };
136
130
 
137
- const measure = () => {
138
- if (!containerRef) return;
139
- syncObservedItems();
140
- let el: HTMLElement | null | undefined;
141
- if (local.activeSelector) {
142
- el = containerRef.querySelector<HTMLElement>(local.activeSelector);
143
- } else if (local.active != null && local.active >= 0) {
144
- const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
145
- el = containerRef.querySelectorAll<HTMLElement>(sel)[local.active];
146
- }
147
- if (!el) {
148
- setPos(null);
149
- return;
150
- }
151
- // Not laid out yet: a hidden/collapsing popover, a display:none tab panel, or
152
- // a portal measured before Kobalte positions it. Hide until real geometry.
153
- const er = el.getBoundingClientRect();
154
- const cr = containerRef.getBoundingClientRect();
155
- if (er.width === 0 || er.height === 0 || cr.width === 0 || cr.height === 0) {
156
- setPos(null);
157
- remeasureNextFrame();
158
- return;
159
- }
160
- retries = 0;
161
- // Measure relative to the container via bounding rects (not offsetLeft),
162
- // so the active item can be a deep descendant (Kobalte menu/listbox items),
163
- // not just a direct child. Add the container's own scroll so the indicator,
164
- // which scrolls with the content, lands at the content offset; subtract the
165
- // border so it aligns to the padding box (where the absolute indicator anchors).
166
- // A row arriving through gh-stagger is still translated: bounding rects
167
- // include that travel, its resting place does not.
168
- // An ancestor mid-zoom (a dialog opening) scales every rect and ends without
169
- // a resize, so rects convert back to layout pixels by the container's ratio.
170
- const sx = containerRef.offsetWidth > 0 ? cr.width / containerRef.offsetWidth : 1;
171
- const sy = containerRef.offsetHeight > 0 ? cr.height / containerRef.offsetHeight : 1;
172
- const [tx, ty] = readTranslate(el);
173
- setPos(
174
- horizontal()
175
- ? {
176
- offset:
177
- (er.left - cr.left) / sx - tx - containerRef.clientLeft + containerRef.scrollLeft,
178
- size: er.width / sx,
179
- cross: er.height / sy,
180
- crossOffset:
181
- (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
182
- }
183
- : {
184
- offset: (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
185
- size: er.height / sy,
186
- cross: er.width / sx,
187
- crossOffset: 0,
188
- },
189
- );
190
- };
131
+ // A zero-size pass is not a resting state, and nothing is guaranteed to fire
132
+ // when it ends: an ancestor dialog's own open animation neither resizes this
133
+ // container nor bubbles its animationend down here.
134
+ const RETRY_FRAMES = 90;
135
+ let retries = 0;
136
+ let retryFrame: number | undefined;
137
+ const remeasureNextFrame = () => {
138
+ if (disposed || retryFrame !== undefined || retries >= RETRY_FRAMES) return;
139
+ retries += 1;
140
+ retryFrame = requestAnimationFrame(() => {
141
+ retryFrame = undefined;
142
+ if (!disposed) measure();
143
+ });
144
+ };
191
145
 
192
- // Re-measure whenever the (index) active changes; queueMicrotask lets DOM settle.
193
- createEffect(() => {
194
- void local.active;
195
- queueMicrotask(measure);
196
- });
146
+ const measure = () => {
147
+ if (!containerRef) return;
148
+ syncObservedItems();
149
+ let el: HTMLElement | null | undefined;
150
+ if (local.activeSelector) {
151
+ el = containerRef.querySelector<HTMLElement>(local.activeSelector);
152
+ } else if (local.active != null && local.active >= 0) {
153
+ const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
154
+ el = containerRef.querySelectorAll<HTMLElement>(sel)[local.active];
155
+ }
156
+ if (!el) {
157
+ measuredEl = undefined;
158
+ setPos(null);
159
+ return;
160
+ }
161
+ // Not laid out yet: a hidden/collapsing popover, a display:none tab panel, or
162
+ // a portal measured before Kobalte positions it. Hide until real geometry.
163
+ const er = el.getBoundingClientRect();
164
+ const cr = containerRef.getBoundingClientRect();
165
+ if (er.width === 0 || er.height === 0 || cr.width === 0 || cr.height === 0) {
166
+ measuredEl = undefined;
167
+ setPos(null);
168
+ remeasureNextFrame();
169
+ return;
170
+ }
171
+ retries = 0;
172
+ // Measure relative to the container via bounding rects (not offsetLeft),
173
+ // so the active item can be a deep descendant (Kobalte menu/listbox items),
174
+ // not just a direct child. Add the container's own scroll so the indicator,
175
+ // which scrolls with the content, lands at the content offset; subtract the
176
+ // border so it aligns to the padding box (where the absolute indicator anchors).
177
+ // A row arriving through gh-stagger is still translated: bounding rects
178
+ // include that travel, its resting place does not.
179
+ // An ancestor mid-zoom (a dialog opening) scales every rect and ends without
180
+ // a resize, so rects convert back to layout pixels by the container's ratio.
181
+ const sx = containerRef.offsetWidth > 0 ? cr.width / containerRef.offsetWidth : 1;
182
+ const sy = containerRef.offsetHeight > 0 ? cr.height / containerRef.offsetHeight : 1;
183
+ const [tx, ty] = readTranslate(el);
184
+ place(
185
+ el,
186
+ horizontal()
187
+ ? {
188
+ offset:
189
+ (er.left - cr.left) / sx - tx - containerRef.clientLeft + containerRef.scrollLeft,
190
+ size: er.width / sx,
191
+ cross: er.height / sy,
192
+ crossOffset:
193
+ (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
194
+ }
195
+ : {
196
+ offset: (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
197
+ size: er.height / sy,
198
+ cross: er.width / sx,
199
+ crossOffset: 0,
200
+ },
201
+ );
202
+ };
197
203
 
198
- // The items actually under the ResizeObserver, so entries can be diffed
199
- // against the freshly-resolved set on every measure() pass.
200
- let ro: ResizeObserver | undefined;
201
- const observedItems = new Set<Element>();
202
- let disposed = false;
204
+ // Re-measure whenever the (index) active changes; queueMicrotask lets DOM settle.
205
+ createEffect(() => {
206
+ void local.active;
207
+ queueMicrotask(measure);
208
+ });
203
209
 
204
- // Observing only the container missed the case that broke the admin tabs
205
- // pill: an <iconify-icon> or a webfont finishes loading AFTER first paint and
206
- // grows the trigger, but a w-full container never itself resizes, so the
207
- // indicator kept the stale width. Observing the resolved item(s) directly
208
- // catches that growth.
209
- function syncObservedItems() {
210
- if (!containerRef || !ro) return;
211
- const next = new Set<Element>();
212
- if (local.activeSelector) {
213
- const el = containerRef.querySelector(local.activeSelector);
214
- if (el) next.add(el);
215
- } else if (local.active != null && local.active >= 0) {
216
- const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
217
- for (const el of containerRef.querySelectorAll(sel)) next.add(el);
218
- }
219
- for (const el of observedItems) {
220
- if (!next.has(el)) {
221
- ro.unobserve(el);
222
- observedItems.delete(el);
223
- }
224
- }
225
- for (const el of next) {
226
- if (!observedItems.has(el)) {
227
- ro.observe(el);
228
- observedItems.add(el);
229
- }
230
- }
231
- }
210
+ // The items actually under the ResizeObserver, so entries can be diffed
211
+ // against the freshly-resolved set on every measure() pass.
212
+ let ro: ResizeObserver | undefined;
213
+ const observedItems = new Set<Element>();
214
+ let disposed = false;
232
215
 
233
- onMount(() => {
234
- if (!containerRef) return;
235
- ro = new ResizeObserver(() => measure());
236
- containerRef?.addEventListener("animationend", measure);
237
- ro.observe(containerRef);
238
- // Attribute-based selection (e.g. Kobalte's [data-selected]/[data-highlighted]):
239
- // re-slide when the active child's marker attribute moves, or when items are
240
- // added/removed, so newly-mounted items land under the same observer.
241
- const mo = new MutationObserver(() => {
242
- syncObservedItems();
243
- queueMicrotask(measure);
244
- });
245
- mo.observe(containerRef, {
246
- childList: true,
247
- subtree: !!local.activeSelector,
248
- attributes: !!local.activeSelector,
249
- });
250
- // Focus-based selection (e.g. Kobalte menus mark the highlighted item with
251
- // roving focus, which is not an attribute mutation).
252
- const onFocusIn = () => queueMicrotask(measure);
253
- if (local.activeSelector) containerRef.addEventListener("focusin", onFocusIn);
254
- syncObservedItems();
255
- queueMicrotask(measure);
256
- // Web fonts can finish loading after the first measure and grow glyphs
257
- // (the same class of bug the item-level ResizeObserver above fixes for
258
- // icons); one extra pass once fonts settle catches that too.
259
- if (typeof document !== "undefined" && document.fonts) {
260
- document.fonts.ready.then(() => {
261
- if (!disposed) measure();
262
- });
263
- }
264
- onCleanup(() => {
265
- disposed = true;
266
- if (retryFrame !== undefined) cancelAnimationFrame(retryFrame);
267
- ro?.disconnect();
268
- mo.disconnect();
269
- containerRef?.removeEventListener("focusin", onFocusIn);
270
- containerRef?.removeEventListener("animationend", measure);
271
- });
272
- });
216
+ // Observing only the container missed the case that broke the admin tabs
217
+ // pill: an <iconify-icon> or a webfont finishes loading AFTER first paint and
218
+ // grows the trigger, but a w-full container never itself resizes, so the
219
+ // indicator kept the stale width. Observing the resolved item(s) directly
220
+ // catches that growth.
221
+ function syncObservedItems() {
222
+ if (!containerRef || !ro) return;
223
+ const next = new Set<Element>();
224
+ if (local.activeSelector) {
225
+ const el = containerRef.querySelector(local.activeSelector);
226
+ if (el) next.add(el);
227
+ } else if (local.active != null && local.active >= 0) {
228
+ const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
229
+ for (const el of containerRef.querySelectorAll(sel)) next.add(el);
230
+ }
231
+ for (const el of observedItems) {
232
+ if (!next.has(el)) {
233
+ ro.unobserve(el);
234
+ observedItems.delete(el);
235
+ }
236
+ }
237
+ for (const el of next) {
238
+ if (!observedItems.has(el)) {
239
+ ro.observe(el);
240
+ observedItems.add(el);
241
+ }
242
+ }
243
+ }
273
244
 
274
- return (
275
- <div ref={setContainerRef} class={cn("relative isolate", local.class)} {...rest}>
276
- <Show when={pos()}>
277
- {(p) => (
278
- <div
279
- ref={indicatorEl}
280
- data-sliding-indicator
281
- aria-hidden="true"
282
- class={cn(
283
- "pointer-events-none absolute -z-10",
284
- local.wrapped
285
- ? "top-0 left-0"
286
- : horizontal()
287
- ? "inset-y-0 left-0"
288
- : "inset-x-0 top-0",
289
- "glass glass-tint",
290
- local.indicatorClass ?? "rounded-lg",
291
- )}
292
- style={{
293
- transition: `transform ${SLIDE_MS}ms ease-in-out, width ${SLIDE_MS}ms ease-in-out, height ${SLIDE_MS}ms ease-in-out`,
294
- "--glass-tone": local.indicatorTone ?? "var(--primary)",
295
- ...(local.wrapped && horizontal()
296
- ? {
297
- transform: `translate(${p().offset}px, ${p().crossOffset}px)`,
298
- width: `${p().size}px`,
299
- height: `${p().cross}px`,
300
- }
301
- : horizontal()
302
- ? { transform: `translateX(${p().offset}px)`, width: `${p().size}px` }
303
- : { transform: `translateY(${p().offset}px)`, height: `${p().size}px` }),
304
- }}
305
- />
306
- )}
307
- </Show>
308
- {local.children}
309
- </div>
310
- );
245
+ onMount(() => {
246
+ if (!containerRef) return;
247
+ ro = new ResizeObserver(() => measure());
248
+ containerRef?.addEventListener("animationend", measure);
249
+ ro.observe(containerRef);
250
+ // Attribute-based selection (e.g. Kobalte's [data-selected]/[data-highlighted]):
251
+ // re-slide when the active child's marker attribute moves, or when items are
252
+ // added/removed, so newly-mounted items land under the same observer.
253
+ const mo = new MutationObserver(() => {
254
+ syncObservedItems();
255
+ queueMicrotask(measure);
256
+ });
257
+ mo.observe(containerRef, {
258
+ childList: true,
259
+ subtree: !!local.activeSelector,
260
+ attributes: !!local.activeSelector,
261
+ });
262
+ // Focus-based selection (e.g. Kobalte menus mark the highlighted item with
263
+ // roving focus, which is not an attribute mutation).
264
+ const onFocusIn = () => queueMicrotask(measure);
265
+ if (local.activeSelector) containerRef.addEventListener("focusin", onFocusIn);
266
+ syncObservedItems();
267
+ queueMicrotask(measure);
268
+ // Web fonts can finish loading after the first measure and grow glyphs
269
+ // (the same class of bug the item-level ResizeObserver above fixes for
270
+ // icons); one extra pass once fonts settle catches that too.
271
+ if (typeof document !== "undefined" && document.fonts) {
272
+ void document.fonts.ready.then(() => {
273
+ if (!disposed) measure();
274
+ });
275
+ }
276
+ onCleanup(() => {
277
+ disposed = true;
278
+ if (retryFrame !== undefined) cancelAnimationFrame(retryFrame);
279
+ clearTimeout(slideTimer);
280
+ ro?.disconnect();
281
+ mo.disconnect();
282
+ containerRef?.removeEventListener("focusin", onFocusIn);
283
+ containerRef?.removeEventListener("animationend", measure);
284
+ });
285
+ });
286
+
287
+ return (
288
+ <div ref={setContainerRef} class={cn("relative isolate", local.class)} {...rest}>
289
+ <Show when={pos()}>
290
+ {(p) => (
291
+ <div
292
+ ref={indicatorEl}
293
+ data-sliding-indicator
294
+ aria-hidden="true"
295
+ class={cn(
296
+ "pointer-events-none absolute -z-10",
297
+ local.wrapped
298
+ ? "top-0 left-0"
299
+ : horizontal()
300
+ ? "inset-y-0 left-0"
301
+ : "inset-x-0 top-0",
302
+ "glass glass-tint",
303
+ local.indicatorClass ?? "rounded-lg",
304
+ )}
305
+ style={{
306
+ transition: sliding()
307
+ ? `transform ${SLIDE_MS}ms ease-in-out, width ${SLIDE_MS}ms ease-in-out, height ${SLIDE_MS}ms ease-in-out`
308
+ : "none",
309
+ "--glass-tone": local.indicatorTone ?? "var(--primary)",
310
+ ...(local.wrapped && horizontal()
311
+ ? {
312
+ transform: `translate(${p().offset}px, ${p().crossOffset}px)`,
313
+ width: `${p().size}px`,
314
+ height: `${p().cross}px`,
315
+ }
316
+ : horizontal()
317
+ ? { transform: `translateX(${p().offset}px)`, width: `${p().size}px` }
318
+ : { transform: `translateY(${p().offset}px)`, height: `${p().size}px` }),
319
+ }}
320
+ />
321
+ )}
322
+ </Show>
323
+ {local.children}
324
+ </div>
325
+ );
311
326
  }