@tsparticles/engine 3.0.0-alpha.1 → 3.0.0-beta.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 (329) hide show
  1. package/README.md +244 -188
  2. package/browser/Core/Canvas.js +271 -241
  3. package/browser/Core/Container.js +90 -106
  4. package/browser/Core/Engine.js +271 -0
  5. package/browser/Core/Particle.js +158 -165
  6. package/browser/Core/Particles.js +148 -143
  7. package/browser/Core/Retina.js +15 -13
  8. package/browser/Core/Utils/Circle.js +10 -6
  9. package/browser/Core/Utils/Constants.js +4 -3
  10. package/browser/Core/Utils/EventListeners.js +258 -234
  11. package/browser/Core/Utils/InteractionManager.js +6 -16
  12. package/browser/Core/Utils/QuadTree.js +14 -20
  13. package/browser/Core/Utils/Vector3d.js +17 -9
  14. package/browser/Options/Classes/AnimatableColor.js +2 -1
  15. package/browser/Options/Classes/AnimationOptions.js +4 -3
  16. package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
  17. package/browser/Options/Classes/ColorAnimation.js +4 -0
  18. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
  19. package/browser/Options/Classes/Interactivity/Events/Events.js +5 -24
  20. package/browser/Options/Classes/Interactivity/Interactivity.js +1 -8
  21. package/browser/Options/Classes/Interactivity/Modes/Modes.js +11 -8
  22. package/browser/Options/Classes/ManualParticle.js +5 -6
  23. package/browser/Options/Classes/Options.js +19 -39
  24. package/browser/Options/Classes/OptionsColor.js +3 -2
  25. package/browser/Options/Classes/Particles/Collisions/Collisions.js +5 -0
  26. package/browser/Options/Classes/Particles/Move/Move.js +11 -41
  27. package/browser/Options/Classes/Particles/Move/MoveAttract.js +9 -20
  28. package/browser/Options/Classes/Particles/Move/MoveTrail.js +2 -8
  29. package/browser/Options/Classes/Particles/Move/OutModes.js +4 -5
  30. package/browser/Options/Classes/Particles/Move/Spin.js +3 -1
  31. package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
  32. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
  33. package/browser/Options/Classes/Particles/Opacity/Opacity.js +11 -7
  34. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
  35. package/browser/Options/Classes/Particles/ParticlesOptions.js +6 -11
  36. package/browser/Options/Classes/Particles/Shape/Shape.js +9 -10
  37. package/browser/Options/Classes/Particles/Size/Size.js +11 -7
  38. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
  39. package/browser/Options/Classes/ValueWithRandom.js +4 -17
  40. package/browser/Utils/CanvasUtils.js +18 -54
  41. package/browser/Utils/ColorUtils.js +17 -19
  42. package/browser/Utils/EventDispatcher.js +7 -6
  43. package/browser/Utils/HslColorManager.js +2 -4
  44. package/browser/Utils/NumberUtils.js +41 -45
  45. package/browser/Utils/RgbColorManager.js +2 -4
  46. package/browser/Utils/Utils.js +133 -62
  47. package/browser/bundle.js +4 -97
  48. package/browser/export-types.js +97 -0
  49. package/browser/exports.js +89 -0
  50. package/browser/index.js +8 -199
  51. package/browser/init.js +12 -0
  52. package/cjs/Core/Canvas.js +269 -239
  53. package/cjs/Core/Container.js +90 -106
  54. package/cjs/Core/Engine.js +275 -0
  55. package/cjs/Core/Particle.js +157 -164
  56. package/cjs/Core/Particles.js +148 -143
  57. package/cjs/Core/Retina.js +15 -13
  58. package/cjs/Core/Utils/Circle.js +10 -6
  59. package/cjs/Core/Utils/Constants.js +5 -4
  60. package/cjs/Core/Utils/EventListeners.js +257 -233
  61. package/cjs/Core/Utils/InteractionManager.js +6 -16
  62. package/cjs/Core/Utils/QuadTree.js +14 -20
  63. package/cjs/Core/Utils/Vector3d.js +17 -9
  64. package/cjs/Options/Classes/AnimatableColor.js +2 -1
  65. package/cjs/Options/Classes/AnimationOptions.js +4 -3
  66. package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
  67. package/cjs/Options/Classes/ColorAnimation.js +4 -0
  68. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
  69. package/cjs/Options/Classes/Interactivity/Events/Events.js +5 -24
  70. package/cjs/Options/Classes/Interactivity/Interactivity.js +1 -8
  71. package/cjs/Options/Classes/Interactivity/Modes/Modes.js +11 -8
  72. package/cjs/Options/Classes/ManualParticle.js +5 -6
  73. package/cjs/Options/Classes/Options.js +18 -38
  74. package/cjs/Options/Classes/OptionsColor.js +3 -2
  75. package/cjs/Options/Classes/Particles/Collisions/Collisions.js +5 -0
  76. package/cjs/Options/Classes/Particles/Move/Move.js +11 -41
  77. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +9 -20
  78. package/cjs/Options/Classes/Particles/Move/MoveTrail.js +2 -8
  79. package/cjs/Options/Classes/Particles/Move/OutModes.js +4 -5
  80. package/cjs/Options/Classes/Particles/Move/Spin.js +3 -1
  81. package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
  82. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
  83. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +10 -6
  84. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
  85. package/cjs/Options/Classes/Particles/ParticlesOptions.js +6 -11
  86. package/cjs/Options/Classes/Particles/Shape/Shape.js +9 -10
  87. package/cjs/Options/Classes/Particles/Size/Size.js +11 -7
  88. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
  89. package/cjs/Options/Classes/ValueWithRandom.js +4 -17
  90. package/cjs/Utils/CanvasUtils.js +21 -58
  91. package/cjs/Utils/ColorUtils.js +16 -18
  92. package/cjs/Utils/EventDispatcher.js +7 -6
  93. package/cjs/Utils/HslColorManager.js +2 -4
  94. package/cjs/Utils/NumberUtils.js +41 -45
  95. package/cjs/Utils/RgbColorManager.js +2 -4
  96. package/cjs/Utils/Utils.js +146 -66
  97. package/cjs/bundle.js +4 -97
  98. package/cjs/export-types.js +113 -0
  99. package/cjs/exports.js +105 -0
  100. package/cjs/index.js +8 -199
  101. package/cjs/init.js +16 -0
  102. package/esm/Core/Canvas.js +271 -241
  103. package/esm/Core/Container.js +90 -106
  104. package/esm/Core/Engine.js +271 -0
  105. package/esm/Core/Particle.js +158 -165
  106. package/esm/Core/Particles.js +148 -143
  107. package/esm/Core/Retina.js +15 -13
  108. package/esm/Core/Utils/Circle.js +10 -6
  109. package/esm/Core/Utils/Constants.js +4 -3
  110. package/esm/Core/Utils/EventListeners.js +258 -234
  111. package/esm/Core/Utils/InteractionManager.js +6 -16
  112. package/esm/Core/Utils/QuadTree.js +14 -20
  113. package/esm/Core/Utils/Vector3d.js +17 -9
  114. package/esm/Options/Classes/AnimatableColor.js +2 -1
  115. package/esm/Options/Classes/AnimationOptions.js +4 -3
  116. package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +2 -1
  117. package/esm/Options/Classes/ColorAnimation.js +4 -0
  118. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -24
  119. package/esm/Options/Classes/Interactivity/Events/Events.js +5 -24
  120. package/esm/Options/Classes/Interactivity/Interactivity.js +1 -8
  121. package/esm/Options/Classes/Interactivity/Modes/Modes.js +11 -8
  122. package/esm/Options/Classes/ManualParticle.js +5 -6
  123. package/esm/Options/Classes/Options.js +19 -39
  124. package/esm/Options/Classes/OptionsColor.js +3 -2
  125. package/esm/Options/Classes/Particles/Collisions/Collisions.js +5 -0
  126. package/esm/Options/Classes/Particles/Move/Move.js +11 -41
  127. package/esm/Options/Classes/Particles/Move/MoveAttract.js +9 -20
  128. package/esm/Options/Classes/Particles/Move/MoveTrail.js +2 -8
  129. package/esm/Options/Classes/Particles/Move/OutModes.js +4 -5
  130. package/esm/Options/Classes/Particles/Move/Spin.js +3 -1
  131. package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
  132. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
  133. package/esm/Options/Classes/Particles/Opacity/Opacity.js +11 -7
  134. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
  135. package/esm/Options/Classes/Particles/ParticlesOptions.js +6 -11
  136. package/esm/Options/Classes/Particles/Shape/Shape.js +9 -10
  137. package/esm/Options/Classes/Particles/Size/Size.js +11 -7
  138. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
  139. package/esm/Options/Classes/ValueWithRandom.js +4 -17
  140. package/esm/Utils/CanvasUtils.js +18 -54
  141. package/esm/Utils/ColorUtils.js +17 -19
  142. package/esm/Utils/EventDispatcher.js +7 -6
  143. package/esm/Utils/HslColorManager.js +2 -4
  144. package/esm/Utils/NumberUtils.js +41 -45
  145. package/esm/Utils/RgbColorManager.js +2 -4
  146. package/esm/Utils/Utils.js +133 -62
  147. package/esm/bundle.js +4 -97
  148. package/esm/export-types.js +97 -0
  149. package/esm/exports.js +89 -0
  150. package/esm/index.js +8 -199
  151. package/esm/init.js +12 -0
  152. package/package.json +17 -2
  153. package/report.html +4 -4
  154. package/scripts/install.js +90 -33
  155. package/tsparticles.engine.js +1832 -2007
  156. package/tsparticles.engine.min.js +1 -1
  157. package/tsparticles.engine.min.js.LICENSE.txt +1 -10
  158. package/types/Core/Canvas.d.ts +20 -16
  159. package/types/Core/Container.d.ts +10 -14
  160. package/types/Core/Engine.d.ts +71 -0
  161. package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -0
  162. package/types/Core/Interfaces/ICoordinates.d.ts +2 -2
  163. package/types/Core/Interfaces/IDimension.d.ts +2 -2
  164. package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -1
  165. package/types/Core/Interfaces/IParticleUpdater.d.ts +0 -2
  166. package/types/Core/Interfaces/IParticleValueAnimation.d.ts +2 -0
  167. package/types/Core/Interfaces/IPlugin.d.ts +4 -3
  168. package/types/Core/Particle.d.ts +7 -7
  169. package/types/Core/Particles.d.ts +14 -11
  170. package/types/Core/Utils/Constants.d.ts +4 -3
  171. package/types/Core/Utils/EventListeners.d.ts +20 -18
  172. package/types/Core/Utils/InteractionManager.d.ts +1 -1
  173. package/types/Core/Utils/QuadTree.d.ts +2 -5
  174. package/types/Core/Utils/Vector3d.d.ts +2 -1
  175. package/types/Enums/Modes/{SizeMode.d.ts → PixelMode.d.ts} +1 -1
  176. package/types/Options/Classes/AnimationOptions.d.ts +1 -1
  177. package/types/Options/Classes/ColorAnimation.d.ts +1 -0
  178. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -6
  179. package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -6
  180. package/types/Options/Classes/Interactivity/Interactivity.d.ts +1 -3
  181. package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +1 -1
  182. package/types/Options/Classes/Options.d.ts +5 -12
  183. package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +2 -0
  184. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -11
  185. package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -4
  186. package/types/Options/Classes/Particles/Move/MoveCenter.d.ts +2 -2
  187. package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +0 -3
  188. package/types/Options/Classes/Particles/Number/ParticlesDensity.d.ts +0 -6
  189. package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +0 -2
  190. package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +4 -4
  191. package/types/Options/Classes/Particles/Opacity/OpacityAnimation.d.ts +0 -2
  192. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +1 -1
  193. package/types/Options/Classes/Particles/Size/Size.d.ts +4 -4
  194. package/types/Options/Classes/Particles/Size/SizeAnimation.d.ts +0 -2
  195. package/types/Options/Classes/Responsive.d.ts +3 -3
  196. package/types/Options/Classes/Theme/Theme.d.ts +2 -2
  197. package/types/Options/Classes/ValueWithRandom.d.ts +2 -6
  198. package/types/Options/Interfaces/IAnimation.d.ts +1 -1
  199. package/types/Options/Interfaces/IOptions.d.ts +1 -4
  200. package/types/Options/Interfaces/IResponsive.d.ts +4 -3
  201. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -3
  202. package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -3
  203. package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -1
  204. package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -1
  205. package/types/Options/Interfaces/Particles/Collisions/ICollisions.d.ts +2 -0
  206. package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -1
  207. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -5
  208. package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -2
  209. package/types/Options/Interfaces/Particles/Move/IMoveTrail.d.ts +0 -2
  210. package/types/Options/Interfaces/Particles/Number/IParticlesDensity.d.ts +0 -3
  211. package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +0 -1
  212. package/types/Options/Interfaces/Particles/Opacity/IOpacity.d.ts +0 -1
  213. package/types/Options/Interfaces/Particles/Opacity/IOpacityAnimation.d.ts +0 -1
  214. package/types/Options/Interfaces/Particles/Size/ISize.d.ts +0 -1
  215. package/types/Options/Interfaces/Particles/Size/ISizeAnimation.d.ts +0 -1
  216. package/types/Options/Interfaces/Theme/ITheme.d.ts +3 -2
  217. package/types/Types/ExportResult.d.ts +5 -0
  218. package/types/Utils/CanvasUtils.d.ts +2 -5
  219. package/types/Utils/OptionsUtils.d.ts +1 -1
  220. package/types/Utils/Utils.d.ts +22 -4
  221. package/types/bundle.d.ts +2 -91
  222. package/types/export-types.d.ts +107 -0
  223. package/types/exports.d.ts +89 -0
  224. package/types/index.d.ts +3 -204
  225. package/types/init.d.ts +2 -0
  226. package/umd/Core/Canvas.js +269 -239
  227. package/umd/Core/Container.js +91 -107
  228. package/umd/Core/Engine.js +285 -0
  229. package/umd/Core/Particle.js +158 -165
  230. package/umd/Core/Particles.js +149 -144
  231. package/umd/Core/Retina.js +15 -13
  232. package/umd/Core/Utils/Circle.js +11 -7
  233. package/umd/Core/Utils/Constants.js +5 -4
  234. package/umd/Core/Utils/EventListeners.js +257 -233
  235. package/umd/Core/Utils/InteractionManager.js +6 -16
  236. package/umd/Core/Utils/QuadTree.js +14 -20
  237. package/umd/Core/Utils/Vector3d.js +18 -10
  238. package/umd/Options/Classes/AnimatableColor.js +3 -2
  239. package/umd/Options/Classes/AnimationOptions.js +4 -3
  240. package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +3 -2
  241. package/umd/Options/Classes/ColorAnimation.js +4 -0
  242. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +1 -25
  243. package/umd/Options/Classes/Interactivity/Events/Events.js +6 -25
  244. package/umd/Options/Classes/Interactivity/Interactivity.js +1 -8
  245. package/umd/Options/Classes/Interactivity/Modes/Modes.js +11 -8
  246. package/umd/Options/Classes/ManualParticle.js +5 -6
  247. package/umd/Options/Classes/Options.js +18 -38
  248. package/umd/Options/Classes/OptionsColor.js +4 -3
  249. package/umd/Options/Classes/Particles/Collisions/Collisions.js +6 -1
  250. package/umd/Options/Classes/Particles/Move/Move.js +12 -42
  251. package/umd/Options/Classes/Particles/Move/MoveAttract.js +9 -20
  252. package/umd/Options/Classes/Particles/Move/MoveTrail.js +2 -8
  253. package/umd/Options/Classes/Particles/Move/OutModes.js +4 -5
  254. package/umd/Options/Classes/Particles/Move/Spin.js +3 -1
  255. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +2 -21
  256. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +2 -9
  257. package/umd/Options/Classes/Particles/Opacity/Opacity.js +10 -6
  258. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +0 -9
  259. package/umd/Options/Classes/Particles/ParticlesOptions.js +6 -11
  260. package/umd/Options/Classes/Particles/Shape/Shape.js +9 -10
  261. package/umd/Options/Classes/Particles/Size/Size.js +12 -8
  262. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +0 -9
  263. package/umd/Options/Classes/ValueWithRandom.js +5 -18
  264. package/umd/Utils/CanvasUtils.js +21 -58
  265. package/umd/Utils/ColorUtils.js +16 -18
  266. package/umd/Utils/EventDispatcher.js +7 -6
  267. package/umd/Utils/HslColorManager.js +2 -4
  268. package/umd/Utils/NumberUtils.js +42 -46
  269. package/umd/Utils/RgbColorManager.js +2 -4
  270. package/umd/Utils/Utils.js +146 -66
  271. package/umd/bundle.js +5 -98
  272. package/umd/export-types.js +123 -0
  273. package/umd/exports.js +115 -0
  274. package/umd/index.js +9 -200
  275. package/umd/init.js +26 -0
  276. package/browser/Core/Utils/FrameManager.js +0 -42
  277. package/browser/Core/Utils/Plugins.js +0 -112
  278. package/browser/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
  279. package/browser/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
  280. package/browser/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
  281. package/browser/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
  282. package/browser/engine.js +0 -175
  283. package/cjs/Core/Utils/FrameManager.js +0 -46
  284. package/cjs/Core/Utils/Plugins.js +0 -116
  285. package/cjs/Enums/Modes/SizeMode.js +0 -2
  286. package/cjs/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -2
  287. package/cjs/Options/Interfaces/Particles/Shape/IImageShape.js +0 -2
  288. package/cjs/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -2
  289. package/cjs/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -17
  290. package/cjs/Options/Interfaces/Particles/Shape/IStarShape.js +0 -2
  291. package/cjs/engine.js +0 -179
  292. package/esm/Core/Interfaces/IParticleOverride.js +0 -1
  293. package/esm/Core/Interfaces/IParticlesMover.js +0 -1
  294. package/esm/Core/Utils/FrameManager.js +0 -42
  295. package/esm/Core/Utils/Plugins.js +0 -112
  296. package/esm/Enums/Modes/SizeMode.js +0 -1
  297. package/esm/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -1
  298. package/esm/Options/Interfaces/Particles/Shape/IImageShape.js +0 -1
  299. package/esm/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -1
  300. package/esm/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -1
  301. package/esm/Options/Interfaces/Particles/Shape/IStarShape.js +0 -1
  302. package/esm/engine.js +0 -175
  303. package/types/Core/Interfaces/IParticleOverride.d.ts +0 -6
  304. package/types/Core/Interfaces/IParticlesMover.d.ts +0 -7
  305. package/types/Core/Utils/FrameManager.d.ts +0 -6
  306. package/types/Core/Utils/Plugins.d.ts +0 -51
  307. package/types/Options/Interfaces/Particles/Shape/ICharacterShape.d.ts +0 -8
  308. package/types/Options/Interfaces/Particles/Shape/IImageShape.d.ts +0 -8
  309. package/types/Options/Interfaces/Particles/Shape/IPolygonShape.d.ts +0 -5
  310. package/types/Options/Interfaces/Particles/Shape/IShapeValues.d.ts +0 -1
  311. package/types/Options/Interfaces/Particles/Shape/IStarShape.d.ts +0 -6
  312. package/types/engine.d.ts +0 -39
  313. package/umd/Core/Utils/FrameManager.js +0 -56
  314. package/umd/Core/Utils/Plugins.js +0 -126
  315. package/umd/Enums/Modes/SizeMode.js +0 -12
  316. package/umd/Options/Interfaces/Particles/Shape/ICharacterShape.js +0 -12
  317. package/umd/Options/Interfaces/Particles/Shape/IImageShape.js +0 -12
  318. package/umd/Options/Interfaces/Particles/Shape/IPolygonShape.js +0 -12
  319. package/umd/Options/Interfaces/Particles/Shape/IShapeValues.js +0 -27
  320. package/umd/Options/Interfaces/Particles/Shape/IStarShape.js +0 -12
  321. package/umd/engine.js +0 -189
  322. /package/browser/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
  323. /package/browser/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
  324. /package/cjs/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
  325. /package/cjs/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
  326. /package/{browser/Enums/Modes/SizeMode.js → esm/Enums/Modes/PixelMode.js} +0 -0
  327. /package/{browser/Options/Interfaces/Particles/Shape/ICharacterShape.js → esm/Types/ExportResult.js} +0 -0
  328. /package/umd/{Core/Interfaces/IParticleOverride.js → Enums/Modes/PixelMode.js} +0 -0
  329. /package/umd/{Core/Interfaces/IParticlesMover.js → Types/ExportResult.js} +0 -0
@@ -1,42 +1,75 @@
1
- import { animate, cancelAnimation } from "../Utils/Utils";
2
1
  import { Canvas } from "./Canvas";
3
2
  import { EventListeners } from "./Utils/EventListeners";
4
- import { FrameManager } from "./Utils/FrameManager";
5
3
  import { Options } from "../Options/Classes/Options";
6
4
  import { Particles } from "./Particles";
7
5
  import { Retina } from "./Retina";
6
+ import { errorPrefix } from "./Utils/Constants";
7
+ import { getLogger } from "../Utils/Utils";
8
8
  import { getRangeValue } from "../Utils/NumberUtils";
9
9
  import { loadOptions } from "../Utils/OptionsUtils";
10
10
  function guardCheck(container) {
11
11
  return container && !container.destroyed;
12
12
  }
13
+ function initDelta(value, fpsLimit = 60, smooth = false) {
14
+ return {
15
+ value,
16
+ factor: smooth ? 60 / fpsLimit : (60 * value) / 1000,
17
+ };
18
+ }
13
19
  function loadContainerOptions(engine, container, ...sourceOptionsArr) {
14
20
  const options = new Options(engine, container);
15
21
  loadOptions(options, ...sourceOptionsArr);
16
22
  return options;
17
23
  }
18
- const defaultPathGeneratorKey = "default", defaultPathGenerator = {
19
- generate: (p) => {
20
- const v = p.velocity.copy();
21
- v.angle += (v.length * Math.PI) / 180;
22
- return v;
23
- },
24
- init: () => {
25
- },
26
- update: () => {
27
- },
28
- reset: () => {
29
- },
30
- };
31
24
  export class Container {
32
25
  constructor(engine, id, sourceOptions) {
33
26
  this.id = id;
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
+ (entry.isIntersecting ? this.play : this.pause)();
36
+ }
37
+ };
38
+ this._nextFrame = async (timestamp) => {
39
+ try {
40
+ if (!this.smooth &&
41
+ this.lastFrameTime !== undefined &&
42
+ timestamp < this.lastFrameTime + 1000 / this.fpsLimit) {
43
+ this.draw(false);
44
+ return;
45
+ }
46
+ this.lastFrameTime ??= timestamp;
47
+ const delta = initDelta(timestamp - this.lastFrameTime, this.fpsLimit, this.smooth);
48
+ this.addLifeTime(delta.value);
49
+ this.lastFrameTime = timestamp;
50
+ if (delta.value > 1000) {
51
+ this.draw(false);
52
+ return;
53
+ }
54
+ await this.particles.draw(delta);
55
+ if (!this.alive()) {
56
+ this.destroy();
57
+ return;
58
+ }
59
+ if (this.getAnimationStatus()) {
60
+ this.draw(false);
61
+ }
62
+ }
63
+ catch (e) {
64
+ getLogger().error(`${errorPrefix} in animation loop`, e);
65
+ }
66
+ };
34
67
  this._engine = engine;
35
68
  this.fpsLimit = 120;
36
69
  this.smooth = false;
37
70
  this._delay = 0;
38
- this.duration = 0;
39
- this.lifeTime = 0;
71
+ this._duration = 0;
72
+ this._lifeTime = 0;
40
73
  this._firstStart = true;
41
74
  this.started = false;
42
75
  this.destroyed = false;
@@ -49,7 +82,6 @@ export class Container {
49
82
  this.retina = new Retina(this);
50
83
  this.canvas = new Canvas(this);
51
84
  this.particles = new Particles(this._engine, this);
52
- this.frameManager = new FrameManager(this);
53
85
  this.pathGenerators = new Map();
54
86
  this.interactivity = {
55
87
  mouse: {
@@ -150,13 +182,19 @@ export class Container {
150
182
  el.addEventListener("touchend", touchEndHandler);
151
183
  el.addEventListener("touchcancel", touchCancelHandler);
152
184
  }
185
+ addLifeTime(value) {
186
+ this._lifeTime += value;
187
+ }
153
188
  addPath(key, generator, override = false) {
154
189
  if (!guardCheck(this) || (!override && this.pathGenerators.has(key))) {
155
190
  return false;
156
191
  }
157
- this.pathGenerators.set(key, generator !== null && generator !== void 0 ? generator : defaultPathGenerator);
192
+ this.pathGenerators.set(key, generator);
158
193
  return true;
159
194
  }
195
+ alive() {
196
+ return !this._duration || this._lifeTime <= this._duration;
197
+ }
160
198
  destroy() {
161
199
  if (!guardCheck(this)) {
162
200
  return;
@@ -165,14 +203,12 @@ export class Container {
165
203
  this.particles.destroy();
166
204
  this.canvas.destroy();
167
205
  for (const [, drawer] of this.drawers) {
168
- if (drawer.destroy) {
169
- drawer.destroy(this);
170
- }
206
+ drawer.destroy && drawer.destroy(this);
171
207
  }
172
208
  for (const key of this.drawers.keys()) {
173
209
  this.drawers.delete(key);
174
210
  }
175
- this._engine.plugins.destroy(this);
211
+ this._engine.clearPlugins(this);
176
212
  this.destroyed = true;
177
213
  const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this);
178
214
  if (idx >= 0) {
@@ -185,30 +221,26 @@ export class Container {
185
221
  return;
186
222
  }
187
223
  let refreshTime = force;
188
- this._drawAnimationFrame = animate()(async (timestamp) => {
224
+ this._drawAnimationFrame = requestAnimationFrame(async (timestamp) => {
189
225
  if (refreshTime) {
190
226
  this.lastFrameTime = undefined;
191
227
  refreshTime = false;
192
228
  }
193
- await this.frameManager.nextFrame(timestamp);
229
+ await this._nextFrame(timestamp);
194
230
  });
195
231
  }
196
- exportConfiguration() {
197
- return JSON.stringify(this.actualOptions, (key, value) => {
198
- if (key === "_engine" || key === "_container") {
199
- return;
232
+ async export(type, options = {}) {
233
+ for (const [, plugin] of this.plugins) {
234
+ if (!plugin.export) {
235
+ continue;
200
236
  }
201
- return value;
202
- }, 2);
203
- }
204
- exportImage(callback, type, quality) {
205
- const element = this.canvas.element;
206
- if (element) {
207
- element.toBlob(callback, type !== null && type !== void 0 ? type : "image/png", quality);
237
+ const res = await plugin.export(type, options);
238
+ if (!res.supported) {
239
+ continue;
240
+ }
241
+ return res.blob;
208
242
  }
209
- }
210
- exportImg(callback) {
211
- this.exportImage(callback);
243
+ getLogger().error(`${errorPrefix} - Export plugin with type ${type} not found`);
212
244
  }
213
245
  getAnimationStatus() {
214
246
  return !this._paused && !this.pageHidden && guardCheck(this);
@@ -219,53 +251,48 @@ export class Container {
219
251
  }
220
252
  this.particles.handleClickMode(mode);
221
253
  for (const [, plugin] of this.plugins) {
222
- if (plugin.handleClickMode) {
223
- plugin.handleClickMode(mode);
224
- }
254
+ plugin.handleClickMode && plugin.handleClickMode(mode);
225
255
  }
226
256
  }
227
257
  async init() {
228
258
  if (!guardCheck(this)) {
229
259
  return;
230
260
  }
231
- const shapes = this._engine.plugins.getSupportedShapes();
261
+ const shapes = this._engine.getSupportedShapes();
232
262
  for (const type of shapes) {
233
- const drawer = this._engine.plugins.getShapeDrawer(type);
263
+ const drawer = this._engine.getShapeDrawer(type);
234
264
  if (drawer) {
235
265
  this.drawers.set(type, drawer);
236
266
  }
237
267
  }
238
268
  this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
239
269
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
240
- const availablePlugins = this._engine.plugins.getAvailablePlugins(this);
270
+ const availablePlugins = this._engine.getAvailablePlugins(this);
241
271
  for (const [id, plugin] of availablePlugins) {
242
272
  this.plugins.set(id, plugin);
243
273
  }
244
274
  this.retina.init();
245
275
  await this.canvas.init();
276
+ this.updateActualOptions();
277
+ this.canvas.initBackground();
278
+ this.canvas.resize();
246
279
  this.zLayers = this.actualOptions.zLayers;
247
- this.duration = getRangeValue(this.actualOptions.duration) * 1000;
280
+ this._duration = getRangeValue(this.actualOptions.duration) * 1000;
248
281
  this._delay = getRangeValue(this.actualOptions.delay) * 1000;
249
- this.lifeTime = 0;
282
+ this._lifeTime = 0;
250
283
  this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
251
284
  this.smooth = this.actualOptions.smooth;
252
285
  for (const [, drawer] of this.drawers) {
253
- if (drawer.init) {
254
- await drawer.init(this);
255
- }
286
+ drawer.init && (await drawer.init(this));
256
287
  }
257
288
  for (const [, plugin] of this.plugins) {
258
- if (plugin.init) {
259
- await plugin.init();
260
- }
289
+ plugin.init && (await plugin.init());
261
290
  }
262
291
  this._engine.dispatchEvent("containerInit", { container: this });
263
292
  this.particles.init();
264
293
  this.particles.setDensity();
265
294
  for (const [, plugin] of this.plugins) {
266
- if (plugin.particlesSetup) {
267
- plugin.particlesSetup();
268
- }
295
+ plugin.particlesSetup && plugin.particlesSetup();
269
296
  }
270
297
  this._engine.dispatchEvent("particlesSetup", { container: this });
271
298
  }
@@ -281,16 +308,14 @@ export class Container {
281
308
  return;
282
309
  }
283
310
  if (this._drawAnimationFrame !== undefined) {
284
- cancelAnimation()(this._drawAnimationFrame);
311
+ cancelAnimationFrame(this._drawAnimationFrame);
285
312
  delete this._drawAnimationFrame;
286
313
  }
287
314
  if (this._paused) {
288
315
  return;
289
316
  }
290
317
  for (const [, plugin] of this.plugins) {
291
- if (plugin.pause) {
292
- plugin.pause();
293
- }
318
+ plugin.pause && plugin.pause();
294
319
  }
295
320
  if (!this.pageHidden) {
296
321
  this._paused = true;
@@ -330,37 +355,11 @@ export class Container {
330
355
  if (!guardCheck(this)) {
331
356
  return;
332
357
  }
358
+ this._initialSourceOptions = undefined;
333
359
  this._options = loadContainerOptions(this._engine, this);
360
+ this.actualOptions = loadContainerOptions(this._engine, this, this._options);
334
361
  return this.refresh();
335
362
  }
336
- setNoise(noiseOrGenerator, init, update) {
337
- if (!guardCheck(this)) {
338
- return;
339
- }
340
- this.setPath(noiseOrGenerator, init, update);
341
- }
342
- setPath(pathOrGenerator, init, update) {
343
- if (!pathOrGenerator || !guardCheck(this)) {
344
- return;
345
- }
346
- const pathGenerator = Object.assign({}, defaultPathGenerator);
347
- if (typeof pathOrGenerator === "function") {
348
- pathGenerator.generate = pathOrGenerator;
349
- if (init) {
350
- pathGenerator.init = init;
351
- }
352
- if (update) {
353
- pathGenerator.update = update;
354
- }
355
- }
356
- else {
357
- const oldGenerator = pathGenerator;
358
- pathGenerator.generate = pathOrGenerator.generate || oldGenerator.generate;
359
- pathGenerator.init = pathOrGenerator.init || oldGenerator.init;
360
- pathGenerator.update = pathOrGenerator.update || oldGenerator.update;
361
- }
362
- this.addPath(defaultPathGeneratorKey, pathGenerator, true);
363
- }
364
363
  async start() {
365
364
  if (!guardCheck(this) || this.started) {
366
365
  return;
@@ -374,9 +373,7 @@ export class Container {
374
373
  this._intersectionObserver.observe(this.interactivity.element);
375
374
  }
376
375
  for (const [, plugin] of this.plugins) {
377
- if (plugin.start) {
378
- await plugin.start();
379
- }
376
+ plugin.start && (await plugin.start());
380
377
  }
381
378
  this._engine.dispatchEvent("containerStarted", { container: this });
382
379
  this.play();
@@ -397,14 +394,12 @@ export class Container {
397
394
  this._eventListeners.removeListeners();
398
395
  this.pause();
399
396
  this.particles.clear();
400
- this.canvas.clear();
397
+ this.canvas.stop();
401
398
  if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
402
399
  this._intersectionObserver.unobserve(this.interactivity.element);
403
400
  }
404
401
  for (const [, plugin] of this.plugins) {
405
- if (plugin.stop) {
406
- plugin.stop();
407
- }
402
+ plugin.stop && plugin.stop();
408
403
  }
409
404
  for (const key of this.plugins.keys()) {
410
405
  this.plugins.delete(key);
@@ -422,15 +417,4 @@ export class Container {
422
417
  this.responsiveMaxWidth = newMaxWidth;
423
418
  return true;
424
419
  }
425
- _intersectionManager(entries) {
426
- if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
427
- return;
428
- }
429
- for (const entry of entries) {
430
- if (entry.target !== this.interactivity.element) {
431
- continue;
432
- }
433
- (entry.isIntersecting ? this.play : this.pause)();
434
- }
435
- }
436
420
  }
@@ -0,0 +1,271 @@
1
+ import { errorPrefix, generatedAttribute } from "./Utils/Constants";
2
+ import { executeOnSingleOrMultiple, getLogger, isBoolean, isFunction, isString, itemFromSingleOrMultiple, } from "../Utils/Utils";
3
+ import { Container } from "./Container";
4
+ import { EventDispatcher } from "../Utils/EventDispatcher";
5
+ import { getRandom } from "../Utils/NumberUtils";
6
+ function getItemsFromInitializer(container, map, initializers, force = false) {
7
+ let res = map.get(container);
8
+ if (!res || force) {
9
+ res = [...initializers.values()].map((t) => t(container));
10
+ map.set(container, res);
11
+ }
12
+ return res;
13
+ }
14
+ async function getDataFromUrl(data) {
15
+ const url = itemFromSingleOrMultiple(data.url, data.index);
16
+ if (!url) {
17
+ return data.fallback;
18
+ }
19
+ const response = await fetch(url);
20
+ if (response.ok) {
21
+ return response.json();
22
+ }
23
+ getLogger().error(`${errorPrefix} ${response.status} while retrieving config file`);
24
+ return data.fallback;
25
+ }
26
+ export class Engine {
27
+ constructor() {
28
+ this._configs = new Map();
29
+ this._domArray = [];
30
+ this._eventDispatcher = new EventDispatcher();
31
+ this._initialized = false;
32
+ this.plugins = [];
33
+ this._initializers = {
34
+ interactors: new Map(),
35
+ movers: new Map(),
36
+ updaters: new Map(),
37
+ };
38
+ this.interactors = new Map();
39
+ this.movers = new Map();
40
+ this.updaters = new Map();
41
+ this.presets = new Map();
42
+ this.drawers = new Map();
43
+ this.pathGenerators = new Map();
44
+ }
45
+ get configs() {
46
+ const res = {};
47
+ for (const [name, config] of this._configs) {
48
+ res[name] = config;
49
+ }
50
+ return res;
51
+ }
52
+ get version() {
53
+ return "3.0.0-beta.0";
54
+ }
55
+ addConfig(nameOrConfig, config) {
56
+ if (isString(nameOrConfig)) {
57
+ if (config) {
58
+ config.name = nameOrConfig;
59
+ this._configs.set(nameOrConfig, config);
60
+ }
61
+ }
62
+ else {
63
+ this._configs.set(nameOrConfig.name ?? "default", nameOrConfig);
64
+ }
65
+ }
66
+ addEventListener(type, listener) {
67
+ this._eventDispatcher.addEventListener(type, listener);
68
+ }
69
+ async addInteractor(name, interactorInitializer, refresh = true) {
70
+ this._initializers.interactors.set(name, interactorInitializer);
71
+ await this.refresh(refresh);
72
+ }
73
+ async addMover(name, moverInitializer, refresh = true) {
74
+ this._initializers.movers.set(name, moverInitializer);
75
+ await this.refresh(refresh);
76
+ }
77
+ async addParticleUpdater(name, updaterInitializer, refresh = true) {
78
+ this._initializers.updaters.set(name, updaterInitializer);
79
+ await this.refresh(refresh);
80
+ }
81
+ async addPathGenerator(name, generator, refresh = true) {
82
+ !this.getPathGenerator(name) && this.pathGenerators.set(name, generator);
83
+ await this.refresh(refresh);
84
+ }
85
+ async addPlugin(plugin, refresh = true) {
86
+ !this.getPlugin(plugin.id) && this.plugins.push(plugin);
87
+ await this.refresh(refresh);
88
+ }
89
+ async addPreset(preset, options, override = false, refresh = true) {
90
+ (override || !this.getPreset(preset)) && this.presets.set(preset, options);
91
+ await this.refresh(refresh);
92
+ }
93
+ async addShape(shape, drawer, initOrRefresh, afterEffectOrRefresh, destroyOrRefresh, refresh = true) {
94
+ let customDrawer;
95
+ let realRefresh = refresh, realInit, realAfterEffect, realDestroy;
96
+ if (isBoolean(initOrRefresh)) {
97
+ realRefresh = initOrRefresh;
98
+ realInit = undefined;
99
+ }
100
+ else {
101
+ realInit = initOrRefresh;
102
+ }
103
+ if (isBoolean(afterEffectOrRefresh)) {
104
+ realRefresh = afterEffectOrRefresh;
105
+ realAfterEffect = undefined;
106
+ }
107
+ else {
108
+ realAfterEffect = afterEffectOrRefresh;
109
+ }
110
+ if (isBoolean(destroyOrRefresh)) {
111
+ realRefresh = destroyOrRefresh;
112
+ realDestroy = undefined;
113
+ }
114
+ else {
115
+ realDestroy = destroyOrRefresh;
116
+ }
117
+ if (isFunction(drawer)) {
118
+ customDrawer = {
119
+ afterEffect: realAfterEffect,
120
+ destroy: realDestroy,
121
+ draw: drawer,
122
+ init: realInit,
123
+ };
124
+ }
125
+ else {
126
+ customDrawer = drawer;
127
+ }
128
+ executeOnSingleOrMultiple(shape, (type) => {
129
+ !this.getShapeDrawer(type) && this.drawers.set(type, customDrawer);
130
+ });
131
+ await this.refresh(realRefresh);
132
+ }
133
+ clearPlugins(container) {
134
+ this.updaters.delete(container);
135
+ this.movers.delete(container);
136
+ this.interactors.delete(container);
137
+ }
138
+ dispatchEvent(type, args) {
139
+ this._eventDispatcher.dispatchEvent(type, args);
140
+ }
141
+ dom() {
142
+ return this._domArray;
143
+ }
144
+ domItem(index) {
145
+ const dom = this.dom(), item = dom[index];
146
+ if (!item || item.destroyed) {
147
+ dom.splice(index, 1);
148
+ return;
149
+ }
150
+ return item;
151
+ }
152
+ getAvailablePlugins(container) {
153
+ const res = new Map();
154
+ for (const plugin of this.plugins) {
155
+ plugin.needsPlugin(container.actualOptions) && res.set(plugin.id, plugin.getPlugin(container));
156
+ }
157
+ return res;
158
+ }
159
+ getInteractors(container, force = false) {
160
+ return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
161
+ }
162
+ getMovers(container, force = false) {
163
+ return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
164
+ }
165
+ getPathGenerator(type) {
166
+ return this.pathGenerators.get(type);
167
+ }
168
+ getPlugin(plugin) {
169
+ return this.plugins.find((t) => t.id === plugin);
170
+ }
171
+ getPreset(preset) {
172
+ return this.presets.get(preset);
173
+ }
174
+ getShapeDrawer(type) {
175
+ return this.drawers.get(type);
176
+ }
177
+ getSupportedShapes() {
178
+ return this.drawers.keys();
179
+ }
180
+ getUpdaters(container, force = false) {
181
+ return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
182
+ }
183
+ init() {
184
+ if (this._initialized) {
185
+ return;
186
+ }
187
+ this._initialized = true;
188
+ }
189
+ async load(params) {
190
+ const id = params.id ?? `tsparticles${Math.floor(getRandom() * 10000)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
191
+ let domContainer = params.element ?? document.getElementById(id);
192
+ if (!domContainer) {
193
+ domContainer = document.createElement("div");
194
+ domContainer.id = id;
195
+ document.body.append(domContainer);
196
+ }
197
+ const currentOptions = itemFromSingleOrMultiple(options, index), dom = this.dom(), oldIndex = dom.findIndex((v) => v.id === id);
198
+ if (oldIndex >= 0) {
199
+ const old = this.domItem(oldIndex);
200
+ if (old && !old.destroyed) {
201
+ old.destroy();
202
+ dom.splice(oldIndex, 1);
203
+ }
204
+ }
205
+ let canvasEl;
206
+ if (domContainer.tagName.toLowerCase() === "canvas") {
207
+ canvasEl = domContainer;
208
+ canvasEl.dataset[generatedAttribute] = "false";
209
+ }
210
+ else {
211
+ const existingCanvases = domContainer.getElementsByTagName("canvas");
212
+ if (existingCanvases.length) {
213
+ canvasEl = existingCanvases[0];
214
+ canvasEl.dataset[generatedAttribute] = "false";
215
+ }
216
+ else {
217
+ canvasEl = document.createElement("canvas");
218
+ canvasEl.dataset[generatedAttribute] = "true";
219
+ domContainer.appendChild(canvasEl);
220
+ }
221
+ }
222
+ if (!canvasEl.style.width) {
223
+ canvasEl.style.width = "100%";
224
+ }
225
+ if (!canvasEl.style.height) {
226
+ canvasEl.style.height = "100%";
227
+ }
228
+ const newItem = new Container(this, id, currentOptions);
229
+ if (oldIndex >= 0) {
230
+ dom.splice(oldIndex, 0, newItem);
231
+ }
232
+ else {
233
+ dom.push(newItem);
234
+ }
235
+ newItem.canvas.loadCanvas(canvasEl);
236
+ await newItem.start();
237
+ return newItem;
238
+ }
239
+ loadOptions(options, sourceOptions) {
240
+ for (const plugin of this.plugins) {
241
+ plugin.loadOptions(options, sourceOptions);
242
+ }
243
+ }
244
+ loadParticlesOptions(container, options, ...sourceOptions) {
245
+ const updaters = this.updaters.get(container);
246
+ if (!updaters) {
247
+ return;
248
+ }
249
+ for (const updater of updaters) {
250
+ updater.loadOptions && updater.loadOptions(options, ...sourceOptions);
251
+ }
252
+ }
253
+ async refresh(refresh = true) {
254
+ if (!refresh) {
255
+ return;
256
+ }
257
+ this.dom().forEach((t) => t.refresh());
258
+ }
259
+ removeEventListener(type, listener) {
260
+ this._eventDispatcher.removeEventListener(type, listener);
261
+ }
262
+ setOnClickHandler(callback) {
263
+ const dom = this.dom();
264
+ if (!dom.length) {
265
+ throw new Error(`${errorPrefix} can only set click handlers after calling tsParticles.load()`);
266
+ }
267
+ for (const domItem of dom) {
268
+ domItem.addClickHandler(callback);
269
+ }
270
+ }
271
+ }