tsparticles 3.0.0-beta.1 → 3.0.0-beta.3

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
- * v3.0.0-beta.1
7
+ * v3.0.0-beta.3
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -207,6 +207,7 @@ __webpack_require__.d(__webpack_exports__, {
207
207
  rectBounce: () => (/* reexport */ rectBounce),
208
208
  resizeEvent: () => (/* reexport */ resizeEvent),
209
209
  rgbToHsl: () => (/* reexport */ rgbToHsl),
210
+ safeIntersectionObserver: () => (/* reexport */ safeIntersectionObserver),
210
211
  safeMatchMedia: () => (/* reexport */ safeMatchMedia),
211
212
  safeMutationObserver: () => (/* reexport */ safeMutationObserver),
212
213
  setLogger: () => (/* reexport */ setLogger),
@@ -573,6 +574,12 @@ function safeMatchMedia(query) {
573
574
  }
574
575
  return matchMedia(query);
575
576
  }
577
+ function safeIntersectionObserver(callback) {
578
+ if (isSsr() || typeof IntersectionObserver === "undefined") {
579
+ return;
580
+ }
581
+ return new IntersectionObserver(callback);
582
+ }
576
583
  function safeMutationObserver(callback) {
577
584
  if (isSsr() || typeof MutationObserver === "undefined") {
578
585
  return;
@@ -1232,7 +1239,15 @@ function drawParticle(data) {
1232
1239
  if (colorStyles.stroke) {
1233
1240
  context.strokeStyle = colorStyles.stroke;
1234
1241
  }
1235
- drawShape(container, context, particle, radius, opacity, delta);
1242
+ const drawData = {
1243
+ container,
1244
+ context,
1245
+ particle,
1246
+ radius,
1247
+ opacity,
1248
+ delta
1249
+ };
1250
+ drawShape(drawData);
1236
1251
  if (strokeWidth > 0) {
1237
1252
  context.stroke();
1238
1253
  }
@@ -1242,11 +1257,19 @@ function drawParticle(data) {
1242
1257
  if (particle.fill) {
1243
1258
  context.fill();
1244
1259
  }
1245
- drawShapeAfterEffect(container, context, particle, radius, opacity, delta);
1260
+ drawShapeAfterEffect(drawData);
1246
1261
  context.globalCompositeOperation = "source-over";
1247
1262
  context.setTransform(1, 0, 0, 1, 0, 0);
1248
1263
  }
1249
- function drawShape(container, context, particle, radius, opacity, delta) {
1264
+ function drawShape(data) {
1265
+ const {
1266
+ container,
1267
+ context,
1268
+ particle,
1269
+ radius,
1270
+ opacity,
1271
+ delta
1272
+ } = data;
1250
1273
  if (!particle.shape) {
1251
1274
  return;
1252
1275
  }
@@ -1254,9 +1277,24 @@ function drawShape(container, context, particle, radius, opacity, delta) {
1254
1277
  if (!drawer) {
1255
1278
  return;
1256
1279
  }
1257
- drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio);
1280
+ drawer.draw({
1281
+ context,
1282
+ particle,
1283
+ radius,
1284
+ opacity,
1285
+ delta,
1286
+ pixelRatio: container.retina.pixelRatio
1287
+ });
1258
1288
  }
1259
- function drawShapeAfterEffect(container, context, particle, radius, opacity, delta) {
1289
+ function drawShapeAfterEffect(data) {
1290
+ const {
1291
+ container,
1292
+ context,
1293
+ particle,
1294
+ radius,
1295
+ opacity,
1296
+ delta
1297
+ } = data;
1260
1298
  if (!particle.shape) {
1261
1299
  return;
1262
1300
  }
@@ -1264,7 +1302,14 @@ function drawShapeAfterEffect(container, context, particle, radius, opacity, del
1264
1302
  if (!drawer || !drawer.afterEffect) {
1265
1303
  return;
1266
1304
  }
1267
- drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio);
1305
+ drawer.afterEffect({
1306
+ context,
1307
+ particle,
1308
+ radius,
1309
+ opacity,
1310
+ delta,
1311
+ pixelRatio: container.retina.pixelRatio
1312
+ });
1268
1313
  }
1269
1314
  function drawPlugin(context, plugin, delta) {
1270
1315
  if (!plugin.draw) {
@@ -3648,7 +3693,17 @@ class InteractionManager {
3648
3693
 
3649
3694
 
3650
3695
 
3651
- const fixOutMode = data => {
3696
+ function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
3697
+ const shapeData = shapeOptions.options[shape];
3698
+ if (!shapeData) {
3699
+ return;
3700
+ }
3701
+ return deepExtend({
3702
+ close: shapeOptions.close,
3703
+ fill: shapeOptions.fill
3704
+ }, itemFromSingleOrMultiple(shapeData, id, reduceDuplicates));
3705
+ }
3706
+ function fixOutMode(data) {
3652
3707
  if (!isInArray(data.outMode, data.checkModes)) {
3653
3708
  return;
3654
3709
  }
@@ -3658,7 +3713,7 @@ const fixOutMode = data => {
3658
3713
  } else if (data.coord < diameter) {
3659
3714
  data.setCb(data.radius);
3660
3715
  }
3661
- };
3716
+ }
3662
3717
  class Particle {
3663
3718
  constructor(engine, id, container, position, overrideOptions, group) {
3664
3719
  this.container = container;
@@ -3783,16 +3838,6 @@ class Particle {
3783
3838
  }
3784
3839
  this.offset = Vector.origin;
3785
3840
  };
3786
- this._loadShapeData = (shapeOptions, reduceDuplicates) => {
3787
- const shapeData = shapeOptions.options[this.shape];
3788
- if (!shapeData) {
3789
- return;
3790
- }
3791
- return deepExtend({
3792
- close: shapeOptions.close,
3793
- fill: shapeOptions.fill
3794
- }, itemFromSingleOrMultiple(shapeData, this.id, reduceDuplicates));
3795
- };
3796
3841
  this._engine = engine;
3797
3842
  this.init(id, position, overrideOptions, group);
3798
3843
  }
@@ -3881,7 +3926,7 @@ class Particle {
3881
3926
  shapeOptions.load(overrideOptions.shape);
3882
3927
  }
3883
3928
  }
3884
- this.shapeData = this._loadShapeData(shapeOptions, reduceDuplicates);
3929
+ this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
3885
3930
  particlesOptions.load(overrideOptions);
3886
3931
  const shapeData = this.shapeData;
3887
3932
  if (shapeData) {
@@ -4192,8 +4237,9 @@ class Particles {
4192
4237
  return false;
4193
4238
  }
4194
4239
  particle.destroy(override);
4240
+ const zIdx = this._zArray.indexOf(particle);
4195
4241
  this._array.splice(index, 1);
4196
- this._zArray = this._zArray.splice(this._zArray.indexOf(particle), 1);
4242
+ this._zArray.splice(zIdx, 1);
4197
4243
  this.pool.push(particle);
4198
4244
  this._engine.dispatchEvent("particleRemoved", {
4199
4245
  container: this._container,
@@ -4300,7 +4346,7 @@ class Particles {
4300
4346
  this.addManualParticles();
4301
4347
  if (!handled) {
4302
4348
  const particlesOptions = options.particles,
4303
- groups = options.particles.groups;
4349
+ groups = particlesOptions.groups;
4304
4350
  for (const group in groups) {
4305
4351
  const groupOptions = groups[group];
4306
4352
  for (let i = this.count, j = 0; j < groupOptions.number?.value && i < particlesOptions.number.value; i++, j++) {
@@ -4476,7 +4522,6 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
4476
4522
  }
4477
4523
  class Container {
4478
4524
  constructor(engine, id, sourceOptions) {
4479
- this.id = id;
4480
4525
  this._intersectionManager = entries => {
4481
4526
  if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
4482
4527
  return;
@@ -4515,6 +4560,7 @@ class Container {
4515
4560
  }
4516
4561
  };
4517
4562
  this._engine = engine;
4563
+ this.id = Symbol(id);
4518
4564
  this.fpsLimit = 120;
4519
4565
  this.smooth = false;
4520
4566
  this._delay = 0;
@@ -4544,9 +4590,7 @@ class Container {
4544
4590
  this._options = loadContainerOptions(this._engine, this);
4545
4591
  this.actualOptions = loadContainerOptions(this._engine, this);
4546
4592
  this._eventListeners = new EventListeners(this);
4547
- if (typeof IntersectionObserver !== "undefined" && IntersectionObserver) {
4548
- this._intersectionObserver = new IntersectionObserver(entries => this._intersectionManager(entries));
4549
- }
4593
+ this._intersectionObserver = safeIntersectionObserver(entries => this._intersectionManager(entries));
4550
4594
  this._engine.dispatchEvent("containerBuilt", {
4551
4595
  container: this
4552
4596
  });
@@ -4989,17 +5033,17 @@ class Engine {
4989
5033
  return res;
4990
5034
  }
4991
5035
  get version() {
4992
- return "3.0.0-beta.1";
5036
+ return "3.0.0-beta.3";
4993
5037
  }
4994
- addConfig(nameOrConfig, config) {
4995
- if (isString(nameOrConfig)) {
4996
- if (config) {
4997
- config.name = nameOrConfig;
4998
- this._configs.set(nameOrConfig, config);
5038
+ addConfig(config) {
5039
+ const name = config.name ?? "default";
5040
+ this._configs.set(name, config);
5041
+ this._eventDispatcher.dispatchEvent("configAdded", {
5042
+ data: {
5043
+ name,
5044
+ config
4999
5045
  }
5000
- } else {
5001
- this._configs.set(nameOrConfig.name ?? "default", nameOrConfig);
5002
- }
5046
+ });
5003
5047
  }
5004
5048
  addEventListener(type, listener) {
5005
5049
  this._eventDispatcher.addEventListener(type, listener);
@@ -5028,44 +5072,11 @@ class Engine {
5028
5072
  (override || !this.getPreset(preset)) && this.presets.set(preset, options);
5029
5073
  await this.refresh(refresh);
5030
5074
  }
5031
- async addShape(shape, drawer, initOrRefresh, afterEffectOrRefresh, destroyOrRefresh, refresh = true) {
5032
- let customDrawer;
5033
- let realRefresh = refresh,
5034
- realInit,
5035
- realAfterEffect,
5036
- realDestroy;
5037
- if (isBoolean(initOrRefresh)) {
5038
- realRefresh = initOrRefresh;
5039
- realInit = undefined;
5040
- } else {
5041
- realInit = initOrRefresh;
5042
- }
5043
- if (isBoolean(afterEffectOrRefresh)) {
5044
- realRefresh = afterEffectOrRefresh;
5045
- realAfterEffect = undefined;
5046
- } else {
5047
- realAfterEffect = afterEffectOrRefresh;
5048
- }
5049
- if (isBoolean(destroyOrRefresh)) {
5050
- realRefresh = destroyOrRefresh;
5051
- realDestroy = undefined;
5052
- } else {
5053
- realDestroy = destroyOrRefresh;
5054
- }
5055
- if (isFunction(drawer)) {
5056
- customDrawer = {
5057
- afterEffect: realAfterEffect,
5058
- destroy: realDestroy,
5059
- draw: drawer,
5060
- init: realInit
5061
- };
5062
- } else {
5063
- customDrawer = drawer;
5064
- }
5075
+ async addShape(shape, drawer, refresh = true) {
5065
5076
  executeOnSingleOrMultiple(shape, type => {
5066
- !this.getShapeDrawer(type) && this.drawers.set(type, customDrawer);
5077
+ !this.getShapeDrawer(type) && this.drawers.set(type, drawer);
5067
5078
  });
5068
- await this.refresh(realRefresh);
5079
+ await this.refresh(refresh);
5069
5080
  }
5070
5081
  clearPlugins(container) {
5071
5082
  this.updaters.delete(container);
@@ -5143,7 +5154,7 @@ class Engine {
5143
5154
  }
5144
5155
  const currentOptions = itemFromSingleOrMultiple(options, index),
5145
5156
  dom = this.dom(),
5146
- oldIndex = dom.findIndex(v => v.id === id);
5157
+ oldIndex = dom.findIndex(v => v.id.description === id);
5147
5158
  if (oldIndex >= 0) {
5148
5159
  const old = this.domItem(oldIndex);
5149
5160
  if (old && !old.destroyed) {
@@ -7284,7 +7295,12 @@ async function loadBaseMover(engine, refresh = true) {
7284
7295
  ;// CONCATENATED MODULE: ../../shapes/circle/dist/browser/CircleDrawer.js
7285
7296
 
7286
7297
  class CircleDrawer {
7287
- draw(context, particle, radius) {
7298
+ draw(data) {
7299
+ const {
7300
+ context,
7301
+ particle,
7302
+ radius
7303
+ } = data;
7288
7304
  if (!particle.circleRange) {
7289
7305
  particle.circleRange = {
7290
7306
  min: 0,
@@ -10088,8 +10104,15 @@ class ImageDrawer {
10088
10104
  }
10089
10105
  this._engine.images.push(image);
10090
10106
  }
10091
- draw(context, particle, radius, opacity, delta) {
10092
- const image = particle.image,
10107
+ draw(data) {
10108
+ const {
10109
+ context,
10110
+ radius,
10111
+ particle,
10112
+ opacity,
10113
+ delta
10114
+ } = data,
10115
+ image = particle.image,
10093
10116
  element = image?.element;
10094
10117
  if (!image) {
10095
10118
  return;
@@ -10525,8 +10548,13 @@ async function loadLifeUpdater(engine, refresh = true) {
10525
10548
  }
10526
10549
  ;// CONCATENATED MODULE: ../../shapes/line/dist/browser/LineDrawer.js
10527
10550
  class LineDrawer {
10528
- draw(context, particle, radius) {
10529
- const shapeData = particle.shapeData;
10551
+ draw(data) {
10552
+ const {
10553
+ context,
10554
+ particle,
10555
+ radius
10556
+ } = data,
10557
+ shapeData = particle.shapeData;
10530
10558
  context.moveTo(-radius / 2, 0);
10531
10559
  context.lineTo(radius / 2, 0);
10532
10560
  context.lineCap = shapeData?.cap ?? "butt";
@@ -11342,8 +11370,13 @@ async function loadParticlesLinksInteraction(engine, refresh = true) {
11342
11370
  ;// CONCATENATED MODULE: ../../shapes/polygon/dist/browser/PolygonDrawerBase.js
11343
11371
 
11344
11372
  class PolygonDrawerBase {
11345
- draw(context, particle, radius) {
11346
- const start = this.getCenter(particle, radius),
11373
+ draw(data) {
11374
+ const {
11375
+ context,
11376
+ particle,
11377
+ radius
11378
+ } = data,
11379
+ start = this.getCenter(particle, radius),
11347
11380
  side = this.getSidesData(particle, radius),
11348
11381
  sideCount = side.count.numerator * side.count.denominator,
11349
11382
  decimalSides = side.count.numerator / side.count.denominator,
@@ -11577,8 +11610,12 @@ async function loadRotateUpdater(engine, refresh = true) {
11577
11610
  ;// CONCATENATED MODULE: ../../shapes/square/dist/browser/SquareDrawer.js
11578
11611
  const fixFactor = Math.sqrt(2);
11579
11612
  class SquareDrawer {
11580
- draw(context, particle, radius) {
11581
- const fixedRadius = radius / fixFactor,
11613
+ draw(data) {
11614
+ const {
11615
+ context,
11616
+ radius
11617
+ } = data,
11618
+ fixedRadius = radius / fixFactor,
11582
11619
  fixedDiameter = fixedRadius * 2;
11583
11620
  context.rect(-fixedRadius, -fixedRadius, fixedDiameter, fixedDiameter);
11584
11621
  }
@@ -11594,8 +11631,13 @@ async function loadSquareShape(engine, refresh = true) {
11594
11631
  ;// CONCATENATED MODULE: ../../shapes/star/dist/browser/StarDrawer.js
11595
11632
 
11596
11633
  class StarDrawer {
11597
- draw(context, particle, radius) {
11598
- const sides = particle.sides,
11634
+ draw(data) {
11635
+ const {
11636
+ context,
11637
+ particle,
11638
+ radius
11639
+ } = data,
11640
+ sides = particle.sides,
11599
11641
  inset = particle.starInset ?? 2;
11600
11642
  context.moveTo(0, 0 - radius);
11601
11643
  for (let i = 0; i < sides; i++) {
@@ -11733,8 +11775,14 @@ async function loadStrokeColorUpdater(engine, refresh = true) {
11733
11775
 
11734
11776
  const validTypes = ["text", "character", "char"];
11735
11777
  class TextDrawer {
11736
- draw(context, particle, radius, opacity) {
11737
- const character = particle.shapeData;
11778
+ draw(data) {
11779
+ const {
11780
+ context,
11781
+ particle,
11782
+ radius,
11783
+ opacity
11784
+ } = data,
11785
+ character = particle.shapeData;
11738
11786
  if (character === undefined) {
11739
11787
  return;
11740
11788
  }