@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
@@ -6,7 +6,7 @@ const Constants_1 = require("./Constants");
6
6
  function manageListener(element, event, handler, add, options) {
7
7
  if (add) {
8
8
  let addOptions = { passive: true };
9
- if (typeof options === "boolean") {
9
+ if ((0, Utils_1.isBoolean)(options)) {
10
10
  addOptions.capture = options;
11
11
  }
12
12
  else if (options !== undefined) {
@@ -22,101 +22,71 @@ function manageListener(element, event, handler, add, options) {
22
22
  class EventListeners {
23
23
  constructor(container) {
24
24
  this.container = container;
25
- this.canPush = true;
26
- this.handlers = {
27
- mouseMove: (e) => this._mouseTouchMove(e),
28
- touchStart: (e) => this._mouseTouchMove(e),
29
- touchMove: (e) => this._mouseTouchMove(e),
30
- touchEnd: () => this._mouseTouchFinish(),
31
- mouseLeave: () => this._mouseTouchFinish(),
32
- touchCancel: () => this._mouseTouchFinish(),
33
- touchEndClick: (e) => this._mouseTouchClick(e),
34
- mouseUp: (e) => this._mouseTouchClick(e),
35
- mouseDown: () => this._mouseDown(),
36
- visibilityChange: () => this._handleVisibilityChange(),
37
- themeChange: (e) => this._handleThemeChange(e),
38
- oldThemeChange: (e) => this._handleThemeChange(e),
39
- resize: () => this._handleWindowResize(),
25
+ this._doMouseTouchClick = (e) => {
26
+ const container = this.container, options = container.actualOptions;
27
+ if (this._canPush) {
28
+ const mouseInteractivity = container.interactivity.mouse, mousePos = mouseInteractivity.position;
29
+ if (!mousePos) {
30
+ return;
31
+ }
32
+ mouseInteractivity.clickPosition = { ...mousePos };
33
+ mouseInteractivity.clickTime = new Date().getTime();
34
+ const onClick = options.interactivity.events.onClick;
35
+ (0, Utils_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this.container.handleClickMode(mode));
36
+ }
37
+ if (e.type === "touchend") {
38
+ setTimeout(() => this._mouseTouchFinish(), 500);
39
+ }
40
40
  };
41
- }
42
- addListeners() {
43
- this._manageListeners(true);
44
- }
45
- removeListeners() {
46
- this._manageListeners(false);
47
- }
48
- _doMouseTouchClick(e) {
49
- const container = this.container, options = container.actualOptions;
50
- if (this.canPush) {
51
- const mouseInteractivity = container.interactivity.mouse, mousePos = mouseInteractivity.position;
52
- if (!mousePos) {
41
+ this._handleThemeChange = (e) => {
42
+ const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
43
+ if (theme && theme.default.auto) {
44
+ container.loadTheme(themeName);
45
+ }
46
+ };
47
+ this._handleVisibilityChange = () => {
48
+ const container = this.container, options = container.actualOptions;
49
+ this._mouseTouchFinish();
50
+ if (!options.pauseOnBlur) {
53
51
  return;
54
52
  }
55
- mouseInteractivity.clickPosition = Object.assign({}, mousePos);
56
- mouseInteractivity.clickTime = new Date().getTime();
57
- const onClick = options.interactivity.events.onClick;
58
- (0, Utils_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this._handleClickMode(mode));
59
- }
60
- if (e.type === "touchend") {
61
- setTimeout(() => this._mouseTouchFinish(), 500);
62
- }
63
- }
64
- _handleClickMode(mode) {
65
- this.container.handleClickMode(mode);
66
- }
67
- _handleThemeChange(e) {
68
- const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
69
- if (theme && theme.default.auto) {
70
- container.loadTheme(themeName);
71
- }
72
- }
73
- _handleVisibilityChange() {
74
- const container = this.container, options = container.actualOptions;
75
- this._mouseTouchFinish();
76
- if (!options.pauseOnBlur) {
77
- return;
78
- }
79
- container.pageHidden = (document === null || document === void 0 ? void 0 : document.hidden) || false;
80
- if (container.pageHidden) {
81
- container.pause();
82
- }
83
- else {
84
- if (container.getAnimationStatus()) {
85
- container.play(true);
53
+ if (document && document.hidden) {
54
+ container.pageHidden = true;
55
+ container.pause();
86
56
  }
87
57
  else {
88
- container.draw(true);
58
+ container.pageHidden = false;
59
+ if (container.getAnimationStatus()) {
60
+ container.play(true);
61
+ }
62
+ else {
63
+ container.draw(true);
64
+ }
65
+ }
66
+ };
67
+ this._handleWindowResize = async () => {
68
+ if (this._resizeTimeout) {
69
+ clearTimeout(this._resizeTimeout);
70
+ delete this._resizeTimeout;
71
+ }
72
+ this._resizeTimeout = setTimeout(async () => {
73
+ const canvas = this.container.canvas;
74
+ canvas && (await canvas.windowResize());
75
+ }, this.container.actualOptions.interactivity.events.resize.delay * 1000);
76
+ };
77
+ this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
78
+ const handlers = this._handlers, container = this.container, options = container.actualOptions;
79
+ const interactivityEl = container.interactivity.element;
80
+ if (!interactivityEl) {
81
+ return;
82
+ }
83
+ const html = interactivityEl, canvasEl = container.canvas.element;
84
+ if (canvasEl) {
85
+ canvasEl.style.pointerEvents = html === canvasEl ? "initial" : "none";
86
+ }
87
+ if (!(options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable)) {
88
+ return;
89
89
  }
90
- }
91
- }
92
- _handleWindowResize() {
93
- if (this.resizeTimeout) {
94
- clearTimeout(this.resizeTimeout);
95
- delete this.resizeTimeout;
96
- }
97
- this.resizeTimeout = setTimeout(async () => { var _a; return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize(); }, this.container.actualOptions.interactivity.events.resize.delay * 1000);
98
- }
99
- _manageInteractivityEvents(add) {
100
- var _a;
101
- const handlers = this.handlers, container = this.container, options = container.actualOptions, detectType = options.interactivity.detectsOn;
102
- let mouseLeaveTmpEvent = Constants_1.mouseLeaveEvent;
103
- if (detectType === "window") {
104
- container.interactivity.element = window;
105
- mouseLeaveTmpEvent = Constants_1.mouseOutEvent;
106
- }
107
- else if (detectType === "parent" && container.canvas.element) {
108
- const canvasEl = container.canvas.element;
109
- container.interactivity.element = (_a = canvasEl.parentElement) !== null && _a !== void 0 ? _a : canvasEl.parentNode;
110
- }
111
- else {
112
- container.interactivity.element = container.canvas.element;
113
- }
114
- const interactivityEl = container.interactivity.element;
115
- if (!interactivityEl) {
116
- return;
117
- }
118
- const html = interactivityEl;
119
- if (options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable) {
120
90
  manageListener(interactivityEl, Constants_1.mouseMoveEvent, handlers.mouseMove, add);
121
91
  manageListener(interactivityEl, Constants_1.touchStartEvent, handlers.touchStart, add);
122
92
  manageListener(interactivityEl, Constants_1.touchMoveEvent, handlers.touchMove, add);
@@ -130,170 +100,224 @@ class EventListeners {
130
100
  }
131
101
  manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
132
102
  manageListener(interactivityEl, Constants_1.touchCancelEvent, handlers.touchCancel, add);
133
- }
134
- if (container.canvas.element) {
135
- container.canvas.element.style.pointerEvents = html === container.canvas.element ? "initial" : "none";
136
- }
137
- }
138
- _manageListeners(add) {
139
- this._manageMediaEvents(add);
140
- this._manageInteractivityEvents(add);
141
- this._manageResizeEvent(add);
142
- this._manageVisibilityEvent(add);
143
- }
144
- _manageMediaEvents(add) {
145
- const handlers = this.handlers, mediaMatch = (0, Utils_1.safeMatchMedia)("(prefers-color-scheme: dark)");
146
- if (!mediaMatch) {
147
- return;
148
- }
149
- if (mediaMatch.addEventListener !== undefined) {
150
- manageListener(mediaMatch, "change", handlers.themeChange, add);
151
- return;
152
- }
153
- if (mediaMatch.addListener !== undefined) {
103
+ };
104
+ this._manageListeners = (add) => {
105
+ const handlers = this._handlers, container = this.container, options = container.actualOptions, detectType = options.interactivity.detectsOn, canvasEl = container.canvas.element;
106
+ let mouseLeaveTmpEvent = Constants_1.mouseLeaveEvent;
107
+ if (detectType === "window") {
108
+ container.interactivity.element = window;
109
+ mouseLeaveTmpEvent = Constants_1.mouseOutEvent;
110
+ }
111
+ else if (detectType === "parent" && canvasEl) {
112
+ container.interactivity.element = canvasEl.parentElement ?? canvasEl.parentNode;
113
+ }
114
+ else {
115
+ container.interactivity.element = canvasEl;
116
+ }
117
+ this._manageMediaMatch(add);
118
+ this._manageResize(add);
119
+ this._manageInteractivityListeners(mouseLeaveTmpEvent, add);
120
+ if (document) {
121
+ manageListener(document, Constants_1.visibilityChangeEvent, handlers.visibilityChange, add, false);
122
+ }
123
+ };
124
+ this._manageMediaMatch = (add) => {
125
+ const handlers = this._handlers, mediaMatch = (0, Utils_1.safeMatchMedia)("(prefers-color-scheme: dark)");
126
+ if (!mediaMatch) {
127
+ return;
128
+ }
129
+ if (mediaMatch.addEventListener !== undefined) {
130
+ manageListener(mediaMatch, "change", handlers.themeChange, add);
131
+ return;
132
+ }
133
+ if (mediaMatch.addListener === undefined) {
134
+ return;
135
+ }
154
136
  if (add) {
155
137
  mediaMatch.addListener(handlers.oldThemeChange);
156
138
  }
157
139
  else {
158
140
  mediaMatch.removeListener(handlers.oldThemeChange);
159
141
  }
160
- }
161
- }
162
- _manageResizeEvent(add) {
163
- const handlers = this.handlers, container = this.container, options = container.actualOptions;
164
- if (!options.interactivity.events.resize) {
165
- return;
166
- }
167
- if (typeof ResizeObserver === "undefined") {
168
- manageListener(window, Constants_1.resizeEvent, handlers.resize, add);
169
- return;
170
- }
171
- if (this.resizeObserver && !add) {
172
- if (container.canvas.element) {
173
- this.resizeObserver.unobserve(container.canvas.element);
142
+ };
143
+ this._manageResize = (add) => {
144
+ const handlers = this._handlers, container = this.container, options = container.actualOptions;
145
+ if (!options.interactivity.events.resize) {
146
+ return;
174
147
  }
175
- this.resizeObserver.disconnect();
176
- delete this.resizeObserver;
177
- }
178
- else if (!this.resizeObserver && add && container.canvas.element) {
179
- this.resizeObserver = new ResizeObserver((entries) => {
180
- const entry = entries.find((e) => e.target === container.canvas.element);
181
- if (!entry) {
182
- return;
148
+ if (typeof ResizeObserver === "undefined") {
149
+ manageListener(window, Constants_1.resizeEvent, handlers.resize, add);
150
+ return;
151
+ }
152
+ const canvasEl = container.canvas.element;
153
+ if (this._resizeObserver && !add) {
154
+ if (canvasEl) {
155
+ this._resizeObserver.unobserve(canvasEl);
183
156
  }
184
- this._handleWindowResize();
185
- });
186
- this.resizeObserver.observe(container.canvas.element);
187
- }
188
- }
189
- _manageVisibilityEvent(add) {
190
- if (!document) {
191
- return;
192
- }
193
- manageListener(document, Constants_1.visibilityChangeEvent, this.handlers.visibilityChange, add);
194
- }
195
- _mouseDown() {
196
- const interactivity = this.container.interactivity;
197
- if (interactivity) {
198
- const mouse = interactivity.mouse;
157
+ this._resizeObserver.disconnect();
158
+ delete this._resizeObserver;
159
+ }
160
+ else if (!this._resizeObserver && add && canvasEl) {
161
+ this._resizeObserver = new ResizeObserver(async (entries) => {
162
+ const entry = entries.find((e) => e.target === canvasEl);
163
+ if (!entry) {
164
+ return;
165
+ }
166
+ await this._handleWindowResize();
167
+ });
168
+ this._resizeObserver.observe(canvasEl);
169
+ }
170
+ };
171
+ this._mouseDown = () => {
172
+ const { interactivity } = this.container;
173
+ if (!interactivity) {
174
+ return;
175
+ }
176
+ const { mouse } = interactivity;
199
177
  mouse.clicking = true;
200
178
  mouse.downPosition = mouse.position;
201
- }
202
- }
203
- _mouseTouchClick(e) {
204
- const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse;
205
- mouse.inside = true;
206
- let handled = false;
207
- const mousePosition = mouse.position;
208
- if (!mousePosition || !options.interactivity.events.onClick.enable) {
209
- return;
210
- }
211
- for (const [, plugin] of container.plugins) {
212
- if (!plugin.clickPositionValid) {
213
- continue;
214
- }
215
- handled = plugin.clickPositionValid(mousePosition);
216
- if (handled) {
217
- break;
179
+ };
180
+ this._mouseTouchClick = (e) => {
181
+ const container = this.container, options = container.actualOptions, { mouse } = container.interactivity;
182
+ mouse.inside = true;
183
+ let handled = false;
184
+ const mousePosition = mouse.position;
185
+ if (!mousePosition || !options.interactivity.events.onClick.enable) {
186
+ return;
218
187
  }
219
- }
220
- if (!handled) {
221
- this._doMouseTouchClick(e);
222
- }
223
- mouse.clicking = false;
224
- }
225
- _mouseTouchFinish() {
226
- const interactivity = this.container.interactivity;
227
- if (!interactivity) {
228
- return;
229
- }
230
- const mouse = interactivity.mouse;
231
- delete mouse.position;
232
- delete mouse.clickPosition;
233
- delete mouse.downPosition;
234
- interactivity.status = Constants_1.mouseLeaveEvent;
235
- mouse.inside = false;
236
- mouse.clicking = false;
237
- }
238
- _mouseTouchMove(e) {
239
- var _a, _b, _c, _d, _e, _f, _g;
240
- const container = this.container, options = container.actualOptions;
241
- if (!((_a = container.interactivity) === null || _a === void 0 ? void 0 : _a.element)) {
242
- return;
243
- }
244
- container.interactivity.mouse.inside = true;
245
- let pos;
246
- const canvas = container.canvas.element;
247
- if (e.type.startsWith("pointer")) {
248
- this.canPush = true;
249
- const mouseEvent = e;
250
- if (container.interactivity.element === window) {
251
- if (canvas) {
252
- const clientRect = canvas.getBoundingClientRect();
253
- pos = {
254
- x: mouseEvent.clientX - clientRect.left,
255
- y: mouseEvent.clientY - clientRect.top,
256
- };
188
+ for (const [, plugin] of container.plugins) {
189
+ if (!plugin.clickPositionValid) {
190
+ continue;
257
191
  }
192
+ handled = plugin.clickPositionValid(mousePosition);
193
+ if (handled) {
194
+ break;
195
+ }
196
+ }
197
+ if (!handled) {
198
+ this._doMouseTouchClick(e);
199
+ }
200
+ mouse.clicking = false;
201
+ };
202
+ this._mouseTouchFinish = () => {
203
+ const interactivity = this.container.interactivity;
204
+ if (!interactivity) {
205
+ return;
206
+ }
207
+ const mouse = interactivity.mouse;
208
+ delete mouse.position;
209
+ delete mouse.clickPosition;
210
+ delete mouse.downPosition;
211
+ interactivity.status = Constants_1.mouseLeaveEvent;
212
+ mouse.inside = false;
213
+ mouse.clicking = false;
214
+ };
215
+ this._mouseTouchMove = (e) => {
216
+ const container = this.container, options = container.actualOptions, interactivity = container.interactivity, canvasEl = container.canvas.element;
217
+ if (!interactivity || !interactivity.element) {
218
+ return;
258
219
  }
259
- else if (options.interactivity.detectsOn === "parent") {
260
- const source = mouseEvent.target, target = mouseEvent.currentTarget, canvasEl = container.canvas.element;
261
- if (source && target && canvasEl) {
262
- const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
220
+ interactivity.mouse.inside = true;
221
+ let pos;
222
+ if (e.type.startsWith("pointer")) {
223
+ this._canPush = true;
224
+ const mouseEvent = e;
225
+ if (interactivity.element === window) {
226
+ if (canvasEl) {
227
+ const clientRect = canvasEl.getBoundingClientRect();
228
+ pos = {
229
+ x: mouseEvent.clientX - clientRect.left,
230
+ y: mouseEvent.clientY - clientRect.top,
231
+ };
232
+ }
233
+ }
234
+ else if (options.interactivity.detectsOn === "parent") {
235
+ const source = mouseEvent.target, target = mouseEvent.currentTarget;
236
+ if (source && target && canvasEl) {
237
+ const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
238
+ pos = {
239
+ x: mouseEvent.offsetX + 2 * sourceRect.left - (targetRect.left + canvasRect.left),
240
+ y: mouseEvent.offsetY + 2 * sourceRect.top - (targetRect.top + canvasRect.top),
241
+ };
242
+ }
243
+ else {
244
+ pos = {
245
+ x: mouseEvent.offsetX ?? mouseEvent.clientX,
246
+ y: mouseEvent.offsetY ?? mouseEvent.clientY,
247
+ };
248
+ }
249
+ }
250
+ else if (mouseEvent.target === canvasEl) {
263
251
  pos = {
264
- x: mouseEvent.offsetX + 2 * sourceRect.left - (targetRect.left + canvasRect.left),
265
- y: mouseEvent.offsetY + 2 * sourceRect.top - (targetRect.top + canvasRect.top),
252
+ x: mouseEvent.offsetX ?? mouseEvent.clientX,
253
+ y: mouseEvent.offsetY ?? mouseEvent.clientY,
266
254
  };
267
255
  }
268
- else {
256
+ }
257
+ else {
258
+ this._canPush = e.type !== "touchmove";
259
+ if (canvasEl) {
260
+ const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - 1], canvasRect = canvasEl.getBoundingClientRect();
269
261
  pos = {
270
- x: (_b = mouseEvent.offsetX) !== null && _b !== void 0 ? _b : mouseEvent.clientX,
271
- y: (_c = mouseEvent.offsetY) !== null && _c !== void 0 ? _c : mouseEvent.clientY,
262
+ x: lastTouch.clientX - (canvasRect.left ?? 0),
263
+ y: lastTouch.clientY - (canvasRect.top ?? 0),
272
264
  };
273
265
  }
274
266
  }
275
- else if (mouseEvent.target === container.canvas.element) {
276
- pos = {
277
- x: (_d = mouseEvent.offsetX) !== null && _d !== void 0 ? _d : mouseEvent.clientX,
278
- y: (_e = mouseEvent.offsetY) !== null && _e !== void 0 ? _e : mouseEvent.clientY,
279
- };
267
+ const pxRatio = container.retina.pixelRatio;
268
+ if (pos) {
269
+ pos.x *= pxRatio;
270
+ pos.y *= pxRatio;
280
271
  }
281
- }
282
- else {
283
- this.canPush = e.type !== "touchmove";
284
- const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - 1], canvasRect = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect();
285
- pos = {
286
- x: lastTouch.clientX - ((_f = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) !== null && _f !== void 0 ? _f : 0),
287
- y: lastTouch.clientY - ((_g = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) !== null && _g !== void 0 ? _g : 0),
288
- };
289
- }
290
- const pxRatio = container.retina.pixelRatio;
291
- if (pos) {
292
- pos.x *= pxRatio;
293
- pos.y *= pxRatio;
294
- }
295
- container.interactivity.mouse.position = pos;
296
- container.interactivity.status = Constants_1.mouseMoveEvent;
272
+ interactivity.mouse.position = pos;
273
+ interactivity.status = Constants_1.mouseMoveEvent;
274
+ };
275
+ this._touchEnd = (e) => {
276
+ const evt = e, touches = Array.from(evt.changedTouches);
277
+ for (const touch of touches) {
278
+ this._touches.delete(touch.identifier);
279
+ }
280
+ this._mouseTouchFinish();
281
+ };
282
+ this._touchEndClick = (e) => {
283
+ const evt = e, touches = Array.from(evt.changedTouches);
284
+ for (const touch of touches) {
285
+ this._touches.delete(touch.identifier);
286
+ }
287
+ this._mouseTouchClick(e);
288
+ };
289
+ this._touchStart = (e) => {
290
+ const evt = e, touches = Array.from(evt.changedTouches);
291
+ for (const touch of touches) {
292
+ this._touches.set(touch.identifier, performance.now());
293
+ }
294
+ this._mouseTouchMove(e);
295
+ };
296
+ this._canPush = true;
297
+ this._touches = new Map();
298
+ this._handlers = {
299
+ mouseDown: () => this._mouseDown(),
300
+ mouseLeave: () => this._mouseTouchFinish(),
301
+ mouseMove: (e) => this._mouseTouchMove(e),
302
+ mouseUp: (e) => this._mouseTouchClick(e),
303
+ touchStart: (e) => this._touchStart(e),
304
+ touchMove: (e) => this._mouseTouchMove(e),
305
+ touchEnd: (e) => this._touchEnd(e),
306
+ touchCancel: (e) => this._touchEnd(e),
307
+ touchEndClick: (e) => this._touchEndClick(e),
308
+ visibilityChange: () => this._handleVisibilityChange(),
309
+ themeChange: (e) => this._handleThemeChange(e),
310
+ oldThemeChange: (e) => this._handleThemeChange(e),
311
+ resize: () => {
312
+ this._handleWindowResize();
313
+ },
314
+ };
315
+ }
316
+ addListeners() {
317
+ this._manageListeners(true);
318
+ }
319
+ removeListeners() {
320
+ this._manageListeners(false);
297
321
  }
298
322
  }
299
323
  exports.EventListeners = EventListeners;
@@ -5,22 +5,18 @@ class InteractionManager {
5
5
  constructor(engine, container) {
6
6
  this.container = container;
7
7
  this._engine = engine;
8
- this._interactors = this._engine.plugins.getInteractors(this.container, true);
8
+ this._interactors = engine.getInteractors(this.container, true);
9
9
  this._externalInteractors = [];
10
10
  this._particleInteractors = [];
11
11
  }
12
12
  async externalInteract(delta) {
13
13
  for (const interactor of this._externalInteractors) {
14
- if (interactor.isEnabled()) {
15
- await interactor.interact(delta);
16
- }
14
+ interactor.isEnabled() && (await interactor.interact(delta));
17
15
  }
18
16
  }
19
17
  handleClickMode(mode) {
20
18
  for (const interactor of this._externalInteractors) {
21
- if (interactor.handleClickMode) {
22
- interactor.handleClickMode(mode);
23
- }
19
+ interactor.handleClickMode && interactor.handleClickMode(mode);
24
20
  }
25
21
  }
26
22
  init() {
@@ -43,21 +39,15 @@ class InteractionManager {
43
39
  interactor.clear(particle, delta);
44
40
  }
45
41
  for (const interactor of this._particleInteractors) {
46
- if (interactor.isEnabled(particle)) {
47
- await interactor.interact(particle, delta);
48
- }
42
+ interactor.isEnabled(particle) && (await interactor.interact(particle, delta));
49
43
  }
50
44
  }
51
45
  async reset(particle) {
52
46
  for (const interactor of this._externalInteractors) {
53
- if (interactor.isEnabled()) {
54
- await interactor.reset(particle);
55
- }
47
+ interactor.isEnabled() && interactor.reset(particle);
56
48
  }
57
49
  for (const interactor of this._particleInteractors) {
58
- if (interactor.isEnabled(particle)) {
59
- await interactor.reset(particle);
60
- }
50
+ interactor.isEnabled(particle) && interactor.reset(particle);
61
51
  }
62
52
  }
63
53
  }
@@ -8,11 +8,18 @@ class QuadTree {
8
8
  constructor(rectangle, capacity) {
9
9
  this.rectangle = rectangle;
10
10
  this.capacity = capacity;
11
+ this._subdivide = () => {
12
+ const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
13
+ for (let i = 0; i < 4; i++) {
14
+ this._subs.push(new QuadTree(new Rectangle_1.Rectangle(x + (width / 2) * (i % 2), y + (height / 2) * (Math.round(i / 2) - (i % 2)), width / 2, height / 2), capacity));
15
+ }
16
+ this._divided = true;
17
+ };
11
18
  this._points = [];
12
19
  this._divided = false;
20
+ this._subs = [];
13
21
  }
14
22
  insert(point) {
15
- var _a, _b, _c, _d, _e;
16
23
  if (!this.rectangle.contains(point.position)) {
17
24
  return false;
18
25
  }
@@ -21,16 +28,12 @@ class QuadTree {
21
28
  return true;
22
29
  }
23
30
  if (!this._divided) {
24
- this.subdivide();
31
+ this._subdivide();
25
32
  }
26
- return ((_e = (((_a = this._NE) === null || _a === void 0 ? void 0 : _a.insert(point)) ||
27
- ((_b = this._NW) === null || _b === void 0 ? void 0 : _b.insert(point)) ||
28
- ((_c = this._SE) === null || _c === void 0 ? void 0 : _c.insert(point)) ||
29
- ((_d = this._SW) === null || _d === void 0 ? void 0 : _d.insert(point)))) !== null && _e !== void 0 ? _e : false);
33
+ return this._subs.some((sub) => sub.insert(point));
30
34
  }
31
35
  query(range, check, found) {
32
- var _a, _b, _c, _d;
33
- const res = found !== null && found !== void 0 ? found : [];
36
+ const res = found || [];
34
37
  if (!range.intersects(this.rectangle)) {
35
38
  return [];
36
39
  }
@@ -43,10 +46,9 @@ class QuadTree {
43
46
  res.push(p.particle);
44
47
  }
45
48
  if (this._divided) {
46
- (_a = this._NE) === null || _a === void 0 ? void 0 : _a.query(range, check, res);
47
- (_b = this._NW) === null || _b === void 0 ? void 0 : _b.query(range, check, res);
48
- (_c = this._SE) === null || _c === void 0 ? void 0 : _c.query(range, check, res);
49
- (_d = this._SW) === null || _d === void 0 ? void 0 : _d.query(range, check, res);
49
+ for (const sub of this._subs) {
50
+ sub.query(range, check, res);
51
+ }
50
52
  }
51
53
  return res;
52
54
  }
@@ -56,13 +58,5 @@ class QuadTree {
56
58
  queryRectangle(position, size, check) {
57
59
  return this.query(new Rectangle_1.Rectangle(position.x, position.y, size.width, size.height), check);
58
60
  }
59
- subdivide() {
60
- const x = this.rectangle.position.x, y = this.rectangle.position.y, w = this.rectangle.size.width, h = this.rectangle.size.height, capacity = this.capacity;
61
- this._NE = new QuadTree(new Rectangle_1.Rectangle(x, y, w / 2, h / 2), capacity);
62
- this._NW = new QuadTree(new Rectangle_1.Rectangle(x + w / 2, y, w / 2, h / 2), capacity);
63
- this._SE = new QuadTree(new Rectangle_1.Rectangle(x, y + h / 2, w / 2, h / 2), capacity);
64
- this._SW = new QuadTree(new Rectangle_1.Rectangle(x + w / 2, y + h / 2, w / 2, h / 2), capacity);
65
- this._divided = true;
66
- }
67
61
  }
68
62
  exports.QuadTree = QuadTree;