Handle color parsing when alpha = 1 (#512)

The `color` library doesn't include alpha when accessing `color.rgb().array()` when the alpha value is 1. Since we always use the alpha value, make it default to 1 when parsing a color.
This commit is contained in:
James Ide
2017-11-23 13:47:01 -08:00
committed by Dustin Savery
parent ffea98f863
commit f9e774e03d
2 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -13,8 +13,8 @@ export default function (colorOrBrush) {
return [1, matched[1]];
//todo:
} else { // solid color
let c = Color(colorOrBrush).rgb().array();
return [0, c[0] / 255, c[1] / 255, c[2] / 255, c[3]];
let [r, g, b, a = 1] = Color(colorOrBrush).rgb().array();
return [0, r / 255, g / 255, b / 255, a];
}
} catch (err) {
console.warn(`"${colorOrBrush}" is not a valid color or brush`);
+5 -5
View File
@@ -36,11 +36,11 @@ export default function(props) {
const gradient = [];
sorted.forEach(({stop}) => {
let channels = stop.rgbaArray();
gradient.push(channels[0] / 255);
gradient.push(channels[1] / 255);
gradient.push(channels[2] / 255);
gradient.push(channels[3]);
let [r, g, b, a = 1] = stop.rgb().array();
gradient.push(r / 255);
gradient.push(g / 255);
gradient.push(b / 255);
gradient.push(a);
});
gradient.push(...sorted.map(({offset}) => +offset));