UNPKG

@smoud/tiny

Version:

Fast and tiny JavaScript library for HTML5 game and playable ads creation.

1 lines 6.08 kB
!function(){var e={538:function(){Object.assign(Tiny.Graphics.prototype,{generateTexture:function(e,t){e=e||1;var i=this.getBounds(),a=new Tiny.CanvasBuffer(i.width*e,i.height*e),r=new Tiny.Texture(a.canvas,t);return r.base.resolution=e,a.context.scale(e,e),a.context.translate(-i.x,-i.y),Tiny.CanvasGraphics.renderGraphics(this,a.context),r},renderCanvas:function(e){if(!1!==this.visible&&0!==this.alpha&&!0!==this.isMask){if(this._cacheAsBitmap)return(this.dirty||this.cachedSpriteDirty)&&(this._generateCachedSprite(),this.updateCachedSpriteTexture(),this.cachedSpriteDirty=!1,this.dirty=!1),this._cachedSprite.alpha=this.alpha,void Tiny.Sprite.prototype.renderCanvas.call(this._cachedSprite,e);var t=e.context,i=this.worldTransform;this._prevTint!==this.tint.int&&(this.dirty=!0,this._prevTint=this.tint.int),this.blendMode!==e.currentBlendMode&&(e.currentBlendMode=this.blendMode,t.globalCompositeOperation=PIXI.blendModesCanvas[e.currentBlendMode]),this._mask&&e.maskManager.pushMask(this._mask,e);var a=e.resolution;t.setTransform(i.a*a,i.b*a,i.c*a,i.d*a,i.tx*a,i.ty*a),Tiny.CanvasGraphics.renderGraphics(this,t);for(var r=0,h=this.children.length;r<h;r++)this.children[r]._renderCanvas(e);this._mask&&e.maskManager.popMask(e)}},_generateCachedSprite:function(){var e=this.getLocalBounds();if(this._cachedSprite)this._cachedSprite.buffer.resize(e.width,e.height);else{var t=new Tiny.CanvasBuffer(e.width,e.height),i=new Tiny.Texture(t.canvas);this._cachedSprite=new Tiny.Sprite(i),this._cachedSprite.buffer=t,this._cachedSprite.worldTransform=this.worldTransform}this._cachedSprite.anchor.x=-e.x/e.width,this._cachedSprite.anchor.y=-e.y/e.height,this._cachedSprite.buffer.context.translate(-e.x,-e.y),this.worldAlpha=1,this.dirty=!0,Tiny.CanvasGraphics.renderGraphics(this,this._cachedSprite.buffer.context),this._cachedSprite.alpha=this.alpha},updateCachedSpriteTexture:function(){var e=this._cachedSprite,t=e.texture,i=e.buffer.canvas;t.base.width=i.width,t.base.height=i.height,t.crop.width=t.frame.width=i.width,t.crop.height=t.frame.height=i.height,e._width=i.width,e._height=i.height,t.base.dirty()},destroyCachedSprite:function(){this._cachedSprite.texture.destroy(!0),this._cachedSprite=null}})}},t={};function i(a){var r=t[a];if(void 0!==r)return r.exports;var h=t[a]={exports:{}};return e[a](h,h.exports,i),h.exports}!function(){"use strict";var e=function(){};e.renderGraphics=function(e,t){var i=e.worldAlpha;e.dirty&&(this.updateGraphicsTint(e),e.dirty=!1);for(var a=0;a<e.graphicsData.length;a++){var r=e.graphicsData[a],h=r.shape,n=r._fillTint,l=r._lineTint;if(t.lineWidth=r.lineWidth,r.type===Tiny.POLY){t.beginPath();var o=h.points;t.moveTo(o[0],o[1]);for(var s=1;s<o.length/2;s++)t.lineTo(o[2*s],o[2*s+1]);h.closed&&t.lineTo(o[0],o[1]),o[0]===o[o.length-2]&&o[1]===o[o.length-1]&&t.closePath(),r.fill&&(t.globalAlpha=n.a*i,t.fillStyle=n.toStyle(),t.fill()),r.lineWidth&&(t.globalAlpha=l.a*i,t.strokeStyle=l.toStyle(),t.stroke())}else if(r.type===Tiny.RECT)r.fillColor&&(t.globalAlpha=n.a*i,t.fillStyle=n.toStyle(),t.fillRect(h.x,h.y,h.width,h.height)),r.lineWidth&&(t.globalAlpha=l.a*i,t.strokeStyle=l.toStyle(),t.strokeRect(h.x,h.y,h.width,h.height));else if(r.type===Tiny.CIRC)t.beginPath(),t.arc(h.x,h.y,h.radius,0,2*Math.PI),t.closePath(),r.fill&&(t.globalAlpha=n.a*i,t.fillStyle=n.toStyle(),t.fill()),r.lineWidth&&(t.globalAlpha=l.a*i,t.strokeStyle=l.toStyle(),t.stroke());else if(r.type===Tiny.ELIP){var c=2*h.width,p=2*h.height,d=h.x-c/2,y=h.y-p/2;t.beginPath();var u=.5522848,T=c/2*u,f=p/2*u,v=d+c,g=y+p,C=d+c/2,S=y+p/2;t.moveTo(d,S),t.bezierCurveTo(d,S-f,C-T,y,C,y),t.bezierCurveTo(C+T,y,v,S-f,v,S),t.bezierCurveTo(v,S+f,C+T,g,C,g),t.bezierCurveTo(C-T,g,d,S+f,d,S),t.closePath(),r.fill&&(t.globalAlpha=n.a*i,t.fillStyle=n.toStyle(),t.fill()),r.lineWidth&&(t.globalAlpha=l.a*i,t.strokeStyle=l.toStyle(),t.stroke())}else if(r.type===Tiny.RREC){var b=h.x,x=h.y,w=h.width,_=h.height,m=h.radius,k=Math.min(w,_)/2|0;m=m>k?k:m,t.beginPath(),t.moveTo(b,x+m),t.lineTo(b,x+_-m),t.quadraticCurveTo(b,x+_,b+m,x+_),t.lineTo(b+w-m,x+_),t.quadraticCurveTo(b+w,x+_,b+w,x+_-m),t.lineTo(b+w,x+m),t.quadraticCurveTo(b+w,x,b+w-m,x),t.lineTo(b+m,x),t.quadraticCurveTo(b,x,b,x+m),t.closePath(),r.fillColor&&(t.globalAlpha=n.a*i,t.fillStyle=n.toStyle(),t.fill()),r.lineWidth&&(t.globalAlpha=l.a*i,t.strokeStyle=l.toStyle(),t.stroke())}}},e.renderGraphicsMask=function(e,t){var i=e.graphicsData.length;if(0!==i){t.beginPath();for(var a=0;a<i;a++){var r=e.graphicsData[a],h=r.shape;if(r.type===Tiny.POLY){var n=h.points;t.moveTo(n[0],n[1]);for(var l=1;l<n.length/2;l++)t.lineTo(n[2*l],n[2*l+1]);n[0]===n[n.length-2]&&n[1]===n[n.length-1]&&t.closePath()}else if(r.type===Tiny.RECT)t.rect(h.x,h.y,h.width,h.height),t.closePath();else if(r.type===Tiny.CIRC)t.arc(h.x,h.y,h.radius,0,2*Math.PI),t.closePath();else if(r.type===Tiny.ELIP){var o=2*h.width,s=2*h.height,c=h.x-o/2,p=h.y-s/2,d=.5522848,y=o/2*d,u=s/2*d,T=c+o,f=p+s,v=c+o/2,g=p+s/2;t.moveTo(c,g),t.bezierCurveTo(c,g-u,v-y,p,v,p),t.bezierCurveTo(v+y,p,T,g-u,T,g),t.bezierCurveTo(T,g+u,v+y,f,v,f),t.bezierCurveTo(v-y,f,c,g+u,c,g),t.closePath()}else if(r.type===Tiny.RREC){var C=h.x,S=h.y,b=h.width,x=h.height,w=h.radius,_=Math.min(b,x)/2|0;w=w>_?_:w,t.moveTo(C,S+w),t.lineTo(C,S+x-w),t.quadraticCurveTo(C,S+x,C+w,S+x),t.lineTo(C+b-w,S+x),t.quadraticCurveTo(C+b,S+x,C+b,S+x-w),t.lineTo(C+b,S+w),t.quadraticCurveTo(C+b,S,C+b-w,S),t.lineTo(C+w,S),t.quadraticCurveTo(C,S,C,S+w),t.closePath()}}}},e.updateGraphicsTint=function(e){if(16777215!==e.tint.int)for(var t=0;t<e.graphicsData.length;t++){var i=e.graphicsData[t];i._fillTint=new Tiny.Color(i.fillColor).multiply(e.tint),i._lineTint=new Tiny.Color(i.lineColor).multiply(e.tint)}};var t=function(){};t.prototype.constructor=t,t.prototype.pushMask=function(e,t){var i=t.context;i.save();var a=e.alpha,r=e.worldTransform,h=t.resolution;i.setTransform(r.a*h,r.b*h,r.c*h,r.d*h,r.tx*h,r.ty*h),Tiny.CanvasGraphics.renderGraphicsMask(e,i),i.clip(),e.worldAlpha=a},t.prototype.popMask=function(e){e.context.restore()};i(538);Tiny.CanvasGraphics=e,Tiny.CanvasMaskManager=t}()}();