| 1 |
const maybeGetColorForVariable = ( color ) => { |
| 2 |
// This external condition handles the following color format: |
| 3 |
// `var(--paletteColor7)` |
| 4 |
if ( color && color.includes( 'var' ) ) { |
| 5 |
const style = window.getComputedStyle( document.body ); |
| 6 |
|
| 7 |
// Slice off `var(` and the slice off the `)` bracket at the end. |
| 8 |
color = color.slice( 4 ).slice( 0, -1 ); |
| 9 |
|
| 10 |
// This nested condition handles the following color format: |
| 11 |
// `var(--paletteColor7, #FBFBFB)` |
| 12 |
if ( color.includes( ',' ) ) { |
| 13 |
color = color.split( ',' ).pop().trim(); |
| 14 |
|
| 15 |
return color; |
| 16 |
} |
| 17 |
|
| 18 |
color = style.getPropertyValue( color ).trim(); |
| 19 |
} |
| 20 |
return color; |
| 21 |
}; |
| 22 |
|
| 23 |
export default maybeGetColorForVariable; |
| 24 |
|