@snap-rail/ui 0.0.0-stage → 0.1.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 (60) hide show
  1. package/LICENSE +202 -0
  2. package/lib/charts.js +142 -0
  3. package/lib/contract.js +543 -0
  4. package/lib/fallback.js +400 -0
  5. package/lib/index.js +3345 -0
  6. package/lib/pages.js +68 -0
  7. package/lib/runtime.js +2064 -0
  8. package/lib/settings.js +1195 -0
  9. package/lib/skins.js +284 -0
  10. package/lib/slots.js +267 -0
  11. package/lib/types/charts.d.ts +62 -0
  12. package/lib/types/charts.js +41 -0
  13. package/lib/types/components/button.d.ts +39 -0
  14. package/lib/types/components/button.js +27 -0
  15. package/lib/types/components/controls.d.ts +66 -0
  16. package/lib/types/components/controls.js +66 -0
  17. package/lib/types/components/dialog.d.ts +58 -0
  18. package/lib/types/components/dialog.js +46 -0
  19. package/lib/types/components/feedback.d.ts +46 -0
  20. package/lib/types/components/feedback.js +20 -0
  21. package/lib/types/components/form.d.ts +31 -0
  22. package/lib/types/components/form.js +13 -0
  23. package/lib/types/components/index.d.ts +15 -0
  24. package/lib/types/components/index.js +15 -0
  25. package/lib/types/components/input.d.ts +37 -0
  26. package/lib/types/components/input.js +15 -0
  27. package/lib/types/components/layout.d.ts +100 -0
  28. package/lib/types/components/layout.js +80 -0
  29. package/lib/types/components/schema-form.d.ts +34 -0
  30. package/lib/types/components/schema-form.js +61 -0
  31. package/lib/types/components/surface.d.ts +49 -0
  32. package/lib/types/components/surface.js +59 -0
  33. package/lib/types/contract.d.ts +358 -0
  34. package/lib/types/contract.js +235 -0
  35. package/lib/types/fallback.d.ts +14 -0
  36. package/lib/types/fallback.js +50 -0
  37. package/lib/types/index.d.ts +19 -0
  38. package/lib/types/index.js +19 -0
  39. package/lib/types/pages.d.ts +40 -0
  40. package/lib/types/pages.js +69 -0
  41. package/lib/types/runtime.d.ts +71 -0
  42. package/lib/types/runtime.js +177 -0
  43. package/lib/types/settings-pages/appearance.d.ts +13 -0
  44. package/lib/types/settings-pages/appearance.js +131 -0
  45. package/lib/types/settings-pages/index.d.ts +3 -0
  46. package/lib/types/settings-pages/index.js +3 -0
  47. package/lib/types/settings-pages/plugins.d.ts +16 -0
  48. package/lib/types/settings-pages/plugins.js +109 -0
  49. package/lib/types/settings.d.ts +58 -0
  50. package/lib/types/settings.js +170 -0
  51. package/lib/types/skins.d.ts +143 -0
  52. package/lib/types/skins.js +268 -0
  53. package/lib/types/slots.d.ts +69 -0
  54. package/lib/types/slots.js +210 -0
  55. package/lib/types/utils.d.ts +15 -0
  56. package/lib/types/utils.js +26 -0
  57. package/package.json +105 -3
  58. package/src/styles/base.css +321 -0
  59. package/src/styles/default.css +734 -0
  60. package/README.md +0 -3
package/lib/skins.js ADDED
@@ -0,0 +1,284 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useSyncExternalStore } from "react";
3
+ //#region lib/types/contract.js
4
+ /** The stable region slots every layout may provide. */
5
+ const UI_SLOT_IDS = {
6
+ /** The one active layout of the operator window. */
7
+ layout: "shell.layout",
8
+ /** The operator titlebar. */
9
+ titlebar: "shell.titlebar",
10
+ /** Contributed titlebar actions. */
11
+ titlebarActions: "shell.titlebar.actions",
12
+ /** Sidebar extension area. */
13
+ sidebar: "shell.sidebar",
14
+ /** Statusbar extension area. */
15
+ statusbar: "shell.statusbar",
16
+ /** The global overlay stack (dialogs, confirms). */
17
+ overlay: "shell.overlay",
18
+ /** The floating ball surface face. */
19
+ ball: "shell.ball",
20
+ /** The settings trigger. */
21
+ settingsEntry: "settings.entry",
22
+ /** The settings surface itself. */
23
+ settingsSurface: "settings.surface"
24
+ };
25
+ UI_SLOT_IDS.layout, UI_SLOT_IDS.titlebar, UI_SLOT_IDS.titlebarActions, UI_SLOT_IDS.sidebar, UI_SLOT_IDS.statusbar, UI_SLOT_IDS.overlay, UI_SLOT_IDS.ball, UI_SLOT_IDS.settingsEntry, UI_SLOT_IDS.settingsSurface;
26
+ /** The presentation targets a skin may tune. */
27
+ const PRESENTATION_TARGETS = [
28
+ "dialog",
29
+ "select",
30
+ "tabs",
31
+ "toast"
32
+ ];
33
+ //#endregion
34
+ //#region lib/types/skins.js
35
+ /** The two colour modes. */
36
+ const SKIN_MODES = ["light", "dark"];
37
+ /** The built-in default skin id. */
38
+ const DEFAULT_SKIN_ID = "default";
39
+ /** The factory cobalt/steel skin. Extra skins override it through the registry. */
40
+ const DEFAULT_SKIN = {
41
+ id: DEFAULT_SKIN_ID,
42
+ title: "工业钴蓝",
43
+ presentations: {
44
+ dialog: "modal",
45
+ select: "popover",
46
+ tabs: "inline",
47
+ toast: "inline"
48
+ },
49
+ tokens: {
50
+ dark: {
51
+ colorBg: "#0b0f14",
52
+ colorSurface: "#11161d",
53
+ colorSurfaceRaised: "#161b22",
54
+ colorText: "#ced8e3",
55
+ colorMuted: "#8b949e",
56
+ colorPrimary: "#4a6cff",
57
+ colorOnPrimary: "#ffffff",
58
+ colorDanger: "#f85149",
59
+ colorSuccess: "#3fb950",
60
+ colorWarning: "#d29922",
61
+ colorBorder: "#1f2933",
62
+ colorFocus: "#4a6cff",
63
+ chart1: "#4a6cff",
64
+ chart2: "#3147a1",
65
+ chart3: "#667fcd",
66
+ chart4: "#7d8fa5",
67
+ chart5: "#55677c",
68
+ chart6: "#33414f",
69
+ fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
70
+ fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
71
+ textXs: "13px",
72
+ textSm: "15px",
73
+ textMd: "17px",
74
+ textLg: "20px",
75
+ textXl: "24px",
76
+ weightNormal: "400",
77
+ weightMedium: "500",
78
+ weightStrong: "600",
79
+ leadingTight: "1.2",
80
+ leadingNormal: "1.55",
81
+ spaceXs: "4px",
82
+ spaceSm: "8px",
83
+ spaceMd: "12px",
84
+ spaceLg: "20px",
85
+ spaceXl: "32px",
86
+ radiusSm: "6px",
87
+ radiusMd: "8px",
88
+ radiusLg: "12px",
89
+ radiusFull: "999px",
90
+ borderWidth: "1px",
91
+ shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
92
+ shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
93
+ shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
94
+ durationFast: "120ms",
95
+ durationNormal: "180ms",
96
+ durationSlow: "280ms",
97
+ easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
98
+ zOverlay: "50",
99
+ zModal: "60",
100
+ zToast: "70",
101
+ controlHeightSm: "40px",
102
+ controlHeightMd: "48px",
103
+ controlHeightLg: "56px",
104
+ density: "comfortable"
105
+ },
106
+ light: {
107
+ colorBg: "#e4e9ef",
108
+ colorSurface: "#f3f6f9",
109
+ colorSurfaceRaised: "#ffffff",
110
+ colorText: "#26323e",
111
+ colorMuted: "#5d6d7e",
112
+ colorPrimary: "#3857e8",
113
+ colorOnPrimary: "#ffffff",
114
+ colorDanger: "#dc2626",
115
+ colorSuccess: "#15803d",
116
+ colorWarning: "#b45309",
117
+ colorBorder: "#c7d0da",
118
+ colorFocus: "#3857e8",
119
+ chart1: "#3857e8",
120
+ chart2: "#7088ee",
121
+ chart3: "#667dd0",
122
+ chart4: "#94a3b8",
123
+ chart5: "#b3c0cd",
124
+ chart6: "#ccd6e0",
125
+ fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
126
+ fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
127
+ textXs: "13px",
128
+ textSm: "15px",
129
+ textMd: "17px",
130
+ textLg: "20px",
131
+ textXl: "24px",
132
+ weightNormal: "400",
133
+ weightMedium: "500",
134
+ weightStrong: "600",
135
+ leadingTight: "1.2",
136
+ leadingNormal: "1.55",
137
+ spaceXs: "4px",
138
+ spaceSm: "8px",
139
+ spaceMd: "12px",
140
+ spaceLg: "20px",
141
+ spaceXl: "32px",
142
+ radiusSm: "6px",
143
+ radiusMd: "8px",
144
+ radiusLg: "12px",
145
+ radiusFull: "999px",
146
+ borderWidth: "1px",
147
+ shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
148
+ shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
149
+ shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
150
+ durationFast: "120ms",
151
+ durationNormal: "180ms",
152
+ durationSlow: "280ms",
153
+ easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
154
+ zOverlay: "50",
155
+ zModal: "60",
156
+ zToast: "70",
157
+ controlHeightSm: "40px",
158
+ controlHeightMd: "48px",
159
+ controlHeightLg: "56px",
160
+ density: "comfortable"
161
+ }
162
+ }
163
+ };
164
+ /** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
165
+ function skinTokenVar(key) {
166
+ return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
167
+ }
168
+ /** Apply the active skin to the document root. */
169
+ function applySkin(skin, mode) {
170
+ if (typeof document === "undefined") return;
171
+ const root = document.documentElement;
172
+ root.dataset["snapSkin"] = skin.id;
173
+ root.dataset["snapMode"] = mode;
174
+ const tokens = skin.tokens[mode];
175
+ for (const [key, value] of Object.entries(tokens)) root.style.setProperty(skinTokenVar(key), value);
176
+ }
177
+ /** Mount the `ctx.skins` registry. */
178
+ const skinsPlugin = {
179
+ name: "snap-rail ui skins",
180
+ apply(ctx) {
181
+ const skins = /* @__PURE__ */ new Map();
182
+ const listeners = /* @__PURE__ */ new Set();
183
+ const styleTags = /* @__PURE__ */ new Map();
184
+ let activeId = DEFAULT_SKIN_ID;
185
+ let mode = "dark";
186
+ let revision = 0;
187
+ skins.set(DEFAULT_SKIN_ID, DEFAULT_SKIN);
188
+ const notify = () => {
189
+ revision += 1;
190
+ for (const listener of listeners) listener();
191
+ ctx.emit("skins/changed");
192
+ };
193
+ const ensureStyleTag = (skin) => {
194
+ if (typeof document === "undefined" || skin.css === void 0) return;
195
+ if (styleTags.has(skin.id)) return;
196
+ const tag = document.createElement("style");
197
+ tag.dataset["snapSkinStyle"] = skin.id;
198
+ tag.textContent = skin.css;
199
+ document.head.append(tag);
200
+ styleTags.set(skin.id, tag);
201
+ };
202
+ const refresh = () => {
203
+ const skin = skins.get(activeId) ?? DEFAULT_SKIN;
204
+ activeId = skin.id;
205
+ ensureStyleTag(skin);
206
+ applySkin(skin, mode);
207
+ notify();
208
+ };
209
+ ctx.provide("skins", {
210
+ register(caller, skin) {
211
+ skins.set(skin.id, skin);
212
+ if (skin.id !== "default") activeId = skin.id;
213
+ refresh();
214
+ const remove = () => {
215
+ if (!skins.delete(skin.id)) return;
216
+ const tag = styleTags.get(skin.id);
217
+ if (tag !== void 0) {
218
+ tag.remove();
219
+ styleTags.delete(skin.id);
220
+ }
221
+ if (activeId === skin.id) activeId = DEFAULT_SKIN_ID;
222
+ refresh();
223
+ };
224
+ caller.effect(() => remove);
225
+ return remove;
226
+ },
227
+ activate(skinId) {
228
+ if (!skins.has(skinId)) return false;
229
+ activeId = skinId;
230
+ refresh();
231
+ return true;
232
+ },
233
+ list: () => [skins.get("default") ?? DEFAULT_SKIN, ...[...skins.values()].filter((skin) => skin.id !== DEFAULT_SKIN_ID)],
234
+ active: () => skins.get(activeId) ?? DEFAULT_SKIN,
235
+ setMode(next) {
236
+ if (mode === next) return;
237
+ mode = next;
238
+ refresh();
239
+ },
240
+ mode: () => mode,
241
+ presentation(target) {
242
+ return (skins.get(activeId) ?? DEFAULT_SKIN).presentations?.[target];
243
+ },
244
+ tokens: () => (skins.get(activeId) ?? DEFAULT_SKIN).tokens[mode],
245
+ subscribe(listener) {
246
+ listeners.add(listener);
247
+ return () => {
248
+ listeners.delete(listener);
249
+ };
250
+ },
251
+ version: () => revision
252
+ });
253
+ refresh();
254
+ }
255
+ };
256
+ /** The React context carrying the skin service. */
257
+ const SkinsContext = createContext(null);
258
+ /** Provide the skin service to a renderer tree. */
259
+ function SkinsProvider(props) {
260
+ return jsx(SkinsContext.Provider, {
261
+ value: props.service,
262
+ children: props.children
263
+ });
264
+ }
265
+ /** Read the skin service. */
266
+ function useSkins() {
267
+ const service = useContext(SkinsContext);
268
+ if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
269
+ return service;
270
+ }
271
+ /** Re-render on skin/mode changes and return the active token set. */
272
+ function useSkinTokens() {
273
+ const service = useSkins();
274
+ useSyncExternalStore(service.subscribe, service.version, service.version);
275
+ return service.tokens();
276
+ }
277
+ /** Re-render on skin/mode changes and return the active presentation default. */
278
+ function usePresentation(target) {
279
+ const service = useSkins();
280
+ useSyncExternalStore(service.subscribe, service.version, service.version);
281
+ return service.presentation(target);
282
+ }
283
+ //#endregion
284
+ export { DEFAULT_SKIN, DEFAULT_SKIN_ID, PRESENTATION_TARGETS, SKIN_MODES, SkinsProvider, skinsPlugin as default, skinTokenVar, usePresentation, useSkinTokens, useSkins };
package/lib/slots.js ADDED
@@ -0,0 +1,267 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { Component, createContext, useContext, useSyncExternalStore } from "react";
3
+ //#region lib/types/contract.js
4
+ /** The stable region slots every layout may provide. */
5
+ const UI_SLOT_IDS = {
6
+ /** The one active layout of the operator window. */
7
+ layout: "shell.layout",
8
+ /** The operator titlebar. */
9
+ titlebar: "shell.titlebar",
10
+ /** Contributed titlebar actions. */
11
+ titlebarActions: "shell.titlebar.actions",
12
+ /** Sidebar extension area. */
13
+ sidebar: "shell.sidebar",
14
+ /** Statusbar extension area. */
15
+ statusbar: "shell.statusbar",
16
+ /** The global overlay stack (dialogs, confirms). */
17
+ overlay: "shell.overlay",
18
+ /** The floating ball surface face. */
19
+ ball: "shell.ball",
20
+ /** The settings trigger. */
21
+ settingsEntry: "settings.entry",
22
+ /** The settings surface itself. */
23
+ settingsSurface: "settings.surface"
24
+ };
25
+ /** A named custom slot is owned by a publisher package. */
26
+ const CUSTOM_SLOT_PATTERN = /^custom:[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*$/;
27
+ /** Check a region-slot id at runtime. */
28
+ function isValidSlotId(value) {
29
+ return Object.values(UI_SLOT_IDS).includes(value) || CUSTOM_SLOT_PATTERN.test(value);
30
+ }
31
+ /** The occupancy mode of every built-in slot. */
32
+ const UI_SLOT_MODES = {
33
+ [UI_SLOT_IDS.layout]: "one",
34
+ [UI_SLOT_IDS.titlebar]: "one",
35
+ [UI_SLOT_IDS.titlebarActions]: "many",
36
+ [UI_SLOT_IDS.sidebar]: "many",
37
+ [UI_SLOT_IDS.statusbar]: "many",
38
+ [UI_SLOT_IDS.overlay]: "many",
39
+ [UI_SLOT_IDS.ball]: "one",
40
+ [UI_SLOT_IDS.settingsEntry]: "one",
41
+ [UI_SLOT_IDS.settingsSurface]: "one"
42
+ };
43
+ //#endregion
44
+ //#region lib/types/slots.js
45
+ const MAX_DIAGNOSTICS = 100;
46
+ /** The default definition of a built-in slot. */
47
+ function builtinDefinition(slot) {
48
+ return {
49
+ id: slot,
50
+ mode: UI_SLOT_MODES[slot] ?? "many"
51
+ };
52
+ }
53
+ /** Mount the `ctx.ui` registry. */
54
+ const slotsPlugin = {
55
+ name: "snap-rail ui slots",
56
+ apply(ctx) {
57
+ const entries = /* @__PURE__ */ new Map();
58
+ const layouts = /* @__PURE__ */ new Map();
59
+ const listeners = /* @__PURE__ */ new Set();
60
+ const diagnostics = [];
61
+ let revision = 0;
62
+ let layoutSeq = 0;
63
+ for (const slot of Object.values(UI_SLOT_IDS)) entries.set(slot, {
64
+ def: builtinDefinition(slot),
65
+ contributions: /* @__PURE__ */ new Map(),
66
+ nextSeq: 0
67
+ });
68
+ const notify = (slot) => {
69
+ revision += 1;
70
+ for (const listener of listeners) listener();
71
+ ctx.emit("ui/changed");
72
+ if (slot !== void 0) ctx.emit("ui/slot-changed", slot);
73
+ };
74
+ const diagnose = (diagnostic) => {
75
+ diagnostics.push({
76
+ ...diagnostic,
77
+ time: Date.now()
78
+ });
79
+ if (diagnostics.length > MAX_DIAGNOSTICS) diagnostics.shift();
80
+ };
81
+ const activeLayoutOf = () => {
82
+ return [...layouts.values()].sort((a, b) => {
83
+ const pa = a.layout.precedence ?? 0;
84
+ return (b.layout.precedence ?? 0) - pa || a.layout.order - b.layout.order || b.seq - a.seq;
85
+ })[0]?.layout;
86
+ };
87
+ const ensureEntry = (slot) => {
88
+ const existing = entries.get(slot);
89
+ if (existing !== void 0) return existing;
90
+ const entry = {
91
+ def: {
92
+ id: slot,
93
+ mode: "many"
94
+ },
95
+ contributions: /* @__PURE__ */ new Map(),
96
+ nextSeq: 0
97
+ };
98
+ entries.set(slot, entry);
99
+ return entry;
100
+ };
101
+ ctx.provide("ui", {
102
+ defineSlot(caller, def) {
103
+ if (!isValidSlotId(def.id)) {
104
+ diagnose({
105
+ kind: "unknown-slot",
106
+ slot: def.id,
107
+ message: `插槽 id 不合法:${def.id}`
108
+ });
109
+ return () => {};
110
+ }
111
+ if (Object.values(UI_SLOT_IDS).includes(def.id)) {
112
+ diagnose({
113
+ kind: "duplicate-id",
114
+ slot: def.id,
115
+ message: `内置插槽不能被重新定义:${def.id}`
116
+ });
117
+ return () => {};
118
+ }
119
+ const entry = ensureEntry(def.id);
120
+ entry.def = def;
121
+ notify(def.id);
122
+ const remove = () => {
123
+ if (entries.delete(def.id)) notify(def.id);
124
+ };
125
+ caller.effect(() => remove);
126
+ return remove;
127
+ },
128
+ registerLayout(caller, layout) {
129
+ for (const slot of layout.provides) if (!isValidSlotId(slot)) diagnose({
130
+ kind: "unknown-slot",
131
+ id: layout.id,
132
+ slot,
133
+ message: `布局 ${layout.id} 声明了非法插槽:${slot}`
134
+ });
135
+ else if (!entries.has(slot)) diagnose({
136
+ kind: "unknown-slot",
137
+ id: layout.id,
138
+ slot,
139
+ message: `布局 ${layout.id} 声明了未定义的插槽:${slot}`
140
+ });
141
+ layouts.set(layout.id, {
142
+ layout,
143
+ seq: layoutSeq++
144
+ });
145
+ notify();
146
+ const remove = () => {
147
+ if (layouts.delete(layout.id)) notify();
148
+ };
149
+ caller.effect(() => remove);
150
+ return remove;
151
+ },
152
+ contribute(caller, slot, contribution) {
153
+ if (!isValidSlotId(slot)) {
154
+ diagnose({
155
+ kind: "unknown-slot",
156
+ id: contribution.id,
157
+ slot,
158
+ message: `贡献 ${contribution.id} 指向非法插槽:${slot}`
159
+ });
160
+ return () => {};
161
+ }
162
+ const entry = entries.get(slot);
163
+ if (entry === void 0) diagnose({
164
+ kind: "unknown-slot",
165
+ id: contribution.id,
166
+ slot,
167
+ message: `贡献 ${contribution.id} 指向未定义的插槽:${slot}`
168
+ });
169
+ const target = entry ?? ensureEntry(slot);
170
+ target.contributions.set(contribution.id, {
171
+ contribution,
172
+ seq: target.nextSeq++
173
+ });
174
+ notify(slot);
175
+ const remove = () => {
176
+ if (target.contributions.delete(contribution.id)) notify(slot);
177
+ };
178
+ caller.effect(() => remove);
179
+ return remove;
180
+ },
181
+ list(slot) {
182
+ const entry = entries.get(slot);
183
+ if (entry === void 0) return [];
184
+ const ranked = [...entry.contributions.values()].sort((a, b) => a.contribution.order - b.contribution.order || a.seq - b.seq);
185
+ if (entry.def.mode !== "one" || ranked.length === 0) return ranked.map((item) => item.contribution);
186
+ return [ranked.reduce((best, item) => {
187
+ const delta = (item.contribution.precedence ?? 0) - (best.contribution.precedence ?? 0);
188
+ return delta > 0 || delta === 0 && item.seq > best.seq ? item : best;
189
+ }).contribution];
190
+ },
191
+ definition: (slot) => entries.get(slot)?.def,
192
+ activeLayout: activeLayoutOf,
193
+ hasProvider(slot) {
194
+ const active = activeLayoutOf();
195
+ return active !== void 0 && active.provides.includes(slot);
196
+ },
197
+ diagnostics: () => diagnostics,
198
+ subscribe(listener) {
199
+ listeners.add(listener);
200
+ return () => {
201
+ listeners.delete(listener);
202
+ };
203
+ },
204
+ version: () => revision
205
+ });
206
+ }
207
+ };
208
+ /** The React context carrying the active UI service. */
209
+ const UiContext = createContext(null);
210
+ /** Provide the UI service to a slot tree. */
211
+ function UiProvider(props) {
212
+ return jsx(UiContext.Provider, {
213
+ value: props.service,
214
+ children: props.children
215
+ });
216
+ }
217
+ /** Read the UI service; throws when a slot tree is mounted outside the runtime. */
218
+ function useUi() {
219
+ const service = useContext(UiContext);
220
+ if (service === null) throw new Error("useUi: no UiProvider in the tree");
221
+ return service;
222
+ }
223
+ /** Re-render on every registry change. */
224
+ function useUiVersion(service) {
225
+ return useSyncExternalStore(service.subscribe, service.version, service.version);
226
+ }
227
+ /** Keep one broken contribution from taking down the whole shell. */
228
+ var SlotBoundary = class extends Component {
229
+ state = { failed: false };
230
+ static getDerivedStateFromError() {
231
+ return { failed: true };
232
+ }
233
+ componentDidCatch(error) {
234
+ this.props.onError(error);
235
+ }
236
+ render() {
237
+ return this.state.failed ? null : this.props.children;
238
+ }
239
+ };
240
+ /** A region-slot outlet rendered by a layout. */
241
+ function Slot(props) {
242
+ const service = useUi();
243
+ useUiVersion(service);
244
+ const provided = service.hasProvider(props.name);
245
+ const entry = service.list(props.name);
246
+ const def = service.definition(props.name);
247
+ const context = props.context ?? {};
248
+ if (!provided) return null;
249
+ if (entry.length === 0) {
250
+ const fallback = def?.fallback;
251
+ return fallback?.(context) ?? null;
252
+ }
253
+ return jsx(Fragment, { children: entry.map((item) => jsx(SlotBoundary, {
254
+ onError: (error) => {
255
+ console.error(`[snap-rail ui] slot ${props.name} contribution ${item.id} failed`, error);
256
+ },
257
+ children: item.render(context)
258
+ }, item.id)) });
259
+ }
260
+ /** Re-render when the active layout changes. */
261
+ function useActiveLayout() {
262
+ const service = useUi();
263
+ useUiVersion(service);
264
+ return service.activeLayout();
265
+ }
266
+ //#endregion
267
+ export { Slot, UiProvider, slotsPlugin as default, useActiveLayout, useUi, useUiVersion };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The visualization bridge: semantic frame around any third-party chart
3
+ * library, plus token-derived themes. The skin owns the frame, title,
4
+ * toolbar and palette; the chart library owns its internal DOM.
5
+ *
6
+ * @module @snap-rail/ui/charts
7
+ */
8
+ import type { CSSProperties, ReactNode } from 'react';
9
+ import { type SkinTokens } from './skins.tsx';
10
+ /** The chart lifecycle state the frame renders around the child. */
11
+ export type ChartState = 'ready' | 'loading' | 'empty' | 'error';
12
+ /** Props of {@link ChartFrame}. */
13
+ export interface ChartFrameProps {
14
+ title?: ReactNode;
15
+ description?: ReactNode;
16
+ actions?: ReactNode;
17
+ state?: ChartState;
18
+ empty?: ReactNode;
19
+ error?: ReactNode;
20
+ loading?: ReactNode;
21
+ children?: ReactNode;
22
+ className?: string;
23
+ style?: CSSProperties;
24
+ }
25
+ /** A semantic frame for a chart, gauge, map, or custom visualization. */
26
+ export declare function ChartFrame({ title, description, actions, state, empty, error, loading, children, className, style, }: ChartFrameProps): ReactNode;
27
+ /** A chart frame that exposes the `visualization.*` anatomy as well. */
28
+ export declare function Visualization(props: ChartFrameProps): ReactNode;
29
+ /** The theme object ECharts/D3 adapters can consume. */
30
+ export interface ChartTheme {
31
+ color: readonly string[];
32
+ backgroundColor: string;
33
+ textStyle: {
34
+ color: string;
35
+ fontFamily: string;
36
+ fontSize: number;
37
+ };
38
+ axisLine: {
39
+ lineStyle: {
40
+ color: string;
41
+ };
42
+ };
43
+ splitLine: {
44
+ lineStyle: {
45
+ color: string;
46
+ type: 'dashed';
47
+ };
48
+ };
49
+ tooltip: {
50
+ backgroundColor: string;
51
+ borderColor: string;
52
+ textStyle: {
53
+ color: string;
54
+ fontFamily: string;
55
+ };
56
+ };
57
+ }
58
+ /** Turn the active skin tokens into a chart-library theme. */
59
+ export declare function chartThemeOf(tokens: SkinTokens): ChartTheme;
60
+ /** The active chart theme, re-derived whenever the skin/mode changes. */
61
+ export declare function useChartTheme(): ChartTheme;
62
+ //# sourceMappingURL=charts.d.ts.map
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn, part } from "./utils.js";
3
+ import { useSkinTokens } from "./skins.js";
4
+ /** A semantic frame for a chart, gauge, map, or custom visualization. */
5
+ export function ChartFrame({ title, description, actions, state = 'ready', empty, error, loading, children, className, style, }) {
6
+ return (_jsxs("section", { ...part('chart-frame', 'root'), className: cn('snap-chart-frame', className), "data-state": state, style: style, children: [(title !== undefined || description !== undefined || actions !== undefined) && (_jsxs("header", { ...part('chart-frame', 'header'), className: "snap-chart-frame-header", children: [_jsxs("div", { children: [title !== undefined && _jsx("div", { ...part('chart-frame', 'title'), children: title }), description !== undefined && _jsx("div", { className: "snap-chart-frame-description", children: description })] }), actions !== undefined && _jsx("div", { ...part('chart-frame', 'actions'), children: actions })] })), _jsx("div", { ...part('chart-frame', 'body'), className: "snap-chart-frame-body", "data-state": state, children: state === 'loading'
7
+ ? loading ?? _jsx("div", { ...part('visualization', 'loading'), children: "\u52A0\u8F7D\u4E2D\u2026" })
8
+ : state === 'empty'
9
+ ? empty ?? _jsx("div", { ...part('visualization', 'empty'), children: "\u6682\u65E0\u6570\u636E" })
10
+ : state === 'error'
11
+ ? error ?? _jsx("div", { ...part('visualization', 'error'), role: "alert", children: "\u56FE\u8868\u52A0\u8F7D\u5931\u8D25" })
12
+ : children })] }));
13
+ }
14
+ /** A chart frame that exposes the `visualization.*` anatomy as well. */
15
+ export function Visualization(props) {
16
+ return _jsx(ChartFrame, { ...props });
17
+ }
18
+ /** Turn the active skin tokens into a chart-library theme. */
19
+ export function chartThemeOf(tokens) {
20
+ return {
21
+ color: [tokens.chart1, tokens.chart2, tokens.chart3, tokens.chart4, tokens.chart5, tokens.chart6],
22
+ backgroundColor: tokens.colorSurface,
23
+ textStyle: {
24
+ color: tokens.colorText,
25
+ fontFamily: tokens.fontSans,
26
+ fontSize: Number.parseInt(tokens.textSm, 10) || 14,
27
+ },
28
+ axisLine: { lineStyle: { color: tokens.colorBorder } },
29
+ splitLine: { lineStyle: { color: tokens.colorBorder, type: 'dashed' } },
30
+ tooltip: {
31
+ backgroundColor: tokens.colorSurfaceRaised,
32
+ borderColor: tokens.colorBorder,
33
+ textStyle: { color: tokens.colorText, fontFamily: tokens.fontSans },
34
+ },
35
+ };
36
+ }
37
+ /** The active chart theme, re-derived whenever the skin/mode changes. */
38
+ export function useChartTheme() {
39
+ return chartThemeOf(useSkinTokens());
40
+ }
41
+ //# sourceMappingURL=charts.js.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
3
+ * `button.root`, `button.label`, `button.icon`, and `button.spinner` parts;
4
+ * intent/emphasis/size are data attributes a skin styles.
5
+ *
6
+ * @module @snap-rail/ui/components/button
7
+ */
8
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
9
+ /** The semantic emphasis of a button. */
10
+ export type ButtonIntent = 'neutral' | 'primary' | 'danger' | 'success' | 'warning';
11
+ /** How strongly the intent is expressed. */
12
+ export type ButtonEmphasis = 'solid' | 'soft' | 'outline' | 'ghost' | 'link';
13
+ /** The control size. */
14
+ export type ButtonSize = 'sm' | 'md' | 'lg';
15
+ /** Props of {@link Button}. */
16
+ export interface ButtonProps extends Omit<ComponentPropsWithoutRef<'button'>, 'color'> {
17
+ intent?: ButtonIntent;
18
+ emphasis?: ButtonEmphasis;
19
+ size?: ButtonSize;
20
+ loading?: boolean;
21
+ icon?: ReactNode;
22
+ iconPosition?: 'start' | 'end';
23
+ asChild?: boolean;
24
+ }
25
+ /** A spinner that inherits the current text colour. */
26
+ export declare function Spinner(props: {
27
+ className?: string;
28
+ }): ReactNode;
29
+ /** A themed button; `asChild` composes the behaviour onto a child element. */
30
+ export declare function Button({ intent, emphasis, size, loading, icon, iconPosition, asChild, disabled, className, children, type, ...props }: ButtonProps): ReactNode;
31
+ /** An icon-only button; `label` is required for accessibility. */
32
+ export interface IconButtonProps extends Omit<ButtonProps, 'children' | 'icon' | 'iconPosition'> {
33
+ icon: ReactNode;
34
+ label: string;
35
+ active?: boolean;
36
+ }
37
+ /** A square glyph button with a mandatory accessible label. */
38
+ export declare function IconButton({ icon, label, active, intent, emphasis, size, className, ...props }: IconButtonProps): ReactNode;
39
+ //# sourceMappingURL=button.d.ts.map