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>
21 lines
668 B
TypeScript
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;
|
|
}
|