Alle Farben in app.css sind Variablen (--ink, --paper, ...); dunkel folgt dem System oder dem Schalter (theme.ts, localStorage). Hintergrund im Dunkeln: Asphalt-Textur unter leichtem Schleier. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
32 lines
843 B
TypeScript
32 lines
843 B
TypeScript
// Darstellung: "system" folgt prefers-color-scheme, "light"/"dark" legen sie
|
|
// über data-theme auf <html> fest (Farben in app.css, Abschnitt Farben).
|
|
// Gespeichert wird nur im Browser; ohne Storage gilt eben "system".
|
|
export type Theme = "system" | "light" | "dark";
|
|
|
|
const key = "kver.theme";
|
|
|
|
export function loadTheme(): Theme {
|
|
try {
|
|
const v = localStorage.getItem(key);
|
|
return v === "light" || v === "dark" ? v : "system";
|
|
} catch {
|
|
return "system";
|
|
}
|
|
}
|
|
|
|
export function applyTheme(t: Theme) {
|
|
const root = document.documentElement;
|
|
if (t === "system") delete root.dataset.theme;
|
|
else root.dataset.theme = t;
|
|
}
|
|
|
|
export function saveTheme(t: Theme) {
|
|
applyTheme(t);
|
|
try {
|
|
if (t === "system") localStorage.removeItem(key);
|
|
else localStorage.setItem(key, t);
|
|
} catch {
|
|
// egal, siehe oben
|
|
}
|
|
}
|