/**
 * hilojs 2.0.0 for kissy
 * Copyright 2016 alibaba.com
 * Licensed under the MIT License
 */
KISSY.add("hilo/view/Stage",function(e,t,i,n,r,s,a,o,h){var d=i.create({Extends:n,constructor:function(e){e=e||{},this.id=this.id||e.id||t.getUid("Stage"),d.superclass.constructor.call(this,e),this._initRenderer(e);var i=this.width,n=this.height,r=this.updateViewport();e.width||(i=r&&r.width||320),e.height||(n=r&&r.height||480),this.resize(i,n,!0)},canvas:null,renderer:null,paused:!1,viewport:null,_initRenderer:function(e){var i=e.canvas,n=e.container,o=e.renderType||"canvas";if("string"==typeof i&&(i=t.getElement(i)),"string"==typeof n&&(n=t.getElement(n)),i)i.getContext||(o="dom");else{var h="dom"===o?"div":"canvas";i=t.createElement(h,{style:{position:"absolute"}})}this.canvas=i,n&&n.appendChild(i);var d={canvas:i,stage:this};switch(o){case"dom":this.renderer=new s(d);break;case"webgl":a.isSupport()?this.renderer=new a(d):this.renderer=new r(d);break;case"canvas":default:this.renderer=new r(d)}},addTo:function(e){var t=this.canvas;return t.parentNode!==e&&e.appendChild(t),this},tick:function(e){this.paused||this._render(this.renderer,e)},enableDOMEvent:function(e,t){var i=this,n=i.canvas,r=i._domListener||(i._domListener=function(e){i._onDOMEvent(e)});e="string"==typeof e?[e]:e,t=t!==!1;for(var s=0;s<e.length;s++){var a=e[s];t?n.addEventListener(a,r,!1):n.removeEventListener(a,r)}return i},_onDOMEvent:function(e){var t=e.type,i=e,n=0==t.indexOf("touch"),r=e;if(n){var s=e.touches,a=e.changedTouches;r=s&&s.length?s[0]:a&&a.length?a[0]:null}var d=r.pageX||r.clientX,u=r.pageY||r.clientY,l=this.viewport||this.updateViewport();i.stageX=d=(d-l.left)/this.scaleX,i.stageY=u=(u-l.top)/this.scaleY,i.stopPropagation=function(){this._stopPropagationed=!0};var c=this.getViewAtPoint(d,u,!0,!1,!0)||this,v=this.canvas,p=this._eventTarget,g="mouseout"===t;if(p&&(p!=c&&(!p.contains||!p.contains(c))||g)){var f="touchmove"===t?"touchout":"mousemove"===t||g||!c?"mouseout":null;if(f){var w=h.copy({},i);w.type=f,w.eventTarget=p,p._fireMouseEvent(w)}i.lastEventTarget=p,this._eventTarget=null}if(c&&c.pointerEnabled&&"mouseout"!==t&&(i.eventTarget=this._eventTarget=c,c._fireMouseEvent(i)),!n){var m=c&&c.pointerEnabled&&c.useHandCursor?"pointer":"";v.style.cursor=m}o.android&&"touchmove"===t&&e.preventDefault()},updateViewport:function(){var e=this.canvas,i=null;return e.parentNode&&(i=this.viewport=t.getElementRect(e)),i},resize:function(e,t,i){(i||this.width!==e||this.height!==t)&&(this.width=e,this.height=t,this.renderer.resize(e,t),this.updateViewport())}});return d},{requires:["hilo/core/Hilo","hilo/core/Class","hilo/view/Container","hilo/renderer/CanvasRenderer","hilo/renderer/DOMRenderer","hilo/renderer/WebGLRenderer","hilo/util/browser","hilo/util/util"]});