@tsparticles/engine 3.7.0 → 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 +51 -36
  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 +52 -37
  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 +51 -36
  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 +53 -38
  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
@@ -3,11 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vector = exports.Vector3d = void 0;
4
4
  const Constants_js_1 = require("./Constants.js");
5
5
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
6
- const origin = {
7
- x: 0,
8
- y: 0,
9
- z: 0,
10
- }, squareExp = 2, inverseFactorNumerator = 1.0;
11
6
  class Vector3d {
12
7
  constructor(xOrCoords, y, z) {
13
8
  this._updateFromAngle = (angle, length) => {
@@ -18,19 +13,19 @@ class Vector3d {
18
13
  this.x = xOrCoords.x;
19
14
  this.y = xOrCoords.y;
20
15
  const coords3d = xOrCoords;
21
- this.z = coords3d.z ? coords3d.z : origin.z;
16
+ this.z = coords3d.z ? coords3d.z : Constants_js_1.originPoint.z;
22
17
  }
23
18
  else if (xOrCoords !== undefined && y !== undefined) {
24
19
  this.x = xOrCoords;
25
20
  this.y = y;
26
- this.z = z ?? origin.z;
21
+ this.z = z ?? Constants_js_1.originPoint.z;
27
22
  }
28
23
  else {
29
24
  throw new Error(`${Constants_js_1.errorPrefix} Vector3d not initialized correctly`);
30
25
  }
31
26
  }
32
27
  static get origin() {
33
- return Vector3d.create(origin.x, origin.y, origin.z);
28
+ return Vector3d.create(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, Constants_js_1.originPoint.z);
34
29
  }
35
30
  get angle() {
36
31
  return Math.atan2(this.y, this.x);
@@ -76,7 +71,7 @@ class Vector3d {
76
71
  this.z /= n;
77
72
  }
78
73
  getLengthSq() {
79
- return this.x ** squareExp + this.y ** squareExp;
74
+ return this.x ** Constants_js_1.squareExp + this.y ** Constants_js_1.squareExp;
80
75
  }
81
76
  mult(n) {
82
77
  return Vector3d.create(this.x * n, this.y * n, this.z * n);
@@ -87,19 +82,19 @@ class Vector3d {
87
82
  this.z *= n;
88
83
  }
89
84
  normalize() {
90
- const length = this.length, noLength = 0;
91
- if (length != noLength) {
92
- this.multTo(inverseFactorNumerator / length);
85
+ const length = this.length;
86
+ if (length != Constants_js_1.none) {
87
+ this.multTo(Constants_js_1.inverseFactorNumerator / length);
93
88
  }
94
89
  }
95
90
  rotate(angle) {
96
- return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle), origin.z);
91
+ return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle), Constants_js_1.originPoint.z);
97
92
  }
98
93
  setTo(c) {
99
94
  this.x = c.x;
100
95
  this.y = c.y;
101
96
  const v3d = c;
102
- this.z = v3d.z ? v3d.z : origin.z;
97
+ this.z = v3d.z ? v3d.z : Constants_js_1.originPoint.z;
103
98
  }
104
99
  sub(v) {
105
100
  return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v.z);
@@ -113,10 +108,10 @@ class Vector3d {
113
108
  exports.Vector3d = Vector3d;
114
109
  class Vector extends Vector3d {
115
110
  constructor(xOrCoords, y) {
116
- super(xOrCoords, y, origin.z);
111
+ super(xOrCoords, y, Constants_js_1.originPoint.z);
117
112
  }
118
113
  static get origin() {
119
- return Vector.create(origin.x, origin.y);
114
+ return Vector.create(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y);
120
115
  }
121
116
  static clone(source) {
122
117
  return Vector.create(source.x, source.y);
@@ -4,7 +4,7 @@ exports.ManualParticle = void 0;
4
4
  const PixelMode_js_1 = require("../../Enums/Modes/PixelMode.js");
5
5
  const Utils_js_1 = require("../../Utils/Utils.js");
6
6
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
7
- const defaultPosition = 50;
7
+ const Constants_js_1 = require("../../Core/Utils/Constants.js");
8
8
  class ManualParticle {
9
9
  load(data) {
10
10
  if ((0, TypeUtils_js_1.isNull)(data)) {
@@ -12,8 +12,8 @@ class ManualParticle {
12
12
  }
13
13
  if (data.position) {
14
14
  this.position = {
15
- x: data.position.x ?? defaultPosition,
16
- y: data.position.y ?? defaultPosition,
15
+ x: data.position.x ?? Constants_js_1.manualDefaultPosition,
16
+ y: data.position.y ?? Constants_js_1.manualDefaultPosition,
17
17
  mode: data.position.mode ?? PixelMode_js_1.PixelMode.percent,
18
18
  };
19
19
  }
@@ -11,14 +11,9 @@ exports.drawShapeAfterDraw = drawShapeAfterDraw;
11
11
  exports.drawPlugin = drawPlugin;
12
12
  exports.drawParticlePlugin = drawParticlePlugin;
13
13
  exports.alterHsl = alterHsl;
14
+ const Constants_js_1 = require("../Core/Utils/Constants.js");
14
15
  const AlterType_js_1 = require("../Enums/Types/AlterType.js");
15
16
  const ColorUtils_js_1 = require("./ColorUtils.js");
16
- const origin = { x: 0, y: 0 }, defaultTransform = {
17
- a: 1,
18
- b: 0,
19
- c: 0,
20
- d: 1,
21
- };
22
17
  function drawLine(context, begin, end) {
23
18
  context.beginPath();
24
19
  context.moveTo(begin.x, begin.y);
@@ -27,28 +22,28 @@ function drawLine(context, begin, end) {
27
22
  }
28
23
  function paintBase(context, dimension, baseColor) {
29
24
  context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
30
- context.fillRect(origin.x, origin.y, dimension.width, dimension.height);
25
+ context.fillRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
31
26
  }
32
27
  function paintImage(context, dimension, image, opacity) {
33
28
  if (!image) {
34
29
  return;
35
30
  }
36
31
  context.globalAlpha = opacity;
37
- context.drawImage(image, origin.x, origin.y, dimension.width, dimension.height);
32
+ context.drawImage(image, Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
38
33
  context.globalAlpha = 1;
39
34
  }
40
35
  function clear(context, dimension) {
41
- context.clearRect(origin.x, origin.y, dimension.width, dimension.height);
36
+ context.clearRect(Constants_js_1.originPoint.x, Constants_js_1.originPoint.y, dimension.width, dimension.height);
42
37
  }
43
38
  function drawParticle(data) {
44
- const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data, pos = particle.getPosition(), defaultAngle = 0, angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : defaultAngle), rotateData = {
39
+ const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data, pos = particle.getPosition(), angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : Constants_js_1.defaultAngle), rotateData = {
45
40
  sin: Math.sin(angle),
46
41
  cos: Math.cos(angle),
47
- }, rotating = !!angle, identity = 1, transformData = {
48
- a: rotateData.cos * (transform.a ?? defaultTransform.a),
49
- b: rotating ? rotateData.sin * (transform.b ?? identity) : (transform.b ?? defaultTransform.b),
50
- c: rotating ? -rotateData.sin * (transform.c ?? identity) : (transform.c ?? defaultTransform.c),
51
- d: rotateData.cos * (transform.d ?? defaultTransform.d),
42
+ }, rotating = !!angle, transformData = {
43
+ a: rotateData.cos * (transform.a ?? Constants_js_1.defaultTransform.a),
44
+ b: rotating ? rotateData.sin * (transform.b ?? Constants_js_1.identity) : (transform.b ?? Constants_js_1.defaultTransform.b),
45
+ c: rotating ? -rotateData.sin * (transform.c ?? Constants_js_1.identity) : (transform.c ?? Constants_js_1.defaultTransform.c),
46
+ d: rotateData.cos * (transform.d ?? Constants_js_1.defaultTransform.d),
52
47
  };
53
48
  context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
54
49
  if (backgroundMask) {
@@ -64,7 +59,7 @@ function drawParticle(data) {
64
59
  if (colorStyles.fill) {
65
60
  context.fillStyle = colorStyles.fill;
66
61
  }
67
- const minStrokeWidth = 0, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
62
+ const strokeWidth = particle.strokeWidth ?? Constants_js_1.minStrokeWidth;
68
63
  context.lineWidth = strokeWidth;
69
64
  if (colorStyles.stroke) {
70
65
  context.strokeStyle = colorStyles.stroke;
@@ -105,7 +100,7 @@ function drawEffect(data) {
105
100
  });
106
101
  }
107
102
  function drawShape(data) {
108
- const { container, context, particle, radius, opacity, delta, strokeWidth, transformData } = data, minStrokeWidth = 0;
103
+ const { container, context, particle, radius, opacity, delta, strokeWidth, transformData } = data;
109
104
  if (!particle.shape) {
110
105
  return;
111
106
  }
@@ -126,7 +121,7 @@ function drawShape(data) {
126
121
  if (particle.shapeClose) {
127
122
  context.closePath();
128
123
  }
129
- if (strokeWidth > minStrokeWidth) {
124
+ if (strokeWidth > Constants_js_1.minStrokeWidth) {
130
125
  context.stroke();
131
126
  }
132
127
  if (particle.shapeFill) {
@@ -165,10 +160,9 @@ function drawParticlePlugin(context, plugin, particle, delta) {
165
160
  plugin.drawParticle(context, particle, delta);
166
161
  }
167
162
  function alterHsl(color, type, value) {
168
- const lFactor = 1;
169
163
  return {
170
164
  h: color.h,
171
165
  s: color.s,
172
- l: color.l + (type === AlterType_js_1.AlterType.darken ? -lFactor : lFactor) * value,
166
+ l: color.l + (type === AlterType_js_1.AlterType.darken ? -Constants_js_1.lFactor : Constants_js_1.lFactor) * value,
173
167
  };
174
168
  }
@@ -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,46 @@ 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
+ top: "0",
496
+ left: "0",
497
+ };
498
+ for (const key in style) {
499
+ const value = style[key];
500
+ fullScreenStyle.setProperty(key, value);
452
501
  }
453
- throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
502
+ return fullScreenStyle;
454
503
  }
504
+ exports.getFullScreenStyle = memoize(computeFullScreenStyle);