UNPKG

1.46 kBJavaScriptView Raw
1import { Color } from '../../color';
2export class LinearGradient {
3 static parse(value) {
4 const result = new LinearGradient();
5 result.angle = value.angle;
6 result.colorStops = value.colors.map((color) => {
7 const offset = color.offset || null;
8 let offsetUnit;
9 if (offset && offset.unit === '%') {
10 offsetUnit = {
11 unit: '%',
12 value: offset.value,
13 };
14 }
15 return {
16 color: color.color,
17 offset: offsetUnit,
18 };
19 });
20 return result;
21 }
22 static equals(first, second) {
23 if (!first && !second) {
24 return true;
25 }
26 else if (!first || !second) {
27 return false;
28 }
29 if (first.angle !== second.angle) {
30 return false;
31 }
32 if (first.colorStops.length !== second.colorStops.length) {
33 return false;
34 }
35 for (let i = 0; i < first.colorStops.length; i++) {
36 const firstStop = first.colorStops[i];
37 const secondStop = second.colorStops[i];
38 if (firstStop.offset !== secondStop.offset) {
39 return false;
40 }
41 if (!Color.equals(firstStop.color, secondStop.color)) {
42 return false;
43 }
44 }
45 return true;
46 }
47}
48//# sourceMappingURL=linear-gradient.js.map
\No newline at end of file