@eum-agent/personalization 1.1.0 → 1.2.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 +5 -141
- package/package.json +2 -2
- package/ui/ui.js +1033 -217
package/ui/ui.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Button, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, FALLBACK_LANGUAGE, Field, FontPicker, InputNumber, LANGUAGES, LANGUAGE_FLAGS, PLUGIN_ICONS, Picker, Segmented, Select, SettingsPreview, SlotOutlet,
|
|
2
|
-
import React, { useEffect, useId, useMemo, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { AlertDialog, Button, ColorPicker, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, FALLBACK_LANGUAGE, Field, FontPicker, Input, InputNumber, LANGUAGES, LANGUAGE_FLAGS, PLUGIN_ICONS, Picker, Segmented, Select, SettingsPreview, SlotOutlet, cn, colorToHex, contributionsIn, i18next, localeLeaves, notifyReadingLayout, parseColorHex, readableForeground, resolveLabel, useDeviceFonts, usePlugins, useTranslation } from "@eum-agent/host/framework";
|
|
2
|
+
import React, { createContext, createElement, forwardRef, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { Fragment, 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. */
|
|
6
6
|
var translations;
|
|
@@ -39,7 +39,31 @@ var en_US_default = {
|
|
|
39
39
|
"previewInfo": "Preview information",
|
|
40
40
|
"previewReading": "Reading text",
|
|
41
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"
|
|
42
|
+
"resetCategory": "Reset to defaults",
|
|
43
|
+
"theme": "Theme",
|
|
44
|
+
"themeHint": "One palette: surfaces, text, borders and the accent, in both light and dark. Editing any of them makes it a custom theme.",
|
|
45
|
+
"themeNeutral": "Neutral",
|
|
46
|
+
"themeCool": "Cool",
|
|
47
|
+
"themeWarm": "Warm",
|
|
48
|
+
"themeCustom": "Custom",
|
|
49
|
+
"themeBackground": "Background",
|
|
50
|
+
"themeForeground": "Text",
|
|
51
|
+
"themeBrand": "Accent",
|
|
52
|
+
"themeEdit": "Edit {{name}} theme",
|
|
53
|
+
"themeBack": "Back to themes",
|
|
54
|
+
"themeEditor": "Edit theme",
|
|
55
|
+
"themePreview": "Theme preview",
|
|
56
|
+
"themePreviewMode": "Preview mode",
|
|
57
|
+
"themePreviewHint": "This illustration previews colors without changing the current theme.",
|
|
58
|
+
"themeCancel": "Cancel",
|
|
59
|
+
"themePickColor": "Choose {{name}} color",
|
|
60
|
+
"themeSave": "Save",
|
|
61
|
+
"themeDiscardTitle": "Discard theme changes?",
|
|
62
|
+
"themeKeepEditing": "Keep editing",
|
|
63
|
+
"themeDiscard": "Discard changes",
|
|
64
|
+
"themeDiscardHint": "Unsaved colors will be lost. Your current theme stays unchanged.",
|
|
65
|
+
"themeInvalidColor": "Enter a valid opaque hexadecimal color, such as #2563eb.",
|
|
66
|
+
"themeSaveError": "Could not save. Your current theme is unchanged. Retry or check browser storage permissions."
|
|
43
67
|
},
|
|
44
68
|
brand: {
|
|
45
69
|
"violet": "Violet",
|
|
@@ -76,7 +100,31 @@ var zh_CN_default = {
|
|
|
76
100
|
"previewInfo": "预览说明",
|
|
77
101
|
"previewReading": "阅读文本",
|
|
78
102
|
"previewDescription": "固定示例会随字体与字号即时更新,字体缺失时使用系统回退。阅读示例仅预览字体与字号;内容宽度作用于实际阅读区域。不会发送消息或执行命令。",
|
|
79
|
-
"resetCategory": "恢复默认"
|
|
103
|
+
"resetCategory": "恢复默认",
|
|
104
|
+
"theme": "主题",
|
|
105
|
+
"themeHint": "一套配色方案:表面、文字、边界与品牌色,浅色与深色各一套。改任何一项就成为自定义主题。",
|
|
106
|
+
"themeNeutral": "中性",
|
|
107
|
+
"themeCool": "冷调",
|
|
108
|
+
"themeWarm": "暖调",
|
|
109
|
+
"themeCustom": "自定义",
|
|
110
|
+
"themeBackground": "背景",
|
|
111
|
+
"themeForeground": "正文",
|
|
112
|
+
"themeBrand": "品牌色",
|
|
113
|
+
"themeEdit": "编辑{{name}}主题",
|
|
114
|
+
"themeBack": "返回主题",
|
|
115
|
+
"themeEditor": "编辑主题",
|
|
116
|
+
"themePreview": "主题预览",
|
|
117
|
+
"themePreviewMode": "预览模式",
|
|
118
|
+
"themePreviewHint": "示意图仅预览配色,不会更改当前主题。",
|
|
119
|
+
"themeCancel": "取消",
|
|
120
|
+
"themePickColor": "选择{{name}}颜色",
|
|
121
|
+
"themeSave": "保存",
|
|
122
|
+
"themeDiscardTitle": "放弃主题修改?",
|
|
123
|
+
"themeKeepEditing": "继续编辑",
|
|
124
|
+
"themeDiscard": "放弃修改",
|
|
125
|
+
"themeDiscardHint": "尚未保存的配色将丢失,当前主题保持不变。",
|
|
126
|
+
"themeInvalidColor": "请输入有效的不透明十六进制颜色(如 #2563eb)。",
|
|
127
|
+
"themeSaveError": "保存失败,当前主题未更改。请重试,或检查浏览器的存储权限。"
|
|
80
128
|
},
|
|
81
129
|
brand: {
|
|
82
130
|
"violet": "鸢紫",
|
|
@@ -102,6 +150,168 @@ function registerTranslations(ctx) {
|
|
|
102
150
|
}, "zh-CN");
|
|
103
151
|
}
|
|
104
152
|
//#endregion
|
|
153
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs
|
|
154
|
+
/**
|
|
155
|
+
* @license lucide-react v1.40.0 - ISC
|
|
156
|
+
*
|
|
157
|
+
* This source code is licensed under the ISC license.
|
|
158
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
159
|
+
*/
|
|
160
|
+
var mergeClasses = (...classes) => classes.filter((className, index, array) => {
|
|
161
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
162
|
+
}).join(" ").trim();
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs
|
|
165
|
+
/**
|
|
166
|
+
* @license lucide-react v1.40.0 - ISC
|
|
167
|
+
*
|
|
168
|
+
* This source code is licensed under the ISC license.
|
|
169
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
170
|
+
*/
|
|
171
|
+
var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs
|
|
174
|
+
/**
|
|
175
|
+
* @license lucide-react v1.40.0 - ISC
|
|
176
|
+
*
|
|
177
|
+
* This source code is licensed under the ISC license.
|
|
178
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
179
|
+
*/
|
|
180
|
+
var toCamelCase = (string) => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs
|
|
183
|
+
/**
|
|
184
|
+
* @license lucide-react v1.40.0 - ISC
|
|
185
|
+
*
|
|
186
|
+
* This source code is licensed under the ISC license.
|
|
187
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
188
|
+
*/
|
|
189
|
+
var toPascalCase = (string) => {
|
|
190
|
+
const camelCase = toCamelCase(string);
|
|
191
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/defaultAttributes.mjs
|
|
195
|
+
/**
|
|
196
|
+
* @license lucide-react v1.40.0 - ISC
|
|
197
|
+
*
|
|
198
|
+
* This source code is licensed under the ISC license.
|
|
199
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
200
|
+
*/
|
|
201
|
+
var defaultAttributes = {
|
|
202
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
203
|
+
width: 24,
|
|
204
|
+
height: 24,
|
|
205
|
+
viewBox: "0 0 24 24",
|
|
206
|
+
fill: "none",
|
|
207
|
+
stroke: "currentColor",
|
|
208
|
+
strokeWidth: 2,
|
|
209
|
+
strokeLinecap: "round",
|
|
210
|
+
strokeLinejoin: "round"
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs
|
|
214
|
+
/**
|
|
215
|
+
* @license lucide-react v1.40.0 - ISC
|
|
216
|
+
*
|
|
217
|
+
* This source code is licensed under the ISC license.
|
|
218
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
219
|
+
*/
|
|
220
|
+
var hasA11yProp = (props) => {
|
|
221
|
+
for (const prop in props) if (prop.startsWith("aria-") || prop === "role" || prop === "title") return true;
|
|
222
|
+
return false;
|
|
223
|
+
};
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/context.mjs
|
|
226
|
+
/**
|
|
227
|
+
* @license lucide-react v1.40.0 - ISC
|
|
228
|
+
*
|
|
229
|
+
* This source code is licensed under the ISC license.
|
|
230
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
+
*/
|
|
232
|
+
var LucideContext = createContext({});
|
|
233
|
+
var useLucideContext = () => useContext(LucideContext);
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/Icon.mjs
|
|
236
|
+
/**
|
|
237
|
+
* @license lucide-react v1.40.0 - ISC
|
|
238
|
+
*
|
|
239
|
+
* This source code is licensed under the ISC license.
|
|
240
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
+
*/
|
|
242
|
+
var Icon = forwardRef(({ color, size, strokeWidth, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref) => {
|
|
243
|
+
const { size: contextSize = 24, strokeWidth: contextStrokeWidth = 2, absoluteStrokeWidth: contextAbsoluteStrokeWidth = false, color: contextColor = "currentColor", className: contextClass = "" } = useLucideContext() ?? {};
|
|
244
|
+
const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;
|
|
245
|
+
return createElement("svg", {
|
|
246
|
+
ref,
|
|
247
|
+
...defaultAttributes,
|
|
248
|
+
width: size ?? contextSize ?? defaultAttributes.width,
|
|
249
|
+
height: size ?? contextSize ?? defaultAttributes.height,
|
|
250
|
+
stroke: color ?? contextColor,
|
|
251
|
+
strokeWidth: calculatedStrokeWidth,
|
|
252
|
+
className: mergeClasses("lucide", contextClass, className),
|
|
253
|
+
...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
|
|
254
|
+
...rest
|
|
255
|
+
}, [...iconNode.map(([tag, attrs]) => createElement(tag, attrs)), ...Array.isArray(children) ? children : [children]]);
|
|
256
|
+
});
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region ../../../node_modules/.pnpm/lucide-react@1.40.0_react@19.2.8/node_modules/lucide-react/dist/esm/createLucideIcon.mjs
|
|
259
|
+
/**
|
|
260
|
+
* @license lucide-react v1.40.0 - ISC
|
|
261
|
+
*
|
|
262
|
+
* This source code is licensed under the ISC license.
|
|
263
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
264
|
+
*/
|
|
265
|
+
var createLucideIcon = (iconName, iconNode) => {
|
|
266
|
+
const Component = forwardRef(({ className, ...props }, ref) => createElement(Icon, {
|
|
267
|
+
ref,
|
|
268
|
+
iconNode,
|
|
269
|
+
className: mergeClasses(`lucide-${toKebabCase(toPascalCase(iconName))}`, `lucide-${iconName}`, className),
|
|
270
|
+
...props
|
|
271
|
+
}));
|
|
272
|
+
Component.displayName = toPascalCase(iconName);
|
|
273
|
+
return Component;
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* @license lucide-react v1.40.0 - ISC
|
|
277
|
+
*
|
|
278
|
+
* This source code is licensed under the ISC license.
|
|
279
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
280
|
+
*/
|
|
281
|
+
var ArrowLeft = createLucideIcon("arrow-left", [["path", {
|
|
282
|
+
d: "m12 19-7-7 7-7",
|
|
283
|
+
key: "1l729n"
|
|
284
|
+
}], ["path", {
|
|
285
|
+
d: "M19 12H5",
|
|
286
|
+
key: "x3x0zl"
|
|
287
|
+
}]]);
|
|
288
|
+
/**
|
|
289
|
+
* @license lucide-react v1.40.0 - ISC
|
|
290
|
+
*
|
|
291
|
+
* This source code is licensed under the ISC license.
|
|
292
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
293
|
+
*/
|
|
294
|
+
var ArrowUp = createLucideIcon("arrow-up", [["path", {
|
|
295
|
+
d: "m5 12 7-7 7 7",
|
|
296
|
+
key: "hav0vg"
|
|
297
|
+
}], ["path", {
|
|
298
|
+
d: "M12 19V5",
|
|
299
|
+
key: "x0mq9r"
|
|
300
|
+
}]]);
|
|
301
|
+
/**
|
|
302
|
+
* @license lucide-react v1.40.0 - ISC
|
|
303
|
+
*
|
|
304
|
+
* This source code is licensed under the ISC license.
|
|
305
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
306
|
+
*/
|
|
307
|
+
var Pencil = createLucideIcon("pencil", [["path", {
|
|
308
|
+
d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",
|
|
309
|
+
key: "1a8usu"
|
|
310
|
+
}], ["path", {
|
|
311
|
+
d: "m15 5 4 4",
|
|
312
|
+
key: "1mk7zo"
|
|
313
|
+
}]]);
|
|
314
|
+
//#endregion
|
|
105
315
|
//#region ui-src/fonts/manifest.json
|
|
106
316
|
var manifest_default = [
|
|
107
317
|
{
|
|
@@ -296,7 +506,7 @@ function createReadingTypography(options) {
|
|
|
296
506
|
}
|
|
297
507
|
//#endregion
|
|
298
508
|
//#region ui-src/lib/font-resource.ts
|
|
299
|
-
/**
|
|
509
|
+
/** Resolves a fixed packaged font through the host's native URL mapping. */
|
|
300
510
|
function resourceFontFace(ctx, id) {
|
|
301
511
|
const asset = READING_FONT_ASSETS.find((asset) => asset.id === id);
|
|
302
512
|
if (!asset) throw new Error("Unknown reading font");
|
|
@@ -305,30 +515,12 @@ function resourceFontFace(ctx, id) {
|
|
|
305
515
|
const entry = {
|
|
306
516
|
cancel: () => controller.abort(),
|
|
307
517
|
async load() {
|
|
308
|
-
const surface = await ctx.call("plugin.surface");
|
|
309
518
|
signal.throwIfAborted();
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
}
|
|
519
|
+
const url = ctx.packageFiles.url(`fonts/${asset.file}`);
|
|
520
|
+
const face = new FontFace(readingFontAlias(id), `url(${JSON.stringify(url)})`, { weight: asset.weight });
|
|
521
|
+
await face.load();
|
|
522
|
+
signal.throwIfAborted();
|
|
523
|
+
entry.face = face;
|
|
332
524
|
}
|
|
333
525
|
};
|
|
334
526
|
return entry;
|
|
@@ -724,13 +916,75 @@ var persist = persistImpl;
|
|
|
724
916
|
//#endregion
|
|
725
917
|
//#region ui-src/lib/theme.ts
|
|
726
918
|
/** Applies a palette atomically, including portals and pseudo-elements, without persisting it. */
|
|
727
|
-
|
|
919
|
+
/** Converts an opaque computed RGB or OKLCH color to its displayed sRGB hex value. */
|
|
920
|
+
function colorHexFromCss(color) {
|
|
921
|
+
if (color.startsWith("oklch(")) {
|
|
922
|
+
const [lightness, chroma, hue] = color.slice(6).match(/[+-]?(?:\d*\.)?\d+(?:e[+-]?\d+)?/gi)?.map(Number) ?? [];
|
|
923
|
+
if (lightness === void 0 || chroma === void 0 || hue === void 0) throw new Error("Invalid computed OKLCH color");
|
|
924
|
+
const radians = hue * Math.PI / 180;
|
|
925
|
+
const a = chroma * Math.cos(radians);
|
|
926
|
+
const b = chroma * Math.sin(radians);
|
|
927
|
+
const l = (lightness + .3963377774 * a + .2158037573 * b) ** 3;
|
|
928
|
+
const m = (lightness - .1055613458 * a - .0638541728 * b) ** 3;
|
|
929
|
+
const s = (lightness - .0894841775 * a - 1.291485548 * b) ** 3;
|
|
930
|
+
const channel = (linear) => 255 * (linear <= .0031308 ? 12.92 * linear : 1.055 * linear ** (1 / 2.4) - .055);
|
|
931
|
+
return colorToHex({
|
|
932
|
+
r: channel(4.0767416621 * l - 3.3077115913 * m + .2309699292 * s),
|
|
933
|
+
g: channel(-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s),
|
|
934
|
+
b: channel(-.0041960863 * l - .7034186147 * m + 1.707614701 * s),
|
|
935
|
+
a: 1
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
const [r = 0, g = 0, b = 0] = color.match(/[\d.]+/g)?.map(Number) ?? [];
|
|
939
|
+
return colorToHex({
|
|
940
|
+
r,
|
|
941
|
+
g,
|
|
942
|
+
b,
|
|
943
|
+
a: 1
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* A preset's surface and text colours, read from the same rules the appearance
|
|
948
|
+
* page's preview paints, so a custom theme starts from what the preview shows.
|
|
949
|
+
*/
|
|
950
|
+
function presetColors(preset, mode) {
|
|
951
|
+
const probe = document.createElement("div");
|
|
952
|
+
probe.className = `palette-${preset} palette-preview-${mode}`;
|
|
953
|
+
probe.style.position = "absolute";
|
|
954
|
+
probe.style.visibility = "hidden";
|
|
955
|
+
(document.body ?? document.documentElement).append(probe);
|
|
956
|
+
const style = getComputedStyle(probe);
|
|
957
|
+
const colors = {
|
|
958
|
+
background: colorHexFromCss(style.backgroundColor),
|
|
959
|
+
foreground: colorHexFromCss(style.color)
|
|
960
|
+
};
|
|
961
|
+
probe.remove();
|
|
962
|
+
return colors;
|
|
963
|
+
}
|
|
964
|
+
function applyDocumentTheme(mode, brand, selection) {
|
|
728
965
|
const root = document.documentElement;
|
|
729
|
-
|
|
966
|
+
const custom = selection?.custom ?? null;
|
|
967
|
+
if (!(root.dataset.uiTheme !== mode || selection !== void 0 && root.dataset.palette !== selection.palette || (custom === null ? root.hasAttribute("data-theme-custom") : !root.hasAttribute("data-theme-custom") || root.style.getPropertyValue("--custom-background") !== custom.background || root.style.getPropertyValue("--custom-foreground") !== custom.foreground || root.style.getPropertyValue("--custom-brand") !== custom.brand || root.style.getPropertyValue("--custom-brand-foreground") !== custom.brandForeground) || brand !== void 0 && (root.style.getPropertyValue("--brand-h") !== String(brand.hue) || root.style.getPropertyValue("--brand-c") !== String(brand.chroma)))) return;
|
|
730
968
|
root.dataset.themeChanging = "";
|
|
731
969
|
try {
|
|
732
970
|
root.dataset.uiTheme = mode;
|
|
733
971
|
root.classList.toggle("dark", mode === "dark");
|
|
972
|
+
if (selection !== void 0) {
|
|
973
|
+
root.dataset.palette = selection.palette;
|
|
974
|
+
if (custom === null) {
|
|
975
|
+
delete root.dataset.themeCustom;
|
|
976
|
+
root.style.removeProperty("--custom-background");
|
|
977
|
+
root.style.removeProperty("--custom-foreground");
|
|
978
|
+
root.style.removeProperty("--custom-brand");
|
|
979
|
+
root.style.removeProperty("--custom-brand-foreground");
|
|
980
|
+
} else {
|
|
981
|
+
root.dataset.themeCustom = "";
|
|
982
|
+
root.style.setProperty("--custom-background", custom.background);
|
|
983
|
+
root.style.setProperty("--custom-foreground", custom.foreground);
|
|
984
|
+
root.style.setProperty("--custom-brand", custom.brand);
|
|
985
|
+
root.style.setProperty("--custom-brand-foreground", custom.brandForeground);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
734
988
|
if (brand) {
|
|
735
989
|
root.style.setProperty("--brand-h", String(brand.hue));
|
|
736
990
|
root.style.setProperty("--brand-c", String(brand.chroma));
|
|
@@ -742,7 +996,7 @@ function applyDocumentTheme(mode, brand) {
|
|
|
742
996
|
}
|
|
743
997
|
//#endregion
|
|
744
998
|
//#region ui-src/store/theme.ts
|
|
745
|
-
/** Browser-local
|
|
999
|
+
/** Browser-local language, color scheme and brand preferences. */
|
|
746
1000
|
/** 瑶光 is Alkaid, the star at the end of the Plough's handle, and a B-type
|
|
747
1001
|
* star is blue-white — which is where the default hue comes from. */
|
|
748
1002
|
var ALKAID = {
|
|
@@ -751,91 +1005,281 @@ var ALKAID = {
|
|
|
751
1005
|
hue: 255,
|
|
752
1006
|
chroma: .15
|
|
753
1007
|
};
|
|
754
|
-
/**
|
|
755
|
-
var
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
labelKey: "brand.violet",
|
|
760
|
-
hue: 295,
|
|
1008
|
+
/** The presets, by name: a theme always has one. */
|
|
1009
|
+
var PRESETS = {
|
|
1010
|
+
neutral: {
|
|
1011
|
+
id: "neutral",
|
|
1012
|
+
hue: 255,
|
|
761
1013
|
chroma: .15
|
|
762
1014
|
},
|
|
763
|
-
{
|
|
764
|
-
id: "
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
chroma: .095
|
|
768
|
-
},
|
|
769
|
-
{
|
|
770
|
-
id: "moss",
|
|
771
|
-
labelKey: "brand.moss",
|
|
772
|
-
hue: 150,
|
|
773
|
-
chroma: .12
|
|
1015
|
+
cool: {
|
|
1016
|
+
id: "cool",
|
|
1017
|
+
hue: 295,
|
|
1018
|
+
chroma: .15
|
|
774
1019
|
},
|
|
775
|
-
{
|
|
776
|
-
id: "
|
|
777
|
-
labelKey: "brand.honey",
|
|
1020
|
+
warm: {
|
|
1021
|
+
id: "warm",
|
|
778
1022
|
hue: 70,
|
|
779
1023
|
chroma: .12
|
|
780
|
-
},
|
|
781
|
-
{
|
|
782
|
-
id: "lotus",
|
|
783
|
-
labelKey: "brand.lotus",
|
|
784
|
-
hue: 355,
|
|
785
|
-
chroma: .15
|
|
786
1024
|
}
|
|
1025
|
+
};
|
|
1026
|
+
/** The presets the appearance page offers, in the order it lists them. */
|
|
1027
|
+
var THEME_PRESETS = [
|
|
1028
|
+
PRESETS.neutral,
|
|
1029
|
+
PRESETS.cool,
|
|
1030
|
+
PRESETS.warm
|
|
787
1031
|
];
|
|
788
|
-
/**
|
|
789
|
-
|
|
790
|
-
|
|
1032
|
+
/** The theme an installation starts from, and the one unknown values fall back to. */
|
|
1033
|
+
var DEFAULT_THEME = "neutral";
|
|
1034
|
+
/** The brand renders at a different lightness in each mode; these are those two. */
|
|
1035
|
+
var BRAND_LIGHTNESS = {
|
|
1036
|
+
light: .52,
|
|
1037
|
+
dark: .76
|
|
1038
|
+
};
|
|
1039
|
+
var BRAND_CHROMA_FACTOR = {
|
|
1040
|
+
light: 1,
|
|
1041
|
+
dark: .8
|
|
1042
|
+
};
|
|
1043
|
+
/** The colour a brand renders as in one mode. */
|
|
1044
|
+
function brandColor(brand, mode) {
|
|
1045
|
+
return colorHexFromCss(`oklch(${BRAND_LIGHTNESS[mode]} ${brand.chroma * BRAND_CHROMA_FACTOR[mode]} ${brand.hue})`);
|
|
1046
|
+
}
|
|
1047
|
+
/** The colour that reads on a brand colour. */
|
|
1048
|
+
function brandForeground(color) {
|
|
1049
|
+
const parsed = parseColorHex(color);
|
|
1050
|
+
return parsed === null ? "#ffffff" : colorToHex(readableForeground(parsed));
|
|
1051
|
+
}
|
|
1052
|
+
/** A custom theme that starts from a preset's own colours. */
|
|
1053
|
+
function customFromPreset(base) {
|
|
1054
|
+
const preset = PRESETS[base];
|
|
1055
|
+
const light = presetColors(base, "light");
|
|
1056
|
+
const dark = presetColors(base, "dark");
|
|
1057
|
+
return {
|
|
1058
|
+
base,
|
|
1059
|
+
light: {
|
|
1060
|
+
background: light.background,
|
|
1061
|
+
foreground: light.foreground,
|
|
1062
|
+
brand: brandColor(preset, "light")
|
|
1063
|
+
},
|
|
1064
|
+
dark: {
|
|
1065
|
+
background: dark.background,
|
|
1066
|
+
foreground: dark.foreground,
|
|
1067
|
+
brand: brandColor(preset, "dark")
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
/** Returns an isolated editing draft without changing applied or saved preferences. */
|
|
1072
|
+
function createThemeDraft(source) {
|
|
1073
|
+
if (source !== "custom") return customFromPreset(source);
|
|
1074
|
+
const state = useTheme.getState();
|
|
1075
|
+
const custom = state.custom;
|
|
1076
|
+
if (custom !== null) return {
|
|
1077
|
+
base: custom.base,
|
|
1078
|
+
light: { ...custom.light },
|
|
1079
|
+
dark: { ...custom.dark }
|
|
1080
|
+
};
|
|
1081
|
+
return customFromPreset(state.theme === "custom" ? DEFAULT_THEME : state.theme);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* A stored or typed opaque hex colour in canonical `#rrggbb` form, accepting surrounding space,
|
|
1085
|
+
* a missing `#` and short form; null for anything else, alpha included.
|
|
1086
|
+
*/
|
|
1087
|
+
function opaqueHex(value) {
|
|
1088
|
+
if (typeof value !== "string") return null;
|
|
1089
|
+
const parsed = parseColorHex(value);
|
|
1090
|
+
return parsed !== null && parsed.a === 1 ? colorToHex(parsed) : null;
|
|
1091
|
+
}
|
|
1092
|
+
/** The three colours of one mode in canonical CSS form, when they are usable; otherwise nothing. */
|
|
1093
|
+
function readColors(stored) {
|
|
1094
|
+
if (typeof stored !== "object" || stored === null) return null;
|
|
1095
|
+
const candidate = stored;
|
|
1096
|
+
const background = opaqueHex(candidate.background);
|
|
1097
|
+
const foreground = opaqueHex(candidate.foreground);
|
|
1098
|
+
const brand = opaqueHex(candidate.brand);
|
|
1099
|
+
if (!background || !foreground || !brand) return null;
|
|
1100
|
+
return {
|
|
1101
|
+
background,
|
|
1102
|
+
foreground,
|
|
1103
|
+
brand
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* The custom theme as it was stored. A mode that is missing or unusable is
|
|
1108
|
+
* filled from the base preset, so a half-written custom still works; a value
|
|
1109
|
+
* that is not a custom theme at all reads as nothing.
|
|
1110
|
+
*/
|
|
1111
|
+
function readCustomTheme(stored) {
|
|
1112
|
+
if (typeof stored !== "object" || stored === null) return null;
|
|
1113
|
+
const candidate = stored;
|
|
1114
|
+
const base = candidate.base === "cool" || candidate.base === "warm" ? candidate.base : DEFAULT_THEME;
|
|
1115
|
+
const fallback = customFromPreset(base);
|
|
1116
|
+
return {
|
|
1117
|
+
base,
|
|
1118
|
+
light: readColors(candidate.light) ?? fallback.light,
|
|
1119
|
+
dark: readColors(candidate.dark) ?? fallback.dark
|
|
1120
|
+
};
|
|
791
1121
|
}
|
|
792
1122
|
var CONTENT_WIDTHS = [
|
|
793
1123
|
"default",
|
|
794
1124
|
"wide",
|
|
795
1125
|
"full"
|
|
796
1126
|
];
|
|
797
|
-
|
|
1127
|
+
function themePreferences({ theme, custom, mode, contentWidth }) {
|
|
1128
|
+
return {
|
|
1129
|
+
theme,
|
|
1130
|
+
custom,
|
|
1131
|
+
mode,
|
|
1132
|
+
contentWidth
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
var createThemeState = (publish, get, api) => persist((set, get) => ({
|
|
798
1136
|
mode: "system",
|
|
799
1137
|
setMode: (mode) => set({ mode }),
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1138
|
+
theme: DEFAULT_THEME,
|
|
1139
|
+
setTheme: (theme) => {
|
|
1140
|
+
if (theme === "custom" && get().custom === null) {
|
|
1141
|
+
const inForce = get().theme;
|
|
1142
|
+
set({
|
|
1143
|
+
theme,
|
|
1144
|
+
custom: customFromPreset(inForce === "custom" ? DEFAULT_THEME : inForce)
|
|
1145
|
+
});
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
set({ theme });
|
|
1149
|
+
},
|
|
1150
|
+
custom: null,
|
|
1151
|
+
setCustomColor: (mode, role, value) => {
|
|
1152
|
+
const state = get();
|
|
1153
|
+
const base = state.custom?.base ?? (state.theme === "custom" ? "neutral" : state.theme);
|
|
1154
|
+
const custom = state.custom ?? customFromPreset(base);
|
|
1155
|
+
set({
|
|
1156
|
+
theme: "custom",
|
|
1157
|
+
custom: {
|
|
1158
|
+
...custom,
|
|
1159
|
+
[mode]: {
|
|
1160
|
+
...custom[mode],
|
|
1161
|
+
[role]: value
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
},
|
|
1166
|
+
copyCustomFrom: (base) => set({
|
|
1167
|
+
theme: "custom",
|
|
1168
|
+
custom: customFromPreset(base)
|
|
805
1169
|
}),
|
|
1170
|
+
saveCustomTheme: (draft) => {
|
|
1171
|
+
const light = readColors(draft.light);
|
|
1172
|
+
const dark = readColors(draft.dark);
|
|
1173
|
+
if (!THEME_PRESETS.some((preset) => preset.id === draft.base) || !light || !dark) throw new Error("Invalid custom theme");
|
|
1174
|
+
const custom = {
|
|
1175
|
+
base: draft.base,
|
|
1176
|
+
light,
|
|
1177
|
+
dark
|
|
1178
|
+
};
|
|
1179
|
+
const options = useTheme.persist.getOptions();
|
|
1180
|
+
if (options.storage === void 0) throw new Error("Theme storage is unavailable");
|
|
1181
|
+
options.storage.setItem(options.name ?? "yaoguang.theme", {
|
|
1182
|
+
state: themePreferences({
|
|
1183
|
+
...get(),
|
|
1184
|
+
theme: "custom",
|
|
1185
|
+
custom
|
|
1186
|
+
}),
|
|
1187
|
+
version: options.version ?? 0
|
|
1188
|
+
});
|
|
1189
|
+
publish({
|
|
1190
|
+
theme: "custom",
|
|
1191
|
+
custom
|
|
1192
|
+
});
|
|
1193
|
+
},
|
|
806
1194
|
contentWidth: "default",
|
|
807
1195
|
setContentWidth: (contentWidth) => set({ contentWidth })
|
|
808
1196
|
}), {
|
|
809
1197
|
name: "yaoguang.theme",
|
|
810
|
-
partialize:
|
|
811
|
-
hue,
|
|
812
|
-
chroma,
|
|
813
|
-
mode,
|
|
814
|
-
contentWidth
|
|
815
|
-
}),
|
|
1198
|
+
partialize: themePreferences,
|
|
816
1199
|
merge: (persisted, current) => {
|
|
817
1200
|
const stored = persisted;
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
1201
|
+
const mode = stored?.mode === "dark" || stored?.mode === "light" ? stored.mode : "system";
|
|
1202
|
+
const contentWidth = CONTENT_WIDTHS.find((width) => width === stored?.contentWidth) ?? "default";
|
|
1203
|
+
const custom = readCustomTheme(stored?.custom);
|
|
1204
|
+
const theme = stored?.theme;
|
|
1205
|
+
if (theme === "neutral" || theme === "cool" || theme === "warm") return {
|
|
1206
|
+
...current,
|
|
1207
|
+
mode,
|
|
1208
|
+
theme,
|
|
1209
|
+
custom,
|
|
1210
|
+
contentWidth
|
|
1211
|
+
};
|
|
1212
|
+
if (theme === "custom" && custom !== null) return {
|
|
1213
|
+
...current,
|
|
1214
|
+
mode,
|
|
1215
|
+
theme: "custom",
|
|
1216
|
+
custom,
|
|
1217
|
+
contentWidth
|
|
1218
|
+
};
|
|
1219
|
+
const hue = stored?.hue ?? ALKAID.hue;
|
|
1220
|
+
const chroma = stored?.chroma ?? ALKAID.chroma;
|
|
1221
|
+
if (hue === ALKAID.hue && chroma === ALKAID.chroma) return {
|
|
1222
|
+
...current,
|
|
1223
|
+
mode,
|
|
1224
|
+
theme: DEFAULT_THEME,
|
|
1225
|
+
custom,
|
|
1226
|
+
contentWidth
|
|
1227
|
+
};
|
|
1228
|
+
const migrated = customFromPreset(DEFAULT_THEME);
|
|
822
1229
|
return {
|
|
823
1230
|
...current,
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1231
|
+
mode,
|
|
1232
|
+
theme: "custom",
|
|
1233
|
+
custom: {
|
|
1234
|
+
...migrated,
|
|
1235
|
+
light: {
|
|
1236
|
+
...migrated.light,
|
|
1237
|
+
brand: brandColor({
|
|
1238
|
+
hue,
|
|
1239
|
+
chroma
|
|
1240
|
+
}, "light")
|
|
1241
|
+
},
|
|
1242
|
+
dark: {
|
|
1243
|
+
...migrated.dark,
|
|
1244
|
+
brand: brandColor({
|
|
1245
|
+
hue,
|
|
1246
|
+
chroma
|
|
1247
|
+
}, "dark")
|
|
1248
|
+
}
|
|
1249
|
+
},
|
|
1250
|
+
contentWidth
|
|
828
1251
|
};
|
|
829
1252
|
}
|
|
830
|
-
}));
|
|
831
|
-
/**
|
|
1253
|
+
})(publish, get, api);
|
|
1254
|
+
/** Browser-local appearance state, persisted under its existing preference key. */
|
|
1255
|
+
var useTheme = create()(createThemeState);
|
|
1256
|
+
/** The mode in force, resolving "system" against the operating system. */
|
|
1257
|
+
function resolveMode(mode) {
|
|
1258
|
+
if (mode !== "system") return mode;
|
|
1259
|
+
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1260
|
+
}
|
|
1261
|
+
/** Applies the scheme, theme and content width to the document, including portalled components. */
|
|
832
1262
|
function applyTheme(state) {
|
|
833
1263
|
document.documentElement.dataset.contentWidth = state.contentWidth ?? "default";
|
|
834
|
-
|
|
1264
|
+
const mode = resolveMode(state.mode);
|
|
1265
|
+
const custom = state.theme === "custom" ? state.custom : null;
|
|
1266
|
+
const base = custom?.base ?? (state.theme === "custom" ? "neutral" : state.theme);
|
|
1267
|
+
const preset = PRESETS[base];
|
|
1268
|
+
const values = custom === null ? null : {
|
|
1269
|
+
...custom[mode],
|
|
1270
|
+
brandForeground: brandForeground(custom[mode].brand)
|
|
1271
|
+
};
|
|
1272
|
+
applyDocumentTheme(mode, {
|
|
1273
|
+
hue: preset.hue,
|
|
1274
|
+
chroma: preset.chroma
|
|
1275
|
+
}, {
|
|
1276
|
+
palette: base,
|
|
1277
|
+
custom: values
|
|
1278
|
+
});
|
|
835
1279
|
}
|
|
836
1280
|
var themeActivation;
|
|
837
1281
|
/**
|
|
838
|
-
* Applies the stored
|
|
1282
|
+
* Applies the stored theme once and keeps it applied. Called before the first
|
|
839
1283
|
* feature renders. Withdrawal removes its listeners and restores the host defaults
|
|
840
1284
|
* while retaining stored preferences for the next activation.
|
|
841
1285
|
*/
|
|
@@ -860,10 +1304,24 @@ function initTheme() {
|
|
|
860
1304
|
document.documentElement.dataset.contentWidth = "default";
|
|
861
1305
|
document.documentElement.style.removeProperty("--brand-h");
|
|
862
1306
|
document.documentElement.style.removeProperty("--brand-c");
|
|
1307
|
+
document.documentElement.style.removeProperty("--custom-background");
|
|
1308
|
+
document.documentElement.style.removeProperty("--custom-foreground");
|
|
1309
|
+
document.documentElement.style.removeProperty("--custom-brand");
|
|
1310
|
+
document.documentElement.style.removeProperty("--custom-brand-foreground");
|
|
1311
|
+
delete document.documentElement.dataset.palette;
|
|
1312
|
+
delete document.documentElement.dataset.themeCustom;
|
|
863
1313
|
applyDocumentTheme("light");
|
|
864
1314
|
};
|
|
865
1315
|
}
|
|
866
1316
|
//#endregion
|
|
1317
|
+
//#region ui-src/components/personalization-navigation.tsx
|
|
1318
|
+
/** Shares preferences navigation through contributed category components. */
|
|
1319
|
+
var PersonalizationNavigationContext = createContext(null);
|
|
1320
|
+
/** Returns the enclosing preferences navigation, if the category has a shell. */
|
|
1321
|
+
function usePersonalizationNavigation() {
|
|
1322
|
+
return useContext(PersonalizationNavigationContext);
|
|
1323
|
+
}
|
|
1324
|
+
//#endregion
|
|
867
1325
|
//#region ui-src/components/settings/reading-typography.tsx
|
|
868
1326
|
var families = [
|
|
869
1327
|
{
|
|
@@ -959,12 +1417,14 @@ function FontPreference({ script, choice, revision }) {
|
|
|
959
1417
|
...device.options,
|
|
960
1418
|
{
|
|
961
1419
|
value: "system-ui",
|
|
962
|
-
label: chinese ? "系统默认" : "System default"
|
|
1420
|
+
label: chinese ? "系统默认" : "System default",
|
|
1421
|
+
group: "system"
|
|
963
1422
|
},
|
|
964
1423
|
...options.map((font) => ({
|
|
965
1424
|
value: font.family,
|
|
966
1425
|
label: chinese ? font.chinese : font.family,
|
|
967
1426
|
previewFamily: "var(--font-sans)",
|
|
1427
|
+
group: "builtin",
|
|
968
1428
|
note: chinese ? "内置字体,选择后加载;此处使用系统字体预览。" : "Bundled; loads when selected. Preview uses the system font."
|
|
969
1429
|
}))
|
|
970
1430
|
]
|
|
@@ -1049,6 +1509,52 @@ function ReadingTypographySettings() {
|
|
|
1049
1509
|
});
|
|
1050
1510
|
}
|
|
1051
1511
|
//#endregion
|
|
1512
|
+
//#region ui-src/components/settings/theme-preview.tsx
|
|
1513
|
+
/** A decorative conversation specimen using the selected palette without changing the document. */
|
|
1514
|
+
function ThemePreview({ base, mode, colors, large = false }) {
|
|
1515
|
+
const preset = THEME_PRESETS.find((entry) => entry.id === base);
|
|
1516
|
+
if (!preset) throw new Error("Unknown theme preset");
|
|
1517
|
+
const brand = colors?.brand ?? `oklch(${mode === "light" ? .52 : .76} ${preset.chroma * (mode === "light" ? 1 : .8)} ${preset.hue})`;
|
|
1518
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1519
|
+
"aria-hidden": "true",
|
|
1520
|
+
className: cn(`palette-${base} palette-preview-${mode} flex min-w-0 flex-col overflow-hidden rounded-control p-3`, large ? "h-60 gap-5 p-6" : "h-36 gap-3"),
|
|
1521
|
+
style: colors ? {
|
|
1522
|
+
background: colors.background,
|
|
1523
|
+
color: colors.foreground
|
|
1524
|
+
} : void 0,
|
|
1525
|
+
children: [
|
|
1526
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1527
|
+
className: "flex items-center gap-2",
|
|
1528
|
+
children: [/* @__PURE__ */ jsx("span", { className: cn("shrink-0 rounded-full bg-current opacity-25", large ? "size-5" : "size-3") }), /* @__PURE__ */ jsx("span", { className: "h-1 w-1/3 rounded-full bg-current opacity-30" })]
|
|
1529
|
+
}),
|
|
1530
|
+
/* @__PURE__ */ jsx("span", {
|
|
1531
|
+
className: cn("flex flex-1 flex-col gap-1.5", large ? "ml-7 gap-2.5" : "ml-5"),
|
|
1532
|
+
children: [
|
|
1533
|
+
100,
|
|
1534
|
+
82,
|
|
1535
|
+
60,
|
|
1536
|
+
92,
|
|
1537
|
+
67
|
|
1538
|
+
].map((width, index) => /* @__PURE__ */ jsx("span", {
|
|
1539
|
+
className: cn("h-1 rounded-full bg-current opacity-35", index === 3 && "mt-2"),
|
|
1540
|
+
style: { width: `${width}%` }
|
|
1541
|
+
}, width))
|
|
1542
|
+
}),
|
|
1543
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1544
|
+
className: cn("flex items-center justify-between gap-2 rounded-control border border-current/20 px-2", large ? "h-10" : "h-7"),
|
|
1545
|
+
children: [/* @__PURE__ */ jsx("span", { className: "h-1 w-2/5 rounded-full bg-current opacity-20" }), /* @__PURE__ */ jsx("span", {
|
|
1546
|
+
className: cn("flex items-center justify-center rounded-control", large ? "size-6" : "size-4"),
|
|
1547
|
+
style: { background: brand },
|
|
1548
|
+
children: /* @__PURE__ */ jsx(ArrowUp, {
|
|
1549
|
+
className: large ? "size-4" : "size-3",
|
|
1550
|
+
style: { color: colors?.background ?? (mode === "light" ? "#ffffff" : "#202020") }
|
|
1551
|
+
})
|
|
1552
|
+
})]
|
|
1553
|
+
})
|
|
1554
|
+
]
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
//#endregion
|
|
1052
1558
|
//#region ui-src/components/settings/appearance.tsx
|
|
1053
1559
|
/** Browser-local language, color scheme and brand preferences. */
|
|
1054
1560
|
function PreferenceRow({ id, label, children }) {
|
|
@@ -1064,15 +1570,109 @@ function PreferenceRow({ id, label, children }) {
|
|
|
1064
1570
|
})]
|
|
1065
1571
|
});
|
|
1066
1572
|
}
|
|
1573
|
+
/** The mode a colour belongs to right now: the chosen one, or the system's. */
|
|
1574
|
+
function useResolvedMode(mode) {
|
|
1575
|
+
const [system, setSystem] = useState(() => window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
1576
|
+
useEffect(() => {
|
|
1577
|
+
const query = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
1578
|
+
if (!query) return;
|
|
1579
|
+
const onChange = () => setSystem(query.matches ? "dark" : "light");
|
|
1580
|
+
query.addEventListener("change", onChange);
|
|
1581
|
+
return () => query.removeEventListener("change", onChange);
|
|
1582
|
+
}, []);
|
|
1583
|
+
return mode === "system" ? system : mode;
|
|
1584
|
+
}
|
|
1585
|
+
/** The existing three presets and one custom palette share compact conversation previews. */
|
|
1586
|
+
function ThemeCards() {
|
|
1587
|
+
const { t } = useTranslation$1();
|
|
1588
|
+
const { theme, setTheme, custom, mode } = useTheme();
|
|
1589
|
+
const editing = useResolvedMode(mode);
|
|
1590
|
+
const navigation = usePersonalizationNavigation();
|
|
1591
|
+
const choices = [...THEME_PRESETS.map((preset) => preset.id), "custom"];
|
|
1592
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1593
|
+
className: "@container flex min-w-0 flex-col gap-3",
|
|
1594
|
+
children: [
|
|
1595
|
+
/* @__PURE__ */ jsx("p", {
|
|
1596
|
+
className: "text-sm font-medium",
|
|
1597
|
+
children: t("settings.theme")
|
|
1598
|
+
}),
|
|
1599
|
+
/* @__PURE__ */ jsx("p", {
|
|
1600
|
+
className: "text-xs text-muted-foreground",
|
|
1601
|
+
children: t("settings.themeHint")
|
|
1602
|
+
}),
|
|
1603
|
+
/* @__PURE__ */ jsx("div", {
|
|
1604
|
+
className: "grid grid-cols-1 gap-3 @min-[24rem]:grid-cols-2 @min-[40rem]:grid-cols-4",
|
|
1605
|
+
children: choices.map((choice) => {
|
|
1606
|
+
const label = t(`settings.theme${choice.charAt(0).toUpperCase()}${choice.slice(1)}`);
|
|
1607
|
+
const base = choice === "custom" ? custom?.base ?? (theme === "custom" ? "neutral" : theme) : choice;
|
|
1608
|
+
const selected = theme === choice;
|
|
1609
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1610
|
+
"data-theme-card": true,
|
|
1611
|
+
className: "relative min-w-0",
|
|
1612
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
1613
|
+
type: "button",
|
|
1614
|
+
"aria-label": label,
|
|
1615
|
+
"aria-pressed": selected,
|
|
1616
|
+
className: `flex w-full min-w-0 flex-col gap-3 rounded-surface border p-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring ${selected ? "border-primary bg-primary/5" : "border-border hover:bg-muted/30"}`,
|
|
1617
|
+
onClick: () => setTheme(choice),
|
|
1618
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1619
|
+
className: "flex min-w-0 items-center gap-2 pr-6 text-sm font-medium",
|
|
1620
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
1621
|
+
className: "truncate",
|
|
1622
|
+
children: label
|
|
1623
|
+
})
|
|
1624
|
+
}), /* @__PURE__ */ jsx(ThemePreview, {
|
|
1625
|
+
base,
|
|
1626
|
+
mode: editing,
|
|
1627
|
+
colors: choice === "custom" ? custom?.[editing] : void 0
|
|
1628
|
+
})]
|
|
1629
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
1630
|
+
type: "button",
|
|
1631
|
+
"data-theme-edit": choice,
|
|
1632
|
+
ref: (entry) => {
|
|
1633
|
+
if (entry) navigation?.themeEntryMounted(choice, entry);
|
|
1634
|
+
},
|
|
1635
|
+
"aria-label": t("settings.themeEdit", { name: label }),
|
|
1636
|
+
title: t("settings.themeEdit", { name: label }),
|
|
1637
|
+
className: "absolute top-2 right-2 flex size-7 items-center justify-center rounded-control text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",
|
|
1638
|
+
onClick: () => navigation?.editTheme(choice),
|
|
1639
|
+
children: /* @__PURE__ */ jsx(Pencil, {
|
|
1640
|
+
"aria-hidden": "true",
|
|
1641
|
+
className: "size-3.5"
|
|
1642
|
+
})
|
|
1643
|
+
})]
|
|
1644
|
+
}, choice);
|
|
1645
|
+
})
|
|
1646
|
+
})
|
|
1647
|
+
]
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1067
1650
|
/** Preferences apply immediately and persist in this browser without gateway writes. */
|
|
1068
1651
|
function InterfacePreferences() {
|
|
1069
1652
|
const { t, i18n } = useTranslation$1();
|
|
1070
1653
|
const languageLabel = useId();
|
|
1071
1654
|
const current = i18n.resolvedLanguage ?? i18n.language;
|
|
1072
|
-
const { mode, setMode
|
|
1655
|
+
const { mode, setMode } = useTheme();
|
|
1073
1656
|
return /* @__PURE__ */ jsxs("div", {
|
|
1074
1657
|
className: "flex min-w-0 flex-col gap-6",
|
|
1075
1658
|
children: [
|
|
1659
|
+
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
1660
|
+
id: languageLabel,
|
|
1661
|
+
label: t("settings.interfaceLanguage"),
|
|
1662
|
+
children: /* @__PURE__ */ jsx(Picker, {
|
|
1663
|
+
labelledBy: languageLabel,
|
|
1664
|
+
slot: "language-picker",
|
|
1665
|
+
value: current,
|
|
1666
|
+
options: LANGUAGES.map((language) => ({
|
|
1667
|
+
value: language,
|
|
1668
|
+
label: t(language === "en-US" ? "language.en-US" : "language.zh-CN"),
|
|
1669
|
+
prefix: LANGUAGE_FLAGS[language]
|
|
1670
|
+
})),
|
|
1671
|
+
onSelect: (language) => {
|
|
1672
|
+
i18n.changeLanguage(language);
|
|
1673
|
+
}
|
|
1674
|
+
})
|
|
1675
|
+
}),
|
|
1076
1676
|
/* @__PURE__ */ jsx(PreferenceRow, {
|
|
1077
1677
|
label: t("settings.colorMode"),
|
|
1078
1678
|
children: /* @__PURE__ */ jsx(Segmented, {
|
|
@@ -1095,39 +1695,7 @@ function InterfacePreferences() {
|
|
|
1095
1695
|
]
|
|
1096
1696
|
})
|
|
1097
1697
|
}),
|
|
1098
|
-
/* @__PURE__ */ jsx(
|
|
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
|
-
})
|
|
1698
|
+
/* @__PURE__ */ jsx(ThemeCards, {})
|
|
1131
1699
|
]
|
|
1132
1700
|
});
|
|
1133
1701
|
}
|
|
@@ -1223,6 +1791,157 @@ function ReadingPreferences() {
|
|
|
1223
1791
|
});
|
|
1224
1792
|
}
|
|
1225
1793
|
//#endregion
|
|
1794
|
+
//#region ui-src/components/settings/theme-editor.tsx
|
|
1795
|
+
/** Edits both color modes in a detached draft; navigation remains owned by the preferences shell. */
|
|
1796
|
+
function ThemeEditor({ source, onCancel, onSaved, onDirtyChange }) {
|
|
1797
|
+
const { t } = useTranslation$1();
|
|
1798
|
+
const [initial] = useState(() => createThemeDraft(source));
|
|
1799
|
+
const [draft, setDraft] = useState(initial);
|
|
1800
|
+
const [preview, setPreview] = useState(initial);
|
|
1801
|
+
const saving = useRef(false);
|
|
1802
|
+
const dirty = JSON.stringify(draft) !== JSON.stringify(initial);
|
|
1803
|
+
useEffect(() => {
|
|
1804
|
+
onDirtyChange(dirty);
|
|
1805
|
+
return () => onDirtyChange(false);
|
|
1806
|
+
}, [dirty, onDirtyChange]);
|
|
1807
|
+
const [mode, setMode] = useState(() => {
|
|
1808
|
+
const selected = useTheme.getState().mode;
|
|
1809
|
+
if (selected !== "system") return selected;
|
|
1810
|
+
return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1811
|
+
});
|
|
1812
|
+
const fieldId = useId();
|
|
1813
|
+
const [invalid, setInvalid] = useState(false);
|
|
1814
|
+
const [error, setError] = useState(null);
|
|
1815
|
+
const updateColor = (role, value) => {
|
|
1816
|
+
setError(null);
|
|
1817
|
+
setDraft((current) => ({
|
|
1818
|
+
...current,
|
|
1819
|
+
[mode]: {
|
|
1820
|
+
...current[mode],
|
|
1821
|
+
[role]: value
|
|
1822
|
+
}
|
|
1823
|
+
}));
|
|
1824
|
+
const parsed = parseColorHex(value);
|
|
1825
|
+
if (parsed !== null && parsed.a === 1) setPreview((current) => ({
|
|
1826
|
+
...current,
|
|
1827
|
+
[mode]: {
|
|
1828
|
+
...current[mode],
|
|
1829
|
+
[role]: colorToHex(parsed)
|
|
1830
|
+
}
|
|
1831
|
+
}));
|
|
1832
|
+
};
|
|
1833
|
+
const valid = (value) => {
|
|
1834
|
+
const parsed = parseColorHex(value);
|
|
1835
|
+
return parsed !== null && parsed.a === 1;
|
|
1836
|
+
};
|
|
1837
|
+
const save = () => {
|
|
1838
|
+
if (saving.current) return;
|
|
1839
|
+
const invalidMode = ["light", "dark"].find((candidate) => roles.some((role) => !valid(draft[candidate][role])));
|
|
1840
|
+
if (invalidMode) {
|
|
1841
|
+
setInvalid(true);
|
|
1842
|
+
setMode(invalidMode);
|
|
1843
|
+
setError(t("settings.themeInvalidColor"));
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
saving.current = true;
|
|
1847
|
+
try {
|
|
1848
|
+
useTheme.getState().saveCustomTheme(draft);
|
|
1849
|
+
onSaved();
|
|
1850
|
+
} catch {
|
|
1851
|
+
setError(t("settings.themeSaveError"));
|
|
1852
|
+
} finally {
|
|
1853
|
+
saving.current = false;
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
const roles = [
|
|
1857
|
+
"background",
|
|
1858
|
+
"foreground",
|
|
1859
|
+
"brand"
|
|
1860
|
+
];
|
|
1861
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1862
|
+
className: "@container flex min-h-0 min-w-0 flex-1 flex-col",
|
|
1863
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1864
|
+
className: "flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto px-6 pt-1 pb-6",
|
|
1865
|
+
children: [
|
|
1866
|
+
/* @__PURE__ */ jsx("div", {
|
|
1867
|
+
className: "flex shrink-0 justify-end",
|
|
1868
|
+
children: /* @__PURE__ */ jsx(Segmented, {
|
|
1869
|
+
label: t("settings.themePreviewMode"),
|
|
1870
|
+
value: mode,
|
|
1871
|
+
onSelect: setMode,
|
|
1872
|
+
options: [{
|
|
1873
|
+
value: "light",
|
|
1874
|
+
label: t("settings.lightMode")
|
|
1875
|
+
}, {
|
|
1876
|
+
value: "dark",
|
|
1877
|
+
label: t("settings.darkMode")
|
|
1878
|
+
}]
|
|
1879
|
+
})
|
|
1880
|
+
}),
|
|
1881
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
1882
|
+
id: `${fieldId}-error`,
|
|
1883
|
+
role: "alert",
|
|
1884
|
+
className: "rounded-control border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive",
|
|
1885
|
+
children: error
|
|
1886
|
+
}),
|
|
1887
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1888
|
+
className: "grid min-w-0 shrink-0 gap-6 @min-[36rem]:grid-cols-[minmax(0,1fr)_14rem]",
|
|
1889
|
+
children: [/* @__PURE__ */ jsxs("section", {
|
|
1890
|
+
"aria-label": t("settings.themePreview"),
|
|
1891
|
+
className: "min-w-0 rounded-surface border border-border bg-muted/20 p-4",
|
|
1892
|
+
children: [/* @__PURE__ */ jsx(ThemePreview, {
|
|
1893
|
+
large: true,
|
|
1894
|
+
base: draft.base,
|
|
1895
|
+
mode,
|
|
1896
|
+
colors: preview[mode]
|
|
1897
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
1898
|
+
className: "mt-3 text-xs text-muted-foreground",
|
|
1899
|
+
children: t("settings.themePreviewHint")
|
|
1900
|
+
})]
|
|
1901
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1902
|
+
className: "flex min-w-0 flex-col gap-5 rounded-surface border border-border p-4",
|
|
1903
|
+
children: roles.map((role) => /* @__PURE__ */ jsxs("div", {
|
|
1904
|
+
className: "flex min-w-0 flex-col gap-2 text-sm",
|
|
1905
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
1906
|
+
htmlFor: `${fieldId}-${role}`,
|
|
1907
|
+
children: t(`settings.theme${role.charAt(0).toUpperCase()}${role.slice(1)}`)
|
|
1908
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1909
|
+
className: "flex min-w-0 items-center gap-2",
|
|
1910
|
+
children: [/* @__PURE__ */ jsx(ColorPicker, {
|
|
1911
|
+
label: t("settings.themePickColor", { name: t(`settings.theme${role.charAt(0).toUpperCase()}${role.slice(1)}`) }),
|
|
1912
|
+
alpha: false,
|
|
1913
|
+
className: "size-8 shrink-0 justify-center p-0 [&>span:last-child]:hidden",
|
|
1914
|
+
value: parseColorHex(preview[mode][role]) ?? void 0,
|
|
1915
|
+
onChange: (value) => updateColor(role, colorToHex(value))
|
|
1916
|
+
}), /* @__PURE__ */ jsx(Input, {
|
|
1917
|
+
id: `${fieldId}-${role}`,
|
|
1918
|
+
"aria-invalid": invalid && !valid(draft[mode][role]) || void 0,
|
|
1919
|
+
"aria-describedby": invalid && !valid(draft[mode][role]) ? `${fieldId}-error` : void 0,
|
|
1920
|
+
value: draft[mode][role],
|
|
1921
|
+
onChange: (event) => updateColor(role, event.target.value),
|
|
1922
|
+
className: "font-mono text-xs"
|
|
1923
|
+
})]
|
|
1924
|
+
})]
|
|
1925
|
+
}, role))
|
|
1926
|
+
})]
|
|
1927
|
+
})
|
|
1928
|
+
]
|
|
1929
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1930
|
+
className: "grid shrink-0 grid-cols-2 gap-2 px-6 pt-4 pb-6",
|
|
1931
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1932
|
+
variant: "outline",
|
|
1933
|
+
onClick: onCancel,
|
|
1934
|
+
children: t("settings.themeCancel")
|
|
1935
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1936
|
+
variant: "primary",
|
|
1937
|
+
icon: "save",
|
|
1938
|
+
onClick: save,
|
|
1939
|
+
children: t("settings.themeSave")
|
|
1940
|
+
})]
|
|
1941
|
+
})]
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
//#endregion
|
|
1226
1945
|
//#region ui-src/components/personalization-dialog.tsx
|
|
1227
1946
|
/** Owner-contributed preferences share the system settings geometry and content boundaries. */
|
|
1228
1947
|
function PersonalizationDialog({ open, onOpenChange: setOpen }) {
|
|
@@ -1235,6 +1954,50 @@ function PersonalizationDialog({ open, onOpenChange: setOpen }) {
|
|
|
1235
1954
|
}, "shell.personalization.category"), [contributions, crashed]);
|
|
1236
1955
|
const roots = categories.filter((entry) => !entry.contribution.parent);
|
|
1237
1956
|
const [selected, setSelected] = useState();
|
|
1957
|
+
const [editor, setEditor] = useState();
|
|
1958
|
+
const dirty = useRef(false);
|
|
1959
|
+
const pageHeading = useRef(null);
|
|
1960
|
+
const focusSource = useRef(void 0);
|
|
1961
|
+
const restoreSource = useRef(void 0);
|
|
1962
|
+
const [pending, setPending] = useState(null);
|
|
1963
|
+
const setDirty = useCallback((next) => {
|
|
1964
|
+
dirty.current = next;
|
|
1965
|
+
}, []);
|
|
1966
|
+
const closeEditor = useCallback(() => {
|
|
1967
|
+
dirty.current = false;
|
|
1968
|
+
setEditor(void 0);
|
|
1969
|
+
const source = focusSource.current;
|
|
1970
|
+
focusSource.current = void 0;
|
|
1971
|
+
if (source) restoreSource.current = source;
|
|
1972
|
+
}, []);
|
|
1973
|
+
const themeEntryMounted = useCallback((source, entry) => {
|
|
1974
|
+
if (restoreSource.current !== source) return;
|
|
1975
|
+
restoreSource.current = void 0;
|
|
1976
|
+
requestAnimationFrame(() => {
|
|
1977
|
+
requestAnimationFrame(() => {
|
|
1978
|
+
if (!entry.isConnected) return;
|
|
1979
|
+
const active = entry.ownerDocument.activeElement;
|
|
1980
|
+
const popup = entry.closest("[role=\"dialog\"]");
|
|
1981
|
+
if (active !== entry.ownerDocument.body && active !== popup && active !== entry) return;
|
|
1982
|
+
entry.focus({ preventScroll: true });
|
|
1983
|
+
entry.closest("[data-theme-card]")?.scrollIntoView?.({
|
|
1984
|
+
block: "nearest",
|
|
1985
|
+
inline: "nearest"
|
|
1986
|
+
});
|
|
1987
|
+
});
|
|
1988
|
+
});
|
|
1989
|
+
}, []);
|
|
1990
|
+
const requestLeave = useCallback((next) => {
|
|
1991
|
+
const proceed = () => {
|
|
1992
|
+
closeEditor();
|
|
1993
|
+
next();
|
|
1994
|
+
};
|
|
1995
|
+
if (dirty.current) setPending(() => proceed);
|
|
1996
|
+
else proceed();
|
|
1997
|
+
}, [closeEditor]);
|
|
1998
|
+
useEffect(() => {
|
|
1999
|
+
if (editor) pageHeading.current?.focus();
|
|
2000
|
+
}, [editor]);
|
|
1238
2001
|
const current = roots.find((entry) => entry.key === selected) ?? roots[0];
|
|
1239
2002
|
useEffect(() => {
|
|
1240
2003
|
const next = open ? current?.key : void 0;
|
|
@@ -1244,109 +2007,162 @@ function PersonalizationDialog({ open, onOpenChange: setOpen }) {
|
|
|
1244
2007
|
current?.key,
|
|
1245
2008
|
selected
|
|
1246
2009
|
]);
|
|
2010
|
+
useEffect(() => {
|
|
2011
|
+
closeEditor();
|
|
2012
|
+
restoreSource.current = void 0;
|
|
2013
|
+
setPending(null);
|
|
2014
|
+
}, [
|
|
2015
|
+
open,
|
|
2016
|
+
current?.key,
|
|
2017
|
+
closeEditor
|
|
2018
|
+
]);
|
|
1247
2019
|
const children = categories.filter((entry) => entry.contribution.parent === current?.key);
|
|
1248
2020
|
const resettable = current ? [current, ...children].filter((entry) => entry.contribution.onReset) : [];
|
|
1249
2021
|
const title = current ? resolveLabel(current.contribution.label, current.contribution.id) : t("settings.personalization");
|
|
1250
|
-
return /* @__PURE__ */
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
2022
|
+
return /* @__PURE__ */ jsxs(PersonalizationNavigationContext.Provider, {
|
|
2023
|
+
value: {
|
|
2024
|
+
themeEntryMounted,
|
|
2025
|
+
editTheme: (source) => requestLeave(() => {
|
|
2026
|
+
focusSource.current = source;
|
|
2027
|
+
setEditor(source);
|
|
2028
|
+
})
|
|
2029
|
+
},
|
|
2030
|
+
children: [/* @__PURE__ */ jsx(Dialog, {
|
|
2031
|
+
open,
|
|
2032
|
+
onOpenChange: (next) => next ? setOpen(true) : requestLeave(() => setOpen(false)),
|
|
2033
|
+
children: /* @__PURE__ */ jsxs(DialogContent, {
|
|
2034
|
+
closeLabel: t("settings.close"),
|
|
2035
|
+
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",
|
|
2036
|
+
children: [/* @__PURE__ */ jsxs("nav", {
|
|
2037
|
+
"aria-label": t("settings.personalizationCategories"),
|
|
2038
|
+
"data-slot": "settings-contents",
|
|
2039
|
+
className: "settings-navigation surface-column flex min-h-0 flex-col overflow-hidden bg-muted/30 px-3 pb-4",
|
|
2040
|
+
children: [
|
|
2041
|
+
/* @__PURE__ */ jsx(DialogHeader, {
|
|
2042
|
+
className: "flex h-16 shrink-0 justify-center px-3 pr-0",
|
|
2043
|
+
children: /* @__PURE__ */ jsx(DialogTitle, { children: t("settings.personalization") })
|
|
2044
|
+
}),
|
|
2045
|
+
/* @__PURE__ */ jsx("div", {
|
|
2046
|
+
className: "settings-category-list flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto",
|
|
2047
|
+
children: roots.map((entry) => {
|
|
2048
|
+
const Icon = PLUGIN_ICONS[entry.contribution.icon ?? "puzzle"];
|
|
2049
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
2050
|
+
variant: "plain",
|
|
2051
|
+
"data-plugin": entry.owner,
|
|
2052
|
+
"aria-current": entry.key === current?.key,
|
|
2053
|
+
onClick: () => requestLeave(() => setSelected(entry.key)),
|
|
2054
|
+
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"),
|
|
2055
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
2056
|
+
"aria-hidden": "true",
|
|
2057
|
+
className: "size-4 shrink-0"
|
|
2058
|
+
}), resolveLabel(entry.contribution.label, entry.contribution.id)]
|
|
2059
|
+
}, entry.key);
|
|
2060
|
+
})
|
|
2061
|
+
}),
|
|
2062
|
+
current && /* @__PURE__ */ jsx("div", {
|
|
2063
|
+
className: "settings-category-select hidden pb-3",
|
|
2064
|
+
children: /* @__PURE__ */ jsx(Select, {
|
|
2065
|
+
"aria-label": t("settings.personalizationCategories"),
|
|
2066
|
+
value: current.key,
|
|
2067
|
+
onValueChange: (next) => requestLeave(() => setSelected(next)),
|
|
2068
|
+
children: roots.map((entry) => /* @__PURE__ */ jsx("option", {
|
|
2069
|
+
value: entry.key,
|
|
2070
|
+
children: resolveLabel(entry.contribution.label, entry.contribution.id)
|
|
2071
|
+
}, entry.key))
|
|
2072
|
+
})
|
|
1293
2073
|
})
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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",
|
|
2074
|
+
]
|
|
2075
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
2076
|
+
className: "flex min-h-0 min-w-0 flex-col overflow-hidden bg-card",
|
|
2077
|
+
children: [
|
|
2078
|
+
/* @__PURE__ */ jsx(DialogDescription, {
|
|
2079
|
+
className: "sr-only",
|
|
1308
2080
|
children: title
|
|
1309
|
-
}),
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
}),
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
children: label
|
|
1335
|
-
}), /* @__PURE__ */ jsx(SlotOutlet, {
|
|
1336
|
-
slot: "shell.personalization.category",
|
|
1337
|
-
only: entry.key,
|
|
1338
|
-
props: {}
|
|
1339
|
-
})]
|
|
1340
|
-
}, entry.key);
|
|
2081
|
+
}),
|
|
2082
|
+
/* @__PURE__ */ jsxs("header", {
|
|
2083
|
+
"data-slot": "settings-page-header",
|
|
2084
|
+
className: "flex h-16 shrink-0 items-center justify-between gap-3 px-6 pr-14",
|
|
2085
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2086
|
+
className: "flex min-w-0 items-center gap-2",
|
|
2087
|
+
children: [editor && /* @__PURE__ */ jsx(Button, {
|
|
2088
|
+
variant: "plain",
|
|
2089
|
+
"aria-label": t("settings.themeBack"),
|
|
2090
|
+
onClick: () => requestLeave(() => {}),
|
|
2091
|
+
className: "flex size-8 shrink-0 items-center justify-center rounded-control",
|
|
2092
|
+
children: /* @__PURE__ */ jsx(ArrowLeft, { className: "size-4" })
|
|
2093
|
+
}), /* @__PURE__ */ jsx("h2", {
|
|
2094
|
+
ref: pageHeading,
|
|
2095
|
+
tabIndex: -1,
|
|
2096
|
+
className: "min-w-0 text-lg font-semibold outline-none",
|
|
2097
|
+
children: editor ? t("settings.themeEditor") : title
|
|
2098
|
+
})]
|
|
2099
|
+
}), !editor && resettable.length > 0 && /* @__PURE__ */ jsx(Button, {
|
|
2100
|
+
variant: "text",
|
|
2101
|
+
className: "shrink-0",
|
|
2102
|
+
onClick: () => requestLeave(() => {
|
|
2103
|
+
for (const entry of resettable) entry.contribution.onReset?.();
|
|
2104
|
+
}),
|
|
2105
|
+
children: t("settings.resetCategory")
|
|
1341
2106
|
})]
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
|
|
2107
|
+
}),
|
|
2108
|
+
/* @__PURE__ */ jsx("div", {
|
|
2109
|
+
"data-slot": "settings-scroll",
|
|
2110
|
+
className: cn("flex min-h-0 min-w-0 flex-1 flex-col", editor ? "overflow-hidden" : "gap-8 overflow-y-auto px-6 pt-1 pb-6"),
|
|
2111
|
+
children: editor ? /* @__PURE__ */ jsx(ThemeEditor, {
|
|
2112
|
+
source: editor,
|
|
2113
|
+
onCancel: () => requestLeave(() => {}),
|
|
2114
|
+
onSaved: closeEditor,
|
|
2115
|
+
onDirtyChange: setDirty
|
|
2116
|
+
}, editor) : current ? /* @__PURE__ */ jsxs("div", {
|
|
2117
|
+
className: "flex min-w-0 flex-1 flex-col gap-8",
|
|
2118
|
+
children: [/* @__PURE__ */ jsx(SlotOutlet, {
|
|
2119
|
+
slot: "shell.personalization.category",
|
|
2120
|
+
only: current.key,
|
|
2121
|
+
props: {}
|
|
2122
|
+
}), children.map((entry) => {
|
|
2123
|
+
const label = resolveLabel(entry.contribution.label, entry.contribution.id);
|
|
2124
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
2125
|
+
"aria-label": label,
|
|
2126
|
+
className: "space-y-4 border-t border-border pt-6",
|
|
2127
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
2128
|
+
className: "text-sm font-medium",
|
|
2129
|
+
children: label
|
|
2130
|
+
}), /* @__PURE__ */ jsx(SlotOutlet, {
|
|
2131
|
+
slot: "shell.personalization.category",
|
|
2132
|
+
only: entry.key,
|
|
2133
|
+
props: {}
|
|
2134
|
+
})]
|
|
2135
|
+
}, entry.key);
|
|
2136
|
+
})]
|
|
2137
|
+
}, current.key) : /* @__PURE__ */ jsx("p", {
|
|
2138
|
+
className: "text-sm text-muted-foreground",
|
|
2139
|
+
children: t("settings.personalizationEmpty")
|
|
2140
|
+
})
|
|
1345
2141
|
})
|
|
1346
|
-
|
|
1347
|
-
]
|
|
1348
|
-
})
|
|
1349
|
-
})
|
|
2142
|
+
]
|
|
2143
|
+
})]
|
|
2144
|
+
})
|
|
2145
|
+
}), /* @__PURE__ */ jsx(AlertDialog, {
|
|
2146
|
+
open: pending !== null,
|
|
2147
|
+
onOpenChange: (next) => {
|
|
2148
|
+
if (!next) setPending(null);
|
|
2149
|
+
},
|
|
2150
|
+
title: t("settings.themeDiscardTitle"),
|
|
2151
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
|
|
2152
|
+
variant: "ghost",
|
|
2153
|
+
onClick: () => setPending(null),
|
|
2154
|
+
children: t("settings.themeKeepEditing")
|
|
2155
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2156
|
+
variant: "destructive",
|
|
2157
|
+
onClick: () => {
|
|
2158
|
+
const next = pending;
|
|
2159
|
+
setPending(null);
|
|
2160
|
+
next?.();
|
|
2161
|
+
},
|
|
2162
|
+
children: t("settings.themeDiscard")
|
|
2163
|
+
})] }),
|
|
2164
|
+
children: /* @__PURE__ */ jsx("p", { children: t("settings.themeDiscardHint") })
|
|
2165
|
+
})]
|
|
1350
2166
|
});
|
|
1351
2167
|
}
|
|
1352
2168
|
//#endregion
|