Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsparticles-updater-out-modes

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsparticles-updater-out-modes - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

73

browser/Utils.js
import { getValue } from "tsparticles-engine";
export function bounceHorizontal(data) {
if (!(data.outMode === "bounce" /* OutMode.bounce */ ||
data.outMode === "bounce-horizontal" /* OutMode.bounceHorizontal */ ||
data.outMode === "bounceHorizontal" ||
data.outMode === "split" /* OutMode.split */)) {
if (data.outMode !== "bounce" /* OutMode.bounce */ &&
data.outMode !== "bounce-horizontal" /* OutMode.bounceHorizontal */ &&
data.outMode !== "bounceHorizontal" &&
data.outMode !== "split" /* OutMode.split */) {
return;
}
if (data.bounds.right < 0) {
data.particle.position.x = data.size + data.offset.x;
}
else if (data.bounds.left > data.canvasSize.width) {
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
}
const velocity = data.particle.velocity.x;

@@ -32,30 +38,35 @@ let bounced = false;

export function bounceVertical(data) {
if (data.outMode === "bounce" /* OutMode.bounce */ ||
data.outMode === "bounce-vertical" /* OutMode.bounceVertical */ ||
data.outMode === "bounceVertical" ||
data.outMode === "split" /* OutMode.split */) {
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" /* OutModeDirection.bottom */ &&
data.bounds.bottom >= data.canvasSize.height &&
velocity > 0) ||
(data.direction === "top" /* OutModeDirection.top */ && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = getValue(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split" /* OutMode.split */) {
data.particle.destroy();
}
if (data.outMode !== "bounce" /* OutMode.bounce */ &&
data.outMode !== "bounce-vertical" /* OutMode.bounceVertical */ &&
data.outMode !== "bounceVertical" &&
data.outMode !== "split" /* OutMode.split */) {
return;
}
if (data.bounds.bottom < 0) {
data.particle.position.y = data.size + data.offset.y;
}
else if (data.bounds.top > data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
}
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" /* OutModeDirection.bottom */ && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
(data.direction === "top" /* OutModeDirection.top */ && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = getValue(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split" /* OutMode.split */) {
data.particle.destroy();
}
}

@@ -6,8 +6,14 @@ "use strict";

function bounceHorizontal(data) {
if (!(data.outMode === "bounce" ||
data.outMode === "bounce-horizontal" ||
data.outMode === "bounceHorizontal" ||
data.outMode === "split")) {
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-horizontal" &&
data.outMode !== "bounceHorizontal" &&
data.outMode !== "split") {
return;
}
if (data.bounds.right < 0) {
data.particle.position.x = data.size + data.offset.x;
}
else if (data.bounds.left > data.canvasSize.width) {
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
}
const velocity = data.particle.velocity.x;

@@ -37,31 +43,36 @@ let bounced = false;

function bounceVertical(data) {
if (data.outMode === "bounce" ||
data.outMode === "bounce-vertical" ||
data.outMode === "bounceVertical" ||
data.outMode === "split") {
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" &&
data.bounds.bottom >= data.canvasSize.height &&
velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = (0, tsparticles_engine_1.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-vertical" &&
data.outMode !== "bounceVertical" &&
data.outMode !== "split") {
return;
}
if (data.bounds.bottom < 0) {
data.particle.position.y = data.size + data.offset.y;
}
else if (data.bounds.top > data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
}
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = (0, tsparticles_engine_1.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
}
exports.bounceVertical = bounceVertical;
import { getValue } from "tsparticles-engine";
export function bounceHorizontal(data) {
if (!(data.outMode === "bounce" ||
data.outMode === "bounce-horizontal" ||
data.outMode === "bounceHorizontal" ||
data.outMode === "split")) {
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-horizontal" &&
data.outMode !== "bounceHorizontal" &&
data.outMode !== "split") {
return;
}
if (data.bounds.right < 0) {
data.particle.position.x = data.size + data.offset.x;
}
else if (data.bounds.left > data.canvasSize.width) {
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
}
const velocity = data.particle.velocity.x;

@@ -32,30 +38,35 @@ let bounced = false;

export function bounceVertical(data) {
if (data.outMode === "bounce" ||
data.outMode === "bounce-vertical" ||
data.outMode === "bounceVertical" ||
data.outMode === "split") {
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" &&
data.bounds.bottom >= data.canvasSize.height &&
velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = getValue(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-vertical" &&
data.outMode !== "bounceVertical" &&
data.outMode !== "split") {
return;
}
if (data.bounds.bottom < 0) {
data.particle.position.y = data.size + data.offset.y;
}
else if (data.bounds.top > data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
}
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = getValue(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
}
{
"name": "tsparticles-updater-out-modes",
"version": "2.1.0",
"version": "2.1.1",
"description": "tsParticles particles out modes updater",

@@ -75,4 +75,4 @@ "homepage": "https://particles.js.org/",

"dependencies": {
"tsparticles-engine": "^2.1.0"
"tsparticles-engine": "^2.1.1"
}
}

@@ -7,3 +7,3 @@ /*!

* How to use? : Check the GitHub README
* v2.1.0
* v2.1.1
*/

@@ -103,12 +103,18 @@ (function webpackUniversalModuleDefinition(root, factory) {

function bounceHorizontal(data) {
if (!(data.outMode === "bounce"
if (data.outMode !== "bounce"
/* OutMode.bounce */
|| data.outMode === "bounce-horizontal"
&& data.outMode !== "bounce-horizontal"
/* OutMode.bounceHorizontal */
|| data.outMode === "bounceHorizontal" || data.outMode === "split"
&& data.outMode !== "bounceHorizontal" && data.outMode !== "split"
/* OutMode.split */
)) {
) {
return;
}
if (data.bounds.right < 0) {
data.particle.position.x = data.size + data.offset.x;
} else if (data.bounds.left > data.canvasSize.width) {
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
}
const velocity = data.particle.velocity.x;

@@ -146,40 +152,48 @@ let bounced = false;

function bounceVertical(data) {
if (data.outMode === "bounce"
if (data.outMode !== "bounce"
/* OutMode.bounce */
|| data.outMode === "bounce-vertical"
&& data.outMode !== "bounce-vertical"
/* OutMode.bounceVertical */
|| data.outMode === "bounceVertical" || data.outMode === "split"
&& data.outMode !== "bounceVertical" && data.outMode !== "split"
/* OutMode.split */
) {
const velocity = data.particle.velocity.y;
let bounced = false;
return;
}
if (data.direction === "bottom"
/* OutModeDirection.bottom */
&& data.bounds.bottom >= data.canvasSize.height && velocity > 0 || data.direction === "top"
/* OutModeDirection.top */
&& data.bounds.top <= 0 && velocity < 0) {
const newVelocity = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (data.bounds.bottom < 0) {
data.particle.position.y = data.size + data.offset.y;
} else if (data.bounds.top > data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
}
if (!bounced) {
return;
}
const velocity = data.particle.velocity.y;
let bounced = false;
const minPos = data.offset.y + data.size;
if (data.direction === "bottom"
/* OutModeDirection.bottom */
&& data.bounds.bottom >= data.canvasSize.height && velocity > 0 || data.direction === "top"
/* OutModeDirection.top */
&& data.bounds.top <= 0 && velocity < 0) {
const newVelocity = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
} else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (!bounced) {
return;
}
if (data.outMode === "split"
/* OutMode.split */
) {
data.particle.destroy();
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
} else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split"
/* OutMode.split */
) {
data.particle.destroy();
}
}

@@ -186,0 +200,0 @@ ;// CONCATENATED MODULE: ./dist/browser/BounceOutMode.js

@@ -1,2 +0,2 @@

/*! tsParticles Out Modes Updater v2.1.0 by Matteo Bruni */
!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={818: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(818);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),l=s.canvas.size;!function(o){if("bounce"!==o.outMode&&"bounce-horizontal"!==o.outMode&&"bounceHorizontal"!==o.outMode&&"split"!==o.outMode)return;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){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,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=Math.random()*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=Math.random()*n.height,o.initialPosition.y=o.position.y)),"bottom"===e&&c.top>n.height+o.offset.y?(i||(o.position.x=Math.random()*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=Math.random()*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.updaters=[new o(t),new e(t),new r(t),new s(t)]}init(){}isEnabled(t){return!t.destroyed&&!t.spawning}update(t,o){var e,i,n,s;const r=t.options.move.outModes;this.updateOutMode(t,o,null!==(e=r.bottom)&&void 0!==e?e:r.default,"bottom"),this.updateOutMode(t,o,null!==(i=r.left)&&void 0!==i?i:r.default,"left"),this.updateOutMode(t,o,null!==(n=r.right)&&void 0!==n?n:r.default,"right"),this.updateOutMode(t,o,null!==(s=r.top)&&void 0!==s?s:r.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 a(t)))}})(),n})()));
/*! tsParticles Out Modes Updater v2.1.1 by Matteo Bruni */
!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={818: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(818);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=Math.random()*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=Math.random()*n.height,o.initialPosition.y=o.position.y)),"bottom"===e&&c.top>n.height+o.offset.y?(i||(o.position.x=Math.random()*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=Math.random()*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})()));

@@ -1,3 +0,3 @@

import type { Container, IDelta, OutModeAlt, Particle } from "tsparticles-engine";
import { OutMode, OutModeDirection } from "tsparticles-engine";
import type { Container, IDelta, OutModeAlt, OutModeDirection, Particle } from "tsparticles-engine";
import { OutMode } from "tsparticles-engine";
import type { IOutModeManager } from "./IOutModeManager";

@@ -4,0 +4,0 @@ export declare class DestroyOutMode implements IOutModeManager {

import type { IBounds, ICoordinates, IDimension, OutMode, OutModeAlt, OutModeDirection } from "tsparticles-engine";
import type { Particle } from "tsparticles-engine";
export interface IBounceData {
particle: Particle;
outMode: OutMode | OutModeAlt | keyof typeof OutMode;
direction: OutModeDirection;
bounds: IBounds;
canvasSize: IDimension;
direction: OutModeDirection;
offset: ICoordinates;
outMode: OutMode | OutModeAlt | keyof typeof OutMode;
particle: Particle;
size: number;
}
import type { IDelta, OutMode, OutModeAlt, OutModeDirection, Particle } from "tsparticles-engine";
export interface IOutModeManager {
modes: (OutMode | OutModeAlt | keyof typeof OutMode)[];
update(particle: Particle, direction: OutModeDirection, delta: IDelta, outMode: OutMode | OutModeAlt | keyof typeof OutMode): void;
modes: (OutMode | OutModeAlt | keyof typeof OutMode)[];
}

@@ -15,8 +15,14 @@ (function (factory) {

function bounceHorizontal(data) {
if (!(data.outMode === "bounce" ||
data.outMode === "bounce-horizontal" ||
data.outMode === "bounceHorizontal" ||
data.outMode === "split")) {
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-horizontal" &&
data.outMode !== "bounceHorizontal" &&
data.outMode !== "split") {
return;
}
if (data.bounds.right < 0) {
data.particle.position.x = data.size + data.offset.x;
}
else if (data.bounds.left > data.canvasSize.width) {
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
}
const velocity = data.particle.velocity.x;

@@ -46,32 +52,37 @@ let bounced = false;

function bounceVertical(data) {
if (data.outMode === "bounce" ||
data.outMode === "bounce-vertical" ||
data.outMode === "bounceVertical" ||
data.outMode === "split") {
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" &&
data.bounds.bottom >= data.canvasSize.height &&
velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = (0, tsparticles_engine_1.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
if (data.outMode !== "bounce" &&
data.outMode !== "bounce-vertical" &&
data.outMode !== "bounceVertical" &&
data.outMode !== "split") {
return;
}
if (data.bounds.bottom < 0) {
data.particle.position.y = data.size + data.offset.y;
}
else if (data.bounds.top > data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
}
const velocity = data.particle.velocity.y;
let bounced = false;
if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
(data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
const newVelocity = (0, tsparticles_engine_1.getValue)(data.particle.options.bounce.vertical);
data.particle.velocity.y *= -newVelocity;
bounced = true;
}
if (!bounced) {
return;
}
const minPos = data.offset.y + data.size;
if (data.bounds.bottom >= data.canvasSize.height) {
data.particle.position.y = data.canvasSize.height - minPos;
}
else if (data.bounds.top <= 0) {
data.particle.position.y = minPos;
}
if (data.outMode === "split") {
data.particle.destroy();
}
}
exports.bounceVertical = bounceVertical;
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc