toaimin-indie-engine 1.0.0

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.
Files changed (149) hide show
  1. package/README.md +55 -0
  2. package/cli/bin.cjs +99 -0
  3. package/dist/audio/AudioBus.d.ts +30 -0
  4. package/dist/audio/AudioBus.d.ts.map +1 -0
  5. package/dist/audio/AudioMock.d.ts +112 -0
  6. package/dist/audio/AudioMock.d.ts.map +1 -0
  7. package/dist/audio/ProceduralAudio.d.ts +48 -0
  8. package/dist/audio/ProceduralAudio.d.ts.map +1 -0
  9. package/dist/audio/SoundManager.d.ts +73 -0
  10. package/dist/audio/SoundManager.d.ts.map +1 -0
  11. package/dist/audio/VoicePool.d.ts +26 -0
  12. package/dist/audio/VoicePool.d.ts.map +1 -0
  13. package/dist/audio/index.d.ts +7 -0
  14. package/dist/audio/index.d.ts.map +1 -0
  15. package/dist/audio/types.d.ts +87 -0
  16. package/dist/audio/types.d.ts.map +1 -0
  17. package/dist/core/EventEmitter.d.ts +64 -0
  18. package/dist/core/EventEmitter.d.ts.map +1 -0
  19. package/dist/core/Game.d.ts +248 -0
  20. package/dist/core/Game.d.ts.map +1 -0
  21. package/dist/core/GameLoop.d.ts +128 -0
  22. package/dist/core/GameLoop.d.ts.map +1 -0
  23. package/dist/core/Time.d.ts +73 -0
  24. package/dist/core/Time.d.ts.map +1 -0
  25. package/dist/core/index.d.ts +5 -0
  26. package/dist/core/index.d.ts.map +1 -0
  27. package/dist/entity/Component.d.ts +31 -0
  28. package/dist/entity/Component.d.ts.map +1 -0
  29. package/dist/entity/Entity.d.ts +61 -0
  30. package/dist/entity/Entity.d.ts.map +1 -0
  31. package/dist/entity/EntityManager.d.ts +46 -0
  32. package/dist/entity/EntityManager.d.ts.map +1 -0
  33. package/dist/entity/components/ColliderComponent.d.ts +47 -0
  34. package/dist/entity/components/ColliderComponent.d.ts.map +1 -0
  35. package/dist/entity/components/RigidBodyComponent.d.ts +38 -0
  36. package/dist/entity/components/RigidBodyComponent.d.ts.map +1 -0
  37. package/dist/entity/components/ScriptComponent.d.ts +32 -0
  38. package/dist/entity/components/ScriptComponent.d.ts.map +1 -0
  39. package/dist/entity/components/ShapeComponent.d.ts +50 -0
  40. package/dist/entity/components/ShapeComponent.d.ts.map +1 -0
  41. package/dist/entity/components/SpriteComponent.d.ts +31 -0
  42. package/dist/entity/components/SpriteComponent.d.ts.map +1 -0
  43. package/dist/entity/components/index.d.ts +6 -0
  44. package/dist/entity/components/index.d.ts.map +1 -0
  45. package/dist/entity/index.d.ts +5 -0
  46. package/dist/entity/index.d.ts.map +1 -0
  47. package/dist/index.cjs +4 -0
  48. package/dist/index.cjs.map +1 -0
  49. package/dist/index.d.ts +15 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +6326 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/input/ActionMap.d.ts +91 -0
  54. package/dist/input/ActionMap.d.ts.map +1 -0
  55. package/dist/input/InputManager.d.ts +102 -0
  56. package/dist/input/InputManager.d.ts.map +1 -0
  57. package/dist/input/Pointer.d.ts +115 -0
  58. package/dist/input/Pointer.d.ts.map +1 -0
  59. package/dist/input/VirtualJoystick.d.ts +79 -0
  60. package/dist/input/VirtualJoystick.d.ts.map +1 -0
  61. package/dist/input/index.d.ts +5 -0
  62. package/dist/input/index.d.ts.map +1 -0
  63. package/dist/math/Circle.d.ts +39 -0
  64. package/dist/math/Circle.d.ts.map +1 -0
  65. package/dist/math/Color.d.ts +58 -0
  66. package/dist/math/Color.d.ts.map +1 -0
  67. package/dist/math/MathUtils.d.ts +82 -0
  68. package/dist/math/MathUtils.d.ts.map +1 -0
  69. package/dist/math/Matrix2D.d.ts +97 -0
  70. package/dist/math/Matrix2D.d.ts.map +1 -0
  71. package/dist/math/Rect.d.ts +54 -0
  72. package/dist/math/Rect.d.ts.map +1 -0
  73. package/dist/math/Transform2D.d.ts +47 -0
  74. package/dist/math/Transform2D.d.ts.map +1 -0
  75. package/dist/math/Vector2.d.ts +89 -0
  76. package/dist/math/Vector2.d.ts.map +1 -0
  77. package/dist/math/index.d.ts +8 -0
  78. package/dist/math/index.d.ts.map +1 -0
  79. package/dist/physics/BoxCollider2D.d.ts +38 -0
  80. package/dist/physics/BoxCollider2D.d.ts.map +1 -0
  81. package/dist/physics/CircleCollider2D.d.ts +27 -0
  82. package/dist/physics/CircleCollider2D.d.ts.map +1 -0
  83. package/dist/physics/Collider2D.d.ts +79 -0
  84. package/dist/physics/Collider2D.d.ts.map +1 -0
  85. package/dist/physics/CollisionFSM.d.ts +84 -0
  86. package/dist/physics/CollisionFSM.d.ts.map +1 -0
  87. package/dist/physics/ContactSolver.d.ts +58 -0
  88. package/dist/physics/ContactSolver.d.ts.map +1 -0
  89. package/dist/physics/Narrowphase.d.ts +25 -0
  90. package/dist/physics/Narrowphase.d.ts.map +1 -0
  91. package/dist/physics/PhysicsWorld2D.d.ts +75 -0
  92. package/dist/physics/PhysicsWorld2D.d.ts.map +1 -0
  93. package/dist/physics/Raycast.d.ts +38 -0
  94. package/dist/physics/Raycast.d.ts.map +1 -0
  95. package/dist/physics/RigidBody2D.d.ts +118 -0
  96. package/dist/physics/RigidBody2D.d.ts.map +1 -0
  97. package/dist/physics/SpatialGrid.d.ts +78 -0
  98. package/dist/physics/SpatialGrid.d.ts.map +1 -0
  99. package/dist/physics/index.d.ts +14 -0
  100. package/dist/physics/index.d.ts.map +1 -0
  101. package/dist/rendering/Animation.d.ts +62 -0
  102. package/dist/rendering/Animation.d.ts.map +1 -0
  103. package/dist/rendering/AssetLoader.d.ts +35 -0
  104. package/dist/rendering/AssetLoader.d.ts.map +1 -0
  105. package/dist/rendering/Camera2D.d.ts +109 -0
  106. package/dist/rendering/Camera2D.d.ts.map +1 -0
  107. package/dist/rendering/CanvasContext.d.ts +80 -0
  108. package/dist/rendering/CanvasContext.d.ts.map +1 -0
  109. package/dist/rendering/CanvasMock.d.ts +163 -0
  110. package/dist/rendering/CanvasMock.d.ts.map +1 -0
  111. package/dist/rendering/ParticleSystem.d.ts +103 -0
  112. package/dist/rendering/ParticleSystem.d.ts.map +1 -0
  113. package/dist/rendering/Renderer.d.ts +98 -0
  114. package/dist/rendering/Renderer.d.ts.map +1 -0
  115. package/dist/rendering/Shapes.d.ts +24 -0
  116. package/dist/rendering/Shapes.d.ts.map +1 -0
  117. package/dist/rendering/Sprite.d.ts +74 -0
  118. package/dist/rendering/Sprite.d.ts.map +1 -0
  119. package/dist/rendering/SpriteSheet.d.ts +22 -0
  120. package/dist/rendering/SpriteSheet.d.ts.map +1 -0
  121. package/dist/rendering/index.d.ts +11 -0
  122. package/dist/rendering/index.d.ts.map +1 -0
  123. package/dist/scene/Blackboard.d.ts +81 -0
  124. package/dist/scene/Blackboard.d.ts.map +1 -0
  125. package/dist/scene/Scene.d.ts +160 -0
  126. package/dist/scene/Scene.d.ts.map +1 -0
  127. package/dist/scene/SceneManager.d.ts +142 -0
  128. package/dist/scene/SceneManager.d.ts.map +1 -0
  129. package/dist/scene/SceneTransition.d.ts +118 -0
  130. package/dist/scene/SceneTransition.d.ts.map +1 -0
  131. package/dist/scene/index.d.ts +5 -0
  132. package/dist/scene/index.d.ts.map +1 -0
  133. package/dist/ui/UIAnchor.d.ts +31 -0
  134. package/dist/ui/UIAnchor.d.ts.map +1 -0
  135. package/dist/ui/UIButton.d.ts +48 -0
  136. package/dist/ui/UIButton.d.ts.map +1 -0
  137. package/dist/ui/UIElement.d.ts +108 -0
  138. package/dist/ui/UIElement.d.ts.map +1 -0
  139. package/dist/ui/UILabel.d.ts +54 -0
  140. package/dist/ui/UILabel.d.ts.map +1 -0
  141. package/dist/ui/UIManager.d.ts +41 -0
  142. package/dist/ui/UIManager.d.ts.map +1 -0
  143. package/dist/ui/UIPanel.d.ts +36 -0
  144. package/dist/ui/UIPanel.d.ts.map +1 -0
  145. package/dist/ui/UIProgressBar.d.ts +47 -0
  146. package/dist/ui/UIProgressBar.d.ts.map +1 -0
  147. package/dist/ui/index.d.ts +8 -0
  148. package/dist/ui/index.d.ts.map +1 -0
  149. package/package.json +47 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class e{x;y;static temp1=new e(0,0);static temp2=new e(0,0);constructor(e=0,t=0){this.x=e,this.y=t}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}copy(e){return this.x=e.x,this.y=e.y,this}addInPlace(e){return this.x+=e.x,this.y+=e.y,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}subInPlace(e){return this.x-=e.x,this.y-=e.y,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}scaleInPlace(e){return this.x*=e,this.y*=e,this}multiplyInPlace(e){return this.x*=e.x,this.y*=e.y,this}divideInPlace(e){return this.x=e.x===0?0:this.x/e.x,this.y=e.y===0?0:this.y/e.y,this}divideScalarInPlace(e){if(e!==0){let t=1/e;this.x*=t,this.y*=t}else this.x=0,this.y=0;return this}negateInPlace(){return this.x=this.x===0?0:-this.x,this.y=this.y===0?0:-this.y,this}normalizeInPlace(){let e=this.x*this.x+this.y*this.y;if(e>1e-12){let t=1/Math.sqrt(e);this.x*=t,this.y*=t}else this.x=0,this.y=0;return this}clampLengthInPlace(e,t){let n=this.length();if(n===0)return this;let r=Math.max(e,Math.min(t,n))/n;return this.x*=r,this.y*=r,this}rotateInPlace(e){let t=Math.cos(e),n=Math.sin(e),r=this.x*t-this.y*n,i=this.x*n+this.y*t;return this.x=r===0?0:r,this.y=i===0?0:i,this}rotateAroundInPlace(e,t){let n=Math.cos(t),r=Math.sin(t),i=this.x-e.x,a=this.y-e.y;return this.x=e.x+(i*n-a*r),this.y=e.y+(i*r+a*n),this}lerpInPlace(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}reflectInPlace(e){let t=e.lengthSq();if(t>=1e-12){let n=2*this.dot(e)/t;this.x-=n*e.x,this.y-=n*e.y}return this}projectInPlace(e){let t=e.lengthSq();if(t>=1e-12){let n=this.dot(e)/t;this.x=e.x*n,this.y=e.y*n}else this.x=0,this.y=0;return this}perpendicularInPlace(e=!0){let t=this.x;return e?(this.x=this.y===0?0:-this.y,this.y=t===0?0:t):(this.x=this.y===0?0:this.y,this.y=t===0?0:-t),this}clone(){return new e(this.x,this.y)}add(t){return new e(this.x+t.x,this.y+t.y)}sub(t){return new e(this.x-t.x,this.y-t.y)}scale(t){return new e(this.x*t,this.y*t)}multiply(t){return new e(this.x*t.x,this.y*t.y)}divide(e){return typeof e==`number`?this.clone().divideScalarInPlace(e):this.clone().divideInPlace(e)}negate(){return new e(-this.x,-this.y)}normalized(){return this.clone().normalizeInPlace()}rotate(e){return this.clone().rotateInPlace(e)}lerp(t,n){return new e(this.x+(t.x-this.x)*n,this.y+(t.y-this.y)*n)}reflect(e){return this.clone().reflectInPlace(e)}project(e){return this.clone().projectInPlace(e)}perpendicular(e=!0){return this.clone().perpendicularInPlace(e)}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.lengthSq())}distanceTo(e){let t=this.x-e.x,n=this.y-e.y;return Math.sqrt(t*t+n*n)}distanceToSq(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}angle(){return Math.atan2(this.y,this.x)}angleTo(e){return Math.atan2(this.cross(e),this.dot(e))}equals(e,t=1e-6){return Math.abs(this.x-e.x)<=t&&Math.abs(this.y-e.y)<=t}isZero(e=1e-6){return Math.abs(this.x)<=e&&Math.abs(this.y)<=e}toString(){return`Vector2(${this.x.toFixed(3)}, ${this.y.toFixed(3)})`}toJSON(){return{x:this.x,y:this.y}}static zero(){return new e(0,0)}static one(){return new e(1,1)}static up(){return new e(0,-1)}static down(){return new e(0,1)}static left(){return new e(-1,0)}static right(){return new e(1,0)}static fromAngle(t,n=1){return new e(Math.cos(t)*n,Math.sin(t)*n)}static distance(e,t){return e.distanceTo(t)}static distanceSq(e,t){return e.distanceToSq(t)}static dot(e,t){return e.dot(t)}static cross(e,t){return e.cross(t)}static lerp(t,n,r,i){let a=i??new e;return a.x=t.x+(n.x-t.x)*r,a.y=t.y+(n.y-t.y)*r,a}},t=class t{a;b;c;d;tx;ty;constructor(e=1,t=0,n=0,r=1,i=0,a=0){this.a=e,this.b=t,this.c=n,this.d=r,this.tx=i,this.ty=a}set(e,t,n,r,i,a){return this.a=e,this.b=t,this.c=n,this.d=r,this.tx=i,this.ty=a,this}identity(){return this.set(1,0,0,1,0,0)}copy(e){return this.set(e.a,e.b,e.c,e.d,e.tx,e.ty)}clone(){return new t(this.a,this.b,this.c,this.d,this.tx,this.ty)}determinant(){return this.a*this.d-this.b*this.c}invert(){let e=this.determinant();if(Math.abs(e)<1e-10)return this.identity(),this;let t=1/e,n=this.a,r=this.b,i=this.c,a=this.d,o=this.tx,s=this.ty;return this.a=a*t,this.b=-r*t,this.c=-i*t,this.d=n*t,this.tx=(i*s-a*o)*t,this.ty=(r*o-n*s)*t,this}getInverse(e){return(e??new t).copy(this).invert()}multiply(e){return this.clone().multiplyInPlace(e)}multiplyInPlace(e){let t=this.a,n=this.b,r=this.c,i=this.d,a=this.tx,o=this.ty,s=e.a,c=e.b,l=e.c,u=e.d,d=e.tx,f=e.ty;return this.a=t*s+r*c,this.b=n*s+i*c,this.c=t*l+r*u,this.d=n*l+i*u,this.tx=t*d+r*f+a,this.ty=n*d+i*f+o,this}append(e){return this.multiplyInPlace(e)}prepend(e){let t=e.a,n=e.b,r=e.c,i=e.d,a=e.tx,o=e.ty,s=this.a,c=this.b,l=this.c,u=this.d,d=this.tx,f=this.ty;return this.a=t*s+r*c,this.b=n*s+i*c,this.c=t*l+r*u,this.d=n*l+i*u,this.tx=t*d+r*f+a,this.ty=n*d+i*f+o,this}translate(e,t){return this.tx+=this.a*e+this.c*t,this.ty+=this.b*e+this.d*t,this}rotate(e){let t=Math.cos(e),n=Math.sin(e),r=this.a,i=this.b,a=this.c,o=this.d;return this.a=r*t+a*n,this.b=i*t+o*n,this.c=-r*n+a*t,this.d=-i*n+o*t,this}scale(e,t=e){return this.a*=e,this.b*=e,this.c*=t,this.d*=t,this}fromTransform(e,t,n,r,i,a=0,o=0){let s=Math.cos(n),c=Math.sin(n),l=s*r,u=c*r,d=-c*i,f=s*i;return this.a=l,this.b=u,this.c=d,this.d=f,this.tx=e-(l*a+d*o),this.ty=t-(u*a+f*o),this}transformPoint(t,n){let r=n??new e,i=t.x,a=t.y;return r.x=this.a*i+this.c*a+this.tx,r.y=this.b*i+this.d*a+this.ty,r}transformDirection(t,n){let r=n??new e,i=t.x,a=t.y;return r.x=this.a*i+this.c*a,r.y=this.b*i+this.d*a,r}decompose(t){let n=t??{position:new e,rotation:0,scale:new e};return n.position.set(this.tx,this.ty),n.scale.set(Math.sqrt(this.a*this.a+this.b*this.b),Math.sqrt(this.c*this.c+this.d*this.d)),n.rotation=Math.atan2(this.b,this.a),n}applyToContext(e){e.setTransform(this.a,this.b,this.c,this.d,this.tx,this.ty)}transformContext(e){e.transform(this.a,this.b,this.c,this.d,this.tx,this.ty)}equals(e,t=1e-6){return Math.abs(this.a-e.a)<=t&&Math.abs(this.b-e.b)<=t&&Math.abs(this.c-e.c)<=t&&Math.abs(this.d-e.d)<=t&&Math.abs(this.tx-e.tx)<=t&&Math.abs(this.ty-e.ty)<=t}static identity(){return new t(1,0,0,1,0,0)}},n=class{position;rotation;scale;pivot;parent=null;children=[];localMatrix=new t;worldMatrix=new t;_isDirty=!0;_isWorldDirty=!0;constructor(t=0,n=0,r=0,i=1,a=1,o=0,s=0){this.position=new e(t,n),this.rotation=r,this.scale=new e(i,a),this.pivot=new e(o,s)}markDirty(){return this._isDirty=!0,this.markWorldDirty(),this}markWorldDirty(){if(!this._isWorldDirty){this._isWorldDirty=!0;for(let e=0;e<this.children.length;e++)this.children[e].markWorldDirty()}}get isDirty(){return this._isDirty||this._isWorldDirty}updateLocalMatrix(){return this._isDirty&&=(this.localMatrix.fromTransform(this.position.x,this.position.y,this.rotation,this.scale.x,this.scale.y,this.pivot.x,this.pivot.y),!1),this.localMatrix}updateWorldMatrix(e=!1){return(this._isDirty||e)&&this.updateLocalMatrix(),(this._isWorldDirty||e)&&(this.parent===null?this.worldMatrix.copy(this.localMatrix):(this.parent.updateWorldMatrix(e),this.worldMatrix.copy(this.parent.worldMatrix).multiplyInPlace(this.localMatrix)),this._isWorldDirty=!1),this.worldMatrix}addChild(e){if(e===this||e.parent===this)return this;let t=this.parent;for(;t!==null;){if(t===e)return this;t=t.parent}return e.parent!==null&&e.parent.removeChild(e),e.parent=this,this.children.push(e),e.markWorldDirty(),this}removeChild(e){let t=this.children.indexOf(e);return t!==-1&&(this.children.splice(t,1),e.parent=null,e.markWorldDirty()),this}setParent(e){return e===this||this.parent===e?this:e===null?(this.parent!==null&&this.parent.removeChild(this),this):(e.addChild(this),this)}localToWorld(e,t){return this.updateWorldMatrix(),this.worldMatrix.transformPoint(e,t)}worldToLocal(e,t){return this.updateWorldMatrix(),this.worldMatrix.clone().invert().transformPoint(e,t)}getWorldPosition(t){this.updateWorldMatrix();let n=t??new e;return n.x=this.worldMatrix.tx,n.y=this.worldMatrix.ty,n}getWorldRotation(){return this.updateWorldMatrix(),Math.atan2(this.worldMatrix.b,this.worldMatrix.a)}getWorldScale(t){this.updateWorldMatrix();let n=t??new e;return n.x=Math.sqrt(this.worldMatrix.a*this.worldMatrix.a+this.worldMatrix.b*this.worldMatrix.b),n.y=Math.sqrt(this.worldMatrix.c*this.worldMatrix.c+this.worldMatrix.d*this.worldMatrix.d),n}setPosition(e,t){return this.position.set(e,t),this.markDirty()}setRotation(e){return this.rotation=e,this.markDirty()}setScale(e,t=e){return this.scale.set(e,t),this.markDirty()}setPivot(e,t){return this.pivot.set(e,t),this.markDirty()}},r=class t{x;y;width;height;constructor(e=0,t=0,n=0,r=0){this.x=e,this.y=t,this.width=n,this.height=r}set(e,t,n,r){return this.x=e,this.y=t,this.width=n,this.height=r,this}copy(e){return this.set(e.x,e.y,e.width,e.height)}clone(){return new t(this.x,this.y,this.width,this.height)}get left(){return this.x}set left(e){this.width+=this.x-e,this.x=e}get right(){return this.x+this.width}set right(e){this.width=e-this.x}get top(){return this.y}set top(e){this.height+=this.y-e,this.y=e}get bottom(){return this.y+this.height}set bottom(e){this.height=e-this.y}get centerX(){return this.x+this.width*.5}get centerY(){return this.y+this.height*.5}get center(){return new e(this.centerX,this.centerY)}get size(){return new e(this.width,this.height)}contains(e,t){return e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height}containsPoint(e){return this.contains(e.x,e.y)}containsRect(e){return e.x>=this.x&&e.right<=this.right&&e.y>=this.y&&e.bottom<=this.bottom}intersects(e){return this.x<=e.right&&this.right>=e.x&&this.y<=e.bottom&&this.bottom>=e.y}intersection(e,n){if(!this.intersects(e))return null;let r=Math.max(this.x,e.x),i=Math.max(this.y,e.y),a=Math.min(this.right,e.right),o=Math.min(this.bottom,e.bottom);return(n??new t).set(r,i,a-r,o-i)}union(e,n){let r=Math.min(this.x,e.x),i=Math.min(this.y,e.y),a=Math.max(this.right,e.right),o=Math.max(this.bottom,e.bottom);return(n??new t).set(r,i,a-r,o-i)}inflate(e,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}offset(e,t){return this.x+=e,this.y+=t,this}static fromPoints(e,n){let r=Math.min(e.x,n.x),i=Math.min(e.y,n.y),a=Math.max(e.x,n.x),o=Math.max(e.y,n.y);return new t(r,i,a-r,o-i)}static fromCenter(e,n,r,i){return new t(e-r*.5,n-i*.5,r,i)}static fromMinMax(e,n,r,i){return new t(e,n,r-e,i-n)}},i=class t{x;y;radius;constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.radius=n}set(e,t,n){return this.x=e,this.y=t,this.radius=n,this}copy(e){return this.set(e.x,e.y,e.radius)}clone(){return new t(this.x,this.y,this.radius)}get center(){return new e(this.x,this.y)}set center(e){this.x=e.x,this.y=e.y}get diameter(){return this.radius*2}get area(){return Math.PI*this.radius*this.radius}get circumference(){return 2*Math.PI*this.radius}contains(e,t){let n=e-this.x,r=t-this.y;return n*n+r*r<=this.radius*this.radius}containsPoint(e){return this.contains(e.x,e.y)}intersects(e){let t=e.x-this.x,n=e.y-this.y,r=t*t+n*n,i=this.radius+e.radius;return r<=i*i}intersectsRect(e){let t=Math.max(e.left,Math.min(this.x,e.right)),n=Math.max(e.top,Math.min(this.y,e.bottom)),r=this.x-t,i=this.y-n;return r*r+i*i<=this.radius*this.radius}getBoundingBox(e){return(e??new r).set(this.x-this.radius,this.y-this.radius,this.radius*2,this.radius*2)}offset(e,t){return this.x+=e,this.y+=t,this}},a=class e{static EPSILON=1e-6;static DEG_TO_RAD=Math.PI/180;static RAD_TO_DEG=180/Math.PI;static TWO_PI=Math.PI*2;static HALF_PI=Math.PI/2;static clamp(e,t,n){return Math.max(t,Math.min(n,e))}static clamp01(e){return Math.max(0,Math.min(1,e))}static lerp(e,t,n){return e+(t-e)*n}static inverseLerp(t,n,r){return Math.abs(n-t)<e.EPSILON?0:e.clamp01((r-t)/(n-t))}static damp(t,n,r,i){return e.lerp(t,n,1-Math.exp(-r*i))}static degToRad(t){return t*e.DEG_TO_RAD}static radToDeg(t){return t*e.RAD_TO_DEG}static randomRange(e,t){return e+Math.random()*(t-e)}static randomInt(e,t){let n=Math.ceil(e);return Math.floor(n+Math.random()*(Math.floor(t)-n+1))}static randomChoice(e){return e[Math.floor(Math.random()*e.length)]}static approximately(t,n,r=e.EPSILON){return Math.abs(t-n)<=r}static wrap(e,t,n){let r=n-t;return r===0?t:t+((e-t)%r+r)%r}static normalizeAngle(t){return e.wrap(t,-Math.PI,Math.PI)}static angleDifference(t,n){return((n-t)%e.TWO_PI+Math.PI*3)%e.TWO_PI-Math.PI}static smoothstep(t,n,r){if(Math.abs(n-t)<e.EPSILON)return+(r>=n);let i=e.clamp01((r-t)/(n-t));return i*i*(3-2*i)}static sign(e){return e>0?1:e<0?-1:0}},o=class e{r;g;b;a;constructor(e=255,t=255,n=255,r=1){this.r=Math.round(a.clamp(e,0,255)),this.g=Math.round(a.clamp(t,0,255)),this.b=Math.round(a.clamp(n,0,255)),this.a=a.clamp01(r)}set(e,t,n,r=1){return this.r=Math.round(a.clamp(e,0,255)),this.g=Math.round(a.clamp(t,0,255)),this.b=Math.round(a.clamp(n,0,255)),this.a=a.clamp01(r),this}copy(e){return this.set(e.r,e.g,e.b,e.a)}clone(){return new e(this.r,this.g,this.b,this.a)}get rNorm(){return this.r/255}get gNorm(){return this.g/255}get bNorm(){return this.b/255}setAlpha(e){return this.a=a.clamp01(e),this}static fromHex(t){let n=t.trim().replace(/^(#|0x)/i,``);if(n.length===3?n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]:n.length===4&&(n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]+n[3]+n[3]),n.length===6){let t=parseInt(n,16);return new e(t>>16&255,t>>8&255,t&255,1)}if(n.length===8){let t=parseInt(n,16),r=t>>24&255,i=t>>16&255,a=t>>8&255,o=(t&255)/255;return new e(r,i,a,o)}return new e(255,255,255,1)}static fromRGB(t,n,r,i=1){return new e(t,n,r,i)}static fromHSL(t,n,r,i=1){let o=a.wrap(t,0,360),s=n>1?n/100:n,c=r>1?r/100:r,l=(1-Math.abs(2*c-1))*s,u=l*(1-Math.abs(o/60%2-1)),d=c-l/2,f=0,p=0,m=0;return o<60?(f=l,p=u,m=0):o<120?(f=u,p=l,m=0):o<180?(f=0,p=l,m=u):o<240?(f=0,p=u,m=l):o<300?(f=u,p=0,m=l):(f=l,p=0,m=u),new e((f+d)*255,(p+d)*255,(m+d)*255,i)}static parse(t){let n=t.trim().toLowerCase();if(n.startsWith(`#`)||n.startsWith(`0x`))return e.fromHex(n);if(n.startsWith(`rgb`)){let t=n.match(/rgba?\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)/);if(t)return new e(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3]),t[4]===void 0?1:parseFloat(t[4]))}if(n.startsWith(`hsl`)){let t=n.match(/hsla?\s*\(\s*([\d.]+)\s*,\s*([\d.]+)%?\s*,\s*([\d.]+)%?(?:\s*,\s*([\d.]+))?\s*\)/);if(t)return e.fromHSL(parseFloat(t[1]),parseFloat(t[2]),parseFloat(t[3]),t[4]===void 0?1:parseFloat(t[4]))}let r={white:e.WHITE,black:e.BLACK,red:e.RED,green:e.GREEN,blue:e.BLUE,yellow:e.YELLOW,cyan:e.CYAN,magenta:e.MAGENTA,gray:e.GRAY,orange:e.ORANGE,purple:e.PURPLE,transparent:e.TRANSPARENT};return r[n]?r[n].clone():e.WHITE.clone()}toRgbaString(){return`rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`}toRgbString(){return`rgb(${this.r}, ${this.g}, ${this.b})`}toHexString(e=!1){let t=this.r.toString(16).padStart(2,`0`),n=this.g.toString(16).padStart(2,`0`),r=this.b.toString(16).padStart(2,`0`);return e?`#${t}${n}${r}${Math.round(this.a*255).toString(16).padStart(2,`0`)}`:`#${t}${n}${r}`}toHsl(){let e=this.rNorm,t=this.gNorm,n=this.bNorm,r=Math.max(e,t,n),i=Math.min(e,t,n),a=r-i,o=0,s=(r+i)/2,c=0;return a!==0&&(c=s>.5?a/(2-r-i):a/(r+i),o=r===e?((t-n)/a+(t<n?6:0))*60:r===t?((n-e)/a+2)*60:((e-t)/a+4)*60),{h:Math.round(o),s:Math.round(c*100),l:Math.round(s*100),a:this.a}}toHslString(){let e=this.toHsl();return`hsla(${e.h}, ${e.s}%, ${e.l}%, ${e.a})`}lerp(t,n){return new e(a.lerp(this.r,t.r,n),a.lerp(this.g,t.g,n),a.lerp(this.b,t.b,n),a.lerp(this.a,t.a,n))}lerpInPlace(e,t){return this.r=Math.round(a.lerp(this.r,e.r,t)),this.g=Math.round(a.lerp(this.g,e.g,t)),this.b=Math.round(a.lerp(this.b,e.b,t)),this.a=a.lerp(this.a,e.a,t),this}equals(e,t=1e-4){return Math.abs(this.r-e.r)<=1&&Math.abs(this.g-e.g)<=1&&Math.abs(this.b-e.b)<=1&&Math.abs(this.a-e.a)<=t}static WHITE=new e(255,255,255,1);static BLACK=new e(0,0,0,1);static TRANSPARENT=new e(0,0,0,0);static RED=new e(239,68,68,1);static GREEN=new e(34,197,94,1);static BLUE=new e(59,130,246,1);static YELLOW=new e(234,179,8,1);static CYAN=new e(6,182,212,1);static MAGENTA=new e(217,70,239,1);static GRAY=new e(107,114,128,1);static ORANGE=new e(249,115,22,1);static PURPLE=new e(168,85,247,1)},s=class{_events;constructor(){this._events=new Map}on(e,t){if(!t||typeof t!=`function`)throw TypeError(`EventEmitter.on: listener must be a function, received ${typeof t}`);let n=this._events.get(e);return n||(n=[],this._events.set(e,n)),n.push({fn:t,once:!1}),this}once(e,t){if(!t||typeof t!=`function`)throw TypeError(`EventEmitter.once: listener must be a function, received ${typeof t}`);let n=this._events.get(e);return n||(n=[],this._events.set(e,n)),n.push({fn:t,once:!0}),this}off(e,t){let n=this._events.get(e);if(!n)return this;for(let e=n.length-1;e>=0;e--)if(n[e].fn===t){n.splice(e,1);break}return n.length===0&&this._events.delete(e),this}subscribe(e,t){this.on(e,t);let n=!1;return()=>{n||(n=!0,this.off(e,t))}}emit(e,...t){let n=this._events.get(e);if(!n||n.length===0)return!1;let r=t[0],i=n.slice();for(let t=0;t<i.length;t++){let n=i[t];n.once&&this.off(e,n.fn);try{n.fn(r)}catch(t){console.error(`EventEmitter error during event "${String(e)}":`,t)}}return!0}clear(e){return e===void 0?this._events.clear():this._events.delete(e),this}listenerCount(e){let t=this._events.get(e);return t?t.length:0}hasListeners(e){return this.listenerCount(e)>0}},c=class e{static deltaTime=0;static rawDeltaTime=0;static fixedDeltaTime=1/60;static time=0;static unscaledTime=0;static frameCount=0;static timeScale=1;static fps=60;static exactFps=60;static SAMPLE_SIZE=30;static _samples=new Float64Array(e.SAMPLE_SIZE);static _sampleIndex=0;static _sampleCount=0;static _sampleSum=0;static update(t){let n=t<0?0:t;if(e.rawDeltaTime=n,e.deltaTime=n*e.timeScale,e.time+=e.deltaTime,e.unscaledTime+=n,e.frameCount++,n>0){e._sampleCount<e.SAMPLE_SIZE?(e._samples[e._sampleIndex]=n,e._sampleSum+=n,e._sampleCount++):(e._sampleSum-=e._samples[e._sampleIndex],e._samples[e._sampleIndex]=n,e._sampleSum+=n),e._sampleIndex=(e._sampleIndex+1)%e.SAMPLE_SIZE;let t=e._sampleSum/e._sampleCount;t>0&&(e.exactFps=1/t,e.fps=Math.round(e.exactFps))}}static setFixedDeltaTime(t){if(t<=0)throw RangeError(`Time.setFixedDeltaTime: fixedDelta must be > 0, received ${t}`);e.fixedDeltaTime=t}static setTimeScale(t){e.timeScale=Math.max(0,t)}static reset(){e.deltaTime=0,e.rawDeltaTime=0,e.fixedDeltaTime=1/60,e.time=0,e.unscaledTime=0,e.frameCount=0,e.timeScale=1,e.fps=60,e.exactFps=60,e._samples.fill(0),e._sampleIndex=0,e._sampleCount=0,e._sampleSum=0}},l=class{callbacks;fixedDeltaTime;maxFrameDelta;maxSubSteps;autoPauseOnHide;renderWhenPaused;_accumulator=0;_lastTime=0;_rafId=null;_running=!1;_paused=!1;_pausedByVisibility=!1;_wasManuallyPaused=!1;_boundVisibilityListener=null;constructor(e,t={}){if(!e||typeof e.update!=`function`||typeof e.fixedUpdate!=`function`||typeof e.render!=`function`)throw TypeError(`GameLoop requires update, fixedUpdate, and render callbacks.`);this.callbacks=e,this.fixedDeltaTime=t.fixedDeltaTime??1/60,this.maxFrameDelta=t.maxFrameDelta??.25,this.maxSubSteps=t.maxSubSteps??Math.max(1,Math.ceil(this.maxFrameDelta/this.fixedDeltaTime)),this.autoPauseOnHide=t.autoPauseOnHide??!0,this.renderWhenPaused=t.renderWhenPaused??!1,c.fixedDeltaTime=this.fixedDeltaTime,this.autoPauseOnHide&&this._initVisibilityListener()}isRunning(){return this._running}isPaused(){return this._paused}getAccumulator(){return this._accumulator}start(){this._running||(this._running=!0,this._paused=!1,this._pausedByVisibility=!1,this._wasManuallyPaused=!1,this._accumulator=0,this._lastTime=this._now(),this._rafId=this._requestFrame(this._tick))}stop(){this._running&&(this._running=!1,this._rafId!==null&&(this._cancelFrame(this._rafId),this._rafId=null))}pause(){!this._running||this._paused||(this._paused=!0)}resume(){!this._running||!this._paused||(this._paused=!1,this._pausedByVisibility=!1,this._wasManuallyPaused=!1,this._lastTime=this._now(),this._accumulator=0)}step(e){let t=e??this.fixedDeltaTime;t<0?t=0:t>this.maxFrameDelta&&(t=this.maxFrameDelta),c.update(t),this.callbacks.update(c.deltaTime),this._accumulator+=t;let n=0;for(;this._accumulator>=this.fixedDeltaTime&&n<this.maxSubSteps;)this.callbacks.fixedUpdate(this.fixedDeltaTime),this._accumulator-=this.fixedDeltaTime,n++;n>=this.maxSubSteps&&(this._accumulator=0);let r=Math.min(Math.max(this._accumulator/this.fixedDeltaTime,0),1);this.callbacks.render(r)}destroy(){this.stop(),this._boundVisibilityListener&&typeof document<`u`&&(document.removeEventListener(`visibilitychange`,this._boundVisibilityListener),this._boundVisibilityListener=null)}_tick=e=>{if(!this._running)return;let t=e??this._now(),n=(t-this._lastTime)/1e3;if(this._lastTime=t,n<0?n=0:n>this.maxFrameDelta&&(n=this.maxFrameDelta),this._paused)this.renderWhenPaused&&this.callbacks.render(1);else{c.update(n),this.callbacks.update(c.deltaTime),this._accumulator+=n;let e=0;for(;this._accumulator>=this.fixedDeltaTime&&e<this.maxSubSteps;)this.callbacks.fixedUpdate(this.fixedDeltaTime),this._accumulator-=this.fixedDeltaTime,e++;e>=this.maxSubSteps&&(this._accumulator=0);let t=Math.min(Math.max(this._accumulator/this.fixedDeltaTime,0),1);this.callbacks.render(t)}this._running&&(this._rafId=this._requestFrame(this._tick))};_now(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}_requestFrame(e){return typeof requestAnimationFrame==`function`?requestAnimationFrame(e):setTimeout(()=>e(this._now()),16)}_cancelFrame(e){typeof cancelAnimationFrame==`function`?cancelAnimationFrame(e):clearTimeout(e)}_initVisibilityListener(){typeof document>`u`||(this._boundVisibilityListener=()=>{document.hidden?this._paused?this._wasManuallyPaused=!0:(this._wasManuallyPaused=!1,this._pausedByVisibility=!0,this.pause()):this._pausedByVisibility&&!this._wasManuallyPaused?this.resume():(this._lastTime=this._now(),this._accumulator=0)},document.addEventListener(`visibilitychange`,this._boundVisibilityListener))}},u=class{rawContext;currentMatrix=new t;_saveDepth=0;_matrixStack=[];_alphaStack=[];_compositeStack=[];constructor(e,t){this.rawContext=e,t?.pixelArt&&this.setImageSmoothing(!1)}get saveDepth(){return this._saveDepth}save(){return this.rawContext.save(),this._saveDepth++,this._matrixStack.push(this.currentMatrix.clone()),this._alphaStack.push(this.rawContext.globalAlpha),this._compositeStack.push(this.rawContext.globalCompositeOperation),this}restore(){if(this._saveDepth<=0)return this;this.rawContext.restore(),this._saveDepth--;let e=this._matrixStack.pop();return e&&this.currentMatrix.copy(e),this._alphaStack.pop(),this._compositeStack.pop(),this}restoreTo(e){for(;this._saveDepth>e&&this._saveDepth>0;)this.restore();return this}setMatrix(e){return this.currentMatrix.copy(e),e.applyToContext(this.rawContext),this}transformMatrix(e){return this.currentMatrix.multiplyInPlace(e),e.transformContext(this.rawContext),this}translate(e,t){return this.currentMatrix.translate(e,t),this.rawContext.translate(e,t),this}rotate(e){return this.currentMatrix.rotate(e),this.rawContext.rotate(e),this}scale(e,t=e){return this.currentMatrix.scale(e,t),this.rawContext.scale(e,t),this}resetTransform(){return this.currentMatrix.identity(),this.rawContext.setTransform(1,0,0,1,0,0),this}getMatrix(e){return(e??new t).copy(this.currentMatrix)}get globalAlpha(){return this.rawContext.globalAlpha}set globalAlpha(e){this.rawContext.globalAlpha=Math.max(0,Math.min(1,e))}pushAlpha(e){return this._alphaStack.push(this.rawContext.globalAlpha),this.rawContext.globalAlpha=Math.max(0,Math.min(1,this.rawContext.globalAlpha*e)),this}popAlpha(){let e=this._alphaStack.pop();return e!==void 0&&(this.rawContext.globalAlpha=e),this}get blendMode(){return this.rawContext.globalCompositeOperation}set blendMode(e){this.rawContext.globalCompositeOperation=e}pushBlendMode(e){return this._compositeStack.push(this.rawContext.globalCompositeOperation),this.rawContext.globalCompositeOperation=e,this}popBlendMode(){let e=this._compositeStack.pop();return e!==void 0&&(this.rawContext.globalCompositeOperation=e),this}get imageSmoothingEnabled(){return this.rawContext.imageSmoothingEnabled}setImageSmoothing(e){return this.rawContext.imageSmoothingEnabled=e,this}setFillStyle(e){return e instanceof o?this.rawContext.fillStyle=e.toRgbaString():this.rawContext.fillStyle=e,this}setStrokeStyle(e){return e instanceof o?this.rawContext.strokeStyle=e.toRgbaString():this.rawContext.strokeStyle=e,this}setLineWidth(e){return this.rawContext.lineWidth=e,this}clearRect(e,t,n,r){return this.rawContext.clearRect(e,t,n,r),this}fillRect(e,t,n,r){return this.rawContext.fillRect(e,t,n,r),this}strokeRect(e,t,n,r){return this.rawContext.strokeRect(e,t,n,r),this}beginPath(){return this.rawContext.beginPath(),this}closePath(){return this.rawContext.closePath(),this}moveTo(e,t){return this.rawContext.moveTo(e,t),this}lineTo(e,t){return this.rawContext.lineTo(e,t),this}arc(e,t,n,r=0,i=Math.PI*2,a=!1){return this.rawContext.arc(e,t,n,r,i,a),this}fill(){return this.rawContext.fill(),this}stroke(){return this.rawContext.stroke(),this}clip(){return this.rawContext.clip(),this}drawImage(e,t,n,r,i,a,o,s,c){return t===void 0?this.rawContext.drawImage(e,0,0):r===void 0?this.rawContext.drawImage(e,t,n):a===void 0?this.rawContext.drawImage(e,t,n,r,i):this.rawContext.drawImage(e,t,n,r,i,a,o,s,c),this}},d=class{canvas;fillStyle=`#000000`;strokeStyle=`#000000`;lineWidth=1;lineCap=`butt`;lineJoin=`miter`;miterLimit=10;globalAlpha=1;globalCompositeOperation=`source-over`;imageSmoothingEnabled=!0;font=`10px sans-serif`;textAlign=`start`;textBaseline=`alphabetic`;shadowBlur=0;shadowColor=`rgba(0, 0, 0, 0)`;shadowOffsetX=0;shadowOffsetY=0;drawCalls=0;callHistory=[];_matrix=new t;_stateStack=[];constructor(e){this.canvas=e}save(){this.callHistory.push({method:`save`,args:[]}),this._stateStack.push({fillStyle:this.fillStyle,strokeStyle:this.strokeStyle,lineWidth:this.lineWidth,lineCap:this.lineCap,lineJoin:this.lineJoin,miterLimit:this.miterLimit,globalAlpha:this.globalAlpha,globalCompositeOperation:this.globalCompositeOperation,imageSmoothingEnabled:this.imageSmoothingEnabled,font:this.font,textAlign:this.textAlign,textBaseline:this.textBaseline,shadowBlur:this.shadowBlur,shadowColor:this.shadowColor,shadowOffsetX:this.shadowOffsetX,shadowOffsetY:this.shadowOffsetY,transform:[this._matrix.a,this._matrix.b,this._matrix.c,this._matrix.d,this._matrix.tx,this._matrix.ty]})}restore(){this.callHistory.push({method:`restore`,args:[]});let e=this._stateStack.pop();e&&(this.fillStyle=e.fillStyle,this.strokeStyle=e.strokeStyle,this.lineWidth=e.lineWidth,this.lineCap=e.lineCap,this.lineJoin=e.lineJoin,this.miterLimit=e.miterLimit,this.globalAlpha=e.globalAlpha,this.globalCompositeOperation=e.globalCompositeOperation,this.imageSmoothingEnabled=e.imageSmoothingEnabled,this.font=e.font,this.textAlign=e.textAlign,this.textBaseline=e.textBaseline,this.shadowBlur=e.shadowBlur,this.shadowColor=e.shadowColor,this.shadowOffsetX=e.shadowOffsetX,this.shadowOffsetY=e.shadowOffsetY,this._matrix.set(e.transform[0],e.transform[1],e.transform[2],e.transform[3],e.transform[4],e.transform[5]))}scale(e,t){this.callHistory.push({method:`scale`,args:[e,t]}),this._matrix.scale(e,t)}rotate(e){this.callHistory.push({method:`rotate`,args:[e]}),this._matrix.rotate(e)}translate(e,t){this.callHistory.push({method:`translate`,args:[e,t]}),this._matrix.translate(e,t)}transform(e,n,r,i,a,o){this.callHistory.push({method:`transform`,args:[e,n,r,i,a,o]});let s=new t(e,n,r,i,a,o);this._matrix.multiplyInPlace(s)}setTransform(e,t,n,r,i,a){this.callHistory.push({method:`setTransform`,args:[e,t,n,r,i,a]}),this._matrix.set(e,t,n,r,i,a)}resetTransform(){this.callHistory.push({method:`resetTransform`,args:[]}),this._matrix.identity()}getTransform(){return{a:this._matrix.a,b:this._matrix.b,c:this._matrix.c,d:this._matrix.d,e:this._matrix.tx,f:this._matrix.ty,m11:this._matrix.a,m12:this._matrix.b,m21:this._matrix.c,m22:this._matrix.d,m41:this._matrix.tx,m42:this._matrix.ty}}clearRect(e,t,n,r){this.callHistory.push({method:`clearRect`,args:[e,t,n,r]})}fillRect(e,t,n,r){this.drawCalls++,this.callHistory.push({method:`fillRect`,args:[e,t,n,r]})}strokeRect(e,t,n,r){this.drawCalls++,this.callHistory.push({method:`strokeRect`,args:[e,t,n,r]})}beginPath(){this.callHistory.push({method:`beginPath`,args:[]})}closePath(){this.callHistory.push({method:`closePath`,args:[]})}moveTo(e,t){this.callHistory.push({method:`moveTo`,args:[e,t]})}lineTo(e,t){this.callHistory.push({method:`lineTo`,args:[e,t]})}arc(e,t,n,r,i,a=!1){this.callHistory.push({method:`arc`,args:[e,t,n,r,i,a]})}rect(e,t,n,r){this.callHistory.push({method:`rect`,args:[e,t,n,r]})}roundRect(e,t,n,r,i){this.callHistory.push({method:`roundRect`,args:[e,t,n,r,i]})}arcTo(e,t,n,r,i){this.callHistory.push({method:`arcTo`,args:[e,t,n,r,i]})}ellipse(e,t,n,r,i,a,o,s=!1){this.callHistory.push({method:`ellipse`,args:[e,t,n,r,i,a,o,s]})}fill(){this.drawCalls++,this.callHistory.push({method:`fill`,args:[]})}stroke(){this.drawCalls++,this.callHistory.push({method:`stroke`,args:[]})}clip(){this.callHistory.push({method:`clip`,args:[]})}drawImage(e,...t){this.drawCalls++,this.callHistory.push({method:`drawImage`,args:[e,...t]})}fillText(e,t,n,r){this.drawCalls++,this.callHistory.push({method:`fillText`,args:[e,t,n,r]})}strokeText(e,t,n,r){this.drawCalls++,this.callHistory.push({method:`strokeText`,args:[e,t,n,r]})}measureText(e){let t=(e?e.length:0)*8;return{width:t,actualBoundingBoxLeft:0,actualBoundingBoxRight:t,actualBoundingBoxAscent:8,actualBoundingBoxDescent:2}}createLinearGradient(e,t,n,r){return{addColorStop:(e,t)=>{}}}createRadialGradient(e,t,n,r,i,a){return{addColorStop:(e,t)=>{}}}clearMock(){this.drawCalls=0,this.callHistory.length=0,this._stateStack.length=0,this._matrix.identity()}},f=class{width;height;style;_context;constructor(e=800,t=600){this.width=e,this.height=t,this.style={width:`${e}px`,height:`${t}px`,position:`relative`,left:`0px`,top:`0px`,display:`block`},this._context=new d(this)}getContext(e){return e===`2d`?this._context:null}getBoundingClientRect(){let e=parseFloat(this.style.width)||this.width,t=parseFloat(this.style.height)||this.height,n=parseFloat(this.style.left)||0,r=parseFloat(this.style.top)||0;return{left:n,top:r,right:n+e,bottom:r+t,width:e,height:t,x:n,y:r}}addEventListener(e,t){}removeEventListener(e,t){}dispatchEvent(e){return!0}};function p(e=800,t=600){return new f(e,t)}var m={MockCanvasElement:f,MockCanvasRenderingContext2D:d,createMockCanvas:p},h=function(e){return e[e.BACKGROUND=-1e3]=`BACKGROUND`,e[e.DEFAULT=0]=`DEFAULT`,e[e.ENTITIES=100]=`ENTITIES`,e[e.EFFECTS=200]=`EFFECTS`,e[e.FOREGROUND=300]=`FOREGROUND`,e[e.UI=1e3]=`UI`,e[e.DEBUG=2e3]=`DEBUG`,e}({}),g=class{canvas;ctx;rawContext;virtualWidth;virtualHeight;scaleMode;pixelArt;highDPI;maxPixelRatio;backgroundColor;dpr=1;scaleX=1;scaleY=1;offsetX=0;offsetY=0;cssWidth=0;cssHeight=0;drawCalls=0;_isFrameActive=!1;_renderQueue=[];constructor(e={}){if(this.virtualWidth=e.width??800,this.virtualHeight=e.height??600,this.scaleMode=e.scaleMode??`letterbox`,this.pixelArt=e.pixelArt??!1,this.highDPI=e.highDPI??!0,this.maxPixelRatio=e.maxPixelRatio??2,this.backgroundColor=e.backgroundColor??`#11111b`,typeof e.canvas==`string`&&typeof document<`u`){let t=document.getElementById(e.canvas);if(!(t instanceof HTMLCanvasElement))throw Error(`Canvas element with id "${e.canvas}" not found`);this.canvas=t}else e.canvas?this.canvas=e.canvas:typeof document<`u`&&typeof document.createElement==`function`?(this.canvas=document.createElement(`canvas`),document.body.appendChild(this.canvas)):this.canvas=p(this.virtualWidth,this.virtualHeight);let t=this.canvas.getContext(`2d`);if(!t)throw Error(`Failed to obtain 2D rendering context`);this.rawContext=t,this.ctx=new u(this.rawContext,{pixelArt:this.pixelArt}),this.dpr=e.dpr===void 0?this.highDPI&&typeof window<`u`&&window.devicePixelRatio?Math.min(window.devicePixelRatio,this.maxPixelRatio):1:e.dpr,this.resize(this.virtualWidth,this.virtualHeight)}resize(e,t){let n=e,r=t;(n===void 0||r===void 0)&&(typeof window<`u`?(n=window.innerWidth,r=window.innerHeight):(n=this.virtualWidth,r=this.virtualHeight));let i=this.virtualWidth,a=this.virtualHeight,o=0,s=0;switch(this.scaleMode){case`letterbox`:{let e=Math.min(n/this.virtualWidth,r/this.virtualHeight);i=Math.floor(this.virtualWidth*e),a=Math.floor(this.virtualHeight*e),o=Math.floor((n-i)/2),s=Math.floor((r-a)/2),this.scaleX=i/this.virtualWidth,this.scaleY=a/this.virtualHeight;break}case`fit`:{let e=Math.min(n/this.virtualWidth,r/this.virtualHeight);i=Math.floor(this.virtualWidth*e),a=Math.floor(this.virtualHeight*e),o=0,s=0,this.scaleX=i/this.virtualWidth,this.scaleY=a/this.virtualHeight;break}case`stretch`:i=n,a=r,o=0,s=0,this.scaleX=n/this.virtualWidth,this.scaleY=r/this.virtualHeight;break;case`fill`:{let e=Math.max(n/this.virtualWidth,r/this.virtualHeight);i=Math.floor(this.virtualWidth*e),a=Math.floor(this.virtualHeight*e),o=Math.floor((n-i)/2),s=Math.floor((r-a)/2),this.scaleX=i/this.virtualWidth,this.scaleY=a/this.virtualHeight;break}default:i=this.virtualWidth,a=this.virtualHeight,o=0,s=0,this.scaleX=1,this.scaleY=1}this.cssWidth=i,this.cssHeight=a,this.offsetX=o,this.offsetY=s,this.canvas.style&&(this.canvas.style.width=`${i}px`,this.canvas.style.height=`${a}px`,this.scaleMode===`letterbox`&&(this.canvas.style.position=`absolute`,this.canvas.style.left=`${o}px`,this.canvas.style.top=`${s}px`));let c=Math.round(i*this.dpr),l=Math.round(a*this.dpr);(this.canvas.width!==c||this.canvas.height!==l)&&(this.canvas.width=c,this.canvas.height=l),this.ctx.setImageSmoothing(!this.pixelArt)}screenToVirtual(t,n,r){let i=r??new e,a={left:0,top:0,width:this.cssWidth,height:this.cssHeight};typeof this.canvas.getBoundingClientRect==`function`&&(a=this.canvas.getBoundingClientRect());let o=t-a.left,s=n-a.top,c=a.width>0?o/a.width*this.virtualWidth:o,l=a.height>0?s/a.height*this.virtualHeight:s;return i.set(c,l)}virtualToScreen(t,n,r){let i=r??new e,a={left:0,top:0,width:this.cssWidth,height:this.cssHeight};typeof this.canvas.getBoundingClientRect==`function`&&(a=this.canvas.getBoundingClientRect());let o=a.left+t/this.virtualWidth*a.width,s=a.top+n/this.virtualHeight*a.height;return i.set(o,s)}clear(e=this.backgroundColor){this.rawContext.save(),this.rawContext.setTransform(1,0,0,1,0,0),this.rawContext.fillStyle=e,this.rawContext.fillRect(0,0,this.canvas.width,this.canvas.height),this.rawContext.restore()}beginFrame(){this._isFrameActive=!0,this.drawCalls=0,this._renderQueue.length=0,this.clear();let e=this.scaleX*this.dpr,t=this.scaleY*this.dpr;this.rawContext.setTransform(e,0,0,t,0,0),this.ctx.currentMatrix.set(e,0,0,t,0,0)}endFrame(){this._isFrameActive&&=(this.flushQueue(),this.ctx.saveDepth>0&&this.ctx.restoreTo(0),this.rawContext.drawCalls!==void 0&&(this.drawCalls=this.rawContext.drawCalls),!1)}submit(e){this._renderQueue.push(e)}flushQueue(){if(this._renderQueue.length===0)return;this._renderQueue.sort((e,t)=>{let n=e.layer??0,r=t.layer??0;return n===r?(e.zIndex??0)-(t.zIndex??0):n-r});let e;for(let t=0;t<this._renderQueue.length;t++){let n=this._renderQueue[t];n.camera!==e&&(e&&this.ctx.restore(),e=n.camera,e&&(this.ctx.save(),e.applyToContext(this.ctx))),n.render(this.ctx)}e&&this.ctx.restore(),this._renderQueue.length=0}},_=class n{position=new e(0,0);origin=new e(.5,.5);offset=new e(0,0);viewportWidth;viewportHeight;_zoom=1;_rotation=0;target=null;followLerp=.1;deadzone=null;bounds=null;trauma=0;traumaDecay=1.5;maxShakeOffset=20;maxShakeAngle=.05;_viewMatrix=new t;_invViewMatrix=new t;_visibleBounds=new r;_isDirty=!0;_boundsDirty=!0;static _scratchScreenTL=new e;static _scratchScreenTR=new e;static _scratchScreenBR=new e;static _scratchScreenBL=new e;static _scratchWorldTL=new e;static _scratchWorldTR=new e;static _scratchWorldBR=new e;static _scratchWorldBL=new e;_lastPosX=NaN;_lastPosY=NaN;_lastOriginX=NaN;_lastOriginY=NaN;_lastOffsetX=NaN;_lastOffsetY=NaN;_lastViewportW=NaN;_lastViewportH=NaN;_shakeOffsetX=0;_shakeOffsetY=0;_shakeAngle=0;constructor(e){this.viewportWidth=e.viewportWidth,this.viewportHeight=e.viewportHeight,(e.x!==void 0||e.y!==void 0)&&this.position.set(e.x??0,e.y??0),e.zoom!==void 0&&(this.zoom=e.zoom),e.rotation!==void 0&&(this.rotation=e.rotation),(e.originX!==void 0||e.originY!==void 0)&&this.origin.set(e.originX??.5,e.originY??.5),e.bounds&&(this.bounds=e.bounds.clone())}get zoom(){return this._zoom}set zoom(e){let t=Math.max(1e-4,e);this._zoom!==t&&(this._zoom=t,this._isDirty=!0,this._boundsDirty=!0)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._isDirty=!0,this._boundsDirty=!0)}setPosition(e,t){return(this.position.x!==e||this.position.y!==t)&&(this.position.set(e,t),this._isDirty=!0,this._boundsDirty=!0),this}setViewportSize(e,t){return(this.viewportWidth!==e||this.viewportHeight!==t)&&(this.viewportWidth=e,this.viewportHeight=t,this._isDirty=!0,this._boundsDirty=!0),this}markDirty(){return this._isDirty=!0,this._boundsDirty=!0,this}follow(e,t=.1,n){return this.target=e,this.followLerp=t,this.deadzone=n??null,this}update(e){if(this.target){let e=`position`in this.target?this.target.position:this.target;if(this.deadzone){let t=e.x-this.position.x,n=e.y-this.position.y,r=this.deadzone.width*.5,i=this.deadzone.height*.5,o=this.position.x,s=this.position.y;Math.abs(t)>r&&(o=e.x-Math.sign(t)*r),Math.abs(n)>i&&(s=e.y-Math.sign(n)*i),this.position.x=a.lerp(this.position.x,o,this.followLerp),this.position.y=a.lerp(this.position.y,s,this.followLerp)}else this.position.x=a.lerp(this.position.x,e.x,this.followLerp),this.position.y=a.lerp(this.position.y,e.y,this.followLerp);this._isDirty=!0,this._boundsDirty=!0}if(this.clampToBounds(),this.trauma>0){this.trauma=Math.max(0,this.trauma-this.traumaDecay*e);let t=this.trauma*this.trauma;this._shakeOffsetX=(Math.random()*2-1)*this.maxShakeOffset*t,this._shakeOffsetY=(Math.random()*2-1)*this.maxShakeOffset*t,this._shakeAngle=(Math.random()*2-1)*this.maxShakeAngle*t,this._isDirty=!0,this._boundsDirty=!0}else(this._shakeOffsetX!==0||this._shakeOffsetY!==0||this._shakeAngle!==0)&&(this._shakeOffsetX=0,this._shakeOffsetY=0,this._shakeAngle=0,this._isDirty=!0,this._boundsDirty=!0)}addTrauma(e){return this.trauma=a.clamp01(this.trauma+e),this}clampToBounds(){if(!this.bounds)return;let e=this.position.x,t=this.position.y,n=this.viewportWidth*this.origin.x/this._zoom,r=this.viewportHeight*this.origin.y/this._zoom,i=this.viewportWidth*(1-this.origin.x)/this._zoom,o=this.viewportHeight*(1-this.origin.y)/this._zoom,s=this.bounds.left+n,c=this.bounds.right-i,l=this.bounds.top+r,u=this.bounds.bottom-o;s<=c?this.position.x=a.clamp(this.position.x,s,c):this.position.x=this.bounds.centerX,l<=u?this.position.y=a.clamp(this.position.y,l,u):this.position.y=this.bounds.centerY,(this.position.x!==e||this.position.y!==t)&&(this._isDirty=!0,this._boundsDirty=!0)}updateMatrix(){if(Number.isNaN(this.position.x)||Number.isNaN(this.position.y)||Number.isNaN(this._rotation)||Number.isNaN(this._zoom)||((this.position.x!==this._lastPosX||this.position.y!==this._lastPosY||this.origin.x!==this._lastOriginX||this.origin.y!==this._lastOriginY||this.offset.x!==this._lastOffsetX||this.offset.y!==this._lastOffsetY||this.viewportWidth!==this._lastViewportW||this.viewportHeight!==this._lastViewportH)&&(this._isDirty=!0,this._boundsDirty=!0),!this._isDirty))return;let e=this.origin.x*this.viewportWidth+this.offset.x,t=this.origin.y*this.viewportHeight+this.offset.y,n=this.position.x+this._shakeOffsetX,r=this.position.y+this._shakeOffsetY,i=this._rotation+this._shakeAngle;this._viewMatrix.identity(),this._viewMatrix.translate(e,t),i!==0&&this._viewMatrix.rotate(i),this._zoom!==1&&this._viewMatrix.scale(this._zoom,this._zoom),this._viewMatrix.translate(-n,-r),this._invViewMatrix.copy(this._viewMatrix).invert(),this._lastPosX=this.position.x,this._lastPosY=this.position.y,this._lastOriginX=this.origin.x,this._lastOriginY=this.origin.y,this._lastOffsetX=this.offset.x,this._lastOffsetY=this.offset.y,this._lastViewportW=this.viewportWidth,this._lastViewportH=this.viewportHeight,this._isDirty=!1,this._recomputeVisibleBounds(),this._boundsDirty=!1}getViewMatrix(){return this.updateMatrix(),this._viewMatrix}getInverseViewMatrix(){return this.updateMatrix(),this._invViewMatrix}worldToScreen(e,t){return this.updateMatrix(),this._viewMatrix.transformPoint(e,t)}screenToWorld(e,t){return this.updateMatrix(),this._invViewMatrix.transformPoint(e,t)}applyToContext(e){this.updateMatrix(),e instanceof u?e.transformMatrix(this._viewMatrix):e&&typeof e.transform==`function`&&this._viewMatrix.transformContext(e)}_recomputeVisibleBounds(){if(this._rotation===0&&this._shakeAngle===0){n._scratchScreenTL.set(0,0),n._scratchScreenBR.set(this.viewportWidth,this.viewportHeight);let e=this._invViewMatrix.transformPoint(n._scratchScreenTL,n._scratchWorldTL),t=this._invViewMatrix.transformPoint(n._scratchScreenBR,n._scratchWorldBR);this._visibleBounds.set(e.x,e.y,t.x-e.x,t.y-e.y);return}n._scratchScreenTL.set(0,0),n._scratchScreenTR.set(this.viewportWidth,0),n._scratchScreenBR.set(this.viewportWidth,this.viewportHeight),n._scratchScreenBL.set(0,this.viewportHeight);let e=this._invViewMatrix.transformPoint(n._scratchScreenTL,n._scratchWorldTL),t=this._invViewMatrix.transformPoint(n._scratchScreenTR,n._scratchWorldTR),r=this._invViewMatrix.transformPoint(n._scratchScreenBR,n._scratchWorldBR),i=this._invViewMatrix.transformPoint(n._scratchScreenBL,n._scratchWorldBL),a=Math.min(e.x,t.x,r.x,i.x),o=Math.min(e.y,t.y,r.y,i.y),s=Math.max(e.x,t.x,r.x,i.x),c=Math.max(e.y,t.y,r.y,i.y);this._visibleBounds.set(a,o,s-a,c-o)}getVisibleBounds(e){return this.updateMatrix(),this._boundsDirty&&=(this._recomputeVisibleBounds(),!1),e&&e!==this._visibleBounds?e.copy(this._visibleBounds):this._visibleBounds}isVisible(e){return this.getVisibleBounds().intersects(e)}},v=function(e){return e[e.Primary=0]=`Primary`,e[e.Middle=1]=`Middle`,e[e.Secondary=2]=`Secondary`,e[e.Back=3]=`Back`,e[e.Forward=4]=`Forward`,e}({});function y(e=0){if(typeof e==`number`)return e;switch(e){case`primary`:case`left`:return 0;case`middle`:return 1;case`secondary`:case`right`:return 2;default:return 0}}var b=class{consumed=!1;screenPosition=new e(0,0);canvasPosition=new e(0,0);previousCanvasPosition=new e(0,0);delta=new e(0,0);wheelDelta=new e(0,0);pointerType=`mouse`;pointerId=0;isInside=!1;_downButtons=new Set;_justPressedButtons=new Set;_justReleasedButtons=new Set;_pendingDownButtons=new Set;_pendingUpButtons=new Set;_pendingWheelDelta=new e(0,0);_worldScratch=new e(0,0);isDown(e=0){return this._downButtons.has(y(e))}isJustPressed(e=0){return this._justPressedButtons.has(y(e))}isJustReleased(e=0){return this._justReleasedButtons.has(y(e))}consume(){this.consumed=!0}isConsumed(){return this.consumed}getWorldPosition(e,t){return e.screenToWorld(this.canvasPosition,t??this._worldScratch)}get x(){return this.canvasPosition.x}get y(){return this.canvasPosition.y}updatePositions(e,t,n){if(this.screenPosition.set(e,t),n&&typeof n.getBoundingClientRect==`function`){let r=n.getBoundingClientRect(),i=n,a=i.width??r.width,o=i.height??r.height,s=r.width>0?a/r.width:1,c=r.height>0?o/r.height:1;this.canvasPosition.set((e-r.left)*s,(t-r.top)*c)}else this.canvasPosition.set(e,t)}recordDown(e){this._pendingDownButtons.add(e)}recordUp(e){this._pendingUpButtons.add(e)}recordWheel(e,t){this._pendingWheelDelta.x+=e,this._pendingWheelDelta.y+=t}update(){this._justPressedButtons.clear(),this._justReleasedButtons.clear();for(let e of this._pendingDownButtons)this._downButtons.has(e)||this._justPressedButtons.add(e),this._downButtons.add(e);this._pendingDownButtons.clear();for(let e of this._pendingUpButtons)(this._downButtons.has(e)||this._justPressedButtons.has(e))&&this._justReleasedButtons.add(e),this._downButtons.delete(e);this._pendingUpButtons.clear(),this.delta.subVectors(this.canvasPosition,this.previousCanvasPosition),this.previousCanvasPosition.copy(this.canvasPosition),this.wheelDelta.copy(this._pendingWheelDelta),this._pendingWheelDelta.set(0,0)}lateUpdate(){this._justPressedButtons.clear(),this._justReleasedButtons.clear(),this.wheelDelta.set(0,0),this.consumed=!1}reset(){this._downButtons.clear(),this._justPressedButtons.clear(),this._justReleasedButtons.clear(),this._pendingDownButtons.clear(),this._pendingUpButtons.clear(),this._pendingWheelDelta.set(0,0),this.wheelDelta.set(0,0),this.delta.set(0,0),this.consumed=!1}},x=class{basePosition=new e(0,0);stickPosition=new e(0,0);value=new e(0,0);direction=new e(0,0);magnitude=0;radius=60;deadzone=.15;mode=`floating`;autoHide=!0;visible=!1;isActive=!1;activeTouchId=null;touchArea=null;constructor(e={}){this.mode=e.mode??`floating`,this.radius=e.radius??60,this.deadzone=e.deadzone??.15,this.touchArea=e.touchArea??null,this.autoHide=e.autoHide??this.mode===`floating`,this.visible=e.visible??this.mode===`fixed`,e.basePosition?this.basePosition.copy(e.basePosition):this.mode===`fixed`&&this.basePosition.set(120,480),this.stickPosition.copy(this.basePosition)}handleTouchStart(e,t){if(this.isActive||this.touchArea&&!this.touchArea.containsPoint(t))return!1;if(this.mode===`floating`)this.basePosition.copy(t),this.stickPosition.copy(t),this.visible=!0;else{if(t.distanceTo(this.basePosition)>this.radius*1.5&&!this.touchArea)return!1;this._updateStick(t)}return this.isActive=!0,this.activeTouchId=e,!0}handleTouchMove(e,t){return!this.isActive||this.activeTouchId!==e?!1:(this._updateStick(t),!0)}handleTouchEnd(e){return!this.isActive||this.activeTouchId!==e?!1:(this.isActive=!1,this.activeTouchId=null,this.stickPosition.copy(this.basePosition),this.value.set(0,0),this.direction.set(0,0),this.magnitude=0,this.autoHide&&(this.visible=!1),!0)}_updateStick(e){let t=e.x-this.basePosition.x,n=e.y-this.basePosition.y,r=Math.sqrt(t*t+n*n);if(r<=this.radius)this.stickPosition.copy(e);else{let e=1/r;this.stickPosition.set(this.basePosition.x+t*e*this.radius,this.basePosition.y+n*e*this.radius)}let i=Math.min(r/this.radius,1);if(i<=this.deadzone||r===0)this.value.set(0,0),this.direction.set(0,0),this.magnitude=0;else{let e=1/r,a=t*e,o=n*e,s=(i-this.deadzone)/(1-this.deadzone);this.direction.set(a,o),this.magnitude=s,this.value.set(a*s,o*s)}}render(e){if(!this.visible)return;let t=e instanceof u?e.rawContext:e;t.save(),t.beginPath(),t.arc(this.basePosition.x,this.basePosition.y,this.radius,0,Math.PI*2),t.fillStyle=`rgba(255, 255, 255, 0.15)`,t.fill(),t.lineWidth=2,t.strokeStyle=`rgba(255, 255, 255, 0.4)`,t.stroke();let n=this.radius*.4;t.beginPath(),t.arc(this.stickPosition.x,this.stickPosition.y,n,0,Math.PI*2),t.fillStyle=`rgba(255, 255, 255, 0.5)`,t.fill(),t.lineWidth=2,t.strokeStyle=`#ffffff`,t.stroke(),t.restore()}reset(){this.isActive=!1,this.activeTouchId=null,this.stickPosition.copy(this.basePosition),this.value.set(0,0),this.direction.set(0,0),this.magnitude=0,this.autoHide&&(this.visible=!1)}},S=class{_input;_actions=new Map;_axes1D=new Map;_axes2D=new Map;_scratchVector=new e(0,0);constructor(e){this._input=e}bindAction(e,...t){let n=this._actions.get(e);n||(n=[],this._actions.set(e,n));for(let e of t)n.includes(e)||n.push(e);return this}unbindAction(e,t){if(!t)return this._actions.delete(e),this;let n=this._actions.get(e);if(n){let r=n.indexOf(t);r!==-1&&n.splice(r,1),n.length===0&&this._actions.delete(e)}return this}isDown(e){let t=this._actions.get(e);if(!t)return!1;for(let e=0;e<t.length;e++)if(this._isInputDown(t[e]))return!0;return!1}isJustPressed(e){let t=this._actions.get(e);if(!t)return!1;for(let e=0;e<t.length;e++)if(this._isInputJustPressed(t[e]))return!0;return!1}isJustReleased(e){let t=this._actions.get(e);if(!t)return!1;let n=!1;for(let e=0;e<t.length;e++)this._isInputJustReleased(t[e])&&(n=!0);return n&&!this.isDown(e)}bindAxis1D(e,t){return this._axes1D.set(e,{positive:Array.isArray(t.positive)?[...t.positive]:[t.positive],negative:Array.isArray(t.negative)?[...t.negative]:[t.negative]}),this}unbindAxis1D(e){return this._axes1D.delete(e),this}getAxis(e){let t=this._axes1D.get(e);if(!t)return 0;let n=0,r=0,i=Array.isArray(t.positive)?t.positive:[t.positive];for(let e=0;e<i.length;e++)if(this._isInputDown(i[e])){n=1;break}let a=Array.isArray(t.negative)?t.negative:[t.negative];for(let e=0;e<a.length;e++)if(this._isInputDown(a[e])){r=1;break}return n-r}bindAxis2D(e,t){return this._axes2D.set(e,{up:Array.isArray(t.up)?[...t.up]:[t.up],down:Array.isArray(t.down)?[...t.down]:[t.down],left:Array.isArray(t.left)?[...t.left]:[t.left],right:Array.isArray(t.right)?[...t.right]:[t.right],useJoystick:t.useJoystick??!0,normalize:t.normalize??!0}),this}unbindAxis2D(e){return this._axes2D.delete(e),this}getVector(e,t){let n=t??this._scratchVector;n.set(0,0);let r=this._axes2D.get(e);if(!r)return n;let i=!1,a=!1,o=!1,s=!1;for(let e of r.up)if(this._isInputDown(e)){i=!0;break}for(let e of r.down)if(this._isInputDown(e)){a=!0;break}for(let e of r.left)if(this._isInputDown(e)){o=!0;break}for(let e of r.right)if(this._isInputDown(e)){s=!0;break}let c=!!s-+!!o,l=!!a-+!!i;if(r.useJoystick&&this._input.joystick.isActive&&this._input.joystick.magnitude>0){let e=this._input.joystick.value.x,t=this._input.joystick.value.y;if(c===0&&l===0)return n.set(e,t),n;c+=e,l+=t}return n.set(c,l),r.normalize&&n.lengthSq()>1&&n.normalizeInPlace(),n}toJSON(){let e={};for(let[t,n]of this._actions)e[t]=[...n];let t={};for(let[e,n]of this._axes1D)t[e]={...n};let n={};for(let[e,t]of this._axes2D)n[e]={...t};return{actions:e,axes1D:t,axes2D:n}}fromJSON(e){if(e.actions){this._actions.clear();for(let[t,n]of Object.entries(e.actions))this._actions.set(t,[...n])}if(e.axes1D){this._axes1D.clear();for(let[t,n]of Object.entries(e.axes1D))this.bindAxis1D(t,n)}if(e.axes2D){this._axes2D.clear();for(let[t,n]of Object.entries(e.axes2D))this.bindAxis2D(t,n)}return this}_isInputDown(e){if(e.startsWith(`mouse:`)||e.startsWith(`pointer:`)){let t=this._parseMouseButton(e);return this._input.pointer.isDown(t)}return this._input.isDown(e)}_isInputJustPressed(e){if(e.startsWith(`mouse:`)||e.startsWith(`pointer:`)){let t=this._parseMouseButton(e);return this._input.pointer.isJustPressed(t)}return this._input.isJustPressed(e)}_isInputJustReleased(e){if(e.startsWith(`mouse:`)||e.startsWith(`pointer:`)){let t=this._parseMouseButton(e);return this._input.pointer.isJustReleased(t)}return this._input.isJustReleased(e)}_parseMouseButton(e){switch(e.split(`:`)[1]?.toLowerCase()){case`left`:case`primary`:case`0`:return 0;case`middle`:case`1`:return 1;case`right`:case`secondary`:case`2`:return 2;default:return 0}}};function C(e){if(!e)return``;let t=e.toLowerCase();if(t.length===1&&t>=`a`&&t<=`z`)return`Key`+t.toUpperCase();if(t.length===1&&t>=`0`&&t<=`9`)return`Digit`+t;switch(t){case`space`:case`spacebar`:return`Space`;case`enter`:case`return`:return`Enter`;case`esc`:case`escape`:return`Escape`;case`shift`:return`ShiftLeft`;case`ctrl`:case`control`:return`ControlLeft`;case`alt`:return`AltLeft`;case`tab`:return`Tab`;case`backspace`:return`Backspace`;case`up`:case`arrowup`:return`ArrowUp`;case`down`:case`arrowdown`:return`ArrowDown`;case`left`:case`arrowleft`:return`ArrowLeft`;case`right`:case`arrowright`:return`ArrowRight`;default:return e}}var w=class{pointer;joystick;actions;_target=null;_preventDefaultKeys;_preventContextMenu;_downKeys=new Set;_justPressedKeys=new Set;_justReleasedKeys=new Set;_pendingKeyEvents=[];_touches=new Map;_boundKeyDown=null;_boundKeyUp=null;_boundPointerDown=null;_boundPointerMove=null;_boundPointerUp=null;_boundPointerCancel=null;_boundWheel=null;_boundContextMenu=null;_boundBlur=null;_isAttached=!1;constructor(e={}){let t=typeof HTMLElement<`u`&&e instanceof HTMLElement?{target:e}:e;this.pointer=new b,this.joystick=new x,this.actions=new S(this),this._preventDefaultKeys=new Set(t.preventDefaultKeys??[`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Space`,`Tab`]),this._preventContextMenu=t.preventContextMenu??!0,t.target&&this.attach(t.target)}attach(t){this._isAttached&&this.detach(),this._target=t??(typeof document<`u`?document.body:null),!(!this._target&&typeof window>`u`)&&(this._boundKeyDown=e=>{let t=e.code||e.key;(this._preventDefaultKeys.has(t)||this._preventDefaultKeys.has(e.code))&&typeof e.preventDefault==`function`&&e.preventDefault(),this._pendingKeyEvents.push({type:`down`,code:t})},this._boundKeyUp=e=>{let t=e.code||e.key;this._pendingKeyEvents.push({type:`up`,code:t})},this._boundPointerDown=t=>{this.pointer.updatePositions(t.clientX,t.clientY,this._target),this.pointer.pointerType=t.pointerType||`mouse`,this.pointer.pointerId=t.pointerId,this.pointer.isInside=!0,this.pointer.recordDown(t.button),t.pointerType===`touch`&&(this._touches.set(t.pointerId,{id:t.pointerId,screenPosition:new e(t.clientX,t.clientY),canvasPosition:this.pointer.canvasPosition.clone()}),this.joystick.handleTouchStart(t.pointerId,this.pointer.canvasPosition))},this._boundPointerMove=e=>{if(this.pointer.updatePositions(e.clientX,e.clientY,this._target),this.pointer.isInside=!0,e.pointerType===`touch`){let t=this._touches.get(e.pointerId);t&&(t.screenPosition.set(e.clientX,e.clientY),t.canvasPosition.copy(this.pointer.canvasPosition)),this.joystick.handleTouchMove(e.pointerId,this.pointer.canvasPosition)}},this._boundPointerUp=e=>{this.pointer.updatePositions(e.clientX,e.clientY,this._target),this.pointer.recordUp(e.button),e.pointerType===`touch`&&(this._touches.delete(e.pointerId),this.joystick.handleTouchEnd(e.pointerId))},this._boundPointerCancel=e=>{this.pointer.recordUp(e.button),e.pointerType===`touch`&&(this._touches.delete(e.pointerId),this.joystick.handleTouchEnd(e.pointerId))},this._boundWheel=e=>{this.pointer.recordWheel(e.deltaX,e.deltaY)},this._boundContextMenu=e=>{this._preventContextMenu&&typeof e.preventDefault==`function`&&e.preventDefault()},this._boundBlur=()=>{this.reset()},typeof window<`u`&&(window.addEventListener(`keydown`,this._boundKeyDown,{passive:!1}),window.addEventListener(`keyup`,this._boundKeyUp,{passive:!1}),window.addEventListener(`blur`,this._boundBlur)),this._target&&typeof this._target.addEventListener==`function`&&(this._target.addEventListener(`pointerdown`,this._boundPointerDown),this._target.addEventListener(`pointermove`,this._boundPointerMove),this._target.addEventListener(`pointerup`,this._boundPointerUp),this._target.addEventListener(`pointercancel`,this._boundPointerCancel),this._target.addEventListener(`wheel`,this._boundWheel,{passive:!1}),this._target.addEventListener(`contextmenu`,this._boundContextMenu)),this._isAttached=!0)}detach(){this._isAttached&&=(typeof window<`u`&&(this._boundKeyDown&&window.removeEventListener(`keydown`,this._boundKeyDown),this._boundKeyUp&&window.removeEventListener(`keyup`,this._boundKeyUp),this._boundBlur&&window.removeEventListener(`blur`,this._boundBlur)),this._target&&typeof this._target.removeEventListener==`function`&&(this._boundPointerDown&&this._target.removeEventListener(`pointerdown`,this._boundPointerDown),this._boundPointerMove&&this._target.removeEventListener(`pointermove`,this._boundPointerMove),this._boundPointerUp&&this._target.removeEventListener(`pointerup`,this._boundPointerUp),this._boundPointerCancel&&this._target.removeEventListener(`pointercancel`,this._boundPointerCancel),this._boundWheel&&this._target.removeEventListener(`wheel`,this._boundWheel),this._boundContextMenu&&this._target.removeEventListener(`contextmenu`,this._boundContextMenu)),!1)}update(){this._justPressedKeys.clear(),this._justReleasedKeys.clear();for(let e=0;e<this._pendingKeyEvents.length;e++){let t=this._pendingKeyEvents[e],n=C(t.code);t.type===`down`?(this._downKeys.has(n)||this._justPressedKeys.add(n),this._downKeys.add(n)):t.type===`up`&&((this._downKeys.has(n)||this._justPressedKeys.has(n))&&this._justReleasedKeys.add(n),this._downKeys.delete(n))}this._pendingKeyEvents.length=0,this.pointer.update()}lateUpdate(){this._justPressedKeys.clear(),this._justReleasedKeys.clear(),this.pointer.lateUpdate()}isDown(e){return this._downKeys.has(C(e))}isJustPressed(e){return this._justPressedKeys.has(C(e))}isJustReleased(e){return this._justReleasedKeys.has(C(e))}reset(){this._downKeys.clear(),this._justPressedKeys.clear(),this._justReleasedKeys.clear(),this._pendingKeyEvents.length=0,this._touches.clear(),this.pointer.reset(),this.joystick.reset()}simulateKeyDown(e){this._pendingKeyEvents.push({type:`down`,code:e})}simulateKeyUp(e){this._pendingKeyEvents.push({type:`up`,code:e})}simulateKeyPress(e){this._pendingKeyEvents.push({type:`down`,code:e}),this._pendingKeyEvents.push({type:`up`,code:e})}simulatePointerDown(e,t,n=0){this.pointer.screenPosition.set(e,t),this.pointer.canvasPosition.set(e,t),this.pointer.recordDown(n)}simulatePointerUp(e,t,n=0){this.pointer.screenPosition.set(e,t),this.pointer.canvasPosition.set(e,t),this.pointer.recordUp(n)}simulatePointerMove(e,t){this.pointer.screenPosition.set(e,t),this.pointer.canvasPosition.set(e,t)}simulateWheel(e,t){this.pointer.recordWheel(e,t)}simulateTouchStart(t,n,r){let i=new e(n,r);this._touches.set(t,{id:t,canvasPosition:i.clone(),screenPosition:i.clone()}),this.simulatePointerDown(n,r,0),this.joystick.handleTouchStart(t,i)}simulateTouchMove(t,n,r){let i=new e(n,r),a=this._touches.get(t);a&&(a.canvasPosition.copy(i),a.screenPosition.copy(i)),this.simulatePointerMove(n,r),this.joystick.handleTouchMove(t,i)}simulateTouchEnd(e){this._touches.delete(e),this.simulatePointerUp(this.pointer.canvasPosition.x,this.pointer.canvasPosition.y,0),this.joystick.handleTouchEnd(e)}simulateBlur(){this.reset()}setupVirtualJoystick(e){e&&(e.mode!==void 0&&(this.joystick.mode=e.mode),e.radius!==void 0&&(this.joystick.radius=e.radius),e.deadzone!==void 0&&(this.joystick.deadzone=e.deadzone),e.touchArea!==void 0&&(this.joystick.touchArea=e.touchArea),e.autoHide!==void 0&&(this.joystick.autoHide=e.autoHide),e.visible!==void 0&&(this.joystick.visible=e.visible),e.basePosition&&this.joystick.basePosition.copy(e.basePosition),this.joystick.reset())}destroy(){this.detach(),this.reset()}},T=function(e){return e.Dynamic=`dynamic`,e.Static=`static`,e.Kinematic=`kinematic`,e}({}),E=class t{static _nextId=1;id;bodyType;position;velocity;acceleration;force;rotation;angularVelocity;torque;_mass=1;_invMass=1;_inertia=1;_invInertia=1;fixedRotation=!1;linearDamping=0;angularDamping=0;gravityScale=1;restitution=0;friction=.5;isBullet=!1;isSleeping=!1;canSleep=!0;sleepTimer=0;static linearSleepTolerance=2;static angularSleepTolerance=.05;static timeToSleep=.5;transform=null;userData=null;onCollisionEnter;onCollisionStay;onCollisionExit;onTriggerEnter;onTriggerStay;onTriggerExit;hasCustomInertia=!1;constructor(n={}){this.id=t._nextId++,this.bodyType=n.bodyType??`dynamic`,this.position=n.position?n.position.clone():new e(0,0),this.velocity=n.velocity?n.velocity.clone():new e(0,0),this.acceleration=n.acceleration?n.acceleration.clone():new e(0,0),this.force=new e(0,0),this.rotation=n.rotation??0,this.angularVelocity=n.angularVelocity??0,this.torque=0,this.fixedRotation=n.fixedRotation??!1,this.linearDamping=n.linearDamping??0,this.angularDamping=n.angularDamping??0,this.gravityScale=n.gravityScale??1,this.restitution=n.restitution??0,this.friction=n.friction??.5,this.isBullet=n.isBullet??!1,this.canSleep=n.canSleep??!0,n.mass!==void 0&&n.inertia!==void 0?(this.setMassAndInertia(n.mass,n.inertia),this.hasCustomInertia=!0):n.mass===void 0?this.setMass(1):this.setMass(n.mass),n.inertia!==void 0&&(this.setInertia(n.inertia),this.hasCustomInertia=!0)}get mass(){return this._mass}get invMass(){return this.bodyType===`static`||this.bodyType===`kinematic`?0:this._invMass}get inertia(){return this._inertia}get invInertia(){return this.bodyType===`static`||this.bodyType===`kinematic`||this.fixedRotation?0:this._invInertia}setMass(e){return e<=0?(this._mass=0,this._invMass=0,this._inertia=0,this._invInertia=0,this.bodyType=`static`):(this._mass=e,this._invMass=1/e),this.wakeUp(),this}setInertia(e){return this.hasCustomInertia=!0,e<=0?(this._inertia=0,this._invInertia=0):(this._inertia=e,this._invInertia=1/e),this.wakeUp(),this}setMassAndInertia(e,t){return this.setMass(e),this.setInertia(t),this}setCircleMass(e,t,n){this.setMass(e);let r=n?n.lengthSq():0,i=.5*e*t*t+e*r;return this.setInertia(i),this}setBoxMass(e,t,n,r){this.setMass(e);let i=r?r.lengthSq():0,a=1/12*e*(t*t+n*n)+e*i;return this.setInertia(a),this}applyForce(e,t){if(this.bodyType===`dynamic`&&(this.wakeUp(),this.force.addInPlace(e),t&&!this.fixedRotation)){let n=t.x-this.position.x,r=t.y-this.position.y;this.torque+=n*e.y-r*e.x}}applyImpulse(e,t){if(this.bodyType!==`dynamic`)return;this.wakeUp();let n=this.invMass;if(this.velocity.x+=e.x*n,this.velocity.y+=e.y*n,t&&!this.fixedRotation){let n=t.x-this.position.x,r=t.y-this.position.y,i=n*e.y-r*e.x;this.angularVelocity+=i*this.invInertia}}applyTorque(e){this.bodyType!==`dynamic`||this.fixedRotation||(this.wakeUp(),this.torque+=e)}applyAngularImpulse(e){this.bodyType!==`dynamic`||this.fixedRotation||(this.wakeUp(),this.angularVelocity+=e*this.invInertia)}clearForces(){this.force.set(0,0),this.torque=0}integrateVelocities(e,t){if(this.isSleeping||this.bodyType===`static`||this.bodyType===`kinematic`)return;let n=this.invMass,r=this.acceleration.x+this.force.x*n+t.x*this.gravityScale,i=this.acceleration.y+this.force.y*n+t.y*this.gravityScale;if(this.velocity.x+=r*e,this.velocity.y+=i*e,this.fixedRotation)this.angularVelocity=0;else{let t=this.torque*this.invInertia;this.angularVelocity+=t*e}let o=a.clamp01(1-this.linearDamping*e);if(this.velocity.x*=o,this.velocity.y*=o,!this.fixedRotation){let t=a.clamp01(1-this.angularDamping*e);this.angularVelocity*=t}}integratePositions(e){this.isSleeping||this.bodyType===`static`||(this.position.x+=this.velocity.x*e,this.position.y+=this.velocity.y*e,this.fixedRotation||(this.rotation+=this.angularVelocity*e,this.rotation=a.normalizeAngle(this.rotation)))}updateSleep(e){if(!this.canSleep||this.bodyType!==`dynamic`||this.isSleeping)return;let n=this.velocity.lengthSq(),r=Math.abs(this.angularVelocity),i=t.linearSleepTolerance,a=t.angularSleepTolerance;n<i*i&&r<a?(this.sleepTimer+=e,this.sleepTimer>=t.timeToSleep&&this.sleep()):this.sleepTimer=0}sleep(){!this.canSleep||this.bodyType!==`dynamic`||(this.isSleeping=!0,this.velocity.set(0,0),this.angularVelocity=0,this.clearForces())}wakeUp(){this.isSleeping=!1,this.sleepTimer=0}syncFromTransform(){this.transform&&(this.position.copy(this.transform.position),this.rotation=this.transform.rotation)}syncToTransform(){this.transform&&(this.transform.setPosition(this.position.x,this.position.y),this.transform.setRotation(this.rotation))}},D=class{velocityIterations;positionIterations;baumgarte;penetrationSlop;restitutionVelocityThreshold;enableWarmStarting;_constraints=[];constructor(e={}){this.velocityIterations=e.velocityIterations??8,this.positionIterations=e.positionIterations??3,this.baumgarte=e.baumgarte??.2,this.penetrationSlop=e.penetrationSlop??.02,this.restitutionVelocityThreshold=e.restitutionVelocityThreshold??30,this.enableWarmStarting=e.enableWarmStarting??!1}preStep(t,n){this._constraints=[];for(let r=0;r<t.length;r++){let i=t[r];if(!i.collided||i.contactPoints.length===0)continue;let a=i.bodyA,o=i.bodyB;if((a.bodyType===T.Static||a.isSleeping)&&(o.bodyType===T.Static||o.isSleeping))continue;a.isSleeping&&o.bodyType!==T.Static&&a.wakeUp(),o.isSleeping&&a.bodyType!==T.Static&&o.wakeUp();let s=i.normal.clone(),c=new e(-s.y,s.x),l=i.friction??Math.sqrt(a.friction*o.friction),u=i.restitution??Math.max(a.restitution,o.restitution),d=a.invMass,f=o.invMass,p=a.invInertia,m=o.invInertia,h=[];for(let t=0;t<i.contactPoints.length;t++){let r=i.contactPoints[t],l=new e(r.x-a.position.x,r.y-a.position.y),g=new e(r.x-o.position.x,r.y-o.position.y),_=l.x*s.y-l.y*s.x,v=g.x*s.y-g.y*s.x,y=l.x*c.y-l.y*c.x,b=g.x*c.y-g.y*c.x,x=d+f+p*_*_+m*v*v,S=x>1e-12?1/x:0,C=d+f+p*y*y+m*b*b,w=C>1e-12?1/C:0,T=a.velocity.x-a.angularVelocity*l.y,E=a.velocity.y+a.angularVelocity*l.x,D=o.velocity.x-o.angularVelocity*g.y,O=o.velocity.y+o.angularVelocity*g.x,k=D-T,A=O-E,j=k*s.x+A*s.y,M=0;j<-this.restitutionVelocityThreshold&&(M=-u*j);let N=0;if(this.positionIterations===0&&n>0){let e=Math.max(0,i.penetration-this.penetrationSlop);N=this.baumgarte/n*e}h.push({point:r,rA:l,rB:g,normalMass:S,tangentMass:w,normalImpulse:0,tangentImpulse:0,velocityBias:M+N,rA_cross_n:_,rB_cross_n:v,rA_cross_t:y,rB_cross_t:b})}this._constraints.push({bodyA:a,bodyB:o,normal:s,tangent:c,friction:l,points:h})}}solveVelocityConstraints(){let e=this._constraints;for(let t=0;t<this.velocityIterations;t++)for(let t=0;t<e.length;t++){let n=e[t],r=n.bodyA,i=n.bodyB,o=n.normal,s=n.tangent,c=n.friction,l=r.invMass,u=i.invMass,d=r.invInertia,f=i.invInertia,p=n.points;if(p.length===1){let e=p[0],t=r.velocity.x-r.angularVelocity*e.rA.y,n=r.velocity.y+r.angularVelocity*e.rA.x,a=i.velocity.x-i.angularVelocity*e.rB.y,s=i.velocity.y+i.angularVelocity*e.rB.x,c=(a-t)*o.x+(s-n)*o.y,m=e.normalMass*(e.velocityBias-c),h=e.normalImpulse;e.normalImpulse=Math.max(h+m,0),m=e.normalImpulse-h;let g=m*o.x,_=m*o.y;r.velocity.x-=g*l,r.velocity.y-=_*l,r.angularVelocity-=e.rA_cross_n*m*d,i.velocity.x+=g*u,i.velocity.y+=_*u,i.angularVelocity+=e.rB_cross_n*m*f}else if(p.length===2){let e=p[0],t=p[1],n=e.rA_cross_n,a=e.rB_cross_n,s=t.rA_cross_n,c=t.rB_cross_n,m=l+u+d*n*n+f*a*a,h=l+u+d*s*s+f*c*c,g=l+u+d*n*s+f*a*c,_=m*h-g*g;if(_>1e-12){let p=h/_,v=m/_,y=-g/_,b=r.velocity.x-r.angularVelocity*e.rA.y,x=r.velocity.y+r.angularVelocity*e.rA.x,S=i.velocity.x-i.angularVelocity*e.rB.y,C=i.velocity.y+i.angularVelocity*e.rB.x,w=(S-b)*o.x+(C-x)*o.y,T=r.velocity.x-r.angularVelocity*t.rA.y,E=r.velocity.y+r.angularVelocity*t.rA.x,D=i.velocity.x-i.angularVelocity*t.rB.y,O=i.velocity.y+i.angularVelocity*t.rB.x,k=(D-T)*o.x+(O-E)*o.y,A=e.normalImpulse,j=t.normalImpulse,M=w-e.velocityBias-(m*A+g*j),N=k-t.velocityBias-(g*A+h*j),P=0,F=0,I=-(p*M+y*N),L=-(y*M+v*N);if(I>=0&&L>=0)P=I,F=L;else{let e=-M/m,t=g*e+N;if(e>=0&&t>=0)P=e,F=0;else{let e=-N/h,t=g*e+M;e>=0&&t>=0?(P=0,F=e):M>=0&&N>=0?(P=0,F=0):(P=Math.max(0,I),F=Math.max(0,L))}}let R=P-A,z=F-j;e.normalImpulse=P,t.normalImpulse=F;let ee=R*o.x,te=R*o.y,ne=z*o.x,re=z*o.y,B=ee+ne,V=te+re;r.velocity.x-=B*l,r.velocity.y-=V*l,r.angularVelocity-=(n*R+s*z)*d,i.velocity.x+=B*u,i.velocity.y+=V*u,i.angularVelocity+=(a*R+c*z)*f}else for(let e=0;e<2;e++){let t=p[e],n=r.velocity.x-r.angularVelocity*t.rA.y,a=r.velocity.y+r.angularVelocity*t.rA.x,s=i.velocity.x-i.angularVelocity*t.rB.y,c=i.velocity.y+i.angularVelocity*t.rB.x,m=(s-n)*o.x+(c-a)*o.y,h=t.normalMass*(t.velocityBias-m),g=t.normalImpulse;t.normalImpulse=Math.max(g+h,0),h=t.normalImpulse-g;let _=h*o.x,v=h*o.y;r.velocity.x-=_*l,r.velocity.y-=v*l,r.angularVelocity-=t.rA_cross_n*h*d,i.velocity.x+=_*u,i.velocity.y+=v*u,i.angularVelocity+=t.rB_cross_n*h*f}}else for(let e=0;e<p.length;e++){let t=p[e],n=r.velocity.x-r.angularVelocity*t.rA.y,a=r.velocity.y+r.angularVelocity*t.rA.x,s=i.velocity.x-i.angularVelocity*t.rB.y,c=i.velocity.y+i.angularVelocity*t.rB.x,m=(s-n)*o.x+(c-a)*o.y,h=t.normalMass*(t.velocityBias-m),g=t.normalImpulse;t.normalImpulse=Math.max(g+h,0),h=t.normalImpulse-g;let _=h*o.x,v=h*o.y;r.velocity.x-=_*l,r.velocity.y-=v*l,r.angularVelocity-=t.rA_cross_n*h*d,i.velocity.x+=_*u,i.velocity.y+=v*u,i.angularVelocity+=t.rB_cross_n*h*f}for(let e=0;e<p.length;e++){let t=p[e],n=r.velocity.x-r.angularVelocity*t.rA.y,o=r.velocity.y+r.angularVelocity*t.rA.x,m=i.velocity.x-i.angularVelocity*t.rB.y,h=i.velocity.y+i.angularVelocity*t.rB.x,g=(m-n)*s.x+(h-o)*s.y,_=t.tangentMass*-g,v=c*t.normalImpulse,y=t.tangentImpulse;t.tangentImpulse=a.clamp(y+_,-v,v),_=t.tangentImpulse-y;let b=_*s.x,x=_*s.y;r.velocity.x-=b*l,r.velocity.y-=x*l,r.angularVelocity-=t.rA_cross_t*_*d,i.velocity.x+=b*u,i.velocity.y+=x*u,i.angularVelocity+=t.rB_cross_t*_*f}}}solvePositionConstraints(e){let t=this.penetrationSlop,n=.5,r=!0;for(let i=0;i<this.positionIterations;i++){let i=0;for(let a=0;a<e.length;a++){let o=e[a];if(!o.collided||o.contactPoints.length===0)continue;let s=o.bodyA,c=o.bodyB,l=s.invMass,u=c.invMass,d=s.invInertia,f=c.invInertia;if(l+u===0)continue;let p=o.normal,m=o.penetration,h=Math.max(0,m-t);if(h>i&&(i=h),h<=0)continue;r=!1;let g=o.contactPoints.length;if(g===2){let e=o.contactPoints[0],t=o.contactPoints[1],r=e.x-s.position.x,i=e.y-s.position.y,a=e.x-c.position.x,m=e.y-c.position.y,g=t.x-s.position.x,_=t.y-s.position.y,v=t.x-c.position.x,y=t.y-c.position.y,b=r*p.y-i*p.x,x=a*p.y-m*p.x,S=g*p.y-_*p.x,C=v*p.y-y*p.x,w=l+u+d*b*b+f*x*x,T=l+u+d*S*S+f*C*C,E=w>1e-12?n*h/w/2:0,D=T>1e-12?n*h/T/2:0,O=E+D,k=O*p.x,A=O*p.y;s.position.x-=k*l,s.position.y-=A*l,s.rotation-=(b*E+S*D)*d,c.position.x+=k*u,c.position.y+=A*u,c.rotation+=(x*E+C*D)*f,o.penetration=Math.max(0,o.penetration-O*(l+u))}else for(let e=0;e<g;e++){let t=o.contactPoints[e],r=t.x-s.position.x,i=t.y-s.position.y,a=t.x-c.position.x,m=t.y-c.position.y,_=r*p.y-i*p.x,v=a*p.y-m*p.x,y=l+u+d*_*_+f*v*v;if(y<1e-12)continue;let b=n*h/y/g,x=b*p.x,S=b*p.y;s.position.x-=x*l,s.position.y-=S*l,s.rotation-=_*b*d,c.position.x+=x*u,c.position.y+=S*u,c.rotation+=v*b*f,o.penetration=Math.max(0,o.penetration-b*(l+u))}}if(i<=t)return!0}return r}},O=class{colliderA;colliderB;get 0(){return this.colliderA}get 1(){return this.colliderB}*[Symbol.iterator](){yield this.colliderA,yield this.colliderB}},k=class{key=0;cx=0;cy=0;colliders=[];clear(){this.colliders.length=0}},A=class{cellSize;invCellSize;_cells=new Map;_activeCells=[];_cellPool=[];_pairs=[];_pairCount=0;_queryStamp=1;constructor(e={}){this.cellSize=e.cellSize??64,this.invCellSize=1/this.cellSize;let t=e.initialCapacity??256;for(let e=0;e<t;e++)this._cellPool.push(new k),this._pairs.push(new O)}getCellKey(e,t){return(e&65535)<<16|t&65535}insert(e){let t=e.bounds,n=Math.floor(t.x*this.invCellSize),r=Math.floor(t.y*this.invCellSize),i=Math.floor((t.x+t.width)*this.invCellSize),a=Math.floor((t.y+t.height)*this.invCellSize);e._gridMinCx=n,e._gridMinCy=r,e._gridMaxCx=i,e._gridMaxCy=a;for(let t=r;t<=a;t++)for(let r=n;r<=i;r++){let n=this.getCellKey(r,t),i=this._cells.get(n);i||(i=this.acquireCell(n,r,t),this._cells.set(n,i),this._activeCells.push(i)),i.colliders.push(e)}}remove(e){let t=e._gridMinCx,n=e._gridMinCy,r=e._gridMaxCx,i=e._gridMaxCy;for(let a=n;a<=i;a++)for(let n=t;n<=r;n++){let t=this.getCellKey(n,a),r=this._cells.get(t);if(!r)continue;let i=r.colliders.indexOf(e);if(i!==-1){let e=r.colliders.pop();i<r.colliders.length&&(r.colliders[i]=e)}if(r.colliders.length===0){this._cells.delete(t);let e=this._activeCells.indexOf(r);if(e!==-1){let t=this._activeCells.pop();e<this._activeCells.length&&(this._activeCells[e]=t)}this.releaseCell(r)}}}update(e){let t=e.updateBounds(),n=Math.floor(t.x*this.invCellSize),r=Math.floor(t.y*this.invCellSize),i=Math.floor((t.x+t.width)*this.invCellSize),a=Math.floor((t.y+t.height)*this.invCellSize);(n!==e._gridMinCx||r!==e._gridMinCy||i!==e._gridMaxCx||a!==e._gridMaxCy)&&(this.remove(e),this.insert(e))}clear(){for(let e=0;e<this._activeCells.length;e++)this.releaseCell(this._activeCells[e]);this._activeCells.length=0,this._cells.clear(),this._pairCount=0}generateCandidatePairs(){this._pairCount=0;let e=this._activeCells;for(let t=0;t<e.length;t++){let n=e[t],r=n.colliders,i=r.length;if(i<2)continue;let a=n.cx,o=n.cy;for(let e=0;e<i;e++){let t=r[e];for(let n=e+1;n<i;n++){let e=r[n];if(a!==(t._gridMinCx>e._gridMinCx?t._gridMinCx:e._gridMinCx)||o!==(t._gridMinCy>e._gridMinCy?t._gridMinCy:e._gridMinCy)||t.body&&e.body&&t.body===e.body)continue;let i=t.body,s=e.body,c=!i||i.bodyType===T.Static,l=!s||s.bodyType===T.Static;c&&l||i&&s&&i.isSleeping&&s.isSleeping||i&&s&&(i.isSleeping&&l||s.isSleeping&&c)||(t.layer&e.mask)!==0&&(e.layer&t.mask)!==0&&t.bounds.intersects(e.bounds)&&this.addPair(t,e)}}}return this._pairs.length=this._pairCount,this._pairs}addPair(e,t){let n=this._pairs[this._pairCount];n||(n=new O,this._pairs[this._pairCount]=n),n.colliderA=e,n.colliderB=t,this._pairCount++}queryAABB(e,t=[]){t.length=0;let n=Math.floor(e.x*this.invCellSize),r=Math.floor(e.y*this.invCellSize),i=Math.floor((e.x+e.width)*this.invCellSize),a=Math.floor((e.y+e.height)*this.invCellSize),o=++this._queryStamp;for(let s=r;s<=a;s++)for(let r=n;r<=i;r++){let n=this.getCellKey(r,s),i=this._cells.get(n);if(!i)continue;let a=i.colliders;for(let n=0;n<a.length;n++){let r=a[n];r._queryStamp!==o&&(r._queryStamp=o,r.bounds.intersects(e)&&t.push(r))}}return t}queryPoint(e,t=[]){t.length=0;let n=Math.floor(e.x*this.invCellSize),r=Math.floor(e.y*this.invCellSize),i=this.getCellKey(n,r),a=this._cells.get(i);if(!a)return t;let o=a.colliders;for(let n=0;n<o.length;n++){let r=o[n];r.containsPoint(e)&&t.push(r)}return t}queryRay(e,t=1e3,n=[]){if(n.length=0,this._activeCells.length===0)return n;let r=Number.isFinite(t)&&t>0?Math.min(t,1e5):t<=0?0:1e4;if(r===0){let t=Math.floor(e.origin.x*this.invCellSize),r=Math.floor(e.origin.y*this.invCellSize),i=this._cells.get(this.getCellKey(t,r));if(i){let t=++this._queryStamp;for(let r=0;r<i.colliders.length;r++){let a=i.colliders[r];a._queryStamp!==t&&(a._queryStamp=t,a.intersectsRay(e,0)&&n.push(a))}}return n}let i=++this._queryStamp,a=this.cellSize,o=this.invCellSize,s=Math.floor(e.origin.x*o),c=Math.floor(e.origin.y*o),l=e.origin.x+e.direction.x*r,u=e.origin.y+e.direction.y*r,d=Math.floor(l*o),f=Math.floor(u*o),p=e.direction.x>0?1:e.direction.x<0?-1:0,m=e.direction.y>0?1:e.direction.y<0?-1:0,h=e.direction.x===0?1/0:Math.abs(a/e.direction.x),g=e.direction.y===0?1/0:Math.abs(a/e.direction.y),_;_=p>0?((s+1)*a-e.origin.x)/e.direction.x:p<0?(s*a-e.origin.x)/e.direction.x:1/0;let v;v=m>0?((c+1)*a-e.origin.y)/e.direction.y:m<0?(c*a-e.origin.y)/e.direction.y:1/0;let y=0;for(;!(++y>1e4);){let t=this.getCellKey(s,c),a=this._cells.get(t);if(a){let t=a.colliders;for(let a=0;a<t.length;a++){let o=t[a];o._queryStamp!==i&&(o._queryStamp=i,o.intersectsRay(e,r)&&n.push(o))}}if(s===d&&c===f||_>r&&v>r)break;_<v?(s+=p,_+=h):(c+=m,v+=g)}return n}acquireCell(e,t,n){let r=this._cellPool.pop()??new k;return r.key=e,r.cx=t,r.cy=n,r.colliders.length=0,r}releaseCell(e){e.clear(),this._cellPool.push(e)}get activeCellCount(){return this._activeCells.length}get pooledCellCount(){return this._cellPool.length}};function j(e,t){return e<t?`${e}:${t}`:`${t}:${e}`}var M=class{_previousCollisions=new Map;_currentCollisions=new Map;_previousTriggers=new Map;_currentTriggers=new Map;_emitter;constructor(e){this._emitter=e}processManifolds(e){let t=[];this._currentCollisions.clear(),this._currentTriggers.clear();for(let n=0;n<e.length;n++){let r=e[n];if(!r.collided)continue;let i=r.colliderA,a=r.colliderB,o=r.bodyA??i?.body??null,s=r.bodyB??a?.body??null,c=j(i.id,a.id),l=i.isTrigger||a.isTrigger,u={key:c,colliderA:i,colliderB:a,bodyA:o,bodyB:s,manifold:r,isTrigger:l};l?(this._currentTriggers.set(c,u),this._previousTriggers.has(c)?this._dispatchTriggerStay(u):this._dispatchTriggerEnter(u)):(this._currentCollisions.set(c,u),t.push(r),this._previousCollisions.has(c)?this._dispatchCollisionStay(u):this._dispatchCollisionEnter(u))}for(let[e,t]of this._previousTriggers)this._currentTriggers.has(e)||this._dispatchTriggerExit(t);for(let[e,t]of this._previousCollisions)this._currentCollisions.has(e)||this._dispatchCollisionExit(t);return t}endStep(){this._previousCollisions.clear();for(let[e,t]of this._currentCollisions)this._previousCollisions.set(e,t);this._previousTriggers.clear();for(let[e,t]of this._currentTriggers)this._previousTriggers.set(e,t)}handleColliderRemoved(e){for(let[t,n]of this._previousCollisions)(n.colliderA.id===e.id||n.colliderB.id===e.id)&&(this._dispatchCollisionExit(n),this._previousCollisions.delete(t));for(let[t,n]of this._previousTriggers)(n.colliderA.id===e.id||n.colliderB.id===e.id)&&(this._dispatchTriggerExit(n),this._previousTriggers.delete(t))}_createInvertedManifold(t){return{...t,normal:new e(-t.normal.x,-t.normal.y),bodyA:t.bodyB,bodyB:t.bodyA,colliderA:t.colliderB,colliderB:t.colliderA}}_dispatchTriggerEnter(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i}=e;t.onTriggerEnter?.(n),n.onTriggerEnter?.(t),r?.onTriggerEnter?.(i,t,n),i?.onTriggerEnter?.(r,n,t),this._emitter.emit(`trigger:enter`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i})}_dispatchTriggerStay(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i}=e;t.onTriggerStay?.(n),n.onTriggerStay?.(t),r?.onTriggerStay?.(i,t,n),i?.onTriggerStay?.(r,n,t),this._emitter.emit(`trigger:stay`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i})}_dispatchTriggerExit(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i}=e;t.onTriggerExit?.(n),n.onTriggerExit?.(t),r?.onTriggerExit?.(i,t,n),i?.onTriggerExit?.(r,n,t),this._emitter.emit(`trigger:exit`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i})}_dispatchCollisionEnter(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i,manifold:a}=e,o=this._createInvertedManifold(a);t.onCollisionEnter?.(n,a),n.onCollisionEnter?.(t,o),r?.onCollisionEnter?.(i,t,n,a),i?.onCollisionEnter?.(r,n,t,o),this._emitter.emit(`collision:enter`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i,manifold:a})}_dispatchCollisionStay(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i,manifold:a}=e,o=this._createInvertedManifold(a);t.onCollisionStay?.(n,a),n.onCollisionStay?.(t,o),r?.onCollisionStay?.(i,t,n,a),i?.onCollisionStay?.(r,n,t,o),this._emitter.emit(`collision:stay`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i,manifold:a})}_dispatchCollisionExit(e){let{colliderA:t,colliderB:n,bodyA:r,bodyB:i}=e;t.onCollisionExit?.(n),n.onCollisionExit?.(t),r?.onCollisionExit?.(i,t,n),i?.onCollisionExit?.(r,n,t),this._emitter.emit(`collision:exit`,{colliderA:t,colliderB:n,bodyA:r,bodyB:i})}},N=function(e){return e.Circle=`circle`,e.Box=`box`,e}({}),P=1,F=class{id=P++;_body=null;get body(){return this._body}set body(e){this._body=e,this.updateBodyInertia()}offset=new e(0,0);isTrigger=!1;density=1;friction=.5;restitution=0;layer=1;mask=4294967295;userData=null;updateBodyInertia(){if(this._body&&!this._body.hasCustomInertia&&this._body.mass>0){let e=this.computeInertia(this._body.mass);e>0&&(this._body.setInertia(e),this._body.hasCustomInertia=!1)}}bounds=new r;_gridMinCx=0;_gridMinCy=0;_gridMaxCx=0;_gridMaxCy=0;_queryStamp=0;onCollisionEnter;onCollisionStay;onCollisionExit;onTriggerEnter;onTriggerStay;onTriggerExit;constructor(e,t){if(typeof e==`object`&&e){let t=e;this.body=t.body??null,t.offset&&this.offset.copy(t.offset),this.isTrigger=t.isTrigger??!1,this.density=t.density??1,this.friction=t.friction??.5,this.restitution=t.restitution??0,this.layer=t.collisionLayer??t.layer??1,this.mask=t.collisionMask??t.mask??4294967295,this.userData=t.userData??null}else typeof e==`number`&&this.offset.set(e,t??0)}get collisionLayer(){return this.layer}set collisionLayer(e){this.layer=e}get collisionMask(){return this.mask}set collisionMask(e){this.mask=e}setOffset(e,t){return this.offset.set(e,t),this}setMaterial(e,t,n=this.density){return this.friction=Math.max(0,e),this.restitution=Math.max(0,Math.min(1,t)),this.density=Math.max(1e-6,n),this}setFilter(e,t){return this.layer=e,this.mask=t,this}getWorldPosition(t){let n=t??new e;if(this.body!==null){let e=Math.cos(this.body.rotation),t=Math.sin(this.body.rotation);n.x=this.body.position.x+(this.offset.x*e-this.offset.y*t),n.y=this.body.position.y+(this.offset.x*t+this.offset.y*e)}else n.copy(this.offset);return n}getWorldRotation(){return this.body===null?0:this.body.rotation}getAABB(e){return this.updateBounds(),e?e.copy(this.bounds):this.bounds}updateWorldBounds(){return this.updateBounds()}},I=class{origin;direction;maxDistance;constructor(t=new e(0,0),n=new e(1,0),r=1/0){this.origin=t.clone(),this.direction=n.clone().normalizeInPlace(),this.maxDistance=Math.max(0,r)}set(e,t,n=this.maxDistance){return this.origin.copy(e),this.direction.copy(t).normalizeInPlace(),this.maxDistance=Math.max(0,n),this}getPoint(t,n){let r=n??new e;return r.x=this.origin.x+this.direction.x*t,r.y=this.origin.y+this.direction.y*t,r}},L=class{static intersectCircle(t,n,r){let i=t.origin.x-n.x,a=t.origin.y-n.y,o=t.direction.x,s=t.direction.y,c=i*o+a*s,l=i*i+a*a-r*r;if(l>0&&c>0)return null;let u=c*c-l;if(u<0)return null;let d=Math.sqrt(u),f=-c-d;if(f<0&&(f=0),f>t.maxDistance)return null;let p=t.origin.x+o*f,m=t.origin.y+s*f,h=new e(p,m),g;return g=f>0&&r>1e-6?new e((p-n.x)/r,(m-n.y)/r):t.direction.clone().negateInPlace(),{fraction:t.maxDistance>0&&Number.isFinite(t.maxDistance)?f/t.maxDistance:0,point:h,normal:g}}static intersectBox(t,n,r,i,a=0){let o=Math.cos(a),s=Math.sin(a),c=t.origin.x-n.x,l=t.origin.y-n.y,u=c*o+l*s,d=-c*s+l*o,f=t.direction.x*o+t.direction.y*s,p=-t.direction.x*s+t.direction.y*o,m=-1/0,h=1/0,g=0,_=1;if(Math.abs(f)<1e-8){if(u<-r||u>r)return null}else{let e=1/f,t=(-r-u)*e,n=(r-u)*e,i=-1;if(t>n){let e=t;t=n,n=e,i=1}if(t>m&&(m=t,g=1,_=i),h=Math.min(h,n),m>h)return null}if(Math.abs(p)<1e-8){if(d<-i||d>i)return null}else{let e=1/p,t=(-i-d)*e,n=(i-d)*e,r=-1;if(t>n){let e=t;t=n,n=e,r=1}if(t>m&&(m=t,g=2,_=r),h=Math.min(h,n),m>h)return null}if(h<0)return null;let v=m>=0?m:0;if(v>t.maxDistance)return null;let y=0,b=0;v>0?g===1?y=_:g===2&&(b=_):(y=-f,b=-p);let x=y*o-b*s,S=y*s+b*o,C=new e(t.origin.x+t.direction.x*v,t.origin.y+t.direction.y*v);return{fraction:t.maxDistance>0&&Number.isFinite(t.maxDistance)?v/t.maxDistance:0,point:C,normal:new e(x,S).normalizeInPlace()}}},R=class t extends F{type=N.Circle;radius=10;constructor(e,t=0,n=0){typeof e==`object`&&e?(super(e),this.radius=Math.max(1e-4,e.radius??10)):(super(t,n),this.radius=Math.max(1e-4,typeof e==`number`?e:10)),this.updateBounds(),this.updateBodyInertia()}computeInertia(e){let t=this.radius===void 0?10:this.radius,n=this.offset?this.offset.lengthSq():0;return .5*e*t*t+e*n}get worldCenter(){return this.getWorldPosition()}setRadius(e){return this.radius=Math.max(1e-4,e),this.updateBounds(),this.updateBodyInertia(),this}updateBounds(){let t=this.getWorldPosition(e.temp1),n=this.radius;return this.bounds.set(t.x-n,t.y-n,n*2,n*2)}containsPoint(t){let n=this.getWorldPosition(e.temp1),r=t.x-n.x,i=t.y-n.y;return r*r+i*i<=this.radius*this.radius}intersectsRay(t,n=t.maxDistance){let r=this.getWorldPosition(e.temp1);return L.intersectCircle(t.maxDistance===n?t:new I(t.origin,t.direction,n),r,this.radius)!==null}raycast(t){let n=this.getWorldPosition(e.temp1),r=L.intersectCircle(t,n,this.radius);if(!r)return null;let i=r.point.distanceTo(t.origin);return{collider:this,body:this.body,point:r.point,normal:r.normal,fraction:r.fraction,distance:i}}intersectsCircle(t,n){let r=this.getWorldPosition(e.temp1),i=t.x-r.x,a=t.y-r.y,o=this.radius+n;return i*i+a*a<=o*o}intersectsBox(t,n,r,i=0){let a=this.getWorldPosition(e.temp1),o=n*.5,s=r*.5,c=a.x-t.x,l=a.y-t.y,u=Math.cos(i),d=Math.sin(i),f=c*u+l*d,p=-c*d+l*u,m=Math.max(-o,Math.min(o,f)),h=Math.max(-s,Math.min(s,p)),g=f-m,_=p-h;return g*g+_*_<=this.radius*this.radius}computeMassAndInertia(e=this.density){let t=this.radius,n=Math.PI*t*t*e;return{mass:n,inertia:.5*n*t*t+n*this.offset.lengthSq()}}clone(){return new t({body:this.body,radius:this.radius,offset:this.offset.clone(),isTrigger:this.isTrigger,density:this.density,friction:this.friction,restitution:this.restitution,layer:this.layer,mask:this.mask,userData:this.userData})}},z=class t extends F{type=N.Box;size=new e(20,20);halfExtents=new e(10,10);rotation=0;constructor(e,t=20,n=0,r=0,i=0){if(typeof e==`object`&&e){super(e);let t=e,n=t.width??(t.size?t.size.x:20),r=t.height??(t.size?t.size.y:20);this.setSize(n,r),this.rotation=t.rotation??0}else{super(n,r);let a=typeof e==`number`?e:20;this.setSize(a,t),this.rotation=i}this.updateBounds(),this.updateBodyInertia()}computeInertia(e){let t=this.size?this.size.x:20,n=this.size?this.size.y:20,r=this.offset?this.offset.lengthSq():0;return 1/12*e*(t*t+n*n)+e*r}get width(){return this.size.x}set width(e){this.setSize(e,this.size.y)}get height(){return this.size.y}set height(e){this.setSize(this.size.x,e)}setSize(e,t){let n=Math.max(1e-4,e),r=Math.max(1e-4,t);return this.size.set(n,r),this.halfExtents.set(n*.5,r*.5),this.updateBounds(),this.updateBodyInertia(),this}getWorldRotation(){return(this.body===null?0:this.body.rotation)+this.rotation}getVertices(t){let n=this.getWorldPosition(e.temp1),r=this.getWorldRotation(),i=Math.cos(r),a=Math.sin(r),o=this.halfExtents.x,s=this.halfExtents.y,c=t&&t[0]?t[0]:new e,l=t&&t[1]?t[1]:new e,u=t&&t[2]?t[2]:new e,d=t&&t[3]?t[3]:new e;return c.set(n.x+(-o*i- -s*a),n.y+(-o*a+-s*i)),l.set(n.x+(o*i- -s*a),n.y+(o*a+-s*i)),u.set(n.x+(o*i-s*a),n.y+(o*a+s*i)),d.set(n.x+(-o*i-s*a),n.y+(-o*a+s*i)),[c,l,u,d]}getNormals(t){let n=this.getWorldRotation(),r=Math.cos(n),i=Math.sin(n),a=t&&t[0]?t[0]:new e,o=t&&t[1]?t[1]:new e;return a.set(r,i),o.set(-i,r),[a,o]}updateBounds(){let t=this.getWorldPosition(e.temp1),n=this.getWorldRotation(),r=Math.abs(Math.cos(n)),i=Math.abs(Math.sin(n)),a=this.halfExtents.x*r+this.halfExtents.y*i,o=this.halfExtents.x*i+this.halfExtents.y*r;return this.bounds.set(t.x-a,t.y-o,a*2,o*2)}containsPoint(t){let n=this.getWorldPosition(e.temp1),r=this.getWorldRotation(),i=t.x-n.x,a=t.y-n.y,o=Math.cos(r),s=Math.sin(r),c=i*o+a*s,l=-i*s+a*o,u=this.halfExtents.x,d=this.halfExtents.y;return c>=-u&&c<=u&&l>=-d&&l<=d}intersectsRay(t,n=t.maxDistance){let r=this.getWorldPosition(e.temp1),i=this.getWorldRotation();return L.intersectBox(t.maxDistance===n?t:new I(t.origin,t.direction,n),r,this.halfExtents.x,this.halfExtents.y,i)!==null}raycast(t){let n=this.getWorldPosition(e.temp1),r=this.getWorldRotation(),i=L.intersectBox(t,n,this.halfExtents.x,this.halfExtents.y,r);if(!i)return null;let a=i.point.distanceTo(t.origin);return{collider:this,body:this.body,point:i.point,normal:i.normal,fraction:i.fraction,distance:a}}intersectsCircle(t,n){let r=this.getWorldPosition(e.temp1),i=this.getWorldRotation(),a=this.halfExtents.x,o=this.halfExtents.y,s=t.x-r.x,c=t.y-r.y,l=Math.cos(i),u=Math.sin(i),d=s*l+c*u,f=-s*u+c*l,p=Math.max(-a,Math.min(a,d)),m=Math.max(-o,Math.min(o,f)),h=d-p,g=f-m;return h*h+g*g<=n*n}intersectsBox(t,n,r,i=0){let a=this.getVertices(),o=this.getNormals(),s=Math.cos(i),c=Math.sin(i),l=n*.5,u=r*.5,d=[new e(t.x+(-l*s- -u*c),t.y+(-l*c+-u*s)),new e(t.x+(l*s- -u*c),t.y+(l*c+-u*s)),new e(t.x+(l*s-u*c),t.y+(l*c+u*s)),new e(t.x+(-l*s-u*c),t.y+(-l*c+u*s))],f=[new e(s,c),new e(-c,s)],p=[o[0],o[1],f[0],f[1]];for(let e=0;e<4;e++){let t=p[e],n=a[0].x*t.x+a[0].y*t.y,r=n;for(let e=1;e<4;e++){let i=a[e].x*t.x+a[e].y*t.y;i<n&&(n=i),i>r&&(r=i)}let i=d[0].x*t.x+d[0].y*t.y,o=i;for(let e=1;e<4;e++){let n=d[e].x*t.x+d[e].y*t.y;n<i&&(i=n),n>o&&(o=n)}if(r<i||o<n)return!1}return!0}computeMassAndInertia(e=this.density){let t=this.size.x,n=this.size.y,r=t*n*e;return{mass:r,inertia:1/12*r*(t*t+n*n)+r*this.offset.lengthSq()}}clone(){return new t({body:this.body,width:this.size.x,height:this.size.y,rotation:this.rotation,offset:this.offset.clone(),isTrigger:this.isTrigger,density:this.density,friction:this.friction,restitution:this.restitution,layer:this.layer,mask:this.mask,userData:this.userData})}},ee=class{static _vertsA=[new e,new e,new e,new e];static _vertsB=[new e,new e,new e,new e];static _axesA=[new e,new e];static _axesB=[new e,new e];static test(e,t){return this.collide(e,t)}static collide(e,t){if(e instanceof R&&t instanceof R)return this.collideCircleVsCircle(e,t);if(e instanceof R&&t instanceof z)return this.collideCircleVsBox(e,t);if(e instanceof z&&t instanceof R){let n=this.collideCircleVsBox(t,e);return n===null?null:(n.normal.negateInPlace(),n.bodyA=e.body,n.bodyB=t.body,n.colliderA=e,n.colliderB=t,n)}return e instanceof z&&t instanceof z?this.collideBoxVsBox(e,t):null}static testCircleCircle(e,t){return this.collideCircleVsCircle(e,t)}static collideCircleVsCircle(t,n){let r=t.getWorldPosition(),i=n.getWorldPosition(),a=t.radius,o=n.radius,s=i.x-r.x,c=i.y-r.y,l=s*s+c*c,u=a+o;if(l>u*u)return null;let d=Math.sqrt(l),f,p,m;return d<1e-6?(f=new e(1,0),p=u,m=r.clone()):(f=new e(s/d,c/d),p=u-d,m=new e(r.x+f.x*(a-p*.5),r.y+f.y*(a-p*.5))),{collided:!0,bodyA:t.body,bodyB:n.body,colliderA:t,colliderB:n,normal:f,penetration:p,contactPoints:[m],friction:Math.sqrt(t.friction*n.friction),restitution:Math.max(t.restitution,n.restitution)}}static testCircleBox(e,t){return this.collideCircleVsBox(e,t)}static collideCircleVsBox(t,n){let r=t.getWorldPosition(),i=n.getWorldPosition(),a=n.getWorldRotation(),o=t.radius,s=n.halfExtents.x,c=n.halfExtents.y,l=r.x-i.x,u=r.y-i.y,d=Math.cos(a),f=Math.sin(a),p=l*d+u*f,m=-l*f+u*d,h=Math.max(-s,Math.min(s,p)),g=Math.max(-c,Math.min(c,m)),_=p-h,v=m-g,y=_*_+v*v,b=(t,n)=>new e(i.x+(t*d-n*f),i.y+(t*f+n*d)),x,S,C,w;if(y>1e-12){let e=Math.sqrt(y);if(e>o)return null;x=-_/e,S=-v/e,C=o-e,w=b(h,g)}else{let e=s-Math.abs(p),t=c-Math.abs(m),n,r;if(e<t){let t=p>=0?1:-1;x=-t,S=0,C=o+e,n=t*s,r=m}else{let e=m>=0?1:-1;x=0,S=-e,C=o+t,n=p,r=e*c}w=b(n,r)}let T=new e(x*d-S*f,x*f+S*d);return{collided:!0,bodyA:t.body,bodyB:n.body,colliderA:t,colliderB:n,normal:T,penetration:C,contactPoints:[w],friction:Math.sqrt(t.friction*n.friction),restitution:Math.max(t.restitution,n.restitution)}}static testBoxBox(e,t){return this.collideBoxVsBox(e,t)}static collideBoxVsBox(t,n){let r=t.getVertices(this._vertsA),i=n.getVertices(this._vertsB),a=t.getNormals(this._axesA),o=n.getNormals(this._axesB),s=[a[0],a[1],o[0],o[1]],c=1/0,l=null,u=-1;for(let e=0;e<4;e++){let t=s[e],n=this.projectBox(r,t),a=this.projectBox(i,t),o=Math.min(n.max,a.max)-Math.max(n.min,a.min);if(o<=0)return null;o<c&&(c=o,l=t,u=e)}if(!l)return null;let d=t.getWorldPosition(),f=n.getWorldPosition(),p=l.clone();(f.x-d.x)*p.x+(f.y-d.y)*p.y<0&&p.negateInPlace();let m=u<2,h=m?r:i,g=m?i:r,_=m?p:p.clone().negateInPlace(),v=-1/0,y=0;for(let e=0;e<4;e++){let t=h[e],n=h[(e+1)%4],r=n.x-t.x,i=n.y-t.y,a=Math.sqrt(r*r+i*i),o=i/a,s=-r/a,c=o*_.x+s*_.y;c>v&&(v=c,y=e)}let b=h[y],x=h[(y+1)%4],S=x.x-b.x,C=x.y-b.y,w=Math.sqrt(S*S+C*C),T=S/w,E=C/w,D=C/w,O=-S/w,k=0,A=1/0;for(let e=0;e<4;e++){let t=g[e],n=g[(e+1)%4],r=n.x-t.x,i=n.y-t.y,a=Math.sqrt(r*r+i*i),o=i/a,s=-r/a,c=o*D+s*O;c<A&&(A=c,k=e)}let j=[g[k].clone(),g[(k+1)%4].clone()];if(j=this.clipSegment(j,-T,-E,-T*b.x-E*b.y),j.length<2||(j=this.clipSegment(j,T,E,T*x.x+E*x.y),j.length<2))return null;let M=[],N=D*b.x+O*b.y;for(let e of j)D*e.x+O*e.y-N<=.001&&M.push(e);return M.length===0&&M.push(new e((j[0].x+j[1].x)*.5,(j[0].y+j[1].y)*.5)),{collided:!0,bodyA:t.body,bodyB:n.body,colliderA:t,colliderB:n,normal:p,penetration:c,contactPoints:M,friction:Math.sqrt(t.friction*n.friction),restitution:Math.max(t.restitution,n.restitution)}}static projectBox(e,t){let n=e[0].x*t.x+e[0].y*t.y,r=n;for(let i=1;i<4;i++){let a=e[i].x*t.x+e[i].y*t.y;a<n&&(n=a),a>r&&(r=a)}return{min:n,max:r}}static clipSegment(t,n,r,i){let a=[],o=n*t[0].x+r*t[0].y-i,s=n*t[1].x+r*t[1].y-i;if(o<=0&&a.push(t[0]),s<=0&&a.push(t[1]),o*s<0){let n=o/(o-s),r=new e(t[0].x+(t[1].x-t[0].x)*n,t[0].y+(t[1].y-t[0].y)*n);o>0?a.unshift(r):a.push(r)}return a}static raycast(e,t){return t.raycast(e)}static raycastCircle(e,t){return t.raycast(e)}static raycastBox(e,t){return t.raycast(e)}},te=class extends s{gravity;velocityIterations;positionIterations;subSteps;fixedDeltaTime;allowSleep;_bodies=[];_colliders=[];_spatialGrid;_contactSolver;_collisionFSM;constructor(t={}){super(),this.gravity=t.gravity?t.gravity.clone():new e(0,980),this.velocityIterations=t.velocityIterations??8,this.positionIterations=t.positionIterations??3,this.subSteps=t.subSteps??1,this.fixedDeltaTime=t.fixedDeltaTime??1/60,this.allowSleep=t.allowSleep??!0,this._spatialGrid=new A({cellSize:t.spatialCellSize??64}),this._contactSolver=new D({velocityIterations:this.velocityIterations,positionIterations:this.positionIterations,baumgarte:t.baumgarte??.2,penetrationSlop:t.penetrationSlop??.02,restitutionVelocityThreshold:t.restitutionVelocityThreshold??30,enableWarmStarting:t.enableWarmStarting??!1}),this._collisionFSM=new M(this)}addBody(e){return this._bodies.includes(e)?this:(this._bodies.push(e),e.wakeUp(),this.emit(`body:add`,{body:e}),this)}removeBody(e){let t=this._bodies.indexOf(e);if(t===-1)return this;this._bodies.splice(t,1);for(let t=this._colliders.length-1;t>=0;t--)this._colliders[t].body===e&&this.removeCollider(this._colliders[t]);return this.emit(`body:remove`,{body:e}),this}addCollider(e){return this._colliders.includes(e)?this:(this._colliders.push(e),e.updateWorldBounds(),this._spatialGrid.insert(e),this.emit(`collider:add`,{collider:e}),this)}removeCollider(e){let t=this._colliders.indexOf(e);return t===-1?this:(this._colliders.splice(t,1),this._spatialGrid.remove(e),this._collisionFSM.handleColliderRemoved(e),this.emit(`collider:remove`,{collider:e}),this)}getBodies(){return this._bodies}getColliders(){return this._colliders}getBodyById(e){return this._bodies.find(t=>t.id===e)}clear(e){return super.clear(e),e===void 0&&(this._bodies=[],this._colliders=[],this._spatialGrid.clear()),this}step(e=this.fixedDeltaTime){if(e<=0)return;let t=Math.max(1,this.subSteps),n=e/t;for(let e=0;e<t;e++)this.emit(`step:pre`,{dt:n,subStep:e}),this._internalSubStep(n),this.emit(`step:post`,{dt:n,subStep:e})}_internalSubStep(e){for(let e=0;e<this._bodies.length;e++){let t=this._bodies[e];t.transform&&t.transform.isDirty&&t.syncFromTransform()}for(let t=0;t<this._bodies.length;t++)this._bodies[t].integrateVelocities(e,this.gravity),this._bodies[t].integratePositions(e);for(let e=0;e<this._colliders.length;e++){let t=this._colliders[e];t.updateWorldBounds(),this._spatialGrid.update(t)}let t=this._spatialGrid.generateCandidatePairs(),n=[];for(let e=0;e<t.length;e++){let r=t[e],i=r.colliderA,a=r.colliderB,o=i.body,s=a.body,c=!o||o.bodyType===T.Static,l=!s||s.bodyType===T.Static;if(c&&l||o&&s&&o.isSleeping&&s.isSleeping||o&&s&&(o.isSleeping&&l||s.isSleeping&&c)||o&&s&&o===s||(i.layer&a.mask)===0||(a.layer&i.mask)===0)continue;let u=ee.collide(i,a);u&&u.collided&&n.push(u)}let r=this._collisionFSM.processManifolds(n);r.length>0&&(this._contactSolver.preStep(r,e),this._contactSolver.solveVelocityConstraints(),this._contactSolver.solvePositionConstraints(r));for(let e=0;e<this._bodies.length;e++){let t=this._bodies[e];t.transform&&t.syncToTransform()}if(this.allowSleep)for(let t=0;t<this._bodies.length;t++)this._bodies[t].updateSleep(e);for(let e=0;e<this._bodies.length;e++)this._bodies[e].clearForces();this._collisionFSM.endStep()}raycast(e,t=4294967295){let n=Number.isFinite(e.maxDistance)&&e.maxDistance>0?Math.min(e.maxDistance,1e5):1e4,r=this._spatialGrid.queryRay(e,n),i=null,a=1/0;for(let n=0;n<r.length;n++){let o=r[n];if((o.layer&t)===0)continue;let s=o.raycast(e);s&&s.distance<a&&(a=s.distance,i=s)}return i}raycastAll(e,t=4294967295){let n=Number.isFinite(e.maxDistance)&&e.maxDistance>0?Math.min(e.maxDistance,1e5):1e4,r=this._spatialGrid.queryRay(e,n),i=[];for(let n=0;n<r.length;n++){let a=r[n];if((a.layer&t)===0)continue;let o=a.raycast(e);o&&i.push(o)}return i.sort((e,t)=>e.distance-t.distance)}overlapCircle(e,t,n=4294967295){let i=new r(e.x-t,e.y-t,t*2,t*2),a=this._spatialGrid.queryAABB(i),o=[];for(let r=0;r<a.length;r++){let i=a[r];(i.layer&n)!==0&&i.intersectsCircle(e,t)&&o.push(i)}return o}overlapBox(e,t,n,i=0,a=4294967295){let o=Math.sqrt(t*t+n*n)*.5,s=new r(e.x-o,e.y-o,o*2,o*2),c=this._spatialGrid.queryAABB(s),l=[];for(let r=0;r<c.length;r++){let o=c[r];(o.layer&a)!==0&&o.intersectsBox(e,t,n,i)&&l.push(o)}return l}overlapPoint(e,t=4294967295){let n=this._spatialGrid.queryPoint(e),r=[];for(let i=0;i<n.length;i++){let a=n[i];(a.layer&t)!==0&&a.containsPoint(e)&&r.push(a)}return r}},ne=class e{name;context;gainNode;_parentBus=null;_children=new Set;_volume=1;_muted=!1;constructor(e,t){this.context=e,this.name=t.name,this._volume=t.volume===void 0?1:Math.max(0,Math.min(1,t.volume)),this._muted=t.muted??!1,this.gainNode=e.createGain();let n=this._muted?0:this._volume;this.gainNode.gain.setValueAtTime(n,e.currentTime),t.parentBus?this.setParentBus(t.parentBus):this.gainNode.connect(e.destination)}get parentBus(){return this._parentBus}setParentBus(e){if(this._parentBus!==e){try{this.gainNode.disconnect()}catch{}this._parentBus&&this._parentBus._children.delete(this),this._parentBus=e,this._parentBus?(this._parentBus._children.add(this),this.gainNode.connect(this._parentBus.gainNode)):this.gainNode.connect(this.context.destination)}}get volume(){return this._volume}setVolume(e,t=0){return this._volume=Math.max(0,Math.min(1,e)),this._muted||this._applyGain(this._volume,t),this}get muted(){return this._muted}setMuted(e,t=0){this._muted=e;let n=this._muted?0:this._volume;return this._applyGain(n,t),this}toggleMute(e=0){return this.setMuted(!this._muted,e),this._muted}get effectiveVolume(){let e=this._parentBus?this._parentBus.effectiveVolume:1;return this._muted?0:this._volume*e}get isEffectiveMuted(){return this._muted?!0:this._parentBus?this._parentBus.isEffectiveMuted:!1}createChildBus(t,n=1){return new e(this.context,{name:t,volume:n,parentBus:this})}connectSource(e){e.connect(this.gainNode)}disconnectSource(e){try{e.disconnect(this.gainNode)}catch{}}_applyGain(e,t){let n=this.context.currentTime,r=this.gainNode.gain;t>0?(r.setValueAtTime(r.value,n),r.linearRampToValueAtTime(e,n+t)):r.setValueAtTime(e,n)}destroy(){try{this.gainNode.disconnect()}catch{}this._parentBus&&=(this._parentBus._children.delete(this),null),this._children.clear()}},re=class{context;maxVoices;maxInstancesPerKey;stealFadeDuration;_activeVoices=new Map;_nextVoiceId=1;constructor(e,t){this.context=e,this.maxVoices=t?.maxVoices??32,this.maxInstancesPerKey=t?.maxInstancesPerKey??8,this.stealFadeDuration=t?.stealFadeDuration??.01}play(e,t,n){let r=n?.key??n?.bus??`default`;this._enforceKeyLimit(r),this._activeVoices.size>=this.maxVoices&&this._stealOldestVoice();let i=this._nextVoiceId++,a=this.context.currentTime,o=this.context.createGain(),s=Math.max(0,Math.min(1,n?.volume??1));n?.fadeInDuration&&n.fadeInDuration>0?(o.gain.setValueAtTime(0,a),o.gain.linearRampToValueAtTime(s,a+n.fadeInDuration)):o.gain.setValueAtTime(s,a),o.connect(t.gainNode);let c=this.context.createBufferSource();c.buffer=e;let l=n?.pitch??1;if(n?.pitchRandom&&n.pitchRandom>0){let e=(Math.random()*2-1)*n.pitchRandom;l*=1+e}c.playbackRate.setValueAtTime(Math.max(.1,l),a),c.loop=!!n?.loop,n?.loopStart!==void 0&&(c.loopStart=n.loopStart),n?.loopEnd!==void 0&&(c.loopEnd=n.loopEnd),c.connect(o);let u={id:i,key:r,sourceNode:c,gainNode:o,startTime:a,duration:n?.duration??e.duration/l,loop:c.loop,bus:t};this._activeVoices.set(i,u),c.onended=()=>{this._cleanupVoice(i)};let d=n?.offset??0;return n?.duration?c.start(a,d,n.duration):c.start(a,d),i}stop(e,t){let n=this._activeVoices.get(e);if(!n)return!1;let r=t===void 0?0:t,i=this.context.currentTime;if(r>0){try{n.gainNode.gain.setValueAtTime(n.gainNode.gain.value,i),n.gainNode.gain.linearRampToValueAtTime(0,i+r)}catch{}this._activeVoices.delete(e),setTimeout(()=>{try{n.sourceNode.stop(),n.sourceNode.disconnect(),n.gainNode.disconnect()}catch{}},r*1e3)}else{try{n.sourceNode.stop()}catch{}this._cleanupVoice(e)}return!0}stopKey(e,t){let n=0;for(let[r,i]of Array.from(this._activeVoices.entries()))i.key===e&&(this.stop(r,t),n++);return n}stopAll(e){let t=Array.from(this._activeVoices.keys());for(let n of t)this.stop(n,e)}getActiveCount(){return this._activeVoices.size}getActiveCountForKey(e){let t=0;for(let n of this._activeVoices.values())n.key===e&&t++;return t}hasVoice(e){return this._activeVoices.has(e)}_enforceKeyLimit(e){let t=[];for(let n of this._activeVoices.values())n.key===e&&t.push(n);if(t.length>=this.maxInstancesPerKey){t.sort((e,t)=>e.startTime-t.startTime);let e=t[0];this.stop(e.id,this.stealFadeDuration)}}_stealOldestVoice(){let e=null;for(let t of this._activeVoices.values())(!e||t.startTime<e.startTime)&&(e=t);e&&this.stop(e.id,this.stealFadeDuration)}_cleanupVoice(e){let t=this._activeVoices.get(e);if(t){t.sourceNode.onended=null;try{t.sourceNode.disconnect()}catch{}try{t.gainNode.disconnect()}catch{}this._activeVoices.delete(e)}}destroy(){this.stopAll(0),this._activeVoices.clear()}},B=class{static createSynthBuffer(e,t){let n=e.sampleRate||44100,r=Math.max(.01,t.duration),i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t.startFreq,c=t.endFreq??t.startFreq,l=Math.max(0,Math.min(1,t.volume??.8)),u=Math.min(r,t.attack??.005),d=t.decay??r-u,f=t.waveform??`sine`,p=0;for(let e=0;e<i;e++){let t=e/n,i=t/r,a=s+(c-s)*i,m=2*Math.PI*a/n;p+=m;let h=0;switch(f){case`square`:h=Math.sin(p)>=0?1:-1;break;case`sawtooth`:h=2*(p/(2*Math.PI)%1)-1;break;case`triangle`:h=2*Math.abs(2*(p/(2*Math.PI)%1)-1)-1;break;default:h=Math.sin(p)}let g=1;if(t<u)g=t/u;else{let e=t-u;g=Math.max(0,1-e/Math.max(.001,d))}o[e]=Math.max(-1,Math.min(1,h*g*l))}return a}static createLaserBuffer(e,t){let n=e.sampleRate||44100,r=.15,i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t?.volume??.7,c=0;for(let e=0;e<i;e++){let t=e/n,i=880*(220/880)**(t/r);c+=2*Math.PI*i/n;let a=Math.sin(c)>=0?.8:-.8,l=(1-t/r)**1.2;o[e]=Math.max(-1,Math.min(1,a*l*s))}return a}static createExplosionBuffer(e,t){let n=e.sampleRate||44100,r=.45,i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t?.volume??.85,c=0;for(let e=0;e<i;e++){let t=e/n,i=Math.random()*2-1,a=800*(60/800)**(t/r),l=2*Math.PI*a/n/(1+2*Math.PI*a/n);c+=l*(i-c);let u=Math.min(1,t/.005),d=Math.exp(t/r*-6);o[e]=Math.max(-1,Math.min(1,c*u*d*s))}return a}static createJumpBuffer(e,t){let n=e.sampleRate||44100,r=.18,i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t?.volume??.7,c=0;for(let e=0;e<i;e++){let t=e/n,i=150+t/r*450;c+=2*Math.PI*i/n;let a=Math.sin(c)>=0?.75:-.75,l=t<.14?1:Math.max(0,1-(t-.14)/.04);o[e]=Math.max(-1,Math.min(1,a*l*s))}return a}static createCoinBuffer(e,t){let n=e.sampleRate||44100,r=Math.floor(n*.3),i=e.createBuffer(1,r,n),a=i.getChannelData(0),o=t?.volume??.75,s=0;for(let e=0;e<r;e++){let t=e/n,r=t>=.08,i=r?1318.51:987.77;s+=2*Math.PI*i/n;let c=Math.sin(s),l=.8*c+.2*(c>=0?1:-1),u=1;if(r){let e=t-.08;u=Math.max(0,1-e/.22)**1.5}a[e]=Math.max(-1,Math.min(1,l*u*o))}return i}static createHitBuffer(e,t){let n=e.sampleRate||44100,r=.12,i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t?.volume??.85,c=0;for(let e=0;e<i;e++){let t=e/n,i=300*(60/300)**(t/r);c+=2*Math.PI*i/n;let a=2*(c/(2*Math.PI)%1)-1,l=(Math.random()*2-1)*.2,u=Math.exp(t/r*-12);o[e]=Math.max(-1,Math.min(1,(a+l)*u*s))}return a}static createPowerupBuffer(e,t){let n=e.sampleRate||44100,r=.36,i=Math.floor(n*r),a=e.createBuffer(1,i,n),o=a.getChannelData(0),s=t?.volume??.75,c=[523.25,659.25,783.99,1046.5],l=.08,u=0;for(let e=0;e<i;e++){let t=e/n,i=Math.min(c.length-1,Math.floor(t/l)),a=c[i];u+=2*Math.PI*a/n;let d=2*Math.abs(2*(u/(2*Math.PI)%1)-1)-1,f=1;if(i===c.length-1){let e=t-(c.length-1)*l;f=Math.max(0,1-e/(r-(c.length-1)*l))}o[e]=Math.max(-1,Math.min(1,d*f*s))}return a}static playLaser(e,t,n){let r=e.currentTime,i=e.createOscillator(),a=e.createGain(),o=n?.volume??.7;return i.type=`square`,i.frequency.setValueAtTime(880,r),i.frequency.exponentialRampToValueAtTime(220,r+.15),a.gain.setValueAtTime(o,r),a.gain.linearRampToValueAtTime(0,r+.15),i.connect(a),a.connect(t),i.start(r),i.stop(r+.15),a}static playJump(e,t,n){let r=e.currentTime,i=e.createOscillator(),a=e.createGain(),o=n?.volume??.7;return i.type=`square`,i.frequency.setValueAtTime(150,r),i.frequency.exponentialRampToValueAtTime(600,r+.18),a.gain.setValueAtTime(o,r),a.gain.setValueAtTime(o,r+.14),a.gain.linearRampToValueAtTime(0,r+.18),i.connect(a),a.connect(t),i.start(r),i.stop(r+.18),a}},V=class extends s{_context=null;_isUnlocked=!1;_unlockListenersAttached=!1;_boundUnlockHandler=null;_masterBus=null;_musicBus=null;_sfxBus=null;_buses=new Map;_voicePool=null;_buffers=new Map;_currentMusicVoiceId=null;_currentMusicKey=null;_currentMusicGain=null;_currentMusicSource=null;_isMusicPlaying=!1;constructor(){super(),this.init()}init(){if(this._context)return;let e=globalThis.AudioContext||globalThis.webkitAudioContext;if(e)try{this._context=new e}catch(e){console.warn(`SoundManager: Failed to construct AudioContext`,e)}this._context&&(this._masterBus=new ne(this._context,{name:`master`,volume:1}),this._musicBus=this._masterBus.createChildBus(`music`,1),this._sfxBus=this._masterBus.createChildBus(`sfx`,1),this._buses.set(`master`,this._masterBus),this._buses.set(`music`,this._musicBus),this._buses.set(`sfx`,this._sfxBus),this._voicePool=new re(this._context),this._prebakeProceduralSounds(),this._context.state===`running`?this._isUnlocked=!0:this._attachAutoplayUnlockListeners())}get context(){return this._context}get state(){return this._context?.state??`closed`}get isUnlocked(){return this._isUnlocked}async unlock(){if(!this._context)return!1;if(this._context.state===`suspended`)try{await this._context.resume()}catch{}return this._context.state===`running`&&(this._handleUnlocked(),!0)}_attachAutoplayUnlockListeners(){if(this._unlockListenersAttached||typeof window>`u`)return;let e=[`click`,`touchstart`,`touchend`,`keydown`,`pointerdown`];this._boundUnlockHandler=()=>{this._context&&(this._context.state===`suspended`?this._context.resume().then(()=>{this._context?.state===`running`&&this._handleUnlocked()}).catch(()=>{}):this._context.state===`running`&&this._handleUnlocked())};for(let t of e)window.addEventListener(t,this._boundUnlockHandler,{passive:!0,once:!1});this._unlockListenersAttached=!0}_handleUnlocked(){this._isUnlocked=!0,this._detachAutoplayUnlockListeners(),this.emit(`unlock`),this.emit(`statechange`,`running`)}_detachAutoplayUnlockListeners(){if(!(!this._unlockListenersAttached||!this._boundUnlockHandler||typeof window>`u`)){for(let e of[`click`,`touchstart`,`touchend`,`keydown`,`pointerdown`])window.removeEventListener(e,this._boundUnlockHandler);this._unlockListenersAttached=!1,this._boundUnlockHandler=null}}get masterVolume(){return this._masterBus?.volume??1}setMasterVolume(e,t=0){this._masterBus?.setVolume(e,t),this.emit(`volumechange`,{bus:`master`,volume:this.masterVolume})}get musicVolume(){return this._musicBus?.volume??1}setMusicVolume(e,t=0){this._musicBus?.setVolume(e,t),this.emit(`volumechange`,{bus:`music`,volume:this.musicVolume})}get sfxVolume(){return this._sfxBus?.volume??1}setSfxVolume(e,t=0){this._sfxBus?.setVolume(e,t),this.emit(`volumechange`,{bus:`sfx`,volume:this.sfxVolume})}get isMuted(){return this._masterBus?.muted??!1}mute(e=0){this._masterBus?.setMuted(!0,e),this.emit(`mutechange`,!0)}unmute(e=0){this._masterBus?.setMuted(!1,e),this.emit(`mutechange`,!1)}toggleMute(e=0){let t=this._masterBus?.toggleMute(e)??!1;return this.emit(`mutechange`,t),t}getBus(e){return this._buses.get(e)}createBus(e,t=`master`){if(!this._context)throw Error(`SoundManager: AudioContext uninitialized`);let n=(this.getBus(t)??this._masterBus).createChildBus(e);return this._buses.set(e,n),n}registerSound(e,t){this._buffers.set(e,t)}hasSound(e){return this._buffers.has(e)}getSound(e){return this._buffers.get(e)}async loadSound(e,t){if(!this._context)throw Error(`SoundManager: AudioContext uninitialized`);if(this._buffers.has(e))return this._buffers.get(e);let n=await fetch(t);if(!n.ok)throw Error(`SoundManager: Failed to fetch sound from ${t} (status: ${n.status})`);let r=await n.arrayBuffer(),i=await this._context.decodeAudioData(r);return this.registerSound(e,i),i}playSound(e,t){if(!this._context||!this._voicePool)return-1;let n=this._buffers.get(e);if(!n)return console.warn(`SoundManager: Sound "${e}" not found in cache.`),-1;let r=(t?.bus?this.getBus(t.bus):null)??this._sfxBus;return this._voicePool.play(n,r,{...t,key:e})}stopSound(e,t){return this._voicePool?.stop(e,t)??!1}stopAllSfx(e){this._voicePool?.stopAll(e)}playMusic(e,t){if(!this._context||!this._musicBus)return;let n=this._buffers.get(e);if(!n){console.warn(`SoundManager: Music "${e}" not found in cache.`);return}let r=t?.crossFadeDuration??.5,i=this._context.currentTime;if(this._currentMusicGain&&this._currentMusicSource&&this._isMusicPlaying){let e=this._currentMusicGain,t=this._currentMusicSource;try{e.gain.setValueAtTime(e.gain.value,i),e.gain.linearRampToValueAtTime(0,i+r),setTimeout(()=>{try{t.stop(),t.disconnect(),e.disconnect()}catch{}},r*1e3)}catch{}}let a=this._context.createGain(),o=Math.max(0,Math.min(1,t?.volume??1));if(r>0||t?.fadeInDuration&&t.fadeInDuration>0){let e=t?.fadeInDuration??r;a.gain.setValueAtTime(0,i),a.gain.linearRampToValueAtTime(o,i+e)}else a.gain.setValueAtTime(o,i);a.connect(this._musicBus.gainNode);let s=this._context.createBufferSource();s.buffer=n,s.loop=t?.loop!==!1,s.connect(a),s.start(i),this._currentMusicGain=a,this._currentMusicSource=s,this._currentMusicKey=e,this._isMusicPlaying=!0}pauseMusic(){!this._context||!this._isMusicPlaying||this.stopMusic(.1)}resumeMusic(){this._currentMusicKey&&this.playMusic(this._currentMusicKey)}stopMusic(e=.2){if(!this._currentMusicGain||!this._currentMusicSource)return;let t=this._context?.currentTime??0,n=this._currentMusicGain,r=this._currentMusicSource;if(e>0)try{n.gain.setValueAtTime(n.gain.value,t),n.gain.linearRampToValueAtTime(0,t+e),setTimeout(()=>{try{r.stop(),r.disconnect(),n.disconnect()}catch{}},e*1e3)}catch{}else try{r.stop(),r.disconnect(),n.disconnect()}catch{}this._isMusicPlaying=!1}isMusicPlaying(){return this._isMusicPlaying}playLaser(e){return this.playSound(`laser`,e)}playExplosion(e){return this.playSound(`explosion`,e)}playJump(e){return this.playSound(`jump`,e)}playCoin(e){return this.playSound(`coin`,e)}playHit(e){return this.playSound(`hit`,e)}playPowerup(e){return this.playSound(`powerup`,e)}playSynth(e,t){if(!this._context||!this._voicePool)return-1;let n=B.createSynthBuffer(this._context,e),r=(t?.bus?this.getBus(t.bus):null)??this._sfxBus;return this._voicePool.play(n,r,t)}_prebakeProceduralSounds(){this._context&&(this.registerSound(`laser`,B.createLaserBuffer(this._context)),this.registerSound(`explosion`,B.createExplosionBuffer(this._context)),this.registerSound(`jump`,B.createJumpBuffer(this._context)),this.registerSound(`coin`,B.createCoinBuffer(this._context)),this.registerSound(`hit`,B.createHitBuffer(this._context)),this.registerSound(`powerup`,B.createPowerupBuffer(this._context)))}stopAll(){this.stopAllSfx(),this.stopMusic(0)}destroy(){if(this.stopAll(),this._detachAutoplayUnlockListeners(),this._voicePool?.destroy(),this._masterBus?.destroy(),this._buses.clear(),this._buffers.clear(),this._context&&this._context.state!==`closed`)try{this._context.close()}catch{}this._context=null,this._isUnlocked=!1,this.clear()}},ie=class{_data=new Map;_emitter=new s;set(e,t){let n=this._data.get(e);if(n===t&&this._data.has(e))return this;this._data.set(e,t);let r={value:t,oldValue:n};return this._emitter.emit(`change:${e}`,r),this._emitter.emit(`change`,{key:e,value:t,oldValue:n}),this}get(e,t){return this._data.has(e)?this._data.get(e):t}has(e){return this._data.has(e)}delete(e){if(!this._data.has(e))return!1;let t=this._data.get(e);this._data.delete(e);let n={value:void 0,oldValue:t};return this._emitter.emit(`change:${e}`,n),this._emitter.emit(`change`,{key:e,value:void 0,oldValue:t}),!0}clear(){this._data.size!==0&&(this._data.clear(),this._emitter.emit(`clear`))}increment(e,t=1){let n=(typeof this.get(e)==`number`?this.get(e):0)+t;return this.set(e,n),n}decrement(e,t=1){return this.increment(e,-t)}toggle(e){let t=!this.get(e,!1);return this.set(e,t),t}onChange(e,t){return this._emitter.subscribe(`change:${e}`,e=>{t(e.value,e.oldValue)})}onAnyChange(e){return this._emitter.subscribe(`change`,t=>{e(t.key,t.value,t.oldValue)})}toObject(){let e={};for(let[t,n]of this._data.entries())e[t]=n;return e}fromObject(e){if(!e||typeof e!=`object`)return this;for(let[t,n]of Object.entries(e))this.set(t,n);return this}serialize(){return JSON.stringify(this.toObject())}deserialize(e){try{let t=JSON.parse(e);this.fromObject(t)}catch(e){console.error(`Blackboard.deserialize failed:`,e)}return this}saveToLocalStorage(e){if(typeof localStorage>`u`)return!1;try{return localStorage.setItem(e,this.serialize()),!0}catch{return!1}}loadFromLocalStorage(e){if(typeof localStorage>`u`)return!1;try{let t=localStorage.getItem(e);if(t!==null)return this.deserialize(t),!0}catch{return!1}return!1}},H=function(e){return e.UNINITIALIZED=`UNINITIALIZED`,e.INACTIVE=`INACTIVE`,e.ENTERING=`ENTERING`,e.ACTIVE=`ACTIVE`,e.PAUSED=`PAUSED`,e.EXITING=`EXITING`,e.DESTROYED=`DESTROYED`,e}({}),ae=class{name=``;game;sceneManager;blackboard;state=`UNINITIALIZED`;renderUnderlying=!1;camera=null;_localState=new Map;get initialized(){return this.state!==`UNINITIALIZED`&&this.state!==`DESTROYED`}get active(){return this.state===`ACTIVE`}get paused(){return this.state===`PAUSED`}init(e){this.game=e,this.state=`INACTIVE`}enter(e){this.state=`ACTIVE`}update(e){}fixedUpdate(e){}render(e){}pause(){this.state=`PAUSED`}resume(e){this.state=`ACTIVE`}exit(){this.state=`INACTIVE`}destroy(){this.state=`DESTROYED`,this._localState.clear(),this.camera=null}setLocal(e,t){this._localState.set(e,t)}getLocal(e,t){return this._localState.has(e)?this._localState.get(e):t}hasLocal(e){return this._localState.has(e)}deleteLocal(e){return this._localState.delete(e)}clearLocal(){this._localState.clear()}},oe=class{game;blackboard;events=new s;_registry=new Map;_instances=new Map;_stack=[];_previousScene=null;_activeTransition=null;_transitionFromScene=null;_transitionToScene=null;_pendingSwitchData=void 0;constructor(e){this.game=e,this.blackboard=new ie}add(e,t){if(!e||typeof e!=`string`)throw TypeError(`SceneManager.add: name must be a non-empty string, received ${e}`);return this._registry.set(e,t),typeof t!=`function`&&(this._instances.set(e,t),this._bindSceneMetadata(e,t),this.events.emit(`scene:added`,{name:e,scene:t})),this}has(e){return this._registry.has(e)}remove(e){if(!this._registry.has(e))return!1;let t=this._instances.get(e);if(t){let n=this._stack.indexOf(t);n!==-1&&(t.exit(),t.destroy(),this._stack.splice(n,1)),this._instances.delete(e)}return this._registry.delete(e),this.events.emit(`scene:removed`,{name:e}),!0}get(e){let t=this._instances.get(e);if(!t){let n=this._registry.get(e);if(!n)return;typeof n==`function`?(t=new n,this._instances.set(e,t),this._bindSceneMetadata(e,t),this.events.emit(`scene:added`,{name:e,scene:t})):t=n}return t}getSceneNames(){return Array.from(this._registry.keys())}get currentScene(){return this._stack.length>0?this._stack[this._stack.length-1]:null}get previousScene(){return this._previousScene}get stackDepth(){return this._stack.length}getStack(){return this._stack}get isTransitioning(){return this._activeTransition!==null&&!this._activeTransition.isComplete}get activeTransition(){return this._activeTransition}switchTo(e,t,n){let r=this.get(e);if(!r)throw Error(`SceneManager.switchTo: Scene "${e}" not found in registry`);this._activeTransition&&!this._activeTransition.isComplete&&this._finishTransition();let i=this.currentScene;return this._ensureSceneInitialized(r),!t||t.duration===0?(this._executeDirectSwitch(i,r,n),!0):(this._activeTransition=t,this._transitionFromScene=i,this._transitionToScene=r,this._pendingSwitchData=n,t.start(i,r),t.hasMidpoint||(r.enter(n),r.state!==H.ACTIVE&&(r.state=H.ACTIVE)),this.events.emit(`transition:start`,{type:t.constructor.name,from:i?i.name:null,to:r.name,duration:t.duration}),!0)}push(e,t,n){let r=this.get(e);if(!r)throw Error(`SceneManager.push: Scene "${e}" not found in registry`);let i=this.currentScene;return i&&typeof i.pause==`function`&&i.pause(),this._ensureSceneInitialized(r),this._stack.push(r),r.enter(n),r.state!==H.ACTIVE&&(r.state=H.ACTIVE),t&&t.duration>0&&(this._activeTransition=t,this._transitionFromScene=i,this._transitionToScene=r,t.start(i,r)),this.events.emit(`scene:pushed`,{name:r.name,depth:this._stack.length,data:n}),!0}pop(e,t){if(this._stack.length<=1)return null;let n=this._stack.pop();n.exit();let r=this.currentScene;return r&&typeof r.resume==`function`&&r.resume(t),e&&e.duration>0&&(this._activeTransition=e,this._transitionFromScene=n,this._transitionToScene=r,e.start(n,r)),this.events.emit(`scene:popped`,{name:n.name,depth:this._stack.length,result:t}),n}update(e){this._activeTransition&&!this._activeTransition.isComplete&&(this._activeTransition.update(e),this._activeTransition.hasMidpoint&&!this._activeTransition.midpointTriggered&&this._activeTransition.progress>=.5&&(this._activeTransition.midpointTriggered=!0,this._executeDirectSwitch(this._transitionFromScene,this._transitionToScene,this._pendingSwitchData)),this._activeTransition.isComplete&&this._finishTransition());let t=this.currentScene;t&&t.state===H.ACTIVE&&t.update(e)}fixedUpdate(e){let t=this.currentScene;t&&t.state===H.ACTIVE&&typeof t.fixedUpdate==`function`&&t.fixedUpdate(e)}render(e){if(this._activeTransition&&!this._activeTransition.isComplete){this._activeTransition.render(e,this._transitionFromScene,this._transitionToScene);return}if(this._stack.length===0)return;let t=this._stack.length-1;for(;t>0&&this._stack[t].renderUnderlying;)t--;for(let n=t;n<this._stack.length;n++)this._stack[n].render(e)}destroy(){for(this._activeTransition&&=null;this._stack.length>0;){let e=this._stack.pop();e.exit(),e.destroy()}for(let e of this._instances.values())e.state!==H.DESTROYED&&e.destroy();this._instances.clear(),this._registry.clear(),this.blackboard.clear(),this.events.clear()}_bindSceneMetadata(e,t){t.name=e,t.sceneManager=this,t.blackboard=this.blackboard,this.game&&(t.game=this.game)}_ensureSceneInitialized(e){e.initialized||(this._bindSceneMetadata(e.name,e),e.init(this.game))}_executeDirectSwitch(e,t,n){for(;this._stack.length>0;)this._stack.pop().exit();this._previousScene=e,this._stack.push(t),t.enter(n),t.state!==H.ACTIVE&&(t.state=H.ACTIVE),this.events.emit(`scene:change`,{from:e?e.name:null,to:t.name,data:n})}_finishTransition(){if(!this._activeTransition)return;let e=this._activeTransition,t=this._transitionFromScene,n=this._transitionToScene;if(!e.hasMidpoint&&this.currentScene!==n){for(;this._stack.length>0;){let e=this._stack.pop();e!==n&&e.exit()}this._previousScene=t,this._stack.push(n),this.events.emit(`scene:change`,{from:t?t.name:null,to:n.name,data:this._pendingSwitchData})}this._activeTransition=null,this._transitionFromScene=null,this._transitionToScene=null,this._pendingSwitchData=void 0,this.events.emit(`transition:complete`,{type:e.constructor.name,from:t?t.name:null,to:n.name})}},se=1,U=class{id;name;position;size;anchor;pivot;scale;rotation=0;visible=!0;interactive=!0;enabled=!0;zIndex=0;alpha=1;cursor=`default`;parent=null;children=[];_worldPosition=new e;_pivotWorldPosition=new e;_worldBounds=new r;_worldScale=new e(1,1);_worldAlpha=1;_isDirty=!0;onClick;onPointerDown;onPointerUp;onPointerMove;onPointerEnter;onPointerLeave;constructor(t={}){this.id=`ui_${se++}`,this.name=t.name??this.id,this.position=t.position instanceof e?t.position.clone():new e(t.position?.x??0,t.position?.y??0),this.size=t.size instanceof e?t.size.clone():new e(t.size?.x??0,t.size?.y??0),this.anchor=t.anchor instanceof e?t.anchor.clone():new e(t.anchor?.x??0,t.anchor?.y??0),this.pivot=t.pivot instanceof e?t.pivot.clone():new e(t.pivot?.x??0,t.pivot?.y??0),this.scale=t.scale instanceof e?t.scale.clone():new e(t.scale?.x??1,t.scale?.y??1),this.rotation=t.rotation??0,this.visible=t.visible??!0,this.interactive=t.interactive??!0,this.enabled=t.enabled??!0,this.zIndex=t.zIndex??0,this.alpha=t.alpha??1,this._worldAlpha=this.alpha,this.cursor=t.cursor??`default`,this.onClick=t.onClick,this.onPointerDown=t.onPointerDown,this.onPointerUp=t.onPointerUp,this.onPointerMove=t.onPointerMove,this.onPointerEnter=t.onPointerEnter,this.onPointerLeave=t.onPointerLeave}markDirty(){this._isDirty=!0;for(let e=0;e<this.children.length;e++)this.children[e].markDirty()}setAnchorAndPivot(e,t=e){return this.anchor.copy(e),this.pivot.copy(t),this.markDirty(),this}updateTransform(e){let t=0,n=0,r=this.size.x,i=this.size.y,a=1,o=1,s=1;this.parent?(this.parent._isDirty&&this.parent.updateTransform(),t=this.parent._worldBounds.x,n=this.parent._worldBounds.y,r=this.parent._worldBounds.width,i=this.parent._worldBounds.height,a=this.parent._worldScale.x,o=this.parent._worldScale.y,s=this.parent._worldAlpha):e&&(t=e.x,n=e.y,r=e.width,i=e.height);let c=t+this.anchor.x*r,l=n+this.anchor.y*i,u=c+this.position.x,d=l+this.position.y;this._pivotWorldPosition.set(u,d),this._worldScale.set(this.scale.x*a,this.scale.y*o),this._worldAlpha=Math.max(0,Math.min(1,this.alpha*s));let f=this.size.x*this._worldScale.x,p=this.size.y*this._worldScale.y,m=u-this.pivot.x*f,h=d-this.pivot.y*p;this._worldPosition.set(m,h),this._worldBounds.set(m,h,f,p),this._isDirty=!1;for(let e=0;e<this.children.length;e++)this.children[e].updateTransform(this._worldBounds)}get worldPosition(){return this._isDirty&&this.updateTransform(),this._worldPosition}get pivotWorldPosition(){return this._isDirty&&this.updateTransform(),this._pivotWorldPosition}get worldBounds(){return this._isDirty&&this.updateTransform(),this._worldBounds}get worldScale(){return this._isDirty&&this.updateTransform(),this._worldScale}get worldAlpha(){return this._isDirty&&this.updateTransform(),this._worldAlpha}addChild(e){return e.parent===this?this:(e.parent&&e.parent.removeChild(e),e.parent=this,this.children.push(e),e.markDirty(),this)}removeChild(e){let t=this.children.indexOf(e);return t!==-1&&(this.children.splice(t,1),e.parent=null,e.markDirty(),!0)}removeFromParent(){return this.parent?this.parent.removeChild(this):!1}removeAllChildren(){for(let e=0;e<this.children.length;e++)this.children[e].parent=null,this.children[e].markDirty();return this.children.length=0,this}getChildByName(e){for(let t=0;t<this.children.length;t++){if(this.children[t].name===e)return this.children[t];let n=this.children[t].getChildByName(e);if(n)return n}return null}getRoot(){let e=this;for(;e.parent;)e=e.parent;return e}containsPoint(e){if(this._isDirty&&this.updateTransform(),this.rotation===0)return this._worldBounds.contains(e.x,e.y);let t=e.x-this._pivotWorldPosition.x,n=e.y-this._pivotWorldPosition.y,r=Math.cos(-this.rotation),i=Math.sin(-this.rotation),a=(t*r-n*i)/(this._worldScale.x||1),o=(t*i+n*r)/(this._worldScale.y||1),s=-this.pivot.x*this.size.x,c=(1-this.pivot.x)*this.size.x,l=-this.pivot.y*this.size.y,u=(1-this.pivot.y)*this.size.y;return a>=s&&a<=c&&o>=l&&o<=u}hitTest(e){if(!this.visible||!this.interactive||this.worldAlpha<=0)return null;let t=this.children.slice().sort((e,t)=>t.zIndex===e.zIndex?this.children.indexOf(t)-this.children.indexOf(e):t.zIndex-e.zIndex);for(let n=0;n<t.length;n++){let r=t[n].hitTest(e);if(r)return r}return this.containsPoint(e)?this:null}update(e){this._isDirty&&this.updateTransform();for(let t=0;t<this.children.length;t++)this.children[t].update(e)}render(e){if(!this.visible||this.worldAlpha<=0)return;this._isDirty&&this.updateTransform();let t=e instanceof u?e.rawContext:e;t.save(),t.globalAlpha=this.worldAlpha,t.translate(this._pivotWorldPosition.x,this._pivotWorldPosition.y),this.rotation!==0&&t.rotate(this.rotation),(this.scale.x!==1||this.scale.y!==1)&&t.scale(this.scale.x,this.scale.y);let n=new r(-this.pivot.x*this.size.x,-this.pivot.y*this.size.y,this.size.x,this.size.y);this.draw(t,n),t.restore();let i=this.children.slice().sort((e,t)=>e.zIndex===t.zIndex?this.children.indexOf(e)-this.children.indexOf(t):e.zIndex-t.zIndex);for(let t=0;t<i.length;t++)i[t].render(e)}draw(e,t){}},ce=class extends U{text;fontFamily;fontSize;fontWeight;fontStyle;color;align;baseline;maxWidth;wordWrap;lineHeight;truncate;shadowColor;shadowBlur;shadowOffsetX;shadowOffsetY;autoSize;constructor(e={}){super(e),this.text=e.text??``,this.fontFamily=e.fontFamily??`sans-serif`,this.fontSize=e.fontSize??16,this.fontWeight=e.fontWeight??`normal`,this.fontStyle=e.fontStyle??`normal`,this.color=e.color??`#ffffff`,this.align=e.align??`left`,this.baseline=e.baseline??`top`,this.maxWidth=e.maxWidth,this.wordWrap=e.wordWrap??!1,this.lineHeight=e.lineHeight??Math.round(this.fontSize*1.25),this.truncate=e.truncate??!1,this.shadowColor=e.shadowColor,this.shadowBlur=e.shadowBlur,this.shadowOffsetX=e.shadowOffsetX,this.shadowOffsetY=e.shadowOffsetY,this.autoSize=e.autoSize??(this.size.x===0&&this.size.y===0)}getFontString(){return`${this.fontStyle} ${this.fontWeight} ${this.fontSize}px ${this.fontFamily}`.trim()}measure(e){let t=e instanceof u?e.rawContext:e,n=this.splitLines(e),r=0;if(t&&typeof t.measureText==`function`){t.font=this.getFontString();for(let e=0;e<n.length;e++){let i=t.measureText(n[e]);i.width>r&&(r=i.width)}}else for(let e=0;e<n.length;e++){let t=n[e].length*(this.fontSize*.55);t>r&&(r=t)}let i=Math.max(this.fontSize,n.length*this.lineHeight);return this.autoSize&&(this.size.set(r,i),this.markDirty()),{width:r,height:i}}splitLines(e){if(!this.text)return[``];if(!this.wordWrap||!this.maxWidth)return this.truncate&&this.maxWidth?[this._truncateLine(this.text,this.maxWidth,e)]:this.text.split(`
2
+ `);let t=e instanceof u?e.rawContext:e,n=this.text.split(`
3
+ `),r=[];for(let e=0;e<n.length;e++){let i=n[e].split(` `),a=``;for(let e=0;e<i.length;e++){let n=a?`${a} ${i[e]}`:i[e],o=0;t&&typeof t.measureText==`function`?(t.font=this.getFontString(),o=t.measureText(n).width):o=n.length*(this.fontSize*.55),o>this.maxWidth&&a?(r.push(a),a=i[e]):a=n}a&&r.push(a)}return r.length>0?r:[``]}_truncateLine(e,t,n){let r=n instanceof u?n.rawContext:n,i=0;if(r&&typeof r.measureText==`function`?(r.font=this.getFontString(),i=r.measureText(e).width):i=e.length*(this.fontSize*.55),i<=t)return e;let a=e;for(;a.length>0;){a=a.slice(0,-1);let e=`${a}...`;if((r&&typeof r.measureText==`function`?r.measureText(e).width:e.length*(this.fontSize*.55))<=t)return e}return`...`}draw(e,t){if(!this.text)return;e.font=this.getFontString(),e.textAlign=this.align,e.textBaseline=this.baseline,e.fillStyle=this.color instanceof o?this.color.toRgbaString():this.color,this.shadowColor&&(e.shadowColor=this.shadowColor instanceof o?this.shadowColor.toRgbaString():this.shadowColor,e.shadowBlur=this.shadowBlur??0,e.shadowOffsetX=this.shadowOffsetX??0,e.shadowOffsetY=this.shadowOffsetY??0);let n=this.splitLines(e),r=t.x;this.align===`center`?r=t.x+t.width*.5:this.align===`right`&&(r=t.x+t.width);let i=t.y;if(this.baseline===`middle`){let e=n.length*this.lineHeight;i=t.y+(t.height-e)*.5+this.lineHeight*.5}for(let t=0;t<n.length;t++){let a=i+t*this.lineHeight;e.fillText(n[t],r,a)}this.shadowColor&&(e.shadowColor=`transparent`,e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0)}};function W(e,t,n,r,i,a){let o=Math.max(0,Math.min(a,r/2,i/2));if(o<=0){e.rect(t,n,r,i);return}typeof e.roundRect==`function`?e.roundRect(t,n,r,i,o):(e.moveTo(t+o,n),e.lineTo(t+r-o,n),e.arcTo(t+r,n,t+r,n+o,o),e.lineTo(t+r,n+i-o),e.arcTo(t+r,n+i,t+r-o,n+i,o),e.lineTo(t+o,n+i),e.arcTo(t,n+i,t,n+i-o,o),e.lineTo(t,n+o),e.arcTo(t,n,t+o,n,o),e.closePath())}var le=class extends U{backgroundColor;borderColor;borderWidth;borderRadius;padding;clipChildren;constructor(e={}){super(e),this.backgroundColor=e.backgroundColor??`#1e1e2e`,this.borderColor=e.borderColor??null,this.borderWidth=e.borderWidth??0,this.borderRadius=e.borderRadius??0,this.clipChildren=e.clipChildren??!1,this.padding=typeof e.padding==`number`?{top:e.padding,right:e.padding,bottom:e.padding,left:e.padding}:e.padding?{...e.padding}:{top:0,right:0,bottom:0,left:0}}getInnerBounds(){let e=this.worldBounds;return new r(e.x+this.padding.left,e.y+this.padding.top,Math.max(0,e.width-this.padding.left-this.padding.right),Math.max(0,e.height-this.padding.top-this.padding.bottom))}hitTest(e){return this.clipChildren&&!this.containsPoint(e)?null:super.hitTest(e)}draw(e,t){let{x:n,y:r,width:i,height:a}=t;i<=0||a<=0||(e.beginPath(),W(e,n,r,i,a,this.borderRadius),this.backgroundColor&&(e.fillStyle=this.backgroundColor instanceof o?this.backgroundColor.toRgbaString():this.backgroundColor,e.fill()),this.borderColor&&this.borderWidth>0&&(e.strokeStyle=this.borderColor instanceof o?this.borderColor.toRgbaString():this.borderColor,e.lineWidth=this.borderWidth,e.stroke()))}render(e){if(!this.visible||this.worldAlpha<=0)return;this._isDirty&&this.updateTransform();let t=e instanceof u?e.rawContext:e;this.clipChildren?(t.save(),t.beginPath(),W(t,this._worldBounds.x,this._worldBounds.y,this._worldBounds.width,this._worldBounds.height,this.borderRadius),t.clip(),super.render(e),t.restore()):super.render(e)}},ue={TopLeft:Object.freeze(new e(0,0)),TopCenter:Object.freeze(new e(.5,0)),TopRight:Object.freeze(new e(1,0)),CenterLeft:Object.freeze(new e(0,.5)),Center:Object.freeze(new e(.5,.5)),CenterRight:Object.freeze(new e(1,.5)),BottomLeft:Object.freeze(new e(0,1)),BottomCenter:Object.freeze(new e(.5,1)),BottomRight:Object.freeze(new e(1,1))},de={TopLeft:Object.freeze(new e(0,0)),TopCenter:Object.freeze(new e(.5,0)),TopRight:Object.freeze(new e(1,0)),CenterLeft:Object.freeze(new e(0,.5)),Center:Object.freeze(new e(.5,.5)),CenterRight:Object.freeze(new e(1,.5)),BottomLeft:Object.freeze(new e(0,1)),BottomCenter:Object.freeze(new e(.5,1)),BottomRight:Object.freeze(new e(1,1))},fe=function(e){return e.Normal=`normal`,e.Hover=`hover`,e.Pressed=`pressed`,e.Disabled=`disabled`,e}({}),G=class extends U{state=`normal`;borderRadius;label=null;stateStyles;onHover;_isHovered=!1;_isPressed=!1;constructor(e={}){super({size:e.size??{x:140,y:44},cursor:`pointer`,...e}),this.borderRadius=e.borderRadius??6,this.onHover=e.onHover,this.stateStyles={normal:{backgroundColor:`#3b82f6`,borderColor:`#2563eb`,borderWidth:1,textColor:`#ffffff`,...e.stateStyles?.normal},hover:{backgroundColor:`#60a5fa`,borderColor:`#3b82f6`,borderWidth:1,textColor:`#ffffff`,...e.stateStyles?.hover},pressed:{backgroundColor:`#1d4ed8`,borderColor:`#1e40af`,borderWidth:2,textColor:`#e2e8f0`,...e.stateStyles?.pressed},disabled:{backgroundColor:`#475569`,borderColor:`#334155`,borderWidth:1,textColor:`#94a3b8`,...e.stateStyles?.disabled}},e.text!==void 0&&(this.label=new ce({text:e.text,fontSize:e.fontSize??16,fontFamily:e.fontFamily??`sans-serif`,color:e.textColor??this.stateStyles.normal.textColor??`#ffffff`,align:`center`,baseline:`middle`,anchor:ue.Center,pivot:de.Center,interactive:!1}),this.addChild(this.label)),this.enabled||(this.state=`disabled`)}set disabled(e){this.enabled=!e,e?(this.state=`disabled`,this._isHovered=!1,this._isPressed=!1):this.state=this._isHovered?`hover`:`normal`,this._syncLabelColor()}get disabled(){return!this.enabled||this.state===`disabled`}handlePointerEnter(e){this.disabled||(this._isHovered=!0,this._isPressed||(this.state=`hover`,this._syncLabelColor()),this.onHover?.(this,!0),this.onPointerEnter?.(e))}handlePointerLeave(e){this.disabled||(this._isHovered=!1,this._isPressed=!1,this.state=`normal`,this._syncLabelColor(),this.onHover?.(this,!1),this.onPointerLeave?.(e))}handlePointerDown(e){this.disabled||(this._isPressed=!0,this.state=`pressed`,this._syncLabelColor(),this.onPointerDown?.(e))}handlePointerUp(e){if(this.disabled)return;let t=this._isPressed;this._isPressed=!1,this._isHovered?(this.state=`hover`,this._syncLabelColor(),this.onPointerUp?.(e),t&&this.onClick?.(e)):(this.state=`normal`,this._syncLabelColor(),this.onPointerUp?.(e))}_syncLabelColor(){if(!this.label)return;let e=this.stateStyles[this.state];e?.textColor&&(this.label.color=e.textColor)}draw(e,t){let{x:n,y:r,width:i,height:a}=t,s=this.stateStyles[this.state]||this.stateStyles.normal;e.beginPath(),W(e,n,r,i,a,this.borderRadius),s.backgroundColor&&(e.fillStyle=s.backgroundColor instanceof o?s.backgroundColor.toRgbaString():s.backgroundColor,e.fill()),s.borderColor&&(s.borderWidth??0)>0&&(e.strokeStyle=s.borderColor instanceof o?s.borderColor.toRgbaString():s.borderColor,e.lineWidth=s.borderWidth??1,e.stroke())}},pe=class{root;viewportWidth;viewportHeight;absorbInput;hoveredElement=null;pressedElement=null;focusedElement=null;constructor(e=800,t=600){typeof e==`number`?(this.viewportWidth=e,this.viewportHeight=t,this.absorbInput=!0):(this.viewportWidth=e.width??800,this.viewportHeight=e.height??600,this.absorbInput=e.absorbInput??!0),this.root=new U({name:`root`,size:{x:this.viewportWidth,y:this.viewportHeight},interactive:!0}),this.root.updateTransform(new r(0,0,this.viewportWidth,this.viewportHeight))}resize(e,t){this.viewportWidth=e,this.viewportHeight=t,this.root.size.set(e,t),this.root.markDirty(),this.root.updateTransform(new r(0,0,e,t))}add(e){return this.root.addChild(e),this}remove(e){return this.root.removeChild(e)}clear(){this.root.removeAllChildren(),this.hoveredElement=null,this.pressedElement=null,this.focusedElement=null}findElement(e){return this.root.getChildByName(e)}hitTest(e){if(!this.root.visible||this.root.worldAlpha<=0)return null;let t=this.root.children.slice().sort((e,t)=>t.zIndex===e.zIndex?this.root.children.indexOf(t)-this.root.children.indexOf(e):t.zIndex-e.zIndex);for(let n=0;n<t.length;n++){let r=t[n].hitTest(e);if(r)return r}return null}processInput(e){let t=e.pointer,n=t.canvasPosition,r=this.hitTest(n),i=!1;if(r!==this.hoveredElement){if(this.hoveredElement){let e=this._createPointerEvent(this.hoveredElement,n,0,t.pointerType);this.hoveredElement instanceof G?this.hoveredElement.handlePointerLeave(e):this.hoveredElement.onPointerLeave?.(e)}if(this.hoveredElement=r,this.hoveredElement){let e=this._createPointerEvent(this.hoveredElement,n,0,t.pointerType);this.hoveredElement instanceof G?this.hoveredElement.handlePointerEnter(e):this.hoveredElement.onPointerEnter?.(e)}}else if(this.hoveredElement){let e=this._createPointerEvent(this.hoveredElement,n,0,t.pointerType);this.hoveredElement.onPointerMove?.(e)}if(t.isJustPressed(v.Primary)&&r){this.pressedElement=r,this.focusedElement=r;let e=this._createPointerEvent(r,n,v.Primary,t.pointerType);r instanceof G?r.handlePointerDown(e):r.onPointerDown?.(e),this.absorbInput&&(t.consume(),i=!0)}if(t.isJustReleased(v.Primary)&&this.pressedElement){let e=this._createPointerEvent(this.pressedElement,n,v.Primary,t.pointerType);this.pressedElement instanceof G?this.pressedElement.handlePointerUp(e):(this.pressedElement.onPointerUp?.(e),this.pressedElement===r&&this.pressedElement.onClick?.(e)),this.pressedElement=null,this.absorbInput&&(t.consume(),i=!0)}return t.isDown(v.Primary)&&this.pressedElement&&this.absorbInput&&(t.consume(),i=!0),i||r!==null&&this.absorbInput&&(t.isDown(v.Primary)||t.isJustPressed(v.Primary)||t.isJustReleased(v.Primary))}_createPointerEvent(e,t,n,r){let i=!1;return{target:e,canvasPosition:t.clone(),button:n,pointerType:r,get consumed(){return i},set consumed(e){i=e},stopPropagation:()=>{i=!0}}}update(e){this.root.update(e)}render(e){this.root.render(e)}},me=1,he=class extends s{id;name;active=!0;tag=`default`;layer=h.ENTITIES;zIndex=0;transform;parent=null;children=[];entityManager=null;_components=[];_hasStarted=!1;_isDestroyed=!1;constructor(e){super(),this.id=me++,this.name=e??`Entity_${this.id}`,this.transform=new n}get isDestroyed(){return this._isDestroyed}get activeInHierarchy(){let e=this;for(;e!==null;){if(!e.active)return!1;e=e.parent}return!0}addChild(e){if(e===this||e.parent===this)return this;let t=this.parent;for(;t!==null;){if(t===e)return this;t=t.parent}return e.parent!==null&&e.parent.removeChild(e),e.parent=this,this.children.push(e),this.transform.addChild(e.transform),this.entityManager&&!e.entityManager&&this.entityManager.add(e),this}removeChild(e){let t=this.children.indexOf(e);return t!==-1&&(this.children.splice(t,1),e.parent=null,this.transform.removeChild(e.transform)),this}setParent(e){return e===this||this.parent===e?this:e===null?(this.parent!==null&&this.parent.removeChild(this),this):(e.addChild(this),this)}addComponent(e){if(e.entity&&e.entity!==this)throw Error(`Component is already attached to another Entity (${e.entity.name})`);return e.entity=this,this._components.push(e),e.onAttach(),this._hasStarted&&!e._hasStarted&&(e._hasStarted=!0,e.onStart()),this.entityManager&&this.entityManager._onComponentAdded(this,e),this.emit(`component:add`,{entity:this,component:e}),e}getComponent(e){for(let t=0;t<this._components.length;t++)if(this._components[t]instanceof e)return this._components[t];return null}getComponents(e){let t=[];for(let n=0;n<this._components.length;n++)this._components[n]instanceof e&&t.push(this._components[n]);return t}hasComponent(e){return this.getComponent(e)!==null}removeComponent(e){let t=null,n=-1;if(typeof e==`function`){for(let r=0;r<this._components.length;r++)if(this._components[r]instanceof e){t=this._components[r],n=r;break}}else n=this._components.indexOf(e),n!==-1&&(t=e);return!t||n===-1?!1:(this._components.splice(n,1),t._isDestroyed=!0,t.onDetach(),t.onDestroy(),this.entityManager&&this.entityManager._onComponentRemoved(this,t),this.emit(`component:remove`,{entity:this,component:t}),!0)}onCollisionEnter(e,t){for(let n=0;n<this._components.length;n++){let r=this._components[n];r.enabled&&typeof r.onCollisionEnter==`function`&&r.onCollisionEnter(e,t)}}onCollisionStay(e,t){for(let n=0;n<this._components.length;n++){let r=this._components[n];r.enabled&&typeof r.onCollisionStay==`function`&&r.onCollisionStay(e,t)}}onCollisionExit(e){for(let t=0;t<this._components.length;t++){let n=this._components[t];n.enabled&&typeof n.onCollisionExit==`function`&&n.onCollisionExit(e)}}onTriggerEnter(e){for(let t=0;t<this._components.length;t++){let n=this._components[t];n.enabled&&typeof n.onTriggerEnter==`function`&&n.onTriggerEnter(e)}}onTriggerStay(e){for(let t=0;t<this._components.length;t++){let n=this._components[t];n.enabled&&typeof n.onTriggerStay==`function`&&n.onTriggerStay(e)}}onTriggerExit(e){for(let t=0;t<this._components.length;t++){let n=this._components[t];n.enabled&&typeof n.onTriggerExit==`function`&&n.onTriggerExit(e)}}start(){if(this._hasStarted)return;this._hasStarted=!0;let e=this._components.slice();for(let t=0;t<e.length;t++){let n=e[t];n.enabled&&!n._hasStarted&&!n._isDestroyed&&(n._hasStarted=!0,n.onStart())}let t=this.children.slice();for(let e=0;e<t.length;e++){let n=t[e];n.active&&!n._isDestroyed&&n.start()}}update(e){if(!this.activeInHierarchy||this._isDestroyed)return;this._hasStarted||this.start();let t=this._components.slice();for(let n=0;n<t.length;n++){let r=t[n];r.enabled&&!r._isDestroyed&&r.onUpdate(e)}let n=this.children.slice();for(let t=0;t<n.length;t++){let r=n[t];r.active&&!r._isDestroyed&&r.update(e)}}fixedUpdate(e){if(!this.activeInHierarchy||this._isDestroyed)return;let t=this._components.slice();for(let n=0;n<t.length;n++){let r=t[n];r.enabled&&!r._isDestroyed&&r.onFixedUpdate(e)}let n=this.children.slice();for(let t=0;t<n.length;t++){let r=n[t];r.active&&!r._isDestroyed&&r.fixedUpdate(e)}}render(e){if(!this.activeInHierarchy||this._isDestroyed)return;let t=this._components.slice();for(let n=0;n<t.length;n++){let r=t[n];r.enabled&&!r._isDestroyed&&r.onRender(e)}let n=this.children.slice();for(let t=0;t<n.length;t++){let r=n[t];r.active&&!r._isDestroyed&&r.render(e)}}destroy(){if(!this._isDestroyed){this._isDestroyed=!0;for(let e=this.children.length-1;e>=0;e--)this.children[e].destroy();for(let e=this._components.length-1;e>=0;e--){let t=this._components[e];t._isDestroyed=!0,t.onDetach(),t.onDestroy()}this._components.length=0,this.parent!==null&&this.parent.removeChild(this),this.entityManager!==null&&this.entityManager.markForDestruction(this),this.emit(`destroy`,{entity:this}),this.clear()}}},K=class{entity;enabled=!0;_hasStarted=!1;_isDestroyed=!1;get transform(){return this.entity.transform}get name(){return this.entity.name}get tag(){return this.entity.tag}get layer(){return this.entity.layer}getComponent(e){return this.entity.getComponent(e)}getComponents(e){return this.entity.getComponents(e)}hasComponent(e){return this.entity.hasComponent(e)}destroy(){this.entity&&!this._isDestroyed&&this.entity.removeComponent(this)}onAttach(){}onDetach(){}onStart(){}onUpdate(e){}onFixedUpdate(e){}onRender(e){}onDestroy(){}},q=class extends K{collider;constructor(e){super(),this.collider=e}get isTrigger(){return this.collider.isTrigger}set isTrigger(e){this.collider.isTrigger=e}get offset(){return this.collider.offset}set offset(e){this.collider.offset.copy(e),this.collider.updateWorldBounds()}get layer(){return this.collider.layer}set layer(e){this.collider.layer=e}get mask(){return this.collider.mask}set mask(e){this.collider.mask=e}get friction(){return this.collider.friction}set friction(e){this.collider.friction=e}get restitution(){return this.collider.restitution}set restitution(e){this.collider.restitution=e}onAttach(){this.collider.userData=this.entity;let e=this.entity.getComponent(J);e?this.collider.body=e.body:(this.collider.offset.copy(this.entity.transform.position),this.collider.updateWorldBounds()),this.collider.onCollisionEnter=(e,t)=>this.entity.onCollisionEnter(e,t),this.collider.onCollisionStay=(e,t)=>this.entity.onCollisionStay(e,t),this.collider.onCollisionExit=e=>this.entity.onCollisionExit(e),this.collider.onTriggerEnter=e=>this.entity.onTriggerEnter(e),this.collider.onTriggerStay=e=>this.entity.onTriggerStay(e),this.collider.onTriggerExit=e=>this.entity.onTriggerExit(e),this.entity.entityManager?.physicsWorld&&this.entity.entityManager.physicsWorld.addCollider(this.collider)}onFixedUpdate(e){this.collider.body||(this.collider.offset.copy(this.entity.transform.position),this.collider.updateWorldBounds())}onDetach(){this.entity.entityManager?.physicsWorld&&this.entity.entityManager.physicsWorld.removeCollider(this.collider),this.collider.body=null,this.collider.userData=null}onDestroy(){this.onDetach()}},ge=class extends q{constructor(e,t){super(new R({radius:e,...t}))}get radius(){return this.collider.radius}set radius(e){this.collider.radius=e,this.collider.updateWorldBounds()}},_e=class extends q{constructor(e,t,n){super(new z({width:e,height:t,...n}))}get width(){return this.collider.size.x}set width(e){this.collider.size.x=e,this.collider.halfExtents.x=e/2,this.collider.updateWorldBounds()}get height(){return this.collider.size.y}set height(e){this.collider.size.y=e,this.collider.halfExtents.y=e/2,this.collider.updateWorldBounds()}},J=class extends K{body;constructor(e){super(),this.body=e instanceof E?e:new E(e)}get bodyType(){return this.body.bodyType}set bodyType(e){this.body.bodyType=e}get velocity(){return this.body.velocity}get angularVelocity(){return this.body.angularVelocity}set angularVelocity(e){this.body.angularVelocity=e}get mass(){return this.body.mass}set mass(e){this.body.setMass(e)}get gravityScale(){return this.body.gravityScale}set gravityScale(e){this.body.gravityScale=e}get restitution(){return this.body.restitution}set restitution(e){this.body.restitution=e}get friction(){return this.body.friction}set friction(e){this.body.friction=e}get fixedRotation(){return this.body.fixedRotation}set fixedRotation(e){this.body.fixedRotation=e}get isSleeping(){return this.body.isSleeping}applyForce(e,t){this.body.applyForce(e,t)}applyImpulse(e,t){this.body.applyImpulse(e,t)}applyTorque(e){this.body.applyTorque(e)}applyAngularImpulse(e){this.body.applyAngularImpulse(e)}setVelocity(e,t){this.body.velocity.set(e,t),this.body.wakeUp()}wakeUp(){this.body.wakeUp()}sleep(){this.body.sleep()}onAttach(){this.body.transform=this.entity.transform,this.body.userData=this.entity,this.body.position.copy(this.entity.transform.position),this.body.rotation=this.entity.transform.rotation;let e=this.entity.getComponents(q);for(let t=0;t<e.length;t++)e[t].collider.body=this.body;this.entity.entityManager?.physicsWorld&&this.entity.entityManager.physicsWorld.addBody(this.body)}onDetach(){this.entity.entityManager?.physicsWorld&&this.entity.entityManager.physicsWorld.removeBody(this.body),this.body.transform=null,this.body.userData=null}onFixedUpdate(e){let t=this.entity.transform,n=this.body,r=n.position.x!==t.position.x||n.position.y!==t.position.y,i=n.rotation!==t.rotation;(t.isDirty||r||i)&&n.syncFromTransform()}onDestroy(){this.onDetach()}},ve=class{physicsWorld=null;camera=null;_entities=[];_entitiesById=new Map;_entitiesByName=new Map;_entitiesByTag=new Map;_entitiesByLayer=new Map;_pendingAdd=[];_pendingDestroy=new Set;_isIterating=!1;constructor(e=null){this.physicsWorld=e}get count(){return this._entities.length}createEntity(e){let t=new he(e);return this.add(t)}add(e){return this._entitiesById.has(e.id)?e:(e.entityManager=this,this._isIterating?this._pendingAdd.push(e):this._registerEntity(e),e)}_registerEntity(e){if(this._entitiesById.has(e.id))return;this._entities.push(e),this._entitiesById.set(e.id,e),this._entitiesByName.set(e.name,e);let t=this._entitiesByTag.get(e.tag);t||(t=new Set,this._entitiesByTag.set(e.tag,t)),t.add(e);let n=this._entitiesByLayer.get(e.layer);if(n||(n=new Set,this._entitiesByLayer.set(e.layer,n)),n.add(e),this.physicsWorld){let t=e.getComponent(J);t&&this.physicsWorld.addBody(t.body);let n=e.getComponents(q);for(let e=0;e<n.length;e++)this.physicsWorld.addCollider(n[e].collider)}for(let t=0;t<e.children.length;t++)this.add(e.children[t])}remove(e){if(this._isIterating){let t=this._pendingAdd.indexOf(e);return t===-1?this._entitiesById.has(e.id)?(this.markForDestruction(e),!0):!1:(this._pendingAdd.splice(t,1),e.entityManager=null,!0)}let t=this._pendingAdd.indexOf(e);return t===-1?this._entitiesById.has(e.id)?(this._unregisterEntity(e),!0):!1:(this._pendingAdd.splice(t,1),e.entityManager=null,!0)}_unregisterEntity(e){let t=this._entities.indexOf(e);t!==-1&&this._entities.splice(t,1),this._entitiesById.delete(e.id),this._entitiesByName.delete(e.name);let n=this._entitiesByTag.get(e.tag);n&&(n.delete(e),n.size===0&&this._entitiesByTag.delete(e.tag));let r=this._entitiesByLayer.get(e.layer);if(r&&(r.delete(e),r.size===0&&this._entitiesByLayer.delete(e.layer)),this.physicsWorld){let t=e.getComponent(J);t&&this.physicsWorld.removeBody(t.body);let n=e.getComponents(q);for(let e=0;e<n.length;e++)this.physicsWorld.removeCollider(n[e].collider)}e.entityManager=null}clear(){for(let e=this._entities.length-1;e>=0;e--)this._entities[e].destroy();this._entities.length=0,this._entitiesById.clear(),this._entitiesByName.clear(),this._entitiesByTag.clear(),this._entitiesByLayer.clear(),this._pendingAdd.length=0,this._pendingDestroy.clear()}getById(e){return this._entitiesById.get(e)}getByName(e){return this._entitiesByName.get(e)}getByTag(e){let t=[];for(let n=0;n<this._entities.length;n++)this._entities[n].tag===e&&t.push(this._entities[n]);return t}getByLayer(e){let t=[];for(let n=0;n<this._entities.length;n++)this._entities[n].layer===e&&t.push(this._entities[n]);return t}queryByComponent(e){let t=[];for(let n=0;n<this._entities.length;n++){let r=this._entities[n];r.active&&r.hasComponent(e)&&t.push(r)}return t}queryByComponents(e){let t=[];for(let n=0;n<this._entities.length;n++){let r=this._entities[n];if(!r.active)continue;let i=!0;for(let t=0;t<e.length;t++)if(!r.hasComponent(e[t])){i=!1;break}i&&t.push(r)}return t}get rootEntities(){return this._entities.filter(e=>e.parent===null||!this._entitiesById.has(e.parent.id))}_onComponentAdded(e,t){this.physicsWorld&&(t instanceof J?this.physicsWorld.addBody(t.body):t instanceof q&&this.physicsWorld.addCollider(t.collider))}_onComponentRemoved(e,t){this.physicsWorld&&(t instanceof J?this.physicsWorld.removeBody(t.body):t instanceof q&&this.physicsWorld.removeCollider(t.collider))}markForDestruction(e){this._pendingDestroy.add(e)}_flushPendingAdd(){if(this._pendingAdd.length===0)return;let e=this._pendingAdd.slice();this._pendingAdd.length=0;for(let t=0;t<e.length;t++)this._registerEntity(e[t])}_flushPendingDestroy(){if(this._pendingDestroy.size!==0){for(let e of this._pendingDestroy)this._unregisterEntity(e);this._pendingDestroy.clear()}}start(){this._flushPendingAdd();let e=this.rootEntities;for(let t=0;t<e.length;t++)e[t].active&&e[t].start()}update(e){this._flushPendingAdd(),this._isIterating=!0;try{let t=this.rootEntities;for(let n=0;n<t.length;n++){let r=t[n];r.active&&!r.isDestroyed&&r.update(e)}}finally{this._isIterating=!1}this._flushPendingAdd(),this._flushPendingDestroy()}fixedUpdate(e){this._flushPendingAdd(),this._isIterating=!0;try{let t=this.rootEntities;for(let n=0;n<t.length;n++){let r=t[n];r.active&&!r.isDestroyed&&r.fixedUpdate(e)}}finally{this._isIterating=!1}this._flushPendingAdd(),this._flushPendingDestroy()}render(e){let t=this.rootEntities;for(let n=0;n<t.length;n++){let r=t[n];r.active&&!r.isDestroyed&&r.render(e)}}},ye=class extends s{config;renderer;canvas;ctx;camera;input;physics;audio;scenes;ui;loop;entities;get sound(){return this.audio}get blackboard(){return this.scenes.blackboard}width;height;applyCamera;_isInitialized=!1;_initialSceneName=null;_boundResizeListener=null;_scratchPointerWorld=new e;constructor(e={}){super(),this.config=Object.freeze({...e}),this.width=e.width??800,this.height=e.height??600,this.applyCamera=e.applyCamera??!0,this._initialSceneName=e.initialScene??e.startScene??null,this.renderer=new g({canvas:e.canvas,width:this.width,height:this.height,scaleMode:e.scaleMode??`letterbox`,pixelArt:e.pixelArt??!1,backgroundColor:e.backgroundColor??`#11111b`,highDPI:e.highDPI??!0,maxPixelRatio:e.maxPixelRatio??2,dpr:e.dpr}),this.canvas=this.renderer.canvas,this.ctx=this.renderer.ctx,this.camera=new _({viewportWidth:this.renderer.virtualWidth,viewportHeight:this.renderer.virtualHeight,originX:e.camera?.originX??.5,originY:e.camera?.originY??.5,...e.camera}),this.input=new w({target:this.canvas,...e.input});let t={update:e=>this._onUpdate(e),fixedUpdate:e=>this._onFixedUpdate(e),render:e=>this._onRender(e)},n=e.fixedDeltaTime??e.fixedTimestep??(e.targetFps?1/e.targetFps:1/60);this.loop=new l(t,{fixedDeltaTime:n,maxFrameDelta:e.maxFrameDelta??.25,maxSubSteps:e.maxSubSteps??15,autoPauseOnHide:e.autoPauseOnHide??!0,renderWhenPaused:e.renderWhenPaused??!1});let r={fixedDeltaTime:this.loop.fixedDeltaTime,...e.physics};if(e.gravity&&!r.gravity&&(r.gravity=e.gravity),this.physics=new te(r),this.audio=new V,this.scenes=new oe(this),e.scenes){if(Array.isArray(e.scenes))for(let t of e.scenes)this.scenes.add(t.name,t.scene);else for(let[t,n]of Object.entries(e.scenes))this.scenes.add(t,n)}this.ui=new pe({width:this.renderer.virtualWidth,height:this.renderer.virtualHeight,absorbInput:e.ui?.absorbInput??!0}),this.entities=new ve(this.physics),this.entities.camera=this.camera,this._initResizeListener()}isRunning(){return this.loop.isRunning()}isPaused(){return this.loop.isPaused()}get isInitialized(){return this._isInitialized}get currentScene(){return this.scenes.currentScene}get deltaTime(){return c.deltaTime}get rawDeltaTime(){return c.rawDeltaTime}get fixedDeltaTime(){return this.loop.fixedDeltaTime}get time(){return c.time}get fps(){return c.fps}get exactFps(){return c.exactFps}get frameCount(){return c.frameCount}get timeScale(){return c.timeScale}set timeScale(e){c.setTimeScale(e)}async init(){return this._isInitialized?this:(this.config.init&&await this.config.init(this),this._initialSceneName&&!this.scenes.currentScene&&await this.scenes.switchTo(this._initialSceneName),this._isInitialized=!0,this.emit(`init`,{game:this}),this)}start(){return this.isRunning()?this:(this._isInitialized||(this.config.init&&this.config.init(this),this._initialSceneName&&!this.scenes.currentScene&&this.scenes.switchTo(this._initialSceneName),this._isInitialized=!0,this.emit(`init`,{game:this})),this.loop.start(),this.emit(`start`,{game:this}),this)}pause(){return!this.isRunning()||this.isPaused()?this:(this.loop.pause(),this.emit(`pause`,{game:this}),this)}resume(){return!this.isRunning()||!this.isPaused()?this:(this.loop.resume(),this.emit(`resume`,{game:this}),this)}stop(){return this.isRunning()?(this.loop.stop(),this.emit(`stop`,{game:this}),this):this}step(e){this._isInitialized||(this._initialSceneName&&!this.scenes.currentScene&&this.scenes.switchTo(this._initialSceneName),this._isInitialized=!0,this.emit(`init`,{game:this})),this.loop.step(e)}destroy(){this.stop(),this.loop.destroy(),this.scenes.destroy(),this.input.detach(),this.audio.destroy(),this.ui.clear(),this.physics.clear(),this.entities.clear(),this._boundResizeListener&&typeof window<`u`&&(window.removeEventListener(`resize`,this._boundResizeListener),this._boundResizeListener=null),this.emit(`destroy`,{game:this}),this.clear()}_onUpdate(e){this.input.update(),this.ui.processInput(this.input);let t=this.scenes.currentScene?.camera??this.camera;t&&t.update(e),this.scenes.update(e),this.entities.update(e),this.ui.update(e),this.config.update&&this.config.update(e,this),this.emit(`update`,{deltaTime:e,game:this})}_onFixedUpdate(e){this.physics.step(e),this.scenes.fixedUpdate(e),this.entities.fixedUpdate(e),this.config.fixedUpdate&&this.config.fixedUpdate(e,this),this.emit(`fixedUpdate`,{fixedDeltaTime:e,game:this})}_onRender(e){this.renderer.beginFrame();let t=this.scenes.currentScene?.camera??this.camera;this.entities.camera=t,this.applyCamera&&t&&(this.ctx.save(),t.applyToContext(this.ctx)),this.scenes.render(this.ctx),this.applyCamera&&t&&this.ctx.restore(),this.entities.render(this.renderer),this.renderer.flushQueue(),this.config.render&&this.config.render(this.ctx,this),this.ui.render(this.ctx),this.renderer.endFrame(),this.input.lateUpdate(),this.emit(`render`,{alpha:e,ctx:this.ctx,game:this})}getPointerWorld(e){let t=e??this._scratchPointerWorld;return(this.scenes.currentScene?.camera??this.camera).screenToWorld(this.input.pointer.canvasPosition,t)}screenToWorld(e,t){return(this.scenes.currentScene?.camera??this.camera).screenToWorld(e,t)}worldToScreen(e,t){return(this.scenes.currentScene?.camera??this.camera).worldToScreen(e,t)}addScene(e,t){return this.scenes.add(e,t),this}switchToScene(e,t,n){this.scenes.switchTo(e,t,n)}resize(e,t){this.renderer.resize(e,t),this.camera.viewportWidth=this.renderer.virtualWidth,this.camera.viewportHeight=this.renderer.virtualHeight,this.ui.resize(this.renderer.virtualWidth,this.renderer.virtualHeight),this.emit(`resize`,{width:e??this.renderer.virtualWidth,height:t??this.renderer.virtualHeight,game:this})}_initResizeListener(){typeof window>`u`||(this._boundResizeListener=()=>{this.resize(window.innerWidth,window.innerHeight)},window.addEventListener(`resize`,this._boundResizeListener))}};function be(e={}){let t=new ye(e);return e.autoStart&&t.start(),t}var xe=class{static _cache=new Map;static getTintedTexture(e,t,n){if(typeof document>`u`)return null;let r=`${e.src??`canvas`}_${t.x}_${t.y}_${t.width}_${t.height}_${n.toHexString(!0)}`,i=this._cache.get(r);if(i)return i;let a=document.createElement(`canvas`);a.width=t.width,a.height=t.height;let o=a.getContext(`2d`);return o?(o.drawImage(e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),o.globalCompositeOperation=`source-atop`,o.fillStyle=n.toRgbaString(),o.fillRect(0,0,t.width,t.height),this._cache.set(r,a),a):null}static clear(){this._cache.clear()}},Y=class{texture;sourceRect;width;height;anchor;tint=null;flipX=!1;flipY=!1;opacity=1;_cachedBounds=new r;constructor(t){this.texture=t.texture;let n=t.texture?.width||32,i=t.texture?.height||32;this.sourceRect=t.sourceRect?t.sourceRect instanceof r?t.sourceRect.clone():new r(t.sourceRect.x,t.sourceRect.y,t.sourceRect.width,t.sourceRect.height):new r(0,0,n,i),this.width=t.width??this.sourceRect.width,this.height=t.height??this.sourceRect.height,this.anchor=t.anchor instanceof e?t.anchor.clone():new e(t.anchor?.x??.5,t.anchor?.y??.5),t.tint&&(this.tint=t.tint instanceof o?t.tint.clone():o.parse(t.tint)),this.flipX=t.flipX??!1,this.flipY=t.flipY??!1,this.opacity=Math.max(0,Math.min(1,t.opacity??1))}setSourceRect(e,t,n,r){return this.sourceRect.set(e,t,n,r),this}setAnchor(e,t){return this.anchor.set(e,t),this}setDimensions(e,t){return this.width=e,this.height=t,this}setFlip(e,t){return this.flipX=e,this.flipY=t,this}setTint(e){return this.tint=e?e instanceof o?e.clone():o.parse(e):null,this}getBounds(e){let t=e??this._cachedBounds;return t.set(-this.width*this.anchor.x,-this.height*this.anchor.y,this.width,this.height),t}_getRawContext(e){return e instanceof u?e.rawContext:e}draw(e,t,n,r=0,i=1,a=1){let o=this._getRawContext(e);o.save(),o.translate(t,n),r!==0&&o.rotate(r);let s=i*(this.flipX?-1:1),c=a*(this.flipY?-1:1);(s!==1||c!==1)&&o.scale(s,c),this.opacity<1&&(o.globalAlpha*=this.opacity);let l=-this.width*this.anchor.x,u=-this.height*this.anchor.y;if(this.tint){let e=xe.getTintedTexture(this.texture,this.sourceRect,this.tint);if(e){o.drawImage(e,0,0,this.sourceRect.width,this.sourceRect.height,l,u,this.width,this.height),o.restore();return}}o.drawImage(this.texture,this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height,l,u,this.width,this.height),o.restore()}drawTransform(e,t){let n=this._getRawContext(e);n.save(),t.updateWorldMatrix().transformContext(n),(this.flipX||this.flipY)&&n.scale(this.flipX?-1:1,this.flipY?-1:1),this.opacity<1&&(n.globalAlpha*=this.opacity);let r=-this.width*this.anchor.x,i=-this.height*this.anchor.y;if(this.tint){let e=xe.getTintedTexture(this.texture,this.sourceRect,this.tint);if(e){n.drawImage(e,0,0,this.sourceRect.width,this.sourceRect.height,r,i,this.width,this.height),n.restore();return}}n.drawImage(this.texture,this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height,r,i,this.width,this.height),n.restore()}},Se=class{name;frames;fps;wrapMode;totalDuration;constructor(e){this.name=e.name,this.fps=e.fps??12,this.wrapMode=e.wrapMode??`loop`,this.frames=e.frames;let t=0;for(let e=0;e<this.frames.length;e++)t+=this.frames[e].duration;this.totalDuration=t>0?t:this.frames.length/this.fps}},Ce=class{_clips=new Map;currentClip=null;currentFrameIndex=0;currentTime=0;playbackSpeed=1;isPlaying=!1;isPaused=!1;isFinished=!1;_direction=1;targetSprite=null;onFrame;onComplete;onLoop;constructor(e){e&&(this.targetSprite=e)}addClip(e){return this._clips.set(e.name,e),this}getClip(e){return this._clips.get(e)}hasClip(e){return this._clips.has(e)}play(e,t=!1){let n=this._clips.get(e);if(!n)return console.warn(`[Animation] Clip "${e}" not found`),this;if(this.currentClip===n&&this.isPlaying&&!t)return this;let r=this.currentClip!==n;return this.currentClip=n,this.isPlaying=!0,this.isPaused=!1,this.isFinished=!1,this._direction=n.wrapMode===`reverse`?-1:1,(t||r)&&(this.currentTime=0,this.currentFrameIndex=this._direction===1?0:n.frames.length-1,this._applyFrame()),this}pause(){return this.isPaused=!0,this}resume(){return this.currentClip&&!this.isFinished&&(this.isPaused=!1,this.isPlaying=!0),this}stop(){return this.isPlaying=!1,this.isPaused=!1,this.currentTime=0,this.currentFrameIndex=0,this}gotoAndStop(e){return this.currentClip?(this.currentFrameIndex=Math.max(0,Math.min(this.currentClip.frames.length-1,e)),this.isPlaying=!1,this._applyFrame(),this):this}gotoAndPlay(e){return this.gotoAndStop(e),this.isPlaying=!0,this}update(e){if(!this.isPlaying||this.isPaused||!this.currentClip||this.isFinished)return;let t=(e===void 0?c.deltaTime:e)*this.playbackSpeed;if(t<=0)return;this.currentTime+=t;let n=this.currentClip,r=n.frames;if(r.length===0)return;let i=r[this.currentFrameIndex],a=0,o=r.length*2;for(;this.currentTime>=Math.max(1e-4,i.duration)&&this.isPlaying&&!this.isFinished&&a++<o;){let e=Math.max(1e-4,i.duration);if(this.currentTime-=e,n.wrapMode===`once`){if(this.currentFrameIndex+1>=r.length){this.currentFrameIndex=r.length-1,this.isPlaying=!1,this.isFinished=!0,this._applyFrame(),this.onComplete?.();return}this.currentFrameIndex++}else if(n.wrapMode===`loop`)this.currentFrameIndex=(this.currentFrameIndex+1)%r.length,this.currentFrameIndex===0&&this.onLoop?.();else if(n.wrapMode===`ping-pong`){let e=this.currentFrameIndex+this._direction;e>=r.length?(this._direction=-1,this.currentFrameIndex=Math.max(0,r.length-2)):e<0?(this._direction=1,this.currentFrameIndex=Math.min(r.length-1,1),this.onLoop?.()):this.currentFrameIndex=e}else if(n.wrapMode===`reverse`){if(this.currentFrameIndex-1<0){this.currentFrameIndex=0,this.isPlaying=!1,this.isFinished=!0,this._applyFrame(),this.onComplete?.();return}this.currentFrameIndex--}i=r[this.currentFrameIndex],this._applyFrame()}a>=o&&(this.currentTime=0)}_applyFrame(){if(!this.currentClip||this.currentClip.frames.length===0)return;let e=this.currentClip.frames[this.currentFrameIndex];this.targetSprite&&(this.targetSprite.sourceRect.copy(e.sourceRect),e.anchor&&this.targetSprite.anchor.copy(e.anchor)),this.onFrame?.(this.currentFrameIndex,e)}},we=class{texture;frames=[];constructor(e,t){this.texture=e;let n=e?.width||0,i=e?.height||0,a=t.frameWidth,o=t.frameHeight,s=t.spacing??0,c=t.margin??0,l=t.columns??(a>0?Math.floor((n-c*2+s)/(a+s)):1),u=t.rows??(o>0?Math.floor((i-c*2+s)/(o+s)):1),d=t.totalFrames??l*u,f=0;for(let e=0;e<u&&f<d;e++)for(let t=0;t<l&&f<d;t++){let n=c+t*(a+s),i=c+e*(o+s);this.frames.push(new r(n,i,a,o)),f++}}getFrame(e){if(e<0||e>=this.frames.length)throw Error(`[SpriteSheet] Frame index ${e} out of bounds (0..${this.frames.length-1})`);return this.frames[e]}createClip(e,t,n=12,r=`loop`){let i=n>0?1/n:.1;return new Se({name:e,frames:t.map((e,t)=>({index:t,sourceRect:this.getFrame(e),duration:i})),fps:n,wrapMode:r})}},Te=class{position=new e(0,0);config;_pool=[];_activeCount=0;_emitTimer=0;isEmitting=!0;constructor(t={}){let n=t.maxParticles??500,r=t.startColor instanceof o?t.startColor:o.parse(t.startColor??`#ffffff`),i=t.endColor instanceof o?t.endColor:o.parse(t.endColor??`rgba(255,255,255,0)`);this.config={maxParticles:n,rate:t.rate??50,lifetime:t.lifetime??[.5,1.5],speed:t.speed??[50,150],angle:t.angle??[0,Math.PI*2],spread:t.spread??0,startSize:t.startSize??[4,8],endSize:t.endSize??[0,2],startColor:r,endColor:i,gravity:t.gravity instanceof e?t.gravity.clone():new e(t.gravity?.x??0,t.gravity?.y??0),radialAcceleration:t.radialAcceleration??0,tangentialAcceleration:t.tangentialAcceleration??0,angularVelocity:t.angularVelocity??0,blendMode:t.blendMode??`source-over`,shape:t.shape??`circle`,texture:t.texture};for(let e=0;e<n;e++)this._pool.push({active:!1,x:0,y:0,vx:0,vy:0,life:0,maxLife:1,startSize:4,endSize:0,currentSize:4,rotation:0,angularVelocity:0,startR:255,startG:255,startB:255,startA:1,endR:255,endG:255,endB:255,endA:0,r:255,g:255,b:255,a:1})}get activeCount(){return this._activeCount}_resolveRange(e){return Array.isArray(e)?e:[e,e]}burst(e,t=this.position.x,n=this.position.y){for(let r=0;r<e&&!(this._activeCount>=this.config.maxParticles);r++)this._spawnParticle(t,n)}_spawnParticle(e,t){if(this._activeCount>=this.config.maxParticles)return;let n=this._pool[this._activeCount];n.active=!0,n.x=e,n.y=t;let[r,i]=this._resolveRange(this.config.speed),o=a.randomRange(r,i),[s,c]=this._resolveRange(this.config.angle),l=a.randomRange(s,c);this.config.spread>0&&(l+=a.randomRange(-this.config.spread/2,this.config.spread/2)),n.vx=Math.cos(l)*o,n.vy=Math.sin(l)*o;let[u,d]=this._resolveRange(this.config.lifetime);n.life=0,n.maxLife=Math.max(.001,a.randomRange(u,d));let[f,p]=this._resolveRange(this.config.startSize);n.startSize=a.randomRange(f,p);let[m,h]=this._resolveRange(this.config.endSize);n.endSize=a.randomRange(m,h),n.currentSize=n.startSize;let[g,_]=this._resolveRange(this.config.angularVelocity);n.angularVelocity=a.randomRange(g,_),n.rotation=a.randomRange(0,Math.PI*2),n.startR=this.config.startColor.r,n.startG=this.config.startColor.g,n.startB=this.config.startColor.b,n.startA=this.config.startColor.a,n.endR=this.config.endColor.r,n.endG=this.config.endColor.g,n.endB=this.config.endColor.b,n.endA=this.config.endColor.a,n.r=n.startR,n.g=n.startG,n.b=n.startB,n.a=n.startA,this._activeCount++}update(e){if(e<=0)return;if(this.isEmitting&&this.config.rate>0){this._emitTimer+=e;let t=1/this.config.rate;for(;this._emitTimer>=t;)this._spawnParticle(this.position.x,this.position.y),this._emitTimer-=t}let t=this.config.gravity.x,n=this.config.gravity.y,[r,i]=this._resolveRange(this.config.radialAcceleration),[o,s]=this._resolveRange(this.config.tangentialAcceleration),c=r!==0||i!==0,l=o!==0||s!==0;for(let u=0;u<this._activeCount;u++){let d=this._pool[u];if(d.life+=e,d.life>=d.maxLife){if(this._activeCount--,u<this._activeCount){let e=this._pool[this._activeCount];this._pool[this._activeCount]=d,this._pool[u]=e,u--}d.active=!1;continue}let f=d.life/d.maxLife;if(d.vx+=t*e,d.vy+=n*e,c||l){let t=d.x-this.position.x,n=d.y-this.position.y,u=Math.sqrt(t*t+n*n);if(u>1e-4){let f=t/u,p=n/u;if(c){let t=a.randomRange(r,i);d.vx+=f*t*e,d.vy+=p*t*e}if(l){let t=a.randomRange(o,s);d.vx+=-p*t*e,d.vy+=f*t*e}}}d.x+=d.vx*e,d.y+=d.vy*e,d.angularVelocity!==0&&(d.rotation+=d.angularVelocity*e),d.currentSize=d.startSize+(d.endSize-d.startSize)*f,d.r=Math.round(d.startR+(d.endR-d.startR)*f),d.g=Math.round(d.startG+(d.endG-d.startG)*f),d.b=Math.round(d.startB+(d.endB-d.startB)*f),d.a=d.startA+(d.endA-d.startA)*f}}_getRawContext(e){return e instanceof u?e.rawContext:e}render(e){if(this._activeCount===0)return;let t=this._getRawContext(e),n=t.globalCompositeOperation;this.config.blendMode!==`source-over`&&(t.globalCompositeOperation=this.config.blendMode);let r=this.config.shape;for(let e=0;e<this._activeCount;e++){let n=this._pool[e];if(!(n.currentSize<=.01||n.a<=0)){if(t.fillStyle=`rgba(${n.r},${n.g},${n.b},${n.a})`,r===`circle`)t.beginPath(),t.arc(n.x,n.y,Math.max(.1,n.currentSize),0,Math.PI*2),t.fill();else if(r===`rect`){let e=n.currentSize;n.rotation===0?t.fillRect(n.x-e,n.y-e,e*2,e*2):(t.save(),t.translate(n.x,n.y),t.rotate(n.rotation),t.fillRect(-e,-e,e*2,e*2),t.restore())}else if(r===`sprite`&&this.config.texture){let e=this.config.texture,r=n.currentSize*2;t.save(),t.translate(n.x,n.y),n.rotation!==0&&t.rotate(n.rotation),t.globalAlpha=n.a,e instanceof Y?e.draw(t,0,0,0,r/e.width,r/e.height):t.drawImage(e,-n.currentSize,-n.currentSize,r,r),t.restore()}}}this.config.blendMode!==`source-over`&&(t.globalCompositeOperation=n)}clear(){this._activeCount=0,this._emitTimer=0}},X=class{static _getRaw(e){return e instanceof u?e.rawContext:e}static _resolveColor(e){return e instanceof o?e.toRgbaString():e}static line(e,t,n,r,i,a,o=1,s=`butt`){let c=this._getRaw(e);c.strokeStyle=this._resolveColor(a),c.lineWidth=o,c.lineCap=s,c.beginPath(),c.moveTo(t,n),c.lineTo(r,i),c.stroke()}static rect(e,t,n,r,i,a,o=!0,s=1){let c=this._getRaw(e),l=this._resolveColor(a);o?(c.fillStyle=l,c.fillRect(t,n,r,i)):(c.strokeStyle=l,c.lineWidth=s,c.strokeRect(t,n,r,i))}static roundedRect(e,t,n,r,i,a,o,s=!0,c=1){let l=this._getRaw(e),u=this._resolveColor(o);if(l.beginPath(),typeof l.roundRect==`function`)l.roundRect(t,n,r,i,a);else{let e=Math.min(a,r/2,i/2);l.moveTo(t+e,n),l.lineTo(t+r-e,n),l.arcTo(t+r,n,t+r,n+e,e),l.lineTo(t+r,n+i-e),l.arcTo(t+r,n+i,t+r-e,n+i,e),l.lineTo(t+e,n+i),l.arcTo(t,n+i,t,n+i-e,e),l.lineTo(t,n+e),l.arcTo(t,n,t+e,n,e),l.closePath()}s?(l.fillStyle=u,l.fill()):(l.strokeStyle=u,l.lineWidth=c,l.stroke())}static circle(e,t,n,r,i,a=!0,o=1){let s=this._getRaw(e),c=this._resolveColor(i);s.beginPath(),s.arc(t,n,r,0,Math.PI*2),a?(s.fillStyle=c,s.fill()):(s.strokeStyle=c,s.lineWidth=o,s.stroke())}static arc(e,t,n,r,i,a,o,s=!1,c=1){let l=this._getRaw(e);l.strokeStyle=this._resolveColor(o),l.lineWidth=c,l.beginPath(),l.arc(t,n,r,i,a,s),l.stroke()}static ellipse(e,t,n,r,i,a=0,o,s=!0,c=1){let l=this._getRaw(e),u=this._resolveColor(o);l.beginPath(),typeof l.ellipse==`function`?l.ellipse(t,n,r,i,a,0,Math.PI*2):(l.save(),l.translate(t,n),l.rotate(a),l.scale(r,i),l.arc(0,0,1,0,Math.PI*2),l.restore()),s?(l.fillStyle=u,l.fill()):(l.strokeStyle=u,l.lineWidth=c,l.stroke())}static polygon(e,t,n,r=!0,i=1){if(t.length<3)return;let a=this._getRaw(e),o=this._resolveColor(n);a.beginPath(),a.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e++)a.lineTo(t[e].x,t[e].y);a.closePath(),r?(a.fillStyle=o,a.fill()):(a.strokeStyle=o,a.lineWidth=i,a.stroke())}static path(e,t,n,r=!1,i=1){if(t.length<2)return;let a=this._getRaw(e);a.strokeStyle=this._resolveColor(n),a.lineWidth=i,a.beginPath(),a.moveTo(t[0].x,t[0].y);for(let e=1;e<t.length;e++)a.lineTo(t[e].x,t[e].y);r&&a.closePath(),a.stroke()}},Ee=class{_textures=new Map;_inFlight=new Map;loadedCount=0;totalCount=0;get isLoading(){return this._inFlight.size>0}get progress(){return this.totalCount===0?1:this.loadedCount/this.totalCount}loadTexture(e,t){if(this._textures.has(e))return Promise.resolve(this._textures.get(e));if(this._inFlight.has(e))return this._inFlight.get(e);this.totalCount++;let n,r=new Promise(e=>{n=e}).finally(()=>{this._inFlight.delete(e)});if(this._inFlight.set(e,r),typeof window>`u`||typeof Image>`u`){let t=this.createCheckerboardTexture(32,32);return this._textures.set(e,t),this.loadedCount++,n(t),r}let i=new Image;return i.onload=()=>{this._textures.set(e,i),this.loadedCount++,n(i)},i.onerror=r=>{console.warn(`[AssetLoader] Texture "${e}" failed to load from "${t}". Substituting procedural fallback.`,r);let i=this.createCheckerboardTexture(32,32);this._textures.set(e,i),this.loadedCount++,n(i)},i.src=t,r}async loadTextures(e,t){let n=Object.keys(e),r=n.map(t=>this.loadTexture(t,e[t])),i=0;for(let e of r)await e,i++,t?.(i/n.length);return this._textures}getTexture(e){return this._textures.get(e)}hasTexture(e){return this._textures.has(e)}registerTexture(e,t){this._textures.set(e,t)}createCheckerboardTexture(e=32,t=32,n=`#ff00ff`,r=`#000000`,i=8){let a=n instanceof o?n.toRgbaString():n,s=r instanceof o?r.toRgbaString():r;if(typeof document>`u`){let n=p(e,t),r=n.getContext(`2d`),o=Math.ceil(e/i),c=Math.ceil(t/i);for(let e=0;e<c;e++)for(let t=0;t<o;t++)r.fillStyle=(e+t)%2==0?a:s,r.fillRect(t*i,e*i,i,i);return n}let c=document.createElement(`canvas`);c.width=e,c.height=t;let l=c.getContext(`2d`);if(!l)return c;let u=Math.ceil(e/i),d=Math.ceil(t/i);for(let e=0;e<d;e++)for(let t=0;t<u;t++)l.fillStyle=(e+t)%2==0?a:s,l.fillRect(t*i,e*i,i,i);return c}createSolidTexture(e=1,t=1,n=o.WHITE){let r=n instanceof o?n.toRgbaString():n;if(typeof document>`u`){let n=p(e,t),i=n.getContext(`2d`);return i.fillStyle=r,i.fillRect(0,0,e,t),n}let i=document.createElement(`canvas`);i.width=e,i.height=t;let a=i.getContext(`2d`);return a&&(a.fillStyle=r,a.fillRect(0,0,e,t)),i}createCircleTexture(e=16,t=o.WHITE){let n=e*2,r=t instanceof o?t:o.parse(t);if(typeof document>`u`){let t=p(n,n),i=t.getContext(`2d`);return i.fillStyle=r.toRgbaString(),i.beginPath(),i.arc(e,e,e,0,Math.PI*2),i.fill(),t}let i=document.createElement(`canvas`);i.width=n,i.height=n;let a=i.getContext(`2d`);if(a){let t=a.createRadialGradient(e,e,0,e,e,e);t.addColorStop(0,r.toRgbaString()),t.addColorStop(1,`rgba(${r.r},${r.g},${r.b},0)`),a.fillStyle=t,a.beginPath(),a.arc(e,e,e,0,Math.PI*2),a.fill()}return i}clear(){this._textures.clear(),this._inFlight.clear(),this.loadedCount=0,this.totalCount=0}},De={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>{let t=e-1;return t*t*t+1},easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,smoothstep:e=>a.smoothstep(0,1,e)},Z=class{duration;elapsed=0;progress=0;isComplete=!1;easing;hasMidpoint=!1;midpointTriggered=!1;constructor(e={}){this.duration=Math.max(0,e.duration??.5),this.easing=e.easing??De.linear,this.duration===0&&(this.isComplete=!0,this.progress=1)}reset(){this.elapsed=0,this.progress=0,this.isComplete=this.duration===0,this.midpointTriggered=!1}start(e,t){this.reset()}update(e){if(this.isComplete)return;this.elapsed+=e;let t=this.duration>0?Math.min(1,this.elapsed/this.duration):1;this.progress=a.clamp01(this.easing(t)),t>=1&&(this.isComplete=!0,this.progress=1)}getCanvasDimensions(e){return{width:e?.virtualWidth??e?.canvas?.width??800,height:e?.virtualHeight??e?.canvas?.height??600}}},Oe=class extends Z{hasMidpoint=!0;color;constructor(e={}){super(e),this.color=e.color??`#000000`}render(e,t,n){let{width:r,height:i}=this.getCanvasDimensions(e),o;this.progress<=.5?(t?.render(e),o=this.progress*2):(n?.render(e),o=(1-this.progress)*2),o=a.clamp01(o),o>0&&(e.save(),e.fillStyle=this.color,e.globalAlpha=o,e.fillRect(0,0,r,i),e.restore())}},ke=class extends Z{direction;mode;constructor(e={}){super(e),this.direction=e.direction??`left`,this.mode=e.mode??`push`}render(e,t,n){let{width:r,height:i}=this.getCanvasDimensions(e),a=0,o=0;switch(this.direction){case`left`:a=-r;break;case`right`:a=r;break;case`up`:o=-i;break;case`down`:o=i}let s=0,c=0,l=0,u=0;switch(this.mode){case`push`:s=a*this.progress,c=o*this.progress,l=a*(this.progress-1),u=o*(this.progress-1);break;case`cover`:s=0,c=0,l=a*(this.progress-1),u=o*(this.progress-1);break;case`reveal`:s=a*this.progress,c=o*this.progress,l=0,u=0}this.mode===`reveal`?(n&&(e.save(),e.translate(l,u),n.render(e),e.restore()),t&&(e.save(),e.translate(s,c),t.render(e),e.restore())):(t&&(e.save(),e.translate(s,c),t.render(e),e.restore()),n&&(e.save(),e.translate(l,u),n.render(e),e.restore()))}},Ae=class extends Z{render(e,t,n){let r=a.clamp01(this.progress);t&&r<1&&(e.save(),e.globalAlpha=1-r,t.render(e),e.restore()),n&&r>0&&(e.save(),e.globalAlpha=r,n.render(e),e.restore())}},je=class extends Z{constructor(){super({duration:0})}render(e,t,n){n?.render(e)}},Me=class extends U{value;min;max;direction;backgroundColor;borderColor;borderWidth;borderRadius;fillColor;fillPadding;fillBorderRadius;showText;textFormat;label;constructor(e={}){super({size:e.size??{x:200,y:24},...e}),this.min=e.min??0,this.max=e.max??100,this.value=e.value===void 0?this.max:e.value,this.direction=e.direction??`horizontal-ltr`,this.backgroundColor=e.backgroundColor??`#1e1e2e`,this.borderColor=e.borderColor??`#313244`,this.borderWidth=e.borderWidth??1,this.borderRadius=e.borderRadius??4,this.fillColor=e.fillColor??`#22c55e`,this.fillPadding=e.fillPadding??2,this.fillBorderRadius=e.fillBorderRadius??2,this.showText=e.showText??!1,this.textFormat=e.textFormat,this.showText&&(this.label=new ce({text:this._getFormattedText(),fontSize:Math.max(10,Math.floor(this.size.y*.6)),align:`center`,baseline:`middle`,anchor:ue.Center,pivot:de.Center,interactive:!1}),this.addChild(this.label))}get normalizedValue(){return this.max<=this.min?0:a.clamp01((this.value-this.min)/(this.max-this.min))}set normalizedValue(e){this.value=this.min+a.clamp01(e)*(this.max-this.min),this._syncLabel()}setProgress(e,t){return t!==void 0&&(this.max=t),this.value=Math.max(this.min,Math.min(this.max,e)),this._syncLabel(),this}_getFormattedText(){let e=this.normalizedValue;return this.textFormat?this.textFormat(this.value,this.max,e):`${Math.round(e*100)}%`}_syncLabel(){this.label&&this.showText&&(this.label.text=this._getFormattedText())}draw(e,t){let{x:n,y:r,width:i,height:a}=t;e.beginPath(),W(e,n,r,i,a,this.borderRadius),e.fillStyle=this.backgroundColor instanceof o?this.backgroundColor.toRgbaString():this.backgroundColor,e.fill(),this.borderWidth>0&&this.borderColor&&(e.strokeStyle=this.borderColor instanceof o?this.borderColor.toRgbaString():this.borderColor,e.lineWidth=this.borderWidth,e.stroke());let s=this.normalizedValue;if(s<=0)return;let c=this.fillPadding,l=n+c,u=r+c,d=Math.max(0,i-c*2),f=Math.max(0,a-c*2),p=l,m=u,h=d,g=f;switch(this.direction){case`horizontal-ltr`:h=d*s;break;case`horizontal-rtl`:h=d*s,p=l+(d-h);break;case`vertical-btt`:g=f*s,m=u+(f-g);break;case`vertical-ttb`:g=f*s}h>0&&g>0&&(e.beginPath(),W(e,p,m,h,g,this.fillBorderRadius),e.fillStyle=this.fillColor instanceof o?this.fillColor.toRgbaString():this.fillColor,e.fill())}},Q=class{value;defaultValue;minValue;maxValue;scheduledEvents=[];constructor(e=0,t=-34e37,n=34e37){this.value=e,this.defaultValue=e,this.minValue=t,this.maxValue=n}setValueAtTime(e,t){return this.value=e,this.scheduledEvents.push({type:`setValue`,value:e,time:t}),this}linearRampToValueAtTime(e,t){return this.value=e,this.scheduledEvents.push({type:`linearRamp`,value:e,time:t}),this}exponentialRampToValueAtTime(e,t){return this.value=e,this.scheduledEvents.push({type:`exponentialRamp`,value:e,time:t}),this}setTargetAtTime(e,t,n){return this.value=e,this.scheduledEvents.push({type:`setTarget`,value:e,time:t}),this}cancelScheduledValues(e){return this.scheduledEvents=this.scheduledEvents.filter(t=>t.time<e),this}},$=class{context;connections=[];constructor(e){this.context=e}connect(e){return this.connections.push(e),e}disconnect(e){if(!e)this.connections.length=0;else{let t=this.connections.indexOf(e);t!==-1&&this.connections.splice(t,1)}}},Ne=class extends ${gain;constructor(e){super(e),this.gain=new Q(1,0,100)}},Pe=class extends ${type=`sine`;frequency;detune;started=!1;stopped=!1;startTime=0;stopTime=0;onended=null;constructor(e){super(e),this.frequency=new Q(440,0,24e3),this.detune=new Q(0,-153600,153600)}start(e=0){this.started=!0,this.startTime=e}stop(e=0){this.stopped=!0,this.stopTime=e,this.onended&&queueMicrotask(()=>{this.onended&&this.onended()})}},Fe=class{numberOfChannels;length;sampleRate;duration;_channels;constructor(e){this.numberOfChannels=e.numberOfChannels,this.length=e.length,this.sampleRate=e.sampleRate,this.duration=e.length/e.sampleRate,this._channels=[];for(let t=0;t<e.numberOfChannels;t++)this._channels.push(new Float32Array(e.length))}getChannelData(e){if(e<0||e>=this.numberOfChannels)throw RangeError(`MockAudioBuffer: Channel ${e} out of bounds`);return this._channels[e]}copyFromChannel(e,t,n=0){let r=this.getChannelData(t);e.set(r.subarray(n,n+e.length))}copyToChannel(e,t,n=0){this.getChannelData(t).set(e,n)}},Ie=class extends ${buffer=null;playbackRate;detune;loop=!1;loopStart=0;loopEnd=0;started=!1;stopped=!1;onended=null;constructor(e){super(e),this.playbackRate=new Q(1,0,1024),this.detune=new Q(0,-153600,153600)}start(e=0,t=0,n){this.started=!0}stop(e=0){this.stopped=!0,this.onended&&queueMicrotask(()=>{this.onended&&this.onended()})}},Le=class{state=`suspended`;currentTime=0;sampleRate=44100;destination;constructor(){this.destination=new $(this)}createGain(){return new Ne(this)}createOscillator(){return new Pe(this)}createBufferSource(){return new Ie(this)}createBuffer(e,t,n){return new Fe({numberOfChannels:e,length:t,sampleRate:n})}async resume(){this.state=`running`}async suspend(){this.state=`suspended`}async close(){this.state=`closed`}advanceTime(e){this.currentTime+=e}decodeAudioData(e){return Promise.resolve(new Fe({numberOfChannels:2,length:44100,sampleRate:44100}))}};function Re(){globalThis.AudioContext=Le,globalThis.webkitAudioContext=Le,globalThis.AudioBuffer=Fe}var ze=class extends K{sprite;zIndex=0;constructor(e){super(),this.sprite=e instanceof Y?e:new Y(e)}get width(){return this.sprite.width}set width(e){this.sprite.width=e}get height(){return this.sprite.height}set height(e){this.sprite.height=e}get anchor(){return this.sprite.anchor}set anchor(e){this.sprite.anchor.copy(e)}get tint(){return this.sprite.tint}set tint(e){this.sprite.setTint(e)}get flipX(){return this.sprite.flipX}set flipX(e){this.sprite.flipX=e}get flipY(){return this.sprite.flipY}set flipY(e){this.sprite.flipY=e}get opacity(){return this.sprite.opacity}set opacity(e){this.sprite.opacity=Math.max(0,Math.min(1,e))}getBounds(e){return this.sprite.getBounds(e)}onRender(e){if(!this.sprite||!this.sprite.texture)return;let t=this.entity.entityManager?.camera;e.submit({layer:this.entity.layer,zIndex:this.entity.zIndex+this.zIndex,camera:t??void 0,render:e=>{this.sprite.drawTransform(e,this.entity.transform)}})}},Be=class t extends K{shapeType;color;filled;lineWidth;size;radius;cornerRadius;radiusX;radiusY;points;offset;zIndex;constructor(t={}){super(),this.shapeType=t.type??`rect`,this.color=t.color??`#ffffff`,this.filled=t.filled??!0,this.lineWidth=t.lineWidth??1,this.size=t.size instanceof e?t.size.clone():new e(t.size?.x??32,t.size?.y??32),this.radius=t.radius??16,this.cornerRadius=t.cornerRadius??4,this.radiusX=t.radiusX??16,this.radiusY=t.radiusY??8,this.points=t.points?t.points.map(t=>t instanceof e?t.clone():new e(t.x,t.y)):[],this.offset=t.offset instanceof e?t.offset.clone():new e(t.offset?.x??0,t.offset?.y??0),this.zIndex=t.zIndex??0}static rect(n,r,i=`#ffffff`,a=!0){return new t({type:`rect`,size:new e(n,r),color:i,filled:a})}static circle(e,n=`#ffffff`,r=!0){return new t({type:`circle`,radius:e,color:n,filled:r})}static roundedRect(n,r,i=4,a=`#ffffff`,o=!0){return new t({type:`roundedRect`,size:new e(n,r),cornerRadius:i,color:a,filled:o})}static polygon(e,n=`#ffffff`,r=!0){return new t({type:`polygon`,points:e,color:n,filled:r})}static line(e,n=`#ffffff`,r=1){return new t({type:`line`,points:e,color:n,filled:!1,lineWidth:r})}onRender(e){let t=this.entity.entityManager?.camera;e.submit({layer:this.entity.layer,zIndex:this.entity.zIndex+this.zIndex,camera:t??void 0,render:e=>{let t=e instanceof u?e.rawContext:e;t.save(),this.entity.transform.updateWorldMatrix().transformContext(t);let n=this.offset.x,r=this.offset.y;switch(this.shapeType){case`rect`:X.rect(t,n-this.size.x/2,r-this.size.y/2,this.size.x,this.size.y,this.color,this.filled,this.lineWidth);break;case`circle`:X.circle(t,n,r,this.radius,this.color,this.filled,this.lineWidth);break;case`roundedRect`:X.roundedRect(t,n-this.size.x/2,r-this.size.y/2,this.size.x,this.size.y,this.cornerRadius,this.color,this.filled,this.lineWidth);break;case`ellipse`:X.ellipse(t,n,r,this.radiusX,this.radiusY,0,this.color,this.filled,this.lineWidth);break;case`polygon`:X.polygon(t,this.points,this.color,this.filled,this.lineWidth);break;case`line`:X.path(t,this.points,this.color,!1,this.lineWidth)}t.restore()}})}},Ve=class extends K{get position(){return this.entity.transform.position}get rotation(){return this.entity.transform.rotation}set rotation(e){this.entity.transform.rotation=e}get scale(){return this.entity.transform.scale}destroyEntity(){this.entity.destroy()}onStart(){}onUpdate(e){}onFixedUpdate(e){}onRender(e){}onDestroy(){}onCollisionEnter(e,t){}onCollisionStay(e,t){}onCollisionExit(e){}onTriggerEnter(e){}onTriggerStay(e){}onTriggerExit(e){}},He=`1.0.0`,Ue=`FrameworkGame`;exports.ActionMap=S,exports.Animation=Ce,exports.AnimationClip=Se,exports.AssetLoader=Ee,exports.AudioBus=ne,exports.Behavior=Ve,exports.ScriptComponent=Ve,exports.Blackboard=ie,exports.BodyType=T,exports.BoxCollider2D=z,exports.BoxColliderComponent=_e,exports.Camera2D=_,exports.CanvasContext=u,exports.CanvasMock=m,exports.Circle=i,exports.CircleCollider2D=R,exports.CircleColliderComponent=ge,exports.Collider2D=F,exports.ColliderComponent=q,exports.ColliderPair=O,exports.ColliderType=N,exports.CollisionFSM=M,exports.Color=o,exports.Component=K,exports.ContactSolver=D,exports.CrossFadeTransition=Ae,exports.Easing=De,exports.Entity=he,exports.EntityManager=ve,exports.EventEmitter=s,exports.FRAMEWORK_NAME=Ue,exports.FadeTransition=Oe,exports.Game=ye,exports.GameLoop=l,exports.GridCell=k,exports.InputManager=w,exports.InstantTransition=je,exports.MathUtils=a,exports.Matrix2D=t,exports.MockAudioBuffer=Fe,exports.MockAudioBufferSourceNode=Ie,exports.MockAudioContext=Le,exports.MockAudioNode=$,exports.MockAudioParam=Q,exports.MockCanvasElement=f,exports.MockCanvasRenderingContext2D=d,exports.MockGainNode=Ne,exports.MockOscillatorNode=Pe,exports.MouseButton=v,exports.Narrowphase=ee,exports.ParticleSystem=Te,exports.PhysicsWorld2D=te,exports.Pointer=b,exports.ProceduralAudio=B,exports.Ray2D=I,exports.Raycast=L,exports.Rect=r,exports.RenderLayer=h,exports.Renderer=g,exports.RigidBody2D=E,exports.RigidBodyComponent=J,exports.Scene=ae,exports.SceneManager=oe,exports.SceneState=H,exports.SceneTransition=Z,exports.ShapeComponent=Be,exports.Shapes=X,exports.SlideTransition=ke,exports.SoundManager=V,exports.SpatialGrid=A,exports.Sprite=Y,exports.SpriteComponent=ze,exports.SpriteSheet=we,exports.TextureTintCache=xe,exports.Time=c,exports.Transform2D=n,exports.UIAnchor=ue,exports.UIButton=G,exports.UIButtonState=fe,exports.UIElement=U,exports.UILabel=ce,exports.UIManager=pe,exports.UIPanel=le,exports.UIPivot=de,exports.UIProgressBar=Me,exports.VERSION=He,exports.Vector2=e,exports.VirtualJoystick=x,exports.VoicePool=re,exports.createGame=be,exports.createMockCanvas=p,exports.drawRoundedRectPath=W,exports.getPairKey=j,exports.installAudioMocks=Re,exports.normalizeButton=y,exports.normalizeKeyCode=C;
4
+ //# sourceMappingURL=index.cjs.map