Replaces the dev-only backdrop-fade knob with a real control: when Background image is on (dark theme), a 0-100% 'Image fade' slider appears beneath it and drives --bg-fade live (higher = fainter). Persists to DB + localStorage via the existing theme prefs path (ThemePrefs.bgFade, applyTheme sets the CSS var). Removed --bg-fade from the GlassTuner so the two don't fight over the var.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { LS, readAccountMerged, writeAccount } from "./storage";
|
||
|
||
type Mode = "dark" | "light";
|
||
export type Scheme = "midnight" | "forest" | "slate" | "youtube" | "starship" | "matrix";
|
||
|
||
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" },
|
||
{ id: "starship", name: "Starship", swatch: "#38b6ff" },
|
||
{ id: "matrix", name: "Matrix", swatch: "#46b87c" },
|
||
];
|
||
|
||
export interface ThemePrefs {
|
||
mode: Mode;
|
||
scheme: Scheme;
|
||
fontScale: number;
|
||
/** Show the per-scheme background image (dark theme only); off = flat colour. */
|
||
bgImage: boolean;
|
||
/** How strongly the background image is faded out, 0–100% (higher = fainter). */
|
||
bgFade: number;
|
||
}
|
||
|
||
export const DEFAULT_THEME: ThemePrefs = {
|
||
mode: "dark",
|
||
scheme: "midnight",
|
||
fontScale: 1.06,
|
||
bgImage: true,
|
||
bgFade: 60,
|
||
};
|
||
|
||
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));
|
||
if (typeof t.bgFade === "number") el.style.setProperty("--bg-fade", `${t.bgFade}%`);
|
||
}
|
||
|
||
export function loadLocalTheme(): ThemePrefs {
|
||
return readAccountMerged(LS.theme, DEFAULT_THEME);
|
||
}
|
||
|
||
export function saveLocalTheme(t: ThemePrefs): void {
|
||
writeAccount(LS.theme, t);
|
||
}
|