@eum-agent/personalization 1.0.0 → 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 +139 -0
- package/package.json +2 -2
- 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 +855 -37
package/ui/ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Dialog, DialogContent, DialogHeader, DialogTitle, FALLBACK_LANGUAGE, LANGUAGES, LANGUAGE_FLAGS, Picker, Segmented, SlotOutlet, ThemeColorPicker, i18next, localeLeaves, themeSwatchColor, useTranslation } from "@eum-agent/host/framework";
|
|
2
|
-
import React, { useId } from "react";
|
|
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
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
//#region ui-src/i18n.ts
|
|
5
5
|
/** Platform browser strings share the host's language and React translation runtime. */
|
|
@@ -30,7 +30,16 @@ var en_US_default = {
|
|
|
30
30
|
"contentWidthDefault": "Default",
|
|
31
31
|
"contentWidthWide": "Wide",
|
|
32
32
|
"contentWidthFull": "Full",
|
|
33
|
-
"interfaceLanguage": "Interface language"
|
|
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"
|
|
34
43
|
},
|
|
35
44
|
brand: {
|
|
36
45
|
"violet": "Violet",
|
|
@@ -58,7 +67,16 @@ var zh_CN_default = {
|
|
|
58
67
|
"contentWidthDefault": "默认",
|
|
59
68
|
"contentWidthWide": "宽屏",
|
|
60
69
|
"contentWidthFull": "全宽",
|
|
61
|
-
"interfaceLanguage": "界面语言"
|
|
70
|
+
"interfaceLanguage": "界面语言",
|
|
71
|
+
"interfaceCategory": "界面",
|
|
72
|
+
"readingCategory": "阅读",
|
|
73
|
+
"personalizationCategories": "个性化分类",
|
|
74
|
+
"personalizationEmpty": "暂无可用的个性化设置",
|
|
75
|
+
"preview": "预览",
|
|
76
|
+
"previewInfo": "预览说明",
|
|
77
|
+
"previewReading": "阅读文本",
|
|
78
|
+
"previewDescription": "固定示例会随字体与字号即时更新,字体缺失时使用系统回退。阅读示例仅预览字体与字号;内容宽度作用于实际阅读区域。不会发送消息或执行命令。",
|
|
79
|
+
"resetCategory": "恢复默认"
|
|
62
80
|
},
|
|
63
81
|
brand: {
|
|
64
82
|
"violet": "鸢紫",
|
|
@@ -84,6 +102,425 @@ function registerTranslations(ctx) {
|
|
|
84
102
|
}, "zh-CN");
|
|
85
103
|
}
|
|
86
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
|
|
87
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
|
|
88
525
|
var createStoreImpl = (createState) => {
|
|
89
526
|
let state;
|
|
@@ -427,6 +864,191 @@ function initTheme() {
|
|
|
427
864
|
};
|
|
428
865
|
}
|
|
429
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
|
|
430
1052
|
//#region ui-src/components/settings/appearance.tsx
|
|
431
1053
|
/** Browser-local language, color scheme and brand preferences. */
|
|
432
1054
|
function PreferenceRow({ id, label, children }) {
|
|
@@ -437,17 +1059,17 @@ function PreferenceRow({ id, label, children }) {
|
|
|
437
1059
|
className: "min-w-0 text-sm font-normal",
|
|
438
1060
|
children: label
|
|
439
1061
|
}), /* @__PURE__ */ jsx("div", {
|
|
440
|
-
className: "flex min-w-0 max-w-full items-center justify-end",
|
|
1062
|
+
className: "ml-auto flex min-w-0 max-w-full items-center justify-end",
|
|
441
1063
|
children
|
|
442
1064
|
})]
|
|
443
1065
|
});
|
|
444
1066
|
}
|
|
445
1067
|
/** Preferences apply immediately and persist in this browser without gateway writes. */
|
|
446
|
-
function
|
|
1068
|
+
function InterfacePreferences() {
|
|
447
1069
|
const { t, i18n } = useTranslation$1();
|
|
448
1070
|
const languageLabel = useId();
|
|
449
1071
|
const current = i18n.resolvedLanguage ?? i18n.language;
|
|
450
|
-
const { mode, setMode, hue, setBrand
|
|
1072
|
+
const { mode, setMode, hue, setBrand } = useTheme();
|
|
451
1073
|
return /* @__PURE__ */ jsxs("div", {
|
|
452
1074
|
className: "flex min-w-0 flex-col gap-6",
|
|
453
1075
|
children: [
|
|
@@ -489,32 +1111,6 @@ function AppearancePanel() {
|
|
|
489
1111
|
}
|
|
490
1112
|
})
|
|
491
1113
|
}),
|
|
492
|
-
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
493
|
-
label: t("settings.contentWidth"),
|
|
494
|
-
children: /* @__PURE__ */ jsx(Segmented, {
|
|
495
|
-
label: t("settings.contentWidth"),
|
|
496
|
-
value: contentWidth,
|
|
497
|
-
onSelect: setContentWidth,
|
|
498
|
-
options: [
|
|
499
|
-
{
|
|
500
|
-
value: "default",
|
|
501
|
-
label: t("settings.contentWidthDefault")
|
|
502
|
-
},
|
|
503
|
-
{
|
|
504
|
-
value: "wide",
|
|
505
|
-
label: t("settings.contentWidthWide")
|
|
506
|
-
},
|
|
507
|
-
{
|
|
508
|
-
value: "full",
|
|
509
|
-
label: t("settings.contentWidthFull")
|
|
510
|
-
}
|
|
511
|
-
]
|
|
512
|
-
})
|
|
513
|
-
}),
|
|
514
|
-
/* @__PURE__ */ jsx(SlotOutlet, {
|
|
515
|
-
slot: "shell.personalization.section",
|
|
516
|
-
props: {}
|
|
517
|
-
}),
|
|
518
1114
|
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
519
1115
|
id: languageLabel,
|
|
520
1116
|
label: t("settings.interfaceLanguage"),
|
|
@@ -535,18 +1131,221 @@ function AppearancePanel() {
|
|
|
535
1131
|
]
|
|
536
1132
|
});
|
|
537
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
|
+
}
|
|
538
1225
|
//#endregion
|
|
539
1226
|
//#region ui-src/components/personalization-dialog.tsx
|
|
540
|
-
/**
|
|
1227
|
+
/** Owner-contributed preferences share the system settings geometry and content boundaries. */
|
|
541
1228
|
function PersonalizationDialog({ open, onOpenChange: setOpen }) {
|
|
542
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");
|
|
543
1250
|
return /* @__PURE__ */ jsx(Dialog, {
|
|
544
1251
|
open,
|
|
545
1252
|
onOpenChange: setOpen,
|
|
546
1253
|
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
547
1254
|
closeLabel: t("settings.close"),
|
|
548
|
-
className: "personalization-dialog max-
|
|
549
|
-
children: [/* @__PURE__ */
|
|
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
|
+
})]
|
|
550
1349
|
})
|
|
551
1350
|
});
|
|
552
1351
|
}
|
|
@@ -593,7 +1392,26 @@ var provides = [];
|
|
|
593
1392
|
/** Applies preferences and owns their settings, listeners and document presentation. */
|
|
594
1393
|
function register(ctx) {
|
|
595
1394
|
registerTranslations(ctx);
|
|
596
|
-
const stops = [
|
|
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
|
+
});
|
|
597
1415
|
ctx.slots.register("shell.dialog.surface", {
|
|
598
1416
|
id: "personalization",
|
|
599
1417
|
component: PersonalizationDialog
|