@tsparticles/all 3.0.1 → 3.0.3

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.1
7
+ * v3.0.3
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,6 +4258,11 @@ 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) {
@@ -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.1";
5168
+ return "3.0.3";
5150
5169
  }
5151
5170
  addConfig(config) {
5152
5171
  const name = config.name ?? "default";
@@ -5261,7 +5280,7 @@ class Engine {
5261
5280
  this._initialized = true;
5262
5281
  }
5263
5282
  async load(params) {
5264
- const id = params.id ?? `tsparticles${Math.floor(getRandom() * 10000)}`,
5283
+ const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * 10000)}`,
5265
5284
  {
5266
5285
  index,
5267
5286
  url
@@ -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();
@@ -10780,8 +10800,9 @@ class EmojiDrawer {
10780
10800
  this._emojiShapeDict = new Map();
10781
10801
  }
10782
10802
  destroy() {
10783
- for (const [, emojiData] of this._emojiShapeDict) {
10803
+ for (const [key, emojiData] of this._emojiShapeDict) {
10784
10804
  emojiData instanceof ImageBitmap && emojiData?.close();
10805
+ this._emojiShapeDict.delete(key);
10785
10806
  }
10786
10807
  }
10787
10808
  draw(data) {
@@ -10816,52 +10837,50 @@ class EmojiDrawer {
10816
10837
  delete particle.emojiData;
10817
10838
  }
10818
10839
  particleInit(container, particle) {
10819
- if (!particle.emojiData) {
10820
- const shapeData = particle.shapeData;
10821
- if (!shapeData?.value) {
10822
- return;
10823
- }
10824
- const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData),
10825
- font = shapeData.font ?? defaultFont;
10826
- if (!emoji) {
10840
+ const shapeData = particle.shapeData;
10841
+ if (!shapeData?.value) {
10842
+ return;
10843
+ }
10844
+ const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData),
10845
+ font = shapeData.font ?? defaultFont;
10846
+ if (!emoji) {
10847
+ return;
10848
+ }
10849
+ const key = `${emoji}_${font}`,
10850
+ existingData = this._emojiShapeDict.get(key);
10851
+ if (existingData) {
10852
+ particle.emojiData = existingData;
10853
+ return;
10854
+ }
10855
+ const canvasSize = getRangeMax(particle.size.value) * 2;
10856
+ let emojiData;
10857
+ if (typeof OffscreenCanvas !== "undefined") {
10858
+ const canvas = new OffscreenCanvas(canvasSize, canvasSize),
10859
+ context = canvas.getContext("2d");
10860
+ if (!context) {
10827
10861
  return;
10828
10862
  }
10829
- const key = `${emoji}_${font}`,
10830
- existingData = this._emojiShapeDict.get(key);
10831
- if (existingData) {
10832
- particle.emojiData = existingData;
10863
+ context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
10864
+ context.textBaseline = "middle";
10865
+ context.textAlign = "center";
10866
+ context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
10867
+ emojiData = canvas.transferToImageBitmap();
10868
+ } else {
10869
+ const canvas = document.createElement("canvas");
10870
+ canvas.width = canvasSize;
10871
+ canvas.height = canvasSize;
10872
+ const context = canvas.getContext("2d");
10873
+ if (!context) {
10833
10874
  return;
10834
10875
  }
10835
- const canvasSize = getRangeMax(particle.size.value) * 2;
10836
- let emojiData;
10837
- if (typeof OffscreenCanvas !== "undefined") {
10838
- const canvas = new OffscreenCanvas(canvasSize, canvasSize),
10839
- context = canvas.getContext("2d");
10840
- if (!context) {
10841
- return;
10842
- }
10843
- context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
10844
- context.textBaseline = "middle";
10845
- context.textAlign = "center";
10846
- context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
10847
- emojiData = canvas.transferToImageBitmap();
10848
- } else {
10849
- const canvas = document.createElement("canvas");
10850
- canvas.width = canvasSize;
10851
- canvas.height = canvasSize;
10852
- const context = canvas.getContext("2d");
10853
- if (!context) {
10854
- return;
10855
- }
10856
- context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
10857
- context.textBaseline = "middle";
10858
- context.textAlign = "center";
10859
- context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
10860
- emojiData = canvas;
10861
- }
10862
- this._emojiShapeDict.set(key, emojiData);
10863
- particle.emojiData = emojiData;
10876
+ context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
10877
+ context.textBaseline = "middle";
10878
+ context.textAlign = "center";
10879
+ context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
10880
+ emojiData = canvas;
10864
10881
  }
10882
+ this._emojiShapeDict.set(key, emojiData);
10883
+ particle.emojiData = emojiData;
10865
10884
  }
10866
10885
  }
10867
10886
  ;// CONCATENATED MODULE: ../../shapes/emoji/dist/browser/index.js
@@ -19929,32 +19948,35 @@ class SoundsInstance {
19929
19948
  return;
19930
19949
  }
19931
19950
  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);
19951
+ const cb = args => {
19952
+ (async () => {
19953
+ const filterNotValid = event.filter && !event.filter(args);
19954
+ if (this._container !== args.container) {
19955
+ return;
19953
19956
  }
19954
- } else if (event.notes) {
19955
- const note = itemFromArray(event.notes);
19956
- await this._playNote([note], 0, false);
19957
- }
19957
+ if (!this._container || this._container.muted || this._container.destroyed) {
19958
+ executeOnSingleOrMultiple(event.event, item => {
19959
+ this._engine.removeEventListener(item, cb);
19960
+ });
19961
+ return;
19962
+ }
19963
+ if (filterNotValid) {
19964
+ return;
19965
+ }
19966
+ if (event.audio) {
19967
+ this._playBuffer(itemFromSingleOrMultiple(event.audio));
19968
+ } else if (event.melodies) {
19969
+ const melody = itemFromArray(event.melodies);
19970
+ if (melody.melodies.length) {
19971
+ await Promise.allSettled(melody.melodies.map(m => this._playNote(m.notes, 0, melody.loop)));
19972
+ } else {
19973
+ await this._playNote(melody.notes, 0, melody.loop);
19974
+ }
19975
+ } else if (event.notes) {
19976
+ const note = itemFromArray(event.notes);
19977
+ await this._playNote([note], 0, false);
19978
+ }
19979
+ })();
19958
19980
  };
19959
19981
  executeOnSingleOrMultiple(event.event, item => {
19960
19982
  this._engine.addEventListener(item, cb);
@@ -20107,16 +20129,18 @@ class SoundsInstance {
20107
20129
  unmuteImg.style.display = container.muted ? "none" : "block";
20108
20130
  }
20109
20131
  };
20110
- this._updateMuteStatus = () => {
20132
+ this._updateMuteStatus = async () => {
20111
20133
  const container = this._container;
20112
20134
  if (container.muted) {
20135
+ await container.audioContext?.suspend();
20113
20136
  this._mute();
20114
20137
  } else {
20138
+ await container.audioContext?.resume();
20115
20139
  this._unmute();
20116
20140
  this._playMuteSound();
20117
20141
  }
20118
20142
  };
20119
- this._updateVolume = () => {
20143
+ this._updateVolume = async () => {
20120
20144
  const container = this._container,
20121
20145
  soundsOptions = container.actualOptions.sounds;
20122
20146
  if (!soundsOptions?.enable) {
@@ -20134,7 +20158,7 @@ class SoundsInstance {
20134
20158
  }
20135
20159
  if (stateChanged) {
20136
20160
  this._updateMuteIcons();
20137
- this._updateMuteStatus();
20161
+ await this._updateMuteStatus();
20138
20162
  }
20139
20163
  if (this._gain?.gain) {
20140
20164
  this._gain.gain.value = this._volume / 100;
@@ -20192,10 +20216,10 @@ class SoundsInstance {
20192
20216
  volumeUp
20193
20217
  } = soundsOptions.icons,
20194
20218
  margin = 10;
20195
- const toggleMute = () => {
20219
+ const toggleMute = async () => {
20196
20220
  container.muted = !container.muted;
20197
20221
  this._updateMuteIcons();
20198
- this._updateMuteStatus();
20222
+ await this._updateMuteStatus();
20199
20223
  };
20200
20224
  this._muteImg = initImage({
20201
20225
  container,
@@ -20225,12 +20249,12 @@ class SoundsInstance {
20225
20249
  iconOptions: volumeDown,
20226
20250
  margin,
20227
20251
  rightOffsets: [volumeUp.width],
20228
- clickCb: () => {
20252
+ clickCb: async () => {
20229
20253
  if (container.muted) {
20230
20254
  this._volume = 0;
20231
20255
  }
20232
20256
  this._volume -= soundsOptions.volume.step;
20233
- this._updateVolume();
20257
+ await this._updateVolume();
20234
20258
  }
20235
20259
  });
20236
20260
  this._volumeUpImg = initImage({
@@ -20241,12 +20265,12 @@ class SoundsInstance {
20241
20265
  iconOptions: volumeUp,
20242
20266
  margin,
20243
20267
  rightOffsets: [],
20244
- clickCb: () => {
20268
+ clickCb: async () => {
20245
20269
  if (container.muted) {
20246
20270
  this._volume = 0;
20247
20271
  }
20248
20272
  this._volume += soundsOptions.volume.step;
20249
- this._updateVolume();
20273
+ await this._updateVolume();
20250
20274
  }
20251
20275
  });
20252
20276
  }