@snap-rail/ui 0.1.1 → 0.3.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 (45) hide show
  1. package/lib/charts.js +12 -5
  2. package/lib/components/index.js +2195 -0
  3. package/lib/contract.js +138 -62
  4. package/lib/fallback.js +21 -4
  5. package/lib/index.js +4287 -261
  6. package/lib/runtime.js +206 -77
  7. package/lib/settings-pages/index.js +1326 -0
  8. package/lib/settings.js +122 -72
  9. package/lib/types/charts.d.ts +1 -1
  10. package/lib/types/charts.js +5 -5
  11. package/lib/types/components/alert.d.ts +57 -0
  12. package/lib/types/components/alert.js +46 -0
  13. package/lib/types/components/button.js +2 -2
  14. package/lib/types/components/combobox.d.ts +45 -0
  15. package/lib/types/components/combobox.js +108 -0
  16. package/lib/types/components/controls.d.ts +74 -11
  17. package/lib/types/components/controls.js +67 -24
  18. package/lib/types/components/dialog.js +1 -1
  19. package/lib/types/components/form-rhf.d.ts +56 -0
  20. package/lib/types/components/form-rhf.js +74 -0
  21. package/lib/types/components/form.d.ts +33 -5
  22. package/lib/types/components/form.js +22 -6
  23. package/lib/types/components/index.d.ts +8 -0
  24. package/lib/types/components/index.js +8 -0
  25. package/lib/types/components/input.d.ts +11 -5
  26. package/lib/types/components/input.js +34 -7
  27. package/lib/types/components/layout.d.ts +28 -6
  28. package/lib/types/components/layout.js +86 -13
  29. package/lib/types/components/overlay.d.ts +110 -0
  30. package/lib/types/components/overlay.js +185 -0
  31. package/lib/types/components/schema-form.d.ts +3 -1
  32. package/lib/types/components/schema-form.js +46 -40
  33. package/lib/types/components/slider.d.ts +18 -0
  34. package/lib/types/components/slider.js +15 -0
  35. package/lib/types/components/surface.js +12 -12
  36. package/lib/types/contract.d.ts +55 -30
  37. package/lib/types/contract.js +55 -30
  38. package/lib/types/runtime.js +3 -2
  39. package/lib/types/settings-pages/appearance.js +2 -2
  40. package/lib/types/settings-pages/plugins.js +2 -2
  41. package/lib/types/utils.d.ts +7 -1
  42. package/lib/types/utils.js +7 -1
  43. package/package.json +14 -7
  44. package/src/styles/base.css +315 -5
  45. package/src/styles/default.css +194 -6
@@ -0,0 +1,2195 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import * as SeparatorPrimitive from "@radix-ui/react-separator";
3
+ import { Slot } from "@radix-ui/react-slot";
4
+ import { createContext, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
5
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
6
+ import * as PopoverPrimitive from "@radix-ui/react-popover";
7
+ import * as ToastPrimitive from "@radix-ui/react-toast";
8
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
9
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
10
+ import * as LabelPrimitive from "@radix-ui/react-label";
11
+ import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
12
+ import * as SelectPrimitive from "@radix-ui/react-select";
13
+ import * as SwitchPrimitive from "@radix-ui/react-switch";
14
+ import * as TabsPrimitive from "@radix-ui/react-tabs";
15
+ import * as DialogPrimitive from "@radix-ui/react-dialog";
16
+ import { Controller, Controller as Controller$1, FormProvider, FormProvider as FormProvider$1, useController, useFieldArray, useForm, useFormContext, useFormState, useFormState as useFormState$1, useWatch } from "react-hook-form";
17
+ import { zodResolver } from "@hookform/resolvers/zod";
18
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
19
+ import * as SliderPrimitive from "@radix-ui/react-slider";
20
+ //#region lib/types/utils.js
21
+ /**
22
+ * Small helpers shared by the headless semantic components: class merging and
23
+ * the stable `data-snap-*` anatomy that skins target.
24
+ *
25
+ * @module @snap-rail/ui/utils
26
+ */
27
+ /** Join truthy class names. */
28
+ function cn(...values) {
29
+ return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
30
+ }
31
+ /**
32
+ * The anatomy attributes every semantic component renders. The identity is
33
+ * component-owned: components spread these AFTER caller props so a composite
34
+ * can never mask a host part (a masked `button.root` loses every skin rule
35
+ * and falls back to the UA default look). Composites tag their own wrappers
36
+ * instead of pushing `part()` into a child component's props.
37
+ */
38
+ function part(component, name) {
39
+ return {
40
+ "data-snap-component": component,
41
+ "data-snap-part": `${component}.${name}`
42
+ };
43
+ }
44
+ /** Map a semantic size token to a control-height CSS variable. */
45
+ function controlHeight(size) {
46
+ return `var(--snap-control-height-${size})`;
47
+ }
48
+ /** Map a semantic spacing token to a CSS variable. */
49
+ function space(token) {
50
+ return `var(--snap-space-${token})`;
51
+ }
52
+ //#endregion
53
+ //#region lib/types/components/alert.js
54
+ /**
55
+ * Attention surfaces: alerts (inline banners), separators, skeletons, and
56
+ * lists. Read-only primitives; the skin owns their visuals through the
57
+ * `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
58
+ *
59
+ * @module @snap-rail/ui/components/alert
60
+ */
61
+ /** An inline status banner for results and failures. */
62
+ function Alert({ intent = "neutral", className, children, ...props }) {
63
+ return jsx("div", {
64
+ role: "alert",
65
+ className: cn("snap-alert", className),
66
+ "data-intent": intent,
67
+ ...props,
68
+ ...part("alert", "root"),
69
+ children
70
+ });
71
+ }
72
+ /** The alert heading line. */
73
+ function AlertTitle({ className, children, ...props }) {
74
+ return jsx("h5", {
75
+ className: cn("snap-alert-title", className),
76
+ ...props,
77
+ ...part("alert", "title"),
78
+ children
79
+ });
80
+ }
81
+ /** The alert body text. */
82
+ function AlertDescription({ className, children, ...props }) {
83
+ return jsx("div", {
84
+ className: cn("snap-alert-description", className),
85
+ ...props,
86
+ ...part("alert", "description"),
87
+ children
88
+ });
89
+ }
90
+ /** A themed rule between sections. */
91
+ function Separator({ orientation = "horizontal", className, ...props }) {
92
+ return jsx(SeparatorPrimitive.Root, {
93
+ orientation,
94
+ className: cn("snap-separator", className),
95
+ ...props,
96
+ ...part("separator", "root")
97
+ });
98
+ }
99
+ /** A neutral loading placeholder shaped by the skin. */
100
+ function Skeleton({ variant = "block", className, ...props }) {
101
+ return jsx("div", {
102
+ className: cn("snap-skeleton", className),
103
+ "data-variant": variant,
104
+ "aria-hidden": "true",
105
+ ...props,
106
+ ...part("skeleton", "root")
107
+ });
108
+ }
109
+ /** A vertical collection of {@link ListItem} rows. */
110
+ function List({ divided = false, className, children, ...props }) {
111
+ return jsx("ul", {
112
+ className: cn("snap-list", className),
113
+ "data-divided": divided || void 0,
114
+ ...props,
115
+ ...part("list", "root"),
116
+ children
117
+ });
118
+ }
119
+ /** One list row with leading/trailing slots. */
120
+ function ListItem({ leading, trailing, selected = false, disabled = false, onClick, className, children, ...props }) {
121
+ const interactive = onClick !== void 0 && !disabled;
122
+ const activate = (event) => {
123
+ if (event.key === "Enter" || event.key === " ") {
124
+ event.preventDefault();
125
+ onClick?.();
126
+ }
127
+ };
128
+ return jsxs("li", {
129
+ className: cn("snap-list-item", className),
130
+ "data-selected": selected || void 0,
131
+ "data-interactive": interactive || void 0,
132
+ "data-disabled": disabled || void 0,
133
+ "aria-disabled": disabled || void 0,
134
+ ...interactive ? {
135
+ role: "button",
136
+ tabIndex: 0,
137
+ onClick,
138
+ onKeyDown: activate
139
+ } : {},
140
+ ...props,
141
+ ...part("list", "item"),
142
+ children: [
143
+ leading !== void 0 && jsx("span", {
144
+ ...part("list", "leading"),
145
+ children: leading
146
+ }),
147
+ jsx("span", {
148
+ ...part("list", "content"),
149
+ style: {
150
+ flex: 1,
151
+ minWidth: 0
152
+ },
153
+ children
154
+ }),
155
+ trailing !== void 0 && jsx("span", {
156
+ ...part("list", "trailing"),
157
+ children: trailing
158
+ })
159
+ ]
160
+ });
161
+ }
162
+ //#endregion
163
+ //#region lib/types/components/button.js
164
+ /**
165
+ * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
166
+ * `button.root`, `button.label`, `button.icon`, and `button.spinner` parts;
167
+ * intent/emphasis/size are data attributes a skin styles.
168
+ *
169
+ * @module @snap-rail/ui/components/button
170
+ */
171
+ /** A spinner that inherits the current text colour. */
172
+ function Spinner(props) {
173
+ return jsxs("svg", {
174
+ ...part("button", "spinner"),
175
+ className: cn("snap-spinner", props.className),
176
+ viewBox: "0 0 24 24",
177
+ "aria-hidden": "true",
178
+ children: [jsx("circle", {
179
+ cx: "12",
180
+ cy: "12",
181
+ r: "9",
182
+ fill: "none",
183
+ stroke: "currentColor",
184
+ strokeWidth: "3",
185
+ opacity: "0.25"
186
+ }), jsx("path", {
187
+ d: "M21 12a9 9 0 0 0-9-9",
188
+ fill: "none",
189
+ stroke: "currentColor",
190
+ strokeWidth: "3",
191
+ strokeLinecap: "round"
192
+ })]
193
+ });
194
+ }
195
+ /** A themed button; `asChild` composes the behaviour onto a child element. */
196
+ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading = false, icon, iconPosition = "start", asChild = false, disabled, className, children, type, ...props }) {
197
+ const Component = asChild ? Slot : "button";
198
+ const content = asChild ? children : jsxs(Fragment, { children: [
199
+ icon !== void 0 && iconPosition === "start" && jsx("span", {
200
+ ...part("button", "icon"),
201
+ children: icon
202
+ }),
203
+ children !== void 0 && jsx("span", {
204
+ ...part("button", "label"),
205
+ children
206
+ }),
207
+ icon !== void 0 && iconPosition === "end" && jsx("span", {
208
+ ...part("button", "icon"),
209
+ children: icon
210
+ }),
211
+ loading && jsx(Spinner, {})
212
+ ] });
213
+ return jsx(Component, {
214
+ ...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
215
+ className: cn("snap-button", className),
216
+ "data-intent": intent,
217
+ "data-emphasis": emphasis,
218
+ "data-size": size,
219
+ "data-loading": loading || void 0,
220
+ "data-disabled": disabled === true || void 0,
221
+ "aria-busy": loading || void 0,
222
+ disabled: !asChild ? disabled === true || loading : void 0,
223
+ ...props,
224
+ ...part("button", "root"),
225
+ children: content
226
+ });
227
+ }
228
+ /** A square glyph button with a mandatory accessible label. */
229
+ function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
230
+ return jsx("button", {
231
+ type: "button",
232
+ className: cn("snap-icon-button", className),
233
+ "data-intent": intent,
234
+ "data-emphasis": emphasis,
235
+ "data-size": size,
236
+ "data-active": active || void 0,
237
+ "aria-label": label,
238
+ "aria-pressed": active || void 0,
239
+ ...props,
240
+ ...part("icon-button", "root"),
241
+ children: jsx("span", {
242
+ ...part("icon-button", "icon"),
243
+ "aria-hidden": "true",
244
+ children: icon
245
+ })
246
+ });
247
+ }
248
+ //#endregion
249
+ //#region lib/types/components/input.js
250
+ /**
251
+ * Text-entry semantics: the wrapper owns the anatomy (prefix/suffix/clear),
252
+ * the native field keeps keyboard and IME behaviour. Skins style the parts.
253
+ *
254
+ * @module @snap-rail/ui/components/input
255
+ */
256
+ /** A single-line text field with semantic prefix/suffix slots. Layout
257
+ * `style`/`className` dress the wrapper — the visible control; the native
258
+ * field already stretches inside it. */
259
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
260
+ return jsxs("div", {
261
+ ...part(componentName, "root"),
262
+ className: cn("snap-input", className),
263
+ style,
264
+ "data-size": size,
265
+ "data-invalid": invalid || void 0,
266
+ "data-disabled": disabled === true || void 0,
267
+ children: [
268
+ prefix !== void 0 && jsx("span", {
269
+ ...part(componentName, "prefix"),
270
+ children: prefix
271
+ }),
272
+ jsx("input", {
273
+ className: cn("snap-input-field", fieldClassName),
274
+ disabled,
275
+ "aria-invalid": invalid || void 0,
276
+ ...props,
277
+ ...part(componentName, "field")
278
+ }),
279
+ onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
280
+ ...part(componentName, "clear"),
281
+ type: "button",
282
+ className: "snap-input-clear",
283
+ "aria-label": "清除",
284
+ onClick: onClear,
285
+ children: "×"
286
+ }),
287
+ suffix !== void 0 && jsx("span", {
288
+ ...part(componentName, "suffix"),
289
+ children: suffix
290
+ })
291
+ ]
292
+ });
293
+ }
294
+ /** A multi-line text field. Like {@link Input}, layout `style`/`className`
295
+ * dress the wrapper; the field stretches inside it. */
296
+ function Textarea({ size = "md", invalid = false, fieldClassName, className, style, disabled, ...props }) {
297
+ return jsx("div", {
298
+ ...part("textarea", "root"),
299
+ className: cn("snap-textarea", className),
300
+ style,
301
+ "data-size": size,
302
+ "data-invalid": invalid || void 0,
303
+ "data-disabled": disabled === true || void 0,
304
+ children: jsx("textarea", {
305
+ className: cn("snap-textarea-field", fieldClassName),
306
+ disabled,
307
+ "aria-invalid": invalid || void 0,
308
+ ...props,
309
+ ...part("textarea", "field")
310
+ })
311
+ });
312
+ }
313
+ /** A numeric field with touch steppers: `step-up`/`step-down` commit through
314
+ * the normal `onChange` (a native input event on the field), clamped to
315
+ * `min`/`max`. */
316
+ function NumberInput({ min, max, step = 1, size = "md", invalid = false, fieldClassName, className, style, disabled, value, onChange, ...props }) {
317
+ const fieldRef = useRef(null);
318
+ const current = typeof value === "number" ? value : void 0;
319
+ const stepBy = (delta) => {
320
+ const field = fieldRef.current;
321
+ if (field === null || disabled === true) return;
322
+ const parsed = typeof value === "number" ? value : Number(field.value);
323
+ let next = (Number.isFinite(parsed) ? parsed : min ?? 0) + delta * step;
324
+ if (min !== void 0 && next < min) next = min;
325
+ if (max !== void 0 && next > max) next = max;
326
+ (Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(field, String(next));
327
+ field.dispatchEvent(new Event("input", { bubbles: true }));
328
+ };
329
+ return jsxs("div", {
330
+ ...part("number-input", "root"),
331
+ className: cn("snap-input", "snap-number-input", className),
332
+ style,
333
+ "data-size": size,
334
+ "data-invalid": invalid || void 0,
335
+ "data-disabled": disabled === true || void 0,
336
+ children: [jsx("input", {
337
+ ref: fieldRef,
338
+ className: cn("snap-input-field", fieldClassName),
339
+ type: "number",
340
+ inputMode: "decimal",
341
+ disabled,
342
+ "aria-invalid": invalid || void 0,
343
+ value,
344
+ onChange,
345
+ ...min !== void 0 ? { min } : {},
346
+ ...max !== void 0 ? { max } : {},
347
+ ...step !== void 0 ? { step } : {},
348
+ ...props,
349
+ ...part("number-input", "field")
350
+ }), jsxs("span", {
351
+ className: "snap-number-input-steps",
352
+ children: [jsx("button", {
353
+ ...part("number-input", "step-up"),
354
+ type: "button",
355
+ tabIndex: -1,
356
+ className: "snap-number-input-step",
357
+ "aria-label": "增大",
358
+ disabled: disabled === true || current !== void 0 && max !== void 0 && current >= max,
359
+ onClick: () => stepBy(1),
360
+ children: "+"
361
+ }), jsx("button", {
362
+ ...part("number-input", "step-down"),
363
+ type: "button",
364
+ tabIndex: -1,
365
+ className: "snap-number-input-step",
366
+ "aria-label": "减小",
367
+ disabled: disabled === true || current !== void 0 && min !== void 0 && current <= min,
368
+ onClick: () => stepBy(-1),
369
+ children: "-"
370
+ })]
371
+ })]
372
+ });
373
+ }
374
+ //#endregion
375
+ //#region lib/types/components/overlay.js
376
+ /**
377
+ * Overlay semantics over Radix: tooltips, popovers, dropdown menus, and
378
+ * toasts. Behaviour/keyboard/focus handling stays here; skins target the
379
+ * stable parts (`tooltip.*`, `popover.*`, `menu.*`, `toast.*`) and state
380
+ * attributes. The imperative toast() helper pairs with the <Toaster/> the
381
+ * runtime mounts in every surface root.
382
+ *
383
+ * @module @snap-rail/ui/components/overlay
384
+ */
385
+ /** The tooltip root; wraps `TooltipTrigger`/`TooltipContent` and owns delay. */
386
+ function Tooltip({ delayDuration, ...props }) {
387
+ return jsx(TooltipPrimitive.Root, {
388
+ ...props,
389
+ delayDuration: delayDuration ?? 300
390
+ });
391
+ }
392
+ /** The tooltip provider; the runtime mounts one, pages only need it standalone. */
393
+ function TooltipProvider(props) {
394
+ return jsx(TooltipPrimitive.Provider, { ...props });
395
+ }
396
+ /** The tooltip trigger; wraps its child and anchors the bubble. */
397
+ function TooltipTrigger(props) {
398
+ return jsx(TooltipPrimitive.Trigger, {
399
+ ...props,
400
+ ...part("tooltip", "trigger")
401
+ });
402
+ }
403
+ /** The portalled tooltip bubble. */
404
+ function TooltipContent({ side = "top", sideOffset = 6, className, children, ...props }) {
405
+ return jsx(TooltipPrimitive.Portal, { children: jsx(TooltipPrimitive.Content, {
406
+ className: cn("snap-tooltip", className),
407
+ side,
408
+ sideOffset,
409
+ ...props,
410
+ ...part("tooltip", "content"),
411
+ children
412
+ }) });
413
+ }
414
+ /** The popover root. */
415
+ const Popover = PopoverPrimitive.Root;
416
+ /** The popover trigger; wraps its child and toggles the panel. */
417
+ function PopoverTrigger(props) {
418
+ return jsx(PopoverPrimitive.Trigger, {
419
+ ...props,
420
+ ...part("popover", "trigger")
421
+ });
422
+ }
423
+ /** An element the panel positions against without toggling it. */
424
+ const PopoverAnchor = PopoverPrimitive.Anchor;
425
+ /** Closes the popover from inside the panel. */
426
+ function PopoverClose(props) {
427
+ return jsx(PopoverPrimitive.Close, { ...props });
428
+ }
429
+ /** Whether the element can hold a text caret (the anchored-combobox opener). */
430
+ function isEditableElement(element) {
431
+ if (element === null || !(element instanceof HTMLElement)) return false;
432
+ return element.tagName === "INPUT" || element.tagName === "TEXTAREA" || element.isContentEditable;
433
+ }
434
+ /**
435
+ * The portalled popover panel, with the two focus dead ends Radix leaves
436
+ * open in anchored mode: on open, the FocusScope default steals the focus
437
+ * from the field a combobox is typing into; on close, the default handler
438
+ * focuses the trigger ref — which is `null` without a `PopoverTrigger`, so
439
+ * focus strands on `body` and every keystroke dies. The wrapper remembers
440
+ * the element that opened the panel and returns focus there; when that
441
+ * element is editable it also keeps the focus in it while the panel is
442
+ * open. Trigger-mode popovers behave exactly as Radix does (the opener IS
443
+ * the trigger).
444
+ */
445
+ function PopoverContent({ side = "bottom", align = "center", sideOffset = 6, autoFocusOnOpen, className, children, onOpenAutoFocus, onCloseAutoFocus, onInteractOutside, ...props }) {
446
+ const openerRef = useRef(null);
447
+ const interactedOutsideRef = useRef(false);
448
+ const handleOpenAutoFocus = (event) => {
449
+ openerRef.current = document.activeElement;
450
+ interactedOutsideRef.current = false;
451
+ onOpenAutoFocus?.(event);
452
+ if (event.defaultPrevented) return;
453
+ if (autoFocusOnOpen === false || autoFocusOnOpen === void 0 && isEditableElement(openerRef.current)) event.preventDefault();
454
+ };
455
+ const handleCloseAutoFocus = (event) => {
456
+ onCloseAutoFocus?.(event);
457
+ if (event.defaultPrevented) return;
458
+ if (interactedOutsideRef.current) return;
459
+ const opener = openerRef.current;
460
+ if (opener !== null && opener !== document.body && opener.isConnected) {
461
+ event.preventDefault();
462
+ opener.focus({ preventScroll: true });
463
+ }
464
+ };
465
+ const handleInteractOutside = (event) => {
466
+ interactedOutsideRef.current = true;
467
+ onInteractOutside?.(event);
468
+ };
469
+ return jsx(PopoverPrimitive.Portal, { children: jsx(PopoverPrimitive.Content, {
470
+ className: cn("snap-popover", className),
471
+ side,
472
+ align,
473
+ sideOffset,
474
+ onOpenAutoFocus: handleOpenAutoFocus,
475
+ onCloseAutoFocus: handleCloseAutoFocus,
476
+ onInteractOutside: handleInteractOutside,
477
+ ...props,
478
+ ...part("popover", "content"),
479
+ children
480
+ }) });
481
+ }
482
+ /** The dropdown menu root. */
483
+ const Menu = DropdownMenuPrimitive.Root;
484
+ /** The menu trigger; wraps its child and toggles the dropdown. */
485
+ function MenuTrigger(props) {
486
+ return jsx(DropdownMenuPrimitive.Trigger, {
487
+ ...props,
488
+ ...part("menu", "trigger")
489
+ });
490
+ }
491
+ /** The portalled dropdown list. */
492
+ function MenuContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
493
+ return jsx(DropdownMenuPrimitive.Portal, { children: jsx(DropdownMenuPrimitive.Content, {
494
+ className: cn("snap-menu", className),
495
+ side,
496
+ align,
497
+ sideOffset,
498
+ ...props,
499
+ ...part("menu", "content"),
500
+ children
501
+ }) });
502
+ }
503
+ /** One menu action. */
504
+ function MenuItem({ className, children, ...props }) {
505
+ return jsx(DropdownMenuPrimitive.Item, {
506
+ className: cn("snap-menu-item", className),
507
+ ...props,
508
+ ...part("menu", "item"),
509
+ children
510
+ });
511
+ }
512
+ /** A checkable menu action with an indicator slot. */
513
+ function MenuCheckboxItem({ className, children, ...props }) {
514
+ return jsxs(DropdownMenuPrimitive.CheckboxItem, {
515
+ className: cn("snap-menu-item", className),
516
+ ...props,
517
+ ...part("menu", "checkbox-item"),
518
+ children: [jsx(DropdownMenuPrimitive.ItemIndicator, {
519
+ ...part("menu", "item-indicator"),
520
+ className: "snap-menu-indicator",
521
+ children: "✓"
522
+ }), children]
523
+ });
524
+ }
525
+ /** A non-interactive group heading. */
526
+ function MenuLabel({ className, children, ...props }) {
527
+ return jsx(DropdownMenuPrimitive.Label, {
528
+ className: cn("snap-menu-label", className),
529
+ ...props,
530
+ ...part("menu", "label"),
531
+ children
532
+ });
533
+ }
534
+ /** A group container for items. */
535
+ function MenuGroup(props) {
536
+ return jsx(DropdownMenuPrimitive.Group, { ...props });
537
+ }
538
+ /** A horizontal rule between menu sections. */
539
+ function MenuSeparator({ className, ...props }) {
540
+ return jsx(DropdownMenuPrimitive.Separator, {
541
+ className: cn("snap-menu-separator", className),
542
+ ...props,
543
+ ...part("menu", "separator")
544
+ });
545
+ }
546
+ let toastNextId = 1;
547
+ let toastRecords = [];
548
+ const toastListeners = /* @__PURE__ */ new Set();
549
+ function toastEmit() {
550
+ for (const listener of toastListeners) listener();
551
+ }
552
+ function toastDismiss(id) {
553
+ toastRecords = toastRecords.filter((record) => record.id !== id);
554
+ toastEmit();
555
+ }
556
+ /** Enqueue a toast on the runtime-mounted {@link Toaster}s. */
557
+ function toast(entry) {
558
+ const id = toastNextId++;
559
+ toastRecords = [...toastRecords, {
560
+ ...entry,
561
+ id
562
+ }];
563
+ toastEmit();
564
+ return id;
565
+ }
566
+ /** Dismiss a queued toast by id. */
567
+ function dismissToast(id) {
568
+ toastDismiss(id);
569
+ }
570
+ /** The runtime-mounted viewport: renders the shared toast queue. Pages never
571
+ * mount this themselves — the runtime provides one per surface root. */
572
+ function Toaster(props) {
573
+ const records = useSyncExternalStore((onStoreChange) => {
574
+ toastListeners.add(onStoreChange);
575
+ return () => toastListeners.delete(onStoreChange);
576
+ }, () => toastRecords, () => toastRecords);
577
+ return jsxs(ToastPrimitive.Provider, {
578
+ ...props,
579
+ children: [records.map((record) => jsxs(ToastPrimitive.Root, {
580
+ ...part("toast", "root"),
581
+ className: "snap-toast",
582
+ "data-intent": record.intent ?? "neutral",
583
+ duration: record.duration ?? 5e3,
584
+ onOpenChange: (open) => {
585
+ if (!open) toastDismiss(record.id);
586
+ },
587
+ children: [
588
+ jsx(ToastTitle, { children: record.title }),
589
+ record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
590
+ jsx(ToastClose, { "aria-label": "关闭" })
591
+ ]
592
+ }, record.id)), jsx(ToastViewport, {})]
593
+ });
594
+ }
595
+ /** The raw toast root for pages that manage their own open state. */
596
+ const Toast = ToastPrimitive.Root;
597
+ /** A toast title with its part tag. */
598
+ function ToastTitle({ className, children, ...props }) {
599
+ return jsx(ToastPrimitive.Title, {
600
+ className: cn("snap-toast-title", className),
601
+ ...props,
602
+ ...part("toast", "title"),
603
+ children
604
+ });
605
+ }
606
+ /** A toast description with its part tag. */
607
+ function ToastDescription({ className, children, ...props }) {
608
+ return jsx(ToastPrimitive.Description, {
609
+ className: cn("snap-toast-description", className),
610
+ ...props,
611
+ ...part("toast", "description"),
612
+ children
613
+ });
614
+ }
615
+ /** An interactive toast action (confirm/retry affordances). */
616
+ function ToastAction({ className, children, ...props }) {
617
+ return jsx(ToastPrimitive.Action, {
618
+ className: cn("snap-toast-action", className),
619
+ ...props,
620
+ ...part("toast", "action"),
621
+ children
622
+ });
623
+ }
624
+ /** A toast dismissal button. */
625
+ function ToastClose({ className, children, ...props }) {
626
+ return jsx(ToastPrimitive.Close, {
627
+ className: cn("snap-toast-close", className),
628
+ ...props,
629
+ ...part("toast", "close"),
630
+ children: children ?? jsx("span", {
631
+ "aria-hidden": "true",
632
+ children: "×"
633
+ })
634
+ });
635
+ }
636
+ /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
637
+ function ToastViewport({ className, ...props }) {
638
+ return jsx(ToastPrimitive.Viewport, {
639
+ className: cn("snap-toast-viewport", className),
640
+ ...props,
641
+ ...part("toast", "viewport")
642
+ });
643
+ }
644
+ //#endregion
645
+ //#region lib/types/components/combobox.js
646
+ /**
647
+ * A text field with an anchored suggestion list: search pickers, filtered
648
+ * choosers, async candidate feeds (operator lookups, assignee search). The
649
+ * focus never leaves the field — keyboard navigation rides
650
+ * `aria-activedescendant`, pointer picks suppress the field's blur, and the
651
+ * panel opens without taking the focus — so typing keeps working through
652
+ * open, navigate, and select. The field is a regular {@link Input}; skins
653
+ * style the `combobox.*` parts around it.
654
+ *
655
+ * @module @snap-rail/ui/components/combobox
656
+ */
657
+ /** The text an option contributes to filtering and to the field once picked. */
658
+ function textOf(option) {
659
+ return typeof option.label === "string" || typeof option.label === "number" ? String(option.label) : option.value;
660
+ }
661
+ /** The next enabled row index from `from`, wrapping; -1 when none is enabled. */
662
+ function nextEnabled(rows, from, step) {
663
+ if (rows.length === 0) return -1;
664
+ let index = from < 0 ? step > 0 ? -1 : 0 : from;
665
+ for (let tries = 0; tries < rows.length; tries++) {
666
+ index = (index + step + rows.length) % rows.length;
667
+ if (rows[index]?.disabled !== true) return index;
668
+ }
669
+ return -1;
670
+ }
671
+ /** A field with an anchored, keyboard-navigable suggestion list. */
672
+ function Combobox({ value, defaultValue, onValueChange, onInputValueChange, options, placeholder, disabled = false, invalid = false, size = "md", loading = false, emptyText = "无匹配项", id, className, contentClassName, "aria-label": ariaLabel }) {
673
+ const listId = useId();
674
+ const anchorRef = useRef(null);
675
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
676
+ const current = value !== void 0 ? value : uncontrolled;
677
+ const selected = options.find((option) => option.value === current);
678
+ const selectedText = selected !== void 0 ? textOf(selected) : void 0;
679
+ const [text, setText] = useState(selectedText ?? "");
680
+ const [open, setOpen] = useState(false);
681
+ const [active, setActive] = useState(-1);
682
+ useEffect(() => {
683
+ if (selectedText !== void 0) setText(selectedText);
684
+ }, [selectedText]);
685
+ const query = text.trim().toLowerCase();
686
+ const rows = onInputValueChange !== void 0 || query === "" || text === selectedText ? options : options.filter((option) => textOf(option).toLowerCase().includes(query));
687
+ const optionId = (index) => `${listId}-${index}`;
688
+ useEffect(() => {
689
+ if (active < 0) return;
690
+ document.getElementById(optionId(active))?.scrollIntoView?.({ block: "nearest" });
691
+ });
692
+ const close = () => {
693
+ setOpen(false);
694
+ setActive(-1);
695
+ };
696
+ const choose = (option) => {
697
+ if (option.disabled === true) return;
698
+ if (value === void 0) setUncontrolled(option.value);
699
+ setText(textOf(option));
700
+ onValueChange?.(option.value);
701
+ close();
702
+ };
703
+ const onKeyDown = (event) => {
704
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
705
+ event.preventDefault();
706
+ if (!open) {
707
+ setOpen(true);
708
+ return;
709
+ }
710
+ setActive((index) => nextEnabled(rows, index, event.key === "ArrowDown" ? 1 : -1));
711
+ return;
712
+ }
713
+ if (event.key === "Enter" && open && active >= 0) {
714
+ const option = rows[active];
715
+ if (option !== void 0) {
716
+ event.preventDefault();
717
+ choose(option);
718
+ }
719
+ return;
720
+ }
721
+ if (event.key === "Escape" && open) {
722
+ event.preventDefault();
723
+ close();
724
+ }
725
+ };
726
+ return jsx("span", {
727
+ ...part("combobox", "root"),
728
+ className: "snap-combobox",
729
+ children: jsxs(Popover, {
730
+ open: open && !disabled,
731
+ onOpenChange: (next) => {
732
+ if (!next) close();
733
+ },
734
+ children: [jsx(PopoverAnchor, {
735
+ asChild: true,
736
+ children: jsx("span", {
737
+ ref: anchorRef,
738
+ ...part("combobox", "anchor"),
739
+ children: jsx(Input, {
740
+ id,
741
+ size,
742
+ invalid,
743
+ disabled,
744
+ placeholder,
745
+ className,
746
+ value: text,
747
+ role: "combobox",
748
+ autoComplete: "off",
749
+ "aria-label": ariaLabel,
750
+ "aria-expanded": open,
751
+ "aria-controls": listId,
752
+ "aria-autocomplete": "list",
753
+ "aria-activedescendant": open && active >= 0 ? optionId(active) : void 0,
754
+ onChange: (event) => {
755
+ setText(event.target.value);
756
+ setActive(-1);
757
+ setOpen(true);
758
+ onInputValueChange?.(event.target.value);
759
+ },
760
+ onFocus: () => setOpen(true),
761
+ onBlur: close,
762
+ onKeyDown
763
+ })
764
+ })
765
+ }), jsx(PopoverContent, {
766
+ align: "start",
767
+ sideOffset: 4,
768
+ autoFocusOnOpen: false,
769
+ className: contentClassName,
770
+ onInteractOutside: (event) => {
771
+ if (anchorRef.current?.contains(event.target) === true) event.preventDefault();
772
+ },
773
+ children: jsxs("div", {
774
+ ...part("combobox", "list"),
775
+ role: "listbox",
776
+ id: listId,
777
+ children: [
778
+ rows.map((option, index) => jsx("div", {
779
+ ...part("combobox", "option"),
780
+ id: optionId(index),
781
+ role: "option",
782
+ "aria-selected": option.value === current,
783
+ "aria-disabled": option.disabled === true || void 0,
784
+ "data-active": index === active || void 0,
785
+ "data-disabled": option.disabled === true || void 0,
786
+ onMouseDown: (event) => event.preventDefault(),
787
+ onClick: () => choose(option),
788
+ children: option.label
789
+ }, option.value)),
790
+ loading && jsx("div", {
791
+ ...part("combobox", "empty"),
792
+ children: "搜索中…"
793
+ }),
794
+ !loading && rows.length === 0 && jsx("div", {
795
+ ...part("combobox", "empty"),
796
+ children: emptyText
797
+ })
798
+ ]
799
+ })
800
+ })]
801
+ })
802
+ });
803
+ }
804
+ //#endregion
805
+ //#region lib/types/components/dialog.js
806
+ /**
807
+ * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
808
+ * the presentation (modal, sheet, fullscreen) through the `presentation`
809
+ * attribute; the core owns dismissal and focus behaviour.
810
+ *
811
+ * @module @snap-rail/ui/components/dialog
812
+ */
813
+ /** The dialog root. */
814
+ const Dialog = DialogPrimitive.Root;
815
+ /** The dialog trigger. */
816
+ const DialogTrigger = DialogPrimitive.Trigger;
817
+ /** The dialog close. */
818
+ const DialogClose = DialogPrimitive.Close;
819
+ /** The portalled dialog content. */
820
+ function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
821
+ const resolved = presentation === "auto" ? "modal" : presentation;
822
+ return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
823
+ ...part("dialog", "overlay"),
824
+ className: "snap-dialog-overlay"
825
+ }), jsxs(DialogPrimitive.Content, {
826
+ className: cn("snap-dialog-panel", className),
827
+ "data-presentation": resolved,
828
+ "data-size": size,
829
+ ...rest,
830
+ ...part("dialog", "panel"),
831
+ children: [children, showClose && jsx(DialogPrimitive.Close, {
832
+ ...part("dialog", "close"),
833
+ className: "snap-dialog-close",
834
+ "aria-label": "关闭",
835
+ children: "×"
836
+ })]
837
+ })] });
838
+ }
839
+ /** The dialog header. */
840
+ function DialogHeader({ children, className }) {
841
+ return jsx("div", {
842
+ ...part("dialog", "header"),
843
+ className: cn("snap-dialog-header", className),
844
+ children
845
+ });
846
+ }
847
+ /** The dialog title. */
848
+ function DialogTitle({ children, className }) {
849
+ return jsx(DialogPrimitive.Title, {
850
+ ...part("dialog", "title"),
851
+ className: cn("snap-dialog-title", className),
852
+ children
853
+ });
854
+ }
855
+ /** The dialog description. */
856
+ function DialogDescription({ children, className }) {
857
+ return jsx(DialogPrimitive.Description, {
858
+ ...part("dialog", "description"),
859
+ className: cn("snap-dialog-description", className),
860
+ children
861
+ });
862
+ }
863
+ /** The dialog body. */
864
+ function DialogBody({ children, className }) {
865
+ return jsx("div", {
866
+ ...part("dialog", "body"),
867
+ className: cn("snap-dialog-body", className),
868
+ children
869
+ });
870
+ }
871
+ /** The dialog footer. */
872
+ function DialogFooter({ children, className }) {
873
+ return jsx("div", {
874
+ ...part("dialog", "footer"),
875
+ className: cn("snap-dialog-footer", className),
876
+ children
877
+ });
878
+ }
879
+ /** A sheet is a dialog with the `sheet` presentation by default. */
880
+ function Sheet(props) {
881
+ return jsx(DialogContent, {
882
+ ...props,
883
+ presentation: props.presentation ?? "sheet"
884
+ });
885
+ }
886
+ //#endregion
887
+ //#region lib/types/components/controls.js
888
+ /**
889
+ * Selection and toggle semantics over Radix: tabs, select, switch, checkbox,
890
+ * and radio groups. All behaviour/keyboard handling stays here; skins target
891
+ * the stable parts and state attributes.
892
+ *
893
+ * @module @snap-rail/ui/components/controls
894
+ */
895
+ /** A form label. */
896
+ function Label({ className, children, ...props }) {
897
+ return jsx(LabelPrimitive.Root, {
898
+ className: cn("snap-label", className),
899
+ ...props,
900
+ children
901
+ });
902
+ }
903
+ /** The tabs root. */
904
+ function Tabs({ className, children, ...props }) {
905
+ return jsx(TabsPrimitive.Root, {
906
+ className: cn("snap-tabs", className),
907
+ ...props,
908
+ ...part("tabs", "root"),
909
+ children
910
+ });
911
+ }
912
+ /** The tabs list. */
913
+ function TabsList({ className, children, ...props }) {
914
+ return jsx(TabsPrimitive.List, {
915
+ className: cn("snap-tabs-list", className),
916
+ ...props,
917
+ ...part("tabs", "list"),
918
+ children
919
+ });
920
+ }
921
+ /** A tab trigger. */
922
+ function TabsTrigger({ className, children, ...props }) {
923
+ return jsx(TabsPrimitive.Trigger, {
924
+ className: cn("snap-tabs-trigger", className),
925
+ ...props,
926
+ ...part("tabs", "trigger"),
927
+ children
928
+ });
929
+ }
930
+ /** A tab panel. */
931
+ function TabsContent({ className, children, ...props }) {
932
+ return jsx(TabsPrimitive.Content, {
933
+ className: cn("snap-tabs-content", className),
934
+ ...props,
935
+ ...part("tabs", "content"),
936
+ children
937
+ });
938
+ }
939
+ /** A boolean switch with an optional label on either side. */
940
+ function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
941
+ const labelNode = label !== void 0 && jsx("span", {
942
+ ...part("switch", "label"),
943
+ children: label
944
+ });
945
+ const row = jsxs("label", {
946
+ className: "snap-switch-label",
947
+ children: [
948
+ labelPosition === "start" && labelNode,
949
+ jsx(SwitchPrimitive.Root, {
950
+ className: cn("snap-switch", className),
951
+ ...props,
952
+ ...part("switch", "root"),
953
+ children: jsx(SwitchPrimitive.Thumb, {
954
+ ...part("switch", "thumb"),
955
+ className: "snap-switch-thumb"
956
+ })
957
+ }),
958
+ labelPosition === "end" && labelNode
959
+ ]
960
+ });
961
+ if (description === void 0) return row;
962
+ return jsxs("span", {
963
+ ...part("switch", "field"),
964
+ className: cn("snap-switch-field", containerClassName),
965
+ children: [row, jsx("span", {
966
+ ...part("switch", "description"),
967
+ className: "snap-field-help",
968
+ children: description
969
+ })]
970
+ });
971
+ }
972
+ /** A tri-state checkbox with an optional label on either side. */
973
+ function Checkbox({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
974
+ const labelNode = label !== void 0 && jsx("span", {
975
+ ...part("checkbox", "label"),
976
+ children: label
977
+ });
978
+ const row = jsxs("label", {
979
+ className: "snap-checkbox-label",
980
+ children: [
981
+ labelPosition === "start" && labelNode,
982
+ jsx(CheckboxPrimitive.Root, {
983
+ className: cn("snap-checkbox", className),
984
+ ...props,
985
+ ...part("checkbox", "root"),
986
+ children: jsx(CheckboxPrimitive.Indicator, {
987
+ ...part("checkbox", "indicator"),
988
+ className: "snap-checkbox-indicator",
989
+ children: "✓"
990
+ })
991
+ }),
992
+ labelPosition === "end" && labelNode
993
+ ]
994
+ });
995
+ if (description === void 0) return row;
996
+ return jsxs("span", {
997
+ ...part("checkbox", "field"),
998
+ className: cn("snap-checkbox-field", containerClassName),
999
+ children: [row, jsx("span", {
1000
+ ...part("checkbox", "description"),
1001
+ className: "snap-field-help",
1002
+ children: description
1003
+ })]
1004
+ });
1005
+ }
1006
+ /** A labelled group of radio items. */
1007
+ function RadioGroup({ className, label, description, children, ...props }) {
1008
+ const labelId = useId();
1009
+ const group = jsx(RadioGroupPrimitive.Root, {
1010
+ className: cn("snap-radio-group", className),
1011
+ ...label !== void 0 ? { "aria-labelledby": labelId } : {},
1012
+ ...props,
1013
+ ...part("radio-group", "root"),
1014
+ children
1015
+ });
1016
+ if (label === void 0 && description === void 0) return group;
1017
+ return jsxs("div", {
1018
+ ...part("radio-group", "block"),
1019
+ className: "snap-radio-group-block",
1020
+ children: [
1021
+ label !== void 0 && jsx(Label, {
1022
+ id: labelId,
1023
+ ...part("radio-group", "label"),
1024
+ children: label
1025
+ }),
1026
+ group,
1027
+ description !== void 0 && jsx("div", {
1028
+ ...part("radio-group", "description"),
1029
+ className: "snap-field-help",
1030
+ children: description
1031
+ })
1032
+ ]
1033
+ });
1034
+ }
1035
+ /** One radio item. */
1036
+ function RadioGroupItem({ className, ...props }) {
1037
+ return jsx(RadioGroupPrimitive.Item, {
1038
+ className: cn("snap-radio-item", className),
1039
+ ...props,
1040
+ ...part("radio-group", "item"),
1041
+ children: jsx(RadioGroupPrimitive.Indicator, {
1042
+ ...part("radio-group", "indicator"),
1043
+ className: "snap-radio-indicator"
1044
+ })
1045
+ });
1046
+ }
1047
+ /** A modal option list; use on touch terminals in place of the popover select. */
1048
+ function TouchSelect({ value, onValueChange, options, placeholder = "请选择", disabled = false, invalid = false, size = "md", className, "aria-label": ariaLabel, title }) {
1049
+ const [open, setOpen] = useState(false);
1050
+ const selected = options.find((option) => option.value === value);
1051
+ return jsxs("span", {
1052
+ ...part("touch-select", "root"),
1053
+ className: "snap-touch-select",
1054
+ children: [jsx("span", {
1055
+ ...part("touch-select", "trigger"),
1056
+ className: "snap-touch-select-trigger",
1057
+ children: jsxs(Button, {
1058
+ type: "button",
1059
+ size,
1060
+ emphasis: "outline",
1061
+ className,
1062
+ disabled,
1063
+ "aria-label": ariaLabel,
1064
+ "aria-invalid": invalid || void 0,
1065
+ "aria-haspopup": "dialog",
1066
+ onClick: () => setOpen(true),
1067
+ children: [jsx("span", {
1068
+ style: {
1069
+ flex: 1,
1070
+ textAlign: "left"
1071
+ },
1072
+ children: selected?.label ?? placeholder
1073
+ }), jsx("span", {
1074
+ "aria-hidden": "true",
1075
+ children: "▾"
1076
+ })]
1077
+ })
1078
+ }), jsx(Dialog, {
1079
+ open,
1080
+ onOpenChange: setOpen,
1081
+ children: jsx(DialogContent, {
1082
+ presentation: "modal",
1083
+ size: "sm",
1084
+ children: jsxs("div", {
1085
+ ...part("touch-select", "sheet"),
1086
+ className: "snap-touch-select-sheet",
1087
+ children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: title ?? ariaLabel ?? "请选择" }) }), jsxs("div", {
1088
+ ...part("touch-select", "options"),
1089
+ style: {
1090
+ display: "flex",
1091
+ flexDirection: "column",
1092
+ gap: "var(--snap-space-sm)"
1093
+ },
1094
+ children: [options.map((option) => jsx(Button, {
1095
+ type: "button",
1096
+ size: "lg",
1097
+ emphasis: option.value === value ? "solid" : "outline",
1098
+ intent: option.value === value ? "primary" : "neutral",
1099
+ disabled: option.disabled === true,
1100
+ onClick: () => {
1101
+ onValueChange?.(option.value);
1102
+ setOpen(false);
1103
+ },
1104
+ children: option.label
1105
+ }, option.value)), options.length === 0 && jsx("span", {
1106
+ style: { color: "var(--snap-color-muted)" },
1107
+ children: "无可选项"
1108
+ })]
1109
+ })]
1110
+ })
1111
+ })
1112
+ })]
1113
+ });
1114
+ }
1115
+ /** The select trigger; composes a {@link SelectValue} inside. */
1116
+ function SelectTrigger({ className, size = "md", invalid = false, disabled = false, children, ...props }) {
1117
+ return jsxs(SelectPrimitive.Trigger, {
1118
+ className: cn("snap-select-trigger", className),
1119
+ "data-size": size,
1120
+ "data-invalid": invalid || void 0,
1121
+ "data-disabled": disabled || void 0,
1122
+ "aria-invalid": invalid || void 0,
1123
+ ...props,
1124
+ ...part("select", "trigger"),
1125
+ children: [children, jsx(SelectPrimitive.Icon, {
1126
+ ...part("select", "chevron"),
1127
+ className: "snap-select-chevron",
1128
+ children: "▾"
1129
+ })]
1130
+ });
1131
+ }
1132
+ /** The selected-value slot of a trigger. */
1133
+ function SelectValue(props) {
1134
+ return jsx(SelectPrimitive.Value, {
1135
+ ...props,
1136
+ ...part("select", "value")
1137
+ });
1138
+ }
1139
+ /** The portalled option list. */
1140
+ function SelectContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
1141
+ return jsx(SelectPrimitive.Portal, { children: jsx(SelectPrimitive.Content, {
1142
+ className: cn("snap-select-content", className),
1143
+ position: "popper",
1144
+ side,
1145
+ align,
1146
+ sideOffset,
1147
+ ...props,
1148
+ ...part("select", "content"),
1149
+ children: jsx(SelectPrimitive.Viewport, { children })
1150
+ }) });
1151
+ }
1152
+ /** One option row. */
1153
+ function SelectItem({ className, children, ...props }) {
1154
+ return jsxs(SelectPrimitive.Item, {
1155
+ className: cn("snap-select-item", className),
1156
+ ...props,
1157
+ ...part("select", "item"),
1158
+ children: [jsx(SelectPrimitive.ItemText, { children }), jsx(SelectPrimitive.ItemIndicator, {
1159
+ ...part("select", "item-indicator"),
1160
+ className: "snap-select-item-indicator",
1161
+ children: "✓"
1162
+ })]
1163
+ });
1164
+ }
1165
+ /** A labelled group of options. */
1166
+ function SelectGroup(props) {
1167
+ return jsx(SelectPrimitive.Group, { ...props });
1168
+ }
1169
+ /** A group heading. */
1170
+ function SelectLabel({ className, ...props }) {
1171
+ return jsx(SelectPrimitive.Label, {
1172
+ className: cn("snap-select-label", className),
1173
+ ...props
1174
+ });
1175
+ }
1176
+ /** A popover select: data-driven via `options`, or composed from
1177
+ * {@link SelectItem} children for full layout control. */
1178
+ function Select({ value, defaultValue, onValueChange, options, children, placeholder = "请选择", disabled = false, invalid = false, required, name, id, size = "md", side = "bottom", align = "start", sideOffset = 4, className, contentClassName, "aria-label": ariaLabel }) {
1179
+ const composite = children !== void 0;
1180
+ const empty = !composite && (options ?? []).length === 0;
1181
+ return jsx("span", {
1182
+ ...part("select", "root"),
1183
+ className: "snap-select",
1184
+ children: jsxs(SelectPrimitive.Root, {
1185
+ ...value !== void 0 ? { value } : {},
1186
+ ...defaultValue !== void 0 ? { defaultValue } : {},
1187
+ ...onValueChange !== void 0 ? { onValueChange } : {},
1188
+ disabled,
1189
+ ...name !== void 0 ? { name } : {},
1190
+ ...required !== void 0 ? { required } : {},
1191
+ children: [jsx(SelectTrigger, {
1192
+ id,
1193
+ size,
1194
+ invalid,
1195
+ disabled,
1196
+ className,
1197
+ "aria-label": ariaLabel,
1198
+ children: jsx(SelectValue, { placeholder })
1199
+ }), jsxs(SelectContent, {
1200
+ side,
1201
+ align,
1202
+ sideOffset,
1203
+ className: contentClassName,
1204
+ children: [composite ? children : (options ?? []).map((option) => jsx(SelectItem, {
1205
+ value: option.value,
1206
+ disabled: option.disabled === true,
1207
+ children: option.label
1208
+ }, option.value)), empty && jsx("div", {
1209
+ ...part("select", "empty"),
1210
+ className: "snap-select-empty",
1211
+ children: "无可选项"
1212
+ })]
1213
+ })]
1214
+ })
1215
+ });
1216
+ }
1217
+ //#endregion
1218
+ //#region lib/types/components/feedback.js
1219
+ /** A compact status/count label. */
1220
+ function Badge({ children, intent = "neutral", className }) {
1221
+ return jsx("span", {
1222
+ ...part("badge", "root"),
1223
+ className: cn("snap-badge", className),
1224
+ "data-intent": intent,
1225
+ children
1226
+ });
1227
+ }
1228
+ /** A status light with a separate halo part for breathing/glow skins. */
1229
+ function Led({ tone = "neutral", label, className }) {
1230
+ return jsx("span", {
1231
+ ...part("led", "root"),
1232
+ className: cn("snap-led", className),
1233
+ "data-tone": tone,
1234
+ "aria-label": label,
1235
+ role: label !== void 0 ? "img" : void 0,
1236
+ children: jsx("span", {
1237
+ ...part("led", "halo"),
1238
+ "aria-hidden": "true"
1239
+ })
1240
+ });
1241
+ }
1242
+ /** A linear progress indicator. */
1243
+ function Progress({ value, label, className }) {
1244
+ const clamped = value === null ? null : Math.min(1, Math.max(0, value));
1245
+ return jsx("div", {
1246
+ ...part("progress", "root"),
1247
+ className: cn("snap-progress", className),
1248
+ role: "progressbar",
1249
+ "aria-label": label,
1250
+ "aria-valuemin": 0,
1251
+ "aria-valuemax": 100,
1252
+ ...clamped !== null ? { "aria-valuenow": Math.round(clamped * 100) } : {},
1253
+ "data-indeterminate": clamped === null || void 0,
1254
+ children: jsx("div", {
1255
+ ...part("progress", "track"),
1256
+ className: "snap-progress-track",
1257
+ children: jsx("div", {
1258
+ ...part("progress", "indicator"),
1259
+ className: "snap-progress-indicator",
1260
+ style: clamped === null ? void 0 : { width: `${Math.round(clamped * 100)}%` }
1261
+ })
1262
+ })
1263
+ });
1264
+ }
1265
+ /** A centered empty/zero-state block. */
1266
+ function EmptyState({ title, description, icon, action, className }) {
1267
+ return jsxs("div", {
1268
+ ...part("empty-state", "root"),
1269
+ className: cn("snap-empty-state", className),
1270
+ children: [
1271
+ icon !== void 0 && jsx("div", {
1272
+ ...part("empty-state", "icon"),
1273
+ children: icon
1274
+ }),
1275
+ jsx("div", {
1276
+ ...part("empty-state", "title"),
1277
+ children: title
1278
+ }),
1279
+ description !== void 0 && jsx("div", {
1280
+ ...part("empty-state", "description"),
1281
+ children: description
1282
+ }),
1283
+ action !== void 0 && jsx("div", {
1284
+ ...part("empty-state", "action"),
1285
+ children: action
1286
+ })
1287
+ ]
1288
+ });
1289
+ }
1290
+ //#endregion
1291
+ //#region lib/types/components/form.js
1292
+ /** A labelled form row. */
1293
+ function Field({ label, htmlFor, help, error, invalid = false, required = false, orientation = "vertical", labelWidth, labelAlign = "start", children, className, style }) {
1294
+ const bad = invalid || error !== void 0;
1295
+ return jsxs("div", {
1296
+ ...part("field", "root"),
1297
+ className: cn("snap-field", className),
1298
+ "data-invalid": bad || void 0,
1299
+ "data-required": required || void 0,
1300
+ "data-orientation": orientation,
1301
+ style,
1302
+ children: [
1303
+ label !== void 0 && jsxs(Label, {
1304
+ ...htmlFor !== void 0 ? { htmlFor } : {},
1305
+ ...part("field", "label"),
1306
+ style: {
1307
+ ...labelWidth !== void 0 ? {
1308
+ width: typeof labelWidth === "number" ? `${labelWidth}px` : labelWidth,
1309
+ flexShrink: 0
1310
+ } : {},
1311
+ ...labelAlign !== "start" ? { textAlign: labelAlign } : {}
1312
+ },
1313
+ children: [label, required && jsx("span", {
1314
+ "aria-hidden": "true",
1315
+ children: " *"
1316
+ })]
1317
+ }),
1318
+ jsx("div", {
1319
+ ...part("field", "control"),
1320
+ children
1321
+ }),
1322
+ help !== void 0 && error === void 0 && jsx("div", {
1323
+ ...part("field", "help"),
1324
+ className: "snap-field-help",
1325
+ children: help
1326
+ }),
1327
+ error !== void 0 && jsx("div", {
1328
+ ...part("field", "error"),
1329
+ className: "snap-field-error",
1330
+ role: "alert",
1331
+ children: error
1332
+ })
1333
+ ]
1334
+ });
1335
+ }
1336
+ /** A form with a fields region and an actions region. */
1337
+ function Form({ children, actions, onSubmit, className, orientation = "stack", gap = "md", columns = 2, form, onValid, onInvalid }) {
1338
+ const fieldsStyle = orientation === "grid" ? {
1339
+ display: "grid",
1340
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
1341
+ gap: space(gap)
1342
+ } : orientation === "inline" ? {
1343
+ display: "flex",
1344
+ flexDirection: "row",
1345
+ flexWrap: "wrap",
1346
+ gap: space(gap)
1347
+ } : {
1348
+ display: "flex",
1349
+ flexDirection: "column",
1350
+ gap: space(gap)
1351
+ };
1352
+ const body = jsxs(Fragment, { children: [jsx("div", {
1353
+ ...part("form", "fields"),
1354
+ className: "snap-form-fields",
1355
+ style: fieldsStyle,
1356
+ children
1357
+ }), actions !== void 0 && jsx("div", {
1358
+ ...part("form", "actions"),
1359
+ className: "snap-form-actions",
1360
+ children: actions
1361
+ })] });
1362
+ const submit = form !== void 0 && onValid !== void 0 ? form.handleSubmit(onValid, onInvalid) : onSubmit;
1363
+ if (form === void 0) return jsx("form", {
1364
+ ...part("form", "root"),
1365
+ className: cn("snap-form", className),
1366
+ "data-orientation": orientation,
1367
+ onSubmit: submit,
1368
+ children: body
1369
+ });
1370
+ return jsx(FormProvider$1, {
1371
+ ...form,
1372
+ children: jsx("form", {
1373
+ ...part("form", "root"),
1374
+ className: cn("snap-form", className),
1375
+ "data-orientation": orientation,
1376
+ onSubmit: submit,
1377
+ children: body
1378
+ })
1379
+ });
1380
+ }
1381
+ //#endregion
1382
+ //#region lib/types/components/form-rhf.js
1383
+ /**
1384
+ * React Hook Form integration in the shadcn composite shape: `FormField`
1385
+ * binds a controller, `FormItem`/`FormLabel`/`FormControl`/
1386
+ * `FormDescription`/`FormMessage` render the same `field.*` anatomy the plain
1387
+ * {@link Field} uses, driven by the form state. The RHF hooks and
1388
+ * `zodResolver` are re-exported so plugin bundles consume the seed's single
1389
+ * module instance — RHF context is module-scoped, and a copy bundled inside a
1390
+ * plugin zip would never see the form state.
1391
+ *
1392
+ * @module @snap-rail/ui/components/form-rhf
1393
+ */
1394
+ const FormFieldContext = createContext(null);
1395
+ const FormItemContext = createContext(null);
1396
+ /** Read the enclosing field binding; fails loud outside a {@link FormField}. */
1397
+ function useFormField() {
1398
+ const field = useContext(FormFieldContext);
1399
+ const item = useContext(FormItemContext);
1400
+ if (field === null || item === null) throw new Error("表单字段部件必须渲染在 FormField 内");
1401
+ return {
1402
+ id: item.id,
1403
+ name: field.name
1404
+ };
1405
+ }
1406
+ /** Bind a controller and expose its name to the anatomy parts inside. */
1407
+ function FormField(props) {
1408
+ const name = props.name;
1409
+ return jsx(FormFieldContext.Provider, {
1410
+ value: { name },
1411
+ children: jsx(Controller$1, {
1412
+ ...props,
1413
+ name,
1414
+ render: props.render
1415
+ })
1416
+ });
1417
+ }
1418
+ /** The field row: owns the shared id every aria attribute anchors to. */
1419
+ function FormItem({ children, className, orientation = "vertical" }) {
1420
+ const id = useId();
1421
+ return jsx(FormItemContext.Provider, {
1422
+ value: { id },
1423
+ children: jsx("div", {
1424
+ ...part("field", "root"),
1425
+ className: cn("snap-field", className),
1426
+ "data-orientation": orientation,
1427
+ children
1428
+ })
1429
+ });
1430
+ }
1431
+ /** The field label; carries `data-invalid` when the field has an error. */
1432
+ function FormLabel({ className, children }) {
1433
+ const { id, name } = useFormField();
1434
+ const invalid = useFormState$1({ name }).errors[name] !== void 0;
1435
+ return jsx(Label, {
1436
+ htmlFor: id,
1437
+ ...part("field", "label"),
1438
+ className: cn("snap-form-label", className),
1439
+ "data-invalid": invalid || void 0,
1440
+ children
1441
+ });
1442
+ }
1443
+ /** Merges the field binding onto the single control child it wraps. */
1444
+ function FormControl({ children }) {
1445
+ const { id, name } = useFormField();
1446
+ const invalid = useFormState$1({ name }).errors[name] !== void 0;
1447
+ return jsx(Slot, {
1448
+ id,
1449
+ "aria-invalid": invalid || void 0,
1450
+ "aria-describedby": `${id}-description ${id}-message`,
1451
+ children
1452
+ });
1453
+ }
1454
+ /** Helper text under the control; linked as `aria-describedby`. */
1455
+ function FormDescription({ className, children }) {
1456
+ const { id } = useFormField();
1457
+ return jsx("div", {
1458
+ ...part("field", "help"),
1459
+ id: `${id}-description`,
1460
+ className: cn("snap-field-help", className),
1461
+ children
1462
+ });
1463
+ }
1464
+ /** The validation message for the bound field. */
1465
+ function FormMessage({ message, children, className }) {
1466
+ const { id, name } = useFormField();
1467
+ const raw = useFormState$1({ name }).errors[name]?.message;
1468
+ const body = message ?? (typeof raw === "string" || typeof raw === "number" || typeof raw === "bigint" || typeof raw === "boolean" ? String(raw) : void 0) ?? children;
1469
+ if (body === void 0 || body === "") return null;
1470
+ return jsx("div", {
1471
+ ...part("field", "error"),
1472
+ id: `${id}-message`,
1473
+ className: cn("snap-field-error", className),
1474
+ role: "alert",
1475
+ children: body
1476
+ });
1477
+ }
1478
+ //#endregion
1479
+ //#region lib/types/components/layout.js
1480
+ /**
1481
+ * Semantic layout primitives. Pages compose these instead of raw flex/grid
1482
+ * utility classes; the structural rules are inline (so layout survives
1483
+ * without a skin) while spacing/density values ride skin tokens.
1484
+ *
1485
+ * @module @snap-rail/ui/components/layout
1486
+ */
1487
+ /** A vertical flow. */
1488
+ function Stack({ gap = "md", padding, align, className, style, children }) {
1489
+ return jsx("div", {
1490
+ ...part("stack", "root"),
1491
+ className: cn("snap-stack", className),
1492
+ style: {
1493
+ display: "flex",
1494
+ flexDirection: "column",
1495
+ gap: space(gap),
1496
+ ...padding !== void 0 ? { padding: space(padding) } : {},
1497
+ ...align !== void 0 ? { alignItems: align } : {},
1498
+ ...style
1499
+ },
1500
+ children
1501
+ });
1502
+ }
1503
+ /** A horizontal flow. */
1504
+ function Row({ gap = "sm", padding, align, justify, wrap = false, className, style, children }) {
1505
+ return jsx("div", {
1506
+ ...part("row", "root"),
1507
+ className: cn("snap-row", className),
1508
+ style: {
1509
+ display: "flex",
1510
+ flexDirection: "row",
1511
+ gap: space(gap),
1512
+ ...padding !== void 0 ? { padding: space(padding) } : {},
1513
+ ...align !== void 0 ? { alignItems: align } : {},
1514
+ ...justify !== void 0 ? { justifyContent: justify } : {},
1515
+ ...wrap ? { flexWrap: "wrap" } : {},
1516
+ ...style
1517
+ },
1518
+ children
1519
+ });
1520
+ }
1521
+ /** A responsive grid. */
1522
+ function Grid({ gap = "md", padding, columns = 2, minColumnWidth, className, style, children }) {
1523
+ const template = typeof columns === "number" ? `repeat(${columns}, minmax(0, 1fr))` : columns;
1524
+ return jsx("div", {
1525
+ ...part("grid", "root"),
1526
+ className: cn("snap-grid", className),
1527
+ style: {
1528
+ display: "grid",
1529
+ gap: space(gap),
1530
+ gridTemplateColumns: minColumnWidth !== void 0 ? `repeat(auto-fit, minmax(${minColumnWidth}, 1fr))` : template,
1531
+ ...padding !== void 0 ? { padding: space(padding) } : {},
1532
+ ...style
1533
+ },
1534
+ children
1535
+ });
1536
+ }
1537
+ /** A two-pane split (sidebar + content, list + detail). */
1538
+ function Split({ start, end, gap = "md", ratio = "minmax(0, 2fr) minmax(0, 3fr)", className, style }) {
1539
+ return jsxs("div", {
1540
+ ...part("split", "root"),
1541
+ className: cn("snap-split", className),
1542
+ style: {
1543
+ display: "grid",
1544
+ gridTemplateColumns: ratio,
1545
+ gap: space(gap),
1546
+ minHeight: 0,
1547
+ ...style
1548
+ },
1549
+ children: [jsx("div", {
1550
+ ...part("split", "start"),
1551
+ style: {
1552
+ minWidth: 0,
1553
+ minHeight: 0
1554
+ },
1555
+ children: start
1556
+ }), jsx("div", {
1557
+ ...part("split", "end"),
1558
+ style: {
1559
+ minWidth: 0,
1560
+ minHeight: 0
1561
+ },
1562
+ children: end
1563
+ })]
1564
+ });
1565
+ }
1566
+ /** The operator-window shell frame. */
1567
+ function AppShell({ header, sidebar, footer, className, style, children }) {
1568
+ return jsxs("div", {
1569
+ ...part("app-shell", "root"),
1570
+ className: cn("snap-app-shell", className),
1571
+ style: {
1572
+ display: "flex",
1573
+ flexDirection: "column",
1574
+ height: "100%",
1575
+ minHeight: 0,
1576
+ ...style
1577
+ },
1578
+ children: [
1579
+ header !== void 0 && jsx("div", {
1580
+ ...part("app-shell", "header"),
1581
+ style: { flexShrink: 0 },
1582
+ children: header
1583
+ }),
1584
+ jsxs("div", {
1585
+ style: {
1586
+ display: "flex",
1587
+ flex: 1,
1588
+ minHeight: 0
1589
+ },
1590
+ children: [sidebar !== void 0 && jsx("div", {
1591
+ ...part("app-shell", "sidebar"),
1592
+ style: {
1593
+ flexShrink: 0,
1594
+ minHeight: 0
1595
+ },
1596
+ children: sidebar
1597
+ }), jsx("div", {
1598
+ ...part("app-shell", "main"),
1599
+ style: {
1600
+ flex: 1,
1601
+ minWidth: 0,
1602
+ minHeight: 0,
1603
+ overflow: "auto"
1604
+ },
1605
+ children
1606
+ })]
1607
+ }),
1608
+ footer !== void 0 && jsx("div", {
1609
+ ...part("app-shell", "footer"),
1610
+ style: { flexShrink: 0 },
1611
+ children: footer
1612
+ })
1613
+ ]
1614
+ });
1615
+ }
1616
+ /** A page body with its own header/actions anatomy. */
1617
+ function Page({ header, actions, title, titleExtra, description, className, style, children }) {
1618
+ return jsxs("div", {
1619
+ ...part("page", "root"),
1620
+ className: cn("snap-page", className),
1621
+ style: {
1622
+ display: "flex",
1623
+ flexDirection: "column",
1624
+ minHeight: 0,
1625
+ ...style
1626
+ },
1627
+ children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
1628
+ ...part("page", "header"),
1629
+ style: {
1630
+ display: "flex",
1631
+ flexDirection: "column",
1632
+ gap: space("sm"),
1633
+ flexShrink: 0
1634
+ },
1635
+ children: [
1636
+ jsxs("div", {
1637
+ style: {
1638
+ display: "flex",
1639
+ alignItems: "flex-start",
1640
+ justifyContent: "space-between",
1641
+ gap: space("md")
1642
+ },
1643
+ children: [jsxs("div", {
1644
+ style: {
1645
+ display: "flex",
1646
+ alignItems: "center",
1647
+ gap: space("sm")
1648
+ },
1649
+ children: [title !== void 0 && jsx("div", {
1650
+ ...part("page", "title"),
1651
+ children: title
1652
+ }), titleExtra !== void 0 && jsx("div", {
1653
+ ...part("page", "title-extra"),
1654
+ children: titleExtra
1655
+ })]
1656
+ }), actions !== void 0 && jsx("div", {
1657
+ ...part("page", "actions"),
1658
+ children: actions
1659
+ })]
1660
+ }),
1661
+ description !== void 0 && jsx("div", {
1662
+ ...part("page", "description"),
1663
+ children: description
1664
+ }),
1665
+ header
1666
+ ]
1667
+ }), jsx("div", {
1668
+ ...part("page", "body"),
1669
+ style: {
1670
+ display: "flex",
1671
+ flexDirection: "column",
1672
+ flex: 1,
1673
+ minHeight: 0
1674
+ },
1675
+ children
1676
+ })]
1677
+ });
1678
+ }
1679
+ /** A titled content section. */
1680
+ function Section({ title, description, actions, className, style, children }) {
1681
+ return jsxs("section", {
1682
+ ...part("section", "root"),
1683
+ className: cn("snap-section", className),
1684
+ style: {
1685
+ display: "flex",
1686
+ flexDirection: "column",
1687
+ gap: space("sm"),
1688
+ ...style
1689
+ },
1690
+ children: [(title !== void 0 || actions !== void 0) && jsxs("div", {
1691
+ ...part("section", "header"),
1692
+ style: {
1693
+ display: "flex",
1694
+ alignItems: "center",
1695
+ justifyContent: "space-between",
1696
+ gap: space("md")
1697
+ },
1698
+ children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
1699
+ ...part("section", "title"),
1700
+ children: title
1701
+ }), description !== void 0 && jsx("div", { children: description })] }), actions !== void 0 && jsx("div", {
1702
+ ...part("section", "actions"),
1703
+ children: actions
1704
+ })]
1705
+ }), jsx("div", {
1706
+ ...part("section", "body"),
1707
+ children
1708
+ })]
1709
+ });
1710
+ }
1711
+ /** A compact action bar; `children` renders between the start and end groups. */
1712
+ function Toolbar({ start, end, children, className, style }) {
1713
+ return jsxs("div", {
1714
+ ...part("toolbar", "root"),
1715
+ className: cn("snap-toolbar", className),
1716
+ style: {
1717
+ display: "flex",
1718
+ alignItems: "center",
1719
+ justifyContent: "space-between",
1720
+ gap: space("sm"),
1721
+ ...style
1722
+ },
1723
+ children: [
1724
+ jsx("div", {
1725
+ ...part("toolbar", "start"),
1726
+ style: {
1727
+ display: "flex",
1728
+ alignItems: "center",
1729
+ gap: space("sm"),
1730
+ minWidth: 0
1731
+ },
1732
+ children: start
1733
+ }),
1734
+ children !== void 0 && jsx("div", {
1735
+ ...part("toolbar", "center"),
1736
+ style: {
1737
+ display: "flex",
1738
+ alignItems: "center",
1739
+ gap: space("sm"),
1740
+ minWidth: 0
1741
+ },
1742
+ children
1743
+ }),
1744
+ jsx("div", {
1745
+ ...part("toolbar", "end"),
1746
+ style: {
1747
+ display: "flex",
1748
+ alignItems: "center",
1749
+ gap: space("sm"),
1750
+ flexShrink: 0
1751
+ },
1752
+ children: end
1753
+ })
1754
+ ]
1755
+ });
1756
+ }
1757
+ /** A scroll container with themed, overlay-style scrollbars over the Radix
1758
+ * viewport. The anatomy stays `scroll-area.root/viewport` plus the
1759
+ * `scroll-area.scrollbar/thumb` parts the skin styles. */
1760
+ function ScrollArea({ direction = "vertical", scrollbarType = "hover", className, style, children }) {
1761
+ return jsxs(ScrollAreaPrimitive.Root, {
1762
+ ...part("scroll-area", "root"),
1763
+ className: cn("snap-scroll-area", className),
1764
+ type: scrollbarType,
1765
+ style: {
1766
+ minHeight: 0,
1767
+ ...direction === "horizontal" ? { height: "100%" } : {},
1768
+ ...style
1769
+ },
1770
+ children: [
1771
+ jsx(ScrollAreaPrimitive.Viewport, {
1772
+ ...part("scroll-area", "viewport"),
1773
+ className: "snap-scroll-area-viewport",
1774
+ children
1775
+ }),
1776
+ direction !== "horizontal" && jsx(ScrollAreaPrimitive.Scrollbar, {
1777
+ ...part("scroll-area", "scrollbar"),
1778
+ className: "snap-scroll-area-scrollbar",
1779
+ orientation: "vertical",
1780
+ children: jsx(ScrollAreaPrimitive.Thumb, {
1781
+ ...part("scroll-area", "thumb"),
1782
+ className: "snap-scroll-area-thumb"
1783
+ })
1784
+ }),
1785
+ direction !== "vertical" && jsx(ScrollAreaPrimitive.Scrollbar, {
1786
+ ...part("scroll-area", "scrollbar"),
1787
+ className: "snap-scroll-area-scrollbar",
1788
+ orientation: "horizontal",
1789
+ children: jsx(ScrollAreaPrimitive.Thumb, {
1790
+ ...part("scroll-area", "thumb"),
1791
+ className: "snap-scroll-area-thumb"
1792
+ })
1793
+ })
1794
+ ]
1795
+ });
1796
+ }
1797
+ /**
1798
+ * Wire an element as a drag-pan surface over its own scroll viewport. Touch
1799
+ * pointers keep native scrolling; mouse/stylus presses pan `scrollLeft`/
1800
+ * `scrollTop` directly once the pointer travels past `threshold`, so child
1801
+ * clicks survive a press-release. While panning the element carries
1802
+ * `data-dragging="true"`. Returns the disposer removing every listener.
1803
+ */
1804
+ function attachDragPan(element, options = {}) {
1805
+ const direction = options.direction ?? "vertical";
1806
+ const threshold = options.threshold ?? 4;
1807
+ let anchor = null;
1808
+ let panned = false;
1809
+ const onPointerDown = (event) => {
1810
+ if (event.pointerType === "touch" || event.button !== 0) return;
1811
+ anchor = {
1812
+ x: event.clientX,
1813
+ y: event.clientY,
1814
+ left: element.scrollLeft,
1815
+ top: element.scrollTop
1816
+ };
1817
+ panned = false;
1818
+ };
1819
+ const onPointerMove = (event) => {
1820
+ if (anchor === null) return;
1821
+ const dx = event.clientX - anchor.x;
1822
+ const dy = event.clientY - anchor.y;
1823
+ if (!panned && Math.hypot(dx, dy) < threshold) return;
1824
+ panned = true;
1825
+ element.setAttribute("data-dragging", "true");
1826
+ if (direction !== "vertical") element.scrollLeft = anchor.left - dx;
1827
+ if (direction !== "horizontal") element.scrollTop = anchor.top - dy;
1828
+ };
1829
+ const endPan = () => {
1830
+ anchor = null;
1831
+ element.removeAttribute("data-dragging");
1832
+ };
1833
+ const onClickCapture = (event) => {
1834
+ if (!panned) return;
1835
+ panned = false;
1836
+ event.preventDefault();
1837
+ event.stopPropagation();
1838
+ };
1839
+ element.addEventListener("pointerdown", onPointerDown);
1840
+ element.addEventListener("pointermove", onPointerMove);
1841
+ element.addEventListener("pointerup", endPan);
1842
+ element.addEventListener("pointercancel", endPan);
1843
+ element.addEventListener("pointerleave", endPan);
1844
+ element.addEventListener("click", onClickCapture, true);
1845
+ return () => {
1846
+ element.removeEventListener("pointerdown", onPointerDown);
1847
+ element.removeEventListener("pointermove", onPointerMove);
1848
+ element.removeEventListener("pointerup", endPan);
1849
+ element.removeEventListener("pointercancel", endPan);
1850
+ element.removeEventListener("pointerleave", endPan);
1851
+ element.removeEventListener("click", onClickCapture, true);
1852
+ };
1853
+ }
1854
+ /** A scroll container any pointer can pan by dragging; touch keeps native
1855
+ * scrolling, mouse/stylus drags pan the viewport past a small travel
1856
+ * threshold, and child clicks survive a press-release. */
1857
+ function DragScroll({ direction = "vertical", className, style, children }) {
1858
+ const rootRef = useRef(null);
1859
+ useEffect(() => {
1860
+ const root = rootRef.current;
1861
+ if (root === null) return;
1862
+ return attachDragPan(root, { direction });
1863
+ }, [direction]);
1864
+ return jsx("div", {
1865
+ ref: rootRef,
1866
+ ...part("drag-scroll", "root"),
1867
+ className: cn("snap-drag-scroll", className),
1868
+ style: {
1869
+ overflowY: direction === "horizontal" ? "hidden" : "auto",
1870
+ overflowX: direction === "vertical" ? "hidden" : "auto",
1871
+ minHeight: 0,
1872
+ ...style
1873
+ },
1874
+ children: jsx("div", {
1875
+ ...part("drag-scroll", "viewport"),
1876
+ children
1877
+ })
1878
+ });
1879
+ }
1880
+ //#endregion
1881
+ //#region lib/types/components/schema-form.js
1882
+ /** The closed literal set a property may take: its `enum`, or — for a union of
1883
+ * scalar literals — the flattened `const` values of the `anyOf` branches, in
1884
+ * declaration order. `undefined` when the property is not a closed literal set
1885
+ * (open unions, non-scalar consts, absent both fields). */
1886
+ function literalValuesOf(property) {
1887
+ if (Array.isArray(property.enum)) return property.enum;
1888
+ const branches = property.anyOf;
1889
+ if (!Array.isArray(branches) || branches.length === 0) return void 0;
1890
+ const values = [];
1891
+ for (const branch of branches) {
1892
+ if (branch === null || typeof branch !== "object" || branch.anyOf !== void 0) return void 0;
1893
+ if (!("const" in branch)) return void 0;
1894
+ const value = branch.const;
1895
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return void 0;
1896
+ values.push(value);
1897
+ }
1898
+ return values;
1899
+ }
1900
+ function asRecord(value) {
1901
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
1902
+ }
1903
+ /** Render a flat JSON-Schema object as semantic fields. */
1904
+ function SchemaForm({ schema, value, onChange, idPrefix = "schema", columns }) {
1905
+ const properties = schema.properties ?? {};
1906
+ const required = new Set(schema.required ?? []);
1907
+ const update = (key, next) => {
1908
+ onChange({
1909
+ ...value,
1910
+ [key]: next
1911
+ });
1912
+ };
1913
+ const renderField = (key, property) => {
1914
+ const id = `${idPrefix}-${key}`;
1915
+ const current = value[key] ?? property.default;
1916
+ const label = property.title ?? key;
1917
+ const common = {
1918
+ label,
1919
+ htmlFor: id,
1920
+ ...property.description !== void 0 ? { help: property.description } : {},
1921
+ ...required.has(key) ? { required: true } : {}
1922
+ };
1923
+ const values = literalValuesOf(property);
1924
+ if (values !== void 0) {
1925
+ const options = values.map((item) => ({
1926
+ value: String(item),
1927
+ label: String(item)
1928
+ }));
1929
+ return jsx(Field, {
1930
+ ...common,
1931
+ children: jsx(TouchSelect, {
1932
+ ...current !== void 0 ? { value: String(current) } : {},
1933
+ options,
1934
+ onValueChange: (next) => {
1935
+ update(key, values.find((item) => String(item) === next) ?? next);
1936
+ },
1937
+ "aria-label": String(label)
1938
+ })
1939
+ });
1940
+ }
1941
+ if (property.type === "boolean") return jsx(Field, {
1942
+ ...common,
1943
+ children: jsx(Switch, {
1944
+ checked: current === true,
1945
+ onCheckedChange: (next) => update(key, next),
1946
+ "aria-label": String(label)
1947
+ })
1948
+ });
1949
+ if (property.type === "number" || property.type === "integer") return jsx(Field, {
1950
+ ...common,
1951
+ children: jsx(NumberInput, {
1952
+ id,
1953
+ value: typeof current === "number" ? current : "",
1954
+ ...property.minimum !== void 0 ? { min: property.minimum } : {},
1955
+ ...property.maximum !== void 0 ? { max: property.maximum } : {},
1956
+ onChange: (event) => {
1957
+ const raw = event.target.value;
1958
+ update(key, raw === "" ? void 0 : Number(raw));
1959
+ }
1960
+ })
1961
+ });
1962
+ if (property.type === "object" || property.type === "array") return jsx(Field, {
1963
+ ...common,
1964
+ help: property.description ?? "JSON 值",
1965
+ children: jsx(Textarea, {
1966
+ id,
1967
+ rows: 4,
1968
+ defaultValue: JSON.stringify(current ?? (property.type === "array" ? [] : {}), null, 2),
1969
+ onBlur: (event) => {
1970
+ try {
1971
+ update(key, JSON.parse(event.target.value));
1972
+ } catch {}
1973
+ }
1974
+ })
1975
+ });
1976
+ return jsx(Field, {
1977
+ ...common,
1978
+ children: jsx(Input, {
1979
+ id,
1980
+ value: typeof current === "string" || typeof current === "number" ? String(current) : "",
1981
+ onChange: (event) => update(key, event.target.value)
1982
+ })
1983
+ });
1984
+ };
1985
+ return jsxs("div", {
1986
+ ...part("schema-form", "root"),
1987
+ className: "snap-schema-form",
1988
+ style: columns !== void 0 ? {
1989
+ display: "grid",
1990
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
1991
+ gap: "var(--snap-space-md)"
1992
+ } : {
1993
+ display: "flex",
1994
+ flexDirection: "column",
1995
+ gap: "var(--snap-space-md)"
1996
+ },
1997
+ children: [Object.entries(properties).map(([key, property]) => jsx("div", {
1998
+ ...part("schema-form", "field"),
1999
+ children: renderField(key, property)
2000
+ }, key)), Object.keys(properties).length === 0 && jsx("span", {
2001
+ style: { color: "var(--snap-color-muted)" },
2002
+ children: "该驱动没有额外配置项。"
2003
+ })]
2004
+ });
2005
+ }
2006
+ /** Normalize a driver's JSON Schema (which may carry `$schema`). */
2007
+ function schemaNodeOf(value) {
2008
+ return asRecord(value);
2009
+ }
2010
+ //#endregion
2011
+ //#region lib/types/components/slider.js
2012
+ /**
2013
+ * Coarse value adjustment for touch operation: a Radix slider with the
2014
+ * semantic anatomy (`slider.root/track/range/thumb`). Thumb size rides the
2015
+ * skin's control tokens so gloved operation keeps a real target.
2016
+ *
2017
+ * @module @snap-rail/ui/components/slider
2018
+ */
2019
+ /** A ranged control with a large touch target and keyboard stepping. */
2020
+ function Slider({ label, className, children, ...props }) {
2021
+ return jsxs(SliderPrimitive.Root, {
2022
+ className: cn("snap-slider", className),
2023
+ "aria-label": label,
2024
+ ...props,
2025
+ ...part("slider", "root"),
2026
+ children: [
2027
+ jsx(SliderPrimitive.Track, {
2028
+ ...part("slider", "track"),
2029
+ className: "snap-slider-track",
2030
+ children: jsx(SliderPrimitive.Range, {
2031
+ ...part("slider", "range"),
2032
+ className: "snap-slider-range"
2033
+ })
2034
+ }),
2035
+ jsx(SliderPrimitive.Thumb, {
2036
+ ...part("slider", "thumb"),
2037
+ className: "snap-slider-thumb",
2038
+ "aria-label": label
2039
+ }),
2040
+ children
2041
+ ]
2042
+ });
2043
+ }
2044
+ //#endregion
2045
+ //#region lib/types/components/surface.js
2046
+ /** A content card. */
2047
+ function Card({ className, children, ...props }) {
2048
+ return jsx("div", {
2049
+ className: cn("snap-card", className),
2050
+ ...props,
2051
+ ...part("card", "root"),
2052
+ children
2053
+ });
2054
+ }
2055
+ /** The card header region. */
2056
+ function CardHeader({ className, children, ...props }) {
2057
+ return jsx("div", {
2058
+ className: cn("snap-card-header", className),
2059
+ ...props,
2060
+ ...part("card", "header"),
2061
+ children
2062
+ });
2063
+ }
2064
+ /** The card title. */
2065
+ function CardTitle({ className, children, ...props }) {
2066
+ return jsx("div", {
2067
+ className: cn("snap-card-title", className),
2068
+ ...props,
2069
+ ...part("card", "title"),
2070
+ children
2071
+ });
2072
+ }
2073
+ /** The card description. */
2074
+ function CardDescription({ className, children, ...props }) {
2075
+ return jsx("div", {
2076
+ className: cn("snap-card-description", className),
2077
+ ...props,
2078
+ ...part("card", "description"),
2079
+ children
2080
+ });
2081
+ }
2082
+ /** The card body. */
2083
+ function CardContent({ className, children, ...props }) {
2084
+ return jsx("div", {
2085
+ className: cn("snap-card-content", className),
2086
+ ...props,
2087
+ ...part("card", "body"),
2088
+ children
2089
+ });
2090
+ }
2091
+ /** The card footer. */
2092
+ function CardFooter({ className, children, ...props }) {
2093
+ return jsx("div", {
2094
+ className: cn("snap-card-footer", className),
2095
+ ...props,
2096
+ ...part("card", "footer"),
2097
+ children
2098
+ });
2099
+ }
2100
+ /** A bounded panel with optional header/footer. */
2101
+ function Panel({ title, actions, footer, className, children, ...props }) {
2102
+ return jsxs("div", {
2103
+ className: cn("snap-panel", className),
2104
+ ...props,
2105
+ ...part("panel", "root"),
2106
+ children: [
2107
+ (title !== void 0 || actions !== void 0) && jsxs("div", {
2108
+ ...part("panel", "header"),
2109
+ className: "snap-panel-header",
2110
+ children: [jsx("div", {
2111
+ ...part("panel", "title"),
2112
+ children: title
2113
+ }), actions !== void 0 && jsx("div", { children: actions })]
2114
+ }),
2115
+ jsx("div", {
2116
+ ...part("panel", "body"),
2117
+ className: "snap-panel-body",
2118
+ children
2119
+ }),
2120
+ footer !== void 0 && jsx("div", {
2121
+ ...part("panel", "footer"),
2122
+ className: "snap-panel-footer",
2123
+ children: footer
2124
+ })
2125
+ ]
2126
+ });
2127
+ }
2128
+ /** A semantic table. */
2129
+ function Table({ className, children, ...props }) {
2130
+ return jsx("div", {
2131
+ ...part("table", "root"),
2132
+ className: cn("snap-table", className),
2133
+ children: jsx("table", {
2134
+ ...props,
2135
+ children
2136
+ })
2137
+ });
2138
+ }
2139
+ /** The table head. */
2140
+ function TableHeader({ className, children, ...props }) {
2141
+ return jsx("thead", {
2142
+ className: cn("snap-table-header", className),
2143
+ ...props,
2144
+ ...part("table", "header"),
2145
+ children
2146
+ });
2147
+ }
2148
+ /** The table body. */
2149
+ function TableBody({ className, children, ...props }) {
2150
+ return jsx("tbody", {
2151
+ className: cn("snap-table-body", className),
2152
+ ...props,
2153
+ ...part("table", "body"),
2154
+ children
2155
+ });
2156
+ }
2157
+ /** A table row. */
2158
+ function TableRow({ className, children, ...props }) {
2159
+ return jsx("tr", {
2160
+ className: cn("snap-table-row", className),
2161
+ ...props,
2162
+ ...part("table", "row"),
2163
+ children
2164
+ });
2165
+ }
2166
+ /** A table header cell. */
2167
+ function TableHead({ className, children, ...props }) {
2168
+ return jsx("th", {
2169
+ className: cn("snap-table-head", className),
2170
+ ...props,
2171
+ ...part("table", "head"),
2172
+ children
2173
+ });
2174
+ }
2175
+ /** A table body cell. */
2176
+ function TableCell({ className, children, ...props }) {
2177
+ return jsx("td", {
2178
+ className: cn("snap-table-cell", className),
2179
+ ...props,
2180
+ ...part("table", "cell"),
2181
+ children
2182
+ });
2183
+ }
2184
+ /** A full-width empty row. */
2185
+ function TableEmpty({ colSpan, children }) {
2186
+ return jsx(TableRow, { children: jsx(TableCell, {
2187
+ colSpan,
2188
+ children: jsx("div", {
2189
+ ...part("table", "empty"),
2190
+ children
2191
+ })
2192
+ }) });
2193
+ }
2194
+ //#endregion
2195
+ export { Alert, AlertDescription, AlertTitle, AppShell, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Combobox, Controller, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DragScroll, EmptyState, Field, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, FormProvider, Grid, IconButton, Input, Label, Led, List, ListItem, Menu, MenuCheckboxItem, MenuContent, MenuGroup, MenuItem, MenuLabel, MenuSeparator, MenuTrigger, NumberInput, Page, Panel, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, Row, SchemaForm, ScrollArea, Section, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, Separator, Sheet, Skeleton, Slider, Spinner, Split, Stack, Switch, Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toast, ToastAction, ToastClose, ToastDescription, ToastTitle, ToastViewport, Toaster, Toolbar, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TouchSelect, attachDragPan, cn, controlHeight, dismissToast, literalValuesOf, part, schemaNodeOf, space, toast, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch, zodResolver };