fix: css colors not parsed correctly within background property

This commit is contained in:
Martin Guillon
2021-08-18 18:56:58 +02:00
parent 66203d24ee
commit 453ea18dc6

View File

@ -78,7 +78,7 @@ export function parseHexColor(text: string, start = 0): Parsed<Color> {
return { start, end, value: new Color('#' + result[1]) };
}
const cssColorRegEx = /\s*((?:rgb|rgba|hsl|hsla|hsv|hsva)\([^\(\)]\))/gy;
const cssColorRegEx = /\s*((?:rgb|rgba|hsl|hsla|hsv|hsva)\([^\(\)]*\))/gy;
export function parseCssColor(text: string, start = 0): Parsed<Color> {
cssColorRegEx.lastIndex = start;
const result = cssColorRegEx.exec(text);
@ -87,11 +87,10 @@ export function parseCssColor(text: string, start = 0): Parsed<Color> {
}
const end = cssColorRegEx.lastIndex;
try {
return { start, end, value: new Color(text) };
return { start, end, value: new Color(result[1]) };
} catch {
return null;
}
}
export function convertHSLToRGBColor(hue: number, saturation: number, lightness: number): { r: number; g: number; b: number } {
@ -132,7 +131,6 @@ export function convertHSLToRGBColor(hue: number, saturation: number, lightness:
};
}
export function parseColorKeyword(value, start: number, keyword = parseKeyword(value, start)): Parsed<Color> {
const parseColor = keyword && getKnownColor(keyword.value);
if (parseColor != null) {