@tsparticles/updater-gradient 3.0.0-alpha.0 → 3.0.0-beta.0

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 (53) hide show
  1. package/README.md +16 -12
  2. package/browser/GradientUpdater.js +34 -132
  3. package/browser/Options/Classes/AnimatableGradientColor.js +2 -2
  4. package/browser/Options/Classes/GradientAngle.js +2 -1
  5. package/browser/Options/Classes/GradientAngleAnimation.js +5 -1
  6. package/browser/Options/Classes/GradientColorOpacity.js +1 -1
  7. package/browser/Options/Classes/GradientColorOpacityAnimation.js +8 -1
  8. package/browser/Types.js +1 -0
  9. package/browser/Utils.js +107 -0
  10. package/browser/index.js +2 -2
  11. package/cjs/GradientUpdater.js +35 -133
  12. package/cjs/Options/Classes/AnimatableGradientColor.js +1 -1
  13. package/cjs/Options/Classes/GradientAngle.js +2 -1
  14. package/cjs/Options/Classes/GradientAngleAnimation.js +4 -0
  15. package/cjs/Options/Classes/GradientColorOpacity.js +1 -1
  16. package/cjs/Options/Classes/GradientColorOpacityAnimation.js +7 -0
  17. package/cjs/Types.js +2 -0
  18. package/cjs/Utils.js +111 -0
  19. package/cjs/index.js +2 -2
  20. package/esm/GradientUpdater.js +34 -132
  21. package/esm/Options/Classes/AnimatableGradientColor.js +2 -2
  22. package/esm/Options/Classes/GradientAngle.js +2 -1
  23. package/esm/Options/Classes/GradientAngleAnimation.js +5 -1
  24. package/esm/Options/Classes/GradientColorOpacity.js +1 -1
  25. package/esm/Options/Classes/GradientColorOpacityAnimation.js +8 -1
  26. package/esm/Types.js +1 -0
  27. package/esm/Utils.js +107 -0
  28. package/esm/index.js +2 -2
  29. package/package.json +10 -5
  30. package/report.html +4 -4
  31. package/tsparticles.updater.gradient.js +87 -56
  32. package/tsparticles.updater.gradient.min.js +1 -1
  33. package/tsparticles.updater.gradient.min.js.LICENSE.txt +1 -8
  34. package/types/GradientUpdater.d.ts +2 -25
  35. package/types/Options/Classes/AnimatableGradient.d.ts +1 -2
  36. package/types/Options/Classes/AnimatableGradientColor.d.ts +1 -2
  37. package/types/Options/Classes/GradientAngle.d.ts +2 -3
  38. package/types/Options/Classes/GradientAngleAnimation.d.ts +2 -1
  39. package/types/Options/Classes/GradientColorOpacity.d.ts +1 -1
  40. package/types/Options/Classes/GradientColorOpacityAnimation.d.ts +2 -2
  41. package/types/Options/Interfaces/Gradients.d.ts +1 -1
  42. package/types/Types.d.ts +23 -0
  43. package/types/Utils.d.ts +3 -0
  44. package/types/index.d.ts +1 -1
  45. package/umd/GradientUpdater.js +36 -134
  46. package/umd/Options/Classes/AnimatableGradientColor.js +1 -1
  47. package/umd/Options/Classes/GradientAngle.js +3 -2
  48. package/umd/Options/Classes/GradientAngleAnimation.js +4 -0
  49. package/umd/Options/Classes/GradientColorOpacity.js +2 -2
  50. package/umd/Options/Classes/GradientColorOpacityAnimation.js +7 -0
  51. package/umd/Types.js +12 -0
  52. package/umd/Utils.js +121 -0
  53. package/umd/index.js +2 -2
@@ -1,3 +1,4 @@
1
+ import { setRangeValue, } from "@tsparticles/engine";
1
2
  import { GradientAngleAnimation } from "./GradientAngleAnimation";
2
3
  export class GradientAngle {
3
4
  constructor() {
@@ -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 { setRangeValue, } from "@tsparticles/engine";
1
2
  import { GradientColorOpacityAnimation } from "./GradientColorOpacityAnimation";
2
- import { setRangeValue } from "@tsparticles/engine";
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
1
  import { GradientUpdater } from "./GradientUpdater";
2
- export function loadGradientUpdater(engine) {
3
- engine.addParticleUpdater("gradient", () => new GradientUpdater());
2
+ export async function loadGradientUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("gradient", () => new GradientUpdater(), refresh);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-gradient",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "tsParticles particles gradient updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -73,6 +73,10 @@
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"
@@ -83,10 +87,11 @@
83
87
  "unpkg": "tsparticles.updater.gradient.min.js",
84
88
  "module": "esm/index.js",
85
89
  "types": "types/index.d.ts",
90
+ "sideEffects": false,
91
+ "dependencies": {
92
+ "@tsparticles/engine": "^3.0.0-beta.0"
93
+ },
86
94
  "publishConfig": {
87
95
  "access": "public"
88
- },
89
- "dependencies": {
90
- "@tsparticles/engine": "^3.0.0-alpha.0"
91
96
  }
92
- }
97
+ }