@danielng23/dsh-client-ui-theme-store 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.
- package/README.md +161 -0
- package/catalog/edex-themes.json +634 -0
- package/lib/client.js +1591 -0
- package/lib/index.js +1093 -0
- package/lib/invariant.js +19 -0
- package/lib/types/client/ThemeStoreSection.d.ts +60 -0
- package/lib/types/client/catalog.d.ts +84 -0
- package/lib/types/client/index.d.ts +40 -0
- package/lib/types/client/locales.d.ts +60 -0
- package/lib/types/client/settings-store.d.ts +35 -0
- package/lib/types/client/theme-store.d.ts +95 -0
- package/lib/types/host/installer.d.ts +82 -0
- package/lib/types/index.d.ts +16 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/theme-store-settings.d.ts +14 -0
- package/package.json +104 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,1591 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@danielng23/dsh-client-ui-theme-store",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
|
|
10
|
+
//#region \0dsh-css:/Users/daniel/workspace/dsh-edex-themes/src/client/ThemeStoreSection.module.css.mjs
|
|
11
|
+
const css = "._20S4Kq_section{flex-direction:column;gap:1rem;padding:0;display:flex}._20S4Kq_header{flex-direction:column;gap:.25rem;display:flex}._20S4Kq_title{color:var(--dsw-alias-label-primary);margin:0;font-size:1.125rem;font-weight:600;line-height:1.5}._20S4Kq_subtitle{color:var(--dsw-alias-label-secondary);margin:0;font-size:.8125rem;line-height:1.4}._20S4Kq_banner{border:1px solid color-mix(in srgb, var(--dsw-alias-state-success-primary,#2e7d32) 45%, transparent);background:color-mix(in srgb, var(--dsw-alias-state-success-primary,#2e7d32) 10%, transparent);border-radius:6px;align-items:center;gap:.5rem;padding:.625rem .75rem;display:flex}._20S4Kq_bannerText{color:var(--dsw-alias-label-primary);flex:1;margin:0;font-size:.8125rem;line-height:1.4}._20S4Kq_bannerDismiss{width:1.5rem;height:1.5rem;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-radius:4px;flex:none;font-size:1rem;line-height:1}._20S4Kq_bannerDismiss:hover{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}._20S4Kq_status{color:var(--dsw-alias-label-secondary);margin:0;font-size:.8125rem;line-height:1.4}._20S4Kq_failure{border:1px solid var(--dsw-alias-state-error-primary,#e03e3e);background:color-mix(in srgb, var(--dsw-alias-state-error-primary,#e03e3e) 8%, transparent);border-radius:6px;flex-direction:column;gap:.5rem;padding:1rem;display:flex}._20S4Kq_failure p{color:var(--dsw-alias-label-primary);white-space:pre-wrap;margin:0;font-size:.8125rem}._20S4Kq_retry{align-self:flex-start}._20S4Kq_grid{grid-template-columns:1fr;gap:.75rem;display:grid}._20S4Kq_card{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:8px;flex-direction:column;gap:.75rem;transition:box-shadow .15s,border-color .15s;display:flex;overflow:hidden}._20S4Kq_card:hover{border-color:var(--dsw-alias-border-l2);box-shadow:0 1px 4px #00000014}._20S4Kq_screenshot{aspect-ratio:16/9;background:var(--dsw-alias-bg-layer-2);justify-content:center;align-items:center;width:100%;display:flex;overflow:hidden}._20S4Kq_screenshotImg{object-fit:cover;width:100%;height:100%;display:block}._20S4Kq_swatchFallback{flex-wrap:wrap;justify-content:center;align-items:center;gap:2px;padding:8px;display:flex}._20S4Kq_swatch{border:1px solid var(--dsw-alias-border-l1);border-radius:4px;width:28px;height:28px;display:block}._20S4Kq_cardBody{flex-direction:column;gap:.25rem;padding:0;display:flex}._20S4Kq_cardMain{flex-direction:column;flex:1;gap:0;min-width:0;padding:.625rem .75rem .75rem;display:flex}._20S4Kq_cardName{color:var(--dsw-alias-label-primary);text-overflow:ellipsis;white-space:nowrap;font-size:.875rem;font-weight:600;line-height:1.4;overflow:hidden}._20S4Kq_cardAuthor{color:var(--dsw-alias-label-secondary);text-overflow:ellipsis;white-space:nowrap;font-size:.75rem;line-height:1.3;overflow:hidden}._20S4Kq_cardScheme{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);border:1px solid var(--dsw-alias-border-l1);border-radius:4px;align-self:flex-start;padding:1px 6px;font-size:.6875rem;line-height:1.2}._20S4Kq_cardScheme[data-scheme=dark]{color:#ccc;background:#1e1e1e;border-color:#444}._20S4Kq_cardScheme[data-scheme=light]{color:#333;background:#f5f5f5;border-color:#ddd}._20S4Kq_cardTags{align-items:center;gap:.375rem;display:flex}._20S4Kq_cardType{background:color-mix(in srgb, var(--dsw-alias-brand-primary,#4ea1ff) 12%, transparent);color:var(--dsw-alias-brand-primary,#4ea1ff);border:1px solid color-mix(in srgb, var(--dsw-alias-brand-primary,#4ea1ff) 35%, transparent);border-radius:4px;padding:1px 6px;font-size:.6875rem;line-height:1.2}._20S4Kq_installBox{flex-direction:column;gap:.375rem;padding:0;display:flex}._20S4Kq_installNote{color:var(--dsw-alias-label-secondary);margin:0;font-size:.6875rem;line-height:1.3}._20S4Kq_installCommand{background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-primary);text-overflow:ellipsis;white-space:nowrap;user-select:all;border-radius:4px;padding:.375rem .5rem;font-size:.6875rem;line-height:1.4;display:block;overflow:hidden}._20S4Kq_installError{color:var(--dsw-alias-state-error-primary,#e03e3e);white-space:pre-wrap;margin:0;font-size:.6875rem;line-height:1.3}._20S4Kq_progress{flex-direction:column;gap:.25rem;display:flex}._20S4Kq_progressBar{background:var(--dsw-alias-bg-layer-2);border-radius:2px;height:4px;display:block;position:relative;overflow:hidden}._20S4Kq_progressBar:after{content:\"\";background:var(--dsw-alias-brand-primary,#4ea1ff);border-radius:2px;width:40%;animation:1.2s ease-in-out infinite _20S4Kq_dshThemeStoreIndeterminate;position:absolute;inset:0}@keyframes _20S4Kq_dshThemeStoreIndeterminate{0%{transform:translate(-100%)}to{transform:translate(250%)}}._20S4Kq_progressLabel{color:var(--dsw-alias-label-secondary);font-size:.6875rem;line-height:1.3}._20S4Kq_applyBtn{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);cursor:pointer;border-radius:6px;align-self:flex-start;margin:.5rem 0 0;padding:.375rem .75rem;font-size:.8125rem;font-weight:500;line-height:1.4;transition:background .12s,border-color .12s}._20S4Kq_applyBtn:hover:not(:disabled){background:var(--dsw-alias-bg-layer-1);border-color:var(--dsw-alias-border-l2)}._20S4Kq_applyBtn:disabled{opacity:.6;cursor:default;background:color-mix(in srgb, var(--dsw-alias-state-success-primary,#2e7d32) 6%, var(--dsw-alias-bg-layer-2));border-color:var(--dsw-alias-state-success-primary,#2e7d32);color:var(--dsw-alias-state-success-primary,#2e7d32)}";
|
|
12
|
+
const tagId = "@danielng23/dsh-client-ui-theme-store/ThemeStoreSection.module.css";
|
|
13
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
14
|
+
const tag = document.createElement("style");
|
|
15
|
+
tag.dataset.plugin = "@danielng23/dsh-client-ui-theme-store";
|
|
16
|
+
tag.dataset.pluginCss = tagId;
|
|
17
|
+
tag.textContent = css;
|
|
18
|
+
document.head.appendChild(tag);
|
|
19
|
+
}
|
|
20
|
+
var ThemeStoreSection_module_css_default = {
|
|
21
|
+
"applyBtn": "_20S4Kq_applyBtn",
|
|
22
|
+
"banner": "_20S4Kq_banner",
|
|
23
|
+
"bannerDismiss": "_20S4Kq_bannerDismiss",
|
|
24
|
+
"bannerText": "_20S4Kq_bannerText",
|
|
25
|
+
"card": "_20S4Kq_card",
|
|
26
|
+
"cardAuthor": "_20S4Kq_cardAuthor",
|
|
27
|
+
"cardBody": "_20S4Kq_cardBody",
|
|
28
|
+
"cardMain": "_20S4Kq_cardMain",
|
|
29
|
+
"cardName": "_20S4Kq_cardName",
|
|
30
|
+
"cardScheme": "_20S4Kq_cardScheme",
|
|
31
|
+
"cardTags": "_20S4Kq_cardTags",
|
|
32
|
+
"cardType": "_20S4Kq_cardType",
|
|
33
|
+
"dshThemeStoreIndeterminate": "_20S4Kq_dshThemeStoreIndeterminate",
|
|
34
|
+
"failure": "_20S4Kq_failure",
|
|
35
|
+
"grid": "_20S4Kq_grid",
|
|
36
|
+
"header": "_20S4Kq_header",
|
|
37
|
+
"installBox": "_20S4Kq_installBox",
|
|
38
|
+
"installCommand": "_20S4Kq_installCommand",
|
|
39
|
+
"installError": "_20S4Kq_installError",
|
|
40
|
+
"installNote": "_20S4Kq_installNote",
|
|
41
|
+
"progress": "_20S4Kq_progress",
|
|
42
|
+
"progressBar": "_20S4Kq_progressBar",
|
|
43
|
+
"progressLabel": "_20S4Kq_progressLabel",
|
|
44
|
+
"retry": "_20S4Kq_retry",
|
|
45
|
+
"screenshot": "_20S4Kq_screenshot",
|
|
46
|
+
"screenshotImg": "_20S4Kq_screenshotImg",
|
|
47
|
+
"section": "_20S4Kq_section",
|
|
48
|
+
"status": "_20S4Kq_status",
|
|
49
|
+
"subtitle": "_20S4Kq_subtitle",
|
|
50
|
+
"swatch": "_20S4Kq_swatch",
|
|
51
|
+
"swatchFallback": "_20S4Kq_swatchFallback",
|
|
52
|
+
"title": "_20S4Kq_title"
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region lib/types/client/ThemeStoreSection.js
|
|
56
|
+
/**
|
|
57
|
+
* Theme store section: a Settings page that lists repository themes as image
|
|
58
|
+
* cards. Color themes apply inline (`register` + `setTheme`); shell themes
|
|
59
|
+
* (eDEX variants) also preview their palette but need a pnpm install for the
|
|
60
|
+
* full UI, so their card surfaces the install command and copies it on demand.
|
|
61
|
+
*
|
|
62
|
+
* The component receives the store mirror (catalog status/themes/applied/
|
|
63
|
+
* installedShells) and injected callbacks. It is a pure props consumer — no
|
|
64
|
+
* React context, no ctx, no subscription machinery.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* sessionStorage key the install flow writes right before `location.reload()`
|
|
68
|
+
* so the section can show a visible "installed and restarted" confirmation
|
|
69
|
+
* after the page comes back (the reload wipes the DevTools console).
|
|
70
|
+
*/
|
|
71
|
+
const LAST_INSTALL_KEY = "theme-store.last-install";
|
|
72
|
+
/** Read (and keep) the last-install marker, if any. */
|
|
73
|
+
function readLastInstall() {
|
|
74
|
+
try {
|
|
75
|
+
const raw = window.sessionStorage.getItem(LAST_INSTALL_KEY);
|
|
76
|
+
if (!raw) return void 0;
|
|
77
|
+
const parsed = JSON.parse(raw);
|
|
78
|
+
if (typeof parsed.id !== "string" || typeof parsed.name !== "string") return void 0;
|
|
79
|
+
return {
|
|
80
|
+
id: parsed.id,
|
|
81
|
+
name: parsed.name,
|
|
82
|
+
ts: typeof parsed.ts === "string" ? parsed.ts : (/* @__PURE__ */ new Date()).toISOString()
|
|
83
|
+
};
|
|
84
|
+
} catch {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** Forget the last-install marker (dismissed by the user). */
|
|
89
|
+
function clearLastInstall() {
|
|
90
|
+
try {
|
|
91
|
+
window.sessionStorage.removeItem(LAST_INSTALL_KEY);
|
|
92
|
+
} catch {}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Render the theme store section.
|
|
96
|
+
* @param props - composed slot props.
|
|
97
|
+
* @returns the section element tree.
|
|
98
|
+
*/
|
|
99
|
+
function ThemeStoreSection({ t, useStore, apply, load, installShell }) {
|
|
100
|
+
const { status, themes, applied, installedShells, error } = useStore((s) => s);
|
|
101
|
+
const [lastInstall, setLastInstall] = (0, react.useState)(readLastInstall);
|
|
102
|
+
const shellCount = themes.filter((theme) => theme.type === "shell").length;
|
|
103
|
+
console.log("[theme-store] ThemeStoreSection rendered:", {
|
|
104
|
+
status,
|
|
105
|
+
themes: themes.length,
|
|
106
|
+
shellThemes: shellCount,
|
|
107
|
+
applied,
|
|
108
|
+
installedShells: installedShells.length,
|
|
109
|
+
lastInstall
|
|
110
|
+
});
|
|
111
|
+
const dismissBanner = () => {
|
|
112
|
+
clearLastInstall();
|
|
113
|
+
setLastInstall(void 0);
|
|
114
|
+
};
|
|
115
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
116
|
+
className: ThemeStoreSection_module_css_default.section,
|
|
117
|
+
"aria-busy": status === "loading",
|
|
118
|
+
children: [
|
|
119
|
+
(0, react_jsx_runtime.jsxs)("div", {
|
|
120
|
+
className: ThemeStoreSection_module_css_default.header,
|
|
121
|
+
children: [(0, react_jsx_runtime.jsx)("h2", {
|
|
122
|
+
className: ThemeStoreSection_module_css_default.title,
|
|
123
|
+
children: t("title")
|
|
124
|
+
}), (0, react_jsx_runtime.jsx)("p", {
|
|
125
|
+
className: ThemeStoreSection_module_css_default.subtitle,
|
|
126
|
+
children: t("subtitle")
|
|
127
|
+
})]
|
|
128
|
+
}),
|
|
129
|
+
lastInstall !== void 0 ? (0, react_jsx_runtime.jsxs)("div", {
|
|
130
|
+
className: ThemeStoreSection_module_css_default.banner,
|
|
131
|
+
role: "status",
|
|
132
|
+
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
133
|
+
className: ThemeStoreSection_module_css_default.bannerText,
|
|
134
|
+
children: t("installedBanner").replace("{name}", lastInstall.name)
|
|
135
|
+
}), (0, react_jsx_runtime.jsx)("button", {
|
|
136
|
+
type: "button",
|
|
137
|
+
className: ThemeStoreSection_module_css_default.bannerDismiss,
|
|
138
|
+
onClick: dismissBanner,
|
|
139
|
+
"aria-label": t("dismiss"),
|
|
140
|
+
children: "×"
|
|
141
|
+
})]
|
|
142
|
+
}) : null,
|
|
143
|
+
status === "loading" ? (0, react_jsx_runtime.jsx)("p", {
|
|
144
|
+
className: ThemeStoreSection_module_css_default.status,
|
|
145
|
+
children: t("loading")
|
|
146
|
+
}) : status === "error" ? (0, react_jsx_runtime.jsxs)("div", {
|
|
147
|
+
className: ThemeStoreSection_module_css_default.failure,
|
|
148
|
+
role: "alert",
|
|
149
|
+
children: [(0, react_jsx_runtime.jsx)("p", { children: error ? error : t("error") }), (0, react_jsx_runtime.jsx)("button", {
|
|
150
|
+
type: "button",
|
|
151
|
+
className: ThemeStoreSection_module_css_default.retry,
|
|
152
|
+
onClick: load,
|
|
153
|
+
children: t("retry")
|
|
154
|
+
})]
|
|
155
|
+
}) : status === "ready" && themes.length === 0 ? (0, react_jsx_runtime.jsx)("p", {
|
|
156
|
+
className: ThemeStoreSection_module_css_default.status,
|
|
157
|
+
children: t("empty")
|
|
158
|
+
}) : status === "ready" ? (0, react_jsx_runtime.jsx)("div", {
|
|
159
|
+
className: ThemeStoreSection_module_css_default.grid,
|
|
160
|
+
children: themes.map((theme) => (0, react_jsx_runtime.jsx)(ThemeCard, {
|
|
161
|
+
theme,
|
|
162
|
+
applied: applied === theme.id,
|
|
163
|
+
installed: theme.type === "shell" && theme.shellPluginId !== void 0 && installedShells.includes(theme.shellPluginId),
|
|
164
|
+
t,
|
|
165
|
+
onApply: () => {
|
|
166
|
+
apply(theme.id);
|
|
167
|
+
},
|
|
168
|
+
onInstall: (onStage) => {
|
|
169
|
+
if (theme.type === "shell" && theme.installPackage !== void 0) return installShell(theme.installPackage, onStage, {
|
|
170
|
+
id: theme.id,
|
|
171
|
+
name: theme.name,
|
|
172
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
173
|
+
});
|
|
174
|
+
onStage?.("installing");
|
|
175
|
+
return Promise.resolve();
|
|
176
|
+
}
|
|
177
|
+
}, theme.id))
|
|
178
|
+
}) : null
|
|
179
|
+
]
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/** One theme card: screenshot, name, author, scheme badge, Apply/Install button. */
|
|
183
|
+
function ThemeCard({ theme, applied, installed, t, onApply, onInstall }) {
|
|
184
|
+
const [broken, setBroken] = (0, react.useState)(false);
|
|
185
|
+
const [stage, setStage] = (0, react.useState)(void 0);
|
|
186
|
+
const [installError, setInstallError] = (0, react.useState)(void 0);
|
|
187
|
+
const schemeLabel = theme.colorScheme === "light" ? t("light") : t("dark");
|
|
188
|
+
const shell = theme.type === "shell";
|
|
189
|
+
const runInstall = () => {
|
|
190
|
+
console.log("[theme-store] Apply/Install clicked:", theme.id, { installPackage: theme.installPackage });
|
|
191
|
+
setInstallError(void 0);
|
|
192
|
+
Promise.resolve().then(() => onInstall(setStage)).catch((error) => {
|
|
193
|
+
console.log("[theme-store] Install failed:", error instanceof Error ? error.message : String(error));
|
|
194
|
+
setStage(void 0);
|
|
195
|
+
setInstallError(error instanceof Error ? error.message : String(error));
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
199
|
+
className: ThemeStoreSection_module_css_default.card,
|
|
200
|
+
"data-theme": theme.id,
|
|
201
|
+
children: [(0, react_jsx_runtime.jsx)("div", {
|
|
202
|
+
className: ThemeStoreSection_module_css_default.screenshot,
|
|
203
|
+
children: !broken ? (0, react_jsx_runtime.jsx)("img", {
|
|
204
|
+
src: theme.screenshot,
|
|
205
|
+
alt: theme.name,
|
|
206
|
+
className: ThemeStoreSection_module_css_default.screenshotImg,
|
|
207
|
+
loading: "lazy",
|
|
208
|
+
onError: () => {
|
|
209
|
+
setBroken(true);
|
|
210
|
+
}
|
|
211
|
+
}) : (0, react_jsx_runtime.jsx)("div", {
|
|
212
|
+
className: ThemeStoreSection_module_css_default.swatchFallback,
|
|
213
|
+
children: Object.entries(theme.tokens).slice(0, 6).map(([name, value]) => (0, react_jsx_runtime.jsx)("span", {
|
|
214
|
+
className: ThemeStoreSection_module_css_default.swatch,
|
|
215
|
+
style: { backgroundColor: value },
|
|
216
|
+
title: `${name}: ${value}`
|
|
217
|
+
}, name))
|
|
218
|
+
})
|
|
219
|
+
}), (0, react_jsx_runtime.jsxs)("div", {
|
|
220
|
+
className: ThemeStoreSection_module_css_default.cardMain,
|
|
221
|
+
children: [(0, react_jsx_runtime.jsxs)("div", {
|
|
222
|
+
className: ThemeStoreSection_module_css_default.cardBody,
|
|
223
|
+
children: [
|
|
224
|
+
(0, react_jsx_runtime.jsx)("strong", {
|
|
225
|
+
className: ThemeStoreSection_module_css_default.cardName,
|
|
226
|
+
children: theme.name
|
|
227
|
+
}),
|
|
228
|
+
(0, react_jsx_runtime.jsxs)("span", {
|
|
229
|
+
className: ThemeStoreSection_module_css_default.cardAuthor,
|
|
230
|
+
children: [
|
|
231
|
+
t("author"),
|
|
232
|
+
": ",
|
|
233
|
+
theme.author
|
|
234
|
+
]
|
|
235
|
+
}),
|
|
236
|
+
(0, react_jsx_runtime.jsxs)("span", {
|
|
237
|
+
className: ThemeStoreSection_module_css_default.cardTags,
|
|
238
|
+
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
239
|
+
className: ThemeStoreSection_module_css_default.cardScheme,
|
|
240
|
+
"data-scheme": theme.colorScheme,
|
|
241
|
+
children: schemeLabel
|
|
242
|
+
}), shell ? (0, react_jsx_runtime.jsx)("span", {
|
|
243
|
+
className: ThemeStoreSection_module_css_default.cardType,
|
|
244
|
+
children: t("shellTheme")
|
|
245
|
+
}) : null]
|
|
246
|
+
})
|
|
247
|
+
]
|
|
248
|
+
}), shell ? (0, react_jsx_runtime.jsxs)("div", {
|
|
249
|
+
className: ThemeStoreSection_module_css_default.installBox,
|
|
250
|
+
children: [
|
|
251
|
+
stage === void 0 ? (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!installed ? (0, react_jsx_runtime.jsx)("p", {
|
|
252
|
+
className: ThemeStoreSection_module_css_default.installNote,
|
|
253
|
+
children: t("shellInstallNote")
|
|
254
|
+
}) : null, theme.installHint !== void 0 && !installed ? (0, react_jsx_runtime.jsx)("code", {
|
|
255
|
+
className: ThemeStoreSection_module_css_default.installCommand,
|
|
256
|
+
children: theme.installHint
|
|
257
|
+
}) : null] }) : null,
|
|
258
|
+
stage !== void 0 ? (0, react_jsx_runtime.jsxs)("div", {
|
|
259
|
+
className: ThemeStoreSection_module_css_default.progress,
|
|
260
|
+
role: "progressbar",
|
|
261
|
+
"aria-label": t(stage),
|
|
262
|
+
children: [(0, react_jsx_runtime.jsx)("span", { className: ThemeStoreSection_module_css_default.progressBar }), (0, react_jsx_runtime.jsx)("span", {
|
|
263
|
+
className: ThemeStoreSection_module_css_default.progressLabel,
|
|
264
|
+
children: t(stage)
|
|
265
|
+
})]
|
|
266
|
+
}) : null,
|
|
267
|
+
installError !== void 0 ? (0, react_jsx_runtime.jsx)("p", {
|
|
268
|
+
className: ThemeStoreSection_module_css_default.installError,
|
|
269
|
+
role: "alert",
|
|
270
|
+
children: installError
|
|
271
|
+
}) : null,
|
|
272
|
+
(0, react_jsx_runtime.jsx)("button", {
|
|
273
|
+
type: "button",
|
|
274
|
+
className: ThemeStoreSection_module_css_default.applyBtn,
|
|
275
|
+
disabled: stage !== void 0,
|
|
276
|
+
onClick: (e) => {
|
|
277
|
+
e.currentTarget.blur();
|
|
278
|
+
runInstall();
|
|
279
|
+
},
|
|
280
|
+
"aria-label": `${t(installed && !applied ? "apply" : applied ? "applied" : "install")} ${theme.name}`,
|
|
281
|
+
children: installed && applied ? t("applied") : installed ? t("apply") : t("install")
|
|
282
|
+
})
|
|
283
|
+
]
|
|
284
|
+
}) : (0, react_jsx_runtime.jsx)("button", {
|
|
285
|
+
type: "button",
|
|
286
|
+
className: ThemeStoreSection_module_css_default.applyBtn,
|
|
287
|
+
disabled: applied,
|
|
288
|
+
"aria-pressed": applied,
|
|
289
|
+
"aria-label": applied ? `${t("applied")} ${theme.name}` : `${t("apply")} ${theme.name}`,
|
|
290
|
+
onClick: (e) => {
|
|
291
|
+
e.currentTarget.blur();
|
|
292
|
+
onApply();
|
|
293
|
+
},
|
|
294
|
+
children: applied ? t("applied") : t("apply")
|
|
295
|
+
})]
|
|
296
|
+
})]
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
//#endregion
|
|
300
|
+
//#region lib/types/client/settings-store.js
|
|
301
|
+
/**
|
|
302
|
+
* Theme store section slot store: mirrors the theme store runtime snapshot.
|
|
303
|
+
* The plugin's apply-world change listener is the only writer; the section
|
|
304
|
+
* component reads via props.useStore.
|
|
305
|
+
*/
|
|
306
|
+
/**
|
|
307
|
+
* Declares the theme store section state and write surface.
|
|
308
|
+
* @returns the store handle.
|
|
309
|
+
*/
|
|
310
|
+
function createThemeStoreStore() {
|
|
311
|
+
return (0, _deepseek_ai_dsh_client_runtime_client.defineStore)({
|
|
312
|
+
init: () => ({
|
|
313
|
+
status: "idle",
|
|
314
|
+
themes: [],
|
|
315
|
+
applied: void 0,
|
|
316
|
+
installedShells: [],
|
|
317
|
+
error: void 0,
|
|
318
|
+
revision: -1
|
|
319
|
+
}),
|
|
320
|
+
actions: { sync: (draft, snapshot) => {
|
|
321
|
+
if (snapshot.revision <= draft.revision) return;
|
|
322
|
+
draft.status = snapshot.status;
|
|
323
|
+
draft.themes = snapshot.themes;
|
|
324
|
+
draft.applied = snapshot.applied;
|
|
325
|
+
draft.installedShells = snapshot.installedShells;
|
|
326
|
+
draft.error = snapshot.error;
|
|
327
|
+
draft.revision = snapshot.revision;
|
|
328
|
+
} }
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region lib/types/client/catalog.js
|
|
333
|
+
/**
|
|
334
|
+
* Theme store catalog: types, runtime validation, and remote loading.
|
|
335
|
+
*
|
|
336
|
+
* The catalog is a plain JSON document hosted in this repository (pushed to
|
|
337
|
+
* GitHub) and fetched at runtime by the browser half. It is deliberately
|
|
338
|
+
* category-free: one flat `themes` array whose entries carry the display
|
|
339
|
+
* metadata the store renders — `name`, `author`, `screenshot` — plus the
|
|
340
|
+
* functional fields needed to apply a theme through the harness theme
|
|
341
|
+
* service (`id`, `colorScheme`, `tokens`).
|
|
342
|
+
*/
|
|
343
|
+
/**
|
|
344
|
+
* Default catalog URL. Served locally by this plugin's node half at the
|
|
345
|
+
* webserver route `/catalog/edex-themes.json` (same origin as the GUI), so
|
|
346
|
+
* themes load without any GitHub push. Overridable at build time via
|
|
347
|
+
* DSH_CLIENT_THEME_STORE_CATALOG_URL.
|
|
348
|
+
*/
|
|
349
|
+
const DEFAULT_CATALOG_URL = "/catalog/edex-themes.json";
|
|
350
|
+
/** Resolve the effective catalog URL (build-time override, else default). */
|
|
351
|
+
function catalogUrl() {
|
|
352
|
+
const override = typeof process !== "undefined" ? process.env.DSH_CLIENT_THEME_STORE_CATALOG_URL : void 0;
|
|
353
|
+
return override !== void 0 && override !== "" ? override : DEFAULT_CATALOG_URL;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Resolve a screenshot reference against the catalog document URL.
|
|
357
|
+
* @param screenshot - absolute URL or catalog-relative path.
|
|
358
|
+
* @param catalogHref - the catalog document's absolute URL (or an origin-relative path).
|
|
359
|
+
* @returns an absolute, fetchable image URL.
|
|
360
|
+
*/
|
|
361
|
+
function resolveScreenshot(screenshot, catalogHref) {
|
|
362
|
+
if (/^[a-z][a-z0-9+.-]*:/iu.test(screenshot)) return screenshot;
|
|
363
|
+
const dir = catalogHref.slice(0, catalogHref.lastIndexOf("/") + 1);
|
|
364
|
+
const absoluteBase = catalogHref.includes("://") ? dir : `${typeof location !== "undefined" ? location.origin : ""}${dir.startsWith("/") ? "" : "/"}${dir}`;
|
|
365
|
+
return new URL(screenshot, absoluteBase).href;
|
|
366
|
+
}
|
|
367
|
+
/** Error thrown when the fetched catalog is not a valid theme catalog. */
|
|
368
|
+
var CatalogParseError = class extends Error {
|
|
369
|
+
name = "CatalogParseError";
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Runtime-validate an unknown parsed JSON value as a {@link ThemeCatalog}.
|
|
373
|
+
* Rejects malformed shapes with a teaching error; returns defensive copies so
|
|
374
|
+
* later caller mutation cannot reach the stored catalog.
|
|
375
|
+
* @param value - the parsed JSON document.
|
|
376
|
+
* @returns the validated catalog.
|
|
377
|
+
*/
|
|
378
|
+
function parseCatalog(value) {
|
|
379
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new CatalogParseError("theme catalog must be an object with a \"themes\" array");
|
|
380
|
+
const raw = value;
|
|
381
|
+
if (!Array.isArray(raw.themes)) throw new CatalogParseError("theme catalog is missing a \"themes\" array");
|
|
382
|
+
const themes = [];
|
|
383
|
+
const seen = /* @__PURE__ */ new Set();
|
|
384
|
+
for (const entry of raw.themes) {
|
|
385
|
+
if (typeof entry !== "object" || entry === null) throw new CatalogParseError("each catalog theme must be an object");
|
|
386
|
+
const theme = entry;
|
|
387
|
+
const id = theme.id;
|
|
388
|
+
if (typeof id !== "string" || id.length === 0) throw new CatalogParseError("each catalog theme needs a non-empty string \"id\"");
|
|
389
|
+
if (seen.has(id)) throw new CatalogParseError(`duplicate catalog theme id "${id}"`);
|
|
390
|
+
seen.add(id);
|
|
391
|
+
for (const field of [
|
|
392
|
+
"name",
|
|
393
|
+
"author",
|
|
394
|
+
"screenshot"
|
|
395
|
+
]) if (typeof theme[field] !== "string" || theme[field].length === 0) throw new CatalogParseError(`catalog theme "${id}" needs a non-empty string "${field}"`);
|
|
396
|
+
const colorScheme = theme.colorScheme;
|
|
397
|
+
if (colorScheme !== "light" && colorScheme !== "dark") throw new CatalogParseError(`catalog theme "${id}" needs colorScheme "light" or "dark"`);
|
|
398
|
+
const tokens = theme.tokens;
|
|
399
|
+
if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens)) throw new CatalogParseError(`catalog theme "${id}" needs a "tokens" object of CSS variable overrides`);
|
|
400
|
+
const tokenRecord = {};
|
|
401
|
+
for (const [name, value] of Object.entries(tokens)) {
|
|
402
|
+
if (typeof value !== "string") throw new CatalogParseError(`catalog theme "${id}" token "${name}" must be a string`);
|
|
403
|
+
tokenRecord[name] = value;
|
|
404
|
+
}
|
|
405
|
+
const shellFields = {};
|
|
406
|
+
if (typeof theme.type === "string") shellFields.type = theme.type;
|
|
407
|
+
if (typeof theme.installPackage === "string") shellFields.installPackage = theme.installPackage;
|
|
408
|
+
if (typeof theme.shellPluginId === "string") shellFields.shellPluginId = theme.shellPluginId;
|
|
409
|
+
if (typeof theme.installHint === "string") shellFields.installHint = theme.installHint;
|
|
410
|
+
themes.push({
|
|
411
|
+
id,
|
|
412
|
+
colorScheme,
|
|
413
|
+
tokens: tokenRecord,
|
|
414
|
+
name: theme.name,
|
|
415
|
+
author: theme.author,
|
|
416
|
+
screenshot: theme.screenshot,
|
|
417
|
+
...shellFields
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
return { themes };
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Fetch and parse the theme catalog from a URL.
|
|
424
|
+
* @param href - catalog document URL (defaults to {@link catalogUrl}).
|
|
425
|
+
* @returns the validated catalog.
|
|
426
|
+
*/
|
|
427
|
+
async function fetchCatalog(href = catalogUrl()) {
|
|
428
|
+
let response;
|
|
429
|
+
try {
|
|
430
|
+
response = await fetch(href, { headers: { Accept: "application/json" } });
|
|
431
|
+
} catch (error) {
|
|
432
|
+
throw new Error(`theme catalog unreachable at ${href}: ${error instanceof Error ? error.message : String(error)}`);
|
|
433
|
+
}
|
|
434
|
+
if (!response.ok) throw new Error(`theme catalog request failed at ${href}: HTTP ${response.status}`);
|
|
435
|
+
let parsed;
|
|
436
|
+
try {
|
|
437
|
+
parsed = await response.json();
|
|
438
|
+
} catch (error) {
|
|
439
|
+
throw new CatalogParseError(`theme catalog at ${href} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
440
|
+
}
|
|
441
|
+
return parseCatalog(parsed);
|
|
442
|
+
}
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region lib/types/client/theme-store.js
|
|
445
|
+
/**
|
|
446
|
+
* Theme catalog store: loads the repository catalog, registers catalog themes
|
|
447
|
+
* with the harness theme service on apply (lazily, so a duplicate id never
|
|
448
|
+
* throws at load), tracks which shell plugins the active profile has
|
|
449
|
+
* installed, and persists the applied theme id across reloads.
|
|
450
|
+
*/
|
|
451
|
+
var ThemeStoreRuntime = class {
|
|
452
|
+
host;
|
|
453
|
+
theme;
|
|
454
|
+
href;
|
|
455
|
+
store;
|
|
456
|
+
/** Theme ids this runtime registered with the theme service (id → disposer). */
|
|
457
|
+
registered = /* @__PURE__ */ new Map();
|
|
458
|
+
/** The active applied theme id. */
|
|
459
|
+
applied = void 0;
|
|
460
|
+
disposed = false;
|
|
461
|
+
offTheme;
|
|
462
|
+
offHost;
|
|
463
|
+
/**
|
|
464
|
+
* @param ctx - owning context (change and theme listeners are released on dispose).
|
|
465
|
+
* @param host - durable `ui-theme-store` scope owned by the same plugin.
|
|
466
|
+
* @param theme - harness theme service (register/setTheme).
|
|
467
|
+
* @param href - catalog document URL (defaults to the build-time catalog URL).
|
|
468
|
+
*/
|
|
469
|
+
constructor(ctx, host, theme, href = catalogUrl()) {
|
|
470
|
+
this.host = host;
|
|
471
|
+
this.theme = theme;
|
|
472
|
+
this.href = href;
|
|
473
|
+
this.store = (0, _deepseek_ai_dsh_client_runtime_client.createSnapshotStore)({
|
|
474
|
+
status: "idle",
|
|
475
|
+
themes: [],
|
|
476
|
+
applied: void 0,
|
|
477
|
+
installedShells: [],
|
|
478
|
+
error: void 0,
|
|
479
|
+
revision: 0
|
|
480
|
+
});
|
|
481
|
+
this.offTheme = ctx.on("theme/change", (snapshot) => {
|
|
482
|
+
this.adoptApplied(snapshot);
|
|
483
|
+
});
|
|
484
|
+
this.adoptApplied(theme.getTheme());
|
|
485
|
+
this.offHost = host.subscribe(() => {
|
|
486
|
+
this.adoptPersisted();
|
|
487
|
+
});
|
|
488
|
+
this.adoptPersisted();
|
|
489
|
+
}
|
|
490
|
+
/** @returns the current immutable snapshot (stable reference until the next change). */
|
|
491
|
+
getState() {
|
|
492
|
+
return this.store.getSnapshot();
|
|
493
|
+
}
|
|
494
|
+
/** Observe snapshot replacements. @returns the disposer. */
|
|
495
|
+
subscribe(listener) {
|
|
496
|
+
return this.store.subscribe(listener);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Load the catalog from the configured URL and reconcile the persisted
|
|
500
|
+
* applied theme. Safe to call repeatedly (retry); a failed fetch leaves
|
|
501
|
+
* the previous ready state intact and reports an error snapshot.
|
|
502
|
+
* @returns completion of the load.
|
|
503
|
+
*/
|
|
504
|
+
async load() {
|
|
505
|
+
if (this.disposed) return;
|
|
506
|
+
this.publish({
|
|
507
|
+
status: "loading",
|
|
508
|
+
error: void 0
|
|
509
|
+
});
|
|
510
|
+
try {
|
|
511
|
+
const catalog = await fetchCatalog(this.href);
|
|
512
|
+
if (this.disposed) return;
|
|
513
|
+
this.publish({
|
|
514
|
+
status: "ready",
|
|
515
|
+
themes: catalog.themes,
|
|
516
|
+
error: void 0
|
|
517
|
+
});
|
|
518
|
+
this.adoptPersisted();
|
|
519
|
+
} catch (error) {
|
|
520
|
+
if (this.disposed) return;
|
|
521
|
+
this.publish({
|
|
522
|
+
status: "error",
|
|
523
|
+
error: error instanceof Error ? error.message : String(error)
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Apply a catalog theme: register it with the harness theme service if
|
|
529
|
+
* needed, switch the active preference to it, and persist the id.
|
|
530
|
+
* @param id - a catalog theme id.
|
|
531
|
+
*/
|
|
532
|
+
apply(id) {
|
|
533
|
+
if (this.disposed) return;
|
|
534
|
+
const theme = this.getState().themes.find((candidate) => candidate.id === id);
|
|
535
|
+
if (theme === void 0) throw new Error(`theme "${id}" is not in the catalog`);
|
|
536
|
+
this.ensureRegistered(theme);
|
|
537
|
+
this.theme.setTheme(id);
|
|
538
|
+
this.host.set("applied", id);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Adopt the currently installed shell plugin ids from the profile's plugin
|
|
542
|
+
* inventory. The store reports shell themes as "installed" when their
|
|
543
|
+
* `shellPluginId` appears here; color themes are unaffected.
|
|
544
|
+
* @param shellPluginIds - module names of installed client shell plugins.
|
|
545
|
+
*/
|
|
546
|
+
syncInstalledShells(shellPluginIds) {
|
|
547
|
+
if (this.disposed) return;
|
|
548
|
+
const current = this.getState().installedShells;
|
|
549
|
+
const next = [...new Set(shellPluginIds)].sort();
|
|
550
|
+
if (current.length === next.length && current.every((value, index) => value === next[index])) return;
|
|
551
|
+
this.publish({ installedShells: next });
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Release the plugin's registrations and listeners. Disposing the active
|
|
555
|
+
* theme resets the harness preference to its default, exactly as the theme
|
|
556
|
+
* service's own disposer contract specifies.
|
|
557
|
+
*/
|
|
558
|
+
dispose() {
|
|
559
|
+
if (this.disposed) return;
|
|
560
|
+
this.disposed = true;
|
|
561
|
+
this.offTheme?.();
|
|
562
|
+
this.offHost?.();
|
|
563
|
+
for (const dispose of this.registered.values()) dispose();
|
|
564
|
+
this.registered.clear();
|
|
565
|
+
}
|
|
566
|
+
ensureRegistered(theme) {
|
|
567
|
+
if (this.registered.has(theme.id)) return;
|
|
568
|
+
if (this.theme.getTheme().themes.some((candidate) => candidate.id === theme.id)) return;
|
|
569
|
+
const dispose = this.theme.register({
|
|
570
|
+
id: theme.id,
|
|
571
|
+
colorScheme: theme.colorScheme,
|
|
572
|
+
tokens: theme.tokens
|
|
573
|
+
});
|
|
574
|
+
this.registered.set(theme.id, dispose);
|
|
575
|
+
}
|
|
576
|
+
/** Keep `applied` in sync with the theme service's active preference. */
|
|
577
|
+
adoptApplied(snapshot) {
|
|
578
|
+
const preference = snapshot.preference;
|
|
579
|
+
const active = this.getState().themes.some((theme) => theme.id === preference) ? preference : void 0;
|
|
580
|
+
if (active === this.applied) return;
|
|
581
|
+
this.applied = active;
|
|
582
|
+
this.publish({ applied: active });
|
|
583
|
+
}
|
|
584
|
+
/** Restore a persisted applied theme id once the catalog is ready. */
|
|
585
|
+
adoptPersisted() {
|
|
586
|
+
if (this.disposed) return;
|
|
587
|
+
const section = this.host.getSnapshot().value;
|
|
588
|
+
if (section === void 0 || section.applied === "") return;
|
|
589
|
+
const id = section.applied;
|
|
590
|
+
const theme = this.getState().themes.find((candidate) => candidate.id === id);
|
|
591
|
+
if (theme === void 0 || this.applied === id) return;
|
|
592
|
+
this.ensureRegistered(theme);
|
|
593
|
+
this.theme.setTheme(id);
|
|
594
|
+
}
|
|
595
|
+
publish(partial) {
|
|
596
|
+
const current = this.store.getSnapshot();
|
|
597
|
+
this.store.set({
|
|
598
|
+
...current,
|
|
599
|
+
...partial,
|
|
600
|
+
revision: current.revision + 1
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region lib/types/client/locales.js
|
|
606
|
+
/** Copy dictionaries for the theme store Settings section. */
|
|
607
|
+
/** Simplified Chinese dictionary and key source of truth. */
|
|
608
|
+
const zh = {
|
|
609
|
+
nav: "主题商店",
|
|
610
|
+
title: "主题商店",
|
|
611
|
+
subtitle: "安装配色主题与完整界面主题",
|
|
612
|
+
loading: "正在读取主题目录…",
|
|
613
|
+
error: "暂时无法读取主题目录。",
|
|
614
|
+
retry: "重试",
|
|
615
|
+
empty: "目录中还没有主题。",
|
|
616
|
+
author: "作者",
|
|
617
|
+
light: "浅色",
|
|
618
|
+
dark: "深色",
|
|
619
|
+
apply: "应用",
|
|
620
|
+
applied: "已应用",
|
|
621
|
+
install: "安装",
|
|
622
|
+
installing: "正在安装…",
|
|
623
|
+
restarting: "正在重启以应用…",
|
|
624
|
+
reloading: "正在重新加载…",
|
|
625
|
+
installFailed: "安装失败",
|
|
626
|
+
installHint: "在终端运行以下命令安装完整界面:",
|
|
627
|
+
copyCommand: "复制命令",
|
|
628
|
+
copied: "已复制",
|
|
629
|
+
colorTheme: "配色主题",
|
|
630
|
+
shellTheme: "界面主题",
|
|
631
|
+
shellInstallNote: "完整界面需要 pnpm 安装",
|
|
632
|
+
installedBanner: "已安装并重启「{name}」——新的界面外壳已挂载。",
|
|
633
|
+
dismiss: "关闭"
|
|
634
|
+
};
|
|
635
|
+
/** English dictionary checked against the Chinese key set. */
|
|
636
|
+
const en = {
|
|
637
|
+
nav: "Theme Store",
|
|
638
|
+
title: "Theme Store",
|
|
639
|
+
subtitle: "Install color themes and full UI shells",
|
|
640
|
+
loading: "Reading the theme catalog…",
|
|
641
|
+
error: "The theme catalog is temporarily unavailable.",
|
|
642
|
+
retry: "Retry",
|
|
643
|
+
empty: "No themes in the catalog yet.",
|
|
644
|
+
author: "Author",
|
|
645
|
+
light: "Light",
|
|
646
|
+
dark: "Dark",
|
|
647
|
+
apply: "Apply",
|
|
648
|
+
applied: "Applied",
|
|
649
|
+
install: "Install",
|
|
650
|
+
installing: "Installing…",
|
|
651
|
+
restarting: "Restarting to apply…",
|
|
652
|
+
reloading: "Reloading…",
|
|
653
|
+
installFailed: "Install failed",
|
|
654
|
+
installHint: "Run this command in your terminal to install the full UI:",
|
|
655
|
+
copyCommand: "Copy command",
|
|
656
|
+
copied: "Copied",
|
|
657
|
+
colorTheme: "Color theme",
|
|
658
|
+
shellTheme: "UI shell",
|
|
659
|
+
shellInstallNote: "Full UI requires pnpm install",
|
|
660
|
+
installedBanner: "Installed and restarted “{name}” — the new UI shell is live.",
|
|
661
|
+
dismiss: "Dismiss"
|
|
662
|
+
};
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.2/node_modules/@deepseek-ai/cosmokit/lib/index.js
|
|
665
|
+
/** Return true when a value is `null` or `undefined`. */
|
|
666
|
+
function isNullable(value) {
|
|
667
|
+
return value === null || value === void 0;
|
|
668
|
+
}
|
|
669
|
+
/** Return true for non-array object values. */
|
|
670
|
+
function isPlainObject(data) {
|
|
671
|
+
return data && typeof data === "object" && !Array.isArray(data);
|
|
672
|
+
}
|
|
673
|
+
/** Filter object entries and return a new object. */
|
|
674
|
+
function filterKeys(object, filter) {
|
|
675
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
|
|
676
|
+
}
|
|
677
|
+
/** Map object values while preserving the original key set. */
|
|
678
|
+
function mapValues(object, transform) {
|
|
679
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
|
|
680
|
+
}
|
|
681
|
+
/** Pick selected keys from an object, optionally including `undefined` values. */
|
|
682
|
+
function pick(source, keys, forced) {
|
|
683
|
+
if (!keys) return { ...source };
|
|
684
|
+
const result = {};
|
|
685
|
+
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
/** Test values using `instanceof` with a `toStringTag` fallback. */
|
|
689
|
+
function is(type, value) {
|
|
690
|
+
if (arguments.length === 1) return (value) => is(type, value);
|
|
691
|
+
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
692
|
+
}
|
|
693
|
+
function isArrayBufferLike(value) {
|
|
694
|
+
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
695
|
+
}
|
|
696
|
+
function isArrayBufferSource(value) {
|
|
697
|
+
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
698
|
+
}
|
|
699
|
+
/** Binary source detection and base64/hex conversion helpers. */
|
|
700
|
+
var Binary;
|
|
701
|
+
(function(Binary) {
|
|
702
|
+
Binary.is = isArrayBufferLike;
|
|
703
|
+
Binary.isSource = isArrayBufferSource;
|
|
704
|
+
function fromSource(source) {
|
|
705
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
706
|
+
else return source;
|
|
707
|
+
}
|
|
708
|
+
Binary.fromSource = fromSource;
|
|
709
|
+
function toBase64(source) {
|
|
710
|
+
source = fromSource(source);
|
|
711
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
|
|
712
|
+
let binary = "";
|
|
713
|
+
const bytes = new Uint8Array(source);
|
|
714
|
+
for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
|
|
715
|
+
return btoa(binary);
|
|
716
|
+
}
|
|
717
|
+
Binary.toBase64 = toBase64;
|
|
718
|
+
function fromBase64(source) {
|
|
719
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
720
|
+
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
721
|
+
}
|
|
722
|
+
Binary.fromBase64 = fromBase64;
|
|
723
|
+
function toHex(source) {
|
|
724
|
+
source = fromSource(source);
|
|
725
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
726
|
+
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
727
|
+
}
|
|
728
|
+
Binary.toHex = toHex;
|
|
729
|
+
function fromHex(source) {
|
|
730
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
731
|
+
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
732
|
+
const buffer = [];
|
|
733
|
+
for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
734
|
+
return Uint8Array.from(buffer).buffer;
|
|
735
|
+
}
|
|
736
|
+
Binary.fromHex = fromHex;
|
|
737
|
+
})(Binary || (Binary = {}));
|
|
738
|
+
Binary.fromBase64;
|
|
739
|
+
Binary.toBase64;
|
|
740
|
+
Binary.fromHex;
|
|
741
|
+
Binary.toHex;
|
|
742
|
+
/** Deep-clone common JavaScript values while preserving prototypes and cycles. */
|
|
743
|
+
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
744
|
+
if (!source || typeof source !== "object") return source;
|
|
745
|
+
if (is("Date", source)) return new Date(source.valueOf());
|
|
746
|
+
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
747
|
+
if (isArrayBufferLike(source)) return source.slice(0);
|
|
748
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
749
|
+
const cached = refs.get(source);
|
|
750
|
+
if (cached) return cached;
|
|
751
|
+
if (Array.isArray(source)) {
|
|
752
|
+
const result = [];
|
|
753
|
+
refs.set(source, result);
|
|
754
|
+
source.forEach((value, index) => {
|
|
755
|
+
result[index] = Reflect.apply(clone, null, [value, refs]);
|
|
756
|
+
});
|
|
757
|
+
return result;
|
|
758
|
+
}
|
|
759
|
+
const result = Object.create(Object.getPrototypeOf(source));
|
|
760
|
+
refs.set(source, result);
|
|
761
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
762
|
+
const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
763
|
+
if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
|
|
764
|
+
Reflect.defineProperty(result, key, descriptor);
|
|
765
|
+
}
|
|
766
|
+
return result;
|
|
767
|
+
}
|
|
768
|
+
/** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
|
|
769
|
+
function deepEqual(a, b, strict) {
|
|
770
|
+
if (a === b) return true;
|
|
771
|
+
if (!strict && isNullable(a) && isNullable(b)) return true;
|
|
772
|
+
if (typeof a !== typeof b) return false;
|
|
773
|
+
if (typeof a !== "object") return false;
|
|
774
|
+
if (!a || !b) return false;
|
|
775
|
+
function check(test, then) {
|
|
776
|
+
return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
|
|
777
|
+
}
|
|
778
|
+
return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
|
|
779
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
780
|
+
const viewA = new Uint8Array(a);
|
|
781
|
+
const viewB = new Uint8Array(b);
|
|
782
|
+
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
783
|
+
return true;
|
|
784
|
+
}) ?? Object.keys({
|
|
785
|
+
...a,
|
|
786
|
+
...b
|
|
787
|
+
}).every((key) => deepEqual(a[key], b[key], strict));
|
|
788
|
+
}
|
|
789
|
+
/** Time constants plus parsing and formatting helpers. */
|
|
790
|
+
var Time;
|
|
791
|
+
(function(Time) {
|
|
792
|
+
Time.millisecond = 1;
|
|
793
|
+
Time.second = 1e3;
|
|
794
|
+
Time.minute = Time.second * 60;
|
|
795
|
+
Time.hour = Time.minute * 60;
|
|
796
|
+
Time.day = Time.hour * 24;
|
|
797
|
+
Time.week = Time.day * 7;
|
|
798
|
+
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
799
|
+
function setTimezoneOffset(offset) {
|
|
800
|
+
timezoneOffset = offset;
|
|
801
|
+
}
|
|
802
|
+
Time.setTimezoneOffset = setTimezoneOffset;
|
|
803
|
+
function getTimezoneOffset() {
|
|
804
|
+
return timezoneOffset;
|
|
805
|
+
}
|
|
806
|
+
Time.getTimezoneOffset = getTimezoneOffset;
|
|
807
|
+
function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
|
|
808
|
+
if (typeof date === "number") date = new Date(date);
|
|
809
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
810
|
+
return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
|
|
811
|
+
}
|
|
812
|
+
Time.getDateNumber = getDateNumber;
|
|
813
|
+
function fromDateNumber(value, offset) {
|
|
814
|
+
const date = new Date(value * Time.day);
|
|
815
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
816
|
+
return new Date(+date + offset * Time.minute);
|
|
817
|
+
}
|
|
818
|
+
Time.fromDateNumber = fromDateNumber;
|
|
819
|
+
const numeric = /\d+(?:\.\d+)?/.source;
|
|
820
|
+
const timeRegExp = new RegExp(`^${[
|
|
821
|
+
"w(?:eek(?:s)?)?",
|
|
822
|
+
"d(?:ay(?:s)?)?",
|
|
823
|
+
"h(?:our(?:s)?)?",
|
|
824
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
825
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
826
|
+
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
827
|
+
function parseTime(source) {
|
|
828
|
+
const capture = timeRegExp.exec(source);
|
|
829
|
+
if (!capture) return 0;
|
|
830
|
+
return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
|
|
831
|
+
}
|
|
832
|
+
Time.parseTime = parseTime;
|
|
833
|
+
function parseDate(date) {
|
|
834
|
+
const parsed = parseTime(date);
|
|
835
|
+
if (parsed) date = Date.now() + parsed;
|
|
836
|
+
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
|
|
837
|
+
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
|
|
838
|
+
return date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
839
|
+
}
|
|
840
|
+
Time.parseDate = parseDate;
|
|
841
|
+
function format(ms) {
|
|
842
|
+
const abs = Math.abs(ms);
|
|
843
|
+
if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
|
|
844
|
+
else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
|
|
845
|
+
else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
|
|
846
|
+
else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
|
|
847
|
+
return ms + "ms";
|
|
848
|
+
}
|
|
849
|
+
Time.format = format;
|
|
850
|
+
function toDigits(source, length = 2) {
|
|
851
|
+
return source.toString().padStart(length, "0");
|
|
852
|
+
}
|
|
853
|
+
Time.toDigits = toDigits;
|
|
854
|
+
function template(template, time = /* @__PURE__ */ new Date()) {
|
|
855
|
+
return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
|
|
856
|
+
}
|
|
857
|
+
Time.template = template;
|
|
858
|
+
})(Time || (Time = {}));
|
|
859
|
+
//#endregion
|
|
860
|
+
//#region node_modules/.pnpm/@deepseek-ai+schemastery@3.18.1/node_modules/@deepseek-ai/schemastery/lib/index.mjs
|
|
861
|
+
const kSchema = Symbol.for("schemastery");
|
|
862
|
+
const kValidationError = Symbol.for("ValidationError");
|
|
863
|
+
globalThis.__schemastery_index__ ??= 0;
|
|
864
|
+
globalThis.__schemastery_refs__ = void 0;
|
|
865
|
+
var ValidationError = class extends TypeError {
|
|
866
|
+
options;
|
|
867
|
+
name = "ValidationError";
|
|
868
|
+
constructor(message, options) {
|
|
869
|
+
let prefix = "$";
|
|
870
|
+
for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
|
|
871
|
+
else if (typeof segment === "number") prefix += "[" + segment + "]";
|
|
872
|
+
else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
|
|
873
|
+
if (prefix.startsWith(".")) prefix = prefix.slice(1);
|
|
874
|
+
super((prefix === "$" ? "" : `${prefix} `) + message);
|
|
875
|
+
this.options = options;
|
|
876
|
+
}
|
|
877
|
+
static is(error) {
|
|
878
|
+
return !!error?.[kValidationError];
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
|
|
882
|
+
const Schema = function(options) {
|
|
883
|
+
const schema = function(data, options = {}) {
|
|
884
|
+
return Schema.resolve(data, schema, options)[0];
|
|
885
|
+
};
|
|
886
|
+
if (options.refs) {
|
|
887
|
+
const refs = mapValues(options.refs, (options) => new Schema(options));
|
|
888
|
+
const getRef = (uid) => refs[uid];
|
|
889
|
+
for (const key in refs) {
|
|
890
|
+
const options = refs[key];
|
|
891
|
+
options.sKey = getRef(options.sKey);
|
|
892
|
+
options.inner = getRef(options.inner);
|
|
893
|
+
options.list = options.list && options.list.map(getRef);
|
|
894
|
+
options.dict = options.dict && mapValues(options.dict, getRef);
|
|
895
|
+
}
|
|
896
|
+
return refs[options.uid];
|
|
897
|
+
}
|
|
898
|
+
Object.assign(schema, options);
|
|
899
|
+
if (typeof schema.callback === "string") try {
|
|
900
|
+
schema.callback = new Function("return " + schema.callback)();
|
|
901
|
+
} catch {}
|
|
902
|
+
Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
|
|
903
|
+
Object.setPrototypeOf(schema, Schema.prototype);
|
|
904
|
+
schema.meta ||= {};
|
|
905
|
+
schema.toString = schema.toString.bind(schema);
|
|
906
|
+
return schema;
|
|
907
|
+
};
|
|
908
|
+
Schema.prototype = Object.create(Function.prototype);
|
|
909
|
+
Schema.prototype[kSchema] = true;
|
|
910
|
+
Object.defineProperty(Schema.prototype, "~standard", { get() {
|
|
911
|
+
return {
|
|
912
|
+
version: 1,
|
|
913
|
+
vendor: "schemastery",
|
|
914
|
+
validate: (value) => {
|
|
915
|
+
try {
|
|
916
|
+
return { value: Schema.resolve(value, this, {})[0] };
|
|
917
|
+
} catch (error) {
|
|
918
|
+
if (ValidationError.is(error)) return { issues: [{
|
|
919
|
+
message: error.message,
|
|
920
|
+
path: error.options.path
|
|
921
|
+
}] };
|
|
922
|
+
throw error;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
} });
|
|
927
|
+
Schema.ValidationError = ValidationError;
|
|
928
|
+
Schema.prototype.toJSON = function toJSON() {
|
|
929
|
+
if (globalThis.__schemastery_refs__) {
|
|
930
|
+
globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
|
|
931
|
+
return this.uid;
|
|
932
|
+
}
|
|
933
|
+
globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
|
|
934
|
+
globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
|
|
935
|
+
const result = {
|
|
936
|
+
uid: this.uid,
|
|
937
|
+
refs: globalThis.__schemastery_refs__
|
|
938
|
+
};
|
|
939
|
+
globalThis.__schemastery_refs__ = void 0;
|
|
940
|
+
return result;
|
|
941
|
+
};
|
|
942
|
+
Schema.prototype.set = function set(key, value) {
|
|
943
|
+
this.dict[key] = value;
|
|
944
|
+
return this;
|
|
945
|
+
};
|
|
946
|
+
Schema.prototype.push = function push(value) {
|
|
947
|
+
this.list.push(value);
|
|
948
|
+
return this;
|
|
949
|
+
};
|
|
950
|
+
function mergeDesc(original, messages) {
|
|
951
|
+
const result = typeof original === "string" ? { "": original } : { ...original };
|
|
952
|
+
for (const locale in messages) {
|
|
953
|
+
const value = messages[locale];
|
|
954
|
+
if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
|
|
955
|
+
else if (typeof value === "string") result[locale] = value;
|
|
956
|
+
}
|
|
957
|
+
return result;
|
|
958
|
+
}
|
|
959
|
+
function getInner(value) {
|
|
960
|
+
return value?.$value ?? value?.$inner;
|
|
961
|
+
}
|
|
962
|
+
function extractKeys(data) {
|
|
963
|
+
return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
|
|
964
|
+
}
|
|
965
|
+
Schema.prototype.i18n = function i18n(messages) {
|
|
966
|
+
const schema = Schema(this);
|
|
967
|
+
const desc = mergeDesc(schema.meta.description, messages);
|
|
968
|
+
if (Object.keys(desc).length) schema.meta.description = desc;
|
|
969
|
+
if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
|
|
970
|
+
return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
|
|
971
|
+
});
|
|
972
|
+
if (schema.list) schema.list = schema.list.map((inner, index) => {
|
|
973
|
+
return inner.i18n(mapValues(messages, (data = {}) => {
|
|
974
|
+
if (Array.isArray(getInner(data))) return getInner(data)[index];
|
|
975
|
+
if (Array.isArray(data)) return data[index];
|
|
976
|
+
return extractKeys(data);
|
|
977
|
+
}));
|
|
978
|
+
});
|
|
979
|
+
if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
|
|
980
|
+
if (getInner(data)) return getInner(data);
|
|
981
|
+
return extractKeys(data);
|
|
982
|
+
}));
|
|
983
|
+
if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
|
|
984
|
+
return schema;
|
|
985
|
+
};
|
|
986
|
+
Schema.prototype.extra = function extra(key, value) {
|
|
987
|
+
const schema = Schema(this);
|
|
988
|
+
schema.meta = {
|
|
989
|
+
...schema.meta,
|
|
990
|
+
[key]: value
|
|
991
|
+
};
|
|
992
|
+
return schema;
|
|
993
|
+
};
|
|
994
|
+
for (const key of [
|
|
995
|
+
"required",
|
|
996
|
+
"disabled",
|
|
997
|
+
"collapse",
|
|
998
|
+
"hidden",
|
|
999
|
+
"loose"
|
|
1000
|
+
]) Object.assign(Schema.prototype, { [key](value = true) {
|
|
1001
|
+
const schema = Schema(this);
|
|
1002
|
+
schema.meta = {
|
|
1003
|
+
...schema.meta,
|
|
1004
|
+
[key]: value
|
|
1005
|
+
};
|
|
1006
|
+
return schema;
|
|
1007
|
+
} });
|
|
1008
|
+
Schema.prototype.deprecated = function deprecated() {
|
|
1009
|
+
const schema = Schema(this);
|
|
1010
|
+
schema.meta.badges ||= [];
|
|
1011
|
+
schema.meta.badges.push({
|
|
1012
|
+
text: "deprecated",
|
|
1013
|
+
type: "danger"
|
|
1014
|
+
});
|
|
1015
|
+
return schema;
|
|
1016
|
+
};
|
|
1017
|
+
Schema.prototype.experimental = function experimental() {
|
|
1018
|
+
const schema = Schema(this);
|
|
1019
|
+
schema.meta.badges ||= [];
|
|
1020
|
+
schema.meta.badges.push({
|
|
1021
|
+
text: "experimental",
|
|
1022
|
+
type: "warning"
|
|
1023
|
+
});
|
|
1024
|
+
return schema;
|
|
1025
|
+
};
|
|
1026
|
+
Schema.prototype.pattern = function pattern(regexp) {
|
|
1027
|
+
const schema = Schema(this);
|
|
1028
|
+
const pattern = pick(regexp, ["source", "flags"]);
|
|
1029
|
+
schema.meta = {
|
|
1030
|
+
...schema.meta,
|
|
1031
|
+
pattern
|
|
1032
|
+
};
|
|
1033
|
+
return schema;
|
|
1034
|
+
};
|
|
1035
|
+
Schema.prototype.simplify = function simplify(value) {
|
|
1036
|
+
if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
|
|
1037
|
+
if (isNullable(value)) return value;
|
|
1038
|
+
if (this.type === "object" || this.type === "dict") {
|
|
1039
|
+
const result = {};
|
|
1040
|
+
for (const key in value) {
|
|
1041
|
+
const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
|
|
1042
|
+
if (this.type === "dict" || !isNullable(item)) result[key] = item;
|
|
1043
|
+
}
|
|
1044
|
+
if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
|
|
1045
|
+
return result;
|
|
1046
|
+
} else if (this.type === "array" || this.type === "tuple") {
|
|
1047
|
+
const result = [];
|
|
1048
|
+
value.forEach((value, index) => {
|
|
1049
|
+
const schema = this.type === "array" ? this.inner : this.list[index];
|
|
1050
|
+
const item = schema ? schema.simplify(value) : value;
|
|
1051
|
+
result.push(item);
|
|
1052
|
+
});
|
|
1053
|
+
return result;
|
|
1054
|
+
} else if (this.type === "intersect") {
|
|
1055
|
+
const result = {};
|
|
1056
|
+
for (const item of this.list) Object.assign(result, item.simplify(value));
|
|
1057
|
+
return result;
|
|
1058
|
+
} else if (this.type === "union") for (const schema of this.list) try {
|
|
1059
|
+
Schema.resolve(value, schema, {});
|
|
1060
|
+
return schema.simplify(value);
|
|
1061
|
+
} catch {}
|
|
1062
|
+
return value;
|
|
1063
|
+
};
|
|
1064
|
+
Schema.prototype.toString = function toString(inline) {
|
|
1065
|
+
return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
|
|
1066
|
+
};
|
|
1067
|
+
Schema.prototype.role = function role(role, extra) {
|
|
1068
|
+
const schema = Schema(this);
|
|
1069
|
+
schema.meta = {
|
|
1070
|
+
...schema.meta,
|
|
1071
|
+
role,
|
|
1072
|
+
extra
|
|
1073
|
+
};
|
|
1074
|
+
return schema;
|
|
1075
|
+
};
|
|
1076
|
+
for (const key of [
|
|
1077
|
+
"default",
|
|
1078
|
+
"link",
|
|
1079
|
+
"comment",
|
|
1080
|
+
"description",
|
|
1081
|
+
"max",
|
|
1082
|
+
"min",
|
|
1083
|
+
"step"
|
|
1084
|
+
]) Object.assign(Schema.prototype, { [key](value) {
|
|
1085
|
+
const schema = Schema(this);
|
|
1086
|
+
schema.meta = {
|
|
1087
|
+
...schema.meta,
|
|
1088
|
+
[key]: value
|
|
1089
|
+
};
|
|
1090
|
+
return schema;
|
|
1091
|
+
} });
|
|
1092
|
+
const resolvers = {};
|
|
1093
|
+
Schema.extend = function extend(type, resolve) {
|
|
1094
|
+
resolvers[type] = resolve;
|
|
1095
|
+
};
|
|
1096
|
+
Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
|
|
1097
|
+
if (!schema) return [data];
|
|
1098
|
+
if (options.ignore?.(data, schema)) return [data];
|
|
1099
|
+
if (isNullable(data) && schema.type !== "lazy") {
|
|
1100
|
+
if (schema.meta.required) throw new ValidationError(`missing required value`, options);
|
|
1101
|
+
let current = schema;
|
|
1102
|
+
let fallback = schema.meta.default;
|
|
1103
|
+
while (current?.type === "intersect" && isNullable(fallback)) {
|
|
1104
|
+
current = current.list[0];
|
|
1105
|
+
fallback = current?.meta.default;
|
|
1106
|
+
}
|
|
1107
|
+
if (isNullable(fallback)) return [data];
|
|
1108
|
+
data = clone(fallback);
|
|
1109
|
+
}
|
|
1110
|
+
const callback = resolvers[schema.type];
|
|
1111
|
+
if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
|
|
1112
|
+
try {
|
|
1113
|
+
return callback(data, schema, options, strict);
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
if (!schema.meta.loose) throw error;
|
|
1116
|
+
return [schema.meta.default];
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
Schema.from = function from(source) {
|
|
1120
|
+
if (isNullable(source)) return Schema.any();
|
|
1121
|
+
else if ([
|
|
1122
|
+
"string",
|
|
1123
|
+
"number",
|
|
1124
|
+
"boolean"
|
|
1125
|
+
].includes(typeof source)) return Schema.const(source).required();
|
|
1126
|
+
else if (source[kSchema]) return source;
|
|
1127
|
+
else if (typeof source === "function") switch (source) {
|
|
1128
|
+
case String: return Schema.string().required();
|
|
1129
|
+
case Number: return Schema.number().required();
|
|
1130
|
+
case Boolean: return Schema.boolean().required();
|
|
1131
|
+
case Function: return Schema.function().required();
|
|
1132
|
+
default: return Schema.is(source).required();
|
|
1133
|
+
}
|
|
1134
|
+
else throw new TypeError(`cannot infer schema from ${source}`);
|
|
1135
|
+
};
|
|
1136
|
+
Schema.lazy = function lazy(builder) {
|
|
1137
|
+
const toJSON = () => {
|
|
1138
|
+
if (!schema.inner[kSchema]) {
|
|
1139
|
+
schema.inner = schema.builder();
|
|
1140
|
+
schema.inner.meta = {
|
|
1141
|
+
...schema.meta,
|
|
1142
|
+
...schema.inner.meta
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
return schema.inner.toJSON();
|
|
1146
|
+
};
|
|
1147
|
+
const schema = new Schema({
|
|
1148
|
+
type: "lazy",
|
|
1149
|
+
builder,
|
|
1150
|
+
inner: { toJSON }
|
|
1151
|
+
});
|
|
1152
|
+
return schema;
|
|
1153
|
+
};
|
|
1154
|
+
Schema.natural = function natural() {
|
|
1155
|
+
return Schema.number().step(1).min(0);
|
|
1156
|
+
};
|
|
1157
|
+
Schema.percent = function percent() {
|
|
1158
|
+
return Schema.number().step(.01).min(0).max(1).role("slider");
|
|
1159
|
+
};
|
|
1160
|
+
Schema.date = function date() {
|
|
1161
|
+
return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
|
|
1162
|
+
const date = new Date(value);
|
|
1163
|
+
if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
|
|
1164
|
+
return date;
|
|
1165
|
+
}, true)]);
|
|
1166
|
+
};
|
|
1167
|
+
Schema.regExp = function regExp(flag = "") {
|
|
1168
|
+
return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
|
|
1169
|
+
try {
|
|
1170
|
+
return new RegExp(value, flag);
|
|
1171
|
+
} catch (e) {
|
|
1172
|
+
throw new ValidationError(e.message, options);
|
|
1173
|
+
}
|
|
1174
|
+
}, true)]);
|
|
1175
|
+
};
|
|
1176
|
+
Schema.arrayBuffer = function arrayBuffer(encoding) {
|
|
1177
|
+
return Schema.union([
|
|
1178
|
+
Schema.is(ArrayBuffer),
|
|
1179
|
+
Schema.is(SharedArrayBuffer),
|
|
1180
|
+
Schema.transform(Schema.any(), (value, options) => {
|
|
1181
|
+
if (Binary.isSource(value)) return Binary.fromSource(value);
|
|
1182
|
+
throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
|
|
1183
|
+
}, true),
|
|
1184
|
+
...encoding ? [Schema.transform(Schema.string(), (value, options) => {
|
|
1185
|
+
try {
|
|
1186
|
+
return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
throw new ValidationError(e.message, options);
|
|
1189
|
+
}
|
|
1190
|
+
}, true)] : []
|
|
1191
|
+
]);
|
|
1192
|
+
};
|
|
1193
|
+
Schema.extend("lazy", (data, schema, options, strict) => {
|
|
1194
|
+
if (!schema.inner[kSchema]) {
|
|
1195
|
+
schema.inner = schema.builder();
|
|
1196
|
+
schema.inner.meta = {
|
|
1197
|
+
...schema.meta,
|
|
1198
|
+
...schema.inner.meta
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
return Schema.resolve(data, schema.inner, options, strict);
|
|
1202
|
+
});
|
|
1203
|
+
Schema.extend("any", (data) => {
|
|
1204
|
+
return [data];
|
|
1205
|
+
});
|
|
1206
|
+
Schema.extend("never", (data, _, options) => {
|
|
1207
|
+
throw new ValidationError(`expected nullable but got ${data}`, options);
|
|
1208
|
+
});
|
|
1209
|
+
Schema.extend("const", (data, { value }, options) => {
|
|
1210
|
+
if (deepEqual(data, value)) return [value];
|
|
1211
|
+
throw new ValidationError(`expected ${value} but got ${data}`, options);
|
|
1212
|
+
});
|
|
1213
|
+
function checkWithinRange(data, meta, description, options, skipMin = false) {
|
|
1214
|
+
const { max = Infinity, min = -Infinity } = meta;
|
|
1215
|
+
if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
|
|
1216
|
+
if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
|
|
1217
|
+
}
|
|
1218
|
+
Schema.extend("string", (data, { meta }, options) => {
|
|
1219
|
+
if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
|
|
1220
|
+
if (meta.pattern) {
|
|
1221
|
+
const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
|
|
1222
|
+
if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
|
|
1223
|
+
}
|
|
1224
|
+
checkWithinRange(data.length, meta, "string length", options);
|
|
1225
|
+
return [data];
|
|
1226
|
+
});
|
|
1227
|
+
function decimalShift(data, digits) {
|
|
1228
|
+
const str = data.toString();
|
|
1229
|
+
if (str.includes("e")) return data * Math.pow(10, digits);
|
|
1230
|
+
const index = str.indexOf(".");
|
|
1231
|
+
if (index === -1) return data * Math.pow(10, digits);
|
|
1232
|
+
const frac = str.slice(index + 1);
|
|
1233
|
+
const integer = str.slice(0, index);
|
|
1234
|
+
if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
|
|
1235
|
+
return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
|
|
1236
|
+
}
|
|
1237
|
+
function isMultipleOf(data, min, step) {
|
|
1238
|
+
step = Math.abs(step);
|
|
1239
|
+
if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
|
|
1240
|
+
const index = step.toString().indexOf(".");
|
|
1241
|
+
const digits = step.toString().slice(index + 1).length;
|
|
1242
|
+
return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
|
|
1243
|
+
}
|
|
1244
|
+
Schema.extend("number", (data, { meta }, options) => {
|
|
1245
|
+
if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
|
|
1246
|
+
checkWithinRange(data, meta, "number", options);
|
|
1247
|
+
const { step } = meta;
|
|
1248
|
+
if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
|
|
1249
|
+
return [data];
|
|
1250
|
+
});
|
|
1251
|
+
Schema.extend("boolean", (data, _, options) => {
|
|
1252
|
+
if (typeof data === "boolean") return [data];
|
|
1253
|
+
throw new ValidationError(`expected boolean but got ${data}`, options);
|
|
1254
|
+
});
|
|
1255
|
+
Schema.extend("bitset", (data, { bits, meta }, options) => {
|
|
1256
|
+
let value = 0, keys = [];
|
|
1257
|
+
if (typeof data === "number") {
|
|
1258
|
+
value = data;
|
|
1259
|
+
for (const key in bits) if (data & bits[key]) keys.push(key);
|
|
1260
|
+
} else if (Array.isArray(data)) {
|
|
1261
|
+
keys = data;
|
|
1262
|
+
for (const key of keys) {
|
|
1263
|
+
if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
|
|
1264
|
+
if (key in bits) value |= bits[key];
|
|
1265
|
+
}
|
|
1266
|
+
} else throw new ValidationError(`expected number or array but got ${data}`, options);
|
|
1267
|
+
if (value === meta.default) return [value];
|
|
1268
|
+
return [value, keys];
|
|
1269
|
+
});
|
|
1270
|
+
Schema.extend("function", (data, _, options) => {
|
|
1271
|
+
if (typeof data === "function") return [data];
|
|
1272
|
+
throw new ValidationError(`expected function but got ${data}`, options);
|
|
1273
|
+
});
|
|
1274
|
+
Schema.extend("is", (data, { constructor }, options) => {
|
|
1275
|
+
if (typeof constructor === "function") {
|
|
1276
|
+
if (data instanceof constructor) return [data];
|
|
1277
|
+
throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
|
|
1278
|
+
} else {
|
|
1279
|
+
if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
1280
|
+
let prototype = Object.getPrototypeOf(data);
|
|
1281
|
+
while (prototype) {
|
|
1282
|
+
if (prototype.constructor?.name === constructor) return [data];
|
|
1283
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
1284
|
+
}
|
|
1285
|
+
throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
function property(data, key, schema, options) {
|
|
1289
|
+
try {
|
|
1290
|
+
const [value, adapted] = Schema.resolve(data[key], schema, {
|
|
1291
|
+
...options,
|
|
1292
|
+
path: [...options.path || [], key]
|
|
1293
|
+
});
|
|
1294
|
+
if (adapted !== void 0) data[key] = adapted;
|
|
1295
|
+
return value;
|
|
1296
|
+
} catch (e) {
|
|
1297
|
+
if (!options?.autofix) throw e;
|
|
1298
|
+
delete data[key];
|
|
1299
|
+
return schema.meta.default;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
Schema.extend("array", (data, { inner, meta }, options) => {
|
|
1303
|
+
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
1304
|
+
checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
|
|
1305
|
+
return [data.map((_, index) => property(data, index, inner, options))];
|
|
1306
|
+
});
|
|
1307
|
+
Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
|
|
1308
|
+
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
1309
|
+
const result = {};
|
|
1310
|
+
for (const key in data) {
|
|
1311
|
+
let rKey;
|
|
1312
|
+
try {
|
|
1313
|
+
rKey = Schema.resolve(key, sKey, options)[0];
|
|
1314
|
+
} catch (error) {
|
|
1315
|
+
if (strict) continue;
|
|
1316
|
+
throw error;
|
|
1317
|
+
}
|
|
1318
|
+
result[rKey] = property(data, key, inner, options);
|
|
1319
|
+
data[rKey] = data[key];
|
|
1320
|
+
if (key !== rKey) delete data[key];
|
|
1321
|
+
}
|
|
1322
|
+
return [result];
|
|
1323
|
+
});
|
|
1324
|
+
Schema.extend("tuple", (data, { list }, options, strict) => {
|
|
1325
|
+
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
1326
|
+
const result = list.map((inner, index) => property(data, index, inner, options));
|
|
1327
|
+
if (strict) return [result];
|
|
1328
|
+
result.push(...data.slice(list.length));
|
|
1329
|
+
return [result];
|
|
1330
|
+
});
|
|
1331
|
+
function merge(result, data) {
|
|
1332
|
+
for (const key in data) {
|
|
1333
|
+
if (key in result) continue;
|
|
1334
|
+
result[key] = data[key];
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
Schema.extend("object", (data, { dict }, options, strict) => {
|
|
1338
|
+
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
1339
|
+
const result = {};
|
|
1340
|
+
for (const key in dict) {
|
|
1341
|
+
const value = property(data, key, dict[key], options);
|
|
1342
|
+
if (!isNullable(value) || key in data) result[key] = value;
|
|
1343
|
+
}
|
|
1344
|
+
if (!strict) merge(result, data);
|
|
1345
|
+
return [result];
|
|
1346
|
+
});
|
|
1347
|
+
Schema.extend("union", (data, { list, toString }, options, strict) => {
|
|
1348
|
+
const messages = [];
|
|
1349
|
+
for (const inner of list) try {
|
|
1350
|
+
return Schema.resolve(data, inner, options, strict);
|
|
1351
|
+
} catch (error) {
|
|
1352
|
+
messages.push(error);
|
|
1353
|
+
}
|
|
1354
|
+
throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
1355
|
+
});
|
|
1356
|
+
Schema.extend("intersect", (data, { list, toString }, options, strict) => {
|
|
1357
|
+
if (!list.length) return [data];
|
|
1358
|
+
let result;
|
|
1359
|
+
for (const inner of list) {
|
|
1360
|
+
const value = Schema.resolve(data, inner, options, true)[0];
|
|
1361
|
+
if (isNullable(value)) continue;
|
|
1362
|
+
if (isNullable(result)) result = value;
|
|
1363
|
+
else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
1364
|
+
else if (typeof value === "object") merge(result ??= {}, value);
|
|
1365
|
+
else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
1366
|
+
}
|
|
1367
|
+
if (!strict && isPlainObject(data)) merge(result, data);
|
|
1368
|
+
return [result];
|
|
1369
|
+
});
|
|
1370
|
+
Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
|
|
1371
|
+
const [result, adapted = data] = Schema.resolve(data, inner, options, true);
|
|
1372
|
+
if (preserve) return [callback(result)];
|
|
1373
|
+
else return [callback(result), callback(adapted)];
|
|
1374
|
+
});
|
|
1375
|
+
const formatters = {};
|
|
1376
|
+
function defineMethod(name, keys, format) {
|
|
1377
|
+
formatters[name] = format;
|
|
1378
|
+
Object.assign(Schema, { [name](...args) {
|
|
1379
|
+
const schema = new Schema({ type: name });
|
|
1380
|
+
keys.forEach((key, index) => {
|
|
1381
|
+
switch (key) {
|
|
1382
|
+
case "sKey":
|
|
1383
|
+
schema.sKey = args[index] ?? Schema.string();
|
|
1384
|
+
break;
|
|
1385
|
+
case "inner":
|
|
1386
|
+
schema.inner = Schema.from(args[index]);
|
|
1387
|
+
break;
|
|
1388
|
+
case "list":
|
|
1389
|
+
schema.list = args[index].map(Schema.from);
|
|
1390
|
+
break;
|
|
1391
|
+
case "dict":
|
|
1392
|
+
schema.dict = mapValues(args[index], Schema.from);
|
|
1393
|
+
break;
|
|
1394
|
+
case "bits":
|
|
1395
|
+
schema.bits = {};
|
|
1396
|
+
for (const key in args[index]) {
|
|
1397
|
+
if (typeof args[index][key] !== "number") continue;
|
|
1398
|
+
schema.bits[key] = args[index][key];
|
|
1399
|
+
}
|
|
1400
|
+
break;
|
|
1401
|
+
case "callback": {
|
|
1402
|
+
const callback = schema.callback = args[index];
|
|
1403
|
+
callback["toJSON"] ||= () => callback.toString();
|
|
1404
|
+
break;
|
|
1405
|
+
}
|
|
1406
|
+
case "constructor": {
|
|
1407
|
+
const constructor = schema.constructor = args[index];
|
|
1408
|
+
if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
|
|
1409
|
+
break;
|
|
1410
|
+
}
|
|
1411
|
+
default: schema[key] = args[index];
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
if (name === "object" || name === "dict") schema.meta.default = {};
|
|
1415
|
+
else if (name === "array" || name === "tuple") schema.meta.default = [];
|
|
1416
|
+
else if (name === "bitset") schema.meta.default = 0;
|
|
1417
|
+
return schema;
|
|
1418
|
+
} });
|
|
1419
|
+
}
|
|
1420
|
+
defineMethod("is", ["constructor"], ({ constructor }) => {
|
|
1421
|
+
if (typeof constructor === "function") return constructor.name;
|
|
1422
|
+
else return constructor;
|
|
1423
|
+
});
|
|
1424
|
+
defineMethod("any", [], () => "any");
|
|
1425
|
+
defineMethod("never", [], () => "never");
|
|
1426
|
+
defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
|
|
1427
|
+
defineMethod("string", [], () => "string");
|
|
1428
|
+
defineMethod("number", [], () => "number");
|
|
1429
|
+
defineMethod("boolean", [], () => "boolean");
|
|
1430
|
+
defineMethod("bitset", ["bits"], () => "bitset");
|
|
1431
|
+
defineMethod("function", [], () => "function");
|
|
1432
|
+
defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
|
|
1433
|
+
defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
|
|
1434
|
+
defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
|
|
1435
|
+
defineMethod("object", ["dict"], ({ dict }) => {
|
|
1436
|
+
if (Object.keys(dict).length === 0) return "{}";
|
|
1437
|
+
return `{ ${Object.entries(dict).map(([key, inner]) => {
|
|
1438
|
+
return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
|
|
1439
|
+
}).join(", ")} }`;
|
|
1440
|
+
});
|
|
1441
|
+
defineMethod("union", ["list"], ({ list }, inline) => {
|
|
1442
|
+
const result = list.map(({ toString: format }) => format()).join(" | ");
|
|
1443
|
+
return inline ? `(${result})` : result;
|
|
1444
|
+
});
|
|
1445
|
+
defineMethod("intersect", ["list"], ({ list }) => {
|
|
1446
|
+
return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
|
|
1447
|
+
});
|
|
1448
|
+
defineMethod("transform", [
|
|
1449
|
+
"inner",
|
|
1450
|
+
"callback",
|
|
1451
|
+
"preserve"
|
|
1452
|
+
], ({ inner }, isInner) => inner.toString(isInner));
|
|
1453
|
+
//#endregion
|
|
1454
|
+
//#region lib/types/theme-store-settings.js
|
|
1455
|
+
/** Theme store settings stored in the Host user-settings document. */
|
|
1456
|
+
/** Settings namespace owned by the theme store plugin. */
|
|
1457
|
+
const THEME_STORE_NAMESPACE = "ui-theme-store";
|
|
1458
|
+
Schema.object({ ["applied"]: Schema.string().default("") });
|
|
1459
|
+
//#endregion
|
|
1460
|
+
//#region lib/types/client/index.js
|
|
1461
|
+
/** Namespace owning this feature's settings-row copy. */
|
|
1462
|
+
const SETTINGS_NS = "settings.themeStore";
|
|
1463
|
+
/**
|
|
1464
|
+
* Required services: slots/locale for the section, the settings scope for the
|
|
1465
|
+
* durable applied id, the harness theme service, the remote transport, and
|
|
1466
|
+
* the plugin inventory Remote to detect installed shell themes.
|
|
1467
|
+
*/
|
|
1468
|
+
const inject = [
|
|
1469
|
+
"slots",
|
|
1470
|
+
"locale",
|
|
1471
|
+
"settingsScope",
|
|
1472
|
+
"theme",
|
|
1473
|
+
"remote",
|
|
1474
|
+
"remote.pluginInventory"
|
|
1475
|
+
];
|
|
1476
|
+
/**
|
|
1477
|
+
* Client plugin body: provide the theme store service and register the
|
|
1478
|
+
* feature-owned Theme Store settings section. On boot, also queries the
|
|
1479
|
+
* plugin inventory to detect which shell themes are already installed.
|
|
1480
|
+
* @param ctx - client cordis context.
|
|
1481
|
+
*/
|
|
1482
|
+
function apply(ctx) {
|
|
1483
|
+
console.log("[theme-store] 🎨 apply(): theme store plugin ACTIVATED in browser", {
|
|
1484
|
+
inject: inject.length,
|
|
1485
|
+
url: typeof location !== "undefined" ? location.href : "n/a"
|
|
1486
|
+
});
|
|
1487
|
+
ctx.effect(() => ctx.locale.register(SETTINGS_NS, {
|
|
1488
|
+
zh,
|
|
1489
|
+
en
|
|
1490
|
+
}), "theme-store: dictionaries");
|
|
1491
|
+
const t = ctx.locale.bind(SETTINGS_NS);
|
|
1492
|
+
const runtime = new ThemeStoreRuntime(ctx, ctx.settingsScope.bind({ namespace: THEME_STORE_NAMESPACE }), ctx.theme);
|
|
1493
|
+
ctx.provide("themeStore", runtime);
|
|
1494
|
+
ctx.effect(() => () => {
|
|
1495
|
+
runtime.dispose();
|
|
1496
|
+
}, "theme-store: runtime disposal");
|
|
1497
|
+
const store = createThemeStoreStore();
|
|
1498
|
+
let bound;
|
|
1499
|
+
const sync = () => {
|
|
1500
|
+
bound?.sync(runtime.getState());
|
|
1501
|
+
};
|
|
1502
|
+
ctx.effect(() => runtime.subscribe(sync), "theme-store: section mirror");
|
|
1503
|
+
const injected = (actions) => {
|
|
1504
|
+
bound = actions;
|
|
1505
|
+
sync();
|
|
1506
|
+
return {
|
|
1507
|
+
load: () => {
|
|
1508
|
+
runtime.load();
|
|
1509
|
+
},
|
|
1510
|
+
apply: (id) => {
|
|
1511
|
+
runtime.apply(id);
|
|
1512
|
+
},
|
|
1513
|
+
copyInstall: (command) => {
|
|
1514
|
+
navigator.clipboard?.writeText(command).catch(() => {});
|
|
1515
|
+
},
|
|
1516
|
+
installShell: async (installPackage, onStage, marker) => {
|
|
1517
|
+
console.log("[theme-store] installShell called:", installPackage);
|
|
1518
|
+
onStage?.("installing");
|
|
1519
|
+
const result = await (await fetch("/api/theme-store/install", {
|
|
1520
|
+
method: "POST",
|
|
1521
|
+
headers: { "content-type": "application/json" },
|
|
1522
|
+
body: JSON.stringify({ installPackage })
|
|
1523
|
+
})).json().catch(() => ({
|
|
1524
|
+
ok: false,
|
|
1525
|
+
error: "invalid response"
|
|
1526
|
+
}));
|
|
1527
|
+
console.log("[theme-store] install response:", JSON.stringify(result));
|
|
1528
|
+
if (result.ok !== true) throw new Error(result.error ?? "install failed");
|
|
1529
|
+
if (result.changed !== false) {
|
|
1530
|
+
onStage?.("restarting");
|
|
1531
|
+
console.log("[theme-store] requesting restart");
|
|
1532
|
+
await fetch("/api/theme-store/restart", { method: "POST" }).catch((error) => {
|
|
1533
|
+
console.log("[theme-store] restart fetch error (expected, server respawning):", String(error));
|
|
1534
|
+
});
|
|
1535
|
+
onStage?.("reloading");
|
|
1536
|
+
console.log("[theme-store] waiting for server to come back");
|
|
1537
|
+
await waitForServer();
|
|
1538
|
+
if (marker !== void 0) try {
|
|
1539
|
+
window.sessionStorage.setItem(LAST_INSTALL_KEY, JSON.stringify(marker));
|
|
1540
|
+
console.log("[theme-store] last-install marker written:", JSON.stringify(marker));
|
|
1541
|
+
} catch {}
|
|
1542
|
+
console.log("[theme-store] server back, reloading page");
|
|
1543
|
+
window.location.reload();
|
|
1544
|
+
} else console.log("[theme-store] no change needed (already active)");
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
};
|
|
1548
|
+
ctx.slots.inject("settings.section", () => {
|
|
1549
|
+
console.log("[theme-store] settings.section registration running");
|
|
1550
|
+
return ctx.slots.register({
|
|
1551
|
+
name: "settings.section",
|
|
1552
|
+
id: "theme-store",
|
|
1553
|
+
order: 12,
|
|
1554
|
+
label: () => t("nav"),
|
|
1555
|
+
locale: SETTINGS_NS,
|
|
1556
|
+
store,
|
|
1557
|
+
inject: injected
|
|
1558
|
+
}, ThemeStoreSection);
|
|
1559
|
+
});
|
|
1560
|
+
runtime.load();
|
|
1561
|
+
(async () => {
|
|
1562
|
+
try {
|
|
1563
|
+
const result = await ctx.remote.pluginInventory.list();
|
|
1564
|
+
if (!result.ok) return;
|
|
1565
|
+
const moduleNames = result.value.entries.filter((e) => e.enabled).map((e) => e.moduleName);
|
|
1566
|
+
runtime.syncInstalledShells(moduleNames);
|
|
1567
|
+
} catch {}
|
|
1568
|
+
})();
|
|
1569
|
+
}
|
|
1570
|
+
/** Poll the GUI until it responds, then return. Used after a restart-respawn. */
|
|
1571
|
+
async function waitForServer() {
|
|
1572
|
+
for (let attempt = 0; attempt < 60; attempt++) {
|
|
1573
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
1574
|
+
try {
|
|
1575
|
+
if ((await fetch("/catalog/edex-themes.json", { method: "HEAD" })).ok) return;
|
|
1576
|
+
} catch {}
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
//#endregion
|
|
1580
|
+
exports.SETTINGS_NS = SETTINGS_NS;
|
|
1581
|
+
exports.ThemeStoreRuntime = ThemeStoreRuntime;
|
|
1582
|
+
exports.apply = apply;
|
|
1583
|
+
exports.createThemeStoreStore = createThemeStoreStore;
|
|
1584
|
+
exports.inject = inject;
|
|
1585
|
+
exports.parseCatalog = parseCatalog;
|
|
1586
|
+
exports.resolveScreenshot = resolveScreenshot;
|
|
1587
|
+
return module.exports;
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
//# sourceMappingURL=client.js.map
|