@tsparticles/preset-stars 4.4.0 → 4.5.0

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.stars = global.__tsParticlesInternals.presets.stars || {})));
7
- })(this, (function (exports) { 'use strict';
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.0 */
4
+ g.__tsParticlesInternals = g.__tsParticlesInternals || {};
5
+ g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
6
+ (function (exports) {
7
+ 'use strict';
8
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", 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 = 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, 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;
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", 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 = 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, 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
  }
@@ -270,11 +301,61 @@
270
301
  };
271
302
  }
272
303
  function parseAlpha(input) {
273
- const defaultAlpha = 1;
274
304
  if (!input) {
275
305
  return defaultAlpha;
276
306
  }
277
- return input.endsWith("%") ? parseFloat(input) / percentDenominator : parseFloat(input);
307
+ return input.endsWith("%") ? Number.parseFloat(input) / percentDenominator : Number.parseFloat(input);
308
+ }
309
+
310
+ const ErrorCodes$1 = {
311
+ engineVersionMismatch: "TSP-1001",
312
+ particlePositionNotFound: "TSP-1002",
313
+ pluginRegisterAfterLoad: "TSP-1003",
314
+ offscreenCanvasUnsupported: "TSP-1101",
315
+ offscreenCanvasTransferFailed: "TSP-1102",
316
+ hdrEnableInvalid: "TSP-1201",
317
+ hdrModeInvalid: "TSP-1202",
318
+ hdrPeakNitsInvalid: "TSP-1203",
319
+ };
320
+
321
+ const messages = {
322
+ [ErrorCodes$1.engineVersionMismatch]: "The tsParticles version is different from the loaded plugins version. Engine version: {0}. Plugin version: {1}",
323
+ [ErrorCodes$1.particlePositionNotFound]: "a valid position cannot be found for particle",
324
+ [ErrorCodes$1.pluginRegisterAfterLoad]: "Register plugins can only be done before calling tsParticles.load()",
325
+ [ErrorCodes$1.offscreenCanvasUnsupported]: "OffscreenCanvas is required but not supported by this browser",
326
+ [ErrorCodes$1.offscreenCanvasTransferFailed]: "OffscreenCanvas transfer failed",
327
+ [ErrorCodes$1.hdrEnableInvalid]: 'Invalid HDR "enable" value: expected a boolean, got "{0}"',
328
+ [ErrorCodes$1.hdrModeInvalid]: 'Invalid HDR "mode" value: expected one of {0}, got "{1}"',
329
+ [ErrorCodes$1.hdrPeakNitsInvalid]: 'Invalid HDR "peakNits" value: expected a positive number, got "{0}"',
330
+ };
331
+
332
+ let registeredMessages;
333
+ const ensureRegisteredMessages = () => {
334
+ registeredMessages ??= new Map(Object.entries(messages));
335
+ return registeredMessages;
336
+ }, toStringValue$1 = (value) => String(value), format = (template, args) => {
337
+ return template.replace(/\{(\d+)\}/g, (match, index) => {
338
+ const arg = args[Number(index)];
339
+ return arg === undefined ? match : toStringValue$1(arg);
340
+ });
341
+ };
342
+ function addErrorMessages(extraMessages) {
343
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
344
+ return;
345
+ }
346
+ const catalog = ensureRegisteredMessages();
347
+ for (const [code, message] of Object.entries(extraMessages)) {
348
+ if (message !== undefined) {
349
+ catalog.set(code, message);
350
+ }
351
+ }
352
+ }
353
+ function getErrorMessage(code, ...args) {
354
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
355
+ return `[tsParticles Error ${code}] https://particles.js.org/errors/#${code}`;
356
+ }
357
+ const template = ensureRegisteredMessages().get(code) ?? `Unknown error code ${code}`;
358
+ return format(template, args);
278
359
  }
279
360
 
280
361
  var OutModeDirection;
@@ -291,7 +372,6 @@
291
372
  PixelMode["percent"] = "percent";
292
373
  })(PixelMode || (PixelMode = {}));
293
374
 
294
- const minRadius = 0;
295
375
  function isForbiddenKey(key) {
296
376
  return key === "__proto__" || key === "constructor" || key === "prototype";
297
377
  }
@@ -487,22 +567,84 @@
487
567
  element.removeEventListener(event, handler, removeOptions);
488
568
  }
489
569
  }
490
- async function getItemsFromInitializer(container, map, initializers, force = false) {
491
- let res = map.get(container);
492
- if (!res || force) {
493
- res = await Promise.all([...initializers.values()].map(t => t(container)));
494
- map.set(container, res);
570
+ async function getItemsFromInitializer(container, initializers) {
571
+ return await Promise.all([...initializers.values()].map(t => t(container)));
572
+ }
573
+ async function getItemMapFromInitializer(container, initializers) {
574
+ const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
575
+ return new Map(entries);
576
+ }
577
+ async function getDataFromUrl(data) {
578
+ const url = itemFromSingleOrMultiple(data.url, data.index);
579
+ if (!url) {
580
+ return data.fallback;
495
581
  }
496
- return res;
582
+ try {
583
+ const response = await fetch(url);
584
+ if (response.ok) {
585
+ const current = (await response.json());
586
+ if (isSourceOptionsValue(current)) {
587
+ return current;
588
+ }
589
+ getLogger().error("invalid configuration data while retrieving config file");
590
+ }
591
+ else {
592
+ getLogger().error(`${response.status.toString()} while retrieving config file`);
593
+ }
594
+ }
595
+ catch (error) {
596
+ getLogger().error(`error while retrieving config file: ${error}`);
597
+ }
598
+ return data.fallback;
497
599
  }
498
- async function getItemMapFromInitializer(container, map, initializers, force = false) {
499
- let res = map.get(container);
500
- if (!res || force) {
501
- const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
502
- res = new Map(entries);
503
- map.set(container, res);
600
+ function isSourceOptionsValue(value) {
601
+ if (isArray(value)) {
602
+ return value.every((entry) => isObject(entry) && !isArray(entry));
504
603
  }
505
- return res;
604
+ return isObject(value) && !isArray(value);
605
+ }
606
+ function getCanvasFromContainer(domContainer) {
607
+ let canvasEl;
608
+ const documentSafe = safeDocument(), isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
609
+ if (isCanvas) {
610
+ canvasEl = domContainer;
611
+ canvasEl.dataset[generatedAttribute] ??= generatedFalse;
612
+ if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
613
+ canvasEl.style.width ||= fullPercent;
614
+ canvasEl.style.height ||= fullPercent;
615
+ canvasEl.style.pointerEvents = "none";
616
+ canvasEl.style.setProperty("pointer-events", "none");
617
+ }
618
+ }
619
+ else {
620
+ const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
621
+ if (foundCanvas) {
622
+ canvasEl = foundCanvas;
623
+ canvasEl.dataset[generatedAttribute] = generatedFalse;
624
+ }
625
+ else {
626
+ canvasEl = documentSafe.createElement(canvasTag);
627
+ canvasEl.dataset[generatedAttribute] = generatedTrue;
628
+ domContainer.appendChild(canvasEl);
629
+ }
630
+ canvasEl.style.width ||= fullPercent;
631
+ canvasEl.style.height ||= fullPercent;
632
+ canvasEl.style.pointerEvents = "none";
633
+ canvasEl.style.setProperty("pointer-events", "none");
634
+ }
635
+ return canvasEl;
636
+ }
637
+ function getDomContainer(id, source) {
638
+ const documentSafe = safeDocument();
639
+ let domContainer = source ?? documentSafe.getElementById(id);
640
+ if (domContainer) {
641
+ return domContainer;
642
+ }
643
+ domContainer = documentSafe.createElement("canvas");
644
+ domContainer.id = id;
645
+ domContainer.dataset[generatedAttribute] = generatedTrue;
646
+ documentSafe.body.append(domContainer);
647
+ return domContainer;
506
648
  }
507
649
 
508
650
  class EventDispatcher {
@@ -573,7 +715,6 @@
573
715
  class PluginManager {
574
716
  colorManagers = new Map();
575
717
  easingFunctions = new Map();
576
- effectDrawers = new Map();
577
718
  initializers = {
578
719
  effects: new Map(),
579
720
  shapes: new Map(),
@@ -582,8 +723,6 @@
582
723
  palettes = new Map();
583
724
  plugins = [];
584
725
  presets = new Map();
585
- shapeDrawers = new Map();
586
- updaters = new Map();
587
726
  #allLoadersSet = new Set();
588
727
  #configs = new Map();
589
728
  #engine;
@@ -601,57 +740,79 @@
601
740
  }
602
741
  return res;
603
742
  }
743
+ get initialized() {
744
+ return this.#initialized;
745
+ }
604
746
  addColorManager(name, manager) {
747
+ if (this.#initialized) {
748
+ return;
749
+ }
605
750
  this.colorManagers.set(name, manager);
606
751
  }
607
752
  addConfig(config) {
753
+ if (this.#initialized) {
754
+ return;
755
+ }
608
756
  const key = config.key ?? config.name ?? "default";
609
757
  this.#configs.set(key, config);
610
758
  this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
611
759
  }
612
760
  addEasing(name, easing) {
761
+ if (this.#initialized) {
762
+ return;
763
+ }
613
764
  if (this.easingFunctions.get(name)) {
614
765
  return;
615
766
  }
616
767
  this.easingFunctions.set(name, easing);
617
768
  }
618
769
  addEffect(effect, drawer) {
770
+ if (this.#initialized) {
771
+ return;
772
+ }
619
773
  this.initializers.effects.set(effect, drawer);
620
774
  }
621
775
  addPalette(name, palette) {
776
+ if (this.#initialized) {
777
+ return;
778
+ }
622
779
  this.palettes.set(name, palette);
623
780
  }
624
781
  addParticleUpdater(name, updaterInitializer) {
782
+ if (this.#initialized) {
783
+ return;
784
+ }
625
785
  this.initializers.updaters.set(name, updaterInitializer);
626
786
  }
627
787
  addPlugin(plugin) {
788
+ if (this.#initialized) {
789
+ return;
790
+ }
628
791
  if (this.getPlugin(plugin.id)) {
629
792
  return;
630
793
  }
631
794
  this.plugins.push(plugin);
632
795
  }
633
796
  addPreset(preset, options, override = false) {
797
+ if (this.#initialized) {
798
+ return;
799
+ }
634
800
  if (!(override || !this.getPreset(preset))) {
635
801
  return;
636
802
  }
637
803
  this.presets.set(preset, options);
638
804
  }
639
805
  addShape(shapes, drawer) {
806
+ if (this.#initialized) {
807
+ return;
808
+ }
640
809
  for (const shape of shapes) {
641
810
  this.initializers.shapes.set(shape, drawer);
642
811
  }
643
812
  }
644
- clearPlugins(container) {
645
- this.effectDrawers.delete(container);
646
- this.shapeDrawers.delete(container);
647
- this.updaters.delete(container);
648
- }
649
813
  getEasing(name) {
650
814
  return this.easingFunctions.get(name) ?? ((value) => value);
651
815
  }
652
- getEffectDrawers(container, force = false) {
653
- return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
654
- }
655
816
  getPalette(name) {
656
817
  return this.palettes.get(name);
657
818
  }
@@ -661,12 +822,6 @@
661
822
  getPreset(preset) {
662
823
  return this.presets.get(preset);
663
824
  }
664
- async getShapeDrawers(container, force = false) {
665
- return getItemMapFromInitializer(container, this.shapeDrawers, this.initializers.shapes, force);
666
- }
667
- async getUpdaters(container, force = false) {
668
- return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
669
- }
670
825
  async init() {
671
826
  if (this.#initialized || this.#isRunningLoaders) {
672
827
  return;
@@ -685,16 +840,9 @@
685
840
  this.#initialized = true;
686
841
  }
687
842
  }
688
- loadParticlesOptions(container, options, ...sourceOptions) {
689
- const updaters = this.updaters.get(container);
690
- if (!updaters) {
691
- return;
692
- }
693
- updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
694
- }
695
843
  async register(...loaders) {
696
844
  if (this.#initialized) {
697
- throw new Error("Register plugins can only be done before calling tsParticles.load()");
845
+ throw new Error(getErrorMessage(ErrorCodes$1.pluginRegisterAfterLoad));
698
846
  }
699
847
  for (const loader of loaders) {
700
848
  if (this.#isRunningLoaders) {
@@ -706,88 +854,15 @@
706
854
  }
707
855
  }
708
856
  async #runLoader(loader, executed, allLoaders) {
709
- if (executed.has(loader))
857
+ if (executed.has(loader)) {
710
858
  return;
859
+ }
711
860
  executed.add(loader);
712
861
  allLoaders.add(loader);
713
862
  await loader(this.#engine);
714
863
  }
715
864
  }
716
865
 
717
- const errorPrefix = "tsParticles - Error";
718
- const wrap = (fn) => (...args) => {
719
- fn(...args);
720
- }, _logger = {
721
- debug: wrap(console.debug),
722
- error: (message, ...optionalParams) => {
723
- console.error(`${errorPrefix} - ${message}`, ...optionalParams);
724
- },
725
- info: wrap(console.info),
726
- log: wrap(console.log),
727
- trace: wrap(console.trace),
728
- verbose: wrap(console.log),
729
- warning: wrap(console.warn),
730
- };
731
- function getLogger() {
732
- return _logger;
733
- }
734
-
735
- const fullPercent = "100%";
736
- async function getDataFromUrl(data) {
737
- const url = itemFromSingleOrMultiple(data.url, data.index);
738
- if (!url) {
739
- return data.fallback;
740
- }
741
- const response = await fetch(url);
742
- if (response.ok) {
743
- return (await response.json());
744
- }
745
- getLogger().error(`${response.status.toString()} while retrieving config file`);
746
- return data.fallback;
747
- }
748
- const getCanvasFromContainer = (domContainer) => {
749
- const documentSafe = safeDocument();
750
- let canvasEl;
751
- const isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
752
- if (isCanvas) {
753
- canvasEl = domContainer;
754
- canvasEl.dataset[generatedAttribute] ??= generatedFalse;
755
- if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
756
- canvasEl.style.width ||= fullPercent;
757
- canvasEl.style.height ||= fullPercent;
758
- canvasEl.style.pointerEvents = "none";
759
- canvasEl.style.setProperty("pointer-events", "none");
760
- }
761
- }
762
- else {
763
- const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
764
- if (foundCanvas) {
765
- canvasEl = foundCanvas;
766
- canvasEl.dataset[generatedAttribute] = generatedFalse;
767
- }
768
- else {
769
- canvasEl = documentSafe.createElement(canvasTag);
770
- canvasEl.dataset[generatedAttribute] = generatedTrue;
771
- domContainer.appendChild(canvasEl);
772
- }
773
- canvasEl.style.width ||= fullPercent;
774
- canvasEl.style.height ||= fullPercent;
775
- canvasEl.style.pointerEvents = "none";
776
- canvasEl.style.setProperty("pointer-events", "none");
777
- }
778
- return canvasEl;
779
- }, getDomContainer = (id, source) => {
780
- const documentSafe = safeDocument();
781
- let domContainer = source ?? documentSafe.getElementById(id);
782
- if (domContainer) {
783
- return domContainer;
784
- }
785
- domContainer = documentSafe.createElement("canvas");
786
- domContainer.id = id;
787
- domContainer.dataset[generatedAttribute] = generatedTrue;
788
- documentSafe.body.append(domContainer);
789
- return domContainer;
790
- };
791
866
  class Engine {
792
867
  pluginManager = new PluginManager(this);
793
868
  #domArray = [];
@@ -797,7 +872,7 @@
797
872
  return this.#domArray;
798
873
  }
799
874
  get version() {
800
- return "4.4.0";
875
+ return "4.5.0";
801
876
  }
802
877
  addEventListener(type, listener) {
803
878
  this.#eventDispatcher.addEventListener(type, listener);
@@ -806,7 +881,7 @@
806
881
  if (this.version === pluginVersion) {
807
882
  return;
808
883
  }
809
- throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
884
+ throw new Error(getErrorMessage(ErrorCodes$1.engineVersionMismatch, this.version, pluginVersion));
810
885
  }
811
886
  dispatchEvent(type, args) {
812
887
  this.#eventDispatcher.dispatchEvent(type, args);
@@ -1055,20 +1130,6 @@
1055
1130
  DrawLayer[DrawLayer["Foreground"] = 7] = "Foreground";
1056
1131
  })(DrawLayer || (DrawLayer = {}));
1057
1132
 
1058
- class OptionLoader {
1059
- load(data) {
1060
- if (isNull(data)) {
1061
- return;
1062
- }
1063
- this.doLoad(data);
1064
- }
1065
- }
1066
- function loadOptions(options, ...sourceOptionsArr) {
1067
- for (const sourceOptions of sourceOptionsArr) {
1068
- options.load(sourceOptions);
1069
- }
1070
- }
1071
-
1072
1133
  function loadProperty(obj, key, value) {
1073
1134
  if (value !== undefined) {
1074
1135
  obj[key] = value;
@@ -1100,6 +1161,20 @@
1100
1161
  }
1101
1162
  }
1102
1163
 
1164
+ class OptionLoader {
1165
+ load(data) {
1166
+ if (isNull(data)) {
1167
+ return;
1168
+ }
1169
+ this.doLoad(data);
1170
+ }
1171
+ }
1172
+ function loadOptions(options, ...sourceOptionsArr) {
1173
+ for (const sourceOptions of sourceOptionsArr) {
1174
+ options.load(sourceOptions);
1175
+ }
1176
+ }
1177
+
1103
1178
  class AnimationOptions extends OptionLoader {
1104
1179
  count = 0;
1105
1180
  decay = 0;
@@ -1250,15 +1325,14 @@
1250
1325
  peakNits = defaultPeakNits;
1251
1326
  doLoad(data) {
1252
1327
  if (data.enable !== undefined && !isBoolean(data.enable)) {
1253
- throw new Error(`Invalid HDR "enable" value: expected a boolean, got "${String(data.enable)}"`);
1328
+ throw new Error(getErrorMessage(ErrorCodes$1.hdrEnableInvalid, String(data.enable)));
1254
1329
  }
1255
- if (data.mode !== undefined &&
1256
- (typeof data.mode !== "string" || !Object.values(HdrMode).includes(data.mode))) {
1257
- throw new Error(`Invalid HDR "mode" value: expected one of ${Object.values(HdrMode).join(", ")}, got "${toStringValue(data.mode)}"`);
1330
+ if (data.mode !== undefined && !isEnumValue(HdrMode, data.mode)) {
1331
+ throw new Error(getErrorMessage(ErrorCodes$1.hdrModeInvalid, Object.values(HdrMode).join(", "), toStringValue(data.mode)));
1258
1332
  }
1259
1333
  if (data.peakNits !== undefined &&
1260
1334
  (!isNumber(data.peakNits) || !Number.isFinite(data.peakNits) || data.peakNits <= minPeakNits)) {
1261
- throw new Error(`Invalid HDR "peakNits" value: expected a positive number, got "${String(data.peakNits)}"`);
1335
+ throw new Error(getErrorMessage(ErrorCodes$1.hdrPeakNitsInvalid, String(data.peakNits)));
1262
1336
  }
1263
1337
  loadProperty(this, "enable", data.enable);
1264
1338
  loadProperty(this, "mode", data.mode);
@@ -1636,12 +1710,10 @@
1636
1710
  plugin.loadParticlesOptions(this.#container, this, data);
1637
1711
  }
1638
1712
  }
1639
- const updaters = this.#pluginManager.updaters.get(this.#container);
1640
- if (updaters) {
1641
- for (const updater of updaters) {
1642
- if (updater.loadOptions) {
1643
- updater.loadOptions(this, data);
1644
- }
1713
+ const updaters = this.#container.particleUpdaters;
1714
+ for (const updater of updaters) {
1715
+ if (updater.loadOptions) {
1716
+ updater.loadOptions(this, data);
1645
1717
  }
1646
1718
  }
1647
1719
  }
@@ -1974,9 +2046,9 @@
1974
2046
  const grayscaleValue = Math.round(lNormalized * rgbMax);
1975
2047
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
1976
2048
  }
1977
- const temp1 = lNormalized < half
2049
+ const temp2 = lNormalized < half
1978
2050
  ? lNormalized * (sNormalizedOffset + sNormalized)
1979
- : 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));
2051
+ : 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));
1980
2052
  return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
1981
2053
  }
1982
2054
  function hslToRgbFloat(hsl) {
@@ -1985,9 +2057,9 @@
1985
2057
  const grayscaleValue = lNormalized * rgbMax;
1986
2058
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
1987
2059
  }
1988
- const temp1 = lNormalized < half
2060
+ const temp2 = lNormalized < half
1989
2061
  ? lNormalized * (sNormalizedOffset + sNormalized)
1990
- : 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));
2062
+ : 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));
1991
2063
  return { r: red, g: green, b: blue };
1992
2064
  }
1993
2065
  function hslaToRgba(hsla) {
@@ -2201,7 +2273,7 @@
2201
2273
  }
2202
2274
 
2203
2275
  async function loadBlendPlugin(engine) {
2204
- engine.checkVersion("4.4.0");
2276
+ engine.checkVersion("4.5.0");
2205
2277
  await engine.pluginManager.register(e => {
2206
2278
  e.pluginManager.addPlugin(new BlendPlugin());
2207
2279
  });
@@ -2238,7 +2310,7 @@
2238
2310
  }
2239
2311
 
2240
2312
  async function loadCircleShape(engine) {
2241
- engine.checkVersion("4.4.0");
2313
+ engine.checkVersion("4.5.0");
2242
2314
  await engine.pluginManager.register(e => {
2243
2315
  e.pluginManager.addShape(["circle"], () => {
2244
2316
  return Promise.resolve(new CircleDrawer());
@@ -2253,7 +2325,7 @@
2253
2325
  RgbIndexes[RgbIndexes["b"] = 3] = "b";
2254
2326
  RgbIndexes[RgbIndexes["a"] = 4] = "a";
2255
2327
  })(RgbIndexes$1 || (RgbIndexes$1 = {}));
2256
- 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;
2328
+ 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;
2257
2329
  class HexColorManager {
2258
2330
  accepts(input) {
2259
2331
  return input.startsWith("#");
@@ -2286,7 +2358,7 @@
2286
2358
  }
2287
2359
 
2288
2360
  async function loadHexColorPlugin(engine) {
2289
- engine.checkVersion("4.4.0");
2361
+ engine.checkVersion("4.5.0");
2290
2362
  await engine.pluginManager.register(e => {
2291
2363
  e.pluginManager.addColorManager("hex", new HexColorManager());
2292
2364
  });
@@ -2326,7 +2398,7 @@
2326
2398
  if (!this.accepts(input)) {
2327
2399
  return;
2328
2400
  }
2329
- const result = hslRegex.exec(input), minLength = 4, defaultAlpha = 1, radix = 10;
2401
+ const result = hslRegex.exec(input), minLength = 4, radix = 10;
2330
2402
  return result
2331
2403
  ? hslaToRgba({
2332
2404
  a: result.length > minLength ? parseAlpha(result[HslIndexes.a]) : defaultAlpha,
@@ -2339,12 +2411,20 @@
2339
2411
  }
2340
2412
 
2341
2413
  async function loadHslColorPlugin(engine) {
2342
- engine.checkVersion("4.4.0");
2414
+ engine.checkVersion("4.5.0");
2343
2415
  await engine.pluginManager.register(e => {
2344
2416
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2345
2417
  });
2346
2418
  }
2347
2419
 
2420
+ const ErrorCodes = {
2421
+ baseMoverNotLoaded: "TSP-3203",
2422
+ };
2423
+
2424
+ const ErrorMessages = {
2425
+ [ErrorCodes.baseMoverNotLoaded]: "tsParticles Base Mover is not loaded",
2426
+ };
2427
+
2348
2428
  class MovePlugin {
2349
2429
  id = "move";
2350
2430
  #pluginManager;
@@ -2363,20 +2443,20 @@
2363
2443
  }
2364
2444
 
2365
2445
  async function loadMovePlugin(engine) {
2366
- engine.checkVersion("4.4.0");
2446
+ engine.checkVersion("4.5.0");
2447
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
2448
+ addErrorMessages(ErrorMessages);
2449
+ }
2367
2450
  await engine.pluginManager.register(e => {
2368
2451
  const moveEngine = e, movePluginManager = moveEngine.pluginManager;
2369
2452
  movePluginManager.initializers.pathGenerators ??= new Map();
2370
- movePluginManager.pathGenerators ??= new Map();
2371
2453
  movePluginManager.addPathGenerator = (name, generator) => {
2454
+ if (movePluginManager.initialized) {
2455
+ return;
2456
+ }
2372
2457
  movePluginManager.initializers.pathGenerators ??= new Map();
2373
2458
  movePluginManager.initializers.pathGenerators.set(name, generator);
2374
2459
  };
2375
- movePluginManager.getPathGenerators = async (container, force = false) => {
2376
- movePluginManager.initializers.pathGenerators ??= new Map();
2377
- movePluginManager.pathGenerators ??= new Map();
2378
- return getItemMapFromInitializer(container, movePluginManager.pathGenerators, movePluginManager.initializers.pathGenerators, force);
2379
- };
2380
2460
  e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
2381
2461
  });
2382
2462
  }
@@ -2573,7 +2653,7 @@
2573
2653
  }
2574
2654
 
2575
2655
  async function loadOpacityUpdater(engine) {
2576
- engine.checkVersion("4.4.0");
2656
+ engine.checkVersion("4.5.0");
2577
2657
  await engine.pluginManager.register(e => {
2578
2658
  e.pluginManager.addParticleUpdater("opacity", container => {
2579
2659
  return Promise.resolve(new OpacityUpdater(container));
@@ -2582,70 +2662,60 @@
2582
2662
  }
2583
2663
 
2584
2664
  const boundsMin = 0;
2585
- function bounceHorizontal(data) {
2586
- if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
2587
- (data.direction !== OutModeDirection.left && data.direction !== OutModeDirection.right)) {
2665
+ const bounceAxisConfigs = {
2666
+ [OutModeDirection.left]: {
2667
+ axis: "x",
2668
+ canvas: "width",
2669
+ bounce: "horizontal",
2670
+ negativeEdge: "right",
2671
+ positiveEdge: "left",
2672
+ negative: true,
2673
+ },
2674
+ [OutModeDirection.right]: {
2675
+ axis: "x",
2676
+ canvas: "width",
2677
+ bounce: "horizontal",
2678
+ negativeEdge: "right",
2679
+ positiveEdge: "left",
2680
+ negative: false,
2681
+ },
2682
+ [OutModeDirection.top]: {
2683
+ axis: "y",
2684
+ canvas: "height",
2685
+ bounce: "vertical",
2686
+ negativeEdge: "bottom",
2687
+ positiveEdge: "top",
2688
+ negative: true,
2689
+ },
2690
+ [OutModeDirection.bottom]: {
2691
+ axis: "y",
2692
+ canvas: "height",
2693
+ bounce: "vertical",
2694
+ negativeEdge: "bottom",
2695
+ positiveEdge: "top",
2696
+ negative: false,
2697
+ },
2698
+ };
2699
+ function bounce(data) {
2700
+ if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) || !(data.direction in bounceAxisConfigs)) {
2588
2701
  return;
2589
2702
  }
2590
- if (data.bounds.right < boundsMin && data.direction === OutModeDirection.left) {
2591
- data.particle.position.x = data.size + data.offset.x;
2703
+ const config = bounceAxisConfigs[data.direction], bounds = data.bounds, canvasDim = data.canvasSize[config.canvas], position = data.particle.position, velocity = data.particle.velocity[config.axis];
2704
+ if (config.negative && bounds[config.negativeEdge] < boundsMin) {
2705
+ position[config.axis] = data.size + data.offset[config.axis];
2592
2706
  }
2593
- else if (data.bounds.left > data.canvasSize.width && data.direction === OutModeDirection.right) {
2594
- data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
2707
+ else if (!config.negative && bounds[config.positiveEdge] > canvasDim) {
2708
+ position[config.axis] = canvasDim - data.size - data.offset[config.axis];
2595
2709
  }
2596
- const velocity = data.particle.velocity.x;
2597
- let bounced = false;
2598
2710
  if (data.outOfCanvas &&
2599
- ((data.direction === OutModeDirection.right && velocity > minVelocity) ||
2600
- (data.direction === OutModeDirection.left && velocity < minVelocity))) {
2601
- const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
2602
- data.particle.velocity.x *= -newVelocity;
2603
- bounced = true;
2711
+ ((config.negative && velocity < minVelocity) || (!config.negative && velocity > minVelocity))) {
2712
+ data.particle.velocity[config.axis] *= -getRangeValue(data.particle.options.bounce[config.bounce].value);
2604
2713
  }
2605
- if (!bounced) {
2714
+ else {
2606
2715
  return;
2607
2716
  }
2608
- const minPos = data.offset.x + data.size;
2609
- if (data.outOfCanvas && data.direction === OutModeDirection.right) {
2610
- data.particle.position.x = data.canvasSize.width - minPos;
2611
- }
2612
- else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
2613
- data.particle.position.x = minPos;
2614
- }
2615
- if (data.outMode === OutMode.split) {
2616
- data.particle.destroy();
2617
- }
2618
- }
2619
- function bounceVertical(data) {
2620
- if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
2621
- (data.direction !== OutModeDirection.bottom && data.direction !== OutModeDirection.top)) {
2622
- return;
2623
- }
2624
- if (data.bounds.bottom < boundsMin && data.direction === OutModeDirection.top) {
2625
- data.particle.position.y = data.size + data.offset.y;
2626
- }
2627
- else if (data.bounds.top > data.canvasSize.height && data.direction === OutModeDirection.bottom) {
2628
- data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
2629
- }
2630
- const velocity = data.particle.velocity.y;
2631
- let bounced = false;
2632
- if (data.outOfCanvas &&
2633
- ((data.direction === OutModeDirection.bottom && velocity > minVelocity) ||
2634
- (data.direction === OutModeDirection.top && velocity < minVelocity))) {
2635
- const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
2636
- data.particle.velocity.y *= -newVelocity;
2637
- bounced = true;
2638
- }
2639
- if (!bounced) {
2640
- return;
2641
- }
2642
- const minPos = data.offset.y + data.size;
2643
- if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
2644
- data.particle.position.y = data.canvasSize.height - minPos;
2645
- }
2646
- else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
2647
- data.particle.position.y = minPos;
2648
- }
2717
+ const minPos = data.offset[config.axis] + data.size;
2718
+ position[config.axis] = config.negative ? minPos : canvasDim - minPos;
2649
2719
  if (data.outMode === OutMode.split) {
2650
2720
  data.particle.destroy();
2651
2721
  }
@@ -2661,26 +2731,19 @@
2661
2731
  OutMode.bounce,
2662
2732
  OutMode.split,
2663
2733
  ];
2664
- this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
2734
+ this.#particleBouncePlugins = container.plugins.filter(p => !!p.particleBounce);
2665
2735
  }
2666
2736
  update(particle, direction, delta, outMode) {
2667
2737
  if (!this.modes.includes(outMode)) {
2668
2738
  return;
2669
2739
  }
2670
- const container = this.#container;
2671
- let handled = false;
2672
2740
  for (const plugin of this.#particleBouncePlugins) {
2673
- handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
2674
- if (handled) {
2675
- break;
2741
+ if (plugin.particleBounce?.(particle, delta, direction)) {
2742
+ return;
2676
2743
  }
2677
2744
  }
2678
- if (handled) {
2679
- return;
2680
- }
2681
- const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
2682
- bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2683
- bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2745
+ const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = this.#container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
2746
+ bounce({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
2684
2747
  }
2685
2748
  }
2686
2749
 
@@ -2769,107 +2832,108 @@
2769
2832
  return;
2770
2833
  }
2771
2834
  const container = this.#container;
2772
- switch (particle.outType) {
2773
- case ParticleOutType.inside: {
2774
- const { x: vx, y: vy } = particle.velocity;
2775
- updateVector.setTo(originPoint);
2776
- updateVector.length = particle.moveCenter.radius;
2777
- updateVector.angle = particle.velocity.angle + Math.PI;
2778
- updateVector.addTo(particle.moveCenter);
2779
- const { dx, dy } = getDistances(particle.position, updateVector);
2780
- if ((vx <= minVelocity && dx >= minDistance) ||
2781
- (vy <= minVelocity && dy >= minDistance) ||
2782
- (vx >= minVelocity && dx <= minDistance) ||
2783
- (vy >= minVelocity && dy <= minDistance)) {
2784
- return;
2785
- }
2786
- particle.position.x = Math.floor(randomInRangeValue({
2787
- min: 0,
2788
- max: container.canvas.size.width,
2789
- }));
2790
- particle.position.y = Math.floor(randomInRangeValue({
2791
- min: 0,
2792
- max: container.canvas.size.height,
2793
- }));
2794
- const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
2795
- particle.direction = Math.atan2(-newDy, -newDx);
2796
- particle.velocity.angle = particle.direction;
2797
- particle.justWarped = true;
2798
- break;
2835
+ if (particle.outType === ParticleOutType.inside) {
2836
+ this.#applyOutModeInside(particle, container);
2837
+ }
2838
+ else {
2839
+ if (particle.isInsideCanvasForOutMode(outMode, direction)) {
2840
+ return;
2799
2841
  }
2800
- default: {
2801
- if (particle.isInsideCanvasForOutMode(outMode, direction)) {
2802
- return;
2803
- }
2804
- switch (particle.outType) {
2805
- case ParticleOutType.outside: {
2806
- particle.position.x =
2807
- Math.floor(randomInRangeValue({
2808
- min: -particle.moveCenter.radius,
2809
- max: particle.moveCenter.radius,
2810
- })) + particle.moveCenter.x;
2811
- particle.position.y =
2812
- Math.floor(randomInRangeValue({
2813
- min: -particle.moveCenter.radius,
2814
- max: particle.moveCenter.radius,
2815
- })) + particle.moveCenter.y;
2816
- const { dx, dy } = getDistances(particle.position, particle.moveCenter);
2817
- if (particle.moveCenter.radius) {
2818
- particle.direction = Math.atan2(dy, dx);
2819
- particle.velocity.angle = particle.direction;
2820
- }
2821
- particle.justWarped = true;
2822
- break;
2823
- }
2824
- case ParticleOutType.normal: {
2825
- const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
2826
- bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
2827
- left: -particle.getRadius() - particle.offset.x,
2828
- right: canvasSize.width + particle.getRadius() + particle.offset.x,
2829
- top: -particle.getRadius() - particle.offset.y,
2830
- }, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
2831
- if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
2832
- particle.position.x = newPos.left;
2833
- particle.initialPosition.x = particle.position.x;
2834
- if (!warp) {
2835
- particle.position.y = getRandom() * canvasSize.height;
2836
- particle.initialPosition.y = particle.position.y;
2837
- }
2838
- particle.justWarped = true;
2839
- }
2840
- else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
2841
- particle.position.x = newPos.right;
2842
- particle.initialPosition.x = particle.position.x;
2843
- if (!warp) {
2844
- particle.position.y = getRandom() * canvasSize.height;
2845
- particle.initialPosition.y = particle.position.y;
2846
- }
2847
- particle.justWarped = true;
2848
- }
2849
- if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
2850
- if (!warp) {
2851
- particle.position.x = getRandom() * canvasSize.width;
2852
- particle.initialPosition.x = particle.position.x;
2853
- }
2854
- particle.position.y = newPos.top;
2855
- particle.initialPosition.y = particle.position.y;
2856
- particle.justWarped = true;
2857
- }
2858
- else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
2859
- if (!warp) {
2860
- particle.position.x = getRandom() * canvasSize.width;
2861
- particle.initialPosition.x = particle.position.x;
2862
- }
2863
- particle.position.y = newPos.bottom;
2864
- particle.initialPosition.y = particle.position.y;
2865
- particle.justWarped = true;
2866
- }
2867
- break;
2868
- }
2869
- }
2870
- break;
2842
+ if (particle.outType === ParticleOutType.outside) {
2843
+ this.#applyParticleModeOutside(particle);
2871
2844
  }
2845
+ else {
2846
+ this.#applyOutModeNormal(particle, container, direction);
2847
+ }
2848
+ }
2849
+ }
2850
+ #applyOutModeInside(particle, container) {
2851
+ const { x: vx, y: vy } = particle.velocity;
2852
+ updateVector.setTo(originPoint);
2853
+ updateVector.length = particle.moveCenter.radius;
2854
+ updateVector.angle = particle.velocity.angle + Math.PI;
2855
+ updateVector.addTo(particle.moveCenter);
2856
+ const { dx, dy } = getDistances(particle.position, updateVector);
2857
+ if ((vx <= minVelocity && dx >= minDistance) ||
2858
+ (vy <= minVelocity && dy >= minDistance) ||
2859
+ (vx >= minVelocity && dx <= minDistance) ||
2860
+ (vy >= minVelocity && dy <= minDistance)) {
2861
+ return;
2872
2862
  }
2863
+ particle.position.x = Math.floor(randomInRangeValue({
2864
+ min: 0,
2865
+ max: container.canvas.size.width,
2866
+ }));
2867
+ particle.position.y = Math.floor(randomInRangeValue({
2868
+ min: 0,
2869
+ max: container.canvas.size.height,
2870
+ }));
2871
+ const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
2872
+ particle.direction = Math.atan2(-newDy, -newDx);
2873
+ particle.velocity.angle = particle.direction;
2874
+ particle.justWarped = true;
2875
+ }
2876
+ #applyOutModeNormal(particle, container, direction) {
2877
+ const warp = particle.options.move.warp, canvasSize = container.canvas.size, sizeValue = particle.getRadius(), newPos = {
2878
+ bottom: canvasSize.height + sizeValue + particle.offset.y,
2879
+ left: -sizeValue - particle.offset.x,
2880
+ right: canvasSize.width + sizeValue + particle.offset.x,
2881
+ top: -sizeValue - particle.offset.y,
2882
+ }, nextBounds = calculateBounds(particle.position, sizeValue);
2883
+ if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
2884
+ particle.position.x = newPos.left;
2885
+ particle.initialPosition.x = particle.position.x;
2886
+ if (!warp) {
2887
+ particle.position.y = getRandom() * canvasSize.height;
2888
+ particle.initialPosition.y = particle.position.y;
2889
+ }
2890
+ particle.justWarped = true;
2891
+ }
2892
+ else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
2893
+ particle.position.x = newPos.right;
2894
+ particle.initialPosition.x = particle.position.x;
2895
+ if (!warp) {
2896
+ particle.position.y = getRandom() * canvasSize.height;
2897
+ particle.initialPosition.y = particle.position.y;
2898
+ }
2899
+ particle.justWarped = true;
2900
+ }
2901
+ if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
2902
+ if (!warp) {
2903
+ particle.position.x = getRandom() * canvasSize.width;
2904
+ particle.initialPosition.x = particle.position.x;
2905
+ }
2906
+ particle.position.y = newPos.top;
2907
+ particle.initialPosition.y = particle.position.y;
2908
+ particle.justWarped = true;
2909
+ }
2910
+ else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
2911
+ if (!warp) {
2912
+ particle.position.x = getRandom() * canvasSize.width;
2913
+ particle.initialPosition.x = particle.position.x;
2914
+ }
2915
+ particle.position.y = newPos.bottom;
2916
+ particle.initialPosition.y = particle.position.y;
2917
+ particle.justWarped = true;
2918
+ }
2919
+ }
2920
+ #applyParticleModeOutside(particle) {
2921
+ particle.position.x =
2922
+ Math.floor(randomInRangeValue({
2923
+ min: -particle.moveCenter.radius,
2924
+ max: particle.moveCenter.radius,
2925
+ })) + particle.moveCenter.x;
2926
+ particle.position.y =
2927
+ Math.floor(randomInRangeValue({
2928
+ min: -particle.moveCenter.radius,
2929
+ max: particle.moveCenter.radius,
2930
+ })) + particle.moveCenter.y;
2931
+ const { dx, dy } = getDistances(particle.position, particle.moveCenter);
2932
+ if (particle.moveCenter.radius) {
2933
+ particle.direction = Math.atan2(dy, dx);
2934
+ particle.velocity.angle = particle.direction;
2935
+ }
2936
+ particle.justWarped = true;
2873
2937
  }
2874
2938
  }
2875
2939
 
@@ -2918,56 +2982,26 @@
2918
2982
  }
2919
2983
 
2920
2984
  async function loadOutModesUpdater(engine) {
2921
- engine.checkVersion("4.4.0");
2985
+ engine.checkVersion("4.5.0");
2922
2986
  await engine.pluginManager.register(e => {
2923
2987
  e.pluginManager.addParticleUpdater("outModes", container => {
2924
2988
  return Promise.resolve(new OutOfCanvasUpdater(container));
2925
2989
  });
2926
- });
2927
- }
2928
-
2929
- const defaultOpacity = 1;
2930
- class PaintUpdater {
2931
- #container;
2932
- #pluginManager;
2933
- constructor(pluginManager, container) {
2934
- this.#container = container;
2935
- this.#pluginManager = pluginManager;
2936
- }
2937
- init(particle) {
2938
- 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;
2939
- if (fill) {
2940
- const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
2941
- particle.fillEnabled = fill.enable;
2942
- particle.fillOpacity = getRangeValue(fill.opacity);
2943
- particle.fillAnimation = fillColor.animation;
2944
- const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
2945
- if (fillHslColor) {
2946
- particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
2947
- }
2948
- }
2949
- else {
2950
- particle.fillEnabled = false;
2951
- particle.fillAnimation = undefined;
2952
- particle.fillColor = undefined;
2953
- particle.fillOpacity = defaultOpacity;
2954
- }
2955
- if (stroke) {
2956
- const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
2957
- particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
2958
- particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
2959
- particle.strokeAnimation = strokeColor.animation;
2960
- const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
2961
- if (strokeHslColor) {
2962
- particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
2963
- }
2964
- }
2965
- else {
2966
- particle.strokeAnimation = undefined;
2967
- particle.strokeColor = undefined;
2968
- particle.strokeOpacity = defaultOpacity;
2969
- particle.strokeWidth = 0;
2970
- }
2990
+ });
2991
+ }
2992
+
2993
+ const defaultOpacity = 1;
2994
+ class PaintUpdater {
2995
+ #container;
2996
+ #pluginManager;
2997
+ constructor(pluginManager, container) {
2998
+ this.#container = container;
2999
+ this.#pluginManager = pluginManager;
3000
+ }
3001
+ init(particle) {
3002
+ const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates);
3003
+ this.#initFill(paint, particle, container);
3004
+ this.#initStroke(paint, particle, container);
2971
3005
  }
2972
3006
  isEnabled(particle) {
2973
3007
  const { fillAnimation, fillColor, strokeAnimation, strokeColor } = particle, fillEnabled = !!fillAnimation &&
@@ -2986,10 +3020,48 @@
2986
3020
  updateColor(particle.fillColor, delta, this.#container.hdr);
2987
3021
  updateColor(particle.strokeColor, delta, this.#container.hdr);
2988
3022
  }
3023
+ #initFill(paint, particle, container) {
3024
+ const fill = paint?.fill, color = paint?.color, paintColor = color ?? undefined;
3025
+ if (!fill) {
3026
+ particle.fillEnabled = false;
3027
+ particle.fillAnimation = undefined;
3028
+ particle.fillColor = undefined;
3029
+ particle.fillOpacity = defaultOpacity;
3030
+ return;
3031
+ }
3032
+ const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
3033
+ particle.fillEnabled = fill.enable;
3034
+ particle.fillOpacity = getRangeValue(fill.opacity);
3035
+ particle.fillAnimation = fillColor.animation;
3036
+ const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
3037
+ if (!fillHslColor) {
3038
+ return;
3039
+ }
3040
+ particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
3041
+ }
3042
+ #initStroke(paint, particle, container) {
3043
+ const stroke = paint?.stroke, color = paint?.color, paintColor = color ?? undefined;
3044
+ if (!stroke) {
3045
+ particle.strokeAnimation = undefined;
3046
+ particle.strokeColor = undefined;
3047
+ particle.strokeOpacity = defaultOpacity;
3048
+ particle.strokeWidth = 0;
3049
+ return;
3050
+ }
3051
+ const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
3052
+ particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
3053
+ particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
3054
+ particle.strokeAnimation = strokeColor.animation;
3055
+ const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
3056
+ if (!strokeHslColor) {
3057
+ return;
3058
+ }
3059
+ particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
3060
+ }
2989
3061
  }
2990
3062
 
2991
3063
  async function loadPaintUpdater(engine) {
2992
- engine.checkVersion("4.4.0");
3064
+ engine.checkVersion("4.5.0");
2993
3065
  await engine.pluginManager.register(e => {
2994
3066
  e.pluginManager.addParticleUpdater("paint", container => {
2995
3067
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3031,7 +3103,7 @@
3031
3103
  if (!this.accepts(input)) {
3032
3104
  return;
3033
3105
  }
3034
- const result = rgbRegex.exec(input), radix = 10, minLength = 4, defaultAlpha = 1;
3106
+ const result = rgbRegex.exec(input), radix = 10, minLength = 4;
3035
3107
  return result
3036
3108
  ? {
3037
3109
  a: result.length > minLength ? parseAlpha(result[RgbIndexes.a]) : defaultAlpha,
@@ -3044,7 +3116,7 @@
3044
3116
  }
3045
3117
 
3046
3118
  async function loadRgbColorPlugin(engine) {
3047
- engine.checkVersion("4.4.0");
3119
+ engine.checkVersion("4.5.0");
3048
3120
  await engine.pluginManager.register(e => {
3049
3121
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3050
3122
  });
@@ -3129,7 +3201,7 @@
3129
3201
  }
3130
3202
 
3131
3203
  async function loadSizeUpdater(engine) {
3132
- engine.checkVersion("4.4.0");
3204
+ engine.checkVersion("4.5.0");
3133
3205
  await engine.pluginManager.register(e => {
3134
3206
  e.pluginManager.addParticleUpdater("size", container => {
3135
3207
  return Promise.resolve(new SizeUpdater(container));
@@ -3138,7 +3210,7 @@
3138
3210
  }
3139
3211
 
3140
3212
  async function loadBasic(engine) {
3141
- engine.checkVersion("4.4.0");
3213
+ engine.checkVersion("4.5.0");
3142
3214
  await engine.pluginManager.register(async (e) => {
3143
3215
  await Promise.all([
3144
3216
  loadBlendPlugin(e),
@@ -3269,21 +3341,28 @@
3269
3341
  });
3270
3342
  }
3271
3343
  clear() {
3344
+ const visited = new Set();
3272
3345
  for (const plugin of this.#canvasClearPlugins) {
3346
+ visited.add(plugin);
3273
3347
  if (plugin.canvasClear?.() ?? false) {
3274
- return;
3348
+ return plugin;
3275
3349
  }
3276
3350
  }
3277
3351
  for (const layer of Object.values(DrawLayer)) {
3278
3352
  if (typeof layer === "number") {
3279
3353
  for (const plugin of this.#getLayerPlugins(layer)) {
3354
+ if (visited.has(plugin)) {
3355
+ continue;
3356
+ }
3357
+ visited.add(plugin);
3280
3358
  if (plugin.canvasClear?.() ?? false) {
3281
- return;
3359
+ return plugin;
3282
3360
  }
3283
3361
  }
3284
3362
  }
3285
3363
  }
3286
3364
  this.canvasClear();
3365
+ return undefined;
3287
3366
  }
3288
3367
  destroy() {
3289
3368
  this.stop();
@@ -3361,8 +3440,7 @@
3361
3440
  });
3362
3441
  }
3363
3442
  drawParticles(delta) {
3364
- const { particles, actualOptions } = this.#container;
3365
- this.clear();
3443
+ const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
3366
3444
  particles.update(delta);
3367
3445
  this.draw(ctx => {
3368
3446
  const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
@@ -3384,7 +3462,9 @@
3384
3462
  }
3385
3463
  }
3386
3464
  for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
3387
- plugin.canvasPaint?.();
3465
+ if (plugin !== clearedPlugin) {
3466
+ plugin.canvasPaint?.();
3467
+ }
3388
3468
  }
3389
3469
  for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
3390
3470
  plugin.drawSettingsSetup?.(ctx, delta);
@@ -3416,35 +3496,7 @@
3416
3496
  this.#layers[layer] = [];
3417
3497
  }
3418
3498
  }
3419
- for (const plugin of this.#container.plugins) {
3420
- if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
3421
- this.#colorPlugins.push(plugin);
3422
- }
3423
- if (plugin.drawParticle) {
3424
- this.#drawParticlePlugins.push(plugin);
3425
- }
3426
- if (plugin.drawParticleSetup) {
3427
- this.#drawParticlesSetupPlugins.push(plugin);
3428
- }
3429
- if (plugin.drawParticleCleanup) {
3430
- this.#drawParticlesCleanupPlugins.push(plugin);
3431
- }
3432
- if (plugin.canvasClear) {
3433
- this.#canvasClearPlugins.push(plugin);
3434
- }
3435
- if (plugin.canvasPaint) {
3436
- this.#getLayerPlugins(DrawLayer.BackgroundMask).push(plugin);
3437
- }
3438
- if (plugin.drawSettingsSetup) {
3439
- this.#getLayerPlugins(DrawLayer.CanvasSetup).push(plugin);
3440
- }
3441
- if (plugin.draw) {
3442
- this.#getLayerPlugins(DrawLayer.PluginContent).push(plugin);
3443
- }
3444
- if (plugin.clearDraw ?? plugin.drawSettingsCleanup) {
3445
- this.#getLayerPlugins(DrawLayer.CanvasCleanup).push(plugin);
3446
- }
3447
- }
3499
+ this.#initPluginsArray();
3448
3500
  }
3449
3501
  initUpdaters() {
3450
3502
  this.#preDrawUpdaters = [];
@@ -3653,6 +3705,45 @@
3653
3705
  this.#reusablePluginColors[sColorIndex] = sColor;
3654
3706
  return this.#reusablePluginColors;
3655
3707
  }
3708
+ #initLayerPlugin(plugin) {
3709
+ const layerMap = [
3710
+ [DrawLayer.BackgroundMask, !!plugin.canvasPaint],
3711
+ [DrawLayer.CanvasSetup, !!plugin.drawSettingsSetup],
3712
+ [DrawLayer.PluginContent, !!plugin.draw],
3713
+ [DrawLayer.CanvasCleanup, !!(plugin.clearDraw ?? plugin.drawSettingsCleanup)],
3714
+ ];
3715
+ for (const [layer, active] of layerMap) {
3716
+ if (active) {
3717
+ this.#layers[layer].push(plugin);
3718
+ }
3719
+ }
3720
+ }
3721
+ #initPluginsArray() {
3722
+ for (const plugin of this.#container.plugins) {
3723
+ if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
3724
+ this.#colorPlugins.push(plugin);
3725
+ }
3726
+ if (plugin.drawParticle) {
3727
+ this.#drawParticlePlugins.push(plugin);
3728
+ }
3729
+ if (plugin.drawParticleSetup) {
3730
+ this.#drawParticlesSetupPlugins.push(plugin);
3731
+ }
3732
+ if (plugin.drawParticleCleanup) {
3733
+ this.#drawParticlesCleanupPlugins.push(plugin);
3734
+ }
3735
+ if (plugin.canvasClear) {
3736
+ this.#canvasClearPlugins.push(plugin);
3737
+ }
3738
+ this.#initLayerPlugin(plugin);
3739
+ }
3740
+ }
3741
+ #isSupportedElement(element) {
3742
+ return ((typeof HTMLCanvasElement !== "undefined" && element instanceof HTMLCanvasElement) ||
3743
+ (typeof OffscreenCanvas !== "undefined" && element instanceof OffscreenCanvas) ||
3744
+ (typeof HTMLVideoElement !== "undefined" && element instanceof HTMLVideoElement) ||
3745
+ (typeof HTMLImageElement !== "undefined" && element instanceof HTMLImageElement));
3746
+ }
3656
3747
  #resolveBackgroundElement() {
3657
3748
  const background = this.#container.actualOptions.background;
3658
3749
  this.#backgroundElement = null;
@@ -3662,9 +3753,7 @@
3662
3753
  if (typeof background.element === "string") {
3663
3754
  if (typeof document !== "undefined") {
3664
3755
  const node = document.querySelector(background.element);
3665
- if ((typeof HTMLCanvasElement !== "undefined" && node instanceof HTMLCanvasElement) ||
3666
- (typeof HTMLVideoElement !== "undefined" && node instanceof HTMLVideoElement) ||
3667
- (typeof HTMLImageElement !== "undefined" && node instanceof HTMLImageElement)) {
3756
+ if (node && this.#isSupportedElement(node)) {
3668
3757
  this.#backgroundElement = node;
3669
3758
  }
3670
3759
  else if (node) {
@@ -3675,10 +3764,7 @@
3675
3764
  }
3676
3765
  }
3677
3766
  }
3678
- else if ((typeof HTMLCanvasElement !== "undefined" && background.element instanceof HTMLCanvasElement) ||
3679
- (typeof OffscreenCanvas !== "undefined" && background.element instanceof OffscreenCanvas) ||
3680
- (typeof HTMLVideoElement !== "undefined" && background.element instanceof HTMLVideoElement) ||
3681
- (typeof HTMLImageElement !== "undefined" && background.element instanceof HTMLImageElement)) {
3767
+ else if (this.#isSupportedElement(background.element)) {
3682
3768
  this.#backgroundElement = background.element;
3683
3769
  }
3684
3770
  }
@@ -3696,7 +3782,7 @@
3696
3782
  return transferredCanvas;
3697
3783
  }
3698
3784
  if (typeof canvas.transferControlToOffscreen !== "function") {
3699
- throw new TypeError("OffscreenCanvas is required but not supported by this browser");
3785
+ throw new TypeError(getErrorMessage(ErrorCodes$1.offscreenCanvasUnsupported));
3700
3786
  }
3701
3787
  try {
3702
3788
  const offscreenCanvas = canvas.transferControlToOffscreen();
@@ -3704,10 +3790,16 @@
3704
3790
  return offscreenCanvas;
3705
3791
  }
3706
3792
  catch {
3707
- throw new TypeError("OffscreenCanvas transfer failed");
3793
+ throw new TypeError(getErrorMessage(ErrorCodes$1.offscreenCanvasTransferFailed));
3708
3794
  }
3709
3795
  }, isHtmlCanvasElement = (canvas) => {
3710
3796
  return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
3797
+ }, getEffectiveColorSpace = (context) => {
3798
+ if (!context) {
3799
+ return undefined;
3800
+ }
3801
+ const colorInfo = context;
3802
+ return colorInfo.getContextAttributes?.().colorSpace ?? undefined;
3711
3803
  };
3712
3804
  function setStyle(canvas, style, important = false) {
3713
3805
  if (!style) {
@@ -3832,7 +3924,7 @@
3832
3924
  const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
3833
3925
  if (color) {
3834
3926
  const hdrOptions = container.actualOptions.hdr;
3835
- elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, hdrOptions.mode);
3927
+ elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard));
3836
3928
  }
3837
3929
  else {
3838
3930
  elementStyle.backgroundColor = "";
@@ -3952,11 +4044,11 @@
3952
4044
  const container = this.#container, canSupportHdr = container.actualOptions.hdr.enable &&
3953
4045
  safeMatchMedia("(color-gamut: p3)")?.matches &&
3954
4046
  safeMatchMedia("(dynamic-range: high)")?.matches;
3955
- container.hdr = canSupportHdr ?? false;
3956
- container.hdrMode = container.actualOptions.hdr.mode;
4047
+ container.hdrMode = toEnumValue(HdrMode, container.actualOptions.hdr.mode, HdrMode.standard);
3957
4048
  container.peakNits = container.actualOptions.hdr.peakNits;
3958
4049
  const renderCanvas = this.renderCanvas;
3959
4050
  if (!renderCanvas) {
4051
+ container.hdr = canSupportHdr ?? false;
3960
4052
  return;
3961
4053
  }
3962
4054
  this.render.setContextSettings({
@@ -3975,7 +4067,6 @@
3975
4067
  context = null;
3976
4068
  }
3977
4069
  if (canSupportHdr && !context) {
3978
- container.hdr = false;
3979
4070
  const sdrSettings = {
3980
4071
  alpha: true,
3981
4072
  desynchronized: true,
@@ -3991,11 +4082,16 @@
3991
4082
  }
3992
4083
  }
3993
4084
  this.render.setContext(context);
4085
+ if (context) {
4086
+ const effectiveColorSpace = getEffectiveColorSpace(context);
4087
+ if (effectiveColorSpace !== undefined) {
4088
+ container.hdr = effectiveColorSpace === "display-p3";
4089
+ }
4090
+ }
3994
4091
  }
3995
4092
  #initHdrListeners() {
3996
4093
  this.#removeHdrListeners();
3997
4094
  const p3Query = safeMatchMedia("(color-gamut: p3)"), hdrQuery = safeMatchMedia("(dynamic-range: high)"), handleChange = () => {
3998
- this.#recreateRenderCanvas();
3999
4095
  this.#initContext();
4000
4096
  this.initBackground();
4001
4097
  }, listeners = [];
@@ -4031,16 +4127,6 @@
4031
4127
  element.style.setProperty(key, value, "important");
4032
4128
  }
4033
4129
  }
4034
- #recreateRenderCanvas() {
4035
- const renderCanvas = this.renderCanvas;
4036
- if (!renderCanvas) {
4037
- return;
4038
- }
4039
- if (this.domElement) {
4040
- return;
4041
- }
4042
- this.renderCanvas = new OffscreenCanvas(renderCanvas.width, renderCanvas.height);
4043
- }
4044
4130
  #removeHdrListeners() {
4045
4131
  if (!this.#hdrMediaListeners) {
4046
4132
  return;
@@ -4139,8 +4225,7 @@
4139
4225
  this.#resizeTimeout = undefined;
4140
4226
  }
4141
4227
  const handleResize = async () => {
4142
- const canvas = this.#container.canvas;
4143
- await canvas.windowResize();
4228
+ await this.#container.canvas.windowResize();
4144
4229
  };
4145
4230
  this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
4146
4231
  }
@@ -4168,8 +4253,8 @@
4168
4253
  }
4169
4254
  else if (!this.#resizeObserver && add && canvasEl) {
4170
4255
  this.#resizeObserver = new ResizeObserver((entries) => {
4171
- const entry = entries.find(e => e.target === canvasEl);
4172
- if (!entry) {
4256
+ const res = entries.some(e => e.target === canvasEl);
4257
+ if (!res) {
4173
4258
  return;
4174
4259
  }
4175
4260
  this.#handleWindowResize();
@@ -4433,10 +4518,10 @@
4433
4518
  return this.#modifiers.find(m => m.id === id);
4434
4519
  }
4435
4520
  getOpacity() {
4436
- 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;
4437
- this.#cachedOpacityData.fillOpacity = fillOpacity;
4521
+ 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;
4522
+ this.#cachedOpacityData.fillOpacity = this.fillOpacity ?? defaultOpacity$1;
4438
4523
  this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
4439
- this.#cachedOpacityData.strokeOpacity = strokeOpacity;
4524
+ this.#cachedOpacityData.strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
4440
4525
  return this.#cachedOpacityData;
4441
4526
  }
4442
4527
  getPosition() {
@@ -4683,7 +4768,7 @@
4683
4768
  #initPosition(position) {
4684
4769
  const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
4685
4770
  if (!initialPosition) {
4686
- throw new Error("a valid position cannot be found for particle");
4771
+ throw new Error(getErrorMessage(ErrorCodes$1.particlePositionNotFound));
4687
4772
  }
4688
4773
  this.position = initialPosition;
4689
4774
  this.initialPosition = this.position.copy();
@@ -4732,6 +4817,12 @@
4732
4817
  this.#circlePoolIdx = 0;
4733
4818
  this.#rectanglePoolIdx = 0;
4734
4819
  }
4820
+ get cellSize() {
4821
+ return this.#cellSize;
4822
+ }
4823
+ set cellSize(value) {
4824
+ this.#pendingCellSize = value;
4825
+ }
4735
4826
  clear() {
4736
4827
  this.#cells.clear();
4737
4828
  const pendingCellSize = this.#pendingCellSize;
@@ -4755,18 +4846,7 @@
4755
4846
  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);
4756
4847
  for (let cx = minCellX; cx <= maxCellX; cx++) {
4757
4848
  for (let cy = minCellY; cy <= maxCellY; cy++) {
4758
- const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
4759
- if (!cellParticles) {
4760
- continue;
4761
- }
4762
- for (const p of cellParticles) {
4763
- if (check && !check(p)) {
4764
- continue;
4765
- }
4766
- if (range.contains(p.getPosition())) {
4767
- out.push(p);
4768
- }
4769
- }
4849
+ this.#queryCell(cx, cy, range, check, out);
4770
4850
  }
4771
4851
  }
4772
4852
  return out;
@@ -4781,14 +4861,23 @@
4781
4861
  this.#releaseShapes();
4782
4862
  return result;
4783
4863
  }
4784
- setCellSize(cellSize) {
4785
- this.#pendingCellSize = cellSize;
4786
- }
4787
4864
  #acquireCircle(x, y, r) {
4788
- return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
4865
+ const idx = this.#circlePoolIdx++;
4866
+ let circle = this.#circlePool[idx];
4867
+ if (!circle) {
4868
+ circle = new Circle(x, y, r);
4869
+ this.#circlePool[idx] = circle;
4870
+ }
4871
+ return circle.reset(x, y, r);
4789
4872
  }
4790
4873
  #acquireRectangle(x, y, w, h) {
4791
- return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
4874
+ const idx = this.#rectanglePoolIdx++;
4875
+ let rectangle = this.#rectanglePool[idx];
4876
+ if (!rectangle) {
4877
+ rectangle = new Rectangle(x, y, w, h);
4878
+ this.#rectanglePool[idx] = rectangle;
4879
+ }
4880
+ return rectangle.reset(x, y, w, h);
4792
4881
  }
4793
4882
  #cellKeyFromCoords(x, y) {
4794
4883
  const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
@@ -4815,6 +4904,20 @@
4815
4904
  }
4816
4905
  return null;
4817
4906
  }
4907
+ #queryCell(cx, cy, range, check, out) {
4908
+ const cellParticles = this.#cells.get(`${cx}_${cy}`);
4909
+ if (!cellParticles) {
4910
+ return;
4911
+ }
4912
+ for (const p of cellParticles) {
4913
+ if (check && !check(p)) {
4914
+ continue;
4915
+ }
4916
+ if (range.contains(p.getPosition())) {
4917
+ out.push(p);
4918
+ }
4919
+ }
4920
+ }
4818
4921
  #releaseShapes() {
4819
4922
  this.#circlePoolIdx = 0;
4820
4923
  this.#rectanglePoolIdx = 0;
@@ -4823,9 +4926,9 @@
4823
4926
 
4824
4927
  class ParticlesManager {
4825
4928
  checkParticlePositionPlugins;
4826
- grid;
4827
4929
  #array;
4828
4930
  #container;
4931
+ #grid;
4829
4932
  #groupLimits;
4830
4933
  #limit;
4831
4934
  #nextId;
@@ -4849,7 +4952,7 @@
4849
4952
  this.#groupLimits = new Map();
4850
4953
  this.#particleBuckets = new Map();
4851
4954
  this.#zBuckets = this.#createBuckets(this.#container.zLayers);
4852
- this.grid = new SpatialHashGrid(spatialHashGridCellSize);
4955
+ this.#grid = new SpatialHashGrid(spatialHashGridCellSize);
4853
4956
  this.checkParticlePositionPlugins = [];
4854
4957
  this.#particleResetPlugins = [];
4855
4958
  this.#particleUpdatePlugins = [];
@@ -4860,23 +4963,12 @@
4860
4963
  get count() {
4861
4964
  return this.#array.length;
4862
4965
  }
4966
+ get grid() {
4967
+ return this.#grid;
4968
+ }
4863
4969
  addParticle(position, overrideOptions, group, initializer) {
4864
- const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
4865
- if (limit > minLimit) {
4866
- switch (limitMode) {
4867
- case LimitMode.delete: {
4868
- const countToRemove = currentCount + countOffset - limit;
4869
- if (countToRemove > minCount) {
4870
- this.removeQuantity(countToRemove);
4871
- }
4872
- break;
4873
- }
4874
- case LimitMode.wait:
4875
- if (currentCount >= limit) {
4876
- return;
4877
- }
4878
- break;
4879
- }
4970
+ if (this.#checkAndApplyLimits(group, this.count)) {
4971
+ return;
4880
4972
  }
4881
4973
  try {
4882
4974
  const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
@@ -4940,7 +5032,7 @@
4940
5032
  return this.#array[index];
4941
5033
  }
4942
5034
  async init() {
4943
- const container = this.#container, options = container.actualOptions;
5035
+ const container = this.#container;
4944
5036
  this.checkParticlePositionPlugins = [];
4945
5037
  this.#updatePlugins = [];
4946
5038
  this.#particleUpdatePlugins = [];
@@ -4949,59 +5041,16 @@
4949
5041
  this.#postParticleUpdatePlugins = [];
4950
5042
  this.#particleBuckets.clear();
4951
5043
  this.#resetBuckets(container.zLayers);
4952
- this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
4953
- for (const plugin of container.plugins) {
4954
- if (plugin.redrawInit) {
4955
- await plugin.redrawInit();
4956
- }
4957
- if (plugin.checkParticlePosition) {
4958
- this.checkParticlePositionPlugins.push(plugin);
4959
- }
4960
- if (plugin.update) {
4961
- this.#updatePlugins.push(plugin);
4962
- }
4963
- if (plugin.particleUpdate) {
4964
- this.#particleUpdatePlugins.push(plugin);
4965
- }
4966
- if (plugin.postUpdate) {
4967
- this.#postUpdatePlugins.push(plugin);
4968
- }
4969
- if (plugin.particleReset) {
4970
- this.#particleResetPlugins.push(plugin);
4971
- }
4972
- if (plugin.postParticleUpdate) {
4973
- this.#postParticleUpdatePlugins.push(plugin);
4974
- }
4975
- }
4976
- await this.#container.initDrawersAndUpdaters();
4977
- for (const drawer of this.#container.effectDrawers.values()) {
4978
- await drawer.init?.(container);
4979
- }
4980
- for (const drawer of this.#container.shapeDrawers.values()) {
4981
- await drawer.init?.(container);
4982
- }
4983
- let handled = false;
4984
- for (const plugin of container.plugins) {
4985
- handled = plugin.particlesInitialization?.() ?? handled;
4986
- if (handled) {
4987
- break;
4988
- }
4989
- }
4990
- if (!handled) {
4991
- const particlesOptions = options.particles, groups = particlesOptions.groups;
4992
- for (const group in groups) {
4993
- const groupOptions = groups[group];
4994
- if (!groupOptions) {
4995
- continue;
4996
- }
4997
- for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
4998
- this.addParticle(undefined, groupOptions, group);
4999
- }
5000
- }
5001
- for (let i = this.count; i < particlesOptions.number.value; i++) {
5002
- this.addParticle();
5044
+ this.#grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
5045
+ this.#applyLimits(container.actualOptions.particles);
5046
+ const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
5047
+ for (const group in groups) {
5048
+ const groupData = groups[group];
5049
+ if (groupData) {
5050
+ this.#applyLimits(loadParticlesOptions(this.#pluginManager, this.#container, groupData), group, groupData);
5003
5051
  }
5004
5052
  }
5053
+ await this.#initPlugins();
5005
5054
  }
5006
5055
  push(nb, position, overrideOptions, group) {
5007
5056
  for (let i = 0; i < nb; i++) {
@@ -5016,13 +5065,13 @@
5016
5065
  remove(particle, group, override) {
5017
5066
  this.removeAt(this.#array.indexOf(particle), undefined, group, override);
5018
5067
  }
5019
- removeAt(index, quantity = defaultRemoveQuantity, group, override) {
5068
+ removeAt(index, quantity = defaultRemoveQuantity, group, override, matchGroup = true) {
5020
5069
  if (index < minIndex || index > this.count) {
5021
5070
  return;
5022
5071
  }
5023
5072
  let deleted = 0;
5024
5073
  for (let i = index; deleted < quantity && i < this.count; i++) {
5025
- if (this.#removeParticle(i, group, override)) {
5074
+ if (this.#removeParticle(i, group, override, matchGroup)) {
5026
5075
  i--;
5027
5076
  deleted++;
5028
5077
  }
@@ -5053,7 +5102,7 @@
5053
5102
  this.#resizeFactor = factor;
5054
5103
  }
5055
5104
  update(delta) {
5056
- this.grid.clear();
5105
+ this.#grid.clear();
5057
5106
  for (const plugin of this.#updatePlugins) {
5058
5107
  plugin.update?.(delta);
5059
5108
  }
@@ -5064,7 +5113,7 @@
5064
5113
  this.#updateParticlesPhase2(delta, particlesToDelete);
5065
5114
  if (particlesToDelete.size) {
5066
5115
  for (const particle of particlesToDelete) {
5067
- this.remove(particle);
5116
+ this.remove(particle, particle.group);
5068
5117
  }
5069
5118
  }
5070
5119
  this.#resizeFactor = undefined;
@@ -5075,12 +5124,7 @@
5075
5124
  #applyDensity(options, pluginsCount, group, groupOptions) {
5076
5125
  const numberOptions = options.number;
5077
5126
  if (!numberOptions.density.enable) {
5078
- if (group === undefined) {
5079
- this.#limit = numberOptions.limit.value;
5080
- }
5081
- else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
5082
- this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
5083
- }
5127
+ this.#applyLimits(options, group, groupOptions);
5084
5128
  return;
5085
5129
  }
5086
5130
  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);
@@ -5088,7 +5132,10 @@
5088
5132
  this.#limit = numberOptions.limit.value * densityFactor;
5089
5133
  }
5090
5134
  else {
5091
- this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
5135
+ this.#groupLimits.set(group, {
5136
+ limit: numberOptions.limit.value * densityFactor,
5137
+ mode: toEnumValue(LimitMode, numberOptions.limit.mode, LimitMode.delete),
5138
+ });
5092
5139
  }
5093
5140
  if (particlesCount < particlesNumber) {
5094
5141
  this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
@@ -5097,6 +5144,55 @@
5097
5144
  this.removeQuantity(particlesCount - particlesNumber, group);
5098
5145
  }
5099
5146
  }
5147
+ #applyLimits(options, group, groupOptions) {
5148
+ if (group === undefined) {
5149
+ this.#limit = options.number.limit.value;
5150
+ const groups = this.#container.actualOptions.particles.groups;
5151
+ for (const existingGroup of this.#groupLimits.keys()) {
5152
+ if (!(existingGroup in groups)) {
5153
+ this.#groupLimits.delete(existingGroup);
5154
+ }
5155
+ }
5156
+ }
5157
+ else {
5158
+ const limitValue = groupOptions?.number?.limit?.value ?? options.number.limit.value;
5159
+ if (limitValue > minLimit) {
5160
+ this.#groupLimits.set(group, {
5161
+ limit: limitValue,
5162
+ mode: toEnumValue(LimitMode, groupOptions?.number?.limit?.mode ?? options.number.limit.mode, LimitMode.delete),
5163
+ });
5164
+ }
5165
+ else {
5166
+ this.#groupLimits.delete(group);
5167
+ }
5168
+ }
5169
+ }
5170
+ #checkAndApplyLimits(group, currentCount) {
5171
+ const globalLimit = this.#limit, globalMode = this.#container.actualOptions.particles.number.limit.mode;
5172
+ if (globalLimit > minLimit && globalMode === LimitMode.wait && currentCount >= globalLimit) {
5173
+ return true;
5174
+ }
5175
+ const groupLimitEntry = group === undefined ? undefined : this.#groupLimits.get(group);
5176
+ if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.wait) {
5177
+ const groupCount = this.filter(t => t.group === group).length;
5178
+ if (groupCount >= groupLimitEntry.limit) {
5179
+ return true;
5180
+ }
5181
+ }
5182
+ if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.delete) {
5183
+ const groupCountToRemove = this.filter(t => t.group === group).length + countOffset - groupLimitEntry.limit;
5184
+ if (groupCountToRemove > minCount) {
5185
+ this.removeQuantity(groupCountToRemove, group);
5186
+ }
5187
+ }
5188
+ if (globalLimit > minLimit && globalMode === LimitMode.delete) {
5189
+ const globalCountToRemove = this.count + countOffset - globalLimit;
5190
+ if (globalCountToRemove > minCount) {
5191
+ this.#removeAny(globalCountToRemove);
5192
+ }
5193
+ }
5194
+ return false;
5195
+ }
5100
5196
  #createBuckets(zLayers) {
5101
5197
  const bucketCount = Math.max(Math.floor(zLayers), one);
5102
5198
  return Array.from({ length: bucketCount }, () => []);
@@ -5119,6 +5215,70 @@
5119
5215
  }
5120
5216
  return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
5121
5217
  }
5218
+ async #initDrawersAndUpdaters() {
5219
+ const container = this.#container;
5220
+ await container.initDrawersAndUpdaters();
5221
+ for (const drawer of container.effectDrawers.values()) {
5222
+ await drawer.init?.(container);
5223
+ }
5224
+ for (const drawer of container.shapeDrawers.values()) {
5225
+ await drawer.init?.(container);
5226
+ }
5227
+ }
5228
+ async #initPlugins() {
5229
+ await this.#initPluginsArrays();
5230
+ await this.#initDrawersAndUpdaters();
5231
+ let handled = false;
5232
+ const container = this.#container;
5233
+ for (const plugin of container.plugins) {
5234
+ handled = plugin.particlesInitialization?.() ?? handled;
5235
+ if (handled) {
5236
+ break;
5237
+ }
5238
+ }
5239
+ if (handled) {
5240
+ return;
5241
+ }
5242
+ const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
5243
+ for (const group in groups) {
5244
+ const groupOptions = groups[group];
5245
+ if (!groupOptions) {
5246
+ continue;
5247
+ }
5248
+ for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
5249
+ this.addParticle(undefined, groupOptions, group);
5250
+ }
5251
+ }
5252
+ for (let i = this.count; i < particlesOptions.number.value; i++) {
5253
+ this.addParticle();
5254
+ }
5255
+ }
5256
+ async #initPluginsArrays() {
5257
+ const container = this.#container;
5258
+ for (const plugin of container.plugins) {
5259
+ if (plugin.redrawInit) {
5260
+ await plugin.redrawInit();
5261
+ }
5262
+ if (plugin.checkParticlePosition) {
5263
+ this.checkParticlePositionPlugins.push(plugin);
5264
+ }
5265
+ if (plugin.update) {
5266
+ this.#updatePlugins.push(plugin);
5267
+ }
5268
+ if (plugin.particleUpdate) {
5269
+ this.#particleUpdatePlugins.push(plugin);
5270
+ }
5271
+ if (plugin.postUpdate) {
5272
+ this.#postUpdatePlugins.push(plugin);
5273
+ }
5274
+ if (plugin.particleReset) {
5275
+ this.#particleResetPlugins.push(plugin);
5276
+ }
5277
+ if (plugin.postParticleUpdate) {
5278
+ this.#postParticleUpdatePlugins.push(plugin);
5279
+ }
5280
+ }
5281
+ }
5122
5282
  #insertParticleIntoBucket(particle) {
5123
5283
  const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
5124
5284
  if (!bucket) {
@@ -5127,12 +5287,15 @@
5127
5287
  bucket.push(particle);
5128
5288
  this.#particleBuckets.set(particle.id, bucketIndex);
5129
5289
  }
5130
- #removeParticle(index, group, override) {
5290
+ #removeAny(quantity) {
5291
+ this.removeAt(minIndex, quantity, undefined, undefined, false);
5292
+ }
5293
+ #removeParticle(index, group, override, matchGroup = true) {
5131
5294
  const particle = this.#array[index];
5132
5295
  if (!particle) {
5133
5296
  return false;
5134
5297
  }
5135
- if (particle.group !== group) {
5298
+ if (matchGroup && particle.group !== group) {
5136
5299
  return false;
5137
5300
  }
5138
5301
  this.#array.splice(index, deleteCount);
@@ -5219,7 +5382,7 @@
5219
5382
  particlesToDelete.add(particle);
5220
5383
  continue;
5221
5384
  }
5222
- this.grid.insert(particle);
5385
+ this.#grid.insert(particle);
5223
5386
  }
5224
5387
  return particlesToDelete;
5225
5388
  }
@@ -5395,7 +5558,6 @@
5395
5558
  this.shapeDrawers = new Map();
5396
5559
  this.particleUpdaters = [];
5397
5560
  this.plugins.length = 0;
5398
- this.#pluginManager.clearPlugins(this);
5399
5561
  this.destroyed = true;
5400
5562
  this.#onDestroy(remove);
5401
5563
  this.dispatchEvent(EventType.containerDestroyed);
@@ -5448,31 +5610,14 @@
5448
5610
  await this.initDrawersAndUpdaters();
5449
5611
  this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
5450
5612
  this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
5451
- this.plugins.length = 0;
5452
- this.particleDestroyedPlugins.length = 0;
5453
- this.particleCreatedPlugins.length = 0;
5454
- this.particlePositionPlugins.length = 0;
5455
- for (const [plugin, containerPlugin] of allContainerPlugins) {
5456
- if (plugin.needsPlugin(this.actualOptions)) {
5457
- this.plugins.push(containerPlugin);
5458
- if (containerPlugin.particleCreated) {
5459
- this.particleCreatedPlugins.push(containerPlugin);
5460
- }
5461
- if (containerPlugin.particleDestroyed) {
5462
- this.particleDestroyedPlugins.push(containerPlugin);
5463
- }
5464
- if (containerPlugin.particlePosition) {
5465
- this.particlePositionPlugins.push(containerPlugin);
5466
- }
5467
- }
5468
- }
5613
+ this.#initPlugins(allContainerPlugins);
5469
5614
  this.retina.init();
5470
5615
  this.canvas.init();
5471
5616
  this.updateActualOptions();
5472
5617
  this.canvas.initBackground();
5473
5618
  this.canvas.resize();
5474
5619
  const { delay, duration, fpsLimit, smooth, zLayers } = this.actualOptions, hdrOptions = this.actualOptions.hdr;
5475
- this.hdrMode = hdrOptions.mode;
5620
+ this.hdrMode = toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard);
5476
5621
  this.peakNits = hdrOptions.peakNits;
5477
5622
  this.zLayers = zLayers;
5478
5623
  this.#duration = getRangeValue(duration) * millisecondsToSeconds;
@@ -5493,9 +5638,9 @@
5493
5638
  }
5494
5639
  async initDrawersAndUpdaters() {
5495
5640
  const pluginManager = this.#pluginManager;
5496
- this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
5497
- this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
5498
- this.particleUpdaters = await pluginManager.getUpdaters(this, true);
5641
+ this.effectDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.effects);
5642
+ this.shapeDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.shapes);
5643
+ this.particleUpdaters = await getItemsFromInitializer(this, pluginManager.initializers.updaters);
5499
5644
  }
5500
5645
  pause() {
5501
5646
  if (!guardCheck(this)) {
@@ -5606,6 +5751,27 @@
5606
5751
  }
5607
5752
  return refresh;
5608
5753
  }
5754
+ #initPlugins(allContainerPlugins) {
5755
+ this.plugins.length = 0;
5756
+ this.particleDestroyedPlugins.length = 0;
5757
+ this.particleCreatedPlugins.length = 0;
5758
+ this.particlePositionPlugins.length = 0;
5759
+ for (const [plugin, containerPlugin] of allContainerPlugins) {
5760
+ if (!plugin.needsPlugin(this.actualOptions)) {
5761
+ continue;
5762
+ }
5763
+ this.plugins.push(containerPlugin);
5764
+ if (containerPlugin.particleCreated) {
5765
+ this.particleCreatedPlugins.push(containerPlugin);
5766
+ }
5767
+ if (containerPlugin.particleDestroyed) {
5768
+ this.particleDestroyedPlugins.push(containerPlugin);
5769
+ }
5770
+ if (containerPlugin.particlePosition) {
5771
+ this.particlePositionPlugins.push(containerPlugin);
5772
+ }
5773
+ }
5774
+ }
5609
5775
  #nextFrame(timestamp) {
5610
5776
  try {
5611
5777
  if (!this.#smooth &&
@@ -5882,11 +6048,11 @@
5882
6048
  }
5883
6049
  }
5884
6050
  async #init() {
5885
- const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
5886
- if (!availablePathGenerators) {
6051
+ const pluginManager = this.#pluginManager;
6052
+ if (!pluginManager.initializers.pathGenerators) {
5887
6053
  return;
5888
6054
  }
5889
- this.availablePathGenerators = availablePathGenerators;
6055
+ this.availablePathGenerators = await getItemMapFromInitializer(this.#container, pluginManager.initializers.pathGenerators);
5890
6056
  this.pathGenerators = new Map();
5891
6057
  for (const pathGenerator of this.pathGenerators.values()) {
5892
6058
  pathGenerator.init();
@@ -5902,6 +6068,7 @@
5902
6068
  exports.loadStarsPreset = loadStarsPreset;
5903
6069
  exports.tsParticles = tsParticles;
5904
6070
 
5905
- }));
6071
+ })(g.__tsParticlesInternals.presets.stars = g.__tsParticlesInternals.presets.stars || {});
6072
+ })(typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : self);
6073
+
5906
6074
  Object.assign(globalThis.window || globalThis, { loadStarsPreset: (globalThis.__tsParticlesInternals.presets.stars || {}).loadStarsPreset });
5907
- delete (globalThis.window || globalThis).tsparticlesInternalExports;