wip: making themes more dynamic and easy to add

This commit is contained in:
rasmusq
2025-11-30 01:30:43 +01:00
parent d165e5992a
commit 152bd7cdb1
12 changed files with 76 additions and 98 deletions

View File

@@ -1,6 +1,7 @@
import { browser } from '$app/environment';
type Theme = 'light' | 'dark' | 'system';
type ResolvedTheme = 'light' | 'dark';
class ThemeStore {
current = $state<Theme>('system');
@@ -35,6 +36,12 @@ class ThemeStore {
}
}
getResolvedTheme(): ResolvedTheme {
const isDark = this.current === 'dark' ||
(this.current === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
return isDark ? 'dark' : 'light';
}
toggle() {
// Cycle through: light -> dark -> system -> light
if (this.current === 'light') {