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