@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,8 +1,17 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import '@snap-rail/app-boot/contract';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
2
  import { rpcErrorText } from '@snap-rail/connection';
4
3
  import { useEffect, useState } from 'react';
5
- import { Badge, Button, EmptyState, Page, Section, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
4
+ import { Alert, Badge, Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, EmptyState, IconButton, Input, Page, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
5
+ /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
6
+ * Electron or in tests. Inlined rather than imported from the app-internal
7
+ * kernel package: it never ships in the installer, and the packaged-app gate
8
+ * refuses any shipped `@snap-rail/ui` lib that requires it. */
9
+ function droppedZipPath(file) {
10
+ const zipPathOf = globalThis.snapRail?.zipPathOf;
11
+ if (typeof zipPathOf !== 'function')
12
+ return null;
13
+ return zipPathOf(file);
14
+ }
6
15
  /** Human labels for the package kinds. */
7
16
  const KIND_LABELS = {
8
17
  skin: '界面风格',
@@ -15,6 +24,12 @@ const PROFILE_LABELS = {
15
24
  integrated: '图表桥接',
16
25
  custom: '自定义界面',
17
26
  };
27
+ /** Search rows shown before the tail is folded into a counter. */
28
+ const SEARCH_ROW_CAP = 20;
29
+ /** The plus glyph for the page's install entry. */
30
+ function PlusIcon() {
31
+ return (_jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "2.4", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M12 5v14M5 12h14" }) }));
32
+ }
18
33
  /** Collapse entry rows into package rows (one master switch per package). */
19
34
  function packageRows(plugins) {
20
35
  const byPackage = new Map();
@@ -41,15 +56,43 @@ function packageRows(plugins) {
41
56
  }
42
57
  return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
43
58
  }
59
+ /** The preview's signature line (one row in the confirm card). */
60
+ function signatureText(signature, viaUrl) {
61
+ if (signature.state === 'verified') {
62
+ return { text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`, warning: false };
63
+ }
64
+ const detail = signature.keyId !== undefined ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : '⚠ 未签名';
65
+ return { text: viaUrl ? `${detail} · 直链无完整性校验` : detail, warning: true };
66
+ }
67
+ /** Does the input name an http(s) address? */
68
+ const isHttpUrl = (text) => /^https?:\/\//i.test(text);
69
+ /** Does the input look like a filesystem path (drive letter, UNC, posix
70
+ * root, or a .zip name with a separator in it)? */
71
+ const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith('\\\\') || text.startsWith('/')
72
+ || (/\.zip$/i.test(text) && /[/\\]/.test(text));
44
73
  /** The plugin management page. */
45
74
  export function PluginsPage({ ctx }) {
46
75
  const [rows, setRows] = useState([]);
47
76
  const [error, setError] = useState(undefined);
48
77
  const [busy, setBusy] = useState(undefined);
49
78
  const [touched, setTouched] = useState(new Set());
79
+ const [restartNeeded, setRestartNeeded] = useState(false);
80
+ // The install pipeline: the tri-form dialog, its search results, and the
81
+ // inspect→confirm→install phase machine (mirrors the kernel recovery page).
82
+ const [installOpen, setInstallOpen] = useState(false);
83
+ const [phase, setPhase] = useState({ kind: 'idle' });
84
+ const [message, setMessage] = useState(undefined);
85
+ const [updates, setUpdates] = useState(new Map());
86
+ const [updatingName, setUpdatingName] = useState(undefined);
87
+ const [keyChange, setKeyChange] = useState(undefined);
88
+ const [query, setQuery] = useState('');
89
+ const [searchResults, setSearchResults] = useState(undefined);
90
+ const [searching, setSearching] = useState(false);
91
+ const [dragging, setDragging] = useState(false);
92
+ const link = ctx.client.link;
50
93
  const load = () => {
51
94
  setError(undefined);
52
- void ctx.client.link.call('plugins.list', {}).then(result => {
95
+ void link.call('plugins.list', {}).then(result => {
53
96
  if (!result.ok) {
54
97
  setError(rpcErrorText(result.error));
55
98
  return;
@@ -58,11 +101,32 @@ export function PluginsPage({ ctx }) {
58
101
  }).catch(cause => {
59
102
  setError(cause instanceof Error ? cause.message : String(cause));
60
103
  });
104
+ void link.call('plugins.updates-check', {}).then(result => {
105
+ if (result.ok)
106
+ setUpdates(new Map(result.value.updates.map(update => [update.name, update])));
107
+ }).catch(() => undefined);
108
+ };
109
+ useEffect(() => {
110
+ load();
111
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
+ }, [link]);
113
+ const openInstall = () => {
114
+ setQuery('');
115
+ setSearchResults(undefined);
116
+ setMessage(undefined);
117
+ setDragging(false);
118
+ setInstallOpen(true);
119
+ };
120
+ const closeInstall = () => {
121
+ setInstallOpen(false);
122
+ setQuery('');
123
+ setSearchResults(undefined);
124
+ setMessage(undefined);
125
+ setDragging(false);
61
126
  };
62
- useEffect(load, []);
63
127
  const toggle = (row, enabled) => {
64
128
  setBusy(row.packageName);
65
- void ctx.client.link.call('plugins.set-enabled', { name: row.packageName, enabled })
129
+ void link.call('plugins.set-enabled', { name: row.packageName, enabled })
66
130
  .then(result => {
67
131
  if (!result.ok) {
68
132
  setError(rpcErrorText(result.error));
@@ -78,32 +142,231 @@ export function PluginsPage({ ctx }) {
78
142
  if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`))
79
143
  return;
80
144
  setBusy(row.packageName);
81
- void ctx.client.link.call('plugins.uninstall', { name: row.packageName })
145
+ void link.call('plugins.uninstall', { name: row.packageName })
82
146
  .then(result => {
83
147
  if (!result.ok) {
84
148
  setError(rpcErrorText(result.error));
85
149
  return;
86
150
  }
87
151
  setTouched(current => new Set(current).add(row.packageName));
152
+ setRestartNeeded(true);
88
153
  load();
89
154
  })
90
155
  .catch(cause => { setError(cause instanceof Error ? cause.message : String(cause)); })
91
156
  .finally(() => { setBusy(undefined); });
92
157
  };
93
- const groups = new Map();
94
- for (const row of rows) {
95
- const bucket = groups.get(row.category);
96
- if (bucket === undefined)
97
- groups.set(row.category, [row]);
98
- else
99
- bucket.push(row);
158
+ const inspectPath = (zipPath) => {
159
+ setMessage(undefined);
160
+ void link.call('plugins.inspect', { zipPath }).then(result => {
161
+ if (!result.ok) {
162
+ setPhase({ kind: 'error', message: `读取插件包失败:${rpcErrorText(result.error)}` });
163
+ return;
164
+ }
165
+ setPhase({ kind: 'confirm', zipPath, archive: result.value.archive, viaUrl: false, risk: false });
166
+ }).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
167
+ };
168
+ const inspectFromUrl = (url) => {
169
+ setMessage(undefined);
170
+ void link.call('plugins.inspect-from-url', { url }).then(result => {
171
+ if (!result.ok) {
172
+ setPhase({ kind: 'error', message: `下载或读取插件包失败:${rpcErrorText(result.error)}` });
173
+ return;
174
+ }
175
+ setPhase({ kind: 'confirm', zipPath: result.value.zipPath, archive: result.value.archive, viaUrl: true, risk: false });
176
+ }).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
177
+ };
178
+ const runInstall = (zipPath, archive) => {
179
+ setPhase({ kind: 'installing' });
180
+ const call = archive.kind === 'combo'
181
+ ? link.call('plugins.install-combo', { zipPath })
182
+ : link.call('plugins.install', { zipPath });
183
+ void call.then(result => {
184
+ if (!result.ok) {
185
+ setPhase({ kind: 'error', message: `安装失败:${rpcErrorText(result.error)}` });
186
+ return;
187
+ }
188
+ setPhase({ kind: 'idle' });
189
+ closeInstall();
190
+ setRestartNeeded(true);
191
+ load();
192
+ }).catch(cause => setPhase({ kind: 'error', message: String(cause) }));
193
+ };
194
+ /** The update pill's click: a plain update installs directly; a key
195
+ * change confirmation intercepts first. */
196
+ const requestUpdate = (update) => {
197
+ if (update.keyChanged === true) {
198
+ setKeyChange(update);
199
+ return;
200
+ }
201
+ updateNow(update.name);
202
+ };
203
+ /** The update itself: the feed's entry, no preview. */
204
+ const updateNow = (name) => {
205
+ setKeyChange(undefined);
206
+ setUpdatingName(name);
207
+ setMessage(undefined);
208
+ void link.call('plugins.remote-install', { name }).then(result => {
209
+ setUpdatingName(undefined);
210
+ if (!result.ok) {
211
+ setMessage({ kind: 'error', text: rpcErrorText(result.error) });
212
+ return;
213
+ }
214
+ setRestartNeeded(true);
215
+ load();
216
+ }).catch(() => setUpdatingName(undefined));
217
+ };
218
+ /** The tri-form input: address/path → inspect, anything else → feed search. */
219
+ const submitQuery = () => {
220
+ const text = query.trim();
221
+ if (text === '')
222
+ return;
223
+ setMessage(undefined);
224
+ if (isHttpUrl(text)) {
225
+ inspectFromUrl(text);
226
+ return;
227
+ }
228
+ if (looksLikePath(text)) {
229
+ inspectPath(text);
230
+ return;
231
+ }
232
+ runSearch(text);
233
+ };
234
+ const runSearch = (text) => {
235
+ setSearching(true);
236
+ setSearchResults(undefined);
237
+ void link.call('plugins.remote-list', {}).then(result => {
238
+ setSearching(false);
239
+ if (!result.ok) {
240
+ setMessage({ kind: 'error', text: `搜索失败:${rpcErrorText(result.error)}` });
241
+ return;
242
+ }
243
+ const needle = text.toLowerCase();
244
+ setSearchResults(result.value.plugins.filter(item => item.name.toLowerCase().includes(needle)
245
+ || (item.title ?? '').toLowerCase().includes(needle)
246
+ || (item.description ?? '').toLowerCase().includes(needle)));
247
+ }).catch(cause => {
248
+ setSearching(false);
249
+ setMessage({ kind: 'error', text: String(cause) });
250
+ });
251
+ };
252
+ /** A search-result entry that is not installed yet: preview first. The
253
+ * entry's own coordinates decide where the zip comes from — a federation
254
+ * row downloads from the author's release, a same-directory row from its
255
+ * feed base. */
256
+ const previewRemote = (item) => {
257
+ if (item.url !== undefined) {
258
+ inspectFromUrl(item.url);
259
+ return;
260
+ }
261
+ if (item.feedUrl === undefined || item.file === undefined)
262
+ return;
263
+ const base = item.feedUrl.endsWith('/') ? item.feedUrl : `${item.feedUrl}/`;
264
+ inspectFromUrl(`${base}${item.file}`);
265
+ };
266
+ const onDrop = (event) => {
267
+ event.preventDefault();
268
+ setDragging(false);
269
+ const file = event.dataTransfer.files[0];
270
+ if (file === undefined)
271
+ return;
272
+ if (!file.name.toLowerCase().endsWith('.zip')) {
273
+ setMessage({ kind: 'error', text: '只支持 .zip 插件包或组合包' });
274
+ return;
275
+ }
276
+ const zipPath = droppedZipPath(file);
277
+ if (zipPath === null) {
278
+ setMessage({ kind: 'error', text: '当前环境不支持拖拽安装(缺少路径桥)' });
279
+ return;
280
+ }
281
+ inspectPath(zipPath);
282
+ };
283
+ const restart = () => {
284
+ void link.call('window.relaunch', {});
285
+ };
286
+ const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
287
+ // Rows arrive category-sorted; one merged cell spans each category block.
288
+ const spans = new Map();
289
+ for (let index = 0; index < rows.length;) {
290
+ const category = rows[index].category;
291
+ let end = index + 1;
292
+ while (end < rows.length && rows[end].category === category)
293
+ end += 1;
294
+ spans.set(index, end - index);
295
+ index = end;
100
296
  }
101
- return (_jsx(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", description: "\u5B89\u88C5\u9A71\u52A8\u3001\u4E1A\u52A1\u9875\u9762\u548C\u754C\u9762\u98CE\u683C\u3002\u542F\u7528/\u505C\u7528\u5199\u5165 plugins.yml\uFF0C\u6E32\u67D3\u7AEF\u5728\u4E0B\u4E00\u6B21\u91CD\u542F\u540E\u751F\u6548\u3002", actions: _jsx(Button, { intent: "neutral", emphasis: "outline", onClick: load, children: "\u5237\u65B0" }), children: _jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)' }, children: error }), rows.length === 0
102
- ? _jsx(EmptyState, { title: "\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6", description: "\u628A\u63D2\u4EF6 zip \u62D6\u5165\u63D2\u4EF6\u5B89\u88C5\u5165\u53E3\uFF0C\u6216\u4ECE\u63D2\u4EF6\u6E90\u641C\u7D22\u5B89\u88C5\u3002" })
103
- : [...groups.entries()].map(([category, entries]) => (_jsx(Section, { title: category, children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: "\u540D\u79F0" }), _jsx(TableHead, { children: "\u7C7B\u578B" }), _jsx(TableHead, { children: "\u7248\u672C" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: entries.map(row => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [row.title, row.builtinDefault && _jsx(Badge, { intent: "neutral", children: "\u5185\u7F6E\u9ED8\u8BA4" })] }), _jsx("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-xs)' }, children: row.packageName })] }) }), _jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== undefined && (_jsx(Badge, { intent: "neutral", children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile }))] }), _jsx(TableCell, { children: row.version ?? '—' }), _jsx(TableCell, { children: row.builtinDefault
104
- ? _jsx(Badge, { intent: "success", children: "\u59CB\u7EC8\u968F\u5E95\u5EA7" })
105
- : (_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [_jsx(Switch, { checked: row.enabled, disabled: busy === row.packageName, onCheckedChange: next => toggle(row, next), "aria-label": `启用 ${row.title}` }), touched.has(row.packageName) && _jsx(Badge, { intent: "warning", children: "\u5F85\u91CD\u542F" })] })) }), _jsx(TableCell, { children: row.builtinDefault
106
- ? _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u5185\u7F6E\u9ED8\u8BA4\u4E0D\u53EF\u5378\u8F7D" })
107
- : (_jsx(Button, { intent: "danger", emphasis: "ghost", size: "sm", disabled: busy === row.packageName, onClick: () => uninstall(row), children: "\u5378\u8F7D" })) })] }, row.packageName))) })] }) }, category)))] }) }));
297
+ return (_jsxs(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", titleExtra: _jsx(IconButton, { icon: _jsx(PlusIcon, {}), label: "\u5B89\u88C5\u63D2\u4EF6", onClick: openInstall }), actions: restartNeeded ? _jsx(Button, { intent: "primary", onClick: restart, children: "\u91CD\u542F\u751F\u6548" }) : undefined, children: [_jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx(Alert, { intent: "danger", children: error }), rows.length === 0
298
+ ? (_jsx(EmptyState, { title: "\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6", action: _jsx(Button, { intent: "primary", onClick: openInstall, children: "\u5B89\u88C5\u63D2\u4EF6" }) }))
299
+ : (_jsxs(Table, { "data-plugins-table": true, children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { style: { width: '6em' }, children: "\u5206\u7C7B" }), _jsx(TableHead, { children: "\u540D\u79F0" }), _jsx(TableHead, { children: "\u7C7B\u578B" }), _jsx(TableHead, { children: "\u7248\u672C" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: rows.map((row, index) => {
300
+ const update = updates.get(row.packageName);
301
+ const span = spans.get(index);
302
+ return (_jsxs(TableRow, { children: [span !== undefined && (_jsx(TableCell, { rowSpan: span, style: { verticalAlign: 'middle', color: 'var(--snap-color-muted)', fontWeight: 600 }, children: row.category })), _jsx(TableCell, { children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsxs("span", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [row.title, row.builtinDefault && _jsx(Badge, { intent: "neutral", children: "\u5185\u7F6E\u9ED8\u8BA4" })] }), _jsx("span", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-xs)' }, children: row.packageName })] }) }), _jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== undefined && (_jsx(Badge, { intent: "neutral", children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile }))] }), _jsx(TableCell, { children: update !== undefined
303
+ ? (_jsx(Button, { intent: "primary", emphasis: "ghost", size: "sm", title: update.keyChanged === true
304
+ ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更`
305
+ : `当前 ${update.installedVersion} → ${update.feedVersion}`, disabled: updatingName === row.packageName, onClick: () => requestUpdate(update), children: updatingName === row.packageName ? '更新中…' : `⟳ ${update.feedVersion}` }))
306
+ : (row.version ?? '—') }), _jsx(TableCell, { children: row.builtinDefault
307
+ ? _jsx(Switch, { checked: true, disabled: true, "aria-label": `启用 ${row.title}` })
308
+ : (_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 'var(--snap-space-sm)' }, children: [_jsx(Switch, { checked: row.enabled, disabled: busy === row.packageName, onCheckedChange: next => toggle(row, next), "aria-label": `启用 ${row.title}` }), touched.has(row.packageName) && _jsx(Badge, { intent: "warning", children: "\u5F85\u91CD\u542F" })] })) }), _jsx(TableCell, { children: row.builtinDefault
309
+ ? _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u5185\u7F6E\u9ED8\u8BA4\u4E0D\u53EF\u5378\u8F7D" })
310
+ : (_jsx(Button, { intent: "danger", emphasis: "ghost", size: "sm", disabled: busy === row.packageName, onClick: () => uninstall(row), children: "\u5378\u8F7D" })) })] }, row.packageName));
311
+ }) })] }))] }), _jsx(Dialog, { open: installOpen, onOpenChange: next => { if (!next)
312
+ closeInstall(); }, children: _jsxs(DialogContent, { presentation: "modal", size: "lg", "data-plugins-dropzone": true, "aria-describedby": undefined, onDragOver: event => {
313
+ event.preventDefault();
314
+ setDragging(true);
315
+ }, onDragLeave: event => {
316
+ if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget))
317
+ setDragging(false);
318
+ }, onDrop: onDrop, children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "\u5B89\u88C5\u63D2\u4EF6" }) }), _jsx(DialogBody, { children: _jsxs(Stack, { gap: "sm", children: [_jsx("div", { "data-plugins-drop-hint": true, style: {
319
+ height: 'calc(var(--snap-control-height-md) * 3)',
320
+ display: 'flex',
321
+ alignItems: 'center',
322
+ justifyContent: 'center',
323
+ border: `1px dashed ${dragging ? 'var(--snap-color-accent)' : 'var(--snap-color-border)'}`,
324
+ borderRadius: 'var(--snap-radius-md)',
325
+ background: dragging ? 'color-mix(in srgb, var(--snap-color-accent) 10%, transparent)' : 'transparent',
326
+ color: 'var(--snap-color-muted)',
327
+ fontSize: 'var(--snap-text-sm)',
328
+ }, children: dragging ? '释放以安装' : '拖入 .zip 安装' }), _jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)' }, children: [_jsx(Input, { value: query, placeholder: "\u672C\u5730\u8DEF\u5F84 / https://\u2026 / \u63D2\u4EF6\u540D", style: { flex: 1, minWidth: 0 }, onChange: event => setQuery(event.target.value), onKeyDown: event => { if (event.key === 'Enter')
329
+ submitQuery(); } }), _jsx(Button, { intent: "neutral", emphasis: "outline", disabled: searching, onClick: submitQuery, children: searching ? '搜索中…' : '搜索' })] }), message !== undefined && (_jsx("div", { role: message.kind === 'error' ? 'alert' : 'status', style: { fontSize: 'var(--snap-text-xs)', color: message.kind === 'error' ? 'var(--snap-color-danger)' : 'var(--snap-color-muted)' }, children: message.text })), visibleResults !== undefined && (_jsxs(Stack, { gap: "sm", children: [_jsxs("div", { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }, children: [_jsxs("span", { style: { fontSize: 'var(--snap-text-sm)', color: 'var(--snap-color-muted)' }, children: ["\u641C\u7D22\u201C", query.trim(), "\u201D\uFF08", searchResults?.length ?? 0, "\uFF09"] }), _jsx(Button, { intent: "neutral", emphasis: "ghost", size: "sm", onClick: () => setSearchResults(undefined), children: "\u2715" })] }), visibleResults.length === 0 && (_jsx("div", { style: { padding: '12px 0', textAlign: 'center', color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: "\u6CA1\u6709\u5339\u914D\u7684\u63D2\u4EF6\u3002" })), visibleResults.map(item => {
330
+ const installed = item.installed !== undefined;
331
+ return (_jsxs("div", { style: {
332
+ display: 'flex', gap: 'var(--snap-space-md)', alignItems: 'center',
333
+ justifyContent: 'space-between', borderBottom: '1px solid var(--snap-color-border)', paddingBottom: 'var(--snap-space-sm)',
334
+ }, children: [_jsxs("div", { style: { minWidth: 0 }, children: [_jsxs("div", { style: { display: 'flex', gap: 'var(--snap-space-sm)', alignItems: 'center' }, children: [item.title ?? item.name, item.source !== undefined && _jsx(Badge, { intent: "neutral", children: item.source })] }), _jsxs("div", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: [item.name, " \u00B7 ", item.version] })] }), item.action === 'install'
335
+ ? _jsx(Button, { intent: "primary", emphasis: "outline", size: "sm", onClick: () => previewRemote(item), children: "\u5B89\u88C5" })
336
+ : item.action === 'update' && installed
337
+ ? (_jsx(Button, { intent: "primary", emphasis: "ghost", size: "sm", title: `当前 ${item.installed?.version} → ${item.version}`, disabled: updatingName === item.name, onClick: () => requestUpdate({
338
+ name: item.name,
339
+ installedVersion: item.installed?.version ?? '',
340
+ feedVersion: item.version,
341
+ }), children: updatingName === item.name ? '更新中…' : `⟳ ${item.version}` }))
342
+ : _jsx("span", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: item.action === 'current' ? '已是最新' : '本地更新' })] }, item.name));
343
+ }), (searchResults?.length ?? 0) > SEARCH_ROW_CAP && (_jsxs("div", { style: { fontSize: 'var(--snap-text-xs)', color: 'var(--snap-color-muted)' }, children: ["\u5DF2\u663E\u793A\u524D ", SEARCH_ROW_CAP, " \u6761\uFF0C\u5171 ", searchResults?.length, " \u6761\u3002"] }))] }))] }) })] }) }), _jsx(Dialog, { open: phase.kind === 'confirm' || phase.kind === 'installing' || phase.kind === 'error', onOpenChange: next => {
344
+ if (!next && phase.kind !== 'installing')
345
+ setPhase({ kind: 'idle' });
346
+ }, children: _jsxs(DialogContent, { presentation: "modal", "aria-describedby": undefined, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: phase.kind === 'confirm'
347
+ ? phase.archive.kind === 'combo'
348
+ ? '安装组合套件'
349
+ : phase.archive.plugin.action === 'update' ? '更新插件' : '安装插件'
350
+ : phase.kind === 'error' ? '安装失败' : '正在安装…' }), phase.kind === 'confirm' && phase.archive.kind === 'combo' && (_jsx(DialogDescription, { children: `${phase.archive.combo.title} · ${phase.archive.combo.id}` }))] }), _jsxs(DialogBody, { children: [phase.kind === 'error' && (_jsx("div", { style: { color: 'var(--snap-color-danger)', whiteSpace: 'pre-wrap', fontSize: 'var(--snap-text-sm)' }, children: phase.message })), phase.kind === 'confirm' && phase.archive.kind === 'combo' && (_jsxs(Stack, { gap: "sm", children: [phase.archive.combo.description !== undefined && (_jsx("div", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: phase.archive.combo.description })), _jsxs("div", { style: { display: 'grid', gap: 'var(--snap-space-xs)', fontSize: 'var(--snap-text-sm)' }, children: [_jsxs("div", { children: ["\u63D2\u4EF6\uFF08", phase.archive.combo.plugins.length, "\uFF09"] }), phase.archive.combo.plugins.map(plugin => {
351
+ const line = signatureText(plugin.signature, phase.viaUrl);
352
+ const action = plugin.action === 'install' ? '安装' : plugin.action === 'update' ? '更新' : '保留';
353
+ return (_jsxs("div", { style: { color: line.warning ? 'var(--snap-color-warning)' : undefined }, children: [plugin.title ?? plugin.name, " ", plugin.version, " \u00B7 ", action, line.warning ? ' · ⚠ 未验证' : ''] }, plugin.name));
354
+ })] }), phase.archive.combo.missing.length > 0 && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u7F3A\u5C11\u4F9D\u8D56\uFF1A", phase.archive.combo.missing.join('、')] }))] })), phase.kind === 'confirm' && phase.archive.kind === 'plugin' && (_jsxs(Stack, { gap: "sm", children: [phase.risk ? (_jsx("div", { "data-plugins-risk": true, style: { color: 'var(--snap-color-warning)', fontWeight: 600 }, children: "\u26A0 \u6B64\u63D2\u4EF6\u672A\u7ECF\u53D1\u5E03\u8005\u9A8C\u8BC1" })) : undefined, !phase.risk && (_jsxs(Stack, { gap: "sm", children: [phase.archive.plugin.title !== undefined && _jsxs("div", { children: ["\u540D\u79F0\uFF1A", phase.archive.plugin.title] }), _jsxs("div", { children: ["\u5305\u540D\uFF1A", phase.archive.plugin.name] }), phase.archive.plugin.action === 'update'
355
+ ? (_jsxs(_Fragment, { children: [_jsxs("div", { children: ["\u5DF2\u5B89\u88C5\u7248\u672C\uFF1A", phase.archive.plugin.installed?.version] }), _jsxs("div", { children: ["\u5C06\u66F4\u65B0\u81F3\uFF1A", phase.archive.plugin.version] })] }))
356
+ : _jsxs("div", { children: ["\u7248\u672C\uFF1A", phase.archive.plugin.version] })] })), (() => {
357
+ const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
358
+ return (_jsxs("div", { "data-plugins-signature": phase.archive.plugin.signature.state, style: { color: line.warning ? 'var(--snap-color-warning)' : undefined }, children: ["\u7B7E\u540D\uFF1A", line.text] }));
359
+ })(), !phase.risk && (_jsxs(Stack, { gap: "sm", children: [_jsxs("div", { children: ["\u6743\u9650\uFF1A", phase.archive.plugin.permissions.length === 0 ? '无' : phase.archive.plugin.permissions.join('、')] }), phase.archive.plugin.missing.length > 0 && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u7F3A\u5C11\u4F9D\u8D56\uFF1A", phase.archive.plugin.missing.join('、')] })), phase.archive.plugin.action === 'blocked' && (_jsxs("div", { style: { color: 'var(--snap-color-danger)', fontSize: 'var(--snap-text-sm)' }, children: ["\u5DF2\u5B89\u88C5 v", phase.archive.plugin.installed?.version, "\uFF0C\u5B89\u88C5\u5305 v", phase.archive.plugin.version, " \u4E0D\u9AD8\u4E8E\u5DF2\u88C5\u7248\u672C\uFF0C\u65E0\u6CD5\u8986\u76D6\u3002"] }))] })), phase.risk && (_jsx("div", { style: { color: 'var(--snap-color-muted)', fontSize: 'var(--snap-text-sm)' }, children: phase.archive.plugin.signature.keyId !== undefined
360
+ ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。`
361
+ : '这个包没有携带任何签名,也没有任何完整性校验。' }))] }))] }), _jsxs(DialogFooter, { children: [phase.kind === 'error' && (_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setPhase({ kind: 'idle' }), children: "\u8FD4\u56DE" })), phase.kind === 'confirm' && (_jsxs(_Fragment, { children: [_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setPhase({ kind: 'idle' }), children: "\u53D6\u6D88" }), phase.risk
362
+ ? (_jsx(Button, { intent: "primary", "data-plugins-risk-confirm": true, onClick: () => runInstall(phase.zipPath, phase.archive), children: "\u6211\u77E5\u6653\u98CE\u9669\uFF0C\u4ECD\u8981\u5B89\u88C5" }))
363
+ : (_jsx(Button, { intent: "primary", "data-plugins-install-confirm": true, disabled: phase.archive.kind === 'plugin' && phase.archive.plugin.action === 'blocked', onClick: () => {
364
+ if (phase.archive.kind === 'plugin' && phase.archive.plugin.signature.state === 'unverified') {
365
+ setPhase({ ...phase, risk: true });
366
+ return;
367
+ }
368
+ runInstall(phase.zipPath, phase.archive);
369
+ }, children: phase.archive.kind === 'combo' ? '安装组合' : phase.archive.plugin.action === 'update' ? '更新' : '安装' }))] })), phase.kind === 'installing' && _jsx("span", { style: { color: 'var(--snap-color-muted)' }, children: "\u6B63\u5728\u5B89\u88C5\u2026" })] })] }) }), _jsx(Dialog, { open: keyChange !== undefined, onOpenChange: next => { if (!next)
370
+ setKeyChange(undefined); }, children: _jsxs(DialogContent, { presentation: "modal", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "\u53D1\u5E03\u8005\u5BC6\u94A5\u5DF2\u53D8\u66F4" }), _jsxs(DialogDescription, { children: [keyChange?.name, " \u7684\u65B0\u7248\u672C\u7531\u4E0D\u540C\u7684\u5BC6\u94A5\u7B7E\u540D\u3002"] })] }), _jsx(DialogBody, { children: keyChange !== undefined && (_jsxs("div", { style: { fontSize: 'var(--snap-text-sm)' }, children: ["\u5DF2\u5B89\u88C5 v", keyChange.installedVersion, " \u2192 \u6E90\u4E0A v", keyChange.feedVersion, "\u3002"] })) }), _jsxs(DialogFooter, { children: [_jsx(Button, { intent: "neutral", emphasis: "outline", onClick: () => setKeyChange(undefined), children: "\u53D6\u6D88" }), _jsx(Button, { intent: "primary", "data-plugins-keychange-confirm": true, onClick: () => keyChange !== undefined && updateNow(keyChange.name), children: "\u4ECD\u8981\u66F4\u65B0" })] })] }) })] }));
108
371
  }
109
372
  //# sourceMappingURL=plugins.js.map
@@ -49,6 +49,7 @@ export declare function SettingsEntry(props: {
49
49
  /** The default settings surface. */
50
50
  export declare function SettingsSurface(props: {
51
51
  service: SettingsService;
52
+ ctx: Context;
52
53
  }): ReactNode;
53
54
  /** Mount the settings registry and its default slot contributions. */
54
55
  declare const settingsPlugin: Plugin.Object<void>;
@@ -1,8 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Component, useSyncExternalStore } from 'react';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Component, useState, useSyncExternalStore } from 'react';
3
3
  import { Button, Dialog, DialogContent, DialogTitle, EmptyState, IconButton, } from "./components/index.js";
4
4
  import { UI_SLOT_IDS } from "./contract.js";
5
5
  import { AppearancePage } from "./settings-pages/appearance.js";
6
+ import { PluginFeedDialog } from "./settings-pages/plugin-feed.js";
6
7
  import { PluginsPage } from "./settings-pages/plugins.js";
7
8
  import { cn, part } from "./utils.js";
8
9
  /** Sort pages by order, then registration time. */
@@ -30,6 +31,10 @@ class SettingsPageBoundary extends Component {
30
31
  function GearIcon() {
31
32
  return (_jsxs("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "3" }), _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" })] }));
32
33
  }
34
+ /** The close glyph used by the surface's dismiss control. */
35
+ function CloseIcon() {
36
+ return (_jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: "1.8", "aria-hidden": "true", children: _jsx("path", { d: "M6 6l12 12M18 6L6 18" }) }));
37
+ }
33
38
  /** The default settings trigger; the layout decides placement/presentation. */
34
39
  export function SettingsEntry(props) {
35
40
  if (props.presentation === 'label') {
@@ -39,12 +44,13 @@ export function SettingsEntry(props) {
39
44
  }
40
45
  /** The default settings surface. */
41
46
  export function SettingsSurface(props) {
42
- const { service } = props;
47
+ const { service, ctx } = props;
43
48
  useSyncExternalStore(service.subscribe, service.version, service.version);
44
49
  const open = service.isOpen();
45
50
  const pages = service.listPages();
46
51
  const activeId = service.activePage();
47
52
  const active = pages.find(page => page.id === activeId);
53
+ const [feedOpen, setFeedOpen] = useState(false);
48
54
  const groups = new Map();
49
55
  for (const page of pages) {
50
56
  const group = page.group ?? '其他';
@@ -54,10 +60,10 @@ export function SettingsSurface(props) {
54
60
  else
55
61
  bucket.push(page);
56
62
  }
57
- return (_jsx(Dialog, { open: open, onOpenChange: next => { if (!next)
58
- service.close(); }, children: _jsx(DialogContent, { presentation: "fullscreen", showClose: false, children: _jsxs("div", { ...part('settings', 'root'), className: "snap-settings", children: [_jsxs("header", { ...part('settings', 'header'), className: "snap-settings-header", children: [_jsx(DialogTitle, { children: "\u8BBE\u7F6E" }), _jsx(Button, { intent: "neutral", emphasis: "ghost", onClick: () => service.close(), children: "\u5173\u95ED" })] }), _jsxs("div", { ...part('settings', 'body'), className: "snap-settings-body", children: [_jsx("nav", { ...part('settings', 'nav'), className: "snap-settings-nav", "aria-label": "\u8BBE\u7F6E\u9875", children: [...groups.entries()].map(([group, entries]) => (_jsxs("div", { ...part('settings', 'group'), className: "snap-settings-group", children: [_jsx("div", { ...part('settings', 'group-title'), className: "snap-settings-group-title", children: group }), entries.map(page => (_jsxs("button", { type: "button", ...part('settings', 'nav-item'), className: cn('snap-settings-nav-item', page.id === activeId && 'is-active'), "data-active": page.id === activeId || undefined, "aria-current": page.id === activeId ? 'page' : undefined, onClick: () => service.open(page.id), children: [page.icon !== undefined && _jsx("span", { ...part('settings', 'nav-icon'), children: page.icon }), _jsx("span", { children: page.title })] }, page.id)))] }, group))) }), _jsx("main", { ...part('settings', 'content'), className: "snap-settings-content", "data-active-page": activeId, children: active === undefined
59
- ? _jsx(EmptyState, { title: "\u6682\u65E0\u8BBE\u7F6E\u9875", description: "\u5B89\u88C5\u6216\u542F\u7528\u4E00\u4E2A\u5E26\u8BBE\u7F6E\u9875\u7684\u63D2\u4EF6\u540E\uFF0C\u5B83\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\u3002" })
60
- : _jsx(SettingsPageBoundary, { page: active.id, children: active.render() }) })] })] }) }) }));
63
+ return (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: open, onOpenChange: next => { if (!next)
64
+ service.close(); }, children: _jsx(DialogContent, { presentation: "fullscreen", showClose: false, children: _jsxs("div", { ...part('settings', 'root'), className: "snap-settings", children: [_jsxs("header", { ...part('settings', 'header'), className: "snap-settings-header", children: [_jsx(DialogTitle, { children: "\u8BBE\u7F6E" }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 4 }, children: [_jsx(IconButton, { icon: _jsx(GearIcon, {}), label: "\u914D\u7F6E\u63D2\u4EF6\u6E90", onClick: () => setFeedOpen(true) }), _jsx(IconButton, { icon: _jsx(CloseIcon, {}), label: "\u5173\u95ED", onClick: () => service.close() })] })] }), _jsxs("div", { ...part('settings', 'body'), className: "snap-settings-body", children: [_jsx("nav", { ...part('settings', 'nav'), className: "snap-settings-nav", "aria-label": "\u8BBE\u7F6E\u9875", children: [...groups.entries()].map(([group, entries]) => (_jsxs("div", { ...part('settings', 'group'), className: "snap-settings-group", children: [_jsx("div", { ...part('settings', 'group-title'), className: "snap-settings-group-title", children: group }), entries.map(page => (_jsxs("button", { type: "button", ...part('settings', 'nav-item'), className: cn('snap-settings-nav-item', page.id === activeId && 'is-active'), "data-active": page.id === activeId || undefined, "aria-current": page.id === activeId ? 'page' : undefined, onClick: () => service.open(page.id), children: [page.icon !== undefined && _jsx("span", { ...part('settings', 'nav-icon'), children: page.icon }), _jsx("span", { children: page.title })] }, page.id)))] }, group))) }), _jsx("main", { ...part('settings', 'content'), className: "snap-settings-content", "data-active-page": activeId, children: active === undefined
65
+ ? _jsx(EmptyState, { title: "\u6682\u65E0\u8BBE\u7F6E\u9875" })
66
+ : _jsx(SettingsPageBoundary, { page: active.id, children: active.render() }) })] })] }) }) }), _jsx(PluginFeedDialog, { ctx: ctx, open: feedOpen, onOpenChange: setFeedOpen })] }));
61
67
  }
62
68
  /** Mount the settings registry and its default slot contributions. */
63
69
  const settingsPlugin = {
@@ -153,7 +159,7 @@ const settingsPlugin = {
153
159
  ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
154
160
  id: 'settings.default-surface',
155
161
  order: 0,
156
- render: () => _jsx(SettingsSurface, { service: service }),
162
+ render: () => _jsx(SettingsSurface, { service: service, ctx: ctx }),
157
163
  });
158
164
  },
159
165
  };
@@ -1,15 +1,16 @@
1
1
  /**
2
- * The skin registry and token bridge. A skin is a declared visual
3
- * implementation of the semantic component contract: token values plus part
4
- * CSS. Exactly one skin is active; the built-in default is always available
5
- * as the fallback.
2
+ * The theme registry and token bridge. A theme is a declared visual
3
+ * implementation of the semantic component contract: one token set plus
4
+ * optional part CSS — pure styling. Component definitions and slots live
5
+ * outside the theme; a theme never shapes behaviour. Exactly one theme is
6
+ * active; the two factory cobalt themes (day/night) are always registered
7
+ * and the dark one is the fallback.
6
8
  *
7
9
  * @module @snap-rail/ui/skins
8
10
  */
9
11
  import { Context, type Plugin } from '@snap-rail/cordis';
10
12
  import { type ReactNode } from 'react';
11
- import { PRESENTATION_TARGETS, type PresentationTarget, type PresentationVariant } from './contract.ts';
12
- /** The colour/typography/spacing vocabulary a skin must populate. */
13
+ /** The colour/typography/spacing vocabulary a theme must populate. */
13
14
  export interface SkinTokens {
14
15
  colorBg: string;
15
16
  colorSurface: string;
@@ -66,51 +67,46 @@ export interface SkinTokens {
66
67
  controlHeightLg: string;
67
68
  density: string;
68
69
  }
69
- /** One skin's full definition. */
70
+ /** One theme's full definition: a single complete look. */
70
71
  export interface SkinDefinition {
71
72
  id: string;
72
73
  title: string;
73
- /** Token values for both modes; the active mode picks one set. */
74
- tokens: {
75
- light: SkinTokens;
76
- dark: SkinTokens;
77
- };
78
- /** Presentation defaults the skin chooses for core variants. */
79
- presentations?: Partial<Record<PresentationTarget, PresentationVariant>>;
80
- /** Parts the skin claims to style (coverage diagnostics, optional). */
81
- parts?: readonly string[];
74
+ /** The theme's single token set; picking another theme switches the set. */
75
+ tokens: SkinTokens;
82
76
  /** Optional CSS text; the registry injects it scoped by `data-snap-skin`. */
83
77
  css?: string;
84
78
  }
85
- /** The two colour modes. */
86
- export declare const SKIN_MODES: readonly ["light", "dark"];
87
- /** One skin mode. */
88
- export type SkinMode = (typeof SKIN_MODES)[number];
89
- /** The built-in default skin id. */
90
- export declare const DEFAULT_SKIN_ID = "default";
91
- /** The factory cobalt/steel skin. Extra skins override it through the registry. */
92
- export declare const DEFAULT_SKIN: SkinDefinition;
79
+ /** The factory day theme id (cobalt palette, light surfaces). */
80
+ export declare const DEFAULT_LIGHT_ID = "default-light";
81
+ /** The factory night theme id (cobalt palette, dark surfaces). */
82
+ export declare const DEFAULT_DARK_ID = "default-dark";
83
+ /** The factory day theme. Always registered; never the first paint though — the night theme is. */
84
+ export declare const DEFAULT_LIGHT: SkinDefinition;
85
+ /** The factory night theme and the registry's fallback. */
86
+ export declare const DEFAULT_DARK: SkinDefinition;
87
+ /** One registered theme as the registry reports it. */
88
+ export interface SkinRow {
89
+ id: string;
90
+ title: string;
91
+ /** The registering package; factory themes carry `@snap-rail/ui`. */
92
+ caller: string;
93
+ }
93
94
  /** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
94
95
  export declare function skinTokenVar(key: keyof SkinTokens): string;
95
96
  /** The service exposed as `ctx.skins`. */
96
97
  export interface SkinsService {
97
- /** Register a skin; disposal removes it and falls back to the default. */
98
+ /** Register a theme; disposal removes it and falls back to the factory night theme. */
98
99
  register(caller: Context, skin: SkinDefinition): () => void;
99
- /** Activate a registered skin by id. */
100
- activate(skinId: string): boolean;
101
- /** Every registered skin, default first. */
102
- list(): readonly SkinDefinition[];
103
- /** The active skin. */
100
+ /** Activate a theme: exact id first, then the id read as a contributor
101
+ * package (a package's first registered theme), then nothing. */
102
+ activate(selection: string): boolean;
103
+ /** Every registered theme, factory themes first. */
104
+ list(): readonly SkinRow[];
105
+ /** The active theme. */
104
106
  active(): SkinDefinition;
105
- /** Set the colour mode and re-apply the active tokens. */
106
- setMode(mode: SkinMode): void;
107
- /** The current colour mode. */
108
- mode(): SkinMode;
109
- /** The active skin's presentation default for a target, when one is set. */
110
- presentation(target: PresentationTarget): PresentationVariant | undefined;
111
- /** The active skin's token object for the current mode. */
107
+ /** The active theme's token object. */
112
108
  tokens(): SkinTokens;
113
- /** Subscribe to skin/mode changes. */
109
+ /** Subscribe to theme changes. */
114
110
  subscribe(listener: () => void): () => void;
115
111
  /** Monotonic change version. */
116
112
  version(): number;
@@ -120,7 +116,7 @@ declare module '@snap-rail/cordis' {
120
116
  skins: SkinsService;
121
117
  }
122
118
  interface Events {
123
- /** The active skin or colour mode changed. */
119
+ /** The active theme changed. */
124
120
  'skins/changed'(): void;
125
121
  }
126
122
  }
@@ -133,11 +129,9 @@ export declare function SkinsProvider(props: {
133
129
  }): ReactNode;
134
130
  /** Read the skin service. */
135
131
  export declare function useSkins(): SkinsService;
136
- /** Re-render on skin/mode changes and return the active token set. */
132
+ /** Re-render on theme changes and return the active token set. */
137
133
  export declare function useSkinTokens(): SkinTokens;
138
- /** Re-render on skin/mode changes and return the active presentation default. */
139
- export declare function usePresentation(target: PresentationTarget): PresentationVariant | undefined;
140
- /** Re-export the presentation vocabulary for skin authors. */
141
- export { PRESENTATION_TARGETS };
134
+ /** Re-render on theme changes and return the active theme id. */
135
+ export declare function useSkinId(): string;
142
136
  export default skinsPlugin;
143
137
  //# sourceMappingURL=skins.d.ts.map