tsparticles 1.37.6 → 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.
package/tsparticles.js CHANGED
@@ -1289,7 +1289,7 @@
1289
1289
  }
1290
1290
  }
1291
1291
  class Constants {}
1292
- Constants.canvasClass = "tsparticles-canvas-el";
1292
+ Constants.generatedAttribute = "generated";
1293
1293
  Constants.randomColorValue = "random";
1294
1294
  Constants.midColorValue = "mid";
1295
1295
  Constants.touchEndEvent = "touchend";
@@ -2249,9 +2249,9 @@
2249
2249
  clearTimeout(this.resizeTimeout);
2250
2250
  delete this.resizeTimeout;
2251
2251
  }
2252
- this.resizeTimeout = setTimeout((() => {
2252
+ this.resizeTimeout = setTimeout((async () => {
2253
2253
  var _a;
2254
- 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());
2255
2255
  }), 500);
2256
2256
  }
2257
2257
  handleVisibilityChange() {
@@ -2659,15 +2659,12 @@
2659
2659
  this.initBackground();
2660
2660
  this.paint();
2661
2661
  }
2662
- loadCanvas(canvas, generatedCanvas) {
2662
+ loadCanvas(canvas) {
2663
2663
  var _a;
2664
- if (!canvas.className) {
2665
- canvas.className = Constants.canvasClass;
2666
- }
2667
2664
  if (this.generatedCanvas) {
2668
2665
  (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
2669
2666
  }
2670
- 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;
2671
2668
  this.element = canvas;
2672
2669
  this.originalStyle = deepExtend({}, this.element.style);
2673
2670
  this.size.height = canvas.offsetHeight;
@@ -2709,7 +2706,7 @@
2709
2706
  }));
2710
2707
  }
2711
2708
  }
2712
- windowResize() {
2709
+ async windowResize() {
2713
2710
  if (!this.element) {
2714
2711
  return;
2715
2712
  }
@@ -2723,7 +2720,7 @@
2723
2720
  }
2724
2721
  }
2725
2722
  if (needsRefresh) {
2726
- container.refresh();
2723
+ await container.refresh();
2727
2724
  }
2728
2725
  }
2729
2726
  resize() {
@@ -2924,6 +2921,16 @@
2924
2921
  element.style.width = originalStyle.width;
2925
2922
  element.style.height = originalStyle.height;
2926
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
+ }
2927
2934
  }
2928
2935
  paintBase(baseColor) {
2929
2936
  this.draw((ctx => {
@@ -6461,6 +6468,7 @@
6461
6468
  this.pauseOnBlur = true;
6462
6469
  this.pauseOnOutsideViewport = true;
6463
6470
  this.responsive = [];
6471
+ this.style = {};
6464
6472
  this.themes = [];
6465
6473
  this.zLayers = 100;
6466
6474
  }
@@ -6537,6 +6545,7 @@
6537
6545
  }
6538
6546
  this.motion.load(data.motion);
6539
6547
  this.particles.load(data.particles);
6548
+ this.style = deepExtend(this.style, data.style);
6540
6549
  Plugins.loadOptions(this, data);
6541
6550
  if (data.responsive !== undefined) {
6542
6551
  for (const responsive of data.responsive) {
@@ -7003,22 +7012,17 @@
7003
7012
  }
7004
7013
  }
7005
7014
  let canvasEl;
7006
- let generatedCanvas;
7007
7015
  if (domContainer.tagName.toLowerCase() === "canvas") {
7008
7016
  canvasEl = domContainer;
7009
- generatedCanvas = false;
7017
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
7010
7018
  } else {
7011
7019
  const existingCanvases = domContainer.getElementsByTagName("canvas");
7012
7020
  if (existingCanvases.length) {
7013
7021
  canvasEl = existingCanvases[0];
7014
- if (!canvasEl.className) {
7015
- canvasEl.className = Constants.canvasClass;
7016
- }
7017
- generatedCanvas = false;
7022
+ canvasEl.dataset[Constants.generatedAttribute] = "false";
7018
7023
  } else {
7019
- generatedCanvas = true;
7020
7024
  canvasEl = document.createElement("canvas");
7021
- canvasEl.className = Constants.canvasClass;
7025
+ canvasEl.dataset[Constants.generatedAttribute] = "true";
7022
7026
  canvasEl.style.width = "100%";
7023
7027
  canvasEl.style.height = "100%";
7024
7028
  domContainer.appendChild(canvasEl);
@@ -7030,7 +7034,7 @@
7030
7034
  } else {
7031
7035
  dom.push(newItem);
7032
7036
  }
7033
- newItem.canvas.loadCanvas(canvasEl, generatedCanvas);
7037
+ newItem.canvas.loadCanvas(canvasEl);
7034
7038
  await newItem.start();
7035
7039
  return newItem;
7036
7040
  }