// тема интерфейса: "" — системная, 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()); }