fix(color): fix rgba convert NaN when input percentage

This commit is contained in:
Kai 2021-12-14 21:20:46 +08:00
parent 80802f59f1
commit 4845904ab3

View File

@ -664,7 +664,12 @@ export const Util = {
_rgbaColorToRGBA(str: string): RGBA { _rgbaColorToRGBA(str: string): RGBA {
if (str.indexOf('rgba(') === 0) { if (str.indexOf('rgba(') === 0) {
str = str.match(/rgba\(([^)]+)\)/)[1]; str = str.match(/rgba\(([^)]+)\)/)[1];
var parts = str.split(/ *, */).map(Number); var parts = str.split(/ *, */).map((n, index) => {
if (n.slice(-1) === '%') {
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
}
return Number(n);
});
return { return {
r: parts[0], r: parts[0],
g: parts[1], g: parts[1],