@eum-agent/personalization 0.0.0-stage → 1.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/dist/index.js +152 -0
- package/package.json +51 -3
- package/ui/fonts/atkinson-LICENSE.txt +93 -0
- package/ui/fonts/atkinson.woff2 +0 -0
- package/ui/fonts/literata-LICENSE.txt +93 -0
- package/ui/fonts/literata.woff2 +0 -0
- package/ui/fonts/manifest.json +72 -0
- package/ui/fonts/source-han-sans-LICENSE.txt +96 -0
- package/ui/fonts/source-han-sans.otf +0 -0
- package/ui/fonts/source-han-serif-LICENSE.txt +96 -0
- package/ui/fonts/source-han-serif.otf +0 -0
- package/ui/fonts/source-sans-LICENSE.txt +93 -0
- package/ui/fonts/source-sans.woff2 +0 -0
- package/ui/fonts/source-serif-LICENSE.txt +93 -0
- package/ui/fonts/source-serif.woff2 +0 -0
- package/ui/fonts/wenkai-LICENSE.txt +94 -0
- package/ui/fonts/wenkai.ttf +0 -0
- package/ui/ui.js +1431 -0
- package/README.md +0 -3
package/ui/ui.js
ADDED
|
@@ -0,0 +1,1431 @@
|
|
|
1
|
+
import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, FALLBACK_LANGUAGE, Field, FontPicker, InputNumber, LANGUAGES, LANGUAGE_FLAGS, PLUGIN_ICONS, Picker, Segmented, Select, SettingsPreview, SlotOutlet, ThemeColorPicker, cn, contributionsIn, i18next, localeLeaves, notifyReadingLayout, resolveLabel, themeSwatchColor, useDeviceFonts, usePlugins, useTranslation } from "@eum-agent/host/framework";
|
|
2
|
+
import React, { useEffect, useId, useMemo, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region ui-src/i18n.ts
|
|
5
|
+
/** Platform browser strings share the host's language and React translation runtime. */
|
|
6
|
+
var translations;
|
|
7
|
+
/** Binds this activation's registered namespace without reconstructing the owner's namespace. */
|
|
8
|
+
function configureTranslations(ctx) {
|
|
9
|
+
translations = ctx.i18n;
|
|
10
|
+
}
|
|
11
|
+
/** Observes the shared language while resolving platform-owned copy. */
|
|
12
|
+
function useTranslation$1() {
|
|
13
|
+
const shared = useTranslation();
|
|
14
|
+
if (!translations) throw new Error("platform browser translations are not registered");
|
|
15
|
+
return {
|
|
16
|
+
...shared,
|
|
17
|
+
t: translations.t
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
var en_US_default = {
|
|
21
|
+
settings: {
|
|
22
|
+
"personalization": "Personalization",
|
|
23
|
+
"close": "Close",
|
|
24
|
+
"colorMode": "Color scheme",
|
|
25
|
+
"systemMode": "System",
|
|
26
|
+
"lightMode": "Light",
|
|
27
|
+
"darkMode": "Dark",
|
|
28
|
+
"brand": "Theme colour",
|
|
29
|
+
"contentWidth": "Content width",
|
|
30
|
+
"contentWidthDefault": "Default",
|
|
31
|
+
"contentWidthWide": "Wide",
|
|
32
|
+
"contentWidthFull": "Full",
|
|
33
|
+
"interfaceLanguage": "Interface language",
|
|
34
|
+
"interfaceCategory": "Interface",
|
|
35
|
+
"readingCategory": "Reading",
|
|
36
|
+
"personalizationCategories": "Personalization categories",
|
|
37
|
+
"personalizationEmpty": "No personalization settings are available",
|
|
38
|
+
"preview": "Preview",
|
|
39
|
+
"previewInfo": "Preview information",
|
|
40
|
+
"previewReading": "Reading text",
|
|
41
|
+
"previewDescription": "This fixed sample updates with your font and size choices, using system fallbacks for missing fonts. It previews typography only; content width applies to actual reading surfaces. It sends no messages and runs no commands.",
|
|
42
|
+
"resetCategory": "Reset to defaults"
|
|
43
|
+
},
|
|
44
|
+
brand: {
|
|
45
|
+
"violet": "Violet",
|
|
46
|
+
"alkaid": "Azure",
|
|
47
|
+
"celadon": "Teal",
|
|
48
|
+
"moss": "Green",
|
|
49
|
+
"honey": "Amber",
|
|
50
|
+
"lotus": "Rose"
|
|
51
|
+
},
|
|
52
|
+
language: {
|
|
53
|
+
"zh-CN": "简体中文",
|
|
54
|
+
"en-US": "English"
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var zh_CN_default = {
|
|
58
|
+
settings: {
|
|
59
|
+
"personalization": "个性化设置",
|
|
60
|
+
"close": "关闭",
|
|
61
|
+
"colorMode": "显示模式",
|
|
62
|
+
"systemMode": "跟随系统",
|
|
63
|
+
"lightMode": "浅色",
|
|
64
|
+
"darkMode": "深色",
|
|
65
|
+
"brand": "主题色",
|
|
66
|
+
"contentWidth": "内容宽度",
|
|
67
|
+
"contentWidthDefault": "默认",
|
|
68
|
+
"contentWidthWide": "宽屏",
|
|
69
|
+
"contentWidthFull": "全宽",
|
|
70
|
+
"interfaceLanguage": "界面语言",
|
|
71
|
+
"interfaceCategory": "界面",
|
|
72
|
+
"readingCategory": "阅读",
|
|
73
|
+
"personalizationCategories": "个性化分类",
|
|
74
|
+
"personalizationEmpty": "暂无可用的个性化设置",
|
|
75
|
+
"preview": "预览",
|
|
76
|
+
"previewInfo": "预览说明",
|
|
77
|
+
"previewReading": "阅读文本",
|
|
78
|
+
"previewDescription": "固定示例会随字体与字号即时更新,字体缺失时使用系统回退。阅读示例仅预览字体与字号;内容宽度作用于实际阅读区域。不会发送消息或执行命令。",
|
|
79
|
+
"resetCategory": "恢复默认"
|
|
80
|
+
},
|
|
81
|
+
brand: {
|
|
82
|
+
"violet": "鸢紫",
|
|
83
|
+
"alkaid": "澄蓝",
|
|
84
|
+
"celadon": "湖青",
|
|
85
|
+
"moss": "松绿",
|
|
86
|
+
"honey": "琥珀",
|
|
87
|
+
"lotus": "玫瑰"
|
|
88
|
+
},
|
|
89
|
+
language: {
|
|
90
|
+
"zh-CN": "简体中文",
|
|
91
|
+
"en-US": "English"
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ui-src/catalogues.ts
|
|
96
|
+
/** Registers this owner's localized client copy for its activation. */
|
|
97
|
+
function registerTranslations(ctx) {
|
|
98
|
+
configureTranslations(ctx);
|
|
99
|
+
ctx.i18n.register({
|
|
100
|
+
"en-US": localeLeaves(en_US_default),
|
|
101
|
+
"zh-CN": localeLeaves(zh_CN_default)
|
|
102
|
+
}, "zh-CN");
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region ui-src/fonts/manifest.json
|
|
106
|
+
var manifest_default = [
|
|
107
|
+
{
|
|
108
|
+
"id": "wenkai",
|
|
109
|
+
"file": "wenkai.ttf",
|
|
110
|
+
"revision": "v1.522",
|
|
111
|
+
"source": "https://github.com/lxgw/LxgwWenKai-Screen/releases/download/v1.522/LXGWWenKaiScreen.ttf",
|
|
112
|
+
"license": "wenkai-LICENSE.txt",
|
|
113
|
+
"weight": "400",
|
|
114
|
+
"bytes": 25673994,
|
|
115
|
+
"sha256": "cd1a6fa39c4ea42fd8f4e289945789b0e510cf7016435640f8893cdad9b220f3"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "source-han-serif",
|
|
119
|
+
"file": "source-han-serif.otf",
|
|
120
|
+
"revision": "7889f11bf31170b5d092a083b357c8c8130f89e0",
|
|
121
|
+
"source": "https://raw.githubusercontent.com/adobe-fonts/source-han-serif/7889f11bf31170b5d092a083b357c8c8130f89e0/SubsetOTF/CN/SourceHanSerifCN-Regular.otf",
|
|
122
|
+
"license": "source-han-serif-LICENSE.txt",
|
|
123
|
+
"weight": "400",
|
|
124
|
+
"bytes": 11626108,
|
|
125
|
+
"sha256": "3754ea669c530e2473354f8f6d9f79680a44d7e26ec7d00eeabee4a7e0753c5d"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"id": "source-han-sans",
|
|
129
|
+
"file": "source-han-sans.otf",
|
|
130
|
+
"revision": "6c709ca72d3d7c46ab42ebecc1a26e7d69595a37",
|
|
131
|
+
"source": "https://raw.githubusercontent.com/adobe-fonts/source-han-sans/6c709ca72d3d7c46ab42ebecc1a26e7d69595a37/SubsetOTF/CN/SourceHanSansCN-Regular.otf",
|
|
132
|
+
"license": "source-han-sans-LICENSE.txt",
|
|
133
|
+
"weight": "400",
|
|
134
|
+
"bytes": 8429224,
|
|
135
|
+
"sha256": "e2bc8a2e7f37474b774fff8db758681ece40bb6947a90d571bce9dd60671a8e4"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"id": "source-serif",
|
|
139
|
+
"file": "source-serif.woff2",
|
|
140
|
+
"revision": "2823e993c53fca27c5c8749f529b56a5a7c77b6b",
|
|
141
|
+
"source": "https://raw.githubusercontent.com/adobe-fonts/source-serif/2823e993c53fca27c5c8749f529b56a5a7c77b6b/WOFF2/VAR/SourceSerif4Variable-Roman.otf.woff2",
|
|
142
|
+
"license": "source-serif-LICENSE.txt",
|
|
143
|
+
"weight": "200 900",
|
|
144
|
+
"bytes": 426716,
|
|
145
|
+
"sha256": "f146ee102dddcc5bc7a2cf4af5bcf129832195941b92bd0a512626f390688c1e"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"id": "source-sans",
|
|
149
|
+
"file": "source-sans.woff2",
|
|
150
|
+
"revision": "ed1808970eb3c7301c9a523bee26473ba0bb62fa",
|
|
151
|
+
"source": "https://raw.githubusercontent.com/adobe-fonts/source-sans/ed1808970eb3c7301c9a523bee26473ba0bb62fa/WOFF2/OTF/SourceSans3-Regular.otf.woff2",
|
|
152
|
+
"license": "source-sans-LICENSE.txt",
|
|
153
|
+
"weight": "400",
|
|
154
|
+
"bytes": 153800,
|
|
155
|
+
"sha256": "63de0da0cc05298e2e9c6e5cef506d8454ca665f6e668a99d94f51174b9256ed"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"id": "atkinson",
|
|
159
|
+
"file": "atkinson.woff2",
|
|
160
|
+
"revision": "7925f50f649b3813257faf2f4c0b381011f434f1",
|
|
161
|
+
"source": "https://raw.githubusercontent.com/googlefonts/atkinson-hyperlegible-next/7925f50f649b3813257faf2f4c0b381011f434f1/fonts/webfonts/AtkinsonHyperlegibleNext%5Bwght%5D.woff2",
|
|
162
|
+
"license": "atkinson-LICENSE.txt",
|
|
163
|
+
"weight": "200 800",
|
|
164
|
+
"bytes": 48188,
|
|
165
|
+
"sha256": "abde1ad5cf78b9ac575ef90d991f2e9101eb0b3b6668bde9a00e2e1e27d99afd"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "literata",
|
|
169
|
+
"file": "literata.woff2",
|
|
170
|
+
"revision": "0c2761b727a1b3a7cffd313c37f0f5163dfc7a63",
|
|
171
|
+
"source": "https://raw.githubusercontent.com/googlefonts/literata/0c2761b727a1b3a7cffd313c37f0f5163dfc7a63/fonts/webfonts/Literata%5Bopsz%2Cwght%5D.woff2",
|
|
172
|
+
"license": "literata-LICENSE.txt",
|
|
173
|
+
"weight": "200 900",
|
|
174
|
+
"bytes": 396224,
|
|
175
|
+
"sha256": "5e50643479bee69e0204164602f830502b0db42bbc29da83edc9980df17e34df"
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region ui-src/font-assets.ts
|
|
180
|
+
/** Immutable packaged fonts with exact upstream revision, size, license and digest. */
|
|
181
|
+
var READING_FONT_ASSETS = manifest_default;
|
|
182
|
+
/** Returns an owner-specific CSS alias independent of an installed device font name. */
|
|
183
|
+
function readingFontAlias(id) {
|
|
184
|
+
if (!manifest_default.some((asset) => asset.id === id)) throw new Error("Unknown reading font");
|
|
185
|
+
return `yaoguang-personalization-${id}`;
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region ui-src/store/reading-typography.ts
|
|
189
|
+
/** Storage identifier independent of theme and terminal preferences. */
|
|
190
|
+
var READING_TYPOGRAPHY_KEY = "yaoguang.readingTypography";
|
|
191
|
+
/** Initial reading appearance shared by restoration and reset. */
|
|
192
|
+
var DEFAULT_READING_TYPOGRAPHY = {
|
|
193
|
+
chinese: {
|
|
194
|
+
kind: "builtin",
|
|
195
|
+
value: "wenkai"
|
|
196
|
+
},
|
|
197
|
+
western: {
|
|
198
|
+
kind: "builtin",
|
|
199
|
+
value: "wenkai"
|
|
200
|
+
},
|
|
201
|
+
bodySize: 14
|
|
202
|
+
};
|
|
203
|
+
var chineseFonts = /* @__PURE__ */ new Set([
|
|
204
|
+
"wenkai",
|
|
205
|
+
"source-han-serif",
|
|
206
|
+
"source-han-sans"
|
|
207
|
+
]);
|
|
208
|
+
var westernFonts = /* @__PURE__ */ new Set([
|
|
209
|
+
"wenkai",
|
|
210
|
+
"source-serif",
|
|
211
|
+
"source-sans",
|
|
212
|
+
"atkinson",
|
|
213
|
+
"literata"
|
|
214
|
+
]);
|
|
215
|
+
/** Creates isolated preferences without acquiring browser listeners or gateway state. */
|
|
216
|
+
function createReadingTypography(options) {
|
|
217
|
+
function font(value, allowed) {
|
|
218
|
+
if (!value || typeof value !== "object") return void 0;
|
|
219
|
+
const candidate = value;
|
|
220
|
+
if (candidate.kind === "system") return { kind: "system" };
|
|
221
|
+
if (typeof candidate.value !== "string") return void 0;
|
|
222
|
+
if (candidate.kind === "builtin" && allowed.has(candidate.value)) return {
|
|
223
|
+
kind: "builtin",
|
|
224
|
+
value: candidate.value
|
|
225
|
+
};
|
|
226
|
+
if (candidate.kind === "custom" && candidate.value.trim() && candidate.value.length <= 512 && options.validFamily(candidate.value)) return {
|
|
227
|
+
kind: "custom",
|
|
228
|
+
value: candidate.value
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function parse(raw) {
|
|
232
|
+
let value = {};
|
|
233
|
+
try {
|
|
234
|
+
const parsed = raw === null ? null : JSON.parse(raw);
|
|
235
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) value = parsed;
|
|
236
|
+
} catch {}
|
|
237
|
+
return {
|
|
238
|
+
chinese: font(value.chinese, chineseFonts) ?? DEFAULT_READING_TYPOGRAPHY.chinese,
|
|
239
|
+
western: font(value.western, westernFonts) ?? DEFAULT_READING_TYPOGRAPHY.western,
|
|
240
|
+
bodySize: typeof value.bodySize === "number" && Number.isInteger(value.bodySize) && value.bodySize >= 14 && value.bodySize <= 22 ? value.bodySize : DEFAULT_READING_TYPOGRAPHY.bodySize
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
let initial = null;
|
|
244
|
+
try {
|
|
245
|
+
initial = options.storage.getItem(READING_TYPOGRAPHY_KEY);
|
|
246
|
+
} catch {}
|
|
247
|
+
let snapshot = {
|
|
248
|
+
preferences: parse(initial),
|
|
249
|
+
saveFailed: false
|
|
250
|
+
};
|
|
251
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
252
|
+
function publish(preferences, persist) {
|
|
253
|
+
let saveFailed = false;
|
|
254
|
+
if (persist) try {
|
|
255
|
+
options.storage.setItem(READING_TYPOGRAPHY_KEY, JSON.stringify(preferences));
|
|
256
|
+
} catch {
|
|
257
|
+
saveFailed = true;
|
|
258
|
+
}
|
|
259
|
+
snapshot = {
|
|
260
|
+
preferences,
|
|
261
|
+
saveFailed
|
|
262
|
+
};
|
|
263
|
+
for (const listener of listeners) listener();
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
/** Returns a stable snapshot until the next preference change. */
|
|
267
|
+
getSnapshot: () => snapshot,
|
|
268
|
+
/** Observes memory changes, including failed persistence. */
|
|
269
|
+
subscribe(listener) {
|
|
270
|
+
listeners.add(listener);
|
|
271
|
+
return () => {
|
|
272
|
+
listeners.delete(listener);
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
/** Validates all supplied fields atomically before applying and attempting persistence. */
|
|
276
|
+
update(patch) {
|
|
277
|
+
if (patch.chinese !== void 0 && !font(patch.chinese, chineseFonts)) return false;
|
|
278
|
+
if (patch.western !== void 0 && !font(patch.western, westernFonts)) return false;
|
|
279
|
+
if (patch.bodySize !== void 0 && (!Number.isInteger(patch.bodySize) || patch.bodySize < 14 || patch.bodySize > 22)) return false;
|
|
280
|
+
publish({
|
|
281
|
+
chinese: patch.chinese === void 0 ? snapshot.preferences.chinese : font(patch.chinese, chineseFonts),
|
|
282
|
+
western: patch.western === void 0 ? snapshot.preferences.western : font(patch.western, westernFonts),
|
|
283
|
+
bodySize: patch.bodySize ?? snapshot.preferences.bodySize
|
|
284
|
+
}, true);
|
|
285
|
+
return true;
|
|
286
|
+
},
|
|
287
|
+
/** Restores a storage event without echoing it to other pages. */
|
|
288
|
+
restore(raw) {
|
|
289
|
+
publish(parse(raw), false);
|
|
290
|
+
},
|
|
291
|
+
/** Resets only reading preferences, leaving other local settings intact. */
|
|
292
|
+
reset() {
|
|
293
|
+
publish(DEFAULT_READING_TYPOGRAPHY, true);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region ui-src/lib/font-resource.ts
|
|
299
|
+
/** Binds a fixed packaged asset to its current owner resource without exposing credentials or paths. */
|
|
300
|
+
function resourceFontFace(ctx, id) {
|
|
301
|
+
const asset = READING_FONT_ASSETS.find((asset) => asset.id === id);
|
|
302
|
+
if (!asset) throw new Error("Unknown reading font");
|
|
303
|
+
const controller = new AbortController();
|
|
304
|
+
const signal = AbortSignal.any([ctx.signal, controller.signal]);
|
|
305
|
+
const entry = {
|
|
306
|
+
cancel: () => controller.abort(),
|
|
307
|
+
async load() {
|
|
308
|
+
const surface = await ctx.call("plugin.surface");
|
|
309
|
+
signal.throwIfAborted();
|
|
310
|
+
const descriptor = surface.plugins.find((plugin) => plugin.plugin === ctx.plugin)?.resources?.find((resource) => resource.local === "fontBytes");
|
|
311
|
+
if (!descriptor) throw new Error("Reading font resource unavailable");
|
|
312
|
+
const read = await ctx.bytes.read(descriptor, { id }, { signal });
|
|
313
|
+
try {
|
|
314
|
+
if (read.bytes.contentLength !== asset.bytes) throw new Error("Reading font length changed");
|
|
315
|
+
const bytes = new Uint8Array(asset.bytes);
|
|
316
|
+
let offset = 0;
|
|
317
|
+
for await (const chunk of read.body) {
|
|
318
|
+
signal.throwIfAborted();
|
|
319
|
+
if (offset + chunk.byteLength > bytes.byteLength) throw new Error("Reading font exceeds its bound");
|
|
320
|
+
bytes.set(chunk, offset);
|
|
321
|
+
offset += chunk.byteLength;
|
|
322
|
+
}
|
|
323
|
+
if (offset !== bytes.byteLength) throw new Error("Reading font ended early");
|
|
324
|
+
signal.throwIfAborted();
|
|
325
|
+
entry.face = new FontFace(readingFontAlias(id), bytes, { weight: asset.weight });
|
|
326
|
+
await entry.face.load();
|
|
327
|
+
} finally {
|
|
328
|
+
const finished = read.close();
|
|
329
|
+
ctx.cleanup.retain(finished);
|
|
330
|
+
await finished;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
return entry;
|
|
335
|
+
}
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region ui-src/lib/reading-fonts.ts
|
|
338
|
+
/** Loads selected faces only and prevents late completion from restoring a withdrawn owner. */
|
|
339
|
+
function createReadingFonts(host) {
|
|
340
|
+
const entries = /* @__PURE__ */ new Map();
|
|
341
|
+
let wanted = /* @__PURE__ */ new Set();
|
|
342
|
+
let disposed = false;
|
|
343
|
+
return {
|
|
344
|
+
/** Returns failed asset IDs; callers keep readable fallback families until a later retry. */
|
|
345
|
+
async select(ids) {
|
|
346
|
+
if (disposed) return [];
|
|
347
|
+
wanted = new Set(ids);
|
|
348
|
+
for (const [id, entry] of entries) if (!wanted.has(id)) {
|
|
349
|
+
entry.face.cancel?.();
|
|
350
|
+
if (entry.installed) host.remove(entry.face);
|
|
351
|
+
entries.delete(id);
|
|
352
|
+
}
|
|
353
|
+
return (await Promise.all([...wanted].map(async (id) => {
|
|
354
|
+
let entry = entries.get(id);
|
|
355
|
+
if (!entry) {
|
|
356
|
+
const face = host.create(id);
|
|
357
|
+
const next = {
|
|
358
|
+
face,
|
|
359
|
+
installed: false,
|
|
360
|
+
work: Promise.resolve(false)
|
|
361
|
+
};
|
|
362
|
+
entries.set(id, next);
|
|
363
|
+
next.work = face.load().then(() => {
|
|
364
|
+
if (disposed || !wanted.has(id) || entries.get(id) !== next) return false;
|
|
365
|
+
host.add(face);
|
|
366
|
+
next.installed = true;
|
|
367
|
+
return true;
|
|
368
|
+
}, () => {
|
|
369
|
+
if (entries.get(id) === next) entries.delete(id);
|
|
370
|
+
return false;
|
|
371
|
+
});
|
|
372
|
+
entry = next;
|
|
373
|
+
}
|
|
374
|
+
return await entry.work ? void 0 : id;
|
|
375
|
+
}))).filter((id) => id !== void 0);
|
|
376
|
+
},
|
|
377
|
+
/** Withdraws loaded faces and ignores unresolved browser loads. */
|
|
378
|
+
dispose() {
|
|
379
|
+
disposed = true;
|
|
380
|
+
wanted.clear();
|
|
381
|
+
for (const entry of entries.values()) {
|
|
382
|
+
entry.face.cancel?.();
|
|
383
|
+
if (entry.installed) host.remove(entry.face);
|
|
384
|
+
}
|
|
385
|
+
entries.clear();
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region ui-src/lib/reading-typography.ts
|
|
391
|
+
/** Validates a complete font-family list without interpreting it as stylesheet text. */
|
|
392
|
+
function validReadingFontFamily(value) {
|
|
393
|
+
if (typeof document === "undefined") return false;
|
|
394
|
+
const style = document.createElement("span").style;
|
|
395
|
+
style.fontFamily = value;
|
|
396
|
+
return style.fontFamily !== "";
|
|
397
|
+
}
|
|
398
|
+
/** Browser-local preference owner; storage failures remain visible in its snapshot. */
|
|
399
|
+
var readingTypography = createReadingTypography({
|
|
400
|
+
storage: {
|
|
401
|
+
getItem: (key) => localStorage.getItem(key),
|
|
402
|
+
setItem: (key, value) => localStorage.setItem(key, value)
|
|
403
|
+
},
|
|
404
|
+
validFamily: validReadingFontFamily
|
|
405
|
+
});
|
|
406
|
+
/** Resolves the selected reading family with the same asset alias and fallback used by live text. */
|
|
407
|
+
function readingFontFamily(choice) {
|
|
408
|
+
if (choice.kind === "system") return "var(--font-sans)";
|
|
409
|
+
if (choice.kind === "custom") return choice.value;
|
|
410
|
+
return `"${readingFontAlias(choice.value)}", var(--font-sans)`;
|
|
411
|
+
}
|
|
412
|
+
var fontStatus = {
|
|
413
|
+
loading: false,
|
|
414
|
+
failed: []
|
|
415
|
+
};
|
|
416
|
+
var fontListeners = /* @__PURE__ */ new Set();
|
|
417
|
+
/** Reads the stable current asset-loading snapshot. */
|
|
418
|
+
function getReadingFontStatus() {
|
|
419
|
+
return fontStatus;
|
|
420
|
+
}
|
|
421
|
+
/** Observes selected-font loading without exposing browser FontFace objects. */
|
|
422
|
+
function subscribeReadingFontStatus(listener) {
|
|
423
|
+
fontListeners.add(listener);
|
|
424
|
+
return () => {
|
|
425
|
+
fontListeners.delete(listener);
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function publishFontStatus(next) {
|
|
429
|
+
fontStatus = next;
|
|
430
|
+
for (const listener of fontListeners) listener();
|
|
431
|
+
}
|
|
432
|
+
var activation;
|
|
433
|
+
var fontContext;
|
|
434
|
+
var fallbackDiscoverySignal = new AbortController().signal;
|
|
435
|
+
/** Returns the active owner's discovery lifetime and optional native metadata source. */
|
|
436
|
+
function readingFontDiscoveryContext() {
|
|
437
|
+
return {
|
|
438
|
+
signal: fontContext?.signal ?? fallbackDiscoverySignal,
|
|
439
|
+
native: fontContext?.services.get("native-device-fonts")
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
/** Owns reading-only tokens, selected FontFaces and same-origin storage synchronization. */
|
|
443
|
+
function initReadingTypography(ctx) {
|
|
444
|
+
const owner = Symbol();
|
|
445
|
+
activation = owner;
|
|
446
|
+
fontContext = ctx;
|
|
447
|
+
const root = document.documentElement;
|
|
448
|
+
const style = document.createElement("style");
|
|
449
|
+
style.dataset.readingTypography = "";
|
|
450
|
+
style.textContent = `
|
|
451
|
+
[data-reading-body] [data-reading-script] { font-size: var(--reading-text-size, var(--reading-body-size)); }
|
|
452
|
+
[data-reading-body] [data-reading-script="chinese"] { font-family: var(--reading-chinese); }
|
|
453
|
+
[data-reading-body] [data-reading-script="western"] { font-family: var(--reading-western); }
|
|
454
|
+
[data-reading-body] h1 { --reading-text-size: calc(var(--reading-body-size) * 1.7); }
|
|
455
|
+
[data-reading-body] h2 { --reading-text-size: calc(var(--reading-body-size) * 1.4); }
|
|
456
|
+
[data-reading-body] h3 { --reading-text-size: calc(var(--reading-body-size) * 1.2); }
|
|
457
|
+
[data-reading-body] :is(p,li,td,th,blockquote):not([data-slot="widget"] *) { line-height: 1.8; }
|
|
458
|
+
`;
|
|
459
|
+
document.head.append(style);
|
|
460
|
+
const fonts = typeof FontFace === "undefined" ? void 0 : createReadingFonts({
|
|
461
|
+
create: (id) => resourceFontFace(ctx, id),
|
|
462
|
+
add: (entry) => {
|
|
463
|
+
if (entry.face) {
|
|
464
|
+
document.fonts.add(entry.face);
|
|
465
|
+
notifyReadingLayout();
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
remove: (entry) => {
|
|
469
|
+
if (entry.face) document.fonts.delete(entry.face);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
let loadingTicket = 0;
|
|
473
|
+
const apply = () => {
|
|
474
|
+
if (activation !== owner) return;
|
|
475
|
+
const { preferences } = readingTypography.getSnapshot();
|
|
476
|
+
root.style.setProperty("--reading-chinese", readingFontFamily(preferences.chinese));
|
|
477
|
+
root.style.setProperty("--reading-western", readingFontFamily(preferences.western));
|
|
478
|
+
root.style.setProperty("--reading-body-size", `${preferences.bodySize}px`);
|
|
479
|
+
notifyReadingLayout();
|
|
480
|
+
const selected = [preferences.chinese, preferences.western].flatMap((choice) => choice.kind === "builtin" ? [choice.value] : []);
|
|
481
|
+
const ticket = ++loadingTicket;
|
|
482
|
+
publishFontStatus({
|
|
483
|
+
loading: selected.length > 0,
|
|
484
|
+
failed: []
|
|
485
|
+
});
|
|
486
|
+
(fonts ? fonts.select(selected) : Promise.resolve(selected)).then((failed) => {
|
|
487
|
+
if (activation === owner && ticket === loadingTicket) publishFontStatus({
|
|
488
|
+
loading: false,
|
|
489
|
+
failed
|
|
490
|
+
});
|
|
491
|
+
}, () => {
|
|
492
|
+
if (activation === owner && ticket === loadingTicket) publishFontStatus({
|
|
493
|
+
loading: false,
|
|
494
|
+
failed: selected
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
const stop = readingTypography.subscribe(apply);
|
|
499
|
+
const storage = (event) => {
|
|
500
|
+
if (activation === owner && (event.key === "yaoguang.readingTypography" || event.key === null)) readingTypography.restore(event.newValue);
|
|
501
|
+
};
|
|
502
|
+
window.addEventListener("storage", storage);
|
|
503
|
+
apply();
|
|
504
|
+
return () => {
|
|
505
|
+
stop();
|
|
506
|
+
window.removeEventListener("storage", storage);
|
|
507
|
+
fonts?.dispose();
|
|
508
|
+
style.remove();
|
|
509
|
+
if (activation !== owner) return;
|
|
510
|
+
activation = void 0;
|
|
511
|
+
fontContext = void 0;
|
|
512
|
+
publishFontStatus({
|
|
513
|
+
loading: false,
|
|
514
|
+
failed: []
|
|
515
|
+
});
|
|
516
|
+
for (const key of [
|
|
517
|
+
"--reading-chinese",
|
|
518
|
+
"--reading-western",
|
|
519
|
+
"--reading-body-size"
|
|
520
|
+
]) root.style.removeProperty(key);
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/vanilla.mjs
|
|
525
|
+
var createStoreImpl = (createState) => {
|
|
526
|
+
let state;
|
|
527
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
528
|
+
const setState = (partial, replace) => {
|
|
529
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
530
|
+
if (!Object.is(nextState, state)) {
|
|
531
|
+
const previousState = state;
|
|
532
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
533
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
const getState = () => state;
|
|
537
|
+
const getInitialState = () => initialState;
|
|
538
|
+
const subscribe = (listener) => {
|
|
539
|
+
listeners.add(listener);
|
|
540
|
+
return () => listeners.delete(listener);
|
|
541
|
+
};
|
|
542
|
+
const api = {
|
|
543
|
+
setState,
|
|
544
|
+
getState,
|
|
545
|
+
getInitialState,
|
|
546
|
+
subscribe
|
|
547
|
+
};
|
|
548
|
+
const initialState = state = createState(setState, getState, api);
|
|
549
|
+
return api;
|
|
550
|
+
};
|
|
551
|
+
var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/react.mjs
|
|
554
|
+
var identity = (arg) => arg;
|
|
555
|
+
function useStore(api, selector = identity) {
|
|
556
|
+
const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
|
|
557
|
+
React.useDebugValue(slice);
|
|
558
|
+
return slice;
|
|
559
|
+
}
|
|
560
|
+
var createImpl = (createState) => {
|
|
561
|
+
const api = createStore(createState);
|
|
562
|
+
const useBoundStore = (selector) => useStore(api, selector);
|
|
563
|
+
Object.assign(useBoundStore, api);
|
|
564
|
+
return useBoundStore;
|
|
565
|
+
};
|
|
566
|
+
var create = ((createState) => createState ? createImpl(createState) : createImpl);
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region ../../../node_modules/.pnpm/zustand@5.0.15_@types+react@19.2.18_react@19.2.8_use-sync-external-store@1.7.0_react@19.2.8_/node_modules/zustand/esm/middleware.mjs
|
|
569
|
+
function createJSONStorage(getStorage, options) {
|
|
570
|
+
let storage;
|
|
571
|
+
try {
|
|
572
|
+
storage = getStorage();
|
|
573
|
+
} catch (e) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
getItem: (name) => {
|
|
578
|
+
var _a;
|
|
579
|
+
const parse = (str2) => {
|
|
580
|
+
if (str2 === null) return null;
|
|
581
|
+
return JSON.parse(str2, options == null ? void 0 : options.reviver);
|
|
582
|
+
};
|
|
583
|
+
const str = (_a = storage.getItem(name)) != null ? _a : null;
|
|
584
|
+
if (str instanceof Promise) return str.then(parse);
|
|
585
|
+
return parse(str);
|
|
586
|
+
},
|
|
587
|
+
setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer)),
|
|
588
|
+
removeItem: (name) => storage.removeItem(name)
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
var toThenable = (fn) => (input) => {
|
|
592
|
+
try {
|
|
593
|
+
const result = fn(input);
|
|
594
|
+
if (result instanceof Promise) return result;
|
|
595
|
+
return {
|
|
596
|
+
then(onFulfilled) {
|
|
597
|
+
return toThenable(onFulfilled)(result);
|
|
598
|
+
},
|
|
599
|
+
catch(_onRejected) {
|
|
600
|
+
return this;
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
} catch (e) {
|
|
604
|
+
return {
|
|
605
|
+
then(_onFulfilled) {
|
|
606
|
+
return this;
|
|
607
|
+
},
|
|
608
|
+
catch(onRejected) {
|
|
609
|
+
return toThenable(onRejected)(e);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var persistImpl = (config, baseOptions) => (set, get, api) => {
|
|
615
|
+
let options = {
|
|
616
|
+
storage: createJSONStorage(() => window.localStorage),
|
|
617
|
+
partialize: (state) => state,
|
|
618
|
+
version: 0,
|
|
619
|
+
merge: (persistedState, currentState) => ({
|
|
620
|
+
...currentState,
|
|
621
|
+
...persistedState
|
|
622
|
+
}),
|
|
623
|
+
...baseOptions
|
|
624
|
+
};
|
|
625
|
+
let hasHydrated = false;
|
|
626
|
+
let hydrationVersion = 0;
|
|
627
|
+
const hydrationListeners = /* @__PURE__ */ new Set();
|
|
628
|
+
const finishHydrationListeners = /* @__PURE__ */ new Set();
|
|
629
|
+
let storage = options.storage;
|
|
630
|
+
if (!storage) return config((...args) => {
|
|
631
|
+
console.warn(`[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`);
|
|
632
|
+
set(...args);
|
|
633
|
+
}, get, api);
|
|
634
|
+
const setItem = () => {
|
|
635
|
+
const state = options.partialize({ ...get() });
|
|
636
|
+
return storage.setItem(options.name, {
|
|
637
|
+
state,
|
|
638
|
+
version: options.version
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
const savedSetState = api.setState;
|
|
642
|
+
api.setState = (state, replace) => {
|
|
643
|
+
savedSetState(state, replace);
|
|
644
|
+
return setItem();
|
|
645
|
+
};
|
|
646
|
+
const configResult = config((...args) => {
|
|
647
|
+
set(...args);
|
|
648
|
+
return setItem();
|
|
649
|
+
}, get, api);
|
|
650
|
+
api.getInitialState = () => configResult;
|
|
651
|
+
let stateFromStorage;
|
|
652
|
+
const hydrate = () => {
|
|
653
|
+
var _a, _b;
|
|
654
|
+
if (!storage) return;
|
|
655
|
+
const currentVersion = ++hydrationVersion;
|
|
656
|
+
hasHydrated = false;
|
|
657
|
+
hydrationListeners.forEach((cb) => {
|
|
658
|
+
var _a2;
|
|
659
|
+
return cb((_a2 = get()) != null ? _a2 : configResult);
|
|
660
|
+
});
|
|
661
|
+
const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a = get()) != null ? _a : configResult)) || void 0;
|
|
662
|
+
return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
|
|
663
|
+
if (deserializedStorageValue) {
|
|
664
|
+
if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
|
|
665
|
+
if (options.migrate) {
|
|
666
|
+
const migration = options.migrate(deserializedStorageValue.state, deserializedStorageValue.version);
|
|
667
|
+
if (migration instanceof Promise) return migration.then((result) => [true, result]);
|
|
668
|
+
return [true, migration];
|
|
669
|
+
}
|
|
670
|
+
console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`);
|
|
671
|
+
} else return [false, deserializedStorageValue.state];
|
|
672
|
+
}
|
|
673
|
+
return [false, void 0];
|
|
674
|
+
}).then((migrationResult) => {
|
|
675
|
+
var _a2;
|
|
676
|
+
if (currentVersion !== hydrationVersion) return;
|
|
677
|
+
const [migrated, migratedState] = migrationResult;
|
|
678
|
+
stateFromStorage = options.merge(migratedState, (_a2 = get()) != null ? _a2 : configResult);
|
|
679
|
+
set(stateFromStorage, true);
|
|
680
|
+
if (migrated) return setItem();
|
|
681
|
+
}).then(() => {
|
|
682
|
+
if (currentVersion !== hydrationVersion) return;
|
|
683
|
+
postRehydrationCallback?.(get(), void 0);
|
|
684
|
+
stateFromStorage = get();
|
|
685
|
+
hasHydrated = true;
|
|
686
|
+
finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
|
|
687
|
+
}).catch((e) => {
|
|
688
|
+
if (currentVersion !== hydrationVersion) return;
|
|
689
|
+
postRehydrationCallback?.(void 0, e);
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
api.persist = {
|
|
693
|
+
setOptions: (newOptions) => {
|
|
694
|
+
options = {
|
|
695
|
+
...options,
|
|
696
|
+
...newOptions
|
|
697
|
+
};
|
|
698
|
+
if (newOptions.storage) storage = newOptions.storage;
|
|
699
|
+
},
|
|
700
|
+
clearStorage: () => {
|
|
701
|
+
++hydrationVersion;
|
|
702
|
+
storage?.removeItem(options.name);
|
|
703
|
+
},
|
|
704
|
+
getOptions: () => options,
|
|
705
|
+
rehydrate: () => hydrate(),
|
|
706
|
+
hasHydrated: () => hasHydrated,
|
|
707
|
+
onHydrate: (cb) => {
|
|
708
|
+
hydrationListeners.add(cb);
|
|
709
|
+
return () => {
|
|
710
|
+
hydrationListeners.delete(cb);
|
|
711
|
+
};
|
|
712
|
+
},
|
|
713
|
+
onFinishHydration: (cb) => {
|
|
714
|
+
finishHydrationListeners.add(cb);
|
|
715
|
+
return () => {
|
|
716
|
+
finishHydrationListeners.delete(cb);
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
if (!options.skipHydration) hydrate();
|
|
721
|
+
return stateFromStorage || configResult;
|
|
722
|
+
};
|
|
723
|
+
var persist = persistImpl;
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region ui-src/lib/theme.ts
|
|
726
|
+
/** Applies a palette atomically, including portals and pseudo-elements, without persisting it. */
|
|
727
|
+
function applyDocumentTheme(mode, brand) {
|
|
728
|
+
const root = document.documentElement;
|
|
729
|
+
if (!(root.dataset.uiTheme !== mode || brand !== void 0 && (root.style.getPropertyValue("--brand-h") !== String(brand.hue) || root.style.getPropertyValue("--brand-c") !== String(brand.chroma)))) return;
|
|
730
|
+
root.dataset.themeChanging = "";
|
|
731
|
+
try {
|
|
732
|
+
root.dataset.uiTheme = mode;
|
|
733
|
+
root.classList.toggle("dark", mode === "dark");
|
|
734
|
+
if (brand) {
|
|
735
|
+
root.style.setProperty("--brand-h", String(brand.hue));
|
|
736
|
+
root.style.setProperty("--brand-c", String(brand.chroma));
|
|
737
|
+
}
|
|
738
|
+
root.offsetHeight;
|
|
739
|
+
} finally {
|
|
740
|
+
delete root.dataset.themeChanging;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region ui-src/store/theme.ts
|
|
745
|
+
/** Browser-local solid color scheme and brand preferences. */
|
|
746
|
+
/** 瑶光 is Alkaid, the star at the end of the Plough's handle, and a B-type
|
|
747
|
+
* star is blue-white — which is where the default hue comes from. */
|
|
748
|
+
var ALKAID = {
|
|
749
|
+
id: "alkaid",
|
|
750
|
+
labelKey: "brand.alkaid",
|
|
751
|
+
hue: 255,
|
|
752
|
+
chroma: .15
|
|
753
|
+
};
|
|
754
|
+
/** Ordered brand presets; Alkaid supplies the default presentation. */
|
|
755
|
+
var BRANDS = [
|
|
756
|
+
ALKAID,
|
|
757
|
+
{
|
|
758
|
+
id: "violet",
|
|
759
|
+
labelKey: "brand.violet",
|
|
760
|
+
hue: 295,
|
|
761
|
+
chroma: .15
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
id: "celadon",
|
|
765
|
+
labelKey: "brand.celadon",
|
|
766
|
+
hue: 185,
|
|
767
|
+
chroma: .095
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
id: "moss",
|
|
771
|
+
labelKey: "brand.moss",
|
|
772
|
+
hue: 150,
|
|
773
|
+
chroma: .12
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
id: "honey",
|
|
777
|
+
labelKey: "brand.honey",
|
|
778
|
+
hue: 70,
|
|
779
|
+
chroma: .12
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
id: "lotus",
|
|
783
|
+
labelKey: "brand.lotus",
|
|
784
|
+
hue: 355,
|
|
785
|
+
chroma: .15
|
|
786
|
+
}
|
|
787
|
+
];
|
|
788
|
+
/** Resolves persisted color values to a preset, selecting Alkaid for unmatched values. */
|
|
789
|
+
function resolveBrand(stored) {
|
|
790
|
+
return BRANDS.find((one) => one.hue === stored.hue && one.chroma === stored.chroma) ?? ALKAID;
|
|
791
|
+
}
|
|
792
|
+
var CONTENT_WIDTHS = [
|
|
793
|
+
"default",
|
|
794
|
+
"wide",
|
|
795
|
+
"full"
|
|
796
|
+
];
|
|
797
|
+
var useTheme = create()(persist((set) => ({
|
|
798
|
+
mode: "system",
|
|
799
|
+
setMode: (mode) => set({ mode }),
|
|
800
|
+
hue: ALKAID.hue,
|
|
801
|
+
chroma: ALKAID.chroma,
|
|
802
|
+
setBrand: ({ hue, chroma }) => set({
|
|
803
|
+
hue,
|
|
804
|
+
chroma
|
|
805
|
+
}),
|
|
806
|
+
contentWidth: "default",
|
|
807
|
+
setContentWidth: (contentWidth) => set({ contentWidth })
|
|
808
|
+
}), {
|
|
809
|
+
name: "yaoguang.theme",
|
|
810
|
+
partialize: ({ hue, chroma, mode, contentWidth }) => ({
|
|
811
|
+
hue,
|
|
812
|
+
chroma,
|
|
813
|
+
mode,
|
|
814
|
+
contentWidth
|
|
815
|
+
}),
|
|
816
|
+
merge: (persisted, current) => {
|
|
817
|
+
const stored = persisted;
|
|
818
|
+
const brand = resolveBrand({
|
|
819
|
+
hue: stored?.hue ?? current.hue,
|
|
820
|
+
chroma: stored?.chroma ?? current.chroma
|
|
821
|
+
});
|
|
822
|
+
return {
|
|
823
|
+
...current,
|
|
824
|
+
hue: brand.hue,
|
|
825
|
+
chroma: brand.chroma,
|
|
826
|
+
mode: stored?.mode === "dark" || stored?.mode === "light" ? stored.mode : "system",
|
|
827
|
+
contentWidth: CONTENT_WIDTHS.find((width) => width === stored?.contentWidth) ?? "default"
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
}));
|
|
831
|
+
/** Applies the scheme, brand and content width to the document, including portalled components. */
|
|
832
|
+
function applyTheme(state) {
|
|
833
|
+
document.documentElement.dataset.contentWidth = state.contentWidth ?? "default";
|
|
834
|
+
applyDocumentTheme(state.mode === "system" ? window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light" : state.mode, state);
|
|
835
|
+
}
|
|
836
|
+
var themeActivation;
|
|
837
|
+
/**
|
|
838
|
+
* Applies the stored brand once and keeps it applied. Called before the first
|
|
839
|
+
* feature renders. Withdrawal removes its listeners and restores the host defaults
|
|
840
|
+
* while retaining stored preferences for the next activation.
|
|
841
|
+
*/
|
|
842
|
+
function initTheme() {
|
|
843
|
+
const activation = Symbol();
|
|
844
|
+
themeActivation = activation;
|
|
845
|
+
applyTheme(useTheme.getState());
|
|
846
|
+
const unsubscribe = useTheme.subscribe((state) => {
|
|
847
|
+
if (themeActivation === activation) applyTheme(state);
|
|
848
|
+
});
|
|
849
|
+
const preference = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
850
|
+
const onChange = () => {
|
|
851
|
+
const state = useTheme.getState();
|
|
852
|
+
if (themeActivation === activation && state.mode === "system") applyTheme(state);
|
|
853
|
+
};
|
|
854
|
+
preference?.addEventListener("change", onChange);
|
|
855
|
+
return () => {
|
|
856
|
+
unsubscribe();
|
|
857
|
+
preference?.removeEventListener("change", onChange);
|
|
858
|
+
if (themeActivation !== activation) return;
|
|
859
|
+
themeActivation = void 0;
|
|
860
|
+
document.documentElement.dataset.contentWidth = "default";
|
|
861
|
+
document.documentElement.style.removeProperty("--brand-h");
|
|
862
|
+
document.documentElement.style.removeProperty("--brand-c");
|
|
863
|
+
applyDocumentTheme("light");
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
//#endregion
|
|
867
|
+
//#region ui-src/components/settings/reading-typography.tsx
|
|
868
|
+
var families = [
|
|
869
|
+
{
|
|
870
|
+
id: "wenkai",
|
|
871
|
+
family: "LXGW WenKai Screen",
|
|
872
|
+
chinese: "霞鹜文楷屏幕阅读版",
|
|
873
|
+
scope: "both"
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
id: "source-han-serif",
|
|
877
|
+
family: "Source Han Serif CN",
|
|
878
|
+
chinese: "思源宋体",
|
|
879
|
+
scope: "chinese"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
id: "source-han-sans",
|
|
883
|
+
family: "Source Han Sans CN",
|
|
884
|
+
chinese: "思源黑体",
|
|
885
|
+
scope: "chinese"
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
id: "source-serif",
|
|
889
|
+
family: "Source Serif 4",
|
|
890
|
+
chinese: "Source Serif 4",
|
|
891
|
+
scope: "western"
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
id: "source-sans",
|
|
895
|
+
family: "Source Sans 3",
|
|
896
|
+
chinese: "Source Sans 3",
|
|
897
|
+
scope: "western"
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
id: "atkinson",
|
|
901
|
+
family: "Atkinson Hyperlegible Next",
|
|
902
|
+
chinese: "Atkinson Hyperlegible Next",
|
|
903
|
+
scope: "western"
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
id: "literata",
|
|
907
|
+
family: "Literata",
|
|
908
|
+
chinese: "Literata",
|
|
909
|
+
scope: "western"
|
|
910
|
+
}
|
|
911
|
+
];
|
|
912
|
+
function display(choice) {
|
|
913
|
+
if (choice.kind === "system") return "system-ui";
|
|
914
|
+
if (choice.kind === "custom") return choice.value;
|
|
915
|
+
return families.find((font) => font.id === choice.value)?.family ?? "";
|
|
916
|
+
}
|
|
917
|
+
function FontPreference({ script, choice, revision }) {
|
|
918
|
+
const { i18n } = useTranslation$1();
|
|
919
|
+
const chinese = i18n.language.startsWith("zh");
|
|
920
|
+
const context = readingFontDiscoveryContext();
|
|
921
|
+
const device = useDeviceFonts(context.signal, context.native);
|
|
922
|
+
const [draft, setDraft] = useState();
|
|
923
|
+
const invalid = draft?.revision === revision;
|
|
924
|
+
const label = script === "chinese" ? chinese ? "中文字体" : "Chinese font" : chinese ? "西文字体" : "Western font";
|
|
925
|
+
const options = families.filter((font) => font.scope === "both" || font.scope === script);
|
|
926
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
927
|
+
label,
|
|
928
|
+
inline: true,
|
|
929
|
+
className: "settings-field-row flex flex-row flex-wrap items-center justify-between [&>div:nth-child(2)]:ml-auto",
|
|
930
|
+
error: invalid ? chinese ? "请输入有效的字体名称或完整字体列表。" : "Enter a valid font name or complete font-family list." : void 0,
|
|
931
|
+
children: (binding) => /* @__PURE__ */ jsx("div", {
|
|
932
|
+
className: "flex min-w-0 justify-end",
|
|
933
|
+
children: /* @__PURE__ */ jsx(FontPicker, {
|
|
934
|
+
...binding,
|
|
935
|
+
className: "w-72 max-w-full",
|
|
936
|
+
label,
|
|
937
|
+
onLoadFonts: device.available ? device.load : void 0,
|
|
938
|
+
loading: device.loading,
|
|
939
|
+
loadError: device.failed ? chinese ? "未能读取本机字体" : "Could not read device fonts" : void 0,
|
|
940
|
+
loadUnavailable: !device.available ? chinese ? "当前环境不支持读取字体" : "Device fonts unavailable" : void 0,
|
|
941
|
+
value: invalid ? draft.value : display(choice),
|
|
942
|
+
"aria-invalid": invalid,
|
|
943
|
+
onValueChange: (value) => {
|
|
944
|
+
const builtin = options.find((font) => font.family === value);
|
|
945
|
+
const next = value === "system-ui" ? { kind: "system" } : builtin ? {
|
|
946
|
+
kind: "builtin",
|
|
947
|
+
value: builtin.id
|
|
948
|
+
} : {
|
|
949
|
+
kind: "custom",
|
|
950
|
+
value
|
|
951
|
+
};
|
|
952
|
+
const accepted = readingTypography.update({ [script]: next });
|
|
953
|
+
setDraft(accepted ? void 0 : {
|
|
954
|
+
value,
|
|
955
|
+
revision
|
|
956
|
+
});
|
|
957
|
+
},
|
|
958
|
+
options: [
|
|
959
|
+
...device.options,
|
|
960
|
+
{
|
|
961
|
+
value: "system-ui",
|
|
962
|
+
label: chinese ? "系统默认" : "System default"
|
|
963
|
+
},
|
|
964
|
+
...options.map((font) => ({
|
|
965
|
+
value: font.family,
|
|
966
|
+
label: chinese ? font.chinese : font.family,
|
|
967
|
+
previewFamily: "var(--font-sans)",
|
|
968
|
+
note: chinese ? "内置字体,选择后加载;此处使用系统字体预览。" : "Bundled; loads when selected. Preview uses the system font."
|
|
969
|
+
}))
|
|
970
|
+
]
|
|
971
|
+
})
|
|
972
|
+
})
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
/** Local reading controls apply independently of theme, terminal and gateway settings. */
|
|
976
|
+
function ReadingTypographySettings() {
|
|
977
|
+
const { i18n } = useTranslation$1();
|
|
978
|
+
const chinese = i18n.language.startsWith("zh");
|
|
979
|
+
const fonts = useSyncExternalStore(subscribeReadingFontStatus, getReadingFontStatus);
|
|
980
|
+
const state = useSyncExternalStore(readingTypography.subscribe, readingTypography.getSnapshot);
|
|
981
|
+
const [sizeDraft, setSizeDraft] = useState();
|
|
982
|
+
const editingSize = sizeDraft?.revision === state;
|
|
983
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
984
|
+
className: "space-y-4",
|
|
985
|
+
"aria-label": chinese ? "阅读字体" : "Reading typography",
|
|
986
|
+
children: [
|
|
987
|
+
/* @__PURE__ */ jsx("h3", {
|
|
988
|
+
className: "text-sm font-medium",
|
|
989
|
+
children: chinese ? "阅读字体" : "Reading typography"
|
|
990
|
+
}),
|
|
991
|
+
/* @__PURE__ */ jsx(FontPreference, {
|
|
992
|
+
script: "chinese",
|
|
993
|
+
choice: state.preferences.chinese,
|
|
994
|
+
revision: state
|
|
995
|
+
}),
|
|
996
|
+
/* @__PURE__ */ jsx(FontPreference, {
|
|
997
|
+
script: "western",
|
|
998
|
+
choice: state.preferences.western,
|
|
999
|
+
revision: state
|
|
1000
|
+
}),
|
|
1001
|
+
/* @__PURE__ */ jsx(Field, {
|
|
1002
|
+
label: chinese ? "正文字号" : "Body size",
|
|
1003
|
+
inline: true,
|
|
1004
|
+
className: "settings-field-row flex flex-row flex-wrap items-center justify-between [&>div:nth-child(2)]:ml-auto",
|
|
1005
|
+
children: (binding) => /* @__PURE__ */ jsx("fieldset", {
|
|
1006
|
+
"aria-label": chinese ? "正文字号调整" : "Body size adjustment",
|
|
1007
|
+
className: "flex min-w-0 justify-end border-0 p-0",
|
|
1008
|
+
onBlur: (event) => {
|
|
1009
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setSizeDraft(void 0);
|
|
1010
|
+
},
|
|
1011
|
+
children: /* @__PURE__ */ jsx(InputNumber, {
|
|
1012
|
+
...binding,
|
|
1013
|
+
label: chinese ? "正文字号" : "Body size",
|
|
1014
|
+
incrementLabel: chinese ? "增大正文字号" : "Increase body size",
|
|
1015
|
+
decrementLabel: chinese ? "减小正文字号" : "Decrease body size",
|
|
1016
|
+
min: 14,
|
|
1017
|
+
max: 22,
|
|
1018
|
+
step: 1,
|
|
1019
|
+
allowOutOfRange: true,
|
|
1020
|
+
value: editingSize ? sizeDraft.value : state.preferences.bodySize,
|
|
1021
|
+
"aria-invalid": editingSize && sizeDraft.value !== null,
|
|
1022
|
+
className: "w-36 max-w-full",
|
|
1023
|
+
onValueChange: (value) => {
|
|
1024
|
+
const accepted = value !== null && readingTypography.update({ bodySize: value });
|
|
1025
|
+
setSizeDraft(accepted ? void 0 : {
|
|
1026
|
+
value,
|
|
1027
|
+
revision: state
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
})
|
|
1031
|
+
})
|
|
1032
|
+
}),
|
|
1033
|
+
fonts.loading && /* @__PURE__ */ jsx("p", {
|
|
1034
|
+
role: "status",
|
|
1035
|
+
className: "text-xs text-muted-foreground",
|
|
1036
|
+
children: chinese ? "正在加载阅读字体…" : "Loading reading fonts…"
|
|
1037
|
+
}),
|
|
1038
|
+
fonts.failed.length > 0 && /* @__PURE__ */ jsx("p", {
|
|
1039
|
+
role: "status",
|
|
1040
|
+
className: "text-xs text-muted-foreground",
|
|
1041
|
+
children: chinese ? "部分字体未能加载,当前使用系统回退字体。重新选择可重试。" : "Some fonts could not load. System fallback is active; select a font again to retry."
|
|
1042
|
+
}),
|
|
1043
|
+
state.saveFailed && /* @__PURE__ */ jsx("p", {
|
|
1044
|
+
role: "status",
|
|
1045
|
+
className: "text-xs text-destructive",
|
|
1046
|
+
children: chinese ? "设置已应用,但未能保存到此浏览器。" : "Applied, but could not save in this browser."
|
|
1047
|
+
})
|
|
1048
|
+
]
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region ui-src/components/settings/appearance.tsx
|
|
1053
|
+
/** Browser-local language, color scheme and brand preferences. */
|
|
1054
|
+
function PreferenceRow({ id, label, children }) {
|
|
1055
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1056
|
+
className: "flex min-w-0 flex-wrap items-center justify-between gap-x-5 gap-y-3",
|
|
1057
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
1058
|
+
id,
|
|
1059
|
+
className: "min-w-0 text-sm font-normal",
|
|
1060
|
+
children: label
|
|
1061
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1062
|
+
className: "ml-auto flex min-w-0 max-w-full items-center justify-end",
|
|
1063
|
+
children
|
|
1064
|
+
})]
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
/** Preferences apply immediately and persist in this browser without gateway writes. */
|
|
1068
|
+
function InterfacePreferences() {
|
|
1069
|
+
const { t, i18n } = useTranslation$1();
|
|
1070
|
+
const languageLabel = useId();
|
|
1071
|
+
const current = i18n.resolvedLanguage ?? i18n.language;
|
|
1072
|
+
const { mode, setMode, hue, setBrand } = useTheme();
|
|
1073
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1074
|
+
className: "flex min-w-0 flex-col gap-6",
|
|
1075
|
+
children: [
|
|
1076
|
+
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
1077
|
+
label: t("settings.colorMode"),
|
|
1078
|
+
children: /* @__PURE__ */ jsx(Segmented, {
|
|
1079
|
+
label: t("settings.colorMode"),
|
|
1080
|
+
value: mode,
|
|
1081
|
+
onSelect: setMode,
|
|
1082
|
+
options: [
|
|
1083
|
+
{
|
|
1084
|
+
value: "system",
|
|
1085
|
+
label: t("settings.systemMode")
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
value: "light",
|
|
1089
|
+
label: t("settings.lightMode")
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
value: "dark",
|
|
1093
|
+
label: t("settings.darkMode")
|
|
1094
|
+
}
|
|
1095
|
+
]
|
|
1096
|
+
})
|
|
1097
|
+
}),
|
|
1098
|
+
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
1099
|
+
label: t("settings.brand"),
|
|
1100
|
+
children: /* @__PURE__ */ jsx(ThemeColorPicker, {
|
|
1101
|
+
label: t("settings.brand"),
|
|
1102
|
+
value: BRANDS.find((brand) => brand.hue === hue)?.id ?? "alkaid",
|
|
1103
|
+
options: BRANDS.map((brand) => ({
|
|
1104
|
+
value: brand.id,
|
|
1105
|
+
label: t(brand.labelKey),
|
|
1106
|
+
color: themeSwatchColor(brand)
|
|
1107
|
+
})),
|
|
1108
|
+
onValueChange: (value) => {
|
|
1109
|
+
const brand = BRANDS.find((brand) => brand.id === value);
|
|
1110
|
+
if (brand) setBrand(brand);
|
|
1111
|
+
}
|
|
1112
|
+
})
|
|
1113
|
+
}),
|
|
1114
|
+
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
1115
|
+
id: languageLabel,
|
|
1116
|
+
label: t("settings.interfaceLanguage"),
|
|
1117
|
+
children: /* @__PURE__ */ jsx(Picker, {
|
|
1118
|
+
labelledBy: languageLabel,
|
|
1119
|
+
slot: "language-picker",
|
|
1120
|
+
value: current,
|
|
1121
|
+
options: LANGUAGES.map((language) => ({
|
|
1122
|
+
value: language,
|
|
1123
|
+
label: t(language === "en-US" ? "language.en-US" : "language.zh-CN"),
|
|
1124
|
+
prefix: LANGUAGE_FLAGS[language]
|
|
1125
|
+
})),
|
|
1126
|
+
onSelect: (language) => {
|
|
1127
|
+
i18n.changeLanguage(language);
|
|
1128
|
+
}
|
|
1129
|
+
})
|
|
1130
|
+
})
|
|
1131
|
+
]
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
/** Restores the reading category's typography and content width through their owner stores. */
|
|
1135
|
+
function resetReadingPreferences() {
|
|
1136
|
+
readingTypography.reset();
|
|
1137
|
+
useTheme.getState().setContentWidth("default");
|
|
1138
|
+
}
|
|
1139
|
+
/** Reading preferences apply immediately through the existing typography and theme stores. */
|
|
1140
|
+
function ReadingPreferences() {
|
|
1141
|
+
const { t } = useTranslation$1();
|
|
1142
|
+
const { contentWidth, setContentWidth } = useTheme();
|
|
1143
|
+
const { preferences } = useSyncExternalStore(readingTypography.subscribe, readingTypography.getSnapshot);
|
|
1144
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1145
|
+
className: "@container flex min-w-0 flex-1 flex-col gap-6",
|
|
1146
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1147
|
+
className: "flex min-w-0 flex-col gap-4",
|
|
1148
|
+
children: [/* @__PURE__ */ jsx(ReadingTypographySettings, {}), /* @__PURE__ */ jsx(Field, {
|
|
1149
|
+
label: t("settings.contentWidth"),
|
|
1150
|
+
inline: true,
|
|
1151
|
+
className: "settings-field-row flex flex-row flex-wrap items-center justify-between [&>div:nth-child(2)]:ml-auto",
|
|
1152
|
+
children: () => /* @__PURE__ */ jsx("div", {
|
|
1153
|
+
className: "flex min-w-0 justify-end",
|
|
1154
|
+
children: /* @__PURE__ */ jsx(Segmented, {
|
|
1155
|
+
className: "flex",
|
|
1156
|
+
label: t("settings.contentWidth"),
|
|
1157
|
+
value: contentWidth,
|
|
1158
|
+
onSelect: setContentWidth,
|
|
1159
|
+
options: [
|
|
1160
|
+
{
|
|
1161
|
+
value: "default",
|
|
1162
|
+
label: t("settings.contentWidthDefault")
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
value: "wide",
|
|
1166
|
+
label: t("settings.contentWidthWide")
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
value: "full",
|
|
1170
|
+
label: t("settings.contentWidthFull")
|
|
1171
|
+
}
|
|
1172
|
+
]
|
|
1173
|
+
})
|
|
1174
|
+
})
|
|
1175
|
+
})]
|
|
1176
|
+
}), /* @__PURE__ */ jsx(SettingsPreview, {
|
|
1177
|
+
title: t("settings.preview"),
|
|
1178
|
+
infoLabel: t("settings.previewInfo"),
|
|
1179
|
+
description: t("settings.previewDescription"),
|
|
1180
|
+
kind: t("settings.previewReading"),
|
|
1181
|
+
canvasClassName: "bg-muted/30 leading-[1.8]",
|
|
1182
|
+
canvasStyle: { fontSize: preferences.bodySize },
|
|
1183
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1184
|
+
"data-reading-body": true,
|
|
1185
|
+
className: "space-y-2",
|
|
1186
|
+
children: [
|
|
1187
|
+
/* @__PURE__ */ jsx("p", {
|
|
1188
|
+
"data-reading-script": "chinese",
|
|
1189
|
+
className: "font-semibold",
|
|
1190
|
+
style: { fontFamily: readingFontFamily(preferences.chinese) },
|
|
1191
|
+
children: "让文字读起来更舒服"
|
|
1192
|
+
}),
|
|
1193
|
+
/* @__PURE__ */ jsx("p", {
|
|
1194
|
+
"data-reading-script": "chinese",
|
|
1195
|
+
style: { fontFamily: readingFontFamily(preferences.chinese) },
|
|
1196
|
+
children: "天地玄黄,宇宙洪荒。选一种合适的字体,让每一次阅读都自然、清晰。"
|
|
1197
|
+
}),
|
|
1198
|
+
/* @__PURE__ */ jsx("p", {
|
|
1199
|
+
"data-reading-script": "western",
|
|
1200
|
+
style: { fontFamily: readingFontFamily(preferences.western) },
|
|
1201
|
+
children: "The quick brown fox jumps over the lazy dog."
|
|
1202
|
+
}),
|
|
1203
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
1204
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1205
|
+
"data-reading-script": "western",
|
|
1206
|
+
style: { fontFamily: readingFontFamily(preferences.western) },
|
|
1207
|
+
children: ["0123456789 · Aa Bb Cc ·", " "]
|
|
1208
|
+
}),
|
|
1209
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1210
|
+
"data-reading-script": "chinese",
|
|
1211
|
+
style: { fontFamily: readingFontFamily(preferences.chinese) },
|
|
1212
|
+
children: ["中文与", " "]
|
|
1213
|
+
}),
|
|
1214
|
+
/* @__PURE__ */ jsx("span", {
|
|
1215
|
+
"data-reading-script": "western",
|
|
1216
|
+
style: { fontFamily: readingFontFamily(preferences.western) },
|
|
1217
|
+
children: "English"
|
|
1218
|
+
})
|
|
1219
|
+
] })
|
|
1220
|
+
]
|
|
1221
|
+
})
|
|
1222
|
+
})]
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region ui-src/components/personalization-dialog.tsx
|
|
1227
|
+
/** Owner-contributed preferences share the system settings geometry and content boundaries. */
|
|
1228
|
+
function PersonalizationDialog({ open, onOpenChange: setOpen }) {
|
|
1229
|
+
const { t } = useTranslation$1();
|
|
1230
|
+
const contributions = usePlugins((state) => state.contributions);
|
|
1231
|
+
const crashed = usePlugins((state) => state.crashed);
|
|
1232
|
+
const categories = useMemo(() => contributionsIn({
|
|
1233
|
+
contributions,
|
|
1234
|
+
crashed
|
|
1235
|
+
}, "shell.personalization.category"), [contributions, crashed]);
|
|
1236
|
+
const roots = categories.filter((entry) => !entry.contribution.parent);
|
|
1237
|
+
const [selected, setSelected] = useState();
|
|
1238
|
+
const current = roots.find((entry) => entry.key === selected) ?? roots[0];
|
|
1239
|
+
useEffect(() => {
|
|
1240
|
+
const next = open ? current?.key : void 0;
|
|
1241
|
+
if (selected !== next) setSelected(next);
|
|
1242
|
+
}, [
|
|
1243
|
+
open,
|
|
1244
|
+
current?.key,
|
|
1245
|
+
selected
|
|
1246
|
+
]);
|
|
1247
|
+
const children = categories.filter((entry) => entry.contribution.parent === current?.key);
|
|
1248
|
+
const resettable = current ? [current, ...children].filter((entry) => entry.contribution.onReset) : [];
|
|
1249
|
+
const title = current ? resolveLabel(current.contribution.label, current.contribution.id) : t("settings.personalization");
|
|
1250
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
1251
|
+
open,
|
|
1252
|
+
onOpenChange: setOpen,
|
|
1253
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
1254
|
+
closeLabel: t("settings.close"),
|
|
1255
|
+
className: "settings-dialog personalization-dialog h-dialog max-w-5xl grid-cols-[12.5rem_minmax(0,1fr)] gap-0 overflow-hidden sm:max-w-5xl",
|
|
1256
|
+
children: [/* @__PURE__ */ jsxs("nav", {
|
|
1257
|
+
"aria-label": t("settings.personalizationCategories"),
|
|
1258
|
+
"data-slot": "settings-contents",
|
|
1259
|
+
className: "settings-navigation surface-column flex min-h-0 flex-col overflow-hidden bg-muted/30 px-3 pb-4",
|
|
1260
|
+
children: [
|
|
1261
|
+
/* @__PURE__ */ jsx(DialogHeader, {
|
|
1262
|
+
className: "flex h-16 shrink-0 justify-center px-3 pr-0",
|
|
1263
|
+
children: /* @__PURE__ */ jsx(DialogTitle, { children: t("settings.personalization") })
|
|
1264
|
+
}),
|
|
1265
|
+
/* @__PURE__ */ jsx("div", {
|
|
1266
|
+
className: "settings-category-list flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto",
|
|
1267
|
+
children: roots.map((entry) => {
|
|
1268
|
+
const Icon = PLUGIN_ICONS[entry.contribution.icon ?? "puzzle"];
|
|
1269
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
1270
|
+
variant: "plain",
|
|
1271
|
+
"data-plugin": entry.owner,
|
|
1272
|
+
"aria-current": entry.key === current?.key,
|
|
1273
|
+
onClick: () => setSelected(entry.key),
|
|
1274
|
+
className: cn("flex min-h-9 shrink-0 items-center gap-2.5 rounded-control px-3 py-2 text-left text-sm outline-none transition-colors duration-150", entry.key === current?.key ? "bg-accent font-medium text-accent-foreground" : "text-muted-foreground hover:bg-muted hover:text-foreground"),
|
|
1275
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
1276
|
+
"aria-hidden": "true",
|
|
1277
|
+
className: "size-4 shrink-0",
|
|
1278
|
+
strokeWidth: 1.75
|
|
1279
|
+
}), resolveLabel(entry.contribution.label, entry.contribution.id)]
|
|
1280
|
+
}, entry.key);
|
|
1281
|
+
})
|
|
1282
|
+
}),
|
|
1283
|
+
current && /* @__PURE__ */ jsx("div", {
|
|
1284
|
+
className: "settings-category-select hidden pb-3",
|
|
1285
|
+
children: /* @__PURE__ */ jsx(Select, {
|
|
1286
|
+
"aria-label": t("settings.personalizationCategories"),
|
|
1287
|
+
value: current.key,
|
|
1288
|
+
onValueChange: setSelected,
|
|
1289
|
+
children: roots.map((entry) => /* @__PURE__ */ jsx("option", {
|
|
1290
|
+
value: entry.key,
|
|
1291
|
+
children: resolveLabel(entry.contribution.label, entry.contribution.id)
|
|
1292
|
+
}, entry.key))
|
|
1293
|
+
})
|
|
1294
|
+
})
|
|
1295
|
+
]
|
|
1296
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1297
|
+
className: "flex min-h-0 min-w-0 flex-col overflow-hidden bg-card",
|
|
1298
|
+
children: [
|
|
1299
|
+
/* @__PURE__ */ jsx(DialogDescription, {
|
|
1300
|
+
className: "sr-only",
|
|
1301
|
+
children: title
|
|
1302
|
+
}),
|
|
1303
|
+
/* @__PURE__ */ jsxs("header", {
|
|
1304
|
+
"data-slot": "settings-page-header",
|
|
1305
|
+
className: "flex h-16 shrink-0 items-center justify-between gap-3 px-6 pr-14",
|
|
1306
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
1307
|
+
className: "min-w-0 text-lg font-semibold",
|
|
1308
|
+
children: title
|
|
1309
|
+
}), resettable.length > 0 && /* @__PURE__ */ jsx(Button, {
|
|
1310
|
+
variant: "text",
|
|
1311
|
+
className: "shrink-0",
|
|
1312
|
+
onClick: () => {
|
|
1313
|
+
for (const entry of resettable) entry.contribution.onReset?.();
|
|
1314
|
+
},
|
|
1315
|
+
children: t("settings.resetCategory")
|
|
1316
|
+
})]
|
|
1317
|
+
}),
|
|
1318
|
+
/* @__PURE__ */ jsx("div", {
|
|
1319
|
+
"data-slot": "settings-scroll",
|
|
1320
|
+
className: "flex min-h-0 min-w-0 flex-1 flex-col gap-8 overflow-y-auto px-6 pt-1 pb-6",
|
|
1321
|
+
children: current ? /* @__PURE__ */ jsxs("div", {
|
|
1322
|
+
className: "flex min-w-0 flex-1 flex-col gap-8",
|
|
1323
|
+
children: [/* @__PURE__ */ jsx(SlotOutlet, {
|
|
1324
|
+
slot: "shell.personalization.category",
|
|
1325
|
+
only: current.key,
|
|
1326
|
+
props: {}
|
|
1327
|
+
}), children.map((entry) => {
|
|
1328
|
+
const label = resolveLabel(entry.contribution.label, entry.contribution.id);
|
|
1329
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
1330
|
+
"aria-label": label,
|
|
1331
|
+
className: "space-y-4 border-t border-border pt-6",
|
|
1332
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
1333
|
+
className: "text-sm font-medium",
|
|
1334
|
+
children: label
|
|
1335
|
+
}), /* @__PURE__ */ jsx(SlotOutlet, {
|
|
1336
|
+
slot: "shell.personalization.category",
|
|
1337
|
+
only: entry.key,
|
|
1338
|
+
props: {}
|
|
1339
|
+
})]
|
|
1340
|
+
}, entry.key);
|
|
1341
|
+
})]
|
|
1342
|
+
}, current.key) : /* @__PURE__ */ jsx("p", {
|
|
1343
|
+
className: "text-sm text-muted-foreground",
|
|
1344
|
+
children: t("settings.personalizationEmpty")
|
|
1345
|
+
})
|
|
1346
|
+
})
|
|
1347
|
+
]
|
|
1348
|
+
})]
|
|
1349
|
+
})
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
//#endregion
|
|
1353
|
+
//#region ui-src/lib/language.ts
|
|
1354
|
+
/** Browser-local language preference and document metadata owned by the platform activation. */
|
|
1355
|
+
/** Browser preference key shared with the platform language editor. */
|
|
1356
|
+
var STORAGE_KEY = "yaoguang.lang";
|
|
1357
|
+
var languageActivation;
|
|
1358
|
+
/** Restores the same saved/navigator language choice and retains changes locally. */
|
|
1359
|
+
function initLanguage() {
|
|
1360
|
+
const activation = Symbol();
|
|
1361
|
+
languageActivation = activation;
|
|
1362
|
+
let saved;
|
|
1363
|
+
try {
|
|
1364
|
+
saved = localStorage.getItem("yaoguang.lang") ?? void 0;
|
|
1365
|
+
} catch {}
|
|
1366
|
+
const selected = (saved ? [saved] : [...navigator.languages]).map((value) => LANGUAGES.find((language) => language.toLowerCase() === value.toLowerCase()) ?? LANGUAGES.find((language) => language.split("-")[0] === value.split("-")[0])).find(Boolean);
|
|
1367
|
+
if (selected) i18next.changeLanguage(selected);
|
|
1368
|
+
const changed = () => {
|
|
1369
|
+
if (languageActivation !== activation) return;
|
|
1370
|
+
const language = i18next.resolvedLanguage ?? "zh-CN";
|
|
1371
|
+
document.documentElement.lang = language;
|
|
1372
|
+
try {
|
|
1373
|
+
localStorage.setItem(STORAGE_KEY, language);
|
|
1374
|
+
} catch {}
|
|
1375
|
+
};
|
|
1376
|
+
changed();
|
|
1377
|
+
i18next.on("languageChanged", changed);
|
|
1378
|
+
return () => {
|
|
1379
|
+
i18next.off("languageChanged", changed);
|
|
1380
|
+
if (languageActivation !== activation) return;
|
|
1381
|
+
languageActivation = void 0;
|
|
1382
|
+
document.documentElement.lang = FALLBACK_LANGUAGE;
|
|
1383
|
+
i18next.changeLanguage(FALLBACK_LANGUAGE);
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
//#endregion
|
|
1387
|
+
//#region ui-src/index.tsx
|
|
1388
|
+
/** Browser module version understood by the host. */
|
|
1389
|
+
var runtimeVersion = 5;
|
|
1390
|
+
/** Personalization contributes presentation without exposing capability-specific state. */
|
|
1391
|
+
var provides = [];
|
|
1392
|
+
/** Applies preferences and owns their settings, listeners and document presentation. */
|
|
1393
|
+
function register(ctx) {
|
|
1394
|
+
registerTranslations(ctx);
|
|
1395
|
+
const stops = [
|
|
1396
|
+
initLanguage(),
|
|
1397
|
+
initTheme(),
|
|
1398
|
+
initReadingTypography(ctx)
|
|
1399
|
+
];
|
|
1400
|
+
ctx.slots.register("shell.personalization.category", {
|
|
1401
|
+
id: "interface",
|
|
1402
|
+
label: () => ctx.i18n.t("settings.interfaceCategory"),
|
|
1403
|
+
icon: "palette",
|
|
1404
|
+
order: 0,
|
|
1405
|
+
component: InterfacePreferences
|
|
1406
|
+
});
|
|
1407
|
+
ctx.slots.register("shell.personalization.category", {
|
|
1408
|
+
id: "reading",
|
|
1409
|
+
onReset: resetReadingPreferences,
|
|
1410
|
+
label: () => ctx.i18n.t("settings.readingCategory"),
|
|
1411
|
+
icon: "notebook",
|
|
1412
|
+
order: 10,
|
|
1413
|
+
component: ReadingPreferences
|
|
1414
|
+
});
|
|
1415
|
+
ctx.slots.register("shell.dialog.surface", {
|
|
1416
|
+
id: "personalization",
|
|
1417
|
+
component: PersonalizationDialog
|
|
1418
|
+
});
|
|
1419
|
+
ctx.slots.register("shell.nav.action", {
|
|
1420
|
+
id: "personalization-action",
|
|
1421
|
+
icon: "palette",
|
|
1422
|
+
label: () => ctx.i18n.t("settings.personalization"),
|
|
1423
|
+
order: 20,
|
|
1424
|
+
onSelect: () => ctx.navigation.openDialog("personalization")
|
|
1425
|
+
});
|
|
1426
|
+
ctx.signal.addEventListener("abort", () => {
|
|
1427
|
+
for (const stop of stops.toReversed()) stop();
|
|
1428
|
+
}, { once: true });
|
|
1429
|
+
}
|
|
1430
|
+
//#endregion
|
|
1431
|
+
export { provides, register, runtimeVersion };
|