Inject a custom theme's CSS and finalize its mode. Falls back to the clean * light export if the theme can't be loaded, so a broken or missing custom * theme never yields an unreadable PDF.
(prefs: ExportPrefs)
| 148 | * light export if the theme can't be loaded, so a broken or missing custom |
| 149 | * theme never yields an unreadable PDF. */ |
| 150 | async function applyCustomExportTheme(prefs: ExportPrefs): Promise<void> { |
| 151 | const html = document.documentElement |
| 152 | try { |
| 153 | const themes = await window.zen.listCustomThemes() |
| 154 | const slug = customThemeSlugFromId(prefs.themeId) |
| 155 | const theme = themes.find((t) => t.slug === slug) |
| 156 | if (!theme) { |
| 157 | applyLightExportTheme() |
| 158 | return |
| 159 | } |
| 160 | const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches |
| 161 | const wantDark = prefs.themeMode === 'auto' ? prefersDark : prefs.themeMode === 'dark' |
| 162 | const mode = resolveCustomThemeMode(theme, wantDark) |
| 163 | html.dataset.theme = prefs.themeId |
| 164 | html.dataset.themeMode = mode |
| 165 | html.style.colorScheme = mode |
| 166 | injectActiveTheme(prefs.themeId, themes) |
| 167 | } catch { |
| 168 | applyLightExportTheme() |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function applyExportPrefs(prefs: ExportPrefs): void { |
| 173 | const html = document.documentElement |
no test coverage detected