@tsparticles/plugin-emitters 3.0.0-alpha.1 → 3.0.0-beta.1

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 (47) hide show
  1. package/README.md +15 -11
  2. package/browser/EmitterInstance.js +101 -113
  3. package/browser/Emitters.js +31 -27
  4. package/browser/Options/Classes/Emitter.js +6 -6
  5. package/browser/Options/Classes/EmitterLife.js +4 -3
  6. package/browser/index.js +23 -26
  7. package/browser/package.json +1 -0
  8. package/cjs/EmitterInstance.js +102 -114
  9. package/cjs/Emitters.js +41 -48
  10. package/cjs/Options/Classes/Emitter.js +8 -8
  11. package/cjs/Options/Classes/EmitterLife.js +4 -3
  12. package/cjs/Shapes/Circle/CircleShape.js +1 -1
  13. package/cjs/index.js +38 -52
  14. package/cjs/package.json +1 -0
  15. package/esm/EmitterInstance.js +101 -113
  16. package/esm/Emitters.js +31 -27
  17. package/esm/Options/Classes/Emitter.js +6 -6
  18. package/esm/Options/Classes/EmitterLife.js +4 -3
  19. package/esm/index.js +23 -26
  20. package/esm/package.json +1 -0
  21. package/package.json +19 -6
  22. package/report.html +4 -4
  23. package/tsparticles.plugin.emitters.js +137 -145
  24. package/tsparticles.plugin.emitters.min.js +1 -1
  25. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -8
  26. package/types/EmitterContainer.d.ts +3 -3
  27. package/types/EmitterInstance.d.ts +12 -12
  28. package/types/Emitters.d.ts +7 -7
  29. package/types/EmittersEngine.d.ts +2 -2
  30. package/types/Enums/EmitterShapeType.d.ts +3 -1
  31. package/types/Options/Classes/Emitter.d.ts +6 -7
  32. package/types/Options/Classes/EmitterLife.d.ts +4 -4
  33. package/types/Options/Classes/EmitterRate.d.ts +2 -2
  34. package/types/Options/Classes/EmitterSize.d.ts +3 -4
  35. package/types/Options/Interfaces/IEmitter.d.ts +4 -4
  36. package/types/Options/Interfaces/IEmitterLife.d.ts +3 -2
  37. package/types/Options/Interfaces/IEmitterSize.d.ts +2 -2
  38. package/types/ShapeManager.d.ts +1 -1
  39. package/types/Shapes/Circle/CircleShape.d.ts +2 -2
  40. package/types/Shapes/Square/SquareShape.d.ts +2 -2
  41. package/types/index.d.ts +6 -6
  42. package/types/types.d.ts +2 -2
  43. package/umd/EmitterInstance.js +103 -115
  44. package/umd/Emitters.js +33 -29
  45. package/umd/Options/Classes/Emitter.js +9 -9
  46. package/umd/Options/Classes/EmitterLife.js +5 -4
  47. package/umd/index.js +32 -35
package/cjs/index.js CHANGED
@@ -13,53 +13,43 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
16
  Object.defineProperty(exports, "__esModule", { value: true });
26
17
  exports.loadEmittersPlugin = void 0;
27
18
  const engine_1 = require("@tsparticles/engine");
28
- const CircleShape_1 = require("./Shapes/Circle/CircleShape");
29
- const Emitter_1 = require("./Options/Classes/Emitter");
30
- const Emitters_1 = require("./Emitters");
31
- const ShapeManager_1 = require("./ShapeManager");
32
- const SquareShape_1 = require("./Shapes/Square/SquareShape");
19
+ const CircleShape_js_1 = require("./Shapes/Circle/CircleShape.js");
20
+ const Emitter_js_1 = require("./Options/Classes/Emitter.js");
21
+ const Emitters_js_1 = require("./Emitters.js");
22
+ const ShapeManager_js_1 = require("./ShapeManager.js");
23
+ const SquareShape_js_1 = require("./Shapes/Square/SquareShape.js");
33
24
  class EmittersPlugin {
34
25
  constructor(engine) {
35
26
  this._engine = engine;
36
27
  this.id = "emitters";
37
28
  }
38
29
  getPlugin(container) {
39
- return new Emitters_1.Emitters(this._engine, container);
30
+ return new Emitters_js_1.Emitters(this._engine, container);
40
31
  }
41
32
  loadOptions(options, source) {
42
- var _a, _b, _c, _d, _e, _f;
43
33
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
44
34
  return;
45
35
  }
46
- if (source === null || source === void 0 ? void 0 : source.emitters) {
36
+ if (source?.emitters) {
47
37
  options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
48
- const tmp = new Emitter_1.Emitter();
38
+ const tmp = new Emitter_js_1.Emitter();
49
39
  tmp.load(emitter);
50
40
  return tmp;
51
41
  });
52
42
  }
53
- const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
43
+ const interactivityEmitters = source?.interactivity?.modes?.emitters;
54
44
  if (interactivityEmitters) {
55
- if (interactivityEmitters instanceof Array) {
45
+ if ((0, engine_1.isArray)(interactivityEmitters)) {
56
46
  options.interactivity.modes.emitters = {
57
47
  random: {
58
48
  count: 1,
59
49
  enable: true,
60
50
  },
61
51
  value: interactivityEmitters.map((s) => {
62
- const tmp = new Emitter_1.Emitter();
52
+ const tmp = new Emitter_js_1.Emitter();
63
53
  tmp.load(s);
64
54
  return tmp;
65
55
  }),
@@ -68,26 +58,26 @@ class EmittersPlugin {
68
58
  else {
69
59
  const emitterMode = interactivityEmitters;
70
60
  if (emitterMode.value !== undefined) {
71
- if (emitterMode.value instanceof Array) {
61
+ if ((0, engine_1.isArray)(emitterMode.value)) {
72
62
  options.interactivity.modes.emitters = {
73
63
  random: {
74
- count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
75
- enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
64
+ count: emitterMode.random.count ?? 1,
65
+ enable: emitterMode.random.enable ?? false,
76
66
  },
77
67
  value: emitterMode.value.map((s) => {
78
- const tmp = new Emitter_1.Emitter();
68
+ const tmp = new Emitter_js_1.Emitter();
79
69
  tmp.load(s);
80
70
  return tmp;
81
71
  }),
82
72
  };
83
73
  }
84
74
  else {
85
- const tmp = new Emitter_1.Emitter();
75
+ const tmp = new Emitter_js_1.Emitter();
86
76
  tmp.load(emitterMode.value);
87
77
  options.interactivity.modes.emitters = {
88
78
  random: {
89
- count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
90
- enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
79
+ count: emitterMode.random.count ?? 1,
80
+ enable: emitterMode.random.enable ?? false,
91
81
  },
92
82
  value: tmp,
93
83
  };
@@ -99,7 +89,7 @@ class EmittersPlugin {
99
89
  count: 1,
100
90
  enable: false,
101
91
  },
102
- value: new Emitter_1.Emitter(),
92
+ value: new Emitter_js_1.Emitter(),
103
93
  });
104
94
  emitterOptions.value.load(interactivityEmitters);
105
95
  }
@@ -107,36 +97,32 @@ class EmittersPlugin {
107
97
  }
108
98
  }
109
99
  needsPlugin(options) {
110
- var _a, _b, _c;
111
100
  if (!options) {
112
101
  return false;
113
102
  }
114
103
  const emitters = options.emitters;
115
- return ((emitters instanceof Array && !!emitters.length) ||
104
+ return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
116
105
  emitters !== undefined ||
117
- (!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
106
+ (!!options.interactivity?.events?.onClick?.mode &&
118
107
  (0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
119
108
  }
120
109
  }
121
- function loadEmittersPlugin(engine) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- if (!engine.emitterShapeManager) {
124
- engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
125
- }
126
- if (!engine.addEmitterShape) {
127
- engine.addEmitterShape = (name, shape) => {
128
- var _a;
129
- (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
130
- };
131
- }
132
- const plugin = new EmittersPlugin(engine);
133
- yield engine.addPlugin(plugin);
134
- engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
135
- engine.addEmitterShape("square", new SquareShape_1.SquareShape());
136
- });
110
+ async function loadEmittersPlugin(engine, refresh = true) {
111
+ if (!engine.emitterShapeManager) {
112
+ engine.emitterShapeManager = new ShapeManager_js_1.ShapeManager(engine);
113
+ }
114
+ if (!engine.addEmitterShape) {
115
+ engine.addEmitterShape = (name, shape) => {
116
+ engine.emitterShapeManager?.addShape(name, shape);
117
+ };
118
+ }
119
+ const plugin = new EmittersPlugin(engine);
120
+ await engine.addPlugin(plugin, refresh);
121
+ engine.addEmitterShape("circle", new CircleShape_js_1.CircleShape());
122
+ engine.addEmitterShape("square", new SquareShape_js_1.SquareShape());
137
123
  }
138
124
  exports.loadEmittersPlugin = loadEmittersPlugin;
139
- __exportStar(require("./EmitterContainer"), exports);
140
- __exportStar(require("./EmittersEngine"), exports);
141
- __exportStar(require("./Enums/EmitterClickMode"), exports);
142
- __exportStar(require("./Enums/EmitterShapeType"), exports);
125
+ __exportStar(require("./EmitterContainer.js"), exports);
126
+ __exportStar(require("./EmittersEngine.js"), exports);
127
+ __exportStar(require("./Enums/EmitterClickMode.js"), exports);
128
+ __exportStar(require("./Enums/EmitterShapeType.js"), exports);
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -1,12 +1,79 @@
1
- import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
2
- import { Emitter } from "./Options/Classes/Emitter";
3
- import { EmitterSize } from "./Options/Classes/EmitterSize";
1
+ import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter.js";
3
+ import { EmitterSize } from "./Options/Classes/EmitterSize.js";
4
4
  export class EmitterInstance {
5
5
  constructor(engine, emitters, container, options, position) {
6
- var _a, _b, _c, _d, _e, _f, _g;
7
- var _h;
8
6
  this.emitters = emitters;
9
7
  this.container = container;
8
+ this._calcPosition = () => {
9
+ return calcPositionOrRandomFromSizeRanged({
10
+ size: this.container.canvas.size,
11
+ position: this.options.position,
12
+ });
13
+ };
14
+ this._destroy = () => {
15
+ this.emitters.removeEmitter(this);
16
+ this._engine.dispatchEvent("emitterDestroyed", {
17
+ container: this.container,
18
+ data: {
19
+ emitter: this,
20
+ },
21
+ });
22
+ };
23
+ this._emit = () => {
24
+ if (this._paused) {
25
+ return;
26
+ }
27
+ const quantity = getRangeValue(this.options.rate.quantity);
28
+ this._emitParticles(quantity);
29
+ };
30
+ this._emitParticles = (quantity) => {
31
+ const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
32
+ for (let i = 0; i < quantity; i++) {
33
+ const particlesOptions = deepExtend({}, singleParticlesOptions);
34
+ if (this.spawnColor) {
35
+ const hslAnimation = this.options.spawnColor?.animation;
36
+ if (hslAnimation) {
37
+ this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
38
+ this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
39
+ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
40
+ }
41
+ if (!particlesOptions.color) {
42
+ particlesOptions.color = {
43
+ value: this.spawnColor,
44
+ };
45
+ }
46
+ else {
47
+ particlesOptions.color.value = this.spawnColor;
48
+ }
49
+ }
50
+ if (!position) {
51
+ return;
52
+ }
53
+ const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
54
+ this.container.particles.addParticle(pPosition, particlesOptions);
55
+ }
56
+ };
57
+ this._prepareToDie = () => {
58
+ if (this._paused) {
59
+ return;
60
+ }
61
+ const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined;
62
+ if (this.container.retina.reduceFactor &&
63
+ (this._lifeCount > 0 || this._immortal) &&
64
+ duration !== undefined &&
65
+ duration > 0) {
66
+ this._duration = duration * 1000;
67
+ }
68
+ };
69
+ this._setColorAnimation = (animation, initValue, maxValue) => {
70
+ const container = this.container;
71
+ if (!animation.enable) {
72
+ return initValue;
73
+ }
74
+ const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue(animation.speed ?? 0);
75
+ return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
76
+ };
10
77
  this._engine = engine;
11
78
  this._currentDuration = 0;
12
79
  this._currentEmitDelay = 0;
@@ -19,33 +86,34 @@ export class EmitterInstance {
19
86
  this.options = new Emitter();
20
87
  this.options.load(options);
21
88
  }
22
- this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
23
- this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
89
+ this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
90
+ this.position = this._initialPosition ?? this._calcPosition();
24
91
  this.name = this.options.name;
25
- this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
92
+ this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
26
93
  this.fill = this.options.fill;
27
94
  this._firstSpawn = !this.options.life.wait;
28
95
  this._startParticlesAdded = false;
29
96
  let particlesOptions = deepExtend({}, this.options.particles);
30
- particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
31
- (_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
32
- (_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
97
+ particlesOptions ??= {};
98
+ particlesOptions.move ??= {};
99
+ particlesOptions.move.direction ??= this.options.direction;
33
100
  if (this.options.spawnColor) {
34
101
  this.spawnColor = rangeColorToHsl(this.options.spawnColor);
35
102
  }
36
103
  this._paused = !this.options.autoPlay;
37
104
  this._particlesOptions = particlesOptions;
38
105
  this.size =
39
- (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
40
- const size = new EmitterSize();
41
- size.load({
42
- height: 0,
43
- mode: "percent",
44
- width: 0,
45
- });
46
- return size;
47
- })();
48
- this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
106
+ this.options.size ??
107
+ (() => {
108
+ const size = new EmitterSize();
109
+ size.load({
110
+ height: 0,
111
+ mode: "percent",
112
+ width: 0,
113
+ });
114
+ return size;
115
+ })();
116
+ this._lifeCount = this.options.life.count ?? -1;
49
117
  this._immortal = this._lifeCount <= 0;
50
118
  this._engine.dispatchEvent("emitterCreated", {
51
119
  container,
@@ -88,14 +156,7 @@ export class EmitterInstance {
88
156
  };
89
157
  }
90
158
  }
91
- return {
92
- width: this.size.mode === "percent"
93
- ? (container.canvas.size.width * this.size.width) / 100
94
- : this.size.width,
95
- height: this.size.mode === "percent"
96
- ? (container.canvas.size.height * this.size.height) / 100
97
- : this.size.height,
98
- };
159
+ return getSize(this.size, container.canvas.size);
99
160
  }
100
161
  pause() {
101
162
  if (this._paused) {
@@ -104,13 +165,12 @@ export class EmitterInstance {
104
165
  delete this._emitDelay;
105
166
  }
106
167
  play() {
107
- var _a;
108
168
  if (this._paused) {
109
169
  return;
110
170
  }
111
171
  if (!(this.container.retina.reduceFactor &&
112
172
  (this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
113
- (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
173
+ (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
114
174
  return;
115
175
  }
116
176
  if (this._emitDelay === undefined) {
@@ -118,7 +178,7 @@ export class EmitterInstance {
118
178
  this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
119
179
  }
120
180
  if (this._lifeCount > 0 || this._immortal) {
121
- this.prepareToDie();
181
+ this._prepareToDie();
122
182
  }
123
183
  }
124
184
  resize() {
@@ -126,21 +186,20 @@ export class EmitterInstance {
126
186
  this.position =
127
187
  initialPosition && isPointInside(initialPosition, this.container.canvas.size, Vector.origin)
128
188
  ? initialPosition
129
- : this.calcPosition();
189
+ : this._calcPosition();
130
190
  }
131
191
  update(delta) {
132
- var _a, _b, _c;
133
192
  if (this._paused) {
134
193
  return;
135
194
  }
136
195
  if (this._firstSpawn) {
137
196
  this._firstSpawn = false;
138
- this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
139
- this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
197
+ this._currentSpawnDelay = this._spawnDelay ?? 0;
198
+ this._currentEmitDelay = this._emitDelay ?? 0;
140
199
  }
141
200
  if (!this._startParticlesAdded) {
142
201
  this._startParticlesAdded = true;
143
- this.emitParticles(this.options.startCount);
202
+ this._emitParticles(this.options.startCount);
144
203
  }
145
204
  if (this._duration !== undefined) {
146
205
  this._currentDuration += delta.value;
@@ -153,11 +212,12 @@ export class EmitterInstance {
153
212
  this._lifeCount--;
154
213
  }
155
214
  if (this._lifeCount > 0 || this._immortal) {
156
- this.position = this.calcPosition();
157
- this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
215
+ this.position = this._calcPosition();
216
+ this._spawnDelay =
217
+ (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
158
218
  }
159
219
  else {
160
- this.destroy();
220
+ this._destroy();
161
221
  }
162
222
  this._currentDuration -= this._duration;
163
223
  delete this._duration;
@@ -177,81 +237,9 @@ export class EmitterInstance {
177
237
  if (this._emitDelay !== undefined) {
178
238
  this._currentEmitDelay += delta.value;
179
239
  if (this._currentEmitDelay >= this._emitDelay) {
180
- this.emit();
240
+ this._emit();
181
241
  this._currentEmitDelay -= this._emitDelay;
182
242
  }
183
243
  }
184
244
  }
185
- calcPosition() {
186
- return calcPositionOrRandomFromSizeRanged({
187
- size: this.container.canvas.size,
188
- position: this.options.position,
189
- });
190
- }
191
- destroy() {
192
- this.emitters.removeEmitter(this);
193
- this._engine.dispatchEvent("emitterDestroyed", {
194
- container: this.container,
195
- data: {
196
- emitter: this,
197
- },
198
- });
199
- }
200
- emit() {
201
- if (this._paused) {
202
- return;
203
- }
204
- const quantity = getRangeValue(this.options.rate.quantity);
205
- this.emitParticles(quantity);
206
- }
207
- emitParticles(quantity) {
208
- var _a, _b, _c;
209
- const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
210
- for (let i = 0; i < quantity; i++) {
211
- const particlesOptions = deepExtend({}, singleParticlesOptions);
212
- if (this.spawnColor) {
213
- const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
214
- if (hslAnimation) {
215
- this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
216
- this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
217
- this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
218
- }
219
- if (!particlesOptions.color) {
220
- particlesOptions.color = {
221
- value: this.spawnColor,
222
- };
223
- }
224
- else {
225
- particlesOptions.color.value = this.spawnColor;
226
- }
227
- }
228
- if (!position) {
229
- return;
230
- }
231
- const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
232
- this.container.particles.addParticle(pPosition, particlesOptions);
233
- }
234
- }
235
- prepareToDie() {
236
- var _a;
237
- if (this._paused) {
238
- return;
239
- }
240
- const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
241
- if (this.container.retina.reduceFactor &&
242
- (this._lifeCount > 0 || this._immortal) &&
243
- duration !== undefined &&
244
- duration > 0) {
245
- this._duration = duration * 1000;
246
- }
247
- }
248
- setColorAnimation(animation, initValue, maxValue) {
249
- var _a;
250
- const container = this.container;
251
- if (!animation.enable) {
252
- return initValue;
253
- }
254
- const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
255
- return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
256
- }
257
245
  }
package/esm/Emitters.js CHANGED
@@ -1,6 +1,6 @@
1
- import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
2
- import { Emitter } from "./Options/Classes/Emitter";
3
- import { EmitterInstance } from "./EmitterInstance";
1
+ import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter.js";
3
+ import { EmitterInstance } from "./EmitterInstance.js";
4
4
  export class Emitters {
5
5
  constructor(engine, container) {
6
6
  this.container = container;
@@ -14,7 +14,7 @@ export class Emitters {
14
14
  },
15
15
  value: [],
16
16
  };
17
- container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
17
+ container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName)
18
18
  ? this.array[idxOrName || 0]
19
19
  : this.array.find((t) => t.name === idxOrName);
20
20
  container.addEmitter = (options, position) => this.addEmitter(options, position);
@@ -46,39 +46,43 @@ export class Emitters {
46
46
  }
47
47
  handleClickMode(mode) {
48
48
  const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
49
- if (mode === "emitter") {
50
- let emittersModeOptions;
51
- if (modeEmitters && modeEmitters.value instanceof Array) {
52
- if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
53
- emittersModeOptions = [];
54
- const usedIndexes = [];
55
- for (let i = 0; i < modeEmitters.random.count; i++) {
56
- const idx = arrayRandomIndex(modeEmitters.value);
57
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
58
- i--;
59
- continue;
60
- }
61
- usedIndexes.push(idx);
62
- emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
49
+ if (mode !== "emitter") {
50
+ return;
51
+ }
52
+ let emittersModeOptions;
53
+ if (modeEmitters && isArray(modeEmitters.value)) {
54
+ if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
55
+ emittersModeOptions = [];
56
+ const usedIndexes = [];
57
+ for (let i = 0; i < modeEmitters.random.count; i++) {
58
+ const idx = arrayRandomIndex(modeEmitters.value);
59
+ if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
60
+ i--;
61
+ continue;
63
62
  }
64
- }
65
- else {
66
- emittersModeOptions = modeEmitters.value;
63
+ usedIndexes.push(idx);
64
+ emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
67
65
  }
68
66
  }
69
67
  else {
70
- emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
68
+ emittersModeOptions = modeEmitters.value;
71
69
  }
72
- const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
73
- executeOnSingleOrMultiple(emittersOptions, (emitter) => {
74
- this.addEmitter(emitter, ePosition);
75
- });
76
70
  }
71
+ else {
72
+ emittersModeOptions = modeEmitters?.value;
73
+ }
74
+ const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
75
+ executeOnSingleOrMultiple(emittersOptions, (emitter) => {
76
+ this.addEmitter(emitter, ePosition);
77
+ });
77
78
  }
78
79
  async init() {
79
80
  this.emitters = this.container.actualOptions.emitters;
80
81
  this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
81
- if (this.emitters instanceof Array) {
82
+ if (!this.emitters) {
83
+ return;
84
+ }
85
+ if (isArray(this.emitters)) {
82
86
  for (const emitterOptions of this.emitters) {
83
87
  this.addEmitter(emitterOptions);
84
88
  }
@@ -1,7 +1,7 @@
1
- import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
2
- import { EmitterLife } from "./EmitterLife";
3
- import { EmitterRate } from "./EmitterRate";
4
- import { EmitterSize } from "./EmitterSize";
1
+ import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue, } from "@tsparticles/engine";
2
+ import { EmitterLife } from "./EmitterLife.js";
3
+ import { EmitterRate } from "./EmitterRate.js";
4
+ import { EmitterSize } from "./EmitterSize.js";
5
5
  export class Emitter {
6
6
  constructor() {
7
7
  this.autoPlay = true;
@@ -12,14 +12,14 @@ export class Emitter {
12
12
  this.startCount = 0;
13
13
  }
14
14
  load(data) {
15
- if (data === undefined) {
15
+ if (!data) {
16
16
  return;
17
17
  }
18
18
  if (data.autoPlay !== undefined) {
19
19
  this.autoPlay = data.autoPlay;
20
20
  }
21
21
  if (data.size !== undefined) {
22
- if (this.size === undefined) {
22
+ if (!this.size) {
23
23
  this.size = new EmitterSize();
24
24
  }
25
25
  this.size.load(data.size);
@@ -1,19 +1,20 @@
1
+ import { setRangeValue } from "@tsparticles/engine";
1
2
  export class EmitterLife {
2
3
  constructor() {
3
4
  this.wait = false;
4
5
  }
5
6
  load(data) {
6
- if (data === undefined) {
7
+ if (!data) {
7
8
  return;
8
9
  }
9
10
  if (data.count !== undefined) {
10
11
  this.count = data.count;
11
12
  }
12
13
  if (data.delay !== undefined) {
13
- this.delay = data.delay;
14
+ this.delay = setRangeValue(data.delay);
14
15
  }
15
16
  if (data.duration !== undefined) {
16
- this.duration = data.duration;
17
+ this.duration = setRangeValue(data.duration);
17
18
  }
18
19
  if (data.wait !== undefined) {
19
20
  this.wait = data.wait;