@tsparticles/engine 4.0.0-alpha.8 → 4.0.0-beta.1

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 (307) hide show
  1. package/155.min.js +1 -0
  2. package/README.md +41 -28
  3. package/browser/Core/CanvasManager.js +303 -0
  4. package/browser/Core/Container.js +134 -101
  5. package/browser/Core/Engine.js +29 -162
  6. package/browser/Core/Particle.js +197 -183
  7. package/browser/Core/ParticlesManager.js +363 -0
  8. package/browser/Core/RenderManager.js +303 -0
  9. package/browser/Core/Retina.js +6 -6
  10. package/browser/Core/Utils/Constants.js +2 -2
  11. package/browser/Core/Utils/EventListeners.js +67 -63
  12. package/browser/Core/Utils/PluginManager.js +145 -0
  13. package/browser/Core/Utils/Ranges.js +29 -10
  14. package/browser/Core/Utils/SpatialHashGrid.js +102 -0
  15. package/browser/Core/Utils/Vectors.js +17 -18
  16. package/browser/Options/Classes/AnimatableColor.js +1 -0
  17. package/browser/Options/Classes/AnimationOptions.js +8 -0
  18. package/browser/Options/Classes/Background/Background.js +6 -0
  19. package/browser/Options/Classes/ColorAnimation.js +12 -1
  20. package/browser/Options/Classes/FullScreen/FullScreen.js +2 -0
  21. package/browser/Options/Classes/HslAnimation.js +4 -5
  22. package/browser/Options/Classes/Options.js +67 -8
  23. package/browser/Options/Classes/OptionsColor.js +1 -0
  24. package/browser/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  25. package/browser/Options/Classes/Particles/Effect/Effect.js +3 -4
  26. package/browser/Options/Classes/Particles/Fill.js +28 -0
  27. package/browser/Options/Classes/Particles/Move/Move.js +17 -3
  28. package/browser/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  29. package/browser/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  30. package/browser/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  31. package/browser/Options/Classes/Particles/Move/OutModes.js +5 -0
  32. package/browser/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  33. package/browser/Options/Classes/Particles/Move/Spin.js +3 -0
  34. package/browser/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  35. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  36. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  37. package/browser/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  38. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  39. package/browser/Options/Classes/Particles/ParticlesOptions.js +29 -9
  40. package/browser/Options/Classes/Particles/Shape/Shape.js +3 -4
  41. package/browser/Options/Classes/Particles/Size/Size.js +1 -0
  42. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  43. package/browser/Options/Classes/Particles/Stroke.js +3 -0
  44. package/browser/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  45. package/browser/Options/Classes/ResizeEvent.js +2 -0
  46. package/browser/Options/Classes/ValueWithRandom.js +3 -4
  47. package/browser/Utils/CanvasUtils.js +44 -51
  48. package/browser/Utils/ColorUtils.js +51 -40
  49. package/browser/Utils/EventDispatcher.js +1 -0
  50. package/browser/Utils/LogUtils.js +1 -0
  51. package/browser/Utils/MathUtils.js +12 -7
  52. package/browser/Utils/OptionsUtils.js +2 -2
  53. package/browser/Utils/Utils.js +109 -31
  54. package/browser/exports.js +1 -2
  55. package/cjs/Core/CanvasManager.js +303 -0
  56. package/cjs/Core/Container.js +134 -101
  57. package/cjs/Core/Engine.js +29 -162
  58. package/cjs/Core/Particle.js +197 -183
  59. package/cjs/Core/ParticlesManager.js +363 -0
  60. package/cjs/Core/RenderManager.js +303 -0
  61. package/cjs/Core/Retina.js +6 -6
  62. package/cjs/Core/Utils/Constants.js +2 -2
  63. package/cjs/Core/Utils/EventListeners.js +67 -63
  64. package/cjs/Core/Utils/PluginManager.js +145 -0
  65. package/cjs/Core/Utils/Ranges.js +29 -10
  66. package/cjs/Core/Utils/SpatialHashGrid.js +102 -0
  67. package/cjs/Core/Utils/Vectors.js +17 -18
  68. package/cjs/Options/Classes/AnimatableColor.js +1 -0
  69. package/cjs/Options/Classes/AnimationOptions.js +8 -0
  70. package/cjs/Options/Classes/Background/Background.js +6 -0
  71. package/cjs/Options/Classes/ColorAnimation.js +12 -1
  72. package/cjs/Options/Classes/FullScreen/FullScreen.js +2 -0
  73. package/cjs/Options/Classes/HslAnimation.js +4 -5
  74. package/cjs/Options/Classes/Options.js +67 -8
  75. package/cjs/Options/Classes/OptionsColor.js +1 -0
  76. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  77. package/cjs/Options/Classes/Particles/Effect/Effect.js +3 -4
  78. package/cjs/Options/Classes/Particles/Fill.js +28 -0
  79. package/cjs/Options/Classes/Particles/Move/Move.js +17 -3
  80. package/cjs/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  81. package/cjs/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  82. package/cjs/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  83. package/cjs/Options/Classes/Particles/Move/OutModes.js +5 -0
  84. package/cjs/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  85. package/cjs/Options/Classes/Particles/Move/Spin.js +3 -0
  86. package/cjs/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  87. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  88. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  89. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  90. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  91. package/cjs/Options/Classes/Particles/ParticlesOptions.js +29 -9
  92. package/cjs/Options/Classes/Particles/Shape/Shape.js +3 -4
  93. package/cjs/Options/Classes/Particles/Size/Size.js +1 -0
  94. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  95. package/cjs/Options/Classes/Particles/Stroke.js +3 -0
  96. package/cjs/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  97. package/cjs/Options/Classes/ResizeEvent.js +2 -0
  98. package/cjs/Options/Classes/ValueWithRandom.js +3 -4
  99. package/cjs/Utils/CanvasUtils.js +44 -51
  100. package/cjs/Utils/ColorUtils.js +51 -40
  101. package/cjs/Utils/EventDispatcher.js +1 -0
  102. package/cjs/Utils/LogUtils.js +1 -0
  103. package/cjs/Utils/MathUtils.js +12 -7
  104. package/cjs/Utils/OptionsUtils.js +2 -2
  105. package/cjs/Utils/Utils.js +109 -31
  106. package/cjs/exports.js +1 -2
  107. package/dist_browser_Core_Container_js.js +30 -20
  108. package/esm/Core/CanvasManager.js +303 -0
  109. package/esm/Core/Container.js +134 -101
  110. package/esm/Core/Engine.js +29 -162
  111. package/esm/Core/Particle.js +197 -183
  112. package/esm/Core/ParticlesManager.js +363 -0
  113. package/esm/Core/RenderManager.js +303 -0
  114. package/esm/Core/Retina.js +6 -6
  115. package/esm/Core/Utils/Constants.js +2 -2
  116. package/esm/Core/Utils/EventListeners.js +67 -63
  117. package/esm/Core/Utils/PluginManager.js +145 -0
  118. package/esm/Core/Utils/Ranges.js +29 -10
  119. package/esm/Core/Utils/SpatialHashGrid.js +102 -0
  120. package/esm/Core/Utils/Vectors.js +17 -18
  121. package/esm/Options/Classes/AnimatableColor.js +1 -0
  122. package/esm/Options/Classes/AnimationOptions.js +8 -0
  123. package/esm/Options/Classes/Background/Background.js +6 -0
  124. package/esm/Options/Classes/ColorAnimation.js +12 -1
  125. package/esm/Options/Classes/FullScreen/FullScreen.js +2 -0
  126. package/esm/Options/Classes/HslAnimation.js +4 -5
  127. package/esm/Options/Classes/Options.js +67 -8
  128. package/esm/Options/Classes/OptionsColor.js +1 -0
  129. package/esm/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  130. package/esm/Options/Classes/Particles/Effect/Effect.js +3 -4
  131. package/esm/Options/Classes/Particles/Fill.js +28 -0
  132. package/esm/Options/Classes/Particles/Move/Move.js +17 -3
  133. package/esm/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  134. package/esm/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  135. package/esm/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  136. package/esm/Options/Classes/Particles/Move/OutModes.js +5 -0
  137. package/esm/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  138. package/esm/Options/Classes/Particles/Move/Spin.js +3 -0
  139. package/esm/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  140. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  141. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  142. package/esm/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  143. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  144. package/esm/Options/Classes/Particles/ParticlesOptions.js +29 -9
  145. package/esm/Options/Classes/Particles/Shape/Shape.js +3 -4
  146. package/esm/Options/Classes/Particles/Size/Size.js +1 -0
  147. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  148. package/esm/Options/Classes/Particles/Stroke.js +3 -0
  149. package/esm/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  150. package/esm/Options/Classes/ResizeEvent.js +2 -0
  151. package/esm/Options/Classes/ValueWithRandom.js +3 -4
  152. package/esm/Utils/CanvasUtils.js +44 -51
  153. package/esm/Utils/ColorUtils.js +51 -40
  154. package/esm/Utils/EventDispatcher.js +1 -0
  155. package/esm/Utils/LogUtils.js +1 -0
  156. package/esm/Utils/MathUtils.js +12 -7
  157. package/esm/Utils/OptionsUtils.js +2 -2
  158. package/esm/Utils/Utils.js +109 -31
  159. package/esm/exports.js +1 -2
  160. package/package.json +1 -1
  161. package/report.html +84 -29
  162. package/scripts/install.js +4 -20
  163. package/tsparticles.engine.js +98 -86
  164. package/tsparticles.engine.min.js +2 -2
  165. package/types/Core/CanvasManager.d.ts +39 -0
  166. package/types/Core/Container.d.ts +29 -14
  167. package/types/Core/Engine.d.ts +2 -61
  168. package/types/Core/Interfaces/IColorManager.d.ts +0 -1
  169. package/types/Core/Interfaces/IContainerPlugin.d.ts +10 -8
  170. package/types/Core/Interfaces/IDrawParticleParams.d.ts +2 -1
  171. package/types/Core/Interfaces/IPalette.d.ts +7 -0
  172. package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
  173. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +4 -4
  174. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -1
  175. package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
  176. package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -1
  177. package/types/Core/Interfaces/IShapeDrawer.d.ts +0 -1
  178. package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
  179. package/types/Core/Particle.d.ts +7 -11
  180. package/types/Core/{Particles.d.ts → ParticlesManager.d.ts} +15 -14
  181. package/types/Core/RenderManager.d.ts +49 -0
  182. package/types/Core/Retina.d.ts +0 -2
  183. package/types/Core/Utils/Constants.d.ts +2 -2
  184. package/types/Core/Utils/PluginManager.d.ts +62 -0
  185. package/types/Core/Utils/Ranges.d.ts +4 -1
  186. package/types/Core/Utils/SpatialHashGrid.d.ts +25 -0
  187. package/types/Core/Utils/Vectors.d.ts +8 -10
  188. package/types/Options/Classes/ColorAnimation.d.ts +3 -1
  189. package/types/Options/Classes/HslAnimation.d.ts +3 -4
  190. package/types/Options/Classes/Options.d.ts +5 -3
  191. package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
  192. package/types/Options/Classes/Particles/Fill.d.ts +12 -0
  193. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
  194. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +5 -5
  195. package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
  196. package/types/Options/Classes/ValueWithRandom.d.ts +0 -1
  197. package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
  198. package/types/Options/Interfaces/IOptions.d.ts +1 -0
  199. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
  200. package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
  201. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
  202. package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
  203. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
  204. package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
  205. package/types/Types/CanvasContextType.d.ts +1 -0
  206. package/types/Types/EngineInitializers.d.ts +6 -3
  207. package/types/Utils/CanvasUtils.d.ts +13 -16
  208. package/types/Utils/ColorUtils.d.ts +11 -10
  209. package/types/Utils/LogUtils.d.ts +1 -0
  210. package/types/Utils/MathUtils.d.ts +2 -0
  211. package/types/Utils/OptionsUtils.d.ts +2 -2
  212. package/types/Utils/Utils.d.ts +8 -1
  213. package/types/export-types.d.ts +7 -7
  214. package/types/exports.d.ts +1 -2
  215. package/umd/Core/CanvasManager.js +317 -0
  216. package/umd/Core/Container.js +134 -101
  217. package/umd/Core/Engine.js +28 -161
  218. package/umd/Core/Particle.js +198 -184
  219. package/umd/Core/{Particles.js → ParticlesManager.js} +186 -167
  220. package/umd/Core/RenderManager.js +317 -0
  221. package/umd/Core/Retina.js +6 -6
  222. package/umd/Core/Utils/Constants.js +3 -3
  223. package/umd/Core/Utils/EventListeners.js +67 -63
  224. package/umd/Core/Utils/PluginManager.js +159 -0
  225. package/umd/Core/Utils/Ranges.js +28 -9
  226. package/umd/Core/Utils/SpatialHashGrid.js +116 -0
  227. package/umd/Core/Utils/Vectors.js +17 -18
  228. package/umd/Options/Classes/AnimatableColor.js +1 -0
  229. package/umd/Options/Classes/AnimationOptions.js +8 -0
  230. package/umd/Options/Classes/Background/Background.js +6 -0
  231. package/umd/Options/Classes/ColorAnimation.js +12 -1
  232. package/umd/Options/Classes/FullScreen/FullScreen.js +2 -0
  233. package/umd/Options/Classes/HslAnimation.js +5 -6
  234. package/umd/Options/Classes/Options.js +67 -8
  235. package/umd/Options/Classes/OptionsColor.js +1 -0
  236. package/umd/Options/Classes/Particles/Bounce/ParticlesBounce.js +2 -0
  237. package/umd/Options/Classes/Particles/Effect/Effect.js +3 -4
  238. package/umd/Options/Classes/Particles/Fill.js +42 -0
  239. package/umd/Options/Classes/Particles/Move/Move.js +18 -4
  240. package/umd/Options/Classes/Particles/Move/MoveAngle.js +2 -0
  241. package/umd/Options/Classes/Particles/Move/MoveCenter.js +4 -0
  242. package/umd/Options/Classes/Particles/Move/MoveGravity.js +4 -0
  243. package/umd/Options/Classes/Particles/Move/OutModes.js +5 -0
  244. package/umd/Options/Classes/Particles/Move/Path/MovePath.js +5 -0
  245. package/umd/Options/Classes/Particles/Move/Spin.js +3 -0
  246. package/umd/Options/Classes/Particles/Number/ParticlesDensity.js +3 -0
  247. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +3 -0
  248. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -0
  249. package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -0
  250. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +1 -0
  251. package/umd/Options/Classes/Particles/ParticlesOptions.js +30 -10
  252. package/umd/Options/Classes/Particles/Shape/Shape.js +3 -4
  253. package/umd/Options/Classes/Particles/Size/Size.js +1 -0
  254. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +1 -0
  255. package/umd/Options/Classes/Particles/Stroke.js +3 -0
  256. package/umd/Options/Classes/Particles/ZIndex/ZIndex.js +3 -0
  257. package/umd/Options/Classes/ResizeEvent.js +2 -0
  258. package/umd/Options/Classes/ValueWithRandom.js +3 -4
  259. package/umd/Utils/CanvasUtils.js +44 -53
  260. package/umd/Utils/ColorUtils.js +51 -39
  261. package/umd/Utils/EventDispatcher.js +1 -0
  262. package/umd/Utils/LogUtils.js +1 -0
  263. package/umd/Utils/MathUtils.js +14 -7
  264. package/umd/Utils/OptionsUtils.js +2 -2
  265. package/umd/Utils/Utils.js +111 -32
  266. package/umd/exports.js +2 -3
  267. package/794.min.js +0 -2
  268. package/794.min.js.LICENSE.txt +0 -1
  269. package/browser/Core/Canvas.js +0 -469
  270. package/browser/Core/Particles.js +0 -344
  271. package/browser/Core/Utils/Point.js +0 -6
  272. package/browser/Core/Utils/QuadTree.js +0 -59
  273. package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  274. package/cjs/Core/Canvas.js +0 -469
  275. package/cjs/Core/Particles.js +0 -344
  276. package/cjs/Core/Utils/Point.js +0 -6
  277. package/cjs/Core/Utils/QuadTree.js +0 -59
  278. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  279. package/esm/Core/Canvas.js +0 -469
  280. package/esm/Core/Particles.js +0 -344
  281. package/esm/Core/Utils/Point.js +0 -6
  282. package/esm/Core/Utils/QuadTree.js +0 -59
  283. package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -33
  284. package/tsparticles.engine.min.js.LICENSE.txt +0 -1
  285. package/types/Core/Canvas.d.ts +0 -55
  286. package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -10
  287. package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
  288. package/types/Core/Utils/Point.d.ts +0 -7
  289. package/types/Core/Utils/QuadTree.d.ts +0 -18
  290. package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
  291. package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
  292. package/umd/Core/Canvas.js +0 -483
  293. package/umd/Core/Utils/Point.js +0 -20
  294. package/umd/Core/Utils/QuadTree.js +0 -73
  295. package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -47
  296. /package/browser/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  297. /package/browser/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  298. /package/browser/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  299. /package/cjs/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  300. /package/cjs/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  301. /package/cjs/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  302. /package/esm/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  303. /package/esm/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  304. /package/esm/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
  305. /package/umd/Core/Interfaces/{IMovePathGenerator.js → IPalette.js} +0 -0
  306. /package/umd/{Core/Interfaces/IParticleMover.js → Options/Interfaces/Particles/IFill.js} +0 -0
  307. /package/umd/{Options/Interfaces/Particles/Move/IMoveAttract.js → Types/CanvasContextType.js} +0 -0
@@ -0,0 +1,363 @@
1
+ import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, spatialHashGridCellSize, squareExp, } from "./Utils/Constants.js";
2
+ import { EventType } from "../Enums/Types/EventType.js";
3
+ import { LimitMode } from "../Enums/Modes/LimitMode.js";
4
+ import { Particle } from "./Particle.js";
5
+ import { SpatialHashGrid } from "./Utils/SpatialHashGrid.js";
6
+ import { getLogger } from "../Utils/LogUtils.js";
7
+ import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
8
+ export class ParticlesManager {
9
+ checkParticlePositionPlugins;
10
+ grid;
11
+ _array;
12
+ _container;
13
+ _groupLimits;
14
+ _limit;
15
+ _maxZIndex;
16
+ _minZIndex;
17
+ _needsSort;
18
+ _nextId;
19
+ _particleResetPlugins;
20
+ _particleUpdatePlugins;
21
+ _pluginManager;
22
+ _pool;
23
+ _postParticleUpdatePlugins;
24
+ _postUpdatePlugins;
25
+ _resizeFactor;
26
+ _updatePlugins;
27
+ _zArray;
28
+ constructor(pluginManager, container) {
29
+ this._pluginManager = pluginManager;
30
+ this._container = container;
31
+ this._nextId = 0;
32
+ this._array = [];
33
+ this._zArray = [];
34
+ this._pool = [];
35
+ this._limit = 0;
36
+ this._groupLimits = new Map();
37
+ this._needsSort = false;
38
+ this._minZIndex = 0;
39
+ this._maxZIndex = 0;
40
+ this.grid = new SpatialHashGrid(spatialHashGridCellSize);
41
+ this.checkParticlePositionPlugins = [];
42
+ this._particleResetPlugins = [];
43
+ this._particleUpdatePlugins = [];
44
+ this._postUpdatePlugins = [];
45
+ this._postParticleUpdatePlugins = [];
46
+ this._updatePlugins = [];
47
+ }
48
+ get count() {
49
+ return this._array.length;
50
+ }
51
+ addParticle(position, overrideOptions, group, initializer) {
52
+ const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
53
+ if (limit > minLimit) {
54
+ switch (limitMode) {
55
+ case LimitMode.delete: {
56
+ const countToRemove = currentCount + countOffset - limit;
57
+ if (countToRemove > minCount) {
58
+ this.removeQuantity(countToRemove);
59
+ }
60
+ break;
61
+ }
62
+ case LimitMode.wait:
63
+ if (currentCount >= limit) {
64
+ return;
65
+ }
66
+ break;
67
+ default:
68
+ break;
69
+ }
70
+ }
71
+ try {
72
+ const particle = this._pool.pop() ?? new Particle(this._pluginManager, this._container);
73
+ particle.init(this._nextId, position, overrideOptions, group);
74
+ let canAdd = true;
75
+ if (initializer) {
76
+ canAdd = initializer(particle);
77
+ }
78
+ if (!canAdd) {
79
+ this._pool.push(particle);
80
+ return;
81
+ }
82
+ this._array.push(particle);
83
+ this._zArray.push(particle);
84
+ this._nextId++;
85
+ this._container.dispatchEvent(EventType.particleAdded, {
86
+ particle,
87
+ });
88
+ return particle;
89
+ }
90
+ catch (e) {
91
+ getLogger().warning(`error adding particle: ${e}`);
92
+ }
93
+ return undefined;
94
+ }
95
+ clear() {
96
+ this._array = [];
97
+ this._zArray = [];
98
+ }
99
+ destroy() {
100
+ this._array = [];
101
+ this._pool.length = 0;
102
+ this._zArray = [];
103
+ this.checkParticlePositionPlugins = [];
104
+ this._particleResetPlugins = [];
105
+ this._particleUpdatePlugins = [];
106
+ this._postUpdatePlugins = [];
107
+ this._postParticleUpdatePlugins = [];
108
+ this._updatePlugins = [];
109
+ }
110
+ drawParticles(delta) {
111
+ for (const particle of this._zArray) {
112
+ particle.draw(delta);
113
+ }
114
+ }
115
+ filter(condition) {
116
+ return this._array.filter(condition);
117
+ }
118
+ find(condition) {
119
+ return this._array.find(condition);
120
+ }
121
+ get(index) {
122
+ return this._array[index];
123
+ }
124
+ async init() {
125
+ const container = this._container, options = container.actualOptions;
126
+ this._minZIndex = 0;
127
+ this._maxZIndex = 0;
128
+ this._needsSort = false;
129
+ this.checkParticlePositionPlugins = [];
130
+ this._updatePlugins = [];
131
+ this._particleUpdatePlugins = [];
132
+ this._postUpdatePlugins = [];
133
+ this._particleResetPlugins = [];
134
+ this._postParticleUpdatePlugins = [];
135
+ this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
136
+ for (const plugin of container.plugins) {
137
+ if (plugin.redrawInit) {
138
+ await plugin.redrawInit();
139
+ }
140
+ if (plugin.checkParticlePosition) {
141
+ this.checkParticlePositionPlugins.push(plugin);
142
+ }
143
+ if (plugin.update) {
144
+ this._updatePlugins.push(plugin);
145
+ }
146
+ if (plugin.particleUpdate) {
147
+ this._particleUpdatePlugins.push(plugin);
148
+ }
149
+ if (plugin.postUpdate) {
150
+ this._postUpdatePlugins.push(plugin);
151
+ }
152
+ if (plugin.particleReset) {
153
+ this._particleResetPlugins.push(plugin);
154
+ }
155
+ if (plugin.postParticleUpdate) {
156
+ this._postParticleUpdatePlugins.push(plugin);
157
+ }
158
+ }
159
+ await this._container.initDrawersAndUpdaters();
160
+ for (const drawer of this._container.effectDrawers.values()) {
161
+ await drawer.init?.(container);
162
+ }
163
+ for (const drawer of this._container.shapeDrawers.values()) {
164
+ await drawer.init?.(container);
165
+ }
166
+ let handled = false;
167
+ for (const plugin of container.plugins) {
168
+ handled = plugin.particlesInitialization?.() ?? handled;
169
+ if (handled) {
170
+ break;
171
+ }
172
+ }
173
+ if (!handled) {
174
+ const particlesOptions = options.particles, groups = particlesOptions.groups;
175
+ for (const group in groups) {
176
+ const groupOptions = groups[group];
177
+ if (!groupOptions) {
178
+ continue;
179
+ }
180
+ for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
181
+ this.addParticle(undefined, groupOptions, group);
182
+ }
183
+ }
184
+ for (let i = this.count; i < particlesOptions.number.value; i++) {
185
+ this.addParticle();
186
+ }
187
+ }
188
+ }
189
+ push(nb, position, overrideOptions, group) {
190
+ for (let i = 0; i < nb; i++) {
191
+ this.addParticle(position, overrideOptions, group);
192
+ }
193
+ }
194
+ async redraw() {
195
+ this.clear();
196
+ await this.init();
197
+ this._container.canvas.render.drawParticles({ value: 0, factor: 0 });
198
+ }
199
+ remove(particle, group, override) {
200
+ this.removeAt(this._array.indexOf(particle), undefined, group, override);
201
+ }
202
+ removeAt(index, quantity = defaultRemoveQuantity, group, override) {
203
+ if (index < minIndex || index > this.count) {
204
+ return;
205
+ }
206
+ let deleted = 0;
207
+ for (let i = index; deleted < quantity && i < this.count; i++) {
208
+ if (this._removeParticle(i, group, override)) {
209
+ i--;
210
+ deleted++;
211
+ }
212
+ }
213
+ }
214
+ removeQuantity(quantity, group) {
215
+ this.removeAt(minIndex, quantity, group);
216
+ }
217
+ setDensity() {
218
+ const options = this._container.actualOptions, groups = options.particles.groups;
219
+ let pluginsCount = 0;
220
+ for (const plugin of this._container.plugins) {
221
+ if (plugin.particlesDensityCount) {
222
+ pluginsCount += plugin.particlesDensityCount();
223
+ }
224
+ }
225
+ for (const group in groups) {
226
+ const groupData = groups[group];
227
+ if (!groupData) {
228
+ continue;
229
+ }
230
+ const groupDataOptions = loadParticlesOptions(this._pluginManager, this._container, groupData);
231
+ this._applyDensity(groupDataOptions, pluginsCount, group);
232
+ }
233
+ this._applyDensity(options.particles, pluginsCount);
234
+ }
235
+ setLastZIndex(zIndex) {
236
+ this._needsSort ||= zIndex >= this._maxZIndex || (zIndex > this._minZIndex && zIndex < this._maxZIndex);
237
+ }
238
+ setResizeFactor(factor) {
239
+ this._resizeFactor = factor;
240
+ }
241
+ update(delta) {
242
+ const particlesToDelete = new Set();
243
+ this.grid.clear();
244
+ for (const plugin of this._updatePlugins) {
245
+ plugin.update?.(delta);
246
+ }
247
+ const resizeFactor = this._resizeFactor;
248
+ for (const particle of this._array) {
249
+ if (resizeFactor && !particle.ignoresResizeRatio) {
250
+ particle.position.x *= resizeFactor.width;
251
+ particle.position.y *= resizeFactor.height;
252
+ particle.initialPosition.x *= resizeFactor.width;
253
+ particle.initialPosition.y *= resizeFactor.height;
254
+ }
255
+ particle.ignoresResizeRatio = false;
256
+ for (const plugin of this._particleResetPlugins) {
257
+ plugin.particleReset?.(particle);
258
+ }
259
+ for (const plugin of this._particleUpdatePlugins) {
260
+ if (particle.destroyed) {
261
+ break;
262
+ }
263
+ plugin.particleUpdate?.(particle, delta);
264
+ }
265
+ if (particle.destroyed) {
266
+ particlesToDelete.add(particle);
267
+ continue;
268
+ }
269
+ this.grid.insert(particle);
270
+ }
271
+ for (const plugin of this._postUpdatePlugins) {
272
+ plugin.postUpdate?.(delta);
273
+ }
274
+ for (const particle of this._array) {
275
+ if (particle.destroyed) {
276
+ particlesToDelete.add(particle);
277
+ continue;
278
+ }
279
+ for (const updater of this._container.particleUpdaters) {
280
+ updater.update(particle, delta);
281
+ }
282
+ if (!particle.destroyed && !particle.spawning) {
283
+ for (const plugin of this._postParticleUpdatePlugins) {
284
+ plugin.postParticleUpdate?.(particle, delta);
285
+ }
286
+ }
287
+ else if (particle.destroyed) {
288
+ particlesToDelete.add(particle);
289
+ }
290
+ }
291
+ if (particlesToDelete.size) {
292
+ for (const particle of particlesToDelete) {
293
+ this.remove(particle);
294
+ }
295
+ }
296
+ delete this._resizeFactor;
297
+ if (this._needsSort) {
298
+ const zArray = this._zArray;
299
+ zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
300
+ const firstItem = zArray[minIndex], lastItem = zArray[zArray.length - lengthOffset];
301
+ if (!firstItem || !lastItem) {
302
+ return;
303
+ }
304
+ this._maxZIndex = firstItem.position.z;
305
+ this._minZIndex = lastItem.position.z;
306
+ this._needsSort = false;
307
+ }
308
+ }
309
+ _addToPool = (...particles) => {
310
+ this._pool.push(...particles);
311
+ };
312
+ _applyDensity = (options, pluginsCount, group, groupOptions) => {
313
+ const numberOptions = options.number;
314
+ if (!numberOptions.density.enable) {
315
+ if (group === undefined) {
316
+ this._limit = numberOptions.limit.value;
317
+ }
318
+ else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
319
+ this._groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
320
+ }
321
+ return;
322
+ }
323
+ const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
324
+ if (group === undefined) {
325
+ this._limit = numberOptions.limit.value * densityFactor;
326
+ }
327
+ else {
328
+ this._groupLimits.set(group, numberOptions.limit.value * densityFactor);
329
+ }
330
+ if (particlesCount < particlesNumber) {
331
+ this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
332
+ }
333
+ else if (particlesCount > particlesNumber) {
334
+ this.removeQuantity(particlesCount - particlesNumber, group);
335
+ }
336
+ };
337
+ _initDensityFactor = densityOptions => {
338
+ const container = this._container;
339
+ if (!container.canvas.element || !densityOptions.enable) {
340
+ return defaultDensityFactor;
341
+ }
342
+ const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
343
+ return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
344
+ };
345
+ _removeParticle = (index, group, override) => {
346
+ const particle = this._array[index];
347
+ if (!particle) {
348
+ return false;
349
+ }
350
+ if (particle.group !== group) {
351
+ return false;
352
+ }
353
+ const zIdx = this._zArray.indexOf(particle);
354
+ this._array.splice(index, deleteCount);
355
+ this._zArray.splice(zIdx, deleteCount);
356
+ particle.destroy(override);
357
+ this._container.dispatchEvent(EventType.particleRemoved, {
358
+ particle,
359
+ });
360
+ this._addToPool(particle);
361
+ return true;
362
+ };
363
+ }
@@ -0,0 +1,303 @@
1
+ import { clear, drawParticle, drawParticlePlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
2
+ import { defaultCompositeValue, defaultTransformValue, minimumSize, zIndexFactorOffset } from "./Utils/Constants.js";
3
+ import { getStyleFromHsl, rangeColorToHsl } from "../Utils/ColorUtils.js";
4
+ const fColorIndex = 0, sColorIndex = 1;
5
+ function setTransformValue(factor, newFactor, key) {
6
+ const newValue = newFactor[key];
7
+ if (newValue !== undefined) {
8
+ factor[key] = (factor[key] ?? defaultTransformValue) * newValue;
9
+ }
10
+ }
11
+ export class RenderManager {
12
+ _canvasClearPlugins;
13
+ _canvasManager;
14
+ _canvasPaintPlugins;
15
+ _clearDrawPlugins;
16
+ _colorPlugins;
17
+ _container;
18
+ _context;
19
+ _contextSettings;
20
+ _drawParticlePlugins;
21
+ _drawParticlesCleanupPlugins;
22
+ _drawParticlesSetupPlugins;
23
+ _drawPlugins;
24
+ _drawSettingsCleanupPlugins;
25
+ _drawSettingsSetupPlugins;
26
+ _pluginManager;
27
+ _postDrawUpdaters;
28
+ _preDrawUpdaters;
29
+ _reusableColorStyles = {};
30
+ _reusablePluginColors = [undefined, undefined];
31
+ _reusableTransform = {};
32
+ constructor(pluginManager, container, canvasManager) {
33
+ this._pluginManager = pluginManager;
34
+ this._container = container;
35
+ this._canvasManager = canvasManager;
36
+ this._context = null;
37
+ this._preDrawUpdaters = [];
38
+ this._postDrawUpdaters = [];
39
+ this._colorPlugins = [];
40
+ this._canvasClearPlugins = [];
41
+ this._canvasPaintPlugins = [];
42
+ this._clearDrawPlugins = [];
43
+ this._drawParticlePlugins = [];
44
+ this._drawParticlesCleanupPlugins = [];
45
+ this._drawParticlesSetupPlugins = [];
46
+ this._drawPlugins = [];
47
+ this._drawSettingsSetupPlugins = [];
48
+ this._drawSettingsCleanupPlugins = [];
49
+ }
50
+ get settings() {
51
+ return this._contextSettings;
52
+ }
53
+ canvasClear() {
54
+ if (!this._container.actualOptions.clear) {
55
+ return;
56
+ }
57
+ this.draw(ctx => {
58
+ clear(ctx, this._canvasManager.size);
59
+ });
60
+ }
61
+ clear() {
62
+ let pluginHandled = false;
63
+ for (const plugin of this._canvasClearPlugins) {
64
+ pluginHandled = plugin.canvasClear?.() ?? false;
65
+ if (pluginHandled) {
66
+ break;
67
+ }
68
+ }
69
+ if (pluginHandled) {
70
+ return;
71
+ }
72
+ this.canvasClear();
73
+ }
74
+ destroy() {
75
+ this.stop();
76
+ this._preDrawUpdaters = [];
77
+ this._postDrawUpdaters = [];
78
+ this._colorPlugins = [];
79
+ this._canvasClearPlugins = [];
80
+ this._canvasPaintPlugins = [];
81
+ this._clearDrawPlugins = [];
82
+ this._drawParticlePlugins = [];
83
+ this._drawParticlesCleanupPlugins = [];
84
+ this._drawParticlesSetupPlugins = [];
85
+ this._drawPlugins = [];
86
+ this._drawSettingsSetupPlugins = [];
87
+ this._drawSettingsCleanupPlugins = [];
88
+ }
89
+ draw(cb) {
90
+ const ctx = this._context;
91
+ if (!ctx) {
92
+ return;
93
+ }
94
+ return cb(ctx);
95
+ }
96
+ drawParticle(particle, delta) {
97
+ if (particle.spawning || particle.destroyed) {
98
+ return;
99
+ }
100
+ const radius = particle.getRadius();
101
+ if (radius <= minimumSize) {
102
+ return;
103
+ }
104
+ const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
105
+ let [fColor, sColor] = this._getPluginParticleColors(particle);
106
+ fColor ??= pfColor;
107
+ sColor ??= psColor;
108
+ if (!fColor && !sColor) {
109
+ return;
110
+ }
111
+ const container = this._container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
112
+ transform.a = transform.b = transform.c = transform.d = undefined;
113
+ colorStyles.fill = fill;
114
+ colorStyles.stroke = stroke;
115
+ this.draw((context) => {
116
+ for (const plugin of this._drawParticlesSetupPlugins) {
117
+ plugin.drawParticleSetup?.(context, particle, delta);
118
+ }
119
+ this._applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
120
+ drawParticle({
121
+ container,
122
+ context,
123
+ particle,
124
+ delta,
125
+ colorStyles,
126
+ radius: radius * zIndexFactor ** zIndexOptions.sizeRate,
127
+ opacity: opacity,
128
+ transform,
129
+ });
130
+ this._applyPostDrawUpdaters(particle);
131
+ for (const plugin of this._drawParticlesCleanupPlugins) {
132
+ plugin.drawParticleCleanup?.(context, particle, delta);
133
+ }
134
+ });
135
+ }
136
+ drawParticlePlugins(particle, delta) {
137
+ this.draw(ctx => {
138
+ for (const plugin of this._drawParticlePlugins) {
139
+ drawParticlePlugin(ctx, plugin, particle, delta);
140
+ }
141
+ });
142
+ }
143
+ drawParticles(delta) {
144
+ const { particles } = this._container;
145
+ this.clear();
146
+ particles.update(delta);
147
+ this.draw(ctx => {
148
+ for (const plugin of this._drawSettingsSetupPlugins) {
149
+ plugin.drawSettingsSetup?.(ctx, delta);
150
+ }
151
+ for (const plugin of this._drawPlugins) {
152
+ plugin.draw?.(ctx, delta);
153
+ }
154
+ particles.drawParticles(delta);
155
+ for (const plugin of this._clearDrawPlugins) {
156
+ plugin.clearDraw?.(ctx, delta);
157
+ }
158
+ for (const plugin of this._drawSettingsCleanupPlugins) {
159
+ plugin.drawSettingsCleanup?.(ctx, delta);
160
+ }
161
+ });
162
+ }
163
+ init() {
164
+ this.initUpdaters();
165
+ this.initPlugins();
166
+ this.paint();
167
+ }
168
+ initPlugins() {
169
+ this._colorPlugins = [];
170
+ this._canvasClearPlugins = [];
171
+ this._canvasPaintPlugins = [];
172
+ this._clearDrawPlugins = [];
173
+ this._drawParticlePlugins = [];
174
+ this._drawParticlesSetupPlugins = [];
175
+ this._drawParticlesCleanupPlugins = [];
176
+ this._drawPlugins = [];
177
+ this._drawSettingsSetupPlugins = [];
178
+ this._drawSettingsCleanupPlugins = [];
179
+ for (const plugin of this._container.plugins) {
180
+ if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
181
+ this._colorPlugins.push(plugin);
182
+ }
183
+ if (plugin.canvasClear) {
184
+ this._canvasClearPlugins.push(plugin);
185
+ }
186
+ if (plugin.canvasPaint) {
187
+ this._canvasPaintPlugins.push(plugin);
188
+ }
189
+ if (plugin.drawParticle) {
190
+ this._drawParticlePlugins.push(plugin);
191
+ }
192
+ if (plugin.drawParticleSetup) {
193
+ this._drawParticlesSetupPlugins.push(plugin);
194
+ }
195
+ if (plugin.drawParticleCleanup) {
196
+ this._drawParticlesCleanupPlugins.push(plugin);
197
+ }
198
+ if (plugin.draw) {
199
+ this._drawPlugins.push(plugin);
200
+ }
201
+ if (plugin.drawSettingsSetup) {
202
+ this._drawSettingsSetupPlugins.push(plugin);
203
+ }
204
+ if (plugin.drawSettingsCleanup) {
205
+ this._drawSettingsCleanupPlugins.push(plugin);
206
+ }
207
+ if (plugin.clearDraw) {
208
+ this._clearDrawPlugins.push(plugin);
209
+ }
210
+ }
211
+ }
212
+ initUpdaters() {
213
+ this._preDrawUpdaters = [];
214
+ this._postDrawUpdaters = [];
215
+ for (const updater of this._container.particleUpdaters) {
216
+ if (updater.afterDraw) {
217
+ this._postDrawUpdaters.push(updater);
218
+ }
219
+ if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
220
+ this._preDrawUpdaters.push(updater);
221
+ }
222
+ }
223
+ }
224
+ paint() {
225
+ let handled = false;
226
+ for (const plugin of this._canvasPaintPlugins) {
227
+ handled = plugin.canvasPaint?.() ?? false;
228
+ if (handled) {
229
+ break;
230
+ }
231
+ }
232
+ if (handled) {
233
+ return;
234
+ }
235
+ this.paintBase();
236
+ }
237
+ paintBase(baseColor) {
238
+ this.draw(ctx => {
239
+ paintBase(ctx, this._canvasManager.size, baseColor);
240
+ });
241
+ }
242
+ paintImage(image, opacity) {
243
+ this.draw(ctx => {
244
+ paintImage(ctx, this._canvasManager.size, image, opacity);
245
+ });
246
+ }
247
+ setContext(context) {
248
+ this._context = context;
249
+ if (this._context) {
250
+ this._context.globalCompositeOperation = defaultCompositeValue;
251
+ }
252
+ }
253
+ setContextSettings(settings) {
254
+ this._contextSettings = settings;
255
+ }
256
+ stop() {
257
+ this.draw(ctx => {
258
+ clear(ctx, this._canvasManager.size);
259
+ });
260
+ }
261
+ _applyPostDrawUpdaters = particle => {
262
+ for (const updater of this._postDrawUpdaters) {
263
+ updater.afterDraw?.(particle);
264
+ }
265
+ };
266
+ _applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
267
+ for (const updater of this._preDrawUpdaters) {
268
+ if (updater.getColorStyles) {
269
+ const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
270
+ if (fill) {
271
+ colorStyles.fill = fill;
272
+ }
273
+ if (stroke) {
274
+ colorStyles.stroke = stroke;
275
+ }
276
+ }
277
+ if (updater.getTransformValues) {
278
+ const updaterTransform = updater.getTransformValues(particle);
279
+ for (const key in updaterTransform) {
280
+ setTransformValue(transform, updaterTransform, key);
281
+ }
282
+ }
283
+ updater.beforeDraw?.(particle);
284
+ }
285
+ };
286
+ _getPluginParticleColors = particle => {
287
+ let fColor, sColor;
288
+ for (const plugin of this._colorPlugins) {
289
+ if (!fColor && plugin.particleFillColor) {
290
+ fColor = rangeColorToHsl(this._pluginManager, plugin.particleFillColor(particle));
291
+ }
292
+ if (!sColor && plugin.particleStrokeColor) {
293
+ sColor = rangeColorToHsl(this._pluginManager, plugin.particleStrokeColor(particle));
294
+ }
295
+ if (fColor && sColor) {
296
+ break;
297
+ }
298
+ }
299
+ this._reusablePluginColors[fColorIndex] = fColor;
300
+ this._reusablePluginColors[sColorIndex] = sColor;
301
+ return this._reusablePluginColors;
302
+ };
303
+ }
@@ -1,6 +1,9 @@
1
1
  import { defaultRatio, defaultReduceFactor } from "./Utils/Constants.js";
2
2
  import { getRangeValue } from "../Utils/MathUtils.js";
3
3
  export class Retina {
4
+ container;
5
+ pixelRatio;
6
+ reduceFactor;
4
7
  constructor(container) {
5
8
  this.container = container;
6
9
  this.pixelRatio = defaultRatio;
@@ -16,18 +19,15 @@ export class Retina {
16
19
  canvas.size.width = element.offsetWidth * ratio;
17
20
  canvas.size.height = element.offsetHeight * ratio;
18
21
  }
19
- const particles = options.particles, moveOptions = particles.move;
20
- this.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
21
- this.sizeAnimationSpeed = getRangeValue(particles.size.animation.speed) * ratio;
22
22
  }
23
23
  initParticle(particle) {
24
24
  const options = particle.options, ratio = this.pixelRatio, moveOptions = options.move, moveDistance = moveOptions.distance, props = particle.retina;
25
+ props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
25
26
  props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
26
27
  props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
27
28
  props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
28
29
  const maxDistance = props.maxDistance;
29
- maxDistance.horizontal = moveDistance.horizontal !== undefined ? moveDistance.horizontal * ratio : undefined;
30
- maxDistance.vertical = moveDistance.vertical !== undefined ? moveDistance.vertical * ratio : undefined;
31
- props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
30
+ maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
31
+ maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
32
32
  }
33
33
  }