text: /**
   * Hilo 1.0.1 for commonjs
   * Copyright 2016 alibaba.com
   * Licensed under the MIT License
   */
  var Class=require("../core/Class"),Hilo=require("../core/Hilo"),Renderer=require("./Renderer"),CanvasRenderer=Class.create({Extends:Renderer,constructor:function(e){CanvasRenderer.superclass.constructor.call(this,e),this.context=this.canvas.getContext("2d")},renderType:"canvas",context:null,startDraw:function(e){return e.visible&&e.alpha>0?(e===this.stage&&this.context.clearRect(0,0,e.width,e.height),this.context.save(),!0):!1},draw:function(e){var t=this.context,a=e.width,r=e.height,i=e.background;i&&(t.fillStyle=i,t.fillRect(0,0,a,r));var s=e.drawable,n=s&&s.image;if(n){var c=s.rect,l=c[2],h=c[3],o=c[4],d=c[5];if(!l||!h)return;a||r||(a=e.width=l,r=e.height=h),(o||d)&&t.translate(o-.5*l,d-.5*h),t.drawImage(n,c[0],c[1],l,h,0,0,a,r)}},endDraw:function(e){this.context.restore()},transform:function(e){var t=e.drawable;if(t&&t.domElement)return void Hilo.setElementStyleByView(e);var a=this.context,r=e.scaleX,i=e.scaleY;if(e===this.stage){var s=this.canvas.style,n=e._scaleX,c=e._scaleY;(!n&&1!=r||n&&n!=r)&&(e._scaleX=r,s.width=r*e.width+"px"),(!c&&1!=i||c&&c!=i)&&(e._scaleY=i,s.height=i*e.height+"px")}else{var l=e.x,h=e.y,o=e.pivotX,d=e.pivotY,v=e.rotation%360,f=e.mask;f&&(f._render(this),a.clip());var u=e.align;if(u)if("function"==typeof u)e.align();else{var g=e.parent;if(g){var w=e.width,p=e.height,b=g.width,x=g.height;switch(u){case"TL":l=0,h=0;break;case"T":l=b-w>>1,h=0;break;case"TR":l=b-w,h=0;break;case"L":l=0,h=x-p>>1;break;case"C":l=b-w>>1,h=x-p>>1;break;case"R":l=b-w,h=x-p>>1;break;case"BL":l=0,h=x-p;break;case"B":l=b-w>>1,h=x-p;break;case"BR":l=b-w,h=x-p}}}0==l&&0==h||a.translate(l,h),0!=v&&a.rotate(v*Math.PI/180),1==r&&1==i||a.scale(r,i),0==o&&0==d||a.translate(-o,-d)}e.alpha>0&&(a.globalAlpha*=e.alpha)},remove:function(e){var t=e.drawable,a=t&&t.domElement;if(a){var r=a.parentNode;r&&r.removeChild(a)}},clear:function(e,t,a,r){this.context.clearRect(e,t,a,r)},resize:function(e,t){this.canvas.width=e,this.canvas.height=t}});module.exports=CanvasRenderer;