(theme: Theme)
| 48 | ); |
| 49 | |
| 50 | function applyTheme(theme: Theme) { |
| 51 | const root = document.documentElement; |
| 52 | |
| 53 | // Disable transitions during the prompt switch to prevent "jank" |
| 54 | // where different elements transition at different speeds. |
| 55 | root.classList.add('theme-switching'); |
| 56 | |
| 57 | if (theme === 'dark') { |
| 58 | root.classList.add('dark'); |
| 59 | } else { |
| 60 | root.classList.remove('dark'); |
| 61 | } |
| 62 | |
| 63 | // Force reflow to flush changes while transitions are disabled |
| 64 | // eslint-disable-next-line @typescript-eslint/no-unused-expressions |
| 65 | root.offsetHeight; |
| 66 | |
| 67 | // Re-enable transitions |
| 68 | root.classList.remove('theme-switching'); |
| 69 | } |
| 70 | |
| 71 | // Initialize theme on module load (handles initial page load) |
| 72 | export function initializeTheme() { |
no test coverage detected