()
| 3 | type ThemeMode = 'light' | 'dark' | 'auto' |
| 4 | |
| 5 | function getInitialMode(): ThemeMode { |
| 6 | if (typeof window === 'undefined') { |
| 7 | return 'auto' |
| 8 | } |
| 9 | |
| 10 | const stored = window.localStorage.getItem('theme') |
| 11 | if (stored === 'light' || stored === 'dark' || stored === 'auto') { |
| 12 | return stored |
| 13 | } |
| 14 | |
| 15 | return 'auto' |
| 16 | } |
| 17 | |
| 18 | function applyThemeMode(mode: ThemeMode) { |
| 19 | const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches |