Simplify extractGradient

This commit is contained in:
Mikael Sand
2019-01-22 18:21:08 +02:00
parent a873f3a687
commit 6567b764ca
+6 -7
View File
@@ -37,22 +37,21 @@ export default function extractGradient(props) {
if (stopColor && !isNaN(offsetNumber)) {
const color = Color(stopColor).alpha(extractOpacity(stopOpacity));
const [r, g, b, a = 1] = color.rgb().array();
stops.push([offsetNumber, [r / 255, g / 255, b / 255, a]]);
stops.push([offsetNumber, r / 255, g / 255, b / 255, a]);
}
}
stops.sort(offsetComparator);
const gradient = [];
const colors = [];
const offsets = [];
for (const stop of stops) {
gradient.push(...stop[1]);
}
for (const stop of stops) {
gradient.push(stop[0]);
offsets.push(stop[0]);
colors.push(stop[1], stop[2], stop[3], stop[4]);
}
return {
gradient,
name: id,
gradient: colors.concat(offsets),
gradientUnits: units[gradientUnits] || 0,
gradientTransform: extractTransform(gradientTransform || transform || props),
};