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 • 11.3 kB
JavaScript
/*! tsParticles v1.42.2 by Matteo Bruni */
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var o=t();for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(window,(function(){return function(){"use strict";var e={d:function(t,o){for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function o(e,t,o){return Math.min(Math.max(e,t),o)}function n(e,t,o,n){return Math.floor((e*o+t*n)/(o+n))}function i(e){const t=s(e);let o=r(e);return t===o&&(o=0),Math.random()*(t-o)+o}function r(e){return"number"==typeof e?e:e.min}function s(e){return"number"==typeof e?e:e.max}function a(e,t){if(e===t||void 0===t&&"number"==typeof e)return e;const o=r(e),n=s(e);return void 0!==t?{min:Math.min(o,t),max:Math.max(n,t)}:a(o,n)}function l(e,t){return function(e,t){const o=e.x-t.x,n=e.y-t.y;return{dx:o,dy:n,distance:Math.sqrt(o*o+n*n)}}(e,t).distance}function u(e,t){if(t instanceof Array){for(const o of t)if(e.matches(o))return!0;return!1}return e.matches(t)}function b(e,t){return e===t||t instanceof Array&&t.indexOf(e)>-1}function c(e,t,o=!0){return e[void 0!==t&&o?t%e.length:function(e){return Math.floor(Math.random()*e.length)}(e)]}function d(e,t){const o=e.selectors;if(o instanceof Array)for(const n of o)t(n,e);else t(o,e)}function f(e,t){if(t&&e)return e instanceof Array?e.find((e=>u(t,e.selectors))):u(t,e.selectors)?e:void 0}function v(e,t,o){let n=o;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function h(e){if(e.startsWith("rgb")){const t=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.]+)\s*)?\)/i.exec(e);return t?{a:t.length>4?parseFloat(t[5]):1,b:parseInt(t[3],10),g:parseInt(t[2],10),r:parseInt(t[1],10)}:void 0}if(e.startsWith("hsl")){const t=/hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i.exec(e);return t?function(e){const t=g(e);return{a:e.a,b:t.b,g:t.g,r:t.r}}({a:t.length>4?parseFloat(t[5]):1,h:parseInt(t[1],10),l:parseInt(t[3],10),s:parseInt(t[2],10)}):void 0}if(e.startsWith("hsv")){const t=/hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i.exec(e);return t?function(e){const t=m(e);return{a:e.a,b:t.b,g:t.g,r:t.r}}({a:t.length>4?parseFloat(t[5]):1,h:parseInt(t[1],10),s:parseInt(t[2],10),v:parseInt(t[3],10)}):void 0}{const t=/^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i,o=e.replace(t,((e,t,o,n,i)=>t+t+o+o+n+n+(void 0!==i?i+i:""))),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(o);return n?{a:void 0!==n[4]?parseInt(n[4],16)/255:1,b:parseInt(n[3],16),g:parseInt(n[2],16),r:parseInt(n[1],16)}:void 0}}function p(e,t,o=!0){var n,i,r;if(void 0===e)return;const s="string"==typeof e?{value:e}:e;let a;if("string"==typeof s.value)a=s.value===O.randomColorValue?M():function(e){return h(e)}(s.value);else if(s.value instanceof Array){a=p({value:c(s.value,t,o)})}else{const e=s.value,t=null!==(n=e.rgb)&&void 0!==n?n:s.value;if(void 0!==t.r)a=t;else{const t=null!==(i=e.hsl)&&void 0!==i?i:s.value;if(void 0!==t.h&&void 0!==t.l)a=g(t);else{const t=null!==(r=e.hsv)&&void 0!==r?r:s.value;void 0!==t.h&&void 0!==t.v&&(a=m(t))}}}return a}function y(e){const t=e.r/255,o=e.g/255,n=e.b/255,i=Math.max(t,o,n),r=Math.min(t,o,n),s={h:0,l:(i+r)/2,s:0};return i!=r&&(s.s=s.l<.5?(i-r)/(i+r):(i-r)/(2-i-r),s.h=t===i?(o-n)/(i-r):s.h=o===i?2+(n-t)/(i-r):4+(t-o)/(i-r)),s.l*=100,s.s*=100,s.h*=60,s.h<0&&(s.h+=360),s}function g(e){const t={b:0,g:0,r:0},o={h:e.h/360,l:e.l/100,s:e.s/100};if(0===o.s)t.b=o.l,t.g=o.l,t.r=o.l;else{const e=o.l<.5?o.l*(1+o.s):o.l+o.s-o.l*o.s,n=2*o.l-e;t.r=v(n,e,o.h+1/3),t.g=v(n,e,o.h),t.b=v(n,e,o.h-1/3)}return t.r=Math.floor(255*t.r),t.g=Math.floor(255*t.g),t.b=Math.floor(255*t.b),t}function m(e){const t={b:0,g:0,r:0},o=e.h/60,n=e.s/100,i=e.v/100,r=i*n,s=r*(1-Math.abs(o%2-1));let a;if(o>=0&&o<=1?a={r:r,g:s,b:0}:o>1&&o<=2?a={r:s,g:r,b:0}:o>2&&o<=3?a={r:0,g:r,b:s}:o>3&&o<=4?a={r:0,g:s,b:r}:o>4&&o<=5?a={r:s,g:0,b:r}:o>5&&o<=6&&(a={r:r,g:0,b:s}),a){const e=i-r;t.r=Math.floor(255*(a.r+e)),t.g=Math.floor(255*(a.g+e)),t.b=Math.floor(255*(a.b+e))}return t}function M(e){const t=null!=e?e:0;return{b:Math.floor(i(a(t,256))),g:Math.floor(i(a(t,256))),r:Math.floor(i(a(t,256)))}}function x(e,t,o,i){let r=e,s=t;return void 0===r.r&&(r=g(e)),void 0===s.r&&(s=g(t)),{b:n(r.b,s.b,o,i),g:n(r.g,s.g,o,i),r:n(r.r,s.r,o,i)}}e.r(t),e.d(t,{loadExternalBubbleInteraction:function(){return B}});class z{constructor(e,t){this.position={x:e,y:t}}}class w extends z{constructor(e,t,o){super(e,t),this.radius=o}contains(e){return l(e,this.position)<=this.radius}intersects(e){const t=e,o=e,n=this.position,i=e.position,r=Math.abs(i.x-n.x),s=Math.abs(i.y-n.y),a=this.radius;if(void 0!==o.radius){return a+o.radius>Math.sqrt(r*r+s+s)}if(void 0!==t.size){const e=t.size.width,o=t.size.height,n=Math.pow(r-e,2)+Math.pow(s-o,2);return!(r>a+e||s>a+o)&&(r<=e||s<=o||n<=a*a)}return!1}}class O{}O.generatedAttribute="generated",O.randomColorValue="random",O.midColorValue="mid",O.touchEndEvent="touchend",O.mouseDownEvent="mousedown",O.mouseUpEvent="mouseup",O.mouseMoveEvent="mousemove",O.touchStartEvent="touchstart",O.touchMoveEvent="touchmove",O.mouseLeaveEvent="mouseleave",O.mouseOutEvent="mouseout",O.touchCancelEvent="touchcancel",O.resizeEvent="resize",O.visibilityChangeEvent="visibilitychange",O.noPolygonDataLoaded="No polygon data loaded.",O.noPolygonFound="No polygon found, you need to specify SVG url in config.";new WeakMap;new WeakMap;class E extends z{constructor(e,t,o,n){super(e,t),this.size={height:n,width:o}}contains(e){const t=this.size.width,o=this.size.height,n=this.position;return e.x>=n.x&&e.x<=n.x+t&&e.y>=n.y&&e.y<=n.y+o}intersects(e){const t=e,o=e,n=this.size.width,i=this.size.height,r=this.position,s=e.position;if(void 0!==o.radius)return o.intersects(this);if(void 0!==t.size){const e=t.size,o=e.width,a=e.height;return s.x<r.x+n&&s.x+o>r.x&&s.y<r.y+i&&s.y+a>r.y}return!1}}new WeakMap,new WeakSet;new WeakMap;new WeakMap;new WeakMap;function C(e,t,n,i){if(t>=n){return o(e+(t-n)*i,e,t)}if(t<n){return o(e-(n-t)*i,t,e)}}new WeakMap;class k extends class{constructor(e){this.container=e,this.type=0}}{constructor(e){super(e)}isEnabled(){const e=this.container,t=e.actualOptions,o=e.interactivity.mouse,n=t.interactivity.events,i=function(e,t){return t instanceof Array?!!t.find((t=>t.enable&&b(e,t.mode))):b(e,t.mode)}("bubble",n.onDiv);if(!(i||n.onHover.enable&&o.position||n.onClick.enable&&o.clickPosition))return!1;const r=n.onHover.mode,s=n.onClick.mode;return b("bubble",r)||b("bubble",s)||i}reset(e,t){e.bubble.inRange&&!t||(delete e.bubble.div,delete e.bubble.opacity,delete e.bubble.radius,delete e.bubble.color)}async interact(){const e=this.container.actualOptions.interactivity.events,t=e.onHover,o=e.onClick,n=t.enable,i=t.mode,r=o.enable,s=o.mode,a=e.onDiv;n&&b("bubble",i)?this.hoverBubble():r&&b("bubble",s)?this.clickBubble():function(e,t,o){if(t instanceof Array)for(const n of t){const t=n.mode;n.enable&&b(e,t)&&d(n,o)}else{const n=t.mode;t.enable&&b(e,n)&&d(t,o)}}("bubble",a,((e,t)=>this.singleSelectorHover(e,t)))}singleSelectorHover(e,t){const o=this.container,n=document.querySelectorAll(e);n.length&&n.forEach((e=>{const n=e,i=o.retina.pixelRatio,r={x:(n.offsetLeft+n.offsetWidth/2)*i,y:(n.offsetTop+n.offsetHeight/2)*i},s=n.offsetWidth/2*i,a="circle"===t.type?new w(r.x,r.y,s):new E(n.offsetLeft*i,n.offsetTop*i,n.offsetWidth*i,n.offsetHeight*i),l=o.particles.quadTree.query(a);for(const e of l){if(!a.contains(e.getPosition()))continue;e.bubble.inRange=!0;const t=f(o.actualOptions.interactivity.modes.bubble.divs,n);e.bubble.div&&e.bubble.div===n||(this.reset(e,!0),e.bubble.div=n),this.hoverBubbleSize(e,1,t),this.hoverBubbleOpacity(e,1,t),this.hoverBubbleColor(e,1,t)}}))}process(e,t,o,n){const i=this.container,r=n.bubbleObj.optValue;if(void 0===r)return;const s=i.actualOptions.interactivity.modes.bubble.duration,a=i.retina.bubbleModeDistance,l=n.particlesObj.optValue,u=n.bubbleObj.value,b=n.particlesObj.value||0,c=n.type;if(r!==l)if(i.bubble.durationEnd)u&&("size"===c&&delete e.bubble.radius,"opacity"===c&&delete e.bubble.opacity);else if(t<=a){if((null!=u?u:b)!==r){const t=b-o*(b-r)/s;"size"===c&&(e.bubble.radius=t),"opacity"===c&&(e.bubble.opacity=t)}}else"size"===c&&delete e.bubble.radius,"opacity"===c&&delete e.bubble.opacity}clickBubble(){var e,t;const o=this.container,n=o.actualOptions,i=o.interactivity.mouse.clickPosition;if(!i)return;const r=o.retina.bubbleModeDistance,a=o.particles.quadTree.queryCircle(i,r);for(const r of a){if(!o.bubble.clicking)continue;r.bubble.inRange=!o.bubble.durationEnd;const a=l(r.getPosition(),i),u=((new Date).getTime()-(o.interactivity.mouse.clickTime||0))/1e3;u>n.interactivity.modes.bubble.duration&&(o.bubble.durationEnd=!0),u>2*n.interactivity.modes.bubble.duration&&(o.bubble.clicking=!1,o.bubble.durationEnd=!1);const b={bubbleObj:{optValue:o.retina.bubbleModeSize,value:r.bubble.radius},particlesObj:{optValue:s(r.options.size.value)*o.retina.pixelRatio,value:r.size.value},type:"size"};this.process(r,a,u,b);const c={bubbleObj:{optValue:n.interactivity.modes.bubble.opacity,value:r.bubble.opacity},particlesObj:{optValue:s(r.options.opacity.value),value:null!==(t=null===(e=r.opacity)||void 0===e?void 0:e.value)&&void 0!==t?t:1},type:"opacity"};this.process(r,a,u,c),o.bubble.durationEnd?delete r.bubble.color:a<=o.retina.bubbleModeDistance?this.hoverBubbleColor(r,a):delete r.bubble.color}}hoverBubble(){const e=this.container,t=e.interactivity.mouse.position;if(void 0===t)return;const o=e.retina.bubbleModeDistance,n=e.particles.quadTree.queryCircle(t,o);for(const i of n){i.bubble.inRange=!0;const n=l(i.getPosition(),t),r=1-n/o;n<=o?r>=0&&e.interactivity.status===O.mouseMoveEvent&&(this.hoverBubbleSize(i,r),this.hoverBubbleOpacity(i,r),this.hoverBubbleColor(i,r)):this.reset(i),e.interactivity.status===O.mouseLeaveEvent&&this.reset(i)}}hoverBubbleSize(e,t,o){const n=this.container,i=(null==o?void 0:o.size)?o.size*n.retina.pixelRatio:n.retina.bubbleModeSize;if(void 0===i)return;const r=s(e.options.size.value)*n.retina.pixelRatio,a=C(e.size.value,i,r,t);void 0!==a&&(e.bubble.radius=a)}hoverBubbleOpacity(e,t,o){var n,i,r;const a=this.container.actualOptions,l=null!==(n=null==o?void 0:o.opacity)&&void 0!==n?n:a.interactivity.modes.bubble.opacity;if(!l)return;const u=e.options.opacity.value,b=C(null!==(r=null===(i=e.opacity)||void 0===i?void 0:i.value)&&void 0!==r?r:1,l,s(u),t);void 0!==b&&(e.bubble.opacity=b)}hoverBubbleColor(e,t,o){const n=this.container.actualOptions,i=null!=o?o:n.interactivity.modes.bubble;if(!e.bubble.finalColor){const t=i.color;if(!t)return;const o=t instanceof Array?c(t):t;e.bubble.finalColor=function(e,t,o=!0){const n=p(e,t,o);return void 0!==n?y(n):void 0}(o)}if(e.bubble.finalColor)if(i.mix){e.bubble.color=void 0;const o=e.getFillColor();e.bubble.color=o?y(x(o,e.bubble.finalColor,1-t,t)):e.bubble.finalColor}else e.bubble.color=e.bubble.finalColor}}async function B(e){await e.addInteractor("externalBubble",(e=>new k(e)))}return t}()}));