@tsparticles/engine 3.2.2 → 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 (281) hide show
  1. package/README.md +0 -4
  2. package/browser/Core/Canvas.js +34 -29
  3. package/browser/Core/Container.js +60 -47
  4. package/browser/Core/Engine.js +82 -74
  5. package/browser/Core/Particle.js +40 -26
  6. package/browser/Core/Particles.js +51 -52
  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 +7 -6
  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 +27 -21
  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 +34 -29
  59. package/cjs/Core/Container.js +60 -47
  60. package/cjs/Core/Engine.js +82 -97
  61. package/cjs/Core/Particle.js +40 -26
  62. package/cjs/Core/Particles.js +52 -76
  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 +7 -6
  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 +27 -21
  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 +34 -29
  115. package/esm/Core/Container.js +60 -47
  116. package/esm/Core/Engine.js +82 -74
  117. package/esm/Core/Particle.js +40 -26
  118. package/esm/Core/Particles.js +51 -52
  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 +7 -6
  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 +27 -21
  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/Canvas.d.ts +4 -4
  176. package/types/Core/Container.d.ts +4 -2
  177. package/types/Core/Engine.d.ts +6 -5
  178. package/types/Core/Interfaces/IContainerPlugin.d.ts +4 -4
  179. package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
  180. package/types/Core/Interfaces/IExternalInteractor.d.ts +1 -1
  181. package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
  182. package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
  183. package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
  184. package/types/Core/Interfaces/IParticlesInteractor.d.ts +1 -1
  185. package/types/Core/Interfaces/IPlugin.d.ts +3 -4
  186. package/types/Core/Interfaces/IShapeDrawer.d.ts +5 -4
  187. package/types/Core/Particle.d.ts +3 -2
  188. package/types/Core/Particles.d.ts +7 -7
  189. package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
  190. package/types/Core/Utils/InteractionManager.d.ts +2 -2
  191. package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
  192. package/types/Enums/AnimationStatus.d.ts +1 -1
  193. package/types/Enums/Directions/MoveDirection.d.ts +1 -1
  194. package/types/Enums/Directions/OutModeDirection.d.ts +1 -1
  195. package/types/Enums/Directions/RotateDirection.d.ts +1 -1
  196. package/types/Enums/InteractivityDetect.d.ts +1 -1
  197. package/types/Enums/Modes/AnimationMode.d.ts +1 -1
  198. package/types/Enums/Modes/CollisionMode.d.ts +1 -1
  199. package/types/Enums/Modes/LimitMode.d.ts +1 -1
  200. package/types/Enums/Modes/OutMode.d.ts +1 -1
  201. package/types/Enums/Modes/PixelMode.d.ts +1 -1
  202. package/types/Enums/Modes/ResponsiveMode.d.ts +1 -1
  203. package/types/Enums/Modes/ThemeMode.d.ts +1 -1
  204. package/types/Enums/Types/AlterType.d.ts +1 -1
  205. package/types/Enums/Types/DestroyType.d.ts +1 -1
  206. package/types/Enums/Types/DivType.d.ts +1 -1
  207. package/types/Enums/Types/EasingType.d.ts +1 -1
  208. package/types/Enums/Types/EventType.d.ts +1 -1
  209. package/types/Enums/Types/GradientType.d.ts +1 -1
  210. package/types/Enums/Types/InteractorType.d.ts +1 -1
  211. package/types/Enums/Types/ParticleOutType.d.ts +1 -1
  212. package/types/Enums/Types/StartValueType.d.ts +1 -1
  213. package/types/Options/Classes/Options.d.ts +2 -1
  214. package/types/Options/Classes/Responsive.d.ts +2 -2
  215. package/types/Options/Classes/Theme/Theme.d.ts +2 -2
  216. package/types/Options/Interfaces/IResponsive.d.ts +2 -3
  217. package/types/Options/Interfaces/Theme/ITheme.d.ts +2 -3
  218. package/types/Types/RangeType.d.ts +1 -1
  219. package/types/Utils/CanvasUtils.d.ts +6 -6
  220. package/umd/Core/Canvas.js +34 -29
  221. package/umd/Core/Container.js +61 -48
  222. package/umd/Core/Engine.js +83 -99
  223. package/umd/Core/Particle.js +41 -27
  224. package/umd/Core/Particles.js +53 -78
  225. package/umd/Core/Utils/EventListeners.js +19 -18
  226. package/umd/Core/Utils/ExternalInteractorBase.js +3 -2
  227. package/umd/Core/Utils/InteractionManager.js +8 -7
  228. package/umd/Core/Utils/ParticlesInteractorBase.js +3 -2
  229. package/umd/Core/Utils/QuadTree.js +1 -1
  230. package/umd/Core/Utils/Ranges.js +6 -5
  231. package/umd/Enums/AnimationStatus.js +6 -0
  232. package/umd/Enums/Directions/MoveDirection.js +15 -0
  233. package/umd/Enums/Directions/OutModeDirection.js +8 -0
  234. package/umd/Enums/Directions/RotateDirection.js +7 -0
  235. package/umd/Enums/InteractivityDetect.js +7 -0
  236. package/umd/Enums/Modes/AnimationMode.js +8 -0
  237. package/umd/Enums/Modes/CollisionMode.js +7 -0
  238. package/umd/Enums/Modes/LimitMode.js +6 -0
  239. package/umd/Enums/Modes/OutMode.js +9 -0
  240. package/umd/Enums/Modes/PixelMode.js +6 -0
  241. package/umd/Enums/Modes/ResponsiveMode.js +6 -0
  242. package/umd/Enums/Modes/ThemeMode.js +7 -0
  243. package/umd/Enums/Types/AlterType.js +6 -0
  244. package/umd/Enums/Types/DestroyType.js +7 -0
  245. package/umd/Enums/Types/DivType.js +6 -0
  246. package/umd/Enums/Types/EasingType.js +31 -0
  247. package/umd/Enums/Types/EventType.js +16 -0
  248. package/umd/Enums/Types/GradientType.js +7 -0
  249. package/umd/Enums/Types/InteractorType.js +6 -0
  250. package/umd/Enums/Types/ParticleOutType.js +7 -0
  251. package/umd/Enums/Types/StartValueType.js +7 -0
  252. package/umd/Options/Classes/AnimationOptions.js +5 -3
  253. package/umd/Options/Classes/Interactivity/Events/DivEvent.js +3 -2
  254. package/umd/Options/Classes/Interactivity/Events/Events.js +1 -1
  255. package/umd/Options/Classes/Interactivity/Interactivity.js +3 -2
  256. package/umd/Options/Classes/ManualParticle.js +3 -2
  257. package/umd/Options/Classes/Options.js +15 -13
  258. package/umd/Options/Classes/Particles/Collisions/Collisions.js +3 -2
  259. package/umd/Options/Classes/Particles/Move/Move.js +3 -2
  260. package/umd/Options/Classes/Particles/Move/MoveCenter.js +3 -2
  261. package/umd/Options/Classes/Particles/Move/OutModes.js +3 -2
  262. package/umd/Options/Classes/Particles/Number/ParticlesNumberLimit.js +3 -2
  263. package/umd/Options/Classes/Particles/Opacity/OpacityAnimation.js +3 -2
  264. package/umd/Options/Classes/Particles/ParticlesOptions.js +1 -1
  265. package/umd/Options/Classes/Particles/Size/SizeAnimation.js +3 -2
  266. package/umd/Options/Classes/Responsive.js +6 -5
  267. package/umd/Options/Classes/Theme/ThemeDefault.js +3 -2
  268. package/umd/Types/RangeType.js +6 -0
  269. package/umd/Utils/CanvasUtils.js +28 -22
  270. package/umd/Utils/ColorUtils.js +18 -10
  271. package/umd/Utils/EventDispatcher.js +1 -1
  272. package/umd/Utils/HslColorManager.js +11 -4
  273. package/umd/Utils/NumberUtils.js +12 -11
  274. package/umd/Utils/RgbColorManager.js +11 -4
  275. package/umd/Utils/Utils.js +38 -32
  276. package/373.min.js +0 -2
  277. package/373.min.js.LICENSE.txt +0 -1
  278. package/438.min.js +0 -2
  279. package/438.min.js.LICENSE.txt +0 -1
  280. package/dist_browser_Core_Container_js.js +0 -92
  281. package/dist_browser_Core_Particle_js.js +0 -32
@@ -1,3 +1,4 @@
1
+ import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
1
2
  import { Vector } from "../Core/Utils/Vectors.js";
2
3
  import { isNumber } from "./TypeUtils.js";
3
4
  import { percentDenominator } from "../Core/Utils/Constants.js";
@@ -71,25 +72,25 @@ export function getParticleDirectionAngle(direction, position, center) {
71
72
  }
72
73
  const empty = 0, half = 0.5, quarter = 0.25, threeQuarter = half + quarter;
73
74
  switch (direction) {
74
- case "top":
75
+ case MoveDirection.top:
75
76
  return -Math.PI * half;
76
- case "top-right":
77
+ case MoveDirection.topRight:
77
78
  return -Math.PI * quarter;
78
- case "right":
79
+ case MoveDirection.right:
79
80
  return empty;
80
- case "bottom-right":
81
+ case MoveDirection.bottomRight:
81
82
  return Math.PI * quarter;
82
- case "bottom":
83
+ case MoveDirection.bottom:
83
84
  return Math.PI * half;
84
- case "bottom-left":
85
+ case MoveDirection.bottomLeft:
85
86
  return Math.PI * threeQuarter;
86
- case "left":
87
+ case MoveDirection.left:
87
88
  return Math.PI;
88
- case "top-left":
89
+ case MoveDirection.topLeft:
89
90
  return -Math.PI * threeQuarter;
90
- case "inside":
91
+ case MoveDirection.inside:
91
92
  return Math.atan2(center.y - position.y, center.x - position.x);
92
- case "outside":
93
+ case MoveDirection.outside:
93
94
  return Math.atan2(position.y - center.y, position.x - center.x);
94
95
  default:
95
96
  return getRandom() * doublePI;
@@ -1,4 +1,11 @@
1
1
  import { getRangeValue, parseAlpha } from "./NumberUtils.js";
2
+ var RgbIndexes;
3
+ (function (RgbIndexes) {
4
+ RgbIndexes[RgbIndexes["r"] = 1] = "r";
5
+ RgbIndexes[RgbIndexes["g"] = 2] = "g";
6
+ RgbIndexes[RgbIndexes["b"] = 3] = "b";
7
+ RgbIndexes[RgbIndexes["a"] = 5] = "a";
8
+ })(RgbIndexes || (RgbIndexes = {}));
2
9
  export class RgbColorManager {
3
10
  constructor() {
4
11
  this.key = "rgb";
@@ -27,10 +34,10 @@ export class RgbColorManager {
27
34
  const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.%]+)\s*)?\)/i, result = regex.exec(input), radix = 10, minLength = 4, defaultAlpha = 1;
28
35
  return result
29
36
  ? {
30
- a: result.length > minLength ? parseAlpha(result[5]) : defaultAlpha,
31
- b: parseInt(result[3], radix),
32
- g: parseInt(result[2], radix),
33
- r: parseInt(result[1], radix),
37
+ a: result.length > minLength ? parseAlpha(result[RgbIndexes.a]) : defaultAlpha,
38
+ b: parseInt(result[RgbIndexes.b], radix),
39
+ g: parseInt(result[RgbIndexes.g], radix),
40
+ r: parseInt(result[RgbIndexes.r], radix),
34
41
  }
35
42
  : undefined;
36
43
  }
@@ -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
  }
@@ -273,11 +278,11 @@ class Canvas {
273
278
  drawAsync(cb) {
274
279
  const ctx = this._context;
275
280
  if (!ctx) {
276
- return Promise.resolve(undefined);
281
+ return undefined;
277
282
  }
278
283
  return cb(ctx);
279
284
  }
280
- async drawParticle(particle, delta) {
285
+ drawParticle(particle, delta) {
281
286
  if (particle.spawning || particle.destroyed) {
282
287
  return;
283
288
  }
@@ -296,13 +301,13 @@ class Canvas {
296
301
  if (!fColor && !sColor) {
297
302
  return;
298
303
  }
299
- await this.drawAsync(async (ctx) => {
304
+ this.draw((ctx) => {
300
305
  const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
301
306
  fill: fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, zOpacity) : undefined,
302
307
  };
303
308
  colorStyles.stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, zStrokeOpacity) : colorStyles.fill;
304
309
  this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
305
- await (0, CanvasUtils_js_1.drawParticle)({
310
+ (0, CanvasUtils_js_1.drawParticle)({
306
311
  container,
307
312
  context: ctx,
308
313
  particle,
@@ -318,15 +323,15 @@ class Canvas {
318
323
  this._applyPostDrawUpdaters(particle);
319
324
  });
320
325
  }
321
- async drawParticlePlugin(plugin, particle, delta) {
322
- await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
326
+ drawParticlePlugin(plugin, particle, delta) {
327
+ this.draw(ctx => (0, CanvasUtils_js_1.drawParticlePlugin)(ctx, plugin, particle, delta));
323
328
  }
324
- async drawPlugin(plugin, delta) {
325
- await this.drawAsync((ctx) => (0, CanvasUtils_js_1.drawPlugin)(ctx, plugin, delta));
329
+ drawPlugin(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,16 +471,16 @@ 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()) {
475
480
  return;
476
481
  }
477
482
  const container = this.container, needsRefresh = container.updateActualOptions();
478
- await container.particles.setDensity();
483
+ container.particles.setDensity();
479
484
  this._applyResizePlugins();
480
485
  if (needsRefresh) {
481
486
  await container.refresh();