UNPKG

tsparticles

Version:

Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.

2 lines 5.86 kB
/*! tsParticles v1.42.2 by Matteo Bruni */ !function(t,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o();else if("function"==typeof define&&define.amd)define([],o);else{var e=o();for(var i in e)("object"==typeof exports?exports:t)[i]=e[i]}}(window,(function(){return function(){"use strict";var t={d:function(o,e){for(var i in e)t.o(e,i)&&!t.o(o,i)&&Object.defineProperty(o,i,{enumerable:!0,get:e[i]})},o:function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},o={};t.r(o),t.d(o,{loadOutModesUpdater:function(){return c}});class e{}e.generatedAttribute="generated",e.randomColorValue="random",e.midColorValue="mid",e.touchEndEvent="touchend",e.mouseDownEvent="mousedown",e.mouseUpEvent="mouseup",e.mouseMoveEvent="mousemove",e.touchStartEvent="touchstart",e.touchMoveEvent="touchmove",e.mouseLeaveEvent="mouseleave",e.mouseOutEvent="mouseout",e.touchCancelEvent="touchcancel",e.resizeEvent="resize",e.visibilityChangeEvent="visibilitychange",e.noPolygonDataLoaded="No polygon data loaded.",e.noPolygonFound="No polygon found, you need to specify SVG url in config.";new WeakMap;new WeakMap;new WeakMap,new WeakSet;new WeakMap;new WeakMap;new WeakMap;function i(t){return"number"==typeof t?t:function(t){const o=s(t);let e=n(t);return o===e&&(e=0),Math.random()*(o-e)+e}(t)}function n(t){return"number"==typeof t?t:t.min}function s(t){return"number"==typeof t?t:t.max}function a(t,o,e,i){return function(t,o,e){let i=!0;e&&"bottom"!==e||(i=t.top<o.height);!i||e&&"left"!==e||(i=t.right>0);!i||e&&"right"!==e||(i=t.left<o.width);!i||e&&"top"!==e||(i=t.bottom>0);return i}(r(t,null!=e?e:0),o,i)}function r(t,o){return{bottom:t.y+o,left:t.x-o,right:t.x+o,top:t.y-o}}new WeakMap;class u{constructor(t){this.container=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){switch(e){case"bounce":case"bounce-vertical":case"bounce-horizontal":case"bounceVertical":case"bounceHorizontal":case"split":this.bounce(t,o,i,e);break;case"destroy":this.destroy(t,i);break;case"out":this.out(t,i);break;case"none":default:this.none(t,i)}}destroy(t,o){const e=this.container;a(t.position,e.canvas.size,t.getRadius(),o)||e.particles.remove(t,void 0,!0)}out(t,o){const e=this.container;if(a(t.position,e.canvas.size,t.getRadius(),o))return;const i=t.options.move.warp,n=e.canvas.size,s={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},u=t.getRadius(),c=r(t.position,u);"right"===o&&c.left>n.width+t.offset.x?(t.position.x=s.left,t.initialPosition.x=t.position.x,i||(t.position.y=Math.random()*n.height,t.initialPosition.y=t.position.y)):"left"===o&&c.right<-t.offset.x&&(t.position.x=s.right,t.initialPosition.x=t.position.x,i||(t.position.y=Math.random()*n.height,t.initialPosition.y=t.position.y)),"bottom"===o&&c.top>n.height+t.offset.y?(i||(t.position.x=Math.random()*n.width,t.initialPosition.x=t.position.x),t.position.y=s.top,t.initialPosition.y=t.position.y):"top"===o&&c.bottom<-t.offset.y&&(i||(t.position.x=Math.random()*n.width,t.initialPosition.x=t.position.x),t.position.y=s.bottom,t.initialPosition.y=t.position.y)}bounce(t,o,e,n){const s=this.container;let a=!1;for(const[,i]of s.plugins)if(void 0!==i.particleBounce&&(a=i.particleBounce(t,o,e)),a)break;if(a)return;const u=t.getPosition(),c=t.offset,d=t.getRadius(),l=r(u,d),p=s.canvas.size;!function(t){if("bounce"!==t.outMode&&"bounce-horizontal"!==t.outMode&&"bounceHorizontal"!==t.outMode&&"split"!==t.outMode)return;const o=t.particle.velocity.x;let e=!1;if("right"===t.direction&&t.bounds.right>=t.canvasSize.width&&o>0||"left"===t.direction&&t.bounds.left<=0&&o<0){const o=i(t.particle.options.bounce.horizontal.value);t.particle.velocity.x*=-o,e=!0}if(!e)return;const n=t.offset.x+t.size;t.bounds.right>=t.canvasSize.width?t.particle.position.x=t.canvasSize.width-n:t.bounds.left<=0&&(t.particle.position.x=n),"split"===t.outMode&&t.particle.destroy()}({particle:t,outMode:n,direction:e,bounds:l,canvasSize:p,offset:c,size:d}),function(t){if("bounce"===t.outMode||"bounce-vertical"===t.outMode||"bounceVertical"===t.outMode||"split"===t.outMode){const o=t.particle.velocity.y;let e=!1;if("bottom"===t.direction&&t.bounds.bottom>=t.canvasSize.height&&o>0||"top"===t.direction&&t.bounds.top<=0&&o<0){const o=i(t.particle.options.bounce.vertical.value);t.particle.velocity.y*=-o,e=!0}if(!e)return;const n=t.offset.y+t.size;t.bounds.bottom>=t.canvasSize.height?t.particle.position.y=t.canvasSize.height-n:t.bounds.top<=0&&(t.particle.position.y=n),"split"===t.outMode&&t.particle.destroy()}}({particle:t,outMode:n,direction:e,bounds:l,canvasSize:p,offset:c,size:d})}none(t,o){if(t.options.move.distance.horizontal&&("left"===o||"right"===o)||t.options.move.distance.vertical&&("top"===o||"bottom"===o))return;const e=t.options.move.gravity,i=this.container,n=i.canvas.size,s=t.getRadius();if(e.enable){const a=t.position;(!e.inverse&&a.y>n.height+s&&"bottom"===o||e.inverse&&a.y<-s&&"top"===o)&&i.particles.remove(t)}else{if(t.velocity.y>0&&t.position.y<=n.height+s||t.velocity.y<0&&t.position.y>=-s||t.velocity.x>0&&t.position.x<=n.width+s||t.velocity.x<0&&t.position.x>=-s)return;a(t.position,i.canvas.size,s,o)||i.particles.remove(t)}}}async function c(t){await t.addParticleUpdater("outModes",(t=>new u(t)))}return o}()}));