Skip to content

The agent that grows with you

feat(desktop): theme typography baseSize/lineHeight/letterSpacing

Brooklyn Nicholson7951ddd7297a
diff --git a/apps/desktop/src/themes/context.test.tsx b/apps/desktop/src/themes/context.test.tsx
index 5d5c077385d..db40de13fae 100644
--- a/apps/desktop/src/themes/context.test.tsx
+++ b/apps/desktop/src/themes/context.test.tsx
@@ -3,7 +3,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { $backendThemes, __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'
import { skinPref, ThemeProvider, useTheme } from './context'
-import { everforestTheme } from './presets'
+import { everforestTheme, midnightTheme } from './presets'
+import type { DesktopTheme } from './types'
+import { installUserTheme } from './user-themes'
// The live-authoring loop: Hermes writes/edits one skin file and every surface
// repaints. An in-place edit keeps the NAME — only the palette moves.
@@ -348,3 +350,66 @@ describe('ThemeProvider customCSS injection', () => {
expect(customStyleEl()?.textContent).toBe('.chat-input { font-size: 18px; }')
})
})
+
+describe('ThemeProvider theme typography (#41766)', () => {
+ beforeEach(() => {
+ window.localStorage.clear()
+ __resetBackendSkinSync()
+ cleanup()
+ })
+
+ // The merged typography is DEFAULT ← nous ← theme, so a user theme that sets
+ // only the new knobs still inherits the font stacks.
+ const bigTypeTheme: DesktopTheme = {
+ ...midnightTheme,
+ name: 'bigtype',
+ label: 'Big Type',
+ description: 'Test theme with typography overrides',
+ typography: { baseSize: '1.125rem', lineHeight: '1.65', letterSpacing: '0.01em' }
+ }
+
+ it('paints baseSize/lineHeight/letterSpacing when the active theme provides them', () => {
+ installUserTheme(bigTypeTheme)
+
+ let ctx: ReturnType<typeof useTheme>
+ render(
+ <ThemeProvider>
+ <ThemeProbe onReady={value => (ctx = value)} />
+ </ThemeProvider>
+ )
+
+ act(() => ctx!.setTheme('bigtype'))
+
+ expect(cssVar('--dt-base-size')).toBe('1.125rem')
+ expect(cssVar('--dt-line-height')).toBe('1.65')
+ expect(cssVar('--dt-letter-spacing')).toBe('0.01em')
+ })
+
+ it('drops the inline vars when switching to a theme without them, restoring the styles.css defaults', () => {
+ installUserTheme(bigTypeTheme)
+
+ let ctx: ReturnType<typeof useTheme>
+ render(
+ <ThemeProvider>
+ <ThemeProbe onReady={value => (ctx = value)} />
+ </ThemeProvider>
+ )
+
+ act(() => ctx!.setTheme('bigtype'))
+ expect(cssVar('--dt-base-size')).toBe('1.125rem')
+
+ // Built-ins carry no size/leading/tracking opinion — the inline values must
+ // go away so :root's own declarations apply again.
+ act(() => ctx!.setTheme('mono'))
+
+ expect(cssVar('--dt-base-size')).toBe('')
+ expect(cssVar('--dt-line-height')).toBe('')
+ expect(cssVar('--dt-letter-spacing')).toBe('')
+ })
+})
+
+function ThemeProbe({ onReady }: { onReady: (ctx: ReturnType<typeof useTheme>) => void }) {
+ onReady(useTheme())
+
+ return null
+}
diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsx
index 49c4c868d91..7cdc326a30b 100644
--- a/apps/desktop/src/themes/context.tsx
+++ b/apps/desktop/src/themes/context.tsx
@@ -33,7 +33,7 @@ import { $chatFontFamily, resolveChatFontFamily } from './chat-font'
import { harmonize, readableInk } from './color'
import { BUILTIN_THEME_LIST, DEFAULT_SKIN_NAME, DEFAULT_TYPOGRAPHY, nousTheme, RETIRED_SKINS } from './presets'
import { retintTheme } from './retint'
-import type { DesktopTheme, DesktopThemeColors } from './types'
+import type { DesktopTheme, DesktopThemeColors, DesktopThemeTypography } from './types'
import { $userThemes, listAllThemes, resolveTheme } from './user-themes'
// Legacy global skin (pre per-profile themes). Still the inheritance fallback
@@ -248,6 +248,28 @@ const mixesFor = (isDark: boolean): Record<string, string> => ({
'--theme-mix-bubble': isDark ? '46%' : '0%'
})
+const TYPOGRAPHY_KNOB_VARS = {
+ baseSize: '--dt-base-size',
+ lineHeight: '--dt-line-height',
+ letterSpacing: '--dt-letter-spacing'
+} as const
+
+// Optional typography knobs. They are the ONLY vars applyTheme may paint
+// inline conditionally: styles.css declares the same fallbacks on :root, so
+// a theme that stops providing one must drop the inline value — otherwise
+// the previous skin's size/leading/tracking sticks across a switch (#41766).
+function applyTypographyKnobs(root: HTMLElement, typo: Partial<DesktopThemeTypography>) {
+ for (const [key, cssVar] of Object.entries(TYPOGRAPHY_KNOB_VARS) as [keyof typeof TYPOGRAPHY_KNOB_VARS, string][]) {
+ const value = typo[key]
+
+ if (value) {
+ root.style.setProperty(cssVar, value)
+ } else {
+ root.style.removeProperty(cssVar)
+ }
+ }
+}
+
function applyTheme(theme: DesktopTheme, mode: 'light' | 'dark', chatFontFamily = $chatFontFamily.get()) {
if (typeof document === 'undefined') {
return
@@ -326,6 +348,8 @@ function applyTheme(theme: DesktopTheme, mode: 'light' | 'dark', chatFontFamily
root.style.setProperty(k, v)
}
+ applyTypographyKnobs(root, typo)
+
const chromeBg = chromeBackground(c.background, isDark)
window.hermesDesktop?.setTitleBarTheme?.({
diff --git a/apps/desktop/src/themes/types.ts b/apps/desktop/src/themes/types.ts
index 08e187468fd..c78e3ca87bc 100644
--- a/apps/desktop/src/themes/types.ts
+++ b/apps/desktop/src/themes/types.ts
@@ -4,9 +4,11 @@
* colors — Tailwind color tokens written directly to CSS vars.
* darkColors — optional hand-tuned dark variant (else `colors` is reused
* unchanged for dark, and a synth pass generates light).
- * typography — font families + optional stylesheet URL.
+ * typography — font families + optional stylesheet URL + optional
+ * baseSize/lineHeight/letterSpacing overrides.
*
- * Everything else (layout, sizing, radius, line-height) lives in styles.css.
+ * Everything else (layout, sizing, radius, line-height) lives in styles.css —
+ * except the three typography knobs above, which themes may override.
* Add new themes in `presets.ts` — no other code changes needed.
*/
@@ -52,6 +54,12 @@ export interface DesktopThemeTypography {
fontMono: string
/** Google/Bunny/self-hosted font stylesheet URL. */
fontUrl?: string
+ /** Root base font size, painted as `--dt-base-size`. Mirrors the dashboard theme system. */
+ baseSize?: string
+ /** Root line height, painted as `--dt-line-height`. */
+ lineHeight?: string
+ /** Root letter spacing, painted as `--dt-letter-spacing`. */
+ letterSpacing?: string
}
/**