@tsparticles/preset-links 4.4.0 → 4.5.1

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,21 +1,35 @@
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);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
2
- /* Preset v4.4.0 */
3
- (function (global, factory) {
4
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
6
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.presets = global.__tsParticlesInternals.presets || {}, global.__tsParticlesInternals.presets.links = global.__tsParticlesInternals.presets.links || {})));
7
- })(this, (function (exports) { 'use strict';
8
-
9
- const generatedAttribute = "generated", defaultCompositeValue = "source-over", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
10
- x: 0,
11
- y: 0,
12
- z: 0,
13
- }, defaultTransform = {
14
- a: 1,
15
- b: 0,
16
- c: 0,
17
- d: 1,
18
- }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, spatialHashGridCellSize = 100, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, inverseFactorNumerator = 1, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, minDistance$2 = 0, defaultTransformValue = 1, minimumSize = 0, zIndexFactorOffset = 1, defaultOpacity$1 = 1, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minZ = 0, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, maxNits = 400, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0, defaultZoom = 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
+ (function (g) {
3
+ /* Preset v4.5.1 */
4
+ g.__tsParticlesInternals = g.__tsParticlesInternals || {};
5
+ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6
+ (function (exports) {
7
+ 'use strict';
8
+
9
+ const errorPrefix = "tsParticles - Error", codedErrorPattern = /^\[tsParticles Error (TSP-\d+)\]\s*/, fullMatchIndex = 0, codeIndex = 1;
10
+ const wrap = (fn) => (...args) => {
11
+ fn(...args);
12
+ }, _logger = {
13
+ debug: wrap(console.debug),
14
+ error: (message, ...optionalParams) => {
15
+ if (typeof message === "string") {
16
+ const match = codedErrorPattern.exec(message);
17
+ if (match?.[codeIndex]) {
18
+ console.error(`tsParticles - ${match[codeIndex]} - ${message.slice(match[fullMatchIndex].length)}`, ...optionalParams);
19
+ return;
20
+ }
21
+ }
22
+ console.error(`${errorPrefix} - ${message}`, ...optionalParams);
23
+ },
24
+ info: wrap(console.info),
25
+ log: wrap(console.log),
26
+ trace: wrap(console.trace),
27
+ verbose: wrap(console.log),
28
+ warning: wrap(console.warn),
29
+ };
30
+ function getLogger() {
31
+ return _logger;
32
+ }
19
33
 
20
34
  var MoveDirection;
21
35
  (function (MoveDirection) {
@@ -32,6 +46,17 @@
32
46
  MoveDirection["inside"] = "inside";
33
47
  })(MoveDirection || (MoveDirection = {}));
34
48
 
49
+ const generatedAttribute = "generated", fullPercent = "100%", defaultCompositeValue = "source-over", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
50
+ x: 0,
51
+ y: 0,
52
+ z: 0,
53
+ }, defaultTransform = {
54
+ a: 1,
55
+ b: 0,
56
+ c: 0,
57
+ d: 1,
58
+ }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, spatialHashGridCellSize = 100, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, inverseFactorNumerator = 1, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, minDistance$2 = 0, minRadius = 0, defaultTransformValue = 1, minimumSize = 0, zIndexFactorOffset = 1, defaultOpacity$1 = 1, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minZ = 0, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, defaultAngle = 0, identity = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, maxNits = 400, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0, defaultZoom = 1;
59
+
35
60
  function getZ(source) {
36
61
  return "z" in source ? source.z : originPoint.z;
37
62
  }
@@ -147,6 +172,12 @@
147
172
  function isNumber(arg) {
148
173
  return typeof arg === "number";
149
174
  }
175
+ function isEnumValue(enumObject, arg) {
176
+ return Object.values(enumObject).some(enumValue => enumValue === arg);
177
+ }
178
+ function toEnumValue(enumObject, arg, defaultValue) {
179
+ return isEnumValue(enumObject, arg) ? arg : defaultValue;
180
+ }
150
181
  function isObject(arg) {
151
182
  return typeof arg === "object" && arg !== null;
152
183
  }
@@ -273,11 +304,61 @@
273
304
  };
274
305
  }
275
306
  function parseAlpha(input) {
276
- const defaultAlpha = 1;
277
307
  if (!input) {
278
308
  return defaultAlpha;
279
309
  }
280
- return input.endsWith("%") ? parseFloat(input) / percentDenominator : parseFloat(input);
310
+ return input.endsWith("%") ? Number.parseFloat(input) / percentDenominator : Number.parseFloat(input);
311
+ }
312
+
313
+ const ErrorCodes$2 = {
314
+ engineVersionMismatch: "TSP-1001",
315
+ particlePositionNotFound: "TSP-1002",
316
+ pluginRegisterAfterLoad: "TSP-1003",
317
+ offscreenCanvasUnsupported: "TSP-1101",
318
+ offscreenCanvasTransferFailed: "TSP-1102",
319
+ hdrEnableInvalid: "TSP-1201",
320
+ hdrModeInvalid: "TSP-1202",
321
+ hdrPeakNitsInvalid: "TSP-1203",
322
+ };
323
+
324
+ const messages = {
325
+ [ErrorCodes$2.engineVersionMismatch]: "The tsParticles version is different from the loaded plugins version. Engine version: {0}. Plugin version: {1}",
326
+ [ErrorCodes$2.particlePositionNotFound]: "a valid position cannot be found for particle",
327
+ [ErrorCodes$2.pluginRegisterAfterLoad]: "Register plugins can only be done before calling tsParticles.load()",
328
+ [ErrorCodes$2.offscreenCanvasUnsupported]: "OffscreenCanvas is required but not supported by this browser",
329
+ [ErrorCodes$2.offscreenCanvasTransferFailed]: "OffscreenCanvas transfer failed",
330
+ [ErrorCodes$2.hdrEnableInvalid]: 'Invalid HDR "enable" value: expected a boolean, got "{0}"',
331
+ [ErrorCodes$2.hdrModeInvalid]: 'Invalid HDR "mode" value: expected one of {0}, got "{1}"',
332
+ [ErrorCodes$2.hdrPeakNitsInvalid]: 'Invalid HDR "peakNits" value: expected a positive number, got "{0}"',
333
+ };
334
+
335
+ let registeredMessages;
336
+ const ensureRegisteredMessages = () => {
337
+ registeredMessages ??= new Map(Object.entries(messages));
338
+ return registeredMessages;
339
+ }, toStringValue$1 = (value) => String(value), format = (template, args) => {
340
+ return template.replace(/\{(\d+)\}/g, (match, index) => {
341
+ const arg = args[Number(index)];
342
+ return arg === undefined ? match : toStringValue$1(arg);
343
+ });
344
+ };
345
+ function addErrorMessages(extraMessages) {
346
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
347
+ return;
348
+ }
349
+ const catalog = ensureRegisteredMessages();
350
+ for (const [code, message] of Object.entries(extraMessages)) {
351
+ if (message !== undefined) {
352
+ catalog.set(code, message);
353
+ }
354
+ }
355
+ }
356
+ function getErrorMessage(code, ...args) {
357
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
358
+ return `[tsParticles Error ${code}] https://particles.js.org/errors/#${code}`;
359
+ }
360
+ const template = ensureRegisteredMessages().get(code) ?? `Unknown error code ${code}`;
361
+ return format(template, args);
281
362
  }
282
363
 
283
364
  var OutModeDirection;
@@ -294,7 +375,6 @@
294
375
  PixelMode["percent"] = "percent";
295
376
  })(PixelMode || (PixelMode = {}));
296
377
 
297
- const minRadius = 0;
298
378
  function isForbiddenKey(key) {
299
379
  return key === "__proto__" || key === "constructor" || key === "prototype";
300
380
  }
@@ -490,22 +570,84 @@
490
570
  element.removeEventListener(event, handler, removeOptions);
491
571
  }
492
572
  }
493
- async function getItemsFromInitializer(container, map, initializers, force = false) {
494
- let res = map.get(container);
495
- if (!res || force) {
496
- res = await Promise.all([...initializers.values()].map(t => t(container)));
497
- map.set(container, res);
573
+ async function getItemsFromInitializer(container, initializers) {
574
+ return await Promise.all([...initializers.values()].map(t => t(container)));
575
+ }
576
+ async function getItemMapFromInitializer(container, initializers) {
577
+ const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
578
+ return new Map(entries);
579
+ }
580
+ async function getDataFromUrl(data) {
581
+ const url = itemFromSingleOrMultiple(data.url, data.index);
582
+ if (!url) {
583
+ return data.fallback;
498
584
  }
499
- return res;
585
+ try {
586
+ const response = await fetch(url);
587
+ if (response.ok) {
588
+ const current = (await response.json());
589
+ if (isSourceOptionsValue(current)) {
590
+ return current;
591
+ }
592
+ getLogger().error("invalid configuration data while retrieving config file");
593
+ }
594
+ else {
595
+ getLogger().error(`${response.status.toString()} while retrieving config file`);
596
+ }
597
+ }
598
+ catch (error) {
599
+ getLogger().error(`error while retrieving config file: ${error}`);
600
+ }
601
+ return data.fallback;
500
602
  }
501
- async function getItemMapFromInitializer(container, map, initializers, force = false) {
502
- let res = map.get(container);
503
- if (!res || force) {
504
- const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
505
- res = new Map(entries);
506
- map.set(container, res);
603
+ function isSourceOptionsValue(value) {
604
+ if (isArray(value)) {
605
+ return value.every((entry) => isObject(entry) && !isArray(entry));
507
606
  }
508
- return res;
607
+ return isObject(value) && !isArray(value);
608
+ }
609
+ function getCanvasFromContainer(domContainer) {
610
+ let canvasEl;
611
+ const documentSafe = safeDocument(), isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
612
+ if (isCanvas) {
613
+ canvasEl = domContainer;
614
+ canvasEl.dataset[generatedAttribute] ??= generatedFalse;
615
+ if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
616
+ canvasEl.style.width ||= fullPercent;
617
+ canvasEl.style.height ||= fullPercent;
618
+ canvasEl.style.pointerEvents = "none";
619
+ canvasEl.style.setProperty("pointer-events", "none");
620
+ }
621
+ }
622
+ else {
623
+ const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
624
+ if (foundCanvas) {
625
+ canvasEl = foundCanvas;
626
+ canvasEl.dataset[generatedAttribute] = generatedFalse;
627
+ }
628
+ else {
629
+ canvasEl = documentSafe.createElement(canvasTag);
630
+ canvasEl.dataset[generatedAttribute] = generatedTrue;
631
+ domContainer.appendChild(canvasEl);
632
+ }
633
+ canvasEl.style.width ||= fullPercent;
634
+ canvasEl.style.height ||= fullPercent;
635
+ canvasEl.style.pointerEvents = "none";
636
+ canvasEl.style.setProperty("pointer-events", "none");
637
+ }
638
+ return canvasEl;
639
+ }
640
+ function getDomContainer(id, source) {
641
+ const documentSafe = safeDocument();
642
+ let domContainer = source ?? documentSafe.getElementById(id);
643
+ if (domContainer) {
644
+ return domContainer;
645
+ }
646
+ domContainer = documentSafe.createElement("canvas");
647
+ domContainer.id = id;
648
+ domContainer.dataset[generatedAttribute] = generatedTrue;
649
+ documentSafe.body.append(domContainer);
650
+ return domContainer;
509
651
  }
510
652
 
511
653
  class EventDispatcher {
@@ -515,12 +657,8 @@
515
657
  }
516
658
  addEventListener(type, listener) {
517
659
  this.removeEventListener(type, listener);
518
- let arr = this.#listeners.get(type);
519
- if (!arr) {
520
- arr = [];
521
- this.#listeners.set(type, arr);
522
- }
523
- arr.push(listener);
660
+ const arr = this.#listeners.get(type);
661
+ this.#listeners.set(type, arr ? [...arr, listener] : [listener]);
524
662
  }
525
663
  dispatchEvent(type, args) {
526
664
  const listeners = this.#listeners.get(type);
@@ -552,7 +690,7 @@
552
690
  this.#listeners.delete(type);
553
691
  }
554
692
  else {
555
- arr.splice(idx, deleteCount);
693
+ this.#listeners.set(type, [...arr.slice(minIndex, idx), ...arr.slice(idx + deleteCount)]);
556
694
  }
557
695
  }
558
696
  }
@@ -576,7 +714,6 @@
576
714
  class PluginManager {
577
715
  colorManagers = new Map();
578
716
  easingFunctions = new Map();
579
- effectDrawers = new Map();
580
717
  initializers = {
581
718
  effects: new Map(),
582
719
  shapes: new Map(),
@@ -585,8 +722,6 @@
585
722
  palettes = new Map();
586
723
  plugins = [];
587
724
  presets = new Map();
588
- shapeDrawers = new Map();
589
- updaters = new Map();
590
725
  #allLoadersSet = new Set();
591
726
  #configs = new Map();
592
727
  #engine;
@@ -604,57 +739,79 @@
604
739
  }
605
740
  return res;
606
741
  }
742
+ get initialized() {
743
+ return this.#initialized;
744
+ }
607
745
  addColorManager(name, manager) {
746
+ if (this.#initialized) {
747
+ return;
748
+ }
608
749
  this.colorManagers.set(name, manager);
609
750
  }
610
751
  addConfig(config) {
752
+ if (this.#initialized) {
753
+ return;
754
+ }
611
755
  const key = config.key ?? config.name ?? "default";
612
756
  this.#configs.set(key, config);
613
757
  this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
614
758
  }
615
759
  addEasing(name, easing) {
760
+ if (this.#initialized) {
761
+ return;
762
+ }
616
763
  if (this.easingFunctions.get(name)) {
617
764
  return;
618
765
  }
619
766
  this.easingFunctions.set(name, easing);
620
767
  }
621
768
  addEffect(effect, drawer) {
769
+ if (this.#initialized) {
770
+ return;
771
+ }
622
772
  this.initializers.effects.set(effect, drawer);
623
773
  }
624
774
  addPalette(name, palette) {
775
+ if (this.#initialized) {
776
+ return;
777
+ }
625
778
  this.palettes.set(name, palette);
626
779
  }
627
780
  addParticleUpdater(name, updaterInitializer) {
781
+ if (this.#initialized) {
782
+ return;
783
+ }
628
784
  this.initializers.updaters.set(name, updaterInitializer);
629
785
  }
630
786
  addPlugin(plugin) {
787
+ if (this.#initialized) {
788
+ return;
789
+ }
631
790
  if (this.getPlugin(plugin.id)) {
632
791
  return;
633
792
  }
634
793
  this.plugins.push(plugin);
635
794
  }
636
795
  addPreset(preset, options, override = false) {
796
+ if (this.#initialized) {
797
+ return;
798
+ }
637
799
  if (!(override || !this.getPreset(preset))) {
638
800
  return;
639
801
  }
640
802
  this.presets.set(preset, options);
641
803
  }
642
804
  addShape(shapes, drawer) {
805
+ if (this.#initialized) {
806
+ return;
807
+ }
643
808
  for (const shape of shapes) {
644
809
  this.initializers.shapes.set(shape, drawer);
645
810
  }
646
811
  }
647
- clearPlugins(container) {
648
- this.effectDrawers.delete(container);
649
- this.shapeDrawers.delete(container);
650
- this.updaters.delete(container);
651
- }
652
812
  getEasing(name) {
653
813
  return this.easingFunctions.get(name) ?? ((value) => value);
654
814
  }
655
- getEffectDrawers(container, force = false) {
656
- return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
657
- }
658
815
  getPalette(name) {
659
816
  return this.palettes.get(name);
660
817
  }
@@ -664,12 +821,6 @@
664
821
  getPreset(preset) {
665
822
  return this.presets.get(preset);
666
823
  }
667
- async getShapeDrawers(container, force = false) {
668
- return getItemMapFromInitializer(container, this.shapeDrawers, this.initializers.shapes, force);
669
- }
670
- async getUpdaters(container, force = false) {
671
- return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
672
- }
673
824
  async init() {
674
825
  if (this.#initialized || this.#isRunningLoaders) {
675
826
  return;
@@ -688,16 +839,9 @@
688
839
  this.#initialized = true;
689
840
  }
690
841
  }
691
- loadParticlesOptions(container, options, ...sourceOptions) {
692
- const updaters = this.updaters.get(container);
693
- if (!updaters) {
694
- return;
695
- }
696
- updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
697
- }
698
842
  async register(...loaders) {
699
843
  if (this.#initialized) {
700
- throw new Error("Register plugins can only be done before calling tsParticles.load()");
844
+ throw new Error(getErrorMessage(ErrorCodes$2.pluginRegisterAfterLoad));
701
845
  }
702
846
  for (const loader of loaders) {
703
847
  if (this.#isRunningLoaders) {
@@ -709,88 +853,15 @@
709
853
  }
710
854
  }
711
855
  async #runLoader(loader, executed, allLoaders) {
712
- if (executed.has(loader))
856
+ if (executed.has(loader)) {
713
857
  return;
858
+ }
714
859
  executed.add(loader);
715
860
  allLoaders.add(loader);
716
861
  await loader(this.#engine);
717
862
  }
718
863
  }
719
864
 
720
- const errorPrefix = "tsParticles - Error";
721
- const wrap = (fn) => (...args) => {
722
- fn(...args);
723
- }, _logger = {
724
- debug: wrap(console.debug),
725
- error: (message, ...optionalParams) => {
726
- console.error(`${errorPrefix} - ${message}`, ...optionalParams);
727
- },
728
- info: wrap(console.info),
729
- log: wrap(console.log),
730
- trace: wrap(console.trace),
731
- verbose: wrap(console.log),
732
- warning: wrap(console.warn),
733
- };
734
- function getLogger() {
735
- return _logger;
736
- }
737
-
738
- const fullPercent = "100%";
739
- async function getDataFromUrl(data) {
740
- const url = itemFromSingleOrMultiple(data.url, data.index);
741
- if (!url) {
742
- return data.fallback;
743
- }
744
- const response = await fetch(url);
745
- if (response.ok) {
746
- return (await response.json());
747
- }
748
- getLogger().error(`${response.status.toString()} while retrieving config file`);
749
- return data.fallback;
750
- }
751
- const getCanvasFromContainer = (domContainer) => {
752
- const documentSafe = safeDocument();
753
- let canvasEl;
754
- const isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
755
- if (isCanvas) {
756
- canvasEl = domContainer;
757
- canvasEl.dataset[generatedAttribute] ??= generatedFalse;
758
- if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
759
- canvasEl.style.width ||= fullPercent;
760
- canvasEl.style.height ||= fullPercent;
761
- canvasEl.style.pointerEvents = "none";
762
- canvasEl.style.setProperty("pointer-events", "none");
763
- }
764
- }
765
- else {
766
- const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
767
- if (foundCanvas) {
768
- canvasEl = foundCanvas;
769
- canvasEl.dataset[generatedAttribute] = generatedFalse;
770
- }
771
- else {
772
- canvasEl = documentSafe.createElement(canvasTag);
773
- canvasEl.dataset[generatedAttribute] = generatedTrue;
774
- domContainer.appendChild(canvasEl);
775
- }
776
- canvasEl.style.width ||= fullPercent;
777
- canvasEl.style.height ||= fullPercent;
778
- canvasEl.style.pointerEvents = "none";
779
- canvasEl.style.setProperty("pointer-events", "none");
780
- }
781
- return canvasEl;
782
- }, getDomContainer = (id, source) => {
783
- const documentSafe = safeDocument();
784
- let domContainer = source ?? documentSafe.getElementById(id);
785
- if (domContainer) {
786
- return domContainer;
787
- }
788
- domContainer = documentSafe.createElement("canvas");
789
- domContainer.id = id;
790
- domContainer.dataset[generatedAttribute] = generatedTrue;
791
- documentSafe.body.append(domContainer);
792
- return domContainer;
793
- };
794
865
  class Engine {
795
866
  pluginManager = new PluginManager(this);
796
867
  #domArray = [];
@@ -800,7 +871,7 @@
800
871
  return this.#domArray;
801
872
  }
802
873
  get version() {
803
- return "4.4.0";
874
+ return "4.5.1";
804
875
  }
805
876
  addEventListener(type, listener) {
806
877
  this.#eventDispatcher.addEventListener(type, listener);
@@ -809,7 +880,7 @@
809
880
  if (this.version === pluginVersion) {
810
881
  return;
811
882
  }
812
- throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
883
+ throw new Error(getErrorMessage(ErrorCodes$2.engineVersionMismatch, this.version, pluginVersion));
813
884
  }
814
885
  dispatchEvent(type, args) {
815
886
  this.#eventDispatcher.dispatchEvent(type, args);
@@ -1058,20 +1129,6 @@
1058
1129
  DrawLayer[DrawLayer["Foreground"] = 7] = "Foreground";
1059
1130
  })(DrawLayer || (DrawLayer = {}));
1060
1131
 
1061
- class OptionLoader {
1062
- load(data) {
1063
- if (isNull(data)) {
1064
- return;
1065
- }
1066
- this.doLoad(data);
1067
- }
1068
- }
1069
- function loadOptions(options, ...sourceOptionsArr) {
1070
- for (const sourceOptions of sourceOptionsArr) {
1071
- options.load(sourceOptions);
1072
- }
1073
- }
1074
-
1075
1132
  function loadProperty(obj, key, value) {
1076
1133
  if (value !== undefined) {
1077
1134
  obj[key] = value;
@@ -1103,6 +1160,20 @@
1103
1160
  }
1104
1161
  }
1105
1162
 
1163
+ class OptionLoader {
1164
+ load(data) {
1165
+ if (isNull(data)) {
1166
+ return;
1167
+ }
1168
+ this.doLoad(data);
1169
+ }
1170
+ }
1171
+ function loadOptions(options, ...sourceOptionsArr) {
1172
+ for (const sourceOptions of sourceOptionsArr) {
1173
+ options.load(sourceOptions);
1174
+ }
1175
+ }
1176
+
1106
1177
  class AnimationOptions extends OptionLoader {
1107
1178
  count = 0;
1108
1179
  decay = 0;
@@ -1253,15 +1324,14 @@
1253
1324
  peakNits = defaultPeakNits;
1254
1325
  doLoad(data) {
1255
1326
  if (data.enable !== undefined && !isBoolean(data.enable)) {
1256
- throw new Error(`Invalid HDR "enable" value: expected a boolean, got "${String(data.enable)}"`);
1327
+ throw new Error(getErrorMessage(ErrorCodes$2.hdrEnableInvalid, String(data.enable)));
1257
1328
  }
1258
- if (data.mode !== undefined &&
1259
- (typeof data.mode !== "string" || !Object.values(HdrMode).includes(data.mode))) {
1260
- throw new Error(`Invalid HDR "mode" value: expected one of ${Object.values(HdrMode).join(", ")}, got "${toStringValue(data.mode)}"`);
1329
+ if (data.mode !== undefined && !isEnumValue(HdrMode, data.mode)) {
1330
+ throw new Error(getErrorMessage(ErrorCodes$2.hdrModeInvalid, Object.values(HdrMode).join(", "), toStringValue(data.mode)));
1261
1331
  }
1262
1332
  if (data.peakNits !== undefined &&
1263
1333
  (!isNumber(data.peakNits) || !Number.isFinite(data.peakNits) || data.peakNits <= minPeakNits)) {
1264
- throw new Error(`Invalid HDR "peakNits" value: expected a positive number, got "${String(data.peakNits)}"`);
1334
+ throw new Error(getErrorMessage(ErrorCodes$2.hdrPeakNitsInvalid, String(data.peakNits)));
1265
1335
  }
1266
1336
  loadProperty(this, "enable", data.enable);
1267
1337
  loadProperty(this, "mode", data.mode);
@@ -1639,12 +1709,10 @@
1639
1709
  plugin.loadParticlesOptions(this.#container, this, data);
1640
1710
  }
1641
1711
  }
1642
- const updaters = this.#pluginManager.updaters.get(this.#container);
1643
- if (updaters) {
1644
- for (const updater of updaters) {
1645
- if (updater.loadOptions) {
1646
- updater.loadOptions(this, data);
1647
- }
1712
+ const updaters = this.#container.particleUpdaters;
1713
+ for (const updater of updaters) {
1714
+ if (updater.loadOptions) {
1715
+ updater.loadOptions(this, data);
1648
1716
  }
1649
1717
  }
1650
1718
  }
@@ -1983,9 +2051,9 @@
1983
2051
  const grayscaleValue = Math.round(lNormalized * rgbMax);
1984
2052
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
1985
2053
  }
1986
- const temp1 = lNormalized < half
2054
+ const temp2 = lNormalized < half
1987
2055
  ? lNormalized * (sNormalizedOffset + sNormalized)
1988
- : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized - phaseThird));
2056
+ : lNormalized + sNormalized - lNormalized * sNormalized, temp1 = double * lNormalized - temp2, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
1989
2057
  return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
1990
2058
  }
1991
2059
  function hslToRgbFloat(hsl) {
@@ -1994,9 +2062,9 @@
1994
2062
  const grayscaleValue = lNormalized * rgbMax;
1995
2063
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
1996
2064
  }
1997
- const temp1 = lNormalized < half
2065
+ const temp2 = lNormalized < half
1998
2066
  ? lNormalized * (sNormalizedOffset + sNormalized)
1999
- : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized - phaseThird));
2067
+ : lNormalized + sNormalized - lNormalized * sNormalized, temp1 = double * lNormalized - temp2, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
2000
2068
  return { r: red, g: green, b: blue };
2001
2069
  }
2002
2070
  function hslaToRgba(hsla) {
@@ -2283,7 +2351,7 @@
2283
2351
  }
2284
2352
 
2285
2353
  async function loadBlendPlugin(engine) {
2286
- engine.checkVersion("4.4.0");
2354
+ engine.checkVersion("4.5.1");
2287
2355
  await engine.pluginManager.register(e => {
2288
2356
  e.pluginManager.addPlugin(new BlendPlugin());
2289
2357
  });
@@ -2320,7 +2388,7 @@
2320
2388
  }
2321
2389
 
2322
2390
  async function loadCircleShape(engine) {
2323
- engine.checkVersion("4.4.0");
2391
+ engine.checkVersion("4.5.1");
2324
2392
  await engine.pluginManager.register(e => {
2325
2393
  e.pluginManager.addShape(["circle"], () => {
2326
2394
  return Promise.resolve(new CircleDrawer());
@@ -2335,7 +2403,7 @@
2335
2403
  RgbIndexes[RgbIndexes["b"] = 3] = "b";
2336
2404
  RgbIndexes[RgbIndexes["a"] = 4] = "a";
2337
2405
  })(RgbIndexes$1 || (RgbIndexes$1 = {}));
2338
- const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, defaultAlpha = 1, alphaFactor = 0xff;
2406
+ const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, alphaFactor = 0xff;
2339
2407
  class HexColorManager {
2340
2408
  accepts(input) {
2341
2409
  return input.startsWith("#");
@@ -2368,7 +2436,7 @@
2368
2436
  }
2369
2437
 
2370
2438
  async function loadHexColorPlugin(engine) {
2371
- engine.checkVersion("4.4.0");
2439
+ engine.checkVersion("4.5.1");
2372
2440
  await engine.pluginManager.register(e => {
2373
2441
  e.pluginManager.addColorManager("hex", new HexColorManager());
2374
2442
  });
@@ -2408,7 +2476,7 @@
2408
2476
  if (!this.accepts(input)) {
2409
2477
  return;
2410
2478
  }
2411
- const result = hslRegex.exec(input), minLength = 4, defaultAlpha = 1, radix = 10;
2479
+ const result = hslRegex.exec(input), minLength = 4, radix = 10;
2412
2480
  return result
2413
2481
  ? hslaToRgba({
2414
2482
  a: result.length > minLength ? parseAlpha(result[HslIndexes.a]) : defaultAlpha,
@@ -2421,12 +2489,20 @@
2421
2489
  }
2422
2490
 
2423
2491
  async function loadHslColorPlugin(engine) {
2424
- engine.checkVersion("4.4.0");
2492
+ engine.checkVersion("4.5.1");
2425
2493
  await engine.pluginManager.register(e => {
2426
2494
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2427
2495
  });
2428
2496
  }
2429
2497
 
2498
+ const ErrorCodes$1 = {
2499
+ baseMoverNotLoaded: "TSP-3203",
2500
+ };
2501
+
2502
+ const ErrorMessages$1 = {
2503
+ [ErrorCodes$1.baseMoverNotLoaded]: "tsParticles Base Mover is not loaded",
2504
+ };
2505
+
2430
2506
  class MovePlugin {
2431
2507
  id = "move";
2432
2508
  #pluginManager;
@@ -2445,20 +2521,20 @@
2445
2521
  }
2446
2522
 
2447
2523
  async function loadMovePlugin(engine) {
2448
- engine.checkVersion("4.4.0");
2524
+ engine.checkVersion("4.5.1");
2525
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
2526
+ addErrorMessages(ErrorMessages$1);
2527
+ }
2449
2528
  await engine.pluginManager.register(e => {
2450
2529
  const moveEngine = e, movePluginManager = moveEngine.pluginManager;
2451
2530
  movePluginManager.initializers.pathGenerators ??= new Map();
2452
- movePluginManager.pathGenerators ??= new Map();
2453
2531
  movePluginManager.addPathGenerator = (name, generator) => {
2532
+ if (movePluginManager.initialized) {
2533
+ return;
2534
+ }
2454
2535
  movePluginManager.initializers.pathGenerators ??= new Map();
2455
2536
  movePluginManager.initializers.pathGenerators.set(name, generator);
2456
2537
  };
2457
- movePluginManager.getPathGenerators = async (container, force = false) => {
2458
- movePluginManager.initializers.pathGenerators ??= new Map();
2459
- movePluginManager.pathGenerators ??= new Map();
2460
- return getItemMapFromInitializer(container, movePluginManager.pathGenerators, movePluginManager.initializers.pathGenerators, force);
2461
- };
2462
2538
  e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
2463
2539
  });
2464
2540
  }
@@ -2655,7 +2731,7 @@
2655
2731
  }
2656
2732
 
2657
2733
  async function loadOpacityUpdater(engine) {
2658
- engine.checkVersion("4.4.0");
2734
+ engine.checkVersion("4.5.1");
2659
2735
  await engine.pluginManager.register(e => {
2660
2736
  e.pluginManager.addParticleUpdater("opacity", container => {
2661
2737
  return Promise.resolve(new OpacityUpdater(container));
@@ -2664,70 +2740,60 @@
2664
2740
  }
2665
2741
 
2666
2742
  const boundsMin = 0;
2667
- function bounceHorizontal(data) {
2668
- if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
2669
- (data.direction !== OutModeDirection.left && data.direction !== OutModeDirection.right)) {
2670
- return;
2671
- }
2672
- if (data.bounds.right < boundsMin && data.direction === OutModeDirection.left) {
2673
- data.particle.position.x = data.size + data.offset.x;
2674
- }
2675
- else if (data.bounds.left > data.canvasSize.width && data.direction === OutModeDirection.right) {
2676
- data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
2677
- }
2678
- const velocity = data.particle.velocity.x;
2679
- let bounced = false;
2680
- if (data.outOfCanvas &&
2681
- ((data.direction === OutModeDirection.right && velocity > minVelocity) ||
2682
- (data.direction === OutModeDirection.left && velocity < minVelocity))) {
2683
- const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
2684
- data.particle.velocity.x *= -newVelocity;
2685
- bounced = true;
2686
- }
2687
- if (!bounced) {
2688
- return;
2689
- }
2690
- const minPos = data.offset.x + data.size;
2691
- if (data.outOfCanvas && data.direction === OutModeDirection.right) {
2692
- data.particle.position.x = data.canvasSize.width - minPos;
2693
- }
2694
- else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
2695
- data.particle.position.x = minPos;
2696
- }
2697
- if (data.outMode === OutMode.split) {
2698
- data.particle.destroy();
2699
- }
2700
- }
2701
- function bounceVertical(data) {
2702
- if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
2703
- (data.direction !== OutModeDirection.bottom && data.direction !== OutModeDirection.top)) {
2743
+ const bounceAxisConfigs = {
2744
+ [OutModeDirection.left]: {
2745
+ axis: "x",
2746
+ canvas: "width",
2747
+ bounce: "horizontal",
2748
+ negativeEdge: "right",
2749
+ positiveEdge: "left",
2750
+ negative: true,
2751
+ },
2752
+ [OutModeDirection.right]: {
2753
+ axis: "x",
2754
+ canvas: "width",
2755
+ bounce: "horizontal",
2756
+ negativeEdge: "right",
2757
+ positiveEdge: "left",
2758
+ negative: false,
2759
+ },
2760
+ [OutModeDirection.top]: {
2761
+ axis: "y",
2762
+ canvas: "height",
2763
+ bounce: "vertical",
2764
+ negativeEdge: "bottom",
2765
+ positiveEdge: "top",
2766
+ negative: true,
2767
+ },
2768
+ [OutModeDirection.bottom]: {
2769
+ axis: "y",
2770
+ canvas: "height",
2771
+ bounce: "vertical",
2772
+ negativeEdge: "bottom",
2773
+ positiveEdge: "top",
2774
+ negative: false,
2775
+ },
2776
+ };
2777
+ function bounce(data) {
2778
+ if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) || !(data.direction in bounceAxisConfigs)) {
2704
2779
  return;
2705
2780
  }
2706
- if (data.bounds.bottom < boundsMin && data.direction === OutModeDirection.top) {
2707
- data.particle.position.y = data.size + data.offset.y;
2781
+ const config = bounceAxisConfigs[data.direction], bounds = data.bounds, canvasDim = data.canvasSize[config.canvas], position = data.particle.position, velocity = data.particle.velocity[config.axis];
2782
+ if (config.negative && bounds[config.negativeEdge] < boundsMin) {
2783
+ position[config.axis] = data.size + data.offset[config.axis];
2708
2784
  }
2709
- else if (data.bounds.top > data.canvasSize.height && data.direction === OutModeDirection.bottom) {
2710
- data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
2785
+ else if (!config.negative && bounds[config.positiveEdge] > canvasDim) {
2786
+ position[config.axis] = canvasDim - data.size - data.offset[config.axis];
2711
2787
  }
2712
- const velocity = data.particle.velocity.y;
2713
- let bounced = false;
2714
2788
  if (data.outOfCanvas &&
2715
- ((data.direction === OutModeDirection.bottom && velocity > minVelocity) ||
2716
- (data.direction === OutModeDirection.top && velocity < minVelocity))) {
2717
- const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
2718
- data.particle.velocity.y *= -newVelocity;
2719
- bounced = true;
2789
+ ((config.negative && velocity < minVelocity) || (!config.negative && velocity > minVelocity))) {
2790
+ data.particle.velocity[config.axis] *= -getRangeValue(data.particle.options.bounce[config.bounce].value);
2720
2791
  }
2721
- if (!bounced) {
2792
+ else {
2722
2793
  return;
2723
2794
  }
2724
- const minPos = data.offset.y + data.size;
2725
- if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
2726
- data.particle.position.y = data.canvasSize.height - minPos;
2727
- }
2728
- else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
2729
- data.particle.position.y = minPos;
2730
- }
2795
+ const minPos = data.offset[config.axis] + data.size;
2796
+ position[config.axis] = config.negative ? minPos : canvasDim - minPos;
2731
2797
  if (data.outMode === OutMode.split) {
2732
2798
  data.particle.destroy();
2733
2799
  }
@@ -2743,26 +2809,19 @@
2743
2809
  OutMode.bounce,
2744
2810
  OutMode.split,
2745
2811
  ];
2746
- this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
2812
+ this.#particleBouncePlugins = container.plugins.filter(p => !!p.particleBounce);
2747
2813
  }
2748
2814
  update(particle, direction, delta, outMode) {
2749
2815
  if (!this.modes.includes(outMode)) {
2750
2816
  return;
2751
2817
  }
2752
- const container = this.#container;
2753
- let handled = false;
2754
2818
  for (const plugin of this.#particleBouncePlugins) {
2755
- handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
2756
- if (handled) {
2757
- break;
2819
+ if (plugin.particleBounce?.(particle, delta, direction)) {
2820
+ return;
2758
2821
  }
2759
2822
  }
2760
- if (handled) {
2761
- return;
2762
- }
2763
- const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
2764
- bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2765
- bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2823
+ const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = this.#container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
2824
+ bounce({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2766
2825
  }
2767
2826
  }
2768
2827
 
@@ -2851,107 +2910,108 @@
2851
2910
  return;
2852
2911
  }
2853
2912
  const container = this.#container;
2854
- switch (particle.outType) {
2855
- case ParticleOutType.inside: {
2856
- const { x: vx, y: vy } = particle.velocity;
2857
- updateVector.setTo(originPoint);
2858
- updateVector.length = particle.moveCenter.radius;
2859
- updateVector.angle = particle.velocity.angle + Math.PI;
2860
- updateVector.addTo(particle.moveCenter);
2861
- const { dx, dy } = getDistances(particle.position, updateVector);
2862
- if ((vx <= minVelocity && dx >= minDistance$2) ||
2863
- (vy <= minVelocity && dy >= minDistance$2) ||
2864
- (vx >= minVelocity && dx <= minDistance$2) ||
2865
- (vy >= minVelocity && dy <= minDistance$2)) {
2866
- return;
2867
- }
2868
- particle.position.x = Math.floor(randomInRangeValue({
2869
- min: 0,
2870
- max: container.canvas.size.width,
2871
- }));
2872
- particle.position.y = Math.floor(randomInRangeValue({
2873
- min: 0,
2874
- max: container.canvas.size.height,
2875
- }));
2876
- const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
2877
- particle.direction = Math.atan2(-newDy, -newDx);
2878
- particle.velocity.angle = particle.direction;
2879
- particle.justWarped = true;
2880
- break;
2913
+ if (particle.outType === ParticleOutType.inside) {
2914
+ this.#applyOutModeInside(particle, container);
2915
+ }
2916
+ else {
2917
+ if (particle.isInsideCanvasForOutMode(outMode, direction)) {
2918
+ return;
2881
2919
  }
2882
- default: {
2883
- if (particle.isInsideCanvasForOutMode(outMode, direction)) {
2884
- return;
2885
- }
2886
- switch (particle.outType) {
2887
- case ParticleOutType.outside: {
2888
- particle.position.x =
2889
- Math.floor(randomInRangeValue({
2890
- min: -particle.moveCenter.radius,
2891
- max: particle.moveCenter.radius,
2892
- })) + particle.moveCenter.x;
2893
- particle.position.y =
2894
- Math.floor(randomInRangeValue({
2895
- min: -particle.moveCenter.radius,
2896
- max: particle.moveCenter.radius,
2897
- })) + particle.moveCenter.y;
2898
- const { dx, dy } = getDistances(particle.position, particle.moveCenter);
2899
- if (particle.moveCenter.radius) {
2900
- particle.direction = Math.atan2(dy, dx);
2901
- particle.velocity.angle = particle.direction;
2902
- }
2903
- particle.justWarped = true;
2904
- break;
2905
- }
2906
- case ParticleOutType.normal: {
2907
- const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
2908
- bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
2909
- left: -particle.getRadius() - particle.offset.x,
2910
- right: canvasSize.width + particle.getRadius() + particle.offset.x,
2911
- top: -particle.getRadius() - particle.offset.y,
2912
- }, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
2913
- if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
2914
- particle.position.x = newPos.left;
2915
- particle.initialPosition.x = particle.position.x;
2916
- if (!warp) {
2917
- particle.position.y = getRandom() * canvasSize.height;
2918
- particle.initialPosition.y = particle.position.y;
2919
- }
2920
- particle.justWarped = true;
2921
- }
2922
- else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
2923
- particle.position.x = newPos.right;
2924
- particle.initialPosition.x = particle.position.x;
2925
- if (!warp) {
2926
- particle.position.y = getRandom() * canvasSize.height;
2927
- particle.initialPosition.y = particle.position.y;
2928
- }
2929
- particle.justWarped = true;
2930
- }
2931
- if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
2932
- if (!warp) {
2933
- particle.position.x = getRandom() * canvasSize.width;
2934
- particle.initialPosition.x = particle.position.x;
2935
- }
2936
- particle.position.y = newPos.top;
2937
- particle.initialPosition.y = particle.position.y;
2938
- particle.justWarped = true;
2939
- }
2940
- else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
2941
- if (!warp) {
2942
- particle.position.x = getRandom() * canvasSize.width;
2943
- particle.initialPosition.x = particle.position.x;
2944
- }
2945
- particle.position.y = newPos.bottom;
2946
- particle.initialPosition.y = particle.position.y;
2947
- particle.justWarped = true;
2948
- }
2949
- break;
2950
- }
2951
- }
2952
- break;
2920
+ if (particle.outType === ParticleOutType.outside) {
2921
+ this.#applyParticleModeOutside(particle);
2953
2922
  }
2954
- }
2923
+ else {
2924
+ this.#applyOutModeNormal(particle, container, direction);
2925
+ }
2926
+ }
2927
+ }
2928
+ #applyOutModeInside(particle, container) {
2929
+ const { x: vx, y: vy } = particle.velocity;
2930
+ updateVector.setTo(originPoint);
2931
+ updateVector.length = particle.moveCenter.radius;
2932
+ updateVector.angle = particle.velocity.angle + Math.PI;
2933
+ updateVector.addTo(particle.moveCenter);
2934
+ const { dx, dy } = getDistances(particle.position, updateVector);
2935
+ if ((vx <= minVelocity && dx >= minDistance$2) ||
2936
+ (vy <= minVelocity && dy >= minDistance$2) ||
2937
+ (vx >= minVelocity && dx <= minDistance$2) ||
2938
+ (vy >= minVelocity && dy <= minDistance$2)) {
2939
+ return;
2940
+ }
2941
+ particle.position.x = Math.floor(randomInRangeValue({
2942
+ min: 0,
2943
+ max: container.canvas.size.width,
2944
+ }));
2945
+ particle.position.y = Math.floor(randomInRangeValue({
2946
+ min: 0,
2947
+ max: container.canvas.size.height,
2948
+ }));
2949
+ const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
2950
+ particle.direction = Math.atan2(-newDy, -newDx);
2951
+ particle.velocity.angle = particle.direction;
2952
+ particle.justWarped = true;
2953
+ }
2954
+ #applyOutModeNormal(particle, container, direction) {
2955
+ const warp = particle.options.move.warp, canvasSize = container.canvas.size, sizeValue = particle.getRadius(), newPos = {
2956
+ bottom: canvasSize.height + sizeValue + particle.offset.y,
2957
+ left: -sizeValue - particle.offset.x,
2958
+ right: canvasSize.width + sizeValue + particle.offset.x,
2959
+ top: -sizeValue - particle.offset.y,
2960
+ }, nextBounds = calculateBounds(particle.position, sizeValue);
2961
+ if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
2962
+ particle.position.x = newPos.left;
2963
+ particle.initialPosition.x = particle.position.x;
2964
+ if (!warp) {
2965
+ particle.position.y = getRandom() * canvasSize.height;
2966
+ particle.initialPosition.y = particle.position.y;
2967
+ }
2968
+ particle.justWarped = true;
2969
+ }
2970
+ else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
2971
+ particle.position.x = newPos.right;
2972
+ particle.initialPosition.x = particle.position.x;
2973
+ if (!warp) {
2974
+ particle.position.y = getRandom() * canvasSize.height;
2975
+ particle.initialPosition.y = particle.position.y;
2976
+ }
2977
+ particle.justWarped = true;
2978
+ }
2979
+ if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
2980
+ if (!warp) {
2981
+ particle.position.x = getRandom() * canvasSize.width;
2982
+ particle.initialPosition.x = particle.position.x;
2983
+ }
2984
+ particle.position.y = newPos.top;
2985
+ particle.initialPosition.y = particle.position.y;
2986
+ particle.justWarped = true;
2987
+ }
2988
+ else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
2989
+ if (!warp) {
2990
+ particle.position.x = getRandom() * canvasSize.width;
2991
+ particle.initialPosition.x = particle.position.x;
2992
+ }
2993
+ particle.position.y = newPos.bottom;
2994
+ particle.initialPosition.y = particle.position.y;
2995
+ particle.justWarped = true;
2996
+ }
2997
+ }
2998
+ #applyParticleModeOutside(particle) {
2999
+ particle.position.x =
3000
+ Math.floor(randomInRangeValue({
3001
+ min: -particle.moveCenter.radius,
3002
+ max: particle.moveCenter.radius,
3003
+ })) + particle.moveCenter.x;
3004
+ particle.position.y =
3005
+ Math.floor(randomInRangeValue({
3006
+ min: -particle.moveCenter.radius,
3007
+ max: particle.moveCenter.radius,
3008
+ })) + particle.moveCenter.y;
3009
+ const { dx, dy } = getDistances(particle.position, particle.moveCenter);
3010
+ if (particle.moveCenter.radius) {
3011
+ particle.direction = Math.atan2(dy, dx);
3012
+ particle.velocity.angle = particle.direction;
3013
+ }
3014
+ particle.justWarped = true;
2955
3015
  }
2956
3016
  }
2957
3017
 
@@ -3000,7 +3060,7 @@
3000
3060
  }
3001
3061
 
3002
3062
  async function loadOutModesUpdater(engine) {
3003
- engine.checkVersion("4.4.0");
3063
+ engine.checkVersion("4.5.1");
3004
3064
  await engine.pluginManager.register(e => {
3005
3065
  e.pluginManager.addParticleUpdater("outModes", container => {
3006
3066
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3017,39 +3077,9 @@
3017
3077
  this.#pluginManager = pluginManager;
3018
3078
  }
3019
3079
  init(particle) {
3020
- const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates), color = paint?.color, paintColor = color ?? undefined, fill = paint?.fill, stroke = paint?.stroke;
3021
- if (fill) {
3022
- const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
3023
- particle.fillEnabled = fill.enable;
3024
- particle.fillOpacity = getRangeValue(fill.opacity);
3025
- particle.fillAnimation = fillColor.animation;
3026
- const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
3027
- if (fillHslColor) {
3028
- particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
3029
- }
3030
- }
3031
- else {
3032
- particle.fillEnabled = false;
3033
- particle.fillAnimation = undefined;
3034
- particle.fillColor = undefined;
3035
- particle.fillOpacity = defaultOpacity;
3036
- }
3037
- if (stroke) {
3038
- const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
3039
- particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
3040
- particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
3041
- particle.strokeAnimation = strokeColor.animation;
3042
- const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
3043
- if (strokeHslColor) {
3044
- particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
3045
- }
3046
- }
3047
- else {
3048
- particle.strokeAnimation = undefined;
3049
- particle.strokeColor = undefined;
3050
- particle.strokeOpacity = defaultOpacity;
3051
- particle.strokeWidth = 0;
3052
- }
3080
+ const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates);
3081
+ this.#initFill(paint, particle, container);
3082
+ this.#initStroke(paint, particle, container);
3053
3083
  }
3054
3084
  isEnabled(particle) {
3055
3085
  const { fillAnimation, fillColor, strokeAnimation, strokeColor } = particle, fillEnabled = !!fillAnimation &&
@@ -3068,10 +3098,48 @@
3068
3098
  updateColor(particle.fillColor, delta, this.#container.hdr);
3069
3099
  updateColor(particle.strokeColor, delta, this.#container.hdr);
3070
3100
  }
3101
+ #initFill(paint, particle, container) {
3102
+ const fill = paint?.fill, color = paint?.color, paintColor = color ?? undefined;
3103
+ if (!fill) {
3104
+ particle.fillEnabled = false;
3105
+ particle.fillAnimation = undefined;
3106
+ particle.fillColor = undefined;
3107
+ particle.fillOpacity = defaultOpacity;
3108
+ return;
3109
+ }
3110
+ const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
3111
+ particle.fillEnabled = fill.enable;
3112
+ particle.fillOpacity = getRangeValue(fill.opacity);
3113
+ particle.fillAnimation = fillColor.animation;
3114
+ const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
3115
+ if (!fillHslColor) {
3116
+ return;
3117
+ }
3118
+ particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
3119
+ }
3120
+ #initStroke(paint, particle, container) {
3121
+ const stroke = paint?.stroke, color = paint?.color, paintColor = color ?? undefined;
3122
+ if (!stroke) {
3123
+ particle.strokeAnimation = undefined;
3124
+ particle.strokeColor = undefined;
3125
+ particle.strokeOpacity = defaultOpacity;
3126
+ particle.strokeWidth = 0;
3127
+ return;
3128
+ }
3129
+ const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
3130
+ particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
3131
+ particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
3132
+ particle.strokeAnimation = strokeColor.animation;
3133
+ const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
3134
+ if (!strokeHslColor) {
3135
+ return;
3136
+ }
3137
+ particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
3138
+ }
3071
3139
  }
3072
3140
 
3073
3141
  async function loadPaintUpdater(engine) {
3074
- engine.checkVersion("4.4.0");
3142
+ engine.checkVersion("4.5.1");
3075
3143
  await engine.pluginManager.register(e => {
3076
3144
  e.pluginManager.addParticleUpdater("paint", container => {
3077
3145
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3113,7 +3181,7 @@
3113
3181
  if (!this.accepts(input)) {
3114
3182
  return;
3115
3183
  }
3116
- const result = rgbRegex.exec(input), radix = 10, minLength = 4, defaultAlpha = 1;
3184
+ const result = rgbRegex.exec(input), radix = 10, minLength = 4;
3117
3185
  return result
3118
3186
  ? {
3119
3187
  a: result.length > minLength ? parseAlpha(result[RgbIndexes.a]) : defaultAlpha,
@@ -3126,7 +3194,7 @@
3126
3194
  }
3127
3195
 
3128
3196
  async function loadRgbColorPlugin(engine) {
3129
- engine.checkVersion("4.4.0");
3197
+ engine.checkVersion("4.5.1");
3130
3198
  await engine.pluginManager.register(e => {
3131
3199
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3132
3200
  });
@@ -3211,7 +3279,7 @@
3211
3279
  }
3212
3280
 
3213
3281
  async function loadSizeUpdater(engine) {
3214
- engine.checkVersion("4.4.0");
3282
+ engine.checkVersion("4.5.1");
3215
3283
  await engine.pluginManager.register(e => {
3216
3284
  e.pluginManager.addParticleUpdater("size", container => {
3217
3285
  return Promise.resolve(new SizeUpdater(container));
@@ -3220,7 +3288,7 @@
3220
3288
  }
3221
3289
 
3222
3290
  async function loadBasic(engine) {
3223
- engine.checkVersion("4.4.0");
3291
+ engine.checkVersion("4.5.1");
3224
3292
  await engine.pluginManager.register(async (e) => {
3225
3293
  await Promise.all([
3226
3294
  loadBlendPlugin(e),
@@ -3237,6 +3305,16 @@
3237
3305
  });
3238
3306
  }
3239
3307
 
3308
+ const ErrorCodes = {
3309
+ interactivityPluginNotLoaded: "TSP-3201",
3310
+ interactivityClickHandlerNotSet: "TSP-3202",
3311
+ };
3312
+
3313
+ const ErrorMessages = {
3314
+ [ErrorCodes.interactivityPluginNotLoaded]: "tsParticles Interactivity Plugin is not loaded",
3315
+ [ErrorCodes.interactivityClickHandlerNotSet]: "Click handlers can only be set after calling tsParticles.load()",
3316
+ };
3317
+
3240
3318
  class ClickEvent {
3241
3319
  enable = false;
3242
3320
  mode = [];
@@ -3313,9 +3391,7 @@
3313
3391
 
3314
3392
  class Modes {
3315
3393
  #container;
3316
- #pluginManager;
3317
- constructor(pluginManager, container) {
3318
- this.#pluginManager = pluginManager;
3394
+ constructor(container) {
3319
3395
  this.#container = container;
3320
3396
  }
3321
3397
  load(data) {
@@ -3325,10 +3401,7 @@
3325
3401
  if (!this.#container) {
3326
3402
  return;
3327
3403
  }
3328
- const interactors = this.#pluginManager.interactors?.get(this.#container);
3329
- if (!interactors) {
3330
- return;
3331
- }
3404
+ const interactors = this.#container.interactionManager?.interactors ?? [];
3332
3405
  for (const interactor of interactors) {
3333
3406
  if (!interactor.loadModeOptions) {
3334
3407
  continue;
@@ -3342,8 +3415,8 @@
3342
3415
  detectsOn = InteractivityDetect.window;
3343
3416
  events = new Events();
3344
3417
  modes;
3345
- constructor(pluginManager, container) {
3346
- this.modes = new Modes(pluginManager, container);
3418
+ constructor(container) {
3419
+ this.modes = new Modes(container);
3347
3420
  }
3348
3421
  load(data) {
3349
3422
  if (isNull(data)) {
@@ -3374,10 +3447,10 @@
3374
3447
  }
3375
3448
  let interactivityOptions = options.interactivity;
3376
3449
  if (!interactivityOptions?.load) {
3377
- options.interactivity = interactivityOptions = new Interactivity(this.#pluginManager, container);
3450
+ options.interactivity = interactivityOptions = new Interactivity(container);
3378
3451
  }
3379
3452
  interactivityOptions.load(source?.interactivity);
3380
- const interactors = this.#pluginManager.interactors?.get(container);
3453
+ const interactors = container.interactionManager?.interactors;
3381
3454
  if (!interactors) {
3382
3455
  return;
3383
3456
  }
@@ -3391,7 +3464,7 @@
3391
3464
  if (source?.interactivity) {
3392
3465
  options.interactivity = deepExtend({}, source.interactivity);
3393
3466
  }
3394
- const interactors = this.#pluginManager.interactors?.get(container);
3467
+ const interactors = container.interactionManager?.interactors;
3395
3468
  if (!interactors) {
3396
3469
  return;
3397
3470
  }
@@ -3421,25 +3494,25 @@
3421
3494
  const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
3422
3495
 
3423
3496
  async function loadInteractivityPlugin(engine) {
3424
- engine.checkVersion("4.4.0");
3497
+ engine.checkVersion("4.5.1");
3498
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
3499
+ addErrorMessages(ErrorMessages);
3500
+ }
3425
3501
  await engine.pluginManager.register(e => {
3426
3502
  const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
3427
3503
  interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
3428
3504
  interactivityPluginManager.initializers.interactors ??= new Map();
3429
- interactivityPluginManager.interactors ??= new Map();
3430
3505
  interactivityPluginManager.addInteractor = (name, interactorInitializer) => {
3506
+ if (interactivityPluginManager.initialized) {
3507
+ return;
3508
+ }
3431
3509
  interactivityPluginManager.initializers.interactors ??= new Map();
3432
3510
  interactivityPluginManager.initializers.interactors.set(name, interactorInitializer);
3433
3511
  };
3434
- interactivityPluginManager.getInteractors = async (container, force = false) => {
3435
- interactivityPluginManager.interactors ??= new Map();
3436
- interactivityPluginManager.initializers.interactors ??= new Map();
3437
- return getItemsFromInitializer(container, interactivityPluginManager.interactors, interactivityPluginManager.initializers.interactors, force);
3438
- };
3439
3512
  interactivityPluginManager.setOnClickHandler = (callback) => {
3440
3513
  const { items } = interactivityEngine;
3441
3514
  if (!items.length) {
3442
- throw new Error("Click handlers can only be set after calling tsParticles.load()");
3515
+ throw new Error(getErrorMessage(ErrorCodes.interactivityClickHandlerNotSet));
3443
3516
  }
3444
3517
  items.forEach(item => {
3445
3518
  const interactivityContainer = item;
@@ -3450,7 +3523,7 @@
3450
3523
  }
3451
3524
  function ensureInteractivityPluginLoaded(e) {
3452
3525
  if (!e.pluginManager.addInteractor) {
3453
- throw new Error("tsParticles Interactivity Plugin is not loaded");
3526
+ throw new Error(getErrorMessage(ErrorCodes.interactivityPluginNotLoaded));
3454
3527
  }
3455
3528
  }
3456
3529
 
@@ -3501,6 +3574,30 @@
3501
3574
  }
3502
3575
  return false;
3503
3576
  }
3577
+ query(grid) {
3578
+ 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;
3579
+ if (!crossesLeft && !crossesRight && !crossesTop && !crossesBottom) {
3580
+ return grid.query(this);
3581
+ }
3582
+ const xShifts = [originPoint.x], yShifts = [originPoint.y];
3583
+ if (crossesLeft)
3584
+ xShifts.push(width);
3585
+ if (crossesRight)
3586
+ xShifts.push(-width);
3587
+ if (crossesTop)
3588
+ yShifts.push(height);
3589
+ if (crossesBottom)
3590
+ yShifts.push(-height);
3591
+ const particles = new Set();
3592
+ for (const dx of xShifts) {
3593
+ for (const dy of yShifts) {
3594
+ for (const particle of grid.queryCircle({ x: x + dx, y: y + dy }, radius)) {
3595
+ particles.add(particle);
3596
+ }
3597
+ }
3598
+ }
3599
+ return [...particles];
3600
+ }
3504
3601
  }
3505
3602
 
3506
3603
  class LinksShadow {
@@ -3610,7 +3707,9 @@
3610
3707
  if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
3611
3708
  return;
3612
3709
  }
3613
- 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);
3710
+ const linkOpt1 = p1.options.links, optOpacity = linkOpt1.opacity, optDistance = p1.retina.linksDistance ?? minDistance$1, warp = linkOpt1.warp, query = (warp
3711
+ ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize).query(container.particles.grid)
3712
+ : container.particles.grid.queryCircle(pos1, optDistance));
3614
3713
  for (const p2 of query) {
3615
3714
  const linkOpt2 = p2.options.links;
3616
3715
  if (p1 === p2 ||
@@ -3698,7 +3797,7 @@
3698
3797
  }
3699
3798
 
3700
3799
  async function loadParticlesLinksInteraction(engine) {
3701
- engine.checkVersion("4.4.0");
3800
+ engine.checkVersion("4.5.1");
3702
3801
  await engine.pluginManager.register((e) => {
3703
3802
  const pluginManager = e.pluginManager;
3704
3803
  ensureInteractivityPluginLoaded(e);
@@ -3821,21 +3920,28 @@
3821
3920
  });
3822
3921
  }
3823
3922
  clear() {
3923
+ const visited = new Set();
3824
3924
  for (const plugin of this.#canvasClearPlugins) {
3925
+ visited.add(plugin);
3825
3926
  if (plugin.canvasClear?.() ?? false) {
3826
- return;
3927
+ return plugin;
3827
3928
  }
3828
3929
  }
3829
3930
  for (const layer of Object.values(DrawLayer)) {
3830
3931
  if (typeof layer === "number") {
3831
3932
  for (const plugin of this.#getLayerPlugins(layer)) {
3933
+ if (visited.has(plugin)) {
3934
+ continue;
3935
+ }
3936
+ visited.add(plugin);
3832
3937
  if (plugin.canvasClear?.() ?? false) {
3833
- return;
3938
+ return plugin;
3834
3939
  }
3835
3940
  }
3836
3941
  }
3837
3942
  }
3838
3943
  this.canvasClear();
3944
+ return undefined;
3839
3945
  }
3840
3946
  destroy() {
3841
3947
  this.stop();
@@ -3913,8 +4019,7 @@
3913
4019
  });
3914
4020
  }
3915
4021
  drawParticles(delta) {
3916
- const { particles, actualOptions } = this.#container;
3917
- this.clear();
4022
+ const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
3918
4023
  particles.update(delta);
3919
4024
  this.draw(ctx => {
3920
4025
  const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
@@ -3936,7 +4041,9 @@
3936
4041
  }
3937
4042
  }
3938
4043
  for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
3939
- plugin.canvasPaint?.();
4044
+ if (plugin !== clearedPlugin) {
4045
+ plugin.canvasPaint?.();
4046
+ }
3940
4047
  }
3941
4048
  for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
3942
4049
  plugin.drawSettingsSetup?.(ctx, delta);
@@ -3952,51 +4059,23 @@
3952
4059
  });
3953
4060
  }
3954
4061
  init() {
3955
- this.initUpdaters();
3956
- this.initPlugins();
3957
- this.#resolveBackgroundElement();
3958
- this.paint();
3959
- }
3960
- initPlugins() {
3961
- this.#canvasClearPlugins = [];
3962
- this.#colorPlugins = [];
3963
- this.#drawParticlePlugins = [];
3964
- this.#drawParticlesSetupPlugins = [];
3965
- this.#drawParticlesCleanupPlugins = [];
3966
- for (const layer of Object.values(DrawLayer)) {
3967
- if (typeof layer === "number") {
3968
- this.#layers[layer] = [];
3969
- }
3970
- }
3971
- for (const plugin of this.#container.plugins) {
3972
- if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
3973
- this.#colorPlugins.push(plugin);
3974
- }
3975
- if (plugin.drawParticle) {
3976
- this.#drawParticlePlugins.push(plugin);
3977
- }
3978
- if (plugin.drawParticleSetup) {
3979
- this.#drawParticlesSetupPlugins.push(plugin);
3980
- }
3981
- if (plugin.drawParticleCleanup) {
3982
- this.#drawParticlesCleanupPlugins.push(plugin);
3983
- }
3984
- if (plugin.canvasClear) {
3985
- this.#canvasClearPlugins.push(plugin);
3986
- }
3987
- if (plugin.canvasPaint) {
3988
- this.#getLayerPlugins(DrawLayer.BackgroundMask).push(plugin);
3989
- }
3990
- if (plugin.drawSettingsSetup) {
3991
- this.#getLayerPlugins(DrawLayer.CanvasSetup).push(plugin);
3992
- }
3993
- if (plugin.draw) {
3994
- this.#getLayerPlugins(DrawLayer.PluginContent).push(plugin);
3995
- }
3996
- if (plugin.clearDraw ?? plugin.drawSettingsCleanup) {
3997
- this.#getLayerPlugins(DrawLayer.CanvasCleanup).push(plugin);
4062
+ this.initUpdaters();
4063
+ this.initPlugins();
4064
+ this.#resolveBackgroundElement();
4065
+ this.paint();
4066
+ }
4067
+ initPlugins() {
4068
+ this.#canvasClearPlugins = [];
4069
+ this.#colorPlugins = [];
4070
+ this.#drawParticlePlugins = [];
4071
+ this.#drawParticlesSetupPlugins = [];
4072
+ this.#drawParticlesCleanupPlugins = [];
4073
+ for (const layer of Object.values(DrawLayer)) {
4074
+ if (typeof layer === "number") {
4075
+ this.#layers[layer] = [];
3998
4076
  }
3999
4077
  }
4078
+ this.#initPluginsArray();
4000
4079
  }
4001
4080
  initUpdaters() {
4002
4081
  this.#preDrawUpdaters = [];
@@ -4205,6 +4284,45 @@
4205
4284
  this.#reusablePluginColors[sColorIndex] = sColor;
4206
4285
  return this.#reusablePluginColors;
4207
4286
  }
4287
+ #initLayerPlugin(plugin) {
4288
+ const layerMap = [
4289
+ [DrawLayer.BackgroundMask, !!plugin.canvasPaint],
4290
+ [DrawLayer.CanvasSetup, !!plugin.drawSettingsSetup],
4291
+ [DrawLayer.PluginContent, !!plugin.draw],
4292
+ [DrawLayer.CanvasCleanup, !!(plugin.clearDraw ?? plugin.drawSettingsCleanup)],
4293
+ ];
4294
+ for (const [layer, active] of layerMap) {
4295
+ if (active) {
4296
+ this.#layers[layer].push(plugin);
4297
+ }
4298
+ }
4299
+ }
4300
+ #initPluginsArray() {
4301
+ for (const plugin of this.#container.plugins) {
4302
+ if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
4303
+ this.#colorPlugins.push(plugin);
4304
+ }
4305
+ if (plugin.drawParticle) {
4306
+ this.#drawParticlePlugins.push(plugin);
4307
+ }
4308
+ if (plugin.drawParticleSetup) {
4309
+ this.#drawParticlesSetupPlugins.push(plugin);
4310
+ }
4311
+ if (plugin.drawParticleCleanup) {
4312
+ this.#drawParticlesCleanupPlugins.push(plugin);
4313
+ }
4314
+ if (plugin.canvasClear) {
4315
+ this.#canvasClearPlugins.push(plugin);
4316
+ }
4317
+ this.#initLayerPlugin(plugin);
4318
+ }
4319
+ }
4320
+ #isSupportedElement(element) {
4321
+ return ((typeof HTMLCanvasElement !== "undefined" && element instanceof HTMLCanvasElement) ||
4322
+ (typeof OffscreenCanvas !== "undefined" && element instanceof OffscreenCanvas) ||
4323
+ (typeof HTMLVideoElement !== "undefined" && element instanceof HTMLVideoElement) ||
4324
+ (typeof HTMLImageElement !== "undefined" && element instanceof HTMLImageElement));
4325
+ }
4208
4326
  #resolveBackgroundElement() {
4209
4327
  const background = this.#container.actualOptions.background;
4210
4328
  this.#backgroundElement = null;
@@ -4214,9 +4332,7 @@
4214
4332
  if (typeof background.element === "string") {
4215
4333
  if (typeof document !== "undefined") {
4216
4334
  const node = document.querySelector(background.element);
4217
- if ((typeof HTMLCanvasElement !== "undefined" && node instanceof HTMLCanvasElement) ||
4218
- (typeof HTMLVideoElement !== "undefined" && node instanceof HTMLVideoElement) ||
4219
- (typeof HTMLImageElement !== "undefined" && node instanceof HTMLImageElement)) {
4335
+ if (node && this.#isSupportedElement(node)) {
4220
4336
  this.#backgroundElement = node;
4221
4337
  }
4222
4338
  else if (node) {
@@ -4227,10 +4343,7 @@
4227
4343
  }
4228
4344
  }
4229
4345
  }
4230
- else if ((typeof HTMLCanvasElement !== "undefined" && background.element instanceof HTMLCanvasElement) ||
4231
- (typeof OffscreenCanvas !== "undefined" && background.element instanceof OffscreenCanvas) ||
4232
- (typeof HTMLVideoElement !== "undefined" && background.element instanceof HTMLVideoElement) ||
4233
- (typeof HTMLImageElement !== "undefined" && background.element instanceof HTMLImageElement)) {
4346
+ else if (this.#isSupportedElement(background.element)) {
4234
4347
  this.#backgroundElement = background.element;
4235
4348
  }
4236
4349
  }
@@ -4248,7 +4361,7 @@
4248
4361
  return transferredCanvas;
4249
4362
  }
4250
4363
  if (typeof canvas.transferControlToOffscreen !== "function") {
4251
- throw new TypeError("OffscreenCanvas is required but not supported by this browser");
4364
+ throw new TypeError(getErrorMessage(ErrorCodes$2.offscreenCanvasUnsupported));
4252
4365
  }
4253
4366
  try {
4254
4367
  const offscreenCanvas = canvas.transferControlToOffscreen();
@@ -4256,10 +4369,16 @@
4256
4369
  return offscreenCanvas;
4257
4370
  }
4258
4371
  catch {
4259
- throw new TypeError("OffscreenCanvas transfer failed");
4372
+ throw new TypeError(getErrorMessage(ErrorCodes$2.offscreenCanvasTransferFailed));
4260
4373
  }
4261
4374
  }, isHtmlCanvasElement = (canvas) => {
4262
4375
  return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
4376
+ }, getEffectiveColorSpace = (context) => {
4377
+ if (!context) {
4378
+ return undefined;
4379
+ }
4380
+ const colorInfo = context;
4381
+ return colorInfo.getContextAttributes?.().colorSpace ?? undefined;
4263
4382
  };
4264
4383
  function setStyle(canvas, style, important = false) {
4265
4384
  if (!style) {
@@ -4384,7 +4503,7 @@
4384
4503
  const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
4385
4504
  if (color) {
4386
4505
  const hdrOptions = container.actualOptions.hdr;
4387
- elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, hdrOptions.mode);
4506
+ elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard));
4388
4507
  }
4389
4508
  else {
4390
4509
  elementStyle.backgroundColor = "";
@@ -4504,11 +4623,11 @@
4504
4623
  const container = this.#container, canSupportHdr = container.actualOptions.hdr.enable &&
4505
4624
  safeMatchMedia("(color-gamut: p3)")?.matches &&
4506
4625
  safeMatchMedia("(dynamic-range: high)")?.matches;
4507
- container.hdr = canSupportHdr ?? false;
4508
- container.hdrMode = container.actualOptions.hdr.mode;
4626
+ container.hdrMode = toEnumValue(HdrMode, container.actualOptions.hdr.mode, HdrMode.standard);
4509
4627
  container.peakNits = container.actualOptions.hdr.peakNits;
4510
4628
  const renderCanvas = this.renderCanvas;
4511
4629
  if (!renderCanvas) {
4630
+ container.hdr = canSupportHdr ?? false;
4512
4631
  return;
4513
4632
  }
4514
4633
  this.render.setContextSettings({
@@ -4527,7 +4646,6 @@
4527
4646
  context = null;
4528
4647
  }
4529
4648
  if (canSupportHdr && !context) {
4530
- container.hdr = false;
4531
4649
  const sdrSettings = {
4532
4650
  alpha: true,
4533
4651
  desynchronized: true,
@@ -4543,11 +4661,16 @@
4543
4661
  }
4544
4662
  }
4545
4663
  this.render.setContext(context);
4664
+ if (context) {
4665
+ const effectiveColorSpace = getEffectiveColorSpace(context);
4666
+ if (effectiveColorSpace !== undefined) {
4667
+ container.hdr = effectiveColorSpace === "display-p3";
4668
+ }
4669
+ }
4546
4670
  }
4547
4671
  #initHdrListeners() {
4548
4672
  this.#removeHdrListeners();
4549
4673
  const p3Query = safeMatchMedia("(color-gamut: p3)"), hdrQuery = safeMatchMedia("(dynamic-range: high)"), handleChange = () => {
4550
- this.#recreateRenderCanvas();
4551
4674
  this.#initContext();
4552
4675
  this.initBackground();
4553
4676
  }, listeners = [];
@@ -4583,16 +4706,6 @@
4583
4706
  element.style.setProperty(key, value, "important");
4584
4707
  }
4585
4708
  }
4586
- #recreateRenderCanvas() {
4587
- const renderCanvas = this.renderCanvas;
4588
- if (!renderCanvas) {
4589
- return;
4590
- }
4591
- if (this.domElement) {
4592
- return;
4593
- }
4594
- this.renderCanvas = new OffscreenCanvas(renderCanvas.width, renderCanvas.height);
4595
- }
4596
4709
  #removeHdrListeners() {
4597
4710
  if (!this.#hdrMediaListeners) {
4598
4711
  return;
@@ -4664,6 +4777,10 @@
4664
4777
  this.#manageListeners(true);
4665
4778
  }
4666
4779
  removeListeners() {
4780
+ if (this.#resizeTimeout !== undefined) {
4781
+ clearTimeout(this.#resizeTimeout);
4782
+ this.#resizeTimeout = undefined;
4783
+ }
4667
4784
  this.#manageListeners(false);
4668
4785
  }
4669
4786
  #handleVisibilityChange() {
@@ -4691,8 +4808,7 @@
4691
4808
  this.#resizeTimeout = undefined;
4692
4809
  }
4693
4810
  const handleResize = async () => {
4694
- const canvas = this.#container.canvas;
4695
- await canvas.windowResize();
4811
+ await this.#container.canvas.windowResize();
4696
4812
  };
4697
4813
  this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
4698
4814
  }
@@ -4720,8 +4836,8 @@
4720
4836
  }
4721
4837
  else if (!this.#resizeObserver && add && canvasEl) {
4722
4838
  this.#resizeObserver = new ResizeObserver((entries) => {
4723
- const entry = entries.find(e => e.target === canvasEl);
4724
- if (!entry) {
4839
+ const res = entries.some(e => e.target === canvasEl);
4840
+ if (!res) {
4725
4841
  return;
4726
4842
  }
4727
4843
  this.#handleWindowResize();
@@ -4985,10 +5101,10 @@
4985
5101
  return this.#modifiers.find(m => m.id === id);
4986
5102
  }
4987
5103
  getOpacity() {
4988
- const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, baseOpacity = getRangeValue(this.opacity?.value ?? defaultOpacity$1), modifierOpacity = this.#applyModifiers(undefined, m => m.opacity), opacity = modifierOpacity ?? baseOpacity, fillOpacity = this.fillOpacity ?? defaultOpacity$1, strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
4989
- this.#cachedOpacityData.fillOpacity = fillOpacity;
5104
+ const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, baseOpacity = getRangeValue(this.opacity?.value ?? defaultOpacity$1), modifierOpacity = this.#applyModifiers(undefined, m => m.opacity), opacity = modifierOpacity ?? baseOpacity;
5105
+ this.#cachedOpacityData.fillOpacity = this.fillOpacity ?? defaultOpacity$1;
4990
5106
  this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
4991
- this.#cachedOpacityData.strokeOpacity = strokeOpacity;
5107
+ this.#cachedOpacityData.strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
4992
5108
  return this.#cachedOpacityData;
4993
5109
  }
4994
5110
  getPosition() {
@@ -5235,7 +5351,7 @@
5235
5351
  #initPosition(position) {
5236
5352
  const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
5237
5353
  if (!initialPosition) {
5238
- throw new Error("a valid position cannot be found for particle");
5354
+ throw new Error(getErrorMessage(ErrorCodes$2.particlePositionNotFound));
5239
5355
  }
5240
5356
  this.position = initialPosition;
5241
5357
  this.initialPosition = this.position.copy();
@@ -5284,6 +5400,12 @@
5284
5400
  this.#circlePoolIdx = 0;
5285
5401
  this.#rectanglePoolIdx = 0;
5286
5402
  }
5403
+ get cellSize() {
5404
+ return this.#cellSize;
5405
+ }
5406
+ set cellSize(value) {
5407
+ this.#pendingCellSize = value;
5408
+ }
5287
5409
  clear() {
5288
5410
  this.#cells.clear();
5289
5411
  const pendingCellSize = this.#pendingCellSize;
@@ -5307,40 +5429,46 @@
5307
5429
  const minCellX = Math.floor(bounds.minX / this.#cellSize), maxCellX = Math.floor(bounds.maxX / this.#cellSize), minCellY = Math.floor(bounds.minY / this.#cellSize), maxCellY = Math.floor(bounds.maxY / this.#cellSize);
5308
5430
  for (let cx = minCellX; cx <= maxCellX; cx++) {
5309
5431
  for (let cy = minCellY; cy <= maxCellY; cy++) {
5310
- const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
5311
- if (!cellParticles) {
5312
- continue;
5313
- }
5314
- for (const p of cellParticles) {
5315
- if (check && !check(p)) {
5316
- continue;
5317
- }
5318
- if (range.contains(p.getPosition())) {
5319
- out.push(p);
5320
- }
5321
- }
5432
+ this.#queryCell(cx, cy, range, check, out);
5322
5433
  }
5323
5434
  }
5324
5435
  return out;
5325
5436
  }
5326
5437
  queryCircle(position, radius, check, out = []) {
5327
- const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
5328
- this.#releaseShapes();
5329
- return result;
5438
+ const circle = this.#acquireCircle(position.x, position.y, radius);
5439
+ try {
5440
+ return this.query(circle, check, out);
5441
+ }
5442
+ finally {
5443
+ this.#circlePoolIdx--;
5444
+ }
5330
5445
  }
5331
5446
  queryRectangle(position, size, check, out = []) {
5332
- const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
5333
- this.#releaseShapes();
5334
- return result;
5335
- }
5336
- setCellSize(cellSize) {
5337
- this.#pendingCellSize = cellSize;
5447
+ const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height);
5448
+ try {
5449
+ return this.query(rect, check, out);
5450
+ }
5451
+ finally {
5452
+ this.#rectanglePoolIdx--;
5453
+ }
5338
5454
  }
5339
5455
  #acquireCircle(x, y, r) {
5340
- return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
5456
+ const idx = this.#circlePoolIdx++;
5457
+ let circle = this.#circlePool[idx];
5458
+ if (!circle) {
5459
+ circle = new Circle(x, y, r);
5460
+ this.#circlePool[idx] = circle;
5461
+ }
5462
+ return circle.reset(x, y, r);
5341
5463
  }
5342
5464
  #acquireRectangle(x, y, w, h) {
5343
- return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
5465
+ const idx = this.#rectanglePoolIdx++;
5466
+ let rectangle = this.#rectanglePool[idx];
5467
+ if (!rectangle) {
5468
+ rectangle = new Rectangle(x, y, w, h);
5469
+ this.#rectanglePool[idx] = rectangle;
5470
+ }
5471
+ return rectangle.reset(x, y, w, h);
5344
5472
  }
5345
5473
  #cellKeyFromCoords(x, y) {
5346
5474
  const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
@@ -5367,17 +5495,27 @@
5367
5495
  }
5368
5496
  return null;
5369
5497
  }
5370
- #releaseShapes() {
5371
- this.#circlePoolIdx = 0;
5372
- this.#rectanglePoolIdx = 0;
5498
+ #queryCell(cx, cy, range, check, out) {
5499
+ const cellParticles = this.#cells.get(`${cx}_${cy}`);
5500
+ if (!cellParticles) {
5501
+ return;
5502
+ }
5503
+ for (const p of cellParticles) {
5504
+ if (check && !check(p)) {
5505
+ continue;
5506
+ }
5507
+ if (range.contains(p.getPosition())) {
5508
+ out.push(p);
5509
+ }
5510
+ }
5373
5511
  }
5374
5512
  }
5375
5513
 
5376
5514
  class ParticlesManager {
5377
5515
  checkParticlePositionPlugins;
5378
- grid;
5379
5516
  #array;
5380
5517
  #container;
5518
+ #grid;
5381
5519
  #groupLimits;
5382
5520
  #limit;
5383
5521
  #nextId;
@@ -5401,7 +5539,7 @@
5401
5539
  this.#groupLimits = new Map();
5402
5540
  this.#particleBuckets = new Map();
5403
5541
  this.#zBuckets = this.#createBuckets(this.#container.zLayers);
5404
- this.grid = new SpatialHashGrid(spatialHashGridCellSize);
5542
+ this.#grid = new SpatialHashGrid(spatialHashGridCellSize);
5405
5543
  this.checkParticlePositionPlugins = [];
5406
5544
  this.#particleResetPlugins = [];
5407
5545
  this.#particleUpdatePlugins = [];
@@ -5412,23 +5550,12 @@
5412
5550
  get count() {
5413
5551
  return this.#array.length;
5414
5552
  }
5553
+ get grid() {
5554
+ return this.#grid;
5555
+ }
5415
5556
  addParticle(position, overrideOptions, group, initializer) {
5416
- const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
5417
- if (limit > minLimit) {
5418
- switch (limitMode) {
5419
- case LimitMode.delete: {
5420
- const countToRemove = currentCount + countOffset - limit;
5421
- if (countToRemove > minCount) {
5422
- this.removeQuantity(countToRemove);
5423
- }
5424
- break;
5425
- }
5426
- case LimitMode.wait:
5427
- if (currentCount >= limit) {
5428
- return;
5429
- }
5430
- break;
5431
- }
5557
+ if (this.#checkAndApplyLimits(group, this.count)) {
5558
+ return;
5432
5559
  }
5433
5560
  try {
5434
5561
  const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
@@ -5492,7 +5619,7 @@
5492
5619
  return this.#array[index];
5493
5620
  }
5494
5621
  async init() {
5495
- const container = this.#container, options = container.actualOptions;
5622
+ const container = this.#container;
5496
5623
  this.checkParticlePositionPlugins = [];
5497
5624
  this.#updatePlugins = [];
5498
5625
  this.#particleUpdatePlugins = [];
@@ -5501,59 +5628,16 @@
5501
5628
  this.#postParticleUpdatePlugins = [];
5502
5629
  this.#particleBuckets.clear();
5503
5630
  this.#resetBuckets(container.zLayers);
5504
- this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
5505
- for (const plugin of container.plugins) {
5506
- if (plugin.redrawInit) {
5507
- await plugin.redrawInit();
5508
- }
5509
- if (plugin.checkParticlePosition) {
5510
- this.checkParticlePositionPlugins.push(plugin);
5511
- }
5512
- if (plugin.update) {
5513
- this.#updatePlugins.push(plugin);
5514
- }
5515
- if (plugin.particleUpdate) {
5516
- this.#particleUpdatePlugins.push(plugin);
5517
- }
5518
- if (plugin.postUpdate) {
5519
- this.#postUpdatePlugins.push(plugin);
5520
- }
5521
- if (plugin.particleReset) {
5522
- this.#particleResetPlugins.push(plugin);
5523
- }
5524
- if (plugin.postParticleUpdate) {
5525
- this.#postParticleUpdatePlugins.push(plugin);
5526
- }
5527
- }
5528
- await this.#container.initDrawersAndUpdaters();
5529
- for (const drawer of this.#container.effectDrawers.values()) {
5530
- await drawer.init?.(container);
5531
- }
5532
- for (const drawer of this.#container.shapeDrawers.values()) {
5533
- await drawer.init?.(container);
5534
- }
5535
- let handled = false;
5536
- for (const plugin of container.plugins) {
5537
- handled = plugin.particlesInitialization?.() ?? handled;
5538
- if (handled) {
5539
- break;
5540
- }
5541
- }
5542
- if (!handled) {
5543
- const particlesOptions = options.particles, groups = particlesOptions.groups;
5544
- for (const group in groups) {
5545
- const groupOptions = groups[group];
5546
- if (!groupOptions) {
5547
- continue;
5548
- }
5549
- for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
5550
- this.addParticle(undefined, groupOptions, group);
5551
- }
5552
- }
5553
- for (let i = this.count; i < particlesOptions.number.value; i++) {
5554
- this.addParticle();
5631
+ this.#grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
5632
+ this.#applyLimits(container.actualOptions.particles);
5633
+ const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
5634
+ for (const group in groups) {
5635
+ const groupData = groups[group];
5636
+ if (groupData) {
5637
+ this.#applyLimits(loadParticlesOptions(this.#pluginManager, this.#container, groupData), group, groupData);
5555
5638
  }
5556
5639
  }
5640
+ await this.#initPlugins();
5557
5641
  }
5558
5642
  push(nb, position, overrideOptions, group) {
5559
5643
  for (let i = 0; i < nb; i++) {
@@ -5568,13 +5652,13 @@
5568
5652
  remove(particle, group, override) {
5569
5653
  this.removeAt(this.#array.indexOf(particle), undefined, group, override);
5570
5654
  }
5571
- removeAt(index, quantity = defaultRemoveQuantity, group, override) {
5655
+ removeAt(index, quantity = defaultRemoveQuantity, group, override, matchGroup = true) {
5572
5656
  if (index < minIndex || index > this.count) {
5573
5657
  return;
5574
5658
  }
5575
5659
  let deleted = 0;
5576
5660
  for (let i = index; deleted < quantity && i < this.count; i++) {
5577
- if (this.#removeParticle(i, group, override)) {
5661
+ if (this.#removeParticle(i, group, override, matchGroup)) {
5578
5662
  i--;
5579
5663
  deleted++;
5580
5664
  }
@@ -5605,7 +5689,7 @@
5605
5689
  this.#resizeFactor = factor;
5606
5690
  }
5607
5691
  update(delta) {
5608
- this.grid.clear();
5692
+ this.#grid.clear();
5609
5693
  for (const plugin of this.#updatePlugins) {
5610
5694
  plugin.update?.(delta);
5611
5695
  }
@@ -5616,7 +5700,7 @@
5616
5700
  this.#updateParticlesPhase2(delta, particlesToDelete);
5617
5701
  if (particlesToDelete.size) {
5618
5702
  for (const particle of particlesToDelete) {
5619
- this.remove(particle);
5703
+ this.remove(particle, particle.group);
5620
5704
  }
5621
5705
  }
5622
5706
  this.#resizeFactor = undefined;
@@ -5627,12 +5711,7 @@
5627
5711
  #applyDensity(options, pluginsCount, group, groupOptions) {
5628
5712
  const numberOptions = options.number;
5629
5713
  if (!numberOptions.density.enable) {
5630
- if (group === undefined) {
5631
- this.#limit = numberOptions.limit.value;
5632
- }
5633
- else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
5634
- this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
5635
- }
5714
+ this.#applyLimits(options, group, groupOptions);
5636
5715
  return;
5637
5716
  }
5638
5717
  const densityFactor = this.#initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + pluginsCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
@@ -5640,7 +5719,10 @@
5640
5719
  this.#limit = numberOptions.limit.value * densityFactor;
5641
5720
  }
5642
5721
  else {
5643
- this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
5722
+ this.#groupLimits.set(group, {
5723
+ limit: numberOptions.limit.value * densityFactor,
5724
+ mode: toEnumValue(LimitMode, numberOptions.limit.mode, LimitMode.delete),
5725
+ });
5644
5726
  }
5645
5727
  if (particlesCount < particlesNumber) {
5646
5728
  this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
@@ -5649,6 +5731,55 @@
5649
5731
  this.removeQuantity(particlesCount - particlesNumber, group);
5650
5732
  }
5651
5733
  }
5734
+ #applyLimits(options, group, groupOptions) {
5735
+ if (group === undefined) {
5736
+ this.#limit = options.number.limit.value;
5737
+ const groups = this.#container.actualOptions.particles.groups;
5738
+ for (const existingGroup of this.#groupLimits.keys()) {
5739
+ if (!(existingGroup in groups)) {
5740
+ this.#groupLimits.delete(existingGroup);
5741
+ }
5742
+ }
5743
+ }
5744
+ else {
5745
+ const limitValue = groupOptions?.number?.limit?.value ?? options.number.limit.value;
5746
+ if (limitValue > minLimit) {
5747
+ this.#groupLimits.set(group, {
5748
+ limit: limitValue,
5749
+ mode: toEnumValue(LimitMode, groupOptions?.number?.limit?.mode ?? options.number.limit.mode, LimitMode.delete),
5750
+ });
5751
+ }
5752
+ else {
5753
+ this.#groupLimits.delete(group);
5754
+ }
5755
+ }
5756
+ }
5757
+ #checkAndApplyLimits(group, currentCount) {
5758
+ const globalLimit = this.#limit, globalMode = this.#container.actualOptions.particles.number.limit.mode;
5759
+ if (globalLimit > minLimit && globalMode === LimitMode.wait && currentCount >= globalLimit) {
5760
+ return true;
5761
+ }
5762
+ const groupLimitEntry = group === undefined ? undefined : this.#groupLimits.get(group);
5763
+ if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.wait) {
5764
+ const groupCount = this.filter(t => t.group === group).length;
5765
+ if (groupCount >= groupLimitEntry.limit) {
5766
+ return true;
5767
+ }
5768
+ }
5769
+ if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.delete) {
5770
+ const groupCountToRemove = this.filter(t => t.group === group).length + countOffset - groupLimitEntry.limit;
5771
+ if (groupCountToRemove > minCount) {
5772
+ this.removeQuantity(groupCountToRemove, group);
5773
+ }
5774
+ }
5775
+ if (globalLimit > minLimit && globalMode === LimitMode.delete) {
5776
+ const globalCountToRemove = this.count + countOffset - globalLimit;
5777
+ if (globalCountToRemove > minCount) {
5778
+ this.#removeAny(globalCountToRemove);
5779
+ }
5780
+ }
5781
+ return false;
5782
+ }
5652
5783
  #createBuckets(zLayers) {
5653
5784
  const bucketCount = Math.max(Math.floor(zLayers), one);
5654
5785
  return Array.from({ length: bucketCount }, () => []);
@@ -5671,6 +5802,70 @@
5671
5802
  }
5672
5803
  return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
5673
5804
  }
5805
+ async #initDrawersAndUpdaters() {
5806
+ const container = this.#container;
5807
+ await container.initDrawersAndUpdaters();
5808
+ for (const drawer of container.effectDrawers.values()) {
5809
+ await drawer.init?.(container);
5810
+ }
5811
+ for (const drawer of container.shapeDrawers.values()) {
5812
+ await drawer.init?.(container);
5813
+ }
5814
+ }
5815
+ async #initPlugins() {
5816
+ await this.#initPluginsArrays();
5817
+ await this.#initDrawersAndUpdaters();
5818
+ let handled = false;
5819
+ const container = this.#container;
5820
+ for (const plugin of container.plugins) {
5821
+ handled = plugin.particlesInitialization?.() ?? handled;
5822
+ if (handled) {
5823
+ break;
5824
+ }
5825
+ }
5826
+ if (handled) {
5827
+ return;
5828
+ }
5829
+ const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
5830
+ for (const group in groups) {
5831
+ const groupOptions = groups[group];
5832
+ if (!groupOptions) {
5833
+ continue;
5834
+ }
5835
+ for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
5836
+ this.addParticle(undefined, groupOptions, group);
5837
+ }
5838
+ }
5839
+ for (let i = this.count; i < particlesOptions.number.value; i++) {
5840
+ this.addParticle();
5841
+ }
5842
+ }
5843
+ async #initPluginsArrays() {
5844
+ const container = this.#container;
5845
+ for (const plugin of container.plugins) {
5846
+ if (plugin.redrawInit) {
5847
+ await plugin.redrawInit();
5848
+ }
5849
+ if (plugin.checkParticlePosition) {
5850
+ this.checkParticlePositionPlugins.push(plugin);
5851
+ }
5852
+ if (plugin.update) {
5853
+ this.#updatePlugins.push(plugin);
5854
+ }
5855
+ if (plugin.particleUpdate) {
5856
+ this.#particleUpdatePlugins.push(plugin);
5857
+ }
5858
+ if (plugin.postUpdate) {
5859
+ this.#postUpdatePlugins.push(plugin);
5860
+ }
5861
+ if (plugin.particleReset) {
5862
+ this.#particleResetPlugins.push(plugin);
5863
+ }
5864
+ if (plugin.postParticleUpdate) {
5865
+ this.#postParticleUpdatePlugins.push(plugin);
5866
+ }
5867
+ }
5868
+ }
5674
5869
  #insertParticleIntoBucket(particle) {
5675
5870
  const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
5676
5871
  if (!bucket) {
@@ -5679,12 +5874,15 @@
5679
5874
  bucket.push(particle);
5680
5875
  this.#particleBuckets.set(particle.id, bucketIndex);
5681
5876
  }
5682
- #removeParticle(index, group, override) {
5877
+ #removeAny(quantity) {
5878
+ this.removeAt(minIndex, quantity, undefined, undefined, false);
5879
+ }
5880
+ #removeParticle(index, group, override, matchGroup = true) {
5683
5881
  const particle = this.#array[index];
5684
5882
  if (!particle) {
5685
5883
  return false;
5686
5884
  }
5687
- if (particle.group !== group) {
5885
+ if (matchGroup && particle.group !== group) {
5688
5886
  return false;
5689
5887
  }
5690
5888
  this.#array.splice(index, deleteCount);
@@ -5771,7 +5969,7 @@
5771
5969
  particlesToDelete.add(particle);
5772
5970
  continue;
5773
5971
  }
5774
- this.grid.insert(particle);
5972
+ this.#grid.insert(particle);
5775
5973
  }
5776
5974
  return particlesToDelete;
5777
5975
  }
@@ -5858,6 +6056,7 @@
5858
6056
  started;
5859
6057
  zLayers;
5860
6058
  #delay;
6059
+ #delayResolve;
5861
6060
  #delayTimeout;
5862
6061
  #delta = { value: 0, factor: 0 };
5863
6062
  #dispatchCallback;
@@ -5947,7 +6146,6 @@
5947
6146
  this.shapeDrawers = new Map();
5948
6147
  this.particleUpdaters = [];
5949
6148
  this.plugins.length = 0;
5950
- this.#pluginManager.clearPlugins(this);
5951
6149
  this.destroyed = true;
5952
6150
  this.#onDestroy(remove);
5953
6151
  this.dispatchEvent(EventType.containerDestroyed);
@@ -6000,31 +6198,14 @@
6000
6198
  await this.initDrawersAndUpdaters();
6001
6199
  this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
6002
6200
  this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
6003
- this.plugins.length = 0;
6004
- this.particleDestroyedPlugins.length = 0;
6005
- this.particleCreatedPlugins.length = 0;
6006
- this.particlePositionPlugins.length = 0;
6007
- for (const [plugin, containerPlugin] of allContainerPlugins) {
6008
- if (plugin.needsPlugin(this.actualOptions)) {
6009
- this.plugins.push(containerPlugin);
6010
- if (containerPlugin.particleCreated) {
6011
- this.particleCreatedPlugins.push(containerPlugin);
6012
- }
6013
- if (containerPlugin.particleDestroyed) {
6014
- this.particleDestroyedPlugins.push(containerPlugin);
6015
- }
6016
- if (containerPlugin.particlePosition) {
6017
- this.particlePositionPlugins.push(containerPlugin);
6018
- }
6019
- }
6020
- }
6201
+ this.#initPlugins(allContainerPlugins);
6021
6202
  this.retina.init();
6022
6203
  this.canvas.init();
6023
6204
  this.updateActualOptions();
6024
6205
  this.canvas.initBackground();
6025
6206
  this.canvas.resize();
6026
6207
  const { delay, duration, fpsLimit, smooth, zLayers } = this.actualOptions, hdrOptions = this.actualOptions.hdr;
6027
- this.hdrMode = hdrOptions.mode;
6208
+ this.hdrMode = toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard);
6028
6209
  this.peakNits = hdrOptions.peakNits;
6029
6210
  this.zLayers = zLayers;
6030
6211
  this.#duration = getRangeValue(duration) * millisecondsToSeconds;
@@ -6045,9 +6226,9 @@
6045
6226
  }
6046
6227
  async initDrawersAndUpdaters() {
6047
6228
  const pluginManager = this.#pluginManager;
6048
- this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
6049
- this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
6050
- this.particleUpdaters = await pluginManager.getUpdaters(this, true);
6229
+ this.effectDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.effects);
6230
+ this.shapeDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.shapes);
6231
+ this.particleUpdaters = await getItemsFromInitializer(this, pluginManager.initializers.updaters);
6051
6232
  }
6052
6233
  pause() {
6053
6234
  if (!guardCheck(this)) {
@@ -6114,7 +6295,10 @@
6114
6295
  await this.init();
6115
6296
  this.started = true;
6116
6297
  await new Promise(resolve => {
6298
+ this.#delayResolve = resolve;
6117
6299
  const start = async () => {
6300
+ this.#delayTimeout = undefined;
6301
+ this.#delayResolve = undefined;
6118
6302
  this.#eventListeners.addListeners();
6119
6303
  for (const plugin of this.plugins) {
6120
6304
  await plugin.start?.();
@@ -6130,9 +6314,11 @@
6130
6314
  if (!guardCheck(this) || !this.started) {
6131
6315
  return;
6132
6316
  }
6133
- if (this.#delayTimeout) {
6317
+ if (this.#delayTimeout !== undefined) {
6134
6318
  clearTimeout(this.#delayTimeout);
6135
6319
  this.#delayTimeout = undefined;
6320
+ this.#delayResolve?.();
6321
+ this.#delayResolve = undefined;
6136
6322
  }
6137
6323
  this.#firstStart = true;
6138
6324
  this.started = false;
@@ -6158,6 +6344,27 @@
6158
6344
  }
6159
6345
  return refresh;
6160
6346
  }
6347
+ #initPlugins(allContainerPlugins) {
6348
+ this.plugins.length = 0;
6349
+ this.particleDestroyedPlugins.length = 0;
6350
+ this.particleCreatedPlugins.length = 0;
6351
+ this.particlePositionPlugins.length = 0;
6352
+ for (const [plugin, containerPlugin] of allContainerPlugins) {
6353
+ if (!plugin.needsPlugin(this.actualOptions)) {
6354
+ continue;
6355
+ }
6356
+ this.plugins.push(containerPlugin);
6357
+ if (containerPlugin.particleCreated) {
6358
+ this.particleCreatedPlugins.push(containerPlugin);
6359
+ }
6360
+ if (containerPlugin.particleDestroyed) {
6361
+ this.particleDestroyedPlugins.push(containerPlugin);
6362
+ }
6363
+ if (containerPlugin.particlePosition) {
6364
+ this.particlePositionPlugins.push(containerPlugin);
6365
+ }
6366
+ }
6367
+ }
6161
6368
  #nextFrame(timestamp) {
6162
6369
  try {
6163
6370
  if (!this.#smooth &&
@@ -6434,11 +6641,11 @@
6434
6641
  }
6435
6642
  }
6436
6643
  async #init() {
6437
- const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
6438
- if (!availablePathGenerators) {
6644
+ const pluginManager = this.#pluginManager;
6645
+ if (!pluginManager.initializers.pathGenerators) {
6439
6646
  return;
6440
6647
  }
6441
- this.availablePathGenerators = availablePathGenerators;
6648
+ this.availablePathGenerators = await getItemMapFromInitializer(this.#container, pluginManager.initializers.pathGenerators);
6442
6649
  this.pathGenerators = new Map();
6443
6650
  for (const pathGenerator of this.pathGenerators.values()) {
6444
6651
  pathGenerator.init();
@@ -6542,28 +6749,14 @@
6542
6749
  }
6543
6750
  const html = interactivityEl, canvas = container.canvas;
6544
6751
  canvas.setPointerEvents(html === canvas.domElement ? "initial" : "none");
6545
- if (add && !(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
6546
- return;
6547
- }
6548
6752
  manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
6549
6753
  manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
6550
6754
  manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
6551
- if (add) {
6552
- if (options.interactivity?.events.onClick.enable) {
6553
- manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
6554
- manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
6555
- manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
6556
- }
6557
- else {
6558
- manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
6559
- }
6560
- }
6561
- else {
6562
- manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
6563
- manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
6564
- manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
6565
- manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
6566
- }
6755
+ const onClickEnabled = !!options.interactivity?.events.onClick.enable;
6756
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add && onClickEnabled);
6757
+ manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add && !onClickEnabled);
6758
+ manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
6759
+ manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
6567
6760
  manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
6568
6761
  manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
6569
6762
  }
@@ -6589,19 +6782,18 @@
6589
6782
  #mouseTouchClick(e) {
6590
6783
  const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
6591
6784
  mouse.inside = true;
6592
- let handled = false;
6593
6785
  const mousePosition = mouse.position;
6594
- if (!mousePosition || !options.interactivity?.events.onClick.enable) {
6595
- return;
6596
- }
6597
- for (const plugin of this.#clickPositionPlugins) {
6598
- handled = plugin.clickPositionValid?.(mousePosition) ?? false;
6599
- if (handled) {
6600
- break;
6786
+ if (mousePosition && options.interactivity?.events.onClick.enable) {
6787
+ let handled = false;
6788
+ for (const plugin of this.#clickPositionPlugins) {
6789
+ handled = plugin.clickPositionValid?.(mousePosition) ?? false;
6790
+ if (handled) {
6791
+ break;
6792
+ }
6793
+ }
6794
+ if (!handled) {
6795
+ this.#doMouseTouchClick(e);
6601
6796
  }
6602
- }
6603
- if (!handled) {
6604
- this.#doMouseTouchClick(e);
6605
6797
  }
6606
6798
  mouse.clicking = false;
6607
6799
  }
@@ -6697,6 +6889,9 @@
6697
6889
  this.#touches.set(touch.identifier, performance.now());
6698
6890
  }
6699
6891
  this.#mouseTouchMove(e);
6892
+ const { mouse } = this.#interactionManager.interactivityData;
6893
+ mouse.clicking = true;
6894
+ mouse.downPosition = mouse.position;
6700
6895
  }
6701
6896
  }
6702
6897
 
@@ -6709,18 +6904,18 @@
6709
6904
  }
6710
6905
  class InteractionManager {
6711
6906
  interactivityData;
6907
+ interactors;
6712
6908
  #clickHandlers;
6713
6909
  #container;
6714
6910
  #eventListeners;
6715
6911
  #externalInteractors;
6716
- #interactors;
6717
6912
  #intersectionObserver;
6718
6913
  #particleInteractors;
6719
6914
  #pluginManager;
6720
6915
  constructor(pluginManager, container) {
6721
6916
  this.#container = container;
6722
6917
  this.#pluginManager = pluginManager;
6723
- this.#interactors = [];
6918
+ this.interactors = [];
6724
6919
  this.#externalInteractors = [];
6725
6920
  this.#particleInteractors = [];
6726
6921
  this.#clickHandlers = new Map();
@@ -6839,7 +7034,7 @@
6839
7034
  }
6840
7035
  init() {
6841
7036
  this.#eventListeners.init();
6842
- for (const interactor of this.#interactors) {
7037
+ for (const interactor of this.interactors) {
6843
7038
  switch (interactor.type) {
6844
7039
  case InteractorType.external:
6845
7040
  this.#externalInteractors.push(interactor);
@@ -6852,11 +7047,11 @@
6852
7047
  }
6853
7048
  }
6854
7049
  async initInteractors() {
6855
- const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
6856
- if (!interactors) {
7050
+ const pluginManager = this.#pluginManager;
7051
+ if (!pluginManager.initializers.interactors) {
6857
7052
  return;
6858
7053
  }
6859
- this.#interactors = interactors;
7054
+ this.interactors = await getItemsFromInitializer(this.#container, pluginManager.initializers.interactors);
6860
7055
  this.#externalInteractors = [];
6861
7056
  this.#particleInteractors = [];
6862
7057
  }
@@ -6901,13 +7096,13 @@
6901
7096
  }
6902
7097
  updateMaxDistance() {
6903
7098
  let maxTotalDistance = 0;
6904
- for (const interactor of this.#interactors) {
7099
+ for (const interactor of this.interactors) {
6905
7100
  if (interactor.maxDistance > maxTotalDistance) {
6906
7101
  maxTotalDistance = interactor.maxDistance;
6907
7102
  }
6908
7103
  }
6909
7104
  const container = this.#container;
6910
- container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
7105
+ container.particles.grid.cellSize = maxTotalDistance * container.retina.pixelRatio;
6911
7106
  }
6912
7107
  #intersectionManager(entries) {
6913
7108
  const container = this.#container;
@@ -6929,59 +7124,59 @@
6929
7124
  }
6930
7125
 
6931
7126
  class InteractivityPluginInstance {
6932
- interactionManager;
6933
7127
  #container;
6934
- #pluginManager;
6935
7128
  constructor(pluginManager, container) {
6936
- this.#container = container;
6937
- this.#pluginManager = pluginManager;
6938
- this.interactionManager = new InteractionManager(pluginManager, container);
6939
- this.#container.addClickHandler = (callback) => {
6940
- this.interactionManager.addClickHandler(callback);
7129
+ container.addClickHandler = (callback) => {
7130
+ container.interactionManager?.addClickHandler(callback);
6941
7131
  };
7132
+ container.interactionManager = new InteractionManager(pluginManager, container);
7133
+ this.#container = container;
6942
7134
  }
6943
7135
  addClickHandler(callback) {
6944
- this.interactionManager.addClickHandler(callback);
7136
+ this.#container.interactionManager?.addClickHandler(callback);
6945
7137
  }
6946
7138
  clearClickHandlers() {
6947
- this.interactionManager.clearClickHandlers();
7139
+ this.#container.interactionManager?.clearClickHandlers();
6948
7140
  }
6949
7141
  destroy() {
6950
7142
  this.clearClickHandlers();
6951
- this.#pluginManager.interactors?.delete(this.#container);
6952
7143
  }
6953
7144
  particleCreated(particle) {
6954
- const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
6955
- interactivity.load(this.#container.actualOptions.interactivity);
7145
+ const interactivityParticle = particle, container = this.#container, interactivity = new Interactivity(container);
7146
+ interactivity.load(container.actualOptions.interactivity);
6956
7147
  interactivity.load(interactivityParticle.options.interactivity);
6957
7148
  interactivityParticle.interactivity = interactivity;
6958
7149
  }
6959
7150
  particleReset(particle) {
6960
- this.interactionManager.reset(particle);
7151
+ this.#container.interactionManager?.reset(particle);
6961
7152
  }
6962
7153
  postParticleUpdate(particle, delta) {
6963
- this.interactionManager.particlesInteract(particle, delta);
7154
+ this.#container.interactionManager?.particlesInteract(particle, delta);
6964
7155
  }
6965
7156
  postUpdate(delta) {
6966
- this.interactionManager.externalInteract(delta);
6967
- this.interactionManager.updateMaxDistance();
7157
+ const container = this.#container;
7158
+ container.interactionManager?.externalInteract(delta);
7159
+ container.interactionManager?.updateMaxDistance();
6968
7160
  }
6969
7161
  async preInit() {
6970
- await this.interactionManager.initInteractors();
6971
- this.interactionManager.init();
7162
+ const container = this.#container;
7163
+ await container.interactionManager?.initInteractors();
7164
+ container.interactionManager?.init();
6972
7165
  }
6973
7166
  async redrawInit() {
6974
- await this.interactionManager.initInteractors();
6975
- this.interactionManager.init();
7167
+ const container = this.#container;
7168
+ await container.interactionManager?.initInteractors();
7169
+ container.interactionManager?.init();
6976
7170
  }
6977
7171
  start() {
6978
- this.interactionManager.addListeners();
6979
- this.interactionManager.startObserving();
7172
+ const container = this.#container;
7173
+ container.interactionManager?.addListeners();
7174
+ container.interactionManager?.startObserving();
6980
7175
  return Promise.resolve();
6981
7176
  }
6982
7177
  stop() {
6983
- this.interactionManager.removeListeners();
6984
- this.interactionManager.stopObserving();
7178
+ this.#container.interactionManager?.removeListeners();
7179
+ this.#container.interactionManager?.stopObserving();
6985
7180
  }
6986
7181
  }
6987
7182
 
@@ -7175,6 +7370,7 @@
7175
7370
  exports.loadLinksPreset = loadLinksPreset;
7176
7371
  exports.tsParticles = tsParticles;
7177
7372
 
7178
- }));
7373
+ })(g.__tsParticlesInternals.presets.links = g.__tsParticlesInternals.presets.links || {});
7374
+ })(typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : self);
7375
+
7179
7376
  Object.assign(globalThis.window || globalThis, { loadLinksPreset: (globalThis.__tsParticlesInternals.presets.links || {}).loadLinksPreset });
7180
- delete (globalThis.window || globalThis).tsparticlesInternalExports;