@tsparticles/engine 4.0.0-alpha.3 → 4.0.0-alpha.5

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 (266) hide show
  1. package/794.min.js +2 -0
  2. package/794.min.js.LICENSE.txt +1 -0
  3. package/README.md +2 -5
  4. package/browser/Core/Canvas.js +3 -3
  5. package/browser/Core/Container.js +35 -155
  6. package/browser/Core/Engine.js +32 -78
  7. package/browser/Core/Particle.js +5 -10
  8. package/browser/Core/Particles.js +36 -25
  9. package/browser/Core/Utils/Constants.js +2 -2
  10. package/browser/Core/Utils/EventListeners.js +5 -250
  11. package/browser/Options/Classes/Options.js +7 -75
  12. package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -11
  13. package/{esm/Options/Classes/Interactivity/Events → browser/Options/Classes}/ResizeEvent.js +1 -1
  14. package/browser/Utils/ColorUtils.js +7 -5
  15. package/browser/Utils/Utils.js +33 -36
  16. package/browser/exports.js +1 -21
  17. package/cjs/Core/Canvas.js +3 -3
  18. package/cjs/Core/Container.js +35 -155
  19. package/cjs/Core/Engine.js +32 -78
  20. package/cjs/Core/Particle.js +5 -10
  21. package/cjs/Core/Particles.js +36 -25
  22. package/cjs/Core/Utils/Constants.js +2 -2
  23. package/cjs/Core/Utils/EventListeners.js +5 -250
  24. package/cjs/Options/Classes/Options.js +7 -75
  25. package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -11
  26. package/cjs/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +1 -1
  27. package/cjs/Utils/ColorUtils.js +7 -5
  28. package/cjs/Utils/Utils.js +33 -36
  29. package/cjs/exports.js +1 -21
  30. package/dist_browser_Core_Container_js.js +6 -16
  31. package/esm/Core/Canvas.js +3 -3
  32. package/esm/Core/Container.js +35 -155
  33. package/esm/Core/Engine.js +32 -78
  34. package/esm/Core/Particle.js +5 -10
  35. package/esm/Core/Particles.js +36 -25
  36. package/esm/Core/Utils/Constants.js +2 -2
  37. package/esm/Core/Utils/EventListeners.js +5 -250
  38. package/esm/Options/Classes/Options.js +7 -75
  39. package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -11
  40. package/{browser/Options/Classes/Interactivity/Events → esm/Options/Classes}/ResizeEvent.js +1 -1
  41. package/esm/Utils/ColorUtils.js +7 -5
  42. package/esm/Utils/Utils.js +33 -36
  43. package/esm/exports.js +1 -21
  44. package/package.json +1 -1
  45. package/report.html +1 -1
  46. package/tsparticles.engine.js +14 -206
  47. package/tsparticles.engine.min.js +1 -1
  48. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  49. package/types/Core/Container.d.ts +3 -15
  50. package/types/Core/Engine.d.ts +8 -19
  51. package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -1
  52. package/types/Core/Interfaces/IPlugin.d.ts +5 -1
  53. package/types/Core/Particle.d.ts +0 -2
  54. package/types/Core/Particles.d.ts +1 -5
  55. package/types/Core/Utils/Constants.d.ts +2 -2
  56. package/types/Core/Utils/EventListeners.d.ts +0 -14
  57. package/types/Options/Classes/Options.d.ts +2 -11
  58. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +0 -2
  59. package/types/Options/Classes/ResizeEvent.d.ts +9 -0
  60. package/types/Options/Interfaces/IOptions.d.ts +2 -8
  61. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -3
  62. package/types/Types/EngineInitializers.d.ts +10 -0
  63. package/types/Utils/Utils.d.ts +4 -6
  64. package/types/export-types.d.ts +3 -19
  65. package/types/exports.d.ts +1 -21
  66. package/umd/Core/Canvas.js +3 -3
  67. package/umd/Core/Container.js +35 -155
  68. package/umd/Core/Engine.js +33 -79
  69. package/umd/Core/Particle.js +6 -11
  70. package/umd/Core/Particles.js +37 -26
  71. package/umd/Core/Utils/Constants.js +3 -3
  72. package/umd/Core/Utils/EventListeners.js +7 -252
  73. package/umd/Options/Classes/Options.js +7 -75
  74. package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -11
  75. package/umd/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +2 -2
  76. package/umd/Utils/ColorUtils.js +7 -5
  77. package/umd/Utils/Utils.js +34 -39
  78. package/umd/exports.js +2 -22
  79. package/638.min.js +0 -2
  80. package/638.min.js.LICENSE.txt +0 -1
  81. package/browser/Core/Interfaces/IMouseData.js +0 -1
  82. package/browser/Core/Interfaces/IParticlesInteractor.js +0 -1
  83. package/browser/Core/Utils/ExternalInteractorBase.js +0 -7
  84. package/browser/Core/Utils/InteractionManager.js +0 -60
  85. package/browser/Core/Utils/ParticlesInteractorBase.js +0 -7
  86. package/browser/Enums/InteractivityDetect.js +0 -6
  87. package/browser/Enums/Modes/ResponsiveMode.js +0 -5
  88. package/browser/Enums/Modes/ThemeMode.js +0 -6
  89. package/browser/Enums/Types/DivType.js +0 -5
  90. package/browser/Enums/Types/InteractorType.js +0 -5
  91. package/browser/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  92. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  93. package/browser/Options/Classes/Interactivity/Events/Events.js +0 -30
  94. package/browser/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  95. package/browser/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  96. package/browser/Options/Classes/Interactivity/Interactivity.js +0 -22
  97. package/browser/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  98. package/browser/Options/Classes/ManualParticle.js +0 -21
  99. package/browser/Options/Classes/Responsive.js +0 -29
  100. package/browser/Options/Classes/Theme/Theme.js +0 -21
  101. package/browser/Options/Classes/Theme/ThemeDefault.js +0 -23
  102. package/browser/Options/Interfaces/IManualParticle.js +0 -1
  103. package/browser/Options/Interfaces/IResponsive.js +0 -1
  104. package/browser/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  105. package/browser/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  106. package/browser/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  107. package/browser/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  108. package/browser/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  109. package/browser/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  110. package/browser/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  111. package/browser/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  112. package/browser/Options/Interfaces/Theme/ITheme.js +0 -1
  113. package/browser/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  114. package/cjs/Core/Interfaces/IContainerInteractivity.js +0 -1
  115. package/cjs/Core/Interfaces/IExternalInteractor.js +0 -1
  116. package/cjs/Core/Interfaces/IInteractor.js +0 -1
  117. package/cjs/Core/Interfaces/IMouseData.js +0 -1
  118. package/cjs/Core/Interfaces/IParticlesInteractor.js +0 -1
  119. package/cjs/Core/Utils/ExternalInteractorBase.js +0 -7
  120. package/cjs/Core/Utils/InteractionManager.js +0 -60
  121. package/cjs/Core/Utils/ParticlesInteractorBase.js +0 -7
  122. package/cjs/Enums/InteractivityDetect.js +0 -6
  123. package/cjs/Enums/Modes/ResponsiveMode.js +0 -5
  124. package/cjs/Enums/Modes/ThemeMode.js +0 -6
  125. package/cjs/Enums/Types/DivType.js +0 -5
  126. package/cjs/Enums/Types/InteractorType.js +0 -5
  127. package/cjs/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  128. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  129. package/cjs/Options/Classes/Interactivity/Events/Events.js +0 -30
  130. package/cjs/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  131. package/cjs/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  132. package/cjs/Options/Classes/Interactivity/Interactivity.js +0 -22
  133. package/cjs/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  134. package/cjs/Options/Classes/ManualParticle.js +0 -21
  135. package/cjs/Options/Classes/Responsive.js +0 -29
  136. package/cjs/Options/Classes/Theme/Theme.js +0 -21
  137. package/cjs/Options/Classes/Theme/ThemeDefault.js +0 -23
  138. package/cjs/Options/Interfaces/IManualParticle.js +0 -1
  139. package/cjs/Options/Interfaces/IResponsive.js +0 -1
  140. package/cjs/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  141. package/cjs/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  142. package/cjs/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  143. package/cjs/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  144. package/cjs/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  145. package/cjs/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  146. package/cjs/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  147. package/cjs/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  148. package/cjs/Options/Interfaces/Theme/ITheme.js +0 -1
  149. package/cjs/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  150. package/esm/Core/Interfaces/IContainerInteractivity.js +0 -1
  151. package/esm/Core/Interfaces/IExternalInteractor.js +0 -1
  152. package/esm/Core/Interfaces/IInteractor.js +0 -1
  153. package/esm/Core/Interfaces/IMouseData.js +0 -1
  154. package/esm/Core/Interfaces/IParticlesInteractor.js +0 -1
  155. package/esm/Core/Utils/ExternalInteractorBase.js +0 -7
  156. package/esm/Core/Utils/InteractionManager.js +0 -60
  157. package/esm/Core/Utils/ParticlesInteractorBase.js +0 -7
  158. package/esm/Enums/InteractivityDetect.js +0 -6
  159. package/esm/Enums/Modes/ResponsiveMode.js +0 -5
  160. package/esm/Enums/Modes/ThemeMode.js +0 -6
  161. package/esm/Enums/Types/DivType.js +0 -5
  162. package/esm/Enums/Types/InteractorType.js +0 -5
  163. package/esm/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  164. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  165. package/esm/Options/Classes/Interactivity/Events/Events.js +0 -30
  166. package/esm/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  167. package/esm/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  168. package/esm/Options/Classes/Interactivity/Interactivity.js +0 -22
  169. package/esm/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  170. package/esm/Options/Classes/ManualParticle.js +0 -21
  171. package/esm/Options/Classes/Responsive.js +0 -29
  172. package/esm/Options/Classes/Theme/Theme.js +0 -21
  173. package/esm/Options/Classes/Theme/ThemeDefault.js +0 -23
  174. package/esm/Options/Interfaces/IManualParticle.js +0 -1
  175. package/esm/Options/Interfaces/IResponsive.js +0 -1
  176. package/esm/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  177. package/esm/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  178. package/esm/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  179. package/esm/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  180. package/esm/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  181. package/esm/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  182. package/esm/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  183. package/esm/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  184. package/esm/Options/Interfaces/Theme/ITheme.js +0 -1
  185. package/esm/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  186. package/types/Core/Interfaces/IContainerInteractivity.d.ts +0 -6
  187. package/types/Core/Interfaces/IExternalInteractor.d.ts +0 -12
  188. package/types/Core/Interfaces/IInteractor.d.ts +0 -16
  189. package/types/Core/Interfaces/IMouseData.d.ts +0 -9
  190. package/types/Core/Interfaces/IParticlesInteractor.d.ts +0 -7
  191. package/types/Core/Utils/ExternalInteractorBase.d.ts +0 -15
  192. package/types/Core/Utils/InteractionManager.d.ts +0 -17
  193. package/types/Core/Utils/ParticlesInteractorBase.d.ts +0 -15
  194. package/types/Enums/InteractivityDetect.d.ts +0 -5
  195. package/types/Enums/Modes/ResponsiveMode.d.ts +0 -4
  196. package/types/Enums/Modes/ThemeMode.d.ts +0 -5
  197. package/types/Enums/Types/DivType.d.ts +0 -4
  198. package/types/Enums/Types/InteractorType.d.ts +0 -4
  199. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +0 -10
  200. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -13
  201. package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -16
  202. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +0 -12
  203. package/types/Options/Classes/Interactivity/Events/Parallax.d.ts +0 -10
  204. package/types/Options/Classes/Interactivity/Events/ResizeEvent.d.ts +0 -9
  205. package/types/Options/Classes/Interactivity/Interactivity.d.ts +0 -16
  206. package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +0 -12
  207. package/types/Options/Classes/ManualParticle.d.ts +0 -10
  208. package/types/Options/Classes/Responsive.d.ts +0 -12
  209. package/types/Options/Classes/Theme/Theme.d.ts +0 -12
  210. package/types/Options/Classes/Theme/ThemeDefault.d.ts +0 -11
  211. package/types/Options/Interfaces/IManualParticle.d.ts +0 -7
  212. package/types/Options/Interfaces/IResponsive.d.ts +0 -7
  213. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +0 -5
  214. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -8
  215. package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -11
  216. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +0 -7
  217. package/types/Options/Interfaces/Interactivity/Events/IParallax.d.ts +0 -5
  218. package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -9
  219. package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -4
  220. package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +0 -1
  221. package/types/Options/Interfaces/Theme/ITheme.d.ts +0 -7
  222. package/types/Options/Interfaces/Theme/IThemeDefault.d.ts +0 -6
  223. package/umd/Core/Interfaces/IExternalInteractor.js +0 -12
  224. package/umd/Core/Interfaces/IInteractor.js +0 -12
  225. package/umd/Core/Interfaces/IMouseData.js +0 -12
  226. package/umd/Core/Interfaces/IParticlesInteractor.js +0 -12
  227. package/umd/Core/Utils/ExternalInteractorBase.js +0 -21
  228. package/umd/Core/Utils/InteractionManager.js +0 -74
  229. package/umd/Core/Utils/ParticlesInteractorBase.js +0 -21
  230. package/umd/Enums/InteractivityDetect.js +0 -19
  231. package/umd/Enums/Modes/ResponsiveMode.js +0 -18
  232. package/umd/Enums/Modes/ThemeMode.js +0 -19
  233. package/umd/Enums/Types/DivType.js +0 -18
  234. package/umd/Enums/Types/InteractorType.js +0 -18
  235. package/umd/Options/Classes/Interactivity/Events/ClickEvent.js +0 -32
  236. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +0 -41
  237. package/umd/Options/Classes/Interactivity/Events/Events.js +0 -44
  238. package/umd/Options/Classes/Interactivity/Events/HoverEvent.js +0 -35
  239. package/umd/Options/Classes/Interactivity/Events/Parallax.js +0 -36
  240. package/umd/Options/Classes/Interactivity/Interactivity.js +0 -36
  241. package/umd/Options/Classes/Interactivity/Modes/Modes.js +0 -39
  242. package/umd/Options/Classes/ManualParticle.js +0 -35
  243. package/umd/Options/Classes/Responsive.js +0 -43
  244. package/umd/Options/Classes/Theme/Theme.js +0 -35
  245. package/umd/Options/Classes/Theme/ThemeDefault.js +0 -37
  246. package/umd/Options/Interfaces/IManualParticle.js +0 -12
  247. package/umd/Options/Interfaces/IResponsive.js +0 -12
  248. package/umd/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -12
  249. package/umd/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -12
  250. package/umd/Options/Interfaces/Interactivity/Events/IEvents.js +0 -12
  251. package/umd/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -12
  252. package/umd/Options/Interfaces/Interactivity/Events/IParallax.js +0 -12
  253. package/umd/Options/Interfaces/Interactivity/IInteractivity.js +0 -12
  254. package/umd/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -12
  255. package/umd/Options/Interfaces/Interactivity/Modes/IModes.js +0 -12
  256. package/umd/Options/Interfaces/Theme/ITheme.js +0 -12
  257. package/umd/Options/Interfaces/Theme/IThemeDefault.js +0 -12
  258. /package/browser/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  259. /package/browser/{Core/Interfaces/IContainerInteractivity.js → Types/EngineInitializers.js} +0 -0
  260. /package/cjs/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  261. /package/{browser/Core/Interfaces/IExternalInteractor.js → cjs/Types/EngineInitializers.js} +0 -0
  262. /package/esm/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  263. /package/{browser/Core/Interfaces/IInteractor.js → esm/Types/EngineInitializers.js} +0 -0
  264. /package/types/Options/Interfaces/{Interactivity/Events/IResizeEvent.d.ts → IResizeEvent.d.ts} +0 -0
  265. /package/umd/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  266. /package/umd/{Core/Interfaces/IContainerInteractivity.js → Types/EngineInitializers.js} +0 -0
@@ -55,9 +55,6 @@ export class ParticlesOptions {
55
55
  this.shape.load(data.shape);
56
56
  this.size.load(data.size);
57
57
  this.zIndex.load(data.zIndex);
58
- if (data.interactivity !== undefined) {
59
- this.interactivity = deepExtend({}, data.interactivity);
60
- }
61
58
  const strokeToLoad = data.stroke;
62
59
  if (strokeToLoad) {
63
60
  this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
@@ -67,6 +64,11 @@ export class ParticlesOptions {
67
64
  });
68
65
  }
69
66
  if (this._container) {
67
+ for (const plugin of this._engine.plugins) {
68
+ if (plugin.loadParticlesOptions) {
69
+ plugin.loadParticlesOptions(this._container, this, data);
70
+ }
71
+ }
70
72
  const updaters = this._engine.updaters.get(this._container);
71
73
  if (updaters) {
72
74
  for (const updater of updaters) {
@@ -75,14 +77,6 @@ export class ParticlesOptions {
75
77
  }
76
78
  }
77
79
  }
78
- const interactors = this._engine.interactors.get(this._container);
79
- if (interactors) {
80
- for (const interactor of interactors) {
81
- if (interactor.loadParticlesOptions) {
82
- interactor.loadParticlesOptions(this, data);
83
- }
84
- }
85
- }
86
80
  }
87
81
  }
88
82
  }
@@ -1,4 +1,4 @@
1
- import { isNull } from "../../../../Utils/TypeUtils.js";
1
+ import { isNull } from "../../Utils/TypeUtils.js";
2
2
  export class ResizeEvent {
3
3
  constructor() {
4
4
  this.delay = 0.5;
@@ -3,14 +3,16 @@ import { decayOffset, defaultLoops, defaultOpacity, defaultRgbMin, defaultTime,
3
3
  import { isArray, isString } from "./TypeUtils.js";
4
4
  import { AnimationStatus } from "../Enums/AnimationStatus.js";
5
5
  import { itemFromArray } from "./Utils.js";
6
- const styleCache = new Map(), maxCacheSize = 1000;
6
+ const styleCache = new Map(), maxCacheSize = 1000, firstIndex = 0, rgbFixedPrecision = 2, hslFixedPrecision = 2;
7
7
  function getCachedStyle(key, generator) {
8
8
  let cached = styleCache.get(key);
9
9
  if (!cached) {
10
10
  cached = generator();
11
- if (styleCache.size < maxCacheSize) {
12
- styleCache.set(key, cached);
11
+ if (styleCache.size >= maxCacheSize) {
12
+ const keysToDelete = [...styleCache.keys()].slice(firstIndex, maxCacheSize * half);
13
+ keysToDelete.forEach(k => styleCache.delete(k));
13
14
  }
15
+ styleCache.set(key, cached);
14
16
  }
15
17
  return cached;
16
18
  }
@@ -166,7 +168,7 @@ export function getRandomRgbColor(min) {
166
168
  };
167
169
  }
168
170
  export function getStyleFromRgb(color, hdr, opacity) {
169
- const op = opacity ?? defaultOpacity, key = `rgb-${color.r.toString()}-${color.g.toString()}-${color.b.toString()}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
171
+ const op = opacity ?? defaultOpacity, key = `rgb-${color.r.toFixed(rgbFixedPrecision)}-${color.g.toFixed(rgbFixedPrecision)}-${color.b.toFixed(rgbFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
170
172
  return getCachedStyle(key, () => (hdr ? getHdrStyleFromRgb(color, opacity) : getSdrStyleFromRgb(color, opacity)));
171
173
  }
172
174
  function getHdrStyleFromRgb(color, opacity) {
@@ -176,7 +178,7 @@ function getSdrStyleFromRgb(color, opacity) {
176
178
  return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? defaultOpacity).toString()})`;
177
179
  }
178
180
  export function getStyleFromHsl(color, hdr, opacity) {
179
- const op = opacity ?? defaultOpacity, key = `hsl-${color.h.toString()}-${color.s.toString()}-${color.l.toString()}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
181
+ const op = opacity ?? defaultOpacity, key = `hsl-${color.h.toFixed(hslFixedPrecision)}-${color.s.toFixed(hslFixedPrecision)}-${color.l.toFixed(hslFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
180
182
  return getCachedStyle(key, () => (hdr ? getHdrStyleFromHsl(color, opacity) : getSdrStyleFromHsl(color, opacity)));
181
183
  }
182
184
  function getHdrStyleFromHsl(color, opacity) {
@@ -1,6 +1,6 @@
1
1
  import { clamp, collisionVelocity, getDistances, getRandom, getRangeMax, getRangeMin, getRangeValue, randomInRangeValue, } from "./MathUtils.js";
2
2
  import { half, millisecondsToSeconds, percentDenominator } from "../Core/Utils/Constants.js";
3
- import { isArray, isNull, isObject } from "./TypeUtils.js";
3
+ import { isArray, isBoolean, isNull, isObject } from "./TypeUtils.js";
4
4
  import { AnimationMode } from "../Enums/Modes/AnimationMode.js";
5
5
  import { AnimationStatus } from "../Enums/AnimationStatus.js";
6
6
  import { DestroyType } from "../Enums/Types/DestroyType.js";
@@ -21,12 +21,6 @@ function memoize(fn) {
21
21
  return result;
22
22
  };
23
23
  }
24
- function checkSelector(element, selectors) {
25
- const res = executeOnSingleOrMultiple(selectors, selector => {
26
- return element.matches(selector);
27
- });
28
- return isArray(res) ? res.some(t => t) : res;
29
- }
30
24
  export function hasMatchMedia() {
31
25
  return typeof matchMedia !== "undefined";
32
26
  }
@@ -104,11 +98,15 @@ export function deepExtend(destination, ...sources) {
104
98
  continue;
105
99
  }
106
100
  const sourceIsArray = Array.isArray(source);
107
- if (sourceIsArray && (isObject(destination) || !destination || !Array.isArray(destination))) {
108
- destination = [];
101
+ if (sourceIsArray) {
102
+ if (!Array.isArray(destination)) {
103
+ destination = [];
104
+ }
109
105
  }
110
- else if (!sourceIsArray && (isObject(destination) || !destination || Array.isArray(destination))) {
111
- destination = {};
106
+ else {
107
+ if (!isObject(destination) || Array.isArray(destination)) {
108
+ destination = {};
109
+ }
112
110
  }
113
111
  for (const key in source) {
114
112
  if (key === "__proto__") {
@@ -123,31 +121,6 @@ export function deepExtend(destination, ...sources) {
123
121
  }
124
122
  return destination;
125
123
  }
126
- export function isDivModeEnabled(mode, divs) {
127
- return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
128
- }
129
- export function divModeExecute(mode, divs, callback) {
130
- executeOnSingleOrMultiple(divs, div => {
131
- const divMode = div.mode, divEnabled = div.enable;
132
- if (divEnabled && isInArray(mode, divMode)) {
133
- singleDivModeExecute(div, callback);
134
- }
135
- });
136
- }
137
- export function singleDivModeExecute(div, callback) {
138
- const selectors = div.selectors;
139
- executeOnSingleOrMultiple(selectors, selector => {
140
- callback(selector, div);
141
- });
142
- }
143
- export function divMode(divs, element) {
144
- if (!element || !divs) {
145
- return;
146
- }
147
- return findItemFromSingleOrMultiple(divs, div => {
148
- return checkSelector(element, div.selectors);
149
- });
150
- }
151
124
  export function circleBounceDataFromParticle(p) {
152
125
  return {
153
126
  position: p.getPosition(),
@@ -368,3 +341,27 @@ function computeFullScreenStyle(zIndex) {
368
341
  return fullScreenStyle;
369
342
  }
370
343
  export const getFullScreenStyle = memoize(computeFullScreenStyle);
344
+ export function manageListener(element, event, handler, add, options) {
345
+ if (add) {
346
+ let addOptions = { passive: true };
347
+ if (isBoolean(options)) {
348
+ addOptions.capture = options;
349
+ }
350
+ else if (options !== undefined) {
351
+ addOptions = options;
352
+ }
353
+ element.addEventListener(event, handler, addOptions);
354
+ }
355
+ else {
356
+ const removeOptions = options;
357
+ element.removeEventListener(event, handler, removeOptions);
358
+ }
359
+ }
360
+ export async function getItemsFromInitializer(container, map, initializers, force = false) {
361
+ let res = map.get(container);
362
+ if (!res || force) {
363
+ res = await Promise.all([...initializers.values()].map(t => t(container)));
364
+ map.set(container, res);
365
+ }
366
+ return res;
367
+ }
@@ -1,6 +1,4 @@
1
1
  export * from "./Core/Utils/Constants.js";
2
- export * from "./Core/Utils/ExternalInteractorBase.js";
3
- export * from "./Core/Utils/ParticlesInteractorBase.js";
4
2
  export * from "./Core/Utils/Point.js";
5
3
  export * from "./Core/Utils/Ranges.js";
6
4
  export * from "./Core/Utils/Vectors.js";
@@ -11,36 +9,20 @@ export * from "./Enums/Modes/AnimationMode.js";
11
9
  export * from "./Enums/Modes/LimitMode.js";
12
10
  export * from "./Enums/Modes/OutMode.js";
13
11
  export * from "./Enums/Modes/PixelMode.js";
14
- export * from "./Enums/Modes/ThemeMode.js";
15
- export * from "./Enums/Modes/ResponsiveMode.js";
16
12
  export * from "./Enums/Types/AlterType.js";
17
13
  export * from "./Enums/Types/DestroyType.js";
18
14
  export * from "./Enums/Types/GradientType.js";
19
- export * from "./Enums/Types/InteractorType.js";
20
15
  export * from "./Enums/Types/ParticleOutType.js";
21
16
  export * from "./Enums/Types/StartValueType.js";
22
- export * from "./Enums/Types/DivType.js";
23
17
  export * from "./Enums/Types/EasingType.js";
24
18
  export * from "./Enums/Types/EventType.js";
25
19
  export * from "./Enums/AnimationStatus.js";
26
- export * from "./Enums/InteractivityDetect.js";
27
20
  export * from "./Options/Classes/AnimatableColor.js";
28
21
  export * from "./Options/Classes/AnimationOptions.js";
29
22
  export * from "./Options/Classes/Background/Background.js";
30
23
  export * from "./Options/Classes/ColorAnimation.js";
31
24
  export * from "./Options/Classes/FullScreen/FullScreen.js";
32
25
  export * from "./Options/Classes/HslAnimation.js";
33
- export * from "./Options/Classes/Interactivity/Events/ClickEvent.js";
34
- export * from "./Options/Classes/Interactivity/Events/DivEvent.js";
35
- export * from "./Options/Classes/Interactivity/Events/ClickEvent.js";
36
- export * from "./Options/Classes/Interactivity/Events/DivEvent.js";
37
- export * from "./Options/Classes/Interactivity/Events/Events.js";
38
- export * from "./Options/Classes/Interactivity/Events/HoverEvent.js";
39
- export * from "./Options/Classes/Interactivity/Events/Parallax.js";
40
- export * from "./Options/Classes/Interactivity/Events/ResizeEvent.js";
41
- export * from "./Options/Classes/Interactivity/Interactivity.js";
42
- export * from "./Options/Classes/Interactivity/Modes/Modes.js";
43
- export * from "./Options/Classes/ManualParticle.js";
44
26
  export * from "./Options/Classes/Options.js";
45
27
  export * from "./Options/Classes/OptionsColor.js";
46
28
  export * from "./Options/Classes/Particles/Bounce/ParticlesBounce.js";
@@ -64,9 +46,7 @@ export * from "./Options/Classes/Particles/Shape/Shape.js";
64
46
  export * from "./Options/Classes/Particles/Size/Size.js";
65
47
  export * from "./Options/Classes/Particles/Size/SizeAnimation.js";
66
48
  export * from "./Options/Classes/Particles/ZIndex/ZIndex.js";
67
- export * from "./Options/Classes/Responsive.js";
68
- export * from "./Options/Classes/Theme/Theme.js";
69
- export * from "./Options/Classes/Theme/ThemeDefault.js";
49
+ export * from "./Options/Classes/ResizeEvent.js";
70
50
  export * from "./Options/Classes/ValueWithRandom.js";
71
51
  export * from "./Utils/CanvasUtils.js";
72
52
  export * from "./Utils/ColorUtils.js";
@@ -184,7 +184,7 @@ export class Canvas {
184
184
  }
185
185
  clear() {
186
186
  let pluginHandled = false;
187
- for (const plugin of this.container.plugins.values()) {
187
+ for (const plugin of this.container.plugins) {
188
188
  if (!pluginHandled && plugin.canvasClear) {
189
189
  pluginHandled = plugin.canvasClear();
190
190
  }
@@ -322,7 +322,7 @@ export class Canvas {
322
322
  }
323
323
  initPlugins() {
324
324
  this._resizePlugins = [];
325
- for (const plugin of this.container.plugins.values()) {
325
+ for (const plugin of this.container.plugins) {
326
326
  if (plugin.resize) {
327
327
  this._resizePlugins.push(plugin);
328
328
  }
@@ -380,7 +380,7 @@ export class Canvas {
380
380
  }
381
381
  paint() {
382
382
  let handled = false;
383
- for (const plugin of this.container.plugins.values()) {
383
+ for (const plugin of this.container.plugins) {
384
384
  if (handled) {
385
385
  break;
386
386
  }
@@ -1,5 +1,5 @@
1
1
  import { animate, cancelAnimation, getRangeValue } from "../Utils/MathUtils.js";
2
- import { clickRadius, defaultFps, defaultFpsLimit, millisecondsToSeconds, minCoordinate, minFpsLimit, removeDeleteCount, removeMinIndex, touchEndLengthOffset, } from "./Utils/Constants.js";
2
+ import { defaultFps, defaultFpsLimit, millisecondsToSeconds, minFpsLimit, removeDeleteCount, removeMinIndex, } from "./Utils/Constants.js";
3
3
  import { Canvas } from "./Canvas.js";
4
4
  import { EventListeners } from "./Utils/EventListeners.js";
5
5
  import { EventType } from "../Enums/Types/EventType.js";
@@ -8,7 +8,6 @@ import { Particles } from "./Particles.js";
8
8
  import { Retina } from "./Retina.js";
9
9
  import { getLogger } from "../Utils/LogUtils.js";
10
10
  import { loadOptions } from "../Utils/OptionsUtils.js";
11
- import { safeIntersectionObserver } from "../Utils/Utils.js";
12
11
  function guardCheck(container) {
13
12
  return !container.destroyed;
14
13
  }
@@ -24,22 +23,6 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
24
23
  export class Container {
25
24
  constructor(engine, id, sourceOptions) {
26
25
  this._delta = { value: 0, factor: 0 };
27
- this._intersectionManager = entries => {
28
- if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
29
- return;
30
- }
31
- for (const entry of entries) {
32
- if (entry.target !== this.interactivity.element) {
33
- continue;
34
- }
35
- if (entry.isIntersecting) {
36
- this.play();
37
- }
38
- else {
39
- this.pause();
40
- }
41
- }
42
- };
43
26
  this._nextFrame = (timestamp) => {
44
27
  try {
45
28
  if (!this._smooth &&
@@ -84,28 +67,18 @@ export class Container {
84
67
  this._lastFrameTime = 0;
85
68
  this.zLayers = 100;
86
69
  this.pageHidden = false;
87
- this._clickHandlers = new Map();
88
70
  this._sourceOptions = sourceOptions;
89
71
  this._initialSourceOptions = sourceOptions;
90
72
  this.retina = new Retina(this);
91
73
  this.canvas = new Canvas(this, this._engine);
92
74
  this.particles = new Particles(this._engine, this);
93
75
  this.pathGenerators = new Map();
94
- this.interactivity = {
95
- mouse: {
96
- clicking: false,
97
- inside: false,
98
- },
99
- };
100
- this.plugins = new Map();
76
+ this.plugins = [];
101
77
  this.effectDrawers = new Map();
102
78
  this.shapeDrawers = new Map();
103
79
  this._options = loadContainerOptions(this._engine, this);
104
80
  this.actualOptions = loadContainerOptions(this._engine, this);
105
81
  this._eventListeners = new EventListeners(this);
106
- this._intersectionObserver = safeIntersectionObserver(entries => {
107
- this._intersectionManager(entries);
108
- });
109
82
  this._engine.dispatchEvent(EventType.containerBuilt, { container: this });
110
83
  }
111
84
  get animationStatus() {
@@ -117,77 +90,6 @@ export class Container {
117
90
  get sourceOptions() {
118
91
  return this._sourceOptions;
119
92
  }
120
- addClickHandler(callback) {
121
- if (!guardCheck(this)) {
122
- return;
123
- }
124
- const el = this.interactivity.element;
125
- if (!el) {
126
- return;
127
- }
128
- const clickOrTouchHandler = (e, pos, radius) => {
129
- if (!guardCheck(this)) {
130
- return;
131
- }
132
- const pxRatio = this.retina.pixelRatio, posRetina = {
133
- x: pos.x * pxRatio,
134
- y: pos.y * pxRatio,
135
- }, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
136
- callback(e, particles);
137
- }, clickHandler = (e) => {
138
- if (!guardCheck(this)) {
139
- return;
140
- }
141
- const mouseEvent = e, pos = {
142
- x: mouseEvent.offsetX || mouseEvent.clientX,
143
- y: mouseEvent.offsetY || mouseEvent.clientY,
144
- };
145
- clickOrTouchHandler(e, pos, clickRadius);
146
- }, touchStartHandler = () => {
147
- if (!guardCheck(this)) {
148
- return;
149
- }
150
- touched = true;
151
- touchMoved = false;
152
- }, touchMoveHandler = () => {
153
- if (!guardCheck(this)) {
154
- return;
155
- }
156
- touchMoved = true;
157
- }, touchEndHandler = (e) => {
158
- if (!guardCheck(this)) {
159
- return;
160
- }
161
- if (touched && !touchMoved) {
162
- const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - touchEndLengthOffset];
163
- if (!lastTouch) {
164
- return;
165
- }
166
- const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
167
- x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
168
- y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
169
- };
170
- clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
171
- }
172
- touched = false;
173
- touchMoved = false;
174
- }, touchCancelHandler = () => {
175
- if (!guardCheck(this)) {
176
- return;
177
- }
178
- touched = false;
179
- touchMoved = false;
180
- };
181
- let touched = false, touchMoved = false;
182
- this._clickHandlers.set("click", clickHandler);
183
- this._clickHandlers.set("touchstart", touchStartHandler);
184
- this._clickHandlers.set("touchmove", touchMoveHandler);
185
- this._clickHandlers.set("touchend", touchEndHandler);
186
- this._clickHandlers.set("touchcancel", touchCancelHandler);
187
- for (const [key, handler] of this._clickHandlers) {
188
- el.addEventListener(key, handler);
189
- }
190
- }
191
93
  addLifeTime(value) {
192
94
  this._lifeTime += value;
193
95
  }
@@ -201,21 +103,11 @@ export class Container {
201
103
  alive() {
202
104
  return !this._duration || this._lifeTime <= this._duration;
203
105
  }
204
- clearClickHandlers() {
205
- if (!guardCheck(this)) {
206
- return;
207
- }
208
- for (const [key, handler] of this._clickHandlers) {
209
- this.interactivity.element?.removeEventListener(key, handler);
210
- }
211
- this._clickHandlers.clear();
212
- }
213
106
  destroy(remove = true) {
214
107
  if (!guardCheck(this)) {
215
108
  return;
216
109
  }
217
110
  this.stop();
218
- this.clearClickHandlers();
219
111
  this.particles.destroy();
220
112
  this.canvas.destroy();
221
113
  for (const effectDrawer of this.effectDrawers.values()) {
@@ -226,10 +118,14 @@ export class Container {
226
118
  shapeDrawer.destroy?.(this);
227
119
  }
228
120
  this.shapeDrawers.clear();
121
+ for (const plugin of this.plugins) {
122
+ plugin.destroy?.();
123
+ }
124
+ this.plugins.length = 0;
229
125
  this._engine.clearPlugins(this);
230
126
  this.destroyed = true;
231
127
  if (remove) {
232
- const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this);
128
+ const mainArr = this._engine.items, idx = mainArr.indexOf(this);
233
129
  if (idx >= removeMinIndex) {
234
130
  mainArr.splice(idx, removeDeleteCount);
235
131
  }
@@ -253,7 +149,7 @@ export class Container {
253
149
  });
254
150
  }
255
151
  async export(type, options = {}) {
256
- for (const plugin of this.plugins.values()) {
152
+ for (const plugin of this.plugins) {
257
153
  if (!plugin.export) {
258
154
  continue;
259
155
  }
@@ -266,15 +162,6 @@ export class Container {
266
162
  getLogger().error(`Export plugin with type ${type} not found`);
267
163
  return undefined;
268
164
  }
269
- handleClickMode(mode) {
270
- if (!guardCheck(this)) {
271
- return;
272
- }
273
- this.particles.handleClickMode(mode);
274
- for (const plugin of this.plugins.values()) {
275
- plugin.handleClickMode?.(mode);
276
- }
277
- }
278
165
  async init() {
279
166
  if (!guardCheck(this)) {
280
167
  return;
@@ -293,12 +180,21 @@ export class Container {
293
180
  this.shapeDrawers.set(type, drawer);
294
181
  }
295
182
  }
183
+ const allContainerPlugins = new Map();
184
+ for (const plugin of this._engine.plugins) {
185
+ const containerPlugin = await plugin.getPlugin(this);
186
+ if (containerPlugin.preInit) {
187
+ await containerPlugin.preInit();
188
+ }
189
+ allContainerPlugins.set(plugin, containerPlugin);
190
+ }
296
191
  await this.particles.initPlugins();
297
192
  this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
298
193
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
299
- const availablePlugins = await this._engine.getAvailablePlugins(this);
300
- for (const [id, plugin] of availablePlugins) {
301
- this.plugins.set(id, plugin);
194
+ for (const [plugin, containerPlugin] of allContainerPlugins) {
195
+ if (plugin.needsPlugin(this.actualOptions)) {
196
+ this.plugins.push(containerPlugin);
197
+ }
302
198
  }
303
199
  this.retina.init();
304
200
  this.canvas.init();
@@ -313,30 +209,23 @@ export class Container {
313
209
  this._lifeTime = 0;
314
210
  this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
315
211
  this._smooth = smooth;
212
+ for (const plugin of this.plugins) {
213
+ await plugin.init?.();
214
+ }
316
215
  for (const drawer of this.effectDrawers.values()) {
317
216
  await drawer.init?.(this);
318
217
  }
319
218
  for (const drawer of this.shapeDrawers.values()) {
320
219
  await drawer.init?.(this);
321
220
  }
322
- for (const plugin of this.plugins.values()) {
323
- await plugin.init?.();
324
- }
325
221
  this._engine.dispatchEvent(EventType.containerInit, { container: this });
326
222
  await this.particles.init();
327
223
  this.particles.setDensity();
328
- for (const plugin of this.plugins.values()) {
224
+ for (const plugin of this.plugins) {
329
225
  plugin.particlesSetup?.();
330
226
  }
331
227
  this._engine.dispatchEvent(EventType.particlesSetup, { container: this });
332
228
  }
333
- async loadTheme(name) {
334
- if (!guardCheck(this)) {
335
- return;
336
- }
337
- this._currentTheme = name;
338
- await this.refresh();
339
- }
340
229
  pause() {
341
230
  if (!guardCheck(this)) {
342
231
  return;
@@ -348,7 +237,7 @@ export class Container {
348
237
  if (this._paused) {
349
238
  return;
350
239
  }
351
- for (const plugin of this.plugins.values()) {
240
+ for (const plugin of this.plugins) {
352
241
  plugin.pause?.();
353
242
  }
354
243
  if (!this.pageHidden) {
@@ -369,7 +258,7 @@ export class Container {
369
258
  this._paused = false;
370
259
  }
371
260
  if (needsUpdate) {
372
- for (const plugin of this.plugins.values()) {
261
+ for (const plugin of this.plugins) {
373
262
  if (plugin.play) {
374
263
  plugin.play();
375
264
  }
@@ -404,10 +293,7 @@ export class Container {
404
293
  await new Promise(resolve => {
405
294
  const start = async () => {
406
295
  this._eventListeners.addListeners();
407
- if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
408
- this._intersectionObserver.observe(this.interactivity.element);
409
- }
410
- for (const plugin of this.plugins.values()) {
296
+ for (const plugin of this.plugins) {
411
297
  await plugin.start?.();
412
298
  }
413
299
  this._engine.dispatchEvent(EventType.containerStarted, { container: this });
@@ -431,26 +317,20 @@ export class Container {
431
317
  this.pause();
432
318
  this.particles.clear();
433
319
  this.canvas.stop();
434
- if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
435
- this._intersectionObserver.unobserve(this.interactivity.element);
436
- }
437
- for (const plugin of this.plugins.values()) {
320
+ for (const plugin of this.plugins) {
438
321
  plugin.stop?.();
439
322
  }
440
- for (const key of this.plugins.keys()) {
441
- this.plugins.delete(key);
442
- }
323
+ this.plugins.length = 0;
443
324
  this._sourceOptions = this._options;
444
325
  this._engine.dispatchEvent(EventType.containerStopped, { container: this });
445
326
  }
446
327
  updateActualOptions() {
447
- this.actualOptions.responsive = [];
448
- const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
449
- this.actualOptions.setTheme(this._currentTheme);
450
- if (this._responsiveMaxWidth === newMaxWidth) {
451
- return false;
328
+ let refresh = false;
329
+ for (const plugin of this.plugins) {
330
+ if (plugin.updateActualOptions) {
331
+ refresh = plugin.updateActualOptions() || refresh;
332
+ }
452
333
  }
453
- this._responsiveMaxWidth = newMaxWidth;
454
- return true;
334
+ return refresh;
455
335
  }
456
336
  }