@tsparticles/slim 3.0.0-beta.2 → 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.2
7
+ * v3.0.0-beta.3
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -206,6 +206,7 @@ __webpack_require__.d(__webpack_exports__, {
206
206
  rectBounce: () => (/* reexport */ rectBounce),
207
207
  resizeEvent: () => (/* reexport */ resizeEvent),
208
208
  rgbToHsl: () => (/* reexport */ rgbToHsl),
209
+ safeIntersectionObserver: () => (/* reexport */ safeIntersectionObserver),
209
210
  safeMatchMedia: () => (/* reexport */ safeMatchMedia),
210
211
  safeMutationObserver: () => (/* reexport */ safeMutationObserver),
211
212
  setLogger: () => (/* reexport */ setLogger),
@@ -572,6 +573,12 @@ function safeMatchMedia(query) {
572
573
  }
573
574
  return matchMedia(query);
574
575
  }
576
+ function safeIntersectionObserver(callback) {
577
+ if (isSsr() || typeof IntersectionObserver === "undefined") {
578
+ return;
579
+ }
580
+ return new IntersectionObserver(callback);
581
+ }
575
582
  function safeMutationObserver(callback) {
576
583
  if (isSsr() || typeof MutationObserver === "undefined") {
577
584
  return;
@@ -1231,7 +1238,15 @@ function drawParticle(data) {
1231
1238
  if (colorStyles.stroke) {
1232
1239
  context.strokeStyle = colorStyles.stroke;
1233
1240
  }
1234
- drawShape(container, context, particle, radius, opacity, delta);
1241
+ const drawData = {
1242
+ container,
1243
+ context,
1244
+ particle,
1245
+ radius,
1246
+ opacity,
1247
+ delta
1248
+ };
1249
+ drawShape(drawData);
1235
1250
  if (strokeWidth > 0) {
1236
1251
  context.stroke();
1237
1252
  }
@@ -1241,11 +1256,19 @@ function drawParticle(data) {
1241
1256
  if (particle.fill) {
1242
1257
  context.fill();
1243
1258
  }
1244
- drawShapeAfterEffect(container, context, particle, radius, opacity, delta);
1259
+ drawShapeAfterEffect(drawData);
1245
1260
  context.globalCompositeOperation = "source-over";
1246
1261
  context.setTransform(1, 0, 0, 1, 0, 0);
1247
1262
  }
1248
- function drawShape(container, context, particle, radius, opacity, delta) {
1263
+ function drawShape(data) {
1264
+ const {
1265
+ container,
1266
+ context,
1267
+ particle,
1268
+ radius,
1269
+ opacity,
1270
+ delta
1271
+ } = data;
1249
1272
  if (!particle.shape) {
1250
1273
  return;
1251
1274
  }
@@ -1253,9 +1276,24 @@ function drawShape(container, context, particle, radius, opacity, delta) {
1253
1276
  if (!drawer) {
1254
1277
  return;
1255
1278
  }
1256
- drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio);
1279
+ drawer.draw({
1280
+ context,
1281
+ particle,
1282
+ radius,
1283
+ opacity,
1284
+ delta,
1285
+ pixelRatio: container.retina.pixelRatio
1286
+ });
1257
1287
  }
1258
- function drawShapeAfterEffect(container, context, particle, radius, opacity, delta) {
1288
+ function drawShapeAfterEffect(data) {
1289
+ const {
1290
+ container,
1291
+ context,
1292
+ particle,
1293
+ radius,
1294
+ opacity,
1295
+ delta
1296
+ } = data;
1259
1297
  if (!particle.shape) {
1260
1298
  return;
1261
1299
  }
@@ -1263,7 +1301,14 @@ function drawShapeAfterEffect(container, context, particle, radius, opacity, del
1263
1301
  if (!drawer || !drawer.afterEffect) {
1264
1302
  return;
1265
1303
  }
1266
- drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio);
1304
+ drawer.afterEffect({
1305
+ context,
1306
+ particle,
1307
+ radius,
1308
+ opacity,
1309
+ delta,
1310
+ pixelRatio: container.retina.pixelRatio
1311
+ });
1267
1312
  }
1268
1313
  function drawPlugin(context, plugin, delta) {
1269
1314
  if (!plugin.draw) {
@@ -3647,7 +3692,17 @@ class InteractionManager {
3647
3692
 
3648
3693
 
3649
3694
 
3650
- const fixOutMode = data => {
3695
+ function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
3696
+ const shapeData = shapeOptions.options[shape];
3697
+ if (!shapeData) {
3698
+ return;
3699
+ }
3700
+ return deepExtend({
3701
+ close: shapeOptions.close,
3702
+ fill: shapeOptions.fill
3703
+ }, itemFromSingleOrMultiple(shapeData, id, reduceDuplicates));
3704
+ }
3705
+ function fixOutMode(data) {
3651
3706
  if (!isInArray(data.outMode, data.checkModes)) {
3652
3707
  return;
3653
3708
  }
@@ -3657,7 +3712,7 @@ const fixOutMode = data => {
3657
3712
  } else if (data.coord < diameter) {
3658
3713
  data.setCb(data.radius);
3659
3714
  }
3660
- };
3715
+ }
3661
3716
  class Particle {
3662
3717
  constructor(engine, id, container, position, overrideOptions, group) {
3663
3718
  this.container = container;
@@ -3782,16 +3837,6 @@ class Particle {
3782
3837
  }
3783
3838
  this.offset = Vector.origin;
3784
3839
  };
3785
- this._loadShapeData = (shapeOptions, reduceDuplicates) => {
3786
- const shapeData = shapeOptions.options[this.shape];
3787
- if (!shapeData) {
3788
- return;
3789
- }
3790
- return deepExtend({
3791
- close: shapeOptions.close,
3792
- fill: shapeOptions.fill
3793
- }, itemFromSingleOrMultiple(shapeData, this.id, reduceDuplicates));
3794
- };
3795
3840
  this._engine = engine;
3796
3841
  this.init(id, position, overrideOptions, group);
3797
3842
  }
@@ -3880,7 +3925,7 @@ class Particle {
3880
3925
  shapeOptions.load(overrideOptions.shape);
3881
3926
  }
3882
3927
  }
3883
- this.shapeData = this._loadShapeData(shapeOptions, reduceDuplicates);
3928
+ this.shapeData = loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates);
3884
3929
  particlesOptions.load(overrideOptions);
3885
3930
  const shapeData = this.shapeData;
3886
3931
  if (shapeData) {
@@ -4476,7 +4521,6 @@ function loadContainerOptions(engine, container, ...sourceOptionsArr) {
4476
4521
  }
4477
4522
  class Container {
4478
4523
  constructor(engine, id, sourceOptions) {
4479
- this.id = id;
4480
4524
  this._intersectionManager = entries => {
4481
4525
  if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
4482
4526
  return;
@@ -4515,6 +4559,7 @@ class Container {
4515
4559
  }
4516
4560
  };
4517
4561
  this._engine = engine;
4562
+ this.id = Symbol(id);
4518
4563
  this.fpsLimit = 120;
4519
4564
  this.smooth = false;
4520
4565
  this._delay = 0;
@@ -4544,9 +4589,7 @@ class Container {
4544
4589
  this._options = loadContainerOptions(this._engine, this);
4545
4590
  this.actualOptions = loadContainerOptions(this._engine, this);
4546
4591
  this._eventListeners = new EventListeners(this);
4547
- if (typeof IntersectionObserver !== "undefined" && IntersectionObserver) {
4548
- this._intersectionObserver = new IntersectionObserver(entries => this._intersectionManager(entries));
4549
- }
4592
+ this._intersectionObserver = safeIntersectionObserver(entries => this._intersectionManager(entries));
4550
4593
  this._engine.dispatchEvent("containerBuilt", {
4551
4594
  container: this
4552
4595
  });
@@ -4989,17 +5032,17 @@ class Engine {
4989
5032
  return res;
4990
5033
  }
4991
5034
  get version() {
4992
- return "3.0.0-beta.2";
5035
+ return "3.0.0-beta.3";
4993
5036
  }
4994
- addConfig(nameOrConfig, config) {
4995
- if (isString(nameOrConfig)) {
4996
- if (config) {
4997
- config.name = nameOrConfig;
4998
- this._configs.set(nameOrConfig, config);
5037
+ addConfig(config) {
5038
+ const name = config.name ?? "default";
5039
+ this._configs.set(name, config);
5040
+ this._eventDispatcher.dispatchEvent("configAdded", {
5041
+ data: {
5042
+ name,
5043
+ config
4999
5044
  }
5000
- } else {
5001
- this._configs.set(nameOrConfig.name ?? "default", nameOrConfig);
5002
- }
5045
+ });
5003
5046
  }
5004
5047
  addEventListener(type, listener) {
5005
5048
  this._eventDispatcher.addEventListener(type, listener);
@@ -5028,44 +5071,11 @@ class Engine {
5028
5071
  (override || !this.getPreset(preset)) && this.presets.set(preset, options);
5029
5072
  await this.refresh(refresh);
5030
5073
  }
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
- }
5074
+ async addShape(shape, drawer, refresh = true) {
5065
5075
  executeOnSingleOrMultiple(shape, type => {
5066
- !this.getShapeDrawer(type) && this.drawers.set(type, customDrawer);
5076
+ !this.getShapeDrawer(type) && this.drawers.set(type, drawer);
5067
5077
  });
5068
- await this.refresh(realRefresh);
5078
+ await this.refresh(refresh);
5069
5079
  }
5070
5080
  clearPlugins(container) {
5071
5081
  this.updaters.delete(container);
@@ -5143,7 +5153,7 @@ class Engine {
5143
5153
  }
5144
5154
  const currentOptions = itemFromSingleOrMultiple(options, index),
5145
5155
  dom = this.dom(),
5146
- oldIndex = dom.findIndex(v => v.id === id);
5156
+ oldIndex = dom.findIndex(v => v.id.description === id);
5147
5157
  if (oldIndex >= 0) {
5148
5158
  const old = this.domItem(oldIndex);
5149
5159
  if (old && !old.destroyed) {
@@ -5750,7 +5760,12 @@ async function loadBaseMover(engine, refresh = true) {
5750
5760
  ;// CONCATENATED MODULE: ../../shapes/circle/dist/browser/CircleDrawer.js
5751
5761
 
5752
5762
  class CircleDrawer {
5753
- draw(context, particle, radius) {
5763
+ draw(data) {
5764
+ const {
5765
+ context,
5766
+ particle,
5767
+ radius
5768
+ } = data;
5754
5769
  if (!particle.circleRange) {
5755
5770
  particle.circleRange = {
5756
5771
  min: 0,
@@ -8554,8 +8569,15 @@ class ImageDrawer {
8554
8569
  }
8555
8570
  this._engine.images.push(image);
8556
8571
  }
8557
- draw(context, particle, radius, opacity, delta) {
8558
- const image = particle.image,
8572
+ draw(data) {
8573
+ const {
8574
+ context,
8575
+ radius,
8576
+ particle,
8577
+ opacity,
8578
+ delta
8579
+ } = data,
8580
+ image = particle.image,
8559
8581
  element = image?.element;
8560
8582
  if (!image) {
8561
8583
  return;
@@ -8991,8 +9013,13 @@ async function loadLifeUpdater(engine, refresh = true) {
8991
9013
  }
8992
9014
  ;// CONCATENATED MODULE: ../../shapes/line/dist/browser/LineDrawer.js
8993
9015
  class LineDrawer {
8994
- draw(context, particle, radius) {
8995
- const shapeData = particle.shapeData;
9016
+ draw(data) {
9017
+ const {
9018
+ context,
9019
+ particle,
9020
+ radius
9021
+ } = data,
9022
+ shapeData = particle.shapeData;
8996
9023
  context.moveTo(-radius / 2, 0);
8997
9024
  context.lineTo(radius / 2, 0);
8998
9025
  context.lineCap = shapeData?.cap ?? "butt";
@@ -9808,8 +9835,13 @@ async function loadParticlesLinksInteraction(engine, refresh = true) {
9808
9835
  ;// CONCATENATED MODULE: ../../shapes/polygon/dist/browser/PolygonDrawerBase.js
9809
9836
 
9810
9837
  class PolygonDrawerBase {
9811
- draw(context, particle, radius) {
9812
- const start = this.getCenter(particle, radius),
9838
+ draw(data) {
9839
+ const {
9840
+ context,
9841
+ particle,
9842
+ radius
9843
+ } = data,
9844
+ start = this.getCenter(particle, radius),
9813
9845
  side = this.getSidesData(particle, radius),
9814
9846
  sideCount = side.count.numerator * side.count.denominator,
9815
9847
  decimalSides = side.count.numerator / side.count.denominator,
@@ -10043,8 +10075,12 @@ async function loadRotateUpdater(engine, refresh = true) {
10043
10075
  ;// CONCATENATED MODULE: ../../shapes/square/dist/browser/SquareDrawer.js
10044
10076
  const fixFactor = Math.sqrt(2);
10045
10077
  class SquareDrawer {
10046
- draw(context, particle, radius) {
10047
- const fixedRadius = radius / fixFactor,
10078
+ draw(data) {
10079
+ const {
10080
+ context,
10081
+ radius
10082
+ } = data,
10083
+ fixedRadius = radius / fixFactor,
10048
10084
  fixedDiameter = fixedRadius * 2;
10049
10085
  context.rect(-fixedRadius, -fixedRadius, fixedDiameter, fixedDiameter);
10050
10086
  }
@@ -10060,8 +10096,13 @@ async function loadSquareShape(engine, refresh = true) {
10060
10096
  ;// CONCATENATED MODULE: ../../shapes/star/dist/browser/StarDrawer.js
10061
10097
 
10062
10098
  class StarDrawer {
10063
- draw(context, particle, radius) {
10064
- const sides = particle.sides,
10099
+ draw(data) {
10100
+ const {
10101
+ context,
10102
+ particle,
10103
+ radius
10104
+ } = data,
10105
+ sides = particle.sides,
10065
10106
  inset = particle.starInset ?? 2;
10066
10107
  context.moveTo(0, 0 - radius);
10067
10108
  for (let i = 0; i < sides; i++) {
@@ -10199,8 +10240,14 @@ async function loadStrokeColorUpdater(engine, refresh = true) {
10199
10240
 
10200
10241
  const validTypes = ["text", "character", "char"];
10201
10242
  class TextDrawer {
10202
- draw(context, particle, radius, opacity) {
10203
- const character = particle.shapeData;
10243
+ draw(data) {
10244
+ const {
10245
+ context,
10246
+ particle,
10247
+ radius,
10248
+ opacity
10249
+ } = data,
10250
+ character = particle.shapeData;
10204
10251
  if (character === undefined) {
10205
10252
  return;
10206
10253
  }