sdlc-hub/web/src/shell/theme.ts
2026-10-22 00:23:39 +04:00

28 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// тема интерфейса: "" — системная, light, dark; ключ graph-theme, как у прежней доски (links.html, строки 1000–1003)
export const THEMES = ["", "light", "dark"] as const;
export type Theme = (typeof THEMES)[number];
const KEY = "graph-theme";
export function readTheme(): Theme {
let v: string | null = null;
try { v = localStorage.getItem(KEY); } catch { /* закрытое хранилище */ }
return (THEMES as readonly string[]).includes(v ?? "") ? ((v ?? "") as Theme) : "";
}
export function saveTheme(t: Theme): void {
try { localStorage.setItem(KEY, t); } catch { /* закрытое хранилище */ }
}
export function applyTheme(t: Theme): void {
if (t) document.documentElement.setAttribute("data-theme", t);
else document.documentElement.removeAttribute("data-theme");
}
export function systemDark(): boolean {
return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
}
export function effectiveDark(t: Theme): boolean {
return t === "dark" || (t === "" && systemDark());
}