Darstellung: Dark Mode mit Schalter in den Einstellungen
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
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
20c17cbf81
commit
74f3ed6e31
@@ -0,0 +1,31 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user