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

Function resolveColor

packages/tui/src/theme/index.ts:243–264  ·  view source on GitHub ↗
(c: ColorValue, chain: string[] = [])

Source from the content-addressed store, hash-verified

241export function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {
242 const defs = theme.defs ?? {}
243 function resolveColor(c: ColorValue, chain: string[] = []): RGBA {
244 if (c instanceof RGBA) return c
245 if (typeof c === "string") {
246 if (c === "transparent" || c === "none") return RGBA.fromInts(0, 0, 0, 0)
247
248 if (c.startsWith("#")) return RGBA.fromHex(c)
249
250 if (chain.includes(c)) {
251 throw new Error(`Circular color reference: ${[...chain, c].join(" -> ")}`)
252 }
253
254 const next = defs[c] ?? theme.theme[c as ThemeColor]
255 if (next === undefined) {
256 throw new Error(`Color reference "${c}" not found in defs or theme`)
257 }
258 return resolveColor(next, [...chain, c])
259 }
260 if (typeof c === "number") {
261 return ansiToRgba(c)
262 }
263 return resolveColor(c[mode], chain)
264 }
265
266 const resolved = Object.fromEntries(
267 Object.entries(theme.theme)

Callers 1

resolveThemeFunction · 0.70

Calls 1

ansiToRgbaFunction · 0.70

Tested by

no test coverage detected