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