@tsparticles/engine 4.0.0-alpha.2 → 4.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) 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 +18 -22
  5. package/browser/Core/Container.js +44 -169
  6. package/browser/Core/Engine.js +40 -61
  7. package/browser/Core/Particle.js +99 -58
  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/CanvasUtils.js +26 -83
  15. package/browser/Utils/ColorUtils.js +17 -2
  16. package/browser/Utils/MathUtils.js +3 -2
  17. package/browser/Utils/Utils.js +26 -33
  18. package/browser/exports.js +1 -21
  19. package/cjs/Core/Canvas.js +18 -22
  20. package/cjs/Core/Container.js +44 -169
  21. package/cjs/Core/Engine.js +40 -61
  22. package/cjs/Core/Particle.js +99 -58
  23. package/cjs/Core/Particles.js +36 -25
  24. package/cjs/Core/Utils/Constants.js +2 -2
  25. package/cjs/Core/Utils/EventListeners.js +5 -250
  26. package/cjs/Options/Classes/Options.js +7 -75
  27. package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -11
  28. package/cjs/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +1 -1
  29. package/cjs/Utils/CanvasUtils.js +26 -83
  30. package/cjs/Utils/ColorUtils.js +17 -2
  31. package/cjs/Utils/MathUtils.js +3 -2
  32. package/cjs/Utils/Utils.js +26 -33
  33. package/cjs/exports.js +1 -21
  34. package/dist_browser_Core_Container_js.js +6 -16
  35. package/esm/Core/Canvas.js +18 -22
  36. package/esm/Core/Container.js +44 -169
  37. package/esm/Core/Engine.js +40 -61
  38. package/esm/Core/Particle.js +99 -58
  39. package/esm/Core/Particles.js +36 -25
  40. package/esm/Core/Utils/Constants.js +2 -2
  41. package/esm/Core/Utils/EventListeners.js +5 -250
  42. package/esm/Options/Classes/Options.js +7 -75
  43. package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -11
  44. package/{browser/Options/Classes/Interactivity/Events → esm/Options/Classes}/ResizeEvent.js +1 -1
  45. package/esm/Utils/CanvasUtils.js +26 -83
  46. package/esm/Utils/ColorUtils.js +17 -2
  47. package/esm/Utils/MathUtils.js +3 -2
  48. package/esm/Utils/Utils.js +26 -33
  49. package/esm/exports.js +1 -21
  50. package/package.json +1 -1
  51. package/report.html +1 -1
  52. package/tsparticles.engine.js +16 -208
  53. package/tsparticles.engine.min.js +1 -1
  54. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  55. package/types/Core/Canvas.d.ts +3 -0
  56. package/types/Core/Container.d.ts +4 -15
  57. package/types/Core/Engine.d.ts +4 -19
  58. package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -1
  59. package/types/Core/Interfaces/IDrawParticleParams.d.ts +1 -1
  60. package/types/Core/Interfaces/IParticleOpacityData.d.ts +4 -0
  61. package/types/Core/Interfaces/IParticleRotateData.d.ts +4 -0
  62. package/types/Core/Interfaces/IParticleTransformValues.d.ts +4 -4
  63. package/types/Core/Interfaces/IParticleUpdater.d.ts +1 -1
  64. package/types/Core/Interfaces/IPlugin.d.ts +5 -1
  65. package/types/Core/Particle.d.ts +12 -2
  66. package/types/Core/Particles.d.ts +1 -5
  67. package/types/Core/Utils/Constants.d.ts +2 -2
  68. package/types/Core/Utils/EventListeners.d.ts +0 -14
  69. package/types/Options/Classes/Options.d.ts +2 -11
  70. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +0 -2
  71. package/types/Options/Classes/ResizeEvent.d.ts +9 -0
  72. package/types/Options/Interfaces/IOptions.d.ts +2 -8
  73. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -3
  74. package/types/Types/CustomEventListener.d.ts +1 -1
  75. package/types/Types/EngineInitializers.d.ts +10 -0
  76. package/types/Utils/CanvasUtils.d.ts +6 -21
  77. package/types/Utils/EventDispatcher.d.ts +1 -1
  78. package/types/Utils/Utils.d.ts +4 -6
  79. package/types/export-types.d.ts +3 -19
  80. package/types/exports.d.ts +1 -21
  81. package/umd/Core/Canvas.js +17 -21
  82. package/umd/Core/Container.js +44 -169
  83. package/umd/Core/Engine.js +41 -62
  84. package/umd/Core/Particle.js +99 -58
  85. package/umd/Core/Particles.js +37 -26
  86. package/umd/Core/Utils/Constants.js +3 -3
  87. package/umd/Core/Utils/EventListeners.js +7 -252
  88. package/umd/Options/Classes/Options.js +7 -75
  89. package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -11
  90. package/umd/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +2 -2
  91. package/umd/Utils/CanvasUtils.js +25 -82
  92. package/umd/Utils/ColorUtils.js +17 -2
  93. package/umd/Utils/MathUtils.js +3 -2
  94. package/umd/Utils/Utils.js +27 -36
  95. package/umd/exports.js +2 -22
  96. package/638.min.js +0 -2
  97. package/638.min.js.LICENSE.txt +0 -1
  98. package/browser/Core/Utils/ExternalInteractorBase.js +0 -7
  99. package/browser/Core/Utils/InteractionManager.js +0 -60
  100. package/browser/Core/Utils/ParticlesInteractorBase.js +0 -7
  101. package/browser/Enums/InteractivityDetect.js +0 -6
  102. package/browser/Enums/Modes/ResponsiveMode.js +0 -5
  103. package/browser/Enums/Modes/ThemeMode.js +0 -6
  104. package/browser/Enums/Types/DivType.js +0 -5
  105. package/browser/Enums/Types/InteractorType.js +0 -5
  106. package/browser/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  107. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  108. package/browser/Options/Classes/Interactivity/Events/Events.js +0 -30
  109. package/browser/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  110. package/browser/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  111. package/browser/Options/Classes/Interactivity/Interactivity.js +0 -22
  112. package/browser/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  113. package/browser/Options/Classes/ManualParticle.js +0 -21
  114. package/browser/Options/Classes/Responsive.js +0 -29
  115. package/browser/Options/Classes/Theme/Theme.js +0 -21
  116. package/browser/Options/Classes/Theme/ThemeDefault.js +0 -23
  117. package/browser/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  118. package/browser/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  119. package/browser/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  120. package/browser/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  121. package/browser/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  122. package/browser/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  123. package/browser/Options/Interfaces/Theme/ITheme.js +0 -1
  124. package/browser/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  125. package/cjs/Core/Interfaces/IContainerInteractivity.js +0 -1
  126. package/cjs/Core/Interfaces/IExternalInteractor.js +0 -1
  127. package/cjs/Core/Interfaces/IInteractor.js +0 -1
  128. package/cjs/Core/Interfaces/IMouseData.js +0 -1
  129. package/cjs/Core/Interfaces/IParticlesInteractor.js +0 -1
  130. package/cjs/Core/Utils/ExternalInteractorBase.js +0 -7
  131. package/cjs/Core/Utils/InteractionManager.js +0 -60
  132. package/cjs/Core/Utils/ParticlesInteractorBase.js +0 -7
  133. package/cjs/Enums/InteractivityDetect.js +0 -6
  134. package/cjs/Enums/Modes/ResponsiveMode.js +0 -5
  135. package/cjs/Enums/Modes/ThemeMode.js +0 -6
  136. package/cjs/Enums/Types/DivType.js +0 -5
  137. package/cjs/Enums/Types/InteractorType.js +0 -5
  138. package/cjs/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  139. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  140. package/cjs/Options/Classes/Interactivity/Events/Events.js +0 -30
  141. package/cjs/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  142. package/cjs/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  143. package/cjs/Options/Classes/Interactivity/Interactivity.js +0 -22
  144. package/cjs/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  145. package/cjs/Options/Classes/ManualParticle.js +0 -21
  146. package/cjs/Options/Classes/Responsive.js +0 -29
  147. package/cjs/Options/Classes/Theme/Theme.js +0 -21
  148. package/cjs/Options/Classes/Theme/ThemeDefault.js +0 -23
  149. package/cjs/Options/Interfaces/IManualParticle.js +0 -1
  150. package/cjs/Options/Interfaces/IResponsive.js +0 -1
  151. package/cjs/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  152. package/cjs/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  153. package/cjs/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  154. package/cjs/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  155. package/cjs/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  156. package/cjs/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  157. package/cjs/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  158. package/cjs/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  159. package/cjs/Options/Interfaces/Theme/ITheme.js +0 -1
  160. package/cjs/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  161. package/esm/Core/Interfaces/IContainerInteractivity.js +0 -1
  162. package/esm/Core/Interfaces/IExternalInteractor.js +0 -1
  163. package/esm/Core/Interfaces/IInteractor.js +0 -1
  164. package/esm/Core/Interfaces/IMouseData.js +0 -1
  165. package/esm/Core/Interfaces/IParticlesInteractor.js +0 -1
  166. package/esm/Core/Utils/ExternalInteractorBase.js +0 -7
  167. package/esm/Core/Utils/InteractionManager.js +0 -60
  168. package/esm/Core/Utils/ParticlesInteractorBase.js +0 -7
  169. package/esm/Enums/InteractivityDetect.js +0 -6
  170. package/esm/Enums/Modes/ResponsiveMode.js +0 -5
  171. package/esm/Enums/Modes/ThemeMode.js +0 -6
  172. package/esm/Enums/Types/DivType.js +0 -5
  173. package/esm/Enums/Types/InteractorType.js +0 -5
  174. package/esm/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  175. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  176. package/esm/Options/Classes/Interactivity/Events/Events.js +0 -30
  177. package/esm/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  178. package/esm/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  179. package/esm/Options/Classes/Interactivity/Interactivity.js +0 -22
  180. package/esm/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  181. package/esm/Options/Classes/ManualParticle.js +0 -21
  182. package/esm/Options/Classes/Responsive.js +0 -29
  183. package/esm/Options/Classes/Theme/Theme.js +0 -21
  184. package/esm/Options/Classes/Theme/ThemeDefault.js +0 -23
  185. package/esm/Options/Interfaces/IManualParticle.js +0 -1
  186. package/esm/Options/Interfaces/IResponsive.js +0 -1
  187. package/esm/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  188. package/esm/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  189. package/esm/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  190. package/esm/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  191. package/esm/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  192. package/esm/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  193. package/esm/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  194. package/esm/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  195. package/esm/Options/Interfaces/Theme/ITheme.js +0 -1
  196. package/esm/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  197. package/types/Core/Interfaces/IContainerInteractivity.d.ts +0 -6
  198. package/types/Core/Interfaces/IExternalInteractor.d.ts +0 -12
  199. package/types/Core/Interfaces/IInteractor.d.ts +0 -16
  200. package/types/Core/Interfaces/IMouseData.d.ts +0 -9
  201. package/types/Core/Interfaces/IParticlesInteractor.d.ts +0 -7
  202. package/types/Core/Utils/ExternalInteractorBase.d.ts +0 -15
  203. package/types/Core/Utils/InteractionManager.d.ts +0 -17
  204. package/types/Core/Utils/ParticlesInteractorBase.d.ts +0 -15
  205. package/types/Enums/InteractivityDetect.d.ts +0 -5
  206. package/types/Enums/Modes/ResponsiveMode.d.ts +0 -4
  207. package/types/Enums/Modes/ThemeMode.d.ts +0 -5
  208. package/types/Enums/Types/DivType.d.ts +0 -4
  209. package/types/Enums/Types/InteractorType.d.ts +0 -4
  210. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +0 -10
  211. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -13
  212. package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -16
  213. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +0 -12
  214. package/types/Options/Classes/Interactivity/Events/Parallax.d.ts +0 -10
  215. package/types/Options/Classes/Interactivity/Events/ResizeEvent.d.ts +0 -9
  216. package/types/Options/Classes/Interactivity/Interactivity.d.ts +0 -16
  217. package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +0 -12
  218. package/types/Options/Classes/ManualParticle.d.ts +0 -10
  219. package/types/Options/Classes/Responsive.d.ts +0 -12
  220. package/types/Options/Classes/Theme/Theme.d.ts +0 -12
  221. package/types/Options/Classes/Theme/ThemeDefault.d.ts +0 -11
  222. package/types/Options/Interfaces/IManualParticle.d.ts +0 -7
  223. package/types/Options/Interfaces/IResponsive.d.ts +0 -7
  224. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +0 -5
  225. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -8
  226. package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -11
  227. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +0 -7
  228. package/types/Options/Interfaces/Interactivity/Events/IParallax.d.ts +0 -5
  229. package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -9
  230. package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -4
  231. package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +0 -1
  232. package/types/Options/Interfaces/Theme/ITheme.d.ts +0 -7
  233. package/types/Options/Interfaces/Theme/IThemeDefault.d.ts +0 -6
  234. package/umd/Core/Interfaces/IMouseData.js +0 -12
  235. package/umd/Core/Interfaces/IParticlesInteractor.js +0 -12
  236. package/umd/Core/Utils/ExternalInteractorBase.js +0 -21
  237. package/umd/Core/Utils/InteractionManager.js +0 -74
  238. package/umd/Core/Utils/ParticlesInteractorBase.js +0 -21
  239. package/umd/Enums/InteractivityDetect.js +0 -19
  240. package/umd/Enums/Modes/ResponsiveMode.js +0 -18
  241. package/umd/Enums/Modes/ThemeMode.js +0 -19
  242. package/umd/Enums/Types/DivType.js +0 -18
  243. package/umd/Enums/Types/InteractorType.js +0 -18
  244. package/umd/Options/Classes/Interactivity/Events/ClickEvent.js +0 -32
  245. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +0 -41
  246. package/umd/Options/Classes/Interactivity/Events/Events.js +0 -44
  247. package/umd/Options/Classes/Interactivity/Events/HoverEvent.js +0 -35
  248. package/umd/Options/Classes/Interactivity/Events/Parallax.js +0 -36
  249. package/umd/Options/Classes/Interactivity/Interactivity.js +0 -36
  250. package/umd/Options/Classes/Interactivity/Modes/Modes.js +0 -39
  251. package/umd/Options/Classes/ManualParticle.js +0 -35
  252. package/umd/Options/Classes/Responsive.js +0 -43
  253. package/umd/Options/Classes/Theme/Theme.js +0 -35
  254. package/umd/Options/Classes/Theme/ThemeDefault.js +0 -37
  255. package/umd/Options/Interfaces/IManualParticle.js +0 -12
  256. package/umd/Options/Interfaces/IResponsive.js +0 -12
  257. package/umd/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -12
  258. package/umd/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -12
  259. package/umd/Options/Interfaces/Interactivity/Events/IEvents.js +0 -12
  260. package/umd/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -12
  261. package/umd/Options/Interfaces/Interactivity/Events/IParallax.js +0 -12
  262. package/umd/Options/Interfaces/Interactivity/IInteractivity.js +0 -12
  263. package/umd/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -12
  264. package/umd/Options/Interfaces/Interactivity/Modes/IModes.js +0 -12
  265. package/umd/Options/Interfaces/Theme/ITheme.js +0 -12
  266. package/umd/Options/Interfaces/Theme/IThemeDefault.js +0 -12
  267. /package/browser/Core/Interfaces/{IContainerInteractivity.js → IParticleOpacityData.js} +0 -0
  268. /package/browser/Core/Interfaces/{IExternalInteractor.js → IParticleRotateData.js} +0 -0
  269. /package/browser/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  270. /package/browser/{Core/Interfaces/IInteractor.js → Types/EngineInitializers.js} +0 -0
  271. /package/{browser/Core/Interfaces/IMouseData.js → cjs/Core/Interfaces/IParticleOpacityData.js} +0 -0
  272. /package/{browser/Core/Interfaces/IParticlesInteractor.js → cjs/Core/Interfaces/IParticleRotateData.js} +0 -0
  273. /package/cjs/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  274. /package/{browser/Options/Interfaces/IManualParticle.js → cjs/Types/EngineInitializers.js} +0 -0
  275. /package/{browser/Options/Interfaces/IResponsive.js → esm/Core/Interfaces/IParticleOpacityData.js} +0 -0
  276. /package/{browser/Options/Interfaces/Interactivity/Events/IClickEvent.js → esm/Core/Interfaces/IParticleRotateData.js} +0 -0
  277. /package/esm/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  278. /package/{browser/Options/Interfaces/Interactivity/Events/IDivEvent.js → esm/Types/EngineInitializers.js} +0 -0
  279. /package/types/Options/Interfaces/{Interactivity/Events/IResizeEvent.d.ts → IResizeEvent.d.ts} +0 -0
  280. /package/umd/Core/Interfaces/{IContainerInteractivity.js → IParticleOpacityData.js} +0 -0
  281. /package/umd/Core/Interfaces/{IExternalInteractor.js → IParticleRotateData.js} +0 -0
  282. /package/umd/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  283. /package/umd/{Core/Interfaces/IInteractor.js → Types/EngineInitializers.js} +0 -0
@@ -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/MathUtils.js", "./Utils/Constants.js", "./Canvas.js", "./Utils/EventListeners.js", "../Enums/Types/EventType.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/LogUtils.js", "../Utils/OptionsUtils.js", "../Utils/Utils.js"], factory);
7
+ define(["require", "exports", "../Utils/MathUtils.js", "./Utils/Constants.js", "./Canvas.js", "./Utils/EventListeners.js", "../Enums/Types/EventType.js", "../Options/Classes/Options.js", "./Particles.js", "./Retina.js", "../Utils/LogUtils.js", "../Utils/OptionsUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -20,15 +20,12 @@
20
20
  const Retina_js_1 = require("./Retina.js");
21
21
  const LogUtils_js_1 = require("../Utils/LogUtils.js");
22
22
  const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
23
- const Utils_js_1 = require("../Utils/Utils.js");
24
23
  function guardCheck(container) {
25
24
  return !container.destroyed;
26
25
  }
27
- function initDelta(value, fpsLimit = Constants_js_1.defaultFps, smooth = false) {
28
- return {
29
- value,
30
- factor: smooth ? Constants_js_1.defaultFps / fpsLimit : (Constants_js_1.defaultFps * value) / Constants_js_1.millisecondsToSeconds,
31
- };
26
+ function updateDelta(delta, value, fpsLimit = Constants_js_1.defaultFps, smooth = false) {
27
+ delta.value = value;
28
+ delta.factor = smooth ? Constants_js_1.defaultFps / fpsLimit : (Constants_js_1.defaultFps * value) / Constants_js_1.millisecondsToSeconds;
32
29
  }
33
30
  function loadContainerOptions(engine, container, ...sourceOptionsArr) {
34
31
  const options = new Options_js_1.Options(engine, container);
@@ -37,22 +34,7 @@
37
34
  }
38
35
  class Container {
39
36
  constructor(engine, id, sourceOptions) {
40
- this._intersectionManager = entries => {
41
- if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
42
- return;
43
- }
44
- for (const entry of entries) {
45
- if (entry.target !== this.interactivity.element) {
46
- continue;
47
- }
48
- if (entry.isIntersecting) {
49
- this.play();
50
- }
51
- else {
52
- this.pause();
53
- }
54
- }
55
- };
37
+ this._delta = { value: 0, factor: 0 };
56
38
  this._nextFrame = (timestamp) => {
57
39
  try {
58
40
  if (!this._smooth &&
@@ -62,14 +44,14 @@
62
44
  return;
63
45
  }
64
46
  this._lastFrameTime ??= timestamp;
65
- const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
66
- this.addLifeTime(delta.value);
47
+ updateDelta(this._delta, timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
48
+ this.addLifeTime(this._delta.value);
67
49
  this._lastFrameTime = timestamp;
68
- if (delta.value > Constants_js_1.millisecondsToSeconds) {
50
+ if (this._delta.value > Constants_js_1.millisecondsToSeconds) {
69
51
  this.draw(false);
70
52
  return;
71
53
  }
72
- this.canvas.drawParticles(delta);
54
+ this.canvas.drawParticles(this._delta);
73
55
  if (!this.alive()) {
74
56
  this.destroy();
75
57
  return;
@@ -97,28 +79,18 @@
97
79
  this._lastFrameTime = 0;
98
80
  this.zLayers = 100;
99
81
  this.pageHidden = false;
100
- this._clickHandlers = new Map();
101
82
  this._sourceOptions = sourceOptions;
102
83
  this._initialSourceOptions = sourceOptions;
103
84
  this.retina = new Retina_js_1.Retina(this);
104
85
  this.canvas = new Canvas_js_1.Canvas(this, this._engine);
105
86
  this.particles = new Particles_js_1.Particles(this._engine, this);
106
87
  this.pathGenerators = new Map();
107
- this.interactivity = {
108
- mouse: {
109
- clicking: false,
110
- inside: false,
111
- },
112
- };
113
- this.plugins = new Map();
88
+ this.plugins = [];
114
89
  this.effectDrawers = new Map();
115
90
  this.shapeDrawers = new Map();
116
91
  this._options = loadContainerOptions(this._engine, this);
117
92
  this.actualOptions = loadContainerOptions(this._engine, this);
118
93
  this._eventListeners = new EventListeners_js_1.EventListeners(this);
119
- this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(entries => {
120
- this._intersectionManager(entries);
121
- });
122
94
  this._engine.dispatchEvent(EventType_js_1.EventType.containerBuilt, { container: this });
123
95
  }
124
96
  get animationStatus() {
@@ -130,77 +102,6 @@
130
102
  get sourceOptions() {
131
103
  return this._sourceOptions;
132
104
  }
133
- addClickHandler(callback) {
134
- if (!guardCheck(this)) {
135
- return;
136
- }
137
- const el = this.interactivity.element;
138
- if (!el) {
139
- return;
140
- }
141
- const clickOrTouchHandler = (e, pos, radius) => {
142
- if (!guardCheck(this)) {
143
- return;
144
- }
145
- const pxRatio = this.retina.pixelRatio, posRetina = {
146
- x: pos.x * pxRatio,
147
- y: pos.y * pxRatio,
148
- }, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
149
- callback(e, particles);
150
- }, clickHandler = (e) => {
151
- if (!guardCheck(this)) {
152
- return;
153
- }
154
- const mouseEvent = e, pos = {
155
- x: mouseEvent.offsetX || mouseEvent.clientX,
156
- y: mouseEvent.offsetY || mouseEvent.clientY,
157
- };
158
- clickOrTouchHandler(e, pos, Constants_js_1.clickRadius);
159
- }, touchStartHandler = () => {
160
- if (!guardCheck(this)) {
161
- return;
162
- }
163
- touched = true;
164
- touchMoved = false;
165
- }, touchMoveHandler = () => {
166
- if (!guardCheck(this)) {
167
- return;
168
- }
169
- touchMoved = true;
170
- }, touchEndHandler = (e) => {
171
- if (!guardCheck(this)) {
172
- return;
173
- }
174
- if (touched && !touchMoved) {
175
- const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - Constants_js_1.touchEndLengthOffset];
176
- if (!lastTouch) {
177
- return;
178
- }
179
- const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
180
- x: lastTouch.clientX - (canvasRect ? canvasRect.left : Constants_js_1.minCoordinate),
181
- y: lastTouch.clientY - (canvasRect ? canvasRect.top : Constants_js_1.minCoordinate),
182
- };
183
- clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
184
- }
185
- touched = false;
186
- touchMoved = false;
187
- }, touchCancelHandler = () => {
188
- if (!guardCheck(this)) {
189
- return;
190
- }
191
- touched = false;
192
- touchMoved = false;
193
- };
194
- let touched = false, touchMoved = false;
195
- this._clickHandlers.set("click", clickHandler);
196
- this._clickHandlers.set("touchstart", touchStartHandler);
197
- this._clickHandlers.set("touchmove", touchMoveHandler);
198
- this._clickHandlers.set("touchend", touchEndHandler);
199
- this._clickHandlers.set("touchcancel", touchCancelHandler);
200
- for (const [key, handler] of this._clickHandlers) {
201
- el.addEventListener(key, handler);
202
- }
203
- }
204
105
  addLifeTime(value) {
205
106
  this._lifeTime += value;
206
107
  }
@@ -214,39 +115,29 @@
214
115
  alive() {
215
116
  return !this._duration || this._lifeTime <= this._duration;
216
117
  }
217
- clearClickHandlers() {
218
- if (!guardCheck(this)) {
219
- return;
220
- }
221
- for (const [key, handler] of this._clickHandlers) {
222
- this.interactivity.element?.removeEventListener(key, handler);
223
- }
224
- this._clickHandlers.clear();
225
- }
226
118
  destroy(remove = true) {
227
119
  if (!guardCheck(this)) {
228
120
  return;
229
121
  }
230
122
  this.stop();
231
- this.clearClickHandlers();
232
123
  this.particles.destroy();
233
124
  this.canvas.destroy();
234
125
  for (const effectDrawer of this.effectDrawers.values()) {
235
126
  effectDrawer.destroy?.(this);
236
127
  }
128
+ this.effectDrawers.clear();
237
129
  for (const shapeDrawer of this.shapeDrawers.values()) {
238
130
  shapeDrawer.destroy?.(this);
239
131
  }
240
- for (const key of this.effectDrawers.keys()) {
241
- this.effectDrawers.delete(key);
242
- }
243
- for (const key of this.shapeDrawers.keys()) {
244
- this.shapeDrawers.delete(key);
132
+ this.shapeDrawers.clear();
133
+ for (const plugin of this.plugins) {
134
+ plugin.destroy?.();
245
135
  }
136
+ this.plugins.length = 0;
246
137
  this._engine.clearPlugins(this);
247
138
  this.destroyed = true;
248
139
  if (remove) {
249
- const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this);
140
+ const mainArr = this._engine.items, idx = mainArr.indexOf(this);
250
141
  if (idx >= Constants_js_1.removeMinIndex) {
251
142
  mainArr.splice(idx, Constants_js_1.removeDeleteCount);
252
143
  }
@@ -270,7 +161,7 @@
270
161
  });
271
162
  }
272
163
  async export(type, options = {}) {
273
- for (const plugin of this.plugins.values()) {
164
+ for (const plugin of this.plugins) {
274
165
  if (!plugin.export) {
275
166
  continue;
276
167
  }
@@ -283,15 +174,6 @@
283
174
  (0, LogUtils_js_1.getLogger)().error(`Export plugin with type ${type} not found`);
284
175
  return undefined;
285
176
  }
286
- handleClickMode(mode) {
287
- if (!guardCheck(this)) {
288
- return;
289
- }
290
- this.particles.handleClickMode(mode);
291
- for (const plugin of this.plugins.values()) {
292
- plugin.handleClickMode?.(mode);
293
- }
294
- }
295
177
  async init() {
296
178
  if (!guardCheck(this)) {
297
179
  return;
@@ -310,12 +192,21 @@
310
192
  this.shapeDrawers.set(type, drawer);
311
193
  }
312
194
  }
195
+ const allContainerPlugins = new Map();
196
+ for (const plugin of this._engine.plugins) {
197
+ const containerPlugin = await plugin.getPlugin(this);
198
+ if (containerPlugin.preInit) {
199
+ await containerPlugin.preInit();
200
+ }
201
+ allContainerPlugins.set(plugin, containerPlugin);
202
+ }
313
203
  await this.particles.initPlugins();
314
204
  this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
315
205
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
316
- const availablePlugins = await this._engine.getAvailablePlugins(this);
317
- for (const [id, plugin] of availablePlugins) {
318
- this.plugins.set(id, plugin);
206
+ for (const [plugin, containerPlugin] of allContainerPlugins) {
207
+ if (plugin.needsPlugin(this.actualOptions)) {
208
+ this.plugins.push(containerPlugin);
209
+ }
319
210
  }
320
211
  this.retina.init();
321
212
  this.canvas.init();
@@ -330,30 +221,23 @@
330
221
  this._lifeTime = 0;
331
222
  this.fpsLimit = fpsLimit > Constants_js_1.minFpsLimit ? fpsLimit : Constants_js_1.defaultFpsLimit;
332
223
  this._smooth = smooth;
224
+ for (const plugin of this.plugins) {
225
+ await plugin.init?.();
226
+ }
333
227
  for (const drawer of this.effectDrawers.values()) {
334
228
  await drawer.init?.(this);
335
229
  }
336
230
  for (const drawer of this.shapeDrawers.values()) {
337
231
  await drawer.init?.(this);
338
232
  }
339
- for (const plugin of this.plugins.values()) {
340
- await plugin.init?.();
341
- }
342
233
  this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
343
234
  await this.particles.init();
344
235
  this.particles.setDensity();
345
- for (const plugin of this.plugins.values()) {
236
+ for (const plugin of this.plugins) {
346
237
  plugin.particlesSetup?.();
347
238
  }
348
239
  this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
349
240
  }
350
- async loadTheme(name) {
351
- if (!guardCheck(this)) {
352
- return;
353
- }
354
- this._currentTheme = name;
355
- await this.refresh();
356
- }
357
241
  pause() {
358
242
  if (!guardCheck(this)) {
359
243
  return;
@@ -365,7 +249,7 @@
365
249
  if (this._paused) {
366
250
  return;
367
251
  }
368
- for (const plugin of this.plugins.values()) {
252
+ for (const plugin of this.plugins) {
369
253
  plugin.pause?.();
370
254
  }
371
255
  if (!this.pageHidden) {
@@ -386,7 +270,7 @@
386
270
  this._paused = false;
387
271
  }
388
272
  if (needsUpdate) {
389
- for (const plugin of this.plugins.values()) {
273
+ for (const plugin of this.plugins) {
390
274
  if (plugin.play) {
391
275
  plugin.play();
392
276
  }
@@ -421,10 +305,7 @@
421
305
  await new Promise(resolve => {
422
306
  const start = async () => {
423
307
  this._eventListeners.addListeners();
424
- if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
425
- this._intersectionObserver.observe(this.interactivity.element);
426
- }
427
- for (const plugin of this.plugins.values()) {
308
+ for (const plugin of this.plugins) {
428
309
  await plugin.start?.();
429
310
  }
430
311
  this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
@@ -448,27 +329,21 @@
448
329
  this.pause();
449
330
  this.particles.clear();
450
331
  this.canvas.stop();
451
- if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
452
- this._intersectionObserver.unobserve(this.interactivity.element);
453
- }
454
- for (const plugin of this.plugins.values()) {
332
+ for (const plugin of this.plugins) {
455
333
  plugin.stop?.();
456
334
  }
457
- for (const key of this.plugins.keys()) {
458
- this.plugins.delete(key);
459
- }
335
+ this.plugins.length = 0;
460
336
  this._sourceOptions = this._options;
461
337
  this._engine.dispatchEvent(EventType_js_1.EventType.containerStopped, { container: this });
462
338
  }
463
339
  updateActualOptions() {
464
- this.actualOptions.responsive = [];
465
- const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
466
- this.actualOptions.setTheme(this._currentTheme);
467
- if (this._responsiveMaxWidth === newMaxWidth) {
468
- return false;
340
+ let refresh = false;
341
+ for (const plugin of this.plugins) {
342
+ if (plugin.updateActualOptions) {
343
+ refresh = plugin.updateActualOptions() || refresh;
344
+ }
469
345
  }
470
- this._responsiveMaxWidth = newMaxWidth;
471
- return true;
346
+ return refresh;
472
347
  }
473
348
  }
474
349
  exports.Container = Container;
@@ -50,14 +50,7 @@ var __importStar = (this && this.__importStar) || (function () {
50
50
  const EventType_js_1 = require("../Enums/Types/EventType.js");
51
51
  const LogUtils_js_1 = require("../Utils/LogUtils.js");
52
52
  const MathUtils_js_1 = require("../Utils/MathUtils.js");
53
- async function getItemsFromInitializer(container, map, initializers, force = false) {
54
- let res = map.get(container);
55
- if (!res || force) {
56
- res = await Promise.all([...initializers.values()].map(t => t(container)));
57
- map.set(container, res);
58
- }
59
- return res;
60
- }
53
+ const fullPercent = "100%";
61
54
  async function getDataFromUrl(data) {
62
55
  const url = (0, Utils_js_1.itemFromSingleOrMultiple)(data.url, data.index);
63
56
  if (!url) {
@@ -71,6 +64,7 @@ var __importStar = (this && this.__importStar) || (function () {
71
64
  return data.fallback;
72
65
  }
73
66
  const getCanvasFromContainer = (domContainer) => {
67
+ const documentSafe = (0, Utils_js_1.safeDocument)();
74
68
  let canvasEl;
75
69
  if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === Constants_js_1.canvasTag) {
76
70
  canvasEl = domContainer;
@@ -83,28 +77,24 @@ var __importStar = (this && this.__importStar) || (function () {
83
77
  canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
84
78
  }
85
79
  else {
86
- canvasEl = (0, Utils_js_1.safeDocument)().createElement(Constants_js_1.canvasTag);
80
+ canvasEl = documentSafe.createElement(Constants_js_1.canvasTag);
87
81
  canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
88
82
  domContainer.appendChild(canvasEl);
89
83
  }
90
84
  }
91
- const fullPercent = "100%";
92
- if (!canvasEl.style.width) {
93
- canvasEl.style.width = fullPercent;
94
- }
95
- if (!canvasEl.style.height) {
96
- canvasEl.style.height = fullPercent;
97
- }
85
+ canvasEl.style.width ||= fullPercent;
86
+ canvasEl.style.height ||= fullPercent;
98
87
  return canvasEl;
99
88
  }, getDomContainer = (id, source) => {
100
- let domContainer = source ?? (0, Utils_js_1.safeDocument)().getElementById(id);
89
+ const documentSafe = (0, Utils_js_1.safeDocument)();
90
+ let domContainer = source ?? documentSafe.getElementById(id);
101
91
  if (domContainer) {
102
92
  return domContainer;
103
93
  }
104
- domContainer = (0, Utils_js_1.safeDocument)().createElement("div");
94
+ domContainer = documentSafe.createElement("div");
105
95
  domContainer.id = id;
106
96
  domContainer.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
107
- (0, Utils_js_1.safeDocument)().body.append(domContainer);
97
+ documentSafe.body.append(domContainer);
108
98
  return domContainer;
109
99
  };
110
100
  class Engine {
@@ -118,11 +108,9 @@ var __importStar = (this && this.__importStar) || (function () {
118
108
  this.colorManagers = new Map();
119
109
  this.easingFunctions = new Map();
120
110
  this._initializers = {
121
- interactors: new Map(),
122
111
  movers: new Map(),
123
112
  updaters: new Map(),
124
113
  };
125
- this.interactors = new Map();
126
114
  this.movers = new Map();
127
115
  this.updaters = new Map();
128
116
  this.presets = new Map();
@@ -141,7 +129,7 @@ var __importStar = (this && this.__importStar) || (function () {
141
129
  return this._domArray;
142
130
  }
143
131
  get version() {
144
- return "4.0.0-alpha.2";
132
+ return "4.0.0-alpha.4";
145
133
  }
146
134
  addColorManager(manager) {
147
135
  this.colorManagers.set(manager.key, manager);
@@ -166,9 +154,6 @@ var __importStar = (this && this.__importStar) || (function () {
166
154
  addEventListener(type, listener) {
167
155
  this._eventDispatcher.addEventListener(type, listener);
168
156
  }
169
- addInteractor(name, interactorInitializer) {
170
- this._initializers.interactors.set(name, interactorInitializer);
171
- }
172
157
  addMover(name, moverInitializer) {
173
158
  this._initializers.movers.set(name, moverInitializer);
174
159
  }
@@ -210,37 +195,18 @@ var __importStar = (this && this.__importStar) || (function () {
210
195
  clearPlugins(container) {
211
196
  this.updaters.delete(container);
212
197
  this.movers.delete(container);
213
- this.interactors.delete(container);
214
198
  }
215
199
  dispatchEvent(type, args) {
216
200
  this._eventDispatcher.dispatchEvent(type, args);
217
201
  }
218
- dom() {
219
- return this.items;
220
- }
221
- domItem(index) {
222
- return this.item(index);
223
- }
224
- async getAvailablePlugins(container) {
225
- const res = new Map();
226
- for (const plugin of this.plugins) {
227
- if (plugin.needsPlugin(container.actualOptions)) {
228
- res.set(plugin.id, await plugin.getPlugin(container));
229
- }
230
- }
231
- return res;
232
- }
233
202
  getEasing(name) {
234
203
  return this.easingFunctions.get(name) ?? ((value) => value);
235
204
  }
236
205
  getEffectDrawer(type) {
237
206
  return this.effectDrawers.get(type);
238
207
  }
239
- async getInteractors(container, force = false) {
240
- return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
241
- }
242
208
  async getMovers(container, force = false) {
243
- return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
209
+ return (0, Utils_js_1.getItemsFromInitializer)(container, this.movers, this._initializers.movers, force);
244
210
  }
245
211
  getPathGenerator(type) {
246
212
  return this.pathGenerators.get(type);
@@ -261,16 +227,42 @@ var __importStar = (this && this.__importStar) || (function () {
261
227
  return this.shapeDrawers.keys();
262
228
  }
263
229
  async getUpdaters(container, force = false) {
264
- return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
230
+ return (0, Utils_js_1.getItemsFromInitializer)(container, this.updaters, this._initializers.updaters, force);
265
231
  }
266
232
  async init() {
267
233
  if (this._initialized) {
268
234
  return;
269
235
  }
270
- for (const loadPromise of this._loadPromises) {
271
- await loadPromise(this);
236
+ const executed = new Set(), allLoaders = new Set(this._loadPromises), stack = [...allLoaders];
237
+ while (stack.length) {
238
+ const loader = stack.shift();
239
+ if (!loader) {
240
+ continue;
241
+ }
242
+ if (executed.has(loader)) {
243
+ continue;
244
+ }
245
+ executed.add(loader);
246
+ const inner = [], origRegister = this.register.bind(this);
247
+ this.register = (...loaders) => {
248
+ inner.push(...loaders);
249
+ for (const loader of loaders) {
250
+ allLoaders.add(loader);
251
+ }
252
+ };
253
+ try {
254
+ await loader(this);
255
+ }
256
+ finally {
257
+ this.register = origRegister;
258
+ }
259
+ stack.unshift(...inner);
260
+ this._loadPromises.delete(loader);
272
261
  }
273
262
  this._loadPromises.clear();
263
+ for (const loader of allLoaders) {
264
+ this._loadPromises.add(loader);
265
+ }
274
266
  this._initialized = true;
275
267
  }
276
268
  item(index) {
@@ -283,6 +275,7 @@ var __importStar = (this && this.__importStar) || (function () {
283
275
  }
284
276
  async load(params) {
285
277
  await this.init();
278
+ this._loadPromises.clear();
286
279
  const { Container } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Container.js"))) : new Promise((resolve_1, reject_1) => { require(["./Container.js"], resolve_1, reject_1); }).then(__importStar)), id = params.id ??
287
280
  params.element?.id ??
288
281
  `tsparticles${Math.floor((0, MathUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container(this, id, currentOptions);
@@ -301,11 +294,6 @@ var __importStar = (this && this.__importStar) || (function () {
301
294
  await newItem.start();
302
295
  return newItem;
303
296
  }
304
- loadOptions(options, sourceOptions) {
305
- this.plugins.forEach(plugin => {
306
- plugin.loadOptions(options, sourceOptions);
307
- });
308
- }
309
297
  loadParticlesOptions(container, options, ...sourceOptions) {
310
298
  const updaters = this.updaters.get(container);
311
299
  if (!updaters) {
@@ -330,15 +318,6 @@ var __importStar = (this && this.__importStar) || (function () {
330
318
  removeEventListener(type, listener) {
331
319
  this._eventDispatcher.removeEventListener(type, listener);
332
320
  }
333
- setOnClickHandler(callback) {
334
- const { items } = this;
335
- if (!items.length) {
336
- throw new Error("Click handlers can only be set after calling tsParticles.load()");
337
- }
338
- items.forEach(item => {
339
- item.addClickHandler(callback);
340
- });
341
- }
342
321
  }
343
322
  exports.Engine = Engine;
344
323
  });