@klarkxy/dsh-font 0.2.0 → 0.2.1
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 +2 -2
- package/docs/README.zh-CN.md +3 -3
- package/lib/client.inner.cjs +18 -5
- package/lib/client.inner.cjs.map +1 -1
- package/lib/client.js +18 -5
- package/lib/contracts.d.ts +3 -2
- package/lib/contracts.js +3 -2
- package/lib/contracts.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,14 +21,14 @@ Open **Plugins → Font**:
|
|
|
21
21
|
- **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.
|
|
22
22
|
- **Conversation font size**: 10–22 px, kept in sync with **Settings → General**.
|
|
23
23
|
|
|
24
|
-
Changes apply immediately and stay in sync with DSH settings. Choose **Default** to
|
|
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.
|
|
25
25
|
|
|
26
26
|
Code font applies to code blocks and inline code. Terminal font and size are independent; adjust them in **Settings → General**.
|
|
27
27
|
|
|
28
28
|
## Limits
|
|
29
29
|
|
|
30
30
|
- **Load system fonts** works only in Chromium-based browsers and asks for permission.
|
|
31
|
-
- Font choices and conversation size are saved by DSH
|
|
31
|
+
- Font choices and conversation size are saved by DSH; every computer where you open the GUI needs the chosen fonts installed.
|
|
32
32
|
- No fonts are bundled; the chosen font must be installed on the computer.
|
|
33
33
|
|
|
34
34
|
## License
|
package/docs/README.zh-CN.md
CHANGED
|
@@ -21,14 +21,14 @@ dsh plugin --profile web add @klarkxy/dsh-font
|
|
|
21
21
|
- **界面字体**和**代码字体**:选预设、手动输入字体名,或点「读取系统字体」从本机已装字体中选择。
|
|
22
22
|
- **会话字号**:10–22 px,与「设置 → 通用」中的字号同步。
|
|
23
23
|
|
|
24
|
-
改动立即生效,并与 DSH
|
|
24
|
+
改动立即生效,并与 DSH 设置保持同步。选择「默认」可恢复 DSH 原字体;「全部恢复默认」重置本页的两项字体和会话字号。
|
|
25
25
|
|
|
26
26
|
代码字体作用于代码块和行内代码。终端字体与字号独立设置,请在「设置 → 通用」中调整。
|
|
27
27
|
|
|
28
28
|
## 限制
|
|
29
29
|
|
|
30
|
-
- 「读取系统字体」只在 Chromium
|
|
31
|
-
- 字体选择和会话字号由 DSH
|
|
30
|
+
- 「读取系统字体」只在 Chromium 系浏览器可用,且需要授权。
|
|
31
|
+
- 字体选择和会话字号由 DSH 保存;在不同电脑打开界面时,每台电脑都需安装所选字体。
|
|
32
32
|
- 插件不附带字体文件,所选字体必须已安装在本机。
|
|
33
33
|
|
|
34
34
|
## 许可证
|
package/lib/client.inner.cjs
CHANGED
|
@@ -403,6 +403,17 @@ ${scope} {
|
|
|
403
403
|
/* --- Layout scaffolding. --- */
|
|
404
404
|
& .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }
|
|
405
405
|
& .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }
|
|
406
|
+
/* Plugin detail pages share one reading column. These are layout recipes;
|
|
407
|
+
* controls keep their own primitive styles. Form spacing follows the host's
|
|
408
|
+
* settings-form/fields.module.css and SettingsForm.module.css. */
|
|
409
|
+
& .dsh-ui-page { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 760px; min-width: 0; }
|
|
410
|
+
& .dsh-ui-form { display: flex; flex-direction: column; gap: 0; min-width: 0; }
|
|
411
|
+
&.dsh-ui-form > .dsh-ui-field, & .dsh-ui-form > .dsh-ui-field { padding: 12px 0; }
|
|
412
|
+
& .dsh-ui-form-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 16px; min-width: 0; }
|
|
413
|
+
& .dsh-ui-fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
414
|
+
@media (max-width: 560px) {
|
|
415
|
+
& .dsh-ui-fields-grid { grid-template-columns: minmax(0, 1fr); }
|
|
416
|
+
}
|
|
406
417
|
& .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
407
418
|
& .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
|
408
419
|
& .dsh-ui-spacer { flex: 1; min-width: 0; }
|
|
@@ -430,6 +441,9 @@ ${scope} {
|
|
|
430
441
|
* official primitive, so this only owns the vertical rhythm. --- */
|
|
431
442
|
& .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
432
443
|
& .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }
|
|
444
|
+
/* Grid fields share a row, so the stacked-field divider must not win later in
|
|
445
|
+
* the cascade. Reset it here, after the field recipe. */
|
|
446
|
+
& .dsh-ui-fields-grid > .dsh-ui-field { padding: 0; border: 0; }
|
|
433
447
|
& .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
434
448
|
& .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
435
449
|
& .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
|
|
@@ -620,7 +634,7 @@ ${scope} {
|
|
|
620
634
|
& *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
|
|
621
635
|
}
|
|
622
636
|
}
|
|
623
|
-
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(
|
|
637
|
+
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?=\s*\{)/gm, (_match, className) => `&${className}, & ${className}`);
|
|
624
638
|
}
|
|
625
639
|
//#endregion
|
|
626
640
|
//#region src/client.tsx
|
|
@@ -682,8 +696,7 @@ function fontCopy(locale) {
|
|
|
682
696
|
return COPY[locale];
|
|
683
697
|
}
|
|
684
698
|
const styles = `${officialUiCss("font-root")}
|
|
685
|
-
.font-root {
|
|
686
|
-
.font-custom { margin-top: 8px; }
|
|
699
|
+
.font-root .font-custom { margin-top: 8px; }
|
|
687
700
|
`;
|
|
688
701
|
function readStorage() {
|
|
689
702
|
try {
|
|
@@ -833,7 +846,7 @@ function FontSettingsPanel(props) {
|
|
|
833
846
|
const sizes = [];
|
|
834
847
|
for (let px = 10; px <= 22; px += 1) sizes.push(px);
|
|
835
848
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
836
|
-
className: "font-root dsh-ui-
|
|
849
|
+
className: "font-root dsh-ui-page dsh-ui-form",
|
|
837
850
|
"data-testid": "font-settings",
|
|
838
851
|
children: [
|
|
839
852
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
@@ -892,7 +905,7 @@ function FontSettingsPanel(props) {
|
|
|
892
905
|
]
|
|
893
906
|
}),
|
|
894
907
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
895
|
-
className: "dsh-ui-
|
|
908
|
+
className: "dsh-ui-form-footer",
|
|
896
909
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
897
910
|
variant: "outline",
|
|
898
911
|
size: "md",
|
package/lib/client.inner.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.inner.cjs","names":["useSyncExternalStore","useState","Input","Button"],"sources":["../src/contracts.ts","../src/preferences.ts","../../dsh-plugin-kit/src/official-ui.ts","../src/client.tsx"],"sourcesContent":["/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,\n * normalization, the CSS-variable application core, and the local store.\n * No React, no cordis — every export runs in Node tests and the browser. */\n\nexport const PLUGIN_NAME = '@klarkxy/dsh-font'\n\n/** Legacy browser-local font choices, retained as the one-time migration backup.\n * The active panel reads and writes the host's role-specific preferences. */\nexport const STORAGE_KEY = 'klarkxy.dsh-font.v1'\n\n/** Host text-role bounds, shared by the native conversation-size stepper. */\nexport const FONT_SIZE_MIN = 10\nexport const FONT_SIZE_MAX = 22\nexport const FONT_SIZE_DEFAULT = 14\n\n/** DSH rc.2 defines these font stacks on :root. Root inline overrides also\n * reach derived Markdown, brand and terminal font tokens. */\nexport const UI_FONT_VARIABLE = '--dsw-font-family'\nexport const CODE_FONT_VARIABLE = '--ds-font-family-code'\n\nexport interface FontSettings {\n /** Full CSS font-family stack for the interface; empty keeps the host default. */\n uiFont: string\n /** Full CSS font-family stack for code blocks, inline code and terminals. */\n codeFont: string\n}\n\nexport function defaultFontSettings(): FontSettings {\n return { uiFont: '', codeFont: '' }\n}\n\n/** A raw font-family string is placed into a single CSS declaration via\n * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but\n * trimming control characters and the CSS delimiters keeps pasted garbage from\n * producing a silently-dead value. */\nexport function normalizeFontFamily(value: unknown): string {\n if (typeof value !== 'string') return ''\n return value\n .replace(/[\\u0000-\\u001F\\u007F;{}<>]/g, '')\n .trim()\n .slice(0, 300)\n}\n\nexport function parseFontSettings(raw: unknown): FontSettings {\n let source = raw\n if (typeof source === 'string') {\n try {\n source = JSON.parse(source)\n } catch {\n return defaultFontSettings()\n }\n }\n if (!source || typeof source !== 'object' || Array.isArray(source)) return defaultFontSettings()\n const record = source as Record<string, unknown>\n return {\n uiFont: normalizeFontFamily(record.uiFont),\n codeFont: normalizeFontFamily(record.codeFont),\n }\n}\n\nexport function serializeFontSettings(settings: FontSettings): string {\n return JSON.stringify({\n uiFont: normalizeFontFamily(settings.uiFont),\n codeFont: normalizeFontFamily(settings.codeFont),\n })\n}\n\nexport interface FontPreset {\n readonly id: string\n readonly label: { readonly zh: string; readonly en: string }\n /** The font-family stack committed when the preset is picked. */\n readonly value: string\n}\n\nexport const UI_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'yahei', label: { zh: '微软雅黑', en: 'Microsoft YaHei' }, value: '\"Microsoft YaHei\", \"PingFang SC\", sans-serif' },\n { id: 'pingfang', label: { zh: '苹方', en: 'PingFang SC' }, value: '\"PingFang SC\", -apple-system, sans-serif' },\n { id: 'simsun', label: { zh: '宋体', en: 'SimSun' }, value: '\"SimSun\", \"Songti SC\", serif' },\n { id: 'kaiti', label: { zh: '楷体', en: 'KaiTi' }, value: '\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif' },\n { id: 'source-han-sans', label: { zh: '思源黑体', en: 'Source Han Sans' }, value: '\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif' },\n { id: 'source-han-serif', label: { zh: '思源宋体', en: 'Source Han Serif' }, value: '\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif' },\n]\n\nexport const CODE_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'cascadia', label: { zh: 'Cascadia', en: 'Cascadia' }, value: '\"Cascadia Mono\", \"Cascadia Code\", monospace' },\n { id: 'jetbrains-mono', label: { zh: 'JetBrains Mono', en: 'JetBrains Mono' }, value: '\"JetBrains Mono\", monospace' },\n { id: 'fira-code', label: { zh: 'Fira Code', en: 'Fira Code' }, value: '\"Fira Code\", monospace' },\n { id: 'consolas', label: { zh: 'Consolas', en: 'Consolas' }, value: 'Consolas, monospace' },\n { id: 'sarasa', label: { zh: '更纱黑体', en: 'Sarasa Mono' }, value: '\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace' },\n { id: 'maple-mono', label: { zh: 'Maple Mono', en: 'Maple Mono' }, value: '\"Maple Mono NF CN\", \"Maple Mono\", monospace' },\n]\n\nexport function presetFor(value: string, presets: readonly FontPreset[]): FontPreset | undefined {\n // The host quotes every non-generic family when persisting a stack.\n const comparable = (stack: string) => stack.split(',').map(name => name.trim().replace(/^[\"']|[\"']$/g, '')).join(',')\n return presets.find(preset => comparable(preset.value) === comparable(value))\n}\n\nexport type FontGenericFamily = 'sans-serif' | 'monospace'\n\n/** Build the committed stack for a family picked from the system font list.\n * The family name comes from the OS (Local Font Access API); quotes and\n * backslashes are stripped so it can be safely re-quoted as one family. */\nexport function fontStackFor(family: string, generic: FontGenericFamily): string {\n const cleaned = normalizeFontFamily(family).replace(/[\"\\\\]/g, '')\n if (!cleaned) return generic\n return `\"${cleaned}\", ${generic}`\n}\n\n/** A system font offered in the picker: `family` is the exact name CSS\n * matching needs; `fullName` is an informative localized alias (e.g. converted\n * CJK fonts whose family is the Latin alias), '' when it only restates the\n * family (\"Microsoft YaHei Regular\" adds nothing). */\nexport interface SystemFontFamily {\n readonly family: string\n readonly fullName: string\n}\n\n/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()\n * result (entries carry `family` and `fullName`; duplicates per style are\n * expected). */\nexport function uniqueSystemFonts(fonts: readonly unknown[]): SystemFontFamily[] {\n const byFamily = new Map<string, string>()\n for (const item of fonts) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) continue\n const record = item as Record<string, unknown>\n const family = normalizeFontFamily(record.family).replace(/[\"\\\\]/g, '')\n if (!family || byFamily.has(family)) continue\n const fullName = normalizeFontFamily(record.fullName).replace(/[\"\\\\]/g, '')\n byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : '')\n }\n return [...byFamily.entries()]\n .map(([family, fullName]) => ({ family, fullName }))\n .sort((a, b) => a.family.localeCompare(b.family))\n}\n\n/** Picker label: the UI locale's recognizable name leads, the alias stays in\n * parentheses because the canonical family is still what a custom input needs. */\nexport function systemFontLabel(item: SystemFontFamily, locale: 'zh' | 'en'): string {\n if (!item.fullName) return item.family\n return locale === 'zh' ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`\n}\n\n/** Minimal write face of CSSStyleDeclaration — document.documentElement.style\n * satisfies it, and tests supply a recording double. */\nexport interface FontStyleTarget {\n setProperty(name: string, value: string): void\n removeProperty(name: string): void\n}\n\nexport function applyFontSettings(style: FontStyleTarget, settings: FontSettings): void {\n if (settings.uiFont) style.setProperty(UI_FONT_VARIABLE, settings.uiFont)\n else style.removeProperty(UI_FONT_VARIABLE)\n if (settings.codeFont) style.setProperty(CODE_FONT_VARIABLE, settings.codeFont)\n else style.removeProperty(CODE_FONT_VARIABLE)\n}\n\nexport function clearFontSettings(style: FontStyleTarget): void {\n style.removeProperty(UI_FONT_VARIABLE)\n style.removeProperty(CODE_FONT_VARIABLE)\n}\n\n/** Read face required to restore only overrides still owned by this instance. */\nexport interface OwnedFontStyleTarget extends FontStyleTarget {\n getPropertyValue(name: string): string\n getPropertyPriority(name: string): string\n setProperty(name: string, value: string, priority?: string): void\n}\n\n/** Root inline overrides preserve the existing local persistence/unload\n * boundary. Save the underlying value (including !important) on first write\n * or when the host replaces a value, and never retract somebody else's write. */\nexport function createFontSettingsOverride(style: OwnedFontStyleTarget) {\n const owned = new Map<string, { previous: string; priority: string; value: string }>()\n function release(name: string) {\n const entry = owned.get(name)\n if (!entry) return\n if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === '') {\n if (entry.previous) style.setProperty(name, entry.previous, entry.priority)\n else style.removeProperty(name)\n }\n owned.delete(name)\n }\n return {\n apply(settings: FontSettings) {\n for (const [name, value] of [\n [UI_FONT_VARIABLE, settings.uiFont],\n [CODE_FONT_VARIABLE, settings.codeFont],\n ] as const) {\n if (!value) { release(name); continue }\n const current = style.getPropertyValue(name)\n const priority = style.getPropertyPriority(name)\n const entry = owned.get(name)\n if (!entry || current !== entry.value || priority !== '') {\n owned.set(name, { previous: current, priority, value: '' })\n }\n style.setProperty(name, value)\n owned.get(name)!.value = style.getPropertyValue(name)\n }\n },\n dispose() { for (const name of [...owned.keys()]) release(name) },\n }\n}\n\nexport interface FontSettingsStorage {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface FontSettingsStore {\n load(): FontSettings\n save(next: FontSettings): void\n}\n\n/** Browser-local persistence. A fully-default setting removes the key so a\n * reset leaves no residue; storage failures (private mode, quota) degrade to\n * in-memory behaviour rather than breaking the panel. */\nexport function createFontSettingsStore(storage: FontSettingsStorage | undefined): FontSettingsStore {\n let current = defaultFontSettings()\n // A failed local write must win over stale persisted values on page remount.\n // Successful writes restore the existing ability to read external updates.\n let pendingPersistence = false\n return {\n load() {\n if (storage && !pendingPersistence) {\n try {\n current = parseFontSettings(storage.getItem(STORAGE_KEY))\n } catch {\n /* keep the last readable or locally saved snapshot */\n }\n }\n return { ...current }\n },\n save(next) {\n current = parseFontSettings(next)\n if (!storage) return\n pendingPersistence = true\n try {\n if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY)\n else storage.setItem(STORAGE_KEY, serializeFontSettings(current))\n pendingPersistence = false\n } catch {\n /* stay in-memory */\n }\n },\n }\n}\n","import { type FontSettingsStore, type FontSettingsStorage, normalizeFontFamily } from './contracts.ts'\n\nexport type FontRole = 'text' | 'code' | 'terminal'\nexport interface FontThemeSnapshot {\n fontSizes: Record<FontRole, number>\n fontFamilies: Record<FontRole, string>\n}\nexport interface FontTheme {\n getTheme(): FontThemeSnapshot\n setFontSize(role: FontRole, px: number): void\n setFontFamily(role: FontRole, value: string): void\n}\nexport const MIGRATION_KEY = 'klarkxy.dsh-font.host-preferences.v1'\n\n/** Preserve the old selection as a backup, but never replay it over native\n * preferences on subsequent loads. Each role migrates independently. */\nexport function migrateFontPreferences(theme: FontTheme, store: FontSettingsStore, storage?: FontSettingsStorage): void {\n try { if (storage?.getItem(MIGRATION_KEY)) return } catch { return }\n const old = store.load()\n const families = theme.getTheme().fontFamilies\n for (const [role, value] of [['text', old.uiFont], ['code', old.codeFont], ['terminal', old.codeFont]] as const) {\n if (!families[role] && normalizeFontFamily(value)) theme.setFontFamily(role, value)\n }\n try { storage?.setItem(MIGRATION_KEY, '1') } catch { /* Host preferences still protect migrated nonempty roles. */ }\n}\n","/**\n * Shared contract that keeps every plugin's browser-side UI on the official\n * DeepSeek Harness Web design language.\n *\n * Two rules produce that language, and both are load-bearing here:\n *\n * 1. Colour, radius, elevation and focus come from the host theme's real\n * `--dsw-*` tokens, written under their own names. Plugins never invent a\n * token, never alias the official ones behind a private palette (a private\n * alias is just a second, diverging theme), and never carries a literal\n * fallback — the host publishes light and dark, and a literal would pin one\n * of them. The only non-colour custom properties used are the host's own\n * content-font axis and frame clearance.\n *\n * 2. Anything the host already ships is used, not reimplemented. Controls come\n * from `@deepseek-ai/dsh-client-ui-primitives` (`Button`, `Input`,\n * `Checkbox`, `Switch`, `Tag`, `Pill`, `SegmentedControl`, `Menu`, `Modal`,\n * `Tooltip`, `Toast`, `DisclosureRow`, `StateDot`, `PathLabel`, the settings\n * form suite). This module only styles what primitives do not cover: page\n * scaffolding, field layout, banners, empty states and scroll regions.\n *\n * The metrics below are transcribed from the primitives' own CSS modules so a\n * feature panel lines up pixel-for-pixel with a native one: the 14/22 body and\n * 13/20 compact type tiers, the 0.5px hairline scale, and the elevation family\n * that draws a surface's edge in its shadow (`border: 0`) instead of a border.\n */\n\n/**\n * Every `--dsw-*` token this repo is allowed to reference, grouped by role.\n *\n * Plugins may only colour through this list. It is exported so the guard test\n * can fail a build when a stylesheet reaches for anything else — the failure\n * mode this prevents is silent: an unknown token resolves to nothing, so a\n * border disappears or a label inherits the wrong colour with no error anywhere.\n */\nexport const OFFICIAL_THEME_TOKENS = {\n /** Surfaces, from the page up to the topmost nested card. */\n surface: [\n '--dsw-alias-bg-base',\n '--dsw-alias-bg-layer-1',\n '--dsw-alias-bg-layer-2',\n '--dsw-alias-bg-layer-3',\n '--dsw-alias-bg-layer-4',\n '--dsw-alias-bg-module-platform',\n '--dsw-alias-bg-overlay',\n ],\n /** Hairlines. l1 is near-invisible on a menu surface, so menus use l2+. */\n border: ['--dsw-alias-border-l1', '--dsw-alias-border-l2', '--dsw-alias-border-l3', '--dsw-alias-border-l4'],\n /** Text. `caption` is menu shortcut text, `dimmed` is placeholder text. */\n label: [\n '--dsw-alias-label-primary',\n '--dsw-alias-label-secondary',\n '--dsw-alias-label-tertiary',\n '--dsw-alias-label-caption',\n '--dsw-alias-label-dimmed',\n '--dsw-alias-label-error',\n '--dsw-alias-label-primary-foreground',\n ],\n /** Interactive fills. The `-danger` hover belongs to destructive rows. */\n interactive: [\n '--dsw-alias-interactive-bg-hover',\n '--dsw-alias-interactive-bg-active',\n '--dsw-alias-interactive-bg-hover-danger',\n ],\n /** Accent and status. `business` is the focus ring's default colour. */\n accent: [\n '--dsw-alias-brand-primary',\n '--dsw-alias-button-primary-fill',\n '--dsw-alias-button-primary-hover',\n '--dsw-alias-button-tool-bar-fill',\n '--dsw-alias-button-tool-bar-hover',\n '--dsw-alias-button-ghost-active-fill',\n '--dsw-alias-button-ghost-active-border',\n ],\n state: [\n '--dsw-alias-state-business-primary',\n '--dsw-alias-state-success-primary',\n '--dsw-alias-state-warn-primary',\n '--dsw-alias-state-error-primary',\n '--dsw-alias-state-idle-primary',\n ],\n /** Corner scale: sm 8, md 12, lg the large card, panel the modal. */\n radius: ['--dsw-radius-sm', '--dsw-radius-md', '--dsw-radius-lg', '--dsw-radius-panel'],\n /** An elevated surface draws its edge in the shadow, so it keeps border: 0. */\n elevation: [\n '--dsw-elevation-soft',\n '--dsw-elevation-stroke',\n '--dsw-elevation-stroke-color',\n '--dsw-elevation-panel',\n '--dsw-elevation-prominent',\n ],\n /** Floats, masks and scrollbars. */\n overlay: [\n '--dsw-menu-surface-fill',\n '--dsw-menu-backdrop-filter',\n '--dsw-mask-blur',\n '--dsw-alias-bg-mask-1',\n '--dsw-alias-menu-icon',\n '--dsw-alias-scrollbar-bg-l2',\n '--dsw-alias-scrollbar-hover-l2',\n '--dsw-shadow-lv3',\n ],\n /** Motion, focus and type axis, published by the host rather than by a component. */\n system: [\n '--dsw-focus-ring-width',\n '--dsw-focus-ring-color',\n '--dsw-font-markdown-code-font-family',\n '--ds-transition-duration',\n '--ds-ease-in-out',\n '--ds-font-family-code',\n '--dsh-scrollbar-thumb',\n '--dsh-scrollbar-thumb-hover',\n '--dsh-content-font-size-secondary',\n '--dsh-content-font-delta',\n '--dsh-frame-top-clearance',\n ],\n} as const\n\n/** Every official token name, flat. Used by the token guard test. */\nexport const OFFICIAL_THEME_TOKEN_NAMES: readonly string[] = Object.values(OFFICIAL_THEME_TOKENS).flat()\n\n/** The elevation steps a surface can be raised by, softest first. */\nexport type OfficialElevation = 'soft' | 'stroke' | 'panel' | 'prominent'\n\n/**\n * The host's focus ring shorthand, verbatim. Writing this per control is how\n * rings drift apart; a stylesheet that draws its own focus style should use\n * {@link officialFocus} instead. The colour fallback is the host's own default.\n */\nexport const OFFICIAL_FOCUS_RING =\n 'var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary))'\n\n/**\n * A complete `outline` declaration at the official geometry. `offset` defaults\n * to the 2px the native controls use; the host's inline field rules sit at 1px\n * and a segmented tab pulls the ring inside itself at -2px.\n */\nexport function officialFocus(offset = '2px'): string {\n return `outline: ${OFFICIAL_FOCUS_RING}; outline-offset: ${offset}`\n}\n\n/**\n * An elevated surface. The host draws a raised surface's edge inside its\n * shadow rather than as a border, so a card sets `border: 0` and takes the edge\n * from the elevation — which is also why its border stays off the alias-border\n * set that a flat, non-elevated rule would use.\n */\nexport function officialElevation(level: OfficialElevation): string {\n return `border: 0; box-shadow: var(--dsw-elevation-${level})`\n}\n\n/**\n * An elevated surface whose edge should read as a specific hairline. Rebinding\n * the stroke colour is how a menu card picks l1 while a panel picks l3, without\n * the two growing apart by hand.\n */\nexport function officialStrokedElevation(level: OfficialElevation, color: string): string {\n return `--dsw-elevation-stroke-color: ${color}; ${officialElevation(level)}`\n}\n\n/**\n * The shared stylesheet for a plugin UI, scoped under that plugin's root class.\n *\n * Scoping is what keeps this safe to always-bundle into every client: the rules\n * can only match inside the plugin's own subtree, so two plugins can both mount\n * `dsh-ui-card` without either styling the other's markup.\n *\n * Each recipe matches the root element *and* its descendants, because the\n * commonest arrangement is one element that is both — a surface that carries\n * the root class and `dsh-ui-card`, or a portaled dialog that is the root and\n * the `dsh-ui-surface`. A descendant-only scope would silently leave those\n * unstyled, with no error anywhere.\n *\n * A caveat worth knowing: `Modal` and `Menu` portal to `document.body`, so their\n * content leaves the plugin's subtree entirely. A portaled surface therefore\n * needs its own root class on an element inside the portal.\n *\n * Only patterns that primitives do not provide live here. If a control appears\n * below that `Button`/`Input`/`Switch`/`Tag`/`Menu` already covers, that is a\n * bug in this file: use the primitive and delete the recipe.\n */\nexport function officialUiCss(roots: string | readonly string[]): string {\n // One plugin often mounts several unrelated surfaces (a settings seat, a chat\n // card, a header menu), so the caller names every root. The rules below are\n // nested under a single selector list and use `&`, which the browser expands\n // per root — so one stylesheet covers all of them without duplicating itself.\n const scope = (typeof roots === 'string' ? [roots] : roots).map(root => `.${root}`).join(', ')\n const sheet = `\n/* Official DSH Web UI contract. Generated by @klarkxy/dsh-plugin-kit/official-ui.\n * Do not hand-edit the copy inside a plugin: change this module so every plugin\n * moves together. Scope: ${scope} */\n/* The scope rule below stays open for the whole sheet: every rule after it\n * nests with the parent selector, so one stylesheet can cover several unrelated\n * roots without leaking into a neighbouring plugin. Its closing brace is last. */\n${scope} {\n color: var(--dsw-alias-label-primary);\n font-family: inherit;\n font-size: 14px;\n line-height: 22px;\n min-width: 0;\n\n& *, & *::before, & *::after { box-sizing: border-box; }\n& h1, & h2, & h3, & h4, & p, & figure { margin: 0; }\n/* Keyboard focus only: pointer input keeps the native resting appearance. The\n * ring needs no radius of its own — the outline already follows the control's\n * own border-radius, and overriding it here would flatten every control. */\n& :focus-visible { ${officialFocus()}; }\n& [hidden] { display: none !important; }\n\n/* --- Type tiers. The same 14/22 and 13/20 steps the primitives use. --- */\n& .dsh-ui-title { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-heading { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-compact { font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-meta { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }\n& .dsh-ui-hint { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-error { font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-warn { color: var(--dsw-alias-state-warn-primary); }\n& .dsh-ui-success { color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-muted { color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n& .dsh-ui-wrap { min-width: 0; overflow-wrap: anywhere; }\n\n/* --- Layout scaffolding. --- */\n& .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }\n& .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }\n& .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }\n& .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }\n& .dsh-ui-spacer { flex: 1; min-width: 0; }\n/* A 0.5px l2 rule is the host's section divider; reserve the same rhythm. */\n& .dsh-ui-divider { height: 0.5px; background: var(--dsw-alias-border-l2); }\n& .dsh-ui-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n\n/* --- Card: a raised surface whose edge lives in the shadow. --- */\n& .dsh-ui-card {\n ${officialElevation('stroke')}\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 16px;\n border-radius: var(--dsw-radius-lg);\n background: var(--dsw-alias-bg-layer-1);\n color: var(--dsw-alias-label-primary);\n min-width: 0;\n}\n& .dsh-ui-card--flat { border: 0.5px solid var(--dsw-alias-border-l3); box-shadow: none; }\n& .dsh-ui-card--nested { background: var(--dsw-alias-bg-layer-2); }\n& .dsh-ui-card--plain { background: none; }\n\n/* --- Field: label, control, help, error. The control itself is an\n * official primitive, so this only owns the vertical rhythm. --- */\n& .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n& .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }\n& .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }\n& .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }\n& .dsh-ui-help p { margin: 0; }\n& .dsh-ui-help p + p { margin-top: 8px; }\n& .dsh-ui-required { color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-control { width: 100%; min-width: 0; }\n/* An invalid control is marked on the control, not only in the message. */\n& .dsh-ui-control[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-readonly { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n& .dsh-ui-readonly > dt { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-readonly > dd { margin: 0; font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }\n\n/* --- Buttons row. A no-op container: it exists so actions line up on the\n * trailing edge the way every native panel does. --- */\n& .dsh-ui-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 4px; }\n& .dsh-ui-actions-end { justify-content: flex-end; }\n\n/* --- Banners. A banner is a left-rail notice, the shape used for warnings,\n * deprecations and blocking instructions. --- */\n& .dsh-ui-banner {\n display: flex;\n flex-direction: column;\n gap: 8px;\n padding: 10px 14px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-left: 3px solid var(--dsw-alias-state-warn-primary);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n}\n& .dsh-ui-banner-title { font-weight: 500; color: var(--dsw-alias-state-warn-primary); }\n& .dsh-ui-banner--info { border-left-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-banner--danger { border-left-color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-banner--success { border-left-color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-banner p { margin: 0; }\n\n/* --- Inline notice: a transient confirmation with no chrome of its own. --- */\n& .dsh-ui-notice { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-notice--error { color: var(--dsw-alias-state-error-primary); }\n\n/* --- Empty and loading states. Both sit in a dashed well so an empty panel\n * reads as \"nothing here yet\" rather than as a broken layout. --- */\n& .dsh-ui-empty {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 6px;\n padding: 20px 16px;\n border: 0.5px dashed var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n}\n& .dsh-ui-loading { display: flex; align-items: center; gap: 8px; padding: 20px 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n\n/* --- Selectable list. A row is a button-sized target with a hover fill and\n * a selected fill; the name carries the weight, the description does not. --- */\n& .dsh-ui-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n& .dsh-ui-list-scroll { max-height: min(66vh, 760px); overflow-y: auto; overflow-x: hidden; }\n& .dsh-ui-list-row { border-radius: var(--dsw-radius-md); }\n& .dsh-ui-list-row:hover { background: var(--dsw-alias-interactive-bg-hover); }\n& .dsh-ui-list-row[aria-selected='true'], & .dsh-ui-list-row[data-selected] { background: var(--dsw-alias-interactive-bg-active); }\n& .dsh-ui-list-item {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 4px;\n width: 100%;\n min-width: 0;\n padding: 10px 12px;\n border: 0;\n border-radius: var(--dsw-radius-md);\n background: none;\n font: inherit;\n color: inherit;\n text-align: start;\n cursor: pointer;\n}\n& .dsh-ui-list-item:disabled { cursor: default; }\n& .dsh-ui-list-item:disabled:hover { background: none; }\n& .dsh-ui-list-name { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); overflow-wrap: anywhere; }\n& .dsh-ui-list-desc { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n\n/* --- Code and structured output. Wraps rather than scrolls, because a\n * feature panel is read rather than scanned. --- */\n& .dsh-ui-code {\n padding: 10px 12px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n font-family: var(--ds-font-family-code);\n font-size: 12px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n overflow-wrap: anywhere;\n white-space: pre-wrap;\n}\n& .dsh-ui-scroll { max-height: 60vh; overflow: auto; overscroll-behavior: contain; }\n\n/* --- A toggle row: label on the left, switch on the trailing edge. This is\n * layout only; the switch itself is the official primitive. --- */\n& .dsh-ui-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 12px 0; }\n& .dsh-ui-toggle-row + .dsh-ui-toggle-row { border-top: 0.5px solid var(--dsw-alias-border-l2); }\n& .dsh-ui-toggle-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n& .dsh-ui-toggle-label { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n\n/* --- Floating surface: a panel anchored to a trigger. This is the material\n * a menu card is made of — the translucent fill plus its backdrop blur, with\n * the edge riding inside the prominent elevation. A plugin that hand-rolls this\n * is how tokens like --dsw-specific-menu get invented; use this instead. --- */\n& .dsh-ui-surface {\n --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n position: relative;\n display: flex;\n flex-direction: column;\n border: 0;\n border-radius: var(--dsw-radius-lg);\n background: var(--dsw-menu-surface-fill);\n backdrop-filter: var(--dsw-menu-backdrop-filter);\n box-shadow: var(--dsw-elevation-prominent);\n color: var(--dsw-alias-label-primary);\n font-size: 13px;\n line-height: 20px;\n min-width: 0;\n}\n& .dsh-ui-surface-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; overflow-y: auto; }\n& .dsh-ui-surface-head { display: flex; align-items: center; gap: 8px; min-width: 0; }\n& .dsh-ui-surface-title { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n\n/* --- Native select. The primitives ship no select, so a plugin that offers a\n * closed list of choices keeps the platform control and matches the official\n * settings field geometry exactly (34px, 0.5px l4, radius-md, layer-3). A\n * SegmentedControl is the primitive to reach for when the choices are few\n * enough to show at once. --- */\n& .dsh-ui-select {\n box-sizing: border-box;\n width: 100%;\n min-width: 0;\n height: 34px;\n padding: 0 12px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-3);\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n}\n& .dsh-ui-select:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-select:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }\n& .dsh-ui-select[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n\n/* --- Native textarea. The primitives ship no textarea either, so a settings\n * prompt keeps the platform element and the same field shell as the select:\n * 0.5px l4, radius-md, layer-3, 13/1.5 type. It grows vertically instead of\n * locking to the select's 34px row. --- */\n& .dsh-ui-textarea {\n box-sizing: border-box;\n width: 100%;\n min-width: 0;\n resize: vertical;\n padding: 8px 12px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-3);\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n}\n& .dsh-ui-textarea:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-textarea:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }\n& .dsh-ui-textarea::placeholder { color: var(--dsw-alias-label-dimmed); }\n& .dsh-ui-textarea[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n\n/* Long panels scroll inside themselves instead of growing the host page. */\n& .dsh-ui-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }\n& .dsh-ui-panel-wide { max-width: 100%; }\n\n@media (prefers-reduced-motion: reduce) {\n & *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }\n}\n}\n`\n // Widen every recipe from \"a descendant of the root\" to \"the root, or one of\n // its descendants\". Written as a transform rather than by hand so no recipe\n // can be added later with only the descendant form. The pattern is narrow on\n // purpose: a leading `&` followed by one recipe class and no combinator, so\n // sibling and child rules such as `.dsh-ui-field + .dsh-ui-field` keep their\n // own meaning and are left alone.\n return sheet.replace(/^& (\\.dsh-ui-[a-z0-9-]+)(?![+>~])/gm, (_match, className: string) =>\n `&${className}, & ${className}`)\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport { migrateFontPreferences, type FontTheme, type FontThemeSnapshot } from './preferences.ts'\nimport { Button, Input } from '@deepseek-ai/dsh-client-ui-primitives'\nimport { officialUiCss } from '@klarkxy/dsh-plugin-kit/official-ui'\nimport { useState, useSyncExternalStore } from 'react'\nimport {\n CODE_FONT_PRESETS, FONT_SIZE_DEFAULT, FONT_SIZE_MAX, FONT_SIZE_MIN, PLUGIN_NAME,\n UI_FONT_PRESETS,\n createFontSettingsStore, fontStackFor, normalizeFontFamily,\n presetFor, systemFontLabel, uniqueSystemFonts,\n type FontGenericFamily, type FontPreset, type FontSettings, type FontSettingsStorage,\n type SystemFontFamily,\n} from './contracts.ts'\n\nexport const name = 'dsh-font-client'\nexport const inject = ['slots', 'theme', 'locale'] as const\n\ntype Client = {\n theme: FontTheme\n locale: { getSnapshot(): { active: string }; subscribe(fn: () => void): () => void }\n slots: {\n inject(key: string, callback: () => unknown): () => void\n register(spec: { name: string; key: string; label?: string }, render: unknown): () => void\n }\n on(event: 'theme/change', listener: (snapshot: FontThemeSnapshot) => void): () => void\n}\n\nconst COPY = {\n zh: {\n label: '字体',\n uiFont: '界面字体',\n codeFont: '代码字体',\n fontSize: '会话字号',\n defaultOption: '默认',\n customOption: '自定义…',\n customUiPlaceholder: '例如 \"Microsoft YaHei\", sans-serif',\n customCodePlaceholder: '例如 \"JetBrains Mono\", monospace',\n uiHelp: '作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。',\n codeHelp: '作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。',\n sizeHelp: '与「设置 → 通用」中的字号同步,范围 10–22。',\n loadFonts: '读取系统字体',\n reloadFonts: '重新读取系统字体',\n loadingFonts: '正在读取系统字体…',\n fontsLoaded: (count: number) => `已读取 ${count} 款系统字体;新装字体后点「重新读取」刷新列表。`,\n fontsPartial: '列表来自浏览器枚举:仅安装到当前用户的字体可能不在其中,可以直接输入字体名使用。',\n fontsDenied: '系统字体读取被拒绝或当前环境不支持,仍可手动输入字体名。',\n systemGroup: '系统字体',\n reset: '全部恢复默认',\n summary: (ui: string, code: string, size: number) => `界面 ${ui} · 代码 ${code} · ${size}px`,\n defaultName: '默认',\n },\n en: {\n label: 'Font',\n uiFont: 'Interface font',\n codeFont: 'Code font',\n fontSize: 'Conversation font size',\n defaultOption: 'Default',\n customOption: 'Custom…',\n customUiPlaceholder: 'e.g. \"Microsoft YaHei\", sans-serif',\n customCodePlaceholder: 'e.g. \"JetBrains Mono\", monospace',\n uiHelp: 'Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.',\n codeHelp: 'Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.',\n sizeHelp: 'Synced with Settings → General; 10–22 px.',\n loadFonts: 'Load system fonts',\n reloadFonts: 'Reload system fonts',\n loadingFonts: 'Loading system fonts…',\n fontsLoaded: (count: number) => `${count} installed fonts loaded; choose “Reload system fonts” after installing new ones.`,\n 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.',\n fontsDenied: 'Access to system fonts was denied or is unsupported here; you can still type a font name.',\n systemGroup: 'Installed fonts',\n reset: 'Reset all to defaults',\n summary: (ui: string, code: string, size: number) => `${ui} · ${code} · ${size}px`,\n defaultName: 'Default',\n },\n} as const\n\nexport function fontCopy(locale: 'zh' | 'en') {\n return COPY[locale]\n}\n\n/* The panel's own geometry only: reading width, and the custom-stack input row\n * rhythm. Everything visual comes from the contract recipes and primitives. */\nconst styles = `${officialUiCss('font-root')}\n.font-root { max-width: 760px; }\n.font-custom { margin-top: 8px; }\n`\n\nfunction readStorage(): FontSettingsStorage | undefined {\n try {\n return typeof localStorage === 'undefined' ? undefined : localStorage\n } catch {\n return undefined\n }\n}\n\nfunction useLocale(client: Client): 'zh' | 'en' {\n const getSnapshot = () => (client.locale.getSnapshot().active.toLowerCase().startsWith('zh') ? 'zh' : 'en') as 'zh' | 'en'\n return useSyncExternalStore(\n fn => client.locale.subscribe(fn),\n getSnapshot,\n getSnapshot,\n )\n}\n\nfunction useFontSize(client: Client): number {\n return useSyncExternalStore(\n fn => client.on('theme/change', () => fn()),\n () => client.theme.getTheme().fontSizes.text,\n () => client.theme.getTheme().fontSizes.text,\n )\n}\n\nfunction presetMode(value: string, presets: readonly FontPreset[]): string {\n return presetFor(value, presets)?.id ?? (value ? 'custom' : '')\n}\n\nexport function FontField(props: {\n label: string\n help: string\n value: string\n presets: readonly FontPreset[]\n locale: 'zh' | 'en'\n generic: FontGenericFamily\n systemFonts?: readonly SystemFontFamily[]\n defaultLabel: string\n customLabel: string\n customPlaceholder: string\n systemGroupLabel: string\n onCommit(value: string): void\n}) {\n // undefined = not editing; the input otherwise shows the committed stack.\n const [draft, setDraft] = useState<string | undefined>(undefined)\n // With an empty (default) value nothing matches \"custom\" on its own, so the\n // choice itself must be remembered until a stack is committed.\n const [customOpen, setCustomOpen] = useState(false)\n const mode = customOpen ? 'custom' : presetMode(props.value, props.presets)\n\n function commitDraft() {\n if (draft === undefined) return\n const next = normalizeFontFamily(draft)\n setDraft(undefined)\n if (!next) setCustomOpen(false)\n if (next !== props.value) props.onCommit(next)\n }\n\n return <label className=\"dsh-ui-field\">\n <span className=\"dsh-ui-label\">{props.label}</span>\n <select\n className=\"dsh-ui-select\"\n value={mode}\n onChange={event => {\n const id = event.target.value\n setDraft(undefined)\n if (id === 'custom') { setCustomOpen(true); return }\n setCustomOpen(false)\n if (id.startsWith('sys:')) { props.onCommit(fontStackFor(id.slice(4), props.generic)); return }\n const preset = props.presets.find(item => item.id === id)\n props.onCommit(preset ? preset.value : '')\n }}\n >\n <option value=\"\">{props.defaultLabel}</option>\n {props.presets.map(preset => (\n <option key={preset.id} value={preset.id}>{preset.label[props.locale]}</option>\n ))}\n <option value=\"custom\">{props.customLabel}</option>\n {props.systemFonts && props.systemFonts.length > 0 ? <optgroup label={props.systemGroupLabel}>\n {props.systemFonts.map(item => <option key={item.family} value={`sys:${item.family}`}>{systemFontLabel(item, props.locale)}</option>)}\n </optgroup> : null}\n </select>\n {mode === 'custom' ? <span className=\"font-custom\">\n <Input\n value={draft ?? props.value}\n placeholder={props.customPlaceholder}\n onChange={event => setDraft(event.target.value)}\n onBlur={commitDraft}\n onKeyDown={event => { if (event.key === 'Enter') commitDraft() }}\n />\n </span> : null}\n <span className=\"dsh-ui-help\">{props.help}</span>\n </label>\n}\n\nexport function FontSettingsPanel(props: {\n client: Client\n view?: 'summary' | 'page'\n}) {\n const locale = useLocale(props.client)\n const text = COPY[locale]\n const families = useSyncExternalStore(\n fn => props.client.on('theme/change', () => fn()),\n () => props.client.theme.getTheme().fontFamilies,\n () => props.client.theme.getTheme().fontFamilies,\n )\n const settings: FontSettings = { uiFont: families.text, codeFont: families.code }\n const fontSize = useFontSize(props.client)\n // System font list is shared by both fields: one permission prompt, one list.\n const [fontList, setFontList] = useState<{ state: 'idle' | 'loading' | 'ready' | 'denied'; families: readonly SystemFontFamily[] }>(\n { state: 'idle', families: [] },\n )\n\n async function loadSystemFonts() {\n if (fontList.state === 'loading') return\n // Every click re-enumerates: fonts installed after the first read appear\n // on the next one (the button relabels to \"reload\" once a list exists).\n // Local Font Access API: Chromium-only and gated behind a permission\n // prompt; anything else (Firefox, Safari, denied permission, Electron\n // policy) falls through to the preset + manual-input flow unchanged.\n const query = (globalThis as { queryLocalFonts?: () => Promise<readonly unknown[]> }).queryLocalFonts\n if (typeof query !== 'function') { setFontList({ state: 'denied', families: [] }); return }\n setFontList(current => ({ state: 'loading', families: current.families }))\n try {\n const fonts = await query()\n setFontList({ state: 'ready', families: uniqueSystemFonts(fonts) })\n } catch {\n setFontList(current => ({ state: 'denied', families: current.families }))\n }\n }\n\n function update(patch: Partial<FontSettings>) {\n if (patch.uiFont !== undefined) props.client.theme.setFontFamily('text', normalizeFontFamily(patch.uiFont))\n if (patch.codeFont !== undefined) props.client.theme.setFontFamily('code', normalizeFontFamily(patch.codeFont))\n }\n\n const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName)\n const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName)\n\n if (props.view === 'summary') {\n return <span className=\"font-root\" data-testid=\"font-summary\">{text.summary(uiName, codeName, fontSize)}</span>\n }\n\n const sizes: number[] = []\n for (let px = FONT_SIZE_MIN; px <= FONT_SIZE_MAX; px += 1) sizes.push(px)\n\n return <section className=\"font-root dsh-ui-panel\" data-testid=\"font-settings\">\n <FontField\n label={text.uiFont}\n help={text.uiHelp}\n value={settings.uiFont}\n presets={UI_FONT_PRESETS}\n locale={locale}\n generic=\"sans-serif\"\n systemFonts={fontList.families}\n defaultLabel={text.defaultOption}\n customLabel={text.customOption}\n customPlaceholder={text.customUiPlaceholder}\n systemGroupLabel={text.systemGroup}\n onCommit={value => update({ uiFont: value })}\n />\n <FontField\n label={text.codeFont}\n help={text.codeHelp}\n value={settings.codeFont}\n presets={CODE_FONT_PRESETS}\n locale={locale}\n generic=\"monospace\"\n systemFonts={fontList.families}\n defaultLabel={text.defaultOption}\n customLabel={text.customOption}\n customPlaceholder={text.customCodePlaceholder}\n systemGroupLabel={text.systemGroup}\n onCommit={value => update({ codeFont: value })}\n />\n <label className=\"dsh-ui-field\">\n <span className=\"dsh-ui-label\">{text.fontSize}</span>\n <select\n className=\"dsh-ui-select\"\n value={fontSize}\n onChange={event => {\n const px = Number(event.target.value)\n if (Number.isInteger(px) && px >= FONT_SIZE_MIN && px <= FONT_SIZE_MAX && px !== fontSize) {\n // The theme service is the only write entry; it validates again and\n // persists through the host settings scope, and theme/change keeps\n // this panel in sync with the native Settings → General stepper.\n try { props.client.theme.setFontSize('text', px) } catch { /* out-of-range guard already applied */ }\n }\n }}\n >\n {sizes.map(px => <option key={px} value={px}>{px}px</option>)}\n </select>\n <span className=\"dsh-ui-help\">{text.sizeHelp}</span>\n </label>\n <div className=\"dsh-ui-actions\">\n <Button variant=\"outline\" size=\"md\" disabled={fontList.state === 'loading'}\n onClick={() => { void loadSystemFonts() }}>\n {fontList.state === 'loading' ? text.loadingFonts : fontList.state === 'ready' ? text.reloadFonts : text.loadFonts}\n </Button>\n <Button variant=\"outline\" size=\"md\" onClick={() => {\n update({ uiFont: '', codeFont: '' })\n if (fontSize !== FONT_SIZE_DEFAULT) props.client.theme.setFontSize('text', FONT_SIZE_DEFAULT)\n }}>{text.reset}</Button>\n </div>\n {fontList.state === 'ready' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsLoaded(fontList.families.length)}</p> : null}\n {fontList.state === 'ready' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsPartial}</p> : null}\n {fontList.state === 'denied' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsDenied}</p> : null}\n </section>\n}\n\nexport function apply(ctx: Context): void {\n const client = ctx as unknown as Client & { effect: Context['effect'] }\n const store = createFontSettingsStore(readStorage())\n migrateFontPreferences(client.theme, store, readStorage())\n ctx.effect(() => {\n if (typeof document === 'undefined') return () => {}\n const style = document.createElement('style')\n style.setAttribute('data-plugin', PLUGIN_NAME)\n style.textContent = styles\n document.head.appendChild(style)\n return () => style.remove()\n }, 'font.styles')\n ctx.effect(() => client.slots.inject('plugins.bundle.config', () => client.slots.register(\n { name: 'plugins.bundle.config', key: PLUGIN_NAME },\n (slotProps: { view?: 'summary' | 'page' }) =>\n <FontSettingsPanel client={client} view={slotProps?.view} />,\n )), 'font.settings')\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,cAAc;;;AAI3B,MAAa,cAAc;AAmB3B,SAAgB,sBAAoC;CAClD,OAAO;EAAE,QAAQ;EAAI,UAAU;CAAG;AACpC;;;;;AAMA,SAAgB,oBAAoB,OAAwB;CAC1D,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MACJ,QAAQ,+BAA+B,EAAE,CAAC,CAC1C,KAAK,CAAC,CACN,MAAM,GAAG,GAAG;AACjB;AAEA,SAAgB,kBAAkB,KAA4B;CAC5D,IAAI,SAAS;CACb,IAAI,OAAO,WAAW,UACpB,IAAI;EACF,SAAS,KAAK,MAAM,MAAM;CAC5B,QAAQ;EACN,OAAO,oBAAoB;CAC7B;CAEF,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG,OAAO,oBAAoB;CAC/F,MAAM,SAAS;CACf,OAAO;EACL,QAAQ,oBAAoB,OAAO,MAAM;EACzC,UAAU,oBAAoB,OAAO,QAAQ;CAC/C;AACF;AAEA,SAAgB,sBAAsB,UAAgC;CACpE,OAAO,KAAK,UAAU;EACpB,QAAQ,oBAAoB,SAAS,MAAM;EAC3C,UAAU,oBAAoB,SAAS,QAAQ;CACjD,CAAC;AACH;AASA,MAAa,kBAAyC;CACpD;EAAE,IAAI;EAAS,OAAO;GAAE,IAAI;GAAQ,IAAI;EAAkB;EAAG,OAAO;CAA+C;CACnH;EAAE,IAAI;EAAY,OAAO;GAAE,IAAI;GAAM,IAAI;EAAc;EAAG,OAAO;CAA2C;CAC5G;EAAE,IAAI;EAAU,OAAO;GAAE,IAAI;G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AAM,WAAW;CAAO,CAAA,CAC/D,CAAC,GAAG,eAAe;AACrB"}
|
|
1
|
+
{"version":3,"file":"client.inner.cjs","names":["useSyncExternalStore","useState","Input","Button"],"sources":["../src/contracts.ts","../src/preferences.ts","../../dsh-plugin-kit/src/official-ui.ts","../src/client.tsx"],"sourcesContent":["/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,\n * normalization, the CSS-variable application core, and the local store.\n * No React, no cordis — every export runs in Node tests and the browser. */\n\nexport const PLUGIN_NAME = '@klarkxy/dsh-font'\n\n/** Legacy browser-local font choices, retained as the one-time migration backup.\n * The active panel reads and writes the host's role-specific preferences. */\nexport const STORAGE_KEY = 'klarkxy.dsh-font.v1'\n\n/** Host text-role bounds, shared by the native conversation-size stepper. */\nexport const FONT_SIZE_MIN = 10\nexport const FONT_SIZE_MAX = 22\nexport const FONT_SIZE_DEFAULT = 14\n\n/** Root font overrides reach derived Markdown, brand and terminal fonts.\n * These are the host variables this feature changes, rather than a private\n * palette used to style the plugin's settings page. */\nexport const UI_FONT_VARIABLE = '--dsw-font-family'\nexport const CODE_FONT_VARIABLE = '--ds-font-family-code'\n\nexport interface FontSettings {\n /** Full CSS font-family stack for the interface; empty keeps the host default. */\n uiFont: string\n /** Full CSS font-family stack for code blocks, inline code and terminals. */\n codeFont: string\n}\n\nexport function defaultFontSettings(): FontSettings {\n return { uiFont: '', codeFont: '' }\n}\n\n/** A raw font-family string is placed into a single CSS declaration via\n * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but\n * trimming control characters and the CSS delimiters keeps pasted garbage from\n * producing a silently-dead value. */\nexport function normalizeFontFamily(value: unknown): string {\n if (typeof value !== 'string') return ''\n return value\n .replace(/[\\u0000-\\u001F\\u007F;{}<>]/g, '')\n .trim()\n .slice(0, 300)\n}\n\nexport function parseFontSettings(raw: unknown): FontSettings {\n let source = raw\n if (typeof source === 'string') {\n try {\n source = JSON.parse(source)\n } catch {\n return defaultFontSettings()\n }\n }\n if (!source || typeof source !== 'object' || Array.isArray(source)) return defaultFontSettings()\n const record = source as Record<string, unknown>\n return {\n uiFont: normalizeFontFamily(record.uiFont),\n codeFont: normalizeFontFamily(record.codeFont),\n }\n}\n\nexport function serializeFontSettings(settings: FontSettings): string {\n return JSON.stringify({\n uiFont: normalizeFontFamily(settings.uiFont),\n codeFont: normalizeFontFamily(settings.codeFont),\n })\n}\n\nexport interface FontPreset {\n readonly id: string\n readonly label: { readonly zh: string; readonly en: string }\n /** The font-family stack committed when the preset is picked. */\n readonly value: string\n}\n\nexport const UI_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'yahei', label: { zh: '微软雅黑', en: 'Microsoft YaHei' }, value: '\"Microsoft YaHei\", \"PingFang SC\", sans-serif' },\n { id: 'pingfang', label: { zh: '苹方', en: 'PingFang SC' }, value: '\"PingFang SC\", -apple-system, sans-serif' },\n { id: 'simsun', label: { zh: '宋体', en: 'SimSun' }, value: '\"SimSun\", \"Songti SC\", serif' },\n { id: 'kaiti', label: { zh: '楷体', en: 'KaiTi' }, value: '\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif' },\n { id: 'source-han-sans', label: { zh: '思源黑体', en: 'Source Han Sans' }, value: '\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif' },\n { id: 'source-han-serif', label: { zh: '思源宋体', en: 'Source Han Serif' }, value: '\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif' },\n]\n\nexport const CODE_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'cascadia', label: { zh: 'Cascadia', en: 'Cascadia' }, value: '\"Cascadia Mono\", \"Cascadia Code\", monospace' },\n { id: 'jetbrains-mono', label: { zh: 'JetBrains Mono', en: 'JetBrains Mono' }, value: '\"JetBrains Mono\", monospace' },\n { id: 'fira-code', label: { zh: 'Fira Code', en: 'Fira Code' }, value: '\"Fira Code\", monospace' },\n { id: 'consolas', label: { zh: 'Consolas', en: 'Consolas' }, value: 'Consolas, monospace' },\n { id: 'sarasa', label: { zh: '更纱黑体', en: 'Sarasa Mono' }, value: '\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace' },\n { id: 'maple-mono', label: { zh: 'Maple Mono', en: 'Maple Mono' }, value: '\"Maple Mono NF CN\", \"Maple Mono\", monospace' },\n]\n\nexport function presetFor(value: string, presets: readonly FontPreset[]): FontPreset | undefined {\n // The host quotes every non-generic family when persisting a stack.\n const comparable = (stack: string) => stack.split(',').map(name => name.trim().replace(/^[\"']|[\"']$/g, '')).join(',')\n return presets.find(preset => comparable(preset.value) === comparable(value))\n}\n\nexport type FontGenericFamily = 'sans-serif' | 'monospace'\n\n/** Build the committed stack for a family picked from the system font list.\n * The family name comes from the OS (Local Font Access API); quotes and\n * backslashes are stripped so it can be safely re-quoted as one family. */\nexport function fontStackFor(family: string, generic: FontGenericFamily): string {\n const cleaned = normalizeFontFamily(family).replace(/[\"\\\\]/g, '')\n if (!cleaned) return generic\n return `\"${cleaned}\", ${generic}`\n}\n\n/** A system font offered in the picker: `family` is the exact name CSS\n * matching needs; `fullName` is an informative localized alias (e.g. converted\n * CJK fonts whose family is the Latin alias), '' when it only restates the\n * family (\"Microsoft YaHei Regular\" adds nothing). */\nexport interface SystemFontFamily {\n readonly family: string\n readonly fullName: string\n}\n\n/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()\n * result (entries carry `family` and `fullName`; duplicates per style are\n * expected). */\nexport function uniqueSystemFonts(fonts: readonly unknown[]): SystemFontFamily[] {\n const byFamily = new Map<string, string>()\n for (const item of fonts) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) continue\n const record = item as Record<string, unknown>\n const family = normalizeFontFamily(record.family).replace(/[\"\\\\]/g, '')\n if (!family || byFamily.has(family)) continue\n const fullName = normalizeFontFamily(record.fullName).replace(/[\"\\\\]/g, '')\n byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : '')\n }\n return [...byFamily.entries()]\n .map(([family, fullName]) => ({ family, fullName }))\n .sort((a, b) => a.family.localeCompare(b.family))\n}\n\n/** Picker label: the UI locale's recognizable name leads, the alias stays in\n * parentheses because the canonical family is still what a custom input needs. */\nexport function systemFontLabel(item: SystemFontFamily, locale: 'zh' | 'en'): string {\n if (!item.fullName) return item.family\n return locale === 'zh' ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`\n}\n\n/** Minimal write face of CSSStyleDeclaration — document.documentElement.style\n * satisfies it, and tests supply a recording double. */\nexport interface FontStyleTarget {\n setProperty(name: string, value: string): void\n removeProperty(name: string): void\n}\n\nexport function applyFontSettings(style: FontStyleTarget, settings: FontSettings): void {\n if (settings.uiFont) style.setProperty(UI_FONT_VARIABLE, settings.uiFont)\n else style.removeProperty(UI_FONT_VARIABLE)\n if (settings.codeFont) style.setProperty(CODE_FONT_VARIABLE, settings.codeFont)\n else style.removeProperty(CODE_FONT_VARIABLE)\n}\n\nexport function clearFontSettings(style: FontStyleTarget): void {\n style.removeProperty(UI_FONT_VARIABLE)\n style.removeProperty(CODE_FONT_VARIABLE)\n}\n\n/** Read face required to restore only overrides still owned by this instance. */\nexport interface OwnedFontStyleTarget extends FontStyleTarget {\n getPropertyValue(name: string): string\n getPropertyPriority(name: string): string\n setProperty(name: string, value: string, priority?: string): void\n}\n\n/** Root inline overrides preserve the existing local persistence/unload\n * boundary. Save the underlying value (including !important) on first write\n * or when the host replaces a value, and never retract somebody else's write. */\nexport function createFontSettingsOverride(style: OwnedFontStyleTarget) {\n const owned = new Map<string, { previous: string; priority: string; value: string }>()\n function release(name: string) {\n const entry = owned.get(name)\n if (!entry) return\n if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === '') {\n if (entry.previous) style.setProperty(name, entry.previous, entry.priority)\n else style.removeProperty(name)\n }\n owned.delete(name)\n }\n return {\n apply(settings: FontSettings) {\n for (const [name, value] of [\n [UI_FONT_VARIABLE, settings.uiFont],\n [CODE_FONT_VARIABLE, settings.codeFont],\n ] as const) {\n if (!value) { release(name); continue }\n const current = style.getPropertyValue(name)\n const priority = style.getPropertyPriority(name)\n const entry = owned.get(name)\n if (!entry || current !== entry.value || priority !== '') {\n owned.set(name, { previous: current, priority, value: '' })\n }\n style.setProperty(name, value)\n owned.get(name)!.value = style.getPropertyValue(name)\n }\n },\n dispose() { for (const name of [...owned.keys()]) release(name) },\n }\n}\n\nexport interface FontSettingsStorage {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface FontSettingsStore {\n load(): FontSettings\n save(next: FontSettings): void\n}\n\n/** Browser-local persistence. A fully-default setting removes the key so a\n * reset leaves no residue; storage failures (private mode, quota) degrade to\n * in-memory behaviour rather than breaking the panel. */\nexport function createFontSettingsStore(storage: FontSettingsStorage | undefined): FontSettingsStore {\n let current = defaultFontSettings()\n // A failed local write must win over stale persisted values on page remount.\n // Successful writes restore the existing ability to read external updates.\n let pendingPersistence = false\n return {\n load() {\n if (storage && !pendingPersistence) {\n try {\n current = parseFontSettings(storage.getItem(STORAGE_KEY))\n } catch {\n /* keep the last readable or locally saved snapshot */\n }\n }\n return { ...current }\n },\n save(next) {\n current = parseFontSettings(next)\n if (!storage) return\n pendingPersistence = true\n try {\n if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY)\n else storage.setItem(STORAGE_KEY, serializeFontSettings(current))\n pendingPersistence = false\n } catch {\n /* stay in-memory */\n }\n },\n }\n}\n","import { type FontSettingsStore, type FontSettingsStorage, normalizeFontFamily } from './contracts.ts'\n\nexport type FontRole = 'text' | 'code' | 'terminal'\nexport interface FontThemeSnapshot {\n fontSizes: Record<FontRole, number>\n fontFamilies: Record<FontRole, string>\n}\nexport interface FontTheme {\n getTheme(): FontThemeSnapshot\n setFontSize(role: FontRole, px: number): void\n setFontFamily(role: FontRole, value: string): void\n}\nexport const MIGRATION_KEY = 'klarkxy.dsh-font.host-preferences.v1'\n\n/** Preserve the old selection as a backup, but never replay it over native\n * preferences on subsequent loads. Each role migrates independently. */\nexport function migrateFontPreferences(theme: FontTheme, store: FontSettingsStore, storage?: FontSettingsStorage): void {\n try { if (storage?.getItem(MIGRATION_KEY)) return } catch { return }\n const old = store.load()\n const families = theme.getTheme().fontFamilies\n for (const [role, value] of [['text', old.uiFont], ['code', old.codeFont], ['terminal', old.codeFont]] as const) {\n if (!families[role] && normalizeFontFamily(value)) theme.setFontFamily(role, value)\n }\n try { storage?.setItem(MIGRATION_KEY, '1') } catch { /* Host preferences still protect migrated nonempty roles. */ }\n}\n","/**\n * Shared contract that keeps every plugin's browser-side UI on the official\n * DeepSeek Harness Web design language.\n *\n * Two rules produce that language, and both are load-bearing here:\n *\n * 1. Colour, radius, elevation and focus come from the host theme's real\n * `--dsw-*` tokens, written under their own names. Plugins never invent a\n * token, never alias the official ones behind a private palette (a private\n * alias is just a second, diverging theme), and never carries a literal\n * fallback — the host publishes light and dark, and a literal would pin one\n * of them. The only non-colour custom properties used are the host's own\n * content-font axis and frame clearance.\n *\n * 2. Anything the host already ships is used, not reimplemented. Controls come\n * from `@deepseek-ai/dsh-client-ui-primitives` (`Button`, `Input`,\n * `Checkbox`, `Switch`, `Tag`, `Pill`, `SegmentedControl`, `Menu`, `Modal`,\n * `Tooltip`, `Toast`, `DisclosureRow`, `StateDot`, `PathLabel`, the settings\n * form suite). This module only styles what primitives do not cover: page\n * scaffolding, field layout, banners, empty states and scroll regions.\n *\n * The metrics below are transcribed from the primitives' own CSS modules so a\n * feature panel lines up pixel-for-pixel with a native one: the 14/22 body and\n * 13/20 compact type tiers, the 0.5px hairline scale, and the elevation family\n * that draws a surface's edge in its shadow (`border: 0`) instead of a border.\n */\n\n/**\n * Every `--dsw-*` token this repo is allowed to reference, grouped by role.\n *\n * Plugins may only colour through this list. It is exported so the guard test\n * can fail a build when a stylesheet reaches for anything else — the failure\n * mode this prevents is silent: an unknown token resolves to nothing, so a\n * border disappears or a label inherits the wrong colour with no error anywhere.\n */\nexport const OFFICIAL_THEME_TOKENS = {\n /** Surfaces, from the page up to the topmost nested card. */\n surface: [\n '--dsw-alias-bg-base',\n '--dsw-alias-bg-layer-1',\n '--dsw-alias-bg-layer-2',\n '--dsw-alias-bg-layer-3',\n '--dsw-alias-bg-layer-4',\n '--dsw-alias-bg-module-platform',\n '--dsw-alias-bg-overlay',\n ],\n /** Hairlines. l1 is near-invisible on a menu surface, so menus use l2+. */\n border: ['--dsw-alias-border-l1', '--dsw-alias-border-l2', '--dsw-alias-border-l3', '--dsw-alias-border-l4'],\n /** Text. `caption` is menu shortcut text, `dimmed` is placeholder text. */\n label: [\n '--dsw-alias-label-primary',\n '--dsw-alias-label-secondary',\n '--dsw-alias-label-tertiary',\n '--dsw-alias-label-caption',\n '--dsw-alias-label-dimmed',\n '--dsw-alias-label-error',\n '--dsw-alias-label-primary-foreground',\n ],\n /** Interactive fills. The `-danger` hover belongs to destructive rows. */\n interactive: [\n '--dsw-alias-interactive-bg-hover',\n '--dsw-alias-interactive-bg-active',\n '--dsw-alias-interactive-bg-hover-danger',\n ],\n /** Accent and status. `business` is the focus ring's default colour. */\n accent: [\n '--dsw-alias-brand-primary',\n '--dsw-alias-button-primary-fill',\n '--dsw-alias-button-primary-hover',\n '--dsw-alias-button-tool-bar-fill',\n '--dsw-alias-button-tool-bar-hover',\n '--dsw-alias-button-ghost-active-fill',\n '--dsw-alias-button-ghost-active-border',\n ],\n state: [\n '--dsw-alias-state-business-primary',\n '--dsw-alias-state-success-primary',\n '--dsw-alias-state-warn-primary',\n '--dsw-alias-state-error-primary',\n '--dsw-alias-state-idle-primary',\n ],\n /** Corner scale: sm 8, md 12, lg the large card, panel the modal. */\n radius: ['--dsw-radius-sm', '--dsw-radius-md', '--dsw-radius-lg', '--dsw-radius-panel'],\n /** An elevated surface draws its edge in the shadow, so it keeps border: 0. */\n elevation: [\n '--dsw-elevation-soft',\n '--dsw-elevation-stroke',\n '--dsw-elevation-stroke-color',\n '--dsw-elevation-panel',\n '--dsw-elevation-prominent',\n ],\n /** Floats, masks and scrollbars. */\n overlay: [\n '--dsw-menu-surface-fill',\n '--dsw-menu-backdrop-filter',\n '--dsw-mask-blur',\n '--dsw-alias-bg-mask-1',\n '--dsw-alias-menu-icon',\n '--dsw-alias-scrollbar-bg-l2',\n '--dsw-alias-scrollbar-hover-l2',\n '--dsw-shadow-lv3',\n ],\n /** Motion, focus and type axis, published by the host rather than by a component. */\n system: [\n '--dsw-focus-ring-width',\n '--dsw-focus-ring-color',\n '--dsw-font-markdown-code-font-family',\n '--ds-transition-duration',\n '--ds-ease-in-out',\n '--ds-font-family-code',\n '--dsh-scrollbar-thumb',\n '--dsh-scrollbar-thumb-hover',\n '--dsh-content-font-size-secondary',\n '--dsh-content-font-delta',\n '--dsh-frame-top-clearance',\n ],\n} as const\n\n/** Every official token name, flat. Used by the token guard test. */\nexport const OFFICIAL_THEME_TOKEN_NAMES: readonly string[] = Object.values(OFFICIAL_THEME_TOKENS).flat()\n\n/** The elevation steps a surface can be raised by, softest first. */\nexport type OfficialElevation = 'soft' | 'stroke' | 'panel' | 'prominent'\n\n/**\n * The host's focus ring shorthand, verbatim. Writing this per control is how\n * rings drift apart; a stylesheet that draws its own focus style should use\n * {@link officialFocus} instead. The colour fallback is the host's own default.\n */\nexport const OFFICIAL_FOCUS_RING =\n 'var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary))'\n\n/**\n * A complete `outline` declaration at the official geometry. `offset` defaults\n * to the 2px the native controls use; the host's inline field rules sit at 1px\n * and a segmented tab pulls the ring inside itself at -2px.\n */\nexport function officialFocus(offset = '2px'): string {\n return `outline: ${OFFICIAL_FOCUS_RING}; outline-offset: ${offset}`\n}\n\n/**\n * An elevated surface. The host draws a raised surface's edge inside its\n * shadow rather than as a border, so a card sets `border: 0` and takes the edge\n * from the elevation — which is also why its border stays off the alias-border\n * set that a flat, non-elevated rule would use.\n */\nexport function officialElevation(level: OfficialElevation): string {\n return `border: 0; box-shadow: var(--dsw-elevation-${level})`\n}\n\n/**\n * An elevated surface whose edge should read as a specific hairline. Rebinding\n * the stroke colour is how a menu card picks l1 while a panel picks l3, without\n * the two growing apart by hand.\n */\nexport function officialStrokedElevation(level: OfficialElevation, color: string): string {\n return `--dsw-elevation-stroke-color: ${color}; ${officialElevation(level)}`\n}\n\n/**\n * The shared stylesheet for a plugin UI, scoped under that plugin's root class.\n *\n * Scoping is what keeps this safe to always-bundle into every client: the rules\n * can only match inside the plugin's own subtree, so two plugins can both mount\n * `dsh-ui-card` without either styling the other's markup.\n *\n * Each recipe matches the root element *and* its descendants, because the\n * commonest arrangement is one element that is both — a surface that carries\n * the root class and `dsh-ui-card`, or a portaled dialog that is the root and\n * the `dsh-ui-surface`. A descendant-only scope would silently leave those\n * unstyled, with no error anywhere.\n *\n * A caveat worth knowing: `Modal` and `Menu` portal to `document.body`, so their\n * content leaves the plugin's subtree entirely. A portaled surface therefore\n * needs its own root class on an element inside the portal.\n *\n * Only patterns that primitives do not provide live here. If a control appears\n * below that `Button`/`Input`/`Switch`/`Tag`/`Menu` already covers, that is a\n * bug in this file: use the primitive and delete the recipe.\n */\nexport function officialUiCss(roots: string | readonly string[]): string {\n // One plugin often mounts several unrelated surfaces (a settings seat, a chat\n // card, a header menu), so the caller names every root. The rules below are\n // nested under a single selector list and use `&`, which the browser expands\n // per root — so one stylesheet covers all of them without duplicating itself.\n const scope = (typeof roots === 'string' ? [roots] : roots).map(root => `.${root}`).join(', ')\n const sheet = `\n/* Official DSH Web UI contract. Generated by @klarkxy/dsh-plugin-kit/official-ui.\n * Do not hand-edit the copy inside a plugin: change this module so every plugin\n * moves together. Scope: ${scope} */\n/* The scope rule below stays open for the whole sheet: every rule after it\n * nests with the parent selector, so one stylesheet can cover several unrelated\n * roots without leaking into a neighbouring plugin. Its closing brace is last. */\n${scope} {\n color: var(--dsw-alias-label-primary);\n font-family: inherit;\n font-size: 14px;\n line-height: 22px;\n min-width: 0;\n\n& *, & *::before, & *::after { box-sizing: border-box; }\n& h1, & h2, & h3, & h4, & p, & figure { margin: 0; }\n/* Keyboard focus only: pointer input keeps the native resting appearance. The\n * ring needs no radius of its own — the outline already follows the control's\n * own border-radius, and overriding it here would flatten every control. */\n& :focus-visible { ${officialFocus()}; }\n& [hidden] { display: none !important; }\n\n/* --- Type tiers. The same 14/22 and 13/20 steps the primitives use. --- */\n& .dsh-ui-title { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-heading { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-compact { font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-meta { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }\n& .dsh-ui-hint { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-error { font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-warn { color: var(--dsw-alias-state-warn-primary); }\n& .dsh-ui-success { color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-muted { color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n& .dsh-ui-wrap { min-width: 0; overflow-wrap: anywhere; }\n\n/* --- Layout scaffolding. --- */\n& .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }\n& .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }\n/* Plugin detail pages share one reading column. These are layout recipes;\n * controls keep their own primitive styles. Form spacing follows the host's\n * settings-form/fields.module.css and SettingsForm.module.css. */\n& .dsh-ui-page { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 760px; min-width: 0; }\n& .dsh-ui-form { display: flex; flex-direction: column; gap: 0; min-width: 0; }\n&.dsh-ui-form > .dsh-ui-field, & .dsh-ui-form > .dsh-ui-field { padding: 12px 0; }\n& .dsh-ui-form-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 16px; min-width: 0; }\n& .dsh-ui-fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; min-width: 0; margin: 0; padding: 0; border: 0; }\n@media (max-width: 560px) {\n & .dsh-ui-fields-grid { grid-template-columns: minmax(0, 1fr); }\n}\n& .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }\n& .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }\n& .dsh-ui-spacer { flex: 1; min-width: 0; }\n/* A 0.5px l2 rule is the host's section divider; reserve the same rhythm. */\n& .dsh-ui-divider { height: 0.5px; background: var(--dsw-alias-border-l2); }\n& .dsh-ui-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }\n\n/* --- Card: a raised surface whose edge lives in the shadow. --- */\n& .dsh-ui-card {\n ${officialElevation('stroke')}\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 16px;\n border-radius: var(--dsw-radius-lg);\n background: var(--dsw-alias-bg-layer-1);\n color: var(--dsw-alias-label-primary);\n min-width: 0;\n}\n& .dsh-ui-card--flat { border: 0.5px solid var(--dsw-alias-border-l3); box-shadow: none; }\n& .dsh-ui-card--nested { background: var(--dsw-alias-bg-layer-2); }\n& .dsh-ui-card--plain { background: none; }\n\n/* --- Field: label, control, help, error. The control itself is an\n * official primitive, so this only owns the vertical rhythm. --- */\n& .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n& .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }\n/* Grid fields share a row, so the stacked-field divider must not win later in\n * the cascade. Reset it here, after the field recipe. */\n& .dsh-ui-fields-grid > .dsh-ui-field { padding: 0; border: 0; }\n& .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n& .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }\n& .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }\n& .dsh-ui-help p { margin: 0; }\n& .dsh-ui-help p + p { margin-top: 8px; }\n& .dsh-ui-required { color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-control { width: 100%; min-width: 0; }\n/* An invalid control is marked on the control, not only in the message. */\n& .dsh-ui-control[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-readonly { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n& .dsh-ui-readonly > dt { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n& .dsh-ui-readonly > dd { margin: 0; font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }\n\n/* --- Buttons row. A no-op container: it exists so actions line up on the\n * trailing edge the way every native panel does. --- */\n& .dsh-ui-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 4px; }\n& .dsh-ui-actions-end { justify-content: flex-end; }\n\n/* --- Banners. A banner is a left-rail notice, the shape used for warnings,\n * deprecations and blocking instructions. --- */\n& .dsh-ui-banner {\n display: flex;\n flex-direction: column;\n gap: 8px;\n padding: 10px 14px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-left: 3px solid var(--dsw-alias-state-warn-primary);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n}\n& .dsh-ui-banner-title { font-weight: 500; color: var(--dsw-alias-state-warn-primary); }\n& .dsh-ui-banner--info { border-left-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-banner--danger { border-left-color: var(--dsw-alias-state-error-primary); }\n& .dsh-ui-banner--success { border-left-color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-banner p { margin: 0; }\n\n/* --- Inline notice: a transient confirmation with no chrome of its own. --- */\n& .dsh-ui-notice { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-success-primary); }\n& .dsh-ui-notice--error { color: var(--dsw-alias-state-error-primary); }\n\n/* --- Empty and loading states. Both sit in a dashed well so an empty panel\n * reads as \"nothing here yet\" rather than as a broken layout. --- */\n& .dsh-ui-empty {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 6px;\n padding: 20px 16px;\n border: 0.5px dashed var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n}\n& .dsh-ui-loading { display: flex; align-items: center; gap: 8px; padding: 20px 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }\n\n/* --- Selectable list. A row is a button-sized target with a hover fill and\n * a selected fill; the name carries the weight, the description does not. --- */\n& .dsh-ui-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n& .dsh-ui-list-scroll { max-height: min(66vh, 760px); overflow-y: auto; overflow-x: hidden; }\n& .dsh-ui-list-row { border-radius: var(--dsw-radius-md); }\n& .dsh-ui-list-row:hover { background: var(--dsw-alias-interactive-bg-hover); }\n& .dsh-ui-list-row[aria-selected='true'], & .dsh-ui-list-row[data-selected] { background: var(--dsw-alias-interactive-bg-active); }\n& .dsh-ui-list-item {\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 4px;\n width: 100%;\n min-width: 0;\n padding: 10px 12px;\n border: 0;\n border-radius: var(--dsw-radius-md);\n background: none;\n font: inherit;\n color: inherit;\n text-align: start;\n cursor: pointer;\n}\n& .dsh-ui-list-item:disabled { cursor: default; }\n& .dsh-ui-list-item:disabled:hover { background: none; }\n& .dsh-ui-list-name { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); overflow-wrap: anywhere; }\n& .dsh-ui-list-desc { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }\n\n/* --- Code and structured output. Wraps rather than scrolls, because a\n * feature panel is read rather than scanned. --- */\n& .dsh-ui-code {\n padding: 10px 12px;\n border: 0.5px solid var(--dsw-alias-border-l3);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-1);\n font-family: var(--ds-font-family-code);\n font-size: 12px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n overflow-wrap: anywhere;\n white-space: pre-wrap;\n}\n& .dsh-ui-scroll { max-height: 60vh; overflow: auto; overscroll-behavior: contain; }\n\n/* --- A toggle row: label on the left, switch on the trailing edge. This is\n * layout only; the switch itself is the official primitive. --- */\n& .dsh-ui-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 12px 0; }\n& .dsh-ui-toggle-row + .dsh-ui-toggle-row { border-top: 0.5px solid var(--dsw-alias-border-l2); }\n& .dsh-ui-toggle-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n& .dsh-ui-toggle-label { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n\n/* --- Floating surface: a panel anchored to a trigger. This is the material\n * a menu card is made of — the translucent fill plus its backdrop blur, with\n * the edge riding inside the prominent elevation. A plugin that hand-rolls this\n * is how tokens like --dsw-specific-menu get invented; use this instead. --- */\n& .dsh-ui-surface {\n --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n position: relative;\n display: flex;\n flex-direction: column;\n border: 0;\n border-radius: var(--dsw-radius-lg);\n background: var(--dsw-menu-surface-fill);\n backdrop-filter: var(--dsw-menu-backdrop-filter);\n box-shadow: var(--dsw-elevation-prominent);\n color: var(--dsw-alias-label-primary);\n font-size: 13px;\n line-height: 20px;\n min-width: 0;\n}\n& .dsh-ui-surface-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; overflow-y: auto; }\n& .dsh-ui-surface-head { display: flex; align-items: center; gap: 8px; min-width: 0; }\n& .dsh-ui-surface-title { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }\n\n/* --- Native select. The primitives ship no select, so a plugin that offers a\n * closed list of choices keeps the platform control and matches the official\n * settings field geometry exactly (34px, 0.5px l4, radius-md, layer-3). A\n * SegmentedControl is the primitive to reach for when the choices are few\n * enough to show at once. --- */\n& .dsh-ui-select {\n box-sizing: border-box;\n width: 100%;\n min-width: 0;\n height: 34px;\n padding: 0 12px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-3);\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n}\n& .dsh-ui-select:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-select:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }\n& .dsh-ui-select[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n\n/* --- Native textarea. The primitives ship no textarea either, so a settings\n * prompt keeps the platform element and the same field shell as the select:\n * 0.5px l4, radius-md, layer-3, 13/1.5 type. It grows vertically instead of\n * locking to the select's 34px row. --- */\n& .dsh-ui-textarea {\n box-sizing: border-box;\n width: 100%;\n min-width: 0;\n resize: vertical;\n padding: 8px 12px;\n border: 0.5px solid var(--dsw-alias-border-l4);\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-bg-layer-3);\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-primary);\n}\n& .dsh-ui-textarea:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }\n& .dsh-ui-textarea:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }\n& .dsh-ui-textarea::placeholder { color: var(--dsw-alias-label-dimmed); }\n& .dsh-ui-textarea[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }\n\n/* Long panels scroll inside themselves instead of growing the host page. */\n& .dsh-ui-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }\n& .dsh-ui-panel-wide { max-width: 100%; }\n\n@media (prefers-reduced-motion: reduce) {\n & *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }\n}\n}\n`\n // Widen every recipe from \"a descendant of the root\" to \"the root, or one of\n // its descendants\". Written as a transform rather than by hand so no recipe\n // can be added later with only the descendant form. The pattern is narrow on\n // purpose: a leading `&` followed by one recipe class and no combinator, so\n // sibling and child rules such as `.dsh-ui-field + .dsh-ui-field` keep their\n // own meaning and are left alone.\n return sheet.replace(/^& (\\.dsh-ui-[a-z0-9-]+)(?=\\s*\\{)/gm, (_match, className: string) =>\n `&${className}, & ${className}`)\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport { migrateFontPreferences, type FontTheme, type FontThemeSnapshot } from './preferences.ts'\nimport { Button, Input } from '@deepseek-ai/dsh-client-ui-primitives'\nimport { officialUiCss } from '@klarkxy/dsh-plugin-kit/official-ui'\nimport { useState, useSyncExternalStore } from 'react'\nimport {\n CODE_FONT_PRESETS, FONT_SIZE_DEFAULT, FONT_SIZE_MAX, FONT_SIZE_MIN, PLUGIN_NAME,\n UI_FONT_PRESETS,\n createFontSettingsStore, fontStackFor, normalizeFontFamily,\n presetFor, systemFontLabel, uniqueSystemFonts,\n type FontGenericFamily, type FontPreset, type FontSettings, type FontSettingsStorage,\n type SystemFontFamily,\n} from './contracts.ts'\n\nexport const name = 'dsh-font-client'\nexport const inject = ['slots', 'theme', 'locale'] as const\n\ntype Client = {\n theme: FontTheme\n locale: { getSnapshot(): { active: string }; subscribe(fn: () => void): () => void }\n slots: {\n inject(key: string, callback: () => unknown): () => void\n register(spec: { name: string; key: string; label?: string }, render: unknown): () => void\n }\n on(event: 'theme/change', listener: (snapshot: FontThemeSnapshot) => void): () => void\n}\n\nconst COPY = {\n zh: {\n label: '字体',\n uiFont: '界面字体',\n codeFont: '代码字体',\n fontSize: '会话字号',\n defaultOption: '默认',\n customOption: '自定义…',\n customUiPlaceholder: '例如 \"Microsoft YaHei\", sans-serif',\n customCodePlaceholder: '例如 \"JetBrains Mono\", monospace',\n uiHelp: '作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。',\n codeHelp: '作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。',\n sizeHelp: '与「设置 → 通用」中的字号同步,范围 10–22。',\n loadFonts: '读取系统字体',\n reloadFonts: '重新读取系统字体',\n loadingFonts: '正在读取系统字体…',\n fontsLoaded: (count: number) => `已读取 ${count} 款系统字体;新装字体后点「重新读取」刷新列表。`,\n fontsPartial: '列表来自浏览器枚举:仅安装到当前用户的字体可能不在其中,可以直接输入字体名使用。',\n fontsDenied: '系统字体读取被拒绝或当前环境不支持,仍可手动输入字体名。',\n systemGroup: '系统字体',\n reset: '全部恢复默认',\n summary: (ui: string, code: string, size: number) => `界面 ${ui} · 代码 ${code} · ${size}px`,\n defaultName: '默认',\n },\n en: {\n label: 'Font',\n uiFont: 'Interface font',\n codeFont: 'Code font',\n fontSize: 'Conversation font size',\n defaultOption: 'Default',\n customOption: 'Custom…',\n customUiPlaceholder: 'e.g. \"Microsoft YaHei\", sans-serif',\n customCodePlaceholder: 'e.g. \"JetBrains Mono\", monospace',\n uiHelp: 'Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.',\n codeHelp: 'Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.',\n sizeHelp: 'Synced with Settings → General; 10–22 px.',\n loadFonts: 'Load system fonts',\n reloadFonts: 'Reload system fonts',\n loadingFonts: 'Loading system fonts…',\n fontsLoaded: (count: number) => `${count} installed fonts loaded; choose “Reload system fonts” after installing new ones.`,\n 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.',\n fontsDenied: 'Access to system fonts was denied or is unsupported here; you can still type a font name.',\n systemGroup: 'Installed fonts',\n reset: 'Reset all to defaults',\n summary: (ui: string, code: string, size: number) => `${ui} · ${code} · ${size}px`,\n defaultName: 'Default',\n },\n} as const\n\nexport function fontCopy(locale: 'zh' | 'en') {\n return COPY[locale]\n}\n\n/* The panel's own geometry only: reading width, and the custom-stack input row\n * rhythm. Everything visual comes from the contract recipes and primitives. */\nconst styles = `${officialUiCss('font-root')}\n.font-root .font-custom { margin-top: 8px; }\n`\n\nfunction readStorage(): FontSettingsStorage | undefined {\n try {\n return typeof localStorage === 'undefined' ? undefined : localStorage\n } catch {\n return undefined\n }\n}\n\nfunction useLocale(client: Client): 'zh' | 'en' {\n const getSnapshot = () => (client.locale.getSnapshot().active.toLowerCase().startsWith('zh') ? 'zh' : 'en') as 'zh' | 'en'\n return useSyncExternalStore(\n fn => client.locale.subscribe(fn),\n getSnapshot,\n getSnapshot,\n )\n}\n\nfunction useFontSize(client: Client): number {\n return useSyncExternalStore(\n fn => client.on('theme/change', () => fn()),\n () => client.theme.getTheme().fontSizes.text,\n () => client.theme.getTheme().fontSizes.text,\n )\n}\n\nfunction presetMode(value: string, presets: readonly FontPreset[]): string {\n return presetFor(value, presets)?.id ?? (value ? 'custom' : '')\n}\n\nexport function FontField(props: {\n label: string\n help: string\n value: string\n presets: readonly FontPreset[]\n locale: 'zh' | 'en'\n generic: FontGenericFamily\n systemFonts?: readonly SystemFontFamily[]\n defaultLabel: string\n customLabel: string\n customPlaceholder: string\n systemGroupLabel: string\n onCommit(value: string): void\n}) {\n // undefined = not editing; the input otherwise shows the committed stack.\n const [draft, setDraft] = useState<string | undefined>(undefined)\n // With an empty (default) value nothing matches \"custom\" on its own, so the\n // choice itself must be remembered until a stack is committed.\n const [customOpen, setCustomOpen] = useState(false)\n const mode = customOpen ? 'custom' : presetMode(props.value, props.presets)\n\n function commitDraft() {\n if (draft === undefined) return\n const next = normalizeFontFamily(draft)\n setDraft(undefined)\n if (!next) setCustomOpen(false)\n if (next !== props.value) props.onCommit(next)\n }\n\n return <label className=\"dsh-ui-field\">\n <span className=\"dsh-ui-label\">{props.label}</span>\n <select\n className=\"dsh-ui-select\"\n value={mode}\n onChange={event => {\n const id = event.target.value\n setDraft(undefined)\n if (id === 'custom') { setCustomOpen(true); return }\n setCustomOpen(false)\n if (id.startsWith('sys:')) { props.onCommit(fontStackFor(id.slice(4), props.generic)); return }\n const preset = props.presets.find(item => item.id === id)\n props.onCommit(preset ? preset.value : '')\n }}\n >\n <option value=\"\">{props.defaultLabel}</option>\n {props.presets.map(preset => (\n <option key={preset.id} value={preset.id}>{preset.label[props.locale]}</option>\n ))}\n <option value=\"custom\">{props.customLabel}</option>\n {props.systemFonts && props.systemFonts.length > 0 ? <optgroup label={props.systemGroupLabel}>\n {props.systemFonts.map(item => <option key={item.family} value={`sys:${item.family}`}>{systemFontLabel(item, props.locale)}</option>)}\n </optgroup> : null}\n </select>\n {mode === 'custom' ? <span className=\"font-custom\">\n <Input\n value={draft ?? props.value}\n placeholder={props.customPlaceholder}\n onChange={event => setDraft(event.target.value)}\n onBlur={commitDraft}\n onKeyDown={event => { if (event.key === 'Enter') commitDraft() }}\n />\n </span> : null}\n <span className=\"dsh-ui-help\">{props.help}</span>\n </label>\n}\n\nexport function FontSettingsPanel(props: {\n client: Client\n view?: 'summary' | 'page'\n}) {\n const locale = useLocale(props.client)\n const text = COPY[locale]\n const families = useSyncExternalStore(\n fn => props.client.on('theme/change', () => fn()),\n () => props.client.theme.getTheme().fontFamilies,\n () => props.client.theme.getTheme().fontFamilies,\n )\n const settings: FontSettings = { uiFont: families.text, codeFont: families.code }\n const fontSize = useFontSize(props.client)\n // System font list is shared by both fields: one permission prompt, one list.\n const [fontList, setFontList] = useState<{ state: 'idle' | 'loading' | 'ready' | 'denied'; families: readonly SystemFontFamily[] }>(\n { state: 'idle', families: [] },\n )\n\n async function loadSystemFonts() {\n if (fontList.state === 'loading') return\n // Every click re-enumerates: fonts installed after the first read appear\n // on the next one (the button relabels to \"reload\" once a list exists).\n // Local Font Access API: Chromium-only and gated behind a permission\n // prompt; anything else (Firefox, Safari, denied permission, Electron\n // policy) falls through to the preset + manual-input flow unchanged.\n const query = (globalThis as { queryLocalFonts?: () => Promise<readonly unknown[]> }).queryLocalFonts\n if (typeof query !== 'function') { setFontList({ state: 'denied', families: [] }); return }\n setFontList(current => ({ state: 'loading', families: current.families }))\n try {\n const fonts = await query()\n setFontList({ state: 'ready', families: uniqueSystemFonts(fonts) })\n } catch {\n setFontList(current => ({ state: 'denied', families: current.families }))\n }\n }\n\n function update(patch: Partial<FontSettings>) {\n if (patch.uiFont !== undefined) props.client.theme.setFontFamily('text', normalizeFontFamily(patch.uiFont))\n if (patch.codeFont !== undefined) props.client.theme.setFontFamily('code', normalizeFontFamily(patch.codeFont))\n }\n\n const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName)\n const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName)\n\n if (props.view === 'summary') {\n return <span className=\"font-root\" data-testid=\"font-summary\">{text.summary(uiName, codeName, fontSize)}</span>\n }\n\n const sizes: number[] = []\n for (let px = FONT_SIZE_MIN; px <= FONT_SIZE_MAX; px += 1) sizes.push(px)\n\n return <section className=\"font-root dsh-ui-page dsh-ui-form\" data-testid=\"font-settings\">\n <FontField\n label={text.uiFont}\n help={text.uiHelp}\n value={settings.uiFont}\n presets={UI_FONT_PRESETS}\n locale={locale}\n generic=\"sans-serif\"\n systemFonts={fontList.families}\n defaultLabel={text.defaultOption}\n customLabel={text.customOption}\n customPlaceholder={text.customUiPlaceholder}\n systemGroupLabel={text.systemGroup}\n onCommit={value => update({ uiFont: value })}\n />\n <FontField\n label={text.codeFont}\n help={text.codeHelp}\n value={settings.codeFont}\n presets={CODE_FONT_PRESETS}\n locale={locale}\n generic=\"monospace\"\n systemFonts={fontList.families}\n defaultLabel={text.defaultOption}\n customLabel={text.customOption}\n customPlaceholder={text.customCodePlaceholder}\n systemGroupLabel={text.systemGroup}\n onCommit={value => update({ codeFont: value })}\n />\n <label className=\"dsh-ui-field\">\n <span className=\"dsh-ui-label\">{text.fontSize}</span>\n <select\n className=\"dsh-ui-select\"\n value={fontSize}\n onChange={event => {\n const px = Number(event.target.value)\n if (Number.isInteger(px) && px >= FONT_SIZE_MIN && px <= FONT_SIZE_MAX && px !== fontSize) {\n // The theme service is the only write entry; it validates again and\n // persists through the host settings scope, and theme/change keeps\n // this panel in sync with the native Settings → General stepper.\n try { props.client.theme.setFontSize('text', px) } catch { /* out-of-range guard already applied */ }\n }\n }}\n >\n {sizes.map(px => <option key={px} value={px}>{px}px</option>)}\n </select>\n <span className=\"dsh-ui-help\">{text.sizeHelp}</span>\n </label>\n <div className=\"dsh-ui-form-footer\">\n <Button variant=\"outline\" size=\"md\" disabled={fontList.state === 'loading'}\n onClick={() => { void loadSystemFonts() }}>\n {fontList.state === 'loading' ? text.loadingFonts : fontList.state === 'ready' ? text.reloadFonts : text.loadFonts}\n </Button>\n <Button variant=\"outline\" size=\"md\" onClick={() => {\n update({ uiFont: '', codeFont: '' })\n if (fontSize !== FONT_SIZE_DEFAULT) props.client.theme.setFontSize('text', FONT_SIZE_DEFAULT)\n }}>{text.reset}</Button>\n </div>\n {fontList.state === 'ready' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsLoaded(fontList.families.length)}</p> : null}\n {fontList.state === 'ready' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsPartial}</p> : null}\n {fontList.state === 'denied' ? <p role=\"status\" className=\"dsh-ui-hint\">{text.fontsDenied}</p> : null}\n </section>\n}\n\nexport function apply(ctx: Context): void {\n const client = ctx as unknown as Client & { effect: Context['effect'] }\n const store = createFontSettingsStore(readStorage())\n migrateFontPreferences(client.theme, store, readStorage())\n ctx.effect(() => {\n if (typeof document === 'undefined') return () => {}\n const style = document.createElement('style')\n style.setAttribute('data-plugin', PLUGIN_NAME)\n style.textContent = styles\n document.head.appendChild(style)\n return () => style.remove()\n }, 'font.styles')\n ctx.effect(() => client.slots.inject('plugins.bundle.config', () => client.slots.register(\n { name: 'plugins.bundle.config', key: PLUGIN_NAME },\n (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. --- */
|
|
410
410
|
& .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }
|
|
411
411
|
& .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }
|
|
412
|
+
/* Plugin detail pages share one reading column. These are layout recipes;
|
|
413
|
+
* controls keep their own primitive styles. Form spacing follows the host's
|
|
414
|
+
* settings-form/fields.module.css and SettingsForm.module.css. */
|
|
415
|
+
& .dsh-ui-page { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 760px; min-width: 0; }
|
|
416
|
+
& .dsh-ui-form { display: flex; flex-direction: column; gap: 0; min-width: 0; }
|
|
417
|
+
&.dsh-ui-form > .dsh-ui-field, & .dsh-ui-form > .dsh-ui-field { padding: 12px 0; }
|
|
418
|
+
& .dsh-ui-form-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 16px; min-width: 0; }
|
|
419
|
+
& .dsh-ui-fields-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
420
|
+
@media (max-width: 560px) {
|
|
421
|
+
& .dsh-ui-fields-grid { grid-template-columns: minmax(0, 1fr); }
|
|
422
|
+
}
|
|
412
423
|
& .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
413
424
|
& .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
|
414
425
|
& .dsh-ui-spacer { flex: 1; min-width: 0; }
|
|
@@ -436,6 +447,9 @@ ${scope} {
|
|
|
436
447
|
* official primitive, so this only owns the vertical rhythm. --- */
|
|
437
448
|
& .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
438
449
|
& .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }
|
|
450
|
+
/* Grid fields share a row, so the stacked-field divider must not win later in
|
|
451
|
+
* the cascade. Reset it here, after the field recipe. */
|
|
452
|
+
& .dsh-ui-fields-grid > .dsh-ui-field { padding: 0; border: 0; }
|
|
439
453
|
& .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
|
|
440
454
|
& .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
|
441
455
|
& .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
|
|
@@ -626,7 +640,7 @@ ${scope} {
|
|
|
626
640
|
& *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
|
|
627
641
|
}
|
|
628
642
|
}
|
|
629
|
-
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(
|
|
643
|
+
`.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?=\s*\{)/gm, (_match, className) => `&${className}, & ${className}`);
|
|
630
644
|
}
|
|
631
645
|
//#endregion
|
|
632
646
|
//#region src/client.tsx
|
|
@@ -688,8 +702,7 @@ function fontCopy(locale) {
|
|
|
688
702
|
return COPY[locale];
|
|
689
703
|
}
|
|
690
704
|
const styles = `${officialUiCss("font-root")}
|
|
691
|
-
.font-root {
|
|
692
|
-
.font-custom { margin-top: 8px; }
|
|
705
|
+
.font-root .font-custom { margin-top: 8px; }
|
|
693
706
|
`;
|
|
694
707
|
function readStorage() {
|
|
695
708
|
try {
|
|
@@ -839,7 +852,7 @@ function FontSettingsPanel(props) {
|
|
|
839
852
|
const sizes = [];
|
|
840
853
|
for (let px = 10; px <= 22; px += 1) sizes.push(px);
|
|
841
854
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
842
|
-
className: "font-root dsh-ui-
|
|
855
|
+
className: "font-root dsh-ui-page dsh-ui-form",
|
|
843
856
|
"data-testid": "font-settings",
|
|
844
857
|
children: [
|
|
845
858
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
|
|
@@ -898,7 +911,7 @@ function FontSettingsPanel(props) {
|
|
|
898
911
|
]
|
|
899
912
|
}),
|
|
900
913
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
901
|
-
className: "dsh-ui-
|
|
914
|
+
className: "dsh-ui-form-footer",
|
|
902
915
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
903
916
|
variant: "outline",
|
|
904
917
|
size: "md",
|
package/lib/contracts.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ declare const STORAGE_KEY = "klarkxy.dsh-font.v1";
|
|
|
10
10
|
declare const FONT_SIZE_MIN = 10;
|
|
11
11
|
declare const FONT_SIZE_MAX = 22;
|
|
12
12
|
declare const FONT_SIZE_DEFAULT = 14;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
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. */
|
|
15
16
|
declare const UI_FONT_VARIABLE = "--dsw-font-family";
|
|
16
17
|
declare const CODE_FONT_VARIABLE = "--ds-font-family-code";
|
|
17
18
|
interface FontSettings {
|
package/lib/contracts.js
CHANGED
|
@@ -10,8 +10,9 @@ const STORAGE_KEY = "klarkxy.dsh-font.v1";
|
|
|
10
10
|
const FONT_SIZE_MIN = 10;
|
|
11
11
|
const FONT_SIZE_MAX = 22;
|
|
12
12
|
const FONT_SIZE_DEFAULT = 14;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
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. */
|
|
15
16
|
const UI_FONT_VARIABLE = "--dsw-font-family";
|
|
16
17
|
const CODE_FONT_VARIABLE = "--ds-font-family-code";
|
|
17
18
|
function defaultFontSettings() {
|
package/lib/contracts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","names":[],"sources":["../src/contracts.ts"],"sourcesContent":["/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,\n * normalization, the CSS-variable application core, and the local store.\n * No React, no cordis — every export runs in Node tests and the browser. */\n\nexport const PLUGIN_NAME = '@klarkxy/dsh-font'\n\n/** Legacy browser-local font choices, retained as the one-time migration backup.\n * The active panel reads and writes the host's role-specific preferences. */\nexport const STORAGE_KEY = 'klarkxy.dsh-font.v1'\n\n/** Host text-role bounds, shared by the native conversation-size stepper. */\nexport const FONT_SIZE_MIN = 10\nexport const FONT_SIZE_MAX = 22\nexport const FONT_SIZE_DEFAULT = 14\n\n/** DSH rc.2 defines these font stacks on :root. Root inline overrides also\n * reach derived Markdown, brand and terminal font tokens. */\nexport const UI_FONT_VARIABLE = '--dsw-font-family'\nexport const CODE_FONT_VARIABLE = '--ds-font-family-code'\n\nexport interface FontSettings {\n /** Full CSS font-family stack for the interface; empty keeps the host default. */\n uiFont: string\n /** Full CSS font-family stack for code blocks, inline code and terminals. */\n codeFont: string\n}\n\nexport function defaultFontSettings(): FontSettings {\n return { uiFont: '', codeFont: '' }\n}\n\n/** A raw font-family string is placed into a single CSS declaration via\n * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but\n * trimming control characters and the CSS delimiters keeps pasted garbage from\n * producing a silently-dead value. */\nexport function normalizeFontFamily(value: unknown): string {\n if (typeof value !== 'string') return ''\n return value\n .replace(/[\\u0000-\\u001F\\u007F;{}<>]/g, '')\n .trim()\n .slice(0, 300)\n}\n\nexport function parseFontSettings(raw: unknown): FontSettings {\n let source = raw\n if (typeof source === 'string') {\n try {\n source = JSON.parse(source)\n } catch {\n return defaultFontSettings()\n }\n }\n if (!source || typeof source !== 'object' || Array.isArray(source)) return defaultFontSettings()\n const record = source as Record<string, unknown>\n return {\n uiFont: normalizeFontFamily(record.uiFont),\n codeFont: normalizeFontFamily(record.codeFont),\n }\n}\n\nexport function serializeFontSettings(settings: FontSettings): string {\n return JSON.stringify({\n uiFont: normalizeFontFamily(settings.uiFont),\n codeFont: normalizeFontFamily(settings.codeFont),\n })\n}\n\nexport interface FontPreset {\n readonly id: string\n readonly label: { readonly zh: string; readonly en: string }\n /** The font-family stack committed when the preset is picked. */\n readonly value: string\n}\n\nexport const UI_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'yahei', label: { zh: '微软雅黑', en: 'Microsoft YaHei' }, value: '\"Microsoft YaHei\", \"PingFang SC\", sans-serif' },\n { id: 'pingfang', label: { zh: '苹方', en: 'PingFang SC' }, value: '\"PingFang SC\", -apple-system, sans-serif' },\n { id: 'simsun', label: { zh: '宋体', en: 'SimSun' }, value: '\"SimSun\", \"Songti SC\", serif' },\n { id: 'kaiti', label: { zh: '楷体', en: 'KaiTi' }, value: '\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif' },\n { id: 'source-han-sans', label: { zh: '思源黑体', en: 'Source Han Sans' }, value: '\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif' },\n { id: 'source-han-serif', label: { zh: '思源宋体', en: 'Source Han Serif' }, value: '\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif' },\n]\n\nexport const CODE_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'cascadia', label: { zh: 'Cascadia', en: 'Cascadia' }, value: '\"Cascadia Mono\", \"Cascadia Code\", monospace' },\n { id: 'jetbrains-mono', label: { zh: 'JetBrains Mono', en: 'JetBrains Mono' }, value: '\"JetBrains Mono\", monospace' },\n { id: 'fira-code', label: { zh: 'Fira Code', en: 'Fira Code' }, value: '\"Fira Code\", monospace' },\n { id: 'consolas', label: { zh: 'Consolas', en: 'Consolas' }, value: 'Consolas, monospace' },\n { id: 'sarasa', label: { zh: '更纱黑体', en: 'Sarasa Mono' }, value: '\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace' },\n { id: 'maple-mono', label: { zh: 'Maple Mono', en: 'Maple Mono' }, value: '\"Maple Mono NF CN\", \"Maple Mono\", monospace' },\n]\n\nexport function presetFor(value: string, presets: readonly FontPreset[]): FontPreset | undefined {\n // The host quotes every non-generic family when persisting a stack.\n const comparable = (stack: string) => stack.split(',').map(name => name.trim().replace(/^[\"']|[\"']$/g, '')).join(',')\n return presets.find(preset => comparable(preset.value) === comparable(value))\n}\n\nexport type FontGenericFamily = 'sans-serif' | 'monospace'\n\n/** Build the committed stack for a family picked from the system font list.\n * The family name comes from the OS (Local Font Access API); quotes and\n * backslashes are stripped so it can be safely re-quoted as one family. */\nexport function fontStackFor(family: string, generic: FontGenericFamily): string {\n const cleaned = normalizeFontFamily(family).replace(/[\"\\\\]/g, '')\n if (!cleaned) return generic\n return `\"${cleaned}\", ${generic}`\n}\n\n/** A system font offered in the picker: `family` is the exact name CSS\n * matching needs; `fullName` is an informative localized alias (e.g. converted\n * CJK fonts whose family is the Latin alias), '' when it only restates the\n * family (\"Microsoft YaHei Regular\" adds nothing). */\nexport interface SystemFontFamily {\n readonly family: string\n readonly fullName: string\n}\n\n/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()\n * result (entries carry `family` and `fullName`; duplicates per style are\n * expected). */\nexport function uniqueSystemFonts(fonts: readonly unknown[]): SystemFontFamily[] {\n const byFamily = new Map<string, string>()\n for (const item of fonts) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) continue\n const record = item as Record<string, unknown>\n const family = normalizeFontFamily(record.family).replace(/[\"\\\\]/g, '')\n if (!family || byFamily.has(family)) continue\n const fullName = normalizeFontFamily(record.fullName).replace(/[\"\\\\]/g, '')\n byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : '')\n }\n return [...byFamily.entries()]\n .map(([family, fullName]) => ({ family, fullName }))\n .sort((a, b) => a.family.localeCompare(b.family))\n}\n\n/** Picker label: the UI locale's recognizable name leads, the alias stays in\n * parentheses because the canonical family is still what a custom input needs. */\nexport function systemFontLabel(item: SystemFontFamily, locale: 'zh' | 'en'): string {\n if (!item.fullName) return item.family\n return locale === 'zh' ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`\n}\n\n/** Minimal write face of CSSStyleDeclaration — document.documentElement.style\n * satisfies it, and tests supply a recording double. */\nexport interface FontStyleTarget {\n setProperty(name: string, value: string): void\n removeProperty(name: string): void\n}\n\nexport function applyFontSettings(style: FontStyleTarget, settings: FontSettings): void {\n if (settings.uiFont) style.setProperty(UI_FONT_VARIABLE, settings.uiFont)\n else style.removeProperty(UI_FONT_VARIABLE)\n if (settings.codeFont) style.setProperty(CODE_FONT_VARIABLE, settings.codeFont)\n else style.removeProperty(CODE_FONT_VARIABLE)\n}\n\nexport function clearFontSettings(style: FontStyleTarget): void {\n style.removeProperty(UI_FONT_VARIABLE)\n style.removeProperty(CODE_FONT_VARIABLE)\n}\n\n/** Read face required to restore only overrides still owned by this instance. */\nexport interface OwnedFontStyleTarget extends FontStyleTarget {\n getPropertyValue(name: string): string\n getPropertyPriority(name: string): string\n setProperty(name: string, value: string, priority?: string): void\n}\n\n/** Root inline overrides preserve the existing local persistence/unload\n * boundary. Save the underlying value (including !important) on first write\n * or when the host replaces a value, and never retract somebody else's write. */\nexport function createFontSettingsOverride(style: OwnedFontStyleTarget) {\n const owned = new Map<string, { previous: string; priority: string; value: string }>()\n function release(name: string) {\n const entry = owned.get(name)\n if (!entry) return\n if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === '') {\n if (entry.previous) style.setProperty(name, entry.previous, entry.priority)\n else style.removeProperty(name)\n }\n owned.delete(name)\n }\n return {\n apply(settings: FontSettings) {\n for (const [name, value] of [\n [UI_FONT_VARIABLE, settings.uiFont],\n [CODE_FONT_VARIABLE, settings.codeFont],\n ] as const) {\n if (!value) { release(name); continue }\n const current = style.getPropertyValue(name)\n const priority = style.getPropertyPriority(name)\n const entry = owned.get(name)\n if (!entry || current !== entry.value || priority !== '') {\n owned.set(name, { previous: current, priority, value: '' })\n }\n style.setProperty(name, value)\n owned.get(name)!.value = style.getPropertyValue(name)\n }\n },\n dispose() { for (const name of [...owned.keys()]) release(name) },\n }\n}\n\nexport interface FontSettingsStorage {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface FontSettingsStore {\n load(): FontSettings\n save(next: FontSettings): void\n}\n\n/** Browser-local persistence. A fully-default setting removes the key so a\n * reset leaves no residue; storage failures (private mode, quota) degrade to\n * in-memory behaviour rather than breaking the panel. */\nexport function createFontSettingsStore(storage: FontSettingsStorage | undefined): FontSettingsStore {\n let current = defaultFontSettings()\n // A failed local write must win over stale persisted values on page remount.\n // Successful writes restore the existing ability to read external updates.\n let pendingPersistence = false\n return {\n load() {\n if (storage && !pendingPersistence) {\n try {\n current = parseFontSettings(storage.getItem(STORAGE_KEY))\n } catch {\n /* keep the last readable or locally saved snapshot */\n }\n }\n return { ...current }\n },\n save(next) {\n current = parseFontSettings(next)\n if (!storage) return\n pendingPersistence = true\n try {\n if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY)\n else storage.setItem(STORAGE_KEY, serializeFontSettings(current))\n pendingPersistence = false\n } catch {\n /* stay in-memory */\n }\n },\n }\n}\n"],"mappings":";;;;AAIA,MAAa,cAAc;;;AAI3B,MAAa,cAAc;;AAG3B,MAAa,gBAAgB;AAC7B,MAAa,gBAAgB;AAC7B,MAAa,oBAAoB;;;AAIjC,MAAa,mBAAmB;AAChC,MAAa,qBAAqB;AASlC,SAAgB,sBAAoC;CAClD,OAAO;EAAE,QAAQ;EAAI,UAAU;CAAG;AACpC;;;;;AAMA,SAAgB,oBAAoB,OAAwB;CAC1D,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MACJ,QAAQ,+BAA+B,EAAE,CAAC,CAC1C,KAAK,CAAC,CACN,MAAM,GAAG,GAAG;AACjB;AAEA,SAAgB,kBAAkB,KAA4B;CAC5D,IAAI,SAAS;CACb,IAAI,OAAO,WAAW,UACpB,IAAI;EACF,SAAS,KAAK,MAAM,MAAM;CAC5B,QAAQ;EACN,OAAO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,MAAM;KAAE,UAAU;KAAS;KAAU,OAAO;IAAG,CAAC;IAE5D,MAAM,YAAY,MAAM,KAAK;IAC7B,MAAM,IAAI,IAAI,CAAC,CAAE,QAAQ,MAAM,iBAAiB,IAAI;GACtD;EACF;EACA,UAAU;GAAE,KAAK,MAAM,QAAQ,CAAC,GAAG,MAAM,KAAK,CAAC,GAAG,QAAQ,IAAI;EAAE;CAClE;AACF;;;;AAgBA,SAAgB,wBAAwB,SAA6D;CACnG,IAAI,UAAU,oBAAoB;CAGlC,IAAI,qBAAqB;CACzB,OAAO;EACL,OAAO;GACL,IAAI,WAAW,CAAC,oBACd,IAAI;IACF,UAAU,kBAAkB,QAAQ,QAAQ,WAAW,CAAC;GAC1D,QAAQ,CAER;GAEF,OAAO,EAAE,GAAG,QAAQ;EACtB;EACA,KAAK,MAAM;GACT,UAAU,kBAAkB,IAAI;GAChC,IAAI,CAAC,SAAS;GACd,qBAAqB;GACrB,IAAI;IACF,IAAI,CAAC,QAAQ,UAAU,CAAC,QAAQ,UAAU,QAAQ,WAAW,WAAW;SACnE,QAAQ,QAAQ,aAAa,sBAAsB,OAAO,CAAC;IAChE,qBAAqB;GACvB,QAAQ,CAER;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"contracts.js","names":[],"sources":["../src/contracts.ts"],"sourcesContent":["/** Browser-safe contracts for @klarkxy/dsh-font: settings shape, font presets,\n * normalization, the CSS-variable application core, and the local store.\n * No React, no cordis — every export runs in Node tests and the browser. */\n\nexport const PLUGIN_NAME = '@klarkxy/dsh-font'\n\n/** Legacy browser-local font choices, retained as the one-time migration backup.\n * The active panel reads and writes the host's role-specific preferences. */\nexport const STORAGE_KEY = 'klarkxy.dsh-font.v1'\n\n/** Host text-role bounds, shared by the native conversation-size stepper. */\nexport const FONT_SIZE_MIN = 10\nexport const FONT_SIZE_MAX = 22\nexport const FONT_SIZE_DEFAULT = 14\n\n/** Root font overrides reach derived Markdown, brand and terminal fonts.\n * These are the host variables this feature changes, rather than a private\n * palette used to style the plugin's settings page. */\nexport const UI_FONT_VARIABLE = '--dsw-font-family'\nexport const CODE_FONT_VARIABLE = '--ds-font-family-code'\n\nexport interface FontSettings {\n /** Full CSS font-family stack for the interface; empty keeps the host default. */\n uiFont: string\n /** Full CSS font-family stack for code blocks, inline code and terminals. */\n codeFont: string\n}\n\nexport function defaultFontSettings(): FontSettings {\n return { uiFont: '', codeFont: '' }\n}\n\n/** A raw font-family string is placed into a single CSS declaration via\n * CSSStyleDeclaration.setProperty, which cannot escape the declaration — but\n * trimming control characters and the CSS delimiters keeps pasted garbage from\n * producing a silently-dead value. */\nexport function normalizeFontFamily(value: unknown): string {\n if (typeof value !== 'string') return ''\n return value\n .replace(/[\\u0000-\\u001F\\u007F;{}<>]/g, '')\n .trim()\n .slice(0, 300)\n}\n\nexport function parseFontSettings(raw: unknown): FontSettings {\n let source = raw\n if (typeof source === 'string') {\n try {\n source = JSON.parse(source)\n } catch {\n return defaultFontSettings()\n }\n }\n if (!source || typeof source !== 'object' || Array.isArray(source)) return defaultFontSettings()\n const record = source as Record<string, unknown>\n return {\n uiFont: normalizeFontFamily(record.uiFont),\n codeFont: normalizeFontFamily(record.codeFont),\n }\n}\n\nexport function serializeFontSettings(settings: FontSettings): string {\n return JSON.stringify({\n uiFont: normalizeFontFamily(settings.uiFont),\n codeFont: normalizeFontFamily(settings.codeFont),\n })\n}\n\nexport interface FontPreset {\n readonly id: string\n readonly label: { readonly zh: string; readonly en: string }\n /** The font-family stack committed when the preset is picked. */\n readonly value: string\n}\n\nexport const UI_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'yahei', label: { zh: '微软雅黑', en: 'Microsoft YaHei' }, value: '\"Microsoft YaHei\", \"PingFang SC\", sans-serif' },\n { id: 'pingfang', label: { zh: '苹方', en: 'PingFang SC' }, value: '\"PingFang SC\", -apple-system, sans-serif' },\n { id: 'simsun', label: { zh: '宋体', en: 'SimSun' }, value: '\"SimSun\", \"Songti SC\", serif' },\n { id: 'kaiti', label: { zh: '楷体', en: 'KaiTi' }, value: '\"KaiTi\", \"Kaiti SC\", \"STKaiti\", serif' },\n { id: 'source-han-sans', label: { zh: '思源黑体', en: 'Source Han Sans' }, value: '\"Source Han Sans SC\", \"Noto Sans CJK SC\", \"Noto Sans SC\", sans-serif' },\n { id: 'source-han-serif', label: { zh: '思源宋体', en: 'Source Han Serif' }, value: '\"Source Han Serif SC\", \"Noto Serif CJK SC\", \"Noto Serif SC\", serif' },\n]\n\nexport const CODE_FONT_PRESETS: readonly FontPreset[] = [\n { id: 'cascadia', label: { zh: 'Cascadia', en: 'Cascadia' }, value: '\"Cascadia Mono\", \"Cascadia Code\", monospace' },\n { id: 'jetbrains-mono', label: { zh: 'JetBrains Mono', en: 'JetBrains Mono' }, value: '\"JetBrains Mono\", monospace' },\n { id: 'fira-code', label: { zh: 'Fira Code', en: 'Fira Code' }, value: '\"Fira Code\", monospace' },\n { id: 'consolas', label: { zh: 'Consolas', en: 'Consolas' }, value: 'Consolas, monospace' },\n { id: 'sarasa', label: { zh: '更纱黑体', en: 'Sarasa Mono' }, value: '\"Sarasa Mono SC\", \"Sarasa Term SC\", monospace' },\n { id: 'maple-mono', label: { zh: 'Maple Mono', en: 'Maple Mono' }, value: '\"Maple Mono NF CN\", \"Maple Mono\", monospace' },\n]\n\nexport function presetFor(value: string, presets: readonly FontPreset[]): FontPreset | undefined {\n // The host quotes every non-generic family when persisting a stack.\n const comparable = (stack: string) => stack.split(',').map(name => name.trim().replace(/^[\"']|[\"']$/g, '')).join(',')\n return presets.find(preset => comparable(preset.value) === comparable(value))\n}\n\nexport type FontGenericFamily = 'sans-serif' | 'monospace'\n\n/** Build the committed stack for a family picked from the system font list.\n * The family name comes from the OS (Local Font Access API); quotes and\n * backslashes are stripped so it can be safely re-quoted as one family. */\nexport function fontStackFor(family: string, generic: FontGenericFamily): string {\n const cleaned = normalizeFontFamily(family).replace(/[\"\\\\]/g, '')\n if (!cleaned) return generic\n return `\"${cleaned}\", ${generic}`\n}\n\n/** A system font offered in the picker: `family` is the exact name CSS\n * matching needs; `fullName` is an informative localized alias (e.g. converted\n * CJK fonts whose family is the Latin alias), '' when it only restates the\n * family (\"Microsoft YaHei Regular\" adds nothing). */\nexport interface SystemFontFamily {\n readonly family: string\n readonly fullName: string\n}\n\n/** Distinct, normalized, family-sorted entries out of a queryLocalFonts()\n * result (entries carry `family` and `fullName`; duplicates per style are\n * expected). */\nexport function uniqueSystemFonts(fonts: readonly unknown[]): SystemFontFamily[] {\n const byFamily = new Map<string, string>()\n for (const item of fonts) {\n if (!item || typeof item !== 'object' || Array.isArray(item)) continue\n const record = item as Record<string, unknown>\n const family = normalizeFontFamily(record.family).replace(/[\"\\\\]/g, '')\n if (!family || byFamily.has(family)) continue\n const fullName = normalizeFontFamily(record.fullName).replace(/[\"\\\\]/g, '')\n byFamily.set(family, fullName && fullName !== family && !fullName.startsWith(`${family} `) ? fullName : '')\n }\n return [...byFamily.entries()]\n .map(([family, fullName]) => ({ family, fullName }))\n .sort((a, b) => a.family.localeCompare(b.family))\n}\n\n/** Picker label: the UI locale's recognizable name leads, the alias stays in\n * parentheses because the canonical family is still what a custom input needs. */\nexport function systemFontLabel(item: SystemFontFamily, locale: 'zh' | 'en'): string {\n if (!item.fullName) return item.family\n return locale === 'zh' ? `${item.fullName}(${item.family})` : `${item.family}(${item.fullName})`\n}\n\n/** Minimal write face of CSSStyleDeclaration — document.documentElement.style\n * satisfies it, and tests supply a recording double. */\nexport interface FontStyleTarget {\n setProperty(name: string, value: string): void\n removeProperty(name: string): void\n}\n\nexport function applyFontSettings(style: FontStyleTarget, settings: FontSettings): void {\n if (settings.uiFont) style.setProperty(UI_FONT_VARIABLE, settings.uiFont)\n else style.removeProperty(UI_FONT_VARIABLE)\n if (settings.codeFont) style.setProperty(CODE_FONT_VARIABLE, settings.codeFont)\n else style.removeProperty(CODE_FONT_VARIABLE)\n}\n\nexport function clearFontSettings(style: FontStyleTarget): void {\n style.removeProperty(UI_FONT_VARIABLE)\n style.removeProperty(CODE_FONT_VARIABLE)\n}\n\n/** Read face required to restore only overrides still owned by this instance. */\nexport interface OwnedFontStyleTarget extends FontStyleTarget {\n getPropertyValue(name: string): string\n getPropertyPriority(name: string): string\n setProperty(name: string, value: string, priority?: string): void\n}\n\n/** Root inline overrides preserve the existing local persistence/unload\n * boundary. Save the underlying value (including !important) on first write\n * or when the host replaces a value, and never retract somebody else's write. */\nexport function createFontSettingsOverride(style: OwnedFontStyleTarget) {\n const owned = new Map<string, { previous: string; priority: string; value: string }>()\n function release(name: string) {\n const entry = owned.get(name)\n if (!entry) return\n if (style.getPropertyValue(name) === entry.value && style.getPropertyPriority(name) === '') {\n if (entry.previous) style.setProperty(name, entry.previous, entry.priority)\n else style.removeProperty(name)\n }\n owned.delete(name)\n }\n return {\n apply(settings: FontSettings) {\n for (const [name, value] of [\n [UI_FONT_VARIABLE, settings.uiFont],\n [CODE_FONT_VARIABLE, settings.codeFont],\n ] as const) {\n if (!value) { release(name); continue }\n const current = style.getPropertyValue(name)\n const priority = style.getPropertyPriority(name)\n const entry = owned.get(name)\n if (!entry || current !== entry.value || priority !== '') {\n owned.set(name, { previous: current, priority, value: '' })\n }\n style.setProperty(name, value)\n owned.get(name)!.value = style.getPropertyValue(name)\n }\n },\n dispose() { for (const name of [...owned.keys()]) release(name) },\n }\n}\n\nexport interface FontSettingsStorage {\n getItem(key: string): string | null\n setItem(key: string, value: string): void\n removeItem(key: string): void\n}\n\nexport interface FontSettingsStore {\n load(): FontSettings\n save(next: FontSettings): void\n}\n\n/** Browser-local persistence. A fully-default setting removes the key so a\n * reset leaves no residue; storage failures (private mode, quota) degrade to\n * in-memory behaviour rather than breaking the panel. */\nexport function createFontSettingsStore(storage: FontSettingsStorage | undefined): FontSettingsStore {\n let current = defaultFontSettings()\n // A failed local write must win over stale persisted values on page remount.\n // Successful writes restore the existing ability to read external updates.\n let pendingPersistence = false\n return {\n load() {\n if (storage && !pendingPersistence) {\n try {\n current = parseFontSettings(storage.getItem(STORAGE_KEY))\n } catch {\n /* keep the last readable or locally saved snapshot */\n }\n }\n return { ...current }\n },\n save(next) {\n current = parseFontSettings(next)\n if (!storage) return\n pendingPersistence = true\n try {\n if (!current.uiFont && !current.codeFont) storage.removeItem(STORAGE_KEY)\n else storage.setItem(STORAGE_KEY, serializeFontSettings(current))\n pendingPersistence = false\n } catch {\n /* stay in-memory */\n }\n },\n }\n}\n"],"mappings":";;;;AAIA,MAAa,cAAc;;;AAI3B,MAAa,cAAc;;AAG3B,MAAa,gBAAgB;AAC7B,MAAa,gBAAgB;AAC7B,MAAa,oBAAoB;;;;AAKjC,MAAa,mBAAmB;AAChC,MAAa,qBAAqB;AASlC,SAAgB,sBAAoC;CAClD,OAAO;EAAE,QAAQ;EAAI,UAAU;CAAG;AACpC;;;;;AAMA,SAAgB,oBAAoB,OAAwB;CAC1D,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,OAAO,MACJ,QAAQ,+BAA+B,EAAE,CAAC,CAC1C,KAAK,CAAC,CACN,MAAM,GAAG,GAAG;AACjB;AAEA,SAAgB,kBAAkB,KAA4B;CAC5D,IAAI,SAAS;CACb,IAAI,OAAO,WAAW,UACpB,IAAI;EACF,SAAS,KAAK,MAAM,MAAM;CAC5B,QAAQ;EACN,OAAO,oBAAoB;CAC7B;CAEF,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG,OAAO,oBAAoB;CAC/F,MAAM,SAAS;CACf,OAAO;EACL,QAAQ,oBAAoB,OAAO,MAAM;EACzC,UAAU,oBAAoB,OAAO,QAAQ;CAC/C;AACF;AAEA,SAAgB,sBAAsB,UAAgC;CACpE,OAAO,KAAK,UAAU;EACpB,QAAQ,oBAAoB,SAAS,MAAM;EAC3C,UAAU,oBAAoB,SAAS,QAAQ;CACjD,CAAC;AACH;AASA,MAAa,kBAAyC;CACpD;EAAE,IAAI;EAAS,OAAO;GAAE,IAAI;GAAQ,IAAI;EAAkB;EAAG,OAAO;CA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C;GAC1D,QAAQ,CAER;GAEF,OAAO,EAAE,GAAG,QAAQ;EACtB;EACA,KAAK,MAAM;GACT,UAAU,kBAAkB,IAAI;GAChC,IAAI,CAAC,SAAS;GACd,qBAAqB;GACrB,IAAI;IACF,IAAI,CAAC,QAAQ,UAAU,CAAC,QAAQ,UAAU,QAAQ,WAAW,WAAW;SACnE,QAAQ,QAAQ,aAAa,sBAAsB,OAAO,CAAC;IAChE,qBAAqB;GACvB,QAAQ,CAER;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klarkxy/dsh-font",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Font: customize the interface font, code font, and conversation font size of the DeepSeek Harness Web GUI.",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@deepseek-ai/cordis": ">=4.0.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@klarkxy/dsh-plugin-kit": "0.
|
|
63
|
+
"@klarkxy/dsh-plugin-kit": "0.5.0",
|
|
64
64
|
"@deepseek-ai/cordis": "4.0.5",
|
|
65
65
|
"react": "^18.2.0",
|
|
66
66
|
"@types/react": "18.3.31",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
},
|
|
96
96
|
"homepage": "https://klarkxy.github.io/dsh-plugins/plugins/font/",
|
|
97
97
|
"dshRelease": {
|
|
98
|
-
"contentHash": "
|
|
98
|
+
"contentHash": "b13c66bd161d995299a9826c4aee408b2c6d8c4dbea1e33ca74a0ff933321912"
|
|
99
99
|
},
|
|
100
100
|
"peerDependenciesMeta": {
|
|
101
101
|
"@deepseek-ai/cordis": {
|