UNPKG

jparticles

Version:

A lightweight, efficient and easy-to-use Canvas library for building some cool particle effects.

7 lines (6 loc) 26.1 kB
/*! * JParticles v3.5.0 (https://github.com/Barrior/JParticles) * Copyright 2016-2024 Barrior <Barrior@qq.com> * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JParticles={})}(this,(function(t){"use strict";var e,i,n,o={opacity:1,color:[],resize:!0},s={linear:function(t,e,i,n){return i+(n-i)*t},swing:function(t,e,i,n,o){return s.easeInOutQuad(t,e,i,n,o)},easeInOutQuad:function(t,e,i,n,o){return(e/=o/2)<1?n/2*e*e+i:-n/2*(--e*(e-2)-1)+i}},a=Math.PI/180,r=2*Math.PI,h=!!window.DeviceOrientationEvent,p=Function.prototype.toString,c=p.call(Object),l=/msie\s8.0/i.test(navigator.userAgent),f=!!Object.defineProperty&&!l,u={trimAll:/\s/g,http:/^(https?:\/\/|\/\/)/i,shapeStar:/^star(:\d+:\d+(\.\d+)?)?$/,imageBase64:/^data:image\/(png|jpe?g|gif|svg\+xml);base64,/};function d(t,e){return Object.prototype.toString.call(t)===e}function v(t){return d(t,"[object Function]")}function m(t){return Array.isArray(t)}function g(t){if(!d(t,"[object Object]"))return!1;var e=Object.getPrototypeOf(t);if(null===e)return!0;var i=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&p.call(i)===c}function y(t){return"string"==typeof t}function x(t){return void 0===t}function w(t){return null===t}function S(t){return!(!t||1!==t.nodeType)}function M(t,e){return void 0===e&&(e=10),parseInt(t,e)}function E(t,e){return void 0===e&&(e=0),parseFloat(Number(t).toFixed(e))}function b(t){return t[0].toUpperCase()+t.substring(1)}function O(t,e){var i=window.getComputedStyle(t)[e];if(y(i)){var n=i.match(/\d+/);if(n)return M(n[0])}}function C(t){var e=t.getBoundingClientRect();return{left:window.pageXOffset+e.left,top:window.pageYOffset+e.top}}!function(t){t.DESTROY="DESTROY",t.RESIZE="RESIZE"}(e||(e={})),function(t){t.PROGRESS="PROGRESS",t.FINISHED="FINISHED"}(i||(i={})),function(t){t.FINISHED="FINISHED"}(n||(n={}));var R,I,P=(R=window.MutationObserver||window.WebKitMutationObserver,I=function(t,e){if(t===e)return!0;if(S(t))for(var i=t.children,n=i.length;n--;)if(I(i[n],e))return!0;return!1},R?function(t,e){new R((function(i,n){for(var o=i.length;o--;)for(var s=i[o].removedNodes,a=s.length;a--;)if(I(s[a],t))return n.disconnect(),e()})).observe(document,{childList:!0,subtree:!0})}:function(t,e){var i=function(n){I(n.target,t)&&(document.removeEventListener("DOMNodeRemoved",i),e())};document.addEventListener("DOMNodeRemoved",i)});function A(t){return t*a}function T(t,e){return t>0&&t<1?t*e:t}function L(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var i=t.length,n=t[0]||{},o=0;o<i;o++)for(var s in t[o]){var a=t[o][s],r=Array.isArray(a);if(r||g(a)){var h=n[s];h=r?Array.isArray(h)?h:[]:g(h)?h:{},n[s]=L(h,a)}else n[s]=a}return n}function k(t,e,i){if(k.cachedImages[t])e(k.cachedImages[t]);else{var n=0;!function o(){var s=new Image;s.addEventListener("load",(function(){k.cachedImages[t]=s,e(s)})),s.addEventListener("error",(function(t){n++,null==i||i(t,n),n<=3&&o()})),s.crossOrigin="Anonymous",s.src=t}()}}function H(t,e){return t===e?t:Math.random()*(t-e)+e}function D(t,e){return(H(t,e)||t)*(Math.random()>.5?1:-1)}function W(){return"#"+Math.random().toString(16).slice(-6)}k.cachedImages={};var F=Object.freeze({__proto__:null,typeChecking:d,isFunction:v,isArray:m,isPlainObject:g,isString:y,isNumber:function(t){return"number"==typeof t},isBoolean:function(t){return"boolean"==typeof t},isUndefined:x,isNull:w,isNil:function(t){return x(t)||w(t)},isElement:S,getNumberValueOfStyle:O,offset:C,observeElementRemoved:P,degreesToRadians:A,radiansToDegrees:function(t){return t/a},calcQuantity:T,merge:L,loadImage:k,randomInRange:H,randomSpeed:D,randomColor:W,pInt:M,toFixed:E,trimAll:function(t){return t.replace(u.trimAll,"")},upperFirst:b}),z=function(){function t(){this.listenerMap={}}return t.prototype.on=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];this.listenerMap[t]||(this.listenerMap[t]=[]);for(var n=0,o=e;n<o.length;n++){var s=o[n];v(s)&&this.listenerMap[t].push(s)}return this},t.prototype.off=function(t,e){if(!t)return this.listenerMap={},this;if(!e)return this.listenerMap[t]=[],this;var i=this.listenerMap[t],n=i.indexOf(e);return-1!==n&&i.splice(n,1),this},t.prototype.trigger=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var n=this.listenerMap[t];return Array.isArray(n)&&n.forEach((function(t){t.apply(void 0,e)})),this},t}(),Y=function(t,e){return(Y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(t,e)};function N(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}Y(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var X,j=function(){return(j=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function q(t,e){for(var i=0,n=e.length,o=t.length;i<n;i++,o++)t[o]=e[i];return t}window.requestAnimationFrame=(X=window).requestAnimationFrame||X.webkitRequestAnimationFrame||X.mozRequestAnimationFrame||function(t){return X.setTimeout(t,1e3/60)},Math.hypot||(Math.hypot=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var i=0,n=0,o=!1,s=0;s<arguments.length;++s){var a=Math.abs(Number(t[s]));a===1/0&&(o=!0),a>i&&(n*=i/a*(i/a),i=a),n+=0===a&&0===i?0:a/i*(a/i)}return o||i===1/0?1/0:i*Math.sqrt(n)});var _=function(){function t(t,e,i){this.elements=[],this.isCanvasRemoved=!1,this.isPaused=!1,this.eventEmitter=new z,this.isRunningSupported=!1,f&&(this.container=S(e)?e:document.querySelector(e),this.isRunningSupported=!!this.container,this.container&&(this.options=L({},o,t,i),this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.container.innerHTML="",this.container.appendChild(this.canvas),this.getColor=this.makeColorMethod()))}return t.prototype.bootstrap=function(){this.isRunningSupported&&(this.setCanvasDimension(),this.observeCanvasRemoved(),this.resizeEvent(),this.init(),this.draw())},t.prototype.clearCanvasAndSetGlobalAttrs=function(){var t=this,e=t.ctx,i=t.canvasWidth,n=t.canvasHeight;e.clearRect(0,0,i,n),e.globalAlpha=this.options.opacity},t.prototype.makeColorMethod=function(){var t=this.options.color,e=Array.isArray(t)?t.length:0;return y(t)?function(){return t}:0===e?W:function(){return t[Math.floor(Math.random()*e)]}},t.prototype.setCanvasDimension=function(){var t=window.devicePixelRatio,e=O(this.container,"width")||485,i=O(this.container,"height")||300;this.canvasWidth=e,this.canvasHeight=i,this.canvas.width=e*t,this.canvas.height=i*t,this.canvas.style.width=e+"px",this.canvas.style.height=i+"px",this.ctx.scale(t,t)},t.prototype.observeCanvasRemoved=function(){var t=this;P(this.canvas,(function(){t.isCanvasRemoved=!0,t.resizeHandler&&window.removeEventListener("resize",t.resizeHandler),t.eventEmitter.trigger(e.DESTROY),t.eventEmitter.off()}))},t.prototype.requestAnimationFrame=function(){this.isPaused||this.isCanvasRemoved||window.requestAnimationFrame(this.draw.bind(this))},t.prototype.resizeEvent=function(){var t=this;this.options.resize&&(this.resizeHandler=function(){var i=t.canvasWidth,n=t.canvasHeight;t.setCanvasDimension();var o=t.canvasWidth/i,s=t.canvasHeight/n;t.elements.forEach((function(t){g(t)&&(t.x*=o,t.y*=s)})),t.eventEmitter.trigger(e.RESIZE,o,s),t.isPaused&&t.draw()},window.addEventListener("resize",this.resizeHandler))},t.prototype.pause=function(){!this.isRunningSupported||this.isCanvasRemoved||this.isPaused||(this.isPaused=!0)},t.prototype.open=function(){this.isRunningSupported&&!this.isCanvasRemoved&&this.isPaused&&(this.isPaused=!1,this.draw())},t.prototype.onDestroy=function(){for(var t,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];return(t=this.eventEmitter).on.apply(t,q([e.DESTROY],i)),this},t.prototype.onResize=function(){for(var t,i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];return(t=this.eventEmitter).on.apply(t,q([e.RESIZE],i)),this},t}(),G=function(t){function e(i,n){var o=t.call(this,e.defaultConfig,i,n)||this;return o.specificAngles=[-180,-90,0,90,180],o.bootstrap(),o}return N(e,t),e.prototype.init=function(){this.createLines(this.options.num),this.createLinesOnClick()},e.prototype.createLines=function(t,e){for(var i=this.options,n=i.maxWidth,o=i.minWidth,s=i.maxSpeed,a=i.minSpeed,r=i.maxDegree,h=i.minDegree;t--;)this.elements.push({x:null!=e?e:Math.random()*this.canvasWidth,width:H(n,o),color:this.getColor(),speed:D(s,a),degree:E(H(r,h)%180)})},e.prototype.createLinesOnClick=function(){var t=this;if(this.options.createOnClick){var e=function(e){if(!t.isPaused){var i=e.pageX-C(t.canvas).left;t.createLines(t.options.numberOfCreations,i)}};this.canvas.addEventListener("click",e),this.onDestroy((function(){t.canvas.removeEventListener("click",e)}))}},e.prototype.draw=function(){var t=this,e=this,i=e.ctx,n=e.canvasWidth,o=e.canvasHeight,s=this.options,a=s.removeOnOverflow,r=s.overflowCompensation,h=s.reservedLines;this.clearCanvasAndSetGlobalAttrs();var p=10*Math.hypot(n,o),c=Math.max(0,r);this.elements.forEach((function(e,n){var o=A(-e.degree),s=0;t.specificAngles.includes(e.degree)||(s=Math.abs(t.canvasHeight/2/Math.tan(o))),i.save(),i.beginPath(),i.translate(e.x,t.canvasHeight/2),i.rotate(o),i.moveTo(-p,0),i.lineTo(p,0),i.lineWidth=e.width,i.strokeStyle=e.color,i.stroke(),i.closePath(),i.restore(),t.isPaused||(e.x+=e.speed);var r=!1,l=!1;e.x+s+e.width+c<0?(r=!0,l=!0):e.x>t.canvasWidth+s+e.width+c&&(r=!0),r&&(a&&t.elements.length>h?t.elements.splice(n,1):e.speed=Math.abs(e.speed)*(l?1:-1))})),this.requestAnimationFrame()},e.defaultConfig={num:6,maxWidth:2,minWidth:1,maxSpeed:3,minSpeed:1,maxDegree:90,minDegree:80,createOnClick:!0,numberOfCreations:3,removeOnOverflow:!0,overflowCompensation:20,reservedLines:6},e}(_),V=["circle","triangle","star","image"];function B(t){if(y(t)){if("circle"===t||"triangle"===t)return{type:t};if(u.shapeStar.test(t)){var e=t.split(":");return{type:"star",sides:Number(e[1])||5,dent:Number(e[2])||.5}}if(u.http.test(t)||u.imageBase64.test(t)){var i={type:"image",isImageLoaded:!1};return k(t,(function(t){i.isImageLoaded=!0,i.source=t})),i}console.warn("Shape value of "+t+" is invalid.")}try{if(t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageBitmap||t instanceof OffscreenCanvas)return{type:"image",isImageLoaded:!0,source:t}}catch(t){console.warn("Your browser does not support [CanvasImageSource](https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource), please upgrade it.")}return{type:"image",isImageLoaded:!1}}function Z(t,e,i,n,o,s){t.translate(e,i),t.moveTo(0,0-n);for(var a=0;a<o;a++)t.rotate(Math.PI/o),t.lineTo(0,0-n*s),t.rotate(Math.PI/o),t.lineTo(0,0-n)}var Q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return N(e,t),e.prototype.getShapeData=function(){var t=this.options.shape,e={type:"circle"};if(!t)return e;if(m(t)){var i=t.length;return i?B(t[Math.floor(Math.random()*i)]):e}return B(t)},e.prototype.drawShape=function(t){var e=t.shape,i=e.type,n=e.isImageLoaded,o=e.source,s=e.sides,h=e.dent;if(-1!==V.indexOf(i)&&("image"!==i||n&&o)){if(this.ctx.save(),this.ctx.translate(t.x,t.y),this.ctx.rotate(t.rotate*a),"image"===i){var p=2*t.r;this.ctx.drawImage(o,0,0,o.width||p,o.height||p,-t.r,-t.r,p,p)}else{switch(this.ctx.beginPath(),t.shape.type){case"circle":this.ctx.arc(0,0,t.r,0,r);break;case"triangle":Z(this.ctx,0,0,t.r,3,.5);break;case"star":Z(this.ctx,0,0,t.r,s,h)}this.ctx.fillStyle=t.color,this.ctx.fill()}this.ctx.restore()}},e}(_),U=function(t){function e(i,n){var o=t.call(this,e.defaultConfig,i,n)||this;return o.mouseX=0,o.mouseY=0,o.bootstrap(),o}return N(e,t),e.prototype.init=function(){this.ownResizeEvent(),this.optionsNormalize(),this.options.range>0&&(this.positionX=Math.random()*this.canvasWidth,this.positionY=Math.random()*this.canvasHeight,this.defineLineShape(),this.positionEvent()),this.mouseX=this.mouseY=0,this.parallaxEvent(),this.createDots()},e.prototype.optionsNormalize=function(){var t=this.canvasWidth,e=this.options;["num","proximity","range"].forEach((function(i){e[i]=M(T(e[i],t))})),S(e.eventElem)||e.eventElem===document||(e.eventElem=this.canvas)},e.prototype.defineLineShape=function(){var t=this,e=this.options,i=e.proximity,n=e.range;switch(e.lineShape){case"cube":this.lineShapeMaker=function(e,o,s,a,r){var h=t,p=h.positionX,c=h.positionY;Math.abs(e-s)<=i&&Math.abs(o-a)<=i&&Math.abs(e-p)<=n&&Math.abs(o-c)<=n&&Math.abs(s-p)<=n&&Math.abs(a-c)<=n&&r()};break;default:this.lineShapeMaker=function(e,o,s,a,r){var h=t,p=h.positionX,c=h.positionY;Math.abs(e-s)<=i&&Math.abs(o-a)<=i&&(Math.abs(e-p)<=n&&Math.abs(o-c)<=n||Math.abs(s-p)<=n&&Math.abs(a-c)<=n)&&r()}}},e.prototype.createDots=function(){for(var t=this,e=t.canvasWidth,i=t.canvasHeight,n=t.getColor,o=this.options,s=o.maxR,a=o.minR,r=o.maxSpeed,h=o.minSpeed,p=o.parallaxLayer,c=o.spin,l=o.spinMaxSpeed,f=o.spinMinSpeed,u=p.length,d=this.options.num;d--;){var v=H(s,a);this.elements.push({r:v,x:H(e-v,v),y:H(i-v,v),vx:D(r,h),vy:D(r,h),color:n(),shape:this.getShapeData(),parallaxLayer:p[Math.floor(Math.random()*u)],parallaxOffsetX:0,parallaxOffsetY:0,rotate:c?H(0,360):0,rotateSpeed:D(l,f)})}},e.prototype.draw=function(){var t=this,e=this.ctx,i=this.options.lineWidth;this.clearCanvasAndSetGlobalAttrs(),e.lineWidth=i,this.updateXY(),this.elements.forEach((function(e){var i=e.x,n=e.y,o=e.parallaxOffsetX,s=e.parallaxOffsetY;t.updateElementRotate(e),t.drawShape(j(j({},e),{x:i+o,y:n+s}))})),this.connectDots(),this.requestAnimationFrame()},e.prototype.updateElementRotate=function(t){this.options.spin&&!this.isPaused&&(t.rotate+=t.rotateSpeed,t.rotate>=360&&(t.rotate=t.rotate-360))},e.prototype.connectDots=function(){if(!(this.options.range<=0)){var t=this,e=t.elements,i=t.ctx,n=t.lineShapeMaker,o=e.length;e.forEach((function(t,s){for(var a=t.x+t.parallaxOffsetX,r=t.y+t.parallaxOffsetY,h=function(){var o=e[s],h=o.x+o.parallaxOffsetX,p=o.y+o.parallaxOffsetY;null==n||n(a,r,h,p,(function(){i.save(),i.beginPath(),i.moveTo(a,r),i.lineTo(h,p),i.strokeStyle=t.color,i.stroke(),i.restore()}))};++s<o;)h()}))}},e.prototype.updateXY=function(){var t=this,e=t.isPaused,i=t.mouseX,n=t.mouseY,o=t.canvasWidth,s=t.canvasHeight,a=this.options,r=a.parallax,h=a.parallaxStrength;e||this.elements.forEach((function(t){if(r){var e=h*t.parallaxLayer;t.parallaxOffsetX+=(i/e-t.parallaxOffsetX)/10,t.parallaxOffsetY+=(n/e-t.parallaxOffsetY)/10}t.x+=t.vx,t.y+=t.vy;var a=t.r,p=t.parallaxOffsetX,c=t.parallaxOffsetY,l=t.x,f=t.y;f+=c,(l+=p)+a>=o?t.vx=-Math.abs(t.vx):l-a<=0&&(t.vx=Math.abs(t.vx)),f+a>=s?t.vy=-Math.abs(t.vy):f-a<=0&&(t.vy=Math.abs(t.vy))}))},e.prototype.getEventElemOffset=function(){var t=this.options.eventElem;return t===document?null:C(t)},e.prototype.eventProxy=function(t,e){var i,n=this,o=this.options.eventElem;h&&(i=function(t){n.isPaused||w(t.beta)||e(Math.min(Math.max(t.beta,-90),90),t.gamma)},window.addEventListener("deviceorientation",i));var s=function(e){if(!n.isPaused){var i=e.pageX,o=e.pageY,s=n.getEventElemOffset();s&&(i-=s.left,o-=s.top),t(i,o)}};o.addEventListener("mousemove",s),this.onDestroy((function(){window.removeEventListener("deviceorientation",i),o.removeEventListener("mousemove",s)}))},e.prototype.positionEvent=function(){var t=this,e=this.options.range;e>this.canvasWidth&&e>this.canvasHeight||this.eventProxy((function(e,i){t.positionX=e,t.positionY=i}),(function(e,i){t.positionX=-(i-90)/180*t.canvasWidth,t.positionY=-(e-90)/180*t.canvasHeight}))},e.prototype.parallaxEvent=function(){var t=this;this.options.parallax&&this.eventProxy((function(e,i){t.mouseX=e-t.canvasWidth/2,t.mouseY=i-t.canvasHeight/2}),(function(e,i){t.mouseX=-i*t.canvasWidth/180,t.mouseY=-e*t.canvasHeight/180}))},e.prototype.ownResizeEvent=function(){var t=this;this.onResize((function(e,i){t.options.range>0&&(t.positionX*=e,t.positionY*=i,t.mouseX*=e,t.mouseY*=i)}))},e.defaultConfig={num:.12,maxR:2.4,minR:.6,maxSpeed:1,minSpeed:.1,proximity:.2,range:.2,lineWidth:.2,lineShape:"spider",eventElem:null,parallax:!1,parallaxLayer:[1,2,3],parallaxStrength:3,spin:!1,spinMaxSpeed:5,spinMinSpeed:1},e}(Q),J=function(t){function e(i,n){var o=t.call(this,e.defaultConfig,i,n)||this;return o.startTime=Date.now(),o.isFinished=!1,o.bootstrap(),o}return N(e,t),e.prototype.init=function(){this.createSnowflakes()},e.prototype.createSnowflake=function(){var t=this.options,e=t.maxR,i=t.minR,n=t.maxSpeed,o=t.minSpeed,s=t.spin,a=t.spinMaxSpeed,r=t.spinMinSpeed,h=H(e,i);return{r:h,x:Math.random()*this.canvasWidth,y:-h,vx:D(n,o),vy:Math.abs(h*D(n,o)),color:this.getColor(),swingAt:Date.now(),shape:this.getShapeData(),rotate:s?H(0,360):0,rotateSpeed:D(a,r)}},e.prototype.createSnowflakes=function(){for(var t=Math.max(0,Math.ceil(Math.random()*this.options.num));t--;)this.elements.push(this.createSnowflake())},e.prototype.draw=function(){var t=this,e=this,i=e.canvasWidth,o=e.canvasHeight,s=e.isPaused,a=this.options,r=a.maxR,h=a.swing,p=a.swingInterval,c=a.swingProbability,l=a.duration;(this.clearCanvasAndSetGlobalAttrs(),this.elements.forEach((function(e,n,a){var f=e.x,u=e.y,d=e.r;t.updateElementRotate(e),t.drawShape(e),s||(e.x+=e.vx,e.y+=e.vy,h&&Date.now()-e.swingAt>p&&Math.random()<d/r*c&&(e.swingAt=Date.now(),e.vx*=-1),f+d<0||f-d>i?l?a.splice(n,1):a.splice(n,1,t.createSnowflake()):u-d>o&&a.splice(n,1))})),s)||(!(!!l&&Date.now()-this.startTime>l)&&Math.random()>.9&&this.createSnowflakes(),this.elements.length?this.requestAnimationFrame():(this.isFinished=!0,this.eventEmitter.trigger(n.FINISHED)))},e.prototype.updateElementRotate=function(t){this.options.spin&&!this.isPaused&&(t.rotate+=t.rotateSpeed,t.rotate>=360&&(t.rotate=t.rotate-360))},e.prototype.fallAgain=function(){this.isRunningSupported&&!this.isCanvasRemoved&&!this.isPaused&&this.isFinished&&(this.isFinished=!1,this.startTime=Date.now(),this.createSnowflakes(),this.draw())},e.prototype.onFinished=function(){for(var t,e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];return(t=this.eventEmitter).on.apply(t,q([n.FINISHED],e)),this},e.defaultConfig={num:6,color:"#fff",maxR:6.5,minR:.5,maxSpeed:.6,minSpeed:.1,swing:!0,swingInterval:2e3,swingProbability:.06,spin:!1,spinMaxSpeed:5,spinMinSpeed:1},e}(Q),K=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.completedMap={},e}return N(e,t),e.prototype.loadMaskImage=function(){var t=this,e=this.options.mask;if(e)if(y(e)){if(this.completedMap[e])return void(this.maskImage=this.completedMap[e]);k(e,(function(i){t.completedMap[e]=i,t.maskImage=i}))}else this.maskImage=e},e.prototype.renderMaskMode=function(t){if(this.maskImage){var e=this.options.maskMode||"normal";this.ctx.save(),this["mode"+b(e)](t),this.ctx.restore()}else t()},e.prototype.modeNormal=function(t){this.drawMaskImage(),this.ctx.globalCompositeOperation="source-atop",t()},e.prototype.modeGhost=function(t){this.ctx.save(),this.ctx.filter="grayscale(100%)",this.drawMaskImage(),this.ctx.restore(),this.ctx.globalCompositeOperation="source-atop",t(),this.ctx.clip(),this.drawMaskImage()},e.prototype.drawMaskImage=function(){if(this.maskImage){var t=this,e=t.ctx,i=t.canvasWidth,n=t.canvasHeight,o=t.maskImage,s=o.width,a=o.height,r=s/a,h=s>i?i:s,p=a>n?n:a;s>a?p=h/r:h=p*r;var c=(i-h)/2,l=(n-p)/2;e.drawImage(o,0,0,s,a,c,l,h,p)}},e}(_),$=["fill","fillColor","line","lineColor","lineWidth","offsetLeft","offsetTop","crestHeight","speed"],tt=["opacity","mask","maskMode"],et=q(q([],$),["crestCount"]),it=function(t){function e(i,n){var o=t.call(this,e.defaultConfig,i,n)||this;return o.waveLength=[],o.bootstrap(),o}return N(e,t),e.prototype.init=function(){this.ownResizeEvent(),this.optionsNormalize(),this.loadMaskImage(),this.createDots()},e.prototype.optionsNormalize=function(){var t=this;et.forEach((function(i){for(var n=t.options.num,o=t.options[i],s=[],a="offsetLeft"===i?t.canvasWidth:t.canvasHeight;n--;){var r=Array.isArray(o)?o[n]:o;s[n]=x(r)?t.getOptionDefaultValue(i):e.getOptionProcessedValue(i,r,a),"crestCount"===i&&(t.waveLength[n]=t.canvasWidth/s[n])}t.options[i]=s}))},e.prototype.getOptionDefaultValue=function(t){var e=this.canvasWidth,i=this.canvasHeight;switch(t){case"lineColor":case"fillColor":return W();case"lineWidth":return H(2,.2);case"offsetLeft":return Math.random()*e;case"offsetTop":case"crestHeight":return Math.random()*i;case"crestCount":return H(e/2,1);case"speed":return H(.4,.1);case"fill":return!1;case"line":return!0}},e.getOptionProcessedValue=function(t,e,i){return"offsetTop"===t||"offsetLeft"===t||"crestHeight"===t?T(e,i):e},e.prototype.createDots=function(){for(var t=this.canvasWidth,e=this.waveLength,i=this.options.num;i--;){for(var n=[],o=r/e[i],s=0;s<=t;s++)n.push({x:s,y:s*o});this.elements[i]=n}},e.prototype.draw=function(){var t=this;this.clearCanvasAndSetGlobalAttrs(),this.renderMaskMode((function(){t.drawWaves()})),this.requestAnimationFrame()},e.prototype.drawWaves=function(){var t=this,e=t.ctx,i=t.canvasWidth,n=t.canvasHeight,o=t.isPaused,s=this.options;this.elements.forEach((function(t,a){var r=s.crestHeight[a],h=s.offsetLeft[a],p=s.offsetTop[a],c=s.speed[a];e.save(),e.beginPath(),t.forEach((function(t,i){e[i?"lineTo":"moveTo"](t.x,r*Math.sin(t.y+h)+p),!o&&(t.y-=c)})),s.fill[a]&&(e.lineTo(i,n),e.lineTo(0,n),e.closePath(),e.fillStyle=s.fillColor[a],e.fill()),s.line[a]&&(e.lineWidth=s.lineWidth[a],e.strokeStyle=s.lineColor[a],e.stroke()),e.restore()}))},e.prototype.ownResizeEvent=function(){var t=this,e=["offsetLeft","offsetTop","crestHeight"],i=this.options;this.onResize((function(n,o){e.forEach((function(t){var e="offsetLeft"===t?n:o;i[t].forEach((function(t,i,n){n[i]=t*e}))})),t.elements.forEach((function(t){t.forEach((function(t){t.x*=n,t.y*=o}))}))}))},e.prototype.updateComplexOptions=function(t,i){if(i){var n="offsetLeft"===t?this.canvasWidth:this.canvasHeight,o=this.options,s=Array.isArray(i);o[t].forEach((function(o,a,r){var h=s?i[a]:i;x(h=e.getOptionProcessedValue(t,h,n))&&(h=o),r[a]=h}))}},e.prototype.updatePlainOptions=function(t,e){this.options[t]=e,"mask"===t&&this.loadMaskImage()},e.prototype.setOptions=function(t){if(this.isRunningSupported&&g(t))for(var e in t)Object.hasOwnProperty.call(t,e)&&(-1!==tt.indexOf(e)?this.updatePlainOptions(e,t[e]):-1!==$.indexOf(e)&&this.updateComplexOptions(e,t[e]))},e.defaultConfig={num:3,fill:!1,fillColor:[],line:!0,lineColor:[],lineWidth:[],offsetLeft:[],offsetTop:[],crestHeight:[],crestCount:[],speed:[]},e}(K),nt=["font","textColor","textFormatter","borderRadius"],ot=function(t){function e(i,n){var o=t.call(this,i,L({},e.defaultConfig,n))||this;return o.progress=0,o.isCompletedImmediately=!1,o.fastStepValue=1,o}return N(e,t),e.prototype.init=function(){this.halfCH=this.canvasHeight/2,this.setOffsetTop(this.canvasHeight),this.setCanvasStyle(),this.ownResizeEvent(),this.optionsNormalize(),this.loadMaskImage(),this.createDots(),this.waveLoadingResizeEvent()},e.prototype.setOffsetTop=function(t){var e=this.options.offsetTop;Array.isArray(e)?e.forEach((function(e,i,n){n[i]=t})):this.options.offsetTop=t},e.prototype.setCanvasStyle=function(){this.canvas.style.borderRadius=this.options.borderRadius},e.prototype.draw=function(){this.calcProgress(),this.progress<100?(this.mainDrawing(),this.requestAnimationFrame()):(this.progress=100,this.mainDrawing(),this.eventEmitter.trigger(i.FINISHED))},e.prototype.mainDrawing=function(){var t=this;this.eventEmitter.trigger(i.PROGRESS,this.progress),this.calcOffsetTop(),this.clearCanvasAndSetGlobalAttrs(),this.renderMaskMode((function(){t.drawWaves()})),this.drawText()},e.prototype.drawText=function(){var t=this,e=t.ctx,i=t.canvasWidth,n=t.halfCH,o=t.progress,s=this.options,a=s.font,r=s.textFormatter,h=s.textColor;if(y(r)&&r){var p=r.replace(/%d/g,String(Math.floor(o)));e.save(),e.font=a;var c=(i-e.measureText(p).width)/2;e.textBaseline="middle",e.fillStyle=h,e.font=a,e.fillText(p,c,n),e.restore()}},e.prototype.calcProgress=function(){if(this.isCompletedImmediately)return this.progress+=this.fastStepValue,void(this.fastStepValue+=.5);if(!(this.progress>=e.progressThreshold)){this.startTime||(this.startTime=Date.now());var t=Date.now()-this.startTime,i=t/this.options.duration;i<=1&&(this.progress=s[this.options.easing](i,t,0,100,this.options.duration),this.progress+.9>=e.progressThreshold&&(this.progress=e.progressThreshold))}},e.prototype.calcOffsetTop=function(){if(this.isCompletedImmediately||!(this.progress>=e.progressThreshold)){var t=Math.max.apply(Math,this.options.crestHeight),i=100===this.progress?-t:Math.ceil((100-this.progress)/100*this.canvasHeight+t);this.setOffsetTop(i)}},e.prototype.waveLoadingResizeEvent=function(){var t=this;this.onResize((function(){t.halfCH=t.canvasHeight/2,100===t.progress&&t.draw()}))},e.prototype.setOptions=function(e){if(this.isRunningSupported&&g(e))for(var i in t.prototype.setOptions.call(this,e),e)if(Object.hasOwnProperty.call(e,i)&&-1!==nt.indexOf(i)){var n=e[i];this.options[i]=n,"borderRadius"===i&&this.setCanvasStyle()}},e.prototype.done=function(){this.isRunningSupported&&!this.isCompletedImmediately&&(this.isCompletedImmediately=!0)},e.prototype.onProgress=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return(t=this.eventEmitter).on.apply(t,q([i.PROGRESS],e)),this},e.prototype.onFinished=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return(t=this.eventEmitter).on.apply(t,q([i.FINISHED],e)),this},e.defaultConfig={num:1,font:"normal 400 16px Arial",textColor:"#333",textFormatter:"loading...%d%",fill:!0,line:!1,fillColor:"#27C9E5",borderRadius:"50%",offsetLeft:0,crestHeight:4,crestCount:1,speed:.3,duration:5e3,easing:"swing"},e.progressThreshold=99.99,e}(it);t.Events=z,t.Line=G,t.Particle=U,t.Snow=J,t.Wave=it,t.WaveLoading=ot,t.commonConfig=o,t.easing=s,t.utils=F}));