MCPcopy Create free account
hub / github.com/codeaashu/claude-code / inkColorToCSS

Function inkColorToCSS

web/lib/ink-compat/color-mapping.ts:68–93  ·  view source on GitHub ↗
(color: string | undefined)

Source from the content-addressed store, hash-verified

66 * Returns `undefined` if `color` is undefined/empty.
67 */
68export function inkColorToCSS(color: string | undefined): string | undefined {
69 if (!color) return undefined
70
71 // Pass through hex colors
72 if (color.startsWith('#')) return color
73
74 // Normalise `rgb(r,g,b)` → `rgb(r, g, b)` (browsers accept both, but clean)
75 if (color.startsWith('rgb(')) {
76 return color.replace(/\s+/g, '')
77 }
78
79 // ansi256(N)
80 const ansi256Match = color.match(/^ansi256\((\d+)\)$/)
81 if (ansi256Match) {
82 return ansi256ToHex(parseInt(ansi256Match[1]!, 10))
83 }
84
85 // ansi:name
86 if (color.startsWith('ansi:')) {
87 const name = color.slice(5)
88 return ANSI_COLORS[name] ?? color
89 }
90
91 // Unknown format — return as-is (browser may understand it)
92 return color
93}

Callers 2

resolveColorFunction · 0.90
inkTextPropsToCSSFunction · 0.90

Calls 1

ansi256ToHexFunction · 0.85

Tested by

no test coverage detected