excalibur 0.25.2 → 0.25.3
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.
- package/CHANGELOG.md +7 -2
- package/build/dist/Actions/Action/Blink.js +51 -0
- package/build/dist/Actions/Action/Blink.js.map +1 -0
- package/build/dist/Actions/Action/CallMethod.js +21 -0
- package/build/dist/Actions/Action/CallMethod.js.map +1 -0
- package/build/dist/Actions/Action/Delay.js +25 -0
- package/build/dist/Actions/Action/Delay.js.map +1 -0
- package/build/dist/Actions/Action/Die.js +22 -0
- package/build/dist/Actions/Action/Die.js.map +1 -0
- package/build/dist/Actions/Action/EaseTo.js +69 -0
- package/build/dist/Actions/Action/EaseTo.js.map +1 -0
- package/build/dist/Actions/Action/Fade.js +46 -0
- package/build/dist/Actions/Action/Fade.js.map +1 -0
- package/build/dist/Actions/Action/Follow.js +55 -0
- package/build/dist/Actions/Action/Follow.js.map +1 -0
- package/build/dist/Actions/Action/Meet.js +52 -0
- package/build/dist/Actions/Action/Meet.js.map +1 -0
- package/build/dist/Actions/Action/MoveBy.js +47 -0
- package/build/dist/Actions/Action/MoveBy.js.map +1 -0
- package/build/dist/Actions/Action/MoveTo.js +40 -0
- package/build/dist/Actions/Action/MoveTo.js.map +1 -0
- package/build/dist/Actions/Action/Repeat.js +31 -0
- package/build/dist/Actions/Action/Repeat.js.map +1 -0
- package/build/dist/Actions/Action/RepeatForever.js +37 -0
- package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
- package/build/dist/Actions/Action/RotateBy.js +91 -0
- package/build/dist/Actions/Action/RotateBy.js.map +1 -0
- package/build/dist/Actions/Action/RotateTo.js +90 -0
- package/build/dist/Actions/Action/RotateTo.js.map +1 -0
- package/build/dist/Actions/Action/ScaleBy.js +45 -0
- package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
- package/build/dist/Actions/Action/ScaleTo.js +56 -0
- package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
- package/build/dist/Actions/Action.js +2 -0
- package/build/dist/Actions/Action.js.map +1 -0
- package/build/dist/Actions/ActionContext.js +305 -0
- package/build/dist/Actions/ActionContext.js.map +1 -0
- package/build/dist/Actions/ActionQueue.js +87 -0
- package/build/dist/Actions/ActionQueue.js.map +1 -0
- package/build/dist/Actions/Actionable.js +2 -0
- package/build/dist/Actions/Actionable.js.map +1 -0
- package/build/dist/Actions/ActionsComponent.js +198 -0
- package/build/dist/Actions/ActionsComponent.js.map +1 -0
- package/build/dist/Actions/ActionsSystem.js +18 -0
- package/build/dist/Actions/ActionsSystem.js.map +1 -0
- package/build/dist/Actions/Index.js +22 -0
- package/build/dist/Actions/Index.js.map +1 -0
- package/build/dist/Actions/RotationType.js +27 -0
- package/build/dist/Actions/RotationType.js.map +1 -0
- package/build/dist/Actor.js +831 -0
- package/build/dist/Actor.js.map +1 -0
- package/build/dist/Camera.js +663 -0
- package/build/dist/Camera.js.map +1 -0
- package/build/dist/Class.js +48 -0
- package/build/dist/Class.js.map +1 -0
- package/build/dist/Collision/BodyComponent.js +351 -0
- package/build/dist/Collision/BodyComponent.js.map +1 -0
- package/build/dist/Collision/BoundingBox.js +361 -0
- package/build/dist/Collision/BoundingBox.js.map +1 -0
- package/build/dist/Collision/ColliderComponent.js +198 -0
- package/build/dist/Collision/ColliderComponent.js.map +1 -0
- package/build/dist/Collision/Colliders/CircleCollider.js +264 -0
- package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/Collider.js +26 -0
- package/build/dist/Collision/Colliders/Collider.js.map +1 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js +301 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/CompositeCollider.js +232 -0
- package/build/dist/Collision/Colliders/CompositeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js +253 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js +389 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
- package/build/dist/Collision/Colliders/Shape.js +102 -0
- package/build/dist/Collision/Colliders/Shape.js.map +1 -0
- package/build/dist/Collision/CollisionSystem.js +116 -0
- package/build/dist/Collision/CollisionSystem.js.map +1 -0
- package/build/dist/Collision/CollisionType.js +33 -0
- package/build/dist/Collision/CollisionType.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionContact.js +46 -0
- package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTree.js +442 -0
- package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js +211 -0
- package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/Pair.js +92 -0
- package/build/dist/Collision/Detection/Pair.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroup.js +114 -0
- package/build/dist/Collision/Group/CollisionGroup.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroupManager.js +52 -0
- package/build/dist/Collision/Group/CollisionGroupManager.js.map +1 -0
- package/build/dist/Collision/Index.js +29 -0
- package/build/dist/Collision/Index.js.map +1 -0
- package/build/dist/Collision/Integrator.js +11 -0
- package/build/dist/Collision/Integrator.js.map +1 -0
- package/build/dist/Collision/MotionSystem.js +42 -0
- package/build/dist/Collision/MotionSystem.js.map +1 -0
- package/build/dist/Collision/Physics.js +163 -0
- package/build/dist/Collision/Physics.js.map +1 -0
- package/build/dist/Collision/Side.js +51 -0
- package/build/dist/Collision/Side.js.map +1 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js +101 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js +83 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
- package/build/dist/Collision/Solver/RealisticSolver.js +248 -0
- package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
- package/build/dist/Collision/Solver/Solver.js +37 -0
- package/build/dist/Collision/Solver/Solver.js.map +1 -0
- package/build/dist/Color.js +461 -0
- package/build/dist/Color.js.map +1 -0
- package/build/dist/Configurable.js +32 -0
- package/build/dist/Configurable.js.map +1 -0
- package/build/dist/Debug/Debug.js +375 -0
- package/build/dist/Debug/Debug.js.map +1 -0
- package/build/dist/Debug/DebugFlags.js +40 -0
- package/build/dist/Debug/DebugFlags.js.map +1 -0
- package/build/dist/Debug/DebugSystem.js +251 -0
- package/build/dist/Debug/DebugSystem.js.map +1 -0
- package/build/dist/Debug/index.js +4 -0
- package/build/dist/Debug/index.js.map +1 -0
- package/build/dist/Deprecated.js +2 -0
- package/build/dist/Deprecated.js.map +1 -0
- package/build/dist/Drawing/Animation.js +294 -0
- package/build/dist/Drawing/Animation.js.map +1 -0
- package/build/dist/Drawing/CanvasDrawComponent.js +16 -0
- package/build/dist/Drawing/CanvasDrawComponent.js.map +1 -0
- package/build/dist/Drawing/CanvasDrawingSystem.js +95 -0
- package/build/dist/Drawing/CanvasDrawingSystem.js.map +1 -0
- package/build/dist/Drawing/Index.js +10 -0
- package/build/dist/Drawing/Index.js.map +1 -0
- package/build/dist/Drawing/Polygon.js +139 -0
- package/build/dist/Drawing/Polygon.js.map +1 -0
- package/build/dist/Drawing/Sprite.js +355 -0
- package/build/dist/Drawing/Sprite.js.map +1 -0
- package/build/dist/Drawing/SpriteEffects.js +246 -0
- package/build/dist/Drawing/SpriteEffects.js.map +1 -0
- package/build/dist/Drawing/SpriteSheet.js +413 -0
- package/build/dist/Drawing/SpriteSheet.js.map +1 -0
- package/build/dist/Drawing/Texture.js +69 -0
- package/build/dist/Drawing/Texture.js.map +1 -0
- package/build/dist/Engine.d.ts +4 -1
- package/build/dist/Engine.js +985 -0
- package/build/dist/Engine.js.map +1 -0
- package/build/dist/EntityComponentSystem/Component.js +65 -0
- package/build/dist/EntityComponentSystem/Component.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js +249 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Entity.js +452 -0
- package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
- package/build/dist/EntityComponentSystem/EntityManager.js +128 -0
- package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Query.js +91 -0
- package/build/dist/EntityComponentSystem/Query.js.map +1 -0
- package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
- package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/System.js +76 -0
- package/build/dist/EntityComponentSystem/System.js.map +1 -0
- package/build/dist/EntityComponentSystem/SystemManager.js +102 -0
- package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Util.js +5 -0
- package/build/dist/EntityComponentSystem/Util.js.map +1 -0
- package/build/dist/EntityComponentSystem/World.js +55 -0
- package/build/dist/EntityComponentSystem/World.js.map +1 -0
- package/build/dist/EntityComponentSystem/index.js +11 -0
- package/build/dist/EntityComponentSystem/index.js.map +1 -0
- package/build/dist/EventDispatcher.js +114 -0
- package/build/dist/EventDispatcher.js.map +1 -0
- package/build/dist/Events/ExEvent.js +12 -0
- package/build/dist/Events/ExEvent.js.map +1 -0
- package/build/dist/Events/MediaEvents.js +75 -0
- package/build/dist/Events/MediaEvents.js.map +1 -0
- package/build/dist/Events/PointerEvents.js +52 -0
- package/build/dist/Events/PointerEvents.js.map +1 -0
- package/build/dist/Events.js +497 -0
- package/build/dist/Events.js.map +1 -0
- package/build/dist/Flags.js +90 -0
- package/build/dist/Flags.js.map +1 -0
- package/build/dist/Graphics/Animation.js +310 -0
- package/build/dist/Graphics/Animation.js.map +1 -0
- package/build/dist/Graphics/Canvas.js +38 -0
- package/build/dist/Graphics/Canvas.js.map +1 -0
- package/build/dist/Graphics/Circle.js +47 -0
- package/build/dist/Graphics/Circle.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +207 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +331 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +160 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/debug-text.js +47 -0
- package/build/dist/Graphics/Context/debug-text.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js +209 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js +87 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js +82 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js +69 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +272 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/render-source.js +16 -0
- package/build/dist/Graphics/Context/render-source.js.map +1 -0
- package/build/dist/Graphics/Context/render-target.js +65 -0
- package/build/dist/Graphics/Context/render-target.js.map +1 -0
- package/build/dist/Graphics/Context/renderer.js +2 -0
- package/build/dist/Graphics/Context/renderer.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +53 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
- package/build/dist/Graphics/Context/shader.js +236 -0
- package/build/dist/Graphics/Context/shader.js.map +1 -0
- package/build/dist/Graphics/Context/state-stack.js +27 -0
- package/build/dist/Graphics/Context/state-stack.js.map +1 -0
- package/build/dist/Graphics/Context/texture-loader.d.ts +8 -0
- package/build/dist/Graphics/Context/texture-loader.js +121 -0
- package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
- package/build/dist/Graphics/Context/transform-stack.js +30 -0
- package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-buffer.js +45 -0
- package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-layout.js +93 -0
- package/build/dist/Graphics/Context/vertex-layout.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-adapter.js +19 -0
- package/build/dist/Graphics/Context/webgl-adapter.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-util.js +105 -0
- package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js +15 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/Filtering.js +17 -0
- package/build/dist/Graphics/Filtering.js.map +1 -0
- package/build/dist/Graphics/Font.js +293 -0
- package/build/dist/Graphics/Font.js.map +1 -0
- package/build/dist/Graphics/FontCommon.js +109 -0
- package/build/dist/Graphics/FontCommon.js.map +1 -0
- package/build/dist/Graphics/Graphic.js +200 -0
- package/build/dist/Graphics/Graphic.js.map +1 -0
- package/build/dist/Graphics/GraphicsComponent.js +290 -0
- package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
- package/build/dist/Graphics/GraphicsGroup.js +69 -0
- package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
- package/build/dist/Graphics/GraphicsSystem.js +153 -0
- package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
- package/build/dist/Graphics/ImageSource.js +116 -0
- package/build/dist/Graphics/ImageSource.js.map +1 -0
- package/build/dist/Graphics/Polygon.js +59 -0
- package/build/dist/Graphics/Polygon.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js +56 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
- package/build/dist/Graphics/Raster.js +207 -0
- package/build/dist/Graphics/Raster.js.map +1 -0
- package/build/dist/Graphics/Rectangle.js +29 -0
- package/build/dist/Graphics/Rectangle.js.map +1 -0
- package/build/dist/Graphics/Sprite.js +103 -0
- package/build/dist/Graphics/Sprite.js.map +1 -0
- package/build/dist/Graphics/SpriteFont.js +120 -0
- package/build/dist/Graphics/SpriteFont.js.map +1 -0
- package/build/dist/Graphics/SpriteSheet.js +115 -0
- package/build/dist/Graphics/SpriteSheet.js.map +1 -0
- package/build/dist/Graphics/Text.js +94 -0
- package/build/dist/Graphics/Text.js.map +1 -0
- package/build/dist/Graphics/index.js +42 -0
- package/build/dist/Graphics/index.js.map +1 -0
- package/build/dist/Id.js +8 -0
- package/build/dist/Id.js.map +1 -0
- package/build/dist/Input/CapturePointerConfig.js +5 -0
- package/build/dist/Input/CapturePointerConfig.js.map +1 -0
- package/build/dist/Input/EngineInput.js +2 -0
- package/build/dist/Input/EngineInput.js.map +1 -0
- package/build/dist/Input/Gamepad.js +358 -0
- package/build/dist/Input/Gamepad.js.map +1 -0
- package/build/dist/Input/Index.js +22 -0
- package/build/dist/Input/Index.js.map +1 -0
- package/build/dist/Input/Keyboard.js +267 -0
- package/build/dist/Input/Keyboard.js.map +1 -0
- package/build/dist/Input/NativePointerButton.js +12 -0
- package/build/dist/Input/NativePointerButton.js.map +1 -0
- package/build/dist/Input/PointerAbstraction.js +41 -0
- package/build/dist/Input/PointerAbstraction.js.map +1 -0
- package/build/dist/Input/PointerButton.js +12 -0
- package/build/dist/Input/PointerButton.js.map +1 -0
- package/build/dist/Input/PointerComponent.js +28 -0
- package/build/dist/Input/PointerComponent.js.map +1 -0
- package/build/dist/Input/PointerEvent.js +25 -0
- package/build/dist/Input/PointerEvent.js.map +1 -0
- package/build/dist/Input/PointerEventReceiver.js +414 -0
- package/build/dist/Input/PointerEventReceiver.js.map +1 -0
- package/build/dist/Input/PointerScope.js +16 -0
- package/build/dist/Input/PointerScope.js.map +1 -0
- package/build/dist/Input/PointerSystem.js +217 -0
- package/build/dist/Input/PointerSystem.js.map +1 -0
- package/build/dist/Input/PointerType.js +11 -0
- package/build/dist/Input/PointerType.js.map +1 -0
- package/build/dist/Input/WheelDeltaMode.js +7 -0
- package/build/dist/Input/WheelDeltaMode.js.map +1 -0
- package/build/dist/Input/WheelEvent.js +21 -0
- package/build/dist/Input/WheelEvent.js.map +1 -0
- package/build/dist/Interfaces/Audio.js +2 -0
- package/build/dist/Interfaces/Audio.js.map +1 -0
- package/build/dist/Interfaces/AudioImplementation.js +11 -0
- package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
- package/build/dist/Interfaces/Clonable.js +2 -0
- package/build/dist/Interfaces/Clonable.js.map +1 -0
- package/build/dist/Interfaces/Drawable.js +2 -0
- package/build/dist/Interfaces/Drawable.js.map +1 -0
- package/build/dist/Interfaces/Evented.js +2 -0
- package/build/dist/Interfaces/Evented.js.map +1 -0
- package/build/dist/Interfaces/Index.js +10 -0
- package/build/dist/Interfaces/Index.js.map +1 -0
- package/build/dist/Interfaces/LifecycleEvents.js +51 -0
- package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
- package/build/dist/Interfaces/Loadable.js +2 -0
- package/build/dist/Interfaces/Loadable.js.map +1 -0
- package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
- package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
- package/build/dist/Interfaces/Trait.js +2 -0
- package/build/dist/Interfaces/Trait.js.map +1 -0
- package/build/dist/Label.js +273 -0
- package/build/dist/Label.js.map +1 -0
- package/build/dist/Loader.js +367 -0
- package/build/dist/Loader.js.map +1 -0
- package/build/dist/Math/Index.js +10 -0
- package/build/dist/Math/Index.js.map +1 -0
- package/build/dist/Math/Random.js +239 -0
- package/build/dist/Math/Random.js.map +1 -0
- package/build/dist/Math/global-coordinates.js +30 -0
- package/build/dist/Math/global-coordinates.js.map +1 -0
- package/build/dist/Math/line.js +194 -0
- package/build/dist/Math/line.js.map +1 -0
- package/build/dist/Math/matrix.js +446 -0
- package/build/dist/Math/matrix.js.map +1 -0
- package/build/dist/Math/projection.js +24 -0
- package/build/dist/Math/projection.js.map +1 -0
- package/build/dist/Math/ray.js +52 -0
- package/build/dist/Math/ray.js.map +1 -0
- package/build/dist/Math/util.js +82 -0
- package/build/dist/Math/util.js.map +1 -0
- package/build/dist/Math/vector-view.js +25 -0
- package/build/dist/Math/vector-view.js.map +1 -0
- package/build/dist/Math/vector.js +326 -0
- package/build/dist/Math/vector.js.map +1 -0
- package/build/dist/Particles.js +449 -0
- package/build/dist/Particles.js.map +1 -0
- package/build/dist/Polyfill.js +56 -0
- package/build/dist/Polyfill.js.map +1 -0
- package/build/dist/Promises.js +205 -0
- package/build/dist/Promises.js.map +1 -0
- package/build/dist/Resources/Gif.js +479 -0
- package/build/dist/Resources/Gif.js.map +1 -0
- package/build/dist/Resources/Index.js +4 -0
- package/build/dist/Resources/Index.js.map +1 -0
- package/build/dist/Resources/Resource.js +74 -0
- package/build/dist/Resources/Resource.js.map +1 -0
- package/build/dist/Resources/Sound/AudioContext.js +16 -0
- package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
- package/build/dist/Resources/Sound/Index.js +4 -0
- package/build/dist/Resources/Sound/Index.js.map +1 -0
- package/build/dist/Resources/Sound/Sound.js +240 -0
- package/build/dist/Resources/Sound/Sound.js.map +1 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js +160 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
- package/build/dist/Scene.js +458 -0
- package/build/dist/Scene.js.map +1 -0
- package/build/dist/Screen.js +634 -0
- package/build/dist/Screen.js.map +1 -0
- package/build/dist/ScreenElement.js +29 -0
- package/build/dist/ScreenElement.js.map +1 -0
- package/build/dist/TileMap.js +488 -0
- package/build/dist/TileMap.js.map +1 -0
- package/build/dist/Timer.js +198 -0
- package/build/dist/Timer.js.map +1 -0
- package/build/dist/Traits/Index.js +5 -0
- package/build/dist/Traits/Index.js.map +1 -0
- package/build/dist/Traits/OffscreenCulling.js +35 -0
- package/build/dist/Traits/OffscreenCulling.js.map +1 -0
- package/build/dist/Trigger.js +113 -0
- package/build/dist/Trigger.js.map +1 -0
- package/build/dist/Util/Actors.js +19 -0
- package/build/dist/Util/Actors.js.map +1 -0
- package/build/dist/Util/Browser.js +66 -0
- package/build/dist/Util/Browser.js.map +1 -0
- package/build/dist/Util/Clock.js +219 -0
- package/build/dist/Util/Clock.js.map +1 -0
- package/build/dist/Util/CullingBox.js +104 -0
- package/build/dist/Util/CullingBox.js.map +1 -0
- package/build/dist/Util/Decorators.js +78 -0
- package/build/dist/Util/Decorators.js.map +1 -0
- package/build/dist/Util/Detector.js +167 -0
- package/build/dist/Util/Detector.js.map +1 -0
- package/build/dist/Util/DrawUtil.js +117 -0
- package/build/dist/Util/DrawUtil.js.map +1 -0
- package/build/dist/Util/EasingFunctions.js +118 -0
- package/build/dist/Util/EasingFunctions.js.map +1 -0
- package/build/dist/Util/Fps.js +47 -0
- package/build/dist/Util/Fps.js.map +1 -0
- package/build/dist/Util/Index.js +7 -0
- package/build/dist/Util/Index.js.map +1 -0
- package/build/dist/Util/Log.js +195 -0
- package/build/dist/Util/Log.js.map +1 -0
- package/build/dist/Util/Observable.js +60 -0
- package/build/dist/Util/Observable.js.map +1 -0
- package/build/dist/Util/Pool.js +66 -0
- package/build/dist/Util/Pool.js.map +1 -0
- package/build/dist/Util/SortedList.js +261 -0
- package/build/dist/Util/SortedList.js.map +1 -0
- package/build/dist/Util/Sound.js +22 -0
- package/build/dist/Util/Sound.js.map +1 -0
- package/build/dist/Util/Util.js +294 -0
- package/build/dist/Util/Util.js.map +1 -0
- package/build/dist/Util/Watch.js +67 -0
- package/build/dist/Util/Watch.js.map +1 -0
- package/build/dist/Util/WebAudio.js +62 -0
- package/build/dist/Util/WebAudio.js.map +1 -0
- package/build/dist/excalibur.js +101 -22
- package/build/dist/excalibur.js.map +1 -1
- package/build/dist/excalibur.min.js +1 -1
- package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
- package/build/dist/excalibur.min.js.map +1 -1
- package/build/dist/index.js +74 -0
- package/build/dist/index.js.map +1 -0
- package/build/esm/Engine.d.ts +4 -1
- package/build/esm/Graphics/Context/texture-loader.d.ts +8 -0
- package/build/esm/excalibur.js +101 -22
- package/build/esm/excalibur.js.map +1 -1
- package/build/esm/excalibur.min.js +1 -1
- package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
- package/build/esm/excalibur.min.js.map +1 -1
- package/package.json +23 -22
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see excalibur.min.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ex=e():t.ex=e()}(self,(function(){return(()=>{var t={4662:(t,e,i)=>{i(3430);var s=i(8791);t.exports=s("Array","sort")},8343:(t,e,i)=>{i(4769);var s=i(9276);t.exports=s.Object.keys},7111:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(9821),o=s.TypeError;t.exports=function(t){if(r(t))return t;throw o(n(t)+" is not a function")}},1176:(t,e,i)=>{var s=i(9859),r=i(5052),n=s.String,o=s.TypeError;t.exports=function(t){if(r(t))return t;throw o(n(t)+" is not an object")}},9540:(t,e,i)=>{var s=i(905),r=i(3231),n=i(9646),o=function(t){return function(e,i,o){var a,h=s(e),l=n(h),c=r(o,l);if(t&&i!=i){for(;l>c;)if((a=h[c++])!=a)return!0}else for(;l>c;c++)if((t||c in h)&&h[c]===i)return t||c||0;return!t&&-1}};t.exports={includes:o(!0),indexOf:o(!1)}},6038:(t,e,i)=>{"use strict";var s=i(4229);t.exports=function(t,e){var i=[][t];return!!i&&s((function(){i.call(null,e||function(){throw 1},1)}))}},9794:(t,e,i)=>{var s=i(9859),r=i(3231),n=i(9646),o=i(2324),a=s.Array,h=Math.max;t.exports=function(t,e,i){for(var s=n(t),l=r(e,s),c=r(void 0===i?s:i,s),d=a(h(c-l,0)),u=0;l<c;l++,u++)o(d,u,t[l]);return d.length=u,d}},3867:(t,e,i)=>{var s=i(9794),r=Math.floor,n=function(t,e){var i=t.length,h=r(i/2);return i<8?o(t,e):a(t,n(s(t,0,h),e),n(s(t,h),e),e)},o=function(t,e){for(var i,s,r=t.length,n=1;n<r;){for(s=n,i=t[n];s&&e(t[s-1],i)>0;)t[s]=t[--s];s!==n++&&(t[s]=i)}return t},a=function(t,e,i,s){for(var r=e.length,n=i.length,o=0,a=0;o<r||a<n;)t[o+a]=o<r&&a<n?s(e[o],i[a])<=0?e[o++]:i[a++]:o<r?e[o++]:i[a++];return t};t.exports=n},7079:(t,e,i)=>{var s=i(5968),r=s({}.toString),n=s("".slice);t.exports=function(t){return n(r(t),8,-1)}},1589:(t,e,i)=>{var s=i(9859),r=i(1601),n=i(6733),o=i(7079),a=i(95)("toStringTag"),h=s.Object,l="Arguments"==o(function(){return arguments}());t.exports=r?o:function(t){var e,i,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=function(t,e){try{return t[e]}catch(t){}}(e=h(t),a))?i:l?o(e):"Object"==(s=o(e))&&n(e.callee)?"Arguments":s}},7081:(t,e,i)=>{var s=i(8270),r=i(4826),n=i(7933),o=i(1787);t.exports=function(t,e,i){for(var a=r(e),h=o.f,l=n.f,c=0;c<a.length;c++){var d=a[c];s(t,d)||i&&s(i,d)||h(t,d,l(e,d))}}},5762:(t,e,i)=>{var s=i(7400),r=i(1787),n=i(5358);t.exports=s?function(t,e,i){return r.f(t,e,n(1,i))}:function(t,e,i){return t[e]=i,t}},5358:t=>{t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},2324:(t,e,i)=>{"use strict";var s=i(9310),r=i(1787),n=i(5358);t.exports=function(t,e,i){var o=s(e);o in t?r.f(t,o,n(0,i)):t[o]=i}},7400:(t,e,i)=>{var s=i(4229);t.exports=!s((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}))},2635:(t,e,i)=>{var s=i(9859),r=i(5052),n=s.document,o=r(n)&&r(n.createElement);t.exports=function(t){return o?n.createElement(t):{}}},2671:(t,e,i)=>{var s=i(598).match(/firefox\/(\d+)/i);t.exports=!!s&&+s[1]},8506:(t,e,i)=>{var s=i(598);t.exports=/MSIE|Trident/.test(s)},598:(t,e,i)=>{var s=i(1333);t.exports=s("navigator","userAgent")||""},6358:(t,e,i)=>{var s,r,n=i(9859),o=i(598),a=n.process,h=n.Deno,l=a&&a.versions||h&&h.version,c=l&&l.v8;c&&(r=(s=c.split("."))[0]>0&&s[0]<4?1:+(s[0]+s[1])),!r&&o&&(!(s=o.match(/Edge\/(\d+)/))||s[1]>=74)&&(s=o.match(/Chrome\/(\d+)/))&&(r=+s[1]),t.exports=r},9811:(t,e,i)=>{var s=i(598).match(/AppleWebKit\/(\d+)\./);t.exports=!!s&&+s[1]},8791:(t,e,i)=>{var s=i(9859),r=i(5968);t.exports=function(t,e){return r(s[t].prototype[e])}},3837:t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3103:(t,e,i)=>{var s=i(9859),r=i(7933).f,n=i(5762),o=i(7487),a=i(2079),h=i(7081),l=i(6541);t.exports=function(t,e){var i,c,d,u,p,g=t.target,_=t.global,f=t.stat;if(i=_?s:f?s[g]||a(g,{}):(s[g]||{}).prototype)for(c in e){if(u=e[c],d=t.noTargetGet?(p=r(i,c))&&p.value:i[c],!l(_?c:g+(f?".":"#")+c,t.forced)&&void 0!==d){if(typeof u==typeof d)continue;h(u,d)}(t.sham||d&&d.sham)&&n(u,"sham",!0),o(i,c,u,t)}}},4229:t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}},266:t=>{var e=Function.prototype.call;t.exports=e.bind?e.bind(e):function(){return e.apply(e,arguments)}},1805:(t,e,i)=>{var s=i(7400),r=i(8270),n=Function.prototype,o=s&&Object.getOwnPropertyDescriptor,a=r(n,"name"),h=a&&"something"===function(){}.name,l=a&&(!s||s&&o(n,"name").configurable);t.exports={EXISTS:a,PROPER:h,CONFIGURABLE:l}},5968:t=>{var e=Function.prototype,i=e.bind,s=e.call,r=i&&i.bind(s,s);t.exports=i?function(t){return t&&r(t)}:function(t){return t&&function(){return s.apply(t,arguments)}}},1333:(t,e,i)=>{var s=i(9859),r=i(6733),n=function(t){return r(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?n(s[t]):s[t]&&s[t][e]}},5300:(t,e,i)=>{var s=i(7111);t.exports=function(t,e){var i=t[e];return null==i?void 0:s(i)}},9859:(t,e,i)=>{var s=function(t){return t&&t.Math==Math&&t};t.exports=s("object"==typeof globalThis&&globalThis)||s("object"==typeof window&&window)||s("object"==typeof self&&self)||s("object"==typeof i.g&&i.g)||function(){return this}()||Function("return this")()},8270:(t,e,i)=>{var s=i(5968),r=i(2991),n=s({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return n(r(t),e)}},5977:t=>{t.exports={}},4394:(t,e,i)=>{var s=i(7400),r=i(4229),n=i(2635);t.exports=!s&&!r((function(){return 7!=Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}))},9337:(t,e,i)=>{var s=i(9859),r=i(5968),n=i(4229),o=i(7079),a=s.Object,h=r("".split);t.exports=n((function(){return!a("z").propertyIsEnumerable(0)}))?function(t){return"String"==o(t)?h(t,""):a(t)}:a},8511:(t,e,i)=>{var s=i(5968),r=i(6733),n=i(5353),o=s(Function.toString);r(n.inspectSource)||(n.inspectSource=function(t){return o(t)}),t.exports=n.inspectSource},6407:(t,e,i)=>{var s,r,n,o=i(8694),a=i(9859),h=i(5968),l=i(5052),c=i(5762),d=i(8270),u=i(5353),p=i(4399),g=i(5977),_="Object already initialized",f=a.TypeError,m=a.WeakMap;if(o||u.state){var v=u.state||(u.state=new m),y=h(v.get),w=h(v.has),x=h(v.set);s=function(t,e){if(w(v,t))throw new f(_);return e.facade=t,x(v,t,e),e},r=function(t){return y(v,t)||{}},n=function(t){return w(v,t)}}else{var b=p("state");g[b]=!0,s=function(t,e){if(d(t,b))throw new f(_);return e.facade=t,c(t,b,e),e},r=function(t){return d(t,b)?t[b]:{}},n=function(t){return d(t,b)}}t.exports={set:s,get:r,has:n,enforce:function(t){return n(t)?r(t):s(t,{})},getterFor:function(t){return function(e){var i;if(!l(e)||(i=r(e)).type!==t)throw f("Incompatible receiver, "+t+" required");return i}}}},6733:t=>{t.exports=function(t){return"function"==typeof t}},6541:(t,e,i)=>{var s=i(4229),r=i(6733),n=/#|\.prototype\./,o=function(t,e){var i=h[a(t)];return i==c||i!=l&&(r(e)?s(e):!!e)},a=o.normalize=function(t){return String(t).replace(n,".").toLowerCase()},h=o.data={},l=o.NATIVE="N",c=o.POLYFILL="P";t.exports=o},5052:(t,e,i)=>{var s=i(6733);t.exports=function(t){return"object"==typeof t?null!==t:s(t)}},4231:t=>{t.exports=!1},9395:(t,e,i)=>{var s=i(9859),r=i(1333),n=i(6733),o=i(1321),a=i(6969),h=s.Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=r("Symbol");return n(e)&&o(e.prototype,h(t))}},9646:(t,e,i)=>{var s=i(4237);t.exports=function(t){return s(t.length)}},3839:(t,e,i)=>{var s=i(6358),r=i(4229);t.exports=!!Object.getOwnPropertySymbols&&!r((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&s&&s<41}))},8694:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(8511),o=s.WeakMap;t.exports=r(o)&&/native code/.test(n(o))},1787:(t,e,i)=>{var s=i(9859),r=i(7400),n=i(4394),o=i(7137),a=i(1176),h=i(9310),l=s.TypeError,c=Object.defineProperty,d=Object.getOwnPropertyDescriptor,u="enumerable",p="configurable",g="writable";e.f=r?o?function(t,e,i){if(a(t),e=h(e),a(i),"function"==typeof t&&"prototype"===e&&"value"in i&&g in i&&!i.writable){var s=d(t,e);s&&s.writable&&(t[e]=i.value,i={configurable:p in i?i.configurable:s.configurable,enumerable:u in i?i.enumerable:s.enumerable,writable:!1})}return c(t,e,i)}:c:function(t,e,i){if(a(t),e=h(e),a(i),n)try{return c(t,e,i)}catch(t){}if("get"in i||"set"in i)throw l("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},7933:(t,e,i)=>{var s=i(7400),r=i(266),n=i(9195),o=i(5358),a=i(905),h=i(9310),l=i(8270),c=i(4394),d=Object.getOwnPropertyDescriptor;e.f=s?d:function(t,e){if(t=a(t),e=h(e),c)try{return d(t,e)}catch(t){}if(l(t,e))return o(!r(n.f,t,e),t[e])}},8151:(t,e,i)=>{var s=i(140),r=i(3837).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return s(t,r)}},894:(t,e)=>{e.f=Object.getOwnPropertySymbols},1321:(t,e,i)=>{var s=i(5968);t.exports=s({}.isPrototypeOf)},140:(t,e,i)=>{var s=i(5968),r=i(8270),n=i(905),o=i(9540).indexOf,a=i(5977),h=s([].push);t.exports=function(t,e){var i,s=n(t),l=0,c=[];for(i in s)!r(a,i)&&r(s,i)&&h(c,i);for(;e.length>l;)r(s,i=e[l++])&&(~o(c,i)||h(c,i));return c}},5632:(t,e,i)=>{var s=i(140),r=i(3837);t.exports=Object.keys||function(t){return s(t,r)}},9195:(t,e)=>{"use strict";var i={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,r=s&&!i.call({1:2},1);e.f=r?function(t){var e=s(this,t);return!!e&&e.enumerable}:i},2914:(t,e,i)=>{var s=i(9859),r=i(266),n=i(6733),o=i(5052),a=s.TypeError;t.exports=function(t,e){var i,s;if("string"===e&&n(i=t.toString)&&!o(s=r(i,t)))return s;if(n(i=t.valueOf)&&!o(s=r(i,t)))return s;if("string"!==e&&n(i=t.toString)&&!o(s=r(i,t)))return s;throw a("Can't convert object to primitive value")}},4826:(t,e,i)=>{var s=i(1333),r=i(5968),n=i(8151),o=i(894),a=i(1176),h=r([].concat);t.exports=s("Reflect","ownKeys")||function(t){var e=n.f(a(t)),i=o.f;return i?h(e,i(t)):e}},9276:(t,e,i)=>{var s=i(9859);t.exports=s},7487:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(8270),o=i(5762),a=i(2079),h=i(8511),l=i(6407),c=i(1805).CONFIGURABLE,d=l.get,u=l.enforce,p=String(String).split("String");(t.exports=function(t,e,i,h){var l,d=!!h&&!!h.unsafe,g=!!h&&!!h.enumerable,_=!!h&&!!h.noTargetGet,f=h&&void 0!==h.name?h.name:e;r(i)&&("Symbol("===String(f).slice(0,7)&&(f="["+String(f).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),(!n(i,"name")||c&&i.name!==f)&&o(i,"name",f),(l=u(i)).source||(l.source=p.join("string"==typeof f?f:""))),t!==s?(d?!_&&t[e]&&(g=!0):delete t[e],g?t[e]=i:o(t,e,i)):g?t[e]=i:a(e,i)})(Function.prototype,"toString",(function(){return r(this)&&d(this).source||h(this)}))},8885:(t,e,i)=>{var s=i(9859).TypeError;t.exports=function(t){if(null==t)throw s("Can't call method on "+t);return t}},2079:(t,e,i)=>{var s=i(9859),r=Object.defineProperty;t.exports=function(t,e){try{r(s,t,{value:e,configurable:!0,writable:!0})}catch(i){s[t]=e}return e}},4399:(t,e,i)=>{var s=i(3036),r=i(1441),n=s("keys");t.exports=function(t){return n[t]||(n[t]=r(t))}},5353:(t,e,i)=>{var s=i(9859),r=i(2079),n="__core-js_shared__",o=s[n]||r(n,{});t.exports=o},3036:(t,e,i)=>{var s=i(4231),r=i(5353);(t.exports=function(t,e){return r[t]||(r[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.20.2",mode:s?"pure":"global",copyright:"© 2022 Denis Pushkarev (zloirock.ru)"})},3231:(t,e,i)=>{var s=i(3329),r=Math.max,n=Math.min;t.exports=function(t,e){var i=s(t);return i<0?r(i+e,0):n(i,e)}},905:(t,e,i)=>{var s=i(9337),r=i(8885);t.exports=function(t){return s(r(t))}},3329:t=>{var e=Math.ceil,i=Math.floor;t.exports=function(t){var s=+t;return s!=s||0===s?0:(s>0?i:e)(s)}},4237:(t,e,i)=>{var s=i(3329),r=Math.min;t.exports=function(t){return t>0?r(s(t),9007199254740991):0}},2991:(t,e,i)=>{var s=i(9859),r=i(8885),n=s.Object;t.exports=function(t){return n(r(t))}},2066:(t,e,i)=>{var s=i(9859),r=i(266),n=i(5052),o=i(9395),a=i(5300),h=i(2914),l=i(95),c=s.TypeError,d=l("toPrimitive");t.exports=function(t,e){if(!n(t)||o(t))return t;var i,s=a(t,d);if(s){if(void 0===e&&(e="default"),i=r(s,t,e),!n(i)||o(i))return i;throw c("Can't convert object to primitive value")}return void 0===e&&(e="number"),h(t,e)}},9310:(t,e,i)=>{var s=i(2066),r=i(9395);t.exports=function(t){var e=s(t,"string");return r(e)?e:e+""}},1601:(t,e,i)=>{var s={};s[i(95)("toStringTag")]="z",t.exports="[object z]"===String(s)},3326:(t,e,i)=>{var s=i(9859),r=i(1589),n=s.String;t.exports=function(t){if("Symbol"===r(t))throw TypeError("Cannot convert a Symbol value to a string");return n(t)}},9821:(t,e,i)=>{var s=i(9859).String;t.exports=function(t){try{return s(t)}catch(t){return"Object"}}},1441:(t,e,i)=>{var s=i(5968),r=0,n=Math.random(),o=s(1..toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+o(++r+n,36)}},6969:(t,e,i)=>{var s=i(3839);t.exports=s&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},7137:(t,e,i)=>{var s=i(7400),r=i(4229);t.exports=s&&r((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))},95:(t,e,i)=>{var s=i(9859),r=i(3036),n=i(8270),o=i(1441),a=i(3839),h=i(6969),l=r("wks"),c=s.Symbol,d=c&&c.for,u=h?c:c&&c.withoutSetter||o;t.exports=function(t){if(!n(l,t)||!a&&"string"!=typeof l[t]){var e="Symbol."+t;a&&n(c,t)?l[t]=c[t]:l[t]=h&&d?d(e):u(e)}return l[t]}},3430:(t,e,i)=>{"use strict";var s=i(3103),r=i(5968),n=i(7111),o=i(2991),a=i(9646),h=i(3326),l=i(4229),c=i(3867),d=i(6038),u=i(2671),p=i(8506),g=i(6358),_=i(9811),f=[],m=r(f.sort),v=r(f.push),y=l((function(){f.sort(void 0)})),w=l((function(){f.sort(null)})),x=d("sort"),b=!l((function(){if(g)return g<70;if(!(u&&u>3)){if(p)return!0;if(_)return _<603;var t,e,i,s,r="";for(t=65;t<76;t++){switch(e=String.fromCharCode(t),t){case 66:case 69:case 70:case 72:i=3;break;case 68:case 71:i=4;break;default:i=2}for(s=0;s<47;s++)f.push({k:e+s,v:i})}for(f.sort((function(t,e){return e.v-t.v})),s=0;s<f.length;s++)e=f[s].k.charAt(0),r.charAt(r.length-1)!==e&&(r+=e);return"DGBEFHACIJK"!==r}}));s({target:"Array",proto:!0,forced:y||!w||!x||!b},{sort:function(t){void 0!==t&&n(t);var e=o(this);if(b)return void 0===t?m(e):m(e,t);var i,s,r=[],l=a(e);for(s=0;s<l;s++)s in e&&v(r,e[s]);for(c(r,function(t){return function(e,i){return void 0===i?-1:void 0===e?1:void 0!==t?+t(e,i)||0:h(e)>h(i)?1:-1}}(t)),i=r.length,s=0;s<i;)e[s]=r[s++];for(;s<l;)delete e[s++];return e}})},4769:(t,e,i)=>{var s=i(3103),r=i(2991),n=i(5632);s({target:"Object",stat:!0,forced:i(4229)((function(){n(1)}))},{keys:function(t){return n(r(t))}})},1388:(t,e,i)=>{"use strict";i.d(e,{Z:()=>a});var s=i(272),r=i.n(s),n=i(2609),o=i.n(n)()(r());o.push([t.id,"/* Buttons styles start */\r\n\r\nbutton#excalibur-play {\r\n display: inline-block;\r\n position: relative;\r\n z-index: 999;\r\n border-radius: 6px;\r\n border: none;\r\n /*border: 3px solid;\r\n border-color: white;\r\n box-shadow: 0 0 10px #ccc;*/\r\n padding: 1rem 1.5rem 1rem 4rem;\r\n margin: 0;\r\n text-decoration: none;\r\n background: #00b233;\r\n color: #ffffff;\r\n font-family: sans-serif;\r\n font-size: 2rem;\r\n white-space: nowrap;\r\n line-height: 1;\r\n cursor: pointer;\r\n text-align: center;\r\n transition: background 250ms ease-in-out, transform 150ms ease;\r\n -webkit-appearance: none;\r\n -moz-appearance: none;\r\n\r\n -webkit-animation: excalibur-button-fadein 200ms; /* Safari, Chrome and Opera > 12.1 */\r\n -moz-animation: excalibur-button-fadein 200ms; /* Firefox < 16 */\r\n -ms-animation: excalibur-button-fadein 200ms; /* Internet Explorer */\r\n -o-animation: excalibur-button-fadein 200ms; /* Opera < 12.1 */\r\n animation: excalibur-button-fadein 200ms;\r\n}\r\n\r\n/*\r\nbutton#excalibur-play {\r\n display: none;\r\n}*/\r\n\r\nbutton#excalibur-play:after {\r\n position: absolute;\r\n content: '';\r\n border: 8px solid;\r\n border-color: transparent transparent transparent white;\r\n left: 35px;\r\n top: 24px;\r\n width: 0;\r\n height: 0;\r\n}\r\n\r\nbutton#excalibur-play:before {\r\n position: absolute;\r\n content: '';\r\n border: 3px solid;\r\n left: 19px;\r\n top: 14px;\r\n border-radius: 20px;\r\n width: 30px;\r\n height: 30px;\r\n}\r\n\r\nbutton#excalibur-play:hover,\r\nbutton#excalibur-play:focus {\r\n background: #00982c;\r\n}\r\n\r\nbutton#excalibur-play:focus {\r\n outline: 1px solid #fff;\r\n outline-offset: -4px;\r\n}\r\n\r\nbutton#excalibur-play:active {\r\n transform: scale(0.99);\r\n}\r\n\r\n@keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Firefox < 16 */\r\n@-moz-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Safari, Chrome and Opera > 12.1 */\r\n@-webkit-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Internet Explorer */\r\n@-ms-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Opera < 12.1 */\r\n@-o-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n","",{version:3,sources:["webpack://./Loader.css"],names:[],mappings:"AAAA,yBAAyB;;AAEzB;EACE,qBAAqB;EACrB,kBAAkB;EAClB,YAAY;EACZ,kBAAkB;EAClB,YAAY;EACZ;;+BAE6B;EAC7B,8BAA8B;EAC9B,SAAS;EACT,qBAAqB;EACrB,mBAAmB;EACnB,cAAc;EACd,uBAAuB;EACvB,eAAe;EACf,mBAAmB;EACnB,cAAc;EACd,eAAe;EACf,kBAAkB;EAClB,8DAA8D;EAC9D,wBAAwB;EACxB,qBAAqB;;EAErB,gDAAgD,EAAE,oCAAoC;EACtF,6CAA6C,EAAE,iBAAiB;EAChE,4CAA4C,EAAE,sBAAsB;EACpE,2CAA2C,EAAE,iBAAiB;EAC9D,wCAAwC;AAC1C;;AAEA;;;EAGE;;AAEF;EACE,kBAAkB;EAClB,WAAW;EACX,iBAAiB;EACjB,uDAAuD;EACvD,UAAU;EACV,SAAS;EACT,QAAQ;EACR,SAAS;AACX;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,iBAAiB;EACjB,UAAU;EACV,SAAS;EACT,mBAAmB;EACnB,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,mBAAmB;AACrB;;AAEA;EACE,uBAAuB;EACvB,oBAAoB;AACtB;;AAEA;EACE,sBAAsB;AACxB;;AAEA;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,iBAAiB;AACjB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,oCAAoC;AACpC;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,sBAAsB;AACtB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,iBAAiB;AACjB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF",sourcesContent:["/* Buttons styles start */\r\n\r\nbutton#excalibur-play {\r\n display: inline-block;\r\n position: relative;\r\n z-index: 999;\r\n border-radius: 6px;\r\n border: none;\r\n /*border: 3px solid;\r\n border-color: white;\r\n box-shadow: 0 0 10px #ccc;*/\r\n padding: 1rem 1.5rem 1rem 4rem;\r\n margin: 0;\r\n text-decoration: none;\r\n background: #00b233;\r\n color: #ffffff;\r\n font-family: sans-serif;\r\n font-size: 2rem;\r\n white-space: nowrap;\r\n line-height: 1;\r\n cursor: pointer;\r\n text-align: center;\r\n transition: background 250ms ease-in-out, transform 150ms ease;\r\n -webkit-appearance: none;\r\n -moz-appearance: none;\r\n\r\n -webkit-animation: excalibur-button-fadein 200ms; /* Safari, Chrome and Opera > 12.1 */\r\n -moz-animation: excalibur-button-fadein 200ms; /* Firefox < 16 */\r\n -ms-animation: excalibur-button-fadein 200ms; /* Internet Explorer */\r\n -o-animation: excalibur-button-fadein 200ms; /* Opera < 12.1 */\r\n animation: excalibur-button-fadein 200ms;\r\n}\r\n\r\n/*\r\nbutton#excalibur-play {\r\n display: none;\r\n}*/\r\n\r\nbutton#excalibur-play:after {\r\n position: absolute;\r\n content: '';\r\n border: 8px solid;\r\n border-color: transparent transparent transparent white;\r\n left: 35px;\r\n top: 24px;\r\n width: 0;\r\n height: 0;\r\n}\r\n\r\nbutton#excalibur-play:before {\r\n position: absolute;\r\n content: '';\r\n border: 3px solid;\r\n left: 19px;\r\n top: 14px;\r\n border-radius: 20px;\r\n width: 30px;\r\n height: 30px;\r\n}\r\n\r\nbutton#excalibur-play:hover,\r\nbutton#excalibur-play:focus {\r\n background: #00982c;\r\n}\r\n\r\nbutton#excalibur-play:focus {\r\n outline: 1px solid #fff;\r\n outline-offset: -4px;\r\n}\r\n\r\nbutton#excalibur-play:active {\r\n transform: scale(0.99);\r\n}\r\n\r\n@keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Firefox < 16 */\r\n@-moz-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Safari, Chrome and Opera > 12.1 */\r\n@-webkit-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Internet Explorer */\r\n@-ms-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Opera < 12.1 */\r\n@-o-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n"],sourceRoot:""}]);const a=o},2609:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var i="",s=void 0!==e[5];return e[4]&&(i+="@supports (".concat(e[4],") {")),e[2]&&(i+="@media ".concat(e[2]," {")),s&&(i+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),i+=t(e),s&&(i+="}"),e[2]&&(i+="}"),e[4]&&(i+="}"),i})).join("")},e.i=function(t,i,s,r,n){"string"==typeof t&&(t=[[null,t,void 0]]);var o={};if(s)for(var a=0;a<this.length;a++){var h=this[a][0];null!=h&&(o[h]=!0)}for(var l=0;l<t.length;l++){var c=[].concat(t[l]);s&&o[c[0]]||(void 0!==n&&(void 0===c[5]||(c[1]="@layer".concat(c[5].length>0?" ".concat(c[5]):""," {").concat(c[1],"}")),c[5]=n),i&&(c[2]?(c[1]="@media ".concat(c[2]," {").concat(c[1],"}"),c[2]=i):c[2]=i),r&&(c[4]?(c[1]="@supports (".concat(c[4],") {").concat(c[1],"}"),c[4]=r):c[4]="".concat(r)),e.push(c))}},e}},272:t=>{"use strict";t.exports=function(t){var e=t[1],i=t[3];if(!i)return e;if("function"==typeof btoa){var s=btoa(unescape(encodeURIComponent(JSON.stringify(i)))),r="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s),n="/*# ".concat(r," */"),o=i.sources.map((function(t){return"/*# sourceURL=".concat(i.sourceRoot||"").concat(t," */")}));return[e].concat(o).concat([n]).join("\n")}return[e].join("\n")}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var n=e[s]={id:s,exports:{}};return t[s](n,n.exports,i),n.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{"use strict";i.r(s),i.d(s,{ActionContext:()=>ks,ActionQueue:()=>ms,ActionsComponent:()=>Fs,ActionsSystem:()=>zr,ActivateEvent:()=>ie,Actor:()=>Us,AddedComponent:()=>es,AddedEntity:()=>hr,Animation:()=>Er,AnimationDirection:()=>Ar,AnimationStrategy:()=>Pr,ArcadeSolver:()=>xr,AudioContextFactory:()=>oi,Axis:()=>Gs,BaseAlign:()=>De,BinaryTreeNode:()=>Qn,Blink:()=>Es,BodyComponent:()=>$i,BoundingBox:()=>B,BroadphaseStrategy:()=>wi,BrowserComponent:()=>on,BrowserEvents:()=>an,Camera:()=>ir,Canvas:()=>St,Cell:()=>Ys,Circle:()=>us,CircleCollider:()=>Vi,Class:()=>hi,Clock:()=>fn,ClosestLine:()=>Hi,ClosestLineJumpTable:()=>Wi,Collider:()=>Oi,ColliderComponent:()=>Zi,CollisionContact:()=>Gi,CollisionEndEvent:()=>te,CollisionGroup:()=>Ri,CollisionGroupManager:()=>En,CollisionJumpTable:()=>qi,CollisionPostSolveEvent:()=>$t,CollisionPreSolveEvent:()=>Qt,CollisionResolutionStrategy:()=>yi,CollisionSolver:()=>wr,CollisionStartEvent:()=>Jt,CollisionSystem:()=>Sr,CollisionType:()=>vi,Color:()=>I,ColorBlindFlags:()=>Vr,ColorBlindnessMode:()=>Or,ColorBlindnessPostProcessor:()=>Wr,Component:()=>Ai,CompositeCollider:()=>Ui,Configurable:()=>xe,ConsoleAppender:()=>m,ContactConstraintPoint:()=>br,ContactEndEvent:()=>Zt,ContactStartEvent:()=>Yt,CoordPlane:()=>Ti,CullingBox:()=>Ji,DeactivateEvent:()=>se,Debug:()=>Gr,DebugGraphicsComponent:()=>Vs,DebugSystem:()=>Fr,DebugText:()=>Ne,DegreeOfFreedom:()=>Qi,Detector:()=>mi,Die:()=>Bs,Direction:()=>ke,DisplayMode:()=>si,DynamicTree:()=>Fi,DynamicTreeCollisionProcessor:()=>zi,EX_VERSION:()=>ro,EaseTo:()=>Ts,EasingFunctions:()=>fs,EdgeCollider:()=>ji,ElasticToActorStrategy:()=>Js,EmitterType:()=>Tr,Engine:()=>xn,EnterTriggerEvent:()=>oe,EnterViewPortEvent:()=>ne,Entity:()=>ns,EntityManager:()=>ur,EventDispatcher:()=>he,EventTypes:()=>lt,Events:()=>e,ExResponse:()=>Bn,ExcaliburGraphicsContext2DCanvas:()=>ln,ExcaliburGraphicsContextWebGL:()=>ii,ExcaliburWebGLContextAccessor:()=>Ve,ExitTriggerEvent:()=>ae,ExitViewPortEvent:()=>re,Experiments:()=>c,Fade:()=>Is,Flags:()=>g,Follow:()=>Ds,Font:()=>Ls,FontStyle:()=>Me,FontUnit:()=>Re,FpsSampler:()=>_n,FrameStats:()=>Xr,GameEvent:()=>At,GameStartEvent:()=>It,GameStopEvent:()=>Rt,GamepadAxisEvent:()=>Wt,GamepadButtonEvent:()=>Ht,GamepadConnectEvent:()=>Ut,GamepadDisconnectEvent:()=>Nt,Gif:()=>Vn,GlobalCoordinates:()=>cn,Graphic:()=>_t,GraphicsComponent:()=>cs,GraphicsGroup:()=>Ir,GraphicsLayer:()=>hs,GraphicsLayers:()=>ls,GraphicsSystem:()=>Mr,HiddenEvent:()=>qt,ImageFiltering:()=>ht,ImageSource:()=>Pe,InitializeEvent:()=>ee,Input:()=>a,Integrator:()=>xi,KillEvent:()=>Pt,Label:()=>Tn,Legacy:()=>d,LegacyDrawing:()=>o,LimitCameraBoundsStrategy:()=>er,Line:()=>Ni,Loader:()=>_i,LockCameraToActorAxisStrategy:()=>$s,LockCameraToActorStrategy:()=>Qs,LogLevel:()=>u,Logger:()=>f,Matrix:()=>ct,MatrixLocations:()=>at,MediaEvent:()=>Cn,Meet:()=>Ms,MockedElement:()=>$n,MotionComponent:()=>Ii,MotionSystem:()=>yr,MoveBy:()=>ws,MoveTo:()=>xs,NativeSoundEvent:()=>Sn,NativeSoundProcessedEvent:()=>An,Observable:()=>Bi,Pair:()=>Di,ParseGif:()=>jn,Particle:()=>Br,ParticleEmitter:()=>Dr,Physics:()=>Ci,PhysicsStats:()=>qr,PointerComponent:()=>ps,PointerSystem:()=>Lr,Polygon:()=>Kn,PolygonCollider:()=>Ki,Pool:()=>Jn,PostCollisionEvent:()=>Kt,PostDebugDrawEvent:()=>kt,PostDrawEvent:()=>Dt,PostFrameEvent:()=>Ot,PostKillEvent:()=>Et,PostUpdateEvent:()=>Lt,PreCollisionEvent:()=>jt,PreDebugDrawEvent:()=>Mt,PreDrawEvent:()=>Bt,PreFrameEvent:()=>zt,PreKillEvent:()=>Tt,PreUpdateEvent:()=>Ft,Projection:()=>Mi,Promise:()=>so,PromiseState:()=>eo,QuadIndexBuffer:()=>Qe,Query:()=>gr,QueryManager:()=>_r,RadiusAroundActorStrategy:()=>tr,Random:()=>M,Raster:()=>Ct,Ray:()=>Li,RealisticSolver:()=>Cr,Rectangle:()=>ds,RemovedComponent:()=>ss,RemovedEntity:()=>cr,Repeat:()=>vs,RepeatForever:()=>ys,Resolution:()=>ri,Resource:()=>le,RotateBy:()=>Cs,RotateTo:()=>bs,RotationType:()=>gs,ScaleBy:()=>As,ScaleTo:()=>Ss,Scene:()=>Nr,Screen:()=>ni,ScreenAppender:()=>v,ScreenElement:()=>Ns,ScreenShader:()=>Hr,ScrollPreventionMode:()=>yn,Shader:()=>Ge,Shape:()=>Yi,Side:()=>T,SortedList:()=>Zn,Sound:()=>Wn,Sprite:()=>Ae,SpriteFont:()=>Ue,SpriteSheet:()=>Oe,StandardClock:()=>mn,StrategyContainer:()=>Zs,Stream:()=>qn,SubscribeEvent:()=>Vt,System:()=>ar,SystemManager:()=>fr,SystemType:()=>or,TagComponent:()=>Pi,TestClock:()=>vn,Text:()=>zs,TextAlign:()=>Be,TextureLoader:()=>bt,TileMap:()=>js,Timer:()=>Ws,Traits:()=>h,TransformComponent:()=>Ei,TreeNode:()=>ki,Trigger:()=>nr,TwoPI:()=>k,UnsubscribeEvent:()=>Gt,Util:()=>l,Vector:()=>A,VectorView:()=>Si,VertexBuffer:()=>Xe,VertexLayout:()=>qe,VisibleEvent:()=>Xt,WebAudio:()=>ai,WebAudioInstance:()=>Nn,World:()=>mr,canonicalizeAngle:()=>O,clamp:()=>z,createId:()=>_,frac:()=>F,hasGraphicsTick:()=>as,hasOnInitialize:()=>Mn,hasOnPostUpdate:()=>zn,hasOnPreUpdate:()=>Fn,hasPostDraw:()=>Un,hasPreDraw:()=>On,has_initialize:()=>Dn,has_postupdate:()=>Ln,has_preupdate:()=>kn,isAddedComponent:()=>is,isAddedSystemEntity:()=>lr,isRemoveSystemEntity:()=>dr,isRemovedComponent:()=>rs,maxMessages:()=>y,obsolete:()=>C,randomInRange:()=>W,randomIntInRange:()=>V,range:()=>H,resetObsoleteCounter:()=>x,sign:()=>L,toDegrees:()=>U,toRadians:()=>N,vec:()=>P,webgl:()=>t});var t={};i.r(t),i.d(t,{ensurePowerOfTwo:()=>vt,getAttributeComponentSize:()=>wt,getAttributePointerType:()=>xt,getGlTypeSizeBytes:()=>yt,isPowerOfTwo:()=>ft,nextHighestPowerOfTwo:()=>mt});var e={};i.r(e),i.d(e,{ActivateEvent:()=>ie,CollisionEndEvent:()=>te,CollisionPostSolveEvent:()=>$t,CollisionPreSolveEvent:()=>Qt,CollisionStartEvent:()=>Jt,ContactEndEvent:()=>Zt,ContactStartEvent:()=>Yt,DeactivateEvent:()=>se,EnterTriggerEvent:()=>oe,EnterViewPortEvent:()=>ne,EventTypes:()=>lt,ExitTriggerEvent:()=>ae,ExitViewPortEvent:()=>re,GameEvent:()=>At,GameStartEvent:()=>It,GameStopEvent:()=>Rt,GamepadAxisEvent:()=>Wt,GamepadButtonEvent:()=>Ht,GamepadConnectEvent:()=>Ut,GamepadDisconnectEvent:()=>Nt,HiddenEvent:()=>qt,InitializeEvent:()=>ee,KillEvent:()=>Pt,PostCollisionEvent:()=>Kt,PostDebugDrawEvent:()=>kt,PostDrawEvent:()=>Dt,PostFrameEvent:()=>Ot,PostKillEvent:()=>Et,PostUpdateEvent:()=>Lt,PreCollisionEvent:()=>jt,PreDebugDrawEvent:()=>Mt,PreDrawEvent:()=>Bt,PreFrameEvent:()=>zt,PreKillEvent:()=>Tt,PreUpdateEvent:()=>Ft,SubscribeEvent:()=>Vt,UnsubscribeEvent:()=>Gt,VisibleEvent:()=>Xt});var r={};i.r(r),i.d(r,{Colorize:()=>ge,Darken:()=>fe,Desaturate:()=>ve,Fill:()=>ye,Grayscale:()=>de,Invert:()=>ue,Lighten:()=>_e,Opacity:()=>pe,Saturate:()=>me});var n={};i.r(n),i.d(n,{circle:()=>pi,line:()=>li,point:()=>ci,roundRect:()=>ui,vector:()=>di});var o={};i.r(o),i.d(o,{Animation:()=>Ie,CanvasDrawComponent:()=>os,CanvasDrawingSystem:()=>kr,Effects:()=>r,Polygon:()=>Rn,Sprite:()=>Se,SpriteFont:()=>ze,SpriteSheet:()=>Le,Texture:()=>we});var a={};i.r(a),i.d(a,{Axes:()=>Zr,Buttons:()=>Yr,Gamepad:()=>nn,Gamepads:()=>rn,KeyEvent:()=>en,Keyboard:()=>sn,Keys:()=>Kr,NativePointerButton:()=>$r,PointerButton:()=>Jr,PointerComponent:()=>ps,PointerEvent:()=>dn,PointerEventReceiver:()=>gn,PointerScope:()=>jr,PointerSystem:()=>Lr,PointerType:()=>tn,WheelDeltaMode:()=>Qr,WheelEvent:()=>un});var h={};i.r(h),i.d(h,{OffscreenCulling:()=>ts});var l={};i.r(l),i.d(l,{Collection:()=>rt,ConsoleAppender:()=>m,DrawUtil:()=>n,EasingFunctions:()=>fs,LogLevel:()=>u,Logger:()=>f,Observable:()=>Bi,ScreenAppender:()=>v,TwoPI:()=>G,addItemToArray:()=>J,canonicalizeAngle:()=>K,clamp:()=>X,contains:()=>et,delay:()=>ot,fail:()=>nt,getOppositeSide:()=>it,getPosition:()=>$,getSideFromDirection:()=>st,randomInRange:()=>q,randomIntInRange:()=>j,range:()=>Q,removeItemFromArray:()=>tt,toDegrees:()=>Y,toRadians:()=>Z});var c,d,u;i(4662),i(8343);function p(){if("undefined"==typeof window&&(window={audioContext:function(){}}),"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setInterval(t,1e3/60)}),"undefined"==typeof window||window.cancelAnimationFrame||(window.cancelAnimationFrame=window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||function(){}),"undefined"!=typeof window&&!window.AudioContext){if(window.webkitAudioContext){const t=window.webkitAudioContext.prototype.decodeAudioData;window.webkitAudioContext.prototype.decodeAudioData=function(e){return new Promise(((i,s)=>{t.call(this,e,i,s)}))}}window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext||window.oAudioContext}"undefined"==typeof window||window.devicePixelRatio||(window.devicePixelRatio=window.devicePixelRatio||1)}!function(t){t.WebGL="use-webgl"}(c||(c={})),function(t){t.Canvas="use-canvas-context",t.LegacyDrawing="use-legacy-drawing"}(d||(d={}));class g{static freeze(){g._FROZEN=!0}static _reset(){g._FROZEN=!1,g._FLAGS={}}static useWebGL(){g.enable(c.WebGL)}static useCanvasGraphicsContext(){g.enable(d.Canvas)}static useLegacyDrawing(){g.enable(d.LegacyDrawing)}static enable(t){if(this._FROZEN)throw Error("Feature flags can only be enabled before Engine constructor time");g._FLAGS[t]=!0}static disable(t){if(this._FROZEN)throw Error("Feature flags can only be disabled before Engine constructor time");g._FLAGS[t]=!1}static isEnabled(t){return!!g._FLAGS[t]}static show(){return Object.keys(g._FLAGS)}}function _(t,e){return{type:t,value:e}}g._FROZEN=!1,g._FLAGS={},function(t){t[t.Debug=0]="Debug",t[t.Info=1]="Info",t[t.Warn=2]="Warn",t[t.Error=3]="Error",t[t.Fatal=4]="Fatal"}(u||(u={}));class f{constructor(){if(this._appenders=[],this.defaultLevel=u.Info,f._INSTANCE)throw new Error("Logger is a singleton");return f._INSTANCE=this,f._INSTANCE.addAppender(new m),f._INSTANCE}static getInstance(){return null==f._INSTANCE&&(f._INSTANCE=new f),f._INSTANCE}addAppender(t){this._appenders.push(t)}clearAppenders(){this._appenders.length=0}_log(t,e){null==t&&(t=this.defaultLevel);const i=this._appenders.length;for(let s=0;s<i;s++)t>=this.defaultLevel&&this._appenders[s].log(t,e)}debug(...t){this._log(u.Debug,t)}info(...t){this._log(u.Info,t)}warn(...t){this._log(u.Warn,t)}error(...t){this._log(u.Error,t)}fatal(...t){this._log(u.Fatal,t)}}f._INSTANCE=null;class m{log(t,e){if(!console&&!console.log&&console.warn&&console.error)return;const i=[];i.unshift.apply(i,e),i.unshift("["+u[t]+"] : "),t<u.Warn?console.log.apply?console.log.apply(console,i):console.log(i.join(" ")):t<u.Error?console.warn.apply?console.warn.apply(console,i):console.warn(i.join(" ")):console.error.apply?console.error.apply(console,i):console.error(i.join(" "))}}class v{constructor(t,e){this._messages=[],this._canvas=document.createElement("canvas"),this._canvas.width=t||window.innerWidth,this._canvas.height=e||window.innerHeight,this._canvas.style.position="absolute",this._ctx=this._canvas.getContext("2d"),document.body.appendChild(this._canvas)}log(t,e){const i=e.join(",");this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._messages.unshift("["+u[t]+"] : "+i);let s=10,r=1;for(let t=0;t<this._messages.length;t++)this._ctx.fillStyle="rgba(255,255,255,"+r.toFixed(2)+")",this._ctx.fillText(this._messages[t],200,s),s+=10,r=r>0?r-.05:0}}const y=5,w={},x=()=>{for(const t in w)w[t]=0},b=(t,e)=>{const i=g.isEnabled("suppress-obsolete-message");w[t]<y&&!i&&(f.getInstance().warn(t),console.trace&&e.showStackTrace&&console.trace()),w[t]++};function C(t){return t={message:"This feature will be removed in future versions of Excalibur.",alternateMethod:null,showStackTrace:!1,...t},function(e,i,s){if(s&&"function"!=typeof s.value&&"function"!=typeof s.get&&"function"!=typeof s.set)throw new SyntaxError("Only classes/functions/getters/setters can be marked as obsolete");const r=`${`${e.name||""}${e.name&&i?".":""}${i||""}`} is marked obsolete: ${t.message}`+(t.alternateMethod?` Use ${t.alternateMethod} instead`:"");w[r]||(w[r]=0);const n=s?{...s}:e;if(!s){class e extends n{constructor(...e){b(r,t),super(...e)}}return e}return s&&s.value?(n.value=function(){return b(r,t),s.value.apply(this,arguments)},n):(s&&s.get&&(n.get=function(){return b(r,t),s.get.apply(this,arguments)}),s&&s.set&&(n.set=function(){return b(r,t),s.set.apply(this,arguments)}),n)}}var S=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class A{constructor(t,e){this._x=0,this._y=0,this._x=t,this._y=e}static get Zero(){return new A(0,0)}static get One(){return new A(1,1)}static get Half(){return new A(.5,.5)}static get Up(){return new A(0,-1)}static get Down(){return new A(0,1)}static get Left(){return new A(-1,0)}static get Right(){return new A(1,0)}static fromAngle(t){return new A(Math.cos(t),Math.sin(t))}static isValid(t){return null!=t&&(!isNaN(t.x)&&!isNaN(t.y)&&(t.x!==1/0&&t.y!==1/0&&t.x!==-1/0&&t.y!==-1/0))}static distance(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}setTo(t,e){this.x=t,this.y=e}equals(t,e=.001){return Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e}distance(t){return t||(t=A.Zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))}squareDistance(t){return t||(t=A.Zero),Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2)}magnitude(){return this.distance()}get size(){return this.distance()}set size(t){const e=this.normalize().scale(t);this.setTo(e.x,e.y)}normalize(){const t=this.distance();return t>0?new A(this.x/t,this.y/t):new A(0,1)}average(t){return this.add(t).scale(.5)}scale(t){return t instanceof A?new A(this.x*t.x,this.y*t.y):new A(this.x*t,this.y*t)}add(t){return new A(this.x+t.x,this.y+t.y)}sub(t){return new A(this.x-t.x,this.y-t.y)}addEqual(t){return this.setTo(this.x+t.x,this.y+t.y),this}subEqual(t){return this.setTo(this.x-t.x,this.y-t.y),this}scaleEqual(t){return this.setTo(this.x*t,this.y*t),this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return t instanceof A?this.x*t.y-this.y*t.x:"number"==typeof t?new A(t*this.y,-t*this.x):void 0}static cross(t,e){return new A(-t*e.y,t*e.x)}perpendicular(){return new A(this.y,-this.x)}normal(){return this.perpendicular().normalize()}negate(){return this.scale(-1)}toAngle(){return Math.atan2(this.y,this.x)}rotate(t,e){e||(e=new A(0,0));const i=Math.sin(t),s=Math.cos(t),r=s*(this.x-e.x)-i*(this.y-e.y)+e.x,n=i*(this.x-e.x)+s*(this.y-e.y)+e.y;return new A(r,n)}clone(){return new A(this.x,this.y)}toString(t){return t?`(${this.x.toFixed(t)}, ${this.y.toFixed(t)})`:`(${this.x}, ${this.y})`}}function P(t,e){return new A(t,e)}S([C({message:"will be removed in favour of `.size` in version 0.25.0"})],A.prototype,"magnitude",null);var T,E=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class I{constructor(t,e,i,s){this.r=t,this.g=e,this.b=i,this.a=null!=s?s:1}static fromRGB(t,e,i,s){return new I(t,e,i,s)}static fromRGBString(t){let e=null;if(e=t.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)/i)){const t=parseInt(e[1],10),i=parseInt(e[2],10),s=parseInt(e[3],10);let r=1;return e[4]&&(r=parseFloat(e[4])),new I(t,i,s,r)}throw new Error("Invalid rgb/a string: "+t)}static fromHex(t){let e=null;if(e=t.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i)){const t=parseInt(e[1],16),i=parseInt(e[2],16),s=parseInt(e[3],16);let r=1;return e[4]&&(r=parseInt(e[4],16)/255),new I(t,i,s,r)}throw new Error("Invalid hex string: "+t)}static fromHSL(t,e,i,s=1){return new R(t,e,i,s).toRGBA()}lighten(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.l+=(1-e.l)*t,e.toRGBA()}darken(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.l-=e.l*t,e.toRGBA()}saturate(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.s+=e.s*t,e.toRGBA()}desaturate(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.s-=e.s*t,e.toRGBA()}multiply(t){const e=t.r/255*this.r/255*255,i=t.g/255*this.g/255*255,s=t.b/255*this.b/255*255,r=t.a*this.a;return new I(e,i,s,r)}mulitiply(t){return this.multiply(t)}screen(t){const e=t.invert(),i=t.invert();return e.multiply(i).invert()}invert(){return new I(255-this.r,255-this.g,255-this.b,1-this.a)}average(t){const e=(t.r+this.r)/2,i=(t.g+this.g)/2,s=(t.b+this.b)/2,r=(t.a+this.a)/2;return new I(e,i,s,r)}equal(t){return this.toString()===t.toString()}toString(t="rgb"){switch(t){case"rgb":return this.toRGBA();case"hsl":return this.toHSLA();case"hex":return this.toHex();default:throw new Error("Invalid Color format")}}_componentToHex(t){const e=t.toString(16);return 1===e.length?"0"+e:e}toHex(){return"#"+this._componentToHex(this.r)+this._componentToHex(this.g)+this._componentToHex(this.b)}toRGBA(){const t=String(this.r.toFixed(0))+", "+String(this.g.toFixed(0))+", "+String(this.b.toFixed(0));return void 0!==this.a||null!==this.a?"rgba("+t+", "+String(this.a)+")":"rgb("+t+")"}toHSLA(){return R.fromRGBA(this.r,this.g,this.b,this.a).toString()}fillStyle(){return this.toString()}clone(){return new I(this.r,this.g,this.b,this.a)}static get Black(){return I.fromHex("#000000")}static get White(){return I.fromHex("#FFFFFF")}static get Gray(){return I.fromHex("#808080")}static get LightGray(){return I.fromHex("#D3D3D3")}static get DarkGray(){return I.fromHex("#A9A9A9")}static get Yellow(){return I.fromHex("#FFFF00")}static get Orange(){return I.fromHex("#FFA500")}static get Red(){return I.fromHex("#FF0000")}static get Vermilion(){return I.fromHex("#FF5B31")}static get Vermillion(){return I.Vermilion}static get Rose(){return I.fromHex("#FF007F")}static get Magenta(){return I.fromHex("#FF00FF")}static get Violet(){return I.fromHex("#7F00FF")}static get Blue(){return I.fromHex("#0000FF")}static get Azure(){return I.fromHex("#007FFF")}static get Cyan(){return I.fromHex("#00FFFF")}static get Viridian(){return I.fromHex("#59978F")}static get Green(){return I.fromHex("#00FF00")}static get Chartreuse(){return I.fromHex("#7FFF00")}static get Transparent(){return I.fromHex("#FFFFFF00")}static get ExcaliburBlue(){return I.fromHex("#176BAA")}}E([C({message:"Alias for incorrect spelling used in older versions, use multiply instead, will be removed in v0.25.0"})],I.prototype,"mulitiply",null),E([C({message:"Alias for incorrect spelling used in older versions",alternateMethod:"Vermilion"})],I,"Vermillion",null);class R{constructor(t,e,i,s){this.h=t,this.s=e,this.l=i,this.a=s}static hue2rgb(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}static fromRGBA(t,e,i,s){t/=255,e/=255,i/=255;const r=Math.max(t,e,i),n=Math.min(t,e,i);let o,a;const h=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=h>.5?s/(2-r-n):s/(r+n),r){case t:o=(e-i)/s+(e<i?6:0);break;case e:o=(i-t)/s+2;break;case i:o=(t-e)/s+4}o/=6}return new R(o,a,h,s)}toRGBA(){let t,e,i;if(0===this.s)t=e=i=this.l;else{const s=this.l<.5?this.l*(1+this.s):this.l+this.s-this.l*this.s,r=2*this.l-s;t=R.hue2rgb(r,s,this.h+1/3),e=R.hue2rgb(r,s,this.h),i=R.hue2rgb(r,s,this.h-1/3)}return new I(255*t,255*e,255*i,this.a)}toString(){return`hsla(${this.h.toFixed(0)}, ${this.s.toFixed(0)}, ${this.l.toFixed(0)}, ${this.a.toFixed(0)})`}}!function(t){t.None="None",t.Top="Top",t.Bottom="Bottom",t.Left="Left",t.Right="Right"}(T||(T={})),function(t){t.getOpposite=function(e){return e===t.Top?t.Bottom:e===t.Bottom?t.Top:e===t.Left?t.Right:e===t.Right?t.Left:t.None},t.fromDirection=function(e){const i=[A.Left,A.Right,A.Up,A.Down],s=[t.Left,t.Right,t.Top,t.Bottom];let r=-Number.MAX_VALUE,n=-1;for(let t=0;t<i.length;t++)i[t].dot(e)>r&&(r=i[t].dot(e),n=t);return s[n]}}(T||(T={}));class B{constructor(t=0,e=0,i=0,s=0){"object"==typeof t?(this.left=t.left,this.top=t.top,this.right=t.right,this.bottom=t.bottom):"number"==typeof t&&(this.left=t,this.top=e,this.right=i,this.bottom=s)}static getSideFromIntersection(t){return t&&t?Math.abs(t.x)>Math.abs(t.y)?t.x<0?T.Right:T.Left:t.y<0?T.Bottom:T.Top:T.None}static fromPoints(t){let e=1/0,i=1/0,s=-1/0,r=-1/0;for(let n=0;n<t.length;n++)t[n].x<e&&(e=t[n].x),t[n].x>s&&(s=t[n].x),t[n].y<i&&(i=t[n].y),t[n].y>r&&(r=t[n].y);return new B(e,i,s,r)}static fromDimension(t,e,i=A.Half,s=A.Zero){return new B(-t*i.x+s.x,-e*i.y+s.y,t-t*i.x+s.x,e-e*i.y+s.y)}get width(){return this.right-this.left}get height(){return this.bottom-this.top}hasZeroDimensions(){return 0===this.width||0===this.height}get center(){return new A((this.left+this.right)/2,(this.top+this.bottom)/2)}translate(t){return new B(this.left+t.x,this.top+t.y,this.right+t.x,this.bottom+t.y)}rotate(t,e=A.Zero){const i=this.getPoints().map((i=>i.rotate(t,e)));return B.fromPoints(i)}scale(t,e=A.Zero){const i=this.translate(e);return new B(i.left*t.x,i.top*t.y,i.right*t.x,i.bottom*t.y)}transform(t){const e=this.getPoints().map((e=>t.multv(e)));return B.fromPoints(e)}getPerimeter(){return 2*(this.width+this.height)}getPoints(){const t=[];return t.push(new A(this.left,this.top)),t.push(new A(this.right,this.top)),t.push(new A(this.right,this.bottom)),t.push(new A(this.left,this.bottom)),t}rayCast(t,e=1/0){let i=-1/0,s=1/0;const r=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,n=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*r,a=(this.right-t.pos.x)*r;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*n,l=(this.bottom-t.pos.y)*n;return i=Math.max(i,Math.min(h,l)),s=Math.min(s,Math.max(h,l)),s>=Math.max(0,i)&&i<e}rayCastTime(t,e=1/0){let i=-1/0,s=1/0;const r=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,n=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*r,a=(this.right-t.pos.x)*r;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*n,l=(this.bottom-t.pos.y)*n;return i=Math.max(i,Math.min(h,l)),s=Math.min(s,Math.max(h,l)),s>=Math.max(0,i)&&i<e?i:-1}contains(t){return t instanceof A?this.left<=t.x&&this.top<=t.y&&this.bottom>=t.y&&this.right>=t.x:t instanceof B&&(this.left<t.left&&this.top<t.top&&t.bottom<this.bottom&&t.right<this.right)}combine(t){return new B(Math.min(this.left,t.left),Math.min(this.top,t.top),Math.max(this.right,t.right),Math.max(this.bottom,t.bottom))}get dimensions(){return new A(this.width,this.height)}intersect(t){const e=this.combine(t);if(e.width<t.width+this.width&&e.height<t.height+this.height&&!e.dimensions.equals(t.dimensions)&&!e.dimensions.equals(this.dimensions)){let e=0;e=this.right>=t.left&&this.right<=t.right?t.left-this.right:t.right-this.left;let i=0;return i=this.top<=t.bottom&&this.top>=t.top?t.bottom-this.top:t.top-this.bottom,Math.abs(e)<Math.abs(i)?new A(e,0):new A(0,i)}if(e.dimensions.equals(t.dimensions)||e.dimensions.equals(this.dimensions)){let e=0;e=this.width-t.width>=0?this.right-t.right<=t.left-this.left?t.left-this.right:t.right-this.left:t.right-this.right<=this.left-t.left?this.left-t.right:this.right-t.left;let i=0;return i=this.height-t.height>=0?this.bottom-t.bottom<=t.top-this.top?t.top-this.bottom:t.bottom-this.top:t.bottom-this.bottom<=this.top-t.top?this.top-t.bottom:this.bottom-t.top,Math.abs(e)<Math.abs(i)?new A(e,0):new A(0,i)}return null}intersectWithSide(t){const e=this.intersect(t);return B.getSideFromIntersection(e)}debugDraw(t,e=I.Yellow){t.strokeStyle=e.toString(),t.strokeRect(this.left,this.top,this.width,this.height)}draw(t,e=I.Yellow){t.debug.drawRect(this.left,this.top,this.width,this.height,{color:e})}}const D=4294967295;class M{constructor(t){this.seed=t,this._lowerMask=2147483647,this._upperMask=2147483648,this._w=32,this._n=624,this._m=397,this._a=2567483615,this._u=11,this._s=7,this._b=2636928640,this._t=15,this._c=4022730752,this._l=18,this._f=1812433253,this._mt=new Array(this._n),this._mt[0]=(t||Date.now())>>>0;for(let t=1;t<this._n;t++){const e=this._mt[t-1]^this._mt[t-1]>>>this._w-2;this._mt[t]=(this._f*((4294901760&e)>>>16)<<16)+this._f*(65535&e)+t>>>0}this._index=this._n}_twist(){const t=[0,this._a];let e=0,i=0;for(;i<this._n-this._m;i++)e=this._mt[i]&this._upperMask|this._mt[i+1]&this._lowerMask,this._mt[i]=this._mt[i+this._m]^e>>>1^t[1&e]&D;for(;i<this._n-1;i++)e=this._mt[i]&this._upperMask|this._mt[i+1]&this._lowerMask,this._mt[i]=this._mt[i+(this._m-this._n)]^e>>>1^t[1&e]&D;e=this._mt[this._n-1]&this._upperMask|this._mt[0]&this._lowerMask,this._mt[this._n-1]=this._mt[this._m-1]^e>>>1^t[1&e]&D,this._index=0}nextInt(){this._index>=this._n&&this._twist();let t=this._mt[this._index++];return t^=t>>>this._u,t^=t<<this._s&this._b,t^=t<<this._t&this._c,t^=t>>>this._l,t>>>0}next(){return this.nextInt()*(1/4294967296)}floating(t,e){return(e-t)*this.next()+t}integer(t,e){return Math.floor((e-t+1)*this.next()+t)}bool(t=.5){return this.next()<=t}pickOne(t){return t[this.integer(0,t.length-1)]}pickSet(t,e,i=!1){return i?this._pickSetWithDuplicates(t,e):this._pickSetWithoutDuplicates(t,e)}_pickSetWithoutDuplicates(t,e){if(e>t.length||e<0)throw new Error("Invalid number of elements to pick, must pick a value 0 < n <= length");if(e===t.length)return t;const i=new Array(e);let s=0;const r=t.slice(0);for(;s<e;){const t=this.integer(0,r.length-1);i[s++]=r[t],r.splice(t,1)}return i}_pickSetWithDuplicates(t,e){if(e<0)throw new Error("Invalid number of elements to pick, must pick a value 0 <= n < MAX_INT");const i=new Array(e);for(let s=0;s<e;s++)i[s]=this.pickOne(t);return i}shuffle(t){const e=t.slice(0);let i=null;for(let t=0;t<e.length-2;t++){const s=this.integer(t,e.length-1);i=e[t],e[t]=e[s],e[s]=i}return e}range(t,e,i){const s=new Array(t);for(let r=0;r<t;r++)s[r]=this.integer(e,i);return s}d4(){return this.integer(1,4)}d6(){return this.integer(1,6)}d8(){return this.integer(1,8)}d10(){return this.integer(1,10)}d12(){return this.integer(1,12)}d20(){return this.integer(1,20)}}const k=2*Math.PI;function F(t){return t>=0?t-Math.floor(t):t-Math.ceil(t)}function L(t){return 0===t?0:t<0?-1:1}function z(t,e,i){return Math.min(Math.max(e,t),i)}function O(t){let e=t;if(t>k)for(;e>k;)e-=k;if(t<0)for(;e<0;)e+=k;return e}function U(t){return 180/Math.PI*t}function N(t){return t/180*Math.PI}const H=(t,e)=>Array.from(new Array(e-t+1),((e,i)=>i+t));function W(t,e,i=new M){return i?i.floating(t,e):t+Math.random()*(e-t)}function V(t,e,i=new M){return i?i.integer(t,e):Math.round(W(t,e))}const G=k,X=z,q=W,j=V,K=O,Y=U,Z=N,Q=H;function $(t){let e=0,i=0;const s=t=>{e+=t.offsetLeft,t.offsetParent&&s(t.offsetParent)},r=t=>{i+=t.offsetTop,t.offsetParent&&r(t.offsetParent)};return s(t),r(t),new A(e,i)}function J(t,e){return-1===e.indexOf(t)&&(e.push(t),!0)}function tt(t,e){let i=-1;return(i=e.indexOf(t))>-1&&(e.splice(i,1),!0)}function et(t,e){for(let i=0;i<t.length;i++)if(t[i]===e)return!0;return!1}function it(t){return t===T.Top?T.Bottom:t===T.Bottom?T.Top:t===T.Left?T.Right:t===T.Right?T.Left:T.None}function st(t){const e=[A.Left,A.Right,A.Up,A.Down],i=[T.Left,T.Right,T.Top,T.Bottom];let s=-Number.MAX_VALUE,r=-1;for(let i=0;i<e.length;i++)e[i].dot(t)>s&&(s=e[i].dot(t),r=i);return i[r]}class rt{constructor(t=rt.DefaultSize){this._internalArray=null,this._endPointer=0,this._internalArray=new Array(t)}_resize(){const t=2*this._internalArray.length,e=new Array(t),i=this.count();for(let t=0;t<i;t++)e[t]=this._internalArray[t];delete this._internalArray,this._internalArray=e}push(t){return this._endPointer===this._internalArray.length&&this._resize(),this._internalArray[this._endPointer++]=t}pop(){return this._endPointer=this._endPointer-1<0?0:this._endPointer-1,this._internalArray[this._endPointer]}count(){return this._endPointer}clear(){this._endPointer=0}internalSize(){return this._internalArray.length}elementAt(t){if(t>=this.count())throw new Error("Invalid index "+t);return this._internalArray[t]}insert(t,e){return t>=this.count()&&this._resize(),this._internalArray[t]=e}remove(t){const e=this.count();if(0===e)throw new Error("Invalid parameter "+t);const i=this._internalArray[t];for(let i=t;i<e;i++)this._internalArray[i]=this._internalArray[i+1];return this._endPointer--,i}removeElement(t){const e=this._internalArray.indexOf(t);this.remove(e)}toArray(){return this._internalArray.slice(0,this._endPointer)}forEach(t){let e=0;const i=this.count();for(;e<i;e++)t.call(this,this._internalArray[e],e)}map(t){const e=this.count();for(let i=0;i<e;i++)this._internalArray[i]=t.call(this,this._internalArray[i],i)}}function nt(t){throw new Error(t)}function ot(t,e){var i;const s=null!==(i=null==e?void 0:e.schedule.bind(e))&&void 0!==i?i:setTimeout;return new Promise((e=>{s((()=>{e()}),t)}))}var at,ht,lt;rt.DefaultSize=200,function(t){t[t.X=12]="X",t[t.Y=13]="Y"}(at||(at={}));class ct{constructor(){this.data=new Float32Array(16),this._scaleSignX=1,this._scaleSignY=1}static ortho(t,e,i,s,r,n){const o=new ct;return o.data[0]=2/(e-t),o.data[1]=0,o.data[2]=0,o.data[3]=0,o.data[4]=0,o.data[5]=2/(s-i),o.data[6]=0,o.data[7]=0,o.data[8]=0,o.data[9]=0,o.data[10]=-2/(n-r),o.data[11]=0,o.data[12]=-(e+t)/(e-t),o.data[13]=-(s+i)/(s-i),o.data[14]=-(n+r)/(n-r),o.data[15]=1,o}clone(){const t=new ct;return t.data[0]=this.data[0],t.data[1]=this.data[1],t.data[2]=this.data[2],t.data[3]=this.data[3],t.data[4]=this.data[4],t.data[5]=this.data[5],t.data[6]=this.data[6],t.data[7]=this.data[7],t.data[8]=this.data[8],t.data[9]=this.data[9],t.data[10]=this.data[10],t.data[11]=this.data[11],t.data[12]=this.data[12],t.data[13]=this.data[13],t.data[14]=this.data[14],t.data[15]=this.data[15],t}toDOMMatrix(){return new DOMMatrix([...this.data])}static identity(){const t=new ct;return t.data[0]=1,t.data[1]=0,t.data[2]=0,t.data[3]=0,t.data[4]=0,t.data[5]=1,t.data[6]=0,t.data[7]=0,t.data[8]=0,t.data[9]=0,t.data[10]=1,t.data[11]=0,t.data[12]=0,t.data[13]=0,t.data[14]=0,t.data[15]=1,t}reset(){const t=this;return t.data[0]=1,t.data[1]=0,t.data[2]=0,t.data[3]=0,t.data[4]=0,t.data[5]=1,t.data[6]=0,t.data[7]=0,t.data[8]=0,t.data[9]=0,t.data[10]=1,t.data[11]=0,t.data[12]=0,t.data[13]=0,t.data[14]=0,t.data[15]=1,t}static translation(t,e){const i=ct.identity();return i.data[12]=t,i.data[13]=e,i}static scale(t,e){const i=ct.identity();return i.data[0]=t,i.data[5]=e,i.data[10]=1,i.data[15]=1,i}static rotation(t){const e=ct.identity();return e.data[0]=Math.cos(t),e.data[4]=-Math.sin(t),e.data[1]=Math.sin(t),e.data[5]=Math.cos(t),e}multv(t){if(t instanceof A)return new A(t.x*this.data[0]+t.y*this.data[4]+0*this.data[6]+1*this.data[12],t.x*this.data[1]+t.y*this.data[5]+0*this.data[9]+1*this.data[13]);return[t[0]*this.data[0]+t[1]*this.data[4]+0*this.data[6]+1*this.data[12],t[0]*this.data[1]+t[1]*this.data[5]+0*this.data[9]+1*this.data[13]]}multm(t){const e=new ct,i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7],c=this.data[8],d=this.data[9],u=this.data[10],p=this.data[11],g=this.data[12],_=this.data[13],f=this.data[14],m=this.data[15],v=t.data[0],y=t.data[1],w=t.data[2],x=t.data[3],b=t.data[4],C=t.data[5],S=t.data[6],A=t.data[7],P=t.data[8],T=t.data[9],E=t.data[10],I=t.data[11],R=t.data[12],B=t.data[13],D=t.data[14],M=t.data[15];e.data[0]=i*v+o*y+c*w+g*x,e.data[1]=s*v+a*y+d*w+_*x,e.data[2]=r*v+h*y+u*w+f*x,e.data[3]=n*v+l*y+p*w+m*x,e.data[4]=i*b+o*C+c*S+g*A,e.data[5]=s*b+a*C+d*S+_*A,e.data[6]=r*b+h*C+u*S+f*A,e.data[7]=n*b+l*C+p*S+m*A,e.data[8]=i*P+o*T+c*E+g*I,e.data[9]=s*P+a*T+d*E+_*I,e.data[10]=r*P+h*T+u*E+f*I,e.data[11]=n*P+l*T+p*E+m*I,e.data[12]=i*R+o*B+c*D+g*M,e.data[13]=s*R+a*B+d*D+_*M,e.data[14]=r*R+h*B+u*D+f*M,e.data[15]=n*R+l*B+p*D+m*M;const k=this.getScale();return e._scaleSignX=L(k.x)*L(e._scaleSignX),e._scaleSignY=L(k.y)*L(e._scaleSignY),e}translate(t,e){const i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7],c=this.data[8],d=this.data[9],u=this.data[10],p=this.data[11],g=this.data[12],_=this.data[13],f=this.data[14],m=this.data[15];return this.data[12]=i*t+o*e+0*c+1*g,this.data[13]=s*t+a*e+0*d+1*_,this.data[14]=r*t+h*e+0*u+1*f,this.data[15]=n*t+l*e+0*p+1*m,this}setPosition(t,e){this.data[12]=t,this.data[13]=e}getPosition(){return P(this.data[12],this.data[13])}rotate(t){const e=this.data[0],i=this.data[1],s=this.data[2],r=this.data[3],n=this.data[4],o=this.data[5],a=this.data[6],h=this.data[7],l=Math.sin(t),c=Math.cos(t);return this.data[0]=c*e+l*n,this.data[1]=c*i+l*o,this.data[2]=c*s+l*a,this.data[3]=c*r+l*h,this.data[4]=c*n-l*e,this.data[5]=c*o-l*i,this.data[6]=c*a-l*s,this.data[7]=c*h-l*r,this}scale(t,e){const i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7];return this.data[0]=i*t,this.data[1]=s*t,this.data[2]=r*t,this.data[3]=n*t,this.data[4]=o*e,this.data[5]=a*e,this.data[6]=h*e,this.data[7]=l*e,this}setRotation(t){const e=this.getScale(),i=Math.sin(t),s=Math.cos(t);this.data[0]=s*e.x,this.data[1]=i*e.y,this.data[4]=-i*e.x,this.data[5]=s*e.y}getRotation(){return O(Math.atan2(this.data[1]/this.getScaleY(),this.data[0]/this.getScaleX()))}getScaleX(){const t=P(this.data[0],this.data[4]).size;return this._scaleSignX*t}getScaleY(){const t=P(this.data[1],this.data[5]).size;return this._scaleSignY*t}getScale(){return P(this.getScaleX(),this.getScaleY())}setScaleX(t){this._scaleSignX=L(t);const e=P(this.data[0]*this._scaleSignX,this.data[4]*this._scaleSignX).normalize();this.data[0]=e.x*t,this.data[4]=e.y*t}setScaleY(t){this._scaleSignY=L(t);const e=P(this.data[1]*this._scaleSignY,this.data[5]*this._scaleSignY).normalize();this.data[1]=e.x*t,this.data[5]=e.y*t}setScale(t){this.setScaleX(t.x),this.setScaleY(t.y)}getBasisDeterminant(){return this.data[0]*this.data[5]-this.data[1]*this.data[4]}getAffineInverse(t){const e=1/this.getBasisDeterminant(),i=this.data[0],s=this.data[4],r=this.data[1],n=this.data[5],o=t||ct.identity();o.data[0]=n*e,o.data[1]=-r*e,o.data[4]=-s*e,o.data[5]=i*e;const a=this.data[12],h=this.data[13];return o.data[12]=-(a*o.data[0]+h*o.data[4]),o.data[13]=-(a*o.data[1]+h*o.data[5]),o}isIdentity(){return 1===this.data[0]&&0===this.data[1]&&0===this.data[2]&&0===this.data[3]&&0===this.data[4]&&1===this.data[5]&&0===this.data[6]&&0===this.data[7]&&0===this.data[8]&&0===this.data[9]&&1===this.data[10]&&0===this.data[11]&&0===this.data[12]&&0===this.data[13]&&0===this.data[14]&&1===this.data[15]}toString(){return`\n[${this.data[0]} ${this.data[4]} ${this.data[8]} ${this.data[12]}]\n[${this.data[1]} ${this.data[5]} ${this.data[9]} ${this.data[13]}]\n[${this.data[2]} ${this.data[6]} ${this.data[10]} ${this.data[14]}]\n[${this.data[3]} ${this.data[7]} ${this.data[11]} ${this.data[15]}]\n`}}class dt{constructor(){this._transforms=[],this._currentTransform=ct.identity()}save(){this._transforms.push(this._currentTransform),this._currentTransform=this._currentTransform.clone()}restore(){this._currentTransform=this._transforms.pop()}translate(t,e){return this._currentTransform.translate(t,e)}rotate(t){return this._currentTransform.rotate(t)}scale(t,e){return this._currentTransform.scale(t,e)}set current(t){this._currentTransform=t}get current(){return this._currentTransform}}class ut{constructor(){this._states=[],this._currentState=this._getDefaultState()}_getDefaultState(){return{opacity:1}}_cloneState(){return{opacity:this._currentState.opacity}}save(){this._states.push(this._currentState),this._currentState=this._cloneState()}restore(){this._currentState=this._states.pop()}get current(){return this._currentState}}function pt(t,e){return t&&void 0===t.__isProxy?new Proxy(t,{set:(t,i,s)=>(t[i]!==s&&(t[i]=s,"string"==typeof i&&"_"!==i[0]&&e(t)),!0),get:(t,e)=>"__isProxy"===e||t[e]}):t}function gt(t,e){return t&&void 0===t.__isProxy?new Proxy(t,{set:(t,i,s)=>(t[i]=s,"string"==typeof i&&"_"!==i[0]&&e(t),!0),get:(t,e)=>"__isProxy"===e||t[e]}):t}class _t{constructor(t){var e,i,s,r,n,o;this.id=_t._ID++,this.transform=ct.identity(),this._transformStale=!0,this.showDebug=!1,this._flipHorizontal=!1,this._flipVertical=!1,this._rotation=0,this.opacity=1,this._scale=A.One,this._origin=null,this._width=0,this._height=0,t&&(this.origin=null!==(e=t.origin)&&void 0!==e?e:this.origin,this.flipHorizontal=null!==(i=t.flipHorizontal)&&void 0!==i?i:this.flipHorizontal,this.flipVertical=null!==(s=t.flipVertical)&&void 0!==s?s:this.flipVertical,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:this.rotation,this.opacity=null!==(n=t.opacity)&&void 0!==n?n:this.opacity,this.scale=null!==(o=t.scale)&&void 0!==o?o:this.scale)}isStale(){return this._transformStale}get flipHorizontal(){return this._flipHorizontal}set flipHorizontal(t){this._flipHorizontal=t,this._transformStale=!0}get flipVertical(){return this._flipVertical}set flipVertical(t){this._flipVertical=t,this._transformStale=!0}get rotation(){return this._rotation}set rotation(t){this._rotation=t,this._transformStale=!0}get scale(){return this._scale}set scale(t){this._scale=pt(t,(()=>{this._transformStale=!0})),this._transformStale=!0}get origin(){return this._origin}set origin(t){this._origin=pt(t,(()=>{this._transformStale=!0})),this._transformStale=!0}cloneGraphicOptions(){return{origin:this.origin?this.origin.clone():null,flipHorizontal:this.flipHorizontal,flipVertical:this.flipVertical,rotation:this.rotation,opacity:this.opacity,scale:this.scale?this.scale.clone():null}}get width(){return Math.abs(this._width*this.scale.x)}get height(){return Math.abs(this._height*this.scale.y)}set width(t){this._width=t,this._transformStale=!0}set height(t){this._height=t,this._transformStale=!0}get localBounds(){return B.fromDimension(this.width,this.height,A.Zero)}draw(t,e,i){this._preDraw(t,e,i),this._drawImage(t,0,0),this._postDraw(t)}_preDraw(t,e,i){t.save(),t.translate(e,i),this._transformStale&&(this.transform.reset(),this.transform.scale(Math.abs(this.scale.x),Math.abs(this.scale.y)),this._rotate(this.transform),this._flip(this.transform),this._transformStale=!1),t.multiply(this.transform),t.opacity=t.opacity*this.opacity}_rotate(t){var e;const i=this.scale.x>0?1:-1,s=this.scale.y>0?1:-1,r=null!==(e=this.origin)&&void 0!==e?e:P(this.width/2,this.height/2);t.translate(r.x,r.y),t.rotate(this.rotation),t.scale(i,s),t.translate(-r.x,-r.y)}_flip(t){this.flipHorizontal&&(t.translate(this.width/this.scale.x,0),t.scale(-1,1)),this.flipVertical&&(t.translate(0,this.height/this.scale.y),t.scale(1,-1))}_postDraw(t){this.showDebug&&t.debug.drawRect(0,0,this.width,this.height),t.restore()}}function ft(t){return 0==(t&t-1)}function mt(t){--t;for(let e=1;e<32;e<<=1)t|=t>>e;return t+1}function vt(t){return ft(t)?t:mt(t)}function yt(t,e){switch(e){case t.FLOAT:return 4;case t.SHORT:case t.UNSIGNED_SHORT:return 2;case t.BYTE:case t.UNSIGNED_BYTE:default:return 1}}function wt(t,e){switch(e){case t.LOW_FLOAT:case t.HIGH_FLOAT:case t.FLOAT:return 1;case t.FLOAT_VEC2:return 2;case t.FLOAT_VEC3:return 3;case t.FLOAT_VEC4:return 4;case t.BYTE:case t.UNSIGNED_BYTE:case t.UNSIGNED_SHORT:case t.SHORT:default:return 1}}function xt(t,e){switch(e){case t.LOW_FLOAT:case t.HIGH_FLOAT:case t.FLOAT:case t.FLOAT_VEC2:case t.FLOAT_VEC3:case t.FLOAT_VEC4:return t.FLOAT;case t.BYTE:return t.BYTE;case t.UNSIGNED_BYTE:return t.UNSIGNED_BYTE;case t.SHORT:return t.SHORT;case t.UNSIGNED_SHORT:return t.UNSIGNED_SHORT;default:return t.FLOAT}}_t._ID=0,function(t){t.Pixel="Pixel",t.Blended="Blended"}(ht||(ht={}));class bt{static register(t){bt._GL=t}static get(t){return bt._TEXTURE_MAP.get(t)}static has(t){return bt._TEXTURE_MAP.has(t)}static load(t,e,i=!1){const s=bt._GL;if(!s)return null;let r=null;if(bt.has(t)&&(r=bt.get(t)),r){if(i){s.bindTexture(s.TEXTURE_2D,r);const e=bt.toPowerOfTwoImage(t);s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,e)}return r}r=s.createTexture();const n=bt.toPowerOfTwoImage(t);s.bindTexture(s.TEXTURE_2D,r),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE);const o=null!=e?e:bt.filtering;return s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,o===ht.Pixel?s.NEAREST:s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,o===ht.Pixel?s.NEAREST:s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,n),bt._TEXTURE_MAP.set(t,r),r}static toPowerOfTwoImage(t){const e=bt._POT_CANVAS,i=bt._POT_CTX;return ft(t.width)&&ft(t.height)||(e.width=vt(t.width),e.height=vt(t.height),i.imageSmoothingEnabled=!1,i.clearRect(0,0,e.width,e.height),i.drawImage(t,0,0,t.width,t.height),t=e),t}}bt.filtering=ht.Blended,bt._POT_CANVAS=document.createElement("canvas"),bt._POT_CTX=bt._POT_CANVAS.getContext("2d"),bt._TEXTURE_MAP=new Map;class Ct extends _t{constructor(t){var e,i,s,r,n,o,a,h;super(t),this.filtering=null,this._dirty=!0,this._smoothing=!1,this._color=pt(I.Black,(()=>this.flagDirty())),this._lineWidth=1,this._lineDash=[],this._padding=0,t&&(this.color=null!==(e=t.color)&&void 0!==e?e:I.Black,this.strokeColor=null==t?void 0:t.strokeColor,this.smoothing=null!==(i=t.smoothing)&&void 0!==i?i:this.smoothing,this.lineWidth=null!==(s=t.lineWidth)&&void 0!==s?s:this.lineWidth,this.lineDash=null!==(r=t.lineDash)&&void 0!==r?r:this.lineDash,this.padding=null!==(n=t.padding)&&void 0!==n?n:this.padding,this.filtering=null!==(o=t.filtering)&&void 0!==o?o:this.filtering),this._bitmap=document.createElement("canvas");const l=null!==(a=null==t?void 0:t.width)&&void 0!==a?a:this._bitmap.width,c=null!==(h=null==t?void 0:t.height)&&void 0!==h?h:this._bitmap.height;this.width=vt(l),this.height=vt(c);const d=this._bitmap.getContext("2d");if(!d)throw new Error("Browser does not support 2d canvas drawing, cannot create Raster graphic");this._ctx=d}cloneRasterOptions(){return{color:this.color?this.color.clone():null,strokeColor:this.strokeColor?this.strokeColor.clone():null,smoothing:this.smoothing,lineWidth:this.lineWidth,lineDash:this.lineDash,padding:this.padding}}get dirty(){return this._dirty}flagDirty(){this._dirty=!0}get width(){return Math.abs(this._getTotalWidth()*this.scale.x)}set width(t){t/=Math.abs(this.scale.x),this._bitmap.width=t,this._originalWidth=t,this.flagDirty()}get height(){return Math.abs(this._getTotalHeight()*this.scale.y)}set height(t){t/=Math.abs(this.scale.y),this._bitmap.height=t,this._originalHeight=t,this.flagDirty()}_getTotalWidth(){var t;return(null!==(t=this._originalWidth)&&void 0!==t?t:this._bitmap.width)+2*this.padding}_getTotalHeight(){var t;return(null!==(t=this._originalHeight)&&void 0!==t?t:this._bitmap.height)+2*this.padding}get localBounds(){return B.fromDimension(this._getTotalWidth()*this.scale.x,this._getTotalHeight()*this.scale.y,A.Zero)}get smoothing(){return this._smoothing}set smoothing(t){this._smoothing=t,this.flagDirty()}get color(){return this._color}set color(t){this.flagDirty(),this._color=pt(t,(()=>this.flagDirty()))}get strokeColor(){return this._strokeColor}set strokeColor(t){this.flagDirty(),this._strokeColor=pt(t,(()=>this.flagDirty()))}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=t,this.flagDirty()}get lineDash(){return this._lineDash}set lineDash(t){this._lineDash=t,this.flagDirty()}get padding(){return this._padding}set padding(t){this._padding=t,this.flagDirty()}rasterize(){this._dirty=!1,this._ctx.clearRect(0,0,this._getTotalWidth(),this._getTotalHeight()),this._ctx.save(),this._applyRasterProperties(this._ctx),this.execute(this._ctx),this._ctx.restore(),bt.load(this._bitmap,this.filtering,!0)}_applyRasterProperties(t){var e,i,s;this._bitmap.width=this._getTotalWidth(),this._bitmap.height=this._getTotalHeight(),t.translate(this.padding,this.padding),t.imageSmoothingEnabled=this.smoothing,t.lineWidth=this.lineWidth,t.setLineDash(null!==(e=this.lineDash)&&void 0!==e?e:t.getLineDash()),t.strokeStyle=null===(i=this.strokeColor)||void 0===i?void 0:i.toString(),t.fillStyle=null===(s=this.color)||void 0===s?void 0:s.toString()}_drawImage(t,e,i){this._dirty&&this.rasterize(),t.drawImage(this._bitmap,e,i)}}class St extends Ct{constructor(t){super(t),this._options=t}get ctx(){return this._ctx}clone(){return new St({...this._options,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){var e,i;(null===(e=this._options)||void 0===e?void 0:e.draw)&&(null===(i=this._options)||void 0===i||i.draw(t)),this._options.cache||this.flagDirty()}}!function(t){t.Kill="kill",t.PreKill="prekill",t.PostKill="postkill",t.PreDraw="predraw",t.PostDraw="postdraw",t.PreDebugDraw="predebugdraw",t.PostDebugDraw="postdebugdraw",t.PreUpdate="preupdate",t.PostUpdate="postupdate",t.PreFrame="preframe",t.PostFrame="postframe",t.PreCollision="precollision",t.CollisionStart="collisionstart",t.CollisionEnd="collisionend",t.PostCollision="postcollision",t.Initialize="initialize",t.Activate="activate",t.Deactivate="deactivate",t.ExitViewport="exitviewport",t.EnterViewport="enterviewport",t.ExitTrigger="exit",t.EnterTrigger="enter",t.Connect="connect",t.Disconnect="disconnect",t.Button="button",t.Axis="axis",t.Subscribe="subscribe",t.Unsubscribe="unsubscribe",t.Visible="visible",t.Hidden="hidden",t.Start="start",t.Stop="stop",t.PointerUp="pointerup",t.PointerDown="pointerdown",t.PointerMove="pointermove",t.PointerEnter="pointerenter",t.PointerLeave="pointerleave",t.PointerCancel="pointercancel",t.PointerWheel="pointerwheel",t.Up="up",t.Down="down",t.Move="move",t.Enter="enter",t.Leave="leave",t.Cancel="cancel",t.Wheel="wheel",t.Press="press",t.Release="release",t.Hold="hold",t.PointerDragStart="pointerdragstart",t.PointerDragEnd="pointerdragend",t.PointerDragEnter="pointerdragenter",t.PointerDragLeave="pointerdragleave",t.PointerDragMove="pointerdragmove"}(lt||(lt={}));class At{constructor(){this._bubbles=!0}get bubbles(){return this._bubbles}set bubbles(t){this._bubbles=t}stopPropagation(){this.bubbles=!1}}class Pt extends At{constructor(t){super(),this.target=t}}class Tt extends At{constructor(t){super(),this.target=t}}class Et extends At{constructor(t){super(),this.target=t}}class It extends At{constructor(t){super(),this.target=t}}class Rt extends At{constructor(t){super(),this.target=t}}class Bt extends At{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class Dt extends At{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class Mt extends At{constructor(t,e){super(),this.ctx=t,this.target=e}}class kt extends At{constructor(t,e){super(),this.ctx=t,this.target=e}}class Ft extends At{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class Lt extends At{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class zt extends At{constructor(t,e){super(),this.engine=t,this.prevStats=e,this.target=t}}class Ot extends At{constructor(t,e){super(),this.engine=t,this.stats=e,this.target=t}}class Ut extends At{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Nt extends At{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Ht extends At{constructor(t,e,i){super(),this.button=t,this.value=e,this.target=i}}class Wt extends At{constructor(t,e,i){super(),this.axis=t,this.value=e,this.target=i}}class Vt extends At{constructor(t,e){super(),this.topic=t,this.handler=e}}class Gt extends At{constructor(t,e){super(),this.topic=t,this.handler=e}}class Xt extends At{constructor(t){super(),this.target=t}}class qt extends At{constructor(t){super(),this.target=t}}class jt extends At{constructor(t,e,i,s){super(),this.other=e,this.side=i,this.intersection=s,this.target=t}}class Kt extends At{constructor(t,e,i,s){super(),this.other=e,this.side=i,this.intersection=s,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class Yt{constructor(t,e,i){this.target=t,this.other=e,this.contact=i}}class Zt{constructor(t,e){this.target=t,this.other=e}}class Qt{constructor(t,e,i,s,r){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=r}}class $t{constructor(t,e,i,s,r){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=r}}class Jt extends At{constructor(t,e,i){super(),this.other=e,this.contact=i,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class te extends At{constructor(t,e){super(),this.other=e,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class ee extends At{constructor(t,e){super(),this.engine=t,this.target=e}}class ie extends At{constructor(t,e){super(),this.oldScene=t,this.target=e}}class se extends At{constructor(t,e){super(),this.newScene=t,this.target=e}}class re extends At{constructor(t){super(),this.target=t}}class ne extends At{constructor(t){super(),this.target=t}}class oe extends At{constructor(t,e){super(),this.target=t,this.actor=e}}class ae extends At{constructor(t,e){super(),this.target=t,this.actor=e}}class he{constructor(){this._handlers={},this._wiredEventDispatchers=[]}clear(){this._handlers={},this._wiredEventDispatchers=[]}emit(t,e){if(!t)return;let i,s;if(t=t.toLowerCase(),e||(e=new At),this._handlers[t])for(i=0,s=this._handlers[t].length;i<s;i++)this._handlers[t][i](e);for(i=0,s=this._wiredEventDispatchers.length;i<s;i++)this._wiredEventDispatchers[i].emit(t,e)}on(t,e){t=t.toLowerCase(),this._handlers[t]||(this._handlers[t]=[]),this._handlers[t].push(e),"unsubscribe"!==t&&"subscribe"!==t&&this.emit("subscribe",new Vt(t,e))}off(t,e){t=t.toLowerCase();const i=this._handlers[t];if(i)if(e){const s=i.indexOf(e);this._handlers[t].splice(s,1)}else this._handlers[t].length=0;"unsubscribe"!==t&&"subscribe"!==t&&this.emit("unsubscribe",new Gt(t,e))}once(t,e){this.on(t,(i=>{const s=i||new At;this.off(t,e),e(s)}))}wire(t){t._wiredEventDispatchers.push(this)}unwire(t){const e=t._wiredEventDispatchers.indexOf(this);e>-1&&t._wiredEventDispatchers.splice(e,1)}}class le{constructor(t,e,i=!0){this.path=t,this.responseType=e,this.bustCache=i,this.data=null,this.logger=f.getInstance(),this.events=new he}isLoaded(){return null!==this.data}_cacheBust(t){return/\?\w*=\w*/.test(t)?t+="&__="+Date.now():t+="?__="+Date.now(),t}load(){return new Promise(((t,e)=>{if(null!==this.data)return this.logger.debug("Already have data for resource",this.path),this.events.emit("complete",this.data),void t(this.data);const i=new XMLHttpRequest;i.open("GET",this.bustCache?this._cacheBust(this.path):this.path,!0),i.responseType=this.responseType,i.addEventListener("loadstart",(t=>this.events.emit("loadstart",t))),i.addEventListener("progress",(t=>this.events.emit("progress",t))),i.addEventListener("error",(t=>this.events.emit("error",t))),i.addEventListener("load",(t=>this.events.emit("load",t))),i.addEventListener("load",(()=>{if(0!==i.status&&200!==i.status)return this.logger.error("Failed to load resource ",this.path," server responded with error code",i.status),this.events.emit("error",i.response),void e(new Error(i.statusText));this.data=i.response,this.events.emit("complete",this.data),this.logger.debug("Completed loading resource",this.path),t(this.data)})),i.send()}))}}var ce=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let de=class{updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=(r[s+0]+r[s+1]+r[s+2])/3;r[s+0]=n,r[s+1]=n,r[s+2]=n}};de=ce([C({message:"Grayscale will be removed in v0.26.0"})],de);let ue=class{updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;r[s+0]=255-r[s+0],r[s+1]=255-r[s+1],r[s+2]=255-r[s+2]}};ue=ce([C({message:"Invert will be removed in v0.26.0"})],ue);let pe=class{constructor(t){this.opacity=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+3]=Math.round(this.opacity*r[s+3]))}};pe=ce([C({message:"Opacity will be removed in v0.26.0"})],pe);let ge=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+0]=(r[s+0]+this.color.r)/2,r[s+1]=(r[s+1]+this.color.g)/2,r[s+2]=(r[s+2]+this.color.b)/2)}};ge=ce([C({message:"Colorize will be removed in v0.26.0"})],ge);let _e=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).lighten(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};_e=ce([C({message:"Lighten will be removed in v0.26.0"})],_e);let fe=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).darken(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};fe=ce([C({message:"Darken will be removed v0.26.0"})],fe);let me=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).saturate(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};me=ce([C({message:"Saturate will be removed in v0.26.0"})],me);let ve=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).desaturate(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};ve=ce([C({message:"Desaturate will be removed in v0.26.0"})],ve);let ye=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+0]=this.color.r,r[s+1]=this.color.g,r[s+2]=this.color.b)}};ye=ce([C({message:"Fill will be removed in v0.26.0"})],ye);class we{constructor(t,e=!0){this.path=t,this.bustCache=e,this._sprite=null,this.loaded=new Promise((t=>{this._loadedResolve=t})),this._resource=new le(t,"blob",e),this._sprite=new Se(this,0,0,0,0)}get image(){return this.data}isLoaded(){return!!this.data}async load(){try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=await this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,await e.decode(),this.data=e,this.width=this._sprite.width=e.naturalWidth,this.height=this._sprite.height=e.naturalHeight,this._sprite=new Se(this,0,0,this.width,this.height)}catch(t){await Promise.reject("Error loading texture")}return this._loadedResolve(this.data),this.data}asSprite(){return this._sprite}}function xe(t){return class extends t{assign(t){for(const e in t)"function"!=typeof this[e]&&(this[e]=t[e])}constructor(...t){super(...t);1!==t.filter((function(t){return void 0!==t})).length||!t[0]||"object"!=typeof t[0]||t[0]instanceof Array||this.assign(t[0])}}}var be=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ce{constructor(t,e,i,s,r){this.x=0,this.y=0,this.rotation=0,this.anchor=A.Half,this.offset=A.Zero,this.scale=A.One,this.drawAroundAnchor=!1,this.logger=f.getInstance(),this.flipVertical=!1,this.flipHorizontal=!1,this.effects=[],this.width=0,this.height=0,this._spriteCanvas=null,this._spriteCtx=null,this._pixelData=null,this._pixelsLoaded=!1,this._dirtyEffect=!0,this._opacity=1;let n=t;if(t&&!(t instanceof we)&&(e=0|t.x,i=0|t.y,s=0|t.width,r=0|t.height,n=t.image,!n)){throw new Error("An image texture is required to construct a sprite")}this.x=e||0,this.y=i||0,this.texture=n,this._spriteCanvas=document.createElement("canvas"),this._spriteCanvas.width=s,this._spriteCanvas.height=r,this._spriteCtx=this._spriteCanvas.getContext("2d"),this._initPixelsFromTexture(),this.width=s,this.height=r}get drawWidth(){return Math.abs(this.width*this.scale.x)}get drawHeight(){return Math.abs(this.height*this.scale.y)}async _initPixelsFromTexture(){try{const t=await this.texture.loaded;this.width=this.width||t.naturalWidth,this.height=this.height||t.naturalHeight,this._spriteCanvas.width=this._spriteCanvas.width||t.naturalWidth,this._spriteCanvas.height=this._spriteCanvas.height||t.naturalHeight,this._loadPixels(),this._dirtyEffect=!0}catch(t){this.logger.error("Error loading texture ",this.texture.path,t)}}_loadPixels(){if(this.texture.isLoaded()&&!this._pixelsLoaded){const t=this.texture.image.naturalWidth||0,e=this.texture.image.naturalHeight||0;if(this.width>t&&this.logger.warn(`The sprite width ${this.width} exceeds the width \n ${t} of the backing texture ${this.texture.path}`),this.width<=0||t<=0)throw new Error(`The width of a sprite cannot be 0 or negative, sprite width: ${this.width}, original width: ${t}`);if(this.height>e&&this.logger.warn(`The sprite height ${this.height} exceeds the height \n ${e} of the backing texture ${this.texture.path}`),this.height<=0||e<=0)throw new Error(`The height of a sprite cannot be 0 or negative, sprite height: ${this.height}, original height: ${e}`);this._flushTexture(),this._pixelsLoaded=!0}}_flushTexture(){const t=this.texture.image.naturalWidth||0,e=this.texture.image.naturalHeight||0;this._spriteCtx.clearRect(0,0,this.width,this.height),this._spriteCtx.drawImage(this.texture.image,z(this.x,0,t),z(this.y,0,e),z(this.width,0,t),z(this.height,0,e),0,0,this.width,this.height)}opacity(t){this._opacity=t}grayscale(){this.addEffect(new de)}invert(){this.addEffect(new ue)}fill(t){this.addEffect(new ye(t))}colorize(t){this.addEffect(new ge(t))}lighten(t=.1){this.addEffect(new _e(t))}darken(t=.1){this.addEffect(new fe(t))}saturate(t=.1){this.addEffect(new me(t))}desaturate(t=.1){this.addEffect(new ve(t))}addEffect(t){this.effects.push(t),this.texture.isLoaded()&&this._pixelsLoaded?this._applyEffects():this._dirtyEffect=!0}removeEffect(t){let e=-1;e="number"==typeof t?t:this.effects.indexOf(t),e<0||e>=this.effects.length||(this.effects.splice(e,1),this.texture.isLoaded()&&this._pixelsLoaded?this._applyEffects():this._dirtyEffect=!0)}_applyEffects(){if(this._flushTexture(),this.effects.length>0){this._pixelData=this._spriteCtx.getImageData(0,0,this.width,this.height);const t=this.effects.length;for(let e=0;e<t;e++)for(let t=0;t<this.height;t++)for(let i=0;i<this.width;i++)this.effects[e].updatePixel(i,t,this._pixelData);this._spriteCtx.clearRect(0,0,this.width,this.height),this._spriteCtx.putImageData(this._pixelData,0,0)}this._dirtyEffect=!1}clearEffects(){this.effects.length=0,this._applyEffects()}reset(){}debugDraw(t,e,i){t.save(),t.translate(e,i),t.rotate(this.rotation);const s=this.drawWidth*this.anchor.x,r=this.drawHeight*this.anchor.y;t.strokeStyle=I.Black.toString(),t.strokeRect(-s,-r,this.drawWidth,this.drawHeight),t.restore()}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:v,flipHorizontal:y,flipVertical:w}={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.width,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.height,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,offset:null!==(a=t.offset)&&void 0!==a?a:this.offset,opacity:(null!==(h=t.opacity)&&void 0!==h?h:1)*(null!==(l=this._opacity)&&void 0!==l?l:1)};this._dirtyEffect&&this._applyEffects();const x=g*f.x+m.x,b=_*f.y+m.y,C=this.scale.x>0?1:-1,S=this.scale.y>0?1:-1;c.save(),c.translate(d,u),c.scale(Math.abs(this.scale.x),Math.abs(this.scale.y)),this.drawAroundAnchor&&c.translate(-x,-b),c.translate(x,b),c.rotate(p),c.scale(C,S),c.translate(-x,-b),y&&(c.translate(g,0),c.scale(-1,1)),w&&(c.translate(0,_),c.scale(1,-1));const A=c.globalAlpha;c.globalAlpha=v,c.drawImage(this._spriteCanvas,0,0,this.width,this.height,0,0,this.width,this.height),c.globalAlpha=A,c.restore()}clone(){const t=new Se(this.texture,this.x,this.y,this.width,this.height);t.anchor=this.anchor.clone(),t.scale=this.scale.clone(),t.rotation=this.rotation,t.flipHorizontal=this.flipHorizontal,t.flipVertical=this.flipVertical;const e=this.effects.length;for(let i=0;i<e;i++)t.addEffect(this.effects[i]);return t}}let Se=class extends(xe(Ce)){constructor(t,e,i,s,r){super(t,e,i,s,r)}};Se=be([C({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Se);class Ae extends _t{constructor(t){var e,i;super(t),this._dirty=!0,this.image=t.image;const{width:s,height:r}=t;this.sourceView=null!==(e=t.sourceView)&&void 0!==e?e:{x:0,y:0,width:null!=s?s:0,height:null!=r?r:0},this.destSize=null!==(i=t.destSize)&&void 0!==i?i:{width:null!=s?s:0,height:null!=r?r:0},this._updateSpriteDimensions(),this.image.ready.then((()=>{this._updateSpriteDimensions()}))}static from(t){return new Ae({image:t})}get width(){return Math.abs(this.destSize.width*this.scale.x)}get height(){return Math.abs(this.destSize.height*this.scale.y)}set width(t){t/=Math.abs(this.scale.x),this.destSize.width=t,super.width=Math.ceil(this.destSize.width)}set height(t){t/=Math.abs(this.scale.y),this.destSize.height=t,super.height=Math.ceil(this.destSize.height)}_updateSpriteDimensions(){var t,e,i,s,r,n;const{width:o,height:a}=this.image;this.sourceView.width=(null===(t=this.sourceView)||void 0===t?void 0:t.width)||o,this.sourceView.height=(null===(e=this.sourceView)||void 0===e?void 0:e.height)||a,this.destSize.width=(null===(i=this.destSize)||void 0===i?void 0:i.width)||(null===(s=this.sourceView)||void 0===s?void 0:s.width)||o,this.destSize.height=(null===(r=this.destSize)||void 0===r?void 0:r.height)||(null===(n=this.sourceView)||void 0===n?void 0:n.height)||a,this.width=Math.ceil(this.destSize.width)*this.scale.x,this.height=Math.ceil(this.destSize.height)*this.scale.y}_preDraw(t,e,i){this.image.isLoaded()&&this._dirty&&(this._dirty=!1,this._updateSpriteDimensions()),super._preDraw(t,e,i)}_drawImage(t,e,i){this.image.isLoaded()&&t.drawImage(this.image.image,this.sourceView.x,this.sourceView.y,this.sourceView.width,this.sourceView.height,e,i,this.destSize.width,this.destSize.height)}static fromLegacySprite(t){const e=t.texture,i=Pe.fromLegacyTexture(e);return new Ae({image:i,sourceView:{x:t.x,y:t.y,width:t.width,height:t.height}})}static toLegacySprite(t){const e=t.image,i=new we(e.path);return i.data=e.image,new Se(i,t.sourceView.x,t.sourceView.y,t.sourceView.width,t.sourceView.height)}clone(){return new Ae({image:this.image,sourceView:{...this.sourceView},destSize:{...this.destSize},...this.cloneGraphicOptions()})}}class Pe{constructor(t,e=!1,i){this.path=t,this._logger=f.getInstance(),this.data=new Image,this._resource=new le(t,"blob",e),this._filtering=i,(t.endsWith(".svg")||t.endsWith(".gif"))&&this._logger.warn(`Image type is not fully supported, you may have mixed results ${t}. Fully supported: jpg, bmp, and png`),this.ready=new Promise((t=>{this._loadedResolve=t}))}get width(){return this.image.naturalWidth}get height(){return this.image.naturalHeight}isLoaded(){return this._src||(this._src=this.data.src),!!this._src}get image(){return this.data}async load(){if(this.isLoaded())return this.data;try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=await this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,await e.decode(),this.data=e}catch(t){throw`Error loading ImageSource from path '${this.path}' with error [${t.message}]`}return bt.load(this.data,this._filtering),this._loadedResolve(this.data),this.data}toSprite(){return Ae.from(this)}static fromLegacyTexture(t){const e=new Pe(t.path);return t.isLoaded()?e.data=t.data:t.loaded.then((()=>{e.data=t.data})),e}unload(){this.data=new Image}}var Te=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ee{constructor(t,e,i,s){this.sprites=[],this.currentFrame=0,this._timeLeftInFrame=0,this._idempotencyToken=-1,this.anchor=A.Zero,this.rotation=0,this.scale=A.One,this.loop=!0,this.freezeFrame=-1,this.flipVertical=!1,this.flipHorizontal=!1,this.drawWidth=0,this.drawHeight=0,this.width=0,this.height=0,this._opacity=1;let r=t;if(t&&!(t instanceof xn)){const n=t;r=n.engine,e=n.sprites,i=n.speed,s=n.loop}this.sprites=e,this.speed=i,this._engine=r,this._timeLeftInFrame=this.speed,null!=s&&(this.loop=s),e&&e[0]&&(this.drawHeight=e[0]?e[0].drawHeight:0,this.drawWidth=e[0]?e[0].drawWidth:0,this.width=e[0]?e[0].width:0,this.height=e[0]?e[0].height:0,this.freezeFrame=e.length-1)}opacity(t){this._opacity=t}grayscale(){this.addEffect(new de)}invert(){this.addEffect(new ue)}fill(t){this.addEffect(new ye(t))}colorize(t){this.addEffect(new ge(t))}lighten(t=.1){this.addEffect(new _e(t))}darken(t=.1){this.addEffect(new fe(t))}saturate(t=.1){this.addEffect(new me(t))}desaturate(t=.1){this.addEffect(new ve(t))}addEffect(t){for(const e in this.sprites)this.sprites[e].addEffect(t)}removeEffect(t){for(const e in this.sprites)this.sprites[e].removeEffect(t)}clearEffects(){for(const t in this.sprites)this.sprites[t].clearEffects()}_setAnchor(t){for(const e in this.sprites)this.sprites[e].anchor.setTo(t.x,t.y)}_setRotation(t){for(const e in this.sprites)this.sprites[e].rotation=t}_setScale(t){for(const e in this.sprites)this.sprites[e].scale=t}reset(){this.currentFrame=0}isDone(){return!this.loop&&this.currentFrame>=this.sprites.length}tick(t,e){if(this._idempotencyToken===e)return;this._idempotencyToken=e,this._timeLeftInFrame-=t,this._timeLeftInFrame<=0&&(this.currentFrame=this.loop?(this.currentFrame+1)%this.sprites.length:this.currentFrame+1,this._timeLeftInFrame=this.speed),this._updateValues();const i=this.sprites[this.currentFrame];i&&(this.width=i.width,this.height=i.height,this.drawWidth=i.drawWidth,this.drawHeight=i.drawHeight)}_updateValues(){this._setAnchor(this.anchor),this._setRotation(this.rotation),this._setScale(this.scale)}skip(t){this.currentFrame=(this.currentFrame+t)%this.sprites.length}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h;const l={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.drawWidth,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.drawHeight,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,opacity:(null!==(a=t.opacity)&&void 0!==a?a:1)*(null!==(h=this._opacity)&&void 0!==h?h:1)};let c;this._updateValues(),this.currentFrame<this.sprites.length&&(c=this.sprites[this.currentFrame],c.draw(l)),-1!==this.freezeFrame&&this.currentFrame>=this.sprites.length&&(c=this.sprites[z(this.freezeFrame,0,this.sprites.length-1)],c.draw(l)),c&&(this.drawWidth=c.drawWidth,this.drawHeight=c.drawHeight)}play(t,e){this.reset(),this._engine.playAnimation(this,t,e)}}let Ie=class extends(xe(Ee)){constructor(t,e,i,s){super(t,e,i,s)}};var Re,Be,De,Me,ke;Ie=Te([C({message:"Animation will be removed in v0.26.0",alternateMethod:"Use Graphics.Animation"})],Ie),function(t){t.Em="em",t.Rem="rem",t.Px="px",t.Pt="pt",t.Percent="%"}(Re||(Re={})),function(t){t.Left="left",t.Right="right",t.Center="center",t.Start="start",t.End="end"}(Be||(Be={})),function(t){t.Top="top",t.Hanging="hanging",t.Middle="middle",t.Alphabetic="alphabetic",t.Ideographic="ideographic",t.Bottom="bottom"}(De||(De={})),function(t){t.Normal="normal",t.Italic="italic",t.Oblique="oblique"}(Me||(Me={})),function(t){t.LeftToRight="ltr",t.RightToLeft="rtl"}(ke||(ke={}));var Fe=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Le{constructor(t,e,i,s,r,n){this._sprites=[],this._image=null,this._columns=0,this._rows=0,this._spWidth=0,this._spHeight=0,this._spacing=0;let o=!1;if(t instanceof Array?this._sprites=t:(!t||t instanceof we?(this._image=t,this._columns=e,this._rows=i,this._spWidth=s,this._spHeight=r,this._spacing=n||0):(this._columns=t.columns,this._rows=t.rows,this._spWidth=t.spWidth,this._spHeight=t.spHeight,this._image=t.image,this._spacing=t.spacing||0),this._sprites=new Array(this._columns*this._rows),o=!0),this.image instanceof we){let t=!1,e=!1;if(this.image.isLoaded()){if(t=this.spWidth*this.columns>this.image.image.naturalWidth,e=this.spHeight*this.rows>this.image.image.naturalHeight,t)throw new RangeError(`SpriteSheet specified is wider, ${this.columns} cols x ${this.spWidth} pixels > ${this.image.image.naturalWidth} pixels than image width`);if(e)throw new RangeError(`SpriteSheet specified is taller, ${this.rows} rows x ${this.spHeight} pixels > ${this.image.image.naturalHeight} pixels than image height`)}}if(o){const t=this.getSpacingDimensions();for(let e=0;e<this.rows;e++)for(let i=0;i<this.columns;i++)this._sprites[i+e*this.columns]=new Se(this.image,i*this.spWidth+t.margin*i+t.left,e*this.spHeight+t.margin*e+t.top,this.spWidth,this.spHeight)}}get spacing(){return this._spacing}get sprites(){return[...this._sprites]}get image(){return this._image}get columns(){return this._columns}get rows(){return this._rows}get spWidth(){return this._spWidth}get spHeight(){return this._spHeight}getSpacingDimensions(){var t,e,i;return"number"==typeof this.spacing?{left:this.spacing,top:this.spacing,margin:this.spacing}:{left:null!==(t=this.spacing.left)&&void 0!==t?t:0,top:null!==(e=this.spacing.top)&&void 0!==e?e:0,margin:null!==(i=this.spacing.margin)&&void 0!==i?i:0}}getAnimationByIndices(t,e,i){let s=e.map((t=>this.sprites[t]));return s=s.map((function(t){return t.clone()})),new Ie(t,s,i)}getAnimationBetween(t,e,i,s){let r=this.sprites.slice(e,i);return r=r.map((function(t){return t.clone()})),new Ie(t,r,s)}getAnimationForAll(t,e){const i=this.sprites.map((function(t){return t.clone()}));return new Ie(t,i,e)}getSprite(t){if(t>=0&&t<this.sprites.length)return this.sprites[t];throw new Error("Invalid index: "+t)}getAnimationByCoords(t,e,i){let s=0,r=0;const n=new Array(e.length);for(let t=0;t<e.length;t++){const i=e[t];i.image=i.image||this.image,s=Math.max(s,i.drawWidth),r=Math.max(r,i.drawHeight),n[t]=new Se(i)}const o=new Ie(t,n,i);return o.drawWidth=s,o.drawHeight=r,o}}let ze=class extends Le{constructor(t,e,i,s,r,n,o,a){super(t instanceof we?{image:t,spWidth:n,spHeight:o,rows:r,columns:s,spacing:a||0}:t),this._currentColor=I.Black,this._currentOpacity=1,this._spriteRecord={},this._textShadowOn=!1,this._textShadowDirty=!0,this._textShadowColor=I.Black,this._textShadowSprites={},this._shadowOffsetX=5,this._shadowOffsetY=5,!t||t instanceof we||(e=t.alphabet,i=t.caseInsensitive),this.alphabet=e,this.caseInsensitive=i,this._spriteRecord=this.getTextSprites()}getTextSprites(){const t={};for(let e=0;e<this.alphabet.length;e++){let i=this.alphabet[e];this.caseInsensitive&&(i=i.toLowerCase()),t[i]=this.sprites[e].clone()}return t}setTextShadow(t,e,i){this._textShadowOn=!0,this._shadowOffsetX=t,this._shadowOffsetY=e,this._textShadowColor=i.clone(),this._textShadowDirty=!0;for(const t in this._spriteRecord)this._textShadowSprites[t]=this._spriteRecord[t].clone()}useTextShadow(t){this._textShadowOn=t,t&&this.setTextShadow(5,5,this._textShadowColor)}draw(t,e,i,s,r){if(r=this._parseOptions(r),this._currentColor.toString()!==r.color.toString()||this._currentOpacity!==r.opacity){this._currentOpacity=r.opacity,this._currentColor=r.color;for(const t in this._spriteRecord)this._spriteRecord[t].clearEffects(),this._spriteRecord[t].fill(r.color),this._spriteRecord[t].opacity(r.opacity)}if(this._textShadowOn&&this._textShadowDirty&&this._textShadowColor){for(const t in this._textShadowSprites)this._textShadowSprites[t].clearEffects(),this._textShadowSprites[t].addEffect(new ye(this._textShadowColor.clone()));this._textShadowDirty=!1}const n=this.sprites[0],o=n.height,a=r.fontSize/o,h=e.length*n.width*a+e.length*r.letterSpacing;let l=i;r.textAlign===Be.Left||r.textAlign===Be.Start?l=i:r.textAlign===Be.Right||r.textAlign===Be.End?l=i-h:r.textAlign===Be.Center&&(l=i-h/2);let c=s-o*a;r.baseAlign===De.Top||r.baseAlign===De.Hanging?c=s:r.baseAlign===De.Ideographic||r.baseAlign===De.Bottom||r.baseAlign===De.Alphabetic?c=s-o*a:r.baseAlign===De.Middle&&(c=s-o*a/2);for(let i=0;i<e.length;i++){let s=e[i];this.caseInsensitive&&(s=s.toLowerCase());try{this._textShadowOn&&(this._textShadowSprites[s].drawAroundAnchor=!1,this._textShadowSprites[s].scale=P(a,a),this._textShadowSprites[s].draw(t,l+this._shadowOffsetX,c+this._shadowOffsetY));const e=this._spriteRecord[s];e.drawAroundAnchor=!1,e.scale=P(a,a),e.draw(t,l,c),l+=e.drawWidth+r.letterSpacing}catch(t){f.getInstance().error(`SpriteFont Error drawing char ${s}`)}}}_parseOptions(t){return{fontSize:t.fontSize||10,letterSpacing:t.letterSpacing||0,color:t.color||I.Black,textAlign:void 0===typeof t.textAlign?Be.Left:t.textAlign,baseAlign:void 0===typeof t.baseAlign?De.Bottom:t.baseAlign,maxWidth:t.maxWidth||-1,opacity:t.opacity||0}}};ze=Fe([C({message:"SpriteSheet will be removed in v0.26.0",alternateMethod:"Use Graphics.SpriteSheet"})],ze);class Oe{constructor(t){this._logger=f.getInstance(),this.sprites=[];const{sprites:e,rows:i,columns:s}=t;this.sprites=e,this.rows=null!=i?i:1,this.columns=null!=s?s:this.sprites.length}getSprite(t,e){if(t>=this.columns||t<0)return this._logger.warn(`No sprite exists in the SpriteSheet at (${t}, ${e}), x: ${t} should be between 0 and ${this.columns-1}`),null;if(e>=this.rows||e<0)return this._logger.warn(`No sprite exists in the SpriteSheet at (${t}, ${e}), y: ${e} should be between 0 and ${this.rows-1}`),null;const i=t+e*this.columns;return this.sprites[i]}static fromLegacySpriteSheet(t){const e=t.sprites.map((t=>Ae.fromLegacySprite(t)));return new Oe({sprites:e})}static toLegacySpriteSheet(t){const e=t.sprites.map((t=>Ae.toLegacySprite(t)));return new Le(e)}static fromImageSource(t){var e;const i=[];t.spacing=null!==(e=t.spacing)&&void 0!==e?e:{};const{image:s,grid:{rows:r,columns:n,spriteWidth:o,spriteHeight:a},spacing:{originOffset:h,margin:l}}=t,c={x:0,y:0,...h},d={x:0,y:0,...l};for(let t=0;t<n;t++)for(let e=0;e<r;e++)i[t+e*n]=new Ae({image:s,sourceView:{x:t*o+d.x*t+c.x,y:e*a+d.y*e+c.y,width:o,height:a},destSize:{height:a,width:o}});return new Oe({sprites:i,rows:r,columns:n})}}class Ue extends _t{constructor(t){super(t),this._text="",this.alphabet="",this.shadow=null,this.caseInsensitive=!1,this.spacing=0,this._logger=f.getInstance(),this._alreadyWarnedAlphabet=!1,this._alreadyWarnedSpriteSheet=!1;const{alphabet:e,spriteSheet:i,caseInsensitive:s,spacing:r,shadow:n}=t;this.alphabet=e,this.spriteSheet=i,this.caseInsensitive=null!=s?s:this.caseInsensitive,this.spacing=null!=r?r:this.spacing,this.shadow=null!=n?n:this.shadow}static fromLegacySpriteFont(t){const e=t.sprites.map(Ae.fromLegacySprite);return new Ue({alphabet:t.alphabet,spacing:0,caseInsensitive:t.caseInsensitive,spriteSheet:new Oe({sprites:e})})}_getCharacterSprites(t){const e=[],i=this.caseInsensitive?t.toLocaleLowerCase():t,s=this.caseInsensitive?this.alphabet.toLocaleLowerCase():this.alphabet;for(let t=0;t<i.length;t++){const r=i[t];let n=s.indexOf(r);-1===n&&(n=0,this._alreadyWarnedAlphabet||(this._logger.warn(`SpriteFont - Cannot find letter '${r}' in configured alphabet '${s}'.`),this._logger.warn("There maybe be more issues in the SpriteFont configuration. No additional warnings will be logged."),this._alreadyWarnedAlphabet=!0));const o=this.spriteSheet.sprites[n];o?e.push(o):this._alreadyWarnedSpriteSheet||(this._logger.warn(`SpriteFont - Cannot find sprite for '${r}' at index '${n}' in configured SpriteSheet`),this._logger.warn("There maybe be more issues in the SpriteFont configuration. No additional warnings will be logged."),this._alreadyWarnedSpriteSheet=!0)}return e}measureText(t){const e=t.split("\n"),i=e.reduce(((t,e)=>t.length>e.length?t:e)),s=this._getCharacterSprites(i);let r=0,n=0;for(const t of s)r+=t.width+this.spacing,n=Math.max(n,t.height);return B.fromDimension(r,n*e.length,A.Zero)}_drawImage(t,e,i){let s=0,r=0,n=0;const o=this._text.split("\n");for(const a of o){for(const o of this._getCharacterSprites(a))o.draw(t,e+s,i+r),s+=o.width+this.spacing,n=Math.max(n,o.height);s=0,r+=n}}render(t,e,i,s,r){this._text=e;const n=this.measureText(e);this.width=n.width,this.height=n.height,this.shadow&&(t.save(),t.translate(this.shadow.offset.x,this.shadow.offset.y),this.draw(t,s,r),t.restore()),this.draw(t,s,r)}clone(){return new Ue({alphabet:this.alphabet,spriteSheet:this.spriteSheet,spacing:this.spacing})}}class Ne{constructor(){this.fontSheet="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAwCAYAAAD+f6R/AAAAAXNSR0IArs4c6QAABcJJREFUeJztnemu7CgMhGE07//KmT9NhrAFVzkQndQntXRP3/bCZkwCSQhCCCGEEEIIIYQQQog/TRz953Ecx/nDGIe/vdNhlc9tIz605Fk/ZmWfsO1hn9Gxuv1KHbvb3iL/VN+d1WORbyr7yR/5b9M4vjNeqko6jPJHq5wGHU151o9J2Udse9hndCxuv0rH7rY3yD/Wdyf13MrnQeDfkZIUSGKM4ff3cWN82pEZuTyQGX2IxeyR63va//8VNCYCq+1yEkLtWyagXv1P1r1H+110gP3PzT4gT8uW/mdQ8mUG8E9DqOz4MS9ICKGbXpS2BpnIrRzYeS96cll08INlCMl2/glzdcfazuuPqQO03lmqrBHsf272Q6NODXj6zzZIJd/LAHYTg3Mays5gBi7ZR27fOgs0yj8rm36DLMFiPgkAdXHKOwUQeMCQ/adSh/qBQrT/tPxbAwA9+DOZEILPAATSuHMgTv7+Auk/df2lHPCZLvMSLJe34LkEQ9PwXF1SRTllMYgvIaflqyVAjLGbsiCDcOK76jflxZ+sINPyROc5071yKWK5CJTV3dMp6+tBlyCtNlhAq/+XbWoBDcRNXYBMzD4VvQygSuPYC2jGGaSSOxXfy3dTUEsanIvNeepm38N/hssSALTPZnAXfwIYRJn2b7UBcw0FKX+nDdAMpm2j9WVnxrUa7TXaVAca/B+TgaAVh6R/rH0P/5m01dt/RLYViJn+w/bhVX2P7f/duqom5qb02pRLCLGIMgBU1wCEEN9BAUCID6MAIMSHUQAQ4sMoAAjxYRQAhPgwd1uB0fuZ7H3cnn2P+9mr/Pe4B8/eB/fwP4eRtci/0f6OfTCPt/9oHwC6G6y19RHZDumxmwzR4eE/s/2Tte/q/+XLdc9DeJ19diesQc/j7Z8fCe4tAS4CxZ7sp7eiJi7HiZmjmOTGJs+93CbS3nP0XIPH3vW8/qz6QPnX2QdsV/1uw/iZYvg8ACeHd28rpPzfNfhL+7vkw/4Ou9s+Onhbv91elpKZ48Dl6bzpwwibHigRArf+Ptk9+L3Y1Q5OB4LgCeSBw1iuB3GeJh1/HrX/zF0A9Mk+u45zMkc3r4rWPomma5+p/514LB+Zo93MErJ1JHxXPzByGa/licRYVKbpeQCoQ6Q8yxuCwJF9IPsoDkHAo/3Tx26cvA4EtJ/n04w8QOq/mrR7ddfLAC5BYFNlVI/0CnOVUflOpvJUQMx9AIMIW/nWDM67/qw0+95v9goBqD9j+72u/KD9U89IbnQbMIR2Zbneh5zUY7Hdk7XIP3UffVb+r+wDYAZLq+1n1+C7y3/ny2r7p5yeByDEh9HzAIQQJwoAQnwYBQAhPowCgBBjoNu3hNxSFACE6INuKvPajPZ4EFEAEKINcybGYzOd247WEd3TgA2jlmjEyrd+j9hvfVbD2PWQ3ZmGlu2HyO8og8eBuNUvNYWoDgMVpwHTJoLWdz1Y+ZYOy5uF7t6PPruZxANrud1lQXkP0jsGz/Yz+vGGMuygFyhSPcJnc1pMnQZElc+cRnoAlxdTvoDuK7puqF7uCQy+3fyFMiA02/vJQHh7DQDogMPTSGFNA56HTzbZ9yAfBOb1Zyo3qGM3MfMZ3f76huXf6xlmAHknMlLNXsBBBvbljIz9Uyz5Y5TzIBLR/qy/rNyrZ8+L/0BZ0m+tgXD0OK5XZxC/9P7I/g4hVFvzXf1/6i5A7+3AlijMPBLMZfCvuAp7A9rY56ApHitmLQc7c8bOv6ftAxlM9Xp35nkEK7nJetBsaMhtAAAuOLQGXwhh2dXQnn1rZ/a42BI3dL7L+jkFAbQddwdA9Ah35yMKhgEgVT46EFh5D4jz+OgavNKxeBCd1wDSJ/97oR8eoJkLi9t9/BDgDHTJ5NE7Dnzechh914OVv9M1K9PCqsfqb88XVg9qN9lm6nG176UPu+zn17GOxuO0vOWEEC/j+LFKTgghlvEfYJaLS+SA2O0AAAAASUVORK5CYII=",this.size=16,this.load()}load(){return this._imageSource=new Pe(this.fontSheet),this._imageSource.load().then((()=>{this._spriteSheet=Oe.fromImageSource({image:this._imageSource,grid:{rows:3,columns:16,spriteWidth:16,spriteHeight:16}}),this._spriteFont=new Ue({alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,!'&.\"?-()+ ",caseInsensitive:!0,spriteSheet:this._spriteSheet,spacing:-6})}))}write(t,e,i){this._imageSource.isLoaded()&&this._spriteFont.render(t,e,null,i.x,i.y)}}class He{constructor(t,e){this._gl=t,this._texture=e}use(){const t=this._gl;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._texture)}disable(){const t=this._gl;t.bindTexture(t.TEXTURE_2D,null)}}class We{constructor(t){this.width=t.width,this.height=t.height,this._gl=t.gl,this._setupFramebuffer()}setResolution(t,e){const i=this._gl;this.width=t,this.height=e,i.bindTexture(i.TEXTURE_2D,this._frameTexture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.width,this.height,0,i.RGBA,i.UNSIGNED_BYTE,null)}get frameBuffer(){return this._frameBuffer}get frameTexture(){return this._frameTexture}_setupFramebuffer(){const t=this._gl;this._frameTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._frameTexture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.width,this.height,0,t.RGBA,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE);const e=t.COLOR_ATTACHMENT0;this._frameBuffer=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,this._frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,e,t.TEXTURE_2D,this._frameTexture,0),this.disable()}toRenderSource(){return new He(this._gl,this._frameTexture)}use(){const t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,this._frameBuffer),t.viewport(0,0,this.width,this.height)}disable(){const t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,null)}}class Ve{static clear(){Ve._GL=null}static register(t){Ve._GL=t}static get gl(){if(!Ve._GL)throw Error("Attempted gl access before init");return Ve._GL}}class Ge{constructor(t){this._gl=Ve.gl,this.uniforms={},this.attributes={},this._compiled=!1;const{vertexSource:e,fragmentSource:i}=t;this.vertexSource=e,this.fragmentSource=i}get compiled(){return this._compiled}use(){this._gl.useProgram(this.program),Ge._ACTIVE_SHADER_INSTANCE=this}isCurrentlyBound(){return Ge._ACTIVE_SHADER_INSTANCE===this}compile(){const t=this._gl,e=this._compileShader(t,this.vertexSource,t.VERTEX_SHADER),i=this._compileShader(t,this.fragmentSource,t.FRAGMENT_SHADER);this.program=this._createProgram(t,e,i);const s=this.getAttributes();for(const t of s)this.attributes[t.name]=t;const r=this.getUniforms();for(const t of r)this.uniforms[t.name]=t;return this._compiled=!0,this.program}getUniforms(){const t=this._gl,e=t.getProgramParameter(this.program,t.ACTIVE_UNIFORMS),i=[];for(let s=0;s<e;s++){const e=t.getActiveUniform(this.program,s),r=t.getUniformLocation(this.program,e.name);i.push({name:e.name,glType:e.type,location:r})}return i}getAttributes(){const t=this._gl,e=t.getProgramParameter(this.program,t.ACTIVE_ATTRIBUTES),i=[];for(let s=0;s<e;s++){const e=t.getActiveAttrib(this.program,s),r=t.getAttribLocation(this.program,e.name);i.push({name:e.name,glType:xt(t,e.type),size:wt(t,e.type),location:r,normalized:!1})}return i}setTexture(t,e){const i=this._gl;i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e)}setUniformInt(t,e){this.setUniform("uniform1i",t,~~e)}setUniformIntArray(t,e){this.setUniform("uniform1iv",t,e)}setUniformBoolean(t,e){this.setUniform("uniform1i",t,e?1:0)}setUniformFloat(t,e){this.setUniform("uniform1f",t,e)}setUniformFloatArray(t,e){this.setUniform("uniform1fv",t,e)}setUniformFloatVector(t,e){this.setUniform("uniform2f",t,e.x,e.y)}setUniformMatrix(t,e){this.setUniform("uniformMatrix4fv",t,!1,e.data)}setUniform(t,e,...i){if(!this._compiled)throw Error(`Must compile shader before setting a uniform ${t}:${e}`);if(!this.isCurrentlyBound())throw Error("Currently accessed shader instance is not the current active shader in WebGL, must call `shader.use()` before setting uniforms");const s=this._gl.getUniformLocation(this.program,e);if(!s)throw Error(`Uniform ${t}:${e} doesn't exist or is not used in the shader source code, unused uniforms are optimized away by most browsers`);{const e=[s,...i];this._gl[t].apply(this._gl,e)}}_createProgram(t,e,i){const s=t.createProgram();if(null===s)throw Error("Could not create graphics shader program");t.attachShader(s,e),t.attachShader(s,i),t.linkProgram(s);if(!t.getProgramParameter(s,t.LINK_STATUS))throw Error(`Could not link the program: [${t.getProgramInfoLog(s)}]`);return s}_compileShader(t,e,i){const s=t.VERTEX_SHADER===i?"vertex":"fragment",r=t.createShader(i);if(null===r)throw Error(`Could not build shader: [${e}]`);t.shaderSource(r,e),t.compileShader(r);if(!t.getShaderParameter(r,t.COMPILE_STATUS)){const i=t.getShaderInfoLog(r);throw Error(`Could not compile ${s} shader:\n\n${i}${this._processSourceForError(e,i)}`)}return r}_processSourceForError(t,e){const i=t.split("\n"),s=e.search(/\d:\d/),r=e.indexOf(" ",s),[n,o]=e.slice(s,r).split(":").map((t=>Number(t)));for(let t=0;t<i.length;t++)i[t]=`${t+1}: ${i[t]}${o===t+1?" <----- ERROR!":""}`;return"\n\nSource:\n"+i.join("\n")}}Ge._ACTIVE_SHADER_INSTANCE=null;class Xe{constructor(t){this._gl=Ve.gl,this.type="dynamic";const{size:e,type:i,data:s}=t;if(this.buffer=this._gl.createBuffer(),!s&&!e)throw Error("Must either provide data or a size to the VertexBuffer");this.bufferData=s||new Float32Array(e),this.type=null!=i?i:this.type}bind(){const t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this.buffer)}upload(){const t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this.buffer),t.bufferData(t.ARRAY_BUFFER,this.bufferData,"static"===this.type?t.STATIC_DRAW:t.DYNAMIC_DRAW)}}class qe{constructor(t){this._gl=Ve.gl,this._logger=f.getInstance(),this._layout=[],this._attributes=[],this._vertexTotalSizeBytes=0;const{shader:e,vertexBuffer:i,attributes:s}=t;this._vertexBuffer=i,this._attributes=s,this._shader=e,this.initialize()}get vertexBuffer(){return this._vertexBuffer}get attributes(){return this._attributes}get totalVertexSizeBytes(){return this._vertexTotalSizeBytes}initialize(){if(!this._shader.compiled)throw Error("Shader not compiled, shader must be compiled before defining a vertex layout");this._layout.length=0;const t=this._shader.attributes;for(const e of this._attributes){const i=t[e[0]];if(!i)throw Error(`The attribute named: ${e[0]} size ${e[1]} not found in the shader source code:\n ${this._shader.vertexSource}`);if(i.size!==e[1])throw Error(`VertexLayout size definition for attribute: [${e[0]}, ${e[1]}], doesnt match shader source size ${i.size}:\n ${this._shader.vertexSource}`);this._layout.push(i)}let e=0;for(const t of this._layout){const i=yt(this._gl,t.glType);this._vertexTotalSizeBytes+=i*t.size,e+=t.size}this._vertexBuffer.bufferData.length%e!=0&&this._logger.warn(`The vertex component size (${e}) does divide evenly into the specified vertex buffer (${this._vertexBuffer.bufferData.length})`)}use(t=!1){const e=this._gl;if(!this._shader.isCurrentlyBound())throw Error("Shader associated with this vertex layout is not active! Call shader.use() before layout.use()");this._vertexBuffer.bind(),t&&this._vertexBuffer.upload();let i=0;for(const t of this._layout)e.vertexAttribPointer(t.location,t.size,t.glType,t.normalized,this.totalVertexSizeBytes,i),e.enableVertexAttribArray(t.location),i+=yt(e,t.glType)*t.size}}class je{static clear(){je.DrawCallCount=0,je.DrawnImagesCount=0}}je.DrawCallCount=0,je.DrawnImagesCount=0;class Ke{constructor(){this.type="ex.line",this.priority=0,this._maxLines=10922,this._vertexIndex=0,this._lineCount=0}initialize(t,e){this._gl=t,this._context=e,this._shader=new Ge({vertexSource:"attribute vec2 a_position;\r\nattribute vec4 a_color;\r\n\r\nvarying lowp vec4 v_color;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Passthrough the color\r\n v_color = a_color;\r\n}",fragmentSource:"precision mediump float;\r\n\r\n// Color\r\nvarying lowp vec4 v_color;\r\n\r\n\r\nvoid main() {\r\n gl_FragColor = v_color;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._vertexBuffer=new Xe({size:12*this._maxLines,type:"dynamic"}),this._layout=new qe({vertexBuffer:this._vertexBuffer,shader:this._shader,attributes:[["a_position",2],["a_color",4]]})}draw(t,e,i){this._isFull()&&this.flush(),this._lineCount++;const s=this._context.getTransform(),r=s.multv(t),n=s.multv(e),o=this._vertexBuffer.bufferData;o[this._vertexIndex++]=r.x,o[this._vertexIndex++]=r.y,o[this._vertexIndex++]=i.r/255,o[this._vertexIndex++]=i.g/255,o[this._vertexIndex++]=i.b/255,o[this._vertexIndex++]=i.a,o[this._vertexIndex++]=n.x,o[this._vertexIndex++]=n.y,o[this._vertexIndex++]=i.r/255,o[this._vertexIndex++]=i.g/255,o[this._vertexIndex++]=i.b/255,o[this._vertexIndex++]=i.a}_isFull(){return this._lineCount>=this._maxLines}hasPendingDraws(){return 0!==this._lineCount}flush(){if(0===this._lineCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),t.drawArrays(t.LINES,0,2*this._lineCount),je.DrawnImagesCount+=this._lineCount,je.DrawCallCount++,this._vertexIndex=0,this._lineCount=0}}class Ye{constructor(){this.type="ex.point",this.priority=0,this._maxPoints=10922,this._pointCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,this._shader=new Ge({vertexSource:"attribute vec2 a_position;\r\nattribute vec4 a_color;\r\nattribute float a_size;\r\nvarying lowp vec4 v_color;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main() {\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n gl_PointSize = a_size * 2.0;\r\n v_color = a_color;\r\n}",fragmentSource:'#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\n\r\nprecision mediump float;\r\nvarying lowp vec4 v_color;\r\n\r\nvoid main() {\r\n float r = 0.0, delta = 0.0, alpha = 1.0;\r\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\r\n r = dot(cxy, cxy);\r\n\r\n#ifdef GL_OES_standard_derivatives\r\n delta = fwidth(r);\r\n alpha = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, r);\r\n#else\r\n if (r > 1.0) {\r\n discard;\r\n }\r\n#endif\r\n // "premultiply" the color by alpha\r\n vec4 color = v_color;\r\n color.a = color.a * alpha;\r\n color.rgb = color.rgb * color.a;\r\n gl_FragColor = color;\r\n}'}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._buffer=new Xe({size:7*this._maxPoints,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_color",4],["a_size",1]]})}draw(t,e,i){this._isFull()&&this.flush(),this._pointCount++;const s=this._context.getTransform(),r=this._context.opacity,n=s.multv(t),o=this._buffer.bufferData;o[this._vertexIndex++]=n.x,o[this._vertexIndex++]=n.y,o[this._vertexIndex++]=e.r/255,o[this._vertexIndex++]=e.g/255,o[this._vertexIndex++]=e.b/255,o[this._vertexIndex++]=e.a*r,o[this._vertexIndex++]=i*Math.max(s.getScaleX(),s.getScaleY())}_isFull(){return this._pointCount>=this._maxPoints}hasPendingDraws(){return 0!==this._pointCount}flush(){if(0===this._pointCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),t.drawArrays(t.POINTS,0,this._pointCount),je.DrawnImagesCount+=this._pointCount,je.DrawCallCount++,this._pointCount=0,this._vertexIndex=0}}class Ze{constructor(t){this._gl=t,this._shader=new Ge({vertexSource:"attribute vec2 a_position;\r\n\r\nattribute vec2 a_texcoord;\r\nvarying vec2 v_texcoord;\r\n\r\nvoid main() {\r\n gl_Position = vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass the texcoord to the fragment shader.\r\n v_texcoord = a_texcoord;\r\n}",fragmentSource:"precision mediump float;\r\n\r\n// Passed in from the vertex shader.\r\nvarying vec2 v_texcoord;\r\n\r\n// The texture.\r\nuniform sampler2D u_texture;\r\n\r\nvoid main() {\r\n gl_FragColor = texture2D(u_texture, v_texcoord);\r\n}"}),this._shader.compile(),this._buffer=new Xe({type:"static",data:new Float32Array([-1,-1,0,0,-1,1,0,1,1,-1,1,0,1,-1,1,0,-1,1,0,1,1,1,1,1])}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_texcoord",2]]}),this._buffer.upload()}renderWithPostProcessor(t){const e=this._gl;t.getShader().use(),t.getLayout().use(),e.drawArrays(e.TRIANGLES,0,6)}renderToScreen(){const t=this._gl;this._shader.use(),this._layout.use(),t.drawArrays(t.TRIANGLES,0,6)}}class Qe{constructor(t,e){this._gl=Ve.gl,this._logger=f.getInstance();const i=this._gl;this.buffer=i.createBuffer(),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this.buffer);const s=6*t;if(i.getExtension("OES_element_index_uint")&&!e)this.bufferData=new Uint32Array(s);else{const e=65535,r=Math.floor((e-1)/4);this.bufferGlType=i.UNSIGNED_SHORT,this.bufferData=new Uint16Array(s),t>r&&this._logger.warn(`Total quads exceeds hardware index buffer limit (uint16), max(${r}) requested quads(${t})`)}let r=0;for(let t=0;t<s;t+=6)this.bufferData[t+0]=r+0,this.bufferData[t+1]=r+1,this.bufferData[t+2]=r+2,this.bufferData[t+3]=r+2,this.bufferData[t+4]=r+1,this.bufferData[t+5]=r+3,r+=4;i.bufferData(i.ELEMENT_ARRAY_BUFFER,this.bufferData,i.STATIC_DRAW)}get size(){return this.bufferData.length}upload(){const t=this._gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.buffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.bufferData,t.STATIC_DRAW)}bind(){const t=this._gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.buffer)}}class $e{constructor(){this.type="ex.image",this.priority=0,this._maxImages=10922,this._maxTextures=0,this._imageCount=0,this._textures=[],this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,this._maxTextures=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);const i=this._transformFragmentSource("precision mediump float;\r\n\r\n// UV coord\r\nvarying vec2 v_texcoord;\r\n\r\n// Texture index\r\nvarying lowp float v_textureIndex;\r\n\r\n// Textures in the current draw\r\nuniform sampler2D u_textures[%%count%%];\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // In order to support the most efficient sprite batching, we have multiple\r\n // textures loaded into the gpu (usually 8) this picker logic skips over textures\r\n // that do not apply to a particular sprite.\r\n\r\n vec4 color = vec4(1.0, 0, 0, 1.0);\r\n\r\n // GLSL is templated out to pick the right texture and set the vec4 color\r\n %%texture_picker%%\r\n\r\n color.rgb = color.rgb * v_opacity;\r\n color.a = color.a * v_opacity;\r\n gl_FragColor = color;\r\n}",this._maxTextures);this._shader=new Ge({fragmentSource:i,vertexSource:"attribute vec2 a_position;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\n// UV coordinate\r\nattribute vec2 a_texcoord;\r\nvarying vec2 v_texcoord;\r\n\r\n// Texture number\r\nattribute lowp float a_textureIndex;\r\nvarying lowp float v_textureIndex;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the UV coord to the fragment shader\r\n v_texcoord = a_texcoord;\r\n // Pass through the texture number to the fragment shader\r\n v_textureIndex = a_textureIndex;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._shader.setUniformIntArray("u_textures",[...Array(this._maxTextures)].map(((t,e)=>e))),this._buffer=new Xe({size:24*this._maxImages,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_opacity",1],["a_texcoord",2],["a_textureIndex",1]]}),this._quads=new Qe(this._maxImages,!0)}_transformFragmentSource(t,e){let i=t.replace("%%count%%",e.toString()),s="";for(let t=0;t<e;t++)s+=0===t?`if (v_textureIndex <= ${t}.5) {\n`:` else if (v_textureIndex <= ${t}.5) {\n`,s+=` color = texture2D(u_textures[${t}], v_texcoord);\n`,s+=" }\n";return i=i.replace("%%texture_picker%%",s),i}_addImageAsTexture(t){const e=bt.load(t);-1===this._textures.indexOf(e)&&this._textures.push(e)}_bindTextures(t){for(let e=0;e<this._maxTextures;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this._textures[e]||this._textures[0])}_getTextureIdForImage(t){return t?this._textures.indexOf(bt.get(t)):-1}_isFull(){return this._imageCount>=this._maxImages||this._textures.length>=this._maxTextures}draw(t,e,i,s,r,n,o,a,h){var l,c,d,u;this._isFull()&&this.flush(),this._imageCount++,this._addImageAsTexture(t);let p=(null==t?void 0:t.width)||s||0,g=(null==t?void 0:t.height)||r||0,_=[0,0,null!==(l=null!=s?s:null==t?void 0:t.width)&&void 0!==l?l:0,null!==(c=null!=r?r:null==t?void 0:t.height)&&void 0!==c?c:0],f=[null!=e?e:1,null!=i?i:1];void 0!==n&&void 0!==o&&void 0!==a&&void 0!==h&&(_=[null!=e?e:1,null!=i?i:1,null!==(d=null!=s?s:null==t?void 0:t.width)&&void 0!==d?d:0,null!==(u=null!=r?r:null==t?void 0:t.height)&&void 0!==u?u:0],f=[n,o],p=a,g=h),e=_[0],i=_[1];const m=_[2],v=_[3],y=this._context.getTransform(),w=this._context.opacity,x=this._context.snapToPixel,b=y.multv([f[0],f[1]]),C=y.multv([f[0]+p,f[1]]),S=y.multv([f[0],f[1]+g]),A=y.multv([f[0]+p,f[1]+g]);x&&(b[0]=~~b[0],b[1]=~~b[1],C[0]=~~C[0],C[1]=~~C[1],S[0]=~~S[0],S[1]=~~S[1],A[0]=~~A[0],A[1]=~~A[1]);const P=this._getTextureIdForImage(t),T=vt(t.width||p),E=vt(t.height||g),I=e/T,R=i/E,B=(e+m-.01)/T,D=(i+v-.01)/E,M=this._layout.vertexBuffer.bufferData;M[this._vertexIndex++]=b[0],M[this._vertexIndex++]=b[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=I,M[this._vertexIndex++]=R,M[this._vertexIndex++]=P,M[this._vertexIndex++]=S[0],M[this._vertexIndex++]=S[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=I,M[this._vertexIndex++]=D,M[this._vertexIndex++]=P,M[this._vertexIndex++]=C[0],M[this._vertexIndex++]=C[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=B,M[this._vertexIndex++]=R,M[this._vertexIndex++]=P,M[this._vertexIndex++]=A[0],M[this._vertexIndex++]=A[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=B,M[this._vertexIndex++]=D,M[this._vertexIndex++]=P}hasPendingDraws(){return 0!==this._imageCount}flush(){if(0===this._imageCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._bindTextures(t),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._imageCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._imageCount,je.DrawCallCount++,this._imageCount=0,this._vertexIndex=0,this._textures.length=0}}class Je{constructor(){this.type="ex.rectangle",this.priority=0,this._maxRectangles=10922,this._rectangleCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,t.getExtension("OES_standard_derivatives"),this._shader=new Ge({fragmentSource:"#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\nprecision mediump float;\r\n\r\n// UV coord\r\nvarying vec2 v_uv;\r\n\r\nvarying vec2 v_size; // in pixels\r\n\r\n// Color coord to blend with image\r\nvarying lowp vec4 v_color;\r\n\r\n// Stroke color if used\r\nvarying lowp vec4 v_strokeColor;\r\n\r\n// Stroke thickness if used\r\nvarying lowp float v_strokeThickness; // in pixels\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // modified from https://stackoverflow.com/questions/59197671/glsl-rounded-rectangle-with-variable-border\r\n vec2 uv = v_uv;\r\n vec2 fragCoord = uv * v_size;\r\n float maxX = v_size.x - v_strokeThickness;\r\n float minX = v_strokeThickness;\r\n float maxY = v_size.y - v_strokeThickness;\r\n float minY = v_strokeThickness;\r\n\r\n if (fragCoord.x < maxX && fragCoord.x > minX &&\r\n fragCoord.y < maxY && fragCoord.y > minY) {\r\n gl_FragColor = v_color;\r\n } else {\r\n gl_FragColor = v_strokeColor;\r\n }\r\n gl_FragColor.a *= v_opacity;\r\n gl_FragColor.rgb *= gl_FragColor.a;\r\n\r\n // vec2 v2CenteredPos = abs(fragCoord - v_size.xy / 2.0);\r\n // vec2 v2HalfShapeSizePx = v_size.xy/2.0 - v_strokeThickness/2.0;\r\n\r\n // float fHalfBorderDist = 0.0;\r\n // float fHalfBorderThickness = 0.0;\r\n\r\n // if (fragCoord.x > max(v_radius, v_strokeThickness) && \r\n // fragCoord.x < v_size.x - max(v_radius, v_strokeThickness))\r\n // {\r\n // fHalfBorderDist = v2CenteredPos.y - v2HalfShapeSizePx.y;\r\n // fHalfBorderThickness = v_strokeThickness / 2.0;\r\n // }\r\n // else if (fragCoord.y > max(v_radius, v_strokeThickness) && \r\n // fragCoord.y < v_size.y - max(v_radius, v_strokeThickness))\r\n // {\r\n // fHalfBorderDist = v2CenteredPos.x - v2HalfShapeSizePx.x;\r\n // fHalfBorderThickness = v_strokeThickness / 2.0;\r\n // }\r\n // else\r\n // {\r\n // vec2 edgeVec = max(vec2(0.0), v_radius - vec2(\r\n // uv.x > 0.5 ? v_size.x - fragCoord.x : fragCoord.x,\r\n // uv.y > 0.5 ? v_size.y - fragCoord.y : fragCoord.y));\r\n \r\n // float ellipse_ab = v_radius-v_strokeThickness;\r\n // vec2 ellipse_isect = (v_strokeThickness > v_radius || v_strokeThickness > v_radius) ? vec2(0.0) :\r\n // edgeVec.xy * ellipse_ab*ellipse_ab / length(ellipse_ab*edgeVec.yx); \r\n \r\n // fHalfBorderThickness = (v_radius - length(ellipse_isect)) / 2.0;\r\n // fHalfBorderDist = length(edgeVec) - (v_radius - fHalfBorderThickness);\r\n // }\r\n\r\n // vec4 v4FromColor = v_strokeColor;\r\n // v4FromColor.rgb *= v4FromColor.a;\r\n // vec4 v4ToColor = vec4(0.0); // background color is transparent\r\n // if (fHalfBorderDist < 0.0) {\r\n // v4ToColor = v_color;\r\n // v4ToColor.rgb *= v4ToColor.a;\r\n // }\r\n\r\n // float mixPct = abs(fHalfBorderDist) - fHalfBorderThickness;\r\n\r\n // vec4 finalColor = mix(v4FromColor, v4ToColor, mixPct);\r\n // gl_FragColor = finalColor;\r\n}",vertexSource:"attribute vec2 a_position;\r\n\r\n// UV coordinate\r\nattribute vec2 a_uv;\r\nvarying vec2 v_uv;\r\n\r\nattribute vec2 a_size;\r\nvarying vec2 v_size;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nattribute vec4 a_strokeColor;\r\nvarying vec4 v_strokeColor;\r\n\r\nattribute float a_strokeThickness;\r\nvarying float v_strokeThickness;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through UV coords\r\n v_uv = a_uv;\r\n // Pass through size\r\n v_size = a_size;\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the color to the fragment shader\r\n v_color = a_color;\r\n // Pass through the stroke color to the fragment shader\r\n v_strokeColor = a_strokeColor;\r\n // Pass through the stroke thickenss to the fragment shader\r\n v_strokeThickness = a_strokeThickness;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._buffer=new Xe({size:64*this._maxRectangles,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_uv",2],["a_size",2],["a_opacity",1],["a_color",4],["a_strokeColor",4],["a_strokeThickness",1]]}),this._quads=new Qe(this._maxRectangles,!0)}_isFull(){return this._rectangleCount>=this._maxRectangles}drawLine(t,e,i,s=1){this._isFull()&&this.flush(),this._rectangleCount++;const r=this._context.getTransform(),n=this._context.opacity,o=e.sub(t),a=o.size,h=o.normalize().perpendicular(),l=s/2,c=r.multv(h.scale(l).add(t)),d=r.multv(h.scale(-l).add(t)),u=r.multv(h.scale(l).add(e)),p=r.multv(h.scale(-l).add(e)),g=I.Transparent,_=this._layout.vertexBuffer.bufferData;_[this._vertexIndex++]=c.x,_[this._vertexIndex++]=c.y,_[this._vertexIndex++]=0,_[this._vertexIndex++]=0,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=d.x,_[this._vertexIndex++]=d.y,_[this._vertexIndex++]=0,_[this._vertexIndex++]=1,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=u.x,_[this._vertexIndex++]=u.y,_[this._vertexIndex++]=1,_[this._vertexIndex++]=0,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=p.x,_[this._vertexIndex++]=p.y,_[this._vertexIndex++]=1,_[this._vertexIndex++]=1,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0}draw(t,e,i,s,r=I.Transparent,n=0){this._isFull()&&this.flush(),this._rectangleCount++;const o=this._context.getTransform(),a=this._context.opacity,h=o.multv(t.add(P(0,0))),l=o.multv(t.add(P(e,0))),c=o.multv(t.add(P(e,i))),d=o.multv(t.add(P(0,i))),u=this._layout.vertexBuffer.bufferData;u[this._vertexIndex++]=h.x,u[this._vertexIndex++]=h.y,u[this._vertexIndex++]=0,u[this._vertexIndex++]=0,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=d.x,u[this._vertexIndex++]=d.y,u[this._vertexIndex++]=0,u[this._vertexIndex++]=1,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=l.x,u[this._vertexIndex++]=l.y,u[this._vertexIndex++]=1,u[this._vertexIndex++]=0,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=c.x,u[this._vertexIndex++]=c.y,u[this._vertexIndex++]=1,u[this._vertexIndex++]=1,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n}hasPendingDraws(){return 0!==this._rectangleCount}flush(){if(0===this._rectangleCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._rectangleCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._rectangleCount,je.DrawCallCount++,this._rectangleCount=0,this._vertexIndex=0}}class ti{constructor(){this.type="ex.circle",this.priority=0,this._maxCircles=10922,this._circleCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,t.getExtension("OES_standard_derivatives"),this._shader=new Ge({fragmentSource:"#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\nprecision highp float;\r\n\r\n// UV coord\r\nvarying vec2 v_uv;\r\n\r\n// Color coord to blend with image\r\nvarying lowp vec4 v_color;\r\n\r\n// Stroke color if used\r\nvarying lowp vec4 v_strokeColor;\r\n\r\n// Stroke thickness if used\r\nvarying lowp float v_strokeThickness;\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // make (0, 0) the center the uv \r\n vec2 uv = v_uv * 2.0 - 1.0;\r\n\r\n vec4 color = v_color;\r\n vec4 strokeColor = v_strokeColor;\r\n\r\n // circle border is at radius 1.0 \r\n // dist is > 0 when inside the circle \r\n float d = length(uv);\r\n float dist = 1.0 - length(uv);\r\n\r\n // Fade based on fwidth\r\n float fade = fwidth(dot(uv, uv));\r\n\r\n // if dist is greater than 0 step to 1;\r\n // when we cross this 0 threshold add a smooth fade\r\n float fill = smoothstep(-fade/2.0, fade/2.0, dist);\r\n\r\n // if dist is greater than the stroke thickness step to 1\r\n float stroke = 1.0 - smoothstep(v_strokeThickness, v_strokeThickness + fade, dist);\r\n\r\n strokeColor.a *= fill * stroke;\r\n strokeColor.rgb *= strokeColor.a;\r\n\r\n color.a *= fill * (1.0 - stroke);\r\n color.rgb *= color.a;\r\n\r\n vec4 finalColor = mix(vec4(0.0), (color + strokeColor), fill);\r\n finalColor.rgb = finalColor.rgb * v_opacity;\r\n finalColor.a = finalColor.a * v_opacity;\r\n gl_FragColor = finalColor;\r\n}",vertexSource:"attribute vec2 a_position;\r\n\r\n// UV coordinate\r\nattribute vec2 a_uv;\r\nvarying vec2 v_uv;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nattribute vec4 a_strokeColor;\r\nvarying vec4 v_strokeColor;\r\n\r\nattribute float a_strokeThickness;\r\nvarying float v_strokeThickness;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through UV coords\r\n v_uv = a_uv;\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the color to the fragment shader\r\n v_color = a_color;\r\n // Pass through the stroke color to the fragment shader\r\n v_strokeColor = a_strokeColor;\r\n // Pass through the stroke thickenss to the fragment shader\r\n v_strokeThickness = a_strokeThickness;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._buffer=new Xe({size:56*this._maxCircles,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_uv",2],["a_opacity",1],["a_color",4],["a_strokeColor",4],["a_strokeThickness",1]]}),this._quads=new Qe(this._maxCircles,!0)}_isFull(){return this._circleCount>=this._maxCircles}draw(t,e,i,s=I.Transparent,r=0){this._isFull()&&this.flush(),this._circleCount++;const n=this._context.getTransform(),o=this._context.opacity,a=n.multv(t.add(P(-e,-e))),h=n.multv(t.add(P(e,-e))),l=n.multv(t.add(P(e,e))),c=n.multv(t.add(P(-e,e))),d=this._layout.vertexBuffer.bufferData;d[this._vertexIndex++]=a.x,d[this._vertexIndex++]=a.y,d[this._vertexIndex++]=0,d[this._vertexIndex++]=0,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=c.x,d[this._vertexIndex++]=c.y,d[this._vertexIndex++]=0,d[this._vertexIndex++]=1,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=h.x,d[this._vertexIndex++]=h.y,d[this._vertexIndex++]=1,d[this._vertexIndex++]=0,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=l.x,d[this._vertexIndex++]=l.y,d[this._vertexIndex++]=1,d[this._vertexIndex++]=1,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e}hasPendingDraws(){return 0!==this._circleCount}flush(){if(0===this._circleCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._circleCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._circleCount,je.DrawCallCount++,this._circleCount=0,this._vertexIndex=0}}class ei{constructor(t){this._webglCtx=t,this._debugText=new Ne}drawRect(t,e,i,s,r={color:I.Black}){this.drawLine(P(t,e),P(t+i,e),{...r}),this.drawLine(P(t+i,e),P(t+i,e+s),{...r}),this.drawLine(P(t+i,e+s),P(t,e+s),{...r}),this.drawLine(P(t,e+s),P(t,e),{...r})}drawLine(t,e,i={color:I.Black}){this._webglCtx.draw("ex.line",t,e,i.color)}drawPoint(t,e={color:I.Black,size:5}){this._webglCtx.draw("ex.point",t,e.color,e.size)}drawText(t,e){this._debugText.write(this._webglCtx,t,e)}}class ii{constructor(t){this._logger=f.getInstance(),this._renderers=new Map,this._isDrawLifecycle=!1,this._postProcessTargets=[],this._postprocessors=[],this._transform=new dt,this._state=new ut,this.snapToPixel=!0,this.smoothing=!1,this.backgroundColor=I.ExcaliburBlue,this._alreadyWarnedDrawLifecycle=!1,this.debug=new ei(this);const{canvasElement:e,enableTransparency:i,smoothing:s,snapToPixel:r,backgroundColor:n}=t;this.__gl=e.getContext("webgl",{antialias:null!=s?s:this.smoothing,premultipliedAlpha:!1,alpha:null==i||i,depth:!0,powerPreference:"high-performance"}),Ve.register(this.__gl),bt.register(this.__gl),this.snapToPixel=null!=r?r:this.snapToPixel,this.smoothing=null!=s?s:this.smoothing,this.backgroundColor=null!=n?n:this.backgroundColor,this._init()}get opacity(){return this._state.current.opacity}set opacity(t){this._state.current.opacity=t}get width(){return this.__gl.canvas.width}get height(){return this.__gl.canvas.height}get ortho(){return this._ortho}checkIfResolutionSupported(t){const e=this.__gl,i=e.getParameter(e.MAX_TEXTURE_SIZE)/4;let s=!0;return(t.width>i||t.height>i)&&(s=!1),s}_init(){const t=this.__gl;this._ortho=ct.ortho(0,t.canvas.width,t.canvas.height,0,400,-400),t.viewport(0,0,t.canvas.width,t.canvas.height),t.clearColor(this.backgroundColor.r/255,this.backgroundColor.g/255,this.backgroundColor.b/255,this.backgroundColor.a),t.clear(t.COLOR_BUFFER_BIT),t.enable(t.BLEND),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.blendEquationSeparate(t.FUNC_ADD,t.FUNC_ADD),t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA),this.register(new $e),this.register(new Je),this.register(new ti),this.register(new Ye),this.register(new Ke),this._screenRenderer=new Ze(t),this._renderTarget=new We({gl:t,width:t.canvas.width,height:t.canvas.height}),this._postProcessTargets=[new We({gl:t,width:t.canvas.width,height:t.canvas.height}),new We({gl:t,width:t.canvas.width,height:t.canvas.height})],this._canvas=new St({width:t.canvas.width,height:t.canvas.height}),this.__ctx=this._canvas.ctx}register(t){this._renderers.set(t.type,t),t.initialize(this.__gl,this)}get(t){return this._renderers.get(t)}_isCurrentRenderer(t){return!this._currentRenderer||this._currentRenderer===t}beginDrawLifecycle(){this._isDrawLifecycle=!0}endDrawLifecycle(){this._isDrawLifecycle=!1}draw(t,...e){this._isDrawLifecycle||this._alreadyWarnedDrawLifecycle||(this._logger.warn("Attempting to draw outside the the drawing lifecycle (preDraw/postDraw) is not supported and is a source of bugs/errors.\nIf you want to do custom drawing, use Actor.graphics, or any onPreDraw or onPostDraw handler."),this._alreadyWarnedDrawLifecycle=!0);const i=this._renderers.get(t);if(!i)throw Error(`No renderer with name ${t} has been registered`);this._currentRenderer||(this._currentRenderer=i),this._isCurrentRenderer(i)||this._currentRenderer.flush(),i.draw(...e),this._currentRenderer=i}resetTransform(){this._transform.current=ct.identity()}updateViewport(t){const e=this.__gl;this._ortho=this._ortho=ct.ortho(0,t.width,t.height,0,400,-400),this._renderTarget.setResolution(e.canvas.width,e.canvas.height),this._postProcessTargets[0].setResolution(e.canvas.width,e.canvas.height),this._postProcessTargets[1].setResolution(e.canvas.width,e.canvas.height),this._canvas.width=e.canvas.width,this._canvas.height=e.canvas.height}drawImage(t,e,i,s,r,n,o,a,h){if(0!==s&&0!==r&&0!==a&&0!==h&&0!==t.width&&0!==t.height)return t?void this.draw("ex.image",t,e,i,s,r,n,o,a,h):(f.getInstance().warn("Cannot draw a null or undefined image"),void(console.trace&&console.trace()))}drawLine(t,e,i,s=1){this._renderers.get("ex.rectangle").drawLine(t,e,i,s)}drawRectangle(t,e,i,s,r,n){this.draw("ex.rectangle",t,e,i,s,r,n)}drawCircle(t,e,i,s,r){this.draw("ex.circle",t,e,i,s,r)}save(){this._transform.save(),this._state.save()}restore(){this._transform.restore(),this._state.restore()}translate(t,e){this._transform.translate(this.snapToPixel?~~t:t,this.snapToPixel?~~e:e)}rotate(t){this._transform.rotate(t)}scale(t,e){this._transform.scale(t,e)}transform(t){this._transform.current=t}getTransform(){return this._transform.current}multiply(t){this._transform.current=this._transform.current.multm(t)}addPostProcessor(t){this._postprocessors.push(t),t.initialize(this.__gl)}removePostProcessor(t){const e=this._postprocessors.indexOf(t);-1!==e&&this._postprocessors.splice(e,1)}clearPostProcessors(){this._postprocessors.length=0}clear(){const t=this.__gl;this._renderTarget.use(),t.clearColor(this.backgroundColor.r/255,this.backgroundColor.g/255,this.backgroundColor.b/255,this.backgroundColor.a),t.clear(t.COLOR_BUFFER_BIT)}flush(){const t=this.__gl;this._renderTarget.use();for(const t of this._renderers.values())t.hasPendingDraws()&&t.flush();this._renderTarget.disable();this._renderTarget.toRenderSource().use();for(let t=0;t<this._postprocessors.length;t++)this._postProcessTargets[t%2].use(),this._screenRenderer.renderWithPostProcessor(this._postprocessors[t]),this._postProcessTargets[t%2].toRenderSource().use();t.bindFramebuffer(t.FRAMEBUFFER,null),this._screenRenderer.renderToScreen()}}var si;!function(t){t.Fixed="Fixed",t.FitScreen="FitScreen",t.FillScreen="FillScreen",t.FitContainer="FitContainer",t.FillContainer="FillContainer",t.Position="Position"}(si||(si={}));class ri{static get SVGA(){return{width:800,height:600}}static get Standard(){return{width:1920,height:1080}}static get Atari2600(){return{width:160,height:192}}static get GameBoy(){return{width:160,height:144}}static get GameBoyAdvance(){return{width:240,height:160}}static get NintendoDS(){return{width:256,height:192}}static get NES(){return{width:256,height:224}}static get SNES(){return{width:256,height:244}}}class ni{constructor(t){var e,i,s;this._antialiasing=!0,this._resolutionStack=[],this._viewportStack=[],this._pixelRatioOverride=null,this._isFullScreen=!1,this._isDisposed=!1,this._logger=f.getInstance(),this._fullscreenChangeHandler=()=>{this._isFullScreen=!this._isFullScreen,this._logger.debug("Fullscreen Change",this._isFullScreen)},this._pixelRatioChangeHandler=()=>{this._logger.debug("Pixel Ratio Change",window.devicePixelRatio),this._listenForPixelRatio(),this._devicePixelRatio=this._calculateDevicePixelRatio(),this.applyResolutionAndViewport()},this._resizeHandler=()=>{const t=this.parent;this._logger.debug("View port resized"),this._setResolutionAndViewportByDisplayMode(t),this.applyResolutionAndViewport()},this._devicePixelRatio=this._calculateDevicePixelRatio(),this._alreadyWarned=!1,this.viewport=t.viewport,this.resolution=null!==(e=t.resolution)&&void 0!==e?e:{...this.viewport},this._displayMode=null!==(i=t.displayMode)&&void 0!==i?i:si.Fixed,this._canvas=t.canvas,this.graphicsContext=t.context,this._antialiasing=null!==(s=t.antialiasing)&&void 0!==s?s:this._antialiasing,this._browser=t.browser,this._position=t.position,this._pixelRatioOverride=t.pixelRatio,this._applyDisplayMode(),this._listenForPixelRatio(),this._canvas.addEventListener("fullscreenchange",this._fullscreenChangeHandler),this.applyResolutionAndViewport()}_listenForPixelRatio(){this._mediaQueryList&&!this._mediaQueryList.addEventListener&&this._mediaQueryList.removeListener(this._pixelRatioChangeHandler),this._mediaQueryList=this._browser.window.nativeComponent.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._mediaQueryList.addEventListener?this._mediaQueryList.addEventListener("change",this._pixelRatioChangeHandler,{once:!0}):this._mediaQueryList.addListener(this._pixelRatioChangeHandler)}dispose(){this._isDisposed||(this._isDisposed=!0,this._browser.window.off("resize",this._resizeHandler),this._resizeObserver&&this._resizeObserver.disconnect(),this.parent.removeEventListener("resize",this._resizeHandler),this._mediaQueryList.removeEventListener?this._mediaQueryList.removeEventListener("change",this._pixelRatioChangeHandler):this._mediaQueryList.removeListener(this._pixelRatioChangeHandler),this._canvas.removeEventListener("fullscreenchange",this._fullscreenChangeHandler))}_calculateDevicePixelRatio(){if(window.devicePixelRatio<1)return 1;return window.devicePixelRatio||1}get pixelRatio(){return this._pixelRatioOverride?this._pixelRatioOverride:this._devicePixelRatio}get isHiDpi(){return 1!==this.pixelRatio}get displayMode(){return this._displayMode}get canvas(){return this._canvas}get parent(){return this.displayMode===si.FillContainer||this.displayMode===si.FitContainer?this.canvas.parentElement||document.body:window}get resolution(){return this._resolution}set resolution(t){this._resolution=t}get viewport(){return this._viewport?this._viewport:this._resolution}set viewport(t){this._viewport=t}get aspectRatio(){return this._resolution.width/this._resolution.height}get scaledWidth(){return this._resolution.width*this.pixelRatio}get scaledHeight(){return this._resolution.height*this.pixelRatio}setCurrentCamera(t){this._camera=t}pushResolutionAndViewport(){this._resolutionStack.push(this.resolution),this._viewportStack.push(this.viewport),this.resolution={...this.resolution},this.viewport={...this.viewport}}peekViewport(){return this._viewportStack[this._viewportStack.length-1]}peekResolution(){return this._resolutionStack[this._resolutionStack.length-1]}popResolutionAndViewport(){this.resolution=this._resolutionStack.pop(),this.viewport=this._viewportStack.pop()}applyResolutionAndViewport(){if(this._canvas.width=this.scaledWidth,this._canvas.height=this.scaledHeight,this.graphicsContext instanceof ii){this.graphicsContext.checkIfResolutionSupported({width:this.scaledWidth,height:this.scaledHeight})||this._alreadyWarned||(this._alreadyWarned=!0,this._logger.warn(`The currently configured resolution (${this.resolution.width}x${this.resolution.height}) is too large for the platform WebGL implementation, this may work but cause WebGL rendering to behave oddly. Try reducing the resolution or disabling Hi DPI scaling to avoid this (read more here https://excaliburjs.com/docs/screens#understanding-viewport--resolution).`))}this._antialiasing?this._canvas.style.imageRendering="auto":(this._canvas.style.imageRendering="pixelated",""===this._canvas.style.imageRendering&&(this._canvas.style.imageRendering="crisp-edges")),this._canvas.style.width=this.viewport.width+"px",this._canvas.style.height=this.viewport.height+"px",this.graphicsContext.updateViewport(this.resolution),this.graphicsContext.resetTransform(),this.graphicsContext.smoothing=this._antialiasing}get antialiasing(){return this._antialiasing}set antialiasing(t){this._antialiasing=t,this.graphicsContext.smoothing=this._antialiasing}get isFullScreen(){return this._isFullScreen}goFullScreen(){return this._canvas.requestFullscreen()}exitFullScreen(){return document.exitFullscreen()}pageToScreenCoordinates(t){let e=t.x,i=t.y;if(this._isFullScreen||(e-=$(this._canvas).x,i-=$(this._canvas).y),this._isFullScreen)if(window.innerWidth/this.aspectRatio<window.innerHeight){const t=window.innerWidth/this.aspectRatio;i=(i-(window.innerHeight-t)/2)/t*this.viewport.height,e=e/window.innerWidth*this.viewport.width}else{const t=window.innerHeight*this.aspectRatio;e=(e-(window.innerWidth-t)/2)/t*this.viewport.width,i=i/window.innerHeight*this.viewport.height}return e=e/this.viewport.width*this.resolution.width,i=i/this.viewport.height*this.resolution.height,new A(e,i)}screenToPageCoordinates(t){let e=t.x,i=t.y;if(e=e/this.resolution.width*this.viewport.width,i=i/this.resolution.height*this.viewport.height,this._isFullScreen)if(window.innerWidth/this.aspectRatio<window.innerHeight){const t=window.innerWidth/this.aspectRatio,s=(window.innerHeight-t)/2;i=i/this.viewport.height*t+s,e=e/this.viewport.width*window.innerWidth}else{const t=window.innerHeight*this.aspectRatio,s=(window.innerWidth-t)/2;e=e/this.viewport.width*t+s,i=i/this.viewport.height*window.innerHeight}return this._isFullScreen||(e+=$(this._canvas).x,i+=$(this._canvas).y),new A(e,i)}screenToWorldCoordinates(t){return this._camera?this._camera.inverse.multv(t):t.sub(P(this.resolution.width/2,this.resolution.height/2))}worldToScreenCoordinates(t){return this._camera?this._camera.transform.multv(t):t.add(P(this.resolution.width/2,this.resolution.height/2))}pageToWorldCoordinates(t){const e=this.pageToScreenCoordinates(t);return this.screenToWorldCoordinates(e)}worldToPageCoordinates(t){const e=this.worldToScreenCoordinates(t);return this.screenToPageCoordinates(e)}getWorldBounds(){const t=this.screenToWorldCoordinates(A.Zero),e=t.x+this.drawWidth,i=t.y+this.drawHeight;return new B(t.x,t.y,e,i)}get canvasWidth(){return this.canvas.width}get halfCanvasWidth(){return this.canvas.width/2}get canvasHeight(){return this.canvas.height}get halfCanvasHeight(){return this.canvas.height/2}get drawWidth(){return this._camera?this.resolution.width/this._camera.zoom:this.resolution.width}get halfDrawWidth(){return this.drawWidth/2}get drawHeight(){return this._camera?this.resolution.height/this._camera.zoom:this.resolution.height}get halfDrawHeight(){return this.drawHeight/2}get center(){return P(this.halfDrawWidth,this.halfDrawHeight)}_computeFit(){document.body.style.margin="0px",document.body.style.overflow="hidden";const t=this.aspectRatio;let e=0,i=0;window.innerWidth/t<window.innerHeight?(e=window.innerWidth,i=window.innerWidth/t):(e=window.innerHeight*t,i=window.innerHeight),this.viewport={width:e,height:i}}_computeFitContainer(){const t=this.aspectRatio;let e=0,i=0;const s=this.canvas.parentElement;s.clientWidth/t<s.clientHeight?(e=s.clientWidth,i=s.clientWidth/t):(e=s.clientHeight*t,i=s.clientHeight),this.viewport={width:e,height:i}}_applyDisplayMode(){this.displayMode===si.Position?this._initializeDisplayModePosition(this._position):(this._setResolutionAndViewportByDisplayMode(this.parent),this.parent instanceof Window?this._browser.window.on("resize",this._resizeHandler):(this._resizeObserver=new ResizeObserver((()=>{this._resizeHandler()})),this._resizeObserver.observe(this.parent)),this.parent.addEventListener("resize",this._resizeHandler))}_setResolutionAndViewportByDisplayMode(t){this.displayMode===si.FillContainer&&(this.resolution={width:t.clientWidth,height:t.clientHeight},this.viewport=this.resolution),this.displayMode===si.FillScreen&&(document.body.style.margin="0px",document.body.style.overflow="hidden",this.resolution={width:t.innerWidth,height:t.innerHeight},this.viewport=this.resolution),this.displayMode===si.FitScreen&&this._computeFit(),this.displayMode===si.FitContainer&&this._computeFitContainer()}_initializeDisplayModePosition(t){if(!t)throw new Error("DisplayMode of Position was selected but no position option was given");if(this.canvas.style.display="block",this.canvas.style.position="absolute","string"==typeof t){const e=t.split(" ");switch(e[0]){case"top":this.canvas.style.top="0px";break;case"bottom":this.canvas.style.bottom="0px";break;case"middle":this.canvas.style.top="50%";const t=-this.halfDrawHeight;this.canvas.style.marginTop=t.toString();break;default:throw new Error("Invalid Position Given")}if(e[1])switch(e[1]){case"left":this.canvas.style.left="0px";break;case"right":this.canvas.style.right="0px";break;case"center":this.canvas.style.left="50%";const t=-this.halfDrawWidth;this.canvas.style.marginLeft=t.toString();break;default:throw new Error("Invalid Position Given")}}else t.top&&("number"==typeof t.top?this.canvas.style.top=t.top.toString()+"px":this.canvas.style.top=t.top),t.right&&("number"==typeof t.right?this.canvas.style.right=t.right.toString()+"px":this.canvas.style.right=t.right),t.bottom&&("number"==typeof t.bottom?this.canvas.style.bottom=t.bottom.toString()+"px":this.canvas.style.bottom=t.bottom),t.left&&("number"==typeof t.left?this.canvas.style.left=t.left.toString()+"px":this.canvas.style.left=t.left)}}class oi{static create(){return this._INSTANCE||(window.AudioContext||window.webkitAudioContext)&&(this._INSTANCE=new AudioContext),this._INSTANCE}}oi._INSTANCE=null;class ai{static unlock(){return new Promise(((t,e)=>{if(ai._UNLOCKED||!oi.create())return t(!0);const i=setTimeout((()=>{f.getInstance().warn("Excalibur was unable to unlock the audio context, audio probably will not play in this browser."),t(!1)}),200),s=oi.create();s.resume().then((()=>{const e=s.createBuffer(1,1,22050),r=s.createBufferSource();let n=!1;r.buffer=e,r.connect(s.destination),r.onended=()=>n=!0,r.start(0),setTimeout((()=>{!function(t){return!!t.playbackState}(r)?(s.currentTime>0||n)&&(ai._UNLOCKED=!0):r.playbackState!==r.PLAYING_STATE&&r.playbackState!==r.FINISHED_STATE||(ai._UNLOCKED=!0)}),0),clearTimeout(i),t(!0)}),(()=>{e()}))}))}static isUnlocked(){return this._UNLOCKED}}ai._UNLOCKED=!1;class hi{constructor(){this.eventDispatcher=new he}on(t,e){this.eventDispatcher.on(t,e)}off(t,e){this.eventDispatcher.off(t,e)}emit(t,e){this.eventDispatcher.emit(t,e)}once(t,e){this.eventDispatcher.once(t,e)}}function li(t,e=I.Red,i,s,r,n,o=1,a="butt"){t.save(),t.beginPath(),t.lineWidth=o,t.lineCap=a,t.strokeStyle=e.toString(),t.moveTo(i,s),t.lineTo(r,n),t.closePath(),t.stroke(),t.restore()}function ci(t,e=I.Red,i){t.beginPath(),t.strokeStyle=e.toString(),t.arc(i.x,i.y,5,0,2*Math.PI),t.closePath(),t.stroke()}function di(t,e,i,s,r=1){const n=e?e.toString():"blue",o=s.scale(r);t.beginPath(),t.strokeStyle=n,t.moveTo(i.x,i.y),t.lineTo(i.x+o.x,i.y+o.y),t.closePath(),t.stroke()}function ui(t,e,i,s,r,n=5,o=I.White,a=null){let h;if("number"==typeof n)h={tl:n,tr:n,br:n,bl:n};else{const t={tl:0,tr:0,br:0,bl:0};for(const e in t)if(t.hasOwnProperty(e)){const i=e;h[i]=n[i]||t[i]}}t.beginPath(),t.moveTo(e+h.tl,i),t.lineTo(e+s-h.tr,i),t.quadraticCurveTo(e+s,i,e+s,i+h.tr),t.lineTo(e+s,i+r-h.br),t.quadraticCurveTo(e+s,i+r,e+s-h.br,i+r),t.lineTo(e+h.bl,i+r),t.quadraticCurveTo(e,i+r,e,i+r-h.bl),t.lineTo(e,i+h.tl),t.quadraticCurveTo(e,i,e+h.tl,i),t.closePath(),a&&(t.fillStyle=a.toString(),t.fill()),o&&(t.strokeStyle=o.toString(),t.stroke())}function pi(t,e,i,s,r=I.White,n=null){t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.closePath(),n&&(t.fillStyle=n.toString(),t.fill()),r&&(t.strokeStyle=r.toString(),t.stroke())}var gi=i(1388);class _i extends hi{constructor(t){super(),this.canvas=new St({filtering:ht.Blended,smoothing:!0,draw:this.draw.bind(this)}),this._resourceList=[],this._index=0,this._playButtonShown=!1,this._resourceCount=0,this._numLoaded=0,this._progressCounts={},this._totalCounts={},this.logo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdQAAAB2CAYAAABxhGI9AAAACXBIWXMAAAsSAAALEgHS3X78AAAKnUlEQVR42u3dP2wjSx0H8N8hJIonIRmJjsq0SBR+BQ1dcqKhe0lD77SvSwpKkJKGPulpktfRIMUdEqKIqV57rpAokM4dbSiyq7ONPTP7x39ifz7SFbnEnp3xer47O7uzH15fXwMA6OYHmgAABCoACFQAEKgAgEAFAIEKAAIVAAQqACBQAUCgAoBABQCBCgAIVAAQqAAgUAFAoAIAAhUABCoACFQAEKgAgECFLbmOiNeFf2PbAyz68Pr6qhUgbRwR92v+/zwiJrYHMEKFMmcN///UtgcQqFBk1PD/97U9Qx8VCFSgu4EmAIEKAAIVAAQqACBQ4Z25jojP8eX+0WtNAgIVaOY+Im5j+eKh24h41jQgUIEyZ7F5NaPU7wCBCiwYd/w9cOB+qAlgJ3KLLow0EV198803RWvJfvfddx+0lhEqHKu5JgAjVCBvlhmFzjQRXUekHz9+TP79y8uLRjNChXfvoePvAYEKxNtj1e42/O5JoIJABcrdRMRVLM+X3kTEpaaB988cKuzWg9EobTWdMx0Oly8uN4dqhAoARqgnaN3arHfqu7OyH8ItKLVB/P+CEfMTHyGPY3npx1m8zWGDEeoBfUk/xdti57dr/r1Wv2+6EPow3tZ5rRdS72s1neuF97xvWd+XTH0/V+UMttDWqbI/r2nrxfp+jv2uSjSO7S+OXy/A/3lN+9xX5T5HxEUPZZ0tfB71+w57eJ/HFu+z+jkv1u92YX9fbI/HhX3JA9rp5MPr66tWaG9UfUGbrHIzi7cLUyYFf/tpTady03EEeL8mUJ6i7MKYNvWNqr4Pe2jradXO60LrvPAz2PQ5RPX684ah8dxD+2zantnCgVipSVV+m/tgB9W2DDq2Sx/vM95wcHhZhWVJm8yrv58cSgfTdc70+++/X/r522+/tUKSEepBqo+om4ZLPerMjUwuNnQCtx1GWJtee1FwdD5uWd86xLs8UaVt2aNEO1/saZ/Z5rYMW4zq6v34rGV9Bg3q2eZ9SkeNm9qwyUh30OPIHYFKx5FG03C7znSOqYBq+qW/zpQ3anH037TNHluG6f0WPsPhHvab4QFty7ogOeuxDYcNy2/zu2214WNYWxmBurNO8bGn97pNBOO8xy/9uCorZZ4I2r4C7aJgO7ZV9iE49Dm6NvOWx+pWE9CUq3zbdTp9doz38TbXtzqH9RT5CyWe422OaZoZGeZCabrhPQY9HjwsjpTvCg4YtlE2+Ta/j2bzn8fqrDqgm+6yUHOmAvWUjAtGhbNYvsBknDnqH1Qhc7VmxHgeb/NbudA5j/UXlYwif2p6luhAc9teu1npiHKnDs8if6tCm7JLX3NKpgttXe9ruc9mHMd7a83iwdxF5vt8tutARaCeklRnNK9C8WnNF7geJQ4T4XG3JhSnVdilQrG+yOnrlVHfsEGYzhNBn7Lu6tS7+HJafJQ4EMiNlNqWXZ9WPvVgnVYHG5M1ByDXkT6leX2EgTqJtyt45yv7S2qO3sEZjZhDLXeR+YKdJ0Zdk8QocvH9N732KrNtq+FZ/zzIHABcJrYpd+Xv14lOd5ap76SgrduW/VTQ1qcQpqnbgu4ifZvUMNpd9XuoZmvCtPaQ2Y/BCHVLgbrJTeRPDdVf6pfMKDU2fOkHmVFFfXr3MsouLsnNvV5kRoe5+s431PeuoKPqWnaurY/ZPBEeqwceN4l96iwO6H7Mjq4y7VGPVNe10VaZMzVCPVWpI/Z6FZbcv5fMqGCU+dLfFGzj58jP8+bCdJCo7yzKTwdOF0bu9Ug7V4c+yz7FJfYeGoysUss0HssIdVZwYLDujMqlESoCdTtGsZtbHnJBeNdDSJSs0jTKdMJN1HNX54Wv7bvsU9NkVJVa13dX+/wuArV0X/l5RHyo/lnfF4G6p6DrS0kHdtXhy35TGErDPYZUn2WfWqDOo/lVqdMD2O/hKJhD7S/odukymq9s02QN4EEPR/zbaOumZc+r15zK1Zqznl9jsfiemTM1QmV3HUuTkedlg9HIQzRbUD93dfC+2tpj2fIHEH2+RqCCQH13gZq7hWXTNpVu19OB1fc9nQ0AKOKUb5lU0P1kDyOneoWk0lOZ9cIP0x7qu8+2BhCoR2wYu1+e7DmaXzBSsu5vaX1ne2zrpmUPTmxf7PM1Dm4y/vC7ny7Nif7+z/9ZmtM0Z3panPLtPmra9f16bcK0Dpbnwk43Vd/RHtu6zfNQTy1QBy3aqG2g9nVmxml+BOoJyT3NpWmn9xhfFnu4bvDa+44BXhqqfdf3uUF9+yz77AT31Yue2mjecYQ62NLfgkA9ghHqLNEhNem4H1c6vdyDxhf/bpz5m4coW/c39wi6VH2bPtHlcaV9cvXts+zxCe6rTeqc2ndL7uGd93QwM9bFcAzMoZZ7SgTBbWx+asui61h/iq1+RmjqdbnQXQ3T1DNQ63V/U9ucqm/pMzPb1rePsk/1iTOjgvatR4W3Lc8ULB78pELyrnAfeTcj1NU509/86mfJ33/8+Mf00a05UyPUEw7UVCeWG/WNEiExyHRMt5ltW30izUPk18ytt7lNfc8i//DvtvXto+ySA5BjljsLUF8lPkqMPEtW1JomDsiGBZ9Byb4NAvUITSN9GuwsIj6t6UTOqk7jJREkmzqli8xIs96udSO20sX0H1vW92IL9e1a9rgqVyf91gbPsTy9UD9n9lOkT8k+RfkFR5PMNqxOcdSf32PBvg3vilO+zdxE+okx9Wm0ph36XYsRZCpMF993GOk5qvqB3Dct6jvssb67KvuUNJ3frw92bhr8/STSF0JdRPMLpUCgnsgo9S76PZ246ZFk1wWvK5m3vVoYvW1Sz7nN91jfXbQ1ZQc7TW6HeaoOalypG/8/p/rP1aNAc6ZHzSnfdqPUPhdy2PQw6Nz9gSVhuhiqueUHR3uu7y7K3rdDX4u46ZrPbUa0IFBZ0seKQ3XQTRt2vm3W/a2DbNKys++rvm3ep6+y1x2UdP3bWU9lzra47U1GmlctX/sQ23t+aOlByLTh/4NAPaCRxtcdO5HLSJ/6vNtCwGx67VPmPbvWd1q9frKHtp4kAqRJ2HR9j762JfX3bZ//elPtj13PPDx1+D5tqk/Xi6NO8SHz7MmH19dXrdBNfVFP6T2PT1UHNit87/t4m5+aRH+nQBdvqyhZDKJLfZs8h7XPsqdV2ZOV+tanKB8aln0dyxdAXbV4j4gvt4oMOrbP6vbU73NW7TMlbdTnPrWpfqXfh9HKZ9vke7KuTeZRNtXRSe6+1FV//ce/ln5eXfsXgcqXzr6+9261M3moOoa7E6nvTZTfy7iNsmfb7kjfgXGsvxe0vihsEts9HTquPpt1q1vtahu2TqAiUAEEKj0zhwoARqgAu/OnX/442WH+9xc/Wvr58re/Tr7f41/+ZsRqhAoACFQAEKgAcHjMoQJskJsz/eqrr5Z+vvr7v5fmQFevAl5lztQIFQAQqAAgUAHgIJlDBdhgdQ41N2eKESoAIFABQKACwFEwhwoARqgAIFABQKACAAIVAAQqAAhUABCoAIBABQCBCgACFQAEKgAgUAFAoAKAQAUAgQoACFQAEKgAIFABQKACAAIVAAQqAAhUABCoAIBABQCBCgACFQAQqAAgUAFAoAKAQAUAlvwPcFDns1DsH4sAAAAASUVORK5CYII=",this.logoWidth=468,this.logoHeight=118,this.loadingBarColor=I.White,this.backgroundColor="#176BAA",this.suppressPlayButton=!1,this._playButtonStyles=gi.Z.toString(),this.playButtonText="Play game",this.startButtonFactory=()=>{let t=document.getElementById("excalibur-play");return t||(t=document.createElement("button")),t.id="excalibur-play",t.textContent=this.playButtonText,t.style.display="none",t},this._isLoadedPromise=new Promise((t=>{this._isLoadedResolve=t})),t&&this.addResources(t)}get _image(){return this._imageElement||(this._imageElement=new Image,this._imageElement.src=this.logo),this._imageElement}get playButtonRootElement(){return this._playButtonRootElement}get playButtonElement(){return this._playButtonElement}get _playButton(){const t=document.getElementById("excalibur-play-root");return t&&(this._playButtonRootElement=t),this._playButtonRootElement||(this._playButtonRootElement=document.createElement("div"),this._playButtonRootElement.id="excalibur-play-root",this._playButtonRootElement.style.position="absolute",document.body.appendChild(this._playButtonRootElement)),this._styleBlock||(this._styleBlock=document.createElement("style"),this._styleBlock.textContent=this._playButtonStyles,document.head.appendChild(this._styleBlock)),this._playButtonElement||(this._playButtonElement=this.startButtonFactory(),this._playButtonRootElement.appendChild(this._playButtonElement)),this._playButtonElement}wireEngine(t){this._engine=t,this.canvas.width=this._engine.canvas.width,this.canvas.height=this._engine.canvas.height}addResource(t){const e=this._index++;this._resourceList.push(t),this._progressCounts[e]=0,this._totalCounts[e]=1,this._resourceCount++}addResources(t){let e=0;const i=t.length;for(;e<i;e++)this.addResource(t[e])}isLoaded(){return this._numLoaded===this._resourceCount}async showPlayButton(){var t,e;if(!this.suppressPlayButton){const t=()=>{this._positionPlayButton()};(null===(e=this._engine)||void 0===e?void 0:e.browser)&&this._engine.browser.window.on("resize",t),this._playButtonShown=!0,this._playButton.style.display="block",document.body.addEventListener("keyup",(t=>{"Enter"===t.key&&this._playButton.click()})),this._positionPlayButton();const i=new Promise((e=>{const i=i=>{var s;i.stopPropagation(),this.hidePlayButton(),(null===(s=this._engine)||void 0===s?void 0:s.browser)&&this._engine.browser.window.off("resize",t),e()};this._playButton.addEventListener("click",i),this._playButton.addEventListener("touchend",i),this._playButton.addEventListener("pointerup",i)}));return await i}this.hidePlayButton(),await ot(500,null===(t=this._engine)||void 0===t?void 0:t.clock)}hidePlayButton(){this._playButtonShown=!1,this._playButton.style.display="none"}dispose(){this._playButtonRootElement.parentElement&&(this._playButtonRootElement.removeChild(this._playButtonElement),document.body.removeChild(this._playButtonRootElement),document.head.removeChild(this._styleBlock),this._playButtonRootElement=null,this._playButtonElement=null,this._styleBlock=null)}update(t,e){}areResourcesLoaded(){return this._isLoadedPromise}async load(){var t,e;return await(null===(t=this._image)||void 0===t?void 0:t.decode()),await Promise.all(this._resourceList.map((t=>t.load().finally((()=>{this._numLoaded++}))))),this._isLoadedResolve(),await ot(200,null===(e=this._engine)||void 0===e?void 0:e.clock),await this.showPlayButton(),await ai.unlock(),this.data=this._resourceList}markResourceComplete(){this._numLoaded++}get progress(){return this._resourceCount>0?z(this._numLoaded,0,this._resourceCount)/this._resourceCount:1}_positionPlayButton(){if(this._engine){const t=this._engine.screen.viewport.height,e=this._engine.screen.viewport.width;if(this._playButtonRootElement){const i=this._engine.canvas.offsetLeft,s=this._engine.canvas.offsetTop,r=this._playButton.clientWidth,n=this._playButton.clientHeight;this.playButtonPosition?(this._playButtonRootElement.style.left=`${this.playButtonPosition.x}px`,this._playButtonRootElement.style.top=`${this.playButtonPosition.y}px`):(this._playButtonRootElement.style.left=i+e/2-r/2+"px",this._playButtonRootElement.style.top=s+t/2-n/2+100+"px")}}}draw(t){const e=this._engine.canvasHeight/this._engine.pixelRatio,i=this._engine.canvasWidth/this._engine.pixelRatio;this._positionPlayButton(),t.fillStyle=this.backgroundColor,t.fillRect(0,0,i,e);let s=e/2;const r=Math.min(this.logoWidth,.75*i);let n=i/2-r/2;this.logoPosition&&(n=this.logoPosition.x,s=this.logoPosition.y);const o=Math.floor(r*(this.logoHeight/this.logoWidth)),a=this._engine.getAntialiasing();if(this._engine.setAntialiasing(!0),this.logoPosition?t.drawImage(this._image,0,0,this.logoWidth,this.logoHeight,n,s,r,o):t.drawImage(this._image,0,0,this.logoWidth,this.logoHeight,n,s-o-20,r,o),!this.suppressPlayButton&&this._playButtonShown)return void this._engine.setAntialiasing(a);let h=n,l=s;this.loadingBarPosition&&(h=this.loadingBarPosition.x,l=this.loadingBarPosition.y),t.lineWidth=2,ui(t,h,l,r,20,10,this.loadingBarColor);const c=r*this.progress-10;ui(t,h+5,l+5,c>10?c:10,10,5,null,this.loadingBarColor),this._engine.setAntialiasing(a)}}const fi={webgl:"WebGL",webaudio:"WebAudio",gamepadapi:"Gamepad API"};class mi{constructor(){this._features=null,this.failedTests=[],this._criticalTests={canvasSupport:function(){const t=document.createElement("canvas");return!(!t.getContext||!t.getContext("2d"))},arrayBufferSupport:function(){const t=new XMLHttpRequest;t.open("GET","/");try{t.responseType="arraybuffer"}catch(t){return!1}return"arraybuffer"===t.responseType},dataUrlSupport:function(){return 0===document.createElement("canvas").toDataURL("image/png").indexOf("data:image/png")},objectUrlSupport:function(){return"URL"in window&&"revokeObjectURL"in URL&&"createObjectURL"in URL},rgbaSupport:function(){const t=document.createElement("a").style;return t.cssText="background-color:rgba(150,255,150,.5)",(""+t.backgroundColor).indexOf("rgba")>-1}},this._warningTest={webAudioSupport:function(){return!!(window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext||window.oAudioContext)},webglSupport:function(){const t=document.createElement("canvas");return!(!t.getContext||!t.getContext("webgl"))}},this._features=this._loadBrowserFeatures()}getBrowserFeatures(){return null===this._features&&(this._features=this._loadBrowserFeatures()),this._features}logBrowserFeatures(){let t="%cSUPPORTED BROWSER FEATURES\n==========================%c\n";const e=["font-weight: bold; color: navy","font-weight: normal; color: inherit"],i=this.getBrowserFeatures();for(const s of Object.keys(fi))i[s]?(t+="(%c✓%c)",e.push("font-weight: bold; color: green"),e.push("font-weight: normal; color: inherit")):(t+="(%c✗%c)",e.push("font-weight: bold; color: red"),e.push("font-weight: normal; color: inherit")),t+=" "+fi[s]+"\n";e.unshift(t),console.log.apply(console,e)}_loadBrowserFeatures(){return{canvas:(()=>this._criticalTests.canvasSupport())(),arraybuffer:(()=>this._criticalTests.arrayBufferSupport())(),dataurl:(()=>this._criticalTests.dataUrlSupport())(),objecturl:(()=>this._criticalTests.objectUrlSupport())(),rgba:(()=>this._criticalTests.rgbaSupport())(),webaudio:(()=>this._warningTest.webAudioSupport())(),webgl:(()=>this._warningTest.webglSupport())(),gamepadapi:!!navigator.getGamepads}}test(){let t=!1;for(const e in this._criticalTests)this._criticalTests[e].call(this)||(this.failedTests.push(e),f.getInstance().error("Critical browser feature missing, Excalibur requires:",e),t=!0);if(t)return!1;for(const t in this._warningTest)this._warningTest[t]()||f.getInstance().warn("Warning browser feature missing, Excalibur will have reduced performance:",t);return!0}}var vi;!function(t){t.PreventCollision="PreventCollision",t.Passive="Passive",t.Active="Active",t.Fixed="Fixed"}(vi||(vi={}));var yi,wi,xi,bi=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};!function(t){t.Arcade="arcade",t.Realistic="realistic"}(yi||(yi={})),function(t){t[t.DynamicAABBTree=0]="DynamicAABBTree"}(wi||(wi={})),function(t){t[t.Euler=0]="Euler"}(xi||(xi={}));class Ci{static get gravity(){return Ci.acc}static set gravity(t){Ci.acc=t}static useArcadePhysics(){Ci.collisionResolutionStrategy=yi.Arcade}static useRealisticPhysics(){Ci.collisionResolutionStrategy=yi.Realistic}static get dynamicTreeVelocityMultiplyer(){return Ci.dynamicTreeVelocityMultiplier}static set dynamicTreeVelocityMultiplyer(t){Ci.dynamicTreeVelocityMultiplier=t}}Ci.acc=new A(0,0),Ci.enabled=!0,Ci.broadphaseStrategy=wi.DynamicAABBTree,Ci.collisionResolutionStrategy=yi.Arcade,Ci.defaultMass=10,Ci.integrator=xi.Euler,Ci.dynamicTreeVelocityMultiplier=2,Ci.boundsPadding=5,Ci.positionIterations=3,Ci.velocityIterations=8,Ci.slop=1,Ci.steeringFactor=.2,Ci.warmStart=!0,Ci.bodiesCanSleepByDefault=!1,Ci.surfaceEpsilon=.1,Ci.sleepEpsilon=.07,Ci.wakeThreshold=3*Ci.sleepEpsilon,Ci.sleepBias=.9,Ci.checkForFastBodies=!0,Ci.disableMinimumSpeedForFastBody=!1,bi([C({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"dynamicTreeVelocityMultiplier"})],Ci,"dynamicTreeVelocityMultiplyer",null);class Si extends A{constructor(t){super(0,0),this._getX=t.getX,this._getY=t.getY,this._setX=t.setX,this._setY=t.setY}get x(){return this._x=this._getX()}set x(t){this._setX(t),this._x=t}get y(){return this._y=this._getY()}set y(t){this._setY(t),this._y=t}}class Ai{constructor(){this.owner=null}clone(){const t=new this.constructor;for(const i in this)if(this.hasOwnProperty(i)){const s=this[i];(null==(e=s)?void 0:e.clone)&&"owner"!==i&&"clone"!==i?t[i]=s.clone():t[i]=s}var e;return t}}class Pi extends Ai{constructor(t,e){super(),this.type=t,this.value=e}}var Ti;!function(t){t.World="world",t.Screen="screen"}(Ti||(Ti={}));class Ei extends Ai{constructor(){super(...arguments),this.type="ex.transform",this._dirty=!1,this.matrix=ct.identity().translate(0,0).rotate(0).scale(1,1),this._position=(t=>{const e=t;return new Si({setX:t=>{e.data[at.X]=t},setY:t=>{e.data[at.Y]=t},getX:()=>e.data[at.X],getY:()=>e.data[at.Y]})})(this.matrix),this._rotation=0,this._scale=(t=>{const e=t;return new Si({setX:t=>{e.setScaleX(t)},setY:t=>{e.setScaleY(t)},getX:()=>e.getScaleX(),getY:()=>e.getScaleY()})})(this.matrix),this.coordPlane=Ti.World,this.z=0}_recalculate(){this._rotation=this.matrix.getRotation(),this._dirty=!1}getGlobalMatrix(){return this.parent?this.parent.getGlobalMatrix().multm(this.matrix):this.matrix}getGlobalTransform(){return{pos:this.globalPos,scale:this.globalScale,rotation:this.globalRotation,z:this.z,coordPlane:this.coordPlane}}get parent(){var t,e;return null===(e=null===(t=null==this?void 0:this.owner)||void 0===t?void 0:t.parent)||void 0===e?void 0:e.get(Ei)}get pos(){return this._dirty&&this._recalculate(),this._position}set pos(t){this.matrix.setPosition(t.x,t.y),this._dirty=!0}get dirty(){var t;if(null===(t=null==this?void 0:this.owner)||void 0===t?void 0:t.parent){return this.parent.dirty||this._dirty}return this._dirty}get globalPos(){const t=this.getGlobalMatrix();return new Si({getX:()=>t.data[at.X],getY:()=>t.data[at.Y],setX:e=>{var i;if(this.parent){const[s]=null===(i=this.parent)||void 0===i?void 0:i.getGlobalMatrix().getAffineInverse().multv([e,t.data[at.Y]]);this.matrix.data[at.X]=s}else this.matrix.data[at.X]=e},setY:e=>{var i;if(this.parent){const[,s]=null===(i=this.parent)||void 0===i?void 0:i.getGlobalMatrix().getAffineInverse().multv([t.data[at.X],e]);this.matrix.data[at.Y]=s}else this.matrix.data[at.Y]=e}})}set globalPos(t){const e=this.parent;this.pos=e?e.getGlobalMatrix().getAffineInverse().multv(t):t}get rotation(){return this._dirty&&this._recalculate(),this._rotation}set rotation(t){this.matrix.setRotation(t),this._dirty=!0}get globalRotation(){return this.getGlobalMatrix().getRotation()}set globalRotation(t){const e=this.parent;this.rotation=e?t-e.globalRotation:t}get scale(){return this._dirty&&this._recalculate(),this._scale}set scale(t){this.matrix.setScale(t),this._dirty=!0}get globalScale(){const t=this.getGlobalMatrix();return new Si({getX:()=>t.getScaleX(),getY:()=>t.getScaleY(),setX:t=>{if(this.parent){const e=this.parent.globalScale.x;this.matrix.setScaleX(t/e)}else this.matrix.setScaleX(t)},setY:t=>{if(this.parent){const e=this.parent.globalScale.y;this.matrix.setScaleY(t/e)}else this.matrix.setScaleY(t)}})}set globalScale(t){const e=this.parent;this.scale=e?P(t.x/e.globalScale.x,t.y/e.globalScale.y):t}apply(t){return this.matrix.multv(t)}applyInverse(t){return this.matrix.getAffineInverse().multv(t)}}class Ii extends Ai{constructor(){super(...arguments),this.type="ex.motion",this.vel=A.Zero,this.acc=A.Zero,this.scaleFactor=A.Zero,this.angularVelocity=0,this.torque=0,this.inertia=1}}class Ri{constructor(t,e,i){this._name=t,this._category=e,this._mask=i}get name(){return this._name}get category(){return this._category}get mask(){return this._mask}canCollide(t){return 0!=(this.category&t.mask)&&0!=(t.category&this.mask)}invert(){return new Ri("~("+this.name+")",~this.category,~this.mask)}static combine(t){const e=t.map((t=>t.name)).join("+"),i=t.reduce(((t,e)=>e.category|t),0);return new Ri(e,i,~i)}static collidesWith(t){return Ri.combine(t).invert()}}Ri.All=new Ri("Collide with all groups",-1,-1);class Bi{constructor(){this.observers=[],this.subscriptions=[]}register(t){this.observers.push(t)}subscribe(t){this.subscriptions.push(t)}unregister(t){const e=this.observers.indexOf(t);-1!==e&&this.observers.splice(e,1)}unsubscribe(t){const e=this.subscriptions.indexOf(t);-1!==e&&this.subscriptions.splice(e,1)}notifyAll(t){this.observers.forEach((e=>e.notify(t))),this.subscriptions.forEach((e=>e(t)))}clear(){this.observers.length=0,this.subscriptions.length=0}}class Di{constructor(t,e){this.colliderA=t,this.colliderB=e,this.id=null,this.id=Di.calculatePairHash(t.id,e.id)}static canCollide(t,e){var i,s;const r=null===(i=null==t?void 0:t.owner)||void 0===i?void 0:i.get($i),n=null===(s=null==e?void 0:e.owner)||void 0===s?void 0:s.get($i);return t.id!==e.id&&((!t.owner||!e.owner||t.owner.id!==e.owner.id)&&(!t.localBounds.hasZeroDimensions()&&!e.localBounds.hasZeroDimensions()&&(!(!r||!n)&&(!!r.group.canCollide(n.group)&&((r.collisionType!==vi.Fixed||n.collisionType!==vi.Fixed)&&(n.collisionType!==vi.PreventCollision&&r.collisionType!==vi.PreventCollision&&!(!r.active||!n.active)))))))}get canCollide(){const t=this.colliderA,e=this.colliderB;return Di.canCollide(t,e)}collide(){return this.colliderA.collide(this.colliderB)}hasCollider(t){return t===this.colliderA||t===this.colliderB}static calculatePairHash(t,e){return t.value<e.value?`#${t.value}+${e.value}`:`#${e.value}+${t.value}`}}class Mi{constructor(t,e){this.min=t,this.max=e}overlaps(t){return this.max>t.min&&t.max>this.min}getOverlap(t){return this.overlaps(t)?this.max>t.max?t.max-this.min:this.max-t.min:0}}class ki{constructor(t){this.parent=t,this.parent=t||null,this.data=null,this.bounds=new B,this.left=null,this.right=null,this.height=0}isLeaf(){return!this.left&&!this.right}}class Fi{constructor(t=new B(-Number.MAX_VALUE,-Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)){this.worldBounds=t,this.root=null,this.nodes={}}_insert(t){if(null===this.root)return this.root=t,void(this.root.parent=null);const e=t.bounds;let i=this.root;for(;!i.isLeaf();){const t=i.left,s=i.right,r=i.bounds.getPerimeter(),n=i.bounds.combine(e).getPerimeter(),o=2*n,a=2*(n-r);let h=0;const l=e.combine(t.bounds);let c,d;t.isLeaf()?h=l.getPerimeter()+a:(d=t.bounds.getPerimeter(),c=l.getPerimeter(),h=c-d+a);let u=0;const p=e.combine(s.bounds);if(s.isLeaf()?u=p.getPerimeter()+a:(d=s.bounds.getPerimeter(),c=p.getPerimeter(),u=c-d+a),o<h&&o<u)break;i=h<u?t:s}const s=i.parent,r=new ki(s);r.bounds=e.combine(i.bounds),r.height=i.height+1,null!==s?(s.left===i?s.left=r:s.right=r,r.left=i,r.right=t,i.parent=r,t.parent=r):(r.left=i,r.right=t,i.parent=r,t.parent=r,this.root=r);let n=t.parent;for(;n;){if(n=this._balance(n),!n.left)throw new Error("Parent of current leaf cannot have a null left child"+n);if(!n.right)throw new Error("Parent of current leaf cannot have a null right child"+n);n.height=1+Math.max(n.left.height,n.right.height),n.bounds=n.left.bounds.combine(n.right.bounds),n=n.parent}}_remove(t){if(t===this.root)return void(this.root=null);const e=t.parent,i=e.parent;let s;if(s=e.left===t?e.right:e.left,i){i.left===e?i.left=s:i.right=s,s.parent=i;let t=i;for(;t;)t=this._balance(t),t.bounds=t.left.bounds.combine(t.right.bounds),t.height=1+Math.max(t.left.height,t.right.height),t=t.parent}else this.root=s,s.parent=null}trackCollider(t){const e=new ki;e.data=t,e.bounds=t.bounds,e.bounds.left-=2,e.bounds.top-=2,e.bounds.right+=2,e.bounds.bottom+=2,this.nodes[t.id.value]=e,this._insert(e)}updateCollider(t){var e;const i=this.nodes[t.id.value];if(!i)return!1;const s=t.bounds;if(!this.worldBounds.contains(s))return f.getInstance().warn("Collider with id "+t.id.value+" is outside the world bounds and will no longer be tracked for physics"),this.untrackCollider(t),!1;if(i.bounds.contains(s))return!1;if(this._remove(i),s.left-=Ci.boundsPadding,s.top-=Ci.boundsPadding,s.right+=Ci.boundsPadding,s.bottom+=Ci.boundsPadding,t.owner){const i=null===(e=t.owner)||void 0===e?void 0:e.get($i);if(i){const t=32*i.vel.x/1e3*Ci.dynamicTreeVelocityMultiplier,e=32*i.vel.y/1e3*Ci.dynamicTreeVelocityMultiplier;t<0?s.left+=t:s.right+=t,e<0?s.top+=e:s.bottom+=e}}return i.bounds=s,this._insert(i),!0}untrackCollider(t){const e=this.nodes[t.id.value];e&&(this._remove(e),this.nodes[t.id.value]=null,delete this.nodes[t.id.value])}_balance(t){if(null===t)throw new Error("Cannot balance at null node");if(t.isLeaf()||t.height<2)return t;const e=t.left,i=t.right,s=t,r=e,n=i,o=e.left,a=e.right,h=i.left,l=i.right,c=n.height-r.height;if(c>1)return n.left=s,n.parent=s.parent,s.parent=n,n.parent?n.parent.left===s?n.parent.left=n:n.parent.right=n:this.root=n,h.height>l.height?(n.right=h,s.right=l,l.parent=s,s.bounds=r.bounds.combine(l.bounds),n.bounds=s.bounds.combine(h.bounds),s.height=1+Math.max(r.height,l.height),n.height=1+Math.max(s.height,h.height)):(n.right=l,s.right=h,h.parent=s,s.bounds=r.bounds.combine(h.bounds),n.bounds=s.bounds.combine(l.bounds),s.height=1+Math.max(r.height,h.height),n.height=1+Math.max(s.height,l.height)),n;if(c<-1){if(r.left=s,r.parent=s.parent,s.parent=r,r.parent)if(r.parent.left===s)r.parent.left=r;else{if(r.parent.right!==s)throw"Error rotating Dynamic Tree";r.parent.right=r}else this.root=r;return o.height>a.height?(r.right=o,s.left=a,a.parent=s,s.bounds=n.bounds.combine(a.bounds),r.bounds=s.bounds.combine(o.bounds),s.height=1+Math.max(n.height,a.height),r.height=1+Math.max(s.height,o.height)):(r.right=a,s.left=o,o.parent=s,s.bounds=n.bounds.combine(o.bounds),r.bounds=s.bounds.combine(a.bounds),s.height=1+Math.max(n.height,o.height),r.height=1+Math.max(s.height,a.height)),r}return t}getHeight(){return null===this.root?0:this.root.height}query(t,e){const i=t.bounds,s=r=>{if(r&&r.bounds.intersect(i)){if(!r.isLeaf()||r.data===t)return s(r.left)||s(r.right);if(e.call(t,r.data))return!0}return!1};s(this.root)}rayCastQuery(t,e=1/0,i){const s=r=>{if(r&&r.bounds.rayCast(t,e)){if(!r.isLeaf())return s(r.left)||s(r.right);if(i.call(t,r.data))return!0}return!1};s(this.root)}getNodes(){const t=e=>e?[e].concat(t(e.left),t(e.right)):[];return t(this.root)}debug(t){const e=i=>{i&&(i.isLeaf()?i.bounds.draw(t,I.Green):i.bounds.draw(t,I.White),i.left&&e(i.left),i.right&&e(i.right))};e(this.root)}}class Li{constructor(t,e){this.pos=t,this.dir=e.normalize()}intersect(t){const e=t.begin.sub(this.pos);if(0===this.dir.cross(t.getSlope())&&0!==e.cross(this.dir))return-1;const i=this.dir.cross(t.getSlope());if(0===i)return-1;const s=e.cross(t.getSlope())/i;if(s>=0){const r=e.cross(this.dir)/i/t.getLength();if(r>=0&&r<=1)return s}return-1}intersectPoint(t){const e=this.intersect(t);return e<0?null:this.getPoint(e)}getPoint(t){return this.pos.add(this.dir.scale(t))}}class zi{constructor(){this._dynamicCollisionTree=new Fi,this._pairs=new Set,this._collisionPairCache=[],this._colliders=[]}getColliders(){return this._colliders}track(t){if(t)if(t instanceof Ui){const e=t.getColliders();for(const i of e)i.owner=t.owner,this._colliders.push(i),this._dynamicCollisionTree.trackCollider(i)}else this._colliders.push(t),this._dynamicCollisionTree.trackCollider(t);else f.getInstance().warn("Cannot track null collider")}untrack(t){if(t)if(t instanceof Ui){const e=t.getColliders();for(const t of e){const e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1),this._dynamicCollisionTree.untrackCollider(t)}}else{const e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1),this._dynamicCollisionTree.untrackCollider(t)}else f.getInstance().warn("Cannot untrack a null collider")}_pairExists(t,e){const i=Di.calculatePairHash(t.id,e.id);return this._pairs.has(i)}broadphase(t,e,i){const s=e/1e3,r=t.filter((t=>{var e,i;const s=null===(e=t.owner)||void 0===e?void 0:e.get($i);return(null===(i=t.owner)||void 0===i?void 0:i.active)&&s.collisionType!==vi.PreventCollision}));let n;this._collisionPairCache=[],this._pairs.clear();for(let t=0,e=r.length;t<e;t++)n=r[t],this._dynamicCollisionTree.query(n,(t=>{if(!this._pairExists(n,t)&&Di.canCollide(n,t)){const e=new Di(n,t);this._pairs.add(e.id),this._collisionPairCache.push(e)}return!1}));if(i&&(i.physics.pairs=this._collisionPairCache.length),Ci.checkForFastBodies)for(const t of r){const e=t.owner.get($i);if(e.collisionType!==vi.Active)continue;const r=e.vel.size*s+.5*e.acc.size*s*s,n=Math.min(t.bounds.height,t.bounds.width);if(Ci.disableMinimumSpeedForFastBody||r>n/2){i&&i.physics.fastBodies++;const s=e.pos.sub(e.oldPos),n=t.center,o=t.getFurthestPoint(e.vel),a=o.sub(s),h=new Li(a,e.vel);let l;h.pos=h.pos.add(h.dir.scale(-2*Ci.surfaceEpsilon));let c=new A(1/0,1/0);if(this._dynamicCollisionTree.rayCastQuery(h,r+2*Ci.surfaceEpsilon,(e=>{if(!this._pairExists(t,e)&&Di.canCollide(t,e)){const t=e.rayCast(h,r+10*Ci.surfaceEpsilon);if(t){const i=t.sub(a);i.size<c.size&&(c=i,l=e)}}return!1})),l&&A.isValid(c)){const s=new Di(t,l);this._pairs.has(s.id)||(this._pairs.add(s.id),this._collisionPairCache.push(s));const r=n.sub(o);e.pos=a.add(r).add(c).add(h.dir.scale(10*Ci.surfaceEpsilon)),t.update(e.transform),i&&i.physics.fastBodyCollisions++}}}return this._collisionPairCache}narrowphase(t,e){let i=[];for(let s=0;s<t.length;s++){const r=t[s].collide();if(i=i.concat(r),e&&r.length>0)for(const t of r)e.physics.contacts.set(t.id,t)}return e&&(e.physics.collisions+=i.length),i}update(t){let e=0;const i=t.length;for(let s=0;s<i;s++)this._dynamicCollisionTree.updateCollider(t[s])&&e++;return e}debug(t){this._dynamicCollisionTree.debug(t)}}class Oi{constructor(){this.id=_("collider",Oi._ID++),this.events=new he}touching(t){return!!this.collide(t)}}Oi._ID=0;class Ui extends Oi{constructor(t){super(),this._collisionProcessor=new zi,this._dynamicAABBTree=new Fi,this._colliders=[];for(const e of t)this.addCollider(e)}clearColliders(){this._colliders=[]}addCollider(t){this.events.wire(t.events),this._colliders.push(t),this._collisionProcessor.track(t),this._dynamicAABBTree.trackCollider(t)}removeCollider(t){this.events.unwire(t.events),tt(t,this._colliders),this._collisionProcessor.untrack(t),this._dynamicAABBTree.untrackCollider(t)}getColliders(){return this._colliders}get worldPos(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:A.Zero}get center(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:A.Zero}get bounds(){var t,e;const i=this.getColliders();return i.reduce(((t,e)=>t.combine(e.bounds)),null!==(e=null===(t=i[0])||void 0===t?void 0:t.bounds)&&void 0!==e?e:(new B).translate(this.worldPos))}get localBounds(){var t,e;const i=this.getColliders();return i.reduce(((t,e)=>t.combine(e.localBounds)),null!==(e=null===(t=i[0])||void 0===t?void 0:t.localBounds)&&void 0!==e?e:new B)}get axes(){const t=this.getColliders();let e=[];for(const i of t)e=e.concat(i.axes);return e}getFurthestPoint(t){const e=this.getColliders(),i=[];for(const s of e)i.push(s.getFurthestPoint(t));let s=i[0],r=-Number.MAX_VALUE;for(const e of i){const i=e.dot(t);i>r&&(s=e,r=i)}return s}getInertia(t){const e=this.getColliders();let i=0;for(const s of e)i+=s.getInertia(t);return i}collide(t){let e=[t];t instanceof Ui&&(e=t.getColliders());const i=[];for(const t of e)this._dynamicAABBTree.query(t,(e=>(i.push(new Di(t,e)),!1)));let s=[];for(const t of i)s=s.concat(t.collide());return s}getClosestLineBetween(t){const e=this.getColliders(),i=[];if(t instanceof Ui){const s=t.getColliders();for(const t of e)for(const e of s){const s=t.getClosestLineBetween(e);s&&i.push(s)}}else for(const s of e){const e=t.getClosestLineBetween(s);e&&i.push(e)}if(i.length){let t=i[0].getLength(),e=i[0];for(const s of i){const i=s.getLength();i<t&&(t=i,e=s)}return e}return null}contains(t){const e=this.getColliders();for(const i of e)if(i.contains(t))return!0;return!1}rayCast(t,e){const i=this.getColliders(),s=[];for(const r of i){const i=r.rayCast(t,e);i&&s.push(i)}if(s.length){let e=s[0],i=e.dot(t.dir);for(const r of s){const s=t.dir.dot(r);s<i&&(e=r,i=s)}return e}return null}project(t){const e=this.getColliders(),i=[];for(const s of e){const e=s.project(t);e&&i.push(e)}if(i.length){const t=new Mi(i[0].min,i[0].max);for(const e of i)t.min=Math.min(e.min,t.min),t.max=Math.max(e.max,t.max);return t}return null}update(t){if(t){const e=this.getColliders();for(const i of e)i.owner=this.owner,i.update(t)}}draw(t,e,i){const s=this.getColliders();for(const r of s)r.draw(t,e,i)}debug(t,e){const i=this.getColliders();for(const s of i)s.debug(t,e)}debugDraw(t,e){const i=this.getColliders();for(const s of i)s.draw(t,e)}clone(){return new Ui(this._colliders.map((t=>t.clone())))}}class Ni{constructor(t,e){this.begin=t,this.end=e}get slope(){return(this.end.y-this.begin.y)/(this.end.x-this.begin.x)}get intercept(){return this.begin.y-this.slope*this.begin.x}normal(){return this.end.sub(this.begin).normal()}dir(){return this.end.sub(this.begin)}getPoints(){return[this.begin,this.end]}getSlope(){const t=this.begin,e=this.end,i=t.distance(e);return e.sub(t).scale(1/i)}getEdge(){const t=this.begin;return this.end.sub(t)}getLength(){const t=this.begin,e=this.end;return t.distance(e)}get midpoint(){return this.begin.add(this.end).scale(.5)}flip(){return new Ni(this.end,this.begin)}below(t){return(this.end.x-this.begin.x)*(t.y-this.begin.y)-(this.end.y-this.begin.y)*(t.x-this.begin.x)>=0}clip(t,e){let i=t;i=i.normalize();const s=i.dot(this.begin)-e,r=i.dot(this.end)-e,n=[];if(s<=0&&n.push(this.begin),r<=0&&n.push(this.end),s*r<0){const t=s/(s-r);n.push(this.begin.add(this.end.sub(this.begin).scale(t)))}return 2!==n.length?null:new Ni(n[0],n[1])}distanceToPoint(t,e=!1){const i=t.x,s=t.y,r=this.getLength(),n=((this.end.y-this.begin.y)*i-(this.end.x-this.begin.x)*s+this.end.x*this.begin.y-this.end.y*this.begin.x)/r;return e?n:Math.abs(n)}findVectorToPoint(t){const e=this.begin.sub(t),i=this.getSlope();return e.sub(i.scale(e.dot(i)))}findPoint(t=null,e=null){const i=this.slope,s=this.intercept;if(null!==t)return new A(t,i*t+s);if(null!==e)return new A((e-s)/i,e);throw new Error("You must provide an X or a Y value")}hasPoint(){let t,e=0;if("number"==typeof arguments[0]&&"number"==typeof arguments[1])t=new A(arguments[0],arguments[1]),e=arguments[2]||0;else{if(!(arguments[0]instanceof A))throw"Could not determine the arguments for Vector.hasPoint";t=arguments[0],e=arguments[1]||0}const i=t.x-this.begin.x,s=t.y-this.begin.y,r=this.end.x-this.begin.x,n=this.end.y-this.begin.y,o=i*n-s*r;return!(Math.abs(o)>e)&&(Math.abs(r)>=Math.abs(n)?r>0?this.begin.x<=t.x&&t.x<=this.end.x:this.end.x<=t.x&&t.x<=this.begin.x:n>0?this.begin.y<=t.y&&t.y<=this.end.y:this.end.y<=t.y&&t.y<=this.begin.y)}}function Hi(t,e,i,s){const r=t.sub(i),n=e.dot(e),o=e.dot(s),a=s.dot(s),h=e.dot(r),l=s.dot(r),c=n*a-o*o;let d=c,u=c;if(0===c||c<=.01){const e=h/o;return new Ni(t,i.add(s.scale(e)))}let p=o*l-a*h,g=n*l-o*h;return p<0?(p=0,g=l,u=a):p>d&&(p=d,g=l+o,u=a),g<0?(g=0,-h<0?p=0:-h>n?p=d:(p=-h,d=n)):g>u&&(g=u,-h+o<0?p=0:-h+o>n?p=d:(p=-h+o,d=n)),p=Math.abs(p)<.001?0:p/d,g=Math.abs(g)<.001?0:g/u,new Ni(t.add(e.scale(p)),i.add(s.scale(g)))}const Wi={PolygonPolygonClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),r=s.negate(),n=new Li(t.worldPos,s),o=new Li(i,r),a=t.rayCast(n).add(n.dir.scale(.1)),h=e.rayCast(o).add(o.dir.scale(.1)),l=t.getClosestFace(a),c=e.getClosestFace(h);return Hi(l.face.begin,l.face.getEdge(),c.face.begin,c.face.getEdge())},PolygonEdgeClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=new Li(t.worldPos,i),r=t.rayCast(s).add(s.dir.scale(.1)),n=t.getClosestFace(r),o=n.face.begin,a=n.face.getEdge(),h=e.asLine();return Hi(o,a,h.begin,h.getEdge())},PolygonCircleClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),r=new Li(t.worldPos,s.normalize()),n=t.rayCast(r).add(r.dir.scale(.1)),o=t.getClosestFace(n),a=o.face.begin,h=o.face.getEdge();let l=(h.x*(i.x-a.x)+h.y*(i.y-a.y))/(h.x*h.x+h.y*h.y);l>1?l=1:l<0&&(l=0);const c=Math.sqrt(Math.pow(a.x+h.x*l-i.x,2)+Math.pow(a.y+h.y*l-i.y,2))-e.radius,d=(a.x+h.x*l-i.x)*e.radius/(e.radius+c),u=(a.y+h.y*l-i.y)*e.radius/(e.radius+c);return new Ni(h.scale(l).add(a),new A(i.x+d,i.y+u))},CircleCircleClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=t.worldPos.sub(e.worldPos),r=new Li(t.worldPos,i),n=new Li(e.worldPos,s),o=t.rayCast(r),a=e.rayCast(n);return new Ni(o,a)},CircleEdgeClosestLine(t,e){const i=t.worldPos,s=e.asLine(),r=s.begin,n=s.getEdge();let o=(n.x*(i.x-r.x)+n.y*(i.y-r.y))/(n.x*n.x+n.y*n.y);o>1?o=1:o<0&&(o=0);const a=Math.sqrt(Math.pow(r.x+n.x*o-i.x,2)+Math.pow(r.y+n.y*o-i.y,2))-t.radius,h=(r.x+n.x*o-i.x)*t.radius/(t.radius+a),l=(r.y+n.y*o-i.y)*t.radius/(t.radius+a);return new Ni(n.scale(o).add(r),new A(i.x+h,i.y+l))},EdgeEdgeClosestLine(t,e){const i=t.asLine(),s=i.begin,r=i.getEdge(),n=e.asLine();return Hi(s,r,n.begin,n.getEdge())}};class Vi extends Oi{constructor(t){super(),this.offset=A.Zero,this.offset=t.offset||A.Zero,this.radius=t.radius||0}get worldPos(){var t,e,i,s;const r=this._transform,n=null!==(t=null==r?void 0:r.globalScale)&&void 0!==t?t:A.One,o=null!==(e=null==r?void 0:r.globalRotation)&&void 0!==e?e:0,a=null!==(i=null==r?void 0:r.globalPos)&&void 0!==i?i:A.Zero;return(null!==(s=this.offset)&&void 0!==s?s:A.Zero).scale(n).rotate(o).add(a)}get radius(){var t;const e=this._transform,i=null!==(t=null==e?void 0:e.globalScale)&&void 0!==t?t:A.One;return this._naturalRadius*Math.min(i.x,i.y)}set radius(t){var e;const i=this._transform,s=null!==(e=null==i?void 0:i.globalScale)&&void 0!==e?e:A.One;this._naturalRadius=t/Math.min(s.x,s.y)}clone(){return new Vi({offset:this.offset.clone(),radius:this.radius})}get center(){var t,e,i,s;const r=this._transform,n=null!==(t=null==r?void 0:r.globalScale)&&void 0!==t?t:A.One,o=null!==(e=null==r?void 0:r.globalRotation)&&void 0!==e?e:0,a=null!==(i=null==r?void 0:r.globalPos)&&void 0!==i?i:A.Zero;return(null!==(s=this.offset)&&void 0!==s?s:A.Zero).scale(n).rotate(o).add(a)}contains(t){var e,i;return(null!==(i=null===(e=this._transform)||void 0===e?void 0:e.pos)&&void 0!==i?i:this.offset).distance(t)<=this.radius}rayCast(t,e=1/0){const i=this.center,s=t.dir,r=t.pos,n=Math.sqrt(Math.pow(s.dot(r.sub(i)),2)-Math.pow(r.sub(i).distance(),2)+Math.pow(this.radius,2));if(n<0)return null;{let o=0;if(0===n)return o=-s.dot(r.sub(i)),o>0&&o<e?t.getPoint(o):null;{const o=-s.dot(r.sub(i))+n,a=-s.dot(r.sub(i))-n,h=[];o>=0&&h.push(o),a>=0&&h.push(a);const l=Math.min(...h);return l<=e?t.getPoint(l):null}}}getClosestLineBetween(t){if(t instanceof Vi)return Wi.CircleCircleClosestLine(this,t);if(t instanceof Ki)return Wi.PolygonCircleClosestLine(t,this).flip();if(t instanceof ji)return Wi.CircleEdgeClosestLine(this,t).flip();throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Vi)return qi.CollideCircleCircle(this,t);if(t instanceof Ki)return qi.CollideCirclePolygon(this,t);if(t instanceof ji)return qi.CollideCircleEdge(this,t);throw new Error("Circle could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){return this.center.add(t.normalize().scale(this.radius))}getFurthestLocalPoint(t){return t.normalize().scale(this.radius)}get bounds(){var t,e,i;const s=this._transform,r=null!==(t=null==s?void 0:s.globalScale)&&void 0!==t?t:A.One,n=null!==(e=null==s?void 0:s.globalRotation)&&void 0!==e?e:0,o=null!==(i=null==s?void 0:s.globalPos)&&void 0!==i?i:A.Zero;return new B(this.offset.x-this._naturalRadius,this.offset.y-this._naturalRadius,this.offset.x+this._naturalRadius,this.offset.y+this._naturalRadius).rotate(n).scale(r).translate(o)}get localBounds(){return new B(this.offset.x-this._naturalRadius,this.offset.y-this._naturalRadius,this.offset.x+this._naturalRadius,this.offset.y+this._naturalRadius)}get axes(){return[]}getInertia(t){return t*this.radius*this.radius/2}update(t){this._transform=t}project(t){const e=[],i=this.center.dot(t);return e.push(i),e.push(i+this.radius),e.push(i-this.radius),new Mi(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=I.Green,i=A.Zero){const s=i.add(this.offset);t.beginPath(),t.fillStyle=e.toString(),t.arc(s.x,s.y,this.radius,0,2*Math.PI),t.closePath(),t.fill()}debug(t,e){var i,s,r,n;const o=this._transform,a=null!==(i=null==o?void 0:o.globalScale)&&void 0!==i?i:A.One,h=null!==(s=null==o?void 0:o.globalRotation)&&void 0!==s?s:0,l=null!==(r=null==o?void 0:o.globalPos)&&void 0!==r?r:A.Zero;t.save(),t.translate(l.x,l.y),t.rotate(h),t.scale(a.x,a.y),t.drawCircle(null!==(n=this.offset)&&void 0!==n?n:A.Zero,this._naturalRadius,I.Transparent,e,2),t.restore()}debugDraw(t,e=I.Green){const i=this._transform,s=i?i.pos.add(this.offset):this.offset,r=i?i.rotation:0;t.beginPath(),t.strokeStyle=e.toString(),t.arc(s.x,s.y,this.radius,0,2*Math.PI),t.closePath(),t.stroke(),t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(Math.cos(r)*this.radius+s.x,Math.sin(r)*this.radius+s.y),t.closePath(),t.stroke()}}class Gi{constructor(t,e,i,s,r,n,o,a){this._canceled=!1,this.colliderA=t,this.colliderB=e,this.mtv=i,this.normal=s,this.tangent=r,this.points=n,this.localPoints=o,this.info=a,this.id=Di.calculatePairHash(t.id,e.id)}matchAwake(){const t=this.colliderA.owner.get($i),e=this.colliderB.owner.get($i);t&&e&&t.sleeping!==e.sleeping&&(t.sleeping&&t.collisionType!==vi.Fixed&&e.sleepMotion>=Ci.wakeThreshold&&t.setSleeping(!1),e.sleeping&&e.collisionType!==vi.Fixed&&t.sleepMotion>=Ci.wakeThreshold&&e.setSleeping(!1))}isCanceled(){return this._canceled}cancel(){this._canceled=!0}}class Xi{static findPolygonPolygonSeparation(t,e){let i=-Number.MAX_VALUE,s=null,r=null,n=-1,o=null;const a=t.getSides(),h=t.getLocalSides();for(let t=0;t<a.length;t++){const h=a[t],l=h.normal(),c=e.getFurthestPoint(l.negate()),d=h.distanceToPoint(c,!0);d>i&&(i=d,s=h,r=l,n=t,o=c)}return{collider:t,separation:r?i:99,axis:r,side:s,localSide:h[n],sideId:n,point:o,localPoint:r?e.getFurthestLocalPoint(r.negate()):null}}static findCirclePolygonSeparation(t,e){const i=e.axes,s=e.center.sub(t.worldPos),r=e.getFurthestPoint(s.negate());i.push(r.sub(t.worldPos).normalize());let n=Number.MAX_VALUE,o=null,a=-1;for(let s=0;s<i.length;s++){const r=e.project(i[s]),h=t.project(i[s]),l=r.getOverlap(h);if(l<=0)return null;l<n&&(n=l,o=i[s],a=s)}return a<0?null:o.normalize().scale(n)}}const qi={CollideCircleCircle(t,e){const i=t.worldPos,s=e.worldPos,r=t.radius+e.radius,n=i.distance(s);if(n>r)return[];const o=r-n,a=s.sub(i).normalize(),h=a.perpendicular(),l=a.scale(o),c=t.getFurthestPoint(a),d=t.getFurthestLocalPoint(a);return[new Gi(t,e,l,a,h,[c],[d],{collider:t,separation:o,axis:a,point:c})]},CollideCirclePolygon(t,e){var i,s;let r=Xi.findCirclePolygonSeparation(t,e);if(!r)return[];const n=r.dot(e.center.sub(t.center));r=n<0?r.negate():r;const o=t.getFurthestPoint(r),a=(null!==(s=null===(i=t.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei).applyInverse(o),h=r.normalize(),l={collider:t,separation:-r.size,axis:h,point:o,localPoint:a,side:e.findSide(h.negate()),localSide:e.findLocalSide(h.negate())};return[new Gi(t,e,r,h,h.perpendicular(),[o],[a],l)]},CollideCircleEdge(t,e){const i=t.center,s=e.asLine(),r=s.end.sub(s.begin),n=r.dot(s.end.sub(i)),o=r.dot(i.sub(s.begin)),a=e.asLine(),h=e.asLocalLine();if(o<=0){const r=s.begin.sub(i),n=r.dot(r);if(n>t.radius*t.radius)return[];const o=r.normalize(),l=t.radius-Math.sqrt(n),c={collider:t,separation:l,axis:o,point:a.begin,side:a,localSide:h};return[new Gi(t,e,o.scale(l),o,o.perpendicular(),[a.begin],[h.begin],c)]}if(n<=0){const r=s.end.sub(i),n=r.dot(r);if(n>t.radius*t.radius)return[];const o=r.normalize(),l=t.radius-Math.sqrt(n),c={collider:t,separation:l,axis:o,point:a.end,side:a,localSide:h};return[new Gi(t,e,o.scale(l),o,o.perpendicular(),[a.end],[h.end],c)]}const l=r.dot(r),c=s.begin.scale(n).add(s.end.scale(o)).scale(1/l),d=i.sub(c),u=d.dot(d);if(u>t.radius*t.radius)return[];let p=r.perpendicular();p.dot(i.sub(s.begin))<0&&(p.x=-p.x,p.y=-p.y),p=p.normalize();const g=t.radius-Math.sqrt(u),_=p.scale(g),f={collider:t,separation:g,axis:p,point:c,side:a,localSide:h};return[new Gi(t,e,_,p.negate(),p.negate().perpendicular(),[c],[c.sub(e.worldPos)],f)]},CollideEdgeEdge:()=>[],CollidePolygonEdge(t,e){var i;const s=t.center,r=e.center.sub(s).normalize(),n=new Ki({points:[e.begin,e.end,e.end.add(r.scale(100)),e.begin.add(r.scale(100))],offset:e.offset});n.owner=e.owner;(null===(i=e.owner)||void 0===i?void 0:i.get(Ei))&&n.update(e.owner.get(Ei));const o=this.CollidePolygonPolygon(t,n);return o.length&&(o[0].colliderB=e,o[0].id=Di.calculatePairHash(t.id,e.id)),o},CollidePolygonPolygon(t,e){var i,s,r,n;const o=Xi.findPolygonPolygonSeparation(t,e);if(o.separation>0)return[];const a=Xi.findPolygonPolygonSeparation(e,t);if(a.separation>0)return[];const h=o.separation>a.separation?o:a,l=(h.collider===t?e:t).findSide(h.axis.negate()),c=h.side,d=c.dir().normalize(),u=l.clip(d.negate(),-d.dot(c.begin));let p=null;if(u&&(p=u.clip(d,d.dot(c.end))),p){const o=p.getPoints().filter((t=>c.below(t)));let a=h.axis,l=a.perpendicular();e.worldPos.sub(t.worldPos).dot(a)<0&&(a=a.negate(),l=a.perpendicular());let d=[];if(h.collider===t){const t=null!==(s=null===(i=e.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei;d=o.map((e=>t.applyInverse(e)))}else{const e=null!==(n=null===(r=t.owner)||void 0===r?void 0:r.get(Ei))&&void 0!==n?n:new Ei;d=o.map((t=>e.applyInverse(t)))}return[new Gi(t,e,a.scale(-h.separation),a,l,o,d,h)]}return[]},FindContactSeparation(t,e){var i,s,r,n;const o=t.colliderA,a=null!==(s=null===(i=t.colliderA.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei,h=t.colliderB,l=null!==(n=null===(r=t.colliderB.owner)||void 0===r?void 0:r.get(Ei))&&void 0!==n?n:new Ei;if(o instanceof Vi&&h instanceof Vi){return-(o.radius+h.radius-a.pos.distance(l.pos))}if(o instanceof Ki&&h instanceof Ki&&t.info.localSide){let i,s;return t.info.collider===o?(i=new Ni(a.apply(t.info.localSide.begin),a.apply(t.info.localSide.end)),s=l.apply(e)):(i=new Ni(l.apply(t.info.localSide.begin),l.apply(t.info.localSide.end)),s=a.apply(e)),i.distanceToPoint(s,!0)}if(o instanceof Ki&&h instanceof Vi||h instanceof Ki&&o instanceof Vi){const i=a.apply(e);if(t.info.side)return t.info.side.distanceToPoint(i,!0)}if(o instanceof ji&&h instanceof Ki||h instanceof ji&&o instanceof Ki){let i;if(i=t.info.collider===o?l.apply(e):a.apply(e),t.info.side)return t.info.side.distanceToPoint(i,!0)}if(o instanceof Vi&&h instanceof ji||h instanceof Vi&&o instanceof ji){const i=l.apply(e);let s;o instanceof Vi&&(s=o.getFurthestPoint(t.normal));const r=i.distance(s);if(t.info.side)return r>0?-r:0}return 0}};class ji extends Oi{constructor(t){var e;super(),this.begin=t.begin||A.Zero,this.end=t.end||A.Zero,this.offset=null!==(e=t.offset)&&void 0!==e?e:A.Zero}clone(){return new ji({begin:this.begin.clone(),end:this.end.clone()})}get worldPos(){var t;const e=this._transform;return null!==(t=null==e?void 0:e.globalPos.add(this.offset))&&void 0!==t?t:this.offset}get center(){return this.begin.average(this.end).add(this._getBodyPos())}_getBodyPos(){var t;const e=this._transform;return null!==(t=null==e?void 0:e.globalPos)&&void 0!==t?t:A.Zero}_getTransformedBegin(){const t=this._transform,e=t?t.globalRotation:0;return this.begin.rotate(e).add(this._getBodyPos())}_getTransformedEnd(){const t=this._transform,e=t?t.globalRotation:0;return this.end.rotate(e).add(this._getBodyPos())}getSlope(){const t=this._getTransformedBegin(),e=this._getTransformedEnd(),i=t.distance(e);return e.sub(t).scale(1/i)}getLength(){const t=this._getTransformedBegin(),e=this._getTransformedEnd();return t.distance(e)}contains(){return!1}rayCast(t,e=1/0){const i=this._getTransformedBegin().sub(t.pos);if(0===t.dir.cross(this.getSlope())&&0!==i.cross(t.dir))return null;const s=t.dir.cross(this.getSlope());if(0===s)return null;const r=i.cross(this.getSlope())/s;if(r>=0&&r<=e){const e=i.cross(t.dir)/s/this.getLength();if(e>=0&&e<=1)return t.getPoint(r)}return null}getClosestLineBetween(t){if(t instanceof Vi)return Wi.CircleEdgeClosestLine(t,this);if(t instanceof Ki)return Wi.PolygonEdgeClosestLine(t,this).flip();if(t instanceof ji)return Wi.EdgeEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Vi)return qi.CollideCircleEdge(t,this);if(t instanceof Ki)return qi.CollidePolygonEdge(t,this);if(t instanceof ji)return qi.CollideEdgeEdge();throw new Error("Edge could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){const e=this._getTransformedBegin(),i=this._getTransformedEnd();return t.dot(e)>0?e:i}_boundsFromBeginEnd(t,e,i=10){return new B(Math.min(t.x,e.x)-i,Math.min(t.y,e.y)-i,Math.max(t.x,e.x)+i,Math.max(t.y,e.y)+i)}get bounds(){const t=this._getTransformedBegin(),e=this._getTransformedEnd();return this._boundsFromBeginEnd(t,e)}get localBounds(){return this._boundsFromBeginEnd(this.begin,this.end)}asLine(){return new Ni(this._getTransformedBegin(),this._getTransformedEnd())}asLocalLine(){return new Ni(this.begin,this.end)}get axes(){const t=this._getTransformedEnd().sub(this._getTransformedBegin()).normal(),e=[];return e.push(t),e.push(t.negate()),e.push(t.normal()),e.push(t.normal().negate()),e}getInertia(t){const e=this.end.sub(this.begin).distance()/2;return t*e*e}update(t){this._transform=t}project(t){const e=[],i=[this._getTransformedBegin(),this._getTransformedEnd()],s=i.length;for(let r=0;r<s;r++)e.push(i[r].dot(t));return new Mi(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=I.Green,i=A.Zero){const s=this.begin.add(i),r=this.end.add(i);t.strokeStyle=e.toString(),t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(r.x,r.y),t.closePath(),t.stroke()}debug(t,e){const i=this._getTransformedBegin(),s=this._getTransformedEnd();t.drawLine(i,s,e,2),t.drawCircle(i,2,e),t.drawCircle(s,2,e)}debugDraw(t,e=I.Red){const i=this._getTransformedBegin(),s=this._getTransformedEnd();t.strokeStyle=e.toString(),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s.x,s.y),t.closePath(),t.stroke()}}class Ki extends Oi{constructor(t){var e;super(),this._transformedPoints=[],this._axes=[],this._sides=[],this._localSides=[],this.offset=null!==(e=t.offset)&&void 0!==e?e:A.Zero;const i=!!t.clockwiseWinding;this.points=(i?t.points.reverse():t.points)||[],this._calculateTransformation()}clone(){return new Ki({offset:this.offset.clone(),points:this.points.map((t=>t.clone()))})}get worldPos(){return this._transform?this._transform.pos.add(this.offset):this.offset}get center(){return this.bounds.center}_calculateTransformation(){const t=this._transform,e=t?t.globalPos.add(this.offset):this.offset,i=t?t.globalRotation:0,s=t?t.globalScale:A.One,r=this.points.length;this._transformedPoints.length=0;for(let t=0;t<r;t++)this._transformedPoints[t]=this.points[t].scale(s).rotate(i).add(e)}getTransformedPoints(){return this._calculateTransformation(),this._transformedPoints}getSides(){if(this._sides.length)return this._sides;const t=[],e=this.getTransformedPoints(),i=e.length;for(let s=0;s<i;s++)t.push(new Ni(e[s],e[(s+1)%i]));return this._sides=t,this._sides}getLocalSides(){if(this._localSides.length)return this._localSides;const t=[],e=this.points,i=e.length;for(let s=0;s<i;s++)t.push(new Ni(e[s],e[(s+1)%i]));return this._localSides=t,this._localSides}findSide(t){const e=this.getSides();let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=e[r],o=n.normal().dot(t);o>s&&(i=n,s=o)}return i}findLocalSide(t){const e=this.getLocalSides();let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=e[r],o=n.normal().dot(t);o>s&&(i=n,s=o)}return i}get axes(){if(this._axes.length)return this._axes;const t=this.getSides().map((t=>t.normal()));return this._axes=t,this._axes}update(t){this._transform=t,this._sides.length=0,this._localSides.length=0,this._axes.length=0,this._transformedPoints.length=0,this.getTransformedPoints(),this.getSides(),this.getLocalSides()}contains(t){const e=new Li(t,new A(1,0));return this.getSides().reduce((function(t,i){return e.intersect(i)>=0?t+1:t}),0)%2!=0}getClosestLineBetween(t){if(t instanceof Vi)return Wi.PolygonCircleClosestLine(this,t);if(t instanceof Ki)return Wi.PolygonPolygonClosestLine(this,t);if(t instanceof ji)return Wi.PolygonEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Vi)return qi.CollideCirclePolygon(t,this);if(t instanceof Ki)return qi.CollidePolygonPolygon(this,t);if(t instanceof ji)return qi.CollidePolygonEdge(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){const e=this.getTransformedPoints();let i=null,s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=t.dot(e[r]);n>s&&(s=n,i=e[r])}return i}getFurthestLocalPoint(t){const e=this.points;let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=t.dot(e[r]);n>s&&(s=n,i=e[r])}return i}getClosestFace(t){const e=this.getSides();let i=Number.POSITIVE_INFINITY,s=-1,r=-1;for(let n=0;n<e.length;n++){const o=e[n].distanceToPoint(t);o<i&&(i=o,s=n,r=o)}return-1!==s?{distance:e[s].normal().scale(r),face:e[s]}:null}get bounds(){var t,e,i;const s=this._transform,r=null!==(t=null==s?void 0:s.globalScale)&&void 0!==t?t:A.One,n=null!==(e=null==s?void 0:s.globalRotation)&&void 0!==e?e:0,o=(null!==(i=null==s?void 0:s.globalPos)&&void 0!==i?i:A.Zero).add(this.offset);return this.localBounds.scale(r).rotate(n).translate(o)}get localBounds(){return B.fromPoints(this.points)}getInertia(t){let e=0,i=0;for(let t=0;t<this.points.length;t++){const s=(t+1)%this.points.length,r=this.points[s].cross(this.points[t]);e+=r*(this.points[t].dot(this.points[t])+this.points[t].dot(this.points[s])+this.points[s].dot(this.points[s])),i+=r}return t/6*(e/i)}rayCast(t,e=1/0){const i=this.getSides(),s=i.length;let r=Number.MAX_VALUE,n=-1;for(let o=0;o<s;o++){const s=t.intersect(i[o]);s>=0&&s<r&&s<=e&&(r=s,n=o)}return n>=0?t.getPoint(r):null}project(t){const e=this.getTransformedPoints(),i=e.length;let s=Number.MAX_VALUE,r=-Number.MAX_VALUE;for(let n=0;n<i;n++){const i=e[n].dot(t);s=Math.min(s,i),r=Math.max(r,i)}return new Mi(s,r)}draw(t,e=I.Green,i=A.Zero){const s=i.add(this.offset);t.beginPath(),t.fillStyle=e.toString();const r=this.points[0].add(s);t.moveTo(r.x,r.y),this.points.map((t=>t.add(s))).forEach((function(e){t.lineTo(e.x,e.y)})),t.lineTo(r.x,r.y),t.closePath(),t.fill()}debug(t,e){const i=this.getTransformedPoints()[0],s=[i,...this.getTransformedPoints(),i];for(let i=0;i<s.length-1;i++)t.drawLine(s[i],s[i+1],e,2),t.drawCircle(s[i],2,e),t.drawCircle(s[i+1],2,e)}debugDraw(t,e=I.Red){t.beginPath(),t.strokeStyle=e.toString();const i=this.getTransformedPoints()[0];t.moveTo(i.x,i.y),this.getTransformedPoints().forEach((function(e){t.lineTo(e.x,e.y)})),t.lineTo(i.x,i.y),t.closePath(),t.stroke()}}class Yi{static Box(t,e,i=A.Half,s=A.Zero){return new Ki({points:new B(-t*i.x,-e*i.y,t-t*i.x,e-e*i.y).getPoints(),offset:s})}static Polygon(t,e=!1,i=A.Zero){return new Ki({points:t,offset:i,clockwiseWinding:e})}static Circle(t,e=A.Zero){return new Vi({radius:t,offset:e})}static Edge(t,e){return new ji({begin:t,end:e})}static Capsule(t,e,i=A.Zero){const s=f.getInstance();t===e&&s.warn("A capsule collider with equal width and height is a circle, consider using a ex.Shape.Circle or ex.CircleCollider");if(e>=t){return new Ui([Yi.Circle(t/2,P(0,-e/2+t/2).add(i)),Yi.Box(t,e-t,A.Half,i),Yi.Circle(t/2,P(0,e/2-t/2).add(i))])}return new Ui([Yi.Circle(e/2,P(-t/2+e/2,0).add(i)),Yi.Box(t-e,e,A.Half,i),Yi.Circle(e/2,P(t/2-e/2,0).add(i))])}}class Zi extends Ai{constructor(t){super(),this.type="ex.collider",this.events=new he,this.$colliderAdded=new Bi,this.$colliderRemoved=new Bi,this.set(t)}get(){return this._collider}set(t){return this.clear(),t&&(this._collider=t,this._collider.owner=this.owner,this.events.wire(t.events),this.$colliderAdded.notifyAll(t),this.update()),t}clear(){this._collider&&(this.events.unwire(this._collider.events),this.$colliderRemoved.notifyAll(this._collider),this._collider.owner=null,this._collider=null)}get bounds(){var t,e;return null!==(e=null===(t=this._collider)||void 0===t?void 0:t.bounds)&&void 0!==e?e:new B}get localBounds(){var t,e;return null!==(e=null===(t=this._collider)||void 0===t?void 0:t.localBounds)&&void 0!==e?e:new B}update(){var t;const e=null===(t=this.owner)||void 0===t?void 0:t.get(Ei);this._collider&&(this._collider.owner=this.owner,e&&this._collider.update(e))}collide(t){let e=this._collider,i=t._collider;if(!e||!i)return[];let s=!1;if(i instanceof Ui&&(e=i,i=this._collider,s=!0),this._collider){const r=e.collide(i);return r?(s&&r.forEach((e=>{e.mtv=e.mtv.negate(),e.normal=e.normal.negate(),e.tangent=e.normal.perpendicular(),e.colliderA=this._collider,e.colliderB=t._collider})),r):[]}return[]}onAdd(t){this._collider&&this.update(),this.events.on("precollision",(e=>{const i=e;t.events.emit("precollision",new jt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("postcollision",(e=>{const i=e;t.events.emit("postcollision",new Kt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("collisionstart",(e=>{const i=e;t.events.emit("collisionstart",new Jt(i.target.owner,i.other.owner,i.contact))})),this.events.on("collisionend",(e=>{const i=e;t.events.emit("collisionend",new te(i.target.owner,i.other.owner))}))}onRemove(){this.events.clear(),this.$colliderRemoved.notifyAll(this._collider)}useBoxCollider(t,e,i=A.Half,s=A.Zero){const r=Yi.Box(t,e,i,s);return this.set(r)}usePolygonCollider(t,e=A.Zero){const i=Yi.Polygon(t,!1,e);return this.set(i)}useCircleCollider(t,e=A.Zero){const i=Yi.Circle(t,e);return this.set(i)}useEdgeCollider(t,e){const i=Yi.Edge(t,e);return this.set(i)}useCompositeCollider(t){return this.set(new Ui(t))}}var Qi;!function(t){t.Rotation="rotation",t.X="x",t.Y="y"}(Qi||(Qi={}));class $i extends Ai{constructor(t){var e,i,s;super(),this.type="ex.body",this.dependencies=[Ei,Ii],this.id=_("body",$i._ID++),this.events=new he,this.collisionType=vi.PreventCollision,this.group=Ri.All,this.mass=Ci.defaultMass,this.sleepMotion=5*Ci.sleepEpsilon,this.canSleep=Ci.bodiesCanSleepByDefault,this._sleeping=!1,this.bounciness=.2,this.friction=.99,this.useGravity=!0,this.limitDegreeOfFreedom=[],this.oldPos=new A(0,0),this.oldVel=new A(0,0),this.oldAcc=A.Zero,this.oldRotation=0,this.oldScale=A.One,t&&(this.collisionType=null!==(e=t.type)&&void 0!==e?e:this.collisionType,this.group=null!==(i=t.group)&&void 0!==i?i:this.group,this.useGravity=null!==(s=t.useGravity)&&void 0!==s?s:this.useGravity)}get inverseMass(){return this.collisionType===vi.Fixed?0:1/this.mass}get sleeping(){return this._sleeping}setSleeping(t){this._sleeping=t,t?(this.vel=A.Zero,this.acc=A.Zero,this.angularVelocity=0,this.sleepMotion=0):this.sleepMotion=5*Ci.sleepEpsilon}updateMotion(){this._sleeping&&this.setSleeping(!0);const t=this.vel.size*this.vel.size+Math.abs(this.angularVelocity*this.angularVelocity),e=Ci.sleepBias;this.sleepMotion=e*this.sleepMotion+(1-e)*t,this.sleepMotion=z(this.sleepMotion,0,10*Ci.sleepEpsilon),this.canSleep&&this.sleepMotion<Ci.sleepEpsilon&&this.setSleeping(!0)}get inertia(){const t=this.owner.get(Zi);return(null==t?void 0:t.get())?t.get().getInertia(this.mass):0}get inverseInertia(){return this.collisionType===vi.Fixed?0:1/this.inertia}get active(){var t;return!!(null===(t=this.owner)||void 0===t?void 0:t.active)}get center(){return this.pos}get transform(){var t;return null===(t=this.owner)||void 0===t?void 0:t.get(Ei)}get motion(){var t;return null===(t=this.owner)||void 0===t?void 0:t.get(Ii)}get pos(){return this.transform.globalPos}set pos(t){this.transform.globalPos=t}get vel(){return this.motion.vel}set vel(t){this.motion.vel=t}get acc(){return this.motion.acc}set acc(t){this.motion.acc=t}get torque(){return this.motion.torque}set torque(t){this.motion.torque=t}get rotation(){return this.transform.globalRotation}set rotation(t){this.transform.globalRotation=t}get scale(){return this.transform.globalScale}set scale(t){this.transform.globalScale=t}get sx(){return this.motion.scaleFactor.x}set sx(t){this.motion.scaleFactor.x=t}get sy(){return this.motion.scaleFactor.y}set sy(t){this.motion.scaleFactor.y=t}get rx(){return this.motion.angularVelocity}set rx(t){this.motion.angularVelocity=t}get angularVelocity(){return this.motion.angularVelocity}set angularVelocity(t){this.motion.angularVelocity=t}applyImpulse(t,e){if(this.collisionType!==vi.Active)return;const i=e.scale(this.inverseMass);if(this.limitDegreeOfFreedom.includes(Qi.X)&&(i.x=0),this.limitDegreeOfFreedom.includes(Qi.Y)&&(i.y=0),this.vel.addEqual(i),!this.limitDegreeOfFreedom.includes(Qi.Rotation)){const i=t.sub(this.pos);this.angularVelocity+=this.inverseInertia*i.cross(e)}}applyLinearImpulse(t){if(this.collisionType!==vi.Active)return;const e=t.scale(this.inverseMass);this.limitDegreeOfFreedom.includes(Qi.X)&&(e.x=0),this.limitDegreeOfFreedom.includes(Qi.Y)&&(e.y=0),this.vel=this.vel.add(e)}applyAngularImpulse(t,e){if(this.collisionType===vi.Active&&!this.limitDegreeOfFreedom.includes(Qi.Rotation)){const i=t.sub(this.pos);this.angularVelocity+=this.inverseInertia*i.cross(e)}}captureOldTransform(){this.oldVel.setTo(this.vel.x,this.vel.y),this.oldPos.setTo(this.pos.x,this.pos.y),this.oldAcc.setTo(this.acc.x,this.acc.y),this.oldScale.setTo(this.scale.x,this.scale.y),this.oldRotation=this.rotation}debugDraw(t){}}$i._ID=0;class Ji{constructor(){this._topLeft=new A(0,0),this._topRight=new A(0,0),this._bottomLeft=new A(0,0),this._bottomRight=new A(0,0)}isSpriteOffScreen(t,e){const i=t.currentDrawing.drawWidth,s=t.currentDrawing.drawHeight,r=t.rotation,n=t.center,o=t.getGlobalPos();this._topLeft=P(o.x-i/2,o.y-s/2),this._topLeft=this._topLeft.rotate(r,n),this._topRight=P(o.x+i/2,o.y-s/2),this._topRight=this._topRight.rotate(r,n),this._bottomLeft=P(o.x-i/2,o.y+s/2),this._bottomLeft=this._bottomLeft.rotate(r,n),this._bottomRight=P(o.x+i/2,o.y+s/2),this._bottomRight=this._bottomRight.rotate(r,n);const a=e.worldToScreenCoordinates(this._topLeft),h=e.worldToScreenCoordinates(this._topRight),l=e.worldToScreenCoordinates(this._bottomLeft),c=e.worldToScreenCoordinates(this._bottomRight);this._xCoords=[],this._yCoords=[],this._xCoords.push(a.x,h.x,l.x,c.x),this._yCoords.push(a.y,h.y,l.y,c.y),this._xMin=Math.min.apply(null,this._xCoords),this._yMin=Math.min.apply(null,this._yCoords),this._xMax=Math.max.apply(null,this._xCoords),this._yMax=Math.max.apply(null,this._yCoords);const d=e.screenToWorldCoordinates(new A(this._xMin,this._yMin)),u=e.screenToWorldCoordinates(new A(this._xMax,this._yMax));this._xMinWorld=d.x,this._yMinWorld=d.y,this._xMaxWorld=u.x,this._yMaxWorld=u.y;const p=[new A(this._xMin,this._yMin),new A(this._xMax,this._yMin),new A(this._xMin,this._yMax),new A(this._xMax,this._yMax)];if(p[0].x<0&&p[1].x>e.canvas.clientWidth&&(p[0].y>0||p[2].y<e.canvas.clientHeight))return!1;if(p[0].y<0&&p[2].y>e.canvas.clientHeight&&(p[1].x>0||p[0].x<e.canvas.clientWidth))return!1;for(let t=0;t<p.length;t++)if(p[t].x>0&&p[t].y>0&&p[t].x<e.canvas.clientWidth&&p[t].y<e.canvas.clientHeight)return!1;return!0}debugDraw(t){t.beginPath(),t.strokeStyle=I.White.toString(),t.rect(this._xMinWorld,this._yMinWorld,this._xMaxWorld-this._xMinWorld,this._yMaxWorld-this._yMinWorld),t.stroke(),t.fillStyle=I.Red.toString(),t.beginPath(),t.arc(this._topLeft.x,this._topLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Green.toString(),t.beginPath(),t.arc(this._topRight.x,this._topRight.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Blue.toString(),t.beginPath(),t.arc(this._bottomLeft.x,this._bottomLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Magenta.toString(),t.beginPath(),t.arc(this._bottomRight.x,this._bottomRight.y,5,0,2*Math.PI),t.closePath(),t.fill()}}class ts{constructor(){this.cullingBox=new Ji}update(t,e){const i=t.eventDispatcher;let s=!0;null!=t.currentDrawing&&(s=this.cullingBox.isSpriteOffScreen(t,e));let r=!1;e&&e.currentScene&&e.currentScene.camera&&e.currentScene.camera.viewport&&!t.parent&&(r=!e.currentScene.camera.viewport.intersect(t.collider.bounds)),t.isOffScreen?r&&s||(i.emit("enterviewport",new ne(t)),t.removeComponent("offscreen")):r&&s&&(i.emit("exitviewport",new re(t)),t.addComponent(new Pi("offscreen")))}}class es{constructor(t){this.data=t,this.type="Component Added"}}function is(t){return!!t&&"Component Added"===t.type}class ss{constructor(t){this.data=t,this.type="Component Removed"}}function rs(t){return!!t&&"Component Removed"===t.type}class ns extends hi{constructor(t,e){if(super(),this.id=ns._ID++,this._name="anonymous",this.active=!0,this._componentsToRemove=[],this._componentTypeToInstance=new Map,this._componentStringToInstance=new Map,this._tagsMemo=[],this._typesMemo=[],this.componentAdded$=new Bi,this.componentRemoved$=new Bi,this._parent=null,this.childrenAdded$=new Bi,this.childrenRemoved$=new Bi,this._children=[],this._isInitialized=!1,this._setName(e),t)for(const e of t)this.addComponent(e)}_setName(t){t&&(this._name=t)}get name(){return this._name}get events(){return this.eventDispatcher}kill(){this.active=!1}isKilled(){return!this.active}get tags(){return this._tagsMemo}hasTag(t){return this.tags.includes(t)}addTag(t){return this.addComponent(new Pi(t))}removeTag(t,e=!1){return this.removeComponent(t,e)}get types(){return this._typesMemo}_rebuildMemos(){this._tagsMemo=Array.from(this._componentStringToInstance.values()).filter((t=>t instanceof Pi)).map((t=>t.type)),this._typesMemo=Array.from(this._componentStringToInstance.keys())}getComponents(){return Array.from(this._componentStringToInstance.values())}_notifyAddComponent(t){this._rebuildMemos();const e=new es({component:t,entity:this});this.componentAdded$.notifyAll(e)}_notifyRemoveComponent(t){const e=new ss({component:t,entity:this});this.componentRemoved$.notifyAll(e),this._rebuildMemos()}get parent(){return this._parent}get children(){return this._children}unparent(){this._parent&&(this._parent.removeChild(this),this._parent=null)}addChild(t){if(null!==t.parent)throw new Error("Entity already has a parent, cannot add without unparenting");if(this.getAncestors().includes(t))throw new Error("Cycle detected, cannot add entity");return this._children.push(t),t._parent=this,this.childrenAdded$.notifyAll(t),this}removeChild(t){return t.parent===this&&(tt(t,this._children),t._parent=null,this.childrenRemoved$.notifyAll(t)),this}removeAllChildren(){return this.children.forEach((t=>{this.removeChild(t)})),this}getAncestors(){const t=[this];let e=this.parent;for(;e;)t.push(e),e=e.parent;return t.reverse()}getDescendants(){let t=[this],e=[this];for(;e.length>0;){const i=e.pop();e=e.concat(i.children),t=t.concat(i.children)}return t}clone(){const t=new ns;for(const e of this.types)t.addComponent(this.get(e).clone());for(const e of this.children)t.addChild(e.clone());return t}addTemplate(t,e=!1){for(const i of t.getComponents())this.addComponent(i.clone(),e);for(const e of t.children)this.addChild(e.clone().addTemplate(e));return this}addComponent(t,e=!1){if(this.has(t.type)){if(!e)return this;this.removeComponent(t)}if(t.dependencies&&t.dependencies.length)for(const e of t.dependencies)this.addComponent(new e);t.owner=this;const i=t.constructor;return this._componentTypeToInstance.set(i,t),this._componentStringToInstance.set(t.type,t),t.onAdd&&t.onAdd(this),this._notifyAddComponent(t),this}removeComponent(t,e=!1){return e?"string"==typeof t?this._removeComponentByType(t):t instanceof Ai&&this._removeComponentByType(t.type):this._componentsToRemove.push(t),this}_removeComponentByType(t){if(this.has(t)){const e=this.get(t);e.owner=null,e.onRemove&&e.onRemove(this);const i=e.constructor;this._componentTypeToInstance.delete(i),this._componentStringToInstance.delete(e.type),this._notifyRemoveComponent(e)}}processComponentRemoval(){for(const t of this._componentsToRemove){const e="string"==typeof t?t:t.type;this._removeComponentByType(e)}this._componentsToRemove.length=0}has(t){return"string"==typeof t?this._componentStringToInstance.has(t):this._componentTypeToInstance.has(t)}get(t){return"string"==typeof t?this._componentStringToInstance.get(t):this._componentTypeToInstance.get(t)}get isInitialized(){return this._isInitialized}_initialize(t){this.isInitialized||(this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0)}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}onInitialize(t){}onPreUpdate(t,e){}onPostUpdate(t,e){}update(t,e){this._initialize(t),this._preupdate(t,e);for(const i of this.children)i.update(t,e);this._postupdate(t,e)}}ns._ID=0;class os extends Ai{constructor(t){var e;super(),this.draw=t,this.type="ex.canvas",this.draw=null!==(e=this.draw)&&void 0!==e?e:()=>{}}}function as(t){return!!t.tick}class hs{constructor(t,e){this._options=t,this._graphics=e,this.graphics=[]}get name(){return this._options.name}hide(t){if(t){let e=null;e=t instanceof _t?t:this._graphics.getGraphic(t),this.graphics=this.graphics.filter((t=>t.graphic!==e))}else this.graphics.length=0}show(t,e){let i;return e={...e},t instanceof _t?i=this._graphics.copyGraphics?t.clone():t:(i=this._graphics.getGraphic(t),i||f.getInstance().error(`No such graphic added to component named ${t}. These named graphics are available: `,this._graphics.getNames())),i?(this.graphics.push({graphic:i,options:e}),i):null}use(t,e){return e={...e},this.hide(),this.show(t,e)}get order(){return this._options.order}set order(t){this._options.order=t}get offset(){var t;return null!==(t=this._options.offset)&&void 0!==t?t:A.Zero}set offset(t){this._options.offset=t}get currentKeys(){var t;return null!==(t=this.name)&&void 0!==t?t:"anonymous"}}class ls{constructor(t){this._component=t,this._layers=[],this._layerMap={},this.default=new hs({name:"default",order:0},t),this._maybeAddLayer(this.default)}create(t){const e=new hs(t,this._component);return this._maybeAddLayer(e)}get(t){return t?this._getLayer(t):this._layers}currentKeys(){const t=[];for(const e of this._layers)t.push(e.currentKeys);return t}has(t){return t in this._layerMap}_maybeAddLayer(t){return this._layerMap[t.name]?this._layerMap[t.name]:(this._layerMap[t.name]=t,this._layers.push(t),this._layers.sort(((t,e)=>t.order-e.order)),t)}_getLayer(t){return this._layerMap[t]}}class cs extends Ai{constructor(t){super(),this.type="ex.graphics",this._graphics={},this.visible=!0,this.opacity=1,this.offset=A.Zero,this.anchor=A.Half,this.copyGraphics=!1,this._bounds=null,t={visible:this.visible,...t};const{current:e,anchor:i,opacity:s,visible:r,graphics:n,offset:o,copyGraphics:a,onPreDraw:h,onPostDraw:l}=t;this._graphics=n||{},this.offset=null!=o?o:this.offset,this.opacity=null!=s?s:this.opacity,this.anchor=null!=i?i:this.anchor,this.copyGraphics=null!=a?a:this.copyGraphics,this.onPreDraw=null!=h?h:this.onPreDraw,this.onPostDraw=null!=l?l:this.onPostDraw,this.visible=!!r,this.layers=new ls(this),e&&this._graphics[e]&&this.show(this._graphics[e])}getGraphic(t){return this._graphics[t]}getNames(){return Object.keys(this._graphics)}get current(){return this.layers.default.graphics}get graphics(){return this._graphics}add(t,e){let i="default",s=null;return"string"==typeof t?(i=t,s=e):s=t,this._graphics[i]=this.copyGraphics?s.clone():s,"default"===i&&this.show("default"),s}show(t,e){return this.layers.default.show(t,e)}use(t,e){return this.layers.default.use(t,e)}hide(t){this.layers.default.hide(t)}set localBounds(t){this._bounds=t}get localBounds(){if(this._bounds)return this._bounds;let t=new B;for(const e of this.layers.get())for(const{graphic:i,options:s}of e.graphics){let r=this.anchor,n=this.offset;(null==s?void 0:s.anchor)&&(r=s.anchor),(null==s?void 0:s.offset)&&(n=s.offset);const o=i.localBounds,a=-o.width*r.x+n.x,h=-o.height*r.y+n.y;t=null==i?void 0:i.localBounds.translate(P(a+e.offset.x,h+e.offset.y)).combine(t)}return t}update(t,e=0){for(const i of this.layers.get())for(const{graphic:s}of i.graphics)as(s)&&(null==s||s.tick(t,e))}}class ds extends Ct{constructor(t){super(t),this.width=t.width,this.height=t.height,this.rasterize()}clone(){return new ds({width:this.width,height:this.height,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){this.color&&t.fillRect(0,0,this.width,this.height),this.strokeColor&&t.strokeRect(0,0,this.width,this.height)}}class us extends Ct{constructor(t){var e,i;super(t),this._radius=0,this.padding=null!==(e=t.padding)&&void 0!==e?e:2,this.radius=t.radius,this.filtering=null!==(i=t.filtering)&&void 0!==i?i:ht.Blended,this.rasterize()}get radius(){return this._radius}set radius(t){this._radius=t,this.width=2*this._radius,this.height=2*this._radius,this.flagDirty()}clone(){return new us({radius:this.radius,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){this.radius>0&&(t.beginPath(),t.arc(this.radius,this.radius,this.radius,0,2*Math.PI),this.color&&t.fill(),this.strokeColor&&t.stroke())}}class ps extends Ai{constructor(){super(...arguments),this.type="ex.pointer",this.useColliderShape=!0,this.useGraphicsBounds=!1}}var gs,_s=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class fs{static CreateReversibleEasingFunction(t){return(e,i,s,r)=>s<i?i-(t(e,s,i,r)-s):t(e,i,s,r)}static CreateReversableEasingFunction(t){return fs.CreateReversibleEasingFunction(t)}static CreateVectorEasingFunction(t){return(e,i,s,r)=>new A(t(e,i.x,s.x,r),t(e,i.y,s.y,r))}}fs.Linear=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*t/s+e)),fs.EaseInQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t+e)),fs.EaseOutQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>-(i-=e)*(t/=s)*(t-2)+e)),fs.EaseInOutQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e,(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e))),fs.EaseInCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t*t+e)),fs.EaseOutCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(t/=s,(i-=e)*(--t*t*t+1)+e))),fs.EaseInOutCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e,(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e))),_s([C({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"CreateReversibleEasingFunction"})],fs,"CreateReversableEasingFunction",null);class ms{constructor(t){this._actions=[],this._completedActions=[],this._entity=t}add(t){this._actions.push(t)}remove(t){const e=this._actions.indexOf(t);this._actions.splice(e,1)}clearActions(){this._actions.length=0,this._completedActions.length=0,this._currentAction&&this._currentAction.stop()}getActions(){return this._actions.concat(this._completedActions)}hasNext(){return this._actions.length>0}isComplete(){return 0===this._actions.length}reset(){this._actions=this.getActions();const t=this._actions.length;for(let e=0;e<t;e++)this._actions[e].reset();this._completedActions=[]}update(t){this._actions.length>0&&(this._currentAction=this._actions[0],this._currentAction.update(t),this._currentAction.isComplete(this._entity)&&this._completedActions.push(this._actions.shift()))}}class vs{constructor(t,e,i){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new ks(t),this._actionQueue=this._repeatContext.getQueue(),this._repeat=i,this._originalRepeat=i,this._repeatBuilder(this._repeatContext),this._repeat--}update(t){this._actionQueue.isComplete()&&(this._actionQueue.clearActions(),this._repeatBuilder(this._repeatContext),this._repeat--),this._actionQueue.update(t)}isComplete(){return this._stopped||this._repeat<=0&&this._actionQueue.isComplete()}stop(){this._stopped=!0}reset(){this._repeat=this._originalRepeat}}class ys{constructor(t,e){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new ks(t),this._actionQueue=this._repeatContext.getQueue(),this._repeatBuilder(this._repeatContext)}update(t){this._stopped||(this._actionQueue.isComplete()&&(this._actionQueue.clearActions(),this._repeatBuilder(this._repeatContext)),this._actionQueue.update(t))}isComplete(){return this._stopped}stop(){this._stopped=!0,this._actionQueue.clearActions()}reset(){}}class ws{constructor(t,e,i,s){if(this._started=!1,this._stopped=!1,this._entity=t,this._tx=t.get(Ei),this._motion=t.get(Ii),this._speed=s,this._offset=new A(e,i),s<=0)throw f.getInstance().error("Attempted to moveBy with speed less than or equal to zero : "+s),new Error("Speed must be greater than 0 pixels per second")}update(t){this._started||(this._started=!0,this._start=new A(this._tx.pos.x,this._tx.pos.y),this._end=this._start.add(this._offset),this._distance=this._offset.size,this._dir=this._end.sub(this._start).normalize()),this.isComplete(this._entity)?(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0)):this._motion.vel=this._dir.scale(this._speed)}isComplete(t){const e=t.get(Ei);return this._stopped||e.pos.distance(this._start)>=this._distance}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}class xs{constructor(t,e,i,s){this.entity=t,this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._end=new A(e,i),this._speed=s}update(t){this._started||(this._started=!0,this._start=new A(this._tx.pos.x,this._tx.pos.y),this._distance=this._start.distance(this._end),this._dir=this._end.sub(this._start).normalize());const e=this._dir.scale(this._speed);this._motion.vel=P(e.x,e.y),this.isComplete(this.entity)&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}isComplete(t){const e=t.get(Ei);return this._stopped||new A(e.pos.x,e.pos.y).distance(this._start)>=this._distance}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}!function(t){t[t.ShortestPath=0]="ShortestPath",t[t.LongestPath=1]="LongestPath",t[t.Clockwise=2]="Clockwise",t[t.CounterClockwise=3]="CounterClockwise"}(gs||(gs={}));class bs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._end=e,this._speed=i,this._rotationType=s||gs.ShortestPath}update(t){if(!this._started){this._started=!0,this._start=this._tx.rotation,this._currentNonCannonAngle=this._tx.rotation;const t=Math.abs(this._end-this._start),e=k-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+k)%k>=Math.PI,this._rotationType){case gs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case gs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case gs.Clockwise:this._direction=1,this._shortestPathIsPositive?this._distance=this._shortDistance:this._distance=this._longDistance;break;case gs.CounterClockwise:this._direction=-1,this._shortestPathIsPositive?this._distance=this._longDistance:this._distance=this._shortDistance}}this._motion.angularVelocity=this._direction*this._speed,this._currentNonCannonAngle+=this._direction*this._speed*(t/1e3),this.isComplete()&&(this._tx.rotation=this._end,this._motion.angularVelocity=0,this._stopped=!0)}isComplete(){const t=Math.abs(this._currentNonCannonAngle-this._start);return this._stopped||t>=Math.abs(this._distance)}stop(){this._motion.angularVelocity=0,this._stopped=!0}reset(){this._started=!1}}class Cs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._speed=i,this._offset=e,this._rotationType=s||gs.ShortestPath}update(t){if(!this._started){this._started=!0,this._start=this._tx.rotation,this._currentNonCannonAngle=this._tx.rotation,this._end=this._start+this._offset;const t=Math.abs(this._end-this._start),e=k-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+k)%k>=Math.PI,this._rotationType){case gs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case gs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case gs.Clockwise:this._direction=1,this._shortDistance>=0?this._distance=this._shortDistance:this._distance=this._longDistance;break;case gs.CounterClockwise:this._direction=-1,this._shortDistance<=0?this._distance=this._shortDistance:this._distance=this._longDistance}}this._motion.angularVelocity=this._direction*this._speed,this._currentNonCannonAngle+=this._direction*this._speed*(t/1e3),this.isComplete()&&(this._tx.rotation=this._end,this._motion.angularVelocity=0,this._stopped=!0)}isComplete(){const t=Math.abs(this._currentNonCannonAngle-this._start);return this._stopped||t>=Math.abs(this._distance)}stop(){this._motion.angularVelocity=0,this._stopped=!0}reset(){this._started=!1}}class Ss{constructor(t,e,i,s,r){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._endX=e,this._endY=i,this._speedX=s,this._speedY=r}update(t){if(this._started||(this._started=!0,this._startX=this._tx.scale.x,this._startY=this._tx.scale.y,this._distanceX=Math.abs(this._endX-this._startX),this._distanceY=Math.abs(this._endY-this._startY)),Math.abs(this._tx.scale.x-this._startX)>=this._distanceX)this._motion.scaleFactor.x=0;else{const t=this._endY<this._startY?-1:1;this._motion.scaleFactor.x=this._speedX*t}if(Math.abs(this._tx.scale.y-this._startY)>=this._distanceY)this._motion.scaleFactor.y=0;else{const t=this._endY<this._startY?-1:1;this._motion.scaleFactor.y=this._speedY*t}this.isComplete()&&(this._tx.scale=P(this._endX,this._endY),this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0)}isComplete(){return this._stopped||Math.abs(this._tx.scale.y-this._startX)>=this._distanceX&&Math.abs(this._tx.scale.y-this._startY)>=this._distanceY}stop(){this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0,this._stopped=!0}reset(){this._started=!1}}class As{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._offset=new A(e,i),this._speedX=this._speedY=s}update(t){this._started||(this._started=!0,this._startScale=this._tx.scale.clone(),this._endScale=this._startScale.add(this._offset),this._distanceX=Math.abs(this._endScale.x-this._startScale.x),this._distanceY=Math.abs(this._endScale.y-this._startScale.y),this._directionX=this._endScale.x<this._startScale.x?-1:1,this._directionY=this._endScale.y<this._startScale.y?-1:1),this._motion.scaleFactor.x=this._speedX*this._directionX,this._motion.scaleFactor.y=this._speedY*this._directionY,this.isComplete()&&(this._tx.scale=this._endScale,this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0)}isComplete(){return this._stopped||Math.abs(this._tx.scale.x-this._startScale.x)>=this._distanceX&&Math.abs(this._tx.scale.y-this._startScale.y)>=this._distanceY}stop(){this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0,this._stopped=!0}reset(){this._started=!1}}class Ps{constructor(t){this._method=null,this._hasBeenCalled=!1,this._method=t}update(t){this._method(),this._hasBeenCalled=!0}isComplete(){return this._hasBeenCalled}reset(){this._hasBeenCalled=!1}stop(){this._hasBeenCalled=!0}}class Ts{constructor(t,e,i,s,r){this.easingFcn=r,this._currentLerpTime=0,this._lerpDuration=1e3,this._lerpStart=new A(0,0),this._lerpEnd=new A(0,0),this._initialized=!1,this._stopped=!1,this._distance=0,this._tx=t.get(Ei),this._motion=t.get(Ii),this._lerpDuration=s,this._lerpEnd=new A(e,i)}_initialize(){this._lerpStart=new A(this._tx.pos.x,this._tx.pos.y),this._currentLerpTime=0,this._distance=this._lerpStart.distance(this._lerpEnd)}update(t){this._initialized||(this._initialize(),this._initialized=!0),this._currentLerpTime+=t;let e=this._tx.pos.x,i=this._tx.pos.y;this._currentLerpTime<this._lerpDuration?(e=this._lerpEnd.x<this._lerpStart.x?this._lerpStart.x-(this.easingFcn(this._currentLerpTime,this._lerpEnd.x,this._lerpStart.x,this._lerpDuration)-this._lerpEnd.x):this.easingFcn(this._currentLerpTime,this._lerpStart.x,this._lerpEnd.x,this._lerpDuration),i=this._lerpEnd.y<this._lerpStart.y?this._lerpStart.y-(this.easingFcn(this._currentLerpTime,this._lerpEnd.y,this._lerpStart.y,this._lerpDuration)-this._lerpEnd.y):this.easingFcn(this._currentLerpTime,this._lerpStart.y,this._lerpEnd.y,this._lerpDuration),this._motion.vel=P((e-this._tx.pos.x)/(t/1e3),(i-this._tx.pos.y)/(t/1e3))):(this._tx.pos=P(this._lerpEnd.x,this._lerpEnd.y),this._motion.vel=A.Zero)}isComplete(t){return this._stopped||new A(t.pos.x,t.pos.y).distance(this._lerpStart)>=this._distance}reset(){this._initialized=!1}stop(){this._motion.vel=P(0,0),this._stopped=!0}}class Es{constructor(t,e,i,s=1){this._timeVisible=0,this._timeNotVisible=0,this._elapsedTime=0,this._totalTime=0,this._stopped=!1,this._started=!1,this._graphics=t.get(cs),this._timeVisible=e,this._timeNotVisible=i,this._duration=(e+i)*s}update(t){this._started||(this._started=!0),this._graphics&&(this._elapsedTime+=t,this._totalTime+=t,this._graphics.visible&&this._elapsedTime>=this._timeVisible&&(this._graphics.visible=!1,this._elapsedTime=0),!this._graphics.visible&&this._elapsedTime>=this._timeNotVisible&&(this._graphics.visible=!0,this._elapsedTime=0),this.isComplete()&&(this._graphics.visible=!0))}isComplete(){return this._stopped||this._totalTime>=this._duration}stop(){this._graphics&&(this._graphics.visible=!0),this._stopped=!0}reset(){this._started=!1,this._elapsedTime=0,this._totalTime=0}}class Is{constructor(t,e,i){this._multiplier=1,this._started=!1,this._stopped=!1,this._graphics=t.get(cs),this._endOpacity=e,this._speed=i}update(t){this._graphics&&(this._started||(this._started=!0,this._endOpacity<this._graphics.opacity?this._multiplier=-1:this._multiplier=1),this._speed>0&&(this._graphics.opacity+=this._multiplier*(Math.abs(this._graphics.opacity-this._endOpacity)*t)/this._speed),this._speed-=t,this.isComplete()&&(this._graphics.opacity=this._endOpacity),f.getInstance().debug("[Action fade] Actor opacity:",this._graphics.opacity))}isComplete(){return this._stopped||Math.abs(this._graphics.opacity-this._endOpacity)<.05}stop(){this._stopped=!0}reset(){this._started=!1}}class Rs{constructor(t){this._elapsedTime=0,this._started=!1,this._stopped=!1,this._delay=t}update(t){this._started||(this._started=!0),this._elapsedTime+=t}isComplete(){return this._stopped||this._elapsedTime>=this._delay}stop(){this._stopped=!0}reset(){this._elapsedTime=0,this._started=!1}}class Bs{constructor(t){this._stopped=!1,this._entity=t}update(t){this._entity.get(Fs).clearActions(),this._entity.kill(),this._stopped=!0}isComplete(){return this._stopped}stop(){}reset(){}}class Ds{constructor(t,e,i){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._followTx=e.get(Ei),this._followMotion=e.get(Ii),this._current=new A(this._tx.pos.x,this._tx.pos.y),this._end=new A(this._followTx.pos.x,this._followTx.pos.y),this._maximumDistance=void 0!==i?i:this._current.distance(this._end),this._speed=0}update(t){this._started||(this._started=!0,this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize());const e=Math.sqrt(Math.pow(this._followMotion.vel.x,2)+Math.pow(this._followMotion.vel.y,2));if(0!==e&&(this._speed=e),this._current=P(this._tx.pos.x,this._tx.pos.y),this._end=P(this._followTx.pos.x,this._followTx.pos.y),this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize(),this._distanceBetween>=this._maximumDistance){const t=this._dir.scale(this._speed);this._motion.vel=P(t.x,t.y)}else this._motion.vel=P(0,0);this.isComplete()&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}stop(){this._motion.vel=P(0,0),this._stopped=!0}isComplete(){return this._stopped}reset(){this._started=!1}}class Ms{constructor(t,e,i){this._started=!1,this._stopped=!1,this._speedWasSpecified=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._meetTx=e.get(Ei),this._meetMotion=e.get(Ii),this._current=new A(this._tx.pos.x,this._tx.pos.y),this._end=new A(this._meetTx.pos.x,this._meetTx.pos.y),this._speed=i||0,void 0!==i&&(this._speedWasSpecified=!0)}update(t){this._started||(this._started=!0,this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize());const e=Math.sqrt(Math.pow(this._meetMotion.vel.x,2)+Math.pow(this._meetMotion.vel.y,2));0===e||this._speedWasSpecified||(this._speed=e),this._current=P(this._tx.pos.x,this._tx.pos.y),this._end=P(this._meetTx.pos.x,this._meetTx.pos.y),this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize();const i=this._dir.scale(this._speed);this._motion.vel=P(i.x,i.y),this.isComplete()&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}isComplete(){return this._stopped||this._distanceBetween<=1}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}class ks{constructor(t){this._entity=t,this._queue=new ms(t)}getQueue(){return this._queue}update(t){this._queue.update(t)}clearActions(){this._queue.clearActions()}easeTo(...t){var e,i;let s=0,r=0,n=0,o=fs.Linear;return t[0]instanceof A?(s=t[0].x,r=t[0].y,n=t[1],o=null!==(e=t[2])&&void 0!==e?e:o):(s=t[0],r=t[1],n=t[2],o=null!==(i=t[3])&&void 0!==i?i:o),this._queue.add(new Ts(this._entity,s,r,n,o)),this}moveTo(t,e,i){let s=0,r=0,n=0;return t instanceof A?(s=t.x,r=t.y,n=e):(s=t,r=e,n=i),this._queue.add(new xs(this._entity,s,r,n)),this}moveBy(t,e,i){let s=0,r=0,n=0;return t instanceof A?(s=t.x,r=t.y,n=e):(s=t,r=e,n=i),this._queue.add(new ws(this._entity,s,r,n)),this}rotateTo(t,e,i){return this._queue.add(new bs(this._entity,t,e,i)),this}rotateBy(t,e,i){return this._queue.add(new Cs(this._entity,t,e,i)),this}scaleTo(t,e,i,s){let r=1,n=1,o=0,a=0;return t instanceof A&&e instanceof A&&(r=t.x,n=t.y,o=e.x,a=e.y),"number"==typeof t&&"number"==typeof e&&(r=t,n=e,o=i,a=s),this._queue.add(new Ss(this._entity,r,n,o,a)),this}scaleBy(t,e,i){let s=1,r=1;return t instanceof A&&(s=t.x,r=t.y,i=e),"number"==typeof t&&"number"==typeof e&&(s=t,r=e),this._queue.add(new As(this._entity,s,r,i)),this}blink(t,e,i=1){return this._queue.add(new Es(this._entity,t,e,i)),this}fade(t,e){return this._queue.add(new Is(this._entity,t,e)),this}delay(t){return this._queue.add(new Rs(t)),this}die(){return this._queue.add(new Bs(this._entity)),this}callMethod(t){return this._queue.add(new Ps(t)),this}repeat(t,e){return e?(this._queue.add(new vs(this._entity,t,e)),this):(this.repeatForever(t),this)}repeatForever(t){return this._queue.add(new ys(this._entity,t)),this}follow(t,e){return void 0===e?this._queue.add(new Ds(this._entity,t)):this._queue.add(new Ds(this._entity,t,e)),this}meet(t,e){return void 0===e?this._queue.add(new Ms(this._entity,t)):this._queue.add(new Ms(this._entity,t,e)),this}asPromise(){return this.toPromise()}toPromise(){return new Promise((t=>{this._queue.add(new Ps((()=>{t()})))}))}}class Fs extends Ai{constructor(){super(...arguments),this.type="ex.actions",this.dependencies=[Ei,Ii]}onAdd(t){this._ctx=new ks(t)}onRemove(){this._ctx=null}getQueue(){var t;return null===(t=this._ctx)||void 0===t?void 0:t.getQueue()}update(t){var e;return null===(e=this._ctx)||void 0===e?void 0:e.update(t)}clearActions(){var t;null===(t=this._ctx)||void 0===t||t.clearActions()}easeTo(...t){return this._ctx.easeTo.apply(this._ctx,t)}moveTo(t,e,i){return this._ctx.moveTo.apply(this._ctx,[t,e,i])}moveBy(t,e,i){return this._ctx.moveBy.apply(this._ctx,[t,e,i])}rotateTo(t,e,i){return this._ctx.rotateTo(t,e,i)}rotateBy(t,e,i){return this._ctx.rotateBy(t,e,i)}scaleTo(t,e,i,s){return this._ctx.scaleTo.apply(this._ctx,[t,e,i,s])}scaleBy(t,e,i){return this._ctx.scaleBy.apply(this._ctx,[t,e,i])}blink(t,e,i){return this._ctx.blink(t,e,i)}fade(t,e){return this._ctx.fade(t,e)}delay(t){return this._ctx.delay(t)}die(){return this._ctx.die()}callMethod(t){return this._ctx.callMethod(t)}repeat(t,e){return this._ctx.repeat(t,e)}repeatForever(t){return this._ctx.repeatForever(t)}follow(t,e){return this._ctx.follow(t,e)}meet(t,e){return this._ctx.meet(t,e)}asPromise(){return this.toPromise()}toPromise(){return this._ctx.toPromise()}}class Ls extends _t{constructor(t={}){var e,i,s,r,n,o,a,h,l,c,d,u,p,g,_,f,m,v,y;super(t),this.filtering=ht.Blended,this.quality=2,this.padding=2,this.smoothing=!1,this.lineWidth=1,this.lineDash=[],this.color=I.Black,this.family="sans-serif",this.style=Me.Normal,this.bold=!1,this.unit=Re.Px,this.textAlign=Be.Left,this.baseAlign=De.Alphabetic,this.direction=ke.LeftToRight,this.size=10,this.shadow=null,this._textBounds=new B,this._textToBitmap=new Map,this._bitmapUsage=new Map,this.smoothing=null!==(e=null==t?void 0:t.smoothing)&&void 0!==e?e:this.smoothing,this.padding=null!==(i=null==t?void 0:t.padding)&&void 0!==i?i:this.padding,this.color=null!==(s=null==t?void 0:t.color)&&void 0!==s?s:this.color,this.strokeColor=null!==(r=null==t?void 0:t.strokeColor)&&void 0!==r?r:this.strokeColor,this.lineDash=null!==(n=null==t?void 0:t.lineDash)&&void 0!==n?n:this.lineDash,this.lineWidth=null!==(o=null==t?void 0:t.lineWidth)&&void 0!==o?o:this.lineWidth,this.filtering=null!==(a=null==t?void 0:t.filtering)&&void 0!==a?a:this.filtering,this.family=null!==(h=null==t?void 0:t.family)&&void 0!==h?h:this.family,this.style=null!==(l=null==t?void 0:t.style)&&void 0!==l?l:this.style,this.bold=null!==(c=null==t?void 0:t.bold)&&void 0!==c?c:this.bold,this.size=null!==(d=null==t?void 0:t.size)&&void 0!==d?d:this.size,this.unit=null!==(u=null==t?void 0:t.unit)&&void 0!==u?u:this.unit,this.textAlign=null!==(p=null==t?void 0:t.textAlign)&&void 0!==p?p:this.textAlign,this.baseAlign=null!==(g=null==t?void 0:t.baseAlign)&&void 0!==g?g:this.baseAlign,this.direction=null!==(_=null==t?void 0:t.direction)&&void 0!==_?_:this.direction,this.quality=null!==(f=null==t?void 0:t.quality)&&void 0!==f?f:this.quality,(null==t?void 0:t.shadow)&&(this.shadow={},this.shadow.blur=null!==(m=t.shadow.blur)&&void 0!==m?m:this.shadow.blur,this.shadow.offset=null!==(v=t.shadow.offset)&&void 0!==v?v:this.shadow.offset,this.shadow.color=null!==(y=t.shadow.color)&&void 0!==y?y:this.shadow.color)}clone(){return new Ls({...this.cloneGraphicOptions(),size:this.size,unit:this.unit,family:this.family,style:this.style,bold:this.bold,textAlign:this.textAlign,baseAlign:this.baseAlign,direction:this.direction,shadow:this.shadow?{blur:this.shadow.blur,offset:this.shadow.offset,color:this.shadow.color}:null})}get fontString(){return`${this.style} ${this.bold?"bold":""} ${this.size}${this.unit} ${this.family}`}get localBounds(){return this._textBounds}_drawImage(t,e,i){}_rotate(t){var e;const i=null!==(e=this.origin)&&void 0!==e?e:this._textBounds.center;t.translate(i.x,i.y),t.rotate(this.rotation),t.translate(-i.x,-i.y)}_flip(t){this.flipHorizontal&&(t.translate(this._textBounds.width/this.scale.x,0),t.scale(-1,1)),this.flipVertical&&(t.translate(0,-this._textBounds.height/2/this.scale.y),t.scale(1,-1))}measureText(t){const e=t.split("\n"),i=e.reduce(((t,e)=>t.length>e.length?t:e)),s=this._getTextBitmap(t);this._applyFont(s);const r=s.measureText(i);let n=Math.abs(r.actualBoundingBoxAscent)+Math.abs(r.actualBoundingBoxDescent);const o=n*e.length;n=o;const a=o-Math.abs(r.actualBoundingBoxAscent);return new B({left:0-Math.abs(r.actualBoundingBoxLeft)-this.padding,top:0-Math.abs(r.actualBoundingBoxAscent)-this.padding,bottom:0+a+this.padding,right:0+Math.abs(r.actualBoundingBoxRight)+this.padding})}_setDimension(t,e){e.canvas.width=2*(t.width+2*this.padding)*this.quality,e.canvas.height=2*(t.height+2*this.padding)*this.quality}_postDraw(t){t.restore()}_getRasterPropertiesHash(t){var e,i;return"__hashcode__"+this.fontString+this.showDebug+this.textAlign+this.baseAlign+this.direction+JSON.stringify(this.shadow)+(this.padding.toString()+this.smoothing.toString()+this.lineWidth.toString()+this.lineDash.toString()+(null===(e=this.strokeColor)||void 0===e?void 0:e.toString())+(t?t.toString():null===(i=this.color)||void 0===i?void 0:i.toString()).toString())}_applyRasterProperties(t,e){var i,s,r;t.translate(this.padding,this.padding),t.imageSmoothingEnabled=this.smoothing,t.lineWidth=this.lineWidth,t.setLineDash(null!==(i=this.lineDash)&&void 0!==i?i:t.getLineDash()),t.strokeStyle=null===(s=this.strokeColor)||void 0===s?void 0:s.toString(),t.fillStyle=e?e.toString():null===(r=this.color)||void 0===r?void 0:r.toString()}_applyFont(t){t.translate(this.padding+t.canvas.width/2,this.padding+t.canvas.height/2),t.scale(this.quality,this.quality),t.textAlign=this.textAlign,t.textBaseline=this.baseAlign,t.font=this.fontString,t.direction=this.direction,this.shadow&&(t.shadowColor=this.shadow.color.toString(),t.shadowBlur=this.shadow.blur,t.shadowOffsetX=this.shadow.offset.x,t.shadowOffsetY=this.shadow.offset.y)}_drawText(t,e,i,s){const r=e.split("\n");this._applyRasterProperties(t,i),this._applyFont(t);for(let e=0;e<r.length;e++){const i=r[e];this.color&&t.fillText(i,0,e*s),this.strokeColor&&t.strokeText(i,0,e*s)}this.showDebug&&(li(t,I.Red,-t.canvas.width/2,0,t.canvas.width/2,0,2),li(t,I.Red,0,-t.canvas.height/2,0,t.canvas.height/2,2))}_getTextBitmap(t,e){const i=t+this._getRasterPropertiesHash(e),s=this._textToBitmap.get(i);if(s)return s;const r=document.createElement("canvas").getContext("2d");return this._textToBitmap.set(i,r),r}render(t,e,i,s,r){this.showDebug&&this.clearCache(),this.checkAndClearCache();const n=this._getTextBitmap(e,i),o=!this._bitmapUsage.get(n);this._textBounds=this.measureText(e),o&&this._setDimension(this._textBounds,n),this._preDraw(t,s,r);const a=e.split("\n"),h=this._textBounds.height/a.length,l=n.canvas.width,c=n.canvas.height;o&&(this._drawText(n,e,i,h),bt.load(n.canvas,this.filtering,!0)),t.drawImage(n.canvas,0,0,l,c,s-l/this.quality/2,r-c/this.quality/2,l/this.quality,c/this.quality),this._postDraw(t),this._bitmapUsage.set(n,performance.now())}get cacheSize(){return this._bitmapUsage.size}clearCache(){this._bitmapUsage.clear()}checkAndClearCache(){for(const[t,e]of this._bitmapUsage.entries())e+1e3<performance.now()&&this._bitmapUsage.delete(t)}}class zs extends _t{constructor(t){var e,i;super(t),this._text="",this._textWidth=0,this._textHeight=0,this.font=null!==(e=t.font)&&void 0!==e?e:new Ls,this.color=null!==(i=t.color)&&void 0!==i?i:this.color,this.text=t.text}clone(){var t,e;return new zs({text:this.text.slice(),color:null!==(e=null===(t=this.color)||void 0===t?void 0:t.clone())&&void 0!==e?e:I.Black,font:this.font.clone()})}get text(){return this._text}set text(t){this._text=t;const e=this.font.measureText(this._text);this._textWidth=e.width,this._textHeight=e.height}get font(){return this._font}set font(t){this._font=t}get width(){return 0===this._textWidth&&this._calculateDimension(),this._textWidth*this.scale.x}get height(){return 0===this._textHeight&&this._calculateDimension(),this._textHeight*this.scale.y}_calculateDimension(){const{width:t,height:e}=this.font.measureText(this._text);this._textWidth=t,this._textHeight=e}get localBounds(){return this.font.measureText(this._text).scale(this.scale)}_rotate(t){}_flip(t){}_drawImage(t,e,i){var s;let r=I.Black;this.font instanceof Ls&&(r=null!==(s=this.color)&&void 0!==s?s:this.font.color),(this.isStale()||this.font.isStale())&&(this.font.flipHorizontal=this.flipHorizontal,this.font.flipVertical=this.flipVertical,this.font.rotation=this.rotation,this.font.origin=this.origin,this.font.opacity=this.opacity);const{width:n,height:o}=this.font.measureText(this._text);this._textWidth=n,this._textHeight=o,this.font.render(t,this._text,r,e,i),this.font.showDebug&&t.debug.drawRect(e-n,i-o,2*n,2*o)}}var Os=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Us extends ns{constructor(t){super(),this._anchor=pt(A.Half,(t=>this._handleAnchorChange(t))),this.logger=f.getInstance(),this.scene=null,this.frames={},this.currentDrawing=null,this._draggable=!1,this._dragging=!1,this._pointerDragStartHandler=()=>{this._dragging=!0},this._pointerDragEndHandler=()=>{this._dragging=!1},this._pointerDragMoveHandler=t=>{this._dragging&&(this.pos=t.worldPos)},this._pointerDragLeaveHandler=t=>{this._dragging&&(this.pos=t.worldPos)},this.traits=[];const{name:e,x:i,y:s,pos:r,coordPlane:n,scale:o,width:a,height:h,radius:l,collider:c,vel:u,acc:p,rotation:_,angularVelocity:m,z:v,color:y,visible:w,anchor:x,collisionType:b,collisionGroup:C}={...t};this._setName(e),this.anchor=null!=x?x:Us.defaults.anchor.clone();const S=new Ei;this.addComponent(S),this.pos=null!=r?r:P(null!=i?i:0,null!=s?s:0),this.rotation=null!=_?_:0,this.scale=null!=o?o:P(1,1),this.z=null!=v?v:0,S.coordPlane=null!=n?n:Ti.World,this.addComponent(new ps),this.addComponent(new cs({anchor:this.anchor})),this.addComponent(new os(((t,e)=>this.draw(t,e)))),this.addComponent(new Ii),this.vel=null!=u?u:A.Zero,this.acc=null!=p?p:A.Zero,this.angularVelocity=null!=m?m:0,this.addComponent(new Fs),this.addComponent(new $i),this.body.collisionType=null!=b?b:vi.Passive,C&&(this.body.group=C),c?this.addComponent(new Zi(c)):l?this.addComponent(new Zi(Yi.Circle(l,this.anchor))):a>0&&h>0?this.addComponent(new Zi(Yi.Box(a,h,this.anchor))):this.addComponent(new Zi),this.graphics.visible=null==w||w,y&&(this.color=y,a&&h?this.graphics.add(new ds({color:y,width:a,height:h})):l&&this.graphics.add(new us({color:y,radius:l}))),g.isEnabled(d.LegacyDrawing)&&this.traits.push(new ts)}get body(){return this.get($i)}get transform(){return this.get(Ei)}get motion(){return this.get(Ii)}get graphics(){return this.get(cs)}get collider(){return this.get(Zi)}get pointer(){return this.get(ps)}get actions(){return this.get(Fs)}get pos(){return this.transform.pos}set pos(t){this.transform.pos=t.clone()}get oldPos(){return this.body.oldPos}set oldPos(t){this.body.oldPos.setTo(t.x,t.y)}get vel(){return this.motion.vel}set vel(t){this.motion.vel=t.clone()}get oldVel(){return this.body.oldVel}set oldVel(t){this.body.oldVel.setTo(t.x,t.y)}get acc(){return this.motion.acc}set acc(t){this.motion.acc=t.clone()}set oldAcc(t){this.body.oldAcc.setTo(t.x,t.y)}get oldAcc(){return this.body.oldAcc}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angularVelocity(){return this.motion.angularVelocity}set angularVelocity(t){this.motion.angularVelocity=t}get scale(){return this.get(Ei).scale}set scale(t){this.get(Ei).scale=t}get anchor(){return this._anchor}set anchor(t){this._anchor=pt(t,(t=>this._handleAnchorChange(t))),this._handleAnchorChange(t)}_handleAnchorChange(t){this.graphics&&(this.graphics.anchor=t)}get isOffScreen(){return this.hasTag("offscreen")}get visible(){return this.graphics.visible}set visible(t){this.graphics.visible=t}get opacity(){return this.graphics.opacity}set opacity(t){this.graphics.opacity=t}get draggable(){return this._draggable}set draggable(t){t&&(t&&!this._draggable?(this.on("pointerdragstart",this._pointerDragStartHandler),this.on("pointerdragend",this._pointerDragEndHandler),this.on("pointerdragmove",this._pointerDragMoveHandler),this.on("pointerdragleave",this._pointerDragLeaveHandler)):!t&&this._draggable&&(this.off("pointerdragstart",this._pointerDragStartHandler),this.off("pointerdragend",this._pointerDragEndHandler),this.off("pointerdragmove",this._pointerDragMoveHandler),this.off("pointerdragleave",this._pointerDragLeaveHandler)),this._draggable=t)}get color(){return this._color}set color(t){var e;this._color=t.clone();const i=null===(e=this.graphics.layers.default.graphics[0])||void 0===e?void 0:e.graphic;(i instanceof Ct||i instanceof zs)&&(i.color=this._color)}onInitialize(t){}_initialize(t){super._initialize(t);for(const e of this.children)e._initialize(t)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}_prekill(t){super.emit("prekill",new Tt(this)),this.onPreKill(t)}onPreKill(t){}_postkill(t){super.emit("postkill",new Et(this)),this.onPostKill(t)}onPostKill(t){}kill(){this.scene?(this._prekill(this.scene),this.emit("kill",new Pt(this)),super.kill(),this._postkill(this.scene)):this.logger.warn("Cannot kill actor, it was never added to the Scene")}unkill(){this.active=!0}isKilled(){return!this.active}setDrawing(t){t=t.toString(),this.currentDrawing!==this.frames[t]&&(null!=this.frames[t]?(this.frames[t].reset(),this.currentDrawing=this.frames[t]):f.getInstance().error(`the specified drawing key ${t} does not exist`)),this.currentDrawing&&this.currentDrawing instanceof Ie&&this.currentDrawing.tick(0)}addDrawing(){2===arguments.length?(this.frames[arguments[0]]=arguments[1],this.currentDrawing||(this.currentDrawing=arguments[1])):(arguments[0]instanceof Se&&this.addDrawing("default",arguments[0]),arguments[0]instanceof we&&this.addDrawing("default",arguments[0].asSprite()))}get z(){return this.get(Ei).z}getZIndex(){return this.get(Ei).z}set z(t){this.get(Ei).z=t}setZIndex(t){this.get(Ei).z=t}get center(){const t=this.getGlobalPos();return new A(t.x+this.width/2-this.anchor.x*this.width,t.y+this.height/2-this.anchor.y*this.height)}get localCenter(){return new A(this.pos.x+this.width/2-this.anchor.x*this.width,this.pos.y+this.height/2-this.anchor.y*this.height)}get width(){return this.collider.localBounds.width*this.getGlobalScale().x}get height(){return this.collider.localBounds.height*this.getGlobalScale().y}getGlobalRotation(){return this.get(Ei).globalRotation}getGlobalPos(){return this.get(Ei).globalPos}getGlobalScale(){return this.get(Ei).globalScale}contains(t,e,i=!1){const s=P(t,e),r=this.get(Zi);r.update();const n=r.get();if(!n)return!1;const o=n.contains(s);return i?o||this.children.some((i=>i.contains(t,e,!0))):o}within(t,e){const i=this.get(Zi),s=t.get(Zi),r=i.get(),n=s.get();return!(!r||!n)&&r.getClosestLineBetween(n).getLength()<=e}update(t,e){this._initialize(t),this._preupdate(t,e);const i=this.currentDrawing;i&&i instanceof Ie&&i.tick(e,t.stats.currFrame.id);for(const i of this.traits)i.update(this,t,e);this._postupdate(t,e)}onPreUpdate(t,e){}onPostUpdate(t,e){}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Ft(t,e,this)),this.onPostUpdate(t,e)}draw(t,e){var i;if(t.save(),this.currentDrawing){t.translate(-this.width*this.anchor.x,-this.height*this.anchor.y),this._predraw(t,e);const i=this.currentDrawing,s=(this.width-i.width*i.scale.x)*this.anchor.x,r=(this.height-i.height*i.scale.y)*this.anchor.y;this.currentDrawing.draw({ctx:t,x:s,y:r,opacity:this.graphics.opacity})}else if(this._predraw(t,e),this.color&&this.collider){const e=this.get(Zi);e.update(),e&&!e.bounds.hasZeroDimensions()&&(t.globalAlpha=this.graphics.opacity,null===(i=e.get())||void 0===i||i.draw(t,this.color,P(0,0)))}t.restore(),this._postdraw(t,e)}onPreDraw(t,e){}onPostDraw(t,e){}_predraw(t,e){this.emit("predraw",new Bt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new Bt(t,e,this)),this.onPostDraw(t,e)}debugDraw(t){}}Us.defaults={anchor:A.Half},Os([C({message:"Actor.visible will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.visible"})],Us.prototype,"visible",null),Os([C({message:"Actor.opacity will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.opacity"})],Us.prototype,"opacity",null),Os([C({message:"Actor.setDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.show() or Actor.graphics.use()"})],Us.prototype,"setDrawing",null),Os([C({message:"Actor.addDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.add()"})],Us.prototype,"addDrawing",null),Os([C({message:"Actor.getZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Us.prototype,"getZIndex",null),Os([C({message:"Actor.setZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Us.prototype,"setZIndex",null);class Ns extends Us{constructor(t){super({...t}),this.get(Ei).coordPlane=Ti.Screen,this.anchor=P(0,0),this.body.collisionType=vi.PreventCollision,this.collider.useBoxCollider(this.width,this.height,this.anchor)}_initialize(t){this._engine=t,super._initialize(t)}contains(t,e,i=!0){if(i)return super.contains(t,e);const s=this._engine.worldToScreenCoordinates(new A(t,e));return super.contains(s.x,s.y)}}var Hs=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ws{constructor(t,e,i,s){if(this._logger=f.getInstance(),this.id=0,this._elapsedTime=0,this._totalTimeAlive=0,this._running=!1,this._numberOfTicks=0,this.interval=10,this.repeats=!1,this.maxNumberOfRepeats=-1,this._complete=!1,this.scene=null,"function"!=typeof t){const r=t;t=r.fcn,e=r.interval,i=r.repeats,s=r.numberOfRepeats}if(s&&s>=0&&(this.maxNumberOfRepeats=s,!i))throw new Error("repeats must be set to true if numberOfRepeats is set");this.id=Ws._MAX_ID++,this.interval=e||this.interval,this.repeats=i||this.repeats,this._callbacks=[],t&&this.on(t)}get complete(){return this._complete}on(t){this._callbacks.push(t)}off(t){const e=this._callbacks.indexOf(t);this._callbacks.splice(e,1)}update(t){this._running&&(this._totalTimeAlive+=t,this._elapsedTime+=t,this.maxNumberOfRepeats>-1&&this._numberOfTicks>=this.maxNumberOfRepeats&&(this._complete=!0,this._running=!1,this._elapsedTime=0),!this.complete&&this._elapsedTime>=this.interval&&(this._callbacks.forEach((t=>{t.call(this)})),this._numberOfTicks++,this.repeats||(this._complete=!0,this._running=!1),this._elapsedTime=0))}reset(t,e){if(t&&t>=0&&(this.interval=t),this.maxNumberOfRepeats&&this.maxNumberOfRepeats>=0&&(this.maxNumberOfRepeats=e,!this.repeats))throw new Error("repeats must be set to true if numberOfRepeats is set");this._complete=!1,this._elapsedTime=0,this._numberOfTicks=0}get timesRepeated(){return this._numberOfTicks}getTimeRunning(){return this._totalTimeAlive}get timeToNextAction(){return this.complete?0:this.interval-this._elapsedTime}get timeElapsedTowardNextAction(){return this._elapsedTime}get isRunning(){return this._running}pause(){return this._running=!1,this}unpause(){this._running=!0}resume(){return this._running=!0,this}start(){return this.scene||this._logger.warn("Cannot start a timer not part of a scene, timer wont start until added"),this._running=!0,this.complete&&(this._complete=!1,this._elapsedTime=0,this._numberOfTicks=0),this}stop(){return this._running=!1,this._elapsedTime=0,this._numberOfTicks=0,this}cancel(){this.pause(),this.scene&&this.scene.cancelTimer(this)}}Ws._MAX_ID=0,Hs([C({message:"Will be removed in v0.26.0",alternateMethod:"Use Timer.resume()"})],Ws.prototype,"unpause",null);class Vs extends Ai{constructor(t){super(),this.draw=t,this.type="ex.debuggraphics"}}var Gs,Xs=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class qs extends ns{constructor(t,e,i,s,r,n){if(super(),this._token=0,this._onScreenXStart=0,this._onScreenXEnd=9999,this._onScreenYStart=0,this._onScreenYEnd=9999,this._spriteSheets={},this._legacySpriteMap=new Map,this.logger=f.getInstance(),this.data=[],this._rows=[],this._cols=[],this.visible=!0,this.isOffscreen=!1,this._dirty=!0,t&&"object"==typeof t){const o=t;t=o.x,e=o.y,i=o.cellWidth,s=o.cellHeight,r=o.rows,n=o.cols}this.addComponent(new Ei),this.addComponent(new Ii),this.addComponent(new $i({type:vi.Fixed})),this.addComponent(new os(((t,e)=>this.draw(t,e)))),this.addComponent(new cs({onPostDraw:(t,e)=>this.draw(t,e)})),this.addComponent(new Vs((t=>this.debug(t)))),this.addComponent(new Zi),this._transform=this.get(Ei),this._motion=this.get(Ii),this._collider=this.get(Zi),this._composite=this._collider.useCompositeCollider([]),this.x=t,this.y=e,this.cellWidth=i,this.cellHeight=s,this.rows=r,this.cols=n,this.data=new Array(r*n),this._rows=new Array(r),this._cols=new Array(n);let o=[];for(let a=0;a<n;a++){for(let h=0;h<r;h++){const r=new Ys(a*i+t,h*s+e,i,s,a+h*n);r.map=this,this.data[a+h*n]=r,o.push(r),this._rows[h]||(this._rows[h]=[]),this._rows[h].push(r)}this._cols[a]=o,o=[]}this.get(cs).localBounds=new B({left:0,top:0,right:this.cols*this.cellWidth,bottom:this.rows*this.cellHeight})}flagDirty(){this._dirty=!0}get x(){var t;return null!==(t=this._transform.pos.x)&&void 0!==t?t:0}set x(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.pos)&&(this.get(Ei).pos=P(t,this.y))}get y(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos.y)&&void 0!==e?e:0}set y(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.pos)&&(this._transform.pos=P(this.x,t))}get z(){var t;return null!==(t=this._transform.z)&&void 0!==t?t:0}set z(t){this._transform&&(this._transform.z=t)}get rotation(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.rotation)&&void 0!==e?e:0}set rotation(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.rotation)&&(this._transform.rotation=t)}get scale(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.scale)&&void 0!==e?e:A.One}set scale(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.scale)&&(this._transform.scale=t)}get pos(){return this._transform.pos}set pos(t){this._transform.pos=t}get vel(){return this._motion.vel}set vel(t){this._motion.vel=t}on(t,e){super.on(t,e)}_initialize(t){super._initialize(t)}registerSpriteSheet(t,e){this._spriteSheets[t]=e instanceof Oe?e:Oe.fromLegacySpriteSheet(e)}_updateColliders(){this._composite.clearColliders();const t=[];let e;for(let i=0;i<this.cols;i++){for(let s=0;s<this.rows;s++){0===s&&(e=null);const r=this.data[i+s*this.cols];r.solid?e=e?e.combine(r.bounds):r.bounds:(e&&t.push(e),e=null)}if(e){const i=t[t.length-1];i&&i.top===e.top&&i.bottom===e.bottom?t[t.length-1]=i.combine(e):t.push(e)}}this._composite=this._collider.useCompositeCollider([]);for(const e of t){const t=Yi.Box(e.width,e.height,A.Zero,P(e.left-this.pos.x,e.top-this.pos.y));t.owner=this,this._composite.addCollider(t)}this._collider.update()}getCellByIndex(t){return this.data[t]}getCell(t,e){return t<0||e<0||t>=this.cols||e>=this.rows?null:this.data[t+e*this.cols]}getCellByPoint(t,e){t=Math.floor((t-this.pos.x)/this.cellWidth),e=Math.floor((e-this.pos.y)/this.cellHeight);const i=this.getCell(t,e);return t>=0&&e>=0&&t<this.cols&&e<this.rows&&i?i:null}getRows(){return this._rows}getColumns(){return this._cols}onPreUpdate(t,e){}onPostUpdate(t,e){}update(t,e){this.onPreUpdate(t,e),this.emit("preupdate",new Ft(t,e,this)),this._dirty&&(this._dirty=!1,this._updateColliders()),this._token++;const i=t.getWorldBounds(),s=P(i.left,i.top),r=P(i.right,i.bottom);this._onScreenXStart=Math.max(Math.floor((s.x-this.x)/this.cellWidth)-2,0),this._onScreenYStart=Math.max(Math.floor((s.y-this.y)/this.cellHeight)-2,0),this._onScreenXEnd=Math.max(Math.floor((r.x-this.x)/this.cellWidth)+2,0),this._onScreenYEnd=Math.max(Math.floor((r.y-this.y)/this.cellHeight)+2,0),this._transform.pos=P(this.x,this.y),this.onPostUpdate(t,e),this.emit("postupdate",new Lt(t,e,this))}draw(t,e){this.emit("predraw",new Bt(t,e,this));let i=this._onScreenXStart;const s=Math.min(this._onScreenXEnd,this.cols);let r=this._onScreenYStart;const n=Math.min(this._onScreenYEnd,this.rows);let o,a,h;for(;i<s;i++){for(;r<n;r++)for(o=this.getCell(i,r).graphics,a=0,h=o.length;a<h;a++){const s=o[a];s&&(t instanceof CanvasRenderingContext2D?s instanceof Ae&&(this._legacySpriteMap.has(s)||this._legacySpriteMap.set(s,Ae.toLegacySprite(s)),this._legacySpriteMap.get(s).draw(t,i*this.cellWidth,r*this.cellHeight)):(as(s)&&(null==s||s.tick(e,this._token)),s.draw(t,i*this.cellWidth,r*this.cellHeight)))}r=this._onScreenYStart}this.emit("postdraw",new Dt(t,e,this))}debug(t){const e=this.cellWidth*this.cols,i=this.cellHeight*this.rows,s=A.Zero;for(let i=0;i<this.rows+1;i++){const r=P(0,i*this.cellHeight);t.drawLine(s.add(r),s.add(P(e,r.y)),I.Red,2)}for(let e=0;e<this.cols+1;e++){const r=P(e*this.cellWidth,0);t.drawLine(s.add(r),s.add(P(r.x,i)),I.Red,2)}const r=this._composite.getColliders();for(const e of r){const i=I.Gray;i.a=.5;const s=e.localBounds,r=e.worldPos.sub(this.pos);t.drawRectangle(r,s.width,s.height,i)}}}Xs([C({message:"No longer used, will be removed in v0.26.0"})],qs.prototype,"registerSpriteSheet",null);class js extends(xe(qs)){constructor(t,e,i,s,r,n){super(t,e,i,s,r,n)}}class Ks extends ns{constructor(t,e,i,s,r,n=!1,o=[]){if(super(),this._solid=!1,this.graphics=[],this.data=new Map,t&&"object"==typeof t){const a=t;t=a.x,e=a.y,i=a.width,s=a.height,r=a.index,n=a.solid,o=a.sprites}this.x=t,this.y=e,this.width=i,this.height=s,this.index=r,this.solid=n,this.graphics=o,this._bounds=new B(this.x,this.y,this.x+this.width,this.y+this.height)}get solid(){return this._solid}set solid(t){var e;null===(e=this.map)||void 0===e||e.flagDirty(),this._solid=t}get bounds(){return this._bounds}get center(){return new A(this.x+this.width/2,this.y+this.height/2)}pushSprite(t){this.addGraphic(t)}addGraphic(t){t instanceof Se?this.graphics.push(Ae.fromLegacySprite(t)):this.graphics.push(t)}removeGraphic(t){tt(t,this.graphics)}clearGraphics(){this.graphics.length=0}}Xs([C({message:"Will be removed in v0.26.0",alternateMethod:"addSprite"})],Ks.prototype,"pushSprite",null);class Ys extends(xe(Ks)){constructor(t,e,i,s,r,n,o){super(t,e,i,s,r,n,o)}}class Zs{constructor(t){this.camera=t}lockToActor(t){this.camera.addStrategy(new Qs(t))}lockToActorAxis(t,e){this.camera.addStrategy(new $s(t,e))}elasticToActor(t,e,i){this.camera.addStrategy(new Js(t,e,i))}radiusAroundActor(t,e){this.camera.addStrategy(new tr(t,e))}limitCameraBounds(t){this.camera.addStrategy(new er(t))}}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(Gs||(Gs={}));class Qs{constructor(t){this.target=t,this.action=(t,e,i,s)=>t.center}}class $s{constructor(t,e){this.target=t,this.axis=e,this.action=(t,e,i,s)=>{const r=t.center,n=e.getFocus();return this.axis===Gs.X?new A(r.x,n.y):new A(n.x,r.y)}}}class Js{constructor(t,e,i){this.target=t,this.cameraElasticity=e,this.cameraFriction=i,this.action=(t,e,i,s)=>{const r=t.center;let n=e.getFocus(),o=e.vel.clone();const a=r.sub(n).scale(this.cameraElasticity);o=o.add(a);const h=o.scale(-1).scale(this.cameraFriction);return o=o.add(h),n=n.add(o),n}}}class tr{constructor(t,e){this.target=t,this.radius=e,this.action=(t,e,i,s)=>{const r=t.center,n=e.getFocus(),o=r.sub(n),a=o.size;if(a>=this.radius){const t=a-this.radius;return n.add(o.normalize().scale(t))}return n}}}class er{constructor(t){this.target=t,this.boundSizeChecked=!1,this.action=(t,e,i,s)=>{const r=e.getFocus();this.boundSizeChecked||((t.bottom-t.top<i.drawHeight||t.right-t.left<i.drawWidth)&&f.getInstance().warn("Camera bounds should not be smaller than the engine viewport"),this.boundSizeChecked=!0);let n=r.x,o=r.y;return r.x<t.left+i.halfDrawWidth?n=t.left+i.halfDrawWidth:r.x>t.right-i.halfDrawWidth&&(n=t.right-i.halfDrawWidth),r.y<t.top+i.halfDrawHeight?o=t.top+i.halfDrawHeight:r.y>t.bottom-i.halfDrawHeight&&(o=t.bottom-i.halfDrawHeight),P(n,o)}}}class ir extends hi{constructor(){super(...arguments),this.transform=ct.identity(),this.inverse=ct.identity(),this._cameraStrategies=[],this.strategy=new Zs(this),this._z=1,this.dz=0,this.az=0,this.rotation=0,this.rx=0,this._posChanged=!1,this._pos=gt(A.Zero,(()=>this._posChanged=!0)),this.vel=A.Zero,this.acc=A.Zero,this._cameraMoving=!1,this._currentLerpTime=0,this._lerpDuration=1e3,this._lerpStart=null,this._lerpEnd=null,this._isShaking=!1,this._shakeMagnitudeX=0,this._shakeMagnitudeY=0,this._shakeDuration=0,this._elapsedShakeTime=0,this._xShake=0,this._yShake=0,this._isZooming=!1,this._zoomStart=1,this._zoomEnd=1,this._currentZoomTime=0,this._zoomDuration=0,this._zoomEasing=fs.EaseInOutCubic,this._easing=fs.EaseInOutCubic,this._halfWidth=0,this._halfHeight=0,this._viewport=null,this._isInitialized=!1}get zoom(){return this._z}set zoom(t){this._z=t,this._engine&&(this._halfWidth=this._engine.halfDrawWidth,this._halfHeight=this._engine.halfDrawHeight)}get angularVelocity(){return this.rx}set angularVelocity(t){this.rx=t}get pos(){return this._pos}set pos(t){this._pos=gt(t,(()=>this._posChanged=!0)),this._posChanged=!0}get x(){return this.pos.x}set x(t){this._follow||this._cameraMoving||(this.pos=P(t,this.pos.y))}get y(){return this.pos.y}set y(t){this._follow||this._cameraMoving||(this.pos=P(this.pos.x,t))}get dx(){return this.vel.x}set dx(t){this.vel=P(t,this.vel.y)}get dy(){return this.vel.y}set dy(t){this.vel=P(this.vel.x,t)}get ax(){return this.acc.x}set ax(t){this.acc=P(t,this.acc.y)}get ay(){return this.acc.y}set ay(t){this.acc=P(this.acc.x,t)}getFocus(){return this.pos}move(t,e,i=fs.EaseInOutCubic){if("function"!=typeof i)throw"Please specify an EasingFunction";return this._follow?Promise.reject(t):(this._lerpPromise&&this._lerpResolve&&this._lerpResolve(t),this._lerpPromise=new Promise((t=>{this._lerpResolve=t})),this._lerpStart=this.getFocus().clone(),this._lerpDuration=e,this._lerpEnd=t,this._currentLerpTime=0,this._cameraMoving=!0,this._easing=i,this._lerpPromise)}shake(t,e,i){this._isShaking=!0,this._shakeMagnitudeX=t,this._shakeMagnitudeY=e,this._shakeDuration=i}zoomOverTime(t,e=0,i=fs.EaseInOutCubic){return this._zoomPromise=new Promise((t=>{this._zoomResolve=t})),e?(this._isZooming=!0,this._zoomEasing=i,this._currentZoomTime=0,this._zoomDuration=e,this._zoomStart=this.zoom,this._zoomEnd=t,this._zoomPromise):(this._isZooming=!1,this.zoom=t,Promise.resolve(!0))}get viewport(){return this._viewport?this._viewport:new B(0,0,0,0)}addStrategy(t){this._cameraStrategies.push(t)}removeStrategy(t){tt(t,this._cameraStrategies)}clearAllStrategies(){this._cameraStrategies.length=0}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}onPreUpdate(t,e){}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}onPostUpdate(t,e){}get isInitialized(){return this._isInitialized}_initialize(t){if(!this.isInitialized){this._engine=t,this._screen=t.screen;const e=this._screen.resolution;let i=P(e.width/2,e.height/2);if(!this._engine.loadingComplete){const t=this._screen.peekResolution();t&&(i=P(t.width/2,t.height/2))}this._halfWidth=i.x,this._halfHeight=i.y,this._posChanged||(this.pos=i),this.updateTransform(),this.runStrategies(t,t.clock.elapsed()),this.updateViewport(),this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0}}onInitialize(t){}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}once(t,e){super.once(t,e)}runStrategies(t,e){for(const i of this._cameraStrategies)this.pos=i.action.call(i,i.target,this,t,e)}updateViewport(){this._viewport=new B(this.x-this._halfWidth,this.y-this._halfHeight,this.x+this._halfWidth,this.y+this._halfHeight)}update(t,e){if(this._initialize(t),this._preupdate(t,e),this.pos=this.pos.add(this.vel.scale(e/1e3)),this.zoom+=this.dz*e/1e3,this.vel=this.vel.add(this.acc.scale(e/1e3)),this.dz+=this.az*e/1e3,this.rotation+=this.angularVelocity*e/1e3,this._isZooming)if(this._currentZoomTime<this._zoomDuration){const t=(0,this._zoomEasing)(this._currentZoomTime,this._zoomStart,this._zoomEnd,this._zoomDuration);this.zoom=t,this._currentZoomTime+=e}else this._isZooming=!1,this.zoom=this._zoomEnd,this._currentZoomTime=0,this._zoomResolve(!0);if(this._cameraMoving)if(this._currentLerpTime<this._lerpDuration){const t=fs.CreateVectorEasingFunction(this._easing)(this._currentLerpTime,this._lerpStart,this._lerpEnd,this._lerpDuration);this.pos=t,this._currentLerpTime+=e}else{this.pos=this._lerpEnd;const t=this._lerpEnd.clone();this._lerpStart=null,this._lerpEnd=null,this._currentLerpTime=0,this._cameraMoving=!1,this._lerpResolve(t)}this._isDoneShaking()?(this._isShaking=!1,this._elapsedShakeTime=0,this._shakeMagnitudeX=0,this._shakeMagnitudeY=0,this._shakeDuration=0,this._xShake=0,this._yShake=0):(this._elapsedShakeTime+=e,this._xShake=1+(Math.random()*this._shakeMagnitudeX|0),this._yShake=1+(Math.random()*this._shakeMagnitudeY|0)),this.updateTransform(),this.runStrategies(t,e),this.updateViewport(),this._postupdate(t,e)}draw(t){if(t instanceof CanvasRenderingContext2D){const e=this.getFocus(),i=this._screen.resolution.width/this.zoom,s=this._screen.resolution.height/this.zoom,r=P(-e.x+i/2+this._xShake,-e.y+s/2+this._yShake);t.scale(this.zoom,this.zoom),t.translate(r.x,r.y)}else t.multiply(this.transform)}updateTransform(){const t=this._screen.resolution.width/this.zoom,e=this._screen.resolution.height/this.zoom,i=P(-this.x+t/2+this._xShake,-this.y+e/2+this._yShake);this.transform.reset(),this.transform.scale(this.zoom,this.zoom),this.transform.translate(i.x,i.y),this.transform.getAffineInverse(this.inverse)}debugDraw(t){}_isDoneShaking(){return!this._isShaking||this._elapsedShakeTime>=this._shakeDuration}}function sr(t){return t instanceof Ns}const rr={pos:A.Zero,width:10,height:10,visible:!1,action:()=>{},filter:()=>!0,repeat:-1};class nr extends Us{constructor(t){super({x:t.pos.x,y:t.pos.y,width:t.width,height:t.height}),this.action=()=>{},this.filter=()=>!0,this.repeat=-1,t={...rr,...t},this.filter=t.filter||this.filter,this.repeat=t.repeat||this.repeat,this.action=t.action||this.action,t.target&&(this.target=t.target),this.graphics.visible=t.visible,this.body.collisionType=vi.Passive,this.eventDispatcher=new he,this.events.on("collisionstart",(t=>{this.filter(t.other)&&(this.emit("enter",new oe(this,t.other)),this._dispatchAction(),0===this.repeat&&this.kill())})),this.events.on("collisionend",(t=>{this.filter(t.other)&&this.emit("exit",new ae(this,t.other))}))}set target(t){this._target=t,this.filter=e=>e===t}get target(){return this._target}_initialize(t){super._initialize(t)}_dispatchAction(){0!==this.repeat&&(this.action.call(this),this.repeat--)}debugDraw(t){super.debugDraw(t),t.save(),t.translate(this.pos.x,this.pos.y);const e=this.collider.bounds,i=this.getGlobalPos();e.left=e.left-i.x,e.right=e.right-i.x,e.top=e.top-i.y,e.bottom=e.bottom-i.y,t.fillStyle=I.Violet.toString(),t.strokeStyle=I.Violet.toString(),t.fillText("Trigger",10,10),e.debugDraw(t),t.restore()}}var or;!function(t){t.Update="update",t.Draw="draw"}(or||(or={}));class ar{constructor(){this.priority=0}notify(t){}}class hr{constructor(t){this.data=t,this.type="Entity Added"}}function lr(t){return!!t&&"Entity Added"===t.type}class cr{constructor(t){this.data=t,this.type="Entity Removed"}}function dr(t){return!!t&&"Entity Removed"===t.type}class ur{constructor(t){this._world=t,this.entities=[],this._entityIndex={},this._entitiesToRemove=[]}updateEntities(t,e){for(const i of this.entities)i.update(t.engine,e),i.active||this.removeEntity(i)}findEntitiesForRemoval(){for(const t of this.entities)t.active||this.removeEntity(t)}notify(t){is(t)&&this._world.queryManager.addEntity(t.data.entity),rs(t)&&this._world.queryManager.removeComponent(t.data.entity,t.data.component)}addEntity(t){t.active=!0,t&&!this._entityIndex[t.id]&&(this._entityIndex[t.id]=t,this.entities.push(t),this._world.queryManager.addEntity(t),t.componentAdded$.register(this),t.componentRemoved$.register(this),t.children.forEach((t=>this.addEntity(t))),t.childrenAdded$.register({notify:t=>{this.addEntity(t)}}),t.childrenRemoved$.register({notify:t=>{this.removeEntity(t,!1)}}))}removeEntity(t,e=!0){var i;let s=0;s=t instanceof ns?t.id:t;const r=this._entityIndex[s];r&&r.active&&r.kill(),r&&e?this._entitiesToRemove.push(r):(delete this._entityIndex[s],r&&(tt(r,this.entities),this._world.queryManager.removeEntity(r),r.componentAdded$.unregister(this),r.componentRemoved$.unregister(this),r.children.forEach((t=>this.removeEntity(t,e))),r.childrenAdded$.clear(),r.childrenRemoved$.clear(),(null===(i=this._world.context)||void 0===i?void 0:i.engine)&&this._world.context.engine.stats.currFrame.actors.killed++))}processEntityRemovals(){for(const t of this._entitiesToRemove)t.active||this.removeEntity(t,!1)}processComponentRemovals(){for(const t of this.entities)t.processComponentRemoval()}getById(t){return this._entityIndex[t]}getByName(t){return this.entities.filter((e=>e.name===t))}clear(){for(const t of this.entities)this.removeEntity(t)}}const pr=t=>[...t].sort(((t,e)=>t.localeCompare(e))).join("+");class gr extends Bi{constructor(t){super(),this._entities=[],t[0]instanceof Function?this.types=t.map((t=>(new t).type)):this.types=t}get key(){return this._key?this._key:this._key=pr(this.types)}getEntities(t){return t&&this._entities.sort(t),this._entities}addEntity(t){!et(this._entities,t)&&this.matches(t)&&(this._entities.push(t),this.notifyAll(new hr(t)))}removeEntity(t){tt(t,this._entities)&&this.notifyAll(new cr(t))}clear(){this._entities.length=0;for(const t of this.observers)this.unregister(t)}matches(t){let e=[];e=t instanceof ns?t.types:t;let i=!0;for(const t of this.types)if(i=i&&e.indexOf(t)>-1,!i)return!1;return i}contain(t){return this.types.indexOf(t)>-1}}class _r{constructor(t){this._world=t,this._queries={}}_addQuery(t){this._queries[pr(t.types)]=t;for(const e of this._world.entityManager.entities)t.addEntity(e)}maybeRemoveQuery(t){0===t.observers.length&&(t.clear(),delete this._queries[pr(t.types)])}addEntity(t){for(const e in this._queries)this._queries[e]&&this._queries[e].addEntity(t)}removeComponent(t,e){for(const i in this._queries)this._queries[i].contain(e.type)&&this._queries[i].removeEntity(t)}removeEntity(t){for(const e in this._queries)this._queries[e].removeEntity(t)}createQuery(t){const e=this.getQuery(t);if(e)return e;const i=new gr(t);return this._addQuery(i),i}getQuery(t){const e=pr(t);return this._queries[e]?this._queries[e]:null}}class fr{constructor(t){this._world=t,this.systems=[],this.initialized=!1}get(t){return this.systems.find((e=>e instanceof t))}addSystem(t){if(!t.types||0===t.types.length)throw new Error("Attempted to add a System without any types");const e=this._world.queryManager.createQuery(t.types);this.systems.push(t),this.systems.sort(((t,e)=>t.priority-e.priority)),e.register(t),this.initialized&&t.initialize&&t.initialize(this._world.context)}removeSystem(t){tt(t,this.systems);const e=this._world.queryManager.getQuery(t.types);e&&(e.unregister(t),this._world.queryManager.maybeRemoveQuery(e))}initialize(){if(!this.initialized){this.initialized=!0;for(const t of this.systems)t.initialize&&t.initialize(this._world.context)}}updateSystems(t,e,i){const s=this.systems.filter((e=>e.systemType===t));for(const t of s)t.preupdate&&t.preupdate(e,i);for(const t of s){const s=this._world.queryManager.getQuery(t.types).getEntities(t.sort);if(e instanceof Nr)for(const t of s)t._initialize(null==e?void 0:e.engine);t.update(s,i)}for(const t of s)t.postupdate&&t.postupdate(e,i)}clear(){for(const t of this.systems)this.removeSystem(t)}}class mr{constructor(t){this.context=t,this.queryManager=new _r(this),this.entityManager=new ur(this),this.systemManager=new fr(this)}update(t,e){t===or.Update&&this.entityManager.updateEntities(this.context,e),this.systemManager.updateSystems(t,this.context,e),this.entityManager.findEntitiesForRemoval(),this.entityManager.processComponentRemovals(),this.entityManager.processEntityRemovals()}add(t){t instanceof ns&&this.entityManager.addEntity(t),t instanceof ar&&this.systemManager.addSystem(t)}remove(t,e=!0){t instanceof ns&&this.entityManager.removeEntity(t,e),t instanceof ar&&this.systemManager.removeSystem(t)}clearEntities(){this.entityManager.clear()}clearSystems(){this.systemManager.clear()}}class vr{static integrate(t,e,i,s){const r=s/1e3;e.vel.addEqual(i.scale(r)),t.pos.addEqual(e.vel.scale(r)).addEqual(i.scale(.5*r*r)),e.angularVelocity+=e.torque*(1/e.inertia)*r,t.rotation+=e.angularVelocity*r,t.scale.addEqual(e.scaleFactor.scale(r))}}class yr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.motion"],this.systemType=or.Update,this.priority=-1}update(t,e){let i,s;for(const r of t){i=r.get(Ei),s=r.get(Ii);const t=r.get($i);if(null==t?void 0:t.sleeping)continue;const n=s.acc.clone();(null==t?void 0:t.collisionType)===vi.Active&&(null==t?void 0:t.useGravity)&&n.addEqual(Ci.gravity),null==t||t.captureOldTransform(),vr.integrate(i,s,n,e)}}debugDraw(t){}}class wr{solve(t){return this.preSolve(t),t=t.filter((t=>!t.isCanceled())),this.solveVelocity(t),this.solvePosition(t),this.postSolve(t),t}}class xr extends wr{preSolve(t){for(const e of t){const t=T.fromDirection(e.mtv),i=e.mtv.negate();e.colliderA.events.emit("precollision",new jt(e.colliderA,e.colliderB,t,i)),e.colliderB.events.emit("precollision",new jt(e.colliderB,e.colliderA,T.getOpposite(t),i.negate()))}}postSolve(t){var e,i;for(const s of t){const t=s.colliderA,r=s.colliderB,n=null===(e=t.owner)||void 0===e?void 0:e.get($i),o=null===(i=r.owner)||void 0===i?void 0:i.get($i);if(n&&o&&(n.collisionType===vi.Passive||o.collisionType===vi.Passive))continue;const a=T.fromDirection(s.mtv),h=s.mtv.negate();s.colliderA.events.emit("postcollision",new Kt(s.colliderA,s.colliderB,a,h)),s.colliderB.events.emit("postcollision",new Kt(s.colliderB,s.colliderA,T.getOpposite(a),h.negate()))}}solvePosition(t){var e,i;for(const s of t){if(!s.colliderA.bounds.intersect(s.colliderB.bounds))continue;let t=s.mtv;const r=s.colliderA,n=s.colliderB,o=null===(e=r.owner)||void 0===e?void 0:e.get($i),a=null===(i=n.owner)||void 0===i?void 0:i.get($i);if(o&&a){if(o.collisionType===vi.Passive||a.collisionType===vi.Passive)continue;o.collisionType===vi.Active&&a.collisionType===vi.Active&&(t=t.scale(.5)),o.collisionType===vi.Active&&(o.pos.x-=t.x,o.pos.y-=t.y),a.collisionType===vi.Active&&(a.pos.x+=t.x,a.pos.y+=t.y)}}}solveVelocity(t){var e,i;for(const s of t){const t=s.colliderA,r=s.colliderB,n=null===(e=t.owner)||void 0===e?void 0:e.get($i),o=null===(i=r.owner)||void 0===i?void 0:i.get($i);if(n&&o){if(n.collisionType===vi.Passive||o.collisionType===vi.Passive)continue;const t=s.normal,e=t.negate();if(n.collisionType===vi.Active){const e=t.scale(t.dot(n.vel.negate()));n.vel=n.vel.add(e)}if(o.collisionType===vi.Active){const t=e.scale(e.dot(o.vel.negate()));o.vel=o.vel.add(t)}}}}}class br{constructor(t,e,i){this.point=t,this.local=e,this.contact=i,this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.aToContact=new A(0,0),this.bToContact=new A(0,0),this.update()}update(){var t,e;const i=null===(t=this.contact.colliderA.owner)||void 0===t?void 0:t.get($i),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get($i);if(i&&s){const t=this.contact.normal,e=this.contact.tangent;this.aToContact=this.point.sub(i.pos),this.bToContact=this.point.sub(s.pos);const r=this.aToContact.cross(t),n=this.bToContact.cross(t);this.normalMass=i.inverseMass+s.inverseMass+i.inverseInertia*r*r+s.inverseInertia*n*n;const o=this.aToContact.cross(e),a=this.bToContact.cross(e);this.tangentMass=i.inverseMass+s.inverseMass+i.inverseInertia*o*o+s.inverseInertia*a*a}return this}getRelativeVelocity(){var t,e;const i=null===(t=this.contact.colliderA.owner)||void 0===t?void 0:t.get($i),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get($i);if(i&&s){const t=i.vel.add(A.cross(i.angularVelocity,this.aToContact));return s.vel.add(A.cross(s.angularVelocity,this.bToContact)).sub(t)}return A.Zero}}class Cr extends wr{constructor(){super(...arguments),this.lastFrameContacts=new Map,this.idToContactConstraint=new Map}getContactConstraints(t){var e;return null!==(e=this.idToContactConstraint.get(t))&&void 0!==e?e:[]}preSolve(t){var e,i,s;for(const e of t){const t=T.fromDirection(e.mtv);e.colliderA.events.emit("precollision",new jt(e.colliderA,e.colliderB,t,e.mtv)),e.colliderA.events.emit("beforecollisionresolve",new Qt(e.colliderA,e.colliderB,t,e.mtv,e)),e.colliderB.events.emit("precollision",new jt(e.colliderB,e.colliderA,T.getOpposite(t),e.mtv.negate())),e.colliderB.events.emit("beforecollisionresolve",new Qt(e.colliderB,e.colliderA,T.getOpposite(t),e.mtv.negate(),e)),e.matchAwake()}const r=Array.from(this.idToContactConstraint.keys());for(const n of t){const t=r.indexOf(n.id);t>-1&&r.splice(t,1);const o=null!==(e=this.idToContactConstraint.get(n.id))&&void 0!==e?e:[];let a=0;const h=n.colliderA.owner.get($i),l=n.colliderB.owner.get($i);if(h&&l)for(const t of n.points){const e=n.normal,r=n.tangent,c=t.sub(h.pos),d=t.sub(l.pos),u=c.cross(e),p=d.cross(e),g=h.inverseMass+l.inverseMass+h.inverseInertia*u*u+l.inverseInertia*p*p,_=c.cross(r),f=d.cross(r),m=h.inverseMass+l.inverseMass+h.inverseInertia*_*_+l.inverseInertia*f*f;o[a]&&(null===(s=null===(i=o[a])||void 0===i?void 0:i.point)||void 0===s?void 0:s.squareDistance(t))<4?(o[a].point=t,o[a].local=n.localPoints[a]):o[a]=new br(t,n.localPoints[a],n),o[a].aToContact=c,o[a].bToContact=d,o[a].normalMass=g,o[a].tangentMass=m,a++}this.idToContactConstraint.set(n.id,o)}for(const t of r)this.idToContactConstraint.delete(t);if(Ci.warmStart)this.warmStart(t);else for(const e of t){const t=this.getContactConstraints(e.id);for(const e of t)e.normalImpulse=0,e.tangentImpulse=0}}postSolve(t){for(const e of t){const t=e.colliderA.owner.get($i),i=e.colliderB.owner.get($i);if(t&&i){if(t.collisionType===vi.Passive||i.collisionType===vi.Passive)continue;t.updateMotion(),i.updateMotion()}const s=T.fromDirection(e.mtv);e.colliderA.events.emit("postcollision",new Kt(e.colliderA,e.colliderB,s,e.mtv)),e.colliderA.events.emit("aftercollisionresolve",new $t(e.colliderA,e.colliderB,s,e.mtv,e)),e.colliderB.events.emit("postcollision",new Kt(e.colliderB,e.colliderA,T.getOpposite(s),e.mtv.negate())),e.colliderB.events.emit("aftercollisionresolve",new $t(e.colliderB,e.colliderA,T.getOpposite(s),e.mtv.negate(),e))}this.lastFrameContacts.clear();for(const e of t)this.lastFrameContacts.set(e.id,e)}warmStart(t){var e,i,s;for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){const e=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const i of e)if(Ci.warmStart){const e=r.normal.scale(i.normalImpulse),s=r.tangent.scale(i.tangentImpulse),o=e.add(s);t.applyImpulse(i.point,o.negate()),n.applyImpulse(i.point,o)}else i.normalImpulse=0,i.tangentImpulse=0}}}solvePosition(t){var e,i,s;for(let r=0;r<Ci.positionIterations;r++)for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){if(t.collisionType===vi.Passive||n.collisionType===vi.Passive)continue;const e=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const i of e){const e=r.normal,s=qi.FindContactSeparation(r,i.local),o=-5,a=z(Ci.steeringFactor*(s+Ci.slop),o,0),h=e.scale(-a/i.normalMass);t.collisionType===vi.Active&&(t.pos=t.pos.add(h.negate().scale(t.inverseMass)),t.rotation-=i.aToContact.cross(h)*t.inverseInertia),n.collisionType===vi.Active&&(n.pos=n.pos.add(h.scale(n.inverseMass)),n.rotation+=i.bToContact.cross(h)*n.inverseInertia)}}}}solveVelocity(t){var e,i,s;for(let r=0;r<Ci.velocityIterations;r++)for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){if(t.collisionType===vi.Passive||n.collisionType===vi.Passive)continue;const e=t.bounciness*n.bounciness,i=Math.min(t.friction,n.friction),o=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const e of o){let s=-e.getRelativeVelocity().dot(r.tangent)/e.tangentMass;const o=i*e.normalImpulse,a=z(e.tangentImpulse+s,-o,o);s=a-e.tangentImpulse,e.tangentImpulse=a;const h=r.tangent.scale(s);t.applyImpulse(e.point,h.negate()),n.applyImpulse(e.point,h)}for(const i of o){let s=-(1+e)*i.getRelativeVelocity().dot(r.normal)/i.normalMass;const o=Math.max(i.normalImpulse+s,0);s=o-i.normalImpulse,i.normalImpulse=o;const a=r.normal.scale(s);t.applyImpulse(i.point,a.negate()),n.applyImpulse(i.point,a)}}}}}class Sr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.motion","ex.collider"],this.systemType=or.Update,this.priority=-1,this._realisticSolver=new Cr,this._arcadeSolver=new xr,this._processor=new zi,this._lastFrameContacts=new Map,this._currentFrameContacts=new Map,this._trackCollider=t=>this._processor.track(t),this._untrackCollider=t=>this._processor.untrack(t)}notify(t){if(lr(t)){const e=t.data.get(Zi);e.$colliderAdded.subscribe(this._trackCollider),e.$colliderRemoved.subscribe(this._untrackCollider);const i=e.get();i&&this._processor.track(i)}else{const e=t.data.get(Zi),i=e.get();e&&i&&this._processor.untrack(i)}}initialize(t){this._engine=t.engine}update(t,e){var i;if(!Ci.enabled)return;let s=[];for(const e of t){const t=e.get(Zi),r=null==t?void 0:t.get();t&&(null===(i=t.owner)||void 0===i?void 0:i.active)&&r&&(t.update(),r instanceof Ui?s=s.concat(r.getColliders()):s.push(r))}this._processor.update(s);const r=this._processor.broadphase(s,e);this._currentFrameContacts.clear();let n=this._processor.narrowphase(r,this._engine.debug.stats.currFrame);n=this.getSolver().solve(n),n.forEach((t=>this._currentFrameContacts.set(t.id,t))),this.runContactStartEnd(),this._lastFrameContacts.clear(),this._lastFrameContacts=new Map(this._currentFrameContacts)}getSolver(){return Ci.collisionResolutionStrategy===yi.Realistic?this._realisticSolver:this._arcadeSolver}debug(t){this._processor.debug(t)}runContactStartEnd(){for(const[t,e]of this._currentFrameContacts)if(!this._lastFrameContacts.has(t)){const t=e.colliderA,i=e.colliderB;t.events.emit("collisionstart",new Jt(t,i,e)),t.events.emit("contactstart",new Yt(t,i,e)),i.events.emit("collisionstart",new Jt(i,t,e)),i.events.emit("contactstart",new Yt(i,t,e))}for(const[t,e]of this._lastFrameContacts)if(!this._currentFrameContacts.has(t)){const t=e.colliderA,i=e.colliderB;t.events.emit("collisionend",new te(t,i)),t.events.emit("contactend",new Zt(t,i)),i.events.emit("collisionend",new te(i,t)),i.events.emit("contactend",new Zt(i,t))}}}var Ar,Pr,Tr;!function(t){t.Forward="forward",t.Backward="backward"}(Ar||(Ar={})),function(t){t.End="end",t.Loop="loop",t.PingPong="pingpong",t.Freeze="freeze"}(Pr||(Pr={}));class Er extends _t{constructor(t){var e,i;super(t),this.events=new he,this.frames=[],this.strategy=Pr.Loop,this.frameDuration=100,this.timeScale=1,this._idempotencyToken=-1,this._firstTick=!0,this._currentFrame=0,this._timeLeftInFrame=0,this._direction=1,this._done=!1,this._playing=!0,this._reversed=!1,this.frames=t.frames,this.strategy=null!==(e=t.strategy)&&void 0!==e?e:this.strategy,this.frameDuration=t.totalDuration?t.totalDuration/this.frames.length:null!==(i=t.frameDuration)&&void 0!==i?i:this.frameDuration,t.reverse&&this.reverse(),this.goToFrame(0)}clone(){return new Er({frames:this.frames.map((t=>({...t}))),frameDuration:this.frameDuration,reverse:this._reversed,strategy:this.strategy,...this.cloneGraphicOptions()})}get width(){const t=this.currentFrame;return t?Math.abs(t.graphic.width*this.scale.x):0}get height(){const t=this.currentFrame;return t?Math.abs(t.graphic.height*this.scale.y):0}static fromSpriteSheet(t,e,i,s=Pr.Loop){const r=t.sprites.length-1,n=e.filter((t=>t<0||t>r));return n.length&&Er._LOGGER.warn(`Indices into SpriteSheet were provided that don't exist: ${n.join(",")} no frame will be shown`),new Er({frames:t.sprites.filter(((t,i)=>e.indexOf(i)>-1)).map((t=>({graphic:t,duration:i}))),strategy:s})}static toLegacyAnimation(t,e){const i=e.frames.map((t=>Ae.toLegacySprite(t.graphic)));return new Ie({sprites:i,loop:e.strategy===Pr.Loop,freezeFrame:e.strategy===Pr.Freeze?i.length-1:void 0,speed:e.frameDuration,engine:t})}get currentFrame(){return this._currentFrame>=0&&this._currentFrame<this.frames.length?this.frames[this._currentFrame]:null}get currentFrameIndex(){return this._currentFrame}get isPlaying(){return this._playing}reverse(){this.frames=this.frames.slice().reverse(),this._reversed=!this._reversed}get direction(){return!(!this._reversed||1!==this._direction)?Ar.Backward:Ar.Forward}play(){this._playing=!0}pause(){this._playing=!1,this._firstTick=!0}reset(){this._done=!1,this._firstTick=!0,this._currentFrame=0}get canFinish(){switch(this.strategy){case Pr.End:case Pr.Freeze:return!0;default:return!1}}get done(){return this._done}goToFrame(t){this._currentFrame=t,this._timeLeftInFrame=this.frameDuration;const e=this.frames[this._currentFrame];e&&!this._done&&(this._timeLeftInFrame=(null==e?void 0:e.duration)||this.frameDuration,this.events.emit("frame",e))}_nextFrame(){const t=this._currentFrame;if(this._done)return t;let e=-1;switch(this.strategy){case Pr.Loop:e=(t+1)%this.frames.length,0===e&&this.events.emit("loop",this);break;case Pr.End:e=t+1,e>=this.frames.length&&(this._done=!0,this._currentFrame=this.frames.length,this.events.emit("end",this));break;case Pr.Freeze:e=z(t+1,0,this.frames.length-1),e>=this.frames.length-1&&(this._done=!0,this.events.emit("end",this));break;case Pr.PingPong:t+this._direction>=this.frames.length&&(this._direction=-1,this.events.emit("loop",this)),t+this._direction<0&&(this._direction=1,this.events.emit("loop",this)),e=t+this._direction%this.frames.length}return e}tick(t,e=0){this._idempotencyToken!==e&&(this._idempotencyToken=e,this._playing&&(this._firstTick&&(this._firstTick=!1,this.events.emit("frame",this.currentFrame)),this._timeLeftInFrame-=t*this.timeScale,this._timeLeftInFrame<=0&&this.goToFrame(this._nextFrame())))}_drawImage(t,e,i){this.currentFrame&&this.currentFrame.graphic.draw(t,e,i)}}Er._LOGGER=f.getInstance();class Ir extends _t{constructor(t){super(t),this.members=[],this.members=t.members,this._updateDimensions()}clone(){return new Ir({members:[...this.members],...this.cloneGraphicOptions()})}_updateDimensions(){let t=new B;for(const{graphic:e,pos:i}of this.members)t=e.localBounds.translate(i).combine(t);return this.width=t.width,this.height=t.height,t}get localBounds(){let t=new B;for(const{graphic:e,pos:i}of this.members)t=e.localBounds.translate(i).combine(t);return t}_isAnimationOrGroup(t){return t instanceof Er||t instanceof Ir}tick(t,e){for(const i of this.members){const s=i.graphic;this._isAnimationOrGroup(s)&&s.tick(t,e)}}reset(){for(const t of this.members){const e=t.graphic;this._isAnimationOrGroup(e)&&e.reset()}}_preDraw(t,e,i){this._updateDimensions(),super._preDraw(t,e,i)}_drawImage(t,e,i){for(const s of this.members)t.save(),t.translate(e,i),s.graphic.draw(t,s.pos.x,s.pos.y),this.showDebug&&t.debug.drawRect(0,0,this.width,this.height),t.restore()}}!function(t){t[t.Circle=0]="Circle",t[t.Rectangle=1]="Rectangle"}(Tr||(Tr={}));class Rr extends ns{constructor(t,e,i,s,r,n,o,a,h,l){super(),this.position=new A(0,0),this.velocity=new A(0,0),this.acceleration=new A(0,0),this.particleRotationalVelocity=0,this.currentRotation=0,this.focus=null,this.focusAccel=0,this.opacity=1,this.beginColor=I.White,this.endColor=I.White,this.life=300,this.fadeFlag=!1,this._rRate=1,this._gRate=1,this._bRate=1,this._aRate=0,this._currentColor=I.White,this.emitter=null,this.particleSize=5,this.particleSprite=null,this.sizeRate=0,this.elapsedMultiplier=0,this.visible=!0,this.isOffscreen=!1;let c=t;if(c&&!(t instanceof Dr)){const d=t;c=d.emitter,e=d.life,i=d.opacity,r=d.endColor,s=d.beginColor,n=d.position,o=d.velocity,a=d.acceleration,h=d.startSize,l=d.endSize}this.emitter=c,this.life=e||this.life,this.opacity=i||this.opacity,this.endColor=r||this.endColor.clone(),this.beginColor=s||this.beginColor.clone(),this._currentColor=this.beginColor.clone(),this.position=(n||this.position).add(this.emitter.pos),this.velocity=o||this.velocity,this.acceleration=a||this.acceleration,this._rRate=(this.endColor.r-this.beginColor.r)/this.life,this._gRate=(this.endColor.g-this.beginColor.g)/this.life,this._bRate=(this.endColor.b-this.beginColor.b)/this.life,this._aRate=this.opacity/this.life,this.startSize=h||0,this.endSize=l||0,this.endSize>0&&this.startSize>0&&(this.sizeRate=(this.endSize-this.startSize)/this.life,this.particleSize=this.startSize),this.addComponent(this.transform=new Ei),this.addComponent(new os((t=>this.draw(t)))),this.addComponent(this.graphics=new cs),this.transform.pos=this.position,this.transform.rotation=this.currentRotation,this.transform.scale=P(1,1),this.particleSprite?(this.graphics.opacity=this.opacity,this.graphics.use(Ae.fromLegacySprite(this.particleSprite))):this.graphics.onPostDraw=t=>{t.save(),this.graphics.opacity=this.opacity;const e=this._currentColor.clone();e.a=1,t.debug.drawPoint(P(0,0),{color:e,size:this.particleSize}),t.restore()}}kill(){this.emitter.removeParticle(this)}update(t,e){if(this.life=this.life-e,this.elapsedMultiplier=this.elapsedMultiplier+e,this.life<0&&this.kill(),this.fadeFlag&&(this.opacity=z(this._aRate*this.life,1e-4,1)),this.startSize>0&&this.endSize>0&&(this.particleSize=z(this.sizeRate*e+this.particleSize,Math.min(this.startSize,this.endSize),Math.max(this.startSize,this.endSize))),this._currentColor.r=z(this._currentColor.r+this._rRate*e,0,255),this._currentColor.g=z(this._currentColor.g+this._gRate*e,0,255),this._currentColor.b=z(this._currentColor.b+this._bRate*e,0,255),this._currentColor.a=z(this.opacity,1e-4,1),this.focus){const t=this.focus.sub(this.position).normalize().scale(this.focusAccel).scale(e/1e3);this.velocity=this.velocity.add(t)}else this.velocity=this.velocity.add(this.acceleration.scale(e/1e3));this.position=this.position.add(this.velocity.scale(e/1e3)),this.particleRotationalVelocity&&(this.currentRotation=(this.currentRotation+this.particleRotationalVelocity*e/1e3)%(2*Math.PI)),this.transform.pos=this.position,this.transform.rotation=this.currentRotation,this.transform.scale=P(1,1),this.graphics.opacity=this.opacity}draw(t){if(this.particleSprite)return this.particleSprite.opacity(this.opacity),void this.particleSprite.draw(t,0,0);t.save(),this._currentColor.a=z(this.opacity,1e-4,1),t.fillStyle=this._currentColor.toString(),t.beginPath(),t.arc(0,0,this.particleSize,0,2*Math.PI),t.fill(),t.closePath(),t.restore()}}class Br extends(xe(Rr)){constructor(t,e,i,s,r,n,o,a,h,l){super(t,e,i,s,r,n,o,a,h,l)}}class Dr extends Us{constructor(t){var e,i;super({width:null!==(e=t.width)&&void 0!==e?e:0,height:null!==(i=t.height)&&void 0!==i?i:0}),this._particlesToEmit=0,this.numParticles=0,this.isEmitting=!0,this.particles=[],this.deadParticles=[],this.minVel=0,this.maxVel=0,this.acceleration=new A(0,0),this.minAngle=0,this.maxAngle=0,this.emitRate=1,this.particleLife=2e3,this.fadeFlag=!1,this.focus=null,this.focusAccel=null,this.startSize=null,this.endSize=null,this.minSize=5,this.maxSize=5,this.beginColor=I.White,this.endColor=I.White,this._og=null,this._sprite=null,this.emitterType=Tr.Rectangle,this.radius=0,this.particleRotationalVelocity=0,this.randomRotation=!1;const{x:s,y:r,pos:n,isEmitting:o,minVel:a,maxVel:h,acceleration:l,minAngle:c,maxAngle:d,emitRate:u,particleLife:p,opacity:g,fadeFlag:_,focus:f,focusAccel:m,startSize:v,endSize:y,minSize:w,maxSize:x,beginColor:b,endColor:C,particleSprite:S,emitterType:T,radius:E,particleRotationalVelocity:R,randomRotation:B,random:D}={...t};this.pos=null!=n?n:P(null!=s?s:0,null!=r?r:0),this.isEmitting=null!=o?o:this.isEmitting,this.minVel=null!=a?a:this.minVel,this.maxVel=null!=h?h:this.maxVel,this.acceleration=null!=l?l:this.acceleration,this.minAngle=null!=c?c:this.minAngle,this.maxAngle=null!=d?d:this.maxAngle,this.emitRate=null!=u?u:this.emitRate,this.particleLife=null!=p?p:this.particleLife,this.opacity=null!=g?g:this.opacity,this.fadeFlag=null!=_?_:this.fadeFlag,this.focus=null!=f?f:this.focus,this.focusAccel=null!=m?m:this.focusAccel,this.startSize=null!=v?v:this.startSize,this.endSize=null!=y?y:this.endSize,this.minSize=null!=w?w:this.minSize,this.maxSize=null!=x?x:this.maxSize,this.beginColor=null!=b?b:this.beginColor,this.endColor=null!=C?C:this.endColor,this.particleSprite=null!=S?S:this.particleSprite,this.emitterType=null!=T?T:this.emitterType,this.radius=null!=E?E:this.radius,this.particleRotationalVelocity=null!=R?R:this.particleRotationalVelocity,this.randomRotation=null!=B?B:this.randomRotation,this.body.collisionType=vi.PreventCollision,this.random=null!=D?D:new M;for(let t=0;t<this.traits.length;t++)this.traits[t]instanceof ts&&this.traits.splice(t,1)}get opacity(){return super.graphics.opacity}set opacity(t){super.graphics.opacity=t}get particleSprite(){return this._og}set particleSprite(t){this._og=t,t&&(this._sprite=Ae.fromLegacySprite(t))}removeParticle(t){this.deadParticles.push(t)}emitParticles(t){var e;for(let i=0;i<t;i++){const t=this._createParticle();this.particles.push(t),(null===(e=null==this?void 0:this.scene)||void 0===e?void 0:e.world)&&this.scene.world.add(t)}}clearParticles(){this.particles.length=0}_createParticle(){let t=0,e=0;const i=W(this.minAngle,this.maxAngle,this.random),s=W(this.minVel,this.maxVel,this.random),r=this.startSize||W(this.minSize,this.maxSize,this.random),n=s*Math.cos(i),o=s*Math.sin(i);if(this.emitterType===Tr.Rectangle)t=W(0,this.width,this.random),e=W(0,this.height,this.random);else if(this.emitterType===Tr.Circle){const s=W(0,this.radius,this.random);t=s*Math.cos(i),e=s*Math.sin(i)}const a=new Br(this,this.particleLife,this.opacity,this.beginColor,this.endColor,new A(t,e),new A(n,o),this.acceleration,this.startSize,this.endSize);return a.fadeFlag=this.fadeFlag,a.particleSize=r,this.particleSprite&&(a.particleSprite=this.particleSprite,a.graphics.opacity=this.opacity,a.graphics.use(this._sprite)),a.particleRotationalVelocity=this.particleRotationalVelocity,this.randomRotation&&(a.currentRotation=W(0,2*Math.PI,this.random)),this.focus&&(a.focus=this.focus.add(new A(this.pos.x,this.pos.y)),a.focusAccel=this.focusAccel),a}update(t,e){var i;super.update(t,e),this.isEmitting&&(this._particlesToEmit+=this.emitRate*(e/1e3),this._particlesToEmit>1&&(this.emitParticles(Math.floor(this._particlesToEmit)),this._particlesToEmit=this._particlesToEmit-Math.floor(this._particlesToEmit)));for(let t=0;t<this.deadParticles.length;t++)tt(this.deadParticles[t],this.particles),(null===(i=null==this?void 0:this.scene)||void 0===i?void 0:i.world)&&this.scene.world.remove(this.deadParticles[t],!1);this.deadParticles.length=0}draw(t){this.particles.forEach((e=>e.draw(t)))}debugDraw(t){super.debugDraw(t),t.fillStyle=I.Black.toString(),t.fillText("Particles: "+this.particles.length,this.pos.x,this.pos.y+20),this.focus&&(t.fillRect(this.focus.x+this.pos.x,this.focus.y+this.pos.y,3,3),li(t,I.Yellow,this.focus.x+this.pos.x,this.focus.y+this.pos.y,this.center.x,this.center.y),t.fillText("Focus",this.focus.x+this.pos.x,this.focus.y+this.pos.y))}}class Mr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.graphics"],this.systemType=or.Draw,this.priority=0,this._token=0}initialize(t){this._graphicsContext=t.engine.graphicsContext,this._camera=t.camera,this._engine=t.engine}sort(t,e){return t.get(Ei).z-e.get(Ei).z}update(t,e){let i,s;this._token++;for(const r of t){i=r.get(Ei),s=r.get(cs);const t=this._isOffscreen(i,s);if(t&&!r.hasTag("offscreen")&&(r.eventDispatcher.emit("exitviewport",new re(r)),r.addComponent(new Pi("offscreen"))),!t&&r.hasTag("offscreen")&&(r.eventDispatcher.emit("enterviewport",new ne(r)),r.removeComponent("offscreen")),t)continue;this._pushCameraTransform(i),this._graphicsContext.save(),s.update(e,this._token),this._applyTransform(r),s.onPreDraw&&s.onPreDraw(this._graphicsContext,e);const n=r instanceof Br?r.opacity:1;this._graphicsContext.opacity=s.opacity*n,this._drawGraphicsComponent(s),s.onPostDraw&&s.onPostDraw(this._graphicsContext,e),this._graphicsContext.restore(),this._popCameraTransform(i)}}_isOffscreen(t,e){if(t.coordPlane===Ti.World){return!this._camera.viewport.intersect(e.localBounds.transform(t.getGlobalMatrix()))}return!1}_drawGraphicsComponent(t){var e,i;if(t.visible)for(const s of t.layers.get())for(const{graphic:r,options:n}of s.graphics){let o=t.anchor,a=t.offset;(null==n?void 0:n.anchor)&&(o=n.anchor),(null==n?void 0:n.offset)&&(a=n.offset);const h=-r.width*o.x+a.x,l=-r.height*o.y+a.y;if(null==r||r.draw(this._graphicsContext,h+s.offset.x,l+s.offset.y),(null===(e=this._engine)||void 0===e?void 0:e.isDebug)&&this._engine.debug.graphics.showBounds){const t=P(h+s.offset.x,l+s.offset.y);if(r instanceof Ir)for(const e of r.members)null===(i=e.graphic)||void 0===i||i.localBounds.translate(t.add(e.pos)).draw(this._graphicsContext,this._engine.debug.graphics.boundsColor);else null==r||r.localBounds.translate(t).draw(this._graphicsContext,this._engine.debug.graphics.boundsColor)}}}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._graphicsContext.translate(e.pos.x,e.pos.y),this._graphicsContext.scale(e.scale.x,e.scale.y),this._graphicsContext.rotate(e.rotation))}}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._graphicsContext.restore()}}class kr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.canvas"],this.systemType=or.Draw,this.priority=-1}initialize(t){this._ctx=t.engine.ctx,this._engine=t.engine,this._camera=t.camera}sort(t,e){return t.get(Ei).z-e.get(Ei).z}update(t,e){var i,s,r;let n,o;this._clearScreen();const a=t.length;for(let h=0;h<a;h++){const a=null===(r=null===(s=null===(i=t[h])||void 0===i?void 0:i.graphics)||void 0===s?void 0:s.visible)||void 0===r||r,l=t[h].isOffScreen;a&&!l&&(n=t[h].get(Ei),o=t[h].get(os),this._ctx.save(),this._pushCameraTransform(n),this._ctx.save(),this._applyTransform(t[h]),o.draw(this._ctx,e),this._ctx.restore(),this._popCameraTransform(n),this._ctx.restore()),this._engine.isDebug&&(this._ctx.save(),this._pushCameraTransform(n),this._ctx.strokeStyle="yellow",t[h].debugDraw(this._ctx),this._popCameraTransform(n),this._ctx.restore())}this._engine.isDebug&&(this._ctx.save(),this._camera.draw(this._ctx),this._camera.debugDraw(this._ctx),this._ctx.restore()),this._engine.stats.currFrame.graphics.drawnImages=je.DrawnImagesCount,this._engine.stats.currFrame.graphics.drawCalls=je.DrawCallCount}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._ctx.translate(e.pos.x,e.pos.y),this._ctx.rotate(e.rotation),this._ctx.scale(e.scale.x,e.scale.y))}}_clearScreen(){this._ctx.clearRect(0,0,this._ctx.canvas.width,this._ctx.canvas.height),this._ctx.fillStyle=this._engine.backgroundColor.toString(),this._ctx.fillRect(0,0,this._ctx.canvas.width,this._ctx.canvas.height)}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._ctx.save(),this._camera&&this._camera.draw(this._ctx))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._ctx.restore()}}class Fr extends ar{constructor(){super(...arguments),this.types=["ex.transform"],this.systemType=or.Draw,this.priority=999}initialize(t){this._graphicsContext=t.engine.graphicsContext,this._camera=t.camera,this._engine=t.engine,this._collisionSystem=t.world.systemManager.get(Sr)}update(t,e){var i,s;if(!this._engine.isDebug)return;const r=this._engine.debug.filter;let n,o;const a=this._engine.debug.entity;let h;const l=this._engine.debug.transform;let c;const d=this._engine.debug.motion;let u;const p=this._engine.debug.collider,g=this._engine.debug.physics;let _;const f=this._engine.debug.graphics;let m,v;const y=this._engine.debug.body,w=this._engine.debug.camera;for(const e of t){if(e.hasTag("offscreen"))continue;if(e instanceof Br)continue;if(r.useFilter){if(!(0===r.ids.length||r.ids.includes(e.id)))continue;if(!(""===r.nameQuery||e.name.includes(r.nameQuery)))continue}let t=A.Zero;const g=P(0,16);if(n=e.id,o=e.name,h=e.get(Ei),this._pushCameraTransform(h),this._graphicsContext.save(),this._applyTransform(e),h&&((l.showAll||l.showPosition)&&this._graphicsContext.debug.drawPoint(A.Zero,{size:4,color:l.positionColor}),(l.showAll||l.showPositionLabel)&&(this._graphicsContext.debug.drawText(`pos${h.pos.toString(2)}`,t),t=t.add(g)),(a.showAll||a.showId)&&(this._graphicsContext.debug.drawText(`id(${n}) ${h.parent?"child of id("+(null===(s=null===(i=h.parent)||void 0===i?void 0:i.owner)||void 0===s?void 0:s.id)+")":""}`,t),t=t.add(g)),(a.showAll||a.showName)&&(this._graphicsContext.debug.drawText(`name(${o})`,t),t=t.add(g)),(l.showAll||l.showRotation)&&(this._graphicsContext.drawLine(A.Zero,A.fromAngle(h.rotation).scale(50).add(A.Zero),l.rotationColor,2),this._graphicsContext.debug.drawText(`rot deg(${U(h.rotation).toFixed(2)})`,t),t=t.add(g)),(l.showAll||l.showScale)&&this._graphicsContext.drawLine(A.Zero,h.scale.add(A.Zero),l.scaleColor,2)),_=e.get(cs),_&&(f.showAll||f.showBounds)){_.localBounds.draw(this._graphicsContext,f.boundsColor)}if(m=e.get(Vs),m&&m.draw(this._graphicsContext),v=e.get($i),v&&((y.showAll||y.showCollisionGroup)&&(this._graphicsContext.debug.drawText(`collision group(${v.group.name})`,t),t=t.add(g)),(y.showAll||y.showCollisionType)&&(this._graphicsContext.debug.drawText(`collision type(${v.collisionType})`,t),t=t.add(g)),(y.showAll||y.showMass)&&(this._graphicsContext.debug.drawText(`mass(${v.mass})`,t),t=t.add(g)),(y.showAll||y.showMotion)&&(this._graphicsContext.debug.drawText(`motion(${v.sleepMotion})`,t),t=t.add(g)),(y.showAll||y.showSleeping)&&(this._graphicsContext.debug.drawText(`sleeping(${v.canSleep?v.sleeping:"cant sleep"})`,t),t=t.add(g))),this._graphicsContext.restore(),c=e.get(Ii),c&&((d.showAll||d.showVelocity)&&(this._graphicsContext.debug.drawText(`vel${c.vel.toString(2)}`,t.add(h.globalPos)),this._graphicsContext.drawLine(h.globalPos,h.globalPos.add(c.vel),d.velocityColor,2),t=t.add(g)),(d.showAll||d.showAcceleration)&&this._graphicsContext.drawLine(h.globalPos,h.globalPos.add(c.acc),d.accelerationColor,2)),u=e.get(Zi),u){const t=u.get();if((p.showAll||p.showGeometry)&&t&&t.debug(this._graphicsContext,p.geometryColor),p.showAll||p.showBounds)if(t instanceof Ui){const e=t.getColliders();for(const t of e){const e=t.bounds,i=P(e.left,e.top);this._graphicsContext.debug.drawRect(i.x,i.y,e.width,e.height,{color:p.boundsColor}),(p.showAll||p.showOwner)&&this._graphicsContext.debug.drawText(`owner id(${t.owner.id})`,i)}u.bounds.draw(this._graphicsContext,p.boundsColor)}else if(t){const t=u.bounds,e=P(t.left,t.top);this._graphicsContext.debug.drawRect(e.x,e.y,t.width,t.height,{color:p.boundsColor}),(p.showAll||p.showOwner)&&this._graphicsContext.debug.drawText(`owner id(${u.owner.id})`,e)}}this._popCameraTransform(h)}if(this._graphicsContext.save(),this._camera.draw(this._graphicsContext),(g.showAll||g.showBroadphaseSpacePartitionDebug)&&this._collisionSystem.debug(this._graphicsContext),g.showAll||g.showCollisionContacts||g.showCollisionNormals)for(const[t,e]of this._engine.debug.stats.currFrame.physics.contacts){if(g.showAll||g.showCollisionContacts)for(const t of e.points)this._graphicsContext.debug.drawPoint(t,{size:5,color:g.collisionContactColor});if(g.showAll||g.showCollisionNormals)for(const t of e.points)this._graphicsContext.debug.drawLine(t,e.normal.scale(30).add(t),{color:g.collisionNormalColor})}this._graphicsContext.restore(),w&&(this._graphicsContext.save(),this._camera.draw(this._graphicsContext),(w.showAll||w.showFocus)&&this._graphicsContext.drawCircle(this._camera.pos,4,w.focusColor),(w.showAll||w.showZoom)&&this._graphicsContext.debug.drawText(`zoom(${this._camera.zoom})`,this._camera.pos),this._graphicsContext.restore()),this._graphicsContext.flush()}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._graphicsContext.translate(e.pos.x,e.pos.y),this._graphicsContext.scale(e.scale.x,e.scale.y),this._graphicsContext.rotate(e.rotation))}}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._graphicsContext.restore()}}class Lr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.pointer"],this.systemType=or.Update,this.priority=-1,this.overrideUseColliderShape=!1,this.overrideUseGraphicsBounds=!1,this.lastFrameEntityToPointers=new Map,this.currentFrameEntityToPointers=new Map}initialize(t){this._engine=t.engine,this._receiver=this._engine.input.pointers}sort(t,e){return e.get(Ei).z-t.get(Ei).z}entityCurrentlyUnderPointer(t,e){return this.currentFrameEntityToPointers.has(t.id)&&this.currentFrameEntityToPointers.get(t.id).includes(e)}entityWasUnderPointer(t,e){return this.lastFrameEntityToPointers.has(t.id)&&this.lastFrameEntityToPointers.get(t.id).includes(e)}entered(t,e){return this.entityCurrentlyUnderPointer(t,e)&&!this.lastFrameEntityToPointers.has(t.id)}left(t,e){return!this.currentFrameEntityToPointers.has(t.id)&&this.entityWasUnderPointer(t,e)}addPointerToEntity(t,e){if(!this.currentFrameEntityToPointers.has(t.id))return void this.currentFrameEntityToPointers.set(t.id,[e]);const i=this.currentFrameEntityToPointers.get(t.id);this.currentFrameEntityToPointers.set(t.id,i.concat(e))}update(t){this._processPointerToEntity(t),this._dispatchEvents(t),this._receiver.update(),this.lastFrameEntityToPointers.clear(),this.lastFrameEntityToPointers=new Map(this.currentFrameEntityToPointers),this.currentFrameEntityToPointers.clear(),this._receiver.clear()}_processPointerToEntity(t){var e;let i,s,r,n;for(const o of t){if(i=o.get(Ei),n=null!==(e=o.get(ps))&&void 0!==e?e:new ps,s=o.get(Zi),s&&(n.useColliderShape||this.overrideUseColliderShape)){const t=s.get();if(t)for(const[e,s]of this._receiver.currentFramePointerCoords.entries())t.contains(i.coordPlane===Ti.World?s.worldPos:s.screenPos)&&this.addPointerToEntity(o,e)}if(r=o.get(cs),r&&(n.useGraphicsBounds||this.overrideUseGraphicsBounds)){const t=r.localBounds.transform(i.getGlobalMatrix());for(const[e,s]of this._receiver.currentFramePointerCoords.entries())t.contains(i.coordPlane===Ti.World?s.worldPos:s.screenPos)&&this.addPointerToEntity(o,e)}}}_processDownAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameDown)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointerdown",i),this._receiver.isDragStart(i.pointerId)&&t.events.emit("pointerdragstart",i)),e.set(i.pointerId,i);return e}_processUpAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameUp)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointerup",i),this._receiver.isDragEnd(i.pointerId)&&t.events.emit("pointerdragend",i)),e.set(i.pointerId,i);return e}_processMoveAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameMove)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointermove",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragmove",i)),e.set(i.pointerId,i);return e}_processEnterLeaveAndEmit(t,e){for(const i of e){if(i.active&&t.active&&this.entered(t,i.pointerId)){t.events.emit("pointerenter",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragenter",i);break}if(i.active&&t.active&&(this.left(t,i.pointerId)||this.entityCurrentlyUnderPointer(t,i.pointerId)&&"up"===i.type)){t.events.emit("pointerleave",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragleave",i);break}}}_processCancelAndEmit(t){for(const e of this._receiver.currentFrameCancel)e.active&&t.active&&this.entityCurrentlyUnderPointer(t,e.pointerId)&&t.events.emit("pointercancel",e)}_processWheelAndEmit(t){for(const e of this._receiver.currentFrameWheel)e.active&&t.active&&this.entityCurrentlyUnderPointer(t,0)&&t.events.emit("pointerwheel",e)}_dispatchEvents(t){const e=new Set(this.lastFrameEntityToPointers.keys()),i=new Set(this.currentFrameEntityToPointers.keys()),s=t.filter((t=>e.has(t.id)||i.has(t.id)));let r,n,o;for(const t of s){o=this._processDownAndEmit(t),n=this._processUpAndEmit(t),r=this._processMoveAndEmit(t);const e=[...r.values(),...o.values(),...n.values()];this._processEnterLeaveAndEmit(t,e),this._processCancelAndEmit(t),this._processWheelAndEmit(t)}}}class zr extends ar{constructor(){super(...arguments),this.types=["ex.actions"],this.systemType=or.Update,this.priority=-1}update(t,e){let i;for(const s of t)i=s.get(Fs),i.update(e)}}var Or,Ur=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Nr extends hi{constructor(){super(),this._logger=f.getInstance(),this.camera=new ir,this.world=new mr(this),this._isInitialized=!1,this._timers=[],this._cancelQueue=[],this.world.add(new zr),this.world.add(new yr),this.world.add(new Sr),this.world.add(new Lr),g.isEnabled(d.LegacyDrawing)?this.world.add(new kr):this.world.add(new Mr),this.world.add(new Fr)}get actors(){return this.world.entityManager.entities.filter((t=>t instanceof Us))}get entities(){return this.world.entityManager.entities}get triggers(){return this.world.entityManager.entities.filter((t=>t instanceof nr))}get tileMaps(){return this.world.entityManager.entities.filter((t=>t instanceof js))}get screenElements(){return this.actors.filter((t=>t instanceof Ns))}get timers(){return this._timers}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}onInitialize(t){}onActivate(t,e){}onDeactivate(t,e){}onPreUpdate(t,e){}onPostUpdate(t,e){}onPreDraw(t,e){}onPostDraw(t,e){}_initializeChildren(){for(const t of this.entities)t._initialize(this.engine)}get isInitialized(){return this._isInitialized}_initialize(t){this.isInitialized||(this.engine=t,this.camera._initialize(t),this.world.systemManager.initialize(),this.onInitialize.call(this,t),this._initializeChildren(),this._logger.debug("Scene.onInitialize",this,t),this.eventDispatcher.emit("initialize",new ee(t,this)),this._isInitialized=!0)}_activate(t,e){this._logger.debug("Scene.onActivate",this),this.onActivate(t,e)}_deactivate(t,e){this._logger.debug("Scene.onDeactivate",this),this.onDeactivate(t,e)}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}_predraw(t,e){this.emit("predraw",new Bt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new Dt(t,e,this)),this.onPostDraw(t,e)}update(t,e){let i,s;for(this._preupdate(t,e),i=0,s=this._cancelQueue.length;i<s;i++)this.removeTimer(this._cancelQueue[i]);this._cancelQueue.length=0;for(const t of this._timers)t.update(e);this.world.update(or.Update,e),this.camera&&this.camera.update(t,e),this._collectActorStats(t),this._postupdate(t,e)}draw(t,e){var i;this._predraw(t,e),this.world.update(or.Draw,e),(null===(i=this.engine)||void 0===i?void 0:i.isDebug)&&this.debugDraw(t),this._postdraw(t,e)}debugDraw(t){this.emit("predebugdraw",new Mt(t,this)),this.emit("postdebugdraw",new kt(t,this))}contains(t){return this.actors.indexOf(t)>-1}add(t){this.emit("entityadded",{target:t}),this.world.add(t),t.scene=this,t instanceof Ws&&(et(this._timers,t)||this.addTimer(t))}remove(t){t instanceof ns&&(this.emit("entityremoved",{target:t}),this.world.remove(t)),t instanceof Ws&&this.removeTimer(t)}addScreenElement(t){this.add(t)}removeScreenElement(t){this.remove(t)}addTileMap(t){this.world.add(t)}removeTileMap(t){this.world.remove(t)}addTimer(t){return this._timers.push(t),t.scene=this,t}removeTimer(t){const e=this._timers.indexOf(t);return-1!==e&&this._timers.splice(e,1),t}cancelTimer(t){return this._cancelQueue.push(t),t}isTimerActive(t){return this._timers.indexOf(t)>-1&&!t.complete}isCurrentScene(){return!!this.engine&&this.engine.currentScene===this}_collectActorStats(t){const e=this.actors.filter((t=>t instanceof Ns));for(const i of e)t.stats.currFrame.actors.ui++;for(const e of this.actors){t.stats.currFrame.actors.alive++;for(const i of e.children)sr(i)?t.stats.currFrame.actors.ui++:t.stats.currFrame.actors.alive++}}}Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"ScreenElements now are normal actors with a Transform Coordinate Plane of Screen"})],Nr.prototype,"screenElements",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Nr.prototype,"addScreenElement",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Nr.prototype,"removeScreenElement",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Nr.prototype,"addTileMap",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Nr.prototype,"removeTileMap",null),function(t){t.Protanope="Protanope",t.Deuteranope="Deuteranope",t.Tritanope="Tritanope"}(Or||(Or={}));class Hr{constructor(t){this._shader=new Ge({vertexSource:"\n attribute vec2 a_position;\n attribute vec2 a_texcoord;\n varying vec2 v_texcoord;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n // Pass the texcoord to the fragment shader.\n v_texcoord = a_texcoord;\n }",fragmentSource:t}),this._shader.compile(),this._buffer=new Xe({type:"static",data:new Float32Array([-1,-1,0,0,-1,1,0,1,1,-1,1,0,1,-1,1,0,-1,1,0,1,1,1,1,1])}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_texcoord",2]]}),this._buffer.upload()}getShader(){return this._shader}getLayout(){return this._layout}}class Wr{constructor(t,e=!1){this._colorBlindnessMode=t,this._simulate=!1,this._simulate=e}initialize(t){this._shader=new Hr("precision mediump float;\r\n// our texture\r\nuniform sampler2D u_image;\r\n// the texCoords passed in from the vertex shader.\r\nvarying vec2 v_texcoord;\r\n\r\n// color blind type\r\nuniform int u_type;\r\n\r\n// simulation?\r\nuniform bool u_simulate;\r\n\r\nvoid main() {\r\n vec4 o = texture2D(u_image, v_texcoord);\r\n // RGB to LMS matrix conversion\r\n float L = (17.8824 * o.r) + (43.5161 * o.g) + (4.11935 * o.b);\r\n float M = (3.45565 * o.r) + (27.1554 * o.g) + (3.86714 * o.b);\r\n float S = (0.0299566 * o.r) + (0.184309 * o.g) + (1.46709 * o.b);\r\n // Simulate color blindness\r\n float l;\r\n float m;\r\n float s;\r\n //MODE CODE//\r\n if (u_type == 0) {\r\n // Protanope\r\n l = 0.0 * L + 2.02344 * M + -2.52581 * S;\r\n m = 0.0 * L + 1.0 * M + 0.0 * S;\r\n s = 0.0 * L + 0.0 * M + 1.0 * S;;\r\n } else if (u_type == 1) {\r\n // Deuteranope\r\n l = 1.0 * L + 0.0 * M + 0.0 * S;\r\n m = 0.494207 * L + 0.0 * M + 1.24827 * S;\r\n s = 0.0 * L + 0.0 * M + 1.0 * S;\r\n } else if (u_type == 2) {\r\n // Tritanope\r\n l = 1.0 * L + 0.0 * M + 0.0 * S;\r\n m = 0.0 * L + 1.0 * M + 0.0 * S;\r\n s = -0.395913 * L + 0.801109 * M + 0.0 * S;\r\n }\r\n\r\n // LMS to RGB matrix conversion\r\n vec4 error; // simulate the colors\r\n error.r = (0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s);\r\n error.g = (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s);\r\n error.b = (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s);\r\n error.a = 1.0;\r\n vec4 diff = o - error;\r\n vec4 correction; // correct the colors\r\n correction.r = 0.0;\r\n correction.g = (diff.r * 0.7) + (diff.g * 1.0);\r\n correction.b = (diff.r * 0.7) + (diff.b * 1.0);\r\n correction = o + correction;\r\n correction.a = o.a;\r\n //SIMULATE//\r\n\r\n // sim \r\n if (u_simulate) {\r\n gl_FragColor = error.rgba;\r\n } else {\r\n gl_FragColor = correction.rgba;\r\n }\r\n}"),this.simulate=this._simulate,this.colorBlindnessMode=this._colorBlindnessMode}getShader(){return this._shader.getShader()}getLayout(){return this._shader.getLayout()}set colorBlindnessMode(t){if(this._colorBlindnessMode=t,this._shader){const t=this._shader.getShader();t.use(),this._colorBlindnessMode===Or.Protanope?t.setUniformInt("u_type",0):this._colorBlindnessMode===Or.Deuteranope?t.setUniformInt("u_type",1):this._colorBlindnessMode===Or.Tritanope&&t.setUniformInt("u_type",2)}}get colorBlindnessMode(){return this._colorBlindnessMode}set simulate(t){if(this._simulate=t,this._shader){const e=this._shader.getShader();e.use(),e.setUniformBoolean("u_simulate",t)}}get simulate(){return this._simulate}}class Vr{constructor(t){this._engine=t,this._colorBlindPostProcessor=new Wr(Or.Protanope)}correct(t){this._engine.graphicsContext instanceof ii&&(this.clear(),this._colorBlindPostProcessor.colorBlindnessMode=t,this._colorBlindPostProcessor.simulate=!1,this._engine.graphicsContext.addPostProcessor(this._colorBlindPostProcessor))}simulate(t){this._engine.graphicsContext instanceof ii&&(this.clear(),this._colorBlindPostProcessor.colorBlindnessMode=t,this._colorBlindPostProcessor.simulate=!0,this._engine.graphicsContext.addPostProcessor(this._colorBlindPostProcessor))}clear(){this._engine.graphicsContext.removePostProcessor(this._colorBlindPostProcessor)}}class Gr{constructor(t){this.stats={currFrame:new Xr,prevFrame:new Xr},this.filter={useFilter:!1,nameQuery:"",ids:[]},this.entity={showAll:!1,showId:!0,showName:!1},this.transform={showAll:!1,showPosition:!1,showPositionLabel:!1,positionColor:I.Yellow,showScale:!1,scaleColor:I.Green,showRotation:!1,rotationColor:I.Blue},this.graphics={showAll:!1,showBounds:!0,boundsColor:I.Yellow},this.collider={showAll:!1,showBounds:!0,boundsColor:I.Blue,showOwner:!1,showGeometry:!0,geometryColor:I.Green},this.physics={showAll:!1,showBroadphaseSpacePartitionDebug:!1,showCollisionNormals:!1,collisionNormalColor:I.Cyan,showCollisionContacts:!0,collisionContactColor:I.Red},this.motion={showAll:!1,showVelocity:!1,velocityColor:I.Yellow,showAcceleration:!1,accelerationColor:I.Red},this.body={showAll:!1,showCollisionGroup:!1,showCollisionType:!1,showSleeping:!1,showMotion:!1,showMass:!1},this.camera={showAll:!1,showFocus:!1,focusColor:I.Red,showZoom:!1},this._engine=t,this.colorBlindMode=new Vr(this._engine)}useTestClock(){const t=this._engine.clock,e=t.isRunning();t.stop();const i=t.toTestClock();return e&&i.start(),this._engine.clock=i,i}useStandardClock(){const t=this._engine.clock,e=t.isRunning();t.stop();const i=t.toStandardClock();return e&&i.start(),this._engine.clock=i,i}}class Xr{constructor(){this._id=0,this._delta=0,this._fps=0,this._actorStats={alive:0,killed:0,ui:0,get remaining(){return this.alive-this.killed},get total(){return this.remaining+this.ui}},this._durationStats={update:0,draw:0,get total(){return this.update+this.draw}},this._physicsStats=new qr,this._graphicsStats={drawCalls:0,drawnImages:0}}reset(t){t?(this.id=t.id,this.delta=t.delta,this.fps=t.fps,this.actors.alive=t.actors.alive,this.actors.killed=t.actors.killed,this.actors.ui=t.actors.ui,this.duration.update=t.duration.update,this.duration.draw=t.duration.draw,this._physicsStats.reset(t.physics),this.graphics.drawCalls=t.graphics.drawCalls,this.graphics.drawnImages=t.graphics.drawnImages):(this.id=this.delta=this.fps=0,this.actors.alive=this.actors.killed=this.actors.ui=0,this.duration.update=this.duration.draw=0,this._physicsStats.reset(),this.graphics.drawnImages=this.graphics.drawCalls=0)}clone(){const t=new Xr;return t.reset(this),t}get id(){return this._id}set id(t){this._id=t}get delta(){return this._delta}set delta(t){this._delta=t}get fps(){return this._fps}set fps(t){this._fps=t}get actors(){return this._actorStats}get duration(){return this._durationStats}get physics(){return this._physicsStats}get graphics(){return this._graphicsStats}}class qr{constructor(){this._pairs=0,this._collisions=0,this._contacts=new Map,this._fastBodies=0,this._fastBodyCollisions=0,this._broadphase=0,this._narrowphase=0}reset(t){t?(this.pairs=t.pairs,this.collisions=t.collisions,this.contacts=t.contacts,this.fastBodies=t.fastBodies,this.fastBodyCollisions=t.fastBodyCollisions,this.broadphase=t.broadphase,this.narrowphase=t.narrowphase):(this.pairs=this.collisions=this.fastBodies=0,this.fastBodyCollisions=this.broadphase=this.narrowphase=0,this.contacts.clear())}clone(){const t=new qr;return t.reset(this),t}get pairs(){return this._pairs}set pairs(t){this._pairs=t}get collisions(){return this._collisions}set collisions(t){this._collisions=t}get contacts(){return this._contacts}set contacts(t){this._contacts=t}get fastBodies(){return this._fastBodies}set fastBodies(t){this._fastBodies=t}get fastBodyCollisions(){return this._fastBodyCollisions}set fastBodyCollisions(t){this._fastBodyCollisions=t}get broadphase(){return this._broadphase}set broadphase(t){this._broadphase=t}get narrowphase(){return this._narrowphase}set narrowphase(t){this._narrowphase=t}}var jr,Kr,Yr,Zr,Qr,$r,Jr,tn;!function(t){t.Canvas="Canvas",t.Document="Document"}(jr||(jr={})),function(t){t.Num0="Numpad0",t.Num1="Numpad1",t.Num2="Numpad2",t.Num3="Numpad3",t.Num4="Numpad4",t.Num5="Numpad5",t.Num6="Numpad6",t.Num7="Numpad7",t.Num8="Numpad8",t.Num9="Numpad9",t.NumAdd="NumpadAdd",t.NumSubtract="NumpadSubtract",t.NumMultiply="NumpadMultiply",t.NumDivide="NumpadDivide",t.NumDecimal="NumpadDecimal",t.Numpad0="Numpad0",t.Numpad1="Numpad1",t.Numpad2="Numpad2",t.Numpad3="Numpad3",t.Numpad4="Numpad4",t.Numpad5="Numpad5",t.Numpad6="Numpad6",t.Numpad7="Numpad7",t.Numpad8="Numpad8",t.Numpad9="Numpad9",t.NumpadAdd="NumpadAdd",t.NumpadSubtract="NumpadSubtract",t.NumpadMultiply="NumpadMultiply",t.NumpadDivide="NumpadDivide",t.NumpadDecimal="NumpadDecimal",t.NumLock="NumLock",t.ShiftLeft="ShiftLeft",t.ShiftRight="ShiftRight",t.AltLeft="AltLeft",t.AltRight="AltRight",t.Key0="Digit0",t.Key1="Digit1",t.Key2="Digit2",t.Key3="Digit3",t.Key4="Digit4",t.Key5="Digit5",t.Key6="Digit6",t.Key7="Digit7",t.Key8="Digit8",t.Key9="Digit9",t.Digit0="Digit0",t.Digit1="Digit1",t.Digit2="Digit2",t.Digit3="Digit3",t.Digit4="Digit4",t.Digit5="Digit5",t.Digit6="Digit6",t.Digit7="Digit7",t.Digit8="Digit8",t.Digit9="Digit9",t.A="KeyA",t.B="KeyB",t.C="KeyC",t.D="KeyD",t.E="KeyE",t.F="KeyF",t.G="KeyG",t.H="KeyH",t.I="KeyI",t.J="KeyJ",t.K="KeyK",t.L="KeyL",t.M="KeyM",t.N="KeyN",t.O="KeyO",t.P="KeyP",t.Q="KeyQ",t.R="KeyR",t.S="KeyS",t.T="KeyT",t.U="KeyU",t.V="KeyV",t.W="KeyW",t.X="KeyX",t.Y="KeyY",t.Z="KeyZ",t.KeyA="KeyA",t.KeyB="KeyB",t.KeyC="KeyC",t.KeyD="KeyD",t.KeyE="KeyE",t.KeyF="KeyF",t.KeyG="KeyG",t.KeyH="KeyH",t.KeyI="KeyI",t.KeyJ="KeyJ",t.KeyK="KeyK",t.KeyL="KeyL",t.KeyM="KeyM",t.KeyN="KeyN",t.KeyO="KeyO",t.KeyP="KeyP",t.KeyQ="KeyQ",t.KeyR="KeyR",t.KeyS="KeyS",t.KeyT="KeyT",t.KeyU="KeyU",t.KeyV="KeyV",t.KeyW="KeyW",t.KeyX="KeyX",t.KeyY="KeyY",t.KeyZ="KeyZ",t.Semicolon="Semicolon",t.Quote="Quote",t.Comma="Comma",t.Minus="Minus",t.Period="Period",t.Slash="Slash",t.Equal="Equal",t.BracketLeft="BracketLeft",t.Backslash="Backslash",t.BracketRight="BracketRight",t.Backquote="Backquote",t.Up="ArrowUp",t.Down="ArrowDown",t.Left="ArrowLeft",t.Right="ArrowRight",t.ArrowUp="ArrowUp",t.ArrowDown="ArrowDown",t.ArrowLeft="ArrowLeft",t.ArrowRight="ArrowRight",t.Space="Space",t.Esc="Escape",t.Escape="Escape"}(Kr||(Kr={}));class en extends At{constructor(t,e,i){super(),this.key=t,this.value=e,this.originalEvent=i}}class sn extends hi{constructor(){super(),this._keys=[],this._keysUp=[],this._keysDown=[]}on(t,e){super.on(t,e)}init(t){if(!t)try{const e=()=>{};window.top.addEventListener("blur",e),window.top.removeEventListener("blur",e),t=window.top}catch(e){t=window,f.getInstance().warn("Failed to bind to keyboard events to top frame. If you are trying to embed Excalibur in a cross-origin iframe, keyboard events will not fire.")}t.addEventListener("blur",(()=>{this._keys.length=0})),t.addEventListener("keyup",(t=>{const e=t.code,i=this._keys.indexOf(e);this._keys.splice(i,1),this._keysUp.push(e);const s=new en(e,t.key,t);this.eventDispatcher.emit("up",s),this.eventDispatcher.emit("release",s)})),t.addEventListener("keydown",(t=>{const e=t.code;if(-1===this._keys.indexOf(e)){this._keys.push(e),this._keysDown.push(e);const i=new en(e,t.key,t);this.eventDispatcher.emit("down",i),this.eventDispatcher.emit("press",i)}}))}update(){this._keysDown.length=0,this._keysUp.length=0;for(let t=0;t<this._keys.length;t++)this.eventDispatcher.emit("hold",new en(this._keys[t]))}getKeys(){return this._keys}wasPressed(t){return this._keysDown.indexOf(t)>-1}isHeld(t){return this._keys.indexOf(t)>-1}wasReleased(t){return this._keysUp.indexOf(t)>-1}}class rn extends hi{constructor(){super(),this.enabled=!1,this.supported=!!navigator.getGamepads,this._gamePadTimeStamps=[0,0,0,0],this._oldPads=[],this._pads=[],this._initSuccess=!1,this._navigator=navigator,this._minimumConfiguration=null}init(){this.supported&&(this._initSuccess||(this._oldPads=this._clonePads(this._navigator.getGamepads()),this._oldPads.length&&this._oldPads[0]&&(this._initSuccess=!0)))}setMinimumGamepadConfiguration(t){this._enableAndUpdate(),this._minimumConfiguration=t}_enableAndUpdate(){this.enabled||(this.enabled=!0,this.update())}_isGamepadValid(t){if(!this._minimumConfiguration)return!0;if(!t)return!1;const e=t.axes.filter((t=>void 0!==typeof t)).length,i=t.buttons.filter((t=>void 0!==typeof t)).length;return e>=this._minimumConfiguration.axis&&i>=this._minimumConfiguration.buttons&&t.connected}on(t,e){this._enableAndUpdate(),super.on(t,e)}off(t,e){this._enableAndUpdate(),super.off(t,e)}update(){if(!this.enabled||!this.supported)return;this.init();const t=this._navigator.getGamepads();for(let e=0;e<t.length;e++){if(!t[e]){const t=this.at(e);t.connected&&this.eventDispatcher.emit("disconnect",new Nt(e,t)),t.connected=!1;continue}if(!this.at(e).connected&&this._isGamepadValid(t[e])&&this.eventDispatcher.emit("connect",new Ut(e,this.at(e))),this.at(e).connected=!0,t[e].timestamp&&t[e].timestamp===this._gamePadTimeStamps[e])continue;let i,s,r,n,o;for(i in this._gamePadTimeStamps[e]=t[e].timestamp,this.at(e).navigatorGamepad=t[e],Yr)s=Yr[i],"number"==typeof s&&t[e].buttons[s]&&(o=t[e].buttons[s].value,o!==this._oldPads[e].getButton(s)&&(t[e].buttons[s].pressed?(this.at(e).updateButton(s,o),this.at(e).eventDispatcher.emit("button",new Ht(s,o,this.at(e)))):this.at(e).updateButton(s,0)));for(r in Zr)n=Zr[r],"number"==typeof n&&(o=t[e].axes[n],o!==this._oldPads[e].getAxes(n)&&(this.at(e).updateAxes(n,o),this.at(e).eventDispatcher.emit("axis",new Wt(n,o,this.at(e)))));this._oldPads[e]=this._clonePad(t[e])}}at(t){if(this._enableAndUpdate(),t>=this._pads.length)for(let e=this._pads.length-1,i=t;e<i;e++)this._pads.push(new nn),this._oldPads.push(new nn);return this._pads[t]}getValidGamepads(){this._enableAndUpdate();const t=[];for(let e=0;e<this._pads.length;e++)this._isGamepadValid(this.at(e).navigatorGamepad)&&this.at(e).connected&&t.push(this.at(e));return t}count(){return this._pads.filter((t=>t.connected)).length}_clonePads(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(this._clonePad(t[i]));return e}_clonePad(t){let e,i;const s=new nn;if(!t)return s;for(e=0,i=t.buttons.length;e<i;e++)t.buttons[e]&&s.updateButton(e,t.buttons[e].value);for(e=0,i=t.axes.length;e<i;e++)s.updateAxes(e,t.axes[e]);return s}}rn.MinAxisMoveThreshold=.05;class nn extends hi{constructor(){super(),this.connected=!1,this._buttons=new Array(16),this._axes=new Array(4);for(let t=0;t<this._buttons.length;t++)this._buttons[t]=0;for(let t=0;t<this._axes.length;t++)this._axes[t]=0}isButtonPressed(t,e=1){return this._buttons[t]>=e}getButton(t){return this._buttons[t]}getAxes(t){const e=this._axes[t];return Math.abs(e)<rn.MinAxisMoveThreshold?0:e}updateButton(t,e){this._buttons[t]=e}updateAxes(t,e){this._axes[t]=e}}!function(t){t[t.Face1=0]="Face1",t[t.Face2=1]="Face2",t[t.Face3=2]="Face3",t[t.Face4=3]="Face4",t[t.LeftBumper=4]="LeftBumper",t[t.RightBumper=5]="RightBumper",t[t.LeftTrigger=6]="LeftTrigger",t[t.RightTrigger=7]="RightTrigger",t[t.Select=8]="Select",t[t.Start=9]="Start",t[t.LeftStick=10]="LeftStick",t[t.RightStick=11]="RightStick",t[t.DpadUp=12]="DpadUp",t[t.DpadDown=13]="DpadDown",t[t.DpadLeft=14]="DpadLeft",t[t.DpadRight=15]="DpadRight"}(Yr||(Yr={})),function(t){t[t.LeftStickX=0]="LeftStickX",t[t.LeftStickY=1]="LeftStickY",t[t.RightStickX=2]="RightStickX",t[t.RightStickY=3]="RightStickY"}(Zr||(Zr={}));class on{constructor(t){this.nativeComponent=t,this._paused=!1,this._nativeHandlers={}}on(t,e){this._nativeHandlers[t]&&this.off(t,this._nativeHandlers[t]),this._nativeHandlers[t]=this._decorate(e),this.nativeComponent.addEventListener(t,this._nativeHandlers[t])}off(t,e){e||(e=this._nativeHandlers[t]),this.nativeComponent.removeEventListener(t,e),this._nativeHandlers[t]=null}_decorate(t){return e=>{this._paused||t(e)}}pause(){this._paused=!0}resume(){this._paused=!1}clear(){for(const t in this._nativeHandlers)this.off(t)}}class an{constructor(t,e){this._windowGlobal=t,this._documentGlobal=e,this._windowComponent=new on(this._windowGlobal),this._documentComponent=new on(this._documentGlobal)}get window(){return this._windowComponent}get document(){return this._documentComponent}pause(){this.window.pause(),this.document.pause()}resume(){this.window.resume(),this.document.resume()}clear(){this.window.clear(),this.document.clear()}}class hn{constructor(t){this._ex=t,this._debugText=new Ne}drawRect(t,e,i,s){this._ex.__ctx.save(),this._ex.__ctx.strokeStyle="red",this._ex.__ctx.strokeRect(this._ex.snapToPixel?~~t:t,this._ex.snapToPixel?~~e:e,this._ex.snapToPixel?~~i:i,this._ex.snapToPixel?~~s:s),this._ex.__ctx.restore()}drawLine(t,e,i={color:I.Black}){this._ex.__ctx.save(),this._ex.__ctx.beginPath(),this._ex.__ctx.strokeStyle=i.color.toString(),this._ex.__ctx.moveTo(this._ex.snapToPixel?~~t.x:t.x,this._ex.snapToPixel?~~t.y:t.y),this._ex.__ctx.lineTo(this._ex.snapToPixel?~~e.x:e.x,this._ex.snapToPixel?~~e.y:e.y),this._ex.__ctx.lineWidth=2,this._ex.__ctx.stroke(),this._ex.__ctx.closePath(),this._ex.__ctx.restore()}drawPoint(t,e={color:I.Black,size:5}){this._ex.__ctx.save(),this._ex.__ctx.beginPath(),this._ex.__ctx.fillStyle=e.color.toString(),this._ex.__ctx.arc(this._ex.snapToPixel?~~t.x:t.x,this._ex.snapToPixel?~~t.y:t.y,e.size,0,2*Math.PI),this._ex.__ctx.fill(),this._ex.__ctx.closePath(),this._ex.__ctx.restore()}drawText(t,e){this._debugText.write(this._ex,t,e)}}class ln{constructor(t){this.backgroundColor=I.ExcaliburBlue,this._state=new ut,this.snapToPixel=!0,this.debug=new hn(this);const{canvasElement:e,enableTransparency:i,snapToPixel:s,smoothing:r,backgroundColor:n}=t;this.__ctx=e.getContext("2d",{alpha:null==i||i}),this.backgroundColor=null!=n?n:this.backgroundColor,this.snapToPixel=null!=s?s:this.snapToPixel,this.smoothing=null!=r?r:this.smoothing}get width(){return this.__ctx.canvas.width}get height(){return this.__ctx.canvas.height}get opacity(){return this._state.current.opacity}set opacity(t){this._state.current.opacity=t}get smoothing(){return this.__ctx.imageSmoothingEnabled}set smoothing(t){this.__ctx.imageSmoothingEnabled=t}resetTransform(){this.__ctx.resetTransform()}updateViewport(t){}drawImage(t,e,i,s,r,n,o,a,h){if(0===s||0===r)return;if(0===a||0===h)return;if(0===t.width||0===t.height)return;this.__ctx.globalAlpha=this.opacity;const l=[t,e,i,s,r,n,o,a,h].filter((t=>void 0!==t)).map((t=>"number"==typeof t&&this.snapToPixel?~~t:t));this.__ctx.drawImage.apply(this.__ctx,l),je.DrawCallCount++,je.DrawnImagesCount=1}drawLine(t,e,i,s=1){this.__ctx.save(),this.__ctx.beginPath(),this.__ctx.strokeStyle=i.toString(),this.__ctx.moveTo(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y),this.__ctx.lineTo(this.snapToPixel?~~e.x:e.x,this.snapToPixel?~~e.y:e.y),this.__ctx.lineWidth=s,this.__ctx.stroke(),this.__ctx.closePath(),this.__ctx.restore()}drawRectangle(t,e,i,s){this.__ctx.save(),this.__ctx.fillStyle=s.toString(),this.__ctx.fillRect(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y,this.snapToPixel?~~e:e,this.snapToPixel?~~i:i),this.__ctx.restore()}drawCircle(t,e,i,s,r){this.__ctx.save(),this.__ctx.beginPath(),s&&(this.__ctx.strokeStyle=s.toString()),r&&(this.__ctx.lineWidth=r),this.__ctx.fillStyle=i.toString(),this.__ctx.arc(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y,e,0,2*Math.PI),this.__ctx.fill(),s&&this.__ctx.stroke(),this.__ctx.closePath(),this.__ctx.restore()}save(){this.__ctx.save()}restore(){this.__ctx.restore()}translate(t,e){this.__ctx.translate(this.snapToPixel?~~t:t,this.snapToPixel?~~e:e)}rotate(t){this.__ctx.rotate(t)}scale(t,e){this.__ctx.scale(t,e)}getTransform(){throw new Error("Not implemented")}multiply(t){this.__ctx.setTransform(this.__ctx.getTransform().multiply(t.toDOMMatrix()))}addPostProcessor(t){throw Error("Not implemented")}removePostProcessor(t){throw Error("Not implemented")}clearPostProcessors(){throw Error("Not implemented")}beginDrawLifecycle(){}endDrawLifecycle(){}clear(){this.__ctx.clearRect(0,0,this.width,this.height),this.__ctx.fillStyle=this.backgroundColor.toString(),this.__ctx.fillRect(0,0,this.width,this.height),je.clear()}flush(){}}class cn{constructor(t,e,i){this.worldPos=t,this.pagePos=e,this.screenPos=i}static fromPagePosition(t,e,i){let s,r,n,o;3===arguments.length?(s=t,r=e,n=new A(s,r),o=i):(n=t,s=n.x,r=n.y,o=e);const a=o.screen.pageToScreenCoordinates(n),h=o.screen.screenToWorldCoordinates(a);return new cn(h,n,a)}}class dn{constructor(t,e,i,s,r,n){this.type=t,this.pointerId=e,this.button=i,this.pointerType=s,this.coordinates=r,this.nativeEvent=n,this.active=!0}cancel(){this.active=!1}get pagePos(){return this.coordinates.pagePos}get screenPos(){return this.coordinates.screenPos}get worldPos(){return this.coordinates.worldPos}}class un{constructor(t,e,i,s,r,n,o,a,h,l,c,d){this.x=t,this.y=e,this.pageX=i,this.pageY=s,this.screenX=r,this.screenY=n,this.index=o,this.deltaX=a,this.deltaY=h,this.deltaZ=l,this.deltaMode=c,this.ev=d,this.active=!0}cancel(){this.active=!1}}class pn extends hi{constructor(){super(),this.lastPagePos=A.Zero,this.lastScreenPos=A.Zero,this.lastWorldPos=A.Zero,this._onPointerMove=t=>{this.lastPagePos=new A(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new A(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new A(t.worldPos.x,t.worldPos.y)},this._onPointerDown=t=>{this.lastPagePos=new A(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new A(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new A(t.worldPos.x,t.worldPos.y)},this.on("move",this._onPointerMove),this.on("down",this._onPointerDown)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}}!function(t){t.Pixel="Pixel",t.Line="Line",t.Page="Page"}(Qr||(Qr={})),function(t){t[t.NoButton=-1]="NoButton",t[t.Left=0]="Left",t[t.Middle=1]="Middle",t[t.Right=2]="Right",t[t.Unknown=3]="Unknown"}($r||($r={})),function(t){t.Left="Left",t.Middle="Middle",t.Right="Right",t.Unknown="Unknown",t.NoButton="NoButton"}(Jr||(Jr={})),function(t){t.Touch="Touch",t.Mouse="Mouse",t.Pen="Pen",t.Unknown="Unknown"}(tn||(tn={}));class gn extends hi{constructor(t,e){super(),this.target=t,this.engine=e,this.primary=new pn,this._activeNativePointerIdsToNormalized=new Map,this.lastFramePointerCoords=new Map,this.currentFramePointerCoords=new Map,this.currentFramePointerDown=new Map,this.lastFramePointerDown=new Map,this.currentFrameDown=[],this.currentFrameUp=[],this.currentFrameMove=[],this.currentFrameCancel=[],this.currentFrameWheel=[],this._pointers=[this.primary],this._boundHandle=this._handle.bind(this),this._boundWheel=this._handleWheel.bind(this)}at(t){if(t>=this._pointers.length)for(let e=this._pointers.length-1,i=t;e<i;e++)this._pointers.push(new pn);return this._pointers[t]}count(){return this._pointers.length}isDown(t){var e;return null!==(e=this.currentFramePointerDown.get(t))&&void 0!==e&&e}wasDown(t){var e;return null!==(e=this.lastFramePointerDown.get(t))&&void 0!==e&&e}isDragging(t){return this.isDown(t)}isDragStart(t){return this.isDown(t)&&!this.wasDown(t)}isDragEnd(t){return!this.isDown(t)&&this.wasDown(t)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}update(){this.lastFramePointerDown=new Map(this.currentFramePointerDown),this.lastFramePointerCoords=new Map(this.currentFramePointerCoords);for(const t of this.currentFrameDown){this.emit("down",t);this.at(t.pointerId).emit("down",t),this.primary.emit("pointerdown",t)}for(const t of this.currentFrameUp){this.emit("up",t);this.at(t.pointerId).emit("up",t)}for(const t of this.currentFrameMove){this.emit("move",t);this.at(t.pointerId).emit("move",t)}for(const t of this.currentFrameCancel){this.emit("cancel",t);this.at(t.pointerId).emit("cancel",t)}for(const t of this.currentFrameWheel)this.emit("wheel",t),this.primary.emit("pointerwheel",t)}clear(){for(const t of this.currentFrameUp){this.currentFramePointerCoords.delete(t.pointerId);const e=this._activeNativePointerIdsToNormalized.entries();for(const[i,s]of e)s===t.pointerId&&this._activeNativePointerIdsToNormalized.delete(i)}this.currentFrameDown.length=0,this.currentFrameUp.length=0,this.currentFrameMove.length=0,this.currentFrameCancel.length=0,this.currentFrameWheel.length=0}init(){this.engine.canvas.style.touchAction="none",window.PointerEvent?(this.target.addEventListener("pointerdown",this._boundHandle),this.target.addEventListener("pointerup",this._boundHandle),this.target.addEventListener("pointermove",this._boundHandle),this.target.addEventListener("pointercancel",this._boundHandle)):(this.target.addEventListener("touchstart",this._boundHandle),this.target.addEventListener("touchend",this._boundHandle),this.target.addEventListener("touchmove",this._boundHandle),this.target.addEventListener("touchcancel",this._boundHandle),this.target.addEventListener("mousedown",this._boundHandle),this.target.addEventListener("mouseup",this._boundHandle),this.target.addEventListener("mousemove",this._boundHandle));const t={passive:!(this.engine.pageScrollPreventionMode===yn.All||this.engine.pageScrollPreventionMode===yn.Canvas)};"onwheel"in document.createElement("div")?this.target.addEventListener("wheel",this._boundWheel,t):void 0!==document.onmousewheel?this.target.addEventListener("mousewheel",this._boundWheel,t):this.target.addEventListener("MozMousePixelScroll",this._boundWheel,t)}detach(){window.PointerEvent?(this.target.removeEventListener("pointerdown",this._boundHandle),this.target.removeEventListener("pointerup",this._boundHandle),this.target.removeEventListener("pointermove",this._boundHandle),this.target.removeEventListener("pointercancel",this._boundHandle)):(this.target.removeEventListener("touchstart",this._boundHandle),this.target.removeEventListener("touchend",this._boundHandle),this.target.removeEventListener("touchmove",this._boundHandle),this.target.removeEventListener("touchcancel",this._boundHandle),this.target.removeEventListener("mousedown",this._boundHandle),this.target.removeEventListener("mouseup",this._boundHandle),this.target.removeEventListener("mousemove",this._boundHandle)),"onwheel"in document.createElement("div")?this.target.removeEventListener("wheel",this._boundWheel):void 0!==document.onmousewheel?this.target.addEventListener("mousewheel",this._boundWheel):this.target.addEventListener("MozMousePixelScroll",this._boundWheel)}_normalizePointerId(t){this._activeNativePointerIdsToNormalized.set(t,-1);const e=Array.from(this._activeNativePointerIdsToNormalized.keys()).sort(((t,e)=>t-e)).findIndex((e=>e===t));return this._activeNativePointerIdsToNormalized.set(t,e),e}_handle(t){t.preventDefault();const e=new Map;let i,s;if(r=t,globalThis.TouchEvent&&r instanceof globalThis.TouchEvent){i=Jr.Unknown,s=tn.Touch;for(let i=0;i<t.changedTouches.length;i++){const s=t.changedTouches[i],r=cn.fromPagePosition(s.pageX,s.pageY,this.engine),n=i+1,o=this._normalizePointerId(n);this.currentFramePointerCoords.set(o,r),e.set(o,r)}}else{i=this._nativeButtonToPointerButton(t.button),s=tn.Mouse;const r=cn.fromPagePosition(t.pageX,t.pageY,this.engine);let n=1;(function(t){return globalThis.PointerEvent&&t instanceof globalThis.PointerEvent})(t)&&(n=t.pointerId,s=this._stringToPointerType(t.pointerType));const o=this._normalizePointerId(n);this.currentFramePointerCoords.set(o,r),e.set(o,r)}var r;for(const[r,n]of e.entries())switch(t.type){case"mousedown":case"pointerdown":case"touchstart":this.currentFrameDown.push(new dn("down",r,i,s,n,t)),this.currentFramePointerDown.set(r,!0);break;case"mouseup":case"pointerup":case"touchend":this.currentFrameUp.push(new dn("up",r,i,s,n,t)),this.currentFramePointerDown.set(r,!1);break;case"mousemove":case"pointermove":case"touchmove":this.currentFrameMove.push(new dn("move",r,i,s,n,t));break;case"touchcancel":case"pointercancel":this.currentFrameCancel.push(new dn("cancel",r,i,s,n,t))}}_handleWheel(t){(this.engine.pageScrollPreventionMode===yn.All||this.engine.pageScrollPreventionMode===yn.Canvas&&t.target===this.engine.canvas)&&t.preventDefault();const e=this.engine.screen.pageToScreenCoordinates(P(t.pageX,t.pageY)),i=this.engine.screen.screenToWorldCoordinates(e),s=-1/40,r=t.deltaX||t.wheelDeltaX*s||0,n=t.deltaY||t.wheelDeltaY*s||t.wheelDelta*s||t.detail||0,o=t.deltaZ||0;let a=Qr.Pixel;t.deltaMode&&(1===t.deltaMode?a=Qr.Line:2===t.deltaMode&&(a=Qr.Page));const h=new un(i.x,i.y,t.pageX,t.pageY,e.x,e.y,0,r,n,o,a,t);this.currentFrameWheel.push(h)}triggerEvent(t,e){const i=this.engine.screen.worldToPageCoordinates(e);window.PointerEvent?this._handle(new window.PointerEvent("pointer"+t,{pointerId:0,clientX:i.x,clientY:i.y})):this._handle(new window.MouseEvent("mouse"+t,{clientX:i.x,clientY:i.y}));const s=this.engine.currentScene.world.systemManager.get(Lr),r=this.engine.currentScene.world.queryManager.createQuery(s.types);s.update(r.getEntities())}_nativeButtonToPointerButton(t){switch(t){case $r.NoButton:return Jr.NoButton;case $r.Left:return Jr.Left;case $r.Middle:return Jr.Middle;case $r.Right:return Jr.Right;case $r.Unknown:return Jr.Unknown;default:return nt(t)}}_stringToPointerType(t){switch(t){case"touch":return tn.Touch;case"mouse":return tn.Mouse;case"pen":return tn.Pen;default:return tn.Unknown}}}class _n{constructor(t){var e;this._samplePeriod=100,this._currentFrameTime=0,this._frames=0,this._previousSampleTime=0,this._beginFrameTime=0,this._fps=t.initialFps,this._samplePeriod=null!==(e=t.samplePeriod)&&void 0!==e?e:this._samplePeriod,this._currentFrameTime=1e3/t.initialFps,this._nowFn=t.nowFn,this._previousSampleTime=this._nowFn()}start(){this._beginFrameTime=this._nowFn()}end(){this._frames++;const t=this._nowFn();this._currentFrameTime=t-this._beginFrameTime,t>=this._previousSampleTime+this._samplePeriod&&(this._fps=1e3*this._frames/(t-this._previousSampleTime),this._previousSampleTime=t,this._frames=0)}get fps(){return this._fps}get instant(){return 1e3/this._currentFrameTime}}class fn{constructor(t){var e,i,s;this._onFatalException=()=>{},this._maxFps=1/0,this._lastTime=0,this._elapsed=1,this._scheduledCbs=[],this._totalElapsed=0,this._options=t,this.tick=t.tick,this._lastTime=null!==(e=this.now())&&void 0!==e?e:0,this._maxFps=null!==(i=t.maxFps)&&void 0!==i?i:this._maxFps,this._onFatalException=null!==(s=t.onFatalException)&&void 0!==s?s:this._onFatalException,this.fpsSampler=new _n({initialFps:60,nowFn:()=>this.now()})}elapsed(){return this._elapsed}now(){return performance.now()}toTestClock(){return new vn({...this._options,defaultUpdateMs:16.6})}toStandardClock(){return new mn({...this._options})}setFatalExceptionHandler(t){this._onFatalException=t}schedule(t,e=0){const i=this.now()+e;this._scheduledCbs.push([t,i])}_runScheduledCbs(){for(let t=this._scheduledCbs.length-1;t>-1;t--)this._scheduledCbs[t][1]<=this._totalElapsed&&(this._scheduledCbs[t][0](),this._scheduledCbs.splice(t,1))}update(t){try{this.fpsSampler.start();const e=this.now();let i=e-this._lastTime||1;const s=1e3/this._maxFps;if(i>=s){let r=0;0!==s&&(r=i%s,i-=r),i>200&&(i=1),this._elapsed=t||i,this._totalElapsed+=this._elapsed,this._runScheduledCbs(),this.tick(t||i),this._lastTime=0!==s?e-r:e,this.fpsSampler.end()}}catch(t){this._onFatalException(t),this.stop()}}}class mn extends fn{constructor(t){super(t),this._running=!1}isRunning(){return this._running}start(){if(this._running)return;this._running=!0;const t=()=>{if(this._running)try{this._requestId=window.requestAnimationFrame(t),this.update()}catch(t){throw window.cancelAnimationFrame(this._requestId),t}};t()}stop(){this._running=!1}}class vn extends fn{constructor(t){super({...t}),this._logger=f.getInstance(),this._running=!1,this._currentTime=0,this._updateMs=t.defaultUpdateMs}now(){var t;return null!==(t=this._currentTime)&&void 0!==t?t:0}isRunning(){return this._running}start(){this._running=!0}stop(){this._running=!1}step(t){const e=null!=t?t:this._updateMs;this._running?(this.update(e),this._currentTime+=e):this._logger.warn("The clock is not running, no step will be performed")}run(t,e){for(let i=0;i<t;i++)this.step(null!=e?e:this._updateMs)}}var yn,wn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};p(),function(t){t[t.None=0]="None",t[t.Canvas=1]="Canvas",t[t.All=2]="All"}(yn||(yn={}));class xn extends hi{constructor(t){var e,i,s,r;super(),this.maxFps=Number.POSITIVE_INFINITY,this._hasStarted=!1,this.scenes={},this._animations=[],this._suppressPlayButton=!1,this.pauseAudioWhenHidden=!0,this._isDebug=!1,this.debugColor=new I(255,255,255),this.enableCanvasTransparency=!0,this.onFatalException=t=>{f.getInstance().fatal(t)},this._timescale=1,this._isInitialized=!1,this._deferredGoTo=null,this._loadingComplete=!1,this._isReady=!1,this._isReadyPromise=new Promise((t=>{this._isReadyResolve=t})),t={...xn._DEFAULT_ENGINE_OPTIONS,...t},g.freeze(),this.browser=new an(window,document);const n=new mi;if(!t.suppressMinimumBrowserFeatureDetection&&!(this._compatible=n.test())){const e=document.createElement("div");if(e.innerText="Sorry, your browser does not support all the features needed for Excalibur",document.body.appendChild(e),n.failedTests.forEach((function(t){const e=document.createElement("div");e.innerText="Browser feature missing "+t,document.body.appendChild(e)})),t.canvasElementId){const e=document.getElementById(t.canvasElementId);e&&e.parentElement.removeChild(e)}return}this._compatible=!0,console.log&&!t.suppressConsoleBootMessage&&(console.log(`%cPowered by Excalibur.js (v${ro})`,"background: #176BAA; color: white; border-radius: 5px; padding: 15px; font-size: 1.5em; line-height: 80px;"),console.log("\n /| ________________\nO|===|* >________________>\n \\|"),console.log("Visit","http://excaliburjs.com","for more information")),t.suppressPlayButton&&(this._suppressPlayButton=!0),this._logger=f.getInstance(),this._logger.defaultLevel===u.Debug&&n.logBrowserFeatures(),this._logger.debug("Building engine..."),this.canvasElementId=t.canvasElementId,t.canvasElementId?(this._logger.debug("Using Canvas element specified: "+t.canvasElementId),this.canvas=document.getElementById(t.canvasElementId)):t.canvasElement?(this._logger.debug("Using Canvas element specified:",t.canvasElement),this.canvas=t.canvasElement):(this._logger.debug("Using generated canvas element"),this.canvas=document.createElement("canvas"));let o=null!==(e=t.displayMode)&&void 0!==e?e:si.Fixed;if(t.width&&t.height||t.viewport?(void 0===t.displayMode&&(o=si.Fixed),this._logger.debug("Engine viewport is size "+t.width+" x "+t.height)):t.displayMode||(this._logger.debug("Engine viewport is fit"),o=si.FitScreen),g.isEnabled(d.Canvas)){const e=new ln({canvasElement:this.canvas,enableTransparency:this.enableCanvasTransparency,smoothing:t.antialiasing,backgroundColor:t.backgroundColor,snapToPixel:t.snapToPixel});this.graphicsContext=e,this.ctx=e.__ctx}else{const e=new ii({canvasElement:this.canvas,enableTransparency:this.enableCanvasTransparency,smoothing:t.antialiasing,backgroundColor:t.backgroundColor,snapToPixel:t.snapToPixel});this.graphicsContext=e,this.ctx=e.__ctx}this.screen=new ni({canvas:this.canvas,context:this.graphicsContext,antialiasing:null===(i=t.antialiasing)||void 0===i||i,browser:this.browser,viewport:null!==(s=t.viewport)&&void 0!==s?s:t.width&&t.height?{width:t.width,height:t.height}:ri.SVGA,resolution:t.resolution,displayMode:o,position:t.position,pixelRatio:t.suppressHiDPIScaling?1:null}),bt.filtering=t.antialiasing?ht.Blended:ht.Pixel,t.backgroundColor&&(this.backgroundColor=t.backgroundColor.clone()),this.maxFps=null!==(r=t.maxFps)&&void 0!==r?r:this.maxFps,this.clock=new mn({maxFps:this.maxFps,tick:this._mainloop.bind(this),onFatalException:t=>this.onFatalException(t)}),this.enableCanvasTransparency=t.enableCanvasTransparency,this._loader=new _i,this._loader.wireEngine(this),this.debug=new Gr(this),this._initialize(t),this.rootScene=this.currentScene=new Nr,this.addScene("root",this.rootScene),window.___EXCALIBUR_DEVTOOL=this}get canvasWidth(){return this.screen.canvasWidth}get halfCanvasWidth(){return this.screen.halfCanvasWidth}get canvasHeight(){return this.screen.canvasHeight}get halfCanvasHeight(){return this.screen.halfCanvasHeight}get drawWidth(){return this.screen.drawWidth}get halfDrawWidth(){return this.screen.halfDrawWidth}get drawHeight(){return this.screen.drawHeight}get halfDrawHeight(){return this.screen.halfDrawHeight}get isHiDpi(){return this.screen.isHiDpi}get stats(){return this.debug.stats}get isFullscreen(){return this.screen.isFullScreen}get displayMode(){return this.screen.displayMode}get pixelRatio(){return this.screen.pixelRatio}get isDebug(){return this._isDebug}get snapToPixel(){return this.graphicsContext.snapToPixel}set snapToPixel(t){this.graphicsContext.snapToPixel=t}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}getWorldBounds(){return this.screen.getWorldBounds()}get timescale(){return this._timescale}set timescale(t){t<=0?f.getInstance().error("Cannot set engine.timescale to a value of 0 or less than 0."):this._timescale=t}playAnimation(t,e,i){this._animations.push(new bn(t,e,i))}addTileMap(t){this.currentScene.addTileMap(t)}removeTileMap(t){this.currentScene.removeTileMap(t)}addTimer(t){return this.currentScene.addTimer(t)}removeTimer(t){return this.currentScene.removeTimer(t)}addScene(t,e){this.scenes[t]&&this._logger.warn("Scene",t,"already exists overwriting"),this.scenes[t]=e}removeScene(t){if(t instanceof Nr)for(const e in this.scenes)this.scenes.hasOwnProperty(e)&&this.scenes[e]===t&&delete this.scenes[e];"string"==typeof t&&delete this.scenes[t]}add(t){2!==arguments.length?this._deferredGoTo&&this.scenes[this._deferredGoTo]?this.scenes[this._deferredGoTo].add(t):this.currentScene.add(t):this.addScene(arguments[0],arguments[1])}remove(t){t instanceof ns&&this.currentScene.remove(t),t instanceof Nr&&this.removeScene(t),"string"==typeof t&&this.removeScene(t)}goToScene(t){if(this.isInitialized)if(this.scenes[t]){const e=this.currentScene,i=this.scenes[t];this._logger.debug("Going to scene:",t),this.currentScene.isInitialized&&(this.currentScene._deactivate.apply(this.currentScene,[e,i]),this.currentScene.eventDispatcher.emit("deactivate",new se(i,this.currentScene))),this.currentScene=i,this.screen.setCurrentCamera(i.camera),this.currentScene._initialize(this),this.currentScene._activate.apply(this.currentScene,[e,i]),this.currentScene.eventDispatcher.emit("activate",new ie(e,this.currentScene))}else this._logger.error("Scene",t,"does not exist!");else this._deferredGoTo=t}screenToWorldCoordinates(t){return this.screen.screenToWorldCoordinates(t)}worldToScreenCoordinates(t){return this.screen.worldToScreenCoordinates(t)}_initialize(t){this.pageScrollPreventionMode=t.scrollPreventionMode;const e=t&&t.pointerScope===jr.Document?document:this.canvas;let i,s;this.input={keyboard:new sn,pointers:new gn(e,this),gamepads:new rn},this.input.keyboard.init(),this.input.pointers.init(),this.input.gamepads.init(),void 0!==document.hidden?(i="hidden",s="visibilitychange"):"msHidden"in document?(i="msHidden",s="msvisibilitychange"):"webkitHidden"in document&&(i="webkitHidden",s="webkitvisibilitychange"),this.browser.document.on(s,(()=>{document[i]?(this.eventDispatcher.emit("hidden",new qt(this)),this._logger.debug("Window hidden")):(this.eventDispatcher.emit("visible",new Xt(this)),this._logger.debug("Window visible"))})),this.canvasElementId||t.canvasElement||document.body.appendChild(this.canvas)}onInitialize(t){}setAntialiasing(t){this.screen.antialiasing=t}getAntialiasing(){return this.screen.antialiasing}get isInitialized(){return this._isInitialized}_overrideInitialize(t){this.isInitialized||(this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0,this._deferredGoTo?this.goToScene(this._deferredGoTo):this.goToScene("root"))}_update(t){if(!this.ready)return this._loader.update(this,t),this.input.keyboard.update(),void this.input.gamepads.update();this._preupdate(t),this.currentScene.update(this,t),this._animations=this._animations.filter((function(t){return!t.animation.isDone()})),this.input.keyboard.update(),this.input.gamepads.update(),this._postupdate(t)}_preupdate(t){this.emit("preupdate",new Ft(this,t,this)),this.onPreUpdate(this,t)}onPreUpdate(t,e){}_postupdate(t){this.emit("postupdate",new Lt(this,t,this)),this.onPostUpdate(this,t)}onPostUpdate(t,e){}_draw(t){const e=this.ctx;if(this.graphicsContext.beginDrawLifecycle(),this.graphicsContext.clear(),this._predraw(e,t),!this._isReady)return this._loader.canvas.draw(this.graphicsContext,0,0),void this.graphicsContext.flush();this.graphicsContext.backgroundColor=this.backgroundColor,this.currentScene.draw(this.ctx,t);let i=0;const s=this._animations.length;for(;i<s;i++)this._animations[i].animation.draw(e,this._animations[i].x,this._animations[i].y);if(this.isDebug){this.ctx.font="Consolas",this.ctx.fillStyle=this.debugColor.toString();const t=this.input.keyboard.getKeys();for(let e=0;e<t.length;e++)this.ctx.fillText(t[e].toString()+" : "+(Kr[t[e]]?Kr[t[e]]:"Not Mapped"),100,10*e+10);this.ctx.fillText("FPS:"+this.stats.currFrame.fps.toFixed(2).toString(),10,10)}this._postdraw(e,t),this.graphicsContext.flush(),this.graphicsContext.endDrawLifecycle()}_predraw(t,e){this.emit("predraw",new Bt(t,e,this)),this.onPreDraw(t,e)}onPreDraw(t,e){}_postdraw(t,e){this.emit("postdraw",new Dt(t,e,this)),this.onPostDraw(t,e)}onPostDraw(t,e){}showDebug(t){this._isDebug=t}toggleDebug(){return this._isDebug=!this._isDebug,this._isDebug}get loadingComplete(){return this._loadingComplete}get ready(){return this._isReady}isReady(){return this._isReadyPromise}async start(t){if(!this._compatible)throw new Error("Excalibur is incompatible with your browser");return t&&(this.screen.pushResolutionAndViewport(),this.screen.resolution=this.screen.viewport,this.screen.applyResolutionAndViewport(),this._loader=t,this._loader.suppressPlayButton=this._suppressPlayButton||this._loader.suppressPlayButton,this._loader.wireEngine(this)),this._logger.debug("Starting game clock..."),this.browser.resume(),this.clock.start(),this._logger.debug("Game clock started"),t&&(await this.load(this._loader),this._loadingComplete=!0,this.screen.popResolutionAndViewport(),this.screen.applyResolutionAndViewport()),this._loadingComplete=!0,this._overrideInitialize(this),this._isReady=!0,this._isReadyResolve(),this.emit("start",new It(this)),this._isReadyPromise}_mainloop(t){this.emit("preframe",new zt(this,this.stats.prevFrame));const e=t*this.timescale,i=this.stats.prevFrame.id+1;this.stats.currFrame.reset(),this.stats.currFrame.id=i,this.stats.currFrame.delta=e,this.stats.currFrame.fps=this.clock.fpsSampler.fps,je.clear();const s=this.clock.now();this._update(e);const r=this.clock.now();this._draw(e);const n=this.clock.now();this.stats.currFrame.duration.update=r-s,this.stats.currFrame.duration.draw=n-r,this.stats.currFrame.graphics.drawnImages=je.DrawnImagesCount,this.stats.currFrame.graphics.drawCalls=je.DrawCallCount,this.emit("postframe",new Ot(this,this.stats.currFrame)),this.stats.prevFrame.reset(this.stats.currFrame)}static createMainLoop(t,e,i){let s=i();const r=new _n({nowFn:i,initialFps:t.maxFps===1/0?60:t.maxFps});return function n(){if(t._hasStarted)try{t._requestId=e(n),r.start(),t.emit("preframe",new zt(t,t.stats.prevFrame));const o=i();let a=o-s||1;const h=t.maxFps===Number.POSITIVE_INFINITY?0:1e3/t.maxFps;if(a<=h)return;a>200&&(a=1);const l=a*t.timescale,c=t.stats.prevFrame.id+1;t.stats.currFrame.reset(),t.stats.currFrame.id=c,t.stats.currFrame.delta=l,t.stats.currFrame.fps=r.fps;const d=i();t._update(l);const u=i();t._draw(l);const p=i();t.stats.currFrame.duration.update=u-d,t.stats.currFrame.duration.draw=p-u,s=h>0?o-a%h:o,t.emit("postframe",new Ot(t,t.stats.currFrame)),r.end(),t.stats.prevFrame.reset(t.stats.currFrame)}catch(e){window.cancelAnimationFrame(t._requestId),t.stop(),t.onFatalException(e)}}}stop(){this.clock.isRunning()&&(this.emit("stop",new Rt(this)),this.browser.pause(),this.clock.stop(),this._logger.debug("Game stopped"))}isPaused(){return!this.clock.isRunning()}isRunning(){return this.clock.isRunning()}screenshot(){const t=new Image,e=this.canvas.toDataURL("image/png");return t.src=e,t}async load(t){try{await t.load()}catch(t){await Promise.resolve()}}}xn._DEFAULT_ENGINE_OPTIONS={width:0,height:0,enableCanvasTransparency:!0,canvasElementId:"",canvasElement:void 0,snapToPixel:!1,pointerScope:jr.Canvas,suppressConsoleBootMessage:null,suppressMinimumBrowserFeatureDetection:null,suppressHiDPIScaling:null,suppressPlayButton:null,scrollPreventionMode:yn.Canvas,backgroundColor:I.fromHex("#2185d0")},wn([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Actor.graphics"})],xn.prototype,"playAnimation",null);let bn=class{constructor(t,e,i){this.animation=t,this.x=e,this.y=i}};bn=wn([C({message:"Will be removed in excalibur v0.26.0"})],bn);class Cn extends At{constructor(t,e="MediaEvent"){super(),this.target=t,this._name=e}set bubbles(t){}get bubbles(){return!1}get _path(){return null}set _path(t){}stopPropagation(){}action(){}propagate(){}layPath(t){}}class Sn extends Cn{constructor(t,e){super(t,"NativeSoundEvent"),this.track=e}}class An extends Cn{constructor(t,e){super(t,"NativeSoundProcessedEvent"),this._processedData=e,this.data=this._processedData}}var Pn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Tn extends Us{constructor(t){super(t),this._font=new Ls,this._text=new zs({text:"",font:this._font}),this.letterSpacing=0,this.caseInsensitive=!0;const{text:e,pos:i,x:s,y:r,spriteFont:n,font:o,color:a}=t;this.pos=null!=i?i:s&&r?P(s,r):this.pos,this.text=null!=e?e:this.text,this.font=null!=o?o:this.font,this.spriteFont=null!=n?n:this.spriteFont,this._text.color=null!=a?a:this.color;const h=this.get(cs);h.anchor=A.Zero,h.use(this._text)}get font(){return this._font}set font(t){this._font=t,this._text.font=t}get text(){return this._text.text}set text(t){this._text.text=t}get color(){return this._text.color}set color(t){this._text&&(this._text.color=t)}get opacity(){return this._text.opacity}set opacity(t){this._text.opacity=t}get bold(){return this.font.bold}set bold(t){this.font.bold=t}get fontFamily(){return this.font.family}set fontFamily(t){this.font.family=t}get fontSize(){return this.font.size}set fontSize(t){this.font.size=t}get fontStyle(){return this.font.style}set fontStyle(t){this.font.style=t}get fontUnit(){return this.font.unit}set fontUnit(t){this.font.unit=t}get textAlign(){return this.font.textAlign}set textAlign(t){this.font.textAlign=t}get baseAlign(){return this.font.baseAlign}set baseAlign(t){this.font.baseAlign=t}get spriteFont(){return this._legacySpriteFont}set spriteFont(t){if(t){if(t instanceof ze)return this._legacySpriteFont=t,this._spriteFont=Ue.fromLegacySpriteFont(t),void(this._text.font=this._spriteFont);this._spriteFont=t,this._text.font=this._spriteFont}}_initialize(t){super._initialize(t),this._graphicsContext=t.graphicsContext}getTextWidth(){return this._text.width}setTextShadow(t,e,i){this.font.shadow={offset:P(t,e),blur:2,color:i}}useTextShadow(t){this.spriteFont&&this.spriteFont.useTextShadow(t)}clearTextShadow(){this.font.shadow=null}draw(t,e){const i=this._graphicsContext;this._text.draw(i,0,0)}}Pn([C({message:"Label.bold will be removed in v0.26.0",alternateMethod:"Use Label.font.bold"})],Tn.prototype,"bold",null),Pn([C({message:"Label.fontFamily will be removed in v0.26.0",alternateMethod:"Use Label.font.family"})],Tn.prototype,"fontFamily",null),Pn([C({message:"Label.fontSize will be removed in v0.26.0",alternateMethod:"Use Label.font.size"})],Tn.prototype,"fontSize",null),Pn([C({message:"Label.fontStyle will be removed in v0.26.0",alternateMethod:"Use Label.font.style"})],Tn.prototype,"fontStyle",null),Pn([C({message:"Label.fontUnit will be removed in v0.26.0",alternateMethod:"Use Label.font.unit"})],Tn.prototype,"fontUnit",null),Pn([C({message:"Label.textAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.textAlign"})],Tn.prototype,"textAlign",null),Pn([C({message:"Label.baseAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.baseAlign"})],Tn.prototype,"baseAlign",null),Pn([C({message:"Label.setTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"setTextShadow",null),Pn([C({message:"Label.useTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"useTextShadow",null),Pn([C({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"clearTextShadow",null);class En{static create(t,e){if(this._CURRENT_GROUP>this._MAX_GROUPS)throw new Error(`Cannot have more than ${this._MAX_GROUPS} collision groups`);if(this._GROUPS.get(t))throw new Error(`Collision group ${t} already exists`);const i=new Ri(t,this._CURRENT_BIT,void 0!==e?e:~this._CURRENT_BIT);return this._CURRENT_BIT=this._CURRENT_BIT<<1|0,this._CURRENT_GROUP++,this._GROUPS.set(t,i),i}static get groups(){return Array.from(this._GROUPS.values())}static groupByName(t){return this._GROUPS.get(t)}static reset(){this._GROUPS=new Map,this._CURRENT_BIT=this._STARTING_BIT,this._CURRENT_GROUP=1}}En._STARTING_BIT=1,En._MAX_GROUPS=32,En._CURRENT_GROUP=1,En._CURRENT_BIT=En._STARTING_BIT,En._GROUPS=new Map;var In=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let Rn=class{constructor(t){this.lineWidth=5,this.filled=!1,this._points=[],this.anchor=A.Zero,this.offset=A.Zero,this.rotation=0,this.scale=A.One,this.opacity=1,this._points=t;const e=this._points.reduce(((t,e)=>Math.min(t,e.x)),0),i=this._points.reduce(((t,e)=>Math.max(t,e.x)),0);this.drawWidth=i-e;const s=this._points.reduce(((t,e)=>Math.min(t,e.y)),0),r=this._points.reduce(((t,e)=>Math.max(t,e.y)),0);this.drawHeight=r-s,this.height=this.drawHeight,this.width=this.drawWidth}addEffect(){}removeEffect(){}clearEffects(){}reset(){}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:v,flipHorizontal:y,flipVertical:w}={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.drawWidth,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.drawHeight,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,offset:null!==(a=t.offset)&&void 0!==a?a:this.offset,opacity:(null!==(h=t.opacity)&&void 0!==h?h:1)*(null!==(l=this.opacity)&&void 0!==l?l:1)},x=g*f.x+m.x+d,b=_*f.y+m.y+u;c.save(),c.translate(x,b),c.scale(this.scale.x,this.scale.y),c.rotate(p),c.beginPath(),c.lineWidth=this.lineWidth;const C=this._points[0];c.moveTo(C.x,C.y);let S=0;const A=this._points.length;for(;S<A;S++)c.lineTo(this._points[S].x,this._points[S].y);c.lineTo(C.x,C.y),c.closePath(),this.filled&&(c.fillStyle=this.fillColor.toString(),c.fill()),c.strokeStyle=this.lineColor.toString(),y&&(c.translate(g,0),c.scale(-1,1)),w&&(c.translate(0,_),c.scale(1,-1));const P=c.globalAlpha;c.globalAlpha=v,c.stroke(),c.globalAlpha=P,c.restore()}};Rn=In([C({message:"Polygon will be removed in v0.26.0",alternateMethod:"Use Graphics.Polygon"})],Rn);class Bn{}function Dn(t){return!!t._initialize}function Mn(t){return!!t.onInitialize}function kn(t){return!!t._preupdate}function Fn(t){return!!t.onPreUpdate}function Ln(t){return!!t.onPostUpdate}function zn(t){return!!t.onPostUpdate}function On(t){return!!t.onPreDraw}function Un(t){return!!t.onPostDraw}Bn.type={any:"",blob:"blob",json:"json",text:"text",document:"document",arraybuffer:"arraybuffer"};class Nn{constructor(t){this._src=t,this._volume=1,this._duration=void 0,this._loop=!1,this._isPlaying=!1,this._isPaused=!1,this._audioContext=oi.create(),this._volumeNode=this._audioContext.createGain(),this._currentOffset=0,this._createNewBufferSource()}set loop(t){this._loop=t,this._instance&&(this._instance.loop=t,this._wireUpOnEnded())}get loop(){return this._loop}set volume(t){t=z(t,0,1),this._volume=t,this._isPlaying&&this._volumeNode.gain.setTargetAtTime?this._volumeNode.gain.setTargetAtTime(t,this._audioContext.currentTime,.1):this._volumeNode.gain.value=t}get volume(){return this._volume}set duration(t){this._duration=t}get duration(){return this._duration}get _playbackRate(){return this._instance?1/(this._instance.playbackRate.value||1):null}isPlaying(){return this._isPlaying}play(t=(()=>{})){return this._isPaused&&(this._resumePlayBack(),t()),this._isPlaying||(this._startPlayBack(),t()),this._playingPromise}pause(){this._isPlaying&&(this._isPaused=!0,this._isPlaying=!1,this._instance.stop(0),this._setPauseOffset())}stop(){this._isPlaying&&(this._isPlaying=!1,this._isPaused=!1,this._currentOffset=0,this._instance.stop(0),this._instance.onended||this._handleOnEnded())}_startPlayBack(){this._isPlaying=!0,this._isPaused=!1,this._playingPromise=new Promise((t=>{this._playingResolve=t})),this._instance||this._createNewBufferSource(),this._rememberStartTime(),this._volumeNode.connect(this._audioContext.destination),this._instance.start(0,0),this._currentOffset=0,this._wireUpOnEnded()}_resumePlayBack(){if(!this._isPaused)return;this._isPaused=!1,this._isPlaying=!0,this._instance.onended=null,this._createNewBufferSource();const t=this._playbackRate*this._src.duration,e=this._currentOffset%t;this._rememberStartTime(-1e3*e),this._instance.start(0,e),this._wireUpOnEnded()}_wireUpOnEnded(){this.loop||(this._instance.onended=()=>this._handleOnEnded())}_handleOnEnded(){this._isPaused||(this._isPlaying=!1,this._playingResolve(!0))}_rememberStartTime(t){this._startTime=(new Date).getTime()+(0|t)}_setPauseOffset(){this._currentOffset=((new Date).getTime()-this._startTime)*this._playbackRate/1e3}_createNewBufferSource(){this._instance=this._audioContext.createBufferSource(),this._instance.buffer=this._src,this._instance.loop=this.loop,this._instance.playbackRate.setValueAtTime(1,0),this._instance.connect(this._volumeNode)}}function Hn(t){try{const e=new Audio,i=/.*\.([A-Za-z0-9]+)$/,s=t.match(i)[1];return!!e.canPlayType("audio/"+s)}catch(t){return f.getInstance().warn("Cannot determine audio support, assuming no support for the Audio Tag",t),!1}}class Wn extends hi{constructor(...t){super(),this.logger=f.getInstance(),this._loop=!1,this._volume=1,this._duration=void 0,this._isStopped=!1,this._isPaused=!1,this._tracks=[],this._wasPlayingOnHidden=!1,this._audioContext=oi.create(),this._resource=new le("",Bn.type.arraybuffer);for(const e of t)if(Hn(e)){this.path=e;break}this.path||(this.logger.warn("This browser does not support any of the audio files specified:",t.join(", ")),this.logger.warn("Attempting to use",t[0]),this.path=t[0])}set loop(t){this._loop=t;for(const t of this._tracks)t.loop=this._loop;this.logger.debug("Set loop for all instances of sound",this.path,"to",this._loop)}get loop(){return this._loop}set volume(t){this._volume=t;for(const t of this._tracks)t.volume=this._volume;this.emit("volumechange",new Sn(this)),this.logger.debug("Set loop for all instances of sound",this.path,"to",this._volume)}get volume(){return this._volume}get duration(){return this._duration}get instances(){return this._tracks}get path(){return this._resource.path}set path(t){this._resource.path=t}isLoaded(){return!!this.data}async load(){if(this.data)return this.data;const t=await this._resource.load(),e=await this.decodeAudio(t.slice(0));return this._duration="object"==typeof e?e.duration:void 0,this.emit("processed",new An(this,e)),this.data=e}async decodeAudio(t){try{return await this._audioContext.decodeAudioData(t.slice(0))}catch(t){return this.logger.error("Unable to decode this browser may not fully support this format, or the file may be corrupt, if this is an mp3 try removing id3 tags and album art from the file."),await Promise.reject()}}wireEngine(t){t&&(this._engine=t,this._engine.on("hidden",(()=>{t.pauseAudioWhenHidden&&this.isPlaying()&&(this._wasPlayingOnHidden=!0,this.pause())})),this._engine.on("visible",(()=>{t.pauseAudioWhenHidden&&this._wasPlayingOnHidden&&(this.play(),this._wasPlayingOnHidden=!1)})),this._engine.on("start",(()=>{this._isStopped=!1})),this._engine.on("stop",(()=>{this.stop(),this._isStopped=!0})))}instanceCount(){return this._tracks.length}isPlaying(){return this._tracks.some((t=>t.isPlaying()))}play(t){return this.isLoaded()?this._isStopped?(this.logger.warn("Cannot start playing. Engine is in a stopped state."),Promise.resolve(!1)):(this.volume=t||this.volume,this._isPaused?this._resumePlayback():this._startPlayback()):(this.logger.warn("Cannot start playing. Resource",this.path,"is not loaded yet"),Promise.resolve(!0))}pause(){if(this.isPlaying()){for(const t of this._tracks)t.pause();this._isPaused=!0,this.emit("pause",new Sn(this)),this.logger.debug("Paused all instances of sound",this.path)}}stop(){for(const t of this._tracks)t.stop();this.emit("stop",new Sn(this)),this._isPaused=!1,this._tracks.length=0,this.logger.debug("Stopped all instances of sound",this.path)}getTrackId(t){return this._tracks.indexOf(t)}async _resumePlayback(){if(this._isPaused){const t=[];for(const e of this._tracks)t.push(e.play());this._isPaused=!1,this.emit("resume",new Sn(this)),this.logger.debug("Resuming paused instances for sound",this.path,this._tracks),await Promise.all(t)}return!0}async _startPlayback(){const t=await this._getTrackInstance(this.data),e=await t.play((()=>{this.emit("playbackstart",new Sn(this,t)),this.logger.debug("Playing new instance for sound",this.path)}));return this.emit("playbackend",new Sn(this,t)),this._tracks.splice(this.getTrackId(t),1),e}_getTrackInstance(t){const e=new Nn(t);return e.loop=this.loop,e.volume=this.volume,e.duration=this.duration,this._tracks.push(e),e}}class Vn{constructor(t,e=I.Magenta,i=!0){this.path=t,this.color=e,this.bustCache=i,this._stream=null,this._gif=null,this._textures=[],this._animation=null,this._transparentColor=null,this._resource=new le(t,"arraybuffer",i),this._transparentColor=e}async load(){const t=await this._resource.load();this._stream=new qn(t),this._gif=new jn(this._stream,this._transparentColor);const e=this._gif.images.map((t=>new Pe(t.src,!1)));return await Promise.all(e.map((t=>t.load()))),this.data=this._textures=e}isLoaded(){return!!this.data}toLegacySprite(t=0){return Ae.toLegacySprite(this.toSprite(t))}toLegacySpriteSheet(){return Oe.toLegacySpriteSheet(this.toSpriteSheet())}toLegacyAnimation(t,e){return Er.toLegacyAnimation(t,this.toAnimation(e))}toSprite(t=0){return this._textures[t].toSprite()}toSpriteSheet(){const t=this._textures.map((t=>t.toSprite()));return new Oe({sprites:t})}toAnimation(t){const e=this.toSpriteSheet(),i=e.sprites.length;return this._animation=Er.fromSpriteSheet(e,H(0,i),t),this._animation}get readCheckBytes(){return this._gif.checkBytes}}const Gn=t=>t.reduce((function(t,e){return 2*t+e}),0),Xn=t=>{const e=[];for(let i=7;i>=0;i--)e.push(!!(t&1<<i));return e};class qn{constructor(t){if(this.data=null,this.len=0,this.position=0,this.readByte=()=>{if(this.position>=this.data.byteLength)throw new Error("Attempted to read past end of stream.");return this.data[this.position++]},this.readBytes=t=>{const e=[];for(let i=0;i<t;i++)e.push(this.readByte());return e},this.read=t=>{let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.readByte());return e},this.readUnsigned=()=>{const t=this.readBytes(2);return(t[1]<<8)+t[0]},this.data=new Uint8Array(t),this.len=this.data.byteLength,0===this.len)throw new Error("No data loaded from file")}}class jn{constructor(t,e=I.Magenta){this._st=null,this._handler={},this._transparentColor=null,this.frames=[],this.images=[],this.globalColorTable=[],this.checkBytes=[],this.parseColorTable=t=>{const e=[];for(let i=0;i<t;i++){const t="#"+this._st.readBytes(3).map((t=>{const e=t.toString(16);return 1===e.length?"0"+e:e})).join("");e.push(t)}return e},this.readSubBlocks=()=>{let t,e;e="";do{t=this._st.readByte(),e+=this._st.read(t)}while(0!==t);return e},this.parseHeader=()=>{const t={sig:null,ver:null,width:null,height:null,colorRes:null,globalColorTableSize:null,gctFlag:null,sorted:null,globalColorTable:[],bgColor:null,pixelAspectRatio:null};if(t.sig=this._st.read(3),t.ver=this._st.read(3),"GIF"!==t.sig)throw new Error("Not a GIF file.");t.width=this._st.readUnsigned(),t.height=this._st.readUnsigned();const e=Xn(this._st.readByte());t.gctFlag=e.shift(),t.colorRes=Gn(e.splice(0,3)),t.sorted=e.shift(),t.globalColorTableSize=Gn(e.splice(0,3)),t.bgColor=this._st.readByte(),t.pixelAspectRatio=this._st.readByte(),t.gctFlag&&(t.globalColorTable=this.parseColorTable(1<<t.globalColorTableSize+1),this.globalColorTable=t.globalColorTable),this._handler.hdr&&this._handler.hdr(t)&&this.checkBytes.push(this._handler.hdr)},this.parseExt=t=>{const e=t=>{this.checkBytes.push(this._st.readByte());const e=Xn(this._st.readByte());t.reserved=e.splice(0,3),t.disposalMethod=Gn(e.splice(0,3)),t.userInput=e.shift(),t.transparencyGiven=e.shift(),t.delayTime=this._st.readUnsigned(),t.transparencyIndex=this._st.readByte(),t.terminator=this._st.readByte(),this._handler.gce&&this._handler.gce(t)&&this.checkBytes.push(this._handler.gce)},i=t=>{t.comment=this.readSubBlocks(),this._handler.com&&this._handler.com(t)&&this.checkBytes.push(this._handler.com)},s=t=>{this.checkBytes.push(this._st.readByte()),t.ptHeader=this._st.readBytes(12),t.ptData=this.readSubBlocks(),this._handler.pte&&this._handler.pte(t)&&this.checkBytes.push(this._handler.pte)},r=t=>{const e=t=>{this.checkBytes.push(this._st.readByte()),t.unknown=this._st.readByte(),t.iterations=this._st.readUnsigned(),t.terminator=this._st.readByte(),this._handler.app&&this._handler.app.NETSCAPE&&this._handler.app.NETSCAPE(t)&&this.checkBytes.push(this._handler.app)},i=t=>{t.appData=this.readSubBlocks(),this._handler.app&&this._handler.app[t.identifier]&&this._handler.app[t.identifier](t)&&this.checkBytes.push(this._handler.app[t.identifier])};if(this.checkBytes.push(this._st.readByte()),t.identifier=this._st.read(8),t.authCode=this._st.read(3),"NETSCAPE"===t.identifier)e(t);else i(t)},n=t=>{t.data=this.readSubBlocks(),this._handler.unknown&&this._handler.unknown(t)&&this.checkBytes.push(this._handler.unknown)};switch(t.label=this._st.readByte(),t.label){case 249:t.extType="gce",e(t);break;case 254:t.extType="com",i(t);break;case 1:t.extType="pte",s(t);break;case 255:t.extType="app",r(t);break;default:t.extType="unknown",n(t)}},this.parseImg=t=>{t.leftPos=this._st.readUnsigned(),t.topPos=this._st.readUnsigned(),t.width=this._st.readUnsigned(),t.height=this._st.readUnsigned();const e=Xn(this._st.readByte());t.lctFlag=e.shift(),t.interlaced=e.shift(),t.sorted=e.shift(),t.reserved=e.splice(0,2),t.lctSize=Gn(e.splice(0,3)),t.lctFlag&&(t.lct=this.parseColorTable(1<<t.lctSize+1)),t.lzwMinCodeSize=this._st.readByte();const i=this.readSubBlocks();t.pixels=function(t,e){let i=0;const s=function(t){let s=0;for(let r=0;r<t;r++)e.charCodeAt(i>>3)&1<<(7&i)&&(s|=1<<r),i++;return s},r=[],n=1<<t,o=n+1;let a=t+1,h=[];const l=function(){h=[],a=t+1;for(let t=0;t<n;t++)h[t]=[t];h[n]=[],h[o]=null};let c,d;for(;;)if(d=c,c=s(a),c!==n){if(c===o)break;if(c<h.length)d!==n&&h.push(h[d].concat(h[c][0]));else{if(c!==h.length)throw new Error("Invalid LZW code.");h.push(h[d].concat(h[d][0]))}r.push.apply(r,h[c]),h.length===1<<a&&a<12&&a++}else l();return r}(t.lzwMinCodeSize,i),t.interlaced&&(t.pixels=((t,e)=>{const i=new Array(t.length),s=t.length/e,r=(s,r)=>{const n=t.slice(r*e,(r+1)*e);i.splice.apply(i,[s*e,e].concat(n))},n=[0,4,2,1],o=[8,8,4,2];let a=0;for(let t=0;t<4;t++)for(let e=n[t];e<s;e+=o[t])r(e,a),a++;return i})(t.pixels,t.width)),this.frames.push(t),this.arrayToImage(t),this._handler.img&&this._handler.img(t)&&this.checkBytes.push(this._handler)},this.parseBlock=()=>{const t={sentinel:this._st.readByte(),type:""};switch(String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this._handler.eof&&this._handler.eof(t)&&this.checkBytes.push(this._handler.eof);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&this.parseBlock()},this.arrayToImage=t=>{let e=0;const i=document.createElement("canvas");i.id=e.toString(),i.width=t.width,i.height=t.height,e++;const s=i.getContext("2d");let r=0,n=0;for(let e=0;e<t.pixels.length;e++)n%t.width==0&&(r++,n=0),this.globalColorTable[t.pixels[e]]===this._transparentColor.toHex()?s.fillStyle="rgba(0, 0, 0, 0)":s.fillStyle=this.globalColorTable[t.pixels[e]],s.fillRect(n,r,1,1),n++;const o=new Image;o.src=i.toDataURL(),this.images.push(o)},this._st=t,this._handler={},this._transparentColor=e,this.parseHeader(),this.parseBlock()}}class Kn extends Ct{constructor(t){super(t),this.points=t.points,this.filtering=ht.Blended,this.rasterize()}get points(){return this._points}set points(t){this._points=t;const e=this.minPoint;this.width=this._points.reduce(((t,e)=>Math.max(e.x,t)),0)-e.x,this.height=this._points.reduce(((t,e)=>Math.max(e.y,t)),0)-e.y,this.flagDirty()}get minPoint(){return P(this._points.reduce(((t,e)=>Math.min(e.x,t)),1/0),this._points.reduce(((t,e)=>Math.min(e.y,t)),1/0))}clone(){return new Kn({points:this.points.map((t=>t.clone())),...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){if(this.points&&this.points.length){t.beginPath();const e=this.minPoint.negate(),i=this.points[0].add(e);t.moveTo(i.x,i.y),this.points.forEach((i=>{t.lineTo(i.x+e.x,i.y+e.y)})),t.lineTo(i.x,i.y),t.closePath(),this.color&&t.fill(),this.strokeColor&&t.stroke()}}}var Yn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let Zn=class{constructor(t){this._getComparable=t}find(t){return this._find(this._root,t)}_find(t,e){return null!=t&&(this._getComparable(e)===t.getKey()?t.getData().indexOf(e)>-1:this._getComparable(e)<t.getKey()?this._find(t.getLeft(),e):this._find(t.getRight(),e))}get(t){return this._get(this._root,t)}_get(t,e){return null==t?[]:e===t.getKey()?t.getData():e<t.getKey()?this._get(t.getLeft(),e):this._get(t.getRight(),e)}add(t){return null==this._root?(this._root=new Qn(this._getComparable(t),[t],null,null),!0):this._insert(this._root,t)}_insert(t,e){return null!=t&&(this._getComparable(e)===t.getKey()?!(t.getData().indexOf(e)>-1)&&(t.getData().push(e),!0):this._getComparable(e)<t.getKey()?null==t.getLeft()?(t.setLeft(new Qn(this._getComparable(e),[e],null,null)),!0):this._insert(t.getLeft(),e):null==t.getRight()?(t.setRight(new Qn(this._getComparable(e),[e],null,null)),!0):this._insert(t.getRight(),e))}removeByComparable(t){this._root=this._remove(this._root,t)}_remove(t,e){if(null==t)return null;if(this._getComparable(e)!==t.getKey())return this._getComparable(e)<t.getKey()?(t.setLeft(this._remove(t.getLeft(),e)),t):(t.setRight(this._remove(t.getRight(),e)),t);{const i=t.getData().indexOf(e);if(i>-1){if(t.getData().splice(i,1),0===t.getData().length){if(null==t.getLeft()&&null==t.getRight())return null;if(null==t.getLeft())return t.getRight();if(null==t.getRight())return t.getLeft();const e=this._findMinNode(t.getRight());return t.setKey(e.getKey()),t.setData(e.getData()),t.setRight(this._cleanup(t.getRight(),e)),t}return t}}return null}_cleanup(t,e){const i=e.getKey();if(null==t)return null;if(i===t.getKey()){if(null==t.getLeft()&&null==t.getRight())return null;if(null==t.getLeft())return t.getRight();if(null==t.getRight())return t.getLeft();const e=this._findMinNode(t.getRight());return t.setKey(e.getKey()),t.setData(e.getData()),t.setRight(this._cleanup(t.getRight(),e)),t}return e.getKey()<t.getKey()?(t.setLeft(this._cleanup(t.getLeft(),e)),t):(t.setRight(this._cleanup(t.getRight(),e)),t)}_findMinNode(t){let e=t;for(;null!=e.getLeft();)e=e.getLeft();return e}list(){const t=new Array;return this._list(this._root,t),t}_list(t,e){null!=t&&(this._list(t.getLeft(),e),t.getData().forEach((t=>{e.push(t)})),this._list(t.getRight(),e))}};Zn=Yn([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use built in JS array.sort"})],Zn);let Qn=class{constructor(t,e,i,s){this._key=t,this._data=e,this._left=i,this._right=s}getKey(){return this._key}setKey(t){this._key=t}getData(){return this._data}setData(t){this._data=t}getLeft(){return this._left}setLeft(t){this._left=t}getRight(){return this._right}setRight(t){this._right=t}};Qn=Yn([C({message:"Will be removed in excalibur v0.26.0"})],Qn);class $n{constructor(t){this._key=0,this._key=t}getTheKey(){return this._key}setKey(t){this._key=t}}class Jn{constructor(t,e,i=100){this.builder=t,this.recycler=e,this.maxObjects=i,this.totalAllocations=0,this.index=0,this.objects=[],this._logger=f.getInstance()}using(t){const e=t(this);return e?this.done(...e):this.done()}borrow(t){t(this.get()),this.index--}get(...t){if(this.index===this.maxObjects&&(this._logger.warn("Max pooled objects reached, possible memory leak? Doubling"),this.maxObjects=2*this.maxObjects),this.objects[this.index])return this.recycler(this.objects[this.index++],...t);this.totalAllocations++;return this.objects[this.index++]=this.builder(...t)}done(...t){this.index=0;for(const e of t){const t=this.objects.indexOf(e);this.objects[t]=this.builder(),this.totalAllocations++}return t}}var to,eo,io=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};!function(t){t[t.Resolved=0]="Resolved",t[t.Rejected=1]="Rejected",t[t.Pending=2]="Pending"}(eo||(eo={}));let so=to=class{constructor(){this._state=eo.Pending,this._successCallbacks=[],this._rejectCallback=()=>{}}static resolve(t){return(new to).resolve(t)}static reject(t){return(new to).reject(t)}static join(){let t=[];if(arguments.length>0&&!Array.isArray(arguments[0]))for(let e=0;e<arguments.length;e++)t[e-0]=arguments[e];else 1===arguments.length&&Array.isArray(arguments[0])&&(t=arguments[0]);const e=new to;if(!t||!t.length)return e.resolve();const i=t.length;let s=0,r=0;const n=[];return t.forEach((t=>{t.then((()=>{s+=1,s===i?e.resolve():s+r+n.length===i&&e.reject(n)}),(()=>{r+=1,s+r+n.length===i&&e.reject(n)})).error((t=>{n.push(t),n.length+s+r===i&&e.reject(n)}))})),e}then(t,e){if(t&&(this._successCallbacks.push(t),this.state()===eo.Resolved))try{t.call(this,this._value)}catch(t){this._handleError(t)}if(e&&(this._rejectCallback=e,this.state()===eo.Rejected))try{e.call(this,this._value)}catch(t){this._handleError(t)}return this}error(t){return t&&(this._errorCallback=t),this}resolve(t){if(this._state!==eo.Pending)throw new Error("Cannot resolve a promise that is not in a pending state!");this._value=t;try{this._state=eo.Resolved,this._successCallbacks.forEach((t=>{t.call(this,this._value)}))}catch(t){this._handleError(t)}return this}reject(t){if(this._state!==eo.Pending)throw new Error("Cannot reject a promise that is not in a pending state!");this._value=t;try{this._state=eo.Rejected,this._rejectCallback.call(this,this._value)}catch(t){this._handleError(t)}return this}state(){return this._state}_handleError(t){if(!this._errorCallback)throw t;this._errorCallback.call(this,t)}};so=to=io([C({message:"ex.Promises are being replaced by native browser promises in v0.26.0",alternateMethod:"Use browser native promises"})],so);const ro="0.25.2";p()})(),s})()}));
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ex=e():t.ex=e()}(self,(function(){return(()=>{var t={4662:(t,e,i)=>{i(3430);var s=i(8791);t.exports=s("Array","sort")},8343:(t,e,i)=>{i(4769);var s=i(9276);t.exports=s.Object.keys},7111:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(9821),o=s.TypeError;t.exports=function(t){if(r(t))return t;throw o(n(t)+" is not a function")}},1176:(t,e,i)=>{var s=i(9859),r=i(5052),n=s.String,o=s.TypeError;t.exports=function(t){if(r(t))return t;throw o(n(t)+" is not an object")}},9540:(t,e,i)=>{var s=i(905),r=i(3231),n=i(9646),o=function(t){return function(e,i,o){var a,h=s(e),l=n(h),c=r(o,l);if(t&&i!=i){for(;l>c;)if((a=h[c++])!=a)return!0}else for(;l>c;c++)if((t||c in h)&&h[c]===i)return t||c||0;return!t&&-1}};t.exports={includes:o(!0),indexOf:o(!1)}},6038:(t,e,i)=>{"use strict";var s=i(4229);t.exports=function(t,e){var i=[][t];return!!i&&s((function(){i.call(null,e||function(){throw 1},1)}))}},9794:(t,e,i)=>{var s=i(9859),r=i(3231),n=i(9646),o=i(2324),a=s.Array,h=Math.max;t.exports=function(t,e,i){for(var s=n(t),l=r(e,s),c=r(void 0===i?s:i,s),d=a(h(c-l,0)),u=0;l<c;l++,u++)o(d,u,t[l]);return d.length=u,d}},3867:(t,e,i)=>{var s=i(9794),r=Math.floor,n=function(t,e){var i=t.length,h=r(i/2);return i<8?o(t,e):a(t,n(s(t,0,h),e),n(s(t,h),e),e)},o=function(t,e){for(var i,s,r=t.length,n=1;n<r;){for(s=n,i=t[n];s&&e(t[s-1],i)>0;)t[s]=t[--s];s!==n++&&(t[s]=i)}return t},a=function(t,e,i,s){for(var r=e.length,n=i.length,o=0,a=0;o<r||a<n;)t[o+a]=o<r&&a<n?s(e[o],i[a])<=0?e[o++]:i[a++]:o<r?e[o++]:i[a++];return t};t.exports=n},7079:(t,e,i)=>{var s=i(5968),r=s({}.toString),n=s("".slice);t.exports=function(t){return n(r(t),8,-1)}},1589:(t,e,i)=>{var s=i(9859),r=i(1601),n=i(6733),o=i(7079),a=i(95)("toStringTag"),h=s.Object,l="Arguments"==o(function(){return arguments}());t.exports=r?o:function(t){var e,i,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=function(t,e){try{return t[e]}catch(t){}}(e=h(t),a))?i:l?o(e):"Object"==(s=o(e))&&n(e.callee)?"Arguments":s}},7081:(t,e,i)=>{var s=i(8270),r=i(4826),n=i(7933),o=i(1787);t.exports=function(t,e,i){for(var a=r(e),h=o.f,l=n.f,c=0;c<a.length;c++){var d=a[c];s(t,d)||i&&s(i,d)||h(t,d,l(e,d))}}},5762:(t,e,i)=>{var s=i(7400),r=i(1787),n=i(5358);t.exports=s?function(t,e,i){return r.f(t,e,n(1,i))}:function(t,e,i){return t[e]=i,t}},5358:t=>{t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},2324:(t,e,i)=>{"use strict";var s=i(9310),r=i(1787),n=i(5358);t.exports=function(t,e,i){var o=s(e);o in t?r.f(t,o,n(0,i)):t[o]=i}},7400:(t,e,i)=>{var s=i(4229);t.exports=!s((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}))},2635:(t,e,i)=>{var s=i(9859),r=i(5052),n=s.document,o=r(n)&&r(n.createElement);t.exports=function(t){return o?n.createElement(t):{}}},2671:(t,e,i)=>{var s=i(598).match(/firefox\/(\d+)/i);t.exports=!!s&&+s[1]},8506:(t,e,i)=>{var s=i(598);t.exports=/MSIE|Trident/.test(s)},598:(t,e,i)=>{var s=i(1333);t.exports=s("navigator","userAgent")||""},6358:(t,e,i)=>{var s,r,n=i(9859),o=i(598),a=n.process,h=n.Deno,l=a&&a.versions||h&&h.version,c=l&&l.v8;c&&(r=(s=c.split("."))[0]>0&&s[0]<4?1:+(s[0]+s[1])),!r&&o&&(!(s=o.match(/Edge\/(\d+)/))||s[1]>=74)&&(s=o.match(/Chrome\/(\d+)/))&&(r=+s[1]),t.exports=r},9811:(t,e,i)=>{var s=i(598).match(/AppleWebKit\/(\d+)\./);t.exports=!!s&&+s[1]},8791:(t,e,i)=>{var s=i(9859),r=i(5968);t.exports=function(t,e){return r(s[t].prototype[e])}},3837:t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3103:(t,e,i)=>{var s=i(9859),r=i(7933).f,n=i(5762),o=i(7487),a=i(2079),h=i(7081),l=i(6541);t.exports=function(t,e){var i,c,d,u,p,g=t.target,_=t.global,f=t.stat;if(i=_?s:f?s[g]||a(g,{}):(s[g]||{}).prototype)for(c in e){if(u=e[c],d=t.noTargetGet?(p=r(i,c))&&p.value:i[c],!l(_?c:g+(f?".":"#")+c,t.forced)&&void 0!==d){if(typeof u==typeof d)continue;h(u,d)}(t.sham||d&&d.sham)&&n(u,"sham",!0),o(i,c,u,t)}}},4229:t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}},7188:(t,e,i)=>{var s=i(4229);t.exports=!s((function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")}))},266:(t,e,i)=>{var s=i(7188),r=Function.prototype.call;t.exports=s?r.bind(r):function(){return r.apply(r,arguments)}},1805:(t,e,i)=>{var s=i(7400),r=i(8270),n=Function.prototype,o=s&&Object.getOwnPropertyDescriptor,a=r(n,"name"),h=a&&"something"===function(){}.name,l=a&&(!s||s&&o(n,"name").configurable);t.exports={EXISTS:a,PROPER:h,CONFIGURABLE:l}},5968:(t,e,i)=>{var s=i(7188),r=Function.prototype,n=r.bind,o=r.call,a=s&&n.bind(o,o);t.exports=s?function(t){return t&&a(t)}:function(t){return t&&function(){return o.apply(t,arguments)}}},1333:(t,e,i)=>{var s=i(9859),r=i(6733),n=function(t){return r(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?n(s[t]):s[t]&&s[t][e]}},5300:(t,e,i)=>{var s=i(7111);t.exports=function(t,e){var i=t[e];return null==i?void 0:s(i)}},9859:(t,e,i)=>{var s=function(t){return t&&t.Math==Math&&t};t.exports=s("object"==typeof globalThis&&globalThis)||s("object"==typeof window&&window)||s("object"==typeof self&&self)||s("object"==typeof i.g&&i.g)||function(){return this}()||Function("return this")()},8270:(t,e,i)=>{var s=i(5968),r=i(2991),n=s({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return n(r(t),e)}},5977:t=>{t.exports={}},4394:(t,e,i)=>{var s=i(7400),r=i(4229),n=i(2635);t.exports=!s&&!r((function(){return 7!=Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a}))},9337:(t,e,i)=>{var s=i(9859),r=i(5968),n=i(4229),o=i(7079),a=s.Object,h=r("".split);t.exports=n((function(){return!a("z").propertyIsEnumerable(0)}))?function(t){return"String"==o(t)?h(t,""):a(t)}:a},8511:(t,e,i)=>{var s=i(5968),r=i(6733),n=i(5353),o=s(Function.toString);r(n.inspectSource)||(n.inspectSource=function(t){return o(t)}),t.exports=n.inspectSource},6407:(t,e,i)=>{var s,r,n,o=i(8694),a=i(9859),h=i(5968),l=i(5052),c=i(5762),d=i(8270),u=i(5353),p=i(4399),g=i(5977),_="Object already initialized",f=a.TypeError,m=a.WeakMap;if(o||u.state){var v=u.state||(u.state=new m),y=h(v.get),w=h(v.has),x=h(v.set);s=function(t,e){if(w(v,t))throw new f(_);return e.facade=t,x(v,t,e),e},r=function(t){return y(v,t)||{}},n=function(t){return w(v,t)}}else{var b=p("state");g[b]=!0,s=function(t,e){if(d(t,b))throw new f(_);return e.facade=t,c(t,b,e),e},r=function(t){return d(t,b)?t[b]:{}},n=function(t){return d(t,b)}}t.exports={set:s,get:r,has:n,enforce:function(t){return n(t)?r(t):s(t,{})},getterFor:function(t){return function(e){var i;if(!l(e)||(i=r(e)).type!==t)throw f("Incompatible receiver, "+t+" required");return i}}}},6733:t=>{t.exports=function(t){return"function"==typeof t}},6541:(t,e,i)=>{var s=i(4229),r=i(6733),n=/#|\.prototype\./,o=function(t,e){var i=h[a(t)];return i==c||i!=l&&(r(e)?s(e):!!e)},a=o.normalize=function(t){return String(t).replace(n,".").toLowerCase()},h=o.data={},l=o.NATIVE="N",c=o.POLYFILL="P";t.exports=o},5052:(t,e,i)=>{var s=i(6733);t.exports=function(t){return"object"==typeof t?null!==t:s(t)}},4231:t=>{t.exports=!1},9395:(t,e,i)=>{var s=i(9859),r=i(1333),n=i(6733),o=i(1321),a=i(6969),h=s.Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=r("Symbol");return n(e)&&o(e.prototype,h(t))}},9646:(t,e,i)=>{var s=i(4237);t.exports=function(t){return s(t.length)}},3839:(t,e,i)=>{var s=i(6358),r=i(4229);t.exports=!!Object.getOwnPropertySymbols&&!r((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&s&&s<41}))},8694:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(8511),o=s.WeakMap;t.exports=r(o)&&/native code/.test(n(o))},1787:(t,e,i)=>{var s=i(9859),r=i(7400),n=i(4394),o=i(7137),a=i(1176),h=i(9310),l=s.TypeError,c=Object.defineProperty,d=Object.getOwnPropertyDescriptor,u="enumerable",p="configurable",g="writable";e.f=r?o?function(t,e,i){if(a(t),e=h(e),a(i),"function"==typeof t&&"prototype"===e&&"value"in i&&g in i&&!i.writable){var s=d(t,e);s&&s.writable&&(t[e]=i.value,i={configurable:p in i?i.configurable:s.configurable,enumerable:u in i?i.enumerable:s.enumerable,writable:!1})}return c(t,e,i)}:c:function(t,e,i){if(a(t),e=h(e),a(i),n)try{return c(t,e,i)}catch(t){}if("get"in i||"set"in i)throw l("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},7933:(t,e,i)=>{var s=i(7400),r=i(266),n=i(9195),o=i(5358),a=i(905),h=i(9310),l=i(8270),c=i(4394),d=Object.getOwnPropertyDescriptor;e.f=s?d:function(t,e){if(t=a(t),e=h(e),c)try{return d(t,e)}catch(t){}if(l(t,e))return o(!r(n.f,t,e),t[e])}},8151:(t,e,i)=>{var s=i(140),r=i(3837).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return s(t,r)}},894:(t,e)=>{e.f=Object.getOwnPropertySymbols},1321:(t,e,i)=>{var s=i(5968);t.exports=s({}.isPrototypeOf)},140:(t,e,i)=>{var s=i(5968),r=i(8270),n=i(905),o=i(9540).indexOf,a=i(5977),h=s([].push);t.exports=function(t,e){var i,s=n(t),l=0,c=[];for(i in s)!r(a,i)&&r(s,i)&&h(c,i);for(;e.length>l;)r(s,i=e[l++])&&(~o(c,i)||h(c,i));return c}},5632:(t,e,i)=>{var s=i(140),r=i(3837);t.exports=Object.keys||function(t){return s(t,r)}},9195:(t,e)=>{"use strict";var i={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,r=s&&!i.call({1:2},1);e.f=r?function(t){var e=s(this,t);return!!e&&e.enumerable}:i},2914:(t,e,i)=>{var s=i(9859),r=i(266),n=i(6733),o=i(5052),a=s.TypeError;t.exports=function(t,e){var i,s;if("string"===e&&n(i=t.toString)&&!o(s=r(i,t)))return s;if(n(i=t.valueOf)&&!o(s=r(i,t)))return s;if("string"!==e&&n(i=t.toString)&&!o(s=r(i,t)))return s;throw a("Can't convert object to primitive value")}},4826:(t,e,i)=>{var s=i(1333),r=i(5968),n=i(8151),o=i(894),a=i(1176),h=r([].concat);t.exports=s("Reflect","ownKeys")||function(t){var e=n.f(a(t)),i=o.f;return i?h(e,i(t)):e}},9276:(t,e,i)=>{var s=i(9859);t.exports=s},7487:(t,e,i)=>{var s=i(9859),r=i(6733),n=i(8270),o=i(5762),a=i(2079),h=i(8511),l=i(6407),c=i(1805).CONFIGURABLE,d=l.get,u=l.enforce,p=String(String).split("String");(t.exports=function(t,e,i,h){var l,d=!!h&&!!h.unsafe,g=!!h&&!!h.enumerable,_=!!h&&!!h.noTargetGet,f=h&&void 0!==h.name?h.name:e;r(i)&&("Symbol("===String(f).slice(0,7)&&(f="["+String(f).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),(!n(i,"name")||c&&i.name!==f)&&o(i,"name",f),(l=u(i)).source||(l.source=p.join("string"==typeof f?f:""))),t!==s?(d?!_&&t[e]&&(g=!0):delete t[e],g?t[e]=i:o(t,e,i)):g?t[e]=i:a(e,i)})(Function.prototype,"toString",(function(){return r(this)&&d(this).source||h(this)}))},8885:(t,e,i)=>{var s=i(9859).TypeError;t.exports=function(t){if(null==t)throw s("Can't call method on "+t);return t}},2079:(t,e,i)=>{var s=i(9859),r=Object.defineProperty;t.exports=function(t,e){try{r(s,t,{value:e,configurable:!0,writable:!0})}catch(i){s[t]=e}return e}},4399:(t,e,i)=>{var s=i(3036),r=i(1441),n=s("keys");t.exports=function(t){return n[t]||(n[t]=r(t))}},5353:(t,e,i)=>{var s=i(9859),r=i(2079),n="__core-js_shared__",o=s[n]||r(n,{});t.exports=o},3036:(t,e,i)=>{var s=i(4231),r=i(5353);(t.exports=function(t,e){return r[t]||(r[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.21.0",mode:s?"pure":"global",copyright:"© 2014-2022 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.21.0/LICENSE",source:"https://github.com/zloirock/core-js"})},3231:(t,e,i)=>{var s=i(3329),r=Math.max,n=Math.min;t.exports=function(t,e){var i=s(t);return i<0?r(i+e,0):n(i,e)}},905:(t,e,i)=>{var s=i(9337),r=i(8885);t.exports=function(t){return s(r(t))}},3329:t=>{var e=Math.ceil,i=Math.floor;t.exports=function(t){var s=+t;return s!=s||0===s?0:(s>0?i:e)(s)}},4237:(t,e,i)=>{var s=i(3329),r=Math.min;t.exports=function(t){return t>0?r(s(t),9007199254740991):0}},2991:(t,e,i)=>{var s=i(9859),r=i(8885),n=s.Object;t.exports=function(t){return n(r(t))}},2066:(t,e,i)=>{var s=i(9859),r=i(266),n=i(5052),o=i(9395),a=i(5300),h=i(2914),l=i(95),c=s.TypeError,d=l("toPrimitive");t.exports=function(t,e){if(!n(t)||o(t))return t;var i,s=a(t,d);if(s){if(void 0===e&&(e="default"),i=r(s,t,e),!n(i)||o(i))return i;throw c("Can't convert object to primitive value")}return void 0===e&&(e="number"),h(t,e)}},9310:(t,e,i)=>{var s=i(2066),r=i(9395);t.exports=function(t){var e=s(t,"string");return r(e)?e:e+""}},1601:(t,e,i)=>{var s={};s[i(95)("toStringTag")]="z",t.exports="[object z]"===String(s)},3326:(t,e,i)=>{var s=i(9859),r=i(1589),n=s.String;t.exports=function(t){if("Symbol"===r(t))throw TypeError("Cannot convert a Symbol value to a string");return n(t)}},9821:(t,e,i)=>{var s=i(9859).String;t.exports=function(t){try{return s(t)}catch(t){return"Object"}}},1441:(t,e,i)=>{var s=i(5968),r=0,n=Math.random(),o=s(1..toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+o(++r+n,36)}},6969:(t,e,i)=>{var s=i(3839);t.exports=s&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},7137:(t,e,i)=>{var s=i(7400),r=i(4229);t.exports=s&&r((function(){return 42!=Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype}))},95:(t,e,i)=>{var s=i(9859),r=i(3036),n=i(8270),o=i(1441),a=i(3839),h=i(6969),l=r("wks"),c=s.Symbol,d=c&&c.for,u=h?c:c&&c.withoutSetter||o;t.exports=function(t){if(!n(l,t)||!a&&"string"!=typeof l[t]){var e="Symbol."+t;a&&n(c,t)?l[t]=c[t]:l[t]=h&&d?d(e):u(e)}return l[t]}},3430:(t,e,i)=>{"use strict";var s=i(3103),r=i(5968),n=i(7111),o=i(2991),a=i(9646),h=i(3326),l=i(4229),c=i(3867),d=i(6038),u=i(2671),p=i(8506),g=i(6358),_=i(9811),f=[],m=r(f.sort),v=r(f.push),y=l((function(){f.sort(void 0)})),w=l((function(){f.sort(null)})),x=d("sort"),b=!l((function(){if(g)return g<70;if(!(u&&u>3)){if(p)return!0;if(_)return _<603;var t,e,i,s,r="";for(t=65;t<76;t++){switch(e=String.fromCharCode(t),t){case 66:case 69:case 70:case 72:i=3;break;case 68:case 71:i=4;break;default:i=2}for(s=0;s<47;s++)f.push({k:e+s,v:i})}for(f.sort((function(t,e){return e.v-t.v})),s=0;s<f.length;s++)e=f[s].k.charAt(0),r.charAt(r.length-1)!==e&&(r+=e);return"DGBEFHACIJK"!==r}}));s({target:"Array",proto:!0,forced:y||!w||!x||!b},{sort:function(t){void 0!==t&&n(t);var e=o(this);if(b)return void 0===t?m(e):m(e,t);var i,s,r=[],l=a(e);for(s=0;s<l;s++)s in e&&v(r,e[s]);for(c(r,function(t){return function(e,i){return void 0===i?-1:void 0===e?1:void 0!==t?+t(e,i)||0:h(e)>h(i)?1:-1}}(t)),i=r.length,s=0;s<i;)e[s]=r[s++];for(;s<l;)delete e[s++];return e}})},4769:(t,e,i)=>{var s=i(3103),r=i(2991),n=i(5632);s({target:"Object",stat:!0,forced:i(4229)((function(){n(1)}))},{keys:function(t){return n(r(t))}})},1388:(t,e,i)=>{"use strict";i.d(e,{Z:()=>a});var s=i(272),r=i.n(s),n=i(2609),o=i.n(n)()(r());o.push([t.id,"/* Buttons styles start */\r\n\r\nbutton#excalibur-play {\r\n display: inline-block;\r\n position: relative;\r\n z-index: 999;\r\n border-radius: 6px;\r\n border: none;\r\n /*border: 3px solid;\r\n border-color: white;\r\n box-shadow: 0 0 10px #ccc;*/\r\n padding: 1rem 1.5rem 1rem 4rem;\r\n margin: 0;\r\n text-decoration: none;\r\n background: #00b233;\r\n color: #ffffff;\r\n font-family: sans-serif;\r\n font-size: 2rem;\r\n white-space: nowrap;\r\n line-height: 1;\r\n cursor: pointer;\r\n text-align: center;\r\n transition: background 250ms ease-in-out, transform 150ms ease;\r\n -webkit-appearance: none;\r\n -moz-appearance: none;\r\n\r\n -webkit-animation: excalibur-button-fadein 200ms; /* Safari, Chrome and Opera > 12.1 */\r\n -moz-animation: excalibur-button-fadein 200ms; /* Firefox < 16 */\r\n -ms-animation: excalibur-button-fadein 200ms; /* Internet Explorer */\r\n -o-animation: excalibur-button-fadein 200ms; /* Opera < 12.1 */\r\n animation: excalibur-button-fadein 200ms;\r\n}\r\n\r\n/*\r\nbutton#excalibur-play {\r\n display: none;\r\n}*/\r\n\r\nbutton#excalibur-play:after {\r\n position: absolute;\r\n content: '';\r\n border: 8px solid;\r\n border-color: transparent transparent transparent white;\r\n left: 35px;\r\n top: 24px;\r\n width: 0;\r\n height: 0;\r\n}\r\n\r\nbutton#excalibur-play:before {\r\n position: absolute;\r\n content: '';\r\n border: 3px solid;\r\n left: 19px;\r\n top: 14px;\r\n border-radius: 20px;\r\n width: 30px;\r\n height: 30px;\r\n}\r\n\r\nbutton#excalibur-play:hover,\r\nbutton#excalibur-play:focus {\r\n background: #00982c;\r\n}\r\n\r\nbutton#excalibur-play:focus {\r\n outline: 1px solid #fff;\r\n outline-offset: -4px;\r\n}\r\n\r\nbutton#excalibur-play:active {\r\n transform: scale(0.99);\r\n}\r\n\r\n@keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Firefox < 16 */\r\n@-moz-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Safari, Chrome and Opera > 12.1 */\r\n@-webkit-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Internet Explorer */\r\n@-ms-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Opera < 12.1 */\r\n@-o-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n","",{version:3,sources:["webpack://./Loader.css"],names:[],mappings:"AAAA,yBAAyB;;AAEzB;EACE,qBAAqB;EACrB,kBAAkB;EAClB,YAAY;EACZ,kBAAkB;EAClB,YAAY;EACZ;;+BAE6B;EAC7B,8BAA8B;EAC9B,SAAS;EACT,qBAAqB;EACrB,mBAAmB;EACnB,cAAc;EACd,uBAAuB;EACvB,eAAe;EACf,mBAAmB;EACnB,cAAc;EACd,eAAe;EACf,kBAAkB;EAClB,8DAA8D;EAC9D,wBAAwB;EACxB,qBAAqB;;EAErB,gDAAgD,EAAE,oCAAoC;EACtF,6CAA6C,EAAE,iBAAiB;EAChE,4CAA4C,EAAE,sBAAsB;EACpE,2CAA2C,EAAE,iBAAiB;EAC9D,wCAAwC;AAC1C;;AAEA;;;EAGE;;AAEF;EACE,kBAAkB;EAClB,WAAW;EACX,iBAAiB;EACjB,uDAAuD;EACvD,UAAU;EACV,SAAS;EACT,QAAQ;EACR,SAAS;AACX;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,iBAAiB;EACjB,UAAU;EACV,SAAS;EACT,mBAAmB;EACnB,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,mBAAmB;AACrB;;AAEA;EACE,uBAAuB;EACvB,oBAAoB;AACtB;;AAEA;EACE,sBAAsB;AACxB;;AAEA;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,iBAAiB;AACjB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,oCAAoC;AACpC;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,sBAAsB;AACtB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF;;AAEA,iBAAiB;AACjB;EACE;IACE,UAAU;EACZ;EACA;IACE,UAAU;EACZ;AACF",sourcesContent:["/* Buttons styles start */\r\n\r\nbutton#excalibur-play {\r\n display: inline-block;\r\n position: relative;\r\n z-index: 999;\r\n border-radius: 6px;\r\n border: none;\r\n /*border: 3px solid;\r\n border-color: white;\r\n box-shadow: 0 0 10px #ccc;*/\r\n padding: 1rem 1.5rem 1rem 4rem;\r\n margin: 0;\r\n text-decoration: none;\r\n background: #00b233;\r\n color: #ffffff;\r\n font-family: sans-serif;\r\n font-size: 2rem;\r\n white-space: nowrap;\r\n line-height: 1;\r\n cursor: pointer;\r\n text-align: center;\r\n transition: background 250ms ease-in-out, transform 150ms ease;\r\n -webkit-appearance: none;\r\n -moz-appearance: none;\r\n\r\n -webkit-animation: excalibur-button-fadein 200ms; /* Safari, Chrome and Opera > 12.1 */\r\n -moz-animation: excalibur-button-fadein 200ms; /* Firefox < 16 */\r\n -ms-animation: excalibur-button-fadein 200ms; /* Internet Explorer */\r\n -o-animation: excalibur-button-fadein 200ms; /* Opera < 12.1 */\r\n animation: excalibur-button-fadein 200ms;\r\n}\r\n\r\n/*\r\nbutton#excalibur-play {\r\n display: none;\r\n}*/\r\n\r\nbutton#excalibur-play:after {\r\n position: absolute;\r\n content: '';\r\n border: 8px solid;\r\n border-color: transparent transparent transparent white;\r\n left: 35px;\r\n top: 24px;\r\n width: 0;\r\n height: 0;\r\n}\r\n\r\nbutton#excalibur-play:before {\r\n position: absolute;\r\n content: '';\r\n border: 3px solid;\r\n left: 19px;\r\n top: 14px;\r\n border-radius: 20px;\r\n width: 30px;\r\n height: 30px;\r\n}\r\n\r\nbutton#excalibur-play:hover,\r\nbutton#excalibur-play:focus {\r\n background: #00982c;\r\n}\r\n\r\nbutton#excalibur-play:focus {\r\n outline: 1px solid #fff;\r\n outline-offset: -4px;\r\n}\r\n\r\nbutton#excalibur-play:active {\r\n transform: scale(0.99);\r\n}\r\n\r\n@keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Firefox < 16 */\r\n@-moz-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Safari, Chrome and Opera > 12.1 */\r\n@-webkit-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Internet Explorer */\r\n@-ms-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n\r\n/* Opera < 12.1 */\r\n@-o-keyframes excalibur-button-fadein {\r\n from {\r\n opacity: 0;\r\n }\r\n to {\r\n opacity: 1;\r\n }\r\n}\r\n"],sourceRoot:""}]);const a=o},2609:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var i="",s=void 0!==e[5];return e[4]&&(i+="@supports (".concat(e[4],") {")),e[2]&&(i+="@media ".concat(e[2]," {")),s&&(i+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),i+=t(e),s&&(i+="}"),e[2]&&(i+="}"),e[4]&&(i+="}"),i})).join("")},e.i=function(t,i,s,r,n){"string"==typeof t&&(t=[[null,t,void 0]]);var o={};if(s)for(var a=0;a<this.length;a++){var h=this[a][0];null!=h&&(o[h]=!0)}for(var l=0;l<t.length;l++){var c=[].concat(t[l]);s&&o[c[0]]||(void 0!==n&&(void 0===c[5]||(c[1]="@layer".concat(c[5].length>0?" ".concat(c[5]):""," {").concat(c[1],"}")),c[5]=n),i&&(c[2]?(c[1]="@media ".concat(c[2]," {").concat(c[1],"}"),c[2]=i):c[2]=i),r&&(c[4]?(c[1]="@supports (".concat(c[4],") {").concat(c[1],"}"),c[4]=r):c[4]="".concat(r)),e.push(c))}},e}},272:t=>{"use strict";t.exports=function(t){var e=t[1],i=t[3];if(!i)return e;if("function"==typeof btoa){var s=btoa(unescape(encodeURIComponent(JSON.stringify(i)))),r="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s),n="/*# ".concat(r," */"),o=i.sources.map((function(t){return"/*# sourceURL=".concat(i.sourceRoot||"").concat(t," */")}));return[e].concat(o).concat([n]).join("\n")}return[e].join("\n")}}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var n=e[s]={id:s,exports:{}};return t[s](n,n.exports,i),n.exports}i.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{"use strict";i.r(s),i.d(s,{ActionContext:()=>ks,ActionQueue:()=>ms,ActionsComponent:()=>Fs,ActionsSystem:()=>zr,ActivateEvent:()=>ie,Actor:()=>Us,AddedComponent:()=>es,AddedEntity:()=>hr,Animation:()=>Er,AnimationDirection:()=>Ar,AnimationStrategy:()=>Pr,ArcadeSolver:()=>xr,AudioContextFactory:()=>oi,Axis:()=>Vs,BaseAlign:()=>Be,BinaryTreeNode:()=>Qn,Blink:()=>Es,BodyComponent:()=>$i,BoundingBox:()=>D,BroadphaseStrategy:()=>wi,BrowserComponent:()=>on,BrowserEvents:()=>an,Camera:()=>ir,Canvas:()=>St,Cell:()=>Zs,Circle:()=>us,CircleCollider:()=>Gi,Class:()=>hi,Clock:()=>fn,ClosestLine:()=>Hi,ClosestLineJumpTable:()=>Wi,Collider:()=>Oi,ColliderComponent:()=>Yi,CollisionContact:()=>Vi,CollisionEndEvent:()=>te,CollisionGroup:()=>Ri,CollisionGroupManager:()=>En,CollisionJumpTable:()=>qi,CollisionPostSolveEvent:()=>$t,CollisionPreSolveEvent:()=>Qt,CollisionResolutionStrategy:()=>yi,CollisionSolver:()=>wr,CollisionStartEvent:()=>Jt,CollisionSystem:()=>Sr,CollisionType:()=>vi,Color:()=>I,ColorBlindFlags:()=>Gr,ColorBlindnessMode:()=>Or,ColorBlindnessPostProcessor:()=>Wr,Component:()=>Ai,CompositeCollider:()=>Ui,Configurable:()=>xe,ConsoleAppender:()=>m,ContactConstraintPoint:()=>br,ContactEndEvent:()=>Yt,ContactStartEvent:()=>Zt,CoordPlane:()=>Ti,CullingBox:()=>Ji,DeactivateEvent:()=>se,Debug:()=>Vr,DebugGraphicsComponent:()=>Gs,DebugSystem:()=>Fr,DebugText:()=>Ne,DegreeOfFreedom:()=>Qi,Detector:()=>mi,Die:()=>Ds,Direction:()=>ke,DisplayMode:()=>si,DynamicTree:()=>Fi,DynamicTreeCollisionProcessor:()=>zi,EX_VERSION:()=>ro,EaseTo:()=>Ts,EasingFunctions:()=>fs,EdgeCollider:()=>ji,ElasticToActorStrategy:()=>Js,EmitterType:()=>Tr,Engine:()=>xn,EnterTriggerEvent:()=>oe,EnterViewPortEvent:()=>ne,Entity:()=>ns,EntityManager:()=>ur,EventDispatcher:()=>he,EventTypes:()=>lt,Events:()=>e,ExResponse:()=>Dn,ExcaliburGraphicsContext2DCanvas:()=>ln,ExcaliburGraphicsContextWebGL:()=>ii,ExcaliburWebGLContextAccessor:()=>Ge,ExitTriggerEvent:()=>ae,ExitViewPortEvent:()=>re,Experiments:()=>c,Fade:()=>Is,Flags:()=>g,Follow:()=>Bs,Font:()=>Ls,FontStyle:()=>Me,FontUnit:()=>Re,FpsSampler:()=>_n,FrameStats:()=>Xr,GameEvent:()=>At,GameStartEvent:()=>It,GameStopEvent:()=>Rt,GamepadAxisEvent:()=>Wt,GamepadButtonEvent:()=>Ht,GamepadConnectEvent:()=>Ut,GamepadDisconnectEvent:()=>Nt,Gif:()=>Gn,GlobalCoordinates:()=>cn,Graphic:()=>_t,GraphicsComponent:()=>cs,GraphicsGroup:()=>Ir,GraphicsLayer:()=>hs,GraphicsLayers:()=>ls,GraphicsSystem:()=>Mr,HiddenEvent:()=>qt,ImageFiltering:()=>ht,ImageSource:()=>Pe,InitializeEvent:()=>ee,Input:()=>a,Integrator:()=>xi,KillEvent:()=>Pt,Label:()=>Tn,Legacy:()=>d,LegacyDrawing:()=>o,LimitCameraBoundsStrategy:()=>er,Line:()=>Ni,Loader:()=>_i,LockCameraToActorAxisStrategy:()=>$s,LockCameraToActorStrategy:()=>Qs,LogLevel:()=>u,Logger:()=>f,Matrix:()=>ct,MatrixLocations:()=>at,MediaEvent:()=>Cn,Meet:()=>Ms,MockedElement:()=>$n,MotionComponent:()=>Ii,MotionSystem:()=>yr,MoveBy:()=>ws,MoveTo:()=>xs,NativeSoundEvent:()=>Sn,NativeSoundProcessedEvent:()=>An,Observable:()=>Di,Pair:()=>Bi,ParseGif:()=>jn,Particle:()=>Dr,ParticleEmitter:()=>Br,Physics:()=>Ci,PhysicsStats:()=>qr,PointerComponent:()=>ps,PointerSystem:()=>Lr,Polygon:()=>Kn,PolygonCollider:()=>Ki,Pool:()=>Jn,PostCollisionEvent:()=>Kt,PostDebugDrawEvent:()=>kt,PostDrawEvent:()=>Bt,PostFrameEvent:()=>Ot,PostKillEvent:()=>Et,PostUpdateEvent:()=>Lt,PreCollisionEvent:()=>jt,PreDebugDrawEvent:()=>Mt,PreDrawEvent:()=>Dt,PreFrameEvent:()=>zt,PreKillEvent:()=>Tt,PreUpdateEvent:()=>Ft,Projection:()=>Mi,Promise:()=>so,PromiseState:()=>eo,QuadIndexBuffer:()=>Qe,Query:()=>gr,QueryManager:()=>_r,RadiusAroundActorStrategy:()=>tr,Random:()=>M,Raster:()=>Ct,Ray:()=>Li,RealisticSolver:()=>Cr,Rectangle:()=>ds,RemovedComponent:()=>ss,RemovedEntity:()=>cr,Repeat:()=>vs,RepeatForever:()=>ys,Resolution:()=>ri,Resource:()=>le,RotateBy:()=>Cs,RotateTo:()=>bs,RotationType:()=>gs,ScaleBy:()=>As,ScaleTo:()=>Ss,Scene:()=>Nr,Screen:()=>ni,ScreenAppender:()=>v,ScreenElement:()=>Ns,ScreenShader:()=>Hr,ScrollPreventionMode:()=>yn,Shader:()=>Ve,Shape:()=>Zi,Side:()=>T,SortedList:()=>Yn,Sound:()=>Wn,Sprite:()=>Ae,SpriteFont:()=>Ue,SpriteSheet:()=>Oe,StandardClock:()=>mn,StrategyContainer:()=>Ys,Stream:()=>qn,SubscribeEvent:()=>Gt,System:()=>ar,SystemManager:()=>fr,SystemType:()=>or,TagComponent:()=>Pi,TestClock:()=>vn,Text:()=>zs,TextAlign:()=>De,TextureLoader:()=>bt,TileMap:()=>js,Timer:()=>Ws,Traits:()=>h,TransformComponent:()=>Ei,TreeNode:()=>ki,Trigger:()=>nr,TwoPI:()=>k,UnsubscribeEvent:()=>Vt,Util:()=>l,Vector:()=>A,VectorView:()=>Si,VertexBuffer:()=>Xe,VertexLayout:()=>qe,VisibleEvent:()=>Xt,WebAudio:()=>ai,WebAudioInstance:()=>Nn,World:()=>mr,canonicalizeAngle:()=>O,clamp:()=>z,createId:()=>_,frac:()=>F,hasGraphicsTick:()=>as,hasOnInitialize:()=>Mn,hasOnPostUpdate:()=>zn,hasOnPreUpdate:()=>Fn,hasPostDraw:()=>Un,hasPreDraw:()=>On,has_initialize:()=>Bn,has_postupdate:()=>Ln,has_preupdate:()=>kn,isAddedComponent:()=>is,isAddedSystemEntity:()=>lr,isRemoveSystemEntity:()=>dr,isRemovedComponent:()=>rs,maxMessages:()=>y,obsolete:()=>C,randomInRange:()=>W,randomIntInRange:()=>G,range:()=>H,resetObsoleteCounter:()=>x,sign:()=>L,toDegrees:()=>U,toRadians:()=>N,vec:()=>P,webgl:()=>t});var t={};i.r(t),i.d(t,{ensurePowerOfTwo:()=>vt,getAttributeComponentSize:()=>wt,getAttributePointerType:()=>xt,getGlTypeSizeBytes:()=>yt,isPowerOfTwo:()=>ft,nextHighestPowerOfTwo:()=>mt});var e={};i.r(e),i.d(e,{ActivateEvent:()=>ie,CollisionEndEvent:()=>te,CollisionPostSolveEvent:()=>$t,CollisionPreSolveEvent:()=>Qt,CollisionStartEvent:()=>Jt,ContactEndEvent:()=>Yt,ContactStartEvent:()=>Zt,DeactivateEvent:()=>se,EnterTriggerEvent:()=>oe,EnterViewPortEvent:()=>ne,EventTypes:()=>lt,ExitTriggerEvent:()=>ae,ExitViewPortEvent:()=>re,GameEvent:()=>At,GameStartEvent:()=>It,GameStopEvent:()=>Rt,GamepadAxisEvent:()=>Wt,GamepadButtonEvent:()=>Ht,GamepadConnectEvent:()=>Ut,GamepadDisconnectEvent:()=>Nt,HiddenEvent:()=>qt,InitializeEvent:()=>ee,KillEvent:()=>Pt,PostCollisionEvent:()=>Kt,PostDebugDrawEvent:()=>kt,PostDrawEvent:()=>Bt,PostFrameEvent:()=>Ot,PostKillEvent:()=>Et,PostUpdateEvent:()=>Lt,PreCollisionEvent:()=>jt,PreDebugDrawEvent:()=>Mt,PreDrawEvent:()=>Dt,PreFrameEvent:()=>zt,PreKillEvent:()=>Tt,PreUpdateEvent:()=>Ft,SubscribeEvent:()=>Gt,UnsubscribeEvent:()=>Vt,VisibleEvent:()=>Xt});var r={};i.r(r),i.d(r,{Colorize:()=>ge,Darken:()=>fe,Desaturate:()=>ve,Fill:()=>ye,Grayscale:()=>de,Invert:()=>ue,Lighten:()=>_e,Opacity:()=>pe,Saturate:()=>me});var n={};i.r(n),i.d(n,{circle:()=>pi,line:()=>li,point:()=>ci,roundRect:()=>ui,vector:()=>di});var o={};i.r(o),i.d(o,{Animation:()=>Ie,CanvasDrawComponent:()=>os,CanvasDrawingSystem:()=>kr,Effects:()=>r,Polygon:()=>Rn,Sprite:()=>Se,SpriteFont:()=>ze,SpriteSheet:()=>Le,Texture:()=>we});var a={};i.r(a),i.d(a,{Axes:()=>Yr,Buttons:()=>Zr,Gamepad:()=>nn,Gamepads:()=>rn,KeyEvent:()=>en,Keyboard:()=>sn,Keys:()=>Kr,NativePointerButton:()=>$r,PointerButton:()=>Jr,PointerComponent:()=>ps,PointerEvent:()=>dn,PointerEventReceiver:()=>gn,PointerScope:()=>jr,PointerSystem:()=>Lr,PointerType:()=>tn,WheelDeltaMode:()=>Qr,WheelEvent:()=>un});var h={};i.r(h),i.d(h,{OffscreenCulling:()=>ts});var l={};i.r(l),i.d(l,{Collection:()=>rt,ConsoleAppender:()=>m,DrawUtil:()=>n,EasingFunctions:()=>fs,LogLevel:()=>u,Logger:()=>f,Observable:()=>Di,ScreenAppender:()=>v,TwoPI:()=>V,addItemToArray:()=>J,canonicalizeAngle:()=>K,clamp:()=>X,contains:()=>et,delay:()=>ot,fail:()=>nt,getOppositeSide:()=>it,getPosition:()=>$,getSideFromDirection:()=>st,randomInRange:()=>q,randomIntInRange:()=>j,range:()=>Q,removeItemFromArray:()=>tt,toDegrees:()=>Z,toRadians:()=>Y});var c,d,u;i(4662),i(8343);function p(){if("undefined"==typeof window&&(window={audioContext:function(){}}),"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setInterval(t,1e3/60)}),"undefined"==typeof window||window.cancelAnimationFrame||(window.cancelAnimationFrame=window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||function(){}),"undefined"!=typeof window&&!window.AudioContext){if(window.webkitAudioContext){const t=window.webkitAudioContext.prototype.decodeAudioData;window.webkitAudioContext.prototype.decodeAudioData=function(e){return new Promise(((i,s)=>{t.call(this,e,i,s)}))}}window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext||window.oAudioContext}"undefined"==typeof window||window.devicePixelRatio||(window.devicePixelRatio=window.devicePixelRatio||1)}!function(t){t.WebGL="use-webgl"}(c||(c={})),function(t){t.Canvas="use-canvas-context",t.LegacyDrawing="use-legacy-drawing"}(d||(d={}));class g{static freeze(){g._FROZEN=!0}static _reset(){g._FROZEN=!1,g._FLAGS={}}static useWebGL(){g.enable(c.WebGL)}static useCanvasGraphicsContext(){g.enable(d.Canvas)}static useLegacyDrawing(){g.enable(d.LegacyDrawing)}static enable(t){if(this._FROZEN)throw Error("Feature flags can only be enabled before Engine constructor time");g._FLAGS[t]=!0}static disable(t){if(this._FROZEN)throw Error("Feature flags can only be disabled before Engine constructor time");g._FLAGS[t]=!1}static isEnabled(t){return!!g._FLAGS[t]}static show(){return Object.keys(g._FLAGS)}}function _(t,e){return{type:t,value:e}}g._FROZEN=!1,g._FLAGS={},function(t){t[t.Debug=0]="Debug",t[t.Info=1]="Info",t[t.Warn=2]="Warn",t[t.Error=3]="Error",t[t.Fatal=4]="Fatal"}(u||(u={}));class f{constructor(){if(this._appenders=[],this.defaultLevel=u.Info,f._INSTANCE)throw new Error("Logger is a singleton");return f._INSTANCE=this,f._INSTANCE.addAppender(new m),f._INSTANCE}static getInstance(){return null==f._INSTANCE&&(f._INSTANCE=new f),f._INSTANCE}addAppender(t){this._appenders.push(t)}clearAppenders(){this._appenders.length=0}_log(t,e){null==t&&(t=this.defaultLevel);const i=this._appenders.length;for(let s=0;s<i;s++)t>=this.defaultLevel&&this._appenders[s].log(t,e)}debug(...t){this._log(u.Debug,t)}info(...t){this._log(u.Info,t)}warn(...t){this._log(u.Warn,t)}error(...t){this._log(u.Error,t)}fatal(...t){this._log(u.Fatal,t)}}f._INSTANCE=null;class m{log(t,e){if(!console&&!console.log&&console.warn&&console.error)return;const i=[];i.unshift.apply(i,e),i.unshift("["+u[t]+"] : "),t<u.Warn?console.log.apply?console.log.apply(console,i):console.log(i.join(" ")):t<u.Error?console.warn.apply?console.warn.apply(console,i):console.warn(i.join(" ")):console.error.apply?console.error.apply(console,i):console.error(i.join(" "))}}class v{constructor(t,e){this._messages=[],this._canvas=document.createElement("canvas"),this._canvas.width=t||window.innerWidth,this._canvas.height=e||window.innerHeight,this._canvas.style.position="absolute",this._ctx=this._canvas.getContext("2d"),document.body.appendChild(this._canvas)}log(t,e){const i=e.join(",");this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._messages.unshift("["+u[t]+"] : "+i);let s=10,r=1;for(let t=0;t<this._messages.length;t++)this._ctx.fillStyle="rgba(255,255,255,"+r.toFixed(2)+")",this._ctx.fillText(this._messages[t],200,s),s+=10,r=r>0?r-.05:0}}const y=5,w={},x=()=>{for(const t in w)w[t]=0},b=(t,e)=>{const i=g.isEnabled("suppress-obsolete-message");w[t]<y&&!i&&(f.getInstance().warn(t),console.trace&&e.showStackTrace&&console.trace()),w[t]++};function C(t){return t={message:"This feature will be removed in future versions of Excalibur.",alternateMethod:null,showStackTrace:!1,...t},function(e,i,s){if(s&&"function"!=typeof s.value&&"function"!=typeof s.get&&"function"!=typeof s.set)throw new SyntaxError("Only classes/functions/getters/setters can be marked as obsolete");const r=`${`${e.name||""}${e.name&&i?".":""}${i||""}`} is marked obsolete: ${t.message}`+(t.alternateMethod?` Use ${t.alternateMethod} instead`:"");w[r]||(w[r]=0);const n=s?{...s}:e;if(!s){class e extends n{constructor(...e){b(r,t),super(...e)}}return e}return s&&s.value?(n.value=function(){return b(r,t),s.value.apply(this,arguments)},n):(s&&s.get&&(n.get=function(){return b(r,t),s.get.apply(this,arguments)}),s&&s.set&&(n.set=function(){return b(r,t),s.set.apply(this,arguments)}),n)}}var S=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class A{constructor(t,e){this._x=0,this._y=0,this._x=t,this._y=e}static get Zero(){return new A(0,0)}static get One(){return new A(1,1)}static get Half(){return new A(.5,.5)}static get Up(){return new A(0,-1)}static get Down(){return new A(0,1)}static get Left(){return new A(-1,0)}static get Right(){return new A(1,0)}static fromAngle(t){return new A(Math.cos(t),Math.sin(t))}static isValid(t){return null!=t&&(!isNaN(t.x)&&!isNaN(t.y)&&(t.x!==1/0&&t.y!==1/0&&t.x!==-1/0&&t.y!==-1/0))}static distance(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}setTo(t,e){this.x=t,this.y=e}equals(t,e=.001){return Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e}distance(t){return t||(t=A.Zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))}squareDistance(t){return t||(t=A.Zero),Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2)}magnitude(){return this.distance()}get size(){return this.distance()}set size(t){const e=this.normalize().scale(t);this.setTo(e.x,e.y)}normalize(){const t=this.distance();return t>0?new A(this.x/t,this.y/t):new A(0,1)}average(t){return this.add(t).scale(.5)}scale(t){return t instanceof A?new A(this.x*t.x,this.y*t.y):new A(this.x*t,this.y*t)}add(t){return new A(this.x+t.x,this.y+t.y)}sub(t){return new A(this.x-t.x,this.y-t.y)}addEqual(t){return this.setTo(this.x+t.x,this.y+t.y),this}subEqual(t){return this.setTo(this.x-t.x,this.y-t.y),this}scaleEqual(t){return this.setTo(this.x*t,this.y*t),this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return t instanceof A?this.x*t.y-this.y*t.x:"number"==typeof t?new A(t*this.y,-t*this.x):void 0}static cross(t,e){return new A(-t*e.y,t*e.x)}perpendicular(){return new A(this.y,-this.x)}normal(){return this.perpendicular().normalize()}negate(){return this.scale(-1)}toAngle(){return Math.atan2(this.y,this.x)}rotate(t,e){e||(e=new A(0,0));const i=Math.sin(t),s=Math.cos(t),r=s*(this.x-e.x)-i*(this.y-e.y)+e.x,n=i*(this.x-e.x)+s*(this.y-e.y)+e.y;return new A(r,n)}clone(){return new A(this.x,this.y)}toString(t){return t?`(${this.x.toFixed(t)}, ${this.y.toFixed(t)})`:`(${this.x}, ${this.y})`}}function P(t,e){return new A(t,e)}S([C({message:"will be removed in favour of `.size` in version 0.25.0"})],A.prototype,"magnitude",null);var T,E=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class I{constructor(t,e,i,s){this.r=t,this.g=e,this.b=i,this.a=null!=s?s:1}static fromRGB(t,e,i,s){return new I(t,e,i,s)}static fromRGBString(t){let e=null;if(e=t.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)/i)){const t=parseInt(e[1],10),i=parseInt(e[2],10),s=parseInt(e[3],10);let r=1;return e[4]&&(r=parseFloat(e[4])),new I(t,i,s,r)}throw new Error("Invalid rgb/a string: "+t)}static fromHex(t){let e=null;if(e=t.match(/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i)){const t=parseInt(e[1],16),i=parseInt(e[2],16),s=parseInt(e[3],16);let r=1;return e[4]&&(r=parseInt(e[4],16)/255),new I(t,i,s,r)}throw new Error("Invalid hex string: "+t)}static fromHSL(t,e,i,s=1){return new R(t,e,i,s).toRGBA()}lighten(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.l+=(1-e.l)*t,e.toRGBA()}darken(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.l-=e.l*t,e.toRGBA()}saturate(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.s+=e.s*t,e.toRGBA()}desaturate(t=.1){const e=R.fromRGBA(this.r,this.g,this.b,this.a);return e.s-=e.s*t,e.toRGBA()}multiply(t){const e=t.r/255*this.r/255*255,i=t.g/255*this.g/255*255,s=t.b/255*this.b/255*255,r=t.a*this.a;return new I(e,i,s,r)}mulitiply(t){return this.multiply(t)}screen(t){const e=t.invert(),i=t.invert();return e.multiply(i).invert()}invert(){return new I(255-this.r,255-this.g,255-this.b,1-this.a)}average(t){const e=(t.r+this.r)/2,i=(t.g+this.g)/2,s=(t.b+this.b)/2,r=(t.a+this.a)/2;return new I(e,i,s,r)}equal(t){return this.toString()===t.toString()}toString(t="rgb"){switch(t){case"rgb":return this.toRGBA();case"hsl":return this.toHSLA();case"hex":return this.toHex();default:throw new Error("Invalid Color format")}}_componentToHex(t){const e=t.toString(16);return 1===e.length?"0"+e:e}toHex(){return"#"+this._componentToHex(this.r)+this._componentToHex(this.g)+this._componentToHex(this.b)}toRGBA(){const t=String(this.r.toFixed(0))+", "+String(this.g.toFixed(0))+", "+String(this.b.toFixed(0));return void 0!==this.a||null!==this.a?"rgba("+t+", "+String(this.a)+")":"rgb("+t+")"}toHSLA(){return R.fromRGBA(this.r,this.g,this.b,this.a).toString()}fillStyle(){return this.toString()}clone(){return new I(this.r,this.g,this.b,this.a)}static get Black(){return I.fromHex("#000000")}static get White(){return I.fromHex("#FFFFFF")}static get Gray(){return I.fromHex("#808080")}static get LightGray(){return I.fromHex("#D3D3D3")}static get DarkGray(){return I.fromHex("#A9A9A9")}static get Yellow(){return I.fromHex("#FFFF00")}static get Orange(){return I.fromHex("#FFA500")}static get Red(){return I.fromHex("#FF0000")}static get Vermilion(){return I.fromHex("#FF5B31")}static get Vermillion(){return I.Vermilion}static get Rose(){return I.fromHex("#FF007F")}static get Magenta(){return I.fromHex("#FF00FF")}static get Violet(){return I.fromHex("#7F00FF")}static get Blue(){return I.fromHex("#0000FF")}static get Azure(){return I.fromHex("#007FFF")}static get Cyan(){return I.fromHex("#00FFFF")}static get Viridian(){return I.fromHex("#59978F")}static get Green(){return I.fromHex("#00FF00")}static get Chartreuse(){return I.fromHex("#7FFF00")}static get Transparent(){return I.fromHex("#FFFFFF00")}static get ExcaliburBlue(){return I.fromHex("#176BAA")}}E([C({message:"Alias for incorrect spelling used in older versions, use multiply instead, will be removed in v0.25.0"})],I.prototype,"mulitiply",null),E([C({message:"Alias for incorrect spelling used in older versions",alternateMethod:"Vermilion"})],I,"Vermillion",null);class R{constructor(t,e,i,s){this.h=t,this.s=e,this.l=i,this.a=s}static hue2rgb(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}static fromRGBA(t,e,i,s){t/=255,e/=255,i/=255;const r=Math.max(t,e,i),n=Math.min(t,e,i);let o,a;const h=(r+n)/2;if(r===n)o=a=0;else{const s=r-n;switch(a=h>.5?s/(2-r-n):s/(r+n),r){case t:o=(e-i)/s+(e<i?6:0);break;case e:o=(i-t)/s+2;break;case i:o=(t-e)/s+4}o/=6}return new R(o,a,h,s)}toRGBA(){let t,e,i;if(0===this.s)t=e=i=this.l;else{const s=this.l<.5?this.l*(1+this.s):this.l+this.s-this.l*this.s,r=2*this.l-s;t=R.hue2rgb(r,s,this.h+1/3),e=R.hue2rgb(r,s,this.h),i=R.hue2rgb(r,s,this.h-1/3)}return new I(255*t,255*e,255*i,this.a)}toString(){return`hsla(${this.h.toFixed(0)}, ${this.s.toFixed(0)}, ${this.l.toFixed(0)}, ${this.a.toFixed(0)})`}}!function(t){t.None="None",t.Top="Top",t.Bottom="Bottom",t.Left="Left",t.Right="Right"}(T||(T={})),function(t){t.getOpposite=function(e){return e===t.Top?t.Bottom:e===t.Bottom?t.Top:e===t.Left?t.Right:e===t.Right?t.Left:t.None},t.fromDirection=function(e){const i=[A.Left,A.Right,A.Up,A.Down],s=[t.Left,t.Right,t.Top,t.Bottom];let r=-Number.MAX_VALUE,n=-1;for(let t=0;t<i.length;t++)i[t].dot(e)>r&&(r=i[t].dot(e),n=t);return s[n]}}(T||(T={}));class D{constructor(t=0,e=0,i=0,s=0){"object"==typeof t?(this.left=t.left,this.top=t.top,this.right=t.right,this.bottom=t.bottom):"number"==typeof t&&(this.left=t,this.top=e,this.right=i,this.bottom=s)}static getSideFromIntersection(t){return t&&t?Math.abs(t.x)>Math.abs(t.y)?t.x<0?T.Right:T.Left:t.y<0?T.Bottom:T.Top:T.None}static fromPoints(t){let e=1/0,i=1/0,s=-1/0,r=-1/0;for(let n=0;n<t.length;n++)t[n].x<e&&(e=t[n].x),t[n].x>s&&(s=t[n].x),t[n].y<i&&(i=t[n].y),t[n].y>r&&(r=t[n].y);return new D(e,i,s,r)}static fromDimension(t,e,i=A.Half,s=A.Zero){return new D(-t*i.x+s.x,-e*i.y+s.y,t-t*i.x+s.x,e-e*i.y+s.y)}get width(){return this.right-this.left}get height(){return this.bottom-this.top}hasZeroDimensions(){return 0===this.width||0===this.height}get center(){return new A((this.left+this.right)/2,(this.top+this.bottom)/2)}translate(t){return new D(this.left+t.x,this.top+t.y,this.right+t.x,this.bottom+t.y)}rotate(t,e=A.Zero){const i=this.getPoints().map((i=>i.rotate(t,e)));return D.fromPoints(i)}scale(t,e=A.Zero){const i=this.translate(e);return new D(i.left*t.x,i.top*t.y,i.right*t.x,i.bottom*t.y)}transform(t){const e=this.getPoints().map((e=>t.multv(e)));return D.fromPoints(e)}getPerimeter(){return 2*(this.width+this.height)}getPoints(){const t=[];return t.push(new A(this.left,this.top)),t.push(new A(this.right,this.top)),t.push(new A(this.right,this.bottom)),t.push(new A(this.left,this.bottom)),t}rayCast(t,e=1/0){let i=-1/0,s=1/0;const r=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,n=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*r,a=(this.right-t.pos.x)*r;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*n,l=(this.bottom-t.pos.y)*n;return i=Math.max(i,Math.min(h,l)),s=Math.min(s,Math.max(h,l)),s>=Math.max(0,i)&&i<e}rayCastTime(t,e=1/0){let i=-1/0,s=1/0;const r=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,n=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*r,a=(this.right-t.pos.x)*r;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*n,l=(this.bottom-t.pos.y)*n;return i=Math.max(i,Math.min(h,l)),s=Math.min(s,Math.max(h,l)),s>=Math.max(0,i)&&i<e?i:-1}contains(t){return t instanceof A?this.left<=t.x&&this.top<=t.y&&this.bottom>=t.y&&this.right>=t.x:t instanceof D&&(this.left<t.left&&this.top<t.top&&t.bottom<this.bottom&&t.right<this.right)}combine(t){return new D(Math.min(this.left,t.left),Math.min(this.top,t.top),Math.max(this.right,t.right),Math.max(this.bottom,t.bottom))}get dimensions(){return new A(this.width,this.height)}intersect(t){const e=this.combine(t);if(e.width<t.width+this.width&&e.height<t.height+this.height&&!e.dimensions.equals(t.dimensions)&&!e.dimensions.equals(this.dimensions)){let e=0;e=this.right>=t.left&&this.right<=t.right?t.left-this.right:t.right-this.left;let i=0;return i=this.top<=t.bottom&&this.top>=t.top?t.bottom-this.top:t.top-this.bottom,Math.abs(e)<Math.abs(i)?new A(e,0):new A(0,i)}if(e.dimensions.equals(t.dimensions)||e.dimensions.equals(this.dimensions)){let e=0;e=this.width-t.width>=0?this.right-t.right<=t.left-this.left?t.left-this.right:t.right-this.left:t.right-this.right<=this.left-t.left?this.left-t.right:this.right-t.left;let i=0;return i=this.height-t.height>=0?this.bottom-t.bottom<=t.top-this.top?t.top-this.bottom:t.bottom-this.top:t.bottom-this.bottom<=this.top-t.top?this.top-t.bottom:this.bottom-t.top,Math.abs(e)<Math.abs(i)?new A(e,0):new A(0,i)}return null}intersectWithSide(t){const e=this.intersect(t);return D.getSideFromIntersection(e)}debugDraw(t,e=I.Yellow){t.strokeStyle=e.toString(),t.strokeRect(this.left,this.top,this.width,this.height)}draw(t,e=I.Yellow){t.debug.drawRect(this.left,this.top,this.width,this.height,{color:e})}}const B=4294967295;class M{constructor(t){this.seed=t,this._lowerMask=2147483647,this._upperMask=2147483648,this._w=32,this._n=624,this._m=397,this._a=2567483615,this._u=11,this._s=7,this._b=2636928640,this._t=15,this._c=4022730752,this._l=18,this._f=1812433253,this._mt=new Array(this._n),this._mt[0]=(t||Date.now())>>>0;for(let t=1;t<this._n;t++){const e=this._mt[t-1]^this._mt[t-1]>>>this._w-2;this._mt[t]=(this._f*((4294901760&e)>>>16)<<16)+this._f*(65535&e)+t>>>0}this._index=this._n}_twist(){const t=[0,this._a];let e=0,i=0;for(;i<this._n-this._m;i++)e=this._mt[i]&this._upperMask|this._mt[i+1]&this._lowerMask,this._mt[i]=this._mt[i+this._m]^e>>>1^t[1&e]&B;for(;i<this._n-1;i++)e=this._mt[i]&this._upperMask|this._mt[i+1]&this._lowerMask,this._mt[i]=this._mt[i+(this._m-this._n)]^e>>>1^t[1&e]&B;e=this._mt[this._n-1]&this._upperMask|this._mt[0]&this._lowerMask,this._mt[this._n-1]=this._mt[this._m-1]^e>>>1^t[1&e]&B,this._index=0}nextInt(){this._index>=this._n&&this._twist();let t=this._mt[this._index++];return t^=t>>>this._u,t^=t<<this._s&this._b,t^=t<<this._t&this._c,t^=t>>>this._l,t>>>0}next(){return this.nextInt()*(1/4294967296)}floating(t,e){return(e-t)*this.next()+t}integer(t,e){return Math.floor((e-t+1)*this.next()+t)}bool(t=.5){return this.next()<=t}pickOne(t){return t[this.integer(0,t.length-1)]}pickSet(t,e,i=!1){return i?this._pickSetWithDuplicates(t,e):this._pickSetWithoutDuplicates(t,e)}_pickSetWithoutDuplicates(t,e){if(e>t.length||e<0)throw new Error("Invalid number of elements to pick, must pick a value 0 < n <= length");if(e===t.length)return t;const i=new Array(e);let s=0;const r=t.slice(0);for(;s<e;){const t=this.integer(0,r.length-1);i[s++]=r[t],r.splice(t,1)}return i}_pickSetWithDuplicates(t,e){if(e<0)throw new Error("Invalid number of elements to pick, must pick a value 0 <= n < MAX_INT");const i=new Array(e);for(let s=0;s<e;s++)i[s]=this.pickOne(t);return i}shuffle(t){const e=t.slice(0);let i=null;for(let t=0;t<e.length-2;t++){const s=this.integer(t,e.length-1);i=e[t],e[t]=e[s],e[s]=i}return e}range(t,e,i){const s=new Array(t);for(let r=0;r<t;r++)s[r]=this.integer(e,i);return s}d4(){return this.integer(1,4)}d6(){return this.integer(1,6)}d8(){return this.integer(1,8)}d10(){return this.integer(1,10)}d12(){return this.integer(1,12)}d20(){return this.integer(1,20)}}const k=2*Math.PI;function F(t){return t>=0?t-Math.floor(t):t-Math.ceil(t)}function L(t){return 0===t?0:t<0?-1:1}function z(t,e,i){return Math.min(Math.max(e,t),i)}function O(t){let e=t;if(t>k)for(;e>k;)e-=k;if(t<0)for(;e<0;)e+=k;return e}function U(t){return 180/Math.PI*t}function N(t){return t/180*Math.PI}const H=(t,e)=>Array.from(new Array(e-t+1),((e,i)=>i+t));function W(t,e,i=new M){return i?i.floating(t,e):t+Math.random()*(e-t)}function G(t,e,i=new M){return i?i.integer(t,e):Math.round(W(t,e))}const V=k,X=z,q=W,j=G,K=O,Z=U,Y=N,Q=H;function $(t){let e=0,i=0;const s=t=>{e+=t.offsetLeft,t.offsetParent&&s(t.offsetParent)},r=t=>{i+=t.offsetTop,t.offsetParent&&r(t.offsetParent)};return s(t),r(t),new A(e,i)}function J(t,e){return-1===e.indexOf(t)&&(e.push(t),!0)}function tt(t,e){let i=-1;return(i=e.indexOf(t))>-1&&(e.splice(i,1),!0)}function et(t,e){for(let i=0;i<t.length;i++)if(t[i]===e)return!0;return!1}function it(t){return t===T.Top?T.Bottom:t===T.Bottom?T.Top:t===T.Left?T.Right:t===T.Right?T.Left:T.None}function st(t){const e=[A.Left,A.Right,A.Up,A.Down],i=[T.Left,T.Right,T.Top,T.Bottom];let s=-Number.MAX_VALUE,r=-1;for(let i=0;i<e.length;i++)e[i].dot(t)>s&&(s=e[i].dot(t),r=i);return i[r]}class rt{constructor(t=rt.DefaultSize){this._internalArray=null,this._endPointer=0,this._internalArray=new Array(t)}_resize(){const t=2*this._internalArray.length,e=new Array(t),i=this.count();for(let t=0;t<i;t++)e[t]=this._internalArray[t];delete this._internalArray,this._internalArray=e}push(t){return this._endPointer===this._internalArray.length&&this._resize(),this._internalArray[this._endPointer++]=t}pop(){return this._endPointer=this._endPointer-1<0?0:this._endPointer-1,this._internalArray[this._endPointer]}count(){return this._endPointer}clear(){this._endPointer=0}internalSize(){return this._internalArray.length}elementAt(t){if(t>=this.count())throw new Error("Invalid index "+t);return this._internalArray[t]}insert(t,e){return t>=this.count()&&this._resize(),this._internalArray[t]=e}remove(t){const e=this.count();if(0===e)throw new Error("Invalid parameter "+t);const i=this._internalArray[t];for(let i=t;i<e;i++)this._internalArray[i]=this._internalArray[i+1];return this._endPointer--,i}removeElement(t){const e=this._internalArray.indexOf(t);this.remove(e)}toArray(){return this._internalArray.slice(0,this._endPointer)}forEach(t){let e=0;const i=this.count();for(;e<i;e++)t.call(this,this._internalArray[e],e)}map(t){const e=this.count();for(let i=0;i<e;i++)this._internalArray[i]=t.call(this,this._internalArray[i],i)}}function nt(t){throw new Error(t)}function ot(t,e){var i;const s=null!==(i=null==e?void 0:e.schedule.bind(e))&&void 0!==i?i:setTimeout;return new Promise((e=>{s((()=>{e()}),t)}))}var at,ht,lt;rt.DefaultSize=200,function(t){t[t.X=12]="X",t[t.Y=13]="Y"}(at||(at={}));class ct{constructor(){this.data=new Float32Array(16),this._scaleSignX=1,this._scaleSignY=1}static ortho(t,e,i,s,r,n){const o=new ct;return o.data[0]=2/(e-t),o.data[1]=0,o.data[2]=0,o.data[3]=0,o.data[4]=0,o.data[5]=2/(s-i),o.data[6]=0,o.data[7]=0,o.data[8]=0,o.data[9]=0,o.data[10]=-2/(n-r),o.data[11]=0,o.data[12]=-(e+t)/(e-t),o.data[13]=-(s+i)/(s-i),o.data[14]=-(n+r)/(n-r),o.data[15]=1,o}clone(){const t=new ct;return t.data[0]=this.data[0],t.data[1]=this.data[1],t.data[2]=this.data[2],t.data[3]=this.data[3],t.data[4]=this.data[4],t.data[5]=this.data[5],t.data[6]=this.data[6],t.data[7]=this.data[7],t.data[8]=this.data[8],t.data[9]=this.data[9],t.data[10]=this.data[10],t.data[11]=this.data[11],t.data[12]=this.data[12],t.data[13]=this.data[13],t.data[14]=this.data[14],t.data[15]=this.data[15],t}toDOMMatrix(){return new DOMMatrix([...this.data])}static identity(){const t=new ct;return t.data[0]=1,t.data[1]=0,t.data[2]=0,t.data[3]=0,t.data[4]=0,t.data[5]=1,t.data[6]=0,t.data[7]=0,t.data[8]=0,t.data[9]=0,t.data[10]=1,t.data[11]=0,t.data[12]=0,t.data[13]=0,t.data[14]=0,t.data[15]=1,t}reset(){const t=this;return t.data[0]=1,t.data[1]=0,t.data[2]=0,t.data[3]=0,t.data[4]=0,t.data[5]=1,t.data[6]=0,t.data[7]=0,t.data[8]=0,t.data[9]=0,t.data[10]=1,t.data[11]=0,t.data[12]=0,t.data[13]=0,t.data[14]=0,t.data[15]=1,t}static translation(t,e){const i=ct.identity();return i.data[12]=t,i.data[13]=e,i}static scale(t,e){const i=ct.identity();return i.data[0]=t,i.data[5]=e,i.data[10]=1,i.data[15]=1,i}static rotation(t){const e=ct.identity();return e.data[0]=Math.cos(t),e.data[4]=-Math.sin(t),e.data[1]=Math.sin(t),e.data[5]=Math.cos(t),e}multv(t){if(t instanceof A)return new A(t.x*this.data[0]+t.y*this.data[4]+0*this.data[6]+1*this.data[12],t.x*this.data[1]+t.y*this.data[5]+0*this.data[9]+1*this.data[13]);return[t[0]*this.data[0]+t[1]*this.data[4]+0*this.data[6]+1*this.data[12],t[0]*this.data[1]+t[1]*this.data[5]+0*this.data[9]+1*this.data[13]]}multm(t){const e=new ct,i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7],c=this.data[8],d=this.data[9],u=this.data[10],p=this.data[11],g=this.data[12],_=this.data[13],f=this.data[14],m=this.data[15],v=t.data[0],y=t.data[1],w=t.data[2],x=t.data[3],b=t.data[4],C=t.data[5],S=t.data[6],A=t.data[7],P=t.data[8],T=t.data[9],E=t.data[10],I=t.data[11],R=t.data[12],D=t.data[13],B=t.data[14],M=t.data[15];e.data[0]=i*v+o*y+c*w+g*x,e.data[1]=s*v+a*y+d*w+_*x,e.data[2]=r*v+h*y+u*w+f*x,e.data[3]=n*v+l*y+p*w+m*x,e.data[4]=i*b+o*C+c*S+g*A,e.data[5]=s*b+a*C+d*S+_*A,e.data[6]=r*b+h*C+u*S+f*A,e.data[7]=n*b+l*C+p*S+m*A,e.data[8]=i*P+o*T+c*E+g*I,e.data[9]=s*P+a*T+d*E+_*I,e.data[10]=r*P+h*T+u*E+f*I,e.data[11]=n*P+l*T+p*E+m*I,e.data[12]=i*R+o*D+c*B+g*M,e.data[13]=s*R+a*D+d*B+_*M,e.data[14]=r*R+h*D+u*B+f*M,e.data[15]=n*R+l*D+p*B+m*M;const k=this.getScale();return e._scaleSignX=L(k.x)*L(e._scaleSignX),e._scaleSignY=L(k.y)*L(e._scaleSignY),e}translate(t,e){const i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7],c=this.data[8],d=this.data[9],u=this.data[10],p=this.data[11],g=this.data[12],_=this.data[13],f=this.data[14],m=this.data[15];return this.data[12]=i*t+o*e+0*c+1*g,this.data[13]=s*t+a*e+0*d+1*_,this.data[14]=r*t+h*e+0*u+1*f,this.data[15]=n*t+l*e+0*p+1*m,this}setPosition(t,e){this.data[12]=t,this.data[13]=e}getPosition(){return P(this.data[12],this.data[13])}rotate(t){const e=this.data[0],i=this.data[1],s=this.data[2],r=this.data[3],n=this.data[4],o=this.data[5],a=this.data[6],h=this.data[7],l=Math.sin(t),c=Math.cos(t);return this.data[0]=c*e+l*n,this.data[1]=c*i+l*o,this.data[2]=c*s+l*a,this.data[3]=c*r+l*h,this.data[4]=c*n-l*e,this.data[5]=c*o-l*i,this.data[6]=c*a-l*s,this.data[7]=c*h-l*r,this}scale(t,e){const i=this.data[0],s=this.data[1],r=this.data[2],n=this.data[3],o=this.data[4],a=this.data[5],h=this.data[6],l=this.data[7];return this.data[0]=i*t,this.data[1]=s*t,this.data[2]=r*t,this.data[3]=n*t,this.data[4]=o*e,this.data[5]=a*e,this.data[6]=h*e,this.data[7]=l*e,this}setRotation(t){const e=this.getScale(),i=Math.sin(t),s=Math.cos(t);this.data[0]=s*e.x,this.data[1]=i*e.y,this.data[4]=-i*e.x,this.data[5]=s*e.y}getRotation(){return O(Math.atan2(this.data[1]/this.getScaleY(),this.data[0]/this.getScaleX()))}getScaleX(){const t=P(this.data[0],this.data[4]).size;return this._scaleSignX*t}getScaleY(){const t=P(this.data[1],this.data[5]).size;return this._scaleSignY*t}getScale(){return P(this.getScaleX(),this.getScaleY())}setScaleX(t){this._scaleSignX=L(t);const e=P(this.data[0]*this._scaleSignX,this.data[4]*this._scaleSignX).normalize();this.data[0]=e.x*t,this.data[4]=e.y*t}setScaleY(t){this._scaleSignY=L(t);const e=P(this.data[1]*this._scaleSignY,this.data[5]*this._scaleSignY).normalize();this.data[1]=e.x*t,this.data[5]=e.y*t}setScale(t){this.setScaleX(t.x),this.setScaleY(t.y)}getBasisDeterminant(){return this.data[0]*this.data[5]-this.data[1]*this.data[4]}getAffineInverse(t){const e=1/this.getBasisDeterminant(),i=this.data[0],s=this.data[4],r=this.data[1],n=this.data[5],o=t||ct.identity();o.data[0]=n*e,o.data[1]=-r*e,o.data[4]=-s*e,o.data[5]=i*e;const a=this.data[12],h=this.data[13];return o.data[12]=-(a*o.data[0]+h*o.data[4]),o.data[13]=-(a*o.data[1]+h*o.data[5]),o}isIdentity(){return 1===this.data[0]&&0===this.data[1]&&0===this.data[2]&&0===this.data[3]&&0===this.data[4]&&1===this.data[5]&&0===this.data[6]&&0===this.data[7]&&0===this.data[8]&&0===this.data[9]&&1===this.data[10]&&0===this.data[11]&&0===this.data[12]&&0===this.data[13]&&0===this.data[14]&&1===this.data[15]}toString(){return`\n[${this.data[0]} ${this.data[4]} ${this.data[8]} ${this.data[12]}]\n[${this.data[1]} ${this.data[5]} ${this.data[9]} ${this.data[13]}]\n[${this.data[2]} ${this.data[6]} ${this.data[10]} ${this.data[14]}]\n[${this.data[3]} ${this.data[7]} ${this.data[11]} ${this.data[15]}]\n`}}class dt{constructor(){this._transforms=[],this._currentTransform=ct.identity()}save(){this._transforms.push(this._currentTransform),this._currentTransform=this._currentTransform.clone()}restore(){this._currentTransform=this._transforms.pop()}translate(t,e){return this._currentTransform.translate(t,e)}rotate(t){return this._currentTransform.rotate(t)}scale(t,e){return this._currentTransform.scale(t,e)}set current(t){this._currentTransform=t}get current(){return this._currentTransform}}class ut{constructor(){this._states=[],this._currentState=this._getDefaultState()}_getDefaultState(){return{opacity:1}}_cloneState(){return{opacity:this._currentState.opacity}}save(){this._states.push(this._currentState),this._currentState=this._cloneState()}restore(){this._currentState=this._states.pop()}get current(){return this._currentState}}function pt(t,e){return t&&void 0===t.__isProxy?new Proxy(t,{set:(t,i,s)=>(t[i]!==s&&(t[i]=s,"string"==typeof i&&"_"!==i[0]&&e(t)),!0),get:(t,e)=>"__isProxy"===e||t[e]}):t}function gt(t,e){return t&&void 0===t.__isProxy?new Proxy(t,{set:(t,i,s)=>(t[i]=s,"string"==typeof i&&"_"!==i[0]&&e(t),!0),get:(t,e)=>"__isProxy"===e||t[e]}):t}class _t{constructor(t){var e,i,s,r,n,o;this.id=_t._ID++,this.transform=ct.identity(),this._transformStale=!0,this.showDebug=!1,this._flipHorizontal=!1,this._flipVertical=!1,this._rotation=0,this.opacity=1,this._scale=A.One,this._origin=null,this._width=0,this._height=0,t&&(this.origin=null!==(e=t.origin)&&void 0!==e?e:this.origin,this.flipHorizontal=null!==(i=t.flipHorizontal)&&void 0!==i?i:this.flipHorizontal,this.flipVertical=null!==(s=t.flipVertical)&&void 0!==s?s:this.flipVertical,this.rotation=null!==(r=t.rotation)&&void 0!==r?r:this.rotation,this.opacity=null!==(n=t.opacity)&&void 0!==n?n:this.opacity,this.scale=null!==(o=t.scale)&&void 0!==o?o:this.scale)}isStale(){return this._transformStale}get flipHorizontal(){return this._flipHorizontal}set flipHorizontal(t){this._flipHorizontal=t,this._transformStale=!0}get flipVertical(){return this._flipVertical}set flipVertical(t){this._flipVertical=t,this._transformStale=!0}get rotation(){return this._rotation}set rotation(t){this._rotation=t,this._transformStale=!0}get scale(){return this._scale}set scale(t){this._scale=pt(t,(()=>{this._transformStale=!0})),this._transformStale=!0}get origin(){return this._origin}set origin(t){this._origin=pt(t,(()=>{this._transformStale=!0})),this._transformStale=!0}cloneGraphicOptions(){return{origin:this.origin?this.origin.clone():null,flipHorizontal:this.flipHorizontal,flipVertical:this.flipVertical,rotation:this.rotation,opacity:this.opacity,scale:this.scale?this.scale.clone():null}}get width(){return Math.abs(this._width*this.scale.x)}get height(){return Math.abs(this._height*this.scale.y)}set width(t){this._width=t,this._transformStale=!0}set height(t){this._height=t,this._transformStale=!0}get localBounds(){return D.fromDimension(this.width,this.height,A.Zero)}draw(t,e,i){this._preDraw(t,e,i),this._drawImage(t,0,0),this._postDraw(t)}_preDraw(t,e,i){t.save(),t.translate(e,i),this._transformStale&&(this.transform.reset(),this.transform.scale(Math.abs(this.scale.x),Math.abs(this.scale.y)),this._rotate(this.transform),this._flip(this.transform),this._transformStale=!1),t.multiply(this.transform),t.opacity=t.opacity*this.opacity}_rotate(t){var e;const i=this.scale.x>0?1:-1,s=this.scale.y>0?1:-1,r=null!==(e=this.origin)&&void 0!==e?e:P(this.width/2,this.height/2);t.translate(r.x,r.y),t.rotate(this.rotation),t.scale(i,s),t.translate(-r.x,-r.y)}_flip(t){this.flipHorizontal&&(t.translate(this.width/this.scale.x,0),t.scale(-1,1)),this.flipVertical&&(t.translate(0,this.height/this.scale.y),t.scale(1,-1))}_postDraw(t){this.showDebug&&t.debug.drawRect(0,0,this.width,this.height),t.restore()}}function ft(t){return 0==(t&t-1)}function mt(t){--t;for(let e=1;e<32;e<<=1)t|=t>>e;return t+1}function vt(t){return ft(t)?t:mt(t)}function yt(t,e){switch(e){case t.FLOAT:return 4;case t.SHORT:case t.UNSIGNED_SHORT:return 2;case t.BYTE:case t.UNSIGNED_BYTE:default:return 1}}function wt(t,e){switch(e){case t.LOW_FLOAT:case t.HIGH_FLOAT:case t.FLOAT:return 1;case t.FLOAT_VEC2:return 2;case t.FLOAT_VEC3:return 3;case t.FLOAT_VEC4:return 4;case t.BYTE:case t.UNSIGNED_BYTE:case t.UNSIGNED_SHORT:case t.SHORT:default:return 1}}function xt(t,e){switch(e){case t.LOW_FLOAT:case t.HIGH_FLOAT:case t.FLOAT:case t.FLOAT_VEC2:case t.FLOAT_VEC3:case t.FLOAT_VEC4:return t.FLOAT;case t.BYTE:return t.BYTE;case t.UNSIGNED_BYTE:return t.UNSIGNED_BYTE;case t.SHORT:return t.SHORT;case t.UNSIGNED_SHORT:return t.UNSIGNED_SHORT;default:return t.FLOAT}}_t._ID=0,function(t){t.Pixel="Pixel",t.Blended="Blended"}(ht||(ht={}));class bt{static register(t){bt._GL=t,bt._MAX_TEXTURE_SIZE=t.getParameter(t.MAX_TEXTURE_SIZE)}static get(t){return bt._TEXTURE_MAP.get(t)}static has(t){return bt._TEXTURE_MAP.has(t)}static load(t,e,i=!1){const s=bt._GL;if(!s)return null;let r=null;if(bt.has(t)&&(r=bt.get(t)),r){if(i){s.bindTexture(s.TEXTURE_2D,r);const e=bt.toPowerOfTwoImage(t);s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,e)}return r}r=s.createTexture();const n=bt.toPowerOfTwoImage(t);bt.checkImageSizeSupportedAndLog(t),s.bindTexture(s.TEXTURE_2D,r),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE);const o=null!=e?e:bt.filtering;return s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,o===ht.Pixel?s.NEAREST:s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,o===ht.Pixel?s.NEAREST:s.LINEAR),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,n),bt._TEXTURE_MAP.set(t,r),r}static toPowerOfTwoImage(t){const e=bt._POT_CANVAS,i=bt._POT_CTX;return ft(t.width)&&ft(t.height)||(e.width=vt(t.width),e.height=vt(t.height),i.imageSmoothingEnabled=!1,i.clearRect(0,0,e.width,e.height),i.drawImage(t,0,0,t.width,t.height),t=e),t}static checkImageSizeSupportedAndLog(t){var e;const i=null!==(e=t.dataset.originalSrc)&&void 0!==e?e:"internal canvas bitmap";return t.width>bt._MAX_TEXTURE_SIZE||t.height>bt._MAX_TEXTURE_SIZE?(bt._LOGGER.error(`The image [${i}] provided to Excalibur is too large for the device's maximum texture size of (${bt._MAX_TEXTURE_SIZE}x${bt._MAX_TEXTURE_SIZE}) please resize to an image for excalibur to render properly.\n\nImages will likely render as black rectangles.\n\nRead more here: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#understand_system_limits`),!1):((t.width>4096||t.height>4096)&&bt._LOGGER.warn(`The image [${i}] provided to excalibur is too large may not work on all mobile devices, it is recommended you resize images to a maximum (4096x4096).\n\nImages will likely render as black rectangles on some mobile platforms.\n\nRead more here: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#understand_system_limits`),!0)}}bt._LOGGER=f.getInstance(),bt.filtering=ht.Blended,bt._POT_CANVAS=document.createElement("canvas"),bt._POT_CTX=bt._POT_CANVAS.getContext("2d"),bt._TEXTURE_MAP=new Map,bt._MAX_TEXTURE_SIZE=0;class Ct extends _t{constructor(t){var e,i,s,r,n,o,a,h;super(t),this.filtering=null,this._dirty=!0,this._smoothing=!1,this._color=pt(I.Black,(()=>this.flagDirty())),this._lineWidth=1,this._lineDash=[],this._padding=0,t&&(this.color=null!==(e=t.color)&&void 0!==e?e:I.Black,this.strokeColor=null==t?void 0:t.strokeColor,this.smoothing=null!==(i=t.smoothing)&&void 0!==i?i:this.smoothing,this.lineWidth=null!==(s=t.lineWidth)&&void 0!==s?s:this.lineWidth,this.lineDash=null!==(r=t.lineDash)&&void 0!==r?r:this.lineDash,this.padding=null!==(n=t.padding)&&void 0!==n?n:this.padding,this.filtering=null!==(o=t.filtering)&&void 0!==o?o:this.filtering),this._bitmap=document.createElement("canvas");const l=null!==(a=null==t?void 0:t.width)&&void 0!==a?a:this._bitmap.width,c=null!==(h=null==t?void 0:t.height)&&void 0!==h?h:this._bitmap.height;this.width=vt(l),this.height=vt(c);const d=this._bitmap.getContext("2d");if(!d)throw new Error("Browser does not support 2d canvas drawing, cannot create Raster graphic");this._ctx=d}cloneRasterOptions(){return{color:this.color?this.color.clone():null,strokeColor:this.strokeColor?this.strokeColor.clone():null,smoothing:this.smoothing,lineWidth:this.lineWidth,lineDash:this.lineDash,padding:this.padding}}get dirty(){return this._dirty}flagDirty(){this._dirty=!0}get width(){return Math.abs(this._getTotalWidth()*this.scale.x)}set width(t){t/=Math.abs(this.scale.x),this._bitmap.width=t,this._originalWidth=t,this.flagDirty()}get height(){return Math.abs(this._getTotalHeight()*this.scale.y)}set height(t){t/=Math.abs(this.scale.y),this._bitmap.height=t,this._originalHeight=t,this.flagDirty()}_getTotalWidth(){var t;return(null!==(t=this._originalWidth)&&void 0!==t?t:this._bitmap.width)+2*this.padding}_getTotalHeight(){var t;return(null!==(t=this._originalHeight)&&void 0!==t?t:this._bitmap.height)+2*this.padding}get localBounds(){return D.fromDimension(this._getTotalWidth()*this.scale.x,this._getTotalHeight()*this.scale.y,A.Zero)}get smoothing(){return this._smoothing}set smoothing(t){this._smoothing=t,this.flagDirty()}get color(){return this._color}set color(t){this.flagDirty(),this._color=pt(t,(()=>this.flagDirty()))}get strokeColor(){return this._strokeColor}set strokeColor(t){this.flagDirty(),this._strokeColor=pt(t,(()=>this.flagDirty()))}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=t,this.flagDirty()}get lineDash(){return this._lineDash}set lineDash(t){this._lineDash=t,this.flagDirty()}get padding(){return this._padding}set padding(t){this._padding=t,this.flagDirty()}rasterize(){this._dirty=!1,this._ctx.clearRect(0,0,this._getTotalWidth(),this._getTotalHeight()),this._ctx.save(),this._applyRasterProperties(this._ctx),this.execute(this._ctx),this._ctx.restore(),bt.load(this._bitmap,this.filtering,!0)}_applyRasterProperties(t){var e,i,s;this._bitmap.width=this._getTotalWidth(),this._bitmap.height=this._getTotalHeight(),t.translate(this.padding,this.padding),t.imageSmoothingEnabled=this.smoothing,t.lineWidth=this.lineWidth,t.setLineDash(null!==(e=this.lineDash)&&void 0!==e?e:t.getLineDash()),t.strokeStyle=null===(i=this.strokeColor)||void 0===i?void 0:i.toString(),t.fillStyle=null===(s=this.color)||void 0===s?void 0:s.toString()}_drawImage(t,e,i){this._dirty&&this.rasterize(),t.drawImage(this._bitmap,e,i)}}class St extends Ct{constructor(t){super(t),this._options=t}get ctx(){return this._ctx}clone(){return new St({...this._options,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){var e,i;(null===(e=this._options)||void 0===e?void 0:e.draw)&&(null===(i=this._options)||void 0===i||i.draw(t)),this._options.cache||this.flagDirty()}}!function(t){t.Kill="kill",t.PreKill="prekill",t.PostKill="postkill",t.PreDraw="predraw",t.PostDraw="postdraw",t.PreDebugDraw="predebugdraw",t.PostDebugDraw="postdebugdraw",t.PreUpdate="preupdate",t.PostUpdate="postupdate",t.PreFrame="preframe",t.PostFrame="postframe",t.PreCollision="precollision",t.CollisionStart="collisionstart",t.CollisionEnd="collisionend",t.PostCollision="postcollision",t.Initialize="initialize",t.Activate="activate",t.Deactivate="deactivate",t.ExitViewport="exitviewport",t.EnterViewport="enterviewport",t.ExitTrigger="exit",t.EnterTrigger="enter",t.Connect="connect",t.Disconnect="disconnect",t.Button="button",t.Axis="axis",t.Subscribe="subscribe",t.Unsubscribe="unsubscribe",t.Visible="visible",t.Hidden="hidden",t.Start="start",t.Stop="stop",t.PointerUp="pointerup",t.PointerDown="pointerdown",t.PointerMove="pointermove",t.PointerEnter="pointerenter",t.PointerLeave="pointerleave",t.PointerCancel="pointercancel",t.PointerWheel="pointerwheel",t.Up="up",t.Down="down",t.Move="move",t.Enter="enter",t.Leave="leave",t.Cancel="cancel",t.Wheel="wheel",t.Press="press",t.Release="release",t.Hold="hold",t.PointerDragStart="pointerdragstart",t.PointerDragEnd="pointerdragend",t.PointerDragEnter="pointerdragenter",t.PointerDragLeave="pointerdragleave",t.PointerDragMove="pointerdragmove"}(lt||(lt={}));class At{constructor(){this._bubbles=!0}get bubbles(){return this._bubbles}set bubbles(t){this._bubbles=t}stopPropagation(){this.bubbles=!1}}class Pt extends At{constructor(t){super(),this.target=t}}class Tt extends At{constructor(t){super(),this.target=t}}class Et extends At{constructor(t){super(),this.target=t}}class It extends At{constructor(t){super(),this.target=t}}class Rt extends At{constructor(t){super(),this.target=t}}class Dt extends At{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class Bt extends At{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class Mt extends At{constructor(t,e){super(),this.ctx=t,this.target=e}}class kt extends At{constructor(t,e){super(),this.ctx=t,this.target=e}}class Ft extends At{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class Lt extends At{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class zt extends At{constructor(t,e){super(),this.engine=t,this.prevStats=e,this.target=t}}class Ot extends At{constructor(t,e){super(),this.engine=t,this.stats=e,this.target=t}}class Ut extends At{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Nt extends At{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Ht extends At{constructor(t,e,i){super(),this.button=t,this.value=e,this.target=i}}class Wt extends At{constructor(t,e,i){super(),this.axis=t,this.value=e,this.target=i}}class Gt extends At{constructor(t,e){super(),this.topic=t,this.handler=e}}class Vt extends At{constructor(t,e){super(),this.topic=t,this.handler=e}}class Xt extends At{constructor(t){super(),this.target=t}}class qt extends At{constructor(t){super(),this.target=t}}class jt extends At{constructor(t,e,i,s){super(),this.other=e,this.side=i,this.intersection=s,this.target=t}}class Kt extends At{constructor(t,e,i,s){super(),this.other=e,this.side=i,this.intersection=s,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class Zt{constructor(t,e,i){this.target=t,this.other=e,this.contact=i}}class Yt{constructor(t,e){this.target=t,this.other=e}}class Qt{constructor(t,e,i,s,r){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=r}}class $t{constructor(t,e,i,s,r){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=r}}class Jt extends At{constructor(t,e,i){super(),this.other=e,this.contact=i,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class te extends At{constructor(t,e){super(),this.other=e,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class ee extends At{constructor(t,e){super(),this.engine=t,this.target=e}}class ie extends At{constructor(t,e){super(),this.oldScene=t,this.target=e}}class se extends At{constructor(t,e){super(),this.newScene=t,this.target=e}}class re extends At{constructor(t){super(),this.target=t}}class ne extends At{constructor(t){super(),this.target=t}}class oe extends At{constructor(t,e){super(),this.target=t,this.actor=e}}class ae extends At{constructor(t,e){super(),this.target=t,this.actor=e}}class he{constructor(){this._handlers={},this._wiredEventDispatchers=[]}clear(){this._handlers={},this._wiredEventDispatchers=[]}emit(t,e){if(!t)return;let i,s;if(t=t.toLowerCase(),e||(e=new At),this._handlers[t])for(i=0,s=this._handlers[t].length;i<s;i++)this._handlers[t][i](e);for(i=0,s=this._wiredEventDispatchers.length;i<s;i++)this._wiredEventDispatchers[i].emit(t,e)}on(t,e){t=t.toLowerCase(),this._handlers[t]||(this._handlers[t]=[]),this._handlers[t].push(e),"unsubscribe"!==t&&"subscribe"!==t&&this.emit("subscribe",new Gt(t,e))}off(t,e){t=t.toLowerCase();const i=this._handlers[t];if(i)if(e){const s=i.indexOf(e);this._handlers[t].splice(s,1)}else this._handlers[t].length=0;"unsubscribe"!==t&&"subscribe"!==t&&this.emit("unsubscribe",new Vt(t,e))}once(t,e){this.on(t,(i=>{const s=i||new At;this.off(t,e),e(s)}))}wire(t){t._wiredEventDispatchers.push(this)}unwire(t){const e=t._wiredEventDispatchers.indexOf(this);e>-1&&t._wiredEventDispatchers.splice(e,1)}}class le{constructor(t,e,i=!0){this.path=t,this.responseType=e,this.bustCache=i,this.data=null,this.logger=f.getInstance(),this.events=new he}isLoaded(){return null!==this.data}_cacheBust(t){return/\?\w*=\w*/.test(t)?t+="&__="+Date.now():t+="?__="+Date.now(),t}load(){return new Promise(((t,e)=>{if(null!==this.data)return this.logger.debug("Already have data for resource",this.path),this.events.emit("complete",this.data),void t(this.data);const i=new XMLHttpRequest;i.open("GET",this.bustCache?this._cacheBust(this.path):this.path,!0),i.responseType=this.responseType,i.addEventListener("loadstart",(t=>this.events.emit("loadstart",t))),i.addEventListener("progress",(t=>this.events.emit("progress",t))),i.addEventListener("error",(t=>this.events.emit("error",t))),i.addEventListener("load",(t=>this.events.emit("load",t))),i.addEventListener("load",(()=>{if(0!==i.status&&200!==i.status)return this.logger.error("Failed to load resource ",this.path," server responded with error code",i.status),this.events.emit("error",i.response),void e(new Error(i.statusText));this.data=i.response,this.events.emit("complete",this.data),this.logger.debug("Completed loading resource",this.path),t(this.data)})),i.send()}))}}var ce=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let de=class{updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=(r[s+0]+r[s+1]+r[s+2])/3;r[s+0]=n,r[s+1]=n,r[s+2]=n}};de=ce([C({message:"Grayscale will be removed in v0.26.0"})],de);let ue=class{updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;r[s+0]=255-r[s+0],r[s+1]=255-r[s+1],r[s+2]=255-r[s+2]}};ue=ce([C({message:"Invert will be removed in v0.26.0"})],ue);let pe=class{constructor(t){this.opacity=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+3]=Math.round(this.opacity*r[s+3]))}};pe=ce([C({message:"Opacity will be removed in v0.26.0"})],pe);let ge=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+0]=(r[s+0]+this.color.r)/2,r[s+1]=(r[s+1]+this.color.g)/2,r[s+2]=(r[s+2]+this.color.b)/2)}};ge=ce([C({message:"Colorize will be removed in v0.26.0"})],ge);let _e=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).lighten(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};_e=ce([C({message:"Lighten will be removed in v0.26.0"})],_e);let fe=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).darken(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};fe=ce([C({message:"Darken will be removed v0.26.0"})],fe);let me=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).saturate(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};me=ce([C({message:"Saturate will be removed in v0.26.0"})],me);let ve=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data,n=I.fromRGB(r[s+0],r[s+1],r[s+2],r[s+3]).desaturate(this.factor);r[s+0]=n.r,r[s+1]=n.g,r[s+2]=n.b,r[s+3]=n.a}};ve=ce([C({message:"Desaturate will be removed in v0.26.0"})],ve);let ye=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),r=i.data;0!==r[s+3]&&(r[s+0]=this.color.r,r[s+1]=this.color.g,r[s+2]=this.color.b)}};ye=ce([C({message:"Fill will be removed in v0.26.0"})],ye);class we{constructor(t,e=!0){this.path=t,this.bustCache=e,this._sprite=null,this.loaded=new Promise((t=>{this._loadedResolve=t})),this._resource=new le(t,"blob",e),this._sprite=new Se(this,0,0,0,0)}get image(){return this.data}isLoaded(){return!!this.data}async load(){try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=await this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,await e.decode(),this.data=e,this.width=this._sprite.width=e.naturalWidth,this.height=this._sprite.height=e.naturalHeight,this._sprite=new Se(this,0,0,this.width,this.height)}catch(t){await Promise.reject("Error loading texture")}return this._loadedResolve(this.data),this.data}asSprite(){return this._sprite}}function xe(t){return class extends t{assign(t){for(const e in t)"function"!=typeof this[e]&&(this[e]=t[e])}constructor(...t){super(...t);1!==t.filter((function(t){return void 0!==t})).length||!t[0]||"object"!=typeof t[0]||t[0]instanceof Array||this.assign(t[0])}}}var be=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ce{constructor(t,e,i,s,r){this.x=0,this.y=0,this.rotation=0,this.anchor=A.Half,this.offset=A.Zero,this.scale=A.One,this.drawAroundAnchor=!1,this.logger=f.getInstance(),this.flipVertical=!1,this.flipHorizontal=!1,this.effects=[],this.width=0,this.height=0,this._spriteCanvas=null,this._spriteCtx=null,this._pixelData=null,this._pixelsLoaded=!1,this._dirtyEffect=!0,this._opacity=1;let n=t;if(t&&!(t instanceof we)&&(e=0|t.x,i=0|t.y,s=0|t.width,r=0|t.height,n=t.image,!n)){throw new Error("An image texture is required to construct a sprite")}this.x=e||0,this.y=i||0,this.texture=n,this._spriteCanvas=document.createElement("canvas"),this._spriteCanvas.width=s,this._spriteCanvas.height=r,this._spriteCtx=this._spriteCanvas.getContext("2d"),this._initPixelsFromTexture(),this.width=s,this.height=r}get drawWidth(){return Math.abs(this.width*this.scale.x)}get drawHeight(){return Math.abs(this.height*this.scale.y)}async _initPixelsFromTexture(){try{const t=await this.texture.loaded;this.width=this.width||t.naturalWidth,this.height=this.height||t.naturalHeight,this._spriteCanvas.width=this._spriteCanvas.width||t.naturalWidth,this._spriteCanvas.height=this._spriteCanvas.height||t.naturalHeight,this._loadPixels(),this._dirtyEffect=!0}catch(t){this.logger.error("Error loading texture ",this.texture.path,t)}}_loadPixels(){if(this.texture.isLoaded()&&!this._pixelsLoaded){const t=this.texture.image.naturalWidth||0,e=this.texture.image.naturalHeight||0;if(this.width>t&&this.logger.warn(`The sprite width ${this.width} exceeds the width \n ${t} of the backing texture ${this.texture.path}`),this.width<=0||t<=0)throw new Error(`The width of a sprite cannot be 0 or negative, sprite width: ${this.width}, original width: ${t}`);if(this.height>e&&this.logger.warn(`The sprite height ${this.height} exceeds the height \n ${e} of the backing texture ${this.texture.path}`),this.height<=0||e<=0)throw new Error(`The height of a sprite cannot be 0 or negative, sprite height: ${this.height}, original height: ${e}`);this._flushTexture(),this._pixelsLoaded=!0}}_flushTexture(){const t=this.texture.image.naturalWidth||0,e=this.texture.image.naturalHeight||0;this._spriteCtx.clearRect(0,0,this.width,this.height),this._spriteCtx.drawImage(this.texture.image,z(this.x,0,t),z(this.y,0,e),z(this.width,0,t),z(this.height,0,e),0,0,this.width,this.height)}opacity(t){this._opacity=t}grayscale(){this.addEffect(new de)}invert(){this.addEffect(new ue)}fill(t){this.addEffect(new ye(t))}colorize(t){this.addEffect(new ge(t))}lighten(t=.1){this.addEffect(new _e(t))}darken(t=.1){this.addEffect(new fe(t))}saturate(t=.1){this.addEffect(new me(t))}desaturate(t=.1){this.addEffect(new ve(t))}addEffect(t){this.effects.push(t),this.texture.isLoaded()&&this._pixelsLoaded?this._applyEffects():this._dirtyEffect=!0}removeEffect(t){let e=-1;e="number"==typeof t?t:this.effects.indexOf(t),e<0||e>=this.effects.length||(this.effects.splice(e,1),this.texture.isLoaded()&&this._pixelsLoaded?this._applyEffects():this._dirtyEffect=!0)}_applyEffects(){if(this._flushTexture(),this.effects.length>0){this._pixelData=this._spriteCtx.getImageData(0,0,this.width,this.height);const t=this.effects.length;for(let e=0;e<t;e++)for(let t=0;t<this.height;t++)for(let i=0;i<this.width;i++)this.effects[e].updatePixel(i,t,this._pixelData);this._spriteCtx.clearRect(0,0,this.width,this.height),this._spriteCtx.putImageData(this._pixelData,0,0)}this._dirtyEffect=!1}clearEffects(){this.effects.length=0,this._applyEffects()}reset(){}debugDraw(t,e,i){t.save(),t.translate(e,i),t.rotate(this.rotation);const s=this.drawWidth*this.anchor.x,r=this.drawHeight*this.anchor.y;t.strokeStyle=I.Black.toString(),t.strokeRect(-s,-r,this.drawWidth,this.drawHeight),t.restore()}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:v,flipHorizontal:y,flipVertical:w}={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.width,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.height,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,offset:null!==(a=t.offset)&&void 0!==a?a:this.offset,opacity:(null!==(h=t.opacity)&&void 0!==h?h:1)*(null!==(l=this._opacity)&&void 0!==l?l:1)};this._dirtyEffect&&this._applyEffects();const x=g*f.x+m.x,b=_*f.y+m.y,C=this.scale.x>0?1:-1,S=this.scale.y>0?1:-1;c.save(),c.translate(d,u),c.scale(Math.abs(this.scale.x),Math.abs(this.scale.y)),this.drawAroundAnchor&&c.translate(-x,-b),c.translate(x,b),c.rotate(p),c.scale(C,S),c.translate(-x,-b),y&&(c.translate(g,0),c.scale(-1,1)),w&&(c.translate(0,_),c.scale(1,-1));const A=c.globalAlpha;c.globalAlpha=v,c.drawImage(this._spriteCanvas,0,0,this.width,this.height,0,0,this.width,this.height),c.globalAlpha=A,c.restore()}clone(){const t=new Se(this.texture,this.x,this.y,this.width,this.height);t.anchor=this.anchor.clone(),t.scale=this.scale.clone(),t.rotation=this.rotation,t.flipHorizontal=this.flipHorizontal,t.flipVertical=this.flipVertical;const e=this.effects.length;for(let i=0;i<e;i++)t.addEffect(this.effects[i]);return t}}let Se=class extends(xe(Ce)){constructor(t,e,i,s,r){super(t,e,i,s,r)}};Se=be([C({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Se);class Ae extends _t{constructor(t){var e,i;super(t),this._dirty=!0,this.image=t.image;const{width:s,height:r}=t;this.sourceView=null!==(e=t.sourceView)&&void 0!==e?e:{x:0,y:0,width:null!=s?s:0,height:null!=r?r:0},this.destSize=null!==(i=t.destSize)&&void 0!==i?i:{width:null!=s?s:0,height:null!=r?r:0},this._updateSpriteDimensions(),this.image.ready.then((()=>{this._updateSpriteDimensions()}))}static from(t){return new Ae({image:t})}get width(){return Math.abs(this.destSize.width*this.scale.x)}get height(){return Math.abs(this.destSize.height*this.scale.y)}set width(t){t/=Math.abs(this.scale.x),this.destSize.width=t,super.width=Math.ceil(this.destSize.width)}set height(t){t/=Math.abs(this.scale.y),this.destSize.height=t,super.height=Math.ceil(this.destSize.height)}_updateSpriteDimensions(){var t,e,i,s,r,n;const{width:o,height:a}=this.image;this.sourceView.width=(null===(t=this.sourceView)||void 0===t?void 0:t.width)||o,this.sourceView.height=(null===(e=this.sourceView)||void 0===e?void 0:e.height)||a,this.destSize.width=(null===(i=this.destSize)||void 0===i?void 0:i.width)||(null===(s=this.sourceView)||void 0===s?void 0:s.width)||o,this.destSize.height=(null===(r=this.destSize)||void 0===r?void 0:r.height)||(null===(n=this.sourceView)||void 0===n?void 0:n.height)||a,this.width=Math.ceil(this.destSize.width)*this.scale.x,this.height=Math.ceil(this.destSize.height)*this.scale.y}_preDraw(t,e,i){this.image.isLoaded()&&this._dirty&&(this._dirty=!1,this._updateSpriteDimensions()),super._preDraw(t,e,i)}_drawImage(t,e,i){this.image.isLoaded()&&t.drawImage(this.image.image,this.sourceView.x,this.sourceView.y,this.sourceView.width,this.sourceView.height,e,i,this.destSize.width,this.destSize.height)}static fromLegacySprite(t){const e=t.texture,i=Pe.fromLegacyTexture(e);return new Ae({image:i,sourceView:{x:t.x,y:t.y,width:t.width,height:t.height}})}static toLegacySprite(t){const e=t.image,i=new we(e.path);return i.data=e.image,new Se(i,t.sourceView.x,t.sourceView.y,t.sourceView.width,t.sourceView.height)}clone(){return new Ae({image:this.image,sourceView:{...this.sourceView},destSize:{...this.destSize},...this.cloneGraphicOptions()})}}class Pe{constructor(t,e=!1,i){this.path=t,this._logger=f.getInstance(),this.data=new Image,this._resource=new le(t,"blob",e),this._filtering=i,(t.endsWith(".svg")||t.endsWith(".gif"))&&this._logger.warn(`Image type is not fully supported, you may have mixed results ${t}. Fully supported: jpg, bmp, and png`),this.ready=new Promise((t=>{this._loadedResolve=t}))}get width(){return this.image.naturalWidth}get height(){return this.image.naturalHeight}isLoaded(){return this._src||(this._src=this.data.src),!!this._src}get image(){return this.data}async load(){if(this.isLoaded())return this.data;try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=await this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,e.setAttribute("data-original-src",this.path),await e.decode(),this.data=e}catch(t){throw`Error loading ImageSource from path '${this.path}' with error [${t.message}]`}return bt.load(this.data,this._filtering),this._loadedResolve(this.data),this.data}toSprite(){return Ae.from(this)}static fromLegacyTexture(t){const e=new Pe(t.path);return t.isLoaded()?e.data=t.data:t.loaded.then((()=>{e.data=t.data})),e}unload(){this.data=new Image}}var Te=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ee{constructor(t,e,i,s){this.sprites=[],this.currentFrame=0,this._timeLeftInFrame=0,this._idempotencyToken=-1,this.anchor=A.Zero,this.rotation=0,this.scale=A.One,this.loop=!0,this.freezeFrame=-1,this.flipVertical=!1,this.flipHorizontal=!1,this.drawWidth=0,this.drawHeight=0,this.width=0,this.height=0,this._opacity=1;let r=t;if(t&&!(t instanceof xn)){const n=t;r=n.engine,e=n.sprites,i=n.speed,s=n.loop}this.sprites=e,this.speed=i,this._engine=r,this._timeLeftInFrame=this.speed,null!=s&&(this.loop=s),e&&e[0]&&(this.drawHeight=e[0]?e[0].drawHeight:0,this.drawWidth=e[0]?e[0].drawWidth:0,this.width=e[0]?e[0].width:0,this.height=e[0]?e[0].height:0,this.freezeFrame=e.length-1)}opacity(t){this._opacity=t}grayscale(){this.addEffect(new de)}invert(){this.addEffect(new ue)}fill(t){this.addEffect(new ye(t))}colorize(t){this.addEffect(new ge(t))}lighten(t=.1){this.addEffect(new _e(t))}darken(t=.1){this.addEffect(new fe(t))}saturate(t=.1){this.addEffect(new me(t))}desaturate(t=.1){this.addEffect(new ve(t))}addEffect(t){for(const e in this.sprites)this.sprites[e].addEffect(t)}removeEffect(t){for(const e in this.sprites)this.sprites[e].removeEffect(t)}clearEffects(){for(const t in this.sprites)this.sprites[t].clearEffects()}_setAnchor(t){for(const e in this.sprites)this.sprites[e].anchor.setTo(t.x,t.y)}_setRotation(t){for(const e in this.sprites)this.sprites[e].rotation=t}_setScale(t){for(const e in this.sprites)this.sprites[e].scale=t}reset(){this.currentFrame=0}isDone(){return!this.loop&&this.currentFrame>=this.sprites.length}tick(t,e){if(this._idempotencyToken===e)return;this._idempotencyToken=e,this._timeLeftInFrame-=t,this._timeLeftInFrame<=0&&(this.currentFrame=this.loop?(this.currentFrame+1)%this.sprites.length:this.currentFrame+1,this._timeLeftInFrame=this.speed),this._updateValues();const i=this.sprites[this.currentFrame];i&&(this.width=i.width,this.height=i.height,this.drawWidth=i.drawWidth,this.drawHeight=i.drawHeight)}_updateValues(){this._setAnchor(this.anchor),this._setRotation(this.rotation),this._setScale(this.scale)}skip(t){this.currentFrame=(this.currentFrame+t)%this.sprites.length}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h;const l={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.drawWidth,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.drawHeight,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,opacity:(null!==(a=t.opacity)&&void 0!==a?a:1)*(null!==(h=this._opacity)&&void 0!==h?h:1)};let c;this._updateValues(),this.currentFrame<this.sprites.length&&(c=this.sprites[this.currentFrame],c.draw(l)),-1!==this.freezeFrame&&this.currentFrame>=this.sprites.length&&(c=this.sprites[z(this.freezeFrame,0,this.sprites.length-1)],c.draw(l)),c&&(this.drawWidth=c.drawWidth,this.drawHeight=c.drawHeight)}play(t,e){this.reset(),this._engine.playAnimation(this,t,e)}}let Ie=class extends(xe(Ee)){constructor(t,e,i,s){super(t,e,i,s)}};var Re,De,Be,Me,ke;Ie=Te([C({message:"Animation will be removed in v0.26.0",alternateMethod:"Use Graphics.Animation"})],Ie),function(t){t.Em="em",t.Rem="rem",t.Px="px",t.Pt="pt",t.Percent="%"}(Re||(Re={})),function(t){t.Left="left",t.Right="right",t.Center="center",t.Start="start",t.End="end"}(De||(De={})),function(t){t.Top="top",t.Hanging="hanging",t.Middle="middle",t.Alphabetic="alphabetic",t.Ideographic="ideographic",t.Bottom="bottom"}(Be||(Be={})),function(t){t.Normal="normal",t.Italic="italic",t.Oblique="oblique"}(Me||(Me={})),function(t){t.LeftToRight="ltr",t.RightToLeft="rtl"}(ke||(ke={}));var Fe=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Le{constructor(t,e,i,s,r,n){this._sprites=[],this._image=null,this._columns=0,this._rows=0,this._spWidth=0,this._spHeight=0,this._spacing=0;let o=!1;if(t instanceof Array?this._sprites=t:(!t||t instanceof we?(this._image=t,this._columns=e,this._rows=i,this._spWidth=s,this._spHeight=r,this._spacing=n||0):(this._columns=t.columns,this._rows=t.rows,this._spWidth=t.spWidth,this._spHeight=t.spHeight,this._image=t.image,this._spacing=t.spacing||0),this._sprites=new Array(this._columns*this._rows),o=!0),this.image instanceof we){let t=!1,e=!1;if(this.image.isLoaded()){if(t=this.spWidth*this.columns>this.image.image.naturalWidth,e=this.spHeight*this.rows>this.image.image.naturalHeight,t)throw new RangeError(`SpriteSheet specified is wider, ${this.columns} cols x ${this.spWidth} pixels > ${this.image.image.naturalWidth} pixels than image width`);if(e)throw new RangeError(`SpriteSheet specified is taller, ${this.rows} rows x ${this.spHeight} pixels > ${this.image.image.naturalHeight} pixels than image height`)}}if(o){const t=this.getSpacingDimensions();for(let e=0;e<this.rows;e++)for(let i=0;i<this.columns;i++)this._sprites[i+e*this.columns]=new Se(this.image,i*this.spWidth+t.margin*i+t.left,e*this.spHeight+t.margin*e+t.top,this.spWidth,this.spHeight)}}get spacing(){return this._spacing}get sprites(){return[...this._sprites]}get image(){return this._image}get columns(){return this._columns}get rows(){return this._rows}get spWidth(){return this._spWidth}get spHeight(){return this._spHeight}getSpacingDimensions(){var t,e,i;return"number"==typeof this.spacing?{left:this.spacing,top:this.spacing,margin:this.spacing}:{left:null!==(t=this.spacing.left)&&void 0!==t?t:0,top:null!==(e=this.spacing.top)&&void 0!==e?e:0,margin:null!==(i=this.spacing.margin)&&void 0!==i?i:0}}getAnimationByIndices(t,e,i){let s=e.map((t=>this.sprites[t]));return s=s.map((function(t){return t.clone()})),new Ie(t,s,i)}getAnimationBetween(t,e,i,s){let r=this.sprites.slice(e,i);return r=r.map((function(t){return t.clone()})),new Ie(t,r,s)}getAnimationForAll(t,e){const i=this.sprites.map((function(t){return t.clone()}));return new Ie(t,i,e)}getSprite(t){if(t>=0&&t<this.sprites.length)return this.sprites[t];throw new Error("Invalid index: "+t)}getAnimationByCoords(t,e,i){let s=0,r=0;const n=new Array(e.length);for(let t=0;t<e.length;t++){const i=e[t];i.image=i.image||this.image,s=Math.max(s,i.drawWidth),r=Math.max(r,i.drawHeight),n[t]=new Se(i)}const o=new Ie(t,n,i);return o.drawWidth=s,o.drawHeight=r,o}}let ze=class extends Le{constructor(t,e,i,s,r,n,o,a){super(t instanceof we?{image:t,spWidth:n,spHeight:o,rows:r,columns:s,spacing:a||0}:t),this._currentColor=I.Black,this._currentOpacity=1,this._spriteRecord={},this._textShadowOn=!1,this._textShadowDirty=!0,this._textShadowColor=I.Black,this._textShadowSprites={},this._shadowOffsetX=5,this._shadowOffsetY=5,!t||t instanceof we||(e=t.alphabet,i=t.caseInsensitive),this.alphabet=e,this.caseInsensitive=i,this._spriteRecord=this.getTextSprites()}getTextSprites(){const t={};for(let e=0;e<this.alphabet.length;e++){let i=this.alphabet[e];this.caseInsensitive&&(i=i.toLowerCase()),t[i]=this.sprites[e].clone()}return t}setTextShadow(t,e,i){this._textShadowOn=!0,this._shadowOffsetX=t,this._shadowOffsetY=e,this._textShadowColor=i.clone(),this._textShadowDirty=!0;for(const t in this._spriteRecord)this._textShadowSprites[t]=this._spriteRecord[t].clone()}useTextShadow(t){this._textShadowOn=t,t&&this.setTextShadow(5,5,this._textShadowColor)}draw(t,e,i,s,r){if(r=this._parseOptions(r),this._currentColor.toString()!==r.color.toString()||this._currentOpacity!==r.opacity){this._currentOpacity=r.opacity,this._currentColor=r.color;for(const t in this._spriteRecord)this._spriteRecord[t].clearEffects(),this._spriteRecord[t].fill(r.color),this._spriteRecord[t].opacity(r.opacity)}if(this._textShadowOn&&this._textShadowDirty&&this._textShadowColor){for(const t in this._textShadowSprites)this._textShadowSprites[t].clearEffects(),this._textShadowSprites[t].addEffect(new ye(this._textShadowColor.clone()));this._textShadowDirty=!1}const n=this.sprites[0],o=n.height,a=r.fontSize/o,h=e.length*n.width*a+e.length*r.letterSpacing;let l=i;r.textAlign===De.Left||r.textAlign===De.Start?l=i:r.textAlign===De.Right||r.textAlign===De.End?l=i-h:r.textAlign===De.Center&&(l=i-h/2);let c=s-o*a;r.baseAlign===Be.Top||r.baseAlign===Be.Hanging?c=s:r.baseAlign===Be.Ideographic||r.baseAlign===Be.Bottom||r.baseAlign===Be.Alphabetic?c=s-o*a:r.baseAlign===Be.Middle&&(c=s-o*a/2);for(let i=0;i<e.length;i++){let s=e[i];this.caseInsensitive&&(s=s.toLowerCase());try{this._textShadowOn&&(this._textShadowSprites[s].drawAroundAnchor=!1,this._textShadowSprites[s].scale=P(a,a),this._textShadowSprites[s].draw(t,l+this._shadowOffsetX,c+this._shadowOffsetY));const e=this._spriteRecord[s];e.drawAroundAnchor=!1,e.scale=P(a,a),e.draw(t,l,c),l+=e.drawWidth+r.letterSpacing}catch(t){f.getInstance().error(`SpriteFont Error drawing char ${s}`)}}}_parseOptions(t){return{fontSize:t.fontSize||10,letterSpacing:t.letterSpacing||0,color:t.color||I.Black,textAlign:void 0===typeof t.textAlign?De.Left:t.textAlign,baseAlign:void 0===typeof t.baseAlign?Be.Bottom:t.baseAlign,maxWidth:t.maxWidth||-1,opacity:t.opacity||0}}};ze=Fe([C({message:"SpriteSheet will be removed in v0.26.0",alternateMethod:"Use Graphics.SpriteSheet"})],ze);class Oe{constructor(t){this._logger=f.getInstance(),this.sprites=[];const{sprites:e,rows:i,columns:s}=t;this.sprites=e,this.rows=null!=i?i:1,this.columns=null!=s?s:this.sprites.length}getSprite(t,e){if(t>=this.columns||t<0)return this._logger.warn(`No sprite exists in the SpriteSheet at (${t}, ${e}), x: ${t} should be between 0 and ${this.columns-1}`),null;if(e>=this.rows||e<0)return this._logger.warn(`No sprite exists in the SpriteSheet at (${t}, ${e}), y: ${e} should be between 0 and ${this.rows-1}`),null;const i=t+e*this.columns;return this.sprites[i]}static fromLegacySpriteSheet(t){const e=t.sprites.map((t=>Ae.fromLegacySprite(t)));return new Oe({sprites:e})}static toLegacySpriteSheet(t){const e=t.sprites.map((t=>Ae.toLegacySprite(t)));return new Le(e)}static fromImageSource(t){var e;const i=[];t.spacing=null!==(e=t.spacing)&&void 0!==e?e:{};const{image:s,grid:{rows:r,columns:n,spriteWidth:o,spriteHeight:a},spacing:{originOffset:h,margin:l}}=t,c={x:0,y:0,...h},d={x:0,y:0,...l};for(let t=0;t<n;t++)for(let e=0;e<r;e++)i[t+e*n]=new Ae({image:s,sourceView:{x:t*o+d.x*t+c.x,y:e*a+d.y*e+c.y,width:o,height:a},destSize:{height:a,width:o}});return new Oe({sprites:i,rows:r,columns:n})}}class Ue extends _t{constructor(t){super(t),this._text="",this.alphabet="",this.shadow=null,this.caseInsensitive=!1,this.spacing=0,this._logger=f.getInstance(),this._alreadyWarnedAlphabet=!1,this._alreadyWarnedSpriteSheet=!1;const{alphabet:e,spriteSheet:i,caseInsensitive:s,spacing:r,shadow:n}=t;this.alphabet=e,this.spriteSheet=i,this.caseInsensitive=null!=s?s:this.caseInsensitive,this.spacing=null!=r?r:this.spacing,this.shadow=null!=n?n:this.shadow}static fromLegacySpriteFont(t){const e=t.sprites.map(Ae.fromLegacySprite);return new Ue({alphabet:t.alphabet,spacing:0,caseInsensitive:t.caseInsensitive,spriteSheet:new Oe({sprites:e})})}_getCharacterSprites(t){const e=[],i=this.caseInsensitive?t.toLocaleLowerCase():t,s=this.caseInsensitive?this.alphabet.toLocaleLowerCase():this.alphabet;for(let t=0;t<i.length;t++){const r=i[t];let n=s.indexOf(r);-1===n&&(n=0,this._alreadyWarnedAlphabet||(this._logger.warn(`SpriteFont - Cannot find letter '${r}' in configured alphabet '${s}'.`),this._logger.warn("There maybe be more issues in the SpriteFont configuration. No additional warnings will be logged."),this._alreadyWarnedAlphabet=!0));const o=this.spriteSheet.sprites[n];o?e.push(o):this._alreadyWarnedSpriteSheet||(this._logger.warn(`SpriteFont - Cannot find sprite for '${r}' at index '${n}' in configured SpriteSheet`),this._logger.warn("There maybe be more issues in the SpriteFont configuration. No additional warnings will be logged."),this._alreadyWarnedSpriteSheet=!0)}return e}measureText(t){const e=t.split("\n"),i=e.reduce(((t,e)=>t.length>e.length?t:e)),s=this._getCharacterSprites(i);let r=0,n=0;for(const t of s)r+=t.width+this.spacing,n=Math.max(n,t.height);return D.fromDimension(r,n*e.length,A.Zero)}_drawImage(t,e,i){let s=0,r=0,n=0;const o=this._text.split("\n");for(const a of o){for(const o of this._getCharacterSprites(a))o.draw(t,e+s,i+r),s+=o.width+this.spacing,n=Math.max(n,o.height);s=0,r+=n}}render(t,e,i,s,r){this._text=e;const n=this.measureText(e);this.width=n.width,this.height=n.height,this.shadow&&(t.save(),t.translate(this.shadow.offset.x,this.shadow.offset.y),this.draw(t,s,r),t.restore()),this.draw(t,s,r)}clone(){return new Ue({alphabet:this.alphabet,spriteSheet:this.spriteSheet,spacing:this.spacing})}}class Ne{constructor(){this.fontSheet="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAwCAYAAAD+f6R/AAAAAXNSR0IArs4c6QAABcJJREFUeJztnemu7CgMhGE07//KmT9NhrAFVzkQndQntXRP3/bCZkwCSQhCCCGEEEIIIYQQQog/TRz953Ecx/nDGIe/vdNhlc9tIz605Fk/ZmWfsO1hn9Gxuv1KHbvb3iL/VN+d1WORbyr7yR/5b9M4vjNeqko6jPJHq5wGHU151o9J2Udse9hndCxuv0rH7rY3yD/Wdyf13MrnQeDfkZIUSGKM4ff3cWN82pEZuTyQGX2IxeyR63va//8VNCYCq+1yEkLtWyagXv1P1r1H+110gP3PzT4gT8uW/mdQ8mUG8E9DqOz4MS9ICKGbXpS2BpnIrRzYeS96cll08INlCMl2/glzdcfazuuPqQO03lmqrBHsf272Q6NODXj6zzZIJd/LAHYTg3Mays5gBi7ZR27fOgs0yj8rm36DLMFiPgkAdXHKOwUQeMCQ/adSh/qBQrT/tPxbAwA9+DOZEILPAATSuHMgTv7+Auk/df2lHPCZLvMSLJe34LkEQ9PwXF1SRTllMYgvIaflqyVAjLGbsiCDcOK76jflxZ+sINPyROc5071yKWK5CJTV3dMp6+tBlyCtNlhAq/+XbWoBDcRNXYBMzD4VvQygSuPYC2jGGaSSOxXfy3dTUEsanIvNeepm38N/hssSALTPZnAXfwIYRJn2b7UBcw0FKX+nDdAMpm2j9WVnxrUa7TXaVAca/B+TgaAVh6R/rH0P/5m01dt/RLYViJn+w/bhVX2P7f/duqom5qb02pRLCLGIMgBU1wCEEN9BAUCID6MAIMSHUQAQ4sMoAAjxYRQAhPgwd1uB0fuZ7H3cnn2P+9mr/Pe4B8/eB/fwP4eRtci/0f6OfTCPt/9oHwC6G6y19RHZDumxmwzR4eE/s/2Tte/q/+XLdc9DeJ19diesQc/j7Z8fCe4tAS4CxZ7sp7eiJi7HiZmjmOTGJs+93CbS3nP0XIPH3vW8/qz6QPnX2QdsV/1uw/iZYvg8ACeHd28rpPzfNfhL+7vkw/4Ou9s+Onhbv91elpKZ48Dl6bzpwwibHigRArf+Ptk9+L3Y1Q5OB4LgCeSBw1iuB3GeJh1/HrX/zF0A9Mk+u45zMkc3r4rWPomma5+p/514LB+Zo93MErJ1JHxXPzByGa/licRYVKbpeQCoQ6Q8yxuCwJF9IPsoDkHAo/3Tx26cvA4EtJ/n04w8QOq/mrR7ddfLAC5BYFNlVI/0CnOVUflOpvJUQMx9AIMIW/nWDM67/qw0+95v9goBqD9j+72u/KD9U89IbnQbMIR2Zbneh5zUY7Hdk7XIP3UffVb+r+wDYAZLq+1n1+C7y3/ny2r7p5yeByDEh9HzAIQQJwoAQnwYBQAhPowCgBBjoNu3hNxSFACE6INuKvPajPZ4EFEAEKINcybGYzOd247WEd3TgA2jlmjEyrd+j9hvfVbD2PWQ3ZmGlu2HyO8og8eBuNUvNYWoDgMVpwHTJoLWdz1Y+ZYOy5uF7t6PPruZxANrud1lQXkP0jsGz/Yz+vGGMuygFyhSPcJnc1pMnQZElc+cRnoAlxdTvoDuK7puqF7uCQy+3fyFMiA02/vJQHh7DQDogMPTSGFNA56HTzbZ9yAfBOb1Zyo3qGM3MfMZ3f76huXf6xlmAHknMlLNXsBBBvbljIz9Uyz5Y5TzIBLR/qy/rNyrZ8+L/0BZ0m+tgXD0OK5XZxC/9P7I/g4hVFvzXf1/6i5A7+3AlijMPBLMZfCvuAp7A9rY56ApHitmLQc7c8bOv6ftAxlM9Xp35nkEK7nJetBsaMhtAAAuOLQGXwhh2dXQnn1rZ/a42BI3dL7L+jkFAbQddwdA9Ah35yMKhgEgVT46EFh5D4jz+OgavNKxeBCd1wDSJ/97oR8eoJkLi9t9/BDgDHTJ5NE7Dnzechh914OVv9M1K9PCqsfqb88XVg9qN9lm6nG176UPu+zn17GOxuO0vOWEEC/j+LFKTgghlvEfYJaLS+SA2O0AAAAASUVORK5CYII=",this.size=16,this.load()}load(){return this._imageSource=new Pe(this.fontSheet),this._imageSource.load().then((()=>{this._spriteSheet=Oe.fromImageSource({image:this._imageSource,grid:{rows:3,columns:16,spriteWidth:16,spriteHeight:16}}),this._spriteFont=new Ue({alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,!'&.\"?-()+ ",caseInsensitive:!0,spriteSheet:this._spriteSheet,spacing:-6})}))}write(t,e,i){this._imageSource.isLoaded()&&this._spriteFont.render(t,e,null,i.x,i.y)}}class He{constructor(t,e){this._gl=t,this._texture=e}use(){const t=this._gl;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._texture)}disable(){const t=this._gl;t.bindTexture(t.TEXTURE_2D,null)}}class We{constructor(t){this.width=t.width,this.height=t.height,this._gl=t.gl,this._setupFramebuffer()}setResolution(t,e){const i=this._gl;this.width=t,this.height=e,i.bindTexture(i.TEXTURE_2D,this._frameTexture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.width,this.height,0,i.RGBA,i.UNSIGNED_BYTE,null)}get frameBuffer(){return this._frameBuffer}get frameTexture(){return this._frameTexture}_setupFramebuffer(){const t=this._gl;this._frameTexture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._frameTexture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.width,this.height,0,t.RGBA,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE);const e=t.COLOR_ATTACHMENT0;this._frameBuffer=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,this._frameBuffer),t.framebufferTexture2D(t.FRAMEBUFFER,e,t.TEXTURE_2D,this._frameTexture,0),this.disable()}toRenderSource(){return new He(this._gl,this._frameTexture)}use(){const t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,this._frameBuffer),t.viewport(0,0,this.width,this.height)}disable(){const t=this._gl;t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,null)}}class Ge{static clear(){Ge._GL=null}static register(t){Ge._GL=t}static get gl(){if(!Ge._GL)throw Error("Attempted gl access before init");return Ge._GL}}class Ve{constructor(t){this._gl=Ge.gl,this.uniforms={},this.attributes={},this._compiled=!1;const{vertexSource:e,fragmentSource:i}=t;this.vertexSource=e,this.fragmentSource=i}get compiled(){return this._compiled}use(){this._gl.useProgram(this.program),Ve._ACTIVE_SHADER_INSTANCE=this}isCurrentlyBound(){return Ve._ACTIVE_SHADER_INSTANCE===this}compile(){const t=this._gl,e=this._compileShader(t,this.vertexSource,t.VERTEX_SHADER),i=this._compileShader(t,this.fragmentSource,t.FRAGMENT_SHADER);this.program=this._createProgram(t,e,i);const s=this.getAttributes();for(const t of s)this.attributes[t.name]=t;const r=this.getUniforms();for(const t of r)this.uniforms[t.name]=t;return this._compiled=!0,this.program}getUniforms(){const t=this._gl,e=t.getProgramParameter(this.program,t.ACTIVE_UNIFORMS),i=[];for(let s=0;s<e;s++){const e=t.getActiveUniform(this.program,s),r=t.getUniformLocation(this.program,e.name);i.push({name:e.name,glType:e.type,location:r})}return i}getAttributes(){const t=this._gl,e=t.getProgramParameter(this.program,t.ACTIVE_ATTRIBUTES),i=[];for(let s=0;s<e;s++){const e=t.getActiveAttrib(this.program,s),r=t.getAttribLocation(this.program,e.name);i.push({name:e.name,glType:xt(t,e.type),size:wt(t,e.type),location:r,normalized:!1})}return i}setTexture(t,e){const i=this._gl;i.activeTexture(i.TEXTURE0+t),i.bindTexture(i.TEXTURE_2D,e)}setUniformInt(t,e){this.setUniform("uniform1i",t,~~e)}setUniformIntArray(t,e){this.setUniform("uniform1iv",t,e)}setUniformBoolean(t,e){this.setUniform("uniform1i",t,e?1:0)}setUniformFloat(t,e){this.setUniform("uniform1f",t,e)}setUniformFloatArray(t,e){this.setUniform("uniform1fv",t,e)}setUniformFloatVector(t,e){this.setUniform("uniform2f",t,e.x,e.y)}setUniformMatrix(t,e){this.setUniform("uniformMatrix4fv",t,!1,e.data)}setUniform(t,e,...i){if(!this._compiled)throw Error(`Must compile shader before setting a uniform ${t}:${e}`);if(!this.isCurrentlyBound())throw Error("Currently accessed shader instance is not the current active shader in WebGL, must call `shader.use()` before setting uniforms");const s=this._gl.getUniformLocation(this.program,e);if(!s)throw Error(`Uniform ${t}:${e} doesn't exist or is not used in the shader source code, unused uniforms are optimized away by most browsers`);{const e=[s,...i];this._gl[t].apply(this._gl,e)}}_createProgram(t,e,i){const s=t.createProgram();if(null===s)throw Error("Could not create graphics shader program");t.attachShader(s,e),t.attachShader(s,i),t.linkProgram(s);if(!t.getProgramParameter(s,t.LINK_STATUS))throw Error(`Could not link the program: [${t.getProgramInfoLog(s)}]`);return s}_compileShader(t,e,i){const s=t.VERTEX_SHADER===i?"vertex":"fragment",r=t.createShader(i);if(null===r)throw Error(`Could not build shader: [${e}]`);t.shaderSource(r,e),t.compileShader(r);if(!t.getShaderParameter(r,t.COMPILE_STATUS)){const i=t.getShaderInfoLog(r);throw Error(`Could not compile ${s} shader:\n\n${i}${this._processSourceForError(e,i)}`)}return r}_processSourceForError(t,e){const i=t.split("\n"),s=e.search(/\d:\d/),r=e.indexOf(" ",s),[n,o]=e.slice(s,r).split(":").map((t=>Number(t)));for(let t=0;t<i.length;t++)i[t]=`${t+1}: ${i[t]}${o===t+1?" <----- ERROR!":""}`;return"\n\nSource:\n"+i.join("\n")}}Ve._ACTIVE_SHADER_INSTANCE=null;class Xe{constructor(t){this._gl=Ge.gl,this.type="dynamic";const{size:e,type:i,data:s}=t;if(this.buffer=this._gl.createBuffer(),!s&&!e)throw Error("Must either provide data or a size to the VertexBuffer");this.bufferData=s||new Float32Array(e),this.type=null!=i?i:this.type}bind(){const t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this.buffer)}upload(){const t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this.buffer),t.bufferData(t.ARRAY_BUFFER,this.bufferData,"static"===this.type?t.STATIC_DRAW:t.DYNAMIC_DRAW)}}class qe{constructor(t){this._gl=Ge.gl,this._logger=f.getInstance(),this._layout=[],this._attributes=[],this._vertexTotalSizeBytes=0;const{shader:e,vertexBuffer:i,attributes:s}=t;this._vertexBuffer=i,this._attributes=s,this._shader=e,this.initialize()}get vertexBuffer(){return this._vertexBuffer}get attributes(){return this._attributes}get totalVertexSizeBytes(){return this._vertexTotalSizeBytes}initialize(){if(!this._shader.compiled)throw Error("Shader not compiled, shader must be compiled before defining a vertex layout");this._layout.length=0;const t=this._shader.attributes;for(const e of this._attributes){const i=t[e[0]];if(!i)throw Error(`The attribute named: ${e[0]} size ${e[1]} not found in the shader source code:\n ${this._shader.vertexSource}`);if(i.size!==e[1])throw Error(`VertexLayout size definition for attribute: [${e[0]}, ${e[1]}], doesnt match shader source size ${i.size}:\n ${this._shader.vertexSource}`);this._layout.push(i)}let e=0;for(const t of this._layout){const i=yt(this._gl,t.glType);this._vertexTotalSizeBytes+=i*t.size,e+=t.size}this._vertexBuffer.bufferData.length%e!=0&&this._logger.warn(`The vertex component size (${e}) does divide evenly into the specified vertex buffer (${this._vertexBuffer.bufferData.length})`)}use(t=!1){const e=this._gl;if(!this._shader.isCurrentlyBound())throw Error("Shader associated with this vertex layout is not active! Call shader.use() before layout.use()");this._vertexBuffer.bind(),t&&this._vertexBuffer.upload();let i=0;for(const t of this._layout)e.vertexAttribPointer(t.location,t.size,t.glType,t.normalized,this.totalVertexSizeBytes,i),e.enableVertexAttribArray(t.location),i+=yt(e,t.glType)*t.size}}class je{static clear(){je.DrawCallCount=0,je.DrawnImagesCount=0}}je.DrawCallCount=0,je.DrawnImagesCount=0;class Ke{constructor(){this.type="ex.line",this.priority=0,this._maxLines=10922,this._vertexIndex=0,this._lineCount=0}initialize(t,e){this._gl=t,this._context=e,this._shader=new Ve({vertexSource:"attribute vec2 a_position;\r\nattribute vec4 a_color;\r\n\r\nvarying lowp vec4 v_color;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Passthrough the color\r\n v_color = a_color;\r\n}",fragmentSource:"precision mediump float;\r\n\r\n// Color\r\nvarying lowp vec4 v_color;\r\n\r\n\r\nvoid main() {\r\n gl_FragColor = v_color;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._vertexBuffer=new Xe({size:12*this._maxLines,type:"dynamic"}),this._layout=new qe({vertexBuffer:this._vertexBuffer,shader:this._shader,attributes:[["a_position",2],["a_color",4]]})}draw(t,e,i){this._isFull()&&this.flush(),this._lineCount++;const s=this._context.getTransform(),r=s.multv(t),n=s.multv(e),o=this._vertexBuffer.bufferData;o[this._vertexIndex++]=r.x,o[this._vertexIndex++]=r.y,o[this._vertexIndex++]=i.r/255,o[this._vertexIndex++]=i.g/255,o[this._vertexIndex++]=i.b/255,o[this._vertexIndex++]=i.a,o[this._vertexIndex++]=n.x,o[this._vertexIndex++]=n.y,o[this._vertexIndex++]=i.r/255,o[this._vertexIndex++]=i.g/255,o[this._vertexIndex++]=i.b/255,o[this._vertexIndex++]=i.a}_isFull(){return this._lineCount>=this._maxLines}hasPendingDraws(){return 0!==this._lineCount}flush(){if(0===this._lineCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),t.drawArrays(t.LINES,0,2*this._lineCount),je.DrawnImagesCount+=this._lineCount,je.DrawCallCount++,this._vertexIndex=0,this._lineCount=0}}class Ze{constructor(){this.type="ex.point",this.priority=0,this._maxPoints=10922,this._pointCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,this._shader=new Ve({vertexSource:"attribute vec2 a_position;\r\nattribute vec4 a_color;\r\nattribute float a_size;\r\nvarying lowp vec4 v_color;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main() {\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n gl_PointSize = a_size * 2.0;\r\n v_color = a_color;\r\n}",fragmentSource:'#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\n\r\nprecision mediump float;\r\nvarying lowp vec4 v_color;\r\n\r\nvoid main() {\r\n float r = 0.0, delta = 0.0, alpha = 1.0;\r\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\r\n r = dot(cxy, cxy);\r\n\r\n#ifdef GL_OES_standard_derivatives\r\n delta = fwidth(r);\r\n alpha = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, r);\r\n#else\r\n if (r > 1.0) {\r\n discard;\r\n }\r\n#endif\r\n // "premultiply" the color by alpha\r\n vec4 color = v_color;\r\n color.a = color.a * alpha;\r\n color.rgb = color.rgb * color.a;\r\n gl_FragColor = color;\r\n}'}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._buffer=new Xe({size:7*this._maxPoints,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_color",4],["a_size",1]]})}draw(t,e,i){this._isFull()&&this.flush(),this._pointCount++;const s=this._context.getTransform(),r=this._context.opacity,n=s.multv(t),o=this._buffer.bufferData;o[this._vertexIndex++]=n.x,o[this._vertexIndex++]=n.y,o[this._vertexIndex++]=e.r/255,o[this._vertexIndex++]=e.g/255,o[this._vertexIndex++]=e.b/255,o[this._vertexIndex++]=e.a*r,o[this._vertexIndex++]=i*Math.max(s.getScaleX(),s.getScaleY())}_isFull(){return this._pointCount>=this._maxPoints}hasPendingDraws(){return 0!==this._pointCount}flush(){if(0===this._pointCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),t.drawArrays(t.POINTS,0,this._pointCount),je.DrawnImagesCount+=this._pointCount,je.DrawCallCount++,this._pointCount=0,this._vertexIndex=0}}class Ye{constructor(t){this._gl=t,this._shader=new Ve({vertexSource:"attribute vec2 a_position;\r\n\r\nattribute vec2 a_texcoord;\r\nvarying vec2 v_texcoord;\r\n\r\nvoid main() {\r\n gl_Position = vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass the texcoord to the fragment shader.\r\n v_texcoord = a_texcoord;\r\n}",fragmentSource:"precision mediump float;\r\n\r\n// Passed in from the vertex shader.\r\nvarying vec2 v_texcoord;\r\n\r\n// The texture.\r\nuniform sampler2D u_texture;\r\n\r\nvoid main() {\r\n gl_FragColor = texture2D(u_texture, v_texcoord);\r\n}"}),this._shader.compile(),this._buffer=new Xe({type:"static",data:new Float32Array([-1,-1,0,0,-1,1,0,1,1,-1,1,0,1,-1,1,0,-1,1,0,1,1,1,1,1])}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_texcoord",2]]}),this._buffer.upload()}renderWithPostProcessor(t){const e=this._gl;t.getShader().use(),t.getLayout().use(),e.drawArrays(e.TRIANGLES,0,6)}renderToScreen(){const t=this._gl;this._shader.use(),this._layout.use(),t.drawArrays(t.TRIANGLES,0,6)}}class Qe{constructor(t,e){this._gl=Ge.gl,this._logger=f.getInstance();const i=this._gl;this.buffer=i.createBuffer(),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this.buffer);const s=6*t;if(i.getExtension("OES_element_index_uint")&&!e)this.bufferData=new Uint32Array(s);else{const e=65535,r=Math.floor((e-1)/4);this.bufferGlType=i.UNSIGNED_SHORT,this.bufferData=new Uint16Array(s),t>r&&this._logger.warn(`Total quads exceeds hardware index buffer limit (uint16), max(${r}) requested quads(${t})`)}let r=0;for(let t=0;t<s;t+=6)this.bufferData[t+0]=r+0,this.bufferData[t+1]=r+1,this.bufferData[t+2]=r+2,this.bufferData[t+3]=r+2,this.bufferData[t+4]=r+1,this.bufferData[t+5]=r+3,r+=4;i.bufferData(i.ELEMENT_ARRAY_BUFFER,this.bufferData,i.STATIC_DRAW)}get size(){return this.bufferData.length}upload(){const t=this._gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.buffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.bufferData,t.STATIC_DRAW)}bind(){const t=this._gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.buffer)}}class $e{constructor(){this.type="ex.image",this.priority=0,this._maxImages=10922,this._maxTextures=0,this._imageCount=0,this._textures=[],this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,this._maxTextures=Math.min(t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),125);const i=this._transformFragmentSource("precision mediump float;\r\n\r\n// UV coord\r\nvarying vec2 v_texcoord;\r\n\r\n// Texture index\r\nvarying lowp float v_textureIndex;\r\n\r\n// Textures in the current draw\r\nuniform sampler2D u_textures[%%count%%];\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // In order to support the most efficient sprite batching, we have multiple\r\n // textures loaded into the gpu (usually 8) this picker logic skips over textures\r\n // that do not apply to a particular sprite.\r\n\r\n vec4 color = vec4(1.0, 0, 0, 1.0);\r\n\r\n // GLSL is templated out to pick the right texture and set the vec4 color\r\n %%texture_picker%%\r\n\r\n color.rgb = color.rgb * v_opacity;\r\n color.a = color.a * v_opacity;\r\n gl_FragColor = color;\r\n}",this._maxTextures);this._shader=new Ve({fragmentSource:i,vertexSource:"attribute vec2 a_position;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\n// UV coordinate\r\nattribute vec2 a_texcoord;\r\nvarying vec2 v_texcoord;\r\n\r\n// Texture number\r\nattribute lowp float a_textureIndex;\r\nvarying lowp float v_textureIndex;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the UV coord to the fragment shader\r\n v_texcoord = a_texcoord;\r\n // Pass through the texture number to the fragment shader\r\n v_textureIndex = a_textureIndex;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._shader.setUniformIntArray("u_textures",[...Array(this._maxTextures)].map(((t,e)=>e))),this._buffer=new Xe({size:24*this._maxImages,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_opacity",1],["a_texcoord",2],["a_textureIndex",1]]}),this._quads=new Qe(this._maxImages,!0)}_transformFragmentSource(t,e){let i=t.replace("%%count%%",e.toString()),s="";for(let t=0;t<e;t++)s+=0===t?`if (v_textureIndex <= ${t}.5) {\n`:` else if (v_textureIndex <= ${t}.5) {\n`,s+=` color = texture2D(u_textures[${t}], v_texcoord);\n`,s+=" }\n";return i=i.replace("%%texture_picker%%",s),i}_addImageAsTexture(t){const e=bt.load(t);-1===this._textures.indexOf(e)&&this._textures.push(e)}_bindTextures(t){for(let e=0;e<this._maxTextures;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this._textures[e]||this._textures[0])}_getTextureIdForImage(t){return t?this._textures.indexOf(bt.get(t)):-1}_isFull(){return this._imageCount>=this._maxImages||this._textures.length>=this._maxTextures}draw(t,e,i,s,r,n,o,a,h){var l,c,d,u;this._isFull()&&this.flush(),this._imageCount++,this._addImageAsTexture(t);let p=(null==t?void 0:t.width)||s||0,g=(null==t?void 0:t.height)||r||0,_=[0,0,null!==(l=null!=s?s:null==t?void 0:t.width)&&void 0!==l?l:0,null!==(c=null!=r?r:null==t?void 0:t.height)&&void 0!==c?c:0],f=[null!=e?e:1,null!=i?i:1];void 0!==n&&void 0!==o&&void 0!==a&&void 0!==h&&(_=[null!=e?e:1,null!=i?i:1,null!==(d=null!=s?s:null==t?void 0:t.width)&&void 0!==d?d:0,null!==(u=null!=r?r:null==t?void 0:t.height)&&void 0!==u?u:0],f=[n,o],p=a,g=h),e=_[0],i=_[1];const m=_[2],v=_[3],y=this._context.getTransform(),w=this._context.opacity,x=this._context.snapToPixel,b=y.multv([f[0],f[1]]),C=y.multv([f[0]+p,f[1]]),S=y.multv([f[0],f[1]+g]),A=y.multv([f[0]+p,f[1]+g]);x&&(b[0]=~~b[0],b[1]=~~b[1],C[0]=~~C[0],C[1]=~~C[1],S[0]=~~S[0],S[1]=~~S[1],A[0]=~~A[0],A[1]=~~A[1]);const P=this._getTextureIdForImage(t),T=vt(t.width||p),E=vt(t.height||g),I=e/T,R=i/E,D=(e+m-.01)/T,B=(i+v-.01)/E,M=this._layout.vertexBuffer.bufferData;M[this._vertexIndex++]=b[0],M[this._vertexIndex++]=b[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=I,M[this._vertexIndex++]=R,M[this._vertexIndex++]=P,M[this._vertexIndex++]=S[0],M[this._vertexIndex++]=S[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=I,M[this._vertexIndex++]=B,M[this._vertexIndex++]=P,M[this._vertexIndex++]=C[0],M[this._vertexIndex++]=C[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=D,M[this._vertexIndex++]=R,M[this._vertexIndex++]=P,M[this._vertexIndex++]=A[0],M[this._vertexIndex++]=A[1],M[this._vertexIndex++]=w,M[this._vertexIndex++]=D,M[this._vertexIndex++]=B,M[this._vertexIndex++]=P}hasPendingDraws(){return 0!==this._imageCount}flush(){if(0===this._imageCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._bindTextures(t),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._imageCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._imageCount,je.DrawCallCount++,this._imageCount=0,this._vertexIndex=0,this._textures.length=0}}class Je{constructor(){this.type="ex.rectangle",this.priority=0,this._maxRectangles=10922,this._rectangleCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,t.getExtension("OES_standard_derivatives"),this._shader=new Ve({fragmentSource:"#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\nprecision mediump float;\r\n\r\n// UV coord\r\nvarying vec2 v_uv;\r\n\r\nvarying vec2 v_size; // in pixels\r\n\r\n// Color coord to blend with image\r\nvarying lowp vec4 v_color;\r\n\r\n// Stroke color if used\r\nvarying lowp vec4 v_strokeColor;\r\n\r\n// Stroke thickness if used\r\nvarying lowp float v_strokeThickness; // in pixels\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // modified from https://stackoverflow.com/questions/59197671/glsl-rounded-rectangle-with-variable-border\r\n vec2 uv = v_uv;\r\n vec2 fragCoord = uv * v_size;\r\n float maxX = v_size.x - v_strokeThickness;\r\n float minX = v_strokeThickness;\r\n float maxY = v_size.y - v_strokeThickness;\r\n float minY = v_strokeThickness;\r\n\r\n if (fragCoord.x < maxX && fragCoord.x > minX &&\r\n fragCoord.y < maxY && fragCoord.y > minY) {\r\n gl_FragColor = v_color;\r\n } else {\r\n gl_FragColor = v_strokeColor;\r\n }\r\n gl_FragColor.a *= v_opacity;\r\n gl_FragColor.rgb *= gl_FragColor.a;\r\n\r\n // vec2 v2CenteredPos = abs(fragCoord - v_size.xy / 2.0);\r\n // vec2 v2HalfShapeSizePx = v_size.xy/2.0 - v_strokeThickness/2.0;\r\n\r\n // float fHalfBorderDist = 0.0;\r\n // float fHalfBorderThickness = 0.0;\r\n\r\n // if (fragCoord.x > max(v_radius, v_strokeThickness) && \r\n // fragCoord.x < v_size.x - max(v_radius, v_strokeThickness))\r\n // {\r\n // fHalfBorderDist = v2CenteredPos.y - v2HalfShapeSizePx.y;\r\n // fHalfBorderThickness = v_strokeThickness / 2.0;\r\n // }\r\n // else if (fragCoord.y > max(v_radius, v_strokeThickness) && \r\n // fragCoord.y < v_size.y - max(v_radius, v_strokeThickness))\r\n // {\r\n // fHalfBorderDist = v2CenteredPos.x - v2HalfShapeSizePx.x;\r\n // fHalfBorderThickness = v_strokeThickness / 2.0;\r\n // }\r\n // else\r\n // {\r\n // vec2 edgeVec = max(vec2(0.0), v_radius - vec2(\r\n // uv.x > 0.5 ? v_size.x - fragCoord.x : fragCoord.x,\r\n // uv.y > 0.5 ? v_size.y - fragCoord.y : fragCoord.y));\r\n \r\n // float ellipse_ab = v_radius-v_strokeThickness;\r\n // vec2 ellipse_isect = (v_strokeThickness > v_radius || v_strokeThickness > v_radius) ? vec2(0.0) :\r\n // edgeVec.xy * ellipse_ab*ellipse_ab / length(ellipse_ab*edgeVec.yx); \r\n \r\n // fHalfBorderThickness = (v_radius - length(ellipse_isect)) / 2.0;\r\n // fHalfBorderDist = length(edgeVec) - (v_radius - fHalfBorderThickness);\r\n // }\r\n\r\n // vec4 v4FromColor = v_strokeColor;\r\n // v4FromColor.rgb *= v4FromColor.a;\r\n // vec4 v4ToColor = vec4(0.0); // background color is transparent\r\n // if (fHalfBorderDist < 0.0) {\r\n // v4ToColor = v_color;\r\n // v4ToColor.rgb *= v4ToColor.a;\r\n // }\r\n\r\n // float mixPct = abs(fHalfBorderDist) - fHalfBorderThickness;\r\n\r\n // vec4 finalColor = mix(v4FromColor, v4ToColor, mixPct);\r\n // gl_FragColor = finalColor;\r\n}",vertexSource:"attribute vec2 a_position;\r\n\r\n// UV coordinate\r\nattribute vec2 a_uv;\r\nvarying vec2 v_uv;\r\n\r\nattribute vec2 a_size;\r\nvarying vec2 v_size;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nattribute vec4 a_strokeColor;\r\nvarying vec4 v_strokeColor;\r\n\r\nattribute float a_strokeThickness;\r\nvarying float v_strokeThickness;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through UV coords\r\n v_uv = a_uv;\r\n // Pass through size\r\n v_size = a_size;\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the color to the fragment shader\r\n v_color = a_color;\r\n // Pass through the stroke color to the fragment shader\r\n v_strokeColor = a_strokeColor;\r\n // Pass through the stroke thickenss to the fragment shader\r\n v_strokeThickness = a_strokeThickness;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._buffer=new Xe({size:64*this._maxRectangles,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_uv",2],["a_size",2],["a_opacity",1],["a_color",4],["a_strokeColor",4],["a_strokeThickness",1]]}),this._quads=new Qe(this._maxRectangles,!0)}_isFull(){return this._rectangleCount>=this._maxRectangles}drawLine(t,e,i,s=1){this._isFull()&&this.flush(),this._rectangleCount++;const r=this._context.getTransform(),n=this._context.opacity,o=e.sub(t),a=o.size,h=o.normalize().perpendicular(),l=s/2,c=r.multv(h.scale(l).add(t)),d=r.multv(h.scale(-l).add(t)),u=r.multv(h.scale(l).add(e)),p=r.multv(h.scale(-l).add(e)),g=I.Transparent,_=this._layout.vertexBuffer.bufferData;_[this._vertexIndex++]=c.x,_[this._vertexIndex++]=c.y,_[this._vertexIndex++]=0,_[this._vertexIndex++]=0,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=d.x,_[this._vertexIndex++]=d.y,_[this._vertexIndex++]=0,_[this._vertexIndex++]=1,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=u.x,_[this._vertexIndex++]=u.y,_[this._vertexIndex++]=1,_[this._vertexIndex++]=0,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0,_[this._vertexIndex++]=p.x,_[this._vertexIndex++]=p.y,_[this._vertexIndex++]=1,_[this._vertexIndex++]=1,_[this._vertexIndex++]=a,_[this._vertexIndex++]=s,_[this._vertexIndex++]=n,_[this._vertexIndex++]=i.r/255,_[this._vertexIndex++]=i.g/255,_[this._vertexIndex++]=i.b/255,_[this._vertexIndex++]=i.a,_[this._vertexIndex++]=g.r/255,_[this._vertexIndex++]=g.g/255,_[this._vertexIndex++]=g.b/255,_[this._vertexIndex++]=g.a,_[this._vertexIndex++]=0}draw(t,e,i,s,r=I.Transparent,n=0){this._isFull()&&this.flush(),this._rectangleCount++;const o=this._context.getTransform(),a=this._context.opacity,h=o.multv(t.add(P(0,0))),l=o.multv(t.add(P(e,0))),c=o.multv(t.add(P(e,i))),d=o.multv(t.add(P(0,i))),u=this._layout.vertexBuffer.bufferData;u[this._vertexIndex++]=h.x,u[this._vertexIndex++]=h.y,u[this._vertexIndex++]=0,u[this._vertexIndex++]=0,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=d.x,u[this._vertexIndex++]=d.y,u[this._vertexIndex++]=0,u[this._vertexIndex++]=1,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=l.x,u[this._vertexIndex++]=l.y,u[this._vertexIndex++]=1,u[this._vertexIndex++]=0,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n,u[this._vertexIndex++]=c.x,u[this._vertexIndex++]=c.y,u[this._vertexIndex++]=1,u[this._vertexIndex++]=1,u[this._vertexIndex++]=e,u[this._vertexIndex++]=i,u[this._vertexIndex++]=a,u[this._vertexIndex++]=s.r/255,u[this._vertexIndex++]=s.g/255,u[this._vertexIndex++]=s.b/255,u[this._vertexIndex++]=s.a,u[this._vertexIndex++]=r.r/255,u[this._vertexIndex++]=r.g/255,u[this._vertexIndex++]=r.b/255,u[this._vertexIndex++]=r.a,u[this._vertexIndex++]=n}hasPendingDraws(){return 0!==this._rectangleCount}flush(){if(0===this._rectangleCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._rectangleCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._rectangleCount,je.DrawCallCount++,this._rectangleCount=0,this._vertexIndex=0}}class ti{constructor(){this.type="ex.circle",this.priority=0,this._maxCircles=10922,this._circleCount=0,this._vertexIndex=0}initialize(t,e){this._gl=t,this._context=e,t.getExtension("OES_standard_derivatives"),this._shader=new Ve({fragmentSource:"#ifdef GL_OES_standard_derivatives\r\n#extension GL_OES_standard_derivatives : enable\r\n#endif\r\nprecision highp float;\r\n\r\n// UV coord\r\nvarying vec2 v_uv;\r\n\r\n// Color coord to blend with image\r\nvarying lowp vec4 v_color;\r\n\r\n// Stroke color if used\r\nvarying lowp vec4 v_strokeColor;\r\n\r\n// Stroke thickness if used\r\nvarying lowp float v_strokeThickness;\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nvoid main() {\r\n // make (0, 0) the center the uv \r\n vec2 uv = v_uv * 2.0 - 1.0;\r\n\r\n vec4 color = v_color;\r\n vec4 strokeColor = v_strokeColor;\r\n\r\n // circle border is at radius 1.0 \r\n // dist is > 0 when inside the circle \r\n float d = length(uv);\r\n float dist = 1.0 - length(uv);\r\n\r\n // Fade based on fwidth\r\n float fade = fwidth(dot(uv, uv));\r\n\r\n // if dist is greater than 0 step to 1;\r\n // when we cross this 0 threshold add a smooth fade\r\n float fill = smoothstep(-fade/2.0, fade/2.0, dist);\r\n\r\n // if dist is greater than the stroke thickness step to 1\r\n float stroke = 1.0 - smoothstep(v_strokeThickness, v_strokeThickness + fade, dist);\r\n\r\n strokeColor.a *= fill * stroke;\r\n strokeColor.rgb *= strokeColor.a;\r\n\r\n color.a *= fill * (1.0 - stroke);\r\n color.rgb *= color.a;\r\n\r\n vec4 finalColor = mix(vec4(0.0), (color + strokeColor), fill);\r\n finalColor.rgb = finalColor.rgb * v_opacity;\r\n finalColor.a = finalColor.a * v_opacity;\r\n gl_FragColor = finalColor;\r\n}",vertexSource:"attribute vec2 a_position;\r\n\r\n// UV coordinate\r\nattribute vec2 a_uv;\r\nvarying vec2 v_uv;\r\n\r\n// Opacity \r\nattribute float a_opacity;\r\nvarying float v_opacity;\r\n\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nattribute vec4 a_strokeColor;\r\nvarying vec4 v_strokeColor;\r\n\r\nattribute float a_strokeThickness;\r\nvarying float v_strokeThickness;\r\n\r\nuniform mat4 u_matrix;\r\n\r\n\r\nvoid main() {\r\n // Set the vertex position using the ortho transform matrix\r\n gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);\r\n\r\n // Pass through UV coords\r\n v_uv = a_uv;\r\n // Pass through the Opacity to the fragment shader\r\n v_opacity = a_opacity;\r\n // Pass through the color to the fragment shader\r\n v_color = a_color;\r\n // Pass through the stroke color to the fragment shader\r\n v_strokeColor = a_strokeColor;\r\n // Pass through the stroke thickenss to the fragment shader\r\n v_strokeThickness = a_strokeThickness;\r\n}"}),this._shader.compile(),this._shader.use(),this._shader.setUniformMatrix("u_matrix",e.ortho),this._buffer=new Xe({size:56*this._maxCircles,type:"dynamic"}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_uv",2],["a_opacity",1],["a_color",4],["a_strokeColor",4],["a_strokeThickness",1]]}),this._quads=new Qe(this._maxCircles,!0)}_isFull(){return this._circleCount>=this._maxCircles}draw(t,e,i,s=I.Transparent,r=0){this._isFull()&&this.flush(),this._circleCount++;const n=this._context.getTransform(),o=this._context.opacity,a=n.multv(t.add(P(-e,-e))),h=n.multv(t.add(P(e,-e))),l=n.multv(t.add(P(e,e))),c=n.multv(t.add(P(-e,e))),d=this._layout.vertexBuffer.bufferData;d[this._vertexIndex++]=a.x,d[this._vertexIndex++]=a.y,d[this._vertexIndex++]=0,d[this._vertexIndex++]=0,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=c.x,d[this._vertexIndex++]=c.y,d[this._vertexIndex++]=0,d[this._vertexIndex++]=1,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=h.x,d[this._vertexIndex++]=h.y,d[this._vertexIndex++]=1,d[this._vertexIndex++]=0,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e,d[this._vertexIndex++]=l.x,d[this._vertexIndex++]=l.y,d[this._vertexIndex++]=1,d[this._vertexIndex++]=1,d[this._vertexIndex++]=o,d[this._vertexIndex++]=i.r/255,d[this._vertexIndex++]=i.g/255,d[this._vertexIndex++]=i.b/255,d[this._vertexIndex++]=i.a,d[this._vertexIndex++]=s.r/255,d[this._vertexIndex++]=s.g/255,d[this._vertexIndex++]=s.b/255,d[this._vertexIndex++]=s.a,d[this._vertexIndex++]=r/e}hasPendingDraws(){return 0!==this._circleCount}flush(){if(0===this._circleCount)return;const t=this._gl;this._shader.use(),this._layout.use(!0),this._shader.setUniformMatrix("u_matrix",this._context.ortho),this._quads.bind(),t.drawElements(t.TRIANGLES,6*this._circleCount,this._quads.bufferGlType,0),je.DrawnImagesCount+=this._circleCount,je.DrawCallCount++,this._circleCount=0,this._vertexIndex=0}}class ei{constructor(t){this._webglCtx=t,this._debugText=new Ne}drawRect(t,e,i,s,r={color:I.Black}){this.drawLine(P(t,e),P(t+i,e),{...r}),this.drawLine(P(t+i,e),P(t+i,e+s),{...r}),this.drawLine(P(t+i,e+s),P(t,e+s),{...r}),this.drawLine(P(t,e+s),P(t,e),{...r})}drawLine(t,e,i={color:I.Black}){this._webglCtx.draw("ex.line",t,e,i.color)}drawPoint(t,e={color:I.Black,size:5}){this._webglCtx.draw("ex.point",t,e.color,e.size)}drawText(t,e){this._debugText.write(this._webglCtx,t,e)}}class ii{constructor(t){this._logger=f.getInstance(),this._renderers=new Map,this._isDrawLifecycle=!1,this._postProcessTargets=[],this._postprocessors=[],this._transform=new dt,this._state=new ut,this.snapToPixel=!0,this.smoothing=!1,this.backgroundColor=I.ExcaliburBlue,this._alreadyWarnedDrawLifecycle=!1,this.debug=new ei(this);const{canvasElement:e,enableTransparency:i,smoothing:s,snapToPixel:r,backgroundColor:n}=t;this.__gl=e.getContext("webgl",{antialias:null!=s?s:this.smoothing,premultipliedAlpha:!1,alpha:null==i||i,depth:!0,powerPreference:"high-performance"}),Ge.register(this.__gl),bt.register(this.__gl),this.snapToPixel=null!=r?r:this.snapToPixel,this.smoothing=null!=s?s:this.smoothing,this.backgroundColor=null!=n?n:this.backgroundColor,this._init()}get opacity(){return this._state.current.opacity}set opacity(t){this._state.current.opacity=t}get width(){return this.__gl.canvas.width}get height(){return this.__gl.canvas.height}get ortho(){return this._ortho}checkIfResolutionSupported(t){let e=!0;return(t.width>4096||t.height>4096)&&(e=!1),e}_init(){const t=this.__gl;this._ortho=ct.ortho(0,t.canvas.width,t.canvas.height,0,400,-400),t.viewport(0,0,t.canvas.width,t.canvas.height),t.clearColor(this.backgroundColor.r/255,this.backgroundColor.g/255,this.backgroundColor.b/255,this.backgroundColor.a),t.clear(t.COLOR_BUFFER_BIT),t.enable(t.BLEND),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.blendEquationSeparate(t.FUNC_ADD,t.FUNC_ADD),t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA),this.register(new $e),this.register(new Je),this.register(new ti),this.register(new Ze),this.register(new Ke),this._screenRenderer=new Ye(t),this._renderTarget=new We({gl:t,width:t.canvas.width,height:t.canvas.height}),this._postProcessTargets=[new We({gl:t,width:t.canvas.width,height:t.canvas.height}),new We({gl:t,width:t.canvas.width,height:t.canvas.height})],this._canvas=new St({width:t.canvas.width,height:t.canvas.height}),this.__ctx=this._canvas.ctx}register(t){this._renderers.set(t.type,t),t.initialize(this.__gl,this)}get(t){return this._renderers.get(t)}_isCurrentRenderer(t){return!this._currentRenderer||this._currentRenderer===t}beginDrawLifecycle(){this._isDrawLifecycle=!0}endDrawLifecycle(){this._isDrawLifecycle=!1}draw(t,...e){this._isDrawLifecycle||this._alreadyWarnedDrawLifecycle||(this._logger.warn("Attempting to draw outside the the drawing lifecycle (preDraw/postDraw) is not supported and is a source of bugs/errors.\nIf you want to do custom drawing, use Actor.graphics, or any onPreDraw or onPostDraw handler."),this._alreadyWarnedDrawLifecycle=!0);const i=this._renderers.get(t);if(!i)throw Error(`No renderer with name ${t} has been registered`);this._currentRenderer||(this._currentRenderer=i),this._isCurrentRenderer(i)||this._currentRenderer.flush(),i.draw(...e),this._currentRenderer=i}resetTransform(){this._transform.current=ct.identity()}updateViewport(t){const e=this.__gl;this._ortho=this._ortho=ct.ortho(0,t.width,t.height,0,400,-400),this._renderTarget.setResolution(e.canvas.width,e.canvas.height),this._postProcessTargets[0].setResolution(e.canvas.width,e.canvas.height),this._postProcessTargets[1].setResolution(e.canvas.width,e.canvas.height),this._canvas.width=e.canvas.width,this._canvas.height=e.canvas.height}drawImage(t,e,i,s,r,n,o,a,h){if(0!==s&&0!==r&&0!==a&&0!==h&&0!==t.width&&0!==t.height)return t?void this.draw("ex.image",t,e,i,s,r,n,o,a,h):(f.getInstance().warn("Cannot draw a null or undefined image"),void(console.trace&&console.trace()))}drawLine(t,e,i,s=1){this._renderers.get("ex.rectangle").drawLine(t,e,i,s)}drawRectangle(t,e,i,s,r,n){this.draw("ex.rectangle",t,e,i,s,r,n)}drawCircle(t,e,i,s,r){this.draw("ex.circle",t,e,i,s,r)}save(){this._transform.save(),this._state.save()}restore(){this._transform.restore(),this._state.restore()}translate(t,e){this._transform.translate(this.snapToPixel?~~t:t,this.snapToPixel?~~e:e)}rotate(t){this._transform.rotate(t)}scale(t,e){this._transform.scale(t,e)}transform(t){this._transform.current=t}getTransform(){return this._transform.current}multiply(t){this._transform.current=this._transform.current.multm(t)}addPostProcessor(t){this._postprocessors.push(t),t.initialize(this.__gl)}removePostProcessor(t){const e=this._postprocessors.indexOf(t);-1!==e&&this._postprocessors.splice(e,1)}clearPostProcessors(){this._postprocessors.length=0}clear(){const t=this.__gl;this._renderTarget.use(),t.clearColor(this.backgroundColor.r/255,this.backgroundColor.g/255,this.backgroundColor.b/255,this.backgroundColor.a),t.clear(t.COLOR_BUFFER_BIT)}flush(){const t=this.__gl;this._renderTarget.use();for(const t of this._renderers.values())t.hasPendingDraws()&&t.flush();this._renderTarget.disable();this._renderTarget.toRenderSource().use();for(let t=0;t<this._postprocessors.length;t++)this._postProcessTargets[t%2].use(),this._screenRenderer.renderWithPostProcessor(this._postprocessors[t]),this._postProcessTargets[t%2].toRenderSource().use();t.bindFramebuffer(t.FRAMEBUFFER,null),this._screenRenderer.renderToScreen()}}var si;!function(t){t.Fixed="Fixed",t.FitScreen="FitScreen",t.FillScreen="FillScreen",t.FitContainer="FitContainer",t.FillContainer="FillContainer",t.Position="Position"}(si||(si={}));class ri{static get SVGA(){return{width:800,height:600}}static get Standard(){return{width:1920,height:1080}}static get Atari2600(){return{width:160,height:192}}static get GameBoy(){return{width:160,height:144}}static get GameBoyAdvance(){return{width:240,height:160}}static get NintendoDS(){return{width:256,height:192}}static get NES(){return{width:256,height:224}}static get SNES(){return{width:256,height:244}}}class ni{constructor(t){var e,i,s;this._antialiasing=!0,this._resolutionStack=[],this._viewportStack=[],this._pixelRatioOverride=null,this._isFullScreen=!1,this._isDisposed=!1,this._logger=f.getInstance(),this._fullscreenChangeHandler=()=>{this._isFullScreen=!this._isFullScreen,this._logger.debug("Fullscreen Change",this._isFullScreen)},this._pixelRatioChangeHandler=()=>{this._logger.debug("Pixel Ratio Change",window.devicePixelRatio),this._listenForPixelRatio(),this._devicePixelRatio=this._calculateDevicePixelRatio(),this.applyResolutionAndViewport()},this._resizeHandler=()=>{const t=this.parent;this._logger.debug("View port resized"),this._setResolutionAndViewportByDisplayMode(t),this.applyResolutionAndViewport()},this._devicePixelRatio=this._calculateDevicePixelRatio(),this._alreadyWarned=!1,this.viewport=t.viewport,this.resolution=null!==(e=t.resolution)&&void 0!==e?e:{...this.viewport},this._displayMode=null!==(i=t.displayMode)&&void 0!==i?i:si.Fixed,this._canvas=t.canvas,this.graphicsContext=t.context,this._antialiasing=null!==(s=t.antialiasing)&&void 0!==s?s:this._antialiasing,this._browser=t.browser,this._position=t.position,this._pixelRatioOverride=t.pixelRatio,this._applyDisplayMode(),this._listenForPixelRatio(),this._canvas.addEventListener("fullscreenchange",this._fullscreenChangeHandler),this.applyResolutionAndViewport()}_listenForPixelRatio(){this._mediaQueryList&&!this._mediaQueryList.addEventListener&&this._mediaQueryList.removeListener(this._pixelRatioChangeHandler),this._mediaQueryList=this._browser.window.nativeComponent.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._mediaQueryList.addEventListener?this._mediaQueryList.addEventListener("change",this._pixelRatioChangeHandler,{once:!0}):this._mediaQueryList.addListener(this._pixelRatioChangeHandler)}dispose(){this._isDisposed||(this._isDisposed=!0,this._browser.window.off("resize",this._resizeHandler),this._resizeObserver&&this._resizeObserver.disconnect(),this.parent.removeEventListener("resize",this._resizeHandler),this._mediaQueryList.removeEventListener?this._mediaQueryList.removeEventListener("change",this._pixelRatioChangeHandler):this._mediaQueryList.removeListener(this._pixelRatioChangeHandler),this._canvas.removeEventListener("fullscreenchange",this._fullscreenChangeHandler))}_calculateDevicePixelRatio(){if(window.devicePixelRatio<1)return 1;return window.devicePixelRatio||1}get pixelRatio(){return this._pixelRatioOverride?this._pixelRatioOverride:this._devicePixelRatio}get isHiDpi(){return 1!==this.pixelRatio}get displayMode(){return this._displayMode}get canvas(){return this._canvas}get parent(){return this.displayMode===si.FillContainer||this.displayMode===si.FitContainer?this.canvas.parentElement||document.body:window}get resolution(){return this._resolution}set resolution(t){this._resolution=t}get viewport(){return this._viewport?this._viewport:this._resolution}set viewport(t){this._viewport=t}get aspectRatio(){return this._resolution.width/this._resolution.height}get scaledWidth(){return this._resolution.width*this.pixelRatio}get scaledHeight(){return this._resolution.height*this.pixelRatio}setCurrentCamera(t){this._camera=t}pushResolutionAndViewport(){this._resolutionStack.push(this.resolution),this._viewportStack.push(this.viewport),this.resolution={...this.resolution},this.viewport={...this.viewport}}peekViewport(){return this._viewportStack[this._viewportStack.length-1]}peekResolution(){return this._resolutionStack[this._resolutionStack.length-1]}popResolutionAndViewport(){this.resolution=this._resolutionStack.pop(),this.viewport=this._viewportStack.pop()}applyResolutionAndViewport(){if(this._canvas.width=this.scaledWidth,this._canvas.height=this.scaledHeight,this.graphicsContext instanceof ii){this.graphicsContext.checkIfResolutionSupported({width:this.scaledWidth,height:this.scaledHeight})||this._alreadyWarned||(this._alreadyWarned=!0,this._logger.warn(`The currently configured resolution (${this.resolution.width}x${this.resolution.height}) is too large for the platform WebGL implementation, this may work but cause WebGL rendering to behave oddly. Try reducing the resolution or disabling Hi DPI scaling to avoid this (read more here https://excaliburjs.com/docs/screens#understanding-viewport--resolution).`))}this._antialiasing?this._canvas.style.imageRendering="auto":(this._canvas.style.imageRendering="pixelated",""===this._canvas.style.imageRendering&&(this._canvas.style.imageRendering="crisp-edges")),this._canvas.style.width=this.viewport.width+"px",this._canvas.style.height=this.viewport.height+"px",this.graphicsContext.updateViewport(this.resolution),this.graphicsContext.resetTransform(),this.graphicsContext.smoothing=this._antialiasing}get antialiasing(){return this._antialiasing}set antialiasing(t){this._antialiasing=t,this.graphicsContext.smoothing=this._antialiasing}get isFullScreen(){return this._isFullScreen}goFullScreen(){return this._canvas.requestFullscreen()}exitFullScreen(){return document.exitFullscreen()}pageToScreenCoordinates(t){let e=t.x,i=t.y;if(this._isFullScreen||(e-=$(this._canvas).x,i-=$(this._canvas).y),this._isFullScreen)if(window.innerWidth/this.aspectRatio<window.innerHeight){const t=window.innerWidth/this.aspectRatio;i=(i-(window.innerHeight-t)/2)/t*this.viewport.height,e=e/window.innerWidth*this.viewport.width}else{const t=window.innerHeight*this.aspectRatio;e=(e-(window.innerWidth-t)/2)/t*this.viewport.width,i=i/window.innerHeight*this.viewport.height}return e=e/this.viewport.width*this.resolution.width,i=i/this.viewport.height*this.resolution.height,new A(e,i)}screenToPageCoordinates(t){let e=t.x,i=t.y;if(e=e/this.resolution.width*this.viewport.width,i=i/this.resolution.height*this.viewport.height,this._isFullScreen)if(window.innerWidth/this.aspectRatio<window.innerHeight){const t=window.innerWidth/this.aspectRatio,s=(window.innerHeight-t)/2;i=i/this.viewport.height*t+s,e=e/this.viewport.width*window.innerWidth}else{const t=window.innerHeight*this.aspectRatio,s=(window.innerWidth-t)/2;e=e/this.viewport.width*t+s,i=i/this.viewport.height*window.innerHeight}return this._isFullScreen||(e+=$(this._canvas).x,i+=$(this._canvas).y),new A(e,i)}screenToWorldCoordinates(t){return this._camera?this._camera.inverse.multv(t):t.sub(P(this.resolution.width/2,this.resolution.height/2))}worldToScreenCoordinates(t){return this._camera?this._camera.transform.multv(t):t.add(P(this.resolution.width/2,this.resolution.height/2))}pageToWorldCoordinates(t){const e=this.pageToScreenCoordinates(t);return this.screenToWorldCoordinates(e)}worldToPageCoordinates(t){const e=this.worldToScreenCoordinates(t);return this.screenToPageCoordinates(e)}getWorldBounds(){const t=this.screenToWorldCoordinates(A.Zero),e=t.x+this.drawWidth,i=t.y+this.drawHeight;return new D(t.x,t.y,e,i)}get canvasWidth(){return this.canvas.width}get halfCanvasWidth(){return this.canvas.width/2}get canvasHeight(){return this.canvas.height}get halfCanvasHeight(){return this.canvas.height/2}get drawWidth(){return this._camera?this.resolution.width/this._camera.zoom:this.resolution.width}get halfDrawWidth(){return this.drawWidth/2}get drawHeight(){return this._camera?this.resolution.height/this._camera.zoom:this.resolution.height}get halfDrawHeight(){return this.drawHeight/2}get center(){return P(this.halfDrawWidth,this.halfDrawHeight)}_computeFit(){document.body.style.margin="0px",document.body.style.overflow="hidden";const t=this.aspectRatio;let e=0,i=0;window.innerWidth/t<window.innerHeight?(e=window.innerWidth,i=window.innerWidth/t):(e=window.innerHeight*t,i=window.innerHeight),this.viewport={width:e,height:i}}_computeFitContainer(){const t=this.aspectRatio;let e=0,i=0;const s=this.canvas.parentElement;s.clientWidth/t<s.clientHeight?(e=s.clientWidth,i=s.clientWidth/t):(e=s.clientHeight*t,i=s.clientHeight),this.viewport={width:e,height:i}}_applyDisplayMode(){this.displayMode===si.Position?this._initializeDisplayModePosition(this._position):(this._setResolutionAndViewportByDisplayMode(this.parent),this.parent instanceof Window?this._browser.window.on("resize",this._resizeHandler):(this._resizeObserver=new ResizeObserver((()=>{this._resizeHandler()})),this._resizeObserver.observe(this.parent)),this.parent.addEventListener("resize",this._resizeHandler))}_setResolutionAndViewportByDisplayMode(t){this.displayMode===si.FillContainer&&(this.resolution={width:t.clientWidth,height:t.clientHeight},this.viewport=this.resolution),this.displayMode===si.FillScreen&&(document.body.style.margin="0px",document.body.style.overflow="hidden",this.resolution={width:t.innerWidth,height:t.innerHeight},this.viewport=this.resolution),this.displayMode===si.FitScreen&&this._computeFit(),this.displayMode===si.FitContainer&&this._computeFitContainer()}_initializeDisplayModePosition(t){if(!t)throw new Error("DisplayMode of Position was selected but no position option was given");if(this.canvas.style.display="block",this.canvas.style.position="absolute","string"==typeof t){const e=t.split(" ");switch(e[0]){case"top":this.canvas.style.top="0px";break;case"bottom":this.canvas.style.bottom="0px";break;case"middle":this.canvas.style.top="50%";const t=-this.halfDrawHeight;this.canvas.style.marginTop=t.toString();break;default:throw new Error("Invalid Position Given")}if(e[1])switch(e[1]){case"left":this.canvas.style.left="0px";break;case"right":this.canvas.style.right="0px";break;case"center":this.canvas.style.left="50%";const t=-this.halfDrawWidth;this.canvas.style.marginLeft=t.toString();break;default:throw new Error("Invalid Position Given")}}else t.top&&("number"==typeof t.top?this.canvas.style.top=t.top.toString()+"px":this.canvas.style.top=t.top),t.right&&("number"==typeof t.right?this.canvas.style.right=t.right.toString()+"px":this.canvas.style.right=t.right),t.bottom&&("number"==typeof t.bottom?this.canvas.style.bottom=t.bottom.toString()+"px":this.canvas.style.bottom=t.bottom),t.left&&("number"==typeof t.left?this.canvas.style.left=t.left.toString()+"px":this.canvas.style.left=t.left)}}class oi{static create(){return this._INSTANCE||(window.AudioContext||window.webkitAudioContext)&&(this._INSTANCE=new AudioContext),this._INSTANCE}}oi._INSTANCE=null;class ai{static unlock(){return new Promise(((t,e)=>{if(ai._UNLOCKED||!oi.create())return t(!0);const i=setTimeout((()=>{f.getInstance().warn("Excalibur was unable to unlock the audio context, audio probably will not play in this browser."),t(!1)}),200),s=oi.create();s.resume().then((()=>{const e=s.createBuffer(1,1,22050),r=s.createBufferSource();let n=!1;r.buffer=e,r.connect(s.destination),r.onended=()=>n=!0,r.start(0),setTimeout((()=>{!function(t){return!!t.playbackState}(r)?(s.currentTime>0||n)&&(ai._UNLOCKED=!0):r.playbackState!==r.PLAYING_STATE&&r.playbackState!==r.FINISHED_STATE||(ai._UNLOCKED=!0)}),0),clearTimeout(i),t(!0)}),(()=>{e()}))}))}static isUnlocked(){return this._UNLOCKED}}ai._UNLOCKED=!1;class hi{constructor(){this.eventDispatcher=new he}on(t,e){this.eventDispatcher.on(t,e)}off(t,e){this.eventDispatcher.off(t,e)}emit(t,e){this.eventDispatcher.emit(t,e)}once(t,e){this.eventDispatcher.once(t,e)}}function li(t,e=I.Red,i,s,r,n,o=1,a="butt"){t.save(),t.beginPath(),t.lineWidth=o,t.lineCap=a,t.strokeStyle=e.toString(),t.moveTo(i,s),t.lineTo(r,n),t.closePath(),t.stroke(),t.restore()}function ci(t,e=I.Red,i){t.beginPath(),t.strokeStyle=e.toString(),t.arc(i.x,i.y,5,0,2*Math.PI),t.closePath(),t.stroke()}function di(t,e,i,s,r=1){const n=e?e.toString():"blue",o=s.scale(r);t.beginPath(),t.strokeStyle=n,t.moveTo(i.x,i.y),t.lineTo(i.x+o.x,i.y+o.y),t.closePath(),t.stroke()}function ui(t,e,i,s,r,n=5,o=I.White,a=null){let h;if("number"==typeof n)h={tl:n,tr:n,br:n,bl:n};else{const t={tl:0,tr:0,br:0,bl:0};for(const e in t)if(t.hasOwnProperty(e)){const i=e;h[i]=n[i]||t[i]}}t.beginPath(),t.moveTo(e+h.tl,i),t.lineTo(e+s-h.tr,i),t.quadraticCurveTo(e+s,i,e+s,i+h.tr),t.lineTo(e+s,i+r-h.br),t.quadraticCurveTo(e+s,i+r,e+s-h.br,i+r),t.lineTo(e+h.bl,i+r),t.quadraticCurveTo(e,i+r,e,i+r-h.bl),t.lineTo(e,i+h.tl),t.quadraticCurveTo(e,i,e+h.tl,i),t.closePath(),a&&(t.fillStyle=a.toString(),t.fill()),o&&(t.strokeStyle=o.toString(),t.stroke())}function pi(t,e,i,s,r=I.White,n=null){t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.closePath(),n&&(t.fillStyle=n.toString(),t.fill()),r&&(t.strokeStyle=r.toString(),t.stroke())}var gi=i(1388);class _i extends hi{constructor(t){super(),this.canvas=new St({filtering:ht.Blended,smoothing:!0,draw:this.draw.bind(this)}),this._resourceList=[],this._index=0,this._playButtonShown=!1,this._resourceCount=0,this._numLoaded=0,this._progressCounts={},this._totalCounts={},this.logo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdQAAAB2CAYAAABxhGI9AAAACXBIWXMAAAsSAAALEgHS3X78AAAKnUlEQVR42u3dP2wjSx0H8N8hJIonIRmJjsq0SBR+BQ1dcqKhe0lD77SvSwpKkJKGPulpktfRIMUdEqKIqV57rpAokM4dbSiyq7ONPTP7x39ifz7SFbnEnp3xer47O7uzH15fXwMA6OYHmgAABCoACFQAEKgAgEAFAIEKAAIVAAQqACBQAUCgAoBABQCBCgAIVAAQqAAgUAFAoAIAAhUABCoACFQAEKgAgECFLbmOiNeFf2PbAyz68Pr6qhUgbRwR92v+/zwiJrYHMEKFMmcN///UtgcQqFBk1PD/97U9Qx8VCFSgu4EmAIEKAAIVAAQqACBQ4Z25jojP8eX+0WtNAgIVaOY+Im5j+eKh24h41jQgUIEyZ7F5NaPU7wCBCiwYd/w9cOB+qAlgJ3KLLow0EV198803RWvJfvfddx+0lhEqHKu5JgAjVCBvlhmFzjQRXUekHz9+TP79y8uLRjNChXfvoePvAYEKxNtj1e42/O5JoIJABcrdRMRVLM+X3kTEpaaB988cKuzWg9EobTWdMx0Oly8uN4dqhAoARqgnaN3arHfqu7OyH8ItKLVB/P+CEfMTHyGPY3npx1m8zWGDEeoBfUk/xdti57dr/r1Wv2+6EPow3tZ5rRdS72s1neuF97xvWd+XTH0/V+UMttDWqbI/r2nrxfp+jv2uSjSO7S+OXy/A/3lN+9xX5T5HxEUPZZ0tfB71+w57eJ/HFu+z+jkv1u92YX9fbI/HhX3JA9rp5MPr66tWaG9UfUGbrHIzi7cLUyYFf/tpTady03EEeL8mUJ6i7MKYNvWNqr4Pe2jradXO60LrvPAz2PQ5RPX684ah8dxD+2zantnCgVipSVV+m/tgB9W2DDq2Sx/vM95wcHhZhWVJm8yrv58cSgfTdc70+++/X/r522+/tUKSEepBqo+om4ZLPerMjUwuNnQCtx1GWJtee1FwdD5uWd86xLs8UaVt2aNEO1/saZ/Z5rYMW4zq6v34rGV9Bg3q2eZ9SkeNm9qwyUh30OPIHYFKx5FG03C7znSOqYBq+qW/zpQ3anH037TNHluG6f0WPsPhHvab4QFty7ogOeuxDYcNy2/zu2214WNYWxmBurNO8bGn97pNBOO8xy/9uCorZZ4I2r4C7aJgO7ZV9iE49Dm6NvOWx+pWE9CUq3zbdTp9doz38TbXtzqH9RT5CyWe422OaZoZGeZCabrhPQY9HjwsjpTvCg4YtlE2+Ta/j2bzn8fqrDqgm+6yUHOmAvWUjAtGhbNYvsBknDnqH1Qhc7VmxHgeb/NbudA5j/UXlYwif2p6luhAc9teu1npiHKnDs8if6tCm7JLX3NKpgttXe9ruc9mHMd7a83iwdxF5vt8tutARaCeklRnNK9C8WnNF7geJQ4T4XG3JhSnVdilQrG+yOnrlVHfsEGYzhNBn7Lu6tS7+HJafJQ4EMiNlNqWXZ9WPvVgnVYHG5M1ByDXkT6leX2EgTqJtyt45yv7S2qO3sEZjZhDLXeR+YKdJ0Zdk8QocvH9N732KrNtq+FZ/zzIHABcJrYpd+Xv14lOd5ap76SgrduW/VTQ1qcQpqnbgu4ifZvUMNpd9XuoZmvCtPaQ2Y/BCHVLgbrJTeRPDdVf6pfMKDU2fOkHmVFFfXr3MsouLsnNvV5kRoe5+s431PeuoKPqWnaurY/ZPBEeqwceN4l96iwO6H7Mjq4y7VGPVNe10VaZMzVCPVWpI/Z6FZbcv5fMqGCU+dLfFGzj58jP8+bCdJCo7yzKTwdOF0bu9Ug7V4c+yz7FJfYeGoysUss0HssIdVZwYLDujMqlESoCdTtGsZtbHnJBeNdDSJSs0jTKdMJN1HNX54Wv7bvsU9NkVJVa13dX+/wuArV0X/l5RHyo/lnfF4G6p6DrS0kHdtXhy35TGErDPYZUn2WfWqDOo/lVqdMD2O/hKJhD7S/odukymq9s02QN4EEPR/zbaOumZc+r15zK1Zqznl9jsfiemTM1QmV3HUuTkedlg9HIQzRbUD93dfC+2tpj2fIHEH2+RqCCQH13gZq7hWXTNpVu19OB1fc9nQ0AKOKUb5lU0P1kDyOneoWk0lOZ9cIP0x7qu8+2BhCoR2wYu1+e7DmaXzBSsu5vaX1ne2zrpmUPTmxf7PM1Dm4y/vC7ny7Nif7+z/9ZmtM0Z3panPLtPmra9f16bcK0Dpbnwk43Vd/RHtu6zfNQTy1QBy3aqG2g9nVmxml+BOoJyT3NpWmn9xhfFnu4bvDa+44BXhqqfdf3uUF9+yz77AT31Yue2mjecYQ62NLfgkA9ghHqLNEhNem4H1c6vdyDxhf/bpz5m4coW/c39wi6VH2bPtHlcaV9cvXts+zxCe6rTeqc2ndL7uGd93QwM9bFcAzMoZZ7SgTBbWx+asui61h/iq1+RmjqdbnQXQ3T1DNQ63V/U9ucqm/pMzPb1rePsk/1iTOjgvatR4W3Lc8ULB78pELyrnAfeTcj1NU509/86mfJ33/8+Mf00a05UyPUEw7UVCeWG/WNEiExyHRMt5ltW30izUPk18ytt7lNfc8i//DvtvXto+ySA5BjljsLUF8lPkqMPEtW1JomDsiGBZ9Byb4NAvUITSN9GuwsIj6t6UTOqk7jJREkmzqli8xIs96udSO20sX0H1vW92IL9e1a9rgqVyf91gbPsTy9UD9n9lOkT8k+RfkFR5PMNqxOcdSf32PBvg3vilO+zdxE+okx9Wm0ph36XYsRZCpMF993GOk5qvqB3Dct6jvssb67KvuUNJ3frw92bhr8/STSF0JdRPMLpUCgnsgo9S76PZ246ZFk1wWvK5m3vVoYvW1Sz7nN91jfXbQ1ZQc7TW6HeaoOalypG/8/p/rP1aNAc6ZHzSnfdqPUPhdy2PQw6Nz9gSVhuhiqueUHR3uu7y7K3rdDX4u46ZrPbUa0IFBZ0seKQ3XQTRt2vm3W/a2DbNKys++rvm3ep6+y1x2UdP3bWU9lzra47U1GmlctX/sQ23t+aOlByLTh/4NAPaCRxtcdO5HLSJ/6vNtCwGx67VPmPbvWd1q9frKHtp4kAqRJ2HR9j762JfX3bZ//elPtj13PPDx1+D5tqk/Xi6NO8SHz7MmH19dXrdBNfVFP6T2PT1UHNit87/t4m5+aRH+nQBdvqyhZDKJLfZs8h7XPsqdV2ZOV+tanKB8aln0dyxdAXbV4j4gvt4oMOrbP6vbU73NW7TMlbdTnPrWpfqXfh9HKZ9vke7KuTeZRNtXRSe6+1FV//ce/ln5eXfsXgcqXzr6+9261M3moOoa7E6nvTZTfy7iNsmfb7kjfgXGsvxe0vihsEts9HTquPpt1q1vtahu2TqAiUAEEKj0zhwoARqgAu/OnX/442WH+9xc/Wvr58re/Tr7f41/+ZsRqhAoACFQAEKgAcHjMoQJskJsz/eqrr5Z+vvr7v5fmQFevAl5lztQIFQAQqAAgUAHgIJlDBdhgdQ41N2eKESoAIFABQKACwFEwhwoARqgAIFABQKACAAIVAAQqAAhUABCoAIBABQCBCgACFQAEKgAgUAFAoAKAQAUAgQoACFQAEKgAIFABQKACAAIVAAQqAAhUABCoAIBABQCBCgACFQAQqAAgUAFAoAKAQAUAlvwPcFDns1DsH4sAAAAASUVORK5CYII=",this.logoWidth=468,this.logoHeight=118,this.loadingBarColor=I.White,this.backgroundColor="#176BAA",this.suppressPlayButton=!1,this._playButtonStyles=gi.Z.toString(),this.playButtonText="Play game",this.startButtonFactory=()=>{let t=document.getElementById("excalibur-play");return t||(t=document.createElement("button")),t.id="excalibur-play",t.textContent=this.playButtonText,t.style.display="none",t},this._isLoadedPromise=new Promise((t=>{this._isLoadedResolve=t})),t&&this.addResources(t)}get _image(){return this._imageElement||(this._imageElement=new Image,this._imageElement.src=this.logo),this._imageElement}get playButtonRootElement(){return this._playButtonRootElement}get playButtonElement(){return this._playButtonElement}get _playButton(){const t=document.getElementById("excalibur-play-root");return t&&(this._playButtonRootElement=t),this._playButtonRootElement||(this._playButtonRootElement=document.createElement("div"),this._playButtonRootElement.id="excalibur-play-root",this._playButtonRootElement.style.position="absolute",document.body.appendChild(this._playButtonRootElement)),this._styleBlock||(this._styleBlock=document.createElement("style"),this._styleBlock.textContent=this._playButtonStyles,document.head.appendChild(this._styleBlock)),this._playButtonElement||(this._playButtonElement=this.startButtonFactory(),this._playButtonRootElement.appendChild(this._playButtonElement)),this._playButtonElement}wireEngine(t){this._engine=t,this.canvas.width=this._engine.canvas.width,this.canvas.height=this._engine.canvas.height}addResource(t){const e=this._index++;this._resourceList.push(t),this._progressCounts[e]=0,this._totalCounts[e]=1,this._resourceCount++}addResources(t){let e=0;const i=t.length;for(;e<i;e++)this.addResource(t[e])}isLoaded(){return this._numLoaded===this._resourceCount}async showPlayButton(){var t,e;if(!this.suppressPlayButton){const t=()=>{this._positionPlayButton()};(null===(e=this._engine)||void 0===e?void 0:e.browser)&&this._engine.browser.window.on("resize",t),this._playButtonShown=!0,this._playButton.style.display="block",document.body.addEventListener("keyup",(t=>{"Enter"===t.key&&this._playButton.click()})),this._positionPlayButton();const i=new Promise((e=>{const i=i=>{var s;i.stopPropagation(),this.hidePlayButton(),(null===(s=this._engine)||void 0===s?void 0:s.browser)&&this._engine.browser.window.off("resize",t),e()};this._playButton.addEventListener("click",i),this._playButton.addEventListener("touchend",i),this._playButton.addEventListener("pointerup",i)}));return await i}this.hidePlayButton(),await ot(500,null===(t=this._engine)||void 0===t?void 0:t.clock)}hidePlayButton(){this._playButtonShown=!1,this._playButton.style.display="none"}dispose(){this._playButtonRootElement.parentElement&&(this._playButtonRootElement.removeChild(this._playButtonElement),document.body.removeChild(this._playButtonRootElement),document.head.removeChild(this._styleBlock),this._playButtonRootElement=null,this._playButtonElement=null,this._styleBlock=null)}update(t,e){}areResourcesLoaded(){return this._isLoadedPromise}async load(){var t,e;return await(null===(t=this._image)||void 0===t?void 0:t.decode()),await Promise.all(this._resourceList.map((t=>t.load().finally((()=>{this._numLoaded++}))))),this._isLoadedResolve(),await ot(200,null===(e=this._engine)||void 0===e?void 0:e.clock),await this.showPlayButton(),await ai.unlock(),this.data=this._resourceList}markResourceComplete(){this._numLoaded++}get progress(){return this._resourceCount>0?z(this._numLoaded,0,this._resourceCount)/this._resourceCount:1}_positionPlayButton(){if(this._engine){const t=this._engine.screen.viewport.height,e=this._engine.screen.viewport.width;if(this._playButtonRootElement){const i=this._engine.canvas.offsetLeft,s=this._engine.canvas.offsetTop,r=this._playButton.clientWidth,n=this._playButton.clientHeight;this.playButtonPosition?(this._playButtonRootElement.style.left=`${this.playButtonPosition.x}px`,this._playButtonRootElement.style.top=`${this.playButtonPosition.y}px`):(this._playButtonRootElement.style.left=i+e/2-r/2+"px",this._playButtonRootElement.style.top=s+t/2-n/2+100+"px")}}}draw(t){const e=this._engine.canvasHeight/this._engine.pixelRatio,i=this._engine.canvasWidth/this._engine.pixelRatio;this._positionPlayButton(),t.fillStyle=this.backgroundColor,t.fillRect(0,0,i,e);let s=e/2;const r=Math.min(this.logoWidth,.75*i);let n=i/2-r/2;this.logoPosition&&(n=this.logoPosition.x,s=this.logoPosition.y);const o=Math.floor(r*(this.logoHeight/this.logoWidth)),a=this._engine.getAntialiasing();if(this._engine.setAntialiasing(!0),this.logoPosition?t.drawImage(this._image,0,0,this.logoWidth,this.logoHeight,n,s,r,o):t.drawImage(this._image,0,0,this.logoWidth,this.logoHeight,n,s-o-20,r,o),!this.suppressPlayButton&&this._playButtonShown)return void this._engine.setAntialiasing(a);let h=n,l=s;this.loadingBarPosition&&(h=this.loadingBarPosition.x,l=this.loadingBarPosition.y),t.lineWidth=2,ui(t,h,l,r,20,10,this.loadingBarColor);const c=r*this.progress-10;ui(t,h+5,l+5,c>10?c:10,10,5,null,this.loadingBarColor),this._engine.setAntialiasing(a)}}const fi={webgl:"WebGL",webaudio:"WebAudio",gamepadapi:"Gamepad API"};class mi{constructor(){this._features=null,this.failedTests=[],this._criticalTests={canvasSupport:function(){const t=document.createElement("canvas");return!(!t.getContext||!t.getContext("2d"))},arrayBufferSupport:function(){const t=new XMLHttpRequest;t.open("GET","/");try{t.responseType="arraybuffer"}catch(t){return!1}return"arraybuffer"===t.responseType},dataUrlSupport:function(){return 0===document.createElement("canvas").toDataURL("image/png").indexOf("data:image/png")},objectUrlSupport:function(){return"URL"in window&&"revokeObjectURL"in URL&&"createObjectURL"in URL},rgbaSupport:function(){const t=document.createElement("a").style;return t.cssText="background-color:rgba(150,255,150,.5)",(""+t.backgroundColor).indexOf("rgba")>-1}},this._warningTest={webAudioSupport:function(){return!!(window.AudioContext||window.webkitAudioContext||window.mozAudioContext||window.msAudioContext||window.oAudioContext)},webglSupport:function(){const t=document.createElement("canvas");return!(!t.getContext||!t.getContext("webgl"))}},this._features=this._loadBrowserFeatures()}getBrowserFeatures(){return null===this._features&&(this._features=this._loadBrowserFeatures()),this._features}logBrowserFeatures(){let t="%cSUPPORTED BROWSER FEATURES\n==========================%c\n";const e=["font-weight: bold; color: navy","font-weight: normal; color: inherit"],i=this.getBrowserFeatures();for(const s of Object.keys(fi))i[s]?(t+="(%c✓%c)",e.push("font-weight: bold; color: green"),e.push("font-weight: normal; color: inherit")):(t+="(%c✗%c)",e.push("font-weight: bold; color: red"),e.push("font-weight: normal; color: inherit")),t+=" "+fi[s]+"\n";e.unshift(t),console.log.apply(console,e)}_loadBrowserFeatures(){return{canvas:(()=>this._criticalTests.canvasSupport())(),arraybuffer:(()=>this._criticalTests.arrayBufferSupport())(),dataurl:(()=>this._criticalTests.dataUrlSupport())(),objecturl:(()=>this._criticalTests.objectUrlSupport())(),rgba:(()=>this._criticalTests.rgbaSupport())(),webaudio:(()=>this._warningTest.webAudioSupport())(),webgl:(()=>this._warningTest.webglSupport())(),gamepadapi:!!navigator.getGamepads}}test(){let t=!1;for(const e in this._criticalTests)this._criticalTests[e].call(this)||(this.failedTests.push(e),f.getInstance().error("Critical browser feature missing, Excalibur requires:",e),t=!0);if(t)return!1;for(const t in this._warningTest)this._warningTest[t]()||f.getInstance().warn("Warning browser feature missing, Excalibur will have reduced performance:",t);return!0}}var vi;!function(t){t.PreventCollision="PreventCollision",t.Passive="Passive",t.Active="Active",t.Fixed="Fixed"}(vi||(vi={}));var yi,wi,xi,bi=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};!function(t){t.Arcade="arcade",t.Realistic="realistic"}(yi||(yi={})),function(t){t[t.DynamicAABBTree=0]="DynamicAABBTree"}(wi||(wi={})),function(t){t[t.Euler=0]="Euler"}(xi||(xi={}));class Ci{static get gravity(){return Ci.acc}static set gravity(t){Ci.acc=t}static useArcadePhysics(){Ci.collisionResolutionStrategy=yi.Arcade}static useRealisticPhysics(){Ci.collisionResolutionStrategy=yi.Realistic}static get dynamicTreeVelocityMultiplyer(){return Ci.dynamicTreeVelocityMultiplier}static set dynamicTreeVelocityMultiplyer(t){Ci.dynamicTreeVelocityMultiplier=t}}Ci.acc=new A(0,0),Ci.enabled=!0,Ci.broadphaseStrategy=wi.DynamicAABBTree,Ci.collisionResolutionStrategy=yi.Arcade,Ci.defaultMass=10,Ci.integrator=xi.Euler,Ci.dynamicTreeVelocityMultiplier=2,Ci.boundsPadding=5,Ci.positionIterations=3,Ci.velocityIterations=8,Ci.slop=1,Ci.steeringFactor=.2,Ci.warmStart=!0,Ci.bodiesCanSleepByDefault=!1,Ci.surfaceEpsilon=.1,Ci.sleepEpsilon=.07,Ci.wakeThreshold=3*Ci.sleepEpsilon,Ci.sleepBias=.9,Ci.checkForFastBodies=!0,Ci.disableMinimumSpeedForFastBody=!1,bi([C({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"dynamicTreeVelocityMultiplier"})],Ci,"dynamicTreeVelocityMultiplyer",null);class Si extends A{constructor(t){super(0,0),this._getX=t.getX,this._getY=t.getY,this._setX=t.setX,this._setY=t.setY}get x(){return this._x=this._getX()}set x(t){this._setX(t),this._x=t}get y(){return this._y=this._getY()}set y(t){this._setY(t),this._y=t}}class Ai{constructor(){this.owner=null}clone(){const t=new this.constructor;for(const i in this)if(this.hasOwnProperty(i)){const s=this[i];(null==(e=s)?void 0:e.clone)&&"owner"!==i&&"clone"!==i?t[i]=s.clone():t[i]=s}var e;return t}}class Pi extends Ai{constructor(t,e){super(),this.type=t,this.value=e}}var Ti;!function(t){t.World="world",t.Screen="screen"}(Ti||(Ti={}));class Ei extends Ai{constructor(){super(...arguments),this.type="ex.transform",this._dirty=!1,this.matrix=ct.identity().translate(0,0).rotate(0).scale(1,1),this._position=(t=>{const e=t;return new Si({setX:t=>{e.data[at.X]=t},setY:t=>{e.data[at.Y]=t},getX:()=>e.data[at.X],getY:()=>e.data[at.Y]})})(this.matrix),this._rotation=0,this._scale=(t=>{const e=t;return new Si({setX:t=>{e.setScaleX(t)},setY:t=>{e.setScaleY(t)},getX:()=>e.getScaleX(),getY:()=>e.getScaleY()})})(this.matrix),this.coordPlane=Ti.World,this.z=0}_recalculate(){this._rotation=this.matrix.getRotation(),this._dirty=!1}getGlobalMatrix(){return this.parent?this.parent.getGlobalMatrix().multm(this.matrix):this.matrix}getGlobalTransform(){return{pos:this.globalPos,scale:this.globalScale,rotation:this.globalRotation,z:this.z,coordPlane:this.coordPlane}}get parent(){var t,e;return null===(e=null===(t=null==this?void 0:this.owner)||void 0===t?void 0:t.parent)||void 0===e?void 0:e.get(Ei)}get pos(){return this._dirty&&this._recalculate(),this._position}set pos(t){this.matrix.setPosition(t.x,t.y),this._dirty=!0}get dirty(){var t;if(null===(t=null==this?void 0:this.owner)||void 0===t?void 0:t.parent){return this.parent.dirty||this._dirty}return this._dirty}get globalPos(){const t=this.getGlobalMatrix();return new Si({getX:()=>t.data[at.X],getY:()=>t.data[at.Y],setX:e=>{var i;if(this.parent){const[s]=null===(i=this.parent)||void 0===i?void 0:i.getGlobalMatrix().getAffineInverse().multv([e,t.data[at.Y]]);this.matrix.data[at.X]=s}else this.matrix.data[at.X]=e},setY:e=>{var i;if(this.parent){const[,s]=null===(i=this.parent)||void 0===i?void 0:i.getGlobalMatrix().getAffineInverse().multv([t.data[at.X],e]);this.matrix.data[at.Y]=s}else this.matrix.data[at.Y]=e}})}set globalPos(t){const e=this.parent;this.pos=e?e.getGlobalMatrix().getAffineInverse().multv(t):t}get rotation(){return this._dirty&&this._recalculate(),this._rotation}set rotation(t){this.matrix.setRotation(t),this._dirty=!0}get globalRotation(){return this.getGlobalMatrix().getRotation()}set globalRotation(t){const e=this.parent;this.rotation=e?t-e.globalRotation:t}get scale(){return this._dirty&&this._recalculate(),this._scale}set scale(t){this.matrix.setScale(t),this._dirty=!0}get globalScale(){const t=this.getGlobalMatrix();return new Si({getX:()=>t.getScaleX(),getY:()=>t.getScaleY(),setX:t=>{if(this.parent){const e=this.parent.globalScale.x;this.matrix.setScaleX(t/e)}else this.matrix.setScaleX(t)},setY:t=>{if(this.parent){const e=this.parent.globalScale.y;this.matrix.setScaleY(t/e)}else this.matrix.setScaleY(t)}})}set globalScale(t){const e=this.parent;this.scale=e?P(t.x/e.globalScale.x,t.y/e.globalScale.y):t}apply(t){return this.matrix.multv(t)}applyInverse(t){return this.matrix.getAffineInverse().multv(t)}}class Ii extends Ai{constructor(){super(...arguments),this.type="ex.motion",this.vel=A.Zero,this.acc=A.Zero,this.scaleFactor=A.Zero,this.angularVelocity=0,this.torque=0,this.inertia=1}}class Ri{constructor(t,e,i){this._name=t,this._category=e,this._mask=i}get name(){return this._name}get category(){return this._category}get mask(){return this._mask}canCollide(t){return 0!=(this.category&t.mask)&&0!=(t.category&this.mask)}invert(){return new Ri("~("+this.name+")",~this.category,~this.mask)}static combine(t){const e=t.map((t=>t.name)).join("+"),i=t.reduce(((t,e)=>e.category|t),0);return new Ri(e,i,~i)}static collidesWith(t){return Ri.combine(t).invert()}}Ri.All=new Ri("Collide with all groups",-1,-1);class Di{constructor(){this.observers=[],this.subscriptions=[]}register(t){this.observers.push(t)}subscribe(t){this.subscriptions.push(t)}unregister(t){const e=this.observers.indexOf(t);-1!==e&&this.observers.splice(e,1)}unsubscribe(t){const e=this.subscriptions.indexOf(t);-1!==e&&this.subscriptions.splice(e,1)}notifyAll(t){this.observers.forEach((e=>e.notify(t))),this.subscriptions.forEach((e=>e(t)))}clear(){this.observers.length=0,this.subscriptions.length=0}}class Bi{constructor(t,e){this.colliderA=t,this.colliderB=e,this.id=null,this.id=Bi.calculatePairHash(t.id,e.id)}static canCollide(t,e){var i,s;const r=null===(i=null==t?void 0:t.owner)||void 0===i?void 0:i.get($i),n=null===(s=null==e?void 0:e.owner)||void 0===s?void 0:s.get($i);return t.id!==e.id&&((!t.owner||!e.owner||t.owner.id!==e.owner.id)&&(!t.localBounds.hasZeroDimensions()&&!e.localBounds.hasZeroDimensions()&&(!(!r||!n)&&(!!r.group.canCollide(n.group)&&((r.collisionType!==vi.Fixed||n.collisionType!==vi.Fixed)&&(n.collisionType!==vi.PreventCollision&&r.collisionType!==vi.PreventCollision&&!(!r.active||!n.active)))))))}get canCollide(){const t=this.colliderA,e=this.colliderB;return Bi.canCollide(t,e)}collide(){return this.colliderA.collide(this.colliderB)}hasCollider(t){return t===this.colliderA||t===this.colliderB}static calculatePairHash(t,e){return t.value<e.value?`#${t.value}+${e.value}`:`#${e.value}+${t.value}`}}class Mi{constructor(t,e){this.min=t,this.max=e}overlaps(t){return this.max>t.min&&t.max>this.min}getOverlap(t){return this.overlaps(t)?this.max>t.max?t.max-this.min:this.max-t.min:0}}class ki{constructor(t){this.parent=t,this.parent=t||null,this.data=null,this.bounds=new D,this.left=null,this.right=null,this.height=0}isLeaf(){return!this.left&&!this.right}}class Fi{constructor(t=new D(-Number.MAX_VALUE,-Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)){this.worldBounds=t,this.root=null,this.nodes={}}_insert(t){if(null===this.root)return this.root=t,void(this.root.parent=null);const e=t.bounds;let i=this.root;for(;!i.isLeaf();){const t=i.left,s=i.right,r=i.bounds.getPerimeter(),n=i.bounds.combine(e).getPerimeter(),o=2*n,a=2*(n-r);let h=0;const l=e.combine(t.bounds);let c,d;t.isLeaf()?h=l.getPerimeter()+a:(d=t.bounds.getPerimeter(),c=l.getPerimeter(),h=c-d+a);let u=0;const p=e.combine(s.bounds);if(s.isLeaf()?u=p.getPerimeter()+a:(d=s.bounds.getPerimeter(),c=p.getPerimeter(),u=c-d+a),o<h&&o<u)break;i=h<u?t:s}const s=i.parent,r=new ki(s);r.bounds=e.combine(i.bounds),r.height=i.height+1,null!==s?(s.left===i?s.left=r:s.right=r,r.left=i,r.right=t,i.parent=r,t.parent=r):(r.left=i,r.right=t,i.parent=r,t.parent=r,this.root=r);let n=t.parent;for(;n;){if(n=this._balance(n),!n.left)throw new Error("Parent of current leaf cannot have a null left child"+n);if(!n.right)throw new Error("Parent of current leaf cannot have a null right child"+n);n.height=1+Math.max(n.left.height,n.right.height),n.bounds=n.left.bounds.combine(n.right.bounds),n=n.parent}}_remove(t){if(t===this.root)return void(this.root=null);const e=t.parent,i=e.parent;let s;if(s=e.left===t?e.right:e.left,i){i.left===e?i.left=s:i.right=s,s.parent=i;let t=i;for(;t;)t=this._balance(t),t.bounds=t.left.bounds.combine(t.right.bounds),t.height=1+Math.max(t.left.height,t.right.height),t=t.parent}else this.root=s,s.parent=null}trackCollider(t){const e=new ki;e.data=t,e.bounds=t.bounds,e.bounds.left-=2,e.bounds.top-=2,e.bounds.right+=2,e.bounds.bottom+=2,this.nodes[t.id.value]=e,this._insert(e)}updateCollider(t){var e;const i=this.nodes[t.id.value];if(!i)return!1;const s=t.bounds;if(!this.worldBounds.contains(s))return f.getInstance().warn("Collider with id "+t.id.value+" is outside the world bounds and will no longer be tracked for physics"),this.untrackCollider(t),!1;if(i.bounds.contains(s))return!1;if(this._remove(i),s.left-=Ci.boundsPadding,s.top-=Ci.boundsPadding,s.right+=Ci.boundsPadding,s.bottom+=Ci.boundsPadding,t.owner){const i=null===(e=t.owner)||void 0===e?void 0:e.get($i);if(i){const t=32*i.vel.x/1e3*Ci.dynamicTreeVelocityMultiplier,e=32*i.vel.y/1e3*Ci.dynamicTreeVelocityMultiplier;t<0?s.left+=t:s.right+=t,e<0?s.top+=e:s.bottom+=e}}return i.bounds=s,this._insert(i),!0}untrackCollider(t){const e=this.nodes[t.id.value];e&&(this._remove(e),this.nodes[t.id.value]=null,delete this.nodes[t.id.value])}_balance(t){if(null===t)throw new Error("Cannot balance at null node");if(t.isLeaf()||t.height<2)return t;const e=t.left,i=t.right,s=t,r=e,n=i,o=e.left,a=e.right,h=i.left,l=i.right,c=n.height-r.height;if(c>1)return n.left=s,n.parent=s.parent,s.parent=n,n.parent?n.parent.left===s?n.parent.left=n:n.parent.right=n:this.root=n,h.height>l.height?(n.right=h,s.right=l,l.parent=s,s.bounds=r.bounds.combine(l.bounds),n.bounds=s.bounds.combine(h.bounds),s.height=1+Math.max(r.height,l.height),n.height=1+Math.max(s.height,h.height)):(n.right=l,s.right=h,h.parent=s,s.bounds=r.bounds.combine(h.bounds),n.bounds=s.bounds.combine(l.bounds),s.height=1+Math.max(r.height,h.height),n.height=1+Math.max(s.height,l.height)),n;if(c<-1){if(r.left=s,r.parent=s.parent,s.parent=r,r.parent)if(r.parent.left===s)r.parent.left=r;else{if(r.parent.right!==s)throw"Error rotating Dynamic Tree";r.parent.right=r}else this.root=r;return o.height>a.height?(r.right=o,s.left=a,a.parent=s,s.bounds=n.bounds.combine(a.bounds),r.bounds=s.bounds.combine(o.bounds),s.height=1+Math.max(n.height,a.height),r.height=1+Math.max(s.height,o.height)):(r.right=a,s.left=o,o.parent=s,s.bounds=n.bounds.combine(o.bounds),r.bounds=s.bounds.combine(a.bounds),s.height=1+Math.max(n.height,o.height),r.height=1+Math.max(s.height,a.height)),r}return t}getHeight(){return null===this.root?0:this.root.height}query(t,e){const i=t.bounds,s=r=>{if(r&&r.bounds.intersect(i)){if(!r.isLeaf()||r.data===t)return s(r.left)||s(r.right);if(e.call(t,r.data))return!0}return!1};s(this.root)}rayCastQuery(t,e=1/0,i){const s=r=>{if(r&&r.bounds.rayCast(t,e)){if(!r.isLeaf())return s(r.left)||s(r.right);if(i.call(t,r.data))return!0}return!1};s(this.root)}getNodes(){const t=e=>e?[e].concat(t(e.left),t(e.right)):[];return t(this.root)}debug(t){const e=i=>{i&&(i.isLeaf()?i.bounds.draw(t,I.Green):i.bounds.draw(t,I.White),i.left&&e(i.left),i.right&&e(i.right))};e(this.root)}}class Li{constructor(t,e){this.pos=t,this.dir=e.normalize()}intersect(t){const e=t.begin.sub(this.pos);if(0===this.dir.cross(t.getSlope())&&0!==e.cross(this.dir))return-1;const i=this.dir.cross(t.getSlope());if(0===i)return-1;const s=e.cross(t.getSlope())/i;if(s>=0){const r=e.cross(this.dir)/i/t.getLength();if(r>=0&&r<=1)return s}return-1}intersectPoint(t){const e=this.intersect(t);return e<0?null:this.getPoint(e)}getPoint(t){return this.pos.add(this.dir.scale(t))}}class zi{constructor(){this._dynamicCollisionTree=new Fi,this._pairs=new Set,this._collisionPairCache=[],this._colliders=[]}getColliders(){return this._colliders}track(t){if(t)if(t instanceof Ui){const e=t.getColliders();for(const i of e)i.owner=t.owner,this._colliders.push(i),this._dynamicCollisionTree.trackCollider(i)}else this._colliders.push(t),this._dynamicCollisionTree.trackCollider(t);else f.getInstance().warn("Cannot track null collider")}untrack(t){if(t)if(t instanceof Ui){const e=t.getColliders();for(const t of e){const e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1),this._dynamicCollisionTree.untrackCollider(t)}}else{const e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1),this._dynamicCollisionTree.untrackCollider(t)}else f.getInstance().warn("Cannot untrack a null collider")}_pairExists(t,e){const i=Bi.calculatePairHash(t.id,e.id);return this._pairs.has(i)}broadphase(t,e,i){const s=e/1e3,r=t.filter((t=>{var e,i;const s=null===(e=t.owner)||void 0===e?void 0:e.get($i);return(null===(i=t.owner)||void 0===i?void 0:i.active)&&s.collisionType!==vi.PreventCollision}));let n;this._collisionPairCache=[],this._pairs.clear();for(let t=0,e=r.length;t<e;t++)n=r[t],this._dynamicCollisionTree.query(n,(t=>{if(!this._pairExists(n,t)&&Bi.canCollide(n,t)){const e=new Bi(n,t);this._pairs.add(e.id),this._collisionPairCache.push(e)}return!1}));if(i&&(i.physics.pairs=this._collisionPairCache.length),Ci.checkForFastBodies)for(const t of r){const e=t.owner.get($i);if(e.collisionType!==vi.Active)continue;const r=e.vel.size*s+.5*e.acc.size*s*s,n=Math.min(t.bounds.height,t.bounds.width);if(Ci.disableMinimumSpeedForFastBody||r>n/2){i&&i.physics.fastBodies++;const s=e.pos.sub(e.oldPos),n=t.center,o=t.getFurthestPoint(e.vel),a=o.sub(s),h=new Li(a,e.vel);let l;h.pos=h.pos.add(h.dir.scale(-2*Ci.surfaceEpsilon));let c=new A(1/0,1/0);if(this._dynamicCollisionTree.rayCastQuery(h,r+2*Ci.surfaceEpsilon,(e=>{if(!this._pairExists(t,e)&&Bi.canCollide(t,e)){const t=e.rayCast(h,r+10*Ci.surfaceEpsilon);if(t){const i=t.sub(a);i.size<c.size&&(c=i,l=e)}}return!1})),l&&A.isValid(c)){const s=new Bi(t,l);this._pairs.has(s.id)||(this._pairs.add(s.id),this._collisionPairCache.push(s));const r=n.sub(o);e.pos=a.add(r).add(c).add(h.dir.scale(10*Ci.surfaceEpsilon)),t.update(e.transform),i&&i.physics.fastBodyCollisions++}}}return this._collisionPairCache}narrowphase(t,e){let i=[];for(let s=0;s<t.length;s++){const r=t[s].collide();if(i=i.concat(r),e&&r.length>0)for(const t of r)e.physics.contacts.set(t.id,t)}return e&&(e.physics.collisions+=i.length),i}update(t){let e=0;const i=t.length;for(let s=0;s<i;s++)this._dynamicCollisionTree.updateCollider(t[s])&&e++;return e}debug(t){this._dynamicCollisionTree.debug(t)}}class Oi{constructor(){this.id=_("collider",Oi._ID++),this.events=new he}touching(t){return!!this.collide(t)}}Oi._ID=0;class Ui extends Oi{constructor(t){super(),this._collisionProcessor=new zi,this._dynamicAABBTree=new Fi,this._colliders=[];for(const e of t)this.addCollider(e)}clearColliders(){this._colliders=[]}addCollider(t){this.events.wire(t.events),this._colliders.push(t),this._collisionProcessor.track(t),this._dynamicAABBTree.trackCollider(t)}removeCollider(t){this.events.unwire(t.events),tt(t,this._colliders),this._collisionProcessor.untrack(t),this._dynamicAABBTree.untrackCollider(t)}getColliders(){return this._colliders}get worldPos(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:A.Zero}get center(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:A.Zero}get bounds(){var t,e;const i=this.getColliders();return i.reduce(((t,e)=>t.combine(e.bounds)),null!==(e=null===(t=i[0])||void 0===t?void 0:t.bounds)&&void 0!==e?e:(new D).translate(this.worldPos))}get localBounds(){var t,e;const i=this.getColliders();return i.reduce(((t,e)=>t.combine(e.localBounds)),null!==(e=null===(t=i[0])||void 0===t?void 0:t.localBounds)&&void 0!==e?e:new D)}get axes(){const t=this.getColliders();let e=[];for(const i of t)e=e.concat(i.axes);return e}getFurthestPoint(t){const e=this.getColliders(),i=[];for(const s of e)i.push(s.getFurthestPoint(t));let s=i[0],r=-Number.MAX_VALUE;for(const e of i){const i=e.dot(t);i>r&&(s=e,r=i)}return s}getInertia(t){const e=this.getColliders();let i=0;for(const s of e)i+=s.getInertia(t);return i}collide(t){let e=[t];t instanceof Ui&&(e=t.getColliders());const i=[];for(const t of e)this._dynamicAABBTree.query(t,(e=>(i.push(new Bi(t,e)),!1)));let s=[];for(const t of i)s=s.concat(t.collide());return s}getClosestLineBetween(t){const e=this.getColliders(),i=[];if(t instanceof Ui){const s=t.getColliders();for(const t of e)for(const e of s){const s=t.getClosestLineBetween(e);s&&i.push(s)}}else for(const s of e){const e=t.getClosestLineBetween(s);e&&i.push(e)}if(i.length){let t=i[0].getLength(),e=i[0];for(const s of i){const i=s.getLength();i<t&&(t=i,e=s)}return e}return null}contains(t){const e=this.getColliders();for(const i of e)if(i.contains(t))return!0;return!1}rayCast(t,e){const i=this.getColliders(),s=[];for(const r of i){const i=r.rayCast(t,e);i&&s.push(i)}if(s.length){let e=s[0],i=e.dot(t.dir);for(const r of s){const s=t.dir.dot(r);s<i&&(e=r,i=s)}return e}return null}project(t){const e=this.getColliders(),i=[];for(const s of e){const e=s.project(t);e&&i.push(e)}if(i.length){const t=new Mi(i[0].min,i[0].max);for(const e of i)t.min=Math.min(e.min,t.min),t.max=Math.max(e.max,t.max);return t}return null}update(t){if(t){const e=this.getColliders();for(const i of e)i.owner=this.owner,i.update(t)}}draw(t,e,i){const s=this.getColliders();for(const r of s)r.draw(t,e,i)}debug(t,e){const i=this.getColliders();for(const s of i)s.debug(t,e)}debugDraw(t,e){const i=this.getColliders();for(const s of i)s.draw(t,e)}clone(){return new Ui(this._colliders.map((t=>t.clone())))}}class Ni{constructor(t,e){this.begin=t,this.end=e}get slope(){return(this.end.y-this.begin.y)/(this.end.x-this.begin.x)}get intercept(){return this.begin.y-this.slope*this.begin.x}normal(){return this.end.sub(this.begin).normal()}dir(){return this.end.sub(this.begin)}getPoints(){return[this.begin,this.end]}getSlope(){const t=this.begin,e=this.end,i=t.distance(e);return e.sub(t).scale(1/i)}getEdge(){const t=this.begin;return this.end.sub(t)}getLength(){const t=this.begin,e=this.end;return t.distance(e)}get midpoint(){return this.begin.add(this.end).scale(.5)}flip(){return new Ni(this.end,this.begin)}below(t){return(this.end.x-this.begin.x)*(t.y-this.begin.y)-(this.end.y-this.begin.y)*(t.x-this.begin.x)>=0}clip(t,e){let i=t;i=i.normalize();const s=i.dot(this.begin)-e,r=i.dot(this.end)-e,n=[];if(s<=0&&n.push(this.begin),r<=0&&n.push(this.end),s*r<0){const t=s/(s-r);n.push(this.begin.add(this.end.sub(this.begin).scale(t)))}return 2!==n.length?null:new Ni(n[0],n[1])}distanceToPoint(t,e=!1){const i=t.x,s=t.y,r=this.getLength(),n=((this.end.y-this.begin.y)*i-(this.end.x-this.begin.x)*s+this.end.x*this.begin.y-this.end.y*this.begin.x)/r;return e?n:Math.abs(n)}findVectorToPoint(t){const e=this.begin.sub(t),i=this.getSlope();return e.sub(i.scale(e.dot(i)))}findPoint(t=null,e=null){const i=this.slope,s=this.intercept;if(null!==t)return new A(t,i*t+s);if(null!==e)return new A((e-s)/i,e);throw new Error("You must provide an X or a Y value")}hasPoint(){let t,e=0;if("number"==typeof arguments[0]&&"number"==typeof arguments[1])t=new A(arguments[0],arguments[1]),e=arguments[2]||0;else{if(!(arguments[0]instanceof A))throw"Could not determine the arguments for Vector.hasPoint";t=arguments[0],e=arguments[1]||0}const i=t.x-this.begin.x,s=t.y-this.begin.y,r=this.end.x-this.begin.x,n=this.end.y-this.begin.y,o=i*n-s*r;return!(Math.abs(o)>e)&&(Math.abs(r)>=Math.abs(n)?r>0?this.begin.x<=t.x&&t.x<=this.end.x:this.end.x<=t.x&&t.x<=this.begin.x:n>0?this.begin.y<=t.y&&t.y<=this.end.y:this.end.y<=t.y&&t.y<=this.begin.y)}}function Hi(t,e,i,s){const r=t.sub(i),n=e.dot(e),o=e.dot(s),a=s.dot(s),h=e.dot(r),l=s.dot(r),c=n*a-o*o;let d=c,u=c;if(0===c||c<=.01){const e=h/o;return new Ni(t,i.add(s.scale(e)))}let p=o*l-a*h,g=n*l-o*h;return p<0?(p=0,g=l,u=a):p>d&&(p=d,g=l+o,u=a),g<0?(g=0,-h<0?p=0:-h>n?p=d:(p=-h,d=n)):g>u&&(g=u,-h+o<0?p=0:-h+o>n?p=d:(p=-h+o,d=n)),p=Math.abs(p)<.001?0:p/d,g=Math.abs(g)<.001?0:g/u,new Ni(t.add(e.scale(p)),i.add(s.scale(g)))}const Wi={PolygonPolygonClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),r=s.negate(),n=new Li(t.worldPos,s),o=new Li(i,r),a=t.rayCast(n).add(n.dir.scale(.1)),h=e.rayCast(o).add(o.dir.scale(.1)),l=t.getClosestFace(a),c=e.getClosestFace(h);return Hi(l.face.begin,l.face.getEdge(),c.face.begin,c.face.getEdge())},PolygonEdgeClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=new Li(t.worldPos,i),r=t.rayCast(s).add(s.dir.scale(.1)),n=t.getClosestFace(r),o=n.face.begin,a=n.face.getEdge(),h=e.asLine();return Hi(o,a,h.begin,h.getEdge())},PolygonCircleClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),r=new Li(t.worldPos,s.normalize()),n=t.rayCast(r).add(r.dir.scale(.1)),o=t.getClosestFace(n),a=o.face.begin,h=o.face.getEdge();let l=(h.x*(i.x-a.x)+h.y*(i.y-a.y))/(h.x*h.x+h.y*h.y);l>1?l=1:l<0&&(l=0);const c=Math.sqrt(Math.pow(a.x+h.x*l-i.x,2)+Math.pow(a.y+h.y*l-i.y,2))-e.radius,d=(a.x+h.x*l-i.x)*e.radius/(e.radius+c),u=(a.y+h.y*l-i.y)*e.radius/(e.radius+c);return new Ni(h.scale(l).add(a),new A(i.x+d,i.y+u))},CircleCircleClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=t.worldPos.sub(e.worldPos),r=new Li(t.worldPos,i),n=new Li(e.worldPos,s),o=t.rayCast(r),a=e.rayCast(n);return new Ni(o,a)},CircleEdgeClosestLine(t,e){const i=t.worldPos,s=e.asLine(),r=s.begin,n=s.getEdge();let o=(n.x*(i.x-r.x)+n.y*(i.y-r.y))/(n.x*n.x+n.y*n.y);o>1?o=1:o<0&&(o=0);const a=Math.sqrt(Math.pow(r.x+n.x*o-i.x,2)+Math.pow(r.y+n.y*o-i.y,2))-t.radius,h=(r.x+n.x*o-i.x)*t.radius/(t.radius+a),l=(r.y+n.y*o-i.y)*t.radius/(t.radius+a);return new Ni(n.scale(o).add(r),new A(i.x+h,i.y+l))},EdgeEdgeClosestLine(t,e){const i=t.asLine(),s=i.begin,r=i.getEdge(),n=e.asLine();return Hi(s,r,n.begin,n.getEdge())}};class Gi extends Oi{constructor(t){super(),this.offset=A.Zero,this.offset=t.offset||A.Zero,this.radius=t.radius||0}get worldPos(){var t,e,i,s;const r=this._transform,n=null!==(t=null==r?void 0:r.globalScale)&&void 0!==t?t:A.One,o=null!==(e=null==r?void 0:r.globalRotation)&&void 0!==e?e:0,a=null!==(i=null==r?void 0:r.globalPos)&&void 0!==i?i:A.Zero;return(null!==(s=this.offset)&&void 0!==s?s:A.Zero).scale(n).rotate(o).add(a)}get radius(){var t;const e=this._transform,i=null!==(t=null==e?void 0:e.globalScale)&&void 0!==t?t:A.One;return this._naturalRadius*Math.min(i.x,i.y)}set radius(t){var e;const i=this._transform,s=null!==(e=null==i?void 0:i.globalScale)&&void 0!==e?e:A.One;this._naturalRadius=t/Math.min(s.x,s.y)}clone(){return new Gi({offset:this.offset.clone(),radius:this.radius})}get center(){var t,e,i,s;const r=this._transform,n=null!==(t=null==r?void 0:r.globalScale)&&void 0!==t?t:A.One,o=null!==(e=null==r?void 0:r.globalRotation)&&void 0!==e?e:0,a=null!==(i=null==r?void 0:r.globalPos)&&void 0!==i?i:A.Zero;return(null!==(s=this.offset)&&void 0!==s?s:A.Zero).scale(n).rotate(o).add(a)}contains(t){var e,i;return(null!==(i=null===(e=this._transform)||void 0===e?void 0:e.pos)&&void 0!==i?i:this.offset).distance(t)<=this.radius}rayCast(t,e=1/0){const i=this.center,s=t.dir,r=t.pos,n=Math.sqrt(Math.pow(s.dot(r.sub(i)),2)-Math.pow(r.sub(i).distance(),2)+Math.pow(this.radius,2));if(n<0)return null;{let o=0;if(0===n)return o=-s.dot(r.sub(i)),o>0&&o<e?t.getPoint(o):null;{const o=-s.dot(r.sub(i))+n,a=-s.dot(r.sub(i))-n,h=[];o>=0&&h.push(o),a>=0&&h.push(a);const l=Math.min(...h);return l<=e?t.getPoint(l):null}}}getClosestLineBetween(t){if(t instanceof Gi)return Wi.CircleCircleClosestLine(this,t);if(t instanceof Ki)return Wi.PolygonCircleClosestLine(t,this).flip();if(t instanceof ji)return Wi.CircleEdgeClosestLine(this,t).flip();throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Gi)return qi.CollideCircleCircle(this,t);if(t instanceof Ki)return qi.CollideCirclePolygon(this,t);if(t instanceof ji)return qi.CollideCircleEdge(this,t);throw new Error("Circle could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){return this.center.add(t.normalize().scale(this.radius))}getFurthestLocalPoint(t){return t.normalize().scale(this.radius)}get bounds(){var t,e,i;const s=this._transform,r=null!==(t=null==s?void 0:s.globalScale)&&void 0!==t?t:A.One,n=null!==(e=null==s?void 0:s.globalRotation)&&void 0!==e?e:0,o=null!==(i=null==s?void 0:s.globalPos)&&void 0!==i?i:A.Zero;return new D(this.offset.x-this._naturalRadius,this.offset.y-this._naturalRadius,this.offset.x+this._naturalRadius,this.offset.y+this._naturalRadius).rotate(n).scale(r).translate(o)}get localBounds(){return new D(this.offset.x-this._naturalRadius,this.offset.y-this._naturalRadius,this.offset.x+this._naturalRadius,this.offset.y+this._naturalRadius)}get axes(){return[]}getInertia(t){return t*this.radius*this.radius/2}update(t){this._transform=t}project(t){const e=[],i=this.center.dot(t);return e.push(i),e.push(i+this.radius),e.push(i-this.radius),new Mi(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=I.Green,i=A.Zero){const s=i.add(this.offset);t.beginPath(),t.fillStyle=e.toString(),t.arc(s.x,s.y,this.radius,0,2*Math.PI),t.closePath(),t.fill()}debug(t,e){var i,s,r,n;const o=this._transform,a=null!==(i=null==o?void 0:o.globalScale)&&void 0!==i?i:A.One,h=null!==(s=null==o?void 0:o.globalRotation)&&void 0!==s?s:0,l=null!==(r=null==o?void 0:o.globalPos)&&void 0!==r?r:A.Zero;t.save(),t.translate(l.x,l.y),t.rotate(h),t.scale(a.x,a.y),t.drawCircle(null!==(n=this.offset)&&void 0!==n?n:A.Zero,this._naturalRadius,I.Transparent,e,2),t.restore()}debugDraw(t,e=I.Green){const i=this._transform,s=i?i.pos.add(this.offset):this.offset,r=i?i.rotation:0;t.beginPath(),t.strokeStyle=e.toString(),t.arc(s.x,s.y,this.radius,0,2*Math.PI),t.closePath(),t.stroke(),t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(Math.cos(r)*this.radius+s.x,Math.sin(r)*this.radius+s.y),t.closePath(),t.stroke()}}class Vi{constructor(t,e,i,s,r,n,o,a){this._canceled=!1,this.colliderA=t,this.colliderB=e,this.mtv=i,this.normal=s,this.tangent=r,this.points=n,this.localPoints=o,this.info=a,this.id=Bi.calculatePairHash(t.id,e.id)}matchAwake(){const t=this.colliderA.owner.get($i),e=this.colliderB.owner.get($i);t&&e&&t.sleeping!==e.sleeping&&(t.sleeping&&t.collisionType!==vi.Fixed&&e.sleepMotion>=Ci.wakeThreshold&&t.setSleeping(!1),e.sleeping&&e.collisionType!==vi.Fixed&&t.sleepMotion>=Ci.wakeThreshold&&e.setSleeping(!1))}isCanceled(){return this._canceled}cancel(){this._canceled=!0}}class Xi{static findPolygonPolygonSeparation(t,e){let i=-Number.MAX_VALUE,s=null,r=null,n=-1,o=null;const a=t.getSides(),h=t.getLocalSides();for(let t=0;t<a.length;t++){const h=a[t],l=h.normal(),c=e.getFurthestPoint(l.negate()),d=h.distanceToPoint(c,!0);d>i&&(i=d,s=h,r=l,n=t,o=c)}return{collider:t,separation:r?i:99,axis:r,side:s,localSide:h[n],sideId:n,point:o,localPoint:r?e.getFurthestLocalPoint(r.negate()):null}}static findCirclePolygonSeparation(t,e){const i=e.axes,s=e.center.sub(t.worldPos),r=e.getFurthestPoint(s.negate());i.push(r.sub(t.worldPos).normalize());let n=Number.MAX_VALUE,o=null,a=-1;for(let s=0;s<i.length;s++){const r=e.project(i[s]),h=t.project(i[s]),l=r.getOverlap(h);if(l<=0)return null;l<n&&(n=l,o=i[s],a=s)}return a<0?null:o.normalize().scale(n)}}const qi={CollideCircleCircle(t,e){const i=t.worldPos,s=e.worldPos,r=t.radius+e.radius,n=i.distance(s);if(n>r)return[];const o=r-n,a=s.sub(i).normalize(),h=a.perpendicular(),l=a.scale(o),c=t.getFurthestPoint(a),d=t.getFurthestLocalPoint(a);return[new Vi(t,e,l,a,h,[c],[d],{collider:t,separation:o,axis:a,point:c})]},CollideCirclePolygon(t,e){var i,s;let r=Xi.findCirclePolygonSeparation(t,e);if(!r)return[];const n=r.dot(e.center.sub(t.center));r=n<0?r.negate():r;const o=t.getFurthestPoint(r),a=(null!==(s=null===(i=t.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei).applyInverse(o),h=r.normalize(),l={collider:t,separation:-r.size,axis:h,point:o,localPoint:a,side:e.findSide(h.negate()),localSide:e.findLocalSide(h.negate())};return[new Vi(t,e,r,h,h.perpendicular(),[o],[a],l)]},CollideCircleEdge(t,e){const i=t.center,s=e.asLine(),r=s.end.sub(s.begin),n=r.dot(s.end.sub(i)),o=r.dot(i.sub(s.begin)),a=e.asLine(),h=e.asLocalLine();if(o<=0){const r=s.begin.sub(i),n=r.dot(r);if(n>t.radius*t.radius)return[];const o=r.normalize(),l=t.radius-Math.sqrt(n),c={collider:t,separation:l,axis:o,point:a.begin,side:a,localSide:h};return[new Vi(t,e,o.scale(l),o,o.perpendicular(),[a.begin],[h.begin],c)]}if(n<=0){const r=s.end.sub(i),n=r.dot(r);if(n>t.radius*t.radius)return[];const o=r.normalize(),l=t.radius-Math.sqrt(n),c={collider:t,separation:l,axis:o,point:a.end,side:a,localSide:h};return[new Vi(t,e,o.scale(l),o,o.perpendicular(),[a.end],[h.end],c)]}const l=r.dot(r),c=s.begin.scale(n).add(s.end.scale(o)).scale(1/l),d=i.sub(c),u=d.dot(d);if(u>t.radius*t.radius)return[];let p=r.perpendicular();p.dot(i.sub(s.begin))<0&&(p.x=-p.x,p.y=-p.y),p=p.normalize();const g=t.radius-Math.sqrt(u),_=p.scale(g),f={collider:t,separation:g,axis:p,point:c,side:a,localSide:h};return[new Vi(t,e,_,p.negate(),p.negate().perpendicular(),[c],[c.sub(e.worldPos)],f)]},CollideEdgeEdge:()=>[],CollidePolygonEdge(t,e){var i;const s=t.center,r=e.center.sub(s).normalize(),n=new Ki({points:[e.begin,e.end,e.end.add(r.scale(100)),e.begin.add(r.scale(100))],offset:e.offset});n.owner=e.owner;(null===(i=e.owner)||void 0===i?void 0:i.get(Ei))&&n.update(e.owner.get(Ei));const o=this.CollidePolygonPolygon(t,n);return o.length&&(o[0].colliderB=e,o[0].id=Bi.calculatePairHash(t.id,e.id)),o},CollidePolygonPolygon(t,e){var i,s,r,n;const o=Xi.findPolygonPolygonSeparation(t,e);if(o.separation>0)return[];const a=Xi.findPolygonPolygonSeparation(e,t);if(a.separation>0)return[];const h=o.separation>a.separation?o:a,l=(h.collider===t?e:t).findSide(h.axis.negate()),c=h.side,d=c.dir().normalize(),u=l.clip(d.negate(),-d.dot(c.begin));let p=null;if(u&&(p=u.clip(d,d.dot(c.end))),p){const o=p.getPoints().filter((t=>c.below(t)));let a=h.axis,l=a.perpendicular();e.center.sub(t.center).dot(a)<0&&(a=a.negate(),l=a.perpendicular());let d=[];if(h.collider===t){const t=null!==(s=null===(i=e.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei;d=o.map((e=>t.applyInverse(e)))}else{const e=null!==(n=null===(r=t.owner)||void 0===r?void 0:r.get(Ei))&&void 0!==n?n:new Ei;d=o.map((t=>e.applyInverse(t)))}return[new Vi(t,e,a.scale(-h.separation),a,l,o,d,h)]}return[]},FindContactSeparation(t,e){var i,s,r,n;const o=t.colliderA,a=null!==(s=null===(i=t.colliderA.owner)||void 0===i?void 0:i.get(Ei))&&void 0!==s?s:new Ei,h=t.colliderB,l=null!==(n=null===(r=t.colliderB.owner)||void 0===r?void 0:r.get(Ei))&&void 0!==n?n:new Ei;if(o instanceof Gi&&h instanceof Gi){return-(o.radius+h.radius-a.pos.distance(l.pos))}if(o instanceof Ki&&h instanceof Ki&&t.info.localSide){let i,s;return t.info.collider===o?(i=new Ni(a.apply(t.info.localSide.begin),a.apply(t.info.localSide.end)),s=l.apply(e)):(i=new Ni(l.apply(t.info.localSide.begin),l.apply(t.info.localSide.end)),s=a.apply(e)),i.distanceToPoint(s,!0)}if(o instanceof Ki&&h instanceof Gi||h instanceof Ki&&o instanceof Gi){const i=a.apply(e);if(t.info.side)return t.info.side.distanceToPoint(i,!0)}if(o instanceof ji&&h instanceof Ki||h instanceof ji&&o instanceof Ki){let i;if(i=t.info.collider===o?l.apply(e):a.apply(e),t.info.side)return t.info.side.distanceToPoint(i,!0)}if(o instanceof Gi&&h instanceof ji||h instanceof Gi&&o instanceof ji){const i=l.apply(e);let s;o instanceof Gi&&(s=o.getFurthestPoint(t.normal));const r=i.distance(s);if(t.info.side)return r>0?-r:0}return 0}};class ji extends Oi{constructor(t){var e;super(),this.begin=t.begin||A.Zero,this.end=t.end||A.Zero,this.offset=null!==(e=t.offset)&&void 0!==e?e:A.Zero}clone(){return new ji({begin:this.begin.clone(),end:this.end.clone()})}get worldPos(){var t;const e=this._transform;return null!==(t=null==e?void 0:e.globalPos.add(this.offset))&&void 0!==t?t:this.offset}get center(){return this.begin.average(this.end).add(this._getBodyPos())}_getBodyPos(){var t;const e=this._transform;return null!==(t=null==e?void 0:e.globalPos)&&void 0!==t?t:A.Zero}_getTransformedBegin(){const t=this._transform,e=t?t.globalRotation:0;return this.begin.rotate(e).add(this._getBodyPos())}_getTransformedEnd(){const t=this._transform,e=t?t.globalRotation:0;return this.end.rotate(e).add(this._getBodyPos())}getSlope(){const t=this._getTransformedBegin(),e=this._getTransformedEnd(),i=t.distance(e);return e.sub(t).scale(1/i)}getLength(){const t=this._getTransformedBegin(),e=this._getTransformedEnd();return t.distance(e)}contains(){return!1}rayCast(t,e=1/0){const i=this._getTransformedBegin().sub(t.pos);if(0===t.dir.cross(this.getSlope())&&0!==i.cross(t.dir))return null;const s=t.dir.cross(this.getSlope());if(0===s)return null;const r=i.cross(this.getSlope())/s;if(r>=0&&r<=e){const e=i.cross(t.dir)/s/this.getLength();if(e>=0&&e<=1)return t.getPoint(r)}return null}getClosestLineBetween(t){if(t instanceof Gi)return Wi.CircleEdgeClosestLine(t,this);if(t instanceof Ki)return Wi.PolygonEdgeClosestLine(t,this).flip();if(t instanceof ji)return Wi.EdgeEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Gi)return qi.CollideCircleEdge(t,this);if(t instanceof Ki)return qi.CollidePolygonEdge(t,this);if(t instanceof ji)return qi.CollideEdgeEdge();throw new Error("Edge could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){const e=this._getTransformedBegin(),i=this._getTransformedEnd();return t.dot(e)>0?e:i}_boundsFromBeginEnd(t,e,i=10){return new D(Math.min(t.x,e.x)-i,Math.min(t.y,e.y)-i,Math.max(t.x,e.x)+i,Math.max(t.y,e.y)+i)}get bounds(){const t=this._getTransformedBegin(),e=this._getTransformedEnd();return this._boundsFromBeginEnd(t,e)}get localBounds(){return this._boundsFromBeginEnd(this.begin,this.end)}asLine(){return new Ni(this._getTransformedBegin(),this._getTransformedEnd())}asLocalLine(){return new Ni(this.begin,this.end)}get axes(){const t=this._getTransformedEnd().sub(this._getTransformedBegin()).normal(),e=[];return e.push(t),e.push(t.negate()),e.push(t.normal()),e.push(t.normal().negate()),e}getInertia(t){const e=this.end.sub(this.begin).distance()/2;return t*e*e}update(t){this._transform=t}project(t){const e=[],i=[this._getTransformedBegin(),this._getTransformedEnd()],s=i.length;for(let r=0;r<s;r++)e.push(i[r].dot(t));return new Mi(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=I.Green,i=A.Zero){const s=this.begin.add(i),r=this.end.add(i);t.strokeStyle=e.toString(),t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(r.x,r.y),t.closePath(),t.stroke()}debug(t,e){const i=this._getTransformedBegin(),s=this._getTransformedEnd();t.drawLine(i,s,e,2),t.drawCircle(i,2,e),t.drawCircle(s,2,e)}debugDraw(t,e=I.Red){const i=this._getTransformedBegin(),s=this._getTransformedEnd();t.strokeStyle=e.toString(),t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s.x,s.y),t.closePath(),t.stroke()}}class Ki extends Oi{constructor(t){var e;super(),this._transformedPoints=[],this._axes=[],this._sides=[],this._localSides=[],this.offset=null!==(e=t.offset)&&void 0!==e?e:A.Zero;const i=!!t.clockwiseWinding;this.points=(i?t.points.reverse():t.points)||[],this._calculateTransformation()}clone(){return new Ki({offset:this.offset.clone(),points:this.points.map((t=>t.clone()))})}get worldPos(){return this._transform?this._transform.pos.add(this.offset):this.offset}get center(){return this.bounds.center}_calculateTransformation(){const t=this._transform,e=t?t.globalPos.add(this.offset):this.offset,i=t?t.globalRotation:0,s=t?t.globalScale:A.One,r=this.points.length;this._transformedPoints.length=0;for(let t=0;t<r;t++)this._transformedPoints[t]=this.points[t].scale(s).rotate(i).add(e)}getTransformedPoints(){return this._calculateTransformation(),this._transformedPoints}getSides(){if(this._sides.length)return this._sides;const t=[],e=this.getTransformedPoints(),i=e.length;for(let s=0;s<i;s++)t.push(new Ni(e[s],e[(s+1)%i]));return this._sides=t,this._sides}getLocalSides(){if(this._localSides.length)return this._localSides;const t=[],e=this.points,i=e.length;for(let s=0;s<i;s++)t.push(new Ni(e[s],e[(s+1)%i]));return this._localSides=t,this._localSides}findSide(t){const e=this.getSides();let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=e[r],o=n.normal().dot(t);o>s&&(i=n,s=o)}return i}findLocalSide(t){const e=this.getLocalSides();let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=e[r],o=n.normal().dot(t);o>s&&(i=n,s=o)}return i}get axes(){if(this._axes.length)return this._axes;const t=this.getSides().map((t=>t.normal()));return this._axes=t,this._axes}update(t){this._transform=t,this._sides.length=0,this._localSides.length=0,this._axes.length=0,this._transformedPoints.length=0,this.getTransformedPoints(),this.getSides(),this.getLocalSides()}contains(t){const e=new Li(t,new A(1,0));return this.getSides().reduce((function(t,i){return e.intersect(i)>=0?t+1:t}),0)%2!=0}getClosestLineBetween(t){if(t instanceof Gi)return Wi.PolygonCircleClosestLine(this,t);if(t instanceof Ki)return Wi.PolygonPolygonClosestLine(this,t);if(t instanceof ji)return Wi.PolygonEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Gi)return qi.CollideCirclePolygon(t,this);if(t instanceof Ki)return qi.CollidePolygonPolygon(this,t);if(t instanceof ji)return qi.CollidePolygonEdge(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}getFurthestPoint(t){const e=this.getTransformedPoints();let i=null,s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=t.dot(e[r]);n>s&&(s=n,i=e[r])}return i}getFurthestLocalPoint(t){const e=this.points;let i=e[0],s=-Number.MAX_VALUE;for(let r=0;r<e.length;r++){const n=t.dot(e[r]);n>s&&(s=n,i=e[r])}return i}getClosestFace(t){const e=this.getSides();let i=Number.POSITIVE_INFINITY,s=-1,r=-1;for(let n=0;n<e.length;n++){const o=e[n].distanceToPoint(t);o<i&&(i=o,s=n,r=o)}return-1!==s?{distance:e[s].normal().scale(r),face:e[s]}:null}get bounds(){var t,e,i;const s=this._transform,r=null!==(t=null==s?void 0:s.globalScale)&&void 0!==t?t:A.One,n=null!==(e=null==s?void 0:s.globalRotation)&&void 0!==e?e:0,o=(null!==(i=null==s?void 0:s.globalPos)&&void 0!==i?i:A.Zero).add(this.offset);return this.localBounds.scale(r).rotate(n).translate(o)}get localBounds(){return D.fromPoints(this.points)}getInertia(t){let e=0,i=0;for(let t=0;t<this.points.length;t++){const s=(t+1)%this.points.length,r=this.points[s].cross(this.points[t]);e+=r*(this.points[t].dot(this.points[t])+this.points[t].dot(this.points[s])+this.points[s].dot(this.points[s])),i+=r}return t/6*(e/i)}rayCast(t,e=1/0){const i=this.getSides(),s=i.length;let r=Number.MAX_VALUE,n=-1;for(let o=0;o<s;o++){const s=t.intersect(i[o]);s>=0&&s<r&&s<=e&&(r=s,n=o)}return n>=0?t.getPoint(r):null}project(t){const e=this.getTransformedPoints(),i=e.length;let s=Number.MAX_VALUE,r=-Number.MAX_VALUE;for(let n=0;n<i;n++){const i=e[n].dot(t);s=Math.min(s,i),r=Math.max(r,i)}return new Mi(s,r)}draw(t,e=I.Green,i=A.Zero){const s=i.add(this.offset);t.beginPath(),t.fillStyle=e.toString();const r=this.points[0].add(s);t.moveTo(r.x,r.y),this.points.map((t=>t.add(s))).forEach((function(e){t.lineTo(e.x,e.y)})),t.lineTo(r.x,r.y),t.closePath(),t.fill()}debug(t,e){const i=this.getTransformedPoints()[0],s=[i,...this.getTransformedPoints(),i];for(let i=0;i<s.length-1;i++)t.drawLine(s[i],s[i+1],e,2),t.drawCircle(s[i],2,e),t.drawCircle(s[i+1],2,e)}debugDraw(t,e=I.Red){t.beginPath(),t.strokeStyle=e.toString();const i=this.getTransformedPoints()[0];t.moveTo(i.x,i.y),this.getTransformedPoints().forEach((function(e){t.lineTo(e.x,e.y)})),t.lineTo(i.x,i.y),t.closePath(),t.stroke()}}class Zi{static Box(t,e,i=A.Half,s=A.Zero){return new Ki({points:new D(-t*i.x,-e*i.y,t-t*i.x,e-e*i.y).getPoints(),offset:s})}static Polygon(t,e=!1,i=A.Zero){return new Ki({points:t,offset:i,clockwiseWinding:e})}static Circle(t,e=A.Zero){return new Gi({radius:t,offset:e})}static Edge(t,e){return new ji({begin:t,end:e})}static Capsule(t,e,i=A.Zero){const s=f.getInstance();t===e&&s.warn("A capsule collider with equal width and height is a circle, consider using a ex.Shape.Circle or ex.CircleCollider");if(e>=t){return new Ui([Zi.Circle(t/2,P(0,-e/2+t/2).add(i)),Zi.Box(t,e-t,A.Half,i),Zi.Circle(t/2,P(0,e/2-t/2).add(i))])}return new Ui([Zi.Circle(e/2,P(-t/2+e/2,0).add(i)),Zi.Box(t-e,e,A.Half,i),Zi.Circle(e/2,P(t/2-e/2,0).add(i))])}}class Yi extends Ai{constructor(t){super(),this.type="ex.collider",this.events=new he,this.$colliderAdded=new Di,this.$colliderRemoved=new Di,this.set(t)}get(){return this._collider}set(t){return this.clear(),t&&(this._collider=t,this._collider.owner=this.owner,this.events.wire(t.events),this.$colliderAdded.notifyAll(t),this.update()),t}clear(){this._collider&&(this.events.unwire(this._collider.events),this.$colliderRemoved.notifyAll(this._collider),this._collider.owner=null,this._collider=null)}get bounds(){var t,e;return null!==(e=null===(t=this._collider)||void 0===t?void 0:t.bounds)&&void 0!==e?e:new D}get localBounds(){var t,e;return null!==(e=null===(t=this._collider)||void 0===t?void 0:t.localBounds)&&void 0!==e?e:new D}update(){var t;const e=null===(t=this.owner)||void 0===t?void 0:t.get(Ei);this._collider&&(this._collider.owner=this.owner,e&&this._collider.update(e))}collide(t){let e=this._collider,i=t._collider;if(!e||!i)return[];let s=!1;if(i instanceof Ui&&(e=i,i=this._collider,s=!0),this._collider){const r=e.collide(i);return r?(s&&r.forEach((e=>{e.mtv=e.mtv.negate(),e.normal=e.normal.negate(),e.tangent=e.normal.perpendicular(),e.colliderA=this._collider,e.colliderB=t._collider})),r):[]}return[]}onAdd(t){this._collider&&this.update(),this.events.on("precollision",(e=>{const i=e;t.events.emit("precollision",new jt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("postcollision",(e=>{const i=e;t.events.emit("postcollision",new Kt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("collisionstart",(e=>{const i=e;t.events.emit("collisionstart",new Jt(i.target.owner,i.other.owner,i.contact))})),this.events.on("collisionend",(e=>{const i=e;t.events.emit("collisionend",new te(i.target.owner,i.other.owner))}))}onRemove(){this.events.clear(),this.$colliderRemoved.notifyAll(this._collider)}useBoxCollider(t,e,i=A.Half,s=A.Zero){const r=Zi.Box(t,e,i,s);return this.set(r)}usePolygonCollider(t,e=A.Zero){const i=Zi.Polygon(t,!1,e);return this.set(i)}useCircleCollider(t,e=A.Zero){const i=Zi.Circle(t,e);return this.set(i)}useEdgeCollider(t,e){const i=Zi.Edge(t,e);return this.set(i)}useCompositeCollider(t){return this.set(new Ui(t))}}var Qi;!function(t){t.Rotation="rotation",t.X="x",t.Y="y"}(Qi||(Qi={}));class $i extends Ai{constructor(t){var e,i,s;super(),this.type="ex.body",this.dependencies=[Ei,Ii],this.id=_("body",$i._ID++),this.events=new he,this.collisionType=vi.PreventCollision,this.group=Ri.All,this.mass=Ci.defaultMass,this.sleepMotion=5*Ci.sleepEpsilon,this.canSleep=Ci.bodiesCanSleepByDefault,this._sleeping=!1,this.bounciness=.2,this.friction=.99,this.useGravity=!0,this.limitDegreeOfFreedom=[],this.oldPos=new A(0,0),this.oldVel=new A(0,0),this.oldAcc=A.Zero,this.oldRotation=0,this.oldScale=A.One,t&&(this.collisionType=null!==(e=t.type)&&void 0!==e?e:this.collisionType,this.group=null!==(i=t.group)&&void 0!==i?i:this.group,this.useGravity=null!==(s=t.useGravity)&&void 0!==s?s:this.useGravity)}get inverseMass(){return this.collisionType===vi.Fixed?0:1/this.mass}get sleeping(){return this._sleeping}setSleeping(t){this._sleeping=t,t?(this.vel=A.Zero,this.acc=A.Zero,this.angularVelocity=0,this.sleepMotion=0):this.sleepMotion=5*Ci.sleepEpsilon}updateMotion(){this._sleeping&&this.setSleeping(!0);const t=this.vel.size*this.vel.size+Math.abs(this.angularVelocity*this.angularVelocity),e=Ci.sleepBias;this.sleepMotion=e*this.sleepMotion+(1-e)*t,this.sleepMotion=z(this.sleepMotion,0,10*Ci.sleepEpsilon),this.canSleep&&this.sleepMotion<Ci.sleepEpsilon&&this.setSleeping(!0)}get inertia(){const t=this.owner.get(Yi);return(null==t?void 0:t.get())?t.get().getInertia(this.mass):0}get inverseInertia(){return this.collisionType===vi.Fixed?0:1/this.inertia}get active(){var t;return!!(null===(t=this.owner)||void 0===t?void 0:t.active)}get center(){return this.pos}get transform(){var t;return null===(t=this.owner)||void 0===t?void 0:t.get(Ei)}get motion(){var t;return null===(t=this.owner)||void 0===t?void 0:t.get(Ii)}get pos(){return this.transform.globalPos}set pos(t){this.transform.globalPos=t}get vel(){return this.motion.vel}set vel(t){this.motion.vel=t}get acc(){return this.motion.acc}set acc(t){this.motion.acc=t}get torque(){return this.motion.torque}set torque(t){this.motion.torque=t}get rotation(){return this.transform.globalRotation}set rotation(t){this.transform.globalRotation=t}get scale(){return this.transform.globalScale}set scale(t){this.transform.globalScale=t}get sx(){return this.motion.scaleFactor.x}set sx(t){this.motion.scaleFactor.x=t}get sy(){return this.motion.scaleFactor.y}set sy(t){this.motion.scaleFactor.y=t}get rx(){return this.motion.angularVelocity}set rx(t){this.motion.angularVelocity=t}get angularVelocity(){return this.motion.angularVelocity}set angularVelocity(t){this.motion.angularVelocity=t}applyImpulse(t,e){if(this.collisionType!==vi.Active)return;const i=e.scale(this.inverseMass);if(this.limitDegreeOfFreedom.includes(Qi.X)&&(i.x=0),this.limitDegreeOfFreedom.includes(Qi.Y)&&(i.y=0),this.vel.addEqual(i),!this.limitDegreeOfFreedom.includes(Qi.Rotation)){const i=t.sub(this.pos);this.angularVelocity+=this.inverseInertia*i.cross(e)}}applyLinearImpulse(t){if(this.collisionType!==vi.Active)return;const e=t.scale(this.inverseMass);this.limitDegreeOfFreedom.includes(Qi.X)&&(e.x=0),this.limitDegreeOfFreedom.includes(Qi.Y)&&(e.y=0),this.vel=this.vel.add(e)}applyAngularImpulse(t,e){if(this.collisionType===vi.Active&&!this.limitDegreeOfFreedom.includes(Qi.Rotation)){const i=t.sub(this.pos);this.angularVelocity+=this.inverseInertia*i.cross(e)}}captureOldTransform(){this.oldVel.setTo(this.vel.x,this.vel.y),this.oldPos.setTo(this.pos.x,this.pos.y),this.oldAcc.setTo(this.acc.x,this.acc.y),this.oldScale.setTo(this.scale.x,this.scale.y),this.oldRotation=this.rotation}debugDraw(t){}}$i._ID=0;class Ji{constructor(){this._topLeft=new A(0,0),this._topRight=new A(0,0),this._bottomLeft=new A(0,0),this._bottomRight=new A(0,0)}isSpriteOffScreen(t,e){const i=t.currentDrawing.drawWidth,s=t.currentDrawing.drawHeight,r=t.rotation,n=t.center,o=t.getGlobalPos();this._topLeft=P(o.x-i/2,o.y-s/2),this._topLeft=this._topLeft.rotate(r,n),this._topRight=P(o.x+i/2,o.y-s/2),this._topRight=this._topRight.rotate(r,n),this._bottomLeft=P(o.x-i/2,o.y+s/2),this._bottomLeft=this._bottomLeft.rotate(r,n),this._bottomRight=P(o.x+i/2,o.y+s/2),this._bottomRight=this._bottomRight.rotate(r,n);const a=e.worldToScreenCoordinates(this._topLeft),h=e.worldToScreenCoordinates(this._topRight),l=e.worldToScreenCoordinates(this._bottomLeft),c=e.worldToScreenCoordinates(this._bottomRight);this._xCoords=[],this._yCoords=[],this._xCoords.push(a.x,h.x,l.x,c.x),this._yCoords.push(a.y,h.y,l.y,c.y),this._xMin=Math.min.apply(null,this._xCoords),this._yMin=Math.min.apply(null,this._yCoords),this._xMax=Math.max.apply(null,this._xCoords),this._yMax=Math.max.apply(null,this._yCoords);const d=e.screenToWorldCoordinates(new A(this._xMin,this._yMin)),u=e.screenToWorldCoordinates(new A(this._xMax,this._yMax));this._xMinWorld=d.x,this._yMinWorld=d.y,this._xMaxWorld=u.x,this._yMaxWorld=u.y;const p=[new A(this._xMin,this._yMin),new A(this._xMax,this._yMin),new A(this._xMin,this._yMax),new A(this._xMax,this._yMax)];if(p[0].x<0&&p[1].x>e.canvas.clientWidth&&(p[0].y>0||p[2].y<e.canvas.clientHeight))return!1;if(p[0].y<0&&p[2].y>e.canvas.clientHeight&&(p[1].x>0||p[0].x<e.canvas.clientWidth))return!1;for(let t=0;t<p.length;t++)if(p[t].x>0&&p[t].y>0&&p[t].x<e.canvas.clientWidth&&p[t].y<e.canvas.clientHeight)return!1;return!0}debugDraw(t){t.beginPath(),t.strokeStyle=I.White.toString(),t.rect(this._xMinWorld,this._yMinWorld,this._xMaxWorld-this._xMinWorld,this._yMaxWorld-this._yMinWorld),t.stroke(),t.fillStyle=I.Red.toString(),t.beginPath(),t.arc(this._topLeft.x,this._topLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Green.toString(),t.beginPath(),t.arc(this._topRight.x,this._topRight.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Blue.toString(),t.beginPath(),t.arc(this._bottomLeft.x,this._bottomLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=I.Magenta.toString(),t.beginPath(),t.arc(this._bottomRight.x,this._bottomRight.y,5,0,2*Math.PI),t.closePath(),t.fill()}}class ts{constructor(){this.cullingBox=new Ji}update(t,e){const i=t.eventDispatcher;let s=!0;null!=t.currentDrawing&&(s=this.cullingBox.isSpriteOffScreen(t,e));let r=!1;e&&e.currentScene&&e.currentScene.camera&&e.currentScene.camera.viewport&&!t.parent&&(r=!e.currentScene.camera.viewport.intersect(t.collider.bounds)),t.isOffScreen?r&&s||(i.emit("enterviewport",new ne(t)),t.removeComponent("offscreen")):r&&s&&(i.emit("exitviewport",new re(t)),t.addComponent(new Pi("offscreen")))}}class es{constructor(t){this.data=t,this.type="Component Added"}}function is(t){return!!t&&"Component Added"===t.type}class ss{constructor(t){this.data=t,this.type="Component Removed"}}function rs(t){return!!t&&"Component Removed"===t.type}class ns extends hi{constructor(t,e){if(super(),this.id=ns._ID++,this._name="anonymous",this.active=!0,this._componentsToRemove=[],this._componentTypeToInstance=new Map,this._componentStringToInstance=new Map,this._tagsMemo=[],this._typesMemo=[],this.componentAdded$=new Di,this.componentRemoved$=new Di,this._parent=null,this.childrenAdded$=new Di,this.childrenRemoved$=new Di,this._children=[],this._isInitialized=!1,this._setName(e),t)for(const e of t)this.addComponent(e)}_setName(t){t&&(this._name=t)}get name(){return this._name}get events(){return this.eventDispatcher}kill(){this.active=!1}isKilled(){return!this.active}get tags(){return this._tagsMemo}hasTag(t){return this.tags.includes(t)}addTag(t){return this.addComponent(new Pi(t))}removeTag(t,e=!1){return this.removeComponent(t,e)}get types(){return this._typesMemo}_rebuildMemos(){this._tagsMemo=Array.from(this._componentStringToInstance.values()).filter((t=>t instanceof Pi)).map((t=>t.type)),this._typesMemo=Array.from(this._componentStringToInstance.keys())}getComponents(){return Array.from(this._componentStringToInstance.values())}_notifyAddComponent(t){this._rebuildMemos();const e=new es({component:t,entity:this});this.componentAdded$.notifyAll(e)}_notifyRemoveComponent(t){const e=new ss({component:t,entity:this});this.componentRemoved$.notifyAll(e),this._rebuildMemos()}get parent(){return this._parent}get children(){return this._children}unparent(){this._parent&&(this._parent.removeChild(this),this._parent=null)}addChild(t){if(null!==t.parent)throw new Error("Entity already has a parent, cannot add without unparenting");if(this.getAncestors().includes(t))throw new Error("Cycle detected, cannot add entity");return this._children.push(t),t._parent=this,this.childrenAdded$.notifyAll(t),this}removeChild(t){return t.parent===this&&(tt(t,this._children),t._parent=null,this.childrenRemoved$.notifyAll(t)),this}removeAllChildren(){return this.children.forEach((t=>{this.removeChild(t)})),this}getAncestors(){const t=[this];let e=this.parent;for(;e;)t.push(e),e=e.parent;return t.reverse()}getDescendants(){let t=[this],e=[this];for(;e.length>0;){const i=e.pop();e=e.concat(i.children),t=t.concat(i.children)}return t}clone(){const t=new ns;for(const e of this.types)t.addComponent(this.get(e).clone());for(const e of this.children)t.addChild(e.clone());return t}addTemplate(t,e=!1){for(const i of t.getComponents())this.addComponent(i.clone(),e);for(const e of t.children)this.addChild(e.clone().addTemplate(e));return this}addComponent(t,e=!1){if(this.has(t.type)){if(!e)return this;this.removeComponent(t)}if(t.dependencies&&t.dependencies.length)for(const e of t.dependencies)this.addComponent(new e);t.owner=this;const i=t.constructor;return this._componentTypeToInstance.set(i,t),this._componentStringToInstance.set(t.type,t),t.onAdd&&t.onAdd(this),this._notifyAddComponent(t),this}removeComponent(t,e=!1){return e?"string"==typeof t?this._removeComponentByType(t):t instanceof Ai&&this._removeComponentByType(t.type):this._componentsToRemove.push(t),this}_removeComponentByType(t){if(this.has(t)){const e=this.get(t);e.owner=null,e.onRemove&&e.onRemove(this);const i=e.constructor;this._componentTypeToInstance.delete(i),this._componentStringToInstance.delete(e.type),this._notifyRemoveComponent(e)}}processComponentRemoval(){for(const t of this._componentsToRemove){const e="string"==typeof t?t:t.type;this._removeComponentByType(e)}this._componentsToRemove.length=0}has(t){return"string"==typeof t?this._componentStringToInstance.has(t):this._componentTypeToInstance.has(t)}get(t){return"string"==typeof t?this._componentStringToInstance.get(t):this._componentTypeToInstance.get(t)}get isInitialized(){return this._isInitialized}_initialize(t){this.isInitialized||(this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0)}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}onInitialize(t){}onPreUpdate(t,e){}onPostUpdate(t,e){}update(t,e){this._initialize(t),this._preupdate(t,e);for(const i of this.children)i.update(t,e);this._postupdate(t,e)}}ns._ID=0;class os extends Ai{constructor(t){var e;super(),this.draw=t,this.type="ex.canvas",this.draw=null!==(e=this.draw)&&void 0!==e?e:()=>{}}}function as(t){return!!t.tick}class hs{constructor(t,e){this._options=t,this._graphics=e,this.graphics=[]}get name(){return this._options.name}hide(t){if(t){let e=null;e=t instanceof _t?t:this._graphics.getGraphic(t),this.graphics=this.graphics.filter((t=>t.graphic!==e))}else this.graphics.length=0}show(t,e){let i;return e={...e},t instanceof _t?i=this._graphics.copyGraphics?t.clone():t:(i=this._graphics.getGraphic(t),i||f.getInstance().error(`No such graphic added to component named ${t}. These named graphics are available: `,this._graphics.getNames())),i?(this.graphics.push({graphic:i,options:e}),i):null}use(t,e){return e={...e},this.hide(),this.show(t,e)}get order(){return this._options.order}set order(t){this._options.order=t}get offset(){var t;return null!==(t=this._options.offset)&&void 0!==t?t:A.Zero}set offset(t){this._options.offset=t}get currentKeys(){var t;return null!==(t=this.name)&&void 0!==t?t:"anonymous"}}class ls{constructor(t){this._component=t,this._layers=[],this._layerMap={},this.default=new hs({name:"default",order:0},t),this._maybeAddLayer(this.default)}create(t){const e=new hs(t,this._component);return this._maybeAddLayer(e)}get(t){return t?this._getLayer(t):this._layers}currentKeys(){const t=[];for(const e of this._layers)t.push(e.currentKeys);return t}has(t){return t in this._layerMap}_maybeAddLayer(t){return this._layerMap[t.name]?this._layerMap[t.name]:(this._layerMap[t.name]=t,this._layers.push(t),this._layers.sort(((t,e)=>t.order-e.order)),t)}_getLayer(t){return this._layerMap[t]}}class cs extends Ai{constructor(t){super(),this.type="ex.graphics",this._graphics={},this.visible=!0,this.opacity=1,this.offset=A.Zero,this.anchor=A.Half,this.copyGraphics=!1,this._bounds=null,t={visible:this.visible,...t};const{current:e,anchor:i,opacity:s,visible:r,graphics:n,offset:o,copyGraphics:a,onPreDraw:h,onPostDraw:l}=t;this._graphics=n||{},this.offset=null!=o?o:this.offset,this.opacity=null!=s?s:this.opacity,this.anchor=null!=i?i:this.anchor,this.copyGraphics=null!=a?a:this.copyGraphics,this.onPreDraw=null!=h?h:this.onPreDraw,this.onPostDraw=null!=l?l:this.onPostDraw,this.visible=!!r,this.layers=new ls(this),e&&this._graphics[e]&&this.show(this._graphics[e])}getGraphic(t){return this._graphics[t]}getNames(){return Object.keys(this._graphics)}get current(){return this.layers.default.graphics}get graphics(){return this._graphics}add(t,e){let i="default",s=null;return"string"==typeof t?(i=t,s=e):s=t,this._graphics[i]=this.copyGraphics?s.clone():s,"default"===i&&this.show("default"),s}show(t,e){return this.layers.default.show(t,e)}use(t,e){return this.layers.default.use(t,e)}hide(t){this.layers.default.hide(t)}set localBounds(t){this._bounds=t}get localBounds(){if(this._bounds)return this._bounds;let t=new D;for(const e of this.layers.get())for(const{graphic:i,options:s}of e.graphics){let r=this.anchor,n=this.offset;(null==s?void 0:s.anchor)&&(r=s.anchor),(null==s?void 0:s.offset)&&(n=s.offset);const o=i.localBounds,a=-o.width*r.x+n.x,h=-o.height*r.y+n.y;t=null==i?void 0:i.localBounds.translate(P(a+e.offset.x,h+e.offset.y)).combine(t)}return t}update(t,e=0){for(const i of this.layers.get())for(const{graphic:s}of i.graphics)as(s)&&(null==s||s.tick(t,e))}}class ds extends Ct{constructor(t){super(t),this.width=t.width,this.height=t.height,this.rasterize()}clone(){return new ds({width:this.width,height:this.height,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){this.color&&t.fillRect(0,0,this.width,this.height),this.strokeColor&&t.strokeRect(0,0,this.width,this.height)}}class us extends Ct{constructor(t){var e,i;super(t),this._radius=0,this.padding=null!==(e=t.padding)&&void 0!==e?e:2,this.radius=t.radius,this.filtering=null!==(i=t.filtering)&&void 0!==i?i:ht.Blended,this.rasterize()}get radius(){return this._radius}set radius(t){this._radius=t,this.width=2*this._radius,this.height=2*this._radius,this.flagDirty()}clone(){return new us({radius:this.radius,...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){this.radius>0&&(t.beginPath(),t.arc(this.radius,this.radius,this.radius,0,2*Math.PI),this.color&&t.fill(),this.strokeColor&&t.stroke())}}class ps extends Ai{constructor(){super(...arguments),this.type="ex.pointer",this.useColliderShape=!0,this.useGraphicsBounds=!1}}var gs,_s=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class fs{static CreateReversibleEasingFunction(t){return(e,i,s,r)=>s<i?i-(t(e,s,i,r)-s):t(e,i,s,r)}static CreateReversableEasingFunction(t){return fs.CreateReversibleEasingFunction(t)}static CreateVectorEasingFunction(t){return(e,i,s,r)=>new A(t(e,i.x,s.x,r),t(e,i.y,s.y,r))}}fs.Linear=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*t/s+e)),fs.EaseInQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t+e)),fs.EaseOutQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>-(i-=e)*(t/=s)*(t-2)+e)),fs.EaseInOutQuad=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e,(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e))),fs.EaseInCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t*t+e)),fs.EaseOutCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(t/=s,(i-=e)*(--t*t*t+1)+e))),fs.EaseInOutCubic=fs.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e,(t/=s/2)<1?i/2*t*t*t+e:i/2*((t-=2)*t*t+2)+e))),_s([C({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"CreateReversibleEasingFunction"})],fs,"CreateReversableEasingFunction",null);class ms{constructor(t){this._actions=[],this._completedActions=[],this._entity=t}add(t){this._actions.push(t)}remove(t){const e=this._actions.indexOf(t);this._actions.splice(e,1)}clearActions(){this._actions.length=0,this._completedActions.length=0,this._currentAction&&this._currentAction.stop()}getActions(){return this._actions.concat(this._completedActions)}hasNext(){return this._actions.length>0}isComplete(){return 0===this._actions.length}reset(){this._actions=this.getActions();const t=this._actions.length;for(let e=0;e<t;e++)this._actions[e].reset();this._completedActions=[]}update(t){this._actions.length>0&&(this._currentAction=this._actions[0],this._currentAction.update(t),this._currentAction.isComplete(this._entity)&&this._completedActions.push(this._actions.shift()))}}class vs{constructor(t,e,i){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new ks(t),this._actionQueue=this._repeatContext.getQueue(),this._repeat=i,this._originalRepeat=i,this._repeatBuilder(this._repeatContext),this._repeat--}update(t){this._actionQueue.isComplete()&&(this._actionQueue.clearActions(),this._repeatBuilder(this._repeatContext),this._repeat--),this._actionQueue.update(t)}isComplete(){return this._stopped||this._repeat<=0&&this._actionQueue.isComplete()}stop(){this._stopped=!0}reset(){this._repeat=this._originalRepeat}}class ys{constructor(t,e){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new ks(t),this._actionQueue=this._repeatContext.getQueue(),this._repeatBuilder(this._repeatContext)}update(t){this._stopped||(this._actionQueue.isComplete()&&(this._actionQueue.clearActions(),this._repeatBuilder(this._repeatContext)),this._actionQueue.update(t))}isComplete(){return this._stopped}stop(){this._stopped=!0,this._actionQueue.clearActions()}reset(){}}class ws{constructor(t,e,i,s){if(this._started=!1,this._stopped=!1,this._entity=t,this._tx=t.get(Ei),this._motion=t.get(Ii),this._speed=s,this._offset=new A(e,i),s<=0)throw f.getInstance().error("Attempted to moveBy with speed less than or equal to zero : "+s),new Error("Speed must be greater than 0 pixels per second")}update(t){this._started||(this._started=!0,this._start=new A(this._tx.pos.x,this._tx.pos.y),this._end=this._start.add(this._offset),this._distance=this._offset.size,this._dir=this._end.sub(this._start).normalize()),this.isComplete(this._entity)?(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0)):this._motion.vel=this._dir.scale(this._speed)}isComplete(t){const e=t.get(Ei);return this._stopped||e.pos.distance(this._start)>=this._distance}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}class xs{constructor(t,e,i,s){this.entity=t,this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._end=new A(e,i),this._speed=s}update(t){this._started||(this._started=!0,this._start=new A(this._tx.pos.x,this._tx.pos.y),this._distance=this._start.distance(this._end),this._dir=this._end.sub(this._start).normalize());const e=this._dir.scale(this._speed);this._motion.vel=P(e.x,e.y),this.isComplete(this.entity)&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}isComplete(t){const e=t.get(Ei);return this._stopped||new A(e.pos.x,e.pos.y).distance(this._start)>=this._distance}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}!function(t){t[t.ShortestPath=0]="ShortestPath",t[t.LongestPath=1]="LongestPath",t[t.Clockwise=2]="Clockwise",t[t.CounterClockwise=3]="CounterClockwise"}(gs||(gs={}));class bs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._end=e,this._speed=i,this._rotationType=s||gs.ShortestPath}update(t){if(!this._started){this._started=!0,this._start=this._tx.rotation,this._currentNonCannonAngle=this._tx.rotation;const t=Math.abs(this._end-this._start),e=k-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+k)%k>=Math.PI,this._rotationType){case gs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case gs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case gs.Clockwise:this._direction=1,this._shortestPathIsPositive?this._distance=this._shortDistance:this._distance=this._longDistance;break;case gs.CounterClockwise:this._direction=-1,this._shortestPathIsPositive?this._distance=this._longDistance:this._distance=this._shortDistance}}this._motion.angularVelocity=this._direction*this._speed,this._currentNonCannonAngle+=this._direction*this._speed*(t/1e3),this.isComplete()&&(this._tx.rotation=this._end,this._motion.angularVelocity=0,this._stopped=!0)}isComplete(){const t=Math.abs(this._currentNonCannonAngle-this._start);return this._stopped||t>=Math.abs(this._distance)}stop(){this._motion.angularVelocity=0,this._stopped=!0}reset(){this._started=!1}}class Cs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._speed=i,this._offset=e,this._rotationType=s||gs.ShortestPath}update(t){if(!this._started){this._started=!0,this._start=this._tx.rotation,this._currentNonCannonAngle=this._tx.rotation,this._end=this._start+this._offset;const t=Math.abs(this._end-this._start),e=k-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+k)%k>=Math.PI,this._rotationType){case gs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case gs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case gs.Clockwise:this._direction=1,this._shortDistance>=0?this._distance=this._shortDistance:this._distance=this._longDistance;break;case gs.CounterClockwise:this._direction=-1,this._shortDistance<=0?this._distance=this._shortDistance:this._distance=this._longDistance}}this._motion.angularVelocity=this._direction*this._speed,this._currentNonCannonAngle+=this._direction*this._speed*(t/1e3),this.isComplete()&&(this._tx.rotation=this._end,this._motion.angularVelocity=0,this._stopped=!0)}isComplete(){const t=Math.abs(this._currentNonCannonAngle-this._start);return this._stopped||t>=Math.abs(this._distance)}stop(){this._motion.angularVelocity=0,this._stopped=!0}reset(){this._started=!1}}class Ss{constructor(t,e,i,s,r){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._endX=e,this._endY=i,this._speedX=s,this._speedY=r}update(t){if(this._started||(this._started=!0,this._startX=this._tx.scale.x,this._startY=this._tx.scale.y,this._distanceX=Math.abs(this._endX-this._startX),this._distanceY=Math.abs(this._endY-this._startY)),Math.abs(this._tx.scale.x-this._startX)>=this._distanceX)this._motion.scaleFactor.x=0;else{const t=this._endY<this._startY?-1:1;this._motion.scaleFactor.x=this._speedX*t}if(Math.abs(this._tx.scale.y-this._startY)>=this._distanceY)this._motion.scaleFactor.y=0;else{const t=this._endY<this._startY?-1:1;this._motion.scaleFactor.y=this._speedY*t}this.isComplete()&&(this._tx.scale=P(this._endX,this._endY),this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0)}isComplete(){return this._stopped||Math.abs(this._tx.scale.y-this._startX)>=this._distanceX&&Math.abs(this._tx.scale.y-this._startY)>=this._distanceY}stop(){this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0,this._stopped=!0}reset(){this._started=!1}}class As{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._offset=new A(e,i),this._speedX=this._speedY=s}update(t){this._started||(this._started=!0,this._startScale=this._tx.scale.clone(),this._endScale=this._startScale.add(this._offset),this._distanceX=Math.abs(this._endScale.x-this._startScale.x),this._distanceY=Math.abs(this._endScale.y-this._startScale.y),this._directionX=this._endScale.x<this._startScale.x?-1:1,this._directionY=this._endScale.y<this._startScale.y?-1:1),this._motion.scaleFactor.x=this._speedX*this._directionX,this._motion.scaleFactor.y=this._speedY*this._directionY,this.isComplete()&&(this._tx.scale=this._endScale,this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0)}isComplete(){return this._stopped||Math.abs(this._tx.scale.x-this._startScale.x)>=this._distanceX&&Math.abs(this._tx.scale.y-this._startScale.y)>=this._distanceY}stop(){this._motion.scaleFactor.x=0,this._motion.scaleFactor.y=0,this._stopped=!0}reset(){this._started=!1}}class Ps{constructor(t){this._method=null,this._hasBeenCalled=!1,this._method=t}update(t){this._method(),this._hasBeenCalled=!0}isComplete(){return this._hasBeenCalled}reset(){this._hasBeenCalled=!1}stop(){this._hasBeenCalled=!0}}class Ts{constructor(t,e,i,s,r){this.easingFcn=r,this._currentLerpTime=0,this._lerpDuration=1e3,this._lerpStart=new A(0,0),this._lerpEnd=new A(0,0),this._initialized=!1,this._stopped=!1,this._distance=0,this._tx=t.get(Ei),this._motion=t.get(Ii),this._lerpDuration=s,this._lerpEnd=new A(e,i)}_initialize(){this._lerpStart=new A(this._tx.pos.x,this._tx.pos.y),this._currentLerpTime=0,this._distance=this._lerpStart.distance(this._lerpEnd)}update(t){this._initialized||(this._initialize(),this._initialized=!0),this._currentLerpTime+=t;let e=this._tx.pos.x,i=this._tx.pos.y;this._currentLerpTime<this._lerpDuration?(e=this._lerpEnd.x<this._lerpStart.x?this._lerpStart.x-(this.easingFcn(this._currentLerpTime,this._lerpEnd.x,this._lerpStart.x,this._lerpDuration)-this._lerpEnd.x):this.easingFcn(this._currentLerpTime,this._lerpStart.x,this._lerpEnd.x,this._lerpDuration),i=this._lerpEnd.y<this._lerpStart.y?this._lerpStart.y-(this.easingFcn(this._currentLerpTime,this._lerpEnd.y,this._lerpStart.y,this._lerpDuration)-this._lerpEnd.y):this.easingFcn(this._currentLerpTime,this._lerpStart.y,this._lerpEnd.y,this._lerpDuration),this._motion.vel=P((e-this._tx.pos.x)/(t/1e3),(i-this._tx.pos.y)/(t/1e3))):(this._tx.pos=P(this._lerpEnd.x,this._lerpEnd.y),this._motion.vel=A.Zero)}isComplete(t){return this._stopped||new A(t.pos.x,t.pos.y).distance(this._lerpStart)>=this._distance}reset(){this._initialized=!1}stop(){this._motion.vel=P(0,0),this._stopped=!0}}class Es{constructor(t,e,i,s=1){this._timeVisible=0,this._timeNotVisible=0,this._elapsedTime=0,this._totalTime=0,this._stopped=!1,this._started=!1,this._graphics=t.get(cs),this._timeVisible=e,this._timeNotVisible=i,this._duration=(e+i)*s}update(t){this._started||(this._started=!0),this._graphics&&(this._elapsedTime+=t,this._totalTime+=t,this._graphics.visible&&this._elapsedTime>=this._timeVisible&&(this._graphics.visible=!1,this._elapsedTime=0),!this._graphics.visible&&this._elapsedTime>=this._timeNotVisible&&(this._graphics.visible=!0,this._elapsedTime=0),this.isComplete()&&(this._graphics.visible=!0))}isComplete(){return this._stopped||this._totalTime>=this._duration}stop(){this._graphics&&(this._graphics.visible=!0),this._stopped=!0}reset(){this._started=!1,this._elapsedTime=0,this._totalTime=0}}class Is{constructor(t,e,i){this._multiplier=1,this._started=!1,this._stopped=!1,this._graphics=t.get(cs),this._endOpacity=e,this._speed=i}update(t){this._graphics&&(this._started||(this._started=!0,this._endOpacity<this._graphics.opacity?this._multiplier=-1:this._multiplier=1),this._speed>0&&(this._graphics.opacity+=this._multiplier*(Math.abs(this._graphics.opacity-this._endOpacity)*t)/this._speed),this._speed-=t,this.isComplete()&&(this._graphics.opacity=this._endOpacity),f.getInstance().debug("[Action fade] Actor opacity:",this._graphics.opacity))}isComplete(){return this._stopped||Math.abs(this._graphics.opacity-this._endOpacity)<.05}stop(){this._stopped=!0}reset(){this._started=!1}}class Rs{constructor(t){this._elapsedTime=0,this._started=!1,this._stopped=!1,this._delay=t}update(t){this._started||(this._started=!0),this._elapsedTime+=t}isComplete(){return this._stopped||this._elapsedTime>=this._delay}stop(){this._stopped=!0}reset(){this._elapsedTime=0,this._started=!1}}class Ds{constructor(t){this._stopped=!1,this._entity=t}update(t){this._entity.get(Fs).clearActions(),this._entity.kill(),this._stopped=!0}isComplete(){return this._stopped}stop(){}reset(){}}class Bs{constructor(t,e,i){this._started=!1,this._stopped=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._followTx=e.get(Ei),this._followMotion=e.get(Ii),this._current=new A(this._tx.pos.x,this._tx.pos.y),this._end=new A(this._followTx.pos.x,this._followTx.pos.y),this._maximumDistance=void 0!==i?i:this._current.distance(this._end),this._speed=0}update(t){this._started||(this._started=!0,this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize());const e=Math.sqrt(Math.pow(this._followMotion.vel.x,2)+Math.pow(this._followMotion.vel.y,2));if(0!==e&&(this._speed=e),this._current=P(this._tx.pos.x,this._tx.pos.y),this._end=P(this._followTx.pos.x,this._followTx.pos.y),this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize(),this._distanceBetween>=this._maximumDistance){const t=this._dir.scale(this._speed);this._motion.vel=P(t.x,t.y)}else this._motion.vel=P(0,0);this.isComplete()&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}stop(){this._motion.vel=P(0,0),this._stopped=!0}isComplete(){return this._stopped}reset(){this._started=!1}}class Ms{constructor(t,e,i){this._started=!1,this._stopped=!1,this._speedWasSpecified=!1,this._tx=t.get(Ei),this._motion=t.get(Ii),this._meetTx=e.get(Ei),this._meetMotion=e.get(Ii),this._current=new A(this._tx.pos.x,this._tx.pos.y),this._end=new A(this._meetTx.pos.x,this._meetTx.pos.y),this._speed=i||0,void 0!==i&&(this._speedWasSpecified=!0)}update(t){this._started||(this._started=!0,this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize());const e=Math.sqrt(Math.pow(this._meetMotion.vel.x,2)+Math.pow(this._meetMotion.vel.y,2));0===e||this._speedWasSpecified||(this._speed=e),this._current=P(this._tx.pos.x,this._tx.pos.y),this._end=P(this._meetTx.pos.x,this._meetTx.pos.y),this._distanceBetween=this._current.distance(this._end),this._dir=this._end.sub(this._current).normalize();const i=this._dir.scale(this._speed);this._motion.vel=P(i.x,i.y),this.isComplete()&&(this._tx.pos=P(this._end.x,this._end.y),this._motion.vel=P(0,0))}isComplete(){return this._stopped||this._distanceBetween<=1}stop(){this._motion.vel=P(0,0),this._stopped=!0}reset(){this._started=!1}}class ks{constructor(t){this._entity=t,this._queue=new ms(t)}getQueue(){return this._queue}update(t){this._queue.update(t)}clearActions(){this._queue.clearActions()}easeTo(...t){var e,i;let s=0,r=0,n=0,o=fs.Linear;return t[0]instanceof A?(s=t[0].x,r=t[0].y,n=t[1],o=null!==(e=t[2])&&void 0!==e?e:o):(s=t[0],r=t[1],n=t[2],o=null!==(i=t[3])&&void 0!==i?i:o),this._queue.add(new Ts(this._entity,s,r,n,o)),this}moveTo(t,e,i){let s=0,r=0,n=0;return t instanceof A?(s=t.x,r=t.y,n=e):(s=t,r=e,n=i),this._queue.add(new xs(this._entity,s,r,n)),this}moveBy(t,e,i){let s=0,r=0,n=0;return t instanceof A?(s=t.x,r=t.y,n=e):(s=t,r=e,n=i),this._queue.add(new ws(this._entity,s,r,n)),this}rotateTo(t,e,i){return this._queue.add(new bs(this._entity,t,e,i)),this}rotateBy(t,e,i){return this._queue.add(new Cs(this._entity,t,e,i)),this}scaleTo(t,e,i,s){let r=1,n=1,o=0,a=0;return t instanceof A&&e instanceof A&&(r=t.x,n=t.y,o=e.x,a=e.y),"number"==typeof t&&"number"==typeof e&&(r=t,n=e,o=i,a=s),this._queue.add(new Ss(this._entity,r,n,o,a)),this}scaleBy(t,e,i){let s=1,r=1;return t instanceof A&&(s=t.x,r=t.y,i=e),"number"==typeof t&&"number"==typeof e&&(s=t,r=e),this._queue.add(new As(this._entity,s,r,i)),this}blink(t,e,i=1){return this._queue.add(new Es(this._entity,t,e,i)),this}fade(t,e){return this._queue.add(new Is(this._entity,t,e)),this}delay(t){return this._queue.add(new Rs(t)),this}die(){return this._queue.add(new Ds(this._entity)),this}callMethod(t){return this._queue.add(new Ps(t)),this}repeat(t,e){return e?(this._queue.add(new vs(this._entity,t,e)),this):(this.repeatForever(t),this)}repeatForever(t){return this._queue.add(new ys(this._entity,t)),this}follow(t,e){return void 0===e?this._queue.add(new Bs(this._entity,t)):this._queue.add(new Bs(this._entity,t,e)),this}meet(t,e){return void 0===e?this._queue.add(new Ms(this._entity,t)):this._queue.add(new Ms(this._entity,t,e)),this}asPromise(){return this.toPromise()}toPromise(){return new Promise((t=>{this._queue.add(new Ps((()=>{t()})))}))}}class Fs extends Ai{constructor(){super(...arguments),this.type="ex.actions",this.dependencies=[Ei,Ii]}onAdd(t){this._ctx=new ks(t)}onRemove(){this._ctx=null}getQueue(){var t;return null===(t=this._ctx)||void 0===t?void 0:t.getQueue()}update(t){var e;return null===(e=this._ctx)||void 0===e?void 0:e.update(t)}clearActions(){var t;null===(t=this._ctx)||void 0===t||t.clearActions()}easeTo(...t){return this._ctx.easeTo.apply(this._ctx,t)}moveTo(t,e,i){return this._ctx.moveTo.apply(this._ctx,[t,e,i])}moveBy(t,e,i){return this._ctx.moveBy.apply(this._ctx,[t,e,i])}rotateTo(t,e,i){return this._ctx.rotateTo(t,e,i)}rotateBy(t,e,i){return this._ctx.rotateBy(t,e,i)}scaleTo(t,e,i,s){return this._ctx.scaleTo.apply(this._ctx,[t,e,i,s])}scaleBy(t,e,i){return this._ctx.scaleBy.apply(this._ctx,[t,e,i])}blink(t,e,i){return this._ctx.blink(t,e,i)}fade(t,e){return this._ctx.fade(t,e)}delay(t){return this._ctx.delay(t)}die(){return this._ctx.die()}callMethod(t){return this._ctx.callMethod(t)}repeat(t,e){return this._ctx.repeat(t,e)}repeatForever(t){return this._ctx.repeatForever(t)}follow(t,e){return this._ctx.follow(t,e)}meet(t,e){return this._ctx.meet(t,e)}asPromise(){return this.toPromise()}toPromise(){return this._ctx.toPromise()}}class Ls extends _t{constructor(t={}){var e,i,s,r,n,o,a,h,l,c,d,u,p,g,_,f,m,v,y;super(t),this.filtering=ht.Blended,this.quality=2,this.padding=2,this.smoothing=!1,this.lineWidth=1,this.lineDash=[],this.color=I.Black,this.family="sans-serif",this.style=Me.Normal,this.bold=!1,this.unit=Re.Px,this.textAlign=De.Left,this.baseAlign=Be.Alphabetic,this.direction=ke.LeftToRight,this.size=10,this.shadow=null,this._textBounds=new D,this._textToBitmap=new Map,this._bitmapUsage=new Map,this.smoothing=null!==(e=null==t?void 0:t.smoothing)&&void 0!==e?e:this.smoothing,this.padding=null!==(i=null==t?void 0:t.padding)&&void 0!==i?i:this.padding,this.color=null!==(s=null==t?void 0:t.color)&&void 0!==s?s:this.color,this.strokeColor=null!==(r=null==t?void 0:t.strokeColor)&&void 0!==r?r:this.strokeColor,this.lineDash=null!==(n=null==t?void 0:t.lineDash)&&void 0!==n?n:this.lineDash,this.lineWidth=null!==(o=null==t?void 0:t.lineWidth)&&void 0!==o?o:this.lineWidth,this.filtering=null!==(a=null==t?void 0:t.filtering)&&void 0!==a?a:this.filtering,this.family=null!==(h=null==t?void 0:t.family)&&void 0!==h?h:this.family,this.style=null!==(l=null==t?void 0:t.style)&&void 0!==l?l:this.style,this.bold=null!==(c=null==t?void 0:t.bold)&&void 0!==c?c:this.bold,this.size=null!==(d=null==t?void 0:t.size)&&void 0!==d?d:this.size,this.unit=null!==(u=null==t?void 0:t.unit)&&void 0!==u?u:this.unit,this.textAlign=null!==(p=null==t?void 0:t.textAlign)&&void 0!==p?p:this.textAlign,this.baseAlign=null!==(g=null==t?void 0:t.baseAlign)&&void 0!==g?g:this.baseAlign,this.direction=null!==(_=null==t?void 0:t.direction)&&void 0!==_?_:this.direction,this.quality=null!==(f=null==t?void 0:t.quality)&&void 0!==f?f:this.quality,(null==t?void 0:t.shadow)&&(this.shadow={},this.shadow.blur=null!==(m=t.shadow.blur)&&void 0!==m?m:this.shadow.blur,this.shadow.offset=null!==(v=t.shadow.offset)&&void 0!==v?v:this.shadow.offset,this.shadow.color=null!==(y=t.shadow.color)&&void 0!==y?y:this.shadow.color)}clone(){return new Ls({...this.cloneGraphicOptions(),size:this.size,unit:this.unit,family:this.family,style:this.style,bold:this.bold,textAlign:this.textAlign,baseAlign:this.baseAlign,direction:this.direction,shadow:this.shadow?{blur:this.shadow.blur,offset:this.shadow.offset,color:this.shadow.color}:null})}get fontString(){return`${this.style} ${this.bold?"bold":""} ${this.size}${this.unit} ${this.family}`}get localBounds(){return this._textBounds}_drawImage(t,e,i){}_rotate(t){var e;const i=null!==(e=this.origin)&&void 0!==e?e:this._textBounds.center;t.translate(i.x,i.y),t.rotate(this.rotation),t.translate(-i.x,-i.y)}_flip(t){this.flipHorizontal&&(t.translate(this._textBounds.width/this.scale.x,0),t.scale(-1,1)),this.flipVertical&&(t.translate(0,-this._textBounds.height/2/this.scale.y),t.scale(1,-1))}measureText(t){const e=t.split("\n"),i=e.reduce(((t,e)=>t.length>e.length?t:e)),s=this._getTextBitmap(t);this._applyFont(s);const r=s.measureText(i);let n=Math.abs(r.actualBoundingBoxAscent)+Math.abs(r.actualBoundingBoxDescent);const o=n*e.length;n=o;const a=o-Math.abs(r.actualBoundingBoxAscent);return new D({left:0-Math.abs(r.actualBoundingBoxLeft)-this.padding,top:0-Math.abs(r.actualBoundingBoxAscent)-this.padding,bottom:0+a+this.padding,right:0+Math.abs(r.actualBoundingBoxRight)+this.padding})}_setDimension(t,e){e.canvas.width=2*(t.width+2*this.padding)*this.quality,e.canvas.height=2*(t.height+2*this.padding)*this.quality}_postDraw(t){t.restore()}_getRasterPropertiesHash(t){var e,i;return"__hashcode__"+this.fontString+this.showDebug+this.textAlign+this.baseAlign+this.direction+JSON.stringify(this.shadow)+(this.padding.toString()+this.smoothing.toString()+this.lineWidth.toString()+this.lineDash.toString()+(null===(e=this.strokeColor)||void 0===e?void 0:e.toString())+(t?t.toString():null===(i=this.color)||void 0===i?void 0:i.toString()).toString())}_applyRasterProperties(t,e){var i,s,r;t.translate(this.padding,this.padding),t.imageSmoothingEnabled=this.smoothing,t.lineWidth=this.lineWidth,t.setLineDash(null!==(i=this.lineDash)&&void 0!==i?i:t.getLineDash()),t.strokeStyle=null===(s=this.strokeColor)||void 0===s?void 0:s.toString(),t.fillStyle=e?e.toString():null===(r=this.color)||void 0===r?void 0:r.toString()}_applyFont(t){t.translate(this.padding+t.canvas.width/2,this.padding+t.canvas.height/2),t.scale(this.quality,this.quality),t.textAlign=this.textAlign,t.textBaseline=this.baseAlign,t.font=this.fontString,t.direction=this.direction,this.shadow&&(t.shadowColor=this.shadow.color.toString(),t.shadowBlur=this.shadow.blur,t.shadowOffsetX=this.shadow.offset.x,t.shadowOffsetY=this.shadow.offset.y)}_drawText(t,e,i,s){const r=e.split("\n");this._applyRasterProperties(t,i),this._applyFont(t);for(let e=0;e<r.length;e++){const i=r[e];this.color&&t.fillText(i,0,e*s),this.strokeColor&&t.strokeText(i,0,e*s)}this.showDebug&&(li(t,I.Red,-t.canvas.width/2,0,t.canvas.width/2,0,2),li(t,I.Red,0,-t.canvas.height/2,0,t.canvas.height/2,2))}_getTextBitmap(t,e){const i=t+this._getRasterPropertiesHash(e),s=this._textToBitmap.get(i);if(s)return s;const r=document.createElement("canvas").getContext("2d");return this._textToBitmap.set(i,r),r}render(t,e,i,s,r){this.showDebug&&this.clearCache(),this.checkAndClearCache();const n=this._getTextBitmap(e,i),o=!this._bitmapUsage.get(n);this._textBounds=this.measureText(e),o&&this._setDimension(this._textBounds,n),this._preDraw(t,s,r);const a=e.split("\n"),h=this._textBounds.height/a.length,l=n.canvas.width,c=n.canvas.height;o&&(this._drawText(n,e,i,h),bt.load(n.canvas,this.filtering,!0)),t.drawImage(n.canvas,0,0,l,c,s-l/this.quality/2,r-c/this.quality/2,l/this.quality,c/this.quality),this._postDraw(t),this._bitmapUsage.set(n,performance.now())}get cacheSize(){return this._bitmapUsage.size}clearCache(){this._bitmapUsage.clear()}checkAndClearCache(){for(const[t,e]of this._bitmapUsage.entries())e+1e3<performance.now()&&this._bitmapUsage.delete(t)}}class zs extends _t{constructor(t){var e,i;super(t),this._text="",this._textWidth=0,this._textHeight=0,this.font=null!==(e=t.font)&&void 0!==e?e:new Ls,this.color=null!==(i=t.color)&&void 0!==i?i:this.color,this.text=t.text}clone(){var t,e;return new zs({text:this.text.slice(),color:null!==(e=null===(t=this.color)||void 0===t?void 0:t.clone())&&void 0!==e?e:I.Black,font:this.font.clone()})}get text(){return this._text}set text(t){this._text=t;const e=this.font.measureText(this._text);this._textWidth=e.width,this._textHeight=e.height}get font(){return this._font}set font(t){this._font=t}get width(){return 0===this._textWidth&&this._calculateDimension(),this._textWidth*this.scale.x}get height(){return 0===this._textHeight&&this._calculateDimension(),this._textHeight*this.scale.y}_calculateDimension(){const{width:t,height:e}=this.font.measureText(this._text);this._textWidth=t,this._textHeight=e}get localBounds(){return this.font.measureText(this._text).scale(this.scale)}_rotate(t){}_flip(t){}_drawImage(t,e,i){var s;let r=I.Black;this.font instanceof Ls&&(r=null!==(s=this.color)&&void 0!==s?s:this.font.color),(this.isStale()||this.font.isStale())&&(this.font.flipHorizontal=this.flipHorizontal,this.font.flipVertical=this.flipVertical,this.font.rotation=this.rotation,this.font.origin=this.origin,this.font.opacity=this.opacity);const{width:n,height:o}=this.font.measureText(this._text);this._textWidth=n,this._textHeight=o,this.font.render(t,this._text,r,e,i),this.font.showDebug&&t.debug.drawRect(e-n,i-o,2*n,2*o)}}var Os=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Us extends ns{constructor(t){super(),this._anchor=pt(A.Half,(t=>this._handleAnchorChange(t))),this.logger=f.getInstance(),this.scene=null,this.frames={},this.currentDrawing=null,this._draggable=!1,this._dragging=!1,this._pointerDragStartHandler=()=>{this._dragging=!0},this._pointerDragEndHandler=()=>{this._dragging=!1},this._pointerDragMoveHandler=t=>{this._dragging&&(this.pos=t.worldPos)},this._pointerDragLeaveHandler=t=>{this._dragging&&(this.pos=t.worldPos)},this.traits=[];const{name:e,x:i,y:s,pos:r,coordPlane:n,scale:o,width:a,height:h,radius:l,collider:c,vel:u,acc:p,rotation:_,angularVelocity:m,z:v,color:y,visible:w,anchor:x,collisionType:b,collisionGroup:C}={...t};this._setName(e),this.anchor=null!=x?x:Us.defaults.anchor.clone();const S=new Ei;this.addComponent(S),this.pos=null!=r?r:P(null!=i?i:0,null!=s?s:0),this.rotation=null!=_?_:0,this.scale=null!=o?o:P(1,1),this.z=null!=v?v:0,S.coordPlane=null!=n?n:Ti.World,this.addComponent(new ps),this.addComponent(new cs({anchor:this.anchor})),this.addComponent(new os(((t,e)=>this.draw(t,e)))),this.addComponent(new Ii),this.vel=null!=u?u:A.Zero,this.acc=null!=p?p:A.Zero,this.angularVelocity=null!=m?m:0,this.addComponent(new Fs),this.addComponent(new $i),this.body.collisionType=null!=b?b:vi.Passive,C&&(this.body.group=C),c?this.addComponent(new Yi(c)):l?this.addComponent(new Yi(Zi.Circle(l,this.anchor))):a>0&&h>0?this.addComponent(new Yi(Zi.Box(a,h,this.anchor))):this.addComponent(new Yi),this.graphics.visible=null==w||w,y&&(this.color=y,a&&h?this.graphics.add(new ds({color:y,width:a,height:h})):l&&this.graphics.add(new us({color:y,radius:l}))),g.isEnabled(d.LegacyDrawing)&&this.traits.push(new ts)}get body(){return this.get($i)}get transform(){return this.get(Ei)}get motion(){return this.get(Ii)}get graphics(){return this.get(cs)}get collider(){return this.get(Yi)}get pointer(){return this.get(ps)}get actions(){return this.get(Fs)}get pos(){return this.transform.pos}set pos(t){this.transform.pos=t.clone()}get oldPos(){return this.body.oldPos}set oldPos(t){this.body.oldPos.setTo(t.x,t.y)}get vel(){return this.motion.vel}set vel(t){this.motion.vel=t.clone()}get oldVel(){return this.body.oldVel}set oldVel(t){this.body.oldVel.setTo(t.x,t.y)}get acc(){return this.motion.acc}set acc(t){this.motion.acc=t.clone()}set oldAcc(t){this.body.oldAcc.setTo(t.x,t.y)}get oldAcc(){return this.body.oldAcc}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angularVelocity(){return this.motion.angularVelocity}set angularVelocity(t){this.motion.angularVelocity=t}get scale(){return this.get(Ei).scale}set scale(t){this.get(Ei).scale=t}get anchor(){return this._anchor}set anchor(t){this._anchor=pt(t,(t=>this._handleAnchorChange(t))),this._handleAnchorChange(t)}_handleAnchorChange(t){this.graphics&&(this.graphics.anchor=t)}get isOffScreen(){return this.hasTag("offscreen")}get visible(){return this.graphics.visible}set visible(t){this.graphics.visible=t}get opacity(){return this.graphics.opacity}set opacity(t){this.graphics.opacity=t}get draggable(){return this._draggable}set draggable(t){t&&(t&&!this._draggable?(this.on("pointerdragstart",this._pointerDragStartHandler),this.on("pointerdragend",this._pointerDragEndHandler),this.on("pointerdragmove",this._pointerDragMoveHandler),this.on("pointerdragleave",this._pointerDragLeaveHandler)):!t&&this._draggable&&(this.off("pointerdragstart",this._pointerDragStartHandler),this.off("pointerdragend",this._pointerDragEndHandler),this.off("pointerdragmove",this._pointerDragMoveHandler),this.off("pointerdragleave",this._pointerDragLeaveHandler)),this._draggable=t)}get color(){return this._color}set color(t){var e;this._color=t.clone();const i=null===(e=this.graphics.layers.default.graphics[0])||void 0===e?void 0:e.graphic;(i instanceof Ct||i instanceof zs)&&(i.color=this._color)}onInitialize(t){}_initialize(t){super._initialize(t);for(const e of this.children)e._initialize(t)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}_prekill(t){super.emit("prekill",new Tt(this)),this.onPreKill(t)}onPreKill(t){}_postkill(t){super.emit("postkill",new Et(this)),this.onPostKill(t)}onPostKill(t){}kill(){this.scene?(this._prekill(this.scene),this.emit("kill",new Pt(this)),super.kill(),this._postkill(this.scene)):this.logger.warn("Cannot kill actor, it was never added to the Scene")}unkill(){this.active=!0}isKilled(){return!this.active}setDrawing(t){t=t.toString(),this.currentDrawing!==this.frames[t]&&(null!=this.frames[t]?(this.frames[t].reset(),this.currentDrawing=this.frames[t]):f.getInstance().error(`the specified drawing key ${t} does not exist`)),this.currentDrawing&&this.currentDrawing instanceof Ie&&this.currentDrawing.tick(0)}addDrawing(){2===arguments.length?(this.frames[arguments[0]]=arguments[1],this.currentDrawing||(this.currentDrawing=arguments[1])):(arguments[0]instanceof Se&&this.addDrawing("default",arguments[0]),arguments[0]instanceof we&&this.addDrawing("default",arguments[0].asSprite()))}get z(){return this.get(Ei).z}getZIndex(){return this.get(Ei).z}set z(t){this.get(Ei).z=t}setZIndex(t){this.get(Ei).z=t}get center(){const t=this.getGlobalPos();return new A(t.x+this.width/2-this.anchor.x*this.width,t.y+this.height/2-this.anchor.y*this.height)}get localCenter(){return new A(this.pos.x+this.width/2-this.anchor.x*this.width,this.pos.y+this.height/2-this.anchor.y*this.height)}get width(){return this.collider.localBounds.width*this.getGlobalScale().x}get height(){return this.collider.localBounds.height*this.getGlobalScale().y}getGlobalRotation(){return this.get(Ei).globalRotation}getGlobalPos(){return this.get(Ei).globalPos}getGlobalScale(){return this.get(Ei).globalScale}contains(t,e,i=!1){const s=P(t,e),r=this.get(Yi);r.update();const n=r.get();if(!n)return!1;const o=n.contains(s);return i?o||this.children.some((i=>i.contains(t,e,!0))):o}within(t,e){const i=this.get(Yi),s=t.get(Yi),r=i.get(),n=s.get();return!(!r||!n)&&r.getClosestLineBetween(n).getLength()<=e}update(t,e){this._initialize(t),this._preupdate(t,e);const i=this.currentDrawing;i&&i instanceof Ie&&i.tick(e,t.stats.currFrame.id);for(const i of this.traits)i.update(this,t,e);this._postupdate(t,e)}onPreUpdate(t,e){}onPostUpdate(t,e){}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Ft(t,e,this)),this.onPostUpdate(t,e)}draw(t,e){var i;if(t.save(),this.currentDrawing){t.translate(-this.width*this.anchor.x,-this.height*this.anchor.y),this._predraw(t,e);const i=this.currentDrawing,s=(this.width-i.width*i.scale.x)*this.anchor.x,r=(this.height-i.height*i.scale.y)*this.anchor.y;this.currentDrawing.draw({ctx:t,x:s,y:r,opacity:this.graphics.opacity})}else if(this._predraw(t,e),this.color&&this.collider){const e=this.get(Yi);e.update(),e&&!e.bounds.hasZeroDimensions()&&(t.globalAlpha=this.graphics.opacity,null===(i=e.get())||void 0===i||i.draw(t,this.color,P(0,0)))}t.restore(),this._postdraw(t,e)}onPreDraw(t,e){}onPostDraw(t,e){}_predraw(t,e){this.emit("predraw",new Dt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new Dt(t,e,this)),this.onPostDraw(t,e)}debugDraw(t){}}Us.defaults={anchor:A.Half},Os([C({message:"Actor.visible will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.visible"})],Us.prototype,"visible",null),Os([C({message:"Actor.opacity will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.opacity"})],Us.prototype,"opacity",null),Os([C({message:"Actor.setDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.show() or Actor.graphics.use()"})],Us.prototype,"setDrawing",null),Os([C({message:"Actor.addDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.add()"})],Us.prototype,"addDrawing",null),Os([C({message:"Actor.getZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Us.prototype,"getZIndex",null),Os([C({message:"Actor.setZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Us.prototype,"setZIndex",null);class Ns extends Us{constructor(t){super({...t}),this.get(Ei).coordPlane=Ti.Screen,this.anchor=P(0,0),this.body.collisionType=vi.PreventCollision,this.collider.useBoxCollider(this.width,this.height,this.anchor)}_initialize(t){this._engine=t,super._initialize(t)}contains(t,e,i=!0){if(i)return super.contains(t,e);const s=this._engine.worldToScreenCoordinates(new A(t,e));return super.contains(s.x,s.y)}}var Hs=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Ws{constructor(t,e,i,s){if(this._logger=f.getInstance(),this.id=0,this._elapsedTime=0,this._totalTimeAlive=0,this._running=!1,this._numberOfTicks=0,this.interval=10,this.repeats=!1,this.maxNumberOfRepeats=-1,this._complete=!1,this.scene=null,"function"!=typeof t){const r=t;t=r.fcn,e=r.interval,i=r.repeats,s=r.numberOfRepeats}if(s&&s>=0&&(this.maxNumberOfRepeats=s,!i))throw new Error("repeats must be set to true if numberOfRepeats is set");this.id=Ws._MAX_ID++,this.interval=e||this.interval,this.repeats=i||this.repeats,this._callbacks=[],t&&this.on(t)}get complete(){return this._complete}on(t){this._callbacks.push(t)}off(t){const e=this._callbacks.indexOf(t);this._callbacks.splice(e,1)}update(t){this._running&&(this._totalTimeAlive+=t,this._elapsedTime+=t,this.maxNumberOfRepeats>-1&&this._numberOfTicks>=this.maxNumberOfRepeats&&(this._complete=!0,this._running=!1,this._elapsedTime=0),!this.complete&&this._elapsedTime>=this.interval&&(this._callbacks.forEach((t=>{t.call(this)})),this._numberOfTicks++,this.repeats||(this._complete=!0,this._running=!1),this._elapsedTime=0))}reset(t,e){if(t&&t>=0&&(this.interval=t),this.maxNumberOfRepeats&&this.maxNumberOfRepeats>=0&&(this.maxNumberOfRepeats=e,!this.repeats))throw new Error("repeats must be set to true if numberOfRepeats is set");this._complete=!1,this._elapsedTime=0,this._numberOfTicks=0}get timesRepeated(){return this._numberOfTicks}getTimeRunning(){return this._totalTimeAlive}get timeToNextAction(){return this.complete?0:this.interval-this._elapsedTime}get timeElapsedTowardNextAction(){return this._elapsedTime}get isRunning(){return this._running}pause(){return this._running=!1,this}unpause(){this._running=!0}resume(){return this._running=!0,this}start(){return this.scene||this._logger.warn("Cannot start a timer not part of a scene, timer wont start until added"),this._running=!0,this.complete&&(this._complete=!1,this._elapsedTime=0,this._numberOfTicks=0),this}stop(){return this._running=!1,this._elapsedTime=0,this._numberOfTicks=0,this}cancel(){this.pause(),this.scene&&this.scene.cancelTimer(this)}}Ws._MAX_ID=0,Hs([C({message:"Will be removed in v0.26.0",alternateMethod:"Use Timer.resume()"})],Ws.prototype,"unpause",null);class Gs extends Ai{constructor(t){super(),this.draw=t,this.type="ex.debuggraphics"}}var Vs,Xs=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class qs extends ns{constructor(t,e,i,s,r,n){if(super(),this._token=0,this._onScreenXStart=0,this._onScreenXEnd=9999,this._onScreenYStart=0,this._onScreenYEnd=9999,this._spriteSheets={},this._legacySpriteMap=new Map,this.logger=f.getInstance(),this.data=[],this._rows=[],this._cols=[],this.visible=!0,this.isOffscreen=!1,this._dirty=!0,t&&"object"==typeof t){const o=t;t=o.x,e=o.y,i=o.cellWidth,s=o.cellHeight,r=o.rows,n=o.cols}this.addComponent(new Ei),this.addComponent(new Ii),this.addComponent(new $i({type:vi.Fixed})),this.addComponent(new os(((t,e)=>this.draw(t,e)))),this.addComponent(new cs({onPostDraw:(t,e)=>this.draw(t,e)})),this.addComponent(new Gs((t=>this.debug(t)))),this.addComponent(new Yi),this._transform=this.get(Ei),this._motion=this.get(Ii),this._collider=this.get(Yi),this._composite=this._collider.useCompositeCollider([]),this.x=t,this.y=e,this.cellWidth=i,this.cellHeight=s,this.rows=r,this.cols=n,this.data=new Array(r*n),this._rows=new Array(r),this._cols=new Array(n);let o=[];for(let a=0;a<n;a++){for(let h=0;h<r;h++){const r=new Zs(a*i+t,h*s+e,i,s,a+h*n);r.map=this,this.data[a+h*n]=r,o.push(r),this._rows[h]||(this._rows[h]=[]),this._rows[h].push(r)}this._cols[a]=o,o=[]}this.get(cs).localBounds=new D({left:0,top:0,right:this.cols*this.cellWidth,bottom:this.rows*this.cellHeight})}flagDirty(){this._dirty=!0}get x(){var t;return null!==(t=this._transform.pos.x)&&void 0!==t?t:0}set x(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.pos)&&(this.get(Ei).pos=P(t,this.y))}get y(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos.y)&&void 0!==e?e:0}set y(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.pos)&&(this._transform.pos=P(this.x,t))}get z(){var t;return null!==(t=this._transform.z)&&void 0!==t?t:0}set z(t){this._transform&&(this._transform.z=t)}get rotation(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.rotation)&&void 0!==e?e:0}set rotation(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.rotation)&&(this._transform.rotation=t)}get scale(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.scale)&&void 0!==e?e:A.One}set scale(t){var e;(null===(e=this._transform)||void 0===e?void 0:e.scale)&&(this._transform.scale=t)}get pos(){return this._transform.pos}set pos(t){this._transform.pos=t}get vel(){return this._motion.vel}set vel(t){this._motion.vel=t}on(t,e){super.on(t,e)}_initialize(t){super._initialize(t)}registerSpriteSheet(t,e){this._spriteSheets[t]=e instanceof Oe?e:Oe.fromLegacySpriteSheet(e)}_updateColliders(){this._composite.clearColliders();const t=[];let e;for(let i=0;i<this.cols;i++){for(let s=0;s<this.rows;s++){0===s&&(e=null);const r=this.data[i+s*this.cols];r.solid?e=e?e.combine(r.bounds):r.bounds:(e&&t.push(e),e=null)}if(e){const i=t[t.length-1];i&&i.top===e.top&&i.bottom===e.bottom?t[t.length-1]=i.combine(e):t.push(e)}}this._composite=this._collider.useCompositeCollider([]);for(const e of t){const t=Zi.Box(e.width,e.height,A.Zero,P(e.left-this.pos.x,e.top-this.pos.y));t.owner=this,this._composite.addCollider(t)}this._collider.update()}getCellByIndex(t){return this.data[t]}getCell(t,e){return t<0||e<0||t>=this.cols||e>=this.rows?null:this.data[t+e*this.cols]}getCellByPoint(t,e){t=Math.floor((t-this.pos.x)/this.cellWidth),e=Math.floor((e-this.pos.y)/this.cellHeight);const i=this.getCell(t,e);return t>=0&&e>=0&&t<this.cols&&e<this.rows&&i?i:null}getRows(){return this._rows}getColumns(){return this._cols}onPreUpdate(t,e){}onPostUpdate(t,e){}update(t,e){this.onPreUpdate(t,e),this.emit("preupdate",new Ft(t,e,this)),this._dirty&&(this._dirty=!1,this._updateColliders()),this._token++;const i=t.getWorldBounds(),s=P(i.left,i.top),r=P(i.right,i.bottom);this._onScreenXStart=Math.max(Math.floor((s.x-this.x)/this.cellWidth)-2,0),this._onScreenYStart=Math.max(Math.floor((s.y-this.y)/this.cellHeight)-2,0),this._onScreenXEnd=Math.max(Math.floor((r.x-this.x)/this.cellWidth)+2,0),this._onScreenYEnd=Math.max(Math.floor((r.y-this.y)/this.cellHeight)+2,0),this._transform.pos=P(this.x,this.y),this.onPostUpdate(t,e),this.emit("postupdate",new Lt(t,e,this))}draw(t,e){this.emit("predraw",new Dt(t,e,this));let i=this._onScreenXStart;const s=Math.min(this._onScreenXEnd,this.cols);let r=this._onScreenYStart;const n=Math.min(this._onScreenYEnd,this.rows);let o,a,h;for(;i<s;i++){for(;r<n;r++)for(o=this.getCell(i,r).graphics,a=0,h=o.length;a<h;a++){const s=o[a];s&&(t instanceof CanvasRenderingContext2D?s instanceof Ae&&(this._legacySpriteMap.has(s)||this._legacySpriteMap.set(s,Ae.toLegacySprite(s)),this._legacySpriteMap.get(s).draw(t,i*this.cellWidth,r*this.cellHeight)):(as(s)&&(null==s||s.tick(e,this._token)),s.draw(t,i*this.cellWidth,r*this.cellHeight)))}r=this._onScreenYStart}this.emit("postdraw",new Bt(t,e,this))}debug(t){const e=this.cellWidth*this.cols,i=this.cellHeight*this.rows,s=A.Zero;for(let i=0;i<this.rows+1;i++){const r=P(0,i*this.cellHeight);t.drawLine(s.add(r),s.add(P(e,r.y)),I.Red,2)}for(let e=0;e<this.cols+1;e++){const r=P(e*this.cellWidth,0);t.drawLine(s.add(r),s.add(P(r.x,i)),I.Red,2)}const r=this._composite.getColliders();for(const e of r){const i=I.Gray;i.a=.5;const s=e.localBounds,r=e.worldPos.sub(this.pos);t.drawRectangle(r,s.width,s.height,i)}}}Xs([C({message:"No longer used, will be removed in v0.26.0"})],qs.prototype,"registerSpriteSheet",null);class js extends(xe(qs)){constructor(t,e,i,s,r,n){super(t,e,i,s,r,n)}}class Ks extends ns{constructor(t,e,i,s,r,n=!1,o=[]){if(super(),this._solid=!1,this.graphics=[],this.data=new Map,t&&"object"==typeof t){const a=t;t=a.x,e=a.y,i=a.width,s=a.height,r=a.index,n=a.solid,o=a.sprites}this.x=t,this.y=e,this.width=i,this.height=s,this.index=r,this.solid=n,this.graphics=o,this._bounds=new D(this.x,this.y,this.x+this.width,this.y+this.height)}get solid(){return this._solid}set solid(t){var e;null===(e=this.map)||void 0===e||e.flagDirty(),this._solid=t}get bounds(){return this._bounds}get center(){return new A(this.x+this.width/2,this.y+this.height/2)}pushSprite(t){this.addGraphic(t)}addGraphic(t){t instanceof Se?this.graphics.push(Ae.fromLegacySprite(t)):this.graphics.push(t)}removeGraphic(t){tt(t,this.graphics)}clearGraphics(){this.graphics.length=0}}Xs([C({message:"Will be removed in v0.26.0",alternateMethod:"addSprite"})],Ks.prototype,"pushSprite",null);class Zs extends(xe(Ks)){constructor(t,e,i,s,r,n,o){super(t,e,i,s,r,n,o)}}class Ys{constructor(t){this.camera=t}lockToActor(t){this.camera.addStrategy(new Qs(t))}lockToActorAxis(t,e){this.camera.addStrategy(new $s(t,e))}elasticToActor(t,e,i){this.camera.addStrategy(new Js(t,e,i))}radiusAroundActor(t,e){this.camera.addStrategy(new tr(t,e))}limitCameraBounds(t){this.camera.addStrategy(new er(t))}}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(Vs||(Vs={}));class Qs{constructor(t){this.target=t,this.action=(t,e,i,s)=>t.center}}class $s{constructor(t,e){this.target=t,this.axis=e,this.action=(t,e,i,s)=>{const r=t.center,n=e.getFocus();return this.axis===Vs.X?new A(r.x,n.y):new A(n.x,r.y)}}}class Js{constructor(t,e,i){this.target=t,this.cameraElasticity=e,this.cameraFriction=i,this.action=(t,e,i,s)=>{const r=t.center;let n=e.getFocus(),o=e.vel.clone();const a=r.sub(n).scale(this.cameraElasticity);o=o.add(a);const h=o.scale(-1).scale(this.cameraFriction);return o=o.add(h),n=n.add(o),n}}}class tr{constructor(t,e){this.target=t,this.radius=e,this.action=(t,e,i,s)=>{const r=t.center,n=e.getFocus(),o=r.sub(n),a=o.size;if(a>=this.radius){const t=a-this.radius;return n.add(o.normalize().scale(t))}return n}}}class er{constructor(t){this.target=t,this.boundSizeChecked=!1,this.action=(t,e,i,s)=>{const r=e.getFocus();this.boundSizeChecked||((t.bottom-t.top<i.drawHeight||t.right-t.left<i.drawWidth)&&f.getInstance().warn("Camera bounds should not be smaller than the engine viewport"),this.boundSizeChecked=!0);let n=r.x,o=r.y;return r.x<t.left+i.halfDrawWidth?n=t.left+i.halfDrawWidth:r.x>t.right-i.halfDrawWidth&&(n=t.right-i.halfDrawWidth),r.y<t.top+i.halfDrawHeight?o=t.top+i.halfDrawHeight:r.y>t.bottom-i.halfDrawHeight&&(o=t.bottom-i.halfDrawHeight),P(n,o)}}}class ir extends hi{constructor(){super(...arguments),this.transform=ct.identity(),this.inverse=ct.identity(),this._cameraStrategies=[],this.strategy=new Ys(this),this._z=1,this.dz=0,this.az=0,this.rotation=0,this.rx=0,this._posChanged=!1,this._pos=gt(A.Zero,(()=>this._posChanged=!0)),this.vel=A.Zero,this.acc=A.Zero,this._cameraMoving=!1,this._currentLerpTime=0,this._lerpDuration=1e3,this._lerpStart=null,this._lerpEnd=null,this._isShaking=!1,this._shakeMagnitudeX=0,this._shakeMagnitudeY=0,this._shakeDuration=0,this._elapsedShakeTime=0,this._xShake=0,this._yShake=0,this._isZooming=!1,this._zoomStart=1,this._zoomEnd=1,this._currentZoomTime=0,this._zoomDuration=0,this._zoomEasing=fs.EaseInOutCubic,this._easing=fs.EaseInOutCubic,this._halfWidth=0,this._halfHeight=0,this._viewport=null,this._isInitialized=!1}get zoom(){return this._z}set zoom(t){this._z=t,this._engine&&(this._halfWidth=this._engine.halfDrawWidth,this._halfHeight=this._engine.halfDrawHeight)}get angularVelocity(){return this.rx}set angularVelocity(t){this.rx=t}get pos(){return this._pos}set pos(t){this._pos=gt(t,(()=>this._posChanged=!0)),this._posChanged=!0}get x(){return this.pos.x}set x(t){this._follow||this._cameraMoving||(this.pos=P(t,this.pos.y))}get y(){return this.pos.y}set y(t){this._follow||this._cameraMoving||(this.pos=P(this.pos.x,t))}get dx(){return this.vel.x}set dx(t){this.vel=P(t,this.vel.y)}get dy(){return this.vel.y}set dy(t){this.vel=P(this.vel.x,t)}get ax(){return this.acc.x}set ax(t){this.acc=P(t,this.acc.y)}get ay(){return this.acc.y}set ay(t){this.acc=P(this.acc.x,t)}getFocus(){return this.pos}move(t,e,i=fs.EaseInOutCubic){if("function"!=typeof i)throw"Please specify an EasingFunction";return this._follow?Promise.reject(t):(this._lerpPromise&&this._lerpResolve&&this._lerpResolve(t),this._lerpPromise=new Promise((t=>{this._lerpResolve=t})),this._lerpStart=this.getFocus().clone(),this._lerpDuration=e,this._lerpEnd=t,this._currentLerpTime=0,this._cameraMoving=!0,this._easing=i,this._lerpPromise)}shake(t,e,i){this._isShaking=!0,this._shakeMagnitudeX=t,this._shakeMagnitudeY=e,this._shakeDuration=i}zoomOverTime(t,e=0,i=fs.EaseInOutCubic){return this._zoomPromise=new Promise((t=>{this._zoomResolve=t})),e?(this._isZooming=!0,this._zoomEasing=i,this._currentZoomTime=0,this._zoomDuration=e,this._zoomStart=this.zoom,this._zoomEnd=t,this._zoomPromise):(this._isZooming=!1,this.zoom=t,Promise.resolve(!0))}get viewport(){return this._viewport?this._viewport:new D(0,0,0,0)}addStrategy(t){this._cameraStrategies.push(t)}removeStrategy(t){tt(t,this._cameraStrategies)}clearAllStrategies(){this._cameraStrategies.length=0}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}onPreUpdate(t,e){}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}onPostUpdate(t,e){}get isInitialized(){return this._isInitialized}_initialize(t){if(!this.isInitialized){this._engine=t,this._screen=t.screen;const e=this._screen.resolution;let i=P(e.width/2,e.height/2);if(!this._engine.loadingComplete){const t=this._screen.peekResolution();t&&(i=P(t.width/2,t.height/2))}this._halfWidth=i.x,this._halfHeight=i.y,this._posChanged||(this.pos=i),this.updateTransform(),this.runStrategies(t,t.clock.elapsed()),this.updateViewport(),this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0}}onInitialize(t){}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}once(t,e){super.once(t,e)}runStrategies(t,e){for(const i of this._cameraStrategies)this.pos=i.action.call(i,i.target,this,t,e)}updateViewport(){this._viewport=new D(this.x-this._halfWidth,this.y-this._halfHeight,this.x+this._halfWidth,this.y+this._halfHeight)}update(t,e){if(this._initialize(t),this._preupdate(t,e),this.pos=this.pos.add(this.vel.scale(e/1e3)),this.zoom+=this.dz*e/1e3,this.vel=this.vel.add(this.acc.scale(e/1e3)),this.dz+=this.az*e/1e3,this.rotation+=this.angularVelocity*e/1e3,this._isZooming)if(this._currentZoomTime<this._zoomDuration){const t=(0,this._zoomEasing)(this._currentZoomTime,this._zoomStart,this._zoomEnd,this._zoomDuration);this.zoom=t,this._currentZoomTime+=e}else this._isZooming=!1,this.zoom=this._zoomEnd,this._currentZoomTime=0,this._zoomResolve(!0);if(this._cameraMoving)if(this._currentLerpTime<this._lerpDuration){const t=fs.CreateVectorEasingFunction(this._easing)(this._currentLerpTime,this._lerpStart,this._lerpEnd,this._lerpDuration);this.pos=t,this._currentLerpTime+=e}else{this.pos=this._lerpEnd;const t=this._lerpEnd.clone();this._lerpStart=null,this._lerpEnd=null,this._currentLerpTime=0,this._cameraMoving=!1,this._lerpResolve(t)}this._isDoneShaking()?(this._isShaking=!1,this._elapsedShakeTime=0,this._shakeMagnitudeX=0,this._shakeMagnitudeY=0,this._shakeDuration=0,this._xShake=0,this._yShake=0):(this._elapsedShakeTime+=e,this._xShake=1+(Math.random()*this._shakeMagnitudeX|0),this._yShake=1+(Math.random()*this._shakeMagnitudeY|0)),this.updateTransform(),this.runStrategies(t,e),this.updateViewport(),this._postupdate(t,e)}draw(t){if(t instanceof CanvasRenderingContext2D){const e=this.getFocus(),i=this._screen.resolution.width/this.zoom,s=this._screen.resolution.height/this.zoom,r=P(-e.x+i/2+this._xShake,-e.y+s/2+this._yShake);t.scale(this.zoom,this.zoom),t.translate(r.x,r.y)}else t.multiply(this.transform)}updateTransform(){const t=this._screen.resolution.width/this.zoom,e=this._screen.resolution.height/this.zoom,i=P(-this.x+t/2+this._xShake,-this.y+e/2+this._yShake);this.transform.reset(),this.transform.scale(this.zoom,this.zoom),this.transform.translate(i.x,i.y),this.transform.getAffineInverse(this.inverse)}debugDraw(t){}_isDoneShaking(){return!this._isShaking||this._elapsedShakeTime>=this._shakeDuration}}function sr(t){return t instanceof Ns}const rr={pos:A.Zero,width:10,height:10,visible:!1,action:()=>{},filter:()=>!0,repeat:-1};class nr extends Us{constructor(t){super({x:t.pos.x,y:t.pos.y,width:t.width,height:t.height}),this.action=()=>{},this.filter=()=>!0,this.repeat=-1,t={...rr,...t},this.filter=t.filter||this.filter,this.repeat=t.repeat||this.repeat,this.action=t.action||this.action,t.target&&(this.target=t.target),this.graphics.visible=t.visible,this.body.collisionType=vi.Passive,this.eventDispatcher=new he,this.events.on("collisionstart",(t=>{this.filter(t.other)&&(this.emit("enter",new oe(this,t.other)),this._dispatchAction(),0===this.repeat&&this.kill())})),this.events.on("collisionend",(t=>{this.filter(t.other)&&this.emit("exit",new ae(this,t.other))}))}set target(t){this._target=t,this.filter=e=>e===t}get target(){return this._target}_initialize(t){super._initialize(t)}_dispatchAction(){0!==this.repeat&&(this.action.call(this),this.repeat--)}debugDraw(t){super.debugDraw(t),t.save(),t.translate(this.pos.x,this.pos.y);const e=this.collider.bounds,i=this.getGlobalPos();e.left=e.left-i.x,e.right=e.right-i.x,e.top=e.top-i.y,e.bottom=e.bottom-i.y,t.fillStyle=I.Violet.toString(),t.strokeStyle=I.Violet.toString(),t.fillText("Trigger",10,10),e.debugDraw(t),t.restore()}}var or;!function(t){t.Update="update",t.Draw="draw"}(or||(or={}));class ar{constructor(){this.priority=0}notify(t){}}class hr{constructor(t){this.data=t,this.type="Entity Added"}}function lr(t){return!!t&&"Entity Added"===t.type}class cr{constructor(t){this.data=t,this.type="Entity Removed"}}function dr(t){return!!t&&"Entity Removed"===t.type}class ur{constructor(t){this._world=t,this.entities=[],this._entityIndex={},this._entitiesToRemove=[]}updateEntities(t,e){for(const i of this.entities)i.update(t.engine,e),i.active||this.removeEntity(i)}findEntitiesForRemoval(){for(const t of this.entities)t.active||this.removeEntity(t)}notify(t){is(t)&&this._world.queryManager.addEntity(t.data.entity),rs(t)&&this._world.queryManager.removeComponent(t.data.entity,t.data.component)}addEntity(t){t.active=!0,t&&!this._entityIndex[t.id]&&(this._entityIndex[t.id]=t,this.entities.push(t),this._world.queryManager.addEntity(t),t.componentAdded$.register(this),t.componentRemoved$.register(this),t.children.forEach((t=>this.addEntity(t))),t.childrenAdded$.register({notify:t=>{this.addEntity(t)}}),t.childrenRemoved$.register({notify:t=>{this.removeEntity(t,!1)}}))}removeEntity(t,e=!0){var i;let s=0;s=t instanceof ns?t.id:t;const r=this._entityIndex[s];r&&r.active&&r.kill(),r&&e?this._entitiesToRemove.push(r):(delete this._entityIndex[s],r&&(tt(r,this.entities),this._world.queryManager.removeEntity(r),r.componentAdded$.unregister(this),r.componentRemoved$.unregister(this),r.children.forEach((t=>this.removeEntity(t,e))),r.childrenAdded$.clear(),r.childrenRemoved$.clear(),(null===(i=this._world.context)||void 0===i?void 0:i.engine)&&this._world.context.engine.stats.currFrame.actors.killed++))}processEntityRemovals(){for(const t of this._entitiesToRemove)t.active||this.removeEntity(t,!1)}processComponentRemovals(){for(const t of this.entities)t.processComponentRemoval()}getById(t){return this._entityIndex[t]}getByName(t){return this.entities.filter((e=>e.name===t))}clear(){for(const t of this.entities)this.removeEntity(t)}}const pr=t=>[...t].sort(((t,e)=>t.localeCompare(e))).join("+");class gr extends Di{constructor(t){super(),this._entities=[],t[0]instanceof Function?this.types=t.map((t=>(new t).type)):this.types=t}get key(){return this._key?this._key:this._key=pr(this.types)}getEntities(t){return t&&this._entities.sort(t),this._entities}addEntity(t){!et(this._entities,t)&&this.matches(t)&&(this._entities.push(t),this.notifyAll(new hr(t)))}removeEntity(t){tt(t,this._entities)&&this.notifyAll(new cr(t))}clear(){this._entities.length=0;for(const t of this.observers)this.unregister(t)}matches(t){let e=[];e=t instanceof ns?t.types:t;let i=!0;for(const t of this.types)if(i=i&&e.indexOf(t)>-1,!i)return!1;return i}contain(t){return this.types.indexOf(t)>-1}}class _r{constructor(t){this._world=t,this._queries={}}_addQuery(t){this._queries[pr(t.types)]=t;for(const e of this._world.entityManager.entities)t.addEntity(e)}maybeRemoveQuery(t){0===t.observers.length&&(t.clear(),delete this._queries[pr(t.types)])}addEntity(t){for(const e in this._queries)this._queries[e]&&this._queries[e].addEntity(t)}removeComponent(t,e){for(const i in this._queries)this._queries[i].contain(e.type)&&this._queries[i].removeEntity(t)}removeEntity(t){for(const e in this._queries)this._queries[e].removeEntity(t)}createQuery(t){const e=this.getQuery(t);if(e)return e;const i=new gr(t);return this._addQuery(i),i}getQuery(t){const e=pr(t);return this._queries[e]?this._queries[e]:null}}class fr{constructor(t){this._world=t,this.systems=[],this.initialized=!1}get(t){return this.systems.find((e=>e instanceof t))}addSystem(t){if(!t.types||0===t.types.length)throw new Error("Attempted to add a System without any types");const e=this._world.queryManager.createQuery(t.types);this.systems.push(t),this.systems.sort(((t,e)=>t.priority-e.priority)),e.register(t),this.initialized&&t.initialize&&t.initialize(this._world.context)}removeSystem(t){tt(t,this.systems);const e=this._world.queryManager.getQuery(t.types);e&&(e.unregister(t),this._world.queryManager.maybeRemoveQuery(e))}initialize(){if(!this.initialized){this.initialized=!0;for(const t of this.systems)t.initialize&&t.initialize(this._world.context)}}updateSystems(t,e,i){const s=this.systems.filter((e=>e.systemType===t));for(const t of s)t.preupdate&&t.preupdate(e,i);for(const t of s){const s=this._world.queryManager.getQuery(t.types).getEntities(t.sort);if(e instanceof Nr)for(const t of s)t._initialize(null==e?void 0:e.engine);t.update(s,i)}for(const t of s)t.postupdate&&t.postupdate(e,i)}clear(){for(const t of this.systems)this.removeSystem(t)}}class mr{constructor(t){this.context=t,this.queryManager=new _r(this),this.entityManager=new ur(this),this.systemManager=new fr(this)}update(t,e){t===or.Update&&this.entityManager.updateEntities(this.context,e),this.systemManager.updateSystems(t,this.context,e),this.entityManager.findEntitiesForRemoval(),this.entityManager.processComponentRemovals(),this.entityManager.processEntityRemovals()}add(t){t instanceof ns&&this.entityManager.addEntity(t),t instanceof ar&&this.systemManager.addSystem(t)}remove(t,e=!0){t instanceof ns&&this.entityManager.removeEntity(t,e),t instanceof ar&&this.systemManager.removeSystem(t)}clearEntities(){this.entityManager.clear()}clearSystems(){this.systemManager.clear()}}class vr{static integrate(t,e,i,s){const r=s/1e3;e.vel.addEqual(i.scale(r)),t.pos.addEqual(e.vel.scale(r)).addEqual(i.scale(.5*r*r)),e.angularVelocity+=e.torque*(1/e.inertia)*r,t.rotation+=e.angularVelocity*r,t.scale.addEqual(e.scaleFactor.scale(r))}}class yr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.motion"],this.systemType=or.Update,this.priority=-1}update(t,e){let i,s;for(const r of t){i=r.get(Ei),s=r.get(Ii);const t=r.get($i);if(null==t?void 0:t.sleeping)continue;const n=s.acc.clone();(null==t?void 0:t.collisionType)===vi.Active&&(null==t?void 0:t.useGravity)&&n.addEqual(Ci.gravity),null==t||t.captureOldTransform(),vr.integrate(i,s,n,e)}}debugDraw(t){}}class wr{solve(t){return this.preSolve(t),t=t.filter((t=>!t.isCanceled())),this.solveVelocity(t),this.solvePosition(t),this.postSolve(t),t}}class xr extends wr{preSolve(t){for(const e of t){const t=T.fromDirection(e.mtv),i=e.mtv.negate();e.colliderA.events.emit("precollision",new jt(e.colliderA,e.colliderB,t,i)),e.colliderB.events.emit("precollision",new jt(e.colliderB,e.colliderA,T.getOpposite(t),i.negate()))}}postSolve(t){var e,i;for(const s of t){const t=s.colliderA,r=s.colliderB,n=null===(e=t.owner)||void 0===e?void 0:e.get($i),o=null===(i=r.owner)||void 0===i?void 0:i.get($i);if(n&&o&&(n.collisionType===vi.Passive||o.collisionType===vi.Passive))continue;const a=T.fromDirection(s.mtv),h=s.mtv.negate();s.colliderA.events.emit("postcollision",new Kt(s.colliderA,s.colliderB,a,h)),s.colliderB.events.emit("postcollision",new Kt(s.colliderB,s.colliderA,T.getOpposite(a),h.negate()))}}solvePosition(t){var e,i;for(const s of t){if(!s.colliderA.bounds.intersect(s.colliderB.bounds))continue;let t=s.mtv;const r=s.colliderA,n=s.colliderB,o=null===(e=r.owner)||void 0===e?void 0:e.get($i),a=null===(i=n.owner)||void 0===i?void 0:i.get($i);if(o&&a){if(o.collisionType===vi.Passive||a.collisionType===vi.Passive)continue;o.collisionType===vi.Active&&a.collisionType===vi.Active&&(t=t.scale(.5)),o.collisionType===vi.Active&&(o.pos.x-=t.x,o.pos.y-=t.y),a.collisionType===vi.Active&&(a.pos.x+=t.x,a.pos.y+=t.y)}}}solveVelocity(t){var e,i;for(const s of t){const t=s.colliderA,r=s.colliderB,n=null===(e=t.owner)||void 0===e?void 0:e.get($i),o=null===(i=r.owner)||void 0===i?void 0:i.get($i);if(n&&o){if(n.collisionType===vi.Passive||o.collisionType===vi.Passive)continue;const t=s.normal,e=t.negate();if(n.collisionType===vi.Active){const e=t.scale(t.dot(n.vel.negate()));n.vel=n.vel.add(e)}if(o.collisionType===vi.Active){const t=e.scale(e.dot(o.vel.negate()));o.vel=o.vel.add(t)}}}}}class br{constructor(t,e,i){this.point=t,this.local=e,this.contact=i,this.normalImpulse=0,this.tangentImpulse=0,this.normalMass=0,this.tangentMass=0,this.aToContact=new A(0,0),this.bToContact=new A(0,0),this.update()}update(){var t,e;const i=null===(t=this.contact.colliderA.owner)||void 0===t?void 0:t.get($i),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get($i);if(i&&s){const t=this.contact.normal,e=this.contact.tangent;this.aToContact=this.point.sub(i.pos),this.bToContact=this.point.sub(s.pos);const r=this.aToContact.cross(t),n=this.bToContact.cross(t);this.normalMass=i.inverseMass+s.inverseMass+i.inverseInertia*r*r+s.inverseInertia*n*n;const o=this.aToContact.cross(e),a=this.bToContact.cross(e);this.tangentMass=i.inverseMass+s.inverseMass+i.inverseInertia*o*o+s.inverseInertia*a*a}return this}getRelativeVelocity(){var t,e;const i=null===(t=this.contact.colliderA.owner)||void 0===t?void 0:t.get($i),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get($i);if(i&&s){const t=i.vel.add(A.cross(i.angularVelocity,this.aToContact));return s.vel.add(A.cross(s.angularVelocity,this.bToContact)).sub(t)}return A.Zero}}class Cr extends wr{constructor(){super(...arguments),this.lastFrameContacts=new Map,this.idToContactConstraint=new Map}getContactConstraints(t){var e;return null!==(e=this.idToContactConstraint.get(t))&&void 0!==e?e:[]}preSolve(t){var e,i,s;for(const e of t){const t=T.fromDirection(e.mtv);e.colliderA.events.emit("precollision",new jt(e.colliderA,e.colliderB,t,e.mtv)),e.colliderA.events.emit("beforecollisionresolve",new Qt(e.colliderA,e.colliderB,t,e.mtv,e)),e.colliderB.events.emit("precollision",new jt(e.colliderB,e.colliderA,T.getOpposite(t),e.mtv.negate())),e.colliderB.events.emit("beforecollisionresolve",new Qt(e.colliderB,e.colliderA,T.getOpposite(t),e.mtv.negate(),e)),e.matchAwake()}const r=Array.from(this.idToContactConstraint.keys());for(const n of t){const t=r.indexOf(n.id);t>-1&&r.splice(t,1);const o=null!==(e=this.idToContactConstraint.get(n.id))&&void 0!==e?e:[];let a=0;const h=n.colliderA.owner.get($i),l=n.colliderB.owner.get($i);if(h&&l)for(const t of n.points){const e=n.normal,r=n.tangent,c=t.sub(h.pos),d=t.sub(l.pos),u=c.cross(e),p=d.cross(e),g=h.inverseMass+l.inverseMass+h.inverseInertia*u*u+l.inverseInertia*p*p,_=c.cross(r),f=d.cross(r),m=h.inverseMass+l.inverseMass+h.inverseInertia*_*_+l.inverseInertia*f*f;o[a]&&(null===(s=null===(i=o[a])||void 0===i?void 0:i.point)||void 0===s?void 0:s.squareDistance(t))<4?(o[a].point=t,o[a].local=n.localPoints[a]):o[a]=new br(t,n.localPoints[a],n),o[a].aToContact=c,o[a].bToContact=d,o[a].normalMass=g,o[a].tangentMass=m,a++}this.idToContactConstraint.set(n.id,o)}for(const t of r)this.idToContactConstraint.delete(t);if(Ci.warmStart)this.warmStart(t);else for(const e of t){const t=this.getContactConstraints(e.id);for(const e of t)e.normalImpulse=0,e.tangentImpulse=0}}postSolve(t){for(const e of t){const t=e.colliderA.owner.get($i),i=e.colliderB.owner.get($i);if(t&&i){if(t.collisionType===vi.Passive||i.collisionType===vi.Passive)continue;t.updateMotion(),i.updateMotion()}const s=T.fromDirection(e.mtv);e.colliderA.events.emit("postcollision",new Kt(e.colliderA,e.colliderB,s,e.mtv)),e.colliderA.events.emit("aftercollisionresolve",new $t(e.colliderA,e.colliderB,s,e.mtv,e)),e.colliderB.events.emit("postcollision",new Kt(e.colliderB,e.colliderA,T.getOpposite(s),e.mtv.negate())),e.colliderB.events.emit("aftercollisionresolve",new $t(e.colliderB,e.colliderA,T.getOpposite(s),e.mtv.negate(),e))}this.lastFrameContacts.clear();for(const e of t)this.lastFrameContacts.set(e.id,e)}warmStart(t){var e,i,s;for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){const e=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const i of e)if(Ci.warmStart){const e=r.normal.scale(i.normalImpulse),s=r.tangent.scale(i.tangentImpulse),o=e.add(s);t.applyImpulse(i.point,o.negate()),n.applyImpulse(i.point,o)}else i.normalImpulse=0,i.tangentImpulse=0}}}solvePosition(t){var e,i,s;for(let r=0;r<Ci.positionIterations;r++)for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){if(t.collisionType===vi.Passive||n.collisionType===vi.Passive)continue;const e=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const i of e){const e=r.normal,s=qi.FindContactSeparation(r,i.local),o=-5,a=z(Ci.steeringFactor*(s+Ci.slop),o,0),h=e.scale(-a/i.normalMass);t.collisionType===vi.Active&&(t.pos=t.pos.add(h.negate().scale(t.inverseMass)),t.rotation-=i.aToContact.cross(h)*t.inverseInertia),n.collisionType===vi.Active&&(n.pos=n.pos.add(h.scale(n.inverseMass)),n.rotation+=i.bToContact.cross(h)*n.inverseInertia)}}}}solveVelocity(t){var e,i,s;for(let r=0;r<Ci.velocityIterations;r++)for(const r of t){const t=null===(e=r.colliderA.owner)||void 0===e?void 0:e.get($i),n=null===(i=r.colliderB.owner)||void 0===i?void 0:i.get($i);if(t&&n){if(t.collisionType===vi.Passive||n.collisionType===vi.Passive)continue;const e=t.bounciness*n.bounciness,i=Math.min(t.friction,n.friction),o=null!==(s=this.idToContactConstraint.get(r.id))&&void 0!==s?s:[];for(const e of o){let s=-e.getRelativeVelocity().dot(r.tangent)/e.tangentMass;const o=i*e.normalImpulse,a=z(e.tangentImpulse+s,-o,o);s=a-e.tangentImpulse,e.tangentImpulse=a;const h=r.tangent.scale(s);t.applyImpulse(e.point,h.negate()),n.applyImpulse(e.point,h)}for(const i of o){let s=-(1+e)*i.getRelativeVelocity().dot(r.normal)/i.normalMass;const o=Math.max(i.normalImpulse+s,0);s=o-i.normalImpulse,i.normalImpulse=o;const a=r.normal.scale(s);t.applyImpulse(i.point,a.negate()),n.applyImpulse(i.point,a)}}}}}class Sr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.motion","ex.collider"],this.systemType=or.Update,this.priority=-1,this._realisticSolver=new Cr,this._arcadeSolver=new xr,this._processor=new zi,this._lastFrameContacts=new Map,this._currentFrameContacts=new Map,this._trackCollider=t=>this._processor.track(t),this._untrackCollider=t=>this._processor.untrack(t)}notify(t){if(lr(t)){const e=t.data.get(Yi);e.$colliderAdded.subscribe(this._trackCollider),e.$colliderRemoved.subscribe(this._untrackCollider);const i=e.get();i&&this._processor.track(i)}else{const e=t.data.get(Yi),i=e.get();e&&i&&this._processor.untrack(i)}}initialize(t){this._engine=t.engine}update(t,e){var i;if(!Ci.enabled)return;let s=[];for(const e of t){const t=e.get(Yi),r=null==t?void 0:t.get();t&&(null===(i=t.owner)||void 0===i?void 0:i.active)&&r&&(t.update(),r instanceof Ui?s=s.concat(r.getColliders()):s.push(r))}this._processor.update(s);const r=this._processor.broadphase(s,e);this._currentFrameContacts.clear();let n=this._processor.narrowphase(r,this._engine.debug.stats.currFrame);n=this.getSolver().solve(n),n.forEach((t=>this._currentFrameContacts.set(t.id,t))),this.runContactStartEnd(),this._lastFrameContacts.clear(),this._lastFrameContacts=new Map(this._currentFrameContacts)}getSolver(){return Ci.collisionResolutionStrategy===yi.Realistic?this._realisticSolver:this._arcadeSolver}debug(t){this._processor.debug(t)}runContactStartEnd(){for(const[t,e]of this._currentFrameContacts)if(!this._lastFrameContacts.has(t)){const t=e.colliderA,i=e.colliderB;t.events.emit("collisionstart",new Jt(t,i,e)),t.events.emit("contactstart",new Zt(t,i,e)),i.events.emit("collisionstart",new Jt(i,t,e)),i.events.emit("contactstart",new Zt(i,t,e))}for(const[t,e]of this._lastFrameContacts)if(!this._currentFrameContacts.has(t)){const t=e.colliderA,i=e.colliderB;t.events.emit("collisionend",new te(t,i)),t.events.emit("contactend",new Yt(t,i)),i.events.emit("collisionend",new te(i,t)),i.events.emit("contactend",new Yt(i,t))}}}var Ar,Pr,Tr;!function(t){t.Forward="forward",t.Backward="backward"}(Ar||(Ar={})),function(t){t.End="end",t.Loop="loop",t.PingPong="pingpong",t.Freeze="freeze"}(Pr||(Pr={}));class Er extends _t{constructor(t){var e,i;super(t),this.events=new he,this.frames=[],this.strategy=Pr.Loop,this.frameDuration=100,this.timeScale=1,this._idempotencyToken=-1,this._firstTick=!0,this._currentFrame=0,this._timeLeftInFrame=0,this._direction=1,this._done=!1,this._playing=!0,this._reversed=!1,this.frames=t.frames,this.strategy=null!==(e=t.strategy)&&void 0!==e?e:this.strategy,this.frameDuration=t.totalDuration?t.totalDuration/this.frames.length:null!==(i=t.frameDuration)&&void 0!==i?i:this.frameDuration,t.reverse&&this.reverse(),this.goToFrame(0)}clone(){return new Er({frames:this.frames.map((t=>({...t}))),frameDuration:this.frameDuration,reverse:this._reversed,strategy:this.strategy,...this.cloneGraphicOptions()})}get width(){const t=this.currentFrame;return t?Math.abs(t.graphic.width*this.scale.x):0}get height(){const t=this.currentFrame;return t?Math.abs(t.graphic.height*this.scale.y):0}static fromSpriteSheet(t,e,i,s=Pr.Loop){const r=t.sprites.length-1,n=e.filter((t=>t<0||t>r));return n.length&&Er._LOGGER.warn(`Indices into SpriteSheet were provided that don't exist: ${n.join(",")} no frame will be shown`),new Er({frames:t.sprites.filter(((t,i)=>e.indexOf(i)>-1)).map((t=>({graphic:t,duration:i}))),strategy:s})}static toLegacyAnimation(t,e){const i=e.frames.map((t=>Ae.toLegacySprite(t.graphic)));return new Ie({sprites:i,loop:e.strategy===Pr.Loop,freezeFrame:e.strategy===Pr.Freeze?i.length-1:void 0,speed:e.frameDuration,engine:t})}get currentFrame(){return this._currentFrame>=0&&this._currentFrame<this.frames.length?this.frames[this._currentFrame]:null}get currentFrameIndex(){return this._currentFrame}get isPlaying(){return this._playing}reverse(){this.frames=this.frames.slice().reverse(),this._reversed=!this._reversed}get direction(){return!(!this._reversed||1!==this._direction)?Ar.Backward:Ar.Forward}play(){this._playing=!0}pause(){this._playing=!1,this._firstTick=!0}reset(){this._done=!1,this._firstTick=!0,this._currentFrame=0}get canFinish(){switch(this.strategy){case Pr.End:case Pr.Freeze:return!0;default:return!1}}get done(){return this._done}goToFrame(t){this._currentFrame=t,this._timeLeftInFrame=this.frameDuration;const e=this.frames[this._currentFrame];e&&!this._done&&(this._timeLeftInFrame=(null==e?void 0:e.duration)||this.frameDuration,this.events.emit("frame",e))}_nextFrame(){const t=this._currentFrame;if(this._done)return t;let e=-1;switch(this.strategy){case Pr.Loop:e=(t+1)%this.frames.length,0===e&&this.events.emit("loop",this);break;case Pr.End:e=t+1,e>=this.frames.length&&(this._done=!0,this._currentFrame=this.frames.length,this.events.emit("end",this));break;case Pr.Freeze:e=z(t+1,0,this.frames.length-1),e>=this.frames.length-1&&(this._done=!0,this.events.emit("end",this));break;case Pr.PingPong:t+this._direction>=this.frames.length&&(this._direction=-1,this.events.emit("loop",this)),t+this._direction<0&&(this._direction=1,this.events.emit("loop",this)),e=t+this._direction%this.frames.length}return e}tick(t,e=0){this._idempotencyToken!==e&&(this._idempotencyToken=e,this._playing&&(this._firstTick&&(this._firstTick=!1,this.events.emit("frame",this.currentFrame)),this._timeLeftInFrame-=t*this.timeScale,this._timeLeftInFrame<=0&&this.goToFrame(this._nextFrame())))}_drawImage(t,e,i){this.currentFrame&&this.currentFrame.graphic.draw(t,e,i)}}Er._LOGGER=f.getInstance();class Ir extends _t{constructor(t){super(t),this.members=[],this.members=t.members,this._updateDimensions()}clone(){return new Ir({members:[...this.members],...this.cloneGraphicOptions()})}_updateDimensions(){let t=new D;for(const{graphic:e,pos:i}of this.members)t=e.localBounds.translate(i).combine(t);return this.width=t.width,this.height=t.height,t}get localBounds(){let t=new D;for(const{graphic:e,pos:i}of this.members)t=e.localBounds.translate(i).combine(t);return t}_isAnimationOrGroup(t){return t instanceof Er||t instanceof Ir}tick(t,e){for(const i of this.members){const s=i.graphic;this._isAnimationOrGroup(s)&&s.tick(t,e)}}reset(){for(const t of this.members){const e=t.graphic;this._isAnimationOrGroup(e)&&e.reset()}}_preDraw(t,e,i){this._updateDimensions(),super._preDraw(t,e,i)}_drawImage(t,e,i){for(const s of this.members)t.save(),t.translate(e,i),s.graphic.draw(t,s.pos.x,s.pos.y),this.showDebug&&t.debug.drawRect(0,0,this.width,this.height),t.restore()}}!function(t){t[t.Circle=0]="Circle",t[t.Rectangle=1]="Rectangle"}(Tr||(Tr={}));class Rr extends ns{constructor(t,e,i,s,r,n,o,a,h,l){super(),this.position=new A(0,0),this.velocity=new A(0,0),this.acceleration=new A(0,0),this.particleRotationalVelocity=0,this.currentRotation=0,this.focus=null,this.focusAccel=0,this.opacity=1,this.beginColor=I.White,this.endColor=I.White,this.life=300,this.fadeFlag=!1,this._rRate=1,this._gRate=1,this._bRate=1,this._aRate=0,this._currentColor=I.White,this.emitter=null,this.particleSize=5,this.particleSprite=null,this.sizeRate=0,this.elapsedMultiplier=0,this.visible=!0,this.isOffscreen=!1;let c=t;if(c&&!(t instanceof Br)){const d=t;c=d.emitter,e=d.life,i=d.opacity,r=d.endColor,s=d.beginColor,n=d.position,o=d.velocity,a=d.acceleration,h=d.startSize,l=d.endSize}this.emitter=c,this.life=e||this.life,this.opacity=i||this.opacity,this.endColor=r||this.endColor.clone(),this.beginColor=s||this.beginColor.clone(),this._currentColor=this.beginColor.clone(),this.position=(n||this.position).add(this.emitter.pos),this.velocity=o||this.velocity,this.acceleration=a||this.acceleration,this._rRate=(this.endColor.r-this.beginColor.r)/this.life,this._gRate=(this.endColor.g-this.beginColor.g)/this.life,this._bRate=(this.endColor.b-this.beginColor.b)/this.life,this._aRate=this.opacity/this.life,this.startSize=h||0,this.endSize=l||0,this.endSize>0&&this.startSize>0&&(this.sizeRate=(this.endSize-this.startSize)/this.life,this.particleSize=this.startSize),this.addComponent(this.transform=new Ei),this.addComponent(new os((t=>this.draw(t)))),this.addComponent(this.graphics=new cs),this.transform.pos=this.position,this.transform.rotation=this.currentRotation,this.transform.scale=P(1,1),this.particleSprite?(this.graphics.opacity=this.opacity,this.graphics.use(Ae.fromLegacySprite(this.particleSprite))):this.graphics.onPostDraw=t=>{t.save(),this.graphics.opacity=this.opacity;const e=this._currentColor.clone();e.a=1,t.debug.drawPoint(P(0,0),{color:e,size:this.particleSize}),t.restore()}}kill(){this.emitter.removeParticle(this)}update(t,e){if(this.life=this.life-e,this.elapsedMultiplier=this.elapsedMultiplier+e,this.life<0&&this.kill(),this.fadeFlag&&(this.opacity=z(this._aRate*this.life,1e-4,1)),this.startSize>0&&this.endSize>0&&(this.particleSize=z(this.sizeRate*e+this.particleSize,Math.min(this.startSize,this.endSize),Math.max(this.startSize,this.endSize))),this._currentColor.r=z(this._currentColor.r+this._rRate*e,0,255),this._currentColor.g=z(this._currentColor.g+this._gRate*e,0,255),this._currentColor.b=z(this._currentColor.b+this._bRate*e,0,255),this._currentColor.a=z(this.opacity,1e-4,1),this.focus){const t=this.focus.sub(this.position).normalize().scale(this.focusAccel).scale(e/1e3);this.velocity=this.velocity.add(t)}else this.velocity=this.velocity.add(this.acceleration.scale(e/1e3));this.position=this.position.add(this.velocity.scale(e/1e3)),this.particleRotationalVelocity&&(this.currentRotation=(this.currentRotation+this.particleRotationalVelocity*e/1e3)%(2*Math.PI)),this.transform.pos=this.position,this.transform.rotation=this.currentRotation,this.transform.scale=P(1,1),this.graphics.opacity=this.opacity}draw(t){if(this.particleSprite)return this.particleSprite.opacity(this.opacity),void this.particleSprite.draw(t,0,0);t.save(),this._currentColor.a=z(this.opacity,1e-4,1),t.fillStyle=this._currentColor.toString(),t.beginPath(),t.arc(0,0,this.particleSize,0,2*Math.PI),t.fill(),t.closePath(),t.restore()}}class Dr extends(xe(Rr)){constructor(t,e,i,s,r,n,o,a,h,l){super(t,e,i,s,r,n,o,a,h,l)}}class Br extends Us{constructor(t){var e,i;super({width:null!==(e=t.width)&&void 0!==e?e:0,height:null!==(i=t.height)&&void 0!==i?i:0}),this._particlesToEmit=0,this.numParticles=0,this.isEmitting=!0,this.particles=[],this.deadParticles=[],this.minVel=0,this.maxVel=0,this.acceleration=new A(0,0),this.minAngle=0,this.maxAngle=0,this.emitRate=1,this.particleLife=2e3,this.fadeFlag=!1,this.focus=null,this.focusAccel=null,this.startSize=null,this.endSize=null,this.minSize=5,this.maxSize=5,this.beginColor=I.White,this.endColor=I.White,this._og=null,this._sprite=null,this.emitterType=Tr.Rectangle,this.radius=0,this.particleRotationalVelocity=0,this.randomRotation=!1;const{x:s,y:r,pos:n,isEmitting:o,minVel:a,maxVel:h,acceleration:l,minAngle:c,maxAngle:d,emitRate:u,particleLife:p,opacity:g,fadeFlag:_,focus:f,focusAccel:m,startSize:v,endSize:y,minSize:w,maxSize:x,beginColor:b,endColor:C,particleSprite:S,emitterType:T,radius:E,particleRotationalVelocity:R,randomRotation:D,random:B}={...t};this.pos=null!=n?n:P(null!=s?s:0,null!=r?r:0),this.isEmitting=null!=o?o:this.isEmitting,this.minVel=null!=a?a:this.minVel,this.maxVel=null!=h?h:this.maxVel,this.acceleration=null!=l?l:this.acceleration,this.minAngle=null!=c?c:this.minAngle,this.maxAngle=null!=d?d:this.maxAngle,this.emitRate=null!=u?u:this.emitRate,this.particleLife=null!=p?p:this.particleLife,this.opacity=null!=g?g:this.opacity,this.fadeFlag=null!=_?_:this.fadeFlag,this.focus=null!=f?f:this.focus,this.focusAccel=null!=m?m:this.focusAccel,this.startSize=null!=v?v:this.startSize,this.endSize=null!=y?y:this.endSize,this.minSize=null!=w?w:this.minSize,this.maxSize=null!=x?x:this.maxSize,this.beginColor=null!=b?b:this.beginColor,this.endColor=null!=C?C:this.endColor,this.particleSprite=null!=S?S:this.particleSprite,this.emitterType=null!=T?T:this.emitterType,this.radius=null!=E?E:this.radius,this.particleRotationalVelocity=null!=R?R:this.particleRotationalVelocity,this.randomRotation=null!=D?D:this.randomRotation,this.body.collisionType=vi.PreventCollision,this.random=null!=B?B:new M;for(let t=0;t<this.traits.length;t++)this.traits[t]instanceof ts&&this.traits.splice(t,1)}get opacity(){return super.graphics.opacity}set opacity(t){super.graphics.opacity=t}get particleSprite(){return this._og}set particleSprite(t){this._og=t,t&&(this._sprite=Ae.fromLegacySprite(t))}removeParticle(t){this.deadParticles.push(t)}emitParticles(t){var e;for(let i=0;i<t;i++){const t=this._createParticle();this.particles.push(t),(null===(e=null==this?void 0:this.scene)||void 0===e?void 0:e.world)&&this.scene.world.add(t)}}clearParticles(){this.particles.length=0}_createParticle(){let t=0,e=0;const i=W(this.minAngle,this.maxAngle,this.random),s=W(this.minVel,this.maxVel,this.random),r=this.startSize||W(this.minSize,this.maxSize,this.random),n=s*Math.cos(i),o=s*Math.sin(i);if(this.emitterType===Tr.Rectangle)t=W(0,this.width,this.random),e=W(0,this.height,this.random);else if(this.emitterType===Tr.Circle){const s=W(0,this.radius,this.random);t=s*Math.cos(i),e=s*Math.sin(i)}const a=new Dr(this,this.particleLife,this.opacity,this.beginColor,this.endColor,new A(t,e),new A(n,o),this.acceleration,this.startSize,this.endSize);return a.fadeFlag=this.fadeFlag,a.particleSize=r,this.particleSprite&&(a.particleSprite=this.particleSprite,a.graphics.opacity=this.opacity,a.graphics.use(this._sprite)),a.particleRotationalVelocity=this.particleRotationalVelocity,this.randomRotation&&(a.currentRotation=W(0,2*Math.PI,this.random)),this.focus&&(a.focus=this.focus.add(new A(this.pos.x,this.pos.y)),a.focusAccel=this.focusAccel),a}update(t,e){var i;super.update(t,e),this.isEmitting&&(this._particlesToEmit+=this.emitRate*(e/1e3),this._particlesToEmit>1&&(this.emitParticles(Math.floor(this._particlesToEmit)),this._particlesToEmit=this._particlesToEmit-Math.floor(this._particlesToEmit)));for(let t=0;t<this.deadParticles.length;t++)tt(this.deadParticles[t],this.particles),(null===(i=null==this?void 0:this.scene)||void 0===i?void 0:i.world)&&this.scene.world.remove(this.deadParticles[t],!1);this.deadParticles.length=0}draw(t){this.particles.forEach((e=>e.draw(t)))}debugDraw(t){super.debugDraw(t),t.fillStyle=I.Black.toString(),t.fillText("Particles: "+this.particles.length,this.pos.x,this.pos.y+20),this.focus&&(t.fillRect(this.focus.x+this.pos.x,this.focus.y+this.pos.y,3,3),li(t,I.Yellow,this.focus.x+this.pos.x,this.focus.y+this.pos.y,this.center.x,this.center.y),t.fillText("Focus",this.focus.x+this.pos.x,this.focus.y+this.pos.y))}}class Mr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.graphics"],this.systemType=or.Draw,this.priority=0,this._token=0}initialize(t){this._graphicsContext=t.engine.graphicsContext,this._camera=t.camera,this._engine=t.engine}sort(t,e){return t.get(Ei).z-e.get(Ei).z}update(t,e){let i,s;this._token++;for(const r of t){i=r.get(Ei),s=r.get(cs);const t=this._isOffscreen(i,s);if(t&&!r.hasTag("offscreen")&&(r.eventDispatcher.emit("exitviewport",new re(r)),r.addComponent(new Pi("offscreen"))),!t&&r.hasTag("offscreen")&&(r.eventDispatcher.emit("enterviewport",new ne(r)),r.removeComponent("offscreen")),t)continue;this._pushCameraTransform(i),this._graphicsContext.save(),s.update(e,this._token),this._applyTransform(r),s.onPreDraw&&s.onPreDraw(this._graphicsContext,e);const n=r instanceof Dr?r.opacity:1;this._graphicsContext.opacity=s.opacity*n,this._drawGraphicsComponent(s),s.onPostDraw&&s.onPostDraw(this._graphicsContext,e),this._graphicsContext.restore(),this._popCameraTransform(i)}}_isOffscreen(t,e){if(t.coordPlane===Ti.World){return!this._camera.viewport.intersect(e.localBounds.transform(t.getGlobalMatrix()))}return!1}_drawGraphicsComponent(t){var e,i;if(t.visible)for(const s of t.layers.get())for(const{graphic:r,options:n}of s.graphics){let o=t.anchor,a=t.offset;(null==n?void 0:n.anchor)&&(o=n.anchor),(null==n?void 0:n.offset)&&(a=n.offset);const h=-r.width*o.x+a.x,l=-r.height*o.y+a.y;if(null==r||r.draw(this._graphicsContext,h+s.offset.x,l+s.offset.y),(null===(e=this._engine)||void 0===e?void 0:e.isDebug)&&this._engine.debug.graphics.showBounds){const t=P(h+s.offset.x,l+s.offset.y);if(r instanceof Ir)for(const e of r.members)null===(i=e.graphic)||void 0===i||i.localBounds.translate(t.add(e.pos)).draw(this._graphicsContext,this._engine.debug.graphics.boundsColor);else null==r||r.localBounds.translate(t).draw(this._graphicsContext,this._engine.debug.graphics.boundsColor)}}}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._graphicsContext.translate(e.pos.x,e.pos.y),this._graphicsContext.scale(e.scale.x,e.scale.y),this._graphicsContext.rotate(e.rotation))}}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._graphicsContext.restore()}}class kr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.canvas"],this.systemType=or.Draw,this.priority=-1}initialize(t){this._ctx=t.engine.ctx,this._engine=t.engine,this._camera=t.camera}sort(t,e){return t.get(Ei).z-e.get(Ei).z}update(t,e){var i,s,r;let n,o;this._clearScreen();const a=t.length;for(let h=0;h<a;h++){const a=null===(r=null===(s=null===(i=t[h])||void 0===i?void 0:i.graphics)||void 0===s?void 0:s.visible)||void 0===r||r,l=t[h].isOffScreen;a&&!l&&(n=t[h].get(Ei),o=t[h].get(os),this._ctx.save(),this._pushCameraTransform(n),this._ctx.save(),this._applyTransform(t[h]),o.draw(this._ctx,e),this._ctx.restore(),this._popCameraTransform(n),this._ctx.restore()),this._engine.isDebug&&(this._ctx.save(),this._pushCameraTransform(n),this._ctx.strokeStyle="yellow",t[h].debugDraw(this._ctx),this._popCameraTransform(n),this._ctx.restore())}this._engine.isDebug&&(this._ctx.save(),this._camera.draw(this._ctx),this._camera.debugDraw(this._ctx),this._ctx.restore()),this._engine.stats.currFrame.graphics.drawnImages=je.DrawnImagesCount,this._engine.stats.currFrame.graphics.drawCalls=je.DrawCallCount}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._ctx.translate(e.pos.x,e.pos.y),this._ctx.rotate(e.rotation),this._ctx.scale(e.scale.x,e.scale.y))}}_clearScreen(){this._ctx.clearRect(0,0,this._ctx.canvas.width,this._ctx.canvas.height),this._ctx.fillStyle=this._engine.backgroundColor.toString(),this._ctx.fillRect(0,0,this._ctx.canvas.width,this._ctx.canvas.height)}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._ctx.save(),this._camera&&this._camera.draw(this._ctx))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._ctx.restore()}}class Fr extends ar{constructor(){super(...arguments),this.types=["ex.transform"],this.systemType=or.Draw,this.priority=999}initialize(t){this._graphicsContext=t.engine.graphicsContext,this._camera=t.camera,this._engine=t.engine,this._collisionSystem=t.world.systemManager.get(Sr)}update(t,e){var i,s;if(!this._engine.isDebug)return;const r=this._engine.debug.filter;let n,o;const a=this._engine.debug.entity;let h;const l=this._engine.debug.transform;let c;const d=this._engine.debug.motion;let u;const p=this._engine.debug.collider,g=this._engine.debug.physics;let _;const f=this._engine.debug.graphics;let m,v;const y=this._engine.debug.body,w=this._engine.debug.camera;for(const e of t){if(e.hasTag("offscreen"))continue;if(e instanceof Dr)continue;if(r.useFilter){if(!(0===r.ids.length||r.ids.includes(e.id)))continue;if(!(""===r.nameQuery||e.name.includes(r.nameQuery)))continue}let t=A.Zero;const g=P(0,16);if(n=e.id,o=e.name,h=e.get(Ei),this._pushCameraTransform(h),this._graphicsContext.save(),this._applyTransform(e),h&&((l.showAll||l.showPosition)&&this._graphicsContext.debug.drawPoint(A.Zero,{size:4,color:l.positionColor}),(l.showAll||l.showPositionLabel)&&(this._graphicsContext.debug.drawText(`pos${h.pos.toString(2)}`,t),t=t.add(g)),(a.showAll||a.showId)&&(this._graphicsContext.debug.drawText(`id(${n}) ${h.parent?"child of id("+(null===(s=null===(i=h.parent)||void 0===i?void 0:i.owner)||void 0===s?void 0:s.id)+")":""}`,t),t=t.add(g)),(a.showAll||a.showName)&&(this._graphicsContext.debug.drawText(`name(${o})`,t),t=t.add(g)),(l.showAll||l.showRotation)&&(this._graphicsContext.drawLine(A.Zero,A.fromAngle(h.rotation).scale(50).add(A.Zero),l.rotationColor,2),this._graphicsContext.debug.drawText(`rot deg(${U(h.rotation).toFixed(2)})`,t),t=t.add(g)),(l.showAll||l.showScale)&&this._graphicsContext.drawLine(A.Zero,h.scale.add(A.Zero),l.scaleColor,2)),_=e.get(cs),_&&(f.showAll||f.showBounds)){_.localBounds.draw(this._graphicsContext,f.boundsColor)}if(m=e.get(Gs),m&&m.draw(this._graphicsContext),v=e.get($i),v&&((y.showAll||y.showCollisionGroup)&&(this._graphicsContext.debug.drawText(`collision group(${v.group.name})`,t),t=t.add(g)),(y.showAll||y.showCollisionType)&&(this._graphicsContext.debug.drawText(`collision type(${v.collisionType})`,t),t=t.add(g)),(y.showAll||y.showMass)&&(this._graphicsContext.debug.drawText(`mass(${v.mass})`,t),t=t.add(g)),(y.showAll||y.showMotion)&&(this._graphicsContext.debug.drawText(`motion(${v.sleepMotion})`,t),t=t.add(g)),(y.showAll||y.showSleeping)&&(this._graphicsContext.debug.drawText(`sleeping(${v.canSleep?v.sleeping:"cant sleep"})`,t),t=t.add(g))),this._graphicsContext.restore(),c=e.get(Ii),c&&((d.showAll||d.showVelocity)&&(this._graphicsContext.debug.drawText(`vel${c.vel.toString(2)}`,t.add(h.globalPos)),this._graphicsContext.drawLine(h.globalPos,h.globalPos.add(c.vel),d.velocityColor,2),t=t.add(g)),(d.showAll||d.showAcceleration)&&this._graphicsContext.drawLine(h.globalPos,h.globalPos.add(c.acc),d.accelerationColor,2)),u=e.get(Yi),u){const t=u.get();if((p.showAll||p.showGeometry)&&t&&t.debug(this._graphicsContext,p.geometryColor),p.showAll||p.showBounds)if(t instanceof Ui){const e=t.getColliders();for(const t of e){const e=t.bounds,i=P(e.left,e.top);this._graphicsContext.debug.drawRect(i.x,i.y,e.width,e.height,{color:p.boundsColor}),(p.showAll||p.showOwner)&&this._graphicsContext.debug.drawText(`owner id(${t.owner.id})`,i)}u.bounds.draw(this._graphicsContext,p.boundsColor)}else if(t){const t=u.bounds,e=P(t.left,t.top);this._graphicsContext.debug.drawRect(e.x,e.y,t.width,t.height,{color:p.boundsColor}),(p.showAll||p.showOwner)&&this._graphicsContext.debug.drawText(`owner id(${u.owner.id})`,e)}}this._popCameraTransform(h)}if(this._graphicsContext.save(),this._camera.draw(this._graphicsContext),(g.showAll||g.showBroadphaseSpacePartitionDebug)&&this._collisionSystem.debug(this._graphicsContext),g.showAll||g.showCollisionContacts||g.showCollisionNormals)for(const[t,e]of this._engine.debug.stats.currFrame.physics.contacts){if(g.showAll||g.showCollisionContacts)for(const t of e.points)this._graphicsContext.debug.drawPoint(t,{size:5,color:g.collisionContactColor});if(g.showAll||g.showCollisionNormals)for(const t of e.points)this._graphicsContext.debug.drawLine(t,e.normal.scale(30).add(t),{color:g.collisionNormalColor})}this._graphicsContext.restore(),w&&(this._graphicsContext.save(),this._camera.draw(this._graphicsContext),(w.showAll||w.showFocus)&&this._graphicsContext.drawCircle(this._camera.pos,4,w.focusColor),(w.showAll||w.showZoom)&&this._graphicsContext.debug.drawText(`zoom(${this._camera.zoom})`,this._camera.pos),this._graphicsContext.restore()),this._graphicsContext.flush()}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(Ei);e&&(this._graphicsContext.translate(e.pos.x,e.pos.y),this._graphicsContext.scale(e.scale.x,e.scale.y),this._graphicsContext.rotate(e.rotation))}}_pushCameraTransform(t){t.coordPlane===Ti.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Ti.World&&this._graphicsContext.restore()}}class Lr extends ar{constructor(){super(...arguments),this.types=["ex.transform","ex.pointer"],this.systemType=or.Update,this.priority=-1,this.overrideUseColliderShape=!1,this.overrideUseGraphicsBounds=!1,this.lastFrameEntityToPointers=new Map,this.currentFrameEntityToPointers=new Map}initialize(t){this._engine=t.engine,this._receiver=this._engine.input.pointers}sort(t,e){return e.get(Ei).z-t.get(Ei).z}entityCurrentlyUnderPointer(t,e){return this.currentFrameEntityToPointers.has(t.id)&&this.currentFrameEntityToPointers.get(t.id).includes(e)}entityWasUnderPointer(t,e){return this.lastFrameEntityToPointers.has(t.id)&&this.lastFrameEntityToPointers.get(t.id).includes(e)}entered(t,e){return this.entityCurrentlyUnderPointer(t,e)&&!this.lastFrameEntityToPointers.has(t.id)}left(t,e){return!this.currentFrameEntityToPointers.has(t.id)&&this.entityWasUnderPointer(t,e)}addPointerToEntity(t,e){if(!this.currentFrameEntityToPointers.has(t.id))return void this.currentFrameEntityToPointers.set(t.id,[e]);const i=this.currentFrameEntityToPointers.get(t.id);this.currentFrameEntityToPointers.set(t.id,i.concat(e))}update(t){this._processPointerToEntity(t),this._dispatchEvents(t),this._receiver.update(),this.lastFrameEntityToPointers.clear(),this.lastFrameEntityToPointers=new Map(this.currentFrameEntityToPointers),this.currentFrameEntityToPointers.clear(),this._receiver.clear()}_processPointerToEntity(t){var e;let i,s,r,n;for(const o of t){if(i=o.get(Ei),n=null!==(e=o.get(ps))&&void 0!==e?e:new ps,s=o.get(Yi),s&&(n.useColliderShape||this.overrideUseColliderShape)){const t=s.get();if(t)for(const[e,s]of this._receiver.currentFramePointerCoords.entries())t.contains(i.coordPlane===Ti.World?s.worldPos:s.screenPos)&&this.addPointerToEntity(o,e)}if(r=o.get(cs),r&&(n.useGraphicsBounds||this.overrideUseGraphicsBounds)){const t=r.localBounds.transform(i.getGlobalMatrix());for(const[e,s]of this._receiver.currentFramePointerCoords.entries())t.contains(i.coordPlane===Ti.World?s.worldPos:s.screenPos)&&this.addPointerToEntity(o,e)}}}_processDownAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameDown)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointerdown",i),this._receiver.isDragStart(i.pointerId)&&t.events.emit("pointerdragstart",i)),e.set(i.pointerId,i);return e}_processUpAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameUp)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointerup",i),this._receiver.isDragEnd(i.pointerId)&&t.events.emit("pointerdragend",i)),e.set(i.pointerId,i);return e}_processMoveAndEmit(t){const e=new Map;for(const i of this._receiver.currentFrameMove)i.active&&t.active&&this.entityCurrentlyUnderPointer(t,i.pointerId)&&(t.events.emit("pointermove",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragmove",i)),e.set(i.pointerId,i);return e}_processEnterLeaveAndEmit(t,e){for(const i of e){if(i.active&&t.active&&this.entered(t,i.pointerId)){t.events.emit("pointerenter",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragenter",i);break}if(i.active&&t.active&&(this.left(t,i.pointerId)||this.entityCurrentlyUnderPointer(t,i.pointerId)&&"up"===i.type)){t.events.emit("pointerleave",i),this._receiver.isDragging(i.pointerId)&&t.events.emit("pointerdragleave",i);break}}}_processCancelAndEmit(t){for(const e of this._receiver.currentFrameCancel)e.active&&t.active&&this.entityCurrentlyUnderPointer(t,e.pointerId)&&t.events.emit("pointercancel",e)}_processWheelAndEmit(t){for(const e of this._receiver.currentFrameWheel)e.active&&t.active&&this.entityCurrentlyUnderPointer(t,0)&&t.events.emit("pointerwheel",e)}_dispatchEvents(t){const e=new Set(this.lastFrameEntityToPointers.keys()),i=new Set(this.currentFrameEntityToPointers.keys()),s=t.filter((t=>e.has(t.id)||i.has(t.id)));let r,n,o;for(const t of s){o=this._processDownAndEmit(t),n=this._processUpAndEmit(t),r=this._processMoveAndEmit(t);const e=[...r.values(),...o.values(),...n.values()];this._processEnterLeaveAndEmit(t,e),this._processCancelAndEmit(t),this._processWheelAndEmit(t)}}}class zr extends ar{constructor(){super(...arguments),this.types=["ex.actions"],this.systemType=or.Update,this.priority=-1}update(t,e){let i;for(const s of t)i=s.get(Fs),i.update(e)}}var Or,Ur=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Nr extends hi{constructor(){super(),this._logger=f.getInstance(),this.camera=new ir,this.world=new mr(this),this._isInitialized=!1,this._timers=[],this._cancelQueue=[],this.world.add(new zr),this.world.add(new yr),this.world.add(new Sr),this.world.add(new Lr),g.isEnabled(d.LegacyDrawing)?this.world.add(new kr):this.world.add(new Mr),this.world.add(new Fr)}get actors(){return this.world.entityManager.entities.filter((t=>t instanceof Us))}get entities(){return this.world.entityManager.entities}get triggers(){return this.world.entityManager.entities.filter((t=>t instanceof nr))}get tileMaps(){return this.world.entityManager.entities.filter((t=>t instanceof js))}get screenElements(){return this.actors.filter((t=>t instanceof Ns))}get timers(){return this._timers}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}onInitialize(t){}onActivate(t,e){}onDeactivate(t,e){}onPreUpdate(t,e){}onPostUpdate(t,e){}onPreDraw(t,e){}onPostDraw(t,e){}_initializeChildren(){for(const t of this.entities)t._initialize(this.engine)}get isInitialized(){return this._isInitialized}_initialize(t){this.isInitialized||(this.engine=t,this.camera._initialize(t),this.world.systemManager.initialize(),this.onInitialize.call(this,t),this._initializeChildren(),this._logger.debug("Scene.onInitialize",this,t),this.eventDispatcher.emit("initialize",new ee(t,this)),this._isInitialized=!0)}_activate(t,e){this._logger.debug("Scene.onActivate",this),this.onActivate(t,e)}_deactivate(t,e){this._logger.debug("Scene.onDeactivate",this),this.onDeactivate(t,e)}_preupdate(t,e){this.emit("preupdate",new Ft(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Lt(t,e,this)),this.onPostUpdate(t,e)}_predraw(t,e){this.emit("predraw",new Dt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new Bt(t,e,this)),this.onPostDraw(t,e)}update(t,e){let i,s;for(this._preupdate(t,e),i=0,s=this._cancelQueue.length;i<s;i++)this.removeTimer(this._cancelQueue[i]);this._cancelQueue.length=0;for(const t of this._timers)t.update(e);this.world.update(or.Update,e),this.camera&&this.camera.update(t,e),this._collectActorStats(t),this._postupdate(t,e)}draw(t,e){var i;this._predraw(t,e),this.world.update(or.Draw,e),(null===(i=this.engine)||void 0===i?void 0:i.isDebug)&&this.debugDraw(t),this._postdraw(t,e)}debugDraw(t){this.emit("predebugdraw",new Mt(t,this)),this.emit("postdebugdraw",new kt(t,this))}contains(t){return this.actors.indexOf(t)>-1}add(t){this.emit("entityadded",{target:t}),this.world.add(t),t.scene=this,t instanceof Ws&&(et(this._timers,t)||this.addTimer(t))}remove(t){t instanceof ns&&(this.emit("entityremoved",{target:t}),this.world.remove(t)),t instanceof Ws&&this.removeTimer(t)}addScreenElement(t){this.add(t)}removeScreenElement(t){this.remove(t)}addTileMap(t){this.world.add(t)}removeTileMap(t){this.world.remove(t)}addTimer(t){return this._timers.push(t),t.scene=this,t}removeTimer(t){const e=this._timers.indexOf(t);return-1!==e&&this._timers.splice(e,1),t}cancelTimer(t){return this._cancelQueue.push(t),t}isTimerActive(t){return this._timers.indexOf(t)>-1&&!t.complete}isCurrentScene(){return!!this.engine&&this.engine.currentScene===this}_collectActorStats(t){const e=this.actors.filter((t=>t instanceof Ns));for(const i of e)t.stats.currFrame.actors.ui++;for(const e of this.actors){t.stats.currFrame.actors.alive++;for(const i of e.children)sr(i)?t.stats.currFrame.actors.ui++:t.stats.currFrame.actors.alive++}}}Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"ScreenElements now are normal actors with a Transform Coordinate Plane of Screen"})],Nr.prototype,"screenElements",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Nr.prototype,"addScreenElement",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Nr.prototype,"removeScreenElement",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Nr.prototype,"addTileMap",null),Ur([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Nr.prototype,"removeTileMap",null),function(t){t.Protanope="Protanope",t.Deuteranope="Deuteranope",t.Tritanope="Tritanope"}(Or||(Or={}));class Hr{constructor(t){this._shader=new Ve({vertexSource:"\n attribute vec2 a_position;\n attribute vec2 a_texcoord;\n varying vec2 v_texcoord;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n // Pass the texcoord to the fragment shader.\n v_texcoord = a_texcoord;\n }",fragmentSource:t}),this._shader.compile(),this._buffer=new Xe({type:"static",data:new Float32Array([-1,-1,0,0,-1,1,0,1,1,-1,1,0,1,-1,1,0,-1,1,0,1,1,1,1,1])}),this._layout=new qe({shader:this._shader,vertexBuffer:this._buffer,attributes:[["a_position",2],["a_texcoord",2]]}),this._buffer.upload()}getShader(){return this._shader}getLayout(){return this._layout}}class Wr{constructor(t,e=!1){this._colorBlindnessMode=t,this._simulate=!1,this._simulate=e}initialize(t){this._shader=new Hr("precision mediump float;\r\n// our texture\r\nuniform sampler2D u_image;\r\n// the texCoords passed in from the vertex shader.\r\nvarying vec2 v_texcoord;\r\n\r\n// color blind type\r\nuniform int u_type;\r\n\r\n// simulation?\r\nuniform bool u_simulate;\r\n\r\nvoid main() {\r\n vec4 o = texture2D(u_image, v_texcoord);\r\n // RGB to LMS matrix conversion\r\n float L = (17.8824 * o.r) + (43.5161 * o.g) + (4.11935 * o.b);\r\n float M = (3.45565 * o.r) + (27.1554 * o.g) + (3.86714 * o.b);\r\n float S = (0.0299566 * o.r) + (0.184309 * o.g) + (1.46709 * o.b);\r\n // Simulate color blindness\r\n float l;\r\n float m;\r\n float s;\r\n //MODE CODE//\r\n if (u_type == 0) {\r\n // Protanope\r\n l = 0.0 * L + 2.02344 * M + -2.52581 * S;\r\n m = 0.0 * L + 1.0 * M + 0.0 * S;\r\n s = 0.0 * L + 0.0 * M + 1.0 * S;;\r\n } else if (u_type == 1) {\r\n // Deuteranope\r\n l = 1.0 * L + 0.0 * M + 0.0 * S;\r\n m = 0.494207 * L + 0.0 * M + 1.24827 * S;\r\n s = 0.0 * L + 0.0 * M + 1.0 * S;\r\n } else if (u_type == 2) {\r\n // Tritanope\r\n l = 1.0 * L + 0.0 * M + 0.0 * S;\r\n m = 0.0 * L + 1.0 * M + 0.0 * S;\r\n s = -0.395913 * L + 0.801109 * M + 0.0 * S;\r\n }\r\n\r\n // LMS to RGB matrix conversion\r\n vec4 error; // simulate the colors\r\n error.r = (0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s);\r\n error.g = (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s);\r\n error.b = (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s);\r\n error.a = 1.0;\r\n vec4 diff = o - error;\r\n vec4 correction; // correct the colors\r\n correction.r = 0.0;\r\n correction.g = (diff.r * 0.7) + (diff.g * 1.0);\r\n correction.b = (diff.r * 0.7) + (diff.b * 1.0);\r\n correction = o + correction;\r\n correction.a = o.a;\r\n //SIMULATE//\r\n\r\n // sim \r\n if (u_simulate) {\r\n gl_FragColor = error.rgba;\r\n } else {\r\n gl_FragColor = correction.rgba;\r\n }\r\n}"),this.simulate=this._simulate,this.colorBlindnessMode=this._colorBlindnessMode}getShader(){return this._shader.getShader()}getLayout(){return this._shader.getLayout()}set colorBlindnessMode(t){if(this._colorBlindnessMode=t,this._shader){const t=this._shader.getShader();t.use(),this._colorBlindnessMode===Or.Protanope?t.setUniformInt("u_type",0):this._colorBlindnessMode===Or.Deuteranope?t.setUniformInt("u_type",1):this._colorBlindnessMode===Or.Tritanope&&t.setUniformInt("u_type",2)}}get colorBlindnessMode(){return this._colorBlindnessMode}set simulate(t){if(this._simulate=t,this._shader){const e=this._shader.getShader();e.use(),e.setUniformBoolean("u_simulate",t)}}get simulate(){return this._simulate}}class Gr{constructor(t){this._engine=t,this._colorBlindPostProcessor=new Wr(Or.Protanope)}correct(t){this._engine.graphicsContext instanceof ii&&(this.clear(),this._colorBlindPostProcessor.colorBlindnessMode=t,this._colorBlindPostProcessor.simulate=!1,this._engine.graphicsContext.addPostProcessor(this._colorBlindPostProcessor))}simulate(t){this._engine.graphicsContext instanceof ii&&(this.clear(),this._colorBlindPostProcessor.colorBlindnessMode=t,this._colorBlindPostProcessor.simulate=!0,this._engine.graphicsContext.addPostProcessor(this._colorBlindPostProcessor))}clear(){this._engine.graphicsContext.removePostProcessor(this._colorBlindPostProcessor)}}class Vr{constructor(t){this.stats={currFrame:new Xr,prevFrame:new Xr},this.filter={useFilter:!1,nameQuery:"",ids:[]},this.entity={showAll:!1,showId:!0,showName:!1},this.transform={showAll:!1,showPosition:!1,showPositionLabel:!1,positionColor:I.Yellow,showScale:!1,scaleColor:I.Green,showRotation:!1,rotationColor:I.Blue},this.graphics={showAll:!1,showBounds:!0,boundsColor:I.Yellow},this.collider={showAll:!1,showBounds:!0,boundsColor:I.Blue,showOwner:!1,showGeometry:!0,geometryColor:I.Green},this.physics={showAll:!1,showBroadphaseSpacePartitionDebug:!1,showCollisionNormals:!1,collisionNormalColor:I.Cyan,showCollisionContacts:!0,collisionContactColor:I.Red},this.motion={showAll:!1,showVelocity:!1,velocityColor:I.Yellow,showAcceleration:!1,accelerationColor:I.Red},this.body={showAll:!1,showCollisionGroup:!1,showCollisionType:!1,showSleeping:!1,showMotion:!1,showMass:!1},this.camera={showAll:!1,showFocus:!1,focusColor:I.Red,showZoom:!1},this._engine=t,this.colorBlindMode=new Gr(this._engine)}useTestClock(){const t=this._engine.clock,e=t.isRunning();t.stop();const i=t.toTestClock();return e&&i.start(),this._engine.clock=i,i}useStandardClock(){const t=this._engine.clock,e=t.isRunning();t.stop();const i=t.toStandardClock();return e&&i.start(),this._engine.clock=i,i}}class Xr{constructor(){this._id=0,this._delta=0,this._fps=0,this._actorStats={alive:0,killed:0,ui:0,get remaining(){return this.alive-this.killed},get total(){return this.remaining+this.ui}},this._durationStats={update:0,draw:0,get total(){return this.update+this.draw}},this._physicsStats=new qr,this._graphicsStats={drawCalls:0,drawnImages:0}}reset(t){t?(this.id=t.id,this.delta=t.delta,this.fps=t.fps,this.actors.alive=t.actors.alive,this.actors.killed=t.actors.killed,this.actors.ui=t.actors.ui,this.duration.update=t.duration.update,this.duration.draw=t.duration.draw,this._physicsStats.reset(t.physics),this.graphics.drawCalls=t.graphics.drawCalls,this.graphics.drawnImages=t.graphics.drawnImages):(this.id=this.delta=this.fps=0,this.actors.alive=this.actors.killed=this.actors.ui=0,this.duration.update=this.duration.draw=0,this._physicsStats.reset(),this.graphics.drawnImages=this.graphics.drawCalls=0)}clone(){const t=new Xr;return t.reset(this),t}get id(){return this._id}set id(t){this._id=t}get delta(){return this._delta}set delta(t){this._delta=t}get fps(){return this._fps}set fps(t){this._fps=t}get actors(){return this._actorStats}get duration(){return this._durationStats}get physics(){return this._physicsStats}get graphics(){return this._graphicsStats}}class qr{constructor(){this._pairs=0,this._collisions=0,this._contacts=new Map,this._fastBodies=0,this._fastBodyCollisions=0,this._broadphase=0,this._narrowphase=0}reset(t){t?(this.pairs=t.pairs,this.collisions=t.collisions,this.contacts=t.contacts,this.fastBodies=t.fastBodies,this.fastBodyCollisions=t.fastBodyCollisions,this.broadphase=t.broadphase,this.narrowphase=t.narrowphase):(this.pairs=this.collisions=this.fastBodies=0,this.fastBodyCollisions=this.broadphase=this.narrowphase=0,this.contacts.clear())}clone(){const t=new qr;return t.reset(this),t}get pairs(){return this._pairs}set pairs(t){this._pairs=t}get collisions(){return this._collisions}set collisions(t){this._collisions=t}get contacts(){return this._contacts}set contacts(t){this._contacts=t}get fastBodies(){return this._fastBodies}set fastBodies(t){this._fastBodies=t}get fastBodyCollisions(){return this._fastBodyCollisions}set fastBodyCollisions(t){this._fastBodyCollisions=t}get broadphase(){return this._broadphase}set broadphase(t){this._broadphase=t}get narrowphase(){return this._narrowphase}set narrowphase(t){this._narrowphase=t}}var jr,Kr,Zr,Yr,Qr,$r,Jr,tn;!function(t){t.Canvas="Canvas",t.Document="Document"}(jr||(jr={})),function(t){t.Num0="Numpad0",t.Num1="Numpad1",t.Num2="Numpad2",t.Num3="Numpad3",t.Num4="Numpad4",t.Num5="Numpad5",t.Num6="Numpad6",t.Num7="Numpad7",t.Num8="Numpad8",t.Num9="Numpad9",t.NumAdd="NumpadAdd",t.NumSubtract="NumpadSubtract",t.NumMultiply="NumpadMultiply",t.NumDivide="NumpadDivide",t.NumDecimal="NumpadDecimal",t.Numpad0="Numpad0",t.Numpad1="Numpad1",t.Numpad2="Numpad2",t.Numpad3="Numpad3",t.Numpad4="Numpad4",t.Numpad5="Numpad5",t.Numpad6="Numpad6",t.Numpad7="Numpad7",t.Numpad8="Numpad8",t.Numpad9="Numpad9",t.NumpadAdd="NumpadAdd",t.NumpadSubtract="NumpadSubtract",t.NumpadMultiply="NumpadMultiply",t.NumpadDivide="NumpadDivide",t.NumpadDecimal="NumpadDecimal",t.NumLock="NumLock",t.ShiftLeft="ShiftLeft",t.ShiftRight="ShiftRight",t.AltLeft="AltLeft",t.AltRight="AltRight",t.Key0="Digit0",t.Key1="Digit1",t.Key2="Digit2",t.Key3="Digit3",t.Key4="Digit4",t.Key5="Digit5",t.Key6="Digit6",t.Key7="Digit7",t.Key8="Digit8",t.Key9="Digit9",t.Digit0="Digit0",t.Digit1="Digit1",t.Digit2="Digit2",t.Digit3="Digit3",t.Digit4="Digit4",t.Digit5="Digit5",t.Digit6="Digit6",t.Digit7="Digit7",t.Digit8="Digit8",t.Digit9="Digit9",t.A="KeyA",t.B="KeyB",t.C="KeyC",t.D="KeyD",t.E="KeyE",t.F="KeyF",t.G="KeyG",t.H="KeyH",t.I="KeyI",t.J="KeyJ",t.K="KeyK",t.L="KeyL",t.M="KeyM",t.N="KeyN",t.O="KeyO",t.P="KeyP",t.Q="KeyQ",t.R="KeyR",t.S="KeyS",t.T="KeyT",t.U="KeyU",t.V="KeyV",t.W="KeyW",t.X="KeyX",t.Y="KeyY",t.Z="KeyZ",t.KeyA="KeyA",t.KeyB="KeyB",t.KeyC="KeyC",t.KeyD="KeyD",t.KeyE="KeyE",t.KeyF="KeyF",t.KeyG="KeyG",t.KeyH="KeyH",t.KeyI="KeyI",t.KeyJ="KeyJ",t.KeyK="KeyK",t.KeyL="KeyL",t.KeyM="KeyM",t.KeyN="KeyN",t.KeyO="KeyO",t.KeyP="KeyP",t.KeyQ="KeyQ",t.KeyR="KeyR",t.KeyS="KeyS",t.KeyT="KeyT",t.KeyU="KeyU",t.KeyV="KeyV",t.KeyW="KeyW",t.KeyX="KeyX",t.KeyY="KeyY",t.KeyZ="KeyZ",t.Semicolon="Semicolon",t.Quote="Quote",t.Comma="Comma",t.Minus="Minus",t.Period="Period",t.Slash="Slash",t.Equal="Equal",t.BracketLeft="BracketLeft",t.Backslash="Backslash",t.BracketRight="BracketRight",t.Backquote="Backquote",t.Up="ArrowUp",t.Down="ArrowDown",t.Left="ArrowLeft",t.Right="ArrowRight",t.ArrowUp="ArrowUp",t.ArrowDown="ArrowDown",t.ArrowLeft="ArrowLeft",t.ArrowRight="ArrowRight",t.Space="Space",t.Esc="Escape",t.Escape="Escape"}(Kr||(Kr={}));class en extends At{constructor(t,e,i){super(),this.key=t,this.value=e,this.originalEvent=i}}class sn extends hi{constructor(){super(),this._keys=[],this._keysUp=[],this._keysDown=[]}on(t,e){super.on(t,e)}init(t){if(!t)try{const e=()=>{};window.top.addEventListener("blur",e),window.top.removeEventListener("blur",e),t=window.top}catch(e){t=window,f.getInstance().warn("Failed to bind to keyboard events to top frame. If you are trying to embed Excalibur in a cross-origin iframe, keyboard events will not fire.")}t.addEventListener("blur",(()=>{this._keys.length=0})),t.addEventListener("keyup",(t=>{const e=t.code,i=this._keys.indexOf(e);this._keys.splice(i,1),this._keysUp.push(e);const s=new en(e,t.key,t);this.eventDispatcher.emit("up",s),this.eventDispatcher.emit("release",s)})),t.addEventListener("keydown",(t=>{const e=t.code;if(-1===this._keys.indexOf(e)){this._keys.push(e),this._keysDown.push(e);const i=new en(e,t.key,t);this.eventDispatcher.emit("down",i),this.eventDispatcher.emit("press",i)}}))}update(){this._keysDown.length=0,this._keysUp.length=0;for(let t=0;t<this._keys.length;t++)this.eventDispatcher.emit("hold",new en(this._keys[t]))}getKeys(){return this._keys}wasPressed(t){return this._keysDown.indexOf(t)>-1}isHeld(t){return this._keys.indexOf(t)>-1}wasReleased(t){return this._keysUp.indexOf(t)>-1}}class rn extends hi{constructor(){super(),this.enabled=!1,this.supported=!!navigator.getGamepads,this._gamePadTimeStamps=[0,0,0,0],this._oldPads=[],this._pads=[],this._initSuccess=!1,this._navigator=navigator,this._minimumConfiguration=null}init(){this.supported&&(this._initSuccess||(this._oldPads=this._clonePads(this._navigator.getGamepads()),this._oldPads.length&&this._oldPads[0]&&(this._initSuccess=!0)))}setMinimumGamepadConfiguration(t){this._enableAndUpdate(),this._minimumConfiguration=t}_enableAndUpdate(){this.enabled||(this.enabled=!0,this.update())}_isGamepadValid(t){if(!this._minimumConfiguration)return!0;if(!t)return!1;const e=t.axes.filter((t=>void 0!==typeof t)).length,i=t.buttons.filter((t=>void 0!==typeof t)).length;return e>=this._minimumConfiguration.axis&&i>=this._minimumConfiguration.buttons&&t.connected}on(t,e){this._enableAndUpdate(),super.on(t,e)}off(t,e){this._enableAndUpdate(),super.off(t,e)}update(){if(!this.enabled||!this.supported)return;this.init();const t=this._navigator.getGamepads();for(let e=0;e<t.length;e++){if(!t[e]){const t=this.at(e);t.connected&&this.eventDispatcher.emit("disconnect",new Nt(e,t)),t.connected=!1;continue}if(!this.at(e).connected&&this._isGamepadValid(t[e])&&this.eventDispatcher.emit("connect",new Ut(e,this.at(e))),this.at(e).connected=!0,t[e].timestamp&&t[e].timestamp===this._gamePadTimeStamps[e])continue;let i,s,r,n,o;for(i in this._gamePadTimeStamps[e]=t[e].timestamp,this.at(e).navigatorGamepad=t[e],Zr)s=Zr[i],"number"==typeof s&&t[e].buttons[s]&&(o=t[e].buttons[s].value,o!==this._oldPads[e].getButton(s)&&(t[e].buttons[s].pressed?(this.at(e).updateButton(s,o),this.at(e).eventDispatcher.emit("button",new Ht(s,o,this.at(e)))):this.at(e).updateButton(s,0)));for(r in Yr)n=Yr[r],"number"==typeof n&&(o=t[e].axes[n],o!==this._oldPads[e].getAxes(n)&&(this.at(e).updateAxes(n,o),this.at(e).eventDispatcher.emit("axis",new Wt(n,o,this.at(e)))));this._oldPads[e]=this._clonePad(t[e])}}at(t){if(this._enableAndUpdate(),t>=this._pads.length)for(let e=this._pads.length-1,i=t;e<i;e++)this._pads.push(new nn),this._oldPads.push(new nn);return this._pads[t]}getValidGamepads(){this._enableAndUpdate();const t=[];for(let e=0;e<this._pads.length;e++)this._isGamepadValid(this.at(e).navigatorGamepad)&&this.at(e).connected&&t.push(this.at(e));return t}count(){return this._pads.filter((t=>t.connected)).length}_clonePads(t){const e=[];for(let i=0,s=t.length;i<s;i++)e.push(this._clonePad(t[i]));return e}_clonePad(t){let e,i;const s=new nn;if(!t)return s;for(e=0,i=t.buttons.length;e<i;e++)t.buttons[e]&&s.updateButton(e,t.buttons[e].value);for(e=0,i=t.axes.length;e<i;e++)s.updateAxes(e,t.axes[e]);return s}}rn.MinAxisMoveThreshold=.05;class nn extends hi{constructor(){super(),this.connected=!1,this._buttons=new Array(16),this._axes=new Array(4);for(let t=0;t<this._buttons.length;t++)this._buttons[t]=0;for(let t=0;t<this._axes.length;t++)this._axes[t]=0}isButtonPressed(t,e=1){return this._buttons[t]>=e}getButton(t){return this._buttons[t]}getAxes(t){const e=this._axes[t];return Math.abs(e)<rn.MinAxisMoveThreshold?0:e}updateButton(t,e){this._buttons[t]=e}updateAxes(t,e){this._axes[t]=e}}!function(t){t[t.Face1=0]="Face1",t[t.Face2=1]="Face2",t[t.Face3=2]="Face3",t[t.Face4=3]="Face4",t[t.LeftBumper=4]="LeftBumper",t[t.RightBumper=5]="RightBumper",t[t.LeftTrigger=6]="LeftTrigger",t[t.RightTrigger=7]="RightTrigger",t[t.Select=8]="Select",t[t.Start=9]="Start",t[t.LeftStick=10]="LeftStick",t[t.RightStick=11]="RightStick",t[t.DpadUp=12]="DpadUp",t[t.DpadDown=13]="DpadDown",t[t.DpadLeft=14]="DpadLeft",t[t.DpadRight=15]="DpadRight"}(Zr||(Zr={})),function(t){t[t.LeftStickX=0]="LeftStickX",t[t.LeftStickY=1]="LeftStickY",t[t.RightStickX=2]="RightStickX",t[t.RightStickY=3]="RightStickY"}(Yr||(Yr={}));class on{constructor(t){this.nativeComponent=t,this._paused=!1,this._nativeHandlers={}}on(t,e){this._nativeHandlers[t]&&this.off(t,this._nativeHandlers[t]),this._nativeHandlers[t]=this._decorate(e),this.nativeComponent.addEventListener(t,this._nativeHandlers[t])}off(t,e){e||(e=this._nativeHandlers[t]),this.nativeComponent.removeEventListener(t,e),this._nativeHandlers[t]=null}_decorate(t){return e=>{this._paused||t(e)}}pause(){this._paused=!0}resume(){this._paused=!1}clear(){for(const t in this._nativeHandlers)this.off(t)}}class an{constructor(t,e){this._windowGlobal=t,this._documentGlobal=e,this._windowComponent=new on(this._windowGlobal),this._documentComponent=new on(this._documentGlobal)}get window(){return this._windowComponent}get document(){return this._documentComponent}pause(){this.window.pause(),this.document.pause()}resume(){this.window.resume(),this.document.resume()}clear(){this.window.clear(),this.document.clear()}}class hn{constructor(t){this._ex=t,this._debugText=new Ne}drawRect(t,e,i,s){this._ex.__ctx.save(),this._ex.__ctx.strokeStyle="red",this._ex.__ctx.strokeRect(this._ex.snapToPixel?~~t:t,this._ex.snapToPixel?~~e:e,this._ex.snapToPixel?~~i:i,this._ex.snapToPixel?~~s:s),this._ex.__ctx.restore()}drawLine(t,e,i={color:I.Black}){this._ex.__ctx.save(),this._ex.__ctx.beginPath(),this._ex.__ctx.strokeStyle=i.color.toString(),this._ex.__ctx.moveTo(this._ex.snapToPixel?~~t.x:t.x,this._ex.snapToPixel?~~t.y:t.y),this._ex.__ctx.lineTo(this._ex.snapToPixel?~~e.x:e.x,this._ex.snapToPixel?~~e.y:e.y),this._ex.__ctx.lineWidth=2,this._ex.__ctx.stroke(),this._ex.__ctx.closePath(),this._ex.__ctx.restore()}drawPoint(t,e={color:I.Black,size:5}){this._ex.__ctx.save(),this._ex.__ctx.beginPath(),this._ex.__ctx.fillStyle=e.color.toString(),this._ex.__ctx.arc(this._ex.snapToPixel?~~t.x:t.x,this._ex.snapToPixel?~~t.y:t.y,e.size,0,2*Math.PI),this._ex.__ctx.fill(),this._ex.__ctx.closePath(),this._ex.__ctx.restore()}drawText(t,e){this._debugText.write(this._ex,t,e)}}class ln{constructor(t){this.backgroundColor=I.ExcaliburBlue,this._state=new ut,this.snapToPixel=!0,this.debug=new hn(this);const{canvasElement:e,enableTransparency:i,snapToPixel:s,smoothing:r,backgroundColor:n}=t;this.__ctx=e.getContext("2d",{alpha:null==i||i}),this.backgroundColor=null!=n?n:this.backgroundColor,this.snapToPixel=null!=s?s:this.snapToPixel,this.smoothing=null!=r?r:this.smoothing}get width(){return this.__ctx.canvas.width}get height(){return this.__ctx.canvas.height}get opacity(){return this._state.current.opacity}set opacity(t){this._state.current.opacity=t}get smoothing(){return this.__ctx.imageSmoothingEnabled}set smoothing(t){this.__ctx.imageSmoothingEnabled=t}resetTransform(){this.__ctx.resetTransform()}updateViewport(t){}drawImage(t,e,i,s,r,n,o,a,h){if(0===s||0===r)return;if(0===a||0===h)return;if(0===t.width||0===t.height)return;this.__ctx.globalAlpha=this.opacity;const l=[t,e,i,s,r,n,o,a,h].filter((t=>void 0!==t)).map((t=>"number"==typeof t&&this.snapToPixel?~~t:t));this.__ctx.drawImage.apply(this.__ctx,l),je.DrawCallCount++,je.DrawnImagesCount=1}drawLine(t,e,i,s=1){this.__ctx.save(),this.__ctx.beginPath(),this.__ctx.strokeStyle=i.toString(),this.__ctx.moveTo(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y),this.__ctx.lineTo(this.snapToPixel?~~e.x:e.x,this.snapToPixel?~~e.y:e.y),this.__ctx.lineWidth=s,this.__ctx.stroke(),this.__ctx.closePath(),this.__ctx.restore()}drawRectangle(t,e,i,s){this.__ctx.save(),this.__ctx.fillStyle=s.toString(),this.__ctx.fillRect(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y,this.snapToPixel?~~e:e,this.snapToPixel?~~i:i),this.__ctx.restore()}drawCircle(t,e,i,s,r){this.__ctx.save(),this.__ctx.beginPath(),s&&(this.__ctx.strokeStyle=s.toString()),r&&(this.__ctx.lineWidth=r),this.__ctx.fillStyle=i.toString(),this.__ctx.arc(this.snapToPixel?~~t.x:t.x,this.snapToPixel?~~t.y:t.y,e,0,2*Math.PI),this.__ctx.fill(),s&&this.__ctx.stroke(),this.__ctx.closePath(),this.__ctx.restore()}save(){this.__ctx.save()}restore(){this.__ctx.restore()}translate(t,e){this.__ctx.translate(this.snapToPixel?~~t:t,this.snapToPixel?~~e:e)}rotate(t){this.__ctx.rotate(t)}scale(t,e){this.__ctx.scale(t,e)}getTransform(){throw new Error("Not implemented")}multiply(t){this.__ctx.setTransform(this.__ctx.getTransform().multiply(t.toDOMMatrix()))}addPostProcessor(t){throw Error("Not implemented")}removePostProcessor(t){throw Error("Not implemented")}clearPostProcessors(){throw Error("Not implemented")}beginDrawLifecycle(){}endDrawLifecycle(){}clear(){this.__ctx.clearRect(0,0,this.width,this.height),this.__ctx.fillStyle=this.backgroundColor.toString(),this.__ctx.fillRect(0,0,this.width,this.height),je.clear()}flush(){}}class cn{constructor(t,e,i){this.worldPos=t,this.pagePos=e,this.screenPos=i}static fromPagePosition(t,e,i){let s,r,n,o;3===arguments.length?(s=t,r=e,n=new A(s,r),o=i):(n=t,s=n.x,r=n.y,o=e);const a=o.screen.pageToScreenCoordinates(n),h=o.screen.screenToWorldCoordinates(a);return new cn(h,n,a)}}class dn{constructor(t,e,i,s,r,n){this.type=t,this.pointerId=e,this.button=i,this.pointerType=s,this.coordinates=r,this.nativeEvent=n,this.active=!0}cancel(){this.active=!1}get pagePos(){return this.coordinates.pagePos}get screenPos(){return this.coordinates.screenPos}get worldPos(){return this.coordinates.worldPos}}class un{constructor(t,e,i,s,r,n,o,a,h,l,c,d){this.x=t,this.y=e,this.pageX=i,this.pageY=s,this.screenX=r,this.screenY=n,this.index=o,this.deltaX=a,this.deltaY=h,this.deltaZ=l,this.deltaMode=c,this.ev=d,this.active=!0}cancel(){this.active=!1}}class pn extends hi{constructor(){super(),this.lastPagePos=A.Zero,this.lastScreenPos=A.Zero,this.lastWorldPos=A.Zero,this._onPointerMove=t=>{this.lastPagePos=new A(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new A(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new A(t.worldPos.x,t.worldPos.y)},this._onPointerDown=t=>{this.lastPagePos=new A(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new A(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new A(t.worldPos.x,t.worldPos.y)},this.on("move",this._onPointerMove),this.on("down",this._onPointerDown)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}}!function(t){t.Pixel="Pixel",t.Line="Line",t.Page="Page"}(Qr||(Qr={})),function(t){t[t.NoButton=-1]="NoButton",t[t.Left=0]="Left",t[t.Middle=1]="Middle",t[t.Right=2]="Right",t[t.Unknown=3]="Unknown"}($r||($r={})),function(t){t.Left="Left",t.Middle="Middle",t.Right="Right",t.Unknown="Unknown",t.NoButton="NoButton"}(Jr||(Jr={})),function(t){t.Touch="Touch",t.Mouse="Mouse",t.Pen="Pen",t.Unknown="Unknown"}(tn||(tn={}));class gn extends hi{constructor(t,e){super(),this.target=t,this.engine=e,this.primary=new pn,this._activeNativePointerIdsToNormalized=new Map,this.lastFramePointerCoords=new Map,this.currentFramePointerCoords=new Map,this.currentFramePointerDown=new Map,this.lastFramePointerDown=new Map,this.currentFrameDown=[],this.currentFrameUp=[],this.currentFrameMove=[],this.currentFrameCancel=[],this.currentFrameWheel=[],this._pointers=[this.primary],this._boundHandle=this._handle.bind(this),this._boundWheel=this._handleWheel.bind(this)}at(t){if(t>=this._pointers.length)for(let e=this._pointers.length-1,i=t;e<i;e++)this._pointers.push(new pn);return this._pointers[t]}count(){return this._pointers.length}isDown(t){var e;return null!==(e=this.currentFramePointerDown.get(t))&&void 0!==e&&e}wasDown(t){var e;return null!==(e=this.lastFramePointerDown.get(t))&&void 0!==e&&e}isDragging(t){return this.isDown(t)}isDragStart(t){return this.isDown(t)&&!this.wasDown(t)}isDragEnd(t){return!this.isDown(t)&&this.wasDown(t)}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}update(){this.lastFramePointerDown=new Map(this.currentFramePointerDown),this.lastFramePointerCoords=new Map(this.currentFramePointerCoords);for(const t of this.currentFrameDown){this.emit("down",t);this.at(t.pointerId).emit("down",t),this.primary.emit("pointerdown",t)}for(const t of this.currentFrameUp){this.emit("up",t);this.at(t.pointerId).emit("up",t)}for(const t of this.currentFrameMove){this.emit("move",t);this.at(t.pointerId).emit("move",t)}for(const t of this.currentFrameCancel){this.emit("cancel",t);this.at(t.pointerId).emit("cancel",t)}for(const t of this.currentFrameWheel)this.emit("wheel",t),this.primary.emit("pointerwheel",t)}clear(){for(const t of this.currentFrameUp){this.currentFramePointerCoords.delete(t.pointerId);const e=this._activeNativePointerIdsToNormalized.entries();for(const[i,s]of e)s===t.pointerId&&this._activeNativePointerIdsToNormalized.delete(i)}this.currentFrameDown.length=0,this.currentFrameUp.length=0,this.currentFrameMove.length=0,this.currentFrameCancel.length=0,this.currentFrameWheel.length=0}init(){this.target===this.engine.canvas?this.engine.canvas.style.touchAction="none":document.body.style.touchAction="none",window.PointerEvent?(this.target.addEventListener("pointerdown",this._boundHandle),this.target.addEventListener("pointerup",this._boundHandle),this.target.addEventListener("pointermove",this._boundHandle),this.target.addEventListener("pointercancel",this._boundHandle)):(this.target.addEventListener("touchstart",this._boundHandle),this.target.addEventListener("touchend",this._boundHandle),this.target.addEventListener("touchmove",this._boundHandle),this.target.addEventListener("touchcancel",this._boundHandle),this.target.addEventListener("mousedown",this._boundHandle),this.target.addEventListener("mouseup",this._boundHandle),this.target.addEventListener("mousemove",this._boundHandle));const t={passive:!(this.engine.pageScrollPreventionMode===yn.All||this.engine.pageScrollPreventionMode===yn.Canvas)};"onwheel"in document.createElement("div")?this.target.addEventListener("wheel",this._boundWheel,t):void 0!==document.onmousewheel?this.target.addEventListener("mousewheel",this._boundWheel,t):this.target.addEventListener("MozMousePixelScroll",this._boundWheel,t)}detach(){window.PointerEvent?(this.target.removeEventListener("pointerdown",this._boundHandle),this.target.removeEventListener("pointerup",this._boundHandle),this.target.removeEventListener("pointermove",this._boundHandle),this.target.removeEventListener("pointercancel",this._boundHandle)):(this.target.removeEventListener("touchstart",this._boundHandle),this.target.removeEventListener("touchend",this._boundHandle),this.target.removeEventListener("touchmove",this._boundHandle),this.target.removeEventListener("touchcancel",this._boundHandle),this.target.removeEventListener("mousedown",this._boundHandle),this.target.removeEventListener("mouseup",this._boundHandle),this.target.removeEventListener("mousemove",this._boundHandle)),"onwheel"in document.createElement("div")?this.target.removeEventListener("wheel",this._boundWheel):void 0!==document.onmousewheel?this.target.addEventListener("mousewheel",this._boundWheel):this.target.addEventListener("MozMousePixelScroll",this._boundWheel)}_normalizePointerId(t){this._activeNativePointerIdsToNormalized.set(t,-1);const e=Array.from(this._activeNativePointerIdsToNormalized.keys()).sort(((t,e)=>t-e)).findIndex((e=>e===t));return this._activeNativePointerIdsToNormalized.set(t,e),e}_handle(t){t.preventDefault();const e=new Map;let i,s;if(r=t,globalThis.TouchEvent&&r instanceof globalThis.TouchEvent){i=Jr.Unknown,s=tn.Touch;for(let i=0;i<t.changedTouches.length;i++){const s=t.changedTouches[i],r=cn.fromPagePosition(s.pageX,s.pageY,this.engine),n=i+1,o=this._normalizePointerId(n);this.currentFramePointerCoords.set(o,r),e.set(o,r)}}else{i=this._nativeButtonToPointerButton(t.button),s=tn.Mouse;const r=cn.fromPagePosition(t.pageX,t.pageY,this.engine);let n=1;(function(t){return globalThis.PointerEvent&&t instanceof globalThis.PointerEvent})(t)&&(n=t.pointerId,s=this._stringToPointerType(t.pointerType));const o=this._normalizePointerId(n);this.currentFramePointerCoords.set(o,r),e.set(o,r)}var r;for(const[r,n]of e.entries())switch(t.type){case"mousedown":case"pointerdown":case"touchstart":this.currentFrameDown.push(new dn("down",r,i,s,n,t)),this.currentFramePointerDown.set(r,!0);break;case"mouseup":case"pointerup":case"touchend":this.currentFrameUp.push(new dn("up",r,i,s,n,t)),this.currentFramePointerDown.set(r,!1);break;case"mousemove":case"pointermove":case"touchmove":this.currentFrameMove.push(new dn("move",r,i,s,n,t));break;case"touchcancel":case"pointercancel":this.currentFrameCancel.push(new dn("cancel",r,i,s,n,t))}}_handleWheel(t){(this.engine.pageScrollPreventionMode===yn.All||this.engine.pageScrollPreventionMode===yn.Canvas&&t.target===this.engine.canvas)&&t.preventDefault();const e=this.engine.screen.pageToScreenCoordinates(P(t.pageX,t.pageY)),i=this.engine.screen.screenToWorldCoordinates(e),s=-1/40,r=t.deltaX||t.wheelDeltaX*s||0,n=t.deltaY||t.wheelDeltaY*s||t.wheelDelta*s||t.detail||0,o=t.deltaZ||0;let a=Qr.Pixel;t.deltaMode&&(1===t.deltaMode?a=Qr.Line:2===t.deltaMode&&(a=Qr.Page));const h=new un(i.x,i.y,t.pageX,t.pageY,e.x,e.y,0,r,n,o,a,t);this.currentFrameWheel.push(h)}triggerEvent(t,e){const i=this.engine.screen.worldToPageCoordinates(e);window.PointerEvent?this._handle(new window.PointerEvent("pointer"+t,{pointerId:0,clientX:i.x,clientY:i.y})):this._handle(new window.MouseEvent("mouse"+t,{clientX:i.x,clientY:i.y}));const s=this.engine.currentScene.world.systemManager.get(Lr),r=this.engine.currentScene.world.queryManager.createQuery(s.types);s.update(r.getEntities())}_nativeButtonToPointerButton(t){switch(t){case $r.NoButton:return Jr.NoButton;case $r.Left:return Jr.Left;case $r.Middle:return Jr.Middle;case $r.Right:return Jr.Right;case $r.Unknown:return Jr.Unknown;default:return nt(t)}}_stringToPointerType(t){switch(t){case"touch":return tn.Touch;case"mouse":return tn.Mouse;case"pen":return tn.Pen;default:return tn.Unknown}}}class _n{constructor(t){var e;this._samplePeriod=100,this._currentFrameTime=0,this._frames=0,this._previousSampleTime=0,this._beginFrameTime=0,this._fps=t.initialFps,this._samplePeriod=null!==(e=t.samplePeriod)&&void 0!==e?e:this._samplePeriod,this._currentFrameTime=1e3/t.initialFps,this._nowFn=t.nowFn,this._previousSampleTime=this._nowFn()}start(){this._beginFrameTime=this._nowFn()}end(){this._frames++;const t=this._nowFn();this._currentFrameTime=t-this._beginFrameTime,t>=this._previousSampleTime+this._samplePeriod&&(this._fps=1e3*this._frames/(t-this._previousSampleTime),this._previousSampleTime=t,this._frames=0)}get fps(){return this._fps}get instant(){return 1e3/this._currentFrameTime}}class fn{constructor(t){var e,i,s;this._onFatalException=()=>{},this._maxFps=1/0,this._lastTime=0,this._elapsed=1,this._scheduledCbs=[],this._totalElapsed=0,this._options=t,this.tick=t.tick,this._lastTime=null!==(e=this.now())&&void 0!==e?e:0,this._maxFps=null!==(i=t.maxFps)&&void 0!==i?i:this._maxFps,this._onFatalException=null!==(s=t.onFatalException)&&void 0!==s?s:this._onFatalException,this.fpsSampler=new _n({initialFps:60,nowFn:()=>this.now()})}elapsed(){return this._elapsed}now(){return performance.now()}toTestClock(){return new vn({...this._options,defaultUpdateMs:16.6})}toStandardClock(){return new mn({...this._options})}setFatalExceptionHandler(t){this._onFatalException=t}schedule(t,e=0){const i=this.now()+e;this._scheduledCbs.push([t,i])}_runScheduledCbs(){for(let t=this._scheduledCbs.length-1;t>-1;t--)this._scheduledCbs[t][1]<=this._totalElapsed&&(this._scheduledCbs[t][0](),this._scheduledCbs.splice(t,1))}update(t){try{this.fpsSampler.start();const e=this.now();let i=e-this._lastTime||1;const s=1e3/this._maxFps;if(i>=s){let r=0;0!==s&&(r=i%s,i-=r),i>200&&(i=1),this._elapsed=t||i,this._totalElapsed+=this._elapsed,this._runScheduledCbs(),this.tick(t||i),this._lastTime=0!==s?e-r:e,this.fpsSampler.end()}}catch(t){this._onFatalException(t),this.stop()}}}class mn extends fn{constructor(t){super(t),this._running=!1}isRunning(){return this._running}start(){if(this._running)return;this._running=!0;const t=()=>{if(this._running)try{this._requestId=window.requestAnimationFrame(t),this.update()}catch(t){throw window.cancelAnimationFrame(this._requestId),t}};t()}stop(){this._running=!1}}class vn extends fn{constructor(t){super({...t}),this._logger=f.getInstance(),this._running=!1,this._currentTime=0,this._updateMs=t.defaultUpdateMs}now(){var t;return null!==(t=this._currentTime)&&void 0!==t?t:0}isRunning(){return this._running}start(){this._running=!0}stop(){this._running=!1}step(t){const e=null!=t?t:this._updateMs;this._running?(this.update(e),this._currentTime+=e):this._logger.warn("The clock is not running, no step will be performed")}run(t,e){for(let i=0;i<t;i++)this.step(null!=e?e:this._updateMs)}}var yn,wn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};p(),function(t){t[t.None=0]="None",t[t.Canvas=1]="Canvas",t[t.All=2]="All"}(yn||(yn={}));class xn extends hi{constructor(t){var e,i,s,r;super(),this.maxFps=Number.POSITIVE_INFINITY,this._hasStarted=!1,this.scenes={},this._animations=[],this._suppressPlayButton=!1,this.pauseAudioWhenHidden=!0,this._isDebug=!1,this.debugColor=new I(255,255,255),this.enableCanvasTransparency=!0,this.onFatalException=t=>{f.getInstance().fatal(t)},this._timescale=1,this._isInitialized=!1,this._deferredGoTo=null,this._loadingComplete=!1,this._isReady=!1,this._isReadyPromise=new Promise((t=>{this._isReadyResolve=t})),this._screenShotRequests=[],t={...xn._DEFAULT_ENGINE_OPTIONS,...t},g.freeze(),this.browser=new an(window,document);const n=new mi;if(!t.suppressMinimumBrowserFeatureDetection&&!(this._compatible=n.test())){const e=document.createElement("div");if(e.innerText="Sorry, your browser does not support all the features needed for Excalibur",document.body.appendChild(e),n.failedTests.forEach((function(t){const e=document.createElement("div");e.innerText="Browser feature missing "+t,document.body.appendChild(e)})),t.canvasElementId){const e=document.getElementById(t.canvasElementId);e&&e.parentElement.removeChild(e)}return}this._compatible=!0,console.log&&!t.suppressConsoleBootMessage&&(console.log(`%cPowered by Excalibur.js (v${ro})`,"background: #176BAA; color: white; border-radius: 5px; padding: 15px; font-size: 1.5em; line-height: 80px;"),console.log("\n /| ________________\nO|===|* >________________>\n \\|"),console.log("Visit","http://excaliburjs.com","for more information")),t.suppressPlayButton&&(this._suppressPlayButton=!0),this._logger=f.getInstance(),this._logger.defaultLevel===u.Debug&&n.logBrowserFeatures(),this._logger.debug("Building engine..."),this.canvasElementId=t.canvasElementId,t.canvasElementId?(this._logger.debug("Using Canvas element specified: "+t.canvasElementId),this.canvas=document.getElementById(t.canvasElementId)):t.canvasElement?(this._logger.debug("Using Canvas element specified:",t.canvasElement),this.canvas=t.canvasElement):(this._logger.debug("Using generated canvas element"),this.canvas=document.createElement("canvas"));let o=null!==(e=t.displayMode)&&void 0!==e?e:si.Fixed;if(t.width&&t.height||t.viewport?(void 0===t.displayMode&&(o=si.Fixed),this._logger.debug("Engine viewport is size "+t.width+" x "+t.height)):t.displayMode||(this._logger.debug("Engine viewport is fit"),o=si.FitScreen),g.isEnabled(d.Canvas)){const e=new ln({canvasElement:this.canvas,enableTransparency:this.enableCanvasTransparency,smoothing:t.antialiasing,backgroundColor:t.backgroundColor,snapToPixel:t.snapToPixel});this.graphicsContext=e,this.ctx=e.__ctx}else{const e=new ii({canvasElement:this.canvas,enableTransparency:this.enableCanvasTransparency,smoothing:t.antialiasing,backgroundColor:t.backgroundColor,snapToPixel:t.snapToPixel});this.graphicsContext=e,this.ctx=e.__ctx}this.screen=new ni({canvas:this.canvas,context:this.graphicsContext,antialiasing:null===(i=t.antialiasing)||void 0===i||i,browser:this.browser,viewport:null!==(s=t.viewport)&&void 0!==s?s:t.width&&t.height?{width:t.width,height:t.height}:ri.SVGA,resolution:t.resolution,displayMode:o,position:t.position,pixelRatio:t.suppressHiDPIScaling?1:null}),bt.filtering=t.antialiasing?ht.Blended:ht.Pixel,t.backgroundColor&&(this.backgroundColor=t.backgroundColor.clone()),this.maxFps=null!==(r=t.maxFps)&&void 0!==r?r:this.maxFps,this.clock=new mn({maxFps:this.maxFps,tick:this._mainloop.bind(this),onFatalException:t=>this.onFatalException(t)}),this.enableCanvasTransparency=t.enableCanvasTransparency,this._loader=new _i,this._loader.wireEngine(this),this.debug=new Vr(this),this._initialize(t),this.rootScene=this.currentScene=new Nr,this.addScene("root",this.rootScene),window.___EXCALIBUR_DEVTOOL=this}get canvasWidth(){return this.screen.canvasWidth}get halfCanvasWidth(){return this.screen.halfCanvasWidth}get canvasHeight(){return this.screen.canvasHeight}get halfCanvasHeight(){return this.screen.halfCanvasHeight}get drawWidth(){return this.screen.drawWidth}get halfDrawWidth(){return this.screen.halfDrawWidth}get drawHeight(){return this.screen.drawHeight}get halfDrawHeight(){return this.screen.halfDrawHeight}get isHiDpi(){return this.screen.isHiDpi}get stats(){return this.debug.stats}get isFullscreen(){return this.screen.isFullScreen}get displayMode(){return this.screen.displayMode}get pixelRatio(){return this.screen.pixelRatio}get isDebug(){return this._isDebug}get snapToPixel(){return this.graphicsContext.snapToPixel}set snapToPixel(t){this.graphicsContext.snapToPixel=t}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}getWorldBounds(){return this.screen.getWorldBounds()}get timescale(){return this._timescale}set timescale(t){t<=0?f.getInstance().error("Cannot set engine.timescale to a value of 0 or less than 0."):this._timescale=t}playAnimation(t,e,i){this._animations.push(new bn(t,e,i))}addTileMap(t){this.currentScene.addTileMap(t)}removeTileMap(t){this.currentScene.removeTileMap(t)}addTimer(t){return this.currentScene.addTimer(t)}removeTimer(t){return this.currentScene.removeTimer(t)}addScene(t,e){this.scenes[t]&&this._logger.warn("Scene",t,"already exists overwriting"),this.scenes[t]=e}removeScene(t){if(t instanceof Nr)for(const e in this.scenes)this.scenes.hasOwnProperty(e)&&this.scenes[e]===t&&delete this.scenes[e];"string"==typeof t&&delete this.scenes[t]}add(t){2!==arguments.length?this._deferredGoTo&&this.scenes[this._deferredGoTo]?this.scenes[this._deferredGoTo].add(t):this.currentScene.add(t):this.addScene(arguments[0],arguments[1])}remove(t){t instanceof ns&&this.currentScene.remove(t),t instanceof Nr&&this.removeScene(t),"string"==typeof t&&this.removeScene(t)}goToScene(t){if(this.isInitialized)if(this.scenes[t]){const e=this.currentScene,i=this.scenes[t];this._logger.debug("Going to scene:",t),this.currentScene.isInitialized&&(this.currentScene._deactivate.apply(this.currentScene,[e,i]),this.currentScene.eventDispatcher.emit("deactivate",new se(i,this.currentScene))),this.currentScene=i,this.screen.setCurrentCamera(i.camera),this.currentScene._initialize(this),this.currentScene._activate.apply(this.currentScene,[e,i]),this.currentScene.eventDispatcher.emit("activate",new ie(e,this.currentScene))}else this._logger.error("Scene",t,"does not exist!");else this._deferredGoTo=t}screenToWorldCoordinates(t){return this.screen.screenToWorldCoordinates(t)}worldToScreenCoordinates(t){return this.screen.worldToScreenCoordinates(t)}_initialize(t){this.pageScrollPreventionMode=t.scrollPreventionMode;const e=t&&t.pointerScope===jr.Document?document:this.canvas;let i,s;this.input={keyboard:new sn,pointers:new gn(e,this),gamepads:new rn},this.input.keyboard.init(),this.input.pointers.init(),this.input.gamepads.init(),void 0!==document.hidden?(i="hidden",s="visibilitychange"):"msHidden"in document?(i="msHidden",s="msvisibilitychange"):"webkitHidden"in document&&(i="webkitHidden",s="webkitvisibilitychange"),this.browser.document.on(s,(()=>{document[i]?(this.eventDispatcher.emit("hidden",new qt(this)),this._logger.debug("Window hidden")):(this.eventDispatcher.emit("visible",new Xt(this)),this._logger.debug("Window visible"))})),this.canvasElementId||t.canvasElement||document.body.appendChild(this.canvas)}onInitialize(t){}setAntialiasing(t){this.screen.antialiasing=t}getAntialiasing(){return this.screen.antialiasing}get isInitialized(){return this._isInitialized}_overrideInitialize(t){this.isInitialized||(this.onInitialize(t),super.emit("initialize",new ee(t,this)),this._isInitialized=!0,this._deferredGoTo?this.goToScene(this._deferredGoTo):this.goToScene("root"))}_update(t){if(!this.ready)return this._loader.update(this,t),this.input.keyboard.update(),void this.input.gamepads.update();this._preupdate(t),this.currentScene.update(this,t),this._animations=this._animations.filter((function(t){return!t.animation.isDone()})),this.input.keyboard.update(),this.input.gamepads.update(),this._postupdate(t)}_preupdate(t){this.emit("preupdate",new Ft(this,t,this)),this.onPreUpdate(this,t)}onPreUpdate(t,e){}_postupdate(t){this.emit("postupdate",new Lt(this,t,this)),this.onPostUpdate(this,t)}onPostUpdate(t,e){}_draw(t){const e=this.ctx;if(this.graphicsContext.beginDrawLifecycle(),this.graphicsContext.clear(),this._predraw(e,t),!this._isReady)return this._loader.canvas.draw(this.graphicsContext,0,0),void this.graphicsContext.flush();this.graphicsContext.backgroundColor=this.backgroundColor,this.currentScene.draw(this.ctx,t);let i=0;const s=this._animations.length;for(;i<s;i++)this._animations[i].animation.draw(e,this._animations[i].x,this._animations[i].y);if(this.isDebug){this.ctx.font="Consolas",this.ctx.fillStyle=this.debugColor.toString();const t=this.input.keyboard.getKeys();for(let e=0;e<t.length;e++)this.ctx.fillText(t[e].toString()+" : "+(Kr[t[e]]?Kr[t[e]]:"Not Mapped"),100,10*e+10);this.ctx.fillText("FPS:"+this.stats.currFrame.fps.toFixed(2).toString(),10,10)}this._postdraw(e,t),this.graphicsContext.flush(),this.graphicsContext.endDrawLifecycle(),this._checkForScreenShots()}_predraw(t,e){this.emit("predraw",new Dt(t,e,this)),this.onPreDraw(t,e)}onPreDraw(t,e){}_postdraw(t,e){this.emit("postdraw",new Bt(t,e,this)),this.onPostDraw(t,e)}onPostDraw(t,e){}showDebug(t){this._isDebug=t}toggleDebug(){return this._isDebug=!this._isDebug,this._isDebug}get loadingComplete(){return this._loadingComplete}get ready(){return this._isReady}isReady(){return this._isReadyPromise}async start(t){if(!this._compatible)throw new Error("Excalibur is incompatible with your browser");return t&&(this.screen.pushResolutionAndViewport(),this.screen.resolution=this.screen.viewport,this.screen.applyResolutionAndViewport(),this._loader=t,this._loader.suppressPlayButton=this._suppressPlayButton||this._loader.suppressPlayButton,this._loader.wireEngine(this)),this._logger.debug("Starting game clock..."),this.browser.resume(),this.clock.start(),this._logger.debug("Game clock started"),t&&(await this.load(this._loader),this._loadingComplete=!0,this.screen.popResolutionAndViewport(),this.screen.applyResolutionAndViewport()),this._loadingComplete=!0,this._overrideInitialize(this),this._isReady=!0,this._isReadyResolve(),this.emit("start",new It(this)),this._isReadyPromise}_mainloop(t){this.emit("preframe",new zt(this,this.stats.prevFrame));const e=t*this.timescale,i=this.stats.prevFrame.id+1;this.stats.currFrame.reset(),this.stats.currFrame.id=i,this.stats.currFrame.delta=e,this.stats.currFrame.fps=this.clock.fpsSampler.fps,je.clear();const s=this.clock.now();this._update(e);const r=this.clock.now();this._draw(e);const n=this.clock.now();this.stats.currFrame.duration.update=r-s,this.stats.currFrame.duration.draw=n-r,this.stats.currFrame.graphics.drawnImages=je.DrawnImagesCount,this.stats.currFrame.graphics.drawCalls=je.DrawCallCount,this.emit("postframe",new Ot(this,this.stats.currFrame)),this.stats.prevFrame.reset(this.stats.currFrame)}static createMainLoop(t,e,i){let s=i();const r=new _n({nowFn:i,initialFps:t.maxFps===1/0?60:t.maxFps});return function n(){if(t._hasStarted)try{t._requestId=e(n),r.start(),t.emit("preframe",new zt(t,t.stats.prevFrame));const o=i();let a=o-s||1;const h=t.maxFps===Number.POSITIVE_INFINITY?0:1e3/t.maxFps;if(a<=h)return;a>200&&(a=1);const l=a*t.timescale,c=t.stats.prevFrame.id+1;t.stats.currFrame.reset(),t.stats.currFrame.id=c,t.stats.currFrame.delta=l,t.stats.currFrame.fps=r.fps;const d=i();t._update(l);const u=i();t._draw(l);const p=i();t.stats.currFrame.duration.update=u-d,t.stats.currFrame.duration.draw=p-u,s=h>0?o-a%h:o,t.emit("postframe",new Ot(t,t.stats.currFrame)),r.end(),t.stats.prevFrame.reset(t.stats.currFrame)}catch(e){window.cancelAnimationFrame(t._requestId),t.stop(),t.onFatalException(e)}}}stop(){this.clock.isRunning()&&(this.emit("stop",new Rt(this)),this.browser.pause(),this.clock.stop(),this._logger.debug("Game stopped"))}isPaused(){return!this.clock.isRunning()}isRunning(){return this.clock.isRunning()}screenshot(t=!1){return new Promise((e=>{this._screenShotRequests.push({preserveHiDPIResolution:t,resolve:e})}))}_checkForScreenShots(){for(const t of this._screenShotRequests){const e=t.preserveHiDPIResolution?this.canvas.width:this.screen.resolution.width,i=t.preserveHiDPIResolution?this.canvas.height:this.screen.resolution.height,s=document.createElement("canvas");s.width=e,s.height=i;s.getContext("2d").drawImage(this.canvas,0,0,e,i);const r=new Image,n=s.toDataURL("image/png");r.src=n,t.resolve(r)}this._screenShotRequests.length=0}async load(t){try{await t.load()}catch(t){await Promise.resolve()}}}xn._DEFAULT_ENGINE_OPTIONS={width:0,height:0,enableCanvasTransparency:!0,canvasElementId:"",canvasElement:void 0,snapToPixel:!1,pointerScope:jr.Canvas,suppressConsoleBootMessage:null,suppressMinimumBrowserFeatureDetection:null,suppressHiDPIScaling:null,suppressPlayButton:null,scrollPreventionMode:yn.Canvas,backgroundColor:I.fromHex("#2185d0")},wn([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Actor.graphics"})],xn.prototype,"playAnimation",null);let bn=class{constructor(t,e,i){this.animation=t,this.x=e,this.y=i}};bn=wn([C({message:"Will be removed in excalibur v0.26.0"})],bn);class Cn extends At{constructor(t,e="MediaEvent"){super(),this.target=t,this._name=e}set bubbles(t){}get bubbles(){return!1}get _path(){return null}set _path(t){}stopPropagation(){}action(){}propagate(){}layPath(t){}}class Sn extends Cn{constructor(t,e){super(t,"NativeSoundEvent"),this.track=e}}class An extends Cn{constructor(t,e){super(t,"NativeSoundProcessedEvent"),this._processedData=e,this.data=this._processedData}}var Pn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class Tn extends Us{constructor(t){super(t),this._font=new Ls,this._text=new zs({text:"",font:this._font}),this.letterSpacing=0,this.caseInsensitive=!0;const{text:e,pos:i,x:s,y:r,spriteFont:n,font:o,color:a}=t;this.pos=null!=i?i:s&&r?P(s,r):this.pos,this.text=null!=e?e:this.text,this.font=null!=o?o:this.font,this.spriteFont=null!=n?n:this.spriteFont,this._text.color=null!=a?a:this.color;const h=this.get(cs);h.anchor=A.Zero,h.use(this._text)}get font(){return this._font}set font(t){this._font=t,this._text.font=t}get text(){return this._text.text}set text(t){this._text.text=t}get color(){return this._text.color}set color(t){this._text&&(this._text.color=t)}get opacity(){return this._text.opacity}set opacity(t){this._text.opacity=t}get bold(){return this.font.bold}set bold(t){this.font.bold=t}get fontFamily(){return this.font.family}set fontFamily(t){this.font.family=t}get fontSize(){return this.font.size}set fontSize(t){this.font.size=t}get fontStyle(){return this.font.style}set fontStyle(t){this.font.style=t}get fontUnit(){return this.font.unit}set fontUnit(t){this.font.unit=t}get textAlign(){return this.font.textAlign}set textAlign(t){this.font.textAlign=t}get baseAlign(){return this.font.baseAlign}set baseAlign(t){this.font.baseAlign=t}get spriteFont(){return this._legacySpriteFont}set spriteFont(t){if(t){if(t instanceof ze)return this._legacySpriteFont=t,this._spriteFont=Ue.fromLegacySpriteFont(t),void(this._text.font=this._spriteFont);this._spriteFont=t,this._text.font=this._spriteFont}}_initialize(t){super._initialize(t),this._graphicsContext=t.graphicsContext}getTextWidth(){return this._text.width}setTextShadow(t,e,i){this.font.shadow={offset:P(t,e),blur:2,color:i}}useTextShadow(t){this.spriteFont&&this.spriteFont.useTextShadow(t)}clearTextShadow(){this.font.shadow=null}draw(t,e){const i=this._graphicsContext;this._text.draw(i,0,0)}}Pn([C({message:"Label.bold will be removed in v0.26.0",alternateMethod:"Use Label.font.bold"})],Tn.prototype,"bold",null),Pn([C({message:"Label.fontFamily will be removed in v0.26.0",alternateMethod:"Use Label.font.family"})],Tn.prototype,"fontFamily",null),Pn([C({message:"Label.fontSize will be removed in v0.26.0",alternateMethod:"Use Label.font.size"})],Tn.prototype,"fontSize",null),Pn([C({message:"Label.fontStyle will be removed in v0.26.0",alternateMethod:"Use Label.font.style"})],Tn.prototype,"fontStyle",null),Pn([C({message:"Label.fontUnit will be removed in v0.26.0",alternateMethod:"Use Label.font.unit"})],Tn.prototype,"fontUnit",null),Pn([C({message:"Label.textAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.textAlign"})],Tn.prototype,"textAlign",null),Pn([C({message:"Label.baseAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.baseAlign"})],Tn.prototype,"baseAlign",null),Pn([C({message:"Label.setTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"setTextShadow",null),Pn([C({message:"Label.useTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"useTextShadow",null),Pn([C({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Tn.prototype,"clearTextShadow",null);class En{static create(t,e){if(this._CURRENT_GROUP>this._MAX_GROUPS)throw new Error(`Cannot have more than ${this._MAX_GROUPS} collision groups`);if(this._GROUPS.get(t))throw new Error(`Collision group ${t} already exists`);const i=new Ri(t,this._CURRENT_BIT,void 0!==e?e:~this._CURRENT_BIT);return this._CURRENT_BIT=this._CURRENT_BIT<<1|0,this._CURRENT_GROUP++,this._GROUPS.set(t,i),i}static get groups(){return Array.from(this._GROUPS.values())}static groupByName(t){return this._GROUPS.get(t)}static reset(){this._GROUPS=new Map,this._CURRENT_BIT=this._STARTING_BIT,this._CURRENT_GROUP=1}}En._STARTING_BIT=1,En._MAX_GROUPS=32,En._CURRENT_GROUP=1,En._CURRENT_BIT=En._STARTING_BIT,En._GROUPS=new Map;var In=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let Rn=class{constructor(t){this.lineWidth=5,this.filled=!1,this._points=[],this.anchor=A.Zero,this.offset=A.Zero,this.rotation=0,this.scale=A.One,this.opacity=1,this._points=t;const e=this._points.reduce(((t,e)=>Math.min(t,e.x)),0),i=this._points.reduce(((t,e)=>Math.max(t,e.x)),0);this.drawWidth=i-e;const s=this._points.reduce(((t,e)=>Math.min(t,e.y)),0),r=this._points.reduce(((t,e)=>Math.max(t,e.y)),0);this.drawHeight=r-s,this.height=this.drawHeight,this.width=this.drawWidth}addEffect(){}removeEffect(){}clearEffects(){}reset(){}draw(t,e,i){t instanceof CanvasRenderingContext2D?this._drawWithOptions({ctx:t,x:e,y:i}):this._drawWithOptions(t)}_drawWithOptions(t){var e,i,s,r,n,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:v,flipHorizontal:y,flipVertical:w}={...t,rotation:null!==(e=t.rotation)&&void 0!==e?e:this.rotation,drawWidth:null!==(i=t.drawWidth)&&void 0!==i?i:this.drawWidth,drawHeight:null!==(s=t.drawHeight)&&void 0!==s?s:this.drawHeight,flipHorizontal:null!==(r=t.flipHorizontal)&&void 0!==r?r:this.flipHorizontal,flipVertical:null!==(n=t.flipVertical)&&void 0!==n?n:this.flipVertical,anchor:null!==(o=t.anchor)&&void 0!==o?o:this.anchor,offset:null!==(a=t.offset)&&void 0!==a?a:this.offset,opacity:(null!==(h=t.opacity)&&void 0!==h?h:1)*(null!==(l=this.opacity)&&void 0!==l?l:1)},x=g*f.x+m.x+d,b=_*f.y+m.y+u;c.save(),c.translate(x,b),c.scale(this.scale.x,this.scale.y),c.rotate(p),c.beginPath(),c.lineWidth=this.lineWidth;const C=this._points[0];c.moveTo(C.x,C.y);let S=0;const A=this._points.length;for(;S<A;S++)c.lineTo(this._points[S].x,this._points[S].y);c.lineTo(C.x,C.y),c.closePath(),this.filled&&(c.fillStyle=this.fillColor.toString(),c.fill()),c.strokeStyle=this.lineColor.toString(),y&&(c.translate(g,0),c.scale(-1,1)),w&&(c.translate(0,_),c.scale(1,-1));const P=c.globalAlpha;c.globalAlpha=v,c.stroke(),c.globalAlpha=P,c.restore()}};Rn=In([C({message:"Polygon will be removed in v0.26.0",alternateMethod:"Use Graphics.Polygon"})],Rn);class Dn{}function Bn(t){return!!t._initialize}function Mn(t){return!!t.onInitialize}function kn(t){return!!t._preupdate}function Fn(t){return!!t.onPreUpdate}function Ln(t){return!!t.onPostUpdate}function zn(t){return!!t.onPostUpdate}function On(t){return!!t.onPreDraw}function Un(t){return!!t.onPostDraw}Dn.type={any:"",blob:"blob",json:"json",text:"text",document:"document",arraybuffer:"arraybuffer"};class Nn{constructor(t){this._src=t,this._volume=1,this._duration=void 0,this._loop=!1,this._isPlaying=!1,this._isPaused=!1,this._audioContext=oi.create(),this._volumeNode=this._audioContext.createGain(),this._currentOffset=0,this._createNewBufferSource()}set loop(t){this._loop=t,this._instance&&(this._instance.loop=t,this._wireUpOnEnded())}get loop(){return this._loop}set volume(t){t=z(t,0,1),this._volume=t,this._isPlaying&&this._volumeNode.gain.setTargetAtTime?this._volumeNode.gain.setTargetAtTime(t,this._audioContext.currentTime,.1):this._volumeNode.gain.value=t}get volume(){return this._volume}set duration(t){this._duration=t}get duration(){return this._duration}get _playbackRate(){return this._instance?1/(this._instance.playbackRate.value||1):null}isPlaying(){return this._isPlaying}play(t=(()=>{})){return this._isPaused&&(this._resumePlayBack(),t()),this._isPlaying||(this._startPlayBack(),t()),this._playingPromise}pause(){this._isPlaying&&(this._isPaused=!0,this._isPlaying=!1,this._instance.stop(0),this._setPauseOffset())}stop(){this._isPlaying&&(this._isPlaying=!1,this._isPaused=!1,this._currentOffset=0,this._instance.stop(0),this._instance.onended||this._handleOnEnded())}_startPlayBack(){this._isPlaying=!0,this._isPaused=!1,this._playingPromise=new Promise((t=>{this._playingResolve=t})),this._instance||this._createNewBufferSource(),this._rememberStartTime(),this._volumeNode.connect(this._audioContext.destination),this._instance.start(0,0),this._currentOffset=0,this._wireUpOnEnded()}_resumePlayBack(){if(!this._isPaused)return;this._isPaused=!1,this._isPlaying=!0,this._instance.onended=null,this._createNewBufferSource();const t=this._playbackRate*this._src.duration,e=this._currentOffset%t;this._rememberStartTime(-1e3*e),this._instance.start(0,e),this._wireUpOnEnded()}_wireUpOnEnded(){this.loop||(this._instance.onended=()=>this._handleOnEnded())}_handleOnEnded(){this._isPaused||(this._isPlaying=!1,this._playingResolve(!0))}_rememberStartTime(t){this._startTime=(new Date).getTime()+(0|t)}_setPauseOffset(){this._currentOffset=((new Date).getTime()-this._startTime)*this._playbackRate/1e3}_createNewBufferSource(){this._instance=this._audioContext.createBufferSource(),this._instance.buffer=this._src,this._instance.loop=this.loop,this._instance.playbackRate.setValueAtTime(1,0),this._instance.connect(this._volumeNode)}}function Hn(t){try{const e=new Audio,i=/.*\.([A-Za-z0-9]+)$/,s=t.match(i)[1];return!!e.canPlayType("audio/"+s)}catch(t){return f.getInstance().warn("Cannot determine audio support, assuming no support for the Audio Tag",t),!1}}class Wn extends hi{constructor(...t){super(),this.logger=f.getInstance(),this._loop=!1,this._volume=1,this._duration=void 0,this._isStopped=!1,this._isPaused=!1,this._tracks=[],this._wasPlayingOnHidden=!1,this._audioContext=oi.create(),this._resource=new le("",Dn.type.arraybuffer);for(const e of t)if(Hn(e)){this.path=e;break}this.path||(this.logger.warn("This browser does not support any of the audio files specified:",t.join(", ")),this.logger.warn("Attempting to use",t[0]),this.path=t[0])}set loop(t){this._loop=t;for(const t of this._tracks)t.loop=this._loop;this.logger.debug("Set loop for all instances of sound",this.path,"to",this._loop)}get loop(){return this._loop}set volume(t){this._volume=t;for(const t of this._tracks)t.volume=this._volume;this.emit("volumechange",new Sn(this)),this.logger.debug("Set loop for all instances of sound",this.path,"to",this._volume)}get volume(){return this._volume}get duration(){return this._duration}get instances(){return this._tracks}get path(){return this._resource.path}set path(t){this._resource.path=t}isLoaded(){return!!this.data}async load(){if(this.data)return this.data;const t=await this._resource.load(),e=await this.decodeAudio(t.slice(0));return this._duration="object"==typeof e?e.duration:void 0,this.emit("processed",new An(this,e)),this.data=e}async decodeAudio(t){try{return await this._audioContext.decodeAudioData(t.slice(0))}catch(t){return this.logger.error("Unable to decode this browser may not fully support this format, or the file may be corrupt, if this is an mp3 try removing id3 tags and album art from the file."),await Promise.reject()}}wireEngine(t){t&&(this._engine=t,this._engine.on("hidden",(()=>{t.pauseAudioWhenHidden&&this.isPlaying()&&(this._wasPlayingOnHidden=!0,this.pause())})),this._engine.on("visible",(()=>{t.pauseAudioWhenHidden&&this._wasPlayingOnHidden&&(this.play(),this._wasPlayingOnHidden=!1)})),this._engine.on("start",(()=>{this._isStopped=!1})),this._engine.on("stop",(()=>{this.stop(),this._isStopped=!0})))}instanceCount(){return this._tracks.length}isPlaying(){return this._tracks.some((t=>t.isPlaying()))}play(t){return this.isLoaded()?this._isStopped?(this.logger.warn("Cannot start playing. Engine is in a stopped state."),Promise.resolve(!1)):(this.volume=t||this.volume,this._isPaused?this._resumePlayback():this._startPlayback()):(this.logger.warn("Cannot start playing. Resource",this.path,"is not loaded yet"),Promise.resolve(!0))}pause(){if(this.isPlaying()){for(const t of this._tracks)t.pause();this._isPaused=!0,this.emit("pause",new Sn(this)),this.logger.debug("Paused all instances of sound",this.path)}}stop(){for(const t of this._tracks)t.stop();this.emit("stop",new Sn(this)),this._isPaused=!1,this._tracks.length=0,this.logger.debug("Stopped all instances of sound",this.path)}getTrackId(t){return this._tracks.indexOf(t)}async _resumePlayback(){if(this._isPaused){const t=[];for(const e of this._tracks)t.push(e.play());this._isPaused=!1,this.emit("resume",new Sn(this)),this.logger.debug("Resuming paused instances for sound",this.path,this._tracks),await Promise.all(t)}return!0}async _startPlayback(){const t=await this._getTrackInstance(this.data),e=await t.play((()=>{this.emit("playbackstart",new Sn(this,t)),this.logger.debug("Playing new instance for sound",this.path)}));return this.emit("playbackend",new Sn(this,t)),this._tracks.splice(this.getTrackId(t),1),e}_getTrackInstance(t){const e=new Nn(t);return e.loop=this.loop,e.volume=this.volume,e.duration=this.duration,this._tracks.push(e),e}}class Gn{constructor(t,e=I.Magenta,i=!0){this.path=t,this.color=e,this.bustCache=i,this._stream=null,this._gif=null,this._textures=[],this._animation=null,this._transparentColor=null,this._resource=new le(t,"arraybuffer",i),this._transparentColor=e}async load(){const t=await this._resource.load();this._stream=new qn(t),this._gif=new jn(this._stream,this._transparentColor);const e=this._gif.images.map((t=>new Pe(t.src,!1)));return await Promise.all(e.map((t=>t.load()))),this.data=this._textures=e}isLoaded(){return!!this.data}toLegacySprite(t=0){return Ae.toLegacySprite(this.toSprite(t))}toLegacySpriteSheet(){return Oe.toLegacySpriteSheet(this.toSpriteSheet())}toLegacyAnimation(t,e){return Er.toLegacyAnimation(t,this.toAnimation(e))}toSprite(t=0){return this._textures[t].toSprite()}toSpriteSheet(){const t=this._textures.map((t=>t.toSprite()));return new Oe({sprites:t})}toAnimation(t){const e=this.toSpriteSheet(),i=e.sprites.length;return this._animation=Er.fromSpriteSheet(e,H(0,i),t),this._animation}get readCheckBytes(){return this._gif.checkBytes}}const Vn=t=>t.reduce((function(t,e){return 2*t+e}),0),Xn=t=>{const e=[];for(let i=7;i>=0;i--)e.push(!!(t&1<<i));return e};class qn{constructor(t){if(this.data=null,this.len=0,this.position=0,this.readByte=()=>{if(this.position>=this.data.byteLength)throw new Error("Attempted to read past end of stream.");return this.data[this.position++]},this.readBytes=t=>{const e=[];for(let i=0;i<t;i++)e.push(this.readByte());return e},this.read=t=>{let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.readByte());return e},this.readUnsigned=()=>{const t=this.readBytes(2);return(t[1]<<8)+t[0]},this.data=new Uint8Array(t),this.len=this.data.byteLength,0===this.len)throw new Error("No data loaded from file")}}class jn{constructor(t,e=I.Magenta){this._st=null,this._handler={},this._transparentColor=null,this.frames=[],this.images=[],this.globalColorTable=[],this.checkBytes=[],this.parseColorTable=t=>{const e=[];for(let i=0;i<t;i++){const t="#"+this._st.readBytes(3).map((t=>{const e=t.toString(16);return 1===e.length?"0"+e:e})).join("");e.push(t)}return e},this.readSubBlocks=()=>{let t,e;e="";do{t=this._st.readByte(),e+=this._st.read(t)}while(0!==t);return e},this.parseHeader=()=>{const t={sig:null,ver:null,width:null,height:null,colorRes:null,globalColorTableSize:null,gctFlag:null,sorted:null,globalColorTable:[],bgColor:null,pixelAspectRatio:null};if(t.sig=this._st.read(3),t.ver=this._st.read(3),"GIF"!==t.sig)throw new Error("Not a GIF file.");t.width=this._st.readUnsigned(),t.height=this._st.readUnsigned();const e=Xn(this._st.readByte());t.gctFlag=e.shift(),t.colorRes=Vn(e.splice(0,3)),t.sorted=e.shift(),t.globalColorTableSize=Vn(e.splice(0,3)),t.bgColor=this._st.readByte(),t.pixelAspectRatio=this._st.readByte(),t.gctFlag&&(t.globalColorTable=this.parseColorTable(1<<t.globalColorTableSize+1),this.globalColorTable=t.globalColorTable),this._handler.hdr&&this._handler.hdr(t)&&this.checkBytes.push(this._handler.hdr)},this.parseExt=t=>{const e=t=>{this.checkBytes.push(this._st.readByte());const e=Xn(this._st.readByte());t.reserved=e.splice(0,3),t.disposalMethod=Vn(e.splice(0,3)),t.userInput=e.shift(),t.transparencyGiven=e.shift(),t.delayTime=this._st.readUnsigned(),t.transparencyIndex=this._st.readByte(),t.terminator=this._st.readByte(),this._handler.gce&&this._handler.gce(t)&&this.checkBytes.push(this._handler.gce)},i=t=>{t.comment=this.readSubBlocks(),this._handler.com&&this._handler.com(t)&&this.checkBytes.push(this._handler.com)},s=t=>{this.checkBytes.push(this._st.readByte()),t.ptHeader=this._st.readBytes(12),t.ptData=this.readSubBlocks(),this._handler.pte&&this._handler.pte(t)&&this.checkBytes.push(this._handler.pte)},r=t=>{const e=t=>{this.checkBytes.push(this._st.readByte()),t.unknown=this._st.readByte(),t.iterations=this._st.readUnsigned(),t.terminator=this._st.readByte(),this._handler.app&&this._handler.app.NETSCAPE&&this._handler.app.NETSCAPE(t)&&this.checkBytes.push(this._handler.app)},i=t=>{t.appData=this.readSubBlocks(),this._handler.app&&this._handler.app[t.identifier]&&this._handler.app[t.identifier](t)&&this.checkBytes.push(this._handler.app[t.identifier])};if(this.checkBytes.push(this._st.readByte()),t.identifier=this._st.read(8),t.authCode=this._st.read(3),"NETSCAPE"===t.identifier)e(t);else i(t)},n=t=>{t.data=this.readSubBlocks(),this._handler.unknown&&this._handler.unknown(t)&&this.checkBytes.push(this._handler.unknown)};switch(t.label=this._st.readByte(),t.label){case 249:t.extType="gce",e(t);break;case 254:t.extType="com",i(t);break;case 1:t.extType="pte",s(t);break;case 255:t.extType="app",r(t);break;default:t.extType="unknown",n(t)}},this.parseImg=t=>{t.leftPos=this._st.readUnsigned(),t.topPos=this._st.readUnsigned(),t.width=this._st.readUnsigned(),t.height=this._st.readUnsigned();const e=Xn(this._st.readByte());t.lctFlag=e.shift(),t.interlaced=e.shift(),t.sorted=e.shift(),t.reserved=e.splice(0,2),t.lctSize=Vn(e.splice(0,3)),t.lctFlag&&(t.lct=this.parseColorTable(1<<t.lctSize+1)),t.lzwMinCodeSize=this._st.readByte();const i=this.readSubBlocks();t.pixels=function(t,e){let i=0;const s=function(t){let s=0;for(let r=0;r<t;r++)e.charCodeAt(i>>3)&1<<(7&i)&&(s|=1<<r),i++;return s},r=[],n=1<<t,o=n+1;let a=t+1,h=[];const l=function(){h=[],a=t+1;for(let t=0;t<n;t++)h[t]=[t];h[n]=[],h[o]=null};let c,d;for(;;)if(d=c,c=s(a),c!==n){if(c===o)break;if(c<h.length)d!==n&&h.push(h[d].concat(h[c][0]));else{if(c!==h.length)throw new Error("Invalid LZW code.");h.push(h[d].concat(h[d][0]))}r.push.apply(r,h[c]),h.length===1<<a&&a<12&&a++}else l();return r}(t.lzwMinCodeSize,i),t.interlaced&&(t.pixels=((t,e)=>{const i=new Array(t.length),s=t.length/e,r=(s,r)=>{const n=t.slice(r*e,(r+1)*e);i.splice.apply(i,[s*e,e].concat(n))},n=[0,4,2,1],o=[8,8,4,2];let a=0;for(let t=0;t<4;t++)for(let e=n[t];e<s;e+=o[t])r(e,a),a++;return i})(t.pixels,t.width)),this.frames.push(t),this.arrayToImage(t),this._handler.img&&this._handler.img(t)&&this.checkBytes.push(this._handler)},this.parseBlock=()=>{const t={sentinel:this._st.readByte(),type:""};switch(String.fromCharCode(t.sentinel)){case"!":t.type="ext",this.parseExt(t);break;case",":t.type="img",this.parseImg(t);break;case";":t.type="eof",this._handler.eof&&this._handler.eof(t)&&this.checkBytes.push(this._handler.eof);break;default:throw new Error("Unknown block: 0x"+t.sentinel.toString(16))}"eof"!==t.type&&this.parseBlock()},this.arrayToImage=t=>{let e=0;const i=document.createElement("canvas");i.id=e.toString(),i.width=t.width,i.height=t.height,e++;const s=i.getContext("2d");let r=0,n=0;for(let e=0;e<t.pixels.length;e++)n%t.width==0&&(r++,n=0),this.globalColorTable[t.pixels[e]]===this._transparentColor.toHex()?s.fillStyle="rgba(0, 0, 0, 0)":s.fillStyle=this.globalColorTable[t.pixels[e]],s.fillRect(n,r,1,1),n++;const o=new Image;o.src=i.toDataURL(),this.images.push(o)},this._st=t,this._handler={},this._transparentColor=e,this.parseHeader(),this.parseBlock()}}class Kn extends Ct{constructor(t){super(t),this.points=t.points,this.filtering=ht.Blended,this.rasterize()}get points(){return this._points}set points(t){this._points=t;const e=this.minPoint;this.width=this._points.reduce(((t,e)=>Math.max(e.x,t)),0)-e.x,this.height=this._points.reduce(((t,e)=>Math.max(e.y,t)),0)-e.y,this.flagDirty()}get minPoint(){return P(this._points.reduce(((t,e)=>Math.min(e.x,t)),1/0),this._points.reduce(((t,e)=>Math.min(e.y,t)),1/0))}clone(){return new Kn({points:this.points.map((t=>t.clone())),...this.cloneGraphicOptions(),...this.cloneRasterOptions()})}execute(t){if(this.points&&this.points.length){t.beginPath();const e=this.minPoint.negate(),i=this.points[0].add(e);t.moveTo(i.x,i.y),this.points.forEach((i=>{t.lineTo(i.x+e.x,i.y+e.y)})),t.lineTo(i.x,i.y),t.closePath(),this.color&&t.fill(),this.strokeColor&&t.stroke()}}}var Zn=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};let Yn=class{constructor(t){this._getComparable=t}find(t){return this._find(this._root,t)}_find(t,e){return null!=t&&(this._getComparable(e)===t.getKey()?t.getData().indexOf(e)>-1:this._getComparable(e)<t.getKey()?this._find(t.getLeft(),e):this._find(t.getRight(),e))}get(t){return this._get(this._root,t)}_get(t,e){return null==t?[]:e===t.getKey()?t.getData():e<t.getKey()?this._get(t.getLeft(),e):this._get(t.getRight(),e)}add(t){return null==this._root?(this._root=new Qn(this._getComparable(t),[t],null,null),!0):this._insert(this._root,t)}_insert(t,e){return null!=t&&(this._getComparable(e)===t.getKey()?!(t.getData().indexOf(e)>-1)&&(t.getData().push(e),!0):this._getComparable(e)<t.getKey()?null==t.getLeft()?(t.setLeft(new Qn(this._getComparable(e),[e],null,null)),!0):this._insert(t.getLeft(),e):null==t.getRight()?(t.setRight(new Qn(this._getComparable(e),[e],null,null)),!0):this._insert(t.getRight(),e))}removeByComparable(t){this._root=this._remove(this._root,t)}_remove(t,e){if(null==t)return null;if(this._getComparable(e)!==t.getKey())return this._getComparable(e)<t.getKey()?(t.setLeft(this._remove(t.getLeft(),e)),t):(t.setRight(this._remove(t.getRight(),e)),t);{const i=t.getData().indexOf(e);if(i>-1){if(t.getData().splice(i,1),0===t.getData().length){if(null==t.getLeft()&&null==t.getRight())return null;if(null==t.getLeft())return t.getRight();if(null==t.getRight())return t.getLeft();const e=this._findMinNode(t.getRight());return t.setKey(e.getKey()),t.setData(e.getData()),t.setRight(this._cleanup(t.getRight(),e)),t}return t}}return null}_cleanup(t,e){const i=e.getKey();if(null==t)return null;if(i===t.getKey()){if(null==t.getLeft()&&null==t.getRight())return null;if(null==t.getLeft())return t.getRight();if(null==t.getRight())return t.getLeft();const e=this._findMinNode(t.getRight());return t.setKey(e.getKey()),t.setData(e.getData()),t.setRight(this._cleanup(t.getRight(),e)),t}return e.getKey()<t.getKey()?(t.setLeft(this._cleanup(t.getLeft(),e)),t):(t.setRight(this._cleanup(t.getRight(),e)),t)}_findMinNode(t){let e=t;for(;null!=e.getLeft();)e=e.getLeft();return e}list(){const t=new Array;return this._list(this._root,t),t}_list(t,e){null!=t&&(this._list(t.getLeft(),e),t.getData().forEach((t=>{e.push(t)})),this._list(t.getRight(),e))}};Yn=Zn([C({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use built in JS array.sort"})],Yn);let Qn=class{constructor(t,e,i,s){this._key=t,this._data=e,this._left=i,this._right=s}getKey(){return this._key}setKey(t){this._key=t}getData(){return this._data}setData(t){this._data=t}getLeft(){return this._left}setLeft(t){this._left=t}getRight(){return this._right}setRight(t){this._right=t}};Qn=Zn([C({message:"Will be removed in excalibur v0.26.0"})],Qn);class $n{constructor(t){this._key=0,this._key=t}getTheKey(){return this._key}setKey(t){this._key=t}}class Jn{constructor(t,e,i=100){this.builder=t,this.recycler=e,this.maxObjects=i,this.totalAllocations=0,this.index=0,this.objects=[],this._logger=f.getInstance()}using(t){const e=t(this);return e?this.done(...e):this.done()}borrow(t){t(this.get()),this.index--}get(...t){if(this.index===this.maxObjects&&(this._logger.warn("Max pooled objects reached, possible memory leak? Doubling"),this.maxObjects=2*this.maxObjects),this.objects[this.index])return this.recycler(this.objects[this.index++],...t);this.totalAllocations++;return this.objects[this.index++]=this.builder(...t)}done(...t){this.index=0;for(const e of t){const t=this.objects.indexOf(e);this.objects[t]=this.builder(),this.totalAllocations++}return t}}var to,eo,io=function(t,e,i,s){var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};!function(t){t[t.Resolved=0]="Resolved",t[t.Rejected=1]="Rejected",t[t.Pending=2]="Pending"}(eo||(eo={}));let so=to=class{constructor(){this._state=eo.Pending,this._successCallbacks=[],this._rejectCallback=()=>{}}static resolve(t){return(new to).resolve(t)}static reject(t){return(new to).reject(t)}static join(){let t=[];if(arguments.length>0&&!Array.isArray(arguments[0]))for(let e=0;e<arguments.length;e++)t[e-0]=arguments[e];else 1===arguments.length&&Array.isArray(arguments[0])&&(t=arguments[0]);const e=new to;if(!t||!t.length)return e.resolve();const i=t.length;let s=0,r=0;const n=[];return t.forEach((t=>{t.then((()=>{s+=1,s===i?e.resolve():s+r+n.length===i&&e.reject(n)}),(()=>{r+=1,s+r+n.length===i&&e.reject(n)})).error((t=>{n.push(t),n.length+s+r===i&&e.reject(n)}))})),e}then(t,e){if(t&&(this._successCallbacks.push(t),this.state()===eo.Resolved))try{t.call(this,this._value)}catch(t){this._handleError(t)}if(e&&(this._rejectCallback=e,this.state()===eo.Rejected))try{e.call(this,this._value)}catch(t){this._handleError(t)}return this}error(t){return t&&(this._errorCallback=t),this}resolve(t){if(this._state!==eo.Pending)throw new Error("Cannot resolve a promise that is not in a pending state!");this._value=t;try{this._state=eo.Resolved,this._successCallbacks.forEach((t=>{t.call(this,this._value)}))}catch(t){this._handleError(t)}return this}reject(t){if(this._state!==eo.Pending)throw new Error("Cannot reject a promise that is not in a pending state!");this._value=t;try{this._state=eo.Rejected,this._rejectCallback.call(this,this._value)}catch(t){this._handleError(t)}return this}state(){return this._state}_handleError(t){if(!this._errorCallback)throw t;this._errorCallback.call(this,t)}};so=to=io([C({message:"ex.Promises are being replaced by native browser promises in v0.26.0",alternateMethod:"Use browser native promises"})],so);const ro="0.25.3";p()})(),s})()}));
|
|
3
3
|
//# sourceMappingURL=excalibur.min.js.map
|