Files
tern-web/src/lib/theme.ts
T
Mateusz PstruchaandClaude Opus 5 1145e31af6 Initial webapp scaffold
Vite + Svelte 5 + TypeScript with no other runtime dependencies, per the
client spec's speed-and-simplicity priority. Wires up the decided palette
with light/dark/system switching, a two-pane desktop shell, and a thin
API client against the sync server.

Deliberately no PWA/service worker, matching the spec's scope cut.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 19:01:07 +02:00

21 lines
668 B
TypeScript

export type ThemePreference = 'light' | 'dark' | 'system';
const STORAGE_KEY = 'tern-theme';
export function loadThemePreference(): ThemePreference {
const stored = localStorage.getItem(STORAGE_KEY);
return stored === 'light' || stored === 'dark' || stored === 'system' ? stored : 'system';
}
export function saveThemePreference(pref: ThemePreference): void {
localStorage.setItem(STORAGE_KEY, pref);
}
export function applyTheme(pref: ThemePreference): void {
const resolved =
pref === 'system'
? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
: pref;
document.documentElement.dataset.theme = resolved;
}