@klarkxy/dsh-font 0.1.3 → 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: [
@@ -404,254 +629,6 @@ ${scope} {
404
629
  `.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?![+>~])/gm, (_match, className) => `&${className}, & ${className}`);
405
630
  }
406
631
  //#endregion
407
- //#region src/contracts.ts
408
- /** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,
409
- * normalization, the CSS-variable application core, and the local store.
410
- * No React, no cordis — every export runs in Node tests and the browser. */
411
- const PLUGIN_NAME = "@klarkxy/dsh-font";
412
- /** localStorage key. Fonts are a property of the rendering environment (each
413
- * browser/machine has its own installed fonts), so they persist browser-local,
414
- * exactly like the host's own GUI preferences (dsh-client-store, ui-theme
415
- * notes). The conversation font size is NOT stored here: the official
416
- * `ctx.theme.setFontSize()` entry persists it host-side already. */
417
- const STORAGE_KEY = "klarkxy.dsh-font.v1";
418
- /** DSH rc.2 defines these font stacks on :root. Root inline overrides also
419
- * reach derived Markdown, brand and terminal font tokens. */
420
- const UI_FONT_VARIABLE = "--dsw-font-family";
421
- const CODE_FONT_VARIABLE = "--ds-font-family-code";
422
- function defaultFontSettings() {
423
- return {
424
- uiFont: "",
425
- codeFont: ""
426
- };
427
- }
428
- /** A raw font-family string is placed into a single CSS declaration via
429
- * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but
430
- * trimming control characters and the CSS delimiters keeps pasted garbage from
431
- * producing a silently-dead value. */
432
- function normalizeFontFamily(value) {
433
- if (typeof value !== "string") return "";
434
- return value.replace(/[\u0000-\u001F\u007F;{}<>]/g, "").trim().slice(0, 300);
435
- }
436
- function parseFontSettings(raw) {
437
- let source = raw;
438
- if (typeof source === "string") try {
439
- source = JSON.parse(source);
440
- } catch {
441
- return defaultFontSettings();
442
- }
443
- if (!source || typeof source !== "object" || Array.isArray(source)) return defaultFontSettings();
444
- const record = source;
445
- return {
446
- uiFont: normalizeFontFamily(record.uiFont),
447
- codeFont: normalizeFontFamily(record.codeFont)
448
- };
449
- }
450
- function serializeFontSettings(settings) {
451
- return JSON.stringify({
452
- uiFont: normalizeFontFamily(settings.uiFont),
453
- codeFont: normalizeFontFamily(settings.codeFont)
454
- });
455
- }
456
- const UI_FONT_PRESETS = [
457
- {
458
- id: "yahei",
459
- label: {
460
- zh: "微软雅黑",
461
- en: "Microsoft YaHei"
462
- },
463
- value: "\"Microsoft YaHei\", \"PingFang SC\", sans-serif"
464
- },
465
- {
466
- id: "pingfang",
467
- label: {
468
- zh: "苹方",
469
- en: "PingFang SC"
470
- },
471
- value: "\"PingFang SC\", -apple-system, sans-serif"
472
- },
473
- {
474
- id: "simsun",
475
- label: {
476
- zh: "宋体",
477
- en: "SimSun"
478
- },
479
- value: "\"SimSun\", \"Songti SC\", serif"
480
- },
481
- {
482
- id: "kaiti",
483
- label: {
484
- zh: "楷体",
485
- en: "KaiTi"
486
- },
487
- value: "\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif"
488
- },
489
- {
490
- id: "source-han-sans",
491
- label: {
492
- zh: "思源黑体",
493
- en: "Source Han Sans"
494
- },
495
- value: "\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif"
496
- },
497
- {
498
- id: "source-han-serif",
499
- label: {
500
- zh: "思源宋体",
501
- en: "Source Han Serif"
502
- },
503
- value: "\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif"
504
- }
505
- ];
506
- const CODE_FONT_PRESETS = [
507
- {
508
- id: "cascadia",
509
- label: {
510
- zh: "Cascadia",
511
- en: "Cascadia"
512
- },
513
- value: "\"Cascadia Mono\", \"Cascadia Code\", monospace"
514
- },
515
- {
516
- id: "jetbrains-mono",
517
- label: {
518
- zh: "JetBrains Mono",
519
- en: "JetBrains Mono"
520
- },
521
- value: "\"JetBrains Mono\", monospace"
522
- },
523
- {
524
- id: "fira-code",
525
- label: {
526
- zh: "Fira Code",
527
- en: "Fira Code"
528
- },
529
- value: "\"Fira Code\", monospace"
530
- },
531
- {
532
- id: "consolas",
533
- label: {
534
- zh: "Consolas",
535
- en: "Consolas"
536
- },
537
- value: "Consolas, monospace"
538
- },
539
- {
540
- id: "sarasa",
541
- label: {
542
- zh: "更纱黑体",
543
- en: "Sarasa Mono"
544
- },
545
- value: "\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace"
546
- },
547
- {
548
- id: "maple-mono",
549
- label: {
550
- zh: "Maple Mono",
551
- en: "Maple Mono"
552
- },
553
- value: "\"Maple Mono NF CN\", \"Maple Mono\", monospace"
554
- }
555
- ];
556
- function presetFor(value, presets) {
557
- return presets.find((preset) => preset.value === value);
558
- }
559
- /** Build the committed stack for a family picked from the system font list.
560
- * The family name comes from the OS (Local Font Access API); quotes and
561
- * backslashes are stripped so it can be safely re-quoted as one family. */
562
- function fontStackFor(family, generic) {
563
- const cleaned = normalizeFontFamily(family).replace(/["\\]/g, "");
564
- if (!cleaned) return generic;
565
- return `"${cleaned}", ${generic}`;
566
- }
567
- /** Distinct, normalized, family-sorted entries out of a queryLocalFonts()
568
- * result (entries carry `family` and `fullName`; duplicates per style are
569
- * expected). */
570
- function uniqueSystemFonts(fonts) {
571
- const byFamily = /* @__PURE__ */ new Map();
572
- for (const item of fonts) {
573
- if (!item || typeof item !== "object" || Array.isArray(item)) continue;
574
- const record = item;
575
- const family = normalizeFontFamily(record.family).replace(/["\\]/g, "");
576
- if (!family || byFamily.has(family)) continue;
577
- const fullName = normalizeFontFamily(record.fullName).replace(/["\\]/g, "");
578
- byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : "");
579
- }
580
- return [...byFamily.entries()].map(([family, fullName]) => ({
581
- family,
582
- fullName
583
- })).sort((a, b) => a.family.localeCompare(b.family));
584
- }
585
- /** Picker label: the UI locale's recognizable name leads, the alias stays in
586
- * parentheses because the canonical family is still what a custom input needs. */
587
- function systemFontLabel(item, locale) {
588
- if (!item.fullName) return item.family;
589
- return locale === "zh" ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`;
590
- }
591
- /** Root inline overrides preserve the existing local persistence/unload
592
- * boundary. Save the underlying value (including !important) on first write
593
- * or when the host replaces a value, and never retract somebody else's write. */
594
- function createFontSettingsOverride(style) {
595
- const owned = /* @__PURE__ */ new Map();
596
- function release(name) {
597
- const entry = owned.get(name);
598
- if (!entry) return;
599
- if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === "") {
600
- if (entry.previous) style.setProperty(name, entry.previous, entry.priority);
601
- else style.removeProperty(name);
602
- }
603
- owned.delete(name);
604
- }
605
- return {
606
- apply(settings) {
607
- for (const [name, value] of [[UI_FONT_VARIABLE, settings.uiFont], [CODE_FONT_VARIABLE, settings.codeFont]]) {
608
- if (!value) {
609
- release(name);
610
- continue;
611
- }
612
- const current = style.getPropertyValue(name);
613
- const priority = style.getPropertyPriority(name);
614
- const entry = owned.get(name);
615
- if (!entry || current !== entry.value || priority !== "") owned.set(name, {
616
- previous: current,
617
- priority,
618
- value: ""
619
- });
620
- style.setProperty(name, value);
621
- owned.get(name).value = style.getPropertyValue(name);
622
- }
623
- },
624
- dispose() {
625
- for (const name of [...owned.keys()]) release(name);
626
- }
627
- };
628
- }
629
- /** Browser-local persistence. A fully-default setting removes the key so a
630
- * reset leaves no residue; storage failures (private mode, quota) degrade to
631
- * in-memory behaviour rather than breaking the panel. */
632
- function createFontSettingsStore(storage) {
633
- let current = defaultFontSettings();
634
- let pendingPersistence = false;
635
- return {
636
- load() {
637
- if (storage && !pendingPersistence) try {
638
- current = parseFontSettings(storage.getItem(STORAGE_KEY));
639
- } catch {}
640
- return { ...current };
641
- },
642
- save(next) {
643
- current = parseFontSettings(next);
644
- if (!storage) return;
645
- pendingPersistence = true;
646
- try {
647
- if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY);
648
- else storage.setItem(STORAGE_KEY, serializeFontSettings(current));
649
- pendingPersistence = false;
650
- } catch {}
651
- }
652
- };
653
- }
654
- //#endregion
655
632
  //#region src/client.tsx
656
633
  const name = "dsh-font-client";
657
634
  const inject = [
@@ -670,7 +647,7 @@ const COPY = {
670
647
  customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
671
648
  customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
672
649
  uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
673
- codeHelp: "作用于代码块、行内代码与终端的等宽字体。",
650
+ codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
674
651
  sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
675
652
  loadFonts: "读取系统字体",
676
653
  reloadFonts: "重新读取系统字体",
@@ -693,7 +670,7 @@ const COPY = {
693
670
  customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
694
671
  customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
695
672
  uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
696
- 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.",
697
674
  sizeHelp: "Synced with Settings → General; 10–22 px.",
698
675
  loadFonts: "Load system fonts",
699
676
  reloadFonts: "Reload system fonts",
@@ -726,7 +703,7 @@ function useLocale(client) {
726
703
  return (0, react.useSyncExternalStore)((fn) => client.locale.subscribe(fn), getSnapshot, getSnapshot);
727
704
  }
728
705
  function useFontSize(client) {
729
- 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);
730
707
  }
731
708
  function presetMode(value, presets) {
732
709
  return presetFor(value, presets)?.id ?? (value ? "custom" : "");
@@ -811,7 +788,11 @@ function FontField(props) {
811
788
  function FontSettingsPanel(props) {
812
789
  const locale = useLocale(props.client);
813
790
  const text = COPY[locale];
814
- 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
+ };
815
796
  const fontSize = useFontSize(props.client);
816
797
  const [fontList, setFontList] = (0, react.useState)({
817
798
  state: "idle",
@@ -845,13 +826,8 @@ function FontSettingsPanel(props) {
845
826
  }
846
827
  }
847
828
  function update(patch) {
848
- const next = {
849
- uiFont: normalizeFontFamily(patch.uiFont ?? settings.uiFont),
850
- codeFont: normalizeFontFamily(patch.codeFont ?? settings.codeFont)
851
- };
852
- props.store.save(next);
853
- props.applySettings(next);
854
- 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));
855
831
  }
856
832
  const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
857
833
  const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
@@ -907,7 +883,7 @@ function FontSettingsPanel(props) {
907
883
  onChange: (event) => {
908
884
  const px = Number(event.target.value);
909
885
  if (Number.isInteger(px) && px >= 10 && px <= 22 && px !== fontSize) try {
910
- props.client.theme.setFontSize(px);
886
+ props.client.theme.setFontSize("text", px);
911
887
  } catch {}
912
888
  },
913
889
  children: sizes.map((px) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
@@ -939,7 +915,7 @@ function FontSettingsPanel(props) {
939
915
  uiFont: "",
940
916
  codeFont: ""
941
917
  });
942
- if (fontSize !== 14) props.client.theme.setFontSize(14);
918
+ if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
943
919
  },
944
920
  children: text.reset
945
921
  })]
@@ -965,7 +941,7 @@ function FontSettingsPanel(props) {
965
941
  function apply(ctx) {
966
942
  const client = ctx;
967
943
  const store = createFontSettingsStore(readStorage());
968
- let applySettings = (_settings) => {};
944
+ migrateFontPreferences(client.theme, store, readStorage());
969
945
  ctx.effect(() => {
970
946
  if (typeof document === "undefined") return () => {};
971
947
  const style = document.createElement("style");
@@ -974,23 +950,11 @@ function apply(ctx) {
974
950
  document.head.appendChild(style);
975
951
  return () => style.remove();
976
952
  }, "font.styles");
977
- ctx.effect(() => {
978
- if (typeof document === "undefined") return () => {};
979
- const override = createFontSettingsOverride(document.documentElement.style);
980
- applySettings = (next) => override.apply(next);
981
- applySettings(store.load());
982
- return () => {
983
- override.dispose();
984
- applySettings = () => {};
985
- };
986
- }, "font.apply");
987
953
  ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
988
954
  name: "plugins.bundle.config",
989
955
  key: PLUGIN_NAME
990
956
  }, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
991
957
  client,
992
- store,
993
- applySettings: (next) => applySettings(next),
994
958
  view: slotProps?.view
995
959
  }))), "font.settings");
996
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