Files
deepseek-harness/packages/client/ui-theme/src/index.ts
T
Turtle 849e9ebd8d feat(client): configure text, code, and terminal fonts and sizes independently
The General font-size row gains a More font settings disclosure that expands
a font field for each of text, code, and the sidebar terminal, plus code
(10-16 px) and terminal (10-20 px) size steppers. Font lists are normalized,
stored in the ui-theme namespace, embedded by the boot script, and placed
ahead of each role's built-in stack; the code size moves the code typography
tokens; the terminal applies font and size live and refits without replacing
the shell. ThemeRuntime adopts Host sections only after its own writes settle.

Refs #5217
2026-10-08 10:26:16 +08:00

66 lines
2.7 KiB
TypeScript

/** Host registration for the browser theme preference and pre-plugin palette. */
import type {} from '@deepseek-ai/dsh-settings'
import type { Volatile } from '@deepseek-ai/cordis'
import type { ThemePreference } from './theme-settings.ts'
import z from '@deepseek-ai/schemastery'
import type { Context } from '@deepseek-ai/cordis'
import type {} from '@deepseek-ai/dsh-host-webserver'
import { bootThemeInjections } from './boot-theme.ts'
import { DEFAULT_PREFERENCE, FONT_SIZE_SPECS, fontSizeSchema, THEME_PREFERENCES } from './theme-settings.ts'
export {
DEFAULT_FONT_SIZE, DEFAULT_PREFERENCE, FONT_SIZE_FIELD, FONT_SIZE_MAX, FONT_SIZE_MIN,
THEME_PREFERENCE_FIELD, THEME_PREFERENCES, THEME_SETTINGS_NAMESPACE,
type ThemePreference, type ThemeSettings,
} from './theme-settings.ts'
/** Runtime preferences projected to the browser. */
export interface Config {
/** Browser palette preference. */
preference: Volatile<ThemePreference>
/** Browser font size in pixels. */
fontSize: Volatile<number>
/** Code-block font size in pixels. */
codeFontSize: Volatile<number>
/** Sidebar terminal font size in pixels. */
terminalFontSize: Volatile<number>
/** Interface and body text font list; `''` keeps the built-in stack. */
textFontFamily: Volatile<string>
/** Code font list; `''` keeps the built-in stack. */
codeFontFamily: Volatile<string>
/** Sidebar terminal font list; `''` keeps the built-in stack. */
terminalFontFamily: Volatile<string>
}
/** Live theme and typography preferences. */
export const Config = z.object({
preference: z.union([...THEME_PREFERENCES]).default(DEFAULT_PREFERENCE).volatile(),
fontSize: fontSizeSchema(FONT_SIZE_SPECS.text).volatile(),
codeFontSize: fontSizeSchema(FONT_SIZE_SPECS.code).volatile(),
terminalFontSize: fontSizeSchema(FONT_SIZE_SPECS.terminal).volatile(),
textFontFamily: z.string().default('').volatile(),
codeFontFamily: z.string().default('').volatile(),
terminalFontFamily: z.string().default('').volatile(),
})
/** Supply the current palette before browser plugins start.
* @param ctx Host plugin context.
* @param config Validated live theme preferences.
*/
export function apply(ctx: Context, config: Config): void {
ctx.inject(['settings'], (child) => { child.effect(() => child.settings.configure({ auto: false }, ctx.fiber)) })
ctx.on('webserver/index-inject', (table) => {
table.push(...bootThemeInjections(config.preference.get(), {
text: config.fontSize.get(),
code: config.codeFontSize.get(),
terminal: config.terminalFontSize.get(),
}, {
text: config.textFontFamily.get(),
code: config.codeFontFamily.get(),
terminal: config.terminalFontFamily.get(),
}))
}, { prepend: true })
}