@glasshome/ui 1.42.0 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/SPEC.md +8 -5
  2. package/dist/index.js +2 -2
  3. package/dist/lib/anchor-placement.d.ts +4 -0
  4. package/dist/lib/balance-rows.d.ts +10 -4
  5. package/dist/lib/behavior/anchored.d.ts +16 -3
  6. package/dist/lib/behavior/button-root.d.ts +7 -0
  7. package/dist/lib/behavior/collection.d.ts +8 -0
  8. package/dist/lib/behavior/dismiss.d.ts +6 -4
  9. package/dist/lib/behavior/focus-scope.d.ts +9 -1
  10. package/dist/lib/behavior/hide-outside.d.ts +1 -1
  11. package/dist/lib/behavior/layer-stack.d.ts +3 -2
  12. package/dist/lib/behavior/menu.d.ts +62 -0
  13. package/dist/lib/behavior/modal-root.d.ts +2 -0
  14. package/dist/lib/behavior/range.d.ts +44 -0
  15. package/dist/lib/color/color.d.ts +41 -0
  16. package/dist/lib/color/index.d.ts +2 -0
  17. package/dist/lib/color/intl.d.ts +40 -0
  18. package/dist/lib/dock-slot-classes.d.ts +2 -0
  19. package/dist/lib/hold.d.ts +1 -1
  20. package/dist/lib/locale.d.ts +3 -0
  21. package/dist/lib/menu-classes.d.ts +2 -0
  22. package/dist/lib/motion-classes.d.ts +2 -1
  23. package/dist/lib/overlay-classes.d.ts +1 -0
  24. package/dist/lib/scroll-track.d.ts +3 -2
  25. package/dist/lib/section-tokens.d.ts +1 -1
  26. package/dist/lib/segment-classes.d.ts +2 -0
  27. package/dist/lib/shadow-layer.d.ts +0 -45
  28. package/dist/lib/toggle-set.d.ts +44 -0
  29. package/dist/lib/visually-hidden.d.ts +3 -0
  30. package/dist/solid/accordion.d.ts +35 -11
  31. package/dist/solid/avatar.d.ts +8 -4
  32. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
  33. package/dist/solid/button.d.ts +5 -4
  34. package/dist/solid/charts.d.ts +1 -1
  35. package/dist/solid/checkbox.d.ts +14 -4
  36. package/dist/solid/collapsible.d.ts +33 -5
  37. package/dist/solid/color-disc.d.ts +1 -1
  38. package/dist/solid/color-slider.d.ts +1 -1
  39. package/dist/solid/color-wheel.d.ts +1 -1
  40. package/dist/solid/context-menu.d.ts +58 -24
  41. package/dist/solid/data-table.d.ts +4 -2
  42. package/dist/solid/dialog-parts.d.ts +8 -8
  43. package/dist/solid/dropdown-menu.d.ts +55 -24
  44. package/dist/solid/empty.d.ts +1 -1
  45. package/dist/solid/form.d.ts +5 -6
  46. package/dist/solid/hover-card.d.ts +65 -9
  47. package/dist/solid/index.d.ts +1 -1
  48. package/dist/solid/index.js +7752 -13493
  49. package/dist/solid/input-group.d.ts +6 -6
  50. package/dist/solid/item.d.ts +1 -1
  51. package/dist/solid/menu-parts.d.ts +175 -24
  52. package/dist/solid/option-card.d.ts +1 -4
  53. package/dist/solid/picker-row.d.ts +2 -0
  54. package/dist/solid/popover.d.ts +77 -12
  55. package/dist/solid/progress.d.ts +11 -3
  56. package/dist/solid/radio-group.d.ts +31 -6
  57. package/dist/solid/responsive-dialog.d.ts +1 -1
  58. package/dist/solid/scroll-area.d.ts +1 -1
  59. package/dist/solid/section-card.d.ts +2 -3
  60. package/dist/solid/select.d.ts +107 -10
  61. package/dist/solid/selection.d.ts +10 -1
  62. package/dist/solid/sheet.d.ts +1 -1
  63. package/dist/solid/sliding-indicator.d.ts +1 -1
  64. package/dist/solid/sonner.d.ts +1 -1
  65. package/dist/solid/toggle.d.ts +11 -3
  66. package/dist/solid/tooltip.d.ts +22 -22
  67. package/dist/tokens/index.js +54 -51
  68. package/dist/{utils-CxAii-e9.js → utils-BbIeGt7o.js} +376 -314
  69. package/package.json +3 -6
  70. package/src/lib/anchor-placement.ts +10 -3
  71. package/src/lib/balance-rows.ts +115 -40
  72. package/src/lib/behavior/anchored.ts +41 -9
  73. package/src/lib/behavior/button-root.tsx +103 -0
  74. package/src/lib/behavior/collection.ts +56 -28
  75. package/src/lib/behavior/dismiss.ts +61 -21
  76. package/src/lib/behavior/focus-scope.ts +75 -9
  77. package/src/lib/behavior/hide-outside.ts +2 -2
  78. package/src/lib/behavior/layer-stack.ts +33 -8
  79. package/src/lib/behavior/menu.ts +462 -0
  80. package/src/lib/behavior/modal-root.tsx +24 -18
  81. package/src/lib/behavior/polymorphic.tsx +1 -1
  82. package/src/lib/behavior/presence.ts +1 -1
  83. package/src/lib/behavior/range.ts +212 -0
  84. package/src/lib/clipboard.ts +2 -3
  85. package/src/lib/color/color.ts +746 -0
  86. package/src/lib/color/index.ts +2 -0
  87. package/src/lib/color/intl.ts +60 -0
  88. package/src/lib/dock-slot-classes.ts +3 -0
  89. package/src/lib/hold.ts +1 -1
  90. package/src/lib/locale.ts +62 -0
  91. package/src/lib/menu-classes.ts +3 -0
  92. package/src/lib/motion-classes.ts +8 -9
  93. package/src/lib/overlay-classes.ts +1 -3
  94. package/src/lib/scroll-track.ts +11 -6
  95. package/src/lib/section-tokens.ts +1 -1
  96. package/src/lib/segment-classes.ts +3 -0
  97. package/src/lib/shadow-layer.ts +0 -118
  98. package/src/lib/toggle-set.ts +133 -0
  99. package/src/lib/visually-hidden.ts +15 -0
  100. package/src/solid/accordion.tsx +294 -20
  101. package/src/solid/area-picker.tsx +4 -4
  102. package/src/solid/avatar.tsx +98 -24
  103. package/src/solid/bottom-sheet/arbitration.ts +4 -11
  104. package/src/solid/bottom-sheet/bottom-sheet.tsx +4 -5
  105. package/src/solid/bottom-sheet/drag-controller.ts +7 -20
  106. package/src/solid/button.tsx +12 -6
  107. package/src/solid/charts.tsx +1 -1
  108. package/src/solid/checkbox.tsx +167 -44
  109. package/src/solid/collapsible.tsx +260 -12
  110. package/src/solid/color-disc.tsx +11 -12
  111. package/src/solid/color-slider.tsx +114 -47
  112. package/src/solid/color-wheel.tsx +137 -39
  113. package/src/solid/context-menu.tsx +285 -94
  114. package/src/solid/data-table.tsx +48 -22
  115. package/src/solid/dialog-parts.tsx +39 -17
  116. package/src/solid/dock.tsx +44 -43
  117. package/src/solid/dropdown-menu.tsx +252 -115
  118. package/src/solid/empty.tsx +1 -1
  119. package/src/solid/entity-selector.tsx +3 -3
  120. package/src/solid/face-toggle.tsx +43 -18
  121. package/src/solid/form.tsx +5 -6
  122. package/src/solid/glyph-tile.tsx +48 -21
  123. package/src/solid/hover-card.tsx +287 -25
  124. package/src/solid/icon-picker.tsx +1 -2
  125. package/src/solid/image-picker.tsx +2 -2
  126. package/src/solid/index.ts +1 -3
  127. package/src/solid/input-group.tsx +2 -2
  128. package/src/solid/item.tsx +1 -1
  129. package/src/solid/menu-parts.tsx +610 -155
  130. package/src/solid/option-card.tsx +7 -13
  131. package/src/solid/picker-row.tsx +5 -1
  132. package/src/solid/popover.tsx +423 -80
  133. package/src/solid/preview-tile.tsx +1 -1
  134. package/src/solid/progress.tsx +84 -15
  135. package/src/solid/radio-group.tsx +271 -34
  136. package/src/solid/responsive-dialog.tsx +1 -1
  137. package/src/solid/schema-form.tsx +1 -6
  138. package/src/solid/scroll-area.tsx +1 -1
  139. package/src/solid/section-card.tsx +3 -4
  140. package/src/solid/select.tsx +939 -95
  141. package/src/solid/selection.tsx +165 -74
  142. package/src/solid/sheet.tsx +1 -1
  143. package/src/solid/slider.tsx +115 -65
  144. package/src/solid/sliding-indicator.tsx +4 -16
  145. package/src/solid/sonner.tsx +1 -1
  146. package/src/solid/tabs.tsx +12 -6
  147. package/src/solid/term.tsx +3 -4
  148. package/src/solid/toggle-group.tsx +34 -101
  149. package/src/solid/toggle.tsx +43 -9
  150. package/src/solid/tooltip.tsx +24 -24
  151. package/src/styles/globals.css +61 -50
  152. package/src/styles/theme.css +12 -6
  153. package/src/tokens/material.ts +11 -2
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type ComponentProps,
3
3
  createContext,
4
+ createSignal,
4
5
  type JSX,
5
6
  onCleanup,
6
7
  onMount,
@@ -8,26 +9,50 @@ import {
8
9
  splitProps,
9
10
  useContext,
10
11
  } from "solid-js";
12
+ import { effect } from "../lib/behavior/solid.js";
11
13
  import { cn } from "../lib/utils.js";
12
14
 
13
15
  /** The attribute (without `data-`) that marks the active item: Kobalte's, or the caller's own. */
14
16
  export type SelectionMarker = "pressed" | "selected" | "highlighted" | "lit";
15
17
 
16
- const SelectionContext = createContext<SelectionMarker>();
18
+ interface SelectionContextValue {
19
+ marker: SelectionMarker;
20
+ report: (item: HTMLElement, active: boolean) => void;
21
+ watchMarker: () => void;
22
+ }
23
+
24
+ const SelectionContext = createContext<SelectionContextValue>();
17
25
 
18
26
  /**
19
27
  * The glass behind an item while it is the active one. Render it as the first child of every
20
28
  * item inside a `SelectionScope`; CSS shows the one whose item carries the scope's marker, so
21
29
  * layout keeps it in place and nothing measures it at rest. Renders nothing outside a scope.
30
+ * Pass `active` when the item knows it carries the marker; without it the scope watches the
31
+ * marker attribute instead, which costs a MutationObserver.
22
32
  */
23
- export function SelectionHighlight() {
24
- const marker = useContext(SelectionContext);
33
+ export function SelectionHighlight(props: { active?: boolean }) {
34
+ const scope = useContext(SelectionContext);
35
+ let span: HTMLSpanElement | undefined;
36
+ const [item, setItem] = createSignal<HTMLElement>();
37
+ onMount(() => setItem(span?.parentElement ?? undefined));
38
+ if (scope && props.active === undefined) scope.watchMarker();
39
+ effect(
40
+ () => [item(), props.active] as const,
41
+ ([item, active]) => {
42
+ if (!scope || !item || active === undefined) return;
43
+ scope.report(item, active);
44
+ return () => {
45
+ if (active) scope.report(item, false);
46
+ };
47
+ },
48
+ );
25
49
  return (
26
- <Show when={marker}>
50
+ <Show when={scope}>
27
51
  {(on) => (
28
52
  <span
53
+ ref={span}
29
54
  data-selection-highlight=""
30
- data-on={on()}
55
+ data-on={on().marker}
31
56
  data-sliding-indicator=""
32
57
  aria-hidden="true"
33
58
  class="glass glass-tint"
@@ -37,7 +62,6 @@ export function SelectionHighlight() {
37
62
  );
38
63
  }
39
64
 
40
- const DEFAULT_DURATION_MS = 220;
41
65
  // Kobalte clears a menu row's highlight on pointerleave and sets the next on pointermove.
42
66
  const GAP_MS = 100;
43
67
  // Squash-and-stretch as a pixel budget per axis, so a big item does not deform more.
@@ -48,19 +72,25 @@ const DEFORM_MAX = 0.14;
48
72
  /** Centre and size in the scope's own content pixels. */
49
73
  type Box = { x: number; y: number; width: number; height: number };
50
74
 
51
- function durationMs(root: HTMLElement): number {
52
- const raw = getComputedStyle(root).getPropertyValue("--duration-slide").trim();
53
- if (!raw) return DEFAULT_DURATION_MS;
54
- const value = Number.parseFloat(raw);
55
- if (Number.isNaN(value)) return DEFAULT_DURATION_MS;
56
- return raw.endsWith("ms") ? value : value * 1000;
75
+ /** The root's place on screen and its scale, which a transformed ancestor sets. */
76
+ function frameOf(root: HTMLElement) {
77
+ const outer = root.getBoundingClientRect();
78
+ const width = root.offsetWidth;
79
+ const height = root.offsetHeight;
80
+ return {
81
+ outer,
82
+ sx: width > 0 ? outer.width / width : 1,
83
+ sy: height > 0 ? outer.height / height : 1,
84
+ };
57
85
  }
58
86
 
59
- function boxIn(root: HTMLElement, el: Element, size: { width: number; height: number }): Box {
60
- const outer = root.getBoundingClientRect();
61
- const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
62
- const sy = root.offsetHeight > 0 ? outer.height / root.offsetHeight : 1;
63
- const rect = el.getBoundingClientRect();
87
+ function boxIn(
88
+ root: HTMLElement,
89
+ rect: DOMRect,
90
+ size: { width: number; height: number },
91
+ frame = frameOf(root),
92
+ ): Box {
93
+ const { outer, sx, sy } = frame;
64
94
  return {
65
95
  x: (rect.left + rect.width / 2 - outer.left) / sx - root.clientLeft + root.scrollLeft,
66
96
  y: (rect.top + rect.height / 2 - outer.top) / sy - root.clientTop + root.scrollTop,
@@ -71,16 +101,27 @@ function boxIn(root: HTMLElement, el: Element, size: { width: number; height: nu
71
101
 
72
102
  function itemBox(root: HTMLElement, item: HTMLElement): Box | undefined {
73
103
  if (!item.isConnected) return undefined;
74
- const box = boxIn(root, item, { width: item.offsetWidth, height: item.offsetHeight });
104
+ const size = { width: item.offsetWidth, height: item.offsetHeight };
105
+ const box = boxIn(root, item.getBoundingClientRect(), size);
75
106
  return box.width > 0 && box.height > 0 ? box : undefined;
76
107
  }
77
108
 
109
+ /** Whether the box shows inside the root's scrollport; a highlight never flies in from out of sight. */
110
+ function inSight(root: HTMLElement, box: Box): boolean {
111
+ const top = root.scrollTop;
112
+ const left = root.scrollLeft;
113
+ return (
114
+ box.y + box.height / 2 > top &&
115
+ box.y - box.height / 2 < top + root.clientHeight &&
116
+ box.x + box.width / 2 > left &&
117
+ box.x - box.width / 2 < left + root.clientWidth
118
+ );
119
+ }
120
+
78
121
  function flyerBox(root: HTMLElement, flyer: HTMLElement): Box {
79
- const outer = root.getBoundingClientRect();
80
- const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
81
- const sy = root.offsetHeight > 0 ? outer.height / root.offsetHeight : 1;
122
+ const frame = frameOf(root);
82
123
  const rect = flyer.getBoundingClientRect();
83
- return boxIn(root, flyer, { width: rect.width / sx, height: rect.height / sy });
124
+ return boxIn(root, rect, { width: rect.width / frame.sx, height: rect.height / frame.sy }, frame);
84
125
  }
85
126
 
86
127
  function highlightOf(item: Element): Element | null {
@@ -99,47 +140,46 @@ function writeStyle(el: HTMLElement, name: string, value: string) {
99
140
  if (el.style.getPropertyValue(name) !== value) el.style.setProperty(name, value);
100
141
  }
101
142
 
102
- /** One flight at a time; every way a flight ends goes through `settle`. */
103
- function createFlight(root: HTMLElement, flyer: HTMLElement) {
104
- let generation = 0;
105
- let running: Animation[] = [];
143
+ /** The corner and tone the flyer takes from its target, without asking the page for a style. */
144
+ function lookOf(item: HTMLElement, radius: string | undefined) {
145
+ if (radius === undefined) {
146
+ const look = getComputedStyle(item);
147
+ return {
148
+ radius: look.borderRadius,
149
+ tone: look.getPropertyValue("--selection-tone").trim(),
150
+ };
151
+ }
152
+ return { radius, tone: item.style.getPropertyValue("--selection-tone").trim() };
153
+ }
154
+
155
+ /**
156
+ * One flight at a time, run by CSS keyframes on the token duration; every way a flight ends goes
157
+ * through `settle`. Each flight flips the phase, so a new flight restarts the keyframes.
158
+ */
159
+ function createFlight(root: HTMLElement, flyer: HTMLElement, radius: () => string | undefined) {
160
+ let phase: "a" | "b" = "b";
106
161
  let landing: Element | undefined;
107
162
 
108
- const stop = () => {
109
- for (const animation of running) animation.cancel();
110
- running = [];
163
+ const settle = () => {
111
164
  landing?.removeAttribute("data-landing");
112
165
  landing = undefined;
166
+ flyer.removeAttribute("data-flying");
113
167
  };
114
168
 
115
- const settle = (of = generation) => {
116
- if (of !== generation) return;
117
- stop();
118
- flyer.removeAttribute("data-flying");
169
+ const ended = (event: AnimationEvent) => {
170
+ if (event.animationName === `selection-glide-${phase}`) settle();
119
171
  };
172
+ flyer.addEventListener("animationend", ended);
173
+ flyer.addEventListener("animationcancel", ended);
120
174
 
121
175
  const start = (from: Box, item: HTMLElement) => {
122
- generation += 1;
123
- const current = generation;
124
- stop();
125
176
  const target = highlightOf(item);
126
177
  const to = itemBox(root, item);
127
- const duration = durationMs(root);
128
- if (!target || !to || duration <= 0) return settle(current);
178
+ if (!target || !to) return settle();
129
179
 
130
- // Read before any write: a computed border-radius after a size write forces a second layout.
131
- const look = getComputedStyle(item);
132
- const radius = look.borderRadius;
133
- const tone = look.getPropertyValue("--selection-tone").trim();
180
+ const look = lookOf(item, radius());
134
181
  const left = to.x - to.width / 2;
135
182
  const top = to.y - to.height / 2;
136
- const rest = `${left}px ${top}px`;
137
- writeStyle(flyer, "width", `${to.width}px`);
138
- writeStyle(flyer, "height", `${to.height}px`);
139
- writeStyle(flyer, "translate", rest);
140
- writeStyle(flyer, "--selection-radius", radius);
141
- writeStyle(flyer, "--selection-tone", tone);
142
-
143
183
  const dx = from.x - to.x;
144
184
  const dy = from.y - to.y;
145
185
  const kx = from.width / to.width;
@@ -154,23 +194,20 @@ function createFlight(root: HTMLElement, flyer: HTMLElement) {
154
194
  peakY *= alongX ? pinch : stretch;
155
195
  }
156
196
 
197
+ writeStyle(flyer, "width", `${to.width}px`);
198
+ writeStyle(flyer, "height", `${to.height}px`);
199
+ writeStyle(flyer, "translate", `${left}px ${top}px`);
200
+ writeStyle(flyer, "--selection-radius", look.radius);
201
+ writeStyle(flyer, "--selection-tone", look.tone);
202
+ writeStyle(flyer, "--selection-from", `${left + dx}px ${top + dy}px`);
203
+ writeStyle(flyer, "--selection-scale-from", `${kx} ${ky}`);
204
+ writeStyle(flyer, "--selection-scale-peak", `${peakX} ${peakY}`);
205
+
206
+ landing?.removeAttribute("data-landing");
157
207
  landing = target;
158
208
  target.setAttribute("data-landing", "");
159
- flyer.setAttribute("data-flying", "");
160
- const timing: KeyframeAnimationOptions = { duration, easing: "ease-in-out" };
161
- const end = () => settle(current);
162
- try {
163
- running = [
164
- flyer.animate([{ translate: `${left + dx}px ${top + dy}px` }, { translate: rest }], timing),
165
- flyer.animate(
166
- [{ scale: `${kx} ${ky}` }, { scale: `${peakX} ${peakY}` }, { scale: "1 1" }],
167
- timing,
168
- ),
169
- ];
170
- } catch {
171
- return end();
172
- }
173
- Promise.all(running.map((animation) => animation.finished)).then(end, end);
209
+ phase = phase === "a" ? "b" : "a";
210
+ flyer.setAttribute("data-flying", phase);
174
211
  };
175
212
 
176
213
  return { settle, start, flying: () => flyer.hasAttribute("data-flying") };
@@ -180,6 +217,11 @@ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
180
217
  marker: SelectionMarker;
181
218
  /** CSS colour for the highlight's glass. Default `var(--material-accent)`. */
182
219
  tone?: string;
220
+ /**
221
+ * The items' corner radius as CSS, which the flyer takes in flight. Without it the scope reads
222
+ * each target's computed corner and tone per flight; that read goes in 2.0.0, where it is required.
223
+ */
224
+ radius?: string;
183
225
  style?: JSX.CSSProperties;
184
226
  }
185
227
 
@@ -188,7 +230,15 @@ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
188
230
  * one flyer animates from the old item to the new one and hands off to its resting highlight.
189
231
  */
190
232
  export function SelectionScope(props: SelectionScopeProps) {
191
- const [local, rest] = splitProps(props, ["marker", "tone", "class", "style", "children", "ref"]);
233
+ const [local, rest] = splitProps(props, [
234
+ "marker",
235
+ "tone",
236
+ "radius",
237
+ "class",
238
+ "style",
239
+ "children",
240
+ "ref",
241
+ ]);
192
242
  let root: HTMLDivElement | undefined;
193
243
  let flyer: HTMLSpanElement | undefined;
194
244
  const setRoot = (el: HTMLDivElement) => {
@@ -197,17 +247,40 @@ export function SelectionScope(props: SelectionScopeProps) {
197
247
  if (typeof forwarded === "function") forwarded(el);
198
248
  };
199
249
 
250
+ let move: ((next: HTMLElement | undefined) => void) | undefined;
251
+ let watching = false;
252
+ let watch: (() => void) | undefined;
253
+ const reported = new Set<HTMLElement>();
254
+ let queued = false;
255
+ // Decides after the task that changed the marker, which may still scroll the new item into view.
256
+ const report = (item: HTMLElement, active: boolean) => {
257
+ if (active) {
258
+ reported.delete(item);
259
+ reported.add(item);
260
+ } else if (!reported.delete(item)) return;
261
+ if (queued) return;
262
+ queued = true;
263
+ queueMicrotask(() => {
264
+ queued = false;
265
+ move?.([...reported].at(-1));
266
+ });
267
+ };
268
+ const watchMarker = () => {
269
+ if (watching) return;
270
+ watching = true;
271
+ watch?.();
272
+ };
273
+
200
274
  onMount(() => {
201
275
  const scope = root;
202
276
  const travel = flyer;
203
277
  if (!scope || !travel) return;
204
278
  const attribute = `data-${local.marker}`;
205
- const flight = createFlight(scope, travel);
206
- let active = activeIn(scope, attribute);
279
+ const flight = createFlight(scope, travel, () => local.radius);
280
+ let active = [...reported].at(-1) ?? activeIn(scope, attribute);
207
281
  let left: { item: HTMLElement; box: Box | undefined; at: number } | undefined;
208
282
 
209
- const observer = new MutationObserver(() => {
210
- const next = activeIn(scope, attribute);
283
+ move = (next) => {
211
284
  if (next === active) return;
212
285
  const previous = active;
213
286
  active = next;
@@ -228,12 +301,20 @@ export function SelectionScope(props: SelectionScopeProps) {
228
301
  : recent
229
302
  ? (recent.box ?? itemBox(scope, recent.item))
230
303
  : undefined;
231
- if (from) flight.start(from, next);
304
+ if (from && inSight(scope, from)) flight.start(from, next);
232
305
  else flight.settle();
233
- });
234
- observer.observe(scope, { subtree: true, attributes: true, attributeFilter: [attribute] });
306
+ };
307
+
308
+ let observer: MutationObserver | undefined;
309
+ watch = () => {
310
+ observer = new MutationObserver(() => move?.(activeIn(scope, attribute)));
311
+ observer.observe(scope, { subtree: true, attributes: true, attributeFilter: [attribute] });
312
+ };
313
+ if (watching) watch();
235
314
  onCleanup(() => {
236
- observer.disconnect();
315
+ observer?.disconnect();
316
+ move = undefined;
317
+ watch = undefined;
237
318
  flight.settle();
238
319
  });
239
320
  });
@@ -246,7 +327,17 @@ export function SelectionScope(props: SelectionScopeProps) {
246
327
  style={local.tone ? { ...local.style, "--selection-tone": local.tone } : local.style}
247
328
  {...rest}
248
329
  >
249
- <SelectionContext.Provider value={local.marker}>{local.children}</SelectionContext.Provider>
330
+ <SelectionContext.Provider
331
+ value={{
332
+ get marker() {
333
+ return local.marker;
334
+ },
335
+ report,
336
+ watchMarker,
337
+ }}
338
+ >
339
+ {local.children}
340
+ </SelectionContext.Provider>
250
341
  <span
251
342
  ref={flyer}
252
343
  data-selection-flyer=""
@@ -75,7 +75,7 @@ const SHEET_SIDE = {
75
75
  "data-[closed]:slide-out-to-right data-[expanded]:slide-in-from-right inset-y-3 right-3 w-3/4 sm:max-w-sm",
76
76
  left: "data-[closed]:slide-out-to-left data-[expanded]:slide-in-from-left inset-y-3 left-3 w-3/4 sm:max-w-sm",
77
77
  top: `data-[closed]:slide-out-to-top data-[expanded]:slide-in-from-top inset-x-3 top-3 ${MODAL_MAX_H}`,
78
- /** @deprecated a modal from the bottom is `BottomSheet` / `ResponsiveDialog`. */
78
+ /** @deprecated `BottomSheet` or `ResponsiveDialog`; removed in 2.0.0. */
79
79
  bottom: `data-[closed]:slide-out-to-bottom data-[expanded]:slide-in-from-bottom inset-x-3 bottom-3 ${MODAL_MAX_H}`,
80
80
  } as const;
81
81
 
@@ -1,7 +1,9 @@
1
- import { Slider as KSlider } from "@kobalte/core/slider";
2
1
  import type { Component } from "solid-js";
3
- import { Index, splitProps } from "solid-js";
2
+ import { createMemo, createSignal, For } from "solid-js";
3
+ import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
4
+ import { alongTrack, createDrag, createRange } from "../lib/behavior/range.js";
4
5
  import { FIELD_CHROME, FOCUS_RING } from "../lib/input-classes.js";
6
+ import { locale, readingDirection } from "../lib/locale.js";
5
7
  import { THUMB_CLASS, THUMB_RAIL_BLEED, THUMB_RAIL_PAD } from "../lib/thumb-classes.js";
6
8
  import { cn } from "../lib/utils.js";
7
9
 
@@ -32,118 +34,166 @@ interface SliderProps {
32
34
  "aria-labelledby"?: string;
33
35
  }
34
36
 
37
+ const decimal = new Intl.NumberFormat(locale, { style: "decimal" });
38
+ const rtl = readingDirection === "rtl";
39
+ const START = rtl ? "right" : "left";
40
+ const END = rtl ? "left" : "right";
41
+ const THUMB_SHIFT = rtl ? "translateX(50%)" : "translateX(-50%)";
42
+
35
43
  const Slider: Component<SliderProps> = (props) => {
36
- const [local] = splitProps(props, [
37
- "value",
38
- "defaultValue",
39
- "min",
40
- "max",
41
- "step",
42
- "disabled",
43
- "onChange",
44
- "onChangeEnd",
45
- "class",
46
- "trackClass",
47
- "thumbClass",
48
- "thumbColors",
49
- "fillTone",
50
- "markers",
51
- "minStepsBetweenThumbs",
52
- "aria-label",
53
- "aria-labelledby",
54
- ]);
44
+ const min = () => props.min ?? 0;
45
+ const max = () => props.max ?? 100;
46
+ const disabled = () => props.disabled ?? false;
47
+ const range = createRange({
48
+ values: () => props.value,
49
+ defaultValues: () => props.defaultValue ?? [min()],
50
+ min,
51
+ max,
52
+ step: () => props.step ?? 1,
53
+ minStepsBetween: () => props.minStepsBetweenThumbs ?? 0,
54
+ disabled,
55
+ onChange: (values) => props.onChange?.(values),
56
+ onChangeEnd: (values) => props.onChangeEnd?.(values),
57
+ });
58
+ const indices = createMemo(() => range.values().map((_, i) => i), [], {
59
+ equals: (a, b) => a.length === b.length,
60
+ });
61
+ const percents = () => range.values().map((v) => range.fraction(v) * 100);
62
+ const [thumbs, setThumbs] = createSignal<HTMLElement[]>([]);
63
+ let active = 0;
64
+ let grab = 0;
65
+
66
+ const drag = createDrag({
67
+ disabled,
68
+ start: (e, rect) => {
69
+ const thumb = (e.target as Element).closest('[data-slot="slider-thumb"]');
70
+ const pressed = thumbs().findIndex((el) => el === thumb);
71
+ const at = alongTrack(e, rect);
72
+ if (pressed >= 0) {
73
+ active = pressed;
74
+ grab = at - range.fraction(range.values()[pressed] ?? 0);
75
+ } else {
76
+ const raw = min() + at * (max() - min());
77
+ grab = 0;
78
+ active = range.closestThumb(raw);
79
+ range.setThumb(active, raw);
80
+ }
81
+ focusWithoutTracking(thumbs()[active]);
82
+ },
83
+ move: (e, rect) => range.setThumb(active, range.valueAt(alongTrack(e, rect) - grab)),
84
+ end: range.dragEnd,
85
+ });
55
86
 
56
87
  const markerPct = (v: number) => {
57
- const min = local.min ?? 0;
58
- const max = local.max ?? 100;
59
- return max === min ? 0 : ((v - min) / (max - min)) * 100;
88
+ const span = max() - min();
89
+ return span === 0 ? 0 : ((v - min()) / span) * 100;
60
90
  };
61
91
 
92
+ const disabledMark = () => (disabled() ? "" : undefined);
93
+
62
94
  return (
63
- <KSlider
64
- value={local.value}
65
- defaultValue={local.defaultValue}
66
- minValue={local.min ?? 0}
67
- maxValue={local.max ?? 100}
68
- step={local.step ?? 1}
69
- minStepsBetweenThumbs={local.minStepsBetweenThumbs}
70
- disabled={local.disabled}
71
- onChange={local.onChange}
72
- onChangeEnd={local.onChangeEnd}
95
+ <div
96
+ role="group"
73
97
  data-slot="slider"
98
+ data-orientation="horizontal"
99
+ data-disabled={disabledMark()}
74
100
  class={cn(
75
101
  // The rail wears the shared toggle/rail chrome, so it reads as an empty
76
102
  // well in both themes (a field's light-theme fill rises to the card).
77
103
  "relative flex w-full touch-none items-center rounded-xl select-none",
78
104
  THUMB_RAIL_PAD,
79
105
  FIELD_CHROME,
80
- local.disabled && "cursor-not-allowed opacity-50",
81
- local.class,
106
+ disabled() && "cursor-not-allowed opacity-50",
107
+ props.class,
82
108
  )}
83
109
  >
84
- <KSlider.Track
110
+ <div
85
111
  data-slot="slider-track"
112
+ data-orientation="horizontal"
113
+ data-disabled={disabledMark()}
86
114
  class={cn(
87
115
  "relative h-7 w-full",
88
- local.disabled ? "cursor-not-allowed" : "cursor-pointer",
89
- local.trackClass,
116
+ disabled() ? "cursor-not-allowed" : "cursor-pointer",
117
+ props.trackClass,
90
118
  )}
119
+ on:pointerdown={drag.onPointerDown}
120
+ on:pointermove={drag.onPointerMove}
121
+ on:pointerup={drag.onPointerUp}
122
+ on:pointercancel={drag.onPointerCancel}
91
123
  >
92
- <KSlider.Fill
124
+ <div
93
125
  data-slot="slider-fill"
126
+ data-orientation="horizontal"
127
+ data-disabled={disabledMark()}
94
128
  class={cn(
95
129
  // The fill sits sunk inside the recessed rail: the tinted-surface
96
130
  // outer drop shadow would read as a halo leaking out of the groove.
97
131
  "glass glass-tint absolute inset-y-0 rounded-xl [--glass-drop:0%] [--glass-wash:90%]",
98
132
  THUMB_RAIL_BLEED,
99
- Array.isArray(local.fillTone) && "glass-edge-gradient",
133
+ Array.isArray(props.fillTone) && "glass-edge-gradient",
100
134
  )}
101
- style={
102
- Array.isArray(local.fillTone)
135
+ style={{
136
+ [START]: `${percents().length > 1 ? Math.min(...percents()) : 0}%`,
137
+ [END]: `${100 - Math.max(...percents())}%`,
138
+ ...(Array.isArray(props.fillTone)
103
139
  ? {
104
- "--glass-tone": local.fillTone[0],
105
- "--glass-tone-2": local.fillTone[1],
140
+ "--glass-tone": props.fillTone[0],
141
+ "--glass-tone-2": props.fillTone[1],
106
142
  "--glass-wash-2": "var(--glass-wash)",
107
143
  "--glass-wash-angle": "90deg",
108
144
  }
109
- : { "--glass-tone": local.fillTone ?? "var(--material-accent)" }
110
- }
145
+ : { "--glass-tone": props.fillTone ?? "var(--material-accent)" }),
146
+ }}
111
147
  />
112
- <Index each={local.markers ?? []}>
148
+ <For each={props.markers ?? []}>
113
149
  {(marker) => (
114
150
  <span
115
151
  data-slot="slider-marker"
116
152
  class="pointer-events-none absolute top-1/2 h-3 w-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full"
117
153
  style={{
118
- left: `${markerPct(marker())}%`,
154
+ left: `${markerPct(marker)}%`,
119
155
  background: "color-mix(in oklab, var(--foreground) 60%, transparent)",
120
156
  }}
121
157
  />
122
158
  )}
123
- </Index>
124
- <Index each={local.value ?? local.defaultValue ?? [0]}>
125
- {(_, thumbIndex) => (
126
- <KSlider.Thumb
159
+ </For>
160
+ <For each={indices()}>
161
+ {(index) => (
162
+ <span
163
+ ref={(el) => setThumbs((all) => Object.assign(all.slice(), { [index]: el }))}
164
+ role="slider"
127
165
  data-slot="slider-thumb"
166
+ data-orientation="horizontal"
167
+ data-disabled={disabledMark()}
168
+ tabIndex={disabled() ? undefined : 0}
169
+ aria-label={props["aria-label"]}
170
+ aria-labelledby={props["aria-labelledby"]}
171
+ aria-valuemin={min()}
172
+ aria-valuemax={max()}
173
+ aria-valuenow={range.values()[index]}
174
+ aria-valuetext={decimal.format(range.values()[index] ?? 0)}
175
+ aria-orientation="horizontal"
176
+ aria-disabled={disabled() || undefined}
128
177
  class={cn(
129
178
  THUMB_CLASS,
130
179
  FOCUS_RING,
131
- "absolute top-0 transition-transform duration-200 ease-out hover:scale-125 active:scale-110",
132
- local.disabled && "cursor-not-allowed",
133
- local.thumbClass,
180
+ "absolute top-0 transition-transform duration-(--duration-expand) ease-out hover:scale-125 active:scale-110",
181
+ disabled() && "cursor-not-allowed",
182
+ props.thumbClass,
134
183
  )}
135
- aria-label={local["aria-label"]}
136
- aria-labelledby={local["aria-labelledby"]}
137
184
  style={{
138
- background: local.thumbColors?.[thumbIndex] ?? "var(--material-control-knob)",
185
+ [START]: `calc(${percents()[index] ?? 0}%)`,
186
+ transform: THUMB_SHIFT,
187
+ "touch-action": "none",
188
+ background: props.thumbColors?.[index] ?? "var(--material-control-knob)",
139
189
  }}
140
- >
141
- <KSlider.Input />
142
- </KSlider.Thumb>
190
+ on:keydown={(e) => range.keyDown(e, index)}
191
+ onBlur={range.blur}
192
+ />
143
193
  )}
144
- </Index>
145
- </KSlider.Track>
146
- </KSlider>
194
+ </For>
195
+ </div>
196
+ </div>
147
197
  );
148
198
  };
149
199
 
@@ -19,13 +19,6 @@ function samePos(a: Pos, b: Pos): boolean {
19
19
  );
20
20
  }
21
21
 
22
- function readTranslate(el: HTMLElement): [number, number] {
23
- const t = getComputedStyle(el).translate;
24
- if (!t || t === "none") return [0, 0];
25
- const [x = "0", y = "0"] = t.split(" ");
26
- return [Number.parseFloat(x) || 0, Number.parseFloat(y) || 0];
27
- }
28
-
29
22
  /**
30
23
  * The sliding "moving background": a tinted indicator that measures the active item
31
24
  * among its children and animates its position/size behind it. Reusable across
@@ -75,7 +68,7 @@ const STRETCH_PX = 6; // grow along travel
75
68
  const SQUASH_PX = 6; // pinch perpendicular
76
69
  const DEFORM_MAX = 0.14;
77
70
 
78
- /** @deprecated Use `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0. */
71
+ /** @deprecated `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0.0. */
79
72
  export function SlidingIndicator(props: SlidingIndicatorProps) {
80
73
  const [local, rest] = splitProps(props, [
81
74
  "active",
@@ -185,26 +178,21 @@ export function SlidingIndicator(props: SlidingIndicatorProps) {
185
178
  // not just a direct child. Add the container's own scroll so the indicator,
186
179
  // which scrolls with the content, lands at the content offset; subtract the
187
180
  // border so it aligns to the padding box (where the absolute indicator anchors).
188
- // A row arriving through gh-stagger is still translated: bounding rects
189
- // include that travel, its resting place does not.
190
181
  // An ancestor mid-zoom (a dialog opening) scales every rect and ends without
191
182
  // a resize, so rects convert back to layout pixels by the container's ratio.
192
183
  const sx = containerRef.offsetWidth > 0 ? cr.width / containerRef.offsetWidth : 1;
193
184
  const sy = containerRef.offsetHeight > 0 ? cr.height / containerRef.offsetHeight : 1;
194
- const [tx, ty] = readTranslate(el);
195
185
  place(
196
186
  el,
197
187
  horizontal()
198
188
  ? {
199
- offset:
200
- (er.left - cr.left) / sx - tx - containerRef.clientLeft + containerRef.scrollLeft,
189
+ offset: (er.left - cr.left) / sx - containerRef.clientLeft + containerRef.scrollLeft,
201
190
  size: er.width / sx,
202
191
  cross: er.height / sy,
203
- crossOffset:
204
- (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
192
+ crossOffset: (er.top - cr.top) / sy - containerRef.clientTop + containerRef.scrollTop,
205
193
  }
206
194
  : {
207
- offset: (er.top - cr.top) / sy - ty - containerRef.clientTop + containerRef.scrollTop,
195
+ offset: (er.top - cr.top) / sy - containerRef.clientTop + containerRef.scrollTop,
208
196
  size: er.height / sy,
209
197
  cross: er.width / sx,
210
198
  crossOffset: 0,