ui: theme tokens and a four-theme runtime

Every color now resolves through CSS custom properties on
html[data-theme=...], so a theme is a table of values rather than code.
Four themes ship: light, dark, night (red hues only, to preserve dark
adaptation off-grid) and amber (monochrome amber terminal).

Fonts are exposed as two roles, --font-body and --font-mono, which a theme
assigns a bundled face to; amber uses the mono face. Faces must be
self-hosted, never fetched from a CDN, so the app keeps working offline.

Night mode also filters media that cannot consume tokens - video, images,
PDFs, embedded pages, canvases - through an SVG color matrix that maps
luminance onto the red channel. Tag such an element with `.media`; a filter
on an app-level ancestor would create a containing block and break fixed
positioning.

ThemeProvider persists the choice and index.html stamps data-theme from
localStorage before the bundle loads, so the first paint already matches the
saved theme on a slow connection. The OS preference is followed only while
"system" is selected; night and amber are explicit choices. The nav toggle
becomes a five-item picker.

Semantic components still render themselves, so only the shell is
token-driven for now; the inverted props stay in place until each component
is migrated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-29 18:32:50 -06:00
parent 616424b223
commit 806727023d
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
12 changed files with 669 additions and 92 deletions

View file

@ -1,7 +1,8 @@
import { CSSProperties } from 'react';
// Theme values
export type ThemeName = 'dark' | 'light';
// Theme values. `night` and `amber` are explicit user choices only; neither is
// ever selected by `prefers-color-scheme`.
export type ThemeName = 'dark' | 'light' | 'night' | 'amber';
export type SavedThemeName = ThemeName | 'system' | null;
// Style objects used by theme
@ -27,6 +28,10 @@ export interface ThemeContextValue {
theme: ThemeName;
/** User's saved theme preference */
savedTheme: SavedThemeName;
/** True when the applied theme is built on a dark background */
isDark: boolean;
/** Apply and save a theme (or 'system' to follow the OS preference) */
setTheme: (value: SavedThemeName) => void;
/** Set dark theme */
setDarkTheme: (save?: boolean) => void;
/** Set light theme */