@deepseek-ai/dsh-client-ui-theme 0.0.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,1126 @@
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 _deepseek_ai_dsh_client_runtime_client = require("@deepseek-ai/dsh-client-runtime/client");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
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:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-theme/src/client/AppearanceRow.module.css.mjs
26
+ const css = "._8HJdBW_group{border-bottom:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:8px;padding:16px 0;display:flex}._8HJdBW_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}._8HJdBW_cubeRow{flex-wrap:wrap;align-items:stretch;gap:8px;display:flex}._8HJdBW_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}._8HJdBW_themeCube:hover:not(._8HJdBW_selected){background:var(--dsw-alias-interactive-bg-hover)}._8HJdBW_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
+ "selected": "_8HJdBW_selected",
37
+ "group": "_8HJdBW_group",
38
+ "cubeRow": "_8HJdBW_cubeRow",
39
+ "themeCube": "_8HJdBW_themeCube",
40
+ "title": "_8HJdBW_title"
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
+ /**
966
+ * Theme registry and preference owner. `light`/`dark` are built in (the base
967
+ * stylesheets carry both palettes); third-party themes register alias-layer
968
+ * overrides. Reads go through {@link getTheme}; writes only through
969
+ * {@link setTheme}; continuous sync only through the `theme/change` event.
970
+ * The service holds the `prefers-color-scheme` media query (environment
971
+ * sensing, not presentation) and re-emits when the OS scheme flips while the
972
+ * preference is `system`.
973
+ */
974
+ var ThemeService = class {
975
+ ctx;
976
+ host;
977
+ themes = [...BUILTIN_THEMES];
978
+ preference;
979
+ revision = 0;
980
+ snapshot;
981
+ media;
982
+ /**
983
+ * @param ctx - owning context (change events are emitted on it; the
984
+ * media-query and scope listeners are released through ctx.effect on dispose).
985
+ * @param host - durable preference scope owned by the same plugin.
986
+ */
987
+ constructor(ctx, host) {
988
+ this.ctx = ctx;
989
+ this.host = host;
990
+ this.preference = DEFAULT_PREFERENCE;
991
+ this.media = typeof matchMedia === "undefined" ? void 0 : matchMedia("(prefers-color-scheme: dark)");
992
+ this.snapshot = this.buildSnapshot();
993
+ if (this.media !== void 0) {
994
+ const media = this.media;
995
+ const onChange = () => {
996
+ if (this.preference !== "system") return;
997
+ this.publish();
998
+ };
999
+ ctx.effect(() => {
1000
+ media.addEventListener("change", onChange);
1001
+ return () => {
1002
+ media.removeEventListener("change", onChange);
1003
+ };
1004
+ }, "ui-theme: prefers-color-scheme listener");
1005
+ }
1006
+ ctx.effect(() => host.subscribe(() => {
1007
+ this.adopt();
1008
+ }), "ui-theme: settings scope adoption");
1009
+ this.adopt();
1010
+ }
1011
+ /**
1012
+ * Read the current immutable theme snapshot.
1013
+ * @returns the current snapshot (stable reference until the next change).
1014
+ */
1015
+ getTheme() {
1016
+ return this.snapshot;
1017
+ }
1018
+ /**
1019
+ * Switch the theme preference — the only user preference write entry.
1020
+ * Built-in preferences are written through the settings scope and every
1021
+ * accepted value emits `theme/change`.
1022
+ * @param id - a registered theme id or `system`; unknown ids throw.
1023
+ */
1024
+ setTheme(id) {
1025
+ if (id !== "system" && !this.themes.some((t) => t.id === id)) throw new Error(`theme "${id}" is not registered`);
1026
+ if (this.preference === id) return;
1027
+ this.preference = id;
1028
+ if (isThemePreference(id)) this.host.set(THEME_PREFERENCE_FIELD, id);
1029
+ this.publish();
1030
+ }
1031
+ /** Adopt the scope's accepted durable preference without writing it back. */
1032
+ adopt() {
1033
+ const section = this.host.getSnapshot().value;
1034
+ if (section === void 0 || this.preference === section.preference) return;
1035
+ this.preference = section.preference;
1036
+ this.publish();
1037
+ }
1038
+ /**
1039
+ * Register a theme. Duplicate id throws (single occupant per id; the
1040
+ * built-in pair counts; `system` is a preference, not a registrable id).
1041
+ * @param definition - theme id, colorScheme, and alias-token overrides.
1042
+ * @returns disposer. Disposing the theme backing the active preference
1043
+ * resets the preference to the default so the UI never keeps tokens of an
1044
+ * unregistered theme.
1045
+ */
1046
+ register(definition) {
1047
+ if (definition.id === "system") throw new Error("\"system\" is a preference, not a registrable theme id");
1048
+ if (this.themes.some((t) => t.id === definition.id)) throw new Error(`theme "${definition.id}" is already registered`);
1049
+ this.themes = [...this.themes, definition];
1050
+ this.publish();
1051
+ return () => {
1052
+ if (!this.themes.some((t) => t.id === definition.id)) return;
1053
+ this.themes = this.themes.filter((t) => t.id !== definition.id);
1054
+ if (this.preference === definition.id) this.preference = DEFAULT_PREFERENCE;
1055
+ this.publish();
1056
+ };
1057
+ }
1058
+ buildSnapshot() {
1059
+ const resolvedId = this.preference === "system" ? this.media?.matches === true ? "dark" : "light" : this.preference;
1060
+ const active = this.themes.find((t) => t.id === resolvedId);
1061
+ /* v8 ignore next 2 -- needs a registry without light/dark, which register()/dispose() cannot produce */
1062
+ if (active === void 0) throw new Error(`theme registry lost "${resolvedId}"`);
1063
+ return Object.freeze({
1064
+ preference: this.preference,
1065
+ active,
1066
+ themes: Object.freeze([...this.themes]),
1067
+ revision: this.revision
1068
+ });
1069
+ }
1070
+ publish() {
1071
+ this.revision += 1;
1072
+ this.snapshot = this.buildSnapshot();
1073
+ this.ctx.emit("theme/change", this.snapshot);
1074
+ }
1075
+ };
1076
+ /** Required services: settings transport plus slots/locale for the Appearance row. */
1077
+ const inject = [
1078
+ "slots",
1079
+ "locale",
1080
+ "connection"
1081
+ ];
1082
+ /**
1083
+ * Client plugin body: provide the theme service and register the
1084
+ * feature-owned Appearance preference row into the General section's item
1085
+ * slot (a feature owns its settings surface).
1086
+ * @param ctx - client cordis context.
1087
+ */
1088
+ function apply(ctx) {
1089
+ const theme = new ThemeService(ctx, (0, _deepseek_ai_dsh_client_runtime_client.bindSettingsScope)(ctx, { namespace: THEME_SETTINGS_NAMESPACE }));
1090
+ ctx.provide("theme", theme);
1091
+ ctx.effect(() => ctx.locale.register(SETTINGS_NS, {
1092
+ zh,
1093
+ en
1094
+ }), "ui-theme: settings row dictionaries");
1095
+ const store = createAppearanceRowStore();
1096
+ let bound;
1097
+ const sync = (snapshot) => {
1098
+ bound?.sync(snapshot.preference, snapshot.revision);
1099
+ };
1100
+ ctx.on("theme/change", sync);
1101
+ const injected = (actions) => {
1102
+ bound = actions;
1103
+ sync(theme.getTheme());
1104
+ return { setTheme: (id) => {
1105
+ theme.setTheme(id);
1106
+ } };
1107
+ };
1108
+ ctx.slots.inject("settings.general.item", () => ctx.slots.register({
1109
+ name: "settings.general.item",
1110
+ id: "appearance",
1111
+ order: 10,
1112
+ store,
1113
+ locale: SETTINGS_NS,
1114
+ inject: injected
1115
+ }, AppearanceRow));
1116
+ }
1117
+ //#endregion
1118
+ exports.SETTINGS_NS = SETTINGS_NS;
1119
+ exports.ThemeService = ThemeService;
1120
+ exports.apply = apply;
1121
+ exports.inject = inject;
1122
+ return module.exports;
1123
+ }
1124
+ });
1125
+
1126
+ //# sourceMappingURL=client.js.map