@zonsh/ui 0.2.0 → 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 (200) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/accordion.js +1 -1
  4. package/dist/components/alert-dialog.js +1 -1
  5. package/dist/components/ascii-field.d.ts +1 -1
  6. package/dist/components/ascii-field.js +2 -1
  7. package/dist/components/bottom-nav.d.ts +86 -0
  8. package/dist/components/bottom-nav.js +175 -0
  9. package/dist/components/breadcrumb.d.ts +9 -0
  10. package/dist/components/breadcrumb.js +6 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +2 -2
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/calendar.d.ts +1 -1
  15. package/dist/components/calendar.js +18 -3
  16. package/dist/components/carousel.d.ts +22 -3
  17. package/dist/components/carousel.js +25 -7
  18. package/dist/components/chart.d.ts +20 -0
  19. package/dist/components/chart.js +52 -3
  20. package/dist/components/code-block.d.ts +20 -10
  21. package/dist/components/code-block.js +54 -12
  22. package/dist/components/collapsible.js +3 -3
  23. package/dist/components/color-picker.d.ts +30 -8
  24. package/dist/components/color-picker.js +48 -27
  25. package/dist/components/combobox.d.ts +21 -3
  26. package/dist/components/combobox.js +79 -7
  27. package/dist/components/command.d.ts +23 -3
  28. package/dist/components/command.js +63 -18
  29. package/dist/components/conversation.d.ts +10 -1
  30. package/dist/components/conversation.js +24 -7
  31. package/dist/components/copy-button.d.ts +15 -6
  32. package/dist/components/copy-button.js +27 -10
  33. package/dist/components/data-table.d.ts +66 -6
  34. package/dist/components/data-table.js +376 -23
  35. package/dist/components/date-picker.d.ts +73 -4
  36. package/dist/components/date-picker.js +138 -7
  37. package/dist/components/dialog.d.ts +10 -1
  38. package/dist/components/dialog.js +6 -3
  39. package/dist/components/drawer.d.ts +10 -1
  40. package/dist/components/drawer.js +6 -3
  41. package/dist/components/feature-list.js +2 -2
  42. package/dist/components/field.d.ts +27 -8
  43. package/dist/components/field.js +49 -4
  44. package/dist/components/file-drop.d.ts +26 -4
  45. package/dist/components/file-drop.js +125 -64
  46. package/dist/components/filter-bar.d.ts +50 -3
  47. package/dist/components/filter-bar.js +71 -33
  48. package/dist/components/form.d.ts +4 -2
  49. package/dist/components/form.js +24 -2
  50. package/dist/components/graph.d.ts +41 -0
  51. package/dist/components/graph.js +106 -50
  52. package/dist/components/illustration.js +51 -4
  53. package/dist/components/input-group.d.ts +18 -7
  54. package/dist/components/input-group.js +41 -19
  55. package/dist/components/input.d.ts +2 -2
  56. package/dist/components/input.js +3 -3
  57. package/dist/components/kbd.d.ts +17 -0
  58. package/dist/components/kbd.js +8 -1
  59. package/dist/components/layout.d.ts +2 -1
  60. package/dist/components/layout.js +55 -11
  61. package/dist/components/lightbox.d.ts +100 -0
  62. package/dist/components/lightbox.js +457 -0
  63. package/dist/components/locale.d.ts +44 -0
  64. package/dist/components/locale.js +37 -0
  65. package/dist/components/logo.js +1 -1
  66. package/dist/components/menu.js +3 -1
  67. package/dist/components/menubar.js +60 -13
  68. package/dist/components/message.d.ts +3 -3
  69. package/dist/components/message.js +12 -8
  70. package/dist/components/meter.js +3 -1
  71. package/dist/components/money-input.d.ts +80 -0
  72. package/dist/components/money-input.js +253 -0
  73. package/dist/components/navigation-menu.js +4 -2
  74. package/dist/components/number-field.d.ts +21 -2
  75. package/dist/components/number-field.js +53 -28
  76. package/dist/components/otp-field.d.ts +14 -1
  77. package/dist/components/otp-field.js +10 -2
  78. package/dist/components/pagination.d.ts +13 -7
  79. package/dist/components/pagination.js +18 -7
  80. package/dist/components/pdf-viewer.d.ts +67 -2
  81. package/dist/components/pdf-viewer.js +88 -21
  82. package/dist/components/phone-input.d.ts +79 -0
  83. package/dist/components/phone-input.js +282 -0
  84. package/dist/components/popover.js +1 -1
  85. package/dist/components/progress.js +3 -1
  86. package/dist/components/prompt-input.d.ts +34 -9
  87. package/dist/components/prompt-input.js +37 -17
  88. package/dist/components/radio-group.js +7 -2
  89. package/dist/components/rating.d.ts +73 -0
  90. package/dist/components/rating.js +124 -0
  91. package/dist/components/reasoning.d.ts +16 -1
  92. package/dist/components/reasoning.js +10 -7
  93. package/dist/components/resizable.d.ts +10 -1
  94. package/dist/components/resizable.js +4 -1
  95. package/dist/components/response.d.ts +17 -5
  96. package/dist/components/response.js +58 -18
  97. package/dist/components/scroll-area.d.ts +1 -1
  98. package/dist/components/select.js +14 -3
  99. package/dist/components/separator.js +1 -1
  100. package/dist/components/sidebar.d.ts +20 -4
  101. package/dist/components/sidebar.js +70 -35
  102. package/dist/components/site-header.d.ts +46 -12
  103. package/dist/components/site-header.js +78 -19
  104. package/dist/components/skeleton.d.ts +1 -1
  105. package/dist/components/skeleton.js +1 -1
  106. package/dist/components/slider.js +3 -1
  107. package/dist/components/sortable.d.ts +178 -0
  108. package/dist/components/sortable.js +1282 -0
  109. package/dist/components/sources.d.ts +17 -2
  110. package/dist/components/sources.js +11 -4
  111. package/dist/components/spinner.d.ts +13 -1
  112. package/dist/components/spinner.js +5 -2
  113. package/dist/components/stat.d.ts +91 -0
  114. package/dist/components/stat.js +141 -0
  115. package/dist/components/stepper.d.ts +71 -0
  116. package/dist/components/stepper.js +101 -0
  117. package/dist/components/switch.d.ts +2 -2
  118. package/dist/components/switch.js +2 -2
  119. package/dist/components/table.d.ts +13 -3
  120. package/dist/components/table.js +231 -41
  121. package/dist/components/tabs.js +8 -4
  122. package/dist/components/tags-input.d.ts +18 -2
  123. package/dist/components/tags-input.js +66 -34
  124. package/dist/components/theme.d.ts +16 -2
  125. package/dist/components/theme.js +34 -8
  126. package/dist/components/time-field.d.ts +24 -4
  127. package/dist/components/time-field.js +32 -9
  128. package/dist/components/timeline.d.ts +18 -2
  129. package/dist/components/timeline.js +13 -4
  130. package/dist/components/tippy.d.ts +48 -0
  131. package/dist/components/tippy.js +648 -0
  132. package/dist/components/toast.d.ts +18 -2
  133. package/dist/components/toast.js +12 -3
  134. package/dist/components/toggle-group.js +1 -0
  135. package/dist/components/tool-call.d.ts +19 -8
  136. package/dist/components/tool-call.js +23 -7
  137. package/dist/components/toolbar.d.ts +1 -1
  138. package/dist/components/toolbar.js +10 -2
  139. package/dist/components/tooltip.d.ts +4 -2
  140. package/dist/components/tooltip.js +10 -4
  141. package/dist/components/tour.d.ts +127 -0
  142. package/dist/components/tour.js +673 -0
  143. package/dist/components/tree.js +45 -9
  144. package/dist/components/video-player.d.ts +10 -2
  145. package/dist/components/video-player.js +134 -38
  146. package/dist/illustration.d.ts +2 -0
  147. package/dist/illustration.js +7 -0
  148. package/dist/index.d.ts +11 -3
  149. package/dist/index.js +11 -3
  150. package/dist/lib/code-highlight.d.ts +3 -16
  151. package/dist/lib/code-highlight.js +160 -10
  152. package/dist/lib/code-theme.js +3 -3
  153. package/dist/lib/digit-roll.js +8 -8
  154. package/dist/lib/field-errors.d.ts +28 -0
  155. package/dist/lib/field-errors.js +24 -0
  156. package/dist/lib/field-value.d.ts +13 -0
  157. package/dist/lib/field-value.js +44 -0
  158. package/dist/lib/glide.d.ts +5 -4
  159. package/dist/lib/glide.js +5 -4
  160. package/dist/lib/graph-layout.js +11 -2
  161. package/dist/lib/money.d.ts +73 -0
  162. package/dist/lib/money.js +343 -0
  163. package/dist/lib/phone-countries.d.ts +1 -0
  164. package/dist/lib/phone-countries.js +281 -0
  165. package/dist/lib/phone.d.ts +90 -0
  166. package/dist/lib/phone.js +286 -0
  167. package/dist/lib/platform.d.ts +8 -3
  168. package/dist/lib/platform.js +13 -6
  169. package/dist/lib/row-index.d.ts +15 -0
  170. package/dist/lib/row-index.js +136 -0
  171. package/dist/lib/table-fit.d.ts +3 -2
  172. package/dist/lib/table-fit.js +52 -23
  173. package/dist/lib/theme-script.d.ts +15 -2
  174. package/dist/lib/theme-script.js +23 -3
  175. package/dist/lib/tippy/pixels.d.ts +47 -0
  176. package/dist/lib/tippy/pixels.js +187 -0
  177. package/dist/lib/tippy/sprite.d.ts +86 -0
  178. package/dist/lib/tippy/sprite.js +753 -0
  179. package/dist/messages/de.d.ts +12 -0
  180. package/dist/messages/de.js +326 -0
  181. package/dist/styles/expressive.css +60 -26
  182. package/dist/styles/index.css +11 -2
  183. package/dist/styles/material.css +47 -23
  184. package/dist/styles/parts/ai.css +4 -2
  185. package/dist/styles/parts/controls.css +85 -32
  186. package/dist/styles/parts/data.css +33 -5
  187. package/dist/styles/parts/feedback.css +110 -13
  188. package/dist/styles/parts/foundations.css +1 -1
  189. package/dist/styles/parts/navigation.css +230 -5
  190. package/dist/styles/parts/overlays.css +98 -11
  191. package/dist/styles/parts/pdf.css +13 -7
  192. package/dist/styles/tokens.css +28 -4
  193. package/dist/vite.d.ts +0 -50
  194. package/dist/vite.js +0 -100
  195. package/package.json +28 -33
  196. package/dist/components/code-highlight.d.ts +0 -13
  197. package/dist/components/code-highlight.js +0 -107
  198. package/dist/components/whiteboard.d.ts +0 -80
  199. package/dist/components/whiteboard.js +0 -389
  200. package/dist/styles/parts/whiteboard.css +0 -855
@@ -6,6 +6,18 @@ import * as React from "react";
6
6
  import { cn } from "../lib/cn.js";
7
7
  import { Button } from "./button.js";
8
8
  import { useDirection } from "./direction.js";
9
+ import { useMessages } from "./locale.js";
10
+ const defaultMessages = {
11
+ carousel: "carousel",
12
+ slide: "slide",
13
+ previous: "Previous slide",
14
+ next: "Next slide",
15
+ goTo: (slide, total) => `Go to slide ${slide} of ${total}`,
16
+ of: "of",
17
+ };
18
+ /** The `labels` of the nearest Carousel, read by its parts. */
19
+ const LabelsContext = React.createContext(undefined);
20
+ const useCarouselText = () => useMessages("carousel", defaultMessages, React.useContext(LabelsContext));
9
21
  const CarouselContext = React.createContext(null);
10
22
  /**
11
23
  * useCarousel — the carousel's state and controls, for building your own counter or buttons
@@ -36,7 +48,8 @@ const useReducedMotion = () => React.useSyncExternalStore(subscribeReduced, () =
36
48
  * The rule people break: hiding content people need inside it. A carousel shows one thing at a
37
49
  * time; anything that must be compared or read in full belongs on the page as a grid or list.
38
50
  */
39
- export function Carousel({ orientation = "horizontal", opts, plugins, setApi, className, children, onKeyDownCapture, ...props }) {
51
+ export function Carousel({ orientation = "horizontal", opts, plugins, setApi, className, children, onKeyDownCapture, labels, ...props }) {
52
+ const text = useMessages("carousel", defaultMessages, labels);
40
53
  // Inside a right-to-left DirectionProvider the slides run right to left too, unless `opts` says.
41
54
  const provided = useDirection();
42
55
  const direction = opts?.direction ?? provided;
@@ -99,7 +112,7 @@ export function Carousel({ orientation = "horizontal", opts, plugins, setApi, cl
99
112
  scrollTo,
100
113
  reducedMotion,
101
114
  };
102
- return (_jsx(CarouselContext.Provider, { value: value, children: _jsx("div", { "data-slot": "carousel", "data-orientation": orientation, role: "region", "aria-roledescription": "carousel", className: cn("relative flex flex-col gap-6", className), onKeyDownCapture: handleKeyDown, ...props, children: children }) }));
115
+ return (_jsx(CarouselContext.Provider, { value: value, children: _jsx(LabelsContext.Provider, { value: labels, children: _jsx("div", { "data-slot": "carousel", "data-orientation": orientation, role: "region", "aria-roledescription": text.carousel, className: cn("relative flex flex-col gap-6", className), onKeyDownCapture: handleKeyDown, ...props, children: children }) }) }));
103
116
  }
104
117
  /** The clipping viewport and the moving track. Slides go inside as `CarouselItem`s. */
105
118
  export function CarouselContent({ viewportClassName, className, ...props }) {
@@ -115,12 +128,14 @@ export function CarouselContent({ viewportClassName, className, ...props }) {
115
128
  */
116
129
  export function CarouselItem({ className, ...props }) {
117
130
  const { orientation } = useCarousel();
118
- return (_jsx("div", { "data-slot": "carousel-item", role: "group", "aria-roledescription": "slide", className: cn("min-w-0 shrink-0 grow-0 basis-full", orientation === "horizontal" ? "pl-4" : "pt-4", className), ...props }));
131
+ const text = useCarouselText();
132
+ return (_jsx("div", { "data-slot": "carousel-item", role: "group", "aria-roledescription": text.slide, className: cn("min-w-0 shrink-0 grow-0 basis-full", orientation === "horizontal" ? "pl-4" : "pt-4", className), ...props }));
119
133
  }
120
134
  /** The previous button: a circular secondary icon button. Disabled at the first slide unless looping. */
121
135
  export function CarouselPrevious({ variant = "secondary", size = "icon", className, children, onClick, ...props }) {
122
136
  const { orientation, scrollPrev, canScrollPrev } = useCarousel();
123
- return (_jsx(Button, { "data-slot": "carousel-previous", variant: variant, size: size, "aria-label": "Previous slide", disabled: !canScrollPrev, className: className, onClick: (event) => {
137
+ const text = useCarouselText();
138
+ return (_jsx(Button, { "data-slot": "carousel-previous", variant: variant, size: size, "aria-label": text.previous, disabled: !canScrollPrev, className: className, onClick: (event) => {
124
139
  onClick?.(event);
125
140
  if (!event.defaultPrevented)
126
141
  scrollPrev();
@@ -130,7 +145,8 @@ export function CarouselPrevious({ variant = "secondary", size = "icon", classNa
130
145
  /** The next button: a circular secondary icon button. Disabled at the last slide unless looping. */
131
146
  export function CarouselNext({ variant = "secondary", size = "icon", className, children, onClick, ...props }) {
132
147
  const { orientation, scrollNext, canScrollNext } = useCarousel();
133
- return (_jsx(Button, { "data-slot": "carousel-next", variant: variant, size: size, "aria-label": "Next slide", disabled: !canScrollNext, className: className, onClick: (event) => {
148
+ const text = useCarouselText();
149
+ return (_jsx(Button, { "data-slot": "carousel-next", variant: variant, size: size, "aria-label": text.next, disabled: !canScrollNext, className: className, onClick: (event) => {
134
150
  onClick?.(event);
135
151
  if (!event.defaultPrevented)
136
152
  scrollNext();
@@ -172,8 +188,10 @@ function snapWeights(api) {
172
188
  * slide) or a mono "01 / 07" index. Never round dots. The long tick moves with the slides, so a
173
189
  * drag or a glide hands it from one tick to the next rather than switching it at the start.
174
190
  */
175
- export function CarouselDots({ variant = "ticks", getLabel = (slide, total) => `Go to slide ${slide} of ${total}`, className, ...props }) {
191
+ export function CarouselDots({ variant = "ticks", getLabel: getLabelProp, className, ...props }) {
176
192
  const { api, orientation, selectedIndex, snapCount, scrollTo } = useCarousel();
193
+ const text = useCarouselText();
194
+ const getLabel = getLabelProp ?? text.goTo;
177
195
  const total = Math.max(snapCount, 1);
178
196
  const ticks = React.useRef([]);
179
197
  // Every frame the slides move, each tick takes how current it is as --current. Written to the
@@ -195,7 +213,7 @@ export function CarouselDots({ variant = "ticks", getLabel = (slide, total) => `
195
213
  if (variant === "index") {
196
214
  return (_jsxs("div", { "data-slot": "carousel-dots", "data-variant": "index",
197
215
  // "01 / 07" stays in that order in a right-to-left page: numerals are never mirrored.
198
- dir: "ltr", "aria-live": "polite", "aria-atomic": "true", className: cn("font-mono text-xs leading-none text-muted-foreground tabular-nums", className), ...props, children: [_jsx("span", { className: "text-foreground", children: pad(selectedIndex + 1) }), _jsx("span", { "aria-hidden": true, children: " / " }), _jsx("span", { className: "sr-only", children: " of " }), pad(total)] }));
216
+ dir: "ltr", "aria-live": "polite", "aria-atomic": "true", className: cn("font-mono text-xs leading-none text-muted-foreground tabular-nums", className), ...props, children: [_jsx("span", { className: "text-foreground", children: pad(selectedIndex + 1) }), _jsx("span", { "aria-hidden": true, children: " / " }), _jsxs("span", { className: "sr-only", children: [" ", text.of, " "] }), pad(total)] }));
199
217
  }
200
218
  const vertical = orientation === "vertical";
201
219
  return (_jsx("div", { "data-slot": "carousel-dots", "data-variant": "ticks", "data-orientation": orientation, className: cn("flex items-center", vertical && "flex-col", className), ...props, children: Array.from({ length: snapCount }, (_, index) => {
@@ -1,6 +1,17 @@
1
1
  import * as React from "react";
2
2
  import * as RechartsPrimitive from "recharts";
3
3
  import type { LegendPayload } from "recharts";
4
+ /**
5
+ * The zon timing for a series that changes: spread it on `Line`, `Area`, `Bar`, `Pie`, `Radar`
6
+ * or `Scatter` (`<Area {...chartAnimation} … />`). Recharts' own defaults morph lines, areas and
7
+ * pies for 1.5s on a plain `ease`, so every new set of data drags; this ends in 300ms on the
8
+ * `--ease` curve (a strong ease-out). Recharts' `isAnimationActive="auto"` default still turns it
9
+ * off under `prefers-reduced-motion`.
10
+ */
11
+ export declare const chartAnimation: {
12
+ readonly animationDuration: 300;
13
+ readonly animationEasing: "cubic-bezier(0.16,1,0.3,1)";
14
+ };
4
15
  /** How one series is named and drawn. Keys are the `dataKey`s (or `nameKey` values) of the chart. */
5
16
  export interface ChartSeriesConfig {
6
17
  /** The series name shown in tooltips and legends. */
@@ -177,4 +188,13 @@ export interface ChartLegendContentProps {
177
188
  * or more series; a single series is named by the chart's title instead.
178
189
  */
179
190
  export declare function ChartLegendContent({ payload, verticalAlign, hideIcon, nameKey, className, }: ChartLegendContentProps): React.JSX.Element | null;
191
+ /**
192
+ * downsample — the points of a long series that a chart can show: for each of `buckets` runs of
193
+ * points, its first point and each series' lowest and highest, in order. A line keeps its shape,
194
+ * its peaks and its dips; a chart a few hundred pixels wide draws no more than that anyway, and
195
+ * Recharts takes seconds over tens of thousands of points.
196
+ *
197
+ * <LineChart data={downsample(readings, ["cpu", "memory"])}>
198
+ */
199
+ export declare function downsample<T extends Record<string, unknown>>(data: readonly T[], keys: readonly (keyof T & string)[], buckets?: number): T[];
180
200
  export {};
@@ -3,6 +3,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
4
  import * as RechartsPrimitive from "recharts";
5
5
  import { cn } from "../lib/cn.js";
6
+ import { useLocale } from "./locale.js";
7
+ /* ── Motion ────────────────────────────────────────────────────────────────── */
8
+ /**
9
+ * The zon timing for a series that changes: spread it on `Line`, `Area`, `Bar`, `Pie`, `Radar`
10
+ * or `Scatter` (`<Area {...chartAnimation} … />`). Recharts' own defaults morph lines, areas and
11
+ * pies for 1.5s on a plain `ease`, so every new set of data drags; this ends in 300ms on the
12
+ * `--ease` curve (a strong ease-out). Recharts' `isAnimationActive="auto"` default still turns it
13
+ * off under `prefers-reduced-motion`.
14
+ */
15
+ export const chartAnimation = {
16
+ animationDuration: 300,
17
+ animationEasing: "cubic-bezier(0.16,1,0.3,1)",
18
+ };
6
19
  const ChartContext = React.createContext(null);
7
20
  /** The config of the nearest `ChartContainer`. For custom tooltip or legend content. */
8
21
  export function useChart() {
@@ -81,7 +94,7 @@ export function ChartContainer({ id, config, palette = "mono", grid = "horizonta
81
94
  const value = React.useMemo(() => ({ config }), [config]);
82
95
  // Pies lift the slice under the pointer (ChartActiveSector): know where it is from the start.
83
96
  React.useEffect(track, []);
84
- return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { "data-slot": "chart", role: props["aria-label"] || props["aria-labelledby"] ? "figure" : undefined, "data-chart": chartId, "data-grid": grid, className: cn("relative flex aspect-video w-full min-w-0 justify-center font-body text-xs text-foreground-soft", className), style: { ...vars, ...style }, ...props, children: [rules ? _jsx("style", { children: `[data-chart="${chartId}"]{${rules}}` }) : null, _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: { width: 320, height: 180 }, children: children })] }) }));
97
+ return (_jsx(ChartContext.Provider, { value: value, children: _jsxs("div", { "data-slot": "chart", id: id, role: props["aria-label"] || props["aria-labelledby"] ? "figure" : undefined, "data-chart": chartId, "data-grid": grid, className: cn("relative flex aspect-video w-full min-w-0 justify-center font-body text-xs text-foreground-soft", className), style: { ...vars, ...style }, ...props, children: [rules ? _jsx("style", { children: `[data-chart="${chartId}"]{${rules}}` }) : null, _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: { width: 320, height: 180 }, children: children })] }) }));
85
98
  }
86
99
  /**
87
100
  * ChartGradient — the soft vertical fill under an area: the series colour fading to nothing.
@@ -227,6 +240,7 @@ export function ChartTooltip(props) {
227
240
  */
228
241
  export function ChartTooltipContent({ active, payload, label, indicator = "dot", hideLabel = false, hideIndicator = false, labelFormatter, valueFormatter, nameKey, labelKey, className, }) {
229
242
  const { config } = useChart();
243
+ const locale = useLocale();
230
244
  if (!active || !payload?.length)
231
245
  return null;
232
246
  const items = payload.filter((item) => item.type !== "none" && !item.hide);
@@ -250,10 +264,10 @@ export function ChartTooltipContent({ active, payload, label, indicator = "dot",
250
264
  const name = series?.label ?? item.name ?? key;
251
265
  const dash = indicator === "dashed" ? "3 2" : (series?.dash ?? item.strokeDasharray?.toString());
252
266
  const Icon = series?.icon;
253
- return (_jsxs("div", { "data-slot": "chart-tooltip-item", className: "flex min-h-4 items-center gap-2", children: [hideIndicator ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground" })) : (_jsx(ChartSwatch, { shape: indicator === "dot" ? "dot" : "line", color: color, dash: dash, pattern: series?.pattern })), _jsx("span", { className: "text-foreground-soft", children: name }), item.value != null ? (_jsx("span", { className: "ml-auto pl-4 font-mono text-xs text-foreground tabular-nums", children: valueFormatter
267
+ return (_jsxs("div", { "data-slot": "chart-tooltip-item", className: "flex min-h-4 items-center gap-2", children: [hideIndicator ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground" })) : (_jsx(ChartSwatch, { shape: indicator === "dot" ? "dot" : "line", color: color, dash: dash, pattern: series?.pattern })), _jsx("span", { className: "text-foreground-soft", children: name }), item.value != null ? (_jsx("span", { className: "ms-auto ps-4 font-mono text-xs text-foreground tabular-nums", children: valueFormatter
254
268
  ? valueFormatter(item.value, name, item)
255
269
  : typeof item.value === "number"
256
- ? item.value.toLocaleString()
270
+ ? item.value.toLocaleString(locale)
257
271
  : String(item.value) })) : null] }, `${key}-${index}`));
258
272
  }) })] }));
259
273
  }
@@ -284,3 +298,38 @@ export function ChartLegendContent({ payload, verticalAlign = "bottom", hideIcon
284
298
  return (_jsxs("li", { "data-slot": "chart-legend-item", "data-inactive": item.inactive ? "" : undefined, className: "flex items-center gap-1.5 font-mono text-[11px] leading-none text-muted-foreground data-inactive:opacity-50", children: [hideIcon ? null : Icon ? (_jsx(Icon, { className: "size-3 shrink-0" })) : (_jsx(ChartSwatch, { shape: item.type === "line" || series?.dash ? "line" : "dot", color: color, dash: dash, pattern: series?.pattern })), series?.label ?? item.value] }, `${key}-${index}`));
285
299
  }) }));
286
300
  }
301
+ /**
302
+ * downsample — the points of a long series that a chart can show: for each of `buckets` runs of
303
+ * points, its first point and each series' lowest and highest, in order. A line keeps its shape,
304
+ * its peaks and its dips; a chart a few hundred pixels wide draws no more than that anyway, and
305
+ * Recharts takes seconds over tens of thousands of points.
306
+ *
307
+ * <LineChart data={downsample(readings, ["cpu", "memory"])}>
308
+ */
309
+ export function downsample(data, keys, buckets = 600) {
310
+ if (data.length <= buckets * (keys.length * 2 + 1))
311
+ return [...data];
312
+ const size = data.length / buckets;
313
+ const picked = [];
314
+ for (let b = 0; b < buckets; b++) {
315
+ const from = Math.floor(b * size);
316
+ const to = Math.min(data.length, Math.floor((b + 1) * size));
317
+ const at = new Set([from]);
318
+ for (const key of keys) {
319
+ let low = from;
320
+ let high = from;
321
+ for (let i = from; i < to; i++) {
322
+ const value = Number(data[i][key]);
323
+ if (value < Number(data[low][key]))
324
+ low = i;
325
+ if (value > Number(data[high][key]))
326
+ high = i;
327
+ }
328
+ at.add(low).add(high);
329
+ }
330
+ picked.push(...[...at].sort((a, b) => a - b));
331
+ }
332
+ if (picked.at(-1) !== data.length - 1)
333
+ picked.push(data.length - 1);
334
+ return picked.map((i) => data[i]);
335
+ }
@@ -1,4 +1,14 @@
1
1
  import * as React from "react";
2
+ import { type CopyButtonMessages } from "./copy-button.js";
3
+ export interface CodeBlockMessages {
4
+ /** The copy button's name. Its confirmation comes from `copyButton`. */
5
+ copy: string;
6
+ }
7
+ declare module "./locale" {
8
+ interface Messages {
9
+ codeBlock: CodeBlockMessages;
10
+ }
11
+ }
2
12
  export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "children"> {
3
13
  /** The source to show. Alternatively pass it as the child string. */
4
14
  code?: string;
@@ -13,8 +23,8 @@ export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "ch
13
23
  */
14
24
  language?: string;
15
25
  /**
16
- * Colour the code by its `language`, in the zon theme. Needs a `CodeHighlightProvider` (from
17
- * `@zonsh/ui/code-highlight`) above it; without one, or for an unknown language, it stays mono.
26
+ * Colour the code by its `language`, in the zon theme. Default `true`; without a `language`, or
27
+ * for one Shiki does not know, the code stays mono either way.
18
28
  */
19
29
  highlight?: boolean;
20
30
  /** Show muted, mono line numbers. */
@@ -23,18 +33,18 @@ export interface CodeBlockProps extends Omit<React.ComponentProps<"figure">, "ch
23
33
  wrap?: boolean;
24
34
  /** Show the copy button. Defaults to `true`. */
25
35
  copyable?: boolean;
26
- /** Accessible names for the copy button and its confirmation (see `CopyButton`). */
27
- labels?: {
28
- copy?: string;
29
- copied?: string;
30
- failed?: string;
31
- };
36
+ /**
37
+ * Accessible names for the copy button and its confirmation (see `CopyButton`). A
38
+ * LocaleProvider sets `copy` for every CodeBlock (`messages.codeBlock`) and the confirmation
39
+ * for every CopyButton (`messages.copyButton`).
40
+ */
41
+ labels?: Partial<CopyButtonMessages>;
32
42
  }
33
43
  /**
34
44
  * CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
35
45
  * scrolling horizontally rather than wrapping. Give it a height or a max height and the code
36
- * scrolls under the header. Monochrome by default; `highlight` colours it by its `language` in
37
- * the zon theme, inside a `CodeHighlightProvider`.
46
+ * scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
47
+ * first time a block needs it); without one, or with `highlight={false}`, it stays mono.
38
48
  *
39
49
  * A **region** by default (square `surface-container`, part of the page); `variant="card"`
40
50
  * makes it a 20px object for a snippet that stands on its own. An optional header carries a
@@ -4,11 +4,13 @@ import * as React from "react";
4
4
  import { useCodeTokens } from "../lib/code-highlight.js";
5
5
  import { cn } from "../lib/cn.js";
6
6
  import { CopyButton } from "./copy-button.js";
7
+ import { useMessages } from "./locale.js";
8
+ const defaultMessages = { copy: "Copy code" };
7
9
  /**
8
10
  * CodeBlock — source code in Licht Mono 13px, 1.75 line height, `white-space: pre`, tab size 2,
9
11
  * scrolling horizontally rather than wrapping. Give it a height or a max height and the code
10
- * scrolls under the header. Monochrome by default; `highlight` colours it by its `language` in
11
- * the zon theme, inside a `CodeHighlightProvider`.
12
+ * scrolls under the header. With a `language`, it is coloured in the zon theme (Shiki, loaded the
13
+ * first time a block needs it); without one, or with `highlight={false}`, it stays mono.
12
14
  *
13
15
  * A **region** by default (square `surface-container`, part of the page); `variant="card"`
14
16
  * makes it a 20px object for a snippet that stands on its own. An optional header carries a
@@ -16,26 +18,66 @@ import { CopyButton } from "./copy-button.js";
16
18
  * people break: a theme of their own. Syntax colours are kinds of token, so they come from the
17
19
  * category tones (`--code-*`), never a palette brought in from an editor.
18
20
  */
19
- export function CodeBlock({ code, children, variant = "region", filename, language, lineNumbers = false, wrap = false, highlight = false, copyable = true, labels, className, ...props }) {
21
+ export function CodeBlock({ code, children, variant = "region", filename, language, lineNumbers = false, wrap = false, highlight = true, copyable = true, labels, className, ...props }) {
20
22
  const source = (code ?? children ?? "").replace(/\n$/, "");
21
23
  const { tokens, pending } = useCodeTokens(source, language, highlight);
22
- const lines = React.useMemo(() => (tokens ? tokens.map(renderTokens) : source.split("\n")), [tokens, source]);
24
+ const lines = React.useMemo(() => {
25
+ if (!tokens)
26
+ return source.split("\n");
27
+ const drawn = tokens.map(renderTokens);
28
+ // Long code takes its colours from the top down: the lines not coloured yet stay plain.
29
+ if (drawn.length > 0 && source.length > 0) {
30
+ const plain = source.split("\n");
31
+ for (let i = drawn.length; i < plain.length; i++)
32
+ drawn.push(plain[i]);
33
+ }
34
+ return drawn;
35
+ }, [tokens, source]);
36
+ const chunked = lines.length > CHUNKED_FROM;
37
+ const widest = React.useMemo(() => chunked && !wrap
38
+ ? source.split("\n").reduce((max, line) => Math.max(max, line.replace(/\t/g, " ").length), 0)
39
+ : 0, [chunked, wrap, source]);
23
40
  const hasHeader = filename != null || language != null;
24
- const copyButton = copyable && (_jsx(CopyButton, { value: source, labels: { ...labels, copy: labels?.copy ?? "Copy code" }, "data-slot": "code-block-copy", className: cn(!hasHeader && "absolute top-3 right-3 z-10") }));
25
- return (_jsxs("figure", { "data-slot": "code-block", "data-variant": variant, "data-highlighted": tokens ? "" : undefined, "data-highlight-pending": pending ? "" : undefined, className: cn("relative m-0 flex min-w-0 flex-col overflow-hidden text-foreground", variant === "card" ? "surface-card [--card-padding:0]" : "rounded-none surface-container", className), ...props, children: [hasHeader && (_jsxs("figcaption", { "data-slot": "code-block-header", className: cn("flex min-h-(--control-h) shrink-0 items-center justify-between gap-3 border-b border-border/60 pl-4",
41
+ const text = useMessages("codeBlock", defaultMessages);
42
+ const copyButton = copyable && (_jsx(CopyButton, { value: source, labels: { ...labels, copy: labels?.copy ?? text.copy }, "data-slot": "code-block-copy", className: cn(!hasHeader && "absolute top-3 right-3 z-10") }));
43
+ return (_jsxs("figure", { "data-slot": "code-block", "data-variant": variant, "data-highlighted": tokens ? "" : undefined, "data-highlight-pending": pending ? "" : undefined, className: cn("relative m-0 flex min-w-0 flex-col overflow-hidden text-foreground", variant === "card" ? "surface-card [--card-padding:0]" : "rounded-none surface-container", className), ...props, children: [hasHeader && (_jsxs("figcaption", { "data-slot": "code-block-header", className: cn("flex min-h-(--control-h) shrink-0 items-center justify-between gap-3 border-b border-border/60 ps-4",
26
44
  // With the copy button, the header is the button plus the same 8px above, below and
27
45
  // to the right, so the button sits as far from the top edge as from the right edge.
28
- copyable ? "py-2 pr-2" : "pr-4"), children: [_jsx("span", { className: "min-w-0 truncate eyebrow text-[11px] tracking-[0.12em] normal-case", children: filename }), _jsxs("span", { className: "flex shrink-0 items-center gap-3", children: [language && _jsx("span", { className: "eyebrow text-[11px]", children: language }), copyButton] })] })), !hasHeader && copyButton, _jsx("pre", { "data-slot": "code-block-pre",
46
+ copyable ? "py-2 pe-2" : "pe-4"), children: [_jsx("span", { className: "min-w-0 truncate eyebrow text-[11px] tracking-[0.12em] normal-case", children: filename }), _jsxs("span", { className: "flex shrink-0 items-center gap-3", children: [language && _jsx("span", { className: "eyebrow text-[11px]", children: language }), copyButton] })] })), !hasHeader && copyButton, _jsx("pre", { "data-slot": "code-block-pre",
29
47
  // Code reads left to right on a right-to-left page too: its brackets and commas stay put.
30
48
  dir: "ltr", tabIndex: 0, className: cn(
31
49
  // A height or max height on the block scrolls the code under the header, both ways.
32
- "m-0 min-h-0 grow overflow-auto bg-transparent px-4 py-4 font-mono text-[13px] leading-[1.75] [tab-size:2] focus-ring", wrap ? "[overflow-wrap:anywhere] whitespace-pre-wrap" : "whitespace-pre", !hasHeader && copyable && "pr-14"), children: _jsx("code", { className: cn("font-[inherit]", lineNumbers && "table min-w-full"), children: lineNumbers
33
- ? lines.map((line, i) => (_jsxs("span", { className: "table-row", children: [_jsx("span", { "aria-hidden": true, className: "table-cell w-[1%] pr-5 text-right text-control-muted tabular-nums select-none", children: i + 1 }), _jsx("span", { className: "table-cell", children: isEmpty(line) ? "\n" : line })] }, i)))
34
- : tokens
35
- ? lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i)))
36
- : source }) })] }));
50
+ "m-0 min-h-0 grow overflow-auto bg-transparent px-4 py-4 font-mono text-[13px] leading-[1.75] [tab-size:2] focus-ring", wrap ? "[overflow-wrap:anywhere] whitespace-pre-wrap" : "whitespace-pre", !hasHeader && copyable && "pr-14"), children: _jsx("code", { className: cn("font-[inherit]", chunked ? "block" : lineNumbers && "table min-w-full"),
51
+ // Chunks out of view are not laid out: the widest line keeps the width to scroll across.
52
+ style: widest
53
+ ? {
54
+ minWidth: `calc(${widest}ch + ${lineNumbers ? `${String(lines.length).length}ch + 1.25rem` : "0px"})`,
55
+ }
56
+ : undefined, children: chunked
57
+ ? Array.from({ length: Math.ceil(lines.length / CHUNK) }, (_, c) => (_jsx(CodeChunk, { from: c * CHUNK, lines: lines.slice(c * CHUNK, (c + 1) * CHUNK), numbers: lineNumbers ? String(lines.length).length : 0 }, c)))
58
+ : lineNumbers
59
+ ? lines.map((line, i) => (_jsxs("span", { className: "table-row", children: [_jsx("span", { "aria-hidden": true, className: "table-cell w-[1%] pr-5 text-right text-control-muted tabular-nums select-none", children: i + 1 }), _jsx("span", { className: "table-cell", children: isEmpty(line) ? "\n" : line })] }, i)))
60
+ : tokens
61
+ ? lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i)))
62
+ : source }) })] }));
37
63
  }
38
64
  const isEmpty = (line) => line === "" || (Array.isArray(line) && line.length === 0);
65
+ /** Code longer than this many lines is drawn in chunks of CHUNK lines, each laid out only near the view. */
66
+ const CHUNKED_FROM = 400;
67
+ const CHUNK = 100;
68
+ /**
69
+ * CHUNK lines of a long block, skipped by layout and paint while out of view (they stay in the
70
+ * page: found by the browser's search, selected and copied). Drawn again only when one of its
71
+ * lines changes, as colours arrive.
72
+ */
73
+ const CodeChunk = React.memo(function CodeChunk({ from, lines, numbers }) {
74
+ return (_jsx("span", { "data-slot": "code-block-chunk", className: "block [content-visibility:auto]", style: { containIntrinsicBlockSize: `auto ${lines.length * 1.75}em` }, children: numbers
75
+ ? lines.map((line, i) => (_jsxs("span", { className: "flex", children: [_jsx("span", { "aria-hidden": true, className: "shrink-0 pr-5 text-right text-control-muted tabular-nums select-none", style: { width: `calc(${numbers}ch + 1.25rem)` }, children: from + i + 1 }), _jsx("span", { children: isEmpty(line) ? "\n" : line })] }, i)))
76
+ : lines.map((line, i) => (_jsxs(React.Fragment, { children: [i > 0 && "\n", line] }, i))) }));
77
+ }, (a, b) => a.from === b.from &&
78
+ a.numbers === b.numbers &&
79
+ a.lines.length === b.lines.length &&
80
+ a.lines.every((line, i) => line === b.lines[i]));
39
81
  /**
40
82
  * Lines already drawn, by their tokens. The highlighter hands back the same tokens for lines that
41
83
  * did not change (code streaming in), and the same elements let React skip them.
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Collapsible as BaseCollapsible } from "@base-ui/react/collapsible";
4
4
  import { ChevronRightIcon } from "lucide-react";
5
- import { sx } from "../lib/cn.js";
5
+ import { sx, triggerSlot } from "../lib/cn.js";
6
6
  /**
7
7
  * Collapsible — one region that can be shown and hidden by a trigger.
8
8
  *
@@ -18,7 +18,7 @@ export function Collapsible({ className, ...props }) {
18
18
  }
19
19
  /** A mono text trigger with a rotating chevron. Use `render` to swap in a `Button`. */
20
20
  export function CollapsibleTrigger({ showIcon = true, className, children, ...props }) {
21
- return (_jsxs(BaseCollapsible.Trigger, { "data-slot": "collapsible-trigger", className: sx([
21
+ return (_jsxs(BaseCollapsible.Trigger, { ...triggerSlot("collapsible-trigger", props.render), className: sx([
22
22
  "group/collapsible-trigger inline-flex w-fit cursor-pointer items-center gap-2 py-1 font-mono text-[13px] text-foreground-soft focus-ring select-none",
23
23
  "transition-colors duration-(--duration) ease-(--ease) hover:text-foreground data-panel-open:text-foreground",
24
24
  "data-disabled:pointer-events-none data-disabled:opacity-50",
@@ -28,5 +28,5 @@ export function CollapsibleTrigger({ showIcon = true, className, children, ...pr
28
28
  }
29
29
  /** The hidden content. Height animates from `--collapsible-panel-height`. */
30
30
  export function CollapsiblePanel({ className, ...props }) {
31
- return (_jsx(BaseCollapsible.Panel, { "data-slot": "collapsible-panel", className: sx("h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-(--duration) ease-(--ease) data-ending-style:h-0 data-starting-style:h-0", className), ...props }));
31
+ return (_jsx(BaseCollapsible.Panel, { "data-slot": "collapsible-panel", className: sx("h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-(--duration-glide) ease-(--ease-glide) data-ending-style:h-0 data-starting-style:h-0", className), ...props }));
32
32
  }
@@ -1,5 +1,28 @@
1
1
  import * as React from "react";
2
2
  import { type PopoverContentProps } from "./popover.js";
3
+ export interface ColorPickerMessages {
4
+ /** The saturation × brightness area's name. */
5
+ area: string;
6
+ /** What screen readers call the area instead of "slider". */
7
+ areaRole: string;
8
+ /** The area's value, read out as it moves. */
9
+ areaValue: (saturation: number, brightness: number) => string;
10
+ /** The hue slider. */
11
+ hue: string;
12
+ /** The opacity slider. */
13
+ alpha: string;
14
+ /** The text field's name, by the format it writes. */
15
+ value: (format: ColorFormat) => string;
16
+ /** The group of preset swatches. */
17
+ presets: string;
18
+ /** ColorPicker's trigger while there is no colour. */
19
+ placeholder: string;
20
+ }
21
+ declare module "./locale" {
22
+ interface Messages {
23
+ colorPicker: ColorPickerMessages;
24
+ }
25
+ }
3
26
  export type ColorFormat = "hex" | "rgb" | "hsl" | "oklch";
4
27
  export type ColorPickerPreset = string | {
5
28
  value: string;
@@ -18,13 +41,12 @@ export interface ColorPickerPanelProps extends Omit<React.ComponentProps<"div">,
18
41
  /** Colours to pick in one click, under the value: values, or `{ value, label }` with a name. */
19
42
  presets?: ColorPickerPreset[];
20
43
  disabled?: boolean;
21
- /** Accessible names for the parts. */
22
- labels?: {
23
- area?: string;
24
- hue?: string;
25
- alpha?: string;
44
+ /**
45
+ * Accessible names for the parts — `input` names the text field whatever its format. A
46
+ * LocaleProvider sets them for every picker (`messages.colorPicker`).
47
+ */
48
+ labels?: Partial<ColorPickerMessages> & {
26
49
  input?: string;
27
- presets?: string;
28
50
  };
29
51
  }
30
52
  /**
@@ -45,7 +67,7 @@ export interface ColorSwatchProps extends React.ComponentProps<"span"> {
45
67
  export declare function ColorSwatch({ color, className, style, ...props }: ColorSwatchProps): React.JSX.Element;
46
68
  declare const triggerSizes: {
47
69
  readonly sm: "min-h-(--control-h-sm) gap-2 px-2.5 text-xs";
48
- readonly default: "min-h-(--control-h) gap-2.5 pr-2.5 pl-2.5 text-[13px]";
70
+ readonly default: "min-h-(--control-h) gap-2.5 px-2.5 text-[13px]";
49
71
  };
50
72
  export interface ColorPickerProps extends Pick<ColorPickerPanelProps, "value" | "defaultValue" | "onValueChange" | "format" | "alpha" | "presets" | "disabled" | "labels"> {
51
73
  /** `sm` (30px) for dense surfaces; `default` (38px) everywhere else. */
@@ -58,7 +80,7 @@ export interface ColorPickerProps extends Pick<ColorPickerPanelProps, "value" |
58
80
  */
59
81
  required?: boolean;
60
82
  id?: string;
61
- /** Shown in the trigger while there is no value. */
83
+ /** Shown in the trigger while there is no value. Default `labels.placeholder`. */
62
84
  placeholder?: string;
63
85
  open?: boolean;
64
86
  defaultOpen?: boolean;