- errorDialog + hints now use createStore (drop their bespoke listener arrays). - theme/sidebarLayout/notifications/App filters/Playlists plSort use readMerged/ readJSON/writeJSON instead of inline try/JSON.parse/catch. - Stats, SettingsPanel and App's channel filter/view tabs use usePersistedState (the 3 sites that reinvented usePersistedTab inline). - Every siftlode.* key now sourced from the LS registry (no scattered literals).
38 lines
1 KiB
TypeScript
38 lines
1 KiB
TypeScript
import { LS, readMerged, writeJSON } from "./storage";
|
|
|
|
export type Mode = "dark" | "light";
|
|
export type Scheme = "midnight" | "forest" | "slate" | "youtube";
|
|
|
|
export const SCHEMES: { id: Scheme; name: string; swatch: string }[] = [
|
|
{ id: "midnight", name: "Midnight", swatch: "#6d8cff" },
|
|
{ id: "forest", name: "Forest", swatch: "#2dd4bf" },
|
|
{ id: "slate", name: "Slate", swatch: "#e8913c" },
|
|
{ id: "youtube", name: "YouTube", swatch: "#ff3b46" },
|
|
];
|
|
|
|
export interface ThemePrefs {
|
|
mode: Mode;
|
|
scheme: Scheme;
|
|
fontScale: number;
|
|
}
|
|
|
|
export const DEFAULT_THEME: ThemePrefs = {
|
|
mode: "dark",
|
|
scheme: "midnight",
|
|
fontScale: 1.06,
|
|
};
|
|
|
|
export function applyTheme(t: ThemePrefs): void {
|
|
const el = document.documentElement;
|
|
el.dataset.theme = t.mode;
|
|
el.dataset.scheme = t.scheme;
|
|
el.style.setProperty("--font-scale", String(t.fontScale));
|
|
}
|
|
|
|
export function loadLocalTheme(): ThemePrefs {
|
|
return readMerged(LS.theme, DEFAULT_THEME);
|
|
}
|
|
|
|
export function saveLocalTheme(t: ThemePrefs): void {
|
|
writeJSON(LS.theme, t);
|
|
}
|