Correct rgba() parsing to use float alpha channel

Fixes #3814
This commit is contained in:
Daniel Imms
2022-05-20 06:34:17 -07:00
parent 41fdb96b68
commit ddd43e0f09
2 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -127,7 +127,7 @@ export namespace css {
};
}
}
const rgbaMatch = css.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(\d{1,3})\s*)?\)/);
const rgbaMatch = css.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);
if (rgbaMatch) { // rgb() or rgba()
return {
css,
@@ -135,7 +135,7 @@ export namespace css {
parseInt(rgbaMatch[1]), // r
parseInt(rgbaMatch[2]), // g
parseInt(rgbaMatch[3]), // b
rgbaMatch[5] === undefined ? 0xFF : parseInt(rgbaMatch[5]) // a?
Math.round((rgbaMatch[5] === undefined ? 1 : parseFloat(rgbaMatch[5])) * 0xFF) // a?
)
};
}