tsparticles 1.37.3 → 1.38.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 (42) hide show
  1. package/Core/Canvas.d.ts +2 -2
  2. package/Core/Canvas.js +17 -7
  3. package/Core/Loader.js +4 -9
  4. package/Options/Classes/Options.d.ts +1 -0
  5. package/Options/Classes/Options.js +2 -0
  6. package/Options/Interfaces/IOptions.d.ts +1 -0
  7. package/README.md +68 -0
  8. package/Utils/Constants.d.ts +1 -1
  9. package/Utils/Constants.js +1 -1
  10. package/Utils/EventListeners.d.ts +1 -0
  11. package/Utils/EventListeners.js +14 -3
  12. package/Utils/Utils.js +4 -7
  13. package/browser/Core/Canvas.d.ts +2 -2
  14. package/browser/Core/Canvas.js +17 -7
  15. package/browser/Core/Loader.js +4 -9
  16. package/browser/Options/Classes/Options.d.ts +1 -0
  17. package/browser/Options/Classes/Options.js +3 -1
  18. package/browser/Options/Interfaces/IOptions.d.ts +1 -0
  19. package/browser/Utils/Constants.d.ts +1 -4
  20. package/browser/Utils/Constants.js +1 -4
  21. package/browser/Utils/EventListeners.d.ts +1 -0
  22. package/browser/Utils/EventListeners.js +15 -4
  23. package/browser/Utils/Utils.js +5 -8
  24. package/esm/Core/Canvas.d.ts +2 -2
  25. package/esm/Core/Canvas.js +17 -7
  26. package/esm/Core/Loader.js +4 -9
  27. package/esm/Options/Classes/Options.d.ts +1 -0
  28. package/esm/Options/Classes/Options.js +3 -1
  29. package/esm/Options/Interfaces/IOptions.d.ts +1 -0
  30. package/esm/Utils/Constants.d.ts +1 -1
  31. package/esm/Utils/Constants.js +1 -1
  32. package/esm/Utils/EventListeners.d.ts +1 -0
  33. package/esm/Utils/EventListeners.js +15 -4
  34. package/esm/Utils/Utils.js +5 -8
  35. package/package.json +1 -1
  36. package/report.html +2 -2
  37. package/report.slim.html +2 -2
  38. package/scripts/install.js +14 -3
  39. package/tsparticles.js +38 -28
  40. package/tsparticles.min.js +2 -2
  41. package/tsparticles.slim.js +38 -28
  42. package/tsparticles.slim.min.js +2 -2
@@ -939,14 +939,11 @@
939
939
  };
940
940
  }
941
941
  function circleBounce(p1, p2) {
942
- const xVelocityDiff = p1.velocity.x;
943
- const yVelocityDiff = p1.velocity.y;
944
- const pos1 = p1.position;
945
- const pos2 = p2.position;
946
- const xDist = pos2.x - pos1.x;
947
- const yDist = pos2.y - pos1.y;
942
+ const {x: xVelocityDiff, y: yVelocityDiff} = p1.velocity.sub(p2.velocity);
943
+ const [pos1, pos2] = [ p1.position, p2.position ];
944
+ const {dx: xDist, dy: yDist} = getDistances(pos2, pos1);
948
945
  if (xVelocityDiff * xDist + yVelocityDiff * yDist >= 0) {
949
- const angle = -Math.atan2(pos2.y - pos1.y, pos2.x - pos1.x);
946
+ const angle = -Math.atan2(yDist, xDist);
950
947
  const m1 = p1.mass;
951
948
  const m2 = p2.mass;
952
949
  const u1 = p1.velocity.rotate(angle);
@@ -1009,7 +1006,7 @@
1009
1006
  }
1010
1007
  }
1011
1008
  class Constants {}
1012
- Constants.canvasClass = "tsparticles-canvas-el";
1009
+ Constants.generatedAttribute = "generated";
1013
1010
  Constants.randomColorValue = "random";
1014
1011
  Constants.midColorValue = "mid";
1015
1012
  Constants.touchEndEvent = "touchend";
@@ -1880,6 +1877,7 @@
1880
1877
  this.mouseDownHandler = () => this.mouseDown();
1881
1878
  this.visibilityChangeHandler = () => this.handleVisibilityChange();
1882
1879
  this.themeChangeHandler = e => this.handleThemeChange(e);
1880
+ this.oldThemeChangeHandler = e => this.handleThemeChange(e);
1883
1881
  this.resizeHandler = () => this.handleWindowResize();
1884
1882
  }
1885
1883
  addListeners() {
@@ -1903,9 +1901,17 @@
1903
1901
  } else {
1904
1902
  container.interactivity.element = container.canvas.element;
1905
1903
  }
1906
- const mediaMatch = typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
1904
+ const mediaMatch = !isSsr() && typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
1907
1905
  if (mediaMatch) {
1908
- manageListener(mediaMatch, "change", this.themeChangeHandler, add);
1906
+ if (mediaMatch.addEventListener !== undefined) {
1907
+ manageListener(mediaMatch, "change", this.themeChangeHandler, add);
1908
+ } else if (mediaMatch.addListener !== undefined) {
1909
+ if (add) {
1910
+ mediaMatch.addListener(this.oldThemeChangeHandler);
1911
+ } else {
1912
+ mediaMatch.removeListener(this.oldThemeChangeHandler);
1913
+ }
1914
+ }
1909
1915
  }
1910
1916
  const interactivityEl = container.interactivity.element;
1911
1917
  if (!interactivityEl) {
@@ -1960,9 +1966,9 @@
1960
1966
  clearTimeout(this.resizeTimeout);
1961
1967
  delete this.resizeTimeout;
1962
1968
  }
1963
- this.resizeTimeout = setTimeout((() => {
1969
+ this.resizeTimeout = setTimeout((async () => {
1964
1970
  var _a;
1965
- return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize();
1971
+ return await ((_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize());
1966
1972
  }), 500);
1967
1973
  }
1968
1974
  handleVisibilityChange() {
@@ -2370,15 +2376,12 @@
2370
2376
  this.initBackground();
2371
2377
  this.paint();
2372
2378
  }
2373
- loadCanvas(canvas, generatedCanvas) {
2379
+ loadCanvas(canvas) {
2374
2380
  var _a;
2375
- if (!canvas.className) {
2376
- canvas.className = Constants.canvasClass;
2377
- }
2378
2381
  if (this.generatedCanvas) {
2379
2382
  (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
2380
2383
  }
2381
- this.generatedCanvas = generatedCanvas !== null && generatedCanvas !== void 0 ? generatedCanvas : this.generatedCanvas;
2384
+ this.generatedCanvas = canvas.dataset && Constants.generatedAttribute in canvas.dataset ? canvas.dataset[Constants.generatedAttribute] === "true" : this.generatedCanvas;
2382
2385
  this.element = canvas;
2383
2386
  this.originalStyle = deepExtend({}, this.element.style);
2384
2387
  this.size.height = canvas.offsetHeight;
@@ -2420,7 +2423,7 @@
2420
2423
  }));
2421
2424
  }
2422
2425
  }
2423
- windowResize() {
2426
+ async windowResize() {
2424
2427
  if (!this.element) {
2425
2428
  return;
2426
2429
  }
@@ -2434,7 +2437,7 @@
2434
2437
  }
2435
2438
  }
2436
2439
  if (needsRefresh) {
2437
- container.refresh();
2440
+ await container.refresh();
2438
2441
  }
2439
2442
  }
2440
2443
  resize() {
@@ -2635,6 +2638,16 @@
2635
2638
  element.style.width = originalStyle.width;
2636
2639
  element.style.height = originalStyle.height;
2637
2640
  }
2641
+ for (const key in options.style) {
2642
+ if (!key || !options.style) {
2643
+ continue;
2644
+ }
2645
+ const value = options.style[key];
2646
+ if (!value) {
2647
+ continue;
2648
+ }
2649
+ element.style[key] = value;
2650
+ }
2638
2651
  }
2639
2652
  paintBase(baseColor) {
2640
2653
  this.draw((ctx => {
@@ -6172,6 +6185,7 @@
6172
6185
  this.pauseOnBlur = true;
6173
6186
  this.pauseOnOutsideViewport = true;
6174
6187
  this.responsive = [];
6188
+ this.style = {};
6175
6189
  this.themes = [];
6176
6190
  this.zLayers = 100;
6177
6191
  }
@@ -6248,6 +6262,7 @@
6248
6262
  }
6249
6263
  this.motion.load(data.motion);
6250
6264
  this.particles.load(data.particles);
6265
+ this.style = deepExtend(this.style, data.style);
6251
6266
  Plugins.loadOptions(this, data);
6252
6267
  if (data.responsive !== undefined) {
6253
6268
  for (const responsive of data.responsive) {
@@ -6714,22 +6729,17 @@
6714
6729
  }
6715
6730
  }
6716
6731
  let canvasEl;
6717
- let generatedCanvas;
6718
6732
  if (domContainer.tagName.toLowerCase() === "canvas") {
6719
6733
  canvasEl = domContainer;
6720
- generatedCanvas = false;
6734
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
6721
6735
  } else {
6722
6736
  const existingCanvases = domContainer.getElementsByTagName("canvas");
6723
6737
  if (existingCanvases.length) {
6724
6738
  canvasEl = existingCanvases[0];
6725
- if (!canvasEl.className) {
6726
- canvasEl.className = Constants.canvasClass;
6727
- }
6728
- generatedCanvas = false;
6739
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
6729
6740
  } else {
6730
- generatedCanvas = true;
6731
6741
  canvasEl = document.createElement("canvas");
6732
- canvasEl.className = Constants.canvasClass;
6742
+ canvasEl.dataset[Constants.generatedAttribute] = "true";
6733
6743
  canvasEl.style.width = "100%";
6734
6744
  canvasEl.style.height = "100%";
6735
6745
  domContainer.appendChild(canvasEl);
@@ -6741,7 +6751,7 @@
6741
6751
  } else {
6742
6752
  dom.push(newItem);
6743
6753
  }
6744
- newItem.canvas.loadCanvas(canvasEl, generatedCanvas);
6754
+ newItem.canvas.loadCanvas(canvasEl);
6745
6755
  await newItem.start();
6746
6756
  return newItem;
6747
6757
  }