UNPKG

3.65 kBJavaScriptView Raw
1import { GradientType, RotateDirection, StartValueType } from "../../Enums";
2import { AnimatableColor } from "./AnimatableColor";
3import { setRangeValue } from "../../Utils";
4export class AnimatableGradient {
5 constructor() {
6 this.angle = new GradientAngle();
7 this.colors = [];
8 this.type = GradientType.random;
9 }
10 load(data) {
11 if (!data) {
12 return;
13 }
14 this.angle.load(data.angle);
15 if (data.colors !== undefined) {
16 this.colors = data.colors.map((s) => {
17 const tmp = new AnimatableGradientColor();
18 tmp.load(s);
19 return tmp;
20 });
21 }
22 if (data.type !== undefined) {
23 this.type = data.type;
24 }
25 }
26}
27export class GradientAngle {
28 constructor() {
29 this.value = 0;
30 this.animation = new GradientAngleAnimation();
31 this.direction = RotateDirection.clockwise;
32 }
33 load(data) {
34 if (!data) {
35 return;
36 }
37 this.animation.load(data.animation);
38 if (data.value !== undefined) {
39 this.value = data.value;
40 }
41 if (data.direction !== undefined) {
42 this.direction = data.direction;
43 }
44 }
45}
46export class GradientColorOpacity {
47 constructor() {
48 this.value = 0;
49 this.animation = new GradientColorOpacityAnimation();
50 }
51 load(data) {
52 if (!data) {
53 return;
54 }
55 this.animation.load(data.animation);
56 if (data.value !== undefined) {
57 this.value = setRangeValue(data.value);
58 }
59 }
60}
61export class AnimatableGradientColor {
62 constructor() {
63 this.stop = 0;
64 this.value = new AnimatableColor();
65 }
66 load(data) {
67 if (!data) {
68 return;
69 }
70 if (data.stop !== undefined) {
71 this.stop = data.stop;
72 }
73 this.value = AnimatableColor.create(this.value, data.value);
74 if (data.opacity !== undefined) {
75 this.opacity = new GradientColorOpacity();
76 if (typeof data.opacity === "number") {
77 this.opacity.value = data.opacity;
78 }
79 else {
80 this.opacity.load(data.opacity);
81 }
82 }
83 }
84}
85export class GradientAngleAnimation {
86 constructor() {
87 this.count = 0;
88 this.enable = false;
89 this.speed = 0;
90 this.sync = false;
91 }
92 load(data) {
93 if (!data) {
94 return;
95 }
96 if (data.count !== undefined) {
97 this.count = data.count;
98 }
99 if (data.enable !== undefined) {
100 this.enable = data.enable;
101 }
102 if (data.speed !== undefined) {
103 this.speed = data.speed;
104 }
105 if (data.sync !== undefined) {
106 this.sync = data.sync;
107 }
108 }
109}
110export class GradientColorOpacityAnimation {
111 constructor() {
112 this.count = 0;
113 this.enable = false;
114 this.speed = 0;
115 this.sync = false;
116 this.startValue = StartValueType.random;
117 }
118 load(data) {
119 if (!data) {
120 return;
121 }
122 if (data.count !== undefined) {
123 this.count = data.count;
124 }
125 if (data.enable !== undefined) {
126 this.enable = data.enable;
127 }
128 if (data.speed !== undefined) {
129 this.speed = data.speed;
130 }
131 if (data.sync !== undefined) {
132 this.sync = data.sync;
133 }
134 if (data.startValue !== undefined) {
135 this.startValue = data.startValue;
136 }
137 }
138}