@tsparticles/updater-out-modes 3.1.0 → 3.2.1

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 (58) hide show
  1. package/103.min.js +2 -0
  2. package/103.min.js.LICENSE.txt +1 -0
  3. package/388.min.js +2 -0
  4. package/388.min.js.LICENSE.txt +1 -0
  5. package/53.min.js +2 -0
  6. package/53.min.js.LICENSE.txt +1 -0
  7. package/569.min.js +2 -0
  8. package/569.min.js.LICENSE.txt +1 -0
  9. package/886.min.js +2 -0
  10. package/886.min.js.LICENSE.txt +1 -0
  11. package/920.min.js +2 -0
  12. package/920.min.js.LICENSE.txt +1 -0
  13. package/browser/BounceOutMode.js +3 -8
  14. package/browser/DestroyOutMode.js +3 -3
  15. package/browser/NoneOutMode.js +3 -4
  16. package/browser/OutOfCanvasUpdater.js +34 -18
  17. package/browser/OutOutMode.js +2 -1
  18. package/browser/Utils.js +2 -8
  19. package/browser/index.js +4 -2
  20. package/cjs/BounceOutMode.js +28 -10
  21. package/cjs/DestroyOutMode.js +3 -3
  22. package/cjs/NoneOutMode.js +3 -4
  23. package/cjs/OutOfCanvasUpdater.js +57 -18
  24. package/cjs/OutOutMode.js +2 -1
  25. package/cjs/Utils.js +2 -8
  26. package/cjs/index.js +27 -2
  27. package/dist_browser_BounceOutMode_js.js +30 -0
  28. package/dist_browser_DestroyOutMode_js.js +30 -0
  29. package/dist_browser_NoneOutMode_js.js +30 -0
  30. package/dist_browser_OutOfCanvasUpdater_js.js +30 -0
  31. package/dist_browser_OutOutMode_js.js +30 -0
  32. package/dist_browser_Utils_js.js +30 -0
  33. package/esm/BounceOutMode.js +3 -8
  34. package/esm/DestroyOutMode.js +3 -3
  35. package/esm/NoneOutMode.js +3 -4
  36. package/esm/OutOfCanvasUpdater.js +34 -18
  37. package/esm/OutOutMode.js +2 -1
  38. package/esm/Utils.js +2 -8
  39. package/esm/index.js +4 -2
  40. package/package.json +2 -2
  41. package/report.html +3 -3
  42. package/tsparticles.updater.out-modes.js +241 -360
  43. package/tsparticles.updater.out-modes.min.js +1 -1
  44. package/tsparticles.updater.out-modes.min.js.LICENSE.txt +1 -1
  45. package/types/BounceOutMode.d.ts +3 -3
  46. package/types/DestroyOutMode.d.ts +3 -3
  47. package/types/IBounceData.d.ts +2 -2
  48. package/types/IOutModeManager.d.ts +3 -3
  49. package/types/NoneOutMode.d.ts +3 -3
  50. package/types/OutOfCanvasUpdater.d.ts +2 -2
  51. package/types/OutOutMode.d.ts +3 -3
  52. package/umd/BounceOutMode.js +30 -11
  53. package/umd/DestroyOutMode.js +3 -3
  54. package/umd/NoneOutMode.js +3 -4
  55. package/umd/OutOfCanvasUpdater.js +59 -19
  56. package/umd/OutOutMode.js +2 -1
  57. package/umd/Utils.js +2 -8
  58. package/umd/index.js +29 -3
package/103.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 103.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[103],{103:(t,i,o)=>{o.d(i,{bounceHorizontal:()=>s,bounceVertical:()=>r});var e=o(533);const n=0,c=0;function s(t){if("bounce"!==t.outMode&&"split"!==t.outMode||"left"!==t.direction&&"right"!==t.direction)return;t.bounds.right<c&&"left"===t.direction?t.particle.position.x=t.size+t.offset.x:t.bounds.left>t.canvasSize.width&&"right"===t.direction&&(t.particle.position.x=t.canvasSize.width-t.size-t.offset.x);const i=t.particle.velocity.x;let o=!1;if("right"===t.direction&&t.bounds.right>=t.canvasSize.width&&i>n||"left"===t.direction&&t.bounds.left<=c&&i<n){const i=(0,e.getRangeValue)(t.particle.options.bounce.horizontal.value);t.particle.velocity.x*=-i,o=!0}if(!o)return;const s=t.offset.x+t.size;t.bounds.right>=t.canvasSize.width&&"right"===t.direction?t.particle.position.x=t.canvasSize.width-s:t.bounds.left<=c&&"left"===t.direction&&(t.particle.position.x=s),"split"===t.outMode&&t.particle.destroy()}function r(t){if("bounce"!==t.outMode&&"split"!==t.outMode||"bottom"!==t.direction&&"top"!==t.direction)return;t.bounds.bottom<c&&"top"===t.direction?t.particle.position.y=t.size+t.offset.y:t.bounds.top>t.canvasSize.height&&"bottom"===t.direction&&(t.particle.position.y=t.canvasSize.height-t.size-t.offset.y);const i=t.particle.velocity.y;let o=!1;if("bottom"===t.direction&&t.bounds.bottom>=t.canvasSize.height&&i>n||"top"===t.direction&&t.bounds.top<=c&&i<n){const i=(0,e.getRangeValue)(t.particle.options.bounce.vertical.value);t.particle.velocity.y*=-i,o=!0}if(!o)return;const s=t.offset.y+t.size;t.bounds.bottom>=t.canvasSize.height&&"bottom"===t.direction?t.particle.position.y=t.canvasSize.height-s:t.bounds.top<=c&&"top"===t.direction&&(t.particle.position.y=s),"split"===t.outMode&&t.particle.destroy()}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
package/388.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 388.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[388],{388:(t,i,e)=>{e.d(i,{NoneOutMode:()=>s});var o=e(533);class s{constructor(t){this.container=t,this.modes=["none"]}async update(t,i,e,s){if(!this.modes.includes(s))return;if((t.options.move.distance.horizontal&&("left"===i||"right"===i))??(t.options.move.distance.vertical&&("top"===i||"bottom"===i)))return;const n=t.options.move.gravity,r=this.container,a=r.canvas.size,c=t.getRadius();if(n.enable){const e=t.position;(!n.inverse&&e.y>a.height+c&&"bottom"===i||n.inverse&&e.y<-c&&"top"===i)&&r.particles.remove(t)}else{if(t.velocity.y>0&&t.position.y<=a.height+c||t.velocity.y<0&&t.position.y>=-c||t.velocity.x>0&&t.position.x<=a.width+c||t.velocity.x<0&&t.position.x>=-c)return;(0,o.isPointInside)(t.position,r.canvas.size,o.Vector.origin,c,i)||r.particles.remove(t)}await Promise.resolve()}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
package/53.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 53.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[53],{53:(t,e,s)=>{s.d(e,{OutOfCanvasUpdater:()=>o});const a=(t,e)=>t.default===e||t.bottom===e||t.left===e||t.right===e||t.top===e;class o{constructor(t){this._updateOutMode=async(t,e,s,a)=>{for(const o of this.updaters)await o.update(t,a,e,s)},this.container=t,this.updaters=[]}async init(t){this.updaters=[];const e=t.options.move.outModes;if(a(e,"bounce")){const{BounceOutMode:t}=await s.e(569).then(s.bind(s,569));this.updaters.push(new t(this.container))}else if(a(e,"out")){const{OutOutMode:t}=await s.e(886).then(s.bind(s,886));this.updaters.push(new t(this.container))}else if(a(e,"destroy")){const{DestroyOutMode:t}=await s.e(920).then(s.bind(s,920));this.updaters.push(new t(this.container))}else if(a(e,"none")){const{NoneOutMode:t}=await s.e(388).then(s.bind(s,388));this.updaters.push(new t(this.container))}}isEnabled(t){return!t.destroyed&&!t.spawning}async update(t,e){const s=t.options.move.outModes;await this._updateOutMode(t,e,s.bottom??s.default,"bottom"),await this._updateOutMode(t,e,s.left??s.default,"left"),await this._updateOutMode(t,e,s.right??s.default,"right"),await this._updateOutMode(t,e,s.top??s.default,"top")}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
package/569.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 569.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[569],{569:(e,t,o)=>{o.d(t,{BounceOutMode:()=>i});var s=o(533);class i{constructor(e){this.container=e,this.modes=["bounce","split"]}async update(e,t,i,n){if(!this.modes.includes(n))return;const a=this.container;let c=!1;for(const[,o]of a.plugins)if(void 0!==o.particleBounce&&(c=await o.particleBounce(e,i,t)),c)break;if(c)return;const u=e.getPosition(),r=e.offset,d=e.getRadius(),l=(0,s.calculateBounds)(u,d),p=a.canvas.size,{bounceHorizontal:f,bounceVertical:h}=await o.e(103).then(o.bind(o,103));f({particle:e,outMode:n,direction:t,bounds:l,canvasSize:p,offset:r,size:d}),h({particle:e,outMode:n,direction:t,bounds:l,canvasSize:p,offset:r,size:d})}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
package/886.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 886.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[886],{886:(t,i,o)=>{o.d(i,{OutOutMode:()=>n});var e=o(533);class n{constructor(t){this.container=t,this.modes=["out"]}async update(t,i,o,n){if(!this.modes.includes(n))return;const s=this.container;switch(t.outType){case"inside":{const{x:i,y:o}=t.velocity,n=e.Vector.origin;n.length=t.moveCenter.radius,n.angle=t.velocity.angle+Math.PI,n.addTo(e.Vector.create(t.moveCenter));const{dx:a,dy:r}=(0,e.getDistances)(t.position,n);if(i<=0&&a>=0||o<=0&&r>=0||i>=0&&a<=0||o>=0&&r<=0)return;t.position.x=Math.floor((0,e.randomInRange)({min:0,max:s.canvas.size.width})),t.position.y=Math.floor((0,e.randomInRange)({min:0,max:s.canvas.size.height}));const{dx:d,dy:c}=(0,e.getDistances)(t.position,t.moveCenter);t.direction=Math.atan2(-c,-d),t.velocity.angle=t.direction;break}default:if((0,e.isPointInside)(t.position,s.canvas.size,e.Vector.origin,t.getRadius(),i))return;switch(t.outType){case"outside":{t.position.x=Math.floor((0,e.randomInRange)({min:-t.moveCenter.radius,max:t.moveCenter.radius}))+t.moveCenter.x,t.position.y=Math.floor((0,e.randomInRange)({min:-t.moveCenter.radius,max:t.moveCenter.radius}))+t.moveCenter.y;const{dx:i,dy:o}=(0,e.getDistances)(t.position,t.moveCenter);t.moveCenter.radius&&(t.direction=Math.atan2(o,i),t.velocity.angle=t.direction);break}case"normal":{const o=t.options.move.warp,n=s.canvas.size,a={bottom:n.height+t.getRadius()+t.offset.y,left:-t.getRadius()-t.offset.x,right:n.width+t.getRadius()+t.offset.x,top:-t.getRadius()-t.offset.y},r=t.getRadius(),d=(0,e.calculateBounds)(t.position,r);"right"===i&&d.left>n.width+t.offset.x?(t.position.x=a.left,t.initialPosition.x=t.position.x,o||(t.position.y=(0,e.getRandom)()*n.height,t.initialPosition.y=t.position.y)):"left"===i&&d.right<-t.offset.x&&(t.position.x=a.right,t.initialPosition.x=t.position.x,o||(t.position.y=(0,e.getRandom)()*n.height,t.initialPosition.y=t.position.y)),"bottom"===i&&d.top>n.height+t.offset.y?(o||(t.position.x=(0,e.getRandom)()*n.width,t.initialPosition.x=t.position.x),t.position.y=a.top,t.initialPosition.y=t.position.y):"top"===i&&d.bottom<-t.offset.y&&(o||(t.position.x=(0,e.getRandom)()*n.width,t.initialPosition.x=t.position.x),t.position.y=a.bottom,t.initialPosition.y=t.position.y);break}}}await Promise.resolve()}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
package/920.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 920.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[920],{920:(e,s,t)=>{t.d(s,{DestroyOutMode:()=>o});var i=t(533);class o{constructor(e){this.container=e,this.modes=["destroy"]}async update(e,s,t,o){if(!this.modes.includes(o))return;const r=this.container;switch(e.outType){case"normal":case"outside":if((0,i.isPointInside)(e.position,r.canvas.size,i.Vector.origin,e.getRadius(),s))return;break;case"inside":{const{dx:s,dy:t}=(0,i.getDistances)(e.position,e.moveCenter),{x:o,y:r}=e.velocity;if(o<0&&s>e.moveCenter.radius||r<0&&t>e.moveCenter.radius||o>=0&&s<-e.moveCenter.radius||r>=0&&t<-e.moveCenter.radius)return;break}}r.particles.remove(e,void 0,!0),await Promise.resolve()}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Out Modes Updater v3.2.1 by Matteo Bruni */
@@ -1,18 +1,13 @@
1
1
  import { calculateBounds, } from "@tsparticles/engine";
2
- import { bounceHorizontal, bounceVertical } from "./Utils.js";
3
2
  export class BounceOutMode {
4
3
  constructor(container) {
5
4
  this.container = container;
6
5
  this.modes = [
7
6
  "bounce",
8
- "bounce-vertical",
9
- "bounce-horizontal",
10
- "bounceVertical",
11
- "bounceHorizontal",
12
7
  "split",
13
8
  ];
14
9
  }
15
- update(particle, direction, delta, outMode) {
10
+ async update(particle, direction, delta, outMode) {
16
11
  if (!this.modes.includes(outMode)) {
17
12
  return;
18
13
  }
@@ -20,7 +15,7 @@ export class BounceOutMode {
20
15
  let handled = false;
21
16
  for (const [, plugin] of container.plugins) {
22
17
  if (plugin.particleBounce !== undefined) {
23
- handled = plugin.particleBounce(particle, delta, direction);
18
+ handled = await plugin.particleBounce(particle, delta, direction);
24
19
  }
25
20
  if (handled) {
26
21
  break;
@@ -29,7 +24,7 @@ export class BounceOutMode {
29
24
  if (handled) {
30
25
  return;
31
26
  }
32
- const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
27
+ const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, { bounceHorizontal, bounceVertical } = await import("./Utils.js");
33
28
  bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
34
29
  bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
35
30
  }
@@ -5,7 +5,7 @@ export class DestroyOutMode {
5
5
  this.container = container;
6
6
  this.modes = ["destroy"];
7
7
  }
8
- update(particle, direction, _delta, outMode) {
8
+ async update(particle, direction, _delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
10
10
  return;
11
11
  }
@@ -18,8 +18,7 @@ export class DestroyOutMode {
18
18
  }
19
19
  break;
20
20
  case "inside": {
21
- const { dx, dy } = getDistances(particle.position, particle.moveCenter);
22
- const { x: vx, y: vy } = particle.velocity;
21
+ const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
23
22
  if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
24
23
  (vy < minVelocity && dy > particle.moveCenter.radius) ||
25
24
  (vx >= minVelocity && dx < -particle.moveCenter.radius) ||
@@ -30,5 +29,6 @@ export class DestroyOutMode {
30
29
  }
31
30
  }
32
31
  container.particles.remove(particle, undefined, true);
32
+ await Promise.resolve();
33
33
  }
34
34
  }
@@ -5,7 +5,7 @@ export class NoneOutMode {
5
5
  this.container = container;
6
6
  this.modes = ["none"];
7
7
  }
8
- update(particle, direction, delta, outMode) {
8
+ async update(particle, direction, delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
10
10
  return;
11
11
  }
@@ -15,9 +15,7 @@ export class NoneOutMode {
15
15
  (direction === "top" || direction === "bottom"))) {
16
16
  return;
17
17
  }
18
- const gravityOptions = particle.options.move.gravity, container = this.container;
19
- const canvasSize = container.canvas.size;
20
- const pRadius = particle.getRadius();
18
+ const gravityOptions = particle.options.move.gravity, container = this.container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
21
19
  if (!gravityOptions.enable) {
22
20
  if ((particle.velocity.y > minVelocity && particle.position.y <= canvasSize.height + pRadius) ||
23
21
  (particle.velocity.y < minVelocity && particle.position.y >= -pRadius) ||
@@ -38,5 +36,6 @@ export class NoneOutMode {
38
36
  container.particles.remove(particle);
39
37
  }
40
38
  }
39
+ await Promise.resolve();
41
40
  }
42
41
  }
@@ -1,32 +1,48 @@
1
- import { BounceOutMode } from "./BounceOutMode.js";
2
- import { DestroyOutMode } from "./DestroyOutMode.js";
3
- import { NoneOutMode } from "./NoneOutMode.js";
4
- import { OutOutMode } from "./OutOutMode.js";
1
+ const checkOutMode = (outModes, outMode) => {
2
+ return (outModes.default === outMode ||
3
+ outModes.bottom === outMode ||
4
+ outModes.left === outMode ||
5
+ outModes.right === outMode ||
6
+ outModes.top === outMode);
7
+ };
5
8
  export class OutOfCanvasUpdater {
6
9
  constructor(container) {
7
- this._updateOutMode = (particle, delta, outMode, direction) => {
10
+ this._updateOutMode = async (particle, delta, outMode, direction) => {
8
11
  for (const updater of this.updaters) {
9
- updater.update(particle, direction, delta, outMode);
12
+ await updater.update(particle, direction, delta, outMode);
10
13
  }
11
14
  };
12
15
  this.container = container;
13
- this.updaters = [
14
- new BounceOutMode(container),
15
- new DestroyOutMode(container),
16
- new OutOutMode(container),
17
- new NoneOutMode(container),
18
- ];
16
+ this.updaters = [];
19
17
  }
20
- init() {
18
+ async init(particle) {
19
+ this.updaters = [];
20
+ const outModes = particle.options.move.outModes;
21
+ if (checkOutMode(outModes, "bounce")) {
22
+ const { BounceOutMode } = await import("./BounceOutMode.js");
23
+ this.updaters.push(new BounceOutMode(this.container));
24
+ }
25
+ else if (checkOutMode(outModes, "out")) {
26
+ const { OutOutMode } = await import("./OutOutMode.js");
27
+ this.updaters.push(new OutOutMode(this.container));
28
+ }
29
+ else if (checkOutMode(outModes, "destroy")) {
30
+ const { DestroyOutMode } = await import("./DestroyOutMode.js");
31
+ this.updaters.push(new DestroyOutMode(this.container));
32
+ }
33
+ else if (checkOutMode(outModes, "none")) {
34
+ const { NoneOutMode } = await import("./NoneOutMode.js");
35
+ this.updaters.push(new NoneOutMode(this.container));
36
+ }
21
37
  }
22
38
  isEnabled(particle) {
23
39
  return !particle.destroyed && !particle.spawning;
24
40
  }
25
- update(particle, delta) {
41
+ async update(particle, delta) {
26
42
  const outModes = particle.options.move.outModes;
27
- this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
28
- this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
29
- this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
30
- this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
43
+ await this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
44
+ await this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
45
+ await this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
46
+ await this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
31
47
  }
32
48
  }
@@ -5,7 +5,7 @@ export class OutOutMode {
5
5
  this.container = container;
6
6
  this.modes = ["out"];
7
7
  }
8
- update(particle, direction, delta, outMode) {
8
+ async update(particle, direction, delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
10
10
  return;
11
11
  }
@@ -107,5 +107,6 @@ export class OutOutMode {
107
107
  break;
108
108
  }
109
109
  }
110
+ await Promise.resolve();
110
111
  }
111
112
  }
package/browser/Utils.js CHANGED
@@ -1,10 +1,7 @@
1
1
  import { getRangeValue } from "@tsparticles/engine";
2
2
  const minVelocity = 0, boundsMin = 0;
3
3
  export function bounceHorizontal(data) {
4
- if ((data.outMode !== "bounce" &&
5
- data.outMode !== "bounce-horizontal" &&
6
- data.outMode !== "bounceHorizontal" &&
7
- data.outMode !== "split") ||
4
+ if ((data.outMode !== "bounce" && data.outMode !== "split") ||
8
5
  (data.direction !== "left" && data.direction !== "right")) {
9
6
  return;
10
7
  }
@@ -39,10 +36,7 @@ export function bounceHorizontal(data) {
39
36
  }
40
37
  }
41
38
  export function bounceVertical(data) {
42
- if ((data.outMode !== "bounce" &&
43
- data.outMode !== "bounce-vertical" &&
44
- data.outMode !== "bounceVertical" &&
45
- data.outMode !== "split") ||
39
+ if ((data.outMode !== "bounce" && data.outMode !== "split") ||
46
40
  (data.direction !== "bottom" && data.direction !== "top")) {
47
41
  return;
48
42
  }
package/browser/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import { OutOfCanvasUpdater } from "./OutOfCanvasUpdater.js";
2
1
  export async function loadOutModesUpdater(engine, refresh = true) {
3
- await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater(container), refresh);
2
+ await engine.addParticleUpdater("outModes", async (container) => {
3
+ const { OutOfCanvasUpdater } = await import("./OutOfCanvasUpdater.js");
4
+ return new OutOfCanvasUpdater(container);
5
+ }, refresh);
4
6
  }
@@ -1,21 +1,39 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.BounceOutMode = void 0;
4
27
  const engine_1 = require("@tsparticles/engine");
5
- const Utils_js_1 = require("./Utils.js");
6
28
  class BounceOutMode {
7
29
  constructor(container) {
8
30
  this.container = container;
9
31
  this.modes = [
10
32
  "bounce",
11
- "bounce-vertical",
12
- "bounce-horizontal",
13
- "bounceVertical",
14
- "bounceHorizontal",
15
33
  "split",
16
34
  ];
17
35
  }
18
- update(particle, direction, delta, outMode) {
36
+ async update(particle, direction, delta, outMode) {
19
37
  if (!this.modes.includes(outMode)) {
20
38
  return;
21
39
  }
@@ -23,7 +41,7 @@ class BounceOutMode {
23
41
  let handled = false;
24
42
  for (const [, plugin] of container.plugins) {
25
43
  if (plugin.particleBounce !== undefined) {
26
- handled = plugin.particleBounce(particle, delta, direction);
44
+ handled = await plugin.particleBounce(particle, delta, direction);
27
45
  }
28
46
  if (handled) {
29
47
  break;
@@ -32,9 +50,9 @@ class BounceOutMode {
32
50
  if (handled) {
33
51
  return;
34
52
  }
35
- const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = (0, engine_1.calculateBounds)(pos, size), canvasSize = container.canvas.size;
36
- (0, Utils_js_1.bounceHorizontal)({ particle, outMode, direction, bounds, canvasSize, offset, size });
37
- (0, Utils_js_1.bounceVertical)({ particle, outMode, direction, bounds, canvasSize, offset, size });
53
+ const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = (0, engine_1.calculateBounds)(pos, size), canvasSize = container.canvas.size, { bounceHorizontal, bounceVertical } = await Promise.resolve().then(() => __importStar(require("./Utils.js")));
54
+ bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
55
+ bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
38
56
  }
39
57
  }
40
58
  exports.BounceOutMode = BounceOutMode;
@@ -8,7 +8,7 @@ class DestroyOutMode {
8
8
  this.container = container;
9
9
  this.modes = ["destroy"];
10
10
  }
11
- update(particle, direction, _delta, outMode) {
11
+ async update(particle, direction, _delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
13
13
  return;
14
14
  }
@@ -21,8 +21,7 @@ class DestroyOutMode {
21
21
  }
22
22
  break;
23
23
  case "inside": {
24
- const { dx, dy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter);
25
- const { x: vx, y: vy } = particle.velocity;
24
+ const { dx, dy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
26
25
  if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
27
26
  (vy < minVelocity && dy > particle.moveCenter.radius) ||
28
27
  (vx >= minVelocity && dx < -particle.moveCenter.radius) ||
@@ -33,6 +32,7 @@ class DestroyOutMode {
33
32
  }
34
33
  }
35
34
  container.particles.remove(particle, undefined, true);
35
+ await Promise.resolve();
36
36
  }
37
37
  }
38
38
  exports.DestroyOutMode = DestroyOutMode;
@@ -8,7 +8,7 @@ class NoneOutMode {
8
8
  this.container = container;
9
9
  this.modes = ["none"];
10
10
  }
11
- update(particle, direction, delta, outMode) {
11
+ async update(particle, direction, delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
13
13
  return;
14
14
  }
@@ -18,9 +18,7 @@ class NoneOutMode {
18
18
  (direction === "top" || direction === "bottom"))) {
19
19
  return;
20
20
  }
21
- const gravityOptions = particle.options.move.gravity, container = this.container;
22
- const canvasSize = container.canvas.size;
23
- const pRadius = particle.getRadius();
21
+ const gravityOptions = particle.options.move.gravity, container = this.container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
24
22
  if (!gravityOptions.enable) {
25
23
  if ((particle.velocity.y > minVelocity && particle.position.y <= canvasSize.height + pRadius) ||
26
24
  (particle.velocity.y < minVelocity && particle.position.y >= -pRadius) ||
@@ -41,6 +39,7 @@ class NoneOutMode {
41
39
  container.particles.remove(particle);
42
40
  }
43
41
  }
42
+ await Promise.resolve();
44
43
  }
45
44
  }
46
45
  exports.NoneOutMode = NoneOutMode;
@@ -1,36 +1,75 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.OutOfCanvasUpdater = void 0;
4
- const BounceOutMode_js_1 = require("./BounceOutMode.js");
5
- const DestroyOutMode_js_1 = require("./DestroyOutMode.js");
6
- const NoneOutMode_js_1 = require("./NoneOutMode.js");
7
- const OutOutMode_js_1 = require("./OutOutMode.js");
27
+ const checkOutMode = (outModes, outMode) => {
28
+ return (outModes.default === outMode ||
29
+ outModes.bottom === outMode ||
30
+ outModes.left === outMode ||
31
+ outModes.right === outMode ||
32
+ outModes.top === outMode);
33
+ };
8
34
  class OutOfCanvasUpdater {
9
35
  constructor(container) {
10
- this._updateOutMode = (particle, delta, outMode, direction) => {
36
+ this._updateOutMode = async (particle, delta, outMode, direction) => {
11
37
  for (const updater of this.updaters) {
12
- updater.update(particle, direction, delta, outMode);
38
+ await updater.update(particle, direction, delta, outMode);
13
39
  }
14
40
  };
15
41
  this.container = container;
16
- this.updaters = [
17
- new BounceOutMode_js_1.BounceOutMode(container),
18
- new DestroyOutMode_js_1.DestroyOutMode(container),
19
- new OutOutMode_js_1.OutOutMode(container),
20
- new NoneOutMode_js_1.NoneOutMode(container),
21
- ];
42
+ this.updaters = [];
22
43
  }
23
- init() {
44
+ async init(particle) {
45
+ this.updaters = [];
46
+ const outModes = particle.options.move.outModes;
47
+ if (checkOutMode(outModes, "bounce")) {
48
+ const { BounceOutMode } = await Promise.resolve().then(() => __importStar(require("./BounceOutMode.js")));
49
+ this.updaters.push(new BounceOutMode(this.container));
50
+ }
51
+ else if (checkOutMode(outModes, "out")) {
52
+ const { OutOutMode } = await Promise.resolve().then(() => __importStar(require("./OutOutMode.js")));
53
+ this.updaters.push(new OutOutMode(this.container));
54
+ }
55
+ else if (checkOutMode(outModes, "destroy")) {
56
+ const { DestroyOutMode } = await Promise.resolve().then(() => __importStar(require("./DestroyOutMode.js")));
57
+ this.updaters.push(new DestroyOutMode(this.container));
58
+ }
59
+ else if (checkOutMode(outModes, "none")) {
60
+ const { NoneOutMode } = await Promise.resolve().then(() => __importStar(require("./NoneOutMode.js")));
61
+ this.updaters.push(new NoneOutMode(this.container));
62
+ }
24
63
  }
25
64
  isEnabled(particle) {
26
65
  return !particle.destroyed && !particle.spawning;
27
66
  }
28
- update(particle, delta) {
67
+ async update(particle, delta) {
29
68
  const outModes = particle.options.move.outModes;
30
- this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
31
- this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
32
- this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
33
- this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
69
+ await this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
70
+ await this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
71
+ await this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
72
+ await this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
34
73
  }
35
74
  }
36
75
  exports.OutOfCanvasUpdater = OutOfCanvasUpdater;
package/cjs/OutOutMode.js CHANGED
@@ -8,7 +8,7 @@ class OutOutMode {
8
8
  this.container = container;
9
9
  this.modes = ["out"];
10
10
  }
11
- update(particle, direction, delta, outMode) {
11
+ async update(particle, direction, delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
13
13
  return;
14
14
  }
@@ -110,6 +110,7 @@ class OutOutMode {
110
110
  break;
111
111
  }
112
112
  }
113
+ await Promise.resolve();
113
114
  }
114
115
  }
115
116
  exports.OutOutMode = OutOutMode;
package/cjs/Utils.js CHANGED
@@ -4,10 +4,7 @@ exports.bounceVertical = exports.bounceHorizontal = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const minVelocity = 0, boundsMin = 0;
6
6
  function bounceHorizontal(data) {
7
- if ((data.outMode !== "bounce" &&
8
- data.outMode !== "bounce-horizontal" &&
9
- data.outMode !== "bounceHorizontal" &&
10
- data.outMode !== "split") ||
7
+ if ((data.outMode !== "bounce" && data.outMode !== "split") ||
11
8
  (data.direction !== "left" && data.direction !== "right")) {
12
9
  return;
13
10
  }
@@ -43,10 +40,7 @@ function bounceHorizontal(data) {
43
40
  }
44
41
  exports.bounceHorizontal = bounceHorizontal;
45
42
  function bounceVertical(data) {
46
- if ((data.outMode !== "bounce" &&
47
- data.outMode !== "bounce-vertical" &&
48
- data.outMode !== "bounceVertical" &&
49
- data.outMode !== "split") ||
43
+ if ((data.outMode !== "bounce" && data.outMode !== "split") ||
50
44
  (data.direction !== "bottom" && data.direction !== "top")) {
51
45
  return;
52
46
  }
package/cjs/index.js CHANGED
@@ -1,8 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.loadOutModesUpdater = void 0;
4
- const OutOfCanvasUpdater_js_1 = require("./OutOfCanvasUpdater.js");
5
27
  async function loadOutModesUpdater(engine, refresh = true) {
6
- await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater_js_1.OutOfCanvasUpdater(container), refresh);
28
+ await engine.addParticleUpdater("outModes", async (container) => {
29
+ const { OutOfCanvasUpdater } = await Promise.resolve().then(() => __importStar(require("./OutOfCanvasUpdater.js")));
30
+ return new OutOfCanvasUpdater(container);
31
+ }, refresh);
7
32
  }
8
33
  exports.loadOutModesUpdater = loadOutModesUpdater;
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.1
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_updater_out_modes"] = this["webpackChunk_tsparticles_updater_out_modes"] || []).push([["dist_browser_BounceOutMode_js"],{
19
+
20
+ /***/ "./dist/browser/BounceOutMode.js":
21
+ /*!***************************************!*\
22
+ !*** ./dist/browser/BounceOutMode.js ***!
23
+ \***************************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BounceOutMode: () => (/* binding */ BounceOutMode)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass BounceOutMode {\n constructor(container) {\n this.container = container;\n this.modes = [\"bounce\", \"split\"];\n }\n async update(particle, direction, delta, outMode) {\n if (!this.modes.includes(outMode)) {\n return;\n }\n const container = this.container;\n let handled = false;\n for (const [, plugin] of container.plugins) {\n if (plugin.particleBounce !== undefined) {\n handled = await plugin.particleBounce(particle, delta, direction);\n }\n if (handled) {\n break;\n }\n }\n if (handled) {\n return;\n }\n const pos = particle.getPosition(),\n offset = particle.offset,\n size = particle.getRadius(),\n bounds = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calculateBounds)(pos, size),\n canvasSize = container.canvas.size,\n {\n bounceHorizontal,\n bounceVertical\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_Utils_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./Utils.js */ \"./dist/browser/Utils.js\"));\n bounceHorizontal({\n particle,\n outMode,\n direction,\n bounds,\n canvasSize,\n offset,\n size\n });\n bounceVertical({\n particle,\n outMode,\n direction,\n bounds,\n canvasSize,\n offset,\n size\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-out-modes/./dist/browser/BounceOutMode.js?");
27
+
28
+ /***/ })
29
+
30
+ }]);
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.1
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_updater_out_modes"] = this["webpackChunk_tsparticles_updater_out_modes"] || []).push([["dist_browser_DestroyOutMode_js"],{
19
+
20
+ /***/ "./dist/browser/DestroyOutMode.js":
21
+ /*!****************************************!*\
22
+ !*** ./dist/browser/DestroyOutMode.js ***!
23
+ \****************************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ DestroyOutMode: () => (/* binding */ DestroyOutMode)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst minVelocity = 0;\nclass DestroyOutMode {\n constructor(container) {\n this.container = container;\n this.modes = [\"destroy\"];\n }\n async update(particle, direction, _delta, outMode) {\n if (!this.modes.includes(outMode)) {\n return;\n }\n const container = this.container;\n switch (particle.outType) {\n case \"normal\":\n case \"outside\":\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isPointInside)(particle.position, container.canvas.size, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin, particle.getRadius(), direction)) {\n return;\n }\n break;\n case \"inside\":\n {\n const {\n dx,\n dy\n } = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getDistances)(particle.position, particle.moveCenter),\n {\n x: vx,\n y: vy\n } = particle.velocity;\n if (vx < minVelocity && dx > particle.moveCenter.radius || vy < minVelocity && dy > particle.moveCenter.radius || vx >= minVelocity && dx < -particle.moveCenter.radius || vy >= minVelocity && dy < -particle.moveCenter.radius) {\n return;\n }\n break;\n }\n }\n container.particles.remove(particle, undefined, true);\n await Promise.resolve();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/updater-out-modes/./dist/browser/DestroyOutMode.js?");
27
+
28
+ /***/ })
29
+
30
+ }]);