UNPKG

playable.js

Version:

A lightweight HTML5 game engine.

1 lines 83.6 kB
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).playable={})}(this,function(exports){"use strict";var extendStatics=function(d,b){return(extendStatics=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(d,b){d.__proto__=b}:function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])}))(d,b)};function __extends(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){return(__assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++)for(var p in s=arguments[i])Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p]);return t}).apply(this,arguments)},Event=function(){function Event(type,data){void 0===data&&(data=null),this.type=null,this.data=null,this.target=null,this.currentTarget=null,this.$init(type,data)}return Event.prototype.$init=function(type,data){return void 0===data&&(data=null),this.type=type,this.data=data,this},Event.prototype.release=function(){this.type=null,this.data=null,Event.recycle(this)},Event.create=function(type,data){void 0===data&&(data=null);var pool=this.$pool;return 0<pool.length?pool.pop().$init(type,data):new Event(type,data)},Event.recycle=function(e){this.$pool.push(e)},Event.ADDED="added",Event.REMOVED="removed",Event.ADDED_TO_STAGE="addedToStage",Event.REMOVED_FROM_STAGE="removeFromStage",Event.ACTIVATE="activate",Event.DEACTIVATE="deactivate",Event.ENTER_FRAME="enterFrame",Event.TICK="tick",Event.TICKER_PAUSE="tickerPause",Event.TICKER_RESUME="tickerResume",Event.VIEWPORT_RESIZE="viewportResize",Event.LOAD="load",Event.ABORT="abort",Event.ERROR="error",Event.PROGRESS="progress",Event.COMPLETE="complete",Event.ENDED="ended",Event.SOUND_COMPLETE="soundComplete",Event.$pool=[],Event}(),Event$1=Object.freeze({__proto__:null,Event:Event}),EventEmitter=function(){function EventEmitter(){this.$events={},this.$emittingType=null,this.$removedListeners=[]}return EventEmitter.prototype.on=function(type,listener){var listeners=this.$events[type]||[];return listeners.push(listener),this.$events[type]=listeners,this},EventEmitter.prototype.off=function(type,listener){return this.$emittingType===type&&listener?this.$removedListeners.push(listener):(type=this.$events[type]||[],listener?0<=(listener=type.indexOf(listener))&&type.splice(listener,1):type.length=0),this},EventEmitter.prototype.once=function(type,listener){function wrapper(){listener.apply(this,arguments),that.off(type,wrapper)}var that=this;return this.on(type,wrapper)},EventEmitter.prototype.emit=function(type){for(var event,args=[],_i=1;_i<arguments.length;_i++)args[_i-1]=arguments[_i];type instanceof Event&&(args=[type],type.target=type.target||this,type.currentTarget=this,type=type.type);var listeners=this.$events[type],hasListeners=listeners&&0<listeners.length,removedListeners=this.$removedListeners;if(!event&&hasListeners&&0===args.length&&((event=Event.create(type)).target=this,event.currentTarget=this,args.push(event)),hasListeners){this.$emittingType=type;for(var _a=0,listeners_1=listeners;_a<listeners_1.length;_a++){var listener=listeners_1[_a];removedListeners.indexOf(listener)<0&&listener.apply(this,args)}this.$emittingType=null}event&&event.release();for(var _b=0,removedListeners_1=removedListeners;_b<removedListeners_1.length;_b++){listener=removedListeners_1[_b];this.off(type,listener)}return removedListeners.length=0,hasListeners},EventEmitter.prototype.hasEventListener=function(type){type=this.$events[type];return!!type&&0<type.length},EventEmitter.prototype.removeAllListeners=function(){return this.$events={},this},EventEmitter}(),EventEmitter$1=Object.freeze({__proto__:null,EventEmitter:EventEmitter}),Ticker=function(_super){function Ticker(stage){var _this=_super.call(this)||this;return _this.$stage=null,_this.$fps=0,_this.$deltaTime=0,_this.$paused=!0,_this.$shouldResume=!1,_this.$timerIndex=0,_this.$lastTimestamp=0,_this.$tickHandle=null,_this.$stage=stage,_this.$timers=[],_this.$boundTick=_this.$tick.bind(_this),_this.$enterFrameCallbackList=[stage],_this.$start(),_this}return __extends(Ticker,_super),Object.defineProperty(Ticker.prototype,"fps",{get:function(){return this.$fps},enumerable:!1,configurable:!0}),Object.defineProperty(Ticker.prototype,"deltaTime",{get:function(){return this.$deltaTime},enumerable:!1,configurable:!0}),Object.defineProperty(Ticker.prototype,"paused",{get:function(){return this.$paused},enumerable:!1,configurable:!0}),Ticker.prototype.$start=function(){for(var _this=this,stage=this.$stage,_i=0,prefixes_1=["","o","ms","moz","webkit"];_i<prefixes_1.length;_i++){var prefix=prefixes_1[_i],cancelKey=prefix?prefix+"CancelAnimationFrame":"cancelAnimationFrame",cancelRequestKey=prefix?prefix+"CancelRequestAnimationFrame":"cancelRequestAnimationFrame";window.requestAnimationFrame=window.requestAnimationFrame||window[prefix?prefix+"RequestAnimationFrame":"requestAnimationFrame"],window.cancelAnimationFrame=window.cancelAnimationFrame||window[cancelKey]||window[cancelRequestKey]}return window.requestAnimationFrame||(window.requestAnimationFrame=function(callback){return window.setTimeout(callback,1e3/60)},window.cancelAnimationFrame=function(handle){window.clearTimeout(handle)}),stage.on(Event.ACTIVATE,function(){_this.$shouldResume&&(_this.resume(),_this.$shouldResume=!1)}),stage.on(Event.DEACTIVATE,function(){_this.$paused||(_this.pause(),_this.$shouldResume=!0)}),stage.activated?(this.$paused=!1,this.$tick()):this.$shouldResume=!0,this},Ticker.prototype.pause=function(){return this.$paused||(this.$paused=!0,this.$lastTimestamp=0,this.emit(Event.TICKER_PAUSE),cancelAnimationFrame(this.$tickHandle)),this},Ticker.prototype.resume=function(){return this.$paused&&(this.$paused=!1,this.$tick(),this.emit(Event.TICKER_RESUME)),this},Ticker.prototype.setTimeout=function(handler,timeout){void 0===timeout&&(timeout=0);var handle=++this.$timerIndex;return this.$timers[handle]={handler:handler,timeout:timeout,resetTime:timeout},handle},Ticker.prototype.clearTimeout=function(handle){delete this.$timers[handle]},Ticker.prototype.setInterval=function(handler,timeout){var handle=++this.$timerIndex;return this.$timers[handle]={handler:handler,timeout:timeout,resetTime:timeout,interval:!0},handle},Ticker.prototype.clearInterval=function(handle){delete this.$timers[handle]},Ticker.prototype.registerEnterFrameCallback=function(layer){var list=this.$enterFrameCallbackList;return list.indexOf(layer)<0&&list.push(layer),this},Ticker.prototype.unregisterEnterFrameCallback=function(layer){var list=this.$enterFrameCallbackList,layer=list.indexOf(layer);return 0<=layer&&list.splice(layer,1),this},Ticker.prototype.$tick=function(){for(var now=Date.now(),deltaTime=this.$lastTimestamp?now-this.$lastTimestamp:1e3/60,enterFrameCallbackList=this.$enterFrameCallbackList,event=(this.$fps=Math.round(1e3/deltaTime),this.$deltaTime=deltaTime,this.$lastTimestamp=now,this.$tickHandle=window.requestAnimationFrame(this.$boundTick),this.$checkTimers(deltaTime),Event.create(Event.ENTER_FRAME,deltaTime)),_i=0,enterFrameCallbackList_1=enterFrameCallbackList;_i<enterFrameCallbackList_1.length;_i++)enterFrameCallbackList_1[_i].emit(event);event.release();now=Event.create(Event.TICK,deltaTime);this.emit(now),now.release()},Ticker.prototype.$checkTimers=function(dt){var key,timers=this.$timers;for(key in timers){var timer=timers[key];(timer.resetTime=timer.resetTime-dt)<=0&&(timer.handler(),timer.interval?timer.resetTime+=timer.timeout:this.clearTimeout(+key))}},Ticker}(EventEmitter),Ticker$1=Object.freeze({__proto__:null,Ticker:Ticker}),Vector=function(){function Vector(x,y){this.set(x,y)}return Object.defineProperty(Vector.prototype,"length",{get:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},enumerable:!1,configurable:!0}),Object.defineProperty(Vector.prototype,"angle",{get:function(){return Math.atan2(this.y,this.x)},enumerable:!1,configurable:!0}),Vector.prototype.set=function(x,y){return this.x=x||0,this.y=y||0,this},Vector.prototype.add=function(x,y){return x instanceof Vector?(this.x+=x.x,this.y+=x.y):(this.x+=x,this.y+=y),this},Vector.prototype.subtract=function(x,y){return x instanceof Vector?(this.x-=x.x,this.y-=x.y):(this.x-=x,this.y-=y),this},Vector.prototype.dotProduct=function(x,y){return x instanceof Vector?this.x*x.x+this.y*x.y:this.x*x+this.y*y},Vector.prototype.normalize=function(){var length=this.length;return this.x=this.x/length,this.y=this.y/length,this},Vector.prototype.negate=function(){return this.x*=-1,this.y*=-1,this},Vector.prototype.scale=function(x,y){return this.x*=x,this.y*=void 0===y?x:y,this},Vector.prototype.rotate=function(angle){var x=this.x,y=this.y;return this.x=x*Math.cos(angle)-y*Math.sin(angle),this.y=x*Math.sin(angle)+y*Math.cos(angle),this},Vector.prototype.transform=function(m){var x=this.x,y=this.y;return this.x=m.a*x+m.c*y+m.tx,this.y=m.b*x+m.d*y+m.ty,this},Vector.prototype.distance=function(v){return Math.sqrt((this.x-v.x)*(this.x-v.x)+(this.y-v.y)*(this.y-v.y))},Vector.prototype.equal=function(v){return this.x===v.x&&this.y===v.y},Vector.prototype.release=function(){return Vector.recycle(this),this},Vector.create=function(x,y){var pool=this.$pool;return 0<pool.length?pool.pop().set(x,y):new Vector(x,y)},Vector.recycle=function(v){this.$pool.push(v)},Vector.$pool=[],Vector}(),Vector$1=Object.freeze({__proto__:null,Vector:Vector}),Matrix=function(){function Matrix(a,b,c,d,tx,ty){0<arguments.length?this.set(a,b,c,d,tx,ty):this.identity()}return Matrix.prototype.set=function(a,b,c,d,tx,ty){return this.a=a,this.b=b,this.c=c,this.d=d,this.tx=tx,this.ty=ty,this},Matrix.prototype.identity=function(){return this.set(1,0,0,1,0,0)},Matrix.prototype.invert=function(){var a=this.a,b=this.b,c=this.c,d=this.d,tx=this.tx,ty=this.ty,n=a*d-c*b;return this.a=d/n,this.b=-b/n,this.c=-c/n,this.d=a/n,this.tx=(c*ty-d*tx)/n,this.ty=(b*tx-a*ty)/n,this},Matrix.prototype.prepend=function(a,b,c,d,tx,ty){var a1,b1,c1,d1,tx1,ty1;return a instanceof Matrix?this.prepend(a.a,a.b,a.c,a.d,a.tx,a.ty):(a1=this.a,b1=this.b,c1=this.c,d1=this.d,tx1=this.tx,ty1=this.ty,this.a=a*a1+b*c1,this.b=a*b1+b*d1,this.c=c*a1+d*c1,this.d=c*b1+d*d1,this.tx=tx*a1+ty*c1+tx1,this.ty=tx*b1+ty*d1+ty1,this)},Matrix.prototype.append=function(a,b,c,d,tx,ty){var a1,b1,c1,d1,tx1,ty1;return a instanceof Matrix?this.append(a.a,a.b,a.c,a.d,a.tx,a.ty):(a1=this.a,b1=this.b,c1=this.c,d1=this.d,tx1=this.tx,ty1=this.ty,this.a=a*a1+c*b1,this.b=b*a1+d*b1,this.c=a*c1+c*d1,this.d=b*c1+d*d1,this.tx=a*tx1+c*ty1+tx,this.ty=b*tx1+d*ty1+ty,this)},Matrix.prototype.scale=function(x,y){return this.append(x,0,0,void 0===y?x:y,0,0)},Matrix.prototype.rotate=function(angle){var sin=Math.sin(angle),angle=Math.cos(angle);return this.append(angle,sin,-sin,angle,0,0)},Matrix.prototype.skew=function(skewX,skewY){return this.append(1,Math.tan(skewY),Math.tan(skewX),1,0,0)},Matrix.prototype.translate=function(x,y){return x instanceof Vector?this.append(1,0,0,1,x.x,x.y):this.append(1,0,0,1,x,y)},Matrix.prototype.equal=function(m){return m instanceof Matrix&&this.a===m.a&&this.b===m.b&&this.c===m.c&&this.d===m.d&&this.tx===m.tx&&this.ty===m.ty},Matrix.prototype.release=function(){Matrix.recycle(this)},Matrix.create=function(a,b,c,d,tx,ty){var pool=this.$pool,pool=0<pool.length?pool.pop():new Matrix;return arguments.length?pool.set(a,b,c,d,tx,ty):pool.identity(),pool},Matrix.recycle=function(m){this.$pool.push(m)},Matrix.$pool=[],Matrix}(),Matrix$1=Object.freeze({__proto__:null,Matrix:Matrix}),Rectangle=function(){function Rectangle(x,y,width,height){this.set(x,y,width,height)}return Object.defineProperty(Rectangle.prototype,"top",{get:function(){return this.y},set:function(top){this.height+=this.y-top,this.y=top},enumerable:!1,configurable:!0}),Object.defineProperty(Rectangle.prototype,"bottom",{get:function(){return this.y+this.height},set:function(bottom){this.height=bottom-this.y},enumerable:!1,configurable:!0}),Object.defineProperty(Rectangle.prototype,"left",{get:function(){return this.x},set:function(left){this.width+=this.x-left,this.x=left},enumerable:!1,configurable:!0}),Object.defineProperty(Rectangle.prototype,"right",{get:function(){return this.x+this.width},set:function(right){this.width=right-this.x},enumerable:!1,configurable:!0}),Object.defineProperty(Rectangle.prototype,"topLeft",{get:function(){return Vector.create(this.left,this.top)},set:function(v){this.top=v.y,this.left=v.x},enumerable:!1,configurable:!0}),Object.defineProperty(Rectangle.prototype,"bottomRight",{get:function(){return Vector.create(this.right,this.bottom)},set:function(v){this.bottom=v.y,this.right=v.x},enumerable:!1,configurable:!0}),Rectangle.prototype.set=function(x,y,width,height){return this.x=x||0,this.y=y||0,this.width=width||0,this.height=height||0,this},Rectangle.prototype.contains=function(x,y){return x instanceof Vector?this.contains(x.x,x.y):x>=this.x&&x<=this.x+this.width&&y>=this.y&&y<=this.y+this.height},Rectangle.prototype.equal=function(r){return r instanceof Rectangle&&r.x===this.x&&r.y===this.y&&r.width===this.width&&r.height===this.height},Rectangle.prototype.release=function(){Rectangle.recycle(this)},Rectangle.create=function(x,y,width,height){var pool=this.$pool;return 0<pool.length?pool.pop().set(x,y,width,height):new Rectangle(x,y,width,height)},Rectangle.recycle=function(r){this.$pool.push(r)},Rectangle.$pool=[],Rectangle}(),Rectangle$1=Object.freeze({__proto__:null,Rectangle:Rectangle}),TouchEvent=function(_super){function TouchEvent(type){var _this=_super.call(this,type)||this;return _this.$init(type),_this}return __extends(TouchEvent,_super),TouchEvent.prototype.$init=function(type){return this.type=type,this.targetX=0,this.targetY=0,this.localX=0,this.localY=0,this.stageX=0,this.stageY=0,this.identifier=0,this.target=null,this.currentTarget=null,this.cancelBubble=!1,this},TouchEvent.prototype.stopPropagation=function(){this.cancelBubble=!0},TouchEvent.prototype.release=function(){TouchEvent.recycle(this)},TouchEvent.create=function(type){var pool=this.$pool;return 0<pool.length?pool.pop().$init(type):new TouchEvent(type)},TouchEvent.recycle=function(e){this.$pool.push(e)},TouchEvent.TOUCH_START="touchStart",TouchEvent.TOUCH_MOVE="touchMove",TouchEvent.TOUCH_END="touchEnd",TouchEvent.TOUCH_CANCEL="touchCancel",TouchEvent.TOUCH_TAP="touchTap",TouchEvent.$pool=[],TouchEvent}(Event),TouchEvent$1=Object.freeze({__proto__:null,TouchEvent:TouchEvent}),Layer=function(_super){function Layer(){var _this=_super.call(this)||this;return _this.name="",_this.tag="",_this.touchable=!0,_this.$x=0,_this.$y=0,_this.$width=0,_this.$height=0,_this.$anchorX=0,_this.$anchorY=0,_this.$skewX=0,_this.$skewY=0,_this.$scaleX=1,_this.$scaleY=1,_this.$rotation=0,_this.$alpha=1,_this.$visible=!0,_this.$smoothing=!0,_this.$background=null,_this.$stage=null,_this.$parent=null,_this.$children=[],_this.$dirty=!0,_this.$shouldEmitTap=!0,_this.$touches=[],_this.$canvas=document.createElement("canvas"),_this.$context=_this.$canvas.getContext("2d"),_this}return __extends(Layer,_super),Object.defineProperty(Layer.prototype,"x",{get:function(){return this.$x},set:function(x){this.$x!==x&&(this.$x=x,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"y",{get:function(){return this.$y},set:function(y){this.$y!==y&&(this.$y=y,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"width",{get:function(){return this.$width||this.$canvas.width/Layer.pixelRatio},set:function(width){this.$width!==width&&(this.$width=width,this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"height",{get:function(){return this.$height||this.$canvas.height/Layer.pixelRatio},set:function(height){this.$height!==height&&(this.$height=height,this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"anchorX",{get:function(){return this.$anchorX},set:function(anchorX){this.$anchorX!==anchorX&&(this.$anchorX=anchorX,this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"anchorY",{get:function(){return this.$anchorY},set:function(anchorY){this.$anchorY!==anchorY&&(this.$anchorY=anchorY,this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"skewX",{get:function(){return this.$skewX},set:function(skewX){this.$skewX!==skewX&&(this.$skewX=skewX,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"skewY",{get:function(){return this.$skewY},set:function(skewY){this.$skewY!==skewY&&(this.$skewY=skewY,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"scaleX",{get:function(){return this.$scaleX},set:function(scaleX){this.$scaleX!==scaleX&&(this.$scaleX=scaleX,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"scaleY",{get:function(){return this.$scaleY},set:function(scaleY){this.$scaleY!==scaleY&&(this.$scaleY=scaleY,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"rotation",{get:function(){return this.$rotation},set:function(rotation){this.$rotation!==rotation&&(this.$rotation=rotation,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"alpha",{get:function(){return this.$alpha},set:function(alpha){this.$alpha!==alpha&&(this.$alpha=alpha,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"visible",{get:function(){return this.$visible},set:function(visible){this.$visible!==visible&&(this.$visible=visible,this.$markParentDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"smoothing",{get:function(){return this.$smoothing},set:function(smoothing){this.$smoothing=smoothing,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"background",{get:function(){return this.$background},set:function(background){this.$background!==background&&(this.$background=background,this.$markDirty())},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"stage",{get:function(){return this.$stage},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"parent",{get:function(){return this.$parent},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"numChildren",{get:function(){return this.$children.length},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"ticker",{get:function(){return this.$stage?this.$stage.ticker:null},enumerable:!1,configurable:!0}),Object.defineProperty(Layer.prototype,"canvas",{get:function(){return this.$canvas},enumerable:!1,configurable:!0}),Layer.prototype.addChild=function(child){return this.addChildAt(child,this.$children.length)},Layer.prototype.addChildAt=function(child,index){var children=this.$children;return child.$parent&&child.$parent.removeChild(child),(index<0||index>children.length)&&(index=children.length),child.$emitAdded(this),children.splice(index,0,child),this.$resizeCanvas(),this},Layer.prototype.replaceChild=function(oldChild,newChild){oldChild=this.getChildIndex(oldChild);return this.removeChildAt(oldChild),this.addChildAt(newChild,oldChild),this},Layer.prototype.getChildByName=function(name){for(var _i=0,children_1=this.$children;_i<children_1.length;_i++){var child=children_1[_i];if(child.name===name)return child}return null},Layer.prototype.getChildrenByTag=function(tag){for(var result=[],_i=0,children_2=this.$children;_i<children_2.length;_i++){var child=children_2[_i];child.tag===tag&&result.push(child)}return result},Layer.prototype.getChildAt=function(index){return this.$children[index]||null},Layer.prototype.getChildIndex=function(child){return this.$children.indexOf(child)},Layer.prototype.hasChild=function(child){return 0<=this.getChildIndex(child)},Layer.prototype.swapChildren=function(child1,child2){child1=this.getChildIndex(child1),child2=this.getChildIndex(child2);return 0<=child1&&0<=child2&&this.swapChildrenAt(child1,child2),this},Layer.prototype.swapChildrenAt=function(index1,index2){var child1=this.$children[index1],child2=this.$children[index2];return index1!==index2&&child1&&child2&&(this.$children[index1]=child2,this.$children[index2]=child1,this.$markDirty()),this},Layer.prototype.setChildIndex=function(child,index){var children=this.$children,oldIndex=this.getChildIndex(child);if(index<0?index=0:index>children.length&&(index=children.length),0<=oldIndex&&oldIndex<index){for(var i=oldIndex+1;i<=index;++i)children[i-1]=children[i];children[index]=child,this.$markDirty()}else if(0<=oldIndex&&index<oldIndex){for(i=oldIndex-1;index<=i;--i)children[i+1]=children[i];children[index]=child,this.$markDirty()}return this},Layer.prototype.removeChild=function(child){child=this.getChildIndex(child);return this.removeChildAt(child)},Layer.prototype.removeChildAt=function(index){var children=this.$children,child=children[index];return child&&(children.splice(index,1),child.$emitRemoved(),this.$resizeCanvas()),this},Layer.prototype.removeChildByName=function(name){for(var children=this.$children,i=0,l=children.length;i<l;++i)if(children[i].name===name){this.removeChildAt(i);break}return this},Layer.prototype.removeChildrenByTag=function(tag){for(var children=this.$children,i=children.length-1;0<=i;--i)children[i].tag===tag&&this.removeChildAt(i);return this},Layer.prototype.removeAllChildren=function(){for(var _i=0,children_3=this.$children;_i<children_3.length;_i++)children_3[_i].$emitRemoved();return this.$children.length=0,this.$resizeCanvas(),this},Layer.prototype.removeSelf=function(){return this.$parent&&this.$parent.removeChild(this),this},Layer.prototype.$markDirty=function(sizeDirty){sizeDirty?this.$resizeParentCanvas():this.$dirty||this.$markParentDirty(),this.$dirty=!0},Layer.prototype.$markParentDirty=function(){this.$parent&&this.$parent.$markDirty()},Layer.prototype.$resizeCanvas=function(){var bounds,width=this.$width,height=this.$height,canvas=this.$canvas,anchorX=this.$anchorX,anchorY=this.$anchorY,context=this.$context,smoothing=this.$smoothing,pixelRatio=Layer.pixelRatio;width&&height?(canvas.width=width*pixelRatio,canvas.height=height*pixelRatio):(bounds=this.$getContentBounds(),canvas.width=(width||bounds.right+anchorX)*pixelRatio,canvas.height=(height||bounds.bottom+anchorY)*pixelRatio,bounds.release()),context.imageSmoothingEnabled!==smoothing&&(context.imageSmoothingEnabled=smoothing),this.$markDirty(!0)},Layer.prototype.$resizeParentCanvas=function(){this.$parent&&this.$parent.$resizeCanvas()},Layer.prototype.$getTransform=function(){var degToRad=Math.PI/180,matrix=Matrix.create();return matrix.translate(-this.$anchorX,-this.$anchorY),matrix.skew(this.skewX*degToRad,this.skewY*degToRad),matrix.rotate(this.rotation*degToRad),matrix.scale(this.scaleX,this.scaleY),matrix.translate(this.x,this.y),matrix},Layer.prototype.$getChildTransform=function(child){return child.$getTransform()},Layer.prototype.$getChildBounds=function(child){var width=child.width,height=child.height,bounds=Rectangle.create(),child=this.$getChildTransform(child),topLeft=Vector.create(0,0).transform(child),topRight=Vector.create(width,0).transform(child),bottomLeft=Vector.create(0,height).transform(child),width=Vector.create(width,height).transform(child),height=Math.min(topLeft.x,topRight.x,bottomLeft.x,width.x),maxX=Math.max(topLeft.x,topRight.x,bottomLeft.x,width.x),minY=Math.min(topLeft.y,topRight.y,bottomLeft.y,width.y),maxY=Math.max(topLeft.y,topRight.y,bottomLeft.y,width.y);return bounds.top=minY,bounds.bottom=maxY,bounds.left=height,bounds.right=maxX,child.release(),topLeft.release(),topRight.release(),bottomLeft.release(),width.release(),bounds},Layer.prototype.$getContentBounds=function(){for(var bounds,_i=0,children_4=this.$children;_i<children_4.length;_i++){var child=children_4[_i];child.$visible&&(child=this.$getChildBounds(child),bounds?(bounds.top=Math.min(bounds.top,child.top),bounds.bottom=Math.max(bounds.bottom,child.bottom),bounds.left=Math.min(bounds.left,child.left),bounds.right=Math.max(bounds.right,child.right),child.release()):bounds=child)}return bounds=bounds||Rectangle.create()},Layer.prototype.$emitTouchEvent=function(event,inside){var type=event.type,localX=event.localX,localY=event.localY,touches=this.$touches,identifier=event.identifier;if(type===TouchEvent.TOUCH_START)this.$shouldEmitTap=!0,touches[identifier]=!0;else{if(!touches[identifier])return!1;type!==TouchEvent.TOUCH_TAP&&type!==TouchEvent.TOUCH_CANCEL||(touches[identifier]=!1)}type===TouchEvent.TOUCH_MOVE&&(this.$shouldEmitTap=!1);for(var children=this.$children,i=children.length-1;0<=i;--i){var child=children[i];if(child.$visible&&child.touchable){var matrix=this.$getChildTransform(child),localPos=Vector.create(localX,localY).transform(matrix.invert()).subtract(child.$anchorX,child.$anchorY),inside_1=child.$localHitTest(localPos);if(localPos.release(),matrix.release(),(inside_1||type!==TouchEvent.TOUCH_START)&&(event.target=child,event.localX=event.targetX=localPos.x,event.localY=event.targetY=localPos.y,child.$emitTouchEvent(event,inside_1)))break}}return(type!==TouchEvent.TOUCH_TAP||inside&&this.$shouldEmitTap)&&!event.cancelBubble&&(event.localX=localX,event.localY=localY,this.emit(event)),!0},Layer.prototype.$emitAdded=function(parent){var stage=parent.$stage;this.$parent=parent,this.emit(Event.ADDED),stage&&this.$emitAddedToStage(stage)},Layer.prototype.$emitRemoved=function(){var stage=this.$stage;this.$parent=null,this.emit(Event.REMOVED),stage&&this.$emitRemovedFromStage()},Layer.prototype.$emitAddedToStage=function(stage){var children=this.$children;this.$stage=stage,this.emit(Event.ADDED_TO_STAGE),this.hasEventListener(Event.ENTER_FRAME)&&stage.ticker.registerEnterFrameCallback(this);for(var _i=0,children_5=children;_i<children_5.length;_i++)children_5[_i].$emitAddedToStage(stage)},Layer.prototype.$emitRemovedFromStage=function(){var stage=this.$stage,children=this.$children;this.$stage=null,this.emit(Event.REMOVED_FROM_STAGE),this.hasEventListener(Event.ENTER_FRAME)&&stage.ticker.unregisterEnterFrameCallback(this);for(var _i=0,children_6=children;_i<children_6.length;_i++)children_6[_i].$emitRemovedFromStage()},Layer.prototype.$localHitTest=function(vector){return vector.x>=-this.anchorX&&vector.x<=this.width-this.anchorX&&vector.y>=-this.anchorY&&vector.y<=this.height-this.anchorY},Layer.prototype.$isChildVisible=function(child){var minX,minY,maxY,maxX;return!!(child.visible&&child.alpha&&child.width&&child.height)&&(minX=-this.$anchorX,maxX=this.width+minX,minY=-this.$anchorY,maxY=this.height+minY,maxX=(child=this.$getChildBounds(child)).left<=maxX&&child.right>=minX&&child.top<=maxY&&child.bottom>=minY,child.release(),maxX)},Layer.prototype.$drawChild=function(child){var tx,ty,ctx=this.$context,canvas=child.$canvas,width=child.width,height=child.height,pixelRatio=Layer.pixelRatio,pixelRatio=this.$getChildTransform(child).scale(pixelRatio),drawCalls=child.$render(),globalAlpha=ctx.globalAlpha;return globalAlpha!==child.alpha&&(ctx.globalAlpha=child.alpha),0===pixelRatio.b&&0===pixelRatio.c?(tx=pixelRatio.tx+.5|0,ty=pixelRatio.ty+.5|0,width=width*pixelRatio.a+.5|0,height=height*pixelRatio.d+.5|0,ctx.drawImage(canvas,tx,ty,width,height)):(ctx.save(),ctx.transform(pixelRatio.a,pixelRatio.b,pixelRatio.c,pixelRatio.d,pixelRatio.tx,pixelRatio.ty),ctx.drawImage(canvas,0,0,width,height),ctx.restore()),globalAlpha!==child.alpha&&(ctx.globalAlpha=globalAlpha),pixelRatio.release(),drawCalls+1},Layer.prototype.$render=function(){if(!this.$dirty)return 0;var drawCalls=0,ctx=this.$context,canvas=this.$canvas,children=this.$children,canvasWidth=canvas.width,canvas=canvas.height,anchorX=this.$anchorX+.5|0,anchorY=this.$anchorY+.5|0,background=this.$background,pixelRatio=Layer.pixelRatio;ctx.globalAlpha=1,ctx.setTransform(1,0,0,1,0,0),ctx.clearRect(0,0,canvasWidth,canvas),background&&(ctx.fillStyle=background,ctx.fillRect(0,0,canvasWidth,canvas)),ctx.translate(anchorX*pixelRatio,anchorY*pixelRatio);for(var _i=0,children_7=children;_i<children_7.length;_i++){var child=children_7[_i];this.$isChildVisible(child)&&(drawCalls+=this.$drawChild(child))}return this.$dirty=!1,drawCalls},Layer.prototype.on=function(type,listener){var event_1;return _super.prototype.on.call(this,type,listener),type===Event.ENTER_FRAME&&this.ticker?this.ticker.registerEnterFrameCallback(this):type===Event.ADDED&&this.$parent?(event_1=Event.create(type),listener.call(this,event_1),event_1.release()):type===Event.ADDED_TO_STAGE&&this.$stage&&(event_1=Event.create(type),listener.call(this,event_1),event_1.release()),this},Layer.prototype.off=function(type,listener){return _super.prototype.off.call(this,type,listener),type===Event.ENTER_FRAME&&!this.hasEventListener(Event.ENTER_FRAME)&&this.ticker&&this.ticker.unregisterEnterFrameCallback(this),this},Layer.pixelRatio="undefined"!=typeof window&&window.devicePixelRatio||1,Layer}(EventEmitter),Layer$1=Object.freeze({__proto__:null,Layer:Layer}),Ease=function(){function Ease(){}return Ease.linear=function(t,b,c,d){return c*t/d+b},Ease.easeInQuad=function(t,b,c,d){return c*(t/=d)*t+b},Ease.easeOutQuad=function(t,b,c,d){return-c*(t/=d)*(t-2)+b},Ease.easeInOutQuad=function(t,b,c,d){return(t/=d/2)<1?c/2*t*t+b:-c/2*(--t*(t-2)-1)+b},Ease.easeInCubic=function(t,b,c,d){return c*(t/=d)*t*t+b},Ease.easeOutCubic=function(t,b,c,d){return c*((t=t/d-1)*t*t+1)+b},Ease.easeInOutCubic=function(t,b,c,d){return(t/=d/2)<1?c/2*t*t*t+b:c/2*((t-=2)*t*t+2)+b},Ease.easeInQuart=function(t,b,c,d){return c*(t/=d)*t*t*t+b},Ease.easeOutQuart=function(t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b},Ease.easeInOutQuart=function(t,b,c,d){return(t/=d/2)<1?c/2*t*t*t*t+b:-c/2*((t-=2)*t*t*t-2)+b},Ease.easeInQuint=function(t,b,c,d){return c*(t/=d)*t*t*t*t+b},Ease.easeOutQuint=function(t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b},Ease.easeInOutQuint=function(t,b,c,d){return(t/=d/2)<1?c/2*t*t*t*t*t+b:c/2*((t-=2)*t*t*t*t+2)+b},Ease.easeInSine=function(t,b,c,d){return t===d?b+c:-c*Math.cos(t/d*(Math.PI/2))+c+b},Ease.easeOutSine=function(t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b},Ease.easeInOutSine=function(t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b},Ease.easeInExpo=function(t,b,c,d){return 0===t?b:c*Math.pow(2,10*(t/d-1))+b},Ease.easeOutExpo=function(t,b,c,d){return t===d?b+c:c*(1-Math.pow(2,-10*t/d))+b},Ease.easeInOutExpo=function(t,b,c,d){return 0===t?b:t===d?b+c:(t/=d/2)<1?c/2*Math.pow(2,10*(t-1))+b:c/2*(2-Math.pow(2,-10*--t))+b},Ease.easeInCirc=function(t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b},Ease.easeOutCirc=function(t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b},Ease.easeInOutCirc=function(t,b,c,d){return(t/=d/2)<1?-c/2*(Math.sqrt(1-t*t)-1)+b:c/2*(Math.sqrt(1-(t-=2)*t)+1)+b},Ease.easeInElastic=function(t,b,c,d){var s=1.70158,p=0,a=c;return 0===t?b:1==(t/=d)?b+c:(p=p||.3*d,s=a<Math.abs(c)?(a=c,p/4):p/(2*Math.PI)*Math.asin(c/a),-(a*Math.pow(2,10*--t)*Math.sin((t*d-s)*(2*Math.PI)/p))+b)},Ease.easeOutElastic=function(t,b,c,d){var s=1.70158,p=0,a=c;return 0===t?b:1==(t/=d)?b+c:(p=p||.3*d,s=a<Math.abs(c)?(a=c,p/4):p/(2*Math.PI)*Math.asin(c/a),a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b)},Ease.easeInOutElastic=function(t,b,c,d){var s=1.70158,p=0,a=c;return 0===t?b:2==(t/=d/2)?b+c:(p=p||d*(.3*1.5),s=a<Math.abs(c)?(a=c,p/4):p/(2*Math.PI)*Math.asin(c/a),t<1?a*Math.pow(2,10*--t)*Math.sin((t*d-s)*(2*Math.PI)/p)*-.5+b:a*Math.pow(2,-10*--t)*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b)},Ease.easeInBack=function(t,b,c,d,s){return void 0===s&&(s=1.70158),t===d?b+c:c*(t/=d)*t*((s+1)*t-s)+b},Ease.easeOutBack=function(t,b,c,d,s){return void 0===s&&(s=1.70158),0===t?b:c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},Ease.easeInOutBack=function(t,b,c,d,s){return void 0===s&&(s=1.70158),(t/=d/2)<1?c/2*(t*t*((1+(s*=1.525))*t-s))+b:c/2*((t-=2)*t*((1+(s*=1.525))*t+s)+2)+b},Ease.easeInBounce=function(t,b,c,d){return c-Ease.easeOutBounce(d-t,0,c,d)+b},Ease.easeOutBounce=function(t,b,c,d){return(t/=d)<1/2.75?c*(7.5625*t*t)+b:t<2/2.75?c*(7.5625*(t-=1.5/2.75)*t+.75)+b:t<2.5/2.75?c*(7.5625*(t-=2.25/2.75)*t+.9375)+b:c*(7.5625*(t-=2.625/2.75)*t+.984375)+b},Ease.easeInOutBounce=function(t,b,c,d){return t<d/2?.5*Ease.easeInBounce(2*t,0,c,d)+b:.5*Ease.easeOutBounce(2*t-d,0,c,d)+.5*c+b},Ease}(),Ease$1=Object.freeze({__proto__:null,Ease:Ease}),Tween=function(_super){function Tween(target,option){var _this=_super.call(this)||this;return _this.loop=!1,_this.$target=null,_this.$paused=!0,_this.$stopped=!0,_this.$stepIndex=0,_this.$stepPosition=0,_this.$steps=[],_this.$stepProps=[],_this.$shouldSaveProps=!0,_this.$target=target,_this.loop=!!option&&option.loop,_this.$boundOnEnterFrame=_this.$onEnterFrame.bind(_this),_this}return __extends(Tween,_super),Object.defineProperty(Tween.prototype,"paused",{get:function(){return this.$paused},enumerable:!1,configurable:!0}),Object.defineProperty(Tween.prototype,"stopped",{get:function(){return this.$stopped},enumerable:!1,configurable:!0}),Tween.prototype.set=function(props){return this.$steps.push({type:"set",props:props}),this},Tween.prototype.to=function(props,duration,ease){return this.$steps.push({type:"to",duration:duration,props:props,ease:ease}),this},Tween.prototype.wait=function(duration){return this.$steps.push({type:"wait",duration:duration}),this},Tween.prototype.call=function(callback){return this.$steps.push({type:"call",callback:callback}),this},Tween.prototype.play=function(){return this.$stopped&&(this.resume(),Tween.$tweens.push(this)),this},Tween.prototype.pause=function(){return this.$paused=!0,this.$target.off(Event.ENTER_FRAME,this.$boundOnEnterFrame),this},Tween.prototype.resume=function(){return this.$paused&&(this.$paused=!1,this.$stopped=!1,this.$target.on(Event.ENTER_FRAME,this.$boundOnEnterFrame)),this},Tween.prototype.stop=function(){this.pause(),this.$stopped=!0;var index=Tween.$tweens.indexOf(this);return 0<=index&&Tween.$tweens.splice(index,1),this},Tween.prototype.$onEnterFrame=function(e){this.$nextFrame(e.data)},Tween.prototype.$nextFrame=function(dt){var loop=this.loop,steps=this.$steps,stepLength=this.$steps.length,stepIndex=this.$stepIndex,dt=this.$stepPosition+dt,steps=steps[stepIndex],type=steps.type,duration=steps.duration||0,props=steps.props,ease=steps.ease||Ease.linear,steps=steps.callback;"set"===type?this.$setProps(props):"to"===type?this.$easeProps(stepIndex,props,dt,duration,ease):"call"===type&&steps.call(this.$target),dt<duration?this.$stepPosition=dt:stepIndex+1<stepLength?(this.$stepPosition=0,this.$stepIndex=stepIndex+1,this.$shouldSaveProps=!0,this.$setProps(props),this.$nextFrame(dt-duration)):loop?(this.$stepIndex=0,this.$stepPosition=0,this.$shouldSaveProps=!0,this.$setProps(props),this.$nextFrame(dt-duration)):(this.$stepIndex=0,this.$stepPosition=0,this.$shouldSaveProps=!0,this.$setProps(props),this.pause())},Tween.prototype.$saveOriginalProps=function(stepIndex,props){var key,target=this.$target,stepProps=this.$stepProps,originalProps=stepProps[stepIndex]=stepProps[stepIndex]||{};for(key in props)originalProps[key]=target[key];this.$shouldSaveProps=!1},Tween.prototype.$easeProps=function(stepIndex,props,position,duration,ease){this.$shouldSaveProps&&this.$saveOriginalProps(stepIndex,props);var key,target=this.$target,originalProps=this.$stepProps[stepIndex]||{};for(key in duration<position&&(position=duration),props){var originalValue=originalProps[key],offsetValue=props[key]-originalValue;target[key]=ease(position,originalValue,offsetValue,duration)}},Tween.prototype.$setProps=function(props){var key,target=this.$target;for(key in props)target[key]=props[key]},Tween.get=function(target,option){return new Tween(target,option)},Tween.pauseTweens=function(target){for(var _i=0,tweens_1=this.$tweens;_i<tweens_1.length;_i++){var tween=tweens_1[_i];tween.$target===target&&tween.pause()}},Tween.resumeTweens=function(target){for(var _i=0,tweens_2=this.$tweens;_i<tweens_2.length;_i++){var tween=tweens_2[_i];tween.$target===target&&tween.resume()}},Tween.removeTweens=function(target){for(var tweens=this.$tweens,i=tweens.length-1;0<=i;--i){var tween=tweens[i];tween.$target===target&&tween.stop()}},Tween.removeAllTweens=function(){for(var tweens=this.$tweens,i=tweens.length-1;0<=i;--i)tweens[i].stop()},Tween.$tweens=[],Tween}(EventEmitter),Tween$1=Object.freeze({__proto__:null,Tween:Tween}),Scroller=function(_super){function Scroller(){var _this=_super.call(this)||this;return _this.$scrollTop=0,_this.$scrollLeft=0,_this.$scrollWidth=0,_this.$scrollHeight=0,_this.$touchingX=null,_this.$touchingY=null,_this.$touchingId=null,_this.$touchingTime=null,_this.$velocitiesX=[],_this.$velocitiesY=[],_this.$inertiaTween=null,_this.width=200,_this.height=200,_this.on(TouchEvent.TOUCH_START,_this.$onTouchStart),_this.on(TouchEvent.TOUCH_MOVE,_this.$onTouchMove),_this.on(TouchEvent.TOUCH_END,_this.$onTouchEnd),_this.on(TouchEvent.TOUCH_CANCEL,_this.$onTouchCancel),_this}return __extends(Scroller,_super),Object.defineProperty(Scroller.prototype,"scrollTop",{get:function(){return this.$scrollTop},set:function(scrollTop){var bounds=this.$getContentBounds(),maxScrollTop=this.$scrollHeight-this.$height;(scrollTop=Math.max(0,Math.min(scrollTop,maxScrollTop)))!==this.$scrollTop&&(this.$scrollTop=scrollTop,this.$markDirty()),bounds.release()},enumerable:!1,configurable:!0}),Object.defineProperty(Scroller.prototype,"scrollLeft",{get:function(){return this.$scrollLeft},set:function(scrollLeft){var bounds=this.$getContentBounds(),maxScrollLeft=this.$scrollWidth-this.width;(scrollLeft=Math.max(0,Math.min(scrollLeft,maxScrollLeft)))!==this.$scrollLeft&&(this.$scrollLeft=scrollLeft,this.$markDirty()),bounds.release()},enumerable:!1,configurable:!0}),Object.defineProperty(Scroller.prototype,"scrollWidth",{get:function(){return this.$scrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(Scroller.prototype,"scrollHeight",{get:function(){return this.$scrollHeight},enumerable:!1,configurable:!0}),Scroller.prototype.$getChildTransform=function(child){child=_super.prototype.$getChildTransform.call(this,child);return child.translate(-this.$scrollLeft,-this.$scrollTop),child},Scroller.prototype.$resizeCanvas=function(){_super.prototype.$resizeCanvas.call(this);var bounds=this.$getContentBounds();this.$scrollWidth=this.$scrollLeft+bounds.right+this.$anchorX,this.$scrollHeight=this.$scrollTop+bounds.bottom+this.$anchorY,this.scrollTop=this.$scrollTop,this.scrollLeft=this.$scrollLeft},Scroller.prototype.$onTouchStart=function(e){this.$touchingX=e.localX,this.$touchingY=e.localY,this.$velocitiesX.length=0,this.$velocitiesY.length=0,this.$touchingTime=Date.now(),this.$touchingId=e.identifier,this.$inertiaTween&&(this.$inertiaTween.pause(),this.$inertiaTween=null)},Scroller.prototype.$onTouchMove=function(e){var now,scrollTop,scrollLeft,dt,velocitiesX,velocitiesY,offsetX,offsetY,scrollingView;e.identifier===this.$touchingId&&(now=Date.now(),scrollTop=this.scrollTop,scrollLeft=this.scrollLeft,dt=now-this.$touchingTime,velocitiesX=this.$velocitiesX,velocitiesY=this.$velocitiesY,offsetX=e.localX-this.$touchingX,offsetY=e.localY-this.$touchingY,scrollingView=Scroller.scrollingView||this,velocitiesX.push(offsetX/dt),velocitiesY.push(offsetY/dt),5<velocitiesX.length&&(velocitiesX.shift(),velocitiesY.shift()),this.$touchingX=e.localX,this.$touchingY=e.localY,scrollingView===this)&&(this.$touchingTime=now,this.scrollTop-=offsetY,this.scrollLeft-=offsetX,this.$scrollLeft===scrollLeft&&this.$scrollTop===scrollTop||(Scroller.scrollingView=this))},Scroller.prototype.$onTouchEnd=function(e){if(e.identifier===this.$touchingId&&Scroller.scrollingView===this){Scroller.scrollingView=null;for(var sumVelocityX=0,sumVelocityY=0,e=this.$scrollTop,scrollLeft=this.$scrollLeft,velocitiesX=this.$velocitiesX,velocitiesY=this.$velocitiesY,numVelocities=velocitiesX.length,i=0;i<numVelocities;++i)sumVelocityX+=velocitiesX[i],sumVelocityY+=velocitiesY[i];var duration,velocityX=sumVelocityX/numVelocities,velocityY=sumVelocityY/numVelocities,absVelocityX=Math.abs(velocityX),absVelocityY=Math.abs(velocityY);(.01<absVelocityX||.01<absVelocityY)&&(duration=1e3*Math.max(absVelocityX,absVelocityY,1),this.$inertiaTween=Tween.get(this).to({scrollTop:e-velocityY*(absVelocityY+1)*200,scrollLeft:scrollLeft-velocityX*(absVelocityX+1)*200},duration,Ease.easeOutQuart).play()),this.$touchingId=null}},Scroller.prototype.$onTouchCancel=function(e){e.identifier===this.$touchingId&&(this.$touchingId=null)},Scroller.prototype.$emitRemovedFromStage=function(){_super.prototype.$emitRemovedFromStage.call(this),this.$inertiaTween&&(this.$inertiaTween.pause(),this.$inertiaTween=null)},Scroller}(Layer),Scroller$1=Object.freeze({__proto__:null,Scroller:Scroller}),Image=function(_super){function Image(texture,width,height){var _this=_super.call(this)||this;return _this.$texture=null,_this.$fillMode=Image.SCALE,_this.$clipRect=null,_this.$scale9Grid=null,_this.$pattern=null,_this.$boundOnTextureLoad=_this.$onTextureLoad.bind(_this),texture&&(_this.$width=width,_this.$height=height,_this.texture=texture),_this}return __extends(Image,_super),Object.defineProperty(Image.prototype,"texture",{get:function(){return this.$texture},set:function(texture){this.$texture&&this.$texture.off(Event.LOAD,this.$boundOnTextureLoad),(this.$texture=texture)?texture.on(Event.LOAD,this.$boundOnTextureLoad):(this.$updatePattern(),this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Image.prototype,"fillMode",{get:function(){return this.$fillMode},set:function(fillMode){this.$fillMode=fillMode,this.$updatePattern(),this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Image.prototype,"clipRect",{get:function(){return this.$clipRect},set:function(clipRect){this.$clipRect=clipRect,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Image.prototype,"scale9Grid",{get:function(){return this.$scale9Grid},set:function(scale9Grid){this.$scale9Grid=scale9Grid,this.$markDirty()},enumerable:!1,configurable:!0}),Image.prototype.$onTextureLoad=function(){this.$updatePattern(),this.$resizeCanvas(),this.$texture.off(Event.LOAD,this.$boundOnTextureLoad)},Image.prototype.$updatePattern=function(){var width=this.$width,height=this.$height,texture=this.$texture,fillMode=this.$fillMode;this.$pattern=(width||height)&&texture&&fillMode&&fillMode!==Image.SCALE?this.$context.createPattern(texture.element,fillMode):null},Image.prototype.$getContentBounds=function(){var texture=this.$texture,clipRect=this.$clipRect,bounds=_super.prototype.$getContentBounds.call(this);return bounds.x=Math.min(bounds.left,-this.$anchorX),bounds.y=Math.min(bounds.top,-this.$anchorY),clipRect?(bounds.width=Math.max(bounds.width,clipRect.width),bounds.height=Math.max(bounds.height,clipRect.height)):texture&&(bounds.width=Math.max(bounds.width,texture.width),bounds.height=Math.max(bounds.height,texture.height)),bounds},Image.prototype.$drawPattern=function(targetX,targetY,targetW,targetH){var ctx=this.$context,texture=this.$texture,pattern=this.$pattern,texture=Layer.pixelRatio/texture.pixelRatio;1!=texture&&ctx.scale(texture,texture),ctx.fillStyle=pattern,ctx.fillRect(targetX,targetY,targetW,targetH)},Image.prototype.$drawTexture=function(sourceX,sourceY,sourceW,sourceH,targetX,targetY,targetW,targetH){var ctx,texture,pixelRatio;sourceW<=0||sourceH<=0||targetW<=0||targetH<=0||(ctx=this.$context,pixelRatio=(texture=this.$texture).pixelRatio,0<sourceW&&0<sourceH&&0<targetW&&0<targetH&&ctx.drawImage(texture.element,sourceX*pixelRatio,sourceY*pixelRatio,sourceW*pixelRatio,sourceH*pixelRatio,targetX,targetY,targetW,targetH))},Image.prototype.$render=function(){var drawCalls,x,y,width,canvas,clipX,clipY,clipWidth,clipRect,sourceX0,sourceY0,texture,pattern,sourceX1,sourceY1,sourceW1,scale9Grid,sourceX2,sourceY2,sourceW2,sourceH2,anchorX,anchorY,targetW0,targetH0,targetX1,targetY1,targetW1,pixelRatio,targetX2,targetY2,targetW2,targetH2;return this.$dirty?(canvas=this.$canvas,anchorX=this.$anchorX,anchorY=this.$anchorY,texture=this.$texture,pattern=this.$pattern,clipRect=this.$clipRect,scale9Grid=this.$scale9Grid,drawCalls=_super.prototype.$render.call(this),x=-anchorX*(pixelRatio=Layer.pixelRatio),y=-anchorY*pixelRatio,width=canvas.width,canvas=canvas.height,clipX=clipRect?clipRect.x:0,clipY=clipRect?clipRect.y:0,clipWidth=clipRect?clipRect.width:texture?texture.width:0,clipRect=clipRect?clipRect.height:texture?texture.height:0,texture&&(pattern?this.$drawPattern(x,y,width,canvas):scale9Grid?(texture=scale9Grid.x,pattern=scale9Grid.y,sourceX2=(sourceX1=(sourceX0=clipX)+texture)+(sourceW1=scale9Grid.width),sourceY2=(sourceY1=(sourceY0=clipY)+pattern)+(scale9Grid=scale9Grid.height),targetX2=(targetX1=(anchorX=-anchorX*pixelRatio)+(targetW0=texture*pixelRatio))+(targetW1=width-(texture+(sourceW2=clipWidth-texture-sourceW1))*pixelRatio),targetY2=(targetY1=(anchorY=-anchorY*pixelRatio)+(targetH0=pattern*pixelRatio))+(pixelRatio=canvas-(pattern+(sourceH2=clipRect-pattern-scale9Grid))*pixelRatio),targetW2=width-targetW0-targetW1,targetH2=canvas-targetH0-pixelRatio,this.$drawTexture(sourceX0,sourceY0,texture,pattern,anchorX,anchorY,targetW0,targetH0),this.$drawTexture(sourceX1,sourceY0,sourceW1,pattern,targetX1,anchorY,targetW1,targetH0),this.$drawTexture(sourceX2,sourceY0,sourceW2,pattern,targetX2,anchorY,targetW2,targetH0),this.$drawTexture(sourceX0,sourceY1,texture,scale9Grid,anchorX,targetY1,targetW0,pixelRatio),this.$drawTexture(sourceX1,sourceY1,sourceW1,scale9Grid,targetX1,targetY1,targetW1,pixelRatio),this.$drawTexture(sourceX2,sourceY1,sourceW2,scale9Grid,targetX2,targetY1,targetW2,pixelRatio),this.$drawTexture(sourceX0,sourceY2,texture,sourceH2,anchorX,targetY2,targetW0,targetH2),this.$drawTexture(sourceX1,sourceY2,sourceW1,sourceH2,targetX1,targetY2,targetW1,targetH2),this.$drawTexture(sourceX2,sourceY2,sourceW2,sourceH2,targetX2,targetY2,targetW2,targetH2)):this.$drawTexture(clipX,clipY,clipWidth,clipRect,x,y,width,canvas)),drawCalls):0},Image.SCALE="scale",Image.REPEAT="repeat",Image.REPEAT_X="repeat-x",Image.REPEAT_Y="repeat-y",Image}(Layer),Image$1=Object.freeze({__proto__:null,Image:Image}),Text=function(_super){function Text(text,options){void 0===options&&(options={});var _this=_super.call(this)||this;return _this.$text="",_this.$color="black",_this.$fontSize=Text.defaultFontSize,_this.$fontStyle="normal",_this.$fontWeight="normal",_this.$textAlign="left",_this.$verticalAlign="top",_this.$lineHeight=1.2,_this.$strokeSize=0,_this.$strokeColor=null,_this.$fontFamily="Helvetica",_this.$multiline=!1,_this.$breakWord=!1,_this.$autoFitSize=!1,_this.$minFontSize=0,_this.$explicitSize=0,_this.$lines=[],_this.$text=text||_this.$text,_this.$color=options.color||_this.$color,_this.$fontSize=options.fontSize||_this.$fontSize,_this.$fontStyle=options.fontStyle||_this.$fontStyle,_this.$fontWeight=options.fontWeight||_this.$fontWeight,_this.$textAlign=options.textAlign||_this.$textAlign,_this.$verticalAlign=options.verticalAlign||_this.$verticalAlign,_this.$lineHeight=options.lineHeight||_this.$lineHeight,_this.$strokeSize=options.strokeSize||_this.$strokeSize,_this.$strokeColor=options.strokeColor||_this.$strokeColor,_this.$fontFamily=options.fontFamily||_this.$fontFamily,_this.$multiline=options.multiline||_this.$multiline,_this.$breakWord=options.breakWord||_this.$breakWord,_this.$autoFitSize=options.autoFitSize||_this.autoFitSize,_this.$minFontSize=options.minFontSize||_this.minFontSize,_this.$resizeCanvas(),_this}return __extends(Text,_super),Object.defineProperty(Text.prototype,"text",{get:function(){return this.$text},set:function(text){this.$text=text,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"color",{get:function(){return this.$color},set:function(color){this.$color=color,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"fontSize",{get:function(){return this.$fontSize},set:function(fontSize){this.$fontSize=fontSize,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"fontStyle",{get:function(){return this.$fontStyle},set:function(fontStyle){this.$fontStyle=fontStyle,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"fontWeight",{get:function(){return this.$fontWeight},set:function(fontWeight){this.$fontWeight=fontWeight,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"textAlign",{get:function(){return this.$textAlign},set:function(textAlign){this.$textAlign=textAlign,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"verticalAlign",{get:function(){return this.$verticalAlign},set:function(verticalAlign){this.$verticalAlign=verticalAlign,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"lineHeight",{get:function(){return this.$lineHeight},set:function(lineHeight){this.$lineHeight=lineHeight,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"strokeSize",{get:function(){return this.$strokeSize},set:function(strokeSize){this.$strokeSize=strokeSize,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"strokeColor",{get:function(){return this.$strokeColor},set:function(strokeColor){this.$strokeColor=strokeColor,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"fontFamily",{get:function(){return this.$fontFamily},set:function(fontFamily){this.$fontFamily=fontFamily,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"multiline",{get:function(){return this.$multiline},set:function(multiline){this.$multiline=multiline,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"breakWord",{get:function(){return this.$breakWord},set:function(breakWord){this.$breakWord=breakWord,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"autoFitSize",{get:function(){return this.$autoFitSize},set:function(autoFitSize){this.$autoFitSize=autoFitSize,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Object.defineProperty(Text.prototype,"minFontSize",{get:function(){return this.$minFontSize},set:function(minFontSize){this.$minFontSize=minFontSize,this.$resizeCanvas()},enumerable:!1,configurable:!0}),Text.prototype.$updateContext=function(){var ctx=this.$context,fontStyle=this.$fontStyle,fontWeight=this.$fontWeight,pixelRatio=Layer.pixelRatio,fontSize=this.$explicitSize||this.$fontSize;ctx.font=fontStyle+" "+fontWeight+" "+(fontSize*pixelRatio+"px")+" "+this.$fontFamily,ctx.textAlign=this.$textAlign,ctx.textBaseline="top",ctx.fillStyle=this.$color,ctx.lineWidth=this.$strokeSize*pixelRatio,ctx.strokeStyle=this.$strokeColor},Text.prototype.$divideUnits=function(){var text=this.$text,breakWord=this.$breakWord,wordRe=Text.wordRe,boundaryRe=Text.boundaryRe;if(breakWord)units=text.split("");else for(var units=[],_i=0,words_1=text.split(boundaryRe);_i<words_1.length;_i++){var unit=words_1[_i];wordRe.test(unit)?units.push(unit):units=units.concat(unit.split(""))}return units},Text.prototype.$divideLines=function(){var text=this.$text;if(this.$multiline)if(this.$width){var line="",ctx=this.$context,lines=this.$lines=[],units=this.$divideUnits(),width=this.$width*Layer.pixelRatio;this.$updateContext();for(var _i=0,units_1=units;_i<units_1.length;_i++){var unit=units_1[_i];"\n"===unit?(lines.push(line),line=""):ctx.measureText(line+unit).width<=width?line+=unit:(line&&lines.push(line),line=unit)}lines.push(line)}else this.$lines=text.split("\n");else this.$lines=[text]},Text.prototype.$resizeCanvas=function(){var width=this.$width,height=this.$height;if(this.$divideLines(),this.$autoFitSize&&(width||height)){var minFontSize=this.$minFontSize||1;for(this.$explicitSize=this.$fontSize;this.$explicitSize>minFontSize;){var bounds=this.$getContentBounds();if(!(width&&bounds.width>width||height&&bounds.height>height))break;--this.$explicitSize,bounds.release()}}_super.prototype.$resizeCanvas.call(this)},Text.prototype.$getContentBounds=function(){var ctx=this.$context,bounds=_super.prototype.$getContentBounds.call(this),lines=this.$lines,lineHeight=this.$lineHeight,pixelRatio=Layer.pixelRatio,fontSize=this.$explicitSize||this.$fontSize;this.$updateContext();for(var _i=0,lines_1=lines;_i<lines_1.length;_i++){var line=lines_1[_i];bounds.width=Math.max(bounds.width,ctx.measureText(line).width/pixelRatio)}return bounds.height=Math.max(bounds.height,fontSize*lineHeight*lines.length),bounds},Text.prototype.$render=function(){if(!this.$dirty)return 0;var x=0,y=0,width=this.width,height=this.height,anchorX=this.anchorX,anchorY=this.anchorY,ctx=this.$context,lines=this.$lines,color=this.$color,textAlign=this.$textAlign,verticalAlign=this.$verticalAlign,lineHeight=this.$lineHeight,strokeSize=this.$strokeSize,strokeColor=this.$strokeColor,pixelRatio=Layer.pixelRatio,fontSize=this.$explicitSize||this.$fontSize,drawCalls=_super.prototype.$render.call(this);this.$updateContext();for(var x="center"===textAlign?width*pixelRatio/2-anchorX*pixelRatio:"right"===textAlign?width*pixelRatio-anchorX*pixelRatio:-anchorX*pixelRatio,y="middle"===verticalAlign?(height-fontSize*lineHeight*(lines.length-1)-fontSize)*pixelRatio/2-anchorY*pixelRatio:"bottom"===verticalAlign?(height-fontSize*lineHeight*(lines.length-1)-fontSize)*pixelRatio-anchorY*pixelRatio:-anchorY*pixelRatio,_i=0,lines_2=lines;_i<lines_2.length;_i++){var line=lines_2[_i];color&&ctx.fillText(line,x,y),strokeSize&&strokeColor&&ctx.strokeText(line,x,y),y+=fontSize*lineHeight*pixelRatio}return drawCalls},Text.defaultFontSize=16,Text.wordRe=/\w+/,Text.boundaryRe=/\b/,Text}(Layer),Text$1=Object.freeze({__proto__:null,Text:Text}),Input=function(_super){function Input(value,options){var _this=_super.call(this,"",options=void 0===options?{}:options)||this;return _this.$value="",_this.$type="text",_this.$maxLength=16777215,_this.$placeholder="",_this.$placeholderColor="#888",_this.$explicitColor="black",_this.$value=value||_this.$value,_this.$type=options.type||_this.$type,_this.$maxLength=options.maxLength||_this.$maxLength,_this.$placeholder=options.placeholder||_this.$placeholder,_this.$placeholderColor=options.placeholderColor||_this.$placeholderColor,_this.$boundFocus=_this.focus.bind(_this),_this.$updateText(),_this.on(TouchEvent.TOUCH_TAP,_this.$onTouchTap),_this}return __extends(Input,_super),Object.defineProperty(Input.prototype,"text",{set:function(text){},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"value",{get:function(){return this.$value},set:function(value){this.$value=value,this.$updateText()},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"type",{get:function(){return this.$type},set:function(type){this.$type=type,this.$updateText()},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"color",{get:function(){return this.$explicitColor},set:function(color){this.$explicitColor=color,this.$value?this.$color=color:this.$color=this.$placeholderColor,this.$markDirty()},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"maxLength",{get:function(){return this.$maxLength},set:function(maxLength){this.$maxLength=maxLength},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"placeholder",{get:function(){return this.$placeholder},set:function(placeholder){this.$placeholder=placeholder,this.$updateText()},enumerable:!1,configurable:!0}),Object.defineProperty(Input.prototype,"placeholderColor",{get:function(){return this.$placeholderColor},set:function(placeholderColor){this.$placeholderColor=placeholderColor,this.$markDirty()},enumerable:!1,configurable:!0}),Input.prototype.selectAll=function(){var element=this.$updateElement();return this.focus(),element.selectionStart=0,element.selectionEnd=this.$value.length,this},Input.prototype.focus=function(){var element=this.$updateElement();return element.style.display="block",element.value=this.$value,element.focus(),Input.$focusedInput=this},Input.prototype.blur=function(){var element=this.$updateElement();return element.style.display="none",element.blur(),Input.$focusedInput===this&&(this.value=element.value,Input.$focusedInput=null),this},Input.prototype.$updateText=function(){var type=this.$type,value=this.$value;if("password"===type)for(var text="",i=0,l=value.length;i<l;++i)text+="•";else text=value;this.$text=text||this.$placeholder,this.color=this.$explicitColor,this.$resizeCanvas()},Input.prototype.$updateElement=function(){var tagName=this.$multiline&&"text"===this.$type?"textarea":"input",element=Input.$getElement(tagName),tagName="input"==tagName;return tagName&&(element.type=this.$type),element.maxLength=this.$maxLength,element.placeholder=this.$placeholder,element.style.left="0",element.style.bottom="0",element.style.margin="0",element.style.width="100%",element.style.height=(tagName?this.$fontSize*this.$lineHeight+24:this.height)+"px",element.style.minHeight=tagName?"0":this.$fontSize*this.$lineHeight*5+12+"px",element.style.maxHeight="50%",element.style.padding="6px",element.style.border="none",element.style.resize="none",element.style.outline="none",element.style.position="fixed",element.style.boxSizing="border-box",element.style.color=this.$explicitColor,element.style.fontSize=this.$fontSize+"px",element.style.fontStyle=this.$fontStyle,element.style.fontFamily=this.$fontFamily,element.style.textAlign=this.$textAlign,element.style.lineHeight=this.$lineHeight+"",element.style.fontWeight=this.$fontWeight+"",element.style.wordBreak=this.$breakWord?"break-all":"normal",element.style.background=this.$background,element.style.boxShadow="0 0 8px #aaa",element},Input.prototype.$markDirty=function(sizeDirty){_super.prototype.$markDirty.call(this,sizeDirty),Input.$focusedInput&&this.$updateElement()},Input.prototype.$onTouchTap=function(){setTimeout(this.$boundFocus,100)},Input.$getElement=function(tagName){var element;return"input"===tagName?element=this.$inputElement:"textarea"===tagName&&(element=this.$textAreaElement),element||((element=document.createElement(tagName)).style.display="none",document.body.appendChild(element),element.addEventListener("input",function(){Input.$focusedInput.value=element.value}),element.addEventListener("blur",function(){Input.$focusedInput.blur()}),"input"===tagName?(element.addEventListener("keydown",function(e){"Enter"!==e.key&&13!==e.keyCode||Input.$focusedInput.blur()}),this.$inputElement=element):"textarea"===tagName&&(this.$textAreaElement=element)),element},Input}(Text),Input$1=Object.freeze({__proto__:null,Input:Input}),MovieClip=function(_super){function MovieClip(texture,frames){texture=_super.call(this,texture)||this;return texture.$loop=!0,texture.$interval=30,texture.$paused=!1,texture.$currentFrame=0,texture.$frames=null,texture.$frames=frames,texture.$boundNextFrame=texture.nextFrame.bind(texture),texture.play(),texture}return __extends(MovieClip,_super),Object.defineProperty(MovieClip.prototype,"loop",{get:function(){return this.$loop},set:function(loop){this.$loop=loop},enumerable:!1,configurable:!0}),Object.defineProperty(MovieClip.prototype,"interval",{get:function(){return this.$interval},set:function(interval){this.$interval=interval},enumerable:!1,configurable:!0}),Object.defineProperty(MovieClip.prototype,"paused",{get:function(){return this.$paused},enumerable:!1,configurable:!0}),Object.defineProperty(MovieClip.prototype,"currentFrame",{get:function(){return this.$currentFrame},enumerable:!1,configurable:!0}),Object.defineProperty(MovieClip.prototype,"totalFrames",{get:function(){return this.$frames.length},enumerable:!1,configurable:!0}),MovieClip.prototype.play=function(){return this.off(Event.ADDED_TO_STAGE,this.play),this.gotoAndPlay(this.$currentFrame)},MovieClip.prototype.pause=function(){var ticker=this.ticker;return this.$paused=!0,ticker&&ticker.clearTimeout(this.$timer),this.off(Event.ADDED_TO_STAGE,this.play),this},MovieClip.prototype.nextFrame=function(){return this.gotoAndPlay(this.$currentFrame+1)},MovieClip.prototype.gotoAndPlay=function(frame){this.$paused=!1,this.$gotoFrame(frame);var loop=this.$loop,ticker=this.ticker,frames=this.$frames,totalFrames=frames.length,frames=frames[this.$currentFrame];if(frames)return ticker?(ticker.clearTimeout(this.$timer),(frame<totalFrames-1||loop)&&(this.$timer=ticker.setTimeout(this.$boundNextFrame,frames.interval||this.$interval))):this.on(Event.ADDED_TO_STAGE,this.play),this},MovieClip.prototype.gotoAndStop=function(frame){return this.$paused=!0,this.$gotoFrame(frame),this},MovieClip.prototype.$gotoFrame=function(frame){var totalFrames=this.$frames.length,totalFrames=this.$frames[frame=(frame=frame<0||totalFrames<=frame?(frame+totalFrames)%totalFrames:frame)<0?0:frame];totalFrames&&(this.$currentFrame=frame,this.clipRect=totalFrames.clip,this.stage)&&totalFrames.callback&&totalFrames.callback.call(this)},MovieClip}(Image),MovieClip$1=Object.freeze({__proto__:null,MovieClip:MovieClip}),Request=function(_super){function Request(url,options){var method,headers,data,responseType,qs_1,_this=_super.call(this)||this,xhr=(_this.$xhr=new XMLHttpRequest,_this.$xhr);return url instanceof Object&&(url=(options=url).url),options&&(url=options.url||url,method=options.method||"get",headers=options.headers,data=options.data,responseType=options.responseType),data instanceof Object&&(options=Request.$getContentType(headers),"get"===method.toLowerCase()?(qs_1=Request.$getQueryString(data),url+=url.indexOf("?")<0?"?"+qs_1:"&"+qs_1):"application/x-www-form-urlencoded"===options?data=Request.$getQueryString(data):"application/json"===options&&(data=JSON.stringify(data))),xhr.open(method||"get",url),xhr.responseType=responseType,headers&&Object.keys(headers).forEach(function(key){xhr.setRequestHeader(key,headers[key])}),xhr.addEventListener("abort",_this.$onAbort.bind(_this)),xhr.addEventListener("progress",_this.$onProgress.bind(_this)),xhr.addEventListener("readystatechange",_this.$onReadyStateChange.bind(_this)),xhr.send(data),_this}return __extends(Request,_super),Object.defineProperty(Request.prototype,"status",{get:function(){return this.$xhr.status},enumerable:!1,configurable:!0}),Object.defineProperty(Request.prototype,"response",{get:function(){return this.$xhr.response},enumerable:!1,configurable:!0}),Object.defineProperty(Request.prototype,"responseHeaders",{get:function(){for(var headers={},_i=0,arr_1=this.$xhr.getAllResponseHeaders().split("\n");_i<arr_1.length;_i++){var header=arr_1[_i],index=header.indexOf(":"),key=header.slice(0,index).trim(),header=header.slice(index+1).trim();headers[key]?(Array.isArray(headers[key])||(headers[key]=[headers[key]]),headers[key].push(header)):key&&(headers[key]=header)}return headers},enumerable:!1,configurable:!0}),Request.prototype.abort=function(){this.$xhr.abort()},Request.prototype.$onAbort=function(){this.emit(Event.ABORT)},Request.prototype.$onProgress=function(e){e.lengthComputable&&(e=Event.create(Event.PROGRESS,e.loaded/e.total),this.emit(e),e.release())},Request.prototype.$onReadyStateChange=function(e){var xhr=this.$xhr;4===xhr.readyState&&(400<=xhr.status||0===xhr.status?this.emit(Event.ERROR,e):(e=Event.create(Event.LOAD,xhr.response),this.emit(e),e.release()),this.emit(Event.COMPLETE))},Request.$getContentType=function(headers){for(var key in headers)if("content-type"===key.toLowerCase())return headers[key].toLowerCase();return null},Request.$getQueryString=function(data){return Object.keys(data).map(function(key){return key+"="+data[key]}).join("&")},Request}(EventEmitter),Request$1=Object.freeze({__proto__:null,Request:Request}),Media=function(_super){function Media(stage){var _this=_super.call(this)||this;return _this.$loaded=!1,_this.$errored=!1,_this.$stage=stage,_this.$boundOnLoad=_this.$onLoad.bind(_this),_this.$boundOnError=_this.$onError.bind(_this),_this}return __extends(Media,_super),Object.defineProperty(Media.prototype,"element",{get:function(){return this.$element},enumerable:!1,configurable:!0}),Object.defineProperty(Media.prototype,"url",{get:function(){return this.$element.src||""},set:function(url){this.$loaded=!1,this.$errored=!1,this.$element.src=url},enumerable:!1,configurable:!0}),Media.prototype.on=function(type,listener){var event_1;return _super.prototype.on.call(this,type,listener),type===Event.LOAD&&this.$loaded?(event_1=Event.create(type),listener.call(this,event_1),event_1.release()):type===Event.ERROR&&this.$errored&&(event_1=Event.create(type),listener.call(this,event_1),event_1.release()),this},Media.prototype.$onLoad=function(){this.$loaded=!0,this.emit(Event.LOAD),this.$element.removeEventListener(Event.LOAD,this.$boundOnLoad)},Media.prototype.$onError=function(){this.$errored=!0,this.emit(Event.ERROR),this.$element.removeEventListener(Event.ERROR,this.$boundOnError)},Media}(EventEmitter),Media$1=Object.freeze({__proto__:null,Media:Media}),Sound=function(_super){function Sound(stage,url){var _this=_super.call(this,stage)||this,audio=(_this.$loops=1,_this.$startTime=0,_this.$paused=!0,document.createElement("audio"));return audio.crossOrigin="*",audio.addEventListener("canplaythrough",_this.$boundOnLoad),audio.addEventListener("error",_this.$boundOnError),audio.addEventListener("ended",_this.$onEnded.bind(_this)),_this.$element=audio,_this.$boundOnTouch=_this.$onTouch.bind(_this),url&&(_this.url=url),stage.ticker.on(Event.TICKER_PAUSE,_this.$onTickerPause.bind(_this)),stage.ticker.on(Event.TICKER_RESUME,_this.$onTickerResume.bind(_this)),stage.on(Event.REMOVED_FROM_STAGE,_this.$onRemovedFromStage.bind(_this)),_this}return __extends(Sound,_super),Object.defineProperty(Sound.prototype,"element",{get:function(){return this.$element},enumerable:!1,configurable:!0}),Object.defineProperty(Sound.prototype,"url",{get:function(){return this.$element.src},set:function(url){this.$paused=!0,this.$element.src=url,this.$element.load(),0===url.indexOf("data:")&&this.$stage.ticker.setTimeout(this.$boundOnLoad)},enumerable:!1,configurable:!0}),Object.defineProperty(Sound.prototype,"volume",{get:function(){return this.$element.volume},set:function(volume){this.$element.volume=volume},enumerable:!1,configurable:!0}),Object.defineProperty(Sound.prototype,"paused",{get:function(){return this.$paused},enumerable:!1,configurable:!0}),Sound.prototype.play=function(startTime,loops){return void 0===startTime&&(startTime=0),this.$loops=loops=void 0===loops?1:loops,this.$startTime=startTime,this.$element.currentTime=startTime,this.$paused=!1,this.$checkStatus(),this},Sound.prototype.stop=function(){return this.$paused=!0,this.$element.pause(),this},Sound.prototype.$checkOnTouch=function(){document.addEventListener("click",this.$boundOnTouch),document.addEventListener("touchend",this.$boundOnTouch)},Sound.prototype.$checkStatus=function(){var promise=this.$element.play();promise&&promise.catch(),this.$paused&&this.$element.pause()},Sound.prototype.$onTouch=function(){this.$checkStatus(),document.removeEventListener("click",this.$boundOnTouch),document.removeEventListener("touchend",this.$boundOnTouch)},Sound.prototype.$onEnded=function(){this.emit(Event.ENDED),1===this.$loops?(this.stop(),this.emit(Event.SOUND_COMPLETE)):0===this.$loops?this.play(this.$startTime,0):this.play(this.$startTime,this.$loops-1)},Sound.prototype.$onTickerPause=function(){this.$paused||this.$element.pause()},Sound.prototype.$onTickerResume=function(){this.$paused||this.$checkStatus()},Sound.prototype.$onRemovedFromStage=function(){this.stop(),document.removeEventListener("click",this.$boundOnTouch),document.removeEventListener("touchend",this.$boundOnTouch)},Sound.prototype.$onLoad=function(){_super.prototype.$onLoad.call(this);var promise=this.$element.play();promise?promise.then(this.$checkStatus.bind(this)).catch(this.$checkOnTouch.bind(this)):this.$checkOnTouch()},Sound}(Media),Sound$1=Object.freeze({__proto__:null,Sound:Sound}),Texture=function(_super){function Texture(stage,url){var stage=_super.call(this,stage)||this,image=(stage.pixelRatio=Texture.defaultPixelRatio,document.createElement("img"));return image.crossOrigin="*",image.addEventListener("load",stage.$boundOnLoad),image.addEventListener("error",stage.$boundOnError),stage.$element=image,url&&(stage.url=url),stage}return __extends(Texture,_super),Object.defineProperty(Texture.prototype,"element",{get:function(){return this.$element},enumerable:!1,configurable:!0}),Object.defineProperty(Texture.prototype,"width",{get:function(){return this.$element.width/this.pixelRatio},enumerable:!1,configurable:!0}),Object.defineProperty(Texture.prototype,"height",{get:function(){return this.$element.height/this.pixelRatio},enumerable:!1,configurable:!0}),Texture.defaultPixelRatio=1,Texture}(Media),Texture$1=Object.freeze({__proto__:null,Texture:Texture}),ResourceManager=function(_super){function ResourceManager(stage,list,options){var _this=_super.call(this)||this;return _this.$errorCount=0,_this.$loadedCount=0,_this.$loadingCount=0,_this.$stage=stage,_this.threads=options&&options.threads||2,_this.timeout=options&&options.timeout||1e4,_this.retryTimes=options&&options.retryTimes||3,_this.$list=list.concat(),_this.$total=list.length,_this.$resources={},_this.$checkPendingTasks(),_this}return __extends(ResourceManager,_super),Object.defineProperty(ResourceManager.prototype,"total",{get:function(){return this.$total},enumerable:!1,configurable:!0}),Object.defineProperty(ResourceManager.prototype,"errorCount",{get:function(){return this.$errorCount},enumerable:!1,configurable:!0}),Object.defineProperty(ResourceManager.prototype,"loadedCount",{get:function(){return this.$loadedCount},enumerable:!1,configurable:!0}),ResourceManager.prototype.$checkPendingTasks=function(){this.$loadingCount<this.threads&&0<this.$list.length&&(++this.$loadingCount,this.$load(this.$list.shift(),1))},ResourceManager.prototype.$load=function(info,attempts){var timer,resource,_this=this,name=info.name,type=info.type,url=info.url,total=this.$total,stage=this.$stage,ticker=stage.ticker,resources=this.$resources,retryTimes=this.retryTimes,successCallback=function(){var errorCount=_this.$errorCount,loadedCount=++_this.$loadedCount,event=(--_this.$loadingCount,ticker.clearTimeout(timer),resource instanceof Request?resources[name]=resource.response:resource instanceof Media&&(resources[name]=resource),resource.off(Event.LOAD,successCallback),resource.off(Event.ERROR,errorCallback),Event.create(Event.PROGRESS,(loadedCount+errorCount)/total));_this.emit(event),event.release(),loadedCount+errorCount===total?_this.emit(Event.COMPLETE):_this.$checkPendingTasks()},errorCallback=function(){var loadedCount,errorCount;attempts<retryTimes?_this.$load(info,attempts+1):(--_this.$loadingCount,loadedCount=_this.$loadedCount,errorCount=++_this.$errorCount,resource instanceof Request?resources[name]=resource.response:resource instanceof Media&&(resources[name]=resource),_this.emit(Event.PROGRESS,(loadedCount+errorCount)/total),loadedCount+errorCount===total?_this.emit(Event.COMPLETE):_this.$checkPendingTasks()),ticker.clearTimeout(timer),resource.off(Event.LOAD,successCallback),resource.off(Event.ERROR,errorCallback)};if(type===ResourceManager.TYPE_TEXT)(resource=new Request(url,{responseType:"text"})).on(Event.LOAD,successCallback);else if(type===ResourceManager.TYPE_JSON)(resource=new Request(url,{responseType:"json"})).on(Event.LOAD,successCallback);else if(type===ResourceManager.TYPE_BINARY)(resource=new Request(url,{responseType:"arraybuffer"})).on(Event.LOAD,successCallback);else if(type===ResourceManager.TYPE_TEXTURE)(resource=new Texture(stage,url)).on(Event.LOAD,successCallback);else{if(type!==ResourceManager.TYPE_SOUND)throw new Error("Unsupported resource type: "+type);(resource=new Sound(stage,url)).on(Event.LOAD,successCallback)}resource.on(Event.ERROR,errorCallback),timer=ticker.setTimeout(errorCallback,this.timeout)},ResourceManager.prototype.has=function(name){return!!this.$resources[name]},ResourceManager.prototype.get=function(name){return this.$resources[name]},ResourceManager.TYPE_TEXT="text",ResourceManager.TYPE_JSON="json",ResourceManager.TYPE_BINARY="binary",ResourceManager.TYPE_TEXTURE="texture",ResourceManager.TYPE_SOUND="sound",ResourceManager}(EventEmitter),ResourceManager$1=Object.freeze({__proto__:null,ResourceManager:ResourceManager}),Stage=function(_super){function Stage(canvas){var _this=_super.call(this)||this;return _this.$drawCalls=0,_this.$activated=!1,_this.$scaleMode=Stage.SHOW_ALL,_this.$viewportWidth=0,_this.$viewportHeight=0,_this.$viewportBackground=null,_this.$renderBounds=Rectangle.create(),_this.$ticker=new Ticker(_this),_this.$elementEvents=[],_this.$viewportCanvas=canvas||document.createElement("canvas"),_this.$viewportContext=_this.$viewportCanvas.getContext("2d"),_this.$boundResizeViewportCanvas=_this.$resizeViewportCanvas.bind(_this),_this.$resizeViewportCanvas(),_this.$initEvents(),_this.width=320,_this.height=568,canvas||(_this.$viewportCanvas.style.top="0",_this.$viewportCanvas.style.left="0",_this.$viewportCanvas.style.position="fixed",document.body.appendChild(_this.$viewportCanvas)),_this}return __extends(Stage,_super),Object.defineProperty(Stage.prototype,"x",{get:function(){return 0},set:function(x){this.$x=0},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"y",{get:function(){return 0},set:function(y){this.$y=0},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"ticker",{get:function(){return this.$ticker},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"fps",{get:function(){return this.$ticker.fps},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"drawCalls",{get:function(){return this.$drawCalls},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"activated",{get:function(){return this.$activated},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"scaleMode",{get:function(){return this.$scaleMode},set:function(scaleMode){this.scaleMode!==scaleMode&&(this.$scaleMode=scaleMode,this.$resizeCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"viewportCanvas",{get:function(){return this.$viewportCanvas},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"viewportWidth",{get:function(){return this.$viewportWidth||this.$viewportCanvas.width/Layer.pixelRatio},set:function(width){this.$viewportWidth!==width&&(this.$viewportWidth=width,this.$resizeViewportCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"viewportHeight",{get:function(){return this.$viewportHeight||this.$viewportCanvas.height/Layer.pixelRatio},set:function(height){this.$viewportHeight!==height&&(this.$viewportHeight=height,this.$resizeViewportCanvas())},enumerable:!1,configurable:!0}),Object.defineProperty(Stage.prototype,"viewportBackground",{get:function(){return this.$viewportBackground},set:function(viewportBackground){this.$viewportBackground=viewportBackground,this.$viewportCanvas.style.background=viewportBackground},enumerable:!1,configurable:!0}),Stage.prototype.createResourceManager=function(list,options){return new ResourceManager(this,list,options)},Stage.prototype.removeSelf=function(){var canvas=this.$viewportCanvas;return canvas.parentElement&&canvas.parentElement.removeChild(canvas),this.$activated&&(this.$activated=!1,this.emit(Event.DEACTIVATE)),this.$stage&&this.$emitRemovedFromStage(),this.$removeElementEvents(),this},Stage.prototype.$initEvents=function(){for(var prefix,hiddenKey,resizeTimer,_this=this,ticker=this.$ticker,_i=0,prefixes_1=["","o","ms","moz","webkit"];_i<prefixes_1.length&&(hiddenKey=(prefix=prefixes_1[_i])?prefix+"Hidden":"hidden",void 0===document[hiddenKey]);_i++);this.$addTouchEventListeners(),this.$addElementEvent(window,"orientationchange",function(){ticker.clearTimeout(resizeTimer),resizeTimer=ticker.setTimeout(_this.$boundResizeViewportCanvas,100)}),this.$addElementEvent(window,prefix+"visibilitychange",function(){var hidden=document[hiddenKey];_this.$activated=!hidden,_this.emit(hidden?Event.DEACTIVATE:Event.ACTIVATE)}),this.on(Event.ENTER_FRAME,this.$render),setTimeout(function(){document[hiddenKey]||(_this.$activated=!0,_this.emit(Event.ACTIVATE)),_this.$emitAddedToStage(_this)})},Stage.prototype.$addElementEvent=function(target,type,listener,options){target.addEventListener(type,listener,options),this.$elementEvents.push({target:target,type:type,listener:listener})},Stage.prototype.$removeElementEvents=function(){for(var listeners=this.$elementEvents,_i=0,listeners_1=listeners;_i<listeners_1.length;_i++){var _a=listeners_1[_i],target=_a.target,type=_a.type,_a=_a.listener;target.removeEventListener(type,_a)}listeners.length=0},Stage.prototype.$addTouchEventListeners=function(){var touching_1,_this=this;void 0!==document.ontouchstart?(this.$addElementEvent(document,"touchstart",function(event){_this.$dispatchTouches(TouchEvent.TOUCH_START,event)}),this.$addElementEvent(document,"touchmove",function(event){_this.$dispatchTouches(TouchEvent.TOUCH_MOVE,event),event.preventDefault()},{passive:!1}),this.$addElementEvent(document,"touchend",function(event){_this.$dispatchTouches(TouchEvent.TOUCH_END,event),_this.$dispatchTouches(TouchEvent.TOUCH_TAP,event)}),this.$addElementEvent(document,"touchcancel",function(event){_this.$dispatchTouches(TouchEvent.TOUCH_CANCEL,event)})):(touching_1=!1,this.$addElementEvent(window,"mousedown",function(event){_this.$dispatchTouchEvent(TouchEvent.TOUCH_START,event.pageX,event.pageY,0),touching_1=!0}),this.$addElementEvent(window,"mousemove",function(event){touching_1&&_this.$dispatchTouchEvent(TouchEvent.TOUCH_MOVE,event.pageX,event.pageY,0)}),this.$addElementEvent(window,"mouseup",function(event){_this.$dispatchTouchEvent(TouchEvent.TOUCH_END,event.pageX,event.pageY,0),touching_1=!1}),this.$addElementEvent(window,"click",function(event){_this.$dispatchTouchEvent(TouchEvent.TOUCH_TAP,event.pageX,event.pageY,0)}),this.$addElementEvent(window,"blur",function(){_this.$dispatchTouchEvent(TouchEvent.TOUCH_CANCEL,0,0,0),touching_1=!1}))},Stage.prototype.$dispatchTouches=function(type,event){for(var touches=event.changedTouches,i=0,l=touches.length;i<l;++i){var touch=touches[i];this.$dispatchTouchEvent(type,touch.pageX,touch.pageY,touch.identifier)}},Stage.prototype.$dispatchTouchEvent=function(type,pageX,pageY,identifier){var event,height,bounds,pixelRatio,scrollX,width,scrollY;!this.$ticker.paused&&this.$visible&&this.touchable&&(event=TouchEvent.create(type),scrollX=window.scrollX||0,scrollY=window.scrollY||0,width=this.$canvas.width,height=this.$canvas.height,bounds=this.$renderBounds,pixelRatio=Layer.pixelRatio,scrollX=(pageX-scrollX-(pageX=this.$viewportCanvas.getBoundingClientRect()).left-bounds.x/pixelRatio)*width/bounds.width-this.$anchorX,width=(pageY-scrollY-pageX.top-bounds.y/pixelRatio)*height/bounds.height-this.$anchorY,pageY=this.$getTransform(),scrollY=Vector.create(scrollX,width).transform(pageY.invert()).subtract(this.$anchorX,this.$anchorY),!(pageX=this.$localHitTest(scrollY))&&type===TouchEvent.TOUCH_START||(event.localX=scrollY.x,event.localY=scrollY.y,event.targetX=event.stageX=scrollX,event.targetY=event.stageY=width,event.identifier=identifier,this.$emitTouchEvent(event,pageX)),event.release(),pageY.release(),scrollY.release())},Stage.prototype.$calculateRenderBounds=function(){var x=0,y=0,canvas=this.$canvas,width=canvas.width,canvas=canvas.height,scaleMode=this.$scaleMode,bounds=this.$renderBounds,aspectRatio=width/canvas,viewportCanvas=this.$viewportCanvas,viewportWidth=viewportCanvas.width,viewportCanvas=viewportCanvas.height,viewportAspectRatio=viewportWidth/viewportCanvas;scaleMode===Stage.SHOW_ALL?viewportAspectRatio<aspectRatio?canvas=(width=viewportWidth)/aspectRatio:width=(canvas=viewportCanvas)*aspectRatio:scaleMode===Stage.EXACT_FIT?(width=viewportWidth,canvas=viewportCanvas):scaleMode===Stage.NO_BORDER?(aspectRatio<viewportAspectRatio?canvas=(width=viewportWidth)/aspectRatio:width=(canvas=viewportCanvas)*aspectRatio,x=(viewportWidth-width)/2,y=(viewportCanvas-canvas)/2):scaleMode===Stage.FIXED_WIDTH?canvas=(width=viewportWidth)/aspectRatio:scaleMode===Stage.FIXED_HEIGHT?width=(canvas=viewportCanvas)*aspectRatio:scaleMode===Stage.FIXED_WIDE?viewportCanvas<viewportWidth?canvas=(width=viewportWidth)/aspectRatio:width=(canvas=viewportCanvas)*aspectRatio:scaleMode===Stage.FIXED_NARROW&&(viewportWidth<viewportCanvas?canvas=(width=viewportWidth)/aspectRatio:width=(canvas=viewportCanvas)*aspectRatio),canvas<viewportCanvas&&(y=(viewportCanvas-canvas)/2),bounds.x=x=width<viewportWidth?(viewportWidth-width)/2:x,bounds.y=y,bounds.width=width,bounds.height=canvas},Stage.prototype.$resizeCanvas=function(){_super.prototype.$resizeCanvas.call(this),this.$calculateRenderBounds()},Stage.prototype.$resizeViewportCanvas=function(){var canvas=this.$viewportCanvas,pixelRatio=Layer.pixelRatio,viewportWidth=this.$viewportWidth||window.innerWidth,viewportHeight=this.$viewportHeight||window.innerHeight,canvasWidth=viewportWidth*pixelRatio,pixelRatio=viewportHeight*pixelRatio;canvas.width===canvasWidth&&canvas.height===pixelRatio||(canvas.width=canvasWidth,canvas.height=pixelRatio,canvas.style.width=viewportWidth+"px",canvas.style.height=viewportHeight+"px",this.$calculateRenderBounds(),this.$markDirty(),this.emit(Event.VIEWPORT_RESIZE))},Stage.prototype.$render=function(){var drawCalls,canvas,ctx,bounds,viewportWidth,viewportCanvas;return this.$dirty?(drawCalls=_super.prototype.$render.call(this),canvas=this.$canvas,ctx=this.$viewportContext,bounds=this.$renderBounds,viewportWidth=(viewportCanvas=this.$viewportCanvas).width,viewportCanvas=viewportCanvas.height,ctx.clearRect(0,0,viewportWidth,viewportCanvas),ctx.drawImage(canvas,bounds.x+.5|0,bounds.y+.5|0,bounds.width+.5|0,bounds.height+.5|0),this.$drawCalls=++drawCalls,drawCalls):this.$drawCalls=0},Stage.SHOW_ALL="showAll",Stage.EXACT_FIT="exactFit",Stage.NO_SCALE="noScale",Stage.NO_BORDER="noBorder",Stage.FIXED_WIDE="fixedWide",Stage.FIXED_NARROW="fixedNarrow",Stage.FIXED_WIDTH="fixedWidth",Stage.FIXED_HEIGHT="fixedHeight",Stage}(Layer),Stage$1=Object.freeze({__proto__:null,Stage:Stage}),Ticker$1=__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({},Ticker$1),Layer$1),Scroller$1),Image$1),Text$1),Input$1),MovieClip$1),Stage$1),Event$1),TouchEvent$1),EventEmitter$1),Matrix$1),Vector$1),Rectangle$1),Media$1),Texture$1),Sound$1),Ease$1),Tween$1),Request$1),ResourceManager$1);exports.Ease=Ease,exports.Event=Event,exports.EventEmitter=EventEmitter,exports.Image=Image,exports.Input=Input,exports.Layer=Layer,exports.Matrix=Matrix,exports.Media=Media,exports.MovieClip=MovieClip,exports.Rectangle=Rectangle,exports.Request=Request,exports.ResourceManager=ResourceManager,exports.Scroller=Scroller,exports.Sound=Sound,exports.Stage=Stage,exports.Text=Text,exports.Texture=Texture,exports.Ticker=Ticker,exports.TouchEvent=TouchEvent,exports.Tween=Tween,exports.Vector=Vector,exports.default=Ticker$1,Object.defineProperty(exports,"__esModule",{value:!0})});