fix color detection

master
Brad Cornes 2021-10-08 18:24:57 +01:00
parent febded6864
commit ba21a2f1d8
1 changed files with 4 additions and 12 deletions

View File

@ -51,18 +51,10 @@ const colorRegex = new RegExp(
function getColorsInString(str: string): (culori.Color | KeywordColor)[] { function getColorsInString(str: string): (culori.Color | KeywordColor)[] {
if (/(?:box|drop)-shadow/.test(str)) return [] if (/(?:box|drop)-shadow/.test(str)) return []
return ( return Array.from(str.matchAll(colorRegex), (match) => {
str let color = match[1].replace(/var\([^)]+\)/, '1')
.match(colorRegex) return getKeywordColor(color) ?? culori.parse(color)
?.map((color) => }).filter(Boolean)
color
.trim()
.replace(/^[,(]|[,)]$/g, '')
.replace(/var\([^)]+\)/, '1')
)
.map((color) => getKeywordColor(color) ?? culori.parse(color))
.filter(Boolean) ?? []
)
} }
function getColorFromDecls( function getColorFromDecls(