excalibur 0.25.1 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/.nvmrc +1 -1
  2. package/CHANGELOG.md +119 -27
  3. package/README.md +0 -1
  4. package/build/dist/Actions/ActionsComponent.d.ts +1 -1
  5. package/build/dist/Actor.d.ts +46 -45
  6. package/build/dist/Camera.d.ts +10 -2
  7. package/build/dist/Class.d.ts +4 -5
  8. package/build/dist/Collision/BodyComponent.d.ts +6 -2
  9. package/build/dist/Collision/BoundingBox.d.ts +6 -0
  10. package/build/dist/Collision/ColliderComponent.d.ts +1 -4
  11. package/build/dist/Collision/Colliders/CircleCollider.d.ts +18 -2
  12. package/build/dist/Collision/Colliders/EdgeCollider.d.ts +1 -1
  13. package/build/dist/Collision/Colliders/SeparatingAxis.d.ts +2 -2
  14. package/build/dist/Collision/Detection/DynamicTreeCollisionProcessor.d.ts +4 -4
  15. package/build/dist/Collision/Detection/Pair.d.ts +5 -1
  16. package/build/dist/Collision/Group/CollisionGroup.d.ts +0 -1
  17. package/build/dist/Collision/MotionSystem.d.ts +4 -0
  18. package/build/dist/Collision/Solver/ContactConstraintPoint.d.ts +1 -1
  19. package/build/dist/Collision/Solver/Solver.d.ts +1 -1
  20. package/build/dist/Debug/Debug.d.ts +18 -1
  21. package/build/dist/Debug/DebugFlags.d.ts +16 -3
  22. package/build/dist/Engine.d.ts +66 -8
  23. package/build/dist/EntityComponentSystem/Component.d.ts +3 -3
  24. package/build/dist/EntityComponentSystem/Components/MotionComponent.d.ts +2 -2
  25. package/build/dist/EntityComponentSystem/Entity.d.ts +4 -4
  26. package/build/dist/EntityComponentSystem/System.d.ts +1 -1
  27. package/build/dist/EntityComponentSystem/SystemManager.d.ts +6 -1
  28. package/build/dist/EventDispatcher.d.ts +0 -5
  29. package/build/dist/Events/ExEvent.d.ts +6 -0
  30. package/build/dist/Events/PointerEvents.d.ts +37 -0
  31. package/build/dist/Graphics/Animation.d.ts +3 -2
  32. package/build/dist/Graphics/Circle.d.ts +2 -0
  33. package/build/dist/Graphics/Context/ExcaliburGraphicsContext.d.ts +37 -5
  34. package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.d.ts +12 -2
  35. package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +29 -13
  36. package/build/dist/Graphics/Context/circle-renderer/circle-renderer.d.ts +22 -0
  37. package/build/dist/Graphics/Context/circle-renderer/circle-renderer.frag.glsl +53 -0
  38. package/build/dist/Graphics/Context/circle-renderer/circle-renderer.vert.glsl +37 -0
  39. package/build/dist/Graphics/Context/image-renderer/image-renderer.d.ts +27 -0
  40. package/build/dist/Graphics/Context/image-renderer/image-renderer.frag.glsl +28 -0
  41. package/build/dist/Graphics/Context/{shaders/image-vertex.glsl → image-renderer/image-renderer.vert.glsl} +2 -7
  42. package/build/dist/Graphics/Context/{shaders → line-renderer}/line-fragment.glsl +0 -0
  43. package/build/dist/Graphics/Context/line-renderer/line-renderer.d.ts +21 -0
  44. package/build/dist/Graphics/Context/{shaders → line-renderer}/line-vertex.glsl +2 -2
  45. package/build/dist/Graphics/Context/{shaders → point-renderer}/point-fragment.glsl +6 -2
  46. package/build/dist/Graphics/Context/point-renderer/point-renderer.d.ts +21 -0
  47. package/build/dist/Graphics/Context/{shaders → point-renderer}/point-vertex.glsl +2 -2
  48. package/build/dist/Graphics/Context/quad-index-buffer.d.ts +36 -0
  49. package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.d.ts +23 -0
  50. package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.frag.glsl +85 -0
  51. package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.vert.glsl +42 -0
  52. package/build/dist/Graphics/Context/render-source.d.ts +7 -0
  53. package/build/dist/Graphics/Context/render-target.d.ts +26 -0
  54. package/build/dist/Graphics/Context/renderer.d.ts +20 -51
  55. package/build/dist/Graphics/Context/screen-pass-painter/screen-fragment.glsl +11 -0
  56. package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.d.ts +13 -0
  57. package/build/dist/Graphics/Context/screen-pass-painter/screen-vertex.glsl +11 -0
  58. package/build/dist/Graphics/Context/shader.d.ts +116 -42
  59. package/build/dist/Graphics/Context/shaders/crt-effect.glsl +64 -0
  60. package/build/dist/Graphics/Context/shaders/grayscale-fragment.glsl +13 -0
  61. package/build/dist/Graphics/Context/shaders/invert-fragment.glsl +12 -0
  62. package/build/dist/Graphics/Context/texture-loader.d.ts +8 -2
  63. package/build/dist/Graphics/Context/vertex-buffer.d.ts +49 -0
  64. package/build/dist/Graphics/Context/vertex-layout.d.ts +52 -0
  65. package/build/dist/Graphics/Context/webgl-adapter.d.ts +9 -0
  66. package/build/dist/Graphics/Context/webgl-util.d.ts +22 -0
  67. package/build/dist/Graphics/DebugGraphicsComponent.d.ts +13 -0
  68. package/build/dist/Graphics/Filtering.d.ts +15 -0
  69. package/build/dist/Graphics/Font.d.ts +61 -23
  70. package/build/dist/Graphics/FontCommon.d.ts +43 -2
  71. package/build/dist/Graphics/Graphic.d.ts +23 -9
  72. package/build/dist/Graphics/GraphicsSystem.d.ts +0 -1
  73. package/build/dist/Graphics/ImageSource.d.ts +8 -3
  74. package/build/dist/Graphics/Polygon.d.ts +2 -0
  75. package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.d.ts +5 -0
  76. package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.d.ts +17 -0
  77. package/build/dist/Graphics/PostProcessor/PostProcessor.d.ts +7 -0
  78. package/build/dist/Graphics/PostProcessor/ScreenShader.d.ts +16 -0
  79. package/build/dist/Graphics/PostProcessor/color-blind-fragment.glsl +62 -0
  80. package/build/dist/Graphics/Raster.d.ts +32 -5
  81. package/build/dist/Graphics/Sprite.d.ts +5 -0
  82. package/build/dist/Graphics/SpriteFont.d.ts +6 -7
  83. package/build/dist/Graphics/SpriteSheet.d.ts +1 -2
  84. package/build/dist/Graphics/Text.d.ts +18 -2
  85. package/build/dist/Graphics/index.d.ts +14 -0
  86. package/build/dist/Id.d.ts +1 -1
  87. package/build/dist/Input/EngineInput.d.ts +2 -2
  88. package/build/dist/Input/Index.d.ts +10 -3
  89. package/build/dist/Input/NativePointerButton.d.ts +10 -0
  90. package/build/dist/Input/PointerAbstraction.d.ts +33 -0
  91. package/build/dist/Input/PointerButton.d.ts +10 -0
  92. package/build/dist/Input/PointerComponent.d.ts +24 -0
  93. package/build/dist/Input/PointerEvent.d.ts +18 -0
  94. package/build/dist/Input/PointerEventReceiver.d.ts +114 -0
  95. package/build/dist/Input/PointerScope.d.ts +14 -0
  96. package/build/dist/Input/PointerSystem.d.ts +43 -0
  97. package/build/dist/Input/PointerType.d.ts +9 -0
  98. package/build/dist/Input/WheelDeltaMode.d.ts +5 -0
  99. package/build/dist/Input/WheelEvent.d.ts +18 -0
  100. package/build/dist/Interfaces/PointerEventHandlers.d.ts +17 -16
  101. package/build/dist/Label.d.ts +9 -2
  102. package/build/dist/Loader.d.ts +5 -2
  103. package/build/dist/Math/Index.d.ts +1 -0
  104. package/build/dist/Math/matrix.d.ts +19 -1
  105. package/build/dist/Math/util.d.ts +45 -0
  106. package/build/dist/Particles.d.ts +12 -0
  107. package/build/dist/Resources/Gif.d.ts +1 -1
  108. package/build/dist/Scene.d.ts +10 -1
  109. package/build/dist/Screen.d.ts +4 -3
  110. package/build/dist/TileMap.d.ts +3 -2
  111. package/build/dist/Traits/Index.d.ts +0 -1
  112. package/build/dist/Trigger.d.ts +4 -0
  113. package/build/dist/Util/Clock.d.ts +118 -0
  114. package/build/dist/Util/Fps.d.ts +40 -0
  115. package/build/dist/Util/Observable.d.ts +1 -1
  116. package/build/dist/Util/Pool.d.ts +2 -10
  117. package/build/dist/Util/Util.d.ts +23 -66
  118. package/build/dist/excalibur.js +9124 -7580
  119. package/build/dist/excalibur.js.map +1 -1
  120. package/build/dist/excalibur.min.js +1 -1
  121. package/build/dist/excalibur.min.js.LICENSE.txt +2 -2
  122. package/build/dist/excalibur.min.js.map +1 -1
  123. package/build/dist/index.d.ts +5 -2
  124. package/build/esm/Actions/ActionsComponent.d.ts +1 -1
  125. package/build/esm/Actor.d.ts +46 -45
  126. package/build/esm/Camera.d.ts +10 -2
  127. package/build/esm/Class.d.ts +4 -5
  128. package/build/esm/Collision/BodyComponent.d.ts +6 -2
  129. package/build/esm/Collision/BoundingBox.d.ts +6 -0
  130. package/build/esm/Collision/ColliderComponent.d.ts +1 -4
  131. package/build/esm/Collision/Colliders/CircleCollider.d.ts +18 -2
  132. package/build/esm/Collision/Colliders/EdgeCollider.d.ts +1 -1
  133. package/build/esm/Collision/Colliders/SeparatingAxis.d.ts +2 -2
  134. package/build/esm/Collision/Detection/DynamicTreeCollisionProcessor.d.ts +4 -4
  135. package/build/esm/Collision/Detection/Pair.d.ts +5 -1
  136. package/build/esm/Collision/Group/CollisionGroup.d.ts +0 -1
  137. package/build/esm/Collision/MotionSystem.d.ts +4 -0
  138. package/build/esm/Collision/Solver/ContactConstraintPoint.d.ts +1 -1
  139. package/build/esm/Collision/Solver/Solver.d.ts +1 -1
  140. package/build/esm/Debug/Debug.d.ts +18 -1
  141. package/build/esm/Debug/DebugFlags.d.ts +16 -3
  142. package/build/esm/Engine.d.ts +66 -8
  143. package/build/esm/EntityComponentSystem/Component.d.ts +3 -3
  144. package/build/esm/EntityComponentSystem/Components/MotionComponent.d.ts +2 -2
  145. package/build/esm/EntityComponentSystem/Entity.d.ts +4 -4
  146. package/build/esm/EntityComponentSystem/System.d.ts +1 -1
  147. package/build/esm/EntityComponentSystem/SystemManager.d.ts +6 -1
  148. package/build/esm/EventDispatcher.d.ts +0 -5
  149. package/build/esm/Events/ExEvent.d.ts +6 -0
  150. package/build/esm/Events/PointerEvents.d.ts +37 -0
  151. package/build/esm/Graphics/Animation.d.ts +3 -2
  152. package/build/esm/Graphics/Circle.d.ts +2 -0
  153. package/build/esm/Graphics/Context/ExcaliburGraphicsContext.d.ts +37 -5
  154. package/build/esm/Graphics/Context/ExcaliburGraphicsContext2DCanvas.d.ts +12 -2
  155. package/build/esm/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +29 -13
  156. package/build/esm/Graphics/Context/circle-renderer/circle-renderer.d.ts +22 -0
  157. package/build/esm/Graphics/Context/image-renderer/image-renderer.d.ts +27 -0
  158. package/build/esm/Graphics/Context/line-renderer/line-renderer.d.ts +21 -0
  159. package/build/esm/Graphics/Context/point-renderer/point-renderer.d.ts +21 -0
  160. package/build/esm/Graphics/Context/quad-index-buffer.d.ts +36 -0
  161. package/build/esm/Graphics/Context/rectangle-renderer/rectangle-renderer.d.ts +23 -0
  162. package/build/esm/Graphics/Context/render-source.d.ts +7 -0
  163. package/build/esm/Graphics/Context/render-target.d.ts +26 -0
  164. package/build/esm/Graphics/Context/renderer.d.ts +20 -51
  165. package/build/esm/Graphics/Context/screen-pass-painter/screen-pass-painter.d.ts +13 -0
  166. package/build/esm/Graphics/Context/shader.d.ts +116 -42
  167. package/build/esm/Graphics/Context/texture-loader.d.ts +8 -2
  168. package/build/esm/Graphics/Context/vertex-buffer.d.ts +49 -0
  169. package/build/esm/Graphics/Context/vertex-layout.d.ts +52 -0
  170. package/build/esm/Graphics/Context/webgl-adapter.d.ts +9 -0
  171. package/build/esm/Graphics/Context/webgl-util.d.ts +22 -0
  172. package/build/esm/Graphics/DebugGraphicsComponent.d.ts +13 -0
  173. package/build/esm/Graphics/Filtering.d.ts +15 -0
  174. package/build/esm/Graphics/Font.d.ts +61 -23
  175. package/build/esm/Graphics/FontCommon.d.ts +43 -2
  176. package/build/esm/Graphics/Graphic.d.ts +23 -9
  177. package/build/esm/Graphics/GraphicsSystem.d.ts +0 -1
  178. package/build/esm/Graphics/ImageSource.d.ts +8 -3
  179. package/build/esm/Graphics/Polygon.d.ts +2 -0
  180. package/build/esm/Graphics/PostProcessor/ColorBlindnessMode.d.ts +5 -0
  181. package/build/esm/Graphics/PostProcessor/ColorBlindnessPostProcessor.d.ts +17 -0
  182. package/build/esm/Graphics/PostProcessor/PostProcessor.d.ts +7 -0
  183. package/build/esm/Graphics/PostProcessor/ScreenShader.d.ts +16 -0
  184. package/build/esm/Graphics/Raster.d.ts +32 -5
  185. package/build/esm/Graphics/Sprite.d.ts +5 -0
  186. package/build/esm/Graphics/SpriteFont.d.ts +6 -7
  187. package/build/esm/Graphics/SpriteSheet.d.ts +1 -2
  188. package/build/esm/Graphics/Text.d.ts +18 -2
  189. package/build/esm/Graphics/index.d.ts +14 -0
  190. package/build/esm/Id.d.ts +1 -1
  191. package/build/esm/Input/EngineInput.d.ts +2 -2
  192. package/build/esm/Input/Index.d.ts +10 -3
  193. package/build/esm/Input/NativePointerButton.d.ts +10 -0
  194. package/build/esm/Input/PointerAbstraction.d.ts +33 -0
  195. package/build/esm/Input/PointerButton.d.ts +10 -0
  196. package/build/esm/Input/PointerComponent.d.ts +24 -0
  197. package/build/esm/Input/PointerEvent.d.ts +18 -0
  198. package/build/esm/Input/PointerEventReceiver.d.ts +114 -0
  199. package/build/esm/Input/PointerScope.d.ts +14 -0
  200. package/build/esm/Input/PointerSystem.d.ts +43 -0
  201. package/build/esm/Input/PointerType.d.ts +9 -0
  202. package/build/esm/Input/WheelDeltaMode.d.ts +5 -0
  203. package/build/esm/Input/WheelEvent.d.ts +18 -0
  204. package/build/esm/Interfaces/PointerEventHandlers.d.ts +17 -16
  205. package/build/esm/Label.d.ts +9 -2
  206. package/build/esm/Loader.d.ts +5 -2
  207. package/build/esm/Math/Index.d.ts +1 -0
  208. package/build/esm/Math/matrix.d.ts +19 -1
  209. package/build/esm/Math/util.d.ts +45 -0
  210. package/build/esm/Particles.d.ts +12 -0
  211. package/build/esm/Resources/Gif.d.ts +1 -1
  212. package/build/esm/Scene.d.ts +10 -1
  213. package/build/esm/Screen.d.ts +4 -3
  214. package/build/esm/TileMap.d.ts +3 -2
  215. package/build/esm/Traits/Index.d.ts +0 -1
  216. package/build/esm/Trigger.d.ts +4 -0
  217. package/build/esm/Util/Clock.d.ts +118 -0
  218. package/build/esm/Util/Fps.d.ts +40 -0
  219. package/build/esm/Util/Observable.d.ts +1 -1
  220. package/build/esm/Util/Pool.d.ts +2 -10
  221. package/build/esm/Util/Util.d.ts +23 -66
  222. package/build/esm/excalibur.js +9001 -7438
  223. package/build/esm/excalibur.js.map +1 -1
  224. package/build/esm/excalibur.min.js +1 -1
  225. package/build/esm/excalibur.min.js.LICENSE.txt +2 -2
  226. package/build/esm/excalibur.min.js.map +1 -1
  227. package/build/esm/index.d.ts +5 -2
  228. package/package.json +31 -27
  229. package/build/dist/Graphics/Context/batch.d.ts +0 -11
  230. package/build/dist/Graphics/Context/draw-image-command.d.ts +0 -47
  231. package/build/dist/Graphics/Context/image-renderer.d.ts +0 -39
  232. package/build/dist/Graphics/Context/line-renderer.d.ts +0 -22
  233. package/build/dist/Graphics/Context/point-renderer.d.ts +0 -22
  234. package/build/dist/Graphics/Context/shaders/image-fragment.glsl +0 -48
  235. package/build/dist/Input/Pointer.d.ts +0 -134
  236. package/build/dist/Input/PointerEvents.d.ts +0 -170
  237. package/build/dist/Input/Pointers.d.ts +0 -78
  238. package/build/dist/PostProcessing/ColorBlindCorrector.d.ts +0 -28
  239. package/build/dist/PostProcessing/Index.d.ts +0 -2
  240. package/build/dist/PostProcessing/PostProcessor.d.ts +0 -6
  241. package/build/dist/Traits/CapturePointer.d.ts +0 -10
  242. package/build/esm/Graphics/Context/batch.d.ts +0 -11
  243. package/build/esm/Graphics/Context/draw-image-command.d.ts +0 -47
  244. package/build/esm/Graphics/Context/image-renderer.d.ts +0 -39
  245. package/build/esm/Graphics/Context/line-renderer.d.ts +0 -22
  246. package/build/esm/Graphics/Context/point-renderer.d.ts +0 -22
  247. package/build/esm/Input/Pointer.d.ts +0 -134
  248. package/build/esm/Input/PointerEvents.d.ts +0 -170
  249. package/build/esm/Input/Pointers.d.ts +0 -78
  250. package/build/esm/PostProcessing/ColorBlindCorrector.d.ts +0 -28
  251. package/build/esm/PostProcessing/Index.d.ts +0 -2
  252. package/build/esm/PostProcessing/PostProcessor.d.ts +0 -6
  253. package/build/esm/Traits/CapturePointer.d.ts +0 -10
  254. package/wallaby.js +0 -77
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see excalibur.min.js.LICENSE.txt */
2
- 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(6733),n=i(9821);t.exports=function(t){if(s(t))return t;throw TypeError(n(t)+" is not a function")}},1176:(t,e,i)=>{var s=i(5052);t.exports=function(t){if(s(t))return t;throw TypeError(String(t)+" is not an object")}},9540:(t,e,i)=>{var s=i(905),n=i(4237),r=i(3231),o=function(t){return function(e,i,o){var a,h=s(e),l=n(h.length),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)=>{var s=i(4229);t.exports=function(t,e){var i=[][t];return!!i&&s((function(){i.call(null,e||function(){throw 1},1)}))}},3867:t=>{var e=Math.floor,i=function(t,r){var o=t.length,a=e(o/2);return o<8?s(t,r):n(i(t.slice(0,a),r),i(t.slice(a),r),r)},s=function(t,e){for(var i,s,n=t.length,r=1;r<n;){for(s=r,i=t[r];s&&e(t[s-1],i)>0;)t[s]=t[--s];s!==r++&&(t[s]=i)}return t},n=function(t,e,i){for(var s=t.length,n=e.length,r=0,o=0,a=[];r<s||o<n;)r<s&&o<n?a.push(i(t[r],e[o])<=0?t[r++]:e[o++]):a.push(r<s?t[r++]:e[o++]);return a};t.exports=i},7079:t=>{var e={}.toString;t.exports=function(t){return e.call(t).slice(8,-1)}},1589:(t,e,i)=>{var s=i(1601),n=i(6733),r=i(7079),o=i(95)("toStringTag"),a="Arguments"==r(function(){return arguments}());t.exports=s?r: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=Object(t),o))?i:a?r(e):"Object"==(s=r(e))&&n(e.callee)?"Arguments":s}},7081:(t,e,i)=>{var s=i(816),n=i(4826),r=i(7933),o=i(1787);t.exports=function(t,e){for(var i=n(e),a=o.f,h=r.f,l=0;l<i.length;l++){var c=i[l];s(t,c)||a(t,c,h(e,c))}}},5762:(t,e,i)=>{var s=i(7400),n=i(1787),r=i(5358);t.exports=s?function(t,e,i){return n.f(t,e,r(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}}},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),n=i(5052),r=s.document,o=n(r)&&n(r.createElement);t.exports=function(t){return o?r.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,n,r=i(9859),o=i(598),a=r.process,h=r.Deno,l=a&&a.versions||h&&h.version,c=l&&l.v8;c?n=(s=c.split("."))[0]<4?1:s[0]+s[1]:o&&(!(s=o.match(/Edge\/(\d+)/))||s[1]>=74)&&(s=o.match(/Chrome\/(\d+)/))&&(n=s[1]),t.exports=n&&+n},9811:(t,e,i)=>{var s=i(598).match(/AppleWebKit\/(\d+)\./);t.exports=!!s&&+s[1]},8791:(t,e,i)=>{var s=i(9859),n=i(7636),r=Function.call;t.exports=function(t,e,i){return n(r,s[t].prototype[e],i)}},3837:t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3103:(t,e,i)=>{var s=i(9859),n=i(7933).f,r=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=n(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)&&r(u,"sham",!0),o(i,c,u,t)}}},4229:t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}},7636:(t,e,i)=>{var s=i(7111);t.exports=function(t,e,i){if(s(t),void 0===e)return t;switch(i){case 0:return function(){return t.call(e)};case 1:return function(i){return t.call(e,i)};case 2:return function(i,s){return t.call(e,i,s)};case 3:return function(i,s,n){return t.call(e,i,s,n)}}return function(){return t.apply(e,arguments)}}},1805:(t,e,i)=>{var s=i(7400),n=i(816),r=Function.prototype,o=s&&Object.getOwnPropertyDescriptor,a=n(r,"name"),h=a&&"something"===function(){}.name,l=a&&(!s||s&&o(r,"name").configurable);t.exports={EXISTS:a,PROPER:h,CONFIGURABLE:l}},1333:(t,e,i)=>{var s=i(9859),n=i(6733),r=function(t){return n(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?r(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")()},816:(t,e,i)=>{var s=i(2991),n={}.hasOwnProperty;t.exports=Object.hasOwn||function(t,e){return n.call(s(t),e)}},5977:t=>{t.exports={}},4394:(t,e,i)=>{var s=i(7400),n=i(4229),r=i(2635);t.exports=!s&&!n((function(){return 7!=Object.defineProperty(r("div"),"a",{get:function(){return 7}}).a}))},9337:(t,e,i)=>{var s=i(4229),n=i(7079),r="".split;t.exports=s((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==n(t)?r.call(t,""):Object(t)}:Object},8511:(t,e,i)=>{var s=i(6733),n=i(5353),r=Function.toString;s(n.inspectSource)||(n.inspectSource=function(t){return r.call(t)}),t.exports=n.inspectSource},6407:(t,e,i)=>{var s,n,r,o=i(8694),a=i(9859),h=i(5052),l=i(5762),c=i(816),d=i(5353),u=i(4399),p=i(5977),g="Object already initialized",_=a.WeakMap;if(o||d.state){var f=d.state||(d.state=new _),m=f.get,w=f.has,y=f.set;s=function(t,e){if(w.call(f,t))throw new TypeError(g);return e.facade=t,y.call(f,t,e),e},n=function(t){return m.call(f,t)||{}},r=function(t){return w.call(f,t)}}else{var v=u("state");p[v]=!0,s=function(t,e){if(c(t,v))throw new TypeError(g);return e.facade=t,l(t,v,e),e},n=function(t){return c(t,v)?t[v]:{}},r=function(t){return c(t,v)}}t.exports={set:s,get:n,has:r,enforce:function(t){return r(t)?n(t):s(t,{})},getterFor:function(t){return function(e){var i;if(!h(e)||(i=n(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return i}}}},6733:t=>{t.exports=function(t){return"function"==typeof t}},6541:(t,e,i)=>{var s=i(4229),n=i(6733),r=/#|\.prototype\./,o=function(t,e){var i=h[a(t)];return i==c||i!=l&&(n(e)?s(e):!!e)},a=o.normalize=function(t){return String(t).replace(r,".").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(6733),n=i(1333),r=i(6969);t.exports=r?function(t){return"symbol"==typeof t}:function(t){var e=n("Symbol");return s(e)&&Object(t)instanceof e}},3839:(t,e,i)=>{var s=i(6358),n=i(4229);t.exports=!!Object.getOwnPropertySymbols&&!n((function(){var t=Symbol();return!String(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&s&&s<41}))},8694:(t,e,i)=>{var s=i(9859),n=i(6733),r=i(8511),o=s.WeakMap;t.exports=n(o)&&/native code/.test(r(o))},1787:(t,e,i)=>{var s=i(7400),n=i(4394),r=i(1176),o=i(9310),a=Object.defineProperty;e.f=s?a:function(t,e,i){if(r(t),e=o(e),r(i),n)try{return a(t,e,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},7933:(t,e,i)=>{var s=i(7400),n=i(9195),r=i(5358),o=i(905),a=i(9310),h=i(816),l=i(4394),c=Object.getOwnPropertyDescriptor;e.f=s?c:function(t,e){if(t=o(t),e=a(e),l)try{return c(t,e)}catch(t){}if(h(t,e))return r(!n.f.call(t,e),t[e])}},8151:(t,e,i)=>{var s=i(140),n=i(3837).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return s(t,n)}},894:(t,e)=>{e.f=Object.getOwnPropertySymbols},140:(t,e,i)=>{var s=i(816),n=i(905),r=i(9540).indexOf,o=i(5977);t.exports=function(t,e){var i,a=n(t),h=0,l=[];for(i in a)!s(o,i)&&s(a,i)&&l.push(i);for(;e.length>h;)s(a,i=e[h++])&&(~r(l,i)||l.push(i));return l}},5632:(t,e,i)=>{var s=i(140),n=i(3837);t.exports=Object.keys||function(t){return s(t,n)}},9195:(t,e)=>{var i={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,n=s&&!i.call({1:2},1);e.f=n?function(t){var e=s(this,t);return!!e&&e.enumerable}:i},2914:(t,e,i)=>{var s=i(6733),n=i(5052);t.exports=function(t,e){var i,r;if("string"===e&&s(i=t.toString)&&!n(r=i.call(t)))return r;if(s(i=t.valueOf)&&!n(r=i.call(t)))return r;if("string"!==e&&s(i=t.toString)&&!n(r=i.call(t)))return r;throw TypeError("Can't convert object to primitive value")}},4826:(t,e,i)=>{var s=i(1333),n=i(8151),r=i(894),o=i(1176);t.exports=s("Reflect","ownKeys")||function(t){var e=n.f(o(t)),i=r.f;return i?e.concat(i(t)):e}},9276:(t,e,i)=>{var s=i(9859);t.exports=s},7487:(t,e,i)=>{var s=i(9859),n=i(6733),r=i(816),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;n(i)&&("Symbol("===String(f).slice(0,7)&&(f="["+String(f).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),(!r(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 n(this)&&d(this).source||h(this)}))},8885:t=>{t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},2079:(t,e,i)=>{var s=i(9859);t.exports=function(t,e){try{Object.defineProperty(s,t,{value:e,configurable:!0,writable:!0})}catch(i){s[t]=e}return e}},4399:(t,e,i)=>{var s=i(3036),n=i(1441),r=s("keys");t.exports=function(t){return r[t]||(r[t]=n(t))}},5353:(t,e,i)=>{var s=i(9859),n=i(2079),r="__core-js_shared__",o=s[r]||n(r,{});t.exports=o},3036:(t,e,i)=>{var s=i(4231),n=i(5353);(t.exports=function(t,e){return n[t]||(n[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.18.1",mode:s?"pure":"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})},3231:(t,e,i)=>{var s=i(6051),n=Math.max,r=Math.min;t.exports=function(t,e){var i=s(t);return i<0?n(i+e,0):r(i,e)}},905:(t,e,i)=>{var s=i(9337),n=i(8885);t.exports=function(t){return s(n(t))}},6051:t=>{var e=Math.ceil,i=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?i:e)(t)}},4237:(t,e,i)=>{var s=i(6051),n=Math.min;t.exports=function(t){return t>0?n(s(t),9007199254740991):0}},2991:(t,e,i)=>{var s=i(8885);t.exports=function(t){return Object(s(t))}},2066:(t,e,i)=>{var s=i(5052),n=i(9395),r=i(5300),o=i(2914),a=i(95)("toPrimitive");t.exports=function(t,e){if(!s(t)||n(t))return t;var i,h=r(t,a);if(h){if(void 0===e&&(e="default"),i=h.call(t,e),!s(i)||n(i))return i;throw TypeError("Can't convert object to primitive value")}return void 0===e&&(e="number"),o(t,e)}},9310:(t,e,i)=>{var s=i(2066),n=i(9395);t.exports=function(t){var e=s(t,"string");return n(e)?e:String(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(1589);t.exports=function(t){if("Symbol"===s(t))throw TypeError("Cannot convert a Symbol value to a string");return String(t)}},9821:t=>{t.exports=function(t){try{return String(t)}catch(t){return"Object"}}},1441:t=>{var e=0,i=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++e+i).toString(36)}},6969:(t,e,i)=>{var s=i(3839);t.exports=s&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},95:(t,e,i)=>{var s=i(9859),n=i(3036),r=i(816),o=i(1441),a=i(3839),h=i(6969),l=n("wks"),c=s.Symbol,d=h?c:c&&c.withoutSetter||o;t.exports=function(t){return r(l,t)&&(a||"string"==typeof l[t])||(a&&r(c,t)?l[t]=c[t]:l[t]=d("Symbol."+t)),l[t]}},3430:(t,e,i)=>{var s=i(3103),n=i(7111),r=i(2991),o=i(4237),a=i(3326),h=i(4229),l=i(3867),c=i(6038),d=i(2671),u=i(8506),p=i(6358),g=i(9811),_=[],f=_.sort,m=h((function(){_.sort(void 0)})),w=h((function(){_.sort(null)})),y=c("sort"),v=!h((function(){if(p)return p<70;if(!(d&&d>3)){if(u)return!0;if(g)return g<603;var t,e,i,s,n="";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++)_.push({k:e+s,v:i})}for(_.sort((function(t,e){return e.v-t.v})),s=0;s<_.length;s++)e=_[s].k.charAt(0),n.charAt(n.length-1)!==e&&(n+=e);return"DGBEFHACIJK"!==n}}));s({target:"Array",proto:!0,forced:m||!w||!y||!v},{sort:function(t){void 0!==t&&n(t);var e=r(this);if(v)return void 0===t?f.call(e):f.call(e,t);var i,s,h=[],c=o(e.length);for(s=0;s<c;s++)s in e&&h.push(e[s]);for(h=l(h,function(t){return function(e,i){return void 0===i?-1:void 0===e?1:void 0!==t?+t(e,i)||0:a(e)>a(i)?1:-1}}(t)),i=h.length,s=0;s<i;)e[s]=h[s++];for(;s<c;)delete e[s++];return e}})},4769:(t,e,i)=>{var s=i(3103),n=i(2991),r=i(5632);s({target:"Object",stat:!0,forced:i(4229)((function(){r(1)}))},{keys:function(t){return r(n(t))}})},1388:(t,e,i)=>{i.d(e,{Z:()=>a});var s=i(272),n=i.n(s),r=i(2609),o=i.n(r)()(n());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=>{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,n,r){"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!==r&&(void 0===c[5]||(c[1]="@layer".concat(c[5].length>0?" ".concat(c[5]):""," {").concat(c[1],"}")),c[5]=r),i&&(c[2]?(c[1]="@media ".concat(c[2]," {").concat(c[1],"}"),c[2]=i):c[2]=i),n&&(c[4]?(c[1]="@supports (".concat(c[4],") {").concat(c[1],"}"),c[4]=n):c[4]="".concat(n)),e.push(c))}},e}},272:t=>{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)))),n="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(s),r="/*# ".concat(n," */"),o=i.sources.map((function(t){return"/*# sourceURL=".concat(i.sourceRoot||"").concat(t," */")}));return[e].concat(o).concat([r]).join("\n")}return[e].join("\n")}}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={id:s,exports:{}};return t[s](r,r.exports,i),r.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={};(()=>{i.d(s,{fWn:()=>Ss,Ia8:()=>hs,hLI:()=>Ps,yyv:()=>Sn,tX5:()=>se,vtX:()=>Ts,r7K:()=>Ki,lCh:()=>Ys,fwF:()=>mn,sce:()=>gn,_c7:()=>_n,KUs:()=>cn,Ajp:()=>Ye,RDh:()=>Ms,_H9:()=>Ie,Ulf:()=>Kr,mxs:()=>ys,OmD:()=>Vi,kBf:()=>J,C4F:()=>di,NQt:()=>ar,JjN:()=>hr,V1s:()=>Gs,Xz7:()=>At,bLd:()=>Os,Cdc:()=>ns,FKn:()=>Fi,wTW:()=>$e,ab2:()=>Mi,GfZ:()=>ki,YMS:()=>Ri,oyv:()=>Ni,aUb:()=>Li,SdD:()=>ee,JUv:()=>xi,jEj:()=>br,TFq:()=>Oi,HDU:()=>Jt,R_y:()=>$t,ydN:()=>ci,_N2:()=>ln,t50:()=>te,s$$:()=>pn,v2G:()=>li,Ilk:()=>Q,H_9:()=>Ln,s9i:()=>In,ksl:()=>Pn,wA2:()=>fi,R_p:()=>Di,IQ$:()=>Ce,I5F:()=>f,X8$:()=>dn,FR6:()=>Qt,U8o:()=>Yt,kbG:()=>wi,oeJ:()=>Gi,iS_:()=>ne,cGG:()=>On,skb:()=>An,SLU:()=>Ge,RdJ:()=>Wi,gU7:()=>hi,LSk:()=>bs,Nmp:()=>ze,d1Y:()=>Ke,xrL:()=>Pi,sRW:()=>Ti,cmV:()=>Jr,N0Q:()=>ws,q8b:()=>as,ynB:()=>zi,jT9:()=>Ns,wAz:()=>fn,D4V:()=>pr,N6H:()=>ae,W1A:()=>oe,JHW:()=>Qi,v2K:()=>tn,pBf:()=>le,GMl:()=>St,zW2:()=>t,B0K:()=>Sr,Nv7:()=>cr,C_p:()=>Xe,MUA:()=>he,xqU:()=>re,peG:()=>l,pTp:()=>vs,vUK:()=>p,j9l:()=>Cs,Zxw:()=>wr,Hdx:()=>Oe,Z$d:()=>Fe,o$7:()=>zn,Zm$:()=>Pt,$QH:()=>Dt,i78:()=>Bt,h6u:()=>Vt,hts:()=>Wt,j88:()=>Ht,VME:()=>Nt,nt:()=>Ur,Ukr:()=>tr,zsu:()=>vt,oA6:()=>is,TVh:()=>wn,TwZ:()=>ts,GTT:()=>es,xxj:()=>bn,XdK:()=>Kt,cXo:()=>De,Dm5:()=>ie,IIB:()=>o,zI0:()=>ui,SKZ:()=>Et,__J:()=>xr,Dvr:()=>c,Tf9:()=>r,RI$:()=>Vs,x12:()=>Bi,aNw:()=>oi,xwn:()=>Hs,dNK:()=>Us,ini:()=>d,YdH:()=>_,y3G:()=>et,l57:()=>Z,xn0:()=>_r,t2V:()=>As,ZyS:()=>qr,uxB:()=>vi,cpd:()=>hn,fiy:()=>ds,$XZ:()=>us,uqK:()=>fr,STE:()=>mr,y$z:()=>bi,sOq:()=>Ci,Sqs:()=>Vr,hpZ:()=>vn,Vol:()=>xn,wIZ:()=>gi,cBi:()=>Un,mgq:()=>Gr,YVA:()=>Ui,Kgp:()=>at,HH$:()=>Zt,M_d:()=>Lt,rgh:()=>kt,Ra6:()=>Ut,KhR:()=>Rt,BS5:()=>Ot,xhz:()=>qt,xOq:()=>Ft,a9j:()=>Mt,bHk:()=>zt,CgK:()=>Tt,cuY:()=>It,kvE:()=>Ai,JDb:()=>$r,Cbi:()=>Yr,AE_:()=>sn,ctO:()=>nn,OLH:()=>Ws,kky:()=>y,nSF:()=>Ct,zHn:()=>Ei,zwx:()=>un,AeJ:()=>ss,hLz:()=>Zi,D9g:()=>$s,wA:()=>ls,jhr:()=>cs,GVs:()=>qe,_zO:()=>ce,w6$:()=>gs,mhV:()=>ps,MOD:()=>rs,kwd:()=>fs,Lmr:()=>_s,xsS:()=>Fn,lLr:()=>Ze,Z$r:()=>m,IXb:()=>Rs,SMj:()=>dr,bnF:()=>Hi,MFA:()=>v,$XC:()=>Xr,$uU:()=>Or,jyi:()=>Te,E03:()=>Ve,V6q:()=>We,nVo:()=>zs,F6N:()=>Wr,ad3:()=>Gt,xP7:()=>Zs,Odq:()=>rn,Zif:()=>qs,ZGJ:()=>mi,xvT:()=>yr,PHM:()=>Le,KwO:()=>Ls,B7y:()=>Bs,SFp:()=>a,Uvn:()=>yi,OFT:()=>Si,xzN:()=>Ks,H6j:()=>jt,ZrN:()=>h,OWs:()=>K,dF9:()=>_i,VHo:()=>Xt,R$E:()=>Fr,q3I:()=>on,Pab:()=>T,uZ5:()=>S,McK:()=>g,k0b:()=>Ji,hnT:()=>Er,RSJ:()=>Br,Mku:()=>Rr,h90:()=>kr,rms:()=>Mr,ErP:()=>Pr,aVg:()=>Dr,lPc:()=>Tr,Z8E:()=>qi,NNA:()=>Qs,yFn:()=>Js,lNv:()=>Yi,MZQ:()=>N,FUM:()=>j,vdf:()=>P,iaL:()=>E,w6H:()=>U,Q4c:()=>V,Uxb:()=>R,Yr5:()=>D,Bhw:()=>q});var t={};i.r(t),i.d(t,{ActivateEvent:()=>se,CollisionEndEvent:()=>ee,CollisionPostSolveEvent:()=>Jt,CollisionPreSolveEvent:()=>$t,CollisionStartEvent:()=>te,ContactEndEvent:()=>Qt,ContactStartEvent:()=>Yt,DeactivateEvent:()=>ne,EnterTriggerEvent:()=>ae,EnterViewPortEvent:()=>oe,EventTypes:()=>St,ExitTriggerEvent:()=>he,ExitViewPortEvent:()=>re,GameEvent:()=>Pt,GameStartEvent:()=>Dt,GameStopEvent:()=>Bt,GamepadAxisEvent:()=>Vt,GamepadButtonEvent:()=>Wt,GamepadConnectEvent:()=>Ht,GamepadDisconnectEvent:()=>Nt,HiddenEvent:()=>Kt,InitializeEvent:()=>ie,KillEvent:()=>Et,PostCollisionEvent:()=>Zt,PostDebugDrawEvent:()=>Lt,PostDrawEvent:()=>kt,PostFrameEvent:()=>Ut,PostKillEvent:()=>Rt,PostUpdateEvent:()=>Ot,PreCollisionEvent:()=>qt,PreDebugDrawEvent:()=>Ft,PreDrawEvent:()=>Mt,PreFrameEvent:()=>zt,PreKillEvent:()=>Tt,PreUpdateEvent:()=>It,SubscribeEvent:()=>Gt,UnsubscribeEvent:()=>jt,VisibleEvent:()=>Xt});var e={};i.r(e),i.d(e,{Colorize:()=>_e,Darken:()=>me,Desaturate:()=>ye,Fill:()=>ve,Grayscale:()=>ue,Invert:()=>pe,Lighten:()=>fe,Opacity:()=>ge,Saturate:()=>we});var n={};i.r(n),i.d(n,{circle:()=>si,line:()=>Je,point:()=>ti,roundRect:()=>ii,vector:()=>ei});var r={};i.r(r),i.d(r,{Animation:()=>ke,CanvasDrawComponent:()=>$i,CanvasDrawingSystem:()=>Cn,Effects:()=>e,Polygon:()=>Ar,Sprite:()=>Ee,SpriteFont:()=>Ne,SpriteSheet:()=>He,Texture:()=>be});var o={};i.r(o),i.d(o,{Axes:()=>or,Buttons:()=>rr,Gamepad:()=>nr,Gamepads:()=>sr,KeyEvent:()=>Hn,Keyboard:()=>Nn,Keys:()=>En,NativePointerButton:()=>Dn,Pointer:()=>Wn,PointerButton:()=>Bn,PointerCancelEvent:()=>Qn,PointerDownEvent:()=>Kn,PointerDragEvent:()=>jn,PointerEnterEvent:()=>Zn,PointerEvent:()=>Vn,PointerEventFactory:()=>Gn,PointerLeaveEvent:()=>Yn,PointerMoveEvent:()=>qn,PointerScope:()=>Rn,PointerType:()=>Tn,PointerUpEvent:()=>Xn,Pointers:()=>ir,WheelDeltaMode:()=>Mn,WheelEvent:()=>$n,createPointerEventByName:()=>Jn});var a={};i.r(a),i.d(a,{CapturePointer:()=>Xi,OffscreenCulling:()=>ji});var h={};i.r(h),i.d(h,{Collection:()=>O,ConsoleAppender:()=>f,DrawUtil:()=>n,EasingFunctions:()=>as,LogLevel:()=>d,Logger:()=>_,Observable:()=>bi,ScreenAppender:()=>m,TwoPI:()=>x,addItemToArray:()=>M,base64Encode:()=>C,canonicalizeAngle:()=>T,clamp:()=>S,contains:()=>F,delay:()=>H,extend:()=>b,fail:()=>z,getOppositeSide:()=>L,getPosition:()=>B,getSideFromDirection:()=>I,nullish:()=>A,randomInRange:()=>P,randomIntInRange:()=>E,range:()=>U,removeItemFromArray:()=>k,toDegrees:()=>R,toRadians:()=>D});var l,c,d;i(4662),i(8343);function u(){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"}(l||(l={})),function(t){t.Canvas="use-canvas-context",t.LegacyDrawing="use-legacy-drawing"}(c||(c={}));class p{static freeze(){p._FROZEN=!0}static _reset(){p._FROZEN=!1,p._FLAGS={}}static useWebGL(){p.enable(l.WebGL)}static useCanvasGraphicsContext(){p.enable(c.Canvas)}static useLegacyDrawing(){p.enable(c.LegacyDrawing)}static enable(t){if(this._FROZEN)throw Error("Feature flags can only be enabled before Engine constructor time");p._FLAGS[t]=!0}static disable(t){if(this._FROZEN)throw Error("Feature flags can only be disabled before Engine constructor time");p._FLAGS[t]=!1}static isEnabled(t){return!!p._FLAGS[t]}static show(){return Object.keys(p._FLAGS)}}function g(t,e){return{type:t,value:e}}p._FROZEN=!1,p._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"}(d||(d={}));class _{constructor(){if(this._appenders=[],this.defaultLevel=d.Info,_._INSTANCE)throw new Error("Logger is a singleton");return _._INSTANCE=this,_._INSTANCE.addAppender(new f),_._INSTANCE}static getInstance(){return null==_._INSTANCE&&(_._INSTANCE=new _),_._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(d.Debug,t)}info(...t){this._log(d.Info,t)}warn(...t){this._log(d.Warn,t)}error(...t){this._log(d.Error,t)}fatal(...t){this._log(d.Fatal,t)}}_._INSTANCE=null;class f{log(t,e){if(!console&&!console.log&&console.warn&&console.error)return;const i=[];i.unshift.apply(i,e),i.unshift("["+d[t]+"] : "),t<d.Warn?console.log.apply?console.log.apply(console,i):console.log(i.join(" ")):t<d.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 m{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("["+d[t]+"] : "+i);let s=10,n=1;for(let t=0;t<this._messages.length;t++)this._ctx.fillStyle="rgba(255,255,255,"+n.toFixed(2)+")",this._ctx.fillText(this._messages[t],200,s),s+=10,n=n>0?n-.05:0}}const w=4294967295;class y{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]&w;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]&w;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]&w,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 n=t.slice(0);for(;s<e;){const t=this.integer(0,n.length-1);i[s++]=n[t],n.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 n=0;n<t;n++)s[n]=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)}}var v;!function(t){t.None="None",t.Top="Top",t.Bottom="Bottom",t.Left="Left",t.Right="Right"}(v||(v={})),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=[K.Left,K.Right,K.Up,K.Down],s=[t.Left,t.Right,t.Top,t.Bottom];let n=-Number.MAX_VALUE,r=-1;for(let t=0;t<i.length;t++)i[t].dot(e)>n&&(n=i[t].dot(e),r=t);return s[r]}}(v||(v={}));const x=2*Math.PI;function b(){const t={};let e=!1,i=0;const s=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(e=arguments[0],i++);const n="function"==typeof Object.assign;let r=null;for(r=n?Object.assign:function(i){for(const s in i)Object.prototype.hasOwnProperty.call(i,s)&&(e&&"[object Object]"===Object.prototype.toString.call(i[s])?t[s]=b(!0,t[s],i[s]):t[s]=i[s])};i<s;i++){const e=arguments[i];n?r(t,e):r(e)}return t}function C(t){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";let i="",s=0;for(;s<t.length;){const n=255&t.charCodeAt(s++),r=255&t.charCodeAt(s++),o=255&t.charCodeAt(s++),a=n>>2,h=(3&n)<<4|r>>4;let l,c;isNaN(r)?l=c=64:(l=(15&r)<<2|o>>6,c=isNaN(o)?64:63&o),i+=e.charAt(a)+e.charAt(h)+e.charAt(l)+e.charAt(c)}return i}function A(t,e){return null!=t?t:e}function S(t,e,i){return Math.min(Math.max(e,t),i)}function P(t,e,i=new y){return i?i.floating(t,e):t+Math.random()*(e-t)}function E(t,e,i=new y){return i?i.integer(t,e):Math.round(P(t,e))}function T(t){let e=t;if(t>x)for(;e>x;)e-=x;if(t<0)for(;e<0;)e+=x;return e}function R(t){return 180/Math.PI*t}function D(t){return t/180*Math.PI}function B(t){let e=0,i=0;const s=t=>{e+=t.offsetLeft,t.offsetParent&&s(t.offsetParent)},n=t=>{i+=t.offsetTop,t.offsetParent&&n(t.offsetParent)};return s(t),n(t),new K(e,i)}function M(t,e){return-1===e.indexOf(t)&&(e.push(t),!0)}function k(t,e){let i=-1;return(i=e.indexOf(t))>-1&&(e.splice(i,1),!0)}function F(t,e){for(let i=0;i<t.length;i++)if(t[i]===e)return!0;return!1}function L(t){return t===v.Top?v.Bottom:t===v.Bottom?v.Top:t===v.Left?v.Right:t===v.Right?v.Left:v.None}function I(t){const e=[K.Left,K.Right,K.Up,K.Down],i=[v.Left,v.Right,v.Top,v.Bottom];let s=-Number.MAX_VALUE,n=-1;for(let i=0;i<e.length;i++)e[i].dot(t)>s&&(s=e[i].dot(t),n=i);return i[n]}class O{constructor(t=O.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 z(t){throw new Error(t)}O.DefaultSize=200;const U=(t,e)=>Array.from(new Array(e-t+1),((e,i)=>i+t));function H(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}const N=5,W={},V=()=>{for(const t in W)W[t]=0},G=(t,e)=>{const i=p.isEnabled("suppress-obsolete-message");W[t]<N&&!i&&(_.getInstance().warn(t),console.trace&&e.showStackTrace&&console.trace()),W[t]++};function j(t){return t=b({},{message:"This feature will be removed in future versions of Excalibur.",alternateMethod:null,showStackTrack:!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 n=`${`${e.name||""}${e.name&&i?".":""}${i||""}`} is marked obsolete: ${t.message}`+(t.alternateMethod?` Use ${t.alternateMethod} instead`:"");W[n]||(W[n]=0);const r=s?Object.assign({},s):e;if(!s){class e extends r{constructor(...e){G(n,t),super(...e)}}return e}return s&&s.value?(r.value=function(){return G(n,t),s.value.apply(this,arguments)},r):(s&&s.get&&(r.get=function(){return G(n,t),s.get.apply(this,arguments)}),s&&s.set&&(r.set=function(){return G(n,t),s.set.apply(this,arguments)}),r)}}var X=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class K{constructor(t,e){this._x=0,this._y=0,this._x=t,this._y=e}static get Zero(){return new K(0,0)}static get One(){return new K(1,1)}static get Half(){return new K(.5,.5)}static get Up(){return new K(0,-1)}static get Down(){return new K(0,1)}static get Left(){return new K(-1,0)}static get Right(){return new K(1,0)}static fromAngle(t){return new K(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=K.Zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))}squareDistance(t){return t||(t=K.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 K(this.x/t,this.y/t):new K(0,1)}average(t){return this.add(t).scale(.5)}scale(t){return t instanceof K?new K(this.x*t.x,this.y*t.y):new K(this.x*t,this.y*t)}add(t){return new K(this.x+t.x,this.y+t.y)}sub(t){return new K(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 K?this.x*t.y-this.y*t.x:"number"==typeof t?new K(t*this.y,-t*this.x):void 0}static cross(t,e){return new K(-t*e.y,t*e.x)}perpendicular(){return new K(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 K(0,0));const i=Math.sin(t),s=Math.cos(t),n=s*(this.x-e.x)-i*(this.y-e.y)+e.x,r=i*(this.x-e.x)+s*(this.y-e.y)+e.y;return new K(n,r)}clone(){return new K(this.x,this.y)}toString(t){return t?`(${this.x.toFixed(t)}, ${this.y.toFixed(t)})`:`(${this.x}, ${this.y})`}}function q(t,e){return new K(t,e)}X([j({message:"will be removed in favour of `.size` in version 0.25.0"})],K.prototype,"magnitude",null);var Z,Y=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Q{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 Q(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 n=1;return e[4]&&(n=parseFloat(e[4])),new Q(t,i,s,n)}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 n=1;return e[4]&&(n=parseInt(e[4],16)/255),new Q(t,i,s,n)}throw new Error("Invalid hex string: "+t)}static fromHSL(t,e,i,s=1){return new $(t,e,i,s).toRGBA()}lighten(t=.1){const e=$.fromRGBA(this.r,this.g,this.b,this.a);return e.l+=(1-e.l)*t,e.toRGBA()}darken(t=.1){const e=$.fromRGBA(this.r,this.g,this.b,this.a);return e.l-=e.l*t,e.toRGBA()}saturate(t=.1){const e=$.fromRGBA(this.r,this.g,this.b,this.a);return e.s+=e.s*t,e.toRGBA()}desaturate(t=.1){const e=$.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,n=t.a*this.a;return new Q(e,i,s,n)}mulitiply(t){return this.multiply(t)}screen(t){const e=t.invert(),i=t.invert();return e.multiply(i).invert()}invert(){return new Q(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,n=(t.a+this.a)/2;return new Q(e,i,s,n)}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 $.fromRGBA(this.r,this.g,this.b,this.a).toString()}fillStyle(){return this.toString()}clone(){return new Q(this.r,this.g,this.b,this.a)}static get Black(){return Q.fromHex("#000000")}static get White(){return Q.fromHex("#FFFFFF")}static get Gray(){return Q.fromHex("#808080")}static get LightGray(){return Q.fromHex("#D3D3D3")}static get DarkGray(){return Q.fromHex("#A9A9A9")}static get Yellow(){return Q.fromHex("#FFFF00")}static get Orange(){return Q.fromHex("#FFA500")}static get Red(){return Q.fromHex("#FF0000")}static get Vermilion(){return Q.fromHex("#FF5B31")}static get Vermillion(){return Q.Vermilion}static get Rose(){return Q.fromHex("#FF007F")}static get Magenta(){return Q.fromHex("#FF00FF")}static get Violet(){return Q.fromHex("#7F00FF")}static get Blue(){return Q.fromHex("#0000FF")}static get Azure(){return Q.fromHex("#007FFF")}static get Cyan(){return Q.fromHex("#00FFFF")}static get Viridian(){return Q.fromHex("#59978F")}static get Green(){return Q.fromHex("#00FF00")}static get Chartreuse(){return Q.fromHex("#7FFF00")}static get Transparent(){return Q.fromHex("#FFFFFF00")}static get ExcaliburBlue(){return Q.fromHex("#176BAA")}}Y([j({message:"Alias for incorrect spelling used in older versions, use multiply instead, will be removed in v0.25.0"})],Q.prototype,"mulitiply",null),Y([j({message:"Alias for incorrect spelling used in older versions",alternateMethod:"Vermilion"})],Q,"Vermillion",null);class ${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 n=Math.max(t,e,i),r=Math.min(t,e,i);let o,a;const h=(n+r)/2;if(n===r)o=a=0;else{const s=n-r;switch(a=h>.5?s/(2-n-r):s/(n+r),n){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 $(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,n=2*this.l-s;t=$.hue2rgb(n,s,this.h+1/3),e=$.hue2rgb(n,s,this.h),i=$.hue2rgb(n,s,this.h-1/3)}return new Q(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)})`}}class J{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?v.Right:v.Left:t.y<0?v.Bottom:v.Top:v.None}static fromPoints(t){let e=1/0,i=1/0,s=-1/0,n=-1/0;for(let r=0;r<t.length;r++)t[r].x<e&&(e=t[r].x),t[r].x>s&&(s=t[r].x),t[r].y<i&&(i=t[r].y),t[r].y>n&&(n=t[r].y);return new J(e,i,s,n)}static fromDimension(t,e,i=K.Half,s=K.Zero){return new J(-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 K((this.left+this.right)/2,(this.top+this.bottom)/2)}translate(t){return new J(this.left+t.x,this.top+t.y,this.right+t.x,this.bottom+t.y)}rotate(t,e=K.Zero){const i=this.getPoints().map((i=>i.rotate(t,e)));return J.fromPoints(i)}scale(t,e=K.Zero){const i=this.translate(e);return new J(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 J.fromPoints(e)}getPerimeter(){return 2*(this.width+this.height)}getPoints(){const t=[];return t.push(new K(this.left,this.top)),t.push(new K(this.right,this.top)),t.push(new K(this.right,this.bottom)),t.push(new K(this.left,this.bottom)),t}rayCast(t,e=1/0){let i=-1/0,s=1/0;const n=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,r=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*n,a=(this.right-t.pos.x)*n;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*r,l=(this.bottom-t.pos.y)*r;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 n=0===t.dir.x?Number.MAX_VALUE:1/t.dir.x,r=0===t.dir.y?Number.MAX_VALUE:1/t.dir.y,o=(this.left-t.pos.x)*n,a=(this.right-t.pos.x)*n;i=Math.min(o,a),s=Math.max(o,a);const h=(this.top-t.pos.y)*r,l=(this.bottom-t.pos.y)*r;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 K?this.left<=t.x&&this.top<=t.y&&this.bottom>=t.y&&this.right>=t.x:t instanceof J&&(this.left<t.left&&this.top<t.top&&t.bottom<this.bottom&&t.right<this.right)}combine(t){return new J(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 K(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 K(e,0):new K(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 K(e,0):new K(0,i)}return null}intersectWithSide(t){const e=this.intersect(t);return J.getSideFromIntersection(e)}debugDraw(t,e=Q.Yellow){t.strokeStyle=e.toString(),t.strokeRect(this.left,this.top,this.width,this.height)}draw(t,e=Q.Yellow){t.debug.drawRect(this.left,this.top,this.width,this.height,{color:e})}}!function(t){t[t.X=12]="X",t[t.Y=13]="Y"}(Z||(Z={}));const tt=t=>0===t?0:t<0?-1:1;class et{constructor(){this.data=new Float32Array(16),this._scaleSignX=1,this._scaleSignY=1}static ortho(t,e,i,s,n,r){const o=new et;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/(r-n),o.data[11]=0,o.data[12]=-(e+t)/(e-t),o.data[13]=-(s+i)/(s-i),o.data[14]=-(r+n)/(r-n),o.data[15]=1,o}clone(){const t=new et;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}static identity(){const t=new et;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=et.identity();return i.data[12]=t,i.data[13]=e,i}static scale(t,e){const i=et.identity();return i.data[0]=t,i.data[5]=e,i.data[10]=1,i.data[15]=1,i}static rotation(t){const e=et.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 K)return new K(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 et,i=this.data[0],s=this.data[1],n=this.data[2],r=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],w=t.data[0],y=t.data[1],v=t.data[2],x=t.data[3],b=t.data[4],C=t.data[5],A=t.data[6],S=t.data[7],P=t.data[8],E=t.data[9],T=t.data[10],R=t.data[11],D=t.data[12],B=t.data[13],M=t.data[14],k=t.data[15];e.data[0]=i*w+o*y+c*v+g*x,e.data[1]=s*w+a*y+d*v+_*x,e.data[2]=n*w+h*y+u*v+f*x,e.data[3]=r*w+l*y+p*v+m*x,e.data[4]=i*b+o*C+c*A+g*S,e.data[5]=s*b+a*C+d*A+_*S,e.data[6]=n*b+h*C+u*A+f*S,e.data[7]=r*b+l*C+p*A+m*S,e.data[8]=i*P+o*E+c*T+g*R,e.data[9]=s*P+a*E+d*T+_*R,e.data[10]=n*P+h*E+u*T+f*R,e.data[11]=r*P+l*E+p*T+m*R,e.data[12]=i*D+o*B+c*M+g*k,e.data[13]=s*D+a*B+d*M+_*k,e.data[14]=n*D+h*B+u*M+f*k,e.data[15]=r*D+l*B+p*M+m*k;const F=this.getScale();return e._scaleSignX=tt(F.x)*tt(e._scaleSignX),e._scaleSignY=tt(F.y)*tt(e._scaleSignY),e}translate(t,e){const i=this.data[0],s=this.data[1],n=this.data[2],r=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]=n*t+h*e+0*u+1*f,this.data[15]=r*t+l*e+0*p+1*m,this}setPosition(t,e){this.data[12]=t,this.data[13]=e}getPosition(){return q(this.data[12],this.data[13])}rotate(t){const e=this.data[0],i=this.data[1],s=this.data[2],n=this.data[3],r=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*r,this.data[1]=c*i+l*o,this.data[2]=c*s+l*a,this.data[3]=c*n+l*h,this.data[4]=c*r-l*e,this.data[5]=c*o-l*i,this.data[6]=c*a-l*s,this.data[7]=c*h-l*n,this}scale(t,e){const i=this.data[0],s=this.data[1],n=this.data[2],r=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]=n*t,this.data[3]=r*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 T(Math.atan2(this.data[1]/this.getScaleY(),this.data[0]/this.getScaleX()))}getScaleX(){const t=q(this.data[0],this.data[4]).size;return this._scaleSignX*t}getScaleY(){const t=q(this.data[1],this.data[5]).size;return this._scaleSignY*t}getScale(){return q(this.getScaleX(),this.getScaleY())}setScaleX(t){this._scaleSignX=tt(t);const e=q(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=tt(t);const e=q(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(){const t=1/this.getBasisDeterminant(),e=this.data[0],i=this.data[4],s=this.data[1],n=this.data[5],r=et.identity();r.data[0]=n*t,r.data[1]=-s*t,r.data[4]=-i*t,r.data[5]=e*t;const o=this.data[12],a=this.data[13];return r.data[12]=-(o*r.data[0]+a*r.data[4]),r.data[13]=-(o*r.data[1]+a*r.data[5]),r}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 it{constructor(){this._transforms=[],this._currentTransform=et.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 st{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}}class nt{constructor(t,e,i){this._gl=t,this._vertexSource=e,this._fragmentSource=i,this.program=null,this.uniforms={},this.attributes={},this.layout=[],this.compile(t)}_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.createShader(i);if(null===s)throw Error(`Could not build shader: [${e}]`);t.shaderSource(s,e),t.compileShader(s);if(!t.getShaderParameter(s,t.COMPILE_STATUS))throw Error(`Could not compile shader [${t.getShaderInfoLog(s)}]`);return s}compile(t){const e=this._compileShader(t,this._vertexSource,t.VERTEX_SHADER),i=this._compileShader(t,this._fragmentSource,t.FRAGMENT_SHADER),s=this._createProgram(t,e,i);return this.program=s}addUniformMatrix(t,e){if(!e)throw Error(`Shader Uniform Matrix '${t}' was set to null or undefined`);const i=this._gl;this.uniforms[t]={name:t,type:"matrix",location:i.getUniformLocation(this.program,t),data:e}}addUniformIntegerArray(t,e){if(!e)throw Error(`Shader Uniform Integery Array '${t}' was set to null or undefined`);const i=this._gl;this.uniforms[t]={name:t,type:"numbers",location:i.getUniformLocation(this.program,t),data:e}}addAttribute(t,e,i,s=!1){const n=this._gl.getAttribLocation(this.program,t);this.attributes[t]={name:t,size:e,glType:i,normalized:s,location:n},this.layout.push(this.attributes[t])}get vertexAttributeSize(){let t=0;for(const e of this.layout)t+=e.size;return t}get totalVertexSizeBytes(){let t=0;for(const e of this.layout){let i=1;if(e.glType===this._gl.FLOAT)i=4;else i=1;t+=i*e.size}return t}getAttributeSize(t){let e=1;if(this.attributes[t].glType===this._gl.FLOAT)e=4;else e=1;return e*this.attributes[t].size}use(){const t=this._gl;t.useProgram(this.program);let e=0;for(const i of this.layout)t.vertexAttribPointer(i.location,i.size,i.glType,i.normalized,this.totalVertexSizeBytes,e),t.enableVertexAttribArray(i.location),e+=this.getAttributeSize(i.name);for(const e in this.uniforms){const i=this.uniforms[e];switch(i.type){case"matrix":t.uniformMatrix4fv(i.location,!1,i.data);break;case"numbers":t.uniform1iv(i.location,i.data)}}}}class rt{constructor(t){this.max=t,this._pool=void 0,this.commands=[]}isFull(){return this.commands.length>=this.max}canAdd(){return!this.isFull()}add(t){this.commands.push(t)}dispose(){return this.commands.length=0,this}}class ot{static clear(){ot.DrawCallCount=0,ot.DrawnImagesCount=0}}ot.DrawCallCount=0,ot.DrawnImagesCount=0;class at{constructor(t,e,i=100){this.builder=t,this.recycler=e,this.maxObjects=i,this.totalAllocations=0,this.index=0,this.objects=[],this._logger=_.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++;const e=this.objects[this.index++]=this.builder(...t);return e._pool=this,e}}done(...t){this.index=0;for(const e of t){const t=this.objects.indexOf(e);this.objects[t]=this.builder(),this.objects[t]._pool=this,this.totalAllocations++,e._pool=void 0}return t}}class ht{constructor(t){var e,i,s;this.priority=0,this._buffer=null,this._maxCommandsPerBatch=2e3,this._batches=[],this._gl=t.gl;const n=t.command;this._verticesPerCommand=null!==(e=null==t?void 0:t.verticesPerCommand)&&void 0!==e?e:1,this._maxCommandsPerBatch=null!==(i=null==t?void 0:t.maxCommandsPerBatch)&&void 0!==i?i:this._maxCommandsPerBatch;const r=null!==(s=null==t?void 0:t.batchFactory)&&void 0!==s?s:()=>new rt(this._maxCommandsPerBatch);this.commands=new at((()=>new n),(t=>t.dispose()),this._maxCommandsPerBatch),this._batchPool=new at(r,(t=>t.dispose()),100)}init(){const t=this._gl;this.shader=this.buildShader(t),this._vertices=new Float32Array(this.shader.vertexAttributeSize*this._verticesPerCommand*this._maxCommandsPerBatch),this._buffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._buffer),t.bufferData(t.ARRAY_BUFFER,this._vertices,t.DYNAMIC_DRAW)}get vertexSize(){return this.shader.vertexAttributeSize}addCommand(t){0===this._batches.length&&this._batches.push(this._batchPool.get());const e=this._batches[this._batches.length-1];if(e.canAdd())e.add(t);else{const e=this._batchPool.get();e.add(t),this._batches.push(e)}}render(){const t=this._gl;t.bindBuffer(t.ARRAY_BUFFER,this._buffer),this.shader.use();let e=0,i=0;for(const s of this._batches){const n=this.buildBatchVertices(this._vertices,s);t.bufferSubData(t.ARRAY_BUFFER,0,this._vertices),this.renderBatch(t,s,n),i+=s.commands.length,e++}this.commands.done(),this._batchPool.done(),this._batches.length=0,ot.DrawCallCount+=e,ot.DrawnImagesCount+=i}}class lt{constructor(){this.color=Q.Black,this.start=K.Zero,this.end=K.Zero}dispose(){return this.color.r=0,this.color.g=0,this.color.b=0,this.color.a=1,this.start.setTo(0,0),this.end.setTo(0,0),this}}class ct extends ht{constructor(t,e){super({gl:t,command:lt,verticesPerCommand:2}),this._contextInfo=e,this.init()}buildShader(t){const e=new nt(t,"attribute vec4 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 * a_position;\r\n\r\n // Passthrough the color\r\n v_color = a_color;\r\n}","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}");return e.addAttribute("a_position",2,t.FLOAT),e.addAttribute("a_color",4,t.FLOAT),e.addUniformMatrix("u_matrix",this._contextInfo.matrix.data),e}addLine(t,e,i){const s=this.commands.get();s.start=this._contextInfo.transform.current.multv(t),s.end=this._contextInfo.transform.current.multv(e),s.color.r=i.r,s.color.g=i.g,s.color.b=i.b,s.color.a=s.color.a*this._contextInfo.state.current.opacity,this.addCommand(s)}buildBatchVertices(t,e){let i=0;for(const s of e.commands)t[i++]=s.start.x,t[i++]=s.start.y,t[i++]=s.color.r/255,t[i++]=s.color.g/255,t[i++]=s.color.b/255,t[i++]=s.color.a,t[i++]=s.end.x,t[i++]=s.end.y,t[i++]=s.color.r/255,t[i++]=s.color.g/255,t[i++]=s.color.b/255,t[i++]=s.color.a;return i/this.vertexSize}renderBatch(t,e,i){t.drawArrays(t.LINES,0,i)}}var dt;!function(t){t.Image="image",t.Line="line",t.Rectangle="rectangle",t.Circle="circle"}(dt||(dt={}));class ut{constructor(t,e,i,s,n,r,o,a,h){this._pool=void 0,this.snapToPixel=!0,this.type=dt.Image,this.opacity=1,this.width=0,this.height=0,this.dest=[0,0],this.view=[0,0,0,0],this._geom=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],this.init(t,e,i,s,n,r,o,a,h)}init(t,e,i,s,n,r,o,a,h){this.type=dt.Image,this.image=t,this.width=(null==t?void 0:t.width)||s||0,this.height=(null==t?void 0:t.height)||n||0,this.view=[0,0,null!=s?s:null==t?void 0:t.width,null!=n?n:null==t?void 0:t.height],this.dest=[e,i],void 0!==r&&void 0!==o&&void 0!==a&&void 0!==h&&(this.view=[e,i,null!=s?s:null==t?void 0:t.width,null!=n?n:null==t?void 0:t.height],this.dest=[r,o],this.width=a,this.height=h);let l=0;if(this._geom[l++]=[this.dest[0],this.dest[1]],this._geom[l++]=[this.dest[0],this.dest[1]+this.height],this._geom[l++]=[this.dest[0]+this.width,this.dest[1]],this._geom[l++]=[this.dest[0]+this.width,this.dest[1]],this._geom[l++]=[this.dest[0],this.dest[1]+this.height],this._geom[l++]=[this.dest[0]+this.width,this.dest[1]+this.height],this.snapToPixel)for(const t of this._geom)t[0]=~~t[0],t[1]=~~t[1];return this}initRect(t,e,i,s){this.type=dt.Rectangle,this.color=t,this.width=i,this.height=s;let n=0;if(this._geom[n++]=[e.x,e.y],this._geom[n++]=[e.x,e.y+this.height],this._geom[n++]=[e.x+this.width,e.y],this._geom[n++]=[e.x+this.width,e.y],this._geom[n++]=[e.x,e.y+this.height],this._geom[n++]=[e.x+this.width,e.y+this.height],this.snapToPixel)for(const t of this._geom)t[0]=~~t[0],t[1]=~~t[1];return this}initLine(t,e,i,s){this.type=dt.Line,this.color=t;const n=i.sub(e).normalize().perpendicular(),r=s/2,o=n.scale(r).add(e),a=n.scale(-r).add(e),h=n.scale(r).add(i),l=n.scale(-r).add(i);let c=0;if(this._geom[c++]=[o.x,o.y],this._geom[c++]=[h.x,h.y],this._geom[c++]=[a.x,a.y],this._geom[c++]=[a.x,a.y],this._geom[c++]=[h.x,h.y],this._geom[c++]=[l.x,l.y],this.snapToPixel)for(const t of this._geom)t[0]=~~t[0],t[1]=~~t[1];return this}initCircle(t,e,i){this.type=dt.Circle,this.color=i;const s=t.add(q(-e,-e)),n=t.add(q(e,-e)),r=t.add(q(e,e)),o=t.add(q(-e,e));let a=0;if(this._geom[a++]=[s.x,s.y],this._geom[a++]=[n.x,n.y],this._geom[a++]=[o.x,o.y],this._geom[a++]=[o.x,o.y],this._geom[a++]=[n.x,n.y],this._geom[a++]=[r.x,r.y],this.snapToPixel)for(const t of this._geom)t[0]=~~t[0],t[1]=~~t[1];return this}dispose(){this.image=null,this.width=0,this.height=0,this.view=[0,0,0,0],this.dest=[0,0];let t=0;return this._geom[t++]=[this.dest[0],this.dest[1]],this._geom[t++]=[this.dest[0],this.dest[1]+this.height],this._geom[t++]=[this.dest[0]+this.width,this.dest[1]],this._geom[t++]=[this.dest[0]+this.width,this.dest[1]],this._geom[t++]=[this.dest[0],this.dest[1]+this.height],this._geom[t++]=[this.dest[0]+this.width,this.dest[1]+this.height],this}applyTransform(t,e){if(t)for(let e=0;e<this._geom.length;e++)this._geom[e]=t.multv(this._geom[e]),this.snapToPixel&&(this._geom[e]=[~~this._geom[e][0],~~this._geom[e][1]]);this.opacity=e}get geometry(){return this._geom}}function pt(t){return 0==(t&t-1)}function gt(t){return pt(t)?t:function(t){--t;for(let e=1;e<32;e<<=1)t|=t>>e;return t+1}(t)}class _t{static registerContext(t){_t._GL=t}static get(t){return _t._TEXTURE_MAP.get(t)}static has(t){return _t._TEXTURE_MAP.has(t)}static load(t,e=!1){const i=_t._GL;if(!i)return null;let s=null;if(_t.has(t)&&(s=_t.get(t)),s){if(e){i.bindTexture(i.TEXTURE_2D,s);const e=_t.toPowerOfTwoImage(t);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,e)}return s}s=i.createTexture();const n=_t.toPowerOfTwoImage(t);return i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),_t._TEXTURE_MAP.set(t,s),s}static toPowerOfTwoImage(t){const e=_t._POT_CANVAS,i=_t._POT_CTX;return pt(t.width)&&pt(t.height)||(e.width=gt(t.width),e.height=gt(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}}_t._POT_CANVAS=document.createElement("canvas"),_t._POT_CTX=_t._POT_CANVAS.getContext("2d"),_t._TEXTURE_MAP=new Map;class ft extends rt{constructor(t,e){super(t),this.maxDraws=t,this.maxTextures=e,this.textures=[],this.commands=[],this._graphicMap={}}isFull(){return this.commands.length>=this.maxDraws||this.textures.length>=this.maxTextures}canAdd(){return!(this.commands.length>=this.maxDraws)&&this.textures.length<this.maxTextures}_isCommandFull(){return this.commands.length>=this.maxDraws}_isTextureFull(){return this.textures.length>=this.maxTextures}_wouldAddTexture(t){return!this._graphicMap[t.image.id]}maybeAdd(t){return(!this._isCommandFull()&&!this._isTextureFull()||!this._wouldAddTexture(t))&&(this.add(t),!0)}add(t){if(t.type===dt.Image){const e=_t.load(t.image);-1===this.textures.indexOf(e)&&this.textures.push(e)}this.commands.push(t)}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])}getBatchTextureId(t){return t.image?this.textures.indexOf(_t.get(t.image)):-1}dispose(){return this.clear(),this}clear(){this.commands.length=0,this.textures.length=0,this._graphicMap={}}}class mt extends ht{constructor(t,e){super({gl:t,command:ut,verticesPerCommand:6,maxCommandsPerBatch:2e3,batchFactory:()=>new ft(2e3,t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS))}),this._contextInfo=e,_t.registerContext(t),this.init()}buildShader(t){const e=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),i=new nt(t,"attribute vec4 a_position;\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\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 * a_position;\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 // Pass through the color to the fragment shader\r\n v_color = a_color;\r\n}",this._transformFragmentSource("#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_texcoord;\r\n\r\n// Texture index\r\nvarying lowp float v_textureIndex;\r\n\r\n// Color coord to blend with image\r\nvarying lowp vec4 v_color;\r\n\r\n// Opacity\r\nvarying float v_opacity;\r\n\r\nuniform sampler2D u_textures[%%count%%];\r\n\r\nfloat circle(in vec2 st, in float radius) {\r\n vec2 dist = st - vec2(0.5);\r\n float r = dot(dist, dist) * 4.0;\r\n float delta = fwidth(r);\r\n return 1.0 - smoothstep(radius - delta, radius + delta, r);\r\n}\r\n\r\nvoid main() {\r\n float r = 0.0, delta = 0.0, alpha = 1.0;\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;\r\n // -1 If there is no texture to sample we are drawing a solid geometry (rectangles)\r\n if (v_textureIndex == -1.0) {\r\n color = v_color;\r\n color.w = color.w * v_opacity;\r\n // -2 If there is no texture we are drawing a circle\r\n } else if (v_textureIndex == -2.0) {\r\n color = v_color;\r\n color.a = color.a * circle(v_texcoord, .95);\r\n } else {\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.w = color.w * v_opacity;\r\n gl_FragColor = color;\r\n}",e));return i.addAttribute("a_position",3,t.FLOAT),i.addAttribute("a_texcoord",2,t.FLOAT),i.addAttribute("a_textureIndex",1,t.FLOAT),i.addAttribute("a_opacity",1,t.FLOAT),i.addAttribute("a_color",4,t.FLOAT),i.addUniformMatrix("u_matrix",this._contextInfo.matrix.data),i.addUniformIntegerArray("u_textures",[...Array(e)].map(((t,e)=>e))),i}_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}addCircle(t,e,i){const s=this.commands.get().initCircle(t,e,i);s.applyTransform(this._contextInfo.transform.current,this._contextInfo.state.current.opacity),this.addCommand(s)}addRectangle(t,e,i,s){const n=this.commands.get().initRect(t,e,i,s);n.applyTransform(this._contextInfo.transform.current,this._contextInfo.state.current.opacity),this.addCommand(n)}addLine(t,e,i,s=1){const n=this.commands.get().initLine(t,e,i,s);n.applyTransform(this._contextInfo.transform.current,this._contextInfo.state.current.opacity),this.addCommand(n)}addImage(t,e,i,s,n,r,o,a,h){const l=this.commands.get().init(t,e,i,s,n,r,o,a,h);l.applyTransform(this._contextInfo.transform.current,this._contextInfo.state.current.opacity),this.addCommand(l)}renderBatch(t,e,i){e.bindTextures(t),t.drawArrays(t.TRIANGLES,0,i)}buildBatchVertices(t,e){var i,s;let n=0,r=0,o=0,a=0,h=0,l=1,c=1,d=0,u=Q.Transparent;for(const p of e.commands){r=p.view[0],o=p.view[1],a=p.view[2],h=p.view[3],l=gt((null===(i=p.image)||void 0===i?void 0:i.width)||p.width),c=gt((null===(s=p.image)||void 0===s?void 0:s.height)||p.height),d=e.getBatchTextureId(p),p.type!==dt.Line&&p.type!==dt.Rectangle||(d=-1,u=p.color),p.type===dt.Circle&&(d=-2,u=p.color);let g=r/l,_=o/c,f=(r+a)/l,m=(o+h)/c;-2===d&&(g=0,_=0,f=1,m=1),t[n++]=p.geometry[0][0],t[n++]=p.geometry[0][1],t[n++]=0,t[n++]=g,t[n++]=_,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a,t[n++]=p.geometry[1][0],t[n++]=p.geometry[1][1],t[n++]=0,t[n++]=g,t[n++]=m,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a,t[n++]=p.geometry[2][0],t[n++]=p.geometry[2][1],t[n++]=0,t[n++]=f,t[n++]=_,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a,t[n++]=p.geometry[3][0],t[n++]=p.geometry[3][1],t[n++]=0,t[n++]=f,t[n++]=_,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a,t[n++]=p.geometry[4][0],t[n++]=p.geometry[4][1],t[n++]=0,t[n++]=g,t[n++]=m,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a,t[n++]=p.geometry[5][0],t[n++]=p.geometry[5][1],t[n++]=0,t[n++]=f,t[n++]=m,t[n++]=d,t[n++]=p.opacity,t[n++]=u.r/255,t[n++]=u.g/255,t[n++]=u.b/255,t[n++]=u.a}return n/this.vertexSize}}class wt{constructor(){this.point=K.Zero,this.color=Q.Black,this.size=1}dispose(){return this.point.setTo(0,0),this.color.r=0,this.color.g=0,this.color.b=0,this.color.a=1,this.size=1,this}}class yt extends ht{constructor(t,e){super({gl:t,command:wt,verticesPerCommand:1}),this._contextInfo=e,this.init()}buildShader(t){t.getExtension("OES_standard_derivatives");const e=new nt(t,"attribute vec4 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 * a_position;\r\n gl_PointSize = a_size * 2.0;\r\n v_color = a_color;\r\n}","#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 gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);\r\n}");return e.addAttribute("a_position",2,t.FLOAT),e.addAttribute("a_color",4,t.FLOAT),e.addAttribute("a_size",1,t.FLOAT),e.addUniformMatrix("u_matrix",this._contextInfo.matrix.data),e}addPoint(t,e,i){const s=this.commands.get();s.point=this._contextInfo.transform.current.multv(t),s.color.r=e.r,s.color.g=e.g,s.color.b=e.b,s.color.a=e.a*this._contextInfo.state.current.opacity,s.size=i*Math.max(this._contextInfo.transform.current.getScaleX(),this._contextInfo.transform.current.getScaleY()),this.addCommand(s)}buildBatchVertices(t,e){let i=0;for(const s of e.commands)t[i++]=s.point.x,t[i++]=s.point.y,t[i++]=s.color.r/255,t[i++]=s.color.g/255,t[i++]=s.color.b/255,t[i++]=s.color.a,t[i++]=s.size;return i/this.vertexSize}renderBatch(t,e,i){t.drawArrays(t.POINTS,0,i)}}class vt{constructor(t){var e,i,s,n,r,o;this.id=vt._ID++,this.showDebug=!1,this.flipHorizontal=!1,this.flipVertical=!1,this.rotation=0,this.opacity=1,this.scale=K.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!==(n=t.rotation)&&void 0!==n?n:this.rotation,this.opacity=null!==(r=t.opacity)&&void 0!==r?r:this.opacity,this.scale=null!==(o=t.scale)&&void 0!==o?o:this.scale)}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}set height(t){this._height=t}get localBounds(){return J.fromDimension(this.width,this.height,K.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),t.scale(Math.abs(this.scale.x),Math.abs(this.scale.y)),this._rotate(t),this._flip(t),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,n=null!==(e=this.origin)&&void 0!==e?e:q(this.width/2,this.height/2);t.translate(n.x,n.y),t.rotate(this.rotation),t.scale(i,s),t.translate(-n.x,-n.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 xt(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 bt(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}vt._ID=0;class Ct extends vt{constructor(t){var e,i,s,n,r,o,a;super(t),this._dirty=!0,this._smoothing=!1,this._color=xt(Q.Black,(()=>this.flagDirty())),this._lineWidth=1,this._lineDash=[],this._padding=0,t&&(this.color=null!==(e=t.color)&&void 0!==e?e:Q.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!==(n=t.lineDash)&&void 0!==n?n:this.lineDash,this.padding=null!==(r=t.padding)&&void 0!==r?r:this.padding),this._bitmap=document.createElement("canvas");const h=null!==(o=null==t?void 0:t.width)&&void 0!==o?o:this._bitmap.width,l=null!==(a=null==t?void 0:t.height)&&void 0!==a?a:this._bitmap.height;this.width=gt(h),this.height=gt(l);const c=this._bitmap.getContext("2d");if(!c)throw new Error("Browser does not support 2d canvas drawing, cannot create Raster graphic");this._ctx=c}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 this._getTotalWidth()}set width(t){this._bitmap.width=t,this._originalWidth=t,this.flagDirty()}get height(){return this._getTotalHeight()}set height(t){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 J.fromDimension(this._getTotalWidth()*this.scale.x,this._getTotalHeight()*this.scale.y,K.Zero)}get smoothing(){return this._smoothing}set smoothing(t){this._smoothing=t,this.flagDirty()}get color(){return this._color}set color(t){var e;(null===(e=this._color)||void 0===e?void 0:e.equal(t))||this.flagDirty(),this._color=xt(t,(()=>this.flagDirty()))}get strokeColor(){return this._strokeColor}set strokeColor(t){var e;(null===(e=this._strokeColor)||void 0===e?void 0:e.equal(t))||this.flagDirty(),this._strokeColor=xt(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._applyRasterProperites(this._ctx),this.execute(this._ctx),this._ctx.restore(),_t.load(this._bitmap,!0)}_applyRasterProperites(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 At extends Ct{constructor(t){super(t),this._options=t}get ctx(){return this._ctx}clone(){return new At(Object.assign(Object.assign(Object.assign({},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()}}var St;!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"}(St||(St={}));class Pt{constructor(){this._bubbles=!0}get bubbles(){return this._bubbles}set bubbles(t){this._bubbles=t}stopPropagation(){this.bubbles=!1}}class Et extends Pt{constructor(t){super(),this.target=t}}class Tt extends Pt{constructor(t){super(),this.target=t}}class Rt extends Pt{constructor(t){super(),this.target=t}}class Dt extends Pt{constructor(t){super(),this.target=t}}class Bt extends Pt{constructor(t){super(),this.target=t}}class Mt extends Pt{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class kt extends Pt{constructor(t,e,i){super(),this.ctx=t,this.delta=e,this.target=i}}class Ft extends Pt{constructor(t,e){super(),this.ctx=t,this.target=e}}class Lt extends Pt{constructor(t,e){super(),this.ctx=t,this.target=e}}class It extends Pt{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class Ot extends Pt{constructor(t,e,i){super(),this.engine=t,this.delta=e,this.target=i}}class zt extends Pt{constructor(t,e){super(),this.engine=t,this.prevStats=e,this.target=t}}class Ut extends Pt{constructor(t,e){super(),this.engine=t,this.stats=e,this.target=t}}class Ht extends Pt{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Nt extends Pt{constructor(t,e){super(),this.index=t,this.gamepad=e,this.target=e}}class Wt extends Pt{constructor(t,e,i){super(),this.button=t,this.value=e,this.target=i}}class Vt extends Pt{constructor(t,e,i){super(),this.axis=t,this.value=e,this.target=i}}class Gt extends Pt{constructor(t,e){super(),this.topic=t,this.handler=e}}class jt extends Pt{constructor(t,e){super(),this.topic=t,this.handler=e}}class Xt extends Pt{constructor(t){super(),this.target=t}}class Kt extends Pt{constructor(t){super(),this.target=t}}class qt extends Pt{constructor(t,e,i,s){super(),this.other=e,this.side=i,this.intersection=s,this.target=t}}class Zt extends Pt{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 Qt{constructor(t,e){this.target=t,this.other=e}}class $t{constructor(t,e,i,s,n){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=n}}class Jt{constructor(t,e,i,s,n){this.target=t,this.other=e,this.side=i,this.intersection=s,this.contact=n}}class te extends Pt{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 ee extends Pt{constructor(t,e){super(),this.other=e,this.target=t}get actor(){return this.target}set actor(t){this.target=t}}class ie extends Pt{constructor(t,e){super(),this.engine=t,this.target=e}}class se extends Pt{constructor(t,e){super(),this.oldScene=t,this.target=e}}class ne extends Pt{constructor(t,e){super(),this.newScene=t,this.target=e}}class re extends Pt{constructor(t){super(),this.target=t}}class oe extends Pt{constructor(t){super(),this.target=t}}class ae extends Pt{constructor(t,e){super(),this.target=t,this.actor=e}}class he extends Pt{constructor(t,e){super(),this.target=t,this.actor=e}}class le{constructor(t){this._handlers={},this._wiredEventDispatchers=[],this._target=t}clear(){this._handlers={},this._wiredEventDispatchers=[]}emit(t,e){if(!t)return;t=t.toLowerCase();const i=this._target;e||(e=new Pt);try{e.target||(e.target=i)}catch(t){}let s,n;if(this._handlers[t])for(s=0,n=this._handlers[t].length;s<n;s++)this._handlers[t][s].call(i,e);for(s=0,n=this._wiredEventDispatchers.length;s<n;s++)this._wiredEventDispatchers[s].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 jt(t,e))}once(t,e){this.on(t,(i=>{const s=i||new Pt;try{s.target=s.target||this._target}catch(t){}this.off(t,e),e.call(s.target,s)}))}wire(t){t._wiredEventDispatchers.push(this)}unwire(t){const e=t._wiredEventDispatchers.indexOf(this);e>-1&&t._wiredEventDispatchers.splice(e,1)}}class ce{constructor(t,e,i=!0){this.path=t,this.responseType=e,this.bustCache=i,this.data=null,this.logger=_.getInstance(),this.events=new le(this)}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 de=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};let ue=class{updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data,r=(n[s+0]+n[s+1]+n[s+2])/3;n[s+0]=r,n[s+1]=r,n[s+2]=r}};ue=de([j({message:"Grayscale will be removed in v0.26.0"})],ue);let pe=class{updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data;n[s+0]=255-n[s+0],n[s+1]=255-n[s+1],n[s+2]=255-n[s+2]}};pe=de([j({message:"Invert will be removed in v0.26.0"})],pe);let ge=class{constructor(t){this.opacity=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data;0!==n[s+3]&&(n[s+3]=Math.round(this.opacity*n[s+3]))}};ge=de([j({message:"Opacity will be removed in v0.26.0"})],ge);let _e=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data;0!==n[s+3]&&(n[s+0]=(n[s+0]+this.color.r)/2,n[s+1]=(n[s+1]+this.color.g)/2,n[s+2]=(n[s+2]+this.color.b)/2)}};_e=de([j({message:"Colorize 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),n=i.data,r=Q.fromRGB(n[s+0],n[s+1],n[s+2],n[s+3]).lighten(this.factor);n[s+0]=r.r,n[s+1]=r.g,n[s+2]=r.b,n[s+3]=r.a}};fe=de([j({message:"Lighten will be removed in v0.26.0"})],fe);let me=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data,r=Q.fromRGB(n[s+0],n[s+1],n[s+2],n[s+3]).darken(this.factor);n[s+0]=r.r,n[s+1]=r.g,n[s+2]=r.b,n[s+3]=r.a}};me=de([j({message:"Darken will be removed v0.26.0"})],me);let we=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data,r=Q.fromRGB(n[s+0],n[s+1],n[s+2],n[s+3]).saturate(this.factor);n[s+0]=r.r,n[s+1]=r.g,n[s+2]=r.b,n[s+3]=r.a}};we=de([j({message:"Saturate will be removed in v0.26.0"})],we);let ye=class{constructor(t=.1){this.factor=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data,r=Q.fromRGB(n[s+0],n[s+1],n[s+2],n[s+3]).desaturate(this.factor);n[s+0]=r.r,n[s+1]=r.g,n[s+2]=r.b,n[s+3]=r.a}};ye=de([j({message:"Desaturate will be removed in v0.26.0"})],ye);let ve=class{constructor(t){this.color=t}updatePixel(t,e,i){const s=4*(t+e*i.width),n=i.data;0!==n[s+3]&&(n[s+0]=this.color.r,n[s+1]=this.color.g,n[s+2]=this.color.b)}};ve=de([j({message:"Fill will be removed in v0.26.0"})],ve);var xe=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class be{constructor(t,e=!0){this.path=t,this.bustCache=e,this._sprite=null,this.loaded=new Promise((t=>{this._loadedResolve=t})),this._resource=new ce(t,"blob",e),this._sprite=new Ee(this,0,0,0,0)}get image(){return this.data}isLoaded(){return!!this.data}load(){return xe(this,void 0,void 0,(function*(){try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=yield this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,yield e.decode(),this.data=e,this.width=this._sprite.width=e.naturalWidth,this.height=this._sprite.height=e.naturalHeight,this._sprite=new Ee(this,0,0,this.width,this.height)}catch(t){yield Promise.reject("Error loading texture")}return this._loadedResolve(this.data),this.data}))}asSprite(){return this._sprite}}function Ce(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 Ae=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o},Se=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class Pe{constructor(t,e,i,s,n){this.x=0,this.y=0,this.rotation=0,this.anchor=K.Half,this.offset=K.Zero,this.scale=K.One,this.drawAroundAnchor=!1,this.logger=_.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 r=t;if(t&&!(t instanceof be)&&(e=0|t.x,i=0|t.y,s=0|t.width,n=0|t.height,r=t.image,!r)){throw new Error("An image texture is required to construct a sprite")}this.x=e||0,this.y=i||0,this.texture=r,this._spriteCanvas=document.createElement("canvas"),this._spriteCanvas.width=s,this._spriteCanvas.height=n,this._spriteCtx=this._spriteCanvas.getContext("2d"),this._initPixelsFromTexture(),this.width=s,this.height=n}get drawWidth(){return Math.abs(this.width*this.scale.x)}get drawHeight(){return Math.abs(this.height*this.scale.y)}_initPixelsFromTexture(){return Se(this,void 0,void 0,(function*(){try{const t=yield 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,S(this.x,0,t),S(this.y,0,e),S(this.width,0,t),S(this.height,0,e),0,0,this.width,this.height)}opacity(t){this._opacity=t}grayscale(){this.addEffect(new ue)}invert(){this.addEffect(new pe)}fill(t){this.addEffect(new ve(t))}colorize(t){this.addEffect(new _e(t))}lighten(t=.1){this.addEffect(new fe(t))}darken(t=.1){this.addEffect(new me(t))}saturate(t=.1){this.addEffect(new we(t))}desaturate(t=.1){this.addEffect(new ye(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,n=this.drawHeight*this.anchor.y;t.strokeStyle=Q.Black.toString(),t.strokeRect(-s,-n,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,n,r,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:w,flipHorizontal:y,flipVertical:v}=Object.assign(Object.assign({},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!==(n=t.flipHorizontal)&&void 0!==n?n:this.flipHorizontal,flipVertical:null!==(r=t.flipVertical)&&void 0!==r?r: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,A=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,A),c.translate(-x,-b),y&&(c.translate(g,0),c.scale(-1,1)),v&&(c.translate(0,_),c.scale(1,-1));const S=c.globalAlpha;c.globalAlpha=w,c.drawImage(this._spriteCanvas,0,0,this.width,this.height,0,0,this.width,this.height),c.globalAlpha=S,c.restore()}clone(){const t=new Ee(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 Ee=class extends(Ce(Pe)){constructor(t,e,i,s,n){super(t,e,i,s,n)}};Ee=Ae([j({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Ee);class Te extends vt{constructor(t){var e,i;super(t),this.image=t.image;const{width:s,height:n}=t;this.sourceView=null!==(e=t.sourceView)&&void 0!==e?e:{x:0,y:0,width:null!=s?s:0,height:null!=n?n:0},this.destSize=null!==(i=t.destSize)&&void 0!==i?i:{width:null!=s?s:0,height:null!=n?n:0},this._updateSpriteDimensions(),this.image.ready.then((()=>{this._updateSpriteDimensions()}))}static from(t){return new Te({image:t})}_updateSpriteDimensions(){var t,e,i,s,n,r;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===(n=this.destSize)||void 0===n?void 0:n.height)||(null===(r=this.sourceView)||void 0===r?void 0:r.height)||a,this.width=Math.ceil(this.destSize.width),this.height=Math.ceil(this.destSize.height)}_preDraw(t,e,i){this.image.isLoaded()&&this._updateSpriteDimensions(),super._preDraw(t,e,i)}_drawImage(t,e,i){this.image.isLoaded()&&(this._updateSpriteDimensions(),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=De.fromLegacyTexture(e);return new Te({image:i,sourceView:{x:t.x,y:t.y,width:t.width,height:t.height}})}static toLegacySprite(t){const e=t.image,i=new be(e.path);return i.data=e.image,new Ee(i,t.sourceView.x,t.sourceView.y,t.sourceView.width,t.sourceView.height)}clone(){return new Te(Object.assign({image:this.image,sourceView:Object.assign({},this.sourceView),destSize:Object.assign({},this.destSize)},this.cloneGraphicOptions()))}}var Re=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class De{constructor(t,e=!1){this.path=t,this._logger=_.getInstance(),this.data=new Image,this._resource=new ce(t,"blob",e),(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.data.src}get image(){return this.data}load(){return Re(this,void 0,void 0,(function*(){if(this.isLoaded())return this.data;try{let t;if(this.path.includes("data:image/"))t=this.path;else{const e=yield this._resource.load();t=URL.createObjectURL(e)}const e=new Image;e.src=t,yield e.decode(),this.data=e}catch(t){throw`Error loading ImageSource from path '${this.path}' with error [${t.message}]`}return this._loadedResolve(this.data),this.data}))}toSprite(){return Te.from(this)}static fromLegacyTexture(t){const e=new De(t.path);return t.isLoaded()?e.data=t.data:t.loaded.then((()=>{e.data=t.data})),e}unload(){this.data=new Image}}var Be=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Me{constructor(t,e,i,s){this.sprites=[],this.currentFrame=0,this._timeLeftInFrame=0,this._idempotencyToken=-1,this.anchor=K.Zero,this.rotation=0,this.scale=K.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 n=t;if(t&&!(t instanceof pr)){const r=t;n=r.engine,e=r.sprites,i=r.speed,s=r.loop}this.sprites=e,this.speed=i,this._engine=n,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 ue)}invert(){this.addEffect(new pe)}fill(t){this.addEffect(new ve(t))}colorize(t){this.addEffect(new _e(t))}lighten(t=.1){this.addEffect(new fe(t))}darken(t=.1){this.addEffect(new me(t))}saturate(t=.1){this.addEffect(new we(t))}desaturate(t=.1){this.addEffect(new ye(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,n,r,o,a,h;const l=Object.assign(Object.assign({},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!==(n=t.flipHorizontal)&&void 0!==n?n:this.flipHorizontal,flipVertical:null!==(r=t.flipVertical)&&void 0!==r?r: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[S(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 ke=class extends(Ce(Me)){constructor(t,e,i,s){super(t,e,i,s)}};var Fe,Le,Ie,Oe,ze;ke=Be([j({message:"Animation will be removed in v0.26.0",alternateMethod:"Use Graphics.Animation"})],ke),function(t){t.Em="em",t.Rem="rem",t.Px="px",t.Pt="pt",t.Percent="%"}(Fe||(Fe={})),function(t){t.Left="left",t.Right="right",t.Center="center",t.Start="start",t.End="end"}(Le||(Le={})),function(t){t.Top="top",t.Hanging="hanging",t.Middle="middle",t.Alphabetic="alphabetic",t.Ideographic="ideographic",t.Bottom="bottom"}(Ie||(Ie={})),function(t){t.Normal="normal",t.Italic="italic",t.Oblique="oblique"}(Oe||(Oe={})),function(t){t.LeftToRight="ltr",t.RightToLeft="rtl"}(ze||(ze={}));var Ue=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class He{constructor(t,e,i,s,n,r){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 be?(this._image=t,this._columns=e,this._rows=i,this._spWidth=s,this._spHeight=n,this._spacing=r||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 be){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 Ee(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 ke(t,s,i)}getAnimationBetween(t,e,i,s){let n=this.sprites.slice(e,i);return n=n.map((function(t){return t.clone()})),new ke(t,n,s)}getAnimationForAll(t,e){const i=this.sprites.map((function(t){return t.clone()}));return new ke(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,n=0;const r=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),n=Math.max(n,i.drawHeight),r[t]=new Ee(i)}const o=new ke(t,r,i);return o.drawWidth=s,o.drawHeight=n,o}}let Ne=class extends He{constructor(t,e,i,s,n,r,o,a){super(t instanceof be?{image:t,spWidth:r,spHeight:o,rows:n,columns:s,spacing:a||0}:t),this._currentColor=Q.Black,this._currentOpacity=1,this._spriteRecord={},this._textShadowOn=!1,this._textShadowDirty=!0,this._textShadowColor=Q.Black,this._textShadowSprites={},this._shadowOffsetX=5,this._shadowOffsetY=5,!t||t instanceof be||(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,n){if(n=this._parseOptions(n),this._currentColor.toString()!==n.color.toString()||this._currentOpacity!==n.opacity){this._currentOpacity=n.opacity,this._currentColor=n.color;for(const t in this._spriteRecord)this._spriteRecord[t].clearEffects(),this._spriteRecord[t].fill(n.color),this._spriteRecord[t].opacity(n.opacity)}if(this._textShadowOn&&this._textShadowDirty&&this._textShadowColor){for(const t in this._textShadowSprites)this._textShadowSprites[t].clearEffects(),this._textShadowSprites[t].addEffect(new ve(this._textShadowColor.clone()));this._textShadowDirty=!1}const r=this.sprites[0],o=r.height,a=n.fontSize/o,h=e.length*r.width*a+e.length*n.letterSpacing;let l=i;n.textAlign===Le.Left||n.textAlign===Le.Start?l=i:n.textAlign===Le.Right||n.textAlign===Le.End?l=i-h:n.textAlign===Le.Center&&(l=i-h/2);let c=s-o*a;n.baseAlign===Ie.Top||n.baseAlign===Ie.Hanging?c=s:n.baseAlign===Ie.Ideographic||n.baseAlign===Ie.Bottom||n.baseAlign===Ie.Alphabetic?c=s-o*a:n.baseAlign===Ie.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=q(a,a),this._textShadowSprites[s].draw(t,l+this._shadowOffsetX,c+this._shadowOffsetY));const e=this._spriteRecord[s];e.drawAroundAnchor=!1,e.scale=q(a,a),e.draw(t,l,c),l+=e.drawWidth+n.letterSpacing}catch(t){_.getInstance().error(`SpriteFont Error drawing char ${s}`)}}}_parseOptions(t){return{fontSize:t.fontSize||10,letterSpacing:t.letterSpacing||0,color:t.color||Q.Black,textAlign:void 0===typeof t.textAlign?Le.Left:t.textAlign,baseAlign:void 0===typeof t.baseAlign?Ie.Bottom:t.baseAlign,maxWidth:t.maxWidth||-1,opacity:t.opacity||0}}};Ne=Ue([j({message:"SpriteSheet will be removed in v0.26.0",alternateMethod:"Use Graphics.SpriteSheet"})],Ne);class We{constructor(t){this._logger=_.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=>Te.fromLegacySprite(t)));return new We({sprites:e})}static toLegacySpriteSheet(t){const e=t.sprites.map((t=>Te.toLegacySprite(t)));return new He(e)}static fromImageSource(t){var e;const i=[];t.spacing=null!==(e=t.spacing)&&void 0!==e?e:{};const{image:s,grid:{rows:n,columns:r,spriteWidth:o,spriteHeight:a},spacing:{originOffset:h,margin:l}}=t,c=Object.assign({x:0,y:0},h),d=Object.assign({x:0,y:0},l);for(let t=0;t<r;t++)for(let e=0;e<n;e++)i[t+e*r]=new Te({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 We({sprites:i,rows:n,columns:r})}}class Ve extends vt{constructor(t){super(t),this._text="",this._dirty=!0,this.alphabet="",this.shadow=null,this.caseInsensitive=!1,this.spacing=0,this._logger=_.getInstance(),this._sprites=[];const{alphabet:e,spriteSheet:i,caseInsensitive:s,spacing:n,shadow:r}=t;this.alphabet=e,this.spriteSheet=i,this.caseInsensitive=null!=s?s:this.caseInsensitive,this.spacing=null!=n?n:this.spacing,this.shadow=null!=r?r:this.shadow,this.spriteSheet.sprites[0].image.ready.then((()=>{this._updateDimensions()}))}static fromLegacySpriteFont(t){const e=t.sprites.map(Te.fromLegacySprite);return new Ve({alphabet:t.alphabet,spacing:0,caseInsensitive:t.caseInsensitive,spriteSheet:new We({sprites:e})})}_getCharacterSprites(t){if(!this._dirty)return this._sprites;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 n=i[t];let r=s.indexOf(n);-1===r&&(r=0,this._logger.warn(`SpriteFont - Cannot find letter '${n}' in configured alphabet '${s}'`));const o=this.spriteSheet.sprites[r];o?e.push(o):this._logger.warn(`SpriteFont - Cannot find sprite for '${n}' at index '${r}' in configured SpriteSheet`)}return this._dirty=!1,this._sprites=e}_updateDimensions(){const t=this._getCharacterSprites(this._text);let e=0,i=0;for(const s of t)e+=s.width+this.spacing,i=Math.max(i,s.height);this.width=e,this.height=i}updateText(t){this._text!==t&&(this._dirty=!0,this._text=t,this._updateDimensions())}_preDraw(t,e,i){this._updateDimensions(),super._preDraw(t,e,i)}_drawImage(t,e,i){let s=0;for(const n of this._getCharacterSprites(this._text))n.draw(t,e+s,i),s+=n.width+this.spacing}render(t,e,i,s){this._text!==e&&(this._dirty=!0,this._text=e),this.shadow&&(t.save(),t.translate(this.shadow.offset.x,this.shadow.offset.y),this.draw(t,i,s),t.restore()),this.draw(t,i,s)}clone(){return new Ve({alphabet:this.alphabet,spriteSheet:this.spriteSheet,spacing:this.spacing})}}class Ge{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 De(this.fontSheet),this._imageSource.load().then((()=>{this._spriteSheet=We.fromImageSource({image:this._imageSource,grid:{rows:3,columns:16,spriteWidth:16,spriteHeight:16}}),this._spriteFont=new Ve({alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ,!'&.\"?-()+ ",caseInsensitive:!0,spriteSheet:this._spriteSheet,spacing:-6})}))}write(t,e,i){this._imageSource.isLoaded()&&this._spriteFont.render(t,e,i.x,i.y)}}class je{constructor(t){this._webglCtx=t,this._debugText=new Ge}drawRect(t,e,i,s,n={color:Q.Black}){this.drawLine(q(t,e),q(t+i,e),Object.assign({},n)),this.drawLine(q(t+i,e),q(t+i,e+s),Object.assign({},n)),this.drawLine(q(t+i,e+s),q(t,e+s),Object.assign({},n)),this.drawLine(q(t,e+s),q(t,e),Object.assign({},n))}drawLine(t,e,i={color:Q.Black}){this._webglCtx.__lineRenderer.addLine(t,e,i.color)}drawPoint(t,e={color:Q.Black,size:5}){this._webglCtx.__pointRenderer.addPoint(t,e.color,e.size)}drawText(t,e){this._debugText.write(this._webglCtx,t,e)}}class Xe{constructor(t){this._transform=new it,this._state=new st,this.snapToPixel=!0,this.smoothing=!1,this.backgroundColor=Q.ExcaliburBlue,this.debug=new je(this);const{canvasElement:e,enableTransparency:i,smoothing:s,snapToPixel:n,backgroundColor:r}=t;this.__gl=e.getContext("webgl",{antialias:null!=s?s:this.smoothing,premultipliedAlpha:!1,alpha:null==i||i,depth:!0,powerPreference:"high-performance"}),this.snapToPixel=null!=n?n:this.snapToPixel,this.smoothing=null!=s?s:this.smoothing,this.backgroundColor=null!=r?r: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}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=et.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.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),this.__pointRenderer=new yt(t,{matrix:this._ortho,transform:this._transform,state:this._state}),this.__lineRenderer=new ct(t,{matrix:this._ortho,transform:this._transform,state:this._state}),this.__imageRenderer=new mt(t,{matrix:this._ortho,transform:this._transform,state:this._state}),this._canvas=new At({width:t.canvas.width,height:t.canvas.height}),this.__ctx=this._canvas.ctx}resetTransform(){this._transform.current=et.identity()}updateViewport(){const t=this.__gl;this._ortho=this._ortho=et.ortho(0,t.canvas.width,t.canvas.height,0,400,-400),this.__pointRenderer.shader.addUniformMatrix("u_matrix",this._ortho.data),this.__lineRenderer.shader.addUniformMatrix("u_matrix",this._ortho.data),this.__imageRenderer.shader.addUniformMatrix("u_matrix",this._ortho.data),this._canvas.width=t.canvas.width,this._canvas.height=t.canvas.height}drawImage(t,e,i,s,n,r,o,a,h){if(0!==s&&0!==n&&0!==a&&0!==h&&0!==t.width&&0!==t.height)return t?void this.__imageRenderer.addImage(t,e,i,s,n,r,o,a,h):(_.getInstance().warn("Cannot draw a null or undefined image"),void(console.trace&&console.trace()))}drawLine(t,e,i,s=1){this.__imageRenderer.addLine(i,t,e,s)}drawRectangle(t,e,i,s){this.__imageRenderer.addRectangle(s,t,e,i)}drawCircle(t,e,i){this.__imageRenderer.addCircle(t,e,i)}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}clear(){const t=this.__gl;t.clearColor(this.backgroundColor.r/255,this.backgroundColor.g/255,this.backgroundColor.b/255,this.backgroundColor.a),t.clear(t.COLOR_BUFFER_BIT),ot.clear()}flush(){const t=this.__gl;t.viewport(0,0,t.canvas.width,t.canvas.height),this.__imageRenderer.render(),this.__lineRenderer.render(),this.__pointRenderer.render()}}var Ke;!function(t){t.Fixed="Fixed",t.FitScreen="FitScreen",t.FillScreen="FillScreen",t.FitContainer="FitContainer",t.FillContainer="FillContainer",t.Position="Position"}(Ke||(Ke={}));class qe{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 Ze{constructor(t){var e,i,s;this._antialiasing=!0,this._resolutionStack=[],this._viewportStack=[],this._pixelRatioOverride=null,this._isFullScreen=!1,this._isDisposed=!1,this._logger=_.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._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:Object.assign({},this.viewport),this._displayMode=null!==(i=t.displayMode)&&void 0!==i?i:Ke.Fixed,this._canvas=t.canvas,this._ctx=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._mediaQueryList=this._browser.window.nativeComponent.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._mediaQueryList.addEventListener("change",this._pixelRatioChangeHandler),this._canvas.addEventListener("fullscreenchange",this._fullscreenChangeHandler),this.applyResolutionAndViewport()}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("change",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===Ke.FillContainer||this.displayMode===Ke.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=Object.assign({},this.resolution),this.viewport=Object.assign({},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._ctx instanceof Xe){this._ctx.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._ctx.updateViewport(),this._ctx.resetTransform(),this._ctx.scale(this.pixelRatio,this.pixelRatio),this._ctx.smoothing=this._antialiasing}get antialiasing(){return this._antialiasing}set antialiasing(t){this._antialiasing=t,this._ctx.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-=B(this._canvas).x,i-=B(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 K(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+=B(this._canvas).x,i+=B(this._canvas).y),new K(e,i)}screenToWorldCoordinates(t){var e,i,s,n;let r=t.x,o=t.y;return r=r/this.resolution.width*this.drawWidth,o=o/this.resolution.height*this.drawHeight,r-=this.halfDrawWidth,o-=this.halfDrawHeight,r+=null!==(i=null===(e=this._camera)||void 0===e?void 0:e.x)&&void 0!==i?i:0,o+=null!==(n=null===(s=this._camera)||void 0===s?void 0:s.y)&&void 0!==n?n:0,new K(r,o)}worldToScreenCoordinates(t){var e,i,s,n;let r=t.x,o=t.y;return r-=null!==(i=null===(e=this._camera)||void 0===e?void 0:e.x)&&void 0!==i?i:0,o-=null!==(n=null===(s=this._camera)||void 0===s?void 0:s.y)&&void 0!==n?n:0,r+=this.halfDrawWidth,o+=this.halfDrawHeight,r=r/this.drawWidth*this.resolution.width,o=o/this.drawHeight*this.resolution.height,new K(r,o)}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(K.Zero).x,e=this.screenToWorldCoordinates(K.Zero).y,i=t+this.drawWidth,s=e+this.drawHeight;return new J(t,e,i,s)}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 q(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===Ke.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===Ke.FillContainer&&(this.resolution={width:t.clientWidth,height:t.clientHeight},this.viewport=this.resolution),this.displayMode===Ke.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===Ke.FitScreen&&this._computeFit(),this.displayMode===Ke.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 Ye{static create(){return this._INSTANCE||(window.AudioContext||window.webkitAudioContext)&&(this._INSTANCE=new AudioContext),this._INSTANCE}}Ye._INSTANCE=null;class Qe{static unlock(){return new Promise(((t,e)=>{if(Qe._UNLOCKED||!Ye.create())return t(!0);const i=setTimeout((()=>{_.getInstance().warn("Excalibur was unable to unlock the audio context, audio probably will not play in this browser."),t(!1)}),200),s=Ye.create();s.resume().then((()=>{const e=s.createBuffer(1,1,22050),n=s.createBufferSource();let r=!1;n.buffer=e,n.connect(s.destination),n.onended=()=>r=!0,n.start(0),setTimeout((()=>{!function(t){return!!t.playbackState}(n)?(s.currentTime>0||r)&&(Qe._UNLOCKED=!0):n.playbackState!==n.PLAYING_STATE&&n.playbackState!==n.FINISHED_STATE||(Qe._UNLOCKED=!0)}),0),clearTimeout(i),t(!0)}),(()=>{e()}))}))}static isUnlocked(){return this._UNLOCKED}}Qe._UNLOCKED=!1;class $e{constructor(){this.eventDispatcher=new le(this)}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 Je(t,e=Q.Red,i,s,n,r,o=1,a="butt"){t.beginPath(),t.lineWidth=o,t.lineCap=a,t.strokeStyle=e.toString(),t.moveTo(i,s),t.lineTo(n,r),t.closePath(),t.stroke()}function ti(t,e=Q.Red,i){t.beginPath(),t.strokeStyle=e.toString(),t.arc(i.x,i.y,5,0,2*Math.PI),t.closePath(),t.stroke()}function ei(t,e,i,s,n=1){const r=e?e.toString():"blue",o=s.scale(n);t.beginPath(),t.strokeStyle=r,t.moveTo(i.x,i.y),t.lineTo(i.x+o.x,i.y+o.y),t.closePath(),t.stroke()}function ii(t,e,i,s,n,r=5,o=Q.White,a=null){let h;if("number"==typeof r)h={tl:r,tr:r,br:r,bl:r};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]=r[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+n-h.br),t.quadraticCurveTo(e+s,i+n,e+s-h.br,i+n),t.lineTo(e+h.bl,i+n),t.quadraticCurveTo(e,i+n,e,i+n-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 si(t,e,i,s,n=Q.White,r=null){t.beginPath(),t.arc(e,i,s,0,2*Math.PI),t.closePath(),r&&(t.fillStyle=r.toString(),t.fill()),n&&(t.strokeStyle=n.toString(),t.stroke())}var ni=i(1388),ri=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class oi extends $e{constructor(t){super(),this.canvas=new At({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=Q.White,this.backgroundColor="#176BAA",this.suppressPlayButton=!1,this._playButtonStyles=ni.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},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}showPlayButton(){var t;if(this.suppressPlayButton)return this.hidePlayButton(),Promise.resolve();{const e=()=>{this._positionPlayButton()};(null===(t=this._engine)||void 0===t?void 0:t.browser)&&this._engine.browser.window.on("resize",e),this._playButtonShown=!0,this._playButton.style.display="block",document.body.addEventListener("keyup",(t=>{"Enter"===t.key&&this._playButton.click()}));const i=new Promise((t=>{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",e),t()};this._playButton.addEventListener("click",i),this._playButton.addEventListener("touchend",i),this._playButton.addEventListener("pointerup",i)}));return i}}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){}load(){return ri(this,void 0,void 0,(function*(){return yield Promise.all(this._resourceList.map((t=>t.load().finally((()=>{this._numLoaded++}))))),yield H(200),yield this.showPlayButton(),yield Qe.unlock(),this.data=this._resourceList}))}markResourceComplete(){this._numLoaded++}get progress(){return this._resourceCount>0?S(this._numLoaded,0,this._resourceCount)/this._resourceCount:1}_positionPlayButton(){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,n=this._playButton.clientWidth,r=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-n/2+"px",this._playButtonRootElement.style.top=s+t/2-r/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 n=Math.min(this.logoWidth,.75*i);let r=i/2-n/2;this.logoPosition&&(r=this.logoPosition.x,s=this.logoPosition.y);const o=Math.floor(n*(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,r,s,n,o):t.drawImage(this._image,0,0,this.logoWidth,this.logoHeight,r,s-o-20,n,o),!this.suppressPlayButton&&this._playButtonShown)return void this._engine.setAntialiasing(a);let h=r,l=s;this.loadingBarPosition&&(h=this.loadingBarPosition.x,l=this.loadingBarPosition.y),t.lineWidth=2,ii(t,h,l,n,20,10,this.loadingBarColor);const c=n*this.progress-10;ii(t,h+5,l+5,c>10?c:10,10,5,null,this.loadingBarColor),this._engine.setAntialiasing(a)}}const ai={webgl:"WebGL",webaudio:"WebAudio",gamepadapi:"Gamepad API"};class hi{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(ai))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+=" "+ai[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),_.getInstance().error("Critical browser feature missing, Excalibur requires:",e),t=!0);if(t)return!1;for(const t in this._warningTest)this._warningTest[t]()||_.getInstance().warn("Warning browser feature missing, Excalibur will have reduced performance:",t);return!0}}var li;!function(t){t.PreventCollision="PreventCollision",t.Passive="Passive",t.Active="Active",t.Fixed="Fixed"}(li||(li={}));var ci,di,ui,pi=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};!function(t){t.Arcade="arcade",t.Realistic="realistic"}(ci||(ci={})),function(t){t[t.DynamicAABBTree=0]="DynamicAABBTree"}(di||(di={})),function(t){t[t.Euler=0]="Euler"}(ui||(ui={}));class gi{static get gravity(){return gi.acc}static set gravity(t){gi.acc=t}static useArcadePhysics(){gi.collisionResolutionStrategy=ci.Arcade}static useRealisticPhysics(){gi.collisionResolutionStrategy=ci.Realistic}static get dynamicTreeVelocityMultiplyer(){return gi.dynamicTreeVelocityMultiplier}static set dynamicTreeVelocityMultiplyer(t){gi.dynamicTreeVelocityMultiplier=t}}gi.acc=new K(0,0),gi.enabled=!0,gi.broadphaseStrategy=di.DynamicAABBTree,gi.collisionResolutionStrategy=ci.Arcade,gi.defaultMass=10,gi.integrator=ui.Euler,gi.dynamicTreeVelocityMultiplier=2,gi.boundsPadding=5,gi.positionIterations=3,gi.velocityIterations=8,gi.slop=1,gi.steeringFactor=.2,gi.warmStart=!0,gi.bodiesCanSleepByDefault=!1,gi.surfaceEpsilon=.1,gi.sleepEpsilon=.07,gi.wakeThreshold=3*gi.sleepEpsilon,gi.sleepBias=.9,gi.checkForFastBodies=!0,gi.disableMinimumSpeedForFastBody=!1,pi([j({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"dynamicTreeVelocityMultiplier"})],gi,"dynamicTreeVelocityMultiplyer",null);class _i extends K{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 fi{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 mi extends fi{constructor(t,e){super(),this.type=t,this.value=e}}var wi;!function(t){t.World="world",t.Screen="screen"}(wi||(wi={}));class yi extends fi{constructor(){super(...arguments),this.type="ex.transform",this._dirty=!1,this.matrix=et.identity().translate(0,0).rotate(0).scale(1,1),this._position=(t=>{const e=t;return new _i({setX:t=>{e.data[Z.X]=t},setY:t=>{e.data[Z.Y]=t},getX:()=>e.data[Z.X],getY:()=>e.data[Z.Y]})})(this.matrix),this._rotation=0,this._scale=(t=>{const e=t;return new _i({setX:t=>{e.setScaleX(t)},setY:t=>{e.setScaleY(t)},getX:()=>e.getScaleX(),getY:()=>e.getScaleY()})})(this.matrix),this.coordPlane=wi.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(yi)}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 _i({getX:()=>t.data[Z.X],getY:()=>t.data[Z.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[Z.Y]]);this.matrix.data[Z.X]=s}else this.matrix.data[Z.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[Z.X],e]);this.matrix.data[Z.Y]=s}else this.matrix.data[Z.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 _i({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?q(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 vi extends fi{constructor(){super(...arguments),this.type="ex.motion",this.vel=K.Zero,this.acc=K.Zero,this.scaleFactor=K.Zero,this.angularVelocity=0,this.torque=0,this.inertia=1}}class xi{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 xi("~("+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 xi(e,i,~i)}static collidesWith(t){return xi.combine(t).invert()}}xi.All=new xi("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 Ci{constructor(t,e){this.colliderA=t,this.colliderB=e,this.id=null,this.id=Ci.calculatePairHash(t.id,e.id)}static canCollide(t,e){var i,s;const n=null===(i=null==t?void 0:t.owner)||void 0===i?void 0:i.get(Vi),r=null===(s=null==e?void 0:e.owner)||void 0===s?void 0:s.get(Vi);return!(!n||!r)&&(!!n.group.canCollide(r.group)&&((n.collisionType!==li.Fixed||r.collisionType!==li.Fixed)&&(r.collisionType!==li.PreventCollision&&n.collisionType!==li.PreventCollision&&!(!n.active||!r.active))))}get canCollide(){const t=this.colliderA,e=this.colliderB;return Ci.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 Ai{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 Si{constructor(t){this.parent=t,this.parent=t||null,this.data=null,this.bounds=new J,this.left=null,this.right=null,this.height=0}isLeaf(){return!this.left&&!this.right}}class Pi{constructor(t=new J(-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,n=i.bounds.getPerimeter(),r=i.bounds.combine(e).getPerimeter(),o=2*r,a=2*(r-n);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,n=new Si(s);n.bounds=e.combine(i.bounds),n.height=i.height+1,null!==s?(s.left===i?s.left=n:s.right=n,n.left=i,n.right=t,i.parent=n,t.parent=n):(n.left=i,n.right=t,i.parent=n,t.parent=n,this.root=n);let r=t.parent;for(;r;){if(r=this._balance(r),!r.left)throw new Error("Parent of current leaf cannot have a null left child"+r);if(!r.right)throw new Error("Parent of current leaf cannot have a null right child"+r);r.height=1+Math.max(r.left.height,r.right.height),r.bounds=r.left.bounds.combine(r.right.bounds),r=r.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 Si;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 _.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-=gi.boundsPadding,s.top-=gi.boundsPadding,s.right+=gi.boundsPadding,s.bottom+=gi.boundsPadding,t.owner){const i=null===(e=t.owner)||void 0===e?void 0:e.get(Vi);if(i){const t=32*i.vel.x/1e3*gi.dynamicTreeVelocityMultiplier,e=32*i.vel.y/1e3*gi.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,n=e,r=i,o=e.left,a=e.right,h=i.left,l=i.right,c=r.height-n.height;if(c>1)return r.left=s,r.parent=s.parent,s.parent=r,r.parent?r.parent.left===s?r.parent.left=r:r.parent.right=r:this.root=r,h.height>l.height?(r.right=h,s.right=l,l.parent=s,s.bounds=n.bounds.combine(l.bounds),r.bounds=s.bounds.combine(h.bounds),s.height=1+Math.max(n.height,l.height),r.height=1+Math.max(s.height,h.height)):(r.right=l,s.right=h,h.parent=s,s.bounds=n.bounds.combine(h.bounds),r.bounds=s.bounds.combine(l.bounds),s.height=1+Math.max(n.height,h.height),r.height=1+Math.max(s.height,l.height)),r;if(c<-1){if(n.left=s,n.parent=s.parent,s.parent=n,n.parent)if(n.parent.left===s)n.parent.left=n;else{if(n.parent.right!==s)throw"Error rotating Dynamic Tree";n.parent.right=n}else this.root=n;return o.height>a.height?(n.right=o,s.left=a,a.parent=s,s.bounds=r.bounds.combine(a.bounds),n.bounds=s.bounds.combine(o.bounds),s.height=1+Math.max(r.height,a.height),n.height=1+Math.max(s.height,o.height)):(n.right=a,s.left=o,o.parent=s,s.bounds=r.bounds.combine(o.bounds),n.bounds=s.bounds.combine(a.bounds),s.height=1+Math.max(r.height,o.height),n.height=1+Math.max(s.height,a.height)),n}return t}getHeight(){return null===this.root?0:this.root.height}query(t,e){const i=t.bounds,s=n=>{if(n&&n.bounds.intersect(i)){if(!n.isLeaf()||n.data===t)return s(n.left)||s(n.right);if(e.call(t,n.data))return!0}return!1};s(this.root)}rayCastQuery(t,e=1/0,i){const s=n=>{if(n&&n.bounds.rayCast(t,e)){if(!n.isLeaf())return s(n.left)||s(n.right);if(i.call(t,n.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,Q.Green):i.bounds.draw(t,Q.White),i.left&&e(i.left),i.right&&e(i.right))};e(this.root)}}class Ei{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 n=e.cross(this.dir)/i/t.getLength();if(n>=0&&n<=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 Ti{constructor(){this._dynamicCollisionTree=new Pi,this._collisions=new Set,this._collisionPairCache=[],this._colliders=[]}getColliders(){return this._colliders}track(t){if(t)if(t instanceof Di){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 _.getInstance().warn("Cannot track null collider")}untrack(t){if(t)if(t instanceof Di){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 _.getInstance().warn("Cannot untrack a null collider")}_shouldGenerateCollisionPair(t,e){if(null!==t.id&&null!==e.id&&t.id===e.id||null!==t.owner&&null!==e.owner&&t.owner===e.owner)return!1;const i=Ci.calculatePairHash(t.id,e.id);return!this._collisions.has(i)&&(!t.localBounds.hasZeroDimensions()&&!e.localBounds.hasZeroDimensions()&&Ci.canCollide(t,e))}broadphase(t,e,i){const s=e/1e3,n=t.filter((t=>{var e,i;const s=null===(e=t.owner)||void 0===e?void 0:e.get(Vi);return(null===(i=t.owner)||void 0===i?void 0:i.active)&&s.collisionType!==li.PreventCollision}));let r;this._collisionPairCache=[],this._collisions.clear();for(let t=0,e=n.length;t<e;t++)r=n[t],this._dynamicCollisionTree.query(r,(t=>{if(this._shouldGenerateCollisionPair(r,t)){const e=new Ci(r,t);this._collisions.add(e.id),this._collisionPairCache.push(e)}return!1}));if(i&&(i.physics.pairs=this._collisionPairCache.length),gi.checkForFastBodies)for(const t of n){const e=t.owner.get(Vi);if(e.collisionType!==li.Active)continue;const n=e.vel.size*s+.5*e.acc.size*s*s,r=Math.min(t.bounds.height,t.bounds.width);if(gi.disableMinimumSpeedForFastBody||n>r/2){i&&i.physics.fastBodies++;const s=e.pos.sub(e.oldPos),r=t.center,o=t.getFurthestPoint(e.vel),a=o.sub(s),h=new Ei(a,e.vel);let l;h.pos=h.pos.add(h.dir.scale(-2*gi.surfaceEpsilon));let c=new K(1/0,1/0);if(this._dynamicCollisionTree.rayCastQuery(h,n+2*gi.surfaceEpsilon,(e=>{if(t!==e&&Ci.canCollide(t,e)){const t=e.rayCast(h,n+10*gi.surfaceEpsilon);if(t){const i=t.sub(a);i.size<c.size&&(c=i,l=e)}}return!1})),l&&K.isValid(c)){const s=new Ci(t,l);this._collisions.has(s.id)||(this._collisions.add(s.id),this._collisionPairCache.push(s));const n=r.sub(o);e.pos=a.add(n).add(c).add(h.dir.scale(10*gi.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 n=t[s].collide();if(i=i.concat(n),e&&n.length>0)for(const t of n)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 Ri{constructor(){this.id=g("collider",Ri._ID++),this.events=new le(this)}touching(t){return!!this.collide(t)}}Ri._ID=0;class Di extends Ri{constructor(t){super(),this._collisionProcessor=new Ti,this._dynamicAABBTree=new Pi,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),k(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:K.Zero}get center(){var t,e;return null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:K.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 J).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 J)}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],n=-Number.MAX_VALUE;for(const e of i){const i=e.dot(t);i>n&&(s=e,n=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 Di&&(e=t.getColliders());const i=[];for(const t of e)this._dynamicAABBTree.query(t,(e=>(i.push(new Ci(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 Di){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 n of i){const i=n.rayCast(t,e);i&&s.push(i)}if(s.length){let e=s[0],i=e.dot(t.dir);for(const n of s){const s=t.dir.dot(n);s<i&&(e=n,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 Ai(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 n of s)n.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 Di(this._colliders.map((t=>t.clone())))}}class Bi{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 Bi(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,n=i.dot(this.end)-e,r=[];if(s<=0&&r.push(this.begin),n<=0&&r.push(this.end),s*n<0){const t=s/(s-n);r.push(this.begin.add(this.end.sub(this.begin).scale(t)))}return 2!==r.length?null:new Bi(r[0],r[1])}distanceToPoint(t,e=!1){const i=t.x,s=t.y,n=this.getLength(),r=((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)/n;return e?r:Math.abs(r)}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 K(t,i*t+s);if(null!==e)return new K((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 K(arguments[0],arguments[1]),e=arguments[2]||0;else{if(!(arguments[0]instanceof K))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,n=this.end.x-this.begin.x,r=this.end.y-this.begin.y,o=i*r-s*n;return!(Math.abs(o)>e)&&(Math.abs(n)>=Math.abs(r)?n>0?this.begin.x<=t.x&&t.x<=this.end.x:this.end.x<=t.x&&t.x<=this.begin.x:r>0?this.begin.y<=t.y&&t.y<=this.end.y:this.end.y<=t.y&&t.y<=this.begin.y)}}function Mi(t,e,i,s){const n=t.sub(i),r=e.dot(e),o=e.dot(s),a=s.dot(s),h=e.dot(n),l=s.dot(n),c=r*a-o*o;let d=c,u=c;if(0===c||c<=.01){const e=h/o;return new Bi(t,i.add(s.scale(e)))}let p=o*l-a*h,g=r*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>r?p=d:(p=-h,d=r)):g>u&&(g=u,-h+o<0?p=0:-h+o>r?p=d:(p=-h+o,d=r)),p=Math.abs(p)<.001?0:p/d,g=Math.abs(g)<.001?0:g/u,new Bi(t.add(e.scale(p)),i.add(s.scale(g)))}const ki={PolygonPolygonClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),n=s.negate(),r=new Ei(t.worldPos,s),o=new Ei(i,n),a=t.rayCast(r).add(r.dir.scale(.1)),h=e.rayCast(o).add(o.dir.scale(.1)),l=t.getClosestFace(a),c=e.getClosestFace(h);return Mi(l.face.begin,l.face.getEdge(),c.face.begin,c.face.getEdge())},PolygonEdgeClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=new Ei(t.worldPos,i),n=t.rayCast(s).add(s.dir.scale(.1)),r=t.getClosestFace(n),o=r.face.begin,a=r.face.getEdge(),h=e.asLine();return Mi(o,a,h.begin,h.getEdge())},PolygonCircleClosestLine(t,e){const i=e.worldPos,s=i.sub(t.worldPos),n=new Ei(t.worldPos,s.normalize()),r=t.rayCast(n).add(n.dir.scale(.1)),o=t.getClosestFace(r),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 Bi(h.scale(l).add(a),new K(i.x+d,i.y+u))},CircleCircleClosestLine(t,e){const i=e.worldPos.sub(t.worldPos),s=t.worldPos.sub(e.worldPos),n=new Ei(t.worldPos,i),r=new Ei(e.worldPos,s),o=t.rayCast(n),a=e.rayCast(r);return new Bi(o,a)},CircleEdgeClosestLine(t,e){const i=t.worldPos,s=e.asLine(),n=s.begin,r=s.getEdge();let o=(r.x*(i.x-n.x)+r.y*(i.y-n.y))/(r.x*r.x+r.y*r.y);o>1?o=1:o<0&&(o=0);const a=Math.sqrt(Math.pow(n.x+r.x*o-i.x,2)+Math.pow(n.y+r.y*o-i.y,2))-t.radius,h=(n.x+r.x*o-i.x)*t.radius/(t.radius+a),l=(n.y+r.y*o-i.y)*t.radius/(t.radius+a);return new Bi(r.scale(o).add(n),new K(i.x+h,i.y+l))},EdgeEdgeClosestLine(t,e){const i=t.asLine(),s=i.begin,n=i.getEdge(),r=e.asLine();return Mi(s,n,r.begin,r.getEdge())}};class Fi extends Ri{constructor(t){super(),this.offset=K.Zero,this.offset=t.offset||K.Zero,this.radius=t.radius||0}get worldPos(){var t,e;return this.offset.add(null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:K.Zero)}clone(){return new Fi({offset:this.offset.clone(),radius:this.radius})}get center(){var t,e;return this.offset.add(null!==(e=null===(t=this._transform)||void 0===t?void 0:t.pos)&&void 0!==e?e:K.Zero)}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,n=t.pos,r=Math.sqrt(Math.pow(s.dot(n.sub(i)),2)-Math.pow(n.sub(i).distance(),2)+Math.pow(this.radius,2));if(r<0)return null;{let o=0;if(0===r)return o=-s.dot(n.sub(i)),o>0&&o<e?t.getPoint(o):null;{const o=-s.dot(n.sub(i))+r,a=-s.dot(n.sub(i))-r,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 Fi)return ki.CircleCircleClosestLine(this,t);if(t instanceof Ui)return ki.PolygonCircleClosestLine(t,this).flip();if(t instanceof zi)return ki.CircleEdgeClosestLine(this,t).flip();throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Fi)return Oi.CollideCircleCircle(this,t);if(t instanceof Ui)return Oi.CollideCirclePolygon(this,t);if(t instanceof zi)return Oi.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;const e=this._transform,i=null!==(t=null==e?void 0:e.globalPos)&&void 0!==t?t:K.Zero;return new J(this.offset.x+i.x-this.radius,this.offset.y+i.y-this.radius,this.offset.x+i.x+this.radius,this.offset.y+i.y+this.radius)}get localBounds(){return new J(this.offset.x-this.radius,this.offset.y-this.radius,this.offset.x+this.radius,this.offset.y+this.radius)}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 Ai(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=Q.Green,i=K.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){const i=this._transform,s=(null==i?void 0:i.globalPos)?null==i?void 0:i.globalPos.add(this.offset):this.offset;t.drawCircle(s,this.radius,e)}debugDraw(t,e=Q.Green){const i=this._transform,s=i?i.pos.add(this.offset):this.offset,n=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(n)*this.radius+s.x,Math.sin(n)*this.radius+s.y),t.closePath(),t.stroke()}}class Li{constructor(t,e,i,s,n,r,o,a){this._canceled=!1,this.colliderA=t,this.colliderB=e,this.mtv=i,this.normal=s,this.tangent=n,this.points=r,this.localPoints=o,this.info=a,this.id=Ci.calculatePairHash(t.id,e.id)}matchAwake(){const t=this.colliderA.owner.get(Vi),e=this.colliderB.owner.get(Vi);t&&e&&t.sleeping!==e.sleeping&&(t.sleeping&&t.collisionType!==li.Fixed&&e.sleepMotion>=gi.wakeThreshold&&t.setSleeping(!1),e.sleeping&&e.collisionType!==li.Fixed&&t.sleepMotion>=gi.wakeThreshold&&e.setSleeping(!1))}isCanceled(){return this._canceled}cancel(){this._canceled=!0}}class Ii{static findPolygonPolygonSeparation(t,e){let i=-Number.MAX_VALUE,s=null,n=null,r=-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,n=l,r=t,o=c)}return{collider:t,separation:n?i:99,axis:n,side:s,localSide:h[r],sideId:r,point:o,localPoint:n?e.getFurthestLocalPoint(n.negate()):null}}static findCirclePolygonSeparation(t,e){const i=e.axes,s=e.center.sub(t.worldPos),n=e.getFurthestPoint(s.negate());i.push(n.sub(t.worldPos).normalize());let r=Number.MAX_VALUE,o=null,a=-1;for(let s=0;s<i.length;s++){const n=e.project(i[s]),h=t.project(i[s]),l=n.getOverlap(h);if(l<=0)return null;l<r&&(r=l,o=i[s],a=s)}return a<0?null:o.normalize().scale(r)}}const Oi={CollideCircleCircle(t,e){const i=t.worldPos,s=e.worldPos,n=t.radius+e.radius,r=i.distance(s);if(r>n)return[];const o=n-r,a=s.sub(i).normalize(),h=a.perpendicular(),l=a.scale(o),c=t.getFurthestPoint(a),d=t.getFurthestLocalPoint(a);return[new Li(t,e,l,a,h,[c],[d],{collider:t,separation:o,axis:a,point:c})]},CollideCirclePolygon(t,e){var i,s;let n=Ii.findCirclePolygonSeparation(t,e);if(!n)return[];const r=n.dot(e.center.sub(t.center));n=r<0?n.negate():n;const o=t.getFurthestPoint(n),a=(null!==(s=null===(i=t.owner)||void 0===i?void 0:i.get(yi))&&void 0!==s?s:new yi).applyInverse(o),h=n.normalize(),l={collider:t,separation:-n.size,axis:h,point:o,localPoint:a,side:e.findSide(h.negate()),localSide:e.findLocalSide(h.negate())};return[new Li(t,e,n,h,h.perpendicular(),[o],[a],l)]},CollideCircleEdge(t,e){const i=t.center,s=e.asLine(),n=s.end.sub(s.begin),r=n.dot(s.end.sub(i)),o=n.dot(i.sub(s.begin)),a=e.asLine(),h=e.asLocalLine();if(o<=0){const n=s.begin.sub(i),r=n.dot(n);if(r>t.radius*t.radius)return[];const o=n.normalize(),l=t.radius-Math.sqrt(r),c={collider:t,separation:l,axis:o,point:a.begin,side:a,localSide:h};return[new Li(t,e,o.scale(l),o,o.perpendicular(),[a.begin],[h.begin],c)]}if(r<=0){const n=s.end.sub(i),r=n.dot(n);if(r>t.radius*t.radius)return[];const o=n.normalize(),l=t.radius-Math.sqrt(r),c={collider:t,separation:l,axis:o,point:a.end,side:a,localSide:h};return[new Li(t,e,o.scale(l),o,o.perpendicular(),[a.end],[h.end],c)]}const l=n.dot(n),c=s.begin.scale(r).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=n.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 Li(t,e,_,p.negate(),p.negate().perpendicular(),[c],[c.sub(e.worldPos)],f)]},CollideEdgeEdge:()=>[],CollidePolygonEdge(t,e){var i;const s=t.center,n=e.center.sub(s).normalize(),r=new Ui({points:[e.begin,e.end,e.end.add(n.scale(100)),e.begin.add(n.scale(100))],offset:e.offset});r.owner=e.owner;(null===(i=e.owner)||void 0===i?void 0:i.get(yi))&&r.update(e.owner.get(yi));const o=this.CollidePolygonPolygon(t,r);return o.length&&(o[0].colliderB=e,o[0].id=Ci.calculatePairHash(t.id,e.id)),o},CollidePolygonPolygon(t,e){var i,s,n,r;const o=Ii.findPolygonPolygonSeparation(t,e);if(o.separation>0)return[];const a=Ii.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(yi))&&void 0!==s?s:new yi;d=o.map((e=>t.applyInverse(e)))}else{const e=null!==(r=null===(n=t.owner)||void 0===n?void 0:n.get(yi))&&void 0!==r?r:new yi;d=o.map((t=>e.applyInverse(t)))}return[new Li(t,e,a.scale(-h.separation),a,l,o,d,h)]}return[]},FindContactSeparation(t,e){var i,s,n,r;const o=t.colliderA,a=null!==(s=null===(i=t.colliderA.owner)||void 0===i?void 0:i.get(yi))&&void 0!==s?s:new yi,h=t.colliderB,l=null!==(r=null===(n=t.colliderB.owner)||void 0===n?void 0:n.get(yi))&&void 0!==r?r:new yi;if(o instanceof Fi&&h instanceof Fi){return-(o.radius+h.radius-a.pos.distance(l.pos))}if(o instanceof Ui&&h instanceof Ui&&t.info.localSide){let i,s;return t.info.collider===o?(i=new Bi(a.apply(t.info.localSide.begin),a.apply(t.info.localSide.end)),s=l.apply(e)):(i=new Bi(l.apply(t.info.localSide.begin),l.apply(t.info.localSide.end)),s=a.apply(e)),i.distanceToPoint(s,!0)}if(o instanceof Ui&&h instanceof Fi||h instanceof Ui&&o instanceof Fi){const i=a.apply(e);if(t.info.side)return t.info.side.distanceToPoint(i,!0)}if(o instanceof zi&&h instanceof Ui||h instanceof zi&&o instanceof Ui){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 Fi&&h instanceof zi||h instanceof Fi&&o instanceof zi){const i=l.apply(e);let s;o instanceof Fi&&(s=o.getFurthestPoint(t.normal));const n=i.distance(s);if(t.info.side)return n>0?-n:0}return 0}};class zi extends Ri{constructor(t){var e;super(),this.begin=t.begin||K.Zero,this.end=t.end||K.Zero,this.offset=null!==(e=t.offset)&&void 0!==e?e:K.Zero}clone(){return new zi({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:K.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 n=i.cross(this.getSlope())/s;if(n>=0&&n<=e){const e=i.cross(t.dir)/s/this.getLength();if(e>=0&&e<=1)return t.getPoint(n)}return null}getClosestLineBetween(t){if(t instanceof Fi)return ki.CircleEdgeClosestLine(t,this);if(t instanceof Ui)return ki.PolygonEdgeClosestLine(t,this).flip();if(t instanceof zi)return ki.EdgeEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Fi)return Oi.CollideCircleEdge(t,this);if(t instanceof Ui)return Oi.CollidePolygonEdge(t,this);if(t instanceof zi)return Oi.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 J(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 Bi(this._getTransformedBegin(),this._getTransformedEnd())}asLocalLine(){return new Bi(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 n=0;n<s;n++)e.push(i[n].dot(t));return new Ai(Math.min.apply(Math,e),Math.max.apply(Math,e))}draw(t,e=Q.Green,i=K.Zero){const s=this.begin.add(i),n=this.end.add(i);t.strokeStyle=e.toString(),t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(n.x,n.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=Q.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 Ui extends Ri{constructor(t){var e;super(),this._transformedPoints=[],this._axes=[],this._sides=[],this._localSides=[],this.offset=null!==(e=t.offset)&&void 0!==e?e:K.Zero;const i=!!t.clockwiseWinding;this.points=(i?t.points.reverse():t.points)||[],this._calculateTransformation()}clone(){return new Ui({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:K.One,n=this.points.length;this._transformedPoints.length=0;for(let t=0;t<n;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 Bi(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 Bi(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 n=0;n<e.length;n++){const r=e[n],o=r.normal().dot(t);o>s&&(i=r,s=o)}return i}findLocalSide(t){const e=this.getLocalSides();let i=e[0],s=-Number.MAX_VALUE;for(let n=0;n<e.length;n++){const r=e[n],o=r.normal().dot(t);o>s&&(i=r,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 Ei(t,new K(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 Fi)return ki.PolygonCircleClosestLine(this,t);if(t instanceof Ui)return ki.PolygonPolygonClosestLine(this,t);if(t instanceof zi)return ki.PolygonEdgeClosestLine(this,t);throw new Error("Polygon could not collide with unknown CollisionShape "+typeof t)}collide(t){if(t instanceof Fi)return Oi.CollideCirclePolygon(t,this);if(t instanceof Ui)return Oi.CollidePolygonPolygon(this,t);if(t instanceof zi)return Oi.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 n=0;n<e.length;n++){const r=t.dot(e[n]);r>s&&(s=r,i=e[n])}return i}getFurthestLocalPoint(t){const e=this.points;let i=e[0],s=-Number.MAX_VALUE;for(let n=0;n<e.length;n++){const r=t.dot(e[n]);r>s&&(s=r,i=e[n])}return i}getClosestFace(t){const e=this.getSides();let i=Number.POSITIVE_INFINITY,s=-1,n=-1;for(let r=0;r<e.length;r++){const o=e[r].distanceToPoint(t);o<i&&(i=o,s=r,n=o)}return-1!==s?{distance:e[s].normal().scale(n),face:e[s]}:null}get bounds(){var t,e,i;const s=this._transform,n=null!==(t=null==s?void 0:s.globalScale)&&void 0!==t?t:K.One,r=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:K.Zero).add(this.offset);return this.localBounds.scale(n).rotate(r).translate(o)}get localBounds(){return J.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,n=this.points[s].cross(this.points[t]);e+=n*(this.points[t].dot(this.points[t])+this.points[t].dot(this.points[s])+this.points[s].dot(this.points[s])),i+=n}return t/6*(e/i)}rayCast(t,e=1/0){const i=this.getSides(),s=i.length;let n=Number.MAX_VALUE,r=-1;for(let o=0;o<s;o++){const s=t.intersect(i[o]);s>=0&&s<n&&s<=e&&(n=s,r=o)}return r>=0?t.getPoint(n):null}project(t){const e=this.getTransformedPoints(),i=e.length;let s=Number.MAX_VALUE,n=-Number.MAX_VALUE;for(let r=0;r<i;r++){const i=e[r].dot(t);s=Math.min(s,i),n=Math.max(n,i)}return new Ai(s,n)}draw(t,e=Q.Green,i=K.Zero){const s=i.add(this.offset);t.beginPath(),t.fillStyle=e.toString();const n=this.points[0].add(s);t.moveTo(n.x,n.y),this.points.map((t=>t.add(s))).forEach((function(e){t.lineTo(e.x,e.y)})),t.lineTo(n.x,n.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=Q.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 Hi{static Box(t,e,i=K.Half,s=K.Zero){return new Ui({points:new J(-t*i.x,-e*i.y,t-t*i.x,e-e*i.y).getPoints(),offset:s})}static Polygon(t,e=!1,i=K.Zero){return new Ui({points:t,offset:i,clockwiseWinding:e})}static Circle(t,e=K.Zero){return new Fi({radius:t,offset:e})}static Edge(t,e){return new zi({begin:t,end:e})}static Capsule(t,e,i=K.Zero){const s=_.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 Di([Hi.Circle(t/2,q(0,-e/2+t/2).add(i)),Hi.Box(t,e-t,K.Half,i),Hi.Circle(t/2,q(0,e/2-t/2).add(i))])}return new Di([Hi.Circle(e/2,q(-t/2+e/2,0).add(i)),Hi.Box(t-e,e,K.Half,i),Hi.Circle(e/2,q(t/2-e/2,0).add(i))])}}class Ni extends fi{constructor(t){super(),this.type="ex.collider",this.events=new le(this),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 J}get localBounds(){var t,e;return null!==(e=null===(t=this._collider)||void 0===t?void 0:t.localBounds)&&void 0!==e?e:new J}update(){var t;const e=null===(t=this.owner)||void 0===t?void 0:t.get(yi);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 Di&&(e=i,i=this._collider,s=!0),this._collider){const n=e.collide(i);return n?(s&&n.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})),n):[]}return[]}onAdd(t){this._collider&&this.update(),this.events.on("precollision",(e=>{const i=e;t.events.emit("precollision",new qt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("postcollision",(e=>{const i=e;t.events.emit("postcollision",new Zt(i.target.owner,i.other.owner,i.side,i.intersection))})),this.events.on("collisionstart",(e=>{const i=e;t.events.emit("collisionstart",new te(i.target.owner,i.other.owner,i.contact))})),this.events.on("collisionend",(e=>{const i=e;t.events.emit("collisionend",new ee(i.target.owner,i.other.owner))}))}onRemove(){this.events.clear(),this.$colliderRemoved.notifyAll(this._collider)}useBoxCollider(t,e,i=K.Half,s=K.Zero){const n=Hi.Box(t,e,i,s);return this.set(n)}usePolygonCollider(t,e=K.Zero){const i=Hi.Polygon(t,!1,e);return this.set(i)}useCircleCollider(t,e=K.Zero){const i=Hi.Circle(t,e);return this.set(i)}useEdgeCollider(t,e){const i=Hi.Edge(t,e);return this.set(i)}useCompositeCollider(t){return this.set(new Di(t))}}var Wi;!function(t){t.Rotation="rotation",t.X="x",t.Y="y"}(Wi||(Wi={}));class Vi extends fi{constructor(t){var e,i,s;super(),this.type="ex.body",this.dependencies=[yi,vi],this.id=g("body",Vi._ID++),this.events=new le(this),this.collisionType=li.PreventCollision,this.group=xi.All,this.mass=gi.defaultMass,this.sleepMotion=5*gi.sleepEpsilon,this.canSleep=gi.bodiesCanSleepByDefault,this._sleeping=!1,this.bounciness=.2,this.friction=.99,this.useGravity=!0,this.limitDegreeOfFreedom=[],this.oldPos=new K(0,0),this.oldVel=new K(0,0),this.oldAcc=K.Zero,this.oldRotation=0,this.oldScale=K.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===li.Fixed?0:1/this.mass}get sleeping(){return this._sleeping}setSleeping(t){this._sleeping=t,t?(this.vel=K.Zero,this.acc=K.Zero,this.angularVelocity=0,this.sleepMotion=0):this.sleepMotion=5*gi.sleepEpsilon}updateMotion(){this._sleeping&&this.setSleeping(!0);const t=this.vel.size*this.vel.size+Math.abs(this.angularVelocity*this.angularVelocity),e=gi.sleepBias;this.sleepMotion=e*this.sleepMotion+(1-e)*t,this.sleepMotion=S(this.sleepMotion,0,10*gi.sleepEpsilon),this.canSleep&&this.sleepMotion<gi.sleepEpsilon&&this.setSleeping(!0)}get inertia(){const t=this.owner.get(Ni);return(null==t?void 0:t.get())?t.get().getInertia(this.mass):0}get inverseInertia(){return this.collisionType===li.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(yi)}get motion(){var t;return null===(t=this.owner)||void 0===t?void 0:t.get(vi)}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!==li.Active)return;const i=e.scale(this.inverseMass);if(this.limitDegreeOfFreedom.includes(Wi.X)&&(i.x=0),this.limitDegreeOfFreedom.includes(Wi.Y)&&(i.y=0),this.vel.addEqual(i),!this.limitDegreeOfFreedom.includes(Wi.Rotation)){const i=t.sub(this.pos);this.angularVelocity+=this.inverseInertia*i.cross(e)}}applyLinearImpulse(t){if(this.collisionType!==li.Active)return;const e=t.scale(this.inverseMass);this.limitDegreeOfFreedom.includes(Wi.X)&&(e.x=0),this.limitDegreeOfFreedom.includes(Wi.Y)&&(e.y=0),this.vel=this.vel.add(e)}applyAngularImpulse(t,e){if(this.collisionType===li.Active&&!this.limitDegreeOfFreedom.includes(Wi.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){}}Vi._ID=0;class Gi{constructor(){this._topLeft=new K(0,0),this._topRight=new K(0,0),this._bottomLeft=new K(0,0),this._bottomRight=new K(0,0)}isSpriteOffScreen(t,e){const i=t.currentDrawing.drawWidth,s=t.currentDrawing.drawHeight,n=t.rotation,r=t.center,o=t.getGlobalPos();this._topLeft=q(o.x-i/2,o.y-s/2),this._topLeft=this._topLeft.rotate(n,r),this._topRight=q(o.x+i/2,o.y-s/2),this._topRight=this._topRight.rotate(n,r),this._bottomLeft=q(o.x-i/2,o.y+s/2),this._bottomLeft=this._bottomLeft.rotate(n,r),this._bottomRight=q(o.x+i/2,o.y+s/2),this._bottomRight=this._bottomRight.rotate(n,r);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 K(this._xMin,this._yMin)),u=e.screenToWorldCoordinates(new K(this._xMax,this._yMax));this._xMinWorld=d.x,this._yMinWorld=d.y,this._xMaxWorld=u.x,this._yMaxWorld=u.y;const p=[new K(this._xMin,this._yMin),new K(this._xMax,this._yMin),new K(this._xMin,this._yMax),new K(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=Q.White.toString(),t.rect(this._xMinWorld,this._yMinWorld,this._xMaxWorld-this._xMinWorld,this._yMaxWorld-this._yMinWorld),t.stroke(),t.fillStyle=Q.Red.toString(),t.beginPath(),t.arc(this._topLeft.x,this._topLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=Q.Green.toString(),t.beginPath(),t.arc(this._topRight.x,this._topRight.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=Q.Blue.toString(),t.beginPath(),t.arc(this._bottomLeft.x,this._bottomLeft.y,5,0,2*Math.PI),t.closePath(),t.fill(),t.fillStyle=Q.Magenta.toString(),t.beginPath(),t.arc(this._bottomRight.x,this._bottomRight.y,5,0,2*Math.PI),t.closePath(),t.fill()}}class ji{constructor(){this.cullingBox=new Gi}update(t,e){const i=t.eventDispatcher;let s=!0;null!=t.currentDrawing&&(s=this.cullingBox.isSpriteOffScreen(t,e));let n=!1;e&&e.currentScene&&e.currentScene.camera&&e.currentScene.camera.viewport&&!t.parent&&(n=!e.currentScene.camera.viewport.intersect(t.collider.bounds)),t.isOffScreen?n&&s||(i.emit("enterviewport",new oe(t)),t.removeComponent("offscreen")):n&&s&&(i.emit("exitviewport",new re(t)),t.addComponent(new mi("offscreen")))}}class Xi{update(t,e){t.enableCapturePointer&&(t.isKilled()||e.input.pointers.checkAndUpdateActorUnderPointer(t))}}class Ki{constructor(t){this.data=t,this.type="Component Added"}}function qi(t){return!!t&&"Component Added"===t.type}class Zi{constructor(t){this.data=t,this.type="Component Removed"}}function Yi(t){return!!t&&"Component Removed"===t.type}class Qi extends $e{constructor(t,e){if(super(),this.id=Qi._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 mi(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 mi)).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 Ki({component:t,entity:this});this.componentAdded$.notifyAll(e)}_notifyRemoveComponent(t){const e=new Zi({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&&(k(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 Qi;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 fi&&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 ie(t,this)),this._isInitialized=!0)}_preupdate(t,e){this.emit("preupdate",new It(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Ot(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)}}Qi._ID=0;class $i extends fi{constructor(t){var e;super(),this.draw=t,this.type="ex.canvas",this.draw=null!==(e=this.draw)&&void 0!==e?e:()=>{}}}function Ji(t){return!!t.tick}class ts{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 vt?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=Object.assign({},e),t instanceof vt?i=this._graphics.copyGraphics?t.clone():t:(i=this._graphics.getGraphic(t),i||_.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=Object.assign({},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:K.Zero}set offset(t){this._options.offset=t}get currentKeys(){var t;return null!==(t=this.name)&&void 0!==t?t:"anonymous"}}class es{constructor(t){this._component=t,this._layers=[],this._layerMap={},this.default=new ts({name:"default",order:0},t),this._maybeAddLayer(this.default)}create(t){const e=new ts(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 is extends fi{constructor(t){super(),this.type="ex.graphics",this._graphics={},this.visible=!0,this.opacity=1,this.offset=K.Zero,this.anchor=K.Half,this.copyGraphics=!1,this._bounds=null,t=Object.assign({visible:this.visible},t);const{current:e,anchor:i,opacity:s,visible:n,graphics:r,offset:o,copyGraphics:a,onPreDraw:h,onPostDraw:l}=t;this._graphics=r||{},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=!!n,this.layers=new es(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 J;for(const e of this.layers.get())for(const{graphic:i,options:s}of e.graphics){let n=this.anchor,r=this.offset;(null==s?void 0:s.anchor)&&(n=s.anchor),(null==s?void 0:s.offset)&&(r=s.offset);const o=i.localBounds,a=-o.width*i.scale.x*n.x+r.x,h=-o.height*i.scale.y*n.y+r.y;t=null==i?void 0:i.localBounds.translate(q(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)Ji(s)&&(null==s||s.tick(t,e))}}class ss extends Ct{constructor(t){super(t),this.width=t.width,this.height=t.height,this.rasterize()}clone(){return new ss(Object.assign(Object.assign({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 ns extends Ct{constructor(t){var e;super(t),this._radius=0,this.padding=null!==(e=t.padding)&&void 0!==e?e:2,this.radius=t.radius,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 ns(Object.assign(Object.assign({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())}}var rs,os=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class as{static CreateReversibleEasingFunction(t){return(e,i,s,n)=>s<i?i-(t(e,s,i,n)-s):t(e,i,s,n)}static CreateReversableEasingFunction(t){return as.CreateReversibleEasingFunction(t)}static CreateVectorEasingFunction(t){return(e,i,s,n)=>new K(t(e,i.x,s.x,n),t(e,i.y,s.y,n))}}as.Linear=as.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*t/s+e)),as.EaseInQuad=as.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t+e)),as.EaseOutQuad=as.CreateReversibleEasingFunction(((t,e,i,s)=>-(i-=e)*(t/=s)*(t-2)+e)),as.EaseInOutQuad=as.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e,(t/=s/2)<1?i/2*t*t+e:-i/2*(--t*(t-2)-1)+e))),as.EaseInCubic=as.CreateReversibleEasingFunction(((t,e,i,s)=>(i-=e)*(t/=s)*t*t+e)),as.EaseOutCubic=as.CreateReversibleEasingFunction(((t,e,i,s)=>(t/=s,(i-=e)*(--t*t*t+1)+e))),as.EaseInOutCubic=as.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))),os([j({message:"Alias for incorrect spelling used in older versions, will be removed in v0.25.0",alternateMethod:"CreateReversibleEasingFunction"})],as,"CreateReversableEasingFunction",null);class hs{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 ls{constructor(t,e,i){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new Ss(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 cs{constructor(t,e){this._stopped=!1,this._repeatBuilder=e,this._repeatContext=new Ss(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 ds{constructor(t,e,i,s){if(this._started=!1,this._stopped=!1,this._entity=t,this._tx=t.get(yi),this._motion=t.get(vi),this._speed=s,this._offset=new K(e,i),s<=0)throw _.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 K(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=q(this._end.x,this._end.y),this._motion.vel=q(0,0)):this._motion.vel=this._dir.scale(this._speed)}isComplete(t){const e=t.get(yi);return this._stopped||e.pos.distance(this._start)>=this._distance}stop(){this._motion.vel=q(0,0),this._stopped=!0}reset(){this._started=!1}}class us{constructor(t,e,i,s){this.entity=t,this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._end=new K(e,i),this._speed=s}update(t){this._started||(this._started=!0,this._start=new K(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=q(e.x,e.y),this.isComplete(this.entity)&&(this._tx.pos=q(this._end.x,this._end.y),this._motion.vel=q(0,0))}isComplete(t){const e=t.get(yi);return this._stopped||new K(e.pos.x,e.pos.y).distance(this._start)>=this._distance}stop(){this._motion.vel=q(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"}(rs||(rs={}));class ps{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._end=e,this._speed=i,this._rotationType=s||rs.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=x-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+x)%x>=Math.PI,this._rotationType){case rs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case rs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case rs.Clockwise:this._direction=1,this._shortestPathIsPositive?this._distance=this._shortDistance:this._distance=this._longDistance;break;case rs.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 gs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._speed=i,this._offset=e,this._rotationType=s||rs.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=x-t;switch(t>e?(this._shortDistance=e,this._longDistance=t):(this._shortDistance=t,this._longDistance=e),this._shortestPathIsPositive=(this._start-this._end+x)%x>=Math.PI,this._rotationType){case rs.ShortestPath:this._distance=this._shortDistance,this._shortestPathIsPositive?this._direction=1:this._direction=-1;break;case rs.LongestPath:this._distance=this._longDistance,this._shortestPathIsPositive?this._direction=-1:this._direction=1;break;case rs.Clockwise:this._direction=1,this._shortDistance>=0?this._distance=this._shortDistance:this._distance=this._longDistance;break;case rs.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 _s{constructor(t,e,i,s,n){this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._endX=e,this._endY=i,this._speedX=s,this._speedY=n}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=q(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 fs{constructor(t,e,i,s){this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._offset=new K(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 ms{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 ws{constructor(t,e,i,s,n){this.easingFcn=n,this._currentLerpTime=0,this._lerpDuration=1e3,this._lerpStart=new K(0,0),this._lerpEnd=new K(0,0),this._initialized=!1,this._stopped=!1,this._distance=0,this._tx=t.get(yi),this._motion=t.get(vi),this._lerpDuration=s,this._lerpEnd=new K(e,i)}_initialize(){this._lerpStart=new K(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=q((e-this._tx.pos.x)/(t/1e3),(i-this._tx.pos.y)/(t/1e3))):(this._tx.pos=q(this._lerpEnd.x,this._lerpEnd.y),this._motion.vel=K.Zero)}isComplete(t){return this._stopped||new K(t.pos.x,t.pos.y).distance(this._lerpStart)>=this._distance}reset(){this._initialized=!1}stop(){this._motion.vel=q(0,0),this._stopped=!0}}class ys{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(is),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 vs{constructor(t,e,i){this._multiplier=1,this._started=!1,this._stopped=!1,this._graphics=t.get(is),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),_.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 xs{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(Ps).clearActions(),this._entity.kill(),this._stopped=!0}isComplete(){return this._stopped}stop(){}reset(){}}class Cs{constructor(t,e,i){this._started=!1,this._stopped=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._followTx=e.get(yi),this._followMotion=e.get(vi),this._current=new K(this._tx.pos.x,this._tx.pos.y),this._end=new K(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=q(this._tx.pos.x,this._tx.pos.y),this._end=q(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=q(t.x,t.y)}else this._motion.vel=q(0,0);this.isComplete()&&(this._tx.pos=q(this._end.x,this._end.y),this._motion.vel=q(0,0))}stop(){this._motion.vel=q(0,0),this._stopped=!0}isComplete(){return this._stopped}reset(){this._started=!1}}class As{constructor(t,e,i){this._started=!1,this._stopped=!1,this._speedWasSpecified=!1,this._tx=t.get(yi),this._motion=t.get(vi),this._meetTx=e.get(yi),this._meetMotion=e.get(vi),this._current=new K(this._tx.pos.x,this._tx.pos.y),this._end=new K(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=q(this._tx.pos.x,this._tx.pos.y),this._end=q(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=q(i.x,i.y),this.isComplete()&&(this._tx.pos=q(this._end.x,this._end.y),this._motion.vel=q(0,0))}isComplete(){return this._stopped||this._distanceBetween<=1}stop(){this._motion.vel=q(0,0),this._stopped=!0}reset(){this._started=!1}}class Ss{constructor(t){this._entity=t,this._queue=new hs(t)}getQueue(){return this._queue}update(t){this._queue.update(t)}clearActions(){this._queue.clearActions()}easeTo(...t){var e,i;let s=0,n=0,r=0,o=as.Linear;return t[0]instanceof K?(s=t[0].x,n=t[0].y,r=t[1],o=null!==(e=t[2])&&void 0!==e?e:o):(s=t[0],n=t[1],r=t[2],o=null!==(i=t[3])&&void 0!==i?i:o),this._queue.add(new ws(this._entity,s,n,r,o)),this}moveTo(t,e,i){let s=0,n=0,r=0;return t instanceof K?(s=t.x,n=t.y,r=e):(s=t,n=e,r=i),this._queue.add(new us(this._entity,s,n,r)),this}moveBy(t,e,i){let s=0,n=0,r=0;return t instanceof K?(s=t.x,n=t.y,r=e):(s=t,n=e,r=i),this._queue.add(new ds(this._entity,s,n,r)),this}rotateTo(t,e,i){return this._queue.add(new ps(this._entity,t,e,i)),this}rotateBy(t,e,i){return this._queue.add(new gs(this._entity,t,e,i)),this}scaleTo(t,e,i,s){let n=1,r=1,o=0,a=0;return t instanceof K&&e instanceof K&&(n=t.x,r=t.y,o=e.x,a=e.y),"number"==typeof t&&"number"==typeof e&&(n=t,r=e,o=i,a=s),this._queue.add(new _s(this._entity,n,r,o,a)),this}scaleBy(t,e,i){let s=1,n=1;return t instanceof K&&(s=t.x,n=t.y,i=e),"number"==typeof t&&"number"==typeof e&&(s=t,n=e),this._queue.add(new fs(this._entity,s,n,i)),this}blink(t,e,i=1){return this._queue.add(new ys(this._entity,t,e,i)),this}fade(t,e){return this._queue.add(new vs(this._entity,t,e)),this}delay(t){return this._queue.add(new xs(t)),this}die(){return this._queue.add(new bs(this._entity)),this}callMethod(t){return this._queue.add(new ms(t)),this}repeat(t,e){return e?(this._queue.add(new ls(this._entity,t,e)),this):(this.repeatForever(t),this)}repeatForever(t){return this._queue.add(new cs(this._entity,t)),this}follow(t,e){return void 0===e?this._queue.add(new Cs(this._entity,t)):this._queue.add(new Cs(this._entity,t,e)),this}meet(t,e){return void 0===e?this._queue.add(new As(this._entity,t)):this._queue.add(new As(this._entity,t,e)),this}asPromise(){return this.toPromise()}toPromise(){return new Promise((t=>{this._queue.add(new ms((()=>{t()})))}))}}class Ps extends fi{constructor(){super(...arguments),this.type="ex.actions",this.dependencies=[yi,vi]}onAdd(t){this._ctx=new Ss(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()}}var Es=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Ts extends Qi{constructor(t){super(),this._anchor=xt(K.Half,(t=>this._handleAnchorChange(t))),this.logger=_.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.pointer.lastWorldPos)},this._pointerDragLeaveHandler=t=>{this._dragging&&(this.pos=t.pointer.lastWorldPos)},this.traits=[],this.enableCapturePointer=!1,this.capturePointer={captureMoveEvents:!1,captureDragEvents:!1},this._capturePointerEvents=["pointerup","pointerdown","pointermove","pointerenter","pointerleave","pointerdragstart","pointerdragend","pointerdragmove","pointerdragenter","pointerdragleave"],this._captureMoveEvents=["pointermove","pointerenter","pointerleave","pointerdragmove","pointerdragenter","pointerdragleave"],this._captureDragEvents=["pointerdragstart","pointerdragend","pointerdragmove","pointerdragenter","pointerdragleave"];const{name:e,x:i,y:s,pos:n,scale:r,width:o,height:a,radius:h,collider:l,vel:d,acc:u,rotation:g,angularVelocity:f,z:m,color:w,visible:y,anchor:v,collisionType:x,collisionGroup:b}=Object.assign({},t);this._setName(e),this.anchor=null!=v?v:Ts.defaults.anchor.clone(),this.addComponent(new yi),this.pos=null!=n?n:q(null!=i?i:0,null!=s?s:0),this.rotation=null!=g?g:0,this.scale=null!=r?r:q(1,1),this.z=null!=m?m:0,this.addComponent(new is),this.addComponent(new $i(((t,e)=>this.draw(t,e)))),this.addComponent(new vi),this.vel=null!=d?d:K.Zero,this.acc=null!=u?u:K.Zero,this.angularVelocity=null!=f?f:0,this.addComponent(new Ps),this.addComponent(new Vi),this.body.collisionType=null!=x?x:li.Passive,b&&(this.body.group=b),l?this.addComponent(new Ni(l)):h?this.addComponent(new Ni(Hi.Circle(h,this.anchor))):o>0&&a>0?this.addComponent(new Ni(Hi.Box(o,a,this.anchor))):this.addComponent(new Ni),this.graphics.visible=null==y||y,w&&(this.color=w,o&&a?this.graphics.add(new ss({color:w,width:o,height:a})):h&&this.graphics.add(new ns({color:w,radius:h}))),p.isEnabled(c.LegacyDrawing)&&this.traits.push(new ji),this.traits.push(new Xi)}get body(){return this.get(Vi)}get transform(){return this.get(yi)}get motion(){return this.get(vi)}get graphics(){return this.get(is)}get collider(){return this.get(Ni)}get actions(){return this.get(Ps)}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(yi).scale}set scale(t){this.get(yi).scale=t}get anchor(){return this._anchor}set anchor(t){this._anchor=xt(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){this._color=t.clone()}onInitialize(t){}_initialize(t){super._initialize(t);for(const e of this.children)e._initialize(t)}_checkForPointerOptIn(t){if(t){const e=t.toLowerCase();-1!==this._capturePointerEvents.indexOf(e)&&(this.enableCapturePointer=!0,-1!==this._captureMoveEvents.indexOf(e)&&(this.capturePointer.captureMoveEvents=!0),-1!==this._captureDragEvents.indexOf(e)&&(this.capturePointer.captureDragEvents=!0))}}on(t,e){this._checkForPointerOptIn(t),super.on(t,e)}once(t,e){this._checkForPointerOptIn(t),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 Rt(this)),this.onPostKill(t)}onPostKill(t){}kill(){this.scene?(this._prekill(this.scene),this.emit("kill",new Et(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]):_.getInstance().error(`the specified drawing key ${t} does not exist`)),this.currentDrawing&&this.currentDrawing instanceof ke&&this.currentDrawing.tick(0)}addDrawing(){2===arguments.length?(this.frames[arguments[0]]=arguments[1],this.currentDrawing||(this.currentDrawing=arguments[1])):(arguments[0]instanceof Ee&&this.addDrawing("default",arguments[0]),arguments[0]instanceof be&&this.addDrawing("default",arguments[0].asSprite()))}get z(){return this.get(yi).z}getZIndex(){return this.get(yi).z}set z(t){this.get(yi).z=t}setZIndex(t){this.get(yi).z=t}get center(){return new K(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(yi).globalRotation}getGlobalPos(){return this.get(yi).globalPos}getGlobalScale(){return this.get(yi).globalScale}contains(t,e,i=!1){const s=q(t,e),n=this.get(Ni);n.update();const r=n.get();if(!r)return!1;const o=r.contains(s);return i?o||this.children.some((i=>i.contains(t,e,!0))):o}within(t,e){const i=this.get(Ni),s=t.get(Ni),n=i.get(),r=s.get();return!(!n||!r)&&n.getClosestLineBetween(r).getLength()<=e}update(t,e){this._initialize(t),this._preupdate(t,e);const i=this.currentDrawing;i&&i instanceof ke&&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 It(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new It(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,n=(this.height-i.height*i.scale.y)*this.anchor.y;this.currentDrawing.draw({ctx:t,x:s,y:n,opacity:this.graphics.opacity})}else if(this._predraw(t,e),this.color&&this.collider){const e=this.get(Ni);e.update(),e&&!e.bounds.hasZeroDimensions()&&(t.globalAlpha=this.graphics.opacity,null===(i=e.get())||void 0===i||i.draw(t,this.color,q(0,0)))}t.restore(),this._postdraw(t,e)}onPreDraw(t,e){}onPostDraw(t,e){}_predraw(t,e){this.emit("predraw",new Mt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new Mt(t,e,this)),this.onPostDraw(t,e)}debugDraw(t){}}Ts.defaults={anchor:K.Half},Es([j({message:"Actor.visible will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.visible"})],Ts.prototype,"visible",null),Es([j({message:"Actor.opacity will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.opacity"})],Ts.prototype,"opacity",null),Es([j({message:"Actor.setDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.show() or Actor.graphics.use()"})],Ts.prototype,"setDrawing",null),Es([j({message:"Actor.addDrawing will be removed in v0.26.0",alternateMethod:"Use Actor.graphics.add()"})],Ts.prototype,"addDrawing",null),Es([j({message:"Actor.getZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Ts.prototype,"getZIndex",null),Es([j({message:"Actor.setZIndex will be removed in v0.26.0",alternateMethod:"Use Actor.transform.z or Actor.z"})],Ts.prototype,"setZIndex",null);class Rs extends Ts{constructor(t){super(Object.assign({},t)),this.get(yi).coordPlane=wi.Screen,this.traits=[],this.traits.push(new Xi),this.anchor=q(0,0),this.body.collisionType=li.PreventCollision,this.collider.useBoxCollider(this.width,this.height,this.anchor),this.enableCapturePointer=!0}_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 K(t,e));return super.contains(s.x,s.y)}}var Ds=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Bs{constructor(t,e,i,s){if(this._logger=_.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 n=t;t=n.fcn,e=n.interval,i=n.repeats,s=n.numberOfRepeats}if(s&&s>=0&&(this.maxNumberOfRepeats=s,!i))throw new Error("repeats must be set to true if numberOfRepeats is set");this.id=Bs._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)}}Bs._MAX_ID=0,Ds([j({message:"Will be removed in v0.26.0",alternateMethod:"Use Timer.resume()"})],Bs.prototype,"unpause",null);var Ms,ks=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Fs extends Qi{constructor(t,e,i,s,n,r){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=_.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,n=o.rows,r=o.cols}this.addComponent(new yi),this.addComponent(new vi),this.addComponent(new Vi({type:li.Fixed})),this.addComponent(new $i(((t,e)=>this.draw(t,e)))),this.addComponent(new is({onPostDraw:(t,e)=>this.draw(t,e)})),this.addComponent(new Ni),this._transform=this.get(yi),this._motion=this.get(vi),this._collider=this.get(Ni),this._composite=this._collider.useCompositeCollider([]),this.x=t,this.y=e,this.cellWidth=i,this.cellHeight=s,this.rows=n,this.cols=r,this.data=new Array(n*r),this._rows=new Array(n),this._cols=new Array(r);let o=[];for(let a=0;a<r;a++){for(let h=0;h<n;h++){const n=new Os(a*i+t,h*s+e,i,s,a+h*r);n.map=this,this.data[a+h*r]=n,o.push(n),this._rows[h]||(this._rows[h]=[]),this._rows[h].push(n)}this._cols[a]=o,o=[]}this.get(is).localBounds=new J({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(yi).pos=q(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=q(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:K.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 We?e:We.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 n=this.data[i+s*this.cols];n.solid?e=e?e.combine(n.bounds):n.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=Hi.Box(e.width,e.height,K.Zero,q(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 It(t,e,this)),this._dirty&&(this._dirty=!1,this._updateColliders()),this._token++;const i=t.getWorldBounds(),s=q(i.left,i.top),n=q(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((n.x-this.x)/this.cellWidth)+2,0),this._onScreenYEnd=Math.max(Math.floor((n.y-this.y)/this.cellHeight)+2,0),this._transform.pos=q(this.x,this.y),this.onPostUpdate(t,e),this.emit("postupdate",new Ot(t,e,this))}draw(t,e){this.emit("predraw",new Mt(t,e,this));let i=this._onScreenXStart;const s=Math.min(this._onScreenXEnd,this.cols);let n=this._onScreenYStart;const r=Math.min(this._onScreenYEnd,this.rows);let o,a,h;for(;i<s;i++){for(;n<r;n++)for(o=this.getCell(i,n).graphics,a=0,h=o.length;a<h;a++){const s=o[a];s&&(t instanceof CanvasRenderingContext2D?s instanceof Te&&(this._legacySpriteMap.has(s)||this._legacySpriteMap.set(s,Te.toLegacySprite(s)),this._legacySpriteMap.get(s).draw(t,i*this.cellWidth,n*this.cellHeight)):(Ji(s)&&(null==s||s.tick(e,this._token)),s.draw(t,i*this.cellWidth,n*this.cellHeight)))}n=this._onScreenYStart}this.emit("postdraw",new kt(t,e,this))}}ks([j({message:"No longer used, will be removed in v0.26.0"})],Fs.prototype,"registerSpriteSheet",null);class Ls extends(Ce(Fs)){constructor(t,e,i,s,n,r){super(t,e,i,s,n,r)}}class Is extends Qi{constructor(t,e,i,s,n,r=!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,n=a.index,r=a.solid,o=a.sprites}this.x=t,this.y=e,this.width=i,this.height=s,this.index=n,this.solid=r,this.graphics=o,this._bounds=new J(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 K(this.x+this.width/2,this.y+this.height/2)}pushSprite(t){this.addGraphic(t)}addGraphic(t){t instanceof Ee?this.graphics.push(Te.fromLegacySprite(t)):this.graphics.push(t)}removeGraphic(t){k(t,this.graphics)}clearGraphics(){this.graphics.length=0}}ks([j({message:"Will be removed in v0.26.0",alternateMethod:"addSprite"})],Is.prototype,"pushSprite",null);class Os extends(Ce(Is)){constructor(t,e,i,s,n,r,o){super(t,e,i,s,n,r,o)}}class zs{constructor(t){this.camera=t}lockToActor(t){this.camera.addStrategy(new Us(t))}lockToActorAxis(t,e){this.camera.addStrategy(new Hs(t,e))}elasticToActor(t,e,i){this.camera.addStrategy(new Ns(t,e,i))}radiusAroundActor(t,e){this.camera.addStrategy(new Ws(t,e))}limitCameraBounds(t){this.camera.addStrategy(new Vs(t))}}!function(t){t[t.X=0]="X",t[t.Y=1]="Y"}(Ms||(Ms={}));class Us{constructor(t){this.target=t,this.action=(t,e,i,s)=>t.center}}class Hs{constructor(t,e){this.target=t,this.axis=e,this.action=(t,e,i,s)=>{const n=t.center,r=e.getFocus();return this.axis===Ms.X?new K(n.x,r.y):new K(r.x,n.y)}}}class Ns{constructor(t,e,i){this.target=t,this.cameraElasticity=e,this.cameraFriction=i,this.action=(t,e,i,s)=>{const n=t.center;let r=e.getFocus(),o=e.vel.clone();const a=n.sub(r).scale(this.cameraElasticity);o=o.add(a);const h=o.scale(-1).scale(this.cameraFriction);return o=o.add(h),r=r.add(o),r}}}class Ws{constructor(t,e){this.target=t,this.radius=e,this.action=(t,e,i,s)=>{const n=t.center,r=e.getFocus(),o=n.sub(r),a=o.size;if(a>=this.radius){const t=a-this.radius;return r.add(o.normalize().scale(t))}return r}}}class Vs{constructor(t){this.target=t,this.boundSizeChecked=!1,this.action=(t,e,i,s)=>{const n=e.getFocus();this.boundSizeChecked||((t.bottom-t.top<i.drawHeight||t.right-t.left<i.drawWidth)&&_.getInstance().warn("Camera bounds should not be smaller than the engine viewport"),this.boundSizeChecked=!0);let r=n.x,o=n.y;return n.x<t.left+i.halfDrawWidth?r=t.left+i.halfDrawWidth:n.x>t.right-i.halfDrawWidth&&(r=t.right-i.halfDrawWidth),n.y<t.top+i.halfDrawHeight?o=t.top+i.halfDrawHeight:n.y>t.bottom-i.halfDrawHeight&&(o=t.bottom-i.halfDrawHeight),q(r,o)}}}class Gs extends $e{constructor(){super(...arguments),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=bt(K.Zero,(()=>this._posChanged=!0)),this.vel=K.Zero,this.acc=K.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=as.EaseInOutCubic,this._easing=as.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=bt(t,(()=>this._posChanged=!0)),this._posChanged=!0}get x(){return this.pos.x}set x(t){this._follow||this._cameraMoving||(this.pos=q(t,this.pos.y))}get y(){return this.pos.y}set y(t){this._follow||this._cameraMoving||(this.pos=q(this.pos.x,t))}get dx(){return this.vel.x}set dx(t){this.vel=q(t,this.vel.y)}get dy(){return this.vel.y}set dy(t){this.vel=q(this.vel.x,t)}get ax(){return this.acc.x}set ax(t){this.acc=q(t,this.acc.y)}get ay(){return this.acc.y}set ay(t){this.acc=q(this.acc.x,t)}getFocus(){return this.pos}move(t,e,i=as.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=as.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 J(0,0,0,0)}addStrategy(t){this._cameraStrategies.push(t)}removeStrategy(t){k(t,this._cameraStrategies)}clearAllStrategies(){this._cameraStrategies.length=0}_preupdate(t,e){this.emit("preupdate",new It(t,e,this)),this.onPreUpdate(t,e)}onPreUpdate(t,e){}_postupdate(t,e){this.emit("postupdate",new Ot(t,e,this)),this.onPostUpdate(t,e)}onPostUpdate(t,e){}get isInitialized(){return this._isInitialized}_initialize(t){if(!this.isInitialized){this._engine=t;const e=this._engine.screen.resolution;let i=q(e.width/2,e.height/2);if(!this._engine.loadingComplete){const t=this._engine.screen.peekResolution();t&&(i=q(t.width/2,t.height/2))}this._halfWidth=i.x,this._halfHeight=i.x,this._posChanged||(this.pos=i),this.onInitialize(t),super.emit("initialize",new ie(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)}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=as.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));for(const i of this._cameraStrategies)this.pos=i.action.call(i,i.target,this,t,e);this._viewport=new J(this.x-this._halfWidth,this.y-this._halfHeight,this.x+this._halfWidth,this.y+this._halfHeight),this._postupdate(t,e)}draw(t){let e=0,i=0;t instanceof CanvasRenderingContext2D?(e=t.canvas.width,i=t.canvas.height):(e=t.width,i=t.height);const s=this.getFocus(),n=this._engine?this._engine.pixelRatio:1,r=this.zoom,o=e/r/n,a=i/r/n;t.scale(r,r),t.translate(-s.x+o/2+this._xShake,-s.y+a/2+this._yShake)}debugDraw(t){}_isDoneShaking(){return!this._isShaking||this._elapsedShakeTime>=this._shakeDuration}}function js(t){return t instanceof Rs}const Xs={pos:K.Zero,width:10,height:10,visible:!1,action:()=>{},filter:()=>!0,repeat:-1};class Ks extends Ts{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=b({},Xs,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=li.Passive,this.eventDispatcher=new le(this),this.events.on("collisionstart",(t=>{this.filter(t.other)&&(this.emit("enter",new ae(this,t.other)),this._dispatchAction(),0===this.repeat&&this.kill())})),this.events.on("collisionend",(t=>{this.filter(t.other)&&this.emit("exit",new he(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=Q.Violet.toString(),t.strokeStyle=Q.Violet.toString(),t.fillText("Trigger",10,10),e.debugDraw(t),t.restore()}}var qs;!function(t){t.Update="update",t.Draw="draw"}(qs||(qs={}));class Zs{constructor(){this.priority=0}notify(t){}}class Ys{constructor(t){this.data=t,this.type="Entity Added"}}function Qs(t){return!!t&&"Entity Added"===t.type}class $s{constructor(t){this.data=t,this.type="Entity Removed"}}function Js(t){return!!t&&"Entity Removed"===t.type}class tn{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){qi(t)&&this._world.queryManager.addEntity(t.data.entity),Yi(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 Qi?t.id:t;const n=this._entityIndex[s];n&&n.active&&n.kill(),n&&e?this._entitiesToRemove.push(n):(delete this._entityIndex[s],n&&(k(n,this.entities),this._world.queryManager.removeEntity(n),n.componentAdded$.unregister(this),n.componentRemoved$.unregister(this),n.children.forEach((t=>this.removeEntity(t,e))),n.childrenAdded$.clear(),n.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 en=t=>[...t].sort(((t,e)=>t.localeCompare(e))).join("+");class sn 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=en(this.types)}getEntities(t){return t&&this._entities.sort(t),this._entities}addEntity(t){!F(this._entities,t)&&this.matches(t)&&(this._entities.push(t),this.notifyAll(new Ys(t)))}removeEntity(t){k(t,this._entities)&&this.notifyAll(new $s(t))}clear(){this._entities.length=0;for(const t of this.observers)this.unregister(t)}matches(t){let e=[];e=t instanceof Qi?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 nn{constructor(t){this._world=t,this._queries={}}_addQuery(t){this._queries[en(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[en(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 sn(t);return this._addQuery(i),i}getQuery(t){const e=en(t);return this._queries[e]?this._queries[e]:null}}class rn{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){k(t,this.systems);const e=this._world.queryManager.getQuery(t.types);e&&(e.unregister(t),this._world.queryManager.maybeRemoveQuery(e))}updateSystems(t,e,i){if(!this.initialized){this.initialized=!0;for(const t of this.systems)t.initialize&&t.initialize(this._world.context)}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 Fn)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 on{constructor(t){this.context=t,this.queryManager=new nn(this),this.entityManager=new tn(this),this.systemManager=new rn(this)}update(t,e){t===qs.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 Qi&&this.entityManager.addEntity(t),t instanceof Zs&&this.systemManager.addSystem(t)}remove(t,e=!0){t instanceof Qi&&this.entityManager.removeEntity(t,e),t instanceof Zs&&this.systemManager.removeSystem(t)}clearEntities(){this.entityManager.clear()}clearSystems(){this.systemManager.clear()}}class an{static integrate(t,e,i,s){const n=s/1e3;e.vel.addEqual(i.scale(n)),t.pos.addEqual(e.vel.scale(n)).addEqual(i.scale(.5*n*n)),e.angularVelocity+=e.torque*(1/e.inertia)*n,t.rotation+=e.angularVelocity*n,t.scale.addEqual(e.scaleFactor.scale(n))}}class hn extends Zs{constructor(){super(...arguments),this.types=["ex.transform","ex.motion"],this.systemType=qs.Update,this.priority=-1}update(t,e){let i,s;for(const n of t){i=n.get(yi),s=n.get(vi);const t=n.get(Vi);if(null==t?void 0:t.sleeping)continue;const r=s.acc.clone();(null==t?void 0:t.collisionType)===li.Active&&(null==t?void 0:t.useGravity)&&r.addEqual(gi.gravity),null==t||t.captureOldTransform(),an.integrate(i,s,r,e)}}debugDraw(t){}}class ln{solve(t){return this.preSolve(t),t=t.filter((t=>!t.isCanceled())),this.solveVelocity(t),this.solvePosition(t),this.postSolve(t),t}}class cn extends ln{preSolve(t){for(const e of t){const t=v.fromDirection(e.mtv),i=e.mtv.negate();e.colliderA.events.emit("precollision",new qt(e.colliderA,e.colliderB,t,i)),e.colliderB.events.emit("precollision",new qt(e.colliderB,e.colliderA,v.getOpposite(t),i.negate()))}}postSolve(t){var e,i;for(const s of t){const t=s.colliderA,n=s.colliderB,r=null===(e=t.owner)||void 0===e?void 0:e.get(Vi),o=null===(i=n.owner)||void 0===i?void 0:i.get(Vi);if(r&&o&&(r.collisionType===li.Passive||o.collisionType===li.Passive))continue;const a=v.fromDirection(s.mtv),h=s.mtv.negate();s.colliderA.events.emit("postcollision",new Zt(s.colliderA,s.colliderB,a,h)),s.colliderB.events.emit("postcollision",new Zt(s.colliderB,s.colliderA,v.getOpposite(a),h.negate()))}}solvePosition(t){var e,i;for(const s of t){let t=s.mtv;const n=s.colliderA,r=s.colliderB,o=null===(e=n.owner)||void 0===e?void 0:e.get(Vi),a=null===(i=r.owner)||void 0===i?void 0:i.get(Vi);if(o&&a){if(o.collisionType===li.Passive||a.collisionType===li.Passive)continue;o.collisionType===li.Active&&a.collisionType===li.Active&&(t=t.scale(.5)),o.collisionType===li.Active&&(o.pos.x-=t.x,o.pos.y-=t.y),a.collisionType===li.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,n=s.colliderB,r=null===(e=t.owner)||void 0===e?void 0:e.get(Vi),o=null===(i=n.owner)||void 0===i?void 0:i.get(Vi);if(r&&o){if(r.collisionType===li.Passive||o.collisionType===li.Passive)continue;const t=s.normal,e=t.negate();if(r.collisionType===li.Active){const e=t.scale(t.dot(r.vel.negate()));r.vel=r.vel.add(e)}if(o.collisionType===li.Active){const t=e.scale(e.dot(o.vel.negate()));o.vel=o.vel.add(t)}}}}}class dn{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 K(0,0),this.bToContact=new K(0,0),this.update()}update(){var t,e;const i=null===(t=this.contact.colliderA.owner)||void 0===t?void 0:t.get(Vi),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get(Vi);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 n=this.aToContact.cross(t),r=this.bToContact.cross(t);this.normalMass=i.inverseMass+s.inverseMass+i.inverseInertia*n*n+s.inverseInertia*r*r;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(Vi),s=null===(e=this.contact.colliderB.owner)||void 0===e?void 0:e.get(Vi);if(i&&s){const t=i.vel.add(K.cross(i.angularVelocity,this.aToContact));return s.vel.add(K.cross(s.angularVelocity,this.bToContact)).sub(t)}return K.Zero}}class un extends ln{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=v.fromDirection(e.mtv);e.colliderA.events.emit("precollision",new qt(e.colliderA,e.colliderB,t,e.mtv)),e.colliderA.events.emit("beforecollisionresolve",new $t(e.colliderA,e.colliderB,t,e.mtv,e)),e.colliderB.events.emit("precollision",new qt(e.colliderB,e.colliderA,v.getOpposite(t),e.mtv.negate())),e.colliderB.events.emit("beforecollisionresolve",new $t(e.colliderB,e.colliderA,v.getOpposite(t),e.mtv.negate(),e)),e.matchAwake()}const n=Array.from(this.idToContactConstraint.keys());for(const r of t){const t=n.indexOf(r.id);t>-1&&n.splice(t,1);const o=null!==(e=this.idToContactConstraint.get(r.id))&&void 0!==e?e:[];let a=0;const h=r.colliderA.owner.get(Vi),l=r.colliderB.owner.get(Vi);if(h&&l)for(const t of r.points){const e=r.normal,n=r.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(n),f=d.cross(n),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=r.localPoints[a]):o[a]=new dn(t,r.localPoints[a],r),o[a].aToContact=c,o[a].bToContact=d,o[a].normalMass=g,o[a].tangentMass=m,a++}this.idToContactConstraint.set(r.id,o)}for(const t of n)this.idToContactConstraint.delete(t);if(gi.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(Vi),i=e.colliderB.owner.get(Vi);if(t&&i){if(t.collisionType===li.Passive||i.collisionType===li.Passive)continue;t.updateMotion(),i.updateMotion()}const s=v.fromDirection(e.mtv);e.colliderA.events.emit("postcollision",new Zt(e.colliderA,e.colliderB,s,e.mtv)),e.colliderA.events.emit("aftercollisionresolve",new Jt(e.colliderA,e.colliderB,s,e.mtv,e)),e.colliderB.events.emit("postcollision",new Zt(e.colliderB,e.colliderA,v.getOpposite(s),e.mtv.negate())),e.colliderB.events.emit("aftercollisionresolve",new Jt(e.colliderB,e.colliderA,v.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 n of t){const t=null===(e=n.colliderA.owner)||void 0===e?void 0:e.get(Vi),r=null===(i=n.colliderB.owner)||void 0===i?void 0:i.get(Vi);if(t&&r){const e=null!==(s=this.idToContactConstraint.get(n.id))&&void 0!==s?s:[];for(const i of e)if(gi.warmStart){const e=n.normal.scale(i.normalImpulse),s=n.tangent.scale(i.tangentImpulse),o=e.add(s);t.applyImpulse(i.point,o.negate()),r.applyImpulse(i.point,o)}else i.normalImpulse=0,i.tangentImpulse=0}}}solvePosition(t){var e,i,s;for(let n=0;n<gi.positionIterations;n++)for(const n of t){const t=null===(e=n.colliderA.owner)||void 0===e?void 0:e.get(Vi),r=null===(i=n.colliderB.owner)||void 0===i?void 0:i.get(Vi);if(t&&r){if(t.collisionType===li.Passive||r.collisionType===li.Passive)continue;const e=null!==(s=this.idToContactConstraint.get(n.id))&&void 0!==s?s:[];for(const i of e){const e=n.normal,s=Oi.FindContactSeparation(n,i.local),o=-5,a=S(gi.steeringFactor*(s+gi.slop),o,0),h=e.scale(-a/i.normalMass);t.collisionType===li.Active&&(t.pos=t.pos.add(h.negate().scale(t.inverseMass)),t.rotation-=i.aToContact.cross(h)*t.inverseInertia),r.collisionType===li.Active&&(r.pos=r.pos.add(h.scale(r.inverseMass)),r.rotation+=i.bToContact.cross(h)*r.inverseInertia)}}}}solveVelocity(t){var e,i,s;for(let n=0;n<gi.velocityIterations;n++)for(const n of t){const t=null===(e=n.colliderA.owner)||void 0===e?void 0:e.get(Vi),r=null===(i=n.colliderB.owner)||void 0===i?void 0:i.get(Vi);if(t&&r){if(t.collisionType===li.Passive||r.collisionType===li.Passive)continue;const e=t.bounciness*r.bounciness,i=Math.min(t.friction,r.friction),o=null!==(s=this.idToContactConstraint.get(n.id))&&void 0!==s?s:[];for(const e of o){let s=-e.getRelativeVelocity().dot(n.tangent)/e.tangentMass;const o=i*e.normalImpulse,a=S(e.tangentImpulse+s,-o,o);s=a-e.tangentImpulse,e.tangentImpulse=a;const h=n.tangent.scale(s);t.applyImpulse(e.point,h.negate()),r.applyImpulse(e.point,h)}for(const i of o){let s=-(1+e)*i.getRelativeVelocity().dot(n.normal)/i.normalMass;const o=Math.max(i.normalImpulse+s,0);s=o-i.normalImpulse,i.normalImpulse=o;const a=n.normal.scale(s);t.applyImpulse(i.point,a.negate()),r.applyImpulse(i.point,a)}}}}}class pn extends Zs{constructor(){super(...arguments),this.types=["ex.transform","ex.motion","ex.collider"],this.systemType=qs.Update,this.priority=-1,this._realisticSolver=new un,this._arcadeSolver=new cn,this._processor=new Ti,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(Qs(t)){const e=t.data.get(Ni);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(Ni),i=e.get();e&&i&&this._processor.untrack(i)}}initialize(t){this._engine=t.engine}update(t,e){var i;if(!gi.enabled)return;let s=[];for(const e of t){const t=e.get(Ni),n=null==t?void 0:t.get();t&&(null===(i=t.owner)||void 0===i?void 0:i.active)&&n&&(t.update(),n instanceof Di?s=s.concat(n.getColliders()):s.push(n))}this._processor.update(s);const n=this._processor.broadphase(s,e);this._currentFrameContacts.clear();let r=this._processor.narrowphase(n,this._engine.debug.stats.currFrame);r=this.getSolver().solve(r),r.forEach((t=>this._currentFrameContacts.set(t.id,t))),this.runContactStartEnd(),this._lastFrameContacts.clear(),this._lastFrameContacts=new Map(this._currentFrameContacts)}getSolver(){return gi.collisionResolutionStrategy===ci.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 te(t,i,e)),t.events.emit("contactstart",new Yt(t,i,e)),i.events.emit("collisionstart",new te(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 ee(t,i)),t.events.emit("contactend",new Qt(t,i)),i.events.emit("collisionend",new ee(i,t)),i.events.emit("contactend",new Qt(i,t))}}}var gn,_n,fn;!function(t){t.Forward="forward",t.Backward="backward"}(gn||(gn={})),function(t){t.End="end",t.Loop="loop",t.PingPong="pingpong",t.Freeze="freeze"}(_n||(_n={}));class mn extends vt{constructor(t){var e,i;super(t),this.events=new le(this),this.frames=[],this.strategy=_n.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 mn(Object.assign({frames:this.frames.map((t=>Object.assign({},t))),frameDuration:this.frameDuration,reverse:this._reversed,strategy:this.strategy},this.cloneGraphicOptions()))}static fromSpriteSheet(t,e,i,s=_n.Loop){const n=t.sprites.length-1,r=e.filter((t=>t<0||t>n));return r.length&&mn._LOGGER.warn(`Indices into SpriteSheet were provided that don't exist: ${r.join(",")} no frame will be shown`),new mn({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=>Te.toLegacySprite(t.graphic)));return new ke({sprites:i,loop:e.strategy===_n.Loop,freezeFrame:e.strategy===_n.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)?gn.Backward:gn.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 _n.End:case _n.Freeze:return!0;default:return!1}}get done(){return this._done}goToFrame(t){var e,i;this._currentFrame=t,this._timeLeftInFrame=this.frameDuration;const s=this.frames[this._currentFrame];s&&!this._done&&(this._timeLeftInFrame=(null==s?void 0:s.duration)||this.frameDuration,this.width=null===(e=s.graphic)||void 0===e?void 0:e.width,this.height=null===(i=s.graphic)||void 0===i?void 0:i.height,this.events.emit("frame",s))}_nextFrame(){const t=this._currentFrame;if(this._done)return t;let e=-1;switch(this.strategy){case _n.Loop:e=(t+1)%this.frames.length,0===e&&this.events.emit("loop",this);break;case _n.End:e=t+1,e>=this.frames.length&&(this._done=!0,this._currentFrame=this.frames.length,this.events.emit("end",this));break;case _n.Freeze:e=S(t+1,0,this.frames.length-1),e>=this.frames.length-1&&(this._done=!0,this.events.emit("end",this));break;case _n.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()),this._updateDimensions()))}_updateDimensions(){var t,e;this.currentFrame&&(this.width=null===(t=this.currentFrame.graphic)||void 0===t?void 0:t.width,this.height=null===(e=this.currentFrame.graphic)||void 0===e?void 0:e.height)}_drawImage(t,e,i){this.currentFrame&&this.currentFrame.graphic.draw(t,e,i)}}mn._LOGGER=_.getInstance();class wn extends vt{constructor(t){super(t),this.members=[],this.members=t.members,this._updateDimensions()}clone(){return new wn(Object.assign({members:[...this.members]},this.cloneGraphicOptions()))}_updateDimensions(){let t=new J;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 J;for(const{graphic:e,pos:i}of this.members)t=e.localBounds.translate(i).combine(t);return t}_isAnimationOrGroup(t){return t instanceof mn||t instanceof wn}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"}(fn||(fn={}));class yn extends Qi{constructor(t,e,i,s,n,r,o,a,h,l){super(),this.position=new K(0,0),this.velocity=new K(0,0),this.acceleration=new K(0,0),this.particleRotationalVelocity=0,this.currentRotation=0,this.focus=null,this.focusAccel=0,this.opacity=1,this.beginColor=Q.White,this.endColor=Q.White,this.life=300,this.fadeFlag=!1,this._rRate=1,this._gRate=1,this._bRate=1,this._aRate=0,this._currentColor=Q.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 xn)){const d=t;c=d.emitter,e=d.life,i=d.opacity,n=d.endColor,s=d.beginColor,r=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=n||this.endColor.clone(),this.beginColor=s||this.beginColor.clone(),this._currentColor=this.beginColor.clone(),this.position=(r||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 yi),this.addComponent(new $i((t=>this.draw(t)))),this.addComponent(this.graphics=new is),this.transform.pos=this.position,this.transform.rotation=this.currentRotation,this.transform.scale=q(1,1),this.particleSprite?(this.graphics.opacity=this.opacity,this.graphics.use(Te.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(q(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=S(this._aRate*this.life,1e-4,1)),this.startSize>0&&this.endSize>0&&(this.particleSize=S(this.sizeRate*e+this.particleSize,Math.min(this.startSize,this.endSize),Math.max(this.startSize,this.endSize))),this._currentColor.r=S(this._currentColor.r+this._rRate*e,0,255),this._currentColor.g=S(this._currentColor.g+this._gRate*e,0,255),this._currentColor.b=S(this._currentColor.b+this._bRate*e,0,255),this._currentColor.a=S(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=q(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=S(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 vn extends(Ce(yn)){constructor(t,e,i,s,n,r,o,a,h,l){super(t,e,i,s,n,r,o,a,h,l)}}class xn extends Ts{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 K(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=Q.White,this.endColor=Q.White,this._og=null,this._sprite=null,this.emitterType=fn.Rectangle,this.radius=0,this.particleRotationalVelocity=0,this.randomRotation=!1;const{x:s,y:n,pos:r,isEmitting:o,minVel:a,maxVel:h,acceleration:l,minAngle:c,maxAngle:d,emitRate:u,particleLife:p,opacity:g,fadeFlag:_,focus:f,focusAccel:m,startSize:w,endSize:v,minSize:x,maxSize:b,beginColor:C,endColor:A,particleSprite:S,emitterType:P,radius:E,particleRotationalVelocity:T,randomRotation:R,random:D}=Object.assign({},t);this.pos=null!=r?r:q(null!=s?s:0,null!=n?n: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!=w?w:this.startSize,this.endSize=null!=v?v:this.endSize,this.minSize=null!=x?x:this.minSize,this.maxSize=null!=b?b:this.maxSize,this.beginColor=null!=C?C:this.beginColor,this.endColor=null!=A?A:this.endColor,this.particleSprite=null!=S?S:this.particleSprite,this.emitterType=null!=P?P:this.emitterType,this.radius=null!=E?E:this.radius,this.particleRotationalVelocity=null!=T?T:this.particleRotationalVelocity,this.randomRotation=null!=R?R:this.randomRotation,this.body.collisionType=li.PreventCollision,this.random=null!=D?D:new y;for(let t=0;t<this.traits.length;t++)this.traits[t]instanceof ji&&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=Te.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=P(this.minAngle,this.maxAngle,this.random),s=P(this.minVel,this.maxVel,this.random),n=this.startSize||P(this.minSize,this.maxSize,this.random),r=s*Math.cos(i),o=s*Math.sin(i);if(this.emitterType===fn.Rectangle)t=P(0,this.width,this.random),e=P(0,this.height,this.random);else if(this.emitterType===fn.Circle){const s=P(0,this.radius,this.random);t=s*Math.cos(i),e=s*Math.sin(i)}const a=new vn(this,this.particleLife,this.opacity,this.beginColor,this.endColor,new K(t,e),new K(r,o),this.acceleration,this.startSize,this.endSize);return a.fadeFlag=this.fadeFlag,a.particleSize=n,this.particleSprite&&(a.particleSprite=this.particleSprite,a.graphics.opacity=this.opacity,a.graphics.use(this._sprite)),a.particleRotationalVelocity=this.particleRotationalVelocity,this.randomRotation&&(a.currentRotation=P(0,2*Math.PI,this.random)),this.focus&&(a.focus=this.focus.add(new K(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++)k(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=Q.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),Je(t,Q.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 bn extends Zs{constructor(){super(...arguments),this.types=["ex.transform","ex.graphics"],this.systemType=qs.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(yi).z-e.get(yi).z}update(t,e){let i,s;this._clearScreen(),this._token++;for(const n of t){i=n.get(yi),s=n.get(is);const t=this._isOffscreen(i,s);if(t&&!n.hasTag("offscreen")&&(n.eventDispatcher.emit("exitviewport",new re(n)),n.addComponent(new mi("offscreen"))),!t&&n.hasTag("offscreen")&&(n.eventDispatcher.emit("enterviewport",new oe(n)),n.removeComponent("offscreen")),t)continue;this._pushCameraTransform(i),this._graphicsContext.save(),s.update(e,this._token),this._applyTransform(n),s.onPreDraw&&s.onPreDraw(this._graphicsContext,e);const r=n instanceof vn?n.opacity:1;this._graphicsContext.opacity=s.opacity*r,this._drawGraphicsComponent(s),s.onPostDraw&&s.onPostDraw(this._graphicsContext,e),this._graphicsContext.restore(),this._popCameraTransform(i)}this._graphicsContext.flush(),this._engine.stats.currFrame.graphics.drawnImages=ot.DrawnImagesCount,this._engine.stats.currFrame.graphics.drawCalls=ot.DrawCallCount}_clearScreen(){this._graphicsContext.clear()}_isOffscreen(t,e){if(t.coordPlane===wi.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:n,options:r}of s.graphics){let o=t.anchor,a=t.offset;(null==r?void 0:r.anchor)&&(o=r.anchor),(null==r?void 0:r.offset)&&(a=r.offset);const h=-n.width*o.x+a.x,l=-n.height*o.y+a.y;if(null==n||n.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=q(h+s.offset.x,l+s.offset.y);if(n instanceof wn)for(const e of n.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==n||n.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(yi);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===wi.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===wi.World&&this._graphicsContext.restore()}}class Cn extends Zs{constructor(){super(...arguments),this.types=["ex.transform","ex.canvas"],this.systemType=qs.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(yi).z-e.get(yi).z}update(t,e){var i,s,n;let r,o;this._clearScreen();const a=t.length;for(let h=0;h<a;h++){const a=null===(n=null===(s=null===(i=t[h])||void 0===i?void 0:i.graphics)||void 0===s?void 0:s.visible)||void 0===n||n,l=t[h].isOffScreen;a&&!l&&(r=t[h].get(yi),o=t[h].get($i),this._ctx.save(),this._pushCameraTransform(r),this._ctx.save(),this._applyTransform(t[h]),o.draw(this._ctx,e),this._ctx.restore(),this._popCameraTransform(r),this._ctx.restore()),this._engine.isDebug&&(this._ctx.save(),this._pushCameraTransform(r),this._ctx.strokeStyle="yellow",t[h].debugDraw(this._ctx),this._popCameraTransform(r),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=ot.DrawnImagesCount,this._engine.stats.currFrame.graphics.drawCalls=ot.DrawCallCount}_applyTransform(t){const e=t.getAncestors();for(const t of e){const e=null==t?void 0:t.get(yi);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===wi.World&&(this._ctx.save(),this._camera&&this._camera.draw(this._ctx))}_popCameraTransform(t){t.coordPlane===wi.World&&this._ctx.restore()}}class An extends Zs{constructor(){super(...arguments),this.types=["ex.transform"],this.systemType=qs.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(pn)}update(t,e){var i,s;if(!this._engine.isDebug)return;const n=this._engine.debug.filter;let r,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;const w=this._engine.debug.body,y=this._engine.debug.camera;for(const e of t){if(e.hasTag("offscreen"))continue;if(e instanceof vn)continue;if(n.useFilter){if(!(0===n.ids.length||n.ids.includes(e.id)))continue;if(!(""===n.nameQuery||e.name.includes(n.nameQuery)))continue}let t=K.Zero;const g=q(0,16);if(r=e.id,o=e.name,h=e.get(yi),this._pushCameraTransform(h),this._graphicsContext.save(),this._applyTransform(e),h&&((l.showAll||l.showPosition)&&(this._graphicsContext.debug.drawPoint(K.Zero,{size:2,color:l.positionColor}),this._graphicsContext.debug.drawText(`pos${h.pos.toString(2)}`,t),t=t.add(g)),(a.showAll||a.showId)&&(this._graphicsContext.debug.drawText(`id(${r}) ${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(K.Zero,K.fromAngle(h.rotation).scale(50).add(K.Zero),l.rotationColor,2),this._graphicsContext.debug.drawText(`rot deg(${R(h.rotation).toFixed(2)})`,t),t=t.add(g)),(l.showAll||l.showScale)&&this._graphicsContext.drawLine(K.Zero,h.scale.add(K.Zero),l.scaleColor,2)),_=e.get(is),_&&(f.showAll||f.showBounds)){_.localBounds.draw(this._graphicsContext,f.boundsColor)}if(m=e.get(Vi),m&&((w.showAll||w.showCollisionGroup)&&(this._graphicsContext.debug.drawText(`collision group(${m.group.name})`,t),t=t.add(g)),(w.showAll||w.showCollisionType)&&(this._graphicsContext.debug.drawText(`collision type(${m.collisionType})`,t),t=t.add(g)),(w.showAll||w.showMass)&&(this._graphicsContext.debug.drawText(`mass(${m.mass})`,t),t=t.add(g)),(w.showAll||w.showMotion)&&(this._graphicsContext.debug.drawText(`motion(${m.sleepMotion})`,t),t=t.add(g)),(w.showAll||w.showSleeping)&&(this._graphicsContext.debug.drawText(`sleeping(${m.canSleep?m.sleeping:"cant sleep"})`,t),t=t.add(g))),this._graphicsContext.restore(),c=e.get(vi),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(Ni),u){const t=u.get();if((p.showAll||p.showGeometry)&&t&&t.debug(this._graphicsContext,p.geometryColor),p.showAll||p.showBounds)if(t instanceof Di){const e=t.getColliders();for(const t of e){const e=t.bounds,i=q(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=q(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(),y&&(this._graphicsContext.save(),this._camera.draw(this._graphicsContext),(y.showAll||y.showFocus)&&this._graphicsContext.drawCircle(this._camera.pos,4,y.focusColor),(y.showAll||y.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(yi);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===wi.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===wi.World&&this._graphicsContext.restore()}}class Sn extends Zs{constructor(){super(...arguments),this.types=["ex.actions"],this.systemType=qs.Update,this.priority=-1}update(t,e){let i;for(const s of t)i=s.get(Ps),i.update(e)}}var Pn,En,Tn,Rn,Dn,Bn,Mn,kn=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class Fn extends $e{constructor(){super(),this._logger=_.getInstance(),this.camera=new Gs,this.world=new on(this),this._isInitialized=!1,this._timers=[],this._cancelQueue=[],this.world.add(new Sn),this.world.add(new hn),this.world.add(new pn),p.isEnabled(c.LegacyDrawing)?this.world.add(new Cn):this.world.add(new bn),this.world.add(new An)}get actors(){return this.world.entityManager.entities.filter((t=>t instanceof Ts))}get entities(){return this.world.entityManager.entities}get triggers(){return this.world.entityManager.entities.filter((t=>t instanceof Ks))}get tileMaps(){return this.world.entityManager.entities.filter((t=>t instanceof Ls))}get screenElements(){return this.actors.filter((t=>t instanceof Rs))}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.onInitialize.call(this,t),this._initializeChildren(),this._logger.debug("Scene.onInitialize",this,t),this.eventDispatcher.emit("initialize",new ie(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 It(t,e,this)),this.onPreUpdate(t,e)}_postupdate(t,e){this.emit("postupdate",new Ot(t,e,this)),this.onPostUpdate(t,e)}_predraw(t,e){this.emit("predraw",new Mt(t,e,this)),this.onPreDraw(t,e)}_postdraw(t,e){this.emit("postdraw",new kt(t,e,this)),this.onPostDraw(t,e)}update(t,e){let i,s;for(this._preupdate(t,e),this.camera&&this.camera.update(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(qs.Update,e),this._collectActorStats(t),t.input.pointers.dispatchPointerEvents(),this._postupdate(t,e)}draw(t,e){var i;this._predraw(t,e),this.world.update(qs.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 Ft(t,this)),this.emit("postdebugdraw",new Lt(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 Bs&&(F(this._timers,t)||this.addTimer(t))}remove(t){t instanceof Qi&&(this.emit("entityremoved",{target:t}),this.world.remove(t)),t instanceof Bs&&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 Rs));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)js(i)?t.stats.currFrame.actors.ui++:t.stats.currFrame.actors.alive++}}}kn([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"ScreenElements now are normal actors with a Transform Coordinate Plane of Screen"})],Fn.prototype,"screenElements",null),kn([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Fn.prototype,"addScreenElement",null),kn([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Fn.prototype,"removeScreenElement",null),kn([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.add"})],Fn.prototype,"addTileMap",null),kn([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Scene.remove"})],Fn.prototype,"removeTileMap",null),function(t){t[t.Protanope=0]="Protanope",t[t.Deuteranope=1]="Deuteranope",t[t.Tritanope=2]="Tritanope"}(Pn||(Pn={}));class Ln{constructor(t,e=!1,i=Pn.Protanope){this.engine=t,this.simulate=e,this.colorMode=i,this._vertexShader="attribute vec2 a_position;attribute vec2 a_texCoord;uniform vec2 u_resolution;varying vec2 v_texCoord;void main() {vec2 zeroToOne = a_position / u_resolution;vec2 zeroToTwo = zeroToOne * 2.0;vec2 clipSpace = zeroToTwo - 1.0;gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);v_texCoord = a_texCoord;}",this._fragmentShader="precision mediump float;uniform sampler2D u_image;varying vec2 v_texCoord;void main() {vec4 o = texture2D(u_image, v_texCoord);float L = (17.8824 * o.r) + (43.5161 * o.g) + (4.11935 * o.b);float M = (3.45565 * o.r) + (27.1554 * o.g) + (3.86714 * o.b);float S = (0.0299566 * o.r) + (0.184309 * o.g) + (1.46709 * o.b);//MODE CODE//vec4 error;error.r = (0.0809444479 * l) + (-0.130504409 * m) + (0.116721066 * s);error.g = (-0.0102485335 * l) + (0.0540193266 * m) + (-0.113614708 * s);error.b = (-0.000365296938 * l) + (-0.00412161469 * m) + (0.693511405 * s);error.a = 1.0;vec4 diff = o - error;vec4 correction;correction.r = 0.0;correction.g = (diff.r * 0.7) + (diff.g * 1.0);correction.b = (diff.r * 0.7) + (diff.b * 1.0);correction = o + correction;correction.a = o.a;//SIMULATE//}",this._internalCanvas=document.createElement("canvas"),this._internalCanvas.width=t.drawWidth,this._internalCanvas.height=t.drawHeight,this._gl=this._internalCanvas.getContext("webgl",{preserveDrawingBuffer:!0}),this._program=this._gl.createProgram();const s=this._getShader("Fragment",this._getFragmentShaderByMode(i)),n=this._getShader("Vertex",this._vertexShader);this._gl.attachShader(this._program,n),this._gl.attachShader(this._program,s),this._gl.linkProgram(this._program),this._gl.getProgramParameter(this._program,this._gl.LINK_STATUS)||_.getInstance().error("Unable to link shader program!"),this._gl.useProgram(this._program)}_getFragmentShaderByMode(t){let e="";return t===Pn.Protanope?e="float l = 0.0 * L + 2.02344 * M + -2.52581 * S;float m = 0.0 * L + 1.0 * M + 0.0 * S;float s = 0.0 * L + 0.0 * M + 1.0 * S;":t===Pn.Deuteranope?e="float l = 1.0 * L + 0.0 * M + 0.0 * S;float m = 0.494207 * L + 0.0 * M + 1.24827 * S;float s = 0.0 * L + 0.0 * M + 1.0 * S;":t===Pn.Tritanope&&(e="float l = 1.0 * L + 0.0 * M + 0.0 * S;float m = 0.0 * L + 1.0 * M + 0.0 * S;float s = -0.395913 * L + 0.801109 * M + 0.0 * S;"),this.simulate?this._fragmentShader=this._fragmentShader.replace("//SIMULATE//","gl_FragColor = error.rgba;"):this._fragmentShader=this._fragmentShader.replace("//SIMULATE//","gl_FragColor = correction.rgba;"),this._fragmentShader.replace("//MODE CODE//",e)}_setRectangle(t,e,i,s){const n=t,r=t+i,o=e,a=e+s;this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array([n,o,r,o,n,a,n,a,r,o,r,a]),this._gl.STATIC_DRAW)}_getShader(t,e){let i;return"Fragment"===t?i=this._gl.createShader(this._gl.FRAGMENT_SHADER):"Vertex"===t?i=this._gl.createShader(this._gl.VERTEX_SHADER):_.getInstance().error("Error unknown shader type",t),this._gl.shaderSource(i,e),this._gl.compileShader(i),this._gl.getShaderParameter(i,this._gl.COMPILE_STATUS)?i:(_.getInstance().error("Unable to compile shader!",this._gl.getShaderInfoLog(i)),null)}process(t,e){const i=this._gl.getAttribLocation(this._program,"a_position"),s=this._gl.getAttribLocation(this._program,"a_texCoord"),n=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,n),this._gl.bufferData(this._gl.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),this._gl.STATIC_DRAW),this._gl.enableVertexAttribArray(s),this._gl.vertexAttribPointer(s,2,this._gl.FLOAT,!1,0,0);const r=this._gl.createTexture();this._gl.bindTexture(this._gl.TEXTURE_2D,r),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,this._gl.NEAREST),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,this._gl.NEAREST),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,1),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t);const o=this._gl.getUniformLocation(this._program,"u_resolution");this._gl.uniform2f(o,this._internalCanvas.width,this._internalCanvas.height);const a=this._gl.createBuffer();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,a),this._gl.enableVertexAttribArray(i),this._gl.vertexAttribPointer(i,2,this._gl.FLOAT,!1,0,0),this._setRectangle(0,0,t.width,t.height),this._gl.drawArrays(this._gl.TRIANGLES,0,6);const h=new Uint8Array(t.width*t.height*4);this._gl.readPixels(0,0,t.width,t.height,this._gl.RGBA,this._gl.UNSIGNED_BYTE,h),t.data.set(h),e.putImageData(t,0,0)}}class In{constructor(t){this._engine=t}correct(t){this._engine.postProcessors.push(new Ln(this._engine,!1,t))}simulate(t){this._engine.postProcessors.push(new Ln(this._engine,!0,t))}}class On{constructor(t){this.stats={currFrame:new zn,prevFrame:new zn},this.filter={useFilter:!1,nameQuery:"",ids:[]},this.entity={showAll:!1,showId:!0,showName:!1},this.transform={showAll:!1,showPosition:!1,positionColor:Q.Yellow,showScale:!1,scaleColor:Q.Green,showRotation:!1,rotationColor:Q.Blue},this.graphics={showAll:!1,showBounds:!0,boundsColor:Q.Yellow},this.collider={showAll:!1,showBounds:!0,boundsColor:Q.Blue,showOwner:!1,showGeometry:!0,geometryColor:Q.Green},this.physics={showAll:!1,showBroadphaseSpacePartitionDebug:!1,showCollisionNormals:!1,collisionNormalColor:Q.Cyan,showCollisionContacts:!0,collisionContactColor:Q.Red},this.motion={showAll:!1,showVelocity:!1,velocityColor:Q.Yellow,showAcceleration:!1,accelerationColor:Q.Red},this.body={showAll:!1,showCollisionGroup:!1,showCollisionType:!1,showSleeping:!1,showMotion:!1,showMass:!1},this.camera={showAll:!1,showFocus:!1,focusColor:Q.Red,showZoom:!1},this._engine=t,this.colorBlindMode=new In(this._engine)}}class zn{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 Un,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 zn;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 Un{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 Un;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}}!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"}(En||(En={}));class Hn extends Pt{constructor(t,e,i){super(),this.key=t,this.value=e,this.originalEvent=i}}class Nn extends $e{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,_.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 Hn(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 Hn(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 Hn(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}}!function(t){t.Touch="Touch",t.Mouse="Mouse",t.Pen="Pen",t.Unknown="Unknown"}(Tn||(Tn={})),function(t){t.Canvas="Canvas",t.Document="Document"}(Rn||(Rn={}));class Wn extends $e{constructor(){super(),this.id=Wn._MAX_ID++,this._isDown=!1,this._wasDown=!1,this._actorsUnderPointer={length:0},this._actors=[],this._actorsLastFrame=[],this._actorsNoLongerUnderPointer=[],this._actorSortingFcn=(t,e)=>t.z===e.z?e.id-t.id:e.z-t.z,this.lastPagePos=null,this.lastScreenPos=null,this.lastWorldPos=null,this.dragTarget=null,this.on("move",this._onPointerMove),this.on("down",this._onPointerDown),this.on("up",this._onPointerUp)}get isDragging(){return this._isDown}get isDragStart(){return!this._wasDown&&this._isDown}get isDragEnd(){return this._wasDown&&!this._isDown}get hasActorsUnderPointer(){return!!this._actorsUnderPointer.length}on(t,e){super.on(t,e)}once(t,e){super.once(t,e)}off(t,e){super.off(t,e)}update(){this._wasDown&&!this._isDown?this._wasDown=!1:!this._wasDown&&this._isDown&&(this._wasDown=!0),this._actorsLastFrame=[...this._actors],this._actorsNoLongerUnderPointer=[]}addActorUnderPointer(t){this.isActorAliveUnderPointer(t)||(this._actorsUnderPointer[t.id]=t,this._actorsUnderPointer.length+=1,this._actors.push(t)),this._actors.sort(this._actorSortingFcn)}removeActorUnderPointer(t){this.isActorAliveUnderPointer(t)&&(delete this._actorsUnderPointer[t.id],this._actorsUnderPointer.length-=1,k(t,this._actors),this._actorsNoLongerUnderPointer.push(t))}getActorsUnderPointer(){return this._actors}getActorsUnderPointerLastFrame(){return this._actorsLastFrame}getActorsForEvents(){return this._actors.concat(this._actorsLastFrame).filter(((t,e,i)=>i.indexOf(t)===e)).sort(this._actorSortingFcn)}checkActorUnderPointer(t){return!!this.lastWorldPos&&t.contains(this.lastWorldPos.x,this.lastWorldPos.y,!js(t))}wasActorUnderPointer(t){return this._actorsLastFrame.indexOf(t)>-1}isActorAliveUnderPointer(t){return!(t.isKilled()||!t.scene||!this._actorsUnderPointer.hasOwnProperty(t.id.toString()))}_onPointerMove(t){this.lastPagePos=new K(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new K(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new K(t.worldPos.x,t.worldPos.y)}_onPointerDown(t){this.lastPagePos=new K(t.pagePos.x,t.pagePos.y),this.lastScreenPos=new K(t.screenPos.x,t.screenPos.y),this.lastWorldPos=new K(t.worldPos.x,t.worldPos.y),this._isDown=!0}_onPointerUp(t){this._isDown=!1,this.dragTarget=null}}Wn._MAX_ID=0,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"}(Dn||(Dn={})),function(t){t.Left="Left",t.Middle="Middle",t.Right="Right",t.Unknown="Unknown",t.NoButton="NoButton"}(Bn||(Bn={})),function(t){t.Pixel="Pixel",t.Line="Line",t.Page="Page"}(Mn||(Mn={}));class Vn extends Pt{constructor(t,e,i,s,n,r){super(),this.coordinates=t,this.pointer=e,this.index=i,this.pointerType=s,this.button=n,this.ev=r,this._canceled=!1}get name(){return this._name}get worldPos(){return this.coordinates.worldPos.clone()}get pagePos(){return this.coordinates.pagePos.clone()}get screenPos(){return this.coordinates.screenPos.clone()}get pos(){return this.coordinates.worldPos.clone()}cancel(){this._canceled=!0}isCanceled(){return this._canceled}propagate(t){this.doAction(t),this.bubbles&&!this.isCanceled()&&t.parent&&this.propagate(t.parent)}doAction(t){t&&(this._onActionStart(t),t.emit(this._name,this),this._onActionEnd(t))}_onActionStart(t){}_onActionEnd(t){}}class Gn{constructor(t){this._pointerEventType=t}create(t,e,i,s,n,r){return new this._pointerEventType(t,e,i,s,n,r)}}class jn extends Vn{}class Xn extends Vn{constructor(){super(...arguments),this._name="pointerup"}_onActionEnd(t){this.pointer.isDragEnd&&t.capturePointer.captureDragEvents&&t.eventDispatcher.emit("pointerdragend",this)}}class Kn extends Vn{constructor(){super(...arguments),this._name="pointerdown"}_onActionEnd(t){this.pointer.isDragStart&&t.capturePointer.captureDragEvents&&t.eventDispatcher.emit("pointerdragstart",this)}}class qn extends Vn{constructor(){super(...arguments),this._name="pointermove"}propagate(t){this.pointer.isActorAliveUnderPointer(t)&&(this.doAction(t),this.bubbles&&!this.isCanceled()&&t.parent&&this.propagate(t.parent))}_onActionStart(t){t.capturePointer.captureMoveEvents&&this.pointer.isDragging&&t.capturePointer.captureDragEvents&&t.eventDispatcher.emit("pointerdragmove",this)}}class Zn extends Vn{constructor(){super(...arguments),this._name="pointerenter"}_onActionStart(t){t.capturePointer.captureMoveEvents}_onActionEnd(t){this.pointer.isDragging&&t.capturePointer.captureDragEvents&&t.eventDispatcher.emit("pointerdragenter",this)}}class Yn extends Vn{constructor(){super(...arguments),this._name="pointerleave"}_onActionStart(t){t.capturePointer.captureMoveEvents}_onActionEnd(t){this.pointer.isDragging&&t.capturePointer.captureDragEvents&&t.eventDispatcher.emit("pointerdragleave",this)}}class Qn extends Vn{constructor(){super(...arguments),this._name="pointercancel"}}class $n extends Pt{constructor(t,e,i,s,n,r,o,a,h,l,c,d){super(),this.x=t,this.y=e,this.pageX=i,this.pageY=s,this.screenX=n,this.screenY=r,this.index=o,this.deltaX=a,this.deltaY=h,this.deltaZ=l,this.deltaMode=c,this.ev=d,this._isCanceled=!1}cancel(){this._isCanceled=!0}isCanceled(){return this._isCanceled}}function Jn(t,e,i,s,n,r,o){let a;switch(t){case"up":a=new Gn(Xn);break;case"down":a=new Gn(Kn);break;case"move":a=new Gn(qn);break;case"cancel":a=new Gn(Qn);break;case"enter":a=new Gn(Zn);break;case"leave":a=new Gn(Yn)}return a.create(e,i,s,n,r,o)}class tr{constructor(t,e,i){this.worldPos=t,this.pagePos=e,this.screenPos=i}static fromPagePosition(t,e,i){let s,n,r,o;3===arguments.length?(s=t,n=e,r=new K(s,n),o=i):(r=t,s=r.x,n=r.y,o=e);const a=o.screen.pageToScreenCoordinates(r),h=o.screen.screenToWorldCoordinates(a);return new tr(h,r,a)}}const er=-1/40;class ir extends $e{constructor(t){super(),this._pointerDown=[],this._pointerUp=[],this._pointerMove=[],this._pointerCancel=[],this._wheel=[],this._pointers=[],this._activePointers=[],this._engine=t,this._pointers.push(new Wn),this._activePointers=[-1],this.primary=this._pointers[0]}on(t,e){super.on(t,e)}init(t){(t=t||this._engine.canvas).addEventListener("touchstart",this._handleTouchEvent("down",this._pointerDown)),t.addEventListener("touchend",this._handleTouchEvent("up",this._pointerUp)),t.addEventListener("touchmove",this._handleTouchEvent("move",this._pointerMove)),t.addEventListener("touchcancel",this._handleTouchEvent("cancel",this._pointerCancel)),window.PointerEvent?(this._engine.canvas.style.touchAction="none",t.addEventListener("pointerdown",this._handlePointerEvent("down",this._pointerDown)),t.addEventListener("pointerup",this._handlePointerEvent("up",this._pointerUp)),t.addEventListener("pointermove",this._handlePointerEvent("move",this._pointerMove)),t.addEventListener("pointercancel",this._handlePointerEvent("cancel",this._pointerCancel))):window.MSPointerEvent?(this._engine.canvas.style.msTouchAction="none",t.addEventListener("MSPointerDown",this._handlePointerEvent("down",this._pointerDown)),t.addEventListener("MSPointerUp",this._handlePointerEvent("up",this._pointerUp)),t.addEventListener("MSPointerMove",this._handlePointerEvent("move",this._pointerMove)),t.addEventListener("MSPointerCancel",this._handlePointerEvent("cancel",this._pointerCancel))):(t.addEventListener("mousedown",this._handleMouseEvent("down",this._pointerDown)),t.addEventListener("mouseup",this._handleMouseEvent("up",this._pointerUp)),t.addEventListener("mousemove",this._handleMouseEvent("move",this._pointerMove)));const e={passive:!(this._engine.pageScrollPreventionMode===dr.All||this._engine.pageScrollPreventionMode===dr.Canvas)};"onwheel"in document.createElement("div")?t.addEventListener("wheel",this._handleWheelEvent("wheel",this._wheel),e):void 0!==document.onmousewheel?t.addEventListener("mousewheel",this._handleWheelEvent("wheel",this._wheel),e):t.addEventListener("MozMousePixelScroll",this._handleWheelEvent("wheel",this._wheel),e)}triggerEvent(t,e,i=Dn.Left,s="mouse",n=0){let r,o=0,a=0;e instanceof tr?(o=e.pagePos.x,a=e.pagePos.y,r=e):(o=e.x,a=e.y,r=new tr(e.clone(),e.clone(),e.clone()));const h={pageX:o,pageY:a,pointerId:n,pointerType:s,button:i,preventDefault:()=>{}};switch(t){case"move":this._handlePointerEvent(t,this._pointerMove,r)(h);break;case"down":this._handlePointerEvent(t,this._pointerDown,r)(h);break;case"up":this._handlePointerEvent(t,this._pointerUp,r)(h);break;case"cancel":this._handlePointerEvent(t,this._pointerCancel,r)(h)}for(const t of this._engine.currentScene.actors){const e=t.traits.filter((t=>t instanceof Xi))[0];e&&e.update(t,this._engine,1)}this.dispatchPointerEvents(),this.update()}update(){this._pointerUp.length=0,this._pointerDown.length=0,this._pointerMove.length=0,this._pointerCancel.length=0,this._wheel.length=0;for(let t=0;t<this._pointers.length;t++)this._pointers[t].update()}at(t){if(t>=this._pointers.length)for(let e=this._pointers.length-1,i=t;e<i;e++)this._pointers.push(new Wn),this._activePointers.push(-1);return this._pointers[t]}count(){return this._pointers.length}checkAndUpdateActorUnderPointer(t){for(const e of this._pointers)e.checkActorUnderPointer(t)?e.addActorUnderPointer(t):e.removeActorUnderPointer(t)}_dispatchWithBubble(t){for(const e of t)for(const t of e.pointer.getActorsForEvents())if(e.isCanceled()||e.propagate(t),!e.bubbles||e.isCanceled())break}_dispatchPointerLeaveEvents(){const t={},e=[];for(const i of this._pointerMove)for(const s of i.pointer.getActorsForEvents())if(!t[i.pointer.id+"+"+s.id]&&i.pointer.wasActorUnderPointer(s)&&!i.pointer.isActorAliveUnderPointer(s)&&!i.isCanceled()){t[i.pointer.id+"+"+s.id]=i;const n=Jn("leave",new tr(i.worldPos,i.pagePos,i.screenPos),i.pointer,i.index,i.pointerType,i.button,i.ev);n.propagate(s),e.push(n)}return e}_dispatchPointerEnterEvents(){const t={},e=[];for(const i of this._pointerMove)for(const s of i.pointer.getActorsForEvents())if(!t[i.pointer.id]&&!i.pointer.wasActorUnderPointer(s)&&i.pointer.isActorAliveUnderPointer(s)&&!i.isCanceled()){t[i.pointer.id]=i;const n=Jn("enter",new tr(i.worldPos,i.pagePos,i.screenPos),i.pointer,i.index,i.pointerType,i.button,i.ev);n.propagate(s),e.push(n),i.pointer.isDragging&&(i.pointer.dragTarget=s)}return e}dispatchPointerEvents(){this._dispatchWithBubble(this._pointerDown),this._dispatchWithBubble(this._pointerUp),this._dispatchWithBubble(this._pointerMove),this._dispatchPointerLeaveEvents(),this._dispatchPointerEnterEvents(),this._dispatchWithBubble(this._pointerCancel);for(const t of this._wheel)for(const e of this._pointers[t.index].getActorsUnderPointer())if(this._propagateWheelPointerEvent(e,t),!t.bubbles||t.isCanceled())break}_propagateWheelPointerEvent(t,e){t.emit("pointerwheel",e),e.bubbles&&!e.isCanceled()&&t.parent&&this._propagateWheelPointerEvent(t.parent,e)}_handleMouseEvent(t,e){return i=>{i.preventDefault();const s=this.at(0),n=tr.fromPagePosition(i.pageX,i.pageY,this._engine),r=Jn(t,n,s,0,Tn.Mouse,this._nativeButtonToPointerButton(i.button),i);e.push(r),s.eventDispatcher.emit(t,r)}}_handleTouchEvent(t,e){return i=>{i.preventDefault();for(let s=0,n=i.changedTouches.length;s<n;s++){const n=this._pointers.length>1?this._getPointerIndex(i.changedTouches[s].identifier):0;if(-1===n)continue;const r=this.at(n),o=tr.fromPagePosition(i.changedTouches[s].pageX,i.changedTouches[s].pageY,this._engine),a=Jn(t,o,r,n,Tn.Touch,Bn.Unknown,i);e.push(a),r.eventDispatcher.emit(t,a),this.emit(t,a),this._pointers.length>1&&("up"===t?this._activePointers[n]=-1:"down"===t&&(this._activePointers[n]=i.changedTouches[s].identifier))}}}_handlePointerEvent(t,e,i){return s=>{s.preventDefault();const n=this._pointers.length>1?this._getPointerIndex(s.pointerId):0;if(-1===n)return;const r=this.at(n),o=i||tr.fromPagePosition(s.pageX,s.pageY,this._engine),a=Jn(t,o,r,n,this._stringToPointerType(s.pointerType),this._nativeButtonToPointerButton(s.button),s);e.push(a),r.eventDispatcher.emit(t,a),this.emit(t,a),this._pointers.length>1&&("up"===t?this._activePointers[n]=-1:"down"===t&&(this._activePointers[n]=s.pointerId))}}_handleWheelEvent(t,e){return i=>{(this._engine.pageScrollPreventionMode===dr.All||this._engine.pageScrollPreventionMode===dr.Canvas&&i.target===this._engine.canvas)&&i.preventDefault();const s=this._engine.screen.pageToScreenCoordinates(q(i.pageX,i.pageY)),n=this._engine.screen.screenToWorldCoordinates(s),r=i.deltaX||i.wheelDeltaX*er||0,o=i.deltaY||i.wheelDeltaY*er||i.wheelDelta*er||i.detail||0,a=i.deltaZ||0;let h=Mn.Pixel;i.deltaMode&&(1===i.deltaMode?h=Mn.Line:2===i.deltaMode&&(h=Mn.Page));const l=new $n(n.x,n.y,i.pageX,i.pageY,s.x,s.y,0,r,o,a,h,i);e.push(l),this.at(0).eventDispatcher.emit(t,l),this.emit(t,l)}}_getPointerIndex(t){let e;if((e=this._activePointers.indexOf(t))>-1)return e;for(let t=0;t<this._activePointers.length;t++)if(-1===this._activePointers[t])return t;return-1}_nativeButtonToPointerButton(t){switch(t){case Dn.NoButton:return Bn.NoButton;case Dn.Left:return Bn.Left;case Dn.Middle:return Bn.Middle;case Dn.Right:return Bn.Right;case Dn.Unknown:return Bn.Unknown;default:return z(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 sr extends $e{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 Ht(e,this.at(e))),this.at(e).connected=!0,t[e].timestamp&&t[e].timestamp===this._gamePadTimeStamps[e])continue;let i,s,n,r,o;for(i in this._gamePadTimeStamps[e]=t[e].timestamp,this.at(e).navigatorGamepad=t[e],rr)s=rr[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 Wt(s,o,this.at(e)))):this.at(e).updateButton(s,0)));for(n in or)r=or[n],"number"==typeof r&&(o=t[e].axes[r],o!==this._oldPads[e].getAxes(r)&&(this.at(e).updateAxes(r,o),this.at(e).eventDispatcher.emit("axis",new Vt(r,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 nr),this._oldPads.push(new nr);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 nr;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}}sr.MinAxisMoveThreshold=.05;class nr extends $e{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)<sr.MinAxisMoveThreshold?0:e}updateButton(t,e){this._buttons[t]=e}updateAxes(t,e){this._axes[t]=e}}var rr,or;!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"}(rr||(rr={})),function(t){t[t.LeftStickX=0]="LeftStickX",t[t.LeftStickY=1]="LeftStickY",t[t.RightStickX=2]="RightStickX",t[t.RightStickY=3]="RightStickY"}(or||(or={}));class ar{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 hr{constructor(t,e){this._windowGlobal=t,this._documentGlobal=e,this._windowComponent=new ar(this._windowGlobal),this._documentComponent=new ar(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 lr{constructor(t){this._ex=t,this._debugText=new Ge}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:Q.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:Q.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 cr{constructor(t){this.backgroundColor=Q.ExcaliburBlue,this._state=new st,this.snapToPixel=!0,this.debug=new lr(this);const{canvasElement:e,enableTransparency:i,snapToPixel:s,smoothing:n,backgroundColor:r}=t;this.__ctx=e.getContext("2d",{alpha:null==i||i}),this.backgroundColor=null!=r?r:this.backgroundColor,this.snapToPixel=null!=s?s:this.snapToPixel,this.smoothing=null!=n?n: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(){}drawImage(t,e,i,s,n,r,o,a,h){if(0===s||0===n)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,n,r,o,a,h].filter((t=>void 0!==t)).map((t=>"number"==typeof t&&this.snapToPixel?~~t:t));this.__ctx.drawImage.apply(this.__ctx,l),ot.DrawCallCount++,ot.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){this.__ctx.save(),this.__ctx.beginPath(),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(),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)}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),ot.clear()}flush(){}}var dr,ur=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};u(),function(t){t[t.None=0]="None",t[t.Canvas=1]="Canvas",t[t.All=2]="All"}(dr||(dr={}));class pr extends $e{constructor(t){var e,i,s;super(),this._hasStarted=!1,this.postProcessors=[],this.scenes={},this._animations=[],this._suppressPlayButton=!1,this.pauseAudioWhenHidden=!0,this._isDebug=!1,this.debugColor=new Q(255,255,255),this.enableCanvasTransparency=!0,this.onFatalException=t=>{_.getInstance().fatal(t)},this._timescale=1,this._isLoading=!1,this._isInitialized=!1,this._deferredGoTo=null,this._loadingComplete=!1,t=Object.assign(Object.assign({},pr._DEFAULT_ENGINE_OPTIONS),t),p.freeze(),this.browser=new hr(window,document);const n=new hi;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${Jr})`,"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=_.getInstance(),this._logger.defaultLevel===d.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 r=null!==(e=t.displayMode)&&void 0!==e?e:Ke.Fixed;if(t.width&&t.height||t.viewport?(void 0===t.displayMode&&(r=Ke.Fixed),this._logger.debug("Engine viewport is size "+t.width+" x "+t.height)):t.displayMode||(this._logger.debug("Engine viewport is fit"),r=Ke.FitScreen),p.isEnabled(c.Canvas)){const e=new cr({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 Xe({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 Ze({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}:qe.SVGA,resolution:t.resolution,displayMode:r,position:t.position,pixelRatio:t.suppressHiDPIScaling?1:null}),t.backgroundColor&&(this.backgroundColor=t.backgroundColor.clone()),this.enableCanvasTransparency=t.enableCanvasTransparency,this._loader=new oi,this.debug=new On(this),this._initialize(t),this.rootScene=this.currentScene=new Fn,this.addScene("root",this.rootScene)}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}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?_.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 gr(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 Fn)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 Qi&&this.currentScene.remove(t),t instanceof Fn&&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 ne(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 se(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){let e,i;this.pageScrollPreventionMode=t.scrollPreventionMode,this.input={keyboard:new Nn,pointers:new ir(this),gamepads:new sr},this.input.keyboard.init(),this.input.pointers.init(t&&t.pointerScope===Rn.Document?document:this.canvas),this.input.gamepads.init(),void 0!==document.hidden?(e="hidden",i="visibilitychange"):"msHidden"in document?(e="msHidden",i="msvisibilitychange"):"webkitHidden"in document&&(e="webkitHidden",i="webkitvisibilitychange"),this.browser.document.on(i,(()=>{document[e]?(this.eventDispatcher.emit("hidden",new Kt(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 ie(t,this)),this._isInitialized=!0,this._deferredGoTo?this.goToScene(this._deferredGoTo):this.goToScene("root"))}_update(t){if(this._isLoading)return this._loader.update(this,t),this.input.keyboard.update(),this.input.pointers.update(),void this.input.gamepads.update();this._overrideInitialize(this),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.pointers.update(),this.input.gamepads.update(),this._postupdate(t)}_preupdate(t){this.emit("preupdate",new It(this,t,this)),this.onPreUpdate(this,t)}onPreUpdate(t,e){}_postupdate(t){this.emit("postupdate",new Ot(this,t,this)),this.onPostUpdate(this,t)}onPostUpdate(t,e){}_draw(t){const e=this.ctx;if(this._predraw(e,t),this._isLoading)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()+" : "+(En[t[e]]?En[t[e]]:"Not Mapped"),100,10*e+10);this.ctx.fillText("FPS:"+this.stats.currFrame.fps.toFixed(2).toString(),10,10)}for(let t=0;t<this.postProcessors.length;t++)this.postProcessors[t].process(this.ctx.getImageData(0,0,this.canvasWidth,this.canvasHeight),this.ctx);this._postdraw(e,t)}_predraw(t,e){this.emit("predraw",new Mt(t,e,this)),this.onPreDraw(t,e)}onPreDraw(t,e){}_postdraw(t,e){this.emit("postdraw",new kt(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}start(t){if(!this._compatible)return Promise.reject("Excalibur is incompatible with your browser");let e;return this.screen.pushResolutionAndViewport(),this.screen.resolution=this.screen.viewport,this.screen.applyResolutionAndViewport(),this.graphicsContext.updateViewport(),t?(this._loader=t,this._loader.suppressPlayButton=this._suppressPlayButton||this._loader.suppressPlayButton,this._loader.wireEngine(this),e=this.load(this._loader)):e=Promise.resolve(),e.then((()=>{this.screen.popResolutionAndViewport(),this.screen.applyResolutionAndViewport(),this.graphicsContext.updateViewport(),this.emit("start",new Dt(this)),this._loadingComplete=!0})),this._hasStarted||(this._hasStarted=!0,this._logger.debug("Starting game..."),this.browser.resume(),pr.createMainLoop(this,window.requestAnimationFrame,Date.now)(),this._logger.debug("Game started")),e}static createMainLoop(t,e,i){let s=i();return function n(){if(t._hasStarted)try{t._requestId=e(n),t.emit("preframe",new zt(t,t.stats.prevFrame));const r=i();let o=Math.floor(r-s)||1;o>200&&(o=1);const a=o*t.timescale,h=t.stats.prevFrame.id+1;t.stats.currFrame.reset(),t.stats.currFrame.id=h,t.stats.currFrame.delta=a,t.stats.currFrame.fps=1/(a/1e3);const l=i();t._update(a);const c=i();t._draw(a);const d=i();t.stats.currFrame.duration.update=c-l,t.stats.currFrame.duration.draw=d-c,s=r,t.emit("postframe",new Ut(t,t.stats.currFrame)),t.stats.prevFrame.reset(t.stats.currFrame)}catch(e){window.cancelAnimationFrame(t._requestId),t.stop(),t.onFatalException(e)}}}stop(){this._hasStarted&&(this.emit("stop",new Bt(this)),this.browser.pause(),this._hasStarted=!1,this._logger.debug("Game stopped"))}isPaused(){return!this._hasStarted}screenshot(){const t=new Image,e=this.canvas.toDataURL("image/png");return t.src=e,t}load(t){return new Promise((e=>{this._isLoading=!0,t.load().then((()=>{this._suppressPlayButton?setTimeout((()=>{this._isLoading=!1,e()}),500):(this._isLoading=!1,e())}))}))}}pr._DEFAULT_ENGINE_OPTIONS={width:0,height:0,enableCanvasTransparency:!0,canvasElementId:"",canvasElement:void 0,snapToPixel:!1,pointerScope:Rn.Canvas,suppressConsoleBootMessage:null,suppressMinimumBrowserFeatureDetection:null,suppressHiDPIScaling:null,suppressPlayButton:null,scrollPreventionMode:dr.Canvas,backgroundColor:Q.fromHex("#2185d0")},ur([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use Actor.graphics"})],pr.prototype,"playAnimation",null);let gr=class{constructor(t,e,i){this.animation=t,this.x=e,this.y=i}};gr=ur([j({message:"Will be removed in excalibur v0.26.0"})],gr);class _r extends Pt{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 fr extends _r{constructor(t,e){super(t,"NativeSoundEvent"),this.track=e}}class mr extends _r{constructor(t,e){super(t,"NativeSoundProcessedEvent"),this._processedData=e,this.data=this._processedData}}class wr extends Ct{constructor(t={}){var e,i,s,n,r,o,a,h,l,c,d,u;super(t),this.quality=2,this.family="sans-serif",this.style=Oe.Normal,this.bold=!1,this.unit=Fe.Px,this.textAlign=Le.Left,this.baseAlign=Ie.Alphabetic,this.direction=ze.LeftToRight,this.size=10,this.shadow=null,this._textBounds=new J,this._textWidth=0,this._textHeight=0,this.family=null!==(e=null==t?void 0:t.family)&&void 0!==e?e:this.family,this.style=null!==(i=null==t?void 0:t.style)&&void 0!==i?i:this.style,this.bold=null!==(s=null==t?void 0:t.bold)&&void 0!==s?s:this.bold,this.size=null!==(n=null==t?void 0:t.size)&&void 0!==n?n:this.size,this.unit=null!==(r=null==t?void 0:t.unit)&&void 0!==r?r:this.unit,this.textAlign=null!==(o=null==t?void 0:t.textAlign)&&void 0!==o?o:this.textAlign,this.baseAlign=null!==(a=null==t?void 0:t.baseAlign)&&void 0!==a?a:this.baseAlign,this.direction=null!==(h=null==t?void 0:t.direction)&&void 0!==h?h:this.direction,this.quality=null!==(l=null==t?void 0:t.quality)&&void 0!==l?l:this.quality,(null==t?void 0:t.shadow)&&(this.shadow={},this.shadow.blur=null!==(c=t.shadow.blur)&&void 0!==c?c:this.shadow.blur,this.shadow.offset=null!==(d=t.shadow.offset)&&void 0!==d?d:this.shadow.offset,this.shadow.color=null!==(u=t.shadow.color)&&void 0!==u?u:this.shadow.color),this.flagDirty()}clone(){return new wr(Object.assign(Object.assign(Object.assign({},this.cloneGraphicOptions()),this.cloneRasterOptions()),{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 width(){return this._textWidth}set width(t){this._textWidth=t}get height(){var t,e;const i=null!==(e=null===(t=this._lines)||void 0===t?void 0:t.length)&&void 0!==e?e:1;return this._textHeight*i}set height(t){var e,i;const s=null!==(i=null===(e=this._lines)||void 0===e?void 0:e.length)&&void 0!==i?i:1;this._textHeight=t/s}get _rasterWidth(){return this._bitmap.width}get _rasterHeight(){return this._bitmap.height}get _halfRasterWidth(){return Math.floor(this._bitmap.width/2)}get _halfRasterHeight(){return Math.floor(this._bitmap.height/2)}get localBounds(){return this._textBounds}_drawImage(t,e,i){this.dirty&&this.rasterize(),t.drawImage(this._bitmap,0,0,this._rasterWidth,this._rasterHeight,e-this._rasterWidth/this.quality/2,i-this._rasterHeight/this.quality/2,this._rasterWidth/this.quality,this._rasterHeight/this.quality)}_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))}updateText(t){this._text!==t&&(this._text=t,this._lines=this._text.split("\n"),this._updateDimensions(),this.flagDirty())}_updateDimensions(){if(this._text){this._applyFont(this._ctx);const t=this._lines.reduce(((t,e)=>t.length>e.length?t:e)),e=this._ctx.measureText(t);this._textWidth=Math.abs(e.actualBoundingBoxLeft)+Math.abs(e.actualBoundingBoxRight),this._textHeight=Math.abs(e.actualBoundingBoxAscent)+Math.abs(e.actualBoundingBoxDescent);const i=this._textHeight*this._lines.length;this._bitmap.width=2*(this._textWidth+2*this.padding)*this.quality,this._bitmap.height=2*(i+2*this.padding)*this.quality;const s=0,n=0,r=i-Math.abs(e.actualBoundingBoxAscent);this._textBounds=new J({left:s-Math.abs(e.actualBoundingBoxLeft)-this.padding,top:n-Math.abs(e.actualBoundingBoxAscent)-this.padding,bottom:n+r+this.padding,right:s+Math.abs(e.actualBoundingBoxRight)+this.padding})}}_preDraw(t,e,i){this.dirty&&this._updateDimensions(),super._preDraw(t,e,i)}_postDraw(t){this.showDebug&&t.debug.drawRect(-this._halfRasterWidth,-this._halfRasterHeight,this._rasterWidth,this._rasterHeight),t.restore()}_applyFont(t){t.translate(this.padding+this._halfRasterWidth,this.padding+this._halfRasterHeight),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)}execute(t){if(this._text){this._applyRasterProperites(t),this._applyFont(t);const e=this._textHeight;for(let i=0;i<this._lines.length;i++){const s=this._lines[i];this.color&&t.fillText(s,0,i*e),this.strokeColor&&t.strokeText(s,0,i*e)}this.showDebug&&(Je(t,Q.Red,-this._halfRasterWidth,0,this._halfRasterWidth,0,2),Je(t,Q.Red,0,-this._halfRasterHeight,0,this._halfRasterHeight,2))}}render(t,e,i,s){this.updateText(e),this.draw(t,i,s)}}class yr extends vt{constructor(t){var e,i;super(t),this._text="",this.font=null!==(e=t.font)&&void 0!==e?e:new wr,this.color=null!==(i=t.color)&&void 0!==i?i:this.color,this.text=t.text}clone(){return new yr({text:this.text.slice(),color:this.color.clone(),font:this.font.clone()})}get text(){return this._text}set text(t){this._text=t,this.font.updateText(t)}get color(){return this.font instanceof wr?this.font.color:Q.Black}set color(t){this.font instanceof wr&&(this.font.color=t)}get font(){return this._font}set font(t){this._font=t instanceof wr?xt(t,(t=>t.flagDirty())):t}get width(){return this.font.width}get height(){return this.font.height}get localBounds(){return this.font.localBounds}_rotate(t){}_flip(t){}_drawImage(t,e,i){this.font instanceof wr&&(this.font.color=this.color),this.font.flipHorizontal=this.flipHorizontal,this.font.flipVertical=this.flipVertical,this.font.scale=this.scale,this.font.rotation=this.rotation,this.font.origin=this.origin,this.font.opacity=this.opacity,this.font.render(t,this._text,e,i)}}var vr=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class xr extends Ts{constructor(t){super(t),this.font=new wr,this._text=new yr({text:"",font:this.font}),this.letterSpacing=0,this.caseInsensitive=!0;const{text:e,pos:i,x:s,y:n,spriteFont:r,font:o,color:a}=t;this.pos=null!=i?i:s&&n?q(s,n):this.pos,this.text=null!=e?e:this.text,this.spriteFont=null!=r?r:this.spriteFont,this.font=null!=o?o:this.font,this.color=null!=a?a:this.color;const h=this.get(is);h.anchor=K.Zero,h.use(this._text)}get text(){return this._text.text}set text(t){this._text.text=t}get color(){return this._text.color}set color(t){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 Ne)return this._legacySpriteFont=t,this._spriteFont=Ve.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:q(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)}}vr([j({message:"Label.bold will be removed in v0.26.0",alternateMethod:"Use Label.font.bold"})],xr.prototype,"bold",null),vr([j({message:"Label.fontFamily will be removed in v0.26.0",alternateMethod:"Use Label.font.family"})],xr.prototype,"fontFamily",null),vr([j({message:"Label.fontSize will be removed in v0.26.0",alternateMethod:"Use Label.font.size"})],xr.prototype,"fontSize",null),vr([j({message:"Label.fontStyle will be removed in v0.26.0",alternateMethod:"Use Lable.font.style"})],xr.prototype,"fontStyle",null),vr([j({message:"Label.fontUnit will be removed in v0.26.0",alternateMethod:"Use Label.font.unit"})],xr.prototype,"fontUnit",null),vr([j({message:"Label.textAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.textAlign"})],xr.prototype,"textAlign",null),vr([j({message:"Label.baseAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.baseAlign"})],xr.prototype,"baseAlign",null),vr([j()],xr.prototype,"spriteFont",null),vr([j({message:"Label.setTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],xr.prototype,"setTextShadow",null),vr([j({message:"Label.useTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],xr.prototype,"useTextShadow",null),vr([j({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],xr.prototype,"clearTextShadow",null);class br{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 xi(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}}br._STARTING_BIT=1,br._MAX_GROUPS=32,br._CURRENT_GROUP=1,br._CURRENT_BIT=br._STARTING_BIT,br._GROUPS=new Map;var Cr=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};let Ar=class{constructor(t){this.lineWidth=5,this.filled=!1,this._points=[],this.anchor=K.Zero,this.offset=K.Zero,this.rotation=0,this.scale=K.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),n=this._points.reduce(((t,e)=>Math.max(t,e.y)),0);this.drawHeight=n-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,n,r,o,a,h,l;const{ctx:c,x:d,y:u,rotation:p,drawWidth:g,drawHeight:_,anchor:f,offset:m,opacity:w,flipHorizontal:y,flipVertical:v}=Object.assign(Object.assign({},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!==(n=t.flipHorizontal)&&void 0!==n?n:this.flipHorizontal,flipVertical:null!==(r=t.flipVertical)&&void 0!==r?r: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 A=0;const S=this._points.length;for(;A<S;A++)c.lineTo(this._points[A].x,this._points[A].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)),v&&(c.translate(0,_),c.scale(1,-1));const P=c.globalAlpha;c.globalAlpha=w,c.stroke(),c.globalAlpha=P,c.restore()}};Ar=Cr([j({message:"Polygon will be removed in v0.26.0",alternateMethod:"Use Graphics.Polygon"})],Ar);class Sr{}function Pr(t){return!!t._initialize}function Er(t){return!!t.onInitialize}function Tr(t){return!!t._preupdate}function Rr(t){return!!t.onPreUpdate}function Dr(t){return!!t.onPostUpdate}function Br(t){return!!t.onPostUpdate}function Mr(t){return!!t.onPreDraw}function kr(t){return!!t.onPostDraw}Sr.type={any:"",blob:"blob",json:"json",text:"text",document:"document",arraybuffer:"arraybuffer"};class Fr{constructor(t){this._src=t,this._volume=1,this._duration=void 0,this._loop=!1,this._isPlaying=!1,this._isPaused=!1,this._audioContext=Ye.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=S(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 Lr(t){try{const e=new Audio,i=/.*\.([A-Za-z0-9]+)$/,s=t.match(i)[1];return!!e.canPlayType("audio/"+s)}catch(t){return _.getInstance().warn("Cannot determine audio support, assuming no support for the Audio Tag",t),!1}}var Ir=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class Or extends $e{constructor(...t){super(),this.logger=_.getInstance(),this._loop=!1,this._volume=1,this._duration=void 0,this._isStopped=!1,this._isPaused=!1,this._tracks=[],this._wasPlayingOnHidden=!1,this._audioContext=Ye.create(),this._resource=new ce("",Sr.type.arraybuffer);for(const e of t)if(Lr(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 fr(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}load(){return Ir(this,void 0,void 0,(function*(){if(this.data)return this.data;const t=yield this._resource.load(),e=yield this.decodeAudio(t.slice(0));return this._duration="object"==typeof e?e.duration:void 0,this.emit("processed",new mr(this,e)),this.data=e}))}decodeAudio(t){return Ir(this,void 0,void 0,(function*(){try{return yield 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."),yield 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 fr(this)),this.logger.debug("Paused all instances of sound",this.path)}}stop(){for(const t of this._tracks)t.stop();this.emit("stop",new fr(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)}_resumePlayback(){return Ir(this,void 0,void 0,(function*(){if(this._isPaused){const t=[];for(const e of this._tracks)t.push(e.play());this._isPaused=!1,this.emit("resume",new fr(this)),this.logger.debug("Resuming paused instances for sound",this.path,this._tracks),yield Promise.all(t)}return!0}))}_startPlayback(){return Ir(this,void 0,void 0,(function*(){const t=yield this._getTrackInstance(this.data),e=yield t.play((()=>{this.emit("playbackstart",new fr(this,t)),this.logger.debug("Playing new instance for sound",this.path)}));return this.emit("playbackend",new fr(this,t)),this._tracks.splice(this.getTrackId(t),1),e}))}_getTrackInstance(t){const e=new Fr(t);return e.loop=this.loop,e.volume=this.volume,e.duration=this.duration,this._tracks.push(e),e}}var zr=function(t,e,i,s){return new(i||(i=Promise))((function(n,r){function o(t){try{h(s.next(t))}catch(t){r(t)}}function a(t){try{h(s.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}h((s=s.apply(t,e||[])).next())}))};class Ur{constructor(t,e=Q.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 ce(t,"arraybuffer",i),this._transparentColor=e}load(){return zr(this,void 0,void 0,(function*(){const t=yield this._resource.load();this._stream=new Wr(t),this._gif=new Vr(this._stream,this._transparentColor);const e=this._gif.images.map((t=>new De(t.src,!1)));return yield Promise.all(e.map((t=>t.load()))),this.data=this._textures=e}))}isLoaded(){return!!this.data}toLegacySprite(t=0){return Te.toLegacySprite(this.toSprite(t))}toLegacySpriteSheet(){return We.toLegacySpriteSheet(this.toSpriteSheet())}toLegacyAnimation(t,e){return mn.toLegacyAnimation(t,this.toAnimation(e))}toSprite(t=0){return this._textures[t].toSprite()}toSpriteSheet(){const t=this._textures.map((t=>t.toSprite()));return new We({sprites:t})}toAnimation(t){const e=this.toSpriteSheet(),i=e.sprites.length;return this._animation=mn.fromSpriteSheet(e,U(0,i),t),this._animation}get readCheckBytes(){return this._gif.checkBytes}}const Hr=t=>t.reduce((function(t,e){return 2*t+e}),0),Nr=t=>{const e=[];for(let i=7;i>=0;i--)e.push(!!(t&1<<i));return e};class Wr{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 Vr{constructor(t,e=Q.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=Nr(this._st.readByte());t.gctFlag=e.shift(),t.colorRes=Hr(e.splice(0,3)),t.sorted=e.shift(),t.globalColorTableSize=Hr(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=Nr(this._st.readByte());t.reserved=e.splice(0,3),t.disposalMethod=Hr(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)},n=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)},r=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",n(t);break;default:t.extType="unknown",r(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=Nr(this._st.readByte());t.lctFlag=e.shift(),t.interlaced=e.shift(),t.sorted=e.shift(),t.reserved=e.splice(0,2),t.lctSize=Hr(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 n=0;n<t;n++)e.charCodeAt(i>>3)&1<<(7&i)&&(s|=1<<n),i++;return s},n=[],r=1<<t,o=r+1;let a=t+1,h=[];const l=function(){h=[],a=t+1;for(let t=0;t<r;t++)h[t]=[t];h[r]=[],h[o]=null};let c,d;for(;;)if(d=c,c=s(a),c!==r){if(c===o)break;if(c<h.length)d!==r&&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]))}n.push.apply(n,h[c]),h.length===1<<a&&a<12&&a++}else l();return n}(t.lzwMinCodeSize,i),t.interlaced&&(t.pixels=((t,e)=>{const i=new Array(t.length),s=t.length/e,n=(s,n)=>{const r=t.slice(n*e,(n+1)*e);i.splice.apply(i,[s*e,e].concat(r))},r=[0,4,2,1],o=[8,8,4,2];let a=0;for(let t=0;t<4;t++)for(let e=r[t];e<s;e+=o[t])n(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 n=0,r=0;for(let e=0;e<t.pixels.length;e++)r%t.width==0&&(n++,r=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(r,n,1,1),r++;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 Gr extends Ct{constructor(t){super(t),this.points=t.points,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 q(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 Gr(Object.assign(Object.assign({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 jr=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};let Xr=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 Kr(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 Kr(this._getComparable(e),[e],null,null)),!0):this._insert(t.getLeft(),e):null==t.getRight()?(t.setRight(new Kr(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))}};Xr=jr([j({message:"Will be removed in excalibur v0.26.0",alternateMethod:"Use built in JS array.sort"})],Xr);let Kr=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}};Kr=jr([j({message:"Will be removed in excalibur v0.26.0"})],Kr);class qr{constructor(t){this._key=0,this._key=t}getTheKey(){return this._key}setKey(t){this._key=t}}var Zr,Yr,Qr=function(t,e,i,s){var n,r=arguments.length,o=r<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--)(n=t[a])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>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"}(Yr||(Yr={}));let $r=Zr=class{constructor(){this._state=Yr.Pending,this._successCallbacks=[],this._rejectCallback=()=>{}}static resolve(t){return(new Zr).resolve(t)}static reject(t){return(new Zr).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 Zr;if(!t||!t.length)return e.resolve();const i=t.length;let s=0,n=0;const r=[];return t.forEach((t=>{t.then((()=>{s+=1,s===i?e.resolve():s+n+r.length===i&&e.reject(r)}),(()=>{n+=1,s+n+r.length===i&&e.reject(r)})).error((t=>{r.push(t),r.length+s+n===i&&e.reject(r)}))})),e}then(t,e){if(t&&(this._successCallbacks.push(t),this.state()===Yr.Resolved))try{t.call(this,this._value)}catch(t){this._handleError(t)}if(e&&(this._rejectCallback=e,this.state()===Yr.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!==Yr.Pending)throw new Error("Cannot resolve a promise that is not in a pending state!");this._value=t;try{this._state=Yr.Resolved,this._successCallbacks.forEach((t=>{t.call(this,this._value)}))}catch(t){this._handleError(t)}return this}reject(t){if(this._state!==Yr.Pending)throw new Error("Cannot reject a promise that is not in a pending state!");this._value=t;try{this._state=Yr.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)}};$r=Zr=Qr([j({message:"ex.Promises are being replaced by native browser promises in v0.26.0",alternateMethod:"Use browser native promises"})],$r);const Jr="0.25.1";u()})();var n=s.fWn,r=s.Ia8,o=s.hLI,a=s.yyv,h=s.tX5,l=s.vtX,c=s.r7K,d=s.lCh,u=s.fwF,p=s.sce,g=s._c7,_=s.KUs,f=s.Ajp,m=s.RDh,w=s._H9,y=s.Ulf,v=s.mxs,x=s.OmD,b=s.kBf,C=s.C4F,A=s.NQt,S=s.JjN,P=s.V1s,E=s.Xz7,T=s.bLd,R=s.Cdc,D=s.FKn,B=s.wTW,M=s.ab2,k=s.GfZ,F=s.YMS,L=s.oyv,I=s.aUb,O=s.SdD,z=s.JUv,U=s.jEj,H=s.TFq,N=s.HDU,W=s.R_y,V=s.ydN,G=s._N2,j=s.t50,X=s.s$$,K=s.v2G,q=s.Ilk,Z=s.H_9,Y=s.s9i,Q=s.ksl,$=s.wA2,J=s.R_p,tt=s.IQ$,et=s.I5F,it=s.X8$,st=s.FR6,nt=s.U8o,rt=s.kbG,ot=s.oeJ,at=s.iS_,ht=s.cGG,lt=s.skb,ct=s.SLU,dt=s.RdJ,ut=s.gU7,pt=s.LSk,gt=s.Nmp,_t=s.d1Y,ft=s.xrL,mt=s.sRW,wt=s.cmV,yt=s.N0Q,vt=s.q8b,xt=s.ynB,bt=s.jT9,Ct=s.wAz,At=s.D4V,St=s.N6H,Pt=s.W1A,Et=s.JHW,Tt=s.v2K,Rt=s.pBf,Dt=s.GMl,Bt=s.zW2,Mt=s.B0K,kt=s.Nv7,Ft=s.C_p,Lt=s.MUA,It=s.xqU,Ot=s.peG,zt=s.pTp,Ut=s.vUK,Ht=s.j9l,Nt=s.Zxw,Wt=s.Hdx,Vt=s.Z$d,Gt=s.o$7,jt=s.Zm$,Xt=s.$QH,Kt=s.i78,qt=s.h6u,Zt=s.hts,Yt=s.j88,Qt=s.VME,$t=s.nt,Jt=s.Ukr,te=s.zsu,ee=s.oA6,ie=s.TVh,se=s.TwZ,ne=s.GTT,re=s.xxj,oe=s.XdK,ae=s.cXo,he=s.Dm5,le=s.IIB,ce=s.zI0,de=s.SKZ,ue=s.__J,pe=s.Dvr,ge=s.Tf9,_e=s.RI$,fe=s.x12,me=s.aNw,we=s.xwn,ye=s.dNK,ve=s.ini,xe=s.YdH,be=s.y3G,Ce=s.l57,Ae=s.xn0,Se=s.t2V,Pe=s.ZyS,Ee=s.uxB,Te=s.cpd,Re=s.fiy,De=s.$XZ,Be=s.uqK,Me=s.STE,ke=s.y$z,Fe=s.sOq,Le=s.Sqs,Ie=s.hpZ,Oe=s.Vol,ze=s.wIZ,Ue=s.cBi,He=s.mgq,Ne=s.YVA,We=s.Kgp,Ve=s.HH$,Ge=s.M_d,je=s.rgh,Xe=s.Ra6,Ke=s.KhR,qe=s.BS5,Ze=s.xhz,Ye=s.xOq,Qe=s.a9j,$e=s.bHk,Je=s.CgK,ti=s.cuY,ei=s.kvE,ii=s.JDb,si=s.Cbi,ni=s.AE_,ri=s.ctO,oi=s.OLH,ai=s.kky,hi=s.nSF,li=s.zHn,ci=s.zwx,di=s.AeJ,ui=s.hLz,pi=s.D9g,gi=s.wA,_i=s.jhr,fi=s.GVs,mi=s._zO,wi=s.w6$,yi=s.mhV,vi=s.MOD,xi=s.kwd,bi=s.Lmr,Ci=s.xsS,Ai=s.lLr,Si=s.Z$r,Pi=s.IXb,Ei=s.SMj,Ti=s.bnF,Ri=s.MFA,Di=s.$XC,Bi=s.$uU,Mi=s.jyi,ki=s.E03,Fi=s.V6q,Li=s.nVo,Ii=s.F6N,Oi=s.ad3,zi=s.xP7,Ui=s.Odq,Hi=s.Zif,Ni=s.ZGJ,Wi=s.xvT,Vi=s.PHM,Gi=s.KwO,ji=s.B7y,Xi=s.SFp,Ki=s.Uvn,qi=s.OFT,Zi=s.xzN,Yi=s.H6j,Qi=s.ZrN,$i=s.OWs,Ji=s.dF9,ts=s.VHo,es=s.R$E,is=s.q3I,ss=s.Pab,ns=s.uZ5,rs=s.McK,os=s.k0b,as=s.hnT,hs=s.RSJ,ls=s.Mku,cs=s.h90,ds=s.rms,us=s.ErP,ps=s.aVg,gs=s.lPc,_s=s.Z8E,fs=s.NNA,ms=s.yFn,ws=s.lNv,ys=s.MZQ,vs=s.FUM,xs=s.vdf,bs=s.iaL,Cs=s.w6H,As=s.Q4c,Ss=s.Uxb,Ps=s.Yr5,Es=s.Bhw;export{n as ActionContext,r as ActionQueue,o as ActionsComponent,a as ActionsSystem,h as ActivateEvent,l as Actor,c as AddedComponent,d as AddedEntity,u as Animation,p as AnimationDirection,g as AnimationStrategy,_ as ArcadeSolver,f as AudioContextFactory,m as Axis,w as BaseAlign,y as BinaryTreeNode,v as Blink,x as BodyComponent,b as BoundingBox,C as BroadphaseStrategy,A as BrowserComponent,S as BrowserEvents,P as Camera,E as Canvas,T as Cell,R as Circle,D as CircleCollider,B as Class,M as ClosestLine,k as ClosestLineJumpTable,F as Collider,L as ColliderComponent,I as CollisionContact,O as CollisionEndEvent,z as CollisionGroup,U as CollisionGroupManager,H as CollisionJumpTable,N as CollisionPostSolveEvent,W as CollisionPreSolveEvent,V as CollisionResolutionStrategy,G as CollisionSolver,j as CollisionStartEvent,X as CollisionSystem,K as CollisionType,q as Color,Z as ColorBlindCorrector,Y as ColorBlindFlags,Q as ColorBlindness,$ as Component,J as CompositeCollider,tt as Configurable,et as ConsoleAppender,it as ContactConstraintPoint,st as ContactEndEvent,nt as ContactStartEvent,rt as CoordPlane,ot as CullingBox,at as DeactivateEvent,ht as Debug,lt as DebugSystem,ct as DebugText,dt as DegreeOfFreedom,ut as Detector,pt as Die,gt as Direction,_t as DisplayMode,ft as DynamicTree,mt as DynamicTreeCollisionProcessor,wt as EX_VERSION,yt as EaseTo,vt as EasingFunctions,xt as EdgeCollider,bt as ElasticToActorStrategy,Ct as EmitterType,At as Engine,St as EnterTriggerEvent,Pt as EnterViewPortEvent,Et as Entity,Tt as EntityManager,Rt as EventDispatcher,Dt as EventTypes,Bt as Events,Mt as ExResponse,kt as ExcaliburGraphicsContext2DCanvas,Ft as ExcaliburGraphicsContextWebGL,Lt as ExitTriggerEvent,It as ExitViewPortEvent,Ot as Experiments,zt as Fade,Ut as Flags,Ht as Follow,Nt as Font,Wt as FontStyle,Vt as FontUnit,Gt as FrameStats,jt as GameEvent,Xt as GameStartEvent,Kt as GameStopEvent,qt as GamepadAxisEvent,Zt as GamepadButtonEvent,Yt as GamepadConnectEvent,Qt as GamepadDisconnectEvent,$t as Gif,Jt as GlobalCoordinates,te as Graphic,ee as GraphicsComponent,ie as GraphicsGroup,se as GraphicsLayer,ne as GraphicsLayers,re as GraphicsSystem,oe as HiddenEvent,ae as ImageSource,he as InitializeEvent,le as Input,ce as Integrator,de as KillEvent,ue as Label,pe as Legacy,ge as LegacyDrawing,_e as LimitCameraBoundsStrategy,fe as Line,me as Loader,we as LockCameraToActorAxisStrategy,ye as LockCameraToActorStrategy,ve as LogLevel,xe as Logger,be as Matrix,Ce as MatrixLocations,Ae as MediaEvent,Se as Meet,Pe as MockedElement,Ee as MotionComponent,Te as MotionSystem,Re as MoveBy,De as MoveTo,Be as NativeSoundEvent,Me as NativeSoundProcessedEvent,ke as Observable,Fe as Pair,Le as ParseGif,Ie as Particle,Oe as ParticleEmitter,ze as Physics,Ue as PhysicsStats,He as Polygon,Ne as PolygonCollider,We as Pool,Ve as PostCollisionEvent,Ge as PostDebugDrawEvent,je as PostDrawEvent,Xe as PostFrameEvent,Ke as PostKillEvent,qe as PostUpdateEvent,Ze as PreCollisionEvent,Ye as PreDebugDrawEvent,Qe as PreDrawEvent,$e as PreFrameEvent,Je as PreKillEvent,ti as PreUpdateEvent,ei as Projection,ii as Promise,si as PromiseState,ni as Query,ri as QueryManager,oi as RadiusAroundActorStrategy,ai as Random,hi as Raster,li as Ray,ci as RealisticSolver,di as Rectangle,ui as RemovedComponent,pi as RemovedEntity,gi as Repeat,_i as RepeatForever,fi as Resolution,mi as Resource,wi as RotateBy,yi as RotateTo,vi as RotationType,xi as ScaleBy,bi as ScaleTo,Ci as Scene,Ai as Screen,Si as ScreenAppender,Pi as ScreenElement,Ei as ScrollPreventionMode,Ti as Shape,Ri as Side,Di as SortedList,Bi as Sound,Mi as Sprite,ki as SpriteFont,Fi as SpriteSheet,Li as StrategyContainer,Ii as Stream,Oi as SubscribeEvent,zi as System,Ui as SystemManager,Hi as SystemType,Ni as TagComponent,Wi as Text,Vi as TextAlign,Gi as TileMap,ji as Timer,Xi as Traits,Ki as TransformComponent,qi as TreeNode,Zi as Trigger,Yi as UnsubscribeEvent,Qi as Util,$i as Vector,Ji as VectorView,ts as VisibleEvent,es as WebAudioInstance,is as World,ss as canonicalizeAngle,ns as clamp,rs as createId,os as hasGraphicsTick,as as hasOnInitialize,hs as hasOnPostUpdate,ls as hasOnPreUpdate,cs as hasPostDraw,ds as hasPreDraw,us as has_initialize,ps as has_postupdate,gs as has_preupdate,_s as isAddedComponent,fs as isAddedSystemEntity,ms as isRemoveSystemEntity,ws as isRemovedComponent,ys as maxMessages,vs as obsolete,xs as randomInRange,bs as randomIntInRange,Cs as range,As as resetObsoleteCounter,Ss as toDegrees,Ps as toRadians,Es as vec};
2
+ 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)=>{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)=>{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)=>{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)=>{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)=>{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=>{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=>{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={};(()=>{i.d(s,{fWn:()=>ks,Ia8:()=>ms,hLI:()=>Fs,yyv:()=>zr,tX5:()=>ie,vtX:()=>Us,r7K:()=>es,lCh:()=>hr,fwF:()=>Er,sce:()=>Ar,_c7:()=>Tr,KUs:()=>xr,Ajp:()=>oi,RDh:()=>Gs,_H9:()=>De,Ulf:()=>Qn,mxs:()=>Es,OmD:()=>$i,kBf:()=>B,C4F:()=>wi,NQt:()=>on,JjN:()=>an,V1s:()=>ir,Xz7:()=>St,bLd:()=>Zs,Cdc:()=>us,FKn:()=>Vi,wTW:()=>hi,SUY:()=>fn,ab2:()=>Hi,GfZ:()=>Wi,YMS:()=>Oi,oyv:()=>Yi,aUb:()=>Gi,SdD:()=>te,JUv:()=>Ri,jEj:()=>En,TFq:()=>qi,HDU:()=>$t,R_y:()=>Qt,ydN:()=>yi,_N2:()=>wr,t50:()=>Jt,s$$:()=>Sr,v2G:()=>vi,Ilk:()=>I,s9i:()=>Vr,dxL:()=>Or,LLX:()=>Wr,wA2:()=>Ai,R_p:()=>Ui,IQ$:()=>xe,I5F:()=>m,X8$:()=>br,FR6:()=>Yt,U8o:()=>Zt,kbG:()=>Pi,oeJ:()=>Ji,iS_:()=>se,cGG:()=>Gr,RPN:()=>Vs,skb:()=>Fr,SLU:()=>Ne,RdJ:()=>Qi,gU7:()=>mi,LSk:()=>Bs,Nmp:()=>ke,d1Y:()=>si,xrL:()=>Fi,sRW:()=>zi,cmV:()=>ro,N0Q:()=>Ps,q8b:()=>fs,ynB:()=>ji,jT9:()=>Js,wAz:()=>Pr,D4V:()=>xn,N6H:()=>oe,W1A:()=>ne,JHW:()=>ns,v2K:()=>ur,pBf:()=>he,GMl:()=>lt,zW2:()=>e,B0K:()=>Bn,Nv7:()=>ln,C_p:()=>ii,iqw:()=>Ve,MUA:()=>ae,xqU:()=>re,peG:()=>c,pTp:()=>Is,vUK:()=>g,j9l:()=>Ds,Zxw:()=>Ls,Hdx:()=>Me,Z$d:()=>Re,iqV:()=>_n,o$7:()=>Xr,Zm$:()=>At,$QH:()=>It,i78:()=>Rt,h6u:()=>Wt,hts:()=>Ht,j88:()=>Ut,VME:()=>Nt,nt:()=>Vn,Ukr:()=>cn,zsu:()=>_t,oA6:()=>cs,TVh:()=>Ir,TwZ:()=>hs,GTT:()=>ls,xxj:()=>Mr,XdK:()=>qt,Jmb:()=>ht,cXo:()=>Te,Dm5:()=>ee,IIB:()=>a,zI0:()=>xi,SKZ:()=>Tt,__J:()=>Pn,Dvr:()=>d,Tf9:()=>o,RI$:()=>er,x12:()=>Ni,aNw:()=>_i,xwn:()=>$s,dNK:()=>Qs,ini:()=>u,YdH:()=>f,y3G:()=>ct,l57:()=>at,xn0:()=>Cn,t2V:()=>Ms,ZyS:()=>$n,uxB:()=>Ii,cpd:()=>yr,fiy:()=>ws,$XZ:()=>xs,uqK:()=>Sn,STE:()=>An,y$z:()=>Bi,sOq:()=>Di,Sqs:()=>jn,hpZ:()=>Br,Vol:()=>Dr,wIZ:()=>Ci,cBi:()=>qr,RFv:()=>ps,kfC:()=>Lr,mgq:()=>Kn,YVA:()=>Ki,Kgp:()=>Jn,HH$:()=>Kt,M_d:()=>kt,rgh:()=>Dt,Ra6:()=>Ot,KhR:()=>Et,BS5:()=>Lt,xhz:()=>jt,xOq:()=>Mt,a9j:()=>Bt,bHk:()=>zt,CgK:()=>Pt,cuY:()=>Ft,kvE:()=>Mi,JDb:()=>so,Cbi:()=>eo,SBu:()=>Qe,AE_:()=>gr,ctO:()=>_r,OLH:()=>tr,kky:()=>M,nSF:()=>Ct,zHn:()=>Li,zwx:()=>Cr,AeJ:()=>ds,hLz:()=>ss,D9g:()=>cr,wA:()=>vs,jhr:()=>ys,GVs:()=>ri,_zO:()=>le,w6$:()=>Cs,mhV:()=>bs,MOD:()=>gs,kwd:()=>As,Lmr:()=>Ss,xsS:()=>Nr,lLr:()=>ni,Z$r:()=>v,IXb:()=>Ns,SGH:()=>Hr,SMj:()=>yn,exe:()=>Ge,bnF:()=>Zi,MFA:()=>P,$XC:()=>Yn,$uU:()=>Wn,jyi:()=>Ae,E03:()=>Ue,V6q:()=>Oe,rg2:()=>mn,nVo:()=>Ys,F6N:()=>qn,ad3:()=>Vt,xP7:()=>ar,Odq:()=>fr,Zif:()=>or,ZGJ:()=>Ti,MJk:()=>vn,xvT:()=>zs,PHM:()=>Be,dpR:()=>bt,KwO:()=>js,B7y:()=>Ws,SFp:()=>h,Uvn:()=>Ei,OFT:()=>ki,xzN:()=>nr,M5Z:()=>k,H6j:()=>Gt,ZrN:()=>l,OWs:()=>A,dF9:()=>Si,oZy:()=>Xe,rD2:()=>qe,VHo:()=>Xt,ohE:()=>ai,R$E:()=>Nn,q3I:()=>mr,Pab:()=>O,uZ5:()=>z,McK:()=>_,F9c:()=>F,k0b:()=>as,hnT:()=>Mn,RSJ:()=>zn,Mku:()=>Fn,h90:()=>Un,rms:()=>On,ErP:()=>Dn,aVg:()=>Ln,lPc:()=>kn,Z8E:()=>is,NNA:()=>lr,yFn:()=>dr,lNv:()=>rs,MZQ:()=>y,FUM:()=>C,vdf:()=>W,iaL:()=>V,w6H:()=>H,Q4c:()=>x,Xxe:()=>L,Uxb:()=>U,Yr5:()=>N,Bhw:()=>T,yOA:()=>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:()=>Tt,PostCollisionEvent:()=>Kt,PostDebugDrawEvent:()=>kt,PostDrawEvent:()=>Dt,PostFrameEvent:()=>Ot,PostKillEvent:()=>Et,PostUpdateEvent:()=>Lt,PreCollisionEvent:()=>jt,PreDebugDrawEvent:()=>Mt,PreDrawEvent:()=>Bt,PreFrameEvent:()=>zt,PreKillEvent:()=>Pt,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:()=>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:()=>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:()=>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 T(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 P,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"}(P||(P={})),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]}}(P||(P={}));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?P.Right:P.Left:t.y<0?P.Bottom:P.Top:P.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,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===P.Top?P.Bottom:t===P.Bottom?P.Top:t===P.Left?P.Right:t===P.Right?P.Left:P.None}function st(t){const e=[A.Left,A.Right,A.Up,A.Down],i=[P.Left,P.Right,P.Top,P.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],T=t.data[8],P=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*T+o*P+c*E+g*I,e.data[9]=s*T+a*P+d*E+_*I,e.data[10]=r*T+h*P+u*E+f*I,e.data[11]=n*T+l*P+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 T(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=T(this.data[0],this.data[4]).size;return this._scaleSignX*t}getScaleY(){const t=T(this.data[1],this.data[5]).size;return this._scaleSignY*t}getScale(){return T(this.getScaleX(),this.getScaleY())}setScaleX(t){this._scaleSignX=L(t);const e=T(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=T(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:T(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 Tt extends At{constructor(t){super(),this.target=t}}class Pt 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 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 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=Te.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 Te{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 Te(t.path);return t.isLoaded()?e.data=t.data:t.loaded.then((()=>{e.data=t.data})),e}unload(){this.data=new Image}}var Pe=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=Pe([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=T(a,a),this._textShadowSprites[s].draw(t,l+this._shadowOffsetX,c+this._shadowOffsetY));const e=this._spriteRecord[s];e.drawAroundAnchor=!1,e.scale=T(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 Te(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 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 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 Ye{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 T=this._getTextureIdForImage(t),P=vt(t.width||p),E=vt(t.height||g),I=e/P,R=i/E,B=(e+m-.01)/P,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++]=T,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++]=T,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++]=T,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++]=T}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(T(0,0))),l=o.multv(t.add(T(e,0))),c=o.multv(t.add(T(e,i))),d=o.multv(t.add(T(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(T(-e,-e))),h=n.multv(t.add(T(e,-e))),l=n.multv(t.add(T(e,e))),c=n.multv(t.add(T(-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(T(t,e),T(t+i,e),{...r}),this.drawLine(T(t+i,e),T(t+i,e+s),{...r}),this.drawLine(T(t+i,e+s),T(t,e+s),{...r}),this.drawLine(T(t,e+s),T(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 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(T(this.resolution.width/2,this.resolution.height/2))}worldToScreenCoordinates(t){return this._camera?this._camera.transform.multv(t):t.add(T(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 T(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 Ti extends Ai{constructor(t,e){super(),this.type=t,this.value=e}}var Pi;!function(t){t.World="world",t.Screen="screen"}(Pi||(Pi={}));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=Pi.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?T(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 Zi{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([Zi.Circle(t/2,T(0,-e/2+t/2).add(i)),Zi.Box(t,e-t,A.Half,i),Zi.Circle(t/2,T(0,e/2-t/2).add(i))])}return new Ui([Zi.Circle(e/2,T(-t/2+e/2,0).add(i)),Zi.Box(t-e,e,A.Half,i),Zi.Circle(e/2,T(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 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=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=T(o.x-i/2,o.y-s/2),this._topLeft=this._topLeft.rotate(r,n),this._topRight=T(o.x+i/2,o.y-s/2),this._topRight=this._topRight.rotate(r,n),this._bottomLeft=T(o.x-i/2,o.y+s/2),this._bottomLeft=this._bottomLeft.rotate(r,n),this._bottomRight=T(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 Ti("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 Ti(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 Ti)).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(T(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=T(this._end.x,this._end.y),this._motion.vel=T(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=T(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=T(e.x,e.y),this.isComplete(this.entity)&&(this._tx.pos=T(this._end.x,this._end.y),this._motion.vel=T(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=T(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=T(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 Ts{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 Ps{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=T((e-this._tx.pos.x)/(t/1e3),(i-this._tx.pos.y)/(t/1e3))):(this._tx.pos=T(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=T(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=T(this._tx.pos.x,this._tx.pos.y),this._end=T(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=T(t.x,t.y)}else this._motion.vel=T(0,0);this.isComplete()&&(this._tx.pos=T(this._end.x,this._end.y),this._motion.vel=T(0,0))}stop(){this._motion.vel=T(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=T(this._tx.pos.x,this._tx.pos.y),this._end=T(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=T(i.x,i.y),this.isComplete()&&(this._tx.pos=T(this._end.x,this._end.y),this._motion.vel=T(0,0))}isComplete(){return this._stopped||this._distanceBetween<=1}stop(){this._motion.vel=T(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 Ps(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 Ts(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 Ts((()=>{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:T(null!=i?i:0,null!=s?s:0),this.rotation=null!=_?_:0,this.scale=null!=o?o:T(1,1),this.z=null!=v?v:0,S.coordPlane=null!=n?n:Pi.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 Pt(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 Tt(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=T(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,T(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=Pi.Screen,this.anchor=T(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 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 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=T(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=T(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,T(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=T(i.left,i.top),r=T(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=T(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=T(0,i*this.cellHeight);t.drawLine(s.add(r),s.add(T(e,r.y)),I.Red,2)}for(let e=0;e<this.cols+1;e++){const r=T(e*this.cellWidth,0);t.drawLine(s.add(r),s.add(T(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 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"}(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),T(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=T(t,this.pos.y))}get y(){return this.pos.y}set y(t){this._follow||this._cameraMoving||(this.pos=T(this.pos.x,t))}get dx(){return this.vel.x}set dx(t){this.vel=T(t,this.vel.y)}get dy(){return this.vel.y}set dy(t){this.vel=T(this.vel.x,t)}get ax(){return this.acc.x}set ax(t){this.acc=T(t,this.acc.y)}get ay(){return this.acc.y}set ay(t){this.acc=T(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=T(e.width/2,e.height/2);if(!this._engine.loadingComplete){const t=this._screen.peekResolution();t&&(i=T(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=T(-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=T(-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=P.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,P.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=P.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,P.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=P.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,P.getOpposite(t),e.mtv.negate())),e.colliderB.events.emit("beforecollisionresolve",new Qt(e.colliderB,e.colliderA,P.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=P.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,P.getOpposite(s),e.mtv.negate())),e.colliderB.events.emit("aftercollisionresolve",new $t(e.colliderB,e.colliderA,P.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,Tr,Pr;!function(t){t.Forward="forward",t.Backward="backward"}(Ar||(Ar={})),function(t){t.End="end",t.Loop="loop",t.PingPong="pingpong",t.Freeze="freeze"}(Tr||(Tr={}));class Er extends _t{constructor(t){var e,i;super(t),this.events=new he,this.frames=[],this.strategy=Tr.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=Tr.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===Tr.Loop,freezeFrame:e.strategy===Tr.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 Tr.End:case Tr.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 Tr.Loop:e=(t+1)%this.frames.length,0===e&&this.events.emit("loop",this);break;case Tr.End:e=t+1,e>=this.frames.length&&(this._done=!0,this._currentFrame=this.frames.length,this.events.emit("end",this));break;case Tr.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 Tr.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"}(Pr||(Pr={}));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=T(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(T(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=T(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=Pr.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:P,radius:E,particleRotationalVelocity:R,randomRotation:B,random:D}={...t};this.pos=null!=n?n:T(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!=P?P: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===Pr.Rectangle)t=W(0,this.width,this.random),e=W(0,this.height,this.random);else if(this.emitterType===Pr.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 Ti("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===Pi.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=T(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===Pi.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Pi.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===Pi.World&&(this._ctx.save(),this._camera&&this._camera.draw(this._ctx))}_popCameraTransform(t){t.coordPlane===Pi.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=T(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(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=T(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=T(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===Pi.World&&(this._graphicsContext.save(),this._camera&&this._camera.draw(this._graphicsContext))}_popCameraTransform(t){t.coordPlane===Pi.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===Pi.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===Pi.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,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.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(T(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 Tn=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 Pn 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?T(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:T(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)}}Tn([C({message:"Label.bold will be removed in v0.26.0",alternateMethod:"Use Label.font.bold"})],Pn.prototype,"bold",null),Tn([C({message:"Label.fontFamily will be removed in v0.26.0",alternateMethod:"Use Label.font.family"})],Pn.prototype,"fontFamily",null),Tn([C({message:"Label.fontSize will be removed in v0.26.0",alternateMethod:"Use Label.font.size"})],Pn.prototype,"fontSize",null),Tn([C({message:"Label.fontStyle will be removed in v0.26.0",alternateMethod:"Use Label.font.style"})],Pn.prototype,"fontStyle",null),Tn([C({message:"Label.fontUnit will be removed in v0.26.0",alternateMethod:"Use Label.font.unit"})],Pn.prototype,"fontUnit",null),Tn([C({message:"Label.textAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.textAlign"})],Pn.prototype,"textAlign",null),Tn([C({message:"Label.baseAlign will be removed in v0.26.0",alternateMethod:"Use Label.font.baseAlign"})],Pn.prototype,"baseAlign",null),Tn([C({message:"Label.setTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Pn.prototype,"setTextShadow",null),Tn([C({message:"Label.useTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Pn.prototype,"useTextShadow",null),Tn([C({message:"Label.clearTextShadow will be removed in v0.26.0",alternateMethod:"Use Label.font.shadow"})],Pn.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 T=c.globalAlpha;c.globalAlpha=v,c.stroke(),c.globalAlpha=T,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 Te(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 T(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.2";p()})();var r=s.fWn,n=s.Ia8,o=s.hLI,a=s.yyv,h=s.tX5,l=s.vtX,c=s.r7K,d=s.lCh,u=s.fwF,p=s.sce,g=s._c7,_=s.KUs,f=s.Ajp,m=s.RDh,v=s._H9,y=s.Ulf,w=s.mxs,x=s.OmD,b=s.kBf,C=s.C4F,S=s.NQt,A=s.JjN,T=s.V1s,P=s.Xz7,E=s.bLd,I=s.Cdc,R=s.FKn,B=s.wTW,D=s.SUY,M=s.ab2,k=s.GfZ,F=s.YMS,L=s.oyv,z=s.aUb,O=s.SdD,U=s.JUv,N=s.jEj,H=s.TFq,W=s.HDU,V=s.R_y,G=s.ydN,X=s._N2,q=s.t50,j=s.s$$,K=s.v2G,Z=s.Ilk,Y=s.s9i,Q=s.dxL,$=s.LLX,J=s.wA2,tt=s.R_p,et=s.IQ$,it=s.I5F,st=s.X8$,rt=s.FR6,nt=s.U8o,ot=s.kbG,at=s.oeJ,ht=s.iS_,lt=s.cGG,ct=s.RPN,dt=s.skb,ut=s.SLU,pt=s.RdJ,gt=s.gU7,_t=s.LSk,ft=s.Nmp,mt=s.d1Y,vt=s.xrL,yt=s.sRW,wt=s.cmV,xt=s.N0Q,bt=s.q8b,Ct=s.ynB,St=s.jT9,At=s.wAz,Tt=s.D4V,Pt=s.N6H,Et=s.W1A,It=s.JHW,Rt=s.v2K,Bt=s.pBf,Dt=s.GMl,Mt=s.zW2,kt=s.B0K,Ft=s.Nv7,Lt=s.C_p,zt=s.iqw,Ot=s.MUA,Ut=s.xqU,Nt=s.peG,Ht=s.pTp,Wt=s.vUK,Vt=s.j9l,Gt=s.Zxw,Xt=s.Hdx,qt=s.Z$d,jt=s.iqV,Kt=s.o$7,Zt=s.Zm$,Yt=s.$QH,Qt=s.i78,$t=s.h6u,Jt=s.hts,te=s.j88,ee=s.VME,ie=s.nt,se=s.Ukr,re=s.zsu,ne=s.oA6,oe=s.TVh,ae=s.TwZ,he=s.GTT,le=s.xxj,ce=s.XdK,de=s.Jmb,ue=s.cXo,pe=s.Dm5,ge=s.IIB,_e=s.zI0,fe=s.SKZ,me=s.__J,ve=s.Dvr,ye=s.Tf9,we=s.RI$,xe=s.x12,be=s.aNw,Ce=s.xwn,Se=s.dNK,Ae=s.ini,Te=s.YdH,Pe=s.y3G,Ee=s.l57,Ie=s.xn0,Re=s.t2V,Be=s.ZyS,De=s.uxB,Me=s.cpd,ke=s.fiy,Fe=s.$XZ,Le=s.uqK,ze=s.STE,Oe=s.y$z,Ue=s.sOq,Ne=s.Sqs,He=s.hpZ,We=s.Vol,Ve=s.wIZ,Ge=s.cBi,Xe=s.RFv,qe=s.kfC,je=s.mgq,Ke=s.YVA,Ze=s.Kgp,Ye=s.HH$,Qe=s.M_d,$e=s.rgh,Je=s.Ra6,ti=s.KhR,ei=s.BS5,ii=s.xhz,si=s.xOq,ri=s.a9j,ni=s.bHk,oi=s.CgK,ai=s.cuY,hi=s.kvE,li=s.JDb,ci=s.Cbi,di=s.SBu,ui=s.AE_,pi=s.ctO,gi=s.OLH,_i=s.kky,fi=s.nSF,mi=s.zHn,vi=s.zwx,yi=s.AeJ,wi=s.hLz,xi=s.D9g,bi=s.wA,Ci=s.jhr,Si=s.GVs,Ai=s._zO,Ti=s.w6$,Pi=s.mhV,Ei=s.MOD,Ii=s.kwd,Ri=s.Lmr,Bi=s.xsS,Di=s.lLr,Mi=s.Z$r,ki=s.IXb,Fi=s.SGH,Li=s.SMj,zi=s.exe,Oi=s.bnF,Ui=s.MFA,Ni=s.$XC,Hi=s.$uU,Wi=s.jyi,Vi=s.E03,Gi=s.V6q,Xi=s.rg2,qi=s.nVo,ji=s.F6N,Ki=s.ad3,Zi=s.xP7,Yi=s.Odq,Qi=s.Zif,$i=s.ZGJ,Ji=s.MJk,ts=s.xvT,es=s.PHM,is=s.dpR,ss=s.KwO,rs=s.B7y,ns=s.SFp,os=s.Uvn,as=s.OFT,hs=s.xzN,ls=s.M5Z,cs=s.H6j,ds=s.ZrN,us=s.OWs,ps=s.dF9,gs=s.oZy,_s=s.rD2,fs=s.VHo,ms=s.ohE,vs=s.R$E,ys=s.q3I,ws=s.Pab,xs=s.uZ5,bs=s.McK,Cs=s.F9c,Ss=s.k0b,As=s.hnT,Ts=s.RSJ,Ps=s.Mku,Es=s.h90,Is=s.rms,Rs=s.ErP,Bs=s.aVg,Ds=s.lPc,Ms=s.Z8E,ks=s.NNA,Fs=s.yFn,Ls=s.lNv,zs=s.MZQ,Os=s.FUM,Us=s.vdf,Ns=s.iaL,Hs=s.w6H,Ws=s.Q4c,Vs=s.Xxe,Gs=s.Uxb,Xs=s.Yr5,qs=s.Bhw,js=s.yOA;export{r as ActionContext,n as ActionQueue,o as ActionsComponent,a as ActionsSystem,h as ActivateEvent,l as Actor,c as AddedComponent,d as AddedEntity,u as Animation,p as AnimationDirection,g as AnimationStrategy,_ as ArcadeSolver,f as AudioContextFactory,m as Axis,v as BaseAlign,y as BinaryTreeNode,w as Blink,x as BodyComponent,b as BoundingBox,C as BroadphaseStrategy,S as BrowserComponent,A as BrowserEvents,T as Camera,P as Canvas,E as Cell,I as Circle,R as CircleCollider,B as Class,D as Clock,M as ClosestLine,k as ClosestLineJumpTable,F as Collider,L as ColliderComponent,z as CollisionContact,O as CollisionEndEvent,U as CollisionGroup,N as CollisionGroupManager,H as CollisionJumpTable,W as CollisionPostSolveEvent,V as CollisionPreSolveEvent,G as CollisionResolutionStrategy,X as CollisionSolver,q as CollisionStartEvent,j as CollisionSystem,K as CollisionType,Z as Color,Y as ColorBlindFlags,Q as ColorBlindnessMode,$ as ColorBlindnessPostProcessor,J as Component,tt as CompositeCollider,et as Configurable,it as ConsoleAppender,st as ContactConstraintPoint,rt as ContactEndEvent,nt as ContactStartEvent,ot as CoordPlane,at as CullingBox,ht as DeactivateEvent,lt as Debug,ct as DebugGraphicsComponent,dt as DebugSystem,ut as DebugText,pt as DegreeOfFreedom,gt as Detector,_t as Die,ft as Direction,mt as DisplayMode,vt as DynamicTree,yt as DynamicTreeCollisionProcessor,wt as EX_VERSION,xt as EaseTo,bt as EasingFunctions,Ct as EdgeCollider,St as ElasticToActorStrategy,At as EmitterType,Tt as Engine,Pt as EnterTriggerEvent,Et as EnterViewPortEvent,It as Entity,Rt as EntityManager,Bt as EventDispatcher,Dt as EventTypes,Mt as Events,kt as ExResponse,Ft as ExcaliburGraphicsContext2DCanvas,Lt as ExcaliburGraphicsContextWebGL,zt as ExcaliburWebGLContextAccessor,Ot as ExitTriggerEvent,Ut as ExitViewPortEvent,Nt as Experiments,Ht as Fade,Wt as Flags,Vt as Follow,Gt as Font,Xt as FontStyle,qt as FontUnit,jt as FpsSampler,Kt as FrameStats,Zt as GameEvent,Yt as GameStartEvent,Qt as GameStopEvent,$t as GamepadAxisEvent,Jt as GamepadButtonEvent,te as GamepadConnectEvent,ee as GamepadDisconnectEvent,ie as Gif,se as GlobalCoordinates,re as Graphic,ne as GraphicsComponent,oe as GraphicsGroup,ae as GraphicsLayer,he as GraphicsLayers,le as GraphicsSystem,ce as HiddenEvent,de as ImageFiltering,ue as ImageSource,pe as InitializeEvent,ge as Input,_e as Integrator,fe as KillEvent,me as Label,ve as Legacy,ye as LegacyDrawing,we as LimitCameraBoundsStrategy,xe as Line,be as Loader,Ce as LockCameraToActorAxisStrategy,Se as LockCameraToActorStrategy,Ae as LogLevel,Te as Logger,Pe as Matrix,Ee as MatrixLocations,Ie as MediaEvent,Re as Meet,Be as MockedElement,De as MotionComponent,Me as MotionSystem,ke as MoveBy,Fe as MoveTo,Le as NativeSoundEvent,ze as NativeSoundProcessedEvent,Oe as Observable,Ue as Pair,Ne as ParseGif,He as Particle,We as ParticleEmitter,Ve as Physics,Ge as PhysicsStats,Xe as PointerComponent,qe as PointerSystem,je as Polygon,Ke as PolygonCollider,Ze as Pool,Ye as PostCollisionEvent,Qe as PostDebugDrawEvent,$e as PostDrawEvent,Je as PostFrameEvent,ti as PostKillEvent,ei as PostUpdateEvent,ii as PreCollisionEvent,si as PreDebugDrawEvent,ri as PreDrawEvent,ni as PreFrameEvent,oi as PreKillEvent,ai as PreUpdateEvent,hi as Projection,li as Promise,ci as PromiseState,di as QuadIndexBuffer,ui as Query,pi as QueryManager,gi as RadiusAroundActorStrategy,_i as Random,fi as Raster,mi as Ray,vi as RealisticSolver,yi as Rectangle,wi as RemovedComponent,xi as RemovedEntity,bi as Repeat,Ci as RepeatForever,Si as Resolution,Ai as Resource,Ti as RotateBy,Pi as RotateTo,Ei as RotationType,Ii as ScaleBy,Ri as ScaleTo,Bi as Scene,Di as Screen,Mi as ScreenAppender,ki as ScreenElement,Fi as ScreenShader,Li as ScrollPreventionMode,zi as Shader,Oi as Shape,Ui as Side,Ni as SortedList,Hi as Sound,Wi as Sprite,Vi as SpriteFont,Gi as SpriteSheet,Xi as StandardClock,qi as StrategyContainer,ji as Stream,Ki as SubscribeEvent,Zi as System,Yi as SystemManager,Qi as SystemType,$i as TagComponent,Ji as TestClock,ts as Text,es as TextAlign,is as TextureLoader,ss as TileMap,rs as Timer,ns as Traits,os as TransformComponent,as as TreeNode,hs as Trigger,ls as TwoPI,cs as UnsubscribeEvent,ds as Util,us as Vector,ps as VectorView,gs as VertexBuffer,_s as VertexLayout,fs as VisibleEvent,ms as WebAudio,vs as WebAudioInstance,ys as World,ws as canonicalizeAngle,xs as clamp,bs as createId,Cs as frac,Ss as hasGraphicsTick,As as hasOnInitialize,Ts as hasOnPostUpdate,Ps as hasOnPreUpdate,Es as hasPostDraw,Is as hasPreDraw,Rs as has_initialize,Bs as has_postupdate,Ds as has_preupdate,Ms as isAddedComponent,ks as isAddedSystemEntity,Fs as isRemoveSystemEntity,Ls as isRemovedComponent,zs as maxMessages,Os as obsolete,Us as randomInRange,Ns as randomIntInRange,Hs as range,Ws as resetObsoleteCounter,Vs as sign,Gs as toDegrees,Xs as toRadians,qs as vec,js as webgl};
3
3
  //# sourceMappingURL=excalibur.min.js.map