@tsparticles/engine 3.3.0 → 3.4.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 (265) hide show
  1. package/README.md +0 -4
  2. package/browser/Core/Canvas.js +27 -22
  3. package/browser/Core/Container.js +55 -42
  4. package/browser/Core/Engine.js +82 -74
  5. package/browser/Core/Particle.js +29 -15
  6. package/browser/Core/Particles.js +23 -24
  7. package/browser/Core/Utils/EventListeners.js +18 -17
  8. package/browser/Core/Utils/ExternalInteractorBase.js +2 -1
  9. package/browser/Core/Utils/InteractionManager.js +3 -2
  10. package/browser/Core/Utils/ParticlesInteractorBase.js +2 -1
  11. package/browser/Core/Utils/QuadTree.js +1 -1
  12. package/browser/Core/Utils/Ranges.js +5 -4
  13. package/browser/Enums/AnimationStatus.js +5 -1
  14. package/browser/Enums/Directions/MoveDirection.js +14 -1
  15. package/browser/Enums/Directions/OutModeDirection.js +7 -1
  16. package/browser/Enums/Directions/RotateDirection.js +6 -1
  17. package/browser/Enums/InteractivityDetect.js +6 -1
  18. package/browser/Enums/Modes/AnimationMode.js +7 -1
  19. package/browser/Enums/Modes/CollisionMode.js +6 -1
  20. package/browser/Enums/Modes/LimitMode.js +5 -1
  21. package/browser/Enums/Modes/OutMode.js +8 -1
  22. package/browser/Enums/Modes/PixelMode.js +5 -1
  23. package/browser/Enums/Modes/ResponsiveMode.js +5 -1
  24. package/browser/Enums/Modes/ThemeMode.js +6 -1
  25. package/browser/Enums/Types/AlterType.js +5 -1
  26. package/browser/Enums/Types/DestroyType.js +6 -1
  27. package/browser/Enums/Types/DivType.js +5 -1
  28. package/browser/Enums/Types/EasingType.js +30 -1
  29. package/browser/Enums/Types/EventType.js +15 -1
  30. package/browser/Enums/Types/GradientType.js +6 -1
  31. package/browser/Enums/Types/InteractorType.js +5 -1
  32. package/browser/Enums/Types/ParticleOutType.js +6 -1
  33. package/browser/Enums/Types/StartValueType.js +6 -1
  34. package/browser/Options/Classes/AnimationOptions.js +4 -2
  35. package/browser/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  36. package/browser/Options/Classes/Interactivity/Events/Events.js +1 -1
  37. package/browser/Options/Classes/Interactivity/Interactivity.js +2 -1
  38. package/browser/Options/Classes/ManualParticle.js +2 -1
  39. package/browser/Options/Classes/Options.js +14 -12
  40. package/browser/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  41. package/browser/Options/Classes/Particles/Move/Move.js +2 -1
  42. package/browser/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  43. package/browser/Options/Classes/Particles/Move/OutModes.js +2 -1
  44. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  45. package/browser/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  46. package/browser/Options/Classes/Particles/ParticlesOptions.js +1 -1
  47. package/browser/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  48. package/browser/Options/Classes/Responsive.js +5 -4
  49. package/browser/Options/Classes/Theme/ThemeDefault.js +2 -1
  50. package/browser/Types/RangeType.js +5 -1
  51. package/browser/Utils/CanvasUtils.js +13 -7
  52. package/browser/Utils/ColorUtils.js +17 -9
  53. package/browser/Utils/EventDispatcher.js +1 -1
  54. package/browser/Utils/HslColorManager.js +11 -4
  55. package/browser/Utils/NumberUtils.js +11 -10
  56. package/browser/Utils/RgbColorManager.js +11 -4
  57. package/browser/Utils/Utils.js +37 -31
  58. package/cjs/Core/Canvas.js +27 -22
  59. package/cjs/Core/Container.js +55 -42
  60. package/cjs/Core/Engine.js +82 -74
  61. package/cjs/Core/Particle.js +29 -15
  62. package/cjs/Core/Particles.js +23 -24
  63. package/cjs/Core/Utils/EventListeners.js +18 -17
  64. package/cjs/Core/Utils/ExternalInteractorBase.js +2 -1
  65. package/cjs/Core/Utils/InteractionManager.js +3 -2
  66. package/cjs/Core/Utils/ParticlesInteractorBase.js +2 -1
  67. package/cjs/Core/Utils/QuadTree.js +1 -1
  68. package/cjs/Core/Utils/Ranges.js +5 -4
  69. package/cjs/Enums/AnimationStatus.js +6 -0
  70. package/cjs/Enums/Directions/MoveDirection.js +15 -0
  71. package/cjs/Enums/Directions/OutModeDirection.js +8 -0
  72. package/cjs/Enums/Directions/RotateDirection.js +7 -0
  73. package/cjs/Enums/InteractivityDetect.js +7 -0
  74. package/cjs/Enums/Modes/AnimationMode.js +8 -0
  75. package/cjs/Enums/Modes/CollisionMode.js +7 -0
  76. package/cjs/Enums/Modes/LimitMode.js +6 -0
  77. package/cjs/Enums/Modes/OutMode.js +9 -0
  78. package/cjs/Enums/Modes/PixelMode.js +6 -0
  79. package/cjs/Enums/Modes/ResponsiveMode.js +6 -0
  80. package/cjs/Enums/Modes/ThemeMode.js +7 -0
  81. package/cjs/Enums/Types/AlterType.js +6 -0
  82. package/cjs/Enums/Types/DestroyType.js +7 -0
  83. package/cjs/Enums/Types/DivType.js +6 -0
  84. package/cjs/Enums/Types/EasingType.js +31 -0
  85. package/cjs/Enums/Types/EventType.js +16 -0
  86. package/cjs/Enums/Types/GradientType.js +7 -0
  87. package/cjs/Enums/Types/InteractorType.js +6 -0
  88. package/cjs/Enums/Types/ParticleOutType.js +7 -0
  89. package/cjs/Enums/Types/StartValueType.js +7 -0
  90. package/cjs/Options/Classes/AnimationOptions.js +4 -2
  91. package/cjs/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  92. package/cjs/Options/Classes/Interactivity/Events/Events.js +1 -1
  93. package/cjs/Options/Classes/Interactivity/Interactivity.js +2 -1
  94. package/cjs/Options/Classes/ManualParticle.js +2 -1
  95. package/cjs/Options/Classes/Options.js +14 -12
  96. package/cjs/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  97. package/cjs/Options/Classes/Particles/Move/Move.js +2 -1
  98. package/cjs/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  99. package/cjs/Options/Classes/Particles/Move/OutModes.js +2 -1
  100. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  101. package/cjs/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  102. package/cjs/Options/Classes/Particles/ParticlesOptions.js +1 -1
  103. package/cjs/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  104. package/cjs/Options/Classes/Responsive.js +5 -4
  105. package/cjs/Options/Classes/Theme/ThemeDefault.js +2 -1
  106. package/cjs/Types/RangeType.js +6 -0
  107. package/cjs/Utils/CanvasUtils.js +13 -7
  108. package/cjs/Utils/ColorUtils.js +17 -9
  109. package/cjs/Utils/EventDispatcher.js +1 -1
  110. package/cjs/Utils/HslColorManager.js +11 -4
  111. package/cjs/Utils/NumberUtils.js +11 -10
  112. package/cjs/Utils/RgbColorManager.js +11 -4
  113. package/cjs/Utils/Utils.js +37 -31
  114. package/esm/Core/Canvas.js +27 -22
  115. package/esm/Core/Container.js +55 -42
  116. package/esm/Core/Engine.js +82 -74
  117. package/esm/Core/Particle.js +29 -15
  118. package/esm/Core/Particles.js +23 -24
  119. package/esm/Core/Utils/EventListeners.js +18 -17
  120. package/esm/Core/Utils/ExternalInteractorBase.js +2 -1
  121. package/esm/Core/Utils/InteractionManager.js +3 -2
  122. package/esm/Core/Utils/ParticlesInteractorBase.js +2 -1
  123. package/esm/Core/Utils/QuadTree.js +1 -1
  124. package/esm/Core/Utils/Ranges.js +5 -4
  125. package/esm/Enums/AnimationStatus.js +5 -1
  126. package/esm/Enums/Directions/MoveDirection.js +14 -1
  127. package/esm/Enums/Directions/OutModeDirection.js +7 -1
  128. package/esm/Enums/Directions/RotateDirection.js +6 -1
  129. package/esm/Enums/InteractivityDetect.js +6 -1
  130. package/esm/Enums/Modes/AnimationMode.js +7 -1
  131. package/esm/Enums/Modes/CollisionMode.js +6 -1
  132. package/esm/Enums/Modes/LimitMode.js +5 -1
  133. package/esm/Enums/Modes/OutMode.js +8 -1
  134. package/esm/Enums/Modes/PixelMode.js +5 -1
  135. package/esm/Enums/Modes/ResponsiveMode.js +5 -1
  136. package/esm/Enums/Modes/ThemeMode.js +6 -1
  137. package/esm/Enums/Types/AlterType.js +5 -1
  138. package/esm/Enums/Types/DestroyType.js +6 -1
  139. package/esm/Enums/Types/DivType.js +5 -1
  140. package/esm/Enums/Types/EasingType.js +30 -1
  141. package/esm/Enums/Types/EventType.js +15 -1
  142. package/esm/Enums/Types/GradientType.js +6 -1
  143. package/esm/Enums/Types/InteractorType.js +5 -1
  144. package/esm/Enums/Types/ParticleOutType.js +6 -1
  145. package/esm/Enums/Types/StartValueType.js +6 -1
  146. package/esm/Options/Classes/AnimationOptions.js +4 -2
  147. package/esm/Options/Classes/Interactivity/Events/DivEvent.js +2 -1
  148. package/esm/Options/Classes/Interactivity/Events/Events.js +1 -1
  149. package/esm/Options/Classes/Interactivity/Interactivity.js +2 -1
  150. package/esm/Options/Classes/ManualParticle.js +2 -1
  151. package/esm/Options/Classes/Options.js +14 -12
  152. package/esm/Options/Classes/Particles/Collisions/Collisions.js +2 -1
  153. package/esm/Options/Classes/Particles/Move/Move.js +2 -1
  154. package/esm/Options/Classes/Particles/Move/MoveCenter.js +2 -1
  155. package/esm/Options/Classes/Particles/Move/OutModes.js +2 -1
  156. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +2 -1
  157. package/esm/Options/Classes/Particles/Opacity/OpacityAnimation.js +2 -1
  158. package/esm/Options/Classes/Particles/ParticlesOptions.js +1 -1
  159. package/esm/Options/Classes/Particles/Size/SizeAnimation.js +2 -1
  160. package/esm/Options/Classes/Responsive.js +5 -4
  161. package/esm/Options/Classes/Theme/ThemeDefault.js +2 -1
  162. package/esm/Types/RangeType.js +5 -1
  163. package/esm/Utils/CanvasUtils.js +13 -7
  164. package/esm/Utils/ColorUtils.js +17 -9
  165. package/esm/Utils/EventDispatcher.js +1 -1
  166. package/esm/Utils/HslColorManager.js +11 -4
  167. package/esm/Utils/NumberUtils.js +11 -10
  168. package/esm/Utils/RgbColorManager.js +11 -4
  169. package/esm/Utils/Utils.js +37 -31
  170. package/package.json +1 -1
  171. package/report.html +1 -1
  172. package/tsparticles.engine.js +327 -225
  173. package/tsparticles.engine.min.js +1 -1
  174. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  175. package/types/Core/Container.d.ts +4 -2
  176. package/types/Core/Engine.d.ts +6 -5
  177. package/types/Core/Interfaces/IPlugin.d.ts +3 -4
  178. package/types/Core/Interfaces/IShapeDrawer.d.ts +1 -0
  179. package/types/Core/Particle.d.ts +1 -0
  180. package/types/Enums/AnimationStatus.d.ts +1 -1
  181. package/types/Enums/Directions/MoveDirection.d.ts +1 -1
  182. package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
  183. package/types/Enums/Directions/RotateDirection.d.ts +1 -1
  184. package/types/Enums/InteractivityDetect.d.ts +1 -1
  185. package/types/Enums/Modes/AnimationMode.d.ts +1 -1
  186. package/types/Enums/Modes/CollisionMode.d.ts +1 -1
  187. package/types/Enums/Modes/LimitMode.d.ts +1 -1
  188. package/types/Enums/Modes/OutMode.d.ts +1 -1
  189. package/types/Enums/Modes/PixelMode.d.ts +1 -1
  190. package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
  191. package/types/Enums/Modes/ThemeMode.d.ts +1 -1
  192. package/types/Enums/Types/AlterType.d.ts +1 -1
  193. package/types/Enums/Types/DestroyType.d.ts +1 -1
  194. package/types/Enums/Types/DivType.d.ts +1 -1
  195. package/types/Enums/Types/EasingType.d.ts +1 -1
  196. package/types/Enums/Types/EventType.d.ts +1 -1
  197. package/types/Enums/Types/GradientType.d.ts +1 -1
  198. package/types/Enums/Types/InteractorType.d.ts +1 -1
  199. package/types/Enums/Types/ParticleOutType.d.ts +1 -1
  200. package/types/Enums/Types/StartValueType.d.ts +1 -1
  201. package/types/Options/Classes/Options.d.ts +2 -1
  202. package/types/Options/Classes/Responsive.d.ts +2 -2
  203. package/types/Options/Classes/Theme/Theme.d.ts +2 -2
  204. package/types/Options/Interfaces/IResponsive.d.ts +2 -3
  205. package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
  206. package/types/Types/RangeType.d.ts +1 -1
  207. package/umd/Core/Canvas.js +27 -22
  208. package/umd/Core/Container.js +56 -43
  209. package/umd/Core/Engine.js +83 -99
  210. package/umd/Core/Particle.js +30 -16
  211. package/umd/Core/Particles.js +24 -25
  212. package/umd/Core/Utils/EventListeners.js +19 -18
  213. package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
  214. package/umd/Core/Utils/InteractionManager.js +4 -3
  215. package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
  216. package/umd/Core/Utils/QuadTree.js +1 -1
  217. package/umd/Core/Utils/Ranges.js +6 -5
  218. package/umd/Enums/AnimationStatus.js +6 -0
  219. package/umd/Enums/Directions/MoveDirection.js +15 -0
  220. package/umd/Enums/Directions/OutModeDirection.js +8 -0
  221. package/umd/Enums/Directions/RotateDirection.js +7 -0
  222. package/umd/Enums/InteractivityDetect.js +7 -0
  223. package/umd/Enums/Modes/AnimationMode.js +8 -0
  224. package/umd/Enums/Modes/CollisionMode.js +7 -0
  225. package/umd/Enums/Modes/LimitMode.js +6 -0
  226. package/umd/Enums/Modes/OutMode.js +9 -0
  227. package/umd/Enums/Modes/PixelMode.js +6 -0
  228. package/umd/Enums/Modes/ResponsiveMode.js +6 -0
  229. package/umd/Enums/Modes/ThemeMode.js +7 -0
  230. package/umd/Enums/Types/AlterType.js +6 -0
  231. package/umd/Enums/Types/DestroyType.js +7 -0
  232. package/umd/Enums/Types/DivType.js +6 -0
  233. package/umd/Enums/Types/EasingType.js +31 -0
  234. package/umd/Enums/Types/EventType.js +16 -0
  235. package/umd/Enums/Types/GradientType.js +7 -0
  236. package/umd/Enums/Types/InteractorType.js +6 -0
  237. package/umd/Enums/Types/ParticleOutType.js +7 -0
  238. package/umd/Enums/Types/StartValueType.js +7 -0
  239. package/umd/Options/Classes/AnimationOptions.js +5 -3
  240. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
  241. package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
  242. package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
  243. package/umd/Options/Classes/ManualParticle.js +3 -2
  244. package/umd/Options/Classes/Options.js +15 -13
  245. package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
  246. package/umd/Options/Classes/Particles/Move/Move.js +3 -2
  247. package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
  248. package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
  249. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
  250. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
  251. package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
  252. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
  253. package/umd/Options/Classes/Responsive.js +6 -5
  254. package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
  255. package/umd/Types/RangeType.js +6 -0
  256. package/umd/Utils/CanvasUtils.js +14 -8
  257. package/umd/Utils/ColorUtils.js +18 -10
  258. package/umd/Utils/EventDispatcher.js +1 -1
  259. package/umd/Utils/HslColorManager.js +11 -4
  260. package/umd/Utils/NumberUtils.js +12 -11
  261. package/umd/Utils/RgbColorManager.js +11 -4
  262. package/umd/Utils/Utils.js +38 -32
  263. package/174.min.js +0 -2
  264. package/174.min.js.LICENSE.txt +0 -1
  265. package/dist_browser_Core_Container_js.js +0 -102
@@ -1,6 +1,12 @@
1
1
  import { clamp, collisionVelocity, getDistances, getRandom, getRangeMax, getRangeMin, getRangeValue, randomInRange, } from "./NumberUtils.js";
2
2
  import { halfRandom, millisecondsToSeconds, percentDenominator } from "../Core/Utils/Constants.js";
3
3
  import { isArray, isObject } from "./TypeUtils.js";
4
+ import { AnimationMode } from "../Enums/Modes/AnimationMode.js";
5
+ import { AnimationStatus } from "../Enums/AnimationStatus.js";
6
+ import { DestroyType } from "../Enums/Types/DestroyType.js";
7
+ import { OutModeDirection } from "../Enums/Directions/OutModeDirection.js";
8
+ import { PixelMode } from "../Enums/Modes/PixelMode.js";
9
+ import { StartValueType } from "../Enums/Types/StartValueType.js";
4
10
  import { Vector } from "../Core/Utils/Vectors.js";
5
11
  const _logger = {
6
12
  debug: console.debug,
@@ -37,10 +43,10 @@ function rectSideBounce(data) {
37
43
  return res;
38
44
  }
39
45
  function checkSelector(element, selectors) {
40
- const res = executeOnSingleOrMultiple(selectors, (selector) => {
46
+ const res = executeOnSingleOrMultiple(selectors, selector => {
41
47
  return element.matches(selector);
42
48
  });
43
- return isArray(res) ? res.some((t) => t) : res;
49
+ return isArray(res) ? res.some(t => t) : res;
44
50
  }
45
51
  export function isSsr() {
46
52
  return typeof window === "undefined" || !window || typeof window.document === "undefined" || !window.document;
@@ -89,16 +95,16 @@ export function isPointInside(point, size, offset, radius, direction) {
89
95
  }
90
96
  export function areBoundsInside(bounds, size, offset, direction) {
91
97
  let inside = true;
92
- if (!direction || direction === "bottom") {
98
+ if (!direction || direction === OutModeDirection.bottom) {
93
99
  inside = bounds.top < size.height + offset.x;
94
100
  }
95
- if (inside && (!direction || direction === "left")) {
101
+ if (inside && (!direction || direction === OutModeDirection.left)) {
96
102
  inside = bounds.right > offset.x;
97
103
  }
98
- if (inside && (!direction || direction === "right")) {
104
+ if (inside && (!direction || direction === OutModeDirection.right)) {
99
105
  inside = bounds.left < size.width + offset.y;
100
106
  }
101
- if (inside && (!direction || direction === "top")) {
107
+ if (inside && (!direction || direction === OutModeDirection.top)) {
102
108
  inside = bounds.bottom > offset.y;
103
109
  }
104
110
  return inside;
@@ -134,17 +140,17 @@ export function deepExtend(destination, ...sources) {
134
140
  const sourceDict = source, value = sourceDict[key], destDict = destination;
135
141
  destDict[key] =
136
142
  isObject(value) && Array.isArray(value)
137
- ? value.map((v) => deepExtend(destDict[key], v))
143
+ ? value.map(v => deepExtend(destDict[key], v))
138
144
  : deepExtend(destDict[key], value);
139
145
  }
140
146
  }
141
147
  return destination;
142
148
  }
143
149
  export function isDivModeEnabled(mode, divs) {
144
- return !!findItemFromSingleOrMultiple(divs, (t) => t.enable && isInArray(mode, t.mode));
150
+ return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
145
151
  }
146
152
  export function divModeExecute(mode, divs, callback) {
147
- executeOnSingleOrMultiple(divs, (div) => {
153
+ executeOnSingleOrMultiple(divs, div => {
148
154
  const divMode = div.mode, divEnabled = div.enable;
149
155
  if (divEnabled && isInArray(mode, divMode)) {
150
156
  singleDivModeExecute(div, callback);
@@ -153,7 +159,7 @@ export function divModeExecute(mode, divs, callback) {
153
159
  }
154
160
  export function singleDivModeExecute(div, callback) {
155
161
  const selectors = div.selectors;
156
- executeOnSingleOrMultiple(selectors, (selector) => {
162
+ executeOnSingleOrMultiple(selectors, selector => {
157
163
  callback(selector, div);
158
164
  });
159
165
  }
@@ -161,7 +167,7 @@ export function divMode(divs, element) {
161
167
  if (!element || !divs) {
162
168
  return;
163
169
  }
164
- return findItemFromSingleOrMultiple(divs, (div) => {
170
+ return findItemFromSingleOrMultiple(divs, div => {
165
171
  return checkSelector(element, div.selectors);
166
172
  });
167
173
  }
@@ -271,35 +277,35 @@ export function initParticleNumericAnimationValue(options, pxRatio) {
271
277
  if (animationOptions.enable) {
272
278
  res.decay = decayOffset - getRangeValue(animationOptions.decay);
273
279
  switch (animationOptions.mode) {
274
- case "increase":
275
- res.status = "increasing";
280
+ case AnimationMode.increase:
281
+ res.status = AnimationStatus.increasing;
276
282
  break;
277
- case "decrease":
278
- res.status = "decreasing";
283
+ case AnimationMode.decrease:
284
+ res.status = AnimationStatus.decreasing;
279
285
  break;
280
- case "random":
281
- res.status = getRandom() >= halfRandom ? "increasing" : "decreasing";
286
+ case AnimationMode.random:
287
+ res.status = getRandom() >= halfRandom ? AnimationStatus.increasing : AnimationStatus.decreasing;
282
288
  break;
283
289
  }
284
- const autoStatus = animationOptions.mode === "auto";
290
+ const autoStatus = animationOptions.mode === AnimationMode.auto;
285
291
  switch (animationOptions.startValue) {
286
- case "min":
292
+ case StartValueType.min:
287
293
  res.value = res.min;
288
294
  if (autoStatus) {
289
- res.status = "increasing";
295
+ res.status = AnimationStatus.increasing;
290
296
  }
291
297
  break;
292
- case "max":
298
+ case StartValueType.max:
293
299
  res.value = res.max;
294
300
  if (autoStatus) {
295
- res.status = "decreasing";
301
+ res.status = AnimationStatus.decreasing;
296
302
  }
297
303
  break;
298
- case "random":
304
+ case StartValueType.random:
299
305
  default:
300
306
  res.value = randomInRange(res);
301
307
  if (autoStatus) {
302
- res.status = getRandom() >= halfRandom ? "increasing" : "decreasing";
308
+ res.status = getRandom() >= halfRandom ? AnimationStatus.increasing : AnimationStatus.decreasing;
303
309
  }
304
310
  break;
305
311
  }
@@ -308,7 +314,7 @@ export function initParticleNumericAnimationValue(options, pxRatio) {
308
314
  return res;
309
315
  }
310
316
  function getPositionOrSize(positionOrSize, canvasSize) {
311
- const isPercent = positionOrSize.mode === "percent";
317
+ const isPercent = positionOrSize.mode === PixelMode.percent;
312
318
  if (!isPercent) {
313
319
  const { mode: _, ...rest } = positionOrSize;
314
320
  return rest;
@@ -335,12 +341,12 @@ export function getSize(size, canvasSize) {
335
341
  }
336
342
  function checkDestroy(particle, destroyType, value, minValue, maxValue) {
337
343
  switch (destroyType) {
338
- case "max":
344
+ case DestroyType.max:
339
345
  if (value >= maxValue) {
340
346
  particle.destroy();
341
347
  }
342
348
  break;
343
- case "min":
349
+ case DestroyType.min:
344
350
  if (value <= minValue) {
345
351
  particle.destroy();
346
352
  }
@@ -366,10 +372,10 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
366
372
  return;
367
373
  }
368
374
  switch (data.status) {
369
- case "increasing":
375
+ case AnimationStatus.increasing:
370
376
  if (data.value >= maxValue) {
371
377
  if (changeDirection) {
372
- data.status = "decreasing";
378
+ data.status = AnimationStatus.decreasing;
373
379
  }
374
380
  else {
375
381
  data.value -= maxValue;
@@ -383,10 +389,10 @@ export function updateAnimation(particle, data, changeDirection, destroyType, de
383
389
  data.value += velocity;
384
390
  }
385
391
  break;
386
- case "decreasing":
392
+ case AnimationStatus.decreasing:
387
393
  if (data.value <= minValue) {
388
394
  if (changeDirection) {
389
- data.status = "increasing";
395
+ data.status = AnimationStatus.increasing;
390
396
  }
391
397
  else {
392
398
  data.value += maxValue;
@@ -34,7 +34,7 @@ function setStyle(canvas, style, important = false) {
34
34
  class Canvas {
35
35
  constructor(container) {
36
36
  this.container = container;
37
- this._applyPostDrawUpdaters = (particle) => {
37
+ this._applyPostDrawUpdaters = particle => {
38
38
  for (const updater of this._postDrawUpdaters) {
39
39
  updater.afterDraw?.(particle);
40
40
  }
@@ -64,7 +64,7 @@ class Canvas {
64
64
  plugin.resize?.();
65
65
  }
66
66
  };
67
- this._getPluginParticleColors = (particle) => {
67
+ this._getPluginParticleColors = particle => {
68
68
  let fColor, sColor;
69
69
  for (const plugin of this._colorPlugins) {
70
70
  if (!fColor && plugin.particleFillColor) {
@@ -104,7 +104,7 @@ class Canvas {
104
104
  };
105
105
  resolve();
106
106
  });
107
- img.addEventListener("error", (evt) => {
107
+ img.addEventListener("error", evt => {
108
108
  reject(evt.error);
109
109
  });
110
110
  img.src = cover.image;
@@ -165,28 +165,33 @@ class Canvas {
165
165
  };
166
166
  resolve();
167
167
  });
168
- img.addEventListener("error", (evt) => {
168
+ img.addEventListener("error", evt => {
169
169
  reject(evt.error);
170
170
  });
171
171
  img.src = trailFill.image;
172
172
  });
173
173
  }
174
174
  };
175
- this._paintBase = (baseColor) => {
176
- this.draw((ctx) => (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor));
175
+ this._paintBase = baseColor => {
176
+ this.draw(ctx => (0, CanvasUtils_js_1.paintBase)(ctx, this.size, baseColor));
177
177
  };
178
178
  this._paintImage = (image, opacity) => {
179
- this.draw((ctx) => (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity));
179
+ this.draw(ctx => (0, CanvasUtils_js_1.paintImage)(ctx, this.size, image, opacity));
180
180
  };
181
181
  this._repairStyle = () => {
182
182
  const element = this.element;
183
183
  if (!element) {
184
184
  return;
185
185
  }
186
- this._safeMutationObserver((observer) => observer.disconnect());
186
+ this._safeMutationObserver(observer => observer.disconnect());
187
187
  this._initStyle();
188
188
  this.initBackground();
189
- this._safeMutationObserver((observer) => observer.observe(element, { attributes: true }));
189
+ this._safeMutationObserver(observer => {
190
+ if (!element || !(element instanceof Node)) {
191
+ return;
192
+ }
193
+ observer.observe(element, { attributes: true });
194
+ });
190
195
  };
191
196
  this._resetOriginalStyle = () => {
192
197
  const element = this.element, originalStyle = this._originalStyle;
@@ -195,7 +200,7 @@ class Canvas {
195
200
  }
196
201
  setStyle(element, originalStyle);
197
202
  };
198
- this._safeMutationObserver = (callback) => {
203
+ this._safeMutationObserver = callback => {
199
204
  if (!this._mutationObserver) {
200
205
  return;
201
206
  }
@@ -244,7 +249,7 @@ class Canvas {
244
249
  }
245
250
  }
246
251
  else if (options.clear) {
247
- this.draw((ctx) => {
252
+ this.draw(ctx => {
248
253
  (0, CanvasUtils_js_1.clear)(ctx, this.size);
249
254
  });
250
255
  }
@@ -319,14 +324,14 @@ class Canvas {
319
324
  });
320
325
  }
321
326
  drawParticlePlugin(plugin, particle, delta) {
322
- this.draw((ctx) => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
327
+ this.draw(ctx => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
323
328
  }
324
329
  drawPlugin(plugin, delta) {
325
- this.draw((ctx) => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
330
+ this.draw(ctx => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
326
331
  }
327
332
  async init() {
328
- this._safeMutationObserver((obs) => obs.disconnect());
329
- this._mutationObserver = (0, Utils_js_1.safeMutationObserver)((records) => {
333
+ this._safeMutationObserver(obs => obs.disconnect());
334
+ this._mutationObserver = (0, Utils_js_1.safeMutationObserver)(records => {
330
335
  for (const record of records) {
331
336
  if (record.type === "attributes" && record.attributeName === "style") {
332
337
  this._repairStyle();
@@ -343,8 +348,8 @@ class Canvas {
343
348
  (0, Utils_js_1.getLogger)().error(e);
344
349
  }
345
350
  this.initBackground();
346
- this._safeMutationObserver((obs) => {
347
- if (!this.element) {
351
+ this._safeMutationObserver(obs => {
352
+ if (!this.element || !(this.element instanceof Node)) {
348
353
  return;
349
354
  }
350
355
  obs.observe(this.element, { attributes: true });
@@ -411,8 +416,8 @@ class Canvas {
411
416
  this.size.height = canvas.offsetHeight;
412
417
  this.size.width = canvas.offsetWidth;
413
418
  this._context = this.element.getContext("2d");
414
- this._safeMutationObserver((obs) => {
415
- if (!this.element) {
419
+ this._safeMutationObserver(obs => {
420
+ if (!this.element || !(this.element instanceof Node)) {
416
421
  return;
417
422
  }
418
423
  obs.observe(this.element, { attributes: true });
@@ -422,7 +427,7 @@ class Canvas {
422
427
  }
423
428
  paint() {
424
429
  const options = this.container.actualOptions;
425
- this.draw((ctx) => {
430
+ this.draw(ctx => {
426
431
  if (options.backgroundMask.enable && options.backgroundMask.cover) {
427
432
  (0, CanvasUtils_js_1.clear)(ctx, this.size);
428
433
  if (this._coverImage) {
@@ -466,9 +471,9 @@ class Canvas {
466
471
  return true;
467
472
  }
468
473
  stop() {
469
- this._safeMutationObserver((obs) => obs.disconnect());
474
+ this._safeMutationObserver(obs => obs.disconnect());
470
475
  this._mutationObserver = undefined;
471
- this.draw((ctx) => (0, CanvasUtils_js_1.clear)(ctx, this.size));
476
+ this.draw(ctx => (0, CanvasUtils_js_1.clear)(ctx, this.size));
472
477
  }
473
478
  async windowResize() {
474
479
  if (!this.element || !this.resize()) {
@@ -5,6 +5,7 @@ const Constants_js_1 = require("./Utils/Constants.js");
5
5
  const Utils_js_1 = require("../Utils/Utils.js");
6
6
  const Canvas_js_1 = require("./Canvas.js");
7
7
  const EventListeners_js_1 = require("./Utils/EventListeners.js");
8
+ const EventType_js_1 = require("../Enums/Types/EventType.js");
8
9
  const Options_js_1 = require("../Options/Classes/Options.js");
9
10
  const Particles_js_1 = require("./Particles.js");
10
11
  const Retina_js_1 = require("./Retina.js");
@@ -27,7 +28,7 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
27
28
  }
28
29
  class Container {
29
30
  constructor(engine, id, sourceOptions) {
30
- this._intersectionManager = (entries) => {
31
+ this._intersectionManager = entries => {
31
32
  if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
32
33
  return;
33
34
  }
@@ -86,6 +87,7 @@ class Container {
86
87
  this._lastFrameTime = 0;
87
88
  this.zLayers = 100;
88
89
  this.pageHidden = false;
90
+ this._clickHandlers = new Map();
89
91
  this._sourceOptions = sourceOptions;
90
92
  this._initialSourceOptions = sourceOptions;
91
93
  this.retina = new Retina_js_1.Retina(this);
@@ -104,8 +106,8 @@ class Container {
104
106
  this._options = loadContainerOptions(this._engine, this);
105
107
  this.actualOptions = loadContainerOptions(this._engine, this);
106
108
  this._eventListeners = new EventListeners_js_1.EventListeners(this);
107
- this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)((entries) => this._intersectionManager(entries));
108
- this._engine.dispatchEvent("containerBuilt", { container: this });
109
+ this._intersectionObserver = (0, Utils_js_1.safeIntersectionObserver)(entries => this._intersectionManager(entries));
110
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerBuilt, { container: this });
109
111
  }
110
112
  get animationStatus() {
111
113
  return !this._paused && !this.pageHidden && guardCheck(this);
@@ -133,8 +135,7 @@ class Container {
133
135
  y: pos.y * pxRatio,
134
136
  }, particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
135
137
  callback(e, particles);
136
- };
137
- const clickHandler = (e) => {
138
+ }, clickHandler = (e) => {
138
139
  if (!guardCheck(this)) {
139
140
  return;
140
141
  }
@@ -143,27 +144,23 @@ class Container {
143
144
  y: mouseEvent.offsetY || mouseEvent.clientY,
144
145
  }, radius = 1;
145
146
  clickOrTouchHandler(e, pos, radius);
146
- };
147
- const touchStartHandler = () => {
147
+ }, touchStartHandler = () => {
148
148
  if (!guardCheck(this)) {
149
149
  return;
150
150
  }
151
151
  touched = true;
152
152
  touchMoved = false;
153
- };
154
- const touchMoveHandler = () => {
153
+ }, touchMoveHandler = () => {
155
154
  if (!guardCheck(this)) {
156
155
  return;
157
156
  }
158
157
  touchMoved = true;
159
- };
160
- const touchEndHandler = (e) => {
158
+ }, touchEndHandler = (e) => {
161
159
  if (!guardCheck(this)) {
162
160
  return;
163
161
  }
164
162
  if (touched && !touchMoved) {
165
- const touchEvent = e;
166
- const lengthOffset = 1;
163
+ const touchEvent = e, lengthOffset = 1;
167
164
  let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
168
165
  if (!lastTouch) {
169
166
  lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
@@ -179,8 +176,7 @@ class Container {
179
176
  }
180
177
  touched = false;
181
178
  touchMoved = false;
182
- };
183
- const touchCancelHandler = () => {
179
+ }, touchCancelHandler = () => {
184
180
  if (!guardCheck(this)) {
185
181
  return;
186
182
  }
@@ -188,11 +184,14 @@ class Container {
188
184
  touchMoved = false;
189
185
  };
190
186
  let touched = false, touchMoved = false;
191
- el.addEventListener("click", clickHandler);
192
- el.addEventListener("touchstart", touchStartHandler);
193
- el.addEventListener("touchmove", touchMoveHandler);
194
- el.addEventListener("touchend", touchEndHandler);
195
- el.addEventListener("touchcancel", touchCancelHandler);
187
+ this._clickHandlers.set("click", clickHandler);
188
+ this._clickHandlers.set("touchstart", touchStartHandler);
189
+ this._clickHandlers.set("touchmove", touchMoveHandler);
190
+ this._clickHandlers.set("touchend", touchEndHandler);
191
+ this._clickHandlers.set("touchcancel", touchCancelHandler);
192
+ for (const [key, handler] of this._clickHandlers) {
193
+ el.addEventListener(key, handler);
194
+ }
196
195
  }
197
196
  addLifeTime(value) {
198
197
  this._lifeTime += value;
@@ -207,11 +206,21 @@ class Container {
207
206
  alive() {
208
207
  return !this._duration || this._lifeTime <= this._duration;
209
208
  }
210
- destroy() {
209
+ clearClickHandlers() {
210
+ if (!guardCheck(this)) {
211
+ return;
212
+ }
213
+ for (const [key, handler] of this._clickHandlers) {
214
+ this.interactivity.element?.removeEventListener(key, handler);
215
+ }
216
+ this._clickHandlers.clear();
217
+ }
218
+ destroy(remove = true) {
211
219
  if (!guardCheck(this)) {
212
220
  return;
213
221
  }
214
222
  this.stop();
223
+ this.clearClickHandlers();
215
224
  this.particles.destroy();
216
225
  this.canvas.destroy();
217
226
  for (const [, effectDrawer] of this.effectDrawers) {
@@ -228,12 +237,14 @@ class Container {
228
237
  }
229
238
  this._engine.clearPlugins(this);
230
239
  this.destroyed = true;
231
- const mainArr = this._engine.dom(), idx = mainArr.findIndex((t) => t === this), minIndex = 0;
232
- if (idx >= minIndex) {
233
- const deleteCount = 1;
234
- mainArr.splice(idx, deleteCount);
240
+ if (remove) {
241
+ const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
242
+ if (idx >= minIndex) {
243
+ const deleteCount = 1;
244
+ mainArr.splice(idx, deleteCount);
245
+ }
235
246
  }
236
- this._engine.dispatchEvent("containerDestroyed", { container: this });
247
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
237
248
  }
238
249
  draw(force) {
239
250
  if (!guardCheck(this)) {
@@ -247,7 +258,7 @@ class Container {
247
258
  }
248
259
  this._nextFrame(timestamp);
249
260
  };
250
- this._drawAnimationFrame = requestAnimationFrame((timestamp) => frame(timestamp));
261
+ this._drawAnimationFrame = requestAnimationFrame(timestamp => frame(timestamp));
251
262
  }
252
263
  async export(type, options = {}) {
253
264
  for (const [, plugin] of this.plugins) {
@@ -301,13 +312,14 @@ class Container {
301
312
  this.updateActualOptions();
302
313
  this.canvas.initBackground();
303
314
  this.canvas.resize();
304
- this.zLayers = this.actualOptions.zLayers;
305
- this._duration = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.duration) * Constants_js_1.millisecondsToSeconds;
306
- this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) * Constants_js_1.millisecondsToSeconds;
315
+ const { zLayers, duration, delay, fpsLimit, smooth } = this.actualOptions;
316
+ this.zLayers = zLayers;
317
+ this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
318
+ this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
307
319
  this._lifeTime = 0;
308
320
  const defaultFpsLimit = 120, minFpsLimit = 0;
309
- this.fpsLimit = this.actualOptions.fpsLimit > minFpsLimit ? this.actualOptions.fpsLimit : defaultFpsLimit;
310
- this._smooth = this.actualOptions.smooth;
321
+ this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
322
+ this._smooth = smooth;
311
323
  for (const [, drawer] of this.effectDrawers) {
312
324
  await drawer.init?.(this);
313
325
  }
@@ -317,13 +329,13 @@ class Container {
317
329
  for (const [, plugin] of this.plugins) {
318
330
  await plugin.init?.();
319
331
  }
320
- this._engine.dispatchEvent("containerInit", { container: this });
332
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerInit, { container: this });
321
333
  await this.particles.init();
322
334
  this.particles.setDensity();
323
335
  for (const [, plugin] of this.plugins) {
324
336
  plugin.particlesSetup?.();
325
337
  }
326
- this._engine.dispatchEvent("particlesSetup", { container: this });
338
+ this._engine.dispatchEvent(EventType_js_1.EventType.particlesSetup, { container: this });
327
339
  }
328
340
  async loadTheme(name) {
329
341
  if (!guardCheck(this)) {
@@ -349,7 +361,7 @@ class Container {
349
361
  if (!this.pageHidden) {
350
362
  this._paused = true;
351
363
  }
352
- this._engine.dispatchEvent("containerPaused", { container: this });
364
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerPaused, { container: this });
353
365
  }
354
366
  play(force) {
355
367
  if (!guardCheck(this)) {
@@ -370,7 +382,7 @@ class Container {
370
382
  }
371
383
  }
372
384
  }
373
- this._engine.dispatchEvent("containerPlay", { container: this });
385
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerPlay, { container: this });
374
386
  this.draw(needsUpdate ?? false);
375
387
  }
376
388
  async refresh() {
@@ -380,12 +392,13 @@ class Container {
380
392
  this.stop();
381
393
  return this.start();
382
394
  }
383
- async reset() {
395
+ async reset(sourceOptions) {
384
396
  if (!guardCheck(this)) {
385
397
  return;
386
398
  }
387
- this._initialSourceOptions = undefined;
388
- this._options = loadContainerOptions(this._engine, this);
399
+ this._initialSourceOptions = sourceOptions;
400
+ this._sourceOptions = sourceOptions;
401
+ this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
389
402
  this.actualOptions = loadContainerOptions(this._engine, this, this._options);
390
403
  return this.refresh();
391
404
  }
@@ -395,7 +408,7 @@ class Container {
395
408
  }
396
409
  await this.init();
397
410
  this.started = true;
398
- await new Promise((resolve) => {
411
+ await new Promise(resolve => {
399
412
  const start = async () => {
400
413
  this._eventListeners.addListeners();
401
414
  if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
@@ -404,7 +417,7 @@ class Container {
404
417
  for (const [, plugin] of this.plugins) {
405
418
  await plugin.start?.();
406
419
  }
407
- this._engine.dispatchEvent("containerStarted", { container: this });
420
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerStarted, { container: this });
408
421
  this.play();
409
422
  resolve();
410
423
  };
@@ -435,7 +448,7 @@ class Container {
435
448
  this.plugins.delete(key);
436
449
  }
437
450
  this._sourceOptions = this._options;
438
- this._engine.dispatchEvent("containerStopped", { container: this });
451
+ this._engine.dispatchEvent(EventType_js_1.EventType.containerStopped, { container: this });
439
452
  }
440
453
  updateActualOptions() {
441
454
  this.actualOptions.responsive = [];