@glasshome/ui 1.21.1 → 1.22.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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/use-is-mobile.d.ts +3 -1
- package/dist/solid/index.d.ts +9 -9
- package/dist/solid/index.js +5431 -5424
- package/dist/solid/sonner.d.ts +1 -0
- package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
- package/package.json +128 -126
- package/scripts/check-gallery.ts +142 -142
- package/scripts/check-pack.ts +13 -13
- package/scripts/check-structural-classes.ts +20 -20
- package/scripts/check-tokens.ts +27 -27
- package/scripts/check-ui-drift.mjs +103 -103
- package/src/index.ts +75 -80
- package/src/lib/alert-tones.ts +41 -41
- package/src/lib/anchor-placement.ts +21 -21
- package/src/lib/button-variants.ts +28 -28
- package/src/lib/card-classes.ts +9 -9
- package/src/lib/carousel-classes.ts +14 -14
- package/src/lib/glass-tone.ts +11 -11
- package/src/lib/input-classes.ts +6 -6
- package/src/lib/layers.ts +4 -4
- package/src/lib/logo-lockup.ts +8 -8
- package/src/lib/menu-classes.ts +2 -2
- package/src/lib/motion-classes.ts +8 -8
- package/src/lib/motion-window.ts +24 -24
- package/src/lib/overlay-classes.ts +6 -6
- package/src/lib/pill-classes.ts +3 -3
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/spotlight-geometry.ts +67 -67
- package/src/lib/thumb-classes.ts +2 -2
- package/src/lib/tier-badge.ts +16 -16
- package/src/lib/use-is-mobile.ts +17 -14
- package/src/lib/utils.ts +1 -1
- package/src/solid/accordion.tsx +41 -41
- package/src/solid/alert-dialog.tsx +95 -95
- package/src/solid/alert.tsx +88 -88
- package/src/solid/area-picker.tsx +204 -204
- package/src/solid/aspect-ratio.tsx +13 -13
- package/src/solid/avatar.tsx +27 -27
- package/src/solid/badge.tsx +49 -49
- package/src/solid/bottom-sheet/arbitration.ts +22 -22
- package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
- package/src/solid/bottom-sheet/drag-controller.ts +201 -201
- package/src/solid/bottom-sheet/focus-trap.ts +51 -47
- package/src/solid/bottom-sheet/index.ts +12 -12
- package/src/solid/bottom-sheet/keyboard.ts +25 -25
- package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
- package/src/solid/bottom-sheet/state-machine.ts +28 -28
- package/src/solid/bottom-sheet/velocity.ts +29 -29
- package/src/solid/breadcrumb.tsx +76 -76
- package/src/solid/button-group.tsx +46 -46
- package/src/solid/button.tsx +19 -19
- package/src/solid/card.tsx +67 -67
- package/src/solid/carousel.tsx +246 -246
- package/src/solid/charts.tsx +253 -253
- package/src/solid/checkbox.tsx +51 -51
- package/src/solid/collapsible.tsx +22 -22
- package/src/solid/color-disc.tsx +213 -213
- package/src/solid/color-slider.tsx +81 -81
- package/src/solid/color-wheel.tsx +61 -61
- package/src/solid/context-menu.tsx +63 -63
- package/src/solid/copy-button.tsx +31 -31
- package/src/solid/count-pill.tsx +11 -11
- package/src/solid/dashboard-preview.tsx +104 -104
- package/src/solid/data-table.tsx +228 -228
- package/src/solid/dialog-parts.tsx +127 -127
- package/src/solid/dialog.tsx +113 -113
- package/src/solid/dock-paging.ts +9 -9
- package/src/solid/dock.tsx +339 -339
- package/src/solid/docked-panel.tsx +35 -35
- package/src/solid/dropdown-menu.tsx +77 -77
- package/src/solid/empty.tsx +70 -70
- package/src/solid/entity-data.ts +38 -38
- package/src/solid/entity-selector.tsx +634 -634
- package/src/solid/field.tsx +205 -205
- package/src/solid/form.tsx +159 -159
- package/src/solid/hero-action.tsx +85 -85
- package/src/solid/hover-card.tsx +11 -11
- package/src/solid/icon-picker.tsx +401 -401
- package/src/solid/icon.tsx +101 -78
- package/src/solid/image-picker.tsx +416 -414
- package/src/solid/index.ts +265 -304
- package/src/solid/input-group.tsx +123 -123
- package/src/solid/input-otp.tsx +143 -143
- package/src/solid/input.tsx +4 -4
- package/src/solid/item.tsx +130 -130
- package/src/solid/kbd.tsx +20 -20
- package/src/solid/label.tsx +12 -12
- package/src/solid/list-reorder.ts +122 -122
- package/src/solid/logo.tsx +60 -60
- package/src/solid/media-copy.ts +21 -21
- package/src/solid/media-store.ts +56 -56
- package/src/solid/media-tile.tsx +85 -85
- package/src/solid/menu-parts.tsx +164 -164
- package/src/solid/number-field.tsx +56 -56
- package/src/solid/option-card.tsx +164 -164
- package/src/solid/ornament.tsx +43 -43
- package/src/solid/overlay.tsx +4 -4
- package/src/solid/page-header.tsx +75 -75
- package/src/solid/pagination.tsx +80 -80
- package/src/solid/password-input.tsx +51 -51
- package/src/solid/picker-row.tsx +83 -83
- package/src/solid/picker-search.tsx +65 -63
- package/src/solid/picker-trigger.tsx +59 -57
- package/src/solid/popover.tsx +54 -54
- package/src/solid/preview-tile.tsx +67 -67
- package/src/solid/progress.tsx +21 -21
- package/src/solid/radio-group.tsx +51 -51
- package/src/solid/resizable.tsx +128 -128
- package/src/solid/responsive-dialog.tsx +134 -134
- package/src/solid/schema-form.tsx +743 -743
- package/src/solid/scope-indicator.tsx +5 -5
- package/src/solid/scroll-area.tsx +16 -16
- package/src/solid/section-card.tsx +281 -281
- package/src/solid/select.tsx +101 -101
- package/src/solid/separator.tsx +25 -25
- package/src/solid/settings-row.tsx +122 -122
- package/src/solid/sheet.tsx +96 -96
- package/src/solid/skeleton.tsx +8 -8
- package/src/solid/slider.tsx +132 -132
- package/src/solid/sliding-indicator.tsx +280 -265
- package/src/solid/sonner.tsx +165 -164
- package/src/solid/spinner.tsx +12 -12
- package/src/solid/spotlight.tsx +140 -140
- package/src/solid/step-indicator.tsx +18 -18
- package/src/solid/swatch-picker.tsx +38 -38
- package/src/solid/switch.tsx +52 -52
- package/src/solid/table.tsx +63 -63
- package/src/solid/tabs.tsx +93 -93
- package/src/solid/textarea.tsx +8 -8
- package/src/solid/toggle-group.tsx +83 -83
- package/src/solid/toggle.tsx +33 -33
- package/src/solid/tooltip.tsx +16 -16
- package/src/solid/widget-card.tsx +90 -90
- package/src/solid/widget-identity.tsx +99 -99
- package/src/solid/widget-trust-badge.tsx +20 -20
- package/src/styles/globals.css +316 -319
- package/src/styles/theme.css +448 -448
- package/src/tokens/hex.ts +29 -29
- package/src/tokens/material.ts +75 -75
- package/src/tokens/presets.ts +303 -303
- package/src/tokens/readability.ts +32 -32
- package/src/tokens/theme-colors.ts +95 -95
- package/src/tokens/theme-css.ts +22 -22
- package/src/tokens/theme-recipe.ts +106 -106
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
}
|