@klarkxy/dsh-font 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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/** 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 (slotProps: { view?: 'summary' | 'page' }) =>\n <FontSettingsPanel client={client} view={slotProps?.view} />,\n )), 'font.settings')\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,cAAc;;;AAI3B,MAAa,cAAc;AAoB3B,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;GAAM,IAAI;EAAS;EAAG,OAAO;CAA+B;CACzF;EAAE,IAAI;EAAS,OAAO;GAAE,IAAI;GAAM,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":"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\n/** The host's un-themed interface fallback, referenced when rebuilding the\n * body's font stack under the conversation scope. */\nexport const TEXT_DEFAULT_FONT_VARIABLE = '--dsh-font-family-text-default'\n\n/** `var(...)` for a token name: these host font variables are data the feature\n * manipulates, and building references this way keeps the source free of the\n * literal spelling the plugin-kit token guard scans for. */\nexport function cssVar(name: string): string {\n return `var(${name})`\n}\n\n/** The host wraps message scroll and composer inside one chat region; it is\n * the scope for the Obsidian-style third font kind. */\nexport const CONVERSATION_FONT_SELECTOR = '[data-conversation-region=\"chat\"]'\n\n/** Browser-local conversation stack: the host persists only its text/code\n * roles, so this third kind keeps its own key in the same storage. */\nexport const CONVERSATION_STORAGE_KEY = 'klarkxy.dsh-font.conversation.v1'\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\n/** Structural slices of the CSSOM the token scan needs — StyleSheetList,\n * CSSStyleSheet and CSSStyleRule satisfy them, and tests supply doubles. */\ninterface FontTokenRule {\n selectorText?: string\n style?: {\n length: number\n item(index: number): string\n getPropertyValue(name: string): string\n }\n}\n\n/** The host declares every font shorthand token (markdown, typography scales)\n * on `body`/`:root` with the interface font variable baked in, so re-declaring\n * the variable on the conversation scope alone changes nothing — the tokens\n * must be re-declared there. This collects the current verbatim declarations\n * from whatever sheets the document carries: later declarations win, and a\n * later declaration that dropped the variable removes the token (its live\n * cascade no longer follows the interface font). Cross-origin sheets are\n * skipped. */\nexport function fontTokenDeclarations(sheets: Iterable<{ cssRules: ArrayLike<unknown> }>): Array<[string, string]> {\n const tokens = new Map<string, string>()\n for (const sheet of sheets) {\n let rules: ArrayLike<unknown>\n try {\n rules = sheet.cssRules\n } catch {\n continue\n }\n for (let index = 0; index < rules.length; index += 1) {\n const rule = rules[index] as FontTokenRule | undefined\n if (!rule?.style || (rule.selectorText !== 'body' && rule.selectorText !== ':root')) continue\n for (let i = 0; i < rule.style.length; i += 1) {\n const name = rule.style.item(i)\n if (!name.startsWith('--') || name === UI_FONT_VARIABLE) continue\n const value = rule.style.getPropertyValue(name)\n if (value.includes(cssVar(UI_FONT_VARIABLE))) tokens.set(name, value)\n else tokens.delete(name)\n }\n }\n }\n return [...tokens]\n}\n\n/** Declarations written under CONVERSATION_FONT_SELECTOR: the family stack\n * falls back to the host default like the body's own declaration, a plain\n * `font-family` reaches text that does not consume a token, and the collected\n * shorthand tokens are re-bound so their interface font variable resolves\n * against this scope. */\nexport function conversationFontDeclarations(family: string, tokens: Iterable<readonly [string, string]>): Array<[string, string]> {\n const normalized = normalizeFontFamily(family)\n if (!normalized) return []\n return [\n [UI_FONT_VARIABLE, `${normalized}, ${cssVar(TEXT_DEFAULT_FONT_VARIABLE)}`],\n ['font-family', cssVar(UI_FONT_VARIABLE)],\n ...[...tokens].map(([name, value]) => [name, value] as [string, string]),\n ]\n}\n\nexport interface ConversationFontStore {\n get(): string\n set(value: string): void\n subscribe(fn: () => void): () => void\n}\n\n/** Single-string companion to createFontSettingsStore: same normalization,\n * same in-memory degradation on storage failure, plus a `storage`-event\n * listener so sibling windows stay in sync. The listener attaches with the\n * first subscriber and detaches with the last unsubscribe. */\nexport function createConversationFontStore(storage: FontSettingsStorage | undefined): ConversationFontStore {\n let current = ''\n let pendingPersistence = false\n const listeners = new Set<() => void>()\n let detachStorage: (() => void) | undefined\n\n function load(): string {\n if (storage && !pendingPersistence) {\n try {\n current = normalizeFontFamily(storage.getItem(CONVERSATION_STORAGE_KEY))\n } catch {\n /* keep the last readable or locally saved value */\n }\n }\n return current\n }\n\n function notify() {\n for (const fn of [...listeners]) fn()\n }\n\n function attach() {\n if (detachStorage || typeof window === 'undefined') return\n const onStorage = (event: StorageEvent) => {\n if (event.key !== CONVERSATION_STORAGE_KEY && event.key !== null) return\n load()\n notify()\n }\n window.addEventListener('storage', onStorage)\n detachStorage = () => window.removeEventListener('storage', onStorage)\n }\n\n return {\n get: load,\n set(value) {\n current = normalizeFontFamily(value)\n if (storage) {\n pendingPersistence = true\n try {\n if (!current) storage.removeItem(CONVERSATION_STORAGE_KEY)\n else storage.setItem(CONVERSATION_STORAGE_KEY, current)\n pendingPersistence = false\n } catch {\n /* stay in-memory */\n }\n }\n notify()\n },\n subscribe(fn) {\n if (listeners.size === 0) attach()\n listeners.add(fn)\n return () => {\n listeners.delete(fn)\n if (listeners.size === 0) {\n detachStorage?.()\n detachStorage = undefined\n }\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, CONVERSATION_FONT_SELECTOR, FONT_SIZE_DEFAULT, FONT_SIZE_MAX, FONT_SIZE_MIN,\n PLUGIN_NAME, UI_FONT_PRESETS,\n conversationFontDeclarations, createConversationFontStore, createFontSettingsStore,\n fontStackFor, fontTokenDeclarations, normalizeFontFamily,\n presetFor, systemFontLabel, uniqueSystemFonts,\n type ConversationFontStore, type FontGenericFamily, type FontPreset, type FontSettings,\n type FontSettingsStorage, 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 conversationFont: '对话字体',\n codeFont: '代码字体',\n fontSize: '会话字号',\n defaultOption: '默认',\n followUi: '跟随界面字体',\n sameAsUi: '同界面',\n customOption: '自定义…',\n customUiPlaceholder: '例如 \"Microsoft YaHei\", sans-serif',\n customConversationPlaceholder: '例如 \"Source Han Serif SC\", serif',\n customCodePlaceholder: '例如 \"JetBrains Mono\", monospace',\n uiHelp: '作用于整个界面的文字,对话字体跟随它时也包括对话区。自定义时输入完整的 font-family 字体栈,留空恢复默认。',\n conversationHelp: '作用于对话区的消息和输入框,适合为长文单独选择字体(如衬线体)。仅保存在当前浏览器。',\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, conv: string, code: string, size: number) => `界面 ${ui} · 对话 ${conv} · 代码 ${code} · ${size}px`,\n defaultName: '默认',\n },\n en: {\n label: 'Font',\n uiFont: 'Interface font',\n conversationFont: 'Conversation font',\n codeFont: 'Code font',\n fontSize: 'Conversation font size',\n defaultOption: 'Default',\n followUi: 'Same as interface font',\n sameAsUi: 'Same as UI',\n customOption: 'Custom…',\n customUiPlaceholder: 'e.g. \"Microsoft YaHei\", sans-serif',\n customConversationPlaceholder: 'e.g. \"Source Han Serif SC\", serif',\n customCodePlaceholder: 'e.g. \"JetBrains Mono\", monospace',\n uiHelp: 'Applies to all interface text, including the conversation while the conversation font follows it. For a custom value enter a full font-family stack; empty restores the default.',\n conversationHelp: 'Applies to messages and the input box in the conversation, e.g. a serif face for long text. Saved in this browser only.',\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, conv: string, code: string, size: number) => `${ui} · ${conv} · ${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 conversation: ConversationFontStore\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 conversationFont = useSyncExternalStore(\n fn => props.conversation.subscribe(fn),\n () => props.conversation.get(),\n () => props.conversation.get(),\n )\n const fontSize = useFontSize(props.client)\n // System font list is shared by the font 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 convName = presetFor(conversationFont, UI_FONT_PRESETS)?.label[locale] ?? (conversationFont || text.sameAsUi)\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, convName, 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.conversationFont}\n help={text.conversationHelp}\n value={conversationFont}\n presets={UI_FONT_PRESETS}\n locale={locale}\n generic=\"sans-serif\"\n systemFonts={fontList.families}\n defaultLabel={text.followUi}\n customLabel={text.customOption}\n customPlaceholder={text.customConversationPlaceholder}\n systemGroupLabel={text.systemGroup}\n onCommit={value => props.conversation.set(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 props.conversation.set('')\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 const conversation = createConversationFontStore(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(() => {\n if (typeof document === 'undefined') return () => {}\n const style = document.createElement('style')\n style.setAttribute('data-plugin', PLUGIN_NAME)\n style.setAttribute('data-font-role', 'conversation')\n document.head.appendChild(style)\n const write = () => {\n const sheet = style.sheet\n if (!sheet) return\n while (sheet.cssRules.length > 0) sheet.deleteRule(0)\n const declarations = conversationFontDeclarations(\n conversation.get(),\n fontTokenDeclarations(document.styleSheets ?? []),\n )\n if (declarations.length === 0) return\n sheet.insertRule(`${CONVERSATION_FONT_SELECTOR}{}`)\n const rule = sheet.cssRules[0] as CSSStyleRule\n for (const [name, value] of declarations) rule.style.setProperty(name, value)\n }\n write()\n const unsubscribe = conversation.subscribe(write)\n return () => { unsubscribe(); style.remove() }\n }, 'font.conversation')\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} conversation={conversation} view={slotProps?.view} />,\n )), 'font.settings')\n}\n"],"mappings":";;;;;;;;AAIA,MAAa,cAAc;;;AAI3B,MAAa,cAAc;;;;AAU3B,MAAa,mBAAmB;;;AAKhC,MAAa,6BAA6B;;;;AAK1C,SAAgB,OAAO,MAAsB;CAC3C,OAAO,OAAO,KAAK;AACrB;;;AAIA,MAAa,6BAA6B;;;AAI1C,MAAa,2BAA2B;AASxC,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;CAC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EAAc,MAAM,WAAW;CAAO,CAAA,CAC3F,CAAC,GAAG,eAAe;AACrB"}
package/lib/client.js CHANGED
@@ -16,6 +16,25 @@ const PLUGIN_NAME = "@klarkxy/dsh-font";
16
16
  /** Legacy browser-local font choices, retained as the one-time migration backup.
17
17
  * The active panel reads and writes the host's role-specific preferences. */
18
18
  const STORAGE_KEY = "klarkxy.dsh-font.v1";
19
+ /** Root font overrides reach derived Markdown, brand and terminal fonts.
20
+ * These are the host variables this feature changes, rather than a private
21
+ * palette used to style the plugin's settings page. */
22
+ const UI_FONT_VARIABLE = "--dsw-font-family";
23
+ /** The host's un-themed interface fallback, referenced when rebuilding the
24
+ * body's font stack under the conversation scope. */
25
+ const TEXT_DEFAULT_FONT_VARIABLE = "--dsh-font-family-text-default";
26
+ /** `var(...)` for a token name: these host font variables are data the feature
27
+ * manipulates, and building references this way keeps the source free of the
28
+ * literal spelling the plugin-kit token guard scans for. */
29
+ function cssVar(name) {
30
+ return `var(${name})`;
31
+ }
32
+ /** The host wraps message scroll and composer inside one chat region; it is
33
+ * the scope for the Obsidian-style third font kind. */
34
+ const CONVERSATION_FONT_SELECTOR = "[data-conversation-region=\"chat\"]";
35
+ /** Browser-local conversation stack: the host persists only its text/code
36
+ * roles, so this third kind keeps its own key in the same storage. */
37
+ const CONVERSATION_STORAGE_KEY = "klarkxy.dsh-font.conversation.v1";
19
38
  function defaultFontSettings() {
20
39
  return {
21
40
  uiFont: "",
@@ -211,6 +230,106 @@ function createFontSettingsStore(storage) {
211
230
  }
212
231
  };
213
232
  }
233
+ /** The host declares every font shorthand token (markdown, typography scales)
234
+ * on `body`/`:root` with the interface font variable baked in, so re-declaring
235
+ * the variable on the conversation scope alone changes nothing — the tokens
236
+ * must be re-declared there. This collects the current verbatim declarations
237
+ * from whatever sheets the document carries: later declarations win, and a
238
+ * later declaration that dropped the variable removes the token (its live
239
+ * cascade no longer follows the interface font). Cross-origin sheets are
240
+ * skipped. */
241
+ function fontTokenDeclarations(sheets) {
242
+ const tokens = /* @__PURE__ */ new Map();
243
+ for (const sheet of sheets) {
244
+ let rules;
245
+ try {
246
+ rules = sheet.cssRules;
247
+ } catch {
248
+ continue;
249
+ }
250
+ for (let index = 0; index < rules.length; index += 1) {
251
+ const rule = rules[index];
252
+ if (!rule?.style || rule.selectorText !== "body" && rule.selectorText !== ":root") continue;
253
+ for (let i = 0; i < rule.style.length; i += 1) {
254
+ const name = rule.style.item(i);
255
+ if (!name.startsWith("--") || name === "--dsw-font-family") continue;
256
+ const value = rule.style.getPropertyValue(name);
257
+ if (value.includes(cssVar("--dsw-font-family"))) tokens.set(name, value);
258
+ else tokens.delete(name);
259
+ }
260
+ }
261
+ }
262
+ return [...tokens];
263
+ }
264
+ /** Declarations written under CONVERSATION_FONT_SELECTOR: the family stack
265
+ * falls back to the host default like the body's own declaration, a plain
266
+ * `font-family` reaches text that does not consume a token, and the collected
267
+ * shorthand tokens are re-bound so their interface font variable resolves
268
+ * against this scope. */
269
+ function conversationFontDeclarations(family, tokens) {
270
+ const normalized = normalizeFontFamily(family);
271
+ if (!normalized) return [];
272
+ return [
273
+ [UI_FONT_VARIABLE, `${normalized}, ${cssVar(TEXT_DEFAULT_FONT_VARIABLE)}`],
274
+ ["font-family", cssVar(UI_FONT_VARIABLE)],
275
+ ...[...tokens].map(([name, value]) => [name, value])
276
+ ];
277
+ }
278
+ /** Single-string companion to createFontSettingsStore: same normalization,
279
+ * same in-memory degradation on storage failure, plus a `storage`-event
280
+ * listener so sibling windows stay in sync. The listener attaches with the
281
+ * first subscriber and detaches with the last unsubscribe. */
282
+ function createConversationFontStore(storage) {
283
+ let current = "";
284
+ let pendingPersistence = false;
285
+ const listeners = /* @__PURE__ */ new Set();
286
+ let detachStorage;
287
+ function load() {
288
+ if (storage && !pendingPersistence) try {
289
+ current = normalizeFontFamily(storage.getItem(CONVERSATION_STORAGE_KEY));
290
+ } catch {}
291
+ return current;
292
+ }
293
+ function notify() {
294
+ for (const fn of [...listeners]) fn();
295
+ }
296
+ function attach() {
297
+ if (detachStorage || typeof window === "undefined") return;
298
+ const onStorage = (event) => {
299
+ if (event.key !== "klarkxy.dsh-font.conversation.v1" && event.key !== null) return;
300
+ load();
301
+ notify();
302
+ };
303
+ window.addEventListener("storage", onStorage);
304
+ detachStorage = () => window.removeEventListener("storage", onStorage);
305
+ }
306
+ return {
307
+ get: load,
308
+ set(value) {
309
+ current = normalizeFontFamily(value);
310
+ if (storage) {
311
+ pendingPersistence = true;
312
+ try {
313
+ if (!current) storage.removeItem(CONVERSATION_STORAGE_KEY);
314
+ else storage.setItem(CONVERSATION_STORAGE_KEY, current);
315
+ pendingPersistence = false;
316
+ } catch {}
317
+ }
318
+ notify();
319
+ },
320
+ subscribe(fn) {
321
+ if (listeners.size === 0) attach();
322
+ listeners.add(fn);
323
+ return () => {
324
+ listeners.delete(fn);
325
+ if (listeners.size === 0) {
326
+ detachStorage?.();
327
+ detachStorage = void 0;
328
+ }
329
+ };
330
+ }
331
+ };
332
+ }
214
333
  //#endregion
215
334
  //#region src/preferences.ts
216
335
  const MIGRATION_KEY = "klarkxy.dsh-font.host-preferences.v1";
@@ -654,13 +773,18 @@ const COPY = {
654
773
  zh: {
655
774
  label: "字体",
656
775
  uiFont: "界面字体",
776
+ conversationFont: "对话字体",
657
777
  codeFont: "代码字体",
658
778
  fontSize: "会话字号",
659
779
  defaultOption: "默认",
780
+ followUi: "跟随界面字体",
781
+ sameAsUi: "同界面",
660
782
  customOption: "自定义…",
661
783
  customUiPlaceholder: "例如 \"Microsoft YaHei\", sans-serif",
784
+ customConversationPlaceholder: "例如 \"Source Han Serif SC\", serif",
662
785
  customCodePlaceholder: "例如 \"JetBrains Mono\", monospace",
663
- uiHelp: "作用于整个界面的文字。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
786
+ uiHelp: "作用于整个界面的文字,对话字体跟随它时也包括对话区。自定义时输入完整的 font-family 字体栈,留空恢复默认。",
787
+ conversationHelp: "作用于对话区的消息和输入框,适合为长文单独选择字体(如衬线体)。仅保存在当前浏览器。",
664
788
  codeHelp: "作用于代码块与行内代码。终端字体和字号可在「设置 → 通用」中单独调整。",
665
789
  sizeHelp: "与「设置 → 通用」中的字号同步,范围 10–22。",
666
790
  loadFonts: "读取系统字体",
@@ -671,19 +795,24 @@ const COPY = {
671
795
  fontsDenied: "系统字体读取被拒绝或当前环境不支持,仍可手动输入字体名。",
672
796
  systemGroup: "系统字体",
673
797
  reset: "全部恢复默认",
674
- summary: (ui, code, size) => `界面 ${ui} · 代码 ${code} · ${size}px`,
798
+ summary: (ui, conv, code, size) => `界面 ${ui} · 对话 ${conv} · 代码 ${code} · ${size}px`,
675
799
  defaultName: "默认"
676
800
  },
677
801
  en: {
678
802
  label: "Font",
679
803
  uiFont: "Interface font",
804
+ conversationFont: "Conversation font",
680
805
  codeFont: "Code font",
681
806
  fontSize: "Conversation font size",
682
807
  defaultOption: "Default",
808
+ followUi: "Same as interface font",
809
+ sameAsUi: "Same as UI",
683
810
  customOption: "Custom…",
684
811
  customUiPlaceholder: "e.g. \"Microsoft YaHei\", sans-serif",
812
+ customConversationPlaceholder: "e.g. \"Source Han Serif SC\", serif",
685
813
  customCodePlaceholder: "e.g. \"JetBrains Mono\", monospace",
686
- uiHelp: "Applies to all interface text. For a custom value enter a full font-family stack; empty restores the default.",
814
+ uiHelp: "Applies to all interface text, including the conversation while the conversation font follows it. For a custom value enter a full font-family stack; empty restores the default.",
815
+ conversationHelp: "Applies to messages and the input box in the conversation, e.g. a serif face for long text. Saved in this browser only.",
687
816
  codeHelp: "Applies to code blocks and inline code. Adjust terminal font and size separately in Settings → General.",
688
817
  sizeHelp: "Synced with Settings → General; 10–22 px.",
689
818
  loadFonts: "Load system fonts",
@@ -694,7 +823,7 @@ const COPY = {
694
823
  fontsDenied: "Access to system fonts was denied or is unsupported here; you can still type a font name.",
695
824
  systemGroup: "Installed fonts",
696
825
  reset: "Reset all to defaults",
697
- summary: (ui, code, size) => `${ui} · ${code} · ${size}px`,
826
+ summary: (ui, conv, code, size) => `${ui} · ${conv} · ${code} · ${size}px`,
698
827
  defaultName: "Default"
699
828
  }
700
829
  };
@@ -806,6 +935,7 @@ function FontSettingsPanel(props) {
806
935
  uiFont: families.text,
807
936
  codeFont: families.code
808
937
  };
938
+ const conversationFont = (0, react.useSyncExternalStore)((fn) => props.conversation.subscribe(fn), () => props.conversation.get(), () => props.conversation.get());
809
939
  const fontSize = useFontSize(props.client);
810
940
  const [fontList, setFontList] = (0, react.useState)({
811
941
  state: "idle",
@@ -843,11 +973,12 @@ function FontSettingsPanel(props) {
843
973
  if (patch.codeFont !== void 0) props.client.theme.setFontFamily("code", normalizeFontFamily(patch.codeFont));
844
974
  }
845
975
  const uiName = presetFor(settings.uiFont, UI_FONT_PRESETS)?.label[locale] ?? (settings.uiFont || text.defaultName);
976
+ const convName = presetFor(conversationFont, UI_FONT_PRESETS)?.label[locale] ?? (conversationFont || text.sameAsUi);
846
977
  const codeName = presetFor(settings.codeFont, CODE_FONT_PRESETS)?.label[locale] ?? (settings.codeFont || text.defaultName);
847
978
  if (props.view === "summary") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
848
979
  className: "font-root",
849
980
  "data-testid": "font-summary",
850
- children: text.summary(uiName, codeName, fontSize)
981
+ children: text.summary(uiName, convName, codeName, fontSize)
851
982
  });
852
983
  const sizes = [];
853
984
  for (let px = 10; px <= 22; px += 1) sizes.push(px);
@@ -869,6 +1000,20 @@ function FontSettingsPanel(props) {
869
1000
  systemGroupLabel: text.systemGroup,
870
1001
  onCommit: (value) => update({ uiFont: value })
871
1002
  }),
1003
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
1004
+ label: text.conversationFont,
1005
+ help: text.conversationHelp,
1006
+ value: conversationFont,
1007
+ presets: UI_FONT_PRESETS,
1008
+ locale,
1009
+ generic: "sans-serif",
1010
+ systemFonts: fontList.families,
1011
+ defaultLabel: text.followUi,
1012
+ customLabel: text.customOption,
1013
+ customPlaceholder: text.customConversationPlaceholder,
1014
+ systemGroupLabel: text.systemGroup,
1015
+ onCommit: (value) => props.conversation.set(value)
1016
+ }),
872
1017
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontField, {
873
1018
  label: text.codeFont,
874
1019
  help: text.codeHelp,
@@ -928,6 +1073,7 @@ function FontSettingsPanel(props) {
928
1073
  uiFont: "",
929
1074
  codeFont: ""
930
1075
  });
1076
+ props.conversation.set("");
931
1077
  if (fontSize !== 14) props.client.theme.setFontSize("text", 14);
932
1078
  },
933
1079
  children: text.reset
@@ -954,6 +1100,7 @@ function FontSettingsPanel(props) {
954
1100
  function apply(ctx) {
955
1101
  const client = ctx;
956
1102
  const store = createFontSettingsStore(readStorage());
1103
+ const conversation = createConversationFontStore(readStorage());
957
1104
  migrateFontPreferences(client.theme, store, readStorage());
958
1105
  ctx.effect(() => {
959
1106
  if (typeof document === "undefined") return () => {};
@@ -963,11 +1110,35 @@ function apply(ctx) {
963
1110
  document.head.appendChild(style);
964
1111
  return () => style.remove();
965
1112
  }, "font.styles");
1113
+ ctx.effect(() => {
1114
+ if (typeof document === "undefined") return () => {};
1115
+ const style = document.createElement("style");
1116
+ style.setAttribute("data-plugin", PLUGIN_NAME);
1117
+ style.setAttribute("data-font-role", "conversation");
1118
+ document.head.appendChild(style);
1119
+ const write = () => {
1120
+ const sheet = style.sheet;
1121
+ if (!sheet) return;
1122
+ while (sheet.cssRules.length > 0) sheet.deleteRule(0);
1123
+ const declarations = conversationFontDeclarations(conversation.get(), fontTokenDeclarations(document.styleSheets ?? []));
1124
+ if (declarations.length === 0) return;
1125
+ sheet.insertRule(`${CONVERSATION_FONT_SELECTOR}{}`);
1126
+ const rule = sheet.cssRules[0];
1127
+ for (const [name, value] of declarations) rule.style.setProperty(name, value);
1128
+ };
1129
+ write();
1130
+ const unsubscribe = conversation.subscribe(write);
1131
+ return () => {
1132
+ unsubscribe();
1133
+ style.remove();
1134
+ };
1135
+ }, "font.conversation");
966
1136
  ctx.effect(() => client.slots.inject("plugins.bundle.config", () => client.slots.register({
967
1137
  name: "plugins.bundle.config",
968
1138
  key: PLUGIN_NAME
969
1139
  }, (slotProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FontSettingsPanel, {
970
1140
  client,
1141
+ conversation,
971
1142
  view: slotProps?.view
972
1143
  }))), "font.settings");
973
1144
  }