tsparticles 1.39.2 → 1.40.2

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 (168) hide show
  1. package/Core/Container.d.ts +3 -1
  2. package/Core/Container.js +30 -15
  3. package/Core/Loader.d.ts +12 -9
  4. package/Core/Loader.js +35 -19
  5. package/Core/Particle.d.ts +3 -1
  6. package/Core/Particle.js +17 -2
  7. package/Core/Particles.d.ts +3 -1
  8. package/Core/Particles.js +20 -5
  9. package/Core/Utils/InteractionManager.d.ts +5 -3
  10. package/Core/Utils/InteractionManager.js +19 -3
  11. package/Core/Utils/Plugins.d.ts +29 -15
  12. package/Core/Utils/Plugins.js +58 -46
  13. package/Options/Classes/Options.d.ts +2 -1
  14. package/Options/Classes/Options.js +14 -7
  15. package/Plugins/Emitters/EmitterInstance.d.ts +6 -3
  16. package/Plugins/Emitters/EmitterInstance.js +46 -16
  17. package/Plugins/Emitters/Emitters.d.ts +3 -1
  18. package/Plugins/Emitters/Emitters.js +17 -2
  19. package/Plugins/Emitters/{EmittersMain.d.ts → EmittersEngine.d.ts} +3 -1
  20. package/Plugins/Emitters/{EmittersMain.js → EmittersEngine.js} +0 -0
  21. package/Plugins/Emitters/IEmitterShape.d.ts +2 -2
  22. package/Plugins/Emitters/Options/Classes/Emitter.d.ts +1 -0
  23. package/Plugins/Emitters/Options/Classes/Emitter.js +1 -0
  24. package/Plugins/Emitters/Options/Interfaces/IEmitter.d.ts +1 -0
  25. package/Plugins/Emitters/ShapeManager.d.ts +6 -3
  26. package/Plugins/Emitters/ShapeManager.js +16 -4
  27. package/Plugins/Emitters/Shapes/Circle/CircleShape.d.ts +2 -2
  28. package/Plugins/Emitters/Shapes/Circle/CircleShape.js +2 -2
  29. package/Plugins/Emitters/Shapes/Square/SquareShape.d.ts +2 -2
  30. package/Plugins/Emitters/Shapes/Square/SquareShape.js +4 -4
  31. package/Plugins/Emitters/index.d.ts +3 -3
  32. package/Plugins/Emitters/index.js +25 -6
  33. package/README.md +1 -1
  34. package/browser/Core/Container.d.ts +4 -1
  35. package/browser/Core/Container.js +32 -16
  36. package/browser/Core/Loader.d.ts +12 -9
  37. package/browser/Core/Loader.js +35 -19
  38. package/browser/Core/Particle.d.ts +3 -1
  39. package/browser/Core/Particle.js +18 -3
  40. package/browser/Core/Particles.d.ts +3 -1
  41. package/browser/Core/Particles.js +21 -6
  42. package/browser/Core/Utils/InteractionManager.d.ts +5 -3
  43. package/browser/Core/Utils/InteractionManager.js +19 -3
  44. package/browser/Core/Utils/Plugins.d.ts +29 -15
  45. package/browser/Core/Utils/Plugins.js +58 -46
  46. package/browser/Options/Classes/Options.d.ts +2 -1
  47. package/browser/Options/Classes/Options.js +14 -7
  48. package/browser/Plugins/Emitters/EmitterInstance.d.ts +6 -3
  49. package/browser/Plugins/Emitters/EmitterInstance.js +46 -16
  50. package/browser/Plugins/Emitters/Emitters.d.ts +3 -1
  51. package/browser/Plugins/Emitters/Emitters.js +17 -2
  52. package/{esm/Plugins/Emitters/EmittersMain.d.ts → browser/Plugins/Emitters/EmittersEngine.d.ts} +3 -1
  53. package/browser/Plugins/Emitters/{EmittersMain.js → EmittersEngine.js} +0 -0
  54. package/browser/Plugins/Emitters/IEmitterShape.d.ts +2 -2
  55. package/browser/Plugins/Emitters/Options/Classes/Emitter.d.ts +1 -0
  56. package/browser/Plugins/Emitters/Options/Classes/Emitter.js +1 -0
  57. package/browser/Plugins/Emitters/Options/Interfaces/IEmitter.d.ts +4 -0
  58. package/browser/Plugins/Emitters/ShapeManager.d.ts +6 -3
  59. package/browser/Plugins/Emitters/ShapeManager.js +16 -4
  60. package/browser/Plugins/Emitters/Shapes/Circle/CircleShape.d.ts +2 -2
  61. package/browser/Plugins/Emitters/Shapes/Circle/CircleShape.js +2 -2
  62. package/browser/Plugins/Emitters/Shapes/Square/SquareShape.d.ts +2 -2
  63. package/browser/Plugins/Emitters/Shapes/Square/SquareShape.js +4 -4
  64. package/browser/Plugins/Emitters/index.d.ts +3 -3
  65. package/browser/Plugins/Emitters/index.js +25 -6
  66. package/browser/engine.d.ts +5 -1
  67. package/browser/engine.js +22 -17
  68. package/engine.d.ts +3 -0
  69. package/engine.js +20 -16
  70. package/esm/Core/Container.d.ts +3 -1
  71. package/esm/Core/Container.js +31 -16
  72. package/esm/Core/Loader.d.ts +12 -9
  73. package/esm/Core/Loader.js +35 -19
  74. package/esm/Core/Particle.d.ts +3 -1
  75. package/esm/Core/Particle.js +18 -3
  76. package/esm/Core/Particles.d.ts +3 -1
  77. package/esm/Core/Particles.js +21 -6
  78. package/esm/Core/Utils/InteractionManager.d.ts +5 -3
  79. package/esm/Core/Utils/InteractionManager.js +19 -3
  80. package/esm/Core/Utils/Plugins.d.ts +29 -15
  81. package/esm/Core/Utils/Plugins.js +58 -46
  82. package/esm/Options/Classes/Options.d.ts +2 -1
  83. package/esm/Options/Classes/Options.js +14 -7
  84. package/esm/Plugins/Emitters/EmitterInstance.d.ts +6 -3
  85. package/esm/Plugins/Emitters/EmitterInstance.js +46 -16
  86. package/esm/Plugins/Emitters/Emitters.d.ts +3 -1
  87. package/esm/Plugins/Emitters/Emitters.js +17 -2
  88. package/{browser/Plugins/Emitters/EmittersMain.d.ts → esm/Plugins/Emitters/EmittersEngine.d.ts} +3 -1
  89. package/esm/Plugins/Emitters/{EmittersMain.js → EmittersEngine.js} +0 -0
  90. package/esm/Plugins/Emitters/IEmitterShape.d.ts +2 -2
  91. package/esm/Plugins/Emitters/Options/Classes/Emitter.d.ts +1 -0
  92. package/esm/Plugins/Emitters/Options/Classes/Emitter.js +1 -0
  93. package/esm/Plugins/Emitters/Options/Interfaces/IEmitter.d.ts +1 -0
  94. package/esm/Plugins/Emitters/ShapeManager.d.ts +6 -3
  95. package/esm/Plugins/Emitters/ShapeManager.js +16 -4
  96. package/esm/Plugins/Emitters/Shapes/Circle/CircleShape.d.ts +2 -2
  97. package/esm/Plugins/Emitters/Shapes/Circle/CircleShape.js +2 -2
  98. package/esm/Plugins/Emitters/Shapes/Square/SquareShape.d.ts +2 -2
  99. package/esm/Plugins/Emitters/Shapes/Square/SquareShape.js +4 -4
  100. package/esm/Plugins/Emitters/index.d.ts +3 -3
  101. package/esm/Plugins/Emitters/index.js +25 -6
  102. package/esm/engine.d.ts +3 -0
  103. package/esm/engine.js +20 -16
  104. package/package.json +11 -6
  105. package/report.html +2 -2
  106. package/report.slim.html +2 -2
  107. package/tsparticles.engine.js +227 -118
  108. package/tsparticles.engine.min.js +2 -2
  109. package/tsparticles.interaction.external.attract.js +205 -100
  110. package/tsparticles.interaction.external.attract.min.js +2 -2
  111. package/tsparticles.interaction.external.bounce.js +205 -100
  112. package/tsparticles.interaction.external.bounce.min.js +2 -2
  113. package/tsparticles.interaction.external.bubble.js +205 -100
  114. package/tsparticles.interaction.external.bubble.min.js +2 -2
  115. package/tsparticles.interaction.external.connect.js +205 -100
  116. package/tsparticles.interaction.external.connect.min.js +2 -2
  117. package/tsparticles.interaction.external.grab.js +205 -100
  118. package/tsparticles.interaction.external.grab.min.js +2 -2
  119. package/tsparticles.interaction.external.repulse.js +205 -100
  120. package/tsparticles.interaction.external.repulse.min.js +2 -2
  121. package/tsparticles.interaction.external.trail.js +205 -100
  122. package/tsparticles.interaction.external.trail.min.js +2 -2
  123. package/tsparticles.interaction.particles.attract.js +205 -100
  124. package/tsparticles.interaction.particles.attract.min.js +2 -2
  125. package/tsparticles.interaction.particles.collisions.js +205 -100
  126. package/tsparticles.interaction.particles.collisions.min.js +2 -2
  127. package/tsparticles.interaction.particles.links.js +205 -100
  128. package/tsparticles.interaction.particles.links.min.js +2 -2
  129. package/tsparticles.js +347 -156
  130. package/tsparticles.min.js +2 -2
  131. package/tsparticles.pathseg.min.js +1 -1
  132. package/tsparticles.plugins.absorbers.js +205 -100
  133. package/tsparticles.plugins.absorbers.min.js +2 -2
  134. package/tsparticles.plugins.emitters.js +330 -143
  135. package/tsparticles.plugins.emitters.min.js +2 -2
  136. package/tsparticles.plugins.polygonMask.js +205 -100
  137. package/tsparticles.plugins.polygonMask.min.js +2 -2
  138. package/tsparticles.shape.circle.min.js +1 -1
  139. package/tsparticles.shape.image.js +208 -103
  140. package/tsparticles.shape.image.min.js +2 -2
  141. package/tsparticles.shape.line.min.js +1 -1
  142. package/tsparticles.shape.polygon.min.js +1 -1
  143. package/tsparticles.shape.square.min.js +1 -1
  144. package/tsparticles.shape.star.min.js +1 -1
  145. package/tsparticles.shape.text.js +205 -100
  146. package/tsparticles.shape.text.min.js +2 -2
  147. package/tsparticles.slim.js +227 -118
  148. package/tsparticles.slim.min.js +2 -2
  149. package/tsparticles.updater.angle.js +205 -100
  150. package/tsparticles.updater.angle.min.js +2 -2
  151. package/tsparticles.updater.color.js +205 -100
  152. package/tsparticles.updater.color.min.js +2 -2
  153. package/tsparticles.updater.life.js +205 -100
  154. package/tsparticles.updater.life.min.js +2 -2
  155. package/tsparticles.updater.opacity.js +205 -100
  156. package/tsparticles.updater.opacity.min.js +2 -2
  157. package/tsparticles.updater.outModes.js +205 -100
  158. package/tsparticles.updater.outModes.min.js +2 -2
  159. package/tsparticles.updater.roll.js +205 -100
  160. package/tsparticles.updater.roll.min.js +2 -2
  161. package/tsparticles.updater.size.js +205 -100
  162. package/tsparticles.updater.size.min.js +2 -2
  163. package/tsparticles.updater.strokeColor.js +205 -100
  164. package/tsparticles.updater.strokeColor.min.js +2 -2
  165. package/tsparticles.updater.tilt.js +205 -100
  166. package/tsparticles.updater.tilt.min.js +2 -2
  167. package/tsparticles.updater.wobble.js +205 -100
  168. package/tsparticles.updater.wobble.min.js +2 -2
@@ -1,5 +1,5 @@
1
1
  export class CircleShape {
2
- randomPosition(position, offset, fill) {
2
+ randomPosition(position, size, fill) {
3
3
  const generateTheta = (x, y) => {
4
4
  const u = Math.random() / 4.0;
5
5
  const theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u));
@@ -18,7 +18,7 @@ export class CircleShape {
18
18
  }
19
19
  };
20
20
  const radius = (x, y, theta) => (x * y) / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2);
21
- const [a, b] = [offset.x / 2, offset.y / 2];
21
+ const [a, b] = [size.width / 2, size.height / 2];
22
22
  const randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt(Math.random()) : maxRadius;
23
23
  return {
24
24
  x: position.x + randomRadius * Math.cos(randomTheta),
@@ -1,5 +1,5 @@
1
- import type { ICoordinates } from "../../../../Core";
1
+ import type { ICoordinates, IDimension } from "../../../../Core";
2
2
  import type { IEmitterShape } from "../../IEmitterShape";
3
3
  export declare class SquareShape implements IEmitterShape {
4
- randomPosition(position: ICoordinates, offset: ICoordinates, fill: boolean): ICoordinates;
4
+ randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
5
5
  }
@@ -2,15 +2,15 @@ function randomSquareCoordinate(position, offset) {
2
2
  return position + offset * (Math.random() - 0.5);
3
3
  }
4
4
  export class SquareShape {
5
- randomPosition(position, offset, fill) {
5
+ randomPosition(position, size, fill) {
6
6
  if (fill) {
7
7
  return {
8
- x: randomSquareCoordinate(position.x, offset.x),
9
- y: randomSquareCoordinate(position.y, offset.y),
8
+ x: randomSquareCoordinate(position.x, size.width),
9
+ y: randomSquareCoordinate(position.y, size.height),
10
10
  };
11
11
  }
12
12
  else {
13
- const halfW = offset.x / 2, halfH = offset.y / 2, side = Math.floor(Math.random() * 4), v = (Math.random() - 0.5) * 2;
13
+ const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor(Math.random() * 4), v = (Math.random() - 0.5) * 2;
14
14
  switch (side) {
15
15
  case 0:
16
16
  // top-left
@@ -1,3 +1,3 @@
1
- import { EmittersMain } from "./EmittersMain";
2
- export declare function loadEmittersPlugin(engine: EmittersMain): Promise<void>;
3
- export * from "./EmittersMain";
1
+ import { EmittersEngine } from "./EmittersEngine";
2
+ export declare function loadEmittersPlugin(engine: EmittersEngine): Promise<void>;
3
+ export * from "./EmittersEngine";
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _EmittersPlugin_engine;
1
13
  import { CircleShape } from "./Shapes/Circle/CircleShape";
2
14
  import { Emitter } from "./Options/Classes/Emitter";
3
15
  import { Emitters } from "./Emitters";
@@ -8,11 +20,13 @@ import { isInArray } from "../../Utils";
8
20
  * @category Emitters Plugin
9
21
  */
10
22
  class EmittersPlugin {
11
- constructor() {
23
+ constructor(engine) {
24
+ _EmittersPlugin_engine.set(this, void 0);
25
+ __classPrivateFieldSet(this, _EmittersPlugin_engine, engine, "f");
12
26
  this.id = "emitters";
13
27
  }
14
28
  getPlugin(container) {
15
- return new Emitters(container);
29
+ return new Emitters(__classPrivateFieldGet(this, _EmittersPlugin_engine, "f"), container);
16
30
  }
17
31
  needsPlugin(options) {
18
32
  var _a, _b, _c;
@@ -66,15 +80,20 @@ class EmittersPlugin {
66
80
  }
67
81
  }
68
82
  }
83
+ _EmittersPlugin_engine = new WeakMap();
69
84
  export async function loadEmittersPlugin(engine) {
70
- const plugin = new EmittersPlugin();
71
- await engine.addPlugin(plugin);
85
+ if (!engine.emitterShapeManager) {
86
+ engine.emitterShapeManager = new ShapeManager(engine);
87
+ }
72
88
  if (!engine.addEmitterShape) {
73
89
  engine.addEmitterShape = (name, shape) => {
74
- ShapeManager.addShape(name, shape);
90
+ var _a;
91
+ (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
75
92
  };
76
93
  }
94
+ const plugin = new EmittersPlugin(engine);
95
+ await engine.addPlugin(plugin);
77
96
  engine.addEmitterShape("circle" /* circle */, new CircleShape());
78
97
  engine.addEmitterShape("square" /* square */, new SquareShape());
79
98
  }
80
- export * from "./EmittersMain";
99
+ export * from "./EmittersEngine";
@@ -1,13 +1,17 @@
1
1
  import type { Container, IInteractor, IMovePathGenerator, IParticleUpdater, IPlugin, IShapeDrawer, Particle } from "./Core";
2
+ import { Plugins } from "./Core";
2
3
  import type { RecursivePartial, ShapeDrawerAfterEffectFunction, ShapeDrawerDestroyFunction, ShapeDrawerDrawFunction, ShapeDrawerInitFunction, SingleOrMultiple } from "./Types";
3
4
  import type { IOptions } from "./Options/Interfaces/IOptions";
4
5
  /**
5
6
  * Engine class for creating the singleton on window.
6
- * It's a singleton proxy to the static [[Loader]] class for initializing [[Container]] instances
7
+ * It's a singleton proxy to the Loader class for initializing [[Container]] instances,
8
+ * and for Plugins class responsible for every external feature
7
9
  * @category Engine
8
10
  */
9
11
  export declare class Engine {
10
12
  #private;
13
+ readonly domArray: Container[];
14
+ readonly plugins: Plugins;
11
15
  constructor();
12
16
  /**
13
17
  * init method, used by imports
package/browser/engine.js CHANGED
@@ -9,17 +9,22 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Engine_initialized;
12
+ var _Engine_initialized, _Engine_loader;
13
13
  import { Loader, Plugins } from "./Core";
14
14
  /**
15
15
  * Engine class for creating the singleton on window.
16
- * It's a singleton proxy to the static [[Loader]] class for initializing [[Container]] instances
16
+ * It's a singleton proxy to the Loader class for initializing [[Container]] instances,
17
+ * and for Plugins class responsible for every external feature
17
18
  * @category Engine
18
19
  */
19
20
  export class Engine {
20
21
  constructor() {
21
22
  _Engine_initialized.set(this, void 0);
23
+ _Engine_loader.set(this, void 0);
22
24
  __classPrivateFieldSet(this, _Engine_initialized, false, "f");
25
+ this.domArray = [];
26
+ __classPrivateFieldSet(this, _Engine_loader, new Loader(this), "f");
27
+ this.plugins = new Plugins(this);
23
28
  }
24
29
  /**
25
30
  * init method, used by imports
@@ -37,7 +42,7 @@ export class Engine {
37
42
  * @returns A Promise with the [[Container]] object created
38
43
  */
39
44
  async loadFromArray(tagId, options, index) {
40
- return Loader.load(tagId, options, index);
45
+ return __classPrivateFieldGet(this, _Engine_loader, "f").load(tagId, options, index);
41
46
  }
42
47
  /**
43
48
  * Loads the provided options to create a [[Container]] object.
@@ -46,7 +51,7 @@ export class Engine {
46
51
  * @returns A Promise with the [[Container]] object created
47
52
  */
48
53
  async load(tagId, options) {
49
- return Loader.load(tagId, options);
54
+ return __classPrivateFieldGet(this, _Engine_loader, "f").load(tagId, options);
50
55
  }
51
56
  /**
52
57
  * Loads the provided option to create a [[Container]] object using the element parameter as a container
@@ -55,7 +60,7 @@ export class Engine {
55
60
  * @param options The options object to initialize the [[Container]]
56
61
  */
57
62
  async set(id, element, options) {
58
- return Loader.set(id, element, options);
63
+ return __classPrivateFieldGet(this, _Engine_loader, "f").set(id, element, options);
59
64
  }
60
65
  /**
61
66
  * Loads the provided json with a GET request. The content will be used to create a [[Container]] object.
@@ -66,7 +71,7 @@ export class Engine {
66
71
  * @returns A Promise with the [[Container]] object created
67
72
  */
68
73
  async loadJSON(tagId, pathConfigJson, index) {
69
- return Loader.loadJSON(tagId, pathConfigJson, index);
74
+ return __classPrivateFieldGet(this, _Engine_loader, "f").loadJSON(tagId, pathConfigJson, index);
70
75
  }
71
76
  /**
72
77
  * Loads the provided option to create a [[Container]] object using the element parameter as a container
@@ -77,21 +82,21 @@ export class Engine {
77
82
  * @returns A Promise with the [[Container]] object created
78
83
  */
79
84
  async setJSON(id, element, pathConfigJson, index) {
80
- return Loader.setJSON(id, element, pathConfigJson, index);
85
+ return __classPrivateFieldGet(this, _Engine_loader, "f").setJSON(id, element, pathConfigJson, index);
81
86
  }
82
87
  /**
83
88
  * Adds an additional click handler to all the loaded [[Container]] objects.
84
89
  * @param callback The function called after the click event is fired
85
90
  */
86
91
  setOnClickHandler(callback) {
87
- Loader.setOnClickHandler(callback);
92
+ __classPrivateFieldGet(this, _Engine_loader, "f").setOnClickHandler(callback);
88
93
  }
89
94
  /**
90
95
  * All the [[Container]] objects loaded
91
96
  * @returns All the [[Container]] objects loaded
92
97
  */
93
98
  dom() {
94
- return Loader.dom();
99
+ return __classPrivateFieldGet(this, _Engine_loader, "f").dom();
95
100
  }
96
101
  /**
97
102
  * Retrieves a [[Container]] from all the objects loaded
@@ -99,7 +104,7 @@ export class Engine {
99
104
  * @returns The [[Container]] object at specified index, if present or not destroyed, otherwise undefined
100
105
  */
101
106
  domItem(index) {
102
- return Loader.domItem(index);
107
+ return __classPrivateFieldGet(this, _Engine_loader, "f").domItem(index);
103
108
  }
104
109
  /**
105
110
  * Reloads all existing tsParticles loaded instances
@@ -130,7 +135,7 @@ export class Engine {
130
135
  else {
131
136
  customDrawer = drawer;
132
137
  }
133
- Plugins.addShapeDrawer(shape, customDrawer);
138
+ this.plugins.addShapeDrawer(shape, customDrawer);
134
139
  await this.refresh();
135
140
  }
136
141
  /**
@@ -140,7 +145,7 @@ export class Engine {
140
145
  * @param override if true, the preset will override any existing with the same name
141
146
  */
142
147
  async addPreset(preset, options, override = false) {
143
- Plugins.addPreset(preset, options, override);
148
+ this.plugins.addPreset(preset, options, override);
144
149
  await this.refresh();
145
150
  }
146
151
  /**
@@ -148,7 +153,7 @@ export class Engine {
148
153
  * @param plugin the plugin implementation of [[IPlugin]]
149
154
  */
150
155
  async addPlugin(plugin) {
151
- Plugins.addPlugin(plugin);
156
+ this.plugins.addPlugin(plugin);
152
157
  await this.refresh();
153
158
  }
154
159
  /**
@@ -157,7 +162,7 @@ export class Engine {
157
162
  * @param generator the path generator object
158
163
  */
159
164
  async addPathGenerator(name, generator) {
160
- Plugins.addPathGenerator(name, generator);
165
+ this.plugins.addPathGenerator(name, generator);
161
166
  await this.refresh();
162
167
  }
163
168
  /**
@@ -166,7 +171,7 @@ export class Engine {
166
171
  * @param interactorInitializer
167
172
  */
168
173
  async addInteractor(name, interactorInitializer) {
169
- Plugins.addInteractor(name, interactorInitializer);
174
+ this.plugins.addInteractor(name, interactorInitializer);
170
175
  await this.refresh();
171
176
  }
172
177
  /**
@@ -175,8 +180,8 @@ export class Engine {
175
180
  * @param updaterInitializer
176
181
  */
177
182
  async addParticleUpdater(name, updaterInitializer) {
178
- Plugins.addParticleUpdater(name, updaterInitializer);
183
+ this.plugins.addParticleUpdater(name, updaterInitializer);
179
184
  await this.refresh();
180
185
  }
181
186
  }
182
- _Engine_initialized = new WeakMap();
187
+ _Engine_initialized = new WeakMap(), _Engine_loader = new WeakMap();
package/engine.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import type { Container, IInteractor, IMovePathGenerator, IParticleUpdater, IPlugin, IShapeDrawer, Particle } from "./Core";
2
+ import { Plugins } from "./Core";
2
3
  import type { RecursivePartial, ShapeDrawerAfterEffectFunction, ShapeDrawerDestroyFunction, ShapeDrawerDrawFunction, ShapeDrawerInitFunction, SingleOrMultiple } from "./Types";
3
4
  import type { IOptions } from "./Options/Interfaces/IOptions";
4
5
  export declare class Engine {
5
6
  #private;
7
+ readonly domArray: Container[];
8
+ readonly plugins: Plugins;
6
9
  constructor();
7
10
  init(): void;
8
11
  loadFromArray(tagId: string, options: RecursivePartial<IOptions>[], index?: number): Promise<Container | undefined>;
package/engine.js CHANGED
@@ -10,14 +10,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Engine_initialized;
13
+ var _Engine_initialized, _Engine_loader;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Engine = void 0;
16
16
  const Core_1 = require("./Core");
17
17
  class Engine {
18
18
  constructor() {
19
19
  _Engine_initialized.set(this, void 0);
20
+ _Engine_loader.set(this, void 0);
20
21
  __classPrivateFieldSet(this, _Engine_initialized, false, "f");
22
+ this.domArray = [];
23
+ __classPrivateFieldSet(this, _Engine_loader, new Core_1.Loader(this), "f");
24
+ this.plugins = new Core_1.Plugins(this);
21
25
  }
22
26
  init() {
23
27
  if (!__classPrivateFieldGet(this, _Engine_initialized, "f")) {
@@ -25,28 +29,28 @@ class Engine {
25
29
  }
26
30
  }
27
31
  async loadFromArray(tagId, options, index) {
28
- return Core_1.Loader.load(tagId, options, index);
32
+ return __classPrivateFieldGet(this, _Engine_loader, "f").load(tagId, options, index);
29
33
  }
30
34
  async load(tagId, options) {
31
- return Core_1.Loader.load(tagId, options);
35
+ return __classPrivateFieldGet(this, _Engine_loader, "f").load(tagId, options);
32
36
  }
33
37
  async set(id, element, options) {
34
- return Core_1.Loader.set(id, element, options);
38
+ return __classPrivateFieldGet(this, _Engine_loader, "f").set(id, element, options);
35
39
  }
36
40
  async loadJSON(tagId, pathConfigJson, index) {
37
- return Core_1.Loader.loadJSON(tagId, pathConfigJson, index);
41
+ return __classPrivateFieldGet(this, _Engine_loader, "f").loadJSON(tagId, pathConfigJson, index);
38
42
  }
39
43
  async setJSON(id, element, pathConfigJson, index) {
40
- return Core_1.Loader.setJSON(id, element, pathConfigJson, index);
44
+ return __classPrivateFieldGet(this, _Engine_loader, "f").setJSON(id, element, pathConfigJson, index);
41
45
  }
42
46
  setOnClickHandler(callback) {
43
- Core_1.Loader.setOnClickHandler(callback);
47
+ __classPrivateFieldGet(this, _Engine_loader, "f").setOnClickHandler(callback);
44
48
  }
45
49
  dom() {
46
- return Core_1.Loader.dom();
50
+ return __classPrivateFieldGet(this, _Engine_loader, "f").dom();
47
51
  }
48
52
  domItem(index) {
49
- return Core_1.Loader.domItem(index);
53
+ return __classPrivateFieldGet(this, _Engine_loader, "f").domItem(index);
50
54
  }
51
55
  async refresh() {
52
56
  for (const instance of this.dom()) {
@@ -66,29 +70,29 @@ class Engine {
66
70
  else {
67
71
  customDrawer = drawer;
68
72
  }
69
- Core_1.Plugins.addShapeDrawer(shape, customDrawer);
73
+ this.plugins.addShapeDrawer(shape, customDrawer);
70
74
  await this.refresh();
71
75
  }
72
76
  async addPreset(preset, options, override = false) {
73
- Core_1.Plugins.addPreset(preset, options, override);
77
+ this.plugins.addPreset(preset, options, override);
74
78
  await this.refresh();
75
79
  }
76
80
  async addPlugin(plugin) {
77
- Core_1.Plugins.addPlugin(plugin);
81
+ this.plugins.addPlugin(plugin);
78
82
  await this.refresh();
79
83
  }
80
84
  async addPathGenerator(name, generator) {
81
- Core_1.Plugins.addPathGenerator(name, generator);
85
+ this.plugins.addPathGenerator(name, generator);
82
86
  await this.refresh();
83
87
  }
84
88
  async addInteractor(name, interactorInitializer) {
85
- Core_1.Plugins.addInteractor(name, interactorInitializer);
89
+ this.plugins.addInteractor(name, interactorInitializer);
86
90
  await this.refresh();
87
91
  }
88
92
  async addParticleUpdater(name, updaterInitializer) {
89
- Core_1.Plugins.addParticleUpdater(name, updaterInitializer);
93
+ this.plugins.addParticleUpdater(name, updaterInitializer);
90
94
  await this.refresh();
91
95
  }
92
96
  }
93
97
  exports.Engine = Engine;
94
- _Engine_initialized = new WeakMap();
98
+ _Engine_initialized = new WeakMap(), _Engine_loader = new WeakMap();
@@ -1,6 +1,7 @@
1
1
  import { FrameManager, Vector } from "./Utils";
2
2
  import type { IAttract, IBubble, IContainerInteractivity, IContainerPlugin, IMovePathGenerator, IRepulse, IShapeDrawer } from "./Interfaces";
3
3
  import { Canvas } from "./Canvas";
4
+ import type { Engine } from "../engine";
4
5
  import type { IOptions } from "../Options/Interfaces/IOptions";
5
6
  import { Options } from "../Options/Classes/Options";
6
7
  import { Particle } from "./Particle";
@@ -8,6 +9,7 @@ import { Particles } from "./Particles";
8
9
  import type { RecursivePartial } from "../Types";
9
10
  import { Retina } from "./Retina";
10
11
  export declare class Container {
12
+ #private;
11
13
  readonly id: string;
12
14
  started: boolean;
13
15
  destroyed: boolean;
@@ -43,7 +45,7 @@ export declare class Container {
43
45
  private readonly presets;
44
46
  private readonly eventListeners;
45
47
  private readonly intersectionObserver?;
46
- constructor(id: string, sourceOptions?: RecursivePartial<IOptions>, ...presets: string[]);
48
+ constructor(engine: Engine, id: string, sourceOptions?: RecursivePartial<IOptions>, ...presets: string[]);
47
49
  play(force?: boolean): void;
48
50
  pause(): void;
49
51
  draw(force: boolean): void;
@@ -1,13 +1,27 @@
1
- import { EventListeners, FrameManager, Plugins, Vector } from "./Utils";
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Container_engine;
13
+ import { EventListeners, FrameManager, Vector } from "./Utils";
2
14
  import { animate, cancelAnimation, getRangeValue } from "../Utils";
3
15
  import { Canvas } from "./Canvas";
4
16
  import { Options } from "../Options/Classes/Options";
5
17
  import { Particles } from "./Particles";
6
18
  import { Retina } from "./Retina";
7
19
  export class Container {
8
- constructor(id, sourceOptions, ...presets) {
20
+ constructor(engine, id, sourceOptions, ...presets) {
9
21
  this.id = id;
10
- this.fpsLimit = 60;
22
+ _Container_engine.set(this, void 0);
23
+ __classPrivateFieldSet(this, _Container_engine, engine, "f");
24
+ this.fpsLimit = 120;
11
25
  this.duration = 0;
12
26
  this.lifeTime = 0;
13
27
  this.firstStart = true;
@@ -21,7 +35,7 @@ export class Container {
21
35
  this._initialSourceOptions = sourceOptions;
22
36
  this.retina = new Retina(this);
23
37
  this.canvas = new Canvas(this);
24
- this.particles = new Particles(this);
38
+ this.particles = new Particles(__classPrivateFieldGet(this, _Container_engine, "f"), this);
25
39
  this.drawer = new FrameManager(this);
26
40
  this.presets = presets;
27
41
  this.pathGenerator = {
@@ -48,8 +62,8 @@ export class Container {
48
62
  this.plugins = new Map();
49
63
  this.drawers = new Map();
50
64
  this.density = 1;
51
- this._options = new Options();
52
- this.actualOptions = new Options();
65
+ this._options = new Options(__classPrivateFieldGet(this, _Container_engine, "f"));
66
+ this.actualOptions = new Options(__classPrivateFieldGet(this, _Container_engine, "f"));
53
67
  this.eventListeners = new EventListeners(this);
54
68
  if (typeof IntersectionObserver !== "undefined" && IntersectionObserver) {
55
69
  this.intersectionObserver = new IntersectionObserver((entries) => this.intersectionManager(entries));
@@ -165,7 +179,7 @@ export class Container {
165
179
  return this.start();
166
180
  }
167
181
  reset() {
168
- this._options = new Options();
182
+ this._options = new Options(__classPrivateFieldGet(this, _Container_engine, "f"));
169
183
  return this.refresh();
170
184
  }
171
185
  stop() {
@@ -179,7 +193,7 @@ export class Container {
179
193
  this.particles.clear();
180
194
  this.canvas.clear();
181
195
  if (this.interactivity.element instanceof HTMLElement && this.intersectionObserver) {
182
- this.intersectionObserver.observe(this.interactivity.element);
196
+ this.intersectionObserver.unobserve(this.interactivity.element);
183
197
  }
184
198
  for (const [, plugin] of this.plugins) {
185
199
  if (plugin.stop) {
@@ -307,20 +321,20 @@ export class Container {
307
321
  return false;
308
322
  }
309
323
  async init() {
310
- this._options = new Options();
324
+ this._options = new Options(__classPrivateFieldGet(this, _Container_engine, "f"));
311
325
  for (const preset of this.presets) {
312
- this._options.load(Plugins.getPreset(preset));
326
+ this._options.load(__classPrivateFieldGet(this, _Container_engine, "f").plugins.getPreset(preset));
313
327
  }
314
- const shapes = Plugins.getSupportedShapes();
328
+ const shapes = __classPrivateFieldGet(this, _Container_engine, "f").plugins.getSupportedShapes();
315
329
  for (const type of shapes) {
316
- const drawer = Plugins.getShapeDrawer(type);
330
+ const drawer = __classPrivateFieldGet(this, _Container_engine, "f").plugins.getShapeDrawer(type);
317
331
  if (drawer) {
318
332
  this.drawers.set(type, drawer);
319
333
  }
320
334
  }
321
335
  this._options.load(this._initialSourceOptions);
322
336
  this._options.load(this._sourceOptions);
323
- this.actualOptions = new Options();
337
+ this.actualOptions = new Options(__classPrivateFieldGet(this, _Container_engine, "f"));
324
338
  this.actualOptions.load(this._options);
325
339
  this.retina.init();
326
340
  this.canvas.init();
@@ -330,8 +344,8 @@ export class Container {
330
344
  this.zLayers = this.actualOptions.zLayers;
331
345
  this.duration = getRangeValue(this.actualOptions.duration);
332
346
  this.lifeTime = 0;
333
- this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 60;
334
- const availablePlugins = Plugins.getAvailablePlugins(this);
347
+ this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
348
+ const availablePlugins = __classPrivateFieldGet(this, _Container_engine, "f").plugins.getAvailablePlugins(this);
335
349
  for (const [id, plugin] of availablePlugins) {
336
350
  this.plugins.set(id, plugin);
337
351
  }
@@ -350,7 +364,7 @@ export class Container {
350
364
  }
351
365
  const pathOptions = this.actualOptions.particles.move.path;
352
366
  if (pathOptions.generator) {
353
- const customGenerator = Plugins.getPathGenerator(pathOptions.generator);
367
+ const customGenerator = __classPrivateFieldGet(this, _Container_engine, "f").plugins.getPathGenerator(pathOptions.generator);
354
368
  if (customGenerator) {
355
369
  if (customGenerator.init) {
356
370
  this.pathGenerator.init = customGenerator.init;
@@ -388,3 +402,4 @@ export class Container {
388
402
  }
389
403
  }
390
404
  }
405
+ _Container_engine = new WeakMap();
@@ -1,4 +1,5 @@
1
1
  import { Container } from "./Container";
2
+ import type { Engine } from "../engine";
2
3
  import type { IOptions } from "../Options/Interfaces/IOptions";
3
4
  import type { Particle } from "./Particle";
4
5
  import type { RecursivePartial } from "../Types";
@@ -16,14 +17,16 @@ interface RemoteLoaderParams {
16
17
  url?: SingleOrMultiple<string>;
17
18
  }
18
19
  export declare class Loader {
19
- static dom(): Container[];
20
- static domItem(index: number): Container | undefined;
21
- static loadOptions(params: LoaderParams): Promise<Container | undefined>;
22
- static loadRemoteOptions(params: RemoteLoaderParams): Promise<Container | undefined>;
23
- static load(tagId: string | SingleOrMultiple<RecursivePartial<IOptions>>, options?: SingleOrMultiple<RecursivePartial<IOptions>> | number, index?: number): Promise<Container | undefined>;
24
- static set(id: string | HTMLElement, domContainer: HTMLElement | SingleOrMultiple<RecursivePartial<IOptions>>, options?: SingleOrMultiple<RecursivePartial<IOptions>> | number, index?: number): Promise<Container | undefined>;
25
- static loadJSON(tagId: string | SingleOrMultiple<string>, jsonUrl?: SingleOrMultiple<string> | number, index?: number): Promise<Container | undefined>;
26
- static setJSON(id: string | HTMLElement, domContainer: HTMLElement | SingleOrMultiple<string>, jsonUrl: SingleOrMultiple<string> | (number | undefined), index?: number): Promise<Container | undefined>;
27
- static setOnClickHandler(callback: (evt: Event, particles?: Particle[]) => void): void;
20
+ #private;
21
+ constructor(engine: Engine);
22
+ dom(): Container[];
23
+ domItem(index: number): Container | undefined;
24
+ loadOptions(params: LoaderParams): Promise<Container | undefined>;
25
+ loadRemoteOptions(params: RemoteLoaderParams): Promise<Container | undefined>;
26
+ load(tagId: string | SingleOrMultiple<RecursivePartial<IOptions>>, options?: SingleOrMultiple<RecursivePartial<IOptions>> | number, index?: number): Promise<Container | undefined>;
27
+ set(id: string | HTMLElement, domContainer: HTMLElement | SingleOrMultiple<RecursivePartial<IOptions>>, options?: SingleOrMultiple<RecursivePartial<IOptions>> | number, index?: number): Promise<Container | undefined>;
28
+ loadJSON(tagId: string | SingleOrMultiple<string>, jsonUrl?: SingleOrMultiple<string> | number, index?: number): Promise<Container | undefined>;
29
+ setJSON(id: string | HTMLElement, domContainer: HTMLElement | SingleOrMultiple<string>, jsonUrl: SingleOrMultiple<string> | (number | undefined), index?: number): Promise<Container | undefined>;
30
+ setOnClickHandler(callback: (evt: Event, particles?: Particle[]) => void): void;
28
31
  }
29
32
  export {};