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