dsh-edge 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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +183 -0
- package/README.zh.md +183 -0
- package/THIRD_PARTY_NOTICES.md +199 -0
- package/dist/_headers +3 -0
- package/dist/assets/fonts/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/fonts/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/fonts/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/fonts/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/fonts/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/fonts/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/fonts/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/fonts/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/fonts/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/fonts/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/fonts/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/fonts/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/fonts/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/fonts/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/fonts/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/fonts/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/fonts/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/fonts/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/index-C-1AiF3k.js +112 -0
- package/dist/assets/index-CSGf6Qzd.css +1 -0
- package/dist/assets/langs/c-BIGW1oBm.js +2 -0
- package/dist/assets/langs/cpp-DIPi6g--.js +2 -0
- package/dist/assets/langs/csharp-DSvCPggb.js +2 -0
- package/dist/assets/langs/css-CLj8gQPS.js +2 -0
- package/dist/assets/langs/go-C27-OAKa.js +2 -0
- package/dist/assets/langs/html-CfGypltT.js +2 -0
- package/dist/assets/langs/ini-BEwlwnbL.js +2 -0
- package/dist/assets/langs/java-CylS5w8V.js +2 -0
- package/dist/assets/langs/kotlin-BdnUsdx6.js +2 -0
- package/dist/assets/langs/less-B1dDrJ26.js +2 -0
- package/dist/assets/langs/lua-BaeVxFsk.js +2 -0
- package/dist/assets/langs/markdown-Cvjx9yec.js +2 -0
- package/dist/assets/langs/mdx-Cmh6b_Ma.js +2 -0
- package/dist/assets/langs/php-D-uCvoST.js +2 -0
- package/dist/assets/langs/python-B6aJPvgy.js +2 -0
- package/dist/assets/langs/ruby-DEItuUFs.js +2 -0
- package/dist/assets/langs/rust-B1yitclQ.js +2 -0
- package/dist/assets/langs/scss-D5BDwBP9.js +2 -0
- package/dist/assets/langs/sql-CRqJ_cUM.js +2 -0
- package/dist/assets/langs/swift-D82vCrfD.js +2 -0
- package/dist/assets/langs/toml-vGWfd6FD.js +2 -0
- package/dist/assets/langs/xml-sdJ4AIDG.js +2 -0
- package/dist/assets/langs/yaml-Buea-lGh.js +2 -0
- package/dist/assets/vendor-Cjbwl5VI.js +411 -0
- package/dist/assets/vendor-CjyC-hUb.css +1 -0
- package/dist/favicon.svg +8 -0
- package/dist/index.html +35 -0
- package/dist/manifest.webmanifest +16 -0
- package/dist/plugins/@deepseek-ai/dsh-api-gateway/client.js +420 -0
- package/dist/plugins/@deepseek-ai/dsh-api-remotes/client.js +5937 -0
- package/dist/plugins/@deepseek-ai/dsh-client-connection/client.js +10207 -0
- package/dist/plugins/@deepseek-ai/dsh-client-locale/client.js +1231 -0
- package/dist/plugins/@deepseek-ai/dsh-client-modules/client.js +259 -0
- package/dist/plugins/@deepseek-ai/dsh-client-runtime/client.js +10539 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-agent-preset/client.js +1725 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-commands/client.js +1116 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-conversation/client.js +9832 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-deliverables/client.js +373 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-edge/client.js +549 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-input-trigger/client.js +859 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-jobs/client.js +280 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-layout/client.js +456 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-model-selection/client.js +804 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-permission-presets/client.js +461 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings/client.js +254 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-general/client.js +609 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar/client.js +292 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-skill/client.js +327 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-subagent/client.js +710 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-theme/client.js +1312 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-tool/client.js +1630 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-trajectory/client.js +7370 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-user-questions/client.js +700 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-workflow-run/client.js +474 -0
- package/dist/plugins/@deepseek-ai/dsh-client-ui-workspace/client.js +2426 -0
- package/dist/plugins/@deepseek-ai/dsh-typert-registry/client.js +1372 -0
- package/package.json +97 -0
- package/scripts/assemble-web.mjs +230 -0
- package/scripts/bundle-size.d.mts +2 -0
- package/scripts/bundle-size.mjs +26 -0
- package/scripts/bundle.mjs +53 -0
- package/scripts/cli.d.mts +39 -0
- package/scripts/cli.mjs +496 -0
- package/scripts/install.d.mts +149 -0
- package/scripts/install.mjs +989 -0
- package/scripts/legal-files.mjs +24 -0
- package/scripts/verify-packed.mjs +32 -0
- package/scripts/wrangler-config.d.mts +18 -0
- package/scripts/wrangler-config.mjs +84 -0
- package/src/agent.ts +119 -0
- package/src/auth.ts +352 -0
- package/src/deepseek.ts +231 -0
- package/src/deployment.ts +147 -0
- package/src/direct-shell-core-empty.ts +10 -0
- package/src/direct-shell-protocol.ts +5 -0
- package/src/direct-shell.ts +341 -0
- package/src/do-session-persistence.ts +1064 -0
- package/src/edge-api.ts +796 -0
- package/src/edge-credentials.ts +56 -0
- package/src/edge-remotes.ts +41 -0
- package/src/edge-workspace-store.ts +339 -0
- package/src/http.ts +212 -0
- package/src/index.ts +196 -0
- package/src/instance.ts +1007 -0
- package/src/isolated-direct-shell-unavailable.ts +11 -0
- package/src/protocol.ts +39 -0
- package/src/release.ts +9 -0
- package/src/session-store.ts +1110 -0
- package/src/sse.ts +86 -0
- package/src/web-search.ts +38 -0
- package/src/workspace.ts +270 -0
- package/wrangler.jsonc +56 -0
|
@@ -0,0 +1,1312 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@deepseek-ai/dsh-client-ui-theme",
|
|
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 _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
9
|
+
let _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
|
|
10
|
+
//#region ../../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
11
|
+
function r(e) {
|
|
12
|
+
var t, f, n = "";
|
|
13
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
14
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
15
|
+
var o = e.length;
|
|
16
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
17
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
18
|
+
return n;
|
|
19
|
+
}
|
|
20
|
+
function clsx() {
|
|
21
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region \0dsh-css:/private/var/folders/nm/n5smty9962gf5rhjc5855kt80000gn/T/dsh-edge-release-worktree.XXXXXX.RcJjogaGt4/repo/packages/client/ui-theme/src/client/AppearanceRow.module.css.mjs
|
|
26
|
+
const css = ".vSHxGG_group{border-bottom:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:8px;padding:16px 0;display:flex}.vSHxGG_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}.vSHxGG_cubeRow{flex-wrap:wrap;align-items:stretch;gap:8px;display:flex}.vSHxGG_themeCube{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;background:0 0;border-radius:16px;flex-direction:column;flex:180px;justify-content:center;align-items:center;gap:4px;padding:20px 32px;font-size:14px;line-height:22px;display:flex}.vSHxGG_themeCube:hover:not(.vSHxGG_selected){background:var(--dsw-alias-interactive-bg-hover)}.vSHxGG_selected{background:var(--dsw-alias-bg-module-platform);border-color:var(--dsw-static-neutral-bluish-400)}";
|
|
27
|
+
const tagId = "@deepseek-ai/dsh-client-ui-theme/AppearanceRow.module.css";
|
|
28
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
29
|
+
const tag = document.createElement("style");
|
|
30
|
+
tag.dataset.plugin = "@deepseek-ai/dsh-client-ui-theme";
|
|
31
|
+
tag.dataset.pluginCss = tagId;
|
|
32
|
+
tag.textContent = css;
|
|
33
|
+
document.head.appendChild(tag);
|
|
34
|
+
}
|
|
35
|
+
var AppearanceRow_module_css_default = {
|
|
36
|
+
"title": "vSHxGG_title",
|
|
37
|
+
"themeCube": "vSHxGG_themeCube",
|
|
38
|
+
"selected": "vSHxGG_selected",
|
|
39
|
+
"group": "vSHxGG_group",
|
|
40
|
+
"cubeRow": "vSHxGG_cubeRow"
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region lib/types/client/AppearanceRow.js
|
|
44
|
+
/**
|
|
45
|
+
* Appearance preference row registered into the General section item slot
|
|
46
|
+
* (figma 501:30012 'Frame 2117131228'): title + three preference cubes.
|
|
47
|
+
* Registered by this package — the theme feature owns its own settings
|
|
48
|
+
* surface. Selection follows the persisted preference, never the resolved
|
|
49
|
+
* active theme.
|
|
50
|
+
*/
|
|
51
|
+
/** Cube order and icons (figma 501:30015-30017: Light, Dark, System). */
|
|
52
|
+
const CUBES = [
|
|
53
|
+
{
|
|
54
|
+
id: "light",
|
|
55
|
+
labelKey: "appearance.light",
|
|
56
|
+
Icon: _deepseek_ai_dsh_client_ui_primitives.IconLightOutline16
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "dark",
|
|
60
|
+
labelKey: "appearance.dark",
|
|
61
|
+
Icon: _deepseek_ai_dsh_client_ui_primitives.IconDarkOutline16
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "system",
|
|
65
|
+
labelKey: "appearance.system",
|
|
66
|
+
Icon: _deepseek_ai_dsh_client_ui_primitives.IconFollowsystemOutline16
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
* Render the Appearance row.
|
|
71
|
+
* @param props - composed slot props.
|
|
72
|
+
* @returns the row element tree.
|
|
73
|
+
*/
|
|
74
|
+
function AppearanceRow({ t, setTheme, useStore }) {
|
|
75
|
+
const preference = useStore((s) => s.preference);
|
|
76
|
+
return (0, react_jsx_runtime.jsxs)("div", {
|
|
77
|
+
className: AppearanceRow_module_css_default.group,
|
|
78
|
+
children: [(0, react_jsx_runtime.jsx)("div", {
|
|
79
|
+
className: AppearanceRow_module_css_default.title,
|
|
80
|
+
children: t("appearance.title")
|
|
81
|
+
}), (0, react_jsx_runtime.jsx)("div", {
|
|
82
|
+
className: AppearanceRow_module_css_default.cubeRow,
|
|
83
|
+
children: CUBES.map(({ id, labelKey, Icon }) => (0, react_jsx_runtime.jsxs)("button", {
|
|
84
|
+
type: "button",
|
|
85
|
+
className: clsx(AppearanceRow_module_css_default.themeCube, preference === id && AppearanceRow_module_css_default.selected),
|
|
86
|
+
"aria-pressed": preference === id,
|
|
87
|
+
onClick: () => {
|
|
88
|
+
setTheme(id);
|
|
89
|
+
},
|
|
90
|
+
children: [(0, react_jsx_runtime.jsx)(Icon, {}), t(labelKey)]
|
|
91
|
+
}, id))
|
|
92
|
+
})]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region lib/types/client/settings-store.js
|
|
97
|
+
/**
|
|
98
|
+
* Appearance row slot store: a mirror of the theme service snapshot. The
|
|
99
|
+
* plugin's apply-world change listener is the only writer; the row component
|
|
100
|
+
* reads via props.useStore.
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* Declares the Appearance row state and write surface.
|
|
104
|
+
* @returns the store handle.
|
|
105
|
+
*/
|
|
106
|
+
function createAppearanceRowStore() {
|
|
107
|
+
return (0, _deepseek_ai_dsh_client_runtime_client.defineStore)({
|
|
108
|
+
init: () => ({
|
|
109
|
+
preference: "system",
|
|
110
|
+
revision: -1
|
|
111
|
+
}),
|
|
112
|
+
actions: { sync: (d, preference, revision) => {
|
|
113
|
+
if (revision <= d.revision) return;
|
|
114
|
+
d.preference = preference;
|
|
115
|
+
d.revision = revision;
|
|
116
|
+
} }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region lib/types/client/locales.js
|
|
121
|
+
/** `settings.theme` namespace dictionaries (the Appearance row's copy). */
|
|
122
|
+
/** Simplified Chinese dictionary (the key-set source of truth). */
|
|
123
|
+
const zh = {
|
|
124
|
+
"appearance.title": "外观",
|
|
125
|
+
"appearance.light": "浅色",
|
|
126
|
+
"appearance.dark": "深色",
|
|
127
|
+
"appearance.system": "跟随系统"
|
|
128
|
+
};
|
|
129
|
+
/** English dictionary, checked complete against the zh key set. */
|
|
130
|
+
const en = {
|
|
131
|
+
"appearance.title": "Appearance",
|
|
132
|
+
"appearance.light": "Light",
|
|
133
|
+
"appearance.dark": "Dark",
|
|
134
|
+
"appearance.system": "System"
|
|
135
|
+
};
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region ../../../vendor/cosmokit/src/misc.ts
|
|
138
|
+
/** Return true when a value is `null` or `undefined`. */
|
|
139
|
+
function isNullable(value) {
|
|
140
|
+
return value === null || value === void 0;
|
|
141
|
+
}
|
|
142
|
+
/** Return true for non-array object values. */
|
|
143
|
+
function isPlainObject(data) {
|
|
144
|
+
return data && typeof data === "object" && !Array.isArray(data);
|
|
145
|
+
}
|
|
146
|
+
/** Filter object entries and return a new object. */
|
|
147
|
+
function filterKeys(object, filter) {
|
|
148
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
|
|
149
|
+
}
|
|
150
|
+
/** Map object values while preserving the original key set. */
|
|
151
|
+
function mapValues(object, transform) {
|
|
152
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
|
|
153
|
+
}
|
|
154
|
+
/** Pick selected keys from an object, optionally including `undefined` values. */
|
|
155
|
+
function pick(source, keys, forced) {
|
|
156
|
+
if (!keys) return { ...source };
|
|
157
|
+
const result = {};
|
|
158
|
+
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region ../../../vendor/cosmokit/src/types.ts
|
|
163
|
+
/** Test values using `instanceof` with a `toStringTag` fallback. */
|
|
164
|
+
function is(type, value) {
|
|
165
|
+
if (arguments.length === 1) return (value) => is(type, value);
|
|
166
|
+
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
167
|
+
}
|
|
168
|
+
function isArrayBufferLike(value) {
|
|
169
|
+
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
170
|
+
}
|
|
171
|
+
function isArrayBufferSource(value) {
|
|
172
|
+
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
173
|
+
}
|
|
174
|
+
let Binary;
|
|
175
|
+
(function(_Binary) {
|
|
176
|
+
_Binary.is = isArrayBufferLike;
|
|
177
|
+
_Binary.isSource = isArrayBufferSource;
|
|
178
|
+
function fromSource(source) {
|
|
179
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
180
|
+
else return source;
|
|
181
|
+
}
|
|
182
|
+
_Binary.fromSource = fromSource;
|
|
183
|
+
function toBase64(source) {
|
|
184
|
+
source = fromSource(source);
|
|
185
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
|
|
186
|
+
let binary = "";
|
|
187
|
+
const bytes = new Uint8Array(source);
|
|
188
|
+
for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
|
|
189
|
+
return btoa(binary);
|
|
190
|
+
}
|
|
191
|
+
_Binary.toBase64 = toBase64;
|
|
192
|
+
function fromBase64(source) {
|
|
193
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
194
|
+
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
195
|
+
}
|
|
196
|
+
_Binary.fromBase64 = fromBase64;
|
|
197
|
+
function toHex(source) {
|
|
198
|
+
source = fromSource(source);
|
|
199
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
200
|
+
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
201
|
+
}
|
|
202
|
+
_Binary.toHex = toHex;
|
|
203
|
+
function fromHex(source) {
|
|
204
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
205
|
+
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
206
|
+
const buffer = [];
|
|
207
|
+
for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
208
|
+
return Uint8Array.from(buffer).buffer;
|
|
209
|
+
}
|
|
210
|
+
_Binary.fromHex = fromHex;
|
|
211
|
+
})(Binary || (Binary = {}));
|
|
212
|
+
Binary.fromBase64;
|
|
213
|
+
Binary.toBase64;
|
|
214
|
+
Binary.fromHex;
|
|
215
|
+
Binary.toHex;
|
|
216
|
+
/** Deep-clone common JavaScript values while preserving prototypes and cycles. */
|
|
217
|
+
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
218
|
+
if (!source || typeof source !== "object") return source;
|
|
219
|
+
if (is("Date", source)) return new Date(source.valueOf());
|
|
220
|
+
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
221
|
+
if (isArrayBufferLike(source)) return source.slice(0);
|
|
222
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
223
|
+
const cached = refs.get(source);
|
|
224
|
+
if (cached) return cached;
|
|
225
|
+
if (Array.isArray(source)) {
|
|
226
|
+
const result = [];
|
|
227
|
+
refs.set(source, result);
|
|
228
|
+
source.forEach((value, index) => {
|
|
229
|
+
result[index] = Reflect.apply(clone, null, [value, refs]);
|
|
230
|
+
});
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
const result = Object.create(Object.getPrototypeOf(source));
|
|
234
|
+
refs.set(source, result);
|
|
235
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
236
|
+
const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
237
|
+
if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
|
|
238
|
+
Reflect.defineProperty(result, key, descriptor);
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
/** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
|
|
243
|
+
function deepEqual(a, b, strict) {
|
|
244
|
+
if (a === b) return true;
|
|
245
|
+
if (!strict && isNullable(a) && isNullable(b)) return true;
|
|
246
|
+
if (typeof a !== typeof b) return false;
|
|
247
|
+
if (typeof a !== "object") return false;
|
|
248
|
+
if (!a || !b) return false;
|
|
249
|
+
function check(test, then) {
|
|
250
|
+
return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
|
|
251
|
+
}
|
|
252
|
+
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) => {
|
|
253
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
254
|
+
const viewA = new Uint8Array(a);
|
|
255
|
+
const viewB = new Uint8Array(b);
|
|
256
|
+
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
257
|
+
return true;
|
|
258
|
+
}) ?? Object.keys({
|
|
259
|
+
...a,
|
|
260
|
+
...b
|
|
261
|
+
}).every((key) => deepEqual(a[key], b[key], strict));
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region ../../../vendor/cosmokit/src/time.ts
|
|
265
|
+
let Time;
|
|
266
|
+
(function(_Time) {
|
|
267
|
+
_Time.millisecond = 1;
|
|
268
|
+
const second = _Time.second = 1e3;
|
|
269
|
+
const minute = _Time.minute = second * 60;
|
|
270
|
+
const hour = _Time.hour = minute * 60;
|
|
271
|
+
const day = _Time.day = hour * 24;
|
|
272
|
+
const week = _Time.week = day * 7;
|
|
273
|
+
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
274
|
+
function setTimezoneOffset(offset) {
|
|
275
|
+
timezoneOffset = offset;
|
|
276
|
+
}
|
|
277
|
+
_Time.setTimezoneOffset = setTimezoneOffset;
|
|
278
|
+
function getTimezoneOffset() {
|
|
279
|
+
return timezoneOffset;
|
|
280
|
+
}
|
|
281
|
+
_Time.getTimezoneOffset = getTimezoneOffset;
|
|
282
|
+
function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
|
|
283
|
+
if (typeof date === "number") date = new Date(date);
|
|
284
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
285
|
+
return Math.floor((date.valueOf() / minute - offset) / 1440);
|
|
286
|
+
}
|
|
287
|
+
_Time.getDateNumber = getDateNumber;
|
|
288
|
+
function fromDateNumber(value, offset) {
|
|
289
|
+
const date = new Date(value * day);
|
|
290
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
291
|
+
return new Date(+date + offset * minute);
|
|
292
|
+
}
|
|
293
|
+
_Time.fromDateNumber = fromDateNumber;
|
|
294
|
+
const numeric = /\d+(?:\.\d+)?/.source;
|
|
295
|
+
const timeRegExp = new RegExp(`^${[
|
|
296
|
+
"w(?:eek(?:s)?)?",
|
|
297
|
+
"d(?:ay(?:s)?)?",
|
|
298
|
+
"h(?:our(?:s)?)?",
|
|
299
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
300
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
301
|
+
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
302
|
+
function parseTime(source) {
|
|
303
|
+
const capture = timeRegExp.exec(source);
|
|
304
|
+
if (!capture) return 0;
|
|
305
|
+
return (parseFloat(capture[1]) * week || 0) + (parseFloat(capture[2]) * day || 0) + (parseFloat(capture[3]) * hour || 0) + (parseFloat(capture[4]) * minute || 0) + (parseFloat(capture[5]) * second || 0);
|
|
306
|
+
}
|
|
307
|
+
_Time.parseTime = parseTime;
|
|
308
|
+
function parseDate(date) {
|
|
309
|
+
const parsed = parseTime(date);
|
|
310
|
+
if (parsed) date = Date.now() + parsed;
|
|
311
|
+
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
|
|
312
|
+
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
|
|
313
|
+
return date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
314
|
+
}
|
|
315
|
+
_Time.parseDate = parseDate;
|
|
316
|
+
function format(ms) {
|
|
317
|
+
const abs = Math.abs(ms);
|
|
318
|
+
if (abs >= day - hour / 2) return Math.round(ms / day) + "d";
|
|
319
|
+
else if (abs >= hour - minute / 2) return Math.round(ms / hour) + "h";
|
|
320
|
+
else if (abs >= minute - second / 2) return Math.round(ms / minute) + "m";
|
|
321
|
+
else if (abs >= second) return Math.round(ms / second) + "s";
|
|
322
|
+
return ms + "ms";
|
|
323
|
+
}
|
|
324
|
+
_Time.format = format;
|
|
325
|
+
function toDigits(source, length = 2) {
|
|
326
|
+
return source.toString().padStart(length, "0");
|
|
327
|
+
}
|
|
328
|
+
_Time.toDigits = toDigits;
|
|
329
|
+
function template(template, time = /* @__PURE__ */ new Date()) {
|
|
330
|
+
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));
|
|
331
|
+
}
|
|
332
|
+
_Time.template = template;
|
|
333
|
+
})(Time || (Time = {}));
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region ../../../vendor/schemastery/src/index.ts
|
|
336
|
+
const kSchema = Symbol.for("schemastery");
|
|
337
|
+
const kValidationError = Symbol.for("ValidationError");
|
|
338
|
+
globalThis.__schemastery_index__ ??= 0;
|
|
339
|
+
globalThis.__schemastery_refs__ = void 0;
|
|
340
|
+
var ValidationError = class extends TypeError {
|
|
341
|
+
options;
|
|
342
|
+
name = "ValidationError";
|
|
343
|
+
constructor(message, options) {
|
|
344
|
+
let prefix = "$";
|
|
345
|
+
for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
|
|
346
|
+
else if (typeof segment === "number") prefix += "[" + segment + "]";
|
|
347
|
+
else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
|
|
348
|
+
if (prefix.startsWith(".")) prefix = prefix.slice(1);
|
|
349
|
+
super((prefix === "$" ? "" : `${prefix} `) + message);
|
|
350
|
+
this.options = options;
|
|
351
|
+
}
|
|
352
|
+
static is(error) {
|
|
353
|
+
return !!error?.[kValidationError];
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
|
|
357
|
+
const Schema = function(options) {
|
|
358
|
+
const schema = function(data, options = {}) {
|
|
359
|
+
return Schema.resolve(data, schema, options)[0];
|
|
360
|
+
};
|
|
361
|
+
if (options.refs) {
|
|
362
|
+
const refs = mapValues(options.refs, (options) => new Schema(options));
|
|
363
|
+
const getRef = (uid) => refs[uid];
|
|
364
|
+
for (const key in refs) {
|
|
365
|
+
const options = refs[key];
|
|
366
|
+
options.sKey = getRef(options.sKey);
|
|
367
|
+
options.inner = getRef(options.inner);
|
|
368
|
+
options.list = options.list && options.list.map(getRef);
|
|
369
|
+
options.dict = options.dict && mapValues(options.dict, getRef);
|
|
370
|
+
}
|
|
371
|
+
return refs[options.uid];
|
|
372
|
+
}
|
|
373
|
+
Object.assign(schema, options);
|
|
374
|
+
if (typeof schema.callback === "string") try {
|
|
375
|
+
schema.callback = new Function("return " + schema.callback)();
|
|
376
|
+
} catch {}
|
|
377
|
+
Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
|
|
378
|
+
Object.setPrototypeOf(schema, Schema.prototype);
|
|
379
|
+
schema.meta ||= {};
|
|
380
|
+
schema.toString = schema.toString.bind(schema);
|
|
381
|
+
return schema;
|
|
382
|
+
};
|
|
383
|
+
Schema.prototype = Object.create(Function.prototype);
|
|
384
|
+
Schema.prototype[kSchema] = true;
|
|
385
|
+
Object.defineProperty(Schema.prototype, "~standard", { get() {
|
|
386
|
+
return {
|
|
387
|
+
version: 1,
|
|
388
|
+
vendor: "schemastery",
|
|
389
|
+
validate: (value) => {
|
|
390
|
+
try {
|
|
391
|
+
return { value: Schema.resolve(value, this, {})[0] };
|
|
392
|
+
} catch (error) {
|
|
393
|
+
if (ValidationError.is(error)) return { issues: [{
|
|
394
|
+
message: error.message,
|
|
395
|
+
path: error.options.path
|
|
396
|
+
}] };
|
|
397
|
+
throw error;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
} });
|
|
402
|
+
Schema.ValidationError = ValidationError;
|
|
403
|
+
Schema.prototype.toJSON = function toJSON() {
|
|
404
|
+
if (globalThis.__schemastery_refs__) {
|
|
405
|
+
globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
|
|
406
|
+
return this.uid;
|
|
407
|
+
}
|
|
408
|
+
globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
|
|
409
|
+
globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
|
|
410
|
+
const result = {
|
|
411
|
+
uid: this.uid,
|
|
412
|
+
refs: globalThis.__schemastery_refs__
|
|
413
|
+
};
|
|
414
|
+
globalThis.__schemastery_refs__ = void 0;
|
|
415
|
+
return result;
|
|
416
|
+
};
|
|
417
|
+
Schema.prototype.set = function set(key, value) {
|
|
418
|
+
this.dict[key] = value;
|
|
419
|
+
return this;
|
|
420
|
+
};
|
|
421
|
+
Schema.prototype.push = function push(value) {
|
|
422
|
+
this.list.push(value);
|
|
423
|
+
return this;
|
|
424
|
+
};
|
|
425
|
+
function mergeDesc(original, messages) {
|
|
426
|
+
const result = typeof original === "string" ? { "": original } : { ...original };
|
|
427
|
+
for (const locale in messages) {
|
|
428
|
+
const value = messages[locale];
|
|
429
|
+
if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
|
|
430
|
+
else if (typeof value === "string") result[locale] = value;
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
function getInner(value) {
|
|
435
|
+
return value?.$value ?? value?.$inner;
|
|
436
|
+
}
|
|
437
|
+
function extractKeys(data) {
|
|
438
|
+
return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
|
|
439
|
+
}
|
|
440
|
+
Schema.prototype.i18n = function i18n(messages) {
|
|
441
|
+
const schema = Schema(this);
|
|
442
|
+
const desc = mergeDesc(schema.meta.description, messages);
|
|
443
|
+
if (Object.keys(desc).length) schema.meta.description = desc;
|
|
444
|
+
if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
|
|
445
|
+
return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
|
|
446
|
+
});
|
|
447
|
+
if (schema.list) schema.list = schema.list.map((inner, index) => {
|
|
448
|
+
return inner.i18n(mapValues(messages, (data = {}) => {
|
|
449
|
+
if (Array.isArray(getInner(data))) return getInner(data)[index];
|
|
450
|
+
if (Array.isArray(data)) return data[index];
|
|
451
|
+
return extractKeys(data);
|
|
452
|
+
}));
|
|
453
|
+
});
|
|
454
|
+
if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
|
|
455
|
+
if (getInner(data)) return getInner(data);
|
|
456
|
+
return extractKeys(data);
|
|
457
|
+
}));
|
|
458
|
+
if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
|
|
459
|
+
return schema;
|
|
460
|
+
};
|
|
461
|
+
Schema.prototype.extra = function extra(key, value) {
|
|
462
|
+
const schema = Schema(this);
|
|
463
|
+
schema.meta = {
|
|
464
|
+
...schema.meta,
|
|
465
|
+
[key]: value
|
|
466
|
+
};
|
|
467
|
+
return schema;
|
|
468
|
+
};
|
|
469
|
+
for (const key of [
|
|
470
|
+
"required",
|
|
471
|
+
"disabled",
|
|
472
|
+
"collapse",
|
|
473
|
+
"hidden",
|
|
474
|
+
"loose"
|
|
475
|
+
]) Object.assign(Schema.prototype, { [key](value = true) {
|
|
476
|
+
const schema = Schema(this);
|
|
477
|
+
schema.meta = {
|
|
478
|
+
...schema.meta,
|
|
479
|
+
[key]: value
|
|
480
|
+
};
|
|
481
|
+
return schema;
|
|
482
|
+
} });
|
|
483
|
+
Schema.prototype.deprecated = function deprecated() {
|
|
484
|
+
const schema = Schema(this);
|
|
485
|
+
schema.meta.badges ||= [];
|
|
486
|
+
schema.meta.badges.push({
|
|
487
|
+
text: "deprecated",
|
|
488
|
+
type: "danger"
|
|
489
|
+
});
|
|
490
|
+
return schema;
|
|
491
|
+
};
|
|
492
|
+
Schema.prototype.experimental = function experimental() {
|
|
493
|
+
const schema = Schema(this);
|
|
494
|
+
schema.meta.badges ||= [];
|
|
495
|
+
schema.meta.badges.push({
|
|
496
|
+
text: "experimental",
|
|
497
|
+
type: "warning"
|
|
498
|
+
});
|
|
499
|
+
return schema;
|
|
500
|
+
};
|
|
501
|
+
Schema.prototype.pattern = function pattern(regexp) {
|
|
502
|
+
const schema = Schema(this);
|
|
503
|
+
const pattern = pick(regexp, ["source", "flags"]);
|
|
504
|
+
schema.meta = {
|
|
505
|
+
...schema.meta,
|
|
506
|
+
pattern
|
|
507
|
+
};
|
|
508
|
+
return schema;
|
|
509
|
+
};
|
|
510
|
+
Schema.prototype.simplify = function simplify(value) {
|
|
511
|
+
if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
|
|
512
|
+
if (isNullable(value)) return value;
|
|
513
|
+
if (this.type === "object" || this.type === "dict") {
|
|
514
|
+
const result = {};
|
|
515
|
+
for (const key in value) {
|
|
516
|
+
const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
|
|
517
|
+
if (this.type === "dict" || !isNullable(item)) result[key] = item;
|
|
518
|
+
}
|
|
519
|
+
if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
|
|
520
|
+
return result;
|
|
521
|
+
} else if (this.type === "array" || this.type === "tuple") {
|
|
522
|
+
const result = [];
|
|
523
|
+
value.forEach((value, index) => {
|
|
524
|
+
const schema = this.type === "array" ? this.inner : this.list[index];
|
|
525
|
+
const item = schema ? schema.simplify(value) : value;
|
|
526
|
+
result.push(item);
|
|
527
|
+
});
|
|
528
|
+
return result;
|
|
529
|
+
} else if (this.type === "intersect") {
|
|
530
|
+
const result = {};
|
|
531
|
+
for (const item of this.list) Object.assign(result, item.simplify(value));
|
|
532
|
+
return result;
|
|
533
|
+
} else if (this.type === "union") for (const schema of this.list) try {
|
|
534
|
+
Schema.resolve(value, schema, {});
|
|
535
|
+
return schema.simplify(value);
|
|
536
|
+
} catch {}
|
|
537
|
+
return value;
|
|
538
|
+
};
|
|
539
|
+
Schema.prototype.toString = function toString(inline) {
|
|
540
|
+
return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
|
|
541
|
+
};
|
|
542
|
+
Schema.prototype.role = function role(role, extra) {
|
|
543
|
+
const schema = Schema(this);
|
|
544
|
+
schema.meta = {
|
|
545
|
+
...schema.meta,
|
|
546
|
+
role,
|
|
547
|
+
extra
|
|
548
|
+
};
|
|
549
|
+
return schema;
|
|
550
|
+
};
|
|
551
|
+
for (const key of [
|
|
552
|
+
"default",
|
|
553
|
+
"link",
|
|
554
|
+
"comment",
|
|
555
|
+
"description",
|
|
556
|
+
"max",
|
|
557
|
+
"min",
|
|
558
|
+
"step"
|
|
559
|
+
]) Object.assign(Schema.prototype, { [key](value) {
|
|
560
|
+
const schema = Schema(this);
|
|
561
|
+
schema.meta = {
|
|
562
|
+
...schema.meta,
|
|
563
|
+
[key]: value
|
|
564
|
+
};
|
|
565
|
+
return schema;
|
|
566
|
+
} });
|
|
567
|
+
const resolvers = {};
|
|
568
|
+
Schema.extend = function extend(type, resolve) {
|
|
569
|
+
resolvers[type] = resolve;
|
|
570
|
+
};
|
|
571
|
+
Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
|
|
572
|
+
if (!schema) return [data];
|
|
573
|
+
if (options.ignore?.(data, schema)) return [data];
|
|
574
|
+
if (isNullable(data) && schema.type !== "lazy") {
|
|
575
|
+
if (schema.meta.required) throw new ValidationError(`missing required value`, options);
|
|
576
|
+
let current = schema;
|
|
577
|
+
let fallback = schema.meta.default;
|
|
578
|
+
while (current?.type === "intersect" && isNullable(fallback)) {
|
|
579
|
+
current = current.list[0];
|
|
580
|
+
fallback = current?.meta.default;
|
|
581
|
+
}
|
|
582
|
+
if (isNullable(fallback)) return [data];
|
|
583
|
+
data = clone(fallback);
|
|
584
|
+
}
|
|
585
|
+
const callback = resolvers[schema.type];
|
|
586
|
+
if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
|
|
587
|
+
try {
|
|
588
|
+
return callback(data, schema, options, strict);
|
|
589
|
+
} catch (error) {
|
|
590
|
+
if (!schema.meta.loose) throw error;
|
|
591
|
+
return [schema.meta.default];
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
Schema.from = function from(source) {
|
|
595
|
+
if (isNullable(source)) return Schema.any();
|
|
596
|
+
else if ([
|
|
597
|
+
"string",
|
|
598
|
+
"number",
|
|
599
|
+
"boolean"
|
|
600
|
+
].includes(typeof source)) return Schema.const(source).required();
|
|
601
|
+
else if (source[kSchema]) return source;
|
|
602
|
+
else if (typeof source === "function") switch (source) {
|
|
603
|
+
case String: return Schema.string().required();
|
|
604
|
+
case Number: return Schema.number().required();
|
|
605
|
+
case Boolean: return Schema.boolean().required();
|
|
606
|
+
case Function: return Schema.function().required();
|
|
607
|
+
default: return Schema.is(source).required();
|
|
608
|
+
}
|
|
609
|
+
else throw new TypeError(`cannot infer schema from ${source}`);
|
|
610
|
+
};
|
|
611
|
+
Schema.lazy = function lazy(builder) {
|
|
612
|
+
const toJSON = () => {
|
|
613
|
+
if (!schema.inner[kSchema]) {
|
|
614
|
+
schema.inner = schema.builder();
|
|
615
|
+
schema.inner.meta = {
|
|
616
|
+
...schema.meta,
|
|
617
|
+
...schema.inner.meta
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
return schema.inner.toJSON();
|
|
621
|
+
};
|
|
622
|
+
const schema = new Schema({
|
|
623
|
+
type: "lazy",
|
|
624
|
+
builder,
|
|
625
|
+
inner: { toJSON }
|
|
626
|
+
});
|
|
627
|
+
return schema;
|
|
628
|
+
};
|
|
629
|
+
Schema.natural = function natural() {
|
|
630
|
+
return Schema.number().step(1).min(0);
|
|
631
|
+
};
|
|
632
|
+
Schema.percent = function percent() {
|
|
633
|
+
return Schema.number().step(.01).min(0).max(1).role("slider");
|
|
634
|
+
};
|
|
635
|
+
Schema.date = function date() {
|
|
636
|
+
return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
|
|
637
|
+
const date = new Date(value);
|
|
638
|
+
if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
|
|
639
|
+
return date;
|
|
640
|
+
}, true)]);
|
|
641
|
+
};
|
|
642
|
+
Schema.regExp = function regExp(flag = "") {
|
|
643
|
+
return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
|
|
644
|
+
try {
|
|
645
|
+
return new RegExp(value, flag);
|
|
646
|
+
} catch (e) {
|
|
647
|
+
throw new ValidationError(e.message, options);
|
|
648
|
+
}
|
|
649
|
+
}, true)]);
|
|
650
|
+
};
|
|
651
|
+
Schema.arrayBuffer = function arrayBuffer(encoding) {
|
|
652
|
+
return Schema.union([
|
|
653
|
+
Schema.is(ArrayBuffer),
|
|
654
|
+
Schema.is(SharedArrayBuffer),
|
|
655
|
+
Schema.transform(Schema.any(), (value, options) => {
|
|
656
|
+
if (Binary.isSource(value)) return Binary.fromSource(value);
|
|
657
|
+
throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
|
|
658
|
+
}, true),
|
|
659
|
+
...encoding ? [Schema.transform(Schema.string(), (value, options) => {
|
|
660
|
+
try {
|
|
661
|
+
return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
|
|
662
|
+
} catch (e) {
|
|
663
|
+
throw new ValidationError(e.message, options);
|
|
664
|
+
}
|
|
665
|
+
}, true)] : []
|
|
666
|
+
]);
|
|
667
|
+
};
|
|
668
|
+
Schema.extend("lazy", (data, schema, options, strict) => {
|
|
669
|
+
if (!schema.inner[kSchema]) {
|
|
670
|
+
schema.inner = schema.builder();
|
|
671
|
+
schema.inner.meta = {
|
|
672
|
+
...schema.meta,
|
|
673
|
+
...schema.inner.meta
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
return Schema.resolve(data, schema.inner, options, strict);
|
|
677
|
+
});
|
|
678
|
+
Schema.extend("any", (data) => {
|
|
679
|
+
return [data];
|
|
680
|
+
});
|
|
681
|
+
Schema.extend("never", (data, _, options) => {
|
|
682
|
+
throw new ValidationError(`expected nullable but got ${data}`, options);
|
|
683
|
+
});
|
|
684
|
+
Schema.extend("const", (data, { value }, options) => {
|
|
685
|
+
if (deepEqual(data, value)) return [value];
|
|
686
|
+
throw new ValidationError(`expected ${value} but got ${data}`, options);
|
|
687
|
+
});
|
|
688
|
+
function checkWithinRange(data, meta, description, options, skipMin = false) {
|
|
689
|
+
const { max = Infinity, min = -Infinity } = meta;
|
|
690
|
+
if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
|
|
691
|
+
if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
|
|
692
|
+
}
|
|
693
|
+
Schema.extend("string", (data, { meta }, options) => {
|
|
694
|
+
if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
|
|
695
|
+
if (meta.pattern) {
|
|
696
|
+
const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
|
|
697
|
+
if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
|
|
698
|
+
}
|
|
699
|
+
checkWithinRange(data.length, meta, "string length", options);
|
|
700
|
+
return [data];
|
|
701
|
+
});
|
|
702
|
+
function decimalShift(data, digits) {
|
|
703
|
+
const str = data.toString();
|
|
704
|
+
if (str.includes("e")) return data * Math.pow(10, digits);
|
|
705
|
+
const index = str.indexOf(".");
|
|
706
|
+
if (index === -1) return data * Math.pow(10, digits);
|
|
707
|
+
const frac = str.slice(index + 1);
|
|
708
|
+
const integer = str.slice(0, index);
|
|
709
|
+
if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
|
|
710
|
+
return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
|
|
711
|
+
}
|
|
712
|
+
function isMultipleOf(data, min, step) {
|
|
713
|
+
step = Math.abs(step);
|
|
714
|
+
if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
|
|
715
|
+
const index = step.toString().indexOf(".");
|
|
716
|
+
const digits = step.toString().slice(index + 1).length;
|
|
717
|
+
return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
|
|
718
|
+
}
|
|
719
|
+
Schema.extend("number", (data, { meta }, options) => {
|
|
720
|
+
if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
|
|
721
|
+
checkWithinRange(data, meta, "number", options);
|
|
722
|
+
const { step } = meta;
|
|
723
|
+
if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
|
|
724
|
+
return [data];
|
|
725
|
+
});
|
|
726
|
+
Schema.extend("boolean", (data, _, options) => {
|
|
727
|
+
if (typeof data === "boolean") return [data];
|
|
728
|
+
throw new ValidationError(`expected boolean but got ${data}`, options);
|
|
729
|
+
});
|
|
730
|
+
Schema.extend("bitset", (data, { bits, meta }, options) => {
|
|
731
|
+
let value = 0, keys = [];
|
|
732
|
+
if (typeof data === "number") {
|
|
733
|
+
value = data;
|
|
734
|
+
for (const key in bits) if (data & bits[key]) keys.push(key);
|
|
735
|
+
} else if (Array.isArray(data)) {
|
|
736
|
+
keys = data;
|
|
737
|
+
for (const key of keys) {
|
|
738
|
+
if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
|
|
739
|
+
if (key in bits) value |= bits[key];
|
|
740
|
+
}
|
|
741
|
+
} else throw new ValidationError(`expected number or array but got ${data}`, options);
|
|
742
|
+
if (value === meta.default) return [value];
|
|
743
|
+
return [value, keys];
|
|
744
|
+
});
|
|
745
|
+
Schema.extend("function", (data, _, options) => {
|
|
746
|
+
if (typeof data === "function") return [data];
|
|
747
|
+
throw new ValidationError(`expected function but got ${data}`, options);
|
|
748
|
+
});
|
|
749
|
+
Schema.extend("is", (data, { constructor }, options) => {
|
|
750
|
+
if (typeof constructor === "function") {
|
|
751
|
+
if (data instanceof constructor) return [data];
|
|
752
|
+
throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
|
|
753
|
+
} else {
|
|
754
|
+
if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
755
|
+
let prototype = Object.getPrototypeOf(data);
|
|
756
|
+
while (prototype) {
|
|
757
|
+
if (prototype.constructor?.name === constructor) return [data];
|
|
758
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
759
|
+
}
|
|
760
|
+
throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
function property(data, key, schema, options) {
|
|
764
|
+
try {
|
|
765
|
+
const [value, adapted] = Schema.resolve(data[key], schema, {
|
|
766
|
+
...options,
|
|
767
|
+
path: [...options.path || [], key]
|
|
768
|
+
});
|
|
769
|
+
if (adapted !== void 0) data[key] = adapted;
|
|
770
|
+
return value;
|
|
771
|
+
} catch (e) {
|
|
772
|
+
if (!options?.autofix) throw e;
|
|
773
|
+
delete data[key];
|
|
774
|
+
return schema.meta.default;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
Schema.extend("array", (data, { inner, meta }, options) => {
|
|
778
|
+
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
779
|
+
checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
|
|
780
|
+
return [data.map((_, index) => property(data, index, inner, options))];
|
|
781
|
+
});
|
|
782
|
+
Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
|
|
783
|
+
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
784
|
+
const result = {};
|
|
785
|
+
for (const key in data) {
|
|
786
|
+
let rKey;
|
|
787
|
+
try {
|
|
788
|
+
rKey = Schema.resolve(key, sKey, options)[0];
|
|
789
|
+
} catch (error) {
|
|
790
|
+
if (strict) continue;
|
|
791
|
+
throw error;
|
|
792
|
+
}
|
|
793
|
+
result[rKey] = property(data, key, inner, options);
|
|
794
|
+
data[rKey] = data[key];
|
|
795
|
+
if (key !== rKey) delete data[key];
|
|
796
|
+
}
|
|
797
|
+
return [result];
|
|
798
|
+
});
|
|
799
|
+
Schema.extend("tuple", (data, { list }, options, strict) => {
|
|
800
|
+
if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
|
|
801
|
+
const result = list.map((inner, index) => property(data, index, inner, options));
|
|
802
|
+
if (strict) return [result];
|
|
803
|
+
result.push(...data.slice(list.length));
|
|
804
|
+
return [result];
|
|
805
|
+
});
|
|
806
|
+
function merge(result, data) {
|
|
807
|
+
for (const key in data) {
|
|
808
|
+
if (key in result) continue;
|
|
809
|
+
result[key] = data[key];
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
Schema.extend("object", (data, { dict }, options, strict) => {
|
|
813
|
+
if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
|
|
814
|
+
const result = {};
|
|
815
|
+
for (const key in dict) {
|
|
816
|
+
const value = property(data, key, dict[key], options);
|
|
817
|
+
if (!isNullable(value) || key in data) result[key] = value;
|
|
818
|
+
}
|
|
819
|
+
if (!strict) merge(result, data);
|
|
820
|
+
return [result];
|
|
821
|
+
});
|
|
822
|
+
Schema.extend("union", (data, { list, toString }, options, strict) => {
|
|
823
|
+
const messages = [];
|
|
824
|
+
for (const inner of list) try {
|
|
825
|
+
return Schema.resolve(data, inner, options, strict);
|
|
826
|
+
} catch (error) {
|
|
827
|
+
messages.push(error);
|
|
828
|
+
}
|
|
829
|
+
throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
830
|
+
});
|
|
831
|
+
Schema.extend("intersect", (data, { list, toString }, options, strict) => {
|
|
832
|
+
if (!list.length) return [data];
|
|
833
|
+
let result;
|
|
834
|
+
for (const inner of list) {
|
|
835
|
+
const value = Schema.resolve(data, inner, options, true)[0];
|
|
836
|
+
if (isNullable(value)) continue;
|
|
837
|
+
if (isNullable(result)) result = value;
|
|
838
|
+
else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
839
|
+
else if (typeof value === "object") merge(result ??= {}, value);
|
|
840
|
+
else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
|
|
841
|
+
}
|
|
842
|
+
if (!strict && isPlainObject(data)) merge(result, data);
|
|
843
|
+
return [result];
|
|
844
|
+
});
|
|
845
|
+
Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
|
|
846
|
+
const [result, adapted = data] = Schema.resolve(data, inner, options, true);
|
|
847
|
+
if (preserve) return [callback(result)];
|
|
848
|
+
else return [callback(result), callback(adapted)];
|
|
849
|
+
});
|
|
850
|
+
const formatters = {};
|
|
851
|
+
function defineMethod(name, keys, format) {
|
|
852
|
+
formatters[name] = format;
|
|
853
|
+
Object.assign(Schema, { [name](...args) {
|
|
854
|
+
const schema = new Schema({ type: name });
|
|
855
|
+
keys.forEach((key, index) => {
|
|
856
|
+
switch (key) {
|
|
857
|
+
case "sKey":
|
|
858
|
+
schema.sKey = args[index] ?? Schema.string();
|
|
859
|
+
break;
|
|
860
|
+
case "inner":
|
|
861
|
+
schema.inner = Schema.from(args[index]);
|
|
862
|
+
break;
|
|
863
|
+
case "list":
|
|
864
|
+
schema.list = args[index].map(Schema.from);
|
|
865
|
+
break;
|
|
866
|
+
case "dict":
|
|
867
|
+
schema.dict = mapValues(args[index], Schema.from);
|
|
868
|
+
break;
|
|
869
|
+
case "bits":
|
|
870
|
+
schema.bits = {};
|
|
871
|
+
for (const key in args[index]) {
|
|
872
|
+
if (typeof args[index][key] !== "number") continue;
|
|
873
|
+
schema.bits[key] = args[index][key];
|
|
874
|
+
}
|
|
875
|
+
break;
|
|
876
|
+
case "callback": {
|
|
877
|
+
const callback = schema.callback = args[index];
|
|
878
|
+
callback["toJSON"] ||= () => callback.toString();
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
case "constructor": {
|
|
882
|
+
const constructor = schema.constructor = args[index];
|
|
883
|
+
if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
|
|
884
|
+
break;
|
|
885
|
+
}
|
|
886
|
+
default: schema[key] = args[index];
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
if (name === "object" || name === "dict") schema.meta.default = {};
|
|
890
|
+
else if (name === "array" || name === "tuple") schema.meta.default = [];
|
|
891
|
+
else if (name === "bitset") schema.meta.default = 0;
|
|
892
|
+
return schema;
|
|
893
|
+
} });
|
|
894
|
+
}
|
|
895
|
+
defineMethod("is", ["constructor"], ({ constructor }) => {
|
|
896
|
+
if (typeof constructor === "function") return constructor.name;
|
|
897
|
+
else return constructor;
|
|
898
|
+
});
|
|
899
|
+
defineMethod("any", [], () => "any");
|
|
900
|
+
defineMethod("never", [], () => "never");
|
|
901
|
+
defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
|
|
902
|
+
defineMethod("string", [], () => "string");
|
|
903
|
+
defineMethod("number", [], () => "number");
|
|
904
|
+
defineMethod("boolean", [], () => "boolean");
|
|
905
|
+
defineMethod("bitset", ["bits"], () => "bitset");
|
|
906
|
+
defineMethod("function", [], () => "function");
|
|
907
|
+
defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
|
|
908
|
+
defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
|
|
909
|
+
defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
|
|
910
|
+
defineMethod("object", ["dict"], ({ dict }) => {
|
|
911
|
+
if (Object.keys(dict).length === 0) return "{}";
|
|
912
|
+
return `{ ${Object.entries(dict).map(([key, inner]) => {
|
|
913
|
+
return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
|
|
914
|
+
}).join(", ")} }`;
|
|
915
|
+
});
|
|
916
|
+
defineMethod("union", ["list"], ({ list }, inline) => {
|
|
917
|
+
const result = list.map(({ toString: format }) => format()).join(" | ");
|
|
918
|
+
return inline ? `(${result})` : result;
|
|
919
|
+
});
|
|
920
|
+
defineMethod("intersect", ["list"], ({ list }) => {
|
|
921
|
+
return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
|
|
922
|
+
});
|
|
923
|
+
defineMethod("transform", [
|
|
924
|
+
"inner",
|
|
925
|
+
"callback",
|
|
926
|
+
"preserve"
|
|
927
|
+
], ({ inner }, isInner) => inner.toString(isInner));
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region lib/types/theme-settings.js
|
|
930
|
+
/** Theme preferences stored in the Host user-settings document. */
|
|
931
|
+
/** Built-in preferences accepted at the registry and settings boundaries. */
|
|
932
|
+
const THEME_PREFERENCES = [
|
|
933
|
+
"light",
|
|
934
|
+
"dark",
|
|
935
|
+
"system"
|
|
936
|
+
];
|
|
937
|
+
/** Settings namespace owned by the theme plugin. */
|
|
938
|
+
const THEME_SETTINGS_NAMESPACE = "ui-theme";
|
|
939
|
+
/** Field carrying the selected built-in theme preference. */
|
|
940
|
+
const THEME_PREFERENCE_FIELD = "preference";
|
|
941
|
+
/** Default preference when the user-settings document has no override. */
|
|
942
|
+
const DEFAULT_PREFERENCE = "system";
|
|
943
|
+
Schema.object({ [THEME_PREFERENCE_FIELD]: Schema.union([...THEME_PREFERENCES]).default(DEFAULT_PREFERENCE) });
|
|
944
|
+
/**
|
|
945
|
+
* Narrow one wire or registry value to a persistable preference.
|
|
946
|
+
* @param value - value crossing the settings or registry boundary.
|
|
947
|
+
* @returns whether the value is a built-in preference.
|
|
948
|
+
*/
|
|
949
|
+
function isThemePreference(value) {
|
|
950
|
+
return THEME_PREFERENCES.some((preference) => preference === value);
|
|
951
|
+
}
|
|
952
|
+
//#endregion
|
|
953
|
+
//#region lib/types/client/index.js
|
|
954
|
+
/** Namespace owning this feature's settings-row copy. */
|
|
955
|
+
const SETTINGS_NS = "settings.theme";
|
|
956
|
+
const BUILTIN_THEMES = Object.freeze([Object.freeze({
|
|
957
|
+
id: "light",
|
|
958
|
+
colorScheme: "light",
|
|
959
|
+
tokens: Object.freeze({})
|
|
960
|
+
}), Object.freeze({
|
|
961
|
+
id: "dark",
|
|
962
|
+
colorScheme: "dark",
|
|
963
|
+
tokens: Object.freeze({})
|
|
964
|
+
})]);
|
|
965
|
+
const BUILTIN_INSPECT_TOKENS = Object.freeze([
|
|
966
|
+
{
|
|
967
|
+
name: "--dsw-alias-bg-base",
|
|
968
|
+
description: "Application base background.",
|
|
969
|
+
valueType: "CSS color",
|
|
970
|
+
requiresLightAndDark: true,
|
|
971
|
+
cssVariable: "--dsw-alias-bg-base"
|
|
972
|
+
},
|
|
973
|
+
{
|
|
974
|
+
name: "--dsw-alias-bg-layer-1",
|
|
975
|
+
description: "Primary raised surface background.",
|
|
976
|
+
valueType: "CSS color",
|
|
977
|
+
requiresLightAndDark: true,
|
|
978
|
+
cssVariable: "--dsw-alias-bg-layer-1"
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
name: "--dsw-alias-bg-layer-2",
|
|
982
|
+
description: "Secondary nested surface background.",
|
|
983
|
+
valueType: "CSS color",
|
|
984
|
+
requiresLightAndDark: true,
|
|
985
|
+
cssVariable: "--dsw-alias-bg-layer-2"
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
name: "--dsw-alias-bg-overlay",
|
|
989
|
+
description: "Overlay and popover background.",
|
|
990
|
+
valueType: "CSS color",
|
|
991
|
+
requiresLightAndDark: true,
|
|
992
|
+
cssVariable: "--dsw-alias-bg-overlay"
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
name: "--dsw-alias-border-l1",
|
|
996
|
+
description: "Primary subtle border.",
|
|
997
|
+
valueType: "CSS color",
|
|
998
|
+
requiresLightAndDark: true,
|
|
999
|
+
cssVariable: "--dsw-alias-border-l1"
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
name: "--dsw-alias-border-l2",
|
|
1003
|
+
description: "Secondary stronger border.",
|
|
1004
|
+
valueType: "CSS color",
|
|
1005
|
+
requiresLightAndDark: true,
|
|
1006
|
+
cssVariable: "--dsw-alias-border-l2"
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
name: "--dsw-alias-brand-primary",
|
|
1010
|
+
description: "Primary brand accent.",
|
|
1011
|
+
valueType: "CSS color",
|
|
1012
|
+
requiresLightAndDark: true,
|
|
1013
|
+
cssVariable: "--dsw-alias-brand-primary"
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
name: "--dsw-alias-label-primary",
|
|
1017
|
+
description: "Primary text color.",
|
|
1018
|
+
valueType: "CSS color",
|
|
1019
|
+
requiresLightAndDark: true,
|
|
1020
|
+
cssVariable: "--dsw-alias-label-primary"
|
|
1021
|
+
},
|
|
1022
|
+
{
|
|
1023
|
+
name: "--dsw-alias-label-secondary",
|
|
1024
|
+
description: "Secondary text color.",
|
|
1025
|
+
valueType: "CSS color",
|
|
1026
|
+
requiresLightAndDark: true,
|
|
1027
|
+
cssVariable: "--dsw-alias-label-secondary"
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
name: "--dsw-alias-state-error-primary",
|
|
1031
|
+
description: "Primary error state color.",
|
|
1032
|
+
valueType: "CSS color",
|
|
1033
|
+
requiresLightAndDark: true,
|
|
1034
|
+
cssVariable: "--dsw-alias-state-error-primary"
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
name: "--dsw-alias-state-success-primary",
|
|
1038
|
+
description: "Primary success state color.",
|
|
1039
|
+
valueType: "CSS color",
|
|
1040
|
+
requiresLightAndDark: true,
|
|
1041
|
+
cssVariable: "--dsw-alias-state-success-primary"
|
|
1042
|
+
},
|
|
1043
|
+
{
|
|
1044
|
+
name: "--dsw-alias-state-warn-primary",
|
|
1045
|
+
description: "Primary warning state color.",
|
|
1046
|
+
valueType: "CSS color",
|
|
1047
|
+
requiresLightAndDark: true,
|
|
1048
|
+
cssVariable: "--dsw-alias-state-warn-primary"
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
name: "--dsw-specific-sidebar-fill",
|
|
1052
|
+
description: "Sidebar column and title-row background.",
|
|
1053
|
+
valueType: "CSS color",
|
|
1054
|
+
requiresLightAndDark: true,
|
|
1055
|
+
cssVariable: "--dsw-specific-sidebar-fill"
|
|
1056
|
+
}
|
|
1057
|
+
]);
|
|
1058
|
+
/**
|
|
1059
|
+
* Theme registry and preference owner. `light`/`dark` are built in (the base
|
|
1060
|
+
* stylesheets carry both palettes); third-party themes register alias-layer
|
|
1061
|
+
* overrides. Reads go through {@link getTheme}; preference writes only
|
|
1062
|
+
* through {@link setTheme}; continuous sync only through the `theme/change`
|
|
1063
|
+
* event. {@link overrideTokens} stacks partial token layers over the active
|
|
1064
|
+
* theme without touching the registry.
|
|
1065
|
+
* The service holds the `prefers-color-scheme` media query (environment
|
|
1066
|
+
* sensing, not presentation) and re-emits when the OS scheme flips while the
|
|
1067
|
+
* preference is `system`.
|
|
1068
|
+
*/
|
|
1069
|
+
var ThemeRuntime = class {
|
|
1070
|
+
ctx;
|
|
1071
|
+
host;
|
|
1072
|
+
themes = [...BUILTIN_THEMES];
|
|
1073
|
+
preference;
|
|
1074
|
+
revision = 0;
|
|
1075
|
+
snapshot;
|
|
1076
|
+
media;
|
|
1077
|
+
/** Override layers by source; seq (monotonic) is the stacking order. */
|
|
1078
|
+
overrides = /* @__PURE__ */ new Map();
|
|
1079
|
+
overrideSeq = 0;
|
|
1080
|
+
/**
|
|
1081
|
+
* @param ctx - owning context (change events are emitted on it; the
|
|
1082
|
+
* media-query and scope listeners are released through ctx.effect on dispose).
|
|
1083
|
+
* @param host - durable preference scope owned by the same plugin.
|
|
1084
|
+
*/
|
|
1085
|
+
constructor(ctx, host) {
|
|
1086
|
+
this.ctx = ctx;
|
|
1087
|
+
this.host = host;
|
|
1088
|
+
this.preference = DEFAULT_PREFERENCE;
|
|
1089
|
+
this.media = typeof matchMedia === "undefined" ? void 0 : matchMedia("(prefers-color-scheme: dark)");
|
|
1090
|
+
this.snapshot = this.buildSnapshot();
|
|
1091
|
+
if (this.media !== void 0) {
|
|
1092
|
+
const media = this.media;
|
|
1093
|
+
const onChange = () => {
|
|
1094
|
+
if (this.preference !== "system") return;
|
|
1095
|
+
this.publish();
|
|
1096
|
+
};
|
|
1097
|
+
ctx.effect(() => {
|
|
1098
|
+
media.addEventListener("change", onChange);
|
|
1099
|
+
return () => {
|
|
1100
|
+
media.removeEventListener("change", onChange);
|
|
1101
|
+
};
|
|
1102
|
+
}, "ui-theme: prefers-color-scheme listener");
|
|
1103
|
+
}
|
|
1104
|
+
ctx.effect(() => host.subscribe(() => {
|
|
1105
|
+
this.adopt();
|
|
1106
|
+
}), "ui-theme: settings scope adoption");
|
|
1107
|
+
this.adopt();
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Read the current immutable theme snapshot.
|
|
1111
|
+
* @returns the current snapshot (stable reference until the next change).
|
|
1112
|
+
*/
|
|
1113
|
+
getTheme() {
|
|
1114
|
+
return this.snapshot;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Export the current token directory without reading DOM or computed styles.
|
|
1118
|
+
* @returns stable JSON-safe token descriptions, including registered and override-only names.
|
|
1119
|
+
*/
|
|
1120
|
+
exportInspectTokens() {
|
|
1121
|
+
const tokens = new Map(BUILTIN_INSPECT_TOKENS.map((token) => [token.name, token]));
|
|
1122
|
+
for (const theme of this.themes) for (const name of Object.keys(theme.tokens)) if (!tokens.has(name)) tokens.set(name, dynamicToken(name));
|
|
1123
|
+
for (const layer of this.overrides.values()) for (const name of Object.keys(layer.tokens)) if (!tokens.has(name)) tokens.set(name, dynamicToken(name));
|
|
1124
|
+
return [...tokens.values()].map((token) => ({ ...token })).sort((left, right) => left.name.localeCompare(right.name));
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Switch the theme preference — the only user preference write entry.
|
|
1128
|
+
* Built-in preferences are written through the settings scope and every
|
|
1129
|
+
* accepted value emits `theme/change`.
|
|
1130
|
+
* @param id - a registered theme id or `system`; unknown ids throw.
|
|
1131
|
+
*/
|
|
1132
|
+
setTheme(id) {
|
|
1133
|
+
if (id !== "system" && !this.themes.some((t) => t.id === id)) throw new Error(`theme "${id}" is not registered`);
|
|
1134
|
+
if (this.preference === id) return;
|
|
1135
|
+
this.preference = id;
|
|
1136
|
+
if (isThemePreference(id)) this.host.set(THEME_PREFERENCE_FIELD, id);
|
|
1137
|
+
this.publish();
|
|
1138
|
+
}
|
|
1139
|
+
/** Adopt the scope's accepted durable preference without writing it back. */
|
|
1140
|
+
adopt() {
|
|
1141
|
+
const section = this.host.getSnapshot().value;
|
|
1142
|
+
if (section === void 0 || this.preference === section.preference) return;
|
|
1143
|
+
this.preference = section.preference;
|
|
1144
|
+
this.publish();
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Register a theme. Duplicate id throws (single occupant per id; the
|
|
1148
|
+
* built-in pair counts; `system` is a preference, not a registrable id).
|
|
1149
|
+
* @param definition - theme id, colorScheme, and alias-token overrides.
|
|
1150
|
+
* @returns disposer. Disposing the theme backing the active preference
|
|
1151
|
+
* resets the preference to the default so the UI never keeps tokens of an
|
|
1152
|
+
* unregistered theme.
|
|
1153
|
+
*/
|
|
1154
|
+
register(definition) {
|
|
1155
|
+
if (definition.id === "system") throw new Error("\"system\" is a preference, not a registrable theme id");
|
|
1156
|
+
if (this.themes.some((t) => t.id === definition.id)) throw new Error(`theme "${definition.id}" is already registered`);
|
|
1157
|
+
this.themes = [...this.themes, definition];
|
|
1158
|
+
this.publish();
|
|
1159
|
+
return () => {
|
|
1160
|
+
if (!this.themes.some((t) => t.id === definition.id)) return;
|
|
1161
|
+
this.themes = this.themes.filter((t) => t.id !== definition.id);
|
|
1162
|
+
if (this.preference === definition.id) this.preference = DEFAULT_PREFERENCE;
|
|
1163
|
+
this.publish();
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Stack a token override layer on top of the active theme — the token-level
|
|
1168
|
+
* analogue of slot shading: the base theme stays untouched, layers compose
|
|
1169
|
+
* in seq order with later layers winning per-token, and removing a layer
|
|
1170
|
+
* restores whatever it covered. Calling again with the same source replaces
|
|
1171
|
+
* that source's whole layer and restacks it on top (effect re-registration
|
|
1172
|
+
* semantics). Emits `theme/change` with the recomposed snapshot.
|
|
1173
|
+
* @param source - layer identity; one layer per source (dynamic packages
|
|
1174
|
+
* pass their package id — the façade pins it, so it also names the layer's
|
|
1175
|
+
* origin for inspection).
|
|
1176
|
+
* @param tokens - token-name → `{ light, dark }` value pairs. Validated at
|
|
1177
|
+
* runtime (model-authored callers reach this boundary with untyped JS);
|
|
1178
|
+
* a bare string value throws a teaching error.
|
|
1179
|
+
* @returns disposer removing exactly the layer this call created; a no-op
|
|
1180
|
+
* once the source has re-overridden (the newer layer is not torn down).
|
|
1181
|
+
*/
|
|
1182
|
+
overrideTokens(source, tokens) {
|
|
1183
|
+
const layer = {
|
|
1184
|
+
seq: this.overrideSeq++,
|
|
1185
|
+
tokens: validateOverrides(source, tokens)
|
|
1186
|
+
};
|
|
1187
|
+
this.overrides.set(source, layer);
|
|
1188
|
+
this.publish();
|
|
1189
|
+
return () => {
|
|
1190
|
+
if (this.overrides.get(source) !== layer) return;
|
|
1191
|
+
this.overrides.delete(source);
|
|
1192
|
+
this.publish();
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
buildSnapshot() {
|
|
1196
|
+
const resolvedId = this.preference === "system" ? this.media?.matches === true ? "dark" : "light" : this.preference;
|
|
1197
|
+
const active = this.themes.find((t) => t.id === resolvedId);
|
|
1198
|
+
/* v8 ignore next 2 -- needs a registry without light/dark, which register()/dispose() cannot produce */
|
|
1199
|
+
if (active === void 0) throw new Error(`theme registry lost "${resolvedId}"`);
|
|
1200
|
+
return Object.freeze({
|
|
1201
|
+
preference: this.preference,
|
|
1202
|
+
active: this.composeActive(active),
|
|
1203
|
+
themes: Object.freeze([...this.themes]),
|
|
1204
|
+
revision: this.revision
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Fold the override layers into the active definition: seq order, later
|
|
1209
|
+
* layers win per-token, each value picked for the active color scheme (the
|
|
1210
|
+
* presenter consumes the composed snapshot and needs no override awareness).
|
|
1211
|
+
* Without layers the registered definition passes through by identity.
|
|
1212
|
+
*/
|
|
1213
|
+
composeActive(active) {
|
|
1214
|
+
if (this.overrides.size === 0) return active;
|
|
1215
|
+
const tokens = { ...active.tokens };
|
|
1216
|
+
for (const layer of [...this.overrides.values()].sort((a, b) => a.seq - b.seq)) for (const [name, modes] of Object.entries(layer.tokens)) tokens[name] = modes[active.colorScheme];
|
|
1217
|
+
return Object.freeze({
|
|
1218
|
+
...active,
|
|
1219
|
+
tokens: Object.freeze(tokens)
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
publish() {
|
|
1223
|
+
this.revision += 1;
|
|
1224
|
+
this.snapshot = this.buildSnapshot();
|
|
1225
|
+
this.ctx.emit("theme/change", this.snapshot);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
/**
|
|
1229
|
+
* Runtime shape check for one override layer (model-authored callers pass
|
|
1230
|
+
* untyped JS through the dynamic-package façade, so the static type cannot
|
|
1231
|
+
* enforce the pair shape there). Returns a defensive per-token copy so later
|
|
1232
|
+
* caller mutation cannot reach the stored layer.
|
|
1233
|
+
*/
|
|
1234
|
+
function validateOverrides(source, tokens) {
|
|
1235
|
+
const validated = {};
|
|
1236
|
+
for (const [name, value] of Object.entries(tokens)) {
|
|
1237
|
+
if (typeof value === "string") throw new TypeError(`theme override "${name}" from "${source}" is a bare string — pass { light: ${JSON.stringify(value)}, dark: ${JSON.stringify(value)} } (repeat the value when it is the same in both palettes); a single value goes illegible when the user switches color scheme`);
|
|
1238
|
+
if (typeof value !== "object" || value === null || typeof value.light !== "string" || typeof value.dark !== "string") throw new TypeError(`theme override "${name}" from "${source}" must map to a { light, dark } pair of strings — one value per color scheme`);
|
|
1239
|
+
const modes = value;
|
|
1240
|
+
validated[name] = {
|
|
1241
|
+
light: modes.light,
|
|
1242
|
+
dark: modes.dark
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
return validated;
|
|
1246
|
+
}
|
|
1247
|
+
function dynamicToken(name) {
|
|
1248
|
+
return {
|
|
1249
|
+
name,
|
|
1250
|
+
description: "Theme token registered by the current Client composition.",
|
|
1251
|
+
valueType: "CSS value",
|
|
1252
|
+
requiresLightAndDark: true,
|
|
1253
|
+
...name.startsWith("--") ? { cssVariable: name } : {}
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Required services: settings transport plus slots/locale for the Appearance
|
|
1258
|
+
* row. `remote` carries the forwarded settings invalidation that
|
|
1259
|
+
* `bindSettingsScope` subscribes to on this context.
|
|
1260
|
+
*/
|
|
1261
|
+
const inject = [
|
|
1262
|
+
"slots",
|
|
1263
|
+
"locale",
|
|
1264
|
+
"connection",
|
|
1265
|
+
"remote",
|
|
1266
|
+
"settingsScope"
|
|
1267
|
+
];
|
|
1268
|
+
/**
|
|
1269
|
+
* Client plugin body: provide the theme service and register the
|
|
1270
|
+
* feature-owned Appearance preference row into the General section's item
|
|
1271
|
+
* slot (a feature owns its settings surface).
|
|
1272
|
+
* @param ctx - client cordis context.
|
|
1273
|
+
*/
|
|
1274
|
+
function apply(ctx) {
|
|
1275
|
+
const theme = new ThemeRuntime(ctx, ctx.settingsScope.bind({ namespace: THEME_SETTINGS_NAMESPACE }));
|
|
1276
|
+
ctx.provide("theme", theme);
|
|
1277
|
+
ctx.effect(() => ctx.locale.register(SETTINGS_NS, {
|
|
1278
|
+
zh,
|
|
1279
|
+
en
|
|
1280
|
+
}), "ui-theme: settings row dictionaries");
|
|
1281
|
+
const store = createAppearanceRowStore();
|
|
1282
|
+
let bound;
|
|
1283
|
+
const sync = (snapshot) => {
|
|
1284
|
+
bound?.sync(snapshot.preference, snapshot.revision);
|
|
1285
|
+
};
|
|
1286
|
+
ctx.on("theme/change", sync);
|
|
1287
|
+
const injected = (actions) => {
|
|
1288
|
+
bound = actions;
|
|
1289
|
+
sync(theme.getTheme());
|
|
1290
|
+
return { setTheme: (id) => {
|
|
1291
|
+
theme.setTheme(id);
|
|
1292
|
+
} };
|
|
1293
|
+
};
|
|
1294
|
+
ctx.slots.inject("settings.general.item", () => ctx.slots.register({
|
|
1295
|
+
name: "settings.general.item",
|
|
1296
|
+
id: "appearance",
|
|
1297
|
+
order: 10,
|
|
1298
|
+
store,
|
|
1299
|
+
locale: SETTINGS_NS,
|
|
1300
|
+
inject: injected
|
|
1301
|
+
}, AppearanceRow));
|
|
1302
|
+
}
|
|
1303
|
+
//#endregion
|
|
1304
|
+
exports.SETTINGS_NS = SETTINGS_NS;
|
|
1305
|
+
exports.ThemeRuntime = ThemeRuntime;
|
|
1306
|
+
exports.apply = apply;
|
|
1307
|
+
exports.inject = inject;
|
|
1308
|
+
return module.exports;
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
//# sourceMappingURL=client.js.map
|