@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/lib/client.js CHANGED
@@ -8,6 +8,231 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
9
  let react = require("react");
10
10
  let react_jsx_runtime = require("react/jsx-runtime");
11
+ //#region src/contracts.ts
12
+ /** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
13
+ * normalization, the CSS-variable application core, and the local store.
14
+ * No React, no cordis — every export runs in Node tests and the browser. */
15
+ const PLUGIN_NAME = "@klarkxy/dsh-font";
16
+ /** Legacy browser-local font choices, retained as the one-time migration backup.
17
+ * The active panel reads and writes the host's role-specific preferences. */
18
+ const STORAGE_KEY = "klarkxy.dsh-font.v1";
19
+ function defaultFontSettings() {
20
+ return {
21
+ uiFont: "",
22
+ codeFont: ""
23
+ };
24
+ }
25
+ /** A raw font-family string is placed into a single CSS declaration via
26
+ * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
27
+ * trimming control characters and the CSS delimiters keeps pasted garbage from
28
+ * producing a silently-dead value. */
29
+ function normalizeFontFamily(value) {
30
+ if (typeof value !== "string") return "";
31
+ return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
32
+ }
33
+ function parseFontSettings(raw) {
34
+ let source = raw;
35
+ if (typeof source === "string") try {
36
+ source = JSON.parse(source);
37
+ } catch {
38
+ return defaultFontSettings();
39
+ }
40
+ if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
41
+ const record = source;
42
+ return {
43
+ uiFont: normalizeFontFamily(record.uiFont),
44
+ codeFont: normalizeFontFamily(record.codeFont)
45
+ };
46
+ }
47
+ function serializeFontSettings(settings) {
48
+ return JSON.stringify({
49
+ uiFont: normalizeFontFamily(settings.uiFont),
50
+ codeFont: normalizeFontFamily(settings.codeFont)
51
+ });
52
+ }
53
+ const UI_FONT_PRESETS = [
54
+ {
55
+ id: "yahei",
56
+ label: {
57
+ zh: "微软雅黑",
58
+ en: "Microsoft YaHei"
59
+ },
60
+ value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
61
+ },
62
+ {
63
+ id: "pingfang",
64
+ label: {
65
+ zh: "苹方",
66
+ en: "PingFang SC"
67
+ },
68
+ value: "\"PingFang SC\", -apple-system, sans-serif"
69
+ },
70
+ {
71
+ id: "simsun",
72
+ label: {
73
+ zh: "宋体",
74
+ en: "SimSun"
75
+ },
76
+ value: "\"SimSun\", \"Songti SC\", serif"
77
+ },
78
+ {
79
+ id: "kaiti",
80
+ label: {
81
+ zh: "楷体",
82
+ en: "KaiTi"
83
+ },
84
+ value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
85
+ },
86
+ {
87
+ id: "source-han-sans",
88
+ label: {
89
+ zh: "思源黑体",
90
+ en: "Source Han Sans"
91
+ },
92
+ value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
93
+ },
94
+ {
95
+ id: "source-han-serif",
96
+ label: {
97
+ zh: "思源宋体",
98
+ en: "Source Han Serif"
99
+ },
100
+ value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
101
+ }
102
+ ];
103
+ const CODE_FONT_PRESETS = [
104
+ {
105
+ id: "cascadia",
106
+ label: {
107
+ zh: "Cascadia",
108
+ en: "Cascadia"
109
+ },
110
+ value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
111
+ },
112
+ {
113
+ id: "jetbrains-mono",
114
+ label: {
115
+ zh: "JetBrains Mono",
116
+ en: "JetBrains Mono"
117
+ },
118
+ value: "\"JetBrains Mono\", monospace"
119
+ },
120
+ {
121
+ id: "fira-code",
122
+ label: {
123
+ zh: "Fira Code",
124
+ en: "Fira Code"
125
+ },
126
+ value: "\"Fira Code\", monospace"
127
+ },
128
+ {
129
+ id: "consolas",
130
+ label: {
131
+ zh: "Consolas",
132
+ en: "Consolas"
133
+ },
134
+ value: "Consolas, monospace"
135
+ },
136
+ {
137
+ id: "sarasa",
138
+ label: {
139
+ zh: "更纱黑体",
140
+ en: "Sarasa Mono"
141
+ },
142
+ value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
143
+ },
144
+ {
145
+ id: "maple-mono",
146
+ label: {
147
+ zh: "Maple Mono",
148
+ en: "Maple Mono"
149
+ },
150
+ value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
151
+ }
152
+ ];
153
+ function presetFor(value, presets) {
154
+ const comparable = (stack) => stack.split(",").map((name) => name.trim().replace(/^["']|["']$/g, "")).join(",");
155
+ return presets.find((preset) => comparable(preset.value) === comparable(value));
156
+ }
157
+ /** Build the committed stack for a family picked from the system font list.
158
+ * The family name comes from the OS (Local Font Access API); quotes and
159
+ * backslashes are stripped so it can be safely re-quoted as one family. */
160
+ function fontStackFor(family, generic) {
161
+ const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
162
+ if (!cleaned) return generic;
163
+ return `"${cleaned}", ${generic}`;
164
+ }
165
+ /** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
166
+ * result (entries carry `family` and `fullName`; duplicates per style are
167
+ * expected). */
168
+ function uniqueSystemFonts(fonts) {
169
+ const byFamily = /* @__PURE__ */ new Map();
170
+ for (const item of fonts) {
171
+ if (!item || typeof item !== "object" || Array.isArray(item)) continue;
172
+ const record = item;
173
+ const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
174
+ if (!family || byFamily.has(family)) continue;
175
+ const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
176
+ byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
177
+ }
178
+ return [...byFamily.entries()].map(([family, fullName]) => ({
179
+ family,
180
+ fullName
181
+ })).sort((a, b) => a.family.localeCompare(b.family));
182
+ }
183
+ /** Picker label: the UI locale's recognizable name leads, the alias stays in
184
+ * parentheses because the canonical family is still what a custom input needs. */
185
+ function systemFontLabel(item, locale) {
186
+ if (!item.fullName) return item.family;
187
+ return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
188
+ }
189
+ /** Browser-local persistence. A fully-default setting removes the key so a
190
+ * reset leaves no residue; storage failures (private mode, quota) degrade to
191
+ * in-memory behaviour rather than breaking the panel. */
192
+ function createFontSettingsStore(storage) {
193
+ let current = defaultFontSettings();
194
+ let pendingPersistence = false;
195
+ return {
196
+ load() {
197
+ if (storage && !pendingPersistence) try {
198
+ current = parseFontSettings(storage.getItem(STORAGE_KEY));
199
+ } catch {}
200
+ return { ...current };
201
+ },
202
+ save(next) {
203
+ current = parseFontSettings(next);
204
+ if (!storage) return;
205
+ pendingPersistence = true;
206
+ try {
207
+ if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
208
+ else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
209
+ pendingPersistence = false;
210
+ } catch {}
211
+ }
212
+ };
213
+ }
214
+ //#endregion
215
+ //#region src/preferences.ts
216
+ const MIGRATION_KEY = "klarkxy.dsh-font.host-preferences.v1";
217
+ /** Preserve the old selection as a backup, but never replay it over native
218
+ * preferences on subsequent loads. Each role migrates independently. */
219
+ function migrateFontPreferences(theme, store, storage) {
220
+ try {
221
+ if (storage?.getItem("klarkxy.dsh-font.host-preferences.v1")) return;
222
+ } catch {
223
+ return;
224
+ }
225
+ const old = store.load();
226
+ const families = theme.getTheme().fontFamilies;
227
+ for (const [role, value] of [
228
+ ["text", old.uiFont],
229
+ ["code", old.codeFont],
230
+ ["terminal", old.codeFont]
231
+ ]) if (!families[role] && normalizeFontFamily(value)) theme.setFontFamily(role, value);
232
+ try {
233
+ storage?.setItem(MIGRATION_KEY, "1");
234
+ } catch {}
235
+ }
11
236
  Object.values({
12
237
  /** Surfaces, from the page up to the topmost nested card. */
13
238
  surface: [
@@ -370,6 +595,29 @@ ${scope} {
370
595
  & .dsh-ui-select:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }
371
596
  & .dsh-ui-select[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
372
597
 
598
+ /* --- Native textarea. The primitives ship no textarea either, so a settings
599
+ * prompt keeps the platform element and the same field shell as the select:
600
+ * 0.5px l4, radius-md, layer-3, 13/1.5 type. It grows vertically instead of
601
+ * locking to the select's 34px row. --- */
602
+ & .dsh-ui-textarea {
603
+ box-sizing: border-box;
604
+ width: 100%;
605
+ min-width: 0;
606
+ resize: vertical;
607
+ padding: 8px 12px;
608
+ border: 0.5px solid var(--dsw-alias-border-l4);
609
+ border-radius: var(--dsw-radius-md);
610
+ background: var(--dsw-alias-bg-layer-3);
611
+ font: inherit;
612
+ font-size: 13px;
613
+ line-height: 1.5;
614
+ color: var(--dsw-alias-label-primary);
615
+ }
616
+ & .dsh-ui-textarea:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }
617
+ & .dsh-ui-textarea:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }
618
+ & .dsh-ui-textarea::placeholder { color: var(--dsw-alias-label-dimmed); }
619
+ & .dsh-ui-textarea[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
620
+
373
621
  /* Long panels scroll inside themselves instead of growing the host page. */
374
622
  & .dsh-ui-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
375
623
  & .dsh-ui-panel-wide { max-width: 100%; }
@@ -381,254 +629,6 @@ ${scope} {
381
629
  `.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?![+>~])/gm, (_match, className) => `&${className}, & ${className}`);
382
630
  }
383
631
  //#endregion
384
- //#region src/contracts.ts
385
- /** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
386
- * normalization, the CSS-variable application core, and the local store.
387
- * No React, no cordis — every export runs in Node tests and the browser. */
388
- const PLUGIN_NAME = "@klarkxy/dsh-font";
389
- /** localStorage key. Fonts are a property of the rendering environment (each
390
- * browser/machine has its own installed fonts), so they persist browser-local,
391
- * exactly like the host's own GUI preferences (dsh-client-store, ui-theme
392
- * notes). The conversation font size is NOT stored here: the official
393
- * `ctx.theme.setFontSize()` entry persists it host-side already. */
394
- const STORAGE_KEY = "klarkxy.dsh-font.v1";
395
- /** DSH rc.2 defines these font stacks on :root. Root inline overrides also
396
- * reach derived Markdown, brand and terminal font tokens. */
397
- const UI_FONT_VARIABLE = "--dsw-font-family";
398
- const CODE_FONT_VARIABLE = "--ds-font-family-code";
399
- function defaultFontSettings() {
400
- return {
401
- uiFont: "",
402
- codeFont: ""
403
- };
404
- }
405
- /** A raw font-family string is placed into a single CSS declaration via
406
- * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
407
- * trimming control characters and the CSS delimiters keeps pasted garbage from
408
- * producing a silently-dead value. */
409
- function normalizeFontFamily(value) {
410
- if (typeof value !== "string") return "";
411
- return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
412
- }
413
- function parseFontSettings(raw) {
414
- let source = raw;
415
- if (typeof source === "string") try {
416
- source = JSON.parse(source);
417
- } catch {
418
- return defaultFontSettings();
419
- }
420
- if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
421
- const record = source;
422
- return {
423
- uiFont: normalizeFontFamily(record.uiFont),
424
- codeFont: normalizeFontFamily(record.codeFont)
425
- };
426
- }
427
- function serializeFontSettings(settings) {
428
- return JSON.stringify({
429
- uiFont: normalizeFontFamily(settings.uiFont),
430
- codeFont: normalizeFontFamily(settings.codeFont)
431
- });
432
- }
433
- const UI_FONT_PRESETS = [
434
- {
435
- id: "yahei",
436
- label: {
437
- zh: "微软雅黑",
438
- en: "Microsoft YaHei"
439
- },
440
- value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
441
- },
442
- {
443
- id: "pingfang",
444
- label: {
445
- zh: "苹方",
446
- en: "PingFang SC"
447
- },
448
- value: "\"PingFang SC\", -apple-system, sans-serif"
449
- },
450
- {
451
- id: "simsun",
452
- label: {
453
- zh: "宋体",
454
- en: "SimSun"
455
- },
456
- value: "\"SimSun\", \"Songti SC\", serif"
457
- },
458
- {
459
- id: "kaiti",
460
- label: {
461
- zh: "楷体",
462
- en: "KaiTi"
463
- },
464
- value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
465
- },
466
- {
467
- id: "source-han-sans",
468
- label: {
469
- zh: "思源黑体",
470
- en: "Source Han Sans"
471
- },
472
- value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
473
- },
474
- {
475
- id: "source-han-serif",
476
- label: {
477
- zh: "思源宋体",
478
- en: "Source Han Serif"
479
- },
480
- value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
481
- }
482
- ];
483
- const CODE_FONT_PRESETS = [
484
- {
485
- id: "cascadia",
486
- label: {
487
- zh: "Cascadia",
488
- en: "Cascadia"
489
- },
490
- value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
491
- },
492
- {
493
- id: "jetbrains-mono",
494
- label: {
495
- zh: "JetBrains Mono",
496
- en: "JetBrains Mono"
497
- },
498
- value: "\"JetBrains Mono\", monospace"
499
- },
500
- {
501
- id: "fira-code",
502
- label: {
503
- zh: "Fira Code",
504
- en: "Fira Code"
505
- },
506
- value: "\"Fira Code\", monospace"
507
- },
508
- {
509
- id: "consolas",
510
- label: {
511
- zh: "Consolas",
512
- en: "Consolas"
513
- },
514
- value: "Consolas, monospace"
515
- },
516
- {
517
- id: "sarasa",
518
- label: {
519
- zh: "更纱黑体",
520
- en: "Sarasa Mono"
521
- },
522
- value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
523
- },
524
- {
525
- id: "maple-mono",
526
- label: {
527
- zh: "Maple Mono",
528
- en: "Maple Mono"
529
- },
530
- value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
531
- }
532
- ];
533
- function presetFor(value, presets) {
534
- return presets.find((preset) => preset.value === value);
535
- }
536
- /** Build the committed stack for a family picked from the system font list.
537
- * The family name comes from the OS (Local Font Access API); quotes and
538
- * backslashes are stripped so it can be safely re-quoted as one family. */
539
- function fontStackFor(family, generic) {
540
- const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
541
- if (!cleaned) return generic;
542
- return `"${cleaned}", ${generic}`;
543
- }
544
- /** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
545
- * result (entries carry `family` and `fullName`; duplicates per style are
546
- * expected). */
547
- function uniqueSystemFonts(fonts) {
548
- const byFamily = /* @__PURE__ */ new Map();
549
- for (const item of fonts) {
550
- if (!item || typeof item !== "object" || Array.isArray(item)) continue;
551
- const record = item;
552
- const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
553
- if (!family || byFamily.has(family)) continue;
554
- const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
555
- byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
556
- }
557
- return [...byFamily.entries()].map(([family, fullName]) => ({
558
- family,
559
- fullName
560
- })).sort((a, b) => a.family.localeCompare(b.family));
561
- }
562
- /** Picker label: the UI locale's recognizable name leads, the alias stays in
563
- * parentheses because the canonical family is still what a custom input needs. */
564
- function systemFontLabel(item, locale) {
565
- if (!item.fullName) return item.family;
566
- return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
567
- }
568
- /** Root inline overrides preserve the existing local persistence/unload
569
- * boundary. Save the underlying value (including !important) on first write
570
- * or when the host replaces a value, and never retract somebody else's write. */
571
- function createFontSettingsOverride(style) {
572
- const owned = /* @__PURE__ */ new Map();
573
- function release(name) {
574
- const entry = owned.get(name);
575
- if (!entry) return;
576
- if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === "") {
577
- if (entry.previous) style.setProperty(name, entry.previous, entry.priority);
578
- else style.removeProperty(name);
579
- }
580
- owned.delete(name);
581
- }
582
- return {
583
- apply(settings) {
584
- for (const [name, value] of [[UI_FONT_VARIABLE, settings.uiFont], [CODE_FONT_VARIABLE, settings.codeFont]]) {
585
- if (!value) {
586
- release(name);
587
- continue;
588
- }
589
- const current = style.getPropertyValue(name);
590
- const priority = style.getPropertyPriority(name);
591
- const entry = owned.get(name);
592
- if (!entry || current !== entry.value || priority !== "") owned.set(name, {
593
- previous: current,
594
- priority,
595
- value: ""
596
- });
597
- style.setProperty(name, value);
598
- owned.get(name).value = style.getPropertyValue(name);
599
- }
600
- },
601
- dispose() {
602
- for (const name of [...owned.keys()]) release(name);
603
- }
604
- };
605
- }
606
- /** Browser-local persistence. A fully-default setting removes the key so a
607
- * reset leaves no residue; storage failures (private mode, quota) degrade to
608
- * in-memory behaviour rather than breaking the panel. */
609
- function createFontSettingsStore(storage) {
610
- let current = defaultFontSettings();
611
- let pendingPersistence = false;
612
- return {
613
- load() {
614
- if (storage && !pendingPersistence) try {
615
- current = parseFontSettings(storage.getItem(STORAGE_KEY));
616
- } catch {}
617
- return { ...current };
618
- },
619
- save(next) {
620
- current = parseFontSettings(next);
621
- if (!storage) return;
622
- pendingPersistence = true;
623
- try {
624
- if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
625
- else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
626
- pendingPersistence = false;
627
- } catch {}
628
- }
629
- };
630
- }
631
- //#endregion
632
632
  //#region src/client.tsx
633
633
  const name = "dsh-font-client";
634
634
  const inject = [
@@ -647,7 +647,7 @@ const COPY = {
647
647
  customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
648
648
  customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
649
649
  uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
650
- codeHelp: "作用于代码块、行内代码与终端的等宽字体。",
650
+ codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
651
651
  sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
652
652
  loadFonts: "读取系统字体",
653
653
  reloadFonts: "重新读取系统字体",
@@ -670,7 +670,7 @@ const COPY = {
670
670
  customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
671
671
  customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
672
672
  uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
673
- codeHelp: "Monospace font for code blocks, inline code and terminals.",
673
+ codeHelp: "Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.",
674
674
  sizeHelp: "Synced with Settings → General; 10–22 px.",
675
675
  loadFonts: "Load system fonts",
676
676
  reloadFonts: "Reload system fonts",
@@ -703,7 +703,7 @@ function useLocale(client) {
703
703
  return (0, react.useSyncExternalStore)((fn) => client.locale.subscribe(fn), getSnapshot, getSnapshot);
704
704
  }
705
705
  function useFontSize(client) {
706
- return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().fontSize, () => client.theme.getTheme().fontSize);
706
+ return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().fontSizes.text, () => client.theme.getTheme().fontSizes.text);
707
707
  }
708
708
  function presetMode(value, presets) {
709
709
  return presetFor(value, presets)?.id ?? (value ? "custom" : "");
@@ -788,7 +788,11 @@ function FontField(props) {
788
788
  function FontSettingsPanel(props) {
789
789
  const locale = useLocale(props.client);
790
790
  const text = COPY[locale];
791
- const [settings, setSettings] = (0, react.useState)(() => props.store.load());
791
+ const families = (0, react.useSyncExternalStore)((fn) => props.client.on("theme/change", () => fn()), () => props.client.theme.getTheme().fontFamilies, () => props.client.theme.getTheme().fontFamilies);
792
+ const settings = {
793
+ uiFont: families.text,
794
+ codeFont: families.code
795
+ };
792
796
  const fontSize = useFontSize(props.client);
793
797
  const [fontList, setFontList] = (0, react.useState)({
794
798
  state: "idle",
@@ -822,13 +826,8 @@ function FontSettingsPanel(props) {
822
826
  }
823
827
  }
824
828
  function update(patch) {
825
- const next = {
826
- uiFont: normalizeFontFamily(patch.uiFont ?? settings.uiFont),
827
- codeFont: normalizeFontFamily(patch.codeFont ?? settings.codeFont)
828
- };
829
- props.store.save(next);
830
- props.applySettings(next);
831
- setSettings(next);
829
+ if (patch.uiFont !== void 0) props.client.theme.setFontFamily("text", normalizeFontFamily(patch.uiFont));
830
+ if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
832
831
  }
833
832
  const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
834
833
  const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
@@ -884,7 +883,7 @@ function FontSettingsPanel(props) {
884
883
  onChange: (event) => {
885
884
  const px = Number(event.target.value);
886
885
  if (Number.isInteger(px) && px >= 10 && px <= 22 && px !== fontSize) try {
887
- props.client.theme.setFontSize(px);
886
+ props.client.theme.setFontSize("text", px);
888
887
  } catch {}
889
888
  },
890
889
  children: sizes.map((px) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
@@ -916,7 +915,7 @@ function FontSettingsPanel(props) {
916
915
  uiFont: "",
917
916
  codeFont: ""
918
917
  });
919
- if (fontSize !== 14) props.client.theme.setFontSize(14);
918
+ if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
920
919
  },
921
920
  children: text.reset
922
921
  })]
@@ -942,7 +941,7 @@ function FontSettingsPanel(props) {
942
941
  function apply(ctx) {
943
942
  const client = ctx;
944
943
  const store = createFontSettingsStore(readStorage());
945
- let applySettings = (_settings) => {};
944
+ migrateFontPreferences(client.theme, store, readStorage());
946
945
  ctx.effect(() => {
947
946
  if (typeof document === "undefined") return () => {};
948
947
  const style = document.createElement("style");
@@ -951,23 +950,11 @@ function apply(ctx) {
951
950
  document.head.appendChild(style);
952
951
  return () => style.remove();
953
952
  }, "font.styles");
954
- ctx.effect(() => {
955
- if (typeof document === "undefined") return () => {};
956
- const override = createFontSettingsOverride(document.documentElement.style);
957
- applySettings = (next) => override.apply(next);
958
- applySettings(store.load());
959
- return () => {
960
- override.dispose();
961
- applySettings = () => {};
962
- };
963
- }, "font.apply");
964
953
  ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
965
954
  name: "plugins.bundle.config",
966
955
  key: PLUGIN_NAME
967
956
  }, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
968
957
  client,
969
- store,
970
- applySettings: (next) => applySettings(next),
971
958
  view: slotProps?.view
972
959
  }))), "font.settings");
973
960
  }
@@ -3,13 +3,10 @@
3
3
  * normalization, the CSS-variable application core, and the local store.
4
4
  * No React, no cordis — every export runs in Node tests and the browser. */
5
5
  declare const PLUGIN_NAME = "@klarkxy/dsh-font";
6
- /** localStorage key. Fonts are a property of the rendering environment (each
7
- * browser/machine has its own installed fonts), so they persist browser-local,
8
- * exactly like the host's own GUI preferences (dsh-client-store, ui-theme
9
- * notes). The conversation font size is NOT stored here: the official
10
- * `ctx.theme.setFontSize()` entry persists it host-side already. */
6
+ /** Legacy browser-local font choices, retained as the one-time migration backup.
7
+ * The active panel reads and writes the host's role-specific preferences. */
11
8
  declare const STORAGE_KEY = "klarkxy.dsh-font.v1";
12
- /** DSH 0.2.0-rc.2 ui-theme/theme-settings.ts bounds, shared by its native stepper. */
9
+ /** Host text-role bounds, shared by the native conversation-size stepper. */
13
10
  declare const FONT_SIZE_MIN = 10;
14
11
  declare const FONT_SIZE_MAX = 22;
15
12
  declare const FONT_SIZE_DEFAULT = 14;
package/lib/contracts.js CHANGED
@@ -3,13 +3,10 @@
3
3
  * normalization, the CSS-variable application core, and the local store.
4
4
  * No React, no cordis — every export runs in Node tests and the browser. */
5
5
  const PLUGIN_NAME = "@klarkxy/dsh-font";
6
- /** localStorage key. Fonts are a property of the rendering environment (each
7
- * browser/machine has its own installed fonts), so they persist browser-local,
8
- * exactly like the host's own GUI preferences (dsh-client-store, ui-theme
9
- * notes). The conversation font size is NOT stored here: the official
10
- * `ctx.theme.setFontSize()` entry persists it host-side already. */
6
+ /** Legacy browser-local font choices, retained as the one-time migration backup.
7
+ * The active panel reads and writes the host's role-specific preferences. */
11
8
  const STORAGE_KEY = "klarkxy.dsh-font.v1";
12
- /** DSH 0.2.0-rc.2 ui-theme/theme-settings.ts bounds, shared by its native stepper. */
9
+ /** Host text-role bounds, shared by the native conversation-size stepper. */
13
10
  const FONT_SIZE_MIN = 10;
14
11
  const FONT_SIZE_MAX = 22;
15
12
  const FONT_SIZE_DEFAULT = 14;
@@ -152,7 +149,8 @@ const CODE_FONT_PRESETS = [
152
149
  }
153
150
  ];
154
151
  function presetFor(value, presets) {
155
- return presets.find((preset) => preset.value === value);
152
+ const comparable = (stack) => stack.split(",").map((name) => name.trim().replace(/^["']|["']$/g, "")).join(",");
153
+ return presets.find((preset) => comparable(preset.value) === comparable(value));
156
154
  }
157
155
  /** Build the committed stack for a family picked from the system font list.
158
156
  * The family name comes from the OS (Local Font Access API); quotes and