@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
@@ -4,12 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "../Core/Utils/Constants.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EventDispatcher = void 0;
13
+ const Constants_js_1 = require("../Core/Utils/Constants.js");
13
14
  class EventDispatcher {
14
15
  constructor() {
15
16
  this._listeners = new Map();
@@ -43,16 +44,15 @@
43
44
  if (!arr) {
44
45
  return;
45
46
  }
46
- const length = arr.length, idx = arr.indexOf(listener), minIndex = 0;
47
- if (idx < minIndex) {
47
+ const length = arr.length, idx = arr.indexOf(listener);
48
+ if (idx < Constants_js_1.minIndex) {
48
49
  return;
49
50
  }
50
- const deleteCount = 1;
51
- if (length === deleteCount) {
51
+ if (length === Constants_js_1.deleteCount) {
52
52
  this._listeners.delete(type);
53
53
  }
54
54
  else {
55
- arr.splice(idx, deleteCount);
55
+ arr.splice(idx, Constants_js_1.deleteCount);
56
56
  }
57
57
  }
58
58
  }
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../Enums/Directions/MoveDirection.js", "../Core/Utils/Vectors.js", "./TypeUtils.js", "../Core/Utils/Constants.js"], factory);
7
+ define(["require", "exports", "../Enums/Directions/MoveDirection.js", "../Core/Utils/Constants.js", "../Core/Utils/Vectors.js", "./TypeUtils.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -34,14 +34,14 @@
34
34
  exports.calcExactPositionOrRandomFromSizeRanged = calcExactPositionOrRandomFromSizeRanged;
35
35
  exports.parseAlpha = parseAlpha;
36
36
  const MoveDirection_js_1 = require("../Enums/Directions/MoveDirection.js");
37
+ const Constants_js_1 = require("../Core/Utils/Constants.js");
37
38
  const Vectors_js_1 = require("../Core/Utils/Vectors.js");
38
39
  const TypeUtils_js_1 = require("./TypeUtils.js");
39
- const Constants_js_1 = require("../Core/Utils/Constants.js");
40
40
  let _random = Math.random;
41
41
  const _animationLoop = {
42
42
  nextFrame: (cb) => requestAnimationFrame(cb),
43
43
  cancel: (idx) => cancelAnimationFrame(idx),
44
- }, double = 2, doublePI = Math.PI * double;
44
+ };
45
45
  function setRandom(rnd = Math.random) {
46
46
  _random = rnd;
47
47
  }
@@ -109,30 +109,29 @@
109
109
  if ((0, TypeUtils_js_1.isNumber)(direction)) {
110
110
  return degToRad(direction);
111
111
  }
112
- const empty = 0, half = 0.5, quarter = 0.25, threeQuarter = half + quarter;
113
112
  switch (direction) {
114
113
  case MoveDirection_js_1.MoveDirection.top:
115
- return -Math.PI * half;
114
+ return -Math.PI * Constants_js_1.half;
116
115
  case MoveDirection_js_1.MoveDirection.topRight:
117
- return -Math.PI * quarter;
116
+ return -Math.PI * Constants_js_1.quarter;
118
117
  case MoveDirection_js_1.MoveDirection.right:
119
- return empty;
118
+ return Constants_js_1.empty;
120
119
  case MoveDirection_js_1.MoveDirection.bottomRight:
121
- return Math.PI * quarter;
120
+ return Math.PI * Constants_js_1.quarter;
122
121
  case MoveDirection_js_1.MoveDirection.bottom:
123
- return Math.PI * half;
122
+ return Math.PI * Constants_js_1.half;
124
123
  case MoveDirection_js_1.MoveDirection.bottomLeft:
125
- return Math.PI * threeQuarter;
124
+ return Math.PI * Constants_js_1.threeQuarter;
126
125
  case MoveDirection_js_1.MoveDirection.left:
127
126
  return Math.PI;
128
127
  case MoveDirection_js_1.MoveDirection.topLeft:
129
- return -Math.PI * threeQuarter;
128
+ return -Math.PI * Constants_js_1.threeQuarter;
130
129
  case MoveDirection_js_1.MoveDirection.inside:
131
130
  return Math.atan2(center.y - position.y, center.x - position.x);
132
131
  case MoveDirection_js_1.MoveDirection.outside:
133
132
  return Math.atan2(position.y - center.y, position.x - center.x);
134
133
  default:
135
- return getRandom() * doublePI;
134
+ return getRandom() * Constants_js_1.doublePI;
136
135
  }
137
136
  }
138
137
  function getParticleBaseVelocity(direction) {
@@ -142,8 +141,7 @@
142
141
  return baseVelocity;
143
142
  }
144
143
  function collisionVelocity(v1, v2, m1, m2) {
145
- const double = 2;
146
- return Vectors_js_1.Vector.create((v1.x * (m1 - m2)) / (m1 + m2) + (v2.x * double * m2) / (m1 + m2), v1.y);
144
+ return Vectors_js_1.Vector.create((v1.x * (m1 - m2)) / (m1 + m2) + (v2.x * Constants_js_1.double * m2) / (m1 + m2), v1.y);
147
145
  }
148
146
  function calcPositionFromSize(data) {
149
147
  return data.position?.x !== undefined && data.position.y !== undefined
@@ -9,6 +9,7 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getFullScreenStyle = void 0;
12
13
  exports.setLogger = setLogger;
13
14
  exports.getLogger = getLogger;
14
15
  exports.isSsr = isSsr;
@@ -38,7 +39,7 @@
38
39
  exports.getPosition = getPosition;
39
40
  exports.getSize = getSize;
40
41
  exports.updateAnimation = updateAnimation;
41
- exports.assertValidVersion = assertValidVersion;
42
+ exports.cloneStyle = cloneStyle;
42
43
  const NumberUtils_js_1 = require("./NumberUtils.js");
43
44
  const Constants_js_1 = require("../Core/Utils/Constants.js");
44
45
  const TypeUtils_js_1 = require("./TypeUtils.js");
@@ -68,16 +69,28 @@
68
69
  function getLogger() {
69
70
  return _logger;
70
71
  }
72
+ function memoize(fn) {
73
+ const cache = new Map();
74
+ return (...args) => {
75
+ const key = JSON.stringify(args);
76
+ if (cache.has(key)) {
77
+ return cache.get(key);
78
+ }
79
+ const result = fn(...args);
80
+ cache.set(key, result);
81
+ return result;
82
+ };
83
+ }
71
84
  function rectSideBounce(data) {
72
- const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data, half = 0.5, minVelocity = 0;
85
+ const res = { bounced: false }, { pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor } = data;
73
86
  if (pOtherSide.min < rectOtherSide.min ||
74
87
  pOtherSide.min > rectOtherSide.max ||
75
88
  pOtherSide.max < rectOtherSide.min ||
76
89
  pOtherSide.max > rectOtherSide.max) {
77
90
  return res;
78
91
  }
79
- if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * half && velocity > minVelocity) ||
80
- (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * half && velocity < minVelocity)) {
92
+ if ((pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) * Constants_js_1.half && velocity > Constants_js_1.minVelocity) ||
93
+ (pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) * Constants_js_1.half && velocity < Constants_js_1.minVelocity)) {
81
94
  res.velocity = velocity * -factor;
82
95
  res.bounced = true;
83
96
  }
@@ -325,7 +338,7 @@
325
338
  res.status = AnimationStatus_js_1.AnimationStatus.decreasing;
326
339
  break;
327
340
  case AnimationMode_js_1.AnimationMode.random:
328
- res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
341
+ res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.half ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
329
342
  break;
330
343
  }
331
344
  const autoStatus = animationOptions.mode === AnimationMode_js_1.AnimationMode.auto;
@@ -346,7 +359,7 @@
346
359
  default:
347
360
  res.value = (0, NumberUtils_js_1.randomInRange)(res);
348
361
  if (autoStatus) {
349
- res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.halfRandom ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
362
+ res.status = (0, NumberUtils_js_1.getRandom)() >= Constants_js_1.half ? AnimationStatus_js_1.AnimationStatus.increasing : AnimationStatus_js_1.AnimationStatus.decreasing;
350
363
  }
351
364
  break;
352
365
  }
@@ -455,10 +468,47 @@
455
468
  data.value = (0, NumberUtils_js_1.clamp)(data.value, minValue, maxValue);
456
469
  }
457
470
  }
458
- function assertValidVersion(engine, pluginVersion) {
459
- if (engine.version === pluginVersion) {
460
- return;
471
+ function cloneStyle(style) {
472
+ const clonedStyle = document.createElement("div").style;
473
+ if (!style) {
474
+ return clonedStyle;
475
+ }
476
+ for (const key in style) {
477
+ const styleKey = style[key];
478
+ if (!Object.prototype.hasOwnProperty.call(style, key) || (0, TypeUtils_js_1.isNull)(styleKey)) {
479
+ continue;
480
+ }
481
+ const styleValue = style.getPropertyValue?.(styleKey);
482
+ if (!styleValue) {
483
+ continue;
484
+ }
485
+ const stylePriority = style.getPropertyPriority?.(styleKey);
486
+ if (!stylePriority) {
487
+ clonedStyle.setProperty?.(styleKey, styleValue);
488
+ }
489
+ else {
490
+ clonedStyle.setProperty?.(styleKey, styleValue, stylePriority);
491
+ }
492
+ }
493
+ return clonedStyle;
494
+ }
495
+ function computeFullScreenStyle(zIndex) {
496
+ const fullScreenStyle = document.createElement("div").style, radix = 10, style = {
497
+ width: "100%",
498
+ height: "100%",
499
+ margin: "0",
500
+ padding: "0",
501
+ borderWidth: "0",
502
+ position: "fixed",
503
+ zIndex: zIndex.toString(radix),
504
+ top: "0",
505
+ left: "0",
506
+ };
507
+ for (const key in style) {
508
+ const value = style[key];
509
+ fullScreenStyle.setProperty(key, value);
461
510
  }
462
- throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${engine.version}. Plugins version: ${pluginVersion}`);
511
+ return fullScreenStyle;
463
512
  }
513
+ exports.getFullScreenStyle = memoize(computeFullScreenStyle);
464
514
  });