@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
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadEmittersPlugin": () => (/* binding */ loadEmittersPlugin)
94
+ loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -126,22 +126,23 @@ class CircleShape {
126
126
  }
127
127
  }
128
128
  ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterLife.js
129
+
129
130
  class EmitterLife {
130
131
  constructor() {
131
132
  this.wait = false;
132
133
  }
133
134
  load(data) {
134
- if (data === undefined) {
135
+ if (!data) {
135
136
  return;
136
137
  }
137
138
  if (data.count !== undefined) {
138
139
  this.count = data.count;
139
140
  }
140
141
  if (data.delay !== undefined) {
141
- this.delay = data.delay;
142
+ this.delay = (0,engine_root_window_.setRangeValue)(data.delay);
142
143
  }
143
144
  if (data.duration !== undefined) {
144
- this.duration = data.duration;
145
+ this.duration = (0,engine_root_window_.setRangeValue)(data.duration);
145
146
  }
146
147
  if (data.wait !== undefined) {
147
148
  this.wait = data.wait;
@@ -204,14 +205,14 @@ class Emitter {
204
205
  this.startCount = 0;
205
206
  }
206
207
  load(data) {
207
- if (data === undefined) {
208
+ if (!data) {
208
209
  return;
209
210
  }
210
211
  if (data.autoPlay !== undefined) {
211
212
  this.autoPlay = data.autoPlay;
212
213
  }
213
214
  if (data.size !== undefined) {
214
- if (this.size === undefined) {
215
+ if (!this.size) {
215
216
  this.size = new EmitterSize();
216
217
  }
217
218
  this.size.load(data.size);
@@ -258,10 +259,78 @@ class Emitter {
258
259
 
259
260
  class EmitterInstance {
260
261
  constructor(engine, emitters, container, options, position) {
261
- var _a, _b, _c, _d, _e, _f, _g;
262
- var _h;
263
262
  this.emitters = emitters;
264
263
  this.container = container;
264
+ this._calcPosition = () => {
265
+ return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({
266
+ size: this.container.canvas.size,
267
+ position: this.options.position
268
+ });
269
+ };
270
+ this._destroy = () => {
271
+ this.emitters.removeEmitter(this);
272
+ this._engine.dispatchEvent("emitterDestroyed", {
273
+ container: this.container,
274
+ data: {
275
+ emitter: this
276
+ }
277
+ });
278
+ };
279
+ this._emit = () => {
280
+ if (this._paused) {
281
+ return;
282
+ }
283
+ const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity);
284
+ this._emitParticles(quantity);
285
+ };
286
+ this._emitParticles = quantity => {
287
+ const position = this.getPosition(),
288
+ size = this.getSize(),
289
+ singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions);
290
+ for (let i = 0; i < quantity; i++) {
291
+ const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions);
292
+ if (this.spawnColor) {
293
+ const hslAnimation = this.options.spawnColor?.animation;
294
+ if (hslAnimation) {
295
+ this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
296
+ this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
297
+ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
298
+ }
299
+ if (!particlesOptions.color) {
300
+ particlesOptions.color = {
301
+ value: this.spawnColor
302
+ };
303
+ } else {
304
+ particlesOptions.color.value = this.spawnColor;
305
+ }
306
+ }
307
+ if (!position) {
308
+ return;
309
+ }
310
+ const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
311
+ this.container.particles.addParticle(pPosition, particlesOptions);
312
+ }
313
+ };
314
+ this._prepareToDie = () => {
315
+ if (this._paused) {
316
+ return;
317
+ }
318
+ const duration = this.options.life?.duration !== undefined ? (0,engine_root_window_.getRangeValue)(this.options.life.duration) : undefined;
319
+ if (this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal) && duration !== undefined && duration > 0) {
320
+ this._duration = duration * 1000;
321
+ }
322
+ };
323
+ this._setColorAnimation = (animation, initValue, maxValue) => {
324
+ const container = this.container;
325
+ if (!animation.enable) {
326
+ return initValue;
327
+ }
328
+ const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset),
329
+ delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay),
330
+ emitFactor = 1000 * delay / container.retina.reduceFactor,
331
+ colorSpeed = (0,engine_root_window_.getRangeValue)(animation.speed ?? 0);
332
+ return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
333
+ };
265
334
  this._engine = engine;
266
335
  this._currentDuration = 0;
267
336
  this._currentEmitDelay = 0;
@@ -273,23 +342,23 @@ class EmitterInstance {
273
342
  this.options = new Emitter();
274
343
  this.options.load(options);
275
344
  }
276
- this._spawnDelay = ((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000 / this.container.retina.reduceFactor;
277
- this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
345
+ this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor;
346
+ this.position = this._initialPosition ?? this._calcPosition();
278
347
  this.name = this.options.name;
279
- this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
348
+ this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
280
349
  this.fill = this.options.fill;
281
350
  this._firstSpawn = !this.options.life.wait;
282
351
  this._startParticlesAdded = false;
283
352
  let particlesOptions = (0,engine_root_window_.deepExtend)({}, this.options.particles);
284
- particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : particlesOptions = {};
285
- (_d = particlesOptions.move) !== null && _d !== void 0 ? _d : particlesOptions.move = {};
286
- (_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : _h.direction = this.options.direction;
353
+ particlesOptions ??= {};
354
+ particlesOptions.move ??= {};
355
+ particlesOptions.move.direction ??= this.options.direction;
287
356
  if (this.options.spawnColor) {
288
357
  this.spawnColor = (0,engine_root_window_.rangeColorToHsl)(this.options.spawnColor);
289
358
  }
290
359
  this._paused = !this.options.autoPlay;
291
360
  this._particlesOptions = particlesOptions;
292
- this.size = (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
361
+ this.size = this.options.size ?? (() => {
293
362
  const size = new EmitterSize();
294
363
  size.load({
295
364
  height: 0,
@@ -298,7 +367,7 @@ class EmitterInstance {
298
367
  });
299
368
  return size;
300
369
  })();
301
- this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
370
+ this._lifeCount = this.options.life.count ?? -1;
302
371
  this._immortal = this._lifeCount <= 0;
303
372
  this._engine.dispatchEvent("emitterCreated", {
304
373
  container,
@@ -342,10 +411,7 @@ class EmitterInstance {
342
411
  };
343
412
  }
344
413
  }
345
- return {
346
- width: this.size.mode === "percent" ? container.canvas.size.width * this.size.width / 100 : this.size.width,
347
- height: this.size.mode === "percent" ? container.canvas.size.height * this.size.height / 100 : this.size.height
348
- };
414
+ return (0,engine_root_window_.getSize)(this.size, container.canvas.size);
349
415
  }
350
416
  pause() {
351
417
  if (this._paused) {
@@ -354,11 +420,10 @@ class EmitterInstance {
354
420
  delete this._emitDelay;
355
421
  }
356
422
  play() {
357
- var _a;
358
423
  if (this._paused) {
359
424
  return;
360
425
  }
361
- if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
426
+ if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
362
427
  return;
363
428
  }
364
429
  if (this._emitDelay === undefined) {
@@ -366,26 +431,25 @@ class EmitterInstance {
366
431
  this._emitDelay = 1000 * delay / this.container.retina.reduceFactor;
367
432
  }
368
433
  if (this._lifeCount > 0 || this._immortal) {
369
- this.prepareToDie();
434
+ this._prepareToDie();
370
435
  }
371
436
  }
372
437
  resize() {
373
438
  const initialPosition = this._initialPosition;
374
- this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this.calcPosition();
439
+ this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this._calcPosition();
375
440
  }
376
441
  update(delta) {
377
- var _a, _b, _c;
378
442
  if (this._paused) {
379
443
  return;
380
444
  }
381
445
  if (this._firstSpawn) {
382
446
  this._firstSpawn = false;
383
- this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
384
- this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
447
+ this._currentSpawnDelay = this._spawnDelay ?? 0;
448
+ this._currentEmitDelay = this._emitDelay ?? 0;
385
449
  }
386
450
  if (!this._startParticlesAdded) {
387
451
  this._startParticlesAdded = true;
388
- this.emitParticles(this.options.startCount);
452
+ this._emitParticles(this.options.startCount);
389
453
  }
390
454
  if (this._duration !== undefined) {
391
455
  this._currentDuration += delta.value;
@@ -398,10 +462,10 @@ class EmitterInstance {
398
462
  this._lifeCount--;
399
463
  }
400
464
  if (this._lifeCount > 0 || this._immortal) {
401
- this.position = this.calcPosition();
402
- this._spawnDelay = ((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000 / this.container.retina.reduceFactor;
465
+ this.position = this._calcPosition();
466
+ this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor;
403
467
  } else {
404
- this.destroy();
468
+ this._destroy();
405
469
  }
406
470
  this._currentDuration -= this._duration;
407
471
  delete this._duration;
@@ -421,84 +485,11 @@ class EmitterInstance {
421
485
  if (this._emitDelay !== undefined) {
422
486
  this._currentEmitDelay += delta.value;
423
487
  if (this._currentEmitDelay >= this._emitDelay) {
424
- this.emit();
488
+ this._emit();
425
489
  this._currentEmitDelay -= this._emitDelay;
426
490
  }
427
491
  }
428
492
  }
429
- calcPosition() {
430
- return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({
431
- size: this.container.canvas.size,
432
- position: this.options.position
433
- });
434
- }
435
- destroy() {
436
- this.emitters.removeEmitter(this);
437
- this._engine.dispatchEvent("emitterDestroyed", {
438
- container: this.container,
439
- data: {
440
- emitter: this
441
- }
442
- });
443
- }
444
- emit() {
445
- if (this._paused) {
446
- return;
447
- }
448
- const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity);
449
- this.emitParticles(quantity);
450
- }
451
- emitParticles(quantity) {
452
- var _a, _b, _c;
453
- const position = this.getPosition(),
454
- size = this.getSize(),
455
- singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions);
456
- for (let i = 0; i < quantity; i++) {
457
- const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions);
458
- if (this.spawnColor) {
459
- const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
460
- if (hslAnimation) {
461
- this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
462
- this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
463
- this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
464
- }
465
- if (!particlesOptions.color) {
466
- particlesOptions.color = {
467
- value: this.spawnColor
468
- };
469
- } else {
470
- particlesOptions.color.value = this.spawnColor;
471
- }
472
- }
473
- if (!position) {
474
- return;
475
- }
476
- const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
477
- this.container.particles.addParticle(pPosition, particlesOptions);
478
- }
479
- }
480
- prepareToDie() {
481
- var _a;
482
- if (this._paused) {
483
- return;
484
- }
485
- const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
486
- if (this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal) && duration !== undefined && duration > 0) {
487
- this._duration = duration * 1000;
488
- }
489
- }
490
- setColorAnimation(animation, initValue, maxValue) {
491
- var _a;
492
- const container = this.container;
493
- if (!animation.enable) {
494
- return initValue;
495
- }
496
- const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset),
497
- delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay),
498
- emitFactor = 1000 * delay / container.retina.reduceFactor,
499
- colorSpeed = (0,engine_root_window_.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
500
- return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
501
- }
502
493
  }
503
494
  ;// CONCATENATED MODULE: ./dist/browser/Emitters.js
504
495
 
@@ -517,7 +508,7 @@ class Emitters {
517
508
  },
518
509
  value: []
519
510
  };
520
- container.getEmitter = idxOrName => idxOrName === undefined || typeof idxOrName === "number" ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
511
+ container.getEmitter = idxOrName => idxOrName === undefined || (0,engine_root_window_.isNumber)(idxOrName) ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
521
512
  container.addEmitter = (options, position) => this.addEmitter(options, position);
522
513
  container.removeEmitter = idxOrName => {
523
514
  const emitter = container.getEmitter(idxOrName);
@@ -548,38 +539,42 @@ class Emitters {
548
539
  handleClickMode(mode) {
549
540
  const emitterOptions = this.emitters,
550
541
  modeEmitters = this.interactivityEmitters;
551
- if (mode === "emitter") {
552
- let emittersModeOptions;
553
- if (modeEmitters && modeEmitters.value instanceof Array) {
554
- if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
555
- emittersModeOptions = [];
556
- const usedIndexes = [];
557
- for (let i = 0; i < modeEmitters.random.count; i++) {
558
- const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value);
559
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
560
- i--;
561
- continue;
562
- }
563
- usedIndexes.push(idx);
564
- emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx));
542
+ if (mode !== "emitter") {
543
+ return;
544
+ }
545
+ let emittersModeOptions;
546
+ if (modeEmitters && (0,engine_root_window_.isArray)(modeEmitters.value)) {
547
+ if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
548
+ emittersModeOptions = [];
549
+ const usedIndexes = [];
550
+ for (let i = 0; i < modeEmitters.random.count; i++) {
551
+ const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value);
552
+ if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
553
+ i--;
554
+ continue;
565
555
  }
566
- } else {
567
- emittersModeOptions = modeEmitters.value;
556
+ usedIndexes.push(idx);
557
+ emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx));
568
558
  }
569
559
  } else {
570
- emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
560
+ emittersModeOptions = modeEmitters.value;
571
561
  }
572
- const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions,
573
- ePosition = this.container.interactivity.mouse.clickPosition;
574
- (0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => {
575
- this.addEmitter(emitter, ePosition);
576
- });
562
+ } else {
563
+ emittersModeOptions = modeEmitters?.value;
577
564
  }
565
+ const emittersOptions = emittersModeOptions ?? emitterOptions,
566
+ ePosition = this.container.interactivity.mouse.clickPosition;
567
+ (0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => {
568
+ this.addEmitter(emitter, ePosition);
569
+ });
578
570
  }
579
571
  async init() {
580
572
  this.emitters = this.container.actualOptions.emitters;
581
573
  this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
582
- if (this.emitters instanceof Array) {
574
+ if (!this.emitters) {
575
+ return;
576
+ }
577
+ if ((0,engine_root_window_.isArray)(this.emitters)) {
583
578
  for (const emitterOptions of this.emitters) {
584
579
  this.addEmitter(emitterOptions);
585
580
  }
@@ -694,20 +689,19 @@ class EmittersPlugin {
694
689
  return new Emitters(this._engine, container);
695
690
  }
696
691
  loadOptions(options, source) {
697
- var _a, _b, _c, _d, _e, _f;
698
692
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
699
693
  return;
700
694
  }
701
- if (source === null || source === void 0 ? void 0 : source.emitters) {
695
+ if (source?.emitters) {
702
696
  options.emitters = (0,engine_root_window_.executeOnSingleOrMultiple)(source.emitters, emitter => {
703
697
  const tmp = new Emitter();
704
698
  tmp.load(emitter);
705
699
  return tmp;
706
700
  });
707
701
  }
708
- 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;
702
+ const interactivityEmitters = source?.interactivity?.modes?.emitters;
709
703
  if (interactivityEmitters) {
710
- if (interactivityEmitters instanceof Array) {
704
+ if ((0,engine_root_window_.isArray)(interactivityEmitters)) {
711
705
  options.interactivity.modes.emitters = {
712
706
  random: {
713
707
  count: 1,
@@ -722,11 +716,11 @@ class EmittersPlugin {
722
716
  } else {
723
717
  const emitterMode = interactivityEmitters;
724
718
  if (emitterMode.value !== undefined) {
725
- if (emitterMode.value instanceof Array) {
719
+ if ((0,engine_root_window_.isArray)(emitterMode.value)) {
726
720
  options.interactivity.modes.emitters = {
727
721
  random: {
728
- count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
729
- enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false
722
+ count: emitterMode.random.count ?? 1,
723
+ enable: emitterMode.random.enable ?? false
730
724
  },
731
725
  value: emitterMode.value.map(s => {
732
726
  const tmp = new Emitter();
@@ -739,8 +733,8 @@ class EmittersPlugin {
739
733
  tmp.load(emitterMode.value);
740
734
  options.interactivity.modes.emitters = {
741
735
  random: {
742
- count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
743
- enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false
736
+ count: emitterMode.random.count ?? 1,
737
+ enable: emitterMode.random.enable ?? false
744
738
  },
745
739
  value: tmp
746
740
  };
@@ -759,26 +753,24 @@ class EmittersPlugin {
759
753
  }
760
754
  }
761
755
  needsPlugin(options) {
762
- var _a, _b, _c;
763
756
  if (!options) {
764
757
  return false;
765
758
  }
766
759
  const emitters = options.emitters;
767
- return emitters instanceof Array && !!emitters.length || emitters !== undefined || !!((_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) && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode);
760
+ return (0,engine_root_window_.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode);
768
761
  }
769
762
  }
770
- async function loadEmittersPlugin(engine) {
763
+ async function loadEmittersPlugin(engine, refresh = true) {
771
764
  if (!engine.emitterShapeManager) {
772
765
  engine.emitterShapeManager = new ShapeManager(engine);
773
766
  }
774
767
  if (!engine.addEmitterShape) {
775
768
  engine.addEmitterShape = (name, shape) => {
776
- var _a;
777
- (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
769
+ engine.emitterShapeManager?.addShape(name, shape);
778
770
  };
779
771
  }
780
772
  const plugin = new EmittersPlugin(engine);
781
- await engine.addPlugin(plugin);
773
+ await engine.addPlugin(plugin, refresh);
782
774
  engine.addEmitterShape("circle", new CircleShape());
783
775
  engine.addEmitterShape("square", new SquareShape());
784
776
  }
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.plugin.emitters.min.js.LICENSE.txt */
2
- !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var e="object"==typeof exports?i(require("@tsparticles/engine")):i(t.window);for(var s in e)("object"==typeof exports?exports:t)[s]=e[s]}}(this,(t=>(()=>{"use strict";var i={533:i=>{i.exports=t}},e={};function s(t){var n=e[t];if(void 0!==n)return n.exports;var o=e[t]={exports:{}};return i[t](o,o.exports,s),o.exports}s.d=(t,i)=>{for(var e in i)s.o(i,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},s.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{loadEmittersPlugin:()=>v});var t=s(533);class i{randomPosition(i,e,s){const[n,o]=[e.width/2,e.height/2],a=((i,e)=>{const s=(0,t.getRandom)()/4,n=Math.atan(e/i*Math.tan(2*Math.PI*s)),o=(0,t.getRandom)();return o<.25?n:o<.5?Math.PI-n:o<.75?Math.PI+n:-n})(n,o),r=(c=a,(h=n)*(d=o)/Math.sqrt((d*Math.cos(c))**2+(h*Math.sin(c))**2)),l=s?r*Math.sqrt((0,t.getRandom)()):r;var h,d,c;return{x:i.x+l*Math.cos(a),y:i.y+l*Math.sin(a)}}}class e{constructor(){this.wait=!1}load(t){void 0!==t&&(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=t.delay),void 0!==t.duration&&(this.duration=t.duration),void 0!==t.wait&&(this.wait=t.wait))}}class o{constructor(){this.quantity=1,this.delay=.1}load(i){void 0!==i&&(void 0!==i.quantity&&(this.quantity=(0,t.setRangeValue)(i.quantity)),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)))}}class a{constructor(){this.mode="percent",this.height=0,this.width=0}load(t){void 0!==t&&(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}class r{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new o,this.shape="square",this.startCount=0}load(i){void 0!==i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(void 0===this.size&&(this.size=new a),this.size.load(i.size)),void 0!==i.direction&&(this.direction=i.direction),this.domId=i.domId,void 0!==i.fill&&(this.fill=i.fill),this.life.load(i.life),this.name=i.name,this.particles=(0,t.executeOnSingleOrMultiple)(i.particles,(i=>(0,t.deepExtend)({},i))),this.rate.load(i.rate),void 0!==i.shape&&(this.shape=i.shape),void 0!==i.position&&(this.position={},void 0!==i.position.x&&(this.position.x=(0,t.setRangeValue)(i.position.x)),void 0!==i.position.y&&(this.position.y=(0,t.setRangeValue)(i.position.y))),void 0!==i.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new t.AnimatableColor),this.spawnColor.load(i.spawnColor)),void 0!==i.startCount&&(this.startCount=i.startCount))}}class l{constructor(i,e,s,n,o){var l,h,d,c,u,p,m,v;this.emitters=e,this.container=s,this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=o,n instanceof r?this.options=n:(this.options=new r,this.options.load(n)),this._spawnDelay=1e3*(null!==(l=this.options.life.delay)&&void 0!==l?l:0)/this.container.retina.reduceFactor,this.position=null!==(h=this._initialPosition)&&void 0!==h?h:this.calcPosition(),this.name=this.options.name,this._shape=null===(d=this._engine.emitterShapeManager)||void 0===d?void 0:d.getShape(this.options.shape),this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let y=(0,t.deepExtend)({},this.options.particles);null!=y||(y={}),null!==(c=y.move)&&void 0!==c||(y.move={}),null!==(u=(v=y.move).direction)&&void 0!==u||(v.direction=this.options.direction),this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=y,this.size=null!==(p=this.options.size)&&void 0!==p?p:(()=>{const t=new a;return t.load({height:0,mode:"percent",width:0}),t})(),this._lifeCount=null!==(m=this.options.life.count)&&void 0!==m?m:-1,this._immortal=this._lifeCount<=0,this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}getPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{x:(e.x+e.width/2)*t.retina.pixelRatio,y:(e.y+e.height/2)*t.retina.pixelRatio}}}return this.position}getSize(){const t=this.container;if(this.options.domId){const i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio}}}return{width:"percent"===this.size.mode?t.canvas.size.width*this.size.width/100:this.size.width,height:"percent"===this.size.mode?t.canvas.size.height*this.size.height/100:this.size.height}}pause(){this._paused||delete this._emitDelay}play(){var i;if(!this._paused&&this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(null!==(i=this._spawnDelay)&&void 0!==i?i:0))){if(void 0===this._emitDelay){const i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=1e3*i/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this.prepareToDie()}}resize(){const i=this._initialPosition;this.position=i&&(0,t.isPointInside)(i,this.container.canvas.size,t.Vector.origin)?i:this.calcPosition()}update(t){var i,e,s;this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=null!==(i=this._spawnDelay)&&void 0!==i?i:0,this._currentEmitDelay=null!==(e=this._emitDelay)&&void 0!==e?e:0),this._startParticlesAdded||(this._startParticlesAdded=!0,this.emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=t.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,this._immortal||this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this.calcPosition(),this._spawnDelay=1e3*(null!==(s=this.options.life.delay)&&void 0!==s?s:0)/this.container.retina.reduceFactor):this.destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this.emit(),this._currentEmitDelay-=this._emitDelay)))}calcPosition(){return(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}destroy(){this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})}emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);this.emitParticles(i)}emitParticles(i){var e,s,n;const o=this.getPosition(),a=this.getSize(),r=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let l=0;l<i;l++){const i=(0,t.deepExtend)({},r);if(this.spawnColor){const t=null===(e=this.options.spawnColor)||void 0===e?void 0:e.animation;t&&(this.spawnColor.h=this.setColorAnimation(t.h,this.spawnColor.h,360),this.spawnColor.s=this.setColorAnimation(t.s,this.spawnColor.s,100),this.spawnColor.l=this.setColorAnimation(t.l,this.spawnColor.l,100)),i.color?i.color.value=this.spawnColor:i.color={value:this.spawnColor}}if(!o)return;const l=null!==(n=null===(s=this._shape)||void 0===s?void 0:s.randomPosition(o,a,this.fill))&&void 0!==n?n:o;this.container.particles.addParticle(l,i)}}prepareToDie(){var t;if(this._paused)return;const i=null===(t=this.options.life)||void 0===t?void 0:t.duration;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=1e3*i)}setColorAnimation(i,e,s){var n;const o=this.container;if(!i.enable)return e;const a=(0,t.randomInRange)(i.offset),r=1e3*(0,t.getRangeValue)(this.options.rate.delay)/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(null!==(n=i.speed)&&void 0!==n?n:0)*o.fpsLimit/r+3.6*a)%s}}class h{constructor(t,i){this.container=i,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]},i.getEmitter=t=>void 0===t||"number"==typeof t?this.array[t||0]:this.array.find((i=>i.name===t)),i.addEmitter=(t,i)=>this.addEmitter(t,i),i.removeEmitter=t=>{const e=i.getEmitter(t);e&&this.removeEmitter(e)},i.playEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPlay()},i.pauseEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPause()}}addEmitter(t,i){const e=new r;e.load(t);const s=new l(this._engine,this,this.container,e,i);return this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"===i){let i;if(s&&s.value instanceof Array)if(s.value.length>0&&s.random.enable){i=[];const e=[];for(let n=0;n<s.random.count;n++){const o=(0,t.arrayRandomIndex)(s.value);e.includes(o)&&e.length<s.value.length?n--:(e.push(o),i.push((0,t.itemFromArray)(s.value,o)))}}else i=s.value;else i=null==s?void 0:s.value;const n=null!=i?i:e,o=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(t=>{this.addEmitter(t,o)}))}}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters instanceof Array)for(const t of this.emitters)this.addEmitter(t);else this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}const d=new Map;class c{constructor(t){this._engine=t}addShape(t,i){this.getShape(t)||d.set(t,i)}getShape(t){return d.get(t)}getSupportedShapes(){return d.keys()}}function u(i,e){return i+e*((0,t.getRandom)()-.5)}class p{randomPosition(i,e,s){if(s)return{x:u(i.x,e.width),y:u(i.y,e.height)};{const s=e.width/2,n=e.height/2,o=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-.5);switch(o){case 0:return{x:i.x+a*s,y:i.y-n};case 1:return{x:i.x-s,y:i.y+a*n};case 2:return{x:i.x+a*s,y:i.y+n};default:return{x:i.x+s,y:i.y+a*n}}}}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new h(this._engine,t)}loadOptions(i,e){var s,n,o,a,l,h;if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;(null==e?void 0:e.emitters)&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new r;return i.load(t),i})));const d=null===(n=null===(s=null==e?void 0:e.interactivity)||void 0===s?void 0:s.modes)||void 0===n?void 0:n.emitters;if(d)if(d instanceof Array)i.interactivity.modes.emitters={random:{count:1,enable:!0},value:d.map((t=>{const i=new r;return i.load(t),i}))};else{const t=d;if(void 0!==t.value)if(t.value instanceof Array)i.interactivity.modes.emitters={random:{count:null!==(o=t.random.count)&&void 0!==o?o:1,enable:null!==(a=t.random.enable)&&void 0!==a&&a},value:t.value.map((t=>{const i=new r;return i.load(t),i}))};else{const e=new r;e.load(t.value),i.interactivity.modes.emitters={random:{count:null!==(l=t.random.count)&&void 0!==l?l:1,enable:null!==(h=t.random.enable)&&void 0!==h&&h},value:e}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new r}).value.load(d)}}}needsPlugin(i){var e,s,n;if(!i)return!1;const o=i.emitters;return o instanceof Array&&!!o.length||void 0!==o||!!(null===(n=null===(s=null===(e=i.interactivity)||void 0===e?void 0:e.events)||void 0===s?void 0:s.onClick)||void 0===n?void 0:n.mode)&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function v(t){t.emitterShapeManager||(t.emitterShapeManager=new c(t)),t.addEmitterShape||(t.addEmitterShape=(i,e)=>{var s;null===(s=t.emitterShapeManager)||void 0===s||s.addShape(i,e)});const e=new m(t);await t.addPlugin(e),t.addEmitterShape("circle",new i),t.addEmitterShape("square",new p)}})(),n})()));
2
+ !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var e="object"==typeof exports?i(require("@tsparticles/engine")):i(t.window);for(var s in e)("object"==typeof exports?exports:t)[s]=e[s]}}(this,(t=>(()=>{"use strict";var i={533:i=>{i.exports=t}},e={};function s(t){var n=e[t];if(void 0!==n)return n.exports;var o=e[t]={exports:{}};return i[t](o,o.exports,s),o.exports}s.d=(t,i)=>{for(var e in i)s.o(i,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},s.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{loadEmittersPlugin:()=>y});var t=s(533);class i{randomPosition(i,e,s){const[n,o]=[e.width/2,e.height/2],a=((i,e)=>{const s=(0,t.getRandom)()/4,n=Math.atan(e/i*Math.tan(2*Math.PI*s)),o=(0,t.getRandom)();return o<.25?n:o<.5?Math.PI-n:o<.75?Math.PI+n:-n})(n,o),r=(c=a,(l=n)*(d=o)/Math.sqrt((d*Math.cos(c))**2+(l*Math.sin(c))**2)),h=s?r*Math.sqrt((0,t.getRandom)()):r;var l,d,c;return{x:i.x+h*Math.cos(a),y:i.y+h*Math.sin(a)}}}class e{constructor(){this.wait=!1}load(i){i&&(void 0!==i.count&&(this.count=i.count),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)),void 0!==i.duration&&(this.duration=(0,t.setRangeValue)(i.duration)),void 0!==i.wait&&(this.wait=i.wait))}}class o{constructor(){this.quantity=1,this.delay=.1}load(i){void 0!==i&&(void 0!==i.quantity&&(this.quantity=(0,t.setRangeValue)(i.quantity)),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)))}}class a{constructor(){this.mode="percent",this.height=0,this.width=0}load(t){void 0!==t&&(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}class r{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new o,this.shape="square",this.startCount=0}load(i){i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(this.size||(this.size=new a),this.size.load(i.size)),void 0!==i.direction&&(this.direction=i.direction),this.domId=i.domId,void 0!==i.fill&&(this.fill=i.fill),this.life.load(i.life),this.name=i.name,this.particles=(0,t.executeOnSingleOrMultiple)(i.particles,(i=>(0,t.deepExtend)({},i))),this.rate.load(i.rate),void 0!==i.shape&&(this.shape=i.shape),void 0!==i.position&&(this.position={},void 0!==i.position.x&&(this.position.x=(0,t.setRangeValue)(i.position.x)),void 0!==i.position.y&&(this.position.y=(0,t.setRangeValue)(i.position.y))),void 0!==i.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new t.AnimatableColor),this.spawnColor.load(i.spawnColor)),void 0!==i.startCount&&(this.startCount=i.startCount))}}class h{constructor(i,e,s,n,o){this.emitters=e,this.container=s,this._calcPosition=()=>(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position}),this._destroy=()=>{this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},this._emit=()=>{if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);this._emitParticles(i)},this._emitParticles=i=>{const e=this.getPosition(),s=this.getSize(),n=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let o=0;o<i;o++){const i=(0,t.deepExtend)({},n);if(this.spawnColor){const t=this.options.spawnColor?.animation;t&&(this.spawnColor.h=this._setColorAnimation(t.h,this.spawnColor.h,360),this.spawnColor.s=this._setColorAnimation(t.s,this.spawnColor.s,100),this.spawnColor.l=this._setColorAnimation(t.l,this.spawnColor.l,100)),i.color?i.color.value=this.spawnColor:i.color={value:this.spawnColor}}if(!e)return;const o=this._shape?.randomPosition(e,s,this.fill)??e;this.container.particles.addParticle(o,i)}},this._prepareToDie=()=>{if(this._paused)return;const i=void 0!==this.options.life?.duration?(0,t.getRangeValue)(this.options.life.duration):void 0;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=1e3*i)},this._setColorAnimation=(i,e,s)=>{const n=this.container;if(!i.enable)return e;const o=(0,t.randomInRange)(i.offset),a=1e3*(0,t.getRangeValue)(this.options.rate.delay)/n.retina.reduceFactor;return(e+(0,t.getRangeValue)(i.speed??0)*n.fpsLimit/a+3.6*o)%s},this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=o,n instanceof r?this.options=n:(this.options=new r,this.options.load(n)),this._spawnDelay=1e3*(0,t.getRangeValue)(this.options.life.delay??0)/this.container.retina.reduceFactor,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this._shape=this._engine.emitterShapeManager?.getShape(this.options.shape),this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let h=(0,t.deepExtend)({},this.options.particles);h??={},h.move??={},h.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=h,this.size=this.options.size??(()=>{const t=new a;return t.load({height:0,mode:"percent",width:0}),t})(),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}getPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{x:(e.x+e.width/2)*t.retina.pixelRatio,y:(e.y+e.height/2)*t.retina.pixelRatio}}}return this.position}getSize(){const i=this.container;if(this.options.domId){const t=document.getElementById(this.options.domId);if(t){const e=t.getBoundingClientRect();return{width:e.width*i.retina.pixelRatio,height:e.height*i.retina.pixelRatio}}}return(0,t.getSize)(this.size,i.canvas.size)}pause(){this._paused||delete this._emitDelay}play(){if(!this._paused&&this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))){if(void 0===this._emitDelay){const i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=1e3*i/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}}resize(){const i=this._initialPosition;this.position=i&&(0,t.isPointInside)(i,this.container.canvas.size,t.Vector.origin)?i:this._calcPosition()}update(i){this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,this._emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=i.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,this._immortal||this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this._calcPosition(),this._spawnDelay=1e3*(0,t.getRangeValue)(this.options.life.delay??0)/this.container.retina.reduceFactor):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=i.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=i.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay)))}}class l{constructor(i,e){this.container=e,this._engine=i,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]},e.getEmitter=i=>void 0===i||(0,t.isNumber)(i)?this.array[i||0]:this.array.find((t=>t.name===i)),e.addEmitter=(t,i)=>this.addEmitter(t,i),e.removeEmitter=t=>{const i=e.getEmitter(t);i&&this.removeEmitter(i)},e.playEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPlay()},e.pauseEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPause()}}addEmitter(t,i){const e=new r;e.load(t);const s=new h(this._engine,this,this.container,e,i);return this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"!==i)return;let n;if(s&&(0,t.isArray)(s.value))if(s.value.length>0&&s.random.enable){n=[];const i=[];for(let e=0;e<s.random.count;e++){const o=(0,t.arrayRandomIndex)(s.value);i.includes(o)&&i.length<s.value.length?e--:(i.push(o),n.push((0,t.itemFromArray)(s.value,o)))}}else n=s.value;else n=s?.value;const o=n??e,a=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(o,(t=>{this.addEmitter(t,a)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters)if((0,t.isArray)(this.emitters))for(const t of this.emitters)this.addEmitter(t);else this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}const d=new Map;class c{constructor(t){this._engine=t}addShape(t,i){this.getShape(t)||d.set(t,i)}getShape(t){return d.get(t)}getSupportedShapes(){return d.keys()}}function u(i,e){return i+e*((0,t.getRandom)()-.5)}class p{randomPosition(i,e,s){if(s)return{x:u(i.x,e.width),y:u(i.y,e.height)};{const s=e.width/2,n=e.height/2,o=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-.5);switch(o){case 0:return{x:i.x+a*s,y:i.y-n};case 1:return{x:i.x-s,y:i.y+a*n};case 2:return{x:i.x+a*s,y:i.y+n};default:return{x:i.x+s,y:i.y+a*n}}}}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new l(this._engine,t)}loadOptions(i,e){if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;e?.emitters&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new r;return i.load(t),i})));const s=e?.interactivity?.modes?.emitters;if(s)if((0,t.isArray)(s))i.interactivity.modes.emitters={random:{count:1,enable:!0},value:s.map((t=>{const i=new r;return i.load(t),i}))};else{const e=s;if(void 0!==e.value)if((0,t.isArray)(e.value))i.interactivity.modes.emitters={random:{count:e.random.count??1,enable:e.random.enable??!1},value:e.value.map((t=>{const i=new r;return i.load(t),i}))};else{const t=new r;t.load(e.value),i.interactivity.modes.emitters={random:{count:e.random.count??1,enable:e.random.enable??!1},value:t}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new r}).value.load(s)}}}needsPlugin(i){if(!i)return!1;const e=i.emitters;return(0,t.isArray)(e)&&!!e.length||void 0!==e||!!i.interactivity?.events?.onClick?.mode&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function y(t,e=!0){t.emitterShapeManager||(t.emitterShapeManager=new c(t)),t.addEmitterShape||(t.addEmitterShape=(i,e)=>{t.emitterShapeManager?.addShape(i,e)});const s=new m(t);await t.addPlugin(s,e),t.addEmitterShape("circle",new i),t.addEmitterShape("square",new p)}})(),n})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
8
- */
1
+ /*! tsParticles Emitters Plugin v3.0.0-beta.0 by Matteo Bruni */
@@ -1,4 +1,4 @@
1
- import type { Container, ICoordinates, IDelta, IDimension, IHsl, RecursivePartial } from "@tsparticles/engine";
1
+ import { type Container, type ICoordinates, type IDelta, type IDimension, type IHsl, type RecursivePartial } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter";
3
3
  import type { Emitters } from "./Emitters";
4
4
  import type { EmittersEngine } from "./EmittersEngine";
@@ -37,10 +37,10 @@ export declare class EmitterInstance {
37
37
  play(): void;
38
38
  resize(): void;
39
39
  update(delta: IDelta): void;
40
- private calcPosition;
41
- private destroy;
42
- private emit;
43
- private emitParticles;
44
- private prepareToDie;
45
- private setColorAnimation;
40
+ private readonly _calcPosition;
41
+ private readonly _destroy;
42
+ private readonly _emit;
43
+ private readonly _emitParticles;
44
+ private readonly _prepareToDie;
45
+ private readonly _setColorAnimation;
46
46
  }
@@ -1,4 +1,4 @@
1
- import type { IContainerPlugin, ICoordinates, IDelta, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
1
+ import { type IContainerPlugin, type ICoordinates, type IDelta, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter";
3
3
  import type { EmitterContainer } from "./EmitterContainer";
4
4
  import { EmitterInstance } from "./EmitterInstance";
@@ -1,4 +1,6 @@
1
1
  export declare const enum EmitterShapeType {
2
2
  circle = "circle",
3
- square = "square"
3
+ polygon = "polygon",
4
+ square = "square",
5
+ star = "star"
4
6
  }
@@ -1,5 +1,4 @@
1
- import { AnimatableColor } from "@tsparticles/engine";
2
- import type { IOptionLoader, IParticlesOptions, IRangedCoordinates, MoveDirection, MoveDirectionAlt, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
1
+ import { AnimatableColor, type IOptionLoader, type IParticlesOptions, type IRangedCoordinates, type MoveDirection, type MoveDirectionAlt, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
3
2
  import { EmitterLife } from "./EmitterLife";
4
3
  import { EmitterRate } from "./EmitterRate";
5
4
  import { EmitterShapeType } from "../../Enums/EmitterShapeType";
@@ -1,9 +1,9 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { IEmitterLife } from "../Interfaces/IEmitterLife";
3
3
  export declare class EmitterLife implements IEmitterLife, IOptionLoader<IEmitterLife> {
4
4
  count?: number;
5
- delay?: number;
6
- duration?: number;
5
+ delay?: RangeValue;
6
+ duration?: RangeValue;
7
7
  wait: boolean;
8
8
  constructor();
9
9
  load(data?: RecursivePartial<IEmitterLife>): void;
@@ -1,4 +1,4 @@
1
- import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { IEmitterRate } from "../Interfaces/IEmitterRate";
3
3
  export declare class EmitterRate implements IEmitterRate, IOptionLoader<IEmitterRate> {
4
4
  delay: RangeValue;
@@ -1,9 +1,8 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, PixelMode, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { IEmitterSize } from "../Interfaces/IEmitterSize";
3
- import { SizeMode } from "@tsparticles/engine";
4
3
  export declare class EmitterSize implements IEmitterSize, IOptionLoader<IEmitterSize> {
5
4
  height: number;
6
- mode: SizeMode | keyof typeof SizeMode;
5
+ mode: PixelMode | keyof typeof PixelMode;
7
6
  width: number;
8
7
  constructor();
9
8
  load(data?: RecursivePartial<IEmitterSize>): void;
@@ -1,6 +1,7 @@
1
+ import type { RangeValue } from "@tsparticles/engine";
1
2
  export interface IEmitterLife {
2
3
  count?: number;
3
- delay?: number;
4
- duration?: number;
4
+ delay?: RangeValue;
5
+ duration?: RangeValue;
5
6
  wait: boolean;
6
7
  }