@smoud/tiny
Version:
Fast and tiny JavaScript library for HTML5 game and playable ads creation.
1 lines • 8.49 kB
JavaScript
!function(){var t={178:function(){Tiny.Object2D.prototype.renderCanvas=function(t){if(!1!==this.visible&&0!==this.alpha)if(this._cacheAsBitmap)this._renderCachedSprite(t);else{this._mask&&t.maskManager.pushMask(this._mask,t);for(var e=0,i=this.children.length;e<i;e++)this.children[e].renderCanvas(t);this._mask&&t.maskManager.popMask(t)}},Tiny.Sprite.prototype.renderCanvas=function(t){if(!(!1===this.visible||0===this.alpha||!1===this.renderable||this.texture.crop.width<=0||this.texture.crop.height<=0)){if(this.blendMode!==t.currentBlendMode&&(t.currentBlendMode=this.blendMode,t.context.globalCompositeOperation=t.blendModes[t.currentBlendMode]),this._mask&&t.maskManager.pushMask(this._mask,t),this.texture.valid){var e=this.texture.base.resolution/t.resolution;t.context.globalAlpha=this.worldAlpha;var i=this.texture.trim?this.texture.trim.x-this.anchor.x*this.texture.trim.width:this.anchor.x*-this.texture.frame.width,r=this.texture.trim?this.texture.trim.y-this.anchor.y*this.texture.trim.height:this.anchor.y*-this.texture.frame.height;t.roundPixels?(t.context.setTransform(this.worldTransform.a,this.worldTransform.b,this.worldTransform.c,this.worldTransform.d,this.worldTransform.tx*t.resolution|0,this.worldTransform.ty*t.resolution|0),i|=0,r|=0):t.context.setTransform(this.worldTransform.a,this.worldTransform.b,this.worldTransform.c,this.worldTransform.d,this.worldTransform.tx*t.resolution,this.worldTransform.ty*t.resolution),16777215!==this.tint.int?(this.cachedTint!==this.tint.int&&(this.cachedTint=this.tint.int,this.tintedTexture=Tiny.CanvasTinter.getTintedTexture(this,this.tint)),t.context.drawImage(this.tintedTexture,0,0,this.texture.crop.width,this.texture.crop.height,i/e,r/e,this.texture.crop.width/e,this.texture.crop.height/e)):t.context.drawImage(this.texture.base.source,this.texture.crop.x,this.texture.crop.y,this.texture.crop.width,this.texture.crop.height,i/e,r/e,this.texture.crop.width/e,this.texture.crop.height/e)}for(var o=0;o<this.children.length;o++)this.children[o].renderCanvas(t);this._mask&&t.maskManager.popMask(t)}},Tiny.Text.prototype.renderCanvas=function(t){(this.dirty||this.resolution!==t.resolution)&&(this.resolution=t.resolution,this.updateText(),this.dirty=!1),Tiny.Sprite.prototype.renderCanvas.call(this,t)},Tiny.RenderTexture.prototype.renderCanvas=function(t,e,i){if(this.valid){var r=t.worldTransform;r.identity(),e&&r.append(e),t.worldAlpha=1;for(var o=t.children,n=0,s=o.length;n<s;n++)o[n].updateTransform();r.identity(),i&&this.textureBuffer.clear();var a=this.textureBuffer.context,h=this.renderer.resolution;this.renderer.resolution=this.base.resolution,this.renderer.renderObject(t,a),this.renderer.resolution=h}}}},e={};function i(r){var o=e[r];if(void 0!==o)return o.exports;var n=e[r]={exports:{}};return t[r](n,n.exports,i),n.exports}!function(){"use strict";function t(t){var e=document.createElement('canvas');e.width=6,e.height=1;var i=e.getContext('2d');return i.fillStyle=t,i.fillRect(0,0,6,1),e}var e;function r(){if(void 0!==e)return e;var i=t('#ff00ff'),r=t('#ffff00'),o=document.createElement('canvas');o.width=6,o.height=1;var n=o.getContext('2d');n.globalCompositeOperation='multiply',n.drawImage(i,0,0),n.drawImage(r,2,0);var s=n.getImageData(2,0,1,1);if(s){var a=s.data;e=255===a[0]&&0===a[1]&&0===a[2]}else e=!1;return e}var o=function(t,e,i){i=i||{},this.resolution=null!=i.resolution?i.resolution:1,this._resolution=this.resolution,this.clearBeforeRender=null==i.clearBeforeRender||i.clearBeforeRender,this.transparent=null!=i.transparent&&i.transparent,this.autoResize=i.autoResize||!1,Tiny.defaultRenderer||(Tiny.defaultRenderer=this);var o=this.domElement=i.domElement||document.createElement('canvas');this.context=o.getContext('2d',{alpha:this.transparent}),this._context=this.context,this.resize(t||800,e||600),this.setClearColor(16777215),Tiny.CanvasMaskManager&&(this.maskManager=new Tiny.CanvasMaskManager),this.roundPixels=!1,'imageSmoothingEnabled'in this.context?this.smoothProperty='imageSmoothingEnabled':'webkitImageSmoothingEnabled'in this.context?this.smoothProperty='webkitImageSmoothingEnabled':'mozImageSmoothingEnabled'in this.context?this.smoothProperty='mozImageSmoothingEnabled':'oImageSmoothingEnabled'in this.context?this.smoothProperty='oImageSmoothingEnabled':'msImageSmoothingEnabled'in this.context&&(this.smoothProperty='msImageSmoothingEnabled');var n=[],s=Tiny;n[s.NORMAL]='source-over',n[s.ADD]='lighter';var a=r();n[s.MULTIPLY]=a?'multiply':'source-over',n[s.SCREEN]=a?'screen':'source-over',n[s.OVERLAY]=a?'overlay':'source-over',n[s.DARKEN]=a?'darken':'source-over',n[s.LIGHTEN]=a?'lighten':'source-over',n[s.COLOR_DODGE]=a?'color-dodge':'source-over',n[s.COLOR_BURN]=a?'color-burn':'source-over',n[s.HARD_LIGHT]=a?'hard-light':'source-over',n[s.SOFT_LIGHT]=a?'soft-light':'source-over',n[s.DIFFERENCE]=a?'difference':'source-over',n[s.EXCLUSION]=a?'exclusion':'source-over',n[s.HUE]=a?'hue':'source-over',n[s.SATURATION]=a?'saturation':'source-over',n[s.COLOR]=a?'color':'source-over',n[s.LUMINOSITY]=a?'luminosity':'source-over',this.blendModes=n};o.prototype.constructor=o,o.prototype.setClearColor=function(t){this.clearColor=new Tiny.Color(t).toStyle()},o.prototype.render=function(t){t.updateTransform(),this._context.setTransform(1,0,0,1,0,0),this._context.globalAlpha=1,this.currentBlendMode=Tiny.NORMAL,this._context.globalCompositeOperation=this.blendModes[Tiny.NORMAL],navigator.isCocoonJS&&this.domElement.screencanvas&&(this._context.fillStyle='black',this._context.clear()),this.clearBeforeRender&&(this.transparent?this._context.clearRect(0,0,this.width*this._resolution,this.height*this._resolution):(this._context.fillStyle=this.clearColor,this._context.fillRect(0,0,this.width*this._resolution,this.height*this._resolution))),this.renderObject(t)},o.prototype.destroy=function(t){void 0===t&&(t=!0),t&&this.domElement.parentNode&&this.domElement.parentNode.removeChild(this.domElement),this.domElement=null,this.context=null,this.maskManager=null,Tiny.defaultRenderer===this&&(Tiny.defaultRenderer=null)},o.prototype.resize=function(t,e){this.width=t,this.height=e;var i=this.domElement;i.width=Math.floor(this.width*this._resolution),i.height=Math.floor(this.height*this._resolution),this.autoResize&&(i.style.width=t+'px',i.style.height=e+'px')},o.prototype.setPixelRatio=function(t){this._resolution=this.resolution=t;var e=this.domElement;e.width=Math.floor(this.width*this._resolution),e.height=Math.floor(this.height*this._resolution)},o.prototype.renderObject=function(t,e,i){this.context=e||this._context,t.renderCanvas(this)};var n=function(){var t=new Tiny.CanvasBuffer(2,1,{willReadFrequently:!0});t.context.fillStyle='rgba(10, 20, 30, 0.5)',t.context.fillRect(0,0,1,1);var e=t.context.getImageData(0,0,1,1);t.context.putImageData(e,1,0);var i=t.context.getImageData(1,0,1,1);return i.data[0]===e.data[0]&&i.data[1]===e.data[1]&&i.data[2]===e.data[2]&&i.data[3]===e.data[3]}(),s=function(){};s.getTintedTexture=function(t,e){var i=e.int,r=t.texture;if(r._tintCache||(r._tintCache={}),r._tintCache[i])return r._tintCache[i];var o=s.canvas||document.createElement('canvas');(s.tintMethod(r,e,o),s.convertTintToImage)?(new Image).src=o.toDataURL():s.canvas=null;return s.cacheTint&&(r._tintCache[i]=o),o},s.tintWithMultiply=function(t,e,i){var r=i.getContext('2d'),o=t.crop;i.width=o.width,i.height=o.height,r.fillStyle=e.toStyle(),r.fillRect(0,0,o.width,o.height),r.globalCompositeOperation='multiply',r.drawImage(t.base.source,o.x,o.y,o.width,o.height,0,0,o.width,o.height),r.globalCompositeOperation='destination-atop',r.drawImage(t.base.source,o.x,o.y,o.width,o.height,0,0,o.width,o.height)},s.tintWithPerPixel=function(t,e,i){var r=i.getContext('2d'),o=t.crop;i.width=o.width,i.height=o.height,r.globalCompositeOperation='copy',r.drawImage(t.base.source,o.x,o.y,o.width,o.height,0,0,o.width,o.height);for(var s=r.getImageData(0,0,o.width,o.height),a=s.data,h=0;h<a.length;h+=4)if(a[h+0]*=e.r,a[h+1]*=e.g,a[h+2]*=e.b,!n){var l=a[h+3];a[h+0]/=255/l,a[h+1]/=255/l,a[h+2]/=255/l}r.putImageData(s,0,0)},s.convertTintToImage=!1,s.cacheTint=!0,s.tintMethod=r()?s.tintWithMultiply:s.tintWithPerPixel;i(178);Tiny.CanvasRenderer=o,Tiny.CanvasTinter=s,Tiny.autoDetectRenderer=function(t,e,i){return function(){try{var t=document.createElement('canvas');return!!window.WebGLRenderingContext&&(t.getContext('webgl')||t.getContext('experimental-webgl'))}catch(t){return!1}}()?new Tiny.Renderer(t,e,i):new Tiny.CanvasRenderer(t,e,i)}}()}();