@tsparticles/engine 3.3.0 → 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 (265) hide show
  1. package/README.md +0 -4
  2. package/browser/Core/Canvas.js +27 -22
  3. package/browser/Core/Container.js +55 -42
  4. package/browser/Core/Engine.js +82 -74
  5. package/browser/Core/Particle.js +29 -15
  6. package/browser/Core/Particles.js +23 -24
  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 +3 -2
  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 +13 -7
  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 +27 -22
  59. package/cjs/Core/Container.js +55 -42
  60. package/cjs/Core/Engine.js +82 -74
  61. package/cjs/Core/Particle.js +29 -15
  62. package/cjs/Core/Particles.js +23 -24
  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 +3 -2
  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 +13 -7
  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 +27 -22
  115. package/esm/Core/Container.js +55 -42
  116. package/esm/Core/Engine.js +82 -74
  117. package/esm/Core/Particle.js +29 -15
  118. package/esm/Core/Particles.js +23 -24
  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 +3 -2
  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 +13 -7
  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/Container.d.ts +4 -2
  176. package/types/Core/Engine.d.ts +6 -5
  177. package/types/Core/Interfaces/IPlugin.d.ts +3 -4
  178. package/types/Core/Interfaces/IShapeDrawer.d.ts +1 -0
  179. package/types/Core/Particle.d.ts +1 -0
  180. package/types/Enums/AnimationStatus.d.ts +1 -1
  181. package/types/Enums/Directions/MoveDirection.d.ts +1 -1
  182. package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
  183. package/types/Enums/Directions/RotateDirection.d.ts +1 -1
  184. package/types/Enums/InteractivityDetect.d.ts +1 -1
  185. package/types/Enums/Modes/AnimationMode.d.ts +1 -1
  186. package/types/Enums/Modes/CollisionMode.d.ts +1 -1
  187. package/types/Enums/Modes/LimitMode.d.ts +1 -1
  188. package/types/Enums/Modes/OutMode.d.ts +1 -1
  189. package/types/Enums/Modes/PixelMode.d.ts +1 -1
  190. package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
  191. package/types/Enums/Modes/ThemeMode.d.ts +1 -1
  192. package/types/Enums/Types/AlterType.d.ts +1 -1
  193. package/types/Enums/Types/DestroyType.d.ts +1 -1
  194. package/types/Enums/Types/DivType.d.ts +1 -1
  195. package/types/Enums/Types/EasingType.d.ts +1 -1
  196. package/types/Enums/Types/EventType.d.ts +1 -1
  197. package/types/Enums/Types/GradientType.d.ts +1 -1
  198. package/types/Enums/Types/InteractorType.d.ts +1 -1
  199. package/types/Enums/Types/ParticleOutType.d.ts +1 -1
  200. package/types/Enums/Types/StartValueType.d.ts +1 -1
  201. package/types/Options/Classes/Options.d.ts +2 -1
  202. package/types/Options/Classes/Responsive.d.ts +2 -2
  203. package/types/Options/Classes/Theme/Theme.d.ts +2 -2
  204. package/types/Options/Interfaces/IResponsive.d.ts +2 -3
  205. package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
  206. package/types/Types/RangeType.d.ts +1 -1
  207. package/umd/Core/Canvas.js +27 -22
  208. package/umd/Core/Container.js +56 -43
  209. package/umd/Core/Engine.js +83 -99
  210. package/umd/Core/Particle.js +30 -16
  211. package/umd/Core/Particles.js +24 -25
  212. package/umd/Core/Utils/EventListeners.js +19 -18
  213. package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
  214. package/umd/Core/Utils/InteractionManager.js +4 -3
  215. package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
  216. package/umd/Core/Utils/QuadTree.js +1 -1
  217. package/umd/Core/Utils/Ranges.js +6 -5
  218. package/umd/Enums/AnimationStatus.js +6 -0
  219. package/umd/Enums/Directions/MoveDirection.js +15 -0
  220. package/umd/Enums/Directions/OutModeDirection.js +8 -0
  221. package/umd/Enums/Directions/RotateDirection.js +7 -0
  222. package/umd/Enums/InteractivityDetect.js +7 -0
  223. package/umd/Enums/Modes/AnimationMode.js +8 -0
  224. package/umd/Enums/Modes/CollisionMode.js +7 -0
  225. package/umd/Enums/Modes/LimitMode.js +6 -0
  226. package/umd/Enums/Modes/OutMode.js +9 -0
  227. package/umd/Enums/Modes/PixelMode.js +6 -0
  228. package/umd/Enums/Modes/ResponsiveMode.js +6 -0
  229. package/umd/Enums/Modes/ThemeMode.js +7 -0
  230. package/umd/Enums/Types/AlterType.js +6 -0
  231. package/umd/Enums/Types/DestroyType.js +7 -0
  232. package/umd/Enums/Types/DivType.js +6 -0
  233. package/umd/Enums/Types/EasingType.js +31 -0
  234. package/umd/Enums/Types/EventType.js +16 -0
  235. package/umd/Enums/Types/GradientType.js +7 -0
  236. package/umd/Enums/Types/InteractorType.js +6 -0
  237. package/umd/Enums/Types/ParticleOutType.js +7 -0
  238. package/umd/Enums/Types/StartValueType.js +7 -0
  239. package/umd/Options/Classes/AnimationOptions.js +5 -3
  240. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
  241. package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
  242. package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
  243. package/umd/Options/Classes/ManualParticle.js +3 -2
  244. package/umd/Options/Classes/Options.js +15 -13
  245. package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
  246. package/umd/Options/Classes/Particles/Move/Move.js +3 -2
  247. package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
  248. package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
  249. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
  250. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
  251. package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
  252. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
  253. package/umd/Options/Classes/Responsive.js +6 -5
  254. package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
  255. package/umd/Types/RangeType.js +6 -0
  256. package/umd/Utils/CanvasUtils.js +14 -8
  257. package/umd/Utils/ColorUtils.js +18 -10
  258. package/umd/Utils/EventDispatcher.js +1 -1
  259. package/umd/Utils/HslColorManager.js +11 -4
  260. package/umd/Utils/NumberUtils.js +12 -11
  261. package/umd/Utils/RgbColorManager.js +11 -4
  262. package/umd/Utils/Utils.js +38 -32
  263. package/174.min.js +0 -2
  264. package/174.min.js.LICENSE.txt +0 -1
  265. package/dist_browser_Core_Container_js.js +0 -102
@@ -5,6 +5,7 @@ import type { Engine } from "../../Core/Engine.js";
5
5
  import { FullScreen } from "./FullScreen/FullScreen.js";
6
6
  import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
7
7
  import type { IOptions } from "../Interfaces/IOptions.js";
8
+ import type { ISourceOptions } from "../../Types/ISourceOptions.js";
8
9
  import { Interactivity } from "./Interactivity/Interactivity.js";
9
10
  import { ManualParticle } from "./ManualParticle.js";
10
11
  import type { RangeValue } from "../../Types/RangeValue.js";
@@ -44,7 +45,7 @@ export declare class Options implements IOptions, IOptionLoader<IOptions> {
44
45
  private readonly _container;
45
46
  private readonly _engine;
46
47
  constructor(engine: Engine, container: Container);
47
- load(data?: RecursivePartial<IOptions>): void;
48
+ load(data?: ISourceOptions): void;
48
49
  setResponsive(width: number, pxRatio: number, defaultOptions: IOptions): number | undefined;
49
50
  setTheme(name?: string): void;
50
51
  private readonly _findDefaultTheme;
@@ -1,12 +1,12 @@
1
1
  import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
2
- import type { IOptions } from "../Interfaces/IOptions.js";
3
2
  import type { IResponsive } from "../Interfaces/IResponsive.js";
3
+ import type { ISourceOptions } from "../../Types/ISourceOptions.js";
4
4
  import type { RecursivePartial } from "../../Types/RecursivePartial.js";
5
5
  import { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
6
6
  export declare class Responsive implements IResponsive, IOptionLoader<IResponsive> {
7
7
  maxWidth: number;
8
8
  mode: ResponsiveMode | keyof typeof ResponsiveMode;
9
- options: RecursivePartial<IOptions>;
9
+ options: ISourceOptions;
10
10
  constructor();
11
11
  load(data?: RecursivePartial<IResponsive>): void;
12
12
  }
@@ -1,12 +1,12 @@
1
1
  import type { IOptionLoader } from "../../Interfaces/IOptionLoader.js";
2
- import type { IOptions } from "../../Interfaces/IOptions.js";
2
+ import type { ISourceOptions } from "../../../Types/ISourceOptions.js";
3
3
  import type { ITheme } from "../../Interfaces/Theme/ITheme.js";
4
4
  import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
5
5
  import { ThemeDefault } from "./ThemeDefault.js";
6
6
  export declare class Theme implements ITheme, IOptionLoader<ITheme> {
7
7
  readonly default: ThemeDefault;
8
8
  name: string;
9
- options?: RecursivePartial<IOptions>;
9
+ options?: ISourceOptions;
10
10
  constructor();
11
11
  load(data?: RecursivePartial<ITheme>): void;
12
12
  }
@@ -1,8 +1,7 @@
1
- import type { IOptions } from "./IOptions.js";
2
- import type { RecursivePartial } from "../../Types/RecursivePartial.js";
1
+ import type { ISourceOptions } from "../../Types/ISourceOptions.js";
3
2
  import type { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
4
3
  export interface IResponsive {
5
4
  maxWidth: number;
6
5
  mode: ResponsiveMode | keyof typeof ResponsiveMode;
7
- options: RecursivePartial<IOptions>;
6
+ options: ISourceOptions;
8
7
  }
@@ -1,8 +1,7 @@
1
- import type { IOptions } from "../IOptions.js";
1
+ import type { ISourceOptions } from "../../../Types/ISourceOptions.js";
2
2
  import type { IThemeDefault } from "./IThemeDefault.js";
3
- import type { RecursivePartial } from "../../../Types/RecursivePartial.js";
4
3
  export interface ITheme {
5
4
  default: IThemeDefault;
6
5
  name: string;
7
- options?: RecursivePartial<IOptions>;
6
+ options?: ISourceOptions;
8
7
  }
@@ -1,4 +1,4 @@
1
- export declare const enum RangeType {
1
+ export declare enum RangeType {
2
2
  circle = "circle",
3
3
  rectangle = "rectangle"
4
4
  }
@@ -43,7 +43,7 @@
43
43
  class Canvas {
44
44
  constructor(container) {
45
45
  this.container = container;
46
- this._applyPostDrawUpdaters = (particle) => {
46
+ this._applyPostDrawUpdaters = particle => {
47
47
  for (const updater of this._postDrawUpdaters) {
48
48
  updater.afterDraw?.(particle);
49
49
  }
@@ -73,7 +73,7 @@
73
73
  plugin.resize?.();
74
74
  }
75
75
  };
76
- this._getPluginParticleColors = (particle) => {
76
+ this._getPluginParticleColors = particle => {
77
77
  let fColor, sColor;
78
78
  for (const plugin of this._colorPlugins) {
79
79
  if (!fColor && plugin.particleFillColor) {
@@ -113,7 +113,7 @@
113
113
  };
114
114
  resolve();
115
115
  });
116
- img.addEventListener("error", (evt) => {
116
+ img.addEventListener("error", evt => {
117
117
  reject(evt.error);
118
118
  });
119
119
  img.src = cover.image;
@@ -174,28 +174,33 @@
174
174
  };
175
175
  resolve();
176
176
  });
177
- img.addEventListener("error", (evt) => {
177
+ img.addEventListener("error", evt => {
178
178
  reject(evt.error);
179
179
  });
180
180
  img.src = trailFill.image;
181
181
  });
182
182
  }
183
183
  };
184
- this._paintBase = (baseColor) => {
185
- this.draw((ctx) => (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor));
184
+ this._paintBase = baseColor => {
185
+ this.draw(ctx => (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor));
186
186
  };
187
187
  this._paintImage = (image, opacity) => {
188
- this.draw((ctx) => (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity));
188
+ this.draw(ctx => (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity));
189
189
  };
190
190
  this._repairStyle = () => {
191
191
  const element = this.element;
192
192
  if (!element) {
193
193
  return;
194
194
  }
195
- this._safeMutationObserver((observer) => observer.disconnect());
195
+ this._safeMutationObserver(observer => observer.disconnect());
196
196
  this._initStyle();
197
197
  this.initBackground();
198
- this._safeMutationObserver((observer) => observer.observe(element, { attributes: true }));
198
+ this._safeMutationObserver(observer => {
199
+ if (!element || !(element instanceof Node)) {
200
+ return;
201
+ }
202
+ observer.observe(element, { attributes: true });
203
+ });
199
204
  };
200
205
  this._resetOriginalStyle = () => {
201
206
  const element = this.element, originalStyle = this._originalStyle;
@@ -204,7 +209,7 @@
204
209
  }
205
210
  setStyle(element, originalStyle);
206
211
  };
207
- this._safeMutationObserver = (callback) => {
212
+ this._safeMutationObserver = callback => {
208
213
  if (!this._mutationObserver) {
209
214
  return;
210
215
  }
@@ -253,7 +258,7 @@
253
258
  }
254
259
  }
255
260
  else if (options.clear) {
256
- this.draw((ctx) => {
261
+ this.draw(ctx => {
257
262
  (0, CanvasUtils_js_1.clear)(ctx, this.size);
258
263
  });
259
264
  }
@@ -328,14 +333,14 @@
328
333
  });
329
334
  }
330
335
  drawParticlePlugin(plugin, particle, delta) {
331
- this.draw((ctx) => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
336
+ this.draw(ctx => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
332
337
  }
333
338
  drawPlugin(plugin, delta) {
334
- this.draw((ctx) => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
339
+ this.draw(ctx => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
335
340
  }
336
341
  async init() {
337
- this._safeMutationObserver((obs) => obs.disconnect());
338
- this._mutationObserver = (0, Utils_js_1.safeMutationObserver)((records) => {
342
+ this._safeMutationObserver(obs => obs.disconnect());
343
+ this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
339
344
  for (const record of records) {
340
345
  if (record.type === "attributes" && record.attributeName === "style") {
341
346
  this._repairStyle();
@@ -352,8 +357,8 @@
352
357
  (0, Utils_js_1.getLogger)().error(e);
353
358
  }
354
359
  this.initBackground();
355
- this._safeMutationObserver((obs) => {
356
- if (!this.element) {
360
+ this._safeMutationObserver(obs => {
361
+ if (!this.element || !(this.element instanceof Node)) {
357
362
  return;
358
363
  }
359
364
  obs.observe(this.element, { attributes: true });
@@ -420,8 +425,8 @@
420
425
  this.size.height = canvas.offsetHeight;
421
426
  this.size.width = canvas.offsetWidth;
422
427
  this._context = this.element.getContext("2d");
423
- this._safeMutationObserver((obs) => {
424
- if (!this.element) {
428
+ this._safeMutationObserver(obs => {
429
+ if (!this.element || !(this.element instanceof Node)) {
425
430
  return;
426
431
  }
427
432
  obs.observe(this.element, { attributes: true });
@@ -431,7 +436,7 @@
431
436
  }
432
437
  paint() {
433
438
  const options = this.container.actualOptions;
434
- this.draw((ctx) => {
439
+ this.draw(ctx => {
435
440
  if (options.backgroundMask.enable && options.backgroundMask.cover) {
436
441
  (0, CanvasUtils_js_1.clear)(ctx, this.size);
437
442
  if (this._coverImage) {
@@ -475,9 +480,9 @@
475
480
  return true;
476
481
  }
477
482
  stop() {
478
- this._safeMutationObserver((obs) => obs.disconnect());
483
+ this._safeMutationObserver(obs => obs.disconnect());
479
484
  this._mutationObserver = undefined;
480
- this.draw((ctx) => (0, CanvasUtils_js_1.clear)(ctx, this.size));
485
+ this.draw(ctx => (0, CanvasUtils_js_1.clear)(ctx, this.size));
481
486
  }
482
487
  async windowResize() {
483
488
  if (!this.element || !this.resize()) {
@@ -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", "./Utils/Constants.js", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/NumberUtils.js", "../Utils/OptionsUtils.js"], factory);
7
+ define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "./Canvas.js", "./Utils/EventListeners.js", "../Enums/Types/EventType.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/NumberUtils.js", "../Utils/OptionsUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -14,6 +14,7 @@
14
14
  const Utils_js_1 = require("../Utils/Utils.js");
15
15
  const Canvas_js_1 = require("./Canvas.js");
16
16
  const EventListeners_js_1 = require("./Utils/EventListeners.js");
17
+ const EventType_js_1 = require("../Enums/Types/EventType.js");
17
18
  const Options_js_1 = require("../Options/Classes/Options.js");
18
19
  const Particles_js_1 = require("./Particles.js");
19
20
  const Retina_js_1 = require("./Retina.js");
@@ -36,7 +37,7 @@
36
37
  }
37
38
  class Container {
38
39
  constructor(engine, id, sourceOptions) {
39
- this._intersectionManager = (entries) => {
40
+ this._intersectionManager = entries => {
40
41
  if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
41
42
  return;
42
43
  }
@@ -95,6 +96,7 @@
95
96
  this._lastFrameTime = 0;
96
97
  this.zLayers = 100;
97
98
  this.pageHidden = false;
99
+ this._clickHandlers = new Map();
98
100
  this._sourceOptions = sourceOptions;
99
101
  this._initialSourceOptions = sourceOptions;
100
102
  this.retina = new Retina_js_1.Retina(this);
@@ -113,8 +115,8 @@
113
115
  this._options = loadContainerOptions(this._engine, this);
114
116
  this.actualOptions = loadContainerOptions(this._engine, this);
115
117
  this._eventListeners = new EventListeners_js_1.EventListeners(this);
116
- this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
117
- this._engine.dispatchEvent("containerBuilt", { container: this });
118
+ this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(entries => this._intersectionManager(entries));
119
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerBuilt, { container: this });
118
120
  }
119
121
  get animationStatus() {
120
122
  return !this._paused && !this.pageHidden && guardCheck(this);
@@ -142,8 +144,7 @@
142
144
  y: pos.y * pxRatio,
143
145
  }, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
144
146
  callback(e, particles);
145
- };
146
- const clickHandler = (e) => {
147
+ }, clickHandler = (e) => {
147
148
  if (!guardCheck(this)) {
148
149
  return;
149
150
  }
@@ -152,27 +153,23 @@
152
153
  y: mouseEvent.offsetY || mouseEvent.clientY,
153
154
  }, radius = 1;
154
155
  clickOrTouchHandler(e, pos, radius);
155
- };
156
- const touchStartHandler = () => {
156
+ }, touchStartHandler = () => {
157
157
  if (!guardCheck(this)) {
158
158
  return;
159
159
  }
160
160
  touched = true;
161
161
  touchMoved = false;
162
- };
163
- const touchMoveHandler = () => {
162
+ }, touchMoveHandler = () => {
164
163
  if (!guardCheck(this)) {
165
164
  return;
166
165
  }
167
166
  touchMoved = true;
168
- };
169
- const touchEndHandler = (e) => {
167
+ }, touchEndHandler = (e) => {
170
168
  if (!guardCheck(this)) {
171
169
  return;
172
170
  }
173
171
  if (touched && !touchMoved) {
174
- const touchEvent = e;
175
- const lengthOffset = 1;
172
+ const touchEvent = e, lengthOffset = 1;
176
173
  let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
177
174
  if (!lastTouch) {
178
175
  lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
@@ -188,8 +185,7 @@
188
185
  }
189
186
  touched = false;
190
187
  touchMoved = false;
191
- };
192
- const touchCancelHandler = () => {
188
+ }, touchCancelHandler = () => {
193
189
  if (!guardCheck(this)) {
194
190
  return;
195
191
  }
@@ -197,11 +193,14 @@
197
193
  touchMoved = false;
198
194
  };
199
195
  let touched = false, touchMoved = false;
200
- el.addEventListener("click", clickHandler);
201
- el.addEventListener("touchstart", touchStartHandler);
202
- el.addEventListener("touchmove", touchMoveHandler);
203
- el.addEventListener("touchend", touchEndHandler);
204
- el.addEventListener("touchcancel", touchCancelHandler);
196
+ this._clickHandlers.set("click", clickHandler);
197
+ this._clickHandlers.set("touchstart", touchStartHandler);
198
+ this._clickHandlers.set("touchmove", touchMoveHandler);
199
+ this._clickHandlers.set("touchend", touchEndHandler);
200
+ this._clickHandlers.set("touchcancel", touchCancelHandler);
201
+ for (const [key, handler] of this._clickHandlers) {
202
+ el.addEventListener(key, handler);
203
+ }
205
204
  }
206
205
  addLifeTime(value) {
207
206
  this._lifeTime += value;
@@ -216,11 +215,21 @@
216
215
  alive() {
217
216
  return !this._duration || this._lifeTime <= this._duration;
218
217
  }
219
- destroy() {
218
+ clearClickHandlers() {
219
+ if (!guardCheck(this)) {
220
+ return;
221
+ }
222
+ for (const [key, handler] of this._clickHandlers) {
223
+ this.interactivity.element?.removeEventListener(key, handler);
224
+ }
225
+ this._clickHandlers.clear();
226
+ }
227
+ destroy(remove = true) {
220
228
  if (!guardCheck(this)) {
221
229
  return;
222
230
  }
223
231
  this.stop();
232
+ this.clearClickHandlers();
224
233
  this.particles.destroy();
225
234
  this.canvas.destroy();
226
235
  for (const [, effectDrawer] of this.effectDrawers) {
@@ -237,12 +246,14 @@
237
246
  }
238
247
  this._engine.clearPlugins(this);
239
248
  this.destroyed = true;
240
- const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this), minIndex = 0;
241
- if (idx >= minIndex) {
242
- const deleteCount = 1;
243
- mainArr.splice(idx, deleteCount);
249
+ if (remove) {
250
+ const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
251
+ if (idx >= minIndex) {
252
+ const deleteCount = 1;
253
+ mainArr.splice(idx, deleteCount);
254
+ }
244
255
  }
245
- this._engine.dispatchEvent("containerDestroyed", { container: this });
256
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
246
257
  }
247
258
  draw(force) {
248
259
  if (!guardCheck(this)) {
@@ -256,7 +267,7 @@
256
267
  }
257
268
  this._nextFrame(timestamp);
258
269
  };
259
- this._drawAnimationFrame = requestAnimationFrame((timestamp) => frame(timestamp));
270
+ this._drawAnimationFrame = requestAnimationFrame(timestamp => frame(timestamp));
260
271
  }
261
272
  async export(type, options = {}) {
262
273
  for (const [, plugin] of this.plugins) {
@@ -310,13 +321,14 @@
310
321
  this.updateActualOptions();
311
322
  this.canvas.initBackground();
312
323
  this.canvas.resize();
313
- this.zLayers = this.actualOptions.zLayers;
314
- this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) * Constants_js_1.millisecondsToSeconds;
315
- this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) * Constants_js_1.millisecondsToSeconds;
324
+ const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
325
+ this.zLayers = zLayers;
326
+ this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
327
+ this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
316
328
  this._lifeTime = 0;
317
329
  const defaultFpsLimit = 120, minFpsLimit = 0;
318
- this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;
319
- this._smooth = this.actualOptions.smooth;
330
+ this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
331
+ this._smooth = smooth;
320
332
  for (const [, drawer] of this.effectDrawers) {
321
333
  await drawer.init?.(this);
322
334
  }
@@ -326,13 +338,13 @@
326
338
  for (const [, plugin] of this.plugins) {
327
339
  await plugin.init?.();
328
340
  }
329
- this._engine.dispatchEvent("containerInit", { container: this });
341
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
330
342
  await this.particles.init();
331
343
  this.particles.setDensity();
332
344
  for (const [, plugin] of this.plugins) {
333
345
  plugin.particlesSetup?.();
334
346
  }
335
- this._engine.dispatchEvent("particlesSetup", { container: this });
347
+ this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
336
348
  }
337
349
  async loadTheme(name) {
338
350
  if (!guardCheck(this)) {
@@ -358,7 +370,7 @@
358
370
  if (!this.pageHidden) {
359
371
  this._paused = true;
360
372
  }
361
- this._engine.dispatchEvent("containerPaused", { container: this });
373
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerPaused, { container: this });
362
374
  }
363
375
  play(force) {
364
376
  if (!guardCheck(this)) {
@@ -379,7 +391,7 @@
379
391
  }
380
392
  }
381
393
  }
382
- this._engine.dispatchEvent("containerPlay", { container: this });
394
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerPlay, { container: this });
383
395
  this.draw(needsUpdate ?? false);
384
396
  }
385
397
  async refresh() {
@@ -389,12 +401,13 @@
389
401
  this.stop();
390
402
  return this.start();
391
403
  }
392
- async reset() {
404
+ async reset(sourceOptions) {
393
405
  if (!guardCheck(this)) {
394
406
  return;
395
407
  }
396
- this._initialSourceOptions = undefined;
397
- this._options = loadContainerOptions(this._engine, this);
408
+ this._initialSourceOptions = sourceOptions;
409
+ this._sourceOptions = sourceOptions;
410
+ this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
398
411
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
399
412
  return this.refresh();
400
413
  }
@@ -404,7 +417,7 @@
404
417
  }
405
418
  await this.init();
406
419
  this.started = true;
407
- await new Promise((resolve) => {
420
+ await new Promise(resolve => {
408
421
  const start = async () => {
409
422
  this._eventListeners.addListeners();
410
423
  if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
@@ -413,7 +426,7 @@
413
426
  for (const [, plugin] of this.plugins) {
414
427
  await plugin.start?.();
415
428
  }
416
- this._engine.dispatchEvent("containerStarted", { container: this });
429
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
417
430
  this.play();
418
431
  resolve();
419
432
  };
@@ -444,7 +457,7 @@
444
457
  this.plugins.delete(key);
445
458
  }
446
459
  this._sourceOptions = this._options;
447
- this._engine.dispatchEvent("containerStopped", { container: this });
460
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerStopped, { container: this });
448
461
  }
449
462
  updateActualOptions() {
450
463
  this.actualOptions.responsive = [];