(varName: string)
| 8 | * @returns The computed color value string |
| 9 | */ |
| 10 | export function getCSSColor(varName: string): string { |
| 11 | const currentTheme = document.documentElement.dataset.theme || 'dark'; |
| 12 | if (currentTheme !== cacheTheme) { |
| 13 | colorCache.clear(); |
| 14 | cacheTheme = currentTheme; |
| 15 | } |
| 16 | const cached = colorCache.get(varName); |
| 17 | if (cached) return cached; |
| 18 | const value = getComputedStyle(document.documentElement) |
| 19 | .getPropertyValue(varName).trim(); |
| 20 | colorCache.set(varName, value); |
| 21 | return value; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Invalidate the color cache. Call when theme changes to ensure |
no test coverage detected