@tsparticles/preset-links 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
  }
@@ -657,12 +657,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
657
657
  }
658
658
  addEventListener(type, listener) {
659
659
  this.removeEventListener(type, listener);
660
- let arr = this.#listeners.get(type);
661
- if (!arr) {
662
- arr = [];
663
- this.#listeners.set(type, arr);
664
- }
665
- arr.push(listener);
660
+ const arr = this.#listeners.get(type);
661
+ this.#listeners.set(type, arr ? [...arr, listener] : [listener]);
666
662
  }
667
663
  dispatchEvent(type, args) {
668
664
  const listeners = this.#listeners.get(type);
@@ -694,7 +690,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
694
690
  this.#listeners.delete(type);
695
691
  }
696
692
  else {
697
- arr.splice(idx, deleteCount);
693
+ this.#listeners.set(type, [...arr.slice(minIndex, idx), ...arr.slice(idx + deleteCount)]);
698
694
  }
699
695
  }
700
696
  }
@@ -871,11 +867,13 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
871
867
  #domArray = [];
872
868
  #eventDispatcher = new EventDispatcher();
873
869
  #initialized = false;
870
+ #loadSequence = 0;
871
+ #loadSequences = new Map();
874
872
  get items() {
875
873
  return this.#domArray;
876
874
  }
877
875
  get version() {
878
- return "4.5.0";
876
+ return "4.5.2";
879
877
  }
880
878
  addEventListener(type, listener) {
881
879
  this.#eventDispatcher.addEventListener(type, listener);
@@ -905,44 +903,60 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
905
903
  return item;
906
904
  }
907
905
  async load(params) {
908
- await this.init();
909
906
  let domSourceElement;
910
907
  if (typeof HTMLElement !== "undefined" && params.element instanceof HTMLElement) {
911
908
  domSourceElement = params.element;
912
909
  }
913
- 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({
914
- dispatchCallback: (eventType, args) => {
915
- this.dispatchEvent(eventType, args);
916
- },
917
- id,
918
- onDestroy: (remove) => {
919
- if (!remove) {
920
- return;
921
- }
922
- const mainArr = this.items, idx = mainArr.indexOf(newItem);
923
- if (idx >= removeMinIndex) {
924
- mainArr.splice(idx, removeDeleteCount);
910
+ const id = params.id ?? domSourceElement?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, loadSequence = ++this.#loadSequence;
911
+ this.#loadSequences.set(id, loadSequence);
912
+ try {
913
+ await this.init();
914
+ const { Container } = await Promise.resolve().then(function () { return Container$1; }), { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
915
+ if (this.#loadSequences.get(id) !== loadSequence) {
916
+ return undefined;
917
+ }
918
+ const currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
919
+ dispatchCallback: (eventType, args) => {
920
+ this.dispatchEvent(eventType, args);
921
+ },
922
+ id,
923
+ onDestroy: (remove) => {
924
+ if (!remove) {
925
+ return;
926
+ }
927
+ const mainArr = this.items, idx = mainArr.indexOf(newItem);
928
+ if (idx >= removeMinIndex) {
929
+ mainArr.splice(idx, removeDeleteCount);
930
+ }
931
+ },
932
+ pluginManager: this.pluginManager,
933
+ sourceOptions: currentOptions,
934
+ });
935
+ if (oldIndex >= loadMinIndex) {
936
+ const old = this.item(oldIndex), deleteCount = old ? one : none;
937
+ if (old && !old.destroyed) {
938
+ old.destroy(false);
925
939
  }
926
- },
927
- pluginManager: this.pluginManager,
928
- sourceOptions: currentOptions,
929
- });
930
- if (oldIndex >= loadMinIndex) {
931
- const old = this.item(oldIndex), deleteCount = old ? one : none;
932
- if (old && !old.destroyed) {
933
- old.destroy(false);
940
+ items.splice(oldIndex, deleteCount, newItem);
941
+ }
942
+ else {
943
+ items.push(newItem);
944
+ }
945
+ const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
946
+ ? params.element
947
+ : getCanvasFromContainer(getDomContainer(id, domSourceElement));
948
+ newItem.canvas.loadCanvas(sourceCanvas);
949
+ await newItem.start();
950
+ if (newItem.destroyed) {
951
+ return undefined;
934
952
  }
935
- items.splice(oldIndex, deleteCount, newItem);
953
+ return newItem;
936
954
  }
937
- else {
938
- items.push(newItem);
955
+ finally {
956
+ if (this.#loadSequences.get(id) === loadSequence) {
957
+ this.#loadSequences.delete(id);
958
+ }
939
959
  }
940
- const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
941
- ? params.element
942
- : getCanvasFromContainer(getDomContainer(id, domSourceElement));
943
- newItem.canvas.loadCanvas(sourceCanvas);
944
- await newItem.start();
945
- return newItem;
946
960
  }
947
961
  async refresh(refresh = true) {
948
962
  if (!refresh) {
@@ -2329,6 +2343,13 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2329
2343
  }
2330
2344
  }
2331
2345
 
2346
+ function hasEnabledBlend(particleOptions) {
2347
+ if (!particleOptions || typeof particleOptions !== "object" || !("blend" in particleOptions)) {
2348
+ return false;
2349
+ }
2350
+ const blend = particleOptions.blend;
2351
+ return !!blend && typeof blend === "object" && "enable" in blend && !!blend.enable;
2352
+ }
2332
2353
  class BlendPlugin {
2333
2354
  id = "blend";
2334
2355
  async getPlugin(container) {
@@ -2350,12 +2371,31 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2350
2371
  options.blend.load(source?.blend);
2351
2372
  }
2352
2373
  needsPlugin(options) {
2353
- return !!options?.blend?.enable || !!options?.particles?.blend?.enable;
2374
+ if (options?.blend?.enable ||
2375
+ options?.particles?.blend?.enable ||
2376
+ Object.values(options?.particles?.groups ?? {}).some(hasEnabledBlend)) {
2377
+ return true;
2378
+ }
2379
+ const emitters = options?.["emitters"];
2380
+ let emitterList = [];
2381
+ if (Array.isArray(emitters)) {
2382
+ emitterList = emitters;
2383
+ }
2384
+ else if (emitters) {
2385
+ emitterList = [emitters];
2386
+ }
2387
+ return emitterList.some(emitter => {
2388
+ if (!emitter || typeof emitter !== "object" || !("particles" in emitter)) {
2389
+ return false;
2390
+ }
2391
+ const particles = emitter.particles;
2392
+ return Array.isArray(particles) ? particles.some(hasEnabledBlend) : hasEnabledBlend(particles);
2393
+ });
2354
2394
  }
2355
2395
  }
2356
2396
 
2357
2397
  async function loadBlendPlugin(engine) {
2358
- engine.checkVersion("4.5.0");
2398
+ engine.checkVersion("4.5.2");
2359
2399
  await engine.pluginManager.register(e => {
2360
2400
  e.pluginManager.addPlugin(new BlendPlugin());
2361
2401
  });
@@ -2392,7 +2432,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2392
2432
  }
2393
2433
 
2394
2434
  async function loadCircleShape(engine) {
2395
- engine.checkVersion("4.5.0");
2435
+ engine.checkVersion("4.5.2");
2396
2436
  await engine.pluginManager.register(e => {
2397
2437
  e.pluginManager.addShape(["circle"], () => {
2398
2438
  return Promise.resolve(new CircleDrawer());
@@ -2440,7 +2480,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2440
2480
  }
2441
2481
 
2442
2482
  async function loadHexColorPlugin(engine) {
2443
- engine.checkVersion("4.5.0");
2483
+ engine.checkVersion("4.5.2");
2444
2484
  await engine.pluginManager.register(e => {
2445
2485
  e.pluginManager.addColorManager("hex", new HexColorManager());
2446
2486
  });
@@ -2493,7 +2533,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2493
2533
  }
2494
2534
 
2495
2535
  async function loadHslColorPlugin(engine) {
2496
- engine.checkVersion("4.5.0");
2536
+ engine.checkVersion("4.5.2");
2497
2537
  await engine.pluginManager.register(e => {
2498
2538
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2499
2539
  });
@@ -2525,7 +2565,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2525
2565
  }
2526
2566
 
2527
2567
  async function loadMovePlugin(engine) {
2528
- engine.checkVersion("4.5.0");
2568
+ engine.checkVersion("4.5.2");
2529
2569
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
2530
2570
  addErrorMessages(ErrorMessages$1);
2531
2571
  }
@@ -2735,7 +2775,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
2735
2775
  }
2736
2776
 
2737
2777
  async function loadOpacityUpdater(engine) {
2738
- engine.checkVersion("4.5.0");
2778
+ engine.checkVersion("4.5.2");
2739
2779
  await engine.pluginManager.register(e => {
2740
2780
  e.pluginManager.addParticleUpdater("opacity", container => {
2741
2781
  return Promise.resolve(new OpacityUpdater(container));
@@ -3064,7 +3104,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3064
3104
  }
3065
3105
 
3066
3106
  async function loadOutModesUpdater(engine) {
3067
- engine.checkVersion("4.5.0");
3107
+ engine.checkVersion("4.5.2");
3068
3108
  await engine.pluginManager.register(e => {
3069
3109
  e.pluginManager.addParticleUpdater("outModes", container => {
3070
3110
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3143,7 +3183,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3143
3183
  }
3144
3184
 
3145
3185
  async function loadPaintUpdater(engine) {
3146
- engine.checkVersion("4.5.0");
3186
+ engine.checkVersion("4.5.2");
3147
3187
  await engine.pluginManager.register(e => {
3148
3188
  e.pluginManager.addParticleUpdater("paint", container => {
3149
3189
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3198,7 +3238,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3198
3238
  }
3199
3239
 
3200
3240
  async function loadRgbColorPlugin(engine) {
3201
- engine.checkVersion("4.5.0");
3241
+ engine.checkVersion("4.5.2");
3202
3242
  await engine.pluginManager.register(e => {
3203
3243
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3204
3244
  });
@@ -3283,7 +3323,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3283
3323
  }
3284
3324
 
3285
3325
  async function loadSizeUpdater(engine) {
3286
- engine.checkVersion("4.5.0");
3326
+ engine.checkVersion("4.5.2");
3287
3327
  await engine.pluginManager.register(e => {
3288
3328
  e.pluginManager.addParticleUpdater("size", container => {
3289
3329
  return Promise.resolve(new SizeUpdater(container));
@@ -3292,7 +3332,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3292
3332
  }
3293
3333
 
3294
3334
  async function loadBasic(engine) {
3295
- engine.checkVersion("4.5.0");
3335
+ engine.checkVersion("4.5.2");
3296
3336
  await engine.pluginManager.register(async (e) => {
3297
3337
  await Promise.all([
3298
3338
  loadBlendPlugin(e),
@@ -3498,7 +3538,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3498
3538
  const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
3499
3539
 
3500
3540
  async function loadInteractivityPlugin(engine) {
3501
- engine.checkVersion("4.5.0");
3541
+ engine.checkVersion("4.5.2");
3502
3542
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
3503
3543
  addErrorMessages(ErrorMessages);
3504
3544
  }
@@ -3538,8 +3578,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3538
3578
  this.#canvasSize = canvasSize;
3539
3579
  }
3540
3580
  contains(point) {
3541
- if (super.contains(point))
3581
+ if (super.contains(point)) {
3542
3582
  return true;
3583
+ }
3543
3584
  const { width, height } = this.#canvasSize, { x, y } = point;
3544
3585
  return (super.contains({ x: x - width, y }) ||
3545
3586
  super.contains({ x: x + width, y }) ||
@@ -3551,8 +3592,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3551
3592
  super.contains({ x: x + width, y: y - height }));
3552
3593
  }
3553
3594
  intersects(range) {
3554
- if (super.intersects(range))
3595
+ if (super.intersects(range)) {
3555
3596
  return true;
3597
+ }
3556
3598
  const { width, height } = this.#canvasSize, pos = range.position, shifts = [
3557
3599
  { x: -width, y: 0 },
3558
3600
  { x: width, y: 0 },
@@ -3573,11 +3615,40 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3573
3615
  const rect = range;
3574
3616
  shiftedRange = new Rectangle(shiftedPos.x, shiftedPos.y, rect.size.width, rect.size.height);
3575
3617
  }
3576
- if (super.intersects(shiftedRange))
3618
+ if (super.intersects(shiftedRange)) {
3577
3619
  return true;
3620
+ }
3578
3621
  }
3579
3622
  return false;
3580
3623
  }
3624
+ query(grid) {
3625
+ const { x, y } = this.position, { width, height } = this.#canvasSize, radius = this.radius, crossesLeft = x - radius <= originPoint.x, crossesRight = x + radius >= width, crossesTop = y - radius <= originPoint.y, crossesBottom = y + radius >= height;
3626
+ if (!crossesLeft && !crossesRight && !crossesTop && !crossesBottom) {
3627
+ return grid.query(this);
3628
+ }
3629
+ const xShifts = [originPoint.x], yShifts = [originPoint.y];
3630
+ if (crossesLeft) {
3631
+ xShifts.push(width);
3632
+ }
3633
+ if (crossesRight) {
3634
+ xShifts.push(-width);
3635
+ }
3636
+ if (crossesTop) {
3637
+ yShifts.push(height);
3638
+ }
3639
+ if (crossesBottom) {
3640
+ yShifts.push(-height);
3641
+ }
3642
+ const particles = new Set();
3643
+ for (const dx of xShifts) {
3644
+ for (const dy of yShifts) {
3645
+ for (const particle of grid.queryCircle({ x: x + dx, y: y + dy }, radius)) {
3646
+ particles.add(particle);
3647
+ }
3648
+ }
3649
+ }
3650
+ return [...particles];
3651
+ }
3581
3652
  }
3582
3653
 
3583
3654
  class LinksShadow {
@@ -3687,7 +3758,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3687
3758
  if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
3688
3759
  return;
3689
3760
  }
3690
- const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance$1, warp = linkOpt1.warp, range = warp ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new Circle(pos1.x, pos1.y, optDistance), query = container.particles.grid.query(range);
3761
+ const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance$1, warp = linkOpt1.warp, query = (warp
3762
+ ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize).query(container.particles.grid)
3763
+ : container.particles.grid.queryCircle(pos1, optDistance));
3691
3764
  for (const p2 of query) {
3692
3765
  const linkOpt2 = p2.options.links;
3693
3766
  if (p1 === p2 ||
@@ -3775,7 +3848,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3775
3848
  }
3776
3849
 
3777
3850
  async function loadParticlesLinksInteraction(engine) {
3778
- engine.checkVersion("4.5.0");
3851
+ engine.checkVersion("4.5.2");
3779
3852
  await engine.pluginManager.register((e) => {
3780
3853
  const pluginManager = e.pluginManager;
3781
3854
  ensureInteractivityPluginLoaded(e);
@@ -3997,7 +4070,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
3997
4070
  });
3998
4071
  }
3999
4072
  drawParticles(delta) {
4000
- const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
4073
+ const { particles, actualOptions } = this.#container;
4074
+ this.clear();
4001
4075
  particles.update(delta);
4002
4076
  this.draw(ctx => {
4003
4077
  const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
@@ -4019,9 +4093,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4019
4093
  }
4020
4094
  }
4021
4095
  for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
4022
- if (plugin !== clearedPlugin) {
4023
- plugin.canvasPaint?.();
4024
- }
4096
+ plugin.canvasPaint?.();
4025
4097
  }
4026
4098
  for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
4027
4099
  plugin.drawSettingsSetup?.(ctx, delta);
@@ -4111,6 +4183,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4111
4183
  ctx.clearRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
4112
4184
  });
4113
4185
  }
4186
+ updateBackgroundElement() {
4187
+ this.#resolveBackgroundElement();
4188
+ }
4114
4189
  #applyPostDrawUpdaters(particle) {
4115
4190
  for (const updater of this.#postDrawUpdaters) {
4116
4191
  updater.afterDraw?.(particle);
@@ -4309,7 +4384,14 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4309
4384
  }
4310
4385
  if (typeof background.element === "string") {
4311
4386
  if (typeof document !== "undefined") {
4312
- const node = document.querySelector(background.element);
4387
+ let node;
4388
+ try {
4389
+ node = document.querySelector(background.element);
4390
+ }
4391
+ catch {
4392
+ this.#warnOnce("background-element-invalid-selector", `Background element selector "${background.element}" is invalid`);
4393
+ return;
4394
+ }
4313
4395
  if (node && this.#isSupportedElement(node)) {
4314
4396
  this.#backgroundElement = node;
4315
4397
  }
@@ -4755,6 +4837,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
4755
4837
  this.#manageListeners(true);
4756
4838
  }
4757
4839
  removeListeners() {
4840
+ if (this.#resizeTimeout !== undefined) {
4841
+ clearTimeout(this.#resizeTimeout);
4842
+ this.#resizeTimeout = undefined;
4843
+ }
4758
4844
  this.#manageListeners(false);
4759
4845
  }
4760
4846
  #handleVisibilityChange() {
@@ -5129,10 +5215,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5129
5215
  runParticleCreatedPlugins(container, this);
5130
5216
  }
5131
5217
  isInsideCanvas(direction) {
5132
- return this.#getInsideCanvasResult({ direction }).inside;
5218
+ return this.#getInsideCanvasResult(direction).inside;
5133
5219
  }
5134
5220
  isInsideCanvasForOutMode(outMode, direction) {
5135
- return this.#getInsideCanvasResult({ direction, outMode }).inside;
5221
+ return this.#getInsideCanvasResult(direction, outMode).inside;
5136
5222
  }
5137
5223
  isShowingBack() {
5138
5224
  if (!this.roll) {
@@ -5249,7 +5335,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5249
5335
  });
5250
5336
  }
5251
5337
  #getDefaultInsideCanvasResult(direction, outMode) {
5252
- const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
5338
+ const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce || outMode === OutMode.split;
5253
5339
  if (direction === OutModeDirection.bottom) {
5254
5340
  return {
5255
5341
  inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
@@ -5291,12 +5377,16 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5291
5377
  radius: this.getRadius(),
5292
5378
  };
5293
5379
  }
5294
- #getInsideCanvasResult(data) {
5295
- 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;
5296
- if (!shapeCheck && !effectCheck) {
5380
+ #getInsideCanvasResult(direction, outMode) {
5381
+ 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;
5382
+ if (!shapeDrawer?.isInsideCanvas && !effectDrawer?.isInsideCanvas) {
5297
5383
  return defaultResult;
5298
5384
  }
5299
- const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
5385
+ const callbackData = this.#getInsideCanvasCallbackData(direction, outMode), shapeResult = shapeDrawer?.isInsideCanvas
5386
+ ? this.#normalizeInsideCanvasResult(shapeDrawer.isInsideCanvas(callbackData), "shape")
5387
+ : undefined, effectResult = effectDrawer?.isInsideCanvas
5388
+ ? this.#normalizeInsideCanvasResult(effectDrawer.isInsideCanvas(callbackData), "effect")
5389
+ : undefined;
5300
5390
  if (shapeResult && effectResult) {
5301
5391
  const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
5302
5392
  return {
@@ -5362,8 +5452,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5362
5452
  }
5363
5453
 
5364
5454
  class SpatialHashGrid {
5365
- #cellSize;
5366
5455
  #cells = new Map();
5456
+ #cellSize;
5367
5457
  #circlePool = [];
5368
5458
  #circlePoolIdx;
5369
5459
  #pendingCellSize;
@@ -5409,14 +5499,22 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5409
5499
  return out;
5410
5500
  }
5411
5501
  queryCircle(position, radius, check, out = []) {
5412
- const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
5413
- this.#releaseShapes();
5414
- return result;
5502
+ const circle = this.#acquireCircle(position.x, position.y, radius);
5503
+ try {
5504
+ return this.query(circle, check, out);
5505
+ }
5506
+ finally {
5507
+ this.#circlePoolIdx--;
5508
+ }
5415
5509
  }
5416
5510
  queryRectangle(position, size, check, out = []) {
5417
- const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
5418
- this.#releaseShapes();
5419
- return result;
5511
+ const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height);
5512
+ try {
5513
+ return this.query(rect, check, out);
5514
+ }
5515
+ finally {
5516
+ this.#rectanglePoolIdx--;
5517
+ }
5420
5518
  }
5421
5519
  #acquireCircle(x, y, r) {
5422
5520
  const idx = this.#circlePoolIdx++;
@@ -5475,10 +5573,6 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
5475
5573
  }
5476
5574
  }
5477
5575
  }
5478
- #releaseShapes() {
5479
- this.#circlePoolIdx = 0;
5480
- this.#rectanglePoolIdx = 0;
5481
- }
5482
5576
  }
5483
5577
 
5484
5578
  class ParticlesManager {
@@ -6017,8 +6111,8 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6017
6111
  particleCreatedPlugins;
6018
6112
  particleDestroyedPlugins;
6019
6113
  particlePositionPlugins;
6020
- particleUpdaters;
6021
6114
  particles;
6115
+ particleUpdaters;
6022
6116
  peakNits;
6023
6117
  plugins;
6024
6118
  retina;
@@ -6026,6 +6120,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6026
6120
  started;
6027
6121
  zLayers;
6028
6122
  #delay;
6123
+ #delayResolve;
6029
6124
  #delayTimeout;
6030
6125
  #delta = { value: 0, factor: 0 };
6031
6126
  #dispatchCallback;
@@ -6264,7 +6359,10 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6264
6359
  await this.init();
6265
6360
  this.started = true;
6266
6361
  await new Promise(resolve => {
6362
+ this.#delayResolve = resolve;
6267
6363
  const start = async () => {
6364
+ this.#delayTimeout = undefined;
6365
+ this.#delayResolve = undefined;
6268
6366
  this.#eventListeners.addListeners();
6269
6367
  for (const plugin of this.plugins) {
6270
6368
  await plugin.start?.();
@@ -6280,9 +6378,11 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6280
6378
  if (!guardCheck(this) || !this.started) {
6281
6379
  return;
6282
6380
  }
6283
- if (this.#delayTimeout) {
6381
+ if (this.#delayTimeout !== undefined) {
6284
6382
  clearTimeout(this.#delayTimeout);
6285
6383
  this.#delayTimeout = undefined;
6384
+ this.#delayResolve?.();
6385
+ this.#delayResolve = undefined;
6286
6386
  }
6287
6387
  this.#firstStart = true;
6288
6388
  this.started = false;
@@ -6306,6 +6406,7 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6306
6406
  refresh = plugin.updateActualOptions() || refresh;
6307
6407
  }
6308
6408
  }
6409
+ this.canvas.render.updateBackgroundElement();
6309
6410
  return refresh;
6310
6411
  }
6311
6412
  #initPlugins(allContainerPlugins) {
@@ -6716,7 +6817,9 @@ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6716
6817
  manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
6717
6818
  manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
6718
6819
  manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
6719
- manageListener(interactivityEl, touchEndEvent, options.interactivity?.events.onClick.enable ? handlers.touchEndClick : handlers.touchEnd, add);
6820
+ const onClickEnabled = !!options.interactivity?.events.onClick.enable;
6821
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add && onClickEnabled);
6822
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add && !onClickEnabled);
6720
6823
  manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
6721
6824
  manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
6722
6825
  manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);