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
@@ -1,3 +1,6 @@
1
+ const path = require('path');
2
+ const reactParticlesJsFoundError = "react-particles-js-found";
3
+
1
4
  try {
2
5
  console.log("Thank you for installing tsParticles.");
3
6
  console.log("Remember to checkout the official website https://particles.js.org to explore some samples.");
@@ -5,8 +8,6 @@ try {
5
8
  console.log("If you need documentation you can find it here: https://particles.js.org");
6
9
  console.log("Remember to leave a star on the tsParticles repository if you like the project and want to support it: https://github.com/matteobruni/tsparticles");
7
10
 
8
- const path = require('path');
9
-
10
11
  const pkgSettings = require(path.join(process.env.INIT_CWD, "package.json"));
11
12
 
12
13
  if (!pkgSettings) {
@@ -19,6 +20,12 @@ try {
19
20
  return;
20
21
  }
21
22
 
23
+ if (dependencies["react-particles-js"]) {
24
+ console.error("\x1b[31m%s\x1b[0m", "The package react-particles-js has been deprecated and is not supported anymore. Please consider switching to react-tsparticles package.");
25
+
26
+ throw new Error(reactParticlesJsFoundError);
27
+ }
28
+
22
29
  if (dependencies["react"] || dependencies["next"]) {
23
30
  if (!dependencies["react-tsparticles"]) {
24
31
  console.warn("\x1b[43m\x1b[30m%s\x1b[0m", "Found React installed. Please download react-tsparticles to use tsParticles with a component ready to use and easier to configure.");
@@ -81,5 +88,9 @@ try {
81
88
  }
82
89
  }
83
90
  } catch (error) {
84
- // ignore errors
91
+ if (error.message === reactParticlesJsFoundError) {
92
+ throw error;
93
+ }
94
+
95
+ console.log(error);
85
96
  }
package/tsparticles.js CHANGED
@@ -1222,14 +1222,11 @@
1222
1222
  };
1223
1223
  }
1224
1224
  function circleBounce(p1, p2) {
1225
- const xVelocityDiff = p1.velocity.x;
1226
- const yVelocityDiff = p1.velocity.y;
1227
- const pos1 = p1.position;
1228
- const pos2 = p2.position;
1229
- const xDist = pos2.x - pos1.x;
1230
- const yDist = pos2.y - pos1.y;
1225
+ const {x: xVelocityDiff, y: yVelocityDiff} = p1.velocity.sub(p2.velocity);
1226
+ const [pos1, pos2] = [ p1.position, p2.position ];
1227
+ const {dx: xDist, dy: yDist} = getDistances(pos2, pos1);
1231
1228
  if (xVelocityDiff * xDist + yVelocityDiff * yDist >= 0) {
1232
- const angle = -Math.atan2(pos2.y - pos1.y, pos2.x - pos1.x);
1229
+ const angle = -Math.atan2(yDist, xDist);
1233
1230
  const m1 = p1.mass;
1234
1231
  const m2 = p2.mass;
1235
1232
  const u1 = p1.velocity.rotate(angle);
@@ -1292,7 +1289,7 @@
1292
1289
  }
1293
1290
  }
1294
1291
  class Constants {}
1295
- Constants.canvasClass = "tsparticles-canvas-el";
1292
+ Constants.generatedAttribute = "generated";
1296
1293
  Constants.randomColorValue = "random";
1297
1294
  Constants.midColorValue = "mid";
1298
1295
  Constants.touchEndEvent = "touchend";
@@ -2163,6 +2160,7 @@
2163
2160
  this.mouseDownHandler = () => this.mouseDown();
2164
2161
  this.visibilityChangeHandler = () => this.handleVisibilityChange();
2165
2162
  this.themeChangeHandler = e => this.handleThemeChange(e);
2163
+ this.oldThemeChangeHandler = e => this.handleThemeChange(e);
2166
2164
  this.resizeHandler = () => this.handleWindowResize();
2167
2165
  }
2168
2166
  addListeners() {
@@ -2186,9 +2184,17 @@
2186
2184
  } else {
2187
2185
  container.interactivity.element = container.canvas.element;
2188
2186
  }
2189
- const mediaMatch = typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
2187
+ const mediaMatch = !isSsr() && typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
2190
2188
  if (mediaMatch) {
2191
- manageListener(mediaMatch, "change", this.themeChangeHandler, add);
2189
+ if (mediaMatch.addEventListener !== undefined) {
2190
+ manageListener(mediaMatch, "change", this.themeChangeHandler, add);
2191
+ } else if (mediaMatch.addListener !== undefined) {
2192
+ if (add) {
2193
+ mediaMatch.addListener(this.oldThemeChangeHandler);
2194
+ } else {
2195
+ mediaMatch.removeListener(this.oldThemeChangeHandler);
2196
+ }
2197
+ }
2192
2198
  }
2193
2199
  const interactivityEl = container.interactivity.element;
2194
2200
  if (!interactivityEl) {
@@ -2243,9 +2249,9 @@
2243
2249
  clearTimeout(this.resizeTimeout);
2244
2250
  delete this.resizeTimeout;
2245
2251
  }
2246
- this.resizeTimeout = setTimeout((() => {
2252
+ this.resizeTimeout = setTimeout((async () => {
2247
2253
  var _a;
2248
- return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize();
2254
+ return await ((_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize());
2249
2255
  }), 500);
2250
2256
  }
2251
2257
  handleVisibilityChange() {
@@ -2653,15 +2659,12 @@
2653
2659
  this.initBackground();
2654
2660
  this.paint();
2655
2661
  }
2656
- loadCanvas(canvas, generatedCanvas) {
2662
+ loadCanvas(canvas) {
2657
2663
  var _a;
2658
- if (!canvas.className) {
2659
- canvas.className = Constants.canvasClass;
2660
- }
2661
2664
  if (this.generatedCanvas) {
2662
2665
  (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
2663
2666
  }
2664
- this.generatedCanvas = generatedCanvas !== null && generatedCanvas !== void 0 ? generatedCanvas : this.generatedCanvas;
2667
+ this.generatedCanvas = canvas.dataset && Constants.generatedAttribute in canvas.dataset ? canvas.dataset[Constants.generatedAttribute] === "true" : this.generatedCanvas;
2665
2668
  this.element = canvas;
2666
2669
  this.originalStyle = deepExtend({}, this.element.style);
2667
2670
  this.size.height = canvas.offsetHeight;
@@ -2703,7 +2706,7 @@
2703
2706
  }));
2704
2707
  }
2705
2708
  }
2706
- windowResize() {
2709
+ async windowResize() {
2707
2710
  if (!this.element) {
2708
2711
  return;
2709
2712
  }
@@ -2717,7 +2720,7 @@
2717
2720
  }
2718
2721
  }
2719
2722
  if (needsRefresh) {
2720
- container.refresh();
2723
+ await container.refresh();
2721
2724
  }
2722
2725
  }
2723
2726
  resize() {
@@ -2918,6 +2921,16 @@
2918
2921
  element.style.width = originalStyle.width;
2919
2922
  element.style.height = originalStyle.height;
2920
2923
  }
2924
+ for (const key in options.style) {
2925
+ if (!key || !options.style) {
2926
+ continue;
2927
+ }
2928
+ const value = options.style[key];
2929
+ if (!value) {
2930
+ continue;
2931
+ }
2932
+ element.style[key] = value;
2933
+ }
2921
2934
  }
2922
2935
  paintBase(baseColor) {
2923
2936
  this.draw((ctx => {
@@ -6455,6 +6468,7 @@
6455
6468
  this.pauseOnBlur = true;
6456
6469
  this.pauseOnOutsideViewport = true;
6457
6470
  this.responsive = [];
6471
+ this.style = {};
6458
6472
  this.themes = [];
6459
6473
  this.zLayers = 100;
6460
6474
  }
@@ -6531,6 +6545,7 @@
6531
6545
  }
6532
6546
  this.motion.load(data.motion);
6533
6547
  this.particles.load(data.particles);
6548
+ this.style = deepExtend(this.style, data.style);
6534
6549
  Plugins.loadOptions(this, data);
6535
6550
  if (data.responsive !== undefined) {
6536
6551
  for (const responsive of data.responsive) {
@@ -6997,22 +7012,17 @@
6997
7012
  }
6998
7013
  }
6999
7014
  let canvasEl;
7000
- let generatedCanvas;
7001
7015
  if (domContainer.tagName.toLowerCase() === "canvas") {
7002
7016
  canvasEl = domContainer;
7003
- generatedCanvas = false;
7017
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
7004
7018
  } else {
7005
7019
  const existingCanvases = domContainer.getElementsByTagName("canvas");
7006
7020
  if (existingCanvases.length) {
7007
7021
  canvasEl = existingCanvases[0];
7008
- if (!canvasEl.className) {
7009
- canvasEl.className = Constants.canvasClass;
7010
- }
7011
- generatedCanvas = false;
7022
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
7012
7023
  } else {
7013
- generatedCanvas = true;
7014
7024
  canvasEl = document.createElement("canvas");
7015
- canvasEl.className = Constants.canvasClass;
7025
+ canvasEl.dataset[Constants.generatedAttribute] = "true";
7016
7026
  canvasEl.style.width = "100%";
7017
7027
  canvasEl.style.height = "100%";
7018
7028
  domContainer.appendChild(canvasEl);
@@ -7024,7 +7034,7 @@
7024
7034
  } else {
7025
7035
  dom.push(newItem);
7026
7036
  }
7027
- newItem.canvas.loadCanvas(canvasEl, generatedCanvas);
7037
+ newItem.canvas.loadCanvas(canvasEl);
7028
7038
  await newItem.start();
7029
7039
  return newItem;
7030
7040
  }