ngx-skycons
Version:
This is a Skycons Angular 7 library.
2 lines • 10.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-skycons",["exports","@angular/core"],e):e(t["ngx-skycons"]={},t.ng.core)}(this,function(t,e){"use strict";var i={CLEAR_DAY:"CLEARDAY",CLEAR_NIGHT:"CLEARNIGHT",PARTLY_CLOUDY_DAY:"PARTLYCLOUDYDAY",PARTLY_CLOUDY_NIGHT:"PARTLYCLOUDYNIGHT",CLOUDY:"CLOUDY",RAIN:"RAIN",SLEET:"SLEET",SNOW:"SNOW",WIND:"WIND",FOG:"FOG"},d=.08,T=2*Math.PI,p=2/Math.sqrt(2),o=function(){function t(){this.list=[],this.raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame,this.caf=window.cancelAnimationFrame||window.webkitCancelAnimationFrame,this.WIND_PATHS=[[-.75,-.18,-.7219,-.1527,-.6971,-.1225,-.6739,-.091,-.6516,-.0588,-.6298,-.0262,-.6083,.0065,-.5868,.0396,-.5643,.0731,-.5372,.1041,-.5033,.1259,-.4662,.1406,-.4275,.1493,-.3881,.153,-.3487,.1526,-.3095,.1488,-.2708,.1421,-.2319,.1342,-.1943,.1217,-.16,.1025,-.129,.0785,-.1012,.0509,-.0764,.0206,-.0547,-.012,-.0378,-.0472,-.0324,-.0857,-.0389,-.1241,-.0546,-.1599,-.0814,-.1876,-.1193,-.1964,-.1582,-.1935,-.1931,-.1769,-.2157,-.1453,-.229,-.1085,-.2327,-.0697,-.224,-.0317,-.2064,.0033,-.1853,.0362,-.1613,.0672,-.135,.0961,-.1051,.1213,-.0706,.1397,-.0332,.1512,.0053,.158,.0442,.1624,.0833,.1636,.1224,.1615,.1613,.1565,.1999,.15,.2378,.1402,.2749,.1279,.3118,.1147,.3487,.1015,.3858,.0892,.4236,.0787,.4621,.0715,.5012,.0702,.5398,.0766,.5768,.089,.6123,.1055,.6466,.1244,.6805,.144,.7147,.163,.75,.18],[-.75,0,-.7033,.0195,-.6569,.0399,-.6104,.06,-.5634,.0789,-.5155,.0954,-.4667,.1089,-.4174,.1206,-.3676,.1299,-.3174,.1365,-.2669,.1398,-.2162,.1391,-.1658,.1347,-.1157,.1271,-.0661,.1169,-.017,.1046,.0316,.0903,.0791,.0728,.1259,.0534,.1723,.0331,.2188,.0129,.2656,-.0064,.3122,-.0263,.3586,-.0466,.4052,-.0665,.4525,-.0847,.5007,-.1002,.5497,-.113,.5991,-.124,.6491,-.1325,.6994,-.138,.75,-.14]],this.WIND_OFFSETS=[{start:.36,end:.11},{start:.56,end:.16}]}return t.prototype.requestInterval=function(t,e){var o=this,i={value:null},n=function(){i.value=o.raf(n),t()};return n(),i},t.prototype.cancelInterval=function(t){this.caf(t.value)},t.prototype.circle=function(t,e,o,i){t.beginPath(),t.arc(e,o,i,0,T,!1),t.fill()},t.prototype.line=function(t,e,o,i,n){t.beginPath(),t.moveTo(e,o),t.lineTo(i,n),t.stroke()},t.prototype.puff=function(t,e,o,i,n,a,s,r){var h=Math.cos(e*T),c=Math.sin(e*T);r-=s,this.circle(t,o-c*n,i+h*a+.5*r,s+(1-.5*h)*r)},t.prototype.puffs=function(t,e,o,i,n,a,s,r){var h;for(h=5;h--;)this.puff(t,e+h/5,o,i,n,a,s,r)},t.prototype.cloud=function(t,e,o,i,n,a,s){e/=3e4;var r=.21*n,h=.12*n,c=.24*n,l=.28*n;t.fillStyle=s,this.puffs(t,e,o,i,r,h,c,l),t.globalCompositeOperation="destination-out",this.puffs(t,e,o,i,r,h,c-a,l-a),t.globalCompositeOperation="source-over"},t.prototype.sun=function(t,e,o,i,n,a,s){e/=12e4;var r,h,c,l,p=.25*n-.5*a,u=.32*n+.5*a,f=.5*n-.5*a;for(t.strokeStyle=s,t.lineWidth=a,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.arc(o,i,p,0,T,!1),t.stroke(),r=8;r--;)h=(e+r/8)*T,c=Math.cos(h),l=Math.sin(h),this.line(t,o+c*u,i+l*u,o+c*f,i+l*f)},t.prototype.moon=function(t,e,o,i,n,a,s){e/=15e3;var r=.29*n-.5*a,h=.05*n,c=Math.cos(e*T),l=c*T/-16;t.strokeStyle=s,t.lineWidth=a,t.lineCap="round",t.lineJoin="round",o+=c*h,t.beginPath(),t.arc(o,i,r,l+T/8,l+7*T/8,!1),t.arc(o+Math.cos(l)*r*p,i+Math.sin(l)*r*p,r,l+5*T/8,l+3*T/8,!0),t.closePath(),t.stroke()},t.prototype._rain=function(t,e,o,i,n,a,s){e/=1350;var r,h,c,l,p=.16*n,u=11*T/12,f=7*T/12;for(t.fillStyle=s,r=4;r--;)c=o+(r-1.5)/1.5*(1===r||2===r?-1:1)*p,l=i+(h=(e+r/4)%1)*h*n,t.beginPath(),t.moveTo(c,l-1.5*a),t.arc(c,l,.75*a,u,f,!1),t.fill()},t.prototype._sleet=function(t,e,o,i,n,a,s){e/=750;var r,h,c,l,p=.1875*n;for(t.strokeStyle=s,t.lineWidth=.5*a,t.lineCap="round",t.lineJoin="round",r=4;r--;)h=(e+r/4)%1,c=Math.floor(o+(r-1.5)/1.5*(1===r||2===r?-1:1)*p)+.5,l=i+h*n,this.line(t,c,l-1.5*a,c,l+1.5*a)},t.prototype._snow=function(t,e,o,i,n,a,s){var r,h,c,l,p=.16*n,u=.75*a,f=(e/=3e3)*T*.7,d=Math.cos(f)*u,y=Math.sin(f)*u,v=f+T/3,g=Math.cos(v)*u,w=Math.sin(v)*u,C=f+2*T/3,M=Math.cos(C)*u,m=Math.sin(C)*u;for(t.strokeStyle=s,t.lineWidth=.5*a,t.lineCap="round",t.lineJoin="round",r=4;r--;)h=(e+r/4)%1,c=o+Math.sin((h+r/4)*T)*p,l=i+h*n,this.line(t,c-d,l-y,c+d,l+y),this.line(t,c-g,l-w,c+g,l+w),this.line(t,c-M,l-m,c+M,l+m)},t.prototype.fogbank=function(t,e,o,i,n,a,s){e/=3e4;var r=.21*n,h=.06*n,c=.21*n,l=.28*n;t.fillStyle=s,this.puffs(t,e,o,i,r,h,c,l),t.globalCompositeOperation="destination-out",this.puffs(t,e,o,i,r,h,c-a,l-a),t.globalCompositeOperation="source-over"},t.prototype.leaf=function(t,e,o,i,n,a,s){var r=n/8,h=r/3,c=2*h,l=e%1*T,p=Math.cos(l),u=Math.sin(l);t.fillStyle=s,t.strokeStyle=s,t.lineWidth=a,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.arc(o,i,r,l,l+Math.PI,!1),t.arc(o-h*p,i-h*u,c,l+Math.PI,l,!1),t.arc(o+c*p,i+c*u,h,l+Math.PI,l,!0),t.globalCompositeOperation="destination-out",t.fill(),t.globalCompositeOperation="source-over",t.stroke()},t.prototype.swoosh=function(t,e,o,i,n,a,s,r,h){e/=2500;var c,l,p,u,f=this.WIND_PATHS[s],d=(e+s-this.WIND_OFFSETS[s].start)%r,y=(e+s-this.WIND_OFFSETS[s].end)%r,v=(e+s)%r;if(t.strokeStyle=h,t.lineWidth=a,t.lineCap="round",t.lineJoin="round",d<1){if(t.beginPath(),d*=f.length/2-1,d-=c=Math.floor(d),c*=2,c+=2,t.moveTo(o+(f[c-2]*(1-d)+f[c]*d)*n,i+(f[c-1]*(1-d)+f[c+1]*d)*n),y<1){for(y*=f.length/2-1,y-=l=Math.floor(y),l*=2,l+=2,u=c;u!==l;u+=2)t.lineTo(o+f[u]*n,i+f[u+1]*n);t.lineTo(o+(f[l-2]*(1-y)+f[l]*y)*n,i+(f[l-1]*(1-y)+f[l+1]*y)*n)}else for(u=c;u!==f.length;u+=2)t.lineTo(o+f[u]*n,i+f[u+1]*n);t.stroke()}else if(y<1){for(t.beginPath(),y*=f.length/2-1,y-=l=Math.floor(y),l*=2,l+=2,t.moveTo(o+f[0]*n,i+f[1]*n),u=2;u!==l;u+=2)t.lineTo(o+f[u]*n,i+f[u+1]*n);t.lineTo(o+(f[l-2]*(1-y)+f[l]*y)*n,i+(f[l-1]*(1-y)+f[l+1]*y)*n),t.stroke()}v<1&&(v*=f.length/2-1,v-=p=Math.floor(v),p*=2,p+=2,this.leaf(t,e,o+(f[p-2]*(1-v)+f[p]*v)*n,i+(f[p-1]*(1-v)+f[p+1]*v)*n,n,a,h))},t.prototype.clearDay=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.sun(t,e,.5*i,.5*n,a,a*d,o)},t.prototype.clearNight=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.moon(t,e,.5*i,.5*n,a,a*d,o)},t.prototype.partlyCloudyDay=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.sun(t,e,.625*i,.375*n,.75*a,a*d,o),this.cloud(t,e,.375*i,.625*n,.75*a,a*d,o)},t.prototype.partlyCloudyNight=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.moon(t,e,.667*i,.375*n,.75*a,a*d,o),this.cloud(t,e,.375*i,.625*n,.75*a,a*d,o)},t.prototype.cloudy=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.cloud(t,e,.5*i,.5*n,a,a*d,o)},t.prototype.rain=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this._rain(t,e,.5*i,.37*n,.9*a,a*d,o),this.cloud(t,e,.5*i,.37*n,.9*a,a*d,o)},t.prototype.sleet=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this._sleet(t,e,.5*i,.37*n,.9*a,a*d,o),this.cloud(t,e,.5*i,.37*n,.9*a,a*d,o)},t.prototype.snow=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this._snow(t,e,.5*i,.37*n,.9*a,a*d,o),this.cloud(t,e,.5*i,.37*n,.9*a,a*d,o)},t.prototype.wind=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n);this.swoosh(t,e,.5*i,.5*n,a,a*d,0,2,o),this.swoosh(t,e,.5*i,.5*n,a,a*d,1,2,o)},t.prototype.fog=function(t,e,o){var i=t.canvas.width,n=t.canvas.height,a=Math.min(i,n),s=a*d;this.fogbank(t,e,.5*i,.32*n,.75*a,s,o),e/=5e3;var r=Math.cos(e*T)*a*.02,h=Math.cos((e+.25)*T)*a*.02,c=Math.cos((e+.5)*T)*a*.02,l=Math.cos((e+.75)*T)*a*.02,p=.936*n,u=Math.floor(p-.5*s)+.5,f=Math.floor(p-2.5*s)+.5;t.strokeStyle=o,t.lineWidth=s,t.lineCap="round",t.lineJoin="round",this.line(t,r+.2*i+.5*s,u,h+.8*i-.5*s,u),this.line(t,c+.2*i+.5*s,f,l+.8*i-.5*s,f)},t.prototype.ngOnInit=function(){},t.prototype.ngOnChanges=function(t){this.remove(),this.ctx=this.canvas.nativeElement,this.add(),this.play()},t.prototype.ngAfterViewInit=function(){this.ctx=this.canvas.nativeElement,this.color||(this.color="#000"),this.add(),this.play()},t.prototype.add=function(){if(this.ctx&&this.weather){var t,e=this.ctx;null!==e&&(t={element:e,context:e.getContext("2d")},this.list.push(t),this.draw(t,500))}},t.prototype.draw=function(t,e){var o=t.context.canvas;switch(this.resizeClear?o.width=o.width:t.context.clearRect(0,0,o.width,o.height),this.weather=this.weather.replace(/[_-\s]/,"").toUpperCase(),this.weather.includes("DAY")&&this.weather.includes("CLOUD")?this.weather=i.PARTLY_CLOUDY_DAY:this.weather.includes("NIGHT")&&this.weather.includes("CLOUD")?this.weather=i.PARTLY_CLOUDY_NIGHT:this.weather.includes("RAIN")&&(this.weather=i.RAIN),this.weather){case i.CLEAR_DAY:this.clearDay(t.context,e,this.color);break;case i.CLEAR_NIGHT:this.clearNight(t.context,e,this.color);break;case i.PARTLY_CLOUDY_DAY:this.partlyCloudyDay(t.context,e,this.color);break;case i.PARTLY_CLOUDY_NIGHT:this.partlyCloudyNight(t.context,e,this.color);break;case i.CLOUDY:this.cloudy(t.context,e,this.color);break;case i.RAIN:this.rain(t.context,e,this.color);break;case i.SLEET:this.sleet(t.context,e,this.color);break;case i.SNOW:this.snow(t.context,e,this.color);break;case i.WIND:this.wind(t.context,e,this.color);break;case i.FOG:this.fog(t.context,e,this.color)}},t.prototype.play=function(){var o=this;this.pause(),this.interval=this.requestInterval(function(){var t,e=Date.now();for(t=o.list.length;t--;)o.draw(o.list[t],e)},1e3/60)},t.prototype.pause=function(){this.interval&&(this.cancelInterval(this.interval),this.interval=null)},t.prototype.remove=function(){for(var t=this.ctx,e=this.list.length;e--;)if(this.list[e].element===t)return void this.list.splice(e,1)},t.decorators=[{type:e.Component,args:[{selector:"sc-skycons",template:'\n <canvas #skyconCanvas class="skycons__canvas"></canvas>\n ',styles:["\n :host {\n width: 100%;\n display: inline-block;\n }\n "]}]}],t.ctorParameters=function(){return[]},t.propDecorators={canvas:[{type:e.ViewChild,args:["skyconCanvas"]}],weather:[{type:e.Input}],color:[{type:e.Input}],resizeClear:[{type:e.Input}],width:[{type:e.Input}]},t}(),n=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[o],imports:[],exports:[o]}]}],t}();t.KEYFRAME=500,t.STROKE=d,t.TAU=T,t.TWO_OVER_SQRT_2=p,t.SkyconsComponent=o,t.SkyconsTypes=i,t.SkyconsModule=n,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-skycons.umd.min.js.map