mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-08 22:21:45 +00:00
Remove the system color-scheme fallback from the web UI theme boot path. Fabro now uses a saved light/dark preference when present and otherwise starts in dark mode by default. Add a regression test for the shared theme selection helper and refresh the built web assets.
16 lines
576 B
TypeScript
16 lines
576 B
TypeScript
type Theme = "light" | "dark";
|
|
|
|
const STORAGE_KEY = "fabro-theme";
|
|
|
|
function resolveTheme(storedTheme: string | null): Theme {
|
|
return storedTheme === "light" || storedTheme === "dark"
|
|
? storedTheme
|
|
: "dark";
|
|
}
|
|
|
|
function buildThemeBootScript(storageKey = STORAGE_KEY) {
|
|
return `(function(){try{var t=localStorage.getItem("${storageKey}");if(t!=="light"&&t!=="dark")t="dark";document.documentElement.classList.add(t)}catch(e){document.documentElement.classList.add("dark")}})()`;
|
|
}
|
|
|
|
export { STORAGE_KEY, buildThemeBootScript, resolveTheme };
|
|
export type { Theme };
|