Fix invalid named color detection
If the named color is invalid, the value is not stored into the property.
This commit is contained in:
+8
-4
@@ -45,10 +45,14 @@ export function asString(color) {
|
|||||||
function fromNamed(color) {
|
function fromNamed(color) {
|
||||||
const el = document.createElement('div');
|
const el = document.createElement('div');
|
||||||
el.style.color = color;
|
el.style.color = color;
|
||||||
document.body.appendChild(el);
|
if (el.style.color !== '') {
|
||||||
const rgb = getComputedStyle(el).color;
|
document.body.appendChild(el);
|
||||||
document.body.removeChild(el);
|
const rgb = getComputedStyle(el).color;
|
||||||
return rgb;
|
document.body.removeChild(el);
|
||||||
|
return rgb;
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user