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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +15 -11
  2. package/browser/EmitterInstance.js +99 -111
  3. package/browser/Emitters.js +29 -25
  4. package/browser/Options/Classes/Emitter.js +3 -3
  5. package/browser/Options/Classes/EmitterLife.js +4 -3
  6. package/browser/index.js +14 -17
  7. package/cjs/EmitterInstance.js +98 -110
  8. package/cjs/Emitters.js +37 -44
  9. package/cjs/Options/Classes/Emitter.js +2 -2
  10. package/cjs/Options/Classes/EmitterLife.js +4 -3
  11. package/cjs/Shapes/Circle/CircleShape.js +1 -1
  12. package/cjs/index.js +23 -37
  13. package/esm/EmitterInstance.js +99 -111
  14. package/esm/Emitters.js +29 -25
  15. package/esm/Options/Classes/Emitter.js +3 -3
  16. package/esm/Options/Classes/EmitterLife.js +4 -3
  17. package/esm/index.js +14 -17
  18. package/package.json +6 -5
  19. package/report.html +4 -4
  20. package/tsparticles.plugin.emitters.js +137 -145
  21. package/tsparticles.plugin.emitters.min.js +1 -1
  22. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -8
  23. package/types/EmitterInstance.d.ts +7 -7
  24. package/types/Emitters.d.ts +1 -1
  25. package/types/Enums/EmitterShapeType.d.ts +3 -1
  26. package/types/Options/Classes/Emitter.d.ts +1 -2
  27. package/types/Options/Classes/EmitterLife.d.ts +3 -3
  28. package/types/Options/Classes/EmitterRate.d.ts +1 -1
  29. package/types/Options/Classes/EmitterSize.d.ts +2 -3
  30. package/types/Options/Interfaces/IEmitterLife.d.ts +3 -2
  31. package/types/Options/Interfaces/IEmitterSize.d.ts +2 -2
  32. package/types/Shapes/Circle/CircleShape.d.ts +1 -1
  33. package/types/Shapes/Square/SquareShape.d.ts +1 -1
  34. package/types/index.d.ts +1 -1
  35. package/umd/EmitterInstance.js +98 -110
  36. package/umd/Emitters.js +28 -24
  37. package/umd/Options/Classes/Emitter.js +2 -2
  38. package/umd/Options/Classes/EmitterLife.js +5 -4
  39. package/umd/index.js +13 -16
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Emitters Plugin
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-plugin-emitters/badge)](https://www.jsdelivr.com/package/npm/tsparticles-plugin-emitters)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-plugin-emitters.svg)](https://www.npmjs.com/package/tsparticles-plugin-emitters)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-plugin-emitters)](https://www.npmjs.com/package/tsparticles-plugin-emitters) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-emitters/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-emitters)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-emitters.svg)](https://www.npmjs.com/package/@tsparticles/plugin-emitters)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-emitters)](https://www.npmjs.com/package/@tsparticles/plugin-emitters) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
8
 
9
9
  [tsParticles](https://github.com/matteobruni/tsparticles) plugin for particles emitters.
10
10
 
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the plugin like thi
42
42
  This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
43
 
44
44
  ```shell
45
- $ npm install tsparticles-plugin-emitters
45
+ $ npm install @tsparticles/plugin-emitters
46
46
  ```
47
47
 
48
48
  or
49
49
 
50
50
  ```shell
51
- $ yarn add tsparticles-plugin-emitters
51
+ $ yarn add @tsparticles/plugin-emitters
52
52
  ```
53
53
 
54
54
  Then you need to import it in the app, like this:
55
55
 
56
56
  ```javascript
57
- const { tsParticles } = require("tsparticles-engine");
58
- const { loadEmittersPlugin } = require("tsparticles-plugin-emitters");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadEmittersPlugin } = require("@tsparticles/plugin-emitters");
59
59
 
60
- loadEmittersPlugin(tsParticles);
60
+ (async () => {
61
+ await loadEmittersPlugin(tsParticles);
62
+ })();
61
63
  ```
62
64
 
63
65
  or
64
66
 
65
67
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadEmittersPlugin } from "tsparticles-plugin-emitters";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
68
70
 
69
- loadEmittersPlugin(tsParticles);
71
+ (async () => {
72
+ await loadEmittersPlugin(tsParticles);
73
+ })();
70
74
  ```
@@ -1,12 +1,79 @@
1
- import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
1
+ import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter";
3
3
  import { EmitterSize } from "./Options/Classes/EmitterSize";
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
  }
@@ -1,4 +1,4 @@
1
- import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
1
+ import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter";
3
3
  import { EmitterInstance } from "./EmitterInstance";
4
4
  export class Emitters {
@@ -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,4 +1,4 @@
1
- import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
1
+ import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue, } from "@tsparticles/engine";
2
2
  import { EmitterLife } from "./EmitterLife";
3
3
  import { EmitterRate } from "./EmitterRate";
4
4
  import { EmitterSize } from "./EmitterSize";
@@ -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;
package/browser/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { executeOnSingleOrMultiple, isInArray } from "@tsparticles/engine";
1
+ import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
2
2
  import { CircleShape } from "./Shapes/Circle/CircleShape";
3
3
  import { Emitter } from "./Options/Classes/Emitter";
4
4
  import { Emitters } from "./Emitters";
@@ -13,20 +13,19 @@ class EmittersPlugin {
13
13
  return new Emitters(this._engine, container);
14
14
  }
15
15
  loadOptions(options, source) {
16
- var _a, _b, _c, _d, _e, _f;
17
16
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
18
17
  return;
19
18
  }
20
- if (source === null || source === void 0 ? void 0 : source.emitters) {
19
+ if (source?.emitters) {
21
20
  options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {
22
21
  const tmp = new Emitter();
23
22
  tmp.load(emitter);
24
23
  return tmp;
25
24
  });
26
25
  }
27
- 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;
26
+ const interactivityEmitters = source?.interactivity?.modes?.emitters;
28
27
  if (interactivityEmitters) {
29
- if (interactivityEmitters instanceof Array) {
28
+ if (isArray(interactivityEmitters)) {
30
29
  options.interactivity.modes.emitters = {
31
30
  random: {
32
31
  count: 1,
@@ -42,11 +41,11 @@ class EmittersPlugin {
42
41
  else {
43
42
  const emitterMode = interactivityEmitters;
44
43
  if (emitterMode.value !== undefined) {
45
- if (emitterMode.value instanceof Array) {
44
+ if (isArray(emitterMode.value)) {
46
45
  options.interactivity.modes.emitters = {
47
46
  random: {
48
- count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
49
- enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
47
+ count: emitterMode.random.count ?? 1,
48
+ enable: emitterMode.random.enable ?? false,
50
49
  },
51
50
  value: emitterMode.value.map((s) => {
52
51
  const tmp = new Emitter();
@@ -60,8 +59,8 @@ class EmittersPlugin {
60
59
  tmp.load(emitterMode.value);
61
60
  options.interactivity.modes.emitters = {
62
61
  random: {
63
- count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
64
- enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
62
+ count: emitterMode.random.count ?? 1,
63
+ enable: emitterMode.random.enable ?? false,
65
64
  },
66
65
  value: tmp,
67
66
  };
@@ -81,29 +80,27 @@ class EmittersPlugin {
81
80
  }
82
81
  }
83
82
  needsPlugin(options) {
84
- var _a, _b, _c;
85
83
  if (!options) {
86
84
  return false;
87
85
  }
88
86
  const emitters = options.emitters;
89
- return ((emitters instanceof Array && !!emitters.length) ||
87
+ return ((isArray(emitters) && !!emitters.length) ||
90
88
  emitters !== undefined ||
91
- (!!((_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) &&
89
+ (!!options.interactivity?.events?.onClick?.mode &&
92
90
  isInArray("emitter", options.interactivity.events.onClick.mode)));
93
91
  }
94
92
  }
95
- export async function loadEmittersPlugin(engine) {
93
+ export async function loadEmittersPlugin(engine, refresh = true) {
96
94
  if (!engine.emitterShapeManager) {
97
95
  engine.emitterShapeManager = new ShapeManager(engine);
98
96
  }
99
97
  if (!engine.addEmitterShape) {
100
98
  engine.addEmitterShape = (name, shape) => {
101
- var _a;
102
- (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
99
+ engine.emitterShapeManager?.addShape(name, shape);
103
100
  };
104
101
  }
105
102
  const plugin = new EmittersPlugin(engine);
106
- await engine.addPlugin(plugin);
103
+ await engine.addPlugin(plugin, refresh);
107
104
  engine.addEmitterShape("circle", new CircleShape());
108
105
  engine.addEmitterShape("square", new SquareShape());
109
106
  }