@tsparticles/engine 4.0.0-alpha.3 → 4.0.0-alpha.4

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 (266) hide show
  1. package/794.min.js +2 -0
  2. package/794.min.js.LICENSE.txt +1 -0
  3. package/README.md +2 -5
  4. package/browser/Core/Canvas.js +3 -3
  5. package/browser/Core/Container.js +35 -155
  6. package/browser/Core/Engine.js +10 -51
  7. package/browser/Core/Particle.js +5 -10
  8. package/browser/Core/Particles.js +36 -25
  9. package/browser/Core/Utils/Constants.js +2 -2
  10. package/browser/Core/Utils/EventListeners.js +5 -250
  11. package/browser/Options/Classes/Options.js +7 -75
  12. package/browser/Options/Classes/Particles/ParticlesOptions.js +5 -11
  13. package/{esm/Options/Classes/Interactivity/Events → browser/Options/Classes}/ResizeEvent.js +1 -1
  14. package/browser/Utils/ColorUtils.js +7 -5
  15. package/browser/Utils/Utils.js +25 -32
  16. package/browser/exports.js +1 -21
  17. package/cjs/Core/Canvas.js +3 -3
  18. package/cjs/Core/Container.js +35 -155
  19. package/cjs/Core/Engine.js +10 -51
  20. package/cjs/Core/Particle.js +5 -10
  21. package/cjs/Core/Particles.js +36 -25
  22. package/cjs/Core/Utils/Constants.js +2 -2
  23. package/cjs/Core/Utils/EventListeners.js +5 -250
  24. package/cjs/Options/Classes/Options.js +7 -75
  25. package/cjs/Options/Classes/Particles/ParticlesOptions.js +5 -11
  26. package/cjs/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +1 -1
  27. package/cjs/Utils/ColorUtils.js +7 -5
  28. package/cjs/Utils/Utils.js +25 -32
  29. package/cjs/exports.js +1 -21
  30. package/dist_browser_Core_Container_js.js +6 -16
  31. package/esm/Core/Canvas.js +3 -3
  32. package/esm/Core/Container.js +35 -155
  33. package/esm/Core/Engine.js +10 -51
  34. package/esm/Core/Particle.js +5 -10
  35. package/esm/Core/Particles.js +36 -25
  36. package/esm/Core/Utils/Constants.js +2 -2
  37. package/esm/Core/Utils/EventListeners.js +5 -250
  38. package/esm/Options/Classes/Options.js +7 -75
  39. package/esm/Options/Classes/Particles/ParticlesOptions.js +5 -11
  40. package/{browser/Options/Classes/Interactivity/Events → esm/Options/Classes}/ResizeEvent.js +1 -1
  41. package/esm/Utils/ColorUtils.js +7 -5
  42. package/esm/Utils/Utils.js +25 -32
  43. package/esm/exports.js +1 -21
  44. package/package.json +1 -1
  45. package/report.html +1 -1
  46. package/tsparticles.engine.js +14 -206
  47. package/tsparticles.engine.min.js +1 -1
  48. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  49. package/types/Core/Container.d.ts +3 -15
  50. package/types/Core/Engine.d.ts +3 -18
  51. package/types/Core/Interfaces/IContainerPlugin.d.ts +8 -1
  52. package/types/Core/Interfaces/IPlugin.d.ts +5 -1
  53. package/types/Core/Particle.d.ts +0 -2
  54. package/types/Core/Particles.d.ts +1 -5
  55. package/types/Core/Utils/Constants.d.ts +2 -2
  56. package/types/Core/Utils/EventListeners.d.ts +0 -14
  57. package/types/Options/Classes/Options.d.ts +2 -11
  58. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +0 -2
  59. package/types/Options/Classes/ResizeEvent.d.ts +9 -0
  60. package/types/Options/Interfaces/IOptions.d.ts +2 -8
  61. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +0 -3
  62. package/types/Types/EngineInitializers.d.ts +10 -0
  63. package/types/Utils/Utils.d.ts +4 -6
  64. package/types/export-types.d.ts +3 -19
  65. package/types/exports.d.ts +1 -21
  66. package/umd/Core/Canvas.js +3 -3
  67. package/umd/Core/Container.js +35 -155
  68. package/umd/Core/Engine.js +11 -52
  69. package/umd/Core/Particle.js +6 -11
  70. package/umd/Core/Particles.js +37 -26
  71. package/umd/Core/Utils/Constants.js +3 -3
  72. package/umd/Core/Utils/EventListeners.js +7 -252
  73. package/umd/Options/Classes/Options.js +7 -75
  74. package/umd/Options/Classes/Particles/ParticlesOptions.js +5 -11
  75. package/umd/Options/Classes/{Interactivity/Events/ResizeEvent.js → ResizeEvent.js} +2 -2
  76. package/umd/Utils/ColorUtils.js +7 -5
  77. package/umd/Utils/Utils.js +26 -35
  78. package/umd/exports.js +2 -22
  79. package/638.min.js +0 -2
  80. package/638.min.js.LICENSE.txt +0 -1
  81. package/browser/Core/Interfaces/IMouseData.js +0 -1
  82. package/browser/Core/Interfaces/IParticlesInteractor.js +0 -1
  83. package/browser/Core/Utils/ExternalInteractorBase.js +0 -7
  84. package/browser/Core/Utils/InteractionManager.js +0 -60
  85. package/browser/Core/Utils/ParticlesInteractorBase.js +0 -7
  86. package/browser/Enums/InteractivityDetect.js +0 -6
  87. package/browser/Enums/Modes/ResponsiveMode.js +0 -5
  88. package/browser/Enums/Modes/ThemeMode.js +0 -6
  89. package/browser/Enums/Types/DivType.js +0 -5
  90. package/browser/Enums/Types/InteractorType.js +0 -5
  91. package/browser/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  92. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  93. package/browser/Options/Classes/Interactivity/Events/Events.js +0 -30
  94. package/browser/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  95. package/browser/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  96. package/browser/Options/Classes/Interactivity/Interactivity.js +0 -22
  97. package/browser/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  98. package/browser/Options/Classes/ManualParticle.js +0 -21
  99. package/browser/Options/Classes/Responsive.js +0 -29
  100. package/browser/Options/Classes/Theme/Theme.js +0 -21
  101. package/browser/Options/Classes/Theme/ThemeDefault.js +0 -23
  102. package/browser/Options/Interfaces/IManualParticle.js +0 -1
  103. package/browser/Options/Interfaces/IResponsive.js +0 -1
  104. package/browser/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  105. package/browser/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  106. package/browser/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  107. package/browser/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  108. package/browser/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  109. package/browser/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  110. package/browser/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  111. package/browser/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  112. package/browser/Options/Interfaces/Theme/ITheme.js +0 -1
  113. package/browser/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  114. package/cjs/Core/Interfaces/IContainerInteractivity.js +0 -1
  115. package/cjs/Core/Interfaces/IExternalInteractor.js +0 -1
  116. package/cjs/Core/Interfaces/IInteractor.js +0 -1
  117. package/cjs/Core/Interfaces/IMouseData.js +0 -1
  118. package/cjs/Core/Interfaces/IParticlesInteractor.js +0 -1
  119. package/cjs/Core/Utils/ExternalInteractorBase.js +0 -7
  120. package/cjs/Core/Utils/InteractionManager.js +0 -60
  121. package/cjs/Core/Utils/ParticlesInteractorBase.js +0 -7
  122. package/cjs/Enums/InteractivityDetect.js +0 -6
  123. package/cjs/Enums/Modes/ResponsiveMode.js +0 -5
  124. package/cjs/Enums/Modes/ThemeMode.js +0 -6
  125. package/cjs/Enums/Types/DivType.js +0 -5
  126. package/cjs/Enums/Types/InteractorType.js +0 -5
  127. package/cjs/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  128. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  129. package/cjs/Options/Classes/Interactivity/Events/Events.js +0 -30
  130. package/cjs/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  131. package/cjs/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  132. package/cjs/Options/Classes/Interactivity/Interactivity.js +0 -22
  133. package/cjs/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  134. package/cjs/Options/Classes/ManualParticle.js +0 -21
  135. package/cjs/Options/Classes/Responsive.js +0 -29
  136. package/cjs/Options/Classes/Theme/Theme.js +0 -21
  137. package/cjs/Options/Classes/Theme/ThemeDefault.js +0 -23
  138. package/cjs/Options/Interfaces/IManualParticle.js +0 -1
  139. package/cjs/Options/Interfaces/IResponsive.js +0 -1
  140. package/cjs/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  141. package/cjs/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  142. package/cjs/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  143. package/cjs/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  144. package/cjs/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  145. package/cjs/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  146. package/cjs/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  147. package/cjs/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  148. package/cjs/Options/Interfaces/Theme/ITheme.js +0 -1
  149. package/cjs/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  150. package/esm/Core/Interfaces/IContainerInteractivity.js +0 -1
  151. package/esm/Core/Interfaces/IExternalInteractor.js +0 -1
  152. package/esm/Core/Interfaces/IInteractor.js +0 -1
  153. package/esm/Core/Interfaces/IMouseData.js +0 -1
  154. package/esm/Core/Interfaces/IParticlesInteractor.js +0 -1
  155. package/esm/Core/Utils/ExternalInteractorBase.js +0 -7
  156. package/esm/Core/Utils/InteractionManager.js +0 -60
  157. package/esm/Core/Utils/ParticlesInteractorBase.js +0 -7
  158. package/esm/Enums/InteractivityDetect.js +0 -6
  159. package/esm/Enums/Modes/ResponsiveMode.js +0 -5
  160. package/esm/Enums/Modes/ThemeMode.js +0 -6
  161. package/esm/Enums/Types/DivType.js +0 -5
  162. package/esm/Enums/Types/InteractorType.js +0 -5
  163. package/esm/Options/Classes/Interactivity/Events/ClickEvent.js +0 -18
  164. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +0 -27
  165. package/esm/Options/Classes/Interactivity/Events/Events.js +0 -30
  166. package/esm/Options/Classes/Interactivity/Events/HoverEvent.js +0 -21
  167. package/esm/Options/Classes/Interactivity/Events/Parallax.js +0 -22
  168. package/esm/Options/Classes/Interactivity/Interactivity.js +0 -22
  169. package/esm/Options/Classes/Interactivity/Modes/Modes.js +0 -25
  170. package/esm/Options/Classes/ManualParticle.js +0 -21
  171. package/esm/Options/Classes/Responsive.js +0 -29
  172. package/esm/Options/Classes/Theme/Theme.js +0 -21
  173. package/esm/Options/Classes/Theme/ThemeDefault.js +0 -23
  174. package/esm/Options/Interfaces/IManualParticle.js +0 -1
  175. package/esm/Options/Interfaces/IResponsive.js +0 -1
  176. package/esm/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -1
  177. package/esm/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -1
  178. package/esm/Options/Interfaces/Interactivity/Events/IEvents.js +0 -1
  179. package/esm/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -1
  180. package/esm/Options/Interfaces/Interactivity/Events/IParallax.js +0 -1
  181. package/esm/Options/Interfaces/Interactivity/IInteractivity.js +0 -1
  182. package/esm/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -1
  183. package/esm/Options/Interfaces/Interactivity/Modes/IModes.js +0 -1
  184. package/esm/Options/Interfaces/Theme/ITheme.js +0 -1
  185. package/esm/Options/Interfaces/Theme/IThemeDefault.js +0 -1
  186. package/types/Core/Interfaces/IContainerInteractivity.d.ts +0 -6
  187. package/types/Core/Interfaces/IExternalInteractor.d.ts +0 -12
  188. package/types/Core/Interfaces/IInteractor.d.ts +0 -16
  189. package/types/Core/Interfaces/IMouseData.d.ts +0 -9
  190. package/types/Core/Interfaces/IParticlesInteractor.d.ts +0 -7
  191. package/types/Core/Utils/ExternalInteractorBase.d.ts +0 -15
  192. package/types/Core/Utils/InteractionManager.d.ts +0 -17
  193. package/types/Core/Utils/ParticlesInteractorBase.d.ts +0 -15
  194. package/types/Enums/InteractivityDetect.d.ts +0 -5
  195. package/types/Enums/Modes/ResponsiveMode.d.ts +0 -4
  196. package/types/Enums/Modes/ThemeMode.d.ts +0 -5
  197. package/types/Enums/Types/DivType.d.ts +0 -4
  198. package/types/Enums/Types/InteractorType.d.ts +0 -4
  199. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +0 -10
  200. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +0 -13
  201. package/types/Options/Classes/Interactivity/Events/Events.d.ts +0 -16
  202. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +0 -12
  203. package/types/Options/Classes/Interactivity/Events/Parallax.d.ts +0 -10
  204. package/types/Options/Classes/Interactivity/Events/ResizeEvent.d.ts +0 -9
  205. package/types/Options/Classes/Interactivity/Interactivity.d.ts +0 -16
  206. package/types/Options/Classes/Interactivity/Modes/Modes.d.ts +0 -12
  207. package/types/Options/Classes/ManualParticle.d.ts +0 -10
  208. package/types/Options/Classes/Responsive.d.ts +0 -12
  209. package/types/Options/Classes/Theme/Theme.d.ts +0 -12
  210. package/types/Options/Classes/Theme/ThemeDefault.d.ts +0 -11
  211. package/types/Options/Interfaces/IManualParticle.d.ts +0 -7
  212. package/types/Options/Interfaces/IResponsive.d.ts +0 -7
  213. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +0 -5
  214. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +0 -8
  215. package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +0 -11
  216. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +0 -7
  217. package/types/Options/Interfaces/Interactivity/Events/IParallax.d.ts +0 -5
  218. package/types/Options/Interfaces/Interactivity/IInteractivity.d.ts +0 -9
  219. package/types/Options/Interfaces/Interactivity/Modes/IModeDiv.d.ts +0 -4
  220. package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +0 -1
  221. package/types/Options/Interfaces/Theme/ITheme.d.ts +0 -7
  222. package/types/Options/Interfaces/Theme/IThemeDefault.d.ts +0 -6
  223. package/umd/Core/Interfaces/IExternalInteractor.js +0 -12
  224. package/umd/Core/Interfaces/IInteractor.js +0 -12
  225. package/umd/Core/Interfaces/IMouseData.js +0 -12
  226. package/umd/Core/Interfaces/IParticlesInteractor.js +0 -12
  227. package/umd/Core/Utils/ExternalInteractorBase.js +0 -21
  228. package/umd/Core/Utils/InteractionManager.js +0 -74
  229. package/umd/Core/Utils/ParticlesInteractorBase.js +0 -21
  230. package/umd/Enums/InteractivityDetect.js +0 -19
  231. package/umd/Enums/Modes/ResponsiveMode.js +0 -18
  232. package/umd/Enums/Modes/ThemeMode.js +0 -19
  233. package/umd/Enums/Types/DivType.js +0 -18
  234. package/umd/Enums/Types/InteractorType.js +0 -18
  235. package/umd/Options/Classes/Interactivity/Events/ClickEvent.js +0 -32
  236. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +0 -41
  237. package/umd/Options/Classes/Interactivity/Events/Events.js +0 -44
  238. package/umd/Options/Classes/Interactivity/Events/HoverEvent.js +0 -35
  239. package/umd/Options/Classes/Interactivity/Events/Parallax.js +0 -36
  240. package/umd/Options/Classes/Interactivity/Interactivity.js +0 -36
  241. package/umd/Options/Classes/Interactivity/Modes/Modes.js +0 -39
  242. package/umd/Options/Classes/ManualParticle.js +0 -35
  243. package/umd/Options/Classes/Responsive.js +0 -43
  244. package/umd/Options/Classes/Theme/Theme.js +0 -35
  245. package/umd/Options/Classes/Theme/ThemeDefault.js +0 -37
  246. package/umd/Options/Interfaces/IManualParticle.js +0 -12
  247. package/umd/Options/Interfaces/IResponsive.js +0 -12
  248. package/umd/Options/Interfaces/Interactivity/Events/IClickEvent.js +0 -12
  249. package/umd/Options/Interfaces/Interactivity/Events/IDivEvent.js +0 -12
  250. package/umd/Options/Interfaces/Interactivity/Events/IEvents.js +0 -12
  251. package/umd/Options/Interfaces/Interactivity/Events/IHoverEvent.js +0 -12
  252. package/umd/Options/Interfaces/Interactivity/Events/IParallax.js +0 -12
  253. package/umd/Options/Interfaces/Interactivity/IInteractivity.js +0 -12
  254. package/umd/Options/Interfaces/Interactivity/Modes/IModeDiv.js +0 -12
  255. package/umd/Options/Interfaces/Interactivity/Modes/IModes.js +0 -12
  256. package/umd/Options/Interfaces/Theme/ITheme.js +0 -12
  257. package/umd/Options/Interfaces/Theme/IThemeDefault.js +0 -12
  258. /package/browser/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  259. /package/browser/{Core/Interfaces/IContainerInteractivity.js → Types/EngineInitializers.js} +0 -0
  260. /package/cjs/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  261. /package/{browser/Core/Interfaces/IExternalInteractor.js → cjs/Types/EngineInitializers.js} +0 -0
  262. /package/esm/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  263. /package/{browser/Core/Interfaces/IInteractor.js → esm/Types/EngineInitializers.js} +0 -0
  264. /package/types/Options/Interfaces/{Interactivity/Events/IResizeEvent.d.ts → IResizeEvent.d.ts} +0 -0
  265. /package/umd/Options/Interfaces/{Interactivity/Events/IResizeEvent.js → IResizeEvent.js} +0 -0
  266. /package/umd/{Core/Interfaces/IContainerInteractivity.js → Types/EngineInitializers.js} +0 -0
@@ -3,7 +3,6 @@ import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelo
3
3
  import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, half, identity, millisecondsToSeconds, minZ, none, randomColorValue, rollFactor, squareExp, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
4
4
  import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
5
5
  import { EventType } from "../Enums/Types/EventType.js";
6
- import { Interactivity } from "../Options/Classes/Interactivity/Interactivity.js";
7
6
  import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
8
7
  import { OutMode } from "../Enums/Modes/OutMode.js";
9
8
  import { ParticleOutType } from "../Enums/Types/ParticleOutType.js";
@@ -53,7 +52,7 @@ export class Particle {
53
52
  };
54
53
  this._calcPosition = (position, zIndex) => {
55
54
  let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
56
- const container = this.container, plugins = Array.from(container.plugins.values()), outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
55
+ const container = this.container, plugins = Array.from(container.plugins), outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
57
56
  while (!signal.aborted) {
58
57
  for (const plugin of plugins) {
59
58
  const pluginPos = plugin.particlePosition?.(posVec, this);
@@ -173,7 +172,7 @@ export class Particle {
173
172
  this.slow.inRange = false;
174
173
  const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
175
174
  shapeDrawer?.particleDestroy?.(this);
176
- for (const plugin of container.plugins.values()) {
175
+ for (const plugin of container.plugins) {
177
176
  plugin.particleDestroyed?.(this, override);
178
177
  }
179
178
  for (const updater of container.particles.updaters) {
@@ -189,7 +188,7 @@ export class Particle {
189
188
  }
190
189
  draw(delta) {
191
190
  const container = this.container, canvas = container.canvas;
192
- for (const plugin of container.plugins.values()) {
191
+ for (const plugin of container.plugins) {
193
192
  canvas.drawParticlePlugin(plugin, this, delta);
194
193
  }
195
194
  canvas.drawParticle(this, delta);
@@ -240,7 +239,7 @@ export class Particle {
240
239
  return this._cachedTransform;
241
240
  }
242
241
  init(id, position, overrideOptions, group) {
243
- const container = this.container, engine = this._engine;
242
+ const container = this.container;
244
243
  this.id = id;
245
244
  this.group = group;
246
245
  this.effectClose = true;
@@ -300,10 +299,6 @@ export class Particle {
300
299
  if (shapeData) {
301
300
  particlesOptions.load(shapeData.particles);
302
301
  }
303
- const interactivity = new Interactivity(engine, container);
304
- interactivity.load(container.actualOptions.interactivity);
305
- interactivity.load(particlesOptions.interactivity);
306
- this.interactivity = interactivity;
307
302
  this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;
308
303
  this.effectClose = effectData?.close ?? particlesOptions.effect.close;
309
304
  this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
@@ -372,7 +367,7 @@ export class Particle {
372
367
  }
373
368
  effectDrawer?.particleInit?.(container, this);
374
369
  shapeDrawer?.particleInit?.(container, this);
375
- for (const plugin of container.plugins.values()) {
370
+ for (const plugin of container.plugins) {
376
371
  plugin.particleCreated?.(this);
377
372
  }
378
373
  }
@@ -1,13 +1,11 @@
1
1
  import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, posOffset, qTreeCapacity, sizeFactor, squareExp, } from "./Utils/Constants.js";
2
2
  import { EventType } from "../Enums/Types/EventType.js";
3
- import { InteractionManager } from "./Utils/InteractionManager.js";
4
3
  import { LimitMode } from "../Enums/Modes/LimitMode.js";
5
4
  import { Particle } from "./Particle.js";
6
5
  import { Point } from "./Utils/Point.js";
7
6
  import { QuadTree } from "./Utils/QuadTree.js";
8
7
  import { Rectangle } from "./Utils/Ranges.js";
9
8
  import { getLogger } from "../Utils/LogUtils.js";
10
- import { getPosition } from "../Utils/Utils.js";
11
9
  import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
12
10
  const qTreeRectangle = (canvasSize) => {
13
11
  const { height, width } = canvasSize;
@@ -18,7 +16,7 @@ export class Particles {
18
16
  this._addToPool = (...particles) => {
19
17
  this._pool.push(...particles);
20
18
  };
21
- this._applyDensity = (options, manualCount, group, groupOptions) => {
19
+ this._applyDensity = (options, pluginsCount, group, groupOptions) => {
22
20
  const numberOptions = options.number;
23
21
  if (!numberOptions.density.enable) {
24
22
  if (group === undefined) {
@@ -29,7 +27,7 @@ export class Particles {
29
27
  }
30
28
  return;
31
29
  }
32
- const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
30
+ 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);
33
31
  if (group === undefined) {
34
32
  this._limit = numberOptions.limit.value * densityFactor;
35
33
  }
@@ -109,7 +107,6 @@ export class Particles {
109
107
  this._groupLimits = new Map();
110
108
  this._needsSort = false;
111
109
  this._lastZIndex = 0;
112
- this._interactionManager = new InteractionManager(engine, container);
113
110
  this._pluginsInitialized = false;
114
111
  const canvasSize = container.canvas.size;
115
112
  this.quadTree = new QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
@@ -119,10 +116,6 @@ export class Particles {
119
116
  get count() {
120
117
  return this._array.length;
121
118
  }
122
- addManualParticles() {
123
- const container = this._container, options = container.actualOptions;
124
- options.manualParticles.forEach(p => this.addParticle(p.position ? getPosition(p.position, container.canvas.size) : undefined, p.options));
125
- }
126
119
  addParticle(position, overrideOptions, group, initializer) {
127
120
  const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
128
121
  if (limit > minLimit) {
@@ -168,22 +161,23 @@ export class Particles {
168
161
  get(index) {
169
162
  return this._array[index];
170
163
  }
171
- handleClickMode(mode) {
172
- this._interactionManager.handleClickMode(mode);
173
- }
174
164
  async init() {
175
165
  const container = this._container, options = container.actualOptions;
176
166
  this._lastZIndex = 0;
177
167
  this._needsSort = false;
168
+ for (const plugin of container.plugins) {
169
+ if (plugin.redrawInit) {
170
+ await plugin.redrawInit();
171
+ }
172
+ }
178
173
  await this.initPlugins();
179
174
  let handled = false;
180
- for (const plugin of container.plugins.values()) {
175
+ for (const plugin of container.plugins) {
181
176
  handled = plugin.particlesInitialization?.() ?? handled;
182
177
  if (handled) {
183
178
  break;
184
179
  }
185
180
  }
186
- this.addManualParticles();
187
181
  if (!handled) {
188
182
  const particlesOptions = options.particles, groups = particlesOptions.groups;
189
183
  for (const group in groups) {
@@ -207,14 +201,13 @@ export class Particles {
207
201
  const container = this._container;
208
202
  this.movers = await this._engine.getMovers(container, true);
209
203
  this.updaters = await this._engine.getUpdaters(container, true);
210
- await this._interactionManager.init();
211
204
  for (const pathGenerator of container.pathGenerators.values()) {
212
205
  pathGenerator.init(container);
213
206
  }
214
207
  }
215
- push(nb, mouse, overrideOptions, group) {
208
+ push(nb, position, overrideOptions, group) {
216
209
  for (let i = 0; i < nb; i++) {
217
- this.addParticle(mouse?.position, overrideOptions, group);
210
+ this.addParticle(position, overrideOptions, group);
218
211
  }
219
212
  }
220
213
  async redraw() {
@@ -241,16 +234,22 @@ export class Particles {
241
234
  this.removeAt(minIndex, quantity, group);
242
235
  }
243
236
  setDensity() {
244
- const options = this._container.actualOptions, groups = options.particles.groups, manualCount = options.manualParticles.length;
237
+ const options = this._container.actualOptions, groups = options.particles.groups;
238
+ let pluginsCount = 0;
239
+ for (const plugin of this._container.plugins) {
240
+ if (plugin.particlesDensityCount) {
241
+ pluginsCount += plugin.particlesDensityCount();
242
+ }
243
+ }
245
244
  for (const group in groups) {
246
245
  const groupData = groups[group];
247
246
  if (!groupData) {
248
247
  continue;
249
248
  }
250
249
  const groupDataOptions = loadParticlesOptions(this._engine, this._container, groupData);
251
- this._applyDensity(groupDataOptions, manualCount, group);
250
+ this._applyDensity(groupDataOptions, pluginsCount, group);
252
251
  }
253
- this._applyDensity(options.particles, manualCount);
252
+ this._applyDensity(options.particles, pluginsCount);
254
253
  }
255
254
  setLastZIndex(zIndex) {
256
255
  this._lastZIndex = zIndex;
@@ -265,7 +264,7 @@ export class Particles {
265
264
  for (const pathGenerator of container.pathGenerators.values()) {
266
265
  pathGenerator.update();
267
266
  }
268
- for (const plugin of container.plugins.values()) {
267
+ for (const plugin of container.plugins) {
269
268
  plugin.update?.(delta);
270
269
  }
271
270
  const resizeFactor = this._resizeFactor;
@@ -277,8 +276,12 @@ export class Particles {
277
276
  particle.initialPosition.y *= resizeFactor.height;
278
277
  }
279
278
  particle.ignoresResizeRatio = false;
280
- this._interactionManager.reset(particle);
281
- for (const plugin of this._container.plugins.values()) {
279
+ for (const plugin of this._container.plugins) {
280
+ if (plugin.particleReset) {
281
+ plugin.particleReset(particle);
282
+ }
283
+ }
284
+ for (const plugin of this._container.plugins) {
282
285
  if (particle.destroyed) {
283
286
  break;
284
287
  }
@@ -309,13 +312,21 @@ export class Particles {
309
312
  }
310
313
  this._addToPool(...particlesToDelete);
311
314
  }
312
- this._interactionManager.externalInteract(delta);
315
+ for (const plugin of container.plugins) {
316
+ if (plugin.postUpdate) {
317
+ plugin.postUpdate(delta);
318
+ }
319
+ }
313
320
  for (const particle of this._array) {
314
321
  for (const updater of this.updaters) {
315
322
  updater.update(particle, delta);
316
323
  }
317
324
  if (!particle.destroyed && !particle.spawning) {
318
- this._interactionManager.particlesInteract(particle, delta);
325
+ for (const plugin of container.plugins) {
326
+ if (plugin.postParticleUpdate) {
327
+ plugin.postParticleUpdate(particle, delta);
328
+ }
329
+ }
319
330
  }
320
331
  }
321
332
  delete this._resizeFactor;
@@ -1,4 +1,4 @@
1
- export const generatedAttribute = "generated", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseOutEvent = "pointerout", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
1
+ export const generatedAttribute = "generated", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
2
2
  x: 0,
3
3
  y: 0,
4
4
  z: 0,
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", mouseDownEvent = "pointerdown", m
7
7
  b: 0,
8
8
  c: 0,
9
9
  d: 1,
10
- }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, rollFactor = 1, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, manualCount = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0;
10
+ }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, inverseFactorNumerator = 1.0, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, rollFactor = 1, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0;
@@ -1,56 +1,10 @@
1
- import { double, lengthOffset, millisecondsToSeconds, mouseDownEvent, mouseLeaveEvent, mouseMoveEvent, mouseOutEvent, mouseUpEvent, resizeEvent, touchCancelEvent, touchDelay, touchEndEvent, touchMoveEvent, touchStartEvent, visibilityChangeEvent, } from "./Constants.js";
2
- import { executeOnSingleOrMultiple, safeDocument, safeMatchMedia } from "../../Utils/Utils.js";
3
- import { InteractivityDetect } from "../../Enums/InteractivityDetect.js";
4
- import { isBoolean } from "../../Utils/TypeUtils.js";
5
- function manageListener(element, event, handler, add, options) {
6
- if (add) {
7
- let addOptions = { passive: true };
8
- if (isBoolean(options)) {
9
- addOptions.capture = options;
10
- }
11
- else if (options !== undefined) {
12
- addOptions = options;
13
- }
14
- element.addEventListener(event, handler, addOptions);
15
- }
16
- else {
17
- const removeOptions = options;
18
- element.removeEventListener(event, handler, removeOptions);
19
- }
20
- }
1
+ import { manageListener, safeDocument } from "../../Utils/Utils.js";
2
+ import { millisecondsToSeconds, resizeEvent, visibilityChangeEvent } from "./Constants.js";
21
3
  export class EventListeners {
22
4
  constructor(container) {
23
5
  this.container = container;
24
- this._canPush = true;
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 = Date.now();
34
- const onClick = options.interactivity.events.onClick;
35
- executeOnSingleOrMultiple(onClick.mode, mode => {
36
- this.container.handleClickMode(mode);
37
- });
38
- }
39
- if (e.type === "touchend") {
40
- setTimeout(() => {
41
- this._mouseTouchFinish();
42
- }, touchDelay);
43
- }
44
- };
45
- this._handleThemeChange = (e) => {
46
- 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);
47
- if (theme?.default.auto) {
48
- void container.loadTheme(themeName);
49
- }
50
- };
51
6
  this._handleVisibilityChange = () => {
52
7
  const container = this.container, options = container.actualOptions;
53
- this._mouseTouchFinish();
54
8
  if (!options.pauseOnBlur) {
55
9
  return;
56
10
  }
@@ -77,60 +31,16 @@ export class EventListeners {
77
31
  const canvas = this.container.canvas;
78
32
  await canvas.windowResize();
79
33
  };
80
- this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * millisecondsToSeconds);
81
- };
82
- this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
83
- const handlers = this._handlers, container = this.container, options = container.actualOptions, interactivityEl = container.interactivity.element;
84
- if (!interactivityEl) {
85
- return;
86
- }
87
- const html = interactivityEl, canvas = container.canvas;
88
- canvas.setPointerEvents(html === canvas.element ? "initial" : "none");
89
- if (!(options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable)) {
90
- return;
91
- }
92
- manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
93
- manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
94
- manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
95
- if (options.interactivity.events.onClick.enable) {
96
- manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
97
- manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
98
- manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
99
- }
100
- else {
101
- manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
102
- }
103
- manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
104
- manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
34
+ this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.resize.delay * millisecondsToSeconds);
105
35
  };
106
36
  this._manageListeners = add => {
107
- const handlers = this._handlers, container = this.container, options = container.actualOptions, detectType = options.interactivity.detectsOn, canvasEl = container.canvas.element;
108
- let mouseLeaveTmpEvent = mouseLeaveEvent;
109
- if (detectType === InteractivityDetect.window) {
110
- container.interactivity.element = window;
111
- mouseLeaveTmpEvent = mouseOutEvent;
112
- }
113
- else if (detectType === InteractivityDetect.parent && canvasEl) {
114
- container.interactivity.element = canvasEl.parentElement ?? canvasEl.parentNode;
115
- }
116
- else {
117
- container.interactivity.element = canvasEl;
118
- }
119
- this._manageMediaMatch(add);
37
+ const handlers = this._handlers;
120
38
  this._manageResize(add);
121
- this._manageInteractivityListeners(mouseLeaveTmpEvent, add);
122
39
  manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
123
40
  };
124
- this._manageMediaMatch = add => {
125
- const handlers = this._handlers;
126
- if (!this._matchMedia) {
127
- return;
128
- }
129
- manageListener(this._matchMedia, "change", handlers.themeChange, add);
130
- };
131
41
  this._manageResize = add => {
132
42
  const handlers = this._handlers, container = this.container, options = container.actualOptions;
133
- if (!options.interactivity.events.resize.enable) {
43
+ if (!options.resize.enable) {
134
44
  return;
135
45
  }
136
46
  if (typeof ResizeObserver === "undefined") {
@@ -156,165 +66,10 @@ export class EventListeners {
156
66
  this._resizeObserver.observe(canvasEl);
157
67
  }
158
68
  };
159
- this._mouseDown = () => {
160
- const { interactivity } = this.container, { mouse } = interactivity;
161
- mouse.clicking = true;
162
- mouse.downPosition = mouse.position;
163
- };
164
- this._mouseTouchClick = e => {
165
- const container = this.container, options = container.actualOptions, { mouse } = container.interactivity;
166
- mouse.inside = true;
167
- let handled = false;
168
- const mousePosition = mouse.position;
169
- if (!mousePosition || !options.interactivity.events.onClick.enable) {
170
- return;
171
- }
172
- for (const plugin of container.plugins.values()) {
173
- if (!plugin.clickPositionValid) {
174
- continue;
175
- }
176
- handled = plugin.clickPositionValid(mousePosition);
177
- if (handled) {
178
- break;
179
- }
180
- }
181
- if (!handled) {
182
- this._doMouseTouchClick(e);
183
- }
184
- mouse.clicking = false;
185
- };
186
- this._mouseTouchFinish = () => {
187
- const { interactivity } = this.container, { mouse } = interactivity;
188
- delete mouse.position;
189
- delete mouse.clickPosition;
190
- delete mouse.downPosition;
191
- interactivity.status = mouseLeaveEvent;
192
- mouse.inside = false;
193
- mouse.clicking = false;
194
- };
195
- this._mouseTouchMove = e => {
196
- const container = this.container, options = container.actualOptions, interactivity = container.interactivity, canvasEl = container.canvas.element;
197
- if (!interactivity.element) {
198
- return;
199
- }
200
- interactivity.mouse.inside = true;
201
- let pos;
202
- if (e.type.startsWith("pointer")) {
203
- this._canPush = true;
204
- const mouseEvent = e;
205
- if (interactivity.element === window) {
206
- if (canvasEl) {
207
- const clientRect = canvasEl.getBoundingClientRect();
208
- pos = {
209
- x: mouseEvent.clientX - clientRect.left,
210
- y: mouseEvent.clientY - clientRect.top,
211
- };
212
- }
213
- }
214
- else if (options.interactivity.detectsOn === InteractivityDetect.parent) {
215
- const source = mouseEvent.target, target = mouseEvent.currentTarget;
216
- if (canvasEl) {
217
- const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
218
- pos = {
219
- x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
220
- y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
221
- };
222
- }
223
- else {
224
- pos = {
225
- x: mouseEvent.offsetX,
226
- y: mouseEvent.offsetY,
227
- };
228
- }
229
- }
230
- else if (mouseEvent.target === canvasEl) {
231
- pos = {
232
- x: mouseEvent.offsetX,
233
- y: mouseEvent.offsetY,
234
- };
235
- }
236
- }
237
- else {
238
- this._canPush = e.type !== "touchmove";
239
- if (canvasEl) {
240
- const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
241
- if (!lastTouch) {
242
- return;
243
- }
244
- pos = {
245
- x: lastTouch.clientX - canvasRect.left,
246
- y: lastTouch.clientY - canvasRect.top,
247
- };
248
- }
249
- }
250
- const pxRatio = container.retina.pixelRatio;
251
- if (pos) {
252
- pos.x *= pxRatio;
253
- pos.y *= pxRatio;
254
- }
255
- interactivity.mouse.position = pos;
256
- interactivity.status = mouseMoveEvent;
257
- };
258
- this._touchEnd = e => {
259
- const evt = e, touches = Array.from(evt.changedTouches);
260
- for (const touch of touches) {
261
- this._touches.delete(touch.identifier);
262
- }
263
- this._mouseTouchFinish();
264
- };
265
- this._touchEndClick = e => {
266
- const evt = e, touches = Array.from(evt.changedTouches);
267
- for (const touch of touches) {
268
- this._touches.delete(touch.identifier);
269
- }
270
- this._mouseTouchClick(e);
271
- };
272
- this._touchStart = e => {
273
- const evt = e, touches = Array.from(evt.changedTouches);
274
- for (const touch of touches) {
275
- this._touches.set(touch.identifier, performance.now());
276
- }
277
- this._mouseTouchMove(e);
278
- };
279
- this._matchMedia = safeMatchMedia("(prefers-color-scheme: dark)");
280
- this._touches = new Map();
281
69
  this._handlers = {
282
- mouseDown: () => {
283
- this._mouseDown();
284
- },
285
- mouseLeave: () => {
286
- this._mouseTouchFinish();
287
- },
288
- mouseMove: (e) => {
289
- this._mouseTouchMove(e);
290
- },
291
- mouseUp: (e) => {
292
- this._mouseTouchClick(e);
293
- },
294
- touchStart: (e) => {
295
- this._touchStart(e);
296
- },
297
- touchMove: (e) => {
298
- this._mouseTouchMove(e);
299
- },
300
- touchEnd: (e) => {
301
- this._touchEnd(e);
302
- },
303
- touchCancel: (e) => {
304
- this._touchEnd(e);
305
- },
306
- touchEndClick: (e) => {
307
- this._touchEndClick(e);
308
- },
309
70
  visibilityChange: () => {
310
71
  this._handleVisibilityChange();
311
72
  },
312
- themeChange: (e) => {
313
- this._handleThemeChange(e);
314
- },
315
- oldThemeChange: (e) => {
316
- this._handleThemeChange(e);
317
- },
318
73
  resize: () => {
319
74
  this._handleWindowResize();
320
75
  },
@@ -1,21 +1,12 @@
1
- import { deepExtend, executeOnSingleOrMultiple, safeMatchMedia } from "../../Utils/Utils.js";
1
+ import { deepExtend, executeOnSingleOrMultiple } from "../../Utils/Utils.js";
2
2
  import { isBoolean, isNull } from "../../Utils/TypeUtils.js";
3
3
  import { Background } from "./Background/Background.js";
4
4
  import { FullScreen } from "./FullScreen/FullScreen.js";
5
- import { Interactivity } from "./Interactivity/Interactivity.js";
6
- import { ManualParticle } from "./ManualParticle.js";
7
- import { Responsive } from "./Responsive.js";
8
- import { ResponsiveMode } from "../../Enums/Modes/ResponsiveMode.js";
9
- import { Theme } from "./Theme/Theme.js";
10
- import { ThemeMode } from "../../Enums/Modes/ThemeMode.js";
5
+ import { ResizeEvent } from "./ResizeEvent.js";
11
6
  import { loadParticlesOptions } from "../../Utils/OptionsUtils.js";
12
7
  import { setRangeValue } from "../../Utils/MathUtils.js";
13
8
  export class Options {
14
9
  constructor(engine, container) {
15
- this._findDefaultTheme = mode => {
16
- return (this.themes.find(theme => theme.default.value && theme.default.mode === mode) ??
17
- this.themes.find(theme => theme.default.value && theme.default.mode === ThemeMode.any));
18
- };
19
10
  this._importPreset = preset => {
20
11
  this.load(this._engine.getPreset(preset));
21
12
  };
@@ -31,15 +22,12 @@ export class Options {
31
22
  this.duration = 0;
32
23
  this.fpsLimit = 120;
33
24
  this.hdr = true;
34
- this.interactivity = new Interactivity(engine, container);
35
- this.manualParticles = [];
36
25
  this.particles = loadParticlesOptions(this._engine, this._container);
37
26
  this.pauseOnBlur = true;
38
27
  this.pauseOnOutsideViewport = true;
39
- this.responsive = [];
28
+ this.resize = new ResizeEvent();
40
29
  this.smooth = false;
41
30
  this.style = {};
42
- this.themes = [];
43
31
  this.zLayers = 100;
44
32
  }
45
33
  load(data) {
@@ -97,70 +85,14 @@ export class Options {
97
85
  else {
98
86
  this.fullScreen.load(fullScreen);
99
87
  }
100
- this.interactivity.load(data.interactivity);
101
- if (data.manualParticles) {
102
- this.manualParticles = data.manualParticles.map(t => {
103
- const tmp = new ManualParticle();
104
- tmp.load(t);
105
- return tmp;
106
- });
107
- }
108
88
  this.particles.load(data.particles);
89
+ this.resize.load(data.resize);
109
90
  this.style = deepExtend(this.style, data.style);
110
- this._engine.loadOptions(this, data);
111
91
  if (data.smooth !== undefined) {
112
92
  this.smooth = data.smooth;
113
93
  }
114
- const interactors = this._engine.interactors.get(this._container);
115
- if (interactors) {
116
- for (const interactor of interactors) {
117
- if (interactor.loadOptions) {
118
- interactor.loadOptions(this, data);
119
- }
120
- }
121
- }
122
- if (data.responsive !== undefined) {
123
- for (const responsive of data.responsive) {
124
- const optResponsive = new Responsive();
125
- optResponsive.load(responsive);
126
- this.responsive.push(optResponsive);
127
- }
128
- }
129
- this.responsive.sort((a, b) => a.maxWidth - b.maxWidth);
130
- if (data.themes !== undefined) {
131
- for (const theme of data.themes) {
132
- const existingTheme = this.themes.find(t => t.name === theme.name);
133
- if (existingTheme) {
134
- existingTheme.load(theme);
135
- }
136
- else {
137
- const optTheme = new Theme();
138
- optTheme.load(theme);
139
- this.themes.push(optTheme);
140
- }
141
- }
142
- }
143
- this.defaultThemes.dark = this._findDefaultTheme(ThemeMode.dark)?.name;
144
- this.defaultThemes.light = this._findDefaultTheme(ThemeMode.light)?.name;
145
- }
146
- setResponsive(width, pxRatio, defaultOptions) {
147
- this.load(defaultOptions);
148
- const responsiveOptions = this.responsive.find(t => t.mode === ResponsiveMode.screen ? t.maxWidth > screen.availWidth : t.maxWidth * pxRatio > width);
149
- this.load(responsiveOptions?.options);
150
- return responsiveOptions?.maxWidth;
151
- }
152
- setTheme(name) {
153
- if (name) {
154
- const chosenTheme = this.themes.find(theme => theme.name === name);
155
- if (chosenTheme) {
156
- this.load(chosenTheme.options);
157
- }
158
- }
159
- else {
160
- const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)"), clientDarkMode = mediaMatch?.matches, defaultTheme = this._findDefaultTheme(clientDarkMode ? ThemeMode.dark : ThemeMode.light);
161
- if (defaultTheme) {
162
- this.load(defaultTheme.options);
163
- }
164
- }
94
+ this._engine.plugins.forEach(plugin => {
95
+ plugin.loadOptions(this._container, this, data);
96
+ });
165
97
  }
166
98
  }