@tsparticles/engine 3.9.0 → 4.0.0-alpha.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 (431) hide show
  1. package/638.min.js +2 -0
  2. package/638.min.js.LICENSE.txt +1 -0
  3. package/browser/Core/Canvas.js +126 -181
  4. package/browser/Core/Container.js +22 -18
  5. package/browser/Core/Engine.js +64 -54
  6. package/browser/Core/Particle.js +43 -48
  7. package/browser/Core/Particles.js +33 -24
  8. package/browser/Core/Retina.js +2 -3
  9. package/browser/Core/Utils/Constants.js +2 -2
  10. package/browser/Core/Utils/EventListeners.js +74 -64
  11. package/browser/Core/Utils/QuadTree.js +1 -1
  12. package/browser/Core/Utils/Ranges.js +2 -2
  13. package/browser/Core/Utils/Vectors.js +15 -21
  14. package/browser/Options/Classes/AnimatableColor.js +3 -3
  15. package/browser/Options/Classes/AnimationOptions.js +1 -1
  16. package/browser/Options/Classes/ColorAnimation.js +1 -1
  17. package/browser/Options/Classes/Options.js +13 -10
  18. package/browser/Options/Classes/Particles/Move/Move.js +1 -4
  19. package/browser/Options/Classes/Particles/Move/MoveAngle.js +1 -1
  20. package/browser/Options/Classes/Particles/Move/MoveAttract.js +1 -1
  21. package/browser/Options/Classes/Particles/Move/MoveGravity.js +1 -1
  22. package/browser/Options/Classes/Particles/Move/Spin.js +1 -1
  23. package/browser/Options/Classes/Particles/ParticlesOptions.js +0 -6
  24. package/browser/Options/Classes/Particles/Stroke.js +1 -1
  25. package/browser/Options/Classes/ValueWithRandom.js +1 -1
  26. package/browser/Utils/CanvasUtils.js +65 -21
  27. package/browser/Utils/ColorUtils.js +61 -45
  28. package/browser/Utils/EventDispatcher.js +3 -1
  29. package/browser/Utils/LogUtils.js +22 -0
  30. package/browser/Utils/{NumberUtils.js → MathUtils.js} +14 -7
  31. package/browser/Utils/Utils.js +23 -125
  32. package/browser/bundle.js +3 -3
  33. package/browser/export-types.js +1 -99
  34. package/browser/exports.js +2 -9
  35. package/browser/index.js +3 -7
  36. package/browser/initEngine.js +4 -0
  37. package/cjs/Core/Canvas.js +136 -195
  38. package/cjs/Core/Container.js +57 -57
  39. package/cjs/Core/Engine.js +77 -71
  40. package/cjs/Core/Interfaces/Colors.js +1 -2
  41. package/cjs/Core/Interfaces/IBounds.js +1 -2
  42. package/cjs/Core/Interfaces/IBubbleParticleData.js +1 -2
  43. package/cjs/Core/Interfaces/ICircleBouncer.js +1 -2
  44. package/cjs/Core/Interfaces/IColorManager.js +1 -2
  45. package/cjs/Core/Interfaces/IContainerInteractivity.js +1 -2
  46. package/cjs/Core/Interfaces/IContainerPlugin.js +1 -2
  47. package/cjs/Core/Interfaces/ICoordinates.js +1 -2
  48. package/cjs/Core/Interfaces/IDelta.js +1 -2
  49. package/cjs/Core/Interfaces/IDimension.js +1 -2
  50. package/cjs/Core/Interfaces/IDistance.js +1 -2
  51. package/cjs/Core/Interfaces/IDrawParticleParams.js +1 -2
  52. package/cjs/Core/Interfaces/IEffectDrawer.js +1 -2
  53. package/cjs/Core/Interfaces/IExternalInteractor.js +1 -2
  54. package/cjs/Core/Interfaces/IInteractor.js +1 -2
  55. package/cjs/Core/Interfaces/ILoadParams.js +1 -2
  56. package/cjs/Core/Interfaces/IMouseData.js +1 -2
  57. package/cjs/Core/Interfaces/IMovePathGenerator.js +1 -2
  58. package/cjs/Core/Interfaces/IParticleColorStyle.js +1 -2
  59. package/cjs/Core/Interfaces/IParticleHslAnimation.js +1 -2
  60. package/cjs/Core/Interfaces/IParticleLife.js +1 -2
  61. package/cjs/Core/Interfaces/IParticleMover.js +1 -2
  62. package/cjs/Core/Interfaces/IParticleRetinaProps.js +1 -2
  63. package/cjs/Core/Interfaces/IParticleRoll.js +1 -2
  64. package/cjs/Core/Interfaces/IParticleTransformValues.js +1 -2
  65. package/cjs/Core/Interfaces/IParticleUpdater.js +1 -2
  66. package/cjs/Core/Interfaces/IParticleValueAnimation.js +1 -2
  67. package/cjs/Core/Interfaces/IParticlesInteractor.js +1 -2
  68. package/cjs/Core/Interfaces/IPlugin.js +1 -2
  69. package/cjs/Core/Interfaces/IPositionFromSizeParams.js +1 -2
  70. package/cjs/Core/Interfaces/IRangeValue.js +1 -2
  71. package/cjs/Core/Interfaces/IShapeDrawData.js +1 -2
  72. package/cjs/Core/Interfaces/IShapeDrawer.js +1 -2
  73. package/cjs/Core/Interfaces/IShapeValues.js +1 -2
  74. package/cjs/Core/Interfaces/ISlowParticleData.js +1 -2
  75. package/cjs/Core/Particle.js +99 -108
  76. package/cjs/Core/Particles.js +63 -58
  77. package/cjs/Core/Retina.js +13 -18
  78. package/cjs/Core/Utils/Constants.js +3 -7
  79. package/cjs/Core/Utils/EventListeners.js +94 -88
  80. package/cjs/Core/Utils/ExternalInteractorBase.js +3 -7
  81. package/cjs/Core/Utils/InteractionManager.js +4 -8
  82. package/cjs/Core/Utils/ParticlesInteractorBase.js +3 -7
  83. package/cjs/Core/Utils/Point.js +1 -5
  84. package/cjs/Core/Utils/QuadTree.js +10 -14
  85. package/cjs/Core/Utils/Ranges.js +14 -20
  86. package/cjs/Core/Utils/Vectors.js +24 -35
  87. package/cjs/Enums/AnimationStatus.js +2 -5
  88. package/cjs/Enums/Directions/MoveDirection.js +2 -5
  89. package/cjs/Enums/Directions/OutModeDirection.js +2 -5
  90. package/cjs/Enums/Directions/RotateDirection.js +2 -5
  91. package/cjs/Enums/InteractivityDetect.js +2 -5
  92. package/cjs/Enums/Modes/AnimationMode.js +2 -5
  93. package/cjs/Enums/Modes/LimitMode.js +2 -5
  94. package/cjs/Enums/Modes/OutMode.js +2 -5
  95. package/cjs/Enums/Modes/PixelMode.js +2 -5
  96. package/cjs/Enums/Modes/ResponsiveMode.js +2 -5
  97. package/cjs/Enums/Modes/ThemeMode.js +2 -5
  98. package/cjs/Enums/Types/AlterType.js +2 -5
  99. package/cjs/Enums/Types/DestroyType.js +2 -5
  100. package/cjs/Enums/Types/DivType.js +2 -5
  101. package/cjs/Enums/Types/EasingType.js +2 -5
  102. package/cjs/Enums/Types/EventType.js +2 -5
  103. package/cjs/Enums/Types/GradientType.js +2 -5
  104. package/cjs/Enums/Types/InteractorType.js +2 -5
  105. package/cjs/Enums/Types/ParticleOutType.js +2 -5
  106. package/cjs/Enums/Types/StartValueType.js +2 -5
  107. package/cjs/Options/Classes/AnimatableColor.js +10 -14
  108. package/cjs/Options/Classes/AnimationOptions.js +14 -19
  109. package/cjs/Options/Classes/Background/Background.js +6 -10
  110. package/cjs/Options/Classes/ColorAnimation.js +6 -10
  111. package/cjs/Options/Classes/FullScreen/FullScreen.js +3 -7
  112. package/cjs/Options/Classes/HslAnimation.js +7 -11
  113. package/cjs/Options/Classes/Interactivity/Events/ClickEvent.js +3 -7
  114. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +5 -9
  115. package/cjs/Options/Classes/Interactivity/Events/Events.js +14 -18
  116. package/cjs/Options/Classes/Interactivity/Events/HoverEvent.js +5 -9
  117. package/cjs/Options/Classes/Interactivity/Events/Parallax.js +3 -7
  118. package/cjs/Options/Classes/Interactivity/Events/ResizeEvent.js +3 -7
  119. package/cjs/Options/Classes/Interactivity/Interactivity.js +9 -13
  120. package/cjs/Options/Classes/Interactivity/Modes/Modes.js +3 -7
  121. package/cjs/Options/Classes/ManualParticle.js +10 -14
  122. package/cjs/Options/Classes/Options.js +41 -42
  123. package/cjs/Options/Classes/OptionsColor.js +5 -9
  124. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +6 -10
  125. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +2 -6
  126. package/cjs/Options/Classes/Particles/Effect/Effect.js +5 -9
  127. package/cjs/Options/Classes/Particles/Move/Move.js +26 -33
  128. package/cjs/Options/Classes/Particles/Move/MoveAngle.js +6 -10
  129. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +5 -9
  130. package/cjs/Options/Classes/Particles/Move/MoveCenter.js +5 -9
  131. package/cjs/Options/Classes/Particles/Move/MoveGravity.js +6 -10
  132. package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -9
  133. package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +7 -11
  134. package/cjs/Options/Classes/Particles/Move/Spin.js +7 -11
  135. package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -7
  136. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +7 -11
  137. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +5 -9
  138. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +6 -10
  139. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +6 -10
  140. package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -39
  141. package/cjs/Options/Classes/Particles/Shape/Shape.js +5 -9
  142. package/cjs/Options/Classes/Particles/Size/Size.js +6 -10
  143. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +6 -10
  144. package/cjs/Options/Classes/Particles/Stroke.js +8 -12
  145. package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +4 -8
  146. package/cjs/Options/Classes/Responsive.js +13 -17
  147. package/cjs/Options/Classes/Theme/Theme.js +7 -11
  148. package/cjs/Options/Classes/Theme/ThemeDefault.js +5 -9
  149. package/cjs/Options/Classes/ValueWithRandom.js +12 -18
  150. package/cjs/Options/Interfaces/Background/IBackground.js +1 -2
  151. package/cjs/Options/Interfaces/FullScreen/IFullScreen.js +1 -2
  152. package/cjs/Options/Interfaces/IAnimatable.js +1 -2
  153. package/cjs/Options/Interfaces/IAnimatableColor.js +1 -2
  154. package/cjs/Options/Interfaces/IAnimation.js +1 -2
  155. package/cjs/Options/Interfaces/IColorAnimation.js +1 -2
  156. package/cjs/Options/Interfaces/IHslAnimation.js +1 -2
  157. package/cjs/Options/Interfaces/IManualParticle.js +1 -2
  158. package/cjs/Options/Interfaces/IOptionLoader.js +1 -2
  159. package/cjs/Options/Interfaces/IOptions.js +1 -2
  160. package/cjs/Options/Interfaces/IOptionsColor.js +1 -2
  161. package/cjs/Options/Interfaces/IResponsive.js +1 -2
  162. package/cjs/Options/Interfaces/IValueWithRandom.js +1 -2
  163. package/cjs/Options/Interfaces/Interactivity/Events/IClickEvent.js +1 -2
  164. package/cjs/Options/Interfaces/Interactivity/Events/IDivEvent.js +1 -2
  165. package/cjs/Options/Interfaces/Interactivity/Events/IEvents.js +1 -2
  166. package/cjs/Options/Interfaces/Interactivity/Events/IHoverEvent.js +1 -2
  167. package/cjs/Options/Interfaces/Interactivity/Events/IParallax.js +1 -2
  168. package/cjs/Options/Interfaces/Interactivity/Events/IResizeEvent.js +1 -2
  169. package/cjs/Options/Interfaces/Interactivity/IInteractivity.js +1 -2
  170. package/cjs/Options/Interfaces/Interactivity/Modes/IModeDiv.js +1 -2
  171. package/cjs/Options/Interfaces/Interactivity/Modes/IModes.js +1 -2
  172. package/cjs/Options/Interfaces/Particles/Bounce/IParticlesBounce.js +1 -2
  173. package/cjs/Options/Interfaces/Particles/Effect/IEffect.js +1 -2
  174. package/cjs/Options/Interfaces/Particles/IParticlesOptions.js +1 -2
  175. package/cjs/Options/Interfaces/Particles/IStroke.js +1 -2
  176. package/cjs/Options/Interfaces/Particles/Move/IMove.js +1 -2
  177. package/cjs/Options/Interfaces/Particles/Move/IMoveAngle.js +1 -2
  178. package/cjs/Options/Interfaces/Particles/Move/IMoveAttract.js +1 -2
  179. package/cjs/Options/Interfaces/Particles/Move/IMoveCenter.js +1 -2
  180. package/cjs/Options/Interfaces/Particles/Move/IMoveGravity.js +1 -2
  181. package/cjs/Options/Interfaces/Particles/Move/IOutModes.js +1 -2
  182. package/cjs/Options/Interfaces/Particles/Move/ISpin.js +1 -2
  183. package/cjs/Options/Interfaces/Particles/Move/Path/IMovePath.js +1 -2
  184. package/cjs/Options/Interfaces/Particles/Number/IParticlesDensity.js +1 -2
  185. package/cjs/Options/Interfaces/Particles/Number/IParticlesNumber.js +1 -2
  186. package/cjs/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +1 -2
  187. package/cjs/Options/Interfaces/Particles/Opacity/IOpacity.js +1 -2
  188. package/cjs/Options/Interfaces/Particles/Opacity/IOpacityAnimation.js +1 -2
  189. package/cjs/Options/Interfaces/Particles/Shape/IShape.js +1 -2
  190. package/cjs/Options/Interfaces/Particles/Size/ISize.js +1 -2
  191. package/cjs/Options/Interfaces/Particles/Size/ISizeAnimation.js +1 -2
  192. package/cjs/Options/Interfaces/Particles/ZIndex/IZIndex.js +1 -2
  193. package/cjs/Options/Interfaces/Theme/ITheme.js +1 -2
  194. package/cjs/Options/Interfaces/Theme/IThemeDefault.js +1 -2
  195. package/cjs/Types/CustomEventArgs.js +1 -2
  196. package/cjs/Types/CustomEventListener.js +1 -2
  197. package/cjs/Types/EasingFunction.js +1 -2
  198. package/cjs/Types/ExportResult.js +1 -2
  199. package/cjs/Types/ISourceOptions.js +1 -2
  200. package/cjs/Types/ParticlesGroups.js +1 -2
  201. package/cjs/Types/PathOptions.js +1 -2
  202. package/cjs/Types/RangeValue.js +1 -2
  203. package/cjs/Types/RecursivePartial.js +1 -2
  204. package/cjs/Types/ShapeData.js +1 -2
  205. package/cjs/Types/SingleOrMultiple.js +1 -2
  206. package/cjs/Utils/CanvasUtils.js +86 -55
  207. package/cjs/Utils/ColorUtils.js +136 -141
  208. package/cjs/Utils/EventDispatcher.js +8 -10
  209. package/cjs/Utils/LogUtils.js +22 -0
  210. package/{esm/Utils/NumberUtils.js → cjs/Utils/MathUtils.js} +14 -7
  211. package/cjs/Utils/OptionsUtils.js +4 -8
  212. package/cjs/Utils/TypeUtils.js +7 -16
  213. package/cjs/Utils/Utils.js +104 -239
  214. package/cjs/bundle.js +5 -22
  215. package/cjs/export-types.js +1 -115
  216. package/cjs/exports.js +77 -100
  217. package/cjs/index.js +5 -26
  218. package/cjs/initEngine.js +4 -0
  219. package/dist_browser_Core_Container_js.js +102 -0
  220. package/esm/Core/Canvas.js +126 -181
  221. package/esm/Core/Container.js +22 -18
  222. package/esm/Core/Engine.js +64 -54
  223. package/esm/Core/Particle.js +43 -48
  224. package/esm/Core/Particles.js +33 -24
  225. package/esm/Core/Retina.js +2 -3
  226. package/esm/Core/Utils/Constants.js +2 -2
  227. package/esm/Core/Utils/EventListeners.js +74 -64
  228. package/esm/Core/Utils/QuadTree.js +1 -1
  229. package/esm/Core/Utils/Ranges.js +2 -2
  230. package/esm/Core/Utils/Vectors.js +15 -21
  231. package/esm/Enums/RangeType.js +5 -0
  232. package/esm/Options/Classes/AnimatableColor.js +3 -3
  233. package/esm/Options/Classes/AnimationOptions.js +1 -1
  234. package/esm/Options/Classes/ColorAnimation.js +1 -1
  235. package/esm/Options/Classes/Options.js +13 -10
  236. package/esm/Options/Classes/Particles/Move/Move.js +1 -4
  237. package/esm/Options/Classes/Particles/Move/MoveAngle.js +1 -1
  238. package/esm/Options/Classes/Particles/Move/MoveAttract.js +1 -1
  239. package/esm/Options/Classes/Particles/Move/MoveGravity.js +1 -1
  240. package/esm/Options/Classes/Particles/Move/Spin.js +1 -1
  241. package/esm/Options/Classes/Particles/ParticlesOptions.js +0 -6
  242. package/esm/Options/Classes/Particles/Stroke.js +1 -1
  243. package/esm/Options/Classes/ValueWithRandom.js +1 -1
  244. package/esm/Utils/CanvasUtils.js +65 -21
  245. package/esm/Utils/ColorUtils.js +61 -45
  246. package/esm/Utils/EventDispatcher.js +3 -1
  247. package/esm/Utils/LogUtils.js +22 -0
  248. package/esm/Utils/MathUtils.js +158 -0
  249. package/esm/Utils/Utils.js +23 -125
  250. package/esm/bundle.js +3 -3
  251. package/esm/export-types.js +1 -99
  252. package/esm/exports.js +2 -9
  253. package/esm/index.js +3 -7
  254. package/esm/initEngine.js +4 -0
  255. package/package.json +3 -2
  256. package/report.html +5 -4
  257. package/scripts/install.js +98 -17
  258. package/tsparticles.engine.js +492 -451
  259. package/tsparticles.engine.min.js +1 -1
  260. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  261. package/types/Core/Canvas.d.ts +6 -9
  262. package/types/Core/Container.d.ts +1 -0
  263. package/types/Core/Engine.d.ts +20 -16
  264. package/types/Core/Interfaces/Colors.d.ts +46 -2
  265. package/types/Core/Interfaces/IColorManager.d.ts +1 -1
  266. package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -0
  267. package/types/Core/Interfaces/IDrawParticleParams.d.ts +0 -4
  268. package/types/Core/Interfaces/IEffectDrawer.d.ts +2 -1
  269. package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -0
  270. package/types/Core/Interfaces/IShapeDrawer.d.ts +1 -0
  271. package/types/Core/Particle.d.ts +4 -5
  272. package/types/Core/Particles.d.ts +1 -1
  273. package/types/Core/Utils/Constants.d.ts +2 -2
  274. package/types/Core/Utils/EventListeners.d.ts +1 -0
  275. package/types/Core/Utils/Vectors.d.ts +3 -3
  276. package/types/Options/Classes/Options.d.ts +1 -2
  277. package/types/Options/Classes/OptionsColor.d.ts +2 -2
  278. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
  279. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +0 -4
  280. package/types/Options/Interfaces/IOptions.d.ts +1 -2
  281. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -4
  282. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
  283. package/types/Utils/CanvasUtils.d.ts +4 -1
  284. package/types/Utils/ColorUtils.d.ts +2 -2
  285. package/types/Utils/LogUtils.d.ts +11 -0
  286. package/types/Utils/{NumberUtils.d.ts → MathUtils.d.ts} +2 -1
  287. package/types/Utils/TypeUtils.d.ts +2 -2
  288. package/types/Utils/Utils.d.ts +4 -16
  289. package/types/export-types.d.ts +91 -101
  290. package/types/exports.d.ts +2 -9
  291. package/types/index.d.ts +1 -1
  292. package/types/initEngine.d.ts +2 -0
  293. package/umd/Core/Canvas.js +123 -178
  294. package/umd/Core/Container.js +25 -21
  295. package/umd/Core/Engine.js +97 -53
  296. package/umd/Core/Particle.js +54 -59
  297. package/umd/Core/Particles.js +33 -24
  298. package/umd/Core/Retina.js +9 -10
  299. package/umd/Core/Utils/Constants.js +3 -3
  300. package/umd/Core/Utils/EventListeners.js +72 -62
  301. package/umd/Core/Utils/QuadTree.js +3 -3
  302. package/umd/Core/Utils/Ranges.js +4 -4
  303. package/umd/Core/Utils/Vectors.js +15 -21
  304. package/umd/Options/Classes/AnimatableColor.js +3 -3
  305. package/umd/Options/Classes/AnimationOptions.js +6 -6
  306. package/umd/Options/Classes/ColorAnimation.js +3 -3
  307. package/umd/Options/Classes/Options.js +16 -13
  308. package/umd/Options/Classes/Particles/Move/Move.js +5 -8
  309. package/umd/Options/Classes/Particles/Move/MoveAngle.js +4 -4
  310. package/umd/Options/Classes/Particles/Move/MoveAttract.js +3 -3
  311. package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -4
  312. package/umd/Options/Classes/Particles/Move/Spin.js +3 -3
  313. package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -7
  314. package/umd/Options/Classes/Particles/Stroke.js +4 -4
  315. package/umd/Options/Classes/ValueWithRandom.js +3 -3
  316. package/umd/Utils/CanvasUtils.js +69 -22
  317. package/umd/Utils/ColorUtils.js +72 -56
  318. package/umd/Utils/EventDispatcher.js +3 -1
  319. package/umd/Utils/LogUtils.js +36 -0
  320. package/umd/Utils/{NumberUtils.js → MathUtils.js} +16 -8
  321. package/umd/Utils/Utils.js +36 -141
  322. package/umd/bundle.js +4 -4
  323. package/umd/export-types.js +1 -114
  324. package/umd/exports.js +3 -10
  325. package/umd/index.js +4 -8
  326. package/umd/{init.js → initEngine.js} +3 -5
  327. package/browser/Core/Interfaces/IRectSideResult.js +0 -1
  328. package/browser/Core/Interfaces/ITrailFillData.js +0 -1
  329. package/browser/Enums/Modes/CollisionMode.js +0 -6
  330. package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +0 -24
  331. package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +0 -21
  332. package/browser/Options/Classes/Particles/Collisions/Collisions.js +0 -33
  333. package/browser/Options/Classes/Particles/Collisions/CollisionsAbsorb.js +0 -14
  334. package/browser/Options/Classes/Particles/Collisions/CollisionsOverlap.js +0 -18
  335. package/browser/Options/Classes/Particles/Move/MoveTrail.js +0 -23
  336. package/browser/Options/Classes/Particles/Move/MoveTrailFill.js +0 -15
  337. package/browser/Options/Classes/Particles/Shadow.js +0 -35
  338. package/browser/Options/Interfaces/BackgroundMask/IBackgroundMask.js +0 -1
  339. package/browser/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.js +0 -1
  340. package/browser/Options/Interfaces/Particles/Collisions/ICollisions.js +0 -1
  341. package/browser/Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js +0 -1
  342. package/browser/Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js +0 -1
  343. package/browser/Options/Interfaces/Particles/IShadow.js +0 -1
  344. package/browser/Options/Interfaces/Particles/Move/IMoveTrail.js +0 -1
  345. package/browser/Options/Interfaces/Particles/Move/IMoveTrailFill.js +0 -1
  346. package/browser/init.js +0 -6
  347. package/cjs/Core/Interfaces/IRectSideResult.js +0 -2
  348. package/cjs/Core/Interfaces/ITrailFillData.js +0 -2
  349. package/cjs/Enums/Modes/CollisionMode.js +0 -9
  350. package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +0 -28
  351. package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +0 -25
  352. package/cjs/Options/Classes/Particles/Collisions/Collisions.js +0 -37
  353. package/cjs/Options/Classes/Particles/Collisions/CollisionsAbsorb.js +0 -18
  354. package/cjs/Options/Classes/Particles/Collisions/CollisionsOverlap.js +0 -22
  355. package/cjs/Options/Classes/Particles/Move/MoveTrail.js +0 -27
  356. package/cjs/Options/Classes/Particles/Move/MoveTrailFill.js +0 -19
  357. package/cjs/Options/Classes/Particles/Shadow.js +0 -39
  358. package/cjs/Options/Interfaces/BackgroundMask/IBackgroundMask.js +0 -2
  359. package/cjs/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.js +0 -2
  360. package/cjs/Options/Interfaces/Particles/Collisions/ICollisions.js +0 -2
  361. package/cjs/Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js +0 -2
  362. package/cjs/Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js +0 -2
  363. package/cjs/Options/Interfaces/Particles/IShadow.js +0 -2
  364. package/cjs/Options/Interfaces/Particles/Move/IMoveTrail.js +0 -2
  365. package/cjs/Options/Interfaces/Particles/Move/IMoveTrailFill.js +0 -2
  366. package/cjs/Types/RangeType.js +0 -8
  367. package/cjs/Utils/NumberUtils.js +0 -177
  368. package/cjs/init.js +0 -9
  369. package/esm/Core/Interfaces/IRectSideResult.js +0 -1
  370. package/esm/Core/Interfaces/ITrailFillData.js +0 -1
  371. package/esm/Enums/Modes/CollisionMode.js +0 -6
  372. package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +0 -24
  373. package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +0 -21
  374. package/esm/Options/Classes/Particles/Collisions/Collisions.js +0 -33
  375. package/esm/Options/Classes/Particles/Collisions/CollisionsAbsorb.js +0 -14
  376. package/esm/Options/Classes/Particles/Collisions/CollisionsOverlap.js +0 -18
  377. package/esm/Options/Classes/Particles/Move/MoveTrail.js +0 -23
  378. package/esm/Options/Classes/Particles/Move/MoveTrailFill.js +0 -15
  379. package/esm/Options/Classes/Particles/Shadow.js +0 -35
  380. package/esm/Options/Interfaces/BackgroundMask/IBackgroundMask.js +0 -1
  381. package/esm/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.js +0 -1
  382. package/esm/Options/Interfaces/Particles/Collisions/ICollisions.js +0 -1
  383. package/esm/Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js +0 -1
  384. package/esm/Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js +0 -1
  385. package/esm/Options/Interfaces/Particles/IShadow.js +0 -1
  386. package/esm/Options/Interfaces/Particles/Move/IMoveTrail.js +0 -1
  387. package/esm/Options/Interfaces/Particles/Move/IMoveTrailFill.js +0 -1
  388. package/esm/init.js +0 -6
  389. package/types/Core/Interfaces/IRectSideResult.d.ts +0 -5
  390. package/types/Core/Interfaces/ITrailFillData.d.ts +0 -6
  391. package/types/Enums/Modes/CollisionMode.d.ts +0 -5
  392. package/types/Options/Classes/BackgroundMask/BackgroundMask.d.ts +0 -11
  393. package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +0 -11
  394. package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +0 -18
  395. package/types/Options/Classes/Particles/Collisions/CollisionsAbsorb.d.ts +0 -8
  396. package/types/Options/Classes/Particles/Collisions/CollisionsOverlap.d.ts +0 -9
  397. package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +0 -11
  398. package/types/Options/Classes/Particles/Move/MoveTrailFill.d.ts +0 -9
  399. package/types/Options/Classes/Particles/Shadow.d.ts +0 -13
  400. package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +0 -8
  401. package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +0 -6
  402. package/types/Options/Interfaces/Particles/Collisions/ICollisions.d.ts +0 -13
  403. package/types/Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.d.ts +0 -3
  404. package/types/Options/Interfaces/Particles/Collisions/ICollisionsOverlap.d.ts +0 -4
  405. package/types/Options/Interfaces/Particles/IShadow.d.ts +0 -8
  406. package/types/Options/Interfaces/Particles/Move/IMoveTrail.d.ts +0 -6
  407. package/types/Options/Interfaces/Particles/Move/IMoveTrailFill.d.ts +0 -5
  408. package/types/init.d.ts +0 -2
  409. package/umd/Core/Interfaces/IRectSideResult.js +0 -12
  410. package/umd/Core/Interfaces/ITrailFillData.js +0 -12
  411. package/umd/Enums/Modes/CollisionMode.js +0 -19
  412. package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +0 -38
  413. package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +0 -35
  414. package/umd/Options/Classes/Particles/Collisions/Collisions.js +0 -47
  415. package/umd/Options/Classes/Particles/Collisions/CollisionsAbsorb.js +0 -28
  416. package/umd/Options/Classes/Particles/Collisions/CollisionsOverlap.js +0 -32
  417. package/umd/Options/Classes/Particles/Move/MoveTrail.js +0 -37
  418. package/umd/Options/Classes/Particles/Move/MoveTrailFill.js +0 -29
  419. package/umd/Options/Classes/Particles/Shadow.js +0 -49
  420. package/umd/Options/Interfaces/BackgroundMask/IBackgroundMask.js +0 -12
  421. package/umd/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.js +0 -12
  422. package/umd/Options/Interfaces/Particles/Collisions/ICollisions.js +0 -12
  423. package/umd/Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js +0 -12
  424. package/umd/Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js +0 -12
  425. package/umd/Options/Interfaces/Particles/IShadow.js +0 -12
  426. package/umd/Options/Interfaces/Particles/Move/IMoveTrail.js +0 -12
  427. package/umd/Options/Interfaces/Particles/Move/IMoveTrailFill.js +0 -12
  428. /package/browser/{Types → Enums}/RangeType.js +0 -0
  429. /package/{esm/Types → cjs/Enums}/RangeType.js +0 -0
  430. /package/types/{Types → Enums}/RangeType.d.ts +0 -0
  431. /package/umd/{Types → Enums}/RangeType.js +0 -0
@@ -1,21 +1,55 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || (function () {
18
+ var ownKeys = function(o) {
19
+ ownKeys = Object.getOwnPropertyNames || function (o) {
20
+ var ar = [];
21
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
22
+ return ar;
23
+ };
24
+ return ownKeys(o);
25
+ };
26
+ return function (mod) {
27
+ if (mod && mod.__esModule) return mod;
28
+ var result = {};
29
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
30
+ __setModuleDefault(result, mod);
31
+ return result;
32
+ };
33
+ })();
1
34
  (function (factory) {
2
35
  if (typeof module === "object" && typeof module.exports === "object") {
3
36
  var v = factory(require, exports);
4
37
  if (v !== undefined) module.exports = v;
5
38
  }
6
39
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "./Container.js", "../Utils/EventDispatcher.js", "../Enums/Types/EventType.js", "../Utils/NumberUtils.js"], factory);
40
+ define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/EventDispatcher.js", "../Enums/Types/EventType.js", "../Utils/LogUtils.js", "../Utils/MathUtils.js"], factory);
8
41
  }
9
42
  })(function (require, exports) {
10
43
  "use strict";
44
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
11
45
  Object.defineProperty(exports, "__esModule", { value: true });
12
46
  exports.Engine = void 0;
13
47
  const Constants_js_1 = require("./Utils/Constants.js");
14
48
  const Utils_js_1 = require("../Utils/Utils.js");
15
- const Container_js_1 = require("./Container.js");
16
49
  const EventDispatcher_js_1 = require("../Utils/EventDispatcher.js");
17
50
  const EventType_js_1 = require("../Enums/Types/EventType.js");
18
- const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
51
+ const LogUtils_js_1 = require("../Utils/LogUtils.js");
52
+ const MathUtils_js_1 = require("../Utils/MathUtils.js");
19
53
  async function getItemsFromInitializer(container, map, initializers, force = false) {
20
54
  let res = map.get(container);
21
55
  if (!res || force) {
@@ -33,25 +67,23 @@
33
67
  if (response.ok) {
34
68
  return (await response.json());
35
69
  }
36
- (0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
70
+ (0, LogUtils_js_1.getLogger)().error(`${response.status.toString()} while retrieving config file`);
37
71
  return data.fallback;
38
72
  }
39
73
  const getCanvasFromContainer = (domContainer) => {
40
74
  let canvasEl;
41
75
  if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === Constants_js_1.canvasTag) {
42
76
  canvasEl = domContainer;
43
- if (!canvasEl.dataset[Constants_js_1.generatedAttribute]) {
44
- canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
45
- }
77
+ canvasEl.dataset[Constants_js_1.generatedAttribute] ??= Constants_js_1.generatedFalse;
46
78
  }
47
79
  else {
48
- const existingCanvases = domContainer.getElementsByTagName(Constants_js_1.canvasTag);
49
- if (existingCanvases.length) {
50
- canvasEl = existingCanvases[Constants_js_1.canvasFirstIndex];
80
+ const existingCanvases = domContainer.getElementsByTagName(Constants_js_1.canvasTag), foundCanvas = existingCanvases[Constants_js_1.canvasFirstIndex];
81
+ if (foundCanvas) {
82
+ canvasEl = foundCanvas;
51
83
  canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
52
84
  }
53
85
  else {
54
- canvasEl = document.createElement(Constants_js_1.canvasTag);
86
+ canvasEl = (0, Utils_js_1.safeDocument)().createElement(Constants_js_1.canvasTag);
55
87
  canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
56
88
  domContainer.appendChild(canvasEl);
57
89
  }
@@ -65,14 +97,14 @@
65
97
  }
66
98
  return canvasEl;
67
99
  }, getDomContainer = (id, source) => {
68
- let domContainer = source ?? document.getElementById(id);
100
+ let domContainer = source ?? (0, Utils_js_1.safeDocument)().getElementById(id);
69
101
  if (domContainer) {
70
102
  return domContainer;
71
103
  }
72
- domContainer = document.createElement("div");
104
+ domContainer = (0, Utils_js_1.safeDocument)().createElement("div");
73
105
  domContainer.id = id;
74
106
  domContainer.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
75
- document.body.append(domContainer);
107
+ (0, Utils_js_1.safeDocument)().body.append(domContainer);
76
108
  return domContainer;
77
109
  };
78
110
  class Engine {
@@ -81,6 +113,7 @@
81
113
  this._domArray = [];
82
114
  this._eventDispatcher = new EventDispatcher_js_1.EventDispatcher();
83
115
  this._initialized = false;
116
+ this._loadPromises = new Set();
84
117
  this.plugins = [];
85
118
  this.colorManagers = new Map();
86
119
  this.easingFunctions = new Map();
@@ -108,73 +141,65 @@
108
141
  return this._domArray;
109
142
  }
110
143
  get version() {
111
- return "3.9.0";
144
+ return "4.0.0-alpha.0";
112
145
  }
113
- async addColorManager(manager, refresh = true) {
146
+ addColorManager(manager) {
114
147
  this.colorManagers.set(manager.key, manager);
115
- await this.refresh(refresh);
116
148
  }
117
149
  addConfig(config) {
118
150
  const key = config.key ?? config.name ?? "default";
119
151
  this._configs.set(key, config);
120
152
  this._eventDispatcher.dispatchEvent(EventType_js_1.EventType.configAdded, { data: { name: key, config } });
121
153
  }
122
- async addEasing(name, easing, refresh = true) {
123
- if (this.getEasing(name)) {
154
+ addEasing(name, easing) {
155
+ if (this.easingFunctions.get(name)) {
124
156
  return;
125
157
  }
126
158
  this.easingFunctions.set(name, easing);
127
- await this.refresh(refresh);
128
159
  }
129
- async addEffect(effect, drawer, refresh = true) {
130
- (0, Utils_js_1.executeOnSingleOrMultiple)(effect, type => {
131
- if (!this.getEffectDrawer(type)) {
132
- this.effectDrawers.set(type, drawer);
133
- }
134
- });
135
- await this.refresh(refresh);
160
+ addEffect(effect, drawer) {
161
+ if (this.getEffectDrawer(effect)) {
162
+ return;
163
+ }
164
+ this.effectDrawers.set(effect, drawer);
136
165
  }
137
166
  addEventListener(type, listener) {
138
167
  this._eventDispatcher.addEventListener(type, listener);
139
168
  }
140
- async addInteractor(name, interactorInitializer, refresh = true) {
169
+ addInteractor(name, interactorInitializer) {
141
170
  this._initializers.interactors.set(name, interactorInitializer);
142
- await this.refresh(refresh);
143
171
  }
144
- async addMover(name, moverInitializer, refresh = true) {
172
+ addMover(name, moverInitializer) {
145
173
  this._initializers.movers.set(name, moverInitializer);
146
- await this.refresh(refresh);
147
174
  }
148
- async addParticleUpdater(name, updaterInitializer, refresh = true) {
175
+ addParticleUpdater(name, updaterInitializer) {
149
176
  this._initializers.updaters.set(name, updaterInitializer);
150
- await this.refresh(refresh);
151
177
  }
152
- async addPathGenerator(name, generator, refresh = true) {
153
- if (!this.getPathGenerator(name)) {
154
- this.pathGenerators.set(name, generator);
178
+ addPathGenerator(name, generator) {
179
+ if (this.getPathGenerator(name)) {
180
+ return;
155
181
  }
156
- await this.refresh(refresh);
182
+ this.pathGenerators.set(name, generator);
157
183
  }
158
- async addPlugin(plugin, refresh = true) {
159
- if (!this.getPlugin(plugin.id)) {
160
- this.plugins.push(plugin);
184
+ addPlugin(plugin) {
185
+ if (this.getPlugin(plugin.id)) {
186
+ return;
161
187
  }
162
- await this.refresh(refresh);
188
+ this.plugins.push(plugin);
163
189
  }
164
- async addPreset(preset, options, override = false, refresh = true) {
165
- if (override || !this.getPreset(preset)) {
166
- this.presets.set(preset, options);
190
+ addPreset(preset, options, override = false) {
191
+ if (!(override || !this.getPreset(preset))) {
192
+ return;
167
193
  }
168
- await this.refresh(refresh);
194
+ this.presets.set(preset, options);
169
195
  }
170
- async addShape(drawer, refresh = true) {
196
+ addShape(drawer) {
171
197
  for (const validType of drawer.validTypes) {
172
198
  if (this.getShapeDrawer(validType)) {
173
199
  continue;
174
200
  }
175
201
  this.shapeDrawers.set(validType, drawer);
176
202
  }
177
- await this.refresh(refresh);
178
203
  }
179
204
  checkVersion(pluginVersion) {
180
205
  if (this.version === pluginVersion) {
@@ -238,22 +263,29 @@
238
263
  async getUpdaters(container, force = false) {
239
264
  return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
240
265
  }
241
- init() {
266
+ async init() {
242
267
  if (this._initialized) {
243
268
  return;
244
269
  }
270
+ for (const loadPromise of this._loadPromises) {
271
+ await loadPromise(this);
272
+ }
273
+ this._loadPromises.clear();
245
274
  this._initialized = true;
246
275
  }
247
276
  item(index) {
248
277
  const { items } = this, item = items[index];
249
- if (!item || item.destroyed) {
278
+ if (item?.destroyed) {
250
279
  items.splice(index, Constants_js_1.removeDeleteCount);
251
280
  return;
252
281
  }
253
282
  return item;
254
283
  }
255
284
  async load(params) {
256
- const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor)}`, { 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_js_1.Container(this, id, currentOptions);
285
+ await this.init();
286
+ 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
+ params.element?.id ??
288
+ `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);
257
289
  if (oldIndex >= Constants_js_1.loadMinIndex) {
258
290
  const old = this.item(oldIndex), deleteCount = old ? Constants_js_1.one : Constants_js_1.none;
259
291
  if (old && !old.destroyed) {
@@ -270,7 +302,9 @@
270
302
  return newItem;
271
303
  }
272
304
  loadOptions(options, sourceOptions) {
273
- this.plugins.forEach(plugin => plugin.loadOptions?.(options, sourceOptions));
305
+ this.plugins.forEach(plugin => {
306
+ plugin.loadOptions(options, sourceOptions);
307
+ });
274
308
  }
275
309
  loadParticlesOptions(container, options, ...sourceOptions) {
276
310
  const updaters = this.updaters.get(container);
@@ -285,15 +319,25 @@
285
319
  }
286
320
  await Promise.all(this.items.map(t => t.refresh()));
287
321
  }
322
+ register(...loadPromises) {
323
+ if (this._initialized) {
324
+ throw new Error(`Register plugins can only be done before calling tsParticles.load()`);
325
+ }
326
+ for (const loadPromise of loadPromises) {
327
+ this._loadPromises.add(loadPromise);
328
+ }
329
+ }
288
330
  removeEventListener(type, listener) {
289
331
  this._eventDispatcher.removeEventListener(type, listener);
290
332
  }
291
333
  setOnClickHandler(callback) {
292
334
  const { items } = this;
293
335
  if (!items.length) {
294
- throw new Error(`${Constants_js_1.errorPrefix} can only set click handlers after calling tsParticles.load()`);
336
+ throw new Error("Click handlers can only be set after calling tsParticles.load()");
295
337
  }
296
- items.forEach(item => item.addClickHandler(callback));
338
+ items.forEach(item => {
339
+ item.addClickHandler(callback);
340
+ });
297
341
  }
298
342
  }
299
343
  exports.Engine = Engine;
@@ -4,30 +4,26 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./Utils/Vectors.js", "../Utils/NumberUtils.js", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/ColorUtils.js", "../Enums/Types/EventType.js", "../Options/Classes/Interactivity/Interactivity.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Enums/Modes/PixelMode.js", "../Utils/CanvasUtils.js", "../Utils/OptionsUtils.js"], factory);
7
+ define(["require", "exports", "./Utils/Vectors.js", "../Utils/MathUtils.js", "./Utils/Constants.js", "../Utils/Utils.js", "../Enums/Types/EventType.js", "../Options/Classes/Interactivity/Interactivity.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Utils/CanvasUtils.js", "../Utils/ColorUtils.js", "../Utils/OptionsUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Particle = void 0;
13
13
  const Vectors_js_1 = require("./Utils/Vectors.js");
14
- const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
14
+ const MathUtils_js_1 = require("../Utils/MathUtils.js");
15
15
  const Constants_js_1 = require("./Utils/Constants.js");
16
16
  const Utils_js_1 = require("../Utils/Utils.js");
17
- const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
18
17
  const EventType_js_1 = require("../Enums/Types/EventType.js");
19
18
  const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
20
19
  const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
21
20
  const OutMode_js_1 = require("../Enums/Modes/OutMode.js");
22
21
  const ParticleOutType_js_1 = require("../Enums/Types/ParticleOutType.js");
23
- const PixelMode_js_1 = require("../Enums/Modes/PixelMode.js");
24
22
  const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
23
+ const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
25
24
  const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
26
25
  function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
27
26
  const effectData = effectOptions.options[effect];
28
- if (!effectData) {
29
- return;
30
- }
31
27
  return (0, Utils_js_1.deepExtend)({
32
28
  close: effectOptions.close,
33
29
  fill: effectOptions.fill,
@@ -35,9 +31,6 @@
35
31
  }
36
32
  function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
37
33
  const shapeData = shapeOptions.options[shape];
38
- if (!shapeData) {
39
- return;
40
- }
41
34
  return (0, Utils_js_1.deepExtend)({
42
35
  close: shapeOptions.close,
43
36
  fill: shapeOptions.fill,
@@ -59,13 +52,14 @@
59
52
  constructor(engine, container) {
60
53
  this.container = container;
61
54
  this._calcPosition = (container, position, zIndex, tryCount = Constants_js_1.defaultRetryCount) => {
62
- for (const plugin of container.plugins.values()) {
63
- const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
55
+ const plugins = container.plugins.values();
56
+ for (const plugin of plugins) {
57
+ const pluginPos = plugin.particlePosition?.(position, this);
64
58
  if (pluginPos) {
65
59
  return Vectors_js_1.Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
66
60
  }
67
61
  }
68
- const canvasSize = container.canvas.size, exactPosition = (0, NumberUtils_js_1.calcExactPositionOrRandomFromSize)({
62
+ const canvasSize = container.canvas.size, exactPosition = (0, MathUtils_js_1.calcExactPositionOrRandomFromSize)({
69
63
  size: canvasSize,
70
64
  position: position,
71
65
  }), pos = Vectors_js_1.Vector3d.create(exactPosition.x, exactPosition.y, zIndex), radius = this.getRadius(), outModes = this.options.move.outModes, fixHorizontal = (outMode) => {
@@ -91,48 +85,40 @@
91
85
  fixHorizontal(outModes.right ?? outModes.default);
92
86
  fixVertical(outModes.top ?? outModes.default);
93
87
  fixVertical(outModes.bottom ?? outModes.default);
94
- if (this._checkOverlap(pos, tryCount)) {
88
+ let isValidPosition = true;
89
+ for (const plugin of plugins) {
90
+ isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount);
91
+ if (isValidPosition === false) {
92
+ break;
93
+ }
94
+ }
95
+ if (!isValidPosition) {
95
96
  return this._calcPosition(container, undefined, zIndex, tryCount + Constants_js_1.tryCountIncrement);
96
97
  }
97
98
  return pos;
98
99
  };
99
100
  this._calculateVelocity = () => {
100
- const baseVelocity = (0, NumberUtils_js_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
101
+ const baseVelocity = (0, MathUtils_js_1.getParticleBaseVelocity)(this.direction), res = baseVelocity.copy(), moveOptions = this.options.move;
101
102
  if (moveOptions.direction === MoveDirection_js_1.MoveDirection.inside || moveOptions.direction === MoveDirection_js_1.MoveDirection.outside) {
102
103
  return res;
103
104
  }
104
- const rad = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
105
+ const rad = (0, MathUtils_js_1.degToRad)((0, MathUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, MathUtils_js_1.degToRad)((0, MathUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
105
106
  left: radOffset - rad * Constants_js_1.half,
106
107
  right: radOffset + rad * Constants_js_1.half,
107
108
  };
108
109
  if (!moveOptions.straight) {
109
- res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
110
+ res.angle += (0, MathUtils_js_1.randomInRangeValue)((0, MathUtils_js_1.setRangeValue)(range.left, range.right));
110
111
  }
111
112
  if (moveOptions.random && typeof moveOptions.speed === "number") {
112
- res.length *= (0, NumberUtils_js_1.getRandom)();
113
+ res.length *= (0, MathUtils_js_1.getRandom)();
113
114
  }
114
115
  return res;
115
116
  };
116
- this._checkOverlap = (pos, tryCount = Constants_js_1.defaultRetryCount) => {
117
- const collisionsOptions = this.options.collisions, radius = this.getRadius();
118
- if (!collisionsOptions.enable) {
119
- return false;
120
- }
121
- const overlapOptions = collisionsOptions.overlap;
122
- if (overlapOptions.enable) {
123
- return false;
124
- }
125
- const retries = overlapOptions.retries;
126
- if (retries >= Constants_js_1.minRetries && tryCount > retries) {
127
- throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
128
- }
129
- return !!this.container.particles.find(particle => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
130
- };
131
117
  this._getRollColor = color => {
132
118
  if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
133
119
  return color;
134
120
  }
135
- const backFactor = this.roll.horizontal && this.roll.vertical ? Constants_js_1.double * Constants_js_1.rollFactor : Constants_js_1.rollFactor, backSum = this.roll.horizontal ? Math.PI * Constants_js_1.half : Constants_js_1.none, rolled = Math.floor(((this.roll.angle ?? Constants_js_1.none) + backSum) / (Math.PI / backFactor)) % Constants_js_1.double;
121
+ const backFactor = this.roll.horizontal && this.roll.vertical ? Constants_js_1.double * Constants_js_1.rollFactor : Constants_js_1.rollFactor, backSum = this.roll.horizontal ? Math.PI * Constants_js_1.half : Constants_js_1.none, rolled = Math.floor((this.roll.angle + backSum) / (Math.PI / backFactor)) % Constants_js_1.double;
136
122
  if (!rolled) {
137
123
  return color;
138
124
  }
@@ -145,16 +131,16 @@
145
131
  return color;
146
132
  };
147
133
  this._initPosition = position => {
148
- const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value);
149
- this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
134
+ const container = this.container, zIndexValue = (0, MathUtils_js_1.getRangeValue)(this.options.zIndex.value);
135
+ this.position = this._calcPosition(container, position, (0, MathUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
150
136
  this.initialPosition = this.position.copy();
151
137
  const canvasSize = container.canvas.size;
152
138
  this.moveCenter = {
153
139
  ...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
154
- radius: this.options.move.center.radius ?? Constants_js_1.defaultRadius,
155
- mode: this.options.move.center.mode ?? PixelMode_js_1.PixelMode.percent,
140
+ radius: this.options.move.center.radius,
141
+ mode: this.options.move.center.mode,
156
142
  };
157
- this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
143
+ this.direction = (0, MathUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
158
144
  switch (this.options.move.direction) {
159
145
  case MoveDirection_js_1.MoveDirection.inside:
160
146
  this.outType = ParticleOutType_js_1.ParticleOutType.inside;
@@ -174,7 +160,7 @@
174
160
  this.destroyed = true;
175
161
  this.bubble.inRange = false;
176
162
  this.slow.inRange = false;
177
- const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = container.shapeDrawers.get(this.shape);
163
+ const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
178
164
  shapeDrawer?.particleDestroy?.(this);
179
165
  for (const plugin of container.plugins.values()) {
180
166
  plugin.particleDestroyed?.(this, override);
@@ -197,6 +183,9 @@
197
183
  }
198
184
  canvas.drawParticle(this, delta);
199
185
  }
186
+ getAngle() {
187
+ return this.rotation + (this.pathRotation ? this.velocity.angle : Constants_js_1.defaultAngle);
188
+ }
200
189
  getFillColor() {
201
190
  return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
202
191
  }
@@ -236,7 +225,7 @@
236
225
  };
237
226
  this.outType = ParticleOutType_js_1.ParticleOutType.normal;
238
227
  this.ignoresResizeRatio = true;
239
- const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), { reduceDuplicates } = particlesOptions, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
228
+ const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
240
229
  this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
241
230
  this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
242
231
  const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
@@ -258,14 +247,16 @@
258
247
  }
259
248
  if (this.effect === Constants_js_1.randomColorValue) {
260
249
  const availableEffects = [...this.container.effectDrawers.keys()];
261
- this.effect = availableEffects[Math.floor((0, NumberUtils_js_1.getRandom)() * availableEffects.length)];
250
+ this.effect = availableEffects[Math.floor((0, MathUtils_js_1.getRandom)() * availableEffects.length)];
262
251
  }
263
252
  if (this.shape === Constants_js_1.randomColorValue) {
264
253
  const availableShapes = [...this.container.shapeDrawers.keys()];
265
- this.shape = availableShapes[Math.floor((0, NumberUtils_js_1.getRandom)() * availableShapes.length)];
254
+ this.shape = availableShapes[Math.floor((0, MathUtils_js_1.getRandom)() * availableShapes.length)];
266
255
  }
267
- this.effectData = loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates);
268
- this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
256
+ this.effectData = this.effect
257
+ ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates)
258
+ : undefined;
259
+ this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
269
260
  particlesOptions.load(overrideOptions);
270
261
  const effectData = this.effectData;
271
262
  if (effectData) {
@@ -285,7 +276,7 @@
285
276
  this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
286
277
  this.options = particlesOptions;
287
278
  const pathOptions = this.options.move.path;
288
- this.pathDelay = (0, NumberUtils_js_1.getRangeValue)(pathOptions.delay.value) * Constants_js_1.millisecondsToSeconds;
279
+ this.pathDelay = (0, MathUtils_js_1.getRangeValue)(pathOptions.delay.value) * Constants_js_1.millisecondsToSeconds;
289
280
  if (pathOptions.generator) {
290
281
  this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
291
282
  if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
@@ -304,26 +295,31 @@
304
295
  this._initPosition(position);
305
296
  this.initialVelocity = this._calculateVelocity();
306
297
  this.velocity = this.initialVelocity.copy();
307
- this.moveDecay = Constants_js_1.decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
298
+ this.moveDecay = Constants_js_1.decayOffset - (0, MathUtils_js_1.getRangeValue)(this.options.move.decay);
308
299
  const particles = container.particles;
309
300
  particles.setLastZIndex(this.position.z);
310
301
  this.zIndexFactor = this.position.z / container.zLayers;
311
302
  this.sides = 24;
312
- let effectDrawer = container.effectDrawers.get(this.effect);
313
- if (!effectDrawer) {
314
- effectDrawer = this._engine.getEffectDrawer(this.effect);
315
- if (effectDrawer) {
316
- container.effectDrawers.set(this.effect, effectDrawer);
303
+ let effectDrawer, shapeDrawer;
304
+ if (this.effect) {
305
+ effectDrawer = container.effectDrawers.get(this.effect);
306
+ if (!effectDrawer) {
307
+ effectDrawer = this._engine.getEffectDrawer(this.effect);
308
+ if (effectDrawer) {
309
+ container.effectDrawers.set(this.effect, effectDrawer);
310
+ }
317
311
  }
318
312
  }
319
313
  if (effectDrawer?.loadEffect) {
320
314
  effectDrawer.loadEffect(this);
321
315
  }
322
- let shapeDrawer = container.shapeDrawers.get(this.shape);
323
- if (!shapeDrawer) {
324
- shapeDrawer = this._engine.getShapeDrawer(this.shape);
325
- if (shapeDrawer) {
326
- container.shapeDrawers.set(this.shape, shapeDrawer);
316
+ if (this.shape) {
317
+ shapeDrawer = container.shapeDrawers.get(this.shape);
318
+ if (!shapeDrawer) {
319
+ shapeDrawer = this._engine.getShapeDrawer(this.shape);
320
+ if (shapeDrawer) {
321
+ container.shapeDrawers.set(this.shape, shapeDrawer);
322
+ }
327
323
  }
328
324
  }
329
325
  if (shapeDrawer?.loadShape) {
@@ -334,12 +330,11 @@
334
330
  this.sides = sideCountFunc(this);
335
331
  }
336
332
  this.spawning = false;
337
- this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, this.options.shadow.color);
338
333
  for (const updater of particles.updaters) {
339
334
  updater.init(this);
340
335
  }
341
336
  for (const mover of particles.movers) {
342
- mover.init?.(this);
337
+ mover.init(this);
343
338
  }
344
339
  effectDrawer?.particleInit?.(container, this);
345
340
  shapeDrawer?.particleInit?.(container, this);