tsparticles 2.7.1 → 2.9.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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v2.7.1
7
+ * v2.9.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -187,6 +187,7 @@ __webpack_require__.d(__webpack_exports__, {
187
187
  "mouseOutEvent": () => (/* reexport */ mouseOutEvent),
188
188
  "mouseUpEvent": () => (/* reexport */ mouseUpEvent),
189
189
  "paintBase": () => (/* reexport */ paintBase),
190
+ "paintImage": () => (/* reexport */ paintImage),
190
191
  "parseAlpha": () => (/* reexport */ parseAlpha),
191
192
  "randomInRange": () => (/* reexport */ randomInRange),
192
193
  "rangeColorToHsl": () => (/* reexport */ rangeColorToHsl),
@@ -1049,6 +1050,14 @@ function paintBase(context, dimension, baseColor) {
1049
1050
  context.fillStyle = baseColor !== null && baseColor !== void 0 ? baseColor : "rgba(0,0,0,0)";
1050
1051
  context.fillRect(0, 0, dimension.width, dimension.height);
1051
1052
  }
1053
+ function paintImage(context, dimension, image, opacity) {
1054
+ if (!image) {
1055
+ return;
1056
+ }
1057
+ context.globalAlpha = opacity;
1058
+ context.drawImage(image, 0, 0, dimension.width, dimension.height);
1059
+ context.globalAlpha = 1;
1060
+ }
1052
1061
  function clear(context, dimension) {
1053
1062
  context.clearRect(0, 0, dimension.width, dimension.height);
1054
1063
  }
@@ -1203,11 +1212,16 @@ class Canvas {
1203
1212
  }
1204
1213
  clear() {
1205
1214
  const options = this.container.actualOptions,
1206
- trail = options.particles.move.trail;
1215
+ trail = options.particles.move.trail,
1216
+ trailFill = this._trailFill;
1207
1217
  if (options.backgroundMask.enable) {
1208
1218
  this.paint();
1209
- } else if (trail.enable && trail.length > 0 && this._trailFillColor) {
1210
- this._paintBase(getStyleFromRgb(this._trailFillColor, 1 / trail.length));
1219
+ } else if (trail.enable && trail.length > 0 && trailFill) {
1220
+ if (trailFill.color) {
1221
+ this._paintBase(getStyleFromRgb(trailFill.color, trailFill.opacity));
1222
+ } else if (trailFill.image) {
1223
+ this._paintImage(trailFill.image, trailFill.opacity);
1224
+ }
1211
1225
  } else {
1212
1226
  this.draw(ctx => {
1213
1227
  clear(ctx, this.size);
@@ -1222,9 +1236,7 @@ class Canvas {
1222
1236
  } else {
1223
1237
  this._resetOriginalStyle();
1224
1238
  }
1225
- this.draw(ctx => {
1226
- clear(ctx, this.size);
1227
- });
1239
+ this.stop();
1228
1240
  this._preDrawUpdaters = [];
1229
1241
  this._postDrawUpdaters = [];
1230
1242
  this._resizePlugins = [];
@@ -1298,12 +1310,16 @@ class Canvas {
1298
1310
  drawPlugin(ctx, plugin, delta);
1299
1311
  });
1300
1312
  }
1301
- init() {
1313
+ async init() {
1302
1314
  var _a;
1303
1315
  this.resize();
1304
1316
  this._initStyle();
1305
1317
  this._initCover();
1306
- this._initTrail();
1318
+ try {
1319
+ await this._initTrail();
1320
+ } catch (e) {
1321
+ console.error(e);
1322
+ }
1307
1323
  this.initBackground();
1308
1324
  if (this.element) {
1309
1325
  (_a = this._mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.element, {
@@ -1409,6 +1425,11 @@ class Canvas {
1409
1425
  };
1410
1426
  }
1411
1427
  }
1428
+ stop() {
1429
+ this.draw(ctx => {
1430
+ clear(ctx, this.size);
1431
+ });
1432
+ }
1412
1433
  async windowResize() {
1413
1434
  if (!this.element) {
1414
1435
  return;
@@ -1512,14 +1533,40 @@ class Canvas {
1512
1533
  element.style.setProperty(key, value, "important");
1513
1534
  }
1514
1535
  }
1515
- _initTrail() {
1536
+ async _initTrail() {
1516
1537
  const options = this.container.actualOptions,
1517
1538
  trail = options.particles.move.trail,
1518
- fillColor = rangeColorToRgb(trail.fillColor);
1519
- if (fillColor) {
1539
+ trailFill = trail.fill;
1540
+ if (!trail.enable) {
1541
+ return;
1542
+ }
1543
+ if (trailFill.color) {
1544
+ const fillColor = rangeColorToRgb(trailFill.color);
1545
+ if (!fillColor) {
1546
+ return;
1547
+ }
1520
1548
  const trail = options.particles.move.trail;
1521
- this._trailFillColor = Object.assign(Object.assign({}, fillColor), {
1522
- a: 1 / trail.length
1549
+ this._trailFill = {
1550
+ color: Object.assign({}, fillColor),
1551
+ opacity: 1 / trail.length
1552
+ };
1553
+ } else {
1554
+ await new Promise((resolve, reject) => {
1555
+ if (!trailFill.image) {
1556
+ return;
1557
+ }
1558
+ const img = document.createElement("img");
1559
+ img.addEventListener("load", () => {
1560
+ this._trailFill = {
1561
+ image: img,
1562
+ opacity: 1 / trail.length
1563
+ };
1564
+ resolve();
1565
+ });
1566
+ img.addEventListener("error", evt => {
1567
+ reject(evt.error);
1568
+ });
1569
+ img.src = trailFill.image;
1523
1570
  });
1524
1571
  }
1525
1572
  }
@@ -1528,6 +1575,11 @@ class Canvas {
1528
1575
  paintBase(ctx, this.size, baseColor);
1529
1576
  });
1530
1577
  }
1578
+ _paintImage(image, opacity) {
1579
+ this.draw(ctx => {
1580
+ paintImage(ctx, this.size, image, opacity);
1581
+ });
1582
+ }
1531
1583
  _repairStyle() {
1532
1584
  var _a, _b;
1533
1585
  const element = this.element;
@@ -2704,14 +2756,36 @@ class MovePath {
2704
2756
  }
2705
2757
  }
2706
2758
  }
2759
+ ;// CONCATENATED MODULE: ../../engine/dist/esm/Options/Classes/Particles/Move/MoveTrailFill.js
2760
+
2761
+ class MoveTrailFill {
2762
+ load(data) {
2763
+ if (!data) {
2764
+ return;
2765
+ }
2766
+ if (data.color !== undefined) {
2767
+ this.color = OptionsColor.create(this.color, data.color);
2768
+ }
2769
+ if (data.image !== undefined) {
2770
+ this.image = data.image;
2771
+ }
2772
+ }
2773
+ }
2707
2774
  ;// CONCATENATED MODULE: ../../engine/dist/esm/Options/Classes/Particles/Move/MoveTrail.js
2708
2775
 
2709
2776
  class MoveTrail {
2710
2777
  constructor() {
2711
2778
  this.enable = false;
2712
2779
  this.length = 10;
2713
- this.fillColor = new OptionsColor();
2714
- this.fillColor.value = "#000000";
2780
+ this.fill = new MoveTrailFill();
2781
+ }
2782
+ get fillColor() {
2783
+ return this.fill.color;
2784
+ }
2785
+ set fillColor(value) {
2786
+ this.fill.load({
2787
+ color: value
2788
+ });
2715
2789
  }
2716
2790
  load(data) {
2717
2791
  if (!data) {
@@ -2720,7 +2794,11 @@ class MoveTrail {
2720
2794
  if (data.enable !== undefined) {
2721
2795
  this.enable = data.enable;
2722
2796
  }
2723
- this.fillColor = OptionsColor.create(this.fillColor, data.fillColor);
2797
+ if (data.fill !== undefined || data.fillColor !== undefined) {
2798
+ this.fill.load(data.fill || {
2799
+ color: data.fillColor
2800
+ });
2801
+ }
2724
2802
  if (data.length !== undefined) {
2725
2803
  this.length = data.length;
2726
2804
  }
@@ -3039,7 +3117,7 @@ class ParticlesNumber {
3039
3117
  constructor() {
3040
3118
  this.density = new ParticlesDensity();
3041
3119
  this.limit = 0;
3042
- this.value = 100;
3120
+ this.value = 0;
3043
3121
  }
3044
3122
  get max() {
3045
3123
  return this.limit;
@@ -4711,7 +4789,7 @@ class Container {
4711
4789
  this.plugins.set(id, plugin);
4712
4790
  }
4713
4791
  this.retina.init();
4714
- this.canvas.init();
4792
+ await this.canvas.init();
4715
4793
  this.updateActualOptions();
4716
4794
  this.canvas.initBackground();
4717
4795
  this.canvas.resize();
@@ -4878,7 +4956,7 @@ class Container {
4878
4956
  this._eventListeners.removeListeners();
4879
4957
  this.pause();
4880
4958
  this.particles.clear();
4881
- this.canvas.clear();
4959
+ this.canvas.stop();
4882
4960
  if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
4883
4961
  this._intersectionObserver.unobserve(this.interactivity.element);
4884
4962
  }
@@ -5196,6 +5274,9 @@ class Engine {
5196
5274
  this._loader = new Loader(this);
5197
5275
  this.plugins = new Plugins(this);
5198
5276
  }
5277
+ get version() {
5278
+ return "2.9.0";
5279
+ }
5199
5280
  addEventListener(type, listener) {
5200
5281
  this._eventDispatcher.addEventListener(type, listener);
5201
5282
  }
@@ -5987,9 +6068,13 @@ class Split {
5987
6068
  this.sizeOffset = true;
5988
6069
  }
5989
6070
  load(data) {
6071
+ var _a;
5990
6072
  if (!data) {
5991
6073
  return;
5992
6074
  }
6075
+ if (data.color !== undefined) {
6076
+ this.color = OptionsColor.create(this.color, data.color);
6077
+ }
5993
6078
  if (data.count !== undefined) {
5994
6079
  this.count = data.count;
5995
6080
  }
@@ -6001,6 +6086,18 @@ class Split {
6001
6086
  if (data.sizeOffset !== undefined) {
6002
6087
  this.sizeOffset = data.sizeOffset;
6003
6088
  }
6089
+ if (data.colorOffset) {
6090
+ this.colorOffset = (_a = this.colorOffset) !== null && _a !== void 0 ? _a : {};
6091
+ if (data.colorOffset.h !== undefined) {
6092
+ this.colorOffset.h = data.colorOffset.h;
6093
+ }
6094
+ if (data.colorOffset.s !== undefined) {
6095
+ this.colorOffset.s = data.colorOffset.s;
6096
+ }
6097
+ if (data.colorOffset.l !== undefined) {
6098
+ this.colorOffset.l = data.colorOffset.l;
6099
+ }
6100
+ }
6004
6101
  }
6005
6102
  }
6006
6103
  ;// CONCATENATED MODULE: ../../updaters/destroy/dist/esm/Options/Classes/Destroy.js
@@ -6092,18 +6189,34 @@ class DestroyUpdater {
6092
6189
  }
6093
6190
  }
6094
6191
  addSplitParticle(parent, splitParticlesOptions) {
6192
+ var _a, _b, _c;
6095
6193
  const destroyOptions = parent.options.destroy;
6096
6194
  if (!destroyOptions) {
6097
6195
  return;
6098
6196
  }
6099
6197
  const splitOptions = destroyOptions.split,
6100
6198
  options = loadParticlesOptions(this.engine, this.container, parent.options),
6101
- factor = getValue(splitOptions.factor);
6102
- options.color.load({
6103
- value: {
6104
- hsl: parent.getFillColor()
6105
- }
6106
- });
6199
+ factor = getValue(splitOptions.factor),
6200
+ parentColor = parent.getFillColor();
6201
+ if (splitOptions.color) {
6202
+ options.color.load(splitOptions.color);
6203
+ } else if (splitOptions.colorOffset && parentColor) {
6204
+ options.color.load({
6205
+ value: {
6206
+ hsl: {
6207
+ h: parentColor.h + getRangeValue((_a = splitOptions.colorOffset.h) !== null && _a !== void 0 ? _a : 0),
6208
+ s: parentColor.s + getRangeValue((_b = splitOptions.colorOffset.s) !== null && _b !== void 0 ? _b : 0),
6209
+ l: parentColor.l + getRangeValue((_c = splitOptions.colorOffset.l) !== null && _c !== void 0 ? _c : 0)
6210
+ }
6211
+ }
6212
+ });
6213
+ } else {
6214
+ options.color.load({
6215
+ value: {
6216
+ hsl: parent.getFillColor()
6217
+ }
6218
+ });
6219
+ }
6107
6220
  options.move.load({
6108
6221
  center: {
6109
6222
  x: parent.position.x,
@@ -6193,7 +6306,7 @@ class EmitterLife {
6193
6306
  this.wait = false;
6194
6307
  }
6195
6308
  load(data) {
6196
- if (data === undefined) {
6309
+ if (!data) {
6197
6310
  return;
6198
6311
  }
6199
6312
  if (data.count !== undefined) {
@@ -6266,14 +6379,14 @@ class Emitter {
6266
6379
  this.startCount = 0;
6267
6380
  }
6268
6381
  load(data) {
6269
- if (data === undefined) {
6382
+ if (!data) {
6270
6383
  return;
6271
6384
  }
6272
6385
  if (data.autoPlay !== undefined) {
6273
6386
  this.autoPlay = data.autoPlay;
6274
6387
  }
6275
6388
  if (data.size !== undefined) {
6276
- if (this.size === undefined) {
6389
+ if (!this.size) {
6277
6390
  this.size = new EmitterSize();
6278
6391
  }
6279
6392
  this.size.load(data.size);