@zonsh/ui 0.2.0 → 0.4.1

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -1,18 +1,40 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { Form as BaseForm } from "@base-ui/react/form";
4
+ import * as React from "react";
4
5
  import { cn, sx } from "../lib/cn.js";
6
+ import { LibraryErrorsContext } from "../lib/field-errors.js";
5
7
  /**
6
8
  * Form — a native `<form>` that collects `Field` validation and shows server errors.
7
9
  *
8
10
  * Fields stack with 20px between them. Pass `errors` (keyed by each `Field`'s `name`) to show
9
11
  * errors returned by the server, and use `onFormSubmit` to receive the values as an object.
10
12
  * End the form with `FormActions`, which puts the submit button on the right.
13
+ * With React Hook Form or TanStack Form, pass the library's submit handler to `onSubmit` and each
14
+ * field's error to `Field error`: the library validates every submit, the Form lays it out.
11
15
  * The rule people break: validating only on the server — add `required`, `type` and
12
16
  * `pattern` to the controls so people see what is wrong before they submit.
13
17
  */
14
- export function Form({ className, ...props }) {
15
- return (_jsx(BaseForm, { "data-slot": "form", className: sx("flex flex-col gap-5", className), ...props }));
18
+ export function Form({ className, onSubmit, onSubmitCapture, ...props }) {
19
+ /*
20
+ * Base UI stops a submit while a field is marked invalid, before `onSubmit` runs. A field marked
21
+ * by a library (`Field error`) could then stay so: the library never sees the submit that would
22
+ * check it again (React Hook Form checks an error that depends on another field only then). While
23
+ * any field shows such an error, the submit goes to `onSubmit` first, and the library decides.
24
+ */
25
+ const [libraryErrors] = React.useState(() => new Set());
26
+ const handled = React.useRef(false);
27
+ return (_jsx(LibraryErrorsContext.Provider, { value: libraryErrors, children: _jsx(BaseForm, { "data-slot": "form", className: sx("flex flex-col gap-5", className), onSubmitCapture: (event) => {
28
+ onSubmitCapture?.(event);
29
+ handled.current = !!onSubmit && libraryErrors.size > 0;
30
+ if (handled.current)
31
+ onSubmit?.(event);
32
+ }, onSubmit: (event) => {
33
+ if (handled.current)
34
+ handled.current = false;
35
+ else
36
+ onSubmit?.(event);
37
+ }, ...props }) }));
16
38
  }
17
39
  const actionAlign = {
18
40
  /** Actions on the right, the primary last. The default. */
@@ -59,6 +59,45 @@ export interface GraphValue {
59
59
  }
60
60
  /** `flow`: layered along `direction`. `tree`: tiers from the root. `network`: forces. `none`: as positioned. */
61
61
  export type GraphLayout = "flow" | "tree" | "network" | "none";
62
+ export interface GraphMessages {
63
+ /** The text field that renames a node, or a connection. */
64
+ nodeLabel: string;
65
+ edgeLabel: string;
66
+ /** What a new node of each kind is called until it is renamed. */
67
+ newNode: (kind: GraphNodeKind) => string;
68
+ /** A kind of node in the canvas menu's "Add here" list. */
69
+ kind: (kind: GraphNodeKind) => string;
70
+ addHere: string;
71
+ tidy: string;
72
+ fit: string;
73
+ zoomIn: string;
74
+ zoomOut: string;
75
+ addNode: string;
76
+ rename: string;
77
+ delete: string;
78
+ renameLabel: string;
79
+ addLabel: string;
80
+ reverse: string;
81
+ removeConnection: string;
82
+ /** The keys the menu shows beside Rename and Delete. */
83
+ enterKey: string;
84
+ deleteKey: string;
85
+ /** A connection as text, for screen readers: "Review to Ship: approved". */
86
+ connection: (from: string, to: string, directed: boolean) => string;
87
+ /** The controls' toolbar and the minimap. */
88
+ controls: string;
89
+ minimap: string;
90
+ /** What React Flow tells a screen reader on a focused node, edge or handle, and after a move. */
91
+ nodeHelp: string;
92
+ edgeHelp: string;
93
+ handle: string;
94
+ moved: (direction: string, x: number, y: number) => string;
95
+ }
96
+ declare module "./locale" {
97
+ interface Messages {
98
+ graph: GraphMessages;
99
+ }
100
+ }
62
101
  export interface GraphProps extends Omit<React.ComponentProps<"div">, "onChange" | "onSelect" | "children"> {
63
102
  nodes: GraphNode[];
64
103
  edges: GraphEdge[];
@@ -89,6 +128,8 @@ export interface GraphProps extends Omit<React.ComponentProps<"div">, "onChange"
89
128
  background?: "dots" | "lines" | "none";
90
129
  /** `region` (default): a square surface; `card`: the 20px object. */
91
130
  variant?: "region" | "card";
131
+ /** The editor's and the controls' words; a LocaleProvider sets them for every Graph. */
132
+ labels?: Partial<GraphMessages>;
92
133
  }
93
134
  /**
94
135
  * Graph — things and how they connect, on a canvas that pans and zooms: a flow of steps (BPMN
@@ -7,9 +7,62 @@ import { cn } from "../lib/cn.js";
7
7
  import { cssDuration } from "../lib/motion.js";
8
8
  import { LANE_HEADER, lanes, layered, network, dragSimulation, } from "../lib/graph-layout.js";
9
9
  import { Avatar } from "./avatar.js";
10
+ import { useMessages } from "./locale.js";
10
11
  import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuGroupLabel, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger, } from "./context-menu.js";
11
12
  import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "./toolbar.js";
12
13
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
14
+ /** Networks of up to this many nodes settle live around a dragged node. */
15
+ const LIVE_DRAG_MAX = 300;
16
+ const newNodes = {
17
+ task: "New step",
18
+ start: "Start",
19
+ end: "End",
20
+ event: "Event",
21
+ gateway: "Decide?",
22
+ note: "A note",
23
+ person: "New person",
24
+ entity: "New node",
25
+ group: "Group",
26
+ };
27
+ const kindNames = {
28
+ task: "Step",
29
+ start: "Start",
30
+ end: "End",
31
+ event: "Event",
32
+ gateway: "Decision",
33
+ note: "Note",
34
+ person: "Person",
35
+ entity: "Node",
36
+ group: "Group",
37
+ };
38
+ const defaultMessages = {
39
+ nodeLabel: "Node label",
40
+ edgeLabel: "Edge label",
41
+ newNode: (kind) => newNodes[kind],
42
+ kind: (kind) => kindNames[kind],
43
+ addHere: "Add here",
44
+ tidy: "Tidy up",
45
+ fit: "Fit to view",
46
+ zoomIn: "Zoom in",
47
+ zoomOut: "Zoom out",
48
+ addNode: "Add a node",
49
+ rename: "Rename",
50
+ delete: "Delete",
51
+ renameLabel: "Rename label",
52
+ addLabel: "Add a label",
53
+ reverse: "Reverse direction",
54
+ removeConnection: "Remove connection",
55
+ enterKey: "Enter",
56
+ deleteKey: "Del",
57
+ connection: (from, to, directed) => `${from} ${directed ? "to" : "and"} ${to}`,
58
+ controls: "Graph",
59
+ minimap: "Map of the graph",
60
+ // React Flow's own words.
61
+ nodeHelp: "Press enter or space to select a node. Press delete to remove it and escape to cancel.",
62
+ edgeHelp: "Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.",
63
+ handle: "Handle",
64
+ moved: (direction, x, y) => `Moved selected node ${direction}. New position, x: ${x}, y: ${y}`,
65
+ };
13
66
  const GraphContext = React.createContext(null);
14
67
  const useGraph = () => React.useContext(GraphContext);
15
68
  const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
@@ -169,7 +222,7 @@ function Handles() {
169
222
  }
170
223
  /** A label that turns into a field while it is being renamed. */
171
224
  function Label({ kind, id, value, className, }) {
172
- const { editing, setEditing, rename } = useGraph();
225
+ const { editing, setEditing, rename, text } = useGraph();
173
226
  const active = editing?.kind === kind && editing.id === id;
174
227
  const [draft, setDraft] = React.useState(value);
175
228
  React.useEffect(() => setDraft(value), [value, active]);
@@ -182,7 +235,7 @@ function Label({ kind, id, value, className, }) {
182
235
  };
183
236
  return (_jsx("input", {
184
237
  // nodrag / nopan: typing and selecting text never moves the canvas.
185
- className: cn("nodrag nopan min-w-0 border-0 bg-transparent p-0 text-inherit outline-none", className), "aria-label": kind === "node" ? "Node label" : "Edge label", autoFocus: true, value: draft, size: Math.max(4, draft.length), onChange: (event) => setDraft(event.currentTarget.value), onFocus: (event) => event.currentTarget.select(), onBlur: () => done(true), onKeyDown: (event) => {
238
+ className: cn("nodrag nopan min-w-0 border-0 bg-transparent p-0 text-inherit outline-none", className), "aria-label": kind === "node" ? text.nodeLabel : text.edgeLabel, autoFocus: true, value: draft, size: Math.max(4, draft.length), onChange: (event) => setDraft(event.currentTarget.value), onFocus: (event) => event.currentTarget.select(), onBlur: () => done(true), onKeyDown: (event) => {
186
239
  event.stopPropagation();
187
240
  if (event.key === "Enter")
188
241
  done(true);
@@ -352,42 +405,12 @@ function EdgeView(props) {
352
405
  return (_jsxs(_Fragment, { children: [_jsx(BaseEdge, { id: id, path: path, markerEnd: marker, interactionWidth: 18, "data-kind": kind, className: "zon-graph-edge", "data-dim": data?.dim ? "" : undefined,
353
406
  "data-lit": data?.lit || props.selected ? "" : undefined }), (edge.label || (editing?.kind === "edge" && editing.id === id)) && (_jsx(EdgeLabelRenderer, { children: _jsx("div", { "data-slot": "graph-edge-label", "data-edge": id, "data-dim": data?.dim ? "" : undefined, "data-lit": data?.lit || props.selected ? "" : undefined, className: "nodrag nopan pointer-events-auto absolute", style: { transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }, children: _jsx(Label, { kind: "edge", id: id, value: edge.label ?? "" }) }) }))] }));
354
407
  }
355
- /** What a new node of each kind is called until it is renamed. */
356
- const fresh = {
357
- task: "New step",
358
- start: "Start",
359
- end: "End",
360
- event: "Event",
361
- gateway: "Decide?",
362
- note: "A note",
363
- person: "New person",
364
- entity: "New node",
365
- group: "Group",
366
- };
367
408
  /** What the canvas menu offers to add, by layout. */
368
409
  const addable = {
369
- flow: [
370
- { kind: "task", label: "Step" },
371
- { kind: "gateway", label: "Decision" },
372
- { kind: "event", label: "Event" },
373
- { kind: "start", label: "Start" },
374
- { kind: "end", label: "End" },
375
- { kind: "note", label: "Note" },
376
- ],
377
- tree: [
378
- { kind: "person", label: "Person" },
379
- { kind: "task", label: "Step" },
380
- ],
381
- network: [
382
- { kind: "entity", label: "Node" },
383
- { kind: "person", label: "Person" },
384
- ],
385
- none: [
386
- { kind: "task", label: "Step" },
387
- { kind: "entity", label: "Node" },
388
- { kind: "person", label: "Person" },
389
- { kind: "note", label: "Note" },
390
- ],
410
+ flow: ["task", "gateway", "event", "start", "end", "note"],
411
+ tree: ["person", "task"],
412
+ network: ["entity", "person"],
413
+ none: ["task", "entity", "person", "note"],
391
414
  };
392
415
  const nodeTypes = { zon: NodeView, "zon-group": GroupView };
393
416
  const edgeTypes = { zon: EdgeView };
@@ -406,7 +429,17 @@ const edgeTypes = { zon: EdgeView };
406
429
  export function Graph(props) {
407
430
  return (_jsx(ReactFlowProvider, { children: _jsx(GraphCanvas, { ...props }) }));
408
431
  }
409
- function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", direction: directionProp, editable = false, onChange, onSelect, newNodeKind, minimap = false, controls = true, background = "dots", variant = "region", className, ...props }) {
432
+ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", direction: directionProp, editable = false, onChange, onSelect, newNodeKind, minimap = false, controls = true, background = "dots", variant = "region", labels, className, ...props }) {
433
+ const text = useMessages("graph", defaultMessages, labels);
434
+ const textRef = React.useRef(text);
435
+ textRef.current = text;
436
+ const ariaLabelConfig = React.useMemo(() => ({
437
+ "node.a11yDescription.default": text.nodeHelp,
438
+ "edge.a11yDescription.default": text.edgeHelp,
439
+ "node.a11yDescription.ariaLiveMessage": ({ direction, x, y, }) => text.moved(direction, x, y),
440
+ "handle.ariaLabel": text.handle,
441
+ "minimap.ariaLabel": text.minimap,
442
+ }), [text]);
410
443
  const direction = directionProp ?? (layout === "tree" ? "down" : "right");
411
444
  const flow = useReactFlow();
412
445
  const markers = React.useId().replace(/[^a-zA-Z0-9]/g, "");
@@ -534,7 +567,11 @@ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", dire
534
567
  const addNode = React.useCallback((at, as) => {
535
568
  const s = latest.current;
536
569
  const kind = as ?? newNodeKind ?? (layout === "network" ? "entity" : "task");
537
- const node = { id: `n${Date.now().toString(36)}`, label: fresh[kind], kind };
570
+ const node = {
571
+ id: `n${Date.now().toString(36)}`,
572
+ label: textRef.current.newNode(kind),
573
+ kind,
574
+ };
538
575
  const size = sizeOf(node, layout);
539
576
  // Without a point, the middle of what is in view.
540
577
  const box = frame.current?.getBoundingClientRect();
@@ -641,7 +678,9 @@ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", dire
641
678
  const reduce = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
642
679
  const onNodeDragStart = React.useCallback((_, node) => {
643
680
  tidying.current?.stop();
644
- if (layout !== "network" || reduce())
681
+ // A network of hundreds of nodes moves only the node dragged: settling it live would take
682
+ // longer than a frame at every frame.
683
+ if (layout !== "network" || reduce() || latest.current.nodes.length > LIVE_DRAG_MAX)
645
684
  return;
646
685
  // A drag that starts while the last one settles takes over from it: one simulation at a time.
647
686
  physics.current?.stop();
@@ -721,7 +760,7 @@ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", dire
721
760
  setSelected(nodes.filter((n) => n.type !== "zon-group").map((n) => n.id));
722
761
  onSelect?.({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) });
723
762
  }, [onSelect]);
724
- const context = React.useMemo(() => ({ layout, direction, editable, markers, editing, setEditing, rename }), [layout, direction, editable, markers, editing, rename]);
763
+ const context = React.useMemo(() => ({ text, layout, direction, editable, markers, editing, setEditing, rename }), [text, layout, direction, editable, markers, editing, rename]);
725
764
  /* The context menu: what was right-clicked. */
726
765
  const [target, setTarget] = React.useState(null);
727
766
  const pick = (event) => {
@@ -766,8 +805,8 @@ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", dire
766
805
  };
767
806
  const targetEdge = target?.type === "edge" ? state.edges.find((e) => e.id === target.id) : undefined;
768
807
  const stepped = layout === "flow" || layout === "tree";
769
- const labels = React.useMemo(() => new Map(state.nodes.map((n) => [n.id, n.data.node.label])), [state.nodes]);
770
- const canvas = (_jsxs(ReactFlow, { nodes: shown.nodes, edges: shown.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: editable ? onConnect : undefined, onConnectEnd: editable ? onConnectEnd : undefined, onNodeMouseEnter: (_, n) => n.type !== "zon-group" && setHovered(n.id), onNodeMouseLeave: () => setHovered(null), onNodeDragStart: onNodeDragStart, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop, onSelectionChange: onSelectionChange, nodesConnectable: editable, edgesReconnectable: false, deleteKeyCode: editable ? ["Backspace", "Delete"] : null, connectionLineType: stepped ? ConnectionLineType.SmoothStep : ConnectionLineType.Straight, fitView: true, fitViewOptions: { padding: 0.18, maxZoom: 1.15 }, minZoom: 0.2, maxZoom: 2, proOptions: { hideAttribution: true }, "aria-describedby": describedBy, children: [background !== "none" && (_jsx(Background, { variant: background === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Dots, gap: background === "lines" ? 32 : 20, size: 1 })), minimap && (_jsx(MiniMap, { position: "bottom-right", style: { width: 152, height: 100 }, pannable: true, zoomable: true, nodeBorderRadius: 4, ariaLabel: "Map of the graph" })), controls && (_jsx(Panel, { position: "bottom-left", children: _jsx(GraphControls, { editable: editable, tidy: layout === "none" ? undefined : tidy, add: () => addNode() }) }))] }));
808
+ const nodeLabels = React.useMemo(() => new Map(state.nodes.map((n) => [n.id, n.data.node.label])), [state.nodes]);
809
+ const canvas = (_jsxs(ReactFlow, { nodes: shown.nodes, edges: shown.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: editable ? onConnect : undefined, onConnectEnd: editable ? onConnectEnd : undefined, onNodeMouseEnter: (_, n) => n.type !== "zon-group" && setHovered(n.id), onNodeMouseLeave: () => setHovered(null), onNodeDragStart: onNodeDragStart, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop, onSelectionChange: onSelectionChange, nodesConnectable: editable, edgesReconnectable: false, deleteKeyCode: editable ? ["Backspace", "Delete"] : null, connectionLineType: stepped ? ConnectionLineType.SmoothStep : ConnectionLineType.Straight, fitView: true, fitViewOptions: { padding: 0.18, maxZoom: 1.15 }, minZoom: 0.2, maxZoom: 2, proOptions: { hideAttribution: true }, ariaLabelConfig: ariaLabelConfig, "aria-describedby": describedBy, children: [background !== "none" && (_jsx(Background, { variant: background === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Dots, gap: background === "lines" ? 32 : 20, size: 1 })), minimap && (_jsx(MiniMap, { position: "bottom-right", style: { width: 152, height: 100 }, pannable: true, zoomable: true, nodeBorderRadius: 4, ariaLabel: text.minimap })), controls && (_jsx(Panel, { position: "bottom-left", children: _jsx(GraphControls, { text: text, editable: editable, tidy: layout === "none" ? undefined : tidy, add: () => addNode() }) }))] }));
771
810
  return (_jsx(GraphContext.Provider, { value: context, children: _jsxs("div", { ref: frame, "data-slot": "graph", "data-layout": layout, "data-editable": editable ? "" : undefined, className: cn("relative h-[min(40rem,80svh)] w-full overflow-hidden", variant === "card" ? "surface-card [--card-padding:0]" : "surface-container", className), onKeyDown: (event) => {
772
811
  // Editable: Enter on a focused node opens its label.
773
812
  const node = event.target.closest(".react-flow__node");
@@ -775,12 +814,12 @@ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", dire
775
814
  return;
776
815
  event.preventDefault();
777
816
  setEditing({ kind: "node", id: node.dataset.id });
778
- }, ...props, children: [_jsx("svg", { "aria-hidden": true, className: "absolute size-0", children: _jsx("defs", { children: ["rest", "lit"].map((tone) => (_jsx("marker", { id: `${markers}-${tone}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M1 1.5 L9 5 L1 8.5 Z", "data-tone": tone, className: "zon-graph-arrow" }) }, tone))) }) }), editable ? (_jsxs(ContextMenu, { children: [_jsx(ContextMenuTrigger, { className: "absolute inset-0", onContextMenuCapture: pick, children: canvas }), _jsxs(ContextMenuContent, { children: [target?.type === "pane" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuGroup, { children: [_jsx(ContextMenuGroupLabel, { children: "Add here" }), addable[layout].map((a) => (_jsxs(ContextMenuItem, { onClick: () => addNode(target.at, a.kind), children: [_jsx(PlusIcon, {}), a.label] }, a.kind)))] }), _jsx(ContextMenuSeparator, {}), layout !== "none" && (_jsxs(ContextMenuItem, { onClick: tidy, children: [_jsx(WandSparklesIcon, {}), "Tidy up"] })), _jsxs(ContextMenuItem, { onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: [_jsx(MaximizeIcon, {}), "Fit to view"] })] })), (target?.type === "node" || target?.type === "group") && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "node", id: target.id }), children: [_jsx(PencilIcon, {}), "Rename", _jsx(ContextMenuShortcut, { children: "Enter" })] }), target.type === "node" && (_jsxs(_Fragment, { children: [_jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeNode(target.id), children: [_jsx(Trash2Icon, {}), "Delete", _jsx(ContextMenuShortcut, { children: "Del" })] })] }))] })), target?.type === "edge" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "edge", id: target.id }), children: [_jsx(PencilIcon, {}), targetEdge?.data?.edge.label ? "Rename label" : "Add a label"] }), targetEdge && isDirected(targetEdge.data.edge, layout) && (_jsxs(ContextMenuItem, { onClick: () => reverse(target.id), children: [_jsx(ArrowLeftRightIcon, {}), "Reverse direction"] })), _jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeEdge(target.id), children: [_jsx(Trash2Icon, {}), "Remove connection", _jsx(ContextMenuShortcut, { children: "Del" })] })] }))] })] })) : (canvas), _jsx("ul", { id: describedBy, className: "sr-only", children: state.edges.map((e) => (_jsxs("li", { children: [labels.get(e.source), " ", isDirected(e.data.edge, layout) ? "to" : "and", " ", labels.get(e.target), e.data.edge.label ? `: ${e.data.edge.label}` : ""] }, e.id))) })] }) }));
817
+ }, ...props, children: [_jsx("svg", { "aria-hidden": true, className: "absolute size-0", children: _jsx("defs", { children: ["rest", "lit"].map((tone) => (_jsx("marker", { id: `${markers}-${tone}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M1 1.5 L9 5 L1 8.5 Z", "data-tone": tone, className: "zon-graph-arrow" }) }, tone))) }) }), editable ? (_jsxs(ContextMenu, { children: [_jsx(ContextMenuTrigger, { className: "absolute inset-0", onContextMenuCapture: pick, children: canvas }), _jsxs(ContextMenuContent, { children: [target?.type === "pane" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuGroup, { children: [_jsx(ContextMenuGroupLabel, { children: text.addHere }), addable[layout].map((kind) => (_jsxs(ContextMenuItem, { onClick: () => addNode(target.at, kind), children: [_jsx(PlusIcon, {}), text.kind(kind)] }, kind)))] }), _jsx(ContextMenuSeparator, {}), layout !== "none" && (_jsxs(ContextMenuItem, { onClick: tidy, children: [_jsx(WandSparklesIcon, {}), text.tidy] })), _jsxs(ContextMenuItem, { onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: [_jsx(MaximizeIcon, {}), text.fit] })] })), (target?.type === "node" || target?.type === "group") && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "node", id: target.id }), children: [_jsx(PencilIcon, {}), text.rename, _jsx(ContextMenuShortcut, { children: text.enterKey })] }), target.type === "node" && (_jsxs(_Fragment, { children: [_jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeNode(target.id), children: [_jsx(Trash2Icon, {}), text.delete, _jsx(ContextMenuShortcut, { children: text.deleteKey })] })] }))] })), target?.type === "edge" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "edge", id: target.id }), children: [_jsx(PencilIcon, {}), targetEdge?.data?.edge.label ? text.renameLabel : text.addLabel] }), targetEdge && isDirected(targetEdge.data.edge, layout) && (_jsxs(ContextMenuItem, { onClick: () => reverse(target.id), children: [_jsx(ArrowLeftRightIcon, {}), text.reverse] })), _jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeEdge(target.id), children: [_jsx(Trash2Icon, {}), text.removeConnection, _jsx(ContextMenuShortcut, { children: text.deleteKey })] })] }))] })] })) : (canvas), _jsx("ul", { id: describedBy, className: "sr-only", children: state.edges.map((e) => (_jsxs("li", { children: [text.connection(nodeLabels.get(e.source) ?? e.source, nodeLabels.get(e.target) ?? e.target, isDirected(e.data.edge, layout)), e.data.edge.label ? `: ${e.data.edge.label}` : ""] }, e.id))) })] }) }));
779
818
  }
780
819
  function ControlButton({ label, onClick, children, }) {
781
820
  return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": label, onClick: onClick }), children: children }), _jsx(TooltipContent, { side: "top", children: label })] }));
782
821
  }
783
- function GraphControls({ editable, tidy, add }) {
822
+ function GraphControls({ text, editable, tidy, add, }) {
784
823
  const flow = useReactFlow();
785
- return (_jsxs(Toolbar, { "aria-label": "Graph", "data-slot": "graph-controls", children: [_jsxs(ToolbarGroup, { children: [_jsx(ControlButton, { label: "Zoom in", onClick: () => void flow.zoomIn({ duration: 200 }), children: _jsx(PlusIcon, {}) }), _jsx(ControlButton, { label: "Zoom out", onClick: () => void flow.zoomOut({ duration: 200 }), children: _jsx(MinusIcon, {}) }), _jsx(ControlButton, { label: "Fit to view", onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: _jsx(MaximizeIcon, {}) })] }), (editable || tidy) && _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [editable && (_jsx(ControlButton, { label: "Add a node", onClick: add, children: _jsx(CircleDotIcon, {}) })), tidy && (_jsx(ControlButton, { label: "Tidy up", onClick: tidy, children: _jsx(WandSparklesIcon, {}) }))] })] }));
824
+ return (_jsxs(Toolbar, { "aria-label": text.controls, "data-slot": "graph-controls", children: [_jsxs(ToolbarGroup, { children: [_jsx(ControlButton, { label: text.zoomIn, onClick: () => void flow.zoomIn({ duration: 200 }), children: _jsx(PlusIcon, {}) }), _jsx(ControlButton, { label: text.zoomOut, onClick: () => void flow.zoomOut({ duration: 200 }), children: _jsx(MinusIcon, {}) }), _jsx(ControlButton, { label: text.fit, onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: _jsx(MaximizeIcon, {}) })] }), (editable || tidy) && _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [editable && (_jsx(ControlButton, { label: text.addNode, onClick: add, children: _jsx(CircleDotIcon, {}) })), tidy && (_jsx(ControlButton, { label: text.tidy, onClick: tidy, children: _jsx(WandSparklesIcon, {}) }))] })] }));
786
825
  }
@@ -150,7 +150,7 @@ export function SpecSheet({ tone = "night", index, eyebrow, titleBlock, marks =
150
150
  onPointerLeave?.(event);
151
151
  }, ...props, children: [hasCaption ? (_jsxs("figcaption", { "data-slot": "spec-sheet-caption", className: cn("absolute inset-x-0 top-0 z-3 flex items-start justify-between gap-4 pt-3.5 font-mono text-[10px] leading-[1.4] tracking-[0.14em] text-(--sheet-caption) uppercase sm:pt-4",
152
152
  // Clear the corner crosshairs when they are shown.
153
- marks ? "px-9" : "px-4 sm:px-5"), children: [_jsx("span", { "data-slot": "spec-sheet-index", className: "tabular-nums", children: index }), eyebrow != null ? (_jsx("span", { "data-slot": "spec-sheet-eyebrow", className: "text-right", children: eyebrow })) : null] })) : null, _jsx("div", { "data-slot": "spec-sheet-drawing", className: cn("absolute inset-0 z-1 grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)] place-items-center p-[max(2.75rem,9%)]", drawingClassName), children: children }), showGrain ? _jsx("div", { "aria-hidden": true, "data-still": "", className: "grain z-2" }) : null, lit ? _jsx("div", { "aria-hidden": true, "data-slot": "spec-sheet-light" }) : null, marks ? (_jsxs(_Fragment, { children: [_jsx(CornerMark, { className: "top-2.5 left-2.5" }), _jsx(CornerMark, { className: "top-2.5 right-2.5" }), _jsx(CornerMark, { className: "bottom-2.5 left-2.5" }), _jsx(CornerMark, { className: "right-2.5 bottom-2.5" })] })) : null, titleBlock?.length ? (_jsx("dl", { "data-slot": "spec-sheet-title-block", className: cn("absolute z-3 m-0 grid grid-cols-2 border-t border-l border-(--sheet-rule) font-mono leading-none", marks ? "right-7 bottom-7" : "right-3 bottom-3 sm:right-4 sm:bottom-4"), children: titleBlock.map((entry, i) => (_jsxs("div", { className: "flex min-w-[64px] flex-col gap-1 border-r border-b border-(--sheet-rule) px-2 py-1.5 last:odd:col-span-2", children: [_jsx("dt", { className: "text-[9px] tracking-[0.14em] text-(--sheet-caption) uppercase", children: entry.label }), _jsx("dd", { className: "m-0 text-[10px] text-foreground tabular-nums", children: entry.value })] }, i))) })) : null] }));
153
+ marks ? "px-9" : "px-4 sm:px-5"), children: [_jsx("span", { "data-slot": "spec-sheet-index", className: "tabular-nums", children: index }), eyebrow != null ? (_jsx("span", { "data-slot": "spec-sheet-eyebrow", className: "text-end", children: eyebrow })) : null] })) : null, _jsx("div", { "data-slot": "spec-sheet-drawing", className: cn("absolute inset-0 z-1 grid grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)] place-items-center p-[max(2.75rem,9%)]", drawingClassName), children: children }), showGrain ? _jsx("div", { "aria-hidden": true, "data-still": "", className: "grain z-2" }) : null, lit ? _jsx("div", { "aria-hidden": true, "data-slot": "spec-sheet-light" }) : null, marks ? (_jsxs(_Fragment, { children: [_jsx(CornerMark, { className: "top-2.5 left-2.5" }), _jsx(CornerMark, { className: "top-2.5 right-2.5" }), _jsx(CornerMark, { className: "bottom-2.5 left-2.5" }), _jsx(CornerMark, { className: "right-2.5 bottom-2.5" })] })) : null, titleBlock?.length ? (_jsx("dl", { "data-slot": "spec-sheet-title-block", className: cn("absolute z-3 m-0 grid grid-cols-2 border-t border-l border-(--sheet-rule) font-mono leading-none", marks ? "right-7 bottom-7" : "right-3 bottom-3 sm:right-4 sm:bottom-4"), children: titleBlock.map((entry, i) => (_jsxs("div", { className: "flex min-w-[64px] flex-col gap-1 border-r border-b border-(--sheet-rule) px-2 py-1.5 last:odd:col-span-2", children: [_jsx("dt", { className: "text-[9px] tracking-[0.14em] text-(--sheet-caption) uppercase", children: entry.label }), _jsx("dd", { className: "m-0 text-[10px] text-foreground tabular-nums", children: entry.value })] }, i))) })) : null] }));
154
154
  }
155
155
  /**
156
156
  * SpecSheetGrid — the light-table wall: a 12-column bento of `SpecSheet` tiles with square
@@ -2,6 +2,17 @@ import { Button as BaseButton } from "@base-ui/react/button";
2
2
  import { Field as BaseField } from "@base-ui/react/field";
3
3
  import { Input as BaseInput } from "@base-ui/react/input";
4
4
  import * as React from "react";
5
+ export interface InputGroupMessages {
6
+ /** InputGroupPasswordToggle's name, whether the password is shown or not. */
7
+ showPassword: string;
8
+ /** InputGroupClearButton's name. */
9
+ clear: string;
10
+ }
11
+ declare module "./locale" {
12
+ interface Messages {
13
+ inputGroup: InputGroupMessages;
14
+ }
15
+ }
5
16
  declare const groupSizes: {
6
17
  readonly sm: "min-h-(--control-h-sm) text-[13px]";
7
18
  readonly default: "min-h-(--control-h) text-base sm:text-[15px]";
@@ -64,10 +75,10 @@ declare const buttonVariants: {
64
75
  };
65
76
  declare const buttonSizes: {
66
77
  /** 24px — fits the dense group, or a quiet action in the default one. */
67
- readonly sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs";
78
+ readonly sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs leading-none";
68
79
  /** 30px — fits the 38px group with a 3px inset, like a segment. */
69
- readonly default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px]";
70
- readonly "icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-3.5";
80
+ readonly default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px] leading-none";
81
+ readonly "icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-[min(14px,calc(var(--control-inset-sm)-4px))]";
71
82
  readonly icon: "size-(--control-inset) rounded-full p-0";
72
83
  };
73
84
  export interface InputGroupButtonProps extends BaseButton.Props {
@@ -90,7 +101,7 @@ export interface InputGroupPasswordToggleProps extends Omit<InputGroupButtonProp
90
101
  onVisibleChange: (visible: boolean) => void;
91
102
  /**
92
103
  * The button's name, the same whether the password is shown or not: `aria-pressed` says which.
93
- * Default "Show password".
104
+ * Default "Show password", or `messages.inputGroup.showPassword` from a LocaleProvider.
94
105
  */
95
106
  label?: string;
96
107
  /** @deprecated A toggle keeps one name: use `label`. Only `show` is read, as that name. */
@@ -114,7 +125,7 @@ export interface InputGroupClearButtonProps extends Omit<InputGroupButtonProps,
114
125
  * its change event, for an uncontrolled input.
115
126
  */
116
127
  onClear?: () => void;
117
- /** The button's name. Default "Clear". Say what it clears: "Clear search". */
128
+ /** The button's name. Default "Clear" (`messages.inputGroup.clear`). Say what it clears: "Clear search". */
118
129
  label?: string;
119
130
  }
120
131
  /**
@@ -8,6 +8,8 @@ import * as React from "react";
8
8
  import { cn, sx } from "../lib/cn.js";
9
9
  import { mergeRefs } from "../lib/merge-refs.js";
10
10
  import { cssDuration } from "../lib/motion.js";
11
+ import { useMessages } from "./locale.js";
12
+ const defaultMessages = { showPassword: "Show password", clear: "Clear" };
11
13
  const groupSizes = {
12
14
  sm: "min-h-(--control-h-sm) text-[13px]",
13
15
  default: "min-h-(--control-h) text-base sm:text-[15px]",
@@ -97,11 +99,13 @@ const buttonVariants = {
97
99
  primary: "material-primary",
98
100
  };
99
101
  const buttonSizes = {
102
+ // `leading-none` after the size: a font size given later would drop it, and a 1.5 line would
103
+ // keep the button from fitting a theme with smaller controls.
100
104
  /** 24px — fits the dense group, or a quiet action in the default one. */
101
- sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs",
105
+ sm: "min-h-(--control-inset-sm) gap-1 rounded-(--input-group-button-radius) px-2 text-xs leading-none",
102
106
  /** 30px — fits the 38px group with a 3px inset, like a segment. */
103
- default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px]",
104
- "icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-3.5",
107
+ default: "min-h-(--control-inset) gap-1.5 rounded-(--input-group-button-radius) px-2.5 text-[13px] leading-none",
108
+ "icon-sm": "size-(--control-inset-sm) rounded-full p-0 [&_svg:not([class*='size-'])]:size-[min(14px,calc(var(--control-inset-sm)-4px))]",
105
109
  icon: "size-(--control-inset) rounded-full p-0",
106
110
  };
107
111
  /**
@@ -128,7 +132,10 @@ export function InputGroupButton({ variant = "secondary", size = "default", clas
128
132
  * a day never means waiting. Only a press of the toggle plays it; reduced motion skips it.
129
133
  */
130
134
  let measurer = null;
131
- /** Where the field's text runs, in the input's own pixels: from its left padding to its end. */
135
+ /**
136
+ * Where the field's text runs, in the input's own pixels: from its start padding to its end — the
137
+ * left one, or the right one in a right-to-left field.
138
+ */
132
139
  function textSpan(input) {
133
140
  const style = getComputedStyle(input);
134
141
  measurer ??= document.createElement("canvas").getContext("2d");
@@ -139,25 +146,36 @@ function textSpan(input) {
139
146
  measurer.letterSpacing = style.letterSpacing;
140
147
  width = measurer.measureText(text).width;
141
148
  }
149
+ const rtl = style.direction === "rtl";
150
+ if (rtl) {
151
+ const right = input.clientWidth - parseFloat(style.paddingRight) - input.scrollLeft;
152
+ return { left: Math.max(0, right - width), right, width: input.clientWidth, rtl };
153
+ }
142
154
  const left = parseFloat(style.paddingLeft) - input.scrollLeft;
143
- return { left, right: Math.min(input.clientWidth, left + width), width: input.clientWidth };
155
+ return { left, right: Math.min(input.clientWidth, left + width), width: input.clientWidth, rtl };
144
156
  }
145
157
  /**
146
158
  * A mask twice the field's width with a soft edge at its middle, slid so the edge travels from
147
159
  * just before the text's start to just past its end — or back, to erase it (`out`).
148
160
  */
149
161
  function sweepFrames(input, out = false) {
150
- const { left, right, width } = textSpan(input);
162
+ const { left, right, width, rtl } = textSpan(input);
151
163
  const soft = 16;
152
164
  const mask = {
153
- maskImage: `linear-gradient(90deg, #000 calc(50% - ${soft}px), transparent calc(50% + ${soft}px))`,
165
+ // Right to left, the shown half is the right one and the edge travels from the text's right.
166
+ maskImage: `linear-gradient(${rtl ? 270 : 90}deg, #000 calc(50% - ${soft}px), transparent calc(50% + ${soft}px))`,
154
167
  maskSize: `${width * 2}px 100%`,
155
168
  maskRepeat: "no-repeat",
156
169
  };
157
- const frames = [
158
- { ...mask, maskPosition: `${left - soft - width}px 0` },
159
- { ...mask, maskPosition: `${right + soft - width}px 0` },
160
- ];
170
+ const frames = rtl
171
+ ? [
172
+ { ...mask, maskPosition: `${right + soft - width}px 0` },
173
+ { ...mask, maskPosition: `${left - soft - width}px 0` },
174
+ ]
175
+ : [
176
+ { ...mask, maskPosition: `${left - soft - width}px 0` },
177
+ { ...mask, maskPosition: `${right + soft - width}px 0` },
178
+ ];
161
179
  return out ? frames.reverse() : frames;
162
180
  }
163
181
  /** The input this part shares an InputGroup with. */
@@ -173,6 +191,7 @@ const groupInput = (el) => el
173
191
  * Switch the input's `type` with `visible`.
174
192
  */
175
193
  export function InputGroupPasswordToggle({ visible, onVisibleChange, label, labels, ref, onClick, ...props }) {
194
+ const text = useMessages("inputGroup", defaultMessages);
176
195
  const own = React.useRef(null);
177
196
  const pressed = React.useRef(false);
178
197
  const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
@@ -185,12 +204,12 @@ export function InputGroupPasswordToggle({ visible, onVisibleChange, label, labe
185
204
  const input = groupInput(own.current);
186
205
  if (!input)
187
206
  return;
188
- const duration = cssDuration(input) * 2.2;
207
+ const duration = cssDuration(input) * 2;
189
208
  if (!duration)
190
209
  return;
191
210
  input.animate(sweepFrames(input), { duration, easing: "cubic-bezier(0.33, 1, 0.68, 1)" });
192
211
  }, [visible]);
193
- return (_jsx(InputGroupButton, { ref: refs, "data-password-toggle": "", variant: "ghost", size: "icon", "aria-label": label ?? labels?.show ?? "Show password", "aria-pressed": visible, onClick: (event) => {
212
+ return (_jsx(InputGroupButton, { ref: refs, "data-password-toggle": "", variant: "ghost", size: "icon", "aria-label": label ?? labels?.show ?? text.showPassword, "aria-pressed": visible, onClick: (event) => {
194
213
  pressed.current = true;
195
214
  onVisibleChange(!visible);
196
215
  onClick?.(event);
@@ -215,7 +234,8 @@ function EyeSlashIcon({ slashed }) {
215
234
  * field. The button fades out while the field is empty and back in when there is text, instead of
216
235
  * popping in and out. Reduced motion clears at once.
217
236
  */
218
- export function InputGroupClearButton({ onClear, label = "Clear", ref, className, ...props }) {
237
+ export function InputGroupClearButton({ onClear, label, ref, className, ...props }) {
238
+ const text = useMessages("inputGroup", defaultMessages);
219
239
  const own = React.useRef(null);
220
240
  const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
221
241
  const [empty, setEmpty] = React.useState(true);
@@ -285,7 +305,7 @@ export function InputGroupClearButton({ onClear, label = "Clear", ref, className
285
305
  release();
286
306
  };
287
307
  };
288
- return (_jsx(InputGroupButton, { ref: refs, "data-clear-button": "", "data-empty": empty ? "" : undefined, variant: "ghost", size: "icon", "aria-label": label, "aria-hidden": empty || undefined, tabIndex: empty ? -1 : undefined, onClick: clear, className: cn(
308
+ return (_jsx(InputGroupButton, { ref: refs, "data-clear-button": "", "data-empty": empty ? "" : undefined, variant: "ghost", size: "icon", "aria-label": label ?? text.clear, "aria-hidden": empty || undefined, tabIndex: empty ? -1 : undefined, onClick: clear, className: cn(
289
309
  // The fade rides the material's own transition list (--material-motion), which a transition
290
310
  // utility would replace.
291
311
  "[--material-motion:opacity_var(--duration)_var(--ease),scale_var(--duration)_var(--ease)] data-empty:pointer-events-none data-empty:scale-75 data-empty:opacity-0", className), ...props, children: _jsx(XIcon, {}) }));
@@ -1,7 +1,7 @@
1
1
  import { Input as BaseInput } from "@base-ui/react/input";
2
2
  declare const sizes: {
3
- readonly sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 file:h-6";
4
- readonly default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] file:h-(--control-h-sm)";
3
+ readonly sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 [&[type=file]]:leading-none file:h-(--control-inset-sm)";
4
+ readonly default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] [&[type=file]]:leading-none file:h-(--control-inset)";
5
5
  };
6
6
  export interface InputProps extends Omit<BaseInput.Props, "size"> {
7
7
  /** `sm` (30px) for dense surfaces; `default` (38px) everywhere else. */
@@ -3,8 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { Input as BaseInput } from "@base-ui/react/input";
4
4
  import { sx } from "../lib/cn.js";
5
5
  const sizes = {
6
- sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 file:h-6",
7
- default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] file:h-(--control-h-sm)",
6
+ sm: "min-h-(--control-h-sm) px-2.5 text-[13px] [&[type=file]]:p-0.5 [&[type=file]]:leading-none file:h-(--control-inset-sm)",
7
+ default: "min-h-(--control-h) px-3.5 text-base sm:text-[15px] [&[type=file]]:p-[3px] [&[type=file]]:leading-none file:h-(--control-inset)",
8
8
  };
9
9
  /**
10
10
  * Input — a recessed single-line field. 10px radius, 38px default, 30px dense, full width of
@@ -17,7 +17,7 @@ export function Input({ size = "default", className, ...props }) {
17
17
  // A file input's "Choose file" is a small raised button inside the field, inset like an
18
18
  // InputGroup button (30px in 38, 24px in 30, 7px corners); the file name stays quiet.
19
19
  "[&[type=file]]:cursor-pointer [&[type=file]]:text-muted-foreground",
20
- "file:mr-3 file:cursor-pointer file:rounded-item file:border-0 file:bg-control-surface file:bg-linear-to-b file:from-control-inner-edge file:to-transparent file:px-3 file:font-body file:text-[13px] file:font-medium file:text-foreground file:shadow-raised file:hover:bg-control-hover",
20
+ "file:me-3 file:cursor-pointer file:rounded-item file:border-0 file:bg-control-surface file:bg-linear-to-b file:from-control-inner-edge file:to-transparent file:px-3 file:font-body file:text-[13px] file:font-medium file:text-foreground file:shadow-raised file:hover:bg-control-hover",
21
21
  // The search field's clear button (×) is a button: it takes the pointer.
22
22
  "[&::-webkit-search-cancel-button]:cursor-pointer",
23
23
  sizes[size],
@@ -1,6 +1,23 @@
1
1
  import type * as React from "react";
2
2
  import { formatShortcut, useShortcutKeys } from "../lib/platform.js";
3
3
  export { formatShortcut, useShortcutKeys };
4
+ /**
5
+ * The modifier keys as keyboards other than Apple's print them, which differ by language
6
+ * (German keyboards print "Strg" for Ctrl). Apple keyboards print symbols, the same everywhere.
7
+ */
8
+ export interface KbdMessages {
9
+ ctrl: string;
10
+ shift: string;
11
+ alt: string;
12
+ enter: string;
13
+ }
14
+ declare module "./locale" {
15
+ interface Messages {
16
+ kbd: KbdMessages;
17
+ }
18
+ }
19
+ /** The key names a LocaleProvider sets, for `keyNames` and `formatShortcut` of your own. */
20
+ export declare function useKeyNames(): KbdMessages;
4
21
  /**
5
22
  * The key-cap look as a class string, for elements that must not be a `<kbd>` — e.g. an
6
23
  * "Esc" hint that is really a close button: `<button className={kbdClassName}>Esc</button>`.
@@ -2,7 +2,13 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { cn } from "../lib/cn.js";
4
4
  import { formatShortcut, keyNames, useShortcutKeys } from "../lib/platform.js";
5
+ import { useMessages } from "./locale.js";
5
6
  export { formatShortcut, useShortcutKeys };
7
+ const defaultMessages = { ctrl: "Ctrl", shift: "Shift", alt: "Alt", enter: "Enter" };
8
+ /** The key names a LocaleProvider sets, for `keyNames` and `formatShortcut` of your own. */
9
+ export function useKeyNames() {
10
+ return useMessages("kbd", defaultMessages);
11
+ }
6
12
  /**
7
13
  * The key-cap look as a class string, for elements that must not be a `<kbd>` — e.g. an
8
14
  * "Esc" hint that is really a close button: `<button className={kbdClassName}>Esc</button>`.
@@ -32,7 +38,8 @@ export function KbdGroup({ className, ...props }) {
32
38
  */
33
39
  export function KbdShortcut({ keys, ...props }) {
34
40
  const { mod, hasKeyboard } = useShortcutKeys();
41
+ const names = useKeyNames();
35
42
  if (!hasKeyboard)
36
43
  return null;
37
- return (_jsx(KbdGroup, { ...props, children: keyNames(keys, mod).map((key, i) => (_jsx(Kbd, { children: key }, i))) }));
44
+ return (_jsx(KbdGroup, { ...props, children: keyNames(keys, mod, names).map((key, i) => (_jsx(Kbd, { children: key }, i))) }));
38
45
  }