@tsparticles/updater-out-modes 3.0.0-alpha.0 → 3.0.0-beta.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
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadOutModesUpdater": () => (/* binding */ loadOutModesUpdater)
94
+ loadOutModesUpdater: () => (/* binding */ loadOutModesUpdater)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -99,12 +99,12 @@ var engine_root_window_ = __webpack_require__(533);
99
99
  ;// CONCATENATED MODULE: ./dist/browser/Utils.js
100
100
 
101
101
  function bounceHorizontal(data) {
102
- if (data.outMode !== "bounce" && data.outMode !== "bounce-horizontal" && data.outMode !== "bounceHorizontal" && data.outMode !== "split") {
102
+ if (data.outMode !== "bounce" && data.outMode !== "bounce-horizontal" && data.outMode !== "bounceHorizontal" && data.outMode !== "split" || data.direction !== "left" && data.direction !== "right") {
103
103
  return;
104
104
  }
105
- if (data.bounds.right < 0) {
105
+ if (data.bounds.right < 0 && data.direction === "left") {
106
106
  data.particle.position.x = data.size + data.offset.x;
107
- } else if (data.bounds.left > data.canvasSize.width) {
107
+ } else if (data.bounds.left > data.canvasSize.width && data.direction === "right") {
108
108
  data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
109
109
  }
110
110
  const velocity = data.particle.velocity.x;
@@ -118,9 +118,9 @@ function bounceHorizontal(data) {
118
118
  return;
119
119
  }
120
120
  const minPos = data.offset.x + data.size;
121
- if (data.bounds.right >= data.canvasSize.width) {
121
+ if (data.bounds.right >= data.canvasSize.width && data.direction === "right") {
122
122
  data.particle.position.x = data.canvasSize.width - minPos;
123
- } else if (data.bounds.left <= 0) {
123
+ } else if (data.bounds.left <= 0 && data.direction === "left") {
124
124
  data.particle.position.x = minPos;
125
125
  }
126
126
  if (data.outMode === "split") {
@@ -128,12 +128,12 @@ function bounceHorizontal(data) {
128
128
  }
129
129
  }
130
130
  function bounceVertical(data) {
131
- if (data.outMode !== "bounce" && data.outMode !== "bounce-vertical" && data.outMode !== "bounceVertical" && data.outMode !== "split") {
131
+ if (data.outMode !== "bounce" && data.outMode !== "bounce-vertical" && data.outMode !== "bounceVertical" && data.outMode !== "split" || data.direction !== "bottom" && data.direction !== "top") {
132
132
  return;
133
133
  }
134
- if (data.bounds.bottom < 0) {
134
+ if (data.bounds.bottom < 0 && data.direction === "top") {
135
135
  data.particle.position.y = data.size + data.offset.y;
136
- } else if (data.bounds.top > data.canvasSize.height) {
136
+ } else if (data.bounds.top > data.canvasSize.height && data.direction === "bottom") {
137
137
  data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
138
138
  }
139
139
  const velocity = data.particle.velocity.y;
@@ -147,9 +147,9 @@ function bounceVertical(data) {
147
147
  return;
148
148
  }
149
149
  const minPos = data.offset.y + data.size;
150
- if (data.bounds.bottom >= data.canvasSize.height) {
150
+ if (data.bounds.bottom >= data.canvasSize.height && data.direction === "bottom") {
151
151
  data.particle.position.y = data.canvasSize.height - minPos;
152
- } else if (data.bounds.top <= 0) {
152
+ } else if (data.bounds.top <= 0 && data.direction === "top") {
153
153
  data.particle.position.y = minPos;
154
154
  }
155
155
  if (data.outMode === "split") {
@@ -213,7 +213,7 @@ class DestroyOutMode {
213
213
  this.container = container;
214
214
  this.modes = ["destroy"];
215
215
  }
216
- update(particle, direction, delta, outMode) {
216
+ update(particle, direction, _delta, outMode) {
217
217
  if (!this.modes.includes(outMode)) {
218
218
  return;
219
219
  }
@@ -407,6 +407,11 @@ class OutOutMode {
407
407
  class OutOfCanvasUpdater {
408
408
  constructor(container) {
409
409
  this.container = container;
410
+ this._updateOutMode = (particle, delta, outMode, direction) => {
411
+ for (const updater of this.updaters) {
412
+ updater.update(particle, direction, delta, outMode);
413
+ }
414
+ };
410
415
  this.updaters = [new BounceOutMode(container), new DestroyOutMode(container), new OutOutMode(container), new NoneOutMode(container)];
411
416
  }
412
417
  init() {}
@@ -414,23 +419,17 @@ class OutOfCanvasUpdater {
414
419
  return !particle.destroyed && !particle.spawning;
415
420
  }
416
421
  update(particle, delta) {
417
- var _a, _b, _c, _d;
418
422
  const outModes = particle.options.move.outModes;
419
- this.updateOutMode(particle, delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, "bottom");
420
- this.updateOutMode(particle, delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, "left");
421
- this.updateOutMode(particle, delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, "right");
422
- this.updateOutMode(particle, delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, "top");
423
- }
424
- updateOutMode(particle, delta, outMode, direction) {
425
- for (const updater of this.updaters) {
426
- updater.update(particle, direction, delta, outMode);
427
- }
423
+ this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
424
+ this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
425
+ this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
426
+ this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
428
427
  }
429
428
  }
430
429
  ;// CONCATENATED MODULE: ./dist/browser/index.js
431
430
 
432
- async function loadOutModesUpdater(engine) {
433
- await engine.addParticleUpdater("outModes", container => new OutOfCanvasUpdater(container));
431
+ async function loadOutModesUpdater(engine, refresh = true) {
432
+ await engine.addParticleUpdater("outModes", container => new OutOfCanvasUpdater(container), refresh);
434
433
  }
435
434
  })();
436
435
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.out-modes.min.js.LICENSE.txt */
2
- !function(t,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var e="object"==typeof exports?o(require("@tsparticles/engine")):o(t.window);for(var i in e)("object"==typeof exports?exports:t)[i]=e[i]}}(this,(t=>(()=>{"use strict";var o={533:o=>{o.exports=t}},e={};function i(t){var n=e[t];if(void 0!==n)return n.exports;var s=e[t]={exports:{}};return o[t](s,s.exports,i),s.exports}i.d=(t,o)=>{for(var e in o)i.o(o,e)&&!i.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},i.o=(t,o)=>Object.prototype.hasOwnProperty.call(t,o),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadOutModesUpdater:()=>c});var t=i(533);class o{constructor(t){this.container=t,this.modes=["bounce","bounce-vertical","bounce-horizontal","bounceVertical","bounceHorizontal","split"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;let a=!1;for(const[,t]of s.plugins)if(void 0!==t.particleBounce&&(a=t.particleBounce(o,i,e)),a)break;if(a)return;const r=o.getPosition(),c=o.offset,d=o.getRadius(),u=(0,t.calculateBounds)(r,d),l=s.canvas.size;!function(o){if("bounce"!==o.outMode&&"bounce-horizontal"!==o.outMode&&"bounceHorizontal"!==o.outMode&&"split"!==o.outMode)return;o.bounds.right<0?o.particle.position.x=o.size+o.offset.x:o.bounds.left>o.canvasSize.width&&(o.particle.position.x=o.canvasSize.width-o.size-o.offset.x);const e=o.particle.velocity.x;let i=!1;if("right"===o.direction&&o.bounds.right>=o.canvasSize.width&&e>0||"left"===o.direction&&o.bounds.left<=0&&e<0){const e=(0,t.getValue)(o.particle.options.bounce.horizontal);o.particle.velocity.x*=-e,i=!0}if(!i)return;const n=o.offset.x+o.size;o.bounds.right>=o.canvasSize.width?o.particle.position.x=o.canvasSize.width-n:o.bounds.left<=0&&(o.particle.position.x=n),"split"===o.outMode&&o.particle.destroy()}({particle:o,outMode:n,direction:e,bounds:u,canvasSize:l,offset:c,size:d}),function(o){if("bounce"!==o.outMode&&"bounce-vertical"!==o.outMode&&"bounceVertical"!==o.outMode&&"split"!==o.outMode)return;o.bounds.bottom<0?o.particle.position.y=o.size+o.offset.y:o.bounds.top>o.canvasSize.height&&(o.particle.position.y=o.canvasSize.height-o.size-o.offset.y);const e=o.particle.velocity.y;let i=!1;if("bottom"===o.direction&&o.bounds.bottom>=o.canvasSize.height&&e>0||"top"===o.direction&&o.bounds.top<=0&&e<0){const e=(0,t.getValue)(o.particle.options.bounce.vertical);o.particle.velocity.y*=-e,i=!0}if(!i)return;const n=o.offset.y+o.size;o.bounds.bottom>=o.canvasSize.height?o.particle.position.y=o.canvasSize.height-n:o.bounds.top<=0&&(o.particle.position.y=n),"split"===o.outMode&&o.particle.destroy()}({particle:o,outMode:n,direction:e,bounds:u,canvasSize:l,offset:c,size:d})}}class e{constructor(t){this.container=t,this.modes=["destroy"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;switch(o.outType){case"normal":case"outside":if((0,t.isPointInside)(o.position,s.canvas.size,t.Vector.origin,o.getRadius(),e))return;break;case"inside":{const{dx:e,dy:i}=(0,t.getDistances)(o.position,o.moveCenter),{x:n,y:s}=o.velocity;if(n<0&&e>o.moveCenter.radius||s<0&&i>o.moveCenter.radius||n>=0&&e<-o.moveCenter.radius||s>=0&&i<-o.moveCenter.radius)return;break}}s.particles.remove(o,void 0,!0)}}class s{constructor(t){this.container=t,this.modes=["none"]}update(o,e,i,n){if(!this.modes.includes(n))return;if(o.options.move.distance.horizontal&&("left"===e||"right"===e)||o.options.move.distance.vertical&&("top"===e||"bottom"===e))return;const s=o.options.move.gravity,a=this.container,r=a.canvas.size,c=o.getRadius();if(s.enable){const t=o.position;(!s.inverse&&t.y>r.height+c&&"bottom"===e||s.inverse&&t.y<-c&&"top"===e)&&a.particles.remove(o)}else{if(o.velocity.y>0&&o.position.y<=r.height+c||o.velocity.y<0&&o.position.y>=-c||o.velocity.x>0&&o.position.x<=r.width+c||o.velocity.x<0&&o.position.x>=-c)return;(0,t.isPointInside)(o.position,a.canvas.size,t.Vector.origin,c,e)||a.particles.remove(o)}}}class a{constructor(t){this.container=t,this.modes=["out"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;switch(o.outType){case"inside":{const{x:e,y:i}=o.velocity,n=t.Vector.origin;n.length=o.moveCenter.radius,n.angle=o.velocity.angle+Math.PI,n.addTo(t.Vector.create(o.moveCenter));const{dx:a,dy:r}=(0,t.getDistances)(o.position,n);if(e<=0&&a>=0||i<=0&&r>=0||e>=0&&a<=0||i>=0&&r<=0)return;o.position.x=Math.floor((0,t.randomInRange)({min:0,max:s.canvas.size.width})),o.position.y=Math.floor((0,t.randomInRange)({min:0,max:s.canvas.size.height}));const{dx:c,dy:d}=(0,t.getDistances)(o.position,o.moveCenter);o.direction=Math.atan2(-d,-c),o.velocity.angle=o.direction;break}default:if((0,t.isPointInside)(o.position,s.canvas.size,t.Vector.origin,o.getRadius(),e))return;switch(o.outType){case"outside":{o.position.x=Math.floor((0,t.randomInRange)({min:-o.moveCenter.radius,max:o.moveCenter.radius}))+o.moveCenter.x,o.position.y=Math.floor((0,t.randomInRange)({min:-o.moveCenter.radius,max:o.moveCenter.radius}))+o.moveCenter.y;const{dx:e,dy:i}=(0,t.getDistances)(o.position,o.moveCenter);o.moveCenter.radius&&(o.direction=Math.atan2(i,e),o.velocity.angle=o.direction);break}case"normal":{const i=o.options.move.warp,n=s.canvas.size,a={bottom:n.height+o.getRadius()+o.offset.y,left:-o.getRadius()-o.offset.x,right:n.width+o.getRadius()+o.offset.x,top:-o.getRadius()-o.offset.y},r=o.getRadius(),c=(0,t.calculateBounds)(o.position,r);"right"===e&&c.left>n.width+o.offset.x?(o.position.x=a.left,o.initialPosition.x=o.position.x,i||(o.position.y=(0,t.getRandom)()*n.height,o.initialPosition.y=o.position.y)):"left"===e&&c.right<-o.offset.x&&(o.position.x=a.right,o.initialPosition.x=o.position.x,i||(o.position.y=(0,t.getRandom)()*n.height,o.initialPosition.y=o.position.y)),"bottom"===e&&c.top>n.height+o.offset.y?(i||(o.position.x=(0,t.getRandom)()*n.width,o.initialPosition.x=o.position.x),o.position.y=a.top,o.initialPosition.y=o.position.y):"top"===e&&c.bottom<-o.offset.y&&(i||(o.position.x=(0,t.getRandom)()*n.width,o.initialPosition.x=o.position.x),o.position.y=a.bottom,o.initialPosition.y=o.position.y);break}}}}}class r{constructor(t){this.container=t,this.updaters=[new o(t),new e(t),new a(t),new s(t)]}init(){}isEnabled(t){return!t.destroyed&&!t.spawning}update(t,o){var e,i,n,s;const a=t.options.move.outModes;this.updateOutMode(t,o,null!==(e=a.bottom)&&void 0!==e?e:a.default,"bottom"),this.updateOutMode(t,o,null!==(i=a.left)&&void 0!==i?i:a.default,"left"),this.updateOutMode(t,o,null!==(n=a.right)&&void 0!==n?n:a.default,"right"),this.updateOutMode(t,o,null!==(s=a.top)&&void 0!==s?s:a.default,"top")}updateOutMode(t,o,e,i){for(const n of this.updaters)n.update(t,i,o,e)}}async function c(t){await t.addParticleUpdater("outModes",(t=>new r(t)))}})(),n})()));
2
+ !function(t,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var e="object"==typeof exports?o(require("@tsparticles/engine")):o(t.window);for(var i in e)("object"==typeof exports?exports:t)[i]=e[i]}}(this,(t=>(()=>{"use strict";var o={533:o=>{o.exports=t}},e={};function i(t){var n=e[t];if(void 0!==n)return n.exports;var s=e[t]={exports:{}};return o[t](s,s.exports,i),s.exports}i.d=(t,o)=>{for(var e in o)i.o(o,e)&&!i.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},i.o=(t,o)=>Object.prototype.hasOwnProperty.call(t,o),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{i.r(n),i.d(n,{loadOutModesUpdater:()=>c});var t=i(533);class o{constructor(t){this.container=t,this.modes=["bounce","bounce-vertical","bounce-horizontal","bounceVertical","bounceHorizontal","split"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;let r=!1;for(const[,t]of s.plugins)if(void 0!==t.particleBounce&&(r=t.particleBounce(o,i,e)),r)break;if(r)return;const a=o.getPosition(),c=o.offset,d=o.getRadius(),u=(0,t.calculateBounds)(a,d),p=s.canvas.size;!function(o){if("bounce"!==o.outMode&&"bounce-horizontal"!==o.outMode&&"bounceHorizontal"!==o.outMode&&"split"!==o.outMode||"left"!==o.direction&&"right"!==o.direction)return;o.bounds.right<0&&"left"===o.direction?o.particle.position.x=o.size+o.offset.x:o.bounds.left>o.canvasSize.width&&"right"===o.direction&&(o.particle.position.x=o.canvasSize.width-o.size-o.offset.x);const e=o.particle.velocity.x;let i=!1;if("right"===o.direction&&o.bounds.right>=o.canvasSize.width&&e>0||"left"===o.direction&&o.bounds.left<=0&&e<0){const e=(0,t.getValue)(o.particle.options.bounce.horizontal);o.particle.velocity.x*=-e,i=!0}if(!i)return;const n=o.offset.x+o.size;o.bounds.right>=o.canvasSize.width&&"right"===o.direction?o.particle.position.x=o.canvasSize.width-n:o.bounds.left<=0&&"left"===o.direction&&(o.particle.position.x=n),"split"===o.outMode&&o.particle.destroy()}({particle:o,outMode:n,direction:e,bounds:u,canvasSize:p,offset:c,size:d}),function(o){if("bounce"!==o.outMode&&"bounce-vertical"!==o.outMode&&"bounceVertical"!==o.outMode&&"split"!==o.outMode||"bottom"!==o.direction&&"top"!==o.direction)return;o.bounds.bottom<0&&"top"===o.direction?o.particle.position.y=o.size+o.offset.y:o.bounds.top>o.canvasSize.height&&"bottom"===o.direction&&(o.particle.position.y=o.canvasSize.height-o.size-o.offset.y);const e=o.particle.velocity.y;let i=!1;if("bottom"===o.direction&&o.bounds.bottom>=o.canvasSize.height&&e>0||"top"===o.direction&&o.bounds.top<=0&&e<0){const e=(0,t.getValue)(o.particle.options.bounce.vertical);o.particle.velocity.y*=-e,i=!0}if(!i)return;const n=o.offset.y+o.size;o.bounds.bottom>=o.canvasSize.height&&"bottom"===o.direction?o.particle.position.y=o.canvasSize.height-n:o.bounds.top<=0&&"top"===o.direction&&(o.particle.position.y=n),"split"===o.outMode&&o.particle.destroy()}({particle:o,outMode:n,direction:e,bounds:u,canvasSize:p,offset:c,size:d})}}class e{constructor(t){this.container=t,this.modes=["destroy"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;switch(o.outType){case"normal":case"outside":if((0,t.isPointInside)(o.position,s.canvas.size,t.Vector.origin,o.getRadius(),e))return;break;case"inside":{const{dx:e,dy:i}=(0,t.getDistances)(o.position,o.moveCenter),{x:n,y:s}=o.velocity;if(n<0&&e>o.moveCenter.radius||s<0&&i>o.moveCenter.radius||n>=0&&e<-o.moveCenter.radius||s>=0&&i<-o.moveCenter.radius)return;break}}s.particles.remove(o,void 0,!0)}}class s{constructor(t){this.container=t,this.modes=["none"]}update(o,e,i,n){if(!this.modes.includes(n))return;if(o.options.move.distance.horizontal&&("left"===e||"right"===e)||o.options.move.distance.vertical&&("top"===e||"bottom"===e))return;const s=o.options.move.gravity,r=this.container,a=r.canvas.size,c=o.getRadius();if(s.enable){const t=o.position;(!s.inverse&&t.y>a.height+c&&"bottom"===e||s.inverse&&t.y<-c&&"top"===e)&&r.particles.remove(o)}else{if(o.velocity.y>0&&o.position.y<=a.height+c||o.velocity.y<0&&o.position.y>=-c||o.velocity.x>0&&o.position.x<=a.width+c||o.velocity.x<0&&o.position.x>=-c)return;(0,t.isPointInside)(o.position,r.canvas.size,t.Vector.origin,c,e)||r.particles.remove(o)}}}class r{constructor(t){this.container=t,this.modes=["out"]}update(o,e,i,n){if(!this.modes.includes(n))return;const s=this.container;switch(o.outType){case"inside":{const{x:e,y:i}=o.velocity,n=t.Vector.origin;n.length=o.moveCenter.radius,n.angle=o.velocity.angle+Math.PI,n.addTo(t.Vector.create(o.moveCenter));const{dx:r,dy:a}=(0,t.getDistances)(o.position,n);if(e<=0&&r>=0||i<=0&&a>=0||e>=0&&r<=0||i>=0&&a<=0)return;o.position.x=Math.floor((0,t.randomInRange)({min:0,max:s.canvas.size.width})),o.position.y=Math.floor((0,t.randomInRange)({min:0,max:s.canvas.size.height}));const{dx:c,dy:d}=(0,t.getDistances)(o.position,o.moveCenter);o.direction=Math.atan2(-d,-c),o.velocity.angle=o.direction;break}default:if((0,t.isPointInside)(o.position,s.canvas.size,t.Vector.origin,o.getRadius(),e))return;switch(o.outType){case"outside":{o.position.x=Math.floor((0,t.randomInRange)({min:-o.moveCenter.radius,max:o.moveCenter.radius}))+o.moveCenter.x,o.position.y=Math.floor((0,t.randomInRange)({min:-o.moveCenter.radius,max:o.moveCenter.radius}))+o.moveCenter.y;const{dx:e,dy:i}=(0,t.getDistances)(o.position,o.moveCenter);o.moveCenter.radius&&(o.direction=Math.atan2(i,e),o.velocity.angle=o.direction);break}case"normal":{const i=o.options.move.warp,n=s.canvas.size,r={bottom:n.height+o.getRadius()+o.offset.y,left:-o.getRadius()-o.offset.x,right:n.width+o.getRadius()+o.offset.x,top:-o.getRadius()-o.offset.y},a=o.getRadius(),c=(0,t.calculateBounds)(o.position,a);"right"===e&&c.left>n.width+o.offset.x?(o.position.x=r.left,o.initialPosition.x=o.position.x,i||(o.position.y=(0,t.getRandom)()*n.height,o.initialPosition.y=o.position.y)):"left"===e&&c.right<-o.offset.x&&(o.position.x=r.right,o.initialPosition.x=o.position.x,i||(o.position.y=(0,t.getRandom)()*n.height,o.initialPosition.y=o.position.y)),"bottom"===e&&c.top>n.height+o.offset.y?(i||(o.position.x=(0,t.getRandom)()*n.width,o.initialPosition.x=o.position.x),o.position.y=r.top,o.initialPosition.y=o.position.y):"top"===e&&c.bottom<-o.offset.y&&(i||(o.position.x=(0,t.getRandom)()*n.width,o.initialPosition.x=o.position.x),o.position.y=r.bottom,o.initialPosition.y=o.position.y);break}}}}}class a{constructor(t){this.container=t,this._updateOutMode=(t,o,e,i)=>{for(const n of this.updaters)n.update(t,i,o,e)},this.updaters=[new o(t),new e(t),new r(t),new s(t)]}init(){}isEnabled(t){return!t.destroyed&&!t.spawning}update(t,o){const e=t.options.move.outModes;this._updateOutMode(t,o,e.bottom??e.default,"bottom"),this._updateOutMode(t,o,e.left??e.default,"left"),this._updateOutMode(t,o,e.right??e.default,"right"),this._updateOutMode(t,o,e.top??e.default,"top")}}async function c(t,o=!0){await t.addParticleUpdater("outModes",(t=>new a(t)),o)}})(),n})()));
@@ -1,8 +1 @@
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.0.0-alpha.0
8
- */
1
+ /*! tsParticles Out Modes Updater v3.0.0-beta.0 by Matteo Bruni */
@@ -1,5 +1,4 @@
1
- import type { Container, IDelta, OutModeAlt, OutModeDirection, Particle } from "@tsparticles/engine";
2
- import { OutMode } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, OutMode, type OutModeAlt, type OutModeDirection, type Particle } from "@tsparticles/engine";
3
2
  import type { IOutModeManager } from "./IOutModeManager";
4
3
  export declare class BounceOutMode implements IOutModeManager {
5
4
  private readonly container;
@@ -1,9 +1,8 @@
1
- import type { Container, IDelta, OutModeAlt, OutModeDirection, Particle } from "@tsparticles/engine";
2
- import { OutMode } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, OutMode, type OutModeAlt, type OutModeDirection, type Particle } from "@tsparticles/engine";
3
2
  import type { IOutModeManager } from "./IOutModeManager";
4
3
  export declare class DestroyOutMode implements IOutModeManager {
5
4
  private readonly container;
6
5
  modes: (OutMode | OutModeAlt | keyof typeof OutMode)[];
7
6
  constructor(container: Container);
8
- update(particle: Particle, direction: OutModeDirection, delta: IDelta, outMode: OutMode | OutModeAlt | keyof typeof OutMode): void;
7
+ update(particle: Particle, direction: OutModeDirection, _delta: IDelta, outMode: OutMode | OutModeAlt | keyof typeof OutMode): void;
9
8
  }
@@ -1,5 +1,4 @@
1
- import type { IBounds, ICoordinates, IDimension, OutMode, OutModeAlt, OutModeDirection } from "@tsparticles/engine";
2
- import type { Particle } from "@tsparticles/engine";
1
+ import type { IBounds, ICoordinates, IDimension, OutMode, OutModeAlt, OutModeDirection, Particle } from "@tsparticles/engine";
3
2
  export interface IBounceData {
4
3
  bounds: IBounds;
5
4
  canvasSize: IDimension;
@@ -1,5 +1,4 @@
1
- import type { Container, IDelta, OutModeAlt, Particle } from "@tsparticles/engine";
2
- import { OutMode, OutModeDirection } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, OutMode, type OutModeAlt, OutModeDirection, type Particle } from "@tsparticles/engine";
3
2
  import type { IOutModeManager } from "./IOutModeManager";
4
3
  export declare class NoneOutMode implements IOutModeManager {
5
4
  private readonly container;
@@ -1,4 +1,4 @@
1
- import type { Container, IDelta, IParticleUpdater, Particle } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, type IParticleUpdater, type Particle } from "@tsparticles/engine";
2
2
  import type { IOutModeManager } from "./IOutModeManager";
3
3
  export declare class OutOfCanvasUpdater implements IParticleUpdater {
4
4
  private readonly container;
@@ -7,5 +7,5 @@ export declare class OutOfCanvasUpdater implements IParticleUpdater {
7
7
  init(): void;
8
8
  isEnabled(particle: Particle): boolean;
9
9
  update(particle: Particle, delta: IDelta): void;
10
- private updateOutMode;
10
+ private readonly _updateOutMode;
11
11
  }
@@ -1,5 +1,4 @@
1
- import type { Container, IDelta, OutModeAlt, Particle } from "@tsparticles/engine";
2
- import { OutMode, OutModeDirection } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, OutMode, type OutModeAlt, OutModeDirection, type Particle } from "@tsparticles/engine";
3
2
  import type { IOutModeManager } from "./IOutModeManager";
4
3
  export declare class OutOutMode implements IOutModeManager {
5
4
  private readonly container;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadOutModesUpdater(engine: Engine): Promise<void>;
2
+ export declare function loadOutModesUpdater(engine: Engine, refresh?: boolean): Promise<void>;
@@ -16,7 +16,7 @@
16
16
  this.container = container;
17
17
  this.modes = ["destroy"];
18
18
  }
19
- update(particle, direction, delta, outMode) {
19
+ update(particle, direction, _delta, outMode) {
20
20
  if (!this.modes.includes(outMode)) {
21
21
  return;
22
22
  }
@@ -17,6 +17,11 @@
17
17
  class OutOfCanvasUpdater {
18
18
  constructor(container) {
19
19
  this.container = container;
20
+ this._updateOutMode = (particle, delta, outMode, direction) => {
21
+ for (const updater of this.updaters) {
22
+ updater.update(particle, direction, delta, outMode);
23
+ }
24
+ };
20
25
  this.updaters = [
21
26
  new BounceOutMode_1.BounceOutMode(container),
22
27
  new DestroyOutMode_1.DestroyOutMode(container),
@@ -30,17 +35,11 @@
30
35
  return !particle.destroyed && !particle.spawning;
31
36
  }
32
37
  update(particle, delta) {
33
- var _a, _b, _c, _d;
34
38
  const outModes = particle.options.move.outModes;
35
- this.updateOutMode(particle, delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, "bottom");
36
- this.updateOutMode(particle, delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, "left");
37
- this.updateOutMode(particle, delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, "right");
38
- this.updateOutMode(particle, delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, "top");
39
- }
40
- updateOutMode(particle, delta, outMode, direction) {
41
- for (const updater of this.updaters) {
42
- updater.update(particle, direction, delta, outMode);
43
- }
39
+ this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
40
+ this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
41
+ this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
42
+ this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
44
43
  }
45
44
  }
46
45
  exports.OutOfCanvasUpdater = OutOfCanvasUpdater;
package/umd/Utils.js CHANGED
@@ -12,16 +12,17 @@
12
12
  exports.bounceVertical = exports.bounceHorizontal = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  function bounceHorizontal(data) {
15
- if (data.outMode !== "bounce" &&
15
+ if ((data.outMode !== "bounce" &&
16
16
  data.outMode !== "bounce-horizontal" &&
17
17
  data.outMode !== "bounceHorizontal" &&
18
- data.outMode !== "split") {
18
+ data.outMode !== "split") ||
19
+ (data.direction !== "left" && data.direction !== "right")) {
19
20
  return;
20
21
  }
21
- if (data.bounds.right < 0) {
22
+ if (data.bounds.right < 0 && data.direction === "left") {
22
23
  data.particle.position.x = data.size + data.offset.x;
23
24
  }
24
- else if (data.bounds.left > data.canvasSize.width) {
25
+ else if (data.bounds.left > data.canvasSize.width && data.direction === "right") {
25
26
  data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
26
27
  }
27
28
  const velocity = data.particle.velocity.x;
@@ -36,10 +37,10 @@
36
37
  return;
37
38
  }
38
39
  const minPos = data.offset.x + data.size;
39
- if (data.bounds.right >= data.canvasSize.width) {
40
+ if (data.bounds.right >= data.canvasSize.width && data.direction === "right") {
40
41
  data.particle.position.x = data.canvasSize.width - minPos;
41
42
  }
42
- else if (data.bounds.left <= 0) {
43
+ else if (data.bounds.left <= 0 && data.direction === "left") {
43
44
  data.particle.position.x = minPos;
44
45
  }
45
46
  if (data.outMode === "split") {
@@ -48,16 +49,17 @@
48
49
  }
49
50
  exports.bounceHorizontal = bounceHorizontal;
50
51
  function bounceVertical(data) {
51
- if (data.outMode !== "bounce" &&
52
+ if ((data.outMode !== "bounce" &&
52
53
  data.outMode !== "bounce-vertical" &&
53
54
  data.outMode !== "bounceVertical" &&
54
- data.outMode !== "split") {
55
+ data.outMode !== "split") ||
56
+ (data.direction !== "bottom" && data.direction !== "top")) {
55
57
  return;
56
58
  }
57
- if (data.bounds.bottom < 0) {
59
+ if (data.bounds.bottom < 0 && data.direction === "top") {
58
60
  data.particle.position.y = data.size + data.offset.y;
59
61
  }
60
- else if (data.bounds.top > data.canvasSize.height) {
62
+ else if (data.bounds.top > data.canvasSize.height && data.direction === "bottom") {
61
63
  data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
62
64
  }
63
65
  const velocity = data.particle.velocity.y;
@@ -72,10 +74,10 @@
72
74
  return;
73
75
  }
74
76
  const minPos = data.offset.y + data.size;
75
- if (data.bounds.bottom >= data.canvasSize.height) {
77
+ if (data.bounds.bottom >= data.canvasSize.height && data.direction === "bottom") {
76
78
  data.particle.position.y = data.canvasSize.height - minPos;
77
79
  }
78
- else if (data.bounds.top <= 0) {
80
+ else if (data.bounds.top <= 0 && data.direction === "top") {
79
81
  data.particle.position.y = minPos;
80
82
  }
81
83
  if (data.outMode === "split") {
package/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadOutModesUpdater = void 0;
13
13
  const OutOfCanvasUpdater_1 = require("./OutOfCanvasUpdater");
14
- async function loadOutModesUpdater(engine) {
15
- await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater_1.OutOfCanvasUpdater(container));
14
+ async function loadOutModesUpdater(engine, refresh = true) {
15
+ await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater_1.OutOfCanvasUpdater(container), refresh);
16
16
  }
17
17
  exports.loadOutModesUpdater = loadOutModesUpdater;
18
18
  });