@snap-rail/ui 0.1.0 → 0.1.1
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.
- package/lib/charts.js +1 -25
- package/lib/contract.js +1 -17
- package/lib/fallback.js +0 -1
- package/lib/index.js +797 -2860
- package/lib/runtime.js +1406 -467
- package/lib/settings.js +1100 -226
- package/lib/skins.js +163 -189
- package/lib/types/components/dialog.d.ts +5 -5
- package/lib/types/components/dialog.js +2 -2
- package/lib/types/components/input.d.ts +7 -4
- package/lib/types/components/input.js +9 -6
- package/lib/types/components/layout.d.ts +4 -1
- package/lib/types/components/layout.js +2 -2
- package/lib/types/components/schema-form.d.ts +13 -3
- package/lib/types/components/schema-form.js +25 -2
- package/lib/types/contract.d.ts +0 -8
- package/lib/types/contract.js +0 -4
- package/lib/types/fallback.js +1 -1
- package/lib/types/runtime.d.ts +23 -1
- package/lib/types/runtime.js +74 -18
- package/lib/types/settings-pages/appearance.d.ts +6 -4
- package/lib/types/settings-pages/appearance.js +33 -36
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +10 -5
- package/lib/types/settings-pages/plugins.js +284 -21
- package/lib/types/settings.d.ts +1 -0
- package/lib/types/settings.js +14 -8
- package/lib/types/skins.d.ts +38 -44
- package/lib/types/skins.js +172 -169
- package/package.json +6 -6
- package/src/styles/base.css +8 -0
- package/src/styles/default.css +137 -136
package/lib/types/skins.js
CHANGED
|
@@ -1,149 +1,147 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useSyncExternalStore } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
|
139
|
-
function applySkin(skin
|
|
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
|
-
|
|
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 =
|
|
158
|
-
let mode = 'dark';
|
|
156
|
+
let activeId = DEFAULT_DARK_ID;
|
|
159
157
|
let revision = 0;
|
|
160
|
-
skins.set(
|
|
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) ??
|
|
180
|
+
const skin = skins.get(activeId) ?? DEFAULT_DARK;
|
|
180
181
|
activeId = skin.id;
|
|
181
182
|
ensureStyleTag(skin);
|
|
182
|
-
applySkin(skin
|
|
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
|
-
|
|
189
|
-
//
|
|
190
|
-
|
|
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 =
|
|
203
|
+
activeId = DEFAULT_DARK_ID;
|
|
203
204
|
refresh();
|
|
204
205
|
};
|
|
205
206
|
caller.effect(() => remove);
|
|
206
207
|
return remove;
|
|
207
208
|
},
|
|
208
|
-
activate(
|
|
209
|
-
|
|
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
|
-
|
|
221
|
+
if (next === activeId)
|
|
222
|
+
return true;
|
|
223
|
+
activeId = next;
|
|
212
224
|
refresh();
|
|
213
225
|
return true;
|
|
214
226
|
},
|
|
215
|
-
list: () => [
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
|
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
|
|
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
|
|
260
|
-
export function
|
|
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.
|
|
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.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
"react-dom": ">=19",
|
|
79
79
|
"zod": "^4.4.3",
|
|
80
80
|
"@snap-rail/connection": "^0.1.0",
|
|
81
|
-
"@snap-rail/protocol": "^0.1.3",
|
|
82
81
|
"@snap-rail/cordis": "^4.0.3",
|
|
83
|
-
"@snap-rail/
|
|
82
|
+
"@snap-rail/protocol": "^0.1.3",
|
|
83
|
+
"@snap-rail/shell": "^0.2.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/react": "^19.2.14",
|
|
@@ -92,13 +92,13 @@
|
|
|
92
92
|
"typescript": "^6.0.3",
|
|
93
93
|
"vitest": "^4.1.8",
|
|
94
94
|
"zod": "^4.4.3",
|
|
95
|
-
"@snap-rail/client-kernel": "^0.1.2",
|
|
96
95
|
"@snap-rail/app-boot": "^0.1.3",
|
|
97
96
|
"@snap-rail/connection": "^0.1.0",
|
|
98
|
-
"@snap-rail/
|
|
97
|
+
"@snap-rail/client-kernel": "^0.1.2",
|
|
99
98
|
"@snap-rail/cordis": "^4.0.3",
|
|
99
|
+
"@snap-rail/cordis-plugin-timer": "^1.1.3",
|
|
100
100
|
"@snap-rail/protocol": "^0.1.3",
|
|
101
|
-
"@snap-rail/shell": "^0.2.
|
|
101
|
+
"@snap-rail/shell": "^0.2.3",
|
|
102
102
|
"@snap-rail/station-rpc": "^0.1.0"
|
|
103
103
|
},
|
|
104
104
|
"snapRail": {
|
package/src/styles/base.css
CHANGED
|
@@ -121,6 +121,13 @@
|
|
|
121
121
|
cursor: pointer;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/* The switch thumb travels by the skin's translateX along the track, which
|
|
125
|
+
* measures from the content edge: centering would strand the off-state
|
|
126
|
+
* thumb mid-track and shove the on-state thumb past the track edge. */
|
|
127
|
+
[data-snap-part='switch.root'] {
|
|
128
|
+
justify-content: flex-start;
|
|
129
|
+
}
|
|
130
|
+
|
|
124
131
|
.snap-switch-label,
|
|
125
132
|
.snap-checkbox-label {
|
|
126
133
|
display: inline-flex;
|
|
@@ -139,6 +146,7 @@
|
|
|
139
146
|
|
|
140
147
|
[data-snap-part='tabs.list'] {
|
|
141
148
|
display: inline-flex;
|
|
149
|
+
flex-wrap: wrap;
|
|
142
150
|
align-items: center;
|
|
143
151
|
gap: var(--snap-space-xs);
|
|
144
152
|
}
|