Allow for custom properties in rgb, rgba, hsl and hsla colors (#7933)
* allow for custom properties in `rgb`, `rgba`, `hsl` and `hsla` colors * update changelog * add more `parseColor` test cases
This commit is contained in:
parent
f3a629a619
commit
315e3a2445
4 changed files with 122 additions and 36 deletions
|
|
@ -2,14 +2,16 @@ import namedColors from 'color-name'
|
|||
|
||||
let HEX = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i
|
||||
let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
|
||||
let VALUE = `(?:\\d+|\\d*\\.\\d+)%?`
|
||||
let SEP = `(?:\\s*,\\s*|\\s+)`
|
||||
let ALPHA_SEP = `\\s*[,/]\\s*`
|
||||
let VALUE = /(?:\d+|\d*\.\d+)%?/
|
||||
let SEP = /(?:\s*,\s*|\s+)/
|
||||
let ALPHA_SEP = /\s*[,/]\s*/
|
||||
let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/
|
||||
|
||||
let RGB = new RegExp(
|
||||
`^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
|
||||
`^rgba?\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`
|
||||
)
|
||||
let HSL = new RegExp(
|
||||
`^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
|
||||
`^hsla?\\(\\s*((?:${VALUE.source})(?:deg|rad|grad|turn)?|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`
|
||||
)
|
||||
|
||||
export function parseColor(value) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue