playable.js
Version:
A lightweight HTML5 game engine.
1 lines • 51.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).playable={})}(this,function(t){"use strict";class e{constructor(t,e=null){this.type=null,this.data=null,this.target=null,this.currentTarget=null,this.$init(t,e)}$init(t,e=null){return this.type=t,this.data=e,this}release(){this.type=null,this.data=null,e.recycle(this)}static create(t,i=null){let s=this.$pool;return s.length>0?s.pop().$init(t,i):new e(t,i)}static recycle(t){this.$pool.push(t)}}e.ADDED="added",e.REMOVED="removed",e.ADDED_TO_STAGE="addedToStage",e.REMOVED_FROM_STAGE="removeFromStage",e.ACTIVATE="activate",e.DEACTIVATE="deactivate",e.ENTER_FRAME="enterFrame",e.TICK="tick",e.TICKER_PAUSE="tickerPause",e.TICKER_RESUME="tickerResume",e.VIEWPORT_RESIZE="viewportResize",e.LOAD="load",e.ABORT="abort",e.ERROR="error",e.PROGRESS="progress",e.COMPLETE="complete",e.ENDED="ended",e.SOUND_COMPLETE="soundComplete",e.$pool=[];var i=Object.freeze({__proto__:null,Event:e});class s{constructor(){this.$events={},this.$emittingType=null,this.$removedListeners=[]}on(t,e){let i=this.$events[t]||[];return i.push(e),this.$events[t]=i,this}off(t,e){if(this.$emittingType===t&&e)this.$removedListeners.push(e);else{let i=this.$events[t]||[];if(e){let t=i.indexOf(e);t>=0&&i.splice(t,1)}else i.length=0}return this}once(t,e){let i=this,s=function(){e.apply(this,arguments),i.off(t,s)};return this.on(t,s)}emit(t,...i){let s;t instanceof e&&(i=[t],t.target=t.target||this,t.currentTarget=this,t=t.type);let h=this.$events[t],r=h&&h.length>0,n=this.$removedListeners;if(!s&&r&&0===i.length&&(s=e.create(t),s.target=this,s.currentTarget=this,i.push(s)),r){this.$emittingType=t;for(let t of h)n.indexOf(t)<0&&t.apply(this,i);this.$emittingType=null}s&&s.release();for(let e of n)this.off(t,e);return n.length=0,r}hasEventListener(t){let e=this.$events[t];return!!e&&e.length>0}removeAllListeners(){return this.$events={},this}}var h=Object.freeze({__proto__:null,EventEmitter:s});class r extends s{constructor(t){super(),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=t,this.$timers=[],this.$boundTick=this.$tick.bind(this),this.$enterFrameCallbackList=[t],this.$start()}get fps(){return this.$fps}get deltaTime(){return this.$deltaTime}get paused(){return this.$paused}$start(){let t=this.$stage,i=["","o","ms","moz","webkit"];for(let t of i){let e=t?t+"RequestAnimationFrame":"requestAnimationFrame",i=t?t+"CancelAnimationFrame":"cancelAnimationFrame",s=t?t+"CancelRequestAnimationFrame":"cancelRequestAnimationFrame";window.requestAnimationFrame=window.requestAnimationFrame||window[e],window.cancelAnimationFrame=window.cancelAnimationFrame||window[i]||window[s]}return window.requestAnimationFrame||(window.requestAnimationFrame=function(t){return window.setTimeout(t,1e3/60)},window.cancelAnimationFrame=function(t){window.clearTimeout(t)}),t.on(e.ACTIVATE,()=>{this.$shouldResume&&(this.resume(),this.$shouldResume=!1)}),t.on(e.DEACTIVATE,()=>{this.$paused||(this.pause(),this.$shouldResume=!0)}),t.activated?(this.$paused=!1,this.$tick()):this.$shouldResume=!0,this}pause(){return this.$paused||(this.$paused=!0,this.$lastTimestamp=0,this.emit(e.TICKER_PAUSE),cancelAnimationFrame(this.$tickHandle)),this}resume(){return this.$paused&&(this.$paused=!1,this.$tick(),this.emit(e.TICKER_RESUME)),this}setTimeout(t,e=0){let i=++this.$timerIndex;return this.$timers[i]={handler:t,timeout:e,resetTime:e},i}clearTimeout(t){delete this.$timers[t]}setInterval(t,e){let i=++this.$timerIndex;return this.$timers[i]={handler:t,timeout:e,resetTime:e,interval:!0},i}clearInterval(t){delete this.$timers[t]}registerEnterFrameCallback(t){let e=this.$enterFrameCallbackList;return e.indexOf(t)<0&&e.push(t),this}unregisterEnterFrameCallback(t){let e=this.$enterFrameCallbackList,i=e.indexOf(t);return i>=0&&e.splice(i,1),this}$tick(){let t=Date.now(),i=this.$lastTimestamp?t-this.$lastTimestamp:1e3/60,s=this.$enterFrameCallbackList;this.$fps=Math.round(1e3/i),this.$deltaTime=i,this.$lastTimestamp=t,this.$tickHandle=window.requestAnimationFrame(this.$boundTick),this.$checkTimers(i);let h=e.create(e.ENTER_FRAME,i);for(let t of s)t.emit(h);h.release();let r=e.create(e.TICK,i);this.emit(r),r.release()}$checkTimers(t){let e=this.$timers;for(let i in e){let s=e[i];(s.resetTime=s.resetTime-t)<=0&&(s.handler(),s.interval?s.resetTime+=s.timeout:this.clearTimeout(+i))}}}var n=Object.freeze({__proto__:null,Ticker:r});class a{constructor(t,e){this.set(t,e)}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get angle(){return Math.atan2(this.y,this.x)}set(t,e){return this.x=t||0,this.y=e||0,this}add(t,e){return t instanceof a?(this.x+=t.x,this.y+=t.y):(this.x+=t,this.y+=e),this}subtract(t,e){return t instanceof a?(this.x-=t.x,this.y-=t.y):(this.x-=t,this.y-=e),this}dotProduct(t,e){return t instanceof a?this.x*t.x+this.y*t.y:this.x*t+this.y*e}normalize(){let t=this.length;return this.x=this.x/t,this.y=this.y/t,this}negate(){return this.x*=-1,this.y*=-1,this}scale(t,e){return this.x*=t,this.y*=void 0===e?t:e,this}rotate(t){let e=this.x,i=this.y;return this.x=e*Math.cos(t)-i*Math.sin(t),this.y=e*Math.sin(t)+i*Math.cos(t),this}transform(t){let e=this.x,i=this.y;return this.x=t.a*e+t.c*i+t.tx,this.y=t.b*e+t.d*i+t.ty,this}distance(t){return Math.sqrt((this.x-t.x)*(this.x-t.x)+(this.y-t.y)*(this.y-t.y))}equal(t){return this.x===t.x&&this.y===t.y}release(){return a.recycle(this),this}static create(t,e){let i=this.$pool;return i.length>0?i.pop().set(t,e):new a(t,e)}static recycle(t){this.$pool.push(t)}}a.$pool=[];var o=Object.freeze({__proto__:null,Vector:a});class l{constructor(t,e,i,s,h,r){arguments.length>0?this.set(t,e,i,s,h,r):this.identity()}set(t,e,i,s,h,r){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=h,this.ty=r,this}identity(){return this.set(1,0,0,1,0,0)}invert(){let t=this.a,e=this.b,i=this.c,s=this.d,h=this.tx,r=this.ty,n=t*s-i*e;return this.a=s/n,this.b=-e/n,this.c=-i/n,this.d=t/n,this.tx=(i*r-s*h)/n,this.ty=(e*h-t*r)/n,this}prepend(t,e,i,s,h,r){if(t instanceof l)return this.prepend(t.a,t.b,t.c,t.d,t.tx,t.ty);let n=this.a,a=this.b,o=this.c,$=this.d,u=this.tx,c=this.ty;return this.a=t*n+e*o,this.b=t*a+e*$,this.c=i*n+s*o,this.d=i*a+s*$,this.tx=h*n+r*o+u,this.ty=h*a+r*$+c,this}append(t,e,i,s,h,r){if(t instanceof l)return this.append(t.a,t.b,t.c,t.d,t.tx,t.ty);let n=this.a,a=this.b,o=this.c,$=this.d,u=this.tx,c=this.ty;return this.a=t*n+i*a,this.b=e*n+s*a,this.c=t*o+i*$,this.d=e*o+s*$,this.tx=t*u+i*c+h,this.ty=e*u+s*c+r,this}scale(t,e){return this.append(t,0,0,void 0===e?t:e,0,0)}rotate(t){let e=Math.sin(t),i=Math.cos(t);return this.append(i,e,-e,i,0,0)}skew(t,e){return this.append(1,Math.tan(e),Math.tan(t),1,0,0)}translate(t,e){return t instanceof a?this.append(1,0,0,1,t.x,t.y):this.append(1,0,0,1,t,e)}equal(t){return t instanceof l&&this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.tx===t.tx&&this.ty===t.ty}release(){l.recycle(this)}static create(t,e,i,s,h,r){let n,a=this.$pool;return n=a.length>0?a.pop():new l,arguments.length?n.set(t,e,i,s,h,r):n.identity(),n}static recycle(t){this.$pool.push(t)}}l.$pool=[];var $=Object.freeze({__proto__:null,Matrix:l});class u{constructor(t,e,i,s){this.set(t,e,i,s)}get top(){return this.y}set top(t){this.height+=this.y-t,this.y=t}get bottom(){return this.y+this.height}set bottom(t){this.height=t-this.y}get left(){return this.x}set left(t){this.width+=this.x-t,this.x=t}get right(){return this.x+this.width}set right(t){this.width=t-this.x}get topLeft(){return a.create(this.left,this.top)}set topLeft(t){this.top=t.y,this.left=t.x}get bottomRight(){return a.create(this.right,this.bottom)}set bottomRight(t){this.bottom=t.y,this.right=t.x}set(t,e,i,s){return this.x=t||0,this.y=e||0,this.width=i||0,this.height=s||0,this}contains(t,e){return t instanceof a?this.contains(t.x,t.y):t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height}equal(t){return t instanceof u&&t.x===this.x&&t.y===this.y&&t.width===this.width&&t.height===this.height}release(){u.recycle(this)}static create(t,e,i,s){let h=this.$pool;return h.length>0?h.pop().set(t,e,i,s):new u(t,e,i,s)}static recycle(t){this.$pool.push(t)}}u.$pool=[];var c=Object.freeze({__proto__:null,Rectangle:u});class d extends e{constructor(t){super(t),this.$init(t)}$init(t){return this.type=t,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}stopPropagation(){this.cancelBubble=!0}release(){d.recycle(this)}static create(t){let e=this.$pool;return e.length>0?e.pop().$init(t):new d(t)}static recycle(t){this.$pool.push(t)}}d.TOUCH_START="touchStart",d.TOUCH_MOVE="touchMove",d.TOUCH_END="touchEnd",d.TOUCH_CANCEL="touchCancel",d.TOUCH_TAP="touchTap",d.$pool=[];var p=Object.freeze({__proto__:null,TouchEvent:d});class g extends s{constructor(){super(),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")}get x(){return this.$x}set x(t){this.$x!==t&&(this.$x=t,this.$markParentDirty())}get y(){return this.$y}set y(t){this.$y!==t&&(this.$y=t,this.$markParentDirty())}get width(){return this.$width?this.$width:this.$canvas.width/g.pixelRatio}set width(t){this.$width!==t&&(this.$width=t,this.$resizeCanvas())}get height(){return this.$height?this.$height:this.$canvas.height/g.pixelRatio}set height(t){this.$height!==t&&(this.$height=t,this.$resizeCanvas())}get anchorX(){return this.$anchorX}set anchorX(t){this.$anchorX!==t&&(this.$anchorX=t,this.$resizeCanvas())}get anchorY(){return this.$anchorY}set anchorY(t){this.$anchorY!==t&&(this.$anchorY=t,this.$resizeCanvas())}get skewX(){return this.$skewX}set skewX(t){this.$skewX!==t&&(this.$skewX=t,this.$markParentDirty())}get skewY(){return this.$skewY}set skewY(t){this.$skewY!==t&&(this.$skewY=t,this.$markParentDirty())}get scaleX(){return this.$scaleX}set scaleX(t){this.$scaleX!==t&&(this.$scaleX=t,this.$markParentDirty())}get scaleY(){return this.$scaleY}set scaleY(t){this.$scaleY!==t&&(this.$scaleY=t,this.$markParentDirty())}get rotation(){return this.$rotation}set rotation(t){this.$rotation!==t&&(this.$rotation=t,this.$markParentDirty())}get alpha(){return this.$alpha}set alpha(t){this.$alpha!==t&&(this.$alpha=t,this.$markParentDirty())}get visible(){return this.$visible}set visible(t){this.$visible!==t&&(this.$visible=t,this.$markParentDirty())}get smoothing(){return this.$smoothing}set smoothing(t){this.$smoothing=t,this.$resizeCanvas()}get background(){return this.$background}set background(t){this.$background!==t&&(this.$background=t,this.$markDirty())}get stage(){return this.$stage}get parent(){return this.$parent}get numChildren(){return this.$children.length}get ticker(){return this.$stage?this.$stage.ticker:null}get canvas(){return this.$canvas}addChild(t){return this.addChildAt(t,this.$children.length)}addChildAt(t,e){let i=this.$children;return t.$parent&&t.$parent.removeChild(t),(e<0||e>i.length)&&(e=i.length),t.$emitAdded(this),i.splice(e,0,t),this.$resizeCanvas(),this}replaceChild(t,e){let i=this.getChildIndex(t);return this.removeChildAt(i),this.addChildAt(e,i),this}getChildByName(t){let e=this.$children;for(let i of e)if(i.name===t)return i;return null}getChildrenByTag(t){let e=[],i=this.$children;for(let s of i)s.tag===t&&e.push(s);return e}getChildAt(t){return this.$children[t]||null}getChildIndex(t){return this.$children.indexOf(t)}hasChild(t){return this.getChildIndex(t)>=0}swapChildren(t,e){let i=this.getChildIndex(t),s=this.getChildIndex(e);return i>=0&&s>=0&&this.swapChildrenAt(i,s),this}swapChildrenAt(t,e){let i=this.$children[t],s=this.$children[e];return t!==e&&i&&s&&(this.$children[t]=s,this.$children[e]=i,this.$markDirty()),this}setChildIndex(t,e){let i=this.$children,s=this.getChildIndex(t);if(e<0?e=0:e>i.length&&(e=i.length),s>=0&&e>s){for(let t=s+1;t<=e;++t)i[t-1]=i[t];i[e]=t,this.$markDirty()}else if(s>=0&&e<s){for(let t=s-1;t>=e;--t)i[t+1]=i[t];i[e]=t,this.$markDirty()}return this}removeChild(t){let e=this.getChildIndex(t);return this.removeChildAt(e)}removeChildAt(t){let e=this.$children,i=e[t];return i&&(e.splice(t,1),i.$emitRemoved(),this.$resizeCanvas()),this}removeChildByName(t){let e=this.$children;for(let i=0,s=e.length;i<s;++i){if(e[i].name===t){this.removeChildAt(i);break}}return this}removeChildrenByTag(t){let e=this.$children;for(let i=e.length-1;i>=0;--i){e[i].tag===t&&this.removeChildAt(i)}return this}removeAllChildren(){let t=this.$children;for(let e of t)e.$emitRemoved();return this.$children.length=0,this.$resizeCanvas(),this}removeSelf(){return this.$parent&&this.$parent.removeChild(this),this}$markDirty(t){t?this.$resizeParentCanvas():this.$dirty||this.$markParentDirty(),this.$dirty=!0}$markParentDirty(){this.$parent&&this.$parent.$markDirty()}$resizeCanvas(){let t=this.$width,e=this.$height,i=this.$canvas,s=this.$anchorX,h=this.$anchorY,r=this.$context,n=this.$smoothing,a=g.pixelRatio;if(t&&e)i.width=t*a,i.height=e*a;else{let r=this.$getContentBounds();i.width=(t||r.right+s)*a,i.height=(e||r.bottom+h)*a,r.release()}r.imageSmoothingEnabled!==n&&(r.imageSmoothingEnabled=n),this.$markDirty(!0)}$resizeParentCanvas(){this.$parent&&this.$parent.$resizeCanvas()}$getTransform(){let t=Math.PI/180,e=l.create();return e.translate(-this.$anchorX,-this.$anchorY),e.skew(this.skewX*t,this.skewY*t),e.rotate(this.rotation*t),e.scale(this.scaleX,this.scaleY),e.translate(this.x,this.y),e}$getChildTransform(t){return t.$getTransform()}$getChildBounds(t){let e=t.width,i=t.height,s=u.create(),h=this.$getChildTransform(t),r=a.create(0,0).transform(h),n=a.create(e,0).transform(h),o=a.create(0,i).transform(h),l=a.create(e,i).transform(h),$=Math.min(r.x,n.x,o.x,l.x),c=Math.max(r.x,n.x,o.x,l.x),d=Math.min(r.y,n.y,o.y,l.y),p=Math.max(r.y,n.y,o.y,l.y);return s.top=d,s.bottom=p,s.left=$,s.right=c,h.release(),r.release(),n.release(),o.release(),l.release(),s}$getContentBounds(){let t,e=this.$children;for(let i of e)if(i.$visible){let e=this.$getChildBounds(i);t?(t.top=Math.min(t.top,e.top),t.bottom=Math.max(t.bottom,e.bottom),t.left=Math.min(t.left,e.left),t.right=Math.max(t.right,e.right),e.release()):t=e}return t=t||u.create(),t}$emitTouchEvent(t,e){let i=t.type,s=t.localX,h=t.localY,r=this.$touches,n=t.identifier;if(i===d.TOUCH_START)this.$shouldEmitTap=!0,r[n]=!0;else{if(!r[n])return!1;i!==d.TOUCH_TAP&&i!==d.TOUCH_CANCEL||(r[n]=!1)}i===d.TOUCH_MOVE&&(this.$shouldEmitTap=!1);let o=this.$children;for(let e=o.length-1;e>=0;--e){let r=o[e];if(!r.$visible||!r.touchable)continue;let n=this.$getChildTransform(r),l=a.create(s,h).transform(n.invert()).subtract(r.$anchorX,r.$anchorY),$=r.$localHitTest(l);if(l.release(),n.release(),($||i!==d.TOUCH_START)&&(t.target=r,t.localX=t.targetX=l.x,t.localY=t.targetY=l.y,r.$emitTouchEvent(t,$)))break}return!(i!==d.TOUCH_TAP||e&&this.$shouldEmitTap)||(t.cancelBubble||(t.localX=s,t.localY=h,this.emit(t)),!0)}$emitAdded(t){let i=t.$stage;this.$parent=t,this.emit(e.ADDED),i&&this.$emitAddedToStage(i)}$emitRemoved(){let t=this.$stage;this.$parent=null,this.emit(e.REMOVED),t&&this.$emitRemovedFromStage()}$emitAddedToStage(t){let i=this.$children;this.$stage=t,this.emit(e.ADDED_TO_STAGE),this.hasEventListener(e.ENTER_FRAME)&&t.ticker.registerEnterFrameCallback(this);for(let e of i)e.$emitAddedToStage(t)}$emitRemovedFromStage(){let t=this.$stage,i=this.$children;this.$stage=null,this.emit(e.REMOVED_FROM_STAGE),this.hasEventListener(e.ENTER_FRAME)&&t.ticker.unregisterEnterFrameCallback(this);for(let t of i)t.$emitRemovedFromStage()}$localHitTest(t){return t.x>=-this.anchorX&&t.x<=this.width-this.anchorX&&t.y>=-this.anchorY&&t.y<=this.height-this.anchorY}$isChildVisible(t){if(!(t.visible&&t.alpha&&t.width&&t.height))return!1;let e=-this.$anchorX,i=this.width+e,s=-this.$anchorY,h=this.height+s,r=this.$getChildBounds(t),n=r.left<=i&&r.right>=e&&r.top<=h&&r.bottom>=s;return r.release(),n}$drawChild(t){let e=this.$context,i=t.$canvas,s=t.width,h=t.height,r=g.pixelRatio,n=this.$getChildTransform(t).scale(r),a=t.$render(),o=e.globalAlpha;if(o!==t.alpha&&(e.globalAlpha=t.alpha),0===n.b&&0===n.c){let t=n.tx+.5|0,r=n.ty+.5|0;s=s*n.a+.5|0,h=h*n.d+.5|0,e.drawImage(i,t,r,s,h)}else e.save(),e.transform(n.a,n.b,n.c,n.d,n.tx,n.ty),e.drawImage(i,0,0,s,h),e.restore();return o!==t.alpha&&(e.globalAlpha=o),n.release(),a+1}$render(){if(!this.$dirty)return 0;let t=0,e=this.$context,i=this.$canvas,s=this.$children,h=i.width,r=i.height,n=this.$anchorX+.5|0,a=this.$anchorY+.5|0,o=this.$background,l=g.pixelRatio;e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,h,r),o&&(e.fillStyle=o,e.fillRect(0,0,h,r)),e.translate(n*l,a*l);for(let e of s)this.$isChildVisible(e)&&(t+=this.$drawChild(e));return this.$dirty=!1,t}on(t,i){if(super.on(t,i),t===e.ENTER_FRAME&&this.ticker)this.ticker.registerEnterFrameCallback(this);else if(t===e.ADDED&&this.$parent){let s=e.create(t);i.call(this,s),s.release()}else if(t===e.ADDED_TO_STAGE&&this.$stage){let s=e.create(t);i.call(this,s),s.release()}return this}off(t,i){return super.off(t,i),t===e.ENTER_FRAME&&!this.hasEventListener(e.ENTER_FRAME)&&this.ticker&&this.ticker.unregisterEnterFrameCallback(this),this}}g.pixelRatio="undefined"==typeof window?1:window.devicePixelRatio||1;var m=Object.freeze({__proto__:null,Layer:g});class f{static linear(t,e,i,s){return i*t/s+e}static easeInQuad(t,e,i,s){return i*(t/=s)*t+e}static easeOutQuad(t,e,i,s){return-i*(t/=s)*(t-2)+e}static easeInOutQuad(t,e,i,s){return(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e}static easeInCubic(t,e,i,s){return i*(t/=s)*t*t+e}static easeOutCubic(t,e,i,s){return i*((t=t/s-1)*t*t+1)+e}static easeInOutCubic(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e}static easeInQuart(t,e,i,s){return i*(t/=s)*t*t*t+e}static easeOutQuart(t,e,i,s){return-i*((t=t/s-1)*t*t*t-1)+e}static easeInOutQuart(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t+e:-i/2*((t-=2)*t*t*t-2)+e}static easeInQuint(t,e,i,s){return i*(t/=s)*t*t*t*t+e}static easeOutQuint(t,e,i,s){return i*((t=t/s-1)*t*t*t*t+1)+e}static easeInOutQuint(t,e,i,s){return(t/=s/2)<1?i/2*t*t*t*t*t+e:i/2*((t-=2)*t*t*t*t+2)+e}static easeInSine(t,e,i,s){return t===s?e+i:-i*Math.cos(t/s*(Math.PI/2))+i+e}static easeOutSine(t,e,i,s){return i*Math.sin(t/s*(Math.PI/2))+e}static easeInOutSine(t,e,i,s){return-i/2*(Math.cos(Math.PI*t/s)-1)+e}static easeInExpo(t,e,i,s){return 0===t?e:i*Math.pow(2,10*(t/s-1))+e}static easeOutExpo(t,e,i,s){return t===s?e+i:i*(1-Math.pow(2,-10*t/s))+e}static easeInOutExpo(t,e,i,s){return 0===t?e:t===s?e+i:(t/=s/2)<1?i/2*Math.pow(2,10*(t-1))+e:i/2*(2-Math.pow(2,-10*--t))+e}static easeInCirc(t,e,i,s){return-i*(Math.sqrt(1-(t/=s)*t)-1)+e}static easeOutCirc(t,e,i,s){return i*Math.sqrt(1-(t=t/s-1)*t)+e}static easeInOutCirc(t,e,i,s){return(t/=s/2)<1?-i/2*(Math.sqrt(1-t*t)-1)+e:i/2*(Math.sqrt(1-(t-=2)*t)+1)+e}static easeInElastic(t,e,i,s){let h=1.70158,r=0,n=i;return 0===t?e:1===(t/=s)?e+i:(r||(r=.3*s),n<Math.abs(i)?(n=i,h=r/4):h=r/(2*Math.PI)*Math.asin(i/n),-n*Math.pow(2,10*(t-=1))*Math.sin((t*s-h)*(2*Math.PI)/r)+e)}static easeOutElastic(t,e,i,s){let h=1.70158,r=0,n=i;return 0===t?e:1===(t/=s)?e+i:(r||(r=.3*s),n<Math.abs(i)?(n=i,h=r/4):h=r/(2*Math.PI)*Math.asin(i/n),n*Math.pow(2,-10*t)*Math.sin((t*s-h)*(2*Math.PI)/r)+i+e)}static easeInOutElastic(t,e,i,s){let h=1.70158,r=0,n=i;return 0===t?e:2==(t/=s/2)?e+i:(r||(r=s*(.3*1.5)),n<Math.abs(i)?(n=i,h=r/4):h=r/(2*Math.PI)*Math.asin(i/n),t<1?n*Math.pow(2,10*(t-=1))*Math.sin((t*s-h)*(2*Math.PI)/r)*-.5+e:n*Math.pow(2,-10*(t-=1))*Math.sin((t*s-h)*(2*Math.PI)/r)*.5+i+e)}static easeInBack(t,e,i,s,h=1.70158){return t===s?e+i:i*(t/=s)*t*((h+1)*t-h)+e}static easeOutBack(t,e,i,s,h=1.70158){return 0===t?e:i*((t=t/s-1)*t*((h+1)*t+h)+1)+e}static easeInOutBack(t,e,i,s,h=1.70158){return(t/=s/2)<1?i/2*(t*t*((1+(h*=1.525))*t-h))+e:i/2*((t-=2)*t*((1+(h*=1.525))*t+h)+2)+e}static easeInBounce(t,e,i,s){return i-f.easeOutBounce(s-t,0,i,s)+e}static easeOutBounce(t,e,i,s){return(t/=s)<1/2.75?i*(7.5625*t*t)+e:t<2/2.75?i*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?i*(7.5625*(t-=2.25/2.75)*t+.9375)+e:i*(7.5625*(t-=2.625/2.75)*t+.984375)+e}static easeInOutBounce(t,e,i,s){return t<s/2?.5*f.easeInBounce(2*t,0,i,s)+e:.5*f.easeOutBounce(2*t-s,0,i,s)+.5*i+e}}var v=Object.freeze({__proto__:null,Ease:f});class T extends s{constructor(t,e){super(),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=t,this.loop=!!e&&e.loop,this.$boundOnEnterFrame=this.$onEnterFrame.bind(this)}get paused(){return this.$paused}get stopped(){return this.$stopped}set(t){return this.$steps.push({type:"set",props:t}),this}to(t,e,i){return this.$steps.push({type:"to",duration:e,props:t,ease:i}),this}wait(t){return this.$steps.push({type:"wait",duration:t}),this}call(t){return this.$steps.push({type:"call",callback:t}),this}play(){return this.$stopped&&(this.resume(),T.$tweens.push(this)),this}pause(){return this.$paused=!0,this.$target.off(e.ENTER_FRAME,this.$boundOnEnterFrame),this}resume(){return this.$paused&&(this.$paused=!1,this.$stopped=!1,this.$target.on(e.ENTER_FRAME,this.$boundOnEnterFrame)),this}stop(){this.pause(),this.$stopped=!0;let t=T.$tweens.indexOf(this);return t>=0&&T.$tweens.splice(t,1),this}$onEnterFrame(t){this.$nextFrame(t.data)}$nextFrame(t){let e=this.loop,i=this.$steps,s=this.$steps.length,h=this.$stepIndex,r=this.$stepPosition+t,n=i[h],a=n.type,o=n.duration||0,l=n.props,$=n.ease||f.linear,u=n.callback;"set"===a?this.$setProps(l):"to"===a?this.$easeProps(h,l,r,o,$):"call"===a&&u.call(this.$target),r<o?this.$stepPosition=r:h+1<s?(this.$stepPosition=0,this.$stepIndex=h+1,this.$shouldSaveProps=!0,this.$setProps(l),this.$nextFrame(r-o)):e?(this.$stepIndex=0,this.$stepPosition=0,this.$shouldSaveProps=!0,this.$setProps(l),this.$nextFrame(r-o)):(this.$stepIndex=0,this.$stepPosition=0,this.$shouldSaveProps=!0,this.$setProps(l),this.pause())}$saveOriginalProps(t,e){let i=this.$target,s=this.$stepProps,h=s[t]=s[t]||{};for(let t in e)h[t]=i[t];this.$shouldSaveProps=!1}$easeProps(t,e,i,s,h){this.$shouldSaveProps&&this.$saveOriginalProps(t,e);let r=this.$target,n=this.$stepProps[t]||{};i>s&&(i=s);for(let t in e){let a=n[t],o=e[t]-a;r[t]=h(i,a,o,s)}}$setProps(t){let e=this.$target;for(let i in t)e[i]=t[i]}static get(t,e){return new T(t,e)}static pauseTweens(t){let e=this.$tweens;for(let i of e)i.$target===t&&i.pause()}static resumeTweens(t){let e=this.$tweens;for(let i of e)i.$target===t&&i.resume()}static removeTweens(t){let e=this.$tweens;for(let i=e.length-1;i>=0;--i){let s=e[i];s.$target===t&&s.stop()}}static removeAllTweens(){let t=this.$tweens;for(let e=t.length-1;e>=0;--e){t[e].stop()}}}T.$tweens=[];var x=Object.freeze({__proto__:null,Tween:T});class E extends g{constructor(){super(),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(d.TOUCH_START,this.$onTouchStart),this.on(d.TOUCH_MOVE,this.$onTouchMove),this.on(d.TOUCH_END,this.$onTouchEnd),this.on(d.TOUCH_CANCEL,this.$onTouchCancel)}get scrollTop(){return this.$scrollTop}set scrollTop(t){let e=this.$getContentBounds(),i=this.$scrollHeight-this.$height;(t=Math.max(0,Math.min(t,i)))!==this.$scrollTop&&(this.$scrollTop=t,this.$markDirty()),e.release()}get scrollLeft(){return this.$scrollLeft}set scrollLeft(t){let e=this.$getContentBounds(),i=this.$scrollWidth-this.width;(t=Math.max(0,Math.min(t,i)))!==this.$scrollLeft&&(this.$scrollLeft=t,this.$markDirty()),e.release()}get scrollWidth(){return this.$scrollWidth}get scrollHeight(){return this.$scrollHeight}$getChildTransform(t){let e=super.$getChildTransform(t);return e.translate(-this.$scrollLeft,-this.$scrollTop),e}$resizeCanvas(){super.$resizeCanvas();let t=this.$getContentBounds();this.$scrollWidth=this.$scrollLeft+t.right+this.$anchorX,this.$scrollHeight=this.$scrollTop+t.bottom+this.$anchorY,this.scrollTop=this.$scrollTop,this.scrollLeft=this.$scrollLeft}$onTouchStart(t){this.$touchingX=t.localX,this.$touchingY=t.localY,this.$velocitiesX.length=0,this.$velocitiesY.length=0,this.$touchingTime=Date.now(),this.$touchingId=t.identifier,this.$inertiaTween&&(this.$inertiaTween.pause(),this.$inertiaTween=null)}$onTouchMove(t){if(t.identifier!==this.$touchingId)return;let e=Date.now(),i=this.scrollTop,s=this.scrollLeft,h=e-this.$touchingTime,r=this.$velocitiesX,n=this.$velocitiesY,a=t.localX-this.$touchingX,o=t.localY-this.$touchingY,l=E.scrollingView||this;r.push(a/h),n.push(o/h),r.length>5&&(r.shift(),n.shift()),this.$touchingX=t.localX,this.$touchingY=t.localY,l===this&&(this.$touchingTime=e,this.scrollTop-=o,this.scrollLeft-=a,this.$scrollLeft===s&&this.$scrollTop===i||(E.scrollingView=this))}$onTouchEnd(t){if(t.identifier!==this.$touchingId)return;if(E.scrollingView!==this)return;E.scrollingView=null;let e=0,i=0,s=this.$scrollTop,h=this.$scrollLeft,r=this.$velocitiesX,n=this.$velocitiesY,a=r.length;for(let t=0;t<a;++t)e+=r[t],i+=n[t];let o=e/a,l=i/a,$=Math.abs(o),u=Math.abs(l);if($>.01||u>.01){let t=1e3*Math.max($,u,1);this.$inertiaTween=T.get(this).to({scrollTop:s-l*(u+1)*200,scrollLeft:h-o*($+1)*200},t,f.easeOutQuart).play()}this.$touchingId=null}$onTouchCancel(t){t.identifier===this.$touchingId&&(this.$touchingId=null)}$emitRemovedFromStage(){super.$emitRemovedFromStage(),this.$inertiaTween&&(this.$inertiaTween.pause(),this.$inertiaTween=null)}}var y=Object.freeze({__proto__:null,Scroller:E});class w extends g{constructor(t,e,i){super(),this.$texture=null,this.$fillMode=w.SCALE,this.$clipRect=null,this.$scale9Grid=null,this.$pattern=null,this.$boundOnTextureLoad=this.$onTextureLoad.bind(this),t&&(this.$width=e,this.$height=i,this.texture=t)}get texture(){return this.$texture}set texture(t){this.$texture&&this.$texture.off(e.LOAD,this.$boundOnTextureLoad),this.$texture=t,t?t.on(e.LOAD,this.$boundOnTextureLoad):(this.$updatePattern(),this.$resizeCanvas())}get fillMode(){return this.$fillMode}set fillMode(t){this.$fillMode=t,this.$updatePattern(),this.$markDirty()}get clipRect(){return this.$clipRect}set clipRect(t){this.$clipRect=t,this.$markDirty()}get scale9Grid(){return this.$scale9Grid}set scale9Grid(t){this.$scale9Grid=t,this.$markDirty()}$onTextureLoad(){this.$updatePattern(),this.$resizeCanvas(),this.$texture.off(e.LOAD,this.$boundOnTextureLoad)}$updatePattern(){let t=this.$width,e=this.$height,i=this.$texture,s=this.$fillMode;(t||e)&&i&&s&&s!==w.SCALE?this.$pattern=this.$context.createPattern(i.element,s):this.$pattern=null}$getContentBounds(){let t=this.$texture,e=this.$clipRect,i=super.$getContentBounds();return i.x=Math.min(i.left,-this.$anchorX),i.y=Math.min(i.top,-this.$anchorY),e?(i.width=Math.max(i.width,e.width),i.height=Math.max(i.height,e.height)):t&&(i.width=Math.max(i.width,t.width),i.height=Math.max(i.height,t.height)),i}$drawPattern(t,e,i,s){let h=this.$context,r=this.$texture,n=this.$pattern,a=g.pixelRatio/r.pixelRatio;1!==a&&h.scale(a,a),h.fillStyle=n,h.fillRect(t,e,i,s)}$drawTexture(t,e,i,s,h,r,n,a){if(i<=0||s<=0||n<=0||a<=0)return;let o=this.$context,l=this.$texture,$=l.pixelRatio;i>0&&s>0&&n>0&&a>0&&o.drawImage(l.element,t*$,e*$,i*$,s*$,h,r,n,a)}$render(){if(!this.$dirty)return 0;let t=this.$canvas,e=this.$anchorX,i=this.$anchorY,s=this.$texture,h=this.$pattern,r=this.$clipRect,n=this.$scale9Grid,a=super.$render(),o=g.pixelRatio,l=-e*o,$=-i*o,u=t.width,c=t.height,d=r?r.x:0,p=r?r.y:0,m=r?r.width:s?s.width:0,f=r?r.height:s?s.height:0;if(!s)return a;if(h)this.$drawPattern(l,$,u,c);else if(n){let t=d,s=p,h=n.x,r=n.y,a=t+h,l=s+r,$=n.width,g=n.height,v=a+$,T=l+g,x=m-h-$,E=f-r-g,y=-e*o,w=-i*o,C=h*o,b=r*o,O=y+C,R=w+b,k=u-(h+x)*o,_=c-(r+E)*o,A=O+k,S=R+_,M=u-C-k,L=c-b-_;this.$drawTexture(t,s,h,r,y,w,C,b),this.$drawTexture(a,s,$,r,O,w,k,b),this.$drawTexture(v,s,x,r,A,w,M,b),this.$drawTexture(t,l,h,g,y,R,C,_),this.$drawTexture(a,l,$,g,O,R,k,_),this.$drawTexture(v,l,x,g,A,R,M,_),this.$drawTexture(t,T,h,E,y,S,C,L),this.$drawTexture(a,T,$,E,O,S,k,L),this.$drawTexture(v,T,x,E,A,S,M,L)}else this.$drawTexture(d,p,m,f,l,$,u,c);return a}}w.SCALE="scale",w.REPEAT="repeat",w.REPEAT_X="repeat-x",w.REPEAT_Y="repeat-y";var C=Object.freeze({__proto__:null,Image:w});class b extends g{constructor(t,e={}){super(),this.$text="",this.$color="black",this.$fontSize=b.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=t||this.$text,this.$color=e.color||this.$color,this.$fontSize=e.fontSize||this.$fontSize,this.$fontStyle=e.fontStyle||this.$fontStyle,this.$fontWeight=e.fontWeight||this.$fontWeight,this.$textAlign=e.textAlign||this.$textAlign,this.$verticalAlign=e.verticalAlign||this.$verticalAlign,this.$lineHeight=e.lineHeight||this.$lineHeight,this.$strokeSize=e.strokeSize||this.$strokeSize,this.$strokeColor=e.strokeColor||this.$strokeColor,this.$fontFamily=e.fontFamily||this.$fontFamily,this.$multiline=e.multiline||this.$multiline,this.$breakWord=e.breakWord||this.$breakWord,this.$autoFitSize=e.autoFitSize||this.autoFitSize,this.$minFontSize=e.minFontSize||this.minFontSize,this.$resizeCanvas()}get text(){return this.$text}set text(t){this.$text=t,this.$resizeCanvas()}get color(){return this.$color}set color(t){this.$color=t,this.$markDirty()}get fontSize(){return this.$fontSize}set fontSize(t){this.$fontSize=t,this.$resizeCanvas()}get fontStyle(){return this.$fontStyle}set fontStyle(t){this.$fontStyle=t,this.$resizeCanvas()}get fontWeight(){return this.$fontWeight}set fontWeight(t){this.$fontWeight=t,this.$resizeCanvas()}get textAlign(){return this.$textAlign}set textAlign(t){this.$textAlign=t,this.$markDirty()}get verticalAlign(){return this.$verticalAlign}set verticalAlign(t){this.$verticalAlign=t,this.$markDirty()}get lineHeight(){return this.$lineHeight}set lineHeight(t){this.$lineHeight=t,this.$resizeCanvas()}get strokeSize(){return this.$strokeSize}set strokeSize(t){this.$strokeSize=t,this.$markDirty()}get strokeColor(){return this.$strokeColor}set strokeColor(t){this.$strokeColor=t,this.$markDirty()}get fontFamily(){return this.$fontFamily}set fontFamily(t){this.$fontFamily=t,this.$resizeCanvas()}get multiline(){return this.$multiline}set multiline(t){this.$multiline=t,this.$resizeCanvas()}get breakWord(){return this.$breakWord}set breakWord(t){this.$breakWord=t,this.$resizeCanvas()}get autoFitSize(){return this.$autoFitSize}set autoFitSize(t){this.$autoFitSize=t,this.$resizeCanvas()}get minFontSize(){return this.$minFontSize}set minFontSize(t){this.$minFontSize=t,this.$resizeCanvas()}$updateContext(){let t=this.$context,e=this.$fontStyle,i=this.$fontWeight,s=g.pixelRatio,h=(this.$explicitSize||this.$fontSize)*s+"px";t.font=e+" "+i+" "+h+" "+this.$fontFamily,t.textAlign=this.$textAlign,t.textBaseline="top",t.fillStyle=this.$color,t.lineWidth=this.$strokeSize*s,t.strokeStyle=this.$strokeColor}$divideUnits(){let t,e=this.$text,i=this.$breakWord,s=b.wordRe,h=b.boundaryRe;if(i)t=e.split("");else{let i=e.split(h);t=[];for(let e of i)s.test(e)?t.push(e):t=t.concat(e.split(""))}return t}$divideLines(){let t=this.$text;if(!this.$multiline)return void(this.$lines=[t]);if(!this.$width)return void(this.$lines=t.split("\n"));let e="",i=this.$context,s=this.$lines=[],h=this.$divideUnits(),r=this.$width*g.pixelRatio;this.$updateContext();for(let t of h){if("\n"===t){s.push(e),e="";continue}i.measureText(e+t).width<=r?e+=t:(e&&s.push(e),e=t)}s.push(e)}$resizeCanvas(){let t=this.$width,e=this.$height;if(this.$divideLines(),this.$autoFitSize&&(t||e)){let i=this.$minFontSize||1;for(this.$explicitSize=this.$fontSize;this.$explicitSize>i;){let i=this.$getContentBounds();if(!(t&&i.width>t||e&&i.height>e))break;--this.$explicitSize,i.release()}}super.$resizeCanvas()}$getContentBounds(){let t=this.$context,e=super.$getContentBounds(),i=this.$lines,s=this.$lineHeight,h=g.pixelRatio,r=this.$explicitSize||this.$fontSize;this.$updateContext();for(let s of i)e.width=Math.max(e.width,t.measureText(s).width/h);return e.height=Math.max(e.height,r*s*i.length),e}$render(){if(!this.$dirty)return 0;let t=0,e=0,i=this.width,s=this.height,h=this.anchorX,r=this.anchorY,n=this.$context,a=this.$lines,o=this.$color,l=this.$textAlign,$=this.$verticalAlign,u=this.$lineHeight,c=this.$strokeSize,d=this.$strokeColor,p=g.pixelRatio,m=this.$explicitSize||this.$fontSize,f=super.$render();this.$updateContext(),t="center"===l?i*p/2-h*p:"right"===l?i*p-h*p:-h*p,e="middle"===$?(s-m*u*(a.length-1)-m)*p/2-r*p:"bottom"===$?(s-m*u*(a.length-1)-m)*p-r*p:-r*p;for(let i of a)o&&n.fillText(i,t,e),c&&d&&n.strokeText(i,t,e),e+=m*u*p;return f}}b.defaultFontSize=16,b.wordRe=/\w+/,b.boundaryRe=/\b/;var O=Object.freeze({__proto__:null,Text:b});class R extends b{constructor(t,e={}){super("",e),this.$value="",this.$type="text",this.$maxLength=16777215,this.$placeholder="",this.$placeholderColor="#888",this.$explicitColor="black",this.$value=t||this.$value,this.$type=e.type||this.$type,this.$maxLength=e.maxLength||this.$maxLength,this.$placeholder=e.placeholder||this.$placeholder,this.$placeholderColor=e.placeholderColor||this.$placeholderColor,this.$boundFocus=this.focus.bind(this),this.$updateText(),this.on(d.TOUCH_TAP,this.$onTouchTap)}set text(t){}get value(){return this.$value}set value(t){this.$value=t,this.$updateText()}get type(){return this.$type}set type(t){this.$type=t,this.$updateText()}get color(){return this.$explicitColor}set color(t){this.$explicitColor=t,this.$value?this.$color=t:this.$color=this.$placeholderColor,this.$markDirty()}get maxLength(){return this.$maxLength}set maxLength(t){this.$maxLength=t}get placeholder(){return this.$placeholder}set placeholder(t){this.$placeholder=t,this.$updateText()}get placeholderColor(){return this.$placeholderColor}set placeholderColor(t){this.$placeholderColor=t,this.$markDirty()}selectAll(){let t=this.$updateElement();return this.focus(),t.selectionStart=0,t.selectionEnd=this.$value.length,this}focus(){let t=this.$updateElement();return t.style.display="block",t.value=this.$value,t.focus(),R.$focusedInput=this,this}blur(){let t=this.$updateElement();return t.style.display="none",t.blur(),R.$focusedInput===this&&(this.value=t.value,R.$focusedInput=null),this}$updateText(){let t,e=this.$type,i=this.$value;if("password"===e){t="";for(let e=0,s=i.length;e<s;++e)t+="•"}else t=i;this.$text=t||this.$placeholder,this.color=this.$explicitColor,this.$resizeCanvas()}$updateElement(){let t=this.$multiline&&"text"===this.$type?"textarea":"input",e=R.$getElement(t),i="input"===t;return i&&(e.type=this.$type),e.maxLength=this.$maxLength,e.placeholder=this.$placeholder,e.style.left="0",e.style.bottom="0",e.style.margin="0",e.style.width="100%",e.style.height=(i?this.$fontSize*this.$lineHeight+24:this.height)+"px",e.style.minHeight=i?"0":this.$fontSize*this.$lineHeight*5+12+"px",e.style.maxHeight="50%",e.style.padding="6px",e.style.border="none",e.style.resize="none",e.style.outline="none",e.style.position="fixed",e.style.boxSizing="border-box",e.style.color=this.$explicitColor,e.style.fontSize=this.$fontSize+"px",e.style.fontStyle=this.$fontStyle,e.style.fontFamily=this.$fontFamily,e.style.textAlign=this.$textAlign,e.style.lineHeight=this.$lineHeight+"",e.style.fontWeight=this.$fontWeight+"",e.style.wordBreak=this.$breakWord?"break-all":"normal",e.style.background=this.$background,e.style.boxShadow="0 0 8px #aaa",e}$markDirty(t){super.$markDirty(t),R.$focusedInput&&this.$updateElement()}$onTouchTap(){setTimeout(this.$boundFocus,100)}static $getElement(t){let e;return"input"===t?e=this.$inputElement:"textarea"===t&&(e=this.$textAreaElement),e||(e=document.createElement(t),e.style.display="none",document.body.appendChild(e),e.addEventListener("input",()=>{R.$focusedInput.value=e.value}),e.addEventListener("blur",()=>{R.$focusedInput.blur()}),"input"===t?(e.addEventListener("keydown",t=>{"Enter"!==t.key&&13!==t.keyCode||R.$focusedInput.blur()}),this.$inputElement=e):"textarea"===t&&(this.$textAreaElement=e)),e}}var k=Object.freeze({__proto__:null,Input:R});class _ extends w{constructor(t,e){super(t),this.$loop=!0,this.$interval=30,this.$paused=!1,this.$currentFrame=0,this.$frames=null,this.$frames=e,this.$boundNextFrame=this.nextFrame.bind(this),this.play()}get loop(){return this.$loop}set loop(t){this.$loop=t}get interval(){return this.$interval}set interval(t){this.$interval=t}get paused(){return this.$paused}get currentFrame(){return this.$currentFrame}get totalFrames(){return this.$frames.length}play(){return this.off(e.ADDED_TO_STAGE,this.play),this.gotoAndPlay(this.$currentFrame)}pause(){let t=this.ticker;return this.$paused=!0,t&&t.clearTimeout(this.$timer),this.off(e.ADDED_TO_STAGE,this.play),this}nextFrame(){return this.gotoAndPlay(this.$currentFrame+1)}gotoAndPlay(t){this.$paused=!1,this.$gotoFrame(t);let i=this.$loop,s=this.ticker,h=this.$frames,r=h.length,n=h[this.$currentFrame];if(n)return s?(s.clearTimeout(this.$timer),(t<r-1||i)&&(this.$timer=s.setTimeout(this.$boundNextFrame,n.interval||this.$interval))):this.on(e.ADDED_TO_STAGE,this.play),this}gotoAndStop(t){return this.$paused=!0,this.$gotoFrame(t),this}$gotoFrame(t){let e=this.$frames.length;(t<0||t>=e)&&(t=(t+e)%e),t<0&&(t=0);let i=this.$frames[t];i&&(this.$currentFrame=t,this.clipRect=i.clip,this.stage&&i.callback&&i.callback.call(this))}}var A=Object.freeze({__proto__:null,MovieClip:_});class S extends s{constructor(t,e){let i,s,h,r;super(),this.$xhr=new XMLHttpRequest;let n=this.$xhr;if(t instanceof Object&&(t=(e=t).url),e&&(t=e.url||t,i=e.method||"get",s=e.headers,h=e.data,r=e.responseType),h instanceof Object){let e=S.$getContentType(s);if("get"===i.toLowerCase()){let e=S.$getQueryString(h);t+=t.indexOf("?")<0?"?"+e:"&"+e}else"application/x-www-form-urlencoded"===e?h=S.$getQueryString(h):"application/json"===e&&(h=JSON.stringify(h))}n.open(i||"get",t),n.responseType=r,s&&Object.keys(s).forEach(t=>{n.setRequestHeader(t,s[t])}),n.addEventListener("abort",this.$onAbort.bind(this)),n.addEventListener("progress",this.$onProgress.bind(this)),n.addEventListener("readystatechange",this.$onReadyStateChange.bind(this)),n.send(h)}get status(){return this.$xhr.status}get response(){return this.$xhr.response}get responseHeaders(){let t={},e=this.$xhr.getAllResponseHeaders().split("\n");for(let i of e){let e=i.indexOf(":"),s=i.slice(0,e).trim(),h=i.slice(e+1).trim();t[s]?(Array.isArray(t[s])||(t[s]=[t[s]]),t[s].push(h)):s&&(t[s]=h)}return t}abort(){this.$xhr.abort()}$onAbort(){this.emit(e.ABORT)}$onProgress(t){if(t.lengthComputable){let i=e.create(e.PROGRESS,t.loaded/t.total);this.emit(i),i.release()}}$onReadyStateChange(t){let i=this.$xhr;if(4===i.readyState){if(i.status>=400||0===i.status)this.emit(e.ERROR,t);else{let t=e.create(e.LOAD,i.response);this.emit(t),t.release()}this.emit(e.COMPLETE)}}static $getContentType(t){for(let e in t)if("content-type"===e.toLowerCase())return t[e].toLowerCase();return null}static $getQueryString(t){return Object.keys(t).map(e=>e+"="+t[e]).join("&")}}var M=Object.freeze({__proto__:null,Request:S});class L extends s{constructor(t){super(),this.$loaded=!1,this.$errored=!1,this.$stage=t,this.$boundOnLoad=this.$onLoad.bind(this),this.$boundOnError=this.$onError.bind(this)}get element(){return this.$element}get url(){return this.$element.src||""}set url(t){this.$loaded=!1,this.$errored=!1,this.$element.src=t}on(t,i){if(super.on(t,i),t===e.LOAD&&this.$loaded){let s=e.create(t);i.call(this,s),s.release()}else if(t===e.ERROR&&this.$errored){let s=e.create(t);i.call(this,s),s.release()}return this}$onLoad(){this.$loaded=!0,this.emit(e.LOAD),this.$element.removeEventListener(e.LOAD,this.$boundOnLoad)}$onError(){this.$errored=!0,this.emit(e.ERROR),this.$element.removeEventListener(e.ERROR,this.$boundOnError)}}var z=Object.freeze({__proto__:null,Media:L});class F extends L{constructor(t,i){super(t),this.$loops=1,this.$startTime=0,this.$paused=!0;let s=document.createElement("audio");s.crossOrigin="*",s.addEventListener("canplaythrough",this.$boundOnLoad),s.addEventListener("error",this.$boundOnError),s.addEventListener("ended",this.$onEnded.bind(this)),this.$element=s,this.$boundOnTouch=this.$onTouch.bind(this),i&&(this.url=i),t.ticker.on(e.TICKER_PAUSE,this.$onTickerPause.bind(this)),t.ticker.on(e.TICKER_RESUME,this.$onTickerResume.bind(this)),t.on(e.REMOVED_FROM_STAGE,this.$onRemovedFromStage.bind(this))}get element(){return this.$element}get url(){return this.$element.src}set url(t){this.$paused=!0,this.$element.src=t,this.$element.load(),0===t.indexOf("data:")&&this.$stage.ticker.setTimeout(this.$boundOnLoad)}get volume(){return this.$element.volume}set volume(t){this.$element.volume=t}get paused(){return this.$paused}play(t=0,e=1){return this.$loops=e,this.$startTime=t,this.$element.currentTime=t,this.$paused=!1,this.$checkStatus(),this}stop(){return this.$paused=!0,this.$element.pause(),this}$checkOnTouch(){document.addEventListener("click",this.$boundOnTouch),document.addEventListener("touchend",this.$boundOnTouch)}$checkStatus(){let t=this.$element.play();t&&t.catch(),this.$paused&&this.$element.pause()}$onTouch(){this.$checkStatus(),document.removeEventListener("click",this.$boundOnTouch),document.removeEventListener("touchend",this.$boundOnTouch)}$onEnded(){this.emit(e.ENDED),1===this.$loops?(this.stop(),this.emit(e.SOUND_COMPLETE)):0===this.$loops?this.play(this.$startTime,0):this.play(this.$startTime,this.$loops-1)}$onTickerPause(){this.$paused||this.$element.pause()}$onTickerResume(){this.$paused||this.$checkStatus()}$onRemovedFromStage(){this.stop(),document.removeEventListener("click",this.$boundOnTouch),document.removeEventListener("touchend",this.$boundOnTouch)}$onLoad(){super.$onLoad();let t=this.$element.play();t?t.then(this.$checkStatus.bind(this)).catch(this.$checkOnTouch.bind(this)):this.$checkOnTouch()}}var D=Object.freeze({__proto__:null,Sound:F});class I extends L{constructor(t,e){super(t),this.pixelRatio=I.defaultPixelRatio;let i=document.createElement("img");i.crossOrigin="*",i.addEventListener("load",this.$boundOnLoad),i.addEventListener("error",this.$boundOnError),this.$element=i,e&&(this.url=e)}get element(){return this.$element}get width(){return this.$element.width/this.pixelRatio}get height(){return this.$element.height/this.pixelRatio}}I.defaultPixelRatio=1;var P=Object.freeze({__proto__:null,Texture:I});class H extends s{constructor(t,e,i){super(),this.$errorCount=0,this.$loadedCount=0,this.$loadingCount=0,this.$stage=t,this.threads=i&&i.threads||2,this.timeout=i&&i.timeout||1e4,this.retryTimes=i&&i.retryTimes||3,this.$list=e.concat(),this.$total=e.length,this.$resources={},this.$checkPendingTasks()}get total(){return this.$total}get errorCount(){return this.$errorCount}get loadedCount(){return this.$loadedCount}$checkPendingTasks(){this.$loadingCount<this.threads&&this.$list.length>0&&(++this.$loadingCount,this.$load(this.$list.shift(),1))}$load(t,i){let s,h,r=t.name,n=t.type,a=t.url,o=this.$total,l=this.$stage,$=l.ticker,u=this.$resources,c=this.retryTimes,d=()=>{let t=this.$errorCount,i=++this.$loadedCount;--this.$loadingCount,$.clearTimeout(s),h instanceof S?u[r]=h.response:h instanceof L&&(u[r]=h),h.off(e.LOAD,d),h.off(e.ERROR,p);let n=e.create(e.PROGRESS,(i+t)/o);this.emit(n),n.release(),i+t===o?this.emit(e.COMPLETE):this.$checkPendingTasks()},p=()=>{if(i<c)this.$load(t,i+1);else{--this.$loadingCount;let t=this.$loadedCount,i=++this.$errorCount;h instanceof S?u[r]=h.response:h instanceof L&&(u[r]=h),this.emit(e.PROGRESS,(t+i)/o),t+i===o?this.emit(e.COMPLETE):this.$checkPendingTasks()}$.clearTimeout(s),h.off(e.LOAD,d),h.off(e.ERROR,p)};if(n===H.TYPE_TEXT)h=new S(a,{responseType:"text"}),h.on(e.LOAD,d),h.on(e.ERROR,p);else if(n===H.TYPE_JSON)h=new S(a,{responseType:"json"}),h.on(e.LOAD,d),h.on(e.ERROR,p);else if(n===H.TYPE_BINARY)h=new S(a,{responseType:"arraybuffer"}),h.on(e.LOAD,d),h.on(e.ERROR,p);else if(n===H.TYPE_TEXTURE)h=new I(l,a),h.on(e.LOAD,d),h.on(e.ERROR,p);else{if(n!==H.TYPE_SOUND)throw new Error("Unsupported resource type: "+n);h=new F(l,a),h.on(e.LOAD,d),h.on(e.ERROR,p)}s=$.setTimeout(p,this.timeout)}has(t){return!!this.$resources[t]}get(t){return this.$resources[t]}}H.TYPE_TEXT="text",H.TYPE_JSON="json",H.TYPE_BINARY="binary",H.TYPE_TEXTURE="texture",H.TYPE_SOUND="sound";var X=Object.freeze({__proto__:null,ResourceManager:H});class Y extends g{constructor(t){super(),this.$drawCalls=0,this.$activated=!1,this.$scaleMode=Y.SHOW_ALL,this.$viewportWidth=0,this.$viewportHeight=0,this.$viewportBackground=null,this.$renderBounds=u.create(),this.$ticker=new r(this),this.$elementEvents=[],this.$viewportCanvas=t||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,t||(this.$viewportCanvas.style.top="0",this.$viewportCanvas.style.left="0",this.$viewportCanvas.style.position="fixed",document.body.appendChild(this.$viewportCanvas))}get x(){return 0}set x(t){this.$x=0}get y(){return 0}set y(t){this.$y=0}get ticker(){return this.$ticker}get fps(){return this.$ticker.fps}get drawCalls(){return this.$drawCalls}get activated(){return this.$activated}get scaleMode(){return this.$scaleMode}set scaleMode(t){this.scaleMode!==t&&(this.$scaleMode=t,this.$resizeCanvas())}get viewportCanvas(){return this.$viewportCanvas}get viewportWidth(){return this.$viewportWidth?this.$viewportWidth:this.$viewportCanvas.width/g.pixelRatio}set viewportWidth(t){this.$viewportWidth!==t&&(this.$viewportWidth=t,this.$resizeViewportCanvas())}get viewportHeight(){return this.$viewportHeight?this.$viewportHeight:this.$viewportCanvas.height/g.pixelRatio}set viewportHeight(t){this.$viewportHeight!==t&&(this.$viewportHeight=t,this.$resizeViewportCanvas())}get viewportBackground(){return this.$viewportBackground}set viewportBackground(t){this.$viewportBackground=t,this.$viewportCanvas.style.background=t}createResourceManager(t,e){return new H(this,t,e)}removeSelf(){let t=this.$viewportCanvas;return t.parentElement&&t.parentElement.removeChild(t),this.$activated&&(this.$activated=!1,this.emit(e.DEACTIVATE)),this.$stage&&this.$emitRemovedFromStage(),this.$removeElementEvents(),this}$initEvents(){let t,i,s,h=this.$ticker,r=["","o","ms","moz","webkit"];for(t of r)if(i=t?t+"Hidden":"hidden",void 0!==document[i])break;this.$addTouchEventListeners(),this.$addElementEvent(window,"orientationchange",()=>{h.clearTimeout(s),s=h.setTimeout(this.$boundResizeViewportCanvas,100)}),this.$addElementEvent(window,t+"visibilitychange",()=>{let t=document[i];this.$activated=!t,this.emit(t?e.DEACTIVATE:e.ACTIVATE)}),this.on(e.ENTER_FRAME,this.$render),setTimeout(()=>{document[i]||(this.$activated=!0,this.emit(e.ACTIVATE)),this.$emitAddedToStage(this)})}$addElementEvent(t,e,i,s){t.addEventListener(e,i,s),this.$elementEvents.push({target:t,type:e,listener:i})}$removeElementEvents(){let t=this.$elementEvents;for(let{target:e,type:i,listener:s}of t)e.removeEventListener(i,s);t.length=0}$addTouchEventListeners(){if(void 0!==document.ontouchstart)this.$addElementEvent(document,"touchstart",t=>{this.$dispatchTouches(d.TOUCH_START,t)}),this.$addElementEvent(document,"touchmove",t=>{this.$dispatchTouches(d.TOUCH_MOVE,t),t.preventDefault()},{passive:!1}),this.$addElementEvent(document,"touchend",t=>{this.$dispatchTouches(d.TOUCH_END,t),this.$dispatchTouches(d.TOUCH_TAP,t)}),this.$addElementEvent(document,"touchcancel",t=>{this.$dispatchTouches(d.TOUCH_CANCEL,t)});else{let t=!1;this.$addElementEvent(window,"mousedown",e=>{this.$dispatchTouchEvent(d.TOUCH_START,e.pageX,e.pageY,0),t=!0}),this.$addElementEvent(window,"mousemove",e=>{t&&this.$dispatchTouchEvent(d.TOUCH_MOVE,e.pageX,e.pageY,0)}),this.$addElementEvent(window,"mouseup",e=>{this.$dispatchTouchEvent(d.TOUCH_END,e.pageX,e.pageY,0),t=!1}),this.$addElementEvent(window,"click",t=>{this.$dispatchTouchEvent(d.TOUCH_TAP,t.pageX,t.pageY,0)}),this.$addElementEvent(window,"blur",()=>{this.$dispatchTouchEvent(d.TOUCH_CANCEL,0,0,0),t=!1})}}$dispatchTouches(t,e){let i=e.changedTouches;for(let e=0,s=i.length;e<s;++e){let s=i[e];this.$dispatchTouchEvent(t,s.pageX,s.pageY,s.identifier)}}$dispatchTouchEvent(t,e,i,s){if(this.$ticker.paused||!this.$visible||!this.touchable)return;let h=d.create(t),r=window.scrollX||0,n=window.scrollY||0,o=this.$canvas.width,l=this.$canvas.height,$=this.$renderBounds,u=g.pixelRatio,c=this.$viewportCanvas.getBoundingClientRect(),p=(e-r-c.left-$.x/u)*o/$.width-this.$anchorX,m=(i-n-c.top-$.y/u)*l/$.height-this.$anchorY,f=this.$getTransform(),v=a.create(p,m).transform(f.invert()).subtract(this.$anchorX,this.$anchorY),T=this.$localHitTest(v);(T||t!==d.TOUCH_START)&&(h.localX=v.x,h.localY=v.y,h.targetX=h.stageX=p,h.targetY=h.stageY=m,h.identifier=s,this.$emitTouchEvent(h,T)),h.release(),f.release(),v.release()}$calculateRenderBounds(){let t=0,e=0,i=this.$canvas,s=i.width,h=i.height,r=this.$scaleMode,n=this.$renderBounds,a=s/h,o=this.$viewportCanvas,l=o.width,$=o.height,u=l/$;r===Y.SHOW_ALL?a>u?(s=l,h=s/a):(h=$,s=h*a):r===Y.EXACT_FIT?(s=l,h=$):r===Y.NO_BORDER?(a<u?(s=l,h=s/a):(h=$,s=h*a),t=(l-s)/2,e=($-h)/2):r===Y.FIXED_WIDTH?(s=l,h=s/a):r===Y.FIXED_HEIGHT?(h=$,s=h*a):r===Y.FIXED_WIDE?