UNPKG

ngx-particlesjs

Version:

[![npm](https://img.shields.io/npm/v/ngx-particlesjs.svg)](https://www.npmjs.com/package/ngx-particlesjs) [![npm](https://img.shields.io/npm/dm/ngx-particlesjs.svg)](https://www.npmjs.com/package/ngx-particlesjs) [![TypeScript](https://img.shields.io/badg

2 lines 4.33 kB
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-particlesjs",["exports","@angular/core"],i):i(t["ngx-particlesjs"]={},t.ng.core)}(this,function(t,i){"use strict";function o(t){var i="function"==typeof Symbol&&t[Symbol.iterator],e=0;return i?i.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}}function e(t){return Math.floor(100*t)/100}var n=function(){function t(t,i,e){void 0===i&&(i="normal"),void 0===e&&(e=1.5),this.max_width=t[0],this.max_height=t[1],this.initPosition(),this.initSpeed(i),this.initSize(e),this.initColor()}return t.prototype.onRange=function(t){this.max_width=t[0],this.max_height=t[1]},t.prototype.initPosition=function(){this.x=e(Math.random()*this.max_width),this.y=e(Math.random()*this.max_height)},t.prototype.initSpeed=function(t){var i=[];if("string"==typeof t)switch(t){case"fast":i=[1,1];break;case"normal":i=[2,2];break;case"slow":i=[5,5];break;default:i=[2,2]}else i=t;this.vx=e(Math.random()/i[0]),this.vy=e(Math.random()/i[1])},t.prototype.initSize=function(t){this.size=(1+Math.random())*t},t.prototype.initColor=function(){this.color="rgb("+Math.floor(256*Math.random())+","+Math.floor(256*Math.random())+","+Math.floor(256*Math.random())+")"},t.prototype.draw=function(t){t.beginPath(),t.arc(this.x,this.y,this.size,0,2*Math.PI),t.fillStyle=this.color,t.strokeStyle=this.color,t.closePath(),t.fill(),t.stroke()},t.prototype.update=function(){this.edge(),this.x=this.x+this.vx,this.y=this.y+this.vy},t.prototype.edge=function(){(this.x+this.vx>this.max_width||this.x+this.vx<0)&&(this.vx=-this.vx),(this.y+this.vy>this.max_height||this.y+this.vy<0)&&(this.vy=-this.vy)},t}(),a=function(){function t(){var h=this;this.particles=[],this.resizing=!1,this.total=100,this.stageChange=function(){var t,i;h.initStage();var e=[h.width,h.height];try{for(var n=o(h.particles),a=n.next();!a.done;a=n.next()){a.value.onRange(e)}}catch(s){t={error:s}}finally{try{a&&!a.done&&(i=n["return"])&&i.call(n)}finally{if(t)throw t.error}}h.resizing=!1},this.drawContext=function(){var t,i;h.ctx.clearRect(0,0,h.width,h.height);try{for(var e=o(h.particles),n=e.next();!n.done;n=e.next()){var a=n.value;a.draw(h.ctx),a.update()}}catch(s){t={error:s}}finally{try{n&&!n.done&&(i=e["return"])&&i.call(e)}finally{if(t)throw t.error}}h.mainAnimationFrame=window.requestAnimationFrame(h.drawContext),h.resizing=!1}}return t.prototype.ngAfterViewInit=function(){this.canvas=this.stageRef.nativeElement,this.ctx=this.canvas.getContext("2d",{alpha:!1}),this.initStage(),this.initParticle(),this.drawContext()},t.prototype.ngOnDestroy=function(){this.ctx.clearRect(0,0,this.width,this.height),window.cancelAnimationFrame(this.mainAnimationFrame),window.cancelAnimationFrame(this.changeAnimationFrame)},t.prototype.onResize=function(){this.resizing||this.default_height&&this.default_width||(this.resizing=!0,window.requestAnimationFrame?window.requestAnimationFrame(this.stageChange):setTimeout(this.stageChange,66))},t.prototype.initStage=function(){var t=this.canvas.parentElement,i=t.clientWidth,e=t.clientHeight;this.default_width?this.canvas.width=this.width=this.default_width:this.canvas.width=this.width=i,this.default_height?this.canvas.height=this.height=this.default_height:this.canvas.height=this.height=e},t.prototype.initParticle=function(){for(var t=[this.width,this.height],i=0;i<this.total;i++)this.particles[i]=new n(t,this.args&&this.args.speed?this.args.speed:"normal",this.args&&this.args.size?this.args.size:1.5)},t.decorators=[{type:i.Component,args:[{selector:"ngx-particle",template:'\n <div id="stage">\n <canvas #stageRef></canvas>\n </div>\n ',styles:["\n #stage {\n height: 100%;\n width: 100%;\n will-change: all;\n }\n "]}]}],t.propDecorators={stageRef:[{type:i.ViewChild,args:["stageRef"]}],total:[{type:i.Input}],default_width:[{type:i.Input}],default_height:[{type:i.Input}],args:[{type:i.Input}],onResize:[{type:i.HostListener,args:["window:resize"]}]},t}(),s=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{imports:[],declarations:[a],exports:[a]}]}],t}();t.NgxParticlesModule=s,t.ɵa=a,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ngx-particlesjs.umd.min.js.map