@klarkxy/dsh-font 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/docs/README.zh-CN.md +5 -3
- package/lib/client.inner.cjs +256 -279
- package/lib/client.inner.cjs.map +1 -1
- package/lib/client.js +256 -279
- package/lib/contracts.d.ts +6 -8
- package/lib/contracts.js +8 -9
- package/lib/contracts.js.map +1 -1
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -21,12 +21,14 @@ Open **Plugins → Font**:
|
|
|
21
21
|
- **Interface font** and **Code font**: pick a preset, type any font name, or click **Load system fonts** to choose from fonts installed on this computer.
|
|
22
22
|
- **Conversation font size**: 10–22 px, kept in sync with **Settings → General**.
|
|
23
23
|
|
|
24
|
-
Changes apply immediately. Choose **Default** to
|
|
24
|
+
Changes apply immediately and stay in sync with DSH settings. Choose **Default** to return to the DSH font; **Reset all to defaults** resets both font choices and the conversation size on this page.
|
|
25
|
+
|
|
26
|
+
Code font applies to code blocks and inline code. Terminal font and size are independent; adjust them in **Settings → General**.
|
|
25
27
|
|
|
26
28
|
## Limits
|
|
27
29
|
|
|
28
30
|
- **Load system fonts** works only in Chromium-based browsers and asks for permission.
|
|
29
|
-
- Font choices are saved
|
|
31
|
+
- Font choices and conversation size are saved by DSH; every computer where you open the GUI needs the chosen fonts installed.
|
|
30
32
|
- No fonts are bundled; the chosen font must be installed on the computer.
|
|
31
33
|
|
|
32
34
|
## License
|
package/docs/README.zh-CN.md
CHANGED
|
@@ -21,12 +21,14 @@ dsh plugin --profile web add @klarkxy/dsh-font
|
|
|
21
21
|
- **界面字体**和**代码字体**:选预设、手动输入字体名,或点「读取系统字体」从本机已装字体中选择。
|
|
22
22
|
- **会话字号**:10–22 px,与「设置 → 通用」中的字号同步。
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
改动立即生效,并与 DSH 设置保持同步。选择「默认」可恢复 DSH 原字体;「全部恢复默认」重置本页的两项字体和会话字号。
|
|
25
|
+
|
|
26
|
+
代码字体作用于代码块和行内代码。终端字体与字号独立设置,请在「设置 → 通用」中调整。
|
|
25
27
|
|
|
26
28
|
## 限制
|
|
27
29
|
|
|
28
|
-
- 「读取系统字体」只在 Chromium
|
|
29
|
-
-
|
|
30
|
+
- 「读取系统字体」只在 Chromium 系浏览器可用,且需要授权。
|
|
31
|
+
- 字体选择和会话字号由 DSH 保存;在不同电脑打开界面时,每台电脑都需安装所选字体。
|
|
30
32
|
- 插件不附带字体文件,所选字体必须已安装在本机。
|
|
31
33
|
|
|
32
34
|
## 许可证
|
package/lib/client.inner.cjs
CHANGED
|
@@ -2,6 +2,231 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/contracts.ts
|
|
6
|
+
/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
|
|
7
|
+
* normalization, the CSS-variable application core, and the local store.
|
|
8
|
+
* No React, no cordis — every export runs in Node tests and the browser. */
|
|
9
|
+
const PLUGIN_NAME = "@klarkxy/dsh-font";
|
|
10
|
+
/** Legacy browser-local font choices, retained as the one-time migration backup.
|
|
11
|
+
* The active panel reads and writes the host's role-specific preferences. */
|
|
12
|
+
const STORAGE_KEY = "klarkxy.dsh-font.v1";
|
|
13
|
+
function defaultFontSettings() {
|
|
14
|
+
return {
|
|
15
|
+
uiFont: "",
|
|
16
|
+
codeFont: ""
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** A raw font-family string is placed into a single CSS declaration via
|
|
20
|
+
* CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
|
|
21
|
+
* trimming control characters and the CSS delimiters keeps pasted garbage from
|
|
22
|
+
* producing a silently-dead value. */
|
|
23
|
+
function normalizeFontFamily(value) {
|
|
24
|
+
if (typeof value !== "string") return "";
|
|
25
|
+
return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
|
|
26
|
+
}
|
|
27
|
+
function parseFontSettings(raw) {
|
|
28
|
+
let source = raw;
|
|
29
|
+
if (typeof source === "string") try {
|
|
30
|
+
source = JSON.parse(source);
|
|
31
|
+
} catch {
|
|
32
|
+
return defaultFontSettings();
|
|
33
|
+
}
|
|
34
|
+
if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
|
|
35
|
+
const record = source;
|
|
36
|
+
return {
|
|
37
|
+
uiFont: normalizeFontFamily(record.uiFont),
|
|
38
|
+
codeFont: normalizeFontFamily(record.codeFont)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function serializeFontSettings(settings) {
|
|
42
|
+
return JSON.stringify({
|
|
43
|
+
uiFont: normalizeFontFamily(settings.uiFont),
|
|
44
|
+
codeFont: normalizeFontFamily(settings.codeFont)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const UI_FONT_PRESETS = [
|
|
48
|
+
{
|
|
49
|
+
id: "yahei",
|
|
50
|
+
label: {
|
|
51
|
+
zh: "微软雅黑",
|
|
52
|
+
en: "Microsoft YaHei"
|
|
53
|
+
},
|
|
54
|
+
value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "pingfang",
|
|
58
|
+
label: {
|
|
59
|
+
zh: "苹方",
|
|
60
|
+
en: "PingFang SC"
|
|
61
|
+
},
|
|
62
|
+
value: "\"PingFang SC\", -apple-system, sans-serif"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "simsun",
|
|
66
|
+
label: {
|
|
67
|
+
zh: "宋体",
|
|
68
|
+
en: "SimSun"
|
|
69
|
+
},
|
|
70
|
+
value: "\"SimSun\", \"Songti SC\", serif"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "kaiti",
|
|
74
|
+
label: {
|
|
75
|
+
zh: "楷体",
|
|
76
|
+
en: "KaiTi"
|
|
77
|
+
},
|
|
78
|
+
value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "source-han-sans",
|
|
82
|
+
label: {
|
|
83
|
+
zh: "思源黑体",
|
|
84
|
+
en: "Source Han Sans"
|
|
85
|
+
},
|
|
86
|
+
value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: "source-han-serif",
|
|
90
|
+
label: {
|
|
91
|
+
zh: "思源宋体",
|
|
92
|
+
en: "Source Han Serif"
|
|
93
|
+
},
|
|
94
|
+
value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
const CODE_FONT_PRESETS = [
|
|
98
|
+
{
|
|
99
|
+
id: "cascadia",
|
|
100
|
+
label: {
|
|
101
|
+
zh: "Cascadia",
|
|
102
|
+
en: "Cascadia"
|
|
103
|
+
},
|
|
104
|
+
value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "jetbrains-mono",
|
|
108
|
+
label: {
|
|
109
|
+
zh: "JetBrains Mono",
|
|
110
|
+
en: "JetBrains Mono"
|
|
111
|
+
},
|
|
112
|
+
value: "\"JetBrains Mono\", monospace"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: "fira-code",
|
|
116
|
+
label: {
|
|
117
|
+
zh: "Fira Code",
|
|
118
|
+
en: "Fira Code"
|
|
119
|
+
},
|
|
120
|
+
value: "\"Fira Code\", monospace"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "consolas",
|
|
124
|
+
label: {
|
|
125
|
+
zh: "Consolas",
|
|
126
|
+
en: "Consolas"
|
|
127
|
+
},
|
|
128
|
+
value: "Consolas, monospace"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "sarasa",
|
|
132
|
+
label: {
|
|
133
|
+
zh: "更纱黑体",
|
|
134
|
+
en: "Sarasa Mono"
|
|
135
|
+
},
|
|
136
|
+
value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "maple-mono",
|
|
140
|
+
label: {
|
|
141
|
+
zh: "Maple Mono",
|
|
142
|
+
en: "Maple Mono"
|
|
143
|
+
},
|
|
144
|
+
value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
|
|
145
|
+
}
|
|
146
|
+
];
|
|
147
|
+
function presetFor(value, presets) {
|
|
148
|
+
const comparable = (stack) => stack.split(",").map((name) => name.trim().replace(/^["']|["']$/g, "")).join(",");
|
|
149
|
+
return presets.find((preset) => comparable(preset.value) === comparable(value));
|
|
150
|
+
}
|
|
151
|
+
/** Build the committed stack for a family picked from the system font list.
|
|
152
|
+
* The family name comes from the OS (Local Font Access API); quotes and
|
|
153
|
+
* backslashes are stripped so it can be safely re-quoted as one family. */
|
|
154
|
+
function fontStackFor(family, generic) {
|
|
155
|
+
const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
|
|
156
|
+
if (!cleaned) return generic;
|
|
157
|
+
return `"${cleaned}", ${generic}`;
|
|
158
|
+
}
|
|
159
|
+
/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
|
|
160
|
+
* result (entries carry `family` and `fullName`; duplicates per style are
|
|
161
|
+
* expected). */
|
|
162
|
+
function uniqueSystemFonts(fonts) {
|
|
163
|
+
const byFamily = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const item of fonts) {
|
|
165
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
166
|
+
const record = item;
|
|
167
|
+
const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
|
|
168
|
+
if (!family || byFamily.has(family)) continue;
|
|
169
|
+
const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
|
|
170
|
+
byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
|
|
171
|
+
}
|
|
172
|
+
return [...byFamily.entries()].map(([family, fullName]) => ({
|
|
173
|
+
family,
|
|
174
|
+
fullName
|
|
175
|
+
})).sort((a, b) => a.family.localeCompare(b.family));
|
|
176
|
+
}
|
|
177
|
+
/** Picker label: the UI locale's recognizable name leads, the alias stays in
|
|
178
|
+
* parentheses because the canonical family is still what a custom input needs. */
|
|
179
|
+
function systemFontLabel(item, locale) {
|
|
180
|
+
if (!item.fullName) return item.family;
|
|
181
|
+
return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
|
|
182
|
+
}
|
|
183
|
+
/** Browser-local persistence. A fully-default setting removes the key so a
|
|
184
|
+
* reset leaves no residue; storage failures (private mode, quota) degrade to
|
|
185
|
+
* in-memory behaviour rather than breaking the panel. */
|
|
186
|
+
function createFontSettingsStore(storage) {
|
|
187
|
+
let current = defaultFontSettings();
|
|
188
|
+
let pendingPersistence = false;
|
|
189
|
+
return {
|
|
190
|
+
load() {
|
|
191
|
+
if (storage && !pendingPersistence) try {
|
|
192
|
+
current = parseFontSettings(storage.getItem(STORAGE_KEY));
|
|
193
|
+
} catch {}
|
|
194
|
+
return { ...current };
|
|
195
|
+
},
|
|
196
|
+
save(next) {
|
|
197
|
+
current = parseFontSettings(next);
|
|
198
|
+
if (!storage) return;
|
|
199
|
+
pendingPersistence = true;
|
|
200
|
+
try {
|
|
201
|
+
if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
|
|
202
|
+
else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
|
|
203
|
+
pendingPersistence = false;
|
|
204
|
+
} catch {}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/preferences.ts
|
|
210
|
+
const MIGRATION_KEY = "klarkxy.dsh-font.host-preferences.v1";
|
|
211
|
+
/** Preserve the old selection as a backup, but never replay it over native
|
|
212
|
+
* preferences on subsequent loads. Each role migrates independently. */
|
|
213
|
+
function migrateFontPreferences(theme, store, storage) {
|
|
214
|
+
try {
|
|
215
|
+
if (storage?.getItem("klarkxy.dsh-font.host-preferences.v1")) return;
|
|
216
|
+
} catch {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const old = store.load();
|
|
220
|
+
const families = theme.getTheme().fontFamilies;
|
|
221
|
+
for (const [role, value] of [
|
|
222
|
+
["text", old.uiFont],
|
|
223
|
+
["code", old.codeFont],
|
|
224
|
+
["terminal", old.codeFont]
|
|
225
|
+
]) if (!families[role] && normalizeFontFamily(value)) theme.setFontFamily(role, value);
|
|
226
|
+
try {
|
|
227
|
+
storage?.setItem(MIGRATION_KEY, "1");
|
|
228
|
+
} catch {}
|
|
229
|
+
}
|
|
5
230
|
Object.values({
|
|
6
231
|
/** Surfaces, from the page up to the topmost nested card. */
|
|
7
232
|
surface: [
|
|
@@ -178,6 +403,17 @@ ${scope} {
|
|
|
178
403
|
/* --- Layout scaffolding. --- */
|
|
179
404
|
& .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }
|
|
180
405
|
& .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }
|
|
406
|
+
/* Plugin detail pages share one reading column. These are layout recipes;
|
|
407
|
+
* controls keep their own primitive styles. Form spacing follows the host's
|
|
408
|
+
* settings-form/fields.module.css and SettingsForm.module.css. */
|
|
409
|
+
& .dsh-ui-page { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 760px; min-width: 0; }
|
|
410
|
+
& .dsh-ui-form { display: flex; flex-direction: column; gap: 0; min-width: 0; }
|
|
411
|
+
&.dsh-ui-form > .dsh-ui-field, & .dsh-ui-form > .dsh-ui-field { padding: 12px 0; }
|
|
412
|
+
& .dsh-ui-form-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 16px; min-width: 0; }
|
|
413
|
+
& .dsh-ui-fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
414
|
+
@media (max-width: 560px) {
|
|
415
|
+
& .dsh-ui-fields-grid { grid-template-columns: minmax(0, 1fr); }
|
|
416
|
+
}
|
|
181
417
|
& .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
182
418
|
& .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
|
183
419
|
& .dsh-ui-spacer { flex: 1; min-width: 0; }
|
|
@@ -205,6 +441,9 @@ ${scope} {
|
|
|
205
441
|
* official primitive, so this only owns the vertical rhythm. --- */
|
|
206
442
|
& .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
207
443
|
& .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }
|
|
444
|
+
/* Grid fields share a row, so the stacked-field divider must not win later in
|
|
445
|
+
* the cascade. Reset it here, after the field recipe. */
|
|
446
|
+
& .dsh-ui-fields-grid > .dsh-ui-field { padding: 0; border: 0; }
|
|
208
447
|
& .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
209
448
|
& .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
210
449
|
& .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
|
|
@@ -395,255 +634,7 @@ ${scope} {
|
|
|
395
634
|
& *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
|
|
396
635
|
}
|
|
397
636
|
}
|
|
398
|
-
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(
|
|
399
|
-
}
|
|
400
|
-
//#endregion
|
|
401
|
-
//#region src/contracts.ts
|
|
402
|
-
/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
|
|
403
|
-
* normalization, the CSS-variable application core, and the local store.
|
|
404
|
-
* No React, no cordis — every export runs in Node tests and the browser. */
|
|
405
|
-
const PLUGIN_NAME = "@klarkxy/dsh-font";
|
|
406
|
-
/** localStorage key. Fonts are a property of the rendering environment (each
|
|
407
|
-
* browser/machine has its own installed fonts), so they persist browser-local,
|
|
408
|
-
* exactly like the host's own GUI preferences (dsh-client-store, ui-theme
|
|
409
|
-
* notes). The conversation font size is NOT stored here: the official
|
|
410
|
-
* `ctx.theme.setFontSize()` entry persists it host-side already. */
|
|
411
|
-
const STORAGE_KEY = "klarkxy.dsh-font.v1";
|
|
412
|
-
/** DSH rc.2 defines these font stacks on :root. Root inline overrides also
|
|
413
|
-
* reach derived Markdown, brand and terminal font tokens. */
|
|
414
|
-
const UI_FONT_VARIABLE = "--dsw-font-family";
|
|
415
|
-
const CODE_FONT_VARIABLE = "--ds-font-family-code";
|
|
416
|
-
function defaultFontSettings() {
|
|
417
|
-
return {
|
|
418
|
-
uiFont: "",
|
|
419
|
-
codeFont: ""
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
/** A raw font-family string is placed into a single CSS declaration via
|
|
423
|
-
* CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
|
|
424
|
-
* trimming control characters and the CSS delimiters keeps pasted garbage from
|
|
425
|
-
* producing a silently-dead value. */
|
|
426
|
-
function normalizeFontFamily(value) {
|
|
427
|
-
if (typeof value !== "string") return "";
|
|
428
|
-
return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
|
|
429
|
-
}
|
|
430
|
-
function parseFontSettings(raw) {
|
|
431
|
-
let source = raw;
|
|
432
|
-
if (typeof source === "string") try {
|
|
433
|
-
source = JSON.parse(source);
|
|
434
|
-
} catch {
|
|
435
|
-
return defaultFontSettings();
|
|
436
|
-
}
|
|
437
|
-
if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
|
|
438
|
-
const record = source;
|
|
439
|
-
return {
|
|
440
|
-
uiFont: normalizeFontFamily(record.uiFont),
|
|
441
|
-
codeFont: normalizeFontFamily(record.codeFont)
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
function serializeFontSettings(settings) {
|
|
445
|
-
return JSON.stringify({
|
|
446
|
-
uiFont: normalizeFontFamily(settings.uiFont),
|
|
447
|
-
codeFont: normalizeFontFamily(settings.codeFont)
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
const UI_FONT_PRESETS = [
|
|
451
|
-
{
|
|
452
|
-
id: "yahei",
|
|
453
|
-
label: {
|
|
454
|
-
zh: "微软雅黑",
|
|
455
|
-
en: "Microsoft YaHei"
|
|
456
|
-
},
|
|
457
|
-
value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
id: "pingfang",
|
|
461
|
-
label: {
|
|
462
|
-
zh: "苹方",
|
|
463
|
-
en: "PingFang SC"
|
|
464
|
-
},
|
|
465
|
-
value: "\"PingFang SC\", -apple-system, sans-serif"
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
id: "simsun",
|
|
469
|
-
label: {
|
|
470
|
-
zh: "宋体",
|
|
471
|
-
en: "SimSun"
|
|
472
|
-
},
|
|
473
|
-
value: "\"SimSun\", \"Songti SC\", serif"
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
id: "kaiti",
|
|
477
|
-
label: {
|
|
478
|
-
zh: "楷体",
|
|
479
|
-
en: "KaiTi"
|
|
480
|
-
},
|
|
481
|
-
value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
id: "source-han-sans",
|
|
485
|
-
label: {
|
|
486
|
-
zh: "思源黑体",
|
|
487
|
-
en: "Source Han Sans"
|
|
488
|
-
},
|
|
489
|
-
value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
id: "source-han-serif",
|
|
493
|
-
label: {
|
|
494
|
-
zh: "思源宋体",
|
|
495
|
-
en: "Source Han Serif"
|
|
496
|
-
},
|
|
497
|
-
value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
|
|
498
|
-
}
|
|
499
|
-
];
|
|
500
|
-
const CODE_FONT_PRESETS = [
|
|
501
|
-
{
|
|
502
|
-
id: "cascadia",
|
|
503
|
-
label: {
|
|
504
|
-
zh: "Cascadia",
|
|
505
|
-
en: "Cascadia"
|
|
506
|
-
},
|
|
507
|
-
value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
id: "jetbrains-mono",
|
|
511
|
-
label: {
|
|
512
|
-
zh: "JetBrains Mono",
|
|
513
|
-
en: "JetBrains Mono"
|
|
514
|
-
},
|
|
515
|
-
value: "\"JetBrains Mono\", monospace"
|
|
516
|
-
},
|
|
517
|
-
{
|
|
518
|
-
id: "fira-code",
|
|
519
|
-
label: {
|
|
520
|
-
zh: "Fira Code",
|
|
521
|
-
en: "Fira Code"
|
|
522
|
-
},
|
|
523
|
-
value: "\"Fira Code\", monospace"
|
|
524
|
-
},
|
|
525
|
-
{
|
|
526
|
-
id: "consolas",
|
|
527
|
-
label: {
|
|
528
|
-
zh: "Consolas",
|
|
529
|
-
en: "Consolas"
|
|
530
|
-
},
|
|
531
|
-
value: "Consolas, monospace"
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
id: "sarasa",
|
|
535
|
-
label: {
|
|
536
|
-
zh: "更纱黑体",
|
|
537
|
-
en: "Sarasa Mono"
|
|
538
|
-
},
|
|
539
|
-
value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
id: "maple-mono",
|
|
543
|
-
label: {
|
|
544
|
-
zh: "Maple Mono",
|
|
545
|
-
en: "Maple Mono"
|
|
546
|
-
},
|
|
547
|
-
value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
|
|
548
|
-
}
|
|
549
|
-
];
|
|
550
|
-
function presetFor(value, presets) {
|
|
551
|
-
return presets.find((preset) => preset.value === value);
|
|
552
|
-
}
|
|
553
|
-
/** Build the committed stack for a family picked from the system font list.
|
|
554
|
-
* The family name comes from the OS (Local Font Access API); quotes and
|
|
555
|
-
* backslashes are stripped so it can be safely re-quoted as one family. */
|
|
556
|
-
function fontStackFor(family, generic) {
|
|
557
|
-
const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
|
|
558
|
-
if (!cleaned) return generic;
|
|
559
|
-
return `"${cleaned}", ${generic}`;
|
|
560
|
-
}
|
|
561
|
-
/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
|
|
562
|
-
* result (entries carry `family` and `fullName`; duplicates per style are
|
|
563
|
-
* expected). */
|
|
564
|
-
function uniqueSystemFonts(fonts) {
|
|
565
|
-
const byFamily = /* @__PURE__ */ new Map();
|
|
566
|
-
for (const item of fonts) {
|
|
567
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
568
|
-
const record = item;
|
|
569
|
-
const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
|
|
570
|
-
if (!family || byFamily.has(family)) continue;
|
|
571
|
-
const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
|
|
572
|
-
byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
|
|
573
|
-
}
|
|
574
|
-
return [...byFamily.entries()].map(([family, fullName]) => ({
|
|
575
|
-
family,
|
|
576
|
-
fullName
|
|
577
|
-
})).sort((a, b) => a.family.localeCompare(b.family));
|
|
578
|
-
}
|
|
579
|
-
/** Picker label: the UI locale's recognizable name leads, the alias stays in
|
|
580
|
-
* parentheses because the canonical family is still what a custom input needs. */
|
|
581
|
-
function systemFontLabel(item, locale) {
|
|
582
|
-
if (!item.fullName) return item.family;
|
|
583
|
-
return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
|
|
584
|
-
}
|
|
585
|
-
/** Root inline overrides preserve the existing local persistence/unload
|
|
586
|
-
* boundary. Save the underlying value (including !important) on first write
|
|
587
|
-
* or when the host replaces a value, and never retract somebody else's write. */
|
|
588
|
-
function createFontSettingsOverride(style) {
|
|
589
|
-
const owned = /* @__PURE__ */ new Map();
|
|
590
|
-
function release(name) {
|
|
591
|
-
const entry = owned.get(name);
|
|
592
|
-
if (!entry) return;
|
|
593
|
-
if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === "") {
|
|
594
|
-
if (entry.previous) style.setProperty(name, entry.previous, entry.priority);
|
|
595
|
-
else style.removeProperty(name);
|
|
596
|
-
}
|
|
597
|
-
owned.delete(name);
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
apply(settings) {
|
|
601
|
-
for (const [name, value] of [[UI_FONT_VARIABLE, settings.uiFont], [CODE_FONT_VARIABLE, settings.codeFont]]) {
|
|
602
|
-
if (!value) {
|
|
603
|
-
release(name);
|
|
604
|
-
continue;
|
|
605
|
-
}
|
|
606
|
-
const current = style.getPropertyValue(name);
|
|
607
|
-
const priority = style.getPropertyPriority(name);
|
|
608
|
-
const entry = owned.get(name);
|
|
609
|
-
if (!entry || current !== entry.value || priority !== "") owned.set(name, {
|
|
610
|
-
previous: current,
|
|
611
|
-
priority,
|
|
612
|
-
value: ""
|
|
613
|
-
});
|
|
614
|
-
style.setProperty(name, value);
|
|
615
|
-
owned.get(name).value = style.getPropertyValue(name);
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
dispose() {
|
|
619
|
-
for (const name of [...owned.keys()]) release(name);
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
/** Browser-local persistence. A fully-default setting removes the key so a
|
|
624
|
-
* reset leaves no residue; storage failures (private mode, quota) degrade to
|
|
625
|
-
* in-memory behaviour rather than breaking the panel. */
|
|
626
|
-
function createFontSettingsStore(storage) {
|
|
627
|
-
let current = defaultFontSettings();
|
|
628
|
-
let pendingPersistence = false;
|
|
629
|
-
return {
|
|
630
|
-
load() {
|
|
631
|
-
if (storage && !pendingPersistence) try {
|
|
632
|
-
current = parseFontSettings(storage.getItem(STORAGE_KEY));
|
|
633
|
-
} catch {}
|
|
634
|
-
return { ...current };
|
|
635
|
-
},
|
|
636
|
-
save(next) {
|
|
637
|
-
current = parseFontSettings(next);
|
|
638
|
-
if (!storage) return;
|
|
639
|
-
pendingPersistence = true;
|
|
640
|
-
try {
|
|
641
|
-
if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
|
|
642
|
-
else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
|
|
643
|
-
pendingPersistence = false;
|
|
644
|
-
} catch {}
|
|
645
|
-
}
|
|
646
|
-
};
|
|
637
|
+
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?=\s*\{)/gm, (_match, className) => `&${className}, & ${className}`);
|
|
647
638
|
}
|
|
648
639
|
//#endregion
|
|
649
640
|
//#region src/client.tsx
|
|
@@ -664,7 +655,7 @@ const COPY = {
|
|
|
664
655
|
customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
|
|
665
656
|
customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
|
|
666
657
|
uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
|
|
667
|
-
codeHelp: "
|
|
658
|
+
codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
|
|
668
659
|
sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
|
|
669
660
|
loadFonts: "读取系统字体",
|
|
670
661
|
reloadFonts: "重新读取系统字体",
|
|
@@ -687,7 +678,7 @@ const COPY = {
|
|
|
687
678
|
customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
|
|
688
679
|
customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
|
|
689
680
|
uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
|
|
690
|
-
codeHelp: "
|
|
681
|
+
codeHelp: "Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.",
|
|
691
682
|
sizeHelp: "Synced with Settings → General; 10–22 px.",
|
|
692
683
|
loadFonts: "Load system fonts",
|
|
693
684
|
reloadFonts: "Reload system fonts",
|
|
@@ -705,8 +696,7 @@ function fontCopy(locale) {
|
|
|
705
696
|
return COPY[locale];
|
|
706
697
|
}
|
|
707
698
|
const styles = `${officialUiCss("font-root")}
|
|
708
|
-
.font-root {
|
|
709
|
-
.font-custom { margin-top: 8px; }
|
|
699
|
+
.font-root .font-custom { margin-top: 8px; }
|
|
710
700
|
`;
|
|
711
701
|
function readStorage() {
|
|
712
702
|
try {
|
|
@@ -720,7 +710,7 @@ function useLocale(client) {
|
|
|
720
710
|
return (0, react.useSyncExternalStore)((fn) => client.locale.subscribe(fn), getSnapshot, getSnapshot);
|
|
721
711
|
}
|
|
722
712
|
function useFontSize(client) {
|
|
723
|
-
return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().
|
|
713
|
+
return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().fontSizes.text, () => client.theme.getTheme().fontSizes.text);
|
|
724
714
|
}
|
|
725
715
|
function presetMode(value, presets) {
|
|
726
716
|
return presetFor(value, presets)?.id ?? (value ? "custom" : "");
|
|
@@ -805,7 +795,11 @@ function FontField(props) {
|
|
|
805
795
|
function FontSettingsPanel(props) {
|
|
806
796
|
const locale = useLocale(props.client);
|
|
807
797
|
const text = COPY[locale];
|
|
808
|
-
const
|
|
798
|
+
const families = (0, react.useSyncExternalStore)((fn) => props.client.on("theme/change", () => fn()), () => props.client.theme.getTheme().fontFamilies, () => props.client.theme.getTheme().fontFamilies);
|
|
799
|
+
const settings = {
|
|
800
|
+
uiFont: families.text,
|
|
801
|
+
codeFont: families.code
|
|
802
|
+
};
|
|
809
803
|
const fontSize = useFontSize(props.client);
|
|
810
804
|
const [fontList, setFontList] = (0, react.useState)({
|
|
811
805
|
state: "idle",
|
|
@@ -839,13 +833,8 @@ function FontSettingsPanel(props) {
|
|
|
839
833
|
}
|
|
840
834
|
}
|
|
841
835
|
function update(patch) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
codeFont: normalizeFontFamily(patch.codeFont ?? settings.codeFont)
|
|
845
|
-
};
|
|
846
|
-
props.store.save(next);
|
|
847
|
-
props.applySettings(next);
|
|
848
|
-
setSettings(next);
|
|
836
|
+
if (patch.uiFont !== void 0) props.client.theme.setFontFamily("text", normalizeFontFamily(patch.uiFont));
|
|
837
|
+
if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
|
|
849
838
|
}
|
|
850
839
|
const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
|
|
851
840
|
const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
|
|
@@ -857,7 +846,7 @@ function FontSettingsPanel(props) {
|
|
|
857
846
|
const sizes = [];
|
|
858
847
|
for (let px = 10; px <= 22; px += 1) sizes.push(px);
|
|
859
848
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
860
|
-
className: "font-root dsh-ui-
|
|
849
|
+
className: "font-root dsh-ui-page dsh-ui-form",
|
|
861
850
|
"data-testid": "font-settings",
|
|
862
851
|
children: [
|
|
863
852
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
@@ -901,7 +890,7 @@ function FontSettingsPanel(props) {
|
|
|
901
890
|
onChange: (event) => {
|
|
902
891
|
const px = Number(event.target.value);
|
|
903
892
|
if (Number.isInteger(px) && px >= 10 && px <= 22 && px !== fontSize) try {
|
|
904
|
-
props.client.theme.setFontSize(px);
|
|
893
|
+
props.client.theme.setFontSize("text", px);
|
|
905
894
|
} catch {}
|
|
906
895
|
},
|
|
907
896
|
children: sizes.map((px) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
|
|
@@ -916,7 +905,7 @@ function FontSettingsPanel(props) {
|
|
|
916
905
|
]
|
|
917
906
|
}),
|
|
918
907
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
919
|
-
className: "dsh-ui-
|
|
908
|
+
className: "dsh-ui-form-footer",
|
|
920
909
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
921
910
|
variant: "outline",
|
|
922
911
|
size: "md",
|
|
@@ -933,7 +922,7 @@ function FontSettingsPanel(props) {
|
|
|
933
922
|
uiFont: "",
|
|
934
923
|
codeFont: ""
|
|
935
924
|
});
|
|
936
|
-
if (fontSize !== 14) props.client.theme.setFontSize(14);
|
|
925
|
+
if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
|
|
937
926
|
},
|
|
938
927
|
children: text.reset
|
|
939
928
|
})]
|
|
@@ -959,7 +948,7 @@ function FontSettingsPanel(props) {
|
|
|
959
948
|
function apply(ctx) {
|
|
960
949
|
const client = ctx;
|
|
961
950
|
const store = createFontSettingsStore(readStorage());
|
|
962
|
-
|
|
951
|
+
migrateFontPreferences(client.theme, store, readStorage());
|
|
963
952
|
ctx.effect(() => {
|
|
964
953
|
if (typeof document === "undefined") return () => {};
|
|
965
954
|
const style = document.createElement("style");
|
|
@@ -968,23 +957,11 @@ function apply(ctx) {
|
|
|
968
957
|
document.head.appendChild(style);
|
|
969
958
|
return () => style.remove();
|
|
970
959
|
}, "font.styles");
|
|
971
|
-
ctx.effect(() => {
|
|
972
|
-
if (typeof document === "undefined") return () => {};
|
|
973
|
-
const override = createFontSettingsOverride(document.documentElement.style);
|
|
974
|
-
applySettings = (next) => override.apply(next);
|
|
975
|
-
applySettings(store.load());
|
|
976
|
-
return () => {
|
|
977
|
-
override.dispose();
|
|
978
|
-
applySettings = () => {};
|
|
979
|
-
};
|
|
980
|
-
}, "font.apply");
|
|
981
960
|
ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
|
|
982
961
|
name: "plugins.bundle.config",
|
|
983
962
|
key: PLUGIN_NAME
|
|
984
963
|
}, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
|
|
985
964
|
client,
|
|
986
|
-
store,
|
|
987
|
-
applySettings: (next) => applySettings(next),
|
|
988
965
|
view: slotProps?.view
|
|
989
966
|
}))), "font.settings");
|
|
990
967
|
}
|