@snap-rail/ui 0.1.0 → 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 (49) hide show
  1. package/lib/charts.js +6 -29
  2. package/lib/contract.js +119 -78
  3. package/lib/fallback.js +11 -1
  4. package/lib/index.js +2466 -735
  5. package/lib/runtime.js +1552 -490
  6. package/lib/settings.js +1162 -244
  7. package/lib/skins.js +163 -189
  8. package/lib/types/charts.d.ts +1 -1
  9. package/lib/types/charts.js +5 -5
  10. package/lib/types/components/alert.d.ts +57 -0
  11. package/lib/types/components/alert.js +46 -0
  12. package/lib/types/components/controls.d.ts +74 -11
  13. package/lib/types/components/controls.js +60 -17
  14. package/lib/types/components/dialog.d.ts +5 -5
  15. package/lib/types/components/dialog.js +2 -2
  16. package/lib/types/components/form-rhf.d.ts +56 -0
  17. package/lib/types/components/form-rhf.js +74 -0
  18. package/lib/types/components/form.d.ts +33 -5
  19. package/lib/types/components/form.js +22 -6
  20. package/lib/types/components/index.d.ts +7 -0
  21. package/lib/types/components/index.js +7 -0
  22. package/lib/types/components/input.d.ts +16 -7
  23. package/lib/types/components/input.js +39 -9
  24. package/lib/types/components/layout.d.ts +32 -7
  25. package/lib/types/components/layout.js +88 -15
  26. package/lib/types/components/overlay.d.ts +95 -0
  27. package/lib/types/components/overlay.js +138 -0
  28. package/lib/types/components/schema-form.d.ts +16 -4
  29. package/lib/types/components/schema-form.js +69 -40
  30. package/lib/types/components/slider.d.ts +18 -0
  31. package/lib/types/components/slider.js +15 -0
  32. package/lib/types/contract.d.ts +49 -37
  33. package/lib/types/contract.js +49 -33
  34. package/lib/types/fallback.js +1 -1
  35. package/lib/types/runtime.d.ts +23 -1
  36. package/lib/types/runtime.js +77 -20
  37. package/lib/types/settings-pages/appearance.d.ts +6 -4
  38. package/lib/types/settings-pages/appearance.js +33 -36
  39. package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
  40. package/lib/types/settings-pages/plugin-feed.js +66 -0
  41. package/lib/types/settings-pages/plugins.d.ts +10 -5
  42. package/lib/types/settings-pages/plugins.js +284 -21
  43. package/lib/types/settings.d.ts +1 -0
  44. package/lib/types/settings.js +14 -8
  45. package/lib/types/skins.d.ts +38 -44
  46. package/lib/types/skins.js +172 -169
  47. package/package.json +16 -9
  48. package/src/styles/base.css +251 -5
  49. package/src/styles/default.css +315 -136
@@ -1,149 +1,147 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useSyncExternalStore } from 'react';
3
- import { PRESENTATION_TARGETS, } from "./contract.js";
4
- /** The two colour modes. */
5
- export const SKIN_MODES = ['light', 'dark'];
6
- /** The built-in default skin id. */
7
- export const DEFAULT_SKIN_ID = 'default';
8
- /** The factory cobalt/steel skin. Extra skins override it through the registry. */
9
- export const DEFAULT_SKIN = {
10
- id: DEFAULT_SKIN_ID,
11
- title: '工业钴蓝',
12
- presentations: {
13
- dialog: 'modal',
14
- select: 'popover',
15
- tabs: 'inline',
16
- toast: 'inline',
17
- },
18
- tokens: {
19
- dark: {
20
- colorBg: '#0b0f14',
21
- colorSurface: '#11161d',
22
- colorSurfaceRaised: '#161b22',
23
- colorText: '#ced8e3',
24
- colorMuted: '#8b949e',
25
- colorPrimary: '#4a6cff',
26
- colorOnPrimary: '#ffffff',
27
- colorDanger: '#f85149',
28
- colorSuccess: '#3fb950',
29
- colorWarning: '#d29922',
30
- colorBorder: '#1f2933',
31
- colorFocus: '#4a6cff',
32
- chart1: '#4a6cff',
33
- chart2: '#3147a1',
34
- chart3: '#667fcd',
35
- chart4: '#7d8fa5',
36
- chart5: '#55677c',
37
- chart6: '#33414f',
38
- fontSans: 'system-ui, "Segoe UI", "Microsoft YaHei", sans-serif',
39
- fontMono: '"Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace',
40
- textXs: '13px',
41
- textSm: '15px',
42
- textMd: '17px',
43
- textLg: '20px',
44
- textXl: '24px',
45
- weightNormal: '400',
46
- weightMedium: '500',
47
- weightStrong: '600',
48
- leadingTight: '1.2',
49
- leadingNormal: '1.55',
50
- spaceXs: '4px',
51
- spaceSm: '8px',
52
- spaceMd: '12px',
53
- spaceLg: '20px',
54
- spaceXl: '32px',
55
- radiusSm: '6px',
56
- radiusMd: '8px',
57
- radiusLg: '12px',
58
- radiusFull: '999px',
59
- borderWidth: '1px',
60
- shadowSm: '0 1px 2px rgb(0 0 0 / 0.25)',
61
- shadowMd: '0 8px 24px rgb(0 0 0 / 0.28)',
62
- shadowLg: '0 24px 64px rgb(0 0 0 / 0.36)',
63
- durationFast: '120ms',
64
- durationNormal: '180ms',
65
- durationSlow: '280ms',
66
- easeStandard: 'cubic-bezier(0.2, 0, 0, 1)',
67
- zOverlay: '50',
68
- zModal: '60',
69
- zToast: '70',
70
- controlHeightSm: '40px',
71
- controlHeightMd: '48px',
72
- controlHeightLg: '56px',
73
- density: 'comfortable',
74
- },
75
- light: {
76
- colorBg: '#e4e9ef',
77
- colorSurface: '#f3f6f9',
78
- colorSurfaceRaised: '#ffffff',
79
- colorText: '#26323e',
80
- colorMuted: '#5d6d7e',
81
- colorPrimary: '#3857e8',
82
- colorOnPrimary: '#ffffff',
83
- colorDanger: '#dc2626',
84
- colorSuccess: '#15803d',
85
- colorWarning: '#b45309',
86
- colorBorder: '#c7d0da',
87
- colorFocus: '#3857e8',
88
- chart1: '#3857e8',
89
- chart2: '#7088ee',
90
- chart3: '#667dd0',
91
- chart4: '#94a3b8',
92
- chart5: '#b3c0cd',
93
- chart6: '#ccd6e0',
94
- fontSans: 'system-ui, "Segoe UI", "Microsoft YaHei", sans-serif',
95
- fontMono: '"Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace',
96
- textXs: '13px',
97
- textSm: '15px',
98
- textMd: '17px',
99
- textLg: '20px',
100
- textXl: '24px',
101
- weightNormal: '400',
102
- weightMedium: '500',
103
- weightStrong: '600',
104
- leadingTight: '1.2',
105
- leadingNormal: '1.55',
106
- spaceXs: '4px',
107
- spaceSm: '8px',
108
- spaceMd: '12px',
109
- spaceLg: '20px',
110
- spaceXl: '32px',
111
- radiusSm: '6px',
112
- radiusMd: '8px',
113
- radiusLg: '12px',
114
- radiusFull: '999px',
115
- borderWidth: '1px',
116
- shadowSm: '0 1px 2px rgb(0 0 0 / 0.08)',
117
- shadowMd: '0 8px 24px rgb(0 0 0 / 0.12)',
118
- shadowLg: '0 24px 64px rgb(0 0 0 / 0.18)',
119
- durationFast: '120ms',
120
- durationNormal: '180ms',
121
- durationSlow: '280ms',
122
- easeStandard: 'cubic-bezier(0.2, 0, 0, 1)',
123
- zOverlay: '50',
124
- zModal: '60',
125
- zToast: '70',
126
- controlHeightSm: '40px',
127
- controlHeightMd: '48px',
128
- controlHeightLg: '56px',
129
- density: 'comfortable',
130
- },
131
- },
3
+ /** The factory day theme id (cobalt palette, light surfaces). */
4
+ export const DEFAULT_LIGHT_ID = 'default-light';
5
+ /** The factory night theme id (cobalt palette, dark surfaces). */
6
+ export const DEFAULT_DARK_ID = 'default-dark';
7
+ /** The contributor label for the factory themes. */
8
+ const FACTORY_CALLER = '@snap-rail/ui';
9
+ const COBALT_DARK_TOKENS = {
10
+ colorBg: '#0b0f14',
11
+ colorSurface: '#11161d',
12
+ colorSurfaceRaised: '#161b22',
13
+ colorText: '#ced8e3',
14
+ colorMuted: '#8b949e',
15
+ colorPrimary: '#4a6cff',
16
+ colorOnPrimary: '#ffffff',
17
+ colorDanger: '#f85149',
18
+ colorSuccess: '#3fb950',
19
+ colorWarning: '#d29922',
20
+ colorBorder: '#1f2933',
21
+ colorFocus: '#4a6cff',
22
+ chart1: '#4a6cff',
23
+ chart2: '#3147a1',
24
+ chart3: '#667fcd',
25
+ chart4: '#7d8fa5',
26
+ chart5: '#55677c',
27
+ chart6: '#33414f',
28
+ fontSans: 'system-ui, "Segoe UI", "Microsoft YaHei", sans-serif',
29
+ fontMono: '"Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace',
30
+ textXs: '13px',
31
+ textSm: '15px',
32
+ textMd: '17px',
33
+ textLg: '20px',
34
+ textXl: '24px',
35
+ weightNormal: '400',
36
+ weightMedium: '500',
37
+ weightStrong: '600',
38
+ leadingTight: '1.2',
39
+ leadingNormal: '1.55',
40
+ spaceXs: '4px',
41
+ spaceSm: '8px',
42
+ spaceMd: '12px',
43
+ spaceLg: '20px',
44
+ spaceXl: '32px',
45
+ radiusSm: '6px',
46
+ radiusMd: '8px',
47
+ radiusLg: '12px',
48
+ radiusFull: '999px',
49
+ borderWidth: '1px',
50
+ shadowSm: '0 1px 2px rgb(0 0 0 / 0.25)',
51
+ shadowMd: '0 8px 24px rgb(0 0 0 / 0.28)',
52
+ shadowLg: '0 24px 64px rgb(0 0 0 / 0.36)',
53
+ durationFast: '120ms',
54
+ durationNormal: '180ms',
55
+ durationSlow: '280ms',
56
+ easeStandard: 'cubic-bezier(0.2, 0, 0, 1)',
57
+ zOverlay: '50',
58
+ zModal: '60',
59
+ zToast: '70',
60
+ controlHeightSm: '40px',
61
+ controlHeightMd: '48px',
62
+ controlHeightLg: '56px',
63
+ density: 'comfortable',
64
+ };
65
+ const COBALT_LIGHT_TOKENS = {
66
+ colorBg: '#e4e9ef',
67
+ colorSurface: '#f3f6f9',
68
+ colorSurfaceRaised: '#ffffff',
69
+ colorText: '#26323e',
70
+ colorMuted: '#5d6d7e',
71
+ colorPrimary: '#3857e8',
72
+ colorOnPrimary: '#ffffff',
73
+ colorDanger: '#dc2626',
74
+ colorSuccess: '#15803d',
75
+ colorWarning: '#b45309',
76
+ colorBorder: '#c7d0da',
77
+ colorFocus: '#3857e8',
78
+ chart1: '#3857e8',
79
+ chart2: '#7088ee',
80
+ chart3: '#667dd0',
81
+ chart4: '#94a3b8',
82
+ chart5: '#b3c0cd',
83
+ chart6: '#ccd6e0',
84
+ fontSans: 'system-ui, "Segoe UI", "Microsoft YaHei", sans-serif',
85
+ fontMono: '"Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace',
86
+ textXs: '13px',
87
+ textSm: '15px',
88
+ textMd: '17px',
89
+ textLg: '20px',
90
+ textXl: '24px',
91
+ weightNormal: '400',
92
+ weightMedium: '500',
93
+ weightStrong: '600',
94
+ leadingTight: '1.2',
95
+ leadingNormal: '1.55',
96
+ spaceXs: '4px',
97
+ spaceSm: '8px',
98
+ spaceMd: '12px',
99
+ spaceLg: '20px',
100
+ spaceXl: '32px',
101
+ radiusSm: '6px',
102
+ radiusMd: '8px',
103
+ radiusLg: '12px',
104
+ radiusFull: '999px',
105
+ borderWidth: '1px',
106
+ shadowSm: '0 1px 2px rgb(0 0 0 / 0.08)',
107
+ shadowMd: '0 8px 24px rgb(0 0 0 / 0.12)',
108
+ shadowLg: '0 24px 64px rgb(0 0 0 / 0.18)',
109
+ durationFast: '120ms',
110
+ durationNormal: '180ms',
111
+ durationSlow: '280ms',
112
+ easeStandard: 'cubic-bezier(0.2, 0, 0, 1)',
113
+ zOverlay: '50',
114
+ zModal: '60',
115
+ zToast: '70',
116
+ controlHeightSm: '40px',
117
+ controlHeightMd: '48px',
118
+ controlHeightLg: '56px',
119
+ density: 'comfortable',
120
+ };
121
+ /** The factory day theme. Always registered; never the first paint though — the night theme is. */
122
+ export const DEFAULT_LIGHT = {
123
+ id: DEFAULT_LIGHT_ID,
124
+ title: '钴蓝·白天',
125
+ tokens: COBALT_LIGHT_TOKENS,
126
+ };
127
+ /** The factory night theme and the registry's fallback. */
128
+ export const DEFAULT_DARK = {
129
+ id: DEFAULT_DARK_ID,
130
+ title: '钴蓝·黑夜',
131
+ tokens: COBALT_DARK_TOKENS,
132
132
  };
133
133
  /** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
134
134
  export function skinTokenVar(key) {
135
135
  const kebab = key.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`).replace(/(\d+)$/, '-$1');
136
136
  return `--snap-${kebab}`;
137
137
  }
138
- /** Apply the active skin to the document root. */
139
- function applySkin(skin, mode) {
138
+ /** Apply the active theme to the document root. */
139
+ function applySkin(skin) {
140
140
  if (typeof document === 'undefined')
141
141
  return;
142
142
  const root = document.documentElement;
143
143
  root.dataset['snapSkin'] = skin.id;
144
- root.dataset['snapMode'] = mode;
145
- const tokens = skin.tokens[mode];
146
- for (const [key, value] of Object.entries(tokens)) {
144
+ for (const [key, value] of Object.entries(skin.tokens)) {
147
145
  root.style.setProperty(skinTokenVar(key), value);
148
146
  }
149
147
  }
@@ -152,12 +150,15 @@ const skinsPlugin = {
152
150
  name: 'snap-rail ui skins',
153
151
  apply(ctx) {
154
152
  const skins = new Map();
153
+ const callers = new Map();
155
154
  const listeners = new Set();
156
155
  const styleTags = new Map();
157
- let activeId = DEFAULT_SKIN_ID;
158
- let mode = 'dark';
156
+ let activeId = DEFAULT_DARK_ID;
159
157
  let revision = 0;
160
- skins.set(DEFAULT_SKIN_ID, DEFAULT_SKIN);
158
+ skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
159
+ callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
160
+ skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
161
+ callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
161
162
  const notify = () => {
162
163
  revision += 1;
163
164
  for (const listener of listeners)
@@ -176,64 +177,68 @@ const skinsPlugin = {
176
177
  styleTags.set(skin.id, tag);
177
178
  };
178
179
  const refresh = () => {
179
- const skin = skins.get(activeId) ?? DEFAULT_SKIN;
180
+ const skin = skins.get(activeId) ?? DEFAULT_DARK;
180
181
  activeId = skin.id;
181
182
  ensureStyleTag(skin);
182
- applySkin(skin, mode);
183
+ applySkin(skin);
183
184
  notify();
184
185
  };
185
186
  ctx.provide('skins', {
186
187
  register(caller, skin) {
187
188
  skins.set(skin.id, skin);
188
- // A pool skin (non-default) becomes active immediately; the default
189
- // stays underneath as the fallback when the pool skin is removed.
190
- if (skin.id !== DEFAULT_SKIN_ID)
191
- activeId = skin.id;
189
+ callers.set(skin.id, caller.fiber.name);
190
+ // Registration only makes a theme selectable; activation stays with
191
+ // the operator's stored selection (applied by the runtime).
192
192
  refresh();
193
193
  const remove = () => {
194
194
  if (!skins.delete(skin.id))
195
195
  return;
196
+ callers.delete(skin.id);
196
197
  const tag = styleTags.get(skin.id);
197
198
  if (tag !== undefined) {
198
199
  tag.remove();
199
200
  styleTags.delete(skin.id);
200
201
  }
201
202
  if (activeId === skin.id)
202
- activeId = DEFAULT_SKIN_ID;
203
+ activeId = DEFAULT_DARK_ID;
203
204
  refresh();
204
205
  };
205
206
  caller.effect(() => remove);
206
207
  return remove;
207
208
  },
208
- activate(skinId) {
209
- if (!skins.has(skinId))
209
+ activate(selection) {
210
+ let next = skins.has(selection) ? selection : undefined;
211
+ if (next === undefined) {
212
+ for (const [id, owner] of callers) {
213
+ if (id !== selection && owner === selection && skins.has(id)) {
214
+ next = id;
215
+ break;
216
+ }
217
+ }
218
+ }
219
+ if (next === undefined)
210
220
  return false;
211
- activeId = skinId;
221
+ if (next === activeId)
222
+ return true;
223
+ activeId = next;
212
224
  refresh();
213
225
  return true;
214
226
  },
215
- list: () => [skins.get(DEFAULT_SKIN_ID) ?? DEFAULT_SKIN, ...[...skins.values()].filter(skin => skin.id !== DEFAULT_SKIN_ID)],
216
- active: () => skins.get(activeId) ?? DEFAULT_SKIN,
217
- setMode(next) {
218
- if (mode === next)
219
- return;
220
- mode = next;
221
- refresh();
222
- },
223
- mode: () => mode,
224
- presentation(target) {
225
- const skin = skins.get(activeId) ?? DEFAULT_SKIN;
226
- return skin.presentations?.[target];
227
- },
228
- tokens: () => (skins.get(activeId) ?? DEFAULT_SKIN).tokens[mode],
227
+ list: () => [...skins.values()].map(skin => ({
228
+ id: skin.id,
229
+ title: skin.title,
230
+ caller: callers.get(skin.id) ?? FACTORY_CALLER,
231
+ })),
232
+ active: () => skins.get(activeId) ?? DEFAULT_DARK,
233
+ tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
229
234
  subscribe(listener) {
230
235
  listeners.add(listener);
231
236
  return () => { listeners.delete(listener); };
232
237
  },
233
238
  version: () => revision,
234
239
  });
235
- // Apply the factory skin immediately so the first paint already carries
236
- // the token vocabulary, even before any plugin registers.
240
+ // Apply the factory night theme immediately so the first paint already
241
+ // carries the token vocabulary, even before any plugin registers.
237
242
  refresh();
238
243
  },
239
244
  };
@@ -250,19 +255,17 @@ export function useSkins() {
250
255
  throw new Error('useSkins: no SkinsProvider in the tree');
251
256
  return service;
252
257
  }
253
- /** Re-render on skin/mode changes and return the active token set. */
258
+ /** Re-render on theme changes and return the active token set. */
254
259
  export function useSkinTokens() {
255
260
  const service = useSkins();
256
261
  useSyncExternalStore(service.subscribe, service.version, service.version);
257
262
  return service.tokens();
258
263
  }
259
- /** Re-render on skin/mode changes and return the active presentation default. */
260
- export function usePresentation(target) {
264
+ /** Re-render on theme changes and return the active theme id. */
265
+ export function useSkinId() {
261
266
  const service = useSkins();
262
267
  useSyncExternalStore(service.subscribe, service.version, service.version);
263
- return service.presentation(target);
268
+ return service.active().id;
264
269
  }
265
- /** Re-export the presentation vocabulary for skin authors. */
266
- export { PRESENTATION_TARGETS };
267
270
  export default skinsPlugin;
268
271
  //# sourceMappingURL=skins.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snap-rail/ui",
3
3
  "description": "The built-in UI substrate: semantic components, typed region slots, skins, settings and renderer runtime",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -62,25 +62,32 @@
62
62
  ],
63
63
  "license": "Apache-2.0",
64
64
  "dependencies": {
65
+ "@hookform/resolvers": "^7.0.2",
65
66
  "@radix-ui/react-checkbox": "^1.1.3",
66
67
  "@radix-ui/react-dialog": "^1.1.6",
68
+ "@radix-ui/react-dropdown-menu": "^2.2.1",
67
69
  "@radix-ui/react-label": "^2.1.2",
70
+ "@radix-ui/react-popover": "^1.3.1",
68
71
  "@radix-ui/react-radio-group": "^1.2.3",
69
72
  "@radix-ui/react-scroll-area": "^1.2.18",
70
73
  "@radix-ui/react-select": "^2.2.6",
74
+ "@radix-ui/react-separator": "^1.2.0",
75
+ "@radix-ui/react-slider": "^1.6.1",
71
76
  "@radix-ui/react-slot": "^1.3.3",
72
77
  "@radix-ui/react-switch": "^1.3.7",
73
78
  "@radix-ui/react-tabs": "^1.1.13",
74
- "@radix-ui/react-tooltip": "^1.2.16"
79
+ "@radix-ui/react-toast": "^1.3.1",
80
+ "@radix-ui/react-tooltip": "^1.2.16",
81
+ "react-hook-form": "^7.91.0"
75
82
  },
76
83
  "peerDependencies": {
77
84
  "react": ">=19",
78
85
  "react-dom": ">=19",
79
86
  "zod": "^4.4.3",
80
87
  "@snap-rail/connection": "^0.1.0",
81
- "@snap-rail/protocol": "^0.1.3",
82
88
  "@snap-rail/cordis": "^4.0.3",
83
- "@snap-rail/shell": "^0.2.2"
89
+ "@snap-rail/protocol": "^0.1.3",
90
+ "@snap-rail/shell": "^0.2.3"
84
91
  },
85
92
  "devDependencies": {
86
93
  "@types/react": "^19.2.14",
@@ -92,14 +99,14 @@
92
99
  "typescript": "^6.0.3",
93
100
  "vitest": "^4.1.8",
94
101
  "zod": "^4.4.3",
95
- "@snap-rail/client-kernel": "^0.1.2",
96
- "@snap-rail/app-boot": "^0.1.3",
97
102
  "@snap-rail/connection": "^0.1.0",
98
- "@snap-rail/cordis-plugin-timer": "^1.1.3",
99
103
  "@snap-rail/cordis": "^4.0.3",
104
+ "@snap-rail/app-boot": "^0.1.3",
105
+ "@snap-rail/cordis-plugin-timer": "^1.1.3",
106
+ "@snap-rail/client-kernel": "^0.1.2",
100
107
  "@snap-rail/protocol": "^0.1.3",
101
- "@snap-rail/shell": "^0.2.2",
102
- "@snap-rail/station-rpc": "^0.1.0"
108
+ "@snap-rail/station-rpc": "^0.1.0",
109
+ "@snap-rail/shell": "^0.2.3"
103
110
  },
104
111
  "snapRail": {
105
112
  "layer": "base",