Download web/src/lib/core/theme.ts from reversely/lifekit: direct link, hf CLI and curl.
- Browser
- Download file 944 Bytes
-
https://huggingface.co/spaces/reversely/lifekit/resolve/main/web/src/lib/core/theme.ts
- Command line
-
hf download hf://spaces/reversely/lifekit/web/src/lib/core/theme.ts
-
curl -L -o theme.ts https://huggingface.co/spaces/reversely/lifekit/resolve/main/web/src/lib/core/theme.ts
944 Bytes
| // Light or dark. The choice persists in this browser; without one the system setting | |
| // decides. The root element carries data-theme so the stylesheet redefines the tokens. | |
| import { writable } from 'svelte/store'; | |
| export type Theme = 'dark' | 'light'; | |
| const KEY = 'lifekit.theme'; | |
| function initial(): Theme { | |
| try { | |
| const saved = localStorage.getItem(KEY); | |
| if (saved === 'dark' || saved === 'light') return saved; | |
| } catch { | |
| /* storage unavailable */ | |
| } | |
| return typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; | |
| } | |
| export const theme = writable<Theme>(initial()); | |
| theme.subscribe((t) => { | |
| if (typeof document !== 'undefined') document.documentElement.setAttribute('data-theme', t); | |
| try { | |
| localStorage.setItem(KEY, t); | |
| } catch { | |
| /* storage unavailable */ | |
| } | |
| }); | |
| export const toggleTheme = () => theme.update((t) => (t === 'dark' ? 'light' : 'dark')); | |