(input: string)
| 362 | } |
| 363 | |
| 364 | export function simplifyHexAlphaToRgba(input: string): string { |
| 365 | if (!input || !input.includes('#')) return input |
| 366 | |
| 367 | return input.replace(/#(?:[0-9a-fA-F]{4}|[0-9a-fA-F]{8})(?![0-9a-fA-F])/g, (match) => { |
| 368 | const parsed = parseHexColor(match) |
| 369 | if (!parsed || parsed.a >= 0.999) return match |
| 370 | const alpha = toDecimalPlace(Math.min(1, Math.max(0, parsed.a)), 2) |
| 371 | return `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, ${alpha})` |
| 372 | }) |
| 373 | } |
| 374 | |
| 375 | function parseHexColor(input: string): { r: number; g: number; b: number; a: number } | null { |
| 376 | let hex = input.trim().replace(/^#/, '') |
no test coverage detected