@tsparticles/engine 3.7.1 → 3.8.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.
Files changed (78) hide show
  1. package/browser/Core/Canvas.js +37 -27
  2. package/browser/Core/Container.js +10 -13
  3. package/browser/Core/Engine.js +15 -11
  4. package/browser/Core/Particle.js +8 -11
  5. package/browser/Core/Particles.js +10 -14
  6. package/browser/Core/Retina.js +1 -1
  7. package/browser/Core/Utils/Constants.js +10 -16
  8. package/browser/Core/Utils/EventListeners.js +5 -8
  9. package/browser/Core/Utils/QuadTree.js +1 -1
  10. package/browser/Core/Utils/Ranges.js +1 -1
  11. package/browser/Core/Utils/Vectors.js +10 -15
  12. package/browser/Options/Classes/ManualParticle.js +3 -3
  13. package/browser/Utils/CanvasUtils.js +8 -14
  14. package/browser/Utils/ColorUtils.js +12 -17
  15. package/browser/Utils/EventDispatcher.js +2 -2
  16. package/browser/Utils/NumberUtils.js +2 -4
  17. package/browser/Utils/Utils.js +58 -9
  18. package/cjs/Core/Canvas.js +38 -28
  19. package/cjs/Core/Container.js +14 -17
  20. package/cjs/Core/Engine.js +21 -17
  21. package/cjs/Core/Particle.js +18 -21
  22. package/cjs/Core/Particles.js +22 -26
  23. package/cjs/Core/Retina.js +5 -5
  24. package/cjs/Core/Utils/Constants.js +12 -17
  25. package/cjs/Core/Utils/EventListeners.js +8 -11
  26. package/cjs/Core/Utils/QuadTree.js +4 -4
  27. package/cjs/Core/Utils/Ranges.js +4 -4
  28. package/cjs/Core/Utils/Vectors.js +11 -16
  29. package/cjs/Options/Classes/ManualParticle.js +3 -3
  30. package/cjs/Utils/CanvasUtils.js +14 -20
  31. package/cjs/Utils/ColorUtils.js +47 -52
  32. package/cjs/Utils/EventDispatcher.js +5 -5
  33. package/cjs/Utils/NumberUtils.js +11 -13
  34. package/cjs/Utils/Utils.js +60 -10
  35. package/esm/Core/Canvas.js +37 -27
  36. package/esm/Core/Container.js +10 -13
  37. package/esm/Core/Engine.js +15 -11
  38. package/esm/Core/Particle.js +8 -11
  39. package/esm/Core/Particles.js +10 -14
  40. package/esm/Core/Retina.js +1 -1
  41. package/esm/Core/Utils/Constants.js +10 -16
  42. package/esm/Core/Utils/EventListeners.js +5 -8
  43. package/esm/Core/Utils/QuadTree.js +1 -1
  44. package/esm/Core/Utils/Ranges.js +1 -1
  45. package/esm/Core/Utils/Vectors.js +10 -15
  46. package/esm/Options/Classes/ManualParticle.js +3 -3
  47. package/esm/Utils/CanvasUtils.js +8 -14
  48. package/esm/Utils/ColorUtils.js +12 -17
  49. package/esm/Utils/EventDispatcher.js +2 -2
  50. package/esm/Utils/NumberUtils.js +2 -4
  51. package/esm/Utils/Utils.js +58 -9
  52. package/package.json +1 -1
  53. package/report.html +1 -1
  54. package/tsparticles.engine.js +20 -20
  55. package/tsparticles.engine.min.js +1 -1
  56. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  57. package/types/Core/Canvas.d.ts +1 -1
  58. package/types/Core/Engine.d.ts +5 -4
  59. package/types/Core/Utils/Constants.d.ts +7 -16
  60. package/types/Utils/ColorUtils.d.ts +1 -1
  61. package/types/Utils/Utils.d.ts +2 -2
  62. package/umd/Core/Canvas.js +39 -29
  63. package/umd/Core/Container.js +14 -17
  64. package/umd/Core/Engine.js +21 -17
  65. package/umd/Core/Particle.js +19 -22
  66. package/umd/Core/Particles.js +23 -27
  67. package/umd/Core/Retina.js +6 -6
  68. package/umd/Core/Utils/Constants.js +11 -17
  69. package/umd/Core/Utils/EventListeners.js +9 -12
  70. package/umd/Core/Utils/QuadTree.js +5 -5
  71. package/umd/Core/Utils/Ranges.js +5 -5
  72. package/umd/Core/Utils/Vectors.js +11 -16
  73. package/umd/Options/Classes/ManualParticle.js +4 -4
  74. package/umd/Utils/CanvasUtils.js +15 -21
  75. package/umd/Utils/ColorUtils.js +48 -53
  76. package/umd/Utils/EventDispatcher.js +6 -6
  77. package/umd/Utils/NumberUtils.js +12 -14
  78. package/umd/Utils/Utils.js +60 -10
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../Utils/CanvasUtils.js", "../Utils/Utils.js", "../Utils/ColorUtils.js", "./Utils/Constants.js"], factory);
7
+ define(["require", "exports", "../Utils/CanvasUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,12 +12,12 @@
12
12
  exports.Canvas = void 0;
13
13
  const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
14
14
  const Utils_js_1 = require("../Utils/Utils.js");
15
- const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
16
15
  const Constants_js_1 = require("./Utils/Constants.js");
16
+ const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
17
17
  function setTransformValue(factor, newFactor, key) {
18
- const newValue = newFactor[key], defaultValue = 1;
18
+ const newValue = newFactor[key];
19
19
  if (newValue !== undefined) {
20
- factor[key] = (factor[key] ?? defaultValue) * newValue;
20
+ factor[key] = (factor[key] ?? Constants_js_1.defaultTransformValue) * newValue;
21
21
  }
22
22
  }
23
23
  function setStyle(canvas, style, important = false) {
@@ -32,9 +32,27 @@
32
32
  if (!elementStyle) {
33
33
  return;
34
34
  }
35
+ const keys = new Set();
36
+ for (const key in elementStyle) {
37
+ if (!Object.prototype.hasOwnProperty.call(elementStyle, key)) {
38
+ continue;
39
+ }
40
+ keys.add(elementStyle[key]);
41
+ }
35
42
  for (const key in style) {
36
- const value = style[key];
37
- elementStyle.setProperty(key, value, important ? "important" : "");
43
+ if (!Object.prototype.hasOwnProperty.call(style, key)) {
44
+ continue;
45
+ }
46
+ keys.add(style[key]);
47
+ }
48
+ for (const key of keys) {
49
+ const value = style.getPropertyValue(key);
50
+ if (!value) {
51
+ elementStyle.removeProperty(key);
52
+ }
53
+ else {
54
+ elementStyle.setProperty(key, value, important ? "important" : "");
55
+ }
38
56
  }
39
57
  }
40
58
  class Canvas {
@@ -123,14 +141,13 @@
123
141
  return;
124
142
  }
125
143
  if (this._fullScreen) {
126
- this._originalStyle = (0, Utils_js_1.deepExtend)({}, element.style);
127
144
  this._setFullScreenStyle();
128
145
  }
129
146
  else {
130
147
  this._resetOriginalStyle();
131
148
  }
132
149
  for (const key in options.style) {
133
- if (!key || !options.style) {
150
+ if (!key || !options.style || !Object.prototype.hasOwnProperty.call(options.style, key)) {
134
151
  continue;
135
152
  }
136
153
  const value = options.style[key];
@@ -145,7 +162,7 @@
145
162
  if (!trail.enable) {
146
163
  return;
147
164
  }
148
- const factorNumerator = 1, opacity = factorNumerator / trail.length;
165
+ const opacity = Constants_js_1.inverseFactorNumerator / trail.length;
149
166
  if (trailFill.color) {
150
167
  const fillColor = (0, ColorUtils_js_1.rangeColorToRgb)(this._engine, trailFill.color);
151
168
  if (!fillColor) {
@@ -201,10 +218,10 @@
201
218
  };
202
219
  this._resetOriginalStyle = () => {
203
220
  const element = this.element, originalStyle = this._originalStyle;
204
- if (!(element && originalStyle)) {
221
+ if (!element || !originalStyle) {
205
222
  return;
206
223
  }
207
- setStyle(element, originalStyle);
224
+ setStyle(element, originalStyle, true);
208
225
  };
209
226
  this._safeMutationObserver = callback => {
210
227
  if (!this._mutationObserver) {
@@ -217,16 +234,7 @@
217
234
  if (!element) {
218
235
  return;
219
236
  }
220
- const radix = 10, zIndex = this.container.actualOptions.fullScreen.zIndex.toString(radix);
221
- setStyle(element, {
222
- position: "fixed",
223
- "z-index": zIndex,
224
- zIndex: zIndex,
225
- top: "0",
226
- left: "0",
227
- width: "100%",
228
- height: "100%",
229
- }, true);
237
+ setStyle(element, (0, Utils_js_1.getFullScreenStyle)(this.container.actualOptions.fullScreen.zIndex), true);
230
238
  };
231
239
  this._engine = engine;
232
240
  this._standardSize = {
@@ -249,11 +257,11 @@
249
257
  return this.container.actualOptions.fullScreen.enable;
250
258
  }
251
259
  clear() {
252
- const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill, minimumLength = 0;
260
+ const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill;
253
261
  if (options.backgroundMask.enable) {
254
262
  this.paint();
255
263
  }
256
- else if (trail.enable && trail.length > minimumLength && trailFill) {
264
+ else if (trail.enable && trail.length > Constants_js_1.minimumLength && trailFill) {
257
265
  if (trailFill.color) {
258
266
  this._paintBase((0, ColorUtils_js_1.getStyleFromRgb)(trailFill.color, trailFill.opacity));
259
267
  }
@@ -272,6 +280,7 @@
272
280
  if (this._generated) {
273
281
  const element = this.element;
274
282
  element?.remove();
283
+ this.element = undefined;
275
284
  }
276
285
  else {
277
286
  this._resetOriginalStyle();
@@ -299,8 +308,8 @@
299
308
  if (particle.spawning || particle.destroyed) {
300
309
  return;
301
310
  }
302
- const radius = particle.getRadius(), minimumSize = 0;
303
- if (radius <= minimumSize) {
311
+ const radius = particle.getRadius();
312
+ if (radius <= Constants_js_1.minimumSize) {
304
313
  return;
305
314
  }
306
315
  const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor() ?? pfColor;
@@ -315,7 +324,7 @@
315
324
  return;
316
325
  }
317
326
  this.draw((ctx) => {
318
- const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactorOffset = 1, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, defaultOpacity = 1, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
327
+ const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactor = Constants_js_1.zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? Constants_js_1.defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
319
328
  fill: fColor ? (0, ColorUtils_js_1.getStyleFromHsl)(fColor, zOpacity) : undefined,
320
329
  };
321
330
  colorStyles.stroke = sColor ? (0, ColorUtils_js_1.getStyleFromHsl)(sColor, zStrokeOpacity) : colorStyles.fill;
@@ -425,7 +434,7 @@
425
434
  : this._generated;
426
435
  this.element = canvas;
427
436
  this.element.ariaHidden = "true";
428
- this._originalStyle = (0, Utils_js_1.deepExtend)({}, this.element.style);
437
+ this._originalStyle = (0, Utils_js_1.cloneStyle)(this.element.style);
429
438
  const standardSize = this._standardSize;
430
439
  standardSize.height = canvas.offsetHeight;
431
440
  standardSize.width = canvas.offsetWidth;
@@ -433,14 +442,15 @@
433
442
  canvas.height = retinaSize.height = standardSize.height * pxRatio;
434
443
  canvas.width = retinaSize.width = standardSize.width * pxRatio;
435
444
  this._context = this.element.getContext("2d");
445
+ this._safeMutationObserver(obs => obs.disconnect());
446
+ this.container.retina.init();
447
+ this.initBackground();
436
448
  this._safeMutationObserver(obs => {
437
449
  if (!this.element || !(this.element instanceof Node)) {
438
450
  return;
439
451
  }
440
452
  obs.observe(this.element, { attributes: true });
441
453
  });
442
- this.container.retina.init();
443
- this.initBackground();
444
454
  }
445
455
  paint() {
446
456
  const options = this.container.actualOptions;
@@ -23,11 +23,10 @@
23
23
  function guardCheck(container) {
24
24
  return container && !container.destroyed;
25
25
  }
26
- const defaultFps = 60;
27
- function initDelta(value, fpsLimit = defaultFps, smooth = false) {
26
+ function initDelta(value, fpsLimit = Constants_js_1.defaultFps, smooth = false) {
28
27
  return {
29
28
  value,
30
- factor: smooth ? defaultFps / fpsLimit : (defaultFps * value) / Constants_js_1.millisecondsToSeconds,
29
+ factor: smooth ? Constants_js_1.defaultFps / fpsLimit : (Constants_js_1.defaultFps * value) / Constants_js_1.millisecondsToSeconds,
31
30
  };
32
31
  }
33
32
  function loadContainerOptions(engine, container, ...sourceOptionsArr) {
@@ -151,8 +150,8 @@
151
150
  const mouseEvent = e, pos = {
152
151
  x: mouseEvent.offsetX || mouseEvent.clientX,
153
152
  y: mouseEvent.offsetY || mouseEvent.clientY,
154
- }, radius = 1;
155
- clickOrTouchHandler(e, pos, radius);
153
+ };
154
+ clickOrTouchHandler(e, pos, Constants_js_1.clickRadius);
156
155
  }, touchStartHandler = () => {
157
156
  if (!guardCheck(this)) {
158
157
  return;
@@ -169,17 +168,17 @@
169
168
  return;
170
169
  }
171
170
  if (touched && !touchMoved) {
172
- const touchEvent = e, lengthOffset = 1;
173
- let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
171
+ const touchEvent = e;
172
+ let lastTouch = touchEvent.touches[touchEvent.touches.length - Constants_js_1.touchEndLengthOffset];
174
173
  if (!lastTouch) {
175
- lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
174
+ lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - Constants_js_1.touchEndLengthOffset];
176
175
  if (!lastTouch) {
177
176
  return;
178
177
  }
179
178
  }
180
- const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, minCoordinate = 0, pos = {
181
- x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
182
- y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
179
+ const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
180
+ x: lastTouch.clientX - (canvasRect ? canvasRect.left : Constants_js_1.minCoordinate),
181
+ y: lastTouch.clientY - (canvasRect ? canvasRect.top : Constants_js_1.minCoordinate),
183
182
  };
184
183
  clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
185
184
  }
@@ -247,10 +246,9 @@
247
246
  this._engine.clearPlugins(this);
248
247
  this.destroyed = true;
249
248
  if (remove) {
250
- const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
251
- if (idx >= minIndex) {
252
- const deleteCount = 1;
253
- mainArr.splice(idx, deleteCount);
249
+ const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this);
250
+ if (idx >= Constants_js_1.removeMinIndex) {
251
+ mainArr.splice(idx, Constants_js_1.removeDeleteCount);
254
252
  }
255
253
  }
256
254
  this._engine.dispatchEvent(EventType_js_1.EventType.containerDestroyed, { container: this });
@@ -326,8 +324,7 @@
326
324
  this._duration = (0, NumberUtils_js_1.getRangeValue)(duration) * Constants_js_1.millisecondsToSeconds;
327
325
  this._delay = (0, NumberUtils_js_1.getRangeValue)(delay) * Constants_js_1.millisecondsToSeconds;
328
326
  this._lifeTime = 0;
329
- const defaultFpsLimit = 120, minFpsLimit = 0;
330
- this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
327
+ this.fpsLimit = fpsLimit > Constants_js_1.minFpsLimit ? fpsLimit : Constants_js_1.defaultFpsLimit;
331
328
  this._smooth = smooth;
332
329
  for (const drawer of this.effectDrawers.values()) {
333
330
  await drawer.init?.(this);
@@ -36,24 +36,23 @@
36
36
  (0, Utils_js_1.getLogger)().error(`${Constants_js_1.errorPrefix} ${response.status} while retrieving config file`);
37
37
  return data.fallback;
38
38
  }
39
- const generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", getCanvasFromContainer = (domContainer) => {
39
+ const getCanvasFromContainer = (domContainer) => {
40
40
  let canvasEl;
41
- if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag) {
41
+ if (domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === Constants_js_1.canvasTag) {
42
42
  canvasEl = domContainer;
43
43
  if (!canvasEl.dataset[Constants_js_1.generatedAttribute]) {
44
- canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
44
+ canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
45
45
  }
46
46
  }
47
47
  else {
48
- const existingCanvases = domContainer.getElementsByTagName(canvasTag);
48
+ const existingCanvases = domContainer.getElementsByTagName(Constants_js_1.canvasTag);
49
49
  if (existingCanvases.length) {
50
- const firstIndex = 0;
51
- canvasEl = existingCanvases[firstIndex];
52
- canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedFalse;
50
+ canvasEl = existingCanvases[Constants_js_1.canvasFirstIndex];
51
+ canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedFalse;
53
52
  }
54
53
  else {
55
- canvasEl = document.createElement(canvasTag);
56
- canvasEl.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
54
+ canvasEl = document.createElement(Constants_js_1.canvasTag);
55
+ canvasEl.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
57
56
  domContainer.appendChild(canvasEl);
58
57
  }
59
58
  }
@@ -72,7 +71,7 @@
72
71
  }
73
72
  domContainer = document.createElement("div");
74
73
  domContainer.id = id;
75
- domContainer.dataset[Constants_js_1.generatedAttribute] = generatedTrue;
74
+ domContainer.dataset[Constants_js_1.generatedAttribute] = Constants_js_1.generatedTrue;
76
75
  document.body.append(domContainer);
77
76
  return domContainer;
78
77
  };
@@ -109,7 +108,7 @@
109
108
  return this._domArray;
110
109
  }
111
110
  get version() {
112
- return "3.7.1";
111
+ return "3.8.0";
113
112
  }
114
113
  async addColorManager(manager, refresh = true) {
115
114
  this.colorManagers.set(manager.key, manager);
@@ -177,6 +176,12 @@
177
176
  }
178
177
  await this.refresh(refresh);
179
178
  }
179
+ checkVersion(pluginVersion) {
180
+ if (this.version === pluginVersion) {
181
+ return;
182
+ }
183
+ throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
184
+ }
180
185
  clearPlugins(container) {
181
186
  this.updaters.delete(container);
182
187
  this.movers.delete(container);
@@ -242,17 +247,16 @@
242
247
  item(index) {
243
248
  const { items } = this, item = items[index];
244
249
  if (!item || item.destroyed) {
245
- const deleteCount = 1;
246
- items.splice(index, deleteCount);
250
+ items.splice(index, Constants_js_1.removeDeleteCount);
247
251
  return;
248
252
  }
249
253
  return item;
250
254
  }
251
255
  async load(params) {
252
- const randomFactor = 10000, id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * randomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
253
- const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), minIndex = 0, newItem = new Container_js_1.Container(this, id, currentOptions);
254
- if (oldIndex >= minIndex) {
255
- const old = this.item(oldIndex), one = 1, none = 0, deleteCount = old ? one : none;
256
+ const id = params.id ?? params.element?.id ?? `tsparticles${Math.floor((0, NumberUtils_js_1.getRandom)() * Constants_js_1.loadRandomFactor)}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options;
257
+ const currentOptions = (0, Utils_js_1.itemFromSingleOrMultiple)(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container_js_1.Container(this, id, currentOptions);
258
+ if (oldIndex >= Constants_js_1.loadMinIndex) {
259
+ const old = this.item(oldIndex), deleteCount = old ? Constants_js_1.one : Constants_js_1.none;
256
260
  if (old && !old.destroyed) {
257
261
  old.destroy(false);
258
262
  }
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./Utils/Vectors.js", "../Utils/NumberUtils.js", "../Utils/Utils.js", "./Utils/Constants.js", "../Utils/ColorUtils.js", "../Enums/Types/EventType.js", "../Options/Classes/Interactivity/Interactivity.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Enums/Modes/PixelMode.js", "../Utils/CanvasUtils.js", "../Utils/OptionsUtils.js"], factory);
7
+ define(["require", "exports", "./Utils/Vectors.js", "../Utils/NumberUtils.js", "./Utils/Constants.js", "../Utils/Utils.js", "../Utils/ColorUtils.js", "../Enums/Types/EventType.js", "../Options/Classes/Interactivity/Interactivity.js", "../Enums/Directions/MoveDirection.js", "../Enums/Modes/OutMode.js", "../Enums/Types/ParticleOutType.js", "../Enums/Modes/PixelMode.js", "../Utils/CanvasUtils.js", "../Utils/OptionsUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,8 +12,8 @@
12
12
  exports.Particle = void 0;
13
13
  const Vectors_js_1 = require("./Utils/Vectors.js");
14
14
  const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
15
- const Utils_js_1 = require("../Utils/Utils.js");
16
15
  const Constants_js_1 = require("./Utils/Constants.js");
16
+ const Utils_js_1 = require("../Utils/Utils.js");
17
17
  const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
18
18
  const EventType_js_1 = require("../Enums/Types/EventType.js");
19
19
  const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
@@ -23,7 +23,6 @@
23
23
  const PixelMode_js_1 = require("../Enums/Modes/PixelMode.js");
24
24
  const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
25
25
  const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
26
- const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2, randomString = "random";
27
26
  function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
28
27
  const effectData = effectOptions.options[effect];
29
28
  if (!effectData) {
@@ -48,7 +47,7 @@
48
47
  if (!(0, Utils_js_1.isInArray)(data.outMode, data.checkModes)) {
49
48
  return;
50
49
  }
51
- const diameter = data.radius * double;
50
+ const diameter = data.radius * Constants_js_1.double;
52
51
  if (data.coord > data.maxCoord - diameter) {
53
52
  data.setCb(-data.radius);
54
53
  }
@@ -59,7 +58,7 @@
59
58
  class Particle {
60
59
  constructor(engine, container) {
61
60
  this.container = container;
62
- this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
61
+ this._calcPosition = (container, position, zIndex, tryCount = Constants_js_1.defaultRetryCount) => {
63
62
  for (const plugin of container.plugins.values()) {
64
63
  const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
65
64
  if (pluginPos) {
@@ -93,8 +92,7 @@
93
92
  fixVertical(outModes.top ?? outModes.default);
94
93
  fixVertical(outModes.bottom ?? outModes.default);
95
94
  if (this._checkOverlap(pos, tryCount)) {
96
- const increment = 1;
97
- return this._calcPosition(container, undefined, zIndex, tryCount + increment);
95
+ return this._calcPosition(container, undefined, zIndex, tryCount + Constants_js_1.tryCountIncrement);
98
96
  }
99
97
  return pos;
100
98
  };
@@ -104,8 +102,8 @@
104
102
  return res;
105
103
  }
106
104
  const rad = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.value)), radOffset = (0, NumberUtils_js_1.degToRad)((0, NumberUtils_js_1.getRangeValue)(moveOptions.angle.offset)), range = {
107
- left: radOffset - rad * half,
108
- right: radOffset + rad * half,
105
+ left: radOffset - rad * Constants_js_1.half,
106
+ right: radOffset + rad * Constants_js_1.half,
109
107
  };
110
108
  if (!moveOptions.straight) {
111
109
  res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
@@ -115,7 +113,7 @@
115
113
  }
116
114
  return res;
117
115
  };
118
- this._checkOverlap = (pos, tryCount = defaultRetryCount) => {
116
+ this._checkOverlap = (pos, tryCount = Constants_js_1.defaultRetryCount) => {
119
117
  const collisionsOptions = this.options.collisions, radius = this.getRadius();
120
118
  if (!collisionsOptions.enable) {
121
119
  return false;
@@ -124,8 +122,8 @@
124
122
  if (overlapOptions.enable) {
125
123
  return false;
126
124
  }
127
- const retries = overlapOptions.retries, minRetries = 0;
128
- if (retries >= minRetries && tryCount > retries) {
125
+ const retries = overlapOptions.retries;
126
+ if (retries >= Constants_js_1.minRetries && tryCount > retries) {
129
127
  throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
130
128
  }
131
129
  return !!this.container.particles.find(particle => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
@@ -134,7 +132,7 @@
134
132
  if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
135
133
  return color;
136
134
  }
137
- const rollFactor = 1, none = 0, backFactor = this.roll.horizontal && this.roll.vertical ? double * rollFactor : rollFactor, backSum = this.roll.horizontal ? Math.PI * half : none, rolled = Math.floor(((this.roll.angle ?? none) + backSum) / (Math.PI / backFactor)) % double;
135
+ const backFactor = this.roll.horizontal && this.roll.vertical ? Constants_js_1.double * Constants_js_1.rollFactor : Constants_js_1.rollFactor, backSum = this.roll.horizontal ? Math.PI * Constants_js_1.half : Constants_js_1.none, rolled = Math.floor(((this.roll.angle ?? Constants_js_1.none) + backSum) / (Math.PI / backFactor)) % Constants_js_1.double;
138
136
  if (!rolled) {
139
137
  return color;
140
138
  }
@@ -147,13 +145,13 @@
147
145
  return color;
148
146
  };
149
147
  this._initPosition = position => {
150
- const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value), minZ = 0;
151
- this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, minZ, container.zLayers));
148
+ const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value);
149
+ this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
152
150
  this.initialPosition = this.position.copy();
153
- const canvasSize = container.canvas.size, defaultRadius = 0;
151
+ const canvasSize = container.canvas.size;
154
152
  this.moveCenter = {
155
153
  ...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
156
- radius: this.options.move.center.radius ?? defaultRadius,
154
+ radius: this.options.move.center.radius ?? Constants_js_1.defaultRadius,
157
155
  mode: this.options.move.center.mode ?? PixelMode_js_1.PixelMode.percent,
158
156
  };
159
157
  this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
@@ -203,7 +201,7 @@
203
201
  return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
204
202
  }
205
203
  getMass() {
206
- return this.getRadius() ** squareExp * Math.PI * half;
204
+ return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
207
205
  }
208
206
  getPosition() {
209
207
  return {
@@ -258,11 +256,11 @@
258
256
  }
259
257
  }
260
258
  }
261
- if (this.effect === randomString) {
259
+ if (this.effect === Constants_js_1.randomColorValue) {
262
260
  const availableEffects = [...this.container.effectDrawers.keys()];
263
261
  this.effect = availableEffects[Math.floor(Math.random() * availableEffects.length)];
264
262
  }
265
- if (this.shape === randomString) {
263
+ if (this.shape === Constants_js_1.randomColorValue) {
266
264
  const availableShapes = [...this.container.shapeDrawers.keys()];
267
265
  this.shape = availableShapes[Math.floor(Math.random() * availableShapes.length)];
268
266
  }
@@ -306,8 +304,7 @@
306
304
  this._initPosition(position);
307
305
  this.initialVelocity = this._calculateVelocity();
308
306
  this.velocity = this.initialVelocity.copy();
309
- const decayOffset = 1;
310
- this.moveDecay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
307
+ this.moveDecay = Constants_js_1.decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
311
308
  const particles = container.particles;
312
309
  particles.setLastZIndex(this.position.z);
313
310
  this.zIndexFactor = this.position.z / container.zLayers;
@@ -4,12 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../Utils/Utils.js", "../Enums/Types/EventType.js", "./Utils/InteractionManager.js", "../Enums/Modes/LimitMode.js", "./Particle.js", "./Utils/Point.js", "./Utils/QuadTree.js", "./Utils/Ranges.js", "./Utils/Constants.js"], factory);
7
+ define(["require", "exports", "./Utils/Constants.js", "../Utils/Utils.js", "../Enums/Types/EventType.js", "./Utils/InteractionManager.js", "../Enums/Modes/LimitMode.js", "./Particle.js", "./Utils/Point.js", "./Utils/QuadTree.js", "./Utils/Ranges.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Particles = void 0;
13
+ const Constants_js_1 = require("./Utils/Constants.js");
13
14
  const Utils_js_1 = require("../Utils/Utils.js");
14
15
  const EventType_js_1 = require("../Enums/Types/EventType.js");
15
16
  const InteractionManager_js_1 = require("./Utils/InteractionManager.js");
@@ -18,11 +19,9 @@
18
19
  const Point_js_1 = require("./Utils/Point.js");
19
20
  const QuadTree_js_1 = require("./Utils/QuadTree.js");
20
21
  const Ranges_js_1 = require("./Utils/Ranges.js");
21
- const Constants_js_1 = require("./Utils/Constants.js");
22
- const qTreeCapacity = 4, squareExp = 2, defaultRemoveQuantity = 1;
23
22
  const qTreeRectangle = (canvasSize) => {
24
- const { height, width } = canvasSize, posOffset = -0.25, sizeFactor = 1.5;
25
- return new Ranges_js_1.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
23
+ const { height, width } = canvasSize;
24
+ return new Ranges_js_1.Rectangle(Constants_js_1.posOffset * width, Constants_js_1.posOffset * height, Constants_js_1.sizeFactor * width, Constants_js_1.sizeFactor * height);
26
25
  };
27
26
  class Particles {
28
27
  constructor(engine, container) {
@@ -40,7 +39,7 @@
40
39
  }
41
40
  return;
42
41
  }
43
- const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, minLimit = 0, optParticlesLimit = numberOptions.limit.value > minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
42
+ const densityFactor = this._initDensityFactor(numberOptions.density), optParticlesNumber = numberOptions.value, optParticlesLimit = numberOptions.limit.value > Constants_js_1.minLimit ? numberOptions.limit.value : optParticlesNumber, particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount, particlesCount = Math.min(this.count, this.filter(t => t.group === group).length);
44
43
  if (group === undefined) {
45
44
  this._limit = numberOptions.limit.value * densityFactor;
46
45
  }
@@ -55,12 +54,12 @@
55
54
  }
56
55
  };
57
56
  this._initDensityFactor = densityOptions => {
58
- const container = this._container, defaultFactor = 1;
57
+ const container = this._container;
59
58
  if (!container.canvas.element || !densityOptions.enable) {
60
- return defaultFactor;
59
+ return Constants_js_1.defaultDensityFactor;
61
60
  }
62
61
  const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
63
- return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
62
+ return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** Constants_js_1.squareExp);
64
63
  };
65
64
  this._pushParticle = (position, overrideOptions, group, initializer) => {
66
65
  try {
@@ -96,9 +95,9 @@
96
95
  if (!particle || particle.group !== group) {
97
96
  return false;
98
97
  }
99
- const zIdx = this._zArray.indexOf(particle), deleteCount = 1;
100
- this._array.splice(index, deleteCount);
101
- this._zArray.splice(zIdx, deleteCount);
98
+ const zIdx = this._zArray.indexOf(particle);
99
+ this._array.splice(index, Constants_js_1.deleteCount);
100
+ this._zArray.splice(zIdx, Constants_js_1.deleteCount);
102
101
  particle.destroy(override);
103
102
  this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
104
103
  container: this._container,
@@ -122,7 +121,7 @@
122
121
  this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
123
122
  this._pluginsInitialized = false;
124
123
  const canvasSize = container.canvas.size;
125
- this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
124
+ this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), Constants_js_1.qTreeCapacity);
126
125
  this.movers = [];
127
126
  this.updaters = [];
128
127
  }
@@ -134,12 +133,12 @@
134
133
  options.manualParticles.forEach(p => this.addParticle(p.position ? (0, Utils_js_1.getPosition)(p.position, container.canvas.size) : undefined, p.options));
135
134
  }
136
135
  addParticle(position, overrideOptions, group, initializer) {
137
- const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count, minLimit = 0;
138
- if (limit > minLimit) {
136
+ const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
137
+ if (limit > Constants_js_1.minLimit) {
139
138
  switch (limitMode) {
140
139
  case LimitMode_js_1.LimitMode.delete: {
141
- const countOffset = 1, minCount = 0, countToRemove = currentCount + countOffset - limit;
142
- if (countToRemove > minCount) {
140
+ const countToRemove = currentCount + Constants_js_1.countOffset - limit;
141
+ if (countToRemove > Constants_js_1.minCount) {
143
142
  this.removeQuantity(countToRemove);
144
143
  }
145
144
  break;
@@ -238,9 +237,8 @@
238
237
  remove(particle, group, override) {
239
238
  this.removeAt(this._array.indexOf(particle), undefined, group, override);
240
239
  }
241
- removeAt(index, quantity = defaultRemoveQuantity, group, override) {
242
- const minIndex = 0;
243
- if (index < minIndex || index > this.count) {
240
+ removeAt(index, quantity = Constants_js_1.defaultRemoveQuantity, group, override) {
241
+ if (index < Constants_js_1.minIndex || index > this.count) {
244
242
  return;
245
243
  }
246
244
  let deleted = 0;
@@ -252,13 +250,12 @@
252
250
  }
253
251
  }
254
252
  removeQuantity(quantity, group) {
255
- const defaultIndex = 0;
256
- this.removeAt(defaultIndex, quantity, group);
253
+ this.removeAt(Constants_js_1.minIndex, quantity, group);
257
254
  }
258
255
  setDensity() {
259
- const options = this._container.actualOptions, groups = options.particles.groups, manualCount = 0;
256
+ const options = this._container.actualOptions, groups = options.particles.groups;
260
257
  for (const group in groups) {
261
- this._applyDensity(groups[group], manualCount, group);
258
+ this._applyDensity(groups[group], Constants_js_1.manualCount, group);
262
259
  }
263
260
  this._applyDensity(options.particles, options.manualParticles.length);
264
261
  }
@@ -271,7 +268,7 @@
271
268
  }
272
269
  update(delta) {
273
270
  const container = this._container, particlesToDelete = new Set();
274
- this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
271
+ this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), Constants_js_1.qTreeCapacity);
275
272
  for (const pathGenerator of container.pathGenerators.values()) {
276
273
  pathGenerator.update();
277
274
  }
@@ -332,8 +329,7 @@
332
329
  if (this._needsSort) {
333
330
  const zArray = this._zArray;
334
331
  zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
335
- const lengthOffset = 1;
336
- this._lastZIndex = zArray[zArray.length - lengthOffset].position.z;
332
+ this._lastZIndex = zArray[zArray.length - Constants_js_1.lengthOffset].position.z;
337
333
  this._needsSort = false;
338
334
  }
339
335
  }