@tsparticles/engine 3.0.0-beta.3 → 3.0.0-beta.4

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 (177) hide show
  1. package/browser/Core/Canvas.js +2 -2
  2. package/browser/Core/Container.js +36 -19
  3. package/browser/Core/Engine.js +18 -5
  4. package/browser/Core/Particle.js +75 -40
  5. package/browser/Core/Particles.js +51 -26
  6. package/browser/Core/Retina.js +0 -2
  7. package/browser/Core/Utils/QuadTree.js +1 -1
  8. package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  9. package/browser/Options/Classes/ColorAnimation.js +4 -24
  10. package/browser/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  11. package/browser/Options/Classes/Particles/Effect/Effect.js +32 -0
  12. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  13. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  14. package/browser/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  15. package/browser/Options/Classes/Particles/ParticlesOptions.js +3 -0
  16. package/browser/Options/Classes/Particles/Size/Size.js +2 -3
  17. package/browser/Options/Classes/ValueWithRandom.js +1 -10
  18. package/browser/Utils/CanvasUtils.js +23 -18
  19. package/browser/Utils/ColorUtils.js +24 -38
  20. package/browser/Utils/NumberUtils.js +7 -16
  21. package/browser/Utils/Utils.js +7 -7
  22. package/browser/export-types.js +4 -0
  23. package/browser/exports.js +2 -3
  24. package/cjs/Core/Canvas.js +2 -2
  25. package/cjs/Core/Container.js +36 -19
  26. package/cjs/Core/Engine.js +18 -5
  27. package/cjs/Core/Particle.js +74 -39
  28. package/cjs/Core/Particles.js +51 -26
  29. package/cjs/Core/Retina.js +0 -2
  30. package/cjs/Core/Utils/QuadTree.js +1 -1
  31. package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  32. package/cjs/Options/Classes/ColorAnimation.js +4 -24
  33. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  34. package/cjs/Options/Classes/Particles/Effect/Effect.js +36 -0
  35. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  36. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +21 -0
  37. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  38. package/cjs/Options/Classes/Particles/ParticlesOptions.js +3 -0
  39. package/cjs/Options/Classes/Particles/Size/Size.js +2 -3
  40. package/cjs/Options/Classes/ValueWithRandom.js +1 -10
  41. package/cjs/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +2 -0
  42. package/cjs/Utils/CanvasUtils.js +26 -21
  43. package/cjs/Utils/ColorUtils.js +24 -38
  44. package/cjs/Utils/NumberUtils.js +8 -18
  45. package/cjs/Utils/Utils.js +6 -6
  46. package/cjs/export-types.js +4 -0
  47. package/cjs/exports.js +2 -3
  48. package/esm/Core/Canvas.js +2 -2
  49. package/esm/Core/Container.js +36 -19
  50. package/esm/Core/Engine.js +18 -5
  51. package/esm/Core/Particle.js +75 -40
  52. package/esm/Core/Particles.js +51 -26
  53. package/esm/Core/Retina.js +0 -2
  54. package/esm/Core/Utils/QuadTree.js +1 -1
  55. package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  56. package/esm/Options/Classes/ColorAnimation.js +4 -24
  57. package/esm/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  58. package/esm/Options/Classes/Particles/Effect/Effect.js +32 -0
  59. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  60. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  61. package/esm/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  62. package/esm/Options/Classes/Particles/ParticlesOptions.js +3 -0
  63. package/esm/Options/Classes/Particles/Size/Size.js +2 -3
  64. package/esm/Options/Classes/ValueWithRandom.js +1 -10
  65. package/esm/Options/Interfaces/Particles/Effect/IEffect.js +1 -0
  66. package/esm/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +1 -0
  67. package/esm/Utils/CanvasUtils.js +23 -18
  68. package/esm/Utils/ColorUtils.js +24 -38
  69. package/esm/Utils/NumberUtils.js +7 -16
  70. package/esm/Utils/Utils.js +7 -7
  71. package/esm/export-types.js +4 -0
  72. package/esm/exports.js +2 -3
  73. package/package.json +1 -1
  74. package/report.html +4 -22
  75. package/tsparticles.engine.js +387 -283
  76. package/tsparticles.engine.min.js +1 -1
  77. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  78. package/types/Core/Canvas.d.ts +0 -1
  79. package/types/Core/Container.d.ts +8 -7
  80. package/types/Core/Engine.d.ts +7 -2
  81. package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -3
  82. package/types/Core/Interfaces/IEffectDrawer.d.ts +10 -0
  83. package/types/Core/Interfaces/IExternalInteractor.d.ts +3 -4
  84. package/types/Core/Interfaces/IInteractor.d.ts +3 -3
  85. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +0 -1
  86. package/types/Core/Interfaces/IParticlesInteractor.d.ts +3 -3
  87. package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -0
  88. package/types/Core/Interfaces/IShapeDrawer.d.ts +2 -10
  89. package/types/Core/Particle.d.ts +6 -2
  90. package/types/Core/Particles.d.ts +10 -7
  91. package/types/Core/Retina.d.ts +0 -1
  92. package/types/Core/Utils/ExternalInteractorBase.d.ts +4 -4
  93. package/types/Core/Utils/InteractionManager.d.ts +1 -2
  94. package/types/Core/Utils/ParticlesInteractorBase.d.ts +5 -5
  95. package/types/Enums/Modes/LimitMode.d.ts +4 -0
  96. package/types/Enums/Types/EasingType.d.ts +3 -0
  97. package/types/Options/Classes/BackgroundMask/BackgroundMask.d.ts +1 -1
  98. package/types/Options/Classes/ColorAnimation.d.ts +2 -7
  99. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +1 -2
  100. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +1 -2
  101. package/types/Options/Classes/Interactivity/Events/Events.d.ts +3 -3
  102. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +2 -3
  103. package/types/Options/Classes/Interactivity/Interactivity.d.ts +2 -2
  104. package/types/Options/Classes/Options.d.ts +6 -6
  105. package/types/Options/Classes/Particles/Bounce/ParticlesBounce.d.ts +2 -2
  106. package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +3 -3
  107. package/types/Options/Classes/Particles/Effect/Effect.d.ts +13 -0
  108. package/types/Options/Classes/Particles/Move/Move.d.ts +8 -8
  109. package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +1 -1
  110. package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +3 -2
  111. package/types/Options/Classes/Particles/Number/ParticlesNumberLimit.d.ts +10 -0
  112. package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +3 -3
  113. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +12 -10
  114. package/types/Options/Classes/Particles/Size/Size.d.ts +3 -3
  115. package/types/Options/Classes/Theme/Theme.d.ts +1 -1
  116. package/types/Options/Classes/ValueWithRandom.d.ts +2 -4
  117. package/types/Options/Interfaces/IValueWithRandom.d.ts +0 -2
  118. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +1 -2
  119. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +1 -2
  120. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +1 -2
  121. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +8 -0
  122. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -0
  123. package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +2 -1
  124. package/types/Options/Interfaces/Particles/Number/IParticlesNumberLimit.d.ts +5 -0
  125. package/types/Utils/CanvasUtils.d.ts +2 -2
  126. package/types/Utils/NumberUtils.d.ts +0 -2
  127. package/types/Utils/Utils.d.ts +2 -3
  128. package/types/export-types.d.ts +5 -0
  129. package/types/exports.d.ts +2 -3
  130. package/umd/Core/Canvas.js +2 -2
  131. package/umd/Core/Container.js +36 -19
  132. package/umd/Core/Engine.js +18 -5
  133. package/umd/Core/Particle.js +74 -39
  134. package/umd/Core/Particles.js +51 -26
  135. package/umd/Core/Retina.js +0 -2
  136. package/umd/Core/Utils/QuadTree.js +1 -1
  137. package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  138. package/umd/Options/Classes/ColorAnimation.js +5 -25
  139. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  140. package/umd/Options/Classes/Particles/Effect/Effect.js +46 -0
  141. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +4 -6
  142. package/umd/Options/Classes/{Random.js → Particles/Number/ParticlesNumberLimit.js} +9 -9
  143. package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  144. package/umd/Options/Classes/Particles/ParticlesOptions.js +4 -1
  145. package/umd/Options/Classes/Particles/Size/Size.js +3 -4
  146. package/umd/Options/Classes/ValueWithRandom.js +2 -11
  147. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +12 -0
  148. package/umd/Utils/CanvasUtils.js +26 -21
  149. package/umd/Utils/ColorUtils.js +24 -38
  150. package/umd/Utils/NumberUtils.js +9 -19
  151. package/umd/Utils/Utils.js +6 -6
  152. package/umd/export-types.js +5 -1
  153. package/umd/exports.js +3 -4
  154. package/browser/Options/Classes/Random.js +0 -17
  155. package/cjs/Options/Classes/Random.js +0 -21
  156. package/esm/Options/Classes/Random.js +0 -17
  157. package/types/Enums/Modes/ClickMode.d.ts +0 -9
  158. package/types/Enums/Modes/DivMode.d.ts +0 -5
  159. package/types/Enums/Modes/HoverMode.d.ts +0 -11
  160. package/types/Options/Classes/Random.d.ts +0 -9
  161. package/types/Options/Interfaces/IRandom.d.ts +0 -4
  162. /package/browser/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  163. /package/browser/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  164. /package/browser/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  165. /package/browser/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  166. /package/{esm/Enums/Modes/ClickMode.js → browser/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js} +0 -0
  167. /package/cjs/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  168. /package/cjs/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  169. /package/cjs/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  170. /package/cjs/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  171. /package/esm/{Enums/Modes/DivMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  172. /package/esm/{Enums/Modes/HoverMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  173. /package/esm/{Options/Interfaces/IRandom.js → Enums/Modes/LimitMode.js} +0 -0
  174. /package/umd/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  175. /package/umd/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  176. /package/umd/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  177. /package/umd/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
@@ -2,26 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RangedAnimationValueWithRandom = exports.AnimationValueWithRandom = exports.ValueWithRandom = void 0;
4
4
  const AnimationOptions_js_1 = require("./AnimationOptions.js");
5
- const Random_js_1 = require("./Random.js");
6
- const Utils_js_1 = require("../../Utils/Utils.js");
7
5
  const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
8
6
  class ValueWithRandom {
9
7
  constructor() {
10
- this.random = new Random_js_1.Random();
11
8
  this.value = 0;
12
9
  }
13
10
  load(data) {
14
11
  if (!data) {
15
12
  return;
16
13
  }
17
- if ((0, Utils_js_1.isBoolean)(data.random)) {
18
- this.random.enable = data.random;
19
- }
20
- else {
21
- this.random.load(data.random);
22
- }
23
14
  if (data.value !== undefined) {
24
- this.value = (0, NumberUtils_js_1.setRangeValue)(data.value, this.random.enable ? this.random.minimumValue : undefined);
15
+ this.value = (0, NumberUtils_js_1.setRangeValue)(data.value);
25
16
  }
26
17
  }
27
18
  }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterEffect = exports.drawShape = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawTriangle = exports.drawLine = void 0;
3
+ exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterDraw = exports.drawShape = exports.drawEffect = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawLine = void 0;
4
4
  const ColorUtils_js_1 = require("./ColorUtils.js");
5
5
  function drawLine(context, begin, end) {
6
6
  context.beginPath();
@@ -9,14 +9,6 @@ function drawLine(context, begin, end) {
9
9
  context.closePath();
10
10
  }
11
11
  exports.drawLine = drawLine;
12
- function drawTriangle(context, p1, p2, p3) {
13
- context.beginPath();
14
- context.moveTo(p1.x, p1.y);
15
- context.lineTo(p2.x, p2.y);
16
- context.lineTo(p3.x, p3.y);
17
- context.closePath();
18
- }
19
- exports.drawTriangle = drawTriangle;
20
12
  function paintBase(context, dimension, baseColor) {
21
13
  context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
22
14
  context.fillRect(0, 0, dimension.width, dimension.height);
@@ -47,7 +39,6 @@ function drawParticle(data) {
47
39
  d: rotateData.cos * (transform.d ?? 1),
48
40
  };
49
41
  context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
50
- context.beginPath();
51
42
  if (backgroundMask) {
52
43
  context.globalCompositeOperation = composite;
53
44
  }
@@ -67,45 +58,59 @@ function drawParticle(data) {
67
58
  context.strokeStyle = colorStyles.stroke;
68
59
  }
69
60
  const drawData = { container, context, particle, radius, opacity, delta };
61
+ context.beginPath();
70
62
  drawShape(drawData);
63
+ if (particle.shapeClose) {
64
+ context.closePath();
65
+ }
71
66
  if (strokeWidth > 0) {
72
67
  context.stroke();
73
68
  }
74
- if (particle.close) {
75
- context.closePath();
76
- }
77
- if (particle.fill) {
69
+ if (particle.shapeFill) {
78
70
  context.fill();
79
71
  }
80
- drawShapeAfterEffect(drawData);
72
+ drawShapeAfterDraw(drawData);
73
+ drawEffect(drawData);
81
74
  context.globalCompositeOperation = "source-over";
82
75
  context.setTransform(1, 0, 0, 1, 0, 0);
83
76
  }
84
77
  exports.drawParticle = drawParticle;
78
+ function drawEffect(data) {
79
+ const { container, context, particle, radius, opacity, delta } = data;
80
+ if (!particle.effect) {
81
+ return;
82
+ }
83
+ const drawer = container.effectDrawers.get(particle.effect);
84
+ if (!drawer) {
85
+ return;
86
+ }
87
+ drawer.draw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
88
+ }
89
+ exports.drawEffect = drawEffect;
85
90
  function drawShape(data) {
86
91
  const { container, context, particle, radius, opacity, delta } = data;
87
92
  if (!particle.shape) {
88
93
  return;
89
94
  }
90
- const drawer = container.drawers.get(particle.shape);
95
+ const drawer = container.shapeDrawers.get(particle.shape);
91
96
  if (!drawer) {
92
97
  return;
93
98
  }
94
99
  drawer.draw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
95
100
  }
96
101
  exports.drawShape = drawShape;
97
- function drawShapeAfterEffect(data) {
102
+ function drawShapeAfterDraw(data) {
98
103
  const { container, context, particle, radius, opacity, delta } = data;
99
104
  if (!particle.shape) {
100
105
  return;
101
106
  }
102
- const drawer = container.drawers.get(particle.shape);
103
- if (!drawer || !drawer.afterEffect) {
107
+ const drawer = container.shapeDrawers.get(particle.shape);
108
+ if (!drawer || !drawer.afterDraw) {
104
109
  return;
105
110
  }
106
- drawer.afterEffect({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
111
+ drawer.afterDraw({ context, particle, radius, opacity, delta, pixelRatio: container.retina.pixelRatio });
107
112
  }
108
- exports.drawShapeAfterEffect = drawShapeAfterEffect;
113
+ exports.drawShapeAfterDraw = drawShapeAfterDraw;
109
114
  function drawPlugin(context, plugin, delta) {
110
115
  if (!plugin.draw) {
111
116
  return;
@@ -8,24 +8,6 @@ function addColorManager(manager) {
8
8
  colorManagers.set(manager.key, manager);
9
9
  }
10
10
  exports.addColorManager = addColorManager;
11
- function hue2rgb(p, q, t) {
12
- if (t < 0) {
13
- t += 1;
14
- }
15
- if (t > 1) {
16
- t -= 1;
17
- }
18
- if (t < 1 / 6) {
19
- return p + (q - p) * 6 * t;
20
- }
21
- if (t < 1 / 2) {
22
- return q;
23
- }
24
- if (t < 2 / 3) {
25
- return p + (q - p) * (2 / 3 - t) * 6;
26
- }
27
- return p;
28
- }
29
11
  function stringToRgba(input) {
30
12
  for (const [, manager] of colorManagers) {
31
13
  if (input.startsWith(manager.stringPrefix)) {
@@ -99,7 +81,7 @@ exports.rangeColorToHsl = rangeColorToHsl;
99
81
  function rgbToHsl(color) {
100
82
  const r1 = color.r / 255, g1 = color.g / 255, b1 = color.b / 255, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
101
83
  h: 0,
102
- l: (max + min) / 2,
84
+ l: (max + min) * 0.5,
103
85
  s: 0,
104
86
  };
105
87
  if (max !== min) {
@@ -130,26 +112,30 @@ function stringToRgb(input) {
130
112
  }
131
113
  exports.stringToRgb = stringToRgb;
132
114
  function hslToRgb(hsl) {
133
- const result = { b: 0, g: 0, r: 0 }, hslPercent = {
134
- h: hsl.h / 360,
135
- l: hsl.l / 100,
136
- s: hsl.s / 100,
137
- };
138
- if (!hslPercent.s) {
139
- result.r = result.g = result.b = hslPercent.l;
115
+ const h = ((hsl.h % 360) + 360) % 360, s = Math.max(0, Math.min(100, hsl.s)), l = Math.max(0, Math.min(100, hsl.l)), hNormalized = h / 360, sNormalized = s / 100, lNormalized = l / 100;
116
+ if (s === 0) {
117
+ const grayscaleValue = Math.round(lNormalized * 255);
118
+ return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
140
119
  }
141
- else {
142
- const q = hslPercent.l < 0.5
143
- ? hslPercent.l * (1 + hslPercent.s)
144
- : hslPercent.l + hslPercent.s - hslPercent.l * hslPercent.s, p = 2 * hslPercent.l - q;
145
- result.r = hue2rgb(p, q, hslPercent.h + 1 / 3);
146
- result.g = hue2rgb(p, q, hslPercent.h);
147
- result.b = hue2rgb(p, q, hslPercent.h - 1 / 3);
148
- }
149
- result.r = Math.floor(result.r * 255);
150
- result.g = Math.floor(result.g * 255);
151
- result.b = Math.floor(result.b * 255);
152
- return result;
120
+ const channel = (temp1, temp2, temp3) => {
121
+ if (temp3 < 0) {
122
+ temp3 += 1;
123
+ }
124
+ if (temp3 > 1) {
125
+ temp3 -= 1;
126
+ }
127
+ if (temp3 * 6 < 1) {
128
+ return temp1 + (temp2 - temp1) * 6 * temp3;
129
+ }
130
+ if (temp3 * 2 < 1) {
131
+ return temp2;
132
+ }
133
+ if (temp3 * 3 < 2) {
134
+ return temp1 + (temp2 - temp1) * (2 / 3 - temp3) * 6;
135
+ }
136
+ return temp1;
137
+ }, temp1 = lNormalized < 0.5 ? lNormalized * (1 + sNormalized) : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = 2 * lNormalized - temp1, red = Math.min(255, 255 * channel(temp2, temp1, hNormalized + 1 / 3)), green = Math.min(255, 255 * channel(temp2, temp1, hNormalized)), blue = Math.min(255, 255 * channel(temp2, temp1, hNormalized - 1 / 3));
138
+ return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
153
139
  }
154
140
  exports.hslToRgb = hslToRgb;
155
141
  function hslaToRgba(hsla) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAlpha = exports.calcExactPositionOrRandomFromSizeRanged = exports.calcExactPositionOrRandomFromSize = exports.calcPositionOrRandomFromSizeRanged = exports.calcPositionOrRandomFromSize = exports.calcPositionFromSize = exports.collisionVelocity = exports.getParticleBaseVelocity = exports.getParticleDirectionAngle = exports.getDistance = exports.getDistances = exports.getValue = exports.setRangeValue = exports.getRangeMax = exports.getRangeMin = exports.getRangeValue = exports.randomInRange = exports.mix = exports.clamp = exports.getRandom = exports.setRandom = exports.getEasing = exports.addEasing = void 0;
4
- const Utils_js_1 = require("./Utils.js");
3
+ exports.parseAlpha = exports.calcExactPositionOrRandomFromSizeRanged = exports.calcExactPositionOrRandomFromSize = exports.calcPositionOrRandomFromSizeRanged = exports.calcPositionOrRandomFromSize = exports.calcPositionFromSize = exports.collisionVelocity = exports.getParticleBaseVelocity = exports.getParticleDirectionAngle = exports.getDistance = exports.getDistances = exports.setRangeValue = exports.getRangeMax = exports.getRangeMin = exports.getRangeValue = exports.randomInRange = exports.mix = exports.clamp = exports.getRandom = exports.setRandom = exports.getEasing = exports.addEasing = void 0;
5
4
  const Vector_js_1 = require("../Core/Utils/Vector.js");
5
+ const Utils_js_1 = require("./Utils.js");
6
6
  let _random = Math.random;
7
7
  const easings = new Map();
8
8
  function addEasing(name, easing) {
@@ -66,16 +66,6 @@ function setRangeValue(source, value) {
66
66
  : setRangeValue(min, max);
67
67
  }
68
68
  exports.setRangeValue = setRangeValue;
69
- function getValue(options) {
70
- const random = options.random, { enable, minimumValue } = (0, Utils_js_1.isBoolean)(random)
71
- ? {
72
- enable: random,
73
- minimumValue: 0,
74
- }
75
- : random;
76
- return enable ? getRangeValue(setRangeValue(options.value, minimumValue)) : getRangeValue(options.value);
77
- }
78
- exports.getValue = getValue;
79
69
  function getDistances(pointA, pointB) {
80
70
  const dx = pointA.x - pointB.x, dy = pointA.y - pointB.y;
81
71
  return { dx: dx, dy: dy, distance: Math.sqrt(dx ** 2 + dy ** 2) };
@@ -91,21 +81,21 @@ function getParticleDirectionAngle(direction, position, center) {
91
81
  }
92
82
  switch (direction) {
93
83
  case "top":
94
- return -Math.PI / 2;
84
+ return -Math.PI * 0.5;
95
85
  case "top-right":
96
- return -Math.PI / 4;
86
+ return -Math.PI * 0.25;
97
87
  case "right":
98
88
  return 0;
99
89
  case "bottom-right":
100
- return Math.PI / 4;
90
+ return Math.PI * 0.25;
101
91
  case "bottom":
102
- return Math.PI / 2;
92
+ return Math.PI * 0.5;
103
93
  case "bottom-left":
104
- return (3 * Math.PI) / 4;
94
+ return Math.PI * 0.75;
105
95
  case "left":
106
96
  return Math.PI;
107
97
  case "top-left":
108
- return (-3 * Math.PI) / 4;
98
+ return -Math.PI * 0.75;
109
99
  case "inside":
110
100
  return Math.atan2(center.y - position.y, center.x - position.x);
111
101
  case "outside":
@@ -32,8 +32,8 @@ function rectSideBounce(data) {
32
32
  pOtherSide.max > rectOtherSide.max) {
33
33
  return res;
34
34
  }
35
- if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) / 2 && velocity > 0) ||
36
- (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) / 2 && velocity < 0)) {
35
+ if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * 0.5 && velocity > 0) ||
36
+ (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * 0.5 && velocity < 0)) {
37
37
  res.velocity = velocity * -factor;
38
38
  res.bounced = true;
39
39
  }
@@ -189,7 +189,7 @@ function circleBounceDataFromParticle(p) {
189
189
  radius: p.getRadius(),
190
190
  mass: p.getMass(),
191
191
  velocity: p.velocity,
192
- factor: Vector_js_1.Vector.create((0, NumberUtils_js_1.getValue)(p.options.bounce.horizontal), (0, NumberUtils_js_1.getValue)(p.options.bounce.vertical)),
192
+ factor: Vector_js_1.Vector.create((0, NumberUtils_js_1.getRangeValue)(p.options.bounce.horizontal.value), (0, NumberUtils_js_1.getRangeValue)(p.options.bounce.vertical.value)),
193
193
  };
194
194
  }
195
195
  exports.circleBounceDataFromParticle = circleBounceDataFromParticle;
@@ -206,7 +206,7 @@ function circleBounce(p1, p2) {
206
206
  }
207
207
  exports.circleBounce = circleBounce;
208
208
  function rectBounce(particle, divBounds) {
209
- const pPos = particle.getPosition(), size = particle.getRadius(), bounds = calculateBounds(pPos, size), resH = rectSideBounce({
209
+ const pPos = particle.getPosition(), size = particle.getRadius(), bounds = calculateBounds(pPos, size), bounceOptions = particle.options.bounce, resH = rectSideBounce({
210
210
  pSide: {
211
211
  min: bounds.left,
212
212
  max: bounds.right,
@@ -224,7 +224,7 @@ function rectBounce(particle, divBounds) {
224
224
  max: divBounds.bottom,
225
225
  },
226
226
  velocity: particle.velocity.x,
227
- factor: (0, NumberUtils_js_1.getValue)(particle.options.bounce.horizontal),
227
+ factor: (0, NumberUtils_js_1.getRangeValue)(bounceOptions.horizontal.value),
228
228
  });
229
229
  if (resH.bounced) {
230
230
  if (resH.velocity !== undefined) {
@@ -252,7 +252,7 @@ function rectBounce(particle, divBounds) {
252
252
  max: divBounds.right,
253
253
  },
254
254
  velocity: particle.velocity.y,
255
- factor: (0, NumberUtils_js_1.getValue)(particle.options.bounce.vertical),
255
+ factor: (0, NumberUtils_js_1.getRangeValue)(bounceOptions.vertical.value),
256
256
  });
257
257
  if (resV.bounced) {
258
258
  if (resV.velocity !== undefined) {
@@ -26,6 +26,7 @@ __exportStar(require("./Core/Interfaces/IDelta.js"), exports);
26
26
  __exportStar(require("./Core/Interfaces/IDimension.js"), exports);
27
27
  __exportStar(require("./Core/Interfaces/IDistance.js"), exports);
28
28
  __exportStar(require("./Core/Interfaces/IDrawParticleParams.js"), exports);
29
+ __exportStar(require("./Core/Interfaces/IEffectDrawer.js"), exports);
29
30
  __exportStar(require("./Core/Interfaces/IExternalInteractor.js"), exports);
30
31
  __exportStar(require("./Core/Interfaces/IInteractor.js"), exports);
31
32
  __exportStar(require("./Core/Interfaces/ILoadParams.js"), exports);
@@ -45,6 +46,7 @@ __exportStar(require("./Core/Interfaces/IPlugin.js"), exports);
45
46
  __exportStar(require("./Core/Interfaces/IPositionFromSizeParams.js"), exports);
46
47
  __exportStar(require("./Core/Interfaces/IRangeValue.js"), exports);
47
48
  __exportStar(require("./Core/Interfaces/IRectSideResult.js"), exports);
49
+ __exportStar(require("./Core/Interfaces/IShapeDrawData.js"), exports);
48
50
  __exportStar(require("./Core/Interfaces/IShapeDrawer.js"), exports);
49
51
  __exportStar(require("./Core/Interfaces/IShapeValues.js"), exports);
50
52
  __exportStar(require("./Core/Interfaces/ISlowParticleData.js"), exports);
@@ -77,6 +79,7 @@ __exportStar(require("./Options/Interfaces/Particles/Bounce/IParticlesBounce.js"
77
79
  __exportStar(require("./Options/Interfaces/Particles/Collisions/ICollisions.js"), exports);
78
80
  __exportStar(require("./Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js"), exports);
79
81
  __exportStar(require("./Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js"), exports);
82
+ __exportStar(require("./Options/Interfaces/Particles/Effect/IEffect.js"), exports);
80
83
  __exportStar(require("./Options/Interfaces/Particles/IParticlesOptions.js"), exports);
81
84
  __exportStar(require("./Options/Interfaces/Particles/IShadow.js"), exports);
82
85
  __exportStar(require("./Options/Interfaces/Particles/IStroke.js"), exports);
@@ -91,6 +94,7 @@ __exportStar(require("./Options/Interfaces/Particles/Move/ISpin.js"), exports);
91
94
  __exportStar(require("./Options/Interfaces/Particles/Move/IMoveTrail.js"), exports);
92
95
  __exportStar(require("./Options/Interfaces/Particles/Number/IParticlesDensity.js"), exports);
93
96
  __exportStar(require("./Options/Interfaces/Particles/Number/IParticlesNumber.js"), exports);
97
+ __exportStar(require("./Options/Interfaces/Particles/Number/IParticlesNumberLimit.js"), exports);
94
98
  __exportStar(require("./Options/Interfaces/Particles/Opacity/IOpacity.js"), exports);
95
99
  __exportStar(require("./Options/Interfaces/Particles/Opacity/IOpacityAnimation.js"), exports);
96
100
  __exportStar(require("./Options/Interfaces/Particles/Shape/IShape.js"), exports);
package/cjs/exports.js CHANGED
@@ -27,10 +27,8 @@ __exportStar(require("./Enums/Directions/MoveDirection.js"), exports);
27
27
  __exportStar(require("./Enums/Directions/RotateDirection.js"), exports);
28
28
  __exportStar(require("./Enums/Directions/OutModeDirection.js"), exports);
29
29
  __exportStar(require("./Enums/Modes/AnimationMode.js"), exports);
30
- __exportStar(require("./Enums/Modes/ClickMode.js"), exports);
31
- __exportStar(require("./Enums/Modes/DivMode.js"), exports);
32
- __exportStar(require("./Enums/Modes/HoverMode.js"), exports);
33
30
  __exportStar(require("./Enums/Modes/CollisionMode.js"), exports);
31
+ __exportStar(require("./Enums/Modes/LimitMode.js"), exports);
34
32
  __exportStar(require("./Enums/Modes/OutMode.js"), exports);
35
33
  __exportStar(require("./Enums/Modes/PixelMode.js"), exports);
36
34
  __exportStar(require("./Enums/Modes/ThemeMode.js"), exports);
@@ -85,6 +83,7 @@ __exportStar(require("./Options/Classes/Particles/Move/Path/MovePath.js"), expor
85
83
  __exportStar(require("./Options/Classes/Particles/Move/Spin.js"), exports);
86
84
  __exportStar(require("./Options/Classes/Particles/Move/MoveTrail.js"), exports);
87
85
  __exportStar(require("./Options/Classes/Particles/Number/ParticlesNumber.js"), exports);
86
+ __exportStar(require("./Options/Classes/Particles/Number/ParticlesNumberLimit.js"), exports);
88
87
  __exportStar(require("./Options/Classes/Particles/Number/ParticlesDensity.js"), exports);
89
88
  __exportStar(require("./Options/Classes/Particles/Opacity/Opacity.js"), exports);
90
89
  __exportStar(require("./Options/Classes/Particles/Opacity/OpacityAnimation.js"), exports);
@@ -402,10 +402,10 @@ export class Canvas {
402
402
  this.element.width = size.width = this.element.offsetWidth * pxRatio;
403
403
  this.element.height = size.height = this.element.offsetHeight * pxRatio;
404
404
  if (this.container.started) {
405
- this.resizeFactor = {
405
+ container.particles.setResizeFactor({
406
406
  width: size.width / oldSize.width,
407
407
  height: size.height / oldSize.height,
408
- };
408
+ });
409
409
  }
410
410
  return true;
411
411
  }
@@ -36,16 +36,16 @@ export class Container {
36
36
  };
37
37
  this._nextFrame = async (timestamp) => {
38
38
  try {
39
- if (!this.smooth &&
40
- this.lastFrameTime !== undefined &&
41
- timestamp < this.lastFrameTime + 1000 / this.fpsLimit) {
39
+ if (!this._smooth &&
40
+ this._lastFrameTime !== undefined &&
41
+ timestamp < this._lastFrameTime + 1000 / this.fpsLimit) {
42
42
  this.draw(false);
43
43
  return;
44
44
  }
45
- this.lastFrameTime ??= timestamp;
46
- const delta = initDelta(timestamp - this.lastFrameTime, this.fpsLimit, this.smooth);
45
+ this._lastFrameTime ??= timestamp;
46
+ const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
47
47
  this.addLifeTime(delta.value);
48
- this.lastFrameTime = timestamp;
48
+ this._lastFrameTime = timestamp;
49
49
  if (delta.value > 1000) {
50
50
  this.draw(false);
51
51
  return;
@@ -66,7 +66,7 @@ export class Container {
66
66
  this._engine = engine;
67
67
  this.id = Symbol(id);
68
68
  this.fpsLimit = 120;
69
- this.smooth = false;
69
+ this._smooth = false;
70
70
  this._delay = 0;
71
71
  this._duration = 0;
72
72
  this._lifeTime = 0;
@@ -74,7 +74,7 @@ export class Container {
74
74
  this.started = false;
75
75
  this.destroyed = false;
76
76
  this._paused = true;
77
- this.lastFrameTime = 0;
77
+ this._lastFrameTime = 0;
78
78
  this.zLayers = 100;
79
79
  this.pageHidden = false;
80
80
  this._sourceOptions = sourceOptions;
@@ -90,7 +90,8 @@ export class Container {
90
90
  },
91
91
  };
92
92
  this.plugins = new Map();
93
- this.drawers = new Map();
93
+ this.effectDrawers = new Map();
94
+ this.shapeDrawers = new Map();
94
95
  this._options = loadContainerOptions(this._engine, this);
95
96
  this.actualOptions = loadContainerOptions(this._engine, this);
96
97
  this._eventListeners = new EventListeners(this);
@@ -200,11 +201,17 @@ export class Container {
200
201
  this.stop();
201
202
  this.particles.destroy();
202
203
  this.canvas.destroy();
203
- for (const [, drawer] of this.drawers) {
204
- drawer.destroy && drawer.destroy(this);
204
+ for (const [, effectDrawer] of this.effectDrawers) {
205
+ effectDrawer.destroy && effectDrawer.destroy(this);
205
206
  }
206
- for (const key of this.drawers.keys()) {
207
- this.drawers.delete(key);
207
+ for (const [, shapeDrawer] of this.shapeDrawers) {
208
+ shapeDrawer.destroy && shapeDrawer.destroy(this);
209
+ }
210
+ for (const key of this.effectDrawers.keys()) {
211
+ this.effectDrawers.delete(key);
212
+ }
213
+ for (const key of this.shapeDrawers.keys()) {
214
+ this.shapeDrawers.delete(key);
208
215
  }
209
216
  this._engine.clearPlugins(this);
210
217
  this.destroyed = true;
@@ -221,7 +228,7 @@ export class Container {
221
228
  let refreshTime = force;
222
229
  this._drawAnimationFrame = requestAnimationFrame(async (timestamp) => {
223
230
  if (refreshTime) {
224
- this.lastFrameTime = undefined;
231
+ this._lastFrameTime = undefined;
225
232
  refreshTime = false;
226
233
  }
227
234
  await this._nextFrame(timestamp);
@@ -256,11 +263,18 @@ export class Container {
256
263
  if (!guardCheck(this)) {
257
264
  return;
258
265
  }
266
+ const effects = this._engine.getSupportedEffects();
267
+ for (const type of effects) {
268
+ const drawer = this._engine.getEffectDrawer(type);
269
+ if (drawer) {
270
+ this.effectDrawers.set(type, drawer);
271
+ }
272
+ }
259
273
  const shapes = this._engine.getSupportedShapes();
260
274
  for (const type of shapes) {
261
275
  const drawer = this._engine.getShapeDrawer(type);
262
276
  if (drawer) {
263
- this.drawers.set(type, drawer);
277
+ this.shapeDrawers.set(type, drawer);
264
278
  }
265
279
  }
266
280
  this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
@@ -279,8 +293,11 @@ export class Container {
279
293
  this._delay = getRangeValue(this.actualOptions.delay) * 1000;
280
294
  this._lifeTime = 0;
281
295
  this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
282
- this.smooth = this.actualOptions.smooth;
283
- for (const [, drawer] of this.drawers) {
296
+ this._smooth = this.actualOptions.smooth;
297
+ for (const [, drawer] of this.effectDrawers) {
298
+ drawer.init && (await drawer.init(this));
299
+ }
300
+ for (const [, drawer] of this.shapeDrawers) {
284
301
  drawer.init && (await drawer.init(this));
285
302
  }
286
303
  for (const [, plugin] of this.plugins) {
@@ -409,10 +426,10 @@ export class Container {
409
426
  this.actualOptions.responsive = [];
410
427
  const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
411
428
  this.actualOptions.setTheme(this._currentTheme);
412
- if (this.responsiveMaxWidth === newMaxWidth) {
429
+ if (this._responsiveMaxWidth === newMaxWidth) {
413
430
  return false;
414
431
  }
415
- this.responsiveMaxWidth = newMaxWidth;
432
+ this._responsiveMaxWidth = newMaxWidth;
416
433
  return true;
417
434
  }
418
435
  }
@@ -39,7 +39,8 @@ export class Engine {
39
39
  this.movers = new Map();
40
40
  this.updaters = new Map();
41
41
  this.presets = new Map();
42
- this.drawers = new Map();
42
+ this.effectDrawers = new Map();
43
+ this.shapeDrawers = new Map();
43
44
  this.pathGenerators = new Map();
44
45
  }
45
46
  get configs() {
@@ -50,13 +51,19 @@ export class Engine {
50
51
  return res;
51
52
  }
52
53
  get version() {
53
- return "3.0.0-beta.3";
54
+ return "3.0.0-beta.4";
54
55
  }
55
56
  addConfig(config) {
56
57
  const name = config.name ?? "default";
57
58
  this._configs.set(name, config);
58
59
  this._eventDispatcher.dispatchEvent("configAdded", { data: { name, config } });
59
60
  }
61
+ async addEffect(effect, drawer, refresh = true) {
62
+ executeOnSingleOrMultiple(effect, (type) => {
63
+ !this.getEffectDrawer(type) && this.effectDrawers.set(type, drawer);
64
+ });
65
+ await this.refresh(refresh);
66
+ }
60
67
  addEventListener(type, listener) {
61
68
  this._eventDispatcher.addEventListener(type, listener);
62
69
  }
@@ -86,7 +93,7 @@ export class Engine {
86
93
  }
87
94
  async addShape(shape, drawer, refresh = true) {
88
95
  executeOnSingleOrMultiple(shape, (type) => {
89
- !this.getShapeDrawer(type) && this.drawers.set(type, drawer);
96
+ !this.getShapeDrawer(type) && this.shapeDrawers.set(type, drawer);
90
97
  });
91
98
  await this.refresh(refresh);
92
99
  }
@@ -116,6 +123,9 @@ export class Engine {
116
123
  }
117
124
  return res;
118
125
  }
126
+ getEffectDrawer(type) {
127
+ return this.effectDrawers.get(type);
128
+ }
119
129
  getInteractors(container, force = false) {
120
130
  return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
121
131
  }
@@ -132,10 +142,13 @@ export class Engine {
132
142
  return this.presets.get(preset);
133
143
  }
134
144
  getShapeDrawer(type) {
135
- return this.drawers.get(type);
145
+ return this.shapeDrawers.get(type);
146
+ }
147
+ getSupportedEffects() {
148
+ return this.effectDrawers.keys();
136
149
  }
137
150
  getSupportedShapes() {
138
- return this.drawers.keys();
151
+ return this.shapeDrawers.keys();
139
152
  }
140
153
  getUpdaters(container, force = false) {
141
154
  return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);