@klarkxy/dsh-font 0.2.1 → 0.2.3
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 +12 -10
- package/docs/README.zh-CN.md +12 -10
- package/docs/preview.png +0 -0
- package/lib/client.inner.cjs +549 -157
- package/lib/client.inner.cjs.map +1 -1
- package/lib/client.js +549 -157
- package/lib/contracts.d.ts +72 -8
- package/lib/contracts.js +138 -8
- package/lib/contracts.js.map +1 -1
- package/lib/index.d.ts +5 -5
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +5 -4
package/lib/client.inner.cjs
CHANGED
|
@@ -10,6 +10,44 @@ 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
|
+
const FONT_SIZE_SPECS = {
|
|
14
|
+
text: {
|
|
15
|
+
min: 10,
|
|
16
|
+
max: 22,
|
|
17
|
+
default: 14
|
|
18
|
+
},
|
|
19
|
+
code: {
|
|
20
|
+
min: 10,
|
|
21
|
+
max: 16,
|
|
22
|
+
default: 11
|
|
23
|
+
},
|
|
24
|
+
terminal: {
|
|
25
|
+
min: 10,
|
|
26
|
+
max: 20,
|
|
27
|
+
default: 13
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/** Root font variables the legacy local-storage model overrode directly:
|
|
31
|
+
* derived Markdown and brand fonts follow the interface variable. Kept as
|
|
32
|
+
* migration data for the pre-theme-service storage; live writes now go
|
|
33
|
+
* through theme.setFontFamily per role instead. */
|
|
34
|
+
const UI_FONT_VARIABLE = "--dsw-font-family";
|
|
35
|
+
/** The host's un-themed interface fallback, referenced when rebuilding the
|
|
36
|
+
* body's font stack under the conversation scope. */
|
|
37
|
+
const TEXT_DEFAULT_FONT_VARIABLE = "--dsh-font-family-text-default";
|
|
38
|
+
/** `var(...)` for a token name: these host font variables are data the feature
|
|
39
|
+
* manipulates, and building references this way keeps the source free of the
|
|
40
|
+
* literal spelling the plugin-kit token guard scans for. */
|
|
41
|
+
function cssVar(name) {
|
|
42
|
+
return `var(${name})`;
|
|
43
|
+
}
|
|
44
|
+
/** The host wraps message scroll and composer inside one chat region; it is
|
|
45
|
+
* the scope for the Obsidian-style third font kind. */
|
|
46
|
+
const CONVERSATION_FONT_SELECTOR = "[data-conversation-region=\"chat\"]";
|
|
47
|
+
/** Browser-local conversation stack: the host persists its own three roles
|
|
48
|
+
* (text/code/terminal), while the plugin-owned conversation kind keeps this
|
|
49
|
+
* separate key in the same storage. */
|
|
50
|
+
const CONVERSATION_STORAGE_KEY = "klarkxy.dsh-font.conversation.v1";
|
|
13
51
|
function defaultFontSettings() {
|
|
14
52
|
return {
|
|
15
53
|
uiFont: "",
|
|
@@ -205,6 +243,106 @@ function createFontSettingsStore(storage) {
|
|
|
205
243
|
}
|
|
206
244
|
};
|
|
207
245
|
}
|
|
246
|
+
/** The host declares every font shorthand token (markdown, typography scales)
|
|
247
|
+
* on `body`/`:root` with the interface font variable baked in, so re-declaring
|
|
248
|
+
* the variable on the conversation scope alone changes nothing — the tokens
|
|
249
|
+
* must be re-declared there. This collects the current verbatim declarations
|
|
250
|
+
* from whatever sheets the document carries: later declarations win, and a
|
|
251
|
+
* later declaration that dropped the variable removes the token (its live
|
|
252
|
+
* cascade no longer follows the interface font). Cross-origin sheets are
|
|
253
|
+
* skipped. */
|
|
254
|
+
function fontTokenDeclarations(sheets) {
|
|
255
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
256
|
+
for (const sheet of sheets) {
|
|
257
|
+
let rules;
|
|
258
|
+
try {
|
|
259
|
+
rules = sheet.cssRules;
|
|
260
|
+
} catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
for (let index = 0; index < rules.length; index += 1) {
|
|
264
|
+
const rule = rules[index];
|
|
265
|
+
if (!rule?.style || rule.selectorText !== "body" && rule.selectorText !== ":root") continue;
|
|
266
|
+
for (let i = 0; i < rule.style.length; i += 1) {
|
|
267
|
+
const name = rule.style.item(i);
|
|
268
|
+
if (!name.startsWith("--") || name === "--dsw-font-family") continue;
|
|
269
|
+
const value = rule.style.getPropertyValue(name);
|
|
270
|
+
if (value.includes(cssVar("--dsw-font-family"))) tokens.set(name, value);
|
|
271
|
+
else tokens.delete(name);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return [...tokens];
|
|
276
|
+
}
|
|
277
|
+
/** Declarations written under CONVERSATION_FONT_SELECTOR: the family stack
|
|
278
|
+
* falls back to the host default like the body's own declaration, a plain
|
|
279
|
+
* `font-family` reaches text that does not consume a token, and the collected
|
|
280
|
+
* shorthand tokens are re-bound so their interface font variable resolves
|
|
281
|
+
* against this scope. */
|
|
282
|
+
function conversationFontDeclarations(family, tokens) {
|
|
283
|
+
const normalized = normalizeFontFamily(family);
|
|
284
|
+
if (!normalized) return [];
|
|
285
|
+
return [
|
|
286
|
+
[UI_FONT_VARIABLE, `${normalized}, ${cssVar(TEXT_DEFAULT_FONT_VARIABLE)}`],
|
|
287
|
+
["font-family", cssVar(UI_FONT_VARIABLE)],
|
|
288
|
+
...[...tokens].map(([name, value]) => [name, value])
|
|
289
|
+
];
|
|
290
|
+
}
|
|
291
|
+
/** Single-string companion to createFontSettingsStore: same normalization,
|
|
292
|
+
* same in-memory degradation on storage failure, plus a `storage`-event
|
|
293
|
+
* listener so sibling windows stay in sync. The listener attaches with the
|
|
294
|
+
* first subscriber and detaches with the last unsubscribe. */
|
|
295
|
+
function createConversationFontStore(storage) {
|
|
296
|
+
let current = "";
|
|
297
|
+
let pendingPersistence = false;
|
|
298
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
299
|
+
let detachStorage;
|
|
300
|
+
function load() {
|
|
301
|
+
if (storage && !pendingPersistence) try {
|
|
302
|
+
current = normalizeFontFamily(storage.getItem(CONVERSATION_STORAGE_KEY));
|
|
303
|
+
} catch {}
|
|
304
|
+
return current;
|
|
305
|
+
}
|
|
306
|
+
function notify() {
|
|
307
|
+
for (const fn of [...listeners]) fn();
|
|
308
|
+
}
|
|
309
|
+
function attach() {
|
|
310
|
+
if (detachStorage || typeof window === "undefined") return;
|
|
311
|
+
const onStorage = (event) => {
|
|
312
|
+
if (event.key !== "klarkxy.dsh-font.conversation.v1" && event.key !== null) return;
|
|
313
|
+
load();
|
|
314
|
+
notify();
|
|
315
|
+
};
|
|
316
|
+
window.addEventListener("storage", onStorage);
|
|
317
|
+
detachStorage = () => window.removeEventListener("storage", onStorage);
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
get: load,
|
|
321
|
+
set(value) {
|
|
322
|
+
current = normalizeFontFamily(value);
|
|
323
|
+
if (storage) {
|
|
324
|
+
pendingPersistence = true;
|
|
325
|
+
try {
|
|
326
|
+
if (!current) storage.removeItem(CONVERSATION_STORAGE_KEY);
|
|
327
|
+
else storage.setItem(CONVERSATION_STORAGE_KEY, current);
|
|
328
|
+
pendingPersistence = false;
|
|
329
|
+
} catch {}
|
|
330
|
+
}
|
|
331
|
+
notify();
|
|
332
|
+
},
|
|
333
|
+
subscribe(fn) {
|
|
334
|
+
if (listeners.size === 0) attach();
|
|
335
|
+
listeners.add(fn);
|
|
336
|
+
return () => {
|
|
337
|
+
listeners.delete(fn);
|
|
338
|
+
if (listeners.size === 0) {
|
|
339
|
+
detachStorage?.();
|
|
340
|
+
detachStorage = void 0;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
208
346
|
//#endregion
|
|
209
347
|
//#region src/preferences.ts
|
|
210
348
|
const MIGRATION_KEY = "klarkxy.dsh-font.host-preferences.v1";
|
|
@@ -637,6 +775,77 @@ ${scope} {
|
|
|
637
775
|
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?=\s*\{)/gm, (_match, className) => `&${className}, & ${className}`);
|
|
638
776
|
}
|
|
639
777
|
//#endregion
|
|
778
|
+
//#region ../dsh-plugin-kit/src/contracts.ts
|
|
779
|
+
/** `@klarkxy/dsh-git-commit` becomes `KlarkxyDshGitCommitModelSettingsChanges`. */
|
|
780
|
+
function modelSettingsChangesIdentity(packageName) {
|
|
781
|
+
const scoped = /^@([^/]+)\/(.+)$/.exec(packageName);
|
|
782
|
+
const parts = (scoped ? `${scoped[1]}/${scoped[2]}` : packageName).split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
783
|
+
if (!parts.length) throw new Error("Model settings package name has no RPC segment");
|
|
784
|
+
const segment = `${parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}ModelSettingsChanges`;
|
|
785
|
+
if (!/^[A-Z][A-Za-z0-9]*$/.test(segment)) throw new Error(`Model settings sync name is not an RPC segment: ${segment}`);
|
|
786
|
+
return {
|
|
787
|
+
service: segment,
|
|
788
|
+
namespace: segment
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Host-owned nav icon seat: a root-scoped list where each entry's `id` must
|
|
793
|
+
* equal the `settings.section` id it decorates. Owner props are
|
|
794
|
+
* `{size, active}`; icons stay `aria-hidden` so the section label remains the
|
|
795
|
+
* accessible name. Contributors into a shared section may register the same
|
|
796
|
+
* icon `id` with different priorities — the ledger keeps every entry while the
|
|
797
|
+
* host renders one icon per section.
|
|
798
|
+
*/
|
|
799
|
+
const SETTINGS_SECTION_ICON_SLOT = "settings.section.icon";
|
|
800
|
+
modelSettingsChangesIdentity("@klarkxy/dsh-plugin-kit");
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region ../dsh-plugin-kit/src/client-utils.ts
|
|
803
|
+
/** One `<svg>` with the shared icon chrome; children are plain elements. */
|
|
804
|
+
function lineIcon(children) {
|
|
805
|
+
return function SettingsSectionIcon(props) {
|
|
806
|
+
return (0, react.createElement)("svg", {
|
|
807
|
+
"aria-hidden": "true",
|
|
808
|
+
width: props.size ?? 16,
|
|
809
|
+
height: props.size ?? 16,
|
|
810
|
+
viewBox: "0 0 16 16",
|
|
811
|
+
fill: "none",
|
|
812
|
+
stroke: "currentColor",
|
|
813
|
+
strokeWidth: 1,
|
|
814
|
+
strokeLinecap: "round",
|
|
815
|
+
strokeLinejoin: "round"
|
|
816
|
+
}, ...children.map(([tag, attrs], index) => (0, react.createElement)(tag, {
|
|
817
|
+
key: index,
|
|
818
|
+
...attrs
|
|
819
|
+
})));
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/** Serif-flavoured letter A for the Font section. */
|
|
823
|
+
const IconFontSettings = lineIcon([
|
|
824
|
+
["path", { d: "M3.3 12.6 7.9 3.1a.5.5 0 0 1 .9 0l4.6 9.5" }],
|
|
825
|
+
["path", { d: "M5.2 9.4h6.3" }],
|
|
826
|
+
["path", { d: "M2.4 12.6h2.4" }],
|
|
827
|
+
["path", { d: "M11.9 12.6h2.4" }]
|
|
828
|
+
]);
|
|
829
|
+
/**
|
|
830
|
+
* Contribute the nav icon of a `settings.section` entry. The `settings
|
|
831
|
+
* .section.icon` seat is declared by the host independently of the section
|
|
832
|
+
* list, so the wait runs in parallel: the icon appears as soon as both seats
|
|
833
|
+
* exist and unloading removes it again, restoring the host's default glyph.
|
|
834
|
+
* The `id` must equal the section id; `order`/`priority` mirror `order` so the
|
|
835
|
+
* icon cell sorts like its section and, for shared sections, several
|
|
836
|
+
* contributors can register the same icon id under different priorities
|
|
837
|
+
* without duplicating nav entries.
|
|
838
|
+
*/
|
|
839
|
+
function registerSettingsSectionIcon(ctx, sectionId, order, component) {
|
|
840
|
+
const slots = ctx.slots;
|
|
841
|
+
return slots.inject(SETTINGS_SECTION_ICON_SLOT, () => slots.register({
|
|
842
|
+
name: SETTINGS_SECTION_ICON_SLOT,
|
|
843
|
+
id: sectionId,
|
|
844
|
+
order,
|
|
845
|
+
priority: order
|
|
846
|
+
}, component));
|
|
847
|
+
}
|
|
848
|
+
//#endregion
|
|
640
849
|
//#region src/client.tsx
|
|
641
850
|
const name = "dsh-font-client";
|
|
642
851
|
const inject = [
|
|
@@ -648,15 +857,29 @@ const COPY = {
|
|
|
648
857
|
zh: {
|
|
649
858
|
label: "字体",
|
|
650
859
|
uiFont: "界面字体",
|
|
860
|
+
conversationFont: "对话字体",
|
|
651
861
|
codeFont: "代码字体",
|
|
652
|
-
|
|
862
|
+
terminalFont: "终端字体",
|
|
863
|
+
textSize: "字号大小",
|
|
864
|
+
textSizeHelp: "仅影响会话内容的字号",
|
|
865
|
+
codeSize: "代码字号",
|
|
866
|
+
codeSizeHelp: "用于代码块、行内代码与工具输出",
|
|
867
|
+
terminalSize: "终端字号",
|
|
868
|
+
terminalSizeHelp: "用于侧栏终端",
|
|
869
|
+
increaseSize: (label) => `增大${label}`,
|
|
870
|
+
decreaseSize: (label) => `减小${label}`,
|
|
871
|
+
sizeUnit: "px",
|
|
653
872
|
defaultOption: "默认",
|
|
873
|
+
followUi: "跟随界面字体",
|
|
654
874
|
customOption: "自定义…",
|
|
655
875
|
customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
|
|
876
|
+
customConversationPlaceholder: "例如 \"Source Han Serif SC\", serif",
|
|
656
877
|
customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
878
|
+
customTerminalPlaceholder: "例如 \"Cascadia Mono\", monospace",
|
|
879
|
+
uiHelp: "作用于整个界面的文字,对话字体跟随它时也包括对话区。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
|
|
880
|
+
conversationHelp: "作用于对话区的消息和输入框,适合为长文单独选择字体(如衬线体)。仅保存在当前浏览器。",
|
|
881
|
+
codeHelp: "作用于代码块、行内代码与工具输出。",
|
|
882
|
+
terminalHelp: "作用于侧栏终端,与代码字体独立。",
|
|
660
883
|
loadFonts: "读取系统字体",
|
|
661
884
|
reloadFonts: "重新读取系统字体",
|
|
662
885
|
loadingFonts: "正在读取系统字体…",
|
|
@@ -664,22 +887,35 @@ const COPY = {
|
|
|
664
887
|
fontsPartial: "列表来自浏览器枚举:仅安装到当前用户的字体可能不在其中,可以直接输入字体名使用。",
|
|
665
888
|
fontsDenied: "系统字体读取被拒绝或当前环境不支持,仍可手动输入字体名。",
|
|
666
889
|
systemGroup: "系统字体",
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
defaultName: "默认"
|
|
890
|
+
resetFonts: "恢复默认字体",
|
|
891
|
+
resetSizes: "恢复默认字号"
|
|
670
892
|
},
|
|
671
893
|
en: {
|
|
672
894
|
label: "Font",
|
|
673
895
|
uiFont: "Interface font",
|
|
896
|
+
conversationFont: "Conversation font",
|
|
674
897
|
codeFont: "Code font",
|
|
675
|
-
|
|
898
|
+
terminalFont: "Terminal font",
|
|
899
|
+
textSize: "Font size",
|
|
900
|
+
textSizeHelp: "Only affects conversation content",
|
|
901
|
+
codeSize: "Code font size",
|
|
902
|
+
codeSizeHelp: "Used for code blocks, inline code, and tool output",
|
|
903
|
+
terminalSize: "Terminal font size",
|
|
904
|
+
terminalSizeHelp: "Used for the sidebar terminal",
|
|
905
|
+
increaseSize: (label) => `Increase ${label.toLowerCase()}`,
|
|
906
|
+
decreaseSize: (label) => `Decrease ${label.toLowerCase()}`,
|
|
907
|
+
sizeUnit: "px",
|
|
676
908
|
defaultOption: "Default",
|
|
909
|
+
followUi: "Same as interface font",
|
|
677
910
|
customOption: "Custom…",
|
|
678
911
|
customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
|
|
912
|
+
customConversationPlaceholder: "e.g. \"Source Han Serif SC\", serif",
|
|
679
913
|
customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
914
|
+
customTerminalPlaceholder: "e.g. \"Cascadia Mono\", monospace",
|
|
915
|
+
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.",
|
|
916
|
+
conversationHelp: "Applies to messages and the input box in the conversation, e.g. a serif face for long text. Saved in this browser only.",
|
|
917
|
+
codeHelp: "Applies to code blocks, inline code, and tool output.",
|
|
918
|
+
terminalHelp: "Applies to the sidebar terminal, independent of the code font.",
|
|
683
919
|
loadFonts: "Load system fonts",
|
|
684
920
|
reloadFonts: "Reload system fonts",
|
|
685
921
|
loadingFonts: "Loading system fonts…",
|
|
@@ -687,16 +923,38 @@ const COPY = {
|
|
|
687
923
|
fontsPartial: "The list comes from the browser’s enumeration: fonts installed only for the current user may be missing — you can still type the family name directly.",
|
|
688
924
|
fontsDenied: "Access to system fonts was denied or is unsupported here; you can still type a font name.",
|
|
689
925
|
systemGroup: "Installed fonts",
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
defaultName: "Default"
|
|
926
|
+
resetFonts: "Reset fonts",
|
|
927
|
+
resetSizes: "Reset font sizes"
|
|
693
928
|
}
|
|
694
929
|
};
|
|
695
930
|
function fontCopy(locale) {
|
|
696
931
|
return COPY[locale];
|
|
697
932
|
}
|
|
698
933
|
const styles = `${officialUiCss("font-root")}
|
|
699
|
-
.font-root .font-
|
|
934
|
+
.font-root .font-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 16px 0; border-bottom: 0.5px solid var(--dsw-alias-border-l2); }
|
|
935
|
+
.font-root .font-row-text { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; padding-right: 40px; }
|
|
936
|
+
.font-root .font-row-title { font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); }
|
|
937
|
+
.font-root .font-row-desc { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
|
|
938
|
+
.font-root .font-row-control { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
|
|
939
|
+
.font-root .font-select { flex: 0 1 240px; width: auto; }
|
|
940
|
+
.font-root .font-custom { flex: 1 1 100%; }
|
|
941
|
+
.font-root .font-stepper { display: inline-flex; align-items: center; justify-content: center; min-width: 72px; height: 36px; position: relative; border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-module-platform); }
|
|
942
|
+
.font-root .font-stepper-value { min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); }
|
|
943
|
+
.font-root .font-stepper-unit { font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-secondary); }
|
|
944
|
+
.font-root .font-stepper-arrows { position: absolute; right: 8px; display: flex; flex-direction: column; gap: 2px; opacity: 0; }
|
|
945
|
+
.font-root .font-stepper:focus-within .font-stepper-arrows { opacity: 1; }
|
|
946
|
+
@media (hover:hover) { .font-root .font-stepper:hover .font-stepper-arrows { opacity: 1; } }
|
|
947
|
+
@media (hover:none) { .font-root .font-stepper-arrows { opacity: 1; } }
|
|
948
|
+
.font-root .font-stepper-arrow { width: 17px; height: 12px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--dsw-radius-sm); background: color-mix(in srgb, var(--dsw-alias-bg-layer-1) 75%, transparent); color: var(--dsw-alias-label-primary); cursor: pointer; }
|
|
949
|
+
@media (hover:hover) { .font-root .font-stepper-arrow:hover:not(:disabled) { background: var(--dsw-alias-bg-layer-1); } }
|
|
950
|
+
.font-root .font-stepper-arrow:disabled { color: var(--dsw-alias-label-caption); cursor: default; }
|
|
951
|
+
/* The last row keeps the hairline off the page's bottom edge, mirroring the
|
|
952
|
+
* host's own last-child rule inside a settings column. */
|
|
953
|
+
.font-root > :last-child, .font-root > :last-child > :last-child { border-bottom: none; }
|
|
954
|
+
@media (max-width: 767px) {
|
|
955
|
+
.font-root .font-row-text { padding-right: 16px; }
|
|
956
|
+
.font-root .font-select { flex: 0 1 auto; width: 240px; max-width: 100%; }
|
|
957
|
+
}
|
|
700
958
|
`;
|
|
701
959
|
function readStorage() {
|
|
702
960
|
try {
|
|
@@ -709,13 +967,14 @@ function useLocale(client) {
|
|
|
709
967
|
const getSnapshot = () => client.locale.getSnapshot().active.toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
710
968
|
return (0, react.useSyncExternalStore)((fn) => client.locale.subscribe(fn), getSnapshot, getSnapshot);
|
|
711
969
|
}
|
|
712
|
-
function useFontSize(client) {
|
|
713
|
-
return (0, react.useSyncExternalStore)((fn) => client.on("theme/change", () => fn()), () => client.theme.getTheme().fontSizes.text, () => client.theme.getTheme().fontSizes.text);
|
|
714
|
-
}
|
|
715
970
|
function presetMode(value, presets) {
|
|
716
971
|
return presetFor(value, presets)?.id ?? (value ? "custom" : "");
|
|
717
972
|
}
|
|
973
|
+
/** One font-family row in the native compact shape: title and description on
|
|
974
|
+
* the left, a preset picker on the trailing edge, the custom stack input
|
|
975
|
+
* wrapping to a full line when the picker is on Custom. */
|
|
718
976
|
function FontField(props) {
|
|
977
|
+
const labelId = (0, react.useId)();
|
|
719
978
|
const [draft, setDraft] = (0, react.useState)(void 0);
|
|
720
979
|
const [customOpen, setCustomOpen] = (0, react.useState)(false);
|
|
721
980
|
const mode = customOpen ? "custom" : presetMode(props.value, props.presets);
|
|
@@ -726,81 +985,149 @@ function FontField(props) {
|
|
|
726
985
|
if (!next) setCustomOpen(false);
|
|
727
986
|
if (next !== props.value) props.onCommit(next);
|
|
728
987
|
}
|
|
729
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("
|
|
730
|
-
className: "
|
|
988
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
989
|
+
className: "font-row",
|
|
731
990
|
children: [
|
|
732
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
733
|
-
className: "
|
|
734
|
-
children:
|
|
991
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
992
|
+
className: "font-row-text",
|
|
993
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
994
|
+
className: "font-row-title",
|
|
995
|
+
id: labelId,
|
|
996
|
+
children: props.label
|
|
997
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
998
|
+
className: "font-row-desc",
|
|
999
|
+
children: props.help
|
|
1000
|
+
})]
|
|
735
1001
|
}),
|
|
736
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
737
|
-
className: "
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1002
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1003
|
+
className: "font-row-control",
|
|
1004
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
1005
|
+
className: "dsh-ui-select font-select",
|
|
1006
|
+
"aria-labelledby": labelId,
|
|
1007
|
+
value: mode,
|
|
1008
|
+
onChange: (event) => {
|
|
1009
|
+
const id = event.target.value;
|
|
1010
|
+
setDraft(void 0);
|
|
1011
|
+
if (id === "custom") {
|
|
1012
|
+
setCustomOpen(true);
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
setCustomOpen(false);
|
|
1016
|
+
if (id.startsWith("sys:")) {
|
|
1017
|
+
props.onCommit(fontStackFor(id.slice(4), props.generic));
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
const preset = props.presets.find((item) => item.id === id);
|
|
1021
|
+
props.onCommit(preset ? preset.value : "");
|
|
1022
|
+
},
|
|
1023
|
+
children: [
|
|
1024
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1025
|
+
value: "",
|
|
1026
|
+
children: props.defaultLabel
|
|
1027
|
+
}),
|
|
1028
|
+
props.presets.map((preset) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1029
|
+
value: preset.id,
|
|
1030
|
+
children: preset.label[props.locale]
|
|
1031
|
+
}, preset.id)),
|
|
1032
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1033
|
+
value: "custom",
|
|
1034
|
+
children: props.customLabel
|
|
1035
|
+
}),
|
|
1036
|
+
props.systemFonts && props.systemFonts.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("optgroup", {
|
|
1037
|
+
label: props.systemGroupLabel,
|
|
1038
|
+
children: props.systemFonts.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1039
|
+
value: `sys:${item.family}`,
|
|
1040
|
+
children: systemFontLabel(item, props.locale)
|
|
1041
|
+
}, item.family))
|
|
1042
|
+
}) : null
|
|
1043
|
+
]
|
|
1044
|
+
})
|
|
775
1045
|
}),
|
|
776
1046
|
mode === "custom" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
777
1047
|
className: "font-custom",
|
|
778
1048
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
|
|
779
1049
|
value: draft ?? props.value,
|
|
780
1050
|
placeholder: props.customPlaceholder,
|
|
1051
|
+
"aria-label": props.label,
|
|
781
1052
|
onChange: (event) => setDraft(event.target.value),
|
|
782
1053
|
onBlur: commitDraft,
|
|
783
1054
|
onKeyDown: (event) => {
|
|
784
1055
|
if (event.key === "Enter") commitDraft();
|
|
785
1056
|
}
|
|
786
1057
|
})
|
|
787
|
-
}) : null
|
|
788
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
789
|
-
className: "dsh-ui-help",
|
|
790
|
-
children: props.help
|
|
791
|
-
})
|
|
1058
|
+
}) : null
|
|
792
1059
|
]
|
|
793
1060
|
});
|
|
794
1061
|
}
|
|
795
|
-
|
|
1062
|
+
/** One font-size row in the native stepper shape: title and description on the
|
|
1063
|
+
* left, a pill holding the centered value with a hover/focus-revealed up/down
|
|
1064
|
+
* arrow column, and the px unit label after it. The displayed value follows
|
|
1065
|
+
* the persisted setting through the theme service, never the click echo, and
|
|
1066
|
+
* the arrows clamp at the role's host bounds instead of asking the service to
|
|
1067
|
+
* reject an out-of-range write. */
|
|
1068
|
+
function FontSizeField(props) {
|
|
1069
|
+
const labelId = (0, react.useId)();
|
|
1070
|
+
const { min, max } = FONT_SIZE_SPECS[props.role];
|
|
1071
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1072
|
+
className: "font-row",
|
|
1073
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1074
|
+
className: "font-row-text",
|
|
1075
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1076
|
+
className: "font-row-title",
|
|
1077
|
+
id: labelId,
|
|
1078
|
+
children: props.label
|
|
1079
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1080
|
+
className: "font-row-desc",
|
|
1081
|
+
children: props.help
|
|
1082
|
+
})]
|
|
1083
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1084
|
+
className: "font-row-control",
|
|
1085
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1086
|
+
className: "font-stepper",
|
|
1087
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1088
|
+
className: "font-stepper-value",
|
|
1089
|
+
"aria-labelledby": labelId,
|
|
1090
|
+
children: props.value
|
|
1091
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1092
|
+
className: "font-stepper-arrows",
|
|
1093
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1094
|
+
type: "button",
|
|
1095
|
+
className: "font-stepper-arrow",
|
|
1096
|
+
"aria-label": props.increaseLabel,
|
|
1097
|
+
disabled: props.value >= max,
|
|
1098
|
+
onClick: () => props.onCommit(props.role, props.value + 1),
|
|
1099
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronUpOutlineRegular, { size: 9 })
|
|
1100
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1101
|
+
type: "button",
|
|
1102
|
+
className: "font-stepper-arrow",
|
|
1103
|
+
"aria-label": props.decreaseLabel,
|
|
1104
|
+
disabled: props.value <= min,
|
|
1105
|
+
onClick: () => props.onCommit(props.role, props.value - 1),
|
|
1106
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { size: 9 })
|
|
1107
|
+
})]
|
|
1108
|
+
})]
|
|
1109
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1110
|
+
className: "font-stepper-unit",
|
|
1111
|
+
children: props.unit
|
|
1112
|
+
})]
|
|
1113
|
+
})]
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/** The plugin's own settings page (Settings → Font): every font control in one
|
|
1117
|
+
* column — interface family, conversation family + content size, code family +
|
|
1118
|
+
* size, terminal family + size — followed by the shared actions. It writes the
|
|
1119
|
+
* same theme service entries the native General font-size cell uses, so sizes
|
|
1120
|
+
* and families stay in sync with any other writer (keyboard zoom included). */
|
|
1121
|
+
function FontSettingsGroup(props) {
|
|
796
1122
|
const locale = useLocale(props.client);
|
|
797
1123
|
const text = COPY[locale];
|
|
798
|
-
const
|
|
1124
|
+
const snapshot = (0, react.useSyncExternalStore)((fn) => props.client.on("theme/change", () => fn()), () => props.client.theme.getTheme(), () => props.client.theme.getTheme());
|
|
799
1125
|
const settings = {
|
|
800
|
-
uiFont:
|
|
801
|
-
codeFont:
|
|
1126
|
+
uiFont: snapshot.fontFamilies.text,
|
|
1127
|
+
codeFont: snapshot.fontFamilies.code
|
|
802
1128
|
};
|
|
803
|
-
const
|
|
1129
|
+
const terminalFont = snapshot.fontFamilies.terminal;
|
|
1130
|
+
const conversationFont = (0, react.useSyncExternalStore)((fn) => props.conversation.subscribe(fn), () => props.conversation.get(), () => props.conversation.get());
|
|
804
1131
|
const [fontList, setFontList] = (0, react.useState)({
|
|
805
1132
|
state: "idle",
|
|
806
1133
|
families: []
|
|
@@ -832,21 +1159,27 @@ function FontSettingsPanel(props) {
|
|
|
832
1159
|
}));
|
|
833
1160
|
}
|
|
834
1161
|
}
|
|
835
|
-
function
|
|
836
|
-
|
|
837
|
-
if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
|
|
1162
|
+
function updateFamily(role, value) {
|
|
1163
|
+
props.client.theme.setFontFamily(role, normalizeFontFamily(value));
|
|
838
1164
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1165
|
+
function updateSize(role, px) {
|
|
1166
|
+
props.client.theme.setFontSize(role, px);
|
|
1167
|
+
}
|
|
1168
|
+
const sizeField = (role, label, help) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSizeField, {
|
|
1169
|
+
label,
|
|
1170
|
+
help,
|
|
1171
|
+
role,
|
|
1172
|
+
value: snapshot.fontSizes[role],
|
|
1173
|
+
locale,
|
|
1174
|
+
increaseLabel: text.increaseSize(label),
|
|
1175
|
+
decreaseLabel: text.decreaseSize(label),
|
|
1176
|
+
unit: text.sizeUnit,
|
|
1177
|
+
onCommit: updateSize
|
|
845
1178
|
});
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
1179
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1180
|
+
className: "font-root",
|
|
1181
|
+
role: "group",
|
|
1182
|
+
"aria-label": text.label,
|
|
850
1183
|
"data-testid": "font-settings",
|
|
851
1184
|
children: [
|
|
852
1185
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
@@ -861,8 +1194,23 @@ function FontSettingsPanel(props) {
|
|
|
861
1194
|
customLabel: text.customOption,
|
|
862
1195
|
customPlaceholder: text.customUiPlaceholder,
|
|
863
1196
|
systemGroupLabel: text.systemGroup,
|
|
864
|
-
onCommit: (value) =>
|
|
1197
|
+
onCommit: (value) => updateFamily("text", value)
|
|
865
1198
|
}),
|
|
1199
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
1200
|
+
label: text.conversationFont,
|
|
1201
|
+
help: text.conversationHelp,
|
|
1202
|
+
value: conversationFont,
|
|
1203
|
+
presets: UI_FONT_PRESETS,
|
|
1204
|
+
locale,
|
|
1205
|
+
generic: "sans-serif",
|
|
1206
|
+
systemFonts: fontList.families,
|
|
1207
|
+
defaultLabel: text.followUi,
|
|
1208
|
+
customLabel: text.customOption,
|
|
1209
|
+
customPlaceholder: text.customConversationPlaceholder,
|
|
1210
|
+
systemGroupLabel: text.systemGroup,
|
|
1211
|
+
onCommit: (value) => props.conversation.set(value)
|
|
1212
|
+
}),
|
|
1213
|
+
sizeField("text", text.textSize, text.textSizeHelp),
|
|
866
1214
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
867
1215
|
label: text.codeFont,
|
|
868
1216
|
help: text.codeHelp,
|
|
@@ -875,79 +1223,88 @@ function FontSettingsPanel(props) {
|
|
|
875
1223
|
customLabel: text.customOption,
|
|
876
1224
|
customPlaceholder: text.customCodePlaceholder,
|
|
877
1225
|
systemGroupLabel: text.systemGroup,
|
|
878
|
-
onCommit: (value) =>
|
|
1226
|
+
onCommit: (value) => updateFamily("code", value)
|
|
879
1227
|
}),
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
} catch {}
|
|
895
|
-
},
|
|
896
|
-
children: sizes.map((px) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("option", {
|
|
897
|
-
value: px,
|
|
898
|
-
children: [px, "px"]
|
|
899
|
-
}, px))
|
|
900
|
-
}),
|
|
901
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
902
|
-
className: "dsh-ui-help",
|
|
903
|
-
children: text.sizeHelp
|
|
904
|
-
})
|
|
905
|
-
]
|
|
1228
|
+
sizeField("code", text.codeSize, text.codeSizeHelp),
|
|
1229
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
1230
|
+
label: text.terminalFont,
|
|
1231
|
+
help: text.terminalHelp,
|
|
1232
|
+
value: terminalFont,
|
|
1233
|
+
presets: CODE_FONT_PRESETS,
|
|
1234
|
+
locale,
|
|
1235
|
+
generic: "monospace",
|
|
1236
|
+
systemFonts: fontList.families,
|
|
1237
|
+
defaultLabel: text.defaultOption,
|
|
1238
|
+
customLabel: text.customOption,
|
|
1239
|
+
customPlaceholder: text.customTerminalPlaceholder,
|
|
1240
|
+
systemGroupLabel: text.systemGroup,
|
|
1241
|
+
onCommit: (value) => updateFamily("terminal", value)
|
|
906
1242
|
}),
|
|
1243
|
+
sizeField("terminal", text.terminalSize, text.terminalSizeHelp),
|
|
907
1244
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
908
|
-
className: "
|
|
909
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1245
|
+
className: "font-row",
|
|
1246
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1247
|
+
className: "font-row-text",
|
|
1248
|
+
children: [
|
|
1249
|
+
fontList.state === "ready" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1250
|
+
className: "font-row-desc",
|
|
1251
|
+
role: "status",
|
|
1252
|
+
children: text.fontsLoaded(fontList.families.length)
|
|
1253
|
+
}) : null,
|
|
1254
|
+
fontList.state === "ready" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1255
|
+
className: "font-row-desc",
|
|
1256
|
+
role: "status",
|
|
1257
|
+
children: text.fontsPartial
|
|
1258
|
+
}) : null,
|
|
1259
|
+
fontList.state === "denied" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1260
|
+
className: "font-row-desc",
|
|
1261
|
+
role: "status",
|
|
1262
|
+
children: text.fontsDenied
|
|
1263
|
+
}) : null
|
|
1264
|
+
]
|
|
1265
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1266
|
+
className: "font-row-control",
|
|
1267
|
+
children: [
|
|
1268
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
1269
|
+
variant: "outline",
|
|
1270
|
+
size: "sm",
|
|
1271
|
+
disabled: fontList.state === "loading",
|
|
1272
|
+
onClick: () => {
|
|
1273
|
+
loadSystemFonts();
|
|
1274
|
+
},
|
|
1275
|
+
children: fontList.state === "loading" ? text.loadingFonts : fontList.state === "ready" ? text.reloadFonts : text.loadFonts
|
|
1276
|
+
}),
|
|
1277
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
1278
|
+
variant: "outline",
|
|
1279
|
+
size: "sm",
|
|
1280
|
+
onClick: () => {
|
|
1281
|
+
updateFamily("text", "");
|
|
1282
|
+
updateFamily("code", "");
|
|
1283
|
+
updateFamily("terminal", "");
|
|
1284
|
+
props.conversation.set("");
|
|
1285
|
+
},
|
|
1286
|
+
children: text.resetFonts
|
|
1287
|
+
}),
|
|
1288
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
1289
|
+
variant: "outline",
|
|
1290
|
+
size: "sm",
|
|
1291
|
+
onClick: () => {
|
|
1292
|
+
updateSize("text", FONT_SIZE_SPECS.text.default);
|
|
1293
|
+
updateSize("code", FONT_SIZE_SPECS.code.default);
|
|
1294
|
+
updateSize("terminal", FONT_SIZE_SPECS.terminal.default);
|
|
1295
|
+
},
|
|
1296
|
+
children: text.resetSizes
|
|
1297
|
+
})
|
|
1298
|
+
]
|
|
928
1299
|
})]
|
|
929
|
-
})
|
|
930
|
-
fontList.state === "ready" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
931
|
-
role: "status",
|
|
932
|
-
className: "dsh-ui-hint",
|
|
933
|
-
children: text.fontsLoaded(fontList.families.length)
|
|
934
|
-
}) : null,
|
|
935
|
-
fontList.state === "ready" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
936
|
-
role: "status",
|
|
937
|
-
className: "dsh-ui-hint",
|
|
938
|
-
children: text.fontsPartial
|
|
939
|
-
}) : null,
|
|
940
|
-
fontList.state === "denied" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
941
|
-
role: "status",
|
|
942
|
-
className: "dsh-ui-hint",
|
|
943
|
-
children: text.fontsDenied
|
|
944
|
-
}) : null
|
|
1300
|
+
})
|
|
945
1301
|
]
|
|
946
1302
|
});
|
|
947
1303
|
}
|
|
948
1304
|
function apply(ctx) {
|
|
949
1305
|
const client = ctx;
|
|
950
1306
|
const store = createFontSettingsStore(readStorage());
|
|
1307
|
+
const conversation = createConversationFontStore(readStorage());
|
|
951
1308
|
migrateFontPreferences(client.theme, store, readStorage());
|
|
952
1309
|
ctx.effect(() => {
|
|
953
1310
|
if (typeof document === "undefined") return () => {};
|
|
@@ -957,17 +1314,52 @@ function apply(ctx) {
|
|
|
957
1314
|
document.head.appendChild(style);
|
|
958
1315
|
return () => style.remove();
|
|
959
1316
|
}, "font.styles");
|
|
960
|
-
ctx.effect(() =>
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1317
|
+
ctx.effect(() => {
|
|
1318
|
+
if (typeof document === "undefined") return () => {};
|
|
1319
|
+
const style = document.createElement("style");
|
|
1320
|
+
style.setAttribute("data-plugin", PLUGIN_NAME);
|
|
1321
|
+
style.setAttribute("data-font-role", "conversation");
|
|
1322
|
+
document.head.appendChild(style);
|
|
1323
|
+
const write = () => {
|
|
1324
|
+
const sheet = style.sheet;
|
|
1325
|
+
if (!sheet) return;
|
|
1326
|
+
while (sheet.cssRules.length > 0) sheet.deleteRule(0);
|
|
1327
|
+
const declarations = conversationFontDeclarations(conversation.get(), fontTokenDeclarations(document.styleSheets ?? []));
|
|
1328
|
+
if (declarations.length === 0) return;
|
|
1329
|
+
sheet.insertRule(`${CONVERSATION_FONT_SELECTOR}{}`);
|
|
1330
|
+
const rule = sheet.cssRules[0];
|
|
1331
|
+
for (const [name, value] of declarations) rule.style.setProperty(name, value);
|
|
1332
|
+
};
|
|
1333
|
+
write();
|
|
1334
|
+
const unsubscribe = conversation.subscribe(write);
|
|
1335
|
+
return () => {
|
|
1336
|
+
unsubscribe();
|
|
1337
|
+
style.remove();
|
|
1338
|
+
};
|
|
1339
|
+
}, "font.conversation");
|
|
1340
|
+
ctx.effect(() => client.slots.inject("settings.section", () => [
|
|
1341
|
+
client.slots.register({
|
|
1342
|
+
name: "settings.section",
|
|
1343
|
+
id: "font",
|
|
1344
|
+
order: 5,
|
|
1345
|
+
label: () => client.locale.getSnapshot().active.toLowerCase().startsWith("zh") ? COPY.zh.label : COPY.en.label
|
|
1346
|
+
}, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsGroup, {
|
|
1347
|
+
client,
|
|
1348
|
+
conversation
|
|
1349
|
+
})),
|
|
1350
|
+
client.slots.inject("settings.general.item", () => client.slots.register({
|
|
1351
|
+
name: "settings.general.item",
|
|
1352
|
+
id: "font-size",
|
|
1353
|
+
order: 11,
|
|
1354
|
+
priority: -10
|
|
1355
|
+
}, () => null)),
|
|
1356
|
+
registerSettingsSectionIcon(ctx, "font", 5, IconFontSettings)
|
|
1357
|
+
]), "font.settings");
|
|
967
1358
|
}
|
|
968
1359
|
//#endregion
|
|
969
1360
|
exports.FontField = FontField;
|
|
970
|
-
exports.
|
|
1361
|
+
exports.FontSettingsGroup = FontSettingsGroup;
|
|
1362
|
+
exports.FontSizeField = FontSizeField;
|
|
971
1363
|
exports.apply = apply;
|
|
972
1364
|
exports.fontCopy = fontCopy;
|
|
973
1365
|
exports.inject = inject;
|