MCPcopy Create free account
hub / github.com/arctic-cli/interface / resolveColor

Function resolveColor

packages/arctic/src/cli/cmd/tui/context/theme.tsx:192–223  ·  view source on GitHub ↗
(c: ColorValue)

Source from the content-addressed store, hash-verified

190function resolveTheme(theme: ThemeJson, mode: "dark" | "light") {
191 const defs = theme.defs ?? {}
192 function resolveColor(c: ColorValue): RGBA {
193 if (c instanceof RGBA) return c
194 if (typeof c === "string") {
195 if (c === "transparent" || c === "none") return RGBA.fromInts(0, 0, 0, 0)
196
197 if (c.startsWith("#")) return RGBA.fromHex(c)
198
199 if (c.startsWith("rgba(")) {
200 const match = c.match(/rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/)
201 if (match) {
202 return RGBA.fromInts(
203 Number.parseInt(match[1]),
204 Number.parseInt(match[2]),
205 Number.parseInt(match[3]),
206 Math.round(Number.parseFloat(match[4]) * 255),
207 )
208 }
209 }
210
211 if (defs[c] != null) {
212 return resolveColor(defs[c])
213 } else if (theme.theme[c as keyof ThemeColors] !== undefined) {
214 return resolveColor(theme.theme[c as keyof ThemeColors]!)
215 } else {
216 throw new Error(`Color reference "${c}" not found in defs or theme`)
217 }
218 }
219 if (typeof c === "number") {
220 return ansiToRgba(c)
221 }
222 return resolveColor(c[mode])
223 }
224
225 const resolved = Object.fromEntries(
226 Object.entries(theme.theme)

Callers 1

resolveThemeFunction · 0.70

Calls 1

ansiToRgbaFunction · 0.85

Tested by

no test coverage detected