@tsparticles/all 3.0.0 → 3.0.2

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.
@@ -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
7
+ * v3.0.2
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -3900,6 +3900,12 @@ class Particle {
3900
3900
  updater.particleDestroyed && updater.particleDestroyed(this, override);
3901
3901
  }
3902
3902
  pathGenerator && pathGenerator.reset(this);
3903
+ this._engine.dispatchEvent("particleDestroyed", {
3904
+ container: this.container,
3905
+ data: {
3906
+ particle: this
3907
+ }
3908
+ });
3903
3909
  }
3904
3910
  draw(delta) {
3905
3911
  const container = this.container,
@@ -4252,12 +4258,17 @@ const qTreeRectangle = canvasSize => {
4252
4258
  };
4253
4259
  class Particles {
4254
4260
  constructor(engine, container) {
4261
+ this._addToPool = (...particles) => {
4262
+ for (const particle of particles) {
4263
+ this._pool.push(particle);
4264
+ }
4265
+ };
4255
4266
  this._applyDensity = (options, manualCount, group) => {
4256
4267
  const numberOptions = options.number;
4257
4268
  if (!options.number.density?.enable) {
4258
4269
  if (group === undefined) {
4259
4270
  this._limit = numberOptions.limit.value;
4260
- } else {
4271
+ } else if (numberOptions.limit) {
4261
4272
  this._groupLimits.set(group, numberOptions.limit.value);
4262
4273
  }
4263
4274
  return;
@@ -4322,17 +4333,17 @@ class Particles {
4322
4333
  if (!particle || particle.group !== group) {
4323
4334
  return false;
4324
4335
  }
4325
- particle.destroy(override);
4326
4336
  const zIdx = this._zArray.indexOf(particle);
4327
4337
  this._array.splice(index, 1);
4328
4338
  this._zArray.splice(zIdx, 1);
4329
- this._pool.push(particle);
4339
+ particle.destroy(override);
4330
4340
  this._engine.dispatchEvent("particleRemoved", {
4331
4341
  container: this._container,
4332
4342
  data: {
4333
4343
  particle
4334
4344
  }
4335
4345
  });
4346
+ this._addToPool(particle);
4336
4347
  return true;
4337
4348
  };
4338
4349
  this._engine = engine;
@@ -4530,7 +4541,15 @@ class Particles {
4530
4541
  const checkDelete = p => !particlesToDelete.has(p);
4531
4542
  this._array = this.filter(checkDelete);
4532
4543
  this._zArray = this._zArray.filter(checkDelete);
4533
- this._pool.push(...particlesToDelete);
4544
+ for (const particle of particlesToDelete) {
4545
+ this._engine.dispatchEvent("particleRemoved", {
4546
+ container: this._container,
4547
+ data: {
4548
+ particle
4549
+ }
4550
+ });
4551
+ }
4552
+ this._addToPool(...particlesToDelete);
4534
4553
  }
4535
4554
  await this._interactionManager.externalInteract(delta);
4536
4555
  for (const particle of this._array) {
@@ -5146,7 +5165,7 @@ class Engine {
5146
5165
  return res;
5147
5166
  }
5148
5167
  get version() {
5149
- return "3.0.0";
5168
+ return "3.0.2";
5150
5169
  }
5151
5170
  addConfig(config) {
5152
5171
  const name = config.name ?? "default";
@@ -7684,6 +7703,7 @@ class EmitterInstance {
7684
7703
  }
7685
7704
  if (this._lifeCount > 0 || this._immortal) {
7686
7705
  this.position = this._calcPosition();
7706
+ this._shape?.resize(this.position, this.size);
7687
7707
  this._spawnDelay = getRangeValue(this.options.life.delay ?? 0) * 1000 / this.container.retina.reduceFactor;
7688
7708
  } else {
7689
7709
  this._destroy();
@@ -19929,32 +19949,35 @@ class SoundsInstance {
19929
19949
  return;
19930
19950
  }
19931
19951
  for (const event of soundsOptions.events) {
19932
- const cb = async args => {
19933
- if (this._container !== args.container) {
19934
- return;
19935
- }
19936
- if (!this._container || this._container.muted || this._container.destroyed) {
19937
- executeOnSingleOrMultiple(event.event, item => {
19938
- this._engine.removeEventListener(item, cb);
19939
- });
19940
- return;
19941
- }
19942
- if (event.filter && !event.filter(args)) {
19943
- return;
19944
- }
19945
- if (event.audio) {
19946
- this._playBuffer(itemFromSingleOrMultiple(event.audio));
19947
- } else if (event.melodies) {
19948
- const melody = itemFromArray(event.melodies);
19949
- if (melody.melodies.length) {
19950
- await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, 0, melody.loop)));
19951
- } else {
19952
- await this._playNote(melody.notes, 0, melody.loop);
19952
+ const cb = args => {
19953
+ (async () => {
19954
+ const filterNotValid = event.filter && !event.filter(args);
19955
+ if (this._container !== args.container) {
19956
+ return;
19953
19957
  }
19954
- } else if (event.notes) {
19955
- const note = itemFromArray(event.notes);
19956
- await this._playNote([note], 0, false);
19957
- }
19958
+ if (!this._container || this._container.muted || this._container.destroyed) {
19959
+ executeOnSingleOrMultiple(event.event, item => {
19960
+ this._engine.removeEventListener(item, cb);
19961
+ });
19962
+ return;
19963
+ }
19964
+ if (filterNotValid) {
19965
+ return;
19966
+ }
19967
+ if (event.audio) {
19968
+ this._playBuffer(itemFromSingleOrMultiple(event.audio));
19969
+ } else if (event.melodies) {
19970
+ const melody = itemFromArray(event.melodies);
19971
+ if (melody.melodies.length) {
19972
+ await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, 0, melody.loop)));
19973
+ } else {
19974
+ await this._playNote(melody.notes, 0, melody.loop);
19975
+ }
19976
+ } else if (event.notes) {
19977
+ const note = itemFromArray(event.notes);
19978
+ await this._playNote([note], 0, false);
19979
+ }
19980
+ })();
19958
19981
  };
19959
19982
  executeOnSingleOrMultiple(event.event, item => {
19960
19983
  this._engine.addEventListener(item, cb);
@@ -20107,16 +20130,18 @@ class SoundsInstance {
20107
20130
  unmuteImg.style.display = container.muted ? "none" : "block";
20108
20131
  }
20109
20132
  };
20110
- this._updateMuteStatus = () => {
20133
+ this._updateMuteStatus = async () => {
20111
20134
  const container = this._container;
20112
20135
  if (container.muted) {
20136
+ await container.audioContext?.suspend();
20113
20137
  this._mute();
20114
20138
  } else {
20139
+ await container.audioContext?.resume();
20115
20140
  this._unmute();
20116
20141
  this._playMuteSound();
20117
20142
  }
20118
20143
  };
20119
- this._updateVolume = () => {
20144
+ this._updateVolume = async () => {
20120
20145
  const container = this._container,
20121
20146
  soundsOptions = container.actualOptions.sounds;
20122
20147
  if (!soundsOptions?.enable) {
@@ -20134,7 +20159,7 @@ class SoundsInstance {
20134
20159
  }
20135
20160
  if (stateChanged) {
20136
20161
  this._updateMuteIcons();
20137
- this._updateMuteStatus();
20162
+ await this._updateMuteStatus();
20138
20163
  }
20139
20164
  if (this._gain?.gain) {
20140
20165
  this._gain.gain.value = this._volume / 100;
@@ -20192,10 +20217,10 @@ class SoundsInstance {
20192
20217
  volumeUp
20193
20218
  } = soundsOptions.icons,
20194
20219
  margin = 10;
20195
- const toggleMute = () => {
20220
+ const toggleMute = async () => {
20196
20221
  container.muted = !container.muted;
20197
20222
  this._updateMuteIcons();
20198
- this._updateMuteStatus();
20223
+ await this._updateMuteStatus();
20199
20224
  };
20200
20225
  this._muteImg = initImage({
20201
20226
  container,
@@ -20225,12 +20250,12 @@ class SoundsInstance {
20225
20250
  iconOptions: volumeDown,
20226
20251
  margin,
20227
20252
  rightOffsets: [volumeUp.width],
20228
- clickCb: () => {
20253
+ clickCb: async () => {
20229
20254
  if (container.muted) {
20230
20255
  this._volume = 0;
20231
20256
  }
20232
20257
  this._volume -= soundsOptions.volume.step;
20233
- this._updateVolume();
20258
+ await this._updateVolume();
20234
20259
  }
20235
20260
  });
20236
20261
  this._volumeUpImg = initImage({
@@ -20241,12 +20266,12 @@ class SoundsInstance {
20241
20266
  iconOptions: volumeUp,
20242
20267
  margin,
20243
20268
  rightOffsets: [],
20244
- clickCb: () => {
20269
+ clickCb: async () => {
20245
20270
  if (container.muted) {
20246
20271
  this._volume = 0;
20247
20272
  }
20248
20273
  this._volume += soundsOptions.volume.step;
20249
- this._updateVolume();
20274
+ await this._updateVolume();
20250
20275
  }
20251
20276
  });
20252
20277
  }