(theme: Theme)
| 30 | } |
| 31 | |
| 32 | export function applyTheme(theme: Theme) { |
| 33 | if (typeof window === 'undefined') return; |
| 34 | |
| 35 | const root = document.documentElement; |
| 36 | const systemTheme = getSystemTheme(); |
| 37 | |
| 38 | // 移除所有主题类 |
| 39 | root.classList.remove('light', 'dark'); |
| 40 | |
| 41 | // 应用主题 |
| 42 | if (theme === 'system') { |
| 43 | root.classList.add(systemTheme); |
| 44 | } else { |
| 45 | root.classList.add(theme); |
| 46 | } |
| 47 | |
| 48 | // 保存到 localStorage |
| 49 | localStorage.setItem('theme', theme); |
| 50 | } |
| 51 | |
| 52 | export function getStoredTheme(): Theme { |
| 53 | if (typeof window === 'undefined') return 'system'; |
no test coverage detected