melonjs 10.7.0 → 10.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v10.7.0
2
+ * melonJS Game Engine - v10.7.1
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -27,4 +27,4 @@
27
27
  *
28
28
  * MIT License
29
29
  */
30
- function(){var t;HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var e=this;if(!e.ctx||!e.ctx.listener)return e;for(var i=e._howls.length-1;i>=0;i--)e._howls[i].stereo(t);return e},HowlerGlobal.prototype.pos=function(t,e,i){var r=this;return r.ctx&&r.ctx.listener?(e="number"!=typeof e?r._pos[1]:e,i="number"!=typeof i?r._pos[2]:i,"number"!=typeof t?r._pos:(r._pos=[t,e,i],void 0!==r.ctx.listener.positionX?(r.ctx.listener.positionX.setTargetAtTime(r._pos[0],Howler.ctx.currentTime,.1),r.ctx.listener.positionY.setTargetAtTime(r._pos[1],Howler.ctx.currentTime,.1),r.ctx.listener.positionZ.setTargetAtTime(r._pos[2],Howler.ctx.currentTime,.1)):r.ctx.listener.setPosition(r._pos[0],r._pos[1],r._pos[2]),r)):r},HowlerGlobal.prototype.orientation=function(t,e,i,r,o,n){var s=this;if(!s.ctx||!s.ctx.listener)return s;var a=s._orientation;return e="number"!=typeof e?a[1]:e,i="number"!=typeof i?a[2]:i,r="number"!=typeof r?a[3]:r,o="number"!=typeof o?a[4]:o,n="number"!=typeof n?a[5]:n,"number"!=typeof t?a:(s._orientation=[t,e,i,r,o,n],void 0!==s.ctx.listener.forwardX?(s.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),s.ctx.listener.forwardY.setTargetAtTime(e,Howler.ctx.currentTime,.1),s.ctx.listener.forwardZ.setTargetAtTime(i,Howler.ctx.currentTime,.1),s.ctx.listener.upX.setTargetAtTime(r,Howler.ctx.currentTime,.1),s.ctx.listener.upY.setTargetAtTime(o,Howler.ctx.currentTime,.1),s.ctx.listener.upZ.setTargetAtTime(n,Howler.ctx.currentTime,.1)):s.ctx.listener.setOrientation(t,e,i,r,o,n),s)},Howl.prototype.init=(t=Howl.prototype.init,function(e){var i=this;return i._orientation=e.orientation||[1,0,0],i._stereo=e.stereo||null,i._pos=e.pos||null,i._pannerAttr={coneInnerAngle:void 0!==e.coneInnerAngle?e.coneInnerAngle:360,coneOuterAngle:void 0!==e.coneOuterAngle?e.coneOuterAngle:360,coneOuterGain:void 0!==e.coneOuterGain?e.coneOuterGain:0,distanceModel:void 0!==e.distanceModel?e.distanceModel:"inverse",maxDistance:void 0!==e.maxDistance?e.maxDistance:1e4,panningModel:void 0!==e.panningModel?e.panningModel:"HRTF",refDistance:void 0!==e.refDistance?e.refDistance:1,rolloffFactor:void 0!==e.rolloffFactor?e.rolloffFactor:1},i._onstereo=e.onstereo?[{fn:e.onstereo}]:[],i._onpos=e.onpos?[{fn:e.onpos}]:[],i._onorientation=e.onorientation?[{fn:e.onorientation}]:[],t.call(this,e)}),Howl.prototype.stereo=function(t,i){var r=this;if(!r._webAudio)return r;if("loaded"!==r._state)return r._queue.push({event:"stereo",action:function(){r.stereo(t,i)}}),r;var o=void 0===Howler.ctx.createStereoPanner?"spatial":"stereo";if(void 0===i){if("number"!=typeof t)return r._stereo;r._stereo=t,r._pos=[t,0,0]}for(var n=r._getSoundIds(i),s=0;s<n.length;s++){var a=r._soundById(n[s]);if(a){if("number"!=typeof t)return a._stereo;a._stereo=t,a._pos=[t,0,0],a._node&&(a._pannerAttr.panningModel="equalpower",a._panner&&a._panner.pan||e(a,o),"spatial"===o?void 0!==a._panner.positionX?(a._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),a._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),a._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):a._panner.setPosition(t,0,0):a._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),r._emit("stereo",a._id)}}return r},Howl.prototype.pos=function(t,i,r,o){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"pos",action:function(){n.pos(t,i,r,o)}}),n;if(i="number"!=typeof i?0:i,r="number"!=typeof r?-.5:r,void 0===o){if("number"!=typeof t)return n._pos;n._pos=[t,i,r]}for(var s=n._getSoundIds(o),a=0;a<s.length;a++){var h=n._soundById(s[a]);if(h){if("number"!=typeof t)return h._pos;h._pos=[t,i,r],h._node&&(h._panner&&!h._panner.pan||e(h,"spatial"),void 0!==h._panner.positionX?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(r,Howler.ctx.currentTime)):h._panner.setPosition(t,i,r)),n._emit("pos",h._id)}}return n},Howl.prototype.orientation=function(t,i,r,o){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"orientation",action:function(){n.orientation(t,i,r,o)}}),n;if(i="number"!=typeof i?n._orientation[1]:i,r="number"!=typeof r?n._orientation[2]:r,void 0===o){if("number"!=typeof t)return n._orientation;n._orientation=[t,i,r]}for(var s=n._getSoundIds(o),a=0;a<s.length;a++){var h=n._soundById(s[a]);if(h){if("number"!=typeof t)return h._orientation;h._orientation=[t,i,r],h._node&&(h._panner||(h._pos||(h._pos=n._pos||[0,0,-.5]),e(h,"spatial")),void 0!==h._panner.orientationX?(h._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.orientationZ.setValueAtTime(r,Howler.ctx.currentTime)):h._panner.setOrientation(t,i,r)),n._emit("orientation",h._id)}}return n},Howl.prototype.pannerAttr=function(){var t,i,r,o=this,n=arguments;if(!o._webAudio)return o;if(0===n.length)return o._pannerAttr;if(1===n.length){if("object"!=typeof n[0])return(r=o._soundById(parseInt(n[0],10)))?r._pannerAttr:o._pannerAttr;t=n[0],void 0===i&&(t.pannerAttr||(t.pannerAttr={coneInnerAngle:t.coneInnerAngle,coneOuterAngle:t.coneOuterAngle,coneOuterGain:t.coneOuterGain,distanceModel:t.distanceModel,maxDistance:t.maxDistance,refDistance:t.refDistance,rolloffFactor:t.rolloffFactor,panningModel:t.panningModel}),o._pannerAttr={coneInnerAngle:void 0!==t.pannerAttr.coneInnerAngle?t.pannerAttr.coneInnerAngle:o._coneInnerAngle,coneOuterAngle:void 0!==t.pannerAttr.coneOuterAngle?t.pannerAttr.coneOuterAngle:o._coneOuterAngle,coneOuterGain:void 0!==t.pannerAttr.coneOuterGain?t.pannerAttr.coneOuterGain:o._coneOuterGain,distanceModel:void 0!==t.pannerAttr.distanceModel?t.pannerAttr.distanceModel:o._distanceModel,maxDistance:void 0!==t.pannerAttr.maxDistance?t.pannerAttr.maxDistance:o._maxDistance,refDistance:void 0!==t.pannerAttr.refDistance?t.pannerAttr.refDistance:o._refDistance,rolloffFactor:void 0!==t.pannerAttr.rolloffFactor?t.pannerAttr.rolloffFactor:o._rolloffFactor,panningModel:void 0!==t.pannerAttr.panningModel?t.pannerAttr.panningModel:o._panningModel})}else 2===n.length&&(t=n[0],i=parseInt(n[1],10));for(var s=o._getSoundIds(i),a=0;a<s.length;a++)if(r=o._soundById(s[a])){var h=r._pannerAttr;h={coneInnerAngle:void 0!==t.coneInnerAngle?t.coneInnerAngle:h.coneInnerAngle,coneOuterAngle:void 0!==t.coneOuterAngle?t.coneOuterAngle:h.coneOuterAngle,coneOuterGain:void 0!==t.coneOuterGain?t.coneOuterGain:h.coneOuterGain,distanceModel:void 0!==t.distanceModel?t.distanceModel:h.distanceModel,maxDistance:void 0!==t.maxDistance?t.maxDistance:h.maxDistance,refDistance:void 0!==t.refDistance?t.refDistance:h.refDistance,rolloffFactor:void 0!==t.rolloffFactor?t.rolloffFactor:h.rolloffFactor,panningModel:void 0!==t.panningModel?t.panningModel:h.panningModel};var l=r._panner;l?(l.coneInnerAngle=h.coneInnerAngle,l.coneOuterAngle=h.coneOuterAngle,l.coneOuterGain=h.coneOuterGain,l.distanceModel=h.distanceModel,l.maxDistance=h.maxDistance,l.refDistance=h.refDistance,l.rolloffFactor=h.rolloffFactor,l.panningModel=h.panningModel):(r._pos||(r._pos=o._pos||[0,0,-.5]),e(r,"spatial"))}return o},Sound.prototype.init=function(t){return function(){var e=this,i=e._parent;e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,t.call(this),e._stereo?i.stereo(e._stereo):e._pos&&i.pos(e._pos[0],e._pos[1],e._pos[2],e._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var e=this,i=e._parent;return e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,e._stereo?i.stereo(e._stereo):e._pos?i.pos(e._pos[0],e._pos[1],e._pos[2],e._id):e._panner&&(e._panner.disconnect(0),e._panner=void 0,i._refreshBuffer(e)),t.call(this)}}(Sound.prototype.reset);var e=function(t,e){"spatial"===(e=e||"spatial")?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,void 0!==t._panner.positionX?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),void 0!==t._panner.orientationX?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}}()}(howler);var ObservableVector2d=function(t){function e(e,i,r){if(void 0===e&&(e=0),void 0===i&&(i=0),t.call(this,e,i),void 0===r)throw new Error("undefined `onUpdate` callback");this.setCallback(r.onUpdate,r.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),this.setMuted(t,e),void 0!==i&&this.setCallback(i.onUpdate,i.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._x,this._y);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._x,this._y);this._y=e&&"y"in e?e.y:t},e.prototype._set=function(t,e){var i=this.onUpdate.call(this.scope,t,e,this._x,this._y);return i&&"x"in i&&"y"in i?(this._x=i.x,this._y=i.y):(this._x=t,this._y=e),this},e.prototype.setMuted=function(t,e){return this._x=t,this._y=e,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y)},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y)},e.prototype.scale=function(t,e){return this._set(this._x*t,this._y*(void 0!==e?e:t))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y)},e.prototype.div=function(t){return this._set(this._x/t,this._y/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y)},e.prototype.clamp=function(t,i){return new e(clamp(this.x,t,i),clamp(this.y,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e))},e.prototype.minV=function(t){return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y)},e.prototype.maxV=function(t){return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y))},e.prototype.negate=function(){return new e(-this._x,-this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y)},e.prototype.copy=function(t){return this._set(t.x,t.y)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},e.prototype.perp=function(){return this._set(this._y,-this._x)},e.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this._x-i,n=this._y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r)},e.prototype.dot=function(t){return this._x*t.x+this._y*t.y},e.prototype.cross=function(t){return this._x*t.y-this._y*t.x},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this},e.prototype.distance=function(t){return Math.sqrt((this._x-t.x)*(this._x-t.x)+(this._y-t.y)*(this._y-t.y))},e.prototype.clone=function(){return pull("ObservableVector2d",this._x,this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.toVector2d=function(){return pull("Vector2d",this._x,this._y)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y},Object.defineProperties(e.prototype,i),e}(Vector2d),Vector3d=function(t,e,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.onResetEvent(t,e,i)};Vector3d.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype._set=function(t,e,i){return void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype.set=function(t,e,i){if(t!==+t||e!==+e||void 0!==i&&i!==+i)throw new Error("invalid x, y, z parameters (not a number)");return this._set(t,e,i)},Vector3d.prototype.setZero=function(){return this.set(0,0,0)},Vector3d.prototype.setV=function(t){return this._set(t.x,t.y,t.z)},Vector3d.prototype.add=function(t){return this._set(this.x+t.x,this.y+t.y,this.z+(t.z||0))},Vector3d.prototype.sub=function(t){return this._set(this.x-t.x,this.y-t.y,this.z-(t.z||0))},Vector3d.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this.x*t,this.y*e,this.z*(i||1))},Vector3d.prototype.scaleV=function(t){return this.scale(t.x,t.y,t.z)},Vector3d.prototype.toIso=function(){return this._set(this.x-this.y,.5*(this.x+this.y),this.z)},Vector3d.prototype.to2d=function(){return this._set(this.y+this.x/2,this.y-this.x/2,this.z)},Vector3d.prototype.div=function(t){return this._set(this.x/t,this.y/t,this.z/t)},Vector3d.prototype.abs=function(){return this._set(this.x<0?-this.x:this.x,this.y<0?-this.y:this.y,this.z<0?-this.z:this.z)},Vector3d.prototype.clamp=function(t,e){return new Vector3d(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.clampSelf=function(t,e){return this._set(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.minV=function(t){var e=t.z||0;return this._set(this.x<t.x?this.x:t.x,this.y<t.y?this.y:t.y,this.z<e?this.z:e)},Vector3d.prototype.maxV=function(t){var e=t.z||0;return this._set(this.x>t.x?this.x:t.x,this.y>t.y?this.y:t.y,this.z>e?this.z:e)},Vector3d.prototype.floor=function(){return new Vector3d(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.floorSelf=function(){return this._set(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.ceil=function(){return new Vector3d(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.ceilSelf=function(){return this._set(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.negate=function(){return new Vector3d(-this.x,-this.y,-this.z)},Vector3d.prototype.negateSelf=function(){return this._set(-this.x,-this.y,-this.z)},Vector3d.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},Vector3d.prototype.equals=function(){var t,e,i;return arguments.length>=2?(t=arguments[0],e=arguments[1],i=arguments[2]):(t=arguments[0].x,e=arguments[0].y,i=arguments[0].z),void 0===i&&(i=this.z),this.x===t&&this.y===e&&this.z===i},Vector3d.prototype.normalize=function(){return this.div(this.length()||1)},Vector3d.prototype.perp=function(){return this._set(this.y,-this.x,this.z)},Vector3d.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this.x-i,n=this.y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r,this.z)},Vector3d.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*(void 0!==t.z?t.z:this.z)},Vector3d.prototype.cross=function(t){var e=this.x,i=this.y,r=this.z,o=t.x,n=t.y,s=t.z;return this.x=i*s-r*n,this.y=r*o-e*s,this.z=e*n-i*o,this},Vector3d.prototype.length2=function(){return this.dot(this)},Vector3d.prototype.length=function(){return Math.sqrt(this.length2())},Vector3d.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},Vector3d.prototype.distance=function(t){var e=this.x-t.x,i=this.y-t.y,r=this.z-(t.z||0);return Math.sqrt(e*e+i*i+r*r)},Vector3d.prototype.angle=function(t){return Math.acos(clamp(this.dot(t)/(this.length()*t.length()),-1,1))},Vector3d.prototype.project=function(t){var e=this.dot(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.projectN=function(t){var e=this.dot(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.clone=function(){return pull("Vector3d",this.x,this.y,this.z)},Vector3d.prototype.toString=function(){return"x:"+this.x+",y:"+this.y+",z:"+this.z};var ObservableVector3d=function(t){function e(e,i,r,o){if(void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=0),t.call(this,e,i,r),void 0===o)throw new Error("undefined `onUpdate` callback");this.setCallback(o.onUpdate,o.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0},z:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,r){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.setMuted(t,e,i),void 0!==r&&this.setCallback(r.onUpdate,r.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._z,this._x,this._y,this._z);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._z,this._x,this._y,this._z);this._y=e&&"y"in e?e.y:t},i.z.get=function(){return this._z},i.z.set=function(t){var e=this.onUpdate.call(this.scope,this._x,this._y,t,this._x,this._y,this._z);this._z=e&&"z"in e?e.z:t},e.prototype._set=function(t,e,i){var r=this.onUpdate.call(this.scope,t,e,i,this._x,this._y,this._z);return r&&"x"in r&&"y"in r&&"z"in r?(this._x=r.x,this._y=r.y,this._z=r.z):(this._x=t,this._y=e,this._z=i||0),this},e.prototype.setMuted=function(t,e,i){return this._x=t,this._y=e,this._z=i||0,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y,this._z+(t.z||0))},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y,this._z-(t.z||0))},e.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this._x*t,this._y*e,this._z*(i||1))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y,this._z*(t.z||1))},e.prototype.div=function(t){return this._set(this._x/t,this._y/t,this._z/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y,this._Z<0?-this._z:this._z)},e.prototype.clamp=function(t,i){return new e(clamp(this._x,t,i),clamp(this._y,t,i),clamp(this._z,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e),clamp(this._z,t,e))},e.prototype.minV=function(t){var e=t.z||0;return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y,this._z<e?this._z:e)},e.prototype.maxV=function(t){var e=t.z||0;return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y,this._z>e?this._z:e)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z))},e.prototype.negate=function(){return new e(-this._x,-this._y,-this._z,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y,-this._z)},e.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y&&this._z===(t.z||this._z)},e.prototype.perp=function(){return this._set(this._y,-this._x,this._z)},e.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this.x-i,n=this.y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r,this.z)},e.prototype.dot=function(t){return this._x*t.x+this._y*t.y+this._z*(t.z||1)},e.prototype.cross=function(t){var e=this._x,i=this._y,r=this._z,o=t.x,n=t.y,s=t.z;return this._set(i*s-r*n,r*o-e*s,e*n-i*o)},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this._z+=(t.z-this._z)*e,this},e.prototype.distance=function(t){var e=this._x-t.x,i=this._y-t.y,r=this._z-(t.z||0);return Math.sqrt(e*e+i*i+r*r)},e.prototype.clone=function(){return pull("ObservableVector3d",this._x,this._y,this._z,{onUpdate:this.onUpdate})},e.prototype.toVector3d=function(){return pull("Vector3d",this._x,this._y,this._z)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y+",z:"+this._z},Object.defineProperties(e.prototype,i),e}(Vector3d),earcut$1={exports:{}};function earcut(t,e,i){i=i||2;var r,o,n,s,a,h,l,c=e&&e.length,u=c?e[0]*i:t.length,d=linkedList(t,0,u,i,!0),p=[];if(!d||d.next===d.prev)return p;if(c&&(d=eliminateHoles(t,e,d,i)),t.length>80*i){r=n=t[0],o=s=t[1];for(var f=i;f<u;f+=i)(a=t[f])<r&&(r=a),(h=t[f+1])<o&&(o=h),a>n&&(n=a),h>s&&(s=h);l=0!==(l=Math.max(n-r,s-o))?1/l:0}return earcutLinked(d,p,i,r,o,l),p}function linkedList(t,e,i,r,o){var n,s;if(o===signedArea(t,e,i,r)>0)for(n=e;n<i;n+=r)s=insertNode(n,t[n],t[n+1],s);else for(n=i-r;n>=e;n-=r)s=insertNode(n,t[n],t[n+1],s);return s&&equals(s,s.next)&&(removeNode(s),s=s.next),s}function filterPoints(t,e){if(!t)return t;e||(e=t);var i,r=t;do{if(i=!1,r.steiner||!equals(r,r.next)&&0!==area(r.prev,r,r.next))r=r.next;else{if(removeNode(r),(r=e=r.prev)===r.next)break;i=!0}}while(i||r!==e);return e}function earcutLinked(t,e,i,r,o,n,s){if(t){!s&&n&&indexCurve(t,r,o,n);for(var a,h,l=t;t.prev!==t.next;)if(a=t.prev,h=t.next,n?isEarHashed(t,r,o,n):isEar(t))e.push(a.i/i),e.push(t.i/i),e.push(h.i/i),removeNode(t),t=h.next,l=h.next;else if((t=h)===l){s?1===s?earcutLinked(t=cureLocalIntersections(filterPoints(t),e,i),e,i,r,o,n,2):2===s&&splitEarcut(t,e,i,r,o,n):earcutLinked(filterPoints(t),e,i,r,o,n,1);break}}}function isEar(t){var e=t.prev,i=t,r=t.next;if(area(e,i,r)>=0)return!1;for(var o=t.next.next;o!==t.prev;){if(pointInTriangle(e.x,e.y,i.x,i.y,r.x,r.y,o.x,o.y)&&area(o.prev,o,o.next)>=0)return!1;o=o.next}return!0}function isEarHashed(t,e,i,r){var o=t.prev,n=t,s=t.next;if(area(o,n,s)>=0)return!1;for(var a=o.x<n.x?o.x<s.x?o.x:s.x:n.x<s.x?n.x:s.x,h=o.y<n.y?o.y<s.y?o.y:s.y:n.y<s.y?n.y:s.y,l=o.x>n.x?o.x>s.x?o.x:s.x:n.x>s.x?n.x:s.x,c=o.y>n.y?o.y>s.y?o.y:s.y:n.y>s.y?n.y:s.y,u=zOrder(a,h,e,i,r),d=zOrder(l,c,e,i,r),p=t.prevZ,f=t.nextZ;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function cureLocalIntersections(t,e,i){var r=t;do{var o=r.prev,n=r.next.next;!equals(o,n)&&intersects(o,r,r.next,n)&&locallyInside(o,n)&&locallyInside(n,o)&&(e.push(o.i/i),e.push(r.i/i),e.push(n.i/i),removeNode(r),removeNode(r.next),r=t=n),r=r.next}while(r!==t);return filterPoints(r)}function splitEarcut(t,e,i,r,o,n){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&isValidDiagonal(s,a)){var h=splitPolygon(s,a);return s=filterPoints(s,s.next),h=filterPoints(h,h.next),earcutLinked(s,e,i,r,o,n),void earcutLinked(h,e,i,r,o,n)}a=a.next}s=s.next}while(s!==t)}function eliminateHoles(t,e,i,r){var o,n,s,a=[];for(o=0,n=e.length;o<n;o++)(s=linkedList(t,e[o]*r,o<n-1?e[o+1]*r:t.length,r,!1))===s.next&&(s.steiner=!0),a.push(getLeftmost(s));for(a.sort(compareX),o=0;o<a.length;o++)i=filterPoints(i=eliminateHole(a[o],i),i.next);return i}function compareX(t,e){return t.x-e.x}function eliminateHole(t,e){var i=findHoleBridge(t,e);if(!i)return e;var r=splitPolygon(i,t),o=filterPoints(i,i.next);return filterPoints(r,r.next),e===i?o:e}function findHoleBridge(t,e){var i,r=e,o=t.x,n=t.y,s=-1/0;do{if(n<=r.y&&n>=r.next.y&&r.next.y!==r.y){var a=r.x+(n-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=o&&a>s){if(s=a,a===o){if(n===r.y)return r;if(n===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==e);if(!i)return null;if(o===s)return i;var h,l=i,c=i.x,u=i.y,d=1/0;r=i;do{o>=r.x&&r.x>=c&&o!==r.x&&pointInTriangle(n<u?o:s,n,c,u,n<u?s:o,n,r.x,r.y)&&(h=Math.abs(n-r.y)/(o-r.x),locallyInside(r,t)&&(h<d||h===d&&(r.x>i.x||r.x===i.x&&sectorContainsSector(i,r)))&&(i=r,d=h)),r=r.next}while(r!==l);return i}function sectorContainsSector(t,e){return area(t.prev,t,e.prev)<0&&area(e.next,t,t.next)<0}function indexCurve(t,e,i,r){var o=t;do{null===o.z&&(o.z=zOrder(o.x,o.y,e,i,r)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,sortLinked(o)}function sortLinked(t){var e,i,r,o,n,s,a,h,l=1;do{for(i=t,t=null,n=null,s=0;i;){for(s++,r=i,a=0,e=0;e<l&&(a++,r=r.nextZ);e++);for(h=l;a>0||h>0&&r;)0!==a&&(0===h||!r||i.z<=r.z)?(o=i,i=i.nextZ,a--):(o=r,r=r.nextZ,h--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;i=r}n.nextZ=null,l*=2}while(s>1);return t}function zOrder(t,e,i,r,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*o)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-r)*o)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function getLeftmost(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function pointInTriangle(t,e,i,r,o,n,s,a){return(o-s)*(e-a)-(t-s)*(n-a)>=0&&(t-s)*(r-a)-(i-s)*(e-a)>=0&&(i-s)*(n-a)-(o-s)*(r-a)>=0}function isValidDiagonal(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!intersectsPolygon(t,e)&&(locallyInside(t,e)&&locallyInside(e,t)&&middleInside(t,e)&&(area(t.prev,t,e.prev)||area(t,e.prev,e))||equals(t,e)&&area(t.prev,t,t.next)>0&&area(e.prev,e,e.next)>0)}function area(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function equals(t,e){return t.x===e.x&&t.y===e.y}function intersects(t,e,i,r){var o=sign(area(t,e,i)),n=sign(area(t,e,r)),s=sign(area(i,r,t)),a=sign(area(i,r,e));return o!==n&&s!==a||(!(0!==o||!onSegment(t,i,e))||(!(0!==n||!onSegment(t,r,e))||(!(0!==s||!onSegment(i,t,r))||!(0!==a||!onSegment(i,e,r)))))}function onSegment(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function sign(t){return t>0?1:t<0?-1:0}function intersectsPolygon(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&intersects(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}function locallyInside(t,e){return area(t.prev,t,t.next)<0?area(t,e,t.next)>=0&&area(t,t.prev,e)>=0:area(t,e,t.prev)<0||area(t,t.next,e)<0}function middleInside(t,e){var i=t,r=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&o<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==t);return r}function splitPolygon(t,e){var i=new Node$1(t.i,t.x,t.y),r=new Node$1(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,i.next=o,o.prev=i,r.next=i,i.prev=r,n.next=r,r.prev=n,r}function insertNode(t,e,i,r){var o=new Node$1(t,e,i);return r?(o.next=r.next,o.prev=r,r.next.prev=o,r.next=o):(o.prev=o,o.next=o),o}function removeNode(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Node$1(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function signedArea(t,e,i,r){for(var o=0,n=e,s=i-r;n<i;n+=r)o+=(t[s]-t[n])*(t[n+1]+t[s+1]),s=n;return o}earcut$1.exports=earcut,earcut$1.exports.default=earcut,earcut.deviation=function(t,e,i,r){var o=e&&e.length,n=o?e[0]*i:t.length,s=Math.abs(signedArea(t,0,n,i));if(o)for(var a=0,h=e.length;a<h;a++){var l=e[a]*i,c=a<h-1?e[a+1]*i:t.length;s-=Math.abs(signedArea(t,l,c,i))}var u=0;for(a=0;a<r.length;a+=3){var d=r[a]*i,p=r[a+1]*i,f=r[a+2]*i;u+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===s&&0===u?0:Math.abs((u-s)/s)},earcut.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},r=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var s=0;s<e;s++)i.vertices.push(t[o][n][s]);o>0&&(r+=t[o-1].length,i.holes.push(r))}return i};var Polygon=function(t,e,i){this.pos=new Vector2d,this._bounds,this.points=[],this.edges=[],this.indices=[],this.normals=[],this.shapeType="Polygon",this.setShape(t,e,i)};Polygon.prototype.onResetEvent=function(t,e,i){this.setShape(t,e,i)},Polygon.prototype.setShape=function(t,e,i){return this.pos.set(t,e),this.setVertices(i),this},Polygon.prototype.setVertices=function(t){var e=this;if(!Array.isArray(t))return this;if(t[0]instanceof Vector2d)this.points=t;else if(this.points.length=0,"object"==typeof t[0])t.forEach((function(t){e.points.push(new Vector2d(t.x,t.y))}));else for(var i=0;i<t.length;i+=2)this.points.push(new Vector2d(t[i],t[i+1]));return this.recalc(),this.updateBounds(),this},Polygon.prototype.transform=function(t){for(var e=this.points,i=e.length,r=0;r<i;r++)t.apply(e[r]);return this.recalc(),this.updateBounds(),this},Polygon.prototype.toIso=function(){return this.rotate(Math.PI/4).scale(Math.SQRT2,Math.SQRT1_2)},Polygon.prototype.to2d=function(){return this.scale(Math.SQRT1_2,Math.SQRT2).rotate(-Math.PI/4)},Polygon.prototype.rotate=function(t,e){if(0!==t){for(var i=this.points,r=i.length,o=0;o<r;o++)i[o].rotate(t,e);this.recalc(),this.updateBounds()}return this},Polygon.prototype.scale=function(t,e){e=void 0!==e?e:t;for(var i=this.points,r=i.length,o=0;o<r;o++)i[o].scale(t,e);return this.recalc(),this.updateBounds(),this},Polygon.prototype.scaleV=function(t){return this.scale(t.x,t.y)},Polygon.prototype.recalc=function(){var t,e=this.edges,i=this.normals,r=this.indices,o=this.points,n=o.length;if(n<3)throw new Error("Requires at least 3 points");for(t=0;t<n;t++)void 0===e[t]&&(e[t]=new Vector2d),e[t].copy(o[(t+1)%n]).sub(o[t]),void 0===i[t]&&(i[t]=new Vector2d),i[t].copy(e[t]).perp().normalize();return e.length=n,i.length=n,r.length=0,this},Polygon.prototype.getIndices=function(){return 0===this.indices.length&&(this.indices=earcut$1.exports(this.points.flatMap((function(t){return[t.x,t.y]})))),this.indices},Polygon.prototype.isConvex=function(){var t,e,i,r,o=0,n=this.points,s=n.length;if(s<3)return null;for(t=0;t<s;t++)if(i=(t+2)%s,r=(n[e=(t+1)%s].x-n[t].x)*(n[i].y-n[e].y),(r-=(n[e].y-n[t].y)*(n[i].x-n[e].x))<0?o|=1:r>0&&(o|=2),3===o)return!1;return 0!==o||null},Polygon.prototype.translate=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},Polygon.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x=t,this.pos.y=e,this.updateBounds()},Polygon.prototype.contains=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);for(var i=!1,r=this.pos.x,o=this.pos.y,n=this.points,s=n.length,a=0,h=s-1;a<s;h=a++){var l=n[a].y+o,c=n[a].x+r,u=n[h].y+o,d=n[h].x+r;l>e!=u>e&&t<(d-c)*(e-l)/(u-l)+c&&(i=!i)}return i},Polygon.prototype.getBounds=function(){return void 0===this._bounds&&(this._bounds=pull("Bounds")),this._bounds},Polygon.prototype.updateBounds=function(){var t=this.getBounds();return t.update(this.points),t.translate(this.pos),t},Polygon.prototype.clone=function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Polygon(this.pos.x,this.pos.y,t)};var Rect=function(t){function e(e,i,r,o){t.call(this,e,i,[new Vector2d(0,0),new Vector2d(r,0),new Vector2d(r,o),new Vector2d(0,o)]),this.shapeType="Rectangle"}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},width:{configurable:!0},height:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,r){this.setShape(t,e,i,r)},e.prototype.setShape=function(t,e,i,r){var o=i;return this.pos.set(t,e),4===arguments.length&&((o=this.points)[0].set(0,0),o[1].set(i,0),o[2].set(i,r),o[3].set(0,r)),this.setVertices(o),this},i.left.get=function(){return this.pos.x},i.right.get=function(){var t=this.width;return this.pos.x+t||t},i.top.get=function(){return this.pos.y},i.bottom.get=function(){var t=this.height;return this.pos.y+t||t},i.width.get=function(){return this.points[2].x},i.width.set=function(t){this.points[1].x=this.points[2].x=t,this.recalc(),this.updateBounds()},i.height.get=function(){return this.points[2].y},i.height.set=function(t){this.points[2].y=this.points[3].y=t,this.recalc(),this.updateBounds()},i.centerX.get=function(){return isFinite(this.width)?this.pos.x+this.width/2:this.width},i.centerX.set=function(t){this.pos.x=t-this.width/2},i.centerY.get=function(){return isFinite(this.height)?this.pos.y+this.height/2:this.height},i.centerY.set=function(t){this.pos.y=t-this.height/2},e.prototype.centerOn=function(t,e){return this.centerX=t,this.centerY=e,this},e.prototype.resize=function(t,e){return this.width=t,this.height=e,this},e.prototype.scale=function(t,e){return void 0===e&&(e=t),this.width*=t,this.height*=e,this},e.prototype.clone=function(){return new e(this.pos.x,this.pos.y,this.width,this.height)},e.prototype.copy=function(t){return this.setShape(t.pos.x,t.pos.y,t.width,t.height)},e.prototype.union=function(t){var e=Math.min(this.left,t.left),i=Math.min(this.top,t.top);return this.resize(Math.max(this.right,t.right)-e,Math.max(this.bottom,t.bottom)-i),this.pos.set(e,i),this},e.prototype.overlaps=function(t){return this.left<t.right&&t.left<this.right&&this.top<t.bottom&&t.top<this.bottom},e.prototype.contains=function(){var t,i,r,o,n=arguments[0];return 2===arguments.length?(t=i=n,r=o=arguments[1]):n instanceof e?(t=n.left,i=n.right,r=n.top,o=n.bottom):(t=i=n.x,r=o=n.y),t>=this.left&&i<=this.right&&r>=this.top&&o<=this.bottom},e.prototype.equals=function(t){return t.left===this.left&&t.right===this.right&&t.top===this.top&&t.bottom===this.bottom},e.prototype.isFinite=function(){return isFinite(this.pos.x)&&isFinite(this.pos.y)&&isFinite(this.width)&&isFinite(this.height)},e.prototype.toPolygon=function(){return new t(this.pos.x,this.pos.y,this.points)},Object.defineProperties(e.prototype,i),e}(Polygon),_keyStatus={},_keyLock={},_keyLocked={},_keyRefs={},_preventDefaultForKeys={},_keyBindings={},keyDownEvent=function(t,e,i){e=e||t.keyCode||t.button;var r=_keyBindings[e];if(emit(KEYDOWN,r,e,!r||!_keyLocked[r]),r){if(!_keyLocked[r]){var o=void 0!==i?i:e;_keyRefs[r][o]||(_keyStatus[r]++,_keyRefs[r][o]=!0)}return!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyUpEvent=function(t,e,i){e=e||t.keyCode||t.button;var r=_keyBindings[e];if(emit(KEYUP,r,e),r){var o=void 0!==i?i:e;return _keyRefs[r][o]=void 0,_keyStatus[r]>0&&_keyStatus[r]--,_keyLocked[r]=!1,!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyBoardEventTarget=null,KEY={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PRINT_SCREEN:42,INSERT:45,DELETE:46,NUM0:48,NUM1:49,NUM2:50,NUM3:51,NUM4:52,NUM5:53,NUM6:54,NUM7:55,NUM8:56,NUM9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,WINDOW_KEY:91,NUMPAD0:96,NUMPAD1:97,NUMPAD2:98,NUMPAD3:99,NUMPAD4:100,NUMPAD5:101,NUMPAD6:102,NUMPAD7:103,NUMPAD8:104,NUMPAD9:105,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,TILDE:126,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,PLUS:187,COMMA:188,MINUS:189,PERIOD:190,FORWAND_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222};function initKeyboardEvent(){null===keyBoardEventTarget&&!1===device$1.isMobile&&"function"==typeof(keyBoardEventTarget=globalThis).addEventListener&&(keyBoardEventTarget.addEventListener("keydown",keyDownEvent,!1),keyBoardEventTarget.addEventListener("keyup",keyUpEvent,!1))}function isKeyPressed(t){return!(!_keyStatus[t]||_keyLocked[t])&&(_keyLock[t]&&(_keyLocked[t]=!0),!0)}function keyStatus(t){return _keyStatus[t]>0}function triggerKeyEvent(t,e,i){!0===e?keyDownEvent({},t,i):keyUpEvent({},t,i)}function bindKey(t,e,i,r){void 0===r&&(r=preventDefault),_keyBindings[t]=e,_preventDefaultForKeys[t]=r,_keyStatus[e]=0,_keyLock[e]=i||!1,_keyLocked[e]=!1,_keyRefs[e]={}}function getBindingKey(t){return _keyBindings[t]}function unlockKey(t){_keyLocked[t]=!1}function unbindKey(t){var e=_keyBindings[t];_keyStatus[e]=0,_keyLock[e]=!1,_keyRefs[e]={},_keyBindings[t]=null,_preventDefaultForKeys[t]=null}var Bounds$1=function(t){this.onResetEvent(t)},prototypeAccessors$1={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds$1.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds$1.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds$1.prototype.setMinMax=function(t,e,i,r){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=r},prototypeAccessors$1.x.get=function(){return this.min.x},prototypeAccessors$1.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors$1.y.get=function(){return this.min.y},prototypeAccessors$1.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors$1.width.get=function(){return this.max.x-this.min.x},prototypeAccessors$1.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors$1.height.get=function(){return this.max.y-this.min.y},prototypeAccessors$1.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors$1.left.get=function(){return this.min.x},prototypeAccessors$1.right.get=function(){return this.max.x},prototypeAccessors$1.top.get=function(){return this.min.y},prototypeAccessors$1.bottom.get=function(){return this.max.y},prototypeAccessors$1.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors$1.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors$1.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds$1.prototype.update=function(t){this.add(t,!0)},Bounds$1.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var r=t[i];r.x>this.max.x&&(this.max.x=r.x),r.x<this.min.x&&(this.min.x=r.x),r.y>this.max.y&&(this.max.y=r.y),r.y<this.min.y&&(this.min.y=r.y)}},Bounds$1.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds$1.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds$1.prototype.addFrame=function(t,e,i,r,o){var n=me.pool.pull("Vector2d");this.addPoint(n.set(t,e),o),this.addPoint(n.set(i,e),o),this.addPoint(n.set(t,r),o),this.addPoint(n.set(i,r),o),me.pool.push(n)},Bounds$1.prototype.contains=function(){var t,e,i,r,o=arguments[0];return 2===arguments.length?(t=e=o,i=r=arguments[1]):o instanceof Bounds$1?(t=o.min.x,e=o.max.x,i=o.min.y,r=o.max.y):(t=e=o.x,i=r=o.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&r<=this.max.y},Bounds$1.prototype.overlaps=function(t){return!(this.right<t.left||this.left>t.right||this.bottom<t.top||this.top>t.bottom)},Bounds$1.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds$1.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds$1.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,r=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+r},Bounds$1.prototype.clone=function(){var t=new Bounds$1;return t.addBounds(this),t},Bounds$1.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds$1.prototype,prototypeAccessors$1);var tmpVec=new Vector2d,Pointer=function(t){function e(e,i,r,o){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===o&&(o=1),t.call(this),this.setMinMax(e,i,e+r,i+o),this.LEFT=0,this.MIDDLE=1,this.RIGHT=2,this.event=void 0,this.type=void 0,this.button=0,this.isPrimary=!1,this.pageX=0,this.pageY=0,this.clientX=0,this.clientY=0,this.movementX=0,this.movementY=0,this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0,this.gameX=0,this.gameY=0,this.gameScreenX=0,this.gameScreenY=0,this.gameWorldX=0,this.gameWorldY=0,this.gameLocalX=0,this.gameLocalY=0,this.pointerId=void 0,this.isNormalized=!1,this.locked=!1,this.bind=[0,0,0]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setEvent=function(t,e,i,r,o,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===n&&(n=1),this.event=t,this.pageX=e,this.pageY=i,this.clientX=r,this.clientY=o,globalToLocal(this.pageX,this.pageY,tmpVec),this.gameScreenX=this.x=tmpVec.x,this.gameScreenY=this.y=tmpVec.y,this.isNormalized=!device$1.PointerEvent||device$1.PointerEvent&&!(t instanceof globalThis.PointerEvent),this.locked=locked,this.movementX=t.movementX||0,this.movementY=t.movementY||0,"wheel"===t.type?(this.deltaMode=t.deltaMode||0,this.deltaX=t.deltaX||0,this.deltaY=t.deltaY||0,this.deltaZ=t.deltaZ||0):(this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0),this.pointerId=n,this.isPrimary=void 0===t.isPrimary||t.isPrimary,this.button=t.button||0,this.type=t.type,void 0!==viewport&&viewport.localToWorld(this.gameScreenX,this.gameScreenY,tmpVec),this.gameWorldX=tmpVec.x,this.gameWorldY=tmpVec.y,!1===this.isNormalized?(this.width=t.width||1,this.height=t.height||1):"number"==typeof t.radiusX?(this.width=2*t.radiusX||1,this.height=2*t.radiusY||1):this.width=this.height=1},e}(Bounds$1),T_POINTERS=[],eventHandlers=new Map,currentPointer,pointerInitialized=!1,lastTimeStamp=0,activeEventList=[],WHEEL=["wheel"],POINTER_MOVE=["pointermove","mousemove","touchmove"],POINTER_DOWN=["pointerdown","mousedown","touchstart"],POINTER_UP=["pointerup","mouseup","touchend"],POINTER_CANCEL=["pointercancel","mousecancel","touchcancel"],POINTER_ENTER=["pointerenter","mouseenter","touchenter"],POINTER_OVER=["pointerover","mouseover","touchover"],POINTER_LEAVE=["pointerleave","mouseleave","touchleave"],pointerEventList=[WHEEL[0],POINTER_MOVE[0],POINTER_DOWN[0],POINTER_UP[0],POINTER_CANCEL[0],POINTER_ENTER[0],POINTER_OVER[0],POINTER_LEAVE[0]],mouseEventList=[WHEEL[0],POINTER_MOVE[1],POINTER_DOWN[1],POINTER_UP[1],POINTER_CANCEL[1],POINTER_ENTER[1],POINTER_OVER[1],POINTER_LEAVE[1]],touchEventList=[POINTER_MOVE[2],POINTER_DOWN[2],POINTER_UP[2],POINTER_CANCEL[2],POINTER_ENTER[2],POINTER_OVER[2],POINTER_LEAVE[2]],pointerEventMap={wheel:WHEEL,pointermove:POINTER_MOVE,pointerdown:POINTER_DOWN,pointerup:POINTER_UP,pointercancel:POINTER_CANCEL,pointerenter:POINTER_ENTER,pointerover:POINTER_OVER,pointerleave:POINTER_LEAVE},normalizedEvents=[];function registerEventListener(t,e){for(var i=0;i<t.length;i++)-1===POINTER_MOVE.indexOf(t[i])&&pointerEventTarget.addEventListener(t[i],e,{passive:!1===preventDefault})}function enablePointerEvent(){if(!pointerInitialized){currentPointer=new Rect(0,0,1,1);for(var t=0;t<device$1.maxTouchPoints;t++)T_POINTERS.push(new Pointer);var e;null===pointerEventTarget&&(pointerEventTarget=renderer.getScreenCanvas()),activeEventList=device$1.PointerEvent?pointerEventList:mouseEventList,device$1.touch&&!device$1.PointerEvent&&(activeEventList=activeEventList.concat(touchEventList)),registerEventListener(activeEventList,onPointerEvent),void 0===throttlingInterval&&(throttlingInterval=~~(1e3/timer$1.maxfps)),!0===device$1.autoFocus&&(device$1.focus(),pointerEventTarget.addEventListener(activeEventList[2],(function(){device$1.focus()}),{passive:!1===preventDefault}));var i=findAllActiveEvents(activeEventList,POINTER_MOVE);if(throttlingInterval<17)for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],onMoveEvent,{passive:!0});else for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],throttle(onMoveEvent,throttlingInterval,!1),{passive:!0});setTouchAction(pointerEventTarget),device$1.hasPointerLockSupport&&document.addEventListener("pointerlockchange",(function(){locked=document.pointerLockElement===getParent(),emit(POINTERLOCKCHANGE,locked)}),!0),pointerInitialized=!0}}function findActiveEvent(t,e){for(var i=0;i<e.length;i++){if(-1!==t.indexOf(e[i]))return e[i]}}function findAllActiveEvents(t,e){for(var i=[],r=0;r<e.length;r++){-1!==t.indexOf(e[r])&&i.push(e[r])}return i}function triggerEvent(t,e,i,r){var o;if(t.callbacks[e]){t.pointerId=r;for(var n=t.callbacks[e].length-1;n>=0&&(o=t.callbacks[e][n]);n--)if(!1===o(i))return!0}return!1}function dispatchEvent(t){for(var e=!1;t.length>0;){var i=t.pop();if(T_POINTERS.push(i),void 0!==i.event.timeStamp){if(i.event.timeStamp<lastTimeStamp)continue;lastTimeStamp=i.event.timeStamp}currentPointer.setShape(i.gameWorldX,i.gameWorldY,i.width,i.height),POINTER_MOVE.includes(i.type)&&(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY,emit(POINTERMOVE,i));for(var r,o=world.broadphase.retrieve(currentPointer,Container.prototype._sortReverseZ),n=(o=o.concat([viewport])).length;r=o[--n];){if(eventHandlers.has(r)&&!0!==r.isKinematic){var s,a=eventHandlers.get(r),h=a.region,l=h.ancestor,c=h.getBounds();if(!0===h.isFloating?(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY):(i.gameX=i.gameLocalX=i.gameWorldX,i.gameY=i.gameLocalY=i.gameWorldY),void 0!==l){var u=l.getBounds();i.gameLocalX=i.gameX-u.x,i.gameLocalY=i.gameY-u.y}var d=i.gameX,p=i.gameY;if(void 0!==h.currentTransform&&!h.currentTransform.isIdentity()){var f=h.currentTransform.applyInverse(pull("Vector2d",d,p));d=f.x,p=f.y,push(f)}switch(s=c.contains(d,p),i.type){case POINTER_MOVE[0]:case POINTER_MOVE[1]:case POINTER_MOVE[2]:case POINTER_MOVE[3]:if(a.pointerId!==i.pointerId||s){if(null===a.pointerId&&s&&triggerEvent(a,findActiveEvent(activeEventList,POINTER_ENTER),i,i.pointerId)){e=!0;break}}else if(triggerEvent(a,findActiveEvent(activeEventList,POINTER_LEAVE),i,null)){e=!0;break}if(s&&triggerEvent(a,i.type,i,i.pointerId)){e=!0;break}break;case POINTER_UP[0]:case POINTER_UP[1]:case POINTER_UP[2]:case POINTER_UP[3]:if(a.pointerId===i.pointerId&&s&&triggerEvent(a,i.type,i,null)){e=!0;break}break;case POINTER_CANCEL[0]:case POINTER_CANCEL[1]:case POINTER_CANCEL[2]:case POINTER_CANCEL[3]:if(a.pointerId===i.pointerId&&triggerEvent(a,i.type,i,null)){e=!0;break}break;default:if(s&&triggerEvent(a,i.type,i,i.pointerId)){e=!0;break}}}if(!0===e)break}}return e}function normalizeEvent(t){var e;if(device$1.TouchEvent&&t.changedTouches)for(var i=0,r=t.changedTouches.length;i<r;i++){var o=t.changedTouches[i];(e=T_POINTERS.pop()).setEvent(t,o.pageX,o.pageY,o.clientX,o.clientY,o.identifier),normalizedEvents.push(e)}else(e=T_POINTERS.pop()).setEvent(t,t.pageX,t.pageY,t.clientX,t.clientY,t.pointerId),normalizedEvents.push(e);return!1===t.isPrimary||(normalizedEvents[0].isPrimary=!0,Object.assign(pointer,normalizedEvents[0])),normalizedEvents}function onMoveEvent(t){dispatchEvent(normalizeEvent(t))}function onPointerEvent(t){normalizeEvent(t);var e=normalizedEvents[0].button;(dispatchEvent(normalizedEvents)||"wheel"===t.type)&&t.preventDefault();var i=pointer.bind[e];i&&triggerKeyEvent(i,POINTER_DOWN.includes(t.type),e+1)}var pointerEventTarget=null,pointer=new Pointer(0,0,1,1),locked=!1,throttlingInterval;function globalToLocal(t,e,i){i=i||pull("Vector2d");var r=device$1.getElementBounds(renderer.getScreenCanvas()),o=device$1.devicePixelRatio;t-=r.left+(globalThis.pageXOffset||0),e-=r.top+(globalThis.pageYOffset||0);var n=scaleRatio;return 1===n.x&&1===n.y||(t/=n.x,e/=n.y),i.set(t*o,e*o)}function setTouchAction(t,e){t.style["touch-action"]=e||"none"}function bindPointer(){var t=arguments.length<2?pointer.LEFT:arguments[0],e=arguments.length<2?arguments[0]:arguments[1];if(enablePointerEvent(),!getBindingKey(e))throw new Error("no action defined for keycode "+e);pointer.bind[t]=e}function unbindPointer(t){pointer.bind[void 0===t?pointer.LEFT:t]=null}function registerPointerEvent(t,e,i){if(enablePointerEvent(),-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);if(void 0===e)throw new Error("registerPointerEvent: region for "+toString(e)+" event is undefined ");var r=findAllActiveEvents(activeEventList,pointerEventMap[t]);eventHandlers.has(e)||eventHandlers.set(e,{region:e,callbacks:{},pointerId:null});for(var o=eventHandlers.get(e),n=0;n<r.length;n++)t=r[n],o.callbacks[t]?o.callbacks[t].push(i):o.callbacks[t]=[i]}function releasePointerEvent(t,e,i){if(-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);var r=findAllActiveEvents(activeEventList,pointerEventMap[t]),o=eventHandlers.get(e);if(void 0!==o){for(var n=0;n<r.length;n++)if(t=r[n],o.callbacks[t]){if(void 0!==i)remove(o.callbacks[t],i);else for(;o.callbacks[t].length>0;)o.callbacks[t].pop();0===o.callbacks[t].length&&delete o.callbacks[t]}0===Object.keys(o.callbacks).length&&eventHandlers.delete(e)}}function releaseAllPointerEvents(t){if(eventHandlers.has(t))for(var e=0;e<pointerEventList.length;e++)releasePointerEvent(pointerEventList[e],t)}function requestPointerLock(){return!!device$1.hasPointerLockSupport&&(getParent().requestPointerLock(),!0)}function exitPointerLock(){return!!device$1.hasPointerLockSupport&&(document.exitPointerLock(),!0)}var deadzone=.1;function wiredXbox360NormalizeFn(t,e,i){return i===this.GAMEPAD.BUTTONS.L2||i===this.GAMEPAD.BUTTONS.R2?(t+1)/2:t}function ouyaNormalizeFn(t,e,i){return t=t>0?i===this.GAMEPAD.BUTTONS.L2?Math.max(0,t-2e4)/111070:(t-1)/131070:(65536+t)/131070+.5}var vendorProductRE=/^([0-9a-f]{1,4})-([0-9a-f]{1,4})-/i,leadingZeroRE=/^0+/;function addMapping(t,e){var i=t.replace(vendorProductRE,(function(t,e,i){return"000".substr(e.length-1)+e+"-"+"000".substr(i.length-1)+i+"-"})),r=t.replace(vendorProductRE,(function(t,e,i){return e.replace(leadingZeroRE,"")+"-"+i.replace(leadingZeroRE,"")+"-"}));e.analog=e.analog||e.buttons.map((function(){return-1})),e.normalize_fn=e.normalize_fn||function(t){return t},remap.set(i,e),remap.set(r,e)}var bindings={},remap=new Map,updateEventHandler;[["45e-28e-Xbox 360 Wired Controller",{axes:[0,1,3,4],buttons:[11,12,13,14,8,9,-1,-1,5,4,6,7,0,1,2,3,10],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:wiredXbox360NormalizeFn}],["54c-268-PLAYSTATION(R)3 Controller",{axes:[0,1,2,3],buttons:[14,13,15,12,10,11,8,9,0,3,1,2,4,6,7,5,16]}],["54c-5c4-Wireless Controller",{axes:[0,1,2,3],buttons:[1,0,2,3,4,5,6,7,8,9,10,11,14,15,16,17,12,13]}],["2836-1-OUYA Game Controller",{axes:[0,3,7,9],buttons:[3,6,4,5,7,8,15,16,-1,-1,9,10,11,12,13,14,-1],analog:[-1,-1,-1,-1,-1,-1,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}],["OUYA Game Controller (Vendor: 2836 Product: 0001)",{axes:[0,1,3,4],buttons:[0,3,1,2,4,5,12,13,-1,-1,6,7,8,9,10,11,-1],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}]].forEach((function(t){addMapping(t[0],t[1])}));var updateGamepads=function(){var t=navigator.getGamepads();Object.keys(bindings).forEach((function(e){var i=t[e];if(i){var r=null;"standard"!==i.mapping&&(r=remap.get(i.id));var o=bindings[e];Object.keys(o.buttons).forEach((function(t){var n=o.buttons[t],s=t,a=-1;if(!(r&&(s=r.buttons[t],a=r.analog[t],s<0&&a<0))){var h=i.buttons[s]||{};if(r&&a>=0){var l=r.normalize_fn(i.axes[a],-1,+t);h={value:l,pressed:h.pressed||Math.abs(l)>=deadzone}}emit(GAMEPAD_UPDATE,e,"buttons",+t,h),!n.pressed&&h.pressed?triggerKeyEvent(n.keyCode,!0,s+256):n.pressed&&!h.pressed&&triggerKeyEvent(n.keyCode,!1,s+256),n.value=h.value,n.pressed=h.pressed}})),Object.keys(o.axes).forEach((function(t){var n=o.axes[t],s=t;if(!(r&&(s=r.axes[t])<0)){var a=i.axes[s];if(void 0!==a){r&&(a=r.normalize_fn(a,+t,-1));var h=Math.sign(a)||1;if(0!==n[h].keyCode){var l=Math.abs(a)>=deadzone+Math.abs(n[h].threshold);emit(GAMEPAD_UPDATE,e,"axes",+t,a),!n[h].pressed&&l?(n[-h].pressed&&(triggerKeyEvent(n[-h].keyCode,!1,s+256),n[-h].value=0,n[-h].pressed=!1),triggerKeyEvent(n[h].keyCode,!0,s+256)):!n[h].pressed&&!n[-h].pressed||l||triggerKeyEvent(n[h=n[h].pressed?h:-h].keyCode,!1,s+256),n[h].value=a,n[h].pressed=l}}}}))}}))};globalThis.navigator&&"function"==typeof globalThis.navigator.getGamepads&&(globalThis.addEventListener("gamepadconnected",(function(t){emit(GAMEPAD_CONNECTED,t.gamepad)}),!1),globalThis.addEventListener("gamepaddisconnected",(function(t){emit(GAMEPAD_DISCONNECTED,t.gamepad)}),!1));var GAMEPAD={AXES:{LX:0,LY:1,RX:2,RY:3,EXTRA_1:4,EXTRA_2:5,EXTRA_3:6,EXTRA_4:7},BUTTONS:{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L1:4,R1:5,L2:6,R2:7,SELECT:8,BACK:8,START:9,FORWARD:9,L3:10,R3:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,HOME:16,EXTRA_1:17,EXTRA_2:18,EXTRA_3:19,EXTRA_4:20}};function bindGamepad(t,e,i){if(!getBindingKey(i))throw new Error("no action defined for keycode "+i);void 0===updateEventHandler&&"function"==typeof navigator.getGamepads&&(updateEventHandler=on(GAME_BEFORE_UPDATE,updateGamepads)),bindings[t]||(bindings[t]={axes:{},buttons:{}});var r={keyCode:i,value:0,pressed:!1,threshold:e.threshold},o=bindings[t][e.type];if("buttons"===e.type)o[e.code]=r;else if("axes"===e.type){var n=Math.sign(e.threshold)||1;o[e.code]||(o[e.code]={});var s=o[e.code];s[n]=r,s[-n]||(s[-n]={keyCode:0,value:0,pressed:!1,threshold:-n})}}function unbindGamepad(t,e){if(!bindings[t])throw new Error("no bindings for gamepad "+t);bindings[t].buttons[e]={}}function setGamepadDeadzone(t){deadzone=t}var setGamepadMapping=addMapping,preventDefault=!0,input=Object.freeze({__proto__:null,preventDefault:preventDefault,get pointerEventTarget(){return pointerEventTarget},pointer:pointer,get locked(){return locked},get throttlingInterval(){return throttlingInterval},globalToLocal:globalToLocal,setTouchAction:setTouchAction,bindPointer:bindPointer,unbindPointer:unbindPointer,registerPointerEvent:registerPointerEvent,releasePointerEvent:releasePointerEvent,releaseAllPointerEvents:releaseAllPointerEvents,requestPointerLock:requestPointerLock,exitPointerLock:exitPointerLock,get keyBoardEventTarget(){return keyBoardEventTarget},KEY:KEY,initKeyboardEvent:initKeyboardEvent,isKeyPressed:isKeyPressed,keyStatus:keyStatus,triggerKeyEvent:triggerKeyEvent,bindKey:bindKey,getBindingKey:getBindingKey,unlockKey:unlockKey,unbindKey:unbindKey,GAMEPAD:GAMEPAD,bindGamepad:bindGamepad,unbindGamepad:unbindGamepad,setGamepadDeadzone:setGamepadDeadzone,setGamepadMapping:setGamepadMapping}),Renderable=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isRenderable=!0,this.isKinematic=!0,this.body=void 0,void 0===this.currentTransform&&(this.currentTransform=pull("Matrix2d")),this.currentTransform.identity(),this.GUID=void 0,this.onVisibilityChange=void 0,this.alwaysUpdate=!1,this.updateWhenPaused=!1,this.isPersistent=!1,this.floating=!1,this.anchorPoint instanceof ObservableVector2d?this.anchorPoint.setMuted(.5,.5).setCallback(this.onAnchorUpdate,this):this.anchorPoint=pull("ObservableVector2d",.5,.5,{onUpdate:this.onAnchorUpdate,scope:this}),this.autoTransform=!0,this.alpha=1,this.ancestor=void 0,this.mask=void 0,this.tint=pull("Color",255,255,255,1),this.blendMode="normal",this.name="",this.pos instanceof ObservableVector3d?this.pos.setMuted(e,i,0).setCallback(this.updateBoundsPos,this):this.pos=pull("ObservableVector3d",e,i,0,{onUpdate:this.updateBoundsPos,scope:this}),this.isDirty=!1,this._flip={x:!1,y:!1},this._inViewport=!1,this.setOpacity(1)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={isFloating:{configurable:!0},inViewport:{configurable:!0},isFlippedX:{configurable:!0},isFlippedY:{configurable:!0}};return i.isFloating.get=function(){return!0===this.floating||void 0!==this.ancestor&&!0===this.ancestor.floating},i.inViewport.get=function(){return this._inViewport},i.inViewport.set=function(t){this._inViewport!==t&&(this._inViewport=t,"function"==typeof this.onVisibilityChange&&this.onVisibilityChange.call(this,t))},i.isFlippedX.get=function(){return!0===this._flip.x},i.isFlippedY.get=function(){return!0===this._flip.y},e.prototype.getBounds=function(){return void 0===this._bounds&&(t.prototype.getBounds.call(this),this.isFinite()?this._bounds.setMinMax(this.pos.x,this.pos.y,this.pos.x+this.width,this.pos.y+this.height):this._bounds.setMinMax(this.pos.x,this.pos.y,this.width,this.height)),this._bounds},e.prototype.getOpacity=function(){return this.alpha},e.prototype.setOpacity=function(t){"number"==typeof t&&(this.alpha=clamp(t,0,1),isNaN(this.alpha)&&(this.alpha=1),this.isDirty=!0)},e.prototype.flipX=function(t){return void 0===t&&(t=!0),this._flip.x=!!t,this.isDirty=!0,this},e.prototype.flipY=function(t){return void 0===t&&(t=!0),this._flip.y=!!t,this.isDirty=!0,this},e.prototype.transform=function(t){return this.currentTransform.multiply(t),this.updateBoundsPos(this.pos.x,this.pos.y),this.isDirty=!0,this},e.prototype.angleTo=function(t){var i,r,o=this.getBounds();if(t instanceof e){var n=t.getBounds();i=n.centerX-o.centerX,r=n.centerY-o.centerY}else i=t.x-o.centerX,r=t.y-o.centerY;return Math.atan2(r,i)},e.prototype.distanceTo=function(t){var i,r,o=this.getBounds();if(t instanceof e){var n=t.getBounds();i=o.centerX-n.centerX,r=o.centerY-n.centerY}else i=o.centerX-t.x,r=o.centerY-t.y;return Math.sqrt(i*i+r*r)},e.prototype.lookAt=function(t){var i;i=t instanceof e?t.pos:t;var r=this.angleTo(i);return this.rotate(r),this},e.prototype.rotate=function(t,e){return isNaN(t)||(this.currentTransform.rotate(t,e),this.isDirty=!0),this},e.prototype.scale=function(e,i){return this.currentTransform.scale(e,i),t.prototype.scale.call(this,e,i),this.isDirty=!0,this},e.prototype.scaleV=function(t){return this.scale(t.x,t.y),this},e.prototype.update=function(t){return this.isDirty},e.prototype.updateBounds=function(){return t.prototype.updateBounds.call(this),this.updateBoundsPos(this.pos.x,this.pos.y),this.getBounds()},e.prototype.updateBoundsPos=function(t,e){var i=this.getBounds();i.shift(t,e),void 0!==this.anchorPoint&&i.isFinite()&&i.translate(-this.anchorPoint.x*i.width,-this.anchorPoint.y*i.height),this.ancestor instanceof Container&&!0!==this.floating&&i.translate(this.ancestor.getAbsolutePosition())},e.prototype.getAbsolutePosition=function(){return void 0===this._absPos&&(this._absPos=pull("Vector2d")),this._absPos.set(this.pos.x,this.pos.y),this.ancestor instanceof Container&&!0!==this.floating&&this._absPos.add(this.ancestor.getAbsolutePosition()),this._absPos},e.prototype.onAnchorUpdate=function(t,e){this.anchorPoint.setMuted(t,e),this.updateBoundsPos(this.pos.x,this.pos.y)},e.prototype.preDraw=function(t){var e=this.getBounds(),i=e.width*this.anchorPoint.x,r=e.height*this.anchorPoint.y;if(t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),this._flip.x||this._flip.y){var o=this._flip.x?this.centerX-i:0,n=this._flip.y?this.centerY-r:0;t.translate(o,n),t.scale(this._flip.x?-1:1,this._flip.y?-1:1),t.translate(-o,-n)}void 0!==this.mask&&(t.translate(this.pos.x,this.pos.y),t.setMask(this.mask),t.translate(-this.pos.x,-this.pos.y)),!0!==this.autoTransform||this.currentTransform.isIdentity()||(t.translate(this.pos.x,this.pos.y),t.transform(this.currentTransform),t.translate(-this.pos.x,-this.pos.y)),t.translate(-i,-r),t.setTint(this.tint,this.getOpacity()),this.blendMode!==t.getBlendMode()&&t.setBlendMode(this.blendMode)},e.prototype.draw=function(t){},e.prototype.postDraw=function(t){t.clearTint(),void 0!==this.mask&&t.clearMask(),t.restore(),this.isDirty=!1},e.prototype.onCollision=function(){return!1},e.prototype.destroy=function(){push(this.currentTransform),this.currentTransform=void 0,push(this.anchorPoint),this.anchorPoint=void 0,push(this.pos),this.pos=void 0,void 0!==this._absPos&&(push(this._absPos),this._absPos=void 0),push(this._bounds),this._bounds=void 0,this.onVisibilityChange=void 0,void 0!==this.mask&&(push(this.mask),this.mask=void 0),void 0!==this.tint&&(push(this.tint),this.tint=void 0),this.ancestor=void 0,void 0!==this.body&&(this.body.destroy.apply(this.body,arguments),this.body=void 0),releaseAllPointerEvents(this),this.onDestroyEvent.apply(this,arguments)},e.prototype.onDestroyEvent=function(){},Object.defineProperties(e.prototype,i),e}(Rect),Ellipse=function(t,e,i,r){this.pos=new Vector2d,this._bounds=void 0,this.radius=NaN,this.radiusV=new Vector2d,this.radiusSq=new Vector2d,this.ratio=new Vector2d,this.shapeType="Ellipse",this.setShape(t,e,i,r)};Ellipse.prototype.onResetEvent=function(t,e,i,r){this.setShape(t,e,i,r)},Ellipse.prototype.setShape=function(t,e,i,r){var o=i/2,n=r/2;this.pos.set(t,e),this.radius=Math.max(o,n),this.ratio.set(o/this.radius,n/this.radius),this.radiusV.set(this.radius,this.radius).scaleV(this.ratio);var s=this.radius*this.radius;return this.radiusSq.set(s,s).scaleV(this.ratio),this.getBounds().setMinMax(t,e,t+i,t+r),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},Ellipse.prototype.rotate=function(t,e){return this.pos.rotate(t,e),this.getBounds().shift(this.pos),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},Ellipse.prototype.scale=function(t,e){return e=void 0!==e?e:t,this.setShape(this.pos.x,this.pos.y,2*this.radiusV.x*t,2*this.radiusV.y*e)},Ellipse.prototype.scaleV=function(t){return this.scale(t.x,t.y)},Ellipse.prototype.transform=function(){return this},Ellipse.prototype.translate=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},Ellipse.prototype.contains=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y,t*t/this.radiusSq.x+e*e/this.radiusSq.y<=1},Ellipse.prototype.getBounds=function(){return void 0===this._bounds&&(this._bounds=pull("Bounds")),this._bounds},Ellipse.prototype.clone=function(){return new Ellipse(this.pos.x,this.pos.y,2*this.radiusV.x,2*this.radiusV.y)};for(var LEFT_VORNOI_REGION=-1,MIDDLE_VORNOI_REGION=0,RIGHT_VORNOI_REGION=1,T_VECTORS=[],v=0;v<10;v++)T_VECTORS.push(new Vector2d);for(var T_ARRAYS=[],a=0;a<5;a++)T_ARRAYS.push([]);function flattenPointsOn(t,e,i){for(var r=Number.MAX_VALUE,o=-Number.MAX_VALUE,n=t.length,s=0;s<n;s++){var a=t[s].dot(e);a<r&&(r=a),a>o&&(o=a)}i[0]=r,i[1]=o}function isSeparatingAxis(t,e,i,r,o,n){var s=T_ARRAYS.pop(),a=T_ARRAYS.pop(),h=T_VECTORS.pop().copy(e).sub(t),l=h.dot(o);if(flattenPointsOn(i,o,s),flattenPointsOn(r,o,a),a[0]+=l,a[1]+=l,s[0]>a[1]||a[0]>s[1])return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!0;if(n){var c=0;if(s[0]<a[0])if(n.aInB=!1,s[1]<a[1])c=s[1]-a[0],n.bInA=!1;else{var u=s[1]-a[0],d=a[1]-s[0];c=u<d?u:-d}else if(n.bInA=!1,s[1]>a[1])c=s[0]-a[1],n.aInB=!1;else{var p=s[1]-a[0],f=a[1]-s[0];c=p<f?p:-f}var y=Math.abs(c);y<n.overlap&&(n.overlap=y,n.overlapN.copy(o),c<0&&n.overlapN.negateSelf())}return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!1}function vornoiRegion(t,e){var i=t.length2(),r=e.dot(t);return r<0?LEFT_VORNOI_REGION:r>i?RIGHT_VORNOI_REGION:MIDDLE_VORNOI_REGION}function testPolygonPolygon(t,e,i,r,o){var n,s=e.points,a=e.normals,h=a.length,l=r.points,c=r.normals,u=c.length,d=T_VECTORS.pop().copy(t.pos).add(t.ancestor.getAbsolutePosition()).add(e.pos),p=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos);for(n=0;n<h;n++)if(isSeparatingAxis(d,p,s,l,a[n],o))return T_VECTORS.push(d),T_VECTORS.push(p),!1;for(n=0;n<u;n++)if(isSeparatingAxis(d,p,s,l,c[n],o))return T_VECTORS.push(d),T_VECTORS.push(p),!1;return o&&(o.a=t,o.b=i,o.overlapV.copy(o.overlapN).scale(o.overlap)),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipseEllipse(t,e,i,r,o){var n=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=e.radius,a=r.radius,h=s+a,l=h*h,c=n.length2();if(c>l)return T_VECTORS.push(n),!1;if(o){var u=Math.sqrt(c);o.a=t,o.b=i,o.overlap=h-u,o.overlapN.copy(n.normalize()),o.overlapV.copy(n).scale(o.overlap),o.aInB=s<=a&&u<=a-s,o.bInA=a<=s&&u<=s-a}return T_VECTORS.push(n),!0}function testPolygonEllipse(t,e,i,r,o){for(var n=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=r.radius,a=s*s,h=e.points,l=e.edges,c=l.length,u=T_VECTORS.pop(),d=T_VECTORS.pop(),p=T_VECTORS.pop(),f=0,y=0;y<c;y++){var g=y===c-1?0:y+1,v=0===y?c-1:y-1,m=0,_=null;u.copy(l[y]),p.copy(n).sub(h[y]),o&&p.length2()>a&&(o.aInB=!1);var x=vornoiRegion(u,p),b=!0;if(x===LEFT_VORNOI_REGION){var T=null;if(c>1&&(u.copy(l[v]),(x=vornoiRegion(u,T=T_VECTORS.pop().copy(n).sub(h[v])))!==RIGHT_VORNOI_REGION&&(b=!1)),b){if((f=p.length())>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),T&&T_VECTORS.push(T),!1;o&&(o.bInA=!1,_=p.normalize(),m=s-f)}T&&T_VECTORS.push(T)}else if(x===RIGHT_VORNOI_REGION){if(c>1&&(u.copy(l[g]),p.copy(n).sub(h[g]),(x=vornoiRegion(u,p))!==LEFT_VORNOI_REGION&&(b=!1)),b){if((f=p.length())>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!1;o&&(o.bInA=!1,_=p.normalize(),m=s-f)}}else{d.copy(e.normals[y]),f=p.dot(d);var w=Math.abs(f);if((1===c||f>0)&&w>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!1;o&&(_=d,m=s-f,(f>=0||m<2*s)&&(o.bInA=!1))}_&&o&&Math.abs(m)<Math.abs(o.overlap)&&(o.overlap=m,o.overlapN.copy(_))}return o&&(o.a=t,o.b=i,o.overlapV.copy(o.overlapN).scale(o.overlap)),T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipsePolygon(t,e,i,r,o){var n=this.testPolygonEllipse(i,r,t,e,o);if(n&&o){var s=o.a,a=o.aInB;o.overlapN.negateSelf(),o.overlapV.negateSelf(),o.a=o.b,o.b=s,o.aInB=o.bInA,o.bInA=a}return n}var SAT=Object.freeze({__proto__:null,testPolygonPolygon:testPolygonPolygon,testEllipseEllipse:testEllipseEllipse,testPolygonEllipse:testPolygonEllipse,testEllipsePolygon:testEllipsePolygon}),dummyObj={pos:new Vector2d(0,0),ancestor:{_absPos:new Vector2d(0,0),getAbsolutePosition:function(){return this._absPos}}};function shouldCollide(t,e){return!0!==t.isKinematic&&!0!==e.isKinematic&&"object"==typeof t.body&&"object"==typeof e.body&&!(!0===t.body.isStatic&&!0===e.body.isStatic)&&0!=(t.body.collisionMask&e.body.collisionType)&&0!=(t.body.collisionType&e.body.collisionMask)}var ResponseObject=function(){this.a=null,this.b=null,this.overlapN=new Vector2d,this.overlapV=new Vector2d,this.aInB=!0,this.bInA=!0,this.indexShapeA=-1,this.indexShapeB=-1,this.overlap=Number.MAX_VALUE};ResponseObject.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this.indexShapeA=-1,this.indexShapeB=-1,this};var globalResponse=new ResponseObject;function collisionCheck(t,e){void 0===e&&(e=globalResponse);for(var i,r=0,o=world.broadphase.retrieve(t),n=o.length;i=o[--n];)if(i!==t&&shouldCollide(t,i)&&t.body.getBounds().overlaps(i.body.getBounds())){var s=t.body.shapes.length,a=i.body.shapes.length;if(0===s||0===a)continue;var h=0;do{var l=t.body.getShape(h),c=0;do{var u=i.body.getShape(c);!0===SAT["test"+l.shapeType+u.shapeType].call(this,t,l,i,u,e.clear())&&(r++,e.indexShapeA=h,e.indexShapeB=c,t.onCollision&&!1!==t.onCollision(e,i)&&!1===t.body.isStatic&&t.body.respondToCollision.call(t.body,e),i.onCollision&&!1!==i.onCollision(e,t)&&!1===i.body.isStatic&&i.body.respondToCollision.call(i.body,e)),c++}while(c<a);h++}while(h<s)}return r>0}function rayCast(t,e){void 0===e&&(e=[]);for(var i,r=0,o=world.broadphase.retrieve(t),n=o.length;i=o[--n];)if(i.body&&t.getBounds().overlaps(i.getBounds())){var s=i.body.shapes.length;if(0===i.body.shapes.length)continue;var a=t,h=0;do{var l=i.body.getShape(h);SAT["test"+a.shapeType+l.shapeType].call(this,dummyObj,a,i,l)&&(e[r]=i,r++),h++}while(h<s)}return e.length=r,e}var collision={maxChildren:8,maxDepth:4,types:{NO_OBJECT:0,PLAYER_OBJECT:1,NPC_OBJECT:2,ENEMY_OBJECT:4,COLLECTABLE_OBJECT:8,ACTION_OBJECT:16,PROJECTILE_OBJECT:32,WORLD_SHAPE:64,USER:128,ALL_OBJECT:4294967295},response:globalResponse,rayCast:function(t,e){return rayCast(t,e)}},Body=function(t,e,i){if(this.ancestor=t,void 0===this.bounds&&(this.bounds=new Bounds$1),void 0===this.shapes&&(this.shapes=[]),this.collisionMask=collision.types.ALL_OBJECT,this.collisionType=collision.types.ENEMY_OBJECT,void 0===this.vel&&(this.vel=new Vector2d),this.vel.set(0,0),void 0===this.force&&(this.force=new Vector2d),this.force.set(0,0),void 0===this.friction&&(this.friction=new Vector2d),this.friction.set(0,0),this.bounce=0,this.mass=1,void 0===this.maxVel&&(this.maxVel=new Vector2d),this.maxVel.set(490,490),this.isStatic=!1,this.gravityScale=1,this.ignoreGravity=!1,this.falling=!1,this.jumping=!1,"function"==typeof i&&(this.onBodyUpdate=i),this.bounds.clear(),void 0!==e)if(Array.isArray(e))for(var r=0;r<e.length;r++)this.addShape(e[r]);else this.addShape(e);this.ancestor.isKinematic=!1};Body.prototype.setStatic=function(t){void 0===t&&(t=!0),this.isStatic=!0===t},Body.prototype.addShape=function(t){if(t instanceof Rect||t instanceof Bounds$1){var e=t.toPolygon();this.shapes.push(e),this.bounds.add(e.points),this.bounds.translate(e.pos)}else t instanceof Ellipse?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.addBounds(t.getBounds()),this.bounds.translate(t.getBounds().x,t.getBounds().y)):t instanceof Polygon?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.add(t.points),this.bounds.translate(t.pos)):this.fromJSON(t);return"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this),this.shapes.length},Body.prototype.setVertices=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=!0);var r=this.getShape(e);r instanceof Polygon?r.setShape(0,0,t):this.shapes[e]=new Polygon(0,0,t),this.bounds.add(this.shapes[e].points,i),"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this)},Body.prototype.addVertices=function(t,e){void 0===e&&(e=0),this.setVertices(t,e,!1)},Body.prototype.fromJSON=function(t,e){var i=t;if(void 0!==e&&(i=t[e]),void 0===i)throw new Error("Identifier ("+e+") undefined for the given JSON object)");if(i.length){for(var r=0;r<i.length;r++)this.addVertices(i[r].shape,r);this.mass=i[0].density||0,this.friction.set(i[0].friction||0,i[0].friction||0),this.bounce=i[0].bounce||0}return i.length},Body.prototype.getShape=function(t){return this.shapes[t||0]},Body.prototype.getBounds=function(){return this.bounds},Body.prototype.removeShape=function(t){this.bounds.clear(),remove(this.shapes,t);for(var e=0;e<this.shapes.length;e++)this.addShape(this.shapes[e]);return this.shapes.length},Body.prototype.removeShapeAt=function(t){return this.removeShape(this.getShape(t))},Body.prototype.setCollisionMask=function(t){void 0===t&&(t=collision.types.ALL_OBJECT),this.collisionMask=t},Body.prototype.setCollisionType=function(t){if(void 0!==t){if(void 0===collision.types[t])throw new Error("Invalid value for the collisionType property");this.collisionType=collision.types[t]}},Body.prototype.respondToCollision=function(t){var e=t.overlapV;if(this.ancestor.pos.sub(e),0!==e.x&&(this.vel.x=~~(.5+this.vel.x-e.x)||0,this.bounce>0&&(this.vel.x*=-this.bounce)),0!==e.y){this.vel.y=~~(.5+this.vel.y-e.y)||0,this.bounce>0&&(this.vel.y*=-this.bounce);var i=Math.sign(world.gravity.y*this.gravityScale)||1;this.falling=e.y>=i,this.jumping=e.y<=-i}},Body.prototype.forEach=function(t,e){var i=this,r=0,o=this.shapes,n=o.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);r<n;)t.call(i,o[r],r,o),r++},Body.prototype.contains=function(){var t,e;if(2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.getBounds().contains(t,e))for(var i,r=this.shapes.length;r--,i=this.shapes[r];)if(i.contains(t,e))return!0;return!1},Body.prototype.rotate=function(t,e){var i=this;return void 0===e&&(e=this.getBounds().center),this.bounds.clear(),this.forEach((function(r){r.rotate(t,e),i.bounds.addBounds(r.getBounds()),r instanceof Ellipse?i.bounds.translate(r.getBounds().x,r.getBounds().y):i.bounds.translate(r.pos)})),this},Body.prototype.setMaxVelocity=function(t,e){this.maxVel.x=t,this.maxVel.y=e},Body.prototype.setFriction=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.friction.x=t,this.friction.y=e},Body.prototype.computeVelocity=function(){var t=timer$1.tick;if(!this.ignoreGravity){var e=world.gravity;this.vel.x+=e.x*this.gravityScale*t,this.vel.y+=e.y*this.gravityScale*t,this.falling=this.vel.y*Math.sign(e.y*this.gravityScale)>0,this.jumping=!this.falling&&this.jumping}if(0!==this.force.x&&(this.vel.x+=this.force.x*t),0!==this.force.y&&(this.vel.y+=this.force.y*t),this.friction.x>0){var i=this.friction.x*t,r=this.vel.x+i,o=this.vel.x-i;this.vel.x=r<0?r:o>0?o:0}if(this.friction.y>0){var n=this.friction.y*t,s=this.vel.y+n,a=this.vel.y-n;this.vel.y=s<0?s:a>0?a:0}0!==this.vel.y&&(this.vel.y=clamp(this.vel.y,-this.maxVel.y,this.maxVel.y)),0!==this.vel.x&&(this.vel.x=clamp(this.vel.x,-this.maxVel.x,this.maxVel.x))},Body.prototype.update=function(t){return this.computeVelocity(t),this.ancestor.pos.add(this.vel),0!==this.vel.x||0!==this.vel.y},Body.prototype.destroy=function(){this.onBodyUpdate=void 0,this.ancestor=void 0,this.bounds=void 0,this.setStatic(!1),this.shapes.length=0};var deferredRemove=function(t,e){this.removeChildNow(t,e)},globalFloatingCounter=0,Container=function(t){function e(e,i,r,o,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=viewport.width),void 0===o&&(o=viewport.height),void 0===n&&(n=!1),t.call(this,e,i,r,o),this.pendingSort=null,this.root=n,this.children=void 0,this.sortOn=sortOn,this.autoSort=!0,this.autoDepth=!0,this.clipping=!1,this.onChildChange=function(){},this.enableChildBoundsUpdate=!1,this.backgroundColor=pull("Color",0,0,0,0),this.drawCount=0,this.autoTransform=!0,this.isKinematic=!1,this.anchorPoint.set(0,0),!0===this.root&&on(CANVAS_ONRESIZE,this.updateBounds.bind(this,!0))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){this.pendingSort&&(clearTimeout(this.pendingSort),this.pendingSort=null);for(var t,e=this.getChildren(),i=e.length;i>=0;t=e[--i])t&&!0!==t.isPersistent&&this.removeChildNow(t);void 0!==this.currentTransform&&this.currentTransform.identity(),this.backgroundColor.setColor(0,0,0,0)},e.prototype.addChild=function(t,i){return t.ancestor instanceof e?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils.createGUID(t.id)),t.ancestor=this,this.getChildren().push(t),void 0!==t.pos&&("number"==typeof i?t.pos.z=i:!0===this.autoDepth&&(t.pos.z=this.getChildren().length)),!0===this.autoSort&&this.sort(),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),t.body instanceof Body&&world.addBody(t.body),this.onChildChange.call(this,this.getChildren().length-1),t},e.prototype.addChildAt=function(t,i){if(i>=0&&i<this.getChildren().length)return t.ancestor instanceof e?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils.createGUID()),t.ancestor=this,this.getChildren().splice(i,0,t),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),t.body instanceof Body&&world.addBody(t.body),this.onChildChange.call(this,i),t;throw new Error("Index ("+i+") Out Of Bounds for addChildAt()")},e.prototype.forEach=function(t,e){var i=this,r=0,o=this.getChildren(),n=o.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);r<n;)t.call(i,o[r],r,o),r++},e.prototype.swapChildren=function(t,e){var i=this.getChildIndex(t),r=this.getChildIndex(e);if(-1===i||-1===r)throw new Error(t+" Both the supplied childs must be a child of the caller "+this);var o=t.pos.z;t.pos.z=e.pos.z,e.pos.z=o,this.getChildren()[i]=e,this.getChildren()[r]=t,this.isDirty=!0},e.prototype.getChildAt=function(t){if(t>=0&&t<this.getChildren().length)return this.getChildren()[t];throw new Error("Index ("+t+") Out Of Bounds for getChildAt()")},e.prototype.getChildIndex=function(t){return this.getChildren().indexOf(t)},e.prototype.getNextChild=function(t){var e=this.getChildren().indexOf(t)-1;if(e>=0&&e<this.getChildren().length)return this.getChildAt(e)},e.prototype.hasChild=function(t){return this===t.ancestor},e.prototype.getChildByProp=function(t,i){var r=[];return this.forEach((function(o){!function(t,e){var o=t[e];i instanceof RegExp&&"string"==typeof o?i.test(o)&&r.push(t):o===i&&r.push(t)}(o,t),o instanceof e&&(r=r.concat(o.getChildByProp(t,i)))})),r},e.prototype.getChildByType=function(t){var i=[];return this.forEach((function(r){r instanceof t&&i.push(r),r instanceof e&&(i=i.concat(r.getChildByType(t)))})),i},e.prototype.getChildByName=function(t){return this.getChildByProp("name",t)},e.prototype.getChildByGUID=function(t){var e=this.getChildByProp("GUID",t);return e.length>0?e[0]:null},e.prototype.getChildren=function(){return void 0===this.children&&(this.children=[]),this.children},e.prototype.updateBounds=function(e){void 0===e&&(e=!1),t.prototype.updateBounds.call(this);var i=this.getBounds();return!0!==e&&!0!==this.enableChildBoundsUpdate||this.forEach((function(t){t.isRenderable&&(t.getBounds().isFinite()&&i.addBounds(t.getBounds()))})),i},e.prototype.isAttachedToRoot=function(){if(!0===this.root)return!0;for(var t=this.ancestor;t;){if(!0===t.root)return!0;t=t.ancestor}return!1},e.prototype.updateBoundsPos=function(e,i){var r=this;return t.prototype.updateBoundsPos.call(this,e,i),this.forEach((function(t){t.isRenderable&&t.updateBoundsPos(t.pos.x+e-r.pos.x,t.pos.y+i-r.pos.y)})),this.getBounds()},e.prototype.onActivateEvent=function(){this.forEach((function(t){"function"==typeof t.onActivateEvent&&t.onActivateEvent()}))},e.prototype.removeChild=function(t,e){if(!this.hasChild(t))throw new Error("Child is not mine.");utils.function.defer(deferredRemove,this,t,e)},e.prototype.removeChildNow=function(t,e){if(this.hasChild(t)&&this.getChildIndex(t)>=0){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent(),t.body instanceof Body&&world.removeBody(t.body),e||!1===push(t,!1)&&"function"==typeof t.destroy&&t.destroy();var i=this.getChildIndex(t);i>=0&&(this.getChildren().splice(i,1),t.ancestor=void 0),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,i)}},e.prototype.setChildsProperty=function(t,i,r){this.forEach((function(o){!0===r&&o instanceof e&&o.setChildsProperty(t,i,r),o[t]=i}))},e.prototype.moveUp=function(t){var e=this.getChildIndex(t);e-1>=0&&(this.swapChildren(t,this.getChildAt(e-1)),this.isDirty=!0)},e.prototype.moveDown=function(t){var e=this.getChildIndex(t);e>=0&&e+1<this.getChildren().length&&(this.swapChildren(t,this.getChildAt(e+1)),this.isDirty=!0)},e.prototype.moveToTop=function(t){var e=this.getChildIndex(t);if(e>0){var i=this.getChildren();i.splice(0,0,i.splice(e,1)[0]),t.pos.z=i[1].pos.z+1,this.isDirty=!0}},e.prototype.moveToBottom=function(t){var e=this.getChildIndex(t),i=this.getChildren();e>=0&&e<i.length-1&&(i.splice(i.length-1,0,i.splice(e,1)[0]),t.pos.z=i[i.length-2].pos.z-1,this.isDirty=!0)},e.prototype.sort=function(t){this.pendingSort||(!0===t&&this.forEach((function(i){i instanceof e&&i.sort(t)})),this.pendingSort=utils.function.defer((function(){this.getChildren().sort(this["_sort"+this.sortOn.toUpperCase()]),this.pendingSort=null,repaint()}),this))},e.prototype.onDeactivateEvent=function(){this.forEach((function(t){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent()}))},e.prototype._sortZ=function(t,e){return e.pos&&t.pos?e.pos.z-t.pos.z:t.pos?-1/0:1/0},e.prototype._sortReverseZ=function(t,e){return t.pos&&e.pos?t.pos.z-e.pos.z:t.pos?1/0:-1/0},e.prototype._sortX=function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.x-t.pos.x},e.prototype._sortY=function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.y-t.pos.y},e.prototype.destroy=function(){this.reset(),t.prototype.destroy.call(this,arguments)},e.prototype.update=function(e){for(var i,r=!1,o=state.isPaused(),n=this.getChildren(),s=n.length;s--,i=n[s];)o&&!i.updateWhenPaused||(i.isRenderable?((r=globalFloatingCounter>0||i.floating)&&globalFloatingCounter++,i.inViewport=!1,state.current().cameras.forEach((function(t){t.isVisible(i,r)&&(i.inViewport=!0)})),this.isDirty|=(i.inViewport||i.alwaysUpdate)&&i.update(e),globalFloatingCounter>0&&globalFloatingCounter--):this.isDirty|=i.update(e));return t.prototype.update.call(this,e)},e.prototype.draw=function(t,e){var i=!1,r=this.getBounds();this.drawCount=0,!1===this.root&&!0===this.clipping&&!0===r.isFinite()&&t.clipRect(r.left,r.top,r.width,r.height),t.translate(this.pos.x,this.pos.y),this.backgroundColor.alpha>1/255&&t.clearColor(this.backgroundColor);for(var o,n=this.getChildren(),s=n.length;o=n[--s];)o.isRenderable&&(i=!0===o.floating,(o.inViewport||i)&&(i&&(t.save(),t.resetTransform()),o.preDraw(t),o.draw(t,e),o.postDraw(t),i&&t.restore(),this.drawCount++))},e}(Renderable),QT_ARRAY=[];function QT_ARRAY_POP(t,e,i,r){if(void 0===e&&(e=4),void 0===i&&(i=4),void 0===r&&(r=0),QT_ARRAY.length>0){var o=QT_ARRAY.pop();return o.bounds=t,o.max_objects=e,o.max_levels=i,o.level=r,o}return new QuadTree(t,e,i,r)}function QT_ARRAY_PUSH(t){QT_ARRAY.push(t)}var QT_VECTOR=new Vector2d,QuadTree=function(t,e,i,r){void 0===e&&(e=4),void 0===i&&(i=4),void 0===r&&(r=0),this.max_objects=e,this.max_levels=i,this.level=r,this.bounds=t,this.objects=[],this.nodes=[]};QuadTree.prototype.split=function(){var t=this.level+1,e=this.bounds.width/2,i=this.bounds.height/2,r=this.bounds.left,o=this.bounds.top;this.nodes[0]=QT_ARRAY_POP({left:r+e,top:o,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[1]=QT_ARRAY_POP({left:r,top:o,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[2]=QT_ARRAY_POP({left:r,top:o+i,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[3]=QT_ARRAY_POP({left:r+e,top:o+i,width:e,height:i},this.max_objects,this.max_levels,t)},QuadTree.prototype.getIndex=function(t){var e,i=t.getBounds(),r=-1,o=(e=!0===t.isFloating?viewport.localToWorld(i.left,i.top,QT_VECTOR):QT_VECTOR.set(t.left,t.top)).x,n=e.y,s=i.width,a=i.height,h=this.bounds.left+this.bounds.width/2,l=this.bounds.top+this.bounds.height/2,c=n<l&&n+a<l,u=n>l;return o<h&&o+s<h?c?r=1:u&&(r=2):o>h&&(c?r=0:u&&(r=3)),r},QuadTree.prototype.insertContainer=function(t){for(var e,i=t.children.length;i--,e=t.children[i];)!0!==e.isKinematic&&(e instanceof Container?("rootContainer"!==e.name&&this.insert(e),this.insertContainer(e)):"function"==typeof e.getBounds&&this.insert(e))},QuadTree.prototype.insert=function(t){var e=-1;if(this.nodes.length>0&&-1!==(e=this.getIndex(t)))this.nodes[e].insert(t);else if(this.objects.push(t),this.objects.length>this.max_objects&&this.level<this.max_levels){0===this.nodes.length&&this.split();for(var i=0;i<this.objects.length;)-1!==(e=this.getIndex(this.objects[i]))?this.nodes[e].insert(this.objects.splice(i,1)[0]):i+=1}},QuadTree.prototype.retrieve=function(t,e){var i=this.objects;if(this.nodes.length>0){var r=this.getIndex(t);if(-1!==r)i=i.concat(this.nodes[r].retrieve(t));else for(var o=0;o<this.nodes.length;o+=1)i=i.concat(this.nodes[o].retrieve(t))}return"function"==typeof e&&i.sort(e),i},QuadTree.prototype.remove=function(t){var e=!1;if(void 0===t.getBounds)return!1;if(this.nodes.length>0){var i=this.getIndex(t);-1!==i&&(e=remove(this.nodes[i],t))&&this.nodes[i].isPrunable()&&this.nodes.splice(i,1)}return!1===e&&-1!==this.objects.indexOf(t)&&(remove(this.objects,t),e=!0),e},QuadTree.prototype.isPrunable=function(){return!(this.hasChildren()||this.objects.length>0)},QuadTree.prototype.hasChildren=function(){for(var t=0;t<this.nodes.length;t+=1){var e=this.nodes[t];if(e.length>0||e.objects.length>0)return!0}return!1},QuadTree.prototype.clear=function(t){this.objects.length=0;for(var e=0;e<this.nodes.length;e++)this.nodes[e].clear(),QT_ARRAY_PUSH(this.nodes[e]);this.nodes.length=0,void 0!==t&&this.bounds.setMinMax(t.min.x,t.min.y,t.max.x,t.max.y)};var World=function(t){function e(e,i,r,o){var n=this;void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1/0),void 0===o&&(o=1/0),t.call(this,e,i,r,o,!0),this.name="rootContainer",this.anchorPoint.set(0,0),this.fps=60,this.gravity=new Vector2d(0,.98),this.preRender=!1,this.bodies=new Set,this.broadphase=new QuadTree(this.getBounds().clone(),collision.maxChildren,collision.maxDepth),on(GAME_RESET,this.reset,this),on(LEVEL_LOADED,(function(){n.broadphase.clear(n.getBounds())}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){this.broadphase.clear(),this.anchorPoint.set(0,0),t.prototype.reset.call(this),this.bodies.clear()},e.prototype.addBody=function(t){return this.bodies.add(t),this},e.prototype.removeBody=function(t){return this.bodies.delete(t),this},e.prototype.update=function(e){var i=state.isPaused();return this.broadphase.clear(),this.broadphase.insertContainer(this),this.bodies.forEach((function(t){if(!t.isStatic){var r=t.ancestor;i&&!r.updateWhenPaused||!r.inViewport&&!r.alwaysUpdate||(!0===t.update(e)&&(r.isDirty=!0),collisionCheck(r))}})),t.prototype.update.call(this,e)},e}(Container),isDirty=!0,isAlwaysDirty=!1,frameCounter=0,frameRate=1,accumulator=0,accumulatorMax=0,accumulatorUpdateDelta=0,stepSize=1e3/60,updateDelta=0,lastUpdateStart=null,updateAverageDelta=0,viewport,world;on(BOOT,(function(){world=new World,emit(GAME_INIT)}));var mergeGroup=!0,sortOn="z",lastUpdate=globalThis.performance.now();function onLevelLoaded(){}function reset(){var t=state.current();void 0!==t&&(viewport=t.cameras.get("default")),emit(GAME_RESET),updateFrameRate()}function updateFrameRate(){frameCounter=0,frameRate=~~(.5+60/timer$1.maxfps),stepSize=1e3/world.fps,accumulator=0,accumulatorMax=10*stepSize,isAlwaysDirty=timer$1.maxfps>world.fps}function getParentContainer(t){return t.ancestor}function repaint(){isDirty=!0}function update$1(t,e){if(++frameCounter%frameRate==0){for(frameCounter=0,emit(GAME_BEFORE_UPDATE,t),accumulator+=timer$1.getDelta(),accumulator=Math.min(accumulator,accumulatorMax),updateDelta=timer$1.interpolation?timer$1.getDelta():stepSize,accumulatorUpdateDelta=timer$1.interpolation?updateDelta:Math.max(updateDelta,updateAverageDelta);accumulator>=accumulatorUpdateDelta||timer$1.interpolation;)if(lastUpdateStart=globalThis.performance.now(),!0!==state.isPaused()&&emit(GAME_UPDATE,t),isDirty=e.update(updateDelta)||isDirty,lastUpdate=globalThis.performance.now(),updateAverageDelta=lastUpdate-lastUpdateStart,accumulator-=accumulatorUpdateDelta,timer$1.interpolation){accumulator=0;break}emit(GAME_AFTER_UPDATE,lastUpdate)}}function draw(t){!0===renderer.isContextValid&&(isDirty||isAlwaysDirty)&&(emit(GAME_BEFORE_DRAW,globalThis.performance.now()),renderer.clear(),t.draw(renderer),isDirty=!1,renderer.flush(),emit(GAME_AFTER_DRAW,globalThis.performance.now()))}var game=Object.freeze({__proto__:null,get viewport(){return viewport},get world(){return world},mergeGroup:mergeGroup,sortOn:sortOn,get lastUpdate(){return lastUpdate},onLevelLoaded:onLevelLoaded,reset:reset,updateFrameRate:updateFrameRate,getParentContainer:getParentContainer,repaint:repaint,update:update$1,draw:draw}),MIN=Math.min,MAX=Math.max,targetV=new Vector2d,Camera2d=function(t){function e(e,i,r,o){t.call(this,e,i,r-e,o-i),this.AXIS={NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},this.bounds=pull("Bounds"),this.smoothFollow=!0,this.damping=1,this.near=-1e3,this.far=1e3,this.projectionMatrix=new Matrix3d,this.invCurrentTransform=new Matrix2d,this.offset=new Vector2d,this.target=null,this.follow_axis=this.AXIS.NONE,this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null},this._fadeOut={color:null,tween:null},this._fadeIn={color:null,tween:null},this.name="default",this.setDeadzone(this.width/6,this.height/6),this.anchorPoint.set(0,0),this.isKinematic=!1,this.bounds.setMinMax(e,i,r,o),this._updateProjectionMatrix(),on(GAME_RESET,this.reset,this),on(CANVAS_ONRESIZE,this.resize,this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._updateProjectionMatrix=function(){this.projectionMatrix.ortho(0,this.width,this.height,0,this.near,this.far)},e.prototype._followH=function(t){var e=this.pos.x;return t.x-this.pos.x>this.deadzone.right?e=MIN(t.x-this.deadzone.right,this.bounds.width-this.width):t.x-this.pos.x<this.deadzone.pos.x&&(e=MAX(t.x-this.deadzone.pos.x,this.bounds.left)),e},e.prototype._followV=function(t){var e=this.pos.y;return t.y-this.pos.y>this.deadzone.bottom?e=MIN(t.y-this.deadzone.bottom,this.bounds.height-this.height):t.y-this.pos.y<this.deadzone.pos.y&&(e=MAX(t.y-this.deadzone.pos.y,this.bounds.top)),e},e.prototype.reset=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.pos.x=t,this.pos.y=e,this.unfollow(),this.smoothFollow=!0,this.damping=1,this.currentTransform.identity(),this.invCurrentTransform.identity().invert(),this._updateProjectionMatrix()},e.prototype.setDeadzone=function(t,e){void 0===this.deadzone&&(this.deadzone=new Rect(0,0,0,0)),this.deadzone.pos.set(~~((this.width-t)/2),~~((this.height-e)/2-.25*e)),this.deadzone.resize(t,e),this.smoothFollow=!1,this.updateTarget(),this.smoothFollow=!0},e.prototype.resize=function(e,i){return t.prototype.resize.call(this,e,i),this.smoothFollow=!1,this.setBounds(0,0,e,i),this.setDeadzone(e/6,i/6),this.update(),this.smoothFollow=!0,this._updateProjectionMatrix(),emit(VIEWPORT_ONRESIZE,this.width,this.height),this},e.prototype.setBounds=function(t,e,i,r){this.smoothFollow=!1,this.bounds.setMinMax(t,e,i+t,r+e),this.moveTo(this.pos.x,this.pos.y),this.update(),this.smoothFollow=!0},e.prototype.follow=function(e,i,r){if(e instanceof t)this.target=e.pos;else{if(!(e instanceof Vector2d||e instanceof Vector3d||e instanceof ObservableVector2d||e instanceof ObservableVector3d))throw new Error("invalid target for me.Camera2d.follow");this.target=e}this.follow_axis=void 0===i?this.AXIS.BOTH:i,this.smoothFollow=!1,this.damping="number"!=typeof r?1:clamp(r,0,1),this.updateTarget(),this.smoothFollow=!0},e.prototype.unfollow=function(){this.target=null,this.follow_axis=this.AXIS.NONE},e.prototype.move=function(t,e){this.moveTo(this.pos.x+t,this.pos.y+e)},e.prototype.moveTo=function(t,e){var i=this.pos.x,r=this.pos.y;this.pos.x=clamp(t,this.bounds.left,this.bounds.width),this.pos.y=clamp(e,this.bounds.top,this.bounds.height),i===this.pos.x&&r===this.pos.y||(this.isDirty=!0)},e.prototype.updateTarget=function(){if(this.target){switch(targetV.setV(this.pos),this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:targetV.x=this._followH(this.target);break;case this.AXIS.VERTICAL:targetV.y=this._followV(this.target);break;case this.AXIS.BOTH:targetV.x=this._followH(this.target),targetV.y=this._followV(this.target)}if(!this.pos.equals(targetV)){if(!0===this.smoothFollow&&this.damping<1){if(toBeCloseTo(targetV.x,this.pos.x,2)&&toBeCloseTo(targetV.y,this.pos.y,2))return void this.pos.setV(targetV);this.pos.lerp(targetV,this.damping)}else this.pos.setV(targetV);this.isDirty=!0}}},e.prototype.update=function(e){return this.updateTarget(e),this._shake.duration>0&&(this._shake.duration-=e,this._shake.duration<=0?(this._shake.duration=0,this.offset.setZero(),"function"==typeof this._shake.onComplete&&this._shake.onComplete()):(this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.HORIZONTAL||(this.offset.x=(Math.random()-.5)*this._shake.intensity),this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.VERTICAL||(this.offset.y=(Math.random()-.5)*this._shake.intensity)),this.isDirty=!0),!0===this.isDirty&&emit(VIEWPORT_ONCHANGE,this.pos),null==this._fadeIn.tween&&null==this._fadeOut.tween||(this.isDirty=!0),this.currentTransform.isIdentity()?this.invCurrentTransform.identity():this.invCurrentTransform.copy(this.currentTransform).invert(),t.prototype.update.call(this,e)},e.prototype.shake=function(t,e,i,r,o){0!==this._shake.duration&&!0!==o||(this._shake.intensity=t,this._shake.duration=e,this._shake.axis=i||this.AXIS.BOTH,this._shake.onComplete="function"==typeof r?r:void 0)},e.prototype.fadeOut=function(t,e,i){void 0===e&&(e=1e3),this._fadeOut.color=pull("Color").copy(t),this._fadeOut.tween=pull("Tween",this._fadeOut.color).to({alpha:0},e).onComplete(i||null),this._fadeOut.tween.isPersistent=!0,this._fadeOut.tween.start()},e.prototype.fadeIn=function(t,e,i){void 0===e&&(e=1e3),this._fadeIn.color=pull("Color").copy(t);var r=this._fadeIn.color.alpha;this._fadeIn.color.alpha=0,this._fadeIn.tween=pull("Tween",this._fadeIn.color).to({alpha:r},e).onComplete(i||null),this._fadeIn.tween.isPersistent=!0,this._fadeIn.tween.start()},e.prototype.focusOn=function(t){var e=t.getBounds();this.moveTo(t.pos.x+e.left+e.width/2,t.pos.y+e.top+e.height/2)},e.prototype.isVisible=function(t,e){return void 0===e&&(e=t.floating),!0===e||!0===t.floating?renderer.overlaps(t.getBounds()):t.getBounds().overlaps(this)},e.prototype.localToWorld=function(t,e,i){return(i=i||pull("Vector2d")).set(t,e).add(this.pos).sub(world.pos),this.currentTransform.isIdentity()||this.invCurrentTransform.apply(i),i},e.prototype.worldToLocal=function(t,e,i){return(i=i||pull("Vector2d")).set(t,e),this.currentTransform.isIdentity()||this.currentTransform.apply(i),i.sub(this.pos).add(world.pos)},e.prototype.drawFX=function(t){this._fadeIn.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeIn.color),t.fillRect(0,0,this.width,this.height),t.restore(),1===this._fadeIn.color.alpha&&(this._fadeIn.tween=null,push(this._fadeIn.color),this._fadeIn.color=null)),this._fadeOut.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeOut.color),t.fillRect(0,0,this.width,this.height),t.restore(),0===this._fadeOut.color.alpha&&(this._fadeOut.tween=null,push(this._fadeOut.color),this._fadeOut.color=null))},e.prototype.draw=function(t,e){var i=this.pos.x+this.offset.x,r=this.pos.y+this.offset.y;e.currentTransform.translate(-i,-r),t.setProjection(this.projectionMatrix),t.clipRect(0,0,this.width,this.height),this.preDraw(t),e.preDraw(t),e.draw(t,this),this.drawFX(t),e.postDraw(t),this.postDraw(t),e.currentTransform.translate(i,r)},e}(Renderable),default_camera,default_settings={cameras:[]},Stage=function(t){this.cameras=new Map,this.settings=Object.assign(default_settings,t||{})};Stage.prototype.reset=function(){var t=this;if(this.settings.cameras.forEach((function(e){t.cameras.set(e.name,e)})),!1===this.cameras.has("default")){if(void 0===default_camera){var e=renderer.getWidth(),i=renderer.getHeight();default_camera=new Camera2d(0,0,e,i)}this.cameras.set("default",default_camera)}reset(),this.onResetEvent.apply(this,arguments)},Stage.prototype.update=function(t){var e=world.update(t);return this.cameras.forEach((function(i){i.update(t)&&(e=!0)})),e},Stage.prototype.draw=function(t){this.cameras.forEach((function(e){e.draw(t,world)}))},Stage.prototype.destroy=function(){this.cameras.clear(),this.onDestroyEvent.apply(this,arguments)},Stage.prototype.onResetEvent=function(){"function"==typeof this.settings.onResetEvent&&this.settings.onResetEvent.apply(this,arguments)},Stage.prototype.onDestroyEvent=function(){"function"==typeof this.settings.onDestroyEvent&&this.settings.onDestroyEvent.apply(this,arguments)};var ProgressBar=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.barHeight=o,this.anchorPoint.set(0,0),on(LOADER_PROGRESS,this.onProgressUpdate,this),on(VIEWPORT_ONRESIZE,this.resize,this),this.anchorPoint.set(0,0),this.progress=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onProgressUpdate=function(t){this.progress=~~(t*this.width),this.isDirty=!0},e.prototype.draw=function(t){t.setColor("black"),t.fillRect(this.pos.x,viewport.centerY,t.getWidth(),this.barHeight/2),t.setColor("#55aa00"),t.fillRect(this.pos.x,viewport.centerY,this.progress,this.barHeight/2)},e.prototype.onDestroyEvent=function(){off(LOADER_PROGRESS,this.onProgressUpdate),off(VIEWPORT_ONRESIZE,this.resize)},e}(Renderable),IconLogo=function(t){function e(e,i){t.call(this,e,i,100,85),this.iconCanvas=createCanvas(renderer.WebGLVersion>1?this.width:nextPowerOfTwo(this.width),renderer.WebGLVersion>1?this.height:nextPowerOfTwo(this.height),!1);var r=renderer.getContext2d(this.iconCanvas);r.beginPath(),r.moveTo(.7,48.9),r.bezierCurveTo(10.8,68.9,38.4,75.8,62.2,64.5),r.bezierCurveTo(86.1,53.1,97.2,27.7,87,7.7),r.lineTo(87,7.7),r.bezierCurveTo(89.9,15.4,73.9,30.2,50.5,41.4),r.bezierCurveTo(27.1,52.5,5.2,55.8,.7,48.9),r.lineTo(.7,48.9),r.closePath(),r.fillStyle="rgb(255, 255, 255)",r.fill(),r.beginPath(),r.moveTo(84,7),r.bezierCurveTo(87.6,14.7,72.5,30.2,50.2,41.6),r.bezierCurveTo(27.9,53,6.9,55.9,3.2,48.2),r.bezierCurveTo(-.5,40.4,14.6,24.9,36.9,13.5),r.bezierCurveTo(59.2,2.2,80.3,-.8,84,7),r.lineTo(84,7),r.closePath(),r.lineWidth=5.3,r.strokeStyle="rgb(255, 255, 255)",r.lineJoin="miter",r.miterLimit=4,r.stroke(),this.anchorPoint.set(.5,.5)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.draw=function(t){t.drawImage(this.iconCanvas,t.getWidth()/2,this.pos.y)},e}(Renderable),DefaultLoadingScreen=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(){world.backgroundColor.parseCSS("#202020"),world.addChild(new ProgressBar(0,renderer.getHeight()/2,renderer.getWidth(),8),1),world.addChild(new IconLogo(renderer.getWidth()/2,renderer.getHeight()/2-16-35),2);var t=pull("Text",renderer.getWidth()/2,renderer.getHeight()/2+16,{font:"century gothic",size:32,fillStyle:"white",textAlign:"left",textBaseline:"top",text:"melon",offScreenCanvas:renderer.WebGLVersion>=1});t.anchorPoint.set(0,0);var e=pull("Text",renderer.getWidth()/2,renderer.getHeight()/2+16,{font:"century gothic",size:32,fillStyle:"#55aa00",textAlign:"left",textBaseline:"top",bold:!0,text:"JS",offScreenCanvas:renderer.WebGLVersion>=1});e.anchorPoint.set(0,0);var i=t.getBounds().width+e.getBounds().width;t.pos.x=renderer.getWidth()/2-i/2,e.pos.x=t.pos.x+t.getBounds().width,world.addChild(t,2),world.addChild(e,2)},e}(Stage),_state=-1,_animFrameId=-1,_isPaused=!1,_stages={},_fade={color:"",duration:0},_onSwitchComplete=null,_extraArgs=null,_pauseTime=0;function _startRunLoop(){-1===_animFrameId&&-1!==_state&&(timer$1.reset(),_animFrameId=globalThis.requestAnimationFrame(_renderFrame))}function _resumeRunLoop(){_isPaused&&-1!==_state&&(timer$1.reset(),_isPaused=!1)}function _pauseRunLoop(){_isPaused=!0}function _renderFrame(t){var e=_stages[_state].stage;update$1(t,e),draw(e),-1!==_animFrameId&&(_animFrameId=globalThis.requestAnimationFrame(_renderFrame))}function _stopRunLoop(){globalThis.cancelAnimationFrame(_animFrameId),_animFrameId=-1}function _switchState(t){_stopRunLoop(),_stages[_state]&&_stages[_state].stage.destroy(),_stages[t]&&(_stages[_state=t].stage.reset.apply(_stages[_state].stage,_extraArgs),_startRunLoop(),_onSwitchComplete&&_onSwitchComplete(),repaint())}on(BOOT,(function(){state.set(state.LOADING,new DefaultLoadingScreen),state.set(state.DEFAULT,new Stage),on(VIDEO_INIT,(function(){state.change(state.DEFAULT,!0)}))}));var state={LOADING:0,MENU:1,READY:2,PLAY:3,GAMEOVER:4,GAME_END:5,SCORE:6,CREDITS:7,SETTINGS:8,DEFAULT:9,USER:100,stop:function(t){void 0===t&&(t=!1),_state!==this.LOADING&&this.isRunning()&&(_stopRunLoop(),!0===t&&t(),_pauseTime=globalThis.performance.now(),emit(STATE_STOP))},pause:function(t){void 0===t&&(t=!1),_state===this.LOADING||this.isPaused()||(_pauseRunLoop(),!0===t&&pauseTrack(),_pauseTime=globalThis.performance.now(),emit(STATE_PAUSE))},restart:function(t){void 0===t&&(t=!1),this.isRunning()||(_startRunLoop(),!0===t&&resumeTrack(),_pauseTime=globalThis.performance.now()-_pauseTime,repaint(),emit(STATE_RESTART,_pauseTime))},resume:function(t){void 0===t&&(t=!1),this.isPaused()&&(_resumeRunLoop(),!0===t&&resumeTrack(),_pauseTime=globalThis.performance.now()-_pauseTime,emit(STATE_RESUME,_pauseTime))},isRunning:function(){return-1!==_animFrameId},isPaused:function(){return _isPaused},set:function(t,e,i){if(void 0===i&&(i=!1),!(e instanceof Stage))throw new Error(e+" is not an instance of me.Stage");_stages[t]={},_stages[t].stage=e,_stages[t].transition=!0,!0===i&&this.change(t)},current:function(){if(void 0!==_stages[_state])return _stages[_state].stage},transition:function(t,e,i){"fade"===t&&(_fade.color=e,_fade.duration=i)},setTransition:function(t,e){_stages[t].transition=e},change:function(t,e){if(void 0===_stages[t])throw new Error("Undefined Stage for state '"+t+"'");this.isCurrent(t)||(_extraArgs=null,arguments.length>1&&(_extraArgs=Array.prototype.slice.call(arguments,1)),_fade.duration&&_stages[t].transition?(_onSwitchComplete=function(){viewport.fadeOut(_fade.color,_fade.duration)},viewport.fadeIn(_fade.color,_fade.duration,(function(){defer(_switchState,this,t)}))):!0===e?_switchState(t):defer(_switchState,this,t))},isCurrent:function(t){return _state===t}};function setTMXValue(name,type,value){var match;if("string"!=typeof value)return value;switch(type){case"int":case"float":value=Number(value);break;case"bool":value="true"===value;break;default:if(!value||isBoolean(value))value=!value||"true"===value;else if(isNumeric(value))value=Number(value);else if(0===value.search(/^json:/i)){match=value.split(/^json:/i)[1];try{value=JSON.parse(match)}catch(t){throw new Error("Unable to parse JSON: "+match)}}else if(0===value.search(/^eval:/i)){match=value.split(/^eval:/i)[1];try{value=eval(match)}catch(t){throw new Error("Unable to evaluate: "+match)}}else((match=value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/))||(match=value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/)))&&(value="#"+match[2]+match[1]);0===name.search(/^(ratio|anchorPoint)$/)&&"number"==typeof value&&(value={x:value,y:value})}return value}function parseAttributes(t,e){if(e.attributes&&e.attributes.length>0)for(var i=0;i<e.attributes.length;i++){var r=e.attributes.item(i);void 0!==r.name?t[r.name]=r.value:t[r.nodeName]=r.nodeValue}}function decompress(){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")}function decodeCSV(t){for(var e=t.replace("\n","").trim().split(","),i=[],r=0;r<e.length;r++)i.push(+e[r]);return i}function decodeBase64AsArray(t,e){var i,r,o;e=e||1;var n=globalThis.atob(t.replace(/[^A-Za-z0-9\+\/\=]/g,"")),s=new Uint32Array(n.length/e);for(i=0,o=n.length/e;i<o;i++)for(s[i]=0,r=e-1;r>=0;--r)s[i]+=n.charCodeAt(i*e+r)<<(r<<3);return s}function decode(t,e,i){switch(i=i||"none",e=e||"none"){case"csv":return decodeCSV(t);case"base64":var r=decodeBase64AsArray(t,4);return"none"===i?r:decompress();case"none":return t;case"xml":throw new Error("XML encoding is deprecated, use base64 instead");default:throw new Error("Unknown layer encoding: "+e)}}function normalize(t,e){var i=e.nodeName;switch(i){case"data":var r=parse(e);r.text=r.text||r.chunk.text,r.encoding=r.encoding||"xml",t.data=decode(r.text,r.encoding,r.compression),t.encoding="none";break;case"imagelayer":case"layer":case"objectgroup":case"group":var o=parse(e);o.type="layer"===i?"tilelayer":i,o.image&&(o.image=o.image.source),t.layers=t.layers||[],t.layers.push(o);break;case"animation":t.animation=parse(e).frames;break;case"frame":case"object":var n=i+"s";t[n]=t[n]||[],t[n].push(parse(e));break;case"tile":var s=parse(e);s.image&&(s.imagewidth=s.image.width,s.imageheight=s.image.height,s.image=s.image.source),t.tiles=t.tiles||{},t.tiles[s.id]=s;break;case"tileset":var a=parse(e);a.image&&(a.imagewidth=a.image.width,a.imageheight=a.image.height,a.image=a.image.source),t.tilesets=t.tilesets||[],t.tilesets.push(a);break;case"polygon":case"polyline":t[i]=[];for(var h,l=parse(e).points.split(" "),c=0;c<l.length;c++)h=l[c].split(","),t[i].push({x:+h[0],y:+h[1]});break;case"properties":t.properties=parse(e);break;case"property":var u=parse(e),d=void 0!==u.value?u.value:u.text;t[u.name]=setTMXValue(u.name,u.type||"string",d);break;default:t[i]=parse(e)}}function parse(t){var e={},i="";if(1===t.nodeType&&parseAttributes(e,t),t.hasChildNodes())for(var r=0;r<t.childNodes.length;r++){var o=t.childNodes.item(r);switch(o.nodeType){case 1:normalize(e,o);break;case 3:i+=o.nodeValue.trim()}}return i&&(e.text=i),e}function applyTMXProperties(t,e){var i=e.properties,r=e.propertytypes;if(void 0!==i)for(var o in i)if(i.hasOwnProperty(o)){var n="string",s=o,a=i[o];void 0!==i[o].name&&(s=i[o].name),void 0!==r?n=r[o]:void 0!==i[o].type&&(n=i[o].type),void 0!==i[o].value&&(a=i[o].value),t[s]=setTMXValue(s,n,a)}}var src={},arraymultimap={},multimap={},__generator=commonjsGlobal&&commonjsGlobal.__generator||function(t,e){var i,r,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function a(n){return function(a){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,r&&(o=2&n[0]?r.return:n[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,n[1])).done)return o;switch(r=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return s.label++,{value:n[1],done:!1};case 5:s.label++,r=n[1],n=[0];continue;case 7:n=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1],o=n;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(n);break}o[2]&&s.ops.pop(),s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t],r=0}finally{i=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}},__values=commonjsGlobal&&commonjsGlobal.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],r=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=commonjsGlobal&&commonjsGlobal.__read||function(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,o,n=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(i=n.return)&&i.call(n)}finally{if(o)throw o.error}}return s};Object.defineProperty(multimap,"__esModule",{value:!0}),multimap.Multimap=void 0;var Multimap=function(){function t(t,e){var i,r;if(this.size_=0,this.map=new Map,this.operator=t,e)try{for(var o=__values(e),n=o.next();!n.done;n=o.next()){var s=__read(n.value,2),a=s[0],h=s[1];this.put(a,h)}}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return this}return Object.defineProperty(t.prototype,"size",{get:function(){return this.size_},enumerable:!1,configurable:!0}),t.prototype.get=function(t){var e=this.map.get(t);return e?this.operator.clone(e):this.operator.create()},t.prototype.put=function(t,e){var i=this.map.get(t);return i||(i=this.operator.create()),!!this.operator.add(e,i)&&(this.map.set(t,i),this.size_++,!0)},t.prototype.putAll=function(e,i){var r,o,n,s,a=0;if(i){var h=e,l=i;try{for(var c=__values(l),u=c.next();!u.done;u=c.next()){var d=u.value;this.put(h,d),a++}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}else{if(!(e instanceof t))throw new TypeError("unexpected arguments");try{for(var p=__values(e.entries()),f=p.next();!f.done;f=p.next()){var y=__read(f.value,2);h=y[0],d=y[1];this.put(h,d),a++}}catch(t){n={error:t}}finally{try{f&&!f.done&&(s=p.return)&&s.call(p)}finally{if(n)throw n.error}}}return a>0},t.prototype.has=function(t){return this.map.has(t)},t.prototype.hasEntry=function(t,e){return this.operator.has(e,this.get(t))},t.prototype.delete=function(t){return this.size_-=this.operator.size(this.get(t)),this.map.delete(t)},t.prototype.deleteEntry=function(t,e){var i=this.get(t);return!!this.operator.delete(e,i)&&(this.map.set(t,i),this.size_--,!0)},t.prototype.clear=function(){this.map.clear(),this.size_=0},t.prototype.keys=function(){return this.map.keys()},t.prototype.entries=function(){var t=this;return function(){var e,i,r,o,n,s,a,h,l,c,u,d,p,f;return __generator(this,(function(y){switch(y.label){case 0:y.trys.push([0,11,12,13]),e=__values(t.map.entries()),i=e.next(),y.label=1;case 1:if(i.done)return[3,10];r=__read(i.value,2),o=r[0],n=r[1],y.label=2;case 2:y.trys.push([2,7,8,9]),p=void 0,s=__values(n),a=s.next(),y.label=3;case 3:return a.done?[3,6]:(h=a.value,[4,[o,h]]);case 4:y.sent(),y.label=5;case 5:return a=s.next(),[3,3];case 6:return[3,9];case 7:return l=y.sent(),p={error:l},[3,9];case 8:try{a&&!a.done&&(f=s.return)&&f.call(s)}finally{if(p)throw p.error}return[7];case 9:return i=e.next(),[3,1];case 10:return[3,13];case 11:return c=y.sent(),u={error:c},[3,13];case 12:try{i&&!i.done&&(d=e.return)&&d.call(e)}finally{if(u)throw u.error}return[7];case 13:return[2]}}))}()},t.prototype.values=function(){var t=this;return function(){var e,i,r,o,n,s;return __generator(this,(function(a){switch(a.label){case 0:a.trys.push([0,5,6,7]),e=__values(t.entries()),i=e.next(),a.label=1;case 1:return i.done?[3,4]:(r=__read(i.value,2),[4,r[1]]);case 2:a.sent(),a.label=3;case 3:return i=e.next(),[3,1];case 4:return[3,7];case 5:return o=a.sent(),n={error:o},[3,7];case 6:try{i&&!i.done&&(s=e.return)&&s.call(e)}finally{if(n)throw n.error}return[7];case 7:return[2]}}))}()},t.prototype.forEach=function(t,e){var i,r;try{for(var o=__values(this.entries()),n=o.next();!n.done;n=o.next()){var s=__read(n.value,2),a=s[0],h=s[1];t.call(void 0===e?this:e,h,a,this)}}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}},t.prototype[Symbol.iterator]=function(){return this.entries()},t.prototype.asMap=function(){var t,e,i=new Map;try{for(var r=__values(this.keys()),o=r.next();!o.done;o=r.next()){var n=o.value;i.set(n,this.operator.clone(this.get(n)))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}return i},t}();multimap.Multimap=Multimap;var __extends$1=commonjsGlobal&&commonjsGlobal.__extends||(extendStatics=function(t,e){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},extendStatics(t,e)},function(t,e){function i(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),extendStatics;Object.defineProperty(arraymultimap,"__esModule",{value:!0}),arraymultimap.ArrayMultimap=void 0;var multimap_1$1=multimap,ArrayMultimap=function(t){function e(e){return t.call(this,new ArrayOperator,e)||this}return __extends$1(e,t),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"ArrayMultimap"},enumerable:!1,configurable:!0}),e}(multimap_1$1.Multimap);arraymultimap.ArrayMultimap=ArrayMultimap;var ArrayOperator=function(){function t(){}return t.prototype.create=function(){return[]},t.prototype.clone=function(t){return t.slice()},t.prototype.add=function(t,e){return e.push(t),!0},t.prototype.size=function(t){return t.length},t.prototype.delete=function(t,e){var i=e.indexOf(t);return i>-1&&(e.splice(i,1),!0)},t.prototype.has=function(t,e){return e.includes(t)},t}(),setmultimap={},__extends=commonjsGlobal&&commonjsGlobal.__extends||function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(setmultimap,"__esModule",{value:!0}),setmultimap.SetMultimap=void 0;var multimap_1=multimap,SetMultimap=function(t){function e(e){return t.call(this,new SetOperator,e)||this}return __extends(e,t),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"SetMultimap"},enumerable:!1,configurable:!0}),e}(multimap_1.Multimap);setmultimap.SetMultimap=SetMultimap;var SetOperator=function(){function t(){}return t.prototype.create=function(){return new Set},t.prototype.clone=function(t){return new Set(t)},t.prototype.add=function(t,e){var i=e.size;return e.add(t),i!==e.size},t.prototype.size=function(t){return t.size},t.prototype.delete=function(t,e){return e.delete(t)},t.prototype.has=function(t,e){return e.has(t)},t}();!function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.SetMultimap=t.ArrayMultimap=void 0;var e=arraymultimap;Object.defineProperty(t,"ArrayMultimap",{enumerable:!0,get:function(){return e.ArrayMultimap}});var i=setmultimap;Object.defineProperty(t,"SetMultimap",{enumerable:!0,get:function(){return i.SetMultimap}})}(src);var TextureCache=function(t){this.cache=new src.ArrayMultimap,this.tinted=new Map,this.units=new Map,this.max_size=t||1/0,this.clear()};function createAtlas(t,e,i,r){return void 0===i&&(i="default"),void 0===r&&(r="no-repeat"),{meta:{app:"melonJS",size:{w:t,h:e},repeat:r,image:"default"},frames:[{filename:i,frame:{x:0,y:0,w:t,h:e}}]}}TextureCache.prototype.clear=function(){this.cache.clear(),this.tinted.clear(),this.units.clear(),this.length=0},TextureCache.prototype.validate=function(){if(this.length>=this.max_size)throw new Error("Texture cache overflow: "+this.max_size+" texture units available for this GPU.")},TextureCache.prototype.get=function(t,e){var i;return void 0===e?i=this.cache.get(t)[0]:this.cache.forEach((function(r,o){var n=r.getAtlas();o===t&&n[0].width===e.framewidth&&n[0].height===e.frameheight&&(i=r)})),void 0===i&&(e||(e=createAtlas(t.width,t.height,t.src?getBasename(t.src):void 0)),i=new TextureAtlas(e,t,!1),this.set(t,i)),i},TextureCache.prototype.delete=function(t){this.cache.has(t)||this.cache.delete(t)},TextureCache.prototype.tint=function(t,e){var i=this.tinted.get(t);return void 0===i&&(i=this.tinted.set(t,new Map)),i.has(e)||i.set(e,renderer.tint(t,e,"multiply")),i.get(e)},TextureCache.prototype.set=function(t,e){var i=t.width,r=t.height;if(!(1!==renderer.WebGLVersion||isPowerOfTwo(i)&&isPowerOfTwo(r))){var o=void 0!==t.src?t.src:t;console.warn("[Texture] "+o+" is not a POT texture ("+i+"x"+r+")")}return this.cache.put(t,e)},TextureCache.prototype.getUnit=function(t){return this.units.has(t)||(this.validate(),this.units.set(t,this.length++)),this.units.get(t)};var TextureAtlas=function(t,e,i){var r=this;if(this.format=null,this.sources=new Map,this.atlases=new Map,void 0!==t)for(var o in t=Array.isArray(t)?t:[t]){var n=t[o];if(void 0!==n.meta){if(n.meta.app.includes("texturepacker")||n.meta.app.includes("free-tex-packer")){if(this.format="texturepacker",void 0===e){var s=loader.getImage(n.meta.image);if(!s)throw new Error("Atlas texture '"+s+"' not found");this.sources.set(n.meta.image,s)}else this.sources.set(n.meta.image||"default","string"==typeof e?loader.getImage(e):e);this.repeat="no-repeat"}else if(n.meta.app.includes("ShoeBox")){if(!n.meta.exporter||!n.meta.exporter.includes("melonJS"))throw new Error("ShoeBox requires the JSON exporter : https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx");this.format="ShoeBox",this.repeat="no-repeat",this.sources.set("default","string"==typeof e?loader.getImage(e):e)}else n.meta.app.includes("melonJS")&&(this.format="melonJS",this.repeat=n.meta.repeat||"no-repeat",this.sources.set("default","string"==typeof e?loader.getImage(e):e));this.atlases.set(n.meta.image||"default",this.parse(n))}else void 0!==n.framewidth&&void 0!==n.frameheight&&(this.format="Spritesheet (fixed cell size)",this.repeat="no-repeat",void 0!==e&&(n.image="string"==typeof e?loader.getImage(e):e),this.atlases.set("default",this.parseFromSpriteSheet(n)),this.sources.set("default",n.image))}if(0===this.atlases.length)throw new Error("texture atlas format not supported");!1!==i&&this.sources.forEach((function(t){i instanceof TextureCache?i.set(t,r):renderer.cache.set(t,r)}))};TextureAtlas.prototype.parse=function(t){var e=this,i={};return t.frames.forEach((function(r){if(r.hasOwnProperty("filename")){var o,n,s=r.frame,a=r.spriteSourceSize&&r.sourceSize&&r.pivot;a&&(o=r.sourceSize.w*r.pivot.x-(r.trimmed?r.spriteSourceSize.x:0),n=r.sourceSize.h*r.pivot.y-(r.trimmed?r.spriteSourceSize.y:0)),i[r.filename]={name:r.filename,texture:t.meta.image||"default",offset:new Vector2d(s.x,s.y),anchorPoint:a?new Vector2d(o/s.w,n/s.h):null,trimmed:!!r.trimmed,width:s.w,height:s.h,angle:!0===r.rotated?-ETA:0},e.addUVs(i,r.filename,t.meta.size.w,t.meta.size.h)}})),i},TextureAtlas.prototype.parseFromSpriteSheet=function(t){var e={},i=t.image,r=t.spacing||0,o=t.margin||0,n=i.width,s=i.height,a=pull("Vector2d",~~((n-o+r)/(t.framewidth+r)),~~((s-o+r)/(t.frameheight+r)));if(n%(t.framewidth+r)!=0||s%(t.frameheight+r)!=0){var h=a.x*(t.framewidth+r),l=a.y*(t.frameheight+r);h-n!==r&&l-s!==r&&(n=h,s=l,console.warn("Spritesheet Texture for image: "+i.src+" is not divisible by "+(t.framewidth+r)+"x"+(t.frameheight+r)+", truncating effective size to "+n+"x"+s))}for(var c=0,u=a.x*a.y;c<u;c++){var d=""+c;e[d]={name:d,texture:"default",offset:new Vector2d(o+(r+t.framewidth)*(c%a.x),o+(r+t.frameheight)*~~(c/a.x)),anchorPoint:t.anchorPoint||null,trimmed:!1,width:t.framewidth,height:t.frameheight,angle:0},this.addUVs(e,d,n,s)}return push(a),e},TextureAtlas.prototype.getAtlas=function(t){return"string"==typeof t?this.atlases.get(t):this.atlases.values().next().value},TextureAtlas.prototype.getFormat=function(){return this.format},TextureAtlas.prototype.getTexture=function(t){return"object"==typeof t&&"string"==typeof t.texture?this.sources.get(t.texture):this.sources.values().next().value},TextureAtlas.prototype.addRegion=function(t,e,i,r,o){!0===renderer.settings.verbose&&console.warn("Adding texture region",t,"for texture",this);var n=this.getTexture(),s=this.getAtlas(),a=n.width,h=n.height;return s[t]={name:t,offset:new Vector2d(e,i),width:r,height:o,angle:0},this.addUVs(s,t,a,h),s[t]},TextureAtlas.prototype.getRegion=function(t,e){var i;return"string"==typeof e?i=this.getAtlas(e)[t]:this.atlases.forEach((function(e){void 0!==e[t]&&(i=e[t])})),i},TextureAtlas.prototype.getUVs=function(t){var e=this.getRegion(t);if(void 0===e){var i=t.split(","),r=+i[0],o=+i[1],n=+i[2],s=+i[3];e=this.addRegion(t,r,o,n,s)}return e.uvs},TextureAtlas.prototype.addUVs=function(t,e,i,r){if(renderer instanceof WebGLRenderer){var o=t[e].offset,n=t[e].width,s=t[e].height;t[e].uvs=new Float32Array([o.x/i,o.y/r,(o.x+n)/i,(o.y+s)/r]),t[o.x+","+o.y+","+i+","+r]=t[e]}return t[e].uvs},TextureAtlas.prototype.createSpriteFromName=function(t,e,i){return void 0===i&&(i=!1),pull(!0===i?"me.NineSliceSprite":"me.Sprite",0,0,Object.assign({image:this,region:t},e||{}))},TextureAtlas.prototype.createAnimationFromName=function(t,e){for(var i,r=[],o={},n=0,s=0,a=0;a<t.length;++a){if(null==(i=this.getRegion(t[a])))throw new Error("Texture - region for "+t[a]+" not found");r[a]=i,o[t[a]]=a,n=Math.max(i.width,n),s=Math.max(i.height,s)}return new Sprite(0,0,Object.assign({image:this,framewidth:n,frameheight:s,margin:0,spacing:0,atlas:r,atlasIndices:o},e||{}))};var Sprite=function(t){function e(e,i,r){if(t.call(this,e,i,0,0),this.animationpause=!1,this.animationspeed=100,this.offset=pull("Vector2d",0,0),this.source=null,this.anim={},this.resetAnim=void 0,this.current={name:"default",length:0,offset:new Vector2d,width:0,height:0,angle:0,idx:0},this.dt=0,this._flicker={isFlickering:!1,duration:0,callback:null,state:!1},r.image instanceof TextureAtlas){if(this.source=r.image,this.image=this.source.getTexture(),this.textureAtlas=r.image,void 0!==r.region){var o=this.source.getRegion(r.region);if(!o)throw new Error("Texture - region for "+r.region+" not found");this.setRegion(o),this.current.width=r.framewidth||o.width,this.current.height=r.frameheight||o.height}}else{if(this.image="object"==typeof r.image?r.image:loader.getImage(r.image),!this.image)throw new Error("me.Sprite: '"+r.image+"' image/texture not found!");this.current.width=r.framewidth=r.framewidth||this.image.width,this.current.height=r.frameheight=r.frameheight||this.image.height,this.source=renderer.cache.get(this.image,r),this.textureAtlas=this.source.getAtlas()}void 0!==r.atlas&&(this.textureAtlas=r.atlas,this.atlasIndices=r.atlasIndices),this.width=this.current.width,this.height=this.current.height,void 0!==r.flipX&&this.flipX(!!r.flipX),void 0!==r.flipY&&this.flipY(!!r.flipY),void 0!==r.rotation&&this.rotate(r.rotation),r.anchorPoint&&this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y),void 0!==r.tint&&this.tint.setColor(r.tint),"string"==typeof r.name&&(this.name=r.name),void 0!==r.z&&(this.pos.z=r.z),0!==this.addAnimation("default",null)&&this.setCurrentAnimation("default"),this.autoTransform=!0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.isFlickering=function(){return this._flicker.isFlickering},e.prototype.flicker=function(t,e){return this._flicker.duration=t,this._flicker.duration<=0?(this._flicker.isFlickering=!1,this._flicker.callback=null):this._flicker.isFlickering||(this._flicker.callback=e,this._flicker.isFlickering=!0),this},e.prototype.addAnimation=function(t,e,i){this.anim[t]={name:t,frames:[],idx:0,length:0};var r=0;if("object"!=typeof this.textureAtlas)return 0;null==e&&(e=[],Object.keys(this.textureAtlas).forEach((function(t,i){e[i]=i})));for(var o=0,n=e.length;o<n;o++){var s,a=e[o],h=(s="number"==typeof a||"string"==typeof a?{name:a,delay:i||this.animationspeed}:a).name;if("number"==typeof h)void 0!==this.textureAtlas[h]&&(this.anim[t].frames[o]=Object.assign({},this.textureAtlas[h],s),r++);else{if(this.source.getFormat().includes("Spritesheet"))throw new Error("string parameters for addAnimation are not allowed for standard spritesheet based Texture");this.anim[t].frames[o]=Object.assign({},this.textureAtlas[this.atlasIndices[h]],s),r++}}return this.anim[t].length=r,r},e.prototype.setCurrentAnimation=function(t,e,i){if(!this.anim[t])throw new Error("animation id '"+t+"' not defined");return this.current.name=t,this.current.length=this.anim[this.current.name].length,this.resetAnim="string"==typeof e?this.setCurrentAnimation.bind(this,e,null,!0):"function"==typeof e?e:void 0,this.setAnimationFrame(this.current.idx),i||(this.dt=0),this.isDirty=!0,this},e.prototype.reverseAnimation=function(t){return void 0!==t&&void 0!==this.anim[t]?this.anim[t].frames.reverse():this.anim[this.current.name].frames.reverse(),this.isDirty=!0,this},e.prototype.isCurrentAnimation=function(t){return this.current.name===t},e.prototype.setRegion=function(t){return this.image=this.source.getTexture(t),this.current.offset.setV(t.offset),this.current.angle=t.angle,this.width=this.current.width=t.width,this.height=this.current.height=t.height,t.anchorPoint&&this.anchorPoint.set(this._flip.x&&!0===t.trimmed?1-t.anchorPoint.x:t.anchorPoint.x,this._flip.y&&!0===t.trimmed?1-t.anchorPoint.y:t.anchorPoint.y),this.isDirty=!0,this},e.prototype.setAnimationFrame=function(t){return this.current.idx=(t||0)%this.current.length,this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx))},e.prototype.getCurrentAnimationFrame=function(){return this.current.idx},e.prototype.getAnimationFrameObjectByIndex=function(t){return this.anim[this.current.name].frames[t]},e.prototype.update=function(e){if(!this.animationpause&&this.current&&this.current.length>0){var i=this.getAnimationFrameObjectByIndex(this.current.idx).delay;for(this.dt+=e;this.dt>=i;){this.isDirty=!0,this.dt-=i;var r=this.current.length>1?this.current.idx+1:this.current.idx;if(this.setAnimationFrame(r),0===this.current.idx&&"function"==typeof this.resetAnim&&!1===this.resetAnim()){this.setAnimationFrame(this.current.length-1),this.dt%=i;break}i=this.getAnimationFrameObjectByIndex(this.current.idx).delay}}return this._flicker.isFlickering&&(this._flicker.duration-=e,this._flicker.duration<0&&("function"==typeof this._flicker.callback&&this._flicker.callback(),this.flicker(-1)),this.isDirty=!0),t.prototype.update.call(this,e)},e.prototype.destroy=function(){push(this.offset),this.offset=void 0,t.prototype.destroy.call(this)},e.prototype.draw=function(t){if(!this._flicker.isFlickering||(this._flicker.state=!this._flicker.state,this._flicker.state)){var e=this.current,i=this.pos.x,r=this.pos.y,o=e.width,n=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-r),t.rotate(e.angle),i-=n,o=e.height,n=e.width),t.drawImage(this.image,a.x+s.x,a.y+s.y,o,n,i,r,o,n)}},e}(Renderable),TMX_FLIP_H=2147483648,TMX_FLIP_V=1073741824,TMX_FLIP_AD=536870912,TMX_CLEAR_BIT_MASK$1=536870911,Tile=function(t){function e(e,i,r,o){var n,s;if(t.call(this),o.isCollection){var a=o.getTileImage(r&TMX_CLEAR_BIT_MASK$1);n=a.width,s=a.height}else n=o.tilewidth,s=o.tileheight;this.setMinMax(0,0,n,s),this.tileset=o,this.currentTransform=null,this.col=e,this.row=i,this.tileId=r,this.flippedX=0!=(this.tileId&TMX_FLIP_H),this.flippedY=0!=(this.tileId&TMX_FLIP_V),this.flippedAD=0!=(this.tileId&TMX_FLIP_AD),this.flipped=this.flippedX||this.flippedY||this.flippedAD,!0===this.flipped&&(null===this.currentTransform&&(this.currentTransform=new Matrix2d),this.setTileTransform(this.currentTransform.identity())),this.tileId&=TMX_CLEAR_BIT_MASK$1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setTileTransform=function(t){t.translate(this.width/2,this.height/2),this.flippedAD&&(t.rotate(-90*Math.PI/180),t.scale(-1,1)),this.flippedX&&t.scale(this.flippedAD?1:-1,this.flippedAD?-1:1),this.flippedY&&t.scale(this.flippedAD?-1:1,this.flippedAD?1:-1),t.translate(-this.width/2,-this.height/2)},e.prototype.getRenderable=function(t){var e,i=this.tileset;if(i.animations.has(this.tileId)){var r=[],o=[];i.animations.get(this.tileId).frames.forEach((function(t){o.push(t.tileid),r.push({name:""+t.tileid,delay:t.duration})})),(e=i.texture.createAnimationFromName(o,t)).addAnimation(this.tileId-i.firstgid,r),e.setCurrentAnimation(this.tileId-i.firstgid)}else if(!0===i.isCollection){var n=i.getTileImage(this.tileId);(e=new Sprite(0,0,Object.assign({image:n}))).anchorPoint.set(0,0),e.scale(t.width/this.width,t.height/this.height),void 0!==t.rotation&&(e.anchorPoint.set(.5,.5),e.currentTransform.rotate(t.rotation),e.currentTransform.translate(t.width/2,t.height/2),t.rotation=void 0)}else(e=i.texture.createSpriteFromName(this.tileId-i.firstgid,t)).anchorPoint.set(0,0);return this.setTileTransform(e.currentTransform),e},e}(Bounds$1),Line=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.contains=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y;var i=this.points[0],r=this.points[1];return(e-i.y)*(r.x-i.x)==(r.y-i.y)*(t-i.x)},e.prototype.recalc=function(){var t=this.edges,e=this.normals,i=this.indices,r=this.points;if(2!==r.length)throw new Error("Requires exactly 2 points");return void 0===t[0]&&(t[0]=new Vector2d),t[0].copy(r[1]).sub(r[0]),void 0===e[0]&&(e[0]=new Vector2d),e[0].copy(t[0]).perp().normalize(),i.length=0,this},e.prototype.clone=function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new e(this.pos.x,this.pos.y,t)},e}(Polygon),Renderer=function(t){this.settings=t,this.isContextValid=!0,this.currentScissor=new Int32Array([0,0,this.settings.width,this.settings.height]),this.currentBlendMode="none",!0===device$1.ejecta?this.canvas=document.getElementById("canvas"):void 0!==globalThis.canvas?this.canvas=globalThis.canvas:void 0!==this.settings.canvas?this.canvas=this.settings.canvas:this.canvas=createCanvas(this.settings.zoomX,this.settings.zoomY),this.backBufferCanvas=this.canvas,this.context=null,this.currentColor=new Color(0,0,0,1),this.currentTint=new Color(255,255,255,1),this.projectionMatrix=new Matrix3d,this.uvOffset=0,on(GAME_RESET,(function(){renderer.reset()}))};Renderer.prototype.clear=function(){},Renderer.prototype.reset=function(){this.resetTransform(),this.setBlendMode(this.settings.blendMode),this.setColor("#000000"),this.clearTint(),this.cache.clear(),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},Renderer.prototype.getCanvas=function(){return this.backBufferCanvas},Renderer.prototype.getScreenCanvas=function(){return this.canvas},Renderer.prototype.getScreenContext=function(){return this.context},Renderer.prototype.getBlendMode=function(){return this.currentBlendMode},Renderer.prototype.getContext2d=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a 2d context");if(void 0===t.getContext)throw new Error("Your browser does not support HTML5 canvas.");"boolean"!=typeof e&&(e=!0);var i=t.getContext("2d",{alpha:e});return i.canvas||(i.canvas=t),this.setAntiAlias(i,this.settings.antiAlias),i},Renderer.prototype.getWidth=function(){return this.backBufferCanvas.width},Renderer.prototype.getHeight=function(){return this.backBufferCanvas.height},Renderer.prototype.getColor=function(){return this.currentColor},Renderer.prototype.globalAlpha=function(){return this.currentColor.glArray[3]},Renderer.prototype.overlaps=function(t){return t.left<=this.getWidth()&&t.right>=0&&t.top<=this.getHeight()&&t.bottom>=0},Renderer.prototype.resize=function(t,e){t===this.backBufferCanvas.width&&e===this.backBufferCanvas.height||(this.canvas.width=this.backBufferCanvas.width=t,this.canvas.height=this.backBufferCanvas.height=e,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=t,this.currentScissor[3]=e,emit(CANVAS_ONRESIZE,t,e))},Renderer.prototype.setAntiAlias=function(t,e){var i=t.canvas;setPrefixed("imageSmoothingEnabled",!0===e,t),!0!==e?(i.style["image-rendering"]="optimizeSpeed",i.style["image-rendering"]="-moz-crisp-edges",i.style["image-rendering"]="-o-crisp-edges",i.style["image-rendering"]="-webkit-optimize-contrast",i.style["image-rendering"]="optimize-contrast",i.style["image-rendering"]="crisp-edges",i.style["image-rendering"]="pixelated",i.style.msInterpolationMode="nearest-neighbor"):i.style["image-rendering"]="auto"},Renderer.prototype.setProjection=function(t){this.projectionMatrix.copy(t)},Renderer.prototype.stroke=function(t,e){t instanceof Rect||t instanceof Bounds$1?this.strokeRect(t.left,t.top,t.width,t.height,e):t instanceof Line||t instanceof Polygon?this.strokePolygon(t,e):t instanceof Ellipse&&this.strokeEllipse(t.pos.x,t.pos.y,t.radiusV.x,t.radiusV.y,e)},Renderer.prototype.tint=function(t,e,i){var r=createCanvas(t.width,t.height,!0),o=this.getContext2d(r);return o.save(),o.fillStyle=e instanceof Color?e.toRGB():e,o.fillRect(0,0,t.width,t.height),o.globalCompositeOperation=i||"multiply",o.drawImage(t,0,0),o.globalCompositeOperation="destination-atop",o.drawImage(t,0,0),o.restore(),r},Renderer.prototype.fill=function(t){this.stroke(t,!0)},Renderer.prototype.setMask=function(t){},Renderer.prototype.clearMask=function(){},Renderer.prototype.setTint=function(t,e){void 0===e&&(e=t.alpha),this.currentTint.copy(t),this.currentTint.alpha*=e},Renderer.prototype.clearTint=function(){this.currentTint.setColor(255,255,255,1)},Renderer.prototype.drawFont=function(){};var CanvasRenderer=function(t){function e(e){var i=this;t.call(this,e),this.context=this.getContext2d(this.getScreenCanvas(),this.settings.transparent),this.settings.doubleBuffering?(this.backBufferCanvas=createCanvas(this.settings.width,this.settings.height,!0),this.backBufferContext2D=this.getContext2d(this.backBufferCanvas)):(this.backBufferCanvas=this.getScreenCanvas(),this.backBufferContext2D=this.context),this.setBlendMode(this.settings.blendMode),this.setColor(this.currentColor),this.cache=new TextureCache,!1===this.settings.textureSeamFix||this.settings.antiAlias||(this.uvOffset=1),this.getScreenCanvas().addEventListener("contextlost",(function(t){t.preventDefault(),i.isContextValid=!1,event.emit(event.ONCONTEXT_LOST,i)}),!1),this.getScreenCanvas().addEventListener("contextrestored",(function(){i.isContextValid=!0,event.emit(event.ONCONTEXT_RESTORED,i),me.game.repaint()}),!1)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),this.clearColor(this.currentColor,!0!==this.settings.transparent)},e.prototype.resetTransform=function(){this.backBufferContext2D.setTransform(1,0,0,1,0,0)},e.prototype.setBlendMode=function(t,e){switch(void 0===t&&(t="normal"),e=e||this.getContext(),this.currentBlendMode=t,t){case"screen":e.globalCompositeOperation="screen";break;case"lighter":case"additive":e.globalCompositeOperation="lighter";break;case"multiply":e.globalCompositeOperation="multiply";break;default:e.globalCompositeOperation="source-over",this.currentBlendMode="normal"}this.settings.doubleBuffering&&this.settings.transparent&&(this.context.globalCompositeOperation="copy")},e.prototype.clear=function(){this.settings.transparent&&this.clearColor("rgba(0,0,0,0)",!0)},e.prototype.flush=function(){this.settings.doubleBuffering&&this.context.drawImage(this.backBufferCanvas,0,0)},e.prototype.clearColor=function(t,e){void 0===t&&(t="#000000"),this.save(),this.resetTransform(),this.backBufferContext2D.globalCompositeOperation=e?"copy":"source-over",this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t,this.fillRect(0,0,this.backBufferCanvas.width,this.backBufferCanvas.height),this.restore()},e.prototype.clearRect=function(t,e,i,r){this.backBufferContext2D.clearRect(t,e,i,r)},e.prototype.createPattern=function(t,e){return this.backBufferContext2D.createPattern(t,e)},e.prototype.drawImage=function(t,e,i,r,o,n,s,a,h){if(!(this.backBufferContext2D.globalAlpha<1/255)){void 0===r?(r=a=t.width,o=h=t.height,n=e,s=i,e=0,i=0):void 0===n&&(n=e,s=i,a=r,h=o,r=t.width,o=t.height,e=0,i=0),!1===this.settings.subPixel&&(n=~~n,s=~~s);var l=t,c=this.currentTint.toArray();1===c[0]&&1===c[1]&&1===c[2]||(l=this.cache.tint(t,this.currentTint.toRGB())),this.backBufferContext2D.drawImage(l,e,i,r,o,n,s,a,h)}},e.prototype.drawPattern=function(t,e,i,r,o){if(!(this.backBufferContext2D.globalAlpha<1/255)){var n=this.backBufferContext2D.fillStyle;this.backBufferContext2D.fillStyle=t,this.backBufferContext2D.fillRect(e,i,r,o),this.backBufferContext2D.fillStyle=n}},e.prototype.strokeArc=function(t,e,i,r,o,n,s){void 0===s&&(s=!1);var a=this.backBufferContext2D;a.globalAlpha<1/255||(a.translate(t,e),a.beginPath(),a.arc(0,0,i,r,o,n||!1),a[!0===s?"fill":"stroke"](),a.translate(-t,-e))},e.prototype.fillArc=function(t,e,i,r,o,n){this.strokeArc(t,e,i,r,o,n||!1,!0)},e.prototype.strokeEllipse=function(t,e,i,r,o){void 0===o&&(o=!1);var n=this.backBufferContext2D;if(!(n.globalAlpha<1/255)){var s=t-i,a=t+i,h=e-r,l=e+r,c=.551784*i,u=.551784*r,d=t-c,p=t+c,f=e-u,y=e+u;n.beginPath(),n.moveTo(t,h),n.bezierCurveTo(p,h,a,f,a,e),n.bezierCurveTo(a,y,p,l,t,l),n.bezierCurveTo(d,l,s,y,s,e),n.bezierCurveTo(s,f,d,h,t,h),n[!0===o?"fill":"stroke"](),n.closePath()}},e.prototype.fillEllipse=function(t,e,i,r){this.strokeEllipse(t,e,i,r,!0)},e.prototype.strokeLine=function(t,e,i,r){var o=this.backBufferContext2D;o<1/255||(o.beginPath(),o.moveTo(t,e),o.lineTo(i,r),o.stroke())},e.prototype.fillLine=function(t,e,i,r){this.strokeLine(t,e,i,r)},e.prototype.strokePolygon=function(t,e){void 0===e&&(e=!1);var i=this.backBufferContext2D;if(!(i.globalAlpha<1/255)){var r;this.translate(t.pos.x,t.pos.y),i.beginPath(),i.moveTo(t.points[0].x,t.points[0].y);for(var o=1;o<t.points.length;o++)r=t.points[o],i.lineTo(r.x,r.y);i.lineTo(t.points[0].x,t.points[0].y),i[!0===e?"fill":"stroke"](),i.closePath(),this.translate(-t.pos.x,-t.pos.y)}},e.prototype.fillPolygon=function(t){this.strokePolygon(t,!0)},e.prototype.strokeRect=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillRect(t,e,i,r);else{if(this.backBufferContext2D.globalAlpha<1/255)return;this.backBufferContext2D.strokeRect(t,e,i,r)}},e.prototype.fillRect=function(t,e,i,r){this.backBufferContext2D.globalAlpha<1/255||this.backBufferContext2D.fillRect(t,e,i,r)},e.prototype.getContext=function(){return this.backBufferContext2D},e.prototype.getFontContext=function(){return this.getContext()},e.prototype.save=function(){this.backBufferContext2D.save()},e.prototype.restore=function(){this.backBufferContext2D.restore(),this.currentColor.glArray[3]=this.backBufferContext2D.globalAlpha,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},e.prototype.rotate=function(t){this.backBufferContext2D.rotate(t)},e.prototype.scale=function(t,e){this.backBufferContext2D.scale(t,e)},e.prototype.setColor=function(t){this.backBufferContext2D.strokeStyle=this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t},e.prototype.setGlobalAlpha=function(t){this.backBufferContext2D.globalAlpha=this.currentColor.glArray[3]=t},e.prototype.setLineWidth=function(t){this.backBufferContext2D.lineWidth=t},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=t.toArray(),i=e[0],r=e[1],o=e[3],n=e[4],s=e[6],a=e[7];!1===this.settings.subPixel&&(s|=0,a|=0),this.backBufferContext2D.transform(i,r,o,n,s,a)},e.prototype.translate=function(t,e){!1===this.settings.subPixel?this.backBufferContext2D.translate(~~t,~~e):this.backBufferContext2D.translate(t,e)},e.prototype.clipRect=function(t,e,i,r){var o=this.backBufferCanvas;if(0!==t||0!==e||i!==o.width||r!==o.height){var n=this.currentScissor;if(n[0]!==t||n[1]!==e||n[2]!==i||n[3]!==r){var s=this.backBufferContext2D;s.beginPath(),s.rect(t,e,i,r),s.clip(),n[0]=t,n[1]=e,n[2]=i,n[3]=r}}},e.prototype.setMask=function(t){var e=this.backBufferContext2D,i=t.pos.x,r=t.pos.y;if(e.save(),t instanceof Ellipse){var o=t.radiusV.x,n=t.radiusV.y,s=i-o,a=i+o,h=r-n,l=r+n,c=.551784*o,u=.551784*n,d=i-c,p=i+c,f=r-u,y=r+u;e.beginPath(),e.moveTo(i,h),e.bezierCurveTo(p,h,a,f,a,r),e.bezierCurveTo(a,y,p,l,i,l),e.bezierCurveTo(d,l,s,y,s,r),e.bezierCurveTo(s,f,d,h,i,h)}else{var g;e.beginPath(),e.moveTo(i+t.points[0].x,r+t.points[0].y);for(var v=1;v<t.points.length;v++)g=t.points[v],e.lineTo(i+g.x,r+g.y)}e.clip()},e.prototype.clearMask=function(){this.backBufferContext2D.restore()},e}(Renderer);function initArray(t){t.layerData=new Array(t.cols);for(var e=0;e<t.cols;e++){t.layerData[e]=new Array(t.rows);for(var i=0;i<t.rows;i++)t.layerData[e][i]=null}}function setLayerData(t,e){var i=0;initArray(t);for(var r=0;r<t.rows;r++)for(var o=0;o<t.cols;o++){var n=e[i++];0!==n&&(t.layerData[o][r]=t.getTileById(n,o,r))}}function preRenderLayer(t,e){for(var i=0;i<t.rows;i++)for(var r=0;r<t.cols;r++){var o=t.layerData[r][i];o instanceof Tile&&t.getRenderer().drawTile(e,r,i,o)}}var TMXLayer=function(t){function e(e,i,r,o,n,s,a){t.call(this,0,0,0,0),this.tilewidth=i.tilewidth||r,this.tileheight=i.tileheight||o,this.orientation=n,this.tilesets=s,this.tileset=this.tilesets?this.tilesets.getTilesetByIndex(0):null,this.maxTileSize={width:0,height:0};for(var h=0;h<this.tilesets.length;h++){var l=this.tilesets.getTilesetByIndex(h);this.maxTileSize.width=Math.max(this.maxTileSize.width,l.tilewidth),this.maxTileSize.height=Math.max(this.maxTileSize.height,l.tileheight)}this.animatedTilesets=[],this.isAnimated=!1,this.renderorder=i.renderorder||"right-down",this.pos.z=a,this.anchorPoint.set(0,0),this.name=i.name,this.cols=+i.width,this.rows=+i.height;var c=void 0!==i.visible?+i.visible:1;this.setOpacity(c?+i.opacity:0),"string"==typeof i.tintcolor&&this.tint.parseHex(i.tintcolor,!0),"isometric"===this.orientation?(this.width=(this.cols+this.rows)*(this.tilewidth/2),this.height=(this.cols+this.rows)*(this.tileheight/2)):(this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight),applyTMXProperties(this,i),void 0===this.preRender&&(this.preRender=world.preRender),this.setRenderer(e.getRenderer()),setLayerData(this,decode(i.data,i.encoding,i.compression))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onActivateEvent=function(){if(void 0===this.animatedTilesets&&(this.animatedTilesets=[]),this.tilesets)for(var t=this.tilesets.tilesets,e=0;e<t.length;e++)t[e].isAnimated&&this.animatedTilesets.push(t[e]);this.isAnimated=this.animatedTilesets.length>0,this.isAnimated&&(this.preRender=!1),this.getBounds().addBounds(this.getRenderer().getBounds(),!0),this.getBounds().shift(this.pos),!0!==this.preRender||this.canvasRenderer||(this.canvasRenderer=new CanvasRenderer({canvas:createCanvas(this.width,this.height),widht:this.width,heigth:this.height,transparent:!0}),preRenderLayer(this,this.canvasRenderer))},e.prototype.onDeactivateEvent=function(){this.animatedTilesets=void 0},e.prototype.setRenderer=function(t){this.renderer=t},e.prototype.getRenderer=function(){return this.renderer},e.prototype.getTileId=function(t,e){var i=this.getTile(t,e);return i?i.tileId:null},e.prototype.getTile=function(t,e){var i=null;if(this.contains(t,e)){var r=this.getRenderer().pixelToTileCoords(t,e,pull("Vector2d"));i=this.cellAt(r.x,r.y),push(r)}return i},e.prototype.setTile=function(t,e,i){return this.layerData[e][i]=t,t},e.prototype.getTileById=function(t,e,i){return this.tileset.contains(t)||(this.tileset=this.tilesets.getTilesetByGid(t)),new Tile(e,i,t,this.tileset)},e.prototype.cellAt=function(t,e,i){var r=~~t,o=~~e,n=this.getRenderer();return!1===i||r>=0&&r<n.cols&&o>=0&&o<n.rows?this.layerData[r][o]:null},e.prototype.clearTile=function(t,e){this.layerData[t][e]=null,this.preRender&&this.canvasRenderer.clearRect(t*this.tilewidth,e*this.tileheight,this.tilewidth,this.tileheight)},e.prototype.update=function(t){if(this.isAnimated){for(var e=!1,i=0;i<this.animatedTilesets.length;i++)e=this.animatedTilesets[i].update(t)||e;return e}return!1},e.prototype.draw=function(t,e){if(this.preRender){var i=Math.min(e.width,this.width),r=Math.min(e.height,this.height);t.drawImage(this.canvasRenderer.getCanvas(),e.pos.x,e.pos.y,i,r,e.pos.x,e.pos.y,i,r)}else this.getRenderer().drawTileLayer(t,this,e)},e}(Renderable),Bounds=function(t){this.onResetEvent(t)},prototypeAccessors={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds.prototype.setMinMax=function(t,e,i,r){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=r},prototypeAccessors.x.get=function(){return this.min.x},prototypeAccessors.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors.y.get=function(){return this.min.y},prototypeAccessors.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors.width.get=function(){return this.max.x-this.min.x},prototypeAccessors.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors.height.get=function(){return this.max.y-this.min.y},prototypeAccessors.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors.left.get=function(){return this.min.x},prototypeAccessors.right.get=function(){return this.max.x},prototypeAccessors.top.get=function(){return this.min.y},prototypeAccessors.bottom.get=function(){return this.max.y},prototypeAccessors.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds.prototype.update=function(t){this.add(t,!0)},Bounds.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var r=t[i];r.x>this.max.x&&(this.max.x=r.x),r.x<this.min.x&&(this.min.x=r.x),r.y>this.max.y&&(this.max.y=r.y),r.y<this.min.y&&(this.min.y=r.y)}},Bounds.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds.prototype.addFrame=function(t,e,i,r,o){var n=me.pool.pull("Vector2d");this.addPoint(n.set(t,e),o),this.addPoint(n.set(i,e),o),this.addPoint(n.set(t,r),o),this.addPoint(n.set(i,r),o),me.pool.push(n)},Bounds.prototype.contains=function(){var t,e,i,r,o=arguments[0];return 2===arguments.length?(t=e=o,i=r=arguments[1]):o instanceof Bounds?(t=o.min.x,e=o.max.x,i=o.min.y,r=o.max.y):(t=e=o.x,i=r=o.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&r<=this.max.y},Bounds.prototype.overlaps=function(t){return!(this.right<t.left||this.left>t.right||this.bottom<t.top||this.top>t.bottom)},Bounds.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,r=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+r},Bounds.prototype.clone=function(){var t=new Bounds;return t.addBounds(this),t},Bounds.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds.prototype,prototypeAccessors);var TMXRenderer=function(t,e,i,r){this.cols=t,this.rows=e,this.tilewidth=i,this.tileheight=r,this.bounds=new Bounds};TMXRenderer.prototype.canRender=function(t){return this.tilewidth===t.tilewidth&&this.tileheight===t.tileheight},TMXRenderer.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return e.setMinMax(0,0,this.cols*this.tilewidth,this.rows*this.tileheight),e},TMXRenderer.prototype.pixelToTileCoords=function(t,e,i){return i},TMXRenderer.prototype.tileToPixelCoords=function(t,e,i){return i},TMXRenderer.prototype.drawTile=function(t,e,i,r){},TMXRenderer.prototype.drawTileLayer=function(t,e,i){};var TMXOrthogonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"orthogonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(t/this.tilewidth,e/this.tileheight)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set(t*this.tilewidth,e*this.tileheight)},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset;o.drawTile(t,o.tileoffset.x+e*this.tilewidth,o.tileoffset.y+(i+1)*this.tileheight-o.tileheight,r)},e.prototype.drawTileLayer=function(t,e,i){var r=1,o=1,n=this.pixelToTileCoords(Math.max(i.pos.x-(e.maxTileSize.width-e.tilewidth),0),Math.max(i.pos.y-(e.maxTileSize.height-e.tileheight),0),pull("Vector2d")).floorSelf(),s=this.pixelToTileCoords(i.pos.x+i.width+this.tilewidth,i.pos.y+i.height+this.tileheight,pull("Vector2d")).ceilSelf();switch(s.x=s.x>this.cols?this.cols:s.x,s.y=s.y>this.rows?this.rows:s.y,e.renderorder){case"right-up":s.y=n.y+(n.y=s.y)-s.y,o=-1;break;case"left-down":s.x=n.x+(n.x=s.x)-s.x,r=-1;break;case"left-up":s.x=n.x+(n.x=s.x)-s.x,s.y=n.y+(n.y=s.y)-s.y,r=-1,o=-1}for(var a=n.y;a!==s.y;a+=o)for(var h=n.x;h!==s.x;h+=r){var l=e.cellAt(h,a,!1);l&&this.drawTile(t,h,a,l)}push(n),push(s)},e}(TMXRenderer),TMXIsometricRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight),this.hTilewidth=this.tilewidth/2,this.hTileheight=this.tileheight/2,this.originX=this.rows*this.hTilewidth}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"isometric"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return e.setMinMax(0,0,(this.cols+this.rows)*(this.tilewidth/2),(this.cols+this.rows)*(this.tileheight/2)),e},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(e/this.tileheight+(t-this.originX)/this.tilewidth,e/this.tileheight-(t-this.originX)/this.tilewidth)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set((t-e)*this.hTilewidth+this.originX,(t+e)*this.hTileheight)},e.prototype.adjustPosition=function(t){var e=t.x/this.hTilewidth,i=t.y/this.tileheight,r=pull("Vector2d");this.tileToPixelCoords(e,i,r),t.x=r.x,t.y=r.y,push(r)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset;o.drawTile(t,(this.cols-1)*o.tilewidth+(e-i)*o.tilewidth>>1,-o.tilewidth+(e+i)*o.tileheight>>2,r)},e.prototype.drawTileLayer=function(t,e,i){var r=e.tileset,o=this.pixelToTileCoords(i.pos.x-r.tilewidth,i.pos.y-r.tileheight,pull("Vector2d")).floorSelf(),n=this.pixelToTileCoords(i.pos.x+i.width+r.tilewidth,i.pos.y+i.height+r.tileheight,pull("Vector2d")).ceilSelf(),s=this.tileToPixelCoords(n.x,n.y,pull("Vector2d")),a=this.tileToPixelCoords(o.x,o.y,pull("Vector2d"));a.x-=this.hTilewidth,a.y+=this.tileheight;var h=a.y-i.pos.y>this.hTileheight,l=i.pos.x-a.x<this.hTilewidth;h&&(l?(o.x--,a.x-=this.hTilewidth):(o.y--,a.x+=this.hTilewidth),a.y-=this.hTileheight);for(var c=h^l,u=o.clone(),d=2*a.y;d-2*this.tileheight<2*s.y;d+=this.tileheight){u.setV(o);for(var p=a.x;p<s.x;p+=this.tilewidth){var f=e.cellAt(u.x,u.y);if(f){var y=(r=f.tileset).tileoffset;r.drawTile(t,y.x+p,y.y+d/2-r.tileheight,f)}u.x++,u.y--}c?(o.y++,a.x-=this.hTilewidth,c=!1):(o.x++,a.x+=this.hTilewidth,c=!0)}push(u),push(o),push(n),push(s),push(a)},e}(TMXRenderer),offsetsStaggerX=[{x:0,y:0},{x:1,y:-1},{x:1,y:0},{x:2,y:0}],offsetsStaggerY=[{x:0,y:0},{x:-1,y:1},{x:0,y:1},{x:0,y:2}],TMXHexagonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,-2&e.tilewidth,-2&e.tileheight),this.hexsidelength=e.hexsidelength||0,this.staggerX="x"===e.staggeraxis,this.staggerEven="even"===e.staggerindex,this.sidelengthx=0,this.sidelengthy=0,"hexagonal"===e.orientation&&(this.staggerX?this.sidelengthx=this.hexsidelength:this.sidelengthy=this.hexsidelength),this.sideoffsetx=(this.tilewidth-this.sidelengthx)/2,this.sideoffsety=(this.tileheight-this.sidelengthy)/2,this.columnwidth=this.sideoffsetx+this.sidelengthx,this.rowheight=this.sideoffsety+this.sidelengthy,this.centers=[new Vector2d,new Vector2d,new Vector2d,new Vector2d]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"hexagonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return this.staggerX?(e.setMinMax(0,0,this.cols*this.columnwidth+this.sideoffsetx,this.rows*(this.tileheight+this.sidelengthy)),e.width>1&&(e.height+=this.rowheight)):(e.setMinMax(0,0,this.cols*(this.tilewidth+this.sidelengthx),this.rows*this.rowheight+this.sideoffsety),e.height>1&&(e.width+=this.columnwidth)),e},e.prototype.doStaggerX=function(t){return this.staggerX&&1&t^this.staggerEven},e.prototype.doStaggerY=function(t){return!this.staggerX&&1&t^this.staggerEven},e.prototype.topLeft=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t-1,e):r.set(t-1,e-1):1&e^this.staggerEven?r.set(t,e-1):r.set(t-1,e-1),r},e.prototype.topRight=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t+1,e):r.set(t+1,e-1):1&e^this.staggerEven?r.set(t+1,e-1):r.set(t,e-1),r},e.prototype.bottomLeft=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t-1,e+1):r.set(t-1,e):1&e^this.staggerEven?r.set(t,e+1):r.set(t-1,e+1),r},e.prototype.bottomRight=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t+1,e+1):r.set(t+1,e):1&e^this.staggerEven?r.set(t+1,e+1):r.set(t,e+1),r},e.prototype.pixelToTileCoords=function(t,e,i){var r=i||new Vector2d;this.staggerX?t-=this.staggerEven?this.tilewidth:this.sideoffsetx:e-=this.staggerEven?this.tileheight:this.sideoffsety;var o,n,s,a,h=pull("Vector2d",Math.floor(t/(2*this.columnwidth)),Math.floor(e/(2*this.rowheight))),l=pull("Vector2d",t-h.x*(2*this.columnwidth),e-h.y*(2*this.rowheight));this.staggerX?(h.x=2*h.x,this.staggerEven&&++h.x):(h.y=2*h.y,this.staggerEven&&++h.y),this.staggerX?(s=(o=this.sidelengthx/2)+this.columnwidth,a=this.tileheight/2,this.centers[0].set(o,a),this.centers[1].set(s,a-this.rowheight),this.centers[2].set(s,a+this.rowheight),this.centers[3].set(s+this.columnwidth,a)):(n=this.sidelengthy/2,s=this.tilewidth/2,a=n+this.rowheight,this.centers[0].set(s,n),this.centers[1].set(s-this.columnwidth,a),this.centers[2].set(s+this.columnwidth,a),this.centers[3].set(s,a+this.rowheight));for(var c=0,u=Number.MAX_VALUE,d=0;d<4;++d){var p=this.centers[d].sub(l).length2();p<u&&(u=p,c=d)}var f=this.staggerX?offsetsStaggerX:offsetsStaggerY;return r.set(h.x+f[c].x,h.y+f[c].y),push(h),push(l),r},e.prototype.tileToPixelCoords=function(t,e,i){var r=Math.floor(t),o=Math.floor(e),n=i||new Vector2d;return this.staggerX?(n.y=o*(this.tileheight+this.sidelengthy),this.doStaggerX(r)&&(n.y+=this.rowheight),n.x=r*this.columnwidth):(n.x=r*(this.tilewidth+this.sidelengthx),this.doStaggerY(o)&&(n.x+=this.columnwidth),n.y=o*this.rowheight),n},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset,n=this.tileToPixelCoords(e,i,pull("Vector2d"));o.drawTile(t,o.tileoffset.x+n.x,o.tileoffset.y+n.y+(this.tileheight-o.tileheight),r),push(n)},e.prototype.drawTileLayer=function(t,e,i){var r,o=this.pixelToTileCoords(i.pos.x,i.pos.y,pull("Vector2d"));o.sub(e.pos);var n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y,pull("Vector2d")),s=o.clone(),a=n.clone(),h=i.pos.y-n.y<this.sideoffsety,l=i.pos.x-n.x<this.sideoffsetx;h&&o.y--,l&&o.x--;var c=e.cols,u=e.rows;if(this.staggerX){o.x=Math.max(0,o.x),o.y=Math.max(0,o.y),n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y);for(var d=this.doStaggerX(o.x+e.pos.x);n.y<i.bottom&&o.y<u;){for(s.setV(o),a.setV(n);a.x<i.right&&s.x<c;s.x+=2)(r=e.cellAt(s.x,s.y,!1))&&r.tileset.drawTile(t,a.x,a.y,r),a.x+=this.tilewidth+this.sidelengthx;d?(o.x-=1,o.y+=1,n.x-=this.columnwidth,d=!1):(o.x+=1,n.x+=this.columnwidth,d=!0),n.y+=this.rowheight}push(s),push(a)}else{for(o.x=Math.max(0,o.x),o.y=Math.max(0,o.y),n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y),this.doStaggerY(o.y)&&(n.x-=this.columnwidth);n.y<i.bottom&&o.y<u;o.y++){for(s.setV(o),a.setV(n),this.doStaggerY(o.y)&&(a.x+=this.columnwidth);a.x<i.right&&s.x<c;s.x++)(r=e.cellAt(s.x,s.y,!1))&&r.tileset.drawTile(t,a.x,a.y,r),a.x+=this.tilewidth+this.sidelengthx;n.y+=this.rowheight}push(s),push(a)}push(o),push(n)},e}(TMXRenderer),TMXStaggeredRenderer=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"staggered"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){var r=i||new Vector2d,o=t,n=e;this.staggerX?o-=this.staggerEven?this.sideoffsetx:0:n-=this.staggerEven?this.sideoffsety:0;var s=pull("Vector2d",Math.floor(o/this.tilewidth),Math.floor(n/this.tileheight));this.staggerX?(s.x=2*s.x,this.staggerEven&&++s.x):(s.y=2*s.y,this.staggerEven&&++s.y);var a=pull("Vector2d",o-s.x*this.tilewidth,n-s.y*this.tileheight),h=a.x*(this.tileheight/this.tilewidth);return this.sideoffsety-h>a.y&&(s=this.topLeft(s.x,s.y,s)),-this.sideoffsety+h>a.y&&(s=this.topRight(s.x,s.y,s)),this.sideoffsety+h<a.y&&(s=this.bottomLeft(s.x,s.y,s)),3*this.sideoffsety-h<a.y&&(s=this.bottomRight(s.x,s.y,s)),(r=this.tileToPixelCoords(s.x,s.y,r)).set(t-r.x,e-r.y),r.set(r.x-this.tilewidth/2,r.y*(this.tilewidth/this.tileheight)),r.div(this.tilewidth/Math.sqrt(2)).rotate(degToRad(-45)).add(s),push(s),push(a),r},e}(TMXHexagonalRenderer),TMXTileset=function(t){var e=0;if(this.TileProperties=[],this.imageCollection=[],this.firstgid=this.lastgid=+t.firstgid,void 0!==t.source){var i=t.source,r=getExtension(i);if(("tsx"===r||"json"===r)&&!(t=loader.getTMX(getBasename(i))))throw new Error(i+" external TSX/JSON tileset not found")}this.name=t.name,this.tilewidth=+t.tilewidth,this.tileheight=+t.tileheight,this.spacing=+t.spacing||0,this.margin=+t.margin||0,this.tileoffset=new Vector2d,this.isAnimated=!1,this.isCollection=!1,this.animations=new Map,this._lastUpdate=0;var o=t.tiles;for(e in o)if(o.hasOwnProperty(e)){if("animation"in o[e]&&(this.isAnimated=!0,this.animations.set(o[+e].animation[0].tileid,{dt:0,idx:0,frames:o[+e].animation,cur:o[+e].animation[0]})),"properties"in o[e])if(Array.isArray(o[e].properties)){var n={};for(var s in o[e].properties)n[o[e].properties[s].name]=o[e].properties[s].value;this.setTileProperty(+o[e].id+this.firstgid,n)}else this.setTileProperty(+e+this.firstgid,o[e].properties);if("image"in o[e]){var a=loader.getImage(o[e].image);if(!a)throw new Error("melonJS: '"+o[e].image+"' file for tile '"+(+e+this.firstgid)+"' not found!");this.imageCollection[+e+this.firstgid]=a}}this.isCollection=this.imageCollection.length>0;var h=t.tileoffset;h&&(this.tileoffset.x=+h.x,this.tileoffset.y=+h.y);var l=t.tileproperties;if(l)for(e in l)l.hasOwnProperty(e)&&this.setTileProperty(+e+this.firstgid,l[e]);if(!1===this.isCollection){if(this.image=loader.getImage(t.image),!this.image)throw new Error("melonJS: '"+t.image+"' file for tileset '"+this.name+"' not found!");this.texture=renderer.cache.get(this.image,{framewidth:this.tilewidth,frameheight:this.tileheight,margin:this.margin,spacing:this.spacing}),this.atlas=this.texture.getAtlas();var c=+t.columns||Math.round(this.image.width/(this.tilewidth+this.spacing)),u=Math.round(this.image.height/(this.tileheight+this.spacing));t.tilecount%c>0&&++u,this.lastgid=this.firstgid+(c*u-1||0),t.tilecount&&this.lastgid-this.firstgid+1!=+t.tilecount&&console.warn("Computed tilecount ("+(this.lastgid-this.firstgid+1)+") does not match expected tilecount ("+t.tilecount+")")}};TMXTileset.prototype.getTileImage=function(t){return this.imageCollection[t]},TMXTileset.prototype.setTileProperty=function(t,e){this.TileProperties[t]=e},TMXTileset.prototype.contains=function(t){return t>=this.firstgid&&t<=this.lastgid},TMXTileset.prototype.getViewTileId=function(t){var e=t-this.firstgid;return this.animations.has(e)?this.animations.get(e).cur.tileid:e},TMXTileset.prototype.getTileProperties=function(t){return this.TileProperties[t]},TMXTileset.prototype.update=function(t){var e=0,i=timer$1.getTime(),r=!1;return this._lastUpdate!==i&&(this._lastUpdate=i,this.animations.forEach((function(i){for(i.dt+=t,e=i.cur.duration;i.dt>=e;)i.dt-=e,i.idx=(i.idx+1)%i.frames.length,i.cur=i.frames[i.idx],e=i.cur.duration,r=!0}))),r},TMXTileset.prototype.drawTile=function(t,e,i,r){if(r.flipped&&(t.save(),t.translate(e,i),t.transform(r.currentTransform),e=i=0),!0===this.isCollection)t.drawImage(this.imageCollection[r.tileId],0,0,r.width,r.height,e,i,r.width,r.height);else{var o=this.atlas[this.getViewTileId(r.tileId)].offset;t.drawImage(this.image,o.x,o.y,this.tilewidth,this.tileheight,e,i,this.tilewidth+t.uvOffset,this.tileheight+t.uvOffset)}r.flipped&&t.restore()};var TMX_CLEAR_BIT_MASK=536870911,TMXTilesetGroup=function(){this.tilesets=[],this.length=0};TMXTilesetGroup.prototype.add=function(t){this.tilesets.push(t),this.length++},TMXTilesetGroup.prototype.getTilesetByIndex=function(t){return this.tilesets[t]},TMXTilesetGroup.prototype.getTilesetByGid=function(t){var e=-1;t&=TMX_CLEAR_BIT_MASK;for(var i=0,r=this.tilesets.length;i<r;i++){if(this.tilesets[i].contains(t))return this.tilesets[i];this.tilesets[i].firstgid===this.tilesets[i].lastgid&&t>=this.tilesets[i].firstgid&&(e=i)}if(-1!==e)return this.tilesets[e];throw new Error("no matching tileset found for gid "+t)};var TMXObject=function(t,e,i){this.points=void 0,this.name=e.name,this.x=+e.x,this.y=+e.y,this.z=+i,this.width=+e.width||0,this.height=+e.height||0,this.gid=+e.gid||null,this.tintcolor=e.tintcolor,this.type=e.type,this.type=e.type,this.rotation=degToRad(+e.rotation||0),this.id=+e.id||void 0,this.orientation=t.orientation,this.shapes=void 0,this.isEllipse=!1,this.isPolygon=!1,this.isPolyLine=!1,"number"==typeof this.gid?this.setTile(t.tilesets):void 0!==e.ellipse?this.isEllipse=!0:void 0!==e.polygon?(this.points=e.polygon,this.isPolygon=!0):void 0!==e.polyline&&(this.points=e.polyline,this.isPolyLine=!0),void 0!==e.text?(this.text=e.text,this.text.font=e.text.fontfamily||"sans-serif",this.text.size=e.text.pixelsize||16,this.text.fillStyle=e.text.color||"#000000",this.text.textAlign=e.text.halign||"left",this.text.textBaseline=e.text.valign||"top",this.text.width=this.width,this.text.height=this.height,applyTMXProperties(this.text,e)):(applyTMXProperties(this,e),this.shapes||(this.shapes=this.parseTMXShapes())),t.isEditor||t.getRenderer().adjustPosition(this)};TMXObject.prototype.setTile=function(t){var e=t.getTilesetByGid(this.gid);!1===e.isCollection&&(this.width=this.framewidth=e.tilewidth,this.height=this.frameheight=e.tileheight),this.tile=new Tile(this.x,this.y,this.gid,e)},TMXObject.prototype.parseTMXShapes=function(){var t=0,e=[];if(!0===this.isEllipse)e.push(new Ellipse(this.width/2,this.height/2,this.width,this.height).rotate(this.rotation));else if(!0===this.isPolygon){var i=new Polygon(0,0,this.points);if(!1===i.isConvex())throw new Error("collision polygones in Tiled should be defined as Convex");e.push(i.rotate(this.rotation))}else if(!0===this.isPolyLine){var r,o,n=this.points,s=n.length-1;for(t=0;t<s;t++)r=new Vector2d(n[t].x,n[t].y),o=new Vector2d(n[t+1].x,n[t+1].y),0!==this.rotation&&(r=r.rotate(this.rotation),o=o.rotate(this.rotation)),e.push(new Line(0,0,[r,o]))}else e.push(new Polygon(0,0,[new Vector2d,new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)]).rotate(this.rotation));if("isometric"===this.orientation)for(t=0;t<e.length;t++)e[t].toIso();return e},TMXObject.prototype.getObjectPropertyByName=function(t){return this[t]};var TMXGroup=function(t,e,i){var r=this;this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.tintcolor=e.tintcolor,this.z=i,this.objects=[];var o=void 0===e.visible||e.visible;this.opacity=!0===o?clamp(+e.opacity||1,0,1):0,applyTMXProperties(this,e),e.objects&&e.objects.forEach((function(e){e.tintcolor=r.tintcolor,r.objects.push(new TMXObject(t,e,i))})),e.layers&&e.layers.forEach((function(e){var o=new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i++);o.setRenderer(t.getRenderer()),r.width=Math.max(r.width,o.width),r.height=Math.max(r.height,o.height),r.objects.push(o)}))};TMXGroup.prototype.destroy=function(){this.objects=null},TMXGroup.prototype.getObjectCount=function(){return this.objects.length},TMXGroup.prototype.getObjectByIndex=function(t){return this.objects[t]};var COLLISION_GROUP="collision";function getNewDefaultRenderer(t){switch(t.orientation){case"orthogonal":return new TMXOrthogonalRenderer(t);case"isometric":return new TMXIsometricRenderer(t);case"hexagonal":return new TMXHexagonalRenderer(t);case"staggered":return new TMXStaggeredRenderer(t);default:throw new Error(t.orientation+" type TMX Tile Map not supported!")}}function readLayer(t,e,i){return new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i)}function readImageLayer(t,e,i){applyTMXProperties(e.properties,e);var r=pull("ImageLayer",+e.offsetx||+e.x||0,+e.offsety||+e.y||0,Object.assign({name:e.name,image:e.image,ratio:pull("Vector2d",+e.parallaxx||1,+e.parallaxy||1),tint:void 0!==e.tintcolor?pull("Color").parseHex(e.tintcolor,!0):void 0,z:i},e.properties)),o=void 0===e.visible||e.visible;return r.setOpacity(o?+e.opacity:0),r}function readTileset(t){return new TMXTileset(t)}function readObjectGroup(t,e,i){return new TMXGroup(t,e,i)}var TMXTileMap=function(t,e){if(this.data=e,this.name=t,this.cols=+e.width,this.rows=+e.height,this.tilewidth=+e.tilewidth,this.tileheight=+e.tileheight,this.infinite=+e.infinite,this.orientation=e.orientation,this.renderorder=e.renderorder||"right-down",this.version=e.version,this.tiledversion=e.tiledversion,this.tilesets=null,void 0===this.layers&&(this.layers=[]),void 0===this.objectGroups&&(this.objectGroups=[]),this.isEditor="melon-editor"===e.editor,this.nextobjectid=+e.nextobjectid||void 0,this.hexsidelength=+e.hexsidelength,this.staggeraxis=e.staggeraxis,this.staggerindex=e.staggerindex,this.bounds=this.getRenderer().getBounds().clone(),this.width=this.bounds.width,this.height=this.bounds.height,this.backgroundcolor=e.backgroundcolor,applyTMXProperties(this,e),this.initialized=!1,1===this.infinite)throw new Error("Tiled Infinite Map not supported!")};TMXTileMap.prototype.getRenderer=function(){return void 0!==this.renderer&&this.renderer.canRender(this)||(this.renderer=getNewDefaultRenderer(this)),this.renderer},TMXTileMap.prototype.getBounds=function(){return this.bounds},TMXTileMap.prototype.readMapObjects=function(t){var e=this;if(!0!==this.initialized){var i=0;if(this.tilesets||(this.tilesets=new TMXTilesetGroup),void 0!==t.tilesets)t.tilesets.forEach((function(t){e.tilesets.add(readTileset(t))}));this.background_image&&this.layers.push(pull("ImageLayer",0,0,{name:"background_image",image:this.background_image,z:i++})),t.layers.forEach((function(t){switch(t.type){case"imagelayer":e.layers.push(readImageLayer(e,t,i++));break;case"tilelayer":e.layers.push(readLayer(e,t,i++));break;case"objectgroup":case"group":e.objectGroups.push(readObjectGroup(e,t,i++))}})),this.initialized=!0}},TMXTileMap.prototype.addTo=function(t,e,i){var r=t.autoSort,o=t.autoDepth,n=this.getBounds();function s(e,i){viewport.setBounds(0,0,Math.max(n.width,e),Math.max(n.height,i)),t.pos.set(Math.max(0,~~((e-n.width)/2)),Math.max(0,~~((i-n.height)/2)),t.pos.z)}t.autoSort=!1,t.autoDepth=!1,this.backgroundcolor&&t.backgroundColor.parseCSS(this.backgroundcolor),this.getLayers().forEach((function(e){t.addChild(e)})),this.getObjects(e).forEach((function(e){t.addChild(e)})),t.resize(this.bounds.width,this.bounds.height),t.sort(!0),!0===i&&(off(VIEWPORT_ONRESIZE,s),s(viewport.width,viewport.height),on(VIEWPORT_ONRESIZE,s,this)),t.autoSort=r,t.autoDepth=o},TMXTileMap.prototype.getObjects=function(t){var e,i=[],r=!1;this.readMapObjects(this.data);for(var o=0;o<this.objectGroups.length;o++){var n=this.objectGroups[o];r=n.name.toLowerCase().includes(COLLISION_GROUP),!1===t&&((e=new Container(0,0,this.width,this.height)).anchorPoint.set(0,0),e.name=n.name,e.pos.z=n.z,e.setOpacity(n.opacity),e.autoSort=!1,e.autoDepth=!1);for(var s=0;s<n.objects.length;s++){var a,h=n.objects[s];void 0===h.anchorPoint&&(h.anchorPoint={x:0,y:0}),void 0!==h.tintcolor&&(h.tint=pull("Color"),h.tint.parseHex(h.tintcolor,!0)),h instanceof TMXLayer?a=h:"object"==typeof h.text?(void 0===h.text.anchorPoint&&(h.text.anchorPoint=h.anchorPoint),(a=!0===h.text.bitmap?pull("BitmapText",h.x,h.y,h.text):pull("Text",h.x,h.y,h.text)).pos.z=h.z):"object"==typeof h.tile?((a=h.tile.getRenderable(h)).body=new Body(a,h.shapes||new Rect(0,0,this.width,this.height)),a.body.setStatic(!0),a.pos.setMuted(h.x,h.y,h.z)):(void 0!==h.name&&""!==h.name?a=pull(h.name,h.x,h.y,h):((a=pull("Renderable",h.x,h.y,h.width,h.height)).anchorPoint.set(0,0),a.name=h.name,a.type=h.type,a.id=h.id,a.body=new Body(a,h.shapes||new Rect(0,0,a.width,a.height)),a.body.setStatic(!0),a.resize(a.body.getBounds().width,a.body.getBounds().height)),a.pos.z=h.z),r&&!h.name&&a.body&&(a.body.collisionType=collision.types.WORLD_SHAPE,a.body.isStatic=!0),!1!==t?(!0===a.isRenderable&&(a.setOpacity(a.getOpacity()*n.opacity),a.renderable instanceof Renderable&&a.renderable.setOpacity(a.renderable.getOpacity()*n.opacity)),i.push(a)):e.addChild(a)}!1===t&&e.children.length>0&&(e.autoSort=!0,e.autoDepth=!0,i.push(e))}return i},TMXTileMap.prototype.getLayers=function(){return this.readMapObjects(this.data),this.layers},TMXTileMap.prototype.destroy=function(){this.tilesets=void 0,this.layers.length=0,this.objectGroups.length=0,this.initialized=!1};var levels={},levelIdx=[],currentLevelIdx=0;function safeLoadLevel(t,e,i){e.container.reset(),reset(),levels[level.getCurrentLevelId()]&&levels[level.getCurrentLevelId()].destroy(),currentLevelIdx=levelIdx.indexOf(t),loadTMXLevel(t,e.container,e.flatten,e.setViewportBounds),emit(LEVEL_LOADED,t),e.onLoaded(t),i&&state.restart()}function loadTMXLevel(t,e,i,r){var o=levels[t];utils.resetGUID(t,o.nextobjectid),e.anchorPoint.set(0,0),o.addTo(e,i,r)}var level={add:function(t,e,i){if("tmx"===t)return null==levels[e]&&(levels[e]=new TMXTileMap(e,loader.getTMX(e)),levelIdx.push(e),i&&i(),!0);throw new Error("no level loader defined for format "+t)},load:function(t,e){if(e=Object.assign({container:world,onLoaded:onLevelLoaded,flatten:mergeGroup,setViewportBounds:!0},e||{}),void 0===levels[t])throw new Error("level "+t+" not found");if(!(levels[t]instanceof TMXTileMap))throw new Error("no level loader defined");return state.isRunning()?(state.stop(),utils.function.defer(safeLoadLevel,this,t,e,!0)):safeLoadLevel(t,e),!0},getCurrentLevelId:function(){return levelIdx[currentLevelIdx]},getCurrentLevel:function(){return levels[this.getCurrentLevelId()]},reload:function(t){return this.load(this.getCurrentLevelId(),t)},next:function(t){return currentLevelIdx+1<levelIdx.length&&this.load(levelIdx[currentLevelIdx+1],t)},previous:function(t){return currentLevelIdx-1>=0&&this.load(levelIdx[currentLevelIdx-1],t)},levelCount:function(){return levelIdx.length}},imgList={},tmxList={},binList={},jsonList={},baseURL={},resourceCount=0,loadCount=0,timerId$1=0;function checkLoadStatus(t){if(loadCount===resourceCount){if(!t&&!loader.onload)throw new Error("no load callback defined");clearTimeout(timerId$1);var e=t||loader.onload;setTimeout((function(){e(),emit(LOADER_COMPLETE)}),300)}else timerId$1=setTimeout((function(){checkLoadStatus(t)}),100)}function preloadImage(t,e,i){imgList[t.name]=new Image,imgList[t.name].onload=e,imgList[t.name].onerror=i,"string"==typeof loader.crossOrigin&&(imgList[t.name].crossOrigin=loader.crossOrigin),imgList[t.name].src=t.src+loader.nocache}function preloadFontFace(t,e,i){var r=new FontFace(t.name,t.src);r.load().then((function(){document.fonts.add(r),document.body.style.fontFamily=t.name,e()}),(function(){i(t.name)}))}function preloadTMX(t,e,i){function r(e){tmxList[t.name]=e,"tmx"===t.type&&level.add(t.type,t.name)}if(t.data)return r(t.data),void e();var o=new XMLHttpRequest,n=getExtension(t.src);o.overrideMimeType&&("json"===n?o.overrideMimeType("application/json"):o.overrideMimeType("text/xml")),o.open("GET",t.src+loader.nocache,!0),o.withCredentials=loader.withCredentials,o.ontimeout=i,o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status||0===o.status&&o.responseText){var s=null;switch(n){case"xml":case"tmx":case"tsx":if(device$1.ua.match(/msie/i)||!o.responseXML){if(!globalThis.DOMParser)throw new Error("XML file format loading not supported, use the JSON file format instead");s=(new DOMParser).parseFromString(o.responseText,"text/xml")}else s=o.responseXML;var a=parse(s);switch(n){case"tmx":s=a.map;break;case"tsx":s=a.tilesets[0]}break;case"json":s=JSON.parse(o.responseText);break;default:throw new Error("TMX file format "+n+"not supported !")}r(s),e()}else i(t.name)},o.send()}function preloadJSON(t,e,i){var r=new XMLHttpRequest;r.overrideMimeType&&r.overrideMimeType("application/json"),r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.ontimeout=i,r.onreadystatechange=function(){4===r.readyState&&(200===r.status||0===r.status&&r.responseText?(jsonList[t.name]=JSON.parse(r.responseText),e()):i(t.name))},r.send()}function preloadBinary(t,e,i){var r=new XMLHttpRequest;r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.responseType="arraybuffer",r.onerror=i,r.onload=function(){var i=r.response;if(i){for(var o=new Uint8Array(i),n=[],s=0;s<o.byteLength;s++)n[s]=String.fromCharCode(o[s]);binList[t.name]=n.join(""),e()}},r.send()}function preloadJavascript(t,e,i){var r=document.createElement("script");r.src=t.src,r.type="text/javascript","string"==typeof loader.crossOrigin&&(r.crossOrigin=loader.crossOrigin),r.defer=!0,r.onload=function(){e()},r.onerror=function(){i(t.name)},document.getElementsByTagName("body")[0].appendChild(r)}var loader={nocache:"",onload:void 0,onProgress:void 0,crossOrigin:void 0,withCredentials:!1,onResourceLoaded:function(t){var e=++loadCount/resourceCount;this.onProgress&&this.onProgress(e,t),emit(LOADER_PROGRESS,e,t)},onLoadingError:function(t){throw new Error("Failed loading resource "+t.src)},setNocache:function(t){this.nocache=t?"?"+~~(1e7*Math.random()):""},setBaseURL:function(t,e){"*"!==t?baseURL[t]=e:(baseURL.audio=e,baseURL.binary=e,baseURL.image=e,baseURL.json=e,baseURL.js=e,baseURL.tmx=e,baseURL.tsx=e)},preload:function(t,e,i){void 0===i&&(i=!0);for(var r=0;r<t.length;r++)resourceCount+=this.load(t[r],this.onResourceLoaded.bind(this,t[r]),this.onLoadingError.bind(this,t[r]));void 0!==e&&(this.onload=e),!0===i&&state.change(state.LOADING),checkLoadStatus(e)},load:function(t,e,i){switch(void 0!==baseURL[t.type]&&(t.src=baseURL[t.type]+t.src),t.type){case"binary":return preloadBinary.call(this,t,e,i),1;case"image":return preloadImage.call(this,t,e,i),1;case"json":return preloadJSON.call(this,t,e,i),1;case"js":return preloadJavascript.call(this,t,e,i),1;case"tmx":case"tsx":return preloadTMX.call(this,t,e,i),1;case"audio":return load(t,!!t.stream,e,i),1;case"fontface":return preloadFontFace.call(this,t,e,i),1;default:throw new Error("load : unknown or invalid resource type : "+t.type)}},unload:function(t){switch(t.type){case"binary":return t.name in binList&&(delete binList[t.name],!0);case"image":return t.name in imgList&&(delete imgList[t.name],!0);case"json":return t.name in jsonList&&(delete jsonList[t.name],!0);case"js":case"fontface":return!0;case"tmx":case"tsx":return t.name in tmxList&&(delete tmxList[t.name],!0);case"audio":return unload(t.name);default:throw new Error("unload : unknown or invalid resource type : "+t.type)}},unloadAll:function(){var t;for(t in binList)binList.hasOwnProperty(t)&&this.unload({name:t,type:"binary"});for(t in imgList)imgList.hasOwnProperty(t)&&this.unload({name:t,type:"image"});for(t in tmxList)tmxList.hasOwnProperty(t)&&this.unload({name:t,type:"tmx"});for(t in jsonList)jsonList.hasOwnProperty(t)&&this.unload({name:t,type:"json"});unloadAll()},getTMX:function(t){return(t=""+t)in tmxList?tmxList[t]:null},getBinary:function(t){return(t=""+t)in binList?binList[t]:null},getImage:function(t){return(t=getBasename(""+t))in imgList?imgList[t]:null},getJSON:function(t){return(t=""+t)in jsonList?jsonList[t]:null}},audioTracks={},current_track_id=null,retry_counter=0,audioExts=[],soundLoadError=function(t,e){if(retry_counter++>3)throw new Error("melonJS: failed loading "+t);audioTracks[t].load()},stopOnAudioError=!0;function init$1(t){return void 0===t&&(t="mp3"),audioExts=t.split(","),!howler.Howler.noAudio}function hasFormat(t){return hasAudio()&&howler.Howler.codecs(t)}function hasAudio(){return!howler.Howler.noAudio}function enable(){unmuteAll()}function disable(){muteAll()}function load(t,e,i,r){var o=[];if(0===audioExts.length)throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");for(var n=0;n<audioExts.length;n++)o.push(t.src+t.name+"."+audioExts[n]+loader.nocache);return audioTracks[t.name]=new howler.Howl({src:o,volume:howler.Howler.volume(),html5:!0===e,xhrWithCredentials:loader.withCredentials,onloaderror:function(){soundLoadError.call(this,t.name,r)},onload:function(){retry_counter=0,i&&i()}}),1}function play(t,e,i,r){void 0===e&&(e=!1);var o=audioTracks[t];if(o&&void 0!==o){var n=o.play();return"boolean"==typeof e&&o.loop(e,n),o.volume("number"==typeof r?clamp(r,0,1):howler.Howler.volume(),n),"function"==typeof i&&(!0===e?o.on("end",i,n):o.once("end",i,n)),n}throw new Error("audio clip "+t+" does not exist")}function fade(t,e,i,r,o){var n=audioTracks[t];if(!n||void 0===n)throw new Error("audio clip "+t+" does not exist");n.fade(e,i,r,o)}function seek(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var r=audioTracks[t];if(r&&void 0!==r)return r.seek.apply(r,e);throw new Error("audio clip "+t+" does not exist")}function rate(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var r=audioTracks[t];if(r&&void 0!==r)return r.rate.apply(r,e);throw new Error("audio clip "+t+" does not exist")}function stop(t,e){if(void 0!==t){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.stop(e),i.off("end",void 0,e)}else howler.Howler.stop()}function pause(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.pause(e)}function resume(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.play(e)}function playTrack(t,e){return play(current_track_id=t,!0,null,e)}function stopTrack(){null!==current_track_id&&(audioTracks[current_track_id].stop(),current_track_id=null)}function pauseTrack(){null!==current_track_id&&audioTracks[current_track_id].pause()}function resumeTrack(){null!==current_track_id&&audioTracks[current_track_id].play()}function getCurrentTrack(){return current_track_id}function setVolume(t){howler.Howler.volume(t)}function getVolume(){return howler.Howler.volume()}function mute(t,e,i){i=void 0===i||!!i;var r=audioTracks[t];if(!r||void 0===r)throw new Error("audio clip "+t+" does not exist");r.mute(i,e)}function unmute(t,e){mute(t,e,!1)}function muteAll(){howler.Howler.mute(!0)}function unmuteAll(){howler.Howler.mute(!1)}function muted(){return howler.Howler._muted}function unload(t){return t in audioTracks&&(audioTracks[t].unload(),delete audioTracks[t],!0)}function unloadAll(){for(var t in audioTracks)audioTracks.hasOwnProperty(t)&&unload(t)}var audio=Object.freeze({__proto__:null,stopOnAudioError:stopOnAudioError,init:init$1,hasFormat:hasFormat,hasAudio:hasAudio,enable:enable,disable:disable,load:load,play:play,fade:fade,seek:seek,rate:rate,stop:stop,pause:pause,resume:resume,playTrack:playTrack,stopTrack:stopTrack,pauseTrack:pauseTrack,resumeTrack:resumeTrack,getCurrentTrack:getCurrentTrack,setVolume:setVolume,getVolume:getVolume,mute:mute,unmute:unmute,muteAll:muteAll,unmuteAll:unmuteAll,muted:muted,unload:unload,unloadAll:unloadAll}),data={};function isReserved(t){return"add"===t||"remove"===t}on(BOOT,(function(){if(!0===device$1.localStorage){var t=localStorage.getItem("me.save");if("string"==typeof t&&t.length>0)(JSON.parse(t)||[]).forEach((function(t){data[t]=JSON.parse(localStorage.getItem("me.save."+t))}))}}));var save={add:function(t){var e=save;Object.keys(t).forEach((function(i){var r;isReserved(i)||(r=i,Object.defineProperty(e,r,{configurable:!0,enumerable:!0,get:function(){return data[r]},set:function(t){data[r]=t,!0===device$1.localStorage&&localStorage.setItem("me.save."+r,JSON.stringify(t))}}),i in data||(e[i]=t[i]))})),!0===device$1.localStorage&&localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))},remove:function(t){isReserved(t)||void 0!==data[t]&&(delete data[t],!0===device$1.localStorage&&(localStorage.removeItem("me.save."+t),localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))))}},accelInitialized=!1,deviceOrientationInitialized=!1,swipeEnabled=!0;function _disableSwipeFn(t){return t.preventDefault(),"function"==typeof globalThis.scroll&&globalThis.scroll(0,0),!1}var readyBound=!1,isReady=!1,readyList=[];function _domReady(){if(!isReady){if(!device.nodeJS&&!document.body)return setTimeout(_domReady,13);for(void 0!==globalThis.document&&"function"==typeof globalThis.document.removeEventListener&&globalThis.document.removeEventListener("DOMContentLoaded",this._domReady,!1),"function"==typeof globalThis.removeEventListener&&globalThis.removeEventListener("load",_domReady,!1);readyList.length;)readyList.shift().call(globalThis,[]);isReady=!0}}var _domRect={left:0,top:0,x:0,y:0,width:0,height:0,right:0,bottom:0};function _detectDevice(){device.iOS=/iPhone|iPad|iPod/i.test(device.ua),device.android=/Android/i.test(device.ua),device.android2=/Android 2/i.test(device.ua),device.linux=/Linux/i.test(device.ua),device.chromeOS=/CrOS/.test(device.ua),device.wp=/Windows Phone/i.test(device.ua),device.BlackBerry=/BlackBerry/i.test(device.ua),device.Kindle=/Kindle|Silk.*Mobile Safari/i.test(device.ua),device.isMobile=/Mobi/i.test(device.ua)||device.iOS||device.android||device.wp||device.BlackBerry||device.Kindle||!1,device.ejecta=void 0!==globalThis.ejecta,device.isWeixin=/MicroMessenger/i.test(device.ua)}function _checkCapabilities(){_detectDevice(),device.isMobile&&device.enableSwipe(!1),device.TouchEvent=!!("ontouchstart"in globalThis),device.PointerEvent=!!globalThis.PointerEvent,globalThis.gesture=prefixed("gesture"),device.touch=device.TouchEvent||device.PointerEvent,device.maxTouchPoints=device.touch?device.PointerEvent?globalThis.navigator.maxTouchPoints||1:10:1,device.wheel=void 0!==globalThis.document&&"onwheel"in globalThis.document.createElement("div"),device.hasPointerLockSupport=void 0!==globalThis.document&&void 0!==globalThis.document.pointerLockElement,device.hasDeviceOrientation=!!globalThis.DeviceOrientationEvent,device.hasAccelerometer=!!globalThis.DeviceMotionEvent,device.ScreenOrientation="undefined"!=typeof screen&&void 0!==screen.orientation,device.hasFullscreenSupport=void 0!==globalThis.document&&(prefixed("fullscreenEnabled",globalThis.document)||globalThis.document.mozFullScreenEnabled),!0===device.hasFullscreenSupport&&(globalThis.document.exitFullscreen=void 0!==globalThis.document&&(prefixed("cancelFullScreen",globalThis.document)||prefixed("exitFullscreen",globalThis.document))),device.hasWebAudio=!(!globalThis.AudioContext&&!globalThis.webkitAudioContext);try{device.localStorage=!!globalThis.localStorage}catch(t){device.localStorage=!1}try{device.OffscreenCanvas=void 0!==globalThis.OffscreenCanvas&&null!==new OffscreenCanvas(0,0).getContext("2d")}catch(t){device.OffscreenCanvas=!1}var t,e;("function"==typeof globalThis.addEventListener&&(globalThis.addEventListener("blur",(function(){device.stopOnBlur&&state.stop(!0),device.pauseOnBlur&&state.pause(!0)}),!1),globalThis.addEventListener("focus",(function(){device.stopOnBlur&&state.restart(!0),device.resumeOnFocus&&state.resume(!0),device.autoFocus&&device.focus()}),!1)),void 0!==globalThis.document)&&(void 0!==globalThis.document.hidden?(t="hidden",e="visibilitychange"):void 0!==globalThis.document.mozHidden?(t="mozHidden",e="mozvisibilitychange"):void 0!==globalThis.document.msHidden?(t="msHidden",e="msvisibilitychange"):void 0!==globalThis.document.webkitHidden&&(t="webkitHidden",e="webkitvisibilitychange"),"string"==typeof e&&globalThis.document.addEventListener(e,(function(){globalThis.document[t]?(device.stopOnBlur&&state.stop(!0),device.pauseOnBlur&&state.pause(!0)):(device.stopOnBlur&&state.restart(!0),device.resumeOnFocus&&state.resume(!0))}),!1))}on(BOOT,(function(){_checkCapabilities()}));var device={ua:void 0!==globalThis.navigator?globalThis.navigator.userAgent:"",localStorage:!1,hasAccelerometer:!1,hasDeviceOrientation:!1,ScreenOrientation:!1,hasFullscreenSupport:!1,hasPointerLockSupport:!1,hasWebAudio:!1,nativeBase64:"function"==typeof globalThis.atob,maxTouchPoints:1,touch:!1,wheel:!1,isMobile:!1,iOS:!1,android:!1,android2:!1,linux:!1,ejecta:!1,isWeixin:!1,nodeJS:"undefined"!=typeof process&&"node"===process.release.name,chromeOS:!1,wp:!1,BlackBerry:!1,Kindle:!1,accelerationX:0,accelerationY:0,accelerationZ:0,gamma:0,beta:0,alpha:0,language:void 0!==globalThis.navigator&&(globalThis.navigator.language||globalThis.navigator.browserLanguage||globalThis.navigator.userLanguage)||"en",pauseOnBlur:!0,resumeOnFocus:!0,autoFocus:!0,stopOnBlur:!1,OffscreenCanvas:!1,onReady:function(t){isReady?t.call(globalThis,[]):(readyList.push(t),readyBound||(!0===device.nodeJS||void 0!==globalThis.document&&"complete"===globalThis.document.readyState?globalThis.setTimeout(_domReady,0):(void 0!==globalThis.document&&"function"==typeof globalThis.document.addEventListener&&globalThis.document.addEventListener("DOMContentLoaded",_domReady,!1),globalThis.addEventListener("load",_domReady,!1)),readyBound=!0))},enableSwipe:function(t){!1!==t?!1===swipeEnabled&&(globalThis.document.removeEventListener("touchmove",_disableSwipeFn,!1),swipeEnabled=!0):!0===swipeEnabled&&(globalThis.document.addEventListener("touchmove",_disableSwipeFn,!1),swipeEnabled=!1)},requestFullscreen:function(t){this.hasFullscreenSupport&&((t=t||getParent()).requestFullscreen=prefixed("requestFullscreen",t)||t.mozRequestFullScreen,t.requestFullscreen())},exitFullscreen:function(){this.hasFullscreenSupport&&document.exitFullscreen()},getScreenOrientation:function(){var t="portrait",e="landscape",i=globalThis.screen;if(!0===this.ScreenOrientation){var r=prefixed("orientation",i);if(void 0!==r&&"string"==typeof r.type)return r.type;if("string"==typeof r)return r}return"number"==typeof globalThis.orientation?90===Math.abs(globalThis.orientation)?e:t:globalThis.outerWidth>globalThis.outerHeight?e:t},lockOrientation:function(t){var e=globalThis.screen;if(void 0!==e){var i=prefixed("lockOrientation",e);if(void 0!==i)return i(t)}return!1},unlockOrientation:function(){var t=globalThis.screen;if(void 0!==t){var e=prefixed("unlockOrientation",t);if(void 0!==e)return e()}return!1},isPortrait:function(){return this.getScreenOrientation().includes("portrait")},isLandscape:function(){return this.getScreenOrientation().includes("landscape")},getStorage:function(t){if(void 0===t&&(t="local"),"local"===t)return save;throw new Error("storage type "+t+" not supported")},getParentElement:function(t){var e=this.getElement(t);return null!==e.parentNode&&(e=e.parentNode),e},getElement:function(t){var e=null;return"undefined"!==t&&("string"==typeof t?e=document.getElementById(t):"object"==typeof t&&t.nodeType===Node.ELEMENT_NODE&&(e=t)),e||(e=document.body),e},getElementBounds:function(t){return"object"==typeof t&&t!==document.body&&void 0!==t.getBoundingClientRect?t.getBoundingClientRect():(_domRect.width=_domRect.right=globalThis.innerWidth,_domRect.height=_domRect.bottom=globalThis.innerHeight,_domRect)},getParentBounds:function(t){return this.getElementBounds(this.getParentElement(t))},isWebGLSupported:function(t){var e=!1;try{var i=document.createElement("canvas"),r={stencil:!0,failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat};e=!(!globalThis.WebGLRenderingContext||!i.getContext("webgl",r)&&!i.getContext("experimental-webgl",r))}catch(t){e=!1}return e},getMaxShaderPrecision:function(t){return t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0?"highp":t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"},focus:function(){"function"==typeof globalThis.focus&&globalThis.focus()},onDeviceMotion:function(t){this.accelerationX=t.accelerationIncludingGravity.x,this.accelerationY=t.accelerationIncludingGravity.y,this.accelerationZ=t.accelerationIncludingGravity.z},onDeviceRotate:function(t){this.gamma=t.gamma,this.beta=t.beta,this.alpha=t.alpha},watchAccelerometer:function(){var t=this;return this.hasAccelerometer&&!accelInitialized&&(DeviceOrientationEvent&&"function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(globalThis.addEventListener("devicemotion",t.onDeviceMotion,!1),accelInitialized=!0)})).catch(console.error):(globalThis.addEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!0)),accelInitialized},unwatchAccelerometer:function(){accelInitialized&&(globalThis.removeEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!1)},watchDeviceOrientation:function(){var t=this;return this.hasDeviceOrientation&&!deviceOrientationInitialized&&("function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(globalThis.addEventListener("deviceorientation",t.onDeviceRotate,!1),deviceOrientationInitialized=!0)})).catch(console.error):(globalThis.addEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!0)),deviceOrientationInitialized},unwatchDeviceOrientation:function(){deviceOrientationInitialized&&(globalThis.removeEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!1)},vibrate:function(t){void 0!==globalThis.navigator&&"function"==typeof globalThis.navigator.vibrate&&globalThis.navigator.vibrate(t)}};Object.defineProperty(device,"devicePixelRatio",{get:function(){return globalThis.devicePixelRatio||1}}),Object.defineProperty(device,"isFullscreen",{get:function(){return!!this.hasFullscreenSupport&&!(!prefixed("fullscreenElement",document)&&!document.mozFullScreenElement)}}),Object.defineProperty(device,"sound",{get:function(){return hasAudio()}});var device$1=device;function extractUniforms(t,e){var i,r={},o=/uniform\s+(\w+)\s+(\w+)/g,n={},s={},a={};return[e.vertex,e.fragment].forEach((function(t){for(;i=o.exec(t);)n[i[2]]=i[1]})),Object.keys(n).forEach((function(i){var r=n[i];a[i]=t.getUniformLocation(e.program,i),s[i]={get:function(t){return function(){return a[t]}}(i),set:function(e,i,r){return 0===i.indexOf("mat")?function(i){t[r](a[e],!1,i)}:function(i){var o=r;i.length&&"v"!==r.substr(-1)&&(o+="v"),t[o](a[e],i)}}(i,r,"uniform"+fnHash[r])}})),Object.defineProperties(r,s),r}function extractAttributes(t,e){for(var i,r={},o=/attribute\s+\w+\s+(\w+)/g,n=0;i=o.exec(e.vertex);)r[i[1]]=n++;return r}function compileShader(t,e,i){var r=t.createShader(e);if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(r));return r}function compileProgram(t,e,i,r){var o=compileShader(t,t.VERTEX_SHADER,e),n=compileShader(t,t.FRAGMENT_SHADER,i),s=t.createProgram();for(var a in t.attachShader(s,o),t.attachShader(s,n),r)t.bindAttribLocation(s,r[a],a);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var h="Error initializing Shader "+this+"\ngl.VALIDATE_STATUS: "+t.getProgramParameter(s,t.VALIDATE_STATUS)+"\ngl.getError()"+t.getError()+"\ngl.getProgramInfoLog()"+t.getProgramInfoLog(s);throw t.deleteProgram(s),s=null,new Error(h)}return t.useProgram(s),t.deleteShader(o),t.deleteShader(n),s}var fnHash={bool:"1i",int:"1i",float:"1f",vec2:"2fv",vec3:"3fv",vec4:"4fv",bvec2:"2iv",bvec3:"3iv",bvec4:"4iv",ivec2:"2iv",ivec3:"3iv",ivec4:"4iv",mat2:"Matrix2fv",mat3:"Matrix3fv",mat4:"Matrix4fv",sampler2D:"1i"};function setPrecision(t,e){return"precision"!==t.substring(0,9)?"precision "+e+" float;"+t:t}function minify(t){return t=(t=(t=(t=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1")).replace(/(\\n\s+)|(\s+\\n)/g,"")).replace(/(\\r|\\n)+/g,"")).replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g,"$1")}var GLShader=function(t,e,i,r){this.gl=t,this.vertex=setPrecision(minify(e),r||device$1.getMaxShaderPrecision(this.gl)),this.fragment=setPrecision(minify(i),r||device$1.getMaxShaderPrecision(this.gl)),this.attributes=extractAttributes(this.gl,this),this.program=compileProgram(this.gl,this.vertex,this.fragment,this.attributes),this.uniforms=extractUniforms(this.gl,this),on(ONCONTEXT_LOST,this.destroy,this)};GLShader.prototype.bind=function(){this.gl.useProgram(this.program)},GLShader.prototype.getAttribLocation=function(t){var e=this.attributes[t];return void 0!==e?e:-1},GLShader.prototype.setUniform=function(t,e){var i=this.uniforms;if(void 0===i[t])throw new Error("undefined ("+t+") uniform for shader "+this);"object"==typeof e&&"function"==typeof e.toArray?i[t]=e.toArray():i[t]=e},GLShader.prototype.destroy=function(){this.uniforms=null,this.attributes=null,this.gl.deleteProgram(this.program),this.vertex=null,this.fragment=null};var VertexArrayBuffer=function(t,e){this.vertexSize=t,this.quadSize=e,this.maxVertex=256,this.vertexCount=0,this.buffer=new ArrayBuffer(this.maxVertex*this.vertexSize*this.quadSize),this.bufferF32=new Float32Array(this.buffer),this.bufferU32=new Uint32Array(this.buffer)};VertexArrayBuffer.prototype.clear=function(){this.vertexCount=0},VertexArrayBuffer.prototype.isFull=function(t){return void 0===t&&(t=this.quadSize),this.vertexCount+t>=this.maxVertex},VertexArrayBuffer.prototype.resize=function(){this.maxVertex<<=1;var t=this.bufferF32;return this.buffer=new ArrayBuffer(this.maxVertex*this.vertexSize*this.quadSize),this.bufferF32=new Float32Array(this.buffer),this.bufferU32=new Uint32Array(this.buffer),this.bufferF32.set(t),this},VertexArrayBuffer.prototype.push=function(t,e,i,r,o){var n=this.vertexCount*this.vertexSize;return this.vertexCount>=this.maxVertex&&this.resize(),this.bufferF32[n+0]=t,this.bufferF32[n+1]=e,void 0!==i&&(this.bufferF32[n+2]=i,this.bufferF32[n+3]=r),void 0!==o&&(this.bufferU32[n+4]=o),this.vertexCount++,this},VertexArrayBuffer.prototype.toFloat32=function(t,e){return void 0!==e?this.bufferF32.subarray(t,e):this.bufferF32},VertexArrayBuffer.prototype.toUint32=function(t,e){return void 0!==e?this.bufferU32.subarray(t,e):this.bufferU32},VertexArrayBuffer.prototype.length=function(){return this.vertexCount},VertexArrayBuffer.prototype.isEmpty=function(){return 0===this.vertexCount};var primitiveVertex="// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\n// Vertex color\nuniform vec4 uColor;\n\n// Fragment color\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(uColor.rgb * uColor.a, uColor.a);\n}\n",primitiveFragment="varying vec4 vColor;\n\nvoid main(void) {\n gl_FragColor = vColor;\n}\n",quadVertex="attribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.bgr * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n",quadFragment="uniform sampler2D uSampler;\nvarying vec4 vColor;\nvarying vec2 vRegion;\n\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vRegion) * vColor;\n}\n",V_ARRAY=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],WebGLCompositor=function(t){this.init(t)};WebGLCompositor.prototype.init=function(t){var e=this,i=t.gl;this.currentTextureUnit=-1,this.boundTextures=[],this.renderer=t,this.gl=t.gl,this.color=t.currentColor,this.viewMatrix=t.currentTransform,this.activeShader=null,this.mode=i.TRIANGLES,this.attributes=[],this.vertexByteSize=0,this.vertexSize=0,this.primitiveShader=new GLShader(this.gl,primitiveVertex,primitiveFragment),this.quadShader=new GLShader(this.gl,quadVertex,quadFragment),this.addAttribute("aVertex",2,i.FLOAT,!1,0*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aRegion",2,i.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aColor",4,i.UNSIGNED_BYTE,!0,4*Float32Array.BYTES_PER_ELEMENT),this.vertexBuffer=new VertexArrayBuffer(this.vertexSize,6),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),i.bufferData(i.ARRAY_BUFFER,this.vertexBuffer.buffer,i.STREAM_DRAW),on(CANVAS_ONRESIZE,(function(t,i){e.flush(),e.setViewport(0,0,t,i)}))},WebGLCompositor.prototype.reset=function(){this.gl=this.renderer.gl,this.flush(),this.setViewport(0,0,this.renderer.getScreenCanvas().width,this.renderer.getScreenCanvas().height),this.clearColor(0,0,0,0);for(var t=0;t<this.renderer.maxTextures;t++){var e=this.getTexture2D(t);void 0!==e&&this.deleteTexture2D(e)}this.currentTextureUnit=-1,this.useShader(this.quadShader)},WebGLCompositor.prototype.addAttribute=function(t,e,i,r,o){switch(this.attributes.push({name:t,size:e,type:i,normalized:r,offset:o}),i){case this.gl.BYTE:this.vertexByteSize+=e*Int8Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_BYTE:this.vertexByteSize+=e*Uint8Array.BYTES_PER_ELEMENT;break;case this.gl.SHORT:this.vertexByteSize+=e*Int16Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_SHORT:this.vertexByteSize+=e*Uint16Array.BYTES_PER_ELEMENT;break;case this.gl.INT:this.vertexByteSize+=e*Int32Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_INT:this.vertexByteSize+=e*Uint32Array.BYTES_PER_ELEMENT;break;case this.gl.FLOAT:this.vertexByteSize+=e*Float32Array.BYTES_PER_ELEMENT;break;default:throw new Error("Invalid GL Attribute type")}this.vertexSize=this.vertexByteSize/Float32Array.BYTES_PER_ELEMENT},WebGLCompositor.prototype.setViewport=function(t,e,i,r){this.gl.viewport(t,e,i,r)},WebGLCompositor.prototype.createTexture2D=function(t,e,i,r,o,n,s,a,h){void 0===r&&(r="no-repeat"),void 0===a&&(a=!0),void 0===h&&(h=!0);var l=this.gl,c=isPowerOfTwo(o||e.width)&&isPowerOfTwo(n||e.height),u=l.createTexture(),d=0===r.search(/^repeat(-x)?$/)&&(c||this.renderer.WebGLVersion>1)?l.REPEAT:l.CLAMP_TO_EDGE,p=0===r.search(/^repeat(-y)?$/)&&(c||this.renderer.WebGLVersion>1)?l.REPEAT:l.CLAMP_TO_EDGE;return this.bindTexture2D(u,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,d),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,p),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,i),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,i),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),o||n||s?l.texImage2D(l.TEXTURE_2D,0,l.RGBA,o,n,s,l.RGBA,l.UNSIGNED_BYTE,e):l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,e),c&&!1!==h&&l.generateMipmap(l.TEXTURE_2D),u},WebGLCompositor.prototype.deleteTexture2D=function(t){this.gl.deleteTexture(t),this.unbindTexture2D(t)},WebGLCompositor.prototype.getTexture2D=function(t){return this.boundTextures[t]},WebGLCompositor.prototype.bindTexture2D=function(t,e){var i=this.gl;t!==this.boundTextures[e]?(this.flush(),this.currentTextureUnit!==e&&(this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,t),this.boundTextures[e]=t):this.currentTextureUnit!==e&&(this.flush(),this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e))},WebGLCompositor.prototype.unbindTexture2D=function(t,e){return void 0===e&&(e=this.boundTextures.indexOf(t)),-1!==e&&(delete this.boundTextures[e],e===this.currentTextureUnit&&(this.currentTextureUnit=-1)),e},WebGLCompositor.prototype.uploadTexture=function(t,e,i,r,o){void 0===o&&(o=!1);var n=this.renderer.cache.getUnit(t),s=this.boundTextures[n];return void 0===s||o?this.createTexture2D(n,t.getTexture(),this.renderer.settings.antiAlias?this.gl.LINEAR:this.gl.NEAREST,t.repeat,e,i,r,t.premultipliedAlpha):this.bindTexture2D(s,n),this.currentTextureUnit},WebGLCompositor.prototype.setProjection=function(t){this.activeShader.setUniform("uProjectionMatrix",t)},WebGLCompositor.prototype.useShader=function(t){if(this.activeShader!==t){this.flush(),this.activeShader=t,this.activeShader.bind(),this.activeShader.setUniform("uProjectionMatrix",this.renderer.projectionMatrix);for(var e=0;e<this.attributes.length;++e){var i=this.gl,r=this.attributes[e],o=this.activeShader.getAttribLocation(r.name);-1!==o?(i.enableVertexAttribArray(o),i.vertexAttribPointer(o,r.size,r.type,r.normalized,this.vertexByteSize,r.offset)):i.disableVertexAttribArray(e)}}},WebGLCompositor.prototype.addQuad=function(t,e,i,r,o,n,s,a,h,l){if(!(this.color.alpha<1/255)){this.useShader(this.quadShader),this.vertexBuffer.isFull(6)&&this.flush();var c=this.uploadTexture(t);this.quadShader.setUniform("uSampler",c);var u=this.viewMatrix,d=V_ARRAY[0].set(e,i),p=V_ARRAY[1].set(e+r,i),f=V_ARRAY[2].set(e,i+o),y=V_ARRAY[3].set(e+r,i+o);u.isIdentity()||(u.apply(d),u.apply(p),u.apply(f),u.apply(y)),this.vertexBuffer.push(d.x,d.y,n,s,l),this.vertexBuffer.push(p.x,p.y,a,s,l),this.vertexBuffer.push(f.x,f.y,n,h,l),this.vertexBuffer.push(f.x,f.y,n,h,l),this.vertexBuffer.push(p.x,p.y,a,s,l),this.vertexBuffer.push(y.x,y.y,a,h,l)}},WebGLCompositor.prototype.flush=function(t){void 0===t&&(t=this.mode);var e=this.vertexBuffer,i=e.vertexCount;if(i>0){var r=this.gl,o=e.vertexSize;this.renderer.WebGLVersion>1?r.bufferData(r.ARRAY_BUFFER,e.toFloat32(),r.STREAM_DRAW,0,i*o):r.bufferData(r.ARRAY_BUFFER,e.toFloat32(0,i*o),r.STREAM_DRAW),r.drawArrays(t,0,i),e.clear()}},WebGLCompositor.prototype.drawVertices=function(t,e,i){void 0===i&&(i=e.length),this.useShader(this.primitiveShader),this.primitiveShader.setUniform("uColor",this.color);for(var r=this.viewMatrix,o=this.vertexBuffer,n=r.isIdentity(),s=0;s<i;s++)n||r.apply(e[s]),o.push(e[s].x,e[s].y);this.flush(t)},WebGLCompositor.prototype.clearColor=function(t,e,i,r){this.gl.clearColor(t,e,i,r)},WebGLCompositor.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)};var WebGLRenderer=function(t){function e(e){var i=this;t.call(this,e),this.WebGLVersion=1,this.GPUVendor=null,this.GPURenderer=null,this.context=this.gl=this.getContextGL(this.getScreenCanvas(),e.transparent),this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this._colorStack=[],this._matrixStack=[],this._scissorStack=[],this._blendStack=[],this._glPoints=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.currentTransform=new Matrix2d,this.currentCompositor=null,this.compositors=new Map;var r=new(this.settings.compositor||WebGLCompositor)(this);this.compositors.set("default",r),this.setCompositor(r),this.gl.disable(this.gl.DEPTH_TEST),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.enable(this.gl.BLEND),this.setBlendMode(this.settings.blendMode);var o=this.gl.getExtension("WEBGL_debug_renderer_info");null!==o&&(this.GPUVendor=this.gl.getParameter(o.UNMASKED_VENDOR_WEBGL),this.GPURenderer=this.gl.getParameter(o.UNMASKED_RENDERER_WEBGL)),this.cache=new TextureCache(this.maxTextures),this.getScreenCanvas().addEventListener("webglcontextlost",(function(t){t.preventDefault(),i.isContextValid=!1,emit(ONCONTEXT_LOST,i)}),!1),this.getScreenCanvas().addEventListener("webglcontextrestored",(function(){i.reset(),i.isContextValid=!0,emit(ONCONTEXT_RESTORED,i)}),!1)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){var e=this;t.prototype.reset.call(this),this.compositors.forEach((function(t){!1===e.isContextValid?t.init(e):t.reset()})),this.gl.disable(this.gl.SCISSOR_TEST),void 0!==this.fontContext2D&&this.createFontTexture(this.cache)},e.prototype.setCompositor=function(t){if(void 0===t&&(t="default"),"string"==typeof t&&(t=this.compositors.get(t)),void 0===t)throw new Error("Invalid WebGL Compositor");this.currentCompositor!==t&&(null!==this.currentCompositor&&this.currentCompositor.flush(),this.currentCompositor=t)},e.prototype.resetTransform=function(){this.currentTransform.identity()},e.prototype.createFontTexture=function(t){if(void 0===this.fontTexture){var e=this.backBufferCanvas,i=e.width,r=e.height;1===this.WebGLVersion&&(isPowerOfTwo(i)||(i=nextPowerOfTwo(e.width)),isPowerOfTwo(r)||(r=nextPowerOfTwo(e.height)));var o=createCanvas(i,r,!0);this.fontContext2D=this.getContext2d(o),this.fontTexture=new TextureAtlas(createAtlas(e.width,e.height,"fontTexture"),o,t),this.currentCompositor.uploadTexture(this.fontTexture,0,0,0)}else t.set(this.fontContext2D.canvas,this.fontTexture)},e.prototype.createPattern=function(t,e){if(!(1!==renderer.WebGLVersion||isPowerOfTwo(t.width)&&isPowerOfTwo(t.height))){var i=void 0!==t.src?t.src:t;throw new Error("[WebGL Renderer] "+i+" is not a POT texture ("+t.width+"x"+t.height+")")}var r=new TextureAtlas(createAtlas(t.width,t.height,"pattern",e),t);return this.currentCompositor.uploadTexture(r),r},e.prototype.flush=function(){this.currentCompositor.flush()},e.prototype.setProjection=function(e){t.prototype.setProjection.call(this,e),this.currentCompositor.setProjection(e)},e.prototype.clearColor=function(t,e){var i;if(void 0===t&&(t="#000000"),void 0===e&&(e=!1),t instanceof Color)i=t.toArray();else{var r=pull("me.Color");i=r.parseCSS(t).toArray(),push(r)}this.currentCompositor.clearColor(i[0],i[1],i[2],!0===e?1:i[3]),this.currentCompositor.clear(),this.currentCompositor.clearColor(0,0,0,0)},e.prototype.clearRect=function(t,e,i,r){this.save(),this.clipRect(t,e,i,r),this.clearColor(),this.restore()},e.prototype.drawFont=function(t){var e=this.getFontContext();this.currentCompositor.uploadTexture(this.fontTexture,0,0,0,!0);var i=this.fontTexture.getUVs(t.left+","+t.top+","+t.width+","+t.height);this.currentCompositor.addQuad(this.fontTexture,t.left,t.top,t.width,t.height,i[0],i[1],i[2],i[3],this.currentTint.toUint32()),e.clearRect(t.left,t.top,t.width,t.height)},e.prototype.drawImage=function(t,e,i,r,o,n,s,a,h){void 0===r?(r=a=t.width,o=h=t.height,n=e,s=i,e=0,i=0):void 0===n&&(n=e,s=i,a=r,h=o,r=t.width,o=t.height,e=0,i=0),!1===this.settings.subPixel&&(n|=0,s|=0);var l=this.cache.get(t),c=l.getUVs(e+","+i+","+r+","+o);this.currentCompositor.addQuad(l,n,s,a,h,c[0],c[1],c[2],c[3],this.currentTint.toUint32())},e.prototype.drawPattern=function(t,e,i,r,o){var n=t.getUVs("0,0,"+r+","+o);this.currentCompositor.addQuad(t,e,i,r,o,n[0],n[1],n[2],n[3],this.currentTint.toUint32())},e.prototype.getScreenContext=function(){return this.gl},e.prototype.getContextGL=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a GL context");"boolean"!=typeof e&&(e=!0);var i,r={alpha:e,antialias:this.settings.antiAlias,depth:!1,stencil:!0,preserveDrawingBuffer:!1,premultipliedAlpha:e,powerPreference:this.settings.powerPreference,failIfMajorPerformanceCaveat:this.settings.failIfMajorPerformanceCaveat};if(!1===this.settings.preferWebGL1&&(i=t.getContext("webgl2",r))&&(this.WebGLVersion=2),i||(this.WebGLVersion=1,i=t.getContext("webgl",r)||t.getContext("experimental-webgl",r)),!i)throw new Error("A WebGL context could not be created.");return i},e.prototype.getContext=function(){return this.gl},e.prototype.setBlendMode=function(t,e){if(void 0===t&&(t="normal"),void 0===e&&(e=this.gl),this.currentBlendMode!==t)switch(this.flush(),e.enable(e.BLEND),this.currentBlendMode=t,t){case"screen":e.blendFunc(e.ONE,e.ONE_MINUS_SRC_COLOR);break;case"lighter":case"additive":e.blendFunc(e.ONE,e.ONE);break;case"multiply":e.blendFunc(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA);break;default:e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode="normal"}},e.prototype.getFontContext=function(){return void 0===this.fontContext2D&&(console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !"),this.createFontTexture(this.cache)),this.fontContext2D},e.prototype.restore=function(){if(0!==this._matrixStack.length){var t=this._colorStack.pop(),e=this._matrixStack.pop();this.currentColor.copy(t),this.currentTransform.copy(e),this.setBlendMode(this._blendStack.pop()),push(t),push(e)}0!==this._scissorStack.length?this.currentScissor.set(this._scissorStack.pop()):(this.gl.disable(this.gl.SCISSOR_TEST),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height)},e.prototype.save=function(){this._colorStack.push(this.currentColor.clone()),this._matrixStack.push(this.currentTransform.clone()),this.gl.isEnabled(this.gl.SCISSOR_TEST)&&this._scissorStack.push(this.currentScissor.slice()),this._blendStack.push(this.getBlendMode())},e.prototype.rotate=function(t){this.currentTransform.rotate(t)},e.prototype.scale=function(t,e){this.currentTransform.scale(t,e)},e.prototype.setAntiAlias=function(e,i){t.prototype.setAntiAlias.call(this,e,i)},e.prototype.setGlobalAlpha=function(t){this.currentColor.alpha=t},e.prototype.setColor=function(t){var e=this.currentColor.alpha;this.currentColor.copy(t),this.currentColor.alpha*=e},e.prototype.setLineWidth=function(t){this.getScreenContext().lineWidth(t)},e.prototype.strokeArc=function(t,e,i,r,o,n,s){if(void 0===n&&(n=!1),!0===s)this.fillArc(t,e,i,r,o,n);else{var a,h=this._glPoints,l=Math.floor(24*Math.sqrt(2*i)),c=(o-r)/(2*l),u=2*c,d=Math.cos(c),p=Math.sin(c);for(a=h.length;a<l+1;a++)h.push(new Vector2d);for(a=0;a<l;a++){var f=c+r+u*a,y=Math.cos(f),g=-Math.sin(f);h[a].x=t+(d*y+p*g)*i,h[a].y=e+(d*-g+p*y)*i}this.currentCompositor.drawVertices(this.gl.LINE_STRIP,h,l)}},e.prototype.fillArc=function(t,e,i,r,o){var n,s=this._glPoints,a=0,h=Math.floor(24*Math.sqrt(2*i)),l=(o-r)/(2*h),c=2*l,u=Math.cos(l),d=Math.sin(l);for(n=s.length;n<2*h;n++)s.push(new Vector2d);for(n=0;n<h-1;n++){var p=l+r+c*n,f=Math.cos(p),y=-Math.sin(p);s[a++].set(t,e),s[a++].set(t-(u*f+d*y)*i,e-(u*-y+d*f)*i)}this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,s,a)},e.prototype.strokeEllipse=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillEllipse(t,e,i,r);else{var n,s=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+r)),a=TAU/s,h=this._glPoints;for(n=h.length;n<s;n++)h.push(new Vector2d);for(n=0;n<s;n++)h[n].x=t+Math.sin(a*-n)*i,h[n].y=e+Math.cos(a*-n)*r;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,h,s)}},e.prototype.fillEllipse=function(t,e,i,r){var o,n=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+r)),s=TAU/n,a=this._glPoints,h=0;for(o=a.length;o<2*(n+1);o++)a.push(new Vector2d);for(o=0;o<n+1;o++)a[h++].set(t,e),a[h++].set(t+Math.sin(s*o)*i,e+Math.cos(s*o)*r);this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeLine=function(t,e,i,r){var o=this._glPoints;o[0].x=t,o[0].y=e,o[1].x=i,o[1].y=r,this.currentCompositor.drawVertices(this.gl.LINE_STRIP,o,2)},e.prototype.fillLine=function(t,e,i,r){this.strokeLine(t,e,i,r)},e.prototype.strokePolygon=function(t,e){if(void 0===e&&(e=!1),!0===e)this.fillPolygon(t);else{var i,r=t.points.length,o=this._glPoints;for(i=o.length;i<r;i++)o.push(new Vector2d);for(i=0;i<r;i++)o[i].x=t.pos.x+t.points[i].x,o[i].y=t.pos.y+t.points[i].y;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,o,r)}},e.prototype.fillPolygon=function(t){var e,i=t.points,r=this._glPoints,o=t.getIndices(),n=t.pos.x,s=t.pos.y;for(e=r.length;e<o.length;e++)r.push(new Vector2d);for(e=0;e<o.length;e++)r[e].set(n+i[o[e]].x,s+i[o[e]].y);this.currentCompositor.drawVertices(this.gl.TRIANGLES,r,o.length)},e.prototype.strokeRect=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillRect(t,e,i,r);else{var n=this._glPoints;n[0].x=t,n[0].y=e,n[1].x=t+i,n[1].y=e,n[2].x=t+i,n[2].y=e+r,n[3].x=t,n[3].y=e+r,this.currentCompositor.drawVertices(this.gl.LINE_LOOP,n,4)}},e.prototype.fillRect=function(t,e,i,r){var o=this._glPoints;o[0].x=t+i,o[0].y=e,o[1].x=t,o[1].y=e,o[2].x=t+i,o[2].y=e+r,o[3].x=t,o[3].y=e+r,this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,o,4)},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=this.currentTransform;if(e.multiply(t),!1===this.settings.subPixel){var i=e.toArray();i[6]|=0,i[7]|=0}},e.prototype.translate=function(t,e){var i=this.currentTransform;if(i.translate(t,e),!1===this.settings.subPixel){var r=i.toArray();r[6]|=0,r[7]|=0}},e.prototype.clipRect=function(t,e,i,r){var o=this.backBufferCanvas,n=this.gl;if(0!==t||0!==e||i!==o.width||r!==o.height){var s=this.currentScissor;if(n.isEnabled(n.SCISSOR_TEST)&&s[0]===t&&s[1]===e&&s[2]===i&&s[3]===r)return;this.flush(),n.enable(this.gl.SCISSOR_TEST),n.scissor(t+this.currentTransform.tx,o.height-r-e-this.currentTransform.ty,i,r),s[0]=t,s[1]=e,s[2]=i,s[3]=r}else n.disable(n.SCISSOR_TEST)},e.prototype.setMask=function(t){var e=this.gl;this.flush(),e.enable(e.STENCIL_TEST),e.clear(e.STENCIL_BUFFER_BIT),e.colorMask(!1,!1,!1,!1),e.stencilFunc(e.NOTEQUAL,1,1),e.stencilOp(e.REPLACE,e.REPLACE,e.REPLACE),this.fill(t),this.flush(),e.colorMask(!0,!0,!0,!0),e.stencilFunc(e.EQUAL,1,1),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)},e.prototype.clearMask=function(){this.flush(),this.gl.disable(this.gl.STENCIL_TEST)},e}(Renderer),designRatio=1,designWidth=0,designHeight=0,settings={parent:void 0,renderer:2,doubleBuffering:!1,autoScale:!1,scale:1,scaleMethod:"fit",transparent:!1,blendMode:"normal",antiAlias:!1,failIfMajorPerformanceCaveat:!0,subPixel:!1,preferWebGL1:!1,powerPreference:"default",verbose:!1,consoleHeader:!0};function autoDetectRenderer(t){try{if(device$1.isWebGLSupported(t))return new WebGLRenderer(t)}catch(t){console.log("Error creating WebGL renderer :"+t.message)}return new CanvasRenderer(t)}function onresize(){var t=renderer.settings,e=1,i=1;if(t.autoScale){var r=1/0,o=1/0;if(globalThis.getComputedStyle){var n=globalThis.getComputedStyle(renderer.getScreenCanvas(),null);r=parseInt(n.maxWidth,10)||1/0,o=parseInt(n.maxHeight,10)||1/0}var s=device$1.getParentBounds(getParent()),a=Math.min(r,s.width),h=Math.min(o,s.height),l=a/h;if("fill-min"===t.scaleMethod&&l>designRatio||"fill-max"===t.scaleMethod&&l<designRatio||"flex-width"===t.scaleMethod){var c=Math.min(r,designHeight*l);e=i=a/c,renderer.resize(Math.floor(c),designHeight)}else if("fill-min"===t.scaleMethod&&l<designRatio||"fill-max"===t.scaleMethod&&l>designRatio||"flex-height"===t.scaleMethod){var u=Math.min(o,designWidth*(h/a));e=i=h/u,renderer.resize(designWidth,Math.floor(u))}else"flex"===t.scaleMethod?renderer.resize(Math.floor(a),Math.floor(h)):"stretch"===t.scaleMethod?(e=a/designWidth,i=h/designHeight):e=i=l<designRatio?a/designWidth:h/designHeight;scale(e,i)}}var CANVAS=0,WEBGL=1,AUTO=2,parent=null,scaleRatio=new Vector2d(1,1),renderer=null;function init(t,e,i){if(!exports.initialized)throw new Error("me.video.init() called before engine initialization.");(settings=Object.assign(settings,i||{})).width=t,settings.height=e,settings.doubleBuffering=!!settings.doubleBuffering,settings.transparent=!!settings.transparent,settings.antiAlias=!!settings.antiAlias,settings.failIfMajorPerformanceCaveat=!!settings.failIfMajorPerformanceCaveat,settings.subPixel=!!settings.subPixel,settings.verbose=!!settings.verbose,-1!==settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/)?settings.autoScale="auto"===settings.scale||!0:(settings.scaleMethod="fit",settings.autoScale="auto"===settings.scale||!1),!1!==settings.consoleHeader&&console.log("melonJS 2 (v"+version+") | http://melonjs.org");var r=utils.getUriFragment();!0!==r.webgl&&!0!==r.webgl1&&!0!==r.webgl2||(settings.renderer=WEBGL,!0===r.webgl1&&(settings.preferWebGL1=!0)),settings.scale=settings.autoScale?1:+settings.scale||1,scaleRatio.set(settings.scale,settings.scale),(settings.autoScale||1!==settings.scale)&&(settings.doubleBuffering=!0),designRatio=t/e,designWidth=t,designHeight=e,settings.zoomX=t*scaleRatio.x,settings.zoomY=e*scaleRatio.y,globalThis.addEventListener("resize",utils.function.throttle((function(t){emit(WINDOW_ONRESIZE,t)}),100),!1),globalThis.addEventListener("orientationchange",(function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),!1),globalThis.addEventListener("onmozorientationchange",(function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),!1),!0===device$1.ScreenOrientation&&(globalThis.screen.orientation.onchange=function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),globalThis.addEventListener("scroll",utils.function.throttle((function(t){emit(WINDOW_ONSCROLL,t)}),100),!1),on(WINDOW_ONRESIZE,onresize,this),on(WINDOW_ONORIENTATION_CHANGE,onresize,this);try{switch(settings.renderer){case AUTO:case WEBGL:renderer=autoDetectRenderer(settings);break;default:renderer=new CanvasRenderer(settings)}}catch(t){return console(t.message),!1}((parent=device$1.getElement(void 0!==settings.parent?settings.parent:document.body)).appendChild(renderer.getScreenCanvas()),onresize(),"MutationObserver"in globalThis)&&new MutationObserver(onresize.bind(this)).observe(parent,{attributes:!1,childList:!0,subtree:!0});if(!1!==settings.consoleHeader){var o=renderer instanceof CanvasRenderer?"CANVAS":"WebGL"+renderer.WebGLVersion,n=device$1.hasWebAudio?"Web Audio":"HTML5 Audio",s="string"==typeof renderer.GPURenderer?" ("+renderer.GPURenderer+")":"";console.log(o+" renderer"+s+" | "+n+" | pixel ratio "+device$1.devicePixelRatio+" | "+(device$1.nodeJS?"node.js":device$1.isMobile?"mobile":"desktop")+" | "+device$1.getScreenOrientation()+" | "+device$1.language),console.log("resolution: requested "+t+"x"+e+", got "+renderer.getWidth()+"x"+renderer.getHeight())}return emit(VIDEO_INIT),!0}function createCanvas(t,e,i){var r;if(void 0===i&&(i=!1),0===t||0===e)throw new Error("width or height was zero, Canvas could not be initialized !");return!0===device$1.OffscreenCanvas&&!0===i?void 0===(r=new OffscreenCanvas(0,0)).style&&(r.style={}):r=document.createElement("canvas"),r.width=t,r.height=e,r}function getParent(){return parent}function scale(t,e){var i=renderer.getScreenCanvas(),r=renderer.getScreenContext(),o=renderer.settings,n=device$1.devicePixelRatio,s=o.zoomX=i.width*t*n,a=o.zoomY=i.height*e*n;scaleRatio.set(t*n,e*n),i.style.width=s/n+"px",i.style.height=a/n+"px",renderer.setAntiAlias(r,o.antiAlias),renderer.setBlendMode(o.blendMode,r),repaint()}var video=Object.freeze({__proto__:null,CANVAS:CANVAS,WEBGL:WEBGL,AUTO:AUTO,get parent(){return parent},scaleRatio:scaleRatio,get renderer(){return renderer},init:init,createCanvas:createCanvas,getParent:getParent,scale:scale}),GUID_base="",GUID_index=0,utils={agent:agentUtils,array:arrayUtils,file:fileUtils,string:stringUtils,function:fnUtils,getPixels:function(t){if(t instanceof HTMLImageElement){var e=CanvasRenderer.getContext2d(createCanvas(t.width,t.height));return e.drawImage(t,0,0),e.getImageData(0,0,t.width,t.height)}return t.getContext("2d").getImageData(0,0,t.width,t.height)},checkVersion:function(t,e){void 0===e&&(e=version);for(var i=t.split("."),r=e.split("."),o=Math.min(i.length,r.length),n=0,s=0;s<o&&!(n=+i[s]-+r[s]);s++);return n||i.length-r.length},getUriFragment:function(t){var e={};if(void 0===t){if(void 0===globalThis.document)return e;var i=globalThis.document.location;if(!i||!i.hash)return e;t=i.hash}else{var r=t.indexOf("#");if(-1===r)return e;t=t.substr(r,t.length)}return t.substr(1).split("&").filter((function(t){return""!==t})).forEach((function(t){var i=t.split("="),r=i.shift(),o=i.join("=");e[r]=o||!0})),e},resetGUID:function(t,e){void 0===e&&(e=0),GUID_base=toHex$1(t.toString().toUpperCase()),GUID_index=e},createGUID:function(t){return void 0===t&&(t=1),GUID_index+=t,GUID_base+"-"+(t||GUID_index)}},framecount=0,framedelta=0,last=0,now=0,delta=0,step=0,minstep=0,timers=[],timerId=0;function update(t){last=now,(delta=(now=t)-last)<0&&(delta=0),timer.tick=delta>minstep&&timer.interpolation?delta/step:1,updateTimers()}function clearTimer(t){for(var e=0,i=timers.length;e<i;e++)if(timers[e].timerId===t){timers.splice(e,1);break}}function updateTimers(){for(var t=0,e=timers.length;t<e;t++){var i=timers[t];i.pauseable&&state.isPaused()||(i.elapsed+=delta),i.elapsed>=i.delay&&(i.fn.apply(null,i.args),!0===i.repeat?i.elapsed-=i.delay:timer.clearTimeout(i.timerId))}}on(BOOT,(function(){timer.reset(),now=last=0,on(GAME_BEFORE_UPDATE,update)}));var timer={tick:1,fps:0,maxfps:60,interpolation:!1,reset:function(){last=now=globalThis.performance.now(),delta=0,framedelta=0,framecount=0,step=Math.ceil(1e3/this.maxfps),minstep=1e3/this.maxfps*1.25},setTimeout:function(t,e,i){for(var r=[],o=arguments.length-3;o-- >0;)r[o]=arguments[o+3];return timers.push({fn:t,delay:e,elapsed:0,repeat:!1,timerId:++timerId,pauseable:!0===i||!0,args:r}),timerId},setInterval:function(t,e,i){for(var r=[],o=arguments.length-3;o-- >0;)r[o]=arguments[o+3];return timers.push({fn:t,delay:e,elapsed:0,repeat:!0,timerId:++timerId,pauseable:!0===i||!0,args:r}),timerId},clearTimeout:function(t){utils.function.defer(clearTimer,this,t)},clearInterval:function(t){utils.function.defer(clearTimer,this,t)},getTime:function(){return now},getDelta:function(){return delta},countFPS:function(){framecount++,framedelta+=delta,framecount%10==0&&(this.fps=clamp(Math.round(1e3*framecount/framedelta),0,this.maxfps),framedelta=0,framecount=0)}},timer$1=timer,lastTime=0,vendors=["ms","moz","webkit","o"],x,requestAnimationFrame=globalThis.requestAnimationFrame,cancelAnimationFrame=globalThis.cancelAnimationFrame;for(x=0;x<vendors.length&&!requestAnimationFrame;++x)requestAnimationFrame=globalThis[vendors[x]+"RequestAnimationFrame"];for(x=0;x<vendors.length&&!cancelAnimationFrame;++x)cancelAnimationFrame=globalThis[vendors[x]+"CancelAnimationFrame"]||globalThis[vendors[x]+"CancelRequestAnimationFrame"];requestAnimationFrame&&cancelAnimationFrame||(requestAnimationFrame=function(t){var e=globalThis.performance.now(),i=Math.max(0,1e3/timer$1.maxfps-(e-lastTime)),r=globalThis.setTimeout((function(){t(e+i)}),i);return lastTime=e+i,r},cancelAnimationFrame=function(t){globalThis.clearTimeout(t)},globalThis.requestAnimationFrame=requestAnimationFrame,globalThis.cancelAnimationFrame=cancelAnimationFrame);var plugins={},BasePlugin=function(){this.version="10.7.0"},plugin={Base:BasePlugin,patch:function(t,e,i){if(void 0!==t.prototype&&(t=t.prototype),"function"!=typeof t[e])throw new Error(e+" is not an existing function");var r=t[e];Object.defineProperty(t,e,{configurable:!0,value:function(t,e){return function(){this._patched=r;var t=e.apply(this,arguments);return this._patched=null,t}}(0,i)})},register:function(t,e){if(plugins[e])throw new Error("plugin "+e+" already registered");var i=[];arguments.length>2&&(i=Array.prototype.slice.call(arguments,1)),i[0]=t;var r=new(t.bind.apply(t,i));if(void 0===r||!(r instanceof plugin.Base))throw new Error("Plugin should extend the me.plugin.Base Class !");if(utils.checkVersion(r.version)>0)throw new Error("Plugin version mismatch, expected: "+r.version+", got: "+version);plugins[e]=r}},Easing={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-Easing.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*Easing.Bounce.In(2*t):.5*Easing.Bounce.Out(2*t-1)+.5}}},Interpolation={Linear:function(t,e){var i=t.length-1,r=i*e,o=Math.floor(r),n=Interpolation.Utils.Linear;return e<0?n(t[0],t[1],r):e>1?n(t[i],t[i-1],i-r):n(t[o],t[o+1>i?i:o+1],r-o)},Bezier:function(t,e){var i,r=0,o=t.length-1,n=Math.pow,s=Interpolation.Utils.Bernstein;for(i=0;i<=o;i++)r+=n(1-e,o-i)*n(e,i)*t[i]*s(o,i);return r},CatmullRom:function(t,e){var i=t.length-1,r=i*e,o=Math.floor(r),n=Interpolation.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(o=Math.floor(r=i*(1+e))),n(t[(o-1+i)%i],t[o],t[(o+1)%i],t[(o+2)%i],r-o)):e<0?t[0]-(n(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[i]-(n(t[i],t[i],t[i-1],t[i-1],r-i)-t[i]):n(t[o?o-1:0],t[o],t[i<o+1?i:o+1],t[i<o+2?i:o+2],r-o)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=Interpolation.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:function(){var t=[1];return function(e){var i,r=1;if(t[e])return t[e];for(i=e;i>1;i--)r*=i;return t[e]=r,r}}(),CatmullRom:function(t,e,i,r,o){var n=.5*(i-t),s=.5*(r-e),a=o*o;return(2*e-2*i+n+s)*(o*a)+(-3*e+3*i-2*n-s)*a+n*o+e}}},Tween=function(t){this.setProperties(t)},staticAccessors={Easing:{configurable:!0},Interpolation:{configurable:!0}};function setContextStyle(t,e,i){void 0===i&&(i=!1),t.font=e.font,t.fillStyle=e.fillStyle.toRGBA(),!0===i&&(t.strokeStyle=e.strokeStyle.toRGBA(),t.lineWidth=e.lineWidth),t.textAlign=e.textAlign,t.textBaseline=e.textBaseline}Tween.prototype.onResetEvent=function(t){this.setProperties(t)},Tween.prototype.setProperties=function(t){for(var e in this._object=t,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._repeat=0,this._yoyo=!1,this._reversed=!1,this._delayTime=0,this._startTime=null,this._easingFunction=Easing.Linear.None,this._interpolationFunction=Interpolation.Linear,this._chainedTweens=[],this._onStartCallback=null,this._onStartCallbackFired=!1,this._onUpdateCallback=null,this._onCompleteCallback=null,this._tweenTimeTracker=lastUpdate,this.isPersistent=!1,this.updateWhenPaused=!1,this.isRenderable=!1,t)"object"!=typeof t&&(this._valuesStart[e]=parseFloat(t[e]))},Tween.prototype._resumeCallback=function(t){this._startTime&&(this._startTime+=t)},Tween.prototype.onActivateEvent=function(){on(STATE_RESUME,this._resumeCallback,this)},Tween.prototype.onDeactivateEvent=function(){off(STATE_RESUME,this._resumeCallback)},Tween.prototype.to=function(t,e){return this._valuesEnd=t,void 0!==e&&("number"==typeof e?this._duration=e:"object"==typeof e&&(e.duration&&(this._duration=e.duration),e.yoyo&&this.yoyo(e.yoyo),e.easing&&this.easing(e.easing),e.repeat&&this.repeat(e.repeat),e.delay&&this.delay(e.delay),e.interpolation&&this.interpolation(e.interpolation),e.autoStart&&this.start())),this},Tween.prototype.start=function(t){for(var e in void 0===t&&(t=timer$1.getTime()),this._onStartCallbackFired=!1,world.addChild(this),this._startTime=t+this._delayTime,this._valuesEnd){if(this._valuesEnd[e]instanceof Array){if(0===this._valuesEnd[e].length)continue;this._valuesEnd[e]=[this._object[e]].concat(this._valuesEnd[e])}this._valuesStart[e]=this._object[e],this._valuesStart[e]instanceof Array==!1&&(this._valuesStart[e]*=1),this._valuesStartRepeat[e]=this._valuesStart[e]||0}return this},Tween.prototype.stop=function(){return world.removeChildNow(this),this},Tween.prototype.delay=function(t){return this._delayTime=t,this},Tween.prototype.repeat=function(t){return this._repeat=t,this},Tween.prototype.yoyo=function(t){return this._yoyo=t,this},Tween.prototype.easing=function(t){if("function"!=typeof t)throw new Error("invalid easing function for me.Tween.easing()");return this._easingFunction=t,this},Tween.prototype.interpolation=function(t){return this._interpolationFunction=t,this},Tween.prototype.chain=function(){return this._chainedTweens=arguments,this},Tween.prototype.onStart=function(t){return this._onStartCallback=t,this},Tween.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},Tween.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},Tween.prototype.update=function(t){this._tweenTimeTracker=lastUpdate>this._tweenTimeTracker?lastUpdate:this._tweenTimeTracker+t;var e,i=this._tweenTimeTracker;if(i<this._startTime)return!0;!1===this._onStartCallbackFired&&(null!==this._onStartCallback&&this._onStartCallback.call(this._object),this._onStartCallbackFired=!0);var r=(i-this._startTime)/this._duration;r=r>1?1:r;var o=this._easingFunction(r);for(e in this._valuesEnd){var n=this._valuesStart[e]||0,s=this._valuesEnd[e];s instanceof Array?this._object[e]=this._interpolationFunction(s,o):("string"==typeof s&&(s=n+parseFloat(s)),"number"==typeof s&&(this._object[e]=n+(s-n)*o))}if(null!==this._onUpdateCallback&&this._onUpdateCallback.call(this._object,o),1===r){if(this._repeat>0){for(e in isFinite(this._repeat)&&this._repeat--,this._valuesStartRepeat){if("string"==typeof this._valuesEnd[e]&&(this._valuesStartRepeat[e]=this._valuesStartRepeat[e]+parseFloat(this._valuesEnd[e])),this._yoyo){var a=this._valuesStartRepeat[e];this._valuesStartRepeat[e]=this._valuesEnd[e],this._valuesEnd[e]=a}this._valuesStart[e]=this._valuesStartRepeat[e]}return this._yoyo&&(this._reversed=!this._reversed),this._startTime=i+this._delayTime,!0}world.removeChildNow(this),null!==this._onCompleteCallback&&this._onCompleteCallback.call(this._object);for(var h=0,l=this._chainedTweens.length;h<l;h++)this._chainedTweens[h].start(i);return!1}return!0},staticAccessors.Easing.get=function(){return Easing},staticAccessors.Interpolation.get=function(){return Interpolation},Object.defineProperties(Tween,staticAccessors);var TextMetrics=function(t){function e(e){t.call(this),this.ancestor=e,this.setMinMax(0,0,0,0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.lineHeight=function(){return this.ancestor instanceof Text?this.ancestor.fontSize*this.ancestor.lineHeight:this.ancestor.fontData.capHeight*this.ancestor.lineHeight*this.ancestor.fontScale.y},e.prototype.lineWidth=function(t,e){if(this.ancestor instanceof Text)return e.measureText(t).width;for(var i=t.split(""),r=0,o=null,n=0;n<i.length;n++){var s=i[n].charCodeAt(0),a=this.ancestor.fontData.glyphs[s],h=o&&o.kerning?o.getKerning(s):0;r+=(a.xadvance+h)*this.ancestor.fontScale.x,o=a}return r},e.prototype.measureText=function(t,e){var i;i=Array.isArray(t)?t:(""+t).split("\n"),void 0!==e&&(e.save(),setContextStyle(e,this.ancestor)),this.width=this.height=0;for(var r=0;r<i.length;r++)this.width=Math.max(this.lineWidth(trimRight(i[r]),e),this.width),this.height+=this.lineHeight();return this.width=Math.ceil(this.width),this.height=Math.ceil(this.height),this.x=Math.floor("right"===this.ancestor.textAlign?this.ancestor.pos.x-this.width:"center"===this.ancestor.textAlign?this.ancestor.pos.x-this.width/2:this.ancestor.pos.x),this.y=Math.floor(0===this.ancestor.textBaseline.search(/^(top|hanging)$/)?this.ancestor.pos.y:"middle"===this.ancestor.textBaseline?this.ancestor.pos.y-this.lineHeight()/2:this.ancestor.pos.y-this.lineHeight()),void 0!==e&&e.restore(),this},e.prototype.wordWrap=function(t,e,i){var r,o="",n=[];Array.isArray(t)&&(t=t.join(" ")),r=t.replace(/[\r\n]+/g," ").split(" "),void 0!==i&&(i.save(),setContextStyle(i,this.ancestor));for(var s=0;s<r.length;s++){var a=r[s];this.lineWidth(o+a+" ",i)<e?o+=a+" ":(n.push(o+"\n"),o=a+" ")}return n.push(o),void 0!==i&&i.restore(),n},e}(Bounds$1),runits=["ex","em","pt","px"],toPX=[12,24,.75,1],getContext2d=function(t,e){return!0===e.offScreenCanvas?e.context:t.getFontContext()},Text=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.onResetEvent(e,i,r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e,i){void 0!==i.fillStyle?i.fillStyle instanceof Color?this.fillStyle=i.fillStyle:this.fillStyle=pull("Color").parseCSS(i.fillStyle):this.fillStyle=pull("Color",0,0,0),void 0!==i.strokeStyle?i.strokeStyle instanceof Color?this.strokeStyle=i.strokeStyle:this.strokeStyle=pull("Color").parseCSS(i.strokeStyle):this.strokeStyle=pull("Color",0,0,0),this.lineWidth=i.lineWidth||1,this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this.offScreenCanvas=!1,this.wordWrapWidth=i.wordWrapWidth||-1,this._text=[],this.fontSize=10,void 0!==i.anchorPoint?this.anchorPoint.setV(i.anchorPoint):this.anchorPoint.set(0,0),void 0!==i.floating&&(this.floating=!!i.floating),this.setFont(i.font,i.size),!0===i.bold&&this.bold(),!0===i.italic&&this.italic(),!0===i.offScreenCanvas&&(this.offScreenCanvas=!0,this.canvas=createCanvas(2,2,!0),this.context=this.canvas.getContext("2d")),this.metrics=new TextMetrics(this),this.setText(i.text)},e.prototype.onDeactivateEvent=function(){!0===this.offScreenCanvas&&(renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit)),renderer.cache.delete(this.canvas),this.canvas.width=this.canvas.height=0,this.context=void 0,this.canvas=void 0,this.glTextureUnit=void 0)},e.prototype.bold=function(){return this.font="bold "+this.font,this.isDirty=!0,this},e.prototype.italic=function(){return this.font="italic "+this.font,this.isDirty=!0,this},e.prototype.setFont=function(t,e){void 0===e&&(e=10);var i=t.split(",").map((function(t){return t=t.trim(),/(^".*"$)|(^'.*'$)/.test(t)?t:'"'+t+'"'}));if("number"==typeof e)this.fontSize=e,e+="px";else{var r=e.match(/([-+]?[\d.]*)(.*)/);this.fontSize=parseFloat(r[1]),r[2]?this.fontSize*=toPX[runits.indexOf(r[2])]:e+="px"}return this.height=this.fontSize,this.font=e+" "+i.join(","),this.isDirty=!0,this},e.prototype.setText=function(t){void 0===t&&(t="");var e=this.getBounds();if(this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n")),this._text.length>0&&this.wordWrapWidth>0&&(this._text=this.metrics.wordWrap(this._text,this.wordWrapWidth,getContext2d(renderer,this))),e.addBounds(this.metrics.measureText(this._text,getContext2d(renderer,this)),!0),!0===this.offScreenCanvas){var i=Math.ceil(this.metrics.width),r=Math.ceil(this.metrics.height);renderer instanceof WebGLRenderer&&(this.glTextureUnit=renderer.cache.getUnit(renderer.cache.get(this.canvas)),renderer.currentCompositor.unbindTexture2D(null,this.glTextureUnit),1===renderer.WebGLVersion&&(i=nextPowerOfTwo(this.metrics.width),r=nextPowerOfTwo(this.metrics.height))),this.canvas.width<i||this.canvas.height<r?(this.canvas.width=i,this.canvas.height=r):this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this._drawFont(this.context,this._text,this.pos.x-this.metrics.x,this.pos.y-this.metrics.y,!1)}return this.isDirty=!0,this},e.prototype.measureText=function(t,e){return void 0===t&&(t=renderer),void 0===e&&(e=this._text),this.metrics.measureText(e,getContext2d(t,this))},e.prototype.draw=function(t,e,i,r,o){void 0===this.ancestor?(this.pos.x===i&&this.pos.y===r||(this.pos.x=i,this.pos.y=r,this.isDirty=!0),this.setText(e),i=this.metrics.x,r=this.metrics.y,t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())):(i=this.pos.x,r=this.pos.y),!1===t.settings.subPixel&&(i=~~i,r=~~r),!0===this.offScreenCanvas?t.drawImage(this.canvas,i,r):t.drawFont(this._drawFont(t.getFontContext(),this._text,i,r,o)),void 0===this.ancestor&&t.restore()},e.prototype.drawStroke=function(t,e,i,r){this.draw(t,e,i,r,!0)},e.prototype._drawFont=function(t,e,i,r,o){void 0===o&&(o=!1),setContextStyle(t,this,o);for(var n=0;n<e.length;n++){var s=trimRight(e[n]);t[o?"strokeText":"fillText"](s,i,r),r+=this.metrics.lineHeight()}return this.metrics},e.prototype.destroy=function(){push(this.fillStyle),push(this.strokeStyle),this.fillStyle=this.strokeStyle=void 0,this.metrics=void 0,this._text.length=0,t.prototype.destroy.call(this)},e}(Renderable),BitmapText=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.textAlign=r.textAlign||"left",this.textBaseline=r.textBaseline||"top",this.lineHeight=r.lineHeight||1,this.wordWrapWidth=r.wordWrapWidth||-1,this._text=[],this.fontScale=pull("Vector2d",1,1),this.fontImage="object"==typeof r.font?r.font:loader.getImage(r.font),"string"!=typeof r.fontData?this.fontData=pull("BitmapTextData",loader.getBinary(r.font)):this.fontData=pull("BitmapTextData",r.fontData.includes("info face")?r.fontData:loader.getBinary(r.fontData)),void 0!==r.floating&&(this.floating=!!r.floating),void 0!==r.fillStyle&&(r.fillStyle instanceof Color?this.fillStyle.setColor(r.fillStyle):this.fillStyle.parseCSS(r.fillStyle)),void 0!==r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0),this.metrics=new TextMetrics(this),"number"==typeof r.size&&1!==r.size&&this.resize(r.size),this.setText(r.text)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={fillStyle:{configurable:!0}};return e.prototype.set=function(t,e){return this.textAlign=t,e&&this.resize(e),this.isDirty=!0,this},e.prototype.setText=function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this._text.length>0&&this.wordWrapWidth>0&&(this._text=this.metrics.wordWrap(this._text,this.wordWrapWidth)),this.getBounds().addBounds(this.metrics.measureText(this._text),!0),this},i.fillStyle.get=function(){return this.tint},i.fillStyle.set=function(t){this.tint=t},e.prototype.resize=function(t){return this.fontScale.set(t,t),this.getBounds().addBounds(this.metrics.measureText(this._text),!0),this.isDirty=!0,this},e.prototype.measureText=function(t){return void 0===t&&(t=this._text),this.metrics.measureText(t)},e.prototype.draw=function(t,e,i,r){var o=t.globalAlpha();void 0===this.ancestor?(this.setText(e),t.setGlobalAlpha(o*this.getOpacity())):(i=this.pos.x,r=this.pos.y);for(var n=i,s=this.metrics.lineHeight(),a=0,h=0;h<this._text.length;h++){i=n;var l=trimRight(this._text[h]),c=this.metrics.lineWidth(l);switch(this.textAlign){case"right":i-=c;break;case"center":i-=.5*c}switch(this.textBaseline){case"middle":r-=.5*s;break;case"ideographic":case"alphabetic":case"bottom":r-=s}!0===this.isDirty&&void 0===this.ancestor&&(0===h&&(this.pos.y=r),a<c&&(a=c,this.pos.x=i));for(var u=null,d=0,p=l.length;d<p;d++){var f=l.charCodeAt(d),y=this.fontData.glyphs[f],g=y.width,v=y.height,m=u&&u.kerning?u.getKerning(f):0;0!==g&&0!==v&&t.drawImage(this.fontImage,y.x,y.y,g,v,i+y.xoffset,r+y.yoffset*this.fontScale.y,g*this.fontScale.x,v*this.fontScale.y),i+=(y.xadvance+m)*this.fontScale.x,u=y}r+=s}void 0===this.ancestor&&t.setGlobalAlpha(o),this.isDirty=!1},e.prototype.destroy=function(){push(this.fontScale),this.fontScale=void 0,push(this.fontData),this.fontData=void 0,this._text.length=0,this.metrics=void 0,t.prototype.destroy.call(this)},Object.defineProperties(e.prototype,i),e}(Renderable),LOG2_PAGE_SIZE=9,PAGE_SIZE=1<<LOG2_PAGE_SIZE,Glyph=function(){this.id=0,this.x=0,this.y=0,this.width=0,this.height=0,this.u=0,this.v=0,this.u2=0,this.v2=0,this.xoffset=0,this.yoffset=0,this.xadvance=0,this.fixedWidth=!1};Glyph.prototype.getKerning=function(t){if(this.kerning){var e=this.kerning[t>>>LOG2_PAGE_SIZE];if(e)return e[t&PAGE_SIZE-1]||0}return 0},Glyph.prototype.setKerning=function(t,e){this.kerning||(this.kerning={});var i=this.kerning[t>>>LOG2_PAGE_SIZE];void 0===i&&(this.kerning[t>>>LOG2_PAGE_SIZE]={},i=this.kerning[t>>>LOG2_PAGE_SIZE]),i[t&PAGE_SIZE-1]=e};var capChars=["M","N","B","D","C","E","F","K","A","G","H","I","J","L","O","P","Q","R","S","T","U","V","W","X","Y","Z"];function getValueFromPair(t,e){var i=t.match(e);if(!i)throw new Error("Could not find pattern "+e+" in string: "+t);return i[0].split("=")[1]}function getFirstGlyph(t){for(var e=Object.keys(t),i=0;i<e.length;i++)if(e[i]>32)return t[e[i]];return null}function createSpaceGlyph(t){var e=" ".charCodeAt(0),i=t[e];i||((i=new Glyph).id=e,i.xadvance=getFirstGlyph(t).xadvance,t[e]=i)}var BitmapTextData=function(t){this.onResetEvent(t)};BitmapTextData.prototype.onResetEvent=function(t){this.padTop=0,this.padRight=0,this.padBottom=0,this.padLeft=0,this.lineHeight=0,this.capHeight=1,this.descent=0,this.glyphs={},this.parse(t)},BitmapTextData.prototype.parse=function(t){if(!t)throw new Error("File containing font data was empty, cannot load the bitmap font.");var e=t.split(/\r\n|\n/),i=t.match(/padding\=\d+,\d+,\d+,\d+/g);if(!i)throw new Error("Padding not found in first line");var r=i[0].split("=")[1].split(",");this.padTop=parseFloat(r[0]),this.padLeft=parseFloat(r[1]),this.padBottom=parseFloat(r[2]),this.padRight=parseFloat(r[3]),this.lineHeight=parseFloat(getValueFromPair(e[1],/lineHeight\=\d+/g));var o,n=parseFloat(getValueFromPair(e[1],/base\=\d+/g)),s=this.padTop+this.padBottom,a=null;for(o=4;o<e.length;o++){var h=e[o],l=h.split(/=|\s+/);if(h&&!/^kernings/.test(h))if(/^kerning\s/.test(h)){var c=parseFloat(l[2]),u=parseFloat(l[4]),d=parseFloat(l[6]);null!=(a=this.glyphs[c])&&a.setKerning(u,d)}else{a=new Glyph;var p=parseFloat(l[2]);a.id=p,a.x=parseFloat(l[4]),a.y=parseFloat(l[6]),a.width=parseFloat(l[8]),a.height=parseFloat(l[10]),a.xoffset=parseFloat(l[12]),a.yoffset=parseFloat(l[14]),a.xadvance=parseFloat(l[16]),a.width>0&&a.height>0&&(this.descent=Math.min(n+a.yoffset,this.descent)),this.glyphs[p]=a}}this.descent+=this.padBottom,createSpaceGlyph(this.glyphs);var f=null;for(o=0;o<capChars.length;o++){var y=capChars[o];if(f=this.glyphs[y.charCodeAt(0)])break}if(f)this.capHeight=f.height;else for(var g in this.glyphs)if(this.glyphs.hasOwnProperty(g)){if(0===(a=this.glyphs[g]).height||0===a.width)continue;this.capHeight=Math.max(this.capHeight,a.height)}this.capHeight-=s};var ColorLayer=function(t){function e(e,i,r){t.call(this,0,0,1/0,1/0),this.color=pull("Color").parseCSS(i),this.onResetEvent(e,i,r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e,i){void 0===i&&(i=0),this.name=t,this.pos.z=i,this.floating=!0,this.color.parseCSS(e)},e.prototype.draw=function(t,e){var i=viewport.pos;t.save(),t.clipRect(e.left-i.x,e.top-i.y,e.width,e.height),t.clearColor(this.color),t.restore()},e.prototype.destroy=function(){push(this.color),this.color=void 0,t.prototype.destroy.call(this)},e}(Renderable),ImageLayer=function(t){function e(e,i,r){t.call(this,e,i,r),this.floating=!0,this.offset.set(e,i),this.ratio=pull("Vector2d",1,1),void 0!==r.ratio&&(isNumeric(r.ratio)?this.ratio.set(r.ratio,+r.ratio):this.ratio.setV(r.ratio)),void 0===r.anchorPoint?this.anchorPoint.set(0,0):"number"==typeof r.anchorPoint?this.anchorPoint.set(r.anchorPoint,r.anchorPoint):this.anchorPoint.setV(r.anchorPoint),this.repeat=r.repeat||"repeat",on(ONCONTEXT_RESTORED,this.createPattern,this)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={repeat:{configurable:!0}};return i.repeat.get=function(){return this._repeat},i.repeat.set=function(t){switch(this._repeat=t,this._repeat){case"no-repeat":this.repeatX=!1,this.repeatY=!1;break;case"repeat-x":this.repeatX=!0,this.repeatY=!1;break;case"repeat-y":this.repeatX=!1,this.repeatY=!0;break;default:this.repeatX=!0,this.repeatY=!0}this.resize(viewport.width,viewport.height),this.createPattern()},e.prototype.onActivateEvent=function(){var t=this;on(VIEWPORT_ONCHANGE,this.updateLayer,this),on(VIEWPORT_ONRESIZE,this.resize,this),once(LEVEL_LOADED,(function(){t.updateLayer(viewport.pos)})),!0!==this.ancestor.root&&this.updateLayer(viewport.pos)},e.prototype.resize=function(e,i){t.prototype.resize.call(this,this.repeatX?1/0:e,this.repeatY?1/0:i)},e.prototype.createPattern=function(){this._pattern=renderer.createPattern(this.image,this._repeat)},e.prototype.updateLayer=function(t){var e=this.ratio.x,i=this.ratio.y;if(0!==e||0!==i){var r=this.width,o=this.height,n=viewport.bounds.width,s=viewport.bounds.height,a=this.anchorPoint.x,h=this.anchorPoint.y,l=a*(e-1)*(n-viewport.width)+this.offset.x-e*t.x,c=h*(i-1)*(s-viewport.height)+this.offset.y-i*t.y;this.repeatX?this.pos.x=l%r:this.pos.x=l,this.repeatY?this.pos.y=c%o:this.pos.y=c,this.isDirty=!0}},e.prototype.preDraw=function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),t.setTint(this.tint)},e.prototype.draw=function(t){var e=this.width,i=this.height,r=viewport.bounds.width,o=viewport.bounds.height,n=this.anchorPoint.x,s=this.anchorPoint.y,a=this.pos.x,h=this.pos.y;0===this.ratio.x&&0===this.ratio.y&&(a+=n*(r-e),h+=s*(o-i)),t.translate(a,h),t.drawPattern(this._pattern,0,0,2*viewport.width,2*viewport.height)},e.prototype.onDeactivateEvent=function(){off(VIEWPORT_ONCHANGE,this.updateLayer),off(VIEWPORT_ONRESIZE,this.resize)},e.prototype.destroy=function(){push(this.ratio),this.ratio=void 0,off(ONCONTEXT_RESTORED,this.createPattern),t.prototype.destroy.call(this)},Object.defineProperties(e.prototype,i),e}(Sprite),NineSliceSprite=function(t){function e(e,i,r){if(t.call(this,e,i,r),"number"!=typeof r.width||"number"!=typeof r.height)throw new Error("height and width properties are mandatory");this.width=Math.floor(r.width),this.height=Math.floor(r.height),this.nss_width=this.width,this.nss_height=this.height,this.insetx=r.insetx,this.insety=r.insety}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.draw=function(t){var e=this.current,i=this.pos.x,r=this.pos.y,o=e.width,n=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-r),t.rotate(e.angle),i-=n,o=e.height,n=e.width);var h=a.x+s.x,l=a.y+s.y,c=this.insetx||o/4,u=this.insety||n/4;t.drawImage(this.image,h,l,c,u,i,r,c,u),t.drawImage(this.image,h+o-c,l,c,u,i+this.nss_width-c,r,c,u),t.drawImage(this.image,h,l+n-u,c,u,i,r+this.nss_height-u,c,u),t.drawImage(this.image,h+o-c,l+n-u,c,u,i+this.nss_width-c,r+this.nss_height-u,c,u);var d=o-(c<<1),p=n-(u<<1),f=this.nss_width-(c<<1),y=this.nss_height-(u<<1);t.drawImage(this.image,h+c,l,d,u,i+c,r,f,u),t.drawImage(this.image,h+c,l+n-u,d,u,i+c,r+this.nss_height-u,f,u),t.drawImage(this.image,h,l+u,c,p,i,r+u,c,y),t.drawImage(this.image,h+o-c,l+u,c,p,i+this.nss_width-c,r+u,c,y),t.drawImage(this.image,h+c,l+u,d,p,i+c,r+u,f,y)},e}(Sprite),GUI_Object=function(t){function e(e,i,r){t.call(this,e,i,r),this.isClickable=!0,this.holdThreshold=250,this.isHoldable=!1,this.hover=!1,this.holdTimeout=null,this.released=!0,this.floating=!0,this.isKinematic=!1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clicked=function(t){if(0===t.button&&this.isClickable)return this.dirty=!0,this.released=!1,this.isHoldable&&(null!==this.holdTimeout&&timer$1.clearTimeout(this.holdTimeout),this.holdTimeout=timer$1.setTimeout(this.hold.bind(this),this.holdThreshold,!1),this.released=!1),this.onClick(t)},e.prototype.onClick=function(){return!1},e.prototype.enter=function(t){return this.hover=!0,this.dirty=!0,this.onOver(t)},e.prototype.onOver=function(){},e.prototype.leave=function(t){return this.hover=!1,this.dirty=!0,this.release(t),this.onOut(t)},e.prototype.onOut=function(){},e.prototype.release=function(t){if(!1===this.released)return this.released=!0,this.dirty=!0,timer$1.clearTimeout(this.holdTimeout),this.onRelease(t)},e.prototype.onRelease=function(){return!1},e.prototype.hold=function(){timer$1.clearTimeout(this.holdTimeout),this.dirty=!0,this.released||this.onHold()},e.prototype.onHold=function(){},e.prototype.onActivateEvent=function(){registerPointerEvent("pointerdown",this,this.clicked.bind(this)),registerPointerEvent("pointerup",this,this.release.bind(this)),registerPointerEvent("pointercancel",this,this.release.bind(this)),registerPointerEvent("pointerenter",this,this.enter.bind(this)),registerPointerEvent("pointerleave",this,this.leave.bind(this))},e.prototype.onDeactivateEvent=function(){releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),releasePointerEvent("pointerenter",this),releasePointerEvent("pointerleave",this),timer$1.clearTimeout(this.holdTimeout)},e}(Sprite),Collectable=function(t){function e(e,i,r){t.call(this,e,i,r),this.name=r.name,this.type=r.type,this.id=r.id,this.body=new Body(this,r.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.COLLECTABLE_OBJECT,this.body.setCollisionMask(collision.types.PLAYER_OBJECT),this.body.setStatic(!0),r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Sprite),Trigger=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.anchorPoint.set(0,0),this.fade=r.fade,this.duration=r.duration,this.fading=!1,this.name="Trigger",this.type=r.type,this.id=r.id,this.gotolevel=r.to,this.triggerSettings={event:"level"},["type","container","onLoaded","flatten","setViewportBounds","to"].forEach(function(t){void 0!==r[t]&&(this.triggerSettings[t]=r[t])}.bind(this)),this.body=new Body(this,r.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.ACTION_OBJECT,this.body.setCollisionMask(collision.types.PLAYER_OBJECT),this.body.setStatic(!0),this.resize(this.body.getBounds().width,this.body.getBounds().height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getTriggerSettings=function(){return"string"==typeof this.triggerSettings.container&&(this.triggerSettings.container=world.getChildByName(this.triggerSettings.container)[0]),this.triggerSettings},e.prototype.onFadeComplete=function(){level.load(this.gotolevel,this.getTriggerSettings()),viewport.fadeOut(this.fade,this.duration)},e.prototype.triggerEvent=function(){var t=this.getTriggerSettings();if("level"!==t.event)throw new Error("Trigger invalid type");this.gotolevel=t.to,this.fade&&this.duration?this.fading||(this.fading=!0,viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))):level.load(this.gotolevel,t)},e.prototype.onCollision=function(){return"Trigger"===this.name&&this.triggerEvent.apply(this),!1},e}(Renderable),Draggable=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isKinematic=!1,this.dragging=!1,this.dragId=null,this.grabOffset=new Vector2d(0,0),this.initEvents()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.initEvents=function(){var t=this;registerPointerEvent("pointerdown",this,(function(e){emit(DRAGSTART,e,t)})),registerPointerEvent("pointerup",this,(function(e){emit(DRAGEND,e,t)})),registerPointerEvent("pointercancel",this,(function(e){emit(DRAGEND,e,t)})),on(POINTERMOVE,this.dragMove.bind(this)),on(DRAGSTART,(function(e,i){i===t&&t.dragStart(e)})),on(DRAGEND,(function(e,i){i===t&&t.dragEnd(e)}))},e.prototype.dragStart=function(t){if(!1===this.dragging)return this.dragging=!0,this.grabOffset.set(t.gameX,t.gameY),this.grabOffset.sub(this.pos),!1},e.prototype.dragMove=function(t){!0===this.dragging&&(this.pos.set(t.gameX,t.gameY,this.pos.z),this.pos.sub(this.grabOffset))},e.prototype.dragEnd=function(){if(!0===this.dragging)return this.dragging=!1,!1},e.prototype.destroy=function(){off(POINTERMOVE,this.dragMove),off(DRAGSTART,this.dragStart),off(DRAGEND,this.dragEnd),releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),t.prototype.destroy.call(this)},e}(Renderable),DropTarget=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isKinematic=!1,this.CHECKMETHOD_OVERLAP="overlaps",this.CHECKMETHOD_CONTAINS="contains",this.checkMethod=this.CHECKMETHOD_OVERLAP,on(DRAGEND,this.checkOnMe,this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setCheckMethod=function(t){"function"==typeof this.getBounds()[this.checkMethod]&&(this.checkMethod=t)},e.prototype.checkOnMe=function(t,e){e&&this.getBounds()[this.checkMethod](e.getBounds())&&this.drop(e)},e.prototype.drop=function(){},e.prototype.destroy=function(){off(DRAGEND,this.checkOnMe),t.prototype.destroy.call(this)},e}(Renderable),ParticleEmitterSettings={width:1,height:1,image:void 0,textureSize:8,tint:"#fff",totalParticles:50,angle:Math.PI/2,angleVariation:0,minLife:1e3,maxLife:3e3,speed:2,speedVariation:1,minRotation:0,maxRotation:0,minStartScale:1,maxStartScale:1,minEndScale:0,maxEndScale:0,gravity:0,wind:0,followTrajectory:!1,textureAdditive:!1,blendMode:"normal",onlyInViewport:!0,floating:!1,maxParticles:10,frequency:100,duration:1/0,framesToSkip:0},defaultParticleTexture;function createDefaultParticleTexture(t,e){if(void 0===t&&(t=8),void 0===e&&(e=8),void 0===defaultParticleTexture){var i=(defaultParticleTexture=createCanvas(t,e,!0)).getContext("2d");i.fillStyle="#fff",i.fillRect(0,0,t,e)}return defaultParticleTexture}var ParticleEmitter=function(t){function e(e,i,r){void 0===r&&(r={}),t.call(this,e,i,1|r.width,1|r.height),this.centerOn(e,i),this._stream=!1,this._frequencyTimer=0,this._durationTimer=0,this._enabled=!1,this.alwaysUpdate=!0,this.autoSort=!1,this._updateCount=0,this.settings={},this._dt=0,this.reset(r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(t){void 0===t&&(t={}),Object.assign(this.settings,ParticleEmitterSettings,t),void 0===this.settings.image&&(this.settings.image=createDefaultParticleTexture(t.textureSize,t.textureSize)),this.floating=this.settings.floating,this.isDirty=!0},e.prototype.getRandomPointX=function(){return randomFloat(0,this.getBounds().width)},e.prototype.getRandomPointY=function(){return randomFloat(0,this.getBounds().height)},e.prototype.addParticles=function(t){for(var e=0;e<~~t;e++)this.addChild(pull("Particle",this),this.pos.z);this.isDirty=!0},e.prototype.isRunning=function(){return this._enabled&&this._stream},e.prototype.streamParticles=function(t){this._enabled=!0,this._stream=!0,this.settings.frequency=Math.max(1,this.settings.frequency),this._durationTimer="number"==typeof t?t:this.settings.duration},e.prototype.stopStream=function(){this._enabled=!1},e.prototype.burstParticles=function(t){this._enabled=!0,this._stream=!1,this.addParticles("number"==typeof t?t:this.settings.totalParticles),this._enabled=!1},e.prototype.update=function(e){if(++this._updateCount>this.settings.framesToSkip&&(this._updateCount=0),this._updateCount>0)return this._dt+=e,this.isDirty;if(e+=this._dt,this._dt=0,this.isDirty|=t.prototype.update.call(this,e),this._enabled&&this._stream){if(this._durationTimer!==1/0&&(this._durationTimer-=e,this._durationTimer<=0))return this.stopStream(),this.isDirty;this._frequencyTimer+=e;var i=this.children.length;i<this.settings.totalParticles&&this._frequencyTimer>=this.settings.frequency&&(i+this.settings.maxParticles<=this.settings.totalParticles?this.addParticles(this.settings.maxParticles):this.addParticles(this.settings.totalParticles-i),this._frequencyTimer=0,this.isDirty=!0)}return this.isDirty},e.prototype.destroy=function(){t.prototype.destroy.call(this,arguments),this.settings.image=void 0,this.settings=void 0},e}(Container),Particle=function(t){function e(e){t.call(this,e.getRandomPointX(),e.getRandomPointY(),e.settings.image.width,e.settings.image.height),this.onResetEvent(e,!0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e){void 0===e&&(e=!1),!1===e?(this.pos.set(t.getRandomPointX(),t.getRandomPointY()),this.resize(t.settings.image.width,t.settings.image.height)):this.vel=new Vector2d,this.image=t.settings.image,this.alwaysUpdate=!0,"string"==typeof t.settings.tint&&this.tint.parseCSS(t.settings.tint),!0===t.settings.textureAdditive&&(this.blendMode="additive"),"normal"!==t.settings.blendMode&&(this.blendMode=t.settings.blendMode);var i=t.settings.angle+(t.settings.angleVariation>0?(randomFloat(0,2)-1)*t.settings.angleVariation:0),r=t.settings.speed+(t.settings.speedVariation>0?(randomFloat(0,2)-1)*t.settings.speedVariation:0);this.vel.set(r*Math.cos(i),-r*Math.sin(i)),this.life=randomFloat(t.settings.minLife,t.settings.maxLife),this.startLife=this.life,this.startScale=clamp(randomFloat(t.settings.minStartScale,t.settings.maxStartScale),t.settings.minStartScale,t.settings.maxStartScale),this.endScale=clamp(randomFloat(t.settings.minEndScale,t.settings.maxEndScale),t.settings.minEndScale,t.settings.maxEndScale),this.gravity=t.settings.gravity,this.wind=t.settings.wind,this.followTrajectory=t.settings.followTrajectory,this.onlyInViewport=t.settings.onlyInViewport,this._deltaInv=timer$1.maxfps/1e3,t.settings.followTrajectory||(this.angle=randomFloat(t.settings.minRotation,t.settings.maxRotation))},e.prototype.update=function(e){var i=e*this._deltaInv;if(this.life=this.life>e?this.life-e:0,this.life<=0)return this.ancestor.removeChild(this),!1;var r=this.life/this.startLife,o=this.startScale;this.startScale>this.endScale?o=(o*=r)<this.endScale?this.endScale:o:this.startScale<this.endScale&&(o=(o/=r)>this.endScale?this.endScale:o),this.alpha=r,this.vel.x+=this.wind*i,this.vel.y+=this.gravity*i;var n=this.followTrajectory?Math.atan2(this.vel.y,this.vel.x):this.angle;return this.pos.x+=this.vel.x*i,this.pos.y+=this.vel.y*i,this.currentTransform.setTransform(o,0,0,0,o,0,this.pos.x,this.pos.y,1).rotate(n),this.isDirty=this.inViewport||!this.onlyInViewport,t.prototype.update.call(this,e)},e.prototype.draw=function(t){var e=this.width,i=this.height;t.drawImage(this.image,0,0,e,i,-e/2,-i/2,e,i)},e}(Renderable),Entity=function(t){function e(e,i,r){if("number"!=typeof r.width||"number"!=typeof r.height)throw new Error("height and width properties are mandatory when passing settings parameters to an object entity");t.call(this,e,i,r.width,r.height),this.children=[],r.image&&(r.framewidth=r.framewidth||r.width,r.frameheight=r.frameheight||r.height,this.renderable=new Sprite(0,0,r)),r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0),"string"==typeof r.name&&(this.name=r.name),this.type=r.type||"",this.id=r.id||"",this.alive=!0,void 0===r.shapes&&(r.shapes=new Polygon(0,0,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])),this.body=new Body(this,r.shapes,this.onBodyUpdate.bind(this)),0===this.width&&0===this.height&&this.resize(this.body.getBounds().width,this.body.getBounds().height),this.body.setCollisionMask(r.collisionMask),this.body.setCollisionType(r.collisionType),this.autoTransform=!1}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={renderable:{configurable:!0}};return i.renderable.get=function(){return this.children[0]},i.renderable.set=function(e){if(!(e instanceof t))throw new Error(e+"should extend me.Renderable");this.children[0]=e,this.children[0].ancestor=this},e.prototype.update=function(e){return this.renderable&&(this.isDirty|=this.renderable.update(e)),t.prototype.update.call(this,e)},e.prototype.onBodyUpdate=function(t){this.getBounds().addBounds(t.getBounds(),!0),this.updateBoundsPos(this.pos.x,this.pos.y)},e.prototype.preDraw=function(e){e.save(),e.translate(this.pos.x+this.body.getBounds().x,this.pos.y+this.body.getBounds().y),this.renderable instanceof t&&e.translate(this.anchorPoint.x*this.body.getBounds().width,this.anchorPoint.y*this.body.getBounds().height)},e.prototype.draw=function(e,i){var r=this.renderable;r instanceof t&&(r.preDraw(e),r.draw(e,i),r.postDraw(e))},e.prototype.destroy=function(){this.renderable&&(this.renderable.destroy.apply(this.renderable,arguments),this.children.splice(0,1)),t.prototype.destroy.call(this,arguments)},e.prototype.onDeactivateEvent=function(){this.renderable&&this.renderable.onDeactivateEvent&&this.renderable.onDeactivateEvent()},Object.defineProperties(e.prototype,i),e}(Renderable);function warning(t,e,i){var r="melonJS: %s is deprecated since version %s, please use %s",o=(new Error).stack;console.groupCollapsed?console.groupCollapsed("%c"+r,"font-weight:normal;color:yellow;",t,i,e):console.warn(r,t,i,e),void 0!==o&&console.warn(o),console.groupCollapsed&&console.groupEnd()}device$1.turnOnPointerLock=function(){return warning("device.turnOnPointerLock()","input.requestPointerLock()","10.3.0"),requestPointerLock()},device$1.turnOffPointerLock=function(){return warning("device.turnOffPointerLock()","input.exitPointerLock()","10.3.0"),exitPointerLock()},Object.defineProperty(Renderer.prototype,"Texture",{get:function(){return warning("me.video.renderer.Texture","me.TextureAtlas","10.4.0"),TextureAtlas}});var DraggableEntity=function(t){function e(e,i,r){warning("DraggableEntity","Draggable","10.5.0"),t.call(this,e,i,r.width,r.height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Draggable),DroptargetEntity=function(t){function e(e,i,r){warning("DroptargetEntity","DropTarget","10.5.0"),t.call(this,e,i,r.width,r.height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(DropTarget),version="10.7.0";exports.initialized=!1;var skipAutoInit=!1;function boot(){!0!==exports.initialized&&(register("me.Entity",Entity),register("me.Collectable",Collectable),register("me.Trigger",Trigger),register("me.Tween",Tween,!0),register("me.Color",Color,!0),register("me.Particle",Particle,!0),register("me.Sprite",Sprite),register("me.NineSliceSprite",NineSliceSprite),register("me.Renderable",Renderable),register("me.Text",Text,!0),register("me.BitmapText",BitmapText),register("me.BitmapTextData",BitmapTextData,!0),register("me.ImageLayer",ImageLayer),register("me.ColorLayer",ColorLayer,!0),register("me.Vector2d",Vector2d,!0),register("me.Vector3d",Vector3d,!0),register("me.ObservableVector2d",ObservableVector2d,!0),register("me.ObservableVector3d",ObservableVector3d,!0),register("me.Matrix2d",Matrix2d,!0),register("me.Matrix3d",Matrix3d,!0),register("me.Rect",Rect,!0),register("me.Polygon",Polygon,!0),register("me.Line",Line,!0),register("me.Ellipse",Ellipse,!0),register("me.Bounds",Bounds$1,!0),register("Entity",Entity),register("Collectable",Collectable),register("Trigger",Trigger),register("Tween",Tween,!0),register("Color",Color,!0),register("Particle",Particle,!0),register("Sprite",Sprite),register("NineSliceSprite",NineSliceSprite),register("Renderable",Renderable),register("Text",Text,!0),register("BitmapText",BitmapText),register("BitmapTextData",BitmapTextData,!0),register("ImageLayer",ImageLayer),register("ColorLayer",ColorLayer,!0),register("Vector2d",Vector2d,!0),register("Vector3d",Vector3d,!0),register("ObservableVector2d",ObservableVector2d,!0),register("ObservableVector3d",ObservableVector3d,!0),register("Matrix2d",Matrix2d,!0),register("Matrix3d",Matrix3d,!0),register("Rect",Rect,!0),register("Polygon",Polygon,!0),register("Line",Line,!0),register("Ellipse",Ellipse,!0),register("Bounds",Bounds$1,!0),emit(BOOT),loader.setNocache(utils.getUriFragment().nocache||!1),initKeyboardEvent(),exports.initialized=!0)}device$1.onReady((function(){boot()})),exports.BitmapText=BitmapText,exports.BitmapTextData=BitmapTextData,exports.Body=Body,exports.Bounds=Bounds$1,exports.Camera2d=Camera2d,exports.CanvasRenderer=CanvasRenderer,exports.Collectable=Collectable,exports.Color=Color,exports.ColorLayer=ColorLayer,exports.Container=Container,exports.Draggable=Draggable,exports.DraggableEntity=DraggableEntity,exports.DropTarget=DropTarget,exports.DroptargetEntity=DroptargetEntity,exports.Ellipse=Ellipse,exports.Entity=Entity,exports.GLShader=GLShader,exports.GUI_Object=GUI_Object,exports.ImageLayer=ImageLayer,exports.Line=Line,exports.Math=math,exports.Matrix2d=Matrix2d,exports.Matrix3d=Matrix3d,exports.NineSliceSprite=NineSliceSprite,exports.ObservableVector2d=ObservableVector2d,exports.ObservableVector3d=ObservableVector3d,exports.Particle=Particle,exports.ParticleEmitter=ParticleEmitter,exports.ParticleEmitterSettings=ParticleEmitterSettings,exports.Pointer=Pointer,exports.Polygon=Polygon,exports.QuadTree=QuadTree,exports.Rect=Rect,exports.Renderable=Renderable,exports.Renderer=Renderer,exports.Sprite=Sprite,exports.Stage=Stage,exports.TMXHexagonalRenderer=TMXHexagonalRenderer,exports.TMXIsometricRenderer=TMXIsometricRenderer,exports.TMXLayer=TMXLayer,exports.TMXOrthogonalRenderer=TMXOrthogonalRenderer,exports.TMXRenderer=TMXRenderer,exports.TMXStaggeredRenderer=TMXStaggeredRenderer,exports.TMXTileMap=TMXTileMap,exports.TMXTileset=TMXTileset,exports.TMXTilesetGroup=TMXTilesetGroup,exports.Text=Text,exports.TextureAtlas=TextureAtlas,exports.Tile=Tile,exports.Trigger=Trigger,exports.Tween=Tween,exports.Vector2d=Vector2d,exports.Vector3d=Vector3d,exports.WebGLCompositor=WebGLCompositor,exports.WebGLRenderer=WebGLRenderer,exports.World=World,exports.audio=audio,exports.boot=boot,exports.collision=collision,exports.device=device$1,exports.event=event$1,exports.game=game,exports.input=input,exports.level=level,exports.loader=loader,exports.plugin=plugin,exports.plugins=plugins,exports.pool=pooling,exports.save=save,exports.skipAutoInit=skipAutoInit,exports.state=state,exports.timer=timer$1,exports.utils=utils,exports.version=version,exports.video=video,exports.warning=warning,Object.defineProperty(exports,"__esModule",{value:!0})}));
30
+ function(){var t;HowlerGlobal.prototype._pos=[0,0,0],HowlerGlobal.prototype._orientation=[0,0,-1,0,1,0],HowlerGlobal.prototype.stereo=function(t){var e=this;if(!e.ctx||!e.ctx.listener)return e;for(var i=e._howls.length-1;i>=0;i--)e._howls[i].stereo(t);return e},HowlerGlobal.prototype.pos=function(t,e,i){var r=this;return r.ctx&&r.ctx.listener?(e="number"!=typeof e?r._pos[1]:e,i="number"!=typeof i?r._pos[2]:i,"number"!=typeof t?r._pos:(r._pos=[t,e,i],void 0!==r.ctx.listener.positionX?(r.ctx.listener.positionX.setTargetAtTime(r._pos[0],Howler.ctx.currentTime,.1),r.ctx.listener.positionY.setTargetAtTime(r._pos[1],Howler.ctx.currentTime,.1),r.ctx.listener.positionZ.setTargetAtTime(r._pos[2],Howler.ctx.currentTime,.1)):r.ctx.listener.setPosition(r._pos[0],r._pos[1],r._pos[2]),r)):r},HowlerGlobal.prototype.orientation=function(t,e,i,r,o,n){var s=this;if(!s.ctx||!s.ctx.listener)return s;var a=s._orientation;return e="number"!=typeof e?a[1]:e,i="number"!=typeof i?a[2]:i,r="number"!=typeof r?a[3]:r,o="number"!=typeof o?a[4]:o,n="number"!=typeof n?a[5]:n,"number"!=typeof t?a:(s._orientation=[t,e,i,r,o,n],void 0!==s.ctx.listener.forwardX?(s.ctx.listener.forwardX.setTargetAtTime(t,Howler.ctx.currentTime,.1),s.ctx.listener.forwardY.setTargetAtTime(e,Howler.ctx.currentTime,.1),s.ctx.listener.forwardZ.setTargetAtTime(i,Howler.ctx.currentTime,.1),s.ctx.listener.upX.setTargetAtTime(r,Howler.ctx.currentTime,.1),s.ctx.listener.upY.setTargetAtTime(o,Howler.ctx.currentTime,.1),s.ctx.listener.upZ.setTargetAtTime(n,Howler.ctx.currentTime,.1)):s.ctx.listener.setOrientation(t,e,i,r,o,n),s)},Howl.prototype.init=(t=Howl.prototype.init,function(e){var i=this;return i._orientation=e.orientation||[1,0,0],i._stereo=e.stereo||null,i._pos=e.pos||null,i._pannerAttr={coneInnerAngle:void 0!==e.coneInnerAngle?e.coneInnerAngle:360,coneOuterAngle:void 0!==e.coneOuterAngle?e.coneOuterAngle:360,coneOuterGain:void 0!==e.coneOuterGain?e.coneOuterGain:0,distanceModel:void 0!==e.distanceModel?e.distanceModel:"inverse",maxDistance:void 0!==e.maxDistance?e.maxDistance:1e4,panningModel:void 0!==e.panningModel?e.panningModel:"HRTF",refDistance:void 0!==e.refDistance?e.refDistance:1,rolloffFactor:void 0!==e.rolloffFactor?e.rolloffFactor:1},i._onstereo=e.onstereo?[{fn:e.onstereo}]:[],i._onpos=e.onpos?[{fn:e.onpos}]:[],i._onorientation=e.onorientation?[{fn:e.onorientation}]:[],t.call(this,e)}),Howl.prototype.stereo=function(t,i){var r=this;if(!r._webAudio)return r;if("loaded"!==r._state)return r._queue.push({event:"stereo",action:function(){r.stereo(t,i)}}),r;var o=void 0===Howler.ctx.createStereoPanner?"spatial":"stereo";if(void 0===i){if("number"!=typeof t)return r._stereo;r._stereo=t,r._pos=[t,0,0]}for(var n=r._getSoundIds(i),s=0;s<n.length;s++){var a=r._soundById(n[s]);if(a){if("number"!=typeof t)return a._stereo;a._stereo=t,a._pos=[t,0,0],a._node&&(a._pannerAttr.panningModel="equalpower",a._panner&&a._panner.pan||e(a,o),"spatial"===o?void 0!==a._panner.positionX?(a._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),a._panner.positionY.setValueAtTime(0,Howler.ctx.currentTime),a._panner.positionZ.setValueAtTime(0,Howler.ctx.currentTime)):a._panner.setPosition(t,0,0):a._panner.pan.setValueAtTime(t,Howler.ctx.currentTime)),r._emit("stereo",a._id)}}return r},Howl.prototype.pos=function(t,i,r,o){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"pos",action:function(){n.pos(t,i,r,o)}}),n;if(i="number"!=typeof i?0:i,r="number"!=typeof r?-.5:r,void 0===o){if("number"!=typeof t)return n._pos;n._pos=[t,i,r]}for(var s=n._getSoundIds(o),a=0;a<s.length;a++){var h=n._soundById(s[a]);if(h){if("number"!=typeof t)return h._pos;h._pos=[t,i,r],h._node&&(h._panner&&!h._panner.pan||e(h,"spatial"),void 0!==h._panner.positionX?(h._panner.positionX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.positionY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.positionZ.setValueAtTime(r,Howler.ctx.currentTime)):h._panner.setPosition(t,i,r)),n._emit("pos",h._id)}}return n},Howl.prototype.orientation=function(t,i,r,o){var n=this;if(!n._webAudio)return n;if("loaded"!==n._state)return n._queue.push({event:"orientation",action:function(){n.orientation(t,i,r,o)}}),n;if(i="number"!=typeof i?n._orientation[1]:i,r="number"!=typeof r?n._orientation[2]:r,void 0===o){if("number"!=typeof t)return n._orientation;n._orientation=[t,i,r]}for(var s=n._getSoundIds(o),a=0;a<s.length;a++){var h=n._soundById(s[a]);if(h){if("number"!=typeof t)return h._orientation;h._orientation=[t,i,r],h._node&&(h._panner||(h._pos||(h._pos=n._pos||[0,0,-.5]),e(h,"spatial")),void 0!==h._panner.orientationX?(h._panner.orientationX.setValueAtTime(t,Howler.ctx.currentTime),h._panner.orientationY.setValueAtTime(i,Howler.ctx.currentTime),h._panner.orientationZ.setValueAtTime(r,Howler.ctx.currentTime)):h._panner.setOrientation(t,i,r)),n._emit("orientation",h._id)}}return n},Howl.prototype.pannerAttr=function(){var t,i,r,o=this,n=arguments;if(!o._webAudio)return o;if(0===n.length)return o._pannerAttr;if(1===n.length){if("object"!=typeof n[0])return(r=o._soundById(parseInt(n[0],10)))?r._pannerAttr:o._pannerAttr;t=n[0],void 0===i&&(t.pannerAttr||(t.pannerAttr={coneInnerAngle:t.coneInnerAngle,coneOuterAngle:t.coneOuterAngle,coneOuterGain:t.coneOuterGain,distanceModel:t.distanceModel,maxDistance:t.maxDistance,refDistance:t.refDistance,rolloffFactor:t.rolloffFactor,panningModel:t.panningModel}),o._pannerAttr={coneInnerAngle:void 0!==t.pannerAttr.coneInnerAngle?t.pannerAttr.coneInnerAngle:o._coneInnerAngle,coneOuterAngle:void 0!==t.pannerAttr.coneOuterAngle?t.pannerAttr.coneOuterAngle:o._coneOuterAngle,coneOuterGain:void 0!==t.pannerAttr.coneOuterGain?t.pannerAttr.coneOuterGain:o._coneOuterGain,distanceModel:void 0!==t.pannerAttr.distanceModel?t.pannerAttr.distanceModel:o._distanceModel,maxDistance:void 0!==t.pannerAttr.maxDistance?t.pannerAttr.maxDistance:o._maxDistance,refDistance:void 0!==t.pannerAttr.refDistance?t.pannerAttr.refDistance:o._refDistance,rolloffFactor:void 0!==t.pannerAttr.rolloffFactor?t.pannerAttr.rolloffFactor:o._rolloffFactor,panningModel:void 0!==t.pannerAttr.panningModel?t.pannerAttr.panningModel:o._panningModel})}else 2===n.length&&(t=n[0],i=parseInt(n[1],10));for(var s=o._getSoundIds(i),a=0;a<s.length;a++)if(r=o._soundById(s[a])){var h=r._pannerAttr;h={coneInnerAngle:void 0!==t.coneInnerAngle?t.coneInnerAngle:h.coneInnerAngle,coneOuterAngle:void 0!==t.coneOuterAngle?t.coneOuterAngle:h.coneOuterAngle,coneOuterGain:void 0!==t.coneOuterGain?t.coneOuterGain:h.coneOuterGain,distanceModel:void 0!==t.distanceModel?t.distanceModel:h.distanceModel,maxDistance:void 0!==t.maxDistance?t.maxDistance:h.maxDistance,refDistance:void 0!==t.refDistance?t.refDistance:h.refDistance,rolloffFactor:void 0!==t.rolloffFactor?t.rolloffFactor:h.rolloffFactor,panningModel:void 0!==t.panningModel?t.panningModel:h.panningModel};var l=r._panner;l?(l.coneInnerAngle=h.coneInnerAngle,l.coneOuterAngle=h.coneOuterAngle,l.coneOuterGain=h.coneOuterGain,l.distanceModel=h.distanceModel,l.maxDistance=h.maxDistance,l.refDistance=h.refDistance,l.rolloffFactor=h.rolloffFactor,l.panningModel=h.panningModel):(r._pos||(r._pos=o._pos||[0,0,-.5]),e(r,"spatial"))}return o},Sound.prototype.init=function(t){return function(){var e=this,i=e._parent;e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,t.call(this),e._stereo?i.stereo(e._stereo):e._pos&&i.pos(e._pos[0],e._pos[1],e._pos[2],e._id)}}(Sound.prototype.init),Sound.prototype.reset=function(t){return function(){var e=this,i=e._parent;return e._orientation=i._orientation,e._stereo=i._stereo,e._pos=i._pos,e._pannerAttr=i._pannerAttr,e._stereo?i.stereo(e._stereo):e._pos?i.pos(e._pos[0],e._pos[1],e._pos[2],e._id):e._panner&&(e._panner.disconnect(0),e._panner=void 0,i._refreshBuffer(e)),t.call(this)}}(Sound.prototype.reset);var e=function(t,e){"spatial"===(e=e||"spatial")?(t._panner=Howler.ctx.createPanner(),t._panner.coneInnerAngle=t._pannerAttr.coneInnerAngle,t._panner.coneOuterAngle=t._pannerAttr.coneOuterAngle,t._panner.coneOuterGain=t._pannerAttr.coneOuterGain,t._panner.distanceModel=t._pannerAttr.distanceModel,t._panner.maxDistance=t._pannerAttr.maxDistance,t._panner.refDistance=t._pannerAttr.refDistance,t._panner.rolloffFactor=t._pannerAttr.rolloffFactor,t._panner.panningModel=t._pannerAttr.panningModel,void 0!==t._panner.positionX?(t._panner.positionX.setValueAtTime(t._pos[0],Howler.ctx.currentTime),t._panner.positionY.setValueAtTime(t._pos[1],Howler.ctx.currentTime),t._panner.positionZ.setValueAtTime(t._pos[2],Howler.ctx.currentTime)):t._panner.setPosition(t._pos[0],t._pos[1],t._pos[2]),void 0!==t._panner.orientationX?(t._panner.orientationX.setValueAtTime(t._orientation[0],Howler.ctx.currentTime),t._panner.orientationY.setValueAtTime(t._orientation[1],Howler.ctx.currentTime),t._panner.orientationZ.setValueAtTime(t._orientation[2],Howler.ctx.currentTime)):t._panner.setOrientation(t._orientation[0],t._orientation[1],t._orientation[2])):(t._panner=Howler.ctx.createStereoPanner(),t._panner.pan.setValueAtTime(t._stereo,Howler.ctx.currentTime)),t._panner.connect(t._node),t._paused||t._parent.pause(t._id,!0).play(t._id,!0)}}()}(howler);var ObservableVector2d=function(t){function e(e,i,r){if(void 0===e&&(e=0),void 0===i&&(i=0),t.call(this,e,i),void 0===r)throw new Error("undefined `onUpdate` callback");this.setCallback(r.onUpdate,r.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),this.setMuted(t,e),void 0!==i&&this.setCallback(i.onUpdate,i.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._x,this._y);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._x,this._y);this._y=e&&"y"in e?e.y:t},e.prototype._set=function(t,e){var i=this.onUpdate.call(this.scope,t,e,this._x,this._y);return i&&"x"in i&&"y"in i?(this._x=i.x,this._y=i.y):(this._x=t,this._y=e),this},e.prototype.setMuted=function(t,e){return this._x=t,this._y=e,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y)},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y)},e.prototype.scale=function(t,e){return this._set(this._x*t,this._y*(void 0!==e?e:t))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y)},e.prototype.div=function(t){return this._set(this._x/t,this._y/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y)},e.prototype.clamp=function(t,i){return new e(clamp(this.x,t,i),clamp(this.y,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e))},e.prototype.minV=function(t){return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y)},e.prototype.maxV=function(t){return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y))},e.prototype.negate=function(){return new e(-this._x,-this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y)},e.prototype.copy=function(t){return this._set(t.x,t.y)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y},e.prototype.perp=function(){return this._set(this._y,-this._x)},e.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this._x-i,n=this._y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r)},e.prototype.dot=function(t){return this._x*t.x+this._y*t.y},e.prototype.cross=function(t){return this._x*t.y-this._y*t.x},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this},e.prototype.distance=function(t){return Math.sqrt((this._x-t.x)*(this._x-t.x)+(this._y-t.y)*(this._y-t.y))},e.prototype.clone=function(){return pull("ObservableVector2d",this._x,this._y,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.toVector2d=function(){return pull("Vector2d",this._x,this._y)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y},Object.defineProperties(e.prototype,i),e}(Vector2d),Vector3d=function(t,e,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.onResetEvent(t,e,i)};Vector3d.prototype.onResetEvent=function(t,e,i){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype._set=function(t,e,i){return void 0===i&&(i=0),this.x=t,this.y=e,this.z=i,this},Vector3d.prototype.set=function(t,e,i){if(t!==+t||e!==+e||void 0!==i&&i!==+i)throw new Error("invalid x, y, z parameters (not a number)");return this._set(t,e,i)},Vector3d.prototype.setZero=function(){return this.set(0,0,0)},Vector3d.prototype.setV=function(t){return this._set(t.x,t.y,t.z)},Vector3d.prototype.add=function(t){return this._set(this.x+t.x,this.y+t.y,this.z+(t.z||0))},Vector3d.prototype.sub=function(t){return this._set(this.x-t.x,this.y-t.y,this.z-(t.z||0))},Vector3d.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this.x*t,this.y*e,this.z*(i||1))},Vector3d.prototype.scaleV=function(t){return this.scale(t.x,t.y,t.z)},Vector3d.prototype.toIso=function(){return this._set(this.x-this.y,.5*(this.x+this.y),this.z)},Vector3d.prototype.to2d=function(){return this._set(this.y+this.x/2,this.y-this.x/2,this.z)},Vector3d.prototype.div=function(t){return this._set(this.x/t,this.y/t,this.z/t)},Vector3d.prototype.abs=function(){return this._set(this.x<0?-this.x:this.x,this.y<0?-this.y:this.y,this.z<0?-this.z:this.z)},Vector3d.prototype.clamp=function(t,e){return new Vector3d(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.clampSelf=function(t,e){return this._set(clamp(this.x,t,e),clamp(this.y,t,e),clamp(this.z,t,e))},Vector3d.prototype.minV=function(t){var e=t.z||0;return this._set(this.x<t.x?this.x:t.x,this.y<t.y?this.y:t.y,this.z<e?this.z:e)},Vector3d.prototype.maxV=function(t){var e=t.z||0;return this._set(this.x>t.x?this.x:t.x,this.y>t.y?this.y:t.y,this.z>e?this.z:e)},Vector3d.prototype.floor=function(){return new Vector3d(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.floorSelf=function(){return this._set(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))},Vector3d.prototype.ceil=function(){return new Vector3d(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.ceilSelf=function(){return this._set(Math.ceil(this.x),Math.ceil(this.y),Math.ceil(this.z))},Vector3d.prototype.negate=function(){return new Vector3d(-this.x,-this.y,-this.z)},Vector3d.prototype.negateSelf=function(){return this._set(-this.x,-this.y,-this.z)},Vector3d.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},Vector3d.prototype.equals=function(){var t,e,i;return arguments.length>=2?(t=arguments[0],e=arguments[1],i=arguments[2]):(t=arguments[0].x,e=arguments[0].y,i=arguments[0].z),void 0===i&&(i=this.z),this.x===t&&this.y===e&&this.z===i},Vector3d.prototype.normalize=function(){return this.div(this.length()||1)},Vector3d.prototype.perp=function(){return this._set(this.y,-this.x,this.z)},Vector3d.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this.x-i,n=this.y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r,this.z)},Vector3d.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*(void 0!==t.z?t.z:this.z)},Vector3d.prototype.cross=function(t){var e=this.x,i=this.y,r=this.z,o=t.x,n=t.y,s=t.z;return this.x=i*s-r*n,this.y=r*o-e*s,this.z=e*n-i*o,this},Vector3d.prototype.length2=function(){return this.dot(this)},Vector3d.prototype.length=function(){return Math.sqrt(this.length2())},Vector3d.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},Vector3d.prototype.distance=function(t){var e=this.x-t.x,i=this.y-t.y,r=this.z-(t.z||0);return Math.sqrt(e*e+i*i+r*r)},Vector3d.prototype.angle=function(t){return Math.acos(clamp(this.dot(t)/(this.length()*t.length()),-1,1))},Vector3d.prototype.project=function(t){var e=this.dot(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.projectN=function(t){var e=this.dot(t)/t.length2();return this.scale(e,e,e)},Vector3d.prototype.clone=function(){return pull("Vector3d",this.x,this.y,this.z)},Vector3d.prototype.toString=function(){return"x:"+this.x+",y:"+this.y+",z:"+this.z};var ObservableVector3d=function(t){function e(e,i,r,o){if(void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=0),t.call(this,e,i,r),void 0===o)throw new Error("undefined `onUpdate` callback");this.setCallback(o.onUpdate,o.scope)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={x:{configurable:!0},y:{configurable:!0},z:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,r){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.setMuted(t,e,i),void 0!==r&&this.setCallback(r.onUpdate,r.scope),this},i.x.get=function(){return this._x},i.x.set=function(t){var e=this.onUpdate.call(this.scope,t,this._y,this._z,this._x,this._y,this._z);this._x=e&&"x"in e?e.x:t},i.y.get=function(){return this._y},i.y.set=function(t){var e=this.onUpdate.call(this.scope,this._x,t,this._z,this._x,this._y,this._z);this._y=e&&"y"in e?e.y:t},i.z.get=function(){return this._z},i.z.set=function(t){var e=this.onUpdate.call(this.scope,this._x,this._y,t,this._x,this._y,this._z);this._z=e&&"z"in e?e.z:t},e.prototype._set=function(t,e,i){var r=this.onUpdate.call(this.scope,t,e,i,this._x,this._y,this._z);return r&&"x"in r&&"y"in r&&"z"in r?(this._x=r.x,this._y=r.y,this._z=r.z):(this._x=t,this._y=e,this._z=i||0),this},e.prototype.setMuted=function(t,e,i){return this._x=t,this._y=e,this._z=i||0,this},e.prototype.setCallback=function(t,e){if(void 0===e&&(e=null),"function"!=typeof t)throw new Error("invalid `onUpdate` callback");return this.onUpdate=t,this.scope=e,this},e.prototype.add=function(t){return this._set(this._x+t.x,this._y+t.y,this._z+(t.z||0))},e.prototype.sub=function(t){return this._set(this._x-t.x,this._y-t.y,this._z-(t.z||0))},e.prototype.scale=function(t,e,i){return e=void 0!==e?e:t,this._set(this._x*t,this._y*e,this._z*(i||1))},e.prototype.scaleV=function(t){return this._set(this._x*t.x,this._y*t.y,this._z*(t.z||1))},e.prototype.div=function(t){return this._set(this._x/t,this._y/t,this._z/t)},e.prototype.abs=function(){return this._set(this._x<0?-this._x:this._x,this._y<0?-this._y:this._y,this._Z<0?-this._z:this._z)},e.prototype.clamp=function(t,i){return new e(clamp(this._x,t,i),clamp(this._y,t,i),clamp(this._z,t,i),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.clampSelf=function(t,e){return this._set(clamp(this._x,t,e),clamp(this._y,t,e),clamp(this._z,t,e))},e.prototype.minV=function(t){var e=t.z||0;return this._set(this._x<t.x?this._x:t.x,this._y<t.y?this._y:t.y,this._z<e?this._z:e)},e.prototype.maxV=function(t){var e=t.z||0;return this._set(this._x>t.x?this._x:t.x,this._y>t.y?this._y:t.y,this._z>e?this._z:e)},e.prototype.floor=function(){return new e(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.floorSelf=function(){return this._set(Math.floor(this._x),Math.floor(this._y),Math.floor(this._z))},e.prototype.ceil=function(){return new e(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z),{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.ceilSelf=function(){return this._set(Math.ceil(this._x),Math.ceil(this._y),Math.ceil(this._z))},e.prototype.negate=function(){return new e(-this._x,-this._y,-this._z,{onUpdate:this.onUpdate,scope:this.scope})},e.prototype.negateSelf=function(){return this._set(-this._x,-this._y,-this._z)},e.prototype.copy=function(t){return this._set(t.x,t.y,t.z||0)},e.prototype.equals=function(t){return this._x===t.x&&this._y===t.y&&this._z===(t.z||this._z)},e.prototype.perp=function(){return this._set(this._y,-this._x,this._z)},e.prototype.rotate=function(t,e){var i=0,r=0;"object"==typeof e&&(i=e.x,r=e.y);var o=this.x-i,n=this.y-r,s=Math.cos(t),a=Math.sin(t);return this._set(o*s-n*a+i,o*a+n*s+r,this.z)},e.prototype.dot=function(t){return this._x*t.x+this._y*t.y+this._z*(t.z||1)},e.prototype.cross=function(t){var e=this._x,i=this._y,r=this._z,o=t.x,n=t.y,s=t.z;return this._set(i*s-r*n,r*o-e*s,e*n-i*o)},e.prototype.lerp=function(t,e){return this._x+=(t.x-this._x)*e,this._y+=(t.y-this._y)*e,this._z+=(t.z-this._z)*e,this},e.prototype.distance=function(t){var e=this._x-t.x,i=this._y-t.y,r=this._z-(t.z||0);return Math.sqrt(e*e+i*i+r*r)},e.prototype.clone=function(){return pull("ObservableVector3d",this._x,this._y,this._z,{onUpdate:this.onUpdate})},e.prototype.toVector3d=function(){return pull("Vector3d",this._x,this._y,this._z)},e.prototype.toString=function(){return"x:"+this._x+",y:"+this._y+",z:"+this._z},Object.defineProperties(e.prototype,i),e}(Vector3d),earcut$1={exports:{}};function earcut(t,e,i){i=i||2;var r,o,n,s,a,h,l,c=e&&e.length,u=c?e[0]*i:t.length,d=linkedList(t,0,u,i,!0),p=[];if(!d||d.next===d.prev)return p;if(c&&(d=eliminateHoles(t,e,d,i)),t.length>80*i){r=n=t[0],o=s=t[1];for(var f=i;f<u;f+=i)(a=t[f])<r&&(r=a),(h=t[f+1])<o&&(o=h),a>n&&(n=a),h>s&&(s=h);l=0!==(l=Math.max(n-r,s-o))?1/l:0}return earcutLinked(d,p,i,r,o,l),p}function linkedList(t,e,i,r,o){var n,s;if(o===signedArea(t,e,i,r)>0)for(n=e;n<i;n+=r)s=insertNode(n,t[n],t[n+1],s);else for(n=i-r;n>=e;n-=r)s=insertNode(n,t[n],t[n+1],s);return s&&equals(s,s.next)&&(removeNode(s),s=s.next),s}function filterPoints(t,e){if(!t)return t;e||(e=t);var i,r=t;do{if(i=!1,r.steiner||!equals(r,r.next)&&0!==area(r.prev,r,r.next))r=r.next;else{if(removeNode(r),(r=e=r.prev)===r.next)break;i=!0}}while(i||r!==e);return e}function earcutLinked(t,e,i,r,o,n,s){if(t){!s&&n&&indexCurve(t,r,o,n);for(var a,h,l=t;t.prev!==t.next;)if(a=t.prev,h=t.next,n?isEarHashed(t,r,o,n):isEar(t))e.push(a.i/i),e.push(t.i/i),e.push(h.i/i),removeNode(t),t=h.next,l=h.next;else if((t=h)===l){s?1===s?earcutLinked(t=cureLocalIntersections(filterPoints(t),e,i),e,i,r,o,n,2):2===s&&splitEarcut(t,e,i,r,o,n):earcutLinked(filterPoints(t),e,i,r,o,n,1);break}}}function isEar(t){var e=t.prev,i=t,r=t.next;if(area(e,i,r)>=0)return!1;for(var o=t.next.next;o!==t.prev;){if(pointInTriangle(e.x,e.y,i.x,i.y,r.x,r.y,o.x,o.y)&&area(o.prev,o,o.next)>=0)return!1;o=o.next}return!0}function isEarHashed(t,e,i,r){var o=t.prev,n=t,s=t.next;if(area(o,n,s)>=0)return!1;for(var a=o.x<n.x?o.x<s.x?o.x:s.x:n.x<s.x?n.x:s.x,h=o.y<n.y?o.y<s.y?o.y:s.y:n.y<s.y?n.y:s.y,l=o.x>n.x?o.x>s.x?o.x:s.x:n.x>s.x?n.x:s.x,c=o.y>n.y?o.y>s.y?o.y:s.y:n.y>s.y?n.y:s.y,u=zOrder(a,h,e,i,r),d=zOrder(l,c,e,i,r),p=t.prevZ,f=t.nextZ;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&pointInTriangle(o.x,o.y,n.x,n.y,s.x,s.y,f.x,f.y)&&area(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function cureLocalIntersections(t,e,i){var r=t;do{var o=r.prev,n=r.next.next;!equals(o,n)&&intersects(o,r,r.next,n)&&locallyInside(o,n)&&locallyInside(n,o)&&(e.push(o.i/i),e.push(r.i/i),e.push(n.i/i),removeNode(r),removeNode(r.next),r=t=n),r=r.next}while(r!==t);return filterPoints(r)}function splitEarcut(t,e,i,r,o,n){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&isValidDiagonal(s,a)){var h=splitPolygon(s,a);return s=filterPoints(s,s.next),h=filterPoints(h,h.next),earcutLinked(s,e,i,r,o,n),void earcutLinked(h,e,i,r,o,n)}a=a.next}s=s.next}while(s!==t)}function eliminateHoles(t,e,i,r){var o,n,s,a=[];for(o=0,n=e.length;o<n;o++)(s=linkedList(t,e[o]*r,o<n-1?e[o+1]*r:t.length,r,!1))===s.next&&(s.steiner=!0),a.push(getLeftmost(s));for(a.sort(compareX),o=0;o<a.length;o++)i=filterPoints(i=eliminateHole(a[o],i),i.next);return i}function compareX(t,e){return t.x-e.x}function eliminateHole(t,e){var i=findHoleBridge(t,e);if(!i)return e;var r=splitPolygon(i,t),o=filterPoints(i,i.next);return filterPoints(r,r.next),e===i?o:e}function findHoleBridge(t,e){var i,r=e,o=t.x,n=t.y,s=-1/0;do{if(n<=r.y&&n>=r.next.y&&r.next.y!==r.y){var a=r.x+(n-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=o&&a>s){if(s=a,a===o){if(n===r.y)return r;if(n===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==e);if(!i)return null;if(o===s)return i;var h,l=i,c=i.x,u=i.y,d=1/0;r=i;do{o>=r.x&&r.x>=c&&o!==r.x&&pointInTriangle(n<u?o:s,n,c,u,n<u?s:o,n,r.x,r.y)&&(h=Math.abs(n-r.y)/(o-r.x),locallyInside(r,t)&&(h<d||h===d&&(r.x>i.x||r.x===i.x&&sectorContainsSector(i,r)))&&(i=r,d=h)),r=r.next}while(r!==l);return i}function sectorContainsSector(t,e){return area(t.prev,t,e.prev)<0&&area(e.next,t,t.next)<0}function indexCurve(t,e,i,r){var o=t;do{null===o.z&&(o.z=zOrder(o.x,o.y,e,i,r)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,sortLinked(o)}function sortLinked(t){var e,i,r,o,n,s,a,h,l=1;do{for(i=t,t=null,n=null,s=0;i;){for(s++,r=i,a=0,e=0;e<l&&(a++,r=r.nextZ);e++);for(h=l;a>0||h>0&&r;)0!==a&&(0===h||!r||i.z<=r.z)?(o=i,i=i.nextZ,a--):(o=r,r=r.nextZ,h--),n?n.nextZ=o:t=o,o.prevZ=n,n=o;i=r}n.nextZ=null,l*=2}while(s>1);return t}function zOrder(t,e,i,r,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*o)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-r)*o)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function getLeftmost(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function pointInTriangle(t,e,i,r,o,n,s,a){return(o-s)*(e-a)-(t-s)*(n-a)>=0&&(t-s)*(r-a)-(i-s)*(e-a)>=0&&(i-s)*(n-a)-(o-s)*(r-a)>=0}function isValidDiagonal(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!intersectsPolygon(t,e)&&(locallyInside(t,e)&&locallyInside(e,t)&&middleInside(t,e)&&(area(t.prev,t,e.prev)||area(t,e.prev,e))||equals(t,e)&&area(t.prev,t,t.next)>0&&area(e.prev,e,e.next)>0)}function area(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function equals(t,e){return t.x===e.x&&t.y===e.y}function intersects(t,e,i,r){var o=sign(area(t,e,i)),n=sign(area(t,e,r)),s=sign(area(i,r,t)),a=sign(area(i,r,e));return o!==n&&s!==a||(!(0!==o||!onSegment(t,i,e))||(!(0!==n||!onSegment(t,r,e))||(!(0!==s||!onSegment(i,t,r))||!(0!==a||!onSegment(i,e,r)))))}function onSegment(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function sign(t){return t>0?1:t<0?-1:0}function intersectsPolygon(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&intersects(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}function locallyInside(t,e){return area(t.prev,t,t.next)<0?area(t,e,t.next)>=0&&area(t,t.prev,e)>=0:area(t,e,t.prev)<0||area(t,t.next,e)<0}function middleInside(t,e){var i=t,r=!1,o=(t.x+e.x)/2,n=(t.y+e.y)/2;do{i.y>n!=i.next.y>n&&i.next.y!==i.y&&o<(i.next.x-i.x)*(n-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==t);return r}function splitPolygon(t,e){var i=new Node$1(t.i,t.x,t.y),r=new Node$1(e.i,e.x,e.y),o=t.next,n=e.prev;return t.next=e,e.prev=t,i.next=o,o.prev=i,r.next=i,i.prev=r,n.next=r,r.prev=n,r}function insertNode(t,e,i,r){var o=new Node$1(t,e,i);return r?(o.next=r.next,o.prev=r,r.next.prev=o,r.next=o):(o.prev=o,o.next=o),o}function removeNode(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Node$1(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function signedArea(t,e,i,r){for(var o=0,n=e,s=i-r;n<i;n+=r)o+=(t[s]-t[n])*(t[n+1]+t[s+1]),s=n;return o}earcut$1.exports=earcut,earcut$1.exports.default=earcut,earcut.deviation=function(t,e,i,r){var o=e&&e.length,n=o?e[0]*i:t.length,s=Math.abs(signedArea(t,0,n,i));if(o)for(var a=0,h=e.length;a<h;a++){var l=e[a]*i,c=a<h-1?e[a+1]*i:t.length;s-=Math.abs(signedArea(t,l,c,i))}var u=0;for(a=0;a<r.length;a+=3){var d=r[a]*i,p=r[a+1]*i,f=r[a+2]*i;u+=Math.abs((t[d]-t[f])*(t[p+1]-t[d+1])-(t[d]-t[p])*(t[f+1]-t[d+1]))}return 0===s&&0===u?0:Math.abs((u-s)/s)},earcut.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},r=0,o=0;o<t.length;o++){for(var n=0;n<t[o].length;n++)for(var s=0;s<e;s++)i.vertices.push(t[o][n][s]);o>0&&(r+=t[o-1].length,i.holes.push(r))}return i};var Polygon=function(t,e,i){this.pos=new Vector2d,this._bounds,this.points=[],this.edges=[],this.indices=[],this.normals=[],this.shapeType="Polygon",this.setShape(t,e,i)};Polygon.prototype.onResetEvent=function(t,e,i){this.setShape(t,e,i)},Polygon.prototype.setShape=function(t,e,i){return this.pos.set(t,e),this.setVertices(i),this},Polygon.prototype.setVertices=function(t){var e=this;if(!Array.isArray(t))return this;if(t[0]instanceof Vector2d)this.points=t;else if(this.points.length=0,"object"==typeof t[0])t.forEach((function(t){e.points.push(new Vector2d(t.x,t.y))}));else for(var i=0;i<t.length;i+=2)this.points.push(new Vector2d(t[i],t[i+1]));return this.recalc(),this.updateBounds(),this},Polygon.prototype.transform=function(t){for(var e=this.points,i=e.length,r=0;r<i;r++)t.apply(e[r]);return this.recalc(),this.updateBounds(),this},Polygon.prototype.toIso=function(){return this.rotate(Math.PI/4).scale(Math.SQRT2,Math.SQRT1_2)},Polygon.prototype.to2d=function(){return this.scale(Math.SQRT1_2,Math.SQRT2).rotate(-Math.PI/4)},Polygon.prototype.rotate=function(t,e){if(0!==t){for(var i=this.points,r=i.length,o=0;o<r;o++)i[o].rotate(t,e);this.recalc(),this.updateBounds()}return this},Polygon.prototype.scale=function(t,e){e=void 0!==e?e:t;for(var i=this.points,r=i.length,o=0;o<r;o++)i[o].scale(t,e);return this.recalc(),this.updateBounds(),this},Polygon.prototype.scaleV=function(t){return this.scale(t.x,t.y)},Polygon.prototype.recalc=function(){var t,e=this.edges,i=this.normals,r=this.indices,o=this.points,n=o.length;if(n<3)throw new Error("Requires at least 3 points");for(t=0;t<n;t++)void 0===e[t]&&(e[t]=new Vector2d),e[t].copy(o[(t+1)%n]).sub(o[t]),void 0===i[t]&&(i[t]=new Vector2d),i[t].copy(e[t]).perp().normalize();return e.length=n,i.length=n,r.length=0,this},Polygon.prototype.getIndices=function(){return 0===this.indices.length&&(this.indices=earcut$1.exports(this.points.flatMap((function(t){return[t.x,t.y]})))),this.indices},Polygon.prototype.isConvex=function(){var t,e,i,r,o=0,n=this.points,s=n.length;if(s<3)return null;for(t=0;t<s;t++)if(i=(t+2)%s,r=(n[e=(t+1)%s].x-n[t].x)*(n[i].y-n[e].y),(r-=(n[e].y-n[t].y)*(n[i].x-n[e].x))<0?o|=1:r>0&&(o|=2),3===o)return!1;return 0!==o||null},Polygon.prototype.translate=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},Polygon.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x=t,this.pos.y=e,this.updateBounds()},Polygon.prototype.contains=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);for(var i=!1,r=this.pos.x,o=this.pos.y,n=this.points,s=n.length,a=0,h=s-1;a<s;h=a++){var l=n[a].y+o,c=n[a].x+r,u=n[h].y+o,d=n[h].x+r;l>e!=u>e&&t<(d-c)*(e-l)/(u-l)+c&&(i=!i)}return i},Polygon.prototype.getBounds=function(){return void 0===this._bounds&&(this._bounds=pull("Bounds")),this._bounds},Polygon.prototype.updateBounds=function(){var t=this.getBounds();return t.update(this.points),t.translate(this.pos),t},Polygon.prototype.clone=function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new Polygon(this.pos.x,this.pos.y,t)};var Rect=function(t){function e(e,i,r,o){t.call(this,e,i,[new Vector2d(0,0),new Vector2d(r,0),new Vector2d(r,o),new Vector2d(0,o)]),this.shapeType="Rectangle"}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},width:{configurable:!0},height:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0}};return e.prototype.onResetEvent=function(t,e,i,r){this.setShape(t,e,i,r)},e.prototype.setShape=function(t,e,i,r){var o=i;return this.pos.set(t,e),4===arguments.length&&((o=this.points)[0].set(0,0),o[1].set(i,0),o[2].set(i,r),o[3].set(0,r)),this.setVertices(o),this},i.left.get=function(){return this.pos.x},i.right.get=function(){var t=this.width;return this.pos.x+t||t},i.top.get=function(){return this.pos.y},i.bottom.get=function(){var t=this.height;return this.pos.y+t||t},i.width.get=function(){return this.points[2].x},i.width.set=function(t){this.points[1].x=this.points[2].x=t,this.recalc(),this.updateBounds()},i.height.get=function(){return this.points[2].y},i.height.set=function(t){this.points[2].y=this.points[3].y=t,this.recalc(),this.updateBounds()},i.centerX.get=function(){return isFinite(this.width)?this.pos.x+this.width/2:this.width},i.centerX.set=function(t){this.pos.x=t-this.width/2},i.centerY.get=function(){return isFinite(this.height)?this.pos.y+this.height/2:this.height},i.centerY.set=function(t){this.pos.y=t-this.height/2},e.prototype.centerOn=function(t,e){return this.centerX=t,this.centerY=e,this},e.prototype.resize=function(t,e){return this.width=t,this.height=e,this},e.prototype.scale=function(t,e){return void 0===e&&(e=t),this.width*=t,this.height*=e,this},e.prototype.clone=function(){return new e(this.pos.x,this.pos.y,this.width,this.height)},e.prototype.copy=function(t){return this.setShape(t.pos.x,t.pos.y,t.width,t.height)},e.prototype.union=function(t){var e=Math.min(this.left,t.left),i=Math.min(this.top,t.top);return this.resize(Math.max(this.right,t.right)-e,Math.max(this.bottom,t.bottom)-i),this.pos.set(e,i),this},e.prototype.overlaps=function(t){return this.left<t.right&&t.left<this.right&&this.top<t.bottom&&t.top<this.bottom},e.prototype.contains=function(){var t,i,r,o,n=arguments[0];return 2===arguments.length?(t=i=n,r=o=arguments[1]):n instanceof e?(t=n.left,i=n.right,r=n.top,o=n.bottom):(t=i=n.x,r=o=n.y),t>=this.left&&i<=this.right&&r>=this.top&&o<=this.bottom},e.prototype.equals=function(t){return t.left===this.left&&t.right===this.right&&t.top===this.top&&t.bottom===this.bottom},e.prototype.isFinite=function(){return isFinite(this.pos.x)&&isFinite(this.pos.y)&&isFinite(this.width)&&isFinite(this.height)},e.prototype.toPolygon=function(){return new t(this.pos.x,this.pos.y,this.points)},Object.defineProperties(e.prototype,i),e}(Polygon),_keyStatus={},_keyLock={},_keyLocked={},_keyRefs={},_preventDefaultForKeys={},_keyBindings={},keyDownEvent=function(t,e,i){e=e||t.keyCode||t.button;var r=_keyBindings[e];if(emit(KEYDOWN,r,e,!r||!_keyLocked[r]),r){if(!_keyLocked[r]){var o=void 0!==i?i:e;_keyRefs[r][o]||(_keyStatus[r]++,_keyRefs[r][o]=!0)}return!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyUpEvent=function(t,e,i){e=e||t.keyCode||t.button;var r=_keyBindings[e];if(emit(KEYUP,r,e),r){var o=void 0!==i?i:e;return _keyRefs[r][o]=void 0,_keyStatus[r]>0&&_keyStatus[r]--,_keyLocked[r]=!1,!_preventDefaultForKeys[e]||"function"!=typeof t.preventDefault||t.preventDefault()}return!0},keyBoardEventTarget=null,KEY={BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PRINT_SCREEN:42,INSERT:45,DELETE:46,NUM0:48,NUM1:49,NUM2:50,NUM3:51,NUM4:52,NUM5:53,NUM6:54,NUM7:55,NUM8:56,NUM9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,WINDOW_KEY:91,NUMPAD0:96,NUMPAD1:97,NUMPAD2:98,NUMPAD3:99,NUMPAD4:100,NUMPAD5:101,NUMPAD6:102,NUMPAD7:103,NUMPAD8:104,NUMPAD9:105,MULTIPLY:106,ADD:107,SUBSTRACT:109,DECIMAL:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,TILDE:126,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,PLUS:187,COMMA:188,MINUS:189,PERIOD:190,FORWAND_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222};function initKeyboardEvent(){null===keyBoardEventTarget&&!1===device$1.isMobile&&"function"==typeof(keyBoardEventTarget=globalThis).addEventListener&&(keyBoardEventTarget.addEventListener("keydown",keyDownEvent,!1),keyBoardEventTarget.addEventListener("keyup",keyUpEvent,!1))}function isKeyPressed(t){return!(!_keyStatus[t]||_keyLocked[t])&&(_keyLock[t]&&(_keyLocked[t]=!0),!0)}function keyStatus(t){return _keyStatus[t]>0}function triggerKeyEvent(t,e,i){!0===e?keyDownEvent({},t,i):keyUpEvent({},t,i)}function bindKey(t,e,i,r){void 0===r&&(r=preventDefault),_keyBindings[t]=e,_preventDefaultForKeys[t]=r,_keyStatus[e]=0,_keyLock[e]=i||!1,_keyLocked[e]=!1,_keyRefs[e]={}}function getBindingKey(t){return _keyBindings[t]}function unlockKey(t){_keyLocked[t]=!1}function unbindKey(t){var e=_keyBindings[t];_keyStatus[e]=0,_keyLock[e]=!1,_keyRefs[e]={},_keyBindings[t]=null,_preventDefaultForKeys[t]=null}var Bounds$1=function(t){this.onResetEvent(t)},prototypeAccessors$1={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds$1.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds$1.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds$1.prototype.setMinMax=function(t,e,i,r){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=r},prototypeAccessors$1.x.get=function(){return this.min.x},prototypeAccessors$1.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors$1.y.get=function(){return this.min.y},prototypeAccessors$1.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors$1.width.get=function(){return this.max.x-this.min.x},prototypeAccessors$1.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors$1.height.get=function(){return this.max.y-this.min.y},prototypeAccessors$1.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors$1.left.get=function(){return this.min.x},prototypeAccessors$1.right.get=function(){return this.max.x},prototypeAccessors$1.top.get=function(){return this.min.y},prototypeAccessors$1.bottom.get=function(){return this.max.y},prototypeAccessors$1.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors$1.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors$1.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds$1.prototype.update=function(t){this.add(t,!0)},Bounds$1.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var r=t[i];r.x>this.max.x&&(this.max.x=r.x),r.x<this.min.x&&(this.min.x=r.x),r.y>this.max.y&&(this.max.y=r.y),r.y<this.min.y&&(this.min.y=r.y)}},Bounds$1.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds$1.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds$1.prototype.addFrame=function(t,e,i,r,o){var n=me.pool.pull("Vector2d");this.addPoint(n.set(t,e),o),this.addPoint(n.set(i,e),o),this.addPoint(n.set(t,r),o),this.addPoint(n.set(i,r),o),me.pool.push(n)},Bounds$1.prototype.contains=function(){var t,e,i,r,o=arguments[0];return 2===arguments.length?(t=e=o,i=r=arguments[1]):o instanceof Bounds$1?(t=o.min.x,e=o.max.x,i=o.min.y,r=o.max.y):(t=e=o.x,i=r=o.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&r<=this.max.y},Bounds$1.prototype.overlaps=function(t){return!(this.right<t.left||this.left>t.right||this.bottom<t.top||this.top>t.bottom)},Bounds$1.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds$1.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds$1.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,r=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+r},Bounds$1.prototype.clone=function(){var t=new Bounds$1;return t.addBounds(this),t},Bounds$1.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds$1.prototype,prototypeAccessors$1);var tmpVec=new Vector2d,Pointer=function(t){function e(e,i,r,o){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===o&&(o=1),t.call(this),this.setMinMax(e,i,e+r,i+o),this.LEFT=0,this.MIDDLE=1,this.RIGHT=2,this.event=void 0,this.type=void 0,this.button=0,this.isPrimary=!1,this.pageX=0,this.pageY=0,this.clientX=0,this.clientY=0,this.movementX=0,this.movementY=0,this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0,this.gameX=0,this.gameY=0,this.gameScreenX=0,this.gameScreenY=0,this.gameWorldX=0,this.gameWorldY=0,this.gameLocalX=0,this.gameLocalY=0,this.pointerId=void 0,this.isNormalized=!1,this.locked=!1,this.bind=[0,0,0]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setEvent=function(t,e,i,r,o,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=0),void 0===o&&(o=0),void 0===n&&(n=1),this.event=t,this.pageX=e,this.pageY=i,this.clientX=r,this.clientY=o,globalToLocal(this.pageX,this.pageY,tmpVec),this.gameScreenX=this.x=tmpVec.x,this.gameScreenY=this.y=tmpVec.y,this.isNormalized=!device$1.PointerEvent||device$1.PointerEvent&&!(t instanceof globalThis.PointerEvent),this.locked=locked,this.movementX=t.movementX||0,this.movementY=t.movementY||0,"wheel"===t.type?(this.deltaMode=t.deltaMode||0,this.deltaX=t.deltaX||0,this.deltaY=t.deltaY||0,this.deltaZ=t.deltaZ||0):(this.deltaMode=0,this.deltaX=0,this.deltaY=0,this.deltaZ=0),this.pointerId=n,this.isPrimary=void 0===t.isPrimary||t.isPrimary,this.button=t.button||0,this.type=t.type,void 0!==viewport&&viewport.localToWorld(this.gameScreenX,this.gameScreenY,tmpVec),this.gameWorldX=tmpVec.x,this.gameWorldY=tmpVec.y,!1===this.isNormalized?(this.width=t.width||1,this.height=t.height||1):"number"==typeof t.radiusX?(this.width=2*t.radiusX||1,this.height=2*t.radiusY||1):this.width=this.height=1},e}(Bounds$1),T_POINTERS=[],eventHandlers=new Map,currentPointer,pointerInitialized=!1,lastTimeStamp=0,activeEventList=[],WHEEL=["wheel"],POINTER_MOVE=["pointermove","mousemove","touchmove"],POINTER_DOWN=["pointerdown","mousedown","touchstart"],POINTER_UP=["pointerup","mouseup","touchend"],POINTER_CANCEL=["pointercancel","mousecancel","touchcancel"],POINTER_ENTER=["pointerenter","mouseenter","touchenter"],POINTER_OVER=["pointerover","mouseover","touchover"],POINTER_LEAVE=["pointerleave","mouseleave","touchleave"],pointerEventList=[WHEEL[0],POINTER_MOVE[0],POINTER_DOWN[0],POINTER_UP[0],POINTER_CANCEL[0],POINTER_ENTER[0],POINTER_OVER[0],POINTER_LEAVE[0]],mouseEventList=[WHEEL[0],POINTER_MOVE[1],POINTER_DOWN[1],POINTER_UP[1],POINTER_CANCEL[1],POINTER_ENTER[1],POINTER_OVER[1],POINTER_LEAVE[1]],touchEventList=[POINTER_MOVE[2],POINTER_DOWN[2],POINTER_UP[2],POINTER_CANCEL[2],POINTER_ENTER[2],POINTER_OVER[2],POINTER_LEAVE[2]],pointerEventMap={wheel:WHEEL,pointermove:POINTER_MOVE,pointerdown:POINTER_DOWN,pointerup:POINTER_UP,pointercancel:POINTER_CANCEL,pointerenter:POINTER_ENTER,pointerover:POINTER_OVER,pointerleave:POINTER_LEAVE},normalizedEvents=[];function registerEventListener(t,e){for(var i=0;i<t.length;i++)-1===POINTER_MOVE.indexOf(t[i])&&pointerEventTarget.addEventListener(t[i],e,{passive:!1===preventDefault})}function enablePointerEvent(){if(!pointerInitialized){currentPointer=new Rect(0,0,1,1);for(var t=0;t<device$1.maxTouchPoints;t++)T_POINTERS.push(new Pointer);var e;null===pointerEventTarget&&(pointerEventTarget=renderer.getScreenCanvas()),activeEventList=device$1.PointerEvent?pointerEventList:mouseEventList,device$1.touch&&!device$1.PointerEvent&&(activeEventList=activeEventList.concat(touchEventList)),registerEventListener(activeEventList,onPointerEvent),void 0===throttlingInterval&&(throttlingInterval=~~(1e3/timer$1.maxfps)),!0===device$1.autoFocus&&(device$1.focus(),pointerEventTarget.addEventListener(activeEventList[2],(function(){device$1.focus()}),{passive:!1===preventDefault}));var i=findAllActiveEvents(activeEventList,POINTER_MOVE);if(throttlingInterval<17)for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],onMoveEvent,{passive:!0});else for(e=0;e<i.length;e++)-1!==activeEventList.indexOf(i[e])&&pointerEventTarget.addEventListener(i[e],throttle(onMoveEvent,throttlingInterval,!1),{passive:!0});setTouchAction(pointerEventTarget),device$1.hasPointerLockSupport&&document.addEventListener("pointerlockchange",(function(){locked=document.pointerLockElement===getParent(),emit(POINTERLOCKCHANGE,locked)}),!0),pointerInitialized=!0}}function findActiveEvent(t,e){for(var i=0;i<e.length;i++){if(-1!==t.indexOf(e[i]))return e[i]}}function findAllActiveEvents(t,e){for(var i=[],r=0;r<e.length;r++){-1!==t.indexOf(e[r])&&i.push(e[r])}return i}function triggerEvent(t,e,i,r){var o;if(t.callbacks[e]){t.pointerId=r;for(var n=t.callbacks[e].length-1;n>=0&&(o=t.callbacks[e][n]);n--)if(!1===o(i))return!0}return!1}function dispatchEvent(t){for(var e=!1;t.length>0;){var i=t.pop();if(T_POINTERS.push(i),void 0!==i.event.timeStamp){if(i.event.timeStamp<lastTimeStamp)continue;lastTimeStamp=i.event.timeStamp}currentPointer.setShape(i.gameWorldX,i.gameWorldY,i.width,i.height),POINTER_MOVE.includes(i.type)&&(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY,emit(POINTERMOVE,i));for(var r,o=world.broadphase.retrieve(currentPointer,Container.prototype._sortReverseZ),n=(o=o.concat([viewport])).length;r=o[--n];){if(eventHandlers.has(r)&&!0!==r.isKinematic){var s,a=eventHandlers.get(r),h=a.region,l=h.ancestor,c=h.getBounds();if(!0===h.isFloating?(i.gameX=i.gameLocalX=i.gameScreenX,i.gameY=i.gameLocalY=i.gameScreenY):(i.gameX=i.gameLocalX=i.gameWorldX,i.gameY=i.gameLocalY=i.gameWorldY),void 0!==l){var u=l.getBounds();i.gameLocalX=i.gameX-u.x,i.gameLocalY=i.gameY-u.y}var d=i.gameX,p=i.gameY;if(void 0!==h.currentTransform&&!h.currentTransform.isIdentity()){var f=h.currentTransform.applyInverse(pull("Vector2d",d,p));d=f.x,p=f.y,push(f)}switch(s=c.contains(d,p),i.type){case POINTER_MOVE[0]:case POINTER_MOVE[1]:case POINTER_MOVE[2]:case POINTER_MOVE[3]:if(a.pointerId!==i.pointerId||s){if(null===a.pointerId&&s&&triggerEvent(a,findActiveEvent(activeEventList,POINTER_ENTER),i,i.pointerId)){e=!0;break}}else if(triggerEvent(a,findActiveEvent(activeEventList,POINTER_LEAVE),i,null)){e=!0;break}if(s&&triggerEvent(a,i.type,i,i.pointerId)){e=!0;break}break;case POINTER_UP[0]:case POINTER_UP[1]:case POINTER_UP[2]:case POINTER_UP[3]:if(a.pointerId===i.pointerId&&s&&triggerEvent(a,i.type,i,null)){e=!0;break}break;case POINTER_CANCEL[0]:case POINTER_CANCEL[1]:case POINTER_CANCEL[2]:case POINTER_CANCEL[3]:if(a.pointerId===i.pointerId&&triggerEvent(a,i.type,i,null)){e=!0;break}break;default:if(s&&triggerEvent(a,i.type,i,i.pointerId)){e=!0;break}}}if(!0===e)break}}return e}function normalizeEvent(t){var e;if(device$1.TouchEvent&&t.changedTouches)for(var i=0,r=t.changedTouches.length;i<r;i++){var o=t.changedTouches[i];(e=T_POINTERS.pop()).setEvent(t,o.pageX,o.pageY,o.clientX,o.clientY,o.identifier),normalizedEvents.push(e)}else(e=T_POINTERS.pop()).setEvent(t,t.pageX,t.pageY,t.clientX,t.clientY,t.pointerId),normalizedEvents.push(e);return!1===t.isPrimary||(normalizedEvents[0].isPrimary=!0,Object.assign(pointer,normalizedEvents[0])),normalizedEvents}function onMoveEvent(t){dispatchEvent(normalizeEvent(t))}function onPointerEvent(t){normalizeEvent(t);var e=normalizedEvents[0].button;(dispatchEvent(normalizedEvents)||"wheel"===t.type)&&t.preventDefault();var i=pointer.bind[e];i&&triggerKeyEvent(i,POINTER_DOWN.includes(t.type),e+1)}var pointerEventTarget=null,pointer=new Pointer(0,0,1,1),locked=!1,throttlingInterval;function globalToLocal(t,e,i){i=i||pull("Vector2d");var r=device$1.getElementBounds(renderer.getScreenCanvas()),o=device$1.devicePixelRatio;t-=r.left+(globalThis.pageXOffset||0),e-=r.top+(globalThis.pageYOffset||0);var n=scaleRatio;return 1===n.x&&1===n.y||(t/=n.x,e/=n.y),i.set(t*o,e*o)}function setTouchAction(t,e){t.style["touch-action"]=e||"none"}function bindPointer(){var t=arguments.length<2?pointer.LEFT:arguments[0],e=arguments.length<2?arguments[0]:arguments[1];if(enablePointerEvent(),!getBindingKey(e))throw new Error("no action defined for keycode "+e);pointer.bind[t]=e}function unbindPointer(t){pointer.bind[void 0===t?pointer.LEFT:t]=null}function registerPointerEvent(t,e,i){if(enablePointerEvent(),-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);if(void 0===e)throw new Error("registerPointerEvent: region for "+toString(e)+" event is undefined ");var r=findAllActiveEvents(activeEventList,pointerEventMap[t]);eventHandlers.has(e)||eventHandlers.set(e,{region:e,callbacks:{},pointerId:null});for(var o=eventHandlers.get(e),n=0;n<r.length;n++)t=r[n],o.callbacks[t]?o.callbacks[t].push(i):o.callbacks[t]=[i]}function releasePointerEvent(t,e,i){if(-1===pointerEventList.indexOf(t))throw new Error("invalid event type : "+t);var r=findAllActiveEvents(activeEventList,pointerEventMap[t]),o=eventHandlers.get(e);if(void 0!==o){for(var n=0;n<r.length;n++)if(t=r[n],o.callbacks[t]){if(void 0!==i)remove(o.callbacks[t],i);else for(;o.callbacks[t].length>0;)o.callbacks[t].pop();0===o.callbacks[t].length&&delete o.callbacks[t]}0===Object.keys(o.callbacks).length&&eventHandlers.delete(e)}}function releaseAllPointerEvents(t){if(eventHandlers.has(t))for(var e=0;e<pointerEventList.length;e++)releasePointerEvent(pointerEventList[e],t)}function requestPointerLock(){return!!device$1.hasPointerLockSupport&&(getParent().requestPointerLock(),!0)}function exitPointerLock(){return!!device$1.hasPointerLockSupport&&(document.exitPointerLock(),!0)}var deadzone=.1;function wiredXbox360NormalizeFn(t,e,i){return i===this.GAMEPAD.BUTTONS.L2||i===this.GAMEPAD.BUTTONS.R2?(t+1)/2:t}function ouyaNormalizeFn(t,e,i){return t=t>0?i===this.GAMEPAD.BUTTONS.L2?Math.max(0,t-2e4)/111070:(t-1)/131070:(65536+t)/131070+.5}var vendorProductRE=/^([0-9a-f]{1,4})-([0-9a-f]{1,4})-/i,leadingZeroRE=/^0+/;function addMapping(t,e){var i=t.replace(vendorProductRE,(function(t,e,i){return"000".substr(e.length-1)+e+"-"+"000".substr(i.length-1)+i+"-"})),r=t.replace(vendorProductRE,(function(t,e,i){return e.replace(leadingZeroRE,"")+"-"+i.replace(leadingZeroRE,"")+"-"}));e.analog=e.analog||e.buttons.map((function(){return-1})),e.normalize_fn=e.normalize_fn||function(t){return t},remap.set(i,e),remap.set(r,e)}var bindings={},remap=new Map,updateEventHandler;[["45e-28e-Xbox 360 Wired Controller",{axes:[0,1,3,4],buttons:[11,12,13,14,8,9,-1,-1,5,4,6,7,0,1,2,3,10],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:wiredXbox360NormalizeFn}],["54c-268-PLAYSTATION(R)3 Controller",{axes:[0,1,2,3],buttons:[14,13,15,12,10,11,8,9,0,3,1,2,4,6,7,5,16]}],["54c-5c4-Wireless Controller",{axes:[0,1,2,3],buttons:[1,0,2,3,4,5,6,7,8,9,10,11,14,15,16,17,12,13]}],["2836-1-OUYA Game Controller",{axes:[0,3,7,9],buttons:[3,6,4,5,7,8,15,16,-1,-1,9,10,11,12,13,14,-1],analog:[-1,-1,-1,-1,-1,-1,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}],["OUYA Game Controller (Vendor: 2836 Product: 0001)",{axes:[0,1,3,4],buttons:[0,3,1,2,4,5,12,13,-1,-1,6,7,8,9,10,11,-1],analog:[-1,-1,-1,-1,-1,-1,2,5,-1,-1,-1,-1,-1,-1,-1,-1,-1],normalize_fn:ouyaNormalizeFn}]].forEach((function(t){addMapping(t[0],t[1])}));var updateGamepads=function(){var t=navigator.getGamepads();Object.keys(bindings).forEach((function(e){var i=t[e];if(i){var r=null;"standard"!==i.mapping&&(r=remap.get(i.id));var o=bindings[e];Object.keys(o.buttons).forEach((function(t){var n=o.buttons[t],s=t,a=-1;if(!(r&&(s=r.buttons[t],a=r.analog[t],s<0&&a<0))){var h=i.buttons[s]||{};if(r&&a>=0){var l=r.normalize_fn(i.axes[a],-1,+t);h={value:l,pressed:h.pressed||Math.abs(l)>=deadzone}}emit(GAMEPAD_UPDATE,e,"buttons",+t,h),!n.pressed&&h.pressed?triggerKeyEvent(n.keyCode,!0,s+256):n.pressed&&!h.pressed&&triggerKeyEvent(n.keyCode,!1,s+256),n.value=h.value,n.pressed=h.pressed}})),Object.keys(o.axes).forEach((function(t){var n=o.axes[t],s=t;if(!(r&&(s=r.axes[t])<0)){var a=i.axes[s];if(void 0!==a){r&&(a=r.normalize_fn(a,+t,-1));var h=Math.sign(a)||1;if(0!==n[h].keyCode){var l=Math.abs(a)>=deadzone+Math.abs(n[h].threshold);emit(GAMEPAD_UPDATE,e,"axes",+t,a),!n[h].pressed&&l?(n[-h].pressed&&(triggerKeyEvent(n[-h].keyCode,!1,s+256),n[-h].value=0,n[-h].pressed=!1),triggerKeyEvent(n[h].keyCode,!0,s+256)):!n[h].pressed&&!n[-h].pressed||l||triggerKeyEvent(n[h=n[h].pressed?h:-h].keyCode,!1,s+256),n[h].value=a,n[h].pressed=l}}}}))}}))};globalThis.navigator&&"function"==typeof globalThis.navigator.getGamepads&&(globalThis.addEventListener("gamepadconnected",(function(t){emit(GAMEPAD_CONNECTED,t.gamepad)}),!1),globalThis.addEventListener("gamepaddisconnected",(function(t){emit(GAMEPAD_DISCONNECTED,t.gamepad)}),!1));var GAMEPAD={AXES:{LX:0,LY:1,RX:2,RY:3,EXTRA_1:4,EXTRA_2:5,EXTRA_3:6,EXTRA_4:7},BUTTONS:{FACE_1:0,FACE_2:1,FACE_3:2,FACE_4:3,L1:4,R1:5,L2:6,R2:7,SELECT:8,BACK:8,START:9,FORWARD:9,L3:10,R3:11,UP:12,DOWN:13,LEFT:14,RIGHT:15,HOME:16,EXTRA_1:17,EXTRA_2:18,EXTRA_3:19,EXTRA_4:20}};function bindGamepad(t,e,i){if(!getBindingKey(i))throw new Error("no action defined for keycode "+i);void 0===updateEventHandler&&"function"==typeof navigator.getGamepads&&(updateEventHandler=on(GAME_BEFORE_UPDATE,updateGamepads)),bindings[t]||(bindings[t]={axes:{},buttons:{}});var r={keyCode:i,value:0,pressed:!1,threshold:e.threshold},o=bindings[t][e.type];if("buttons"===e.type)o[e.code]=r;else if("axes"===e.type){var n=Math.sign(e.threshold)||1;o[e.code]||(o[e.code]={});var s=o[e.code];s[n]=r,s[-n]||(s[-n]={keyCode:0,value:0,pressed:!1,threshold:-n})}}function unbindGamepad(t,e){if(!bindings[t])throw new Error("no bindings for gamepad "+t);bindings[t].buttons[e]={}}function setGamepadDeadzone(t){deadzone=t}var setGamepadMapping=addMapping,preventDefault=!0,input=Object.freeze({__proto__:null,preventDefault:preventDefault,get pointerEventTarget(){return pointerEventTarget},pointer:pointer,get locked(){return locked},get throttlingInterval(){return throttlingInterval},globalToLocal:globalToLocal,setTouchAction:setTouchAction,bindPointer:bindPointer,unbindPointer:unbindPointer,registerPointerEvent:registerPointerEvent,releasePointerEvent:releasePointerEvent,releaseAllPointerEvents:releaseAllPointerEvents,requestPointerLock:requestPointerLock,exitPointerLock:exitPointerLock,get keyBoardEventTarget(){return keyBoardEventTarget},KEY:KEY,initKeyboardEvent:initKeyboardEvent,isKeyPressed:isKeyPressed,keyStatus:keyStatus,triggerKeyEvent:triggerKeyEvent,bindKey:bindKey,getBindingKey:getBindingKey,unlockKey:unlockKey,unbindKey:unbindKey,GAMEPAD:GAMEPAD,bindGamepad:bindGamepad,unbindGamepad:unbindGamepad,setGamepadDeadzone:setGamepadDeadzone,setGamepadMapping:setGamepadMapping}),Renderable=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isRenderable=!0,this.isKinematic=!0,this.body=void 0,void 0===this.currentTransform&&(this.currentTransform=pull("Matrix2d")),this.currentTransform.identity(),this.GUID=void 0,this.onVisibilityChange=void 0,this.alwaysUpdate=!1,this.updateWhenPaused=!1,this.isPersistent=!1,this.floating=!1,this.anchorPoint instanceof ObservableVector2d?this.anchorPoint.setMuted(.5,.5).setCallback(this.onAnchorUpdate,this):this.anchorPoint=pull("ObservableVector2d",.5,.5,{onUpdate:this.onAnchorUpdate,scope:this}),this.autoTransform=!0,this.alpha=1,this.ancestor=void 0,this.mask=void 0,this.tint=pull("Color",255,255,255,1),this.blendMode="normal",this.name="",this.pos instanceof ObservableVector3d?this.pos.setMuted(e,i,0).setCallback(this.updateBoundsPos,this):this.pos=pull("ObservableVector3d",e,i,0,{onUpdate:this.updateBoundsPos,scope:this}),this.isDirty=!1,this._flip={x:!1,y:!1},this._inViewport=!1,this.setOpacity(1)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={isFloating:{configurable:!0},inViewport:{configurable:!0},isFlippedX:{configurable:!0},isFlippedY:{configurable:!0}};return i.isFloating.get=function(){return!0===this.floating||void 0!==this.ancestor&&!0===this.ancestor.floating},i.inViewport.get=function(){return this._inViewport},i.inViewport.set=function(t){this._inViewport!==t&&(this._inViewport=t,"function"==typeof this.onVisibilityChange&&this.onVisibilityChange.call(this,t))},i.isFlippedX.get=function(){return!0===this._flip.x},i.isFlippedY.get=function(){return!0===this._flip.y},e.prototype.getBounds=function(){return void 0===this._bounds&&(t.prototype.getBounds.call(this),this.isFinite()?this._bounds.setMinMax(this.pos.x,this.pos.y,this.pos.x+this.width,this.pos.y+this.height):this._bounds.setMinMax(this.pos.x,this.pos.y,this.width,this.height)),this._bounds},e.prototype.getOpacity=function(){return this.alpha},e.prototype.setOpacity=function(t){"number"==typeof t&&(this.alpha=clamp(t,0,1),isNaN(this.alpha)&&(this.alpha=1),this.isDirty=!0)},e.prototype.flipX=function(t){return void 0===t&&(t=!0),this._flip.x=!!t,this.isDirty=!0,this},e.prototype.flipY=function(t){return void 0===t&&(t=!0),this._flip.y=!!t,this.isDirty=!0,this},e.prototype.transform=function(t){return this.currentTransform.multiply(t),this.updateBoundsPos(this.pos.x,this.pos.y),this.isDirty=!0,this},e.prototype.angleTo=function(t){var i,r,o=this.getBounds();if(t instanceof e){var n=t.getBounds();i=n.centerX-o.centerX,r=n.centerY-o.centerY}else i=t.x-o.centerX,r=t.y-o.centerY;return Math.atan2(r,i)},e.prototype.distanceTo=function(t){var i,r,o=this.getBounds();if(t instanceof e){var n=t.getBounds();i=o.centerX-n.centerX,r=o.centerY-n.centerY}else i=o.centerX-t.x,r=o.centerY-t.y;return Math.sqrt(i*i+r*r)},e.prototype.lookAt=function(t){var i;i=t instanceof e?t.pos:t;var r=this.angleTo(i);return this.rotate(r),this},e.prototype.rotate=function(t,e){return isNaN(t)||(this.currentTransform.rotate(t,e),this.isDirty=!0),this},e.prototype.scale=function(e,i){return this.currentTransform.scale(e,i),t.prototype.scale.call(this,e,i),this.isDirty=!0,this},e.prototype.scaleV=function(t){return this.scale(t.x,t.y),this},e.prototype.update=function(t){return this.isDirty},e.prototype.updateBounds=function(){return t.prototype.updateBounds.call(this),this.updateBoundsPos(this.pos.x,this.pos.y),this.getBounds()},e.prototype.updateBoundsPos=function(t,e){var i=this.getBounds();i.shift(t,e),void 0!==this.anchorPoint&&i.isFinite()&&i.translate(-this.anchorPoint.x*i.width,-this.anchorPoint.y*i.height),this.ancestor instanceof Container&&!0!==this.floating&&i.translate(this.ancestor.getAbsolutePosition())},e.prototype.getAbsolutePosition=function(){return void 0===this._absPos&&(this._absPos=pull("Vector2d")),this._absPos.set(this.pos.x,this.pos.y),this.ancestor instanceof Container&&!0!==this.floating&&this._absPos.add(this.ancestor.getAbsolutePosition()),this._absPos},e.prototype.onAnchorUpdate=function(t,e){this.anchorPoint.setMuted(t,e),this.updateBoundsPos(this.pos.x,this.pos.y)},e.prototype.preDraw=function(t){var e=this.getBounds(),i=e.width*this.anchorPoint.x,r=e.height*this.anchorPoint.y;if(t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),this._flip.x||this._flip.y){var o=this._flip.x?this.centerX-i:0,n=this._flip.y?this.centerY-r:0;t.translate(o,n),t.scale(this._flip.x?-1:1,this._flip.y?-1:1),t.translate(-o,-n)}void 0!==this.mask&&(t.translate(this.pos.x,this.pos.y),t.setMask(this.mask),t.translate(-this.pos.x,-this.pos.y)),!0!==this.autoTransform||this.currentTransform.isIdentity()||(t.translate(this.pos.x,this.pos.y),t.transform(this.currentTransform),t.translate(-this.pos.x,-this.pos.y)),t.translate(-i,-r),t.setTint(this.tint,this.getOpacity()),this.blendMode!==t.getBlendMode()&&t.setBlendMode(this.blendMode)},e.prototype.draw=function(t){},e.prototype.postDraw=function(t){t.clearTint(),void 0!==this.mask&&t.clearMask(),t.restore(),this.isDirty=!1},e.prototype.onCollision=function(){return!1},e.prototype.destroy=function(){push(this.currentTransform),this.currentTransform=void 0,push(this.anchorPoint),this.anchorPoint=void 0,push(this.pos),this.pos=void 0,void 0!==this._absPos&&(push(this._absPos),this._absPos=void 0),push(this._bounds),this._bounds=void 0,this.onVisibilityChange=void 0,void 0!==this.mask&&(push(this.mask),this.mask=void 0),void 0!==this.tint&&(push(this.tint),this.tint=void 0),this.ancestor=void 0,void 0!==this.body&&(this.body.destroy.apply(this.body,arguments),this.body=void 0),releaseAllPointerEvents(this),this.onDestroyEvent.apply(this,arguments)},e.prototype.onDestroyEvent=function(){},Object.defineProperties(e.prototype,i),e}(Rect),Ellipse=function(t,e,i,r){this.pos=new Vector2d,this._bounds=void 0,this.radius=NaN,this.radiusV=new Vector2d,this.radiusSq=new Vector2d,this.ratio=new Vector2d,this.shapeType="Ellipse",this.setShape(t,e,i,r)};Ellipse.prototype.onResetEvent=function(t,e,i,r){this.setShape(t,e,i,r)},Ellipse.prototype.setShape=function(t,e,i,r){var o=i/2,n=r/2;this.pos.set(t,e),this.radius=Math.max(o,n),this.ratio.set(o/this.radius,n/this.radius),this.radiusV.set(this.radius,this.radius).scaleV(this.ratio);var s=this.radius*this.radius;return this.radiusSq.set(s,s).scaleV(this.ratio),this.getBounds().setMinMax(t,e,t+i,t+r),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},Ellipse.prototype.rotate=function(t,e){return this.pos.rotate(t,e),this.getBounds().shift(this.pos),this.getBounds().translate(-this.radiusV.x,-this.radiusV.y),this},Ellipse.prototype.scale=function(t,e){return e=void 0!==e?e:t,this.setShape(this.pos.x,this.pos.y,2*this.radiusV.x*t,2*this.radiusV.y*e)},Ellipse.prototype.scaleV=function(t){return this.scale(t.x,t.y)},Ellipse.prototype.transform=function(){return this},Ellipse.prototype.translate=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.pos.x+=t,this.pos.y+=e,this.getBounds().translate(t,e),this},Ellipse.prototype.contains=function(){var t,e;return 2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y,t*t/this.radiusSq.x+e*e/this.radiusSq.y<=1},Ellipse.prototype.getBounds=function(){return void 0===this._bounds&&(this._bounds=pull("Bounds")),this._bounds},Ellipse.prototype.clone=function(){return new Ellipse(this.pos.x,this.pos.y,2*this.radiusV.x,2*this.radiusV.y)};for(var LEFT_VORNOI_REGION=-1,MIDDLE_VORNOI_REGION=0,RIGHT_VORNOI_REGION=1,T_VECTORS=[],v=0;v<10;v++)T_VECTORS.push(new Vector2d);for(var T_ARRAYS=[],a=0;a<5;a++)T_ARRAYS.push([]);function flattenPointsOn(t,e,i){for(var r=Number.MAX_VALUE,o=-Number.MAX_VALUE,n=t.length,s=0;s<n;s++){var a=t[s].dot(e);a<r&&(r=a),a>o&&(o=a)}i[0]=r,i[1]=o}function isSeparatingAxis(t,e,i,r,o,n){var s=T_ARRAYS.pop(),a=T_ARRAYS.pop(),h=T_VECTORS.pop().copy(e).sub(t),l=h.dot(o);if(flattenPointsOn(i,o,s),flattenPointsOn(r,o,a),a[0]+=l,a[1]+=l,s[0]>a[1]||a[0]>s[1])return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!0;if(n){var c=0;if(s[0]<a[0])if(n.aInB=!1,s[1]<a[1])c=s[1]-a[0],n.bInA=!1;else{var u=s[1]-a[0],d=a[1]-s[0];c=u<d?u:-d}else if(n.bInA=!1,s[1]>a[1])c=s[0]-a[1],n.aInB=!1;else{var p=s[1]-a[0],f=a[1]-s[0];c=p<f?p:-f}var y=Math.abs(c);y<n.overlap&&(n.overlap=y,n.overlapN.copy(o),c<0&&n.overlapN.negateSelf())}return T_VECTORS.push(h),T_ARRAYS.push(s),T_ARRAYS.push(a),!1}function vornoiRegion(t,e){var i=t.length2(),r=e.dot(t);return r<0?LEFT_VORNOI_REGION:r>i?RIGHT_VORNOI_REGION:MIDDLE_VORNOI_REGION}function testPolygonPolygon(t,e,i,r,o){var n,s=e.points,a=e.normals,h=a.length,l=r.points,c=r.normals,u=c.length,d=T_VECTORS.pop().copy(t.pos).add(t.ancestor.getAbsolutePosition()).add(e.pos),p=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos);for(n=0;n<h;n++)if(isSeparatingAxis(d,p,s,l,a[n],o))return T_VECTORS.push(d),T_VECTORS.push(p),!1;for(n=0;n<u;n++)if(isSeparatingAxis(d,p,s,l,c[n],o))return T_VECTORS.push(d),T_VECTORS.push(p),!1;return o&&(o.a=t,o.b=i,o.overlapV.copy(o.overlapN).scale(o.overlap)),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipseEllipse(t,e,i,r,o){var n=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=e.radius,a=r.radius,h=s+a,l=h*h,c=n.length2();if(c>l)return T_VECTORS.push(n),!1;if(o){var u=Math.sqrt(c);o.a=t,o.b=i,o.overlap=h-u,o.overlapN.copy(n.normalize()),o.overlapV.copy(n).scale(o.overlap),o.aInB=s<=a&&u<=a-s,o.bInA=a<=s&&u<=s-a}return T_VECTORS.push(n),!0}function testPolygonEllipse(t,e,i,r,o){for(var n=T_VECTORS.pop().copy(i.pos).add(i.ancestor.getAbsolutePosition()).add(r.pos).sub(t.pos).add(t.ancestor.getAbsolutePosition()).sub(e.pos),s=r.radius,a=s*s,h=e.points,l=e.edges,c=l.length,u=T_VECTORS.pop(),d=T_VECTORS.pop(),p=T_VECTORS.pop(),f=0,y=0;y<c;y++){var g=y===c-1?0:y+1,v=0===y?c-1:y-1,m=0,_=null;u.copy(l[y]),p.copy(n).sub(h[y]),o&&p.length2()>a&&(o.aInB=!1);var x=vornoiRegion(u,p),b=!0;if(x===LEFT_VORNOI_REGION){var T=null;if(c>1&&(u.copy(l[v]),(x=vornoiRegion(u,T=T_VECTORS.pop().copy(n).sub(h[v])))!==RIGHT_VORNOI_REGION&&(b=!1)),b){if((f=p.length())>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),T&&T_VECTORS.push(T),!1;o&&(o.bInA=!1,_=p.normalize(),m=s-f)}T&&T_VECTORS.push(T)}else if(x===RIGHT_VORNOI_REGION){if(c>1&&(u.copy(l[g]),p.copy(n).sub(h[g]),(x=vornoiRegion(u,p))!==LEFT_VORNOI_REGION&&(b=!1)),b){if((f=p.length())>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!1;o&&(o.bInA=!1,_=p.normalize(),m=s-f)}}else{d.copy(e.normals[y]),f=p.dot(d);var w=Math.abs(f);if((1===c||f>0)&&w>s)return T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!1;o&&(_=d,m=s-f,(f>=0||m<2*s)&&(o.bInA=!1))}_&&o&&Math.abs(m)<Math.abs(o.overlap)&&(o.overlap=m,o.overlapN.copy(_))}return o&&(o.a=t,o.b=i,o.overlapV.copy(o.overlapN).scale(o.overlap)),T_VECTORS.push(n),T_VECTORS.push(u),T_VECTORS.push(d),T_VECTORS.push(p),!0}function testEllipsePolygon(t,e,i,r,o){var n=this.testPolygonEllipse(i,r,t,e,o);if(n&&o){var s=o.a,a=o.aInB;o.overlapN.negateSelf(),o.overlapV.negateSelf(),o.a=o.b,o.b=s,o.aInB=o.bInA,o.bInA=a}return n}var SAT=Object.freeze({__proto__:null,testPolygonPolygon:testPolygonPolygon,testEllipseEllipse:testEllipseEllipse,testPolygonEllipse:testPolygonEllipse,testEllipsePolygon:testEllipsePolygon}),dummyObj={pos:new Vector2d(0,0),ancestor:{_absPos:new Vector2d(0,0),getAbsolutePosition:function(){return this._absPos}}};function shouldCollide(t,e){return!0!==t.isKinematic&&!0!==e.isKinematic&&"object"==typeof t.body&&"object"==typeof e.body&&!(!0===t.body.isStatic&&!0===e.body.isStatic)&&0!=(t.body.collisionMask&e.body.collisionType)&&0!=(t.body.collisionType&e.body.collisionMask)}var ResponseObject=function(){this.a=null,this.b=null,this.overlapN=new Vector2d,this.overlapV=new Vector2d,this.aInB=!0,this.bInA=!0,this.indexShapeA=-1,this.indexShapeB=-1,this.overlap=Number.MAX_VALUE};ResponseObject.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this.indexShapeA=-1,this.indexShapeB=-1,this};var globalResponse=new ResponseObject;function collisionCheck(t,e){void 0===e&&(e=globalResponse);for(var i,r=0,o=world.broadphase.retrieve(t),n=o.length;i=o[--n];)if(i!==t&&shouldCollide(t,i)&&t.body.getBounds().overlaps(i.body.getBounds())){var s=t.body.shapes.length,a=i.body.shapes.length;if(0===s||0===a)continue;var h=0;do{var l=t.body.getShape(h),c=0;do{var u=i.body.getShape(c);!0===SAT["test"+l.shapeType+u.shapeType].call(this,t,l,i,u,e.clear())&&(r++,e.indexShapeA=h,e.indexShapeB=c,t.onCollision&&!1!==t.onCollision(e,i)&&!1===t.body.isStatic&&t.body.respondToCollision.call(t.body,e),i.onCollision&&!1!==i.onCollision(e,t)&&!1===i.body.isStatic&&i.body.respondToCollision.call(i.body,e)),c++}while(c<a);h++}while(h<s)}return r>0}function rayCast(t,e){void 0===e&&(e=[]);for(var i,r=0,o=world.broadphase.retrieve(t),n=o.length;i=o[--n];)if(i.body&&t.getBounds().overlaps(i.getBounds())){var s=i.body.shapes.length;if(0===i.body.shapes.length)continue;var a=t,h=0;do{var l=i.body.getShape(h);SAT["test"+a.shapeType+l.shapeType].call(this,dummyObj,a,i,l)&&(e[r]=i,r++),h++}while(h<s)}return e.length=r,e}var collision={maxChildren:8,maxDepth:4,types:{NO_OBJECT:0,PLAYER_OBJECT:1,NPC_OBJECT:2,ENEMY_OBJECT:4,COLLECTABLE_OBJECT:8,ACTION_OBJECT:16,PROJECTILE_OBJECT:32,WORLD_SHAPE:64,USER:128,ALL_OBJECT:4294967295},response:globalResponse,rayCast:function(t,e){return rayCast(t,e)}},Body=function(t,e,i){if(this.ancestor=t,void 0===this.bounds&&(this.bounds=new Bounds$1),void 0===this.shapes&&(this.shapes=[]),this.collisionMask=collision.types.ALL_OBJECT,this.collisionType=collision.types.ENEMY_OBJECT,void 0===this.vel&&(this.vel=new Vector2d),this.vel.set(0,0),void 0===this.force&&(this.force=new Vector2d),this.force.set(0,0),void 0===this.friction&&(this.friction=new Vector2d),this.friction.set(0,0),this.bounce=0,this.mass=1,void 0===this.maxVel&&(this.maxVel=new Vector2d),this.maxVel.set(490,490),this.isStatic=!1,this.gravityScale=1,this.ignoreGravity=!1,this.falling=!1,this.jumping=!1,"function"==typeof i&&(this.onBodyUpdate=i),this.bounds.clear(),void 0!==e)if(Array.isArray(e))for(var r=0;r<e.length;r++)this.addShape(e[r]);else this.addShape(e);this.ancestor.isKinematic=!1};Body.prototype.setStatic=function(t){void 0===t&&(t=!0),this.isStatic=!0===t},Body.prototype.addShape=function(t){if(t instanceof Rect||t instanceof Bounds$1){var e=t.toPolygon();this.shapes.push(e),this.bounds.add(e.points),this.bounds.translate(e.pos)}else t instanceof Ellipse?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.addBounds(t.getBounds()),this.bounds.translate(t.getBounds().x,t.getBounds().y)):t instanceof Polygon?(this.shapes.includes(t)||this.shapes.push(t),this.bounds.add(t.points),this.bounds.translate(t.pos)):this.fromJSON(t);return"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this),this.shapes.length},Body.prototype.setVertices=function(t,e,i){void 0===e&&(e=0),void 0===i&&(i=!0);var r=this.getShape(e);r instanceof Polygon?r.setShape(0,0,t):this.shapes[e]=new Polygon(0,0,t),this.bounds.add(this.shapes[e].points,i),"function"==typeof this.onBodyUpdate&&this.onBodyUpdate(this)},Body.prototype.addVertices=function(t,e){void 0===e&&(e=0),this.setVertices(t,e,!1)},Body.prototype.fromJSON=function(t,e){var i=t;if(void 0!==e&&(i=t[e]),void 0===i)throw new Error("Identifier ("+e+") undefined for the given JSON object)");if(i.length){for(var r=0;r<i.length;r++)this.addVertices(i[r].shape,r);this.mass=i[0].density||0,this.friction.set(i[0].friction||0,i[0].friction||0),this.bounce=i[0].bounce||0}return i.length},Body.prototype.getShape=function(t){return this.shapes[t||0]},Body.prototype.getBounds=function(){return this.bounds},Body.prototype.removeShape=function(t){this.bounds.clear(),remove(this.shapes,t);for(var e=0;e<this.shapes.length;e++)this.addShape(this.shapes[e]);return this.shapes.length},Body.prototype.removeShapeAt=function(t){return this.removeShape(this.getShape(t))},Body.prototype.setCollisionMask=function(t){void 0===t&&(t=collision.types.ALL_OBJECT),this.collisionMask=t},Body.prototype.setCollisionType=function(t){if(void 0!==t){if(void 0===collision.types[t])throw new Error("Invalid value for the collisionType property");this.collisionType=collision.types[t]}},Body.prototype.respondToCollision=function(t){var e=t.overlapV;if(this.ancestor.pos.sub(e),0!==e.x&&(this.vel.x=~~(.5+this.vel.x-e.x)||0,this.bounce>0&&(this.vel.x*=-this.bounce)),0!==e.y){this.vel.y=~~(.5+this.vel.y-e.y)||0,this.bounce>0&&(this.vel.y*=-this.bounce);var i=Math.sign(world.gravity.y*this.gravityScale)||1;this.falling=e.y>=i,this.jumping=e.y<=-i}},Body.prototype.forEach=function(t,e){var i=this,r=0,o=this.shapes,n=o.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);r<n;)t.call(i,o[r],r,o),r++},Body.prototype.contains=function(){var t,e;if(2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.getBounds().contains(t,e))for(var i,r=this.shapes.length;r--,i=this.shapes[r];)if(i.contains(t,e))return!0;return!1},Body.prototype.rotate=function(t,e){var i=this;return void 0===e&&(e=this.getBounds().center),this.bounds.clear(),this.forEach((function(r){r.rotate(t,e),i.bounds.addBounds(r.getBounds()),r instanceof Ellipse?i.bounds.translate(r.getBounds().x,r.getBounds().y):i.bounds.translate(r.pos)})),this},Body.prototype.setMaxVelocity=function(t,e){this.maxVel.x=t,this.maxVel.y=e},Body.prototype.setFriction=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.friction.x=t,this.friction.y=e},Body.prototype.computeVelocity=function(){var t=timer$1.tick;if(!this.ignoreGravity){var e=world.gravity;this.vel.x+=e.x*this.gravityScale*t,this.vel.y+=e.y*this.gravityScale*t,this.falling=this.vel.y*Math.sign(e.y*this.gravityScale)>0,this.jumping=!this.falling&&this.jumping}if(0!==this.force.x&&(this.vel.x+=this.force.x*t),0!==this.force.y&&(this.vel.y+=this.force.y*t),this.friction.x>0){var i=this.friction.x*t,r=this.vel.x+i,o=this.vel.x-i;this.vel.x=r<0?r:o>0?o:0}if(this.friction.y>0){var n=this.friction.y*t,s=this.vel.y+n,a=this.vel.y-n;this.vel.y=s<0?s:a>0?a:0}0!==this.vel.y&&(this.vel.y=clamp(this.vel.y,-this.maxVel.y,this.maxVel.y)),0!==this.vel.x&&(this.vel.x=clamp(this.vel.x,-this.maxVel.x,this.maxVel.x))},Body.prototype.update=function(t){return this.computeVelocity(t),this.ancestor.pos.add(this.vel),0!==this.vel.x||0!==this.vel.y},Body.prototype.destroy=function(){this.onBodyUpdate=void 0,this.ancestor=void 0,this.bounds=void 0,this.setStatic(!1),this.shapes.length=0};var deferredRemove=function(t,e){this.removeChildNow(t,e)},globalFloatingCounter=0,Container=function(t){function e(e,i,r,o,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=viewport.width),void 0===o&&(o=viewport.height),void 0===n&&(n=!1),t.call(this,e,i,r,o),this.pendingSort=null,this.root=n,this.children=void 0,this.sortOn=sortOn,this.autoSort=!0,this.autoDepth=!0,this.clipping=!1,this.onChildChange=function(){},this.enableChildBoundsUpdate=!1,this.backgroundColor=pull("Color",0,0,0,0),this.drawCount=0,this.autoTransform=!0,this.isKinematic=!1,this.anchorPoint.set(0,0),!0===this.root&&on(CANVAS_ONRESIZE,this.updateBounds.bind(this,!0))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){this.pendingSort&&(clearTimeout(this.pendingSort),this.pendingSort=null);for(var t,e=this.getChildren(),i=e.length;i>=0;t=e[--i])t&&!0!==t.isPersistent&&this.removeChildNow(t);void 0!==this.currentTransform&&this.currentTransform.identity(),this.backgroundColor.setColor(0,0,0,0)},e.prototype.addChild=function(t,i){return t.ancestor instanceof e?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils.createGUID(t.id)),t.ancestor=this,this.getChildren().push(t),void 0!==t.pos&&("number"==typeof i?t.pos.z=i:!0===this.autoDepth&&(t.pos.z=this.getChildren().length)),!0===this.autoSort&&this.sort(),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),t.body instanceof Body&&world.addBody(t.body),this.onChildChange.call(this,this.getChildren().length-1),t},e.prototype.addChildAt=function(t,i){if(i>=0&&i<this.getChildren().length)return t.ancestor instanceof e?t.ancestor.removeChildNow(t):t.isRenderable&&(t.GUID=utils.createGUID()),t.ancestor=this,this.getChildren().splice(i,0,t),"function"==typeof t.onActivateEvent&&this.isAttachedToRoot()&&t.onActivateEvent(),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),t.body instanceof Body&&world.addBody(t.body),this.onChildChange.call(this,i),t;throw new Error("Index ("+i+") Out Of Bounds for addChildAt()")},e.prototype.forEach=function(t,e){var i=this,r=0,o=this.getChildren(),n=o.length;if("function"!=typeof t)throw new Error(t+" is not a function");for(arguments.length>1&&(i=e);r<n;)t.call(i,o[r],r,o),r++},e.prototype.swapChildren=function(t,e){var i=this.getChildIndex(t),r=this.getChildIndex(e);if(-1===i||-1===r)throw new Error(t+" Both the supplied childs must be a child of the caller "+this);var o=t.pos.z;t.pos.z=e.pos.z,e.pos.z=o,this.getChildren()[i]=e,this.getChildren()[r]=t,this.isDirty=!0},e.prototype.getChildAt=function(t){if(t>=0&&t<this.getChildren().length)return this.getChildren()[t];throw new Error("Index ("+t+") Out Of Bounds for getChildAt()")},e.prototype.getChildIndex=function(t){return this.getChildren().indexOf(t)},e.prototype.getNextChild=function(t){var e=this.getChildren().indexOf(t)-1;if(e>=0&&e<this.getChildren().length)return this.getChildAt(e)},e.prototype.hasChild=function(t){return this===t.ancestor},e.prototype.getChildByProp=function(t,i){var r=[];return this.forEach((function(o){!function(t,e){var o=t[e];i instanceof RegExp&&"string"==typeof o?i.test(o)&&r.push(t):o===i&&r.push(t)}(o,t),o instanceof e&&(r=r.concat(o.getChildByProp(t,i)))})),r},e.prototype.getChildByType=function(t){var i=[];return this.forEach((function(r){r instanceof t&&i.push(r),r instanceof e&&(i=i.concat(r.getChildByType(t)))})),i},e.prototype.getChildByName=function(t){return this.getChildByProp("name",t)},e.prototype.getChildByGUID=function(t){var e=this.getChildByProp("GUID",t);return e.length>0?e[0]:null},e.prototype.getChildren=function(){return void 0===this.children&&(this.children=[]),this.children},e.prototype.updateBounds=function(e){void 0===e&&(e=!1),t.prototype.updateBounds.call(this);var i=this.getBounds();return!0!==e&&!0!==this.enableChildBoundsUpdate||this.forEach((function(t){t.isRenderable&&(t.getBounds().isFinite()&&i.addBounds(t.getBounds()))})),i},e.prototype.isAttachedToRoot=function(){if(!0===this.root)return!0;for(var t=this.ancestor;t;){if(!0===t.root)return!0;t=t.ancestor}return!1},e.prototype.updateBoundsPos=function(e,i){var r=this;return t.prototype.updateBoundsPos.call(this,e,i),this.forEach((function(t){t.isRenderable&&t.updateBoundsPos(t.pos.x+e-r.pos.x,t.pos.y+i-r.pos.y)})),this.getBounds()},e.prototype.onActivateEvent=function(){this.forEach((function(t){"function"==typeof t.onActivateEvent&&t.onActivateEvent()}))},e.prototype.removeChild=function(t,e){if(!this.hasChild(t))throw new Error("Child is not mine.");utils.function.defer(deferredRemove,this,t,e)},e.prototype.removeChildNow=function(t,e){if(this.hasChild(t)&&this.getChildIndex(t)>=0){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent(),t.body instanceof Body&&world.removeBody(t.body),e||!1===push(t,!1)&&"function"==typeof t.destroy&&t.destroy();var i=this.getChildIndex(t);i>=0&&(this.getChildren().splice(i,1),t.ancestor=void 0),!0===this.isAttachedToRoot()&&repaint(),this.enableChildBoundsUpdate&&this.updateBounds(!0),this.onChildChange.call(this,i)}},e.prototype.setChildsProperty=function(t,i,r){this.forEach((function(o){!0===r&&o instanceof e&&o.setChildsProperty(t,i,r),o[t]=i}))},e.prototype.moveUp=function(t){var e=this.getChildIndex(t);e-1>=0&&(this.swapChildren(t,this.getChildAt(e-1)),this.isDirty=!0)},e.prototype.moveDown=function(t){var e=this.getChildIndex(t);e>=0&&e+1<this.getChildren().length&&(this.swapChildren(t,this.getChildAt(e+1)),this.isDirty=!0)},e.prototype.moveToTop=function(t){var e=this.getChildIndex(t);if(e>0){var i=this.getChildren();i.splice(0,0,i.splice(e,1)[0]),t.pos.z=i[1].pos.z+1,this.isDirty=!0}},e.prototype.moveToBottom=function(t){var e=this.getChildIndex(t),i=this.getChildren();e>=0&&e<i.length-1&&(i.splice(i.length-1,0,i.splice(e,1)[0]),t.pos.z=i[i.length-2].pos.z-1,this.isDirty=!0)},e.prototype.sort=function(t){this.pendingSort||(!0===t&&this.forEach((function(i){i instanceof e&&i.sort(t)})),this.pendingSort=utils.function.defer((function(){this.getChildren().sort(this["_sort"+this.sortOn.toUpperCase()]),this.pendingSort=null,repaint()}),this))},e.prototype.onDeactivateEvent=function(){this.forEach((function(t){"function"==typeof t.onDeactivateEvent&&t.onDeactivateEvent()}))},e.prototype._sortZ=function(t,e){return e.pos&&t.pos?e.pos.z-t.pos.z:t.pos?-1/0:1/0},e.prototype._sortReverseZ=function(t,e){return t.pos&&e.pos?t.pos.z-e.pos.z:t.pos?1/0:-1/0},e.prototype._sortX=function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.x-t.pos.x},e.prototype._sortY=function(t,e){if(!e.pos||!t.pos)return t.pos?-1/0:1/0;var i=e.pos.z-t.pos.z;return i||e.pos.y-t.pos.y},e.prototype.destroy=function(){this.reset(),t.prototype.destroy.call(this,arguments)},e.prototype.update=function(e){for(var i,r=!1,o=state.isPaused(),n=this.getChildren(),s=n.length;s--,i=n[s];)o&&!i.updateWhenPaused||(i.isRenderable?((r=globalFloatingCounter>0||i.floating)&&globalFloatingCounter++,i.inViewport=!1,state.current().cameras.forEach((function(t){t.isVisible(i,r)&&(i.inViewport=!0)})),this.isDirty|=(i.inViewport||i.alwaysUpdate)&&i.update(e),globalFloatingCounter>0&&globalFloatingCounter--):this.isDirty|=i.update(e));return t.prototype.update.call(this,e)},e.prototype.draw=function(t,e){var i=!1,r=this.getBounds();this.drawCount=0,!1===this.root&&!0===this.clipping&&!0===r.isFinite()&&t.clipRect(r.left,r.top,r.width,r.height),t.translate(this.pos.x,this.pos.y),this.backgroundColor.alpha>1/255&&t.clearColor(this.backgroundColor);for(var o,n=this.getChildren(),s=n.length;o=n[--s];)o.isRenderable&&(i=!0===o.floating,(o.inViewport||i)&&(i&&(t.save(),t.resetTransform()),o.preDraw(t),o.draw(t,e),o.postDraw(t),i&&t.restore(),this.drawCount++))},e}(Renderable),QT_ARRAY=[];function QT_ARRAY_POP(t,e,i,r){if(void 0===e&&(e=4),void 0===i&&(i=4),void 0===r&&(r=0),QT_ARRAY.length>0){var o=QT_ARRAY.pop();return o.bounds=t,o.max_objects=e,o.max_levels=i,o.level=r,o}return new QuadTree(t,e,i,r)}function QT_ARRAY_PUSH(t){QT_ARRAY.push(t)}var QT_VECTOR=new Vector2d,QuadTree=function(t,e,i,r){void 0===e&&(e=4),void 0===i&&(i=4),void 0===r&&(r=0),this.max_objects=e,this.max_levels=i,this.level=r,this.bounds=t,this.objects=[],this.nodes=[]};QuadTree.prototype.split=function(){var t=this.level+1,e=this.bounds.width/2,i=this.bounds.height/2,r=this.bounds.left,o=this.bounds.top;this.nodes[0]=QT_ARRAY_POP({left:r+e,top:o,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[1]=QT_ARRAY_POP({left:r,top:o,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[2]=QT_ARRAY_POP({left:r,top:o+i,width:e,height:i},this.max_objects,this.max_levels,t),this.nodes[3]=QT_ARRAY_POP({left:r+e,top:o+i,width:e,height:i},this.max_objects,this.max_levels,t)},QuadTree.prototype.getIndex=function(t){var e,i=t.getBounds(),r=-1,o=(e=!0===t.isFloating?viewport.localToWorld(i.left,i.top,QT_VECTOR):QT_VECTOR.set(t.left,t.top)).x,n=e.y,s=i.width,a=i.height,h=this.bounds.left+this.bounds.width/2,l=this.bounds.top+this.bounds.height/2,c=n<l&&n+a<l,u=n>l;return o<h&&o+s<h?c?r=1:u&&(r=2):o>h&&(c?r=0:u&&(r=3)),r},QuadTree.prototype.insertContainer=function(t){for(var e,i=t.children.length;i--,e=t.children[i];)!0!==e.isKinematic&&(e instanceof Container?("rootContainer"!==e.name&&this.insert(e),this.insertContainer(e)):"function"==typeof e.getBounds&&this.insert(e))},QuadTree.prototype.insert=function(t){var e=-1;if(this.nodes.length>0&&-1!==(e=this.getIndex(t)))this.nodes[e].insert(t);else if(this.objects.push(t),this.objects.length>this.max_objects&&this.level<this.max_levels){0===this.nodes.length&&this.split();for(var i=0;i<this.objects.length;)-1!==(e=this.getIndex(this.objects[i]))?this.nodes[e].insert(this.objects.splice(i,1)[0]):i+=1}},QuadTree.prototype.retrieve=function(t,e){var i=this.objects;if(this.nodes.length>0){var r=this.getIndex(t);if(-1!==r)i=i.concat(this.nodes[r].retrieve(t));else for(var o=0;o<this.nodes.length;o+=1)i=i.concat(this.nodes[o].retrieve(t))}return"function"==typeof e&&i.sort(e),i},QuadTree.prototype.remove=function(t){var e=!1;if(void 0===t.getBounds)return!1;if(this.nodes.length>0){var i=this.getIndex(t);-1!==i&&(e=remove(this.nodes[i],t))&&this.nodes[i].isPrunable()&&this.nodes.splice(i,1)}return!1===e&&-1!==this.objects.indexOf(t)&&(remove(this.objects,t),e=!0),e},QuadTree.prototype.isPrunable=function(){return!(this.hasChildren()||this.objects.length>0)},QuadTree.prototype.hasChildren=function(){for(var t=0;t<this.nodes.length;t+=1){var e=this.nodes[t];if(e.length>0||e.objects.length>0)return!0}return!1},QuadTree.prototype.clear=function(t){this.objects.length=0;for(var e=0;e<this.nodes.length;e++)this.nodes[e].clear(),QT_ARRAY_PUSH(this.nodes[e]);this.nodes.length=0,void 0!==t&&this.bounds.setMinMax(t.min.x,t.min.y,t.max.x,t.max.y)};var World=function(t){function e(e,i,r,o){var n=this;void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1/0),void 0===o&&(o=1/0),t.call(this,e,i,r,o,!0),this.name="rootContainer",this.anchorPoint.set(0,0),this.fps=60,this.gravity=new Vector2d(0,.98),this.preRender=!1,this.bodies=new Set,this.broadphase=new QuadTree(this.getBounds().clone(),collision.maxChildren,collision.maxDepth),on(GAME_RESET,this.reset,this),on(LEVEL_LOADED,(function(){n.broadphase.clear(n.getBounds())}))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){this.broadphase.clear(),this.anchorPoint.set(0,0),t.prototype.reset.call(this),this.bodies.clear()},e.prototype.addBody=function(t){return this.bodies.add(t),this},e.prototype.removeBody=function(t){return this.bodies.delete(t),this},e.prototype.update=function(e){var i=state.isPaused();return this.broadphase.clear(),this.broadphase.insertContainer(this),this.bodies.forEach((function(t){if(!t.isStatic){var r=t.ancestor;i&&!r.updateWhenPaused||!r.inViewport&&!r.alwaysUpdate||(!0===t.update(e)&&(r.isDirty=!0),collisionCheck(r))}})),t.prototype.update.call(this,e)},e}(Container),isDirty=!0,isAlwaysDirty=!1,frameCounter=0,frameRate=1,accumulator=0,accumulatorMax=0,accumulatorUpdateDelta=0,stepSize=1e3/60,updateDelta=0,lastUpdateStart=null,updateAverageDelta=0,viewport,world;on(BOOT,(function(){world=new World,emit(GAME_INIT)}));var mergeGroup=!0,sortOn="z",lastUpdate=globalThis.performance.now();function onLevelLoaded(){}function reset(){var t=state.current();void 0!==t&&(viewport=t.cameras.get("default")),emit(GAME_RESET),updateFrameRate()}function updateFrameRate(){frameCounter=0,frameRate=~~(.5+60/timer$1.maxfps),stepSize=1e3/world.fps,accumulator=0,accumulatorMax=10*stepSize,isAlwaysDirty=timer$1.maxfps>world.fps}function getParentContainer(t){return t.ancestor}function repaint(){isDirty=!0}function update$1(t,e){if(++frameCounter%frameRate==0){for(frameCounter=0,emit(GAME_BEFORE_UPDATE,t),accumulator+=timer$1.getDelta(),accumulator=Math.min(accumulator,accumulatorMax),updateDelta=timer$1.interpolation?timer$1.getDelta():stepSize,accumulatorUpdateDelta=timer$1.interpolation?updateDelta:Math.max(updateDelta,updateAverageDelta);accumulator>=accumulatorUpdateDelta||timer$1.interpolation;)if(lastUpdateStart=globalThis.performance.now(),!0!==state.isPaused()&&emit(GAME_UPDATE,t),isDirty=e.update(updateDelta)||isDirty,lastUpdate=globalThis.performance.now(),updateAverageDelta=lastUpdate-lastUpdateStart,accumulator-=accumulatorUpdateDelta,timer$1.interpolation){accumulator=0;break}emit(GAME_AFTER_UPDATE,lastUpdate)}}function draw(t){!0===renderer.isContextValid&&(isDirty||isAlwaysDirty)&&(emit(GAME_BEFORE_DRAW,globalThis.performance.now()),renderer.clear(),t.draw(renderer),isDirty=!1,renderer.flush(),emit(GAME_AFTER_DRAW,globalThis.performance.now()))}var game=Object.freeze({__proto__:null,get viewport(){return viewport},get world(){return world},mergeGroup:mergeGroup,sortOn:sortOn,get lastUpdate(){return lastUpdate},onLevelLoaded:onLevelLoaded,reset:reset,updateFrameRate:updateFrameRate,getParentContainer:getParentContainer,repaint:repaint,update:update$1,draw:draw}),MIN=Math.min,MAX=Math.max,targetV=new Vector2d,Camera2d=function(t){function e(e,i,r,o){t.call(this,e,i,r-e,o-i),this.AXIS={NONE:0,HORIZONTAL:1,VERTICAL:2,BOTH:3},this.bounds=pull("Bounds"),this.smoothFollow=!0,this.damping=1,this.near=-1e3,this.far=1e3,this.projectionMatrix=new Matrix3d,this.invCurrentTransform=new Matrix2d,this.offset=new Vector2d,this.target=null,this.follow_axis=this.AXIS.NONE,this._shake={intensity:0,duration:0,axis:this.AXIS.BOTH,onComplete:null},this._fadeOut={color:null,tween:null},this._fadeIn={color:null,tween:null},this.name="default",this.setDeadzone(this.width/6,this.height/6),this.anchorPoint.set(0,0),this.isKinematic=!1,this.bounds.setMinMax(e,i,r,o),this._updateProjectionMatrix(),on(GAME_RESET,this.reset,this),on(CANVAS_ONRESIZE,this.resize,this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype._updateProjectionMatrix=function(){this.projectionMatrix.ortho(0,this.width,this.height,0,this.near,this.far)},e.prototype._followH=function(t){var e=this.pos.x;return t.x-this.pos.x>this.deadzone.right?e=MIN(t.x-this.deadzone.right,this.bounds.width-this.width):t.x-this.pos.x<this.deadzone.pos.x&&(e=MAX(t.x-this.deadzone.pos.x,this.bounds.left)),e},e.prototype._followV=function(t){var e=this.pos.y;return t.y-this.pos.y>this.deadzone.bottom?e=MIN(t.y-this.deadzone.bottom,this.bounds.height-this.height):t.y-this.pos.y<this.deadzone.pos.y&&(e=MAX(t.y-this.deadzone.pos.y,this.bounds.top)),e},e.prototype.reset=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.pos.x=t,this.pos.y=e,this.unfollow(),this.smoothFollow=!0,this.damping=1,this.currentTransform.identity(),this.invCurrentTransform.identity().invert(),this._updateProjectionMatrix()},e.prototype.setDeadzone=function(t,e){void 0===this.deadzone&&(this.deadzone=new Rect(0,0,0,0)),this.deadzone.pos.set(~~((this.width-t)/2),~~((this.height-e)/2-.25*e)),this.deadzone.resize(t,e),this.smoothFollow=!1,this.updateTarget(),this.smoothFollow=!0},e.prototype.resize=function(e,i){return t.prototype.resize.call(this,e,i),this.smoothFollow=!1,this.setBounds(0,0,e,i),this.setDeadzone(e/6,i/6),this.update(),this.smoothFollow=!0,this._updateProjectionMatrix(),emit(VIEWPORT_ONRESIZE,this.width,this.height),this},e.prototype.setBounds=function(t,e,i,r){this.smoothFollow=!1,this.bounds.setMinMax(t,e,i+t,r+e),this.moveTo(this.pos.x,this.pos.y),this.update(),this.smoothFollow=!0},e.prototype.follow=function(e,i,r){if(e instanceof t)this.target=e.pos;else{if(!(e instanceof Vector2d||e instanceof Vector3d||e instanceof ObservableVector2d||e instanceof ObservableVector3d))throw new Error("invalid target for me.Camera2d.follow");this.target=e}this.follow_axis=void 0===i?this.AXIS.BOTH:i,this.smoothFollow=!1,this.damping="number"!=typeof r?1:clamp(r,0,1),this.updateTarget(),this.smoothFollow=!0},e.prototype.unfollow=function(){this.target=null,this.follow_axis=this.AXIS.NONE},e.prototype.move=function(t,e){this.moveTo(this.pos.x+t,this.pos.y+e)},e.prototype.moveTo=function(t,e){var i=this.pos.x,r=this.pos.y;this.pos.x=clamp(t,this.bounds.left,this.bounds.width),this.pos.y=clamp(e,this.bounds.top,this.bounds.height),i===this.pos.x&&r===this.pos.y||(this.isDirty=!0)},e.prototype.updateTarget=function(){if(this.target){switch(targetV.setV(this.pos),this.follow_axis){case this.AXIS.NONE:break;case this.AXIS.HORIZONTAL:targetV.x=this._followH(this.target);break;case this.AXIS.VERTICAL:targetV.y=this._followV(this.target);break;case this.AXIS.BOTH:targetV.x=this._followH(this.target),targetV.y=this._followV(this.target)}if(!this.pos.equals(targetV)){if(!0===this.smoothFollow&&this.damping<1){if(toBeCloseTo(targetV.x,this.pos.x,2)&&toBeCloseTo(targetV.y,this.pos.y,2))return void this.pos.setV(targetV);this.pos.lerp(targetV,this.damping)}else this.pos.setV(targetV);this.isDirty=!0}}},e.prototype.update=function(e){return this.updateTarget(e),this._shake.duration>0&&(this._shake.duration-=e,this._shake.duration<=0?(this._shake.duration=0,this.offset.setZero(),"function"==typeof this._shake.onComplete&&this._shake.onComplete()):(this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.HORIZONTAL||(this.offset.x=(Math.random()-.5)*this._shake.intensity),this._shake.axis!==this.AXIS.BOTH&&this._shake.axis!==this.AXIS.VERTICAL||(this.offset.y=(Math.random()-.5)*this._shake.intensity)),this.isDirty=!0),!0===this.isDirty&&emit(VIEWPORT_ONCHANGE,this.pos),null==this._fadeIn.tween&&null==this._fadeOut.tween||(this.isDirty=!0),this.currentTransform.isIdentity()?this.invCurrentTransform.identity():this.invCurrentTransform.copy(this.currentTransform).invert(),t.prototype.update.call(this,e)},e.prototype.shake=function(t,e,i,r,o){0!==this._shake.duration&&!0!==o||(this._shake.intensity=t,this._shake.duration=e,this._shake.axis=i||this.AXIS.BOTH,this._shake.onComplete="function"==typeof r?r:void 0)},e.prototype.fadeOut=function(t,e,i){void 0===e&&(e=1e3),this._fadeOut.color=pull("Color").copy(t),this._fadeOut.tween=pull("Tween",this._fadeOut.color).to({alpha:0},e).onComplete(i||null),this._fadeOut.tween.isPersistent=!0,this._fadeOut.tween.start()},e.prototype.fadeIn=function(t,e,i){void 0===e&&(e=1e3),this._fadeIn.color=pull("Color").copy(t);var r=this._fadeIn.color.alpha;this._fadeIn.color.alpha=0,this._fadeIn.tween=pull("Tween",this._fadeIn.color).to({alpha:r},e).onComplete(i||null),this._fadeIn.tween.isPersistent=!0,this._fadeIn.tween.start()},e.prototype.focusOn=function(t){var e=t.getBounds();this.moveTo(t.pos.x+e.left+e.width/2,t.pos.y+e.top+e.height/2)},e.prototype.isVisible=function(t,e){return void 0===e&&(e=t.floating),!0===e||!0===t.floating?renderer.overlaps(t.getBounds()):t.getBounds().overlaps(this)},e.prototype.localToWorld=function(t,e,i){return(i=i||pull("Vector2d")).set(t,e).add(this.pos).sub(world.pos),this.currentTransform.isIdentity()||this.invCurrentTransform.apply(i),i},e.prototype.worldToLocal=function(t,e,i){return(i=i||pull("Vector2d")).set(t,e),this.currentTransform.isIdentity()||this.currentTransform.apply(i),i.sub(this.pos).add(world.pos)},e.prototype.drawFX=function(t){this._fadeIn.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeIn.color),t.fillRect(0,0,this.width,this.height),t.restore(),1===this._fadeIn.color.alpha&&(this._fadeIn.tween=null,push(this._fadeIn.color),this._fadeIn.color=null)),this._fadeOut.tween&&(t.save(),t.resetTransform(),t.setColor(this._fadeOut.color),t.fillRect(0,0,this.width,this.height),t.restore(),0===this._fadeOut.color.alpha&&(this._fadeOut.tween=null,push(this._fadeOut.color),this._fadeOut.color=null))},e.prototype.draw=function(t,e){var i=this.pos.x+this.offset.x,r=this.pos.y+this.offset.y;e.currentTransform.translate(-i,-r),t.setProjection(this.projectionMatrix),t.clipRect(0,0,this.width,this.height),this.preDraw(t),e.preDraw(t),e.draw(t,this),this.drawFX(t),e.postDraw(t),this.postDraw(t),e.currentTransform.translate(i,r)},e}(Renderable),default_camera,default_settings={cameras:[]},Stage=function(t){this.cameras=new Map,this.settings=Object.assign(default_settings,t||{})};Stage.prototype.reset=function(){var t=this;if(this.settings.cameras.forEach((function(e){t.cameras.set(e.name,e)})),!1===this.cameras.has("default")){if(void 0===default_camera){var e=renderer.getWidth(),i=renderer.getHeight();default_camera=new Camera2d(0,0,e,i)}this.cameras.set("default",default_camera)}reset(),this.onResetEvent.apply(this,arguments)},Stage.prototype.update=function(t){var e=world.update(t);return this.cameras.forEach((function(i){i.update(t)&&(e=!0)})),e},Stage.prototype.draw=function(t){this.cameras.forEach((function(e){e.draw(t,world)}))},Stage.prototype.destroy=function(){this.cameras.clear(),this.onDestroyEvent.apply(this,arguments)},Stage.prototype.onResetEvent=function(){"function"==typeof this.settings.onResetEvent&&this.settings.onResetEvent.apply(this,arguments)},Stage.prototype.onDestroyEvent=function(){"function"==typeof this.settings.onDestroyEvent&&this.settings.onDestroyEvent.apply(this,arguments)};var ProgressBar=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.barHeight=o,this.anchorPoint.set(0,0),on(LOADER_PROGRESS,this.onProgressUpdate,this),on(VIEWPORT_ONRESIZE,this.resize,this),this.anchorPoint.set(0,0),this.progress=0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onProgressUpdate=function(t){this.progress=~~(t*this.width),this.isDirty=!0},e.prototype.draw=function(t){t.setColor("black"),t.fillRect(this.pos.x,viewport.centerY,t.getWidth(),this.barHeight/2),t.setColor("#55aa00"),t.fillRect(this.pos.x,viewport.centerY,this.progress,this.barHeight/2)},e.prototype.onDestroyEvent=function(){off(LOADER_PROGRESS,this.onProgressUpdate),off(VIEWPORT_ONRESIZE,this.resize)},e}(Renderable),IconLogo=function(t){function e(e,i){t.call(this,e,i,100,85),this.iconCanvas=createCanvas(renderer.WebGLVersion>1?this.width:nextPowerOfTwo(this.width),renderer.WebGLVersion>1?this.height:nextPowerOfTwo(this.height),!1);var r=renderer.getContext2d(this.iconCanvas);r.beginPath(),r.moveTo(.7,48.9),r.bezierCurveTo(10.8,68.9,38.4,75.8,62.2,64.5),r.bezierCurveTo(86.1,53.1,97.2,27.7,87,7.7),r.lineTo(87,7.7),r.bezierCurveTo(89.9,15.4,73.9,30.2,50.5,41.4),r.bezierCurveTo(27.1,52.5,5.2,55.8,.7,48.9),r.lineTo(.7,48.9),r.closePath(),r.fillStyle="rgb(255, 255, 255)",r.fill(),r.beginPath(),r.moveTo(84,7),r.bezierCurveTo(87.6,14.7,72.5,30.2,50.2,41.6),r.bezierCurveTo(27.9,53,6.9,55.9,3.2,48.2),r.bezierCurveTo(-.5,40.4,14.6,24.9,36.9,13.5),r.bezierCurveTo(59.2,2.2,80.3,-.8,84,7),r.lineTo(84,7),r.closePath(),r.lineWidth=5.3,r.strokeStyle="rgb(255, 255, 255)",r.lineJoin="miter",r.miterLimit=4,r.stroke(),this.anchorPoint.set(.5,.5)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.draw=function(t){t.drawImage(this.iconCanvas,t.getWidth()/2,this.pos.y)},e}(Renderable),DefaultLoadingScreen=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(){world.backgroundColor.parseCSS("#202020"),world.addChild(new ProgressBar(0,renderer.getHeight()/2,renderer.getWidth(),8),1),world.addChild(new IconLogo(renderer.getWidth()/2,renderer.getHeight()/2-16-35),2);var t=pull("Text",renderer.getWidth()/2,renderer.getHeight()/2+16,{font:"century gothic",size:32,fillStyle:"white",textAlign:"left",textBaseline:"top",text:"melon",offScreenCanvas:renderer.WebGLVersion>=1});t.anchorPoint.set(0,0);var e=pull("Text",renderer.getWidth()/2,renderer.getHeight()/2+16,{font:"century gothic",size:32,fillStyle:"#55aa00",textAlign:"left",textBaseline:"top",bold:!0,text:"JS",offScreenCanvas:renderer.WebGLVersion>=1});e.anchorPoint.set(0,0);var i=t.getBounds().width+e.getBounds().width;t.pos.x=renderer.getWidth()/2-i/2,e.pos.x=t.pos.x+t.getBounds().width,world.addChild(t,2),world.addChild(e,2)},e}(Stage),_state=-1,_animFrameId=-1,_isPaused=!1,_stages={},_fade={color:"",duration:0},_onSwitchComplete=null,_extraArgs=null,_pauseTime=0;function _startRunLoop(){-1===_animFrameId&&-1!==_state&&(timer$1.reset(),_animFrameId=globalThis.requestAnimationFrame(_renderFrame))}function _resumeRunLoop(){_isPaused&&-1!==_state&&(timer$1.reset(),_isPaused=!1)}function _pauseRunLoop(){_isPaused=!0}function _renderFrame(t){var e=_stages[_state].stage;update$1(t,e),draw(e),-1!==_animFrameId&&(_animFrameId=globalThis.requestAnimationFrame(_renderFrame))}function _stopRunLoop(){globalThis.cancelAnimationFrame(_animFrameId),_animFrameId=-1}function _switchState(t){_stopRunLoop(),_stages[_state]&&_stages[_state].stage.destroy(),_stages[t]&&(_stages[_state=t].stage.reset.apply(_stages[_state].stage,_extraArgs),_startRunLoop(),_onSwitchComplete&&_onSwitchComplete(),repaint())}on(BOOT,(function(){state.set(state.LOADING,new DefaultLoadingScreen),state.set(state.DEFAULT,new Stage),on(VIDEO_INIT,(function(){state.change(state.DEFAULT,!0)}))}));var state={LOADING:0,MENU:1,READY:2,PLAY:3,GAMEOVER:4,GAME_END:5,SCORE:6,CREDITS:7,SETTINGS:8,DEFAULT:9,USER:100,stop:function(t){void 0===t&&(t=!1),_state!==this.LOADING&&this.isRunning()&&(_stopRunLoop(),!0===t&&t(),_pauseTime=globalThis.performance.now(),emit(STATE_STOP))},pause:function(t){void 0===t&&(t=!1),_state===this.LOADING||this.isPaused()||(_pauseRunLoop(),!0===t&&pauseTrack(),_pauseTime=globalThis.performance.now(),emit(STATE_PAUSE))},restart:function(t){void 0===t&&(t=!1),this.isRunning()||(_startRunLoop(),!0===t&&resumeTrack(),_pauseTime=globalThis.performance.now()-_pauseTime,repaint(),emit(STATE_RESTART,_pauseTime))},resume:function(t){void 0===t&&(t=!1),this.isPaused()&&(_resumeRunLoop(),!0===t&&resumeTrack(),_pauseTime=globalThis.performance.now()-_pauseTime,emit(STATE_RESUME,_pauseTime))},isRunning:function(){return-1!==_animFrameId},isPaused:function(){return _isPaused},set:function(t,e,i){if(void 0===i&&(i=!1),!(e instanceof Stage))throw new Error(e+" is not an instance of me.Stage");_stages[t]={},_stages[t].stage=e,_stages[t].transition=!0,!0===i&&this.change(t)},current:function(){if(void 0!==_stages[_state])return _stages[_state].stage},transition:function(t,e,i){"fade"===t&&(_fade.color=e,_fade.duration=i)},setTransition:function(t,e){_stages[t].transition=e},change:function(t,e){if(void 0===_stages[t])throw new Error("Undefined Stage for state '"+t+"'");this.isCurrent(t)||(_extraArgs=null,arguments.length>1&&(_extraArgs=Array.prototype.slice.call(arguments,1)),_fade.duration&&_stages[t].transition?(_onSwitchComplete=function(){viewport.fadeOut(_fade.color,_fade.duration)},viewport.fadeIn(_fade.color,_fade.duration,(function(){defer(_switchState,this,t)}))):!0===e?_switchState(t):defer(_switchState,this,t))},isCurrent:function(t){return _state===t}};function setTMXValue(name,type,value){var match;if("string"!=typeof value)return value;switch(type){case"int":case"float":value=Number(value);break;case"bool":value="true"===value;break;default:if(!value||isBoolean(value))value=!value||"true"===value;else if(isNumeric(value))value=Number(value);else if(0===value.search(/^json:/i)){match=value.split(/^json:/i)[1];try{value=JSON.parse(match)}catch(t){throw new Error("Unable to parse JSON: "+match)}}else if(0===value.search(/^eval:/i)){match=value.split(/^eval:/i)[1];try{value=eval(match)}catch(t){throw new Error("Unable to evaluate: "+match)}}else((match=value.match(/^#([\da-fA-F])([\da-fA-F]{3})$/))||(match=value.match(/^#([\da-fA-F]{2})([\da-fA-F]{6})$/)))&&(value="#"+match[2]+match[1]);0===name.search(/^(ratio|anchorPoint)$/)&&"number"==typeof value&&(value={x:value,y:value})}return value}function parseAttributes(t,e){if(e.attributes&&e.attributes.length>0)for(var i=0;i<e.attributes.length;i++){var r=e.attributes.item(i);void 0!==r.name?t[r.name]=r.value:t[r.nodeName]=r.nodeValue}}function decompress(){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")}function decodeCSV(t){for(var e=t.replace("\n","").trim().split(","),i=[],r=0;r<e.length;r++)i.push(+e[r]);return i}function decodeBase64AsArray(t,e){var i,r,o;e=e||1;var n=globalThis.atob(t.replace(/[^A-Za-z0-9\+\/\=]/g,"")),s=new Uint32Array(n.length/e);for(i=0,o=n.length/e;i<o;i++)for(s[i]=0,r=e-1;r>=0;--r)s[i]+=n.charCodeAt(i*e+r)<<(r<<3);return s}function decode(t,e,i){switch(i=i||"none",e=e||"none"){case"csv":return decodeCSV(t);case"base64":var r=decodeBase64AsArray(t,4);return"none"===i?r:decompress();case"none":return t;case"xml":throw new Error("XML encoding is deprecated, use base64 instead");default:throw new Error("Unknown layer encoding: "+e)}}function normalize(t,e){var i=e.nodeName;switch(i){case"data":var r=parse(e);r.text=r.text||r.chunk.text,r.encoding=r.encoding||"xml",t.data=decode(r.text,r.encoding,r.compression),t.encoding="none";break;case"imagelayer":case"layer":case"objectgroup":case"group":var o=parse(e);o.type="layer"===i?"tilelayer":i,o.image&&(o.image=o.image.source),t.layers=t.layers||[],t.layers.push(o);break;case"animation":t.animation=parse(e).frames;break;case"frame":case"object":var n=i+"s";t[n]=t[n]||[],t[n].push(parse(e));break;case"tile":var s=parse(e);s.image&&(s.imagewidth=s.image.width,s.imageheight=s.image.height,s.image=s.image.source),t.tiles=t.tiles||{},t.tiles[s.id]=s;break;case"tileset":var a=parse(e);a.image&&(a.imagewidth=a.image.width,a.imageheight=a.image.height,a.image=a.image.source),t.tilesets=t.tilesets||[],t.tilesets.push(a);break;case"polygon":case"polyline":t[i]=[];for(var h,l=parse(e).points.split(" "),c=0;c<l.length;c++)h=l[c].split(","),t[i].push({x:+h[0],y:+h[1]});break;case"properties":t.properties=parse(e);break;case"property":var u=parse(e),d=void 0!==u.value?u.value:u.text;t[u.name]=setTMXValue(u.name,u.type||"string",d);break;default:t[i]=parse(e)}}function parse(t){var e={},i="";if(1===t.nodeType&&parseAttributes(e,t),t.hasChildNodes())for(var r=0;r<t.childNodes.length;r++){var o=t.childNodes.item(r);switch(o.nodeType){case 1:normalize(e,o);break;case 3:i+=o.nodeValue.trim()}}return i&&(e.text=i),e}function applyTMXProperties(t,e){var i=e.properties,r=e.propertytypes;if(void 0!==i)for(var o in i)if(i.hasOwnProperty(o)){var n="string",s=o,a=i[o];void 0!==i[o].name&&(s=i[o].name),void 0!==r?n=r[o]:void 0!==i[o].type&&(n=i[o].type),void 0!==i[o].value&&(a=i[o].value),t[s]=setTMXValue(s,n,a)}}var src={},arraymultimap={},multimap={},__generator=commonjsGlobal&&commonjsGlobal.__generator||function(t,e){var i,r,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function a(n){return function(a){return function(n){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,r&&(o=2&n[0]?r.return:n[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,n[1])).done)return o;switch(r=0,o&&(n=[2&n[0],o.value]),n[0]){case 0:case 1:o=n;break;case 4:return s.label++,{value:n[1],done:!1};case 5:s.label++,r=n[1],n=[0];continue;case 7:n=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==n[0]&&2!==n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1],o=n;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(n);break}o[2]&&s.ops.pop(),s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t],r=0}finally{i=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}},__values=commonjsGlobal&&commonjsGlobal.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],r=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=commonjsGlobal&&commonjsGlobal.__read||function(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,o,n=i.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(i=n.return)&&i.call(n)}finally{if(o)throw o.error}}return s};Object.defineProperty(multimap,"__esModule",{value:!0}),multimap.Multimap=void 0;var Multimap=function(){function t(t,e){var i,r;if(this.size_=0,this.map=new Map,this.operator=t,e)try{for(var o=__values(e),n=o.next();!n.done;n=o.next()){var s=__read(n.value,2),a=s[0],h=s[1];this.put(a,h)}}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return this}return Object.defineProperty(t.prototype,"size",{get:function(){return this.size_},enumerable:!1,configurable:!0}),t.prototype.get=function(t){var e=this.map.get(t);return e?this.operator.clone(e):this.operator.create()},t.prototype.put=function(t,e){var i=this.map.get(t);return i||(i=this.operator.create()),!!this.operator.add(e,i)&&(this.map.set(t,i),this.size_++,!0)},t.prototype.putAll=function(e,i){var r,o,n,s,a=0;if(i){var h=e,l=i;try{for(var c=__values(l),u=c.next();!u.done;u=c.next()){var d=u.value;this.put(h,d),a++}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}}else{if(!(e instanceof t))throw new TypeError("unexpected arguments");try{for(var p=__values(e.entries()),f=p.next();!f.done;f=p.next()){var y=__read(f.value,2);h=y[0],d=y[1];this.put(h,d),a++}}catch(t){n={error:t}}finally{try{f&&!f.done&&(s=p.return)&&s.call(p)}finally{if(n)throw n.error}}}return a>0},t.prototype.has=function(t){return this.map.has(t)},t.prototype.hasEntry=function(t,e){return this.operator.has(e,this.get(t))},t.prototype.delete=function(t){return this.size_-=this.operator.size(this.get(t)),this.map.delete(t)},t.prototype.deleteEntry=function(t,e){var i=this.get(t);return!!this.operator.delete(e,i)&&(this.map.set(t,i),this.size_--,!0)},t.prototype.clear=function(){this.map.clear(),this.size_=0},t.prototype.keys=function(){return this.map.keys()},t.prototype.entries=function(){var t=this;return function(){var e,i,r,o,n,s,a,h,l,c,u,d,p,f;return __generator(this,(function(y){switch(y.label){case 0:y.trys.push([0,11,12,13]),e=__values(t.map.entries()),i=e.next(),y.label=1;case 1:if(i.done)return[3,10];r=__read(i.value,2),o=r[0],n=r[1],y.label=2;case 2:y.trys.push([2,7,8,9]),p=void 0,s=__values(n),a=s.next(),y.label=3;case 3:return a.done?[3,6]:(h=a.value,[4,[o,h]]);case 4:y.sent(),y.label=5;case 5:return a=s.next(),[3,3];case 6:return[3,9];case 7:return l=y.sent(),p={error:l},[3,9];case 8:try{a&&!a.done&&(f=s.return)&&f.call(s)}finally{if(p)throw p.error}return[7];case 9:return i=e.next(),[3,1];case 10:return[3,13];case 11:return c=y.sent(),u={error:c},[3,13];case 12:try{i&&!i.done&&(d=e.return)&&d.call(e)}finally{if(u)throw u.error}return[7];case 13:return[2]}}))}()},t.prototype.values=function(){var t=this;return function(){var e,i,r,o,n,s;return __generator(this,(function(a){switch(a.label){case 0:a.trys.push([0,5,6,7]),e=__values(t.entries()),i=e.next(),a.label=1;case 1:return i.done?[3,4]:(r=__read(i.value,2),[4,r[1]]);case 2:a.sent(),a.label=3;case 3:return i=e.next(),[3,1];case 4:return[3,7];case 5:return o=a.sent(),n={error:o},[3,7];case 6:try{i&&!i.done&&(s=e.return)&&s.call(e)}finally{if(n)throw n.error}return[7];case 7:return[2]}}))}()},t.prototype.forEach=function(t,e){var i,r;try{for(var o=__values(this.entries()),n=o.next();!n.done;n=o.next()){var s=__read(n.value,2),a=s[0],h=s[1];t.call(void 0===e?this:e,h,a,this)}}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}},t.prototype[Symbol.iterator]=function(){return this.entries()},t.prototype.asMap=function(){var t,e,i=new Map;try{for(var r=__values(this.keys()),o=r.next();!o.done;o=r.next()){var n=o.value;i.set(n,this.operator.clone(this.get(n)))}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}return i},t}();multimap.Multimap=Multimap;var __extends$1=commonjsGlobal&&commonjsGlobal.__extends||(extendStatics=function(t,e){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},extendStatics(t,e)},function(t,e){function i(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),extendStatics;Object.defineProperty(arraymultimap,"__esModule",{value:!0}),arraymultimap.ArrayMultimap=void 0;var multimap_1$1=multimap,ArrayMultimap=function(t){function e(e){return t.call(this,new ArrayOperator,e)||this}return __extends$1(e,t),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"ArrayMultimap"},enumerable:!1,configurable:!0}),e}(multimap_1$1.Multimap);arraymultimap.ArrayMultimap=ArrayMultimap;var ArrayOperator=function(){function t(){}return t.prototype.create=function(){return[]},t.prototype.clone=function(t){return t.slice()},t.prototype.add=function(t,e){return e.push(t),!0},t.prototype.size=function(t){return t.length},t.prototype.delete=function(t,e){var i=e.indexOf(t);return i>-1&&(e.splice(i,1),!0)},t.prototype.has=function(t,e){return e.includes(t)},t}(),setmultimap={},__extends=commonjsGlobal&&commonjsGlobal.__extends||function(){var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();Object.defineProperty(setmultimap,"__esModule",{value:!0}),setmultimap.SetMultimap=void 0;var multimap_1=multimap,SetMultimap=function(t){function e(e){return t.call(this,new SetOperator,e)||this}return __extends(e,t),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"SetMultimap"},enumerable:!1,configurable:!0}),e}(multimap_1.Multimap);setmultimap.SetMultimap=SetMultimap;var SetOperator=function(){function t(){}return t.prototype.create=function(){return new Set},t.prototype.clone=function(t){return new Set(t)},t.prototype.add=function(t,e){var i=e.size;return e.add(t),i!==e.size},t.prototype.size=function(t){return t.size},t.prototype.delete=function(t,e){return e.delete(t)},t.prototype.has=function(t,e){return e.has(t)},t}();!function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.SetMultimap=t.ArrayMultimap=void 0;var e=arraymultimap;Object.defineProperty(t,"ArrayMultimap",{enumerable:!0,get:function(){return e.ArrayMultimap}});var i=setmultimap;Object.defineProperty(t,"SetMultimap",{enumerable:!0,get:function(){return i.SetMultimap}})}(src);var TextureCache=function(t){this.cache=new src.ArrayMultimap,this.tinted=new Map,this.units=new Map,this.max_size=t||1/0,this.clear()};function createAtlas(t,e,i,r){return void 0===i&&(i="default"),void 0===r&&(r="no-repeat"),{meta:{app:"melonJS",size:{w:t,h:e},repeat:r,image:"default"},frames:[{filename:i,frame:{x:0,y:0,w:t,h:e}}]}}TextureCache.prototype.clear=function(){this.cache.clear(),this.tinted.clear(),this.units.clear(),this.length=0},TextureCache.prototype.validate=function(){if(this.length>=this.max_size)throw new Error("Texture cache overflow: "+this.max_size+" texture units available for this GPU.")},TextureCache.prototype.get=function(t,e){var i;return void 0===e?i=this.cache.get(t)[0]:this.cache.forEach((function(r,o){var n=r.getAtlas();o===t&&n[0].width===e.framewidth&&n[0].height===e.frameheight&&(i=r)})),void 0===i&&(e||(e=createAtlas(t.width,t.height,t.src?getBasename(t.src):void 0)),i=new TextureAtlas(e,t,!1),this.set(t,i)),i},TextureCache.prototype.delete=function(t){this.cache.has(t)||this.cache.delete(t)},TextureCache.prototype.tint=function(t,e){var i=this.tinted.get(t);return void 0===i&&(i=this.tinted.set(t,new Map)),i.has(e)||i.set(e,renderer.tint(t,e,"multiply")),i.get(e)},TextureCache.prototype.set=function(t,e){var i=t.width,r=t.height;if(!(1!==renderer.WebGLVersion||isPowerOfTwo(i)&&isPowerOfTwo(r))){var o=void 0!==t.src?t.src:t;console.warn("[Texture] "+o+" is not a POT texture ("+i+"x"+r+")")}return this.cache.put(t,e)},TextureCache.prototype.getUnit=function(t){return this.units.has(t)||(this.validate(),this.units.set(t,this.length++)),this.units.get(t)};var TextureAtlas=function(t,e,i){var r=this;if(this.format=null,this.sources=new Map,this.atlases=new Map,void 0!==t)for(var o in t=Array.isArray(t)?t:[t]){var n=t[o];if(void 0!==n.meta){if(n.meta.app.includes("texturepacker")||n.meta.app.includes("free-tex-packer")){if(this.format="texturepacker",void 0===e){var s=loader.getImage(n.meta.image);if(!s)throw new Error("Atlas texture '"+s+"' not found");this.sources.set(n.meta.image,s)}else this.sources.set(n.meta.image||"default","string"==typeof e?loader.getImage(e):e);this.repeat="no-repeat"}else if(n.meta.app.includes("ShoeBox")){if(!n.meta.exporter||!n.meta.exporter.includes("melonJS"))throw new Error("ShoeBox requires the JSON exporter : https://github.com/melonjs/melonJS/tree/master/media/shoebox_JSON_export.sbx");this.format="ShoeBox",this.repeat="no-repeat",this.sources.set("default","string"==typeof e?loader.getImage(e):e)}else n.meta.app.includes("melonJS")&&(this.format="melonJS",this.repeat=n.meta.repeat||"no-repeat",this.sources.set("default","string"==typeof e?loader.getImage(e):e));this.atlases.set(n.meta.image||"default",this.parse(n))}else void 0!==n.framewidth&&void 0!==n.frameheight&&(this.format="Spritesheet (fixed cell size)",this.repeat="no-repeat",void 0!==e&&(n.image="string"==typeof e?loader.getImage(e):e),this.atlases.set("default",this.parseFromSpriteSheet(n)),this.sources.set("default",n.image))}if(0===this.atlases.length)throw new Error("texture atlas format not supported");!1!==i&&this.sources.forEach((function(t){i instanceof TextureCache?i.set(t,r):renderer.cache.set(t,r)}))};TextureAtlas.prototype.parse=function(t){var e=this,i={};return t.frames.forEach((function(r){if(r.hasOwnProperty("filename")){var o,n,s=r.frame,a=r.spriteSourceSize&&r.sourceSize&&r.pivot;a&&(o=r.sourceSize.w*r.pivot.x-(r.trimmed?r.spriteSourceSize.x:0),n=r.sourceSize.h*r.pivot.y-(r.trimmed?r.spriteSourceSize.y:0)),i[r.filename]={name:r.filename,texture:t.meta.image||"default",offset:new Vector2d(s.x,s.y),anchorPoint:a?new Vector2d(o/s.w,n/s.h):null,trimmed:!!r.trimmed,width:s.w,height:s.h,angle:!0===r.rotated?-ETA:0},e.addUVs(i,r.filename,t.meta.size.w,t.meta.size.h)}})),i},TextureAtlas.prototype.parseFromSpriteSheet=function(t){var e={},i=t.image,r=t.spacing||0,o=t.margin||0,n=i.width,s=i.height,a=pull("Vector2d",~~((n-o+r)/(t.framewidth+r)),~~((s-o+r)/(t.frameheight+r)));if(n%(t.framewidth+r)!=0||s%(t.frameheight+r)!=0){var h=a.x*(t.framewidth+r),l=a.y*(t.frameheight+r);h-n!==r&&l-s!==r&&(n=h,s=l,console.warn("Spritesheet Texture for image: "+i.src+" is not divisible by "+(t.framewidth+r)+"x"+(t.frameheight+r)+", truncating effective size to "+n+"x"+s))}for(var c=0,u=a.x*a.y;c<u;c++){var d=""+c;e[d]={name:d,texture:"default",offset:new Vector2d(o+(r+t.framewidth)*(c%a.x),o+(r+t.frameheight)*~~(c/a.x)),anchorPoint:t.anchorPoint||null,trimmed:!1,width:t.framewidth,height:t.frameheight,angle:0},this.addUVs(e,d,n,s)}return push(a),e},TextureAtlas.prototype.getAtlas=function(t){return"string"==typeof t?this.atlases.get(t):this.atlases.values().next().value},TextureAtlas.prototype.getFormat=function(){return this.format},TextureAtlas.prototype.getTexture=function(t){return"object"==typeof t&&"string"==typeof t.texture?this.sources.get(t.texture):this.sources.values().next().value},TextureAtlas.prototype.addRegion=function(t,e,i,r,o){!0===renderer.settings.verbose&&console.warn("Adding texture region",t,"for texture",this);var n=this.getTexture(),s=this.getAtlas(),a=n.width,h=n.height;return s[t]={name:t,offset:new Vector2d(e,i),width:r,height:o,angle:0},this.addUVs(s,t,a,h),s[t]},TextureAtlas.prototype.getRegion=function(t,e){var i;return"string"==typeof e?i=this.getAtlas(e)[t]:this.atlases.forEach((function(e){void 0!==e[t]&&(i=e[t])})),i},TextureAtlas.prototype.getUVs=function(t){var e=this.getRegion(t);if(void 0===e){var i=t.split(","),r=+i[0],o=+i[1],n=+i[2],s=+i[3];e=this.addRegion(t,r,o,n,s)}return e.uvs},TextureAtlas.prototype.addUVs=function(t,e,i,r){if(renderer instanceof WebGLRenderer){var o=t[e].offset,n=t[e].width,s=t[e].height;t[e].uvs=new Float32Array([o.x/i,o.y/r,(o.x+n)/i,(o.y+s)/r]),t[o.x+","+o.y+","+i+","+r]=t[e]}return t[e].uvs},TextureAtlas.prototype.createSpriteFromName=function(t,e,i){return void 0===i&&(i=!1),pull(!0===i?"me.NineSliceSprite":"me.Sprite",0,0,Object.assign({image:this,region:t},e||{}))},TextureAtlas.prototype.createAnimationFromName=function(t,e){for(var i,r=[],o={},n=0,s=0,a=0;a<t.length;++a){if(null==(i=this.getRegion(t[a])))throw new Error("Texture - region for "+t[a]+" not found");r[a]=i,o[t[a]]=a,n=Math.max(i.width,n),s=Math.max(i.height,s)}return new Sprite(0,0,Object.assign({image:this,framewidth:n,frameheight:s,margin:0,spacing:0,atlas:r,atlasIndices:o},e||{}))};var Sprite=function(t){function e(e,i,r){if(t.call(this,e,i,0,0),this.animationpause=!1,this.animationspeed=100,this.offset=pull("Vector2d",0,0),this.source=null,this.anim={},this.resetAnim=void 0,this.current={name:"default",length:0,offset:new Vector2d,width:0,height:0,angle:0,idx:0},this.dt=0,this._flicker={isFlickering:!1,duration:0,callback:null,state:!1},r.image instanceof TextureAtlas){if(this.source=r.image,this.image=this.source.getTexture(),this.textureAtlas=r.image,void 0!==r.region){var o=this.source.getRegion(r.region);if(!o)throw new Error("Texture - region for "+r.region+" not found");this.setRegion(o),this.current.width=r.framewidth||o.width,this.current.height=r.frameheight||o.height}}else{if(this.image="object"==typeof r.image?r.image:loader.getImage(r.image),!this.image)throw new Error("me.Sprite: '"+r.image+"' image/texture not found!");this.current.width=r.framewidth=r.framewidth||this.image.width,this.current.height=r.frameheight=r.frameheight||this.image.height,this.source=renderer.cache.get(this.image,r),this.textureAtlas=this.source.getAtlas()}void 0!==r.atlas&&(this.textureAtlas=r.atlas,this.atlasIndices=r.atlasIndices),this.width=this.current.width,this.height=this.current.height,void 0!==r.flipX&&this.flipX(!!r.flipX),void 0!==r.flipY&&this.flipY(!!r.flipY),void 0!==r.rotation&&this.rotate(r.rotation),r.anchorPoint&&this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y),void 0!==r.tint&&this.tint.setColor(r.tint),"string"==typeof r.name&&(this.name=r.name),void 0!==r.z&&(this.pos.z=r.z),0!==this.addAnimation("default",null)&&this.setCurrentAnimation("default"),this.autoTransform=!0}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.isFlickering=function(){return this._flicker.isFlickering},e.prototype.flicker=function(t,e){return this._flicker.duration=t,this._flicker.duration<=0?(this._flicker.isFlickering=!1,this._flicker.callback=null):this._flicker.isFlickering||(this._flicker.callback=e,this._flicker.isFlickering=!0),this},e.prototype.addAnimation=function(t,e,i){this.anim[t]={name:t,frames:[],idx:0,length:0};var r=0;if("object"!=typeof this.textureAtlas)return 0;null==e&&(e=[],Object.keys(this.textureAtlas).forEach((function(t,i){e[i]=i})));for(var o=0,n=e.length;o<n;o++){var s,a=e[o],h=(s="number"==typeof a||"string"==typeof a?{name:a,delay:i||this.animationspeed}:a).name;if("number"==typeof h)void 0!==this.textureAtlas[h]&&(this.anim[t].frames[o]=Object.assign({},this.textureAtlas[h],s),r++);else{if(this.source.getFormat().includes("Spritesheet"))throw new Error("string parameters for addAnimation are not allowed for standard spritesheet based Texture");this.anim[t].frames[o]=Object.assign({},this.textureAtlas[this.atlasIndices[h]],s),r++}}return this.anim[t].length=r,r},e.prototype.setCurrentAnimation=function(t,e,i){if(!this.anim[t])throw new Error("animation id '"+t+"' not defined");return this.current.name=t,this.current.length=this.anim[this.current.name].length,this.resetAnim="string"==typeof e?this.setCurrentAnimation.bind(this,e,null,!0):"function"==typeof e?e:void 0,this.setAnimationFrame(this.current.idx),i||(this.dt=0),this.isDirty=!0,this},e.prototype.reverseAnimation=function(t){return void 0!==t&&void 0!==this.anim[t]?this.anim[t].frames.reverse():this.anim[this.current.name].frames.reverse(),this.isDirty=!0,this},e.prototype.isCurrentAnimation=function(t){return this.current.name===t},e.prototype.setRegion=function(t){return this.image=this.source.getTexture(t),this.current.offset.setV(t.offset),this.current.angle=t.angle,this.width=this.current.width=t.width,this.height=this.current.height=t.height,t.anchorPoint&&this.anchorPoint.set(this._flip.x&&!0===t.trimmed?1-t.anchorPoint.x:t.anchorPoint.x,this._flip.y&&!0===t.trimmed?1-t.anchorPoint.y:t.anchorPoint.y),this.isDirty=!0,this},e.prototype.setAnimationFrame=function(t){return this.current.idx=(t||0)%this.current.length,this.setRegion(this.getAnimationFrameObjectByIndex(this.current.idx))},e.prototype.getCurrentAnimationFrame=function(){return this.current.idx},e.prototype.getAnimationFrameObjectByIndex=function(t){return this.anim[this.current.name].frames[t]},e.prototype.update=function(e){if(!this.animationpause&&this.current&&this.current.length>0){var i=this.getAnimationFrameObjectByIndex(this.current.idx).delay;for(this.dt+=e;this.dt>=i;){this.isDirty=!0,this.dt-=i;var r=this.current.length>1?this.current.idx+1:this.current.idx;if(this.setAnimationFrame(r),0===this.current.idx&&"function"==typeof this.resetAnim&&!1===this.resetAnim()){this.setAnimationFrame(this.current.length-1),this.dt%=i;break}i=this.getAnimationFrameObjectByIndex(this.current.idx).delay}}return this._flicker.isFlickering&&(this._flicker.duration-=e,this._flicker.duration<0&&("function"==typeof this._flicker.callback&&this._flicker.callback(),this.flicker(-1)),this.isDirty=!0),t.prototype.update.call(this,e)},e.prototype.destroy=function(){push(this.offset),this.offset=void 0,t.prototype.destroy.call(this)},e.prototype.draw=function(t){if(!this._flicker.isFlickering||(this._flicker.state=!this._flicker.state,this._flicker.state)){var e=this.current,i=this.pos.x,r=this.pos.y,o=e.width,n=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-r),t.rotate(e.angle),i-=n,o=e.height,n=e.width),t.drawImage(this.image,a.x+s.x,a.y+s.y,o,n,i,r,o,n)}},e}(Renderable),TMX_FLIP_H=2147483648,TMX_FLIP_V=1073741824,TMX_FLIP_AD=536870912,TMX_CLEAR_BIT_MASK$1=536870911,Tile=function(t){function e(e,i,r,o){var n,s;if(t.call(this),o.isCollection){var a=o.getTileImage(r&TMX_CLEAR_BIT_MASK$1);n=a.width,s=a.height}else n=o.tilewidth,s=o.tileheight;this.setMinMax(0,0,n,s),this.tileset=o,this.currentTransform=null,this.col=e,this.row=i,this.tileId=r,this.flippedX=0!=(this.tileId&TMX_FLIP_H),this.flippedY=0!=(this.tileId&TMX_FLIP_V),this.flippedAD=0!=(this.tileId&TMX_FLIP_AD),this.flipped=this.flippedX||this.flippedY||this.flippedAD,!0===this.flipped&&(null===this.currentTransform&&(this.currentTransform=new Matrix2d),this.setTileTransform(this.currentTransform.identity())),this.tileId&=TMX_CLEAR_BIT_MASK$1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setTileTransform=function(t){t.translate(this.width/2,this.height/2),this.flippedAD&&(t.rotate(-90*Math.PI/180),t.scale(-1,1)),this.flippedX&&t.scale(this.flippedAD?1:-1,this.flippedAD?-1:1),this.flippedY&&t.scale(this.flippedAD?-1:1,this.flippedAD?1:-1),t.translate(-this.width/2,-this.height/2)},e.prototype.getRenderable=function(t){var e,i=this.tileset;if(i.animations.has(this.tileId)){var r=[],o=[];i.animations.get(this.tileId).frames.forEach((function(t){o.push(t.tileid),r.push({name:""+t.tileid,delay:t.duration})})),(e=i.texture.createAnimationFromName(o,t)).addAnimation(this.tileId-i.firstgid,r),e.setCurrentAnimation(this.tileId-i.firstgid)}else if(!0===i.isCollection){var n=i.getTileImage(this.tileId);(e=new Sprite(0,0,Object.assign({image:n}))).anchorPoint.set(0,0),e.scale(t.width/this.width,t.height/this.height),void 0!==t.rotation&&(e.anchorPoint.set(.5,.5),e.currentTransform.rotate(t.rotation),e.currentTransform.translate(t.width/2,t.height/2),t.rotation=void 0)}else(e=i.texture.createSpriteFromName(this.tileId-i.firstgid,t)).anchorPoint.set(0,0);return this.setTileTransform(e.currentTransform),e},e}(Bounds$1),Line=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.contains=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),t-=this.pos.x,e-=this.pos.y;var i=this.points[0],r=this.points[1];return(e-i.y)*(r.x-i.x)==(r.y-i.y)*(t-i.x)},e.prototype.recalc=function(){var t=this.edges,e=this.normals,i=this.indices,r=this.points;if(2!==r.length)throw new Error("Requires exactly 2 points");return void 0===t[0]&&(t[0]=new Vector2d),t[0].copy(r[1]).sub(r[0]),void 0===e[0]&&(e[0]=new Vector2d),e[0].copy(t[0]).perp().normalize(),i.length=0,this},e.prototype.clone=function(){var t=[];return this.points.forEach((function(e){t.push(e.clone())})),new e(this.pos.x,this.pos.y,t)},e}(Polygon),Renderer=function(t){this.settings=t,this.isContextValid=!0,this.currentScissor=new Int32Array([0,0,this.settings.width,this.settings.height]),this.currentBlendMode="none",!0===device$1.ejecta?this.canvas=document.getElementById("canvas"):void 0!==globalThis.canvas?this.canvas=globalThis.canvas:void 0!==this.settings.canvas?this.canvas=this.settings.canvas:this.canvas=createCanvas(this.settings.zoomX,this.settings.zoomY),this.backBufferCanvas=this.canvas,this.context=null,this.currentColor=new Color(0,0,0,1),this.currentTint=new Color(255,255,255,1),this.projectionMatrix=new Matrix3d,this.uvOffset=0,on(GAME_RESET,(function(){renderer.reset()}))};Renderer.prototype.clear=function(){},Renderer.prototype.reset=function(){this.resetTransform(),this.setBlendMode(this.settings.blendMode),this.setColor("#000000"),this.clearTint(),this.cache.clear(),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},Renderer.prototype.getCanvas=function(){return this.backBufferCanvas},Renderer.prototype.getScreenCanvas=function(){return this.canvas},Renderer.prototype.getScreenContext=function(){return this.context},Renderer.prototype.getBlendMode=function(){return this.currentBlendMode},Renderer.prototype.getContext2d=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a 2d context");if(void 0===t.getContext)throw new Error("Your browser does not support HTML5 canvas.");"boolean"!=typeof e&&(e=!0);var i=t.getContext("2d",{alpha:e});return i.canvas||(i.canvas=t),this.setAntiAlias(i,this.settings.antiAlias),i},Renderer.prototype.getWidth=function(){return this.backBufferCanvas.width},Renderer.prototype.getHeight=function(){return this.backBufferCanvas.height},Renderer.prototype.getColor=function(){return this.currentColor},Renderer.prototype.globalAlpha=function(){return this.currentColor.glArray[3]},Renderer.prototype.overlaps=function(t){return t.left<=this.getWidth()&&t.right>=0&&t.top<=this.getHeight()&&t.bottom>=0},Renderer.prototype.resize=function(t,e){t===this.backBufferCanvas.width&&e===this.backBufferCanvas.height||(this.canvas.width=this.backBufferCanvas.width=t,this.canvas.height=this.backBufferCanvas.height=e,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=t,this.currentScissor[3]=e,emit(CANVAS_ONRESIZE,t,e))},Renderer.prototype.setAntiAlias=function(t,e){var i=t.canvas;setPrefixed("imageSmoothingEnabled",!0===e,t),!0!==e?(i.style["image-rendering"]="optimizeSpeed",i.style["image-rendering"]="-moz-crisp-edges",i.style["image-rendering"]="-o-crisp-edges",i.style["image-rendering"]="-webkit-optimize-contrast",i.style["image-rendering"]="optimize-contrast",i.style["image-rendering"]="crisp-edges",i.style["image-rendering"]="pixelated",i.style.msInterpolationMode="nearest-neighbor"):i.style["image-rendering"]="auto"},Renderer.prototype.setProjection=function(t){this.projectionMatrix.copy(t)},Renderer.prototype.stroke=function(t,e){t instanceof Rect||t instanceof Bounds$1?this.strokeRect(t.left,t.top,t.width,t.height,e):t instanceof Line||t instanceof Polygon?this.strokePolygon(t,e):t instanceof Ellipse&&this.strokeEllipse(t.pos.x,t.pos.y,t.radiusV.x,t.radiusV.y,e)},Renderer.prototype.tint=function(t,e,i){var r=createCanvas(t.width,t.height,!0),o=this.getContext2d(r);return o.save(),o.fillStyle=e instanceof Color?e.toRGB():e,o.fillRect(0,0,t.width,t.height),o.globalCompositeOperation=i||"multiply",o.drawImage(t,0,0),o.globalCompositeOperation="destination-atop",o.drawImage(t,0,0),o.restore(),r},Renderer.prototype.fill=function(t){this.stroke(t,!0)},Renderer.prototype.setMask=function(t){},Renderer.prototype.clearMask=function(){},Renderer.prototype.setTint=function(t,e){void 0===e&&(e=t.alpha),this.currentTint.copy(t),this.currentTint.alpha*=e},Renderer.prototype.clearTint=function(){this.currentTint.setColor(255,255,255,1)},Renderer.prototype.drawFont=function(){};var CanvasRenderer=function(t){function e(e){var i=this;t.call(this,e),this.context=this.getContext2d(this.getScreenCanvas(),this.settings.transparent),this.settings.doubleBuffering?(this.backBufferCanvas=createCanvas(this.settings.width,this.settings.height,!0),this.backBufferContext2D=this.getContext2d(this.backBufferCanvas)):(this.backBufferCanvas=this.getScreenCanvas(),this.backBufferContext2D=this.context),this.setBlendMode(this.settings.blendMode),this.setColor(this.currentColor),this.cache=new TextureCache,!1===this.settings.textureSeamFix||this.settings.antiAlias||(this.uvOffset=1),this.getScreenCanvas().addEventListener("contextlost",(function(t){t.preventDefault(),i.isContextValid=!1,event.emit(event.ONCONTEXT_LOST,i)}),!1),this.getScreenCanvas().addEventListener("contextrestored",(function(){i.isContextValid=!0,event.emit(event.ONCONTEXT_RESTORED,i)}),!1)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){t.prototype.reset.call(this),this.clearColor(this.currentColor,!0!==this.settings.transparent)},e.prototype.resetTransform=function(){this.backBufferContext2D.setTransform(1,0,0,1,0,0)},e.prototype.setBlendMode=function(t,e){switch(void 0===t&&(t="normal"),e=e||this.getContext(),this.currentBlendMode=t,t){case"screen":e.globalCompositeOperation="screen";break;case"lighter":case"additive":e.globalCompositeOperation="lighter";break;case"multiply":e.globalCompositeOperation="multiply";break;default:e.globalCompositeOperation="source-over",this.currentBlendMode="normal"}this.settings.doubleBuffering&&this.settings.transparent&&(this.context.globalCompositeOperation="copy")},e.prototype.clear=function(){this.settings.transparent&&this.clearColor("rgba(0,0,0,0)",!0)},e.prototype.flush=function(){this.settings.doubleBuffering&&this.context.drawImage(this.backBufferCanvas,0,0)},e.prototype.clearColor=function(t,e){void 0===t&&(t="#000000"),this.save(),this.resetTransform(),this.backBufferContext2D.globalCompositeOperation=e?"copy":"source-over",this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t,this.fillRect(0,0,this.backBufferCanvas.width,this.backBufferCanvas.height),this.restore()},e.prototype.clearRect=function(t,e,i,r){this.backBufferContext2D.clearRect(t,e,i,r)},e.prototype.createPattern=function(t,e){return this.backBufferContext2D.createPattern(t,e)},e.prototype.drawImage=function(t,e,i,r,o,n,s,a,h){if(!(this.backBufferContext2D.globalAlpha<1/255)){void 0===r?(r=a=t.width,o=h=t.height,n=e,s=i,e=0,i=0):void 0===n&&(n=e,s=i,a=r,h=o,r=t.width,o=t.height,e=0,i=0),!1===this.settings.subPixel&&(n=~~n,s=~~s);var l=t,c=this.currentTint.toArray();1===c[0]&&1===c[1]&&1===c[2]||(l=this.cache.tint(t,this.currentTint.toRGB())),this.backBufferContext2D.drawImage(l,e,i,r,o,n,s,a,h)}},e.prototype.drawPattern=function(t,e,i,r,o){if(!(this.backBufferContext2D.globalAlpha<1/255)){var n=this.backBufferContext2D.fillStyle;this.backBufferContext2D.fillStyle=t,this.backBufferContext2D.fillRect(e,i,r,o),this.backBufferContext2D.fillStyle=n}},e.prototype.strokeArc=function(t,e,i,r,o,n,s){void 0===s&&(s=!1);var a=this.backBufferContext2D;a.globalAlpha<1/255||(a.translate(t,e),a.beginPath(),a.arc(0,0,i,r,o,n||!1),a[!0===s?"fill":"stroke"](),a.translate(-t,-e))},e.prototype.fillArc=function(t,e,i,r,o,n){this.strokeArc(t,e,i,r,o,n||!1,!0)},e.prototype.strokeEllipse=function(t,e,i,r,o){void 0===o&&(o=!1);var n=this.backBufferContext2D;if(!(n.globalAlpha<1/255)){var s=t-i,a=t+i,h=e-r,l=e+r,c=.551784*i,u=.551784*r,d=t-c,p=t+c,f=e-u,y=e+u;n.beginPath(),n.moveTo(t,h),n.bezierCurveTo(p,h,a,f,a,e),n.bezierCurveTo(a,y,p,l,t,l),n.bezierCurveTo(d,l,s,y,s,e),n.bezierCurveTo(s,f,d,h,t,h),n[!0===o?"fill":"stroke"](),n.closePath()}},e.prototype.fillEllipse=function(t,e,i,r){this.strokeEllipse(t,e,i,r,!0)},e.prototype.strokeLine=function(t,e,i,r){var o=this.backBufferContext2D;o<1/255||(o.beginPath(),o.moveTo(t,e),o.lineTo(i,r),o.stroke())},e.prototype.fillLine=function(t,e,i,r){this.strokeLine(t,e,i,r)},e.prototype.strokePolygon=function(t,e){void 0===e&&(e=!1);var i=this.backBufferContext2D;if(!(i.globalAlpha<1/255)){var r;this.translate(t.pos.x,t.pos.y),i.beginPath(),i.moveTo(t.points[0].x,t.points[0].y);for(var o=1;o<t.points.length;o++)r=t.points[o],i.lineTo(r.x,r.y);i.lineTo(t.points[0].x,t.points[0].y),i[!0===e?"fill":"stroke"](),i.closePath(),this.translate(-t.pos.x,-t.pos.y)}},e.prototype.fillPolygon=function(t){this.strokePolygon(t,!0)},e.prototype.strokeRect=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillRect(t,e,i,r);else{if(this.backBufferContext2D.globalAlpha<1/255)return;this.backBufferContext2D.strokeRect(t,e,i,r)}},e.prototype.fillRect=function(t,e,i,r){this.backBufferContext2D.globalAlpha<1/255||this.backBufferContext2D.fillRect(t,e,i,r)},e.prototype.getContext=function(){return this.backBufferContext2D},e.prototype.getFontContext=function(){return this.getContext()},e.prototype.save=function(){this.backBufferContext2D.save()},e.prototype.restore=function(){this.backBufferContext2D.restore(),this.currentColor.glArray[3]=this.backBufferContext2D.globalAlpha,this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height},e.prototype.rotate=function(t){this.backBufferContext2D.rotate(t)},e.prototype.scale=function(t,e){this.backBufferContext2D.scale(t,e)},e.prototype.setColor=function(t){this.backBufferContext2D.strokeStyle=this.backBufferContext2D.fillStyle=t instanceof Color?t.toRGBA():t},e.prototype.setGlobalAlpha=function(t){this.backBufferContext2D.globalAlpha=this.currentColor.glArray[3]=t},e.prototype.setLineWidth=function(t){this.backBufferContext2D.lineWidth=t},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=t.toArray(),i=e[0],r=e[1],o=e[3],n=e[4],s=e[6],a=e[7];!1===this.settings.subPixel&&(s|=0,a|=0),this.backBufferContext2D.transform(i,r,o,n,s,a)},e.prototype.translate=function(t,e){!1===this.settings.subPixel?this.backBufferContext2D.translate(~~t,~~e):this.backBufferContext2D.translate(t,e)},e.prototype.clipRect=function(t,e,i,r){var o=this.backBufferCanvas;if(0!==t||0!==e||i!==o.width||r!==o.height){var n=this.currentScissor;if(n[0]!==t||n[1]!==e||n[2]!==i||n[3]!==r){var s=this.backBufferContext2D;s.beginPath(),s.rect(t,e,i,r),s.clip(),n[0]=t,n[1]=e,n[2]=i,n[3]=r}}},e.prototype.setMask=function(t){var e=this.backBufferContext2D,i=t.pos.x,r=t.pos.y;if(e.save(),t instanceof Ellipse){var o=t.radiusV.x,n=t.radiusV.y,s=i-o,a=i+o,h=r-n,l=r+n,c=.551784*o,u=.551784*n,d=i-c,p=i+c,f=r-u,y=r+u;e.beginPath(),e.moveTo(i,h),e.bezierCurveTo(p,h,a,f,a,r),e.bezierCurveTo(a,y,p,l,i,l),e.bezierCurveTo(d,l,s,y,s,r),e.bezierCurveTo(s,f,d,h,i,h)}else{var g;e.beginPath(),e.moveTo(i+t.points[0].x,r+t.points[0].y);for(var v=1;v<t.points.length;v++)g=t.points[v],e.lineTo(i+g.x,r+g.y)}e.clip()},e.prototype.clearMask=function(){this.backBufferContext2D.restore()},e}(Renderer);function initArray(t){t.layerData=new Array(t.cols);for(var e=0;e<t.cols;e++){t.layerData[e]=new Array(t.rows);for(var i=0;i<t.rows;i++)t.layerData[e][i]=null}}function setLayerData(t,e){var i=0;initArray(t);for(var r=0;r<t.rows;r++)for(var o=0;o<t.cols;o++){var n=e[i++];0!==n&&(t.layerData[o][r]=t.getTileById(n,o,r))}}function preRenderLayer(t,e){for(var i=0;i<t.rows;i++)for(var r=0;r<t.cols;r++){var o=t.layerData[r][i];o instanceof Tile&&t.getRenderer().drawTile(e,r,i,o)}}var TMXLayer=function(t){function e(e,i,r,o,n,s,a){t.call(this,0,0,0,0),this.tilewidth=i.tilewidth||r,this.tileheight=i.tileheight||o,this.orientation=n,this.tilesets=s,this.tileset=this.tilesets?this.tilesets.getTilesetByIndex(0):null,this.maxTileSize={width:0,height:0};for(var h=0;h<this.tilesets.length;h++){var l=this.tilesets.getTilesetByIndex(h);this.maxTileSize.width=Math.max(this.maxTileSize.width,l.tilewidth),this.maxTileSize.height=Math.max(this.maxTileSize.height,l.tileheight)}this.animatedTilesets=[],this.isAnimated=!1,this.renderorder=i.renderorder||"right-down",this.pos.z=a,this.anchorPoint.set(0,0),this.name=i.name,this.cols=+i.width,this.rows=+i.height;var c=void 0!==i.visible?+i.visible:1;this.setOpacity(c?+i.opacity:0),"string"==typeof i.tintcolor&&this.tint.parseHex(i.tintcolor,!0),"isometric"===this.orientation?(this.width=(this.cols+this.rows)*(this.tilewidth/2),this.height=(this.cols+this.rows)*(this.tileheight/2)):(this.width=this.cols*this.tilewidth,this.height=this.rows*this.tileheight),applyTMXProperties(this,i),void 0===this.preRender&&(this.preRender=world.preRender),this.setRenderer(e.getRenderer()),setLayerData(this,decode(i.data,i.encoding,i.compression))}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onActivateEvent=function(){if(void 0===this.animatedTilesets&&(this.animatedTilesets=[]),this.tilesets)for(var t=this.tilesets.tilesets,e=0;e<t.length;e++)t[e].isAnimated&&this.animatedTilesets.push(t[e]);this.isAnimated=this.animatedTilesets.length>0,this.isAnimated&&(this.preRender=!1),this.getBounds().addBounds(this.getRenderer().getBounds(),!0),this.getBounds().shift(this.pos),!0!==this.preRender||this.canvasRenderer||(this.canvasRenderer=new CanvasRenderer({canvas:createCanvas(this.width,this.height),widht:this.width,heigth:this.height,transparent:!0}),preRenderLayer(this,this.canvasRenderer))},e.prototype.onDeactivateEvent=function(){this.animatedTilesets=void 0},e.prototype.setRenderer=function(t){this.renderer=t},e.prototype.getRenderer=function(){return this.renderer},e.prototype.getTileId=function(t,e){var i=this.getTile(t,e);return i?i.tileId:null},e.prototype.getTile=function(t,e){var i=null;if(this.contains(t,e)){var r=this.getRenderer().pixelToTileCoords(t,e,pull("Vector2d"));i=this.cellAt(r.x,r.y),push(r)}return i},e.prototype.setTile=function(t,e,i){return this.layerData[e][i]=t,t},e.prototype.getTileById=function(t,e,i){return this.tileset.contains(t)||(this.tileset=this.tilesets.getTilesetByGid(t)),new Tile(e,i,t,this.tileset)},e.prototype.cellAt=function(t,e,i){var r=~~t,o=~~e,n=this.getRenderer();return!1===i||r>=0&&r<n.cols&&o>=0&&o<n.rows?this.layerData[r][o]:null},e.prototype.clearTile=function(t,e){this.layerData[t][e]=null,this.preRender&&this.canvasRenderer.clearRect(t*this.tilewidth,e*this.tileheight,this.tilewidth,this.tileheight)},e.prototype.update=function(t){if(this.isAnimated){for(var e=!1,i=0;i<this.animatedTilesets.length;i++)e=this.animatedTilesets[i].update(t)||e;return e}return!1},e.prototype.draw=function(t,e){if(this.preRender){var i=Math.min(e.width,this.width),r=Math.min(e.height,this.height);t.drawImage(this.canvasRenderer.getCanvas(),e.pos.x,e.pos.y,i,r,e.pos.x,e.pos.y,i,r)}else this.getRenderer().drawTileLayer(t,this,e)},e}(Renderable),Bounds=function(t){this.onResetEvent(t)},prototypeAccessors={x:{configurable:!0},y:{configurable:!0},width:{configurable:!0},height:{configurable:!0},left:{configurable:!0},right:{configurable:!0},top:{configurable:!0},bottom:{configurable:!0},centerX:{configurable:!0},centerY:{configurable:!0},center:{configurable:!0}};Bounds.prototype.onResetEvent=function(t){void 0===this.min?(this.min={x:1/0,y:1/0},this.max={x:-1/0,y:-1/0}):this.clear(),void 0!==t&&this.update(t),this._center=new Vector2d},Bounds.prototype.clear=function(){this.setMinMax(1/0,1/0,-1/0,-1/0)},Bounds.prototype.setMinMax=function(t,e,i,r){this.min.x=t,this.min.y=e,this.max.x=i,this.max.y=r},prototypeAccessors.x.get=function(){return this.min.x},prototypeAccessors.x.set=function(t){var e=this.max.x-this.min.x;this.min.x=t,this.max.x=t+e},prototypeAccessors.y.get=function(){return this.min.y},prototypeAccessors.y.set=function(t){var e=this.max.y-this.min.y;this.min.y=t,this.max.y=t+e},prototypeAccessors.width.get=function(){return this.max.x-this.min.x},prototypeAccessors.width.set=function(t){this.max.x=this.min.x+t},prototypeAccessors.height.get=function(){return this.max.y-this.min.y},prototypeAccessors.height.set=function(t){this.max.y=this.min.y+t},prototypeAccessors.left.get=function(){return this.min.x},prototypeAccessors.right.get=function(){return this.max.x},prototypeAccessors.top.get=function(){return this.min.y},prototypeAccessors.bottom.get=function(){return this.max.y},prototypeAccessors.centerX.get=function(){return this.min.x+this.width/2},prototypeAccessors.centerY.get=function(){return this.min.y+this.height/2},prototypeAccessors.center.get=function(){return this._center.set(this.centerX,this.centerY)},Bounds.prototype.update=function(t){this.add(t,!0)},Bounds.prototype.add=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear();for(var i=0;i<t.length;i++){var r=t[i];r.x>this.max.x&&(this.max.x=r.x),r.x<this.min.x&&(this.min.x=r.x),r.y>this.max.y&&(this.max.y=r.y),r.y<this.min.y&&(this.min.y=r.y)}},Bounds.prototype.addBounds=function(t,e){void 0===e&&(e=!1),!0===e&&this.clear(),t.max.x>this.max.x&&(this.max.x=t.max.x),t.min.x<this.min.x&&(this.min.x=t.min.x),t.max.y>this.max.y&&(this.max.y=t.max.y),t.min.y<this.min.y&&(this.min.y=t.min.y)},Bounds.prototype.addPoint=function(t,e){void 0!==e&&(t=e.apply(t)),this.min.x=Math.min(this.min.x,t.x),this.max.x=Math.max(this.max.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.max.y=Math.max(this.max.y,t.y)},Bounds.prototype.addFrame=function(t,e,i,r,o){var n=me.pool.pull("Vector2d");this.addPoint(n.set(t,e),o),this.addPoint(n.set(i,e),o),this.addPoint(n.set(t,r),o),this.addPoint(n.set(i,r),o),me.pool.push(n)},Bounds.prototype.contains=function(){var t,e,i,r,o=arguments[0];return 2===arguments.length?(t=e=o,i=r=arguments[1]):o instanceof Bounds?(t=o.min.x,e=o.max.x,i=o.min.y,r=o.max.y):(t=e=o.x,i=r=o.y),t>=this.min.x&&e<=this.max.x&&i>=this.min.y&&r<=this.max.y},Bounds.prototype.overlaps=function(t){return!(this.right<t.left||this.left>t.right||this.bottom<t.top||this.top>t.bottom)},Bounds.prototype.isFinite=function(){return isFinite(this.min.x)&&isFinite(this.max.x)&&isFinite(this.min.y)&&isFinite(this.max.y)},Bounds.prototype.translate=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y),this.min.x+=t,this.max.x+=t,this.min.y+=e,this.max.y+=e},Bounds.prototype.shift=function(){var t,e;2===arguments.length?(t=arguments[0],e=arguments[1]):(t=arguments[0].x,e=arguments[0].y);var i=this.max.x-this.min.x,r=this.max.y-this.min.y;this.min.x=t,this.max.x=t+i,this.min.y=e,this.max.y=e+r},Bounds.prototype.clone=function(){var t=new Bounds;return t.addBounds(this),t},Bounds.prototype.toPolygon=function(){return new Polygon(this.x,this.y,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])},Object.defineProperties(Bounds.prototype,prototypeAccessors);var TMXRenderer=function(t,e,i,r){this.cols=t,this.rows=e,this.tilewidth=i,this.tileheight=r,this.bounds=new Bounds};TMXRenderer.prototype.canRender=function(t){return this.tilewidth===t.tilewidth&&this.tileheight===t.tileheight},TMXRenderer.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return e.setMinMax(0,0,this.cols*this.tilewidth,this.rows*this.tileheight),e},TMXRenderer.prototype.pixelToTileCoords=function(t,e,i){return i},TMXRenderer.prototype.tileToPixelCoords=function(t,e,i){return i},TMXRenderer.prototype.drawTile=function(t,e,i,r){},TMXRenderer.prototype.drawTileLayer=function(t,e,i){};var TMXOrthogonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"orthogonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(t/this.tilewidth,e/this.tileheight)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set(t*this.tilewidth,e*this.tileheight)},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset;o.drawTile(t,o.tileoffset.x+e*this.tilewidth,o.tileoffset.y+(i+1)*this.tileheight-o.tileheight,r)},e.prototype.drawTileLayer=function(t,e,i){var r=1,o=1,n=this.pixelToTileCoords(Math.max(i.pos.x-(e.maxTileSize.width-e.tilewidth),0),Math.max(i.pos.y-(e.maxTileSize.height-e.tileheight),0),pull("Vector2d")).floorSelf(),s=this.pixelToTileCoords(i.pos.x+i.width+this.tilewidth,i.pos.y+i.height+this.tileheight,pull("Vector2d")).ceilSelf();switch(s.x=s.x>this.cols?this.cols:s.x,s.y=s.y>this.rows?this.rows:s.y,e.renderorder){case"right-up":s.y=n.y+(n.y=s.y)-s.y,o=-1;break;case"left-down":s.x=n.x+(n.x=s.x)-s.x,r=-1;break;case"left-up":s.x=n.x+(n.x=s.x)-s.x,s.y=n.y+(n.y=s.y)-s.y,r=-1,o=-1}for(var a=n.y;a!==s.y;a+=o)for(var h=n.x;h!==s.x;h+=r){var l=e.cellAt(h,a,!1);l&&this.drawTile(t,h,a,l)}push(n),push(s)},e}(TMXRenderer),TMXIsometricRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,e.tilewidth,e.tileheight),this.hTilewidth=this.tilewidth/2,this.hTileheight=this.tileheight/2,this.originX=this.rows*this.hTilewidth}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"isometric"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return e.setMinMax(0,0,(this.cols+this.rows)*(this.tilewidth/2),(this.cols+this.rows)*(this.tileheight/2)),e},e.prototype.pixelToTileCoords=function(t,e,i){return(i||new Vector2d).set(e/this.tileheight+(t-this.originX)/this.tilewidth,e/this.tileheight-(t-this.originX)/this.tilewidth)},e.prototype.tileToPixelCoords=function(t,e,i){return(i||new Vector2d).set((t-e)*this.hTilewidth+this.originX,(t+e)*this.hTileheight)},e.prototype.adjustPosition=function(t){var e=t.x/this.hTilewidth,i=t.y/this.tileheight,r=pull("Vector2d");this.tileToPixelCoords(e,i,r),t.x=r.x,t.y=r.y,push(r)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset;o.drawTile(t,(this.cols-1)*o.tilewidth+(e-i)*o.tilewidth>>1,-o.tilewidth+(e+i)*o.tileheight>>2,r)},e.prototype.drawTileLayer=function(t,e,i){var r=e.tileset,o=this.pixelToTileCoords(i.pos.x-r.tilewidth,i.pos.y-r.tileheight,pull("Vector2d")).floorSelf(),n=this.pixelToTileCoords(i.pos.x+i.width+r.tilewidth,i.pos.y+i.height+r.tileheight,pull("Vector2d")).ceilSelf(),s=this.tileToPixelCoords(n.x,n.y,pull("Vector2d")),a=this.tileToPixelCoords(o.x,o.y,pull("Vector2d"));a.x-=this.hTilewidth,a.y+=this.tileheight;var h=a.y-i.pos.y>this.hTileheight,l=i.pos.x-a.x<this.hTilewidth;h&&(l?(o.x--,a.x-=this.hTilewidth):(o.y--,a.x+=this.hTilewidth),a.y-=this.hTileheight);for(var c=h^l,u=o.clone(),d=2*a.y;d-2*this.tileheight<2*s.y;d+=this.tileheight){u.setV(o);for(var p=a.x;p<s.x;p+=this.tilewidth){var f=e.cellAt(u.x,u.y);if(f){var y=(r=f.tileset).tileoffset;r.drawTile(t,y.x+p,y.y+d/2-r.tileheight,f)}u.x++,u.y--}c?(o.y++,a.x-=this.hTilewidth,c=!1):(o.x++,a.x+=this.hTilewidth,c=!0)}push(u),push(o),push(n),push(s),push(a)},e}(TMXRenderer),offsetsStaggerX=[{x:0,y:0},{x:1,y:-1},{x:1,y:0},{x:2,y:0}],offsetsStaggerY=[{x:0,y:0},{x:-1,y:1},{x:0,y:1},{x:0,y:2}],TMXHexagonalRenderer=function(t){function e(e){t.call(this,e.cols,e.rows,-2&e.tilewidth,-2&e.tileheight),this.hexsidelength=e.hexsidelength||0,this.staggerX="x"===e.staggeraxis,this.staggerEven="even"===e.staggerindex,this.sidelengthx=0,this.sidelengthy=0,"hexagonal"===e.orientation&&(this.staggerX?this.sidelengthx=this.hexsidelength:this.sidelengthy=this.hexsidelength),this.sideoffsetx=(this.tilewidth-this.sidelengthx)/2,this.sideoffsety=(this.tileheight-this.sidelengthy)/2,this.columnwidth=this.sideoffsetx+this.sidelengthx,this.rowheight=this.sideoffsety+this.sidelengthy,this.centers=[new Vector2d,new Vector2d,new Vector2d,new Vector2d]}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"hexagonal"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.getBounds=function(t){var e=t instanceof TMXLayer?pull("Bounds"):this.bounds;return this.staggerX?(e.setMinMax(0,0,this.cols*this.columnwidth+this.sideoffsetx,this.rows*(this.tileheight+this.sidelengthy)),e.width>1&&(e.height+=this.rowheight)):(e.setMinMax(0,0,this.cols*(this.tilewidth+this.sidelengthx),this.rows*this.rowheight+this.sideoffsety),e.height>1&&(e.width+=this.columnwidth)),e},e.prototype.doStaggerX=function(t){return this.staggerX&&1&t^this.staggerEven},e.prototype.doStaggerY=function(t){return!this.staggerX&&1&t^this.staggerEven},e.prototype.topLeft=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t-1,e):r.set(t-1,e-1):1&e^this.staggerEven?r.set(t,e-1):r.set(t-1,e-1),r},e.prototype.topRight=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t+1,e):r.set(t+1,e-1):1&e^this.staggerEven?r.set(t+1,e-1):r.set(t,e-1),r},e.prototype.bottomLeft=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t-1,e+1):r.set(t-1,e):1&e^this.staggerEven?r.set(t,e+1):r.set(t-1,e+1),r},e.prototype.bottomRight=function(t,e,i){var r=i||new Vector2d;return this.staggerX?1&t^this.staggerEven?r.set(t+1,e+1):r.set(t+1,e):1&e^this.staggerEven?r.set(t+1,e+1):r.set(t,e+1),r},e.prototype.pixelToTileCoords=function(t,e,i){var r=i||new Vector2d;this.staggerX?t-=this.staggerEven?this.tilewidth:this.sideoffsetx:e-=this.staggerEven?this.tileheight:this.sideoffsety;var o,n,s,a,h=pull("Vector2d",Math.floor(t/(2*this.columnwidth)),Math.floor(e/(2*this.rowheight))),l=pull("Vector2d",t-h.x*(2*this.columnwidth),e-h.y*(2*this.rowheight));this.staggerX?(h.x=2*h.x,this.staggerEven&&++h.x):(h.y=2*h.y,this.staggerEven&&++h.y),this.staggerX?(s=(o=this.sidelengthx/2)+this.columnwidth,a=this.tileheight/2,this.centers[0].set(o,a),this.centers[1].set(s,a-this.rowheight),this.centers[2].set(s,a+this.rowheight),this.centers[3].set(s+this.columnwidth,a)):(n=this.sidelengthy/2,s=this.tilewidth/2,a=n+this.rowheight,this.centers[0].set(s,n),this.centers[1].set(s-this.columnwidth,a),this.centers[2].set(s+this.columnwidth,a),this.centers[3].set(s,a+this.rowheight));for(var c=0,u=Number.MAX_VALUE,d=0;d<4;++d){var p=this.centers[d].sub(l).length2();p<u&&(u=p,c=d)}var f=this.staggerX?offsetsStaggerX:offsetsStaggerY;return r.set(h.x+f[c].x,h.y+f[c].y),push(h),push(l),r},e.prototype.tileToPixelCoords=function(t,e,i){var r=Math.floor(t),o=Math.floor(e),n=i||new Vector2d;return this.staggerX?(n.y=o*(this.tileheight+this.sidelengthy),this.doStaggerX(r)&&(n.y+=this.rowheight),n.x=r*this.columnwidth):(n.x=r*(this.tilewidth+this.sidelengthx),this.doStaggerY(o)&&(n.x+=this.columnwidth),n.y=o*this.rowheight),n},e.prototype.adjustPosition=function(t){"number"==typeof t.gid&&(t.y-=t.height)},e.prototype.drawTile=function(t,e,i,r){var o=r.tileset,n=this.tileToPixelCoords(e,i,pull("Vector2d"));o.drawTile(t,o.tileoffset.x+n.x,o.tileoffset.y+n.y+(this.tileheight-o.tileheight),r),push(n)},e.prototype.drawTileLayer=function(t,e,i){var r,o=this.pixelToTileCoords(i.pos.x,i.pos.y,pull("Vector2d"));o.sub(e.pos);var n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y,pull("Vector2d")),s=o.clone(),a=n.clone(),h=i.pos.y-n.y<this.sideoffsety,l=i.pos.x-n.x<this.sideoffsetx;h&&o.y--,l&&o.x--;var c=e.cols,u=e.rows;if(this.staggerX){o.x=Math.max(0,o.x),o.y=Math.max(0,o.y),n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y);for(var d=this.doStaggerX(o.x+e.pos.x);n.y<i.bottom&&o.y<u;){for(s.setV(o),a.setV(n);a.x<i.right&&s.x<c;s.x+=2)(r=e.cellAt(s.x,s.y,!1))&&r.tileset.drawTile(t,a.x,a.y,r),a.x+=this.tilewidth+this.sidelengthx;d?(o.x-=1,o.y+=1,n.x-=this.columnwidth,d=!1):(o.x+=1,n.x+=this.columnwidth,d=!0),n.y+=this.rowheight}push(s),push(a)}else{for(o.x=Math.max(0,o.x),o.y=Math.max(0,o.y),n=this.tileToPixelCoords(o.x+e.pos.x,o.y+e.pos.y),this.doStaggerY(o.y)&&(n.x-=this.columnwidth);n.y<i.bottom&&o.y<u;o.y++){for(s.setV(o),a.setV(n),this.doStaggerY(o.y)&&(a.x+=this.columnwidth);a.x<i.right&&s.x<c;s.x++)(r=e.cellAt(s.x,s.y,!1))&&r.tileset.drawTile(t,a.x,a.y,r),a.x+=this.tilewidth+this.sidelengthx;n.y+=this.rowheight}push(s),push(a)}push(o),push(n)},e}(TMXRenderer),TMXStaggeredRenderer=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.canRender=function(e){return"staggered"===e.orientation&&t.prototype.canRender.call(this,e)},e.prototype.pixelToTileCoords=function(t,e,i){var r=i||new Vector2d,o=t,n=e;this.staggerX?o-=this.staggerEven?this.sideoffsetx:0:n-=this.staggerEven?this.sideoffsety:0;var s=pull("Vector2d",Math.floor(o/this.tilewidth),Math.floor(n/this.tileheight));this.staggerX?(s.x=2*s.x,this.staggerEven&&++s.x):(s.y=2*s.y,this.staggerEven&&++s.y);var a=pull("Vector2d",o-s.x*this.tilewidth,n-s.y*this.tileheight),h=a.x*(this.tileheight/this.tilewidth);return this.sideoffsety-h>a.y&&(s=this.topLeft(s.x,s.y,s)),-this.sideoffsety+h>a.y&&(s=this.topRight(s.x,s.y,s)),this.sideoffsety+h<a.y&&(s=this.bottomLeft(s.x,s.y,s)),3*this.sideoffsety-h<a.y&&(s=this.bottomRight(s.x,s.y,s)),(r=this.tileToPixelCoords(s.x,s.y,r)).set(t-r.x,e-r.y),r.set(r.x-this.tilewidth/2,r.y*(this.tilewidth/this.tileheight)),r.div(this.tilewidth/Math.sqrt(2)).rotate(degToRad(-45)).add(s),push(s),push(a),r},e}(TMXHexagonalRenderer),TMXTileset=function(t){var e=0;if(this.TileProperties=[],this.imageCollection=[],this.firstgid=this.lastgid=+t.firstgid,void 0!==t.source){var i=t.source,r=getExtension(i);if(("tsx"===r||"json"===r)&&!(t=loader.getTMX(getBasename(i))))throw new Error(i+" external TSX/JSON tileset not found")}this.name=t.name,this.tilewidth=+t.tilewidth,this.tileheight=+t.tileheight,this.spacing=+t.spacing||0,this.margin=+t.margin||0,this.tileoffset=new Vector2d,this.isAnimated=!1,this.isCollection=!1,this.animations=new Map,this._lastUpdate=0;var o=t.tiles;for(e in o)if(o.hasOwnProperty(e)){if("animation"in o[e]&&(this.isAnimated=!0,this.animations.set(o[+e].animation[0].tileid,{dt:0,idx:0,frames:o[+e].animation,cur:o[+e].animation[0]})),"properties"in o[e])if(Array.isArray(o[e].properties)){var n={};for(var s in o[e].properties)n[o[e].properties[s].name]=o[e].properties[s].value;this.setTileProperty(+o[e].id+this.firstgid,n)}else this.setTileProperty(+e+this.firstgid,o[e].properties);if("image"in o[e]){var a=loader.getImage(o[e].image);if(!a)throw new Error("melonJS: '"+o[e].image+"' file for tile '"+(+e+this.firstgid)+"' not found!");this.imageCollection[+e+this.firstgid]=a}}this.isCollection=this.imageCollection.length>0;var h=t.tileoffset;h&&(this.tileoffset.x=+h.x,this.tileoffset.y=+h.y);var l=t.tileproperties;if(l)for(e in l)l.hasOwnProperty(e)&&this.setTileProperty(+e+this.firstgid,l[e]);if(!1===this.isCollection){if(this.image=loader.getImage(t.image),!this.image)throw new Error("melonJS: '"+t.image+"' file for tileset '"+this.name+"' not found!");this.texture=renderer.cache.get(this.image,{framewidth:this.tilewidth,frameheight:this.tileheight,margin:this.margin,spacing:this.spacing}),this.atlas=this.texture.getAtlas();var c=+t.columns||Math.round(this.image.width/(this.tilewidth+this.spacing)),u=Math.round(this.image.height/(this.tileheight+this.spacing));t.tilecount%c>0&&++u,this.lastgid=this.firstgid+(c*u-1||0),t.tilecount&&this.lastgid-this.firstgid+1!=+t.tilecount&&console.warn("Computed tilecount ("+(this.lastgid-this.firstgid+1)+") does not match expected tilecount ("+t.tilecount+")")}};TMXTileset.prototype.getTileImage=function(t){return this.imageCollection[t]},TMXTileset.prototype.setTileProperty=function(t,e){this.TileProperties[t]=e},TMXTileset.prototype.contains=function(t){return t>=this.firstgid&&t<=this.lastgid},TMXTileset.prototype.getViewTileId=function(t){var e=t-this.firstgid;return this.animations.has(e)?this.animations.get(e).cur.tileid:e},TMXTileset.prototype.getTileProperties=function(t){return this.TileProperties[t]},TMXTileset.prototype.update=function(t){var e=0,i=timer$1.getTime(),r=!1;return this._lastUpdate!==i&&(this._lastUpdate=i,this.animations.forEach((function(i){for(i.dt+=t,e=i.cur.duration;i.dt>=e;)i.dt-=e,i.idx=(i.idx+1)%i.frames.length,i.cur=i.frames[i.idx],e=i.cur.duration,r=!0}))),r},TMXTileset.prototype.drawTile=function(t,e,i,r){if(r.flipped&&(t.save(),t.translate(e,i),t.transform(r.currentTransform),e=i=0),!0===this.isCollection)t.drawImage(this.imageCollection[r.tileId],0,0,r.width,r.height,e,i,r.width,r.height);else{var o=this.atlas[this.getViewTileId(r.tileId)].offset;t.drawImage(this.image,o.x,o.y,this.tilewidth,this.tileheight,e,i,this.tilewidth+t.uvOffset,this.tileheight+t.uvOffset)}r.flipped&&t.restore()};var TMX_CLEAR_BIT_MASK=536870911,TMXTilesetGroup=function(){this.tilesets=[],this.length=0};TMXTilesetGroup.prototype.add=function(t){this.tilesets.push(t),this.length++},TMXTilesetGroup.prototype.getTilesetByIndex=function(t){return this.tilesets[t]},TMXTilesetGroup.prototype.getTilesetByGid=function(t){var e=-1;t&=TMX_CLEAR_BIT_MASK;for(var i=0,r=this.tilesets.length;i<r;i++){if(this.tilesets[i].contains(t))return this.tilesets[i];this.tilesets[i].firstgid===this.tilesets[i].lastgid&&t>=this.tilesets[i].firstgid&&(e=i)}if(-1!==e)return this.tilesets[e];throw new Error("no matching tileset found for gid "+t)};var TMXObject=function(t,e,i){this.points=void 0,this.name=e.name,this.x=+e.x,this.y=+e.y,this.z=+i,this.width=+e.width||0,this.height=+e.height||0,this.gid=+e.gid||null,this.tintcolor=e.tintcolor,this.type=e.type,this.type=e.type,this.rotation=degToRad(+e.rotation||0),this.id=+e.id||void 0,this.orientation=t.orientation,this.shapes=void 0,this.isEllipse=!1,this.isPolygon=!1,this.isPolyLine=!1,"number"==typeof this.gid?this.setTile(t.tilesets):void 0!==e.ellipse?this.isEllipse=!0:void 0!==e.polygon?(this.points=e.polygon,this.isPolygon=!0):void 0!==e.polyline&&(this.points=e.polyline,this.isPolyLine=!0),void 0!==e.text?(this.text=e.text,this.text.font=e.text.fontfamily||"sans-serif",this.text.size=e.text.pixelsize||16,this.text.fillStyle=e.text.color||"#000000",this.text.textAlign=e.text.halign||"left",this.text.textBaseline=e.text.valign||"top",this.text.width=this.width,this.text.height=this.height,applyTMXProperties(this.text,e)):(applyTMXProperties(this,e),this.shapes||(this.shapes=this.parseTMXShapes())),t.isEditor||t.getRenderer().adjustPosition(this)};TMXObject.prototype.setTile=function(t){var e=t.getTilesetByGid(this.gid);!1===e.isCollection&&(this.width=this.framewidth=e.tilewidth,this.height=this.frameheight=e.tileheight),this.tile=new Tile(this.x,this.y,this.gid,e)},TMXObject.prototype.parseTMXShapes=function(){var t=0,e=[];if(!0===this.isEllipse)e.push(new Ellipse(this.width/2,this.height/2,this.width,this.height).rotate(this.rotation));else if(!0===this.isPolygon){var i=new Polygon(0,0,this.points);if(!1===i.isConvex())throw new Error("collision polygones in Tiled should be defined as Convex");e.push(i.rotate(this.rotation))}else if(!0===this.isPolyLine){var r,o,n=this.points,s=n.length-1;for(t=0;t<s;t++)r=new Vector2d(n[t].x,n[t].y),o=new Vector2d(n[t+1].x,n[t+1].y),0!==this.rotation&&(r=r.rotate(this.rotation),o=o.rotate(this.rotation)),e.push(new Line(0,0,[r,o]))}else e.push(new Polygon(0,0,[new Vector2d,new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)]).rotate(this.rotation));if("isometric"===this.orientation)for(t=0;t<e.length;t++)e[t].toIso();return e},TMXObject.prototype.getObjectPropertyByName=function(t){return this[t]};var TMXGroup=function(t,e,i){var r=this;this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.tintcolor=e.tintcolor,this.z=i,this.objects=[];var o=void 0===e.visible||e.visible;this.opacity=!0===o?clamp(+e.opacity||1,0,1):0,applyTMXProperties(this,e),e.objects&&e.objects.forEach((function(e){e.tintcolor=r.tintcolor,r.objects.push(new TMXObject(t,e,i))})),e.layers&&e.layers.forEach((function(e){var o=new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i++);o.setRenderer(t.getRenderer()),r.width=Math.max(r.width,o.width),r.height=Math.max(r.height,o.height),r.objects.push(o)}))};TMXGroup.prototype.destroy=function(){this.objects=null},TMXGroup.prototype.getObjectCount=function(){return this.objects.length},TMXGroup.prototype.getObjectByIndex=function(t){return this.objects[t]};var COLLISION_GROUP="collision";function getNewDefaultRenderer(t){switch(t.orientation){case"orthogonal":return new TMXOrthogonalRenderer(t);case"isometric":return new TMXIsometricRenderer(t);case"hexagonal":return new TMXHexagonalRenderer(t);case"staggered":return new TMXStaggeredRenderer(t);default:throw new Error(t.orientation+" type TMX Tile Map not supported!")}}function readLayer(t,e,i){return new TMXLayer(t,e,t.tilewidth,t.tileheight,t.orientation,t.tilesets,i)}function readImageLayer(t,e,i){applyTMXProperties(e.properties,e);var r=pull("ImageLayer",+e.offsetx||+e.x||0,+e.offsety||+e.y||0,Object.assign({name:e.name,image:e.image,ratio:pull("Vector2d",+e.parallaxx||1,+e.parallaxy||1),tint:void 0!==e.tintcolor?pull("Color").parseHex(e.tintcolor,!0):void 0,z:i},e.properties)),o=void 0===e.visible||e.visible;return r.setOpacity(o?+e.opacity:0),r}function readTileset(t){return new TMXTileset(t)}function readObjectGroup(t,e,i){return new TMXGroup(t,e,i)}var TMXTileMap=function(t,e){if(this.data=e,this.name=t,this.cols=+e.width,this.rows=+e.height,this.tilewidth=+e.tilewidth,this.tileheight=+e.tileheight,this.infinite=+e.infinite,this.orientation=e.orientation,this.renderorder=e.renderorder||"right-down",this.version=e.version,this.tiledversion=e.tiledversion,this.tilesets=null,void 0===this.layers&&(this.layers=[]),void 0===this.objectGroups&&(this.objectGroups=[]),this.isEditor="melon-editor"===e.editor,this.nextobjectid=+e.nextobjectid||void 0,this.hexsidelength=+e.hexsidelength,this.staggeraxis=e.staggeraxis,this.staggerindex=e.staggerindex,this.bounds=this.getRenderer().getBounds().clone(),this.width=this.bounds.width,this.height=this.bounds.height,this.backgroundcolor=e.backgroundcolor,applyTMXProperties(this,e),this.initialized=!1,1===this.infinite)throw new Error("Tiled Infinite Map not supported!")};TMXTileMap.prototype.getRenderer=function(){return void 0!==this.renderer&&this.renderer.canRender(this)||(this.renderer=getNewDefaultRenderer(this)),this.renderer},TMXTileMap.prototype.getBounds=function(){return this.bounds},TMXTileMap.prototype.readMapObjects=function(t){var e=this;if(!0!==this.initialized){var i=0;if(this.tilesets||(this.tilesets=new TMXTilesetGroup),void 0!==t.tilesets)t.tilesets.forEach((function(t){e.tilesets.add(readTileset(t))}));this.background_image&&this.layers.push(pull("ImageLayer",0,0,{name:"background_image",image:this.background_image,z:i++})),t.layers.forEach((function(t){switch(t.type){case"imagelayer":e.layers.push(readImageLayer(e,t,i++));break;case"tilelayer":e.layers.push(readLayer(e,t,i++));break;case"objectgroup":case"group":e.objectGroups.push(readObjectGroup(e,t,i++))}})),this.initialized=!0}},TMXTileMap.prototype.addTo=function(t,e,i){var r=t.autoSort,o=t.autoDepth,n=this.getBounds();function s(e,i){viewport.setBounds(0,0,Math.max(n.width,e),Math.max(n.height,i)),t.pos.set(Math.max(0,~~((e-n.width)/2)),Math.max(0,~~((i-n.height)/2)),t.pos.z)}t.autoSort=!1,t.autoDepth=!1,this.backgroundcolor&&t.backgroundColor.parseCSS(this.backgroundcolor),this.getLayers().forEach((function(e){t.addChild(e)})),this.getObjects(e).forEach((function(e){t.addChild(e)})),t.resize(this.bounds.width,this.bounds.height),t.sort(!0),!0===i&&(off(VIEWPORT_ONRESIZE,s),s(viewport.width,viewport.height),on(VIEWPORT_ONRESIZE,s,this)),t.autoSort=r,t.autoDepth=o},TMXTileMap.prototype.getObjects=function(t){var e,i=[],r=!1;this.readMapObjects(this.data);for(var o=0;o<this.objectGroups.length;o++){var n=this.objectGroups[o];r=n.name.toLowerCase().includes(COLLISION_GROUP),!1===t&&((e=new Container(0,0,this.width,this.height)).anchorPoint.set(0,0),e.name=n.name,e.pos.z=n.z,e.setOpacity(n.opacity),e.autoSort=!1,e.autoDepth=!1);for(var s=0;s<n.objects.length;s++){var a,h=n.objects[s];void 0===h.anchorPoint&&(h.anchorPoint={x:0,y:0}),void 0!==h.tintcolor&&(h.tint=pull("Color"),h.tint.parseHex(h.tintcolor,!0)),h instanceof TMXLayer?a=h:"object"==typeof h.text?(void 0===h.text.anchorPoint&&(h.text.anchorPoint=h.anchorPoint),(a=!0===h.text.bitmap?pull("BitmapText",h.x,h.y,h.text):pull("Text",h.x,h.y,h.text)).pos.z=h.z):"object"==typeof h.tile?((a=h.tile.getRenderable(h)).body=new Body(a,h.shapes||new Rect(0,0,this.width,this.height)),a.body.setStatic(!0),a.pos.setMuted(h.x,h.y,h.z)):(void 0!==h.name&&""!==h.name?a=pull(h.name,h.x,h.y,h):((a=pull("Renderable",h.x,h.y,h.width,h.height)).anchorPoint.set(0,0),a.name=h.name,a.type=h.type,a.id=h.id,a.body=new Body(a,h.shapes||new Rect(0,0,a.width,a.height)),a.body.setStatic(!0),a.resize(a.body.getBounds().width,a.body.getBounds().height)),a.pos.z=h.z),r&&!h.name&&a.body&&(a.body.collisionType=collision.types.WORLD_SHAPE,a.body.isStatic=!0),!1!==t?(!0===a.isRenderable&&(a.setOpacity(a.getOpacity()*n.opacity),a.renderable instanceof Renderable&&a.renderable.setOpacity(a.renderable.getOpacity()*n.opacity)),i.push(a)):e.addChild(a)}!1===t&&e.children.length>0&&(e.autoSort=!0,e.autoDepth=!0,i.push(e))}return i},TMXTileMap.prototype.getLayers=function(){return this.readMapObjects(this.data),this.layers},TMXTileMap.prototype.destroy=function(){this.tilesets=void 0,this.layers.length=0,this.objectGroups.length=0,this.initialized=!1};var levels={},levelIdx=[],currentLevelIdx=0;function safeLoadLevel(t,e,i){e.container.reset(),reset(),levels[level.getCurrentLevelId()]&&levels[level.getCurrentLevelId()].destroy(),currentLevelIdx=levelIdx.indexOf(t),loadTMXLevel(t,e.container,e.flatten,e.setViewportBounds),emit(LEVEL_LOADED,t),e.onLoaded(t),i&&state.restart()}function loadTMXLevel(t,e,i,r){var o=levels[t];utils.resetGUID(t,o.nextobjectid),e.anchorPoint.set(0,0),o.addTo(e,i,r)}var level={add:function(t,e,i){if("tmx"===t)return null==levels[e]&&(levels[e]=new TMXTileMap(e,loader.getTMX(e)),levelIdx.push(e),i&&i(),!0);throw new Error("no level loader defined for format "+t)},load:function(t,e){if(e=Object.assign({container:world,onLoaded:onLevelLoaded,flatten:mergeGroup,setViewportBounds:!0},e||{}),void 0===levels[t])throw new Error("level "+t+" not found");if(!(levels[t]instanceof TMXTileMap))throw new Error("no level loader defined");return state.isRunning()?(state.stop(),utils.function.defer(safeLoadLevel,this,t,e,!0)):safeLoadLevel(t,e),!0},getCurrentLevelId:function(){return levelIdx[currentLevelIdx]},getCurrentLevel:function(){return levels[this.getCurrentLevelId()]},reload:function(t){return this.load(this.getCurrentLevelId(),t)},next:function(t){return currentLevelIdx+1<levelIdx.length&&this.load(levelIdx[currentLevelIdx+1],t)},previous:function(t){return currentLevelIdx-1>=0&&this.load(levelIdx[currentLevelIdx-1],t)},levelCount:function(){return levelIdx.length}},imgList={},tmxList={},binList={},jsonList={},baseURL={},resourceCount=0,loadCount=0,timerId$1=0;function checkLoadStatus(t){if(loadCount===resourceCount){if(!t&&!loader.onload)throw new Error("no load callback defined");clearTimeout(timerId$1);var e=t||loader.onload;setTimeout((function(){e(),emit(LOADER_COMPLETE)}),300)}else timerId$1=setTimeout((function(){checkLoadStatus(t)}),100)}function preloadImage(t,e,i){imgList[t.name]=new Image,imgList[t.name].onload=e,imgList[t.name].onerror=i,"string"==typeof loader.crossOrigin&&(imgList[t.name].crossOrigin=loader.crossOrigin),imgList[t.name].src=t.src+loader.nocache}function preloadFontFace(t,e,i){var r=new FontFace(t.name,t.src);r.load().then((function(){document.fonts.add(r),document.body.style.fontFamily=t.name,e()}),(function(){i(t.name)}))}function preloadTMX(t,e,i){function r(e){tmxList[t.name]=e,"tmx"===t.type&&level.add(t.type,t.name)}if(t.data)return r(t.data),void e();var o=new XMLHttpRequest,n=getExtension(t.src);o.overrideMimeType&&("json"===n?o.overrideMimeType("application/json"):o.overrideMimeType("text/xml")),o.open("GET",t.src+loader.nocache,!0),o.withCredentials=loader.withCredentials,o.ontimeout=i,o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status||0===o.status&&o.responseText){var s=null;switch(n){case"xml":case"tmx":case"tsx":if(device$1.ua.match(/msie/i)||!o.responseXML){if(!globalThis.DOMParser)throw new Error("XML file format loading not supported, use the JSON file format instead");s=(new DOMParser).parseFromString(o.responseText,"text/xml")}else s=o.responseXML;var a=parse(s);switch(n){case"tmx":s=a.map;break;case"tsx":s=a.tilesets[0]}break;case"json":s=JSON.parse(o.responseText);break;default:throw new Error("TMX file format "+n+"not supported !")}r(s),e()}else i(t.name)},o.send()}function preloadJSON(t,e,i){var r=new XMLHttpRequest;r.overrideMimeType&&r.overrideMimeType("application/json"),r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.ontimeout=i,r.onreadystatechange=function(){4===r.readyState&&(200===r.status||0===r.status&&r.responseText?(jsonList[t.name]=JSON.parse(r.responseText),e()):i(t.name))},r.send()}function preloadBinary(t,e,i){var r=new XMLHttpRequest;r.open("GET",t.src+loader.nocache,!0),r.withCredentials=loader.withCredentials,r.responseType="arraybuffer",r.onerror=i,r.onload=function(){var i=r.response;if(i){for(var o=new Uint8Array(i),n=[],s=0;s<o.byteLength;s++)n[s]=String.fromCharCode(o[s]);binList[t.name]=n.join(""),e()}},r.send()}function preloadJavascript(t,e,i){var r=document.createElement("script");r.src=t.src,r.type="text/javascript","string"==typeof loader.crossOrigin&&(r.crossOrigin=loader.crossOrigin),r.defer=!0,r.onload=function(){e()},r.onerror=function(){i(t.name)},document.getElementsByTagName("body")[0].appendChild(r)}var loader={nocache:"",onload:void 0,onProgress:void 0,crossOrigin:void 0,withCredentials:!1,onResourceLoaded:function(t){var e=++loadCount/resourceCount;this.onProgress&&this.onProgress(e,t),emit(LOADER_PROGRESS,e,t)},onLoadingError:function(t){throw new Error("Failed loading resource "+t.src)},setNocache:function(t){this.nocache=t?"?"+~~(1e7*Math.random()):""},setBaseURL:function(t,e){"*"!==t?baseURL[t]=e:(baseURL.audio=e,baseURL.binary=e,baseURL.image=e,baseURL.json=e,baseURL.js=e,baseURL.tmx=e,baseURL.tsx=e)},preload:function(t,e,i){void 0===i&&(i=!0);for(var r=0;r<t.length;r++)resourceCount+=this.load(t[r],this.onResourceLoaded.bind(this,t[r]),this.onLoadingError.bind(this,t[r]));void 0!==e&&(this.onload=e),!0===i&&state.change(state.LOADING),checkLoadStatus(e)},load:function(t,e,i){switch(void 0!==baseURL[t.type]&&(t.src=baseURL[t.type]+t.src),t.type){case"binary":return preloadBinary.call(this,t,e,i),1;case"image":return preloadImage.call(this,t,e,i),1;case"json":return preloadJSON.call(this,t,e,i),1;case"js":return preloadJavascript.call(this,t,e,i),1;case"tmx":case"tsx":return preloadTMX.call(this,t,e,i),1;case"audio":return load(t,!!t.stream,e,i),1;case"fontface":return preloadFontFace.call(this,t,e,i),1;default:throw new Error("load : unknown or invalid resource type : "+t.type)}},unload:function(t){switch(t.type){case"binary":return t.name in binList&&(delete binList[t.name],!0);case"image":return t.name in imgList&&(delete imgList[t.name],!0);case"json":return t.name in jsonList&&(delete jsonList[t.name],!0);case"js":case"fontface":return!0;case"tmx":case"tsx":return t.name in tmxList&&(delete tmxList[t.name],!0);case"audio":return unload(t.name);default:throw new Error("unload : unknown or invalid resource type : "+t.type)}},unloadAll:function(){var t;for(t in binList)binList.hasOwnProperty(t)&&this.unload({name:t,type:"binary"});for(t in imgList)imgList.hasOwnProperty(t)&&this.unload({name:t,type:"image"});for(t in tmxList)tmxList.hasOwnProperty(t)&&this.unload({name:t,type:"tmx"});for(t in jsonList)jsonList.hasOwnProperty(t)&&this.unload({name:t,type:"json"});unloadAll()},getTMX:function(t){return(t=""+t)in tmxList?tmxList[t]:null},getBinary:function(t){return(t=""+t)in binList?binList[t]:null},getImage:function(t){return(t=getBasename(""+t))in imgList?imgList[t]:null},getJSON:function(t){return(t=""+t)in jsonList?jsonList[t]:null}},audioTracks={},current_track_id=null,retry_counter=0,audioExts=[],soundLoadError=function(t,e){if(retry_counter++>3)throw new Error("melonJS: failed loading "+t);audioTracks[t].load()},stopOnAudioError=!0;function init$1(t){return void 0===t&&(t="mp3"),audioExts=t.split(","),!howler.Howler.noAudio}function hasFormat(t){return hasAudio()&&howler.Howler.codecs(t)}function hasAudio(){return!howler.Howler.noAudio}function enable(){unmuteAll()}function disable(){muteAll()}function load(t,e,i,r){var o=[];if(0===audioExts.length)throw new Error("target audio extension(s) should be set through me.audio.init() before calling the preloader.");for(var n=0;n<audioExts.length;n++)o.push(t.src+t.name+"."+audioExts[n]+loader.nocache);return audioTracks[t.name]=new howler.Howl({src:o,volume:howler.Howler.volume(),html5:!0===e,xhrWithCredentials:loader.withCredentials,onloaderror:function(){soundLoadError.call(this,t.name,r)},onload:function(){retry_counter=0,i&&i()}}),1}function play(t,e,i,r){void 0===e&&(e=!1);var o=audioTracks[t];if(o&&void 0!==o){var n=o.play();return"boolean"==typeof e&&o.loop(e,n),o.volume("number"==typeof r?clamp(r,0,1):howler.Howler.volume(),n),"function"==typeof i&&(!0===e?o.on("end",i,n):o.once("end",i,n)),n}throw new Error("audio clip "+t+" does not exist")}function fade(t,e,i,r,o){var n=audioTracks[t];if(!n||void 0===n)throw new Error("audio clip "+t+" does not exist");n.fade(e,i,r,o)}function seek(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var r=audioTracks[t];if(r&&void 0!==r)return r.seek.apply(r,e);throw new Error("audio clip "+t+" does not exist")}function rate(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];var r=audioTracks[t];if(r&&void 0!==r)return r.rate.apply(r,e);throw new Error("audio clip "+t+" does not exist")}function stop(t,e){if(void 0!==t){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.stop(e),i.off("end",void 0,e)}else howler.Howler.stop()}function pause(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.pause(e)}function resume(t,e){var i=audioTracks[t];if(!i||void 0===i)throw new Error("audio clip "+t+" does not exist");i.play(e)}function playTrack(t,e){return play(current_track_id=t,!0,null,e)}function stopTrack(){null!==current_track_id&&(audioTracks[current_track_id].stop(),current_track_id=null)}function pauseTrack(){null!==current_track_id&&audioTracks[current_track_id].pause()}function resumeTrack(){null!==current_track_id&&audioTracks[current_track_id].play()}function getCurrentTrack(){return current_track_id}function setVolume(t){howler.Howler.volume(t)}function getVolume(){return howler.Howler.volume()}function mute(t,e,i){i=void 0===i||!!i;var r=audioTracks[t];if(!r||void 0===r)throw new Error("audio clip "+t+" does not exist");r.mute(i,e)}function unmute(t,e){mute(t,e,!1)}function muteAll(){howler.Howler.mute(!0)}function unmuteAll(){howler.Howler.mute(!1)}function muted(){return howler.Howler._muted}function unload(t){return t in audioTracks&&(audioTracks[t].unload(),delete audioTracks[t],!0)}function unloadAll(){for(var t in audioTracks)audioTracks.hasOwnProperty(t)&&unload(t)}var audio=Object.freeze({__proto__:null,stopOnAudioError:stopOnAudioError,init:init$1,hasFormat:hasFormat,hasAudio:hasAudio,enable:enable,disable:disable,load:load,play:play,fade:fade,seek:seek,rate:rate,stop:stop,pause:pause,resume:resume,playTrack:playTrack,stopTrack:stopTrack,pauseTrack:pauseTrack,resumeTrack:resumeTrack,getCurrentTrack:getCurrentTrack,setVolume:setVolume,getVolume:getVolume,mute:mute,unmute:unmute,muteAll:muteAll,unmuteAll:unmuteAll,muted:muted,unload:unload,unloadAll:unloadAll}),data={};function isReserved(t){return"add"===t||"remove"===t}on(BOOT,(function(){if(!0===device$1.localStorage){var t=localStorage.getItem("me.save");if("string"==typeof t&&t.length>0)(JSON.parse(t)||[]).forEach((function(t){data[t]=JSON.parse(localStorage.getItem("me.save."+t))}))}}));var save={add:function(t){var e=save;Object.keys(t).forEach((function(i){var r;isReserved(i)||(r=i,Object.defineProperty(e,r,{configurable:!0,enumerable:!0,get:function(){return data[r]},set:function(t){data[r]=t,!0===device$1.localStorage&&localStorage.setItem("me.save."+r,JSON.stringify(t))}}),i in data||(e[i]=t[i]))})),!0===device$1.localStorage&&localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))},remove:function(t){isReserved(t)||void 0!==data[t]&&(delete data[t],!0===device$1.localStorage&&(localStorage.removeItem("me.save."+t),localStorage.setItem("me.save",JSON.stringify(Object.keys(data)))))}},accelInitialized=!1,deviceOrientationInitialized=!1,swipeEnabled=!0;function _disableSwipeFn(t){return t.preventDefault(),"function"==typeof globalThis.scroll&&globalThis.scroll(0,0),!1}var readyBound=!1,isReady=!1,readyList=[];function _domReady(){if(!isReady){if(!device.nodeJS&&!document.body)return setTimeout(_domReady,13);for(void 0!==globalThis.document&&"function"==typeof globalThis.document.removeEventListener&&globalThis.document.removeEventListener("DOMContentLoaded",this._domReady,!1),"function"==typeof globalThis.removeEventListener&&globalThis.removeEventListener("load",_domReady,!1);readyList.length;)readyList.shift().call(globalThis,[]);isReady=!0}}var _domRect={left:0,top:0,x:0,y:0,width:0,height:0,right:0,bottom:0};function _detectDevice(){device.iOS=/iPhone|iPad|iPod/i.test(device.ua),device.android=/Android/i.test(device.ua),device.android2=/Android 2/i.test(device.ua),device.linux=/Linux/i.test(device.ua),device.chromeOS=/CrOS/.test(device.ua),device.wp=/Windows Phone/i.test(device.ua),device.BlackBerry=/BlackBerry/i.test(device.ua),device.Kindle=/Kindle|Silk.*Mobile Safari/i.test(device.ua),device.isMobile=/Mobi/i.test(device.ua)||device.iOS||device.android||device.wp||device.BlackBerry||device.Kindle||!1,device.ejecta=void 0!==globalThis.ejecta,device.isWeixin=/MicroMessenger/i.test(device.ua)}function _checkCapabilities(){_detectDevice(),device.isMobile&&device.enableSwipe(!1),device.TouchEvent=!!("ontouchstart"in globalThis),device.PointerEvent=!!globalThis.PointerEvent,globalThis.gesture=prefixed("gesture"),device.touch=device.TouchEvent||device.PointerEvent,device.maxTouchPoints=device.touch?device.PointerEvent?globalThis.navigator.maxTouchPoints||1:10:1,device.wheel=void 0!==globalThis.document&&"onwheel"in globalThis.document.createElement("div"),device.hasPointerLockSupport=void 0!==globalThis.document&&void 0!==globalThis.document.pointerLockElement,device.hasDeviceOrientation=!!globalThis.DeviceOrientationEvent,device.hasAccelerometer=!!globalThis.DeviceMotionEvent,device.ScreenOrientation="undefined"!=typeof screen&&void 0!==screen.orientation,device.hasFullscreenSupport=void 0!==globalThis.document&&(prefixed("fullscreenEnabled",globalThis.document)||globalThis.document.mozFullScreenEnabled),!0===device.hasFullscreenSupport&&(globalThis.document.exitFullscreen=void 0!==globalThis.document&&(prefixed("cancelFullScreen",globalThis.document)||prefixed("exitFullscreen",globalThis.document))),device.hasWebAudio=!(!globalThis.AudioContext&&!globalThis.webkitAudioContext);try{device.localStorage=!!globalThis.localStorage}catch(t){device.localStorage=!1}try{device.OffscreenCanvas=void 0!==globalThis.OffscreenCanvas&&null!==new OffscreenCanvas(0,0).getContext("2d")}catch(t){device.OffscreenCanvas=!1}var t,e;("function"==typeof globalThis.addEventListener&&(globalThis.addEventListener("blur",(function(){device.stopOnBlur&&state.stop(!0),device.pauseOnBlur&&state.pause(!0)}),!1),globalThis.addEventListener("focus",(function(){device.stopOnBlur&&state.restart(!0),device.resumeOnFocus&&state.resume(!0),device.autoFocus&&device.focus()}),!1)),void 0!==globalThis.document)&&(void 0!==globalThis.document.hidden?(t="hidden",e="visibilitychange"):void 0!==globalThis.document.mozHidden?(t="mozHidden",e="mozvisibilitychange"):void 0!==globalThis.document.msHidden?(t="msHidden",e="msvisibilitychange"):void 0!==globalThis.document.webkitHidden&&(t="webkitHidden",e="webkitvisibilitychange"),"string"==typeof e&&globalThis.document.addEventListener(e,(function(){globalThis.document[t]?(device.stopOnBlur&&state.stop(!0),device.pauseOnBlur&&state.pause(!0)):(device.stopOnBlur&&state.restart(!0),device.resumeOnFocus&&state.resume(!0))}),!1))}on(BOOT,(function(){_checkCapabilities()}));var device={ua:void 0!==globalThis.navigator?globalThis.navigator.userAgent:"",localStorage:!1,hasAccelerometer:!1,hasDeviceOrientation:!1,ScreenOrientation:!1,hasFullscreenSupport:!1,hasPointerLockSupport:!1,hasWebAudio:!1,nativeBase64:"function"==typeof globalThis.atob,maxTouchPoints:1,touch:!1,wheel:!1,isMobile:!1,iOS:!1,android:!1,android2:!1,linux:!1,ejecta:!1,isWeixin:!1,nodeJS:"undefined"!=typeof process&&"node"===process.release.name,chromeOS:!1,wp:!1,BlackBerry:!1,Kindle:!1,accelerationX:0,accelerationY:0,accelerationZ:0,gamma:0,beta:0,alpha:0,language:void 0!==globalThis.navigator&&(globalThis.navigator.language||globalThis.navigator.browserLanguage||globalThis.navigator.userLanguage)||"en",pauseOnBlur:!0,resumeOnFocus:!0,autoFocus:!0,stopOnBlur:!1,OffscreenCanvas:!1,onReady:function(t){isReady?t.call(globalThis,[]):(readyList.push(t),readyBound||(!0===device.nodeJS||void 0!==globalThis.document&&"complete"===globalThis.document.readyState?globalThis.setTimeout(_domReady,0):(void 0!==globalThis.document&&"function"==typeof globalThis.document.addEventListener&&globalThis.document.addEventListener("DOMContentLoaded",_domReady,!1),globalThis.addEventListener("load",_domReady,!1)),readyBound=!0))},enableSwipe:function(t){!1!==t?!1===swipeEnabled&&(globalThis.document.removeEventListener("touchmove",_disableSwipeFn,!1),swipeEnabled=!0):!0===swipeEnabled&&(globalThis.document.addEventListener("touchmove",_disableSwipeFn,!1),swipeEnabled=!1)},requestFullscreen:function(t){this.hasFullscreenSupport&&((t=t||getParent()).requestFullscreen=prefixed("requestFullscreen",t)||t.mozRequestFullScreen,t.requestFullscreen())},exitFullscreen:function(){this.hasFullscreenSupport&&document.exitFullscreen()},getScreenOrientation:function(){var t="portrait",e="landscape",i=globalThis.screen;if(!0===this.ScreenOrientation){var r=prefixed("orientation",i);if(void 0!==r&&"string"==typeof r.type)return r.type;if("string"==typeof r)return r}return"number"==typeof globalThis.orientation?90===Math.abs(globalThis.orientation)?e:t:globalThis.outerWidth>globalThis.outerHeight?e:t},lockOrientation:function(t){var e=globalThis.screen;if(void 0!==e){var i=prefixed("lockOrientation",e);if(void 0!==i)return i(t)}return!1},unlockOrientation:function(){var t=globalThis.screen;if(void 0!==t){var e=prefixed("unlockOrientation",t);if(void 0!==e)return e()}return!1},isPortrait:function(){return this.getScreenOrientation().includes("portrait")},isLandscape:function(){return this.getScreenOrientation().includes("landscape")},getStorage:function(t){if(void 0===t&&(t="local"),"local"===t)return save;throw new Error("storage type "+t+" not supported")},getParentElement:function(t){var e=this.getElement(t);return null!==e.parentNode&&(e=e.parentNode),e},getElement:function(t){var e=null;return"undefined"!==t&&("string"==typeof t?e=document.getElementById(t):"object"==typeof t&&t.nodeType===Node.ELEMENT_NODE&&(e=t)),e||(e=document.body),e},getElementBounds:function(t){return"object"==typeof t&&t!==document.body&&void 0!==t.getBoundingClientRect?t.getBoundingClientRect():(_domRect.width=_domRect.right=globalThis.innerWidth,_domRect.height=_domRect.bottom=globalThis.innerHeight,_domRect)},getParentBounds:function(t){return this.getElementBounds(this.getParentElement(t))},isWebGLSupported:function(t){var e=!1;try{var i=document.createElement("canvas"),r={stencil:!0,failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat};e=!(!globalThis.WebGLRenderingContext||!i.getContext("webgl",r)&&!i.getContext("experimental-webgl",r))}catch(t){e=!1}return e},getMaxShaderPrecision:function(t){return t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0?"highp":t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"},focus:function(){"function"==typeof globalThis.focus&&globalThis.focus()},onDeviceMotion:function(t){this.accelerationX=t.accelerationIncludingGravity.x,this.accelerationY=t.accelerationIncludingGravity.y,this.accelerationZ=t.accelerationIncludingGravity.z},onDeviceRotate:function(t){this.gamma=t.gamma,this.beta=t.beta,this.alpha=t.alpha},watchAccelerometer:function(){var t=this;return this.hasAccelerometer&&!accelInitialized&&(DeviceOrientationEvent&&"function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(globalThis.addEventListener("devicemotion",t.onDeviceMotion,!1),accelInitialized=!0)})).catch(console.error):(globalThis.addEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!0)),accelInitialized},unwatchAccelerometer:function(){accelInitialized&&(globalThis.removeEventListener("devicemotion",this.onDeviceMotion,!1),accelInitialized=!1)},watchDeviceOrientation:function(){var t=this;return this.hasDeviceOrientation&&!deviceOrientationInitialized&&("function"==typeof DeviceOrientationEvent.requestPermission?DeviceOrientationEvent.requestPermission().then((function(e){"granted"===e&&(globalThis.addEventListener("deviceorientation",t.onDeviceRotate,!1),deviceOrientationInitialized=!0)})).catch(console.error):(globalThis.addEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!0)),deviceOrientationInitialized},unwatchDeviceOrientation:function(){deviceOrientationInitialized&&(globalThis.removeEventListener("deviceorientation",this.onDeviceRotate,!1),deviceOrientationInitialized=!1)},vibrate:function(t){void 0!==globalThis.navigator&&"function"==typeof globalThis.navigator.vibrate&&globalThis.navigator.vibrate(t)}};Object.defineProperty(device,"devicePixelRatio",{get:function(){return globalThis.devicePixelRatio||1}}),Object.defineProperty(device,"isFullscreen",{get:function(){return!!this.hasFullscreenSupport&&!(!prefixed("fullscreenElement",document)&&!document.mozFullScreenElement)}}),Object.defineProperty(device,"sound",{get:function(){return hasAudio()}});var device$1=device;function extractUniforms(t,e){var i,r={},o=/uniform\s+(\w+)\s+(\w+)/g,n={},s={},a={};return[e.vertex,e.fragment].forEach((function(t){for(;i=o.exec(t);)n[i[2]]=i[1]})),Object.keys(n).forEach((function(i){var r=n[i];a[i]=t.getUniformLocation(e.program,i),s[i]={get:function(t){return function(){return a[t]}}(i),set:function(e,i,r){return 0===i.indexOf("mat")?function(i){t[r](a[e],!1,i)}:function(i){var o=r;i.length&&"v"!==r.substr(-1)&&(o+="v"),t[o](a[e],i)}}(i,r,"uniform"+fnHash[r])}})),Object.defineProperties(r,s),r}function extractAttributes(t,e){for(var i,r={},o=/attribute\s+\w+\s+(\w+)/g,n=0;i=o.exec(e.vertex);)r[i[1]]=n++;return r}function compileShader(t,e,i){var r=t.createShader(e);if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error(t.getShaderInfoLog(r));return r}function compileProgram(t,e,i,r){var o=compileShader(t,t.VERTEX_SHADER,e),n=compileShader(t,t.FRAGMENT_SHADER,i),s=t.createProgram();for(var a in t.attachShader(s,o),t.attachShader(s,n),r)t.bindAttribLocation(s,r[a],a);if(t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){var h="Error initializing Shader "+this+"\ngl.VALIDATE_STATUS: "+t.getProgramParameter(s,t.VALIDATE_STATUS)+"\ngl.getError()"+t.getError()+"\ngl.getProgramInfoLog()"+t.getProgramInfoLog(s);throw t.deleteProgram(s),s=null,new Error(h)}return t.useProgram(s),t.deleteShader(o),t.deleteShader(n),s}var fnHash={bool:"1i",int:"1i",float:"1f",vec2:"2fv",vec3:"3fv",vec4:"4fv",bvec2:"2iv",bvec3:"3iv",bvec4:"4iv",ivec2:"2iv",ivec3:"3iv",ivec4:"4iv",mat2:"Matrix2fv",mat3:"Matrix3fv",mat4:"Matrix4fv",sampler2D:"1i"};function setPrecision(t,e){return"precision"!==t.substring(0,9)?"precision "+e+" float;"+t:t}function minify(t){return t=(t=(t=(t=t.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,"$1")).replace(/(\\n\s+)|(\s+\\n)/g,"")).replace(/(\\r|\\n)+/g,"")).replace(/\s*([;,[\](){}\\\/\-+*|^&!=<>?~%])\s*/g,"$1")}var GLShader=function(t,e,i,r){this.gl=t,this.vertex=setPrecision(minify(e),r||device$1.getMaxShaderPrecision(this.gl)),this.fragment=setPrecision(minify(i),r||device$1.getMaxShaderPrecision(this.gl)),this.attributes=extractAttributes(this.gl,this),this.program=compileProgram(this.gl,this.vertex,this.fragment,this.attributes),this.uniforms=extractUniforms(this.gl,this),on(ONCONTEXT_LOST,this.destroy,this)};GLShader.prototype.bind=function(){this.gl.useProgram(this.program)},GLShader.prototype.getAttribLocation=function(t){var e=this.attributes[t];return void 0!==e?e:-1},GLShader.prototype.setUniform=function(t,e){var i=this.uniforms;if(void 0===i[t])throw new Error("undefined ("+t+") uniform for shader "+this);"object"==typeof e&&"function"==typeof e.toArray?i[t]=e.toArray():i[t]=e},GLShader.prototype.destroy=function(){this.uniforms=null,this.attributes=null,this.gl.deleteProgram(this.program),this.vertex=null,this.fragment=null};var VertexArrayBuffer=function(t,e){this.vertexSize=t,this.quadSize=e,this.maxVertex=256,this.vertexCount=0,this.buffer=new ArrayBuffer(this.maxVertex*this.vertexSize*this.quadSize),this.bufferF32=new Float32Array(this.buffer),this.bufferU32=new Uint32Array(this.buffer)};VertexArrayBuffer.prototype.clear=function(){this.vertexCount=0},VertexArrayBuffer.prototype.isFull=function(t){return void 0===t&&(t=this.quadSize),this.vertexCount+t>=this.maxVertex},VertexArrayBuffer.prototype.resize=function(){this.maxVertex<<=1;var t=this.bufferF32;return this.buffer=new ArrayBuffer(this.maxVertex*this.vertexSize*this.quadSize),this.bufferF32=new Float32Array(this.buffer),this.bufferU32=new Uint32Array(this.buffer),this.bufferF32.set(t),this},VertexArrayBuffer.prototype.push=function(t,e,i,r,o){var n=this.vertexCount*this.vertexSize;return this.vertexCount>=this.maxVertex&&this.resize(),this.bufferF32[n+0]=t,this.bufferF32[n+1]=e,void 0!==i&&(this.bufferF32[n+2]=i,this.bufferF32[n+3]=r),void 0!==o&&(this.bufferU32[n+4]=o),this.vertexCount++,this},VertexArrayBuffer.prototype.toFloat32=function(t,e){return void 0!==e?this.bufferF32.subarray(t,e):this.bufferF32},VertexArrayBuffer.prototype.toUint32=function(t,e){return void 0!==e?this.bufferU32.subarray(t,e):this.bufferU32},VertexArrayBuffer.prototype.length=function(){return this.vertexCount},VertexArrayBuffer.prototype.isEmpty=function(){return 0===this.vertexCount};var primitiveVertex="// Current vertex point\nattribute vec2 aVertex;\n\n// Projection matrix\nuniform mat4 uProjectionMatrix;\n\n// Vertex color\nuniform vec4 uColor;\n\n// Fragment color\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(uColor.rgb * uColor.a, uColor.a);\n}\n",primitiveFragment="varying vec4 vColor;\n\nvoid main(void) {\n gl_FragColor = vColor;\n}\n",quadVertex="attribute vec2 aVertex;\nattribute vec2 aRegion;\nattribute vec4 aColor;\n\nuniform mat4 uProjectionMatrix;\n\nvarying vec2 vRegion;\nvarying vec4 vColor;\n\nvoid main(void) {\n // Transform the vertex position by the projection matrix\n gl_Position = uProjectionMatrix * vec4(aVertex, 0.0, 1.0);\n // Pass the remaining attributes to the fragment shader\n vColor = vec4(aColor.bgr * aColor.a, aColor.a);\n vRegion = aRegion;\n}\n",quadFragment="uniform sampler2D uSampler;\nvarying vec4 vColor;\nvarying vec2 vRegion;\n\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vRegion) * vColor;\n}\n",V_ARRAY=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],WebGLCompositor=function(t){this.init(t)};WebGLCompositor.prototype.init=function(t){var e=this,i=t.gl;this.currentTextureUnit=-1,this.boundTextures=[],this.renderer=t,this.gl=t.gl,this.color=t.currentColor,this.viewMatrix=t.currentTransform,this.activeShader=null,this.mode=i.TRIANGLES,this.attributes=[],this.vertexByteSize=0,this.vertexSize=0,this.primitiveShader=new GLShader(this.gl,primitiveVertex,primitiveFragment),this.quadShader=new GLShader(this.gl,quadVertex,quadFragment),this.addAttribute("aVertex",2,i.FLOAT,!1,0*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aRegion",2,i.FLOAT,!1,2*Float32Array.BYTES_PER_ELEMENT),this.addAttribute("aColor",4,i.UNSIGNED_BYTE,!0,4*Float32Array.BYTES_PER_ELEMENT),this.vertexBuffer=new VertexArrayBuffer(this.vertexSize,6),i.bindBuffer(i.ARRAY_BUFFER,i.createBuffer()),i.bufferData(i.ARRAY_BUFFER,this.vertexBuffer.buffer,i.STREAM_DRAW),on(CANVAS_ONRESIZE,(function(t,i){e.flush(),e.setViewport(0,0,t,i)}))},WebGLCompositor.prototype.reset=function(){this.gl=this.renderer.gl,this.flush(),this.setViewport(0,0,this.renderer.getScreenCanvas().width,this.renderer.getScreenCanvas().height),this.clearColor(0,0,0,0);for(var t=0;t<this.renderer.maxTextures;t++){var e=this.getTexture2D(t);void 0!==e&&this.deleteTexture2D(e)}this.currentTextureUnit=-1,this.useShader(this.quadShader)},WebGLCompositor.prototype.addAttribute=function(t,e,i,r,o){switch(this.attributes.push({name:t,size:e,type:i,normalized:r,offset:o}),i){case this.gl.BYTE:this.vertexByteSize+=e*Int8Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_BYTE:this.vertexByteSize+=e*Uint8Array.BYTES_PER_ELEMENT;break;case this.gl.SHORT:this.vertexByteSize+=e*Int16Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_SHORT:this.vertexByteSize+=e*Uint16Array.BYTES_PER_ELEMENT;break;case this.gl.INT:this.vertexByteSize+=e*Int32Array.BYTES_PER_ELEMENT;break;case this.gl.UNSIGNED_INT:this.vertexByteSize+=e*Uint32Array.BYTES_PER_ELEMENT;break;case this.gl.FLOAT:this.vertexByteSize+=e*Float32Array.BYTES_PER_ELEMENT;break;default:throw new Error("Invalid GL Attribute type")}this.vertexSize=this.vertexByteSize/Float32Array.BYTES_PER_ELEMENT},WebGLCompositor.prototype.setViewport=function(t,e,i,r){this.gl.viewport(t,e,i,r)},WebGLCompositor.prototype.createTexture2D=function(t,e,i,r,o,n,s,a,h){void 0===r&&(r="no-repeat"),void 0===a&&(a=!0),void 0===h&&(h=!0);var l=this.gl,c=isPowerOfTwo(o||e.width)&&isPowerOfTwo(n||e.height),u=l.createTexture(),d=0===r.search(/^repeat(-x)?$/)&&(c||this.renderer.WebGLVersion>1)?l.REPEAT:l.CLAMP_TO_EDGE,p=0===r.search(/^repeat(-y)?$/)&&(c||this.renderer.WebGLVersion>1)?l.REPEAT:l.CLAMP_TO_EDGE;return this.bindTexture2D(u,t),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,d),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,p),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,i),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,i),l.pixelStorei(l.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a),o||n||s?l.texImage2D(l.TEXTURE_2D,0,l.RGBA,o,n,s,l.RGBA,l.UNSIGNED_BYTE,e):l.texImage2D(l.TEXTURE_2D,0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,e),c&&!1!==h&&l.generateMipmap(l.TEXTURE_2D),u},WebGLCompositor.prototype.deleteTexture2D=function(t){this.gl.deleteTexture(t),this.unbindTexture2D(t)},WebGLCompositor.prototype.getTexture2D=function(t){return this.boundTextures[t]},WebGLCompositor.prototype.bindTexture2D=function(t,e){var i=this.gl;t!==this.boundTextures[e]?(this.flush(),this.currentTextureUnit!==e&&(this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,t),this.boundTextures[e]=t):this.currentTextureUnit!==e&&(this.flush(),this.currentTextureUnit=e,i.activeTexture(i.TEXTURE0+e))},WebGLCompositor.prototype.unbindTexture2D=function(t,e){return void 0===e&&(e=this.boundTextures.indexOf(t)),-1!==e&&(delete this.boundTextures[e],e===this.currentTextureUnit&&(this.currentTextureUnit=-1)),e},WebGLCompositor.prototype.uploadTexture=function(t,e,i,r,o){void 0===o&&(o=!1);var n=this.renderer.cache.getUnit(t),s=this.boundTextures[n];return void 0===s||o?this.createTexture2D(n,t.getTexture(),this.renderer.settings.antiAlias?this.gl.LINEAR:this.gl.NEAREST,t.repeat,e,i,r,t.premultipliedAlpha):this.bindTexture2D(s,n),this.currentTextureUnit},WebGLCompositor.prototype.setProjection=function(t){this.activeShader.setUniform("uProjectionMatrix",t)},WebGLCompositor.prototype.useShader=function(t){if(this.activeShader!==t){this.flush(),this.activeShader=t,this.activeShader.bind(),this.activeShader.setUniform("uProjectionMatrix",this.renderer.projectionMatrix);for(var e=0;e<this.attributes.length;++e){var i=this.gl,r=this.attributes[e],o=this.activeShader.getAttribLocation(r.name);-1!==o?(i.enableVertexAttribArray(o),i.vertexAttribPointer(o,r.size,r.type,r.normalized,this.vertexByteSize,r.offset)):i.disableVertexAttribArray(e)}}},WebGLCompositor.prototype.addQuad=function(t,e,i,r,o,n,s,a,h,l){if(!(this.color.alpha<1/255)){this.useShader(this.quadShader),this.vertexBuffer.isFull(6)&&this.flush();var c=this.uploadTexture(t);this.quadShader.setUniform("uSampler",c);var u=this.viewMatrix,d=V_ARRAY[0].set(e,i),p=V_ARRAY[1].set(e+r,i),f=V_ARRAY[2].set(e,i+o),y=V_ARRAY[3].set(e+r,i+o);u.isIdentity()||(u.apply(d),u.apply(p),u.apply(f),u.apply(y)),this.vertexBuffer.push(d.x,d.y,n,s,l),this.vertexBuffer.push(p.x,p.y,a,s,l),this.vertexBuffer.push(f.x,f.y,n,h,l),this.vertexBuffer.push(f.x,f.y,n,h,l),this.vertexBuffer.push(p.x,p.y,a,s,l),this.vertexBuffer.push(y.x,y.y,a,h,l)}},WebGLCompositor.prototype.flush=function(t){void 0===t&&(t=this.mode);var e=this.vertexBuffer,i=e.vertexCount;if(i>0){var r=this.gl,o=e.vertexSize;this.renderer.WebGLVersion>1?r.bufferData(r.ARRAY_BUFFER,e.toFloat32(),r.STREAM_DRAW,0,i*o):r.bufferData(r.ARRAY_BUFFER,e.toFloat32(0,i*o),r.STREAM_DRAW),r.drawArrays(t,0,i),e.clear()}},WebGLCompositor.prototype.drawVertices=function(t,e,i){void 0===i&&(i=e.length),this.useShader(this.primitiveShader),this.primitiveShader.setUniform("uColor",this.color);for(var r=this.viewMatrix,o=this.vertexBuffer,n=r.isIdentity(),s=0;s<i;s++)n||r.apply(e[s]),o.push(e[s].x,e[s].y);this.flush(t)},WebGLCompositor.prototype.clearColor=function(t,e,i,r){this.gl.clearColor(t,e,i,r)},WebGLCompositor.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)};var WebGLRenderer=function(t){function e(e){var i=this;t.call(this,e),this.WebGLVersion=1,this.GPUVendor=null,this.GPURenderer=null,this.context=this.gl=this.getContextGL(this.getScreenCanvas(),e.transparent),this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this._colorStack=[],this._matrixStack=[],this._scissorStack=[],this._blendStack=[],this._glPoints=[new Vector2d,new Vector2d,new Vector2d,new Vector2d],this.currentTransform=new Matrix2d,this.currentCompositor=null,this.compositors=new Map;var r=new(this.settings.compositor||WebGLCompositor)(this);this.compositors.set("default",r),this.setCompositor(r),this.gl.disable(this.gl.DEPTH_TEST),this.gl.disable(this.gl.SCISSOR_TEST),this.gl.enable(this.gl.BLEND),this.setBlendMode(this.settings.blendMode);var o=this.gl.getExtension("WEBGL_debug_renderer_info");null!==o&&(this.GPUVendor=this.gl.getParameter(o.UNMASKED_VENDOR_WEBGL),this.GPURenderer=this.gl.getParameter(o.UNMASKED_RENDERER_WEBGL)),this.cache=new TextureCache(this.maxTextures),this.getScreenCanvas().addEventListener("webglcontextlost",(function(t){t.preventDefault(),i.isContextValid=!1,emit(ONCONTEXT_LOST,i)}),!1),this.getScreenCanvas().addEventListener("webglcontextrestored",(function(){i.reset(),i.isContextValid=!0,emit(ONCONTEXT_RESTORED,i)}),!1)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(){var e=this;t.prototype.reset.call(this),this.compositors.forEach((function(t){!1===e.isContextValid?t.init(e):t.reset()})),this.gl.disable(this.gl.SCISSOR_TEST),void 0!==this.fontContext2D&&this.createFontTexture(this.cache)},e.prototype.setCompositor=function(t){if(void 0===t&&(t="default"),"string"==typeof t&&(t=this.compositors.get(t)),void 0===t)throw new Error("Invalid WebGL Compositor");this.currentCompositor!==t&&(null!==this.currentCompositor&&this.currentCompositor.flush(),this.currentCompositor=t)},e.prototype.resetTransform=function(){this.currentTransform.identity()},e.prototype.createFontTexture=function(t){if(void 0===this.fontTexture){var e=this.backBufferCanvas,i=e.width,r=e.height;1===this.WebGLVersion&&(isPowerOfTwo(i)||(i=nextPowerOfTwo(e.width)),isPowerOfTwo(r)||(r=nextPowerOfTwo(e.height)));var o=createCanvas(i,r,!0);this.fontContext2D=this.getContext2d(o),this.fontTexture=new TextureAtlas(createAtlas(e.width,e.height,"fontTexture"),o,t),this.currentCompositor.uploadTexture(this.fontTexture,0,0,0)}else t.set(this.fontContext2D.canvas,this.fontTexture)},e.prototype.createPattern=function(t,e){if(!(1!==renderer.WebGLVersion||isPowerOfTwo(t.width)&&isPowerOfTwo(t.height))){var i=void 0!==t.src?t.src:t;throw new Error("[WebGL Renderer] "+i+" is not a POT texture ("+t.width+"x"+t.height+")")}var r=new TextureAtlas(createAtlas(t.width,t.height,"pattern",e),t);return this.currentCompositor.uploadTexture(r),r},e.prototype.flush=function(){this.currentCompositor.flush()},e.prototype.setProjection=function(e){t.prototype.setProjection.call(this,e),this.currentCompositor.setProjection(e)},e.prototype.clearColor=function(t,e){var i;if(void 0===t&&(t="#000000"),void 0===e&&(e=!1),t instanceof Color)i=t.toArray();else{var r=pull("me.Color");i=r.parseCSS(t).toArray(),push(r)}this.currentCompositor.clearColor(i[0],i[1],i[2],!0===e?1:i[3]),this.currentCompositor.clear(),this.currentCompositor.clearColor(0,0,0,0)},e.prototype.clearRect=function(t,e,i,r){this.save(),this.clipRect(t,e,i,r),this.clearColor(),this.restore()},e.prototype.drawFont=function(t){var e=this.getFontContext();this.currentCompositor.uploadTexture(this.fontTexture,0,0,0,!0);var i=this.fontTexture.getUVs(t.left+","+t.top+","+t.width+","+t.height);this.currentCompositor.addQuad(this.fontTexture,t.left,t.top,t.width,t.height,i[0],i[1],i[2],i[3],this.currentTint.toUint32()),e.clearRect(t.left,t.top,t.width,t.height)},e.prototype.drawImage=function(t,e,i,r,o,n,s,a,h){void 0===r?(r=a=t.width,o=h=t.height,n=e,s=i,e=0,i=0):void 0===n&&(n=e,s=i,a=r,h=o,r=t.width,o=t.height,e=0,i=0),!1===this.settings.subPixel&&(n|=0,s|=0);var l=this.cache.get(t),c=l.getUVs(e+","+i+","+r+","+o);this.currentCompositor.addQuad(l,n,s,a,h,c[0],c[1],c[2],c[3],this.currentTint.toUint32())},e.prototype.drawPattern=function(t,e,i,r,o){var n=t.getUVs("0,0,"+r+","+o);this.currentCompositor.addQuad(t,e,i,r,o,n[0],n[1],n[2],n[3],this.currentTint.toUint32())},e.prototype.getScreenContext=function(){return this.gl},e.prototype.getContextGL=function(t,e){if(null==t)throw new Error("You must pass a canvas element in order to create a GL context");"boolean"!=typeof e&&(e=!0);var i,r={alpha:e,antialias:this.settings.antiAlias,depth:!1,stencil:!0,preserveDrawingBuffer:!1,premultipliedAlpha:e,powerPreference:this.settings.powerPreference,failIfMajorPerformanceCaveat:this.settings.failIfMajorPerformanceCaveat};if(!1===this.settings.preferWebGL1&&(i=t.getContext("webgl2",r))&&(this.WebGLVersion=2),i||(this.WebGLVersion=1,i=t.getContext("webgl",r)||t.getContext("experimental-webgl",r)),!i)throw new Error("A WebGL context could not be created.");return i},e.prototype.getContext=function(){return this.gl},e.prototype.setBlendMode=function(t,e){if(void 0===t&&(t="normal"),void 0===e&&(e=this.gl),this.currentBlendMode!==t)switch(this.flush(),e.enable(e.BLEND),this.currentBlendMode=t,t){case"screen":e.blendFunc(e.ONE,e.ONE_MINUS_SRC_COLOR);break;case"lighter":case"additive":e.blendFunc(e.ONE,e.ONE);break;case"multiply":e.blendFunc(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA);break;default:e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA),this.currentBlendMode="normal"}},e.prototype.getFontContext=function(){return void 0===this.fontContext2D&&(console.warn("[WebGL Renderer] WARNING : Using Standard me.Text with WebGL will severly impact performances !"),this.createFontTexture(this.cache)),this.fontContext2D},e.prototype.restore=function(){if(0!==this._matrixStack.length){var t=this._colorStack.pop(),e=this._matrixStack.pop();this.currentColor.copy(t),this.currentTransform.copy(e),this.setBlendMode(this._blendStack.pop()),push(t),push(e)}0!==this._scissorStack.length?this.currentScissor.set(this._scissorStack.pop()):(this.gl.disable(this.gl.SCISSOR_TEST),this.currentScissor[0]=0,this.currentScissor[1]=0,this.currentScissor[2]=this.backBufferCanvas.width,this.currentScissor[3]=this.backBufferCanvas.height)},e.prototype.save=function(){this._colorStack.push(this.currentColor.clone()),this._matrixStack.push(this.currentTransform.clone()),this.gl.isEnabled(this.gl.SCISSOR_TEST)&&this._scissorStack.push(this.currentScissor.slice()),this._blendStack.push(this.getBlendMode())},e.prototype.rotate=function(t){this.currentTransform.rotate(t)},e.prototype.scale=function(t,e){this.currentTransform.scale(t,e)},e.prototype.setAntiAlias=function(e,i){t.prototype.setAntiAlias.call(this,e,i)},e.prototype.setGlobalAlpha=function(t){this.currentColor.alpha=t},e.prototype.setColor=function(t){var e=this.currentColor.alpha;this.currentColor.copy(t),this.currentColor.alpha*=e},e.prototype.setLineWidth=function(t){this.getScreenContext().lineWidth(t)},e.prototype.strokeArc=function(t,e,i,r,o,n,s){if(void 0===n&&(n=!1),!0===s)this.fillArc(t,e,i,r,o,n);else{var a,h=this._glPoints,l=Math.floor(24*Math.sqrt(2*i)),c=(o-r)/(2*l),u=2*c,d=Math.cos(c),p=Math.sin(c);for(a=h.length;a<l+1;a++)h.push(new Vector2d);for(a=0;a<l;a++){var f=c+r+u*a,y=Math.cos(f),g=-Math.sin(f);h[a].x=t+(d*y+p*g)*i,h[a].y=e+(d*-g+p*y)*i}this.currentCompositor.drawVertices(this.gl.LINE_STRIP,h,l)}},e.prototype.fillArc=function(t,e,i,r,o){var n,s=this._glPoints,a=0,h=Math.floor(24*Math.sqrt(2*i)),l=(o-r)/(2*h),c=2*l,u=Math.cos(l),d=Math.sin(l);for(n=s.length;n<2*h;n++)s.push(new Vector2d);for(n=0;n<h-1;n++){var p=l+r+c*n,f=Math.cos(p),y=-Math.sin(p);s[a++].set(t,e),s[a++].set(t-(u*f+d*y)*i,e-(u*-y+d*f)*i)}this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,s,a)},e.prototype.strokeEllipse=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillEllipse(t,e,i,r);else{var n,s=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+r)),a=TAU/s,h=this._glPoints;for(n=h.length;n<s;n++)h.push(new Vector2d);for(n=0;n<s;n++)h[n].x=t+Math.sin(a*-n)*i,h[n].y=e+Math.cos(a*-n)*r;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,h,s)}},e.prototype.fillEllipse=function(t,e,i,r){var o,n=Math.floor(24*Math.sqrt(i))||Math.floor(12*Math.sqrt(i+r)),s=TAU/n,a=this._glPoints,h=0;for(o=a.length;o<2*(n+1);o++)a.push(new Vector2d);for(o=0;o<n+1;o++)a[h++].set(t,e),a[h++].set(t+Math.sin(s*o)*i,e+Math.cos(s*o)*r);this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,a,h)},e.prototype.strokeLine=function(t,e,i,r){var o=this._glPoints;o[0].x=t,o[0].y=e,o[1].x=i,o[1].y=r,this.currentCompositor.drawVertices(this.gl.LINE_STRIP,o,2)},e.prototype.fillLine=function(t,e,i,r){this.strokeLine(t,e,i,r)},e.prototype.strokePolygon=function(t,e){if(void 0===e&&(e=!1),!0===e)this.fillPolygon(t);else{var i,r=t.points.length,o=this._glPoints;for(i=o.length;i<r;i++)o.push(new Vector2d);for(i=0;i<r;i++)o[i].x=t.pos.x+t.points[i].x,o[i].y=t.pos.y+t.points[i].y;this.currentCompositor.drawVertices(this.gl.LINE_LOOP,o,r)}},e.prototype.fillPolygon=function(t){var e,i=t.points,r=this._glPoints,o=t.getIndices(),n=t.pos.x,s=t.pos.y;for(e=r.length;e<o.length;e++)r.push(new Vector2d);for(e=0;e<o.length;e++)r[e].set(n+i[o[e]].x,s+i[o[e]].y);this.currentCompositor.drawVertices(this.gl.TRIANGLES,r,o.length)},e.prototype.strokeRect=function(t,e,i,r,o){if(void 0===o&&(o=!1),!0===o)this.fillRect(t,e,i,r);else{var n=this._glPoints;n[0].x=t,n[0].y=e,n[1].x=t+i,n[1].y=e,n[2].x=t+i,n[2].y=e+r,n[3].x=t,n[3].y=e+r,this.currentCompositor.drawVertices(this.gl.LINE_LOOP,n,4)}},e.prototype.fillRect=function(t,e,i,r){var o=this._glPoints;o[0].x=t+i,o[0].y=e,o[1].x=t,o[1].y=e,o[2].x=t+i,o[2].y=e+r,o[3].x=t,o[3].y=e+r,this.currentCompositor.drawVertices(this.gl.TRIANGLE_STRIP,o,4)},e.prototype.setTransform=function(t){this.resetTransform(),this.transform(t)},e.prototype.transform=function(t){var e=this.currentTransform;if(e.multiply(t),!1===this.settings.subPixel){var i=e.toArray();i[6]|=0,i[7]|=0}},e.prototype.translate=function(t,e){var i=this.currentTransform;if(i.translate(t,e),!1===this.settings.subPixel){var r=i.toArray();r[6]|=0,r[7]|=0}},e.prototype.clipRect=function(t,e,i,r){var o=this.backBufferCanvas,n=this.gl;if(0!==t||0!==e||i!==o.width||r!==o.height){var s=this.currentScissor;if(n.isEnabled(n.SCISSOR_TEST)&&s[0]===t&&s[1]===e&&s[2]===i&&s[3]===r)return;this.flush(),n.enable(this.gl.SCISSOR_TEST),n.scissor(t+this.currentTransform.tx,o.height-r-e-this.currentTransform.ty,i,r),s[0]=t,s[1]=e,s[2]=i,s[3]=r}else n.disable(n.SCISSOR_TEST)},e.prototype.setMask=function(t){var e=this.gl;this.flush(),e.enable(e.STENCIL_TEST),e.clear(e.STENCIL_BUFFER_BIT),e.colorMask(!1,!1,!1,!1),e.stencilFunc(e.NOTEQUAL,1,1),e.stencilOp(e.REPLACE,e.REPLACE,e.REPLACE),this.fill(t),this.flush(),e.colorMask(!0,!0,!0,!0),e.stencilFunc(e.EQUAL,1,1),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)},e.prototype.clearMask=function(){this.flush(),this.gl.disable(this.gl.STENCIL_TEST)},e}(Renderer),designRatio=1,designWidth=0,designHeight=0,settings={parent:void 0,renderer:2,doubleBuffering:!1,autoScale:!1,scale:1,scaleMethod:"fit",transparent:!1,blendMode:"normal",antiAlias:!1,failIfMajorPerformanceCaveat:!0,subPixel:!1,preferWebGL1:!1,powerPreference:"default",verbose:!1,consoleHeader:!0};function autoDetectRenderer(t){try{if(device$1.isWebGLSupported(t))return new WebGLRenderer(t)}catch(t){console.log("Error creating WebGL renderer :"+t.message)}return new CanvasRenderer(t)}function onresize(){var t=renderer.settings,e=1,i=1;if(t.autoScale){var r=1/0,o=1/0;if(globalThis.getComputedStyle){var n=globalThis.getComputedStyle(renderer.getScreenCanvas(),null);r=parseInt(n.maxWidth,10)||1/0,o=parseInt(n.maxHeight,10)||1/0}var s=device$1.getParentBounds(getParent()),a=Math.min(r,s.width),h=Math.min(o,s.height),l=a/h;if("fill-min"===t.scaleMethod&&l>designRatio||"fill-max"===t.scaleMethod&&l<designRatio||"flex-width"===t.scaleMethod){var c=Math.min(r,designHeight*l);e=i=a/c,renderer.resize(Math.floor(c),designHeight)}else if("fill-min"===t.scaleMethod&&l<designRatio||"fill-max"===t.scaleMethod&&l>designRatio||"flex-height"===t.scaleMethod){var u=Math.min(o,designWidth*(h/a));e=i=h/u,renderer.resize(designWidth,Math.floor(u))}else"flex"===t.scaleMethod?renderer.resize(Math.floor(a),Math.floor(h)):"stretch"===t.scaleMethod?(e=a/designWidth,i=h/designHeight):e=i=l<designRatio?a/designWidth:h/designHeight;scale(e,i)}}var CANVAS=0,WEBGL=1,AUTO=2,parent=null,scaleRatio=new Vector2d(1,1),renderer=null;function init(t,e,i){if(!exports.initialized)throw new Error("me.video.init() called before engine initialization.");(settings=Object.assign(settings,i||{})).width=t,settings.height=e,settings.doubleBuffering=!!settings.doubleBuffering,settings.transparent=!!settings.transparent,settings.antiAlias=!!settings.antiAlias,settings.failIfMajorPerformanceCaveat=!!settings.failIfMajorPerformanceCaveat,settings.subPixel=!!settings.subPixel,settings.verbose=!!settings.verbose,-1!==settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/)?settings.autoScale="auto"===settings.scale||!0:(settings.scaleMethod="fit",settings.autoScale="auto"===settings.scale||!1),!1!==settings.consoleHeader&&console.log("melonJS 2 (v"+version+") | http://melonjs.org");var r=utils.getUriFragment();!0!==r.webgl&&!0!==r.webgl1&&!0!==r.webgl2||(settings.renderer=WEBGL,!0===r.webgl1&&(settings.preferWebGL1=!0)),settings.scale=settings.autoScale?1:+settings.scale||1,scaleRatio.set(settings.scale,settings.scale),(settings.autoScale||1!==settings.scale)&&(settings.doubleBuffering=!0),designRatio=t/e,designWidth=t,designHeight=e,settings.zoomX=t*scaleRatio.x,settings.zoomY=e*scaleRatio.y,globalThis.addEventListener("resize",utils.function.throttle((function(t){emit(WINDOW_ONRESIZE,t)}),100),!1),globalThis.addEventListener("orientationchange",(function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),!1),globalThis.addEventListener("onmozorientationchange",(function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),!1),!0===device$1.ScreenOrientation&&(globalThis.screen.orientation.onchange=function(t){emit(WINDOW_ONORIENTATION_CHANGE,t)}),globalThis.addEventListener("scroll",utils.function.throttle((function(t){emit(WINDOW_ONSCROLL,t)}),100),!1),on(WINDOW_ONRESIZE,onresize,this),on(WINDOW_ONORIENTATION_CHANGE,onresize,this);try{switch(settings.renderer){case AUTO:case WEBGL:renderer=autoDetectRenderer(settings);break;default:renderer=new CanvasRenderer(settings)}}catch(t){return console(t.message),!1}((parent=device$1.getElement(void 0!==settings.parent?settings.parent:document.body)).appendChild(renderer.getScreenCanvas()),onresize(),"MutationObserver"in globalThis)&&new MutationObserver(onresize.bind(this)).observe(parent,{attributes:!1,childList:!0,subtree:!0});if(!1!==settings.consoleHeader){var o=renderer instanceof CanvasRenderer?"CANVAS":"WebGL"+renderer.WebGLVersion,n=device$1.hasWebAudio?"Web Audio":"HTML5 Audio",s="string"==typeof renderer.GPURenderer?" ("+renderer.GPURenderer+")":"";console.log(o+" renderer"+s+" | "+n+" | pixel ratio "+device$1.devicePixelRatio+" | "+(device$1.nodeJS?"node.js":device$1.isMobile?"mobile":"desktop")+" | "+device$1.getScreenOrientation()+" | "+device$1.language),console.log("resolution: requested "+t+"x"+e+", got "+renderer.getWidth()+"x"+renderer.getHeight())}return emit(VIDEO_INIT),!0}function createCanvas(t,e,i){var r;if(void 0===i&&(i=!1),0===t||0===e)throw new Error("width or height was zero, Canvas could not be initialized !");return!0===device$1.OffscreenCanvas&&!0===i?void 0===(r=new OffscreenCanvas(0,0)).style&&(r.style={}):r=document.createElement("canvas"),r.width=t,r.height=e,r}function getParent(){return parent}function scale(t,e){var i=renderer.getScreenCanvas(),r=renderer.getScreenContext(),o=renderer.settings,n=device$1.devicePixelRatio,s=o.zoomX=i.width*t*n,a=o.zoomY=i.height*e*n;scaleRatio.set(t*n,e*n),i.style.width=s/n+"px",i.style.height=a/n+"px",renderer.setAntiAlias(r,o.antiAlias),renderer.setBlendMode(o.blendMode,r),repaint()}var video=Object.freeze({__proto__:null,CANVAS:CANVAS,WEBGL:WEBGL,AUTO:AUTO,get parent(){return parent},scaleRatio:scaleRatio,get renderer(){return renderer},init:init,createCanvas:createCanvas,getParent:getParent,scale:scale}),GUID_base="",GUID_index=0,utils={agent:agentUtils,array:arrayUtils,file:fileUtils,string:stringUtils,function:fnUtils,getPixels:function(t){if(t instanceof HTMLImageElement){var e=CanvasRenderer.getContext2d(createCanvas(t.width,t.height));return e.drawImage(t,0,0),e.getImageData(0,0,t.width,t.height)}return t.getContext("2d").getImageData(0,0,t.width,t.height)},checkVersion:function(t,e){void 0===e&&(e=version);for(var i=t.split("."),r=e.split("."),o=Math.min(i.length,r.length),n=0,s=0;s<o&&!(n=+i[s]-+r[s]);s++);return n||i.length-r.length},getUriFragment:function(t){var e={};if(void 0===t){if(void 0===globalThis.document)return e;var i=globalThis.document.location;if(!i||!i.hash)return e;t=i.hash}else{var r=t.indexOf("#");if(-1===r)return e;t=t.substr(r,t.length)}return t.substr(1).split("&").filter((function(t){return""!==t})).forEach((function(t){var i=t.split("="),r=i.shift(),o=i.join("=");e[r]=o||!0})),e},resetGUID:function(t,e){void 0===e&&(e=0),GUID_base=toHex$1(t.toString().toUpperCase()),GUID_index=e},createGUID:function(t){return void 0===t&&(t=1),GUID_index+=t,GUID_base+"-"+(t||GUID_index)}},framecount=0,framedelta=0,last=0,now=0,delta=0,step=0,minstep=0,timers=[],timerId=0;function update(t){last=now,(delta=(now=t)-last)<0&&(delta=0),timer.tick=delta>minstep&&timer.interpolation?delta/step:1,updateTimers()}function clearTimer(t){for(var e=0,i=timers.length;e<i;e++)if(timers[e].timerId===t){timers.splice(e,1);break}}function updateTimers(){for(var t=0,e=timers.length;t<e;t++){var i=timers[t];i.pauseable&&state.isPaused()||(i.elapsed+=delta),i.elapsed>=i.delay&&(i.fn.apply(null,i.args),!0===i.repeat?i.elapsed-=i.delay:timer.clearTimeout(i.timerId))}}on(BOOT,(function(){timer.reset(),now=last=0,on(GAME_BEFORE_UPDATE,update)}));var timer={tick:1,fps:0,maxfps:60,interpolation:!1,reset:function(){last=now=globalThis.performance.now(),delta=0,framedelta=0,framecount=0,step=Math.ceil(1e3/this.maxfps),minstep=1e3/this.maxfps*1.25},setTimeout:function(t,e,i){for(var r=[],o=arguments.length-3;o-- >0;)r[o]=arguments[o+3];return timers.push({fn:t,delay:e,elapsed:0,repeat:!1,timerId:++timerId,pauseable:!0===i||!0,args:r}),timerId},setInterval:function(t,e,i){for(var r=[],o=arguments.length-3;o-- >0;)r[o]=arguments[o+3];return timers.push({fn:t,delay:e,elapsed:0,repeat:!0,timerId:++timerId,pauseable:!0===i||!0,args:r}),timerId},clearTimeout:function(t){utils.function.defer(clearTimer,this,t)},clearInterval:function(t){utils.function.defer(clearTimer,this,t)},getTime:function(){return now},getDelta:function(){return delta},countFPS:function(){framecount++,framedelta+=delta,framecount%10==0&&(this.fps=clamp(Math.round(1e3*framecount/framedelta),0,this.maxfps),framedelta=0,framecount=0)}},timer$1=timer,lastTime=0,vendors=["ms","moz","webkit","o"],x,requestAnimationFrame=globalThis.requestAnimationFrame,cancelAnimationFrame=globalThis.cancelAnimationFrame;for(x=0;x<vendors.length&&!requestAnimationFrame;++x)requestAnimationFrame=globalThis[vendors[x]+"RequestAnimationFrame"];for(x=0;x<vendors.length&&!cancelAnimationFrame;++x)cancelAnimationFrame=globalThis[vendors[x]+"CancelAnimationFrame"]||globalThis[vendors[x]+"CancelRequestAnimationFrame"];requestAnimationFrame&&cancelAnimationFrame||(requestAnimationFrame=function(t){var e=globalThis.performance.now(),i=Math.max(0,1e3/timer$1.maxfps-(e-lastTime)),r=globalThis.setTimeout((function(){t(e+i)}),i);return lastTime=e+i,r},cancelAnimationFrame=function(t){globalThis.clearTimeout(t)},globalThis.requestAnimationFrame=requestAnimationFrame,globalThis.cancelAnimationFrame=cancelAnimationFrame);var plugins={},BasePlugin=function(){this.version="10.7.1"},plugin={Base:BasePlugin,patch:function(t,e,i){if(void 0!==t.prototype&&(t=t.prototype),"function"!=typeof t[e])throw new Error(e+" is not an existing function");var r=t[e];Object.defineProperty(t,e,{configurable:!0,value:function(t,e){return function(){this._patched=r;var t=e.apply(this,arguments);return this._patched=null,t}}(0,i)})},register:function(t,e){if(plugins[e])throw new Error("plugin "+e+" already registered");var i=[];arguments.length>2&&(i=Array.prototype.slice.call(arguments,1)),i[0]=t;var r=new(t.bind.apply(t,i));if(void 0===r||!(r instanceof plugin.Base))throw new Error("Plugin should extend the me.plugin.Base Class !");if(utils.checkVersion(r.version)>0)throw new Error("Plugin version mismatch, expected: "+r.version+", got: "+version);plugins[e]=r}},Easing={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-Easing.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*Easing.Bounce.In(2*t):.5*Easing.Bounce.Out(2*t-1)+.5}}},Interpolation={Linear:function(t,e){var i=t.length-1,r=i*e,o=Math.floor(r),n=Interpolation.Utils.Linear;return e<0?n(t[0],t[1],r):e>1?n(t[i],t[i-1],i-r):n(t[o],t[o+1>i?i:o+1],r-o)},Bezier:function(t,e){var i,r=0,o=t.length-1,n=Math.pow,s=Interpolation.Utils.Bernstein;for(i=0;i<=o;i++)r+=n(1-e,o-i)*n(e,i)*t[i]*s(o,i);return r},CatmullRom:function(t,e){var i=t.length-1,r=i*e,o=Math.floor(r),n=Interpolation.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(o=Math.floor(r=i*(1+e))),n(t[(o-1+i)%i],t[o],t[(o+1)%i],t[(o+2)%i],r-o)):e<0?t[0]-(n(t[0],t[0],t[1],t[1],-r)-t[0]):e>1?t[i]-(n(t[i],t[i],t[i-1],t[i-1],r-i)-t[i]):n(t[o?o-1:0],t[o],t[i<o+1?i:o+1],t[i<o+2?i:o+2],r-o)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=Interpolation.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:function(){var t=[1];return function(e){var i,r=1;if(t[e])return t[e];for(i=e;i>1;i--)r*=i;return t[e]=r,r}}(),CatmullRom:function(t,e,i,r,o){var n=.5*(i-t),s=.5*(r-e),a=o*o;return(2*e-2*i+n+s)*(o*a)+(-3*e+3*i-2*n-s)*a+n*o+e}}},Tween=function(t){this.setProperties(t)},staticAccessors={Easing:{configurable:!0},Interpolation:{configurable:!0}};function setContextStyle(t,e,i){void 0===i&&(i=!1),t.font=e.font,t.fillStyle=e.fillStyle.toRGBA(),!0===i&&(t.strokeStyle=e.strokeStyle.toRGBA(),t.lineWidth=e.lineWidth),t.textAlign=e.textAlign,t.textBaseline=e.textBaseline}Tween.prototype.onResetEvent=function(t){this.setProperties(t)},Tween.prototype.setProperties=function(t){for(var e in this._object=t,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._repeat=0,this._yoyo=!1,this._reversed=!1,this._delayTime=0,this._startTime=null,this._easingFunction=Easing.Linear.None,this._interpolationFunction=Interpolation.Linear,this._chainedTweens=[],this._onStartCallback=null,this._onStartCallbackFired=!1,this._onUpdateCallback=null,this._onCompleteCallback=null,this._tweenTimeTracker=lastUpdate,this.isPersistent=!1,this.updateWhenPaused=!1,this.isRenderable=!1,t)"object"!=typeof t&&(this._valuesStart[e]=parseFloat(t[e]))},Tween.prototype._resumeCallback=function(t){this._startTime&&(this._startTime+=t)},Tween.prototype.onActivateEvent=function(){on(STATE_RESUME,this._resumeCallback,this)},Tween.prototype.onDeactivateEvent=function(){off(STATE_RESUME,this._resumeCallback)},Tween.prototype.to=function(t,e){return this._valuesEnd=t,void 0!==e&&("number"==typeof e?this._duration=e:"object"==typeof e&&(e.duration&&(this._duration=e.duration),e.yoyo&&this.yoyo(e.yoyo),e.easing&&this.easing(e.easing),e.repeat&&this.repeat(e.repeat),e.delay&&this.delay(e.delay),e.interpolation&&this.interpolation(e.interpolation),e.autoStart&&this.start())),this},Tween.prototype.start=function(t){for(var e in void 0===t&&(t=timer$1.getTime()),this._onStartCallbackFired=!1,world.addChild(this),this._startTime=t+this._delayTime,this._valuesEnd){if(this._valuesEnd[e]instanceof Array){if(0===this._valuesEnd[e].length)continue;this._valuesEnd[e]=[this._object[e]].concat(this._valuesEnd[e])}this._valuesStart[e]=this._object[e],this._valuesStart[e]instanceof Array==!1&&(this._valuesStart[e]*=1),this._valuesStartRepeat[e]=this._valuesStart[e]||0}return this},Tween.prototype.stop=function(){return world.removeChildNow(this),this},Tween.prototype.delay=function(t){return this._delayTime=t,this},Tween.prototype.repeat=function(t){return this._repeat=t,this},Tween.prototype.yoyo=function(t){return this._yoyo=t,this},Tween.prototype.easing=function(t){if("function"!=typeof t)throw new Error("invalid easing function for me.Tween.easing()");return this._easingFunction=t,this},Tween.prototype.interpolation=function(t){return this._interpolationFunction=t,this},Tween.prototype.chain=function(){return this._chainedTweens=arguments,this},Tween.prototype.onStart=function(t){return this._onStartCallback=t,this},Tween.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},Tween.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},Tween.prototype.update=function(t){this._tweenTimeTracker=lastUpdate>this._tweenTimeTracker?lastUpdate:this._tweenTimeTracker+t;var e,i=this._tweenTimeTracker;if(i<this._startTime)return!0;!1===this._onStartCallbackFired&&(null!==this._onStartCallback&&this._onStartCallback.call(this._object),this._onStartCallbackFired=!0);var r=(i-this._startTime)/this._duration;r=r>1?1:r;var o=this._easingFunction(r);for(e in this._valuesEnd){var n=this._valuesStart[e]||0,s=this._valuesEnd[e];s instanceof Array?this._object[e]=this._interpolationFunction(s,o):("string"==typeof s&&(s=n+parseFloat(s)),"number"==typeof s&&(this._object[e]=n+(s-n)*o))}if(null!==this._onUpdateCallback&&this._onUpdateCallback.call(this._object,o),1===r){if(this._repeat>0){for(e in isFinite(this._repeat)&&this._repeat--,this._valuesStartRepeat){if("string"==typeof this._valuesEnd[e]&&(this._valuesStartRepeat[e]=this._valuesStartRepeat[e]+parseFloat(this._valuesEnd[e])),this._yoyo){var a=this._valuesStartRepeat[e];this._valuesStartRepeat[e]=this._valuesEnd[e],this._valuesEnd[e]=a}this._valuesStart[e]=this._valuesStartRepeat[e]}return this._yoyo&&(this._reversed=!this._reversed),this._startTime=i+this._delayTime,!0}world.removeChildNow(this),null!==this._onCompleteCallback&&this._onCompleteCallback.call(this._object);for(var h=0,l=this._chainedTweens.length;h<l;h++)this._chainedTweens[h].start(i);return!1}return!0},staticAccessors.Easing.get=function(){return Easing},staticAccessors.Interpolation.get=function(){return Interpolation},Object.defineProperties(Tween,staticAccessors);var TextMetrics=function(t){function e(e){t.call(this),this.ancestor=e,this.setMinMax(0,0,0,0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.lineHeight=function(){return this.ancestor instanceof Text?this.ancestor.fontSize*this.ancestor.lineHeight:this.ancestor.fontData.capHeight*this.ancestor.lineHeight*this.ancestor.fontScale.y},e.prototype.lineWidth=function(t,e){if(this.ancestor instanceof Text)return e.measureText(t).width;for(var i=t.split(""),r=0,o=null,n=0;n<i.length;n++){var s=i[n].charCodeAt(0),a=this.ancestor.fontData.glyphs[s],h=o&&o.kerning?o.getKerning(s):0;r+=(a.xadvance+h)*this.ancestor.fontScale.x,o=a}return r},e.prototype.measureText=function(t,e){var i;i=Array.isArray(t)?t:(""+t).split("\n"),void 0!==e&&(e.save(),setContextStyle(e,this.ancestor)),this.width=this.height=0;for(var r=0;r<i.length;r++)this.width=Math.max(this.lineWidth(trimRight(i[r]),e),this.width),this.height+=this.lineHeight();return this.width=Math.ceil(this.width),this.height=Math.ceil(this.height),this.x=Math.floor("right"===this.ancestor.textAlign?this.ancestor.pos.x-this.width:"center"===this.ancestor.textAlign?this.ancestor.pos.x-this.width/2:this.ancestor.pos.x),this.y=Math.floor(0===this.ancestor.textBaseline.search(/^(top|hanging)$/)?this.ancestor.pos.y:"middle"===this.ancestor.textBaseline?this.ancestor.pos.y-this.lineHeight()/2:this.ancestor.pos.y-this.lineHeight()),void 0!==e&&e.restore(),this},e.prototype.wordWrap=function(t,e,i){var r,o="",n=[];Array.isArray(t)&&(t=t.join(" ")),r=t.replace(/[\r\n]+/g," ").split(" "),void 0!==i&&(i.save(),setContextStyle(i,this.ancestor));for(var s=0;s<r.length;s++){var a=r[s];this.lineWidth(o+a+" ",i)<e?o+=a+" ":(n.push(o+"\n"),o=a+" ")}return n.push(o),void 0!==i&&i.restore(),n},e}(Bounds$1),runits=["ex","em","pt","px"],toPX=[12,24,.75,1],getContext2d=function(t,e){return!0===e.offScreenCanvas?e.context:t.getFontContext()},Text=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.onResetEvent(e,i,r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e,i){void 0!==i.fillStyle?i.fillStyle instanceof Color?this.fillStyle=i.fillStyle:this.fillStyle=pull("Color").parseCSS(i.fillStyle):this.fillStyle=pull("Color",0,0,0),void 0!==i.strokeStyle?i.strokeStyle instanceof Color?this.strokeStyle=i.strokeStyle:this.strokeStyle=pull("Color").parseCSS(i.strokeStyle):this.strokeStyle=pull("Color",0,0,0),this.lineWidth=i.lineWidth||1,this.textAlign=i.textAlign||"left",this.textBaseline=i.textBaseline||"top",this.lineHeight=i.lineHeight||1,this.offScreenCanvas=!1,this.wordWrapWidth=i.wordWrapWidth||-1,this._text=[],this.fontSize=10,void 0!==i.anchorPoint?this.anchorPoint.setV(i.anchorPoint):this.anchorPoint.set(0,0),void 0!==i.floating&&(this.floating=!!i.floating),this.setFont(i.font,i.size),!0===i.bold&&this.bold(),!0===i.italic&&this.italic(),!0===i.offScreenCanvas&&(this.offScreenCanvas=!0,this.canvas=createCanvas(2,2,!0),this.context=this.canvas.getContext("2d")),this.metrics=new TextMetrics(this),this.setText(i.text)},e.prototype.onDeactivateEvent=function(){!0===this.offScreenCanvas&&(renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit)),renderer.cache.delete(this.canvas),this.canvas.width=this.canvas.height=0,this.context=void 0,this.canvas=void 0,this.glTextureUnit=void 0)},e.prototype.bold=function(){return this.font="bold "+this.font,this.isDirty=!0,this},e.prototype.italic=function(){return this.font="italic "+this.font,this.isDirty=!0,this},e.prototype.setFont=function(t,e){void 0===e&&(e=10);var i=t.split(",").map((function(t){return t=t.trim(),/(^".*"$)|(^'.*'$)/.test(t)?t:'"'+t+'"'}));if("number"==typeof e)this.fontSize=e,e+="px";else{var r=e.match(/([-+]?[\d.]*)(.*)/);this.fontSize=parseFloat(r[1]),r[2]?this.fontSize*=toPX[runits.indexOf(r[2])]:e+="px"}return this.height=this.fontSize,this.font=e+" "+i.join(","),this.isDirty=!0,this},e.prototype.setText=function(t){void 0===t&&(t="");var e=this.getBounds();if(this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n")),this._text.length>0&&this.wordWrapWidth>0&&(this._text=this.metrics.wordWrap(this._text,this.wordWrapWidth,getContext2d(renderer,this))),e.addBounds(this.metrics.measureText(this._text,getContext2d(renderer,this)),!0),!0===this.offScreenCanvas){var i=Math.ceil(this.metrics.width),r=Math.ceil(this.metrics.height);renderer instanceof WebGLRenderer&&(this.glTextureUnit=renderer.cache.getUnit(renderer.cache.get(this.canvas)),renderer.currentCompositor.unbindTexture2D(null,this.glTextureUnit),1===renderer.WebGLVersion&&(i=nextPowerOfTwo(this.metrics.width),r=nextPowerOfTwo(this.metrics.height))),this.canvas.width<i||this.canvas.height<r?(this.canvas.width=i,this.canvas.height=r):this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this._drawFont(this.context,this._text,this.pos.x-this.metrics.x,this.pos.y-this.metrics.y,!1)}return this.isDirty=!0,this},e.prototype.measureText=function(t,e){return void 0===t&&(t=renderer),void 0===e&&(e=this._text),this.metrics.measureText(e,getContext2d(t,this))},e.prototype.draw=function(t,e,i,r,o){void 0===this.ancestor?(this.pos.x===i&&this.pos.y===r||(this.pos.x=i,this.pos.y=r,this.isDirty=!0),this.setText(e),i=this.metrics.x,r=this.metrics.y,t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity())):(i=this.pos.x,r=this.pos.y),!1===t.settings.subPixel&&(i=~~i,r=~~r),!0===this.offScreenCanvas?t.drawImage(this.canvas,i,r):t.drawFont(this._drawFont(t.getFontContext(),this._text,i,r,o)),void 0===this.ancestor&&t.restore()},e.prototype.drawStroke=function(t,e,i,r){this.draw(t,e,i,r,!0)},e.prototype._drawFont=function(t,e,i,r,o){void 0===o&&(o=!1),setContextStyle(t,this,o);for(var n=0;n<e.length;n++){var s=trimRight(e[n]);t[o?"strokeText":"fillText"](s,i,r),r+=this.metrics.lineHeight()}return this.metrics},e.prototype.destroy=function(){push(this.fillStyle),push(this.strokeStyle),this.fillStyle=this.strokeStyle=void 0,this.metrics=void 0,this._text.length=0,t.prototype.destroy.call(this)},e}(Renderable),BitmapText=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.textAlign=r.textAlign||"left",this.textBaseline=r.textBaseline||"top",this.lineHeight=r.lineHeight||1,this.wordWrapWidth=r.wordWrapWidth||-1,this._text=[],this.fontScale=pull("Vector2d",1,1),this.fontImage="object"==typeof r.font?r.font:loader.getImage(r.font),"string"!=typeof r.fontData?this.fontData=pull("BitmapTextData",loader.getBinary(r.font)):this.fontData=pull("BitmapTextData",r.fontData.includes("info face")?r.fontData:loader.getBinary(r.fontData)),void 0!==r.floating&&(this.floating=!!r.floating),void 0!==r.fillStyle&&(r.fillStyle instanceof Color?this.fillStyle.setColor(r.fillStyle):this.fillStyle.parseCSS(r.fillStyle)),void 0!==r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0),this.metrics=new TextMetrics(this),"number"==typeof r.size&&1!==r.size&&this.resize(r.size),this.setText(r.text)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={fillStyle:{configurable:!0}};return e.prototype.set=function(t,e){return this.textAlign=t,e&&this.resize(e),this.isDirty=!0,this},e.prototype.setText=function(t){return void 0===t&&(t=""),this._text.toString()!==t.toString()&&(Array.isArray(t)?this._text=t:this._text=(""+t).split("\n"),this.isDirty=!0),this._text.length>0&&this.wordWrapWidth>0&&(this._text=this.metrics.wordWrap(this._text,this.wordWrapWidth)),this.getBounds().addBounds(this.metrics.measureText(this._text),!0),this},i.fillStyle.get=function(){return this.tint},i.fillStyle.set=function(t){this.tint=t},e.prototype.resize=function(t){return this.fontScale.set(t,t),this.getBounds().addBounds(this.metrics.measureText(this._text),!0),this.isDirty=!0,this},e.prototype.measureText=function(t){return void 0===t&&(t=this._text),this.metrics.measureText(t)},e.prototype.draw=function(t,e,i,r){var o=t.globalAlpha();void 0===this.ancestor?(this.setText(e),t.setGlobalAlpha(o*this.getOpacity())):(i=this.pos.x,r=this.pos.y);for(var n=i,s=this.metrics.lineHeight(),a=0,h=0;h<this._text.length;h++){i=n;var l=trimRight(this._text[h]),c=this.metrics.lineWidth(l);switch(this.textAlign){case"right":i-=c;break;case"center":i-=.5*c}switch(this.textBaseline){case"middle":r-=.5*s;break;case"ideographic":case"alphabetic":case"bottom":r-=s}!0===this.isDirty&&void 0===this.ancestor&&(0===h&&(this.pos.y=r),a<c&&(a=c,this.pos.x=i));for(var u=null,d=0,p=l.length;d<p;d++){var f=l.charCodeAt(d),y=this.fontData.glyphs[f],g=y.width,v=y.height,m=u&&u.kerning?u.getKerning(f):0;0!==g&&0!==v&&t.drawImage(this.fontImage,y.x,y.y,g,v,i+y.xoffset,r+y.yoffset*this.fontScale.y,g*this.fontScale.x,v*this.fontScale.y),i+=(y.xadvance+m)*this.fontScale.x,u=y}r+=s}void 0===this.ancestor&&t.setGlobalAlpha(o),this.isDirty=!1},e.prototype.destroy=function(){push(this.fontScale),this.fontScale=void 0,push(this.fontData),this.fontData=void 0,this._text.length=0,this.metrics=void 0,t.prototype.destroy.call(this)},Object.defineProperties(e.prototype,i),e}(Renderable),LOG2_PAGE_SIZE=9,PAGE_SIZE=1<<LOG2_PAGE_SIZE,Glyph=function(){this.id=0,this.x=0,this.y=0,this.width=0,this.height=0,this.u=0,this.v=0,this.u2=0,this.v2=0,this.xoffset=0,this.yoffset=0,this.xadvance=0,this.fixedWidth=!1};Glyph.prototype.getKerning=function(t){if(this.kerning){var e=this.kerning[t>>>LOG2_PAGE_SIZE];if(e)return e[t&PAGE_SIZE-1]||0}return 0},Glyph.prototype.setKerning=function(t,e){this.kerning||(this.kerning={});var i=this.kerning[t>>>LOG2_PAGE_SIZE];void 0===i&&(this.kerning[t>>>LOG2_PAGE_SIZE]={},i=this.kerning[t>>>LOG2_PAGE_SIZE]),i[t&PAGE_SIZE-1]=e};var capChars=["M","N","B","D","C","E","F","K","A","G","H","I","J","L","O","P","Q","R","S","T","U","V","W","X","Y","Z"];function getValueFromPair(t,e){var i=t.match(e);if(!i)throw new Error("Could not find pattern "+e+" in string: "+t);return i[0].split("=")[1]}function getFirstGlyph(t){for(var e=Object.keys(t),i=0;i<e.length;i++)if(e[i]>32)return t[e[i]];return null}function createSpaceGlyph(t){var e=" ".charCodeAt(0),i=t[e];i||((i=new Glyph).id=e,i.xadvance=getFirstGlyph(t).xadvance,t[e]=i)}var BitmapTextData=function(t){this.onResetEvent(t)};BitmapTextData.prototype.onResetEvent=function(t){this.padTop=0,this.padRight=0,this.padBottom=0,this.padLeft=0,this.lineHeight=0,this.capHeight=1,this.descent=0,this.glyphs={},this.parse(t)},BitmapTextData.prototype.parse=function(t){if(!t)throw new Error("File containing font data was empty, cannot load the bitmap font.");var e=t.split(/\r\n|\n/),i=t.match(/padding\=\d+,\d+,\d+,\d+/g);if(!i)throw new Error("Padding not found in first line");var r=i[0].split("=")[1].split(",");this.padTop=parseFloat(r[0]),this.padLeft=parseFloat(r[1]),this.padBottom=parseFloat(r[2]),this.padRight=parseFloat(r[3]),this.lineHeight=parseFloat(getValueFromPair(e[1],/lineHeight\=\d+/g));var o,n=parseFloat(getValueFromPair(e[1],/base\=\d+/g)),s=this.padTop+this.padBottom,a=null;for(o=4;o<e.length;o++){var h=e[o],l=h.split(/=|\s+/);if(h&&!/^kernings/.test(h))if(/^kerning\s/.test(h)){var c=parseFloat(l[2]),u=parseFloat(l[4]),d=parseFloat(l[6]);null!=(a=this.glyphs[c])&&a.setKerning(u,d)}else{a=new Glyph;var p=parseFloat(l[2]);a.id=p,a.x=parseFloat(l[4]),a.y=parseFloat(l[6]),a.width=parseFloat(l[8]),a.height=parseFloat(l[10]),a.xoffset=parseFloat(l[12]),a.yoffset=parseFloat(l[14]),a.xadvance=parseFloat(l[16]),a.width>0&&a.height>0&&(this.descent=Math.min(n+a.yoffset,this.descent)),this.glyphs[p]=a}}this.descent+=this.padBottom,createSpaceGlyph(this.glyphs);var f=null;for(o=0;o<capChars.length;o++){var y=capChars[o];if(f=this.glyphs[y.charCodeAt(0)])break}if(f)this.capHeight=f.height;else for(var g in this.glyphs)if(this.glyphs.hasOwnProperty(g)){if(0===(a=this.glyphs[g]).height||0===a.width)continue;this.capHeight=Math.max(this.capHeight,a.height)}this.capHeight-=s};var ColorLayer=function(t){function e(e,i,r){t.call(this,0,0,1/0,1/0),this.color=pull("Color").parseCSS(i),this.onResetEvent(e,i,r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e,i){void 0===i&&(i=0),this.name=t,this.pos.z=i,this.floating=!0,this.color.parseCSS(e)},e.prototype.draw=function(t,e){var i=viewport.pos;t.save(),t.clipRect(e.left-i.x,e.top-i.y,e.width,e.height),t.clearColor(this.color),t.restore()},e.prototype.destroy=function(){push(this.color),this.color=void 0,t.prototype.destroy.call(this)},e}(Renderable),ImageLayer=function(t){function e(e,i,r){t.call(this,e,i,r),this.floating=!0,this.offset.set(e,i),this.ratio=pull("Vector2d",1,1),void 0!==r.ratio&&(isNumeric(r.ratio)?this.ratio.set(r.ratio,+r.ratio):this.ratio.setV(r.ratio)),void 0===r.anchorPoint?this.anchorPoint.set(0,0):"number"==typeof r.anchorPoint?this.anchorPoint.set(r.anchorPoint,r.anchorPoint):this.anchorPoint.setV(r.anchorPoint),this.repeat=r.repeat||"repeat",on(ONCONTEXT_RESTORED,this.createPattern,this)}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={repeat:{configurable:!0}};return i.repeat.get=function(){return this._repeat},i.repeat.set=function(t){switch(this._repeat=t,this._repeat){case"no-repeat":this.repeatX=!1,this.repeatY=!1;break;case"repeat-x":this.repeatX=!0,this.repeatY=!1;break;case"repeat-y":this.repeatX=!1,this.repeatY=!0;break;default:this.repeatX=!0,this.repeatY=!0}this.resize(viewport.width,viewport.height),this.createPattern()},e.prototype.onActivateEvent=function(){var t=this;on(VIEWPORT_ONCHANGE,this.updateLayer,this),on(VIEWPORT_ONRESIZE,this.resize,this),once(LEVEL_LOADED,(function(){t.updateLayer(viewport.pos)})),!0!==this.ancestor.root&&this.updateLayer(viewport.pos)},e.prototype.resize=function(e,i){t.prototype.resize.call(this,this.repeatX?1/0:e,this.repeatY?1/0:i)},e.prototype.createPattern=function(){this._pattern=renderer.createPattern(this.image,this._repeat)},e.prototype.updateLayer=function(t){var e=this.ratio.x,i=this.ratio.y;if(0!==e||0!==i){var r=this.width,o=this.height,n=viewport.bounds.width,s=viewport.bounds.height,a=this.anchorPoint.x,h=this.anchorPoint.y,l=a*(e-1)*(n-viewport.width)+this.offset.x-e*t.x,c=h*(i-1)*(s-viewport.height)+this.offset.y-i*t.y;this.repeatX?this.pos.x=l%r:this.pos.x=l,this.repeatY?this.pos.y=c%o:this.pos.y=c,this.isDirty=!0}},e.prototype.preDraw=function(t){t.save(),t.setGlobalAlpha(t.globalAlpha()*this.getOpacity()),t.setTint(this.tint)},e.prototype.draw=function(t){var e=this.width,i=this.height,r=viewport.bounds.width,o=viewport.bounds.height,n=this.anchorPoint.x,s=this.anchorPoint.y,a=this.pos.x,h=this.pos.y;0===this.ratio.x&&0===this.ratio.y&&(a+=n*(r-e),h+=s*(o-i)),t.translate(a,h),t.drawPattern(this._pattern,0,0,2*viewport.width,2*viewport.height)},e.prototype.onDeactivateEvent=function(){off(VIEWPORT_ONCHANGE,this.updateLayer),off(VIEWPORT_ONRESIZE,this.resize)},e.prototype.destroy=function(){push(this.ratio),this.ratio=void 0,off(ONCONTEXT_RESTORED,this.createPattern),t.prototype.destroy.call(this)},Object.defineProperties(e.prototype,i),e}(Sprite),NineSliceSprite=function(t){function e(e,i,r){if(t.call(this,e,i,r),"number"!=typeof r.width||"number"!=typeof r.height)throw new Error("height and width properties are mandatory");this.width=Math.floor(r.width),this.height=Math.floor(r.height),this.nss_width=this.width,this.nss_height=this.height,this.insetx=r.insetx,this.insety=r.insety}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.draw=function(t){var e=this.current,i=this.pos.x,r=this.pos.y,o=e.width,n=e.height,s=e.offset,a=this.offset;0!==e.angle&&(t.translate(-i,-r),t.rotate(e.angle),i-=n,o=e.height,n=e.width);var h=a.x+s.x,l=a.y+s.y,c=this.insetx||o/4,u=this.insety||n/4;t.drawImage(this.image,h,l,c,u,i,r,c,u),t.drawImage(this.image,h+o-c,l,c,u,i+this.nss_width-c,r,c,u),t.drawImage(this.image,h,l+n-u,c,u,i,r+this.nss_height-u,c,u),t.drawImage(this.image,h+o-c,l+n-u,c,u,i+this.nss_width-c,r+this.nss_height-u,c,u);var d=o-(c<<1),p=n-(u<<1),f=this.nss_width-(c<<1),y=this.nss_height-(u<<1);t.drawImage(this.image,h+c,l,d,u,i+c,r,f,u),t.drawImage(this.image,h+c,l+n-u,d,u,i+c,r+this.nss_height-u,f,u),t.drawImage(this.image,h,l+u,c,p,i,r+u,c,y),t.drawImage(this.image,h+o-c,l+u,c,p,i+this.nss_width-c,r+u,c,y),t.drawImage(this.image,h+c,l+u,d,p,i+c,r+u,f,y)},e}(Sprite),GUI_Object=function(t){function e(e,i,r){t.call(this,e,i,r),this.isClickable=!0,this.holdThreshold=250,this.isHoldable=!1,this.hover=!1,this.holdTimeout=null,this.released=!0,this.floating=!0,this.isKinematic=!1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.clicked=function(t){if(0===t.button&&this.isClickable)return this.dirty=!0,this.released=!1,this.isHoldable&&(null!==this.holdTimeout&&timer$1.clearTimeout(this.holdTimeout),this.holdTimeout=timer$1.setTimeout(this.hold.bind(this),this.holdThreshold,!1),this.released=!1),this.onClick(t)},e.prototype.onClick=function(){return!1},e.prototype.enter=function(t){return this.hover=!0,this.dirty=!0,this.onOver(t)},e.prototype.onOver=function(){},e.prototype.leave=function(t){return this.hover=!1,this.dirty=!0,this.release(t),this.onOut(t)},e.prototype.onOut=function(){},e.prototype.release=function(t){if(!1===this.released)return this.released=!0,this.dirty=!0,timer$1.clearTimeout(this.holdTimeout),this.onRelease(t)},e.prototype.onRelease=function(){return!1},e.prototype.hold=function(){timer$1.clearTimeout(this.holdTimeout),this.dirty=!0,this.released||this.onHold()},e.prototype.onHold=function(){},e.prototype.onActivateEvent=function(){registerPointerEvent("pointerdown",this,this.clicked.bind(this)),registerPointerEvent("pointerup",this,this.release.bind(this)),registerPointerEvent("pointercancel",this,this.release.bind(this)),registerPointerEvent("pointerenter",this,this.enter.bind(this)),registerPointerEvent("pointerleave",this,this.leave.bind(this))},e.prototype.onDeactivateEvent=function(){releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),releasePointerEvent("pointerenter",this),releasePointerEvent("pointerleave",this),timer$1.clearTimeout(this.holdTimeout)},e}(Sprite),Collectable=function(t){function e(e,i,r){t.call(this,e,i,r),this.name=r.name,this.type=r.type,this.id=r.id,this.body=new Body(this,r.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.COLLECTABLE_OBJECT,this.body.setCollisionMask(collision.types.PLAYER_OBJECT),this.body.setStatic(!0),r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Sprite),Trigger=function(t){function e(e,i,r){t.call(this,e,i,r.width||0,r.height||0),this.anchorPoint.set(0,0),this.fade=r.fade,this.duration=r.duration,this.fading=!1,this.name="Trigger",this.type=r.type,this.id=r.id,this.gotolevel=r.to,this.triggerSettings={event:"level"},["type","container","onLoaded","flatten","setViewportBounds","to"].forEach(function(t){void 0!==r[t]&&(this.triggerSettings[t]=r[t])}.bind(this)),this.body=new Body(this,r.shapes||new Rect(0,0,this.width,this.height)),this.body.collisionType=collision.types.ACTION_OBJECT,this.body.setCollisionMask(collision.types.PLAYER_OBJECT),this.body.setStatic(!0),this.resize(this.body.getBounds().width,this.body.getBounds().height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getTriggerSettings=function(){return"string"==typeof this.triggerSettings.container&&(this.triggerSettings.container=world.getChildByName(this.triggerSettings.container)[0]),this.triggerSettings},e.prototype.onFadeComplete=function(){level.load(this.gotolevel,this.getTriggerSettings()),viewport.fadeOut(this.fade,this.duration)},e.prototype.triggerEvent=function(){var t=this.getTriggerSettings();if("level"!==t.event)throw new Error("Trigger invalid type");this.gotolevel=t.to,this.fade&&this.duration?this.fading||(this.fading=!0,viewport.fadeIn(this.fade,this.duration,this.onFadeComplete.bind(this))):level.load(this.gotolevel,t)},e.prototype.onCollision=function(){return"Trigger"===this.name&&this.triggerEvent.apply(this),!1},e}(Renderable),Draggable=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isKinematic=!1,this.dragging=!1,this.dragId=null,this.grabOffset=new Vector2d(0,0),this.initEvents()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.initEvents=function(){var t=this;registerPointerEvent("pointerdown",this,(function(e){emit(DRAGSTART,e,t)})),registerPointerEvent("pointerup",this,(function(e){emit(DRAGEND,e,t)})),registerPointerEvent("pointercancel",this,(function(e){emit(DRAGEND,e,t)})),on(POINTERMOVE,this.dragMove.bind(this)),on(DRAGSTART,(function(e,i){i===t&&t.dragStart(e)})),on(DRAGEND,(function(e,i){i===t&&t.dragEnd(e)}))},e.prototype.dragStart=function(t){if(!1===this.dragging)return this.dragging=!0,this.grabOffset.set(t.gameX,t.gameY),this.grabOffset.sub(this.pos),!1},e.prototype.dragMove=function(t){!0===this.dragging&&(this.pos.set(t.gameX,t.gameY,this.pos.z),this.pos.sub(this.grabOffset))},e.prototype.dragEnd=function(){if(!0===this.dragging)return this.dragging=!1,!1},e.prototype.destroy=function(){off(POINTERMOVE,this.dragMove),off(DRAGSTART,this.dragStart),off(DRAGEND,this.dragEnd),releasePointerEvent("pointerdown",this),releasePointerEvent("pointerup",this),releasePointerEvent("pointercancel",this),t.prototype.destroy.call(this)},e}(Renderable),DropTarget=function(t){function e(e,i,r,o){t.call(this,e,i,r,o),this.isKinematic=!1,this.CHECKMETHOD_OVERLAP="overlaps",this.CHECKMETHOD_CONTAINS="contains",this.checkMethod=this.CHECKMETHOD_OVERLAP,on(DRAGEND,this.checkOnMe,this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.setCheckMethod=function(t){"function"==typeof this.getBounds()[this.checkMethod]&&(this.checkMethod=t)},e.prototype.checkOnMe=function(t,e){e&&this.getBounds()[this.checkMethod](e.getBounds())&&this.drop(e)},e.prototype.drop=function(){},e.prototype.destroy=function(){off(DRAGEND,this.checkOnMe),t.prototype.destroy.call(this)},e}(Renderable),ParticleEmitterSettings={width:1,height:1,image:void 0,textureSize:8,tint:"#fff",totalParticles:50,angle:Math.PI/2,angleVariation:0,minLife:1e3,maxLife:3e3,speed:2,speedVariation:1,minRotation:0,maxRotation:0,minStartScale:1,maxStartScale:1,minEndScale:0,maxEndScale:0,gravity:0,wind:0,followTrajectory:!1,textureAdditive:!1,blendMode:"normal",onlyInViewport:!0,floating:!1,maxParticles:10,frequency:100,duration:1/0,framesToSkip:0},defaultParticleTexture;function createDefaultParticleTexture(t,e){if(void 0===t&&(t=8),void 0===e&&(e=8),void 0===defaultParticleTexture){var i=(defaultParticleTexture=createCanvas(t,e,!0)).getContext("2d");i.fillStyle="#fff",i.fillRect(0,0,t,e)}return defaultParticleTexture}var ParticleEmitter=function(t){function e(e,i,r){void 0===r&&(r={}),t.call(this,e,i,1|r.width,1|r.height),this.centerOn(e,i),this._stream=!1,this._frequencyTimer=0,this._durationTimer=0,this._enabled=!1,this.alwaysUpdate=!0,this.autoSort=!1,this._updateCount=0,this.settings={},this._dt=0,this.reset(r)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.reset=function(t){void 0===t&&(t={}),Object.assign(this.settings,ParticleEmitterSettings,t),void 0===this.settings.image&&(this.settings.image=createDefaultParticleTexture(t.textureSize,t.textureSize)),this.floating=this.settings.floating,this.isDirty=!0},e.prototype.getRandomPointX=function(){return randomFloat(0,this.getBounds().width)},e.prototype.getRandomPointY=function(){return randomFloat(0,this.getBounds().height)},e.prototype.addParticles=function(t){for(var e=0;e<~~t;e++)this.addChild(pull("Particle",this),this.pos.z);this.isDirty=!0},e.prototype.isRunning=function(){return this._enabled&&this._stream},e.prototype.streamParticles=function(t){this._enabled=!0,this._stream=!0,this.settings.frequency=Math.max(1,this.settings.frequency),this._durationTimer="number"==typeof t?t:this.settings.duration},e.prototype.stopStream=function(){this._enabled=!1},e.prototype.burstParticles=function(t){this._enabled=!0,this._stream=!1,this.addParticles("number"==typeof t?t:this.settings.totalParticles),this._enabled=!1},e.prototype.update=function(e){if(++this._updateCount>this.settings.framesToSkip&&(this._updateCount=0),this._updateCount>0)return this._dt+=e,this.isDirty;if(e+=this._dt,this._dt=0,this.isDirty|=t.prototype.update.call(this,e),this._enabled&&this._stream){if(this._durationTimer!==1/0&&(this._durationTimer-=e,this._durationTimer<=0))return this.stopStream(),this.isDirty;this._frequencyTimer+=e;var i=this.children.length;i<this.settings.totalParticles&&this._frequencyTimer>=this.settings.frequency&&(i+this.settings.maxParticles<=this.settings.totalParticles?this.addParticles(this.settings.maxParticles):this.addParticles(this.settings.totalParticles-i),this._frequencyTimer=0,this.isDirty=!0)}return this.isDirty},e.prototype.destroy=function(){t.prototype.destroy.call(this,arguments),this.settings.image=void 0,this.settings=void 0},e}(Container),Particle=function(t){function e(e){t.call(this,e.getRandomPointX(),e.getRandomPointY(),e.settings.image.width,e.settings.image.height),this.onResetEvent(e,!0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.onResetEvent=function(t,e){void 0===e&&(e=!1),!1===e?(this.pos.set(t.getRandomPointX(),t.getRandomPointY()),this.resize(t.settings.image.width,t.settings.image.height)):this.vel=new Vector2d,this.image=t.settings.image,this.alwaysUpdate=!0,"string"==typeof t.settings.tint&&this.tint.parseCSS(t.settings.tint),!0===t.settings.textureAdditive&&(this.blendMode="additive"),"normal"!==t.settings.blendMode&&(this.blendMode=t.settings.blendMode);var i=t.settings.angle+(t.settings.angleVariation>0?(randomFloat(0,2)-1)*t.settings.angleVariation:0),r=t.settings.speed+(t.settings.speedVariation>0?(randomFloat(0,2)-1)*t.settings.speedVariation:0);this.vel.set(r*Math.cos(i),-r*Math.sin(i)),this.life=randomFloat(t.settings.minLife,t.settings.maxLife),this.startLife=this.life,this.startScale=clamp(randomFloat(t.settings.minStartScale,t.settings.maxStartScale),t.settings.minStartScale,t.settings.maxStartScale),this.endScale=clamp(randomFloat(t.settings.minEndScale,t.settings.maxEndScale),t.settings.minEndScale,t.settings.maxEndScale),this.gravity=t.settings.gravity,this.wind=t.settings.wind,this.followTrajectory=t.settings.followTrajectory,this.onlyInViewport=t.settings.onlyInViewport,this._deltaInv=timer$1.maxfps/1e3,t.settings.followTrajectory||(this.angle=randomFloat(t.settings.minRotation,t.settings.maxRotation))},e.prototype.update=function(e){var i=e*this._deltaInv;if(this.life=this.life>e?this.life-e:0,this.life<=0)return this.ancestor.removeChild(this),!1;var r=this.life/this.startLife,o=this.startScale;this.startScale>this.endScale?o=(o*=r)<this.endScale?this.endScale:o:this.startScale<this.endScale&&(o=(o/=r)>this.endScale?this.endScale:o),this.alpha=r,this.vel.x+=this.wind*i,this.vel.y+=this.gravity*i;var n=this.followTrajectory?Math.atan2(this.vel.y,this.vel.x):this.angle;return this.pos.x+=this.vel.x*i,this.pos.y+=this.vel.y*i,this.currentTransform.setTransform(o,0,0,0,o,0,this.pos.x,this.pos.y,1).rotate(n),this.isDirty=this.inViewport||!this.onlyInViewport,t.prototype.update.call(this,e)},e.prototype.draw=function(t){var e=this.width,i=this.height;t.drawImage(this.image,0,0,e,i,-e/2,-i/2,e,i)},e}(Renderable),Entity=function(t){function e(e,i,r){if("number"!=typeof r.width||"number"!=typeof r.height)throw new Error("height and width properties are mandatory when passing settings parameters to an object entity");t.call(this,e,i,r.width,r.height),this.children=[],r.image&&(r.framewidth=r.framewidth||r.width,r.frameheight=r.frameheight||r.height,this.renderable=new Sprite(0,0,r)),r.anchorPoint?this.anchorPoint.set(r.anchorPoint.x,r.anchorPoint.y):this.anchorPoint.set(0,0),"string"==typeof r.name&&(this.name=r.name),this.type=r.type||"",this.id=r.id||"",this.alive=!0,void 0===r.shapes&&(r.shapes=new Polygon(0,0,[new Vector2d(0,0),new Vector2d(this.width,0),new Vector2d(this.width,this.height),new Vector2d(0,this.height)])),this.body=new Body(this,r.shapes,this.onBodyUpdate.bind(this)),0===this.width&&0===this.height&&this.resize(this.body.getBounds().width,this.body.getBounds().height),this.body.setCollisionMask(r.collisionMask),this.body.setCollisionType(r.collisionType),this.autoTransform=!1}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var i={renderable:{configurable:!0}};return i.renderable.get=function(){return this.children[0]},i.renderable.set=function(e){if(!(e instanceof t))throw new Error(e+"should extend me.Renderable");this.children[0]=e,this.children[0].ancestor=this},e.prototype.update=function(e){return this.renderable&&(this.isDirty|=this.renderable.update(e)),t.prototype.update.call(this,e)},e.prototype.onBodyUpdate=function(t){this.getBounds().addBounds(t.getBounds(),!0),this.updateBoundsPos(this.pos.x,this.pos.y)},e.prototype.preDraw=function(e){e.save(),e.translate(this.pos.x+this.body.getBounds().x,this.pos.y+this.body.getBounds().y),this.renderable instanceof t&&e.translate(this.anchorPoint.x*this.body.getBounds().width,this.anchorPoint.y*this.body.getBounds().height)},e.prototype.draw=function(e,i){var r=this.renderable;r instanceof t&&(r.preDraw(e),r.draw(e,i),r.postDraw(e))},e.prototype.destroy=function(){this.renderable&&(this.renderable.destroy.apply(this.renderable,arguments),this.children.splice(0,1)),t.prototype.destroy.call(this,arguments)},e.prototype.onDeactivateEvent=function(){this.renderable&&this.renderable.onDeactivateEvent&&this.renderable.onDeactivateEvent()},Object.defineProperties(e.prototype,i),e}(Renderable);function warning(t,e,i){var r="melonJS: %s is deprecated since version %s, please use %s",o=(new Error).stack;console.groupCollapsed?console.groupCollapsed("%c"+r,"font-weight:normal;color:yellow;",t,i,e):console.warn(r,t,i,e),void 0!==o&&console.warn(o),console.groupCollapsed&&console.groupEnd()}device$1.turnOnPointerLock=function(){return warning("device.turnOnPointerLock()","input.requestPointerLock()","10.3.0"),requestPointerLock()},device$1.turnOffPointerLock=function(){return warning("device.turnOffPointerLock()","input.exitPointerLock()","10.3.0"),exitPointerLock()},Object.defineProperty(Renderer.prototype,"Texture",{get:function(){return warning("me.video.renderer.Texture","me.TextureAtlas","10.4.0"),TextureAtlas}});var DraggableEntity=function(t){function e(e,i,r){warning("DraggableEntity","Draggable","10.5.0"),t.call(this,e,i,r.width,r.height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(Draggable),DroptargetEntity=function(t){function e(e,i,r){warning("DroptargetEntity","DropTarget","10.5.0"),t.call(this,e,i,r.width,r.height)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e}(DropTarget),version="10.7.1";exports.initialized=!1;var skipAutoInit=!1;function boot(){!0!==exports.initialized&&(register("me.Entity",Entity),register("me.Collectable",Collectable),register("me.Trigger",Trigger),register("me.Tween",Tween,!0),register("me.Color",Color,!0),register("me.Particle",Particle,!0),register("me.Sprite",Sprite),register("me.NineSliceSprite",NineSliceSprite),register("me.Renderable",Renderable),register("me.Text",Text,!0),register("me.BitmapText",BitmapText),register("me.BitmapTextData",BitmapTextData,!0),register("me.ImageLayer",ImageLayer),register("me.ColorLayer",ColorLayer,!0),register("me.Vector2d",Vector2d,!0),register("me.Vector3d",Vector3d,!0),register("me.ObservableVector2d",ObservableVector2d,!0),register("me.ObservableVector3d",ObservableVector3d,!0),register("me.Matrix2d",Matrix2d,!0),register("me.Matrix3d",Matrix3d,!0),register("me.Rect",Rect,!0),register("me.Polygon",Polygon,!0),register("me.Line",Line,!0),register("me.Ellipse",Ellipse,!0),register("me.Bounds",Bounds$1,!0),register("Entity",Entity),register("Collectable",Collectable),register("Trigger",Trigger),register("Tween",Tween,!0),register("Color",Color,!0),register("Particle",Particle,!0),register("Sprite",Sprite),register("NineSliceSprite",NineSliceSprite),register("Renderable",Renderable),register("Text",Text,!0),register("BitmapText",BitmapText),register("BitmapTextData",BitmapTextData,!0),register("ImageLayer",ImageLayer),register("ColorLayer",ColorLayer,!0),register("Vector2d",Vector2d,!0),register("Vector3d",Vector3d,!0),register("ObservableVector2d",ObservableVector2d,!0),register("ObservableVector3d",ObservableVector3d,!0),register("Matrix2d",Matrix2d,!0),register("Matrix3d",Matrix3d,!0),register("Rect",Rect,!0),register("Polygon",Polygon,!0),register("Line",Line,!0),register("Ellipse",Ellipse,!0),register("Bounds",Bounds$1,!0),emit(BOOT),loader.setNocache(utils.getUriFragment().nocache||!1),initKeyboardEvent(),exports.initialized=!0)}device$1.onReady((function(){boot()})),exports.BitmapText=BitmapText,exports.BitmapTextData=BitmapTextData,exports.Body=Body,exports.Bounds=Bounds$1,exports.Camera2d=Camera2d,exports.CanvasRenderer=CanvasRenderer,exports.Collectable=Collectable,exports.Color=Color,exports.ColorLayer=ColorLayer,exports.Container=Container,exports.Draggable=Draggable,exports.DraggableEntity=DraggableEntity,exports.DropTarget=DropTarget,exports.DroptargetEntity=DroptargetEntity,exports.Ellipse=Ellipse,exports.Entity=Entity,exports.GLShader=GLShader,exports.GUI_Object=GUI_Object,exports.ImageLayer=ImageLayer,exports.Line=Line,exports.Math=math,exports.Matrix2d=Matrix2d,exports.Matrix3d=Matrix3d,exports.NineSliceSprite=NineSliceSprite,exports.ObservableVector2d=ObservableVector2d,exports.ObservableVector3d=ObservableVector3d,exports.Particle=Particle,exports.ParticleEmitter=ParticleEmitter,exports.ParticleEmitterSettings=ParticleEmitterSettings,exports.Pointer=Pointer,exports.Polygon=Polygon,exports.QuadTree=QuadTree,exports.Rect=Rect,exports.Renderable=Renderable,exports.Renderer=Renderer,exports.Sprite=Sprite,exports.Stage=Stage,exports.TMXHexagonalRenderer=TMXHexagonalRenderer,exports.TMXIsometricRenderer=TMXIsometricRenderer,exports.TMXLayer=TMXLayer,exports.TMXOrthogonalRenderer=TMXOrthogonalRenderer,exports.TMXRenderer=TMXRenderer,exports.TMXStaggeredRenderer=TMXStaggeredRenderer,exports.TMXTileMap=TMXTileMap,exports.TMXTileset=TMXTileset,exports.TMXTilesetGroup=TMXTilesetGroup,exports.Text=Text,exports.TextureAtlas=TextureAtlas,exports.Tile=Tile,exports.Trigger=Trigger,exports.Tween=Tween,exports.Vector2d=Vector2d,exports.Vector3d=Vector3d,exports.WebGLCompositor=WebGLCompositor,exports.WebGLRenderer=WebGLRenderer,exports.World=World,exports.audio=audio,exports.boot=boot,exports.collision=collision,exports.device=device$1,exports.event=event$1,exports.game=game,exports.input=input,exports.level=level,exports.loader=loader,exports.plugin=plugin,exports.plugins=plugins,exports.pool=pooling,exports.save=save,exports.skipAutoInit=skipAutoInit,exports.state=state,exports.timer=timer$1,exports.utils=utils,exports.version=version,exports.video=video,exports.warning=warning,Object.defineProperty(exports,"__esModule",{value:!0})}));