@tsparticles/engine 3.0.0-beta.3 → 3.0.0-beta.5

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 (182) hide show
  1. package/browser/Core/Canvas.js +2 -2
  2. package/browser/Core/Container.js +36 -19
  3. package/browser/Core/Engine.js +18 -5
  4. package/browser/Core/Particle.js +77 -41
  5. package/browser/Core/Particles.js +51 -26
  6. package/browser/Core/Retina.js +0 -2
  7. package/browser/Core/Utils/QuadTree.js +1 -1
  8. package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  9. package/browser/Options/Classes/ColorAnimation.js +4 -24
  10. package/browser/Options/Classes/Interactivity/Events/Events.js +2 -7
  11. package/browser/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  12. package/browser/Options/Classes/Particles/Effect/Effect.js +32 -0
  13. package/browser/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  14. package/browser/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  15. package/browser/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  16. package/browser/Options/Classes/Particles/ParticlesOptions.js +12 -6
  17. package/browser/Options/Classes/Particles/Size/Size.js +2 -3
  18. package/browser/Options/Classes/ValueWithRandom.js +1 -10
  19. package/browser/Utils/CanvasUtils.js +23 -18
  20. package/browser/Utils/ColorUtils.js +24 -38
  21. package/browser/Utils/NumberUtils.js +7 -16
  22. package/browser/Utils/Utils.js +7 -7
  23. package/browser/export-types.js +4 -0
  24. package/browser/exports.js +2 -3
  25. package/cjs/Core/Canvas.js +2 -2
  26. package/cjs/Core/Container.js +36 -19
  27. package/cjs/Core/Engine.js +18 -5
  28. package/cjs/Core/Particle.js +76 -40
  29. package/cjs/Core/Particles.js +51 -26
  30. package/cjs/Core/Retina.js +0 -2
  31. package/cjs/Core/Utils/QuadTree.js +1 -1
  32. package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  33. package/cjs/Options/Classes/ColorAnimation.js +4 -24
  34. package/cjs/Options/Classes/Interactivity/Events/Events.js +2 -7
  35. package/cjs/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  36. package/cjs/Options/Classes/Particles/Effect/Effect.js +36 -0
  37. package/cjs/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  38. package/cjs/Options/Classes/Particles/Number/ParticlesNumberLimit.js +21 -0
  39. package/cjs/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  40. package/cjs/Options/Classes/Particles/ParticlesOptions.js +12 -6
  41. package/cjs/Options/Classes/Particles/Size/Size.js +2 -3
  42. package/cjs/Options/Classes/ValueWithRandom.js +1 -10
  43. package/cjs/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +2 -0
  44. package/cjs/Utils/CanvasUtils.js +26 -21
  45. package/cjs/Utils/ColorUtils.js +24 -38
  46. package/cjs/Utils/NumberUtils.js +8 -18
  47. package/cjs/Utils/Utils.js +6 -6
  48. package/cjs/export-types.js +4 -0
  49. package/cjs/exports.js +2 -3
  50. package/esm/Core/Canvas.js +2 -2
  51. package/esm/Core/Container.js +36 -19
  52. package/esm/Core/Engine.js +18 -5
  53. package/esm/Core/Particle.js +77 -41
  54. package/esm/Core/Particles.js +51 -26
  55. package/esm/Core/Retina.js +0 -2
  56. package/esm/Core/Utils/QuadTree.js +1 -1
  57. package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  58. package/esm/Options/Classes/ColorAnimation.js +4 -24
  59. package/esm/Options/Classes/Interactivity/Events/Events.js +2 -7
  60. package/esm/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  61. package/esm/Options/Classes/Particles/Effect/Effect.js +32 -0
  62. package/esm/Options/Classes/Particles/Number/ParticlesNumber.js +3 -5
  63. package/esm/Options/Classes/Particles/Number/ParticlesNumberLimit.js +17 -0
  64. package/esm/Options/Classes/Particles/Opacity/Opacity.js +2 -3
  65. package/esm/Options/Classes/Particles/ParticlesOptions.js +12 -6
  66. package/esm/Options/Classes/Particles/Size/Size.js +2 -3
  67. package/esm/Options/Classes/ValueWithRandom.js +1 -10
  68. package/esm/Options/Interfaces/Particles/Effect/IEffect.js +1 -0
  69. package/esm/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +1 -0
  70. package/esm/Utils/CanvasUtils.js +23 -18
  71. package/esm/Utils/ColorUtils.js +24 -38
  72. package/esm/Utils/NumberUtils.js +7 -16
  73. package/esm/Utils/Utils.js +7 -7
  74. package/esm/export-types.js +4 -0
  75. package/esm/exports.js +2 -3
  76. package/package.json +1 -1
  77. package/report.html +4 -22
  78. package/tsparticles.engine.js +400 -295
  79. package/tsparticles.engine.min.js +1 -1
  80. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  81. package/types/Core/Canvas.d.ts +0 -1
  82. package/types/Core/Container.d.ts +8 -7
  83. package/types/Core/Engine.d.ts +7 -2
  84. package/types/Core/Interfaces/IContainerPlugin.d.ts +2 -3
  85. package/types/Core/Interfaces/IEffectDrawer.d.ts +10 -0
  86. package/types/Core/Interfaces/IExternalInteractor.d.ts +3 -4
  87. package/types/Core/Interfaces/IInteractor.d.ts +3 -3
  88. package/types/Core/Interfaces/IParticleRetinaProps.d.ts +0 -1
  89. package/types/Core/Interfaces/IParticlesInteractor.d.ts +3 -3
  90. package/types/Core/Interfaces/IShapeDrawData.d.ts +10 -0
  91. package/types/Core/Interfaces/IShapeDrawer.d.ts +3 -10
  92. package/types/Core/Particle.d.ts +6 -2
  93. package/types/Core/Particles.d.ts +10 -7
  94. package/types/Core/Retina.d.ts +0 -1
  95. package/types/Core/Utils/ExternalInteractorBase.d.ts +4 -4
  96. package/types/Core/Utils/InteractionManager.d.ts +1 -2
  97. package/types/Core/Utils/ParticlesInteractorBase.d.ts +5 -5
  98. package/types/Enums/Modes/LimitMode.d.ts +4 -0
  99. package/types/Enums/Types/EasingType.d.ts +3 -0
  100. package/types/Options/Classes/BackgroundMask/BackgroundMask.d.ts +1 -1
  101. package/types/Options/Classes/ColorAnimation.d.ts +2 -7
  102. package/types/Options/Classes/Interactivity/Events/ClickEvent.d.ts +1 -2
  103. package/types/Options/Classes/Interactivity/Events/DivEvent.d.ts +1 -2
  104. package/types/Options/Classes/Interactivity/Events/Events.d.ts +3 -3
  105. package/types/Options/Classes/Interactivity/Events/HoverEvent.d.ts +2 -3
  106. package/types/Options/Classes/Interactivity/Interactivity.d.ts +2 -2
  107. package/types/Options/Classes/Options.d.ts +6 -6
  108. package/types/Options/Classes/Particles/Bounce/ParticlesBounce.d.ts +2 -2
  109. package/types/Options/Classes/Particles/Collisions/Collisions.d.ts +3 -3
  110. package/types/Options/Classes/Particles/Effect/Effect.d.ts +13 -0
  111. package/types/Options/Classes/Particles/Move/Move.d.ts +8 -8
  112. package/types/Options/Classes/Particles/Move/MoveTrail.d.ts +1 -1
  113. package/types/Options/Classes/Particles/Number/ParticlesNumber.d.ts +3 -2
  114. package/types/Options/Classes/Particles/Number/ParticlesNumberLimit.d.ts +10 -0
  115. package/types/Options/Classes/Particles/Opacity/Opacity.d.ts +3 -3
  116. package/types/Options/Classes/Particles/ParticlesOptions.d.ts +12 -10
  117. package/types/Options/Classes/Particles/Size/Size.d.ts +3 -3
  118. package/types/Options/Classes/Theme/Theme.d.ts +1 -1
  119. package/types/Options/Classes/ValueWithRandom.d.ts +2 -4
  120. package/types/Options/Interfaces/IValueWithRandom.d.ts +0 -2
  121. package/types/Options/Interfaces/Interactivity/Events/IClickEvent.d.ts +1 -2
  122. package/types/Options/Interfaces/Interactivity/Events/IDivEvent.d.ts +1 -2
  123. package/types/Options/Interfaces/Interactivity/Events/IEvents.d.ts +1 -1
  124. package/types/Options/Interfaces/Interactivity/Events/IHoverEvent.d.ts +1 -2
  125. package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +8 -0
  126. package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -0
  127. package/types/Options/Interfaces/Particles/Number/IParticlesNumber.d.ts +2 -1
  128. package/types/Options/Interfaces/Particles/Number/IParticlesNumberLimit.d.ts +5 -0
  129. package/types/Utils/CanvasUtils.d.ts +2 -2
  130. package/types/Utils/NumberUtils.d.ts +0 -2
  131. package/types/Utils/Utils.d.ts +2 -3
  132. package/types/export-types.d.ts +5 -0
  133. package/types/exports.d.ts +2 -3
  134. package/umd/Core/Canvas.js +2 -2
  135. package/umd/Core/Container.js +36 -19
  136. package/umd/Core/Engine.js +18 -5
  137. package/umd/Core/Particle.js +76 -40
  138. package/umd/Core/Particles.js +51 -26
  139. package/umd/Core/Retina.js +0 -2
  140. package/umd/Core/Utils/QuadTree.js +1 -1
  141. package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -2
  142. package/umd/Options/Classes/ColorAnimation.js +5 -25
  143. package/umd/Options/Classes/Interactivity/Events/Events.js +3 -8
  144. package/umd/Options/Classes/Particles/Bounce/ParticlesBounceFactor.js +0 -1
  145. package/umd/Options/Classes/Particles/Effect/Effect.js +46 -0
  146. package/umd/Options/Classes/Particles/Number/ParticlesNumber.js +4 -6
  147. package/umd/Options/Classes/{Random.js → Particles/Number/ParticlesNumberLimit.js} +9 -9
  148. package/umd/Options/Classes/Particles/Opacity/Opacity.js +1 -2
  149. package/umd/Options/Classes/Particles/ParticlesOptions.js +13 -7
  150. package/umd/Options/Classes/Particles/Size/Size.js +3 -4
  151. package/umd/Options/Classes/ValueWithRandom.js +2 -11
  152. package/umd/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js +12 -0
  153. package/umd/Utils/CanvasUtils.js +26 -21
  154. package/umd/Utils/ColorUtils.js +24 -38
  155. package/umd/Utils/NumberUtils.js +9 -19
  156. package/umd/Utils/Utils.js +6 -6
  157. package/umd/export-types.js +5 -1
  158. package/umd/exports.js +3 -4
  159. package/browser/Options/Classes/Random.js +0 -17
  160. package/cjs/Options/Classes/Random.js +0 -21
  161. package/esm/Options/Classes/Random.js +0 -17
  162. package/types/Enums/Modes/ClickMode.d.ts +0 -9
  163. package/types/Enums/Modes/DivMode.d.ts +0 -5
  164. package/types/Enums/Modes/HoverMode.d.ts +0 -11
  165. package/types/Options/Classes/Random.d.ts +0 -9
  166. package/types/Options/Interfaces/IRandom.d.ts +0 -4
  167. /package/browser/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  168. /package/browser/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  169. /package/browser/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  170. /package/browser/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  171. /package/{esm/Enums/Modes/ClickMode.js → browser/Options/Interfaces/Particles/Number/IParticlesNumberLimit.js} +0 -0
  172. /package/cjs/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  173. /package/cjs/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  174. /package/cjs/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  175. /package/cjs/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
  176. /package/esm/{Enums/Modes/DivMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  177. /package/esm/{Enums/Modes/HoverMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  178. /package/esm/{Options/Interfaces/IRandom.js → Enums/Modes/LimitMode.js} +0 -0
  179. /package/umd/{Enums/Modes/ClickMode.js → Core/Interfaces/IEffectDrawer.js} +0 -0
  180. /package/umd/{Enums/Modes/DivMode.js → Core/Interfaces/IShapeDrawData.js} +0 -0
  181. /package/umd/Enums/Modes/{HoverMode.js → LimitMode.js} +0 -0
  182. /package/umd/Options/Interfaces/{IRandom.js → Particles/Effect/IEffect.js} +0 -0
@@ -8,7 +8,6 @@ import type { IDrawParticleParams } from "../Core/Interfaces/IDrawParticleParams
8
8
  import type { IHsl } from "../Core/Interfaces/Colors.js";
9
9
  import type { Particle } from "../Core/Particle.js";
10
10
  export declare function drawLine(context: CanvasRenderingContext2D, begin: ICoordinates, end: ICoordinates): void;
11
- export declare function drawTriangle(context: CanvasRenderingContext2D, p1: ICoordinates, p2: ICoordinates, p3: ICoordinates): void;
12
11
  export declare function paintBase(context: CanvasRenderingContext2D, dimension: IDimension, baseColor?: string): void;
13
12
  export declare function paintImage(context: CanvasRenderingContext2D, dimension: IDimension, image: HTMLImageElement | undefined, opacity: number): void;
14
13
  export declare function clear(context: CanvasRenderingContext2D, dimension: IDimension): void;
@@ -21,8 +20,9 @@ type DrawShapeData = {
21
20
  particle: Particle;
22
21
  radius: number;
23
22
  };
23
+ export declare function drawEffect(data: DrawShapeData): void;
24
24
  export declare function drawShape(data: DrawShapeData): void;
25
- export declare function drawShapeAfterEffect(data: DrawShapeData): void;
25
+ export declare function drawShapeAfterDraw(data: DrawShapeData): void;
26
26
  export declare function drawPlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, delta: IDelta): void;
27
27
  export declare function drawParticlePlugin(context: CanvasRenderingContext2D, plugin: IContainerPlugin, particle: Particle, delta: IDelta): void;
28
28
  export declare function alterHsl(color: IHsl, type: AlterType, value: number): IHsl;
@@ -1,7 +1,6 @@
1
1
  import type { EasingType, EasingTypeAlt } from "../Enums/Types/EasingType.js";
2
2
  import type { IPositionFromSizeParams, IRangedPositionFromSizeParams } from "../Core/Interfaces/IPositionFromSizeParams.js";
3
3
  import type { ICoordinates } from "../Core/Interfaces/ICoordinates.js";
4
- import type { IValueWithRandom } from "../Options/Interfaces/IValueWithRandom.js";
5
4
  import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
6
5
  import type { MoveDirectionAlt } from "../Enums/Directions/MoveDirection.js";
7
6
  import type { RangeValue } from "../Types/RangeValue.js";
@@ -18,7 +17,6 @@ export declare function getRangeValue(value: RangeValue): number;
18
17
  export declare function getRangeMin(value: RangeValue): number;
19
18
  export declare function getRangeMax(value: RangeValue): number;
20
19
  export declare function setRangeValue(source: RangeValue, value?: number): RangeValue;
21
- export declare function getValue(options: IValueWithRandom): number;
22
20
  export declare function getDistances(pointA: ICoordinates, pointB: ICoordinates): {
23
21
  distance: number;
24
22
  dx: number;
@@ -1,7 +1,6 @@
1
1
  import type { ICoordinates, ICoordinatesWithMode } from "../Core/Interfaces/ICoordinates.js";
2
2
  import type { IDimension, IDimensionWithMode } from "../Core/Interfaces/IDimension.js";
3
3
  import type { DivEvent } from "../Options/Classes/Interactivity/Events/DivEvent.js";
4
- import type { DivMode } from "../Enums/Modes/DivMode.js";
5
4
  import type { IBounds } from "../Core/Interfaces/IBounds.js";
6
5
  import type { ICircleBouncer } from "../Core/Interfaces/ICircleBouncer.js";
7
6
  import type { IModeDiv } from "../Options/Interfaces/Interactivity/Modes/IModeDiv.js";
@@ -33,8 +32,8 @@ export declare function isPointInside(point: ICoordinates, size: IDimension, off
33
32
  export declare function areBoundsInside(bounds: IBounds, size: IDimension, offset: ICoordinates, direction?: OutModeDirection): boolean;
34
33
  export declare function calculateBounds(point: ICoordinates, radius: number): IBounds;
35
34
  export declare function deepExtend(destination: unknown, ...sources: unknown[]): unknown;
36
- export declare function isDivModeEnabled(mode: DivMode, divs: SingleOrMultiple<DivEvent>): boolean;
37
- export declare function divModeExecute(mode: DivMode, divs: SingleOrMultiple<DivEvent>, callback: (id: string, div: DivEvent) => void): void;
35
+ export declare function isDivModeEnabled(mode: string, divs: SingleOrMultiple<DivEvent>): boolean;
36
+ export declare function divModeExecute(mode: string, divs: SingleOrMultiple<DivEvent>, callback: (id: string, div: DivEvent) => void): void;
38
37
  export declare function singleDivModeExecute(div: DivEvent, callback: (selector: string, div: DivEvent) => void): void;
39
38
  export declare function divMode<T extends IModeDiv>(divs?: SingleOrMultiple<T>, element?: HTMLElement): T | undefined;
40
39
  export declare function circleBounceDataFromParticle(p: Particle): ICircleBouncer;
@@ -11,6 +11,7 @@ export * from "./Core/Interfaces/IDelta.js";
11
11
  export * from "./Core/Interfaces/IDimension.js";
12
12
  export * from "./Core/Interfaces/IDistance.js";
13
13
  export * from "./Core/Interfaces/IDrawParticleParams.js";
14
+ export * from "./Core/Interfaces/IEffectDrawer.js";
14
15
  export * from "./Core/Interfaces/IExternalInteractor.js";
15
16
  export * from "./Core/Interfaces/IInteractor.js";
16
17
  export * from "./Core/Interfaces/ILoadParams.js";
@@ -30,6 +31,7 @@ export * from "./Core/Interfaces/IPlugin.js";
30
31
  export * from "./Core/Interfaces/IPositionFromSizeParams.js";
31
32
  export * from "./Core/Interfaces/IRangeValue.js";
32
33
  export * from "./Core/Interfaces/IRectSideResult.js";
34
+ export * from "./Core/Interfaces/IShapeDrawData.js";
33
35
  export * from "./Core/Interfaces/IShapeDrawer.js";
34
36
  export * from "./Core/Interfaces/IShapeValues.js";
35
37
  export * from "./Core/Interfaces/ISlowParticleData.js";
@@ -62,6 +64,7 @@ export * from "./Options/Interfaces/Particles/Bounce/IParticlesBounce.js";
62
64
  export * from "./Options/Interfaces/Particles/Collisions/ICollisions.js";
63
65
  export * from "./Options/Interfaces/Particles/Collisions/ICollisionsAbsorb.js";
64
66
  export * from "./Options/Interfaces/Particles/Collisions/ICollisionsOverlap.js";
67
+ export * from "./Options/Interfaces/Particles/Effect/IEffect.js";
65
68
  export * from "./Options/Interfaces/Particles/IParticlesOptions.js";
66
69
  export * from "./Options/Interfaces/Particles/IShadow.js";
67
70
  export * from "./Options/Interfaces/Particles/IStroke.js";
@@ -76,6 +79,7 @@ export * from "./Options/Interfaces/Particles/Move/ISpin.js";
76
79
  export * from "./Options/Interfaces/Particles/Move/IMoveTrail.js";
77
80
  export * from "./Options/Interfaces/Particles/Number/IParticlesDensity.js";
78
81
  export * from "./Options/Interfaces/Particles/Number/IParticlesNumber.js";
82
+ export * from "./Options/Interfaces/Particles/Number/IParticlesNumberLimit.js";
79
83
  export * from "./Options/Interfaces/Particles/Opacity/IOpacity.js";
80
84
  export * from "./Options/Interfaces/Particles/Opacity/IOpacityAnimation.js";
81
85
  export * from "./Options/Interfaces/Particles/Shape/IShape.js";
@@ -103,3 +107,4 @@ export type { Particle } from "./Core/Particle.js";
103
107
  export type { Particles } from "./Core/Particles.js";
104
108
  export type { Retina } from "./Core/Retina.js";
105
109
  export type { Engine, Engine as Main };
110
+ export type { IParticlesNumberLimit } from "./Options/Interfaces/Particles/Number/IParticlesNumberLimit.js";
@@ -11,10 +11,8 @@ export * from "./Enums/Directions/MoveDirection.js";
11
11
  export * from "./Enums/Directions/RotateDirection.js";
12
12
  export * from "./Enums/Directions/OutModeDirection.js";
13
13
  export * from "./Enums/Modes/AnimationMode.js";
14
- export * from "./Enums/Modes/ClickMode.js";
15
- export * from "./Enums/Modes/DivMode.js";
16
- export * from "./Enums/Modes/HoverMode.js";
17
14
  export * from "./Enums/Modes/CollisionMode.js";
15
+ export * from "./Enums/Modes/LimitMode.js";
18
16
  export * from "./Enums/Modes/OutMode.js";
19
17
  export * from "./Enums/Modes/PixelMode.js";
20
18
  export * from "./Enums/Modes/ThemeMode.js";
@@ -69,6 +67,7 @@ export * from "./Options/Classes/Particles/Move/Path/MovePath.js";
69
67
  export * from "./Options/Classes/Particles/Move/Spin.js";
70
68
  export * from "./Options/Classes/Particles/Move/MoveTrail.js";
71
69
  export * from "./Options/Classes/Particles/Number/ParticlesNumber.js";
70
+ export * from "./Options/Classes/Particles/Number/ParticlesNumberLimit.js";
72
71
  export * from "./Options/Classes/Particles/Number/ParticlesDensity.js";
73
72
  export * from "./Options/Classes/Particles/Opacity/Opacity.js";
74
73
  export * from "./Options/Classes/Particles/Opacity/OpacityAnimation.js";
@@ -414,10 +414,10 @@
414
414
  this.element.width = size.width = this.element.offsetWidth * pxRatio;
415
415
  this.element.height = size.height = this.element.offsetHeight * pxRatio;
416
416
  if (this.container.started) {
417
- this.resizeFactor = {
417
+ container.particles.setResizeFactor({
418
418
  width: size.width / oldSize.width,
419
419
  height: size.height / oldSize.height,
420
- };
420
+ });
421
421
  }
422
422
  return true;
423
423
  }
@@ -48,16 +48,16 @@
48
48
  };
49
49
  this._nextFrame = async (timestamp) => {
50
50
  try {
51
- if (!this.smooth &&
52
- this.lastFrameTime !== undefined &&
53
- timestamp < this.lastFrameTime + 1000 / this.fpsLimit) {
51
+ if (!this._smooth &&
52
+ this._lastFrameTime !== undefined &&
53
+ timestamp < this._lastFrameTime + 1000 / this.fpsLimit) {
54
54
  this.draw(false);
55
55
  return;
56
56
  }
57
- this.lastFrameTime ??= timestamp;
58
- const delta = initDelta(timestamp - this.lastFrameTime, this.fpsLimit, this.smooth);
57
+ this._lastFrameTime ??= timestamp;
58
+ const delta = initDelta(timestamp - this._lastFrameTime, this.fpsLimit, this._smooth);
59
59
  this.addLifeTime(delta.value);
60
- this.lastFrameTime = timestamp;
60
+ this._lastFrameTime = timestamp;
61
61
  if (delta.value > 1000) {
62
62
  this.draw(false);
63
63
  return;
@@ -78,7 +78,7 @@
78
78
  this._engine = engine;
79
79
  this.id = Symbol(id);
80
80
  this.fpsLimit = 120;
81
- this.smooth = false;
81
+ this._smooth = false;
82
82
  this._delay = 0;
83
83
  this._duration = 0;
84
84
  this._lifeTime = 0;
@@ -86,7 +86,7 @@
86
86
  this.started = false;
87
87
  this.destroyed = false;
88
88
  this._paused = true;
89
- this.lastFrameTime = 0;
89
+ this._lastFrameTime = 0;
90
90
  this.zLayers = 100;
91
91
  this.pageHidden = false;
92
92
  this._sourceOptions = sourceOptions;
@@ -102,7 +102,8 @@
102
102
  },
103
103
  };
104
104
  this.plugins = new Map();
105
- this.drawers = new Map();
105
+ this.effectDrawers = new Map();
106
+ this.shapeDrawers = new Map();
106
107
  this._options = loadContainerOptions(this._engine, this);
107
108
  this.actualOptions = loadContainerOptions(this._engine, this);
108
109
  this._eventListeners = new EventListeners_js_1.EventListeners(this);
@@ -212,11 +213,17 @@
212
213
  this.stop();
213
214
  this.particles.destroy();
214
215
  this.canvas.destroy();
215
- for (const [, drawer] of this.drawers) {
216
- drawer.destroy && drawer.destroy(this);
216
+ for (const [, effectDrawer] of this.effectDrawers) {
217
+ effectDrawer.destroy && effectDrawer.destroy(this);
217
218
  }
218
- for (const key of this.drawers.keys()) {
219
- this.drawers.delete(key);
219
+ for (const [, shapeDrawer] of this.shapeDrawers) {
220
+ shapeDrawer.destroy && shapeDrawer.destroy(this);
221
+ }
222
+ for (const key of this.effectDrawers.keys()) {
223
+ this.effectDrawers.delete(key);
224
+ }
225
+ for (const key of this.shapeDrawers.keys()) {
226
+ this.shapeDrawers.delete(key);
220
227
  }
221
228
  this._engine.clearPlugins(this);
222
229
  this.destroyed = true;
@@ -233,7 +240,7 @@
233
240
  let refreshTime = force;
234
241
  this._drawAnimationFrame = requestAnimationFrame(async (timestamp) => {
235
242
  if (refreshTime) {
236
- this.lastFrameTime = undefined;
243
+ this._lastFrameTime = undefined;
237
244
  refreshTime = false;
238
245
  }
239
246
  await this._nextFrame(timestamp);
@@ -268,11 +275,18 @@
268
275
  if (!guardCheck(this)) {
269
276
  return;
270
277
  }
278
+ const effects = this._engine.getSupportedEffects();
279
+ for (const type of effects) {
280
+ const drawer = this._engine.getEffectDrawer(type);
281
+ if (drawer) {
282
+ this.effectDrawers.set(type, drawer);
283
+ }
284
+ }
271
285
  const shapes = this._engine.getSupportedShapes();
272
286
  for (const type of shapes) {
273
287
  const drawer = this._engine.getShapeDrawer(type);
274
288
  if (drawer) {
275
- this.drawers.set(type, drawer);
289
+ this.shapeDrawers.set(type, drawer);
276
290
  }
277
291
  }
278
292
  this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
@@ -291,8 +305,11 @@
291
305
  this._delay = (0, NumberUtils_js_1.getRangeValue)(this.actualOptions.delay) * 1000;
292
306
  this._lifeTime = 0;
293
307
  this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
294
- this.smooth = this.actualOptions.smooth;
295
- for (const [, drawer] of this.drawers) {
308
+ this._smooth = this.actualOptions.smooth;
309
+ for (const [, drawer] of this.effectDrawers) {
310
+ drawer.init && (await drawer.init(this));
311
+ }
312
+ for (const [, drawer] of this.shapeDrawers) {
296
313
  drawer.init && (await drawer.init(this));
297
314
  }
298
315
  for (const [, plugin] of this.plugins) {
@@ -421,10 +438,10 @@
421
438
  this.actualOptions.responsive = [];
422
439
  const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
423
440
  this.actualOptions.setTheme(this._currentTheme);
424
- if (this.responsiveMaxWidth === newMaxWidth) {
441
+ if (this._responsiveMaxWidth === newMaxWidth) {
425
442
  return false;
426
443
  }
427
- this.responsiveMaxWidth = newMaxWidth;
444
+ this._responsiveMaxWidth = newMaxWidth;
428
445
  return true;
429
446
  }
430
447
  }
@@ -51,7 +51,8 @@
51
51
  this.movers = new Map();
52
52
  this.updaters = new Map();
53
53
  this.presets = new Map();
54
- this.drawers = new Map();
54
+ this.effectDrawers = new Map();
55
+ this.shapeDrawers = new Map();
55
56
  this.pathGenerators = new Map();
56
57
  }
57
58
  get configs() {
@@ -62,13 +63,19 @@
62
63
  return res;
63
64
  }
64
65
  get version() {
65
- return "3.0.0-beta.3";
66
+ return "3.0.0-beta.5";
66
67
  }
67
68
  addConfig(config) {
68
69
  const name = config.name ?? "default";
69
70
  this._configs.set(name, config);
70
71
  this._eventDispatcher.dispatchEvent("configAdded", { data: { name, config } });
71
72
  }
73
+ async addEffect(effect, drawer, refresh = true) {
74
+ (0, Utils_js_1.executeOnSingleOrMultiple)(effect, (type) => {
75
+ !this.getEffectDrawer(type) && this.effectDrawers.set(type, drawer);
76
+ });
77
+ await this.refresh(refresh);
78
+ }
72
79
  addEventListener(type, listener) {
73
80
  this._eventDispatcher.addEventListener(type, listener);
74
81
  }
@@ -98,7 +105,7 @@
98
105
  }
99
106
  async addShape(shape, drawer, refresh = true) {
100
107
  (0, Utils_js_1.executeOnSingleOrMultiple)(shape, (type) => {
101
- !this.getShapeDrawer(type) && this.drawers.set(type, drawer);
108
+ !this.getShapeDrawer(type) && this.shapeDrawers.set(type, drawer);
102
109
  });
103
110
  await this.refresh(refresh);
104
111
  }
@@ -128,6 +135,9 @@
128
135
  }
129
136
  return res;
130
137
  }
138
+ getEffectDrawer(type) {
139
+ return this.effectDrawers.get(type);
140
+ }
131
141
  getInteractors(container, force = false) {
132
142
  return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
133
143
  }
@@ -144,10 +154,13 @@
144
154
  return this.presets.get(preset);
145
155
  }
146
156
  getShapeDrawer(type) {
147
- return this.drawers.get(type);
157
+ return this.shapeDrawers.get(type);
158
+ }
159
+ getSupportedEffects() {
160
+ return this.effectDrawers.keys();
148
161
  }
149
162
  getSupportedShapes() {
150
- return this.drawers.keys();
163
+ return this.shapeDrawers.keys();
151
164
  }
152
165
  getUpdaters(container, force = false) {
153
166
  return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
@@ -19,6 +19,16 @@
19
19
  const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
20
20
  const Constants_js_1 = require("./Utils/Constants.js");
21
21
  const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
22
+ function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
23
+ const effectData = effectOptions.options[effect];
24
+ if (!effectData) {
25
+ return;
26
+ }
27
+ return (0, Utils_js_1.deepExtend)({
28
+ close: effectOptions.close,
29
+ fill: effectOptions.fill,
30
+ }, (0, Utils_js_1.itemFromSingleOrMultiple)(effectData, id, reduceDuplicates));
31
+ }
22
32
  function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
23
33
  const shapeData = shapeOptions.options[shape];
24
34
  if (!shapeData) {
@@ -88,8 +98,8 @@
88
98
  return res;
89
99
  }
90
100
  const rad = (Math.PI / 180) * (0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value), radOffset = (Math.PI / 180) * (0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset), range = {
91
- left: radOffset - rad / 2,
92
- right: radOffset + rad / 2,
101
+ left: radOffset - rad * 0.5,
102
+ right: radOffset + rad * 0.5,
93
103
  };
94
104
  if (!moveOptions.straight) {
95
105
  res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
@@ -118,7 +128,7 @@
118
128
  if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
119
129
  return color;
120
130
  }
121
- const backFactor = this.roll.horizontal && this.roll.vertical ? 2 : 1, backSum = this.roll.horizontal ? Math.PI / 2 : 0, rolled = Math.floor(((this.roll.angle ?? 0) + backSum) / (Math.PI / backFactor)) % 2;
131
+ const backFactor = this.roll.horizontal && this.roll.vertical ? 2 : 1, backSum = this.roll.horizontal ? Math.PI * 0.5 : 0, rolled = Math.floor(((this.roll.angle ?? 0) + backSum) / (Math.PI / backFactor)) % 2;
122
132
  if (!rolled) {
123
133
  return color;
124
134
  }
@@ -161,20 +171,15 @@
161
171
  this.destroyed = true;
162
172
  this.bubble.inRange = false;
163
173
  this.slow.inRange = false;
164
- const container = this.container, pathGenerator = this.pathGenerator;
174
+ const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = container.shapeDrawers.get(this.shape);
175
+ shapeDrawer && shapeDrawer.particleDestroy && shapeDrawer.particleDestroy(this);
165
176
  for (const [, plugin] of container.plugins) {
166
- if (plugin.particleDestroyed) {
167
- plugin.particleDestroyed(this, override);
168
- }
177
+ plugin.particleDestroyed && plugin.particleDestroyed(this, override);
169
178
  }
170
179
  for (const updater of container.particles.updaters) {
171
- if (updater.particleDestroyed) {
172
- updater.particleDestroyed(this, override);
173
- }
174
- }
175
- if (pathGenerator) {
176
- pathGenerator.reset(this);
180
+ updater.particleDestroyed && updater.particleDestroyed(this, override);
177
181
  }
182
+ pathGenerator && pathGenerator.reset(this);
178
183
  }
179
184
  draw(delta) {
180
185
  const container = this.container, canvas = container.canvas;
@@ -187,7 +192,7 @@
187
192
  return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
188
193
  }
189
194
  getMass() {
190
- return (this.getRadius() ** 2 * Math.PI) / 2;
195
+ return this.getRadius() ** 2 * Math.PI * 0.5;
191
196
  }
192
197
  getPosition() {
193
198
  return {
@@ -206,9 +211,11 @@
206
211
  const container = this.container, engine = this._engine;
207
212
  this.id = id;
208
213
  this.group = group;
209
- this.fill = true;
214
+ this.effectClose = true;
215
+ this.effectFill = true;
216
+ this.shapeClose = true;
217
+ this.shapeFill = true;
210
218
  this.pathRotation = false;
211
- this.close = true;
212
219
  this.lastPathTime = 0;
213
220
  this.destroyed = false;
214
221
  this.unbreakable = false;
@@ -219,18 +226,33 @@
219
226
  };
220
227
  this.outType = "normal";
221
228
  this.ignoresResizeRatio = true;
222
- const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), shapeType = particlesOptions.shape.type, { reduceDuplicates } = particlesOptions;
229
+ const pxRatio = container.retina.pixelRatio, mainOptions = container.actualOptions, particlesOptions = (0, OptionsUtils_js_1.loadParticlesOptions)(this._engine, container, mainOptions.particles), effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type, { reduceDuplicates } = particlesOptions;
230
+ this.effect = (0, Utils_js_1.itemFromSingleOrMultiple)(effectType, this.id, reduceDuplicates);
223
231
  this.shape = (0, Utils_js_1.itemFromSingleOrMultiple)(shapeType, this.id, reduceDuplicates);
224
- const shapeOptions = particlesOptions.shape;
225
- if (overrideOptions && overrideOptions.shape && overrideOptions.shape.type) {
226
- const overrideShapeType = overrideOptions.shape.type, shape = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);
227
- if (shape) {
228
- this.shape = shape;
229
- shapeOptions.load(overrideOptions.shape);
232
+ const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
233
+ if (overrideOptions) {
234
+ if (overrideOptions.effect && overrideOptions.effect.type) {
235
+ const overrideEffectType = overrideOptions.effect.type, effect = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideEffectType, this.id, reduceDuplicates);
236
+ if (effect) {
237
+ this.effect = effect;
238
+ effectOptions.load(overrideOptions.effect);
239
+ }
240
+ }
241
+ if (overrideOptions.shape && overrideOptions.shape.type) {
242
+ const overrideShapeType = overrideOptions.shape.type, shape = (0, Utils_js_1.itemFromSingleOrMultiple)(overrideShapeType, this.id, reduceDuplicates);
243
+ if (shape) {
244
+ this.shape = shape;
245
+ shapeOptions.load(overrideOptions.shape);
246
+ }
230
247
  }
231
248
  }
249
+ this.effectData = loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates);
232
250
  this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
233
251
  particlesOptions.load(overrideOptions);
252
+ const effectData = this.effectData;
253
+ if (effectData) {
254
+ particlesOptions.load(effectData.particles);
255
+ }
234
256
  const shapeData = this.shapeData;
235
257
  if (shapeData) {
236
258
  particlesOptions.load(shapeData.particles);
@@ -239,11 +261,13 @@
239
261
  interactivity.load(container.actualOptions.interactivity);
240
262
  interactivity.load(particlesOptions.interactivity);
241
263
  this.interactivity = interactivity;
242
- this.fill = shapeData?.fill ?? particlesOptions.shape.fill;
243
- this.close = shapeData?.close ?? particlesOptions.shape.close;
264
+ this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;
265
+ this.effectClose = effectData?.close ?? particlesOptions.effect.close;
266
+ this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
267
+ this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
244
268
  this.options = particlesOptions;
245
269
  const pathOptions = this.options.move.path;
246
- this.pathDelay = (0, NumberUtils_js_1.getValue)(pathOptions.delay) * 1000;
270
+ this.pathDelay = (0, NumberUtils_js_1.getRangeValue)(pathOptions.delay.value) * 1000;
247
271
  if (pathOptions.generator) {
248
272
  this.pathGenerator = this._engine.getPathGenerator(pathOptions.generator);
249
273
  if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
@@ -264,34 +288,46 @@
264
288
  this.velocity = this.initialVelocity.copy();
265
289
  this.moveDecay = 1 - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
266
290
  const particles = container.particles;
267
- particles.needsSort = particles.needsSort || particles.lastZIndex < this.position.z;
268
- particles.lastZIndex = this.position.z;
291
+ particles.setLastZIndex(this.position.z);
269
292
  this.zIndexFactor = this.position.z / container.zLayers;
270
293
  this.sides = 24;
271
- let drawer = container.drawers.get(this.shape);
272
- if (!drawer) {
273
- drawer = this._engine.getShapeDrawer(this.shape);
274
- if (drawer) {
275
- container.drawers.set(this.shape, drawer);
294
+ let effectDrawer = container.effectDrawers.get(this.effect);
295
+ if (!effectDrawer) {
296
+ effectDrawer = this._engine.getEffectDrawer(this.effect);
297
+ if (effectDrawer) {
298
+ container.effectDrawers.set(this.effect, effectDrawer);
299
+ }
300
+ }
301
+ if (effectDrawer && effectDrawer.loadEffect) {
302
+ effectDrawer.loadEffect(this);
303
+ }
304
+ let shapeDrawer = container.shapeDrawers.get(this.shape);
305
+ if (!shapeDrawer) {
306
+ shapeDrawer = this._engine.getShapeDrawer(this.shape);
307
+ if (shapeDrawer) {
308
+ container.shapeDrawers.set(this.shape, shapeDrawer);
276
309
  }
277
310
  }
278
- if (drawer && drawer.loadShape) {
279
- drawer.loadShape(this);
311
+ if (shapeDrawer && shapeDrawer.loadShape) {
312
+ shapeDrawer.loadShape(this);
280
313
  }
281
- const sideCountFunc = drawer?.getSidesCount;
314
+ const sideCountFunc = shapeDrawer?.getSidesCount;
282
315
  if (sideCountFunc) {
283
316
  this.sides = sideCountFunc(this);
284
317
  }
285
318
  this.spawning = false;
286
319
  this.shadowColor = (0, ColorUtils_js_1.rangeColorToRgb)(this.options.shadow.color);
287
- for (const updater of container.particles.updaters) {
320
+ for (const updater of particles.updaters) {
288
321
  updater.init(this);
289
322
  }
290
- for (const mover of container.particles.movers) {
323
+ for (const mover of particles.movers) {
291
324
  mover.init && mover.init(this);
292
325
  }
293
- if (drawer && drawer.particleInit) {
294
- drawer.particleInit(container, this);
326
+ if (effectDrawer && effectDrawer.particleInit) {
327
+ effectDrawer.particleInit(container, this);
328
+ }
329
+ if (shapeDrawer && shapeDrawer.particleInit) {
330
+ shapeDrawer.particleInit(container, this);
295
331
  }
296
332
  for (const [, plugin] of container.plugins) {
297
333
  plugin.particleCreated && plugin.particleCreated(this);