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