(c: ColorValue, chain: string[] = [])
| 241 | export 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) |
no test coverage detected