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