@tsparticles/engine 4.0.0-alpha.25 → 4.0.0-alpha.27

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 (140) hide show
  1. package/164.min.js +1 -0
  2. package/README.md +3 -3
  3. package/browser/Core/Canvas.js +7 -4
  4. package/browser/Core/Engine.js +6 -16
  5. package/browser/Core/Particle.js +10 -35
  6. package/browser/Core/Particles.js +0 -23
  7. package/browser/Core/Utils/Constants.js +1 -1
  8. package/browser/Core/Utils/Ranges.js +2 -2
  9. package/browser/Core/Utils/Vectors.js +10 -7
  10. package/browser/Options/Classes/ColorAnimation.js +11 -1
  11. package/browser/Options/Classes/HslAnimation.js +4 -3
  12. package/browser/Options/Classes/Options.js +38 -1
  13. package/browser/Options/Classes/Particles/Effect/Effect.js +0 -5
  14. package/browser/Options/Classes/Particles/Fill.js +28 -0
  15. package/browser/Options/Classes/Particles/Move/Move.js +0 -4
  16. package/browser/Options/Classes/Particles/ParticlesOptions.js +12 -6
  17. package/browser/Options/Classes/Particles/Shape/Shape.js +0 -5
  18. package/browser/Utils/CanvasUtils.js +33 -36
  19. package/browser/Utils/ColorUtils.js +22 -19
  20. package/browser/Utils/MathUtils.js +8 -1
  21. package/browser/Utils/Utils.js +93 -24
  22. package/browser/exports.js +1 -1
  23. package/cjs/Core/Canvas.js +7 -4
  24. package/cjs/Core/Engine.js +6 -16
  25. package/cjs/Core/Particle.js +10 -35
  26. package/cjs/Core/Particles.js +0 -23
  27. package/cjs/Core/Utils/Constants.js +1 -1
  28. package/cjs/Core/Utils/Ranges.js +2 -2
  29. package/cjs/Core/Utils/Vectors.js +10 -7
  30. package/cjs/Options/Classes/ColorAnimation.js +11 -1
  31. package/cjs/Options/Classes/HslAnimation.js +4 -3
  32. package/cjs/Options/Classes/Options.js +38 -1
  33. package/cjs/Options/Classes/Particles/Effect/Effect.js +0 -5
  34. package/cjs/Options/Classes/Particles/Fill.js +28 -0
  35. package/cjs/Options/Classes/Particles/Move/Move.js +0 -4
  36. package/cjs/Options/Classes/Particles/ParticlesOptions.js +12 -6
  37. package/cjs/Options/Classes/Particles/Shape/Shape.js +0 -5
  38. package/cjs/Utils/CanvasUtils.js +33 -36
  39. package/cjs/Utils/ColorUtils.js +22 -19
  40. package/cjs/Utils/MathUtils.js +8 -1
  41. package/cjs/Utils/Utils.js +93 -24
  42. package/cjs/exports.js +1 -1
  43. package/dist_browser_Core_Container_js.js +4 -4
  44. package/esm/Core/Canvas.js +7 -4
  45. package/esm/Core/Engine.js +6 -16
  46. package/esm/Core/Particle.js +10 -35
  47. package/esm/Core/Particles.js +0 -23
  48. package/esm/Core/Utils/Constants.js +1 -1
  49. package/esm/Core/Utils/Ranges.js +2 -2
  50. package/esm/Core/Utils/Vectors.js +10 -7
  51. package/esm/Options/Classes/ColorAnimation.js +11 -1
  52. package/esm/Options/Classes/HslAnimation.js +4 -3
  53. package/esm/Options/Classes/Options.js +38 -1
  54. package/esm/Options/Classes/Particles/Effect/Effect.js +0 -5
  55. package/esm/Options/Classes/Particles/Fill.js +28 -0
  56. package/esm/Options/Classes/Particles/Move/Move.js +0 -4
  57. package/esm/Options/Classes/Particles/ParticlesOptions.js +12 -6
  58. package/esm/Options/Classes/Particles/Shape/Shape.js +0 -5
  59. package/esm/Utils/CanvasUtils.js +33 -36
  60. package/esm/Utils/ColorUtils.js +22 -19
  61. package/esm/Utils/MathUtils.js +8 -1
  62. package/esm/Utils/Utils.js +93 -24
  63. package/esm/exports.js +1 -1
  64. package/package.json +1 -1
  65. package/report.html +1 -1
  66. package/scripts/install.js +4 -20
  67. package/tsparticles.engine.js +34 -34
  68. package/tsparticles.engine.min.js +2 -2
  69. package/types/Core/Engine.d.ts +5 -9
  70. package/types/Core/Interfaces/IPalette.d.ts +7 -0
  71. package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
  72. package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
  73. package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
  74. package/types/Core/Particle.d.ts +3 -7
  75. package/types/Core/Particles.d.ts +0 -5
  76. package/types/Core/Utils/Constants.d.ts +1 -1
  77. package/types/Core/Utils/Vectors.d.ts +6 -6
  78. package/types/Options/Classes/ColorAnimation.d.ts +3 -1
  79. package/types/Options/Classes/Options.d.ts +2 -0
  80. package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
  81. package/types/Options/Classes/Particles/Fill.d.ts +12 -0
  82. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
  83. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +2 -2
  84. package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
  85. package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
  86. package/types/Options/Interfaces/IOptions.d.ts +1 -0
  87. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
  88. package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
  89. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
  90. package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
  91. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
  92. package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
  93. package/types/Types/EngineInitializers.d.ts +0 -6
  94. package/types/Utils/CanvasUtils.d.ts +6 -7
  95. package/types/Utils/ColorUtils.d.ts +1 -2
  96. package/types/Utils/MathUtils.d.ts +2 -0
  97. package/types/Utils/Utils.d.ts +7 -0
  98. package/types/export-types.d.ts +2 -4
  99. package/types/exports.d.ts +1 -1
  100. package/umd/Core/Canvas.js +6 -3
  101. package/umd/Core/Engine.js +6 -16
  102. package/umd/Core/Particle.js +11 -36
  103. package/umd/Core/Particles.js +0 -23
  104. package/umd/Core/Utils/Constants.js +2 -2
  105. package/umd/Core/Utils/Ranges.js +1 -1
  106. package/umd/Core/Utils/Vectors.js +10 -7
  107. package/umd/Options/Classes/ColorAnimation.js +11 -1
  108. package/umd/Options/Classes/HslAnimation.js +5 -4
  109. package/umd/Options/Classes/Options.js +38 -1
  110. package/umd/Options/Classes/Particles/Effect/Effect.js +0 -5
  111. package/umd/Options/Classes/Particles/Fill.js +42 -0
  112. package/umd/Options/Classes/Particles/Move/Move.js +1 -5
  113. package/umd/Options/Classes/Particles/ParticlesOptions.js +13 -7
  114. package/umd/Options/Classes/Particles/Shape/Shape.js +0 -5
  115. package/umd/Utils/CanvasUtils.js +33 -36
  116. package/umd/Utils/ColorUtils.js +21 -18
  117. package/umd/Utils/MathUtils.js +10 -1
  118. package/umd/Utils/Utils.js +94 -24
  119. package/umd/exports.js +2 -2
  120. package/152.min.js +0 -1
  121. package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  122. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  123. package/esm/Core/Interfaces/IMovePathGenerator.js +0 -1
  124. package/esm/Core/Interfaces/IParticleMover.js +0 -1
  125. package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  126. package/esm/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
  127. package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -9
  128. package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
  129. package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
  130. package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
  131. package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -50
  132. package/umd/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -12
  133. /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  134. /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  135. /package/{browser/Options/Interfaces/Particles/Move/IMoveAttract.js → cjs/Core/Interfaces/IPalette.js} +0 -0
  136. /package/cjs/{Core/Interfaces/IMovePathGenerator.js → Options/Interfaces/Particles/IFill.js} +0 -0
  137. /package/{cjs/Core/Interfaces/IParticleMover.js → esm/Core/Interfaces/IPalette.js} +0 -0
  138. /package/{cjs/Options/Interfaces/Particles/Move/IMoveAttract.js → esm/Options/Interfaces/Particles/IFill.js} +0 -0
  139. /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  140. /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
@@ -4,18 +4,19 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./ColorAnimation.js", "../../Utils/TypeUtils.js"], factory);
7
+ define(["require", "exports", "../../Core/Utils/Constants.js", "./ColorAnimation.js", "../../Utils/TypeUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.HslAnimation = void 0;
13
+ const Constants_js_1 = require("../../Core/Utils/Constants.js");
13
14
  const ColorAnimation_js_1 = require("./ColorAnimation.js");
14
15
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
15
16
  class HslAnimation {
16
- h = new ColorAnimation_js_1.ColorAnimation();
17
- l = new ColorAnimation_js_1.ColorAnimation();
18
- s = new ColorAnimation_js_1.ColorAnimation();
17
+ h = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.hMin, Constants_js_1.hMax);
18
+ l = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.lMin, Constants_js_1.lMax);
19
+ s = new ColorAnimation_js_1.ColorAnimation(Constants_js_1.sMin, Constants_js_1.sMax);
19
20
  load(data) {
20
21
  if ((0, TypeUtils_js_1.isNull)(data)) {
21
22
  return;
@@ -30,6 +30,7 @@
30
30
  hdr;
31
31
  key;
32
32
  name;
33
+ palette;
33
34
  particles;
34
35
  pauseOnBlur;
35
36
  pauseOnOutsideViewport;
@@ -66,10 +67,15 @@
66
67
  return;
67
68
  }
68
69
  if (data.preset !== undefined) {
69
- (0, Utils_js_1.executeOnSingleOrMultiple)(data.preset, preset => {
70
+ this.preset = data.preset;
71
+ (0, Utils_js_1.executeOnSingleOrMultiple)(this.preset, preset => {
70
72
  this._importPreset(preset);
71
73
  });
72
74
  }
75
+ if (data.palette !== undefined) {
76
+ this.palette = data.palette;
77
+ this._importPalette(this.palette);
78
+ }
73
79
  if (data.autoPlay !== undefined) {
74
80
  this.autoPlay = data.autoPlay;
75
81
  }
@@ -126,6 +132,37 @@
126
132
  plugin.loadOptions(this._container, this, data);
127
133
  });
128
134
  }
135
+ _importPalette = palette => {
136
+ const paletteData = this._engine.getPalette(palette);
137
+ if (!paletteData) {
138
+ return;
139
+ }
140
+ this.load({
141
+ background: {
142
+ color: paletteData.background,
143
+ },
144
+ blend: {
145
+ enable: true,
146
+ mode: paletteData.blendMode,
147
+ },
148
+ particles: {
149
+ fill: {
150
+ color: paletteData.fill
151
+ ? {
152
+ value: paletteData.colors,
153
+ }
154
+ : undefined,
155
+ enable: paletteData.fill,
156
+ },
157
+ stroke: !paletteData.fill
158
+ ? paletteData.colors.map(color => ({
159
+ color: { value: color },
160
+ width: 1,
161
+ }))
162
+ : undefined,
163
+ },
164
+ });
165
+ };
129
166
  _importPreset = preset => {
130
167
  this.load(this._engine.getPreset(preset));
131
168
  };
@@ -14,12 +14,10 @@
14
14
  const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
15
15
  class Effect {
16
16
  close;
17
- fill;
18
17
  options;
19
18
  type;
20
19
  constructor() {
21
20
  this.close = true;
22
- this.fill = true;
23
21
  this.options = {};
24
22
  this.type = [];
25
23
  }
@@ -39,9 +37,6 @@
39
37
  if (data.close !== undefined) {
40
38
  this.close = data.close;
41
39
  }
42
- if (data.fill !== undefined) {
43
- this.fill = data.fill;
44
- }
45
40
  if (data.type !== undefined) {
46
41
  this.type = data.type;
47
42
  }
@@ -0,0 +1,42 @@
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", "../AnimatableColor.js", "../../../Utils/TypeUtils.js", "../../../Utils/MathUtils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Fill = void 0;
13
+ const AnimatableColor_js_1 = require("../AnimatableColor.js");
14
+ const TypeUtils_js_1 = require("../../../Utils/TypeUtils.js");
15
+ const MathUtils_js_1 = require("../../../Utils/MathUtils.js");
16
+ class Fill {
17
+ color;
18
+ enable;
19
+ opacity;
20
+ constructor() {
21
+ this.enable = true;
22
+ this.color = new AnimatableColor_js_1.AnimatableColor();
23
+ this.color.value = "#fff";
24
+ this.opacity = 1;
25
+ }
26
+ load(data) {
27
+ if ((0, TypeUtils_js_1.isNull)(data)) {
28
+ return;
29
+ }
30
+ if (data.color !== undefined) {
31
+ this.color = AnimatableColor_js_1.AnimatableColor.create(this.color, data.color);
32
+ }
33
+ if (data.enable !== undefined) {
34
+ this.enable = data.enable;
35
+ }
36
+ if (data.opacity !== undefined) {
37
+ this.opacity = (0, MathUtils_js_1.setRangeValue)(data.opacity);
38
+ }
39
+ }
40
+ }
41
+ exports.Fill = Fill;
42
+ });
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../../../../Enums/Directions/MoveDirection.js", "../../../../Utils/TypeUtils.js", "./MoveAngle.js", "./MoveAttract.js", "./MoveCenter.js", "./MoveGravity.js", "./Path/MovePath.js", "./OutModes.js", "./Spin.js", "../../../../Utils/MathUtils.js"], factory);
7
+ define(["require", "exports", "../../../../Enums/Directions/MoveDirection.js", "../../../../Utils/TypeUtils.js", "./MoveAngle.js", "./MoveCenter.js", "./MoveGravity.js", "./Path/MovePath.js", "./OutModes.js", "./Spin.js", "../../../../Utils/MathUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -13,7 +13,6 @@
13
13
  const MoveDirection_js_1 = require("../../../../Enums/Directions/MoveDirection.js");
14
14
  const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
15
15
  const MoveAngle_js_1 = require("./MoveAngle.js");
16
- const MoveAttract_js_1 = require("./MoveAttract.js");
17
16
  const MoveCenter_js_1 = require("./MoveCenter.js");
18
17
  const MoveGravity_js_1 = require("./MoveGravity.js");
19
18
  const MovePath_js_1 = require("./Path/MovePath.js");
@@ -22,7 +21,6 @@
22
21
  const MathUtils_js_1 = require("../../../../Utils/MathUtils.js");
23
22
  class Move {
24
23
  angle;
25
- attract;
26
24
  center;
27
25
  decay;
28
26
  direction;
@@ -41,7 +39,6 @@
41
39
  warp;
42
40
  constructor() {
43
41
  this.angle = new MoveAngle_js_1.MoveAngle();
44
- this.attract = new MoveAttract_js_1.MoveAttract();
45
42
  this.center = new MoveCenter_js_1.MoveCenter();
46
43
  this.decay = 0;
47
44
  this.distance = {};
@@ -64,7 +61,6 @@
64
61
  return;
65
62
  }
66
63
  this.angle.load((0, TypeUtils_js_1.isNumber)(data.angle) ? { value: data.angle } : data.angle);
67
- this.attract.load(data.attract);
68
64
  this.center.load(data.center);
69
65
  if (data.decay !== undefined) {
70
66
  this.decay = (0, MathUtils_js_1.setRangeValue)(data.decay);
@@ -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", "../../../Utils/Utils.js", "../AnimatableColor.js", "./Effect/Effect.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js", "../../../Utils/TypeUtils.js"], factory);
7
+ define(["require", "exports", "../../../Utils/Utils.js", "./Effect/Effect.js", "./Fill.js", "./Move/Move.js", "./Opacity/Opacity.js", "./Bounce/ParticlesBounce.js", "./Number/ParticlesNumber.js", "./Shape/Shape.js", "./Size/Size.js", "./Stroke.js", "./ZIndex/ZIndex.js", "../../../Utils/TypeUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ParticlesOptions = void 0;
13
13
  const Utils_js_1 = require("../../../Utils/Utils.js");
14
- const AnimatableColor_js_1 = require("../AnimatableColor.js");
15
14
  const Effect_js_1 = require("./Effect/Effect.js");
15
+ const Fill_js_1 = require("./Fill.js");
16
16
  const Move_js_1 = require("./Move/Move.js");
17
17
  const Opacity_js_1 = require("./Opacity/Opacity.js");
18
18
  const ParticlesBounce_js_1 = require("./Bounce/ParticlesBounce.js");
@@ -24,8 +24,8 @@
24
24
  const TypeUtils_js_1 = require("../../../Utils/TypeUtils.js");
25
25
  class ParticlesOptions {
26
26
  bounce;
27
- color;
28
27
  effect;
28
+ fill;
29
29
  groups;
30
30
  move;
31
31
  number;
@@ -41,9 +41,8 @@
41
41
  this._engine = engine;
42
42
  this._container = container;
43
43
  this.bounce = new ParticlesBounce_js_1.ParticlesBounce();
44
- this.color = new AnimatableColor_js_1.AnimatableColor();
45
- this.color.value = "#fff";
46
44
  this.effect = new Effect_js_1.Effect();
45
+ this.fill = new Fill_js_1.Fill();
47
46
  this.groups = {};
48
47
  this.move = new Move_js_1.Move();
49
48
  this.number = new ParticlesNumber_js_1.ParticlesNumber();
@@ -60,7 +59,7 @@
60
59
  }
61
60
  if (data.groups !== undefined) {
62
61
  for (const group of Object.keys(data.groups)) {
63
- if (!Object.hasOwn(data.groups, group)) {
62
+ if (!(group in data.groups)) {
64
63
  continue;
65
64
  }
66
65
  const item = data.groups[group];
@@ -73,7 +72,6 @@
73
72
  this.reduceDuplicates = data.reduceDuplicates;
74
73
  }
75
74
  this.bounce.load(data.bounce);
76
- this.color.load(AnimatableColor_js_1.AnimatableColor.create(this.color, data.color));
77
75
  this.effect.load(data.effect);
78
76
  this.move.load(data.move);
79
77
  this.number.load(data.number);
@@ -81,6 +79,14 @@
81
79
  this.shape.load(data.shape);
82
80
  this.size.load(data.size);
83
81
  this.zIndex.load(data.zIndex);
82
+ const fillToLoad = data.fill;
83
+ if (fillToLoad) {
84
+ this.fill = (0, Utils_js_1.executeOnSingleOrMultiple)(fillToLoad, t => {
85
+ const tmp = new Fill_js_1.Fill();
86
+ tmp.load(t);
87
+ return tmp;
88
+ });
89
+ }
84
90
  const strokeToLoad = data.stroke;
85
91
  if (strokeToLoad) {
86
92
  this.stroke = (0, Utils_js_1.executeOnSingleOrMultiple)(strokeToLoad, t => {
@@ -14,12 +14,10 @@
14
14
  const TypeUtils_js_1 = require("../../../../Utils/TypeUtils.js");
15
15
  class Shape {
16
16
  close;
17
- fill;
18
17
  options;
19
18
  type;
20
19
  constructor() {
21
20
  this.close = true;
22
- this.fill = true;
23
21
  this.options = {};
24
22
  this.type = "circle";
25
23
  }
@@ -39,9 +37,6 @@
39
37
  if (data.close !== undefined) {
40
38
  this.close = data.close;
41
39
  }
42
- if (data.fill !== undefined) {
43
- this.fill = data.fill;
44
- }
45
40
  if (data.type !== undefined) {
46
41
  this.type = data.type;
47
42
  }
@@ -28,15 +28,16 @@
28
28
  if (!image) {
29
29
  return;
30
30
  }
31
+ const prevAlpha = context.globalAlpha;
31
32
  context.globalAlpha = opacity;
32
33
  context.drawImage(image, Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
33
- context.globalAlpha = 1;
34
+ context.globalAlpha = prevAlpha;
34
35
  }
35
36
  function clear(context, dimension) {
36
37
  context.clearRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
37
38
  }
38
39
  function drawParticle(data) {
39
- const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
40
+ const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container.particles, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = Constants_js_1.defaultZoom, drawPosition = {
40
41
  x: pos.x,
41
42
  y: pos.y,
42
43
  };
@@ -44,7 +45,7 @@
44
45
  if (colorStyles.fill) {
45
46
  context.fillStyle = colorStyles.fill;
46
47
  }
47
- const strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
48
+ const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
48
49
  context.lineWidth = strokeWidth;
49
50
  if (colorStyles.stroke) {
50
51
  context.strokeStyle = colorStyles.stroke;
@@ -57,8 +58,8 @@
57
58
  opacity,
58
59
  delta,
59
60
  pixelRatio: container.retina.pixelRatio,
60
- fill: particle.shapeFill,
61
- stroke: strokeWidth > Constants_js_1.minStrokeWidth || !particle.shapeFill,
61
+ fill: fillEnabled,
62
+ stroke: strokeWidth > Constants_js_1.minStrokeWidth,
62
63
  transformData,
63
64
  position: { ...pos },
64
65
  drawPosition,
@@ -67,42 +68,40 @@
67
68
  for (const plugin of container.plugins) {
68
69
  plugin.drawParticleTransform?.(drawData);
69
70
  }
70
- drawBeforeEffect(container, drawData);
71
- drawShapeBeforeDraw(container, drawData);
72
- drawShape(container, drawData);
73
- drawShapeAfterDraw(container, drawData);
74
- drawAfterEffect(container, drawData);
71
+ const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
72
+ drawBeforeEffect(effect, drawData);
73
+ drawShapeBeforeDraw(shape, drawData);
74
+ drawShape(shape, drawData);
75
+ drawShapeAfterDraw(shape, drawData);
76
+ drawAfterEffect(effect, drawData);
75
77
  context.resetTransform();
76
78
  }
77
- function drawAfterEffect(container, data) {
79
+ function drawAfterEffect(drawer, data) {
80
+ if (!drawer?.drawAfter) {
81
+ return;
82
+ }
78
83
  const { particle } = data;
79
84
  if (!particle.effect) {
80
85
  return;
81
86
  }
82
- const drawer = container.particles.effectDrawers.get(particle.effect), drawFunc = drawer?.drawAfter;
83
- if (!drawFunc) {
87
+ drawer.drawAfter(data);
88
+ }
89
+ function drawBeforeEffect(drawer, data) {
90
+ if (!drawer?.drawBefore) {
84
91
  return;
85
92
  }
86
- drawFunc(data);
87
- }
88
- function drawBeforeEffect(container, data) {
89
93
  const { particle } = data;
90
94
  if (!particle.effect) {
91
95
  return;
92
96
  }
93
- const drawer = container.particles.effectDrawers.get(particle.effect);
94
- if (!drawer?.drawBefore) {
95
- return;
96
- }
97
97
  drawer.drawBefore(data);
98
98
  }
99
- function drawShape(container, data) {
100
- const { context, particle, stroke } = data;
101
- if (!particle.shape) {
99
+ function drawShape(drawer, data) {
100
+ if (!drawer) {
102
101
  return;
103
102
  }
104
- const drawer = container.particles.shapeDrawers.get(particle.shape);
105
- if (!drawer) {
103
+ const { context, fill, particle, stroke } = data;
104
+ if (!particle.shape) {
106
105
  return;
107
106
  }
108
107
  context.beginPath();
@@ -113,30 +112,28 @@
113
112
  if (stroke) {
114
113
  context.stroke();
115
114
  }
116
- if (particle.shapeFill) {
115
+ if (fill) {
117
116
  context.fill();
118
117
  }
119
118
  }
120
- function drawShapeAfterDraw(container, data) {
121
- const { particle } = data;
122
- if (!particle.shape) {
123
- return;
124
- }
125
- const drawer = container.particles.shapeDrawers.get(particle.shape);
119
+ function drawShapeAfterDraw(drawer, data) {
126
120
  if (!drawer?.afterDraw) {
127
121
  return;
128
122
  }
129
- drawer.afterDraw(data);
130
- }
131
- function drawShapeBeforeDraw(container, data) {
132
123
  const { particle } = data;
133
124
  if (!particle.shape) {
134
125
  return;
135
126
  }
136
- const drawer = container.particles.shapeDrawers.get(particle.shape);
127
+ drawer.afterDraw(data);
128
+ }
129
+ function drawShapeBeforeDraw(drawer, data) {
137
130
  if (!drawer?.beforeDraw) {
138
131
  return;
139
132
  }
133
+ const { particle } = data;
134
+ if (!particle.shape) {
135
+ return;
136
+ }
140
137
  drawer.beforeDraw(data);
141
138
  }
142
139
  function drawParticlePlugin(context, plugin, particle, delta) {
@@ -221,10 +221,10 @@
221
221
  }
222
222
  function colorMix(color1, color2, size1, size2) {
223
223
  let rgb1 = color1, rgb2 = color2;
224
- if (!Object.hasOwn(rgb1, "r")) {
224
+ if (!("r" in rgb1)) {
225
225
  rgb1 = hslToRgb(color1);
226
226
  }
227
- if (!Object.hasOwn(rgb2, "r")) {
227
+ if (!("r" in rgb2)) {
228
228
  rgb2 = hslToRgb(color2);
229
229
  }
230
230
  return {
@@ -277,27 +277,33 @@
277
277
  }
278
278
  }
279
279
  function getHslFromAnimation(animation) {
280
- return animation !== undefined
281
- ? {
280
+ return animation === undefined
281
+ ? undefined
282
+ : {
282
283
  h: animation.h.value,
283
284
  s: animation.s.value,
284
285
  l: animation.l.value,
285
- }
286
- : undefined;
286
+ };
287
287
  }
288
288
  function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
289
289
  const resColor = {
290
290
  h: {
291
291
  enable: false,
292
292
  value: hsl.h,
293
+ min: Constants_js_1.hMin,
294
+ max: Constants_js_1.hMax,
293
295
  },
294
296
  s: {
295
297
  enable: false,
296
298
  value: hsl.s,
299
+ min: Constants_js_1.sMin,
300
+ max: Constants_js_1.sMax,
297
301
  },
298
302
  l: {
299
303
  enable: false,
300
304
  value: hsl.l,
305
+ min: Constants_js_1.lMin,
306
+ max: Constants_js_1.lMax,
301
307
  },
302
308
  };
303
309
  if (animationOptions) {
@@ -309,6 +315,8 @@
309
315
  }
310
316
  function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
311
317
  colorValue.enable = colorAnimation.enable;
318
+ colorValue.min = colorAnimation.min;
319
+ colorValue.max = colorAnimation.max;
312
320
  if (colorValue.enable) {
313
321
  colorValue.velocity = ((0, MathUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
314
322
  colorValue.decay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(colorAnimation.decay);
@@ -328,7 +336,7 @@
328
336
  colorValue.velocity = Constants_js_1.defaultVelocity;
329
337
  }
330
338
  }
331
- function updateColorValue(data, range, decrease, delta) {
339
+ function updateColorValue(data, decrease, delta) {
332
340
  const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
333
341
  if (!data.enable ||
334
342
  ((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
@@ -341,7 +349,7 @@
341
349
  if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
342
350
  return;
343
351
  }
344
- const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = (0, MathUtils_js_1.getRangeMax)(range), min = (0, MathUtils_js_1.getRangeMin)(range);
352
+ const offset = data.offset ? (0, MathUtils_js_1.randomInRangeValue)(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
345
353
  if (!decrease || data.status === AnimationStatus_js_1.AnimationStatus.increasing) {
346
354
  data.value += velocity;
347
355
  if (data.value > max) {
@@ -357,8 +365,7 @@
357
365
  }
358
366
  else {
359
367
  data.value -= velocity;
360
- const minValue = 0;
361
- if (data.value < minValue) {
368
+ if (data.value < min) {
362
369
  data.loops ??= 0;
363
370
  data.loops++;
364
371
  data.status = AnimationStatus_js_1.AnimationStatus.increasing;
@@ -373,14 +380,10 @@
373
380
  if (!color) {
374
381
  return;
375
382
  }
376
- const { h, s, l } = color, ranges = {
377
- h: { min: Constants_js_1.hMin, max: Constants_js_1.hMax },
378
- s: { min: Constants_js_1.sMin, max: Constants_js_1.sMax },
379
- l: { min: Constants_js_1.lMin, max: Constants_js_1.lMax },
380
- };
381
- updateColorValue(h, ranges.h, false, delta);
382
- updateColorValue(s, ranges.s, true, delta);
383
- updateColorValue(l, ranges.l, true, delta);
383
+ const { h, s, l } = color;
384
+ updateColorValue(h, false, delta);
385
+ updateColorValue(s, true, delta);
386
+ updateColorValue(l, true, delta);
384
387
  }
385
388
  function alterHsl(color, type, value) {
386
389
  return {
@@ -23,7 +23,9 @@
23
23
  exports.getRangeMax = getRangeMax;
24
24
  exports.setRangeValue = setRangeValue;
25
25
  exports.getDistances = getDistances;
26
+ exports.getDistanceSq = getDistanceSq;
26
27
  exports.getDistance = getDistance;
28
+ exports.checkDistance = checkDistance;
27
29
  exports.degToRad = degToRad;
28
30
  exports.getParticleDirectionAngle = getParticleDirectionAngle;
29
31
  exports.getParticleBaseVelocity = getParticleBaseVelocity;
@@ -105,8 +107,15 @@
105
107
  const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
106
108
  return { dx: dx, dy: dy, distance: Math.hypot(dx, dy) };
107
109
  }
110
+ function getDistanceSq(pointA, pointB) {
111
+ const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
112
+ return dx * dx + dy * dy;
113
+ }
108
114
  function getDistance(pointA, pointB) {
109
- return getDistances(pointA, pointB).distance;
115
+ return Math.sqrt(getDistanceSq(pointA, pointB));
116
+ }
117
+ function checkDistance(pointA, pointB, distance) {
118
+ return getDistanceSq(pointA, pointB) <= distance * distance;
110
119
  }
111
120
  function degToRad(degrees) {
112
121
  return degrees * degToRadFactor;