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