BlueSky & more on desktop
lazurite.stormlightlabs.org/
tauri
rust
typescript
bluesky
appview
atproto
solid
1import type { Theme } from "$/lib/types";
2
3export type EffectiveTheme = "light" | "dark";
4
5export function normalizeThemeSetting(value: string | null | undefined): Theme {
6 return value === "light" || value === "dark" || value === "auto" ? value : "auto";
7}
8
9export function resolveEffectiveTheme(setting: Theme, systemTheme: EffectiveTheme): EffectiveTheme {
10 if (setting === "light") {
11 return "light";
12 }
13
14 if (setting === "dark") {
15 return "dark";
16 }
17
18 return systemTheme;
19}
20
21export function toEffectiveTheme(value: string | null | undefined, fallback: EffectiveTheme): EffectiveTheme {
22 return value === "light" || value === "dark" ? value : fallback;
23}
24
25export function applyThemeToDocument(theme: EffectiveTheme, doc: Document = document) {
26 doc.documentElement.dataset.theme = theme;
27 doc.documentElement.style.colorScheme = theme;
28}