($color: string)
| 20 | const rgbaParseCache = new Map<string, RGBA>(); |
| 21 | |
| 22 | export function parseColorWithCache($color: string): RGBA | null { |
| 23 | $color = $color.trim(); |
| 24 | if (rgbaParseCache.has($color)) { |
| 25 | return rgbaParseCache.get($color)!; |
| 26 | } |
| 27 | // We cannot _really_ parse any color which has the calc() expression, |
| 28 | // so we try our best to remove those and then parse the value. |
| 29 | if ($color.includes('calc(')) { |
| 30 | $color = lowerCalcExpression($color); |
| 31 | } |
| 32 | const color = parse($color); |
| 33 | if (color) { |
| 34 | rgbaParseCache.set($color, color); |
| 35 | return color; |
| 36 | } |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | export function parseToHSLWithCache(color: string): HSLA | null { |
| 41 | if (hslaParseCache.has(color)) { |
no test coverage detected