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

@ -75,10 +75,10 @@ export function parseHexColor(text: string, start = 0): Parsed<Color> {
return null; return null;
} }
const end = hexColorRegEx.lastIndex; const end = hexColorRegEx.lastIndex;
return { start, end, value: new Color('#'+ result[1]) }; 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> { export function parseCssColor(text: string, start = 0): Parsed<Color> {
cssColorRegEx.lastIndex = start; cssColorRegEx.lastIndex = start;
const result = cssColorRegEx.exec(text); const result = cssColorRegEx.exec(text);
@ -87,11 +87,10 @@ export function parseCssColor(text: string, start = 0): Parsed<Color> {
} }
const end = cssColorRegEx.lastIndex; const end = cssColorRegEx.lastIndex;
try { try {
return { start, end, value: new Color(text) }; return { start, end, value: new Color(result[1]) };
} catch { } catch {
return null; return null;
} }
} }
export function convertHSLToRGBColor(hue: number, saturation: number, lightness: number): { r: number; g: number; b: number } { 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> { export function parseColorKeyword(value, start: number, keyword = parseKeyword(value, start)): Parsed<Color> {
const parseColor = keyword && getKnownColor(keyword.value); const parseColor = keyword && getKnownColor(keyword.value);
if (parseColor != null) { if (parseColor != null) {