Fix: validateAlpha
This commit is contained in:
parent
52604f04e9
commit
d1dd9d9e3c
|
@ -72,8 +72,10 @@ const colorConverter = (() => {
|
||||||
|
|
||||||
// % converted before function call
|
// % converted before function call
|
||||||
function validateAlpha(alpha) {
|
function validateAlpha(alpha) {
|
||||||
const num = parseFloat(alpha);
|
if (alpha.endsWith('%')) {
|
||||||
return num >= 0 && num <= 1;
|
return validatePercentage(alpha);
|
||||||
|
}
|
||||||
|
return Number(alpha) >= 0 && Number(alpha) <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(str) {
|
function parse(str) {
|
||||||
|
@ -104,10 +106,10 @@ const colorConverter = (() => {
|
||||||
const comma = value.includes(',') && !value.includes('/');
|
const comma = value.includes(',') && !value.includes('/');
|
||||||
const num = value.split(comma ? /\s*,\s*/ : /\s+(?!\/)|\s*\/\s*/);
|
const num = value.split(comma ? /\s*,\s*/ : /\s+(?!\/)|\s*\/\s*/);
|
||||||
if (num.length < 3 || num.length > 4) return;
|
if (num.length < 3 || num.length > 4) return;
|
||||||
|
if (num[3] && !validateAlpha(num[3])) return null;
|
||||||
|
|
||||||
let a = !num[3] ? 1 : parseFloat(num[3]) / (num[3].endsWith('%') ? 100 : 1);
|
let a = !num[3] ? 1 : parseFloat(num[3]) / (num[3].endsWith('%') ? 100 : 1);
|
||||||
if (isNaN(a)) a = 1;
|
if (isNaN(a)) a = 1;
|
||||||
if (!validateAlpha(a)) return null;
|
|
||||||
|
|
||||||
const first = num[0];
|
const first = num[0];
|
||||||
if (/rgb/i.test(type)) {
|
if (/rgb/i.test(type)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user