@tsparticles/engine 3.7.1 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +59 -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 +61 -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 +59 -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 +61 -10
@@ -20,11 +20,10 @@ exports.getHslAnimationFromHsl = getHslAnimationFromHsl;
20
20
  exports.updateColorValue = updateColorValue;
21
21
  exports.updateColor = updateColor;
22
22
  const NumberUtils_js_1 = require("./NumberUtils.js");
23
- const TypeUtils_js_1 = require("./TypeUtils.js");
24
23
  const Constants_js_1 = require("../Core/Utils/Constants.js");
24
+ const TypeUtils_js_1 = require("./TypeUtils.js");
25
25
  const AnimationStatus_js_1 = require("../Enums/AnimationStatus.js");
26
26
  const Utils_js_1 = require("./Utils.js");
27
- const randomColorValue = "random", midColorValue = "mid";
28
27
  function stringToRgba(engine, input) {
29
28
  if (!input) {
30
29
  return;
@@ -61,7 +60,7 @@ function colorToRgb(engine, input, index, useIndex = true) {
61
60
  }
62
61
  const color = (0, TypeUtils_js_1.isString)(input) ? { value: input } : input;
63
62
  if ((0, TypeUtils_js_1.isString)(color.value)) {
64
- return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(engine, color.value);
63
+ return color.value === Constants_js_1.randomColorValue ? getRandomRgbColor() : stringToRgb(engine, color.value);
65
64
  }
66
65
  if ((0, TypeUtils_js_1.isArray)(color.value)) {
67
66
  return colorToRgb(engine, {
@@ -84,26 +83,26 @@ function rangeColorToHsl(engine, color, index, useIndex = true) {
84
83
  return rgb ? rgbToHsl(rgb) : undefined;
85
84
  }
86
85
  function rgbToHsl(color) {
87
- const rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, half = 0.5, double = 2, r1 = color.r / rgbMax, g1 = color.g / rgbMax, b1 = color.b / rgbMax, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
88
- h: hMin,
89
- l: (max + min) * half,
90
- s: sMin,
86
+ const r1 = color.r / Constants_js_1.rgbMax, g1 = color.g / Constants_js_1.rgbMax, b1 = color.b / Constants_js_1.rgbMax, max = Math.max(r1, g1, b1), min = Math.min(r1, g1, b1), res = {
87
+ h: Constants_js_1.hMin,
88
+ l: (max + min) * Constants_js_1.half,
89
+ s: Constants_js_1.sMin,
91
90
  };
92
91
  if (max !== min) {
93
- res.s = res.l < half ? (max - min) / (max + min) : (max - min) / (double - max - min);
92
+ res.s = res.l < Constants_js_1.half ? (max - min) / (max + min) : (max - min) / (Constants_js_1.double - max - min);
94
93
  res.h =
95
94
  r1 === max
96
95
  ? (g1 - b1) / (max - min)
97
- : (res.h = g1 === max ? double + (b1 - r1) / (max - min) : double * double + (r1 - g1) / (max - min));
96
+ : (res.h = g1 === max ? Constants_js_1.double + (b1 - r1) / (max - min) : Constants_js_1.double * Constants_js_1.double + (r1 - g1) / (max - min));
98
97
  }
99
- res.l *= lMax;
100
- res.s *= sMax;
101
- res.h *= hPhase;
102
- if (res.h < hMin) {
103
- res.h += hMax;
98
+ res.l *= Constants_js_1.lMax;
99
+ res.s *= Constants_js_1.sMax;
100
+ res.h *= Constants_js_1.hPhase;
101
+ if (res.h < Constants_js_1.hMin) {
102
+ res.h += Constants_js_1.hMax;
104
103
  }
105
- if (res.h >= hMax) {
106
- res.h -= hMax;
104
+ if (res.h >= Constants_js_1.hMax) {
105
+ res.h -= Constants_js_1.hMax;
107
106
  }
108
107
  return res;
109
108
  }
@@ -114,33 +113,33 @@ function stringToRgb(engine, input) {
114
113
  return stringToRgba(engine, input);
115
114
  }
116
115
  function hslToRgb(hsl) {
117
- const hMax = 360, sMax = 100, lMax = 100, sMin = 0, lMin = 0, h = ((hsl.h % hMax) + hMax) % hMax, s = Math.max(sMin, Math.min(sMax, hsl.s)), l = Math.max(lMin, Math.min(lMax, hsl.l)), hNormalized = h / hMax, sNormalized = s / sMax, lNormalized = l / lMax, rgbFactor = 255, triple = 3;
118
- if (s === sMin) {
119
- const grayscaleValue = Math.round(lNormalized * rgbFactor);
116
+ const h = ((hsl.h % Constants_js_1.hMax) + Constants_js_1.hMax) % Constants_js_1.hMax, s = Math.max(Constants_js_1.sMin, Math.min(Constants_js_1.sMax, hsl.s)), l = Math.max(Constants_js_1.lMin, Math.min(Constants_js_1.lMax, hsl.l)), hNormalized = h / Constants_js_1.hMax, sNormalized = s / Constants_js_1.sMax, lNormalized = l / Constants_js_1.lMax;
117
+ if (s === Constants_js_1.sMin) {
118
+ const grayscaleValue = Math.round(lNormalized * Constants_js_1.rgbFactor);
120
119
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
121
120
  }
122
- const half = 0.5, double = 2, channel = (temp1, temp2, temp3) => {
123
- const temp3Min = 0, temp3Max = 1, sextuple = 6;
121
+ const channel = (temp1, temp2, temp3) => {
122
+ const temp3Min = 0, temp3Max = 1;
124
123
  if (temp3 < temp3Min) {
125
124
  temp3++;
126
125
  }
127
126
  if (temp3 > temp3Max) {
128
127
  temp3--;
129
128
  }
130
- if (temp3 * sextuple < temp3Max) {
131
- return temp1 + (temp2 - temp1) * sextuple * temp3;
129
+ if (temp3 * Constants_js_1.sextuple < temp3Max) {
130
+ return temp1 + (temp2 - temp1) * Constants_js_1.sextuple * temp3;
132
131
  }
133
- if (temp3 * double < temp3Max) {
132
+ if (temp3 * Constants_js_1.double < temp3Max) {
134
133
  return temp2;
135
134
  }
136
- if (temp3 * triple < temp3Max * double) {
137
- const temp3Offset = double / triple;
138
- return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * sextuple;
135
+ if (temp3 * Constants_js_1.triple < temp3Max * Constants_js_1.double) {
136
+ const temp3Offset = Constants_js_1.double / Constants_js_1.triple;
137
+ return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * Constants_js_1.sextuple;
139
138
  }
140
139
  return temp1;
141
- }, sNormalizedOffset = 1, temp1 = lNormalized < half
142
- ? lNormalized * (sNormalizedOffset + sNormalized)
143
- : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseNumerator = 1, phaseThird = phaseNumerator / triple, red = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized)), blue = Math.min(rgbFactor, rgbFactor * channel(temp2, temp1, hNormalized - phaseThird));
140
+ }, temp1 = lNormalized < Constants_js_1.half
141
+ ? lNormalized * (Constants_js_1.sNormalizedOffset + sNormalized)
142
+ : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = Constants_js_1.double * lNormalized - temp1, phaseThird = Constants_js_1.phaseNumerator / Constants_js_1.triple, red = Math.min(Constants_js_1.rgbFactor, Constants_js_1.rgbFactor * channel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(Constants_js_1.rgbFactor, Constants_js_1.rgbFactor * channel(temp2, temp1, hNormalized)), blue = Math.min(Constants_js_1.rgbFactor, Constants_js_1.rgbFactor * channel(temp2, temp1, hNormalized - phaseThird));
144
143
  return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
145
144
  }
146
145
  function hslaToRgba(hsla) {
@@ -153,20 +152,18 @@ function hslaToRgba(hsla) {
153
152
  };
154
153
  }
155
154
  function getRandomRgbColor(min) {
156
- const defaultMin = 0, fixedMin = min ?? defaultMin, rgbMax = 256;
155
+ const fixedMin = min ?? Constants_js_1.defaultRgbMin, fixedMax = Constants_js_1.rgbMax + Constants_js_1.identity;
157
156
  return {
158
- b: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
159
- g: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
160
- r: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, rgbMax))),
157
+ b: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, fixedMax))),
158
+ g: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, fixedMax))),
159
+ r: Math.floor((0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(fixedMin, fixedMax))),
161
160
  };
162
161
  }
163
162
  function getStyleFromRgb(color, opacity) {
164
- const defaultOpacity = 1;
165
- return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity ?? defaultOpacity})`;
163
+ return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity ?? Constants_js_1.defaultOpacity})`;
166
164
  }
167
165
  function getStyleFromHsl(color, opacity) {
168
- const defaultOpacity = 1;
169
- return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity ?? defaultOpacity})`;
166
+ return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity ?? Constants_js_1.defaultOpacity})`;
170
167
  }
171
168
  function colorMix(color1, color2, size1, size2) {
172
169
  let rgb1 = color1, rgb2 = color2;
@@ -183,10 +180,10 @@ function colorMix(color1, color2, size1, size2) {
183
180
  };
184
181
  }
185
182
  function getLinkColor(p1, p2, linkColor) {
186
- if (linkColor === randomColorValue) {
183
+ if (linkColor === Constants_js_1.randomColorValue) {
187
184
  return getRandomRgbColor();
188
185
  }
189
- else if (linkColor === midColorValue) {
186
+ else if (linkColor === Constants_js_1.midColorValue) {
190
187
  const sourceColor = p1.getFillColor() ?? p1.getStrokeColor(), destColor = p2?.getFillColor() ?? p2?.getStrokeColor();
191
188
  if (sourceColor && destColor && p2) {
192
189
  return colorMix(sourceColor, destColor, p1.getRadius(), p2.getRadius());
@@ -204,19 +201,19 @@ function getLinkColor(p1, p2, linkColor) {
204
201
  }
205
202
  function getLinkRandomColor(engine, optColor, blink, consent) {
206
203
  const color = (0, TypeUtils_js_1.isString)(optColor) ? optColor : optColor.value;
207
- if (color === randomColorValue) {
204
+ if (color === Constants_js_1.randomColorValue) {
208
205
  if (consent) {
209
206
  return rangeColorToRgb(engine, {
210
207
  value: color,
211
208
  });
212
209
  }
213
210
  if (blink) {
214
- return randomColorValue;
211
+ return Constants_js_1.randomColorValue;
215
212
  }
216
- return midColorValue;
213
+ return Constants_js_1.midColorValue;
217
214
  }
218
- else if (color === midColorValue) {
219
- return midColorValue;
215
+ else if (color === Constants_js_1.midColorValue) {
216
+ return Constants_js_1.midColorValue;
220
217
  }
221
218
  else {
222
219
  return rangeColorToRgb(engine, {
@@ -257,14 +254,13 @@ function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
257
254
  }
258
255
  function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
259
256
  colorValue.enable = colorAnimation.enable;
260
- const defaultVelocity = 0, decayOffset = 1, defaultLoops = 0, defaultTime = 0;
261
257
  if (colorValue.enable) {
262
258
  colorValue.velocity = ((0, NumberUtils_js_1.getRangeValue)(colorAnimation.speed) / Constants_js_1.percentDenominator) * reduceFactor;
263
- colorValue.decay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(colorAnimation.decay);
259
+ colorValue.decay = Constants_js_1.decayOffset - (0, NumberUtils_js_1.getRangeValue)(colorAnimation.decay);
264
260
  colorValue.status = AnimationStatus_js_1.AnimationStatus.increasing;
265
- colorValue.loops = defaultLoops;
261
+ colorValue.loops = Constants_js_1.defaultLoops;
266
262
  colorValue.maxLoops = (0, NumberUtils_js_1.getRangeValue)(colorAnimation.count);
267
- colorValue.time = defaultTime;
263
+ colorValue.time = Constants_js_1.defaultTime;
268
264
  colorValue.delayTime = (0, NumberUtils_js_1.getRangeValue)(colorAnimation.delay) * Constants_js_1.millisecondsToSeconds;
269
265
  if (!colorAnimation.sync) {
270
266
  colorValue.velocity *= (0, NumberUtils_js_1.getRandom)();
@@ -274,7 +270,7 @@ function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
274
270
  colorValue.offset = (0, NumberUtils_js_1.setRangeValue)(colorAnimation.offset);
275
271
  }
276
272
  else {
277
- colorValue.velocity = defaultVelocity;
273
+ colorValue.velocity = Constants_js_1.defaultVelocity;
278
274
  }
279
275
  }
280
276
  function updateColorValue(data, range, decrease, delta) {
@@ -329,8 +325,7 @@ function updateColor(color, delta) {
329
325
  if (!color) {
330
326
  return;
331
327
  }
332
- const { h, s, l } = color;
333
- const ranges = {
328
+ const { h, s, l } = color, ranges = {
334
329
  h: { min: 0, max: 360 },
335
330
  s: { min: 0, max: 100 },
336
331
  l: { min: 0, max: 100 },
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventDispatcher = void 0;
4
+ const Constants_js_1 = require("../Core/Utils/Constants.js");
4
5
  class EventDispatcher {
5
6
  constructor() {
6
7
  this._listeners = new Map();
@@ -34,16 +35,15 @@ class EventDispatcher {
34
35
  if (!arr) {
35
36
  return;
36
37
  }
37
- const length = arr.length, idx = arr.indexOf(listener), minIndex = 0;
38
- if (idx < minIndex) {
38
+ const length = arr.length, idx = arr.indexOf(listener);
39
+ if (idx < Constants_js_1.minIndex) {
39
40
  return;
40
41
  }
41
- const deleteCount = 1;
42
- if (length === deleteCount) {
42
+ if (length === Constants_js_1.deleteCount) {
43
43
  this._listeners.delete(type);
44
44
  }
45
45
  else {
46
- arr.splice(idx, deleteCount);
46
+ arr.splice(idx, Constants_js_1.deleteCount);
47
47
  }
48
48
  }
49
49
  }
@@ -25,14 +25,14 @@ exports.calcExactPositionOrRandomFromSize = calcExactPositionOrRandomFromSize;
25
25
  exports.calcExactPositionOrRandomFromSizeRanged = calcExactPositionOrRandomFromSizeRanged;
26
26
  exports.parseAlpha = parseAlpha;
27
27
  const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
28
+ const Constants_js_1 = require("../Core/Utils/Constants.js");
28
29
  const Vectors_js_1 = require("../Core/Utils/Vectors.js");
29
30
  const TypeUtils_js_1 = require("./TypeUtils.js");
30
- const Constants_js_1 = require("../Core/Utils/Constants.js");
31
31
  let _random = Math.random;
32
32
  const _animationLoop = {
33
33
  nextFrame: (cb) => requestAnimationFrame(cb),
34
34
  cancel: (idx) => cancelAnimationFrame(idx),
35
- }, double = 2, doublePI = Math.PI * double;
35
+ };
36
36
  function setRandom(rnd = Math.random) {
37
37
  _random = rnd;
38
38
  }
@@ -100,30 +100,29 @@ function getParticleDirectionAngle(direction, position, center) {
100
100
  if ((0, TypeUtils_js_1.isNumber)(direction)) {
101
101
  return degToRad(direction);
102
102
  }
103
- const empty = 0, half = 0.5, quarter = 0.25, threeQuarter = half + quarter;
104
103
  switch (direction) {
105
104
  case MoveDirection_js_1.MoveDirection.top:
106
- return -Math.PI * half;
105
+ return -Math.PI * Constants_js_1.half;
107
106
  case MoveDirection_js_1.MoveDirection.topRight:
108
- return -Math.PI * quarter;
107
+ return -Math.PI * Constants_js_1.quarter;
109
108
  case MoveDirection_js_1.MoveDirection.right:
110
- return empty;
109
+ return Constants_js_1.empty;
111
110
  case MoveDirection_js_1.MoveDirection.bottomRight:
112
- return Math.PI * quarter;
111
+ return Math.PI * Constants_js_1.quarter;
113
112
  case MoveDirection_js_1.MoveDirection.bottom:
114
- return Math.PI * half;
113
+ return Math.PI * Constants_js_1.half;
115
114
  case MoveDirection_js_1.MoveDirection.bottomLeft:
116
- return Math.PI * threeQuarter;
115
+ return Math.PI * Constants_js_1.threeQuarter;
117
116
  case MoveDirection_js_1.MoveDirection.left:
118
117
  return Math.PI;
119
118
  case MoveDirection_js_1.MoveDirection.topLeft:
120
- return -Math.PI * threeQuarter;
119
+ return -Math.PI * Constants_js_1.threeQuarter;
121
120
  case MoveDirection_js_1.MoveDirection.inside:
122
121
  return Math.atan2(center.y - position.y, center.x - position.x);
123
122
  case MoveDirection_js_1.MoveDirection.outside:
124
123
  return Math.atan2(position.y - center.y, position.x - center.x);
125
124
  default:
126
- return getRandom() * doublePI;
125
+ return getRandom() * Constants_js_1.doublePI;
127
126
  }
128
127
  }
129
128
  function getParticleBaseVelocity(direction) {
@@ -133,8 +132,7 @@ function getParticleBaseVelocity(direction) {
133
132
  return baseVelocity;
134
133
  }
135
134
  function collisionVelocity(v1, v2, m1, m2) {
136
- const double = 2;
137
- return Vectors_js_1.Vector.create((v1.x * (m1 - m2)) / (m1 + m2) + (v2.x * double * m2) / (m1 + m2), v1.y);
135
+ return Vectors_js_1.Vector.create((v1.x * (m1 - m2)) / (m1 + m2) + (v2.x * Constants_js_1.double * m2) / (m1 + m2), v1.y);
138
136
  }
139
137
  function calcPositionFromSize(data) {
140
138
  return data.position?.x !== undefined && data.position.y !== undefined
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFullScreenStyle = void 0;
3
4
  exports.setLogger = setLogger;
4
5
  exports.getLogger = getLogger;
5
6
  exports.isSsr = isSsr;
@@ -29,7 +30,7 @@ exports.initParticleNumericAnimationValue = initParticleNumericAnimationValue;
29
30
  exports.getPosition = getPosition;
30
31
  exports.getSize = getSize;
31
32
  exports.updateAnimation = updateAnimation;
32
- exports.assertValidVersion = assertValidVersion;
33
+ exports.cloneStyle = cloneStyle;
33
34
  const NumberUtils_js_1 = require("./NumberUtils.js");
34
35
  const Constants_js_1 = require("../Core/Utils/Constants.js");
35
36
  const TypeUtils_js_1 = require("./TypeUtils.js");
@@ -59,16 +60,28 @@ function setLogger(logger) {
59
60
  function getLogger() {
60
61
  return _logger;
61
62
  }
63
+ function memoize(fn) {
64
+ const cache = new Map();
65
+ return (...args) => {
66
+ const key = JSON.stringify(args);
67
+ if (cache.has(key)) {
68
+ return cache.get(key);
69
+ }
70
+ const result = fn(...args);
71
+ cache.set(key, result);
72
+ return result;
73
+ };
74
+ }
62
75
  function rectSideBounce(data) {
63
- const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data, half = 0.5, minVelocity = 0;
76
+ const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data;
64
77
  if (pOtherSide.min < rectOtherSide.min ||
65
78
  pOtherSide.min > rectOtherSide.max ||
66
79
  pOtherSide.max < rectOtherSide.min ||
67
80
  pOtherSide.max > rectOtherSide.max) {
68
81
  return res;
69
82
  }
70
- if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * half && velocity > minVelocity) ||
71
- (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * half && velocity < minVelocity)) {
83
+ if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * Constants_js_1.half && velocity > Constants_js_1.minVelocity) ||
84
+ (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * Constants_js_1.half && velocity < Constants_js_1.minVelocity)) {
72
85
  res.velocity = velocity * -factor;
73
86
  res.bounced = true;
74
87
  }
@@ -316,7 +329,7 @@ function initParticleNumericAnimationValue(options, pxRatio) {
316
329
  res.status = AnimationStatus_js_1.AnimationStatus.decreasing;
317
330
  break;
318
331
  case AnimationMode_js_1.AnimationMode.random:
319
- res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
332
+ res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.half ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
320
333
  break;
321
334
  }
322
335
  const autoStatus = animationOptions.mode === AnimationMode_js_1.AnimationMode.auto;
@@ -337,7 +350,7 @@ function initParticleNumericAnimationValue(options, pxRatio) {
337
350
  default:
338
351
  res.value = (0, NumberUtils_js_1.randomInRange)(res);
339
352
  if (autoStatus) {
340
- res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
353
+ res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.half ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
341
354
  }
342
355
  break;
343
356
  }
@@ -446,9 +459,47 @@ function updateAnimation(particle, data, changeDirection, destroyType, delta) {
446
459
  data.value = (0, NumberUtils_js_1.clamp)(data.value, minValue, maxValue);
447
460
  }
448
461
  }
449
- function assertValidVersion(engine, pluginVersion) {
450
- if (engine.version === pluginVersion) {
451
- return;
462
+ function cloneStyle(style) {
463
+ const clonedStyle = document.createElement("div").style;
464
+ if (!style) {
465
+ return clonedStyle;
466
+ }
467
+ for (const key in style) {
468
+ const styleKey = style[key];
469
+ if (!Object.prototype.hasOwnProperty.call(style, key) || (0, TypeUtils_js_1.isNull)(styleKey)) {
470
+ continue;
471
+ }
472
+ const styleValue = style.getPropertyValue?.(styleKey);
473
+ if (!styleValue) {
474
+ continue;
475
+ }
476
+ const stylePriority = style.getPropertyPriority?.(styleKey);
477
+ if (!stylePriority) {
478
+ clonedStyle.setProperty?.(styleKey, styleValue);
479
+ }
480
+ else {
481
+ clonedStyle.setProperty?.(styleKey, styleValue, stylePriority);
482
+ }
483
+ }
484
+ return clonedStyle;
485
+ }
486
+ function computeFullScreenStyle(zIndex) {
487
+ const fullScreenStyle = document.createElement("div").style, radix = 10, style = {
488
+ width: "100%",
489
+ height: "100%",
490
+ margin: "0",
491
+ padding: "0",
492
+ borderWidth: "0",
493
+ position: "fixed",
494
+ zIndex: zIndex.toString(radix),
495
+ "z-index": zIndex.toString(radix),
496
+ top: "0",
497
+ left: "0",
498
+ };
499
+ for (const key in style) {
500
+ const value = style[key];
501
+ fullScreenStyle.setProperty(key, value);
452
502
  }
453
- throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
503
+ return fullScreenStyle;
454
504
  }
505
+ exports.getFullScreenStyle = memoize(computeFullScreenStyle);
@@ -1,11 +1,11 @@
1
1
  import { clear, drawParticle, drawParticlePlugin, drawPlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
2
- import { deepExtend, getLogger, safeMutationObserver } from "../Utils/Utils.js";
2
+ import { cloneStyle, getFullScreenStyle, getLogger, safeMutationObserver } from "../Utils/Utils.js";
3
+ import { defaultOpacity, defaultTransformValue, generatedAttribute, inverseFactorNumerator, minimumLength, minimumSize, zIndexFactorOffset, } from "./Utils/Constants.js";
3
4
  import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
4
- import { generatedAttribute } from "./Utils/Constants.js";
5
5
  function setTransformValue(factor, newFactor, key) {
6
- const newValue = newFactor[key], defaultValue = 1;
6
+ const newValue = newFactor[key];
7
7
  if (newValue !== undefined) {
8
- factor[key] = (factor[key] ?? defaultValue) * newValue;
8
+ factor[key] = (factor[key] ?? defaultTransformValue) * newValue;
9
9
  }
10
10
  }
11
11
  function setStyle(canvas, style, important = false) {
@@ -20,9 +20,27 @@ function setStyle(canvas, style, important = false) {
20
20
  if (!elementStyle) {
21
21
  return;
22
22
  }
23
+ const keys = new Set();
24
+ for (const key in elementStyle) {
25
+ if (!Object.prototype.hasOwnProperty.call(elementStyle, key)) {
26
+ continue;
27
+ }
28
+ keys.add(elementStyle[key]);
29
+ }
23
30
  for (const key in style) {
24
- const value = style[key];
25
- elementStyle.setProperty(key, value, important ? "important" : "");
31
+ if (!Object.prototype.hasOwnProperty.call(style, key)) {
32
+ continue;
33
+ }
34
+ keys.add(style[key]);
35
+ }
36
+ for (const key of keys) {
37
+ const value = style.getPropertyValue(key);
38
+ if (!value) {
39
+ elementStyle.removeProperty(key);
40
+ }
41
+ else {
42
+ elementStyle.setProperty(key, value, important ? "important" : "");
43
+ }
26
44
  }
27
45
  }
28
46
  export class Canvas {
@@ -111,14 +129,13 @@ export class Canvas {
111
129
  return;
112
130
  }
113
131
  if (this._fullScreen) {
114
- this._originalStyle = deepExtend({}, element.style);
115
132
  this._setFullScreenStyle();
116
133
  }
117
134
  else {
118
135
  this._resetOriginalStyle();
119
136
  }
120
137
  for (const key in options.style) {
121
- if (!key || !options.style) {
138
+ if (!key || !options.style || !Object.prototype.hasOwnProperty.call(options.style, key)) {
122
139
  continue;
123
140
  }
124
141
  const value = options.style[key];
@@ -133,7 +150,7 @@ export class Canvas {
133
150
  if (!trail.enable) {
134
151
  return;
135
152
  }
136
- const factorNumerator = 1, opacity = factorNumerator / trail.length;
153
+ const opacity = inverseFactorNumerator / trail.length;
137
154
  if (trailFill.color) {
138
155
  const fillColor = rangeColorToRgb(this._engine, trailFill.color);
139
156
  if (!fillColor) {
@@ -189,10 +206,10 @@ export class Canvas {
189
206
  };
190
207
  this._resetOriginalStyle = () => {
191
208
  const element = this.element, originalStyle = this._originalStyle;
192
- if (!(element && originalStyle)) {
209
+ if (!element || !originalStyle) {
193
210
  return;
194
211
  }
195
- setStyle(element, originalStyle);
212
+ setStyle(element, originalStyle, true);
196
213
  };
197
214
  this._safeMutationObserver = callback => {
198
215
  if (!this._mutationObserver) {
@@ -205,16 +222,7 @@ export class Canvas {
205
222
  if (!element) {
206
223
  return;
207
224
  }
208
- const radix = 10, zIndex = this.container.actualOptions.fullScreen.zIndex.toString(radix);
209
- setStyle(element, {
210
- position: "fixed",
211
- "z-index": zIndex,
212
- zIndex: zIndex,
213
- top: "0",
214
- left: "0",
215
- width: "100%",
216
- height: "100%",
217
- }, true);
225
+ setStyle(element, getFullScreenStyle(this.container.actualOptions.fullScreen.zIndex), true);
218
226
  };
219
227
  this._engine = engine;
220
228
  this._standardSize = {
@@ -237,7 +245,7 @@ export class Canvas {
237
245
  return this.container.actualOptions.fullScreen.enable;
238
246
  }
239
247
  clear() {
240
- const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill, minimumLength = 0;
248
+ const options = this.container.actualOptions, trail = options.particles.move.trail, trailFill = this._trailFill;
241
249
  if (options.backgroundMask.enable) {
242
250
  this.paint();
243
251
  }
@@ -260,6 +268,7 @@ export class Canvas {
260
268
  if (this._generated) {
261
269
  const element = this.element;
262
270
  element?.remove();
271
+ this.element = undefined;
263
272
  }
264
273
  else {
265
274
  this._resetOriginalStyle();
@@ -287,7 +296,7 @@ export class Canvas {
287
296
  if (particle.spawning || particle.destroyed) {
288
297
  return;
289
298
  }
290
- const radius = particle.getRadius(), minimumSize = 0;
299
+ const radius = particle.getRadius();
291
300
  if (radius <= minimumSize) {
292
301
  return;
293
302
  }
@@ -303,7 +312,7 @@ export class Canvas {
303
312
  return;
304
313
  }
305
314
  this.draw((ctx) => {
306
- 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 = {
315
+ const container = this.container, options = container.actualOptions, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = particle.bubble.opacity ?? particle.opacity?.value ?? defaultOpacity, strokeOpacity = particle.strokeOpacity ?? opacity, zOpacity = opacity * zOpacityFactor, zStrokeOpacity = strokeOpacity * zOpacityFactor, transform = {}, colorStyles = {
307
316
  fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined,
308
317
  };
309
318
  colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
@@ -413,7 +422,7 @@ export class Canvas {
413
422
  : this._generated;
414
423
  this.element = canvas;
415
424
  this.element.ariaHidden = "true";
416
- this._originalStyle = deepExtend({}, this.element.style);
425
+ this._originalStyle = cloneStyle(this.element.style);
417
426
  const standardSize = this._standardSize;
418
427
  standardSize.height = canvas.offsetHeight;
419
428
  standardSize.width = canvas.offsetWidth;
@@ -421,14 +430,15 @@ export class Canvas {
421
430
  canvas.height = retinaSize.height = standardSize.height * pxRatio;
422
431
  canvas.width = retinaSize.width = standardSize.width * pxRatio;
423
432
  this._context = this.element.getContext("2d");
433
+ this._safeMutationObserver(obs => obs.disconnect());
434
+ this.container.retina.init();
435
+ this.initBackground();
424
436
  this._safeMutationObserver(obs => {
425
437
  if (!this.element || !(this.element instanceof Node)) {
426
438
  return;
427
439
  }
428
440
  obs.observe(this.element, { attributes: true });
429
441
  });
430
- this.container.retina.init();
431
- this.initBackground();
432
442
  }
433
443
  paint() {
434
444
  const options = this.container.actualOptions;
@@ -1,5 +1,5 @@
1
1
  import { animate, cancelAnimation, getRangeValue } from "../Utils/NumberUtils.js";
2
- import { errorPrefix, millisecondsToSeconds } from "./Utils/Constants.js";
2
+ import { clickRadius, defaultFps, defaultFpsLimit, errorPrefix, millisecondsToSeconds, minCoordinate, minFpsLimit, removeDeleteCount, removeMinIndex, touchEndLengthOffset, } from "./Utils/Constants.js";
3
3
  import { getLogger, safeIntersectionObserver } from "../Utils/Utils.js";
4
4
  import { Canvas } from "./Canvas.js";
5
5
  import { EventListeners } from "./Utils/EventListeners.js";
@@ -11,7 +11,6 @@ import { loadOptions } from "../Utils/OptionsUtils.js";
11
11
  function guardCheck(container) {
12
12
  return container && !container.destroyed;
13
13
  }
14
- const defaultFps = 60;
15
14
  function initDelta(value, fpsLimit = defaultFps, smooth = false) {
16
15
  return {
17
16
  value,
@@ -139,8 +138,8 @@ export class Container {
139
138
  const mouseEvent = e, pos = {
140
139
  x: mouseEvent.offsetX || mouseEvent.clientX,
141
140
  y: mouseEvent.offsetY || mouseEvent.clientY,
142
- }, radius = 1;
143
- clickOrTouchHandler(e, pos, radius);
141
+ };
142
+ clickOrTouchHandler(e, pos, clickRadius);
144
143
  }, touchStartHandler = () => {
145
144
  if (!guardCheck(this)) {
146
145
  return;
@@ -157,15 +156,15 @@ export class Container {
157
156
  return;
158
157
  }
159
158
  if (touched && !touchMoved) {
160
- const touchEvent = e, lengthOffset = 1;
161
- let lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset];
159
+ const touchEvent = e;
160
+ let lastTouch = touchEvent.touches[touchEvent.touches.length - touchEndLengthOffset];
162
161
  if (!lastTouch) {
163
- lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - lengthOffset];
162
+ lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - touchEndLengthOffset];
164
163
  if (!lastTouch) {
165
164
  return;
166
165
  }
167
166
  }
168
- const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, minCoordinate = 0, pos = {
167
+ const element = this.canvas.element, canvasRect = element ? element.getBoundingClientRect() : undefined, pos = {
169
168
  x: lastTouch.clientX - (canvasRect ? canvasRect.left : minCoordinate),
170
169
  y: lastTouch.clientY - (canvasRect ? canvasRect.top : minCoordinate),
171
170
  };
@@ -235,10 +234,9 @@ export class Container {
235
234
  this._engine.clearPlugins(this);
236
235
  this.destroyed = true;
237
236
  if (remove) {
238
- const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this), minIndex = 0;
239
- if (idx >= minIndex) {
240
- const deleteCount = 1;
241
- mainArr.splice(idx, deleteCount);
237
+ const mainArr = this._engine.items, idx = mainArr.findIndex(t => t === this);
238
+ if (idx >= removeMinIndex) {
239
+ mainArr.splice(idx, removeDeleteCount);
242
240
  }
243
241
  }
244
242
  this._engine.dispatchEvent(EventType.containerDestroyed, { container: this });
@@ -314,7 +312,6 @@ export class Container {
314
312
  this._duration = getRangeValue(duration) * millisecondsToSeconds;
315
313
  this._delay = getRangeValue(delay) * millisecondsToSeconds;
316
314
  this._lifeTime = 0;
317
- const defaultFpsLimit = 120, minFpsLimit = 0;
318
315
  this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
319
316
  this._smooth = smooth;
320
317
  for (const drawer of this.effectDrawers.values()) {