@tsparticles/engine 3.2.2 → 3.4.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 (281) hide show
  1. package/README.md +0 -4
  2. package/browser/Core/Canvas.js +34 -29
  3. package/browser/Core/Container.js +60 -47
  4. package/browser/Core/Engine.js +82 -74
  5. package/browser/Core/Particle.js +40 -26
  6. package/browser/Core/Particles.js +51 -52
  7. package/browser/Core/Utils/EventListeners.js +18 -17
  8. package/browser/Core/Utils/ExternalInteractorBase.js +2 -1
  9. package/browser/Core/Utils/InteractionManager.js +7 -6
  10. package/browser/Core/Utils/ParticlesInteractorBase.js +2 -1
  11. package/browser/Core/Utils/QuadTree.js +1 -1
  12. package/browser/Core/Utils/Ranges.js +5 -4
  13. package/browser/Enums/AnimationStatus.js +5 -1
  14. package/browser/Enums/Directions/MoveDirection.js +14 -1
  15. package/browser/Enums/Directions/OutModeDirection.js +7 -1
  16. package/browser/Enums/Directions/RotateDirection.js +6 -1
  17. package/browser/Enums/InteractivityDetect.js +6 -1
  18. package/browser/Enums/Modes/AnimationMode.js +7 -1
  19. package/browser/Enums/Modes/CollisionMode.js +6 -1
  20. package/browser/Enums/Modes/LimitMode.js +5 -1
  21. package/browser/Enums/Modes/OutMode.js +8 -1
  22. package/browser/Enums/Modes/PixelMode.js +5 -1
  23. package/browser/Enums/Modes/ResponsiveMode.js +5 -1
  24. package/browser/Enums/Modes/ThemeMode.js +6 -1
  25. package/browser/Enums/Types/AlterType.js +5 -1
  26. package/browser/Enums/Types/DestroyType.js +6 -1
  27. package/browser/Enums/Types/DivType.js +5 -1
  28. package/browser/Enums/Types/EasingType.js +30 -1
  29. package/browser/Enums/Types/EventType.js +15 -1
  30. package/browser/Enums/Types/GradientType.js +6 -1
  31. package/browser/Enums/Types/InteractorType.js +5 -1
  32. package/browser/Enums/Types/ParticleOutType.js +6 -1
  33. package/browser/Enums/Types/StartValueType.js +6 -1
  34. package/browser/Options/Classes/AnimationOptions.js +4 -2
  35. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  36. package/browser/Options/Classes/Interactivity/Events/Events.js +1 -1
  37. package/browser/Options/Classes/Interactivity/Interactivity.js +2 -1
  38. package/browser/Options/Classes/ManualParticle.js +2 -1
  39. package/browser/Options/Classes/Options.js +14 -12
  40. package/browser/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  41. package/browser/Options/Classes/Particles/Move/Move.js +2 -1
  42. package/browser/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  43. package/browser/Options/Classes/Particles/Move/OutModes.js +2 -1
  44. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  45. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  46. package/browser/Options/Classes/Particles/ParticlesOptions.js +1 -1
  47. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  48. package/browser/Options/Classes/Responsive.js +5 -4
  49. package/browser/Options/Classes/Theme/ThemeDefault.js +2 -1
  50. package/browser/Types/RangeType.js +5 -1
  51. package/browser/Utils/CanvasUtils.js +27 -21
  52. package/browser/Utils/ColorUtils.js +17 -9
  53. package/browser/Utils/EventDispatcher.js +1 -1
  54. package/browser/Utils/HslColorManager.js +11 -4
  55. package/browser/Utils/NumberUtils.js +11 -10
  56. package/browser/Utils/RgbColorManager.js +11 -4
  57. package/browser/Utils/Utils.js +37 -31
  58. package/cjs/Core/Canvas.js +34 -29
  59. package/cjs/Core/Container.js +60 -47
  60. package/cjs/Core/Engine.js +82 -97
  61. package/cjs/Core/Particle.js +40 -26
  62. package/cjs/Core/Particles.js +52 -76
  63. package/cjs/Core/Utils/EventListeners.js +18 -17
  64. package/cjs/Core/Utils/ExternalInteractorBase.js +2 -1
  65. package/cjs/Core/Utils/InteractionManager.js +7 -6
  66. package/cjs/Core/Utils/ParticlesInteractorBase.js +2 -1
  67. package/cjs/Core/Utils/QuadTree.js +1 -1
  68. package/cjs/Core/Utils/Ranges.js +5 -4
  69. package/cjs/Enums/AnimationStatus.js +6 -0
  70. package/cjs/Enums/Directions/MoveDirection.js +15 -0
  71. package/cjs/Enums/Directions/OutModeDirection.js +8 -0
  72. package/cjs/Enums/Directions/RotateDirection.js +7 -0
  73. package/cjs/Enums/InteractivityDetect.js +7 -0
  74. package/cjs/Enums/Modes/AnimationMode.js +8 -0
  75. package/cjs/Enums/Modes/CollisionMode.js +7 -0
  76. package/cjs/Enums/Modes/LimitMode.js +6 -0
  77. package/cjs/Enums/Modes/OutMode.js +9 -0
  78. package/cjs/Enums/Modes/PixelMode.js +6 -0
  79. package/cjs/Enums/Modes/ResponsiveMode.js +6 -0
  80. package/cjs/Enums/Modes/ThemeMode.js +7 -0
  81. package/cjs/Enums/Types/AlterType.js +6 -0
  82. package/cjs/Enums/Types/DestroyType.js +7 -0
  83. package/cjs/Enums/Types/DivType.js +6 -0
  84. package/cjs/Enums/Types/EasingType.js +31 -0
  85. package/cjs/Enums/Types/EventType.js +16 -0
  86. package/cjs/Enums/Types/GradientType.js +7 -0
  87. package/cjs/Enums/Types/InteractorType.js +6 -0
  88. package/cjs/Enums/Types/ParticleOutType.js +7 -0
  89. package/cjs/Enums/Types/StartValueType.js +7 -0
  90. package/cjs/Options/Classes/AnimationOptions.js +4 -2
  91. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  92. package/cjs/Options/Classes/Interactivity/Events/Events.js +1 -1
  93. package/cjs/Options/Classes/Interactivity/Interactivity.js +2 -1
  94. package/cjs/Options/Classes/ManualParticle.js +2 -1
  95. package/cjs/Options/Classes/Options.js +14 -12
  96. package/cjs/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  97. package/cjs/Options/Classes/Particles/Move/Move.js +2 -1
  98. package/cjs/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  99. package/cjs/Options/Classes/Particles/Move/OutModes.js +2 -1
  100. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  101. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  102. package/cjs/Options/Classes/Particles/ParticlesOptions.js +1 -1
  103. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  104. package/cjs/Options/Classes/Responsive.js +5 -4
  105. package/cjs/Options/Classes/Theme/ThemeDefault.js +2 -1
  106. package/cjs/Types/RangeType.js +6 -0
  107. package/cjs/Utils/CanvasUtils.js +27 -21
  108. package/cjs/Utils/ColorUtils.js +17 -9
  109. package/cjs/Utils/EventDispatcher.js +1 -1
  110. package/cjs/Utils/HslColorManager.js +11 -4
  111. package/cjs/Utils/NumberUtils.js +11 -10
  112. package/cjs/Utils/RgbColorManager.js +11 -4
  113. package/cjs/Utils/Utils.js +37 -31
  114. package/esm/Core/Canvas.js +34 -29
  115. package/esm/Core/Container.js +60 -47
  116. package/esm/Core/Engine.js +82 -74
  117. package/esm/Core/Particle.js +40 -26
  118. package/esm/Core/Particles.js +51 -52
  119. package/esm/Core/Utils/EventListeners.js +18 -17
  120. package/esm/Core/Utils/ExternalInteractorBase.js +2 -1
  121. package/esm/Core/Utils/InteractionManager.js +7 -6
  122. package/esm/Core/Utils/ParticlesInteractorBase.js +2 -1
  123. package/esm/Core/Utils/QuadTree.js +1 -1
  124. package/esm/Core/Utils/Ranges.js +5 -4
  125. package/esm/Enums/AnimationStatus.js +5 -1
  126. package/esm/Enums/Directions/MoveDirection.js +14 -1
  127. package/esm/Enums/Directions/OutModeDirection.js +7 -1
  128. package/esm/Enums/Directions/RotateDirection.js +6 -1
  129. package/esm/Enums/InteractivityDetect.js +6 -1
  130. package/esm/Enums/Modes/AnimationMode.js +7 -1
  131. package/esm/Enums/Modes/CollisionMode.js +6 -1
  132. package/esm/Enums/Modes/LimitMode.js +5 -1
  133. package/esm/Enums/Modes/OutMode.js +8 -1
  134. package/esm/Enums/Modes/PixelMode.js +5 -1
  135. package/esm/Enums/Modes/ResponsiveMode.js +5 -1
  136. package/esm/Enums/Modes/ThemeMode.js +6 -1
  137. package/esm/Enums/Types/AlterType.js +5 -1
  138. package/esm/Enums/Types/DestroyType.js +6 -1
  139. package/esm/Enums/Types/DivType.js +5 -1
  140. package/esm/Enums/Types/EasingType.js +30 -1
  141. package/esm/Enums/Types/EventType.js +15 -1
  142. package/esm/Enums/Types/GradientType.js +6 -1
  143. package/esm/Enums/Types/InteractorType.js +5 -1
  144. package/esm/Enums/Types/ParticleOutType.js +6 -1
  145. package/esm/Enums/Types/StartValueType.js +6 -1
  146. package/esm/Options/Classes/AnimationOptions.js +4 -2
  147. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  148. package/esm/Options/Classes/Interactivity/Events/Events.js +1 -1
  149. package/esm/Options/Classes/Interactivity/Interactivity.js +2 -1
  150. package/esm/Options/Classes/ManualParticle.js +2 -1
  151. package/esm/Options/Classes/Options.js +14 -12
  152. package/esm/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  153. package/esm/Options/Classes/Particles/Move/Move.js +2 -1
  154. package/esm/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  155. package/esm/Options/Classes/Particles/Move/OutModes.js +2 -1
  156. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  157. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  158. package/esm/Options/Classes/Particles/ParticlesOptions.js +1 -1
  159. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  160. package/esm/Options/Classes/Responsive.js +5 -4
  161. package/esm/Options/Classes/Theme/ThemeDefault.js +2 -1
  162. package/esm/Types/RangeType.js +5 -1
  163. package/esm/Utils/CanvasUtils.js +27 -21
  164. package/esm/Utils/ColorUtils.js +17 -9
  165. package/esm/Utils/EventDispatcher.js +1 -1
  166. package/esm/Utils/HslColorManager.js +11 -4
  167. package/esm/Utils/NumberUtils.js +11 -10
  168. package/esm/Utils/RgbColorManager.js +11 -4
  169. package/esm/Utils/Utils.js +37 -31
  170. package/package.json +1 -1
  171. package/report.html +1 -1
  172. package/tsparticles.engine.js +327 -225
  173. package/tsparticles.engine.min.js +1 -1
  174. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  175. package/types/Core/Canvas.d.ts +4 -4
  176. package/types/Core/Container.d.ts +4 -2
  177. package/types/Core/Engine.d.ts +6 -5
  178. package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -4
  179. package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
  180. package/types/Core/Interfaces/IExternalInteractor.d.ts +1 -1
  181. package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
  182. package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
  183. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
  184. package/types/Core/Interfaces/IParticlesInteractor.d.ts +1 -1
  185. package/types/Core/Interfaces/IPlugin.d.ts +3 -4
  186. package/types/Core/Interfaces/IShapeDrawer.d.ts +5 -4
  187. package/types/Core/Particle.d.ts +3 -2
  188. package/types/Core/Particles.d.ts +7 -7
  189. package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
  190. package/types/Core/Utils/InteractionManager.d.ts +2 -2
  191. package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
  192. package/types/Enums/AnimationStatus.d.ts +1 -1
  193. package/types/Enums/Directions/MoveDirection.d.ts +1 -1
  194. package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
  195. package/types/Enums/Directions/RotateDirection.d.ts +1 -1
  196. package/types/Enums/InteractivityDetect.d.ts +1 -1
  197. package/types/Enums/Modes/AnimationMode.d.ts +1 -1
  198. package/types/Enums/Modes/CollisionMode.d.ts +1 -1
  199. package/types/Enums/Modes/LimitMode.d.ts +1 -1
  200. package/types/Enums/Modes/OutMode.d.ts +1 -1
  201. package/types/Enums/Modes/PixelMode.d.ts +1 -1
  202. package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
  203. package/types/Enums/Modes/ThemeMode.d.ts +1 -1
  204. package/types/Enums/Types/AlterType.d.ts +1 -1
  205. package/types/Enums/Types/DestroyType.d.ts +1 -1
  206. package/types/Enums/Types/DivType.d.ts +1 -1
  207. package/types/Enums/Types/EasingType.d.ts +1 -1
  208. package/types/Enums/Types/EventType.d.ts +1 -1
  209. package/types/Enums/Types/GradientType.d.ts +1 -1
  210. package/types/Enums/Types/InteractorType.d.ts +1 -1
  211. package/types/Enums/Types/ParticleOutType.d.ts +1 -1
  212. package/types/Enums/Types/StartValueType.d.ts +1 -1
  213. package/types/Options/Classes/Options.d.ts +2 -1
  214. package/types/Options/Classes/Responsive.d.ts +2 -2
  215. package/types/Options/Classes/Theme/Theme.d.ts +2 -2
  216. package/types/Options/Interfaces/IResponsive.d.ts +2 -3
  217. package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
  218. package/types/Types/RangeType.d.ts +1 -1
  219. package/types/Utils/CanvasUtils.d.ts +6 -6
  220. package/umd/Core/Canvas.js +34 -29
  221. package/umd/Core/Container.js +61 -48
  222. package/umd/Core/Engine.js +83 -99
  223. package/umd/Core/Particle.js +41 -27
  224. package/umd/Core/Particles.js +53 -78
  225. package/umd/Core/Utils/EventListeners.js +19 -18
  226. package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
  227. package/umd/Core/Utils/InteractionManager.js +8 -7
  228. package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
  229. package/umd/Core/Utils/QuadTree.js +1 -1
  230. package/umd/Core/Utils/Ranges.js +6 -5
  231. package/umd/Enums/AnimationStatus.js +6 -0
  232. package/umd/Enums/Directions/MoveDirection.js +15 -0
  233. package/umd/Enums/Directions/OutModeDirection.js +8 -0
  234. package/umd/Enums/Directions/RotateDirection.js +7 -0
  235. package/umd/Enums/InteractivityDetect.js +7 -0
  236. package/umd/Enums/Modes/AnimationMode.js +8 -0
  237. package/umd/Enums/Modes/CollisionMode.js +7 -0
  238. package/umd/Enums/Modes/LimitMode.js +6 -0
  239. package/umd/Enums/Modes/OutMode.js +9 -0
  240. package/umd/Enums/Modes/PixelMode.js +6 -0
  241. package/umd/Enums/Modes/ResponsiveMode.js +6 -0
  242. package/umd/Enums/Modes/ThemeMode.js +7 -0
  243. package/umd/Enums/Types/AlterType.js +6 -0
  244. package/umd/Enums/Types/DestroyType.js +7 -0
  245. package/umd/Enums/Types/DivType.js +6 -0
  246. package/umd/Enums/Types/EasingType.js +31 -0
  247. package/umd/Enums/Types/EventType.js +16 -0
  248. package/umd/Enums/Types/GradientType.js +7 -0
  249. package/umd/Enums/Types/InteractorType.js +6 -0
  250. package/umd/Enums/Types/ParticleOutType.js +7 -0
  251. package/umd/Enums/Types/StartValueType.js +7 -0
  252. package/umd/Options/Classes/AnimationOptions.js +5 -3
  253. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
  254. package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
  255. package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
  256. package/umd/Options/Classes/ManualParticle.js +3 -2
  257. package/umd/Options/Classes/Options.js +15 -13
  258. package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
  259. package/umd/Options/Classes/Particles/Move/Move.js +3 -2
  260. package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
  261. package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
  262. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
  263. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
  264. package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
  265. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
  266. package/umd/Options/Classes/Responsive.js +6 -5
  267. package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
  268. package/umd/Types/RangeType.js +6 -0
  269. package/umd/Utils/CanvasUtils.js +28 -22
  270. package/umd/Utils/ColorUtils.js +18 -10
  271. package/umd/Utils/EventDispatcher.js +1 -1
  272. package/umd/Utils/HslColorManager.js +11 -4
  273. package/umd/Utils/NumberUtils.js +12 -11
  274. package/umd/Utils/RgbColorManager.js +11 -4
  275. package/umd/Utils/Utils.js +38 -32
  276. package/373.min.js +0 -2
  277. package/373.min.js.LICENSE.txt +0 -1
  278. package/438.min.js +0 -2
  279. package/438.min.js.LICENSE.txt +0 -1
  280. package/dist_browser_Core_Container_js.js +0 -92
  281. package/dist_browser_Core_Particle_js.js +0 -32
package/README.md CHANGED
@@ -969,10 +969,6 @@ flowchart TD
969
969
 
970
970
  ## Sponsors
971
971
 
972
- ### ScribbleMaps
973
-
974
- Huge thanks to [ScribbleMaps](https://www.scribblemaps.com/) for their support on this project.
975
-
976
972
  ### JetBrains
977
973
 
978
974
  Huge thanks to [JetBrains](https://www.jetbrains.com/?from=tsParticles) for the 2020-2022 Open Source Licenses!
@@ -31,7 +31,7 @@ function setStyle(canvas, style, important = false) {
31
31
  export class Canvas {
32
32
  constructor(container) {
33
33
  this.container = container;
34
- this._applyPostDrawUpdaters = (particle) => {
34
+ this._applyPostDrawUpdaters = particle => {
35
35
  for (const updater of this._postDrawUpdaters) {
36
36
  updater.afterDraw?.(particle);
37
37
  }
@@ -61,7 +61,7 @@ export class Canvas {
61
61
  plugin.resize?.();
62
62
  }
63
63
  };
64
- this._getPluginParticleColors = (particle) => {
64
+ this._getPluginParticleColors = particle => {
65
65
  let fColor, sColor;
66
66
  for (const plugin of this._colorPlugins) {
67
67
  if (!fColor && plugin.particleFillColor) {
@@ -101,7 +101,7 @@ export class Canvas {
101
101
  };
102
102
  resolve();
103
103
  });
104
- img.addEventListener("error", (evt) => {
104
+ img.addEventListener("error", evt => {
105
105
  reject(evt.error);
106
106
  });
107
107
  img.src = cover.image;
@@ -162,28 +162,33 @@ export class Canvas {
162
162
  };
163
163
  resolve();
164
164
  });
165
- img.addEventListener("error", (evt) => {
165
+ img.addEventListener("error", evt => {
166
166
  reject(evt.error);
167
167
  });
168
168
  img.src = trailFill.image;
169
169
  });
170
170
  }
171
171
  };
172
- this._paintBase = (baseColor) => {
173
- this.draw((ctx) => paintBase(ctx, this.size, baseColor));
172
+ this._paintBase = baseColor => {
173
+ this.draw(ctx => paintBase(ctx, this.size, baseColor));
174
174
  };
175
175
  this._paintImage = (image, opacity) => {
176
- this.draw((ctx) => paintImage(ctx, this.size, image, opacity));
176
+ this.draw(ctx => paintImage(ctx, this.size, image, opacity));
177
177
  };
178
178
  this._repairStyle = () => {
179
179
  const element = this.element;
180
180
  if (!element) {
181
181
  return;
182
182
  }
183
- this._safeMutationObserver((observer) => observer.disconnect());
183
+ this._safeMutationObserver(observer => observer.disconnect());
184
184
  this._initStyle();
185
185
  this.initBackground();
186
- this._safeMutationObserver((observer) => observer.observe(element, { attributes: true }));
186
+ this._safeMutationObserver(observer => {
187
+ if (!element || !(element instanceof Node)) {
188
+ return;
189
+ }
190
+ observer.observe(element, { attributes: true });
191
+ });
187
192
  };
188
193
  this._resetOriginalStyle = () => {
189
194
  const element = this.element, originalStyle = this._originalStyle;
@@ -192,7 +197,7 @@ export class Canvas {
192
197
  }
193
198
  setStyle(element, originalStyle);
194
199
  };
195
- this._safeMutationObserver = (callback) => {
200
+ this._safeMutationObserver = callback => {
196
201
  if (!this._mutationObserver) {
197
202
  return;
198
203
  }
@@ -241,7 +246,7 @@ export class Canvas {
241
246
  }
242
247
  }
243
248
  else if (options.clear) {
244
- this.draw((ctx) => {
249
+ this.draw(ctx => {
245
250
  clear(ctx, this.size);
246
251
  });
247
252
  }
@@ -270,11 +275,11 @@ export class Canvas {
270
275
  drawAsync(cb) {
271
276
  const ctx = this._context;
272
277
  if (!ctx) {
273
- return Promise.resolve(undefined);
278
+ return undefined;
274
279
  }
275
280
  return cb(ctx);
276
281
  }
277
- async drawParticle(particle, delta) {
282
+ drawParticle(particle, delta) {
278
283
  if (particle.spawning || particle.destroyed) {
279
284
  return;
280
285
  }
@@ -293,13 +298,13 @@ export class Canvas {
293
298
  if (!fColor && !sColor) {
294
299
  return;
295
300
  }
296
- await this.drawAsync(async (ctx) => {
301
+ this.draw((ctx) => {
297
302
  const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
298
303
  fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
299
304
  };
300
305
  colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
301
306
  this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
302
- await drawParticle({
307
+ drawParticle({
303
308
  container,
304
309
  context: ctx,
305
310
  particle,
@@ -315,15 +320,15 @@ export class Canvas {
315
320
  this._applyPostDrawUpdaters(particle);
316
321
  });
317
322
  }
318
- async drawParticlePlugin(plugin, particle, delta) {
319
- await this.drawAsync((ctx) => drawParticlePlugin(ctx, plugin, particle, delta));
323
+ drawParticlePlugin(plugin, particle, delta) {
324
+ this.draw(ctx => drawParticlePlugin(ctx, plugin, particle, delta));
320
325
  }
321
- async drawPlugin(plugin, delta) {
322
- await this.drawAsync((ctx) => drawPlugin(ctx, plugin, delta));
326
+ drawPlugin(plugin, delta) {
327
+ this.draw(ctx => drawPlugin(ctx, plugin, delta));
323
328
  }
324
329
  async init() {
325
- this._safeMutationObserver((obs) => obs.disconnect());
326
- this._mutationObserver = safeMutationObserver((records) => {
330
+ this._safeMutationObserver(obs => obs.disconnect());
331
+ this._mutationObserver = safeMutationObserver(records => {
327
332
  for (const record of records) {
328
333
  if (record.type === "attributes" && record.attributeName === "style") {
329
334
  this._repairStyle();
@@ -340,8 +345,8 @@ export class Canvas {
340
345
  getLogger().error(e);
341
346
  }
342
347
  this.initBackground();
343
- this._safeMutationObserver((obs) => {
344
- if (!this.element) {
348
+ this._safeMutationObserver(obs => {
349
+ if (!this.element || !(this.element instanceof Node)) {
345
350
  return;
346
351
  }
347
352
  obs.observe(this.element, { attributes: true });
@@ -408,8 +413,8 @@ export class Canvas {
408
413
  this.size.height = canvas.offsetHeight;
409
414
  this.size.width = canvas.offsetWidth;
410
415
  this._context = this.element.getContext("2d");
411
- this._safeMutationObserver((obs) => {
412
- if (!this.element) {
416
+ this._safeMutationObserver(obs => {
417
+ if (!this.element || !(this.element instanceof Node)) {
413
418
  return;
414
419
  }
415
420
  obs.observe(this.element, { attributes: true });
@@ -419,7 +424,7 @@ export class Canvas {
419
424
  }
420
425
  paint() {
421
426
  const options = this.container.actualOptions;
422
- this.draw((ctx) => {
427
+ this.draw(ctx => {
423
428
  if (options.backgroundMask.enable && options.backgroundMask.cover) {
424
429
  clear(ctx, this.size);
425
430
  if (this._coverImage) {
@@ -463,16 +468,16 @@ export class Canvas {
463
468
  return true;
464
469
  }
465
470
  stop() {
466
- this._safeMutationObserver((obs) => obs.disconnect());
471
+ this._safeMutationObserver(obs => obs.disconnect());
467
472
  this._mutationObserver = undefined;
468
- this.draw((ctx) => clear(ctx, this.size));
473
+ this.draw(ctx => clear(ctx, this.size));
469
474
  }
470
475
  async windowResize() {
471
476
  if (!this.element || !this.resize()) {
472
477
  return;
473
478
  }
474
479
  const container = this.container, needsRefresh = container.updateActualOptions();
475
- await container.particles.setDensity();
480
+ container.particles.setDensity();
476
481
  this._applyResizePlugins();
477
482
  if (needsRefresh) {
478
483
  await container.refresh();
@@ -2,6 +2,7 @@ import { errorPrefix, millisecondsToSeconds } from "./Utils/Constants.js";
2
2
  import { getLogger, safeIntersectionObserver } from "../Utils/Utils.js";
3
3
  import { Canvas } from "./Canvas.js";
4
4
  import { EventListeners } from "./Utils/EventListeners.js";
5
+ import { EventType } from "../Enums/Types/EventType.js";
5
6
  import { Options } from "../Options/Classes/Options.js";
6
7
  import { Particles } from "./Particles.js";
7
8
  import { Retina } from "./Retina.js";
@@ -24,7 +25,7 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
24
25
  }
25
26
  export class Container {
26
27
  constructor(engine, id, sourceOptions) {
27
- this._intersectionManager = (entries) => {
28
+ this._intersectionManager = entries => {
28
29
  if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
29
30
  return;
30
31
  }
@@ -40,7 +41,7 @@ export class Container {
40
41
  }
41
42
  }
42
43
  };
43
- this._nextFrame = async (timestamp) => {
44
+ this._nextFrame = (timestamp) => {
44
45
  try {
45
46
  if (!this._smooth &&
46
47
  this._lastFrameTime !== undefined &&
@@ -56,7 +57,7 @@ export class Container {
56
57
  this.draw(false);
57
58
  return;
58
59
  }
59
- await this.particles.draw(delta);
60
+ this.particles.draw(delta);
60
61
  if (!this.alive()) {
61
62
  this.destroy();
62
63
  return;
@@ -83,6 +84,7 @@ export class Container {
83
84
  this._lastFrameTime = 0;
84
85
  this.zLayers = 100;
85
86
  this.pageHidden = false;
87
+ this._clickHandlers = new Map();
86
88
  this._sourceOptions = sourceOptions;
87
89
  this._initialSourceOptions = sourceOptions;
88
90
  this.retina = new Retina(this);
@@ -101,8 +103,8 @@ export class Container {
101
103
  this._options = loadContainerOptions(this._engine, this);
102
104
  this.actualOptions = loadContainerOptions(this._engine, this);
103
105
  this._eventListeners = new EventListeners(this);
104
- this._intersectionObserver = safeIntersectionObserver((entries) => this._intersectionManager(entries));
105
- this._engine.dispatchEvent("containerBuilt", { container: this });
106
+ this._intersectionObserver = safeIntersectionObserver(entries => this._intersectionManager(entries));
107
+ this._engine.dispatchEvent(EventType.containerBuilt, { container: this });
106
108
  }
107
109
  get animationStatus() {
108
110
  return !this._paused && !this.pageHidden && guardCheck(this);
@@ -130,8 +132,7 @@ export class Container {
130
132
  y: pos.y * pxRatio,
131
133
  }, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
132
134
  callback(e, particles);
133
- };
134
- const clickHandler = (e) => {
135
+ }, clickHandler = (e) => {
135
136
  if (!guardCheck(this)) {
136
137
  return;
137
138
  }
@@ -140,27 +141,23 @@ export class Container {
140
141
  y: mouseEvent.offsetY || mouseEvent.clientY,
141
142
  }, radius = 1;
142
143
  clickOrTouchHandler(e, pos, radius);
143
- };
144
- const touchStartHandler = () => {
144
+ }, touchStartHandler = () => {
145
145
  if (!guardCheck(this)) {
146
146
  return;
147
147
  }
148
148
  touched = true;
149
149
  touchMoved = false;
150
- };
151
- const touchMoveHandler = () => {
150
+ }, touchMoveHandler = () => {
152
151
  if (!guardCheck(this)) {
153
152
  return;
154
153
  }
155
154
  touchMoved = true;
156
- };
157
- const touchEndHandler = (e) => {
155
+ }, touchEndHandler = (e) => {
158
156
  if (!guardCheck(this)) {
159
157
  return;
160
158
  }
161
159
  if (touched && !touchMoved) {
162
- const touchEvent = e;
163
- const lengthOffset = 1;
160
+ const touchEvent = e, lengthOffset = 1;
164
161
  let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
165
162
  if (!lastTouch) {
166
163
  lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
@@ -176,8 +173,7 @@ export class Container {
176
173
  }
177
174
  touched = false;
178
175
  touchMoved = false;
179
- };
180
- const touchCancelHandler = () => {
176
+ }, touchCancelHandler = () => {
181
177
  if (!guardCheck(this)) {
182
178
  return;
183
179
  }
@@ -185,11 +181,14 @@ export class Container {
185
181
  touchMoved = false;
186
182
  };
187
183
  let touched = false, touchMoved = false;
188
- el.addEventListener("click", clickHandler);
189
- el.addEventListener("touchstart", touchStartHandler);
190
- el.addEventListener("touchmove", touchMoveHandler);
191
- el.addEventListener("touchend", touchEndHandler);
192
- el.addEventListener("touchcancel", touchCancelHandler);
184
+ this._clickHandlers.set("click", clickHandler);
185
+ this._clickHandlers.set("touchstart", touchStartHandler);
186
+ this._clickHandlers.set("touchmove", touchMoveHandler);
187
+ this._clickHandlers.set("touchend", touchEndHandler);
188
+ this._clickHandlers.set("touchcancel", touchCancelHandler);
189
+ for (const [key, handler] of this._clickHandlers) {
190
+ el.addEventListener(key, handler);
191
+ }
193
192
  }
194
193
  addLifeTime(value) {
195
194
  this._lifeTime += value;
@@ -204,11 +203,21 @@ export class Container {
204
203
  alive() {
205
204
  return !this._duration || this._lifeTime <= this._duration;
206
205
  }
207
- destroy() {
206
+ clearClickHandlers() {
207
+ if (!guardCheck(this)) {
208
+ return;
209
+ }
210
+ for (const [key, handler] of this._clickHandlers) {
211
+ this.interactivity.element?.removeEventListener(key, handler);
212
+ }
213
+ this._clickHandlers.clear();
214
+ }
215
+ destroy(remove = true) {
208
216
  if (!guardCheck(this)) {
209
217
  return;
210
218
  }
211
219
  this.stop();
220
+ this.clearClickHandlers();
212
221
  this.particles.destroy();
213
222
  this.canvas.destroy();
214
223
  for (const [, effectDrawer] of this.effectDrawers) {
@@ -225,26 +234,28 @@ export class Container {
225
234
  }
226
235
  this._engine.clearPlugins(this);
227
236
  this.destroyed = true;
228
- const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this), minIndex = 0;
229
- if (idx >= minIndex) {
230
- const deleteCount = 1;
231
- mainArr.splice(idx, deleteCount);
237
+ if (remove) {
238
+ const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
239
+ if (idx >= minIndex) {
240
+ const deleteCount = 1;
241
+ mainArr.splice(idx, deleteCount);
242
+ }
232
243
  }
233
- this._engine.dispatchEvent("containerDestroyed", { container: this });
244
+ this._engine.dispatchEvent(EventType.containerDestroyed, { container: this });
234
245
  }
235
246
  draw(force) {
236
247
  if (!guardCheck(this)) {
237
248
  return;
238
249
  }
239
250
  let refreshTime = force;
240
- const frame = async (timestamp) => {
251
+ const frame = (timestamp) => {
241
252
  if (refreshTime) {
242
253
  this._lastFrameTime = undefined;
243
254
  refreshTime = false;
244
255
  }
245
- await this._nextFrame(timestamp);
256
+ this._nextFrame(timestamp);
246
257
  };
247
- this._drawAnimationFrame = requestAnimationFrame((timestamp) => void frame(timestamp));
258
+ this._drawAnimationFrame = requestAnimationFrame(timestamp => frame(timestamp));
248
259
  }
249
260
  async export(type, options = {}) {
250
261
  for (const [, plugin] of this.plugins) {
@@ -298,13 +309,14 @@ export class Container {
298
309
  this.updateActualOptions();
299
310
  this.canvas.initBackground();
300
311
  this.canvas.resize();
301
- this.zLayers = this.actualOptions.zLayers;
302
- this._duration = getRangeValue(this.actualOptions.duration) * millisecondsToSeconds;
303
- this._delay = getRangeValue(this.actualOptions.delay) * millisecondsToSeconds;
312
+ const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
313
+ this.zLayers = zLayers;
314
+ this._duration = getRangeValue(duration) * millisecondsToSeconds;
315
+ this._delay = getRangeValue(delay) * millisecondsToSeconds;
304
316
  this._lifeTime = 0;
305
317
  const defaultFpsLimit = 120, minFpsLimit = 0;
306
- this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;
307
- this._smooth = this.actualOptions.smooth;
318
+ this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
319
+ this._smooth = smooth;
308
320
  for (const [, drawer] of this.effectDrawers) {
309
321
  await drawer.init?.(this);
310
322
  }
@@ -314,13 +326,13 @@ export class Container {
314
326
  for (const [, plugin] of this.plugins) {
315
327
  await plugin.init?.();
316
328
  }
317
- this._engine.dispatchEvent("containerInit", { container: this });
329
+ this._engine.dispatchEvent(EventType.containerInit, { container: this });
318
330
  await this.particles.init();
319
- await this.particles.setDensity();
331
+ this.particles.setDensity();
320
332
  for (const [, plugin] of this.plugins) {
321
333
  plugin.particlesSetup?.();
322
334
  }
323
- this._engine.dispatchEvent("particlesSetup", { container: this });
335
+ this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
324
336
  }
325
337
  async loadTheme(name) {
326
338
  if (!guardCheck(this)) {
@@ -346,7 +358,7 @@ export class Container {
346
358
  if (!this.pageHidden) {
347
359
  this._paused = true;
348
360
  }
349
- this._engine.dispatchEvent("containerPaused", { container: this });
361
+ this._engine.dispatchEvent(EventType.containerPaused, { container: this });
350
362
  }
351
363
  play(force) {
352
364
  if (!guardCheck(this)) {
@@ -367,7 +379,7 @@ export class Container {
367
379
  }
368
380
  }
369
381
  }
370
- this._engine.dispatchEvent("containerPlay", { container: this });
382
+ this._engine.dispatchEvent(EventType.containerPlay, { container: this });
371
383
  this.draw(needsUpdate ?? false);
372
384
  }
373
385
  async refresh() {
@@ -377,12 +389,13 @@ export class Container {
377
389
  this.stop();
378
390
  return this.start();
379
391
  }
380
- async reset() {
392
+ async reset(sourceOptions) {
381
393
  if (!guardCheck(this)) {
382
394
  return;
383
395
  }
384
- this._initialSourceOptions = undefined;
385
- this._options = loadContainerOptions(this._engine, this);
396
+ this._initialSourceOptions = sourceOptions;
397
+ this._sourceOptions = sourceOptions;
398
+ this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
386
399
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
387
400
  return this.refresh();
388
401
  }
@@ -392,7 +405,7 @@ export class Container {
392
405
  }
393
406
  await this.init();
394
407
  this.started = true;
395
- await new Promise((resolve) => {
408
+ await new Promise(resolve => {
396
409
  const start = async () => {
397
410
  this._eventListeners.addListeners();
398
411
  if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
@@ -401,7 +414,7 @@ export class Container {
401
414
  for (const [, plugin] of this.plugins) {
402
415
  await plugin.start?.();
403
416
  }
404
- this._engine.dispatchEvent("containerStarted", { container: this });
417
+ this._engine.dispatchEvent(EventType.containerStarted, { container: this });
405
418
  this.play();
406
419
  resolve();
407
420
  };
@@ -432,7 +445,7 @@ export class Container {
432
445
  this.plugins.delete(key);
433
446
  }
434
447
  this._sourceOptions = this._options;
435
- this._engine.dispatchEvent("containerStopped", { container: this });
448
+ this._engine.dispatchEvent(EventType.containerStopped, { container: this });
436
449
  }
437
450
  updateActualOptions() {
438
451
  this.actualOptions.responsive = [];