@klarkxy/dsh-font 0.1.2 → 0.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/README.md +4 -2
- package/docs/README.zh-CN.md +4 -2
- package/lib/client.inner.cjs +261 -274
- package/lib/client.inner.cjs.map +1 -1
- package/lib/client.js +261 -274
- package/lib/contracts.d.ts +3 -6
- package/lib/contracts.js +5 -7
- 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 go back to the DSH font.
|
|
24
|
+
Changes apply immediately and stay in sync with DSH settings. Choose **Default** to go back to the DSH font. **Reset all to defaults** resets the two font choices and 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
|
|
31
|
+
- Font choices and conversation size are saved by DSH. Fonts must be available on each computer where you open the GUI.
|
|
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
30
|
- 「读取系统字体」只在 Chromium 系浏览器可用,首次使用需要授权。
|
|
29
|
-
-
|
|
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: [
|
|
@@ -364,6 +589,29 @@ ${scope} {
|
|
|
364
589
|
& .dsh-ui-select:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }
|
|
365
590
|
& .dsh-ui-select[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
|
|
366
591
|
|
|
592
|
+
/* --- Native textarea. The primitives ship no textarea either, so a settings
|
|
593
|
+
* prompt keeps the platform element and the same field shell as the select:
|
|
594
|
+
* 0.5px l4, radius-md, layer-3, 13/1.5 type. It grows vertically instead of
|
|
595
|
+
* locking to the select's 34px row. --- */
|
|
596
|
+
& .dsh-ui-textarea {
|
|
597
|
+
box-sizing: border-box;
|
|
598
|
+
width: 100%;
|
|
599
|
+
min-width: 0;
|
|
600
|
+
resize: vertical;
|
|
601
|
+
padding: 8px 12px;
|
|
602
|
+
border: 0.5px solid var(--dsw-alias-border-l4);
|
|
603
|
+
border-radius: var(--dsw-radius-md);
|
|
604
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
605
|
+
font: inherit;
|
|
606
|
+
font-size: 13px;
|
|
607
|
+
line-height: 1.5;
|
|
608
|
+
color: var(--dsw-alias-label-primary);
|
|
609
|
+
}
|
|
610
|
+
& .dsh-ui-textarea:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }
|
|
611
|
+
& .dsh-ui-textarea:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }
|
|
612
|
+
& .dsh-ui-textarea::placeholder { color: var(--dsw-alias-label-dimmed); }
|
|
613
|
+
& .dsh-ui-textarea[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
|
|
614
|
+
|
|
367
615
|
/* Long panels scroll inside themselves instead of growing the host page. */
|
|
368
616
|
& .dsh-ui-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
|
|
369
617
|
& .dsh-ui-panel-wide { max-width: 100%; }
|
|
@@ -375,254 +623,6 @@ ${scope} {
|
|
|
375
623
|
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?![+>~])/gm, (_match, className) => `&${className}, & ${className}`);
|
|
376
624
|
}
|
|
377
625
|
//#endregion
|
|
378
|
-
//#region src/contracts.ts
|
|
379
|
-
/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
|
|
380
|
-
* normalization, the CSS-variable application core, and the local store.
|
|
381
|
-
* No React, no cordis — every export runs in Node tests and the browser. */
|
|
382
|
-
const PLUGIN_NAME = "@klarkxy/dsh-font";
|
|
383
|
-
/** localStorage key. Fonts are a property of the rendering environment (each
|
|
384
|
-
* browser/machine has its own installed fonts), so they persist browser-local,
|
|
385
|
-
* exactly like the host's own GUI preferences (dsh-client-store, ui-theme
|
|
386
|
-
* notes). The conversation font size is NOT stored here: the official
|
|
387
|
-
* `ctx.theme.setFontSize()` entry persists it host-side already. */
|
|
388
|
-
const STORAGE_KEY = "klarkxy.dsh-font.v1";
|
|
389
|
-
/** DSH rc.2 defines these font stacks on :root. Root inline overrides also
|
|
390
|
-
* reach derived Markdown, brand and terminal font tokens. */
|
|
391
|
-
const UI_FONT_VARIABLE = "--dsw-font-family";
|
|
392
|
-
const CODE_FONT_VARIABLE = "--ds-font-family-code";
|
|
393
|
-
function defaultFontSettings() {
|
|
394
|
-
return {
|
|
395
|
-
uiFont: "",
|
|
396
|
-
codeFont: ""
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
/** A raw font-family string is placed into a single CSS declaration via
|
|
400
|
-
* CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
|
|
401
|
-
* trimming control characters and the CSS delimiters keeps pasted garbage from
|
|
402
|
-
* producing a silently-dead value. */
|
|
403
|
-
function normalizeFontFamily(value) {
|
|
404
|
-
if (typeof value !== "string") return "";
|
|
405
|
-
return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
|
|
406
|
-
}
|
|
407
|
-
function parseFontSettings(raw) {
|
|
408
|
-
let source = raw;
|
|
409
|
-
if (typeof source === "string") try {
|
|
410
|
-
source = JSON.parse(source);
|
|
411
|
-
} catch {
|
|
412
|
-
return defaultFontSettings();
|
|
413
|
-
}
|
|
414
|
-
if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
|
|
415
|
-
const record = source;
|
|
416
|
-
return {
|
|
417
|
-
uiFont: normalizeFontFamily(record.uiFont),
|
|
418
|
-
codeFont: normalizeFontFamily(record.codeFont)
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
function serializeFontSettings(settings) {
|
|
422
|
-
return JSON.stringify({
|
|
423
|
-
uiFont: normalizeFontFamily(settings.uiFont),
|
|
424
|
-
codeFont: normalizeFontFamily(settings.codeFont)
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
const UI_FONT_PRESETS = [
|
|
428
|
-
{
|
|
429
|
-
id: "yahei",
|
|
430
|
-
label: {
|
|
431
|
-
zh: "微软雅黑",
|
|
432
|
-
en: "Microsoft YaHei"
|
|
433
|
-
},
|
|
434
|
-
value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
|
|
435
|
-
},
|
|
436
|
-
{
|
|
437
|
-
id: "pingfang",
|
|
438
|
-
label: {
|
|
439
|
-
zh: "苹方",
|
|
440
|
-
en: "PingFang SC"
|
|
441
|
-
},
|
|
442
|
-
value: "\"PingFang SC\", -apple-system, sans-serif"
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
id: "simsun",
|
|
446
|
-
label: {
|
|
447
|
-
zh: "宋体",
|
|
448
|
-
en: "SimSun"
|
|
449
|
-
},
|
|
450
|
-
value: "\"SimSun\", \"Songti SC\", serif"
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
id: "kaiti",
|
|
454
|
-
label: {
|
|
455
|
-
zh: "楷体",
|
|
456
|
-
en: "KaiTi"
|
|
457
|
-
},
|
|
458
|
-
value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
id: "source-han-sans",
|
|
462
|
-
label: {
|
|
463
|
-
zh: "思源黑体",
|
|
464
|
-
en: "Source Han Sans"
|
|
465
|
-
},
|
|
466
|
-
value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
|
|
467
|
-
},
|
|
468
|
-
{
|
|
469
|
-
id: "source-han-serif",
|
|
470
|
-
label: {
|
|
471
|
-
zh: "思源宋体",
|
|
472
|
-
en: "Source Han Serif"
|
|
473
|
-
},
|
|
474
|
-
value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
|
|
475
|
-
}
|
|
476
|
-
];
|
|
477
|
-
const CODE_FONT_PRESETS = [
|
|
478
|
-
{
|
|
479
|
-
id: "cascadia",
|
|
480
|
-
label: {
|
|
481
|
-
zh: "Cascadia",
|
|
482
|
-
en: "Cascadia"
|
|
483
|
-
},
|
|
484
|
-
value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
|
|
485
|
-
},
|
|
486
|
-
{
|
|
487
|
-
id: "jetbrains-mono",
|
|
488
|
-
label: {
|
|
489
|
-
zh: "JetBrains Mono",
|
|
490
|
-
en: "JetBrains Mono"
|
|
491
|
-
},
|
|
492
|
-
value: "\"JetBrains Mono\", monospace"
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
id: "fira-code",
|
|
496
|
-
label: {
|
|
497
|
-
zh: "Fira Code",
|
|
498
|
-
en: "Fira Code"
|
|
499
|
-
},
|
|
500
|
-
value: "\"Fira Code\", monospace"
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
id: "consolas",
|
|
504
|
-
label: {
|
|
505
|
-
zh: "Consolas",
|
|
506
|
-
en: "Consolas"
|
|
507
|
-
},
|
|
508
|
-
value: "Consolas, monospace"
|
|
509
|
-
},
|
|
510
|
-
{
|
|
511
|
-
id: "sarasa",
|
|
512
|
-
label: {
|
|
513
|
-
zh: "更纱黑体",
|
|
514
|
-
en: "Sarasa Mono"
|
|
515
|
-
},
|
|
516
|
-
value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
id: "maple-mono",
|
|
520
|
-
label: {
|
|
521
|
-
zh: "Maple Mono",
|
|
522
|
-
en: "Maple Mono"
|
|
523
|
-
},
|
|
524
|
-
value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
|
|
525
|
-
}
|
|
526
|
-
];
|
|
527
|
-
function presetFor(value, presets) {
|
|
528
|
-
return presets.find((preset) => preset.value === value);
|
|
529
|
-
}
|
|
530
|
-
/** Build the committed stack for a family picked from the system font list.
|
|
531
|
-
* The family name comes from the OS (Local Font Access API); quotes and
|
|
532
|
-
* backslashes are stripped so it can be safely re-quoted as one family. */
|
|
533
|
-
function fontStackFor(family, generic) {
|
|
534
|
-
const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
|
|
535
|
-
if (!cleaned) return generic;
|
|
536
|
-
return `"${cleaned}", ${generic}`;
|
|
537
|
-
}
|
|
538
|
-
/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
|
|
539
|
-
* result (entries carry `family` and `fullName`; duplicates per style are
|
|
540
|
-
* expected). */
|
|
541
|
-
function uniqueSystemFonts(fonts) {
|
|
542
|
-
const byFamily = /* @__PURE__ */ new Map();
|
|
543
|
-
for (const item of fonts) {
|
|
544
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
545
|
-
const record = item;
|
|
546
|
-
const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
|
|
547
|
-
if (!family || byFamily.has(family)) continue;
|
|
548
|
-
const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
|
|
549
|
-
byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
|
|
550
|
-
}
|
|
551
|
-
return [...byFamily.entries()].map(([family, fullName]) => ({
|
|
552
|
-
family,
|
|
553
|
-
fullName
|
|
554
|
-
})).sort((a, b) => a.family.localeCompare(b.family));
|
|
555
|
-
}
|
|
556
|
-
/** Picker label: the UI locale's recognizable name leads, the alias stays in
|
|
557
|
-
* parentheses because the canonical family is still what a custom input needs. */
|
|
558
|
-
function systemFontLabel(item, locale) {
|
|
559
|
-
if (!item.fullName) return item.family;
|
|
560
|
-
return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
|
|
561
|
-
}
|
|
562
|
-
/** Root inline overrides preserve the existing local persistence/unload
|
|
563
|
-
* boundary. Save the underlying value (including !important) on first write
|
|
564
|
-
* or when the host replaces a value, and never retract somebody else's write. */
|
|
565
|
-
function createFontSettingsOverride(style) {
|
|
566
|
-
const owned = /* @__PURE__ */ new Map();
|
|
567
|
-
function release(name) {
|
|
568
|
-
const entry = owned.get(name);
|
|
569
|
-
if (!entry) return;
|
|
570
|
-
if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === "") {
|
|
571
|
-
if (entry.previous) style.setProperty(name, entry.previous, entry.priority);
|
|
572
|
-
else style.removeProperty(name);
|
|
573
|
-
}
|
|
574
|
-
owned.delete(name);
|
|
575
|
-
}
|
|
576
|
-
return {
|
|
577
|
-
apply(settings) {
|
|
578
|
-
for (const [name, value] of [[UI_FONT_VARIABLE, settings.uiFont], [CODE_FONT_VARIABLE, settings.codeFont]]) {
|
|
579
|
-
if (!value) {
|
|
580
|
-
release(name);
|
|
581
|
-
continue;
|
|
582
|
-
}
|
|
583
|
-
const current = style.getPropertyValue(name);
|
|
584
|
-
const priority = style.getPropertyPriority(name);
|
|
585
|
-
const entry = owned.get(name);
|
|
586
|
-
if (!entry || current !== entry.value || priority !== "") owned.set(name, {
|
|
587
|
-
previous: current,
|
|
588
|
-
priority,
|
|
589
|
-
value: ""
|
|
590
|
-
});
|
|
591
|
-
style.setProperty(name, value);
|
|
592
|
-
owned.get(name).value = style.getPropertyValue(name);
|
|
593
|
-
}
|
|
594
|
-
},
|
|
595
|
-
dispose() {
|
|
596
|
-
for (const name of [...owned.keys()]) release(name);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
/** Browser-local persistence. A fully-default setting removes the key so a
|
|
601
|
-
* reset leaves no residue; storage failures (private mode, quota) degrade to
|
|
602
|
-
* in-memory behaviour rather than breaking the panel. */
|
|
603
|
-
function createFontSettingsStore(storage) {
|
|
604
|
-
let current = defaultFontSettings();
|
|
605
|
-
let pendingPersistence = false;
|
|
606
|
-
return {
|
|
607
|
-
load() {
|
|
608
|
-
if (storage && !pendingPersistence) try {
|
|
609
|
-
current = parseFontSettings(storage.getItem(STORAGE_KEY));
|
|
610
|
-
} catch {}
|
|
611
|
-
return { ...current };
|
|
612
|
-
},
|
|
613
|
-
save(next) {
|
|
614
|
-
current = parseFontSettings(next);
|
|
615
|
-
if (!storage) return;
|
|
616
|
-
pendingPersistence = true;
|
|
617
|
-
try {
|
|
618
|
-
if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
|
|
619
|
-
else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
|
|
620
|
-
pendingPersistence = false;
|
|
621
|
-
} catch {}
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
//#endregion
|
|
626
626
|
//#region src/client.tsx
|
|
627
627
|
const name = "dsh-font-client";
|
|
628
628
|
const inject = [
|
|
@@ -641,7 +641,7 @@ const COPY = {
|
|
|
641
641
|
customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
|
|
642
642
|
customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
|
|
643
643
|
uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
|
|
644
|
-
codeHelp: "
|
|
644
|
+
codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
|
|
645
645
|
sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
|
|
646
646
|
loadFonts: "读取系统字体",
|
|
647
647
|
reloadFonts: "重新读取系统字体",
|
|
@@ -664,7 +664,7 @@ const COPY = {
|
|
|
664
664
|
customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
|
|
665
665
|
customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
|
|
666
666
|
uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
|
|
667
|
-
codeHelp: "
|
|
667
|
+
codeHelp: "Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.",
|
|
668
668
|
sizeHelp: "Synced with Settings → General; 10–22 px.",
|
|
669
669
|
loadFonts: "Load system fonts",
|
|
670
670
|
reloadFonts: "Reload system fonts",
|
|
@@ -697,7 +697,7 @@ function useLocale(client) {
|
|
|
697
697
|
return (0, react.useSyncExternalStore)((fn) => client.locale.subscribe(fn), getSnapshot, getSnapshot);
|
|
698
698
|
}
|
|
699
699
|
function useFontSize(client) {
|
|
700
|
-
return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().
|
|
700
|
+
return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().fontSizes.text, () => client.theme.getTheme().fontSizes.text);
|
|
701
701
|
}
|
|
702
702
|
function presetMode(value, presets) {
|
|
703
703
|
return presetFor(value, presets)?.id ?? (value ? "custom" : "");
|
|
@@ -782,7 +782,11 @@ function FontField(props) {
|
|
|
782
782
|
function FontSettingsPanel(props) {
|
|
783
783
|
const locale = useLocale(props.client);
|
|
784
784
|
const text = COPY[locale];
|
|
785
|
-
const
|
|
785
|
+
const families = (0, react.useSyncExternalStore)((fn) => props.client.on("theme/change", () => fn()), () => props.client.theme.getTheme().fontFamilies, () => props.client.theme.getTheme().fontFamilies);
|
|
786
|
+
const settings = {
|
|
787
|
+
uiFont: families.text,
|
|
788
|
+
codeFont: families.code
|
|
789
|
+
};
|
|
786
790
|
const fontSize = useFontSize(props.client);
|
|
787
791
|
const [fontList, setFontList] = (0, react.useState)({
|
|
788
792
|
state: "idle",
|
|
@@ -816,13 +820,8 @@ function FontSettingsPanel(props) {
|
|
|
816
820
|
}
|
|
817
821
|
}
|
|
818
822
|
function update(patch) {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
codeFont: normalizeFontFamily(patch.codeFont ?? settings.codeFont)
|
|
822
|
-
};
|
|
823
|
-
props.store.save(next);
|
|
824
|
-
props.applySettings(next);
|
|
825
|
-
setSettings(next);
|
|
823
|
+
if (patch.uiFont !== void 0) props.client.theme.setFontFamily("text", normalizeFontFamily(patch.uiFont));
|
|
824
|
+
if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
|
|
826
825
|
}
|
|
827
826
|
const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
|
|
828
827
|
const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
|
|
@@ -878,7 +877,7 @@ function FontSettingsPanel(props) {
|
|
|
878
877
|
onChange: (event) => {
|
|
879
878
|
const px = Number(event.target.value);
|
|
880
879
|
if (Number.isInteger(px) && px >= 10 && px <= 22 && px !== fontSize) try {
|
|
881
|
-
props.client.theme.setFontSize(px);
|
|
880
|
+
props.client.theme.setFontSize("text", px);
|
|
882
881
|
} catch {}
|
|
883
882
|
},
|
|
884
883
|
children: sizes.map((px) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
|
|
@@ -910,7 +909,7 @@ function FontSettingsPanel(props) {
|
|
|
910
909
|
uiFont: "",
|
|
911
910
|
codeFont: ""
|
|
912
911
|
});
|
|
913
|
-
if (fontSize !== 14) props.client.theme.setFontSize(14);
|
|
912
|
+
if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
|
|
914
913
|
},
|
|
915
914
|
children: text.reset
|
|
916
915
|
})]
|
|
@@ -936,7 +935,7 @@ function FontSettingsPanel(props) {
|
|
|
936
935
|
function apply(ctx) {
|
|
937
936
|
const client = ctx;
|
|
938
937
|
const store = createFontSettingsStore(readStorage());
|
|
939
|
-
|
|
938
|
+
migrateFontPreferences(client.theme, store, readStorage());
|
|
940
939
|
ctx.effect(() => {
|
|
941
940
|
if (typeof document === "undefined") return () => {};
|
|
942
941
|
const style = document.createElement("style");
|
|
@@ -945,23 +944,11 @@ function apply(ctx) {
|
|
|
945
944
|
document.head.appendChild(style);
|
|
946
945
|
return () => style.remove();
|
|
947
946
|
}, "font.styles");
|
|
948
|
-
ctx.effect(() => {
|
|
949
|
-
if (typeof document === "undefined") return () => {};
|
|
950
|
-
const override = createFontSettingsOverride(document.documentElement.style);
|
|
951
|
-
applySettings = (next) => override.apply(next);
|
|
952
|
-
applySettings(store.load());
|
|
953
|
-
return () => {
|
|
954
|
-
override.dispose();
|
|
955
|
-
applySettings = () => {};
|
|
956
|
-
};
|
|
957
|
-
}, "font.apply");
|
|
958
947
|
ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
|
|
959
948
|
name: "plugins.bundle.config",
|
|
960
949
|
key: PLUGIN_NAME
|
|
961
950
|
}, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
|
|
962
951
|
client,
|
|
963
|
-
store,
|
|
964
|
-
applySettings: (next) => applySettings(next),
|
|
965
952
|
view: slotProps?.view
|
|
966
953
|
}))), "font.settings");
|
|
967
954
|
}
|