(theme: DesktopTheme, themeId: string, mode: "light" | "dark")
| 131 | } |
| 132 | |
| 133 | function applyThemeCss(theme: DesktopTheme, themeId: string, mode: "light" | "dark") { |
| 134 | const isDark = mode === "dark" |
| 135 | const variant = isDark ? theme.dark : theme.light |
| 136 | const tokens = resolveThemeVariant(variant, isDark) |
| 137 | const css = themeToCss(tokens) |
| 138 | const v2 = themeV2ToCss(resolveThemeVariantV2(variant, isDark)) |
| 139 | |
| 140 | if (themeId !== "oc-2") { |
| 141 | write(isDark ? STORAGE_KEYS.THEME_CSS_DARK : STORAGE_KEYS.THEME_CSS_LIGHT, `${css}\n ${v2}`) |
| 142 | } |
| 143 | |
| 144 | const fullCss = `:root { |
| 145 | color-scheme: ${mode}; |
| 146 | --text-mix-blend-mode: ${isDark ? "plus-lighter" : "multiply"}; |
| 147 | ${css} |
| 148 | ${v2} |
| 149 | }` |
| 150 | |
| 151 | document.getElementById("oc-theme-preload")?.remove() |
| 152 | ensureThemeStyleElement().textContent = fullCss |
| 153 | document.documentElement.dataset.theme = themeId |
| 154 | document.documentElement.dataset.colorScheme = mode |
| 155 | document.documentElement.style.backgroundColor = isDark ? "#080808" : "#fafafa" |
| 156 | |
| 157 | // Update theme-color meta tag to match light/dark mode |
| 158 | const meta = document.querySelector('meta[name="theme-color"]') |
| 159 | if (meta) meta.setAttribute("content", isDark ? "#080808" : "#fafafa") |
| 160 | } |
| 161 | |
| 162 | function cacheThemeVariants(theme: DesktopTheme, themeId: string) { |
| 163 | if (themeId === "oc-2") return |
no test coverage detected