@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/esm/GradientUpdater.js
CHANGED
|
@@ -1,111 +1,8 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, getHslAnimationFromHsl, getRandom, getRangeMax, getRangeMin, getRangeValue, getStyleFromHsl, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
|
-
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient";
|
|
3
|
-
|
|
4
|
-
var _a, _b, _c;
|
|
5
|
-
if (!value.enable) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
const decay = (_a = value.decay) !== null && _a !== void 0 ? _a : 1;
|
|
9
|
-
switch (value.status) {
|
|
10
|
-
case "increasing":
|
|
11
|
-
if (value.value >= value.max) {
|
|
12
|
-
value.status = "decreasing";
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
value.value += ((_b = value.velocity) !== null && _b !== void 0 ? _b : 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 -= ((_c = value.velocity) !== null && _c !== void 0 ? _c : 0) * delta.factor;
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
if (value.velocity && decay !== 1) {
|
|
28
|
-
value.velocity *= decay;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function updateColorValue(delta, value, max, decrease) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const colorValue = value;
|
|
34
|
-
if (!colorValue || !colorValue.enable) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
|
38
|
-
if (!decrease || colorValue.status === "increasing") {
|
|
39
|
-
colorValue.value += velocity;
|
|
40
|
-
if (decrease && colorValue.value > max) {
|
|
41
|
-
colorValue.status = "decreasing";
|
|
42
|
-
colorValue.value -= colorValue.value % max;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
colorValue.value -= velocity;
|
|
47
|
-
if (colorValue.value < 0) {
|
|
48
|
-
colorValue.status = "increasing";
|
|
49
|
-
colorValue.value += colorValue.value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (colorValue.value > max) {
|
|
53
|
-
colorValue.value %= max;
|
|
54
|
-
}
|
|
55
|
-
if (value.velocity && decay !== 1) {
|
|
56
|
-
value.velocity *= decay;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function updateAngle(delta, angle) {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
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;
|
|
62
|
-
if (!angle.enable) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
switch (angle.status) {
|
|
66
|
-
case "increasing":
|
|
67
|
-
angle.value += speed;
|
|
68
|
-
if (angle.value > max) {
|
|
69
|
-
angle.value -= max;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case "decreasing":
|
|
73
|
-
default:
|
|
74
|
-
angle.value -= speed;
|
|
75
|
-
if (angle.value < 0) {
|
|
76
|
-
angle.value += max;
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if (angle.velocity && decay !== 1) {
|
|
81
|
-
angle.velocity *= decay;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function updateGradient(particle, delta) {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
-
const gradient = particle.gradient;
|
|
87
|
-
if (!gradient) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
updateAngle(delta, gradient.angle);
|
|
91
|
-
for (const color of gradient.colors) {
|
|
92
|
-
if (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h) !== undefined) {
|
|
93
|
-
updateColorValue(delta, color.value.h, 360, false);
|
|
94
|
-
}
|
|
95
|
-
if (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s) !== undefined) {
|
|
96
|
-
updateColorValue(delta, color.value.s, 100, true);
|
|
97
|
-
}
|
|
98
|
-
if (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l) !== undefined) {
|
|
99
|
-
updateColorValue(delta, color.value.l, 100, true);
|
|
100
|
-
}
|
|
101
|
-
if (color.opacity) {
|
|
102
|
-
updateColorOpacity(delta, color.opacity);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
2
|
+
import { AnimatableGradient } from "./Options/Classes/AnimatableGradient.js";
|
|
3
|
+
import { updateGradient } from "./Utils.js";
|
|
106
4
|
export class GradientUpdater {
|
|
107
5
|
getColorStyles(particle, context, radius, opacity) {
|
|
108
|
-
var _a, _b;
|
|
109
6
|
const gradient = particle.gradient;
|
|
110
7
|
if (!gradient) {
|
|
111
8
|
return {};
|
|
@@ -113,12 +10,12 @@ export class GradientUpdater {
|
|
|
113
10
|
const gradientAngle = gradient.angle.value, fillGradient = gradient.type === "radial"
|
|
114
11
|
? context.createRadialGradient(0, 0, 0, 0, 0, radius)
|
|
115
12
|
: context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
|
|
116
|
-
for (const
|
|
117
|
-
fillGradient.addColorStop(
|
|
118
|
-
h:
|
|
119
|
-
s:
|
|
120
|
-
l:
|
|
121
|
-
},
|
|
13
|
+
for (const { stop, value, opacity: cOpacity } of gradient.colors) {
|
|
14
|
+
fillGradient.addColorStop(stop, getStyleFromHsl({
|
|
15
|
+
h: value.h.value,
|
|
16
|
+
s: value.s.value,
|
|
17
|
+
l: value.l.value,
|
|
18
|
+
}, cOpacity?.value ?? opacity));
|
|
122
19
|
}
|
|
123
20
|
return { fill: fillGradient };
|
|
124
21
|
}
|
|
@@ -127,20 +24,22 @@ export class GradientUpdater {
|
|
|
127
24
|
if (!gradient) {
|
|
128
25
|
return;
|
|
129
26
|
}
|
|
27
|
+
const { angle } = gradient;
|
|
130
28
|
particle.gradient = {
|
|
131
29
|
angle: {
|
|
132
|
-
value:
|
|
133
|
-
enable:
|
|
134
|
-
velocity: (getRangeValue(
|
|
135
|
-
decay: 1 - getRangeValue(
|
|
30
|
+
value: getRangeValue(angle.value),
|
|
31
|
+
enable: angle.animation.enable,
|
|
32
|
+
velocity: (getRangeValue(angle.animation.speed) / 360) * particle.container.retina.reduceFactor,
|
|
33
|
+
decay: 1 - getRangeValue(angle.animation.decay),
|
|
34
|
+
delayTime: getRangeValue(angle.animation.delay) * 1000,
|
|
35
|
+
time: 0,
|
|
136
36
|
},
|
|
137
37
|
type: gradient.type,
|
|
138
38
|
colors: [],
|
|
139
39
|
};
|
|
140
40
|
let rotateDirection = gradient.angle.direction;
|
|
141
41
|
if (rotateDirection === "random") {
|
|
142
|
-
|
|
143
|
-
rotateDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
42
|
+
rotateDirection = getRandom() > 0.5 ? "counter-clockwise" : "clockwise";
|
|
144
43
|
}
|
|
145
44
|
switch (rotateDirection) {
|
|
146
45
|
case "counter-clockwise":
|
|
@@ -170,28 +69,31 @@ export class GradientUpdater {
|
|
|
170
69
|
velocity: (getRangeValue(grColor.opacity.animation.speed) / 100) *
|
|
171
70
|
particle.container.retina.reduceFactor,
|
|
172
71
|
decay: 1 - getRangeValue(grColor.opacity.animation.decay),
|
|
72
|
+
delayTime: getRangeValue(grColor.opacity.animation.delay) * 1000,
|
|
73
|
+
time: 0,
|
|
173
74
|
}
|
|
174
75
|
: undefined,
|
|
175
76
|
};
|
|
176
|
-
|
|
77
|
+
const { opacity: addOpacity } = addColor;
|
|
78
|
+
if (grColor.opacity && addOpacity) {
|
|
177
79
|
const opacityRange = grColor.opacity.value;
|
|
178
|
-
|
|
179
|
-
|
|
80
|
+
addOpacity.min = getRangeMin(opacityRange);
|
|
81
|
+
addOpacity.max = getRangeMax(opacityRange);
|
|
180
82
|
const opacityAnimation = grColor.opacity.animation;
|
|
181
83
|
switch (opacityAnimation.startValue) {
|
|
182
84
|
case "min":
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
break;
|
|
186
|
-
case "random":
|
|
187
|
-
addColor.opacity.value = randomInRange(addColor.opacity);
|
|
188
|
-
addColor.opacity.status =
|
|
189
|
-
getRandom() >= 0.5 ? "increasing" : "decreasing";
|
|
85
|
+
addOpacity.value = addOpacity.min;
|
|
86
|
+
addOpacity.status = "increasing";
|
|
190
87
|
break;
|
|
191
88
|
case "max":
|
|
89
|
+
addOpacity.value = addOpacity.max;
|
|
90
|
+
addOpacity.status = "decreasing";
|
|
91
|
+
break;
|
|
92
|
+
case "random":
|
|
192
93
|
default:
|
|
193
|
-
|
|
194
|
-
|
|
94
|
+
addOpacity.value = randomInRange(addOpacity);
|
|
95
|
+
addOpacity.status =
|
|
96
|
+
getRandom() >= 0.5 ? "increasing" : "decreasing";
|
|
195
97
|
break;
|
|
196
98
|
}
|
|
197
99
|
}
|
|
@@ -199,15 +101,15 @@ export class GradientUpdater {
|
|
|
199
101
|
}
|
|
200
102
|
}
|
|
201
103
|
isEnabled(particle) {
|
|
202
|
-
var _a, _b, _c;
|
|
203
104
|
return (!particle.destroyed &&
|
|
204
105
|
!particle.spawning &&
|
|
205
|
-
(
|
|
206
|
-
(
|
|
106
|
+
(particle.gradient?.angle.enable ||
|
|
107
|
+
(particle.gradient?.colors.some((c) => c.value.h.enable || c.value.s.enable || c.value.l.enable) ??
|
|
108
|
+
false)));
|
|
207
109
|
}
|
|
208
110
|
loadOptions(options, ...sources) {
|
|
209
111
|
for (const source of sources) {
|
|
210
|
-
if (!
|
|
112
|
+
if (!source?.gradient) {
|
|
211
113
|
continue;
|
|
212
114
|
}
|
|
213
115
|
const gradientToLoad = source.gradient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnimatableGradientColor } from "./AnimatableGradientColor";
|
|
2
|
-
import { GradientAngle } from "./GradientAngle";
|
|
1
|
+
import { AnimatableGradientColor } from "./AnimatableGradientColor.js";
|
|
2
|
+
import { GradientAngle } from "./GradientAngle.js";
|
|
3
3
|
export class AnimatableGradient {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.angle = new GradientAngle();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnimatableColor } from "@tsparticles/engine";
|
|
2
|
-
import { GradientColorOpacity } from "./GradientColorOpacity";
|
|
1
|
+
import { AnimatableColor, isNumber } from "@tsparticles/engine";
|
|
2
|
+
import { GradientColorOpacity } from "./GradientColorOpacity.js";
|
|
3
3
|
export class AnimatableGradientColor {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.stop = 0;
|
|
@@ -15,7 +15,7 @@ export class AnimatableGradientColor {
|
|
|
15
15
|
this.value = AnimatableColor.create(this.value, data.value);
|
|
16
16
|
if (data.opacity !== undefined) {
|
|
17
17
|
this.opacity = new GradientColorOpacity();
|
|
18
|
-
if (
|
|
18
|
+
if (isNumber(data.opacity)) {
|
|
19
19
|
this.opacity.value = data.opacity;
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { GradientAngleAnimation } from "./GradientAngleAnimation.js";
|
|
2
3
|
export class GradientAngle {
|
|
3
4
|
constructor() {
|
|
4
5
|
this.value = 0;
|
|
@@ -11,7 +12,7 @@ export class GradientAngle {
|
|
|
11
12
|
}
|
|
12
13
|
this.animation.load(data.animation);
|
|
13
14
|
if (data.value !== undefined) {
|
|
14
|
-
this.value = data.value;
|
|
15
|
+
this.value = setRangeValue(data.value);
|
|
15
16
|
}
|
|
16
17
|
if (data.direction !== undefined) {
|
|
17
18
|
this.direction = data.direction;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { setRangeValue } from "@tsparticles/engine";
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientAngleAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
5
5
|
this.enable = false;
|
|
6
6
|
this.speed = 0;
|
|
7
7
|
this.decay = 0;
|
|
8
|
+
this.delay = 0;
|
|
8
9
|
this.sync = false;
|
|
9
10
|
}
|
|
10
11
|
load(data) {
|
|
@@ -23,6 +24,9 @@ export class GradientAngleAnimation {
|
|
|
23
24
|
if (data.decay !== undefined) {
|
|
24
25
|
this.decay = setRangeValue(data.decay);
|
|
25
26
|
}
|
|
27
|
+
if (data.delay !== undefined) {
|
|
28
|
+
this.delay = setRangeValue(data.delay);
|
|
29
|
+
}
|
|
26
30
|
if (data.sync !== undefined) {
|
|
27
31
|
this.sync = data.sync;
|
|
28
32
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { GradientColorOpacityAnimation } from "./GradientColorOpacityAnimation.js";
|
|
3
3
|
export class GradientColorOpacity {
|
|
4
4
|
constructor() {
|
|
5
5
|
this.value = 0;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { setRangeValue } from "@tsparticles/engine";
|
|
1
|
+
import { setRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
export class GradientColorOpacityAnimation {
|
|
3
3
|
constructor() {
|
|
4
4
|
this.count = 0;
|
|
5
5
|
this.enable = false;
|
|
6
6
|
this.speed = 0;
|
|
7
7
|
this.decay = 0;
|
|
8
|
+
this.delay = 0;
|
|
8
9
|
this.sync = false;
|
|
9
10
|
this.startValue = "random";
|
|
10
11
|
}
|
|
@@ -27,5 +28,11 @@ export class GradientColorOpacityAnimation {
|
|
|
27
28
|
if (data.startValue !== undefined) {
|
|
28
29
|
this.startValue = data.startValue;
|
|
29
30
|
}
|
|
31
|
+
if (data.decay !== undefined) {
|
|
32
|
+
this.decay = setRangeValue(data.decay);
|
|
33
|
+
}
|
|
34
|
+
if (data.delay !== undefined) {
|
|
35
|
+
this.delay = setRangeValue(data.delay);
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
}
|
package/esm/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/Utils.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function updateColorOpacity(delta, value) {
|
|
2
|
+
if (!value.enable) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const decay = value.decay ?? 1;
|
|
6
|
+
switch (value.status) {
|
|
7
|
+
case "increasing":
|
|
8
|
+
if (value.value >= value.max) {
|
|
9
|
+
value.status = "decreasing";
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
value.value += (value.velocity ?? 0) * delta.factor;
|
|
13
|
+
}
|
|
14
|
+
break;
|
|
15
|
+
case "decreasing":
|
|
16
|
+
if (value.value <= value.min) {
|
|
17
|
+
value.status = "increasing";
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
value.value -= (value.velocity ?? 0) * delta.factor;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
if (value.velocity && decay !== 1) {
|
|
25
|
+
value.velocity *= decay;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function updateColorValue(delta, colorValue, max, decrease) {
|
|
29
|
+
if (!colorValue || !colorValue.enable) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!colorValue.time) {
|
|
33
|
+
colorValue.time = 0;
|
|
34
|
+
}
|
|
35
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
36
|
+
colorValue.time += delta.value;
|
|
37
|
+
}
|
|
38
|
+
if ((colorValue.delayTime ?? 0) > 0 && colorValue.time < (colorValue.delayTime ?? 0)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const velocity = (colorValue.velocity ?? 0) * delta.factor, decay = colorValue.decay ?? 1;
|
|
42
|
+
if (!decrease || colorValue.status === "increasing") {
|
|
43
|
+
colorValue.value += velocity;
|
|
44
|
+
if (decrease && colorValue.value > max) {
|
|
45
|
+
colorValue.status = "decreasing";
|
|
46
|
+
colorValue.value -= colorValue.value % max;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
colorValue.value -= velocity;
|
|
51
|
+
if (colorValue.value < 0) {
|
|
52
|
+
colorValue.status = "increasing";
|
|
53
|
+
colorValue.value += colorValue.value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (colorValue.value > max) {
|
|
57
|
+
colorValue.value %= max;
|
|
58
|
+
}
|
|
59
|
+
if (colorValue.velocity && decay !== 1) {
|
|
60
|
+
colorValue.velocity *= decay;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function updateAngle(delta, angle) {
|
|
64
|
+
const speed = (angle.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = angle.decay ?? 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
|
+
export function updateGradient(particle, delta) {
|
|
88
|
+
const { gradient } = particle;
|
|
89
|
+
if (!gradient) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
updateAngle(delta, gradient.angle);
|
|
93
|
+
for (const color of gradient.colors) {
|
|
94
|
+
if (particle.color?.h !== undefined) {
|
|
95
|
+
updateColorValue(delta, color.value.h, 360, false);
|
|
96
|
+
}
|
|
97
|
+
if (particle.color?.s !== undefined) {
|
|
98
|
+
updateColorValue(delta, color.value.s, 100, true);
|
|
99
|
+
}
|
|
100
|
+
if (particle.color?.l !== undefined) {
|
|
101
|
+
updateColorValue(delta, color.value.l, 100, true);
|
|
102
|
+
}
|
|
103
|
+
if (color.opacity) {
|
|
104
|
+
updateColorOpacity(delta, color.opacity);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GradientUpdater } from "./GradientUpdater";
|
|
2
|
-
export function loadGradientUpdater(engine) {
|
|
3
|
-
engine.addParticleUpdater("gradient", () => new GradientUpdater());
|
|
1
|
+
import { GradientUpdater } from "./GradientUpdater.js";
|
|
2
|
+
export async function loadGradientUpdater(engine, refresh = true) {
|
|
3
|
+
await engine.addParticleUpdater("gradient", () => new GradientUpdater(), refresh);
|
|
4
4
|
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-gradient",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "tsParticles particles gradient updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -73,20 +73,37 @@
|
|
|
73
73
|
"type": "github",
|
|
74
74
|
"url": "https://github.com/sponsors/matteobruni"
|
|
75
75
|
},
|
|
76
|
+
{
|
|
77
|
+
"type": "github",
|
|
78
|
+
"url": "https://github.com/sponsors/tsparticles"
|
|
79
|
+
},
|
|
76
80
|
{
|
|
77
81
|
"type": "buymeacoffee",
|
|
78
82
|
"url": "https://www.buymeacoffee.com/matteobruni"
|
|
79
83
|
}
|
|
80
84
|
],
|
|
81
|
-
"
|
|
85
|
+
"sideEffects": false,
|
|
82
86
|
"jsdelivr": "tsparticles.updater.gradient.min.js",
|
|
83
87
|
"unpkg": "tsparticles.updater.gradient.min.js",
|
|
88
|
+
"browser": "browser/index.js",
|
|
89
|
+
"main": "cjs/index.js",
|
|
84
90
|
"module": "esm/index.js",
|
|
85
91
|
"types": "types/index.d.ts",
|
|
86
|
-
"
|
|
87
|
-
"
|
|
92
|
+
"exports": {
|
|
93
|
+
".": {
|
|
94
|
+
"types": "./types/index.d.ts",
|
|
95
|
+
"browser": "./browser/index.js",
|
|
96
|
+
"import": "./esm/index.js",
|
|
97
|
+
"require": "./cjs/index.js",
|
|
98
|
+
"umd": "./umd/index.js",
|
|
99
|
+
"default": "./cjs/index.js"
|
|
100
|
+
},
|
|
101
|
+
"./package.json": "./package.json"
|
|
88
102
|
},
|
|
89
103
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.0.0-
|
|
104
|
+
"@tsparticles/engine": "^3.0.0-beta.1"
|
|
105
|
+
},
|
|
106
|
+
"publishConfig": {
|
|
107
|
+
"access": "public"
|
|
91
108
|
}
|
|
92
|
-
}
|
|
109
|
+
}
|