* Parse CSS variables from a CSS string
(css: string)
| 7 | * Parse CSS variables from a CSS string |
| 8 | */ |
| 9 | function parseCSSVariables(css: string): Record<string, string> { |
| 10 | const variables: Record<string, string> = {}; |
| 11 | |
| 12 | // Match CSS variable declarations like --variable-name: value; |
| 13 | const variableRegex = /--([a-zA-Z0-9-]+):\s*([^;]+);/g; |
| 14 | |
| 15 | let match = variableRegex.exec(css); |
| 16 | while (match !== null) { |
| 17 | const [, name, value] = match; |
| 18 | variables[name] = value.trim(); |
| 19 | match = variableRegex.exec(css); |
| 20 | } |
| 21 | |
| 22 | return variables; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Normalize color value to hex using culori |