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