@zonsh/ui 0.4.1 → 0.5.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 (67) hide show
  1. package/dist/components/accordion.js +1 -1
  2. package/dist/components/ascii-field.js +2 -1
  3. package/dist/components/bottom-nav.js +4 -4
  4. package/dist/components/button.js +1 -1
  5. package/dist/components/chart.d.ts +11 -0
  6. package/dist/components/chart.js +12 -0
  7. package/dist/components/collapsible.js +1 -1
  8. package/dist/components/command.js +3 -3
  9. package/dist/components/conversation.js +10 -3
  10. package/dist/components/copy-button.js +7 -5
  11. package/dist/components/graph.js +24 -7
  12. package/dist/components/illustration.js +50 -3
  13. package/dist/components/input-group.d.ts +2 -2
  14. package/dist/components/input-group.js +6 -4
  15. package/dist/components/input.d.ts +1 -1
  16. package/dist/components/input.js +1 -1
  17. package/dist/components/layout.d.ts +2 -1
  18. package/dist/components/layout.js +55 -11
  19. package/dist/components/lightbox.js +22 -4
  20. package/dist/components/menubar.js +60 -13
  21. package/dist/components/message.js +3 -2
  22. package/dist/components/navigation-menu.js +4 -2
  23. package/dist/components/number-field.js +26 -12
  24. package/dist/components/pagination.js +1 -1
  25. package/dist/components/prompt-input.js +14 -6
  26. package/dist/components/radio-group.js +7 -2
  27. package/dist/components/reasoning.js +1 -1
  28. package/dist/components/response.d.ts +3 -2
  29. package/dist/components/response.js +22 -10
  30. package/dist/components/sidebar.js +37 -18
  31. package/dist/components/site-header.js +6 -1
  32. package/dist/components/skeleton.d.ts +1 -1
  33. package/dist/components/skeleton.js +1 -1
  34. package/dist/components/sortable.js +61 -37
  35. package/dist/components/table.d.ts +1 -1
  36. package/dist/components/table.js +55 -2
  37. package/dist/components/tabs.js +8 -4
  38. package/dist/components/tags-input.js +1 -1
  39. package/dist/components/theme.d.ts +1 -1
  40. package/dist/components/theme.js +21 -3
  41. package/dist/components/time-field.d.ts +2 -1
  42. package/dist/components/time-field.js +13 -3
  43. package/dist/components/toggle-group.js +1 -0
  44. package/dist/components/tool-call.js +6 -1
  45. package/dist/components/toolbar.d.ts +1 -1
  46. package/dist/components/toolbar.js +5 -2
  47. package/dist/components/tooltip.d.ts +4 -2
  48. package/dist/components/tooltip.js +10 -4
  49. package/dist/components/tour.js +35 -10
  50. package/dist/components/tree.js +29 -6
  51. package/dist/components/video-player.js +61 -5
  52. package/dist/lib/glide.d.ts +5 -4
  53. package/dist/lib/glide.js +5 -4
  54. package/dist/lib/table-fit.d.ts +3 -2
  55. package/dist/lib/table-fit.js +29 -19
  56. package/dist/styles/expressive.css +40 -21
  57. package/dist/styles/index.css +8 -0
  58. package/dist/styles/material.css +40 -20
  59. package/dist/styles/parts/ai.css +2 -1
  60. package/dist/styles/parts/controls.css +24 -20
  61. package/dist/styles/parts/data.css +33 -5
  62. package/dist/styles/parts/feedback.css +43 -13
  63. package/dist/styles/parts/navigation.css +42 -9
  64. package/dist/styles/parts/overlays.css +93 -6
  65. package/dist/styles/parts/pdf.css +13 -7
  66. package/dist/styles/tokens.css +16 -1
  67. package/package.json +1 -1
@@ -68,7 +68,7 @@ const LONG_PRESS = 400;
68
68
  const TOUCH_SLOP = 8;
69
69
  /** Within this many pixels of a scrolling edge, a drag scrolls it. */
70
70
  const EDGE = 56;
71
- /** The fastest autoscroll, in pixels a frame, right at the edge. */
71
+ /** The fastest autoscroll, right at the edge: pixels per 16ms (a 60Hz frame). */
72
72
  const SPEED = 14;
73
73
  /** A release this far past the root's edge still lands in the nearest list; further out it cancels. */
74
74
  const DROP_MARGIN = 32;
@@ -192,53 +192,65 @@ function flip(els, before) {
192
192
  el.style.translate = "";
193
193
  });
194
194
  }
195
+ /**
196
+ * The containers that could scroll from `from` outwards to the page, read once when a drag
197
+ * starts: their overflow does not change mid-drag, and reading every ancestor's style each frame
198
+ * would cost a style read per ancestor per frame.
199
+ */
200
+ function scrollersOf(from) {
201
+ const page = document.scrollingElement ?? document.documentElement;
202
+ const chain = [];
203
+ for (let el = from; el; el = el.parentElement) {
204
+ if (el === page || el === document.body)
205
+ break;
206
+ const style = getComputedStyle(el);
207
+ const x = /auto|scroll/.test(style.overflowX);
208
+ const y = /auto|scroll/.test(style.overflowY);
209
+ if (x || y)
210
+ chain.push({ el, page: false, x, y });
211
+ }
212
+ chain.push({ el: page, page: true, x: true, y: true });
213
+ return chain;
214
+ }
195
215
  /**
196
216
  * Scroll whatever scrolls under the pointer while it is held near an edge: the innermost
197
- * container, from the list outwards to the page, that can still move that way.
217
+ * container, from the list outwards to the page, that can still move that way. The speed is per
218
+ * millisecond, by the time since the last frame (at most 32ms), so it is the same at 60 and 120Hz.
198
219
  */
199
- function autoScroll(from, x, y) {
220
+ function autoScroll(scrollers, x, y, dt) {
200
221
  let doneX = false;
201
222
  let doneY = false;
202
- const page = document.scrollingElement ?? document.documentElement;
203
- for (let el = from; el && !(doneX && doneY); el = el.parentElement) {
204
- const isPage = el === page || el === document.body;
205
- const style = getComputedStyle(el);
206
- const rect = isPage
207
- ? new DOMRect(0, 0, window.innerWidth, window.innerHeight)
208
- : el.getBoundingClientRect();
209
- const target = isPage ? page : el;
210
- const step = (low, high, size) => {
211
- const edge = Math.min(EDGE, size / 4);
212
- if (low < edge)
213
- return -Math.ceil(SPEED * (1 - Math.max(low, 0) / edge));
214
- if (high < edge)
215
- return Math.ceil(SPEED * (1 - Math.max(high, 0) / edge));
216
- return 0;
217
- };
218
- if (!doneX &&
219
- (isPage || /auto|scroll/.test(style.overflowX)) &&
220
- target.scrollWidth > target.clientWidth) {
223
+ const step = (low, high, size) => {
224
+ const edge = Math.min(EDGE, size / 4);
225
+ const speed = (SPEED / 16) * dt;
226
+ if (low < edge)
227
+ return -Math.ceil(speed * (1 - Math.max(low, 0) / edge));
228
+ if (high < edge)
229
+ return Math.ceil(speed * (1 - Math.max(high, 0) / edge));
230
+ return 0;
231
+ };
232
+ for (const { el, page, x: canX, y: canY } of scrollers) {
233
+ if (doneX && doneY)
234
+ break;
235
+ const rect = page ? new DOMRect(0, 0, window.innerWidth, window.innerHeight) : el.getBoundingClientRect();
236
+ if (!doneX && canX && el.scrollWidth > el.clientWidth) {
221
237
  const dx = step(x - rect.left, rect.right - x, rect.width);
222
238
  if (dx) {
223
- const before = target.scrollLeft;
224
- target.scrollLeft += dx;
225
- if (target.scrollLeft !== before)
239
+ const before = el.scrollLeft;
240
+ el.scrollLeft += dx;
241
+ if (el.scrollLeft !== before)
226
242
  doneX = true;
227
243
  }
228
244
  }
229
- if (!doneY &&
230
- (isPage || /auto|scroll/.test(style.overflowY)) &&
231
- target.scrollHeight > target.clientHeight) {
245
+ if (!doneY && canY && el.scrollHeight > el.clientHeight) {
232
246
  const dy = step(y - rect.top, rect.bottom - y, rect.height);
233
247
  if (dy) {
234
- const before = target.scrollTop;
235
- target.scrollTop += dy;
236
- if (target.scrollTop !== before)
248
+ const before = el.scrollTop;
249
+ el.scrollTop += dy;
250
+ if (el.scrollTop !== before)
237
251
  doneY = true;
238
252
  }
239
253
  }
240
- if (isPage)
241
- break;
242
254
  }
243
255
  }
244
256
  /**
@@ -619,6 +631,10 @@ export function Sortable({ value: valueProp, defaultValue, onValueChange, onMove
619
631
  let active = false;
620
632
  let frame = 0;
621
633
  let timer = 0;
634
+ /** The last frame's time, for the autoscroll's speed per millisecond. */
635
+ let lastTick = 0;
636
+ /** Each list's scrolling ancestors, read when the drag starts (or a list appears mid-drag). */
637
+ const scrollers = new Map();
622
638
  const bodyStyle = { userSelect: document.body.style.userSelect, cursor: document.body.style.cursor };
623
639
  /** Where a release now would put the item: nowhere past the root's edge. */
624
640
  const dropTarget = (session) => within(session.root, pointer.x, pointer.y)
@@ -638,16 +654,22 @@ export function Sortable({ value: valueProp, defaultValue, onValueChange, onMove
638
654
  // Once a frame: read the rects again if something scrolled, scroll near the edges — not once
639
655
  // the pointer is past the root's edge: it is on its way out, and a release there cancels —
640
656
  // and open the gap where the item would land.
641
- const tick = () => {
657
+ const tick = (now) => {
642
658
  const session = sessionRef.current;
643
659
  if (!session)
644
660
  return;
661
+ const dt = Math.min(32, lastTick ? now - lastTick : 16);
662
+ lastTick = now;
645
663
  if (session.dirty)
646
664
  refresh(session);
647
665
  if (within(session.root, pointer.x, pointer.y)) {
648
666
  const under = placeAt(session, pointer.x, pointer.y);
649
- if (under)
650
- autoScroll(under.list.el, pointer.x, pointer.y);
667
+ if (under) {
668
+ let chain = scrollers.get(under.list.el);
669
+ if (!chain)
670
+ scrollers.set(under.list.el, (chain = scrollersOf(under.list.el)));
671
+ autoScroll(chain, pointer.x, pointer.y, dt);
672
+ }
651
673
  }
652
674
  retarget(session);
653
675
  // A copy fitting another list's width keeps the pointer at the same share of it.
@@ -666,6 +688,8 @@ export function Sortable({ value: valueProp, defaultValue, onValueChange, onMove
666
688
  return end(false);
667
689
  before.current = null;
668
690
  const lists = measure();
691
+ for (const list of lists.values())
692
+ scrollers.set(list.el, scrollersOf(list.el));
669
693
  const rect = itemEl.getBoundingClientRect();
670
694
  sessionRef.current = {
671
695
  item,
@@ -1143,7 +1167,7 @@ export function Sortable({ value: valueProp, defaultValue, onValueChange, onMove
1143
1167
  },
1144
1168
  });
1145
1169
  return (_jsxs(SortableContext.Provider, { value: context, children: [element, drag &&
1146
- createPortal(_jsx("div", { ref: overlayRef, "aria-hidden": true, inert: true, dir: drag.dir, "data-slot": "sortable-overlay", "data-offset-x": drag.offsetX, "data-offset-y": drag.offsetY, className: "pointer-events-none fixed top-0 left-0 z-50 list-none", style: { width: drag.width }, children: overlay && (_jsx(SortableItemContext.Provider, { value: {
1170
+ createPortal(_jsx("div", { ref: overlayRef, "aria-hidden": true, inert: true, dir: drag.dir, "data-slot": "sortable-overlay", "data-phase": drag.phase, "data-offset-x": drag.offsetX, "data-offset-y": drag.offsetY, className: "pointer-events-none fixed top-0 left-0 z-50 list-none", style: { width: drag.width }, children: overlay && (_jsx(SortableItemContext.Provider, { value: {
1147
1171
  value: drag.item,
1148
1172
  label: labelOf(drag.item),
1149
1173
  disabled: false,
@@ -91,7 +91,7 @@ export interface TableGroupProps extends React.ComponentProps<"tbody"> {
91
91
  * break: grouping by something every row shares, or into groups of one. If most groups would
92
92
  * hold a single row, sort the column instead.
93
93
  */
94
- export declare function TableGroup({ open: openProp, defaultOpen, onOpenChange, collapsible, className, ...props }: TableGroupProps): React.JSX.Element;
94
+ export declare function TableGroup({ open: openProp, defaultOpen, onOpenChange, collapsible, className, ref, ...props }: TableGroupProps): React.JSX.Element;
95
95
  export interface TableGroupHeaderProps extends Omit<React.ComponentProps<"tr">, "children"> {
96
96
  /** The group's label: the shared value ("Running"), or a `Tag` for a status. */
97
97
  children: React.ReactNode;
@@ -6,6 +6,7 @@ import * as React from "react";
6
6
  import { flushSync } from "react-dom";
7
7
  import { cn } from "../lib/cn.js";
8
8
  import { mergeRefs } from "../lib/merge-refs.js";
9
+ import { cssDuration } from "../lib/motion.js";
9
10
  import { Flip, drawOrder, fitStep, layoutFor, measureMetrics, reducedMotion, removalOrder, titleRoom, widestRows, } from "../lib/table-fit.js";
10
11
  const TableDenseContext = React.createContext(false);
11
12
  const TableFitContext = React.createContext(null);
@@ -416,6 +417,55 @@ export function TableCell({ numeric = false, className, ...props }) {
416
417
  return (_jsx("td", { "data-slot": "table-cell", className: cn("px-4 align-middle text-foreground-soft first:ps-6 last:pe-6", dense ? "h-(--control-h-sm) py-1 text-[13px]" : "h-(--control-h-lg) py-2", numeric && "text-end font-mono text-[13px] whitespace-nowrap tabular-nums", className), ...props }));
417
418
  }
418
419
  const TableGroupContext = React.createContext(null);
420
+ /** The rows after the header that a group reveals, at most this many of them staggered. */
421
+ const REVEAL_STAGGER_ROWS = 6;
422
+ const REVEAL_STAGGER_MS = 15;
423
+ /** `--duration-fade` in ms (kept under reduced motion), in either unit a build may write. */
424
+ function fadeMs(el) {
425
+ const value = getComputedStyle(el).getPropertyValue("--duration-fade").trim();
426
+ const n = parseFloat(value);
427
+ if (!Number.isFinite(n))
428
+ return 0;
429
+ return value.endsWith("ms") ? n : value.endsWith("s") ? n * 1000 : n;
430
+ }
431
+ /**
432
+ * A group that opens shows its rows at once (they are not drawn while it is closed), then fades
433
+ * them in, each rising 4px, the first few a beat apart: --duration and 5 × 15ms, within 300ms.
434
+ * Under reduced motion they only fade, on --duration-fade. Closing stays instant: the rows go
435
+ * as they were asked to. The first render reveals nothing.
436
+ */
437
+ function useRevealRows(group, open) {
438
+ const was = React.useRef(open);
439
+ React.useLayoutEffect(() => {
440
+ const opened = open && !was.current;
441
+ was.current = open;
442
+ const el = group.current;
443
+ if (!opened || !el || typeof el.animate !== "function")
444
+ return;
445
+ const rows = el.querySelectorAll(':scope > [data-slot="table-row"]');
446
+ const move = cssDuration(el);
447
+ const fade = move ? 0 : fadeMs(el);
448
+ const easing = getComputedStyle(el).getPropertyValue("--ease").trim() || "ease-out";
449
+ const running = [];
450
+ rows.forEach((row, i) => {
451
+ running.push(row.animate(move
452
+ ? [
453
+ { opacity: 0, translate: "0 -4px" },
454
+ { opacity: 1, translate: "0 0" },
455
+ ]
456
+ : [{ opacity: 0 }, { opacity: 1 }], {
457
+ duration: move || fade,
458
+ delay: move ? Math.min(i, REVEAL_STAGGER_ROWS - 1) * REVEAL_STAGGER_MS : 0,
459
+ easing,
460
+ fill: "backwards",
461
+ }));
462
+ });
463
+ return () => {
464
+ for (const a of running)
465
+ a.cancel();
466
+ };
467
+ }, [group, open]);
468
+ }
419
469
  /**
420
470
  * TableGroup — one group of rows: a `<tbody>` that starts with a `TableGroupHeader` and holds
421
471
  * ordinary `TableRow`s. Use several in place of a single `TableBody`.
@@ -424,8 +474,10 @@ const TableGroupContext = React.createContext(null);
424
474
  * break: grouping by something every row shares, or into groups of one. If most groups would
425
475
  * hold a single row, sort the column instead.
426
476
  */
427
- export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, collapsible = true, className, ...props }) {
477
+ export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, collapsible = true, className, ref, ...props }) {
428
478
  const fit = React.useContext(TableFitContext);
479
+ const own = React.useRef(null);
480
+ const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
429
481
  const [uncontrolled, setUncontrolled] = React.useState(defaultOpen);
430
482
  const open = openProp ?? uncontrolled;
431
483
  const onOpenChangeRef = React.useRef(onOpenChange);
@@ -437,7 +489,8 @@ export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, c
437
489
  }, [openProp]);
438
490
  const value = React.useMemo(() => ({ open, setOpen, collapsible }), [open, setOpen, collapsible]);
439
491
  const state = { "data-open": open ? "" : undefined, "data-closed": open ? undefined : "" };
440
- return (_jsx(TableGroupContext.Provider, { value: value, children: fit ? (_jsx("div", { role: "rowgroup", "data-slot": "table-group", ...state, className: cn(SUBGRID, className), ...props })) : (_jsx("tbody", { "data-slot": "table-group", ...state, className: className, ...props })) }));
492
+ useRevealRows(own, open);
493
+ return (_jsx(TableGroupContext.Provider, { value: value, children: fit ? (_jsx("div", { ref: refs, role: "rowgroup", "data-slot": "table-group", ...state, className: cn(SUBGRID, className), ...props })) : (_jsx("tbody", { ref: refs, "data-slot": "table-group", ...state, className: className, ...props })) }));
441
494
  }
442
495
  /**
443
496
  * The first row of a `TableGroup`: a full-width band with the label, a mono count and an
@@ -48,12 +48,12 @@ const indicatorVariants = {
48
48
  segmented: [
49
49
  "pointer-events-none absolute top-0 left-0 -z-10 h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top) rounded-item",
50
50
  "bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-raised",
51
- "transition-[translate,width,height] duration-(--duration) ease-(--ease)",
51
+ "transition-[translate,width,height] duration-(--duration-glide) ease-(--ease-glide)",
52
52
  ].join(" "),
53
53
  underline: [
54
54
  "pointer-events-none absolute bottom-0 left-0 h-px w-(--active-tab-width) translate-x-(--active-tab-left) bg-foreground forced-colors:bg-[color:Highlight] forced-colors:forced-color-adjust-none",
55
55
  "data-[orientation=vertical]:top-0 data-[orientation=vertical]:bottom-auto data-[orientation=vertical]:-start-px data-[orientation=vertical]:h-(--active-tab-height) data-[orientation=vertical]:w-px data-[orientation=vertical]:translate-x-0 data-[orientation=vertical]:translate-y-(--active-tab-top)",
56
- "transition-[translate,width,height] duration-(--duration) ease-(--ease)",
56
+ "transition-[translate,width,height] duration-(--duration-glide) ease-(--ease-glide)",
57
57
  ].join(" "),
58
58
  };
59
59
  /**
@@ -149,7 +149,7 @@ export function TabsTab({ className, ...props }) {
149
149
  const variant = React.useContext(TabsVariantContext);
150
150
  return (_jsx(BaseTabs.Tab, { "data-slot": "tabs-tab", className: sx([
151
151
  "relative inline-flex shrink-0 cursor-pointer items-center leading-none whitespace-nowrap focus-ring select-none",
152
- "transition-colors duration-(--duration) ease-(--ease)",
152
+ "transition-colors duration-(--duration-fade) ease-(--ease)",
153
153
  // A disabled tab stays focusable (Base UI) and still takes hover, so a tooltip can say why.
154
154
  "disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:opacity-50",
155
155
  "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
@@ -158,5 +158,9 @@ export function TabsTab({ className, ...props }) {
158
158
  }
159
159
  /** The content for one tab. Only the active panel is mounted unless `keepMounted` is set. */
160
160
  export function TabsPanel({ className, ...props }) {
161
- return (_jsx(BaseTabs.Panel, { "data-slot": "tabs-panel", className: sx("min-w-0 flex-1 focus-ring", className), ...props }));
161
+ return (_jsx(BaseTabs.Panel, { "data-slot": "tabs-panel",
162
+ // Base UI keeps the panel that is leaving for a frame, for an exit animation, beside the one
163
+ // arriving: both at once would double the height for that frame, and the page jump under
164
+ // the pointer. A panel has no exit animation here, so the leaving one goes at once.
165
+ className: sx("min-w-0 flex-1 focus-ring data-ending-style:hidden", className), ...props }));
162
166
  }
@@ -23,7 +23,7 @@ const removeSizes = {
23
23
  default: "size-(--control-inset-sm) [&_svg]:size-3.5",
24
24
  };
25
25
  const inputSizes = {
26
- sm: "min-h-(--control-inset-sm) text-[13px]",
26
+ sm: "min-h-(--control-inset-sm) text-[13px] pointer-coarse:text-base",
27
27
  default: "min-h-(--control-h-sm) text-base sm:text-[15px]",
28
28
  };
29
29
  const defaultMessages = {
@@ -10,7 +10,7 @@ declare module "./locale" {
10
10
  theme: ThemeMessages;
11
11
  }
12
12
  }
13
- export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY, type ThemeMode } from "../lib/theme-script.js";
13
+ export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY, type ThemeMode, } from "../lib/theme-script.js";
14
14
  export type ResolvedTheme = "light" | "dark";
15
15
  export interface ThemeContextValue {
16
16
  /** The stored preference: `light`, `dark` or `system`. */
@@ -6,7 +6,7 @@ import { DARK_QUERY, setThemeColor, THEME_STORAGE_KEY } from "../lib/theme-scrip
6
6
  import { Button } from "./button.js";
7
7
  import { useMessages } from "./locale.js";
8
8
  const defaultMessages = { toggle: "Toggle light and dark theme" };
9
- export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY } from "../lib/theme-script.js";
9
+ export { createThemeScript, themeScript, PAGE_TONE, THEME_STORAGE_KEY, } from "../lib/theme-script.js";
10
10
  const ThemeContext = createContext(null);
11
11
  const isMode = (v) => v === "light" || v === "dark" || v === "system";
12
12
  function readStored(key) {
@@ -78,7 +78,7 @@ export function ThemeProvider({ children, defaultTheme = "system", storageKey =
78
78
  useEffect(() => {
79
79
  if (!mounted)
80
80
  return;
81
- document.documentElement.classList.toggle("dark", resolvedTheme === "dark");
81
+ applyDark(resolvedTheme === "dark");
82
82
  if (themeColor)
83
83
  setThemeColor(resolvedTheme === "dark");
84
84
  }, [mounted, resolvedTheme, themeColor]);
@@ -88,13 +88,31 @@ export function ThemeProvider({ children, defaultTheme = "system", storageKey =
88
88
  // Applied at once too: the effect above runs only when the resolved theme changes, and
89
89
  // something outside this provider may have changed the class since.
90
90
  const dark = next === "dark" || (next === "system" && systemDark());
91
- document.documentElement.classList.toggle("dark", dark);
91
+ applyDark(dark);
92
92
  if (themeColor)
93
93
  setThemeColor(dark);
94
94
  }, [storageKey, themeColor]);
95
95
  const value = useMemo(() => ({ theme, resolvedTheme, setTheme }), [theme, resolvedTheme, setTheme]);
96
96
  return _jsx(ThemeContext.Provider, { value: value, children: children });
97
97
  }
98
+ /**
99
+ * Flip `.dark` on <html> in one frame. The page's colours change at once, but every material
100
+ * transitions its background and shadows over `--duration`, so for a moment half the page would
101
+ * show each theme. Transitions are off for the flip — a style read commits it — and come back on
102
+ * the next frame, before anything else moves.
103
+ */
104
+ function applyDark(dark) {
105
+ const root = document.documentElement;
106
+ if (root.classList.contains("dark") === dark)
107
+ return;
108
+ const style = document.createElement("style");
109
+ style.textContent = "*,*::before,*::after{transition:none!important}";
110
+ document.head.appendChild(style);
111
+ root.classList.toggle("dark", dark);
112
+ // Read a style so the browser applies the new theme while transitions are off.
113
+ void getComputedStyle(root).colorScheme;
114
+ requestAnimationFrame(() => style.remove());
115
+ }
98
116
  /** Read and change the theme. Must be used inside `ThemeProvider`. */
99
117
  export function useTheme() {
100
118
  const ctx = useContext(ThemeContext);
@@ -60,7 +60,8 @@ declare module "./locale" {
60
60
  * TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
61
61
  * mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
62
62
  *
63
- * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField),
63
+ * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField;
64
+ * a held key counts in place rather than restarting the roll on every repeat),
64
65
  * typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
65
66
  * string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
66
67
  * departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
@@ -4,6 +4,7 @@ import { Field as BaseField } from "@base-ui/react/field";
4
4
  import { ClockIcon } from "lucide-react";
5
5
  import * as React from "react";
6
6
  import { cn } from "../lib/cn.js";
7
+ import { cssDuration } from "../lib/motion.js";
7
8
  import { DigitRoll, reducedMotion } from "../lib/digit-roll.js";
8
9
  import { useLocale, useMessages } from "./locale.js";
9
10
  const groupSizes = {
@@ -93,7 +94,8 @@ function useClock(locale, hourCycle, seconds) {
93
94
  * TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
94
95
  * mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
95
96
  *
96
- * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField),
97
+ * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField;
98
+ * a held key counts in place rather than restarting the roll on every repeat),
97
99
  * typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
98
100
  * string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
99
101
  * departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
@@ -155,6 +157,7 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
155
157
  };
156
158
  /* The digit roll: a step remembers the segment's text before and after, and which way it went. */
157
159
  const [rolls, setRolls] = React.useState({});
160
+ const lastStep = React.useRef(-Infinity);
158
161
  const endRoll = React.useMemo(() => {
159
162
  const end = (type) => () => setRolls((r) => ({ ...r, [type]: undefined }));
160
163
  return { hour: end("hour"), minute: end("minute"), second: end("second"), dayPeriod: end("dayPeriod") };
@@ -183,8 +186,15 @@ export function TimeField({ value: valueProp, defaultValue, onValueChange, size
183
186
  }
184
187
  const from = rolls[type]?.to ?? display(type, s);
185
188
  const to = display(type, next);
186
- if (from !== to && !from.includes("–") && !reducedMotion())
187
- setRolls((r) => ({ ...r, [type]: { from, to, dir, key: performance.now() } }));
189
+ // A held key repeats faster than a roll lasts, and a roll that restarts on every repeat never
190
+ // lands: a step that close to the last one shows its value in place, and the running roll gives way.
191
+ const now = performance.now();
192
+ const repeat = now - lastStep.current < cssDuration();
193
+ lastStep.current = now;
194
+ if (repeat)
195
+ setRolls((r) => ({ ...r, [type]: undefined }));
196
+ else if (from !== to && !from.includes("–") && !reducedMotion())
197
+ setRolls((r) => ({ ...r, [type]: { from, to, dir, key: now } }));
188
198
  update(next);
189
199
  };
190
200
  const setSegment = (type, n) => {
@@ -130,6 +130,7 @@ export function ToggleGroupItem({ icon, className, children, ...props }) {
130
130
  "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
131
131
  // Hover only brightens the label; the raised material means "selected".
132
132
  "hover:not-data-disabled:text-foreground",
133
+ "transition-[background-color,color] duration-(--duration-fade) ease-(--ease)",
133
134
  "data-pressed:bg-control-surface data-pressed:bg-linear-to-b data-pressed:from-control-inner-edge data-pressed:to-transparent data-pressed:text-foreground data-pressed:shadow-raised",
134
135
  // Once the gliding indicator is placed it carries the raised surface instead.
135
136
  "group-data-indicator/toggle-group:data-pressed:bg-transparent group-data-indicator/toggle-group:data-pressed:bg-none group-data-indicator/toggle-group:data-pressed:shadow-none",
@@ -8,6 +8,11 @@ import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "./collapsible
8
8
  import { useMessages } from "./locale.js";
9
9
  import { Spinner } from "./spinner.js";
10
10
  import { Tag } from "./tag.js";
11
+ /* The status icon's faces, stacked like CopyButton's: they cross-fade and scale from 0.85 on
12
+ --duration (0 under reduced motion). A face out of sight stops its animation. */
13
+ const statusFace = "col-start-1 row-start-1 grid place-items-center transition-[opacity,scale] duration-(--duration) ease-(--ease)";
14
+ const statusShown = "scale-100 opacity-100";
15
+ const statusHidden = "scale-[0.85] opacity-0 [&,&_*]:animate-none";
11
16
  const defaultMessages = {
12
17
  pending: "Pending",
13
18
  running: "Running",
@@ -32,7 +37,7 @@ const MessagesContext = React.createContext(null);
32
37
  export function ToolCall({ name, status, icon, labels, highlight = true, className, children, ...props }) {
33
38
  const text = useMessages("toolCall", defaultMessages, labels);
34
39
  const label = text[status];
35
- return (_jsx(MessagesContext.Provider, { value: text, children: _jsx(HighlightContext.Provider, { value: highlight, children: _jsxs(Collapsible, { "data-slot": "tool-call", "data-status": status, className: sx("overflow-hidden surface-card [--card-padding:0]", className), ...props, children: [_jsxs(CollapsibleTrigger, { "data-slot": "tool-call-trigger", showIcon: false, className: "w-full justify-between gap-3 px-4 py-2.5 text-foreground", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { "aria-hidden": true, className: "flex shrink-0 text-muted-foreground [&_svg]:size-3.5", children: icon ?? _jsx(WrenchIcon, {}) }), _jsx("span", { className: "truncate", children: name })] }), _jsxs("span", { className: "flex shrink-0 items-center gap-2", children: [_jsxs(Tag, { "data-slot": "tool-call-status", variant: status === "error" ? "destructive" : status === "completed" ? "default" : "muted", children: [status === "running" ? (_jsx(Spinner, { size: "sm", label: label })) : status === "completed" ? (_jsx(CheckIcon, { "aria-hidden": true, className: "text-success" })) : status === "error" ? (_jsx(CircleAlertIcon, { "aria-hidden": true })) : (_jsx(CircleDashedIcon, { "aria-hidden": true })), _jsx("span", { "aria-hidden": status === "running" || undefined, children: label })] }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5 text-muted-foreground transition-[rotate] duration-(--duration) ease-(--ease) group-data-panel-open/collapsible-trigger:rotate-180" })] })] }), _jsx(CollapsiblePanel, { "data-slot": "tool-call-panel", children: _jsx("div", { className: "flex flex-col gap-4 border-t border-border/60 p-4", children: children }) })] }) }) }));
40
+ return (_jsx(MessagesContext.Provider, { value: text, children: _jsx(HighlightContext.Provider, { value: highlight, children: _jsxs(Collapsible, { "data-slot": "tool-call", "data-status": status, className: sx("overflow-hidden surface-card [--card-padding:0]", className), ...props, children: [_jsxs(CollapsibleTrigger, { "data-slot": "tool-call-trigger", showIcon: false, className: "w-full justify-between gap-3 px-4 py-2.5 text-foreground", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { "aria-hidden": true, className: "flex shrink-0 text-muted-foreground [&_svg]:size-3.5", children: icon ?? _jsx(WrenchIcon, {}) }), _jsx("span", { className: "truncate", children: name })] }), _jsxs("span", { className: "flex shrink-0 items-center gap-2", children: [_jsxs(Tag, { "data-slot": "tool-call-status", variant: status === "error" ? "destructive" : status === "completed" ? "default" : "muted", children: [_jsxs("span", { "data-slot": "tool-call-status-icon", className: "grid", children: [_jsx("span", { className: cn(statusFace, status === "pending" ? statusShown : statusHidden), "aria-hidden": true, children: _jsx(CircleDashedIcon, {}) }), _jsx("span", { className: cn(statusFace, status === "running" ? statusShown : statusHidden), "aria-hidden": status !== "running" || undefined, children: _jsx(Spinner, { size: "sm", label: label }) }), _jsx("span", { className: cn(statusFace, status === "completed" ? statusShown : statusHidden), "aria-hidden": true, children: _jsx(CheckIcon, { className: "text-success" }) }), _jsx("span", { className: cn(statusFace, status === "error" ? statusShown : statusHidden), "aria-hidden": true, children: _jsx(CircleAlertIcon, {}) })] }), _jsx("span", { "aria-hidden": status === "running" || undefined, children: label })] }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3.5 text-muted-foreground transition-[rotate] duration-(--duration) ease-(--ease) group-data-panel-open/collapsible-trigger:rotate-180" })] })] }), _jsx(CollapsiblePanel, { "data-slot": "tool-call-panel", children: _jsx("div", { className: "flex flex-col gap-4 border-t border-border/60 p-4", children: children }) })] }) }) }));
36
41
  }
37
42
  function Section({ label, children, slot, }) {
38
43
  return (_jsxs("section", { "data-slot": slot, className: "flex min-w-0 flex-col gap-2", children: [_jsx("h4", { className: "m-0 eyebrow text-[11px]", children: label }), children] }));
@@ -8,7 +8,7 @@ import { Toolbar as BaseToolbar } from "@base-ui/react/toolbar";
8
8
  * The rule people break: mixing 38px controls into it. A toolbar is a dense surface — every
9
9
  * control inside is 30px (`size="sm"` on `Select`, `Input` and `Button`).
10
10
  */
11
- export declare function Toolbar({ className, ...props }: BaseToolbar.Root.Props): import("react").JSX.Element;
11
+ export declare function Toolbar({ className, children, ...props }: BaseToolbar.Root.Props): import("react").JSX.Element;
12
12
  /** A 30px command. Icon-only buttons need an `aria-label`. Toggles set `aria-pressed`. */
13
13
  export declare function ToolbarButton({ className, ...props }: BaseToolbar.Button.Props): import("react").JSX.Element;
14
14
  /** A run of related buttons, e.g. bold / italic / underline. */
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { Toolbar as BaseToolbar } from "@base-ui/react/toolbar";
4
4
  import { sx } from "../lib/cn.js";
5
+ import { TooltipProvider } from "./tooltip.js";
5
6
  /**
6
7
  * Toolbar — a dense row of related commands (editor formatting, table actions, view options).
7
8
  *
@@ -11,13 +12,15 @@ import { sx } from "../lib/cn.js";
11
12
  * The rule people break: mixing 38px controls into it. A toolbar is a dense surface — every
12
13
  * control inside is 30px (`size="sm"` on `Select`, `Input` and `Button`).
13
14
  */
14
- export function Toolbar({ className, ...props }) {
15
+ export function Toolbar({ className, children, ...props }) {
16
+ // Its own tooltip group: after the first tooltip, the next one opens at once and without motion
17
+ // (Base UI marks it data-instant), as the pointer runs along the buttons.
15
18
  return (_jsx(BaseToolbar.Root, { "data-slot": "toolbar", className: sx([
16
19
  "inline-flex w-fit max-w-full items-center gap-1 rounded-button p-1 surface-container data-[orientation=vertical]:flex-col",
17
20
  // More than fits — a phone, a taller theme — scrolls inside the bar (its 4px inset keeps
18
21
  // focus outlines whole) instead of pushing the page wider.
19
22
  "scroll-px-1 [scrollbar-width:none] data-[orientation=horizontal]:overflow-x-auto data-[orientation=horizontal]:overflow-y-hidden [&::-webkit-scrollbar]:hidden",
20
- ], className), ...props }));
23
+ ], className), ...props, children: _jsx(TooltipProvider, { children: children }) }));
21
24
  }
22
25
  /** A 30px command. Icon-only buttons need an `aria-label`. Toggles set `aria-pressed`. */
23
26
  export function ToolbarButton({ className, ...props }) {
@@ -2,9 +2,11 @@ import { Tooltip as BaseTooltip } from "@base-ui/react/tooltip";
2
2
  import * as React from "react";
3
3
  /**
4
4
  * TooltipProvider — shares one quick delay across every tooltip below it, so moving from one
5
- * icon button to the next opens the next tooltip instantly. Wrap the app (or a toolbar) once.
5
+ * icon button to the next opens the next tooltip instantly (and without its opening motion).
6
+ * Wrap the app once; a `Toolbar` brings its own. Nested inside another provider with no delays of
7
+ * its own, it defers to the outer one, so the group carries on across it.
6
8
  */
7
- export declare function TooltipProvider({ delay, closeDelay, ...props }: BaseTooltip.Provider.Props): React.JSX.Element;
9
+ export declare function TooltipProvider({ delay, closeDelay, timeout, children }: BaseTooltip.Provider.Props): React.JSX.Element;
8
10
  /**
9
11
  * Tooltip — a short label for a control that has no visible text, shown on hover and focus.
10
12
  *
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Tooltip as BaseTooltip } from "@base-ui/react/tooltip";
4
4
  import * as React from "react";
5
5
  import { sx, triggerSlot } from "../lib/cn.js";
@@ -10,10 +10,16 @@ const TOOLTIP_DELAY = 150;
10
10
  const InProviderContext = React.createContext(false);
11
11
  /**
12
12
  * TooltipProvider — shares one quick delay across every tooltip below it, so moving from one
13
- * icon button to the next opens the next tooltip instantly. Wrap the app (or a toolbar) once.
13
+ * icon button to the next opens the next tooltip instantly (and without its opening motion).
14
+ * Wrap the app once; a `Toolbar` brings its own. Nested inside another provider with no delays of
15
+ * its own, it defers to the outer one, so the group carries on across it.
14
16
  */
15
- export function TooltipProvider({ delay = TOOLTIP_DELAY, closeDelay = 0, ...props }) {
16
- return (_jsx(InProviderContext.Provider, { value: true, children: _jsx(BaseTooltip.Provider, { delay: delay, closeDelay: closeDelay, ...props }) }));
17
+ export function TooltipProvider({ delay, closeDelay, timeout, children }) {
18
+ const inProvider = React.useContext(InProviderContext);
19
+ if (inProvider && delay === undefined && closeDelay === undefined && timeout === undefined) {
20
+ return _jsx(_Fragment, { children: children });
21
+ }
22
+ return (_jsx(InProviderContext.Provider, { value: true, children: _jsx(BaseTooltip.Provider, { delay: delay ?? TOOLTIP_DELAY, closeDelay: closeDelay ?? 0, timeout: timeout, children: children }) }));
17
23
  }
18
24
  /**
19
25
  * Tooltip — a short label for a control that has no visible text, shown on hover and focus.