()
| 13 | export const themeStore = atom<Theme>(initStore()); |
| 14 | |
| 15 | function initStore() { |
| 16 | if (!import.meta.env.SSR) { |
| 17 | const persistedTheme = localStorage.getItem(kTheme) as Theme | undefined; |
| 18 | const themeAttribute = document.querySelector('html')?.getAttribute('data-theme'); |
| 19 | |
| 20 | return persistedTheme ?? (themeAttribute as Theme) ?? DEFAULT_THEME; |
| 21 | } |
| 22 | |
| 23 | return DEFAULT_THEME; |
| 24 | } |
| 25 | |
| 26 | export function toggleTheme() { |
| 27 | const currentTheme = themeStore.get(); |