MCPcopy Create free account
hub / github.com/anomalyco/opencode / applyThemeCss

Function applyThemeCss

packages/ui/src/theme/context.tsx:133–160  ·  view source on GitHub ↗
(theme: DesktopTheme, themeId: string, mode: "light" | "dark")

Source from the content-addressed store, hash-verified

131}
132
133function 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
162function cacheThemeVariants(theme: DesktopTheme, themeId: string) {
163 if (themeId === "oc-2") return

Callers 1

applyThemeFunction · 0.85

Calls 7

resolveThemeVariantFunction · 0.90
themeToCssFunction · 0.90
themeV2ToCssFunction · 0.90
resolveThemeVariantV2Function · 0.90
ensureThemeStyleElementFunction · 0.85
writeFunction · 0.70
removeMethod · 0.65

Tested by

no test coverage detected