@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
package/lib/index.js CHANGED
@@ -1,14 +1,632 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { rpcErrorText } from "@snap-rail/connection";
3
- import { useEffect, useState } from "react";
4
- import { Slot } from "@radix-ui/react-slot";
5
- import "@radix-ui/react-checkbox";
6
- import "@radix-ui/react-label";
7
- import "@radix-ui/react-radio-group";
8
- import "@radix-ui/react-select";
2
+ import { Component, createContext, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
+ import * as SeparatorPrimitive from "@radix-ui/react-separator";
4
+ import { Slot as Slot$1 } from "@radix-ui/react-slot";
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";
9
13
  import * as SwitchPrimitive from "@radix-ui/react-switch";
10
- import "@radix-ui/react-tabs";
14
+ import * as TabsPrimitive from "@radix-ui/react-tabs";
11
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
+ import { attachBallDrag as attachBallDrag$1 } from "@snap-rail/client-kernel";
21
+ import { rpcErrorText, subscribeFrame } from "@snap-rail/connection";
22
+ import { settingsChangedSchema } from "@snap-rail/station-rpc/contract";
23
+ import { Context } from "@snap-rail/cordis";
24
+ import { TimerService } from "@snap-rail/cordis-plugin-timer";
25
+ import { shellContract } from "@snap-rail/shell/contract";
26
+ import { createRoot } from "react-dom/client";
27
+ import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
28
+ //#region lib/types/contract.js
29
+ /**
30
+ * The semantic UI contract: component names, region-slot ids, scoped slot
31
+ * contexts, and the author-facing UI profile vocabulary. This module is pure
32
+ * (types, constants, guards) so host and renderer faces can both import it
33
+ * without dragging React or the renderer runtime into the host graph.
34
+ *
35
+ * @module @snap-rail/ui/contract
36
+ */
37
+ /** The author-declared relationship between a plugin and the skin contract. */
38
+ const UI_PROFILES = [
39
+ "native",
40
+ "integrated",
41
+ "custom"
42
+ ];
43
+ /** The stable region slots every layout may provide. */
44
+ const UI_SLOT_IDS = {
45
+ /** The one active layout of the operator window. */
46
+ layout: "shell.layout",
47
+ /** The operator titlebar. */
48
+ titlebar: "shell.titlebar",
49
+ /** Contributed titlebar actions. */
50
+ titlebarActions: "shell.titlebar.actions",
51
+ /** Sidebar extension area. */
52
+ sidebar: "shell.sidebar",
53
+ /** Statusbar extension area. */
54
+ statusbar: "shell.statusbar",
55
+ /** The global overlay stack (dialogs, confirms). */
56
+ overlay: "shell.overlay",
57
+ /** The floating ball surface face. */
58
+ ball: "shell.ball",
59
+ /** The settings trigger. */
60
+ settingsEntry: "settings.entry",
61
+ /** The settings surface itself. */
62
+ settingsSurface: "settings.surface"
63
+ };
64
+ /** A named custom slot is owned by a publisher package. */
65
+ const CUSTOM_SLOT_PATTERN = /^custom:[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*$/;
66
+ /** Check a region-slot id at runtime. */
67
+ function isValidSlotId(value) {
68
+ return Object.values(UI_SLOT_IDS).includes(value) || CUSTOM_SLOT_PATTERN.test(value);
69
+ }
70
+ /** The occupancy mode of every built-in slot. */
71
+ const UI_SLOT_MODES = {
72
+ [UI_SLOT_IDS.layout]: "one",
73
+ [UI_SLOT_IDS.titlebar]: "one",
74
+ [UI_SLOT_IDS.titlebarActions]: "many",
75
+ [UI_SLOT_IDS.sidebar]: "many",
76
+ [UI_SLOT_IDS.statusbar]: "many",
77
+ [UI_SLOT_IDS.overlay]: "many",
78
+ [UI_SLOT_IDS.ball]: "one",
79
+ [UI_SLOT_IDS.settingsEntry]: "one",
80
+ [UI_SLOT_IDS.settingsSurface]: "one"
81
+ };
82
+ /** Diagnostic kinds surfaced by the UI registry. */
83
+ const UI_DIAGNOSTIC_KINDS = [
84
+ "unknown-slot",
85
+ "missing-provider",
86
+ "invalid-context",
87
+ "duplicate-id",
88
+ "render-failed",
89
+ "declared-not-rendered"
90
+ ];
91
+ /**
92
+ * The component catalog. It is the shared vocabulary for the gallery, skin
93
+ * coverage checks, and author documentation; adding a component here is a
94
+ * contract change, not an implementation detail.
95
+ */
96
+ const UI_COMPONENTS = {
97
+ button: {
98
+ parts: [
99
+ "button.root",
100
+ "button.label",
101
+ "button.icon",
102
+ "button.spinner"
103
+ ],
104
+ slots: ["label", "icon"],
105
+ props: [
106
+ "intent",
107
+ "emphasis",
108
+ "size",
109
+ "loading",
110
+ "disabled"
111
+ ]
112
+ },
113
+ "icon-button": {
114
+ parts: ["icon-button.root", "icon-button.icon"],
115
+ slots: ["icon"],
116
+ props: [
117
+ "intent",
118
+ "emphasis",
119
+ "size",
120
+ "active",
121
+ "disabled"
122
+ ]
123
+ },
124
+ input: {
125
+ parts: [
126
+ "input.root",
127
+ "input.field",
128
+ "input.prefix",
129
+ "input.suffix",
130
+ "input.clear"
131
+ ],
132
+ slots: ["prefix", "suffix"],
133
+ props: [
134
+ "size",
135
+ "invalid",
136
+ "disabled",
137
+ "fieldClassName"
138
+ ]
139
+ },
140
+ textarea: {
141
+ parts: ["textarea.root", "textarea.field"],
142
+ props: [
143
+ "size",
144
+ "invalid",
145
+ "disabled",
146
+ "fieldClassName"
147
+ ]
148
+ },
149
+ "number-input": {
150
+ parts: [
151
+ "number-input.root",
152
+ "number-input.field",
153
+ "number-input.step-up",
154
+ "number-input.step-down"
155
+ ],
156
+ props: [
157
+ "size",
158
+ "invalid",
159
+ "disabled"
160
+ ]
161
+ },
162
+ select: {
163
+ parts: [
164
+ "select.root",
165
+ "select.trigger",
166
+ "select.value",
167
+ "select.chevron",
168
+ "select.content",
169
+ "select.item",
170
+ "select.item-indicator",
171
+ "select.empty"
172
+ ],
173
+ slots: ["empty", "children"],
174
+ props: [
175
+ "size",
176
+ "invalid",
177
+ "disabled",
178
+ "defaultValue",
179
+ "side",
180
+ "align"
181
+ ]
182
+ },
183
+ "touch-select": {
184
+ parts: [
185
+ "touch-select.root",
186
+ "touch-select.trigger",
187
+ "touch-select.sheet",
188
+ "touch-select.options"
189
+ ],
190
+ props: ["invalid", "disabled"]
191
+ },
192
+ combobox: {
193
+ parts: [
194
+ "combobox.root",
195
+ "combobox.anchor",
196
+ "combobox.list",
197
+ "combobox.option",
198
+ "combobox.empty"
199
+ ],
200
+ slots: ["empty"],
201
+ props: [
202
+ "value",
203
+ "options",
204
+ "size",
205
+ "invalid",
206
+ "disabled",
207
+ "loading",
208
+ "onInputValueChange"
209
+ ]
210
+ },
211
+ checkbox: {
212
+ parts: [
213
+ "checkbox.root",
214
+ "checkbox.indicator",
215
+ "checkbox.label",
216
+ "checkbox.field",
217
+ "checkbox.description"
218
+ ],
219
+ slots: ["label", "description"],
220
+ props: [
221
+ "checked",
222
+ "invalid",
223
+ "disabled",
224
+ "labelPosition"
225
+ ]
226
+ },
227
+ switch: {
228
+ parts: [
229
+ "switch.root",
230
+ "switch.thumb",
231
+ "switch.label",
232
+ "switch.field",
233
+ "switch.description"
234
+ ],
235
+ slots: ["label", "description"],
236
+ props: [
237
+ "checked",
238
+ "disabled",
239
+ "labelPosition"
240
+ ]
241
+ },
242
+ "radio-group": {
243
+ parts: [
244
+ "radio-group.root",
245
+ "radio-group.item",
246
+ "radio-group.indicator",
247
+ "radio-group.label",
248
+ "radio-group.block",
249
+ "radio-group.description"
250
+ ],
251
+ props: [
252
+ "value",
253
+ "disabled",
254
+ "label",
255
+ "description"
256
+ ]
257
+ },
258
+ tabs: {
259
+ parts: [
260
+ "tabs.root",
261
+ "tabs.list",
262
+ "tabs.trigger",
263
+ "tabs.content"
264
+ ],
265
+ slots: ["list", "content"],
266
+ props: ["value"]
267
+ },
268
+ table: {
269
+ parts: [
270
+ "table.root",
271
+ "table.header",
272
+ "table.body",
273
+ "table.row",
274
+ "table.head",
275
+ "table.cell",
276
+ "table.empty"
277
+ ],
278
+ slots: ["empty"]
279
+ },
280
+ card: {
281
+ parts: [
282
+ "card.root",
283
+ "card.header",
284
+ "card.title",
285
+ "card.description",
286
+ "card.body",
287
+ "card.footer"
288
+ ],
289
+ slots: [
290
+ "header",
291
+ "title",
292
+ "description",
293
+ "body",
294
+ "footer"
295
+ ]
296
+ },
297
+ panel: {
298
+ parts: [
299
+ "panel.root",
300
+ "panel.header",
301
+ "panel.title",
302
+ "panel.body",
303
+ "panel.footer"
304
+ ],
305
+ slots: [
306
+ "header",
307
+ "title",
308
+ "body",
309
+ "footer"
310
+ ]
311
+ },
312
+ dialog: {
313
+ parts: [
314
+ "dialog.overlay",
315
+ "dialog.panel",
316
+ "dialog.header",
317
+ "dialog.title",
318
+ "dialog.description",
319
+ "dialog.body",
320
+ "dialog.footer",
321
+ "dialog.close"
322
+ ],
323
+ slots: [
324
+ "header",
325
+ "title",
326
+ "description",
327
+ "body",
328
+ "footer"
329
+ ],
330
+ props: [
331
+ "open",
332
+ "presentation",
333
+ "size"
334
+ ]
335
+ },
336
+ sheet: {
337
+ parts: [
338
+ "dialog.overlay",
339
+ "dialog.panel",
340
+ "dialog.header",
341
+ "dialog.title",
342
+ "dialog.description",
343
+ "dialog.body",
344
+ "dialog.footer"
345
+ ],
346
+ slots: [
347
+ "header",
348
+ "body",
349
+ "footer"
350
+ ],
351
+ props: ["open", "presentation"]
352
+ },
353
+ popover: {
354
+ parts: ["popover.trigger", "popover.content"],
355
+ slots: ["trigger", "content"]
356
+ },
357
+ tooltip: {
358
+ parts: ["tooltip.trigger", "tooltip.content"],
359
+ slots: ["trigger", "content"]
360
+ },
361
+ menu: {
362
+ parts: [
363
+ "menu.trigger",
364
+ "menu.content",
365
+ "menu.item",
366
+ "menu.checkbox-item",
367
+ "menu.item-indicator",
368
+ "menu.separator"
369
+ ],
370
+ slots: ["trigger", "content"]
371
+ },
372
+ toast: {
373
+ parts: [
374
+ "toast.root",
375
+ "toast.title",
376
+ "toast.description",
377
+ "toast.action",
378
+ "toast.close",
379
+ "toast.viewport"
380
+ ],
381
+ slots: ["action"]
382
+ },
383
+ progress: { parts: [
384
+ "progress.root",
385
+ "progress.track",
386
+ "progress.indicator"
387
+ ] },
388
+ badge: { parts: ["badge.root"] },
389
+ led: {
390
+ parts: ["led.root", "led.halo"],
391
+ props: ["tone"]
392
+ },
393
+ alert: {
394
+ parts: [
395
+ "alert.root",
396
+ "alert.title",
397
+ "alert.description"
398
+ ],
399
+ slots: ["title", "description"],
400
+ props: ["intent"]
401
+ },
402
+ separator: {
403
+ parts: ["separator.root"],
404
+ props: ["orientation"]
405
+ },
406
+ skeleton: {
407
+ parts: ["skeleton.root"],
408
+ props: ["variant"]
409
+ },
410
+ list: {
411
+ parts: [
412
+ "list.root",
413
+ "list.item",
414
+ "list.leading",
415
+ "list.content",
416
+ "list.trailing"
417
+ ],
418
+ slots: ["leading", "trailing"],
419
+ props: [
420
+ "divided",
421
+ "selected",
422
+ "disabled"
423
+ ]
424
+ },
425
+ slider: {
426
+ parts: [
427
+ "slider.root",
428
+ "slider.track",
429
+ "slider.range",
430
+ "slider.thumb"
431
+ ],
432
+ props: [
433
+ "value",
434
+ "min",
435
+ "max",
436
+ "step"
437
+ ]
438
+ },
439
+ spinner: { parts: ["spinner.root"] },
440
+ "empty-state": {
441
+ parts: [
442
+ "empty-state.root",
443
+ "empty-state.icon",
444
+ "empty-state.title",
445
+ "empty-state.description",
446
+ "empty-state.action"
447
+ ],
448
+ slots: [
449
+ "icon",
450
+ "title",
451
+ "description",
452
+ "action"
453
+ ]
454
+ },
455
+ form: {
456
+ parts: [
457
+ "form.root",
458
+ "form.fields",
459
+ "form.actions"
460
+ ],
461
+ slots: ["fields", "actions"],
462
+ props: [
463
+ "orientation",
464
+ "gap",
465
+ "columns",
466
+ "form"
467
+ ]
468
+ },
469
+ field: {
470
+ parts: [
471
+ "field.root",
472
+ "field.label",
473
+ "field.control",
474
+ "field.help",
475
+ "field.error"
476
+ ],
477
+ slots: [
478
+ "label",
479
+ "control",
480
+ "help",
481
+ "error"
482
+ ],
483
+ props: [
484
+ "invalid",
485
+ "required",
486
+ "orientation",
487
+ "labelWidth",
488
+ "labelAlign"
489
+ ]
490
+ },
491
+ "schema-form": {
492
+ parts: ["schema-form.root", "schema-form.field"],
493
+ slots: ["fields"],
494
+ props: ["columns"]
495
+ },
496
+ "app-shell": {
497
+ parts: [
498
+ "app-shell.root",
499
+ "app-shell.header",
500
+ "app-shell.sidebar",
501
+ "app-shell.main",
502
+ "app-shell.footer"
503
+ ],
504
+ slots: [
505
+ "header",
506
+ "sidebar",
507
+ "main",
508
+ "footer"
509
+ ]
510
+ },
511
+ page: {
512
+ parts: [
513
+ "page.root",
514
+ "page.header",
515
+ "page.title",
516
+ "page.description",
517
+ "page.actions",
518
+ "page.body"
519
+ ],
520
+ slots: [
521
+ "header",
522
+ "title",
523
+ "description",
524
+ "actions",
525
+ "body"
526
+ ]
527
+ },
528
+ section: {
529
+ parts: [
530
+ "section.root",
531
+ "section.header",
532
+ "section.title",
533
+ "section.actions",
534
+ "section.body"
535
+ ],
536
+ slots: [
537
+ "header",
538
+ "title",
539
+ "actions",
540
+ "body"
541
+ ]
542
+ },
543
+ toolbar: {
544
+ parts: [
545
+ "toolbar.root",
546
+ "toolbar.start",
547
+ "toolbar.center",
548
+ "toolbar.end"
549
+ ],
550
+ slots: ["start", "end"]
551
+ },
552
+ stack: {
553
+ parts: ["stack.root"],
554
+ props: [
555
+ "gap",
556
+ "padding",
557
+ "align"
558
+ ]
559
+ },
560
+ row: {
561
+ parts: ["row.root"],
562
+ props: [
563
+ "gap",
564
+ "padding",
565
+ "align",
566
+ "justify"
567
+ ]
568
+ },
569
+ grid: {
570
+ parts: ["grid.root"],
571
+ props: [
572
+ "gap",
573
+ "columns",
574
+ "padding"
575
+ ]
576
+ },
577
+ split: {
578
+ parts: [
579
+ "split.root",
580
+ "split.start",
581
+ "split.end"
582
+ ],
583
+ slots: ["start", "end"]
584
+ },
585
+ "scroll-area": { parts: [
586
+ "scroll-area.root",
587
+ "scroll-area.viewport",
588
+ "scroll-area.scrollbar",
589
+ "scroll-area.thumb"
590
+ ] },
591
+ "drag-scroll": { parts: ["drag-scroll.root", "drag-scroll.viewport"] },
592
+ "chart-frame": {
593
+ parts: [
594
+ "chart-frame.root",
595
+ "chart-frame.header",
596
+ "chart-frame.title",
597
+ "chart-frame.description",
598
+ "chart-frame.actions",
599
+ "chart-frame.body",
600
+ "chart-frame.loading",
601
+ "chart-frame.empty",
602
+ "chart-frame.error"
603
+ ],
604
+ slots: [
605
+ "header",
606
+ "title",
607
+ "description",
608
+ "actions",
609
+ "body",
610
+ "empty",
611
+ "error",
612
+ "loading"
613
+ ],
614
+ props: ["state"]
615
+ },
616
+ settings: { parts: [
617
+ "settings.root",
618
+ "settings.header",
619
+ "settings.title",
620
+ "settings.body",
621
+ "settings.nav",
622
+ "settings.nav-item",
623
+ "settings.nav-icon",
624
+ "settings.group",
625
+ "settings.group-title",
626
+ "settings.content"
627
+ ] }
628
+ };
629
+ //#endregion
12
630
  //#region lib/types/utils.js
13
631
  /**
14
632
  * Small helpers shared by the headless semantic components: class merging and
@@ -20,18 +638,474 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
20
638
  function cn(...values) {
21
639
  return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
22
640
  }
23
- /** The anatomy attributes every semantic component renders. */
641
+ /**
642
+ * The anatomy attributes every semantic component renders. The identity is
643
+ * component-owned: components spread these AFTER caller props so a composite
644
+ * can never mask a host part (a masked `button.root` loses every skin rule
645
+ * and falls back to the UA default look). Composites tag their own wrappers
646
+ * instead of pushing `part()` into a child component's props.
647
+ */
24
648
  function part(component, name) {
25
649
  return {
26
650
  "data-snap-component": component,
27
651
  "data-snap-part": `${component}.${name}`
28
652
  };
29
653
  }
654
+ /** Map a semantic size token to a control-height CSS variable. */
655
+ function controlHeight(size) {
656
+ return `var(--snap-control-height-${size})`;
657
+ }
30
658
  /** Map a semantic spacing token to a CSS variable. */
31
659
  function space(token) {
32
660
  return `var(--snap-space-${token})`;
33
661
  }
34
662
  //#endregion
663
+ //#region lib/types/skins.js
664
+ /** The factory day theme id (cobalt palette, light surfaces). */
665
+ const DEFAULT_LIGHT_ID = "default-light";
666
+ /** The factory night theme id (cobalt palette, dark surfaces). */
667
+ const DEFAULT_DARK_ID = "default-dark";
668
+ /** The contributor label for the factory themes. */
669
+ const FACTORY_CALLER = "@snap-rail/ui";
670
+ const COBALT_DARK_TOKENS = {
671
+ colorBg: "#0b0f14",
672
+ colorSurface: "#11161d",
673
+ colorSurfaceRaised: "#161b22",
674
+ colorText: "#ced8e3",
675
+ colorMuted: "#8b949e",
676
+ colorPrimary: "#4a6cff",
677
+ colorOnPrimary: "#ffffff",
678
+ colorDanger: "#f85149",
679
+ colorSuccess: "#3fb950",
680
+ colorWarning: "#d29922",
681
+ colorBorder: "#1f2933",
682
+ colorFocus: "#4a6cff",
683
+ chart1: "#4a6cff",
684
+ chart2: "#3147a1",
685
+ chart3: "#667fcd",
686
+ chart4: "#7d8fa5",
687
+ chart5: "#55677c",
688
+ chart6: "#33414f",
689
+ fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
690
+ fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
691
+ textXs: "13px",
692
+ textSm: "15px",
693
+ textMd: "17px",
694
+ textLg: "20px",
695
+ textXl: "24px",
696
+ weightNormal: "400",
697
+ weightMedium: "500",
698
+ weightStrong: "600",
699
+ leadingTight: "1.2",
700
+ leadingNormal: "1.55",
701
+ spaceXs: "4px",
702
+ spaceSm: "8px",
703
+ spaceMd: "12px",
704
+ spaceLg: "20px",
705
+ spaceXl: "32px",
706
+ radiusSm: "6px",
707
+ radiusMd: "8px",
708
+ radiusLg: "12px",
709
+ radiusFull: "999px",
710
+ borderWidth: "1px",
711
+ shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
712
+ shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
713
+ shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
714
+ durationFast: "120ms",
715
+ durationNormal: "180ms",
716
+ durationSlow: "280ms",
717
+ easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
718
+ zOverlay: "50",
719
+ zModal: "60",
720
+ zToast: "70",
721
+ controlHeightSm: "40px",
722
+ controlHeightMd: "48px",
723
+ controlHeightLg: "56px",
724
+ density: "comfortable"
725
+ };
726
+ /** The factory day theme. Always registered; never the first paint though — the night theme is. */
727
+ const DEFAULT_LIGHT = {
728
+ id: DEFAULT_LIGHT_ID,
729
+ title: "钴蓝·白天",
730
+ tokens: {
731
+ colorBg: "#e4e9ef",
732
+ colorSurface: "#f3f6f9",
733
+ colorSurfaceRaised: "#ffffff",
734
+ colorText: "#26323e",
735
+ colorMuted: "#5d6d7e",
736
+ colorPrimary: "#3857e8",
737
+ colorOnPrimary: "#ffffff",
738
+ colorDanger: "#dc2626",
739
+ colorSuccess: "#15803d",
740
+ colorWarning: "#b45309",
741
+ colorBorder: "#c7d0da",
742
+ colorFocus: "#3857e8",
743
+ chart1: "#3857e8",
744
+ chart2: "#7088ee",
745
+ chart3: "#667dd0",
746
+ chart4: "#94a3b8",
747
+ chart5: "#b3c0cd",
748
+ chart6: "#ccd6e0",
749
+ fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
750
+ fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
751
+ textXs: "13px",
752
+ textSm: "15px",
753
+ textMd: "17px",
754
+ textLg: "20px",
755
+ textXl: "24px",
756
+ weightNormal: "400",
757
+ weightMedium: "500",
758
+ weightStrong: "600",
759
+ leadingTight: "1.2",
760
+ leadingNormal: "1.55",
761
+ spaceXs: "4px",
762
+ spaceSm: "8px",
763
+ spaceMd: "12px",
764
+ spaceLg: "20px",
765
+ spaceXl: "32px",
766
+ radiusSm: "6px",
767
+ radiusMd: "8px",
768
+ radiusLg: "12px",
769
+ radiusFull: "999px",
770
+ borderWidth: "1px",
771
+ shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
772
+ shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
773
+ shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
774
+ durationFast: "120ms",
775
+ durationNormal: "180ms",
776
+ durationSlow: "280ms",
777
+ easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
778
+ zOverlay: "50",
779
+ zModal: "60",
780
+ zToast: "70",
781
+ controlHeightSm: "40px",
782
+ controlHeightMd: "48px",
783
+ controlHeightLg: "56px",
784
+ density: "comfortable"
785
+ }
786
+ };
787
+ /** The factory night theme and the registry's fallback. */
788
+ const DEFAULT_DARK = {
789
+ id: DEFAULT_DARK_ID,
790
+ title: "钴蓝·黑夜",
791
+ tokens: COBALT_DARK_TOKENS
792
+ };
793
+ /** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
794
+ function skinTokenVar(key) {
795
+ return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
796
+ }
797
+ /** Apply the active theme to the document root. */
798
+ function applySkin(skin) {
799
+ if (typeof document === "undefined") return;
800
+ const root = document.documentElement;
801
+ root.dataset["snapSkin"] = skin.id;
802
+ for (const [key, value] of Object.entries(skin.tokens)) root.style.setProperty(skinTokenVar(key), value);
803
+ }
804
+ /** Mount the `ctx.skins` registry. */
805
+ const skinsPlugin = {
806
+ name: "snap-rail ui skins",
807
+ apply(ctx) {
808
+ const skins = /* @__PURE__ */ new Map();
809
+ const callers = /* @__PURE__ */ new Map();
810
+ const listeners = /* @__PURE__ */ new Set();
811
+ const styleTags = /* @__PURE__ */ new Map();
812
+ let activeId = DEFAULT_DARK_ID;
813
+ let revision = 0;
814
+ skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
815
+ callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
816
+ skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
817
+ callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
818
+ const notify = () => {
819
+ revision += 1;
820
+ for (const listener of listeners) listener();
821
+ ctx.emit("skins/changed");
822
+ };
823
+ const ensureStyleTag = (skin) => {
824
+ if (typeof document === "undefined" || skin.css === void 0) return;
825
+ if (styleTags.has(skin.id)) return;
826
+ const tag = document.createElement("style");
827
+ tag.dataset["snapSkinStyle"] = skin.id;
828
+ tag.textContent = skin.css;
829
+ document.head.append(tag);
830
+ styleTags.set(skin.id, tag);
831
+ };
832
+ const refresh = () => {
833
+ const skin = skins.get(activeId) ?? DEFAULT_DARK;
834
+ activeId = skin.id;
835
+ ensureStyleTag(skin);
836
+ applySkin(skin);
837
+ notify();
838
+ };
839
+ ctx.provide("skins", {
840
+ register(caller, skin) {
841
+ skins.set(skin.id, skin);
842
+ callers.set(skin.id, caller.fiber.name);
843
+ refresh();
844
+ const remove = () => {
845
+ if (!skins.delete(skin.id)) return;
846
+ callers.delete(skin.id);
847
+ const tag = styleTags.get(skin.id);
848
+ if (tag !== void 0) {
849
+ tag.remove();
850
+ styleTags.delete(skin.id);
851
+ }
852
+ if (activeId === skin.id) activeId = DEFAULT_DARK_ID;
853
+ refresh();
854
+ };
855
+ caller.effect(() => remove);
856
+ return remove;
857
+ },
858
+ activate(selection) {
859
+ let next = skins.has(selection) ? selection : void 0;
860
+ if (next === void 0) {
861
+ for (const [id, owner] of callers) if (id !== selection && owner === selection && skins.has(id)) {
862
+ next = id;
863
+ break;
864
+ }
865
+ }
866
+ if (next === void 0) return false;
867
+ if (next === activeId) return true;
868
+ activeId = next;
869
+ refresh();
870
+ return true;
871
+ },
872
+ list: () => [...skins.values()].map((skin) => ({
873
+ id: skin.id,
874
+ title: skin.title,
875
+ caller: callers.get(skin.id) ?? FACTORY_CALLER
876
+ })),
877
+ active: () => skins.get(activeId) ?? DEFAULT_DARK,
878
+ tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
879
+ subscribe(listener) {
880
+ listeners.add(listener);
881
+ return () => {
882
+ listeners.delete(listener);
883
+ };
884
+ },
885
+ version: () => revision
886
+ });
887
+ refresh();
888
+ }
889
+ };
890
+ /** The React context carrying the skin service. */
891
+ const SkinsContext = createContext(null);
892
+ /** Provide the skin service to a renderer tree. */
893
+ function SkinsProvider(props) {
894
+ return jsx(SkinsContext.Provider, {
895
+ value: props.service,
896
+ children: props.children
897
+ });
898
+ }
899
+ /** Read the skin service. */
900
+ function useSkins() {
901
+ const service = useContext(SkinsContext);
902
+ if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
903
+ return service;
904
+ }
905
+ /** Re-render on theme changes and return the active token set. */
906
+ function useSkinTokens() {
907
+ const service = useSkins();
908
+ useSyncExternalStore(service.subscribe, service.version, service.version);
909
+ return service.tokens();
910
+ }
911
+ /** Re-render on theme changes and return the active theme id. */
912
+ function useSkinId() {
913
+ const service = useSkins();
914
+ useSyncExternalStore(service.subscribe, service.version, service.version);
915
+ return service.active().id;
916
+ }
917
+ //#endregion
918
+ //#region lib/types/charts.js
919
+ /** A semantic frame for a chart, gauge, map, or custom visualization. */
920
+ function ChartFrame({ title, description, actions, state = "ready", empty, error, loading, children, className, style }) {
921
+ return jsxs("section", {
922
+ ...part("chart-frame", "root"),
923
+ className: cn("snap-chart-frame", className),
924
+ "data-state": state,
925
+ style,
926
+ children: [(title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("header", {
927
+ ...part("chart-frame", "header"),
928
+ className: "snap-chart-frame-header",
929
+ children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
930
+ ...part("chart-frame", "title"),
931
+ children: title
932
+ }), description !== void 0 && jsx("div", {
933
+ ...part("chart-frame", "description"),
934
+ className: "snap-chart-frame-description",
935
+ children: description
936
+ })] }), actions !== void 0 && jsx("div", {
937
+ ...part("chart-frame", "actions"),
938
+ children: actions
939
+ })]
940
+ }), jsx("div", {
941
+ ...part("chart-frame", "body"),
942
+ className: "snap-chart-frame-body",
943
+ "data-state": state,
944
+ children: state === "loading" ? loading ?? jsx("div", {
945
+ ...part("chart-frame", "loading"),
946
+ children: "加载中…"
947
+ }) : state === "empty" ? empty ?? jsx("div", {
948
+ ...part("chart-frame", "empty"),
949
+ children: "暂无数据"
950
+ }) : state === "error" ? error ?? jsx("div", {
951
+ ...part("chart-frame", "error"),
952
+ role: "alert",
953
+ children: "图表加载失败"
954
+ }) : children
955
+ })]
956
+ });
957
+ }
958
+ /** An alias of {@link ChartFrame} for pages that prefer the generic name. */
959
+ function Visualization(props) {
960
+ return jsx(ChartFrame, { ...props });
961
+ }
962
+ /** Turn the active skin tokens into a chart-library theme. */
963
+ function chartThemeOf(tokens) {
964
+ return {
965
+ color: [
966
+ tokens.chart1,
967
+ tokens.chart2,
968
+ tokens.chart3,
969
+ tokens.chart4,
970
+ tokens.chart5,
971
+ tokens.chart6
972
+ ],
973
+ backgroundColor: tokens.colorSurface,
974
+ textStyle: {
975
+ color: tokens.colorText,
976
+ fontFamily: tokens.fontSans,
977
+ fontSize: Number.parseInt(tokens.textSm, 10) || 14
978
+ },
979
+ axisLine: { lineStyle: { color: tokens.colorBorder } },
980
+ splitLine: { lineStyle: {
981
+ color: tokens.colorBorder,
982
+ type: "dashed"
983
+ } },
984
+ tooltip: {
985
+ backgroundColor: tokens.colorSurfaceRaised,
986
+ borderColor: tokens.colorBorder,
987
+ textStyle: {
988
+ color: tokens.colorText,
989
+ fontFamily: tokens.fontSans
990
+ }
991
+ }
992
+ };
993
+ }
994
+ /** The active chart theme, re-derived whenever the skin/mode changes. */
995
+ function useChartTheme() {
996
+ return chartThemeOf(useSkinTokens());
997
+ }
998
+ //#endregion
999
+ //#region lib/types/components/alert.js
1000
+ /**
1001
+ * Attention surfaces: alerts (inline banners), separators, skeletons, and
1002
+ * lists. Read-only primitives; the skin owns their visuals through the
1003
+ * `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
1004
+ *
1005
+ * @module @snap-rail/ui/components/alert
1006
+ */
1007
+ /** An inline status banner for results and failures. */
1008
+ function Alert({ intent = "neutral", className, children, ...props }) {
1009
+ return jsx("div", {
1010
+ role: "alert",
1011
+ className: cn("snap-alert", className),
1012
+ "data-intent": intent,
1013
+ ...props,
1014
+ ...part("alert", "root"),
1015
+ children
1016
+ });
1017
+ }
1018
+ /** The alert heading line. */
1019
+ function AlertTitle({ className, children, ...props }) {
1020
+ return jsx("h5", {
1021
+ className: cn("snap-alert-title", className),
1022
+ ...props,
1023
+ ...part("alert", "title"),
1024
+ children
1025
+ });
1026
+ }
1027
+ /** The alert body text. */
1028
+ function AlertDescription({ className, children, ...props }) {
1029
+ return jsx("div", {
1030
+ className: cn("snap-alert-description", className),
1031
+ ...props,
1032
+ ...part("alert", "description"),
1033
+ children
1034
+ });
1035
+ }
1036
+ /** A themed rule between sections. */
1037
+ function Separator({ orientation = "horizontal", className, ...props }) {
1038
+ return jsx(SeparatorPrimitive.Root, {
1039
+ orientation,
1040
+ className: cn("snap-separator", className),
1041
+ ...props,
1042
+ ...part("separator", "root")
1043
+ });
1044
+ }
1045
+ /** A neutral loading placeholder shaped by the skin. */
1046
+ function Skeleton({ variant = "block", className, ...props }) {
1047
+ return jsx("div", {
1048
+ className: cn("snap-skeleton", className),
1049
+ "data-variant": variant,
1050
+ "aria-hidden": "true",
1051
+ ...props,
1052
+ ...part("skeleton", "root")
1053
+ });
1054
+ }
1055
+ /** A vertical collection of {@link ListItem} rows. */
1056
+ function List({ divided = false, className, children, ...props }) {
1057
+ return jsx("ul", {
1058
+ className: cn("snap-list", className),
1059
+ "data-divided": divided || void 0,
1060
+ ...props,
1061
+ ...part("list", "root"),
1062
+ children
1063
+ });
1064
+ }
1065
+ /** One list row with leading/trailing slots. */
1066
+ function ListItem({ leading, trailing, selected = false, disabled = false, onClick, className, children, ...props }) {
1067
+ const interactive = onClick !== void 0 && !disabled;
1068
+ const activate = (event) => {
1069
+ if (event.key === "Enter" || event.key === " ") {
1070
+ event.preventDefault();
1071
+ onClick?.();
1072
+ }
1073
+ };
1074
+ return jsxs("li", {
1075
+ className: cn("snap-list-item", className),
1076
+ "data-selected": selected || void 0,
1077
+ "data-interactive": interactive || void 0,
1078
+ "data-disabled": disabled || void 0,
1079
+ "aria-disabled": disabled || void 0,
1080
+ ...interactive ? {
1081
+ role: "button",
1082
+ tabIndex: 0,
1083
+ onClick,
1084
+ onKeyDown: activate
1085
+ } : {},
1086
+ ...props,
1087
+ ...part("list", "item"),
1088
+ children: [
1089
+ leading !== void 0 && jsx("span", {
1090
+ ...part("list", "leading"),
1091
+ children: leading
1092
+ }),
1093
+ jsx("span", {
1094
+ ...part("list", "content"),
1095
+ style: {
1096
+ flex: 1,
1097
+ minWidth: 0
1098
+ },
1099
+ children
1100
+ }),
1101
+ trailing !== void 0 && jsx("span", {
1102
+ ...part("list", "trailing"),
1103
+ children: trailing
1104
+ })
1105
+ ]
1106
+ });
1107
+ }
1108
+ //#endregion
35
1109
  //#region lib/types/components/button.js
36
1110
  /**
37
1111
  * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
@@ -66,7 +1140,7 @@ function Spinner(props) {
66
1140
  }
67
1141
  /** A themed button; `asChild` composes the behaviour onto a child element. */
68
1142
  function Button({ intent = "neutral", emphasis = "solid", size = "md", loading = false, icon, iconPosition = "start", asChild = false, disabled, className, children, type, ...props }) {
69
- const Component = asChild ? Slot : "button";
1143
+ const Component = asChild ? Slot$1 : "button";
70
1144
  const content = asChild ? children : jsxs(Fragment, { children: [
71
1145
  icon !== void 0 && iconPosition === "start" && jsx("span", {
72
1146
  ...part("button", "icon"),
@@ -83,7 +1157,6 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
83
1157
  loading && jsx(Spinner, {})
84
1158
  ] });
85
1159
  return jsx(Component, {
86
- ...part("button", "root"),
87
1160
  ...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
88
1161
  className: cn("snap-button", className),
89
1162
  "data-intent": intent,
@@ -94,13 +1167,13 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
94
1167
  "aria-busy": loading || void 0,
95
1168
  disabled: !asChild ? disabled === true || loading : void 0,
96
1169
  ...props,
1170
+ ...part("button", "root"),
97
1171
  children: content
98
1172
  });
99
1173
  }
100
1174
  /** A square glyph button with a mandatory accessible label. */
101
1175
  function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
102
1176
  return jsx("button", {
103
- ...part("icon-button", "root"),
104
1177
  type: "button",
105
1178
  className: cn("snap-icon-button", className),
106
1179
  "data-intent": intent,
@@ -110,6 +1183,7 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
110
1183
  "aria-label": label,
111
1184
  "aria-pressed": active || void 0,
112
1185
  ...props,
1186
+ ...part("icon-button", "root"),
113
1187
  children: jsx("span", {
114
1188
  ...part("icon-button", "icon"),
115
1189
  "aria-hidden": "true",
@@ -118,138 +1192,17 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
118
1192
  });
119
1193
  }
120
1194
  //#endregion
121
- //#region lib/types/components/dialog.js
1195
+ //#region lib/types/components/input.js
122
1196
  /**
123
- * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
124
- * the presentation (modal, sheet, fullscreen) through the `presentation`
125
- * attribute; the core owns dismissal and focus behaviour.
1197
+ * Text-entry semantics: the wrapper owns the anatomy (prefix/suffix/clear),
1198
+ * the native field keeps keyboard and IME behaviour. Skins style the parts.
126
1199
  *
127
- * @module @snap-rail/ui/components/dialog
1200
+ * @module @snap-rail/ui/components/input
128
1201
  */
129
- /** The dialog root. */
130
- const Dialog = DialogPrimitive.Root;
131
- /** The portalled dialog content. */
132
- function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
133
- const resolved = presentation === "auto" ? "modal" : presentation;
134
- return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
135
- ...part("dialog", "overlay"),
136
- className: "snap-dialog-overlay"
137
- }), jsxs(DialogPrimitive.Content, {
138
- ...part("dialog", "panel"),
139
- className: cn("snap-dialog-panel", className),
140
- "data-presentation": resolved,
141
- "data-size": size,
142
- ...rest,
143
- children: [children, showClose && jsx(DialogPrimitive.Close, {
144
- ...part("dialog", "close"),
145
- className: "snap-dialog-close",
146
- "aria-label": "关闭",
147
- children: "×"
148
- })]
149
- })] });
150
- }
151
- /** The dialog header. */
152
- function DialogHeader({ children, className }) {
153
- return jsx("div", {
154
- ...part("dialog", "header"),
155
- className: cn("snap-dialog-header", className),
156
- children
157
- });
158
- }
159
- /** The dialog title. */
160
- function DialogTitle({ children, className }) {
161
- return jsx(DialogPrimitive.Title, {
162
- ...part("dialog", "title"),
163
- className: cn("snap-dialog-title", className),
164
- children
165
- });
166
- }
167
- /** The dialog description. */
168
- function DialogDescription({ children, className }) {
169
- return jsx(DialogPrimitive.Description, {
170
- ...part("dialog", "description"),
171
- className: cn("snap-dialog-description", className),
172
- children
173
- });
174
- }
175
- /** The dialog body. */
176
- function DialogBody({ children, className }) {
177
- return jsx("div", {
178
- ...part("dialog", "body"),
179
- className: cn("snap-dialog-body", className),
180
- children
181
- });
182
- }
183
- /** The dialog footer. */
184
- function DialogFooter({ children, className }) {
185
- return jsx("div", {
186
- ...part("dialog", "footer"),
187
- className: cn("snap-dialog-footer", className),
188
- children
189
- });
190
- }
191
- //#endregion
192
- //#region lib/types/components/controls.js
193
- /** A boolean switch. */
194
- function Switch({ className, label, ...props }) {
195
- return jsxs("label", {
196
- className: "snap-switch-label",
197
- children: [jsx(SwitchPrimitive.Root, {
198
- ...part("switch", "root"),
199
- className: cn("snap-switch", className),
200
- ...props,
201
- children: jsx(SwitchPrimitive.Thumb, {
202
- ...part("switch", "thumb"),
203
- className: "snap-switch-thumb"
204
- })
205
- }), label !== void 0 && jsx("span", {
206
- ...part("switch", "label"),
207
- children: label
208
- })]
209
- });
210
- }
211
- //#endregion
212
- //#region lib/types/components/feedback.js
213
- /** A compact status/count label. */
214
- function Badge({ children, intent = "neutral", className }) {
215
- return jsx("span", {
216
- ...part("badge", "root"),
217
- className: cn("snap-badge", className),
218
- "data-intent": intent,
219
- children
220
- });
221
- }
222
- /** A centered empty/zero-state block. */
223
- function EmptyState({ title, description, icon, action, className }) {
224
- return jsxs("div", {
225
- ...part("empty-state", "root"),
226
- className: cn("snap-empty-state", className),
227
- children: [
228
- icon !== void 0 && jsx("div", {
229
- ...part("empty-state", "icon"),
230
- children: icon
231
- }),
232
- jsx("div", {
233
- ...part("empty-state", "title"),
234
- children: title
235
- }),
236
- description !== void 0 && jsx("div", {
237
- ...part("empty-state", "description"),
238
- children: description
239
- }),
240
- action !== void 0 && jsx("div", {
241
- ...part("empty-state", "action"),
242
- children: action
243
- })
244
- ]
245
- });
246
- }
247
- //#endregion
248
- //#region lib/types/components/input.js
249
1202
  /** A single-line text field with semantic prefix/suffix slots. Layout
250
1203
  * `style`/`className` dress the wrapper — the visible control; the native
251
1204
  * field already stretches inside it. */
252
- function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
1205
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
253
1206
  return jsxs("div", {
254
1207
  ...part(componentName, "root"),
255
1208
  className: cn("snap-input", className),
@@ -263,11 +1216,11 @@ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componen
263
1216
  children: prefix
264
1217
  }),
265
1218
  jsx("input", {
266
- ...part(componentName, "field"),
267
- className: "snap-input-field",
1219
+ className: cn("snap-input-field", fieldClassName),
268
1220
  disabled,
269
1221
  "aria-invalid": invalid || void 0,
270
- ...props
1222
+ ...props,
1223
+ ...part(componentName, "field")
271
1224
  }),
272
1225
  onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
273
1226
  ...part(componentName, "clear"),
@@ -284,145 +1237,2695 @@ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componen
284
1237
  ]
285
1238
  });
286
1239
  }
287
- //#endregion
288
- //#region lib/types/components/layout.js
289
- /** A vertical flow. */
290
- function Stack({ gap = "md", padding, align, className, style, children }) {
1240
+ /** A multi-line text field. Like {@link Input}, layout `style`/`className`
1241
+ * dress the wrapper; the field stretches inside it. */
1242
+ function Textarea({ size = "md", invalid = false, fieldClassName, className, style, disabled, ...props }) {
291
1243
  return jsx("div", {
292
- ...part("stack", "root"),
293
- className: cn("snap-stack", className),
294
- style: {
295
- display: "flex",
296
- flexDirection: "column",
297
- gap: space(gap),
298
- ...padding !== void 0 ? { padding: space(padding) } : {},
299
- ...align !== void 0 ? { alignItems: align } : {},
300
- ...style
301
- },
302
- children
1244
+ ...part("textarea", "root"),
1245
+ className: cn("snap-textarea", className),
1246
+ style,
1247
+ "data-size": size,
1248
+ "data-invalid": invalid || void 0,
1249
+ "data-disabled": disabled === true || void 0,
1250
+ children: jsx("textarea", {
1251
+ className: cn("snap-textarea-field", fieldClassName),
1252
+ disabled,
1253
+ "aria-invalid": invalid || void 0,
1254
+ ...props,
1255
+ ...part("textarea", "field")
1256
+ })
303
1257
  });
304
1258
  }
305
- /** A page body with its own header/actions anatomy. */
306
- function Page({ header, actions, title, titleExtra, description, className, style, children }) {
1259
+ /** A numeric field with touch steppers: `step-up`/`step-down` commit through
1260
+ * the normal `onChange` (a native input event on the field), clamped to
1261
+ * `min`/`max`. */
1262
+ function NumberInput({ min, max, step = 1, size = "md", invalid = false, fieldClassName, className, style, disabled, value, onChange, ...props }) {
1263
+ const fieldRef = useRef(null);
1264
+ const current = typeof value === "number" ? value : void 0;
1265
+ const stepBy = (delta) => {
1266
+ const field = fieldRef.current;
1267
+ if (field === null || disabled === true) return;
1268
+ const parsed = typeof value === "number" ? value : Number(field.value);
1269
+ let next = (Number.isFinite(parsed) ? parsed : min ?? 0) + delta * step;
1270
+ if (min !== void 0 && next < min) next = min;
1271
+ if (max !== void 0 && next > max) next = max;
1272
+ (Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(field, String(next));
1273
+ field.dispatchEvent(new Event("input", { bubbles: true }));
1274
+ };
307
1275
  return jsxs("div", {
308
- ...part("page", "root"),
1276
+ ...part("number-input", "root"),
1277
+ className: cn("snap-input", "snap-number-input", className),
1278
+ style,
1279
+ "data-size": size,
1280
+ "data-invalid": invalid || void 0,
1281
+ "data-disabled": disabled === true || void 0,
1282
+ children: [jsx("input", {
1283
+ ref: fieldRef,
1284
+ className: cn("snap-input-field", fieldClassName),
1285
+ type: "number",
1286
+ inputMode: "decimal",
1287
+ disabled,
1288
+ "aria-invalid": invalid || void 0,
1289
+ value,
1290
+ onChange,
1291
+ ...min !== void 0 ? { min } : {},
1292
+ ...max !== void 0 ? { max } : {},
1293
+ ...step !== void 0 ? { step } : {},
1294
+ ...props,
1295
+ ...part("number-input", "field")
1296
+ }), jsxs("span", {
1297
+ className: "snap-number-input-steps",
1298
+ children: [jsx("button", {
1299
+ ...part("number-input", "step-up"),
1300
+ type: "button",
1301
+ tabIndex: -1,
1302
+ className: "snap-number-input-step",
1303
+ "aria-label": "增大",
1304
+ disabled: disabled === true || current !== void 0 && max !== void 0 && current >= max,
1305
+ onClick: () => stepBy(1),
1306
+ children: "+"
1307
+ }), jsx("button", {
1308
+ ...part("number-input", "step-down"),
1309
+ type: "button",
1310
+ tabIndex: -1,
1311
+ className: "snap-number-input-step",
1312
+ "aria-label": "减小",
1313
+ disabled: disabled === true || current !== void 0 && min !== void 0 && current <= min,
1314
+ onClick: () => stepBy(-1),
1315
+ children: "-"
1316
+ })]
1317
+ })]
1318
+ });
1319
+ }
1320
+ //#endregion
1321
+ //#region lib/types/components/overlay.js
1322
+ /**
1323
+ * Overlay semantics over Radix: tooltips, popovers, dropdown menus, and
1324
+ * toasts. Behaviour/keyboard/focus handling stays here; skins target the
1325
+ * stable parts (`tooltip.*`, `popover.*`, `menu.*`, `toast.*`) and state
1326
+ * attributes. The imperative toast() helper pairs with the <Toaster/> the
1327
+ * runtime mounts in every surface root.
1328
+ *
1329
+ * @module @snap-rail/ui/components/overlay
1330
+ */
1331
+ /** The tooltip root; wraps `TooltipTrigger`/`TooltipContent` and owns delay. */
1332
+ function Tooltip({ delayDuration, ...props }) {
1333
+ return jsx(TooltipPrimitive.Root, {
1334
+ ...props,
1335
+ delayDuration: delayDuration ?? 300
1336
+ });
1337
+ }
1338
+ /** The tooltip provider; the runtime mounts one, pages only need it standalone. */
1339
+ function TooltipProvider(props) {
1340
+ return jsx(TooltipPrimitive.Provider, { ...props });
1341
+ }
1342
+ /** The tooltip trigger; wraps its child and anchors the bubble. */
1343
+ function TooltipTrigger(props) {
1344
+ return jsx(TooltipPrimitive.Trigger, {
1345
+ ...props,
1346
+ ...part("tooltip", "trigger")
1347
+ });
1348
+ }
1349
+ /** The portalled tooltip bubble. */
1350
+ function TooltipContent({ side = "top", sideOffset = 6, className, children, ...props }) {
1351
+ return jsx(TooltipPrimitive.Portal, { children: jsx(TooltipPrimitive.Content, {
1352
+ className: cn("snap-tooltip", className),
1353
+ side,
1354
+ sideOffset,
1355
+ ...props,
1356
+ ...part("tooltip", "content"),
1357
+ children
1358
+ }) });
1359
+ }
1360
+ /** The popover root. */
1361
+ const Popover = PopoverPrimitive.Root;
1362
+ /** The popover trigger; wraps its child and toggles the panel. */
1363
+ function PopoverTrigger(props) {
1364
+ return jsx(PopoverPrimitive.Trigger, {
1365
+ ...props,
1366
+ ...part("popover", "trigger")
1367
+ });
1368
+ }
1369
+ /** An element the panel positions against without toggling it. */
1370
+ const PopoverAnchor = PopoverPrimitive.Anchor;
1371
+ /** Closes the popover from inside the panel. */
1372
+ function PopoverClose(props) {
1373
+ return jsx(PopoverPrimitive.Close, { ...props });
1374
+ }
1375
+ /** Whether the element can hold a text caret (the anchored-combobox opener). */
1376
+ function isEditableElement(element) {
1377
+ if (element === null || !(element instanceof HTMLElement)) return false;
1378
+ return element.tagName === "INPUT" || element.tagName === "TEXTAREA" || element.isContentEditable;
1379
+ }
1380
+ /**
1381
+ * The portalled popover panel, with the two focus dead ends Radix leaves
1382
+ * open in anchored mode: on open, the FocusScope default steals the focus
1383
+ * from the field a combobox is typing into; on close, the default handler
1384
+ * focuses the trigger ref — which is `null` without a `PopoverTrigger`, so
1385
+ * focus strands on `body` and every keystroke dies. The wrapper remembers
1386
+ * the element that opened the panel and returns focus there; when that
1387
+ * element is editable it also keeps the focus in it while the panel is
1388
+ * open. Trigger-mode popovers behave exactly as Radix does (the opener IS
1389
+ * the trigger).
1390
+ */
1391
+ function PopoverContent({ side = "bottom", align = "center", sideOffset = 6, autoFocusOnOpen, className, children, onOpenAutoFocus, onCloseAutoFocus, onInteractOutside, ...props }) {
1392
+ const openerRef = useRef(null);
1393
+ const interactedOutsideRef = useRef(false);
1394
+ const handleOpenAutoFocus = (event) => {
1395
+ openerRef.current = document.activeElement;
1396
+ interactedOutsideRef.current = false;
1397
+ onOpenAutoFocus?.(event);
1398
+ if (event.defaultPrevented) return;
1399
+ if (autoFocusOnOpen === false || autoFocusOnOpen === void 0 && isEditableElement(openerRef.current)) event.preventDefault();
1400
+ };
1401
+ const handleCloseAutoFocus = (event) => {
1402
+ onCloseAutoFocus?.(event);
1403
+ if (event.defaultPrevented) return;
1404
+ if (interactedOutsideRef.current) return;
1405
+ const opener = openerRef.current;
1406
+ if (opener !== null && opener !== document.body && opener.isConnected) {
1407
+ event.preventDefault();
1408
+ opener.focus({ preventScroll: true });
1409
+ }
1410
+ };
1411
+ const handleInteractOutside = (event) => {
1412
+ interactedOutsideRef.current = true;
1413
+ onInteractOutside?.(event);
1414
+ };
1415
+ return jsx(PopoverPrimitive.Portal, { children: jsx(PopoverPrimitive.Content, {
1416
+ className: cn("snap-popover", className),
1417
+ side,
1418
+ align,
1419
+ sideOffset,
1420
+ onOpenAutoFocus: handleOpenAutoFocus,
1421
+ onCloseAutoFocus: handleCloseAutoFocus,
1422
+ onInteractOutside: handleInteractOutside,
1423
+ ...props,
1424
+ ...part("popover", "content"),
1425
+ children
1426
+ }) });
1427
+ }
1428
+ /** The dropdown menu root. */
1429
+ const Menu = DropdownMenuPrimitive.Root;
1430
+ /** The menu trigger; wraps its child and toggles the dropdown. */
1431
+ function MenuTrigger(props) {
1432
+ return jsx(DropdownMenuPrimitive.Trigger, {
1433
+ ...props,
1434
+ ...part("menu", "trigger")
1435
+ });
1436
+ }
1437
+ /** The portalled dropdown list. */
1438
+ function MenuContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
1439
+ return jsx(DropdownMenuPrimitive.Portal, { children: jsx(DropdownMenuPrimitive.Content, {
1440
+ className: cn("snap-menu", className),
1441
+ side,
1442
+ align,
1443
+ sideOffset,
1444
+ ...props,
1445
+ ...part("menu", "content"),
1446
+ children
1447
+ }) });
1448
+ }
1449
+ /** One menu action. */
1450
+ function MenuItem({ className, children, ...props }) {
1451
+ return jsx(DropdownMenuPrimitive.Item, {
1452
+ className: cn("snap-menu-item", className),
1453
+ ...props,
1454
+ ...part("menu", "item"),
1455
+ children
1456
+ });
1457
+ }
1458
+ /** A checkable menu action with an indicator slot. */
1459
+ function MenuCheckboxItem({ className, children, ...props }) {
1460
+ return jsxs(DropdownMenuPrimitive.CheckboxItem, {
1461
+ className: cn("snap-menu-item", className),
1462
+ ...props,
1463
+ ...part("menu", "checkbox-item"),
1464
+ children: [jsx(DropdownMenuPrimitive.ItemIndicator, {
1465
+ ...part("menu", "item-indicator"),
1466
+ className: "snap-menu-indicator",
1467
+ children: "✓"
1468
+ }), children]
1469
+ });
1470
+ }
1471
+ /** A non-interactive group heading. */
1472
+ function MenuLabel({ className, children, ...props }) {
1473
+ return jsx(DropdownMenuPrimitive.Label, {
1474
+ className: cn("snap-menu-label", className),
1475
+ ...props,
1476
+ ...part("menu", "label"),
1477
+ children
1478
+ });
1479
+ }
1480
+ /** A group container for items. */
1481
+ function MenuGroup(props) {
1482
+ return jsx(DropdownMenuPrimitive.Group, { ...props });
1483
+ }
1484
+ /** A horizontal rule between menu sections. */
1485
+ function MenuSeparator({ className, ...props }) {
1486
+ return jsx(DropdownMenuPrimitive.Separator, {
1487
+ className: cn("snap-menu-separator", className),
1488
+ ...props,
1489
+ ...part("menu", "separator")
1490
+ });
1491
+ }
1492
+ let toastNextId = 1;
1493
+ let toastRecords = [];
1494
+ const toastListeners = /* @__PURE__ */ new Set();
1495
+ function toastEmit() {
1496
+ for (const listener of toastListeners) listener();
1497
+ }
1498
+ function toastDismiss(id) {
1499
+ toastRecords = toastRecords.filter((record) => record.id !== id);
1500
+ toastEmit();
1501
+ }
1502
+ /** Enqueue a toast on the runtime-mounted {@link Toaster}s. */
1503
+ function toast(entry) {
1504
+ const id = toastNextId++;
1505
+ toastRecords = [...toastRecords, {
1506
+ ...entry,
1507
+ id
1508
+ }];
1509
+ toastEmit();
1510
+ return id;
1511
+ }
1512
+ /** Dismiss a queued toast by id. */
1513
+ function dismissToast(id) {
1514
+ toastDismiss(id);
1515
+ }
1516
+ /** The runtime-mounted viewport: renders the shared toast queue. Pages never
1517
+ * mount this themselves — the runtime provides one per surface root. */
1518
+ function Toaster(props) {
1519
+ const records = useSyncExternalStore((onStoreChange) => {
1520
+ toastListeners.add(onStoreChange);
1521
+ return () => toastListeners.delete(onStoreChange);
1522
+ }, () => toastRecords, () => toastRecords);
1523
+ return jsxs(ToastPrimitive.Provider, {
1524
+ ...props,
1525
+ children: [records.map((record) => jsxs(ToastPrimitive.Root, {
1526
+ ...part("toast", "root"),
1527
+ className: "snap-toast",
1528
+ "data-intent": record.intent ?? "neutral",
1529
+ duration: record.duration ?? 5e3,
1530
+ onOpenChange: (open) => {
1531
+ if (!open) toastDismiss(record.id);
1532
+ },
1533
+ children: [
1534
+ jsx(ToastTitle, { children: record.title }),
1535
+ record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
1536
+ jsx(ToastClose, { "aria-label": "关闭" })
1537
+ ]
1538
+ }, record.id)), jsx(ToastViewport, {})]
1539
+ });
1540
+ }
1541
+ /** The raw toast root for pages that manage their own open state. */
1542
+ const Toast = ToastPrimitive.Root;
1543
+ /** A toast title with its part tag. */
1544
+ function ToastTitle({ className, children, ...props }) {
1545
+ return jsx(ToastPrimitive.Title, {
1546
+ className: cn("snap-toast-title", className),
1547
+ ...props,
1548
+ ...part("toast", "title"),
1549
+ children
1550
+ });
1551
+ }
1552
+ /** A toast description with its part tag. */
1553
+ function ToastDescription({ className, children, ...props }) {
1554
+ return jsx(ToastPrimitive.Description, {
1555
+ className: cn("snap-toast-description", className),
1556
+ ...props,
1557
+ ...part("toast", "description"),
1558
+ children
1559
+ });
1560
+ }
1561
+ /** An interactive toast action (confirm/retry affordances). */
1562
+ function ToastAction({ className, children, ...props }) {
1563
+ return jsx(ToastPrimitive.Action, {
1564
+ className: cn("snap-toast-action", className),
1565
+ ...props,
1566
+ ...part("toast", "action"),
1567
+ children
1568
+ });
1569
+ }
1570
+ /** A toast dismissal button. */
1571
+ function ToastClose({ className, children, ...props }) {
1572
+ return jsx(ToastPrimitive.Close, {
1573
+ className: cn("snap-toast-close", className),
1574
+ ...props,
1575
+ ...part("toast", "close"),
1576
+ children: children ?? jsx("span", {
1577
+ "aria-hidden": "true",
1578
+ children: "×"
1579
+ })
1580
+ });
1581
+ }
1582
+ /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
1583
+ function ToastViewport({ className, ...props }) {
1584
+ return jsx(ToastPrimitive.Viewport, {
1585
+ className: cn("snap-toast-viewport", className),
1586
+ ...props,
1587
+ ...part("toast", "viewport")
1588
+ });
1589
+ }
1590
+ //#endregion
1591
+ //#region lib/types/components/combobox.js
1592
+ /**
1593
+ * A text field with an anchored suggestion list: search pickers, filtered
1594
+ * choosers, async candidate feeds (operator lookups, assignee search). The
1595
+ * focus never leaves the field — keyboard navigation rides
1596
+ * `aria-activedescendant`, pointer picks suppress the field's blur, and the
1597
+ * panel opens without taking the focus — so typing keeps working through
1598
+ * open, navigate, and select. The field is a regular {@link Input}; skins
1599
+ * style the `combobox.*` parts around it.
1600
+ *
1601
+ * @module @snap-rail/ui/components/combobox
1602
+ */
1603
+ /** The text an option contributes to filtering and to the field once picked. */
1604
+ function textOf(option) {
1605
+ return typeof option.label === "string" || typeof option.label === "number" ? String(option.label) : option.value;
1606
+ }
1607
+ /** The next enabled row index from `from`, wrapping; -1 when none is enabled. */
1608
+ function nextEnabled(rows, from, step) {
1609
+ if (rows.length === 0) return -1;
1610
+ let index = from < 0 ? step > 0 ? -1 : 0 : from;
1611
+ for (let tries = 0; tries < rows.length; tries++) {
1612
+ index = (index + step + rows.length) % rows.length;
1613
+ if (rows[index]?.disabled !== true) return index;
1614
+ }
1615
+ return -1;
1616
+ }
1617
+ /** A field with an anchored, keyboard-navigable suggestion list. */
1618
+ function Combobox({ value, defaultValue, onValueChange, onInputValueChange, options, placeholder, disabled = false, invalid = false, size = "md", loading = false, emptyText = "无匹配项", id, className, contentClassName, "aria-label": ariaLabel }) {
1619
+ const listId = useId();
1620
+ const anchorRef = useRef(null);
1621
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
1622
+ const current = value !== void 0 ? value : uncontrolled;
1623
+ const selected = options.find((option) => option.value === current);
1624
+ const selectedText = selected !== void 0 ? textOf(selected) : void 0;
1625
+ const [text, setText] = useState(selectedText ?? "");
1626
+ const [open, setOpen] = useState(false);
1627
+ const [active, setActive] = useState(-1);
1628
+ useEffect(() => {
1629
+ if (selectedText !== void 0) setText(selectedText);
1630
+ }, [selectedText]);
1631
+ const query = text.trim().toLowerCase();
1632
+ const rows = onInputValueChange !== void 0 || query === "" || text === selectedText ? options : options.filter((option) => textOf(option).toLowerCase().includes(query));
1633
+ const optionId = (index) => `${listId}-${index}`;
1634
+ useEffect(() => {
1635
+ if (active < 0) return;
1636
+ document.getElementById(optionId(active))?.scrollIntoView?.({ block: "nearest" });
1637
+ });
1638
+ const close = () => {
1639
+ setOpen(false);
1640
+ setActive(-1);
1641
+ };
1642
+ const choose = (option) => {
1643
+ if (option.disabled === true) return;
1644
+ if (value === void 0) setUncontrolled(option.value);
1645
+ setText(textOf(option));
1646
+ onValueChange?.(option.value);
1647
+ close();
1648
+ };
1649
+ const onKeyDown = (event) => {
1650
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1651
+ event.preventDefault();
1652
+ if (!open) {
1653
+ setOpen(true);
1654
+ return;
1655
+ }
1656
+ setActive((index) => nextEnabled(rows, index, event.key === "ArrowDown" ? 1 : -1));
1657
+ return;
1658
+ }
1659
+ if (event.key === "Enter" && open && active >= 0) {
1660
+ const option = rows[active];
1661
+ if (option !== void 0) {
1662
+ event.preventDefault();
1663
+ choose(option);
1664
+ }
1665
+ return;
1666
+ }
1667
+ if (event.key === "Escape" && open) {
1668
+ event.preventDefault();
1669
+ close();
1670
+ }
1671
+ };
1672
+ return jsx("span", {
1673
+ ...part("combobox", "root"),
1674
+ className: "snap-combobox",
1675
+ children: jsxs(Popover, {
1676
+ open: open && !disabled,
1677
+ onOpenChange: (next) => {
1678
+ if (!next) close();
1679
+ },
1680
+ children: [jsx(PopoverAnchor, {
1681
+ asChild: true,
1682
+ children: jsx("span", {
1683
+ ref: anchorRef,
1684
+ ...part("combobox", "anchor"),
1685
+ children: jsx(Input, {
1686
+ id,
1687
+ size,
1688
+ invalid,
1689
+ disabled,
1690
+ placeholder,
1691
+ className,
1692
+ value: text,
1693
+ role: "combobox",
1694
+ autoComplete: "off",
1695
+ "aria-label": ariaLabel,
1696
+ "aria-expanded": open,
1697
+ "aria-controls": listId,
1698
+ "aria-autocomplete": "list",
1699
+ "aria-activedescendant": open && active >= 0 ? optionId(active) : void 0,
1700
+ onChange: (event) => {
1701
+ setText(event.target.value);
1702
+ setActive(-1);
1703
+ setOpen(true);
1704
+ onInputValueChange?.(event.target.value);
1705
+ },
1706
+ onFocus: () => setOpen(true),
1707
+ onBlur: close,
1708
+ onKeyDown
1709
+ })
1710
+ })
1711
+ }), jsx(PopoverContent, {
1712
+ align: "start",
1713
+ sideOffset: 4,
1714
+ autoFocusOnOpen: false,
1715
+ className: contentClassName,
1716
+ onInteractOutside: (event) => {
1717
+ if (anchorRef.current?.contains(event.target) === true) event.preventDefault();
1718
+ },
1719
+ children: jsxs("div", {
1720
+ ...part("combobox", "list"),
1721
+ role: "listbox",
1722
+ id: listId,
1723
+ children: [
1724
+ rows.map((option, index) => jsx("div", {
1725
+ ...part("combobox", "option"),
1726
+ id: optionId(index),
1727
+ role: "option",
1728
+ "aria-selected": option.value === current,
1729
+ "aria-disabled": option.disabled === true || void 0,
1730
+ "data-active": index === active || void 0,
1731
+ "data-disabled": option.disabled === true || void 0,
1732
+ onMouseDown: (event) => event.preventDefault(),
1733
+ onClick: () => choose(option),
1734
+ children: option.label
1735
+ }, option.value)),
1736
+ loading && jsx("div", {
1737
+ ...part("combobox", "empty"),
1738
+ children: "搜索中…"
1739
+ }),
1740
+ !loading && rows.length === 0 && jsx("div", {
1741
+ ...part("combobox", "empty"),
1742
+ children: emptyText
1743
+ })
1744
+ ]
1745
+ })
1746
+ })]
1747
+ })
1748
+ });
1749
+ }
1750
+ //#endregion
1751
+ //#region lib/types/components/dialog.js
1752
+ /**
1753
+ * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
1754
+ * the presentation (modal, sheet, fullscreen) through the `presentation`
1755
+ * attribute; the core owns dismissal and focus behaviour.
1756
+ *
1757
+ * @module @snap-rail/ui/components/dialog
1758
+ */
1759
+ /** The dialog root. */
1760
+ const Dialog = DialogPrimitive.Root;
1761
+ /** The dialog trigger. */
1762
+ const DialogTrigger = DialogPrimitive.Trigger;
1763
+ /** The dialog close. */
1764
+ const DialogClose = DialogPrimitive.Close;
1765
+ /** The portalled dialog content. */
1766
+ function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
1767
+ const resolved = presentation === "auto" ? "modal" : presentation;
1768
+ return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
1769
+ ...part("dialog", "overlay"),
1770
+ className: "snap-dialog-overlay"
1771
+ }), jsxs(DialogPrimitive.Content, {
1772
+ className: cn("snap-dialog-panel", className),
1773
+ "data-presentation": resolved,
1774
+ "data-size": size,
1775
+ ...rest,
1776
+ ...part("dialog", "panel"),
1777
+ children: [children, showClose && jsx(DialogPrimitive.Close, {
1778
+ ...part("dialog", "close"),
1779
+ className: "snap-dialog-close",
1780
+ "aria-label": "关闭",
1781
+ children: "×"
1782
+ })]
1783
+ })] });
1784
+ }
1785
+ /** The dialog header. */
1786
+ function DialogHeader({ children, className }) {
1787
+ return jsx("div", {
1788
+ ...part("dialog", "header"),
1789
+ className: cn("snap-dialog-header", className),
1790
+ children
1791
+ });
1792
+ }
1793
+ /** The dialog title. */
1794
+ function DialogTitle({ children, className }) {
1795
+ return jsx(DialogPrimitive.Title, {
1796
+ ...part("dialog", "title"),
1797
+ className: cn("snap-dialog-title", className),
1798
+ children
1799
+ });
1800
+ }
1801
+ /** The dialog description. */
1802
+ function DialogDescription({ children, className }) {
1803
+ return jsx(DialogPrimitive.Description, {
1804
+ ...part("dialog", "description"),
1805
+ className: cn("snap-dialog-description", className),
1806
+ children
1807
+ });
1808
+ }
1809
+ /** The dialog body. */
1810
+ function DialogBody({ children, className }) {
1811
+ return jsx("div", {
1812
+ ...part("dialog", "body"),
1813
+ className: cn("snap-dialog-body", className),
1814
+ children
1815
+ });
1816
+ }
1817
+ /** The dialog footer. */
1818
+ function DialogFooter({ children, className }) {
1819
+ return jsx("div", {
1820
+ ...part("dialog", "footer"),
1821
+ className: cn("snap-dialog-footer", className),
1822
+ children
1823
+ });
1824
+ }
1825
+ /** A sheet is a dialog with the `sheet` presentation by default. */
1826
+ function Sheet(props) {
1827
+ return jsx(DialogContent, {
1828
+ ...props,
1829
+ presentation: props.presentation ?? "sheet"
1830
+ });
1831
+ }
1832
+ //#endregion
1833
+ //#region lib/types/components/controls.js
1834
+ /**
1835
+ * Selection and toggle semantics over Radix: tabs, select, switch, checkbox,
1836
+ * and radio groups. All behaviour/keyboard handling stays here; skins target
1837
+ * the stable parts and state attributes.
1838
+ *
1839
+ * @module @snap-rail/ui/components/controls
1840
+ */
1841
+ /** A form label. */
1842
+ function Label({ className, children, ...props }) {
1843
+ return jsx(LabelPrimitive.Root, {
1844
+ className: cn("snap-label", className),
1845
+ ...props,
1846
+ children
1847
+ });
1848
+ }
1849
+ /** The tabs root. */
1850
+ function Tabs({ className, children, ...props }) {
1851
+ return jsx(TabsPrimitive.Root, {
1852
+ className: cn("snap-tabs", className),
1853
+ ...props,
1854
+ ...part("tabs", "root"),
1855
+ children
1856
+ });
1857
+ }
1858
+ /** The tabs list. */
1859
+ function TabsList({ className, children, ...props }) {
1860
+ return jsx(TabsPrimitive.List, {
1861
+ className: cn("snap-tabs-list", className),
1862
+ ...props,
1863
+ ...part("tabs", "list"),
1864
+ children
1865
+ });
1866
+ }
1867
+ /** A tab trigger. */
1868
+ function TabsTrigger({ className, children, ...props }) {
1869
+ return jsx(TabsPrimitive.Trigger, {
1870
+ className: cn("snap-tabs-trigger", className),
1871
+ ...props,
1872
+ ...part("tabs", "trigger"),
1873
+ children
1874
+ });
1875
+ }
1876
+ /** A tab panel. */
1877
+ function TabsContent({ className, children, ...props }) {
1878
+ return jsx(TabsPrimitive.Content, {
1879
+ className: cn("snap-tabs-content", className),
1880
+ ...props,
1881
+ ...part("tabs", "content"),
1882
+ children
1883
+ });
1884
+ }
1885
+ /** A boolean switch with an optional label on either side. */
1886
+ function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
1887
+ const labelNode = label !== void 0 && jsx("span", {
1888
+ ...part("switch", "label"),
1889
+ children: label
1890
+ });
1891
+ const row = jsxs("label", {
1892
+ className: "snap-switch-label",
1893
+ children: [
1894
+ labelPosition === "start" && labelNode,
1895
+ jsx(SwitchPrimitive.Root, {
1896
+ className: cn("snap-switch", className),
1897
+ ...props,
1898
+ ...part("switch", "root"),
1899
+ children: jsx(SwitchPrimitive.Thumb, {
1900
+ ...part("switch", "thumb"),
1901
+ className: "snap-switch-thumb"
1902
+ })
1903
+ }),
1904
+ labelPosition === "end" && labelNode
1905
+ ]
1906
+ });
1907
+ if (description === void 0) return row;
1908
+ return jsxs("span", {
1909
+ ...part("switch", "field"),
1910
+ className: cn("snap-switch-field", containerClassName),
1911
+ children: [row, jsx("span", {
1912
+ ...part("switch", "description"),
1913
+ className: "snap-field-help",
1914
+ children: description
1915
+ })]
1916
+ });
1917
+ }
1918
+ /** A tri-state checkbox with an optional label on either side. */
1919
+ function Checkbox({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
1920
+ const labelNode = label !== void 0 && jsx("span", {
1921
+ ...part("checkbox", "label"),
1922
+ children: label
1923
+ });
1924
+ const row = jsxs("label", {
1925
+ className: "snap-checkbox-label",
1926
+ children: [
1927
+ labelPosition === "start" && labelNode,
1928
+ jsx(CheckboxPrimitive.Root, {
1929
+ className: cn("snap-checkbox", className),
1930
+ ...props,
1931
+ ...part("checkbox", "root"),
1932
+ children: jsx(CheckboxPrimitive.Indicator, {
1933
+ ...part("checkbox", "indicator"),
1934
+ className: "snap-checkbox-indicator",
1935
+ children: "✓"
1936
+ })
1937
+ }),
1938
+ labelPosition === "end" && labelNode
1939
+ ]
1940
+ });
1941
+ if (description === void 0) return row;
1942
+ return jsxs("span", {
1943
+ ...part("checkbox", "field"),
1944
+ className: cn("snap-checkbox-field", containerClassName),
1945
+ children: [row, jsx("span", {
1946
+ ...part("checkbox", "description"),
1947
+ className: "snap-field-help",
1948
+ children: description
1949
+ })]
1950
+ });
1951
+ }
1952
+ /** A labelled group of radio items. */
1953
+ function RadioGroup({ className, label, description, children, ...props }) {
1954
+ const labelId = useId();
1955
+ const group = jsx(RadioGroupPrimitive.Root, {
1956
+ className: cn("snap-radio-group", className),
1957
+ ...label !== void 0 ? { "aria-labelledby": labelId } : {},
1958
+ ...props,
1959
+ ...part("radio-group", "root"),
1960
+ children
1961
+ });
1962
+ if (label === void 0 && description === void 0) return group;
1963
+ return jsxs("div", {
1964
+ ...part("radio-group", "block"),
1965
+ className: "snap-radio-group-block",
1966
+ children: [
1967
+ label !== void 0 && jsx(Label, {
1968
+ id: labelId,
1969
+ ...part("radio-group", "label"),
1970
+ children: label
1971
+ }),
1972
+ group,
1973
+ description !== void 0 && jsx("div", {
1974
+ ...part("radio-group", "description"),
1975
+ className: "snap-field-help",
1976
+ children: description
1977
+ })
1978
+ ]
1979
+ });
1980
+ }
1981
+ /** One radio item. */
1982
+ function RadioGroupItem({ className, ...props }) {
1983
+ return jsx(RadioGroupPrimitive.Item, {
1984
+ className: cn("snap-radio-item", className),
1985
+ ...props,
1986
+ ...part("radio-group", "item"),
1987
+ children: jsx(RadioGroupPrimitive.Indicator, {
1988
+ ...part("radio-group", "indicator"),
1989
+ className: "snap-radio-indicator"
1990
+ })
1991
+ });
1992
+ }
1993
+ /** A modal option list; use on touch terminals in place of the popover select. */
1994
+ function TouchSelect({ value, onValueChange, options, placeholder = "请选择", disabled = false, invalid = false, size = "md", className, "aria-label": ariaLabel, title }) {
1995
+ const [open, setOpen] = useState(false);
1996
+ const selected = options.find((option) => option.value === value);
1997
+ return jsxs("span", {
1998
+ ...part("touch-select", "root"),
1999
+ className: "snap-touch-select",
2000
+ children: [jsx("span", {
2001
+ ...part("touch-select", "trigger"),
2002
+ className: "snap-touch-select-trigger",
2003
+ children: jsxs(Button, {
2004
+ type: "button",
2005
+ size,
2006
+ emphasis: "outline",
2007
+ className,
2008
+ disabled,
2009
+ "aria-label": ariaLabel,
2010
+ "aria-invalid": invalid || void 0,
2011
+ "aria-haspopup": "dialog",
2012
+ onClick: () => setOpen(true),
2013
+ children: [jsx("span", {
2014
+ style: {
2015
+ flex: 1,
2016
+ textAlign: "left"
2017
+ },
2018
+ children: selected?.label ?? placeholder
2019
+ }), jsx("span", {
2020
+ "aria-hidden": "true",
2021
+ children: "▾"
2022
+ })]
2023
+ })
2024
+ }), jsx(Dialog, {
2025
+ open,
2026
+ onOpenChange: setOpen,
2027
+ children: jsx(DialogContent, {
2028
+ presentation: "modal",
2029
+ size: "sm",
2030
+ children: jsxs("div", {
2031
+ ...part("touch-select", "sheet"),
2032
+ className: "snap-touch-select-sheet",
2033
+ children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: title ?? ariaLabel ?? "请选择" }) }), jsxs("div", {
2034
+ ...part("touch-select", "options"),
2035
+ style: {
2036
+ display: "flex",
2037
+ flexDirection: "column",
2038
+ gap: "var(--snap-space-sm)"
2039
+ },
2040
+ children: [options.map((option) => jsx(Button, {
2041
+ type: "button",
2042
+ size: "lg",
2043
+ emphasis: option.value === value ? "solid" : "outline",
2044
+ intent: option.value === value ? "primary" : "neutral",
2045
+ disabled: option.disabled === true,
2046
+ onClick: () => {
2047
+ onValueChange?.(option.value);
2048
+ setOpen(false);
2049
+ },
2050
+ children: option.label
2051
+ }, option.value)), options.length === 0 && jsx("span", {
2052
+ style: { color: "var(--snap-color-muted)" },
2053
+ children: "无可选项"
2054
+ })]
2055
+ })]
2056
+ })
2057
+ })
2058
+ })]
2059
+ });
2060
+ }
2061
+ /** The select trigger; composes a {@link SelectValue} inside. */
2062
+ function SelectTrigger({ className, size = "md", invalid = false, disabled = false, children, ...props }) {
2063
+ return jsxs(SelectPrimitive.Trigger, {
2064
+ className: cn("snap-select-trigger", className),
2065
+ "data-size": size,
2066
+ "data-invalid": invalid || void 0,
2067
+ "data-disabled": disabled || void 0,
2068
+ "aria-invalid": invalid || void 0,
2069
+ ...props,
2070
+ ...part("select", "trigger"),
2071
+ children: [children, jsx(SelectPrimitive.Icon, {
2072
+ ...part("select", "chevron"),
2073
+ className: "snap-select-chevron",
2074
+ children: "▾"
2075
+ })]
2076
+ });
2077
+ }
2078
+ /** The selected-value slot of a trigger. */
2079
+ function SelectValue(props) {
2080
+ return jsx(SelectPrimitive.Value, {
2081
+ ...props,
2082
+ ...part("select", "value")
2083
+ });
2084
+ }
2085
+ /** The portalled option list. */
2086
+ function SelectContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
2087
+ return jsx(SelectPrimitive.Portal, { children: jsx(SelectPrimitive.Content, {
2088
+ className: cn("snap-select-content", className),
2089
+ position: "popper",
2090
+ side,
2091
+ align,
2092
+ sideOffset,
2093
+ ...props,
2094
+ ...part("select", "content"),
2095
+ children: jsx(SelectPrimitive.Viewport, { children })
2096
+ }) });
2097
+ }
2098
+ /** One option row. */
2099
+ function SelectItem({ className, children, ...props }) {
2100
+ return jsxs(SelectPrimitive.Item, {
2101
+ className: cn("snap-select-item", className),
2102
+ ...props,
2103
+ ...part("select", "item"),
2104
+ children: [jsx(SelectPrimitive.ItemText, { children }), jsx(SelectPrimitive.ItemIndicator, {
2105
+ ...part("select", "item-indicator"),
2106
+ className: "snap-select-item-indicator",
2107
+ children: "✓"
2108
+ })]
2109
+ });
2110
+ }
2111
+ /** A labelled group of options. */
2112
+ function SelectGroup(props) {
2113
+ return jsx(SelectPrimitive.Group, { ...props });
2114
+ }
2115
+ /** A group heading. */
2116
+ function SelectLabel({ className, ...props }) {
2117
+ return jsx(SelectPrimitive.Label, {
2118
+ className: cn("snap-select-label", className),
2119
+ ...props
2120
+ });
2121
+ }
2122
+ /** A popover select: data-driven via `options`, or composed from
2123
+ * {@link SelectItem} children for full layout control. */
2124
+ 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 }) {
2125
+ const composite = children !== void 0;
2126
+ const empty = !composite && (options ?? []).length === 0;
2127
+ return jsx("span", {
2128
+ ...part("select", "root"),
2129
+ className: "snap-select",
2130
+ children: jsxs(SelectPrimitive.Root, {
2131
+ ...value !== void 0 ? { value } : {},
2132
+ ...defaultValue !== void 0 ? { defaultValue } : {},
2133
+ ...onValueChange !== void 0 ? { onValueChange } : {},
2134
+ disabled,
2135
+ ...name !== void 0 ? { name } : {},
2136
+ ...required !== void 0 ? { required } : {},
2137
+ children: [jsx(SelectTrigger, {
2138
+ id,
2139
+ size,
2140
+ invalid,
2141
+ disabled,
2142
+ className,
2143
+ "aria-label": ariaLabel,
2144
+ children: jsx(SelectValue, { placeholder })
2145
+ }), jsxs(SelectContent, {
2146
+ side,
2147
+ align,
2148
+ sideOffset,
2149
+ className: contentClassName,
2150
+ children: [composite ? children : (options ?? []).map((option) => jsx(SelectItem, {
2151
+ value: option.value,
2152
+ disabled: option.disabled === true,
2153
+ children: option.label
2154
+ }, option.value)), empty && jsx("div", {
2155
+ ...part("select", "empty"),
2156
+ className: "snap-select-empty",
2157
+ children: "无可选项"
2158
+ })]
2159
+ })]
2160
+ })
2161
+ });
2162
+ }
2163
+ //#endregion
2164
+ //#region lib/types/components/feedback.js
2165
+ /** A compact status/count label. */
2166
+ function Badge({ children, intent = "neutral", className }) {
2167
+ return jsx("span", {
2168
+ ...part("badge", "root"),
2169
+ className: cn("snap-badge", className),
2170
+ "data-intent": intent,
2171
+ children
2172
+ });
2173
+ }
2174
+ /** A status light with a separate halo part for breathing/glow skins. */
2175
+ function Led({ tone = "neutral", label, className }) {
2176
+ return jsx("span", {
2177
+ ...part("led", "root"),
2178
+ className: cn("snap-led", className),
2179
+ "data-tone": tone,
2180
+ "aria-label": label,
2181
+ role: label !== void 0 ? "img" : void 0,
2182
+ children: jsx("span", {
2183
+ ...part("led", "halo"),
2184
+ "aria-hidden": "true"
2185
+ })
2186
+ });
2187
+ }
2188
+ /** A linear progress indicator. */
2189
+ function Progress({ value, label, className }) {
2190
+ const clamped = value === null ? null : Math.min(1, Math.max(0, value));
2191
+ return jsx("div", {
2192
+ ...part("progress", "root"),
2193
+ className: cn("snap-progress", className),
2194
+ role: "progressbar",
2195
+ "aria-label": label,
2196
+ "aria-valuemin": 0,
2197
+ "aria-valuemax": 100,
2198
+ ...clamped !== null ? { "aria-valuenow": Math.round(clamped * 100) } : {},
2199
+ "data-indeterminate": clamped === null || void 0,
2200
+ children: jsx("div", {
2201
+ ...part("progress", "track"),
2202
+ className: "snap-progress-track",
2203
+ children: jsx("div", {
2204
+ ...part("progress", "indicator"),
2205
+ className: "snap-progress-indicator",
2206
+ style: clamped === null ? void 0 : { width: `${Math.round(clamped * 100)}%` }
2207
+ })
2208
+ })
2209
+ });
2210
+ }
2211
+ /** A centered empty/zero-state block. */
2212
+ function EmptyState({ title, description, icon, action, className }) {
2213
+ return jsxs("div", {
2214
+ ...part("empty-state", "root"),
2215
+ className: cn("snap-empty-state", className),
2216
+ children: [
2217
+ icon !== void 0 && jsx("div", {
2218
+ ...part("empty-state", "icon"),
2219
+ children: icon
2220
+ }),
2221
+ jsx("div", {
2222
+ ...part("empty-state", "title"),
2223
+ children: title
2224
+ }),
2225
+ description !== void 0 && jsx("div", {
2226
+ ...part("empty-state", "description"),
2227
+ children: description
2228
+ }),
2229
+ action !== void 0 && jsx("div", {
2230
+ ...part("empty-state", "action"),
2231
+ children: action
2232
+ })
2233
+ ]
2234
+ });
2235
+ }
2236
+ //#endregion
2237
+ //#region lib/types/components/form.js
2238
+ /** A labelled form row. */
2239
+ function Field({ label, htmlFor, help, error, invalid = false, required = false, orientation = "vertical", labelWidth, labelAlign = "start", children, className, style }) {
2240
+ const bad = invalid || error !== void 0;
2241
+ return jsxs("div", {
2242
+ ...part("field", "root"),
2243
+ className: cn("snap-field", className),
2244
+ "data-invalid": bad || void 0,
2245
+ "data-required": required || void 0,
2246
+ "data-orientation": orientation,
2247
+ style,
2248
+ children: [
2249
+ label !== void 0 && jsxs(Label, {
2250
+ ...htmlFor !== void 0 ? { htmlFor } : {},
2251
+ ...part("field", "label"),
2252
+ style: {
2253
+ ...labelWidth !== void 0 ? {
2254
+ width: typeof labelWidth === "number" ? `${labelWidth}px` : labelWidth,
2255
+ flexShrink: 0
2256
+ } : {},
2257
+ ...labelAlign !== "start" ? { textAlign: labelAlign } : {}
2258
+ },
2259
+ children: [label, required && jsx("span", {
2260
+ "aria-hidden": "true",
2261
+ children: " *"
2262
+ })]
2263
+ }),
2264
+ jsx("div", {
2265
+ ...part("field", "control"),
2266
+ children
2267
+ }),
2268
+ help !== void 0 && error === void 0 && jsx("div", {
2269
+ ...part("field", "help"),
2270
+ className: "snap-field-help",
2271
+ children: help
2272
+ }),
2273
+ error !== void 0 && jsx("div", {
2274
+ ...part("field", "error"),
2275
+ className: "snap-field-error",
2276
+ role: "alert",
2277
+ children: error
2278
+ })
2279
+ ]
2280
+ });
2281
+ }
2282
+ /** A form with a fields region and an actions region. */
2283
+ function Form({ children, actions, onSubmit, className, orientation = "stack", gap = "md", columns = 2, form, onValid, onInvalid }) {
2284
+ const fieldsStyle = orientation === "grid" ? {
2285
+ display: "grid",
2286
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
2287
+ gap: space(gap)
2288
+ } : orientation === "inline" ? {
2289
+ display: "flex",
2290
+ flexDirection: "row",
2291
+ flexWrap: "wrap",
2292
+ gap: space(gap)
2293
+ } : {
2294
+ display: "flex",
2295
+ flexDirection: "column",
2296
+ gap: space(gap)
2297
+ };
2298
+ const body = jsxs(Fragment, { children: [jsx("div", {
2299
+ ...part("form", "fields"),
2300
+ className: "snap-form-fields",
2301
+ style: fieldsStyle,
2302
+ children
2303
+ }), actions !== void 0 && jsx("div", {
2304
+ ...part("form", "actions"),
2305
+ className: "snap-form-actions",
2306
+ children: actions
2307
+ })] });
2308
+ const submit = form !== void 0 && onValid !== void 0 ? form.handleSubmit(onValid, onInvalid) : onSubmit;
2309
+ if (form === void 0) return jsx("form", {
2310
+ ...part("form", "root"),
2311
+ className: cn("snap-form", className),
2312
+ "data-orientation": orientation,
2313
+ onSubmit: submit,
2314
+ children: body
2315
+ });
2316
+ return jsx(FormProvider$1, {
2317
+ ...form,
2318
+ children: jsx("form", {
2319
+ ...part("form", "root"),
2320
+ className: cn("snap-form", className),
2321
+ "data-orientation": orientation,
2322
+ onSubmit: submit,
2323
+ children: body
2324
+ })
2325
+ });
2326
+ }
2327
+ //#endregion
2328
+ //#region lib/types/components/form-rhf.js
2329
+ /**
2330
+ * React Hook Form integration in the shadcn composite shape: `FormField`
2331
+ * binds a controller, `FormItem`/`FormLabel`/`FormControl`/
2332
+ * `FormDescription`/`FormMessage` render the same `field.*` anatomy the plain
2333
+ * {@link Field} uses, driven by the form state. The RHF hooks and
2334
+ * `zodResolver` are re-exported so plugin bundles consume the seed's single
2335
+ * module instance — RHF context is module-scoped, and a copy bundled inside a
2336
+ * plugin zip would never see the form state.
2337
+ *
2338
+ * @module @snap-rail/ui/components/form-rhf
2339
+ */
2340
+ const FormFieldContext = createContext(null);
2341
+ const FormItemContext = createContext(null);
2342
+ /** Read the enclosing field binding; fails loud outside a {@link FormField}. */
2343
+ function useFormField() {
2344
+ const field = useContext(FormFieldContext);
2345
+ const item = useContext(FormItemContext);
2346
+ if (field === null || item === null) throw new Error("表单字段部件必须渲染在 FormField 内");
2347
+ return {
2348
+ id: item.id,
2349
+ name: field.name
2350
+ };
2351
+ }
2352
+ /** Bind a controller and expose its name to the anatomy parts inside. */
2353
+ function FormField(props) {
2354
+ const name = props.name;
2355
+ return jsx(FormFieldContext.Provider, {
2356
+ value: { name },
2357
+ children: jsx(Controller$1, {
2358
+ ...props,
2359
+ name,
2360
+ render: props.render
2361
+ })
2362
+ });
2363
+ }
2364
+ /** The field row: owns the shared id every aria attribute anchors to. */
2365
+ function FormItem({ children, className, orientation = "vertical" }) {
2366
+ const id = useId();
2367
+ return jsx(FormItemContext.Provider, {
2368
+ value: { id },
2369
+ children: jsx("div", {
2370
+ ...part("field", "root"),
2371
+ className: cn("snap-field", className),
2372
+ "data-orientation": orientation,
2373
+ children
2374
+ })
2375
+ });
2376
+ }
2377
+ /** The field label; carries `data-invalid` when the field has an error. */
2378
+ function FormLabel({ className, children }) {
2379
+ const { id, name } = useFormField();
2380
+ const invalid = useFormState$1({ name }).errors[name] !== void 0;
2381
+ return jsx(Label, {
2382
+ htmlFor: id,
2383
+ ...part("field", "label"),
2384
+ className: cn("snap-form-label", className),
2385
+ "data-invalid": invalid || void 0,
2386
+ children
2387
+ });
2388
+ }
2389
+ /** Merges the field binding onto the single control child it wraps. */
2390
+ function FormControl({ children }) {
2391
+ const { id, name } = useFormField();
2392
+ const invalid = useFormState$1({ name }).errors[name] !== void 0;
2393
+ return jsx(Slot$1, {
2394
+ id,
2395
+ "aria-invalid": invalid || void 0,
2396
+ "aria-describedby": `${id}-description ${id}-message`,
2397
+ children
2398
+ });
2399
+ }
2400
+ /** Helper text under the control; linked as `aria-describedby`. */
2401
+ function FormDescription({ className, children }) {
2402
+ const { id } = useFormField();
2403
+ return jsx("div", {
2404
+ ...part("field", "help"),
2405
+ id: `${id}-description`,
2406
+ className: cn("snap-field-help", className),
2407
+ children
2408
+ });
2409
+ }
2410
+ /** The validation message for the bound field. */
2411
+ function FormMessage({ message, children, className }) {
2412
+ const { id, name } = useFormField();
2413
+ const raw = useFormState$1({ name }).errors[name]?.message;
2414
+ const body = message ?? (typeof raw === "string" || typeof raw === "number" || typeof raw === "bigint" || typeof raw === "boolean" ? String(raw) : void 0) ?? children;
2415
+ if (body === void 0 || body === "") return null;
2416
+ return jsx("div", {
2417
+ ...part("field", "error"),
2418
+ id: `${id}-message`,
2419
+ className: cn("snap-field-error", className),
2420
+ role: "alert",
2421
+ children: body
2422
+ });
2423
+ }
2424
+ //#endregion
2425
+ //#region lib/types/components/layout.js
2426
+ /**
2427
+ * Semantic layout primitives. Pages compose these instead of raw flex/grid
2428
+ * utility classes; the structural rules are inline (so layout survives
2429
+ * without a skin) while spacing/density values ride skin tokens.
2430
+ *
2431
+ * @module @snap-rail/ui/components/layout
2432
+ */
2433
+ /** A vertical flow. */
2434
+ function Stack({ gap = "md", padding, align, className, style, children }) {
2435
+ return jsx("div", {
2436
+ ...part("stack", "root"),
2437
+ className: cn("snap-stack", className),
2438
+ style: {
2439
+ display: "flex",
2440
+ flexDirection: "column",
2441
+ gap: space(gap),
2442
+ ...padding !== void 0 ? { padding: space(padding) } : {},
2443
+ ...align !== void 0 ? { alignItems: align } : {},
2444
+ ...style
2445
+ },
2446
+ children
2447
+ });
2448
+ }
2449
+ /** A horizontal flow. */
2450
+ function Row({ gap = "sm", padding, align, justify, wrap = false, className, style, children }) {
2451
+ return jsx("div", {
2452
+ ...part("row", "root"),
2453
+ className: cn("snap-row", className),
2454
+ style: {
2455
+ display: "flex",
2456
+ flexDirection: "row",
2457
+ gap: space(gap),
2458
+ ...padding !== void 0 ? { padding: space(padding) } : {},
2459
+ ...align !== void 0 ? { alignItems: align } : {},
2460
+ ...justify !== void 0 ? { justifyContent: justify } : {},
2461
+ ...wrap ? { flexWrap: "wrap" } : {},
2462
+ ...style
2463
+ },
2464
+ children
2465
+ });
2466
+ }
2467
+ /** A responsive grid. */
2468
+ function Grid({ gap = "md", padding, columns = 2, minColumnWidth, className, style, children }) {
2469
+ const template = typeof columns === "number" ? `repeat(${columns}, minmax(0, 1fr))` : columns;
2470
+ return jsx("div", {
2471
+ ...part("grid", "root"),
2472
+ className: cn("snap-grid", className),
2473
+ style: {
2474
+ display: "grid",
2475
+ gap: space(gap),
2476
+ gridTemplateColumns: minColumnWidth !== void 0 ? `repeat(auto-fit, minmax(${minColumnWidth}, 1fr))` : template,
2477
+ ...padding !== void 0 ? { padding: space(padding) } : {},
2478
+ ...style
2479
+ },
2480
+ children
2481
+ });
2482
+ }
2483
+ /** A two-pane split (sidebar + content, list + detail). */
2484
+ function Split({ start, end, gap = "md", ratio = "minmax(0, 2fr) minmax(0, 3fr)", className, style }) {
2485
+ return jsxs("div", {
2486
+ ...part("split", "root"),
2487
+ className: cn("snap-split", className),
2488
+ style: {
2489
+ display: "grid",
2490
+ gridTemplateColumns: ratio,
2491
+ gap: space(gap),
2492
+ minHeight: 0,
2493
+ ...style
2494
+ },
2495
+ children: [jsx("div", {
2496
+ ...part("split", "start"),
2497
+ style: {
2498
+ minWidth: 0,
2499
+ minHeight: 0
2500
+ },
2501
+ children: start
2502
+ }), jsx("div", {
2503
+ ...part("split", "end"),
2504
+ style: {
2505
+ minWidth: 0,
2506
+ minHeight: 0
2507
+ },
2508
+ children: end
2509
+ })]
2510
+ });
2511
+ }
2512
+ /** The operator-window shell frame. */
2513
+ function AppShell({ header, sidebar, footer, className, style, children }) {
2514
+ return jsxs("div", {
2515
+ ...part("app-shell", "root"),
2516
+ className: cn("snap-app-shell", className),
2517
+ style: {
2518
+ display: "flex",
2519
+ flexDirection: "column",
2520
+ height: "100%",
2521
+ minHeight: 0,
2522
+ ...style
2523
+ },
2524
+ children: [
2525
+ header !== void 0 && jsx("div", {
2526
+ ...part("app-shell", "header"),
2527
+ style: { flexShrink: 0 },
2528
+ children: header
2529
+ }),
2530
+ jsxs("div", {
2531
+ style: {
2532
+ display: "flex",
2533
+ flex: 1,
2534
+ minHeight: 0
2535
+ },
2536
+ children: [sidebar !== void 0 && jsx("div", {
2537
+ ...part("app-shell", "sidebar"),
2538
+ style: {
2539
+ flexShrink: 0,
2540
+ minHeight: 0
2541
+ },
2542
+ children: sidebar
2543
+ }), jsx("div", {
2544
+ ...part("app-shell", "main"),
2545
+ style: {
2546
+ flex: 1,
2547
+ minWidth: 0,
2548
+ minHeight: 0,
2549
+ overflow: "auto"
2550
+ },
2551
+ children
2552
+ })]
2553
+ }),
2554
+ footer !== void 0 && jsx("div", {
2555
+ ...part("app-shell", "footer"),
2556
+ style: { flexShrink: 0 },
2557
+ children: footer
2558
+ })
2559
+ ]
2560
+ });
2561
+ }
2562
+ /** A page body with its own header/actions anatomy. */
2563
+ function Page({ header, actions, title, titleExtra, description, className, style, children }) {
2564
+ return jsxs("div", {
2565
+ ...part("page", "root"),
309
2566
  className: cn("snap-page", className),
310
2567
  style: {
311
2568
  display: "flex",
312
2569
  flexDirection: "column",
313
- minHeight: 0,
314
- ...style
2570
+ minHeight: 0,
2571
+ ...style
2572
+ },
2573
+ children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
2574
+ ...part("page", "header"),
2575
+ style: {
2576
+ display: "flex",
2577
+ flexDirection: "column",
2578
+ gap: space("sm"),
2579
+ flexShrink: 0
2580
+ },
2581
+ children: [
2582
+ jsxs("div", {
2583
+ style: {
2584
+ display: "flex",
2585
+ alignItems: "flex-start",
2586
+ justifyContent: "space-between",
2587
+ gap: space("md")
2588
+ },
2589
+ children: [jsxs("div", {
2590
+ style: {
2591
+ display: "flex",
2592
+ alignItems: "center",
2593
+ gap: space("sm")
2594
+ },
2595
+ children: [title !== void 0 && jsx("div", {
2596
+ ...part("page", "title"),
2597
+ children: title
2598
+ }), titleExtra !== void 0 && jsx("div", {
2599
+ ...part("page", "title-extra"),
2600
+ children: titleExtra
2601
+ })]
2602
+ }), actions !== void 0 && jsx("div", {
2603
+ ...part("page", "actions"),
2604
+ children: actions
2605
+ })]
2606
+ }),
2607
+ description !== void 0 && jsx("div", {
2608
+ ...part("page", "description"),
2609
+ children: description
2610
+ }),
2611
+ header
2612
+ ]
2613
+ }), jsx("div", {
2614
+ ...part("page", "body"),
2615
+ style: {
2616
+ display: "flex",
2617
+ flexDirection: "column",
2618
+ flex: 1,
2619
+ minHeight: 0
2620
+ },
2621
+ children
2622
+ })]
2623
+ });
2624
+ }
2625
+ /** A titled content section. */
2626
+ function Section({ title, description, actions, className, style, children }) {
2627
+ return jsxs("section", {
2628
+ ...part("section", "root"),
2629
+ className: cn("snap-section", className),
2630
+ style: {
2631
+ display: "flex",
2632
+ flexDirection: "column",
2633
+ gap: space("sm"),
2634
+ ...style
2635
+ },
2636
+ children: [(title !== void 0 || actions !== void 0) && jsxs("div", {
2637
+ ...part("section", "header"),
2638
+ style: {
2639
+ display: "flex",
2640
+ alignItems: "center",
2641
+ justifyContent: "space-between",
2642
+ gap: space("md")
2643
+ },
2644
+ children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
2645
+ ...part("section", "title"),
2646
+ children: title
2647
+ }), description !== void 0 && jsx("div", { children: description })] }), actions !== void 0 && jsx("div", {
2648
+ ...part("section", "actions"),
2649
+ children: actions
2650
+ })]
2651
+ }), jsx("div", {
2652
+ ...part("section", "body"),
2653
+ children
2654
+ })]
2655
+ });
2656
+ }
2657
+ /** A compact action bar; `children` renders between the start and end groups. */
2658
+ function Toolbar({ start, end, children, className, style }) {
2659
+ return jsxs("div", {
2660
+ ...part("toolbar", "root"),
2661
+ className: cn("snap-toolbar", className),
2662
+ style: {
2663
+ display: "flex",
2664
+ alignItems: "center",
2665
+ justifyContent: "space-between",
2666
+ gap: space("sm"),
2667
+ ...style
2668
+ },
2669
+ children: [
2670
+ jsx("div", {
2671
+ ...part("toolbar", "start"),
2672
+ style: {
2673
+ display: "flex",
2674
+ alignItems: "center",
2675
+ gap: space("sm"),
2676
+ minWidth: 0
2677
+ },
2678
+ children: start
2679
+ }),
2680
+ children !== void 0 && jsx("div", {
2681
+ ...part("toolbar", "center"),
2682
+ style: {
2683
+ display: "flex",
2684
+ alignItems: "center",
2685
+ gap: space("sm"),
2686
+ minWidth: 0
2687
+ },
2688
+ children
2689
+ }),
2690
+ jsx("div", {
2691
+ ...part("toolbar", "end"),
2692
+ style: {
2693
+ display: "flex",
2694
+ alignItems: "center",
2695
+ gap: space("sm"),
2696
+ flexShrink: 0
2697
+ },
2698
+ children: end
2699
+ })
2700
+ ]
2701
+ });
2702
+ }
2703
+ /** A scroll container with themed, overlay-style scrollbars over the Radix
2704
+ * viewport. The anatomy stays `scroll-area.root/viewport` plus the
2705
+ * `scroll-area.scrollbar/thumb` parts the skin styles. */
2706
+ function ScrollArea({ direction = "vertical", scrollbarType = "hover", className, style, children }) {
2707
+ return jsxs(ScrollAreaPrimitive.Root, {
2708
+ ...part("scroll-area", "root"),
2709
+ className: cn("snap-scroll-area", className),
2710
+ type: scrollbarType,
2711
+ style: {
2712
+ minHeight: 0,
2713
+ ...direction === "horizontal" ? { height: "100%" } : {},
2714
+ ...style
2715
+ },
2716
+ children: [
2717
+ jsx(ScrollAreaPrimitive.Viewport, {
2718
+ ...part("scroll-area", "viewport"),
2719
+ className: "snap-scroll-area-viewport",
2720
+ children
2721
+ }),
2722
+ direction !== "horizontal" && jsx(ScrollAreaPrimitive.Scrollbar, {
2723
+ ...part("scroll-area", "scrollbar"),
2724
+ className: "snap-scroll-area-scrollbar",
2725
+ orientation: "vertical",
2726
+ children: jsx(ScrollAreaPrimitive.Thumb, {
2727
+ ...part("scroll-area", "thumb"),
2728
+ className: "snap-scroll-area-thumb"
2729
+ })
2730
+ }),
2731
+ direction !== "vertical" && jsx(ScrollAreaPrimitive.Scrollbar, {
2732
+ ...part("scroll-area", "scrollbar"),
2733
+ className: "snap-scroll-area-scrollbar",
2734
+ orientation: "horizontal",
2735
+ children: jsx(ScrollAreaPrimitive.Thumb, {
2736
+ ...part("scroll-area", "thumb"),
2737
+ className: "snap-scroll-area-thumb"
2738
+ })
2739
+ })
2740
+ ]
2741
+ });
2742
+ }
2743
+ /**
2744
+ * Wire an element as a drag-pan surface over its own scroll viewport. Touch
2745
+ * pointers keep native scrolling; mouse/stylus presses pan `scrollLeft`/
2746
+ * `scrollTop` directly once the pointer travels past `threshold`, so child
2747
+ * clicks survive a press-release. While panning the element carries
2748
+ * `data-dragging="true"`. Returns the disposer removing every listener.
2749
+ */
2750
+ function attachDragPan(element, options = {}) {
2751
+ const direction = options.direction ?? "vertical";
2752
+ const threshold = options.threshold ?? 4;
2753
+ let anchor = null;
2754
+ let panned = false;
2755
+ const onPointerDown = (event) => {
2756
+ if (event.pointerType === "touch" || event.button !== 0) return;
2757
+ anchor = {
2758
+ x: event.clientX,
2759
+ y: event.clientY,
2760
+ left: element.scrollLeft,
2761
+ top: element.scrollTop
2762
+ };
2763
+ panned = false;
2764
+ };
2765
+ const onPointerMove = (event) => {
2766
+ if (anchor === null) return;
2767
+ const dx = event.clientX - anchor.x;
2768
+ const dy = event.clientY - anchor.y;
2769
+ if (!panned && Math.hypot(dx, dy) < threshold) return;
2770
+ panned = true;
2771
+ element.setAttribute("data-dragging", "true");
2772
+ if (direction !== "vertical") element.scrollLeft = anchor.left - dx;
2773
+ if (direction !== "horizontal") element.scrollTop = anchor.top - dy;
2774
+ };
2775
+ const endPan = () => {
2776
+ anchor = null;
2777
+ element.removeAttribute("data-dragging");
2778
+ };
2779
+ const onClickCapture = (event) => {
2780
+ if (!panned) return;
2781
+ panned = false;
2782
+ event.preventDefault();
2783
+ event.stopPropagation();
2784
+ };
2785
+ element.addEventListener("pointerdown", onPointerDown);
2786
+ element.addEventListener("pointermove", onPointerMove);
2787
+ element.addEventListener("pointerup", endPan);
2788
+ element.addEventListener("pointercancel", endPan);
2789
+ element.addEventListener("pointerleave", endPan);
2790
+ element.addEventListener("click", onClickCapture, true);
2791
+ return () => {
2792
+ element.removeEventListener("pointerdown", onPointerDown);
2793
+ element.removeEventListener("pointermove", onPointerMove);
2794
+ element.removeEventListener("pointerup", endPan);
2795
+ element.removeEventListener("pointercancel", endPan);
2796
+ element.removeEventListener("pointerleave", endPan);
2797
+ element.removeEventListener("click", onClickCapture, true);
2798
+ };
2799
+ }
2800
+ /** A scroll container any pointer can pan by dragging; touch keeps native
2801
+ * scrolling, mouse/stylus drags pan the viewport past a small travel
2802
+ * threshold, and child clicks survive a press-release. */
2803
+ function DragScroll({ direction = "vertical", className, style, children }) {
2804
+ const rootRef = useRef(null);
2805
+ useEffect(() => {
2806
+ const root = rootRef.current;
2807
+ if (root === null) return;
2808
+ return attachDragPan(root, { direction });
2809
+ }, [direction]);
2810
+ return jsx("div", {
2811
+ ref: rootRef,
2812
+ ...part("drag-scroll", "root"),
2813
+ className: cn("snap-drag-scroll", className),
2814
+ style: {
2815
+ overflowY: direction === "horizontal" ? "hidden" : "auto",
2816
+ overflowX: direction === "vertical" ? "hidden" : "auto",
2817
+ minHeight: 0,
2818
+ ...style
2819
+ },
2820
+ children: jsx("div", {
2821
+ ...part("drag-scroll", "viewport"),
2822
+ children
2823
+ })
2824
+ });
2825
+ }
2826
+ //#endregion
2827
+ //#region lib/types/components/schema-form.js
2828
+ /** The closed literal set a property may take: its `enum`, or — for a union of
2829
+ * scalar literals — the flattened `const` values of the `anyOf` branches, in
2830
+ * declaration order. `undefined` when the property is not a closed literal set
2831
+ * (open unions, non-scalar consts, absent both fields). */
2832
+ function literalValuesOf(property) {
2833
+ if (Array.isArray(property.enum)) return property.enum;
2834
+ const branches = property.anyOf;
2835
+ if (!Array.isArray(branches) || branches.length === 0) return void 0;
2836
+ const values = [];
2837
+ for (const branch of branches) {
2838
+ if (branch === null || typeof branch !== "object" || branch.anyOf !== void 0) return void 0;
2839
+ if (!("const" in branch)) return void 0;
2840
+ const value = branch.const;
2841
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return void 0;
2842
+ values.push(value);
2843
+ }
2844
+ return values;
2845
+ }
2846
+ function asRecord(value) {
2847
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
2848
+ }
2849
+ /** Render a flat JSON-Schema object as semantic fields. */
2850
+ function SchemaForm({ schema, value, onChange, idPrefix = "schema", columns }) {
2851
+ const properties = schema.properties ?? {};
2852
+ const required = new Set(schema.required ?? []);
2853
+ const update = (key, next) => {
2854
+ onChange({
2855
+ ...value,
2856
+ [key]: next
2857
+ });
2858
+ };
2859
+ const renderField = (key, property) => {
2860
+ const id = `${idPrefix}-${key}`;
2861
+ const current = value[key] ?? property.default;
2862
+ const label = property.title ?? key;
2863
+ const common = {
2864
+ label,
2865
+ htmlFor: id,
2866
+ ...property.description !== void 0 ? { help: property.description } : {},
2867
+ ...required.has(key) ? { required: true } : {}
2868
+ };
2869
+ const values = literalValuesOf(property);
2870
+ if (values !== void 0) {
2871
+ const options = values.map((item) => ({
2872
+ value: String(item),
2873
+ label: String(item)
2874
+ }));
2875
+ return jsx(Field, {
2876
+ ...common,
2877
+ children: jsx(TouchSelect, {
2878
+ ...current !== void 0 ? { value: String(current) } : {},
2879
+ options,
2880
+ onValueChange: (next) => {
2881
+ update(key, values.find((item) => String(item) === next) ?? next);
2882
+ },
2883
+ "aria-label": String(label)
2884
+ })
2885
+ });
2886
+ }
2887
+ if (property.type === "boolean") return jsx(Field, {
2888
+ ...common,
2889
+ children: jsx(Switch, {
2890
+ checked: current === true,
2891
+ onCheckedChange: (next) => update(key, next),
2892
+ "aria-label": String(label)
2893
+ })
2894
+ });
2895
+ if (property.type === "number" || property.type === "integer") return jsx(Field, {
2896
+ ...common,
2897
+ children: jsx(NumberInput, {
2898
+ id,
2899
+ value: typeof current === "number" ? current : "",
2900
+ ...property.minimum !== void 0 ? { min: property.minimum } : {},
2901
+ ...property.maximum !== void 0 ? { max: property.maximum } : {},
2902
+ onChange: (event) => {
2903
+ const raw = event.target.value;
2904
+ update(key, raw === "" ? void 0 : Number(raw));
2905
+ }
2906
+ })
2907
+ });
2908
+ if (property.type === "object" || property.type === "array") return jsx(Field, {
2909
+ ...common,
2910
+ help: property.description ?? "JSON 值",
2911
+ children: jsx(Textarea, {
2912
+ id,
2913
+ rows: 4,
2914
+ defaultValue: JSON.stringify(current ?? (property.type === "array" ? [] : {}), null, 2),
2915
+ onBlur: (event) => {
2916
+ try {
2917
+ update(key, JSON.parse(event.target.value));
2918
+ } catch {}
2919
+ }
2920
+ })
2921
+ });
2922
+ return jsx(Field, {
2923
+ ...common,
2924
+ children: jsx(Input, {
2925
+ id,
2926
+ value: typeof current === "string" || typeof current === "number" ? String(current) : "",
2927
+ onChange: (event) => update(key, event.target.value)
2928
+ })
2929
+ });
2930
+ };
2931
+ return jsxs("div", {
2932
+ ...part("schema-form", "root"),
2933
+ className: "snap-schema-form",
2934
+ style: columns !== void 0 ? {
2935
+ display: "grid",
2936
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
2937
+ gap: "var(--snap-space-md)"
2938
+ } : {
2939
+ display: "flex",
2940
+ flexDirection: "column",
2941
+ gap: "var(--snap-space-md)"
315
2942
  },
316
- children: [(header !== void 0 || title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("div", {
317
- ...part("page", "header"),
2943
+ children: [Object.entries(properties).map(([key, property]) => jsx("div", {
2944
+ ...part("schema-form", "field"),
2945
+ children: renderField(key, property)
2946
+ }, key)), Object.keys(properties).length === 0 && jsx("span", {
2947
+ style: { color: "var(--snap-color-muted)" },
2948
+ children: "该驱动没有额外配置项。"
2949
+ })]
2950
+ });
2951
+ }
2952
+ /** Normalize a driver's JSON Schema (which may carry `$schema`). */
2953
+ function schemaNodeOf(value) {
2954
+ return asRecord(value);
2955
+ }
2956
+ //#endregion
2957
+ //#region lib/types/components/slider.js
2958
+ /**
2959
+ * Coarse value adjustment for touch operation: a Radix slider with the
2960
+ * semantic anatomy (`slider.root/track/range/thumb`). Thumb size rides the
2961
+ * skin's control tokens so gloved operation keeps a real target.
2962
+ *
2963
+ * @module @snap-rail/ui/components/slider
2964
+ */
2965
+ /** A ranged control with a large touch target and keyboard stepping. */
2966
+ function Slider({ label, className, children, ...props }) {
2967
+ return jsxs(SliderPrimitive.Root, {
2968
+ className: cn("snap-slider", className),
2969
+ "aria-label": label,
2970
+ ...props,
2971
+ ...part("slider", "root"),
2972
+ children: [
2973
+ jsx(SliderPrimitive.Track, {
2974
+ ...part("slider", "track"),
2975
+ className: "snap-slider-track",
2976
+ children: jsx(SliderPrimitive.Range, {
2977
+ ...part("slider", "range"),
2978
+ className: "snap-slider-range"
2979
+ })
2980
+ }),
2981
+ jsx(SliderPrimitive.Thumb, {
2982
+ ...part("slider", "thumb"),
2983
+ className: "snap-slider-thumb",
2984
+ "aria-label": label
2985
+ }),
2986
+ children
2987
+ ]
2988
+ });
2989
+ }
2990
+ //#endregion
2991
+ //#region lib/types/components/surface.js
2992
+ /** A content card. */
2993
+ function Card({ className, children, ...props }) {
2994
+ return jsx("div", {
2995
+ className: cn("snap-card", className),
2996
+ ...props,
2997
+ ...part("card", "root"),
2998
+ children
2999
+ });
3000
+ }
3001
+ /** The card header region. */
3002
+ function CardHeader({ className, children, ...props }) {
3003
+ return jsx("div", {
3004
+ className: cn("snap-card-header", className),
3005
+ ...props,
3006
+ ...part("card", "header"),
3007
+ children
3008
+ });
3009
+ }
3010
+ /** The card title. */
3011
+ function CardTitle({ className, children, ...props }) {
3012
+ return jsx("div", {
3013
+ className: cn("snap-card-title", className),
3014
+ ...props,
3015
+ ...part("card", "title"),
3016
+ children
3017
+ });
3018
+ }
3019
+ /** The card description. */
3020
+ function CardDescription({ className, children, ...props }) {
3021
+ return jsx("div", {
3022
+ className: cn("snap-card-description", className),
3023
+ ...props,
3024
+ ...part("card", "description"),
3025
+ children
3026
+ });
3027
+ }
3028
+ /** The card body. */
3029
+ function CardContent({ className, children, ...props }) {
3030
+ return jsx("div", {
3031
+ className: cn("snap-card-content", className),
3032
+ ...props,
3033
+ ...part("card", "body"),
3034
+ children
3035
+ });
3036
+ }
3037
+ /** The card footer. */
3038
+ function CardFooter({ className, children, ...props }) {
3039
+ return jsx("div", {
3040
+ className: cn("snap-card-footer", className),
3041
+ ...props,
3042
+ ...part("card", "footer"),
3043
+ children
3044
+ });
3045
+ }
3046
+ /** A bounded panel with optional header/footer. */
3047
+ function Panel({ title, actions, footer, className, children, ...props }) {
3048
+ return jsxs("div", {
3049
+ className: cn("snap-panel", className),
3050
+ ...props,
3051
+ ...part("panel", "root"),
3052
+ children: [
3053
+ (title !== void 0 || actions !== void 0) && jsxs("div", {
3054
+ ...part("panel", "header"),
3055
+ className: "snap-panel-header",
3056
+ children: [jsx("div", {
3057
+ ...part("panel", "title"),
3058
+ children: title
3059
+ }), actions !== void 0 && jsx("div", { children: actions })]
3060
+ }),
3061
+ jsx("div", {
3062
+ ...part("panel", "body"),
3063
+ className: "snap-panel-body",
3064
+ children
3065
+ }),
3066
+ footer !== void 0 && jsx("div", {
3067
+ ...part("panel", "footer"),
3068
+ className: "snap-panel-footer",
3069
+ children: footer
3070
+ })
3071
+ ]
3072
+ });
3073
+ }
3074
+ /** A semantic table. */
3075
+ function Table({ className, children, ...props }) {
3076
+ return jsx("div", {
3077
+ ...part("table", "root"),
3078
+ className: cn("snap-table", className),
3079
+ children: jsx("table", {
3080
+ ...props,
3081
+ children
3082
+ })
3083
+ });
3084
+ }
3085
+ /** The table head. */
3086
+ function TableHeader({ className, children, ...props }) {
3087
+ return jsx("thead", {
3088
+ className: cn("snap-table-header", className),
3089
+ ...props,
3090
+ ...part("table", "header"),
3091
+ children
3092
+ });
3093
+ }
3094
+ /** The table body. */
3095
+ function TableBody({ className, children, ...props }) {
3096
+ return jsx("tbody", {
3097
+ className: cn("snap-table-body", className),
3098
+ ...props,
3099
+ ...part("table", "body"),
3100
+ children
3101
+ });
3102
+ }
3103
+ /** A table row. */
3104
+ function TableRow({ className, children, ...props }) {
3105
+ return jsx("tr", {
3106
+ className: cn("snap-table-row", className),
3107
+ ...props,
3108
+ ...part("table", "row"),
3109
+ children
3110
+ });
3111
+ }
3112
+ /** A table header cell. */
3113
+ function TableHead({ className, children, ...props }) {
3114
+ return jsx("th", {
3115
+ className: cn("snap-table-head", className),
3116
+ ...props,
3117
+ ...part("table", "head"),
3118
+ children
3119
+ });
3120
+ }
3121
+ /** A table body cell. */
3122
+ function TableCell({ className, children, ...props }) {
3123
+ return jsx("td", {
3124
+ className: cn("snap-table-cell", className),
3125
+ ...props,
3126
+ ...part("table", "cell"),
3127
+ children
3128
+ });
3129
+ }
3130
+ /** A full-width empty row. */
3131
+ function TableEmpty({ colSpan, children }) {
3132
+ return jsx(TableRow, { children: jsx(TableCell, {
3133
+ colSpan,
3134
+ children: jsx("div", {
3135
+ ...part("table", "empty"),
3136
+ children
3137
+ })
3138
+ }) });
3139
+ }
3140
+ //#endregion
3141
+ //#region lib/types/pages.js
3142
+ /**
3143
+ * The main-page registry: business views contribute a page, a layout renders
3144
+ * the active one. This is deliberately separate from settings pages and from
3145
+ * the chrome slots; gating/workflows can wrap it later without changing the
3146
+ * page authoring surface.
3147
+ *
3148
+ * @module @snap-rail/ui/pages
3149
+ */
3150
+ /** Mount the page registry. */
3151
+ const pagesPlugin = {
3152
+ name: "snap-rail ui pages",
3153
+ apply(ctx) {
3154
+ const pages = /* @__PURE__ */ new Map();
3155
+ const listeners = /* @__PURE__ */ new Set();
3156
+ let revision = 0;
3157
+ let seq = 0;
3158
+ let activeId;
3159
+ const ordered = () => [...pages.values()].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
3160
+ const notify = () => {
3161
+ revision += 1;
3162
+ for (const listener of listeners) listener();
3163
+ ctx.emit("pages/changed");
3164
+ };
3165
+ const service = {
3166
+ registerPage(caller, page) {
3167
+ pages.set(page.id, {
3168
+ page,
3169
+ seq: seq++
3170
+ });
3171
+ activeId ??= page.id;
3172
+ notify();
3173
+ const remove = () => {
3174
+ if (!pages.delete(page.id)) return;
3175
+ if (activeId === page.id) activeId = ordered()[0]?.id;
3176
+ notify();
3177
+ };
3178
+ caller.effect(() => remove);
3179
+ return remove;
3180
+ },
3181
+ list: ordered,
3182
+ active() {
3183
+ if (activeId === void 0) return void 0;
3184
+ return pages.get(activeId)?.page ?? ordered()[0];
3185
+ },
3186
+ setActive(id) {
3187
+ if (!pages.has(id) || activeId === id) return;
3188
+ activeId = id;
3189
+ notify();
3190
+ },
3191
+ subscribe(listener) {
3192
+ listeners.add(listener);
3193
+ return () => {
3194
+ listeners.delete(listener);
3195
+ };
3196
+ },
3197
+ version: () => revision
3198
+ };
3199
+ ctx.provide("pages", service);
3200
+ }
3201
+ };
3202
+ /** Re-render a layout when the page registry or active page changes. */
3203
+ function usePagesVersion(ctx) {
3204
+ return useSyncExternalStore(ctx.pages.subscribe, ctx.pages.version, ctx.pages.version);
3205
+ }
3206
+ //#endregion
3207
+ //#region lib/types/slots.js
3208
+ const MAX_DIAGNOSTICS = 100;
3209
+ /** The default definition of a built-in slot. */
3210
+ function builtinDefinition(slot) {
3211
+ return {
3212
+ id: slot,
3213
+ mode: UI_SLOT_MODES[slot] ?? "many"
3214
+ };
3215
+ }
3216
+ /** Mount the `ctx.ui` registry. */
3217
+ const slotsPlugin = {
3218
+ name: "snap-rail ui slots",
3219
+ apply(ctx) {
3220
+ const entries = /* @__PURE__ */ new Map();
3221
+ const layouts = /* @__PURE__ */ new Map();
3222
+ const listeners = /* @__PURE__ */ new Set();
3223
+ const diagnostics = [];
3224
+ let revision = 0;
3225
+ let layoutSeq = 0;
3226
+ for (const slot of Object.values(UI_SLOT_IDS)) entries.set(slot, {
3227
+ def: builtinDefinition(slot),
3228
+ contributions: /* @__PURE__ */ new Map(),
3229
+ nextSeq: 0
3230
+ });
3231
+ const notify = (slot) => {
3232
+ revision += 1;
3233
+ for (const listener of listeners) listener();
3234
+ ctx.emit("ui/changed");
3235
+ if (slot !== void 0) ctx.emit("ui/slot-changed", slot);
3236
+ };
3237
+ const diagnose = (diagnostic) => {
3238
+ diagnostics.push({
3239
+ ...diagnostic,
3240
+ time: Date.now()
3241
+ });
3242
+ if (diagnostics.length > MAX_DIAGNOSTICS) diagnostics.shift();
3243
+ };
3244
+ const activeLayoutOf = () => {
3245
+ return [...layouts.values()].sort((a, b) => {
3246
+ const pa = a.layout.precedence ?? 0;
3247
+ return (b.layout.precedence ?? 0) - pa || a.layout.order - b.layout.order || b.seq - a.seq;
3248
+ })[0]?.layout;
3249
+ };
3250
+ const ensureEntry = (slot) => {
3251
+ const existing = entries.get(slot);
3252
+ if (existing !== void 0) return existing;
3253
+ const entry = {
3254
+ def: {
3255
+ id: slot,
3256
+ mode: "many"
3257
+ },
3258
+ contributions: /* @__PURE__ */ new Map(),
3259
+ nextSeq: 0
3260
+ };
3261
+ entries.set(slot, entry);
3262
+ return entry;
3263
+ };
3264
+ ctx.provide("ui", {
3265
+ defineSlot(caller, def) {
3266
+ if (!isValidSlotId(def.id)) {
3267
+ diagnose({
3268
+ kind: "unknown-slot",
3269
+ slot: def.id,
3270
+ message: `插槽 id 不合法:${def.id}`
3271
+ });
3272
+ return () => {};
3273
+ }
3274
+ if (Object.values(UI_SLOT_IDS).includes(def.id)) {
3275
+ diagnose({
3276
+ kind: "duplicate-id",
3277
+ slot: def.id,
3278
+ message: `内置插槽不能被重新定义:${def.id}`
3279
+ });
3280
+ return () => {};
3281
+ }
3282
+ const entry = ensureEntry(def.id);
3283
+ entry.def = def;
3284
+ notify(def.id);
3285
+ const remove = () => {
3286
+ if (entries.delete(def.id)) notify(def.id);
3287
+ };
3288
+ caller.effect(() => remove);
3289
+ return remove;
3290
+ },
3291
+ registerLayout(caller, layout) {
3292
+ for (const slot of layout.provides) if (!isValidSlotId(slot)) diagnose({
3293
+ kind: "unknown-slot",
3294
+ id: layout.id,
3295
+ slot,
3296
+ message: `布局 ${layout.id} 声明了非法插槽:${slot}`
3297
+ });
3298
+ else if (!entries.has(slot)) diagnose({
3299
+ kind: "unknown-slot",
3300
+ id: layout.id,
3301
+ slot,
3302
+ message: `布局 ${layout.id} 声明了未定义的插槽:${slot}`
3303
+ });
3304
+ layouts.set(layout.id, {
3305
+ layout,
3306
+ seq: layoutSeq++
3307
+ });
3308
+ notify();
3309
+ const remove = () => {
3310
+ if (layouts.delete(layout.id)) notify();
3311
+ };
3312
+ caller.effect(() => remove);
3313
+ return remove;
3314
+ },
3315
+ contribute(caller, slot, contribution) {
3316
+ if (!isValidSlotId(slot)) {
3317
+ diagnose({
3318
+ kind: "unknown-slot",
3319
+ id: contribution.id,
3320
+ slot,
3321
+ message: `贡献 ${contribution.id} 指向非法插槽:${slot}`
3322
+ });
3323
+ return () => {};
3324
+ }
3325
+ const entry = entries.get(slot);
3326
+ if (entry === void 0) diagnose({
3327
+ kind: "unknown-slot",
3328
+ id: contribution.id,
3329
+ slot,
3330
+ message: `贡献 ${contribution.id} 指向未定义的插槽:${slot}`
3331
+ });
3332
+ const target = entry ?? ensureEntry(slot);
3333
+ target.contributions.set(contribution.id, {
3334
+ contribution,
3335
+ seq: target.nextSeq++
3336
+ });
3337
+ notify(slot);
3338
+ const remove = () => {
3339
+ if (target.contributions.delete(contribution.id)) notify(slot);
3340
+ };
3341
+ caller.effect(() => remove);
3342
+ return remove;
3343
+ },
3344
+ list(slot) {
3345
+ const entry = entries.get(slot);
3346
+ if (entry === void 0) return [];
3347
+ const ranked = [...entry.contributions.values()].sort((a, b) => a.contribution.order - b.contribution.order || a.seq - b.seq);
3348
+ if (entry.def.mode !== "one" || ranked.length === 0) return ranked.map((item) => item.contribution);
3349
+ return [ranked.reduce((best, item) => {
3350
+ const delta = (item.contribution.precedence ?? 0) - (best.contribution.precedence ?? 0);
3351
+ return delta > 0 || delta === 0 && item.seq > best.seq ? item : best;
3352
+ }).contribution];
3353
+ },
3354
+ definition: (slot) => entries.get(slot)?.def,
3355
+ activeLayout: activeLayoutOf,
3356
+ hasProvider(slot) {
3357
+ const active = activeLayoutOf();
3358
+ return active !== void 0 && active.provides.includes(slot);
3359
+ },
3360
+ diagnostics: () => diagnostics,
3361
+ subscribe(listener) {
3362
+ listeners.add(listener);
3363
+ return () => {
3364
+ listeners.delete(listener);
3365
+ };
3366
+ },
3367
+ version: () => revision
3368
+ });
3369
+ }
3370
+ };
3371
+ /** The React context carrying the active UI service. */
3372
+ const UiContext = createContext(null);
3373
+ /** Provide the UI service to a slot tree. */
3374
+ function UiProvider(props) {
3375
+ return jsx(UiContext.Provider, {
3376
+ value: props.service,
3377
+ children: props.children
3378
+ });
3379
+ }
3380
+ /** Read the UI service; throws when a slot tree is mounted outside the runtime. */
3381
+ function useUi() {
3382
+ const service = useContext(UiContext);
3383
+ if (service === null) throw new Error("useUi: no UiProvider in the tree");
3384
+ return service;
3385
+ }
3386
+ /** Re-render on every registry change. */
3387
+ function useUiVersion(service) {
3388
+ return useSyncExternalStore(service.subscribe, service.version, service.version);
3389
+ }
3390
+ /** Keep one broken contribution from taking down the whole shell. */
3391
+ var SlotBoundary = class extends Component {
3392
+ state = { failed: false };
3393
+ static getDerivedStateFromError() {
3394
+ return { failed: true };
3395
+ }
3396
+ componentDidCatch(error) {
3397
+ this.props.onError(error);
3398
+ }
3399
+ render() {
3400
+ return this.state.failed ? null : this.props.children;
3401
+ }
3402
+ };
3403
+ /** A region-slot outlet rendered by a layout. */
3404
+ function Slot(props) {
3405
+ const service = useUi();
3406
+ useUiVersion(service);
3407
+ const provided = service.hasProvider(props.name);
3408
+ const entry = service.list(props.name);
3409
+ const def = service.definition(props.name);
3410
+ const context = props.context ?? {};
3411
+ if (!provided) return null;
3412
+ if (entry.length === 0) {
3413
+ const fallback = def?.fallback;
3414
+ return fallback?.(context) ?? null;
3415
+ }
3416
+ return jsx(Fragment, { children: entry.map((item) => jsx(SlotBoundary, {
3417
+ onError: (error) => {
3418
+ console.error(`[snap-rail ui] slot ${props.name} contribution ${item.id} failed`, error);
3419
+ },
3420
+ children: item.render(context)
3421
+ }, item.id)) });
3422
+ }
3423
+ /** Re-render when the active layout changes. */
3424
+ function useActiveLayout() {
3425
+ const service = useUi();
3426
+ useUiVersion(service);
3427
+ return service.activeLayout();
3428
+ }
3429
+ //#endregion
3430
+ //#region lib/types/fallback.js
3431
+ /** A compact glyph for the window controls. */
3432
+ function Glyph(props) {
3433
+ return jsx("span", {
3434
+ "aria-hidden": "true",
3435
+ style: { lineHeight: 1 },
3436
+ children: props.children
3437
+ });
3438
+ }
3439
+ /** The fallback body. */
3440
+ function FallbackShell(props) {
3441
+ useUiVersion(props.ctx.ui);
3442
+ usePagesVersion(props.ctx);
3443
+ const active = props.ctx.pages.active();
3444
+ const control = (action) => {
3445
+ props.ctx.client.link.call("window.control", { action }).catch(() => {});
3446
+ };
3447
+ const header = jsxs("div", {
3448
+ className: "snap-fallback-titlebar",
3449
+ style: {
3450
+ display: "flex",
3451
+ alignItems: "center",
3452
+ justifyContent: "space-between",
3453
+ minHeight: 48,
3454
+ paddingLeft: 16
3455
+ },
3456
+ children: [jsxs("span", {
3457
+ style: {
3458
+ color: "var(--snap-color-muted)",
3459
+ fontSize: "var(--snap-text-sm)"
3460
+ },
3461
+ children: ["snap-rail", active !== void 0 ? ` · ${active.title}` : ""]
3462
+ }), jsxs("div", {
318
3463
  style: {
319
3464
  display: "flex",
320
- flexDirection: "column",
321
- gap: space("sm"),
322
- flexShrink: 0
3465
+ alignItems: "center",
3466
+ gap: 4
3467
+ },
3468
+ children: [
3469
+ jsx(Slot, {
3470
+ name: UI_SLOT_IDS.settingsEntry,
3471
+ context: {
3472
+ presentation: "icon",
3473
+ open: () => props.ctx.settings.open(),
3474
+ isOpen: props.ctx.settings.isOpen()
3475
+ }
3476
+ }),
3477
+ jsx(IconButton, {
3478
+ icon: jsx(Glyph, { children: "—" }),
3479
+ label: "最小化",
3480
+ onClick: () => control("minimize")
3481
+ }),
3482
+ jsx(IconButton, {
3483
+ icon: jsx(Glyph, { children: "□" }),
3484
+ label: "最大化切换",
3485
+ onClick: () => control("toggle-maximize")
3486
+ }),
3487
+ jsx(IconButton, {
3488
+ icon: jsx(Glyph, { children: "×" }),
3489
+ label: "关闭",
3490
+ onClick: () => control("close")
3491
+ })
3492
+ ]
3493
+ })]
3494
+ });
3495
+ return jsx(AppShell, {
3496
+ header,
3497
+ children: active !== void 0 ? active.render() : jsx("div", {
3498
+ style: {
3499
+ display: "flex",
3500
+ minHeight: "100%",
3501
+ alignItems: "center",
3502
+ justifyContent: "center",
3503
+ padding: 24
3504
+ },
3505
+ children: jsx(EmptyState, {
3506
+ title: "尚未激活业务套件",
3507
+ action: jsx(Button, {
3508
+ intent: "primary",
3509
+ onClick: () => props.ctx.settings.open("plugins"),
3510
+ children: "打开设置"
3511
+ })
3512
+ })
3513
+ })
3514
+ });
3515
+ }
3516
+ /** The fallback layout occupant. */
3517
+ const fallbackPlugin = {
3518
+ name: "snap-rail fallback layout",
3519
+ inject: [
3520
+ "ui",
3521
+ "settings",
3522
+ "pages",
3523
+ "client"
3524
+ ],
3525
+ apply(ctx) {
3526
+ ctx.ui.registerLayout(ctx, {
3527
+ id: "fallback",
3528
+ order: 200,
3529
+ precedence: 0,
3530
+ provides: [
3531
+ UI_SLOT_IDS.titlebar,
3532
+ UI_SLOT_IDS.titlebarActions,
3533
+ UI_SLOT_IDS.sidebar,
3534
+ UI_SLOT_IDS.statusbar,
3535
+ UI_SLOT_IDS.settingsEntry
3536
+ ],
3537
+ window: {
3538
+ width: 1280,
3539
+ height: 800,
3540
+ minWidth: 960,
3541
+ minHeight: 600
323
3542
  },
3543
+ ball: { size: 128 },
3544
+ render: () => jsx(FallbackShell, { ctx })
3545
+ });
3546
+ }
3547
+ };
3548
+ //#endregion
3549
+ //#region lib/types/settings-pages/appearance.js
3550
+ const THEME_KEY = "ui.theme";
3551
+ const WINDOW_KEY = "ui.window";
3552
+ const BALL_KEY = "ui.ball";
3553
+ const WINDOW_PRESETS = [
3554
+ {
3555
+ label: "1280 × 800",
3556
+ width: 1280,
3557
+ height: 800
3558
+ },
3559
+ {
3560
+ label: "1440 × 900",
3561
+ width: 1440,
3562
+ height: 900
3563
+ },
3564
+ {
3565
+ label: "1600 × 900",
3566
+ width: 1600,
3567
+ height: 900
3568
+ },
3569
+ {
3570
+ label: "1920 × 1080",
3571
+ width: 1920,
3572
+ height: 1080
3573
+ }
3574
+ ];
3575
+ const BALL_SIZES = [
3576
+ 96,
3577
+ 112,
3578
+ 128,
3579
+ 160,
3580
+ 192
3581
+ ];
3582
+ /** Read a settings value through the host link. */
3583
+ async function readSetting(link, key) {
3584
+ const result = await link.call("settings.get", { key });
3585
+ return result.ok ? result.value.value : void 0;
3586
+ }
3587
+ /** Write a settings value; `null` clears the row. */
3588
+ async function writeSetting(link, key, value) {
3589
+ await link.call("settings.set", {
3590
+ key,
3591
+ value
3592
+ });
3593
+ }
3594
+ /** The appearance/display page. */
3595
+ function AppearancePage() {
3596
+ const { link } = useClient();
3597
+ const skins = useSkins();
3598
+ const activeId = useSkinId();
3599
+ const [packages, setPackages] = useState([]);
3600
+ const [windowPreset, setWindowPreset] = useState(void 0);
3601
+ const [ballSize, setBallSize] = useState(128);
3602
+ const [ballEnabled, setBallEnabled] = useState(true);
3603
+ const [ballCollapse, setBallCollapse] = useState(true);
3604
+ const [error, setError] = useState(void 0);
3605
+ const [busy, setBusy] = useState(false);
3606
+ useEffect(() => {
3607
+ Promise.all([
3608
+ readSetting(link, WINDOW_KEY),
3609
+ readSetting(link, BALL_KEY),
3610
+ link.call("plugins.list", {})
3611
+ ]).then(([windowRow, ballRow, plugins]) => {
3612
+ const windowProfile = windowRow;
3613
+ if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
3614
+ const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
3615
+ setWindowPreset(preset?.label);
3616
+ }
3617
+ const ballProfile = ballRow;
3618
+ if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
3619
+ if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
3620
+ if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
3621
+ if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
3622
+ name: plugin.packageName,
3623
+ title: plugin.title ?? plugin.packageName,
3624
+ enabled: plugin.enabled
3625
+ })));
3626
+ }).catch((cause) => {
3627
+ setError(cause instanceof Error ? cause.message : String(cause));
3628
+ });
3629
+ }, [link]);
3630
+ const saveWindow = (width, height, label) => {
3631
+ setWindowPreset(label);
3632
+ writeSetting(link, WINDOW_KEY, {
3633
+ width,
3634
+ height,
3635
+ minWidth: 960,
3636
+ minHeight: 600
3637
+ }).catch((cause) => {
3638
+ setError(cause instanceof Error ? cause.message : String(cause));
3639
+ });
3640
+ };
3641
+ const resetWindow = () => {
3642
+ setWindowPreset(void 0);
3643
+ writeSetting(link, WINDOW_KEY, null).catch((cause) => {
3644
+ setError(cause instanceof Error ? cause.message : String(cause));
3645
+ });
3646
+ };
3647
+ const saveBall = (patch) => {
3648
+ const next = {
3649
+ size: patch.size ?? ballSize,
3650
+ enabled: patch.enabled ?? ballEnabled,
3651
+ collapse: patch.collapse ?? ballCollapse
3652
+ };
3653
+ if (patch.size !== void 0) setBallSize(patch.size);
3654
+ if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
3655
+ if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
3656
+ writeSetting(link, BALL_KEY, next).catch((cause) => {
3657
+ setError(cause instanceof Error ? cause.message : String(cause));
3658
+ });
3659
+ };
3660
+ const tabs = [...skins.list().map((row) => ({
3661
+ id: row.id,
3662
+ title: row.title
3663
+ })), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
3664
+ id: pkg.name,
3665
+ title: pkg.title,
3666
+ enable: pkg.name
3667
+ }))];
3668
+ const selectTheme = (tab) => {
3669
+ if (busy) return;
3670
+ if (tab.enable === void 0) {
3671
+ writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
3672
+ setError(cause instanceof Error ? cause.message : String(cause));
3673
+ });
3674
+ return;
3675
+ }
3676
+ setBusy(true);
3677
+ link.call("plugins.set-enabled", {
3678
+ name: tab.enable,
3679
+ enabled: true
3680
+ }).then((result) => {
3681
+ if (!result.ok) {
3682
+ setError(rpcErrorText(result.error));
3683
+ return;
3684
+ }
3685
+ setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
3686
+ ...pkg,
3687
+ enabled: true
3688
+ } : pkg));
3689
+ return writeSetting(link, THEME_KEY, { id: tab.id });
3690
+ }).catch((cause) => {
3691
+ setError(cause instanceof Error ? cause.message : String(cause));
3692
+ }).finally(() => {
3693
+ setBusy(false);
3694
+ });
3695
+ };
3696
+ return jsx(Page, {
3697
+ title: "外观与显示",
3698
+ description: "主题、主窗口尺寸和悬浮球外观。",
3699
+ children: jsxs(Stack, {
3700
+ gap: "lg",
324
3701
  children: [
325
- jsxs("div", {
326
- style: {
327
- display: "flex",
328
- alignItems: "flex-start",
329
- justifyContent: "space-between",
330
- gap: space("md")
331
- },
332
- children: [jsxs("div", {
333
- style: {
334
- display: "flex",
335
- alignItems: "center",
336
- gap: space("sm")
3702
+ error !== void 0 && jsx(Alert, {
3703
+ intent: "danger",
3704
+ children: error
3705
+ }),
3706
+ jsx(Section, {
3707
+ title: "主题",
3708
+ children: jsx(Tabs, {
3709
+ value: activeId,
3710
+ onValueChange: (value) => {
3711
+ const tab = tabs.find((item) => item.id === value);
3712
+ if (tab !== void 0) selectTheme(tab);
337
3713
  },
338
- children: [title !== void 0 && jsx("div", {
339
- ...part("page", "title"),
340
- children: title
341
- }), titleExtra !== void 0 && jsx("div", {
342
- ...part("page", "title-extra"),
343
- children: titleExtra
344
- })]
345
- }), actions !== void 0 && jsx("div", {
346
- ...part("page", "actions"),
347
- children: actions
348
- })]
3714
+ children: jsx(TabsList, {
3715
+ "aria-label": "主题",
3716
+ children: tabs.map((tab) => jsx(TabsTrigger, {
3717
+ value: tab.id,
3718
+ disabled: busy,
3719
+ children: tab.title
3720
+ }, tab.id))
3721
+ })
3722
+ })
349
3723
  }),
350
- description !== void 0 && jsx("div", {
351
- ...part("page", "description"),
352
- children: description
3724
+ jsx(Section, {
3725
+ title: "主窗口",
3726
+ children: jsxs(Stack, {
3727
+ gap: "sm",
3728
+ children: [jsxs(Row, {
3729
+ gap: "sm",
3730
+ wrap: true,
3731
+ children: [WINDOW_PRESETS.map((preset) => jsx(Button, {
3732
+ size: "sm",
3733
+ intent: windowPreset === preset.label ? "primary" : "neutral",
3734
+ emphasis: windowPreset === preset.label ? "solid" : "outline",
3735
+ onClick: () => saveWindow(preset.width, preset.height, preset.label),
3736
+ children: preset.label
3737
+ }, preset.label)), jsx(Button, {
3738
+ size: "sm",
3739
+ emphasis: "ghost",
3740
+ onClick: resetWindow,
3741
+ children: "跟随布局"
3742
+ })]
3743
+ }), jsxs("span", {
3744
+ style: {
3745
+ color: "var(--snap-color-muted)",
3746
+ fontSize: "var(--snap-text-sm)"
3747
+ },
3748
+ children: ["当前:", windowPreset ?? "跟随布局推荐 / 默认 1280 × 800"]
3749
+ })]
3750
+ })
353
3751
  }),
354
- header
3752
+ jsx(Section, {
3753
+ title: "悬浮球",
3754
+ description: "球面尺寸与停泊行为。",
3755
+ children: jsxs(Stack, {
3756
+ gap: "md",
3757
+ children: [jsx(Row, {
3758
+ gap: "sm",
3759
+ wrap: true,
3760
+ align: "center",
3761
+ children: BALL_SIZES.map((size) => jsxs(Button, {
3762
+ size: "sm",
3763
+ intent: ballSize === size ? "primary" : "neutral",
3764
+ emphasis: ballSize === size ? "solid" : "outline",
3765
+ onClick: () => saveBall({ size }),
3766
+ children: [size, "px"]
3767
+ }, size))
3768
+ }), jsxs(Row, {
3769
+ gap: "lg",
3770
+ wrap: true,
3771
+ align: "center",
3772
+ children: [jsx(Switch, {
3773
+ label: "启用悬浮球",
3774
+ checked: ballEnabled,
3775
+ onCheckedChange: (enabled) => saveBall({ enabled })
3776
+ }), jsx(Switch, {
3777
+ label: "允许贴边收起",
3778
+ checked: ballCollapse,
3779
+ onCheckedChange: (collapse) => saveBall({ collapse })
3780
+ })]
3781
+ })]
3782
+ })
3783
+ })
355
3784
  ]
356
- }), jsx("div", {
357
- ...part("page", "body"),
358
- style: {
359
- display: "flex",
360
- flexDirection: "column",
361
- flex: 1,
362
- minHeight: 0
363
- },
364
- children
365
- })]
3785
+ })
366
3786
  });
367
3787
  }
368
3788
  //#endregion
369
- //#region lib/types/components/surface.js
370
- /** A semantic table. */
371
- function Table({ className, children, ...props }) {
372
- return jsx("div", {
373
- ...part("table", "root"),
374
- className: cn("snap-table", className),
375
- children: jsx("table", {
376
- ...props,
377
- children
3789
+ //#region lib/types/settings-pages/plugin-feed.js
3790
+ /** The feed-source editor dialog; the open state lives with the opener. */
3791
+ function PluginFeedDialog(props) {
3792
+ const { open } = props;
3793
+ const link = props.ctx.client.link;
3794
+ const [urls, setUrls] = useState([]);
3795
+ const [draft, setDraft] = useState("");
3796
+ const [error, setError] = useState(void 0);
3797
+ useEffect(() => {
3798
+ if (!open) return;
3799
+ link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
3800
+ if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
3801
+ }).catch(() => void 0);
3802
+ }, [open, link]);
3803
+ const save = () => {
3804
+ for (const url of urls) try {
3805
+ const parsed = new URL(url);
3806
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
3807
+ } catch {
3808
+ setError("插件源地址需要以 http(s) 开头");
3809
+ return;
3810
+ }
3811
+ setError(void 0);
3812
+ link.call("settings.set", {
3813
+ key: PLUGINS_FEED_URLS_KEY,
3814
+ value: urls
3815
+ }).then((result) => {
3816
+ if (!result.ok) {
3817
+ setError(rpcErrorText(result.error));
3818
+ return;
3819
+ }
3820
+ props.onOpenChange(false);
3821
+ }).catch((cause) => setError(String(cause)));
3822
+ };
3823
+ const append = () => {
3824
+ const value = draft.trim();
3825
+ if (value === "") return;
3826
+ try {
3827
+ const parsed = new URL(value);
3828
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
3829
+ } catch {
3830
+ setError("请填写 http(s) 开头的插件源地址");
3831
+ return;
3832
+ }
3833
+ setError(void 0);
3834
+ setDraft("");
3835
+ setUrls((current) => current.includes(value) ? current : [...current, value]);
3836
+ };
3837
+ return jsx(Dialog, {
3838
+ open,
3839
+ onOpenChange: props.onOpenChange,
3840
+ children: jsxs(DialogContent, {
3841
+ presentation: "modal",
3842
+ "aria-describedby": void 0,
3843
+ children: [
3844
+ jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
3845
+ jsx(DialogBody, { children: jsxs(Stack, {
3846
+ gap: "sm",
3847
+ children: [
3848
+ urls.length === 0 && jsx("div", {
3849
+ style: {
3850
+ fontSize: "var(--snap-text-xs)",
3851
+ color: "var(--snap-color-muted)"
3852
+ },
3853
+ children: "尚未添加自定义源(当前使用出厂默认源)。"
3854
+ }),
3855
+ urls.map((url, index) => jsxs("div", {
3856
+ style: {
3857
+ display: "flex",
3858
+ gap: "var(--snap-space-sm)",
3859
+ alignItems: "center"
3860
+ },
3861
+ children: [jsx("span", {
3862
+ style: {
3863
+ flex: 1,
3864
+ minWidth: 0,
3865
+ overflow: "hidden",
3866
+ textOverflow: "ellipsis",
3867
+ whiteSpace: "nowrap",
3868
+ fontSize: "var(--snap-text-xs)"
3869
+ },
3870
+ children: url
3871
+ }), jsx(Button, {
3872
+ intent: "neutral",
3873
+ emphasis: "ghost",
3874
+ size: "sm",
3875
+ "aria-label": `移除 ${url}`,
3876
+ onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
3877
+ children: "✕"
3878
+ })]
3879
+ }, url)),
3880
+ jsxs("div", {
3881
+ style: {
3882
+ display: "flex",
3883
+ gap: "var(--snap-space-sm)",
3884
+ width: "100%"
3885
+ },
3886
+ children: [jsx(Input, {
3887
+ value: draft,
3888
+ placeholder: "https://…",
3889
+ style: {
3890
+ flex: 1,
3891
+ minWidth: 0
3892
+ },
3893
+ onChange: (event) => setDraft(event.target.value),
3894
+ onKeyDown: (event) => {
3895
+ if (event.key === "Enter") append();
3896
+ }
3897
+ }), jsx(Button, {
3898
+ intent: "neutral",
3899
+ emphasis: "outline",
3900
+ onClick: append,
3901
+ children: "添加源"
3902
+ })]
3903
+ }),
3904
+ error !== void 0 && jsx("div", {
3905
+ role: "alert",
3906
+ style: {
3907
+ color: "var(--snap-color-danger)",
3908
+ fontSize: "var(--snap-text-sm)"
3909
+ },
3910
+ children: error
3911
+ })
3912
+ ]
3913
+ }) }),
3914
+ jsxs(DialogFooter, { children: [jsx(Button, {
3915
+ intent: "neutral",
3916
+ emphasis: "outline",
3917
+ onClick: () => props.onOpenChange(false),
3918
+ children: "取消"
3919
+ }), jsx(Button, {
3920
+ intent: "primary",
3921
+ "data-plugins-feed-save": true,
3922
+ onClick: save,
3923
+ children: "保存"
3924
+ })] })
3925
+ ]
378
3926
  })
379
3927
  });
380
3928
  }
381
- /** The table head. */
382
- function TableHeader({ className, children, ...props }) {
383
- return jsx("thead", {
384
- ...part("table", "header"),
385
- className: cn("snap-table-header", className),
386
- ...props,
387
- children
388
- });
389
- }
390
- /** The table body. */
391
- function TableBody({ className, children, ...props }) {
392
- return jsx("tbody", {
393
- ...part("table", "body"),
394
- className: cn("snap-table-body", className),
395
- ...props,
396
- children
397
- });
398
- }
399
- /** A table row. */
400
- function TableRow({ className, children, ...props }) {
401
- return jsx("tr", {
402
- ...part("table", "row"),
403
- className: cn("snap-table-row", className),
404
- ...props,
405
- children
406
- });
407
- }
408
- /** A table header cell. */
409
- function TableHead({ className, children, ...props }) {
410
- return jsx("th", {
411
- ...part("table", "head"),
412
- className: cn("snap-table-head", className),
413
- ...props,
414
- children
415
- });
416
- }
417
- /** A table body cell. */
418
- function TableCell({ className, children, ...props }) {
419
- return jsx("td", {
420
- ...part("table", "cell"),
421
- className: cn("snap-table-cell", className),
422
- ...props,
423
- children
424
- });
425
- }
426
3929
  //#endregion
427
3930
  //#region lib/types/settings-pages/plugins.js
428
3931
  /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
@@ -781,9 +4284,8 @@ function PluginsPage({ ctx }) {
781
4284
  children: [
782
4285
  jsxs(Stack, {
783
4286
  gap: "lg",
784
- children: [error !== void 0 && jsx("div", {
785
- role: "alert",
786
- style: { color: "var(--snap-color-danger)" },
4287
+ children: [error !== void 0 && jsx(Alert, {
4288
+ intent: "danger",
787
4289
  children: error
788
4290
  }), rows.length === 0 ? jsx(EmptyState, {
789
4291
  title: "还没有安装插件",
@@ -1279,4 +4781,528 @@ function PluginsPage({ ctx }) {
1279
4781
  });
1280
4782
  }
1281
4783
  //#endregion
1282
- export { PluginsPage };
4784
+ //#region lib/types/settings.js
4785
+ /** Sort pages by order, then registration time. */
4786
+ function orderedPages(pages) {
4787
+ return [...pages].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
4788
+ }
4789
+ /** A page-level boundary: one broken settings page must not take down the shell. */
4790
+ var SettingsPageBoundary = class extends Component {
4791
+ state = { failed: false };
4792
+ static getDerivedStateFromError() {
4793
+ return { failed: true };
4794
+ }
4795
+ componentDidCatch(error) {
4796
+ console.error(`[snap-rail ui] settings page ${this.props.page} failed`, error);
4797
+ }
4798
+ render() {
4799
+ return this.state.failed ? jsx(EmptyState, {
4800
+ title: "设置页加载失败",
4801
+ description: "该页面抛出了异常,其他设置页仍可使用。"
4802
+ }) : this.props.children;
4803
+ }
4804
+ };
4805
+ /** The gear glyph used by the default trigger. */
4806
+ function GearIcon() {
4807
+ return jsxs("svg", {
4808
+ viewBox: "0 0 24 24",
4809
+ width: "18",
4810
+ height: "18",
4811
+ fill: "none",
4812
+ stroke: "currentColor",
4813
+ strokeWidth: "1.8",
4814
+ "aria-hidden": "true",
4815
+ children: [jsx("circle", {
4816
+ cx: "12",
4817
+ cy: "12",
4818
+ r: "3"
4819
+ }), jsx("path", { d: "M19.4 15a1.7 1.7 0 0 0 .34 1.87l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.7 1.7 0 0 0-1.87-.34 1.7 1.7 0 0 0-1 1.55V21a2 2 0 1 1-4 0v-.09a1.7 1.7 0 0 0-1-1.55 1.7 1.7 0 0 0-1.87.34l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.7 1.7 0 0 0 .34-1.87 1.7 1.7 0 0 0-1.55-1H3a2 2 0 1 1 0-4h.09a1.7 1.7 0 0 0 1.55-1 1.7 1.7 0 0 0-.34-1.87l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.7 1.7 0 0 0 1.87.34h0a1.7 1.7 0 0 0 1-1.55V3a2 2 0 1 1 4 0v.09a1.7 1.7 0 0 0 1 1.55h0a1.7 1.7 0 0 0 1.87-.34l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.7 1.7 0 0 0-.34 1.87v0a1.7 1.7 0 0 0 1.55 1H21a2 2 0 1 1 0 4h-.09a1.7 1.7 0 0 0-1.55 1Z" })]
4820
+ });
4821
+ }
4822
+ /** The close glyph used by the surface's dismiss control. */
4823
+ function CloseIcon() {
4824
+ return jsx("svg", {
4825
+ viewBox: "0 0 24 24",
4826
+ width: "18",
4827
+ height: "18",
4828
+ fill: "none",
4829
+ stroke: "currentColor",
4830
+ strokeWidth: "1.8",
4831
+ "aria-hidden": "true",
4832
+ children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
4833
+ });
4834
+ }
4835
+ /** The default settings trigger; the layout decides placement/presentation. */
4836
+ function SettingsEntry(props) {
4837
+ if (props.presentation === "label") return jsx(Button, {
4838
+ intent: "neutral",
4839
+ emphasis: "ghost",
4840
+ icon: jsx(GearIcon, {}),
4841
+ onClick: props.open,
4842
+ children: "设置"
4843
+ });
4844
+ return jsx(IconButton, {
4845
+ icon: jsx(GearIcon, {}),
4846
+ label: "设置",
4847
+ active: props.isOpen,
4848
+ onClick: props.open
4849
+ });
4850
+ }
4851
+ /** The default settings surface. */
4852
+ function SettingsSurface(props) {
4853
+ const { service, ctx } = props;
4854
+ useSyncExternalStore(service.subscribe, service.version, service.version);
4855
+ const open = service.isOpen();
4856
+ const pages = service.listPages();
4857
+ const activeId = service.activePage();
4858
+ const active = pages.find((page) => page.id === activeId);
4859
+ const [feedOpen, setFeedOpen] = useState(false);
4860
+ const groups = /* @__PURE__ */ new Map();
4861
+ for (const page of pages) {
4862
+ const group = page.group ?? "其他";
4863
+ const bucket = groups.get(group);
4864
+ if (bucket === void 0) groups.set(group, [page]);
4865
+ else bucket.push(page);
4866
+ }
4867
+ return jsxs(Fragment, { children: [jsx(Dialog, {
4868
+ open,
4869
+ onOpenChange: (next) => {
4870
+ if (!next) service.close();
4871
+ },
4872
+ children: jsx(DialogContent, {
4873
+ presentation: "fullscreen",
4874
+ showClose: false,
4875
+ children: jsxs("div", {
4876
+ ...part("settings", "root"),
4877
+ className: "snap-settings",
4878
+ children: [jsxs("header", {
4879
+ ...part("settings", "header"),
4880
+ className: "snap-settings-header",
4881
+ children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
4882
+ style: {
4883
+ display: "flex",
4884
+ alignItems: "center",
4885
+ gap: 4
4886
+ },
4887
+ children: [jsx(IconButton, {
4888
+ icon: jsx(GearIcon, {}),
4889
+ label: "配置插件源",
4890
+ onClick: () => setFeedOpen(true)
4891
+ }), jsx(IconButton, {
4892
+ icon: jsx(CloseIcon, {}),
4893
+ label: "关闭",
4894
+ onClick: () => service.close()
4895
+ })]
4896
+ })]
4897
+ }), jsxs("div", {
4898
+ ...part("settings", "body"),
4899
+ className: "snap-settings-body",
4900
+ children: [jsx("nav", {
4901
+ ...part("settings", "nav"),
4902
+ className: "snap-settings-nav",
4903
+ "aria-label": "设置页",
4904
+ children: [...groups.entries()].map(([group, entries]) => jsxs("div", {
4905
+ ...part("settings", "group"),
4906
+ className: "snap-settings-group",
4907
+ children: [jsx("div", {
4908
+ ...part("settings", "group-title"),
4909
+ className: "snap-settings-group-title",
4910
+ children: group
4911
+ }), entries.map((page) => jsxs("button", {
4912
+ type: "button",
4913
+ ...part("settings", "nav-item"),
4914
+ className: cn("snap-settings-nav-item", page.id === activeId && "is-active"),
4915
+ "data-active": page.id === activeId || void 0,
4916
+ "aria-current": page.id === activeId ? "page" : void 0,
4917
+ onClick: () => service.open(page.id),
4918
+ children: [page.icon !== void 0 && jsx("span", {
4919
+ ...part("settings", "nav-icon"),
4920
+ children: page.icon
4921
+ }), jsx("span", { children: page.title })]
4922
+ }, page.id))]
4923
+ }, group))
4924
+ }), jsx("main", {
4925
+ ...part("settings", "content"),
4926
+ className: "snap-settings-content",
4927
+ "data-active-page": activeId,
4928
+ children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
4929
+ page: active.id,
4930
+ children: active.render()
4931
+ })
4932
+ })]
4933
+ })]
4934
+ })
4935
+ })
4936
+ }), jsx(PluginFeedDialog, {
4937
+ ctx,
4938
+ open: feedOpen,
4939
+ onOpenChange: setFeedOpen
4940
+ })] });
4941
+ }
4942
+ /** Mount the settings registry and its default slot contributions. */
4943
+ const settingsPlugin = {
4944
+ name: "snap-rail settings",
4945
+ inject: ["ui"],
4946
+ apply(ctx) {
4947
+ const pages = /* @__PURE__ */ new Map();
4948
+ const listeners = /* @__PURE__ */ new Set();
4949
+ let open = false;
4950
+ let requestedId;
4951
+ let revision = 0;
4952
+ let seq = 0;
4953
+ const notify = (kind) => {
4954
+ revision += 1;
4955
+ for (const listener of listeners) listener();
4956
+ ctx.emit(kind === "pages" ? "settings/pages-changed" : "settings/open-changed");
4957
+ };
4958
+ const firstId = () => orderedPages(pages.values())[0]?.id;
4959
+ const activeId = () => {
4960
+ if (!open) return void 0;
4961
+ if (requestedId !== void 0 && pages.has(requestedId)) return requestedId;
4962
+ return firstId();
4963
+ };
4964
+ const service = {
4965
+ registerPage(caller, page) {
4966
+ pages.set(page.id, {
4967
+ page,
4968
+ seq: seq++
4969
+ });
4970
+ notify("pages");
4971
+ const remove = () => {
4972
+ if (pages.delete(page.id)) notify("pages");
4973
+ };
4974
+ caller.effect(() => remove);
4975
+ return remove;
4976
+ },
4977
+ listPages: () => orderedPages(pages.values()),
4978
+ open(pageId) {
4979
+ if (pageId !== void 0) requestedId = pageId;
4980
+ if (open && pageId === void 0) return;
4981
+ open = true;
4982
+ notify("open");
4983
+ },
4984
+ close() {
4985
+ if (!open) return;
4986
+ open = false;
4987
+ notify("open");
4988
+ },
4989
+ toggle() {
4990
+ if (open) service.close();
4991
+ else service.open();
4992
+ },
4993
+ isOpen: () => open,
4994
+ activePage: activeId,
4995
+ subscribe(listener) {
4996
+ listeners.add(listener);
4997
+ return () => {
4998
+ listeners.delete(listener);
4999
+ };
5000
+ },
5001
+ version: () => revision
5002
+ };
5003
+ ctx.provide("settings", service);
5004
+ ctx.settings.registerPage(ctx, {
5005
+ id: "plugins",
5006
+ title: "插件管理",
5007
+ group: "系统",
5008
+ order: 0,
5009
+ keywords: [
5010
+ "安装",
5011
+ "启用",
5012
+ "卸载",
5013
+ "驱动",
5014
+ "皮肤"
5015
+ ],
5016
+ render: () => jsx(PluginsPage, { ctx })
5017
+ });
5018
+ ctx.settings.registerPage(ctx, {
5019
+ id: "appearance",
5020
+ title: "外观与显示",
5021
+ group: "系统",
5022
+ order: 1,
5023
+ keywords: [
5024
+ "主题",
5025
+ "皮肤",
5026
+ "窗口",
5027
+ "悬浮球",
5028
+ "尺寸"
5029
+ ],
5030
+ render: () => jsx(AppearancePage, {})
5031
+ });
5032
+ ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsEntry, {
5033
+ id: "settings.default-entry",
5034
+ order: 0,
5035
+ render: (context) => jsx(SettingsEntry, {
5036
+ presentation: context.presentation,
5037
+ open: context.open,
5038
+ isOpen: context.isOpen
5039
+ })
5040
+ });
5041
+ ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
5042
+ id: "settings.default-surface",
5043
+ order: 0,
5044
+ render: () => jsx(SettingsSurface, {
5045
+ service,
5046
+ ctx
5047
+ })
5048
+ });
5049
+ }
5050
+ };
5051
+ /** The settings page info the slot context exposes. */
5052
+ function settingsPageInfo(page) {
5053
+ return {
5054
+ id: page.id,
5055
+ title: page.title,
5056
+ ...page.group !== void 0 ? { group: page.group } : {},
5057
+ order: page.order
5058
+ };
5059
+ }
5060
+ //#endregion
5061
+ //#region lib/types/runtime.js
5062
+ /**
5063
+ * The built-in renderer runtime: it takes over the kernel root, mounts the
5064
+ * core services, the skins, the layout/page plugins, and finally the fallback
5065
+ * layout. There is no framework row and no framework seed: the substrate is
5066
+ * always present, so a fresh install has a usable UI before any plugin is
5067
+ * installed.
5068
+ *
5069
+ * @module @snap-rail/ui/runtime
5070
+ */
5071
+ /** The React context carrying the host link/surface into builtin pages. */
5072
+ const ClientContext = createContext(null);
5073
+ /** Provide the client services to builtin page components. */
5074
+ function ClientProvider(props) {
5075
+ return jsx(ClientContext.Provider, {
5076
+ value: props.service,
5077
+ children: props.children
5078
+ });
5079
+ }
5080
+ /** Read the client services (host link + surface) from a builtin page. */
5081
+ function useClient() {
5082
+ const service = useContext(ClientContext);
5083
+ if (service === null) throw new Error("useClient: no ClientProvider in the tree");
5084
+ return service;
5085
+ }
5086
+ /**
5087
+ * Wire an element as a ball face's single drag/click surface. Past the travel
5088
+ * threshold the face only signals `shell.ball.move` `begin`/`end`; the host
5089
+ * anchors the grab from the OS cursor and runs the dock settle, so the face
5090
+ * never streams coordinates. A press-release inside the threshold is the
5091
+ * click. Returns the disposer removing every listener.
5092
+ */
5093
+ const attachBallDrag = attachBallDrag$1;
5094
+ /** Re-render on settings open/page changes. */
5095
+ function useSettingsVersion(ctx) {
5096
+ return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
5097
+ }
5098
+ /** Apply the active layout's stage profiles to the host. */
5099
+ function StageProfiles(props) {
5100
+ const link = props.ctx.client.link;
5101
+ const layout = props.layout;
5102
+ useEffect(() => {
5103
+ if (layout?.window !== void 0) link.call("shell.window.configure", { profile: layout.window }).catch(() => {});
5104
+ if (layout?.ball !== void 0) link.call("shell.ball.configure", { profile: layout.ball }).catch(() => {});
5105
+ }, [layout?.id]);
5106
+ return null;
5107
+ }
5108
+ /** The global overlay host: registry-owned surfaces do not depend on a layout. */
5109
+ function OverlayHost(props) {
5110
+ useUiVersion(props.ctx.ui);
5111
+ useSettingsVersion(props.ctx);
5112
+ const overlays = props.ctx.ui.list(UI_SLOT_IDS.overlay);
5113
+ const settingsSurfaces = props.ctx.settings.isOpen() ? props.ctx.ui.list(UI_SLOT_IDS.settingsSurface) : [];
5114
+ const context = {
5115
+ pages: props.ctx.settings.listPages().map((page) => ({
5116
+ id: page.id,
5117
+ title: page.title,
5118
+ ...page.group !== void 0 ? { group: page.group } : {},
5119
+ order: page.order
5120
+ })),
5121
+ ...props.ctx.settings.activePage() !== void 0 ? { activeId: props.ctx.settings.activePage() } : {},
5122
+ close: () => props.ctx.settings.close()
5123
+ };
5124
+ return jsxs(Fragment, { children: [overlays.map((item) => jsx("span", { children: item.render({ surface: "main" }) }, item.id)), settingsSurfaces.map((item) => jsx("span", { children: item.render(context) }, item.id))] });
5125
+ }
5126
+ /** The floating settings fallback, rendered only when no layout provides the seat. */
5127
+ function SettingsFallbackHost(props) {
5128
+ useUiVersion(props.ctx.ui);
5129
+ useSettingsVersion(props.ctx);
5130
+ if (props.ctx.ui.hasProvider(UI_SLOT_IDS.settingsEntry)) return null;
5131
+ const entry = props.ctx.ui.list(UI_SLOT_IDS.settingsEntry)[0];
5132
+ if (entry === void 0) return null;
5133
+ return jsx("div", {
5134
+ "data-snap-part": "settings.fallback",
5135
+ style: {
5136
+ position: "fixed",
5137
+ right: 16,
5138
+ bottom: 16,
5139
+ zIndex: "var(--snap-z-overlay)"
5140
+ },
5141
+ children: entry.render({
5142
+ presentation: "icon",
5143
+ open: () => props.ctx.settings.open(),
5144
+ isOpen: props.ctx.settings.isOpen()
5145
+ })
5146
+ });
5147
+ }
5148
+ /** The operator-window root. */
5149
+ function MainRoot(props) {
5150
+ const layout = useActiveLayout();
5151
+ return jsx(Fragment, { children: jsxs(TooltipProvider, { children: [
5152
+ jsx(StageProfiles, {
5153
+ ctx: props.ctx,
5154
+ layout
5155
+ }),
5156
+ layout === void 0 ? jsx("div", {
5157
+ style: { padding: 24 },
5158
+ children: "没有已加载的布局插件。"
5159
+ }) : layout.render(),
5160
+ jsx(OverlayHost, { ctx: props.ctx }),
5161
+ jsx(SettingsFallbackHost, { ctx: props.ctx }),
5162
+ jsx(Toaster, {})
5163
+ ] }) });
5164
+ }
5165
+ /**
5166
+ * The fallback ball face used when no plugin occupies `shell.ball`: a themed
5167
+ * disc that follows the active skin tokens (visible on any colour mode). The
5168
+ * whole ball is one drag/click surface ({@link attachBallDrag}): press-move
5169
+ * drags the window over `shell.ball.move`, a press-release summons the
5170
+ * operator window — the same anatomy the kernel's crash fallback paints.
5171
+ */
5172
+ function BallRoot(props) {
5173
+ useUiVersion(props.ctx.ui);
5174
+ const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
5175
+ const link = props.ctx.client.link;
5176
+ const hasOccupant = occupant !== void 0;
5177
+ const rootRef = useRef(null);
5178
+ useEffect(() => {
5179
+ if (hasOccupant) return void 0;
5180
+ const element = rootRef.current;
5181
+ if (element === null) return void 0;
5182
+ return attachBallDrag(element, {
5183
+ link,
5184
+ onClick: () => {
5185
+ link.call("shell.surface.present", { surface: "main" });
5186
+ }
5187
+ });
5188
+ }, [hasOccupant, link]);
5189
+ if (occupant !== void 0) return jsxs(TooltipProvider, { children: [jsx("div", {
5190
+ style: {
5191
+ width: "100%",
5192
+ height: "100%"
5193
+ },
5194
+ children: occupant.render({ surface: "ball" })
5195
+ }), jsx(Toaster, {})] });
5196
+ return jsx("div", {
5197
+ ref: rootRef,
5198
+ "data-snap-part": "ball.root",
5199
+ style: {
5200
+ display: "flex",
5201
+ alignItems: "center",
5202
+ justifyContent: "center",
5203
+ width: "100%",
5204
+ height: "100%"
5205
+ },
5206
+ children: jsx("div", {
5207
+ "data-snap-part": "ball.orb",
5208
+ style: {
5209
+ display: "flex",
5210
+ alignItems: "center",
5211
+ justifyContent: "center",
5212
+ width: "calc(100% - 16px)",
5213
+ height: "calc(100% - 16px)",
5214
+ borderRadius: "50%",
5215
+ background: "var(--snap-color-surface-raised)",
5216
+ border: "var(--snap-border-width) solid var(--snap-color-border)"
5217
+ },
5218
+ children: jsx("button", {
5219
+ type: "button",
5220
+ "data-snap-part": "ball.core",
5221
+ title: "打开主窗口",
5222
+ style: {
5223
+ width: "calc(100% - 16px)",
5224
+ height: "calc(100% - 16px)",
5225
+ borderRadius: "50%",
5226
+ border: "none",
5227
+ background: "var(--snap-color-surface)",
5228
+ color: "var(--snap-color-text)",
5229
+ fontSize: "var(--snap-text-xs)",
5230
+ fontWeight: "var(--snap-weight-medium)",
5231
+ cursor: "default"
5232
+ },
5233
+ children: "snap-rail"
5234
+ })
5235
+ })
5236
+ });
5237
+ }
5238
+ /** The root that mounts the layout (or the ball face) and the global overlays. */
5239
+ function UiRoot(props) {
5240
+ return jsx(ClientProvider, {
5241
+ service: props.ctx.client,
5242
+ children: jsx(UiProvider, {
5243
+ service: props.ctx.ui,
5244
+ children: jsx(SkinsProvider, {
5245
+ service: props.ctx.skins,
5246
+ children: props.surface === "main" ? jsx(MainRoot, { ctx: props.ctx }) : jsx(BallRoot, { ctx: props.ctx })
5247
+ })
5248
+ })
5249
+ });
5250
+ }
5251
+ /**
5252
+ * Take over the kernel root and mount the UI substrate.
5253
+ *
5254
+ * @param handle - the kernel boot result.
5255
+ * @param options - see {@link RuntimeOptions}.
5256
+ */
5257
+ async function createClientRuntime(handle, options) {
5258
+ const surface = options.surface ?? "main";
5259
+ const ctx = new Context();
5260
+ ctx.provide("client", {
5261
+ link: handle.link,
5262
+ surface
5263
+ });
5264
+ await ctx.plugin(TimerService);
5265
+ await ctx.plugin(slotsPlugin);
5266
+ await ctx.plugin(pagesPlugin);
5267
+ await ctx.plugin(skinsPlugin);
5268
+ await ctx.plugin(settingsPlugin);
5269
+ const applyThemeRow = (value) => {
5270
+ const row = value;
5271
+ const selection = typeof row?.id === "string" && row.id !== "" ? row.id : row?.mode === "light" ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
5272
+ if (!ctx.skins.activate(selection)) ctx.skins.activate(DEFAULT_DARK_ID);
5273
+ };
5274
+ handle.link.call("settings.get", { key: "ui.theme" }).then((result) => {
5275
+ if (result.ok) applyThemeRow(result.value.value);
5276
+ }).catch(() => {});
5277
+ const dropTheme = subscribeFrame(handle.link, "settings/changed", settingsChangedSchema, (change) => {
5278
+ if (change.key === "ui.theme") applyThemeRow(change.value);
5279
+ });
5280
+ const dropOpenSettings = subscribeFrame(handle.link, "shell/settings-open-requested", shellContract.frames["shell/settings-open-requested"], () => {
5281
+ ctx.settings.open();
5282
+ });
5283
+ ctx.effect(() => () => {
5284
+ dropTheme();
5285
+ dropOpenSettings();
5286
+ });
5287
+ for (const page of options.builtinPages ?? []) ctx.settings.registerPage(ctx, page);
5288
+ for (const seat of options.plugins) {
5289
+ const spec = "plugin" in seat ? seat : { plugin: seat };
5290
+ const plugin = spec.plugin;
5291
+ await ctx.plugin(plugin, spec.config === void 0 ? {} : spec.config);
5292
+ }
5293
+ if (surface === "main") await ctx.plugin(fallbackPlugin);
5294
+ handle.root.unmount();
5295
+ const shellRoot = createRoot(handle.element);
5296
+ shellRoot.render(jsx(UiRoot, {
5297
+ ctx,
5298
+ surface
5299
+ }));
5300
+ return {
5301
+ ctx,
5302
+ dispose: () => ctx.fiber.dispose().then(() => {
5303
+ shellRoot.unmount();
5304
+ })
5305
+ };
5306
+ }
5307
+ //#endregion
5308
+ export { Alert, AlertDescription, AlertTitle, AppShell, Badge, Button, CUSTOM_SLOT_PATTERN, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartFrame, Checkbox, ClientProvider, Combobox, Controller, DEFAULT_DARK, DEFAULT_DARK_ID, DEFAULT_LIGHT, DEFAULT_LIGHT_ID, 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, SettingsEntry, SettingsSurface, Sheet, Skeleton, SkinsProvider, Slider, Slot, 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, UI_COMPONENTS, UI_DIAGNOSTIC_KINDS, UI_PROFILES, UI_SLOT_IDS, UI_SLOT_MODES, UiProvider, Visualization, attachBallDrag, attachDragPan, chartThemeOf, cn, controlHeight, createClientRuntime, dismissToast, fallbackPlugin, isValidSlotId, literalValuesOf, pagesPlugin, part, schemaNodeOf, settingsPageInfo, settingsPlugin, skinTokenVar, skinsPlugin, slotsPlugin, space, toast, useActiveLayout, useChartTheme, useClient, useController, useFieldArray, useForm, useFormContext, useFormState, usePagesVersion, useSkinId, useSkinTokens, useSkins, useUi, useUiVersion, useWatch, zodResolver };