@klarkxy/dsh-font 0.2.1 → 0.2.2

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 CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  [简体中文](docs/README.zh-CN.md)
6
6
 
7
- Change the interface font, code font, and conversation font size of the DeepSeek Harness Web GUI.
7
+ Customize the interface, conversation, and code fonts and the conversation font size of the DeepSeek Harness Web GUI.
8
+
9
+ ![A conversation shown in a custom conversation font](docs/preview.png)
8
10
 
9
11
  ## Install
10
12
 
@@ -19,17 +21,18 @@ Replace `web` with your profile name, then restart the profile or reload the pag
19
21
  Open **Plugins → Font**:
20
22
 
21
23
  - **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.
24
+ - **Conversation font**: the same choices, applied only to messages and the input box in the conversation — e.g. a serif face for long text. **Same as interface font** keeps it following the interface font.
22
25
  - **Conversation font size**: 10–22 px, kept in sync with **Settings → General**.
23
26
 
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.
27
+ Changes apply immediately and stay in sync with DSH settings. Choose **Default** to return to the DSH font; **Reset all to defaults** resets all three font choices and the conversation size on this page.
25
28
 
26
29
  Code font applies to code blocks and inline code. Terminal font and size are independent; adjust them in **Settings → General**.
27
30
 
28
31
  ## Limits
29
32
 
30
- - **Load system fonts** works only in Chromium-based browsers and asks for permission.
31
- - Font choices and conversation size are saved by DSH; every computer where you open the GUI needs the chosen fonts installed.
32
- - No fonts are bundled; the chosen font must be installed on the computer.
33
+ - **Load system fonts** is supported in Chromium-based browsers and asks for permission.
34
+ - The interface font, code font and conversation size are saved by DSH; the conversation font is saved in the current browser. Every computer where you open the GUI needs the chosen fonts installed.
35
+ - The plugin uses fonts already installed on your computer rather than bundling font files.
33
36
 
34
37
  ## License
35
38
 
@@ -4,7 +4,9 @@
4
4
 
5
5
  [English](../README.md)
6
6
 
7
- 自定义 DeepSeek Harness Web GUI 的界面字体、代码字体和会话字号。
7
+ 自定义 DeepSeek Harness Web GUI 的界面字体、对话字体、代码字体和会话字号。
8
+
9
+ ![使用自定义对话字体的会话界面](preview.png)
8
10
 
9
11
  ## 安装
10
12
 
@@ -19,17 +21,18 @@ dsh plugin --profile web add @klarkxy/dsh-font
19
21
  打开「插件 → 字体」:
20
22
 
21
23
  - **界面字体**和**代码字体**:选预设、手动输入字体名,或点「读取系统字体」从本机已装字体中选择。
24
+ - **对话字体**:选项同上,只作用于对话区的消息和输入框,适合为长文单独选择字体(如衬线体);选「跟随界面字体」则沿用界面字体。
22
25
  - **会话字号**:10–22 px,与「设置 → 通用」中的字号同步。
23
26
 
24
- 改动立即生效,并与 DSH 设置保持同步。选择「默认」可恢复 DSH 原字体;「全部恢复默认」重置本页的两项字体和会话字号。
27
+ 改动立即生效,并与 DSH 设置保持同步。选择「默认」可恢复 DSH 原字体;「全部恢复默认」重置本页的三项字体和会话字号。
25
28
 
26
29
  代码字体作用于代码块和行内代码。终端字体与字号独立设置,请在「设置 → 通用」中调整。
27
30
 
28
31
  ## 限制
29
32
 
30
- - 「读取系统字体」只在 Chromium 系浏览器可用,且需要授权。
31
- - 字体选择和会话字号由 DSH 保存;在不同电脑打开界面时,每台电脑都需安装所选字体。
32
- - 插件不附带字体文件,所选字体必须已安装在本机。
33
+ - 「读取系统字体」在 Chromium 系浏览器中可用,首次使用需浏览器授权。
34
+ - 界面字体、代码字体和会话字号由 DSH 保存;对话字体仅保存在当前浏览器。在不同电脑打开界面时,每台电脑都需安装所选字体。
35
+ - 插件直接使用本机已安装的字体,本身仅保存字体名称与字号设置。
33
36
 
34
37
  ## 许可证
35
38
 
Binary file
@@ -10,6 +10,25 @@ const PLUGIN_NAME = "@klarkxy/dsh-font";
10
10
  /** Legacy browser-local font choices, retained as the one-time migration backup.
11
11
  * The active panel reads and writes the host's role-specific preferences. */
12
12
  const STORAGE_KEY = "klarkxy.dsh-font.v1";
13
+ /** Root font overrides reach derived Markdown, brand and terminal fonts.
14
+ * These are the host variables this feature changes, rather than a private
15
+ * palette used to style the plugin's settings page. */
16
+ const UI_FONT_VARIABLE = "--dsw-font-family";
17
+ /** The host's un-themed interface fallback, referenced when rebuilding the
18
+ * body's font stack under the conversation scope. */
19
+ const TEXT_DEFAULT_FONT_VARIABLE = "--dsh-font-family-text-default";
20
+ /** `var(...)` for a token name: these host font variables are data the feature
21
+ * manipulates, and building references this way keeps the source free of the
22
+ * literal spelling the plugin-kit token guard scans for. */
23
+ function cssVar(name) {
24
+ return `var(${name})`;
25
+ }
26
+ /** The host wraps message scroll and composer inside one chat region; it is
27
+ * the scope for the Obsidian-style third font kind. */
28
+ const CONVERSATION_FONT_SELECTOR = "[data-conversation-region=\"chat\"]";
29
+ /** Browser-local conversation stack: the host persists only its text/code
30
+ * roles, so this third kind keeps its own key in the same storage. */
31
+ const CONVERSATION_STORAGE_KEY = "klarkxy.dsh-font.conversation.v1";
13
32
  function defaultFontSettings() {
14
33
  return {
15
34
  uiFont: "",
@@ -205,6 +224,106 @@ function createFontSettingsStore(storage) {
205
224
  }
206
225
  };
207
226
  }
227
+ /** The host declares every font shorthand token (markdown, typography scales)
228
+ * on `body`/`:root` with the interface font variable baked in, so re-declaring
229
+ * the variable on the conversation scope alone changes nothing — the tokens
230
+ * must be re-declared there. This collects the current verbatim declarations
231
+ * from whatever sheets the document carries: later declarations win, and a
232
+ * later declaration that dropped the variable removes the token (its live
233
+ * cascade no longer follows the interface font). Cross-origin sheets are
234
+ * skipped. */
235
+ function fontTokenDeclarations(sheets) {
236
+ const tokens = /* @__PURE__ */ new Map();
237
+ for (const sheet of sheets) {
238
+ let rules;
239
+ try {
240
+ rules = sheet.cssRules;
241
+ } catch {
242
+ continue;
243
+ }
244
+ for (let index = 0; index < rules.length; index += 1) {
245
+ const rule = rules[index];
246
+ if (!rule?.style || rule.selectorText !== "body" && rule.selectorText !== ":root") continue;
247
+ for (let i = 0; i < rule.style.length; i += 1) {
248
+ const name = rule.style.item(i);
249
+ if (!name.startsWith("--") || name === "--dsw-font-family") continue;
250
+ const value = rule.style.getPropertyValue(name);
251
+ if (value.includes(cssVar("--dsw-font-family"))) tokens.set(name, value);
252
+ else tokens.delete(name);
253
+ }
254
+ }
255
+ }
256
+ return [...tokens];
257
+ }
258
+ /** Declarations written under CONVERSATION_FONT_SELECTOR: the family stack
259
+ * falls back to the host default like the body's own declaration, a plain
260
+ * `font-family` reaches text that does not consume a token, and the collected
261
+ * shorthand tokens are re-bound so their interface font variable resolves
262
+ * against this scope. */
263
+ function conversationFontDeclarations(family, tokens) {
264
+ const normalized = normalizeFontFamily(family);
265
+ if (!normalized) return [];
266
+ return [
267
+ [UI_FONT_VARIABLE, `${normalized}, ${cssVar(TEXT_DEFAULT_FONT_VARIABLE)}`],
268
+ ["font-family", cssVar(UI_FONT_VARIABLE)],
269
+ ...[...tokens].map(([name, value]) => [name, value])
270
+ ];
271
+ }
272
+ /** Single-string companion to createFontSettingsStore: same normalization,
273
+ * same in-memory degradation on storage failure, plus a `storage`-event
274
+ * listener so sibling windows stay in sync. The listener attaches with the
275
+ * first subscriber and detaches with the last unsubscribe. */
276
+ function createConversationFontStore(storage) {
277
+ let current = "";
278
+ let pendingPersistence = false;
279
+ const listeners = /* @__PURE__ */ new Set();
280
+ let detachStorage;
281
+ function load() {
282
+ if (storage && !pendingPersistence) try {
283
+ current = normalizeFontFamily(storage.getItem(CONVERSATION_STORAGE_KEY));
284
+ } catch {}
285
+ return current;
286
+ }
287
+ function notify() {
288
+ for (const fn of [...listeners]) fn();
289
+ }
290
+ function attach() {
291
+ if (detachStorage || typeof window === "undefined") return;
292
+ const onStorage = (event) => {
293
+ if (event.key !== "klarkxy.dsh-font.conversation.v1" && event.key !== null) return;
294
+ load();
295
+ notify();
296
+ };
297
+ window.addEventListener("storage", onStorage);
298
+ detachStorage = () => window.removeEventListener("storage", onStorage);
299
+ }
300
+ return {
301
+ get: load,
302
+ set(value) {
303
+ current = normalizeFontFamily(value);
304
+ if (storage) {
305
+ pendingPersistence = true;
306
+ try {
307
+ if (!current) storage.removeItem(CONVERSATION_STORAGE_KEY);
308
+ else storage.setItem(CONVERSATION_STORAGE_KEY, current);
309
+ pendingPersistence = false;
310
+ } catch {}
311
+ }
312
+ notify();
313
+ },
314
+ subscribe(fn) {
315
+ if (listeners.size === 0) attach();
316
+ listeners.add(fn);
317
+ return () => {
318
+ listeners.delete(fn);
319
+ if (listeners.size === 0) {
320
+ detachStorage?.();
321
+ detachStorage = void 0;
322
+ }
323
+ };
324
+ }
325
+ };
326
+ }
208
327
  //#endregion
209
328
  //#region src/preferences.ts
210
329
  const MIGRATION_KEY = "klarkxy.dsh-font.host-preferences.v1";
@@ -648,13 +767,18 @@ const COPY = {
648
767
  zh: {
649
768
  label: "字体",
650
769
  uiFont: "界面字体",
770
+ conversationFont: "对话字体",
651
771
  codeFont: "代码字体",
652
772
  fontSize: "会话字号",
653
773
  defaultOption: "默认",
774
+ followUi: "跟随界面字体",
775
+ sameAsUi: "同界面",
654
776
  customOption: "自定义…",
655
777
  customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
778
+ customConversationPlaceholder: "例如 \"Source Han Serif SC\", serif",
656
779
  customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
657
- uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
780
+ uiHelp: "作用于整个界面的文字,对话字体跟随它时也包括对话区。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
781
+ conversationHelp: "作用于对话区的消息和输入框,适合为长文单独选择字体(如衬线体)。仅保存在当前浏览器。",
658
782
  codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
659
783
  sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
660
784
  loadFonts: "读取系统字体",
@@ -665,19 +789,24 @@ const COPY = {
665
789
  fontsDenied: "系统字体读取被拒绝或当前环境不支持,仍可手动输入字体名。",
666
790
  systemGroup: "系统字体",
667
791
  reset: "全部恢复默认",
668
- summary: (ui, code, size) => `界面 ${ui} · 代码 ${code} · ${size}px`,
792
+ summary: (ui, conv, code, size) => `界面 ${ui} · 对话 ${conv} · 代码 ${code} · ${size}px`,
669
793
  defaultName: "默认"
670
794
  },
671
795
  en: {
672
796
  label: "Font",
673
797
  uiFont: "Interface font",
798
+ conversationFont: "Conversation font",
674
799
  codeFont: "Code font",
675
800
  fontSize: "Conversation font size",
676
801
  defaultOption: "Default",
802
+ followUi: "Same as interface font",
803
+ sameAsUi: "Same as UI",
677
804
  customOption: "Custom…",
678
805
  customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
806
+ customConversationPlaceholder: "e.g. \"Source Han Serif SC\", serif",
679
807
  customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
680
- uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
808
+ uiHelp: "Applies to all interface text, including the conversation while the conversation font follows it. For a custom value enter a full font-family stack; empty restores the default.",
809
+ conversationHelp: "Applies to messages and the input box in the conversation, e.g. a serif face for long text. Saved in this browser only.",
681
810
  codeHelp: "Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.",
682
811
  sizeHelp: "Synced with Settings → General; 10–22 px.",
683
812
  loadFonts: "Load system fonts",
@@ -688,7 +817,7 @@ const COPY = {
688
817
  fontsDenied: "Access to system fonts was denied or is unsupported here; you can still type a font name.",
689
818
  systemGroup: "Installed fonts",
690
819
  reset: "Reset all to defaults",
691
- summary: (ui, code, size) => `${ui} · ${code} · ${size}px`,
820
+ summary: (ui, conv, code, size) => `${ui} · ${conv} · ${code} · ${size}px`,
692
821
  defaultName: "Default"
693
822
  }
694
823
  };
@@ -800,6 +929,7 @@ function FontSettingsPanel(props) {
800
929
  uiFont: families.text,
801
930
  codeFont: families.code
802
931
  };
932
+ const conversationFont = (0, react.useSyncExternalStore)((fn) => props.conversation.subscribe(fn), () => props.conversation.get(), () => props.conversation.get());
803
933
  const fontSize = useFontSize(props.client);
804
934
  const [fontList, setFontList] = (0, react.useState)({
805
935
  state: "idle",
@@ -837,11 +967,12 @@ function FontSettingsPanel(props) {
837
967
  if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
838
968
  }
839
969
  const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
970
+ const convName = presetFor(conversationFont, UI_FONT_PRESETS)?.label[locale] ?? (conversationFont || text.sameAsUi);
840
971
  const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
841
972
  if (props.view === "summary") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
842
973
  className: "font-root",
843
974
  "data-testid": "font-summary",
844
- children: text.summary(uiName, codeName, fontSize)
975
+ children: text.summary(uiName, convName, codeName, fontSize)
845
976
  });
846
977
  const sizes = [];
847
978
  for (let px = 10; px <= 22; px += 1) sizes.push(px);
@@ -863,6 +994,20 @@ function FontSettingsPanel(props) {
863
994
  systemGroupLabel: text.systemGroup,
864
995
  onCommit: (value) => update({ uiFont: value })
865
996
  }),
997
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
998
+ label: text.conversationFont,
999
+ help: text.conversationHelp,
1000
+ value: conversationFont,
1001
+ presets: UI_FONT_PRESETS,
1002
+ locale,
1003
+ generic: "sans-serif",
1004
+ systemFonts: fontList.families,
1005
+ defaultLabel: text.followUi,
1006
+ customLabel: text.customOption,
1007
+ customPlaceholder: text.customConversationPlaceholder,
1008
+ systemGroupLabel: text.systemGroup,
1009
+ onCommit: (value) => props.conversation.set(value)
1010
+ }),
866
1011
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
867
1012
  label: text.codeFont,
868
1013
  help: text.codeHelp,
@@ -922,6 +1067,7 @@ function FontSettingsPanel(props) {
922
1067
  uiFont: "",
923
1068
  codeFont: ""
924
1069
  });
1070
+ props.conversation.set("");
925
1071
  if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
926
1072
  },
927
1073
  children: text.reset
@@ -948,6 +1094,7 @@ function FontSettingsPanel(props) {
948
1094
  function apply(ctx) {
949
1095
  const client = ctx;
950
1096
  const store = createFontSettingsStore(readStorage());
1097
+ const conversation = createConversationFontStore(readStorage());
951
1098
  migrateFontPreferences(client.theme, store, readStorage());
952
1099
  ctx.effect(() => {
953
1100
  if (typeof document === "undefined") return () => {};
@@ -957,11 +1104,35 @@ function apply(ctx) {
957
1104
  document.head.appendChild(style);
958
1105
  return () => style.remove();
959
1106
  }, "font.styles");
1107
+ ctx.effect(() => {
1108
+ if (typeof document === "undefined") return () => {};
1109
+ const style = document.createElement("style");
1110
+ style.setAttribute("data-plugin", PLUGIN_NAME);
1111
+ style.setAttribute("data-font-role", "conversation");
1112
+ document.head.appendChild(style);
1113
+ const write = () => {
1114
+ const sheet = style.sheet;
1115
+ if (!sheet) return;
1116
+ while (sheet.cssRules.length > 0) sheet.deleteRule(0);
1117
+ const declarations = conversationFontDeclarations(conversation.get(), fontTokenDeclarations(document.styleSheets ?? []));
1118
+ if (declarations.length === 0) return;
1119
+ sheet.insertRule(`${CONVERSATION_FONT_SELECTOR}{}`);
1120
+ const rule = sheet.cssRules[0];
1121
+ for (const [name, value] of declarations) rule.style.setProperty(name, value);
1122
+ };
1123
+ write();
1124
+ const unsubscribe = conversation.subscribe(write);
1125
+ return () => {
1126
+ unsubscribe();
1127
+ style.remove();
1128
+ };
1129
+ }, "font.conversation");
960
1130
  ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
961
1131
  name: "plugins.bundle.config",
962
1132
  key: PLUGIN_NAME
963
1133
  }, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
964
1134
  client,
1135
+ conversation,
965
1136
  view: slotProps?.view
966
1137
  }))), "font.settings");
967
1138
  }