@tsparticles/preset-firefly 4.5.0 → 4.5.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.
@@ -1,6 +1,6 @@
1
1
  (function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
2
2
  (function (g) {
3
- /* Preset v4.5.0 */
3
+ /* Preset v4.5.2 */
4
4
  g.__tsParticlesInternals = g.__tsParticlesInternals || {};
5
5
  g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6
6
  (function (exports) {
@@ -120,7 +120,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
120
120
  }
121
121
  normalize() {
122
122
  const length = this.length;
123
- if (length != none) {
123
+ if (length !== none) {
124
124
  this.multTo(inverseFactorNumerator / length);
125
125
  }
126
126
  }
@@ -654,12 +654,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
654
654
  }
655
655
  addEventListener(type, listener) {
656
656
  this.removeEventListener(type, listener);
657
- let arr = this.#listeners.get(type);
658
- if (!arr) {
659
- arr = [];
660
- this.#listeners.set(type, arr);
661
- }
662
- arr.push(listener);
657
+ const arr = this.#listeners.get(type);
658
+ this.#listeners.set(type, arr ? [...arr, listener] : [listener]);
663
659
  }
664
660
  dispatchEvent(type, args) {
665
661
  const listeners = this.#listeners.get(type);
@@ -691,7 +687,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
691
687
  this.#listeners.delete(type);
692
688
  }
693
689
  else {
694
- arr.splice(idx, deleteCount);
690
+ this.#listeners.set(type, [...arr.slice(minIndex, idx), ...arr.slice(idx + deleteCount)]);
695
691
  }
696
692
  }
697
693
  }
@@ -868,11 +864,13 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
868
864
  #domArray = [];
869
865
  #eventDispatcher = new EventDispatcher();
870
866
  #initialized = false;
867
+ #loadSequence = 0;
868
+ #loadSequences = new Map();
871
869
  get items() {
872
870
  return this.#domArray;
873
871
  }
874
872
  get version() {
875
- return "4.5.0";
873
+ return "4.5.2";
876
874
  }
877
875
  addEventListener(type, listener) {
878
876
  this.#eventDispatcher.addEventListener(type, listener);
@@ -902,44 +900,60 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
902
900
  return item;
903
901
  }
904
902
  async load(params) {
905
- await this.init();
906
903
  let domSourceElement;
907
904
  if (typeof HTMLElement !== "undefined" && params.element instanceof HTMLElement) {
908
905
  domSourceElement = params.element;
909
906
  }
910
- const { Container } = await Promise.resolve().then(function () { return Container$1; }), id = params.id ?? domSourceElement?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
911
- dispatchCallback: (eventType, args) => {
912
- this.dispatchEvent(eventType, args);
913
- },
914
- id,
915
- onDestroy: (remove) => {
916
- if (!remove) {
917
- return;
918
- }
919
- const mainArr = this.items, idx = mainArr.indexOf(newItem);
920
- if (idx >= removeMinIndex) {
921
- mainArr.splice(idx, removeDeleteCount);
907
+ const id = params.id ?? domSourceElement?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, loadSequence = ++this.#loadSequence;
908
+ this.#loadSequences.set(id, loadSequence);
909
+ try {
910
+ await this.init();
911
+ const { Container } = await Promise.resolve().then(function () { return Container$1; }), { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
912
+ if (this.#loadSequences.get(id) !== loadSequence) {
913
+ return undefined;
914
+ }
915
+ const currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
916
+ dispatchCallback: (eventType, args) => {
917
+ this.dispatchEvent(eventType, args);
918
+ },
919
+ id,
920
+ onDestroy: (remove) => {
921
+ if (!remove) {
922
+ return;
923
+ }
924
+ const mainArr = this.items, idx = mainArr.indexOf(newItem);
925
+ if (idx >= removeMinIndex) {
926
+ mainArr.splice(idx, removeDeleteCount);
927
+ }
928
+ },
929
+ pluginManager: this.pluginManager,
930
+ sourceOptions: currentOptions,
931
+ });
932
+ if (oldIndex >= loadMinIndex) {
933
+ const old = this.item(oldIndex), deleteCount = old ? one : none;
934
+ if (old && !old.destroyed) {
935
+ old.destroy(false);
922
936
  }
923
- },
924
- pluginManager: this.pluginManager,
925
- sourceOptions: currentOptions,
926
- });
927
- if (oldIndex >= loadMinIndex) {
928
- const old = this.item(oldIndex), deleteCount = old ? one : none;
929
- if (old && !old.destroyed) {
930
- old.destroy(false);
937
+ items.splice(oldIndex, deleteCount, newItem);
938
+ }
939
+ else {
940
+ items.push(newItem);
931
941
  }
932
- items.splice(oldIndex, deleteCount, newItem);
942
+ const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
943
+ ? params.element
944
+ : getCanvasFromContainer(getDomContainer(id, domSourceElement));
945
+ newItem.canvas.loadCanvas(sourceCanvas);
946
+ await newItem.start();
947
+ if (newItem.destroyed) {
948
+ return undefined;
949
+ }
950
+ return newItem;
933
951
  }
934
- else {
935
- items.push(newItem);
952
+ finally {
953
+ if (this.#loadSequences.get(id) === loadSequence) {
954
+ this.#loadSequences.delete(id);
955
+ }
936
956
  }
937
- const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
938
- ? params.element
939
- : getCanvasFromContainer(getDomContainer(id, domSourceElement));
940
- newItem.canvas.loadCanvas(sourceCanvas);
941
- await newItem.start();
942
- return newItem;
943
957
  }
944
958
  async refresh(refresh = true) {
945
959
  if (!refresh) {
@@ -2247,6 +2261,13 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2247
2261
  }
2248
2262
  }
2249
2263
 
2264
+ function hasEnabledBlend(particleOptions) {
2265
+ if (!particleOptions || typeof particleOptions !== "object" || !("blend" in particleOptions)) {
2266
+ return false;
2267
+ }
2268
+ const blend = particleOptions.blend;
2269
+ return !!blend && typeof blend === "object" && "enable" in blend && !!blend.enable;
2270
+ }
2250
2271
  class BlendPlugin {
2251
2272
  id = "blend";
2252
2273
  async getPlugin(container) {
@@ -2268,12 +2289,31 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2268
2289
  options.blend.load(source?.blend);
2269
2290
  }
2270
2291
  needsPlugin(options) {
2271
- return !!options?.blend?.enable || !!options?.particles?.blend?.enable;
2292
+ if (options?.blend?.enable ||
2293
+ options?.particles?.blend?.enable ||
2294
+ Object.values(options?.particles?.groups ?? {}).some(hasEnabledBlend)) {
2295
+ return true;
2296
+ }
2297
+ const emitters = options?.["emitters"];
2298
+ let emitterList = [];
2299
+ if (Array.isArray(emitters)) {
2300
+ emitterList = emitters;
2301
+ }
2302
+ else if (emitters) {
2303
+ emitterList = [emitters];
2304
+ }
2305
+ return emitterList.some(emitter => {
2306
+ if (!emitter || typeof emitter !== "object" || !("particles" in emitter)) {
2307
+ return false;
2308
+ }
2309
+ const particles = emitter.particles;
2310
+ return Array.isArray(particles) ? particles.some(hasEnabledBlend) : hasEnabledBlend(particles);
2311
+ });
2272
2312
  }
2273
2313
  }
2274
2314
 
2275
2315
  async function loadBlendPlugin(engine) {
2276
- engine.checkVersion("4.5.0");
2316
+ engine.checkVersion("4.5.2");
2277
2317
  await engine.pluginManager.register(e => {
2278
2318
  e.pluginManager.addPlugin(new BlendPlugin());
2279
2319
  });
@@ -2310,7 +2350,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2310
2350
  }
2311
2351
 
2312
2352
  async function loadCircleShape(engine) {
2313
- engine.checkVersion("4.5.0");
2353
+ engine.checkVersion("4.5.2");
2314
2354
  await engine.pluginManager.register(e => {
2315
2355
  e.pluginManager.addShape(["circle"], () => {
2316
2356
  return Promise.resolve(new CircleDrawer());
@@ -2358,7 +2398,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2358
2398
  }
2359
2399
 
2360
2400
  async function loadHexColorPlugin(engine) {
2361
- engine.checkVersion("4.5.0");
2401
+ engine.checkVersion("4.5.2");
2362
2402
  await engine.pluginManager.register(e => {
2363
2403
  e.pluginManager.addColorManager("hex", new HexColorManager());
2364
2404
  });
@@ -2411,7 +2451,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2411
2451
  }
2412
2452
 
2413
2453
  async function loadHslColorPlugin(engine) {
2414
- engine.checkVersion("4.5.0");
2454
+ engine.checkVersion("4.5.2");
2415
2455
  await engine.pluginManager.register(e => {
2416
2456
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2417
2457
  });
@@ -2443,7 +2483,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2443
2483
  }
2444
2484
 
2445
2485
  async function loadMovePlugin(engine) {
2446
- engine.checkVersion("4.5.0");
2486
+ engine.checkVersion("4.5.2");
2447
2487
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
2448
2488
  addErrorMessages(ErrorMessages$1);
2449
2489
  }
@@ -2653,7 +2693,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2653
2693
  }
2654
2694
 
2655
2695
  async function loadOpacityUpdater(engine) {
2656
- engine.checkVersion("4.5.0");
2696
+ engine.checkVersion("4.5.2");
2657
2697
  await engine.pluginManager.register(e => {
2658
2698
  e.pluginManager.addParticleUpdater("opacity", container => {
2659
2699
  return Promise.resolve(new OpacityUpdater(container));
@@ -2982,7 +3022,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2982
3022
  }
2983
3023
 
2984
3024
  async function loadOutModesUpdater(engine) {
2985
- engine.checkVersion("4.5.0");
3025
+ engine.checkVersion("4.5.2");
2986
3026
  await engine.pluginManager.register(e => {
2987
3027
  e.pluginManager.addParticleUpdater("outModes", container => {
2988
3028
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3061,7 +3101,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3061
3101
  }
3062
3102
 
3063
3103
  async function loadPaintUpdater(engine) {
3064
- engine.checkVersion("4.5.0");
3104
+ engine.checkVersion("4.5.2");
3065
3105
  await engine.pluginManager.register(e => {
3066
3106
  e.pluginManager.addParticleUpdater("paint", container => {
3067
3107
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3116,7 +3156,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3116
3156
  }
3117
3157
 
3118
3158
  async function loadRgbColorPlugin(engine) {
3119
- engine.checkVersion("4.5.0");
3159
+ engine.checkVersion("4.5.2");
3120
3160
  await engine.pluginManager.register(e => {
3121
3161
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3122
3162
  });
@@ -3201,7 +3241,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3201
3241
  }
3202
3242
 
3203
3243
  async function loadSizeUpdater(engine) {
3204
- engine.checkVersion("4.5.0");
3244
+ engine.checkVersion("4.5.2");
3205
3245
  await engine.pluginManager.register(e => {
3206
3246
  e.pluginManager.addParticleUpdater("size", container => {
3207
3247
  return Promise.resolve(new SizeUpdater(container));
@@ -3210,7 +3250,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3210
3250
  }
3211
3251
 
3212
3252
  async function loadBasic(engine) {
3213
- engine.checkVersion("4.5.0");
3253
+ engine.checkVersion("4.5.2");
3214
3254
  await engine.pluginManager.register(async (e) => {
3215
3255
  await Promise.all([
3216
3256
  loadBlendPlugin(e),
@@ -3416,7 +3456,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3416
3456
  const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
3417
3457
 
3418
3458
  async function loadInteractivityPlugin(engine) {
3419
- engine.checkVersion("4.5.0");
3459
+ engine.checkVersion("4.5.2");
3420
3460
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
3421
3461
  addErrorMessages(ErrorMessages);
3422
3462
  }
@@ -3508,8 +3548,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3508
3548
  pauseOnStop = false;
3509
3549
  quantity = 1;
3510
3550
  load(data) {
3511
- if (isNull(data))
3551
+ if (isNull(data)) {
3512
3552
  return;
3553
+ }
3513
3554
  loadProperty(this, "delay", data.delay);
3514
3555
  loadProperty(this, "quantity", data.quantity);
3515
3556
  loadProperty(this, "pauseOnStop", data.pauseOnStop);
@@ -3540,17 +3581,20 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3540
3581
  }
3541
3582
  interact(interactivityData, delta) {
3542
3583
  const container = this.container;
3543
- if (!container.retina.reduceFactor)
3584
+ if (!container.retina.reduceFactor) {
3544
3585
  return;
3586
+ }
3545
3587
  const options = container.actualOptions, trailOptions = options.interactivity?.modes.trail;
3546
- if (!trailOptions)
3588
+ if (!trailOptions) {
3547
3589
  return;
3590
+ }
3548
3591
  const optDelay = (trailOptions.delay * millisecondsToSeconds) / this.container.retina.reduceFactor;
3549
3592
  if (this.#delay < optDelay) {
3550
3593
  this.#delay += delta.value;
3551
3594
  }
3552
- if (this.#delay < optDelay)
3595
+ if (this.#delay < optDelay) {
3553
3596
  return;
3597
+ }
3554
3598
  const mousePos = interactivityData.mouse.position, canEmit = !(trailOptions.pauseOnStop &&
3555
3599
  (mousePos === this.#lastPosition ||
3556
3600
  (mousePos?.x === this.#lastPosition?.x && mousePos?.y === this.#lastPosition?.y)));
@@ -3570,8 +3614,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3570
3614
  }, hasWeights = (comp) => {
3571
3615
  return !!(comp?.weights?.x ?? comp?.weights?.y);
3572
3616
  }, calculateValue = (comp, originalValue, defaultMax) => {
3573
- if (!hasWeights(comp))
3617
+ if (!hasWeights(comp)) {
3574
3618
  return undefined;
3619
+ }
3575
3620
  const w = comp?.weights, factor = norm.x * (w?.x ?? defaultWeight) + norm.y * (w?.y ?? defaultWeight), rangeSource = comp?.value ?? originalValue, min = getRangeMin(rangeSource ?? defaultMin), max = getRangeMax(rangeSource ?? defaultMax), result = min + factor * (max - min);
3576
3621
  return Math.min(max, Math.max(min, result));
3577
3622
  }, trailPaintOptions = trailOptions.particles?.paint
@@ -3613,7 +3658,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3613
3658
  }
3614
3659
 
3615
3660
  async function loadExternalTrailInteraction(engine) {
3616
- engine.checkVersion("4.5.0");
3661
+ engine.checkVersion("4.5.2");
3617
3662
  await engine.pluginManager.register((e) => {
3618
3663
  ensureInteractivityPluginLoaded(e);
3619
3664
  e.pluginManager.addInteractor?.("externalTrail", container => {
@@ -3697,7 +3742,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3697
3742
  particle.destroy();
3698
3743
  return;
3699
3744
  }
3700
- const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.width);
3745
+ const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.height);
3701
3746
  particle.position.x = randomInRangeValue(widthRange);
3702
3747
  particle.position.y = randomInRangeValue(heightRange);
3703
3748
  particle.spawning = true;
@@ -3759,7 +3804,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3759
3804
  }
3760
3805
 
3761
3806
  async function loadLifeUpdater(engine) {
3762
- engine.checkVersion("4.5.0");
3807
+ engine.checkVersion("4.5.2");
3763
3808
  await engine.pluginManager.register(e => {
3764
3809
  e.pluginManager.addParticleUpdater("life", container => {
3765
3810
  return Promise.resolve(new LifeUpdater(container));
@@ -4012,7 +4057,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4012
4057
  });
4013
4058
  }
4014
4059
  drawParticles(delta) {
4015
- const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
4060
+ const { particles, actualOptions } = this.#container;
4061
+ this.clear();
4016
4062
  particles.update(delta);
4017
4063
  this.draw(ctx => {
4018
4064
  const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
@@ -4034,9 +4080,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4034
4080
  }
4035
4081
  }
4036
4082
  for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
4037
- if (plugin !== clearedPlugin) {
4038
- plugin.canvasPaint?.();
4039
- }
4083
+ plugin.canvasPaint?.();
4040
4084
  }
4041
4085
  for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
4042
4086
  plugin.drawSettingsSetup?.(ctx, delta);
@@ -4126,6 +4170,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4126
4170
  ctx.clearRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
4127
4171
  });
4128
4172
  }
4173
+ updateBackgroundElement() {
4174
+ this.#resolveBackgroundElement();
4175
+ }
4129
4176
  #applyPostDrawUpdaters(particle) {
4130
4177
  for (const updater of this.#postDrawUpdaters) {
4131
4178
  updater.afterDraw?.(particle);
@@ -4324,7 +4371,14 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4324
4371
  }
4325
4372
  if (typeof background.element === "string") {
4326
4373
  if (typeof document !== "undefined") {
4327
- const node = document.querySelector(background.element);
4374
+ let node;
4375
+ try {
4376
+ node = document.querySelector(background.element);
4377
+ }
4378
+ catch {
4379
+ this.#warnOnce("background-element-invalid-selector", `Background element selector "${background.element}" is invalid`);
4380
+ return;
4381
+ }
4328
4382
  if (node && this.#isSupportedElement(node)) {
4329
4383
  this.#backgroundElement = node;
4330
4384
  }
@@ -4770,6 +4824,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4770
4824
  this.#manageListeners(true);
4771
4825
  }
4772
4826
  removeListeners() {
4827
+ if (this.#resizeTimeout !== undefined) {
4828
+ clearTimeout(this.#resizeTimeout);
4829
+ this.#resizeTimeout = undefined;
4830
+ }
4773
4831
  this.#manageListeners(false);
4774
4832
  }
4775
4833
  #handleVisibilityChange() {
@@ -5144,10 +5202,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5144
5202
  runParticleCreatedPlugins(container, this);
5145
5203
  }
5146
5204
  isInsideCanvas(direction) {
5147
- return this.#getInsideCanvasResult({ direction }).inside;
5205
+ return this.#getInsideCanvasResult(direction).inside;
5148
5206
  }
5149
5207
  isInsideCanvasForOutMode(outMode, direction) {
5150
- return this.#getInsideCanvasResult({ direction, outMode }).inside;
5208
+ return this.#getInsideCanvasResult(direction, outMode).inside;
5151
5209
  }
5152
5210
  isShowingBack() {
5153
5211
  if (!this.roll) {
@@ -5264,7 +5322,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5264
5322
  });
5265
5323
  }
5266
5324
  #getDefaultInsideCanvasResult(direction, outMode) {
5267
- const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
5325
+ const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce || outMode === OutMode.split;
5268
5326
  if (direction === OutModeDirection.bottom) {
5269
5327
  return {
5270
5328
  inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
@@ -5306,12 +5364,16 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5306
5364
  radius: this.getRadius(),
5307
5365
  };
5308
5366
  }
5309
- #getInsideCanvasResult(data) {
5310
- const defaultResult = this.#getDefaultInsideCanvasResult(data.direction, data.outMode), container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined, effectDrawer = this.effect ? container.effectDrawers.get(this.effect) : undefined, shapeCheck = shapeDrawer?.isInsideCanvas, effectCheck = effectDrawer?.isInsideCanvas;
5311
- if (!shapeCheck && !effectCheck) {
5367
+ #getInsideCanvasResult(direction, outMode) {
5368
+ const defaultResult = this.#getDefaultInsideCanvasResult(direction, outMode), container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined, effectDrawer = this.effect ? container.effectDrawers.get(this.effect) : undefined;
5369
+ if (!shapeDrawer?.isInsideCanvas && !effectDrawer?.isInsideCanvas) {
5312
5370
  return defaultResult;
5313
5371
  }
5314
- const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
5372
+ const callbackData = this.#getInsideCanvasCallbackData(direction, outMode), shapeResult = shapeDrawer?.isInsideCanvas
5373
+ ? this.#normalizeInsideCanvasResult(shapeDrawer.isInsideCanvas(callbackData), "shape")
5374
+ : undefined, effectResult = effectDrawer?.isInsideCanvas
5375
+ ? this.#normalizeInsideCanvasResult(effectDrawer.isInsideCanvas(callbackData), "effect")
5376
+ : undefined;
5315
5377
  if (shapeResult && effectResult) {
5316
5378
  const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
5317
5379
  return {
@@ -5377,8 +5439,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5377
5439
  }
5378
5440
 
5379
5441
  class SpatialHashGrid {
5380
- #cellSize;
5381
5442
  #cells = new Map();
5443
+ #cellSize;
5382
5444
  #circlePool = [];
5383
5445
  #circlePoolIdx;
5384
5446
  #pendingCellSize;
@@ -5424,14 +5486,22 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5424
5486
  return out;
5425
5487
  }
5426
5488
  queryCircle(position, radius, check, out = []) {
5427
- const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
5428
- this.#releaseShapes();
5429
- return result;
5489
+ const circle = this.#acquireCircle(position.x, position.y, radius);
5490
+ try {
5491
+ return this.query(circle, check, out);
5492
+ }
5493
+ finally {
5494
+ this.#circlePoolIdx--;
5495
+ }
5430
5496
  }
5431
5497
  queryRectangle(position, size, check, out = []) {
5432
- const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
5433
- this.#releaseShapes();
5434
- return result;
5498
+ const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height);
5499
+ try {
5500
+ return this.query(rect, check, out);
5501
+ }
5502
+ finally {
5503
+ this.#rectanglePoolIdx--;
5504
+ }
5435
5505
  }
5436
5506
  #acquireCircle(x, y, r) {
5437
5507
  const idx = this.#circlePoolIdx++;
@@ -5490,10 +5560,6 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5490
5560
  }
5491
5561
  }
5492
5562
  }
5493
- #releaseShapes() {
5494
- this.#circlePoolIdx = 0;
5495
- this.#rectanglePoolIdx = 0;
5496
- }
5497
5563
  }
5498
5564
 
5499
5565
  class ParticlesManager {
@@ -6032,8 +6098,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6032
6098
  particleCreatedPlugins;
6033
6099
  particleDestroyedPlugins;
6034
6100
  particlePositionPlugins;
6035
- particleUpdaters;
6036
6101
  particles;
6102
+ particleUpdaters;
6037
6103
  peakNits;
6038
6104
  plugins;
6039
6105
  retina;
@@ -6041,6 +6107,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6041
6107
  started;
6042
6108
  zLayers;
6043
6109
  #delay;
6110
+ #delayResolve;
6044
6111
  #delayTimeout;
6045
6112
  #delta = { value: 0, factor: 0 };
6046
6113
  #dispatchCallback;
@@ -6279,7 +6346,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6279
6346
  await this.init();
6280
6347
  this.started = true;
6281
6348
  await new Promise(resolve => {
6349
+ this.#delayResolve = resolve;
6282
6350
  const start = async () => {
6351
+ this.#delayTimeout = undefined;
6352
+ this.#delayResolve = undefined;
6283
6353
  this.#eventListeners.addListeners();
6284
6354
  for (const plugin of this.plugins) {
6285
6355
  await plugin.start?.();
@@ -6295,9 +6365,11 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6295
6365
  if (!guardCheck(this) || !this.started) {
6296
6366
  return;
6297
6367
  }
6298
- if (this.#delayTimeout) {
6368
+ if (this.#delayTimeout !== undefined) {
6299
6369
  clearTimeout(this.#delayTimeout);
6300
6370
  this.#delayTimeout = undefined;
6371
+ this.#delayResolve?.();
6372
+ this.#delayResolve = undefined;
6301
6373
  }
6302
6374
  this.#firstStart = true;
6303
6375
  this.started = false;
@@ -6321,6 +6393,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6321
6393
  refresh = plugin.updateActualOptions() || refresh;
6322
6394
  }
6323
6395
  }
6396
+ this.canvas.render.updateBackgroundElement();
6324
6397
  return refresh;
6325
6398
  }
6326
6399
  #initPlugins(allContainerPlugins) {
@@ -6731,7 +6804,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6731
6804
  manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
6732
6805
  manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
6733
6806
  manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
6734
- manageListener(interactivityEl, touchEndEvent, options.interactivity?.events.onClick.enable ? handlers.touchEndClick : handlers.touchEnd, add);
6807
+ const onClickEnabled = !!options.interactivity?.events.onClick.enable;
6808
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add && onClickEnabled);
6809
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add && !onClickEnabled);
6735
6810
  manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
6736
6811
  manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
6737
6812
  manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);