@tsparticles/particles 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
- /* tsParticles v4.5.0 */
3
+ /* tsParticles v4.5.2 */
4
4
  g.__tsParticlesInternals = g.__tsParticlesInternals || {};
5
5
  g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6
6
  (function (exports) {
@@ -143,7 +143,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
143
143
  }
144
144
  normalize() {
145
145
  const length = this.length;
146
- if (length != none) {
146
+ if (length !== none) {
147
147
  this.multTo(inverseFactorNumerator / length);
148
148
  }
149
149
  }
@@ -737,12 +737,8 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
737
737
  }
738
738
  addEventListener(type, listener) {
739
739
  this.removeEventListener(type, listener);
740
- let arr = this.#listeners.get(type);
741
- if (!arr) {
742
- arr = [];
743
- this.#listeners.set(type, arr);
744
- }
745
- arr.push(listener);
740
+ const arr = this.#listeners.get(type);
741
+ this.#listeners.set(type, arr ? [...arr, listener] : [listener]);
746
742
  }
747
743
  dispatchEvent(type, args) {
748
744
  const listeners = this.#listeners.get(type);
@@ -774,7 +770,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
774
770
  this.#listeners.delete(type);
775
771
  }
776
772
  else {
777
- arr.splice(idx, deleteCount);
773
+ this.#listeners.set(type, [...arr.slice(minIndex, idx), ...arr.slice(idx + deleteCount)]);
778
774
  }
779
775
  }
780
776
  }
@@ -951,11 +947,13 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
951
947
  #domArray = [];
952
948
  #eventDispatcher = new EventDispatcher();
953
949
  #initialized = false;
950
+ #loadSequence = 0;
951
+ #loadSequences = new Map();
954
952
  get items() {
955
953
  return this.#domArray;
956
954
  }
957
955
  get version() {
958
- return "4.5.0";
956
+ return "4.5.2";
959
957
  }
960
958
  addEventListener(type, listener) {
961
959
  this.#eventDispatcher.addEventListener(type, listener);
@@ -985,44 +983,60 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
985
983
  return item;
986
984
  }
987
985
  async load(params) {
988
- await this.init();
989
986
  let domSourceElement;
990
987
  if (typeof HTMLElement !== "undefined" && params.element instanceof HTMLElement) {
991
988
  domSourceElement = params.element;
992
989
  }
993
- 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({
994
- dispatchCallback: (eventType, args) => {
995
- this.dispatchEvent(eventType, args);
996
- },
997
- id,
998
- onDestroy: (remove) => {
999
- if (!remove) {
1000
- return;
1001
- }
1002
- const mainArr = this.items, idx = mainArr.indexOf(newItem);
1003
- if (idx >= removeMinIndex) {
1004
- mainArr.splice(idx, removeDeleteCount);
990
+ const id = params.id ?? domSourceElement?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, loadSequence = ++this.#loadSequence;
991
+ this.#loadSequences.set(id, loadSequence);
992
+ try {
993
+ await this.init();
994
+ const { Container } = await Promise.resolve().then(function () { return Container$1; }), { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
995
+ if (this.#loadSequences.get(id) !== loadSequence) {
996
+ return undefined;
997
+ }
998
+ const currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
999
+ dispatchCallback: (eventType, args) => {
1000
+ this.dispatchEvent(eventType, args);
1001
+ },
1002
+ id,
1003
+ onDestroy: (remove) => {
1004
+ if (!remove) {
1005
+ return;
1006
+ }
1007
+ const mainArr = this.items, idx = mainArr.indexOf(newItem);
1008
+ if (idx >= removeMinIndex) {
1009
+ mainArr.splice(idx, removeDeleteCount);
1010
+ }
1011
+ },
1012
+ pluginManager: this.pluginManager,
1013
+ sourceOptions: currentOptions,
1014
+ });
1015
+ if (oldIndex >= loadMinIndex) {
1016
+ const old = this.item(oldIndex), deleteCount = old ? one : none;
1017
+ if (old && !old.destroyed) {
1018
+ old.destroy(false);
1005
1019
  }
1006
- },
1007
- pluginManager: this.pluginManager,
1008
- sourceOptions: currentOptions,
1009
- });
1010
- if (oldIndex >= loadMinIndex) {
1011
- const old = this.item(oldIndex), deleteCount = old ? one : none;
1012
- if (old && !old.destroyed) {
1013
- old.destroy(false);
1020
+ items.splice(oldIndex, deleteCount, newItem);
1014
1021
  }
1015
- items.splice(oldIndex, deleteCount, newItem);
1022
+ else {
1023
+ items.push(newItem);
1024
+ }
1025
+ const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
1026
+ ? params.element
1027
+ : getCanvasFromContainer(getDomContainer(id, domSourceElement));
1028
+ newItem.canvas.loadCanvas(sourceCanvas);
1029
+ await newItem.start();
1030
+ if (newItem.destroyed) {
1031
+ return undefined;
1032
+ }
1033
+ return newItem;
1016
1034
  }
1017
- else {
1018
- items.push(newItem);
1035
+ finally {
1036
+ if (this.#loadSequences.get(id) === loadSequence) {
1037
+ this.#loadSequences.delete(id);
1038
+ }
1019
1039
  }
1020
- const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
1021
- ? params.element
1022
- : getCanvasFromContainer(getDomContainer(id, domSourceElement));
1023
- newItem.canvas.loadCanvas(sourceCanvas);
1024
- await newItem.start();
1025
- return newItem;
1026
1040
  }
1027
1041
  async refresh(refresh = true) {
1028
1042
  if (!refresh) {
@@ -2495,6 +2509,13 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2495
2509
  }
2496
2510
  }
2497
2511
 
2512
+ function hasEnabledBlend(particleOptions) {
2513
+ if (!particleOptions || typeof particleOptions !== "object" || !("blend" in particleOptions)) {
2514
+ return false;
2515
+ }
2516
+ const blend = particleOptions.blend;
2517
+ return !!blend && typeof blend === "object" && "enable" in blend && !!blend.enable;
2518
+ }
2498
2519
  class BlendPlugin {
2499
2520
  id = "blend";
2500
2521
  async getPlugin(container) {
@@ -2516,12 +2537,31 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2516
2537
  options.blend.load(source?.blend);
2517
2538
  }
2518
2539
  needsPlugin(options) {
2519
- return !!options?.blend?.enable || !!options?.particles?.blend?.enable;
2540
+ if (options?.blend?.enable ||
2541
+ options?.particles?.blend?.enable ||
2542
+ Object.values(options?.particles?.groups ?? {}).some(hasEnabledBlend)) {
2543
+ return true;
2544
+ }
2545
+ const emitters = options?.["emitters"];
2546
+ let emitterList = [];
2547
+ if (Array.isArray(emitters)) {
2548
+ emitterList = emitters;
2549
+ }
2550
+ else if (emitters) {
2551
+ emitterList = [emitters];
2552
+ }
2553
+ return emitterList.some(emitter => {
2554
+ if (!emitter || typeof emitter !== "object" || !("particles" in emitter)) {
2555
+ return false;
2556
+ }
2557
+ const particles = emitter.particles;
2558
+ return Array.isArray(particles) ? particles.some(hasEnabledBlend) : hasEnabledBlend(particles);
2559
+ });
2520
2560
  }
2521
2561
  }
2522
2562
 
2523
2563
  async function loadBlendPlugin(engine) {
2524
- engine.checkVersion("4.5.0");
2564
+ engine.checkVersion("4.5.2");
2525
2565
  await engine.pluginManager.register(e => {
2526
2566
  e.pluginManager.addPlugin(new BlendPlugin());
2527
2567
  });
@@ -2558,7 +2598,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2558
2598
  }
2559
2599
 
2560
2600
  async function loadCircleShape(engine) {
2561
- engine.checkVersion("4.5.0");
2601
+ engine.checkVersion("4.5.2");
2562
2602
  await engine.pluginManager.register(e => {
2563
2603
  e.pluginManager.addShape(["circle"], () => {
2564
2604
  return Promise.resolve(new CircleDrawer());
@@ -2606,7 +2646,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2606
2646
  }
2607
2647
 
2608
2648
  async function loadHexColorPlugin(engine) {
2609
- engine.checkVersion("4.5.0");
2649
+ engine.checkVersion("4.5.2");
2610
2650
  await engine.pluginManager.register(e => {
2611
2651
  e.pluginManager.addColorManager("hex", new HexColorManager());
2612
2652
  });
@@ -2659,7 +2699,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2659
2699
  }
2660
2700
 
2661
2701
  async function loadHslColorPlugin(engine) {
2662
- engine.checkVersion("4.5.0");
2702
+ engine.checkVersion("4.5.2");
2663
2703
  await engine.pluginManager.register(e => {
2664
2704
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2665
2705
  });
@@ -2691,7 +2731,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2691
2731
  }
2692
2732
 
2693
2733
  async function loadMovePlugin(engine) {
2694
- engine.checkVersion("4.5.0");
2734
+ engine.checkVersion("4.5.2");
2695
2735
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
2696
2736
  addErrorMessages(ErrorMessages$2);
2697
2737
  }
@@ -2901,7 +2941,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
2901
2941
  }
2902
2942
 
2903
2943
  async function loadOpacityUpdater(engine) {
2904
- engine.checkVersion("4.5.0");
2944
+ engine.checkVersion("4.5.2");
2905
2945
  await engine.pluginManager.register(e => {
2906
2946
  e.pluginManager.addParticleUpdater("opacity", container => {
2907
2947
  return Promise.resolve(new OpacityUpdater(container));
@@ -3230,7 +3270,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3230
3270
  }
3231
3271
 
3232
3272
  async function loadOutModesUpdater(engine) {
3233
- engine.checkVersion("4.5.0");
3273
+ engine.checkVersion("4.5.2");
3234
3274
  await engine.pluginManager.register(e => {
3235
3275
  e.pluginManager.addParticleUpdater("outModes", container => {
3236
3276
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3309,7 +3349,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3309
3349
  }
3310
3350
 
3311
3351
  async function loadPaintUpdater(engine) {
3312
- engine.checkVersion("4.5.0");
3352
+ engine.checkVersion("4.5.2");
3313
3353
  await engine.pluginManager.register(e => {
3314
3354
  e.pluginManager.addParticleUpdater("paint", container => {
3315
3355
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3364,7 +3404,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3364
3404
  }
3365
3405
 
3366
3406
  async function loadRgbColorPlugin(engine) {
3367
- engine.checkVersion("4.5.0");
3407
+ engine.checkVersion("4.5.2");
3368
3408
  await engine.pluginManager.register(e => {
3369
3409
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3370
3410
  });
@@ -3449,7 +3489,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3449
3489
  }
3450
3490
 
3451
3491
  async function loadSizeUpdater(engine) {
3452
- engine.checkVersion("4.5.0");
3492
+ engine.checkVersion("4.5.2");
3453
3493
  await engine.pluginManager.register(e => {
3454
3494
  e.pluginManager.addParticleUpdater("size", container => {
3455
3495
  return Promise.resolve(new SizeUpdater(container));
@@ -3458,7 +3498,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3458
3498
  }
3459
3499
 
3460
3500
  async function loadBasic(engine) {
3461
- engine.checkVersion("4.5.0");
3501
+ engine.checkVersion("4.5.2");
3462
3502
  await engine.pluginManager.register(async (e) => {
3463
3503
  await Promise.all([
3464
3504
  loadBlendPlugin(e),
@@ -3664,7 +3704,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3664
3704
  const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
3665
3705
 
3666
3706
  async function loadInteractivityPlugin(engine) {
3667
- engine.checkVersion("4.5.0");
3707
+ engine.checkVersion("4.5.2");
3668
3708
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
3669
3709
  addErrorMessages(ErrorMessages$1);
3670
3710
  }
@@ -3821,7 +3861,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3821
3861
  return (Math.abs(Math.round(this.#ownerZ) - Math.round(neighbor.getPosition().z)) <= ownerRadius + neighbor.getRadius());
3822
3862
  };
3823
3863
  }
3824
- separateOverlaps(particle, position) {
3864
+ separateOverlaps(particle, position, margin, maxX, maxY) {
3825
3865
  const neighbors = this.#neighbors, particlePosition = particle.position;
3826
3866
  particlePosition.setTo(position);
3827
3867
  for (let iteration = 0; iteration < separationIterations; iteration++) {
@@ -3829,6 +3869,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3829
3869
  this.#projectPair(particle, neighbor);
3830
3870
  }
3831
3871
  }
3872
+ if (margin !== undefined && maxX !== undefined && maxY !== undefined) {
3873
+ clampToWalls(particlePosition, margin, maxX, maxY);
3874
+ }
3832
3875
  }
3833
3876
  solve(container, particle) {
3834
3877
  const collisionsOptions = particle.options.collisions;
@@ -3876,7 +3919,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3876
3919
  if (hasBounds) {
3877
3920
  clampToWalls(position, margin, maxX, maxY);
3878
3921
  }
3879
- this.separateOverlaps(particle, position);
3922
+ this.separateOverlaps(particle, position, hasBounds ? margin : undefined, maxX, maxY);
3880
3923
  this.#dampContacts(particle);
3881
3924
  if (hasBounds) {
3882
3925
  this.#cancelWallVelocity(particle, margin, maxX, maxY);
@@ -3929,10 +3972,10 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
3929
3972
  }
3930
3973
  }
3931
3974
  #queryNeighbors(container, particle, radius, maxNeighbors) {
3975
+ this.#neighbors.length = 0;
3932
3976
  if (radius <= minRadius || maxNeighbors <= minCount) {
3933
3977
  return;
3934
3978
  }
3935
- this.#neighbors.length = 0;
3936
3979
  container.particles.grid.queryCircle(particle.getPosition(), radius, this.#isNeighbor, this.#neighbors);
3937
3980
  }
3938
3981
  }
@@ -4116,7 +4159,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4116
4159
  }
4117
4160
 
4118
4161
  async function loadParticlesCollisionsInteraction(engine) {
4119
- engine.checkVersion("4.5.0");
4162
+ engine.checkVersion("4.5.2");
4120
4163
  if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
4121
4164
  addErrorMessages(ErrorMessages);
4122
4165
  }
@@ -4136,8 +4179,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4136
4179
  this.#canvasSize = canvasSize;
4137
4180
  }
4138
4181
  contains(point) {
4139
- if (super.contains(point))
4182
+ if (super.contains(point)) {
4140
4183
  return true;
4184
+ }
4141
4185
  const { width, height } = this.#canvasSize, { x, y } = point;
4142
4186
  return (super.contains({ x: x - width, y }) ||
4143
4187
  super.contains({ x: x + width, y }) ||
@@ -4149,8 +4193,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4149
4193
  super.contains({ x: x + width, y: y - height }));
4150
4194
  }
4151
4195
  intersects(range) {
4152
- if (super.intersects(range))
4196
+ if (super.intersects(range)) {
4153
4197
  return true;
4198
+ }
4154
4199
  const { width, height } = this.#canvasSize, pos = range.position, shifts = [
4155
4200
  { x: -width, y: 0 },
4156
4201
  { x: width, y: 0 },
@@ -4171,11 +4216,40 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4171
4216
  const rect = range;
4172
4217
  shiftedRange = new Rectangle(shiftedPos.x, shiftedPos.y, rect.size.width, rect.size.height);
4173
4218
  }
4174
- if (super.intersects(shiftedRange))
4219
+ if (super.intersects(shiftedRange)) {
4175
4220
  return true;
4221
+ }
4176
4222
  }
4177
4223
  return false;
4178
4224
  }
4225
+ query(grid) {
4226
+ 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;
4227
+ if (!crossesLeft && !crossesRight && !crossesTop && !crossesBottom) {
4228
+ return grid.query(this);
4229
+ }
4230
+ const xShifts = [originPoint.x], yShifts = [originPoint.y];
4231
+ if (crossesLeft) {
4232
+ xShifts.push(width);
4233
+ }
4234
+ if (crossesRight) {
4235
+ xShifts.push(-width);
4236
+ }
4237
+ if (crossesTop) {
4238
+ yShifts.push(height);
4239
+ }
4240
+ if (crossesBottom) {
4241
+ yShifts.push(-height);
4242
+ }
4243
+ const particles = new Set();
4244
+ for (const dx of xShifts) {
4245
+ for (const dy of yShifts) {
4246
+ for (const particle of grid.queryCircle({ x: x + dx, y: y + dy }, radius)) {
4247
+ particles.add(particle);
4248
+ }
4249
+ }
4250
+ }
4251
+ return [...particles];
4252
+ }
4179
4253
  }
4180
4254
 
4181
4255
  class LinksShadow {
@@ -4285,7 +4359,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4285
4359
  if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
4286
4360
  return;
4287
4361
  }
4288
- 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);
4362
+ const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance$1, warp = linkOpt1.warp, query = (warp
4363
+ ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize).query(container.particles.grid)
4364
+ : container.particles.grid.queryCircle(pos1, optDistance));
4289
4365
  for (const p2 of query) {
4290
4366
  const linkOpt2 = p2.options.links;
4291
4367
  if (p1 === p2 ||
@@ -4373,7 +4449,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4373
4449
  }
4374
4450
 
4375
4451
  async function loadParticlesLinksInteraction(engine) {
4376
- engine.checkVersion("4.5.0");
4452
+ engine.checkVersion("4.5.2");
4377
4453
  await engine.pluginManager.register((e) => {
4378
4454
  const pluginManager = e.pluginManager;
4379
4455
  ensureInteractivityPluginLoaded(e);
@@ -4386,7 +4462,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4386
4462
 
4387
4463
  let initPromise = null;
4388
4464
  async function doInitPlugins(engine) {
4389
- engine.checkVersion("4.5.0");
4465
+ engine.checkVersion("4.5.2");
4390
4466
  await engine.pluginManager.register(async (e) => {
4391
4467
  const loadParticlesInteractivity = async (e) => {
4392
4468
  await loadInteractivityPlugin(e);
@@ -4429,7 +4505,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4429
4505
  particles.init = async () => {
4430
4506
  await initPlugins(tsParticles);
4431
4507
  };
4432
- particles.version = "4.5.0";
4508
+ particles.version = "4.5.2";
4433
4509
  globalThis.particles = particles;
4434
4510
 
4435
4511
  const globalObject = globalThis;
@@ -4598,7 +4674,8 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4598
4674
  });
4599
4675
  }
4600
4676
  drawParticles(delta) {
4601
- const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
4677
+ const { particles, actualOptions } = this.#container;
4678
+ this.clear();
4602
4679
  particles.update(delta);
4603
4680
  this.draw(ctx => {
4604
4681
  const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
@@ -4620,9 +4697,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4620
4697
  }
4621
4698
  }
4622
4699
  for (const plugin of this.#getLayerPlugins(exports.DrawLayer.BackgroundMask)) {
4623
- if (plugin !== clearedPlugin) {
4624
- plugin.canvasPaint?.();
4625
- }
4700
+ plugin.canvasPaint?.();
4626
4701
  }
4627
4702
  for (const plugin of this.#getLayerPlugins(exports.DrawLayer.CanvasSetup)) {
4628
4703
  plugin.drawSettingsSetup?.(ctx, delta);
@@ -4712,6 +4787,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4712
4787
  ctx.clearRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
4713
4788
  });
4714
4789
  }
4790
+ updateBackgroundElement() {
4791
+ this.#resolveBackgroundElement();
4792
+ }
4715
4793
  #applyPostDrawUpdaters(particle) {
4716
4794
  for (const updater of this.#postDrawUpdaters) {
4717
4795
  updater.afterDraw?.(particle);
@@ -4910,7 +4988,14 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
4910
4988
  }
4911
4989
  if (typeof background.element === "string") {
4912
4990
  if (typeof document !== "undefined") {
4913
- const node = document.querySelector(background.element);
4991
+ let node;
4992
+ try {
4993
+ node = document.querySelector(background.element);
4994
+ }
4995
+ catch {
4996
+ this.#warnOnce("background-element-invalid-selector", `Background element selector "${background.element}" is invalid`);
4997
+ return;
4998
+ }
4914
4999
  if (node && this.#isSupportedElement(node)) {
4915
5000
  this.#backgroundElement = node;
4916
5001
  }
@@ -5356,6 +5441,10 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
5356
5441
  this.#manageListeners(true);
5357
5442
  }
5358
5443
  removeListeners() {
5444
+ if (this.#resizeTimeout !== undefined) {
5445
+ clearTimeout(this.#resizeTimeout);
5446
+ this.#resizeTimeout = undefined;
5447
+ }
5359
5448
  this.#manageListeners(false);
5360
5449
  }
5361
5450
  #handleVisibilityChange() {
@@ -5730,10 +5819,10 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
5730
5819
  runParticleCreatedPlugins(container, this);
5731
5820
  }
5732
5821
  isInsideCanvas(direction) {
5733
- return this.#getInsideCanvasResult({ direction }).inside;
5822
+ return this.#getInsideCanvasResult(direction).inside;
5734
5823
  }
5735
5824
  isInsideCanvasForOutMode(outMode, direction) {
5736
- return this.#getInsideCanvasResult({ direction, outMode }).inside;
5825
+ return this.#getInsideCanvasResult(direction, outMode).inside;
5737
5826
  }
5738
5827
  isShowingBack() {
5739
5828
  if (!this.roll) {
@@ -5850,7 +5939,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
5850
5939
  });
5851
5940
  }
5852
5941
  #getDefaultInsideCanvasResult(direction, outMode) {
5853
- const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === exports.OutMode.bounce;
5942
+ const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === exports.OutMode.bounce || outMode === exports.OutMode.split;
5854
5943
  if (direction === exports.OutModeDirection.bottom) {
5855
5944
  return {
5856
5945
  inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
@@ -5892,12 +5981,16 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
5892
5981
  radius: this.getRadius(),
5893
5982
  };
5894
5983
  }
5895
- #getInsideCanvasResult(data) {
5896
- 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;
5897
- if (!shapeCheck && !effectCheck) {
5984
+ #getInsideCanvasResult(direction, outMode) {
5985
+ 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;
5986
+ if (!shapeDrawer?.isInsideCanvas && !effectDrawer?.isInsideCanvas) {
5898
5987
  return defaultResult;
5899
5988
  }
5900
- const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
5989
+ const callbackData = this.#getInsideCanvasCallbackData(direction, outMode), shapeResult = shapeDrawer?.isInsideCanvas
5990
+ ? this.#normalizeInsideCanvasResult(shapeDrawer.isInsideCanvas(callbackData), "shape")
5991
+ : undefined, effectResult = effectDrawer?.isInsideCanvas
5992
+ ? this.#normalizeInsideCanvasResult(effectDrawer.isInsideCanvas(callbackData), "effect")
5993
+ : undefined;
5901
5994
  if (shapeResult && effectResult) {
5902
5995
  const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
5903
5996
  return {
@@ -5963,8 +6056,8 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
5963
6056
  }
5964
6057
 
5965
6058
  class SpatialHashGrid {
5966
- #cellSize;
5967
6059
  #cells = new Map();
6060
+ #cellSize;
5968
6061
  #circlePool = [];
5969
6062
  #circlePoolIdx;
5970
6063
  #pendingCellSize;
@@ -6010,14 +6103,22 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6010
6103
  return out;
6011
6104
  }
6012
6105
  queryCircle(position, radius, check, out = []) {
6013
- const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
6014
- this.#releaseShapes();
6015
- return result;
6106
+ const circle = this.#acquireCircle(position.x, position.y, radius);
6107
+ try {
6108
+ return this.query(circle, check, out);
6109
+ }
6110
+ finally {
6111
+ this.#circlePoolIdx--;
6112
+ }
6016
6113
  }
6017
6114
  queryRectangle(position, size, check, out = []) {
6018
- const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
6019
- this.#releaseShapes();
6020
- return result;
6115
+ const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height);
6116
+ try {
6117
+ return this.query(rect, check, out);
6118
+ }
6119
+ finally {
6120
+ this.#rectanglePoolIdx--;
6121
+ }
6021
6122
  }
6022
6123
  #acquireCircle(x, y, r) {
6023
6124
  const idx = this.#circlePoolIdx++;
@@ -6076,10 +6177,6 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6076
6177
  }
6077
6178
  }
6078
6179
  }
6079
- #releaseShapes() {
6080
- this.#circlePoolIdx = 0;
6081
- this.#rectanglePoolIdx = 0;
6082
- }
6083
6180
  }
6084
6181
 
6085
6182
  class ParticlesManager {
@@ -6618,8 +6715,8 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6618
6715
  particleCreatedPlugins;
6619
6716
  particleDestroyedPlugins;
6620
6717
  particlePositionPlugins;
6621
- particleUpdaters;
6622
6718
  particles;
6719
+ particleUpdaters;
6623
6720
  peakNits;
6624
6721
  plugins;
6625
6722
  retina;
@@ -6627,6 +6724,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6627
6724
  started;
6628
6725
  zLayers;
6629
6726
  #delay;
6727
+ #delayResolve;
6630
6728
  #delayTimeout;
6631
6729
  #delta = { value: 0, factor: 0 };
6632
6730
  #dispatchCallback;
@@ -6865,7 +6963,10 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6865
6963
  await this.init();
6866
6964
  this.started = true;
6867
6965
  await new Promise(resolve => {
6966
+ this.#delayResolve = resolve;
6868
6967
  const start = async () => {
6968
+ this.#delayTimeout = undefined;
6969
+ this.#delayResolve = undefined;
6869
6970
  this.#eventListeners.addListeners();
6870
6971
  for (const plugin of this.plugins) {
6871
6972
  await plugin.start?.();
@@ -6881,9 +6982,11 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6881
6982
  if (!guardCheck(this) || !this.started) {
6882
6983
  return;
6883
6984
  }
6884
- if (this.#delayTimeout) {
6985
+ if (this.#delayTimeout !== undefined) {
6885
6986
  clearTimeout(this.#delayTimeout);
6886
6987
  this.#delayTimeout = undefined;
6988
+ this.#delayResolve?.();
6989
+ this.#delayResolve = undefined;
6887
6990
  }
6888
6991
  this.#firstStart = true;
6889
6992
  this.started = false;
@@ -6907,6 +7010,7 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
6907
7010
  refresh = plugin.updateActualOptions() || refresh;
6908
7011
  }
6909
7012
  }
7013
+ this.canvas.render.updateBackgroundElement();
6910
7014
  return refresh;
6911
7015
  }
6912
7016
  #initPlugins(allContainerPlugins) {
@@ -7347,7 +7451,9 @@ g.__tsParticlesInternals.bundles = g.__tsParticlesInternals.bundles || {};
7347
7451
  manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
7348
7452
  manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
7349
7453
  manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
7350
- manageListener(interactivityEl, touchEndEvent, options.interactivity?.events.onClick.enable ? handlers.touchEndClick : handlers.touchEnd, add);
7454
+ const onClickEnabled = !!options.interactivity?.events.onClick.enable;
7455
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add && onClickEnabled);
7456
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add && !onClickEnabled);
7351
7457
  manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
7352
7458
  manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
7353
7459
  manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);