@tsparticles/engine 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.
Files changed (55) hide show
  1. package/README.md +8 -8
  2. package/browser/Core/Container.js +3 -5
  3. package/browser/Core/Engine.js +10 -50
  4. package/browser/Core/Particle.js +13 -13
  5. package/browser/Core/Particles.js +3 -2
  6. package/browser/Utils/CanvasUtils.js +9 -6
  7. package/browser/Utils/Utils.js +6 -0
  8. package/browser/export-types.js +0 -2
  9. package/cjs/Core/Container.js +3 -5
  10. package/cjs/Core/Engine.js +9 -49
  11. package/cjs/Core/Particle.js +13 -13
  12. package/cjs/Core/Particles.js +3 -2
  13. package/cjs/Utils/CanvasUtils.js +9 -6
  14. package/cjs/Utils/Utils.js +8 -1
  15. package/cjs/export-types.js +0 -2
  16. package/esm/Core/Container.js +3 -5
  17. package/esm/Core/Engine.js +10 -50
  18. package/esm/Core/Particle.js +13 -13
  19. package/esm/Core/Particles.js +3 -2
  20. package/esm/Utils/CanvasUtils.js +9 -6
  21. package/esm/Utils/Utils.js +6 -0
  22. package/esm/export-types.js +0 -2
  23. package/package.json +3 -3
  24. package/report.html +23 -5
  25. package/scripts/install.js +8 -8
  26. package/tsparticles.engine.js +83 -72
  27. package/tsparticles.engine.min.js +1 -1
  28. package/tsparticles.engine.min.js.LICENSE.txt +1 -1
  29. package/types/Core/Container.d.ts +2 -2
  30. package/types/Core/Engine.d.ts +3 -4
  31. package/types/Core/Interfaces/IShapeDrawer.d.ts +19 -9
  32. package/types/Core/Particle.d.ts +1 -3
  33. package/types/Enums/Types/EventType.d.ts +1 -0
  34. package/types/Types/CustomEventArgs.d.ts +1 -1
  35. package/types/Utils/CanvasUtils.d.ts +11 -2
  36. package/types/Utils/ColorUtils.d.ts +2 -2
  37. package/types/Utils/Utils.d.ts +4 -3
  38. package/types/export-types.d.ts +0 -2
  39. package/umd/Core/Container.js +4 -6
  40. package/umd/Core/Engine.js +9 -49
  41. package/umd/Core/Particle.js +13 -13
  42. package/umd/Core/Particles.js +3 -2
  43. package/umd/Utils/CanvasUtils.js +9 -6
  44. package/umd/Utils/Utils.js +8 -1
  45. package/umd/export-types.js +1 -3
  46. package/browser/Core/Interfaces/IParticle.js +0 -1
  47. package/browser/Types/ShapeDrawerFunctions.js +0 -1
  48. package/cjs/Core/Interfaces/IParticle.js +0 -2
  49. package/cjs/Types/ShapeDrawerFunctions.js +0 -2
  50. package/esm/Core/Interfaces/IParticle.js +0 -1
  51. package/esm/Types/ShapeDrawerFunctions.js +0 -1
  52. package/types/Core/Interfaces/IParticle.d.ts +0 -48
  53. package/types/Types/ShapeDrawerFunctions.d.ts +0 -10
  54. package/umd/Core/Interfaces/IParticle.js +0 -12
  55. package/umd/Types/ShapeDrawerFunctions.js +0 -12
@@ -8,7 +8,7 @@ try {
8
8
  console.log("You can find more samples on CodePen too: https://codepen.io/collection/DPOage");
9
9
  console.log("If you need documentation you can find it here: https://particles.js.org/docs");
10
10
  console.log(
11
- "Don't forget to star the tsParticles repository, if you like the project and want to support it: https://github.com/matteobruni/tsparticles"
11
+ "Don't forget to star the tsParticles repository, if you like the project and want to support it: https://github.com/tsparticles/tsparticles"
12
12
  );
13
13
 
14
14
  const pkgSettings = require(path.join(process.env.INIT_CWD, "package.json"));
@@ -62,7 +62,7 @@ try {
62
62
  "Found React installed. Please download react-particles to use tsParticles with a component ready to use and easier to configure."
63
63
  );
64
64
  console.log(
65
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/react/README.md"
65
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/react/README.md"
66
66
  );
67
67
  }
68
68
  }
@@ -90,7 +90,7 @@ try {
90
90
  "Found Vue 3.x installed. Please Download vue3-particles to use tsParticles with a component ready to use and easier to configure."
91
91
  );
92
92
  console.log(
93
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/vue3/README.md"
93
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/vue3/README.md"
94
94
  );
95
95
  }
96
96
  } else {
@@ -100,7 +100,7 @@ try {
100
100
  "Found Vue 2.x installed. Please Download vue2-particles to use tsParticles with a component ready to use and easier to configure."
101
101
  );
102
102
  console.log(
103
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/vue/README.md"
103
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/vue/README.md"
104
104
  );
105
105
  }
106
106
  }
@@ -113,7 +113,7 @@ try {
113
113
  "Found Svelte installed. Please Download svelte-particles to use tsParticles with a component ready to use and easier to configure."
114
114
  );
115
115
  console.log(
116
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/svelte/README.md"
116
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/svelte/README.md"
117
117
  );
118
118
  }
119
119
  }
@@ -125,7 +125,7 @@ try {
125
125
  "Found Inferno installed. Please Download inferno-particles to use tsParticles with a component ready to use and easier to configure."
126
126
  );
127
127
  console.log(
128
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/inferno/README.md"
128
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/inferno/README.md"
129
129
  );
130
130
  }
131
131
  }
@@ -137,7 +137,7 @@ try {
137
137
  "Found Preact installed. Please Download preact-particles to use tsParticles with a component ready to use and easier to configure."
138
138
  );
139
139
  console.log(
140
- "You can read more about the component here: https://github.com/matteobruni/tsparticles/blob/main/components/preact/README.md"
140
+ "You can read more about the component here: https://github.com/tsparticles/tsparticles/blob/main/components/preact/README.md"
141
141
  );
142
142
  }
143
143
  }
@@ -149,7 +149,7 @@ try {
149
149
  "Found jQuery installed. Please Download jquery-particles to use tsParticles with a plugin ready to use and easier to configure."
150
150
  );
151
151
  console.log(
152
- "You can read more about the plugin here: https://github.com/matteobruni/tsparticles/blob/main/components/jquery/README.md"
152
+ "You can read more about the plugin here: https://github.com/tsparticles/tsparticles/blob/main/components/jquery/README.md"
153
153
  );
154
154
  }
155
155
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * tsParticles Engine v3.0.0-beta.1
2
+ * tsParticles Engine v3.0.0-beta.3
3
3
  * Author: Matteo Bruni
4
4
  * MIT license: https://opensource.org/licenses/MIT
5
5
  * Website: https://particles.js.org/
@@ -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) {