@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
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Particle = void 0;
4
4
  const Vectors_js_1 = require("./Utils/Vectors.js");
5
5
  const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
6
- const Utils_js_1 = require("../Utils/Utils.js");
7
6
  const Constants_js_1 = require("./Utils/Constants.js");
7
+ const Utils_js_1 = require("../Utils/Utils.js");
8
8
  const ColorUtils_js_1 = require("../Utils/ColorUtils.js");
9
9
  const EventType_js_1 = require("../Enums/Types/EventType.js");
10
10
  const Interactivity_js_1 = require("../Options/Classes/Interactivity/Interactivity.js");
@@ -14,7 +14,6 @@ const ParticleOutType_js_1 = require("../Enums/Types/ParticleOutType.js");
14
14
  const PixelMode_js_1 = require("../Enums/Modes/PixelMode.js");
15
15
  const CanvasUtils_js_1 = require("../Utils/CanvasUtils.js");
16
16
  const OptionsUtils_js_1 = require("../Utils/OptionsUtils.js");
17
- const defaultRetryCount = 0, double = 2, half = 0.5, squareExp = 2, randomString = "random";
18
17
  function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
19
18
  const effectData = effectOptions.options[effect];
20
19
  if (!effectData) {
@@ -39,7 +38,7 @@ function fixOutMode(data) {
39
38
  if (!(0, Utils_js_1.isInArray)(data.outMode, data.checkModes)) {
40
39
  return;
41
40
  }
42
- const diameter = data.radius * double;
41
+ const diameter = data.radius * Constants_js_1.double;
43
42
  if (data.coord > data.maxCoord - diameter) {
44
43
  data.setCb(-data.radius);
45
44
  }
@@ -50,7 +49,7 @@ function fixOutMode(data) {
50
49
  class Particle {
51
50
  constructor(engine, container) {
52
51
  this.container = container;
53
- this._calcPosition = (container, position, zIndex, tryCount = defaultRetryCount) => {
52
+ this._calcPosition = (container, position, zIndex, tryCount = Constants_js_1.defaultRetryCount) => {
54
53
  for (const plugin of container.plugins.values()) {
55
54
  const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
56
55
  if (pluginPos) {
@@ -84,8 +83,7 @@ class Particle {
84
83
  fixVertical(outModes.top ?? outModes.default);
85
84
  fixVertical(outModes.bottom ?? outModes.default);
86
85
  if (this._checkOverlap(pos, tryCount)) {
87
- const increment = 1;
88
- return this._calcPosition(container, undefined, zIndex, tryCount + increment);
86
+ return this._calcPosition(container, undefined, zIndex, tryCount + Constants_js_1.tryCountIncrement);
89
87
  }
90
88
  return pos;
91
89
  };
@@ -95,8 +93,8 @@ class Particle {
95
93
  return res;
96
94
  }
97
95
  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 = {
98
- left: radOffset - rad * half,
99
- right: radOffset + rad * half,
96
+ left: radOffset - rad * Constants_js_1.half,
97
+ right: radOffset + rad * Constants_js_1.half,
100
98
  };
101
99
  if (!moveOptions.straight) {
102
100
  res.angle += (0, NumberUtils_js_1.randomInRange)((0, NumberUtils_js_1.setRangeValue)(range.left, range.right));
@@ -106,7 +104,7 @@ class Particle {
106
104
  }
107
105
  return res;
108
106
  };
109
- this._checkOverlap = (pos, tryCount = defaultRetryCount) => {
107
+ this._checkOverlap = (pos, tryCount = Constants_js_1.defaultRetryCount) => {
110
108
  const collisionsOptions = this.options.collisions, radius = this.getRadius();
111
109
  if (!collisionsOptions.enable) {
112
110
  return false;
@@ -115,8 +113,8 @@ class Particle {
115
113
  if (overlapOptions.enable) {
116
114
  return false;
117
115
  }
118
- const retries = overlapOptions.retries, minRetries = 0;
119
- if (retries >= minRetries && tryCount > retries) {
116
+ const retries = overlapOptions.retries;
117
+ if (retries >= Constants_js_1.minRetries && tryCount > retries) {
120
118
  throw new Error(`${Constants_js_1.errorPrefix} particle is overlapping and can't be placed`);
121
119
  }
122
120
  return !!this.container.particles.find(particle => (0, NumberUtils_js_1.getDistance)(pos, particle.position) < radius + particle.getRadius());
@@ -125,7 +123,7 @@ class Particle {
125
123
  if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
126
124
  return color;
127
125
  }
128
- 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;
126
+ 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;
129
127
  if (!rolled) {
130
128
  return color;
131
129
  }
@@ -138,13 +136,13 @@ class Particle {
138
136
  return color;
139
137
  };
140
138
  this._initPosition = position => {
141
- const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value), minZ = 0;
142
- this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, minZ, container.zLayers));
139
+ const container = this.container, zIndexValue = (0, NumberUtils_js_1.getRangeValue)(this.options.zIndex.value);
140
+ this.position = this._calcPosition(container, position, (0, NumberUtils_js_1.clamp)(zIndexValue, Constants_js_1.minZ, container.zLayers));
143
141
  this.initialPosition = this.position.copy();
144
- const canvasSize = container.canvas.size, defaultRadius = 0;
142
+ const canvasSize = container.canvas.size;
145
143
  this.moveCenter = {
146
144
  ...(0, Utils_js_1.getPosition)(this.options.move.center, canvasSize),
147
- radius: this.options.move.center.radius ?? defaultRadius,
145
+ radius: this.options.move.center.radius ?? Constants_js_1.defaultRadius,
148
146
  mode: this.options.move.center.mode ?? PixelMode_js_1.PixelMode.percent,
149
147
  };
150
148
  this.direction = (0, NumberUtils_js_1.getParticleDirectionAngle)(this.options.move.direction, this.position, this.moveCenter);
@@ -194,7 +192,7 @@ class Particle {
194
192
  return this._getRollColor(this.bubble.color ?? (0, ColorUtils_js_1.getHslFromAnimation)(this.color));
195
193
  }
196
194
  getMass() {
197
- return this.getRadius() ** squareExp * Math.PI * half;
195
+ return this.getRadius() ** Constants_js_1.squareExp * Math.PI * Constants_js_1.half;
198
196
  }
199
197
  getPosition() {
200
198
  return {
@@ -249,11 +247,11 @@ class Particle {
249
247
  }
250
248
  }
251
249
  }
252
- if (this.effect === randomString) {
250
+ if (this.effect === Constants_js_1.randomColorValue) {
253
251
  const availableEffects = [...this.container.effectDrawers.keys()];
254
252
  this.effect = availableEffects[Math.floor(Math.random() * availableEffects.length)];
255
253
  }
256
- if (this.shape === randomString) {
254
+ if (this.shape === Constants_js_1.randomColorValue) {
257
255
  const availableShapes = [...this.container.shapeDrawers.keys()];
258
256
  this.shape = availableShapes[Math.floor(Math.random() * availableShapes.length)];
259
257
  }
@@ -297,8 +295,7 @@ class Particle {
297
295
  this._initPosition(position);
298
296
  this.initialVelocity = this._calculateVelocity();
299
297
  this.velocity = this.initialVelocity.copy();
300
- const decayOffset = 1;
301
- this.moveDecay = decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
298
+ this.moveDecay = Constants_js_1.decayOffset - (0, NumberUtils_js_1.getRangeValue)(this.options.move.decay);
302
299
  const particles = container.particles;
303
300
  particles.setLastZIndex(this.position.z);
304
301
  this.zIndexFactor = this.position.z / container.zLayers;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Particles = void 0;
4
+ const Constants_js_1 = require("./Utils/Constants.js");
4
5
  const Utils_js_1 = require("../Utils/Utils.js");
5
6
  const EventType_js_1 = require("../Enums/Types/EventType.js");
6
7
  const InteractionManager_js_1 = require("./Utils/InteractionManager.js");
@@ -9,11 +10,9 @@ const Particle_js_1 = require("./Particle.js");
9
10
  const Point_js_1 = require("./Utils/Point.js");
10
11
  const QuadTree_js_1 = require("./Utils/QuadTree.js");
11
12
  const Ranges_js_1 = require("./Utils/Ranges.js");
12
- const Constants_js_1 = require("./Utils/Constants.js");
13
- const qTreeCapacity = 4, squareExp = 2, defaultRemoveQuantity = 1;
14
13
  const qTreeRectangle = (canvasSize) => {
15
- const { height, width } = canvasSize, posOffset = -0.25, sizeFactor = 1.5;
16
- return new Ranges_js_1.Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
14
+ const { height, width } = canvasSize;
15
+ 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);
17
16
  };
18
17
  class Particles {
19
18
  constructor(engine, container) {
@@ -31,7 +30,7 @@ class Particles {
31
30
  }
32
31
  return;
33
32
  }
34
- 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);
33
+ 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);
35
34
  if (group === undefined) {
36
35
  this._limit = numberOptions.limit.value * densityFactor;
37
36
  }
@@ -46,12 +45,12 @@ class Particles {
46
45
  }
47
46
  };
48
47
  this._initDensityFactor = densityOptions => {
49
- const container = this._container, defaultFactor = 1;
48
+ const container = this._container;
50
49
  if (!container.canvas.element || !densityOptions.enable) {
51
- return defaultFactor;
50
+ return Constants_js_1.defaultDensityFactor;
52
51
  }
53
52
  const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
54
- return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
53
+ return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** Constants_js_1.squareExp);
55
54
  };
56
55
  this._pushParticle = (position, overrideOptions, group, initializer) => {
57
56
  try {
@@ -87,9 +86,9 @@ class Particles {
87
86
  if (!particle || particle.group !== group) {
88
87
  return false;
89
88
  }
90
- const zIdx = this._zArray.indexOf(particle), deleteCount = 1;
91
- this._array.splice(index, deleteCount);
92
- this._zArray.splice(zIdx, deleteCount);
89
+ const zIdx = this._zArray.indexOf(particle);
90
+ this._array.splice(index, Constants_js_1.deleteCount);
91
+ this._zArray.splice(zIdx, Constants_js_1.deleteCount);
93
92
  particle.destroy(override);
94
93
  this._engine.dispatchEvent(EventType_js_1.EventType.particleRemoved, {
95
94
  container: this._container,
@@ -113,7 +112,7 @@ class Particles {
113
112
  this._interactionManager = new InteractionManager_js_1.InteractionManager(engine, container);
114
113
  this._pluginsInitialized = false;
115
114
  const canvasSize = container.canvas.size;
116
- this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
115
+ this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(canvasSize), Constants_js_1.qTreeCapacity);
117
116
  this.movers = [];
118
117
  this.updaters = [];
119
118
  }
@@ -125,12 +124,12 @@ class Particles {
125
124
  options.manualParticles.forEach(p => this.addParticle(p.position ? (0, Utils_js_1.getPosition)(p.position, container.canvas.size) : undefined, p.options));
126
125
  }
127
126
  addParticle(position, overrideOptions, group, initializer) {
128
- 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;
129
- if (limit > minLimit) {
127
+ const limitMode = this._container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this._limit : (this._groupLimits.get(group) ?? this._limit), currentCount = this.count;
128
+ if (limit > Constants_js_1.minLimit) {
130
129
  switch (limitMode) {
131
130
  case LimitMode_js_1.LimitMode.delete: {
132
- const countOffset = 1, minCount = 0, countToRemove = currentCount + countOffset - limit;
133
- if (countToRemove > minCount) {
131
+ const countToRemove = currentCount + Constants_js_1.countOffset - limit;
132
+ if (countToRemove > Constants_js_1.minCount) {
134
133
  this.removeQuantity(countToRemove);
135
134
  }
136
135
  break;
@@ -229,9 +228,8 @@ class Particles {
229
228
  remove(particle, group, override) {
230
229
  this.removeAt(this._array.indexOf(particle), undefined, group, override);
231
230
  }
232
- removeAt(index, quantity = defaultRemoveQuantity, group, override) {
233
- const minIndex = 0;
234
- if (index < minIndex || index > this.count) {
231
+ removeAt(index, quantity = Constants_js_1.defaultRemoveQuantity, group, override) {
232
+ if (index < Constants_js_1.minIndex || index > this.count) {
235
233
  return;
236
234
  }
237
235
  let deleted = 0;
@@ -243,13 +241,12 @@ class Particles {
243
241
  }
244
242
  }
245
243
  removeQuantity(quantity, group) {
246
- const defaultIndex = 0;
247
- this.removeAt(defaultIndex, quantity, group);
244
+ this.removeAt(Constants_js_1.minIndex, quantity, group);
248
245
  }
249
246
  setDensity() {
250
- const options = this._container.actualOptions, groups = options.particles.groups, manualCount = 0;
247
+ const options = this._container.actualOptions, groups = options.particles.groups;
251
248
  for (const group in groups) {
252
- this._applyDensity(groups[group], manualCount, group);
249
+ this._applyDensity(groups[group], Constants_js_1.manualCount, group);
253
250
  }
254
251
  this._applyDensity(options.particles, options.manualParticles.length);
255
252
  }
@@ -262,7 +259,7 @@ class Particles {
262
259
  }
263
260
  update(delta) {
264
261
  const container = this._container, particlesToDelete = new Set();
265
- this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
262
+ this.quadTree = new QuadTree_js_1.QuadTree(qTreeRectangle(container.canvas.size), Constants_js_1.qTreeCapacity);
266
263
  for (const pathGenerator of container.pathGenerators.values()) {
267
264
  pathGenerator.update();
268
265
  }
@@ -323,8 +320,7 @@ class Particles {
323
320
  if (this._needsSort) {
324
321
  const zArray = this._zArray;
325
322
  zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
326
- const lengthOffset = 1;
327
- this._lastZIndex = zArray[zArray.length - lengthOffset].position.z;
323
+ this._lastZIndex = zArray[zArray.length - Constants_js_1.lengthOffset].position.z;
328
324
  this._needsSort = false;
329
325
  }
330
326
  }
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Retina = void 0;
4
+ const Constants_js_1 = require("./Utils/Constants.js");
4
5
  const NumberUtils_js_1 = require("../Utils/NumberUtils.js");
5
6
  const Utils_js_1 = require("../Utils/Utils.js");
6
- const defaultRatio = 1, defaultReduceFactor = 1;
7
7
  class Retina {
8
8
  constructor(container) {
9
9
  this.container = container;
10
- this.pixelRatio = defaultRatio;
11
- this.reduceFactor = defaultReduceFactor;
10
+ this.pixelRatio = Constants_js_1.defaultRatio;
11
+ this.reduceFactor = Constants_js_1.defaultReduceFactor;
12
12
  }
13
13
  init() {
14
14
  const container = this.container, options = container.actualOptions;
15
- this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ? defaultRatio : window.devicePixelRatio;
16
- this.reduceFactor = defaultReduceFactor;
15
+ this.pixelRatio = !options.detectRetina || (0, Utils_js_1.isSsr)() ? Constants_js_1.defaultRatio : window.devicePixelRatio;
16
+ this.reduceFactor = Constants_js_1.defaultReduceFactor;
17
17
  const ratio = this.pixelRatio, canvas = container.canvas;
18
18
  if (canvas.element) {
19
19
  const element = canvas.element;
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.millisecondsToSeconds = exports.halfRandom = exports.percentDenominator = exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
4
- exports.generatedAttribute = "generated";
5
- exports.mouseDownEvent = "pointerdown";
6
- exports.mouseUpEvent = "pointerup";
7
- exports.mouseLeaveEvent = "pointerleave";
8
- exports.mouseOutEvent = "pointerout";
9
- exports.mouseMoveEvent = "pointermove";
10
- exports.touchStartEvent = "touchstart";
11
- exports.touchEndEvent = "touchend";
12
- exports.touchMoveEvent = "touchmove";
13
- exports.touchCancelEvent = "touchcancel";
14
- exports.resizeEvent = "resize";
15
- exports.visibilityChangeEvent = "visibilitychange";
16
- exports.errorPrefix = "tsParticles - Error";
17
- exports.percentDenominator = 100;
18
- exports.halfRandom = 0.5;
19
- exports.millisecondsToSeconds = 1000;
3
+ exports.zIndexFactorOffset = exports.minimumLength = exports.minimumSize = exports.defaultTransformValue = exports.minVelocity = exports.threeQuarter = exports.quarter = exports.empty = exports.hPhase = exports.sMin = exports.hMin = exports.lMax = exports.sMax = exports.hMax = exports.rgbMax = exports.inverseFactorNumerator = exports.subdivideCount = exports.defaultReduceFactor = exports.defaultRatio = exports.defaultRemoveQuantity = exports.qTreeCapacity = exports.squareExp = exports.defaultRetryCount = exports.canvasTag = exports.generatedFalse = exports.generatedTrue = exports.defaultAlpha = exports.defaultFps = exports.doublePI = exports.double = exports.midColorValue = exports.randomColorValue = exports.defaultTransform = exports.originPoint = exports.millisecondsToSeconds = exports.half = exports.percentDenominator = exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
4
+ exports.defaultTime = exports.defaultLoops = exports.defaultVelocity = exports.defaultRgbMin = exports.phaseNumerator = exports.sNormalizedOffset = exports.sextuple = exports.triple = exports.rgbFactor = exports.lMin = exports.lFactor = exports.minStrokeWidth = exports.identity = exports.defaultAngle = exports.manualDefaultPosition = exports.touchDelay = exports.deleteCount = exports.defaultDensityFactor = exports.lengthOffset = exports.manualCount = exports.minIndex = exports.minCount = exports.countOffset = exports.minLimit = exports.sizeFactor = exports.posOffset = exports.defaultRadius = exports.minZ = exports.rollFactor = exports.minRetries = exports.tryCountIncrement = exports.decayOffset = exports.none = exports.one = exports.loadMinIndex = exports.loadRandomFactor = exports.canvasFirstIndex = exports.minFpsLimit = exports.defaultFpsLimit = exports.removeMinIndex = exports.removeDeleteCount = exports.minCoordinate = exports.touchEndLengthOffset = exports.clickRadius = exports.defaultOpacity = void 0;
5
+ exports.generatedAttribute = "generated", exports.mouseDownEvent = "pointerdown", exports.mouseUpEvent = "pointerup", exports.mouseLeaveEvent = "pointerleave", exports.mouseOutEvent = "pointerout", exports.mouseMoveEvent = "pointermove", exports.touchStartEvent = "touchstart", exports.touchEndEvent = "touchend", exports.touchMoveEvent = "touchmove", exports.touchCancelEvent = "touchcancel", exports.resizeEvent = "resize", exports.visibilityChangeEvent = "visibilitychange", exports.errorPrefix = "tsParticles - Error", exports.percentDenominator = 100, exports.half = 0.5, exports.millisecondsToSeconds = 1000, exports.originPoint = {
6
+ x: 0,
7
+ y: 0,
8
+ z: 0,
9
+ }, exports.defaultTransform = {
10
+ a: 1,
11
+ b: 0,
12
+ c: 0,
13
+ d: 1,
14
+ }, exports.randomColorValue = "random", exports.midColorValue = "mid", exports.double = 2, exports.doublePI = Math.PI * exports.double, exports.defaultFps = 60, exports.defaultAlpha = 1, exports.generatedTrue = "true", exports.generatedFalse = "false", exports.canvasTag = "canvas", exports.defaultRetryCount = 0, exports.squareExp = 2, exports.qTreeCapacity = 4, exports.defaultRemoveQuantity = 1, exports.defaultRatio = 1, exports.defaultReduceFactor = 1, exports.subdivideCount = 4, exports.inverseFactorNumerator = 1.0, exports.rgbMax = 255, exports.hMax = 360, exports.sMax = 100, exports.lMax = 100, exports.hMin = 0, exports.sMin = 0, exports.hPhase = 60, exports.empty = 0, exports.quarter = 0.25, exports.threeQuarter = exports.half + exports.quarter, exports.minVelocity = 0, exports.defaultTransformValue = 1, exports.minimumSize = 0, exports.minimumLength = 0, exports.zIndexFactorOffset = 1, exports.defaultOpacity = 1, exports.clickRadius = 1, exports.touchEndLengthOffset = 1, exports.minCoordinate = 0, exports.removeDeleteCount = 1, exports.removeMinIndex = 0, exports.defaultFpsLimit = 120, exports.minFpsLimit = 0, exports.canvasFirstIndex = 0, exports.loadRandomFactor = 10000, exports.loadMinIndex = 0, exports.one = 1, exports.none = 0, exports.decayOffset = 1, exports.tryCountIncrement = 1, exports.minRetries = 0, exports.rollFactor = 1, exports.minZ = 0, exports.defaultRadius = 0, exports.posOffset = -exports.quarter, exports.sizeFactor = 1.5, exports.minLimit = 0, exports.countOffset = 1, exports.minCount = 0, exports.minIndex = 0, exports.manualCount = 0, exports.lengthOffset = 1, exports.defaultDensityFactor = 1, exports.deleteCount = 1, exports.touchDelay = 500, exports.manualDefaultPosition = 50, exports.defaultAngle = 0, exports.identity = 1, exports.minStrokeWidth = 0, exports.lFactor = 1, exports.lMin = 0, exports.rgbFactor = 255, exports.triple = 3, exports.sextuple = 6, exports.sNormalizedOffset = 1, exports.phaseNumerator = 1, exports.defaultRgbMin = 0, exports.defaultVelocity = 0, exports.defaultLoops = 0, exports.defaultTime = 0;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventListeners = void 0;
4
- const Utils_js_1 = require("../../Utils/Utils.js");
5
4
  const Constants_js_1 = require("./Constants.js");
5
+ const Utils_js_1 = require("../../Utils/Utils.js");
6
6
  const InteractivityDetect_js_1 = require("../../Enums/InteractivityDetect.js");
7
7
  const TypeUtils_js_1 = require("../../Utils/TypeUtils.js");
8
- const double = 2;
9
8
  function manageListener(element, event, handler, add, options) {
10
9
  if (add) {
11
10
  let addOptions = { passive: true };
@@ -38,8 +37,7 @@ class EventListeners {
38
37
  (0, Utils_js_1.executeOnSingleOrMultiple)(onClick.mode, mode => this.container.handleClickMode(mode));
39
38
  }
40
39
  if (e.type === "touchend") {
41
- const touchDelay = 500;
42
- setTimeout(() => this._mouseTouchFinish(), touchDelay);
40
+ setTimeout(() => this._mouseTouchFinish(), Constants_js_1.touchDelay);
43
41
  }
44
42
  };
45
43
  this._handleThemeChange = (e) => {
@@ -80,8 +78,7 @@ class EventListeners {
80
78
  this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * Constants_js_1.millisecondsToSeconds);
81
79
  };
82
80
  this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
83
- const handlers = this._handlers, container = this.container, options = container.actualOptions;
84
- const interactivityEl = container.interactivity.element;
81
+ const handlers = this._handlers, container = this.container, options = container.actualOptions, interactivityEl = container.interactivity.element;
85
82
  if (!interactivityEl) {
86
83
  return;
87
84
  }
@@ -241,8 +238,8 @@ class EventListeners {
241
238
  if (source && target && canvasEl) {
242
239
  const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
243
240
  pos = {
244
- x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
245
- y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
241
+ x: mouseEvent.offsetX + Constants_js_1.double * sourceRect.left - (targetRect.left + canvasRect.left),
242
+ y: mouseEvent.offsetY + Constants_js_1.double * sourceRect.top - (targetRect.top + canvasRect.top),
246
243
  };
247
244
  }
248
245
  else {
@@ -262,10 +259,10 @@ class EventListeners {
262
259
  else {
263
260
  this._canPush = e.type !== "touchmove";
264
261
  if (canvasEl) {
265
- const touchEvent = e, lengthOffset = 1, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect(), defaultCoordinate = 0;
262
+ const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - Constants_js_1.lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
266
263
  pos = {
267
- x: lastTouch.clientX - (canvasRect.left ?? defaultCoordinate),
268
- y: lastTouch.clientY - (canvasRect.top ?? defaultCoordinate),
264
+ x: lastTouch.clientX - (canvasRect.left ?? Constants_js_1.minCoordinate),
265
+ y: lastTouch.clientY - (canvasRect.top ?? Constants_js_1.minCoordinate),
269
266
  };
270
267
  }
271
268
  }
@@ -2,17 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuadTree = void 0;
4
4
  const Ranges_js_1 = require("./Ranges.js");
5
+ const Constants_js_1 = require("./Constants.js");
5
6
  const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
6
- const half = 0.5, double = 2, subdivideCount = 4;
7
7
  class QuadTree {
8
8
  constructor(rectangle, capacity) {
9
9
  this.rectangle = rectangle;
10
10
  this.capacity = capacity;
11
11
  this._subdivide = () => {
12
12
  const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
13
- for (let i = 0; i < subdivideCount; i++) {
14
- const fixedIndex = i % double;
15
- this._subs.push(new QuadTree(new Ranges_js_1.Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));
13
+ for (let i = 0; i < Constants_js_1.subdivideCount; i++) {
14
+ const fixedIndex = i % Constants_js_1.double;
15
+ this._subs.push(new QuadTree(new Ranges_js_1.Rectangle(x + width * Constants_js_1.half * fixedIndex, y + height * Constants_js_1.half * (Math.round(i * Constants_js_1.half) - fixedIndex), width * Constants_js_1.half, height * Constants_js_1.half), capacity));
16
16
  }
17
17
  this._divided = true;
18
18
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Rectangle = exports.Circle = exports.BaseRange = void 0;
4
4
  const RangeType_js_1 = require("../../Types/RangeType.js");
5
5
  const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
6
- const squareExp = 2;
6
+ const Constants_js_1 = require("./Constants.js");
7
7
  class BaseRange {
8
8
  constructor(x, y, type) {
9
9
  this.position = {
@@ -25,12 +25,12 @@ class Circle extends BaseRange {
25
25
  intersects(range) {
26
26
  const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
27
27
  if (range instanceof Circle || range.type === RangeType_js_1.RangeType.circle) {
28
- const circleRange = range, rSum = r + circleRange.radius, dist = Math.sqrt(distPos.x ** squareExp + distPos.y ** squareExp);
28
+ const circleRange = range, rSum = r + circleRange.radius, dist = Math.sqrt(distPos.x ** Constants_js_1.squareExp + distPos.y ** Constants_js_1.squareExp);
29
29
  return rSum > dist;
30
30
  }
31
31
  else if (range instanceof Rectangle || range.type === RangeType_js_1.RangeType.rectangle) {
32
- const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(distPos.x - width, squareExp) + Math.pow(distPos.y - height, squareExp);
33
- return (edges <= r ** squareExp ||
32
+ const rectRange = range, { width, height } = rectRange.size, edges = Math.pow(distPos.x - width, Constants_js_1.squareExp) + Math.pow(distPos.y - height, Constants_js_1.squareExp);
33
+ return (edges <= r ** Constants_js_1.squareExp ||
34
34
  (distPos.x <= r + width && distPos.y <= r + height) ||
35
35
  distPos.x <= width ||
36
36
  distPos.y <= height);
@@ -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
  }