@tsparticles/updater-gradient 3.0.0-alpha.1 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -12
- package/browser/GradientUpdater.js +35 -133
- package/browser/Options/Classes/AnimatableGradient.js +2 -2
- package/browser/Options/Classes/AnimatableGradientColor.js +3 -3
- package/browser/Options/Classes/GradientAngle.js +3 -2
- package/browser/Options/Classes/GradientAngleAnimation.js +5 -1
- package/browser/Options/Classes/GradientColorOpacity.js +2 -2
- package/browser/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/browser/Types.js +1 -0
- package/browser/Utils.js +107 -0
- package/browser/index.js +3 -3
- package/browser/package.json +1 -0
- package/cjs/GradientUpdater.js +37 -135
- package/cjs/Options/Classes/AnimatableGradient.js +4 -4
- package/cjs/Options/Classes/AnimatableGradientColor.js +3 -3
- package/cjs/Options/Classes/GradientAngle.js +4 -3
- package/cjs/Options/Classes/GradientAngleAnimation.js +4 -0
- package/cjs/Options/Classes/GradientColorOpacity.js +2 -2
- package/cjs/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +111 -0
- package/cjs/index.js +3 -3
- package/cjs/package.json +1 -0
- package/esm/GradientUpdater.js +35 -133
- package/esm/Options/Classes/AnimatableGradient.js +2 -2
- package/esm/Options/Classes/AnimatableGradientColor.js +3 -3
- package/esm/Options/Classes/GradientAngle.js +3 -2
- package/esm/Options/Classes/GradientAngleAnimation.js +5 -1
- package/esm/Options/Classes/GradientColorOpacity.js +2 -2
- package/esm/Options/Classes/GradientColorOpacityAnimation.js +8 -1
- package/esm/Types.js +1 -0
- package/esm/Utils.js +107 -0
- package/esm/index.js +3 -3
- package/esm/package.json +1 -0
- package/package.json +23 -6
- package/report.html +4 -4
- package/tsparticles.updater.gradient.js +87 -56
- package/tsparticles.updater.gradient.min.js +1 -1
- package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -8
- package/types/GradientUpdater.d.ts +2 -25
- package/types/Options/Classes/AnimatableGradient.d.ts +4 -5
- package/types/Options/Classes/AnimatableGradientColor.d.ts +3 -4
- package/types/Options/Classes/GradientAngle.d.ts +4 -5
- package/types/Options/Classes/GradientAngleAnimation.d.ts +2 -1
- package/types/Options/Classes/GradientColorOpacity.d.ts +4 -4
- package/types/Options/Classes/GradientColorOpacityAnimation.d.ts +3 -3
- package/types/Options/Interfaces/Gradients.d.ts +1 -1
- package/types/Options/Interfaces/IAnimatableGradient.d.ts +2 -2
- package/types/Options/Interfaces/IOptionsGradient.d.ts +1 -1
- package/types/Types.d.ts +23 -0
- package/types/Utils.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/umd/GradientUpdater.js +38 -136
- package/umd/Options/Classes/AnimatableGradient.js +5 -5
- package/umd/Options/Classes/AnimatableGradientColor.js +4 -4
- package/umd/Options/Classes/GradientAngle.js +5 -4
- package/umd/Options/Classes/GradientAngleAnimation.js +4 -0
- package/umd/Options/Classes/GradientColorOpacity.js +3 -3
- package/umd/Options/Classes/GradientColorOpacityAnimation.js +7 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +121 -0
- package/umd/index.js +4 -4
package/cjs/GradientUpdater.js
CHANGED
|
@@ -2,113 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GradientUpdater = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
var _a, _b, _c;
|
|
8
|
-
if (!value.enable) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const decay = (_a = value.decay) !== null && _a !== void 0 ? _a : 1;
|
|
12
|
-
switch (value.status) {
|
|
13
|
-
case "increasing":
|
|
14
|
-
if (value.value >= value.max) {
|
|
15
|
-
value.status = "decreasing";
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
value.value += ((_b = value.velocity) !== null && _b !== void 0 ? _b : 0) * delta.factor;
|
|
19
|
-
}
|
|
20
|
-
break;
|
|
21
|
-
case "decreasing":
|
|
22
|
-
if (value.value <= value.min) {
|
|
23
|
-
value.status = "increasing";
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
value.value -= ((_c = value.velocity) !== null && _c !== void 0 ? _c : 0) * delta.factor;
|
|
27
|
-
}
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
if (value.velocity && decay !== 1) {
|
|
31
|
-
value.velocity *= decay;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function updateColorValue(delta, value, max, decrease) {
|
|
35
|
-
var _a, _b;
|
|
36
|
-
const colorValue = value;
|
|
37
|
-
if (!colorValue || !colorValue.enable) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
41
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
42
|
-
colorValue.value += velocity;
|
|
43
|
-
if (decrease && colorValue.value > max) {
|
|
44
|
-
colorValue.status = "decreasing";
|
|
45
|
-
colorValue.value -= colorValue.value % max;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
colorValue.value -= velocity;
|
|
50
|
-
if (colorValue.value < 0) {
|
|
51
|
-
colorValue.status = "increasing";
|
|
52
|
-
colorValue.value += colorValue.value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (colorValue.value > max) {
|
|
56
|
-
colorValue.value %= max;
|
|
57
|
-
}
|
|
58
|
-
if (value.velocity && decay !== 1) {
|
|
59
|
-
value.velocity *= decay;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function updateAngle(delta, angle) {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
const speed = ((_a = angle.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = angle.decay) !== null && _b !== void 0 ? _b : 1;
|
|
65
|
-
if (!angle.enable) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
switch (angle.status) {
|
|
69
|
-
case "increasing":
|
|
70
|
-
angle.value += speed;
|
|
71
|
-
if (angle.value > max) {
|
|
72
|
-
angle.value -= max;
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case "decreasing":
|
|
76
|
-
default:
|
|
77
|
-
angle.value -= speed;
|
|
78
|
-
if (angle.value < 0) {
|
|
79
|
-
angle.value += max;
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
if (angle.velocity && decay !== 1) {
|
|
84
|
-
angle.velocity *= decay;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function updateGradient(particle, delta) {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
const gradient = particle.gradient;
|
|
90
|
-
if (!gradient) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
updateAngle(delta, gradient.angle);
|
|
94
|
-
for (const color of gradient.colors) {
|
|
95
|
-
if (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h) !== undefined) {
|
|
96
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
97
|
-
}
|
|
98
|
-
if (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s) !== undefined) {
|
|
99
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
100
|
-
}
|
|
101
|
-
if (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l) !== undefined) {
|
|
102
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
103
|
-
}
|
|
104
|
-
if (color.opacity) {
|
|
105
|
-
updateColorOpacity(delta, color.opacity);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
5
|
+
const AnimatableGradient_js_1 = require("./Options/Classes/AnimatableGradient.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
109
7
|
class GradientUpdater {
|
|
110
8
|
getColorStyles(particle, context, radius, opacity) {
|
|
111
|
-
var _a, _b;
|
|
112
9
|
const gradient = particle.gradient;
|
|
113
10
|
if (!gradient) {
|
|
114
11
|
return {};
|
|
@@ -116,12 +13,12 @@ class GradientUpdater {
|
|
|
116
13
|
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
117
14
|
? context.createRadialGradient(0, 0, 0, 0, 0, radius)
|
|
118
15
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
119
|
-
for (const
|
|
120
|
-
fillGradient.addColorStop(
|
|
121
|
-
h:
|
|
122
|
-
s:
|
|
123
|
-
l:
|
|
124
|
-
},
|
|
16
|
+
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
17
|
+
fillGradient.addColorStop(stop, (0, engine_1.getStyleFromHsl)({
|
|
18
|
+
h: value.h.value,
|
|
19
|
+
s: value.s.value,
|
|
20
|
+
l: value.l.value,
|
|
21
|
+
}, cOpacity?.value ?? opacity));
|
|
125
22
|
}
|
|
126
23
|
return { fill: fillGradient };
|
|
127
24
|
}
|
|
@@ -130,20 +27,22 @@ class GradientUpdater {
|
|
|
130
27
|
if (!gradient) {
|
|
131
28
|
return;
|
|
132
29
|
}
|
|
30
|
+
const { angle } = gradient;
|
|
133
31
|
particle.gradient = {
|
|
134
32
|
angle: {
|
|
135
|
-
value:
|
|
136
|
-
enable:
|
|
137
|
-
velocity: ((0, engine_1.getRangeValue)(
|
|
138
|
-
decay: 1 - (0, engine_1.getRangeValue)(
|
|
33
|
+
value: (0, engine_1.getRangeValue)(angle.value),
|
|
34
|
+
enable: angle.animation.enable,
|
|
35
|
+
velocity: ((0, engine_1.getRangeValue)(angle.animation.speed) / 360) * particle.container.retina.reduceFactor,
|
|
36
|
+
decay: 1 - (0, engine_1.getRangeValue)(angle.animation.decay),
|
|
37
|
+
delayTime: (0, engine_1.getRangeValue)(angle.animation.delay) * 1000,
|
|
38
|
+
time: 0,
|
|
139
39
|
},
|
|
140
40
|
type: gradient.type,
|
|
141
41
|
colors: [],
|
|
142
42
|
};
|
|
143
43
|
let rotateDirection = gradient.angle.direction;
|
|
144
44
|
if (rotateDirection === "random") {
|
|
145
|
-
|
|
146
|
-
rotateDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
45
|
+
rotateDirection = (0, engine_1.getRandom)() > 0.5 ? "counter-clockwise" : "clockwise";
|
|
147
46
|
}
|
|
148
47
|
switch (rotateDirection) {
|
|
149
48
|
case "counter-clockwise":
|
|
@@ -173,28 +72,31 @@ class GradientUpdater {
|
|
|
173
72
|
velocity: ((0, engine_1.getRangeValue)(grColor.opacity.animation.speed) / 100) *
|
|
174
73
|
particle.container.retina.reduceFactor,
|
|
175
74
|
decay: 1 - (0, engine_1.getRangeValue)(grColor.opacity.animation.decay),
|
|
75
|
+
delayTime: (0, engine_1.getRangeValue)(grColor.opacity.animation.delay) * 1000,
|
|
76
|
+
time: 0,
|
|
176
77
|
}
|
|
177
78
|
: undefined,
|
|
178
79
|
};
|
|
179
|
-
|
|
80
|
+
const { opacity: addOpacity } = addColor;
|
|
81
|
+
if (grColor.opacity && addOpacity) {
|
|
180
82
|
const opacityRange = grColor.opacity.value;
|
|
181
|
-
|
|
182
|
-
|
|
83
|
+
addOpacity.min = (0, engine_1.getRangeMin)(opacityRange);
|
|
84
|
+
addOpacity.max = (0, engine_1.getRangeMax)(opacityRange);
|
|
183
85
|
const opacityAnimation = grColor.opacity.animation;
|
|
184
86
|
switch (opacityAnimation.startValue) {
|
|
185
87
|
case "min":
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
break;
|
|
189
|
-
case "random":
|
|
190
|
-
addColor.opacity.value = (0, engine_1.randomInRange)(addColor.opacity);
|
|
191
|
-
addColor.opacity.status =
|
|
192
|
-
(0, engine_1.getRandom)() >= 0.5 ? "increasing" : "decreasing";
|
|
88
|
+
addOpacity.value = addOpacity.min;
|
|
89
|
+
addOpacity.status = "increasing";
|
|
193
90
|
break;
|
|
194
91
|
case "max":
|
|
92
|
+
addOpacity.value = addOpacity.max;
|
|
93
|
+
addOpacity.status = "decreasing";
|
|
94
|
+
break;
|
|
95
|
+
case "random":
|
|
195
96
|
default:
|
|
196
|
-
|
|
197
|
-
|
|
97
|
+
addOpacity.value = (0, engine_1.randomInRange)(addOpacity);
|
|
98
|
+
addOpacity.status =
|
|
99
|
+
(0, engine_1.getRandom)() >= 0.5 ? "increasing" : "decreasing";
|
|
198
100
|
break;
|
|
199
101
|
}
|
|
200
102
|
}
|
|
@@ -202,15 +104,15 @@ class GradientUpdater {
|
|
|
202
104
|
}
|
|
203
105
|
}
|
|
204
106
|
isEnabled(particle) {
|
|
205
|
-
var _a, _b, _c;
|
|
206
107
|
return (!particle.destroyed &&
|
|
207
108
|
!particle.spawning &&
|
|
208
|
-
(
|
|
209
|
-
(
|
|
109
|
+
(particle.gradient?.angle.enable ||
|
|
110
|
+
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
111
|
+
false)));
|
|
210
112
|
}
|
|
211
113
|
loadOptions(options, ...sources) {
|
|
212
114
|
for (const source of sources) {
|
|
213
|
-
if (!
|
|
115
|
+
if (!source?.gradient) {
|
|
214
116
|
continue;
|
|
215
117
|
}
|
|
216
118
|
const gradientToLoad = source.gradient;
|
|
@@ -218,14 +120,14 @@ class GradientUpdater {
|
|
|
218
120
|
continue;
|
|
219
121
|
}
|
|
220
122
|
options.gradient = (0, engine_1.executeOnSingleOrMultiple)(gradientToLoad, (gradient) => {
|
|
221
|
-
const tmp = new
|
|
123
|
+
const tmp = new AnimatableGradient_js_1.AnimatableGradient();
|
|
222
124
|
tmp.load(gradient);
|
|
223
125
|
return tmp;
|
|
224
126
|
});
|
|
225
127
|
}
|
|
226
128
|
}
|
|
227
129
|
update(particle, delta) {
|
|
228
|
-
updateGradient(particle, delta);
|
|
130
|
+
(0, Utils_js_1.updateGradient)(particle, delta);
|
|
229
131
|
}
|
|
230
132
|
}
|
|
231
133
|
exports.GradientUpdater = GradientUpdater;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AnimatableGradient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const AnimatableGradientColor_js_1 = require("./AnimatableGradientColor.js");
|
|
5
|
+
const GradientAngle_js_1 = require("./GradientAngle.js");
|
|
6
6
|
class AnimatableGradient {
|
|
7
7
|
constructor() {
|
|
8
|
-
this.angle = new
|
|
8
|
+
this.angle = new GradientAngle_js_1.GradientAngle();
|
|
9
9
|
this.colors = [];
|
|
10
10
|
this.type = "random";
|
|
11
11
|
}
|
|
@@ -16,7 +16,7 @@ class AnimatableGradient {
|
|
|
16
16
|
this.angle.load(data.angle);
|
|
17
17
|
if (data.colors !== undefined) {
|
|
18
18
|
this.colors = data.colors.map((s) => {
|
|
19
|
-
const tmp = new
|
|
19
|
+
const tmp = new AnimatableGradientColor_js_1.AnimatableGradientColor();
|
|
20
20
|
tmp.load(s);
|
|
21
21
|
return tmp;
|
|
22
22
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AnimatableGradientColor = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const
|
|
5
|
+
const GradientColorOpacity_js_1 = require("./GradientColorOpacity.js");
|
|
6
6
|
class AnimatableGradientColor {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.stop = 0;
|
|
@@ -17,8 +17,8 @@ class AnimatableGradientColor {
|
|
|
17
17
|
}
|
|
18
18
|
this.value = engine_1.AnimatableColor.create(this.value, data.value);
|
|
19
19
|
if (data.opacity !== undefined) {
|
|
20
|
-
this.opacity = new
|
|
21
|
-
if (
|
|
20
|
+
this.opacity = new GradientColorOpacity_js_1.GradientColorOpacity();
|
|
21
|
+
if ((0, engine_1.isNumber)(data.opacity)) {
|
|
22
22
|
this.opacity.value = data.opacity;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GradientAngle = void 0;
|
|
4
|
-
const
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const GradientAngleAnimation_js_1 = require("./GradientAngleAnimation.js");
|
|
5
6
|
class GradientAngle {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.value = 0;
|
|
8
|
-
this.animation = new
|
|
9
|
+
this.animation = new GradientAngleAnimation_js_1.GradientAngleAnimation();
|
|
9
10
|
this.direction = "clockwise";
|
|
10
11
|
}
|
|
11
12
|
load(data) {
|
|
@@ -14,7 +15,7 @@ class GradientAngle {
|
|
|
14
15
|
}
|
|
15
16
|
this.animation.load(data.animation);
|
|
16
17
|
if (data.value !== undefined) {
|
|
17
|
-
this.value = data.value;
|
|
18
|
+
this.value = (0, engine_1.setRangeValue)(data.value);
|
|
18
19
|
}
|
|
19
20
|
if (data.direction !== undefined) {
|
|
20
21
|
this.direction = data.direction;
|
|
@@ -8,6 +8,7 @@ class GradientAngleAnimation {
|
|
|
8
8
|
this.enable = false;
|
|
9
9
|
this.speed = 0;
|
|
10
10
|
this.decay = 0;
|
|
11
|
+
this.delay = 0;
|
|
11
12
|
this.sync = false;
|
|
12
13
|
}
|
|
13
14
|
load(data) {
|
|
@@ -26,6 +27,9 @@ class GradientAngleAnimation {
|
|
|
26
27
|
if (data.decay !== undefined) {
|
|
27
28
|
this.decay = (0, engine_1.setRangeValue)(data.decay);
|
|
28
29
|
}
|
|
30
|
+
if (data.delay !== undefined) {
|
|
31
|
+
this.delay = (0, engine_1.setRangeValue)(data.delay);
|
|
32
|
+
}
|
|
29
33
|
if (data.sync !== undefined) {
|
|
30
34
|
this.sync = data.sync;
|
|
31
35
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GradientColorOpacity = void 0;
|
|
4
|
-
const GradientColorOpacityAnimation_1 = require("./GradientColorOpacityAnimation");
|
|
5
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const GradientColorOpacityAnimation_js_1 = require("./GradientColorOpacityAnimation.js");
|
|
6
6
|
class GradientColorOpacity {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.value = 0;
|
|
9
|
-
this.animation = new
|
|
9
|
+
this.animation = new GradientColorOpacityAnimation_js_1.GradientColorOpacityAnimation();
|
|
10
10
|
}
|
|
11
11
|
load(data) {
|
|
12
12
|
if (!data) {
|
|
@@ -8,6 +8,7 @@ class GradientColorOpacityAnimation {
|
|
|
8
8
|
this.enable = false;
|
|
9
9
|
this.speed = 0;
|
|
10
10
|
this.decay = 0;
|
|
11
|
+
this.delay = 0;
|
|
11
12
|
this.sync = false;
|
|
12
13
|
this.startValue = "random";
|
|
13
14
|
}
|
|
@@ -30,6 +31,12 @@ class GradientColorOpacityAnimation {
|
|
|
30
31
|
if (data.startValue !== undefined) {
|
|
31
32
|
this.startValue = data.startValue;
|
|
32
33
|
}
|
|
34
|
+
if (data.decay !== undefined) {
|
|
35
|
+
this.decay = (0, engine_1.setRangeValue)(data.decay);
|
|
36
|
+
}
|
|
37
|
+
if (data.delay !== undefined) {
|
|
38
|
+
this.delay = (0, engine_1.setRangeValue)(data.delay);
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
exports.GradientColorOpacityAnimation = GradientColorOpacityAnimation;
|
package/cjs/Types.js
ADDED
package/cjs/Utils.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateGradient = void 0;
|
|
4
|
+
function updateColorOpacity(delta, value) {
|
|
5
|
+
if (!value.enable) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const decay = value.decay ?? 1;
|
|
9
|
+
switch (value.status) {
|
|
10
|
+
case "increasing":
|
|
11
|
+
if (value.value >= value.max) {
|
|
12
|
+
value.status = "decreasing";
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
value.value += (value.velocity ?? 0) * delta.factor;
|
|
16
|
+
}
|
|
17
|
+
break;
|
|
18
|
+
case "decreasing":
|
|
19
|
+
if (value.value <= value.min) {
|
|
20
|
+
value.status = "increasing";
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (value.velocity && decay !== 1) {
|
|
28
|
+
value.velocity *= decay;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function updateColorValue(delta, colorValue, max, decrease) {
|
|
32
|
+
if (!colorValue || !colorValue.enable) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!colorValue.time) {
|
|
36
|
+
colorValue.time = 0;
|
|
37
|
+
}
|
|
38
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
39
|
+
colorValue.time += delta.value;
|
|
40
|
+
}
|
|
41
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
45
|
+
if (!decrease || colorValue.status === "increasing") {
|
|
46
|
+
colorValue.value += velocity;
|
|
47
|
+
if (decrease && colorValue.value > max) {
|
|
48
|
+
colorValue.status = "decreasing";
|
|
49
|
+
colorValue.value -= colorValue.value % max;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
colorValue.value -= velocity;
|
|
54
|
+
if (colorValue.value < 0) {
|
|
55
|
+
colorValue.status = "increasing";
|
|
56
|
+
colorValue.value += colorValue.value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (colorValue.value > max) {
|
|
60
|
+
colorValue.value %= max;
|
|
61
|
+
}
|
|
62
|
+
if (colorValue.velocity && decay !== 1) {
|
|
63
|
+
colorValue.velocity *= decay;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function updateAngle(delta, angle) {
|
|
67
|
+
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 1;
|
|
68
|
+
if (!angle.enable) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
switch (angle.status) {
|
|
72
|
+
case "increasing":
|
|
73
|
+
angle.value += speed;
|
|
74
|
+
if (angle.value > max) {
|
|
75
|
+
angle.value -= max;
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "decreasing":
|
|
79
|
+
default:
|
|
80
|
+
angle.value -= speed;
|
|
81
|
+
if (angle.value < 0) {
|
|
82
|
+
angle.value += max;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (angle.velocity && decay !== 1) {
|
|
87
|
+
angle.velocity *= decay;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function updateGradient(particle, delta) {
|
|
91
|
+
const { gradient } = particle;
|
|
92
|
+
if (!gradient) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
updateAngle(delta, gradient.angle);
|
|
96
|
+
for (const color of gradient.colors) {
|
|
97
|
+
if (particle.color?.h !== undefined) {
|
|
98
|
+
updateColorValue(delta, color.value.h, 360, false);
|
|
99
|
+
}
|
|
100
|
+
if (particle.color?.s !== undefined) {
|
|
101
|
+
updateColorValue(delta, color.value.s, 100, true);
|
|
102
|
+
}
|
|
103
|
+
if (particle.color?.l !== undefined) {
|
|
104
|
+
updateColorValue(delta, color.value.l, 100, true);
|
|
105
|
+
}
|
|
106
|
+
if (color.opacity) {
|
|
107
|
+
updateColorOpacity(delta, color.opacity);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.updateGradient = updateGradient;
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadGradientUpdater = void 0;
|
|
4
|
-
const
|
|
5
|
-
function loadGradientUpdater(engine) {
|
|
6
|
-
engine.addParticleUpdater("gradient", () => new
|
|
4
|
+
const GradientUpdater_js_1 = require("./GradientUpdater.js");
|
|
5
|
+
async function loadGradientUpdater(engine, refresh = true) {
|
|
6
|
+
await engine.addParticleUpdater("gradient", () => new GradientUpdater_js_1.GradientUpdater(), refresh);
|
|
7
7
|
}
|
|
8
8
|
exports.loadGradientUpdater = loadGradientUpdater;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|