angry-pixel 2.4.1 → 2.4.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.
package/lib/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t;exports.BroadPhaseMethods=void 0,(t=exports.BroadPhaseMethods||(exports.BroadPhaseMethods={}))[t.QuadTree=0]="QuadTree",t[t.SpatialGrid=1]="SpatialGrid";class e{constructor(t=0,e=0){this._x=t,this._y=e}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}get magnitude(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))}get direction(){return this._direction||(this._direction=new e),e.unit(this._direction,this)}set(t,e){this._x=t,this._y=e}copy(t){this.set(t.x,t.y)}equals(t){return this._x===t.x&&this._y===t.y}clone(){return new e(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){const i=e.x*e.x+e.y*e.y;if(0===i)t.set(0,0);else{const s=1/Math.sqrt(i);t.set(e.x*s,e.y*s)}return t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}static floor(t,e){return t.set(Math.floor(e.x),Math.floor(e.y)),t}static ceil(t,e){return t.set(Math.ceil(e.x),Math.ceil(e.y)),t}toString(){return`(${this._x}, ${this._y})`}}class i{constructor(t=0,i=0,s=0,o=0){this.width=0,this.height=0,this._position=new e,this._center=new e,this.set(t,i,s,o)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this.width}get y1(){return this._position.y+this.height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,s){this._position.set(t,e),this.width=i,this.height=s}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}intersects(t){return!(this.x1<t.x||this.x>t.x1||this.y1<t.y||this.y>t.y1)}contains(t){return t instanceof i?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof e&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}toString(){return`(${this.position.x}, ${this.position.y}, ${this.width}, ${this.height})`}}const s=(t,e,i)=>Math.min(i,Math.max(e,t)),o=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),r=(t,e,i=1)=>{const s=[];for(let o=t;o<=e;o+=i)s.push(o);return s},n=(t,e,i)=>t>=e&&t<=i,a=t=>t*(Math.PI/180);class h{constructor(){this.instances=new Map,this.types=new Map}add(t,e){if(!e&&!t.prototype.__ioc_injectable)throw new Error(`Type ${t.name} is not injectable`);return this.types.set(null!=e?e:t.prototype.__ioc_injectable,t),this}set(t,e){return this.instances.set(t,e),this}get(t){var e,i;if(!this.instances.has(t)){const s=this.types.get(t);if(!s)throw new Error(`${t.toString()} is not a valid type`);const o=new s(...(null!==(e=s.prototype.__ioc_inject_constructor)&&void 0!==e?e:[]).map((t=>this.get(t))));(null!==(i=s.prototype.__ioc_inject_prop)&&void 0!==i?i:[]).forEach((([t,e])=>o[t]=this.get(e))),this.instances.set(t,o)}return this.instances.get(t)}has(t){return this.types.has(t)||this.instances.has(t)}}function l(t){return function(e){e.prototype.__ioc_injectable&&e.prototype.__ioc_injectable===t||(e.prototype.__ioc_injectable=t)}}function c(t){return function(e,i,s){void 0!==s?(e.prototype.__ioc_inject_constructor||(e.prototype.__ioc_inject_constructor=[]),e.prototype.__ioc_inject_constructor[s]=t):void 0!==i&&(e.constructor.prototype.__ioc_inject_prop||(e.constructor.prototype.__ioc_inject_prop=[]),e.constructor.prototype.__ioc_inject_prop.push([i,t]))}}const d={CollisionRepository:Symbol.for("CollisionRepository"),CollisionBroadphaseResolver:Symbol.for("CollisionBroadphaseResolver"),CollisionResolutionMethod:Symbol.for("CollisionResolutionMethod"),CollisionAABBResolver:Symbol.for("CollisionAABBResolver"),CollisionCircumferenceAABBResolver:Symbol.for("CollisionCircumferenceAABBResolver"),CollisionCircumferenceResolver:Symbol.for("CollisionCircumferenceResolver"),CollisionSatResolver:Symbol.for("CollisionSatResolver"),CollisionMatrix:Symbol.for("CollisionMatrix"),CollisionResolutionPool:Symbol.for("CollisionResolutionPool")};var g,p=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let u=g=class{constructor(t=new i,e=0,s=[]){this.bounds=t,this.level=e,this.objects=[],this.nodes=[],this.rects=s}update(t){if(this.clear(),this.rects.length=0,0===t.length)return;let e=1/0,i=1/0,s=-1/0,o=-1/0;for(const{id:r,boundingBox:n}of t)this.rects[r]=n,e=Math.min(e,n.x),i=Math.min(i,n.y),s=Math.max(s,n.x1),o=Math.max(o,n.y1);this.bounds.set(e,i,s-e,o-i);for(const{id:e}of t)this.insert(e)}retrieve(t){const e=[];return this.query(t,e),e}clear(){this.objects=[];for(const t of this.nodes)t.clear();this.nodes=[]}split(){const t=this.bounds.width/2,e=this.bounds.height/2,s=this.bounds.x,o=this.bounds.y;this.nodes=[new g(new i(s+t,o+e,t,e),this.level+1,this.rects),new g(new i(s,o+e,t,e),this.level+1,this.rects),new g(new i(s,o,t,e),this.level+1,this.rects),new g(new i(s+t,o,t,e),this.level+1,this.rects)]}getIndex(t){const e=this.bounds.x+this.bounds.width/2,i=this.bounds.y+this.bounds.height/2,s=t.y1<i,o=t.y>i,r=t.x1<e,n=t.x>e;return o&&n?0:o&&r?1:s&&r?2:s&&n?3:-1}insert(t){if(this.nodes.length>0){const e=this.getIndex(this.rects[t]);if(-1!==e)return void this.nodes[e].insert(t)}if(this.objects.push(t),this.objects.length>10&&this.level<5){0===this.nodes.length&&this.split();let t=0;for(;t<this.objects.length;){const e=this.getIndex(this.rects[this.objects[t]]);-1!==e?this.nodes[e].insert(this.objects.splice(t,1)[0]):t++}}}query(t,e){for(const i of this.objects)this.rects[i].intersects(t)&&e.push(i);if(0===this.nodes.length)return;const i=this.bounds.x+this.bounds.width/2,s=this.bounds.y+this.bounds.height/2,o=t.y<s,r=t.y1>s,n=t.x<i,a=t.x1>i;r&&a&&this.nodes[0].query(t,e),r&&n&&this.nodes[1].query(t,e),o&&n&&this.nodes[2].query(t,e),o&&a&&this.nodes[3].query(t,e)}};u=g=p([l(d.CollisionBroadphaseResolver)],u);var m=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};const f=(t,e,i,s)=>{const o=(t-e)/i|0;return o<0?0:o>=s?s-1:o};let y=class{constructor(){this.area=new i,this.cells=[[]],this.usedCells=[],this.boxes=[],this.columns=1,this.rows=1,this.cellWidth=0,this.cellHeight=0,this.seenGen=[],this.retrieveSerial=0,this.retrieveResult=[],this.coordinates={x0:0,x1:0,y0:0,y1:0}}update(t){if(this.clearCells(),this.boxes.length=0,0!==t.length){this.resize(t),this.ensureSeenCapacity(t.length);for(let e=0;e<t.length;e++)this.insert(t[e].id,t[e].boundingBox)}}ensureSeenCapacity(t){if(this.seenGen.length<t){const e=this.seenGen.length;this.seenGen.length=t,this.seenGen.fill(0,e,t)}}clearCells(){for(let t=0;t<this.usedCells.length;t++)this.cells[this.usedCells[t]].length=0;this.usedCells.length=0}resize(t){let e=1/0,i=1/0,s=-1/0,o=-1/0,r=0;for(let n=0;n<t.length;n++){const a=t[n].boundingBox;e=Math.min(e,a.x),i=Math.min(i,a.y),s=Math.max(s,a.x1),o=Math.max(o,a.y1),r+=Math.max(a.width,a.height)}const n=s-e,a=o-i,h=t.length;this.area.set(e,i,n,a);const l=Math.max(Math.sqrt(n*a/h),Math.max(n,a)/h,r/h)||1;this.columns=Math.ceil(n/l)||1,this.rows=Math.ceil(a/l)||1,this.cellWidth=n/this.columns,this.cellHeight=a/this.rows;for(let t=this.cells.length,e=this.columns*this.rows;t<e;t++)this.cells.push([])}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++){const s=e*this.rows+i;0===this.cells[s].length&&this.usedCells.push(s),this.cells[s].push(t)}this.boxes[t]=e}retrieve(t){this.retrieveResult.length=0,2147483647==++this.retrieveSerial&&(this.retrieveSerial=1,this.seenGen.fill(0)),this.updateCoordinates(t);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++){const s=this.cells[e*this.rows+i];for(let e=0,i=s.length;e<i;e++){const i=s[e];this.seenGen[i]!==this.retrieveSerial&&(this.seenGen[i]=this.retrieveSerial,this.boxes[i].intersects(t)&&this.retrieveResult.push(i))}}return this.retrieveResult}updateCoordinates(t){this.coordinates.x0=f(t.x,this.area.x,this.cellWidth,this.columns),this.coordinates.x1=f(t.x1,this.area.x,this.cellWidth,this.columns),this.coordinates.y0=f(t.y,this.area.y,this.cellHeight,this.rows),this.coordinates.y1=f(t.y1,this.area.y,this.cellHeight,this.rows)}};y=m([l(d.CollisionBroadphaseResolver)],y);const x=(t,i)=>Math.abs(e.cross(t,i))<1e-6;class M{get vertexModel(){return this._vertexModel}set vertexModel(t){if(this._vertexModel=t,2===t.length)return this.vertices=[new e,new e],this.edgeNormals=[],void(this.projectionAxes=[new e]);this.vertices=[],this.edgeNormals=[],this.projectionAxes=[],this._vertexModel.forEach((()=>{this.vertices.push(new e),this.edgeNormals.push(new e)}))}constructor(t,s=0){this.rotation=s,this.boundingBox=new i,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new e,this.projectionAxes=[],this.edgeNormals=[],this.radius=0,this.vertices=[],this.updateCollisions=!0,this._vertexModel=[],this.vertexModel=t}}class v{constructor(t){this.radius=t,this.boundingBox=new i,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new e,this.projectionAxes=[new e],this.rotation=0,this.vertexModel=[],this.vertices=[new e,new e],this.updateCollisions=!0}}var C=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},b=function(t,e){return function(i,s){e(i,s,t)}};let S=class{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}findCollision(t,e){return t instanceof M&&e instanceof M?this.AABBResolver.resolve(t,e):t instanceof v&&e instanceof M?this.circumferenceAABBResolver.resolve(t,e):t instanceof M&&e instanceof v?this.circumferenceAABBResolver.resolve(e,t,!0):t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):void 0}};var w;S=C([l(d.CollisionResolutionMethod),b(0,c(d.CollisionAABBResolver)),b(1,c(d.CollisionCircumferenceAABBResolver)),b(2,c(d.CollisionCircumferenceResolver))],S),exports.CollisionMethods=void 0,(w=exports.CollisionMethods||(exports.CollisionMethods={}))[w.AABB=0]="AABB",w[w.SAT=1]="SAT";var A=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},R=function(t,e){return function(i,s){e(i,s,t)}};let _=class{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}findCollision(t,e){return t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}};_=A([l(d.CollisionResolutionMethod),R(0,c(d.CollisionCircumferenceResolver)),R(1,c(d.CollisionSatResolver))],_);var E=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let T=class{constructor(){this.direction=new e,this.resolutionDirection=new e}resolve({boundingBox:t},{boundingBox:i}){if(this.overlapX=Math.min(t.x1,i.x1)-Math.max(t.x,i.x),this.overlapY=Math.min(t.y1,i.y1)-Math.max(t.y,i.y),this.overlapX<0||this.overlapY<0)return;this.checkOverlapForLines(t,i),this.direction.set(Math.sign(i.center.x-t.center.x),Math.sign(i.center.y-t.center.y)),this.preventContainment(t,i),this.overlapY<=this.overlapX?(this.minOverlap=this.overlapY,this.resolutionDirection.set(0,this.direction.y||1)):(this.minOverlap=this.overlapX,this.resolutionDirection.set(this.direction.x||1,0));const s=this.collisionResolutionPool.get();return e.unit(s.direction,this.resolutionDirection),s.penetration=this.minOverlap,s}checkOverlapForLines(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))}preventContainment(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){const i=Math.abs(t.y-e.y),s=Math.abs(t.y1-e.y1);this.overlapY+=i<s?i:s}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),s=Math.abs(t.x1-e.x1);this.overlapX+=i<s?i:s}}};E([c(d.CollisionResolutionPool)],T.prototype,"collisionResolutionPool",void 0),T=E([l(d.CollisionAABBResolver)],T);var P=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let B=class{constructor(){this.closestPoint=new e,this.distance=new e,this.direction=new e}resolve(t,i,o=!1){this.closestPoint.set(s(t.position.x,i.boundingBox.x,i.boundingBox.x1),s(t.position.y,i.boundingBox.y,i.boundingBox.y1)),e.subtract(this.distance,this.closestPoint,t.position);const r=this.distance.x*this.distance.x+this.distance.y*this.distance.y;if(r>t.radius*t.radius)return;const n=Math.sqrt(r);let a;n>0?(e.unit(this.direction,this.distance),a=t.radius-n):a=t.radius+this.setDirectionToNearestFace(t.position,i.boundingBox),o&&e.scale(this.direction,this.direction,-1);const h=this.collisionResolutionPool.get();return h.direction.copy(this.direction),h.penetration=a,h}setDirectionToNearestFace({x:t,y:e},i){const s=t-i.x,o=i.x1-t,r=e-i.y,n=i.y1-e,a=Math.min(s,o,r,n);return a===s?this.direction.set(1,0):a===o?this.direction.set(-1,0):a===r?this.direction.set(0,1):this.direction.set(0,-1),a}};P([c(d.CollisionResolutionPool)],B.prototype,"collisionResolutionPool",void 0),B=P([l(d.CollisionCircumferenceAABBResolver)],B);var D=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let F=class{constructor(){this.distance=new e}resolve(t,i){e.subtract(this.distance,i.position,t.position);const s=t.radius+i.radius,o=this.distance.x*this.distance.x+this.distance.y*this.distance.y;if(o>s*s)return;const r=Math.sqrt(o),n=this.collisionResolutionPool.get();return n.penetration=s-r,r>0?e.unit(n.direction,this.distance):n.direction.set(1,0),n}};D([c(d.CollisionResolutionPool)],F.prototype,"collisionResolutionPool",void 0),F=D([l(d.CollisionCircumferenceResolver)],F);var j=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let U=class{constructor(){this.mergedAxes=[],this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new e,this.distance=new e(1/0,1/0),this.cache=new e}resolve(t,i){this.minOverlap=1/0;const s=t instanceof v,o=!s&&i instanceof v;if(s?this.setCircumferenceAxis(t,i):o&&this.setCircumferenceAxis(i,t),this.mergeProjectionAxes(t,i),0===this.mergedAxes.length)return;for(let r=0;r<this.mergedAxes.length;r++){const n=this.mergedAxes[r];if(s?this.projectCircumferenceOntoAxis(this.projA,t,n):this.projectShapeOntoAxis(this.projA,t,n),o?this.projectCircumferenceOntoAxis(this.projB,i,n):this.projectShapeOntoAxis(this.projB,i,n),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return;(this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min)&&(this.currentOverlap+=Math.min(Math.abs(this.projA.min-this.projB.min),Math.abs(this.projA.max-this.projB.max))),this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.projA.min+this.projA.max<this.projB.min+this.projB.max?this.smallestAxis.copy(n):e.scale(this.smallestAxis,n,-1))}const r=this.collisionResolutionPool.get();return r.direction.copy(this.smallestAxis),r.penetration=this.minOverlap,r}mergeProjectionAxes(t,e){const i=t.projectionAxes,s=e.projectionAxes;this.mergedAxes.length=0;for(let t=0;t<i.length;t++)0===i[t].x&&0===i[t].y||this.mergedAxes.push(i[t]);for(let t=0;t<s.length;t++){const e=s[t];if(0===e.x&&0===e.y)continue;let i=!1;for(let t=0;t<this.mergedAxes.length;t++)if(x(this.mergedAxes[t],e)){i=!0;break}i||this.mergedAxes.push(e)}}projectShapeOntoAxis(t,i,s){t.min=1/0,t.max=-1/0;const o=i.vertices;for(let i=0;i<o.length;i++){const r=e.dot(s,o[i]);r<t.min&&(t.min=r),r>t.max&&(t.max=r)}return t}setCircumferenceAxis(t,i){this.distance.set(1/0,1/0);let s=1/0;const o=i.vertices;for(let i=0;i<o.length;i++){e.subtract(this.cache,o[i],t.position);const r=this.cache.x*this.cache.x+this.cache.y*this.cache.y;r<s&&(s=r,this.distance.copy(this.cache))}e.unit(t.projectionAxes[0],this.distance)}projectCircumferenceOntoAxis(t,{position:i,radius:s},o){const r=e.dot(o,i);t.min=r-s,t.max=r+s}};j([c(d.CollisionResolutionPool)],U.prototype,"collisionResolutionPool",void 0),U=j([l(d.CollisionSatResolver)],U);var I=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let L=class{constructor(){this.pool=[],this.index=0}get(){return this.index>=this.pool.length&&this.pool.push({direction:new e,penetration:0}),this.pool[this.index++]}clear(){this.index=0}};L=I([l(d.CollisionResolutionPool)],L);var O=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};exports.CollisionRepository=class{constructor(){this.collisionPool=[],this.collisionPoolIndex=0,this.collisions=[],this.step=0,this.findCache=new WeakMap}updateCache(t){this.findCache.has(t)||this.findCache.set(t,{step:0,collisions:[]});const i=this.findCache.get(t);i.step!==this.step&&(i.step=this.step,i.collisions=this.collisions.filter((e=>e.localCollider===t||e.remoteCollider===t)).map((i=>((t,i)=>t.localCollider===i?Object.assign(Object.assign({},t),{resolution:{direction:t.resolution.direction.clone(),penetration:t.resolution.penetration}}):{localCollider:t.remoteCollider,localEntity:t.remoteEntity,remoteCollider:t.localCollider,remoteEntity:t.localEntity,resolution:{direction:e.scale(new e,t.resolution.direction,-1),penetration:t.resolution.penetration}})(i,t))))}findCollisionsForCollider(t){return this.updateCache(t),this.findCache.get(t).collisions}findCollisionsForColliderAndLayer(t,e){return this.updateCache(t),this.findCache.get(t).collisions.filter((t=>t.remoteCollider.layer===e))}getCollisions(){return this.collisions}persist(t,e,i,s,{direction:o,penetration:r}){if(this.collisionPoolIndex<this.collisionPool.length){const n=this.collisionPool[this.collisionPoolIndex++];n.localCollider=e,n.localEntity=t,n.remoteCollider=s,n.remoteEntity=i,n.resolution.direction.copy(o),n.resolution.penetration=r,this.collisions.push(n)}else{const n={localCollider:e,localEntity:t,remoteCollider:s,remoteEntity:i,resolution:{direction:o.clone(),penetration:r}};this.collisionPool.push(n),this.collisionPoolIndex++,this.collisions.push(n)}}clear(){this.collisions.length=0,this.collisionPoolIndex=0,this.step++}},exports.CollisionRepository=O([l(d.CollisionRepository)],exports.CollisionRepository);const k=t=>{if(null===t||"object"!=typeof t)return t;if("undefined"!=typeof Node&&t instanceof Node)return t;if("undefined"!=typeof FontFace&&t instanceof FontFace)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array)return t.map((t=>k(t)));if(t instanceof Map){const e=new Map;for(const[i,s]of t)e.set(k(i),k(s));return e}if(t instanceof Set){const e=new Set;for(const i of t)e.add(k(i));return e}const e=Object.getPrototypeOf(t),i=Object.create(e);for(const e of Object.keys(t))i[e]=k(t[e]);return i},G={EntityManager:Symbol.for("EntityManager"),SystemManager:Symbol.for("SystemManager")};var V=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};const N=Symbol("ecs.componentTypeId");let W=0;exports.EntityManager=class{constructor(){this.lastEntityId=0,this.entities=new Set,this.components=new Map,this.entityComponents=new Map,this.componentToEntity=new WeakMap,this.disabledEntities=new Set,this.manuallyDisabledEntities=new Set,this.disabledComponents=new Map,this.parentEntities=new Map,this.childEntities=new Map}createEntity(t,e){if(void 0===t){const t=this.lastEntityId++;return this.entities.add(t),t}return Array.isArray(t)?this.createEntityFromArray(t,e):this.createEntityFromArchetype(t,e)}addArchetype(t,{components:e,disabledComponents:i,children:s,enabled:o}){this.createComponentsForEntity(e,t),i&&this.createComponentsForEntity(i,t,!0),s&&s.forEach((e=>this.createEntityFromArchetype(e,t))),!1===o&&this.disableEntity(t)}createEntityFromArray(t,e){const i=this.createEntity();return this.createComponentsForEntity(t,i),void 0!==e&&this.setParent(i,e),i}createEntityFromArchetype(t,e){const i=this.createEntity();return void 0!==e&&this.setParent(i,e),this.addArchetype(i,t),i}createComponentsForEntity(t,e,i=!1){t.forEach((t=>{let s;if("object"==typeof t)s=this.addComponent(e,k(t));else{if("function"!=typeof t)throw new Error("Invalid component type");s=this.addComponent(e,t)}i&&this.disableComponent(s)}))}removeEntity(t){var e;this.getChildren(t).forEach((t=>this.removeEntity(t)));const i=this.entityComponents.get(t);i&&(i.forEach(((e,i)=>{var s;null===(s=this.components.get(i))||void 0===s||s.delete(t),this.componentToEntity.delete(e)})),this.entityComponents.delete(t)),this.disabledComponents.delete(t),this.disabledEntities.delete(t),this.manuallyDisabledEntities.delete(t);const s=this.getParent(t);void 0!==s&&(null===(e=this.childEntities.get(s))||void 0===e||e.delete(t)),this.parentEntities.delete(t),this.childEntities.delete(t),this.entities.delete(t)}removeAllEntities(t){const e=(null==t?void 0:t.preserveEntitiesWithComponent)?this.search(t.preserveEntitiesWithComponent):[];if(e.length>0){const t=new Set(e.map((({entity:t})=>t)));for(const e of this.entities)t.has(e)||this.removeEntity(e)}else this.components.clear(),this.entityComponents.clear(),this.componentToEntity=new WeakMap,this.disabledComponents.clear(),this.disabledEntities.clear(),this.manuallyDisabledEntities.clear(),this.lastEntityId=0,this.entities.clear(),this.parentEntities.clear(),this.childEntities.clear()}isEntity(t){return this.entities.has(t)}isEntityEnabled(t){return this.isEntity(t)&&!this.disabledEntities.has(t)}enableEntity(t){this.disabledEntities.has(t)&&(this.disabledEntities.delete(t),this.getChildren(t).forEach((t=>{this.manuallyDisabledEntities.has(t)||this.enableEntity(t)})))}disableEntity(t){this.disabledEntities.has(t)||(this.disabledEntities.add(t),this.getChildren(t).forEach((t=>{this.disabledEntities.has(t)?this.manuallyDisabledEntities.add(t):this.disableEntity(t)})))}disableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.disableEntity(s)}enableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.enableEntity(s)}setParent(t,e){if(!this.isEntity(t)||!this.isEntity(e))throw new Error("Both entities must exist to set a parent-child relationship.");if(this.parentEntities.has(t)){const i=this.parentEntities.get(t);if(i===e)return;this.childEntities.get(i).delete(t)}this.parentEntities.set(t,e),this.childEntities.has(e)||this.childEntities.set(e,new Set),this.childEntities.get(e).add(t)}getParent(t){return this.parentEntities.get(t)}getChildren(t){return Array.from(this.childEntities.get(t)||[])}removeParent(t){const e=this.parentEntities.get(t);void 0!==e&&(this.parentEntities.delete(t),this.childEntities.get(e).delete(t))}removeChild(t,e){this.parentEntities.get(e)===t&&(this.parentEntities.delete(e),this.childEntities.get(t).delete(e))}addComponent(t,e){var i;const s=this.getComponentTypeId(e),o="object"==typeof e?e:new e;if(this.components.has(s)||this.components.set(s,new Map),this.components.get(s).has(t)){const e=null!==(i=o.constructor.componentName)&&void 0!==i?i:o.constructor.name;throw new Error(`Entity ${t} already has a component of type ${e}`)}this.components.get(s).set(t,o);let r=this.entityComponents.get(t);return r||(r=new Map,this.entityComponents.set(t,r)),r.set(s,o),this.componentToEntity.set(o,t),o}hasComponent(t,e){var i,s;return null!==(s=null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.has(t))&&void 0!==s&&s}getComponent(t,e){var i;return null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.get(t)}getComponents(t){const e=this.entityComponents.get(t);return e?Array.from(e.values()):[]}updateComponentData(t,e,i){const s=this.getComponent(t,e);s&&i(s)}getEntityForComponent(t){return this.componentToEntity.get(t)}removeComponent(t,e){const i=this.getComponentTypeId("object"==typeof t?t:e),s="number"==typeof t?t:this.getEntityForComponent(t);if(void 0===s)return;const o=this.components.get(i),r=null==o?void 0:o.get(s);if(void 0===r)return;o.delete(s),this.componentToEntity.delete(r);const n=this.entityComponents.get(s);n&&(n.delete(i),0===n.size&&this.entityComponents.delete(s))}isComponentEnabled(t,e){var i,s;const o=this.getComponentTypeId("object"==typeof t?t:e);if("number"==typeof t&&!(null===(i=this.components.get(o))||void 0===i?void 0:i.has(t)))return!1;const r="number"==typeof t?t:this.getEntityForComponent(t);return!(null===(s=this.disabledComponents.get(r))||void 0===s?void 0:s.has(o))}disableComponent(t,e){const i="number"==typeof t?t:this.getEntityForComponent(t),s=this.getComponentTypeId("object"==typeof t?t:e);null!=i&&(this.disabledComponents.has(i)?this.disabledComponents.get(i).has(s)||this.disabledComponents.get(i).add(s):this.disabledComponents.set(i,new Set([s])))}enableComponent(t,e){var i;const s="number"==typeof t?t:this.getEntityForComponent(t),o=this.getComponentTypeId("object"==typeof t?t:e);void 0!==s&&(null===(i=this.disabledComponents.get(s))||void 0===i?void 0:i.has(o))&&this.disabledComponents.get(s).delete(o)}getComponentFromParent(t,e){let i=t;for(;i;){const t=this.getComponent(i,e);if(t)return t;i=this.getParent(i)}}search(t,e,i=!1){var s,o;const r=this.getComponentTypeId(t),n="function"==typeof e?e:void 0,a="boolean"==typeof e?e:i,h=this.components.get(r);if(!h)return n?void 0:[];if(n){for(const[t,e]of h)(a||!this.disabledEntities.has(t)&&!(null===(s=this.disabledComponents.get(t))||void 0===s?void 0:s.has(r)))&&n(e,t);return}const l=[];for(const[t,e]of h)(a||!this.disabledEntities.has(t)&&!(null===(o=this.disabledComponents.get(t))||void 0===o?void 0:o.has(r)))&&l.push({entity:t,component:e});return l}searchEntitiesByComponents(t){if(0===t.length)return[];const e=[];for(const i of t){const t=this.getComponentTypeId(i),s=this.components.get(t);if(!s||0===s.size)return[];e.push(s)}e.sort(((t,e)=>t.size-e.size));const[i,...s]=e,o=[];for(const t of i.keys()){let e=!0;for(const i of s)if(!i.has(t)){e=!1;break}e&&o.push(t)}return o}searchInChildren(t,e,i=!1){const s=new Set(this.getChildren(t));return this.search(e,i).filter((({entity:t})=>s.has(t)))}getComponentTypeId(t){const e="object"==typeof t?t.constructor:t;return void 0===e[N]&&(e[N]=++W),e[N]}},exports.EntityManager=V([l(G.EntityManager)],exports.EntityManager);var z,H=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};exports.SystemManager=class{constructor(){this.systems=[]}findSystemIndex(t){return this.systems.findIndex((e=>e[0]instanceof t))}addSystem(t,e){if(this.systems.some((t=>t[0]instanceof t.constructor)))throw new Error(`SystemManager already has an instance of ${t.constructor.name}.`);this.systems.push([t,e,!1])}hasSystem(t){return this.systems.some((e=>e[0]instanceof t))}getSystem(t){const e=this.findSystemIndex(t);return-1!==e?this.systems[e][0]:void 0}groupHasSystems(t){return this.systems.filter((e=>e[1]===t)).length>0}enableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!0===this.systems[e][2])return;this.systems[e][2]=!0}disableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!1===this.systems[e][2])return;this.systems[e][2]=!1}setExecutionOrder(t,e){const i=this.findSystemIndex(t);if(-1===i)throw new Error(`Cannot set execution order because ${t.name} is not a system.`);this.systems.splice(e,0,this.systems.splice(i,1)[0])}removeSystem(t){const e=this.findSystemIndex(t);-1!==e&&this.systems.splice(e,1)}disableAllSystems(){this.systems.forEach((t=>{t[2]&&this.disableSystem(t[0].constructor)}))}update(t){this.systems.filter((e=>e[1]===t&&!0===e[2])).forEach((t=>t[0].onUpdate()))}},exports.SystemManager=H([l(G.SystemManager)],exports.SystemManager),function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(z||(z={}));class Y{constructor(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}getContextVersion(){return null!==this.canvas.getContext(z.WebGL2)?z.WebGL2:null!==this.canvas.getContext(z.LegacyWebGL)?z.LegacyWebGL:void 0}}class ${constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(this.getId(t))}getFontAtlas(t){return this.fontAtlas.get(this.getId(t))}getOrCreate(t){var e;return null!==(e=this.getFontAtlas(t))&&void 0!==e?e:this.create(t)}create(t){const{font:e,charRanges:i,fontSize:s,spacing:o}=t;this.chars=[];for(let t=0;t<i.length;t+=2)for(let e=i[t];e<=i[t+1];e++)this.chars.push(String.fromCharCode(e));this.font=e instanceof FontFace?e.family:e,this.fontSize=s,this.spacing=o,this.id=this.getId(t);const r=this.renderAtlas();return this.fontAtlas.set(this.id,r),r}getId({font:t,charRanges:e,fontSize:i,spacing:s}){return JSON.stringify({font:t instanceof FontFace?t.family:t,charRanges:e,fontSize:i,spacing:s})}renderAtlas(){const t=new X(this.id,this.fontSize,Math.ceil(Math.sqrt(this.chars.length)),this.spacing),e=t.canvas.getContext("2d");e.clearRect(0,0,t.canvas.width,t.canvas.height),e.textBaseline="top",e.fillStyle="#FFFFFF",e.font=`${this.fontSize}px ${this.font}`;let i=0,s=0;for(let o=0;o<this.chars.length;o++)e.fillText(this.chars[o],i,s),t.glyphs.set(this.chars[o],{id:o,width:e.measureText(this.chars[o]).width}),(i+=this.fontSize+this.spacing)>t.canvas.width-this.fontSize&&(i=0,s+=this.fontSize+this.spacing);return t}}class X{constructor(t,e,i,s){this.id=t,this.fontSize=e,this.gridSize=i,this.spacing=s,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*(this.fontSize+this.spacing),this.canvas.height=this.canvas.width}}class q{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),s=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,s),this.gl.attachShader(i,o),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class K{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i,this.lightUniforms=[]}loadProgram(){this.program=this.contextVersion===z.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nout vec2 texCoords;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","#version 300 es\nprecision highp float;\n\nin vec2 texCoords;\n\n// texture, mask and darkness\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[64];\nuniform int u_numLights;\n\nout vec4 fragColor;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < u_numLights; i++) {\n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n fragColor = vec4(u_solidColor.rgb, alpha);\n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}","precision mediump float;\n\nvarying vec2 texCoords;\n\n// texture, mask and darkness\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light\nstruct Light {\n vec2 position;\n float radius;\n float smoothMode;\n float intensity;\n};\n\nuniform int u_renderLight;\nuniform Light u_lights[64];\nuniform int u_numLights;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n\n for (int i = 0; i < 64; i++) {\n if (u_lights[i].intensity == 0.0) continue; \n \n Light light = u_lights[i];\n float dist = distance(fragCoord, light.position);\n \n if (dist < light.radius) {\n alpha -= (light.smoothMode > 0.0 ? smoothstep(light.radius, 0.0, dist) : 1.0) * light.intensity;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n gl_FragColor = vec4(u_solidColor.rgb, alpha);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}"),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.renderLightUniform=this.gl.getUniformLocation(this.program,"u_renderLight"),this.numLightsUniform=this.gl.getUniformLocation(this.program,"u_numLights"),this.lightUniforms=[];for(let t=0;t<64;t++)this.lightUniforms.push({position:this.gl.getUniformLocation(this.program,`u_lights[${t}].position`),radius:this.gl.getUniformLocation(this.program,`u_lights[${t}].radius`),smoothMode:this.gl.getUniformLocation(this.program,`u_lights[${t}].smoothMode`),intensity:this.gl.getUniformLocation(this.program,`u_lights[${t}].intensity`)});this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)}}class J{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const s=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,s)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var Q="undefined"!=typeof Float32Array?Float32Array:Array;function Z(){var t=new Q(16);return Q!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function tt(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function et(t,e,i){var s,o,r,n,a,h,l,c,d,g,p,u,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(s=e[0],o=e[1],r=e[2],n=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],g=e[9],p=e[10],u=e[11],t[0]=s,t[1]=o,t[2]=r,t[3]=n,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=g,t[10]=p,t[11]=u,t[12]=s*m+a*f+d*y+e[12],t[13]=o*m+h*f+g*y+e[13],t[14]=r*m+l*f+p*y+e[14],t[15]=n*m+c*f+u*y+e[15]),t}function it(t,e,i){var s=i[0],o=i[1],r=i[2];return t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function st(t,e,i){var s=Math.sin(i),o=Math.cos(i),r=e[0],n=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],g=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*o+l*s,t[1]=n*o+c*s,t[2]=a*o+d*s,t[3]=h*o+g*s,t[4]=l*o-r*s,t[5]=c*o-n*s,t[6]=d*o-a*s,t[7]=g*o-h*s,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ot=function(t,e,i,s,o,r,n){var a=1/(e-i),h=1/(s-o),l=1/(r-n);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(o+s)*h,t[14]=(n+r)*l,t[15]=1,t};const rt=(t,e,i,s)=>{t=tt(t),ot(t,-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),it(t,t,[null!=i?i:1,null!=i?i:1,1]),et(t,t,[-s.x,-s.y,0])},nt=new Map,at=t=>{const e=nt.get(t);if(void 0!==e)return e;const i=/^#?([a-f\d]{2})?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);if(!i)throw new Error(`Invalid hex color: ${t}`);const s=Object.freeze({r:parseInt(i[2],16)/255,g:parseInt(i[3],16)/255,b:parseInt(i[4],16)/255,a:void 0!==i[1]?parseInt(i[1],16)/255:1});return nt.size>=1024&&nt.clear(),nt.set(t,s),s};class ht{constructor(t){this.gl=t}render(t){const e=at(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var lt;!function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric",t[t.Video=5]="Video",t[t.Darkness=6]="Darkness"}(lt||(lt={}));var ct;exports.GeometricShape=void 0,(ct=exports.GeometricShape||(exports.GeometricShape={}))[ct.Polygon=0]="Polygon",ct[ct.Circumference=1]="Circumference",ct[ct.Line=2]="Line";let dt=class{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.circumferencePositionBuffer=this.gl.createBuffer(),this.linesPositionBuffer=this.gl.createBuffer();const i=2*Math.PI/60,s=new Float32Array(r(1,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]));this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.STATIC_DRAW)}render(t,e,i){switch(this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr),t.shape){case exports.GeometricShape.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP);break;case exports.GeometricShape.Line:this.renderLines(t,e,this.gl.LINES);break;case exports.GeometricShape.Circumference:this.renderCircumference(t,e,i);break;default:return!1}return!0}renderLines(t,e,i){var s;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.linesPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertexModel.reduce(((t,e)=>[...t,e.x,e.y]),[])),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:o,g:r,b:n,a:a}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,n,a),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,t.vertexModel.length),this.lastShape="polygon"}renderCircumference(t,e,i){i===lt.Geometric&&"circumference"===this.lastShape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),it(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:s,g:o,b:r,a:n}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,s,o,r,n),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,60),this.lastShape="circumference"}};var gt;exports.MaskShape=void 0,(gt=exports.MaskShape||(exports.MaskShape={}))[gt.Rectangle=0]="Rectangle",gt[gt.Circumference=1]="Circumference",gt[gt.Polygon=2]="Polygon";let pt=class{constructor(t,e){this.gl=t,this.programManager=e,this.type=lt.Mask,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.circumferencePositionBuffer=this.gl.createBuffer(),this.rectanglePositionBuffer=this.gl.createBuffer(),this.polygonPositionBuffer=this.gl.createBuffer();const i=2*Math.PI/60,s=[0,0];for(let t=0;t<=60;t++)s.push(Math.cos(t*i),Math.sin(t*i));this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(s),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.rectanglePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW)}render(t,e,i){return this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr),t.shape===exports.MaskShape.Rectangle?this.renderRectangle(t,e,i):t.shape===exports.MaskShape.Circumference?this.renderCircumference(t,e,i):t.shape===exports.MaskShape.Polygon&&this.renderPolygon(t,e,i),this.lastShape=t.shape,!0}renderRectangle(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Rectangle||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.rectanglePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}renderCircumference(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Circumference||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,62)}renderPolygon(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Polygon||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.polygonPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertices.reduce(((t,e)=>[...t,e.x,e.y]),[0,0])),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,t.vertices.length+1)}},ut=class{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW)}render(t,e,i){var s,o;i!==lt.Darkness&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0),this.gl.uniform1i(this.programManager.renderLightUniform,1);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.numLightsUniform,Math.min(t.lights.length,64));for(const[i,s]of t.lights.entries()){if(i>=64)break;const t=this.programManager.lightUniforms[i];this.gl.uniform2f(t.position,this.gl.canvas.width/2+(s.position.x-e.position.x)*e.zoom,this.gl.canvas.height/2+(s.position.y-e.position.y)*e.zoom),this.gl.uniform1f(t.radius,s.radius*e.zoom),this.gl.uniform1f(t.smoothMode,s.smooth?1:0),this.gl.uniform1f(t.intensity,Math.max(0,Math.min(1,s.intensity)))}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.gl.uniform1i(this.programManager.renderLightUniform,0),!0}},mt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.tiledPosVertices=new Map,this.tiledTexVertices=new Map,this.isTiled=!1,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.tiledPositionBuffer=this.gl.createBuffer(),this.tiledTextureBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0]),this.gl.STATIC_DRAW),this.lastDrawMode="sprite"}render(t,e,i){var s,o,r,n;this.isTiled=t.tiled&&(t.tiled.x>1||t.tiled.y>1),this.isTiled||i===lt.Sprite&&"sprite"===this.lastDrawMode?this.isTiled&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.tiledPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getTiledPositionVertices(t.tiled),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.tiledTextureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getTiledTextureVertices(t.tiled),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)):(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.lastDrawMode=this.isTiled?"tiled":"sprite",this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontally?-1:1),t.height*(t.flipVertically?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),t.slice&&(et(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),it(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.isTiled?this.gl.drawArrays(this.gl.TRIANGLES,0,t.tiled.x*t.tiled.y*6):this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}getTiledPositionVertices(t){const e=t.toString();if(!this.tiledPosVertices.has(e)){const i=[];for(let e=-t.x/2;e<t.x/2;e++)for(let s=-t.y/2;s<t.y/2;s++)i.push(e,s,e,s+1,e+1,s,e+1,s,e,s+1,e+1,s+1);this.tiledPosVertices.set(e,new Float32Array(i))}return this.tiledPosVertices.get(e)}getTiledTextureVertices(t){const e=t.toString();if(!this.tiledTexVertices.has(e)){const i=[];for(let e=0;e<t.x*t.y;e++)i.push(0,1,0,0,1,1,1,1,0,0,1,0);this.tiledTexVertices.set(e,new Float32Array(i))}return this.tiledTexVertices.get(e)}};var ft;exports.TextAlignment=void 0,(ft=exports.TextAlignment||(exports.TextAlignment={}))[ft.Center=0]="Center",ft[ft.Right=1]="Right",ft[ft.Left=2]="Left";let yt=class{constructor(t,i,s,o){this.gl=t,this.programManager=i,this.textureManager=s,this.fontAtlasFactory=o,this.type=lt.Text,this.posVertices=[],this.texVertices=[],this.shadowPosition=new e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer()}render(t,i,s,o=!1){var r;if(!t.text)return!1;const n=this.fontAtlasFactory.getOrCreate(Object.assign({font:t.font},t.textureAtlas));if(o||(this.generateTextVertices(n,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),t.shadow){const{color:o,offset:r,opacity:n}=t.shadow,a=Object.assign(Object.assign({},t),{color:o,opacity:n*t.opacity,position:e.add(this.shadowPosition,t.position,r)});a.shadow=void 0,this.render(a,i,s,!0),s=lt.Text}this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),it(this.modelMatrix,this.modelMatrix,[t.fontSize*(t.flipHorizontally?-1:1),t.fontSize*(t.flipVertically?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),rt(this.projectionMatrix,this.gl,i.zoom,i.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromCanvas(n.id,n.canvas,t.smooth);this.lastTexture===a&&s===lt.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.useMaskColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.opacity);const{r:h,g:l,b:c,a:d}=at(t.color);return this.gl.uniform1i(this.programManager.useTintColorUniform,1),this.gl.uniform4f(this.programManager.tintColorUniform,h,l,c,d),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}generateTextVertices(t,e){this.posVertices=[],this.texVertices=[];const i=this.preProcessText(t,e),s=e.letterSpacing/e.fontSize,o=e.lineHeight/e.fontSize,r=e.boundingBox.height/e.fontSize,n=e.boundingBox.width/e.fontSize;let a=r/2;for(const r of i){const{text:i,width:h}=r;let l=e.alignment===exports.TextAlignment.Center?-h/2:e.alignment===exports.TextAlignment.Left?-n/2:n/2-h;for(const e of i){const i=t.glyphs.get(e);if(i){const e=i.width/t.fontSize;this.posVertices.push(l,a-1,l+e,a-1,l,a,l,a,l+e,a-1,l+e,a);const o=i.id%t.gridSize*(t.fontSize+t.spacing),r=(i.id/t.gridSize|0)*(t.fontSize+t.spacing),n=o/t.canvas.width,h=r/t.canvas.height,c=(o+i.width)/t.canvas.width,d=(r+t.fontSize)/t.canvas.height;this.texVertices.push(n,d,c,d,n,h,n,h,c,d,c,h),l+=e+s}}l=-n/2,a-=o}}preProcessText(t,{text:e,fontSize:i,letterSpacing:s,lineHeight:o,boundingBox:{width:r,height:n}}){const a=[];s/=i,o/=i,r/=i,n/=i;const h=t.glyphs.get(" ").width/t.fontSize+s;let l=0;const c=e.split("\n");for(const e of c){let i=[],c=0;l+=o;const d=e.split(" ");for(const e of d){if(l>n)return a;const d=0===i.length;let g=0;for(const i of e){const e=t.glyphs.get(i);e&&(g+=e.width/t.fontSize+s)}g-=s,d||(g+=h),d&&g>=r?(a.push({width:g,text:e}),l+=o):c+g===r?(i.push(e),a.push({width:c+g,text:i.join(" ")}),i=[],c=0,l+=o):c+g>r?(a.push({width:c,text:i.join(" ")}),i=[e],c=g-h,l+=o):(c+=g,i.push(e))}i.length>0&&a.push({width:c,text:i.join(" ")})}return a}};var xt;exports.TilemapOrientation=void 0,(xt=exports.TilemapOrientation||(exports.TilemapOrientation={}))[xt.Center=0]="Center",xt[xt.RightUp=1]="RightUp",xt[xt.RightDown=2]="RightDown",xt[xt.RightCenter=3]="RightCenter";let Mt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer()}render(t,e,i){var s,o,r,n;if(this.processTileset(t.tileset),this.generateVertices(t),0===this.posVertices.length)return!1;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===lt.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}processTileset(t){var i,s,o,r;if(t._texData)return;const{naturalWidth:n,naturalHeight:a}=t.image;if(!n||!a)return;const h=null!==(i=t.margin)&&void 0!==i?i:0,l=null!==(s=t.spacing)&&void 0!==s?s:0,c=Math.floor((n-2*h+l)/(t.tileWidth+l)),d=Math.floor((a-2*h+l)/(t.tileHeight+l));t._texData={columns:c,firstgid:null!==(o=t.firstgid)&&void 0!==o?o:1,tileCount:null!==(r=t.tileCount)&&void 0!==r?r:c*d,margin:new e(h/n,h/a),step:new e((t.tileWidth+l)/n,(t.tileHeight+l)/a),tileSize:new e(t.tileWidth/n,t.tileHeight/a)}}generateVertices({tiles:t,tilemap:e,tileset:i}){if(this.posVertices=[],this.texVertices=[],!i._texData)return;const{columns:s,firstgid:o,tileCount:r,margin:n,step:a,tileSize:h}=i._texData,l=Math.floor(t.length/e.width);t.forEach(((t,c)=>{var d,g;if(t<o||t>=o+r)return;const p=null!==(g=null===(d=i._animationState)||void 0===d?void 0:d.get(t))&&void 0!==g?g:t,u=c%e.width-e.width/2,m=l/2-Math.floor(c/e.width);this.posVertices.push(u,m-1,u+1,m-1,u,m,u,m,u+1,m-1,u+1,m);const f=n.x+(p-o)%s*a.x,y=n.y+Math.floor((p-o)/s)*a.y;this.texVertices.push(f,y+h.y,f+h.x,y+h.y,f,y,f,y,f+h.x,y+h.y,f+h.x,y)}))}},vt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0]),this.gl.STATIC_DRAW)}render(t,e,i){var s,o,r,n;i!==lt.Video&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),t.slice&&(et(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),it(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===lt.Video||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),t.video.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};class Ct{constructor(t){this.gl=t}createFromImage(t,e=!1,i){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(()=>this.createFromSource(t,i,e))),i}createFromCanvas(t,e=!1,i){return i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i}createPixelTexture(){const t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),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.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t}createFromSource(t,e,i=!1){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),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),i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)):(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.bindTexture(this.gl.TEXTURE_2D,null)}}const bt=(t,e)=>`${e?"_smooth_":""}${t}`;class St{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!1){var i;return null!==(i=this.textures.get(bt(t.src,e)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!1){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(bt(t.src,e),i),i}getOrCreateTextureFromCanvas(t,e,i=!1){var s;return null!==(s=this.textures.get(bt(t,i)))&&void 0!==s?s:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!1){const s=this.textureFactory.createFromCanvas(e,i);return this.textures.set(bt(t,i),s),s}getOrCreateTextureFromVideo(t){var e;return null!==(e=this.textures.get(t.src))&&void 0!==e?e:this.createTextureFromVideo(t)}createTextureFromVideo(t){const e=this.textureFactory.createPixelTexture();return this.textures.set(t.src,e),e}}const wt={CanvasElement:Symbol.for("CanvasElement"),WebGLManager:Symbol.for("WebGLManager")};var At=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},Rt=function(t,e){return function(i,s){e(i,s,t)}};let _t=class{constructor(t){this.renderers=new Map;const e=new Y(t),i=e.gl,s=e.contextVersion,o=new K(i,s,new q(i,new J(i))),r=new St(new Ct(i));this.fontAtlasFactory=new $,this.renderers.set(lt.Sprite,new mt(i,o,r)),this.renderers.set(lt.Text,new yt(i,o,r,this.fontAtlasFactory)),this.renderers.set(lt.Tilemap,new Mt(i,o,r)),this.renderers.set(lt.Geometric,new dt(i,o)),this.renderers.set(lt.Mask,new pt(i,o)),this.renderers.set(lt.Video,new vt(i,o,r)),this.renderers.set(lt.Darkness,new ut(i,o)),this.canvasColorRenderer=new ht(i),o.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender)&&(this.lastRender=t.type)}renderCanvasColor(t){this.canvasColorRenderer.render(t)}};_t=At([l(wt.WebGLManager),Rt(0,c(wt.CanvasElement))],_t);const Et=Object.assign(Object.assign(Object.assign({AssetManager:Symbol.for("AssetManager"),AudioContext:Symbol.for("AudioContext"),CreateSystemService:Symbol.for("CreateSystemService"),GameConfig:Symbol.for("GameConfig"),InputManager:Symbol.for("InputManager"),LoopManager:Symbol.for("LoopManager"),RenderManager:Symbol.for("RenderManager"),SceneManager:Symbol.for("SceneManager"),TimeManager:Symbol.for("TimeManager")},d),G),wt);function Tt(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function Pt(t,e){return function(i,s){e(i,s,t)}}function Bt(t,e,i,s){return new(i||(i=Promise))((function(o,r){function n(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?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class Dt{constructor(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new e,this._leftStickAxes=new e,this._rightStickAxes=new e}get dpadAxes(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes}get leftStickAxes(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes}get rightStickAxes(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes}get dpadUp(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t}get dpadDown(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t}get dpadLeft(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t}get dpadRight(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t}get bottomFace(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t}get rightFace(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t}get leftFace(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t}get topFace(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t}get leftShoulder(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t}get rightShoulder(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t}get leftTrigger(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t}get rightTrigger(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t}get back(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t}get start(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t}get leftStickButton(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t}get rightStickButton(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t}get leftStickHorizontal(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0}get leftStickVertical(){var t;return-(null!==(t=this.axes.get(1))&&void 0!==t?t:0)}get rightStickHorizontal(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0}get rightStickVertical(){var t;return-(null!==(t=this.axes.get(3))&&void 0!==t?t:0)}get anyButtonPressed(){var t;return null!==(t=Array.from(this.buttons.values()).find((t=>t)))&&void 0!==t&&t}vibrate(t=200,e=.2,i=.2,s=0){this.vibrationInput={duration:t,weakMagnitude:e,startDelay:s,strongMagnitude:i}}}class Ft{constructor(){this.pressedKeys=[]}isPressed(t){return this.pressedKeys.includes(t)}orPressed(t){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)}andPressed(t){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)}isPressedReturn(t,e,i){return this.pressedKeys.includes(t)?e:i}orPressedReturn(t,e,i){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)?e:i}andPressedReturn(t,e,i){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)?e:i}}class jt{constructor(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new e,this.hasMoved=!1,this.wheelScroll=new e}}class Ut{constructor(){this.touching=!1,this.interactions=[]}}exports.InputManager=class{constructor(){this.keyboard=new Ft,this.mouse=new jt,this.touchScreen=new Ut,this.gamepads=[]}},exports.InputManager=Tt([l(Et.InputManager)],exports.InputManager);const It=[60,120,180,240];var Lt;exports.TimeManager=class{get deltaTime(){return this.unscaledDeltaTime*this.timeScale}get physicsDeltaTime(){return this.unscaledPhysicsDeltaTime*this.timeScale}get renderDeltaTime(){return this.browserDeltaTime*this.timeScale}get unscaledRenderDeltaTime(){return this.browserDeltaTime}constructor({physicsFramerate:t},e){if(this.entityManager=e,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForRender=0,this.lastIntervalId=0,this.intervals=new Map,t&&!It.includes(t))throw new Error(`Invalid Physics frame rate. Allowed: [${It.join(", ")}]`);this.fixedGameFramerate=60,this.fixedGameDeltaTime=parseFloat((1/this.fixedGameFramerate).toFixed(6)),this.fixedPhysicsFramerate=null!=t?t:180,this.fixedPhysicsDeltaTime=parseFloat((1/this.fixedPhysicsFramerate).toFixed(6))}updateForRender(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForRender),this.maxDeltaTime),this.thenForRender=t}updateForGame(t){this.unscaledDeltaTime=Math.min(Math.max(this.fixedGameDeltaTime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t}updateForPhysics(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t}updateIntervals(){if(0!==this.intervals.size)for(const[t,e]of this.intervals)this.intervalHealthCheck(e)?(e.executeImmediately?(e.timer=e.delay,e.executeImmediately=!1):e.timer+=1e3*(e.useTimeScale?this.deltaTime:this.unscaledDeltaTime),e.timer>=e.delay&&(e.callback(),e.times&&--e.times<=0?this.clearInterval(t):e.timer-=e.delay)):this.clearInterval(t)}intervalHealthCheck(t){return!(t.entityRef&&!this.entityManager.isEntityEnabled(t.entityRef))&&!(t.componentRef&&!this.entityManager.isComponentEnabled(t.componentRef))}setInterval({callback:t,delay:e,times:i,executeImmediately:s,entityRef:o,componentRef:r,useTimeScale:n=!0}){const a=++this.lastIntervalId;return this.intervals.set(a,{callback:t,delay:e,times:i,executeImmediately:s,entityRef:o,componentRef:r,timer:0,useTimeScale:n}),a}clearInterval(t){this.intervals.delete(t)}clearAllIntervals(){this.intervals.clear()}},exports.TimeManager=Tt([l(Et.TimeManager),Pt(0,c(Et.GameConfig)),Pt(1,c(Et.EntityManager))],exports.TimeManager),function(t){t[t.Image=0]="Image",t[t.Audio=1]="Audio",t[t.Font=2]="Font",t[t.Video=3]="Video",t[t.Json=4]="Json"}(Lt||(Lt={})),exports.AssetManager=class{constructor(t){this.audioContext=t,this.assets=[]}getAssetsLoaded(){return this.assets.reduce(((t,e)=>t&&e.loaded),!0)}loadImage(t,e){if(this.getImage(t))return this.getImage(t);const i=new Image;i.crossOrigin="",i.src=t;const s=this.createAsset(t,Lt.Image,i,e),o=()=>s.loaded=!0;return i.complete?o():i.addEventListener("load",o),i}loadAudio(t,e){const i=this.getAudio(t);if(i)return i;if(!this.audioContext){return void(this.createAsset(t,Lt.Audio,void 0,e).loaded=!0)}const s=new Audio;s.src=t;const o={element:s},r=this.createAsset(t,Lt.Audio,o,e);return this.decodeAudioBuffer(t).then((t=>{o.buffer=t,r.loaded=!0})),o}decodeAudioBuffer(t){return Bt(this,void 0,void 0,(function*(){const e=yield fetch(t),i=yield e.arrayBuffer();return this.audioContext.decodeAudioData(i)}))}loadFont(t,e){if(this.getFont(t))return this.getFont(t);const i=new FontFace(t,`url(${e})`),s=this.createAsset(e,Lt.Font,i);return s.family=t,document.fonts.add(i),i.load().then((()=>s.loaded=!0)),i}loadVideo(t,e){if(this.getVideo(t))return this.getVideo(t);const i=document.createElement("video");i.playsInline=!0,i.src=t;const s=this.createAsset(t,Lt.Video,i,e);return i.duration?s.loaded=!0:i.addEventListener("canplaythrough",(()=>s.loaded=!0)),i}loadJson(t,e){return Bt(this,void 0,void 0,(function*(){if(this.getJson(t))return this.getJson(t);const i=this.createAsset(t,Lt.Json,void 0,e),s=yield fetch(t),o=yield s.json();return i.loaded=!0,i.element=o,o}))}getImage(t){var e;return null===(e=this.assets.find((e=>e.type===Lt.Image&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getAudio(t){var e;return null===(e=this.assets.find((e=>e.type===Lt.Audio&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getFont(t){var e;return null===(e=this.assets.find((e=>e.type===Lt.Font&&e.family===t)))||void 0===e?void 0:e.element}getVideo(t){var e;return null===(e=this.assets.find((e=>e.type===Lt.Video&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getJson(t){var e;return null===(e=this.assets.find((e=>e.type===Lt.Json&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}createAsset(t,e,i,s){this.deleteAssetIfExists({url:t,name:s});const o={type:e,url:t,element:i,loaded:!1,name:s};return this.assets.push(o),o}deleteAssetIfExists({url:t,name:e}){const i=this.assets.findIndex((i=>i.url===t||void 0!==i.name&&i.name===e));-1!==i&&this.assets.splice(i,1)}},exports.AssetManager=Tt([l(Et.AssetManager),Pt(0,c(Et.AudioContext))],exports.AssetManager);class Ot{get currentTime(){return this._currentTime}get playing(){return"playing"===this.state}get paused(){return"paused"===this.state}get stopped(){return"stopped"===this.state}constructor(t){this.stopOnSceneTransition=!0,this.fixedToTimeScale=!1,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.startAt=0,this.state="stopped",this.volume=1,this._currentAudioSource=void 0,this._sourceNode=void 0,this._gainNode=void 0,this._startedAt=0,this._pauseOffset=0,this._currentTime=0,this._playAfterUserInput=!1,Object.assign(this,t)}play(t){t&&(this.audioSource=t),this.action="play"}pause(){this.action="pause"}stop(){this.action="stop"}}Ot.componentName="AudioPlayer";const kt={AudioPlayerSystem:Symbol.for("AudioPlayerSystem"),ButtonSystem:Symbol.for("ButtonSystem"),TiledObjectSystem:Symbol.for("TiledObjectSystem"),TiledWrapperSystem:Symbol.for("TiledWrapperSystem"),TilemapPreProcessingSystem:Symbol.for("TilemapPreProcessingSystem"),TransformSystem:Symbol.for("TransformSystem"),GamepadSystem:Symbol.for("GamepadSystem"),KeyboardSystem:Symbol.for("KeyboardSystem"),MouseSystem:Symbol.for("MouseSystem"),TouchScreenSystem:Symbol.for("TouchScreenSystem"),UpdateBallColliderShapeSystem:Symbol.for("UpdateBallColliderShapeSystem"),UpdateBoxColliderShapeSystem:Symbol.for("UpdateBoxColliderShapeSystem"),UpdateEdgeColliderShapeSystem:Symbol.for("UpdateEdgeColliderShapeSystem"),UpdatePolygonColliderShapeSystem:Symbol.for("UpdatePolygonColliderShapeSystem"),UpdateTilemapColliderShapeSystem:Symbol.for("UpdateTilemapColliderShapeSystem"),UpdateCollidersAfterRepositionSystem:Symbol.for("UpdateCollidersAfterRepositionSystem"),ApplyRepositionSystem:Symbol.for("ApplyRepositionSystem"),ApplyVelocitySystem:Symbol.for("ApplyVelocitySystem"),ResolveCollisionSystem:Symbol.for("ResolveCollisionSystem"),AnimatorSystem:Symbol.for("AnimatorSystem"),TilemapAnimationSystem:Symbol.for("TilemapAnimationSystem"),CameraSystem:Symbol.for("CameraSystem"),ClearScreenSystem:Symbol.for("ClearScreenSystem"),CullingSystem:Symbol.for("CullingSystem"),MaskRendererSystem:Symbol.for("MaskRendererSystem"),RenderSystem:Symbol.for("RenderSystem"),DarknessLightRendererSystem:Symbol.for("DarknessLightRendererSystem"),SpriteRendererSystem:Symbol.for("SpriteRendererSystem"),GeometricRendererSystem:Symbol.for("GeometricRendererSystem"),TextRendererSystem:Symbol.for("TextRendererSystem"),TilemapRendererSystem:Symbol.for("TilemapRendererSystem"),VideoRendererSystem:Symbol.for("VideoRendererSystem"),DebugButtonSystem:Symbol.for("DebugButtonSystem"),DebugColliderRenderSystem:Symbol.for("DebugColliderRenderSystem"),DebugMousePositionSystem:Symbol.for("DebugMousePositionSystem"),DebugTextRendererSystem:Symbol.for("DebugTextRendererSystem")},Gt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Vt=class{constructor(t,e,i,s,o){this.entityManager=t,this.inputManager=e,this.timeManager=i,this.assetManager=s,this.audioContext=o,this.canPlay=!0,this.userInputErrorCatched=!1,this.userInputEventHandler=()=>{Gt.forEach((t=>window.removeEventListener(t,this.userInputEventHandler))),this.canPlay=!0,"suspended"===this.audioContext.state&&this.audioContext.resume()},document.addEventListener("visibilitychange",(()=>{document.hidden?(this.canPlay=!1,"running"===this.audioContext.state&&this.audioContext.suspend()):(this.canPlay=!0,"suspended"===this.audioContext.state&&this.audioContext.resume())}))}catchUserInput(){this.canPlay=!1,this.userInputErrorCatched=!0,Gt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(Ot,(t=>{var e;if("string"==typeof t.audioSource){const e=this.assetManager.getAudio(t.audioSource);if(!(null==e?void 0:e.buffer))return;t.audioSource=e}(null===(e=t.audioSource)||void 0===e?void 0:e.buffer)&&(t._playAfterUserInput&&(t._playAfterUserInput=!1,t.action="play"),t.audioSource!==t._currentAudioSource&&(this.disposeSource(t),t._currentAudioSource=t.audioSource,t._pauseOffset=0,t.state="stopped"),t._gainNode&&(t._gainNode.gain.value=t.volume),t._sourceNode&&(t._sourceNode.playbackRate.value=this.computePlaybackRate(t),this.applyLoop(t,t._sourceNode)),"play"===t.action&&"playing"!==t.state?"suspended"===this.audioContext.state?(t._playAfterUserInput=!0,this.userInputErrorCatched||this.catchUserInput()):("stopped"===t.state&&(t._pauseOffset=t.startAt),this.startSource(t),t.state="playing"):"pause"===t.action&&"playing"===t.state?(this.pauseSource(t),t.state="paused"):"stop"===t.action&&"stopped"!==t.state&&(this.disposeSource(t),t._pauseOffset=0,t.state="stopped"),t.action=void 0,this.updateCurrentTime(t))}))}onSceneDestroyed(){this.entityManager.search(Ot,(t=>{t.stopOnSceneTransition&&this.stopAudioPlayer(t)}),!0)}onGameStopped(){this.entityManager.search(Ot,(t=>this.stopAudioPlayer(t)),!0)}stopAudioPlayer(t){this.disposeSource(t),t._pauseOffset=0,t.state="stopped"}computePlaybackRate(t){return t.fixedToTimeScale?this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16):1}startSource(t){var e;const i=this.audioContext.createBufferSource();i.buffer=t._currentAudioSource.buffer,this.applyLoop(t,i),i.playbackRate.value=this.computePlaybackRate(t);const s=null!==(e=t._gainNode)&&void 0!==e?e:this.audioContext.createGain();s.gain.value=t.volume,i.connect(s),t._gainNode||s.connect(this.audioContext.destination),i.onended=()=>{t._sourceNode===i&&(t._sourceNode=void 0,t._pauseOffset=0,t.state="stopped")};const o=t._pauseOffset;i.start(0,o),t._sourceNode=i,t._gainNode=s,t._startedAt=this.audioContext.currentTime-o}pauseSource(t){t._sourceNode&&(t._pauseOffset=this.wrapElapsed(t,this.audioContext.currentTime-t._startedAt),this.disposeSource(t))}applyLoop(t,e){e.loop=t.loop,e.loopStart=t.loopStart,e.loopEnd=t.loopEnd}wrapElapsed(t,e){if(t.loop&&t._currentAudioSource){const{loopStart:i,loopEnd:s}=t;s>i?e>s&&(e=i+(e-i)%(s-i)):e%=t._currentAudioSource.buffer.duration}return Math.max(0,e)}updateCurrentTime(t){"playing"===t.state&&t._sourceNode?t._currentTime=this.wrapElapsed(t,this.audioContext.currentTime-t._startedAt):t._currentTime=t._pauseOffset}disposeSource(t){if(t._sourceNode){t._sourceNode.onended=null;try{t._sourceNode.stop()}catch(t){}t._sourceNode=void 0}}};var Nt;Vt=Tt([l(kt.AudioPlayerSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.InputManager)),Pt(2,c(Et.TimeManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.AudioContext))],Vt),function(t){t[t.GameLogic=0]="GameLogic",t[t.GamePhysics=1]="GamePhysics",t[t.GamePreRender=2]="GamePreRender",t[t.Physics=3]="Physics",t[t.PreGameLogic=4]="PreGameLogic",t[t.Render=5]="Render",t[t.Transform=6]="Transform"}(Nt||(Nt={}));const Wt=(t,e)=>{t.prototype.__system_group||(t.prototype.__system_group=e)};class zt{constructor(t){this.position=new e,this.scale=new e(1,1),this.rotation=0,this.ignoreParentPosition=!1,this.ignoreParentScale=!1,this.ignoreParentRotation=!1,this.localPosition=new e,this.localScale=new e(1,1),this.localRotation=0,this._awake=!1,this._parent=void 0,Object.assign(this,t)}}zt.componentName="Transform";const Ht="Default",Yt="Debug";class $t{constructor(t){this.layers=[Ht],this.zoom=1,this.depth=0,this.debug=!1,this._renderData={position:new e,depth:0,zoom:1,layers:[]},Object.assign(this,t)}}$t.componentName="Camera";class Xt{constructor(t){this.fixedToTimeScale=!1,this.layer=Ht,this.loop=!1,this.offset=new e,this.playing=!1,this.rotation=0,this.volume=1,this._currentVideoSrc=void 0,this._playPromisePendind=!1,this._renderData={type:lt.Video,height:void 0,layer:void 0,position:new e,video:void 0,width:void 0,flipHorizontal:void 0,flipVertical:void 0,maskColor:void 0,maskColorMix:void 0,opacity:void 0,rotation:void 0,slice:void 0,tintColor:void 0},Object.assign(this,t)}play(t){t&&(this.video=t),this.action="play"}pause(){this.action="pause"}stop(){this.action="stop"}}Xt.componentName="VideoRenderer";const qt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Kt=class{constructor(t,i,s,o,r){this.entityManager=t,this.renderManager=i,this.timeManager=s,this.assetManager=o,this.inputManager=r,this.scaledOffset=new e,this.canPlay=!0,this.userInputErrorCatched=!1,this.userInputEventHandler=()=>{qt.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0},document.addEventListener("visibilitychange",(()=>{this.entityManager.search(Xt,(({video:t,playing:e})=>{t&&"string"!=typeof t&&(document.hidden?t.pause():!document.hidden&&e&&t.play(),this.canPlay=!document.hidden)}))}))}catchUserInput(){this.canPlay=!1,this.userInputErrorCatched=!0,qt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(Xt,((t,i)=>{var s,o;const r=this.entityManager.getComponent(i,zt);if(!r)throw new Error("VideoRenderer component needs a Transform");if("string"==typeof t.video&&(t.video=this.assetManager.getVideo(t.video),!t.video))throw new Error(`Asset ${t.video} not found`);t.video&&t.video.duration&&(this.checkVideoState(t),this.scaledOffset.set(t.offset.x*r.localScale.x,t.offset.y*r.localScale.y),e.add(t._renderData.position,r.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.video=t.video,t._renderData.width=(null!==(s=t.width)&&void 0!==s?s:t.video.videoWidth)*Math.abs(r.localScale.x),t._renderData.height=(null!==(o=t.height)&&void 0!==o?o:t.video.videoHeight)*Math.abs(r.localScale.y),t._renderData.rotation=r.localRotation+t.rotation,t._renderData.slice=t.slice,t._renderData.flipHorizontal=t.flipHorizontally,t._renderData.flipVertical=t.flipVertically,t._renderData.opacity=t.opacity,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.tintColor=t.tintColor,0!==r.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,r),this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}checkVideoState(t){const{video:e,action:i,loop:s,volume:o}=t;"string"!=typeof e&&(e.src!==t._currentVideoSrc&&(t._currentVideoSrc=e.src,t.playing=!1,e.currentTime=0),e.loop=s,e.volume=o,e.playbackRate=t.fixedToTimeScale?this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16):1,"play"!==i||t.playing||t._playPromisePendind||!this.canPlay||(t._playPromisePendind=!0,e.play().then((()=>{t._playPromisePendind=!1,t.playing=!0})).catch((()=>{t._playPromisePendind=!1,this.userInputErrorCatched||this.catchUserInput()}))),"play"===i&&e.ended&&(t.action="stop",t.playing=!1),"stop"===i&&e.currentTime>0&&(e.pause(),e.currentTime=0,t.playing=!1),"pause"!==i||e.paused||e.pause())}onSceneDestroyed(){this.entityManager.search(Xt,(t=>{t.video&&"string"!=typeof t.video&&(t.video.pause(),t.video.currentTime=0,t.playing=!1)}),!0)}};Kt=Tt([l(kt.VideoRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.TimeManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.InputManager))],Kt),exports.SceneManager=class{constructor(t,e,i,s,o){this.systemManager=t,this.systemFactory=e,this.entityManager=i,this.assetManager=s,this.timeManager=o,this.scenes=new Map,this._loadingScene=!1,this._sceneLoadedThisFrame=!1,this.preserveEntitiesWithComponent=void 0}addScene(t,e,i=!1){const s=new t(this.entityManager,this.assetManager);this.scenes.set(e,s),i&&(this.openingSceneName=e)}loadScene(t,e){if(!this.scenes.has(t))throw new Error(`Invalid scene name: '${t}'`);this.sceneNameToBeLoaded=t,this.preserveEntitiesWithComponent=null==e?void 0:e.preserveEntitiesWithComponent}loadOpeningScene(t){if(!this.openingSceneName)throw new Error("There is no opening scene");this.loadScene(this.openingSceneName,t)}get loadingScene(){return this._loadingScene}get sceneLoadedThisFrame(){return this._sceneLoadedThisFrame}update(){if(this._sceneLoadedThisFrame=!1,this.sceneNameToBeLoaded){this.currentSceneName&&this.destroyCurrentScene(),this.currentSceneName=this.sceneNameToBeLoaded,this.sceneNameToBeLoaded=void 0;const t=this.scenes.get(this.currentSceneName);t.systems=[],t.loadAssets(),this._loadingScene=!0}if(this._loadingScene&&this.assetManager.getAssetsLoaded()){const t=this.scenes.get(this.currentSceneName);this._loadingScene=!1,this._sceneLoadedThisFrame=!0,t.setup(),this.systemManager.update(Nt.Transform),this.systemManager.update(Nt.PreGameLogic),t.systems.forEach(((t,e)=>{this.systemFactory.createSystemIfNotExists(t),this.systemManager.enableSystem(t),this.systemManager.setExecutionOrder(t,e);const i=this.systemManager.getSystem(t);"onSceneLoaded"in i&&"function"==typeof i.onSceneLoaded&&i.onSceneLoaded()}))}}destroyCurrentScene(){var t,e;this.currentSceneName&&(null===(t=this.systemManager.getSystem(Vt))||void 0===t||t.onSceneDestroyed(),null===(e=this.systemManager.getSystem(Kt))||void 0===e||e.onSceneDestroyed(),this._loadingScene||(this.scenes.get(this.currentSceneName).systems.forEach((t=>{const e=this.systemManager.getSystem(t);"onSceneDestroyed"in e&&"function"==typeof e.onSceneDestroyed&&e.onSceneDestroyed(),this.systemManager.disableSystem(t)})),this.entityManager.removeAllEntities({preserveEntitiesWithComponent:this.preserveEntitiesWithComponent}),this.timeManager.clearAllIntervals(),this.currentSceneName=void 0))}},exports.SceneManager=Tt([l(Et.SceneManager),Pt(0,c(Et.SystemManager)),Pt(1,c(Et.CreateSystemService)),Pt(2,c(Et.EntityManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.TimeManager))],exports.SceneManager);class Jt{constructor(t){this.width=0,this.height=0,this.radius=0,this.touchEnabled=!0,this.offset=new e,this.pressed=!1,this.mouseOver=!1,Object.assign(this,t)}}var Qt;Jt.componentName="Button",exports.ButtonShape=void 0,(Qt=exports.ButtonShape||(exports.ButtonShape={}))[Qt.Rectangle=0]="Rectangle",Qt[Qt.Circumference=1]="Circumference";let Zt=class{constructor(t,i){this.entityManager=t,this.scaled={position:new e,width:0,height:0,radius:0},this.distance=new e,this.pressedLastFrame=!1,this.mouse=i.mouse,this.touchScreen=i.touchScreen}onUpdate(){this.entityManager.search(Jt,((t,e)=>{const i=this.entityManager.getComponent(e,zt);if(!i)throw new Error("Button component needs a Transform");this.pressedLastFrame=t.pressed,t.pressed=!1,this.scale(t,i),t.mouseOver=this.isMouseOverButton(t),t.pressed=t.mouseOver&&this.mouse.leftButtonPressed,t.touchEnabled&&this.touchScreen.touching&&(this.resolveTouchAndRectangle(t),this.resolveTouchAndCircumference(t)),t.onClick&&!this.pressedLastFrame&&t.pressed&&t.onClick(),t.onPressed&&t.pressed&&t.onPressed()}))}scale(t,{localPosition:e,localScale:i}){this.scaled.width=t.width*i.x,this.scaled.height=t.height*i.y,this.scaled.position.x=e.x+t.offset.x*i.x,this.scaled.position.y=e.y+t.offset.y*i.y,this.scaled.radius=t.radius*Math.max(Math.abs(i.x),Math.abs(i.y))}isMouseOverButton(t){return this.isMouseOverRectangleButton(t)||this.isMouseOverCircumferenceButton(t)}isMouseOverRectangleButton(t){return t.shape===exports.ButtonShape.Rectangle&&(n(this.mouse.positionInViewport.x,this.scaled.position.x-this.scaled.width/2,this.scaled.position.x+this.scaled.width/2)&&n(this.mouse.positionInViewport.y,this.scaled.position.y-this.scaled.height/2,this.scaled.position.y+this.scaled.height/2))}isMouseOverCircumferenceButton(t){return t.shape===exports.ButtonShape.Circumference&&(e.subtract(this.distance,this.scaled.position,this.mouse.positionInViewport),this.distance.magnitude<=this.scaled.radius)}resolveTouchAndRectangle(t){if(t.shape===exports.ButtonShape.Rectangle)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;t.pressed=this.scaled.position.x+this.scaled.width/2>=e.x-i.x&&this.scaled.position.x-this.scaled.width/2<=e.x+i.x&&this.scaled.position.y+this.scaled.height/2>=e.y-i.y&&this.scaled.position.y-this.scaled.height/2<=e.y+i.y}}resolveTouchAndCircumference(t){if(t.shape===exports.ButtonShape.Circumference)for(const{positionInViewport:i,radius:s}of this.touchScreen.interactions){if(t.pressed)return;e.subtract(this.distance,this.scaled.position,i),t.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(s.x,s.y)}}};Zt=Tt([l(kt.ButtonSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.InputManager))],Zt);class te{constructor(t){this.objects=new Map,this._processed=!1,this._objectsCreated=!1,this._animationsMapped=!1,this._origin=new e,this._tilemap=void 0,this._tilesetsCreated=!1,Object.assign(this,t)}refresh(){this._processed=!1,this._animationsMapped=!1}}te.componentName="TiledWrapper";class ee{constructor(t){if(this.layer=Ht,this.tilesets=[],this.data=[],this.chunks=[],this.width=0,this.height=0,this.tileWidth=void 0,this.tileHeight=void 0,this.tintColor=void 0,this.opacity=1,this.smooth=!1,this.offset=new e,this._processed=!1,this._dataFromChunks=!1,this._renderData=[],t&&"tileset"in t)throw new Error("TilemapRenderer.tileset was replaced by TilemapRenderer.tilesets, which takes an array");Object.assign(this,t)}refresh(){this._dataFromChunks?this.data=[]:this.chunks=[],this.height=0,this._processed=!1}}ee.componentName="TilemapRenderer";class ie{constructor(t){var e,i;this.tiles=[],this.fps=12,this.currentFrame=0,this.currentTime=0,t&&(this.tiles=null!==(e=t.tiles)&&void 0!==e?e:this.tiles,this.fps=null!==(i=t.fps)&&void 0!==i?i:this.fps)}}const se=(t,e,i=0,s=0,o=!0,r=1)=>t.forEach((t=>{var n,a,h;const l=i+(null!==(n=t.offsetx)&&void 0!==n?n:0),c=s+(null!==(a=t.offsety)&&void 0!==a?a:0),d=o&&!1!==t.visible,g=r*(null!==(h=t.opacity)&&void 0!==h?h:1);"group"===t.type?se(t.layers,e,l,c,d,g):e(t,l,c,d,g)})),oe=(t,e)=>{if(!t||e.startsWith("/")||e.includes("://"))return e;const i=[];return`${t.slice(0,t.lastIndexOf("/")+1)}${e}`.split("/").forEach((t=>{"."!==t&&(".."===t&&i.length>0&&".."!==i[i.length-1]?i.pop():i.push(t))})),i.join("/")};let re=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(te,((t,e)=>{var i;!t._objectsCreated&&(null===(i=t.objects)||void 0===i?void 0:i.size)>0&&t._tilemap&&(this.createObjects(t,t._tilemap,e),t._objectsCreated=!0)}))}createObjects(t,i,s){const o=this.collectObjects(t,i),r=new Map(o.map((({object:t})=>[t.id,this.entityManager.createEntity()]))),n=this.entityManager.getComponent(s,zt),a=n?n.position:new e,h=this.getBounds(i,s);o.forEach((e=>{var s;const{object:o}=e,n=t.objects.get(ne(o)),l=r.get(o.id),c="function"==typeof n?n(this.mapProperties(o,r),o):n;if(!c)throw new Error(`The blueprint for the Tiled object class ${ne(o)} returned nothing`);const d=Array.isArray(c)?{components:c}:c;this.entityManager.addArchetype(l,d);const g=null!==(s=this.entityManager.getComponent(l,zt))&&void 0!==s?s:this.entityManager.addComponent(l,zt);ae(g,i,e,a,t._origin,h)}))}getBounds(t,e){var i;const{width:s,height:o,tileWidth:r,tileHeight:n,_processed:a}=null!==(i=this.entityManager.getComponent(e,ee))&&void 0!==i?i:{};return a&&s>0&&o>0?{width:s,height:o,tileWidth:r,tileHeight:n}:{width:t.width,height:t.height,tileWidth:t.tilewidth,tileHeight:t.tileheight}}collectObjects(t,e){const i=[];return se(e.layers,((e,s,o,r)=>{"objectgroup"===e.type&&r&&e.objects.forEach((e=>{!1!==e.visible&&t.objects.has(ne(e))&&i.push({object:e,offsetX:s,offsetY:o})}))})),i}mapProperties(t,e){const i=new Map;return t.properties&&t.properties.forEach((({name:t,type:s,value:o})=>i.set(t,"object"===s?e.get(o):o))),i}};re=Tt([l(kt.TiledObjectSystem),Pt(0,c(Et.EntityManager))],re);const ne=t=>{var e;return null!==(e=t.class)&&void 0!==e?e:t.type},ae=(t,e,{object:i,offsetX:s,offsetY:o},r,n,{width:h,height:l,tileWidth:c,tileHeight:d})=>{var g;const p=i.width/2,u=void 0!==i.gid?-i.height/2:i.height/2,m=a(null!==(g=i.rotation)&&void 0!==g?g:0),f=Math.cos(m),y=Math.sin(m),x=(i.x+s+p*f-u*y)/e.tilewidth-n.x,M=(i.y+o+p*y+u*f)/e.tileheight-n.y;t.position.set(r.x+(x-h/2)*c,r.y+(l/2-M)*d),0!==m&&(t.rotation=-m)};let he=class{constructor(t,e){this.entityManager=t,this.assetManager=e,this.requestedTilemaps=new Set}onUpdate(){this.entityManager.search(te,((t,e)=>{if(t._processed&&t._animationsMapped)return;const i=this.resolveTilemap(t);if(!i)return;const s=this.entityManager.getComponent(e,ee);t._processed||(s&&(this.resolveTilesets(t,i,s),this.renderLayer(t,i,s)),t._processed=!0),t._animationsMapped||(i.tilesets&&(null==s?void 0:s.tilesets.length)>0&&this.mapAnimations(i,s.tilesets),t._animationsMapped=!0)}))}resolveTilemap(t){if(!t.tilemapPath)return;const e=this.assetManager.getJson(t.tilemapPath);if(e)return this.requestedTilemaps.delete(t.tilemapPath),t._tilemap=e,e;this.requestedTilemaps.has(t.tilemapPath)||(this.requestedTilemaps.add(t.tilemapPath),this.assetManager.loadJson(t.tilemapPath))}resolveTilesets(t,e,i){var s;if(i.tilesets.length>0&&!t._tilesetsCreated)i.tilesets.forEach(((t,i)=>{var s,o,r,n;t.firstgid=null!==(n=null!==(s=t.firstgid)&&void 0!==s?s:null===(r=null===(o=e.tilesets)||void 0===o?void 0:o[i])||void 0===r?void 0:r.firstgid)&&void 0!==n?n:1}));else{if(!((null===(s=e.tilesets)||void 0===s?void 0:s.length)>0))throw new Error(`The tilemap ${t.tilemapPath} has no embedded tilesets. Export it from Tiled with its tilesets embedded, or declare the tilesets of the TilemapRenderer`);i.tilesets=e.tilesets.map((e=>this.createTileset(e,t.tilemapPath))),t._tilesetsCreated=!0}}createTileset({firstgid:t,name:e,source:i,image:s,tilewidth:o,tileheight:r,margin:n,spacing:a,tilecount:h},l){if(!s)throw new Error(`The tileset ${null!=e?e:i} is not embedded in the tilemap, the engine does not read external tilesets. Export the tilemap with its tilesets embedded, or declare the tilesets of the TilemapRenderer`);return{image:oe(l,s),tileWidth:o,tileHeight:r,margin:n,spacing:a,firstgid:t,tileCount:h}}renderLayer(t,e,i){var s,o,r,n;let a,h,l;if(se(e.layers,((e,s,o,r,n)=>{a||"tilelayer"!==e.type||e.name!==t.layerToRender||(a=e,h=r,l=n,i.offset.set(s,-o))})),a){var c;if(i.opacity=l,a.tintcolor&&(i.tintColor=9===(c=a.tintcolor).length?`#${c.slice(3)}`:c),i.tileWidth=null!==(s=i.tileWidth)&&void 0!==s?s:e.tilewidth,i.tileHeight=null!==(o=i.tileHeight)&&void 0!==o?o:e.tileheight,!h)return i.data=[],i.chunks=[],i.width=0,void(i.height=0);if(e.infinite){const e=null!==(r=a.startx)&&void 0!==r?r:0,s=null!==(n=a.starty)&&void 0!==n?n:0;i.chunks=a.chunks.map((t=>Object.assign(Object.assign({},t),{x:t.x-e,y:t.y-s}))),i.width=a.width,i.height=a.height,t._origin.set(e,s)}else i.data=a.data,i.width=e.width,i.height=e.height,t._origin.set(0,0)}}mapAnimations(t,e){t.tilesets.forEach((({firstgid:t,tiles:i})=>{if(!i)return;const s=e.find((e=>e.firstgid===t));s&&i.forEach((({id:e,animation:i})=>{var o;if(!i||0===i.length)return;const r=t+e;(null===(o=s.animations)||void 0===o?void 0:o.has(r))||(s.animations||(s.animations=new Map),s.animations.set(r,new ie({tiles:i.map((({tileid:e})=>t+e)),fps:1e3*i.length/i.reduce(((t,{duration:e})=>t+e),0)})))}))}))}};he=Tt([l(kt.TiledWrapperSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.AssetManager))],he);const le=16;let ce=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(ee,(t=>{var e,i,s,o;t._processed||(t.chunks&&t.chunks.length>0?(t._dataFromChunks=!0,this.chunksToData(t)):t.data&&t.data.length>0&&(t._dataFromChunks=!1,this.dataToChunks(t)),t.tileWidth=null!==(e=t.tileWidth)&&void 0!==e?e:null===(i=t.tilesets[0])||void 0===i?void 0:i.tileWidth,t.tileHeight=null!==(s=t.tileHeight)&&void 0!==s?s:null===(o=t.tilesets[0])||void 0===o?void 0:o.tileHeight,t._processed=!0)}))}dataToChunks(t){t.height=t.height||Math.ceil(t.data.length/t.width);const e=Math.ceil(t.width/le),i=Math.ceil(t.height/le);for(let s=0;s<i;s++)for(let i=0;i<e;i++){const e={x:i*le,y:s*le,width:le,height:le,data:[]};for(let i=0;i<e.width*e.height;i++){const s=e.x+i%e.width,o=t.width*(e.y+Math.floor(i/e.width));e.data[i]=s<t.width&&o<t.height*t.width?t.data[o+s]:0}t.chunks.push(e)}}chunksToData(t){t.data=[],t.chunks.forEach((e=>e.data.forEach(((i,s)=>{t.data[t.width*(e.y+Math.floor(s/e.width))+e.x+s%e.width]=i})))),t.height=t.height||Math.ceil(t.data.length/t.width)}};ce=Tt([l(kt.TilemapPreProcessingSystem),Pt(0,c(Et.EntityManager))],ce);let de=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(zt).sort(((t,e)=>this.getBranchLength(t.entity)-this.getBranchLength(e.entity))).forEach((({component:t,entity:i})=>{const s=this.entityManager.getParent(i);s&&this.entityManager.isEntityEnabled(s)&&this.entityManager.isComponentEnabled(s,zt)?(t._parent||(t._parent=this.entityManager.getComponent(s,zt),t._awake&&!t.ignoreParentPosition&&e.subtract(t.position,t.localPosition,t._parent.position)),t._parent?this.translateChild(t):this.updateTransform(t)):(t._parent&&this.removeParent(t),this.updateTransform(t)),t._awake=!0}))}getBranchLength(t){const e=this.entityManager.getParent(t);return e?1+this.getBranchLength(e):0}removeParent(t){t._parent=void 0,t.position.copy(t.localPosition),t.rotation=t.localRotation}updateTransform(t){t.localPosition.copy(t.position),t.localScale.copy(t.scale),t.localRotation=t.rotation,t._parent=void 0}translateChild(t){t.localRotation=t.rotation+(t.ignoreParentRotation?0:t._parent.localRotation),t.localScale.x=t.scale.x*(t.ignoreParentScale?1:t._parent.scale.x),t.localScale.y=t.scale.y*(t.ignoreParentScale?1:t._parent.scale.y);const e=t.position.magnitude,i=Math.atan2(t.position.y,t.position.x)+(t.ignoreParentRotation?0:t._parent.localRotation);t.localPosition.set(e*Math.cos(i)+(t.ignoreParentPosition?0:t._parent.localPosition.x),e*Math.sin(i)+(t.ignoreParentPosition?0:t._parent.localPosition.y))}};de=Tt([l(kt.TransformSystem),Pt(0,c(Et.EntityManager))],de);let ge=class{constructor(t){this.inputManager=t,this.gamepads=new Map,this.eventHandler=t=>{"gamepadconnected"===t.type?this.gamepadConnected(t.gamepad):"gamepaddisconnected"===t.type&&this.gamepadDisconected(t.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}gamepadConnected(t){this.gamepads.set(t.index,t),this.inputManager.gamepads[t.index]||(this.inputManager.gamepads[t.index]=new Dt,this.inputManager.gamepads[t.index].index=t.index),this.inputManager.gamepads[t.index].id=t.id,this.inputManager.gamepads[t.index].connected=!0}gamepadDisconected(t){this.gamepads.delete(t.index),this.inputManager.gamepads[t.index].connected=!1}onUpdate(){for(const t of this.getGamepadsFromBrowser())t&&(!1===this.gamepads.has(t.index)?this.gamepadConnected(t):this.gamepads.set(t.index,t));this.gamepads.forEach((t=>{const e=this.inputManager.gamepads[t.index];t.buttons.forEach(((t,i)=>e.buttons.set(i,t.pressed))),t.axes.forEach(((t,i)=>e.axes.set(i,t))),e.vibrationInput&&(t.vibrationActuator.playEffect(t.vibrationActuator.type,{duration:e.vibrationInput.duration,weakMagnitude:e.vibrationInput.weakMagnitude,strongMagnitude:e.vibrationInput.strongMagnitude,startDelay:e.vibrationInput.startDelay}).catch((()=>e.vibrating=!1)).finally((()=>e.vibrating=!1)),e.vibrating=!0,e.vibrationInput=void 0)}))}getGamepadsFromBrowser(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]}};ge=Tt([l(kt.GamepadSystem),Pt(0,c(Et.InputManager))],ge);let pe=class{constructor(t,{keyboard:e}){this.pressedKeys=new Set,this.eventHandler=t=>{"keydown"!==t.type||this.pressedKeys.has(t.code)||this.pressedKeys.add(t.code),"keyup"===t.type&&this.pressedKeys.has(t.code)&&this.pressedKeys.delete(t.code)},this.keyboard=e,t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler),t.addEventListener("focusout",(()=>this.pressedKeys.clear()))}onUpdate(){this.keyboard.pressedKeys=[...this.pressedKeys]}};pe=Tt([l(kt.KeyboardSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],pe);let ue=class{constructor(t,{mouse:i}){this.canvas=t,this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new e,this.lastPositionInViewport=new e,this.mouse=i,this.canvas.addEventListener("mousemove",(t=>this.updatePosition(t))),this.canvas.addEventListener("mousedown",(t=>this.updateButtonDown(t))),this.canvas.addEventListener("mouseup",(t=>this.updateButtonUp(t))),this.canvas.addEventListener("wheel",(t=>this.handleWheelEvent(t))),this.canvas.addEventListener("focusout",(()=>this.onFocusOut()))}updateButtonDown(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0===t.button||this.leftButtonPressed,this.scrollButtonPressed=1===t.button||this.scrollButtonPressed,this.rightButtonPressed=2===t.button||this.rightButtonPressed}updateButtonUp(t){t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0!==t.button&&this.leftButtonPressed,this.scrollButtonPressed=1!==t.button&&this.scrollButtonPressed,this.rightButtonPressed=2!==t.button&&this.rightButtonPressed}updatePosition(t){t.preventDefault(),t.stopPropagation(),this.positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)}handleWheelEvent(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t}onFocusOut(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1}onUpdate(){this.mouse.leftButtonPressed=this.leftButtonPressed,this.mouse.rightButtonPressed=this.rightButtonPressed,this.mouse.scrollButtonPressed=this.scrollButtonPressed,this.mouse.positionInViewport.copy(this.positionInViewport),this.positionInViewport.equals(this.lastPositionInViewport)?this.mouse.hasMoved=!1:(this.mouse.hasMoved=!0,this.lastPositionInViewport.copy(this.positionInViewport)),this.wheelEvent?(this.mouse.wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this.mouse.wheelScroll.set(0,0)}};ue=Tt([l(kt.MouseSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],ue);let me=class{constructor(t,{touchScreen:e}){this.canvas=t,this.touching=!1,this.interactions=[],this.eventHandler=t=>{"touchstart"===t.type&&(this.touching=!0,this.updatePosition(t)),"touchmove"===t.type&&this.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(this.touching=!1)},this.touchScreen=e,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}updatePosition(t){if(t.preventDefault(),t.stopPropagation(),this.interactions=[],0!==t.targetTouches.length)for(let i=0;i<t.targetTouches.length;i++)this.interactions[i]={positionInViewport:new e((t.targetTouches[i].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[i].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new e(t.targetTouches[i].radiusX,t.targetTouches[i].radiusY)}}onUpdate(){this.touchScreen.touching=this.touching,this.touchScreen.interactions=this.touching?[...this.interactions]:[]}};me=Tt([l(kt.TouchScreenSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],me);class fe{constructor(t){this.animations=new Map,this.speed=1,this.reset=!1,this.playing=!1,this.currentFrame=0,this.currentTime=0,this.ignoreTimeScale=!1,this._currentAnimation=void 0,this._assetsReady=!1,Object.assign(this,t)}play(t){void 0!==t&&t!==this.animation&&(this.animation=t,this.reset=!0),this.playing=!0}pause(){this.playing=!1}stop(){this.playing=!1,this.currentFrame=0,this.currentTime=0}}fe.componentName="Animator";class ye{constructor(t){this.layer=Ht,this.smooth=!1,this.offset=new e,this.flipHorizontally=!1,this.flipVertically=!1,this.rotation=0,this.opacity=1,this.scale=new e(1,1),this._renderData={type:lt.Sprite,position:new e,layer:void 0,image:void 0,width:void 0,height:void 0},Object.assign(this,t)}}ye.componentName="SpriteRenderer";let xe=class{constructor(t,e,i){this.entityManager=t,this.timeManager=e,this.assetManager=i}onUpdate(){this.entityManager.search(fe,((t,e)=>{if(this.processAssets(t),this.reset(t),this.animation=t.animations.get(t.animation),!this.animation)return;this.play(t),t._currentAnimation=t.animation;const i=this.entityManager.getComponent(e,ye);i&&this.renderSprite(t,i)}))}processAssets(t){t._assetsReady||(t.animations.forEach((t=>{if("string"==typeof t.image){if(t.image=this.assetManager.getImage(t.image),!t.image)throw new Error(`Asset ${t.image} not found`)}else Array.isArray(t.image)&&(t.image=t.image.map((t=>{if("string"==typeof t){const e=this.assetManager.getImage(t);if(!e)throw new Error(`Asset ${t} not found`);return e}return t})))})),t._assetsReady=!0)}reset(t){t.reset&&(t.currentFrame=0,t.currentTime=0,t.playing=void 0!==t.animation,t.reset=!1)}play(t){t.animation!==t._currentAnimation&&(t._currentAnimation=t.animation,t.currentFrame=0,t.currentTime=0,t.playing=!0),t.playing&&(t.currentTime>=1/this.animation.fps*(t.currentFrame+1)&&(t.currentFrame===this.animation.frames.length-1?this.animation.loop?(t.currentFrame=0,t.currentTime=0):t.playing=!1:t.currentFrame++),t.currentTime+=(t.ignoreTimeScale?this.timeManager.unscaledRenderDeltaTime:this.timeManager.renderDeltaTime)*t.speed)}renderSprite(t,e){if(Array.isArray(this.animation.image))e.image=this.animation.image[t.currentFrame];else{if("string"==typeof this.animation.image)return;const i=this.animation.frames[t.currentFrame],s=Math.ceil(this.animation.image.naturalWidth/this.animation.slice.size.x);e.image=this.animation.image,e.slice={x:i%s*this.animation.slice.size.x+this.animation.slice.offset.x,y:Math.floor(i/s)*this.animation.slice.size.y+this.animation.slice.offset.y,width:this.animation.slice.size.x-this.animation.slice.padding.y,height:this.animation.slice.size.y-this.animation.slice.padding.y}}}};xe=Tt([l(kt.AnimatorSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager)),Pt(2,c(Et.AssetManager))],xe);let Me=class{constructor(t,e){this.entityManager=t,this.timeManager=e,this.tilesets=new Set}onUpdate(){this.tilesets.clear(),this.entityManager.search(ee,(t=>{t.tilesets.forEach((t=>this.tilesets.add(t)))})),this.tilesets.forEach((t=>this.updateTileset(t)))}updateTileset(t){var e;t.animations&&0!==t.animations.size?(t._animationState||(t._animationState=new Map),t._animationState.forEach(((e,i)=>{t.animations.has(i)||t._animationState.delete(i)})),t.animations.forEach(((e,i)=>{this.advance(e),t._animationState.set(i,e.tiles[e.currentFrame])}))):null===(e=t._animationState)||void 0===e||e.clear()}advance(t){0!==t.tiles.length&&(t.currentTime>=1/t.fps*(t.currentFrame+1)&&(t.currentFrame===t.tiles.length-1?(t.currentFrame=0,t.currentTime=0):t.currentFrame++),t.currentTime+=this.timeManager.renderDeltaTime)}};Me=Tt([l(kt.TilemapAnimationSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager))],Me);let ve=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search($t,((t,e)=>{const i=this.entityManager.getComponent(e,zt);if(!i)throw new Error("Camera component needs a Transform");t._renderData.position.copy(i.localPosition),t._renderData.layers=[...t.layers],t._renderData.depth=t.depth,t._renderData.zoom=t.zoom,t.debug&&t._renderData.layers.push(Yt),this.renderManager.addCameraData(t._renderData)}))}};ve=Tt([l(kt.CameraSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],ve);let Ce=class{constructor(t,e){this.webGLManager=t,this.gameConfig=e}onUpdate(){this.webGLManager.renderCanvasColor(this.gameConfig.canvasColor)}};Ce=Tt([l(kt.ClearScreenSystem),Pt(0,c(Et.WebGLManager)),Pt(1,c(Et.GameConfig))],Ce);class be{constructor(t){this.radius=0,this.offset=new e,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}be.componentName="BallCollider";class Se{constructor(t){this.layer="",this.physics=!0,this.width=0,this.height=0,this.offset=new e,this.rotation=0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}Se.componentName="BoxCollider";class we{constructor(t){this.vertexModel=[],this.offset=new e,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}we.componentName="EdgeCollider";class Ae{constructor(t){this.vertexModel=[],this.offset=new e,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}Ae.componentName="PolygonCollider";class Re{constructor(t){this.composite=!0,this.layer="",this.ignoreCollisionsWithLayers=[],this.offset=new e,this.physics=!0,this.shapes=[],Object.assign(this,t)}refresh(){this.shapes=[]}}Re.componentName="TilemapCollider";let _e=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.colliders)&&[be,Se,Ae,we,Re].forEach((t=>this.entityManager.search(t,(t=>t.shapes.forEach((t=>{const i={type:lt.Geometric,position:new e,layer:Yt,color:this.gameConfig.debug.collidersColor,shape:void 0,radius:void 0,rotation:void 0,vertexModel:void 0};t instanceof M?this.gameConfig.collisions.collisionMethod===exports.CollisionMethods.SAT?(i.shape=t.vertices.length>2?exports.GeometricShape.Polygon:exports.GeometricShape.Line,i.vertexModel=t.vertices):this.gameConfig.collisions.collisionMethod===exports.CollisionMethods.AABB&&(i.shape=exports.GeometricShape.Polygon,i.vertexModel=[new e(t.boundingBox.x,t.boundingBox.y),new e(t.boundingBox.x,t.boundingBox.y1),new e(t.boundingBox.x1,t.boundingBox.y1),new e(t.boundingBox.x1,t.boundingBox.y)]):t instanceof v&&(i.shape=exports.GeometricShape.Circumference,i.position.copy(t.position),i.radius=t.radius),this.renderManager.addRenderData(i)}))))))}};_e=Tt([l(kt.DebugColliderRenderSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],_e);let Ee=class{constructor(t,e){this.renderManager=t,this.canvas=e,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0},this.culledRenderData=[]}onUpdate(){this.culledRenderData=[],this.renderManager.getCameraData().forEach((t=>{this.setViewport(t),this.renderManager.getRenderData().filter((e=>t.layers.includes(e.layer))).forEach((t=>{this.isInViewPort(t)&&(t.type===lt.Tilemap&&this.applyCullingInTiles(t),this.culledRenderData.push(t))}))})),this.renderManager.setRenderData(this.culledRenderData)}isInViewPort(t){switch(t.type){case lt.Video:case lt.Darkness:case lt.Sprite:this.setObjectForResizeable(t);break;case lt.Mask:this.setObjectForMask(t);break;case lt.Geometric:this.setObjectForGeometric(t);break;case lt.Text:this.setObjectForText(t);break;case lt.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1}setViewport({position:t,zoom:e}){this.viewport.x=t.x-this.canvas.width/e/2,this.viewport.x1=t.x+this.canvas.width/e/2,this.viewport.y=t.y-this.canvas.height/e/2,this.viewport.y1=t.y+this.canvas.height/e/2}setObjectForResizeable({position:t,width:e,height:i,rotation:s=0,tiled:o}){const r=Math.abs(Math.sin(s)),n=Math.abs(Math.cos(s));o&&(e*=o.x,i*=o.y);const a=r*i+n*e,h=r*e+n*i;this.object.x=t.x-a/2,this.object.x1=t.x+a/2,this.object.y=t.y-h/2,this.object.y1=t.y+h/2}setObjectForText({position:t,text:e,fontSize:i,lineHeight:s,letterSpacing:o,rotation:r}){const n=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=o?o:0))*2,a=e.split("\n").length*(null!=s?s:i);this.setObjectForResizeable({position:t,width:n,height:a,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:s}){i===exports.GeometricShape.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForMask({position:t,vertices:e,shape:i,radius:s,rotation:o,width:r,height:n}){i===exports.MaskShape.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):i===exports.MaskShape.Polygon?(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)}))):this.setObjectForResizeable({position:t,width:r,height:n,rotation:o})}setObjectForTilemap(t){this.setObjectForResizeable({position:t.position,width:t.tilemap.realWidth,height:t.tilemap.realHeight,rotation:t.rotation})}applyCullingInTiles(t){const{tiles:e,tilemap:{width:i,tileWidth:s,tileHeight:o}}=t;t.tiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*s&&this.viewport.x<=this.object.x+e%i*s+s&&this.viewport.y1>=this.object.y1-((e/i|0)*o+o)&&this.viewport.y<=this.object.y1-(e/i|0)*o?t:0))}};Ee=Tt([l(kt.CullingSystem),Pt(0,c(Et.RenderManager)),Pt(1,c(Et.CanvasElement))],Ee);class Te{constructor(t){this.width=0,this.height=0,this.radius=0,this.vertexModel=[],this.color="#000000",this.offset=new e,this.rotation=0,this.opacity=1,this.layer=Ht,this._renderData={type:lt.Mask,color:void 0,height:void 0,vertices:[],layer:void 0,opacity:void 0,position:new e,radius:void 0,rotation:void 0,shape:void 0,width:void 0},Object.assign(this,t)}}Te.componentName="MaskRenderer";let Pe=class{constructor(t,i){this.entityManager=t,this.renderManager=i,this.scaledOffset=new e}onUpdate(){this.entityManager.search(Te,((t,i)=>{const s=this.entityManager.getComponent(i,zt);if(!s)throw new Error("MaskRenderer component needs a Transform");this.scaledOffset.set(t.offset.x*s.localScale.x,t.offset.y*s.localScale.y),e.add(t._renderData.position,s.localPosition,this.scaledOffset),t._renderData.width=t.width*Math.abs(s.localScale.x),t._renderData.height=t.height*Math.abs(s.localScale.y),t._renderData.rotation=s.localRotation+t.rotation,t._renderData.color=t.color,t._renderData.layer=t.layer,t._renderData.opacity=t.opacity,t._renderData.radius=t.radius*Math.max(Math.abs(s.localScale.x),Math.abs(s.localScale.y)),t._renderData.shape=t.shape,t.shape===exports.MaskShape.Polygon&&(t._renderData.vertices.length!==t.vertexModel.length&&(t._renderData.vertices=t.vertexModel.map((()=>new e))),t.vertexModel.forEach(((e,i)=>t._renderData.vertices[i].set(e.x*s.localScale.x,e.y*s.localScale.y))),0!==s.localRotation&&t._renderData.vertices.forEach((t=>t.set(t.x*Math.cos(s.localRotation)-t.y*Math.sin(s.localRotation),t.x*Math.sin(s.localRotation)+t.y*Math.cos(s.localRotation))))),0!==s.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,s),this.renderManager.addRenderData(t._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Pe=Tt([l(kt.MaskRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],Pe);let Be=class{constructor(t){this.renderManager=t}onUpdate(){this.renderManager.render(),this.renderManager.removeCameraData(),this.renderManager.removeRenderData()}};Be=Tt([l(kt.RenderSystem),Pt(0,c(Et.RenderManager))],Be);class De{constructor(t){this.radius=0,this.smooth=!1,this.layer=Ht,this.intensity=1,this._boundingBox=new i,Object.assign(this,t)}}De.componentName="LightRenderer";class Fe{constructor(t){this.width=0,this.height=0,this.color="#000000",this.opacity=1,this.layer=Ht,this._boundingBox=new i,this._renderData={type:lt.Darkness,layer:void 0,color:void 0,opacity:void 0,width:void 0,height:void 0,position:void 0,rotation:void 0,lights:[]},Object.assign(this,t)}}Fe.componentName="DarknessRenderer";let je=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){const t=this.entityManager.search(De);t.forEach((({entity:t,component:e})=>this.updateLightRendererBoundingBox(t,e))),this.entityManager.search(Fe,((e,i)=>{this.updatDarknessRendererBoundingBox(i,e),e._renderData.layer=e.layer,e._renderData.color=e.color,e._renderData.opacity=e.opacity,e._renderData.width=e._boundingBox.width,e._renderData.height=e._boundingBox.height,e._renderData.position=e._boundingBox.center,e._renderData.rotation=0,e._renderData.lights=[],e._renderData.lights=t.filter((({component:t})=>t.layer===e.layer&&t._boundingBox.intersects(e._boundingBox))).map((({component:{_boundingBox:t,smooth:e,intensity:i}})=>({position:t.center,radius:t.width/2,smooth:e,intensity:i}))),this.renderManager.addRenderData(e._renderData)}))}updateLightRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,zt);if(!i)throw new Error("LightRenderer component needs a Transform");const s=e.radius*Math.abs(Math.max(i.localScale.x,i.localScale.y));e._boundingBox.set(i.localPosition.x-s,i.localPosition.y-s,2*s,2*s)}updatDarknessRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,zt);if(!i)throw new Error("DarknessRenderer component needs a Transform");const s=e.width*Math.abs(i.localScale.x),o=e.height*Math.abs(i.localScale.y);e._boundingBox.set(i.localPosition.x-s/2,i.localPosition.y-o/2,s,o)}};je=Tt([l(kt.DarknessLightRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],je);class Ue{constructor(t){this.shape=exports.GeometricShape.Polygon,this.color="#FFFFFF",this.layer=Ht,this.vertexModel=[],this.radius=0,this.offset=new e,this.rotation=0,this._renderData={type:lt.Geometric,position:new e,layer:Ht,color:"#FFFFFF",shape:exports.GeometricShape.Polygon,vertexModel:[],rotation:0,radius:0},Object.assign(this,t)}}Ue.componentName="GeometricRenderer";let Ie=class{constructor(t,i){this.entityManager=t,this.renderManager=i,this.scaledOffset=new e}onUpdate(){this.entityManager.search(Ue,((t,i)=>{const s=this.entityManager.getComponent(i,zt);if(!s)throw new Error("GeometricRenderer component needs a Transform");if(!this.isValidGeometry(t))return;this.scaledOffset.set(t.offset.x*s.localScale.x,t.offset.y*s.localScale.y),e.add(t._renderData.position,s.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.color=t.color,t._renderData.shape=t.shape,t._renderData.rotation=s.localRotation+t.rotation,0!==s.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,s);const o=s.localScale.x,r=s.localScale.y;t.shape===exports.GeometricShape.Circumference?(t._renderData.radius=t.radius*Math.max(Math.abs(o),Math.abs(r)),t._renderData.vertexModel.length=0):(this.ensureVertexModelLength(t,t.vertexModel.length),t.vertexModel.forEach(((e,i)=>t._renderData.vertexModel[i].set(e.x*o,e.y*r)))),this.renderManager.addRenderData(t._renderData)}))}isValidGeometry(t){switch(t.shape){case exports.GeometricShape.Circumference:return t.radius>0;case exports.GeometricShape.Polygon:return t.vertexModel.length>=3;case exports.GeometricShape.Line:return t.vertexModel.length>=2&&t.vertexModel.length%2==0;default:return!1}}ensureVertexModelLength(t,i){const s=t._renderData.vertexModel;for(;s.length<i;)s.push(new e);s.length=i}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Ie=Tt([l(kt.GeometricRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],Ie);let Le=class{constructor(t,i,s){this.entityManager=t,this.renderManager=i,this.assetManager=s,this.scaledOffset=new e}onUpdate(){this.entityManager.search(ye,((t,i)=>{var s,o,r,n,a,h;const l=this.entityManager.getComponent(i,zt);if(!l)throw new Error("SpriteRenderer component needs a Transform");if("string"==typeof t.image&&(t.image=this.assetManager.getImage(t.image),!t.image))throw new Error(`Asset ${t.image} not found`);t.image&&t.image.complete&&(this.scaledOffset.set(t.offset.x*l.localScale.x,t.offset.y*l.localScale.y),e.add(t._renderData.position,l.localPosition,this.scaledOffset),t._renderData.width=(null!==(r=null!==(s=t.width)&&void 0!==s?s:null===(o=t.slice)||void 0===o?void 0:o.width)&&void 0!==r?r:t.image.naturalWidth)*Math.abs(t.scale.x*l.localScale.x),t._renderData.height=(null!==(h=null!==(n=t.height)&&void 0!==n?n:null===(a=t.slice)||void 0===a?void 0:a.height)&&void 0!==h?h:t.image.naturalHeight)*Math.abs(t.scale.y*l.localScale.y),t._renderData.flipHorizontally=t.flipHorizontally!==l.scale.x<0,t._renderData.flipVertically=t.flipVertically!==l.scale.y<0,t._renderData.rotation=l.localRotation+t.rotation,0!==l.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,l),t._renderData.image=t.image,t._renderData.layer=t.layer,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.opacity=t.opacity,t._renderData.slice=t.slice,t._renderData.smooth=t.smooth,t._renderData.tintColor=t.tintColor,t._renderData.tiled=t.tiled,this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Le=Tt([l(kt.SpriteRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Le);const Oe={charRanges:[32,132,161,255],fontSize:64,spacing:8};class ke{constructor(t){this.color="#000000",this.flipHorizontally=!1,this.flipVertically=!1,this.font="Arial",this.fontSize=16,this.height=16,this.layer=Ht,this.letterSpacing=0,this.lineHeight=void 0,this.offset=new e,this.opacity=1,this.alignment=exports.TextAlignment.Center,this.rotation=0,this.shadow=void 0,this.smooth=!1,this.text="Hello World!",this.textureAtlas=Object.assign({},Oe),this.width=192,this._renderData={color:void 0,flipHorizontally:!1,flipVertically:!1,font:void 0,fontSize:void 0,layer:void 0,letterSpacing:void 0,lineHeight:void 0,opacity:void 0,position:new e,rotation:void 0,shadow:void 0,smooth:void 0,text:void 0,textureAtlas:Object.assign({},Oe),type:lt.Text,boundingBox:{width:0,height:0},alignment:void 0},Object.assign(this,t)}}ke.componentName="TextRenderer";let Ge=class{constructor(t,i,s){this.entityManager=t,this.renderManager=i,this.assetManager=s,this.scaledOffset=new e}onUpdate(){this.entityManager.search(ke,((t,i)=>{var s;const o=this.entityManager.getComponent(i,zt);if(!o)throw new Error("TextRenderer component needs a Transform");if("string"==typeof t.font){const e=this.assetManager.getFont(t.font);e&&(t.font=e)}if(0===t.text.length||t.font instanceof FontFace&&"loaded"!==t.font.status)return;this.scaledOffset.set(t.offset.x*o.localScale.x,t.offset.y*o.localScale.y),e.add(t._renderData.position,o.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.font=t.font,t._renderData.fontSize=t.fontSize,t._renderData.text=t.text,t._renderData.color=t.color,t._renderData.lineHeight=null!==(s=t.lineHeight)&&void 0!==s?s:t.fontSize,t._renderData.letterSpacing=t.letterSpacing,t._renderData.smooth=t.smooth,t._renderData.rotation=o.localRotation+t.rotation,t._renderData.opacity=t.opacity,t._renderData.boundingBox={width:t.width,height:t.height},t._renderData.alignment=t.alignment;const{charRanges:r,fontSize:n,spacing:a}=t.textureAtlas;r&&(t._renderData.textureAtlas.charRanges=t.textureAtlas.charRanges),n&&(t._renderData.textureAtlas.fontSize=t.textureAtlas.fontSize),a&&(t._renderData.textureAtlas.spacing=t.textureAtlas.spacing),t._renderData.flipHorizontally=t.flipHorizontally,t._renderData.flipVertically=t.flipVertically,t._renderData.shadow=t.shadow,0!==o.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,o),this.renderManager.addRenderData(t._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Ge=Tt([l(kt.TextRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Ge);let Ve=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.assetManager=i}onUpdate(){this.entityManager.search(ee,((t,e)=>{const i=this.entityManager.getComponent(e,zt);if(!i)throw new Error("TilemapRenderer component needs a Transform");t.tilesets.forEach((t=>{if("string"==typeof t.image){const e=this.assetManager.getImage(t.image);if(!e)throw new Error(`Asset ${t.image} not found`);t.image=e}})),t._processed&&t.tilesets.forEach(((e,s)=>{e.image&&e.image.complete&&t.chunks.forEach(((o,r)=>{const n=s*t.chunks.length+r;t._renderData[n]||(t._renderData[n]=Ne());const a=t._renderData[n];a.type=lt.Tilemap,a.orientation=exports.TilemapOrientation.Center,a.layer=t.layer,a.tilemap.width=o.width,a.tilemap.height=o.height,a.tilemap.tileWidth=t.tileWidth*Math.abs(i.localScale.x),a.tilemap.tileHeight=t.tileHeight*Math.abs(i.localScale.y),a.tilemap.realWidth=a.tilemap.width*a.tilemap.tileWidth,a.tilemap.realHeight=a.tilemap.height*a.tilemap.tileHeight,a.tiles=o.data,a.tileset=e,a.opacity=t.opacity,a.rotation=i.localRotation,a.tintColor=t.tintColor,a.smooth=t.smooth,a.maskColor=t.maskColor,a.maskColorMix=t.maskColorMix,a.position.x=i.localPosition.x+t.offset.x*i.localScale.x+(o.x-t.width/2+o.width/2)*a.tilemap.tileWidth,a.position.y=i.localPosition.y+t.offset.y*i.localScale.y+(t.height/2-o.y-o.height/2)*a.tilemap.tileHeight,this.renderManager.addRenderData(a)}))}))}))}};Ve=Tt([l(kt.TilemapRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Ve);const Ne=()=>({type:lt.Tilemap,layer:void 0,position:new e,tilemap:{height:void 0,realHeight:void 0,realWidth:void 0,tileHeight:void 0,tileWidth:void 0,width:void 0},tiles:void 0,tileset:void 0});var We;exports.RigidBodyType=void 0,(We=exports.RigidBodyType||(exports.RigidBodyType={}))[We.Dynamic=0]="Dynamic",We[We.Kinematic=1]="Kinematic",We[We.Static=2]="Static";class ze{constructor(t){this.type=exports.RigidBodyType.Dynamic,this.velocity=new e,this.gravity=0,this.acceleration=new e,this.staticForLayers=[],Object.assign(this,t)}}ze.componentName="RigidBody";let He=class{constructor(t,i,s){this.entityManager=t,this.timeManager=i,this.transformSystem=s,this.types=new Set([exports.RigidBodyType.Dynamic,exports.RigidBodyType.Kinematic]),this.displacement=new e,this.totalAcceleration=new e,this.scaledAcceleration=new e,this.scaledVelocity=new e}onUpdate(){this.timeManager.timeScale<=0||(this.entityManager.search(ze,(({velocity:t,acceleration:i,gravity:s,type:o},r)=>{if(!this.types.has(o))return;const{position:n}=this.entityManager.getComponent(r,zt);o===exports.RigidBodyType.Dynamic?(this.totalAcceleration.y=i.y-s,this.totalAcceleration.x=i.x):this.totalAcceleration.copy(i),e.add(t,t,e.scale(this.scaledAcceleration,this.totalAcceleration,this.timeManager.physicsDeltaTime)),e.add(n,n,e.add(this.displacement,e.scale(this.scaledVelocity,t,this.timeManager.physicsDeltaTime),e.scale(this.scaledAcceleration,this.totalAcceleration,.5*Math.pow(this.timeManager.physicsDeltaTime,2))))})),this.transformSystem.onUpdate())}};He=Tt([l(kt.ApplyVelocitySystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager)),Pt(2,c(kt.TransformSystem))],He);class Ye{constructor(){this.auxMin=new e,this.auxMax=new e,this.auxScaledOffset=new e}updatePositionAndVertices(t,e,i){this.translatePosition(t,e,i),t instanceof M?(this.auxAngle=t.rotation+i.localRotation,t.vertexModel.forEach(((e,s)=>t.vertices[s].set(e.x*i.localScale.x,e.y*i.localScale.y))),t.vertices.forEach((e=>e.set(e.x*Math.cos(this.auxAngle)-e.y*Math.sin(this.auxAngle)+t.position.x,e.x*Math.sin(this.auxAngle)+e.y*Math.cos(this.auxAngle)+t.position.y)))):t instanceof v&&(t.radius*=Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)))}translatePosition(t,i,{localPosition:s,localScale:o,localRotation:r}){if(this.auxScaledOffset.set(i.x*o.x,i.y*o.y),0!==r){const e=Math.atan2(this.auxScaledOffset.y,this.auxScaledOffset.x)+r,i=this.auxScaledOffset.magnitude;t.position.set(s.x+i*Math.cos(e),s.y+i*Math.sin(e))}else e.add(t.position,s,this.auxScaledOffset)}updateBoundingBox(t){t instanceof v?this.updateCircumferenceBoundingBox(t):t instanceof M&&this.updatePolygonBoundingBox(t)}updateCircumferenceBoundingBox(t){t.boundingBox.set(t.position.x-t.radius,t.position.y-t.radius,2*t.radius,2*t.radius)}updatePolygonBoundingBox(t){this.auxMin.x=t.vertices[0].x,this.auxMin.y=t.vertices[0].y,this.auxMax.x=t.vertices[0].x,this.auxMax.y=t.vertices[0].y,t.vertices.forEach((t=>{this.auxMin.x=Math.min(t.x,this.auxMin.x),this.auxMin.y=Math.min(t.y,this.auxMin.y),this.auxMax.x=Math.max(t.x,this.auxMax.x),this.auxMax.y=Math.max(t.y,this.auxMax.y)})),t.boundingBox.set(this.auxMin.x,this.auxMin.y,this.auxMax.x-this.auxMin.x,this.auxMax.y-this.auxMin.y)}updateProjectionAxes(t){var i;if(t.vertices.length>2){const{edgeNormals:s,projectionAxes:o}=t;o.length=0;for(let r=0;r<t.vertices.length;r++){if(e.normal(s[r],e.subtract(s[r],null!==(i=t.vertices[r+1])&&void 0!==i?i:t.vertices[0],t.vertices[r])),0===s[r].x&&0===s[r].y)continue;let n=!1;for(let t=0;t<o.length;t++)if(x(o[t],s[r])){n=!0;break}n||o.push(s[r])}}else e.normal(t.projectionAxes[0],e.subtract(t.projectionAxes[0],t.vertices[1],t.vertices[0]))}}let $e=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(be,((t,e)=>{0===t.shapes.length&&(t.shapes[0]=new v(t.radius)),t.shapes[0].radius=t.radius,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,zt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};$e=Tt([l(kt.UpdateBallColliderShapeSystem),Pt(0,c(Et.EntityManager))],$e);let Xe=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Se,((t,i)=>{0===t.shapes.length&&(t.shapes[0]=new M([new e,new e,new e,new e])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel[0].set(-t.width/2,-t.height/2),t.shapes[0].vertexModel[1].set(-t.width/2,t.height/2),t.shapes[0].vertexModel[2].set(t.width/2,t.height/2),t.shapes[0].vertexModel[3].set(t.width/2,-t.height/2),this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(i,zt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Xe=Tt([l(kt.UpdateBoxColliderShapeSystem),Pt(0,c(Et.EntityManager))],Xe);let qe=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(we,((t,i)=>{for(let s=0;s<t.vertexModel.length-1;s++)t.shapes[s]||(t.shapes[s]=new M([new e,new e])),t.shapes[s].rotation=t.rotation,t.shapes[s].vertexModel=[t.vertexModel[s],t.vertexModel[s+1]],this.updatePositionAndVertices(t.shapes[s],t.offset,this.entityManager.getComponent(i,zt)),this.updateBoundingBox(t.shapes[s]),this.updateProjectionAxes(t.shapes[s])}))}};qe=Tt([l(kt.UpdateEdgeColliderShapeSystem),Pt(0,c(Et.EntityManager))],qe);let Ke=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Ae,((t,e)=>{0===t.shapes.length&&(t.shapes[0]=new M([])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel=t.vertexModel,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,zt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Ke=Tt([l(kt.UpdatePolygonColliderShapeSystem),Pt(0,c(Et.EntityManager))],Ke);let Je=class extends Ye{constructor(t){super(),this.entityManager=t,this.offset=new e}onUpdate(){this.entityManager.search(Re,((t,i)=>{const s=this.entityManager.getComponent(i,ee);if(s&&0!==s.data.length){0===t.shapes.length&&(t.composite?this.useEdges(t,s):this.useBoxes(t,s)),e.add(this.offset,t.offset,s.offset);for(const e of t.shapes)this.updatePositionAndVertices(e,this.offset,this.entityManager.getComponent(i,zt)),this.updateBoundingBox(e),this.updateProjectionAxes(e)}}))}useBoxes(t,e){t.shapes=[],e.data.forEach(((i,s)=>{if(!this.needsCollider(i,s,e))return;const o=new M(this.generateRectangleVertices(s,e));o.updateCollisions=!1,t.shapes.push(o)}))}generateRectangleVertices(t,{width:i,height:s,tileWidth:o,tileHeight:r}){const n=-i*o/2+t%i*o,a=s*r/2-Math.floor(t/i)*r;return[new e(n,a-r),new e(n,a),new e(n+o,a),new e(n+o,a-r)]}needsCollider(t,e,{data:i,width:s,height:o}){return 0!==t&&this.getNeighbors(e,s,o).some((t=>!t||!i[t]||0===i[t]))}useEdges(t,i){t.shapes=[];const s=[],o=[];let r,n;i.data.forEach(((t,e)=>{if(0===t)return;const r=e%i.width,n=Math.floor(e/i.width);s[n]||(s[n]=[]),s[n+1]||(s[n+1]=[]),o[n]||(o[n]=[]),o[n+1]||(o[n+1]=[]);const a=this.getNeighbors(e,i.width,i.height);this.hasTile(a[0],i)||(s[n][r]=!0),this.hasTile(a[2],i)||(s[n+1][r]=!0),this.hasTile(a[1],i)||(o[n][r]=!0),this.hasTile(a[3],i)||(o[n][r+1]=!0)}));for(let o=0;o<s.length;o++)if(s[o])for(let a=0;a<s[o].length;a++)!r||!n||o===n.y&&s[o][a]||(t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0),s[o][a]&&(r||(r=new e(a,o)),n=new e(a+1,o));r&&n&&t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0;for(let s=0;s<=i.width;s++)for(let a=0;a<o.length;a++)o[a]&&(!r||!n||s===n.x&&o[a][s]||(t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0),o[a][s]&&(r||(r=new e(s,a)),n=new e(s,a+1)));r&&n&&t.shapes.push(this.createEdge(r,n,i))}hasTile(t,{data:e}){return void 0!==t&&e[t]&&e[t]>0}createEdge(t,i,{width:s,height:o,tileWidth:r,tileHeight:n}){t.x=-s*r/2+t.x*r,t.y=o*n/2-t.y*n,i.x=-s*r/2+i.x*r,i.y=o*n/2-i.y*n;const a=new M([new e(t.x,t.y),new e(i.x,i.y)]);return a.updateCollisions=!1,a}getNeighbors(t,e,i){return[t-e>=0?t-e:void 0,t%e>0?t-1:void 0,t+e<=e*i?t+e:void 0,t%e<e-1?t+1:void 0]}};Je=Tt([l(kt.UpdateTilemapColliderShapeSystem),Pt(0,c(Et.EntityManager))],Je);let Qe=class{constructor(t,e,i,s,o,r){if(this.entityManager=t,this.broadPhaseResolver=e,this.collisionResolutionMethod=s,this.collisionRepository=o,this.collisionResolutionPool=r,this.colliderTypes=[be,Se,Ae,we,Re],this.colliders=[],this.resolvedCollisions=new Set,this.shapes=[],i){const t=new Map;for(let e=0;e<i.length;e++){const[s,o]=i[e];t.has(s)||t.set(s,new Set),t.has(o)||t.set(o,new Set),t.get(s).add(o),t.get(o).add(s)}this.layerNeighbors=t}}onUpdate(){this.collisionRepository.clear(),this.resolvedCollisions.clear(),this.collisionResolutionPool.clear(),this.colliders.length=0,this.shapes.length=0,this.colliderTypes.forEach((t=>this.entityManager.search(t,((t,e)=>{this.colliders.push(t),t.shapes.forEach((i=>{var s;i.entity=e,i.collider=this.colliders.length-1,i.id=this.shapes.length,i.ignoreCollisionsWithLayers=null!==(s=t.ignoreCollisionsWithLayers)&&void 0!==s?s:[],i.layer=t.layer,this.shapes.push(i)}))})))),this.broadPhaseResolver.update(this.shapes),this.shapes.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase({boundingBox:t,layer:e}){const i=this.broadPhaseResolver.retrieve(t),s=i.length,o=[];if(this.layerNeighbors){const t=this.layerNeighbors.get(e);if(!t)return o;for(let e=0;e<s;e++){const s=this.shapes[i[e]];t.has(s.layer)&&o.push(s)}return o}for(let t=0;t<s;t++)o.push(this.shapes[i[t]]);return o}narrowPhase(t,e){e.filter((e=>t.entity!==e.entity&&t.id!==e.id&&!t.ignoreCollisionsWithLayers.includes(e.layer)&&!e.ignoreCollisionsWithLayers.includes(t.layer)&&!this.isResolved(t,e))).forEach((e=>{this.resolvedCollisions.add(`${t.id}-${e.id}`),this.resolvedCollisions.add(`${e.id}-${t.id}`);const i=this.collisionResolutionMethod.findCollision(t,e);i&&this.collisionRepository.persist(t.entity,this.colliders[t.collider],e.entity,this.colliders[e.collider],i)}))}isResolved(t,e){return this.resolvedCollisions.has(`${t.id}-${e.id}`)}};Qe=Tt([l(kt.ResolveCollisionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.CollisionBroadphaseResolver)),Pt(2,c(Et.CollisionMatrix)),Pt(3,c(Et.CollisionResolutionMethod)),Pt(4,c(Et.CollisionRepository)),Pt(5,c(Et.CollisionResolutionPool))],Qe);let Ze=class{constructor(t,i,s){this.entityManager=t,this.collisionRepository=i,this.transformSystem=s,this.correction=new e,this.maxCorrection=new e,this.aux=new e}onUpdate(){const t=this.collisionRepository.getCollisions().filter((({localCollider:t,remoteCollider:e,remoteEntity:i,localEntity:s})=>t.physics&&e.physics&&this.entityManager.hasComponent(s,ze)&&this.entityManager.hasComponent(i,ze)));0!==t.length&&(this.entityManager.search(ze,((i,s)=>{if(i.type!==exports.RigidBodyType.Dynamic)return;if(this.maxCorrection.set(0,0),t.filter((({localEntity:t,remoteEntity:e})=>s===t||s===e)).forEach((t=>{const o=t.remoteEntity===s,r=this.entityManager.getComponent(o?t.localEntity:t.remoteEntity,ze),n=o?t.remoteCollider.layer:t.localCollider.layer,a=o?t.localCollider.layer:t.remoteCollider.layer;if(r.type===exports.RigidBodyType.Dynamic&&i.staticForLayers.includes(a))return;const h=r.type!==exports.RigidBodyType.Dynamic||r.staticForLayers.includes(n);let l=t.resolution.penetration;const c=o?e.scale(this.aux,t.resolution.direction,-1):t.resolution.direction;h||(l/=2),e.scale(this.correction,c,-l),this.correction.magnitude>this.maxCorrection.magnitude&&this.maxCorrection.copy(this.correction)})),0===this.maxCorrection.x&&0===this.maxCorrection.y)return;const{position:o}=this.entityManager.getComponent(s,zt);e.add(o,o,this.maxCorrection),i.gravity>0&&this.maxCorrection.y*i.velocity.y<0&&(i.velocity.y=0)})),this.transformSystem.onUpdate())}};Ze=Tt([l(kt.ApplyRepositionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.CollisionRepository)),Pt(2,c(kt.TransformSystem))],Ze);const ti=new Set([Se,be,Ae,we,Re]);let ei=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(ze,((t,e)=>{if(t.type!==exports.RigidBodyType.Dynamic)return;const i=this.entityManager.getComponent(e,zt);for(const t of ti)if(this.entityManager.hasComponent(e,t)){const s=this.entityManager.getComponent(e,t);s.shapes.forEach((t=>{this.updatePositionAndVertices(t,s.offset,i),this.updateBoundingBox(t)}))}}))}};ei=Tt([l(kt.UpdateCollidersAfterRepositionSystem),Pt(0,c(Et.EntityManager))],ei);const ii=24;let si=class{constructor(t,i,s,o,r){this.entityManager=t,this.renderManager=i,this.inputManager=s,this.canvas=o,this.gameConfig=r,this.positionInViewport=new e,this.positionInCameraViewport=new e,this.positionInWorldspace=new e,this.renderDataPerCamera=new Map}onUpdate(){var t;if(!(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.mousePosition)||!this.inputManager.mouse)return;const{positionInViewport:i}=this.inputManager.mouse;this.entityManager.search($t,((t,s)=>{if(!t.debug)return;const{zoom:o}=t,r=this.entityManager.getComponent(s,zt).position;this.renderDataPerCamera.has(s)||this.renderDataPerCamera.set(s,oi());const n=this.renderDataPerCamera.get(s);e.floor(this.positionInWorldspace,e.add(this.positionInWorldspace,r,e.scale(this.positionInWorldspace,i,1/o))),e.floor(this.positionInCameraViewport,e.scale(this.positionInCameraViewport,i,1/o)),e.round(this.positionInViewport,i),n.color=this.gameConfig.debug.textColor,n.text=`mouse_position: canvas_viewport=${this.positionInViewport}, camera_viewport=${this.positionInCameraViewport}, world_space=${this.positionInWorldspace}`,n.fontSize=ii/o,n.lineHeight=n.fontSize,n.shadow.offset.x=2/o,n.shadow.offset.y=-2/o,n.boundingBox={width:this.canvas.width/o,height:n.fontSize},this.updateRenderDataPosition(n,r,o),this.renderManager.addRenderData(n)}))}updateRenderDataPosition(t,e,i){switch(t.position.x=e.x,this.gameConfig.debug.textPosition){case"top-right":t.alignment=exports.TextAlignment.Right,t.position.y=e.y+(this.canvas.height/2-ii)/i;break;case"top-left":t.alignment=exports.TextAlignment.Left,t.position.y=e.y+(this.canvas.height/2-ii)/i;break;case"bottom-left":t.alignment=exports.TextAlignment.Left,t.position.y=e.y-(this.canvas.height/2-ii)/i;break;default:t.alignment=exports.TextAlignment.Right,t.position.y=e.y-(this.canvas.height/2-ii)/i}}};si=Tt([l(kt.DebugMousePositionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.InputManager)),Pt(3,c(Et.CanvasElement)),Pt(4,c(Et.GameConfig))],si);const oi=(t=24)=>({type:lt.Text,text:"",position:new e,layer:Yt,color:"#00FF00",fontSize:t,font:"Arial",shadow:{color:"#000000",opacity:1,offset:new e(1,-1)},flipHorizontally:!1,flipVertically:!1,letterSpacing:0,lineHeight:t,opacity:1,rotation:0,smooth:!1,textureAtlas:Object.assign({},Oe),boundingBox:{width:0,height:0},alignment:exports.TextAlignment.Left});let ri=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.textRendererBoundingBoxes)&&this.entityManager.search(ke,(({width:t,height:i,rotation:s,layer:o,offset:r},n)=>{const a=this.entityManager.getComponent(n,zt);if(!a)return;const h={type:lt.Geometric,shape:exports.GeometricShape.Polygon,position:e.add(new e,a.localPosition,r),layer:o,color:this.gameConfig.debug.textBoxColor,radius:void 0,rotation:s+a.localRotation,vertexModel:[new e(-t/2,-i/2),new e(-t/2,i/2),new e(t/2,i/2),new e(t/2,-i/2)]};this.renderManager.addRenderData(h)}))}};ri=Tt([l(kt.DebugTextRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],ri);let ni=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.buttons)&&this.entityManager.search(Jt,(({shape:t,width:i,height:s,radius:o,offset:r},n)=>{if(t!==exports.ButtonShape.Rectangle&&t!==exports.ButtonShape.Circumference)return;const a=this.entityManager.getComponent(n,zt);if(!a)return;const{localPosition:h,localScale:l}=a,c={type:lt.Geometric,shape:void 0,position:new e(h.x+r.x*l.x,h.y+r.y*l.y),layer:Yt,color:this.gameConfig.debug.buttonColor,radius:void 0,rotation:void 0,vertexModel:void 0};if(t===exports.ButtonShape.Rectangle){const t=i*l.x,o=s*l.y;c.shape=exports.GeometricShape.Polygon,c.vertexModel=[new e(-t/2,-o/2),new e(-t/2,o/2),new e(t/2,o/2),new e(t/2,-o/2)]}else t===exports.ButtonShape.Circumference&&(c.shape=exports.GeometricShape.Circumference,c.radius=o*Math.max(Math.abs(l.x),Math.abs(l.y)));this.renderManager.addRenderData(c)}))}};ni=Tt([l(kt.DebugButtonSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],ni);const ai=new Map([[Nt.PreGameLogic,[{name:kt.KeyboardSystem,type:pe},{name:kt.MouseSystem,type:ue},{name:kt.TouchScreenSystem,type:me},{name:kt.GamepadSystem,type:ge},{name:kt.ButtonSystem,type:Zt},{name:kt.AudioPlayerSystem,type:Vt},{name:kt.TiledWrapperSystem,type:he},{name:kt.TilemapPreProcessingSystem,type:ce},{name:kt.TiledObjectSystem,type:re}]],[Nt.Transform,[{name:kt.TransformSystem,type:de}]],[Nt.Physics,[{name:kt.ApplyVelocitySystem,type:He},{name:kt.UpdateBallColliderShapeSystem,type:$e},{name:kt.UpdateBoxColliderShapeSystem,type:Xe},{name:kt.UpdateEdgeColliderShapeSystem,type:qe},{name:kt.UpdatePolygonColliderShapeSystem,type:Ke},{name:kt.UpdateTilemapColliderShapeSystem,type:Je},{name:kt.ResolveCollisionSystem,type:Qe},{name:kt.ApplyRepositionSystem,type:Ze},{name:kt.UpdateCollidersAfterRepositionSystem,type:ei}]],[Nt.Render,[{name:kt.AnimatorSystem,type:xe},{name:kt.TilemapAnimationSystem,type:Me},{name:kt.CameraSystem,type:ve},{name:kt.TilemapRendererSystem,type:Ve},{name:kt.SpriteRendererSystem,type:Le},{name:kt.GeometricRendererSystem,type:Ie},{name:kt.MaskRendererSystem,type:Pe},{name:kt.DarknessLightRendererSystem,type:je},{name:kt.TextRendererSystem,type:Ge},{name:kt.VideoRendererSystem,type:Kt},{name:kt.DebugColliderRenderSystem,type:_e},{name:kt.DebugMousePositionSystem,type:si},{name:kt.DebugTextRendererSystem,type:ri},{name:kt.DebugButtonSystem,type:ni},{name:kt.CullingSystem,type:Ee},{name:kt.ClearScreenSystem,type:Ce},{name:kt.RenderSystem,type:Be}]]]);let hi=class{constructor(t,e,i){this.timeManager=t,this.systemManager=e,this.sceneManager=i,this.running=!1,this.gameLoopAccumulator=0}start(){this.running||(this.running=!0,this.gameLoopAccumulator=0,this.enableSystems(),this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.asyncPhysicsLoop())}enableSystems(){ai.forEach((t=>{t.forEach((({type:t})=>this.systemManager.enableSystem(t)))}))}stop(){var t;this.running&&(null===(t=this.systemManager.getSystem(Vt))||void 0===t||t.onGameStopped(),this.sceneManager.destroyCurrentScene(),this.systemManager.disableAllSystems(),this.running=!1)}requestAnimationLoop(t){this.running&&(this.timeManager.updateForRender(.001*t),this.sceneManager.update(),this.sceneManager.loadingScene||(this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.sceneManager.sceneLoadedThisFrame&&(this.gameLoopAccumulator=this.timeManager.fixedGameDeltaTime),this.gameLoopAccumulator>=this.timeManager.fixedGameDeltaTime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.fixedGameDeltaTime),this.renderIteration()),window.requestAnimationFrame((t=>this.requestAnimationLoop(t))))}gameLogicIteration(t){this.timeManager.updateForGame(t),this.systemManager.update(Nt.PreGameLogic),this.systemManager.update(Nt.GameLogic),this.timeManager.updateIntervals(),this.systemManager.update(Nt.Transform)}renderIteration(){this.systemManager.groupHasSystems(Nt.GamePreRender)&&(this.systemManager.update(Nt.GamePreRender),this.systemManager.update(Nt.Transform)),this.systemManager.update(Nt.Render)}asyncPhysicsLoop(){this.physicsIntervalId=window.setInterval((()=>{if(!this.running)return window.clearInterval(this.physicsIntervalId);this.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||this.physicsIteration()}),1e3/this.timeManager.fixedPhysicsFramerate)}physicsIteration(){this.systemManager.groupHasSystems(Nt.GamePhysics)&&(this.systemManager.update(Nt.GamePhysics),this.systemManager.update(Nt.Transform)),this.systemManager.update(Nt.Physics)}};hi=Tt([l(Et.LoopManager),Pt(0,c(Et.TimeManager)),Pt(1,c(Et.SystemManager)),Pt(2,c(Et.SceneManager))],hi);class li{constructor(t,e){this.container=t,this.systemManager=e,this.lastSystemTypeId=0}createSystemIfNotExists(t){if(this.systemManager.hasSystem(t))return;const e="__system_"+this.lastSystemTypeId++;var i;this.container.add(t,e),this.systemManager.addSystem(this.container.get(e),null!==(i=t.prototype.__system_group)&&void 0!==i?i:Nt.GameLogic)}}let ci=class{constructor(t){this.webGLManager=t,this.renderData=[],this.cameraData=[]}addCameraData(t){this.cameraData.push(t)}addRenderData(t){this.renderData.push(t)}setRenderData(t){this.renderData=t}getCameraData(){return this.cameraData}getRenderData(){return this.renderData}removeCameraData(){this.cameraData=[]}removeRenderData(){this.renderData=[]}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).forEach((e=>this.webGLManager.render(e,t)))))}};ci=Tt([l(Et.RenderManager),Pt(0,c(Et.WebGLManager))],ci);const di=({headless:t})=>{var e;if(t)return;const i="undefined"!=typeof window?null!==(e=window.AudioContext)&&void 0!==e?e:window.webkitAudioContext:void 0;return i?new i:void 0},gi=t=>{var e,i,s,o,r,n,a,h,l,c,d,g,p;if(!(t.containerNode instanceof HTMLElement))throw new Error("GameConfig Error: Invalid containerNode");if("number"!=typeof t.width)throw new Error("GameConfig Error: Invalid width");if("number"!=typeof t.height)throw new Error("GameConfig Error: Invalid height");t.canvasColor=null!==(e=t.canvasColor)&&void 0!==e?e:"#000000",t.physicsFramerate=null!==(i=t.physicsFramerate)&&void 0!==i?i:180,t.headless=null!==(s=t.headless)&&void 0!==s&&s,t.debug=null!==(o=t.debug)&&void 0!==o?o:{colliders:!1,mousePosition:!1,textRendererBoundingBoxes:!1},t.debug.collidersColor=null!==(r=t.debug.collidersColor)&&void 0!==r?r:"#00FF00",t.debug.textColor=null!==(n=t.debug.textColor)&&void 0!==n?n:"#00FF00",t.debug.textBoxColor=null!==(a=t.debug.textBoxColor)&&void 0!==a?a:"#0000FF",t.debug.buttonColor=null!==(h=t.debug.buttonColor)&&void 0!==h?h:"#FF00FF",t.debug.textPosition=null!==(l=t.debug.textPosition)&&void 0!==l?l:"bottom-left",t.collisions=null!==(c=t.collisions)&&void 0!==c?c:{},t.collisions.collisionBroadPhaseMethod=null!==(d=t.collisions.collisionBroadPhaseMethod)&&void 0!==d?d:exports.BroadPhaseMethods.SpatialGrid,t.collisions.collisionMatrix=null!==(g=t.collisions.collisionMatrix)&&void 0!==g?g:void 0,t.collisions.collisionMethod=null!==(p=t.collisions.collisionMethod)&&void 0!==p?p:exports.CollisionMethods.SAT},pi=({containerNode:t,width:e,height:i})=>{const s=document.createElement("canvas");return s.id="angryPixelGameCanvas",s.width=Math.floor(e),s.height=Math.floor(i),s.tabIndex=0,s.addEventListener("contextmenu",(t=>t.preventDefault())),t.appendChild(s),s.focus(),s},ui=t=>{t.add(exports.EntityManager),t.add(exports.SystemManager),t.set(Et.CreateSystemService,new li(t,t.get(Et.SystemManager))),t.add(exports.TimeManager),t.add(exports.AssetManager),t.add(exports.InputManager),t.add(exports.SceneManager),t.add(exports.InputManager),t.add(hi),t.add(_t),t.add(ci)},mi=t=>{t.get(Et.GameConfig).headless&&fi(ai),ai.forEach(((e,i)=>e.forEach((({type:e,name:s})=>{t.add(e),t.get(Et.SystemManager).addSystem(t.get(s),i)}))))},fi=t=>{t.delete(Nt.Render),t.set(Nt.PreGameLogic,t.get(Nt.PreGameLogic).filter((({name:t})=>![kt.AudioPlayerSystem,kt.ButtonSystem,kt.GamepadSystem,kt.KeyboardSystem,kt.MouseSystem,kt.TouchScreenSystem].includes(t))))},yi=t=>{const{collisions:{collisionBroadPhaseMethod:e,collisionMatrix:i,collisionMethod:s}}=t.get(Et.GameConfig);t.add(L),t.add(exports.CollisionRepository),t.add(F),s===exports.CollisionMethods.AABB?(t.add(T),t.add(B)):t.add(U),t.add(e===exports.BroadPhaseMethods.QuadTree?u:y),t.add(s===exports.CollisionMethods.AABB?S:_),t.set(Et.CollisionMatrix,i)},xi=t=>{const e=t.get(Et.GameConfig);e.dependencies&&e.dependencies.forEach((([e,i])=>{t.set(e,i)}))};class Mi{onUpdate(){}onSceneLoaded(){}onSceneDestroyed(){}}Tt([c(Et.EntityManager)],Mi.prototype,"entityManager",void 0),Tt([c(Et.SystemManager)],Mi.prototype,"systemManager",void 0),Tt([c(Et.AssetManager)],Mi.prototype,"assetManager",void 0),Tt([c(Et.SceneManager)],Mi.prototype,"sceneManager",void 0),Tt([c(Et.TimeManager)],Mi.prototype,"timeManager",void 0),Tt([c(Et.InputManager)],Mi.prototype,"inputManager",void 0),Tt([c(Et.CollisionRepository)],Mi.prototype,"collisionRepository",void 0),Tt([c(Et.GameConfig)],Mi.prototype,"gameConfig",void 0);const vi={AssetManager:Et.AssetManager,CanvasElement:wt.CanvasElement,CollisionRepository:d.CollisionRepository,EntityManager:G.EntityManager,GameConfig:Et.GameConfig,InputManager:Et.InputManager,SceneManager:Et.SceneManager,SystemManager:G.SystemManager,TimeManager:Et.TimeManager};exports.Animation=class{constructor(t){var i,s,o;this.slice={size:new e,offset:new e,padding:new e},this.frames=[],this.fps=12,this.loop=!1,t&&(this.image=t.image,this.frames=null!==(i=t.frames)&&void 0!==i?i:this.frames,this.fps=null!==(s=t.fps)&&void 0!==s?s:this.fps,this.loop=null!==(o=t.loop)&&void 0!==o?o:this.loop,t.slice&&(this.slice.size.copy(t.slice.size),t.slice.offset&&this.slice.offset.copy(t.slice.offset),t.slice.padding&&this.slice.padding.copy(t.slice.padding)))}},exports.Animator=fe,exports.AudioPlayer=Ot,exports.BallCollider=be,exports.BoxCollider=Se,exports.Button=Jt,exports.Camera=$t,exports.Circumference=v,exports.DarknessRenderer=Fe,exports.EdgeCollider=we,exports.Game=class{constructor(t){this.container=(t=>{gi(t);const e=new h;return e.set(Et.GameConfig,t),e.set(Et.CanvasElement,pi(t)),e.set(Et.AudioContext,di(t)),yi(e),ui(e),mi(e),xi(e),e})(t)}get running(){return this.container.get(Et.LoopManager).running}addScene(t,e,i=!1){this.container.get(Et.SceneManager).addScene(t,e,i)}addDependencyType(t,e){this.container.add(t,e)}addDependencyInstance(t,e){this.container.set(e,t)}start(){this.container.get(Et.LoopManager).start()}stop(){this.container.get(Et.LoopManager).stop()}},exports.GameSystem=Mi,exports.GamepadController=Dt,exports.GeometricRenderer=Ue,exports.Keyboard=Ft,exports.LightRenderer=De,exports.MaskRenderer=Te,exports.Mouse=jt,exports.Polygon=M,exports.PolygonCollider=Ae,exports.Rectangle=i,exports.RigidBody=ze,exports.SYMBOLS=vi,exports.Scene=class{constructor(t,e){this.entityManager=t,this.assetManager=e,this.systems=[]}loadAssets(){}setup(){}},exports.SpriteRenderer=ye,exports.TextRenderer=ke,exports.TileAnimation=ie,exports.TiledWrapper=te,exports.TilemapCollider=Re,exports.TilemapRenderer=ee,exports.TouchScreen=Ut,exports.Transform=zt,exports.Vector2=e,exports.VideoRenderer=Xt,exports.between=n,exports.clamp=s,exports.debugRenderLayer=Yt,exports.decorate=function(t,e,i){"number"==typeof i?t(e.prototype,void 0,i):void 0!==i?t(e.prototype,i):t(e)},exports.defaultRenderLayer=Ht,exports.defaultTextureAtlasOptions=Oe,exports.degreesToRadians=a,exports.fixedRound=o,exports.gameLogicSystem=function(){return function(t){Wt(t,Nt.GameLogic)}},exports.gamePhysicsSystem=function(){return function(t){Wt(t,Nt.GamePhysics)}},exports.gamePreRenderSystem=function(){return function(t){Wt(t,Nt.GamePreRender)}},exports.inject=c,exports.injectable=l,exports.playSfx=({audioSource:t,volume:e=1,loop:i=!1})=>{const{element:s}=t;s.volume=e,s.loop=i,s.currentTime=0,s.play().catch((t=>console.warn("playSfx error:",t)))},exports.radiansToDegrees=t=>t*(180/Math.PI),exports.randomFloat=(t,e,i=2)=>o(Math.random()*(e-t)+t,i),exports.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,exports.range=r,exports.rgbToHex=({r:t,g:e,b:i},s="#")=>{const o=t=>t.toString(16).padStart(2,"0");return`${s}${o(t)}${o(e)}${o(i)}`},exports.stopSfx=t=>{t.element.pause(),t.element.currentTime=0};
1
+ "use strict";var t;exports.BroadPhaseMethods=void 0,(t=exports.BroadPhaseMethods||(exports.BroadPhaseMethods={}))[t.QuadTree=0]="QuadTree",t[t.SpatialGrid=1]="SpatialGrid";class e{constructor(t=0,e=0){this._x=t,this._y=e}get x(){return this._x}set x(t){this._x=t}get y(){return this._y}set y(t){this._y=t}get magnitude(){return Math.sqrt(Math.pow(this._x,2)+Math.pow(this._y,2))}get direction(){return this._direction||(this._direction=new e),e.unit(this._direction,this)}set(t,e){this._x=t,this._y=e}copy(t){this.set(t.x,t.y)}equals(t){return this._x===t.x&&this._y===t.y}clone(){return new e(this._x,this._y)}distance(t){return Math.sqrt(Math.pow(this._x-t.x,2)+Math.pow(this._y-t.y,2))}static add(t,e,i){return t.set(e.x+i.x,e.y+i.y),t}static subtract(t,e,i){return t.set(e.x-i.x,e.y-i.y),t}static unit(t,e){const i=e.x*e.x+e.y*e.y;if(0===i)t.set(0,0);else{const s=1/Math.sqrt(i);t.set(e.x*s,e.y*s)}return t}static normal(t,e){return t.set(-e.y,e.x),this.unit(t,t)}static scale(t,e,i){return t.set(e.x*i,e.y*i),t}static dot(t,e){return t.x*e.x+t.y*e.y}static cross(t,e){return t.x*e.y-t.y*e.x}static round(t,e){return t.set(Math.round(e.x),Math.round(e.y)),t}static floor(t,e){return t.set(Math.floor(e.x),Math.floor(e.y)),t}static ceil(t,e){return t.set(Math.ceil(e.x),Math.ceil(e.y)),t}toString(){return`(${this._x}, ${this._y})`}}class i{constructor(t=0,i=0,s=0,o=0){this.width=0,this.height=0,this._position=new e,this._center=new e,this.set(t,i,s,o)}get x(){return this._position.x}set x(t){this._position.set(t,this._position.y)}get y(){return this._position.y}set y(t){this._position.set(this._position.x,t)}get x1(){return this._position.x+this.width}get y1(){return this._position.y+this.height}get position(){return this._position}set position(t){this._position.set(t.x,t.y)}get center(){return this._center.set(this.x+this.width/2,this.y+this.height/2),this._center}set(t,e,i,s){this._position.set(t,e),this.width=i,this.height=s}equals(t){return this.position.equals(t.position)&&this.width===t.width&&this.height===t.height}copy(t){this.set(t.x,t.y,t.width,t.height)}intersects(t){return!(this.x1<t.x||this.x>t.x1||this.y1<t.y||this.y>t.y1)}contains(t){return t instanceof i?t.x1<=this.x1&&t.x>=this.x&&t.y1<=this.y1&&t.y>=this.y:t instanceof e&&!(t.x<this.x||t.y<this.y||t.x>=this.x1||t.y>=this.y1)}toString(){return`(${this.position.x}, ${this.position.y}, ${this.width}, ${this.height})`}}const s=(t,e,i)=>Math.min(i,Math.max(e,t)),o=(t,e)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),r=(t,e,i=1)=>{const s=[];for(let o=t;o<=e;o+=i)s.push(o);return s},n=(t,e,i)=>t>=e&&t<=i,a=t=>t*(Math.PI/180);class h{constructor(){this.instances=new Map,this.types=new Map}add(t,e){if(!e&&!t.prototype.__ioc_injectable)throw new Error(`Type ${t.name} is not injectable`);return this.types.set(null!=e?e:t.prototype.__ioc_injectable,t),this}set(t,e){return this.instances.set(t,e),this}get(t){var e,i;if(!this.instances.has(t)){const s=this.types.get(t);if(!s)throw new Error(`${t.toString()} is not a valid type`);const o=new s(...(null!==(e=s.prototype.__ioc_inject_constructor)&&void 0!==e?e:[]).map((t=>this.get(t))));(null!==(i=s.prototype.__ioc_inject_prop)&&void 0!==i?i:[]).forEach((([t,e])=>o[t]=this.get(e))),this.instances.set(t,o)}return this.instances.get(t)}has(t){return this.types.has(t)||this.instances.has(t)}}function l(t){return function(e){e.prototype.__ioc_injectable&&e.prototype.__ioc_injectable===t||(e.prototype.__ioc_injectable=t)}}function c(t){return function(e,i,s){void 0!==s?(e.prototype.__ioc_inject_constructor||(e.prototype.__ioc_inject_constructor=[]),e.prototype.__ioc_inject_constructor[s]=t):void 0!==i&&(e.constructor.prototype.__ioc_inject_prop||(e.constructor.prototype.__ioc_inject_prop=[]),e.constructor.prototype.__ioc_inject_prop.push([i,t]))}}const d={CollisionRepository:Symbol.for("CollisionRepository"),CollisionBroadphaseResolver:Symbol.for("CollisionBroadphaseResolver"),CollisionResolutionMethod:Symbol.for("CollisionResolutionMethod"),CollisionAABBResolver:Symbol.for("CollisionAABBResolver"),CollisionCircumferenceAABBResolver:Symbol.for("CollisionCircumferenceAABBResolver"),CollisionCircumferenceResolver:Symbol.for("CollisionCircumferenceResolver"),CollisionSatResolver:Symbol.for("CollisionSatResolver"),CollisionMatrix:Symbol.for("CollisionMatrix"),CollisionResolutionPool:Symbol.for("CollisionResolutionPool")};var g,p=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let u=g=class{constructor(t=new i,e=0,s=[]){this.bounds=t,this.level=e,this.objects=[],this.nodes=[],this.rects=s}update(t){if(this.clear(),this.rects.length=0,0===t.length)return;let e=1/0,i=1/0,s=-1/0,o=-1/0;for(const{id:r,boundingBox:n}of t)this.rects[r]=n,e=Math.min(e,n.x),i=Math.min(i,n.y),s=Math.max(s,n.x1),o=Math.max(o,n.y1);this.bounds.set(e,i,s-e,o-i);for(const{id:e}of t)this.insert(e)}retrieve(t){const e=[];return this.query(t,e),e}clear(){this.objects=[];for(const t of this.nodes)t.clear();this.nodes=[]}split(){const t=this.bounds.width/2,e=this.bounds.height/2,s=this.bounds.x,o=this.bounds.y;this.nodes=[new g(new i(s+t,o+e,t,e),this.level+1,this.rects),new g(new i(s,o+e,t,e),this.level+1,this.rects),new g(new i(s,o,t,e),this.level+1,this.rects),new g(new i(s+t,o,t,e),this.level+1,this.rects)]}getIndex(t){const e=this.bounds.x+this.bounds.width/2,i=this.bounds.y+this.bounds.height/2,s=t.y1<i,o=t.y>i,r=t.x1<e,n=t.x>e;return o&&n?0:o&&r?1:s&&r?2:s&&n?3:-1}insert(t){if(this.nodes.length>0){const e=this.getIndex(this.rects[t]);if(-1!==e)return void this.nodes[e].insert(t)}if(this.objects.push(t),this.objects.length>10&&this.level<5){0===this.nodes.length&&this.split();let t=0;for(;t<this.objects.length;){const e=this.getIndex(this.rects[this.objects[t]]);-1!==e?this.nodes[e].insert(this.objects.splice(t,1)[0]):t++}}}query(t,e){for(const i of this.objects)this.rects[i].intersects(t)&&e.push(i);if(0===this.nodes.length)return;const i=this.bounds.x+this.bounds.width/2,s=this.bounds.y+this.bounds.height/2,o=t.y<s,r=t.y1>s,n=t.x<i,a=t.x1>i;r&&a&&this.nodes[0].query(t,e),r&&n&&this.nodes[1].query(t,e),o&&n&&this.nodes[2].query(t,e),o&&a&&this.nodes[3].query(t,e)}};u=g=p([l(d.CollisionBroadphaseResolver)],u);var m=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};const f=(t,e,i,s)=>{const o=(t-e)/i|0;return o<0?0:o>=s?s-1:o};let y=class{constructor(){this.area=new i,this.cells=[[]],this.usedCells=[],this.boxes=[],this.columns=1,this.rows=1,this.cellWidth=0,this.cellHeight=0,this.seenGen=[],this.retrieveSerial=0,this.retrieveResult=[],this.coordinates={x0:0,x1:0,y0:0,y1:0}}update(t){if(this.clearCells(),this.boxes.length=0,0!==t.length){this.resize(t),this.ensureSeenCapacity(t.length);for(let e=0;e<t.length;e++)this.insert(t[e].id,t[e].boundingBox)}}ensureSeenCapacity(t){if(this.seenGen.length<t){const e=this.seenGen.length;this.seenGen.length=t,this.seenGen.fill(0,e,t)}}clearCells(){for(let t=0;t<this.usedCells.length;t++)this.cells[this.usedCells[t]].length=0;this.usedCells.length=0}resize(t){let e=1/0,i=1/0,s=-1/0,o=-1/0,r=0;for(let n=0;n<t.length;n++){const a=t[n].boundingBox;e=Math.min(e,a.x),i=Math.min(i,a.y),s=Math.max(s,a.x1),o=Math.max(o,a.y1),r+=Math.max(a.width,a.height)}const n=s-e,a=o-i,h=t.length;this.area.set(e,i,n,a);const l=Math.max(Math.sqrt(n*a/h),Math.max(n,a)/h,r/h)||1;this.columns=Math.ceil(n/l)||1,this.rows=Math.ceil(a/l)||1,this.cellWidth=n/this.columns,this.cellHeight=a/this.rows;for(let t=this.cells.length,e=this.columns*this.rows;t<e;t++)this.cells.push([])}insert(t,e){this.updateCoordinates(e);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++){const s=e*this.rows+i;0===this.cells[s].length&&this.usedCells.push(s),this.cells[s].push(t)}this.boxes[t]=e}retrieve(t){this.retrieveResult.length=0,2147483647==++this.retrieveSerial&&(this.retrieveSerial=1,this.seenGen.fill(0)),this.updateCoordinates(t);for(let e=this.coordinates.x0;e<=this.coordinates.x1;e++)for(let i=this.coordinates.y0;i<=this.coordinates.y1;i++){const s=this.cells[e*this.rows+i];for(let e=0,i=s.length;e<i;e++){const i=s[e];this.seenGen[i]!==this.retrieveSerial&&(this.seenGen[i]=this.retrieveSerial,this.boxes[i].intersects(t)&&this.retrieveResult.push(i))}}return this.retrieveResult}updateCoordinates(t){this.coordinates.x0=f(t.x,this.area.x,this.cellWidth,this.columns),this.coordinates.x1=f(t.x1,this.area.x,this.cellWidth,this.columns),this.coordinates.y0=f(t.y,this.area.y,this.cellHeight,this.rows),this.coordinates.y1=f(t.y1,this.area.y,this.cellHeight,this.rows)}};y=m([l(d.CollisionBroadphaseResolver)],y);const x=(t,i)=>Math.abs(e.cross(t,i))<1e-6;class M{get vertexModel(){return this._vertexModel}set vertexModel(t){if(this._vertexModel=t,2===t.length)return this.vertices=[new e,new e],this.edgeNormals=[],void(this.projectionAxes=[new e]);this.vertices=[],this.edgeNormals=[],this.projectionAxes=[],this._vertexModel.forEach((()=>{this.vertices.push(new e),this.edgeNormals.push(new e)}))}constructor(t,s=0){this.rotation=s,this.boundingBox=new i,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new e,this.projectionAxes=[],this.edgeNormals=[],this.radius=0,this.vertices=[],this.updateCollisions=!0,this._vertexModel=[],this.vertexModel=t}}class v{constructor(t){this.radius=t,this.boundingBox=new i,this.collider=void 0,this.entity=void 0,this.id=void 0,this.ignoreCollisionsWithLayers=void 0,this.layer=void 0,this.position=new e,this.projectionAxes=[new e],this.rotation=0,this.vertexModel=[],this.vertices=[new e,new e],this.updateCollisions=!0}}var C=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},b=function(t,e){return function(i,s){e(i,s,t)}};let S=class{constructor(t,e,i){this.AABBResolver=t,this.circumferenceAABBResolver=e,this.circumferenceResolver=i}findCollision(t,e){return t instanceof M&&e instanceof M?this.AABBResolver.resolve(t,e):t instanceof v&&e instanceof M?this.circumferenceAABBResolver.resolve(t,e):t instanceof M&&e instanceof v?this.circumferenceAABBResolver.resolve(e,t,!0):t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):void 0}};var w;S=C([l(d.CollisionResolutionMethod),b(0,c(d.CollisionAABBResolver)),b(1,c(d.CollisionCircumferenceAABBResolver)),b(2,c(d.CollisionCircumferenceResolver))],S),exports.CollisionMethods=void 0,(w=exports.CollisionMethods||(exports.CollisionMethods={}))[w.AABB=0]="AABB",w[w.SAT=1]="SAT";var A=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},R=function(t,e){return function(i,s){e(i,s,t)}};let _=class{constructor(t,e){this.circumferenceResolver=t,this.satResolver=e}findCollision(t,e){return t instanceof v&&e instanceof v?this.circumferenceResolver.resolve(t,e):this.satResolver.resolve(t,e)}};_=A([l(d.CollisionResolutionMethod),R(0,c(d.CollisionCircumferenceResolver)),R(1,c(d.CollisionSatResolver))],_);var E=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let T=class{constructor(){this.direction=new e,this.resolutionDirection=new e}resolve({boundingBox:t},{boundingBox:i}){if(this.overlapX=Math.min(t.x1,i.x1)-Math.max(t.x,i.x),this.overlapY=Math.min(t.y1,i.y1)-Math.max(t.y,i.y),this.overlapX<0||this.overlapY<0)return;this.checkOverlapForLines(t,i),this.direction.set(Math.sign(i.center.x-t.center.x),Math.sign(i.center.y-t.center.y)),this.preventContainment(t,i),this.overlapY<=this.overlapX?(this.minOverlap=this.overlapY,this.resolutionDirection.set(0,this.direction.y||1)):(this.minOverlap=this.overlapX,this.resolutionDirection.set(this.direction.x||1,0));const s=this.collisionResolutionPool.get();return e.unit(s.direction,this.resolutionDirection),s.penetration=this.minOverlap,s}checkOverlapForLines(t,e){0!==t.width&&0!==e.width||0!==this.overlapX||(this.overlapX=Math.min(Math.abs(t.x-e.x),Math.abs(t.x1-e.x1))),0!==t.height&&0!==e.height||0!==this.overlapY||(this.overlapY=Math.min(Math.abs(t.y-e.y),Math.abs(t.y1-e.y1)))}preventContainment(t,e){if(this.overlapY>0&&(t.y1>e.y1&&t.y<e.y||t.y1<e.y1&&t.y>e.y)){const i=Math.abs(t.y-e.y),s=Math.abs(t.y1-e.y1);this.overlapY+=i<s?i:s}if(this.overlapX>0&&(t.x1>e.x1&&t.x<e.x||t.x1<e.x1&&t.x>e.x)){const i=Math.abs(t.x-e.x),s=Math.abs(t.x1-e.x1);this.overlapX+=i<s?i:s}}};E([c(d.CollisionResolutionPool)],T.prototype,"collisionResolutionPool",void 0),T=E([l(d.CollisionAABBResolver)],T);var P=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let B=class{constructor(){this.closestPoint=new e,this.distance=new e,this.direction=new e}resolve(t,i,o=!1){this.closestPoint.set(s(t.position.x,i.boundingBox.x,i.boundingBox.x1),s(t.position.y,i.boundingBox.y,i.boundingBox.y1)),e.subtract(this.distance,this.closestPoint,t.position);const r=this.distance.x*this.distance.x+this.distance.y*this.distance.y;if(r>t.radius*t.radius)return;const n=Math.sqrt(r);let a;n>0?(e.unit(this.direction,this.distance),a=t.radius-n):a=t.radius+this.setDirectionToNearestFace(t.position,i.boundingBox),o&&e.scale(this.direction,this.direction,-1);const h=this.collisionResolutionPool.get();return h.direction.copy(this.direction),h.penetration=a,h}setDirectionToNearestFace({x:t,y:e},i){const s=t-i.x,o=i.x1-t,r=e-i.y,n=i.y1-e,a=Math.min(s,o,r,n);return a===s?this.direction.set(1,0):a===o?this.direction.set(-1,0):a===r?this.direction.set(0,1):this.direction.set(0,-1),a}};P([c(d.CollisionResolutionPool)],B.prototype,"collisionResolutionPool",void 0),B=P([l(d.CollisionCircumferenceAABBResolver)],B);var D=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let F=class{constructor(){this.distance=new e}resolve(t,i){e.subtract(this.distance,i.position,t.position);const s=t.radius+i.radius,o=this.distance.x*this.distance.x+this.distance.y*this.distance.y;if(o>s*s)return;const r=Math.sqrt(o),n=this.collisionResolutionPool.get();return n.penetration=s-r,r>0?e.unit(n.direction,this.distance):n.direction.set(1,0),n}};D([c(d.CollisionResolutionPool)],F.prototype,"collisionResolutionPool",void 0),F=D([l(d.CollisionCircumferenceResolver)],F);var j=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let U=class{constructor(){this.mergedAxes=[],this.projA={min:0,max:0},this.projB={min:0,max:0},this.smallestAxis=new e,this.distance=new e(1/0,1/0),this.cache=new e}resolve(t,i){this.minOverlap=1/0;const s=t instanceof v,o=!s&&i instanceof v;if(s?this.setCircumferenceAxis(t,i):o&&this.setCircumferenceAxis(i,t),this.mergeProjectionAxes(t,i),0===this.mergedAxes.length)return;for(let r=0;r<this.mergedAxes.length;r++){const n=this.mergedAxes[r];if(s?this.projectCircumferenceOntoAxis(this.projA,t,n):this.projectShapeOntoAxis(this.projA,t,n),o?this.projectCircumferenceOntoAxis(this.projB,i,n):this.projectShapeOntoAxis(this.projB,i,n),this.currentOverlap=Math.min(this.projA.max,this.projB.max)-Math.max(this.projA.min,this.projB.min),this.currentOverlap<0)return;(this.projA.max>this.projB.max&&this.projA.min<this.projB.min||this.projA.max<this.projB.max&&this.projA.min>this.projB.min)&&(this.currentOverlap+=Math.min(Math.abs(this.projA.min-this.projB.min),Math.abs(this.projA.max-this.projB.max))),this.currentOverlap<this.minOverlap&&(this.minOverlap=this.currentOverlap,this.projA.min+this.projA.max<this.projB.min+this.projB.max?this.smallestAxis.copy(n):e.scale(this.smallestAxis,n,-1))}const r=this.collisionResolutionPool.get();return r.direction.copy(this.smallestAxis),r.penetration=this.minOverlap,r}mergeProjectionAxes(t,e){const i=t.projectionAxes,s=e.projectionAxes;this.mergedAxes.length=0;for(let t=0;t<i.length;t++)0===i[t].x&&0===i[t].y||this.mergedAxes.push(i[t]);for(let t=0;t<s.length;t++){const e=s[t];if(0===e.x&&0===e.y)continue;let i=!1;for(let t=0;t<this.mergedAxes.length;t++)if(x(this.mergedAxes[t],e)){i=!0;break}i||this.mergedAxes.push(e)}}projectShapeOntoAxis(t,i,s){t.min=1/0,t.max=-1/0;const o=i.vertices;for(let i=0;i<o.length;i++){const r=e.dot(s,o[i]);r<t.min&&(t.min=r),r>t.max&&(t.max=r)}return t}setCircumferenceAxis(t,i){this.distance.set(1/0,1/0);let s=1/0;const o=i.vertices;for(let i=0;i<o.length;i++){e.subtract(this.cache,o[i],t.position);const r=this.cache.x*this.cache.x+this.cache.y*this.cache.y;r<s&&(s=r,this.distance.copy(this.cache))}e.unit(t.projectionAxes[0],this.distance)}projectCircumferenceOntoAxis(t,{position:i,radius:s},o){const r=e.dot(o,i);t.min=r-s,t.max=r+s}};j([c(d.CollisionResolutionPool)],U.prototype,"collisionResolutionPool",void 0),U=j([l(d.CollisionSatResolver)],U);var L=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let I=class{constructor(){this.pool=[],this.index=0}get(){return this.index>=this.pool.length&&this.pool.push({direction:new e,penetration:0}),this.pool[this.index++]}clear(){this.index=0}};I=L([l(d.CollisionResolutionPool)],I);var O=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};exports.CollisionRepository=class{constructor(){this.collisionPool=[],this.collisionPoolIndex=0,this.collisions=[],this.step=0,this.findCache=new WeakMap}updateCache(t){this.findCache.has(t)||this.findCache.set(t,{step:0,collisions:[]});const i=this.findCache.get(t);i.step!==this.step&&(i.step=this.step,i.collisions=this.collisions.filter((e=>e.localCollider===t||e.remoteCollider===t)).map((i=>((t,i)=>t.localCollider===i?Object.assign(Object.assign({},t),{resolution:{direction:t.resolution.direction.clone(),penetration:t.resolution.penetration}}):{localCollider:t.remoteCollider,localEntity:t.remoteEntity,remoteCollider:t.localCollider,remoteEntity:t.localEntity,resolution:{direction:e.scale(new e,t.resolution.direction,-1),penetration:t.resolution.penetration}})(i,t))))}findCollisionsForCollider(t){return this.updateCache(t),this.findCache.get(t).collisions}findCollisionsForColliderAndLayer(t,e){return this.updateCache(t),this.findCache.get(t).collisions.filter((t=>t.remoteCollider.layer===e))}getCollisions(){return this.collisions}persist(t,e,i,s,{direction:o,penetration:r}){if(this.collisionPoolIndex<this.collisionPool.length){const n=this.collisionPool[this.collisionPoolIndex++];n.localCollider=e,n.localEntity=t,n.remoteCollider=s,n.remoteEntity=i,n.resolution.direction.copy(o),n.resolution.penetration=r,this.collisions.push(n)}else{const n={localCollider:e,localEntity:t,remoteCollider:s,remoteEntity:i,resolution:{direction:o.clone(),penetration:r}};this.collisionPool.push(n),this.collisionPoolIndex++,this.collisions.push(n)}}clear(){this.collisions.length=0,this.collisionPoolIndex=0,this.step++}},exports.CollisionRepository=O([l(d.CollisionRepository)],exports.CollisionRepository);const k=t=>{if(null===t||"object"!=typeof t)return t;if("undefined"!=typeof Node&&t instanceof Node)return t;if("undefined"!=typeof FontFace&&t instanceof FontFace)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array)return t.map((t=>k(t)));if(t instanceof Map){const e=new Map;for(const[i,s]of t)e.set(k(i),k(s));return e}if(t instanceof Set){const e=new Set;for(const i of t)e.add(k(i));return e}const e=Object.getPrototypeOf(t),i=Object.create(e);for(const e of Object.keys(t))i[e]=k(t[e]);return i},G={EntityManager:Symbol.for("EntityManager"),SystemManager:Symbol.for("SystemManager")};var V=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};const N=Symbol("ecs.componentTypeId");let z=0;exports.EntityManager=class{constructor(){this.lastEntityId=0,this.entities=new Set,this.components=new Map,this.entityComponents=new Map,this.componentToEntity=new WeakMap,this.disabledEntities=new Set,this.manuallyDisabledEntities=new Set,this.disabledComponents=new Map,this.parentEntities=new Map,this.childEntities=new Map}createEntity(t,e){if(void 0===t){const t=this.lastEntityId++;return this.entities.add(t),t}return Array.isArray(t)?this.createEntityFromArray(t,e):this.createEntityFromArchetype(t,e)}addArchetype(t,{components:e,disabledComponents:i,children:s,enabled:o}){this.createComponentsForEntity(e,t),i&&this.createComponentsForEntity(i,t,!0),s&&s.forEach((e=>this.createEntityFromArchetype(e,t))),!1===o&&this.disableEntity(t)}createEntityFromArray(t,e){const i=this.createEntity();return this.createComponentsForEntity(t,i),void 0!==e&&this.setParent(i,e),i}createEntityFromArchetype(t,e){const i=this.createEntity();return void 0!==e&&this.setParent(i,e),this.addArchetype(i,t),i}createComponentsForEntity(t,e,i=!1){t.forEach((t=>{let s;if("object"==typeof t)s=this.addComponent(e,k(t));else{if("function"!=typeof t)throw new Error("Invalid component type");s=this.addComponent(e,t)}i&&this.disableComponent(s)}))}removeEntity(t){var e;this.getChildren(t).forEach((t=>this.removeEntity(t)));const i=this.entityComponents.get(t);i&&(i.forEach(((e,i)=>{var s;null===(s=this.components.get(i))||void 0===s||s.delete(t),this.componentToEntity.delete(e)})),this.entityComponents.delete(t)),this.disabledComponents.delete(t),this.disabledEntities.delete(t),this.manuallyDisabledEntities.delete(t);const s=this.getParent(t);void 0!==s&&(null===(e=this.childEntities.get(s))||void 0===e||e.delete(t)),this.parentEntities.delete(t),this.childEntities.delete(t),this.entities.delete(t)}removeAllEntities(t){const e=(null==t?void 0:t.preserveEntitiesWithComponent)?this.search(t.preserveEntitiesWithComponent,!0):[];if(e.length>0){const t=new Set;e.forEach((({entity:e})=>this.addBranch(e,t))),t.forEach((e=>{const i=this.getParent(e);void 0===i||t.has(i)||this.removeParent(e)}));for(const e of this.entities)t.has(e)||this.removeEntity(e)}else this.components.clear(),this.entityComponents.clear(),this.componentToEntity=new WeakMap,this.disabledComponents.clear(),this.disabledEntities.clear(),this.manuallyDisabledEntities.clear(),this.lastEntityId=0,this.entities.clear(),this.parentEntities.clear(),this.childEntities.clear()}addBranch(t,e){e.add(t),this.getChildren(t).forEach((t=>this.addBranch(t,e)))}isEntity(t){return this.entities.has(t)}isEntityEnabled(t){return this.isEntity(t)&&!this.disabledEntities.has(t)}enableEntity(t){this.disabledEntities.has(t)&&(this.disabledEntities.delete(t),this.getChildren(t).forEach((t=>{this.manuallyDisabledEntities.has(t)||this.enableEntity(t)})))}disableEntity(t){this.disabledEntities.has(t)||(this.disabledEntities.add(t),this.getChildren(t).forEach((t=>{this.disabledEntities.has(t)?this.manuallyDisabledEntities.add(t):this.disableEntity(t)})))}disableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.disableEntity(s)}enableEntitiesByComponent(t){var e,i;for(const s of null!==(i=null===(e=this.components.get(this.getComponentTypeId(t)))||void 0===e?void 0:e.keys())&&void 0!==i?i:[])this.enableEntity(s)}setParent(t,e){if(!this.isEntity(t)||!this.isEntity(e))throw new Error("Both entities must exist to set a parent-child relationship.");if(this.parentEntities.has(t)){const i=this.parentEntities.get(t);if(i===e)return;this.childEntities.get(i).delete(t)}this.parentEntities.set(t,e),this.childEntities.has(e)||this.childEntities.set(e,new Set),this.childEntities.get(e).add(t)}getParent(t){return this.parentEntities.get(t)}getChildren(t){return Array.from(this.childEntities.get(t)||[])}removeParent(t){const e=this.parentEntities.get(t);void 0!==e&&(this.parentEntities.delete(t),this.childEntities.get(e).delete(t))}removeChild(t,e){this.parentEntities.get(e)===t&&(this.parentEntities.delete(e),this.childEntities.get(t).delete(e))}addComponent(t,e){var i;const s=this.getComponentTypeId(e),o="object"==typeof e?e:new e;if(this.components.has(s)||this.components.set(s,new Map),this.components.get(s).has(t)){const e=null!==(i=o.constructor.componentName)&&void 0!==i?i:o.constructor.name;throw new Error(`Entity ${t} already has a component of type ${e}`)}this.components.get(s).set(t,o);let r=this.entityComponents.get(t);return r||(r=new Map,this.entityComponents.set(t,r)),r.set(s,o),this.componentToEntity.set(o,t),o}hasComponent(t,e){var i,s;return null!==(s=null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.has(t))&&void 0!==s&&s}getComponent(t,e){var i;return null===(i=this.components.get(this.getComponentTypeId(e)))||void 0===i?void 0:i.get(t)}getComponents(t){const e=this.entityComponents.get(t);return e?Array.from(e.values()):[]}updateComponentData(t,e,i){const s=this.getComponent(t,e);s&&i(s)}getEntityForComponent(t){return this.componentToEntity.get(t)}removeComponent(t,e){const i=this.getComponentTypeId("object"==typeof t?t:e),s="number"==typeof t?t:this.getEntityForComponent(t);if(void 0===s)return;const o=this.components.get(i),r=null==o?void 0:o.get(s);if(void 0===r)return;o.delete(s),this.componentToEntity.delete(r);const n=this.entityComponents.get(s);n&&(n.delete(i),0===n.size&&this.entityComponents.delete(s))}isComponentEnabled(t,e){var i,s;const o=this.getComponentTypeId("object"==typeof t?t:e);if("number"==typeof t&&!(null===(i=this.components.get(o))||void 0===i?void 0:i.has(t)))return!1;const r="number"==typeof t?t:this.getEntityForComponent(t);return void 0!==r&&!(null===(s=this.disabledComponents.get(r))||void 0===s?void 0:s.has(o))}disableComponent(t,e){const i="number"==typeof t?t:this.getEntityForComponent(t),s=this.getComponentTypeId("object"==typeof t?t:e);null!=i&&(this.disabledComponents.has(i)?this.disabledComponents.get(i).has(s)||this.disabledComponents.get(i).add(s):this.disabledComponents.set(i,new Set([s])))}enableComponent(t,e){var i;const s="number"==typeof t?t:this.getEntityForComponent(t),o=this.getComponentTypeId("object"==typeof t?t:e);void 0!==s&&(null===(i=this.disabledComponents.get(s))||void 0===i?void 0:i.has(o))&&this.disabledComponents.get(s).delete(o)}getComponentFromParent(t,e){let i=t;for(;i;){const t=this.getComponent(i,e);if(t)return t;i=this.getParent(i)}}search(t,e,i=!1){var s,o;const r=this.getComponentTypeId(t),n="function"==typeof e?e:void 0,a="boolean"==typeof e?e:i,h=this.components.get(r);if(!h)return n?void 0:[];if(n){for(const[t,e]of h)(a||!this.disabledEntities.has(t)&&!(null===(s=this.disabledComponents.get(t))||void 0===s?void 0:s.has(r)))&&n(e,t);return}const l=[];for(const[t,e]of h)(a||!this.disabledEntities.has(t)&&!(null===(o=this.disabledComponents.get(t))||void 0===o?void 0:o.has(r)))&&l.push({entity:t,component:e});return l}searchEntitiesByComponents(t){if(0===t.length)return[];const e=[];for(const i of t){const t=this.getComponentTypeId(i),s=this.components.get(t);if(!s||0===s.size)return[];e.push(s)}e.sort(((t,e)=>t.size-e.size));const[i,...s]=e,o=[];for(const t of i.keys()){let e=!0;for(const i of s)if(!i.has(t)){e=!1;break}e&&o.push(t)}return o}searchInChildren(t,e,i=!1){const s=new Set(this.getChildren(t));return this.search(e,i).filter((({entity:t})=>s.has(t)))}getComponentTypeId(t){const e="object"==typeof t?t.constructor:t;return void 0===e[N]&&(e[N]=++z),e[N]}},exports.EntityManager=V([l(G.EntityManager)],exports.EntityManager);var W,H=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};exports.SystemManager=class{constructor(){this.systems=[]}findSystemIndex(t){return this.systems.findIndex((e=>e[0]instanceof t))}addSystem(t,e){if(this.systems.some((t=>t[0]instanceof t.constructor)))throw new Error(`SystemManager already has an instance of ${t.constructor.name}.`);this.systems.push([t,e,!1])}hasSystem(t){return this.systems.some((e=>e[0]instanceof t))}getSystem(t){const e=this.findSystemIndex(t);return-1!==e?this.systems[e][0]:void 0}groupHasSystems(t){return this.systems.filter((e=>e[1]===t)).length>0}enableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!0===this.systems[e][2])return;this.systems[e][2]=!0}disableSystem(t){const e=this.findSystemIndex(t);if(-1===e||!1===this.systems[e][2])return;this.systems[e][2]=!1}setExecutionOrder(t,e){const i=this.findSystemIndex(t);if(-1===i)throw new Error(`Cannot set execution order because ${t.name} is not a system.`);this.systems.splice(e,0,this.systems.splice(i,1)[0])}removeSystem(t){const e=this.findSystemIndex(t);-1!==e&&this.systems.splice(e,1)}disableAllSystems(){this.systems.forEach((t=>{t[2]&&this.disableSystem(t[0].constructor)}))}update(t){this.systems.filter((e=>e[1]===t&&!0===e[2])).forEach((t=>t[0].onUpdate()))}},exports.SystemManager=H([l(G.SystemManager)],exports.SystemManager),function(t){t.LegacyWebGL="webgl",t.WebGL2="webgl2"}(W||(W={}));class Y{constructor(t){if(this.canvas=t,this.contextVersion=this.getContextVersion(),!this.contextVersion)throw new Error("Your browser does not support WebGL.");this.gl=this.canvas.getContext(this.contextVersion)}getContextVersion(){return null!==this.canvas.getContext(W.WebGL2)?W.WebGL2:null!==this.canvas.getContext(W.LegacyWebGL)?W.LegacyWebGL:void 0}}class ${constructor(){this.fontAtlas=new Map}hasFontAtlas(t){return this.fontAtlas.has(this.getId(t))}getFontAtlas(t){return this.fontAtlas.get(this.getId(t))}getOrCreate(t){var e;return null!==(e=this.getFontAtlas(t))&&void 0!==e?e:this.create(t)}create(t){const{font:e,charRanges:i,fontSize:s,spacing:o}=t;this.chars=[];for(let t=0;t<i.length;t+=2)for(let e=i[t];e<=i[t+1];e++)this.chars.push(String.fromCharCode(e));this.font=e instanceof FontFace?e.family:e,this.fontSize=s,this.spacing=o,this.id=this.getId(t);const r=this.renderAtlas();return this.fontAtlas.set(this.id,r),r}getId({font:t,charRanges:e,fontSize:i,spacing:s}){return JSON.stringify({font:t instanceof FontFace?t.family:t,charRanges:e,fontSize:i,spacing:s})}renderAtlas(){const t=new X(this.id,this.fontSize,Math.ceil(Math.sqrt(this.chars.length)),this.spacing),e=t.canvas.getContext("2d");e.clearRect(0,0,t.canvas.width,t.canvas.height),e.textBaseline="top",e.fillStyle="#FFFFFF",e.font=`${this.fontSize}px ${this.font}`;let i=0,s=0;for(let o=0;o<this.chars.length;o++)e.fillText(this.chars[o],i,s),t.glyphs.set(this.chars[o],{id:o,width:e.measureText(this.chars[o]).width}),(i+=this.fontSize+this.spacing)>t.canvas.width-this.fontSize&&(i=0,s+=this.fontSize+this.spacing);return t}}class X{constructor(t,e,i,s){this.id=t,this.fontSize=e,this.gridSize=i,this.spacing=s,this.canvas=document.createElement("canvas"),this.glyphs=new Map,this.canvas.width=this.gridSize*(this.fontSize+this.spacing),this.canvas.height=this.canvas.width}}class q{constructor(t,e){this.gl=t,this.shaderLoader=e}create(t,e){const i=this.gl.createProgram(),s=this.shaderLoader.load(this.gl.VERTEX_SHADER,t),o=this.shaderLoader.load(this.gl.FRAGMENT_SHADER,e);this.gl.attachShader(i,s),this.gl.attachShader(i,o),this.gl.linkProgram(i);const r=this.gl.LINK_STATUS;if(!this.gl.getProgramParameter(i,r)){const t=this.gl.getProgramInfoLog(i);throw this.gl.deleteProgram(i),new Error(`Unable to initialize the Program: ${t}`)}return i}}class K{constructor(t,e,i){this.gl=t,this.contextVersion=e,this.programFactory=i}loadProgram(){const t=this.gl.getParameter(this.gl.MAX_FRAGMENT_UNIFORM_VECTORS);var e;this.maxLights=Math.max(1,Math.min(256,Math.floor((t-16)/2))),this.program=this.contextVersion===W.WebGL2?this.programFactory.create("#version 300 es\n\nin vec4 positionCoords;\nin vec2 textureCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nout vec2 texCoords;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * positionCoords;\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}",`#version 300 es\nprecision highp float;\n\nin vec2 texCoords;\n\n// texture, mask and darkness\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light, packed in vec4 so each light takes exactly two uniform vectors\nuniform int u_renderLight;\n// xy: position, z: radius, w: steps (0 means a continuous fade, 1 means a hard edge)\nuniform vec4 u_lightGeometry[${e=this.maxLights}];\n// rgb: glow color, a: intensity\nuniform vec4 u_lightColor[${e}];\nuniform int u_numLights;\n// screen pixels per light pixel\nuniform float u_lightPixelSize;\n// screen position of the world origin\nuniform vec2 u_lightGridOrigin;\n\nout vec4 fragColor;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n fragColor = vec4(texColor.rgb, u_alpha * texColor.a); \n } else if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n vec3 glow = vec3(0.0);\n\n // every fragment in a light pixel uses the center of that pixel\n fragCoord = (floor((fragCoord - u_lightGridOrigin) / u_lightPixelSize) + 0.5) * u_lightPixelSize + u_lightGridOrigin;\n\n for (int i = 0; i < u_numLights; i++) {\n vec4 geometry = u_lightGeometry[i];\n vec4 color = u_lightColor[i];\n float dist = distance(fragCoord, geometry.xy);\n\n if (dist < geometry.z) {\n float falloff = 1.0 - smoothstep(0.0, geometry.z, dist);\n // the outer ring is kept even if the falloff rounds to 0 near the edge\n if (geometry.w > 0.0) falloff = max(ceil(falloff * geometry.w), 1.0) / geometry.w;\n\n alpha -= falloff * color.a;\n glow += color.rgb * falloff * color.a;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n // premultiplied alpha output, see the blend function in the DarknessRenderer\n fragColor = vec4(u_solidColor.rgb * alpha + glow, alpha);\n } else {\n fragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}`):this.programFactory.create("precision mediump float;\n\nattribute vec2 positionCoords;\nattribute vec2 textureCoords;\n\nvarying vec2 texCoords;\n\nuniform mat4 projectionMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 textureMatrix;\n\nvoid main()\n{\n gl_Position = projectionMatrix * modelMatrix * vec4(positionCoords, 0, 1);\n texCoords = (textureMatrix * vec4(textureCoords, 0, 1)).xy;\n}",(t=>`precision mediump float;\n\nvarying vec2 texCoords;\n\n// texture, mask and darkness\nuniform int u_renderTexture;\nuniform sampler2D u_texImage;\nuniform vec4 u_solidColor;\nuniform int u_useTintColor;\nuniform vec4 u_tintColor;\nuniform int u_useMaskColor;\nuniform vec4 u_maskColor;\nuniform float u_maskColorMix;\nuniform float u_alpha;\n\n// light, packed in vec4 so each light takes exactly two uniform vectors\nuniform int u_renderLight;\n// xy: position, z: radius, w: steps (0 means a continuous fade, 1 means a hard edge)\nuniform vec4 u_lightGeometry[${t}];\n// rgb: glow color, a: intensity\nuniform vec4 u_lightColor[${t}];\nuniform int u_numLights;\n// screen pixels per light pixel\nuniform float u_lightPixelSize;\n// screen position of the world origin\nuniform vec2 u_lightGridOrigin;\n\nvoid main()\n{\n if (u_renderTexture == 1) {\n vec4 texColor = texture2D(u_texImage, texCoords);\n\n if (texColor.a < 0.0001) {\n discard;\n }\n\n if (u_useTintColor == 1) {\n texColor = u_tintColor * texColor;\n }\n\n if (u_useMaskColor == 1) {\n texColor = mix(texColor, u_maskColor, clamp(u_maskColorMix, 0.0, 1.0));\n }\n\n gl_FragColor = vec4(texColor.rgb, u_alpha * texColor.a);\n } else if (u_renderLight == 1) {\n vec2 fragCoord = gl_FragCoord.xy;\n float alpha = u_alpha;\n vec3 glow = vec3(0.0);\n\n // every fragment in a light pixel uses the center of that pixel\n fragCoord = (floor((fragCoord - u_lightGridOrigin) / u_lightPixelSize) + 0.5) * u_lightPixelSize + u_lightGridOrigin;\n\n for (int i = 0; i < ${t}; i++) {\n if (i >= u_numLights) break;\n \n vec4 geometry = u_lightGeometry[i];\n vec4 color = u_lightColor[i];\n float dist = distance(fragCoord, geometry.xy);\n\n if (dist < geometry.z) {\n float falloff = 1.0 - smoothstep(0.0, geometry.z, dist);\n // the outer ring is kept even if the falloff rounds to 0 near the edge\n if (geometry.w > 0.0) falloff = max(ceil(falloff * geometry.w), 1.0) / geometry.w;\n\n alpha -= falloff * color.a;\n glow += color.rgb * falloff * color.a;\n }\n }\n\n alpha = clamp(alpha, 0.0, u_alpha);\n\n // premultiplied alpha output, see the blend function in the DarknessRenderer\n gl_FragColor = vec4(u_solidColor.rgb * alpha + glow, alpha);\n } else {\n gl_FragColor = vec4(u_solidColor.rgb, u_alpha);\n }\n}`)(this.maxLights)),this.positionCoordsAttr=this.gl.getAttribLocation(this.program,"positionCoords"),this.texCoordsAttr=this.gl.getAttribLocation(this.program,"textureCoords"),this.modelMatrixUniform=this.gl.getUniformLocation(this.program,"modelMatrix"),this.projectionMatrixUniform=this.gl.getUniformLocation(this.program,"projectionMatrix"),this.textureMatrixUniform=this.gl.getUniformLocation(this.program,"textureMatrix"),this.renderTextureUniform=this.gl.getUniformLocation(this.program,"u_renderTexture"),this.textureUniform=this.gl.getUniformLocation(this.program,"u_texImage"),this.solidColorUniform=this.gl.getUniformLocation(this.program,"u_solidColor"),this.useTintColorUniform=this.gl.getUniformLocation(this.program,"u_useTintColor"),this.tintColorUniform=this.gl.getUniformLocation(this.program,"u_tintColor"),this.useMaskColorUniform=this.gl.getUniformLocation(this.program,"u_useMaskColor"),this.maskColorUniform=this.gl.getUniformLocation(this.program,"u_maskColor"),this.maskColorMixUniform=this.gl.getUniformLocation(this.program,"u_maskColorMix"),this.alphaUniform=this.gl.getUniformLocation(this.program,"u_alpha"),this.renderLightUniform=this.gl.getUniformLocation(this.program,"u_renderLight"),this.numLightsUniform=this.gl.getUniformLocation(this.program,"u_numLights"),this.lightPixelSizeUniform=this.gl.getUniformLocation(this.program,"u_lightPixelSize"),this.lightGridOriginUniform=this.gl.getUniformLocation(this.program,"u_lightGridOrigin"),this.lightGeometryUniform=this.gl.getUniformLocation(this.program,"u_lightGeometry"),this.lightColorUniform=this.gl.getUniformLocation(this.program,"u_lightColor"),this.gl.useProgram(this.program),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)}}class J{constructor(t){this.gl=t}load(t,e){const i=this.gl.createShader(t);this.gl.shaderSource(i,e),this.gl.compileShader(i);const s=this.gl.COMPILE_STATUS;if(!this.gl.getShaderParameter(i,s)){const t=this.gl.getShaderInfoLog(i);throw this.gl.deleteShader(i),new Error(`Unable to initialize the shader program: ${t}`)}return i}}var Q="undefined"!=typeof Float32Array?Float32Array:Array;function Z(){var t=new Q(16);return Q!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function tt(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function et(t,e,i){var s,o,r,n,a,h,l,c,d,g,p,u,m=i[0],f=i[1],y=i[2];return e===t?(t[12]=e[0]*m+e[4]*f+e[8]*y+e[12],t[13]=e[1]*m+e[5]*f+e[9]*y+e[13],t[14]=e[2]*m+e[6]*f+e[10]*y+e[14],t[15]=e[3]*m+e[7]*f+e[11]*y+e[15]):(s=e[0],o=e[1],r=e[2],n=e[3],a=e[4],h=e[5],l=e[6],c=e[7],d=e[8],g=e[9],p=e[10],u=e[11],t[0]=s,t[1]=o,t[2]=r,t[3]=n,t[4]=a,t[5]=h,t[6]=l,t[7]=c,t[8]=d,t[9]=g,t[10]=p,t[11]=u,t[12]=s*m+a*f+d*y+e[12],t[13]=o*m+h*f+g*y+e[13],t[14]=r*m+l*f+p*y+e[14],t[15]=n*m+c*f+u*y+e[15]),t}function it(t,e,i){var s=i[0],o=i[1],r=i[2];return t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t[3]=e[3]*s,t[4]=e[4]*o,t[5]=e[5]*o,t[6]=e[6]*o,t[7]=e[7]*o,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function st(t,e,i){var s=Math.sin(i),o=Math.cos(i),r=e[0],n=e[1],a=e[2],h=e[3],l=e[4],c=e[5],d=e[6],g=e[7];return e!==t&&(t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=r*o+l*s,t[1]=n*o+c*s,t[2]=a*o+d*s,t[3]=h*o+g*s,t[4]=l*o-r*s,t[5]=c*o-n*s,t[6]=d*o-a*s,t[7]=g*o-h*s,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var ot=function(t,e,i,s,o,r,n){var a=1/(e-i),h=1/(s-o),l=1/(r-n);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*h,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*l,t[11]=0,t[12]=(e+i)*a,t[13]=(o+s)*h,t[14]=(n+r)*l,t[15]=1,t};const rt=(t,e,i,s)=>{t=tt(t),ot(t,-e.canvas.width/2,e.canvas.width/2,-e.canvas.height/2,e.canvas.height/2,-1,1),it(t,t,[null!=i?i:1,null!=i?i:1,1]),et(t,t,[-s.x,-s.y,0])},nt=new Map,at=t=>{const e=nt.get(t);if(void 0!==e)return e;const i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(t);if(!i)throw new Error(`Invalid hex color: ${t}`);const s=Object.freeze({r:parseInt(i[1],16)/255,g:parseInt(i[2],16)/255,b:parseInt(i[3],16)/255,a:void 0!==i[4]?parseInt(i[4],16)/255:1});return nt.size>=1024&&nt.clear(),nt.set(t,s),s};class ht{constructor(t){this.gl=t}render(t){const e=at(t);this.gl.clearColor(e.r,e.g,e.b,e.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}}var lt;!function(t){t[t.Sprite=0]="Sprite",t[t.Text=1]="Text",t[t.Tilemap=2]="Tilemap",t[t.Mask=3]="Mask",t[t.Geometric=4]="Geometric",t[t.Video=5]="Video",t[t.Darkness=6]="Darkness"}(lt||(lt={}));var ct;exports.GeometricShape=void 0,(ct=exports.GeometricShape||(exports.GeometricShape={}))[ct.Polygon=0]="Polygon",ct[ct.Circumference=1]="Circumference",ct[ct.Line=2]="Line";let dt=class{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.circumferencePositionBuffer=this.gl.createBuffer(),this.linesPositionBuffer=this.gl.createBuffer();const i=2*Math.PI/60,s=new Float32Array(r(1,60,1).reduce(((t,e)=>[...t,Math.cos(e*i),Math.sin(e*i)]),[]));this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,s,this.gl.STATIC_DRAW)}render(t,e,i){switch(this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr),t.shape){case exports.GeometricShape.Polygon:this.renderLines(t,e,this.gl.LINE_LOOP);break;case exports.GeometricShape.Line:this.renderLines(t,e,this.gl.LINES);break;case exports.GeometricShape.Circumference:this.renderCircumference(t,e,i);break;default:return!1}return!0}renderLines(t,e,i){var s;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.linesPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertexModel.reduce(((t,e)=>[...t,e.x,e.y]),[])),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:o,g:r,b:n,a:a}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,o,r,n,a),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(i,0,t.vertexModel.length),this.lastShape="polygon"}renderCircumference(t,e,i){i===lt.Geometric&&"circumference"===this.lastShape||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),it(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:s,g:o,b:r,a:n}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,s,o,r,n),this.gl.uniform1f(this.programManager.alphaUniform,1),this.gl.drawArrays(this.gl.LINE_LOOP,0,60),this.lastShape="circumference"}};var gt;exports.MaskShape=void 0,(gt=exports.MaskShape||(exports.MaskShape={}))[gt.Rectangle=0]="Rectangle",gt[gt.Circumference=1]="Circumference",gt[gt.Polygon=2]="Polygon";let pt=class{constructor(t,e){this.gl=t,this.programManager=e,this.type=lt.Mask,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.circumferencePositionBuffer=this.gl.createBuffer(),this.rectanglePositionBuffer=this.gl.createBuffer(),this.polygonPositionBuffer=this.gl.createBuffer();const i=2*Math.PI/60,s=[0,0];for(let t=0;t<=60;t++)s.push(Math.cos(t*i),Math.sin(t*i));this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(s),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.rectanglePositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW)}render(t,e,i){return this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr),t.shape===exports.MaskShape.Rectangle?this.renderRectangle(t,e,i):t.shape===exports.MaskShape.Circumference?this.renderCircumference(t,e,i):t.shape===exports.MaskShape.Polygon&&this.renderPolygon(t,e,i),this.lastShape=t.shape,!0}renderRectangle(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Rectangle||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.rectanglePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLES,0,6)}renderCircumference(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Circumference||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.circumferencePositionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.radius,t.radius,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,62)}renderPolygon(t,e,i){var s,o;i===lt.Mask&&this.lastShape===exports.MaskShape.Polygon||(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.polygonPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(t.vertices.reduce(((t,e)=>[...t,e.x,e.y]),[0,0])),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),t.opacity>=0&&t.opacity<1?this.gl.enable(this.gl.BLEND):this.gl.disable(this.gl.BLEND),this.gl.uniform1i(this.programManager.renderTextureUniform,0);const{r:r,g:n,b:a,a:h}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,r,n,a,h),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.drawArrays(this.gl.TRIANGLE_FAN,0,t.vertices.length+1)}},ut=class{constructor(t,e){this.gl=t,this.programManager=e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW)}render(t,e,i){var s,o,r,n,a,h,l;i!==lt.Darkness&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.disableVertexAttribArray(this.programManager.texCoordsAttr)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width,t.height,1]),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND),this.gl.blendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.uniform1i(this.programManager.renderTextureUniform,0),this.gl.uniform1i(this.programManager.renderLightUniform,1);const{r:c,g:d,b:g,a:p}=at(t.color);this.gl.uniform4f(this.programManager.solidColorUniform,c,d,g,p),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1f(this.programManager.lightPixelSizeUniform,e.zoom),this.gl.uniform2f(this.programManager.lightGridOriginUniform,this.gl.canvas.width/2-e.position.x*e.zoom,this.gl.canvas.height/2-e.position.y*e.zoom),(null===(r=this.lightGeometryData)||void 0===r?void 0:r.length)!==4*this.programManager.maxLights&&(this.lightGeometryData=new Float32Array(4*this.programManager.maxLights),this.lightColorData=new Float32Array(4*this.programManager.maxLights));let u=0;for(let i=0;i<t.lights.length&&u<this.programManager.maxLights;i++){const s=t.lights[i],o=this.gl.canvas.width/2+(Math.round(s.position.x)-e.position.x)*e.zoom,r=this.gl.canvas.height/2+(Math.round(s.position.y)-e.position.y)*e.zoom,c=s.radius*e.zoom,d=c+e.zoom;if(o+d<0||o-d>this.gl.canvas.width||r+d<0||r-d>this.gl.canvas.height)continue;const g=4*u++;this.lightGeometryData[g]=o,this.lightGeometryData[g+1]=r,this.lightGeometryData[g+2]=c,this.lightGeometryData[g+3]=s.smooth?Math.max(0,Math.round(null!==(n=s.steps)&&void 0!==n?n:0)):1;const p=s.color?at(s.color):void 0;this.lightColorData[g]=null!==(a=null==p?void 0:p.r)&&void 0!==a?a:0,this.lightColorData[g+1]=null!==(h=null==p?void 0:p.g)&&void 0!==h?h:0,this.lightColorData[g+2]=null!==(l=null==p?void 0:p.b)&&void 0!==l?l:0,this.lightColorData[g+3]=Math.max(0,Math.min(1,s.intensity))}return this.gl.uniform1i(this.programManager.numLightsUniform,u),this.gl.uniform4fv(this.programManager.lightGeometryUniform,this.lightGeometryData),this.gl.uniform4fv(this.programManager.lightColorUniform,this.lightColorData),this.gl.drawArrays(this.gl.TRIANGLES,0,6),this.gl.uniform1i(this.programManager.renderLightUniform,0),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),!0}},mt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.tiledPosVertices=new Map,this.tiledTexVertices=new Map,this.isTiled=!1,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.tiledPositionBuffer=this.gl.createBuffer(),this.tiledTextureBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0]),this.gl.STATIC_DRAW),this.lastDrawMode="sprite"}render(t,e,i){var s,o,r,n;this.isTiled=t.tiled&&(t.tiled.x>1||t.tiled.y>1),this.isTiled||i===lt.Sprite&&"sprite"===this.lastDrawMode?this.isTiled&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.tiledPositionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getTiledPositionVertices(t.tiled),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.tiledTextureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,this.getTiledTextureVertices(t.tiled),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)):(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.lastDrawMode=this.isTiled?"tiled":"sprite",this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontally?-1:1),t.height*(t.flipVertically?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),t.slice&&(et(this.textureMatrix,this.textureMatrix,[t.slice.x/t.image.naturalWidth,t.slice.y/t.image.naturalHeight,0]),it(this.textureMatrix,this.textureMatrix,[t.slice.width/t.image.naturalWidth,t.slice.height/t.image.naturalHeight,1])),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.image,t.smooth);if(this.lastTexture===a&&i===t.type||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.isTiled?this.gl.drawArrays(this.gl.TRIANGLES,0,t.tiled.x*t.tiled.y*6):this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}getTiledPositionVertices(t){const e=t.toString();if(!this.tiledPosVertices.has(e)){const i=[];for(let e=-t.x/2;e<t.x/2;e++)for(let s=-t.y/2;s<t.y/2;s++)i.push(e,s,e,s+1,e+1,s,e+1,s,e,s+1,e+1,s+1);this.tiledPosVertices.set(e,new Float32Array(i))}return this.tiledPosVertices.get(e)}getTiledTextureVertices(t){const e=t.toString();if(!this.tiledTexVertices.has(e)){const i=[];for(let e=0;e<t.x*t.y;e++)i.push(0,1,0,0,1,1,1,1,0,0,1,0);this.tiledTexVertices.set(e,new Float32Array(i))}return this.tiledTexVertices.get(e)}};var ft;exports.TextAlignment=void 0,(ft=exports.TextAlignment||(exports.TextAlignment={}))[ft.Center=0]="Center",ft[ft.Right=1]="Right",ft[ft.Left=2]="Left";let yt=class{constructor(t,i,s,o){this.gl=t,this.programManager=i,this.textureManager=s,this.fontAtlasFactory=o,this.type=lt.Text,this.posVertices=[],this.texVertices=[],this.shadowPosition=new e,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer()}render(t,i,s,o=!1){var r;if(!t.text)return!1;const n=this.fontAtlasFactory.getOrCreate(Object.assign({font:t.font},t.textureAtlas));if(o||(this.generateTextVertices(n,t),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),t.shadow){const{color:o,offset:r,opacity:n}=t.shadow,a=Object.assign(Object.assign({},t),{color:o,opacity:n*t.opacity,position:e.add(this.shadowPosition,t.position,r)});a.shadow=void 0,this.render(a,i,s,!0),s=lt.Text}this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(r=t.rotation)&&void 0!==r?r:0),it(this.modelMatrix,this.modelMatrix,[t.fontSize*(t.flipHorizontally?-1:1),t.fontSize*(t.flipVertically?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),rt(this.projectionMatrix,this.gl,i.zoom,i.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromCanvas(n.id,n.canvas,t.smooth);this.lastTexture===a&&s===lt.Text||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.useMaskColorUniform,0),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,t.opacity);const{r:h,g:l,b:c,a:d}=at(t.color);return this.gl.uniform1i(this.programManager.useTintColorUniform,1),this.gl.uniform4f(this.programManager.tintColorUniform,h,l,c,d),this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}generateTextVertices(t,e){this.posVertices=[],this.texVertices=[];const i=this.preProcessText(t,e),s=e.letterSpacing/e.fontSize,o=e.lineHeight/e.fontSize,r=e.boundingBox.height/e.fontSize,n=e.boundingBox.width/e.fontSize;let a=r/2;for(const r of i){const{text:i,width:h}=r;let l=e.alignment===exports.TextAlignment.Center?-h/2:e.alignment===exports.TextAlignment.Left?-n/2:n/2-h;for(const e of i){const i=t.glyphs.get(e);if(i){const e=i.width/t.fontSize;this.posVertices.push(l,a-1,l+e,a-1,l,a,l,a,l+e,a-1,l+e,a);const o=i.id%t.gridSize*(t.fontSize+t.spacing),r=(i.id/t.gridSize|0)*(t.fontSize+t.spacing),n=o/t.canvas.width,h=r/t.canvas.height,c=(o+i.width)/t.canvas.width,d=(r+t.fontSize)/t.canvas.height;this.texVertices.push(n,d,c,d,n,h,n,h,c,d,c,h),l+=e+s}}l=-n/2,a-=o}}preProcessText(t,{text:e,fontSize:i,letterSpacing:s,lineHeight:o,boundingBox:{width:r,height:n}}){const a=[];s/=i,o/=i,r/=i,n/=i;const h=t.glyphs.get(" ").width/t.fontSize+s;let l=0;const c=e.split("\n");for(const e of c){let i=[],c=0;l+=o;const d=e.split(" ");for(const e of d){if(l>n)return a;const d=0===i.length;let g=0;for(const i of e){const e=t.glyphs.get(i);e&&(g+=e.width/t.fontSize+s)}g-=s,d||(g+=h),d&&g>=r?(a.push({width:g,text:e}),l+=o):c+g===r?(i.push(e),a.push({width:c+g,text:i.join(" ")}),i=[],c=0,l+=o):c+g>r?(a.push({width:c,text:i.join(" ")}),i=[e],c=g-h,l+=o):(c+=g,i.push(e))}i.length>0&&a.push({width:c,text:i.join(" ")})}return a}};var xt;exports.TilemapOrientation=void 0,(xt=exports.TilemapOrientation||(exports.TilemapOrientation={}))[xt.Center=0]="Center",xt[xt.RightUp=1]="RightUp",xt[xt.RightDown=2]="RightDown",xt[xt.RightCenter=3]="RightCenter";let Mt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.posVertices=[],this.texVertices=[],this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer()}render(t,e,i){var s,o,r,n;if(this.processTileset(t.tileset),this.generateVertices(t),0===this.posVertices.length)return!1;this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.posVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(this.texVertices),this.gl.DYNAMIC_DRAW),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.tilemap.tileWidth*(t.flipHorizontal?-1:1),t.tilemap.tileHeight*(t.flipVertical?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromImage(t.tileset.image,t.smooth);if(this.lastTexture===a&&i===lt.Tilemap||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,this.posVertices.length/2),!0}processTileset(t){var i,s,o,r;if(t._texData)return;const{naturalWidth:n,naturalHeight:a}=t.image;if(!n||!a)return;const h=null!==(i=t.margin)&&void 0!==i?i:0,l=null!==(s=t.spacing)&&void 0!==s?s:0,c=Math.floor((n-2*h+l)/(t.tileWidth+l)),d=Math.floor((a-2*h+l)/(t.tileHeight+l));t._texData={columns:c,firstgid:null!==(o=t.firstgid)&&void 0!==o?o:1,tileCount:null!==(r=t.tileCount)&&void 0!==r?r:c*d,margin:new e(h/n,h/a),step:new e((t.tileWidth+l)/n,(t.tileHeight+l)/a),tileSize:new e(t.tileWidth/n,t.tileHeight/a)}}generateVertices({tiles:t,tilemap:e,tileset:i}){if(this.posVertices=[],this.texVertices=[],!i._texData)return;const{columns:s,firstgid:o,tileCount:r,margin:n,step:a,tileSize:h}=i._texData,l=Math.floor(t.length/e.width);t.forEach(((t,c)=>{var d,g;if(t<o||t>=o+r)return;const p=null!==(g=null===(d=i._animationState)||void 0===d?void 0:d.get(t))&&void 0!==g?g:t,u=c%e.width-e.width/2,m=l/2-Math.floor(c/e.width);this.posVertices.push(u,m-1,u+1,m-1,u,m,u,m,u+1,m-1,u+1,m);const f=n.x+(p-o)%s*a.x,y=n.y+Math.floor((p-o)/s)*a.y;this.texVertices.push(f,y+h.y,f+h.x,y+h.y,f,y,f,y,f+h.x,y+h.y,f+h.x,y)}))}},vt=class{constructor(t,e,i){this.gl=t,this.programManager=e,this.textureManager=i,this.projectionMatrix=Z(),this.modelMatrix=Z(),this.textureMatrix=Z(),this.positionBuffer=this.gl.createBuffer(),this.textureBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,.5,.5,.5]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,1,0,0,1,1,1,1,0,0,1,0]),this.gl.STATIC_DRAW)}render(t,e,i){var s,o,r,n;i!==lt.Video&&(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.positionBuffer),this.gl.enableVertexAttribArray(this.programManager.positionCoordsAttr),this.gl.vertexAttribPointer(this.programManager.positionCoordsAttr,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.textureBuffer),this.gl.enableVertexAttribArray(this.programManager.texCoordsAttr),this.gl.vertexAttribPointer(this.programManager.texCoordsAttr,2,this.gl.FLOAT,!1,0,0)),this.modelMatrix=tt(this.modelMatrix),et(this.modelMatrix,this.modelMatrix,[t.position.x,t.position.y,0]),st(this.modelMatrix,this.modelMatrix,null!==(s=t.rotation)&&void 0!==s?s:0),it(this.modelMatrix,this.modelMatrix,[t.width*(t.flipHorizontal?-1:1),t.height*(t.flipVertical?-1:1),1]),this.textureMatrix=tt(this.textureMatrix),t.slice&&(et(this.textureMatrix,this.textureMatrix,[t.slice.x/t.video.videoWidth,t.slice.y/t.video.videoHeight,0]),it(this.textureMatrix,this.textureMatrix,[t.slice.width/t.video.videoWidth,t.slice.height/t.video.videoHeight,1])),rt(this.projectionMatrix,this.gl,e.zoom,e.position),this.gl.uniformMatrix4fv(this.programManager.projectionMatrixUniform,!1,this.projectionMatrix),this.gl.uniformMatrix4fv(this.programManager.modelMatrixUniform,!1,this.modelMatrix),this.gl.uniformMatrix4fv(this.programManager.textureMatrixUniform,!1,this.textureMatrix),this.gl.enable(this.gl.BLEND);const a=this.textureManager.getOrCreateTextureFromVideo(t.video);if(this.lastTexture===a&&i===lt.Video||(this.gl.bindTexture(this.gl.TEXTURE_2D,a),this.gl.uniform1i(this.programManager.textureUniform,0),this.lastTexture=a),t.video.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t.video),this.gl.uniform1i(this.programManager.renderTextureUniform,1),this.gl.uniform1f(this.programManager.alphaUniform,null!==(o=t.opacity)&&void 0!==o?o:1),this.gl.uniform1i(this.programManager.useTintColorUniform,t.tintColor?1:0),t.tintColor){const{r:e,g:i,b:s,a:o}=at(t.tintColor);this.gl.uniform4f(this.programManager.tintColorUniform,e,i,s,o)}if(this.gl.uniform1i(this.programManager.useMaskColorUniform,t.maskColor?1:0),t.maskColor){const{r:e,g:i,b:s}=at(t.maskColor);this.gl.uniform4f(this.programManager.maskColorUniform,e,i,s,null!==(r=t.opacity)&&void 0!==r?r:1),this.gl.uniform1f(this.programManager.maskColorMixUniform,null!==(n=t.maskColorMix)&&void 0!==n?n:1)}return this.gl.drawArrays(this.gl.TRIANGLES,0,6),!0}};class Ct{constructor(t){this.gl=t}createFromImage(t,e=!1,i){return i=null!=i?i:this.gl.createTexture(),t.naturalWidth?this.createFromSource(t,i,e):t.addEventListener("load",(()=>this.createFromSource(t,i,e))),i}createFromCanvas(t,e=!1,i){return i=null!=i?i:this.gl.createTexture(),this.createFromSource(t,i,e),i}createPixelTexture(){const t=this.gl.createTexture();return this.gl.bindTexture(this.gl.TEXTURE_2D,t),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,1,1,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),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.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.bindTexture(this.gl.TEXTURE_2D,null),t}createFromSource(t,e,i=!1){this.gl.bindTexture(this.gl.TEXTURE_2D,e),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,t),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),i?(this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR)):(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.bindTexture(this.gl.TEXTURE_2D,null)}}const bt=(t,e)=>`${e?"_smooth_":""}${t}`;class St{constructor(t){this.textureFactory=t,this.textures=new Map}getOrCreateTextureFromImage(t,e=!1){var i;return null!==(i=this.textures.get(bt(t.src,e)))&&void 0!==i?i:this.createTextureFromImage(t,e)}createTextureFromImage(t,e=!1){const i=this.textureFactory.createFromImage(t,e);return this.textures.set(bt(t.src,e),i),i}getOrCreateTextureFromCanvas(t,e,i=!1){var s;return null!==(s=this.textures.get(bt(t,i)))&&void 0!==s?s:this.createTextureFromCanvas(t,e,i)}createTextureFromCanvas(t,e,i=!1){const s=this.textureFactory.createFromCanvas(e,i);return this.textures.set(bt(t,i),s),s}getOrCreateTextureFromVideo(t){var e;return null!==(e=this.textures.get(t.src))&&void 0!==e?e:this.createTextureFromVideo(t)}createTextureFromVideo(t){const e=this.textureFactory.createPixelTexture();return this.textures.set(t.src,e),e}}const wt={CanvasElement:Symbol.for("CanvasElement"),WebGLManager:Symbol.for("WebGLManager")};var At=function(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n},Rt=function(t,e){return function(i,s){e(i,s,t)}};let _t=class{constructor(t){this.renderers=new Map;const e=new Y(t),i=e.gl,s=e.contextVersion,o=new K(i,s,new q(i,new J(i))),r=new St(new Ct(i));this.fontAtlasFactory=new $,this.renderers.set(lt.Sprite,new mt(i,o,r)),this.renderers.set(lt.Text,new yt(i,o,r,this.fontAtlasFactory)),this.renderers.set(lt.Tilemap,new Mt(i,o,r)),this.renderers.set(lt.Geometric,new dt(i,o)),this.renderers.set(lt.Mask,new pt(i,o)),this.renderers.set(lt.Video,new vt(i,o,r)),this.renderers.set(lt.Darkness,new ut(i,o)),this.canvasColorRenderer=new ht(i),o.loadProgram()}render(t,e){this.renderers.get(t.type).render(t,e,this.lastRender)&&(this.lastRender=t.type)}renderCanvasColor(t){this.canvasColorRenderer.render(t)}};_t=At([l(wt.WebGLManager),Rt(0,c(wt.CanvasElement))],_t);const Et=Object.assign(Object.assign(Object.assign({AssetManager:Symbol.for("AssetManager"),AudioContext:Symbol.for("AudioContext"),CreateSystemService:Symbol.for("CreateSystemService"),GameConfig:Symbol.for("GameConfig"),InputManager:Symbol.for("InputManager"),LoopManager:Symbol.for("LoopManager"),RenderManager:Symbol.for("RenderManager"),SceneManager:Symbol.for("SceneManager"),TimeManager:Symbol.for("TimeManager")},d),G),wt);function Tt(t,e,i,s){var o,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(n=(r<3?o(n):r>3?o(e,i,n):o(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function Pt(t,e){return function(i,s){e(i,s,t)}}function Bt(t,e,i,s){return new(i||(i=Promise))((function(o,r){function n(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?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}h((s=s.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class Dt{constructor(){this.buttons=new Map,this.axes=new Map,this._dpadAxes=new e,this._leftStickAxes=new e,this._rightStickAxes=new e}get dpadAxes(){return this._dpadAxes.set(this.dpadRight?1:this.dpadLeft?-1:0,this.dpadUp?1:this.dpadDown?-1:0),this._dpadAxes}get leftStickAxes(){return this._leftStickAxes.set(this.leftStickHorizontal,this.leftStickVertical),this._leftStickAxes}get rightStickAxes(){return this._rightStickAxes.set(this.rightStickHorizontal,this.rightStickVertical),this._rightStickAxes}get dpadUp(){var t;return null!==(t=this.buttons.get(12))&&void 0!==t&&t}get dpadDown(){var t;return null!==(t=this.buttons.get(13))&&void 0!==t&&t}get dpadLeft(){var t;return null!==(t=this.buttons.get(14))&&void 0!==t&&t}get dpadRight(){var t;return null!==(t=this.buttons.get(15))&&void 0!==t&&t}get bottomFace(){var t;return null!==(t=this.buttons.get(0))&&void 0!==t&&t}get rightFace(){var t;return null!==(t=this.buttons.get(1))&&void 0!==t&&t}get leftFace(){var t;return null!==(t=this.buttons.get(2))&&void 0!==t&&t}get topFace(){var t;return null!==(t=this.buttons.get(3))&&void 0!==t&&t}get leftShoulder(){var t;return null!==(t=this.buttons.get(4))&&void 0!==t&&t}get rightShoulder(){var t;return null!==(t=this.buttons.get(5))&&void 0!==t&&t}get leftTrigger(){var t;return null!==(t=this.buttons.get(6))&&void 0!==t&&t}get rightTrigger(){var t;return null!==(t=this.buttons.get(7))&&void 0!==t&&t}get back(){var t;return null!==(t=this.buttons.get(8))&&void 0!==t&&t}get start(){var t;return null!==(t=this.buttons.get(9))&&void 0!==t&&t}get leftStickButton(){var t;return null!==(t=this.buttons.get(10))&&void 0!==t&&t}get rightStickButton(){var t;return null!==(t=this.buttons.get(11))&&void 0!==t&&t}get leftStickHorizontal(){var t;return null!==(t=this.axes.get(0))&&void 0!==t?t:0}get leftStickVertical(){var t;return-(null!==(t=this.axes.get(1))&&void 0!==t?t:0)}get rightStickHorizontal(){var t;return null!==(t=this.axes.get(2))&&void 0!==t?t:0}get rightStickVertical(){var t;return-(null!==(t=this.axes.get(3))&&void 0!==t?t:0)}get anyButtonPressed(){var t;return null!==(t=Array.from(this.buttons.values()).find((t=>t)))&&void 0!==t&&t}vibrate(t=200,e=.2,i=.2,s=0){this.vibrationInput={duration:t,weakMagnitude:e,startDelay:s,strongMagnitude:i}}}class Ft{constructor(){this.pressedKeys=[]}isPressed(t){return this.pressedKeys.includes(t)}orPressed(t){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)}andPressed(t){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)}isPressedReturn(t,e,i){return this.pressedKeys.includes(t)?e:i}orPressedReturn(t,e,i){return t.reduce(((t,e)=>t||this.pressedKeys.includes(e)),!1)?e:i}andPressedReturn(t,e,i){return t.reduce(((t,e)=>t&&this.pressedKeys.includes(e)),!0)?e:i}}class jt{constructor(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new e,this.hasMoved=!1,this.wheelScroll=new e}}class Ut{constructor(){this.touching=!1,this.interactions=[]}}exports.InputManager=class{constructor(){this.keyboard=new Ft,this.mouse=new jt,this.touchScreen=new Ut,this.gamepads=[]}},exports.InputManager=Tt([l(Et.InputManager)],exports.InputManager);const Lt=[60,120,180,240];var It;exports.TimeManager=class{get deltaTime(){return this.unscaledDeltaTime*this.timeScale}get physicsDeltaTime(){return this.unscaledPhysicsDeltaTime*this.timeScale}get renderDeltaTime(){return this.browserDeltaTime*this.timeScale}get unscaledRenderDeltaTime(){return this.browserDeltaTime}constructor({physicsFramerate:t},e){if(this.entityManager=e,this.timeScale=1,this.browserDeltaTime=0,this.unscaledDeltaTime=0,this.unscaledPhysicsDeltaTime=0,this.maxDeltaTime=1/30,this.thenForGame=0,this.thenForPhysics=0,this.thenForRender=0,this.lastIntervalId=0,this.intervals=new Map,t&&!Lt.includes(t))throw new Error(`Invalid Physics frame rate. Allowed: [${Lt.join(", ")}]`);this.fixedGameFramerate=60,this.fixedGameDeltaTime=parseFloat((1/this.fixedGameFramerate).toFixed(6)),this.fixedPhysicsFramerate=null!=t?t:180,this.fixedPhysicsDeltaTime=parseFloat((1/this.fixedPhysicsFramerate).toFixed(6))}updateForRender(t){this.browserDeltaTime=Math.min(Math.max(0,t-this.thenForRender),this.maxDeltaTime),this.thenForRender=t}updateForGame(t){this.unscaledDeltaTime=Math.min(Math.max(this.fixedGameDeltaTime,t-this.thenForGame),this.maxDeltaTime),this.thenForGame=t}updateForPhysics(t){this.unscaledPhysicsDeltaTime=Math.min(Math.max(0,t-this.thenForPhysics),this.maxDeltaTime),this.thenForPhysics=t}updateIntervals(){if(0!==this.intervals.size)for(const[t,e]of this.intervals)this.intervalHealthCheck(e)?(e.executeImmediately?(e.timer=e.delay,e.executeImmediately=!1):e.timer+=1e3*(e.useTimeScale?this.deltaTime:this.unscaledDeltaTime),e.timer>=e.delay&&(e.callback(),e.times&&--e.times<=0?this.clearInterval(t):e.timer-=e.delay)):this.clearInterval(t)}intervalHealthCheck(t){return!(t.entityRef&&!this.entityManager.isEntityEnabled(t.entityRef))&&!(t.componentRef&&!this.entityManager.isComponentEnabled(t.componentRef))}setInterval({callback:t,delay:e,times:i,executeImmediately:s,entityRef:o,componentRef:r,useTimeScale:n=!0}){const a=++this.lastIntervalId;return this.intervals.set(a,{callback:t,delay:e,times:i,executeImmediately:s,entityRef:o,componentRef:r,timer:0,useTimeScale:n}),a}clearInterval(t){this.intervals.delete(t)}clearAllIntervals(){this.intervals.clear()}},exports.TimeManager=Tt([l(Et.TimeManager),Pt(0,c(Et.GameConfig)),Pt(1,c(Et.EntityManager))],exports.TimeManager),function(t){t[t.Image=0]="Image",t[t.Audio=1]="Audio",t[t.Font=2]="Font",t[t.Video=3]="Video",t[t.Json=4]="Json"}(It||(It={})),exports.AssetManager=class{constructor(t){this.audioContext=t,this.assets=[]}getAssetsLoaded(){return this.assets.reduce(((t,e)=>t&&e.loaded),!0)}loadImage(t,e){if(this.getImage(t))return this.getImage(t);const i=new Image;i.crossOrigin="",i.src=t;const s=this.createAsset(t,It.Image,i,e),o=()=>s.loaded=!0;return i.complete?o():i.addEventListener("load",o),i}loadAudio(t,e){const i=this.getAudio(t);if(i)return i;if(!this.audioContext){return void(this.createAsset(t,It.Audio,void 0,e).loaded=!0)}const s=new Audio;s.src=t;const o={element:s},r=this.createAsset(t,It.Audio,o,e);return this.decodeAudioBuffer(t).then((t=>{o.buffer=t,r.loaded=!0})),o}decodeAudioBuffer(t){return Bt(this,void 0,void 0,(function*(){const e=yield fetch(t),i=yield e.arrayBuffer();return this.audioContext.decodeAudioData(i)}))}loadFont(t,e){if(this.getFont(t))return this.getFont(t);const i=new FontFace(t,`url(${e})`),s=this.createAsset(e,It.Font,i);return s.family=t,document.fonts.add(i),i.load().then((()=>s.loaded=!0)),i}loadVideo(t,e){if(this.getVideo(t))return this.getVideo(t);const i=document.createElement("video");i.playsInline=!0,i.src=t;const s=this.createAsset(t,It.Video,i,e);return i.duration?s.loaded=!0:i.addEventListener("canplaythrough",(()=>s.loaded=!0)),i}loadJson(t,e){return Bt(this,void 0,void 0,(function*(){if(this.getJson(t))return this.getJson(t);const i=this.createAsset(t,It.Json,void 0,e),s=yield fetch(t),o=yield s.json();return i.loaded=!0,i.element=o,o}))}getImage(t){var e;return null===(e=this.assets.find((e=>e.type===It.Image&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getAudio(t){var e;return null===(e=this.assets.find((e=>e.type===It.Audio&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getFont(t){var e;return null===(e=this.assets.find((e=>e.type===It.Font&&e.family===t)))||void 0===e?void 0:e.element}getVideo(t){var e;return null===(e=this.assets.find((e=>e.type===It.Video&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}getJson(t){var e;return null===(e=this.assets.find((e=>e.type===It.Json&&(e.url===t||e.name===t))))||void 0===e?void 0:e.element}createAsset(t,e,i,s){this.deleteAssetIfExists({url:t,name:s});const o={type:e,url:t,element:i,loaded:!1,name:s};return this.assets.push(o),o}deleteAssetIfExists({url:t,name:e}){const i=this.assets.findIndex((i=>i.url===t||void 0!==i.name&&i.name===e));-1!==i&&this.assets.splice(i,1)}},exports.AssetManager=Tt([l(Et.AssetManager),Pt(0,c(Et.AudioContext))],exports.AssetManager);class Ot{get currentTime(){return this._currentTime}get playing(){return"playing"===this.state}get paused(){return"paused"===this.state}get stopped(){return"stopped"===this.state}constructor(t){this.stopOnSceneTransition=!0,this.fixedToTimeScale=!1,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.startAt=0,this.state="stopped",this.volume=1,this._currentAudioSource=void 0,this._sourceNode=void 0,this._gainNode=void 0,this._startedAt=0,this._pauseOffset=0,this._currentTime=0,this._playAfterUserInput=!1,Object.assign(this,t)}play(t){t&&(this.audioSource=t),this.action="play"}pause(){this.action="pause"}stop(){this.action="stop"}}Ot.componentName="AudioPlayer";const kt={AudioPlayerSystem:Symbol.for("AudioPlayerSystem"),ButtonSystem:Symbol.for("ButtonSystem"),TiledObjectSystem:Symbol.for("TiledObjectSystem"),TiledWrapperSystem:Symbol.for("TiledWrapperSystem"),TilemapPreProcessingSystem:Symbol.for("TilemapPreProcessingSystem"),TransformSystem:Symbol.for("TransformSystem"),GamepadSystem:Symbol.for("GamepadSystem"),KeyboardSystem:Symbol.for("KeyboardSystem"),MouseSystem:Symbol.for("MouseSystem"),TouchScreenSystem:Symbol.for("TouchScreenSystem"),UpdateBallColliderShapeSystem:Symbol.for("UpdateBallColliderShapeSystem"),UpdateBoxColliderShapeSystem:Symbol.for("UpdateBoxColliderShapeSystem"),UpdateEdgeColliderShapeSystem:Symbol.for("UpdateEdgeColliderShapeSystem"),UpdatePolygonColliderShapeSystem:Symbol.for("UpdatePolygonColliderShapeSystem"),UpdateTilemapColliderShapeSystem:Symbol.for("UpdateTilemapColliderShapeSystem"),UpdateCollidersAfterRepositionSystem:Symbol.for("UpdateCollidersAfterRepositionSystem"),ApplyRepositionSystem:Symbol.for("ApplyRepositionSystem"),ApplyVelocitySystem:Symbol.for("ApplyVelocitySystem"),ResolveCollisionSystem:Symbol.for("ResolveCollisionSystem"),AnimatorSystem:Symbol.for("AnimatorSystem"),TilemapAnimationSystem:Symbol.for("TilemapAnimationSystem"),CameraSystem:Symbol.for("CameraSystem"),ClearScreenSystem:Symbol.for("ClearScreenSystem"),CullingSystem:Symbol.for("CullingSystem"),MaskRendererSystem:Symbol.for("MaskRendererSystem"),RenderSystem:Symbol.for("RenderSystem"),DarknessLightRendererSystem:Symbol.for("DarknessLightRendererSystem"),SpriteRendererSystem:Symbol.for("SpriteRendererSystem"),GeometricRendererSystem:Symbol.for("GeometricRendererSystem"),TextRendererSystem:Symbol.for("TextRendererSystem"),TilemapRendererSystem:Symbol.for("TilemapRendererSystem"),VideoRendererSystem:Symbol.for("VideoRendererSystem"),DebugButtonSystem:Symbol.for("DebugButtonSystem"),DebugColliderRenderSystem:Symbol.for("DebugColliderRenderSystem"),DebugMousePositionSystem:Symbol.for("DebugMousePositionSystem"),DebugTextRendererSystem:Symbol.for("DebugTextRendererSystem")},Gt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Vt=class{constructor(t,e,i,s,o){this.entityManager=t,this.inputManager=e,this.timeManager=i,this.assetManager=s,this.audioContext=o,this.canPlay=!0,this.userInputErrorCatched=!1,this.userInputEventHandler=()=>{Gt.forEach((t=>window.removeEventListener(t,this.userInputEventHandler))),this.canPlay=!0,"suspended"===this.audioContext.state&&this.audioContext.resume()},document.addEventListener("visibilitychange",(()=>{document.hidden?(this.canPlay=!1,"running"===this.audioContext.state&&this.audioContext.suspend()):(this.canPlay=!0,"suspended"===this.audioContext.state&&this.audioContext.resume())}))}catchUserInput(){this.canPlay=!1,this.userInputErrorCatched=!0,Gt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(Ot,(t=>{var e;if("string"==typeof t.audioSource){const e=this.assetManager.getAudio(t.audioSource);if(!(null==e?void 0:e.buffer))return;t.audioSource=e}(null===(e=t.audioSource)||void 0===e?void 0:e.buffer)&&(t._playAfterUserInput&&(t._playAfterUserInput=!1,t.action="play"),t.audioSource!==t._currentAudioSource&&(this.disposeSource(t),t._currentAudioSource=t.audioSource,t._pauseOffset=0,t.state="stopped"),t._gainNode&&(t._gainNode.gain.value=t.volume),t._sourceNode&&(t._sourceNode.playbackRate.value=this.computePlaybackRate(t),this.applyLoop(t,t._sourceNode)),"play"===t.action&&"playing"!==t.state?"suspended"===this.audioContext.state?(t._playAfterUserInput=!0,this.userInputErrorCatched||this.catchUserInput()):("stopped"===t.state&&(t._pauseOffset=t.startAt),this.startSource(t),t.state="playing"):"pause"===t.action&&"playing"===t.state?(this.pauseSource(t),t.state="paused"):"stop"===t.action&&"stopped"!==t.state&&(this.disposeSource(t),t._pauseOffset=0,t.state="stopped"),t.action=void 0,this.updateCurrentTime(t))}))}onSceneDestroyed(){this.entityManager.search(Ot,(t=>{t.stopOnSceneTransition&&this.stopAudioPlayer(t)}),!0)}onGameStopped(){this.entityManager.search(Ot,(t=>this.stopAudioPlayer(t)),!0)}stopAudioPlayer(t){this.disposeSource(t),t._pauseOffset=0,t.state="stopped"}computePlaybackRate(t){return t.fixedToTimeScale?this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16):1}startSource(t){var e;const i=this.audioContext.createBufferSource();i.buffer=t._currentAudioSource.buffer,this.applyLoop(t,i),i.playbackRate.value=this.computePlaybackRate(t);const s=null!==(e=t._gainNode)&&void 0!==e?e:this.audioContext.createGain();s.gain.value=t.volume,i.connect(s),t._gainNode||s.connect(this.audioContext.destination),i.onended=()=>{t._sourceNode===i&&(t._sourceNode=void 0,t._pauseOffset=0,t.state="stopped")};const o=t._pauseOffset;i.start(0,o),t._sourceNode=i,t._gainNode=s,t._startedAt=this.audioContext.currentTime-o}pauseSource(t){t._sourceNode&&(t._pauseOffset=this.wrapElapsed(t,this.audioContext.currentTime-t._startedAt),this.disposeSource(t))}applyLoop(t,e){e.loop=t.loop,e.loopStart=t.loopStart,e.loopEnd=t.loopEnd}wrapElapsed(t,e){if(t.loop&&t._currentAudioSource){const{loopStart:i,loopEnd:s}=t;s>i?e>s&&(e=i+(e-i)%(s-i)):e%=t._currentAudioSource.buffer.duration}return Math.max(0,e)}updateCurrentTime(t){"playing"===t.state&&t._sourceNode?t._currentTime=this.wrapElapsed(t,this.audioContext.currentTime-t._startedAt):t._currentTime=t._pauseOffset}disposeSource(t){if(t._sourceNode){t._sourceNode.onended=null;try{t._sourceNode.stop()}catch(t){}t._sourceNode=void 0}}};var Nt;Vt=Tt([l(kt.AudioPlayerSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.InputManager)),Pt(2,c(Et.TimeManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.AudioContext))],Vt),function(t){t[t.GameLogic=0]="GameLogic",t[t.GamePhysics=1]="GamePhysics",t[t.GamePreRender=2]="GamePreRender",t[t.Physics=3]="Physics",t[t.PreGameLogic=4]="PreGameLogic",t[t.Render=5]="Render",t[t.Transform=6]="Transform"}(Nt||(Nt={}));const zt=(t,e)=>{t.prototype.__system_group||(t.prototype.__system_group=e)};class Wt{constructor(t){this.position=new e,this.scale=new e(1,1),this.rotation=0,this.ignoreParentPosition=!1,this.ignoreParentScale=!1,this.ignoreParentRotation=!1,this.localPosition=new e,this.localScale=new e(1,1),this.localRotation=0,this._awake=!1,this._parent=void 0,Object.assign(this,t)}}Wt.componentName="Transform";const Ht="Default",Yt="Debug";class $t{constructor(t){this.layers=[Ht],this.zoom=1,this.depth=0,this.debug=!1,this._renderData={position:new e,depth:0,zoom:1,layers:[]},Object.assign(this,t)}}$t.componentName="Camera";class Xt{constructor(t){this.fixedToTimeScale=!1,this.layer=Ht,this.loop=!1,this.offset=new e,this.playing=!1,this.rotation=0,this.volume=1,this._currentVideoSrc=void 0,this._playPromisePendind=!1,this._renderData={type:lt.Video,height:void 0,layer:void 0,position:new e,video:void 0,width:void 0,flipHorizontal:void 0,flipVertical:void 0,maskColor:void 0,maskColorMix:void 0,opacity:void 0,rotation:void 0,slice:void 0,tintColor:void 0},Object.assign(this,t)}play(t){t&&(this.video=t),this.action="play"}pause(){this.action="pause"}stop(){this.action="stop"}}Xt.componentName="VideoRenderer";const qt=["click","contextmenu","auxclick","dblclick","mousedown","mouseup","pointerup","touchend","keydown","keyup"];let Kt=class{constructor(t,i,s,o,r){this.entityManager=t,this.renderManager=i,this.timeManager=s,this.assetManager=o,this.inputManager=r,this.scaledOffset=new e,this.canPlay=!0,this.userInputErrorCatched=!1,this.userInputEventHandler=()=>{qt.forEach((t=>{window.removeEventListener(t,this.userInputEventHandler)})),this.canPlay=!0},document.addEventListener("visibilitychange",(()=>{this.entityManager.search(Xt,(({video:t,playing:e})=>{t&&"string"!=typeof t&&(document.hidden?t.pause():!document.hidden&&e&&t.play(),this.canPlay=!document.hidden)}))}))}catchUserInput(){this.canPlay=!1,this.userInputErrorCatched=!0,qt.forEach((t=>window.addEventListener(t,this.userInputEventHandler)))}checkGamepad(){return this.canPlay=this.inputManager.gamepads.some((t=>t.anyButtonPressed)),this.canPlay}onUpdate(){(this.canPlay||this.checkGamepad())&&this.entityManager.search(Xt,((t,i)=>{var s,o;const r=this.entityManager.getComponent(i,Wt);if(!r)throw new Error("VideoRenderer component needs a Transform");if("string"==typeof t.video&&(t.video=this.assetManager.getVideo(t.video),!t.video))throw new Error(`Asset ${t.video} not found`);t.video&&t.video.duration&&(this.checkVideoState(t),this.scaledOffset.set(t.offset.x*r.localScale.x,t.offset.y*r.localScale.y),e.add(t._renderData.position,r.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.video=t.video,t._renderData.width=(null!==(s=t.width)&&void 0!==s?s:t.video.videoWidth)*Math.abs(r.localScale.x),t._renderData.height=(null!==(o=t.height)&&void 0!==o?o:t.video.videoHeight)*Math.abs(r.localScale.y),t._renderData.rotation=r.localRotation+t.rotation,t._renderData.slice=t.slice,t._renderData.flipHorizontal=t.flipHorizontally,t._renderData.flipVertical=t.flipVertically,t._renderData.opacity=t.opacity,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.tintColor=t.tintColor,0!==r.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,r),this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}checkVideoState(t){const{video:e,action:i,loop:s,volume:o}=t;"string"!=typeof e&&(e.src!==t._currentVideoSrc&&(t._currentVideoSrc=e.src,t.playing=!1,e.currentTime=0),e.loop=s,e.volume=o,e.playbackRate=t.fixedToTimeScale?this.timeManager.timeScale<.0625?0:Math.min(this.timeManager.timeScale,16):1,"play"!==i||t.playing||t._playPromisePendind||!this.canPlay||(t._playPromisePendind=!0,e.play().then((()=>{t._playPromisePendind=!1,t.playing=!0})).catch((()=>{t._playPromisePendind=!1,this.userInputErrorCatched||this.catchUserInput()}))),"play"===i&&e.ended&&(t.action="stop",t.playing=!1),"stop"===i&&e.currentTime>0&&(e.pause(),e.currentTime=0,t.playing=!1),"pause"!==i||e.paused||e.pause())}onSceneDestroyed(){this.entityManager.search(Xt,(t=>{t.video&&"string"!=typeof t.video&&(t.video.pause(),t.video.currentTime=0,t.playing=!1)}),!0)}};Kt=Tt([l(kt.VideoRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.TimeManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.InputManager))],Kt),exports.SceneManager=class{constructor(t,e,i,s,o){this.systemManager=t,this.systemFactory=e,this.entityManager=i,this.assetManager=s,this.timeManager=o,this.scenes=new Map,this._loadingScene=!1,this._sceneLoadedThisFrame=!1,this.preserveEntitiesWithComponent=void 0}addScene(t,e,i=!1){const s=new t(this.entityManager,this.assetManager);this.scenes.set(e,s),i&&(this.openingSceneName=e)}loadScene(t,e){if(!this.scenes.has(t))throw new Error(`Invalid scene name: '${t}'`);this.sceneNameToBeLoaded=t,this.preserveEntitiesWithComponent=null==e?void 0:e.preserveEntitiesWithComponent}loadOpeningScene(t){if(!this.openingSceneName)throw new Error("There is no opening scene");this.loadScene(this.openingSceneName,t)}get loadingScene(){return this._loadingScene}get sceneLoadedThisFrame(){return this._sceneLoadedThisFrame}update(){if(this._sceneLoadedThisFrame=!1,this.sceneNameToBeLoaded){this.currentSceneName&&this.destroyCurrentScene(),this.currentSceneName=this.sceneNameToBeLoaded,this.sceneNameToBeLoaded=void 0;const t=this.scenes.get(this.currentSceneName);t.systems=[],t.loadAssets(),this._loadingScene=!0}if(this._loadingScene&&this.assetManager.getAssetsLoaded()){const t=this.scenes.get(this.currentSceneName);this._loadingScene=!1,this._sceneLoadedThisFrame=!0,t.setup(),this.systemManager.update(Nt.Transform),this.systemManager.update(Nt.PreGameLogic),t.systems.forEach(((t,e)=>{this.systemFactory.createSystemIfNotExists(t),this.systemManager.enableSystem(t),this.systemManager.setExecutionOrder(t,e);const i=this.systemManager.getSystem(t);"onSceneLoaded"in i&&"function"==typeof i.onSceneLoaded&&i.onSceneLoaded()}))}}destroyCurrentScene(){var t,e;this.currentSceneName&&(null===(t=this.systemManager.getSystem(Vt))||void 0===t||t.onSceneDestroyed(),null===(e=this.systemManager.getSystem(Kt))||void 0===e||e.onSceneDestroyed(),this._loadingScene||(this.scenes.get(this.currentSceneName).systems.forEach((t=>{const e=this.systemManager.getSystem(t);"onSceneDestroyed"in e&&"function"==typeof e.onSceneDestroyed&&e.onSceneDestroyed(),this.systemManager.disableSystem(t)})),this.entityManager.removeAllEntities({preserveEntitiesWithComponent:this.preserveEntitiesWithComponent}),this.timeManager.clearAllIntervals(),this.currentSceneName=void 0))}},exports.SceneManager=Tt([l(Et.SceneManager),Pt(0,c(Et.SystemManager)),Pt(1,c(Et.CreateSystemService)),Pt(2,c(Et.EntityManager)),Pt(3,c(Et.AssetManager)),Pt(4,c(Et.TimeManager))],exports.SceneManager);class Jt{constructor(t){this.width=0,this.height=0,this.radius=0,this.touchEnabled=!0,this.offset=new e,this.pressed=!1,this.mouseOver=!1,Object.assign(this,t)}}var Qt;Jt.componentName="Button",exports.ButtonShape=void 0,(Qt=exports.ButtonShape||(exports.ButtonShape={}))[Qt.Rectangle=0]="Rectangle",Qt[Qt.Circumference=1]="Circumference";let Zt=class{constructor(t,i){this.entityManager=t,this.scaled={position:new e,width:0,height:0,radius:0},this.distance=new e,this.pressedLastFrame=!1,this.mouse=i.mouse,this.touchScreen=i.touchScreen}onUpdate(){this.entityManager.search(Jt,((t,e)=>{const i=this.entityManager.getComponent(e,Wt);if(!i)throw new Error("Button component needs a Transform");this.pressedLastFrame=t.pressed,t.pressed=!1,this.scale(t,i),t.mouseOver=this.isMouseOverButton(t),t.pressed=t.mouseOver&&this.mouse.leftButtonPressed,t.touchEnabled&&this.touchScreen.touching&&(this.resolveTouchAndRectangle(t),this.resolveTouchAndCircumference(t)),t.onClick&&!this.pressedLastFrame&&t.pressed&&t.onClick(),t.onPressed&&t.pressed&&t.onPressed()}))}scale(t,{localPosition:e,localScale:i}){this.scaled.width=t.width*i.x,this.scaled.height=t.height*i.y,this.scaled.position.x=e.x+t.offset.x*i.x,this.scaled.position.y=e.y+t.offset.y*i.y,this.scaled.radius=t.radius*Math.max(Math.abs(i.x),Math.abs(i.y))}isMouseOverButton(t){return this.isMouseOverRectangleButton(t)||this.isMouseOverCircumferenceButton(t)}isMouseOverRectangleButton(t){return t.shape===exports.ButtonShape.Rectangle&&(n(this.mouse.positionInViewport.x,this.scaled.position.x-this.scaled.width/2,this.scaled.position.x+this.scaled.width/2)&&n(this.mouse.positionInViewport.y,this.scaled.position.y-this.scaled.height/2,this.scaled.position.y+this.scaled.height/2))}isMouseOverCircumferenceButton(t){return t.shape===exports.ButtonShape.Circumference&&(e.subtract(this.distance,this.scaled.position,this.mouse.positionInViewport),this.distance.magnitude<=this.scaled.radius)}resolveTouchAndRectangle(t){if(t.shape===exports.ButtonShape.Rectangle)for(const{positionInViewport:e,radius:i}of this.touchScreen.interactions){if(t.pressed)return;t.pressed=this.scaled.position.x+this.scaled.width/2>=e.x-i.x&&this.scaled.position.x-this.scaled.width/2<=e.x+i.x&&this.scaled.position.y+this.scaled.height/2>=e.y-i.y&&this.scaled.position.y-this.scaled.height/2<=e.y+i.y}}resolveTouchAndCircumference(t){if(t.shape===exports.ButtonShape.Circumference)for(const{positionInViewport:i,radius:s}of this.touchScreen.interactions){if(t.pressed)return;e.subtract(this.distance,this.scaled.position,i),t.pressed=this.distance.magnitude<=this.scaled.radius+Math.max(s.x,s.y)}}};Zt=Tt([l(kt.ButtonSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.InputManager))],Zt);class te{constructor(t){this.objects=new Map,this._processed=!1,this._objectsCreated=!1,this._animationsMapped=!1,this._origin=new e,this._tilemap=void 0,this._tilesetsCreated=!1,Object.assign(this,t)}refresh(){this._processed=!1,this._animationsMapped=!1}}te.componentName="TiledWrapper";class ee{constructor(t){if(this.layer=Ht,this.tilesets=[],this.data=[],this.chunks=[],this.width=0,this.height=0,this.tileWidth=void 0,this.tileHeight=void 0,this.tintColor=void 0,this.opacity=1,this.smooth=!1,this.offset=new e,this._processed=!1,this._dataFromChunks=!1,this._renderData=[],t&&"tileset"in t)throw new Error("TilemapRenderer.tileset was replaced by TilemapRenderer.tilesets, which takes an array");Object.assign(this,t)}refresh(){this._dataFromChunks?this.data=[]:this.chunks=[],this.height=0,this._processed=!1}}ee.componentName="TilemapRenderer";class ie{constructor(t){var e,i;this.tiles=[],this.fps=12,this.currentFrame=0,this.currentTime=0,t&&(this.tiles=null!==(e=t.tiles)&&void 0!==e?e:this.tiles,this.fps=null!==(i=t.fps)&&void 0!==i?i:this.fps)}}const se=(t,e,i=0,s=0,o=!0,r=1)=>t.forEach((t=>{var n,a,h;const l=i+(null!==(n=t.offsetx)&&void 0!==n?n:0),c=s+(null!==(a=t.offsety)&&void 0!==a?a:0),d=o&&!1!==t.visible,g=r*(null!==(h=t.opacity)&&void 0!==h?h:1);"group"===t.type?se(t.layers,e,l,c,d,g):e(t,l,c,d,g)})),oe=(t,e)=>{if(!t||e.startsWith("/")||e.includes("://"))return e;const i=[];return`${t.slice(0,t.lastIndexOf("/")+1)}${e}`.split("/").forEach((t=>{"."!==t&&(".."===t&&i.length>0&&".."!==i[i.length-1]?i.pop():i.push(t))})),i.join("/")};let re=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(te,((t,e)=>{var i;!t._objectsCreated&&(null===(i=t.objects)||void 0===i?void 0:i.size)>0&&t._tilemap&&(this.createObjects(t,t._tilemap,e),t._objectsCreated=!0)}))}createObjects(t,i,s){const o=this.collectObjects(t,i),r=new Map(o.map((({object:t})=>[t.id,this.entityManager.createEntity()]))),n=this.entityManager.getComponent(s,Wt),a=n?n.position:new e,h=this.getBounds(i,s);o.forEach((e=>{var s;const{object:o}=e,n=t.objects.get(ne(o)),l=r.get(o.id),c="function"==typeof n?n(this.mapProperties(o,r),o):n;if(!c)throw new Error(`The blueprint for the Tiled object class ${ne(o)} returned nothing`);const d=Array.isArray(c)?{components:c}:c;this.entityManager.addArchetype(l,d);const g=null!==(s=this.entityManager.getComponent(l,Wt))&&void 0!==s?s:this.entityManager.addComponent(l,Wt);ae(g,i,e,a,t._origin,h)}))}getBounds(t,e){var i;const{width:s,height:o,tileWidth:r,tileHeight:n,_processed:a}=null!==(i=this.entityManager.getComponent(e,ee))&&void 0!==i?i:{};return a&&s>0&&o>0?{width:s,height:o,tileWidth:r,tileHeight:n}:{width:t.width,height:t.height,tileWidth:t.tilewidth,tileHeight:t.tileheight}}collectObjects(t,e){const i=[];return se(e.layers,((e,s,o,r)=>{"objectgroup"===e.type&&r&&e.objects.forEach((e=>{!1!==e.visible&&t.objects.has(ne(e))&&i.push({object:e,offsetX:s,offsetY:o})}))})),i}mapProperties(t,e){const i=new Map;return t.properties&&t.properties.forEach((({name:t,type:s,value:o})=>i.set(t,"object"===s?e.get(o):o))),i}};re=Tt([l(kt.TiledObjectSystem),Pt(0,c(Et.EntityManager))],re);const ne=t=>{var e;return null!==(e=t.class)&&void 0!==e?e:t.type},ae=(t,e,{object:i,offsetX:s,offsetY:o},r,n,{width:h,height:l,tileWidth:c,tileHeight:d})=>{var g;const p=i.width/2,u=void 0!==i.gid?-i.height/2:i.height/2,m=a(null!==(g=i.rotation)&&void 0!==g?g:0),f=Math.cos(m),y=Math.sin(m),x=(i.x+s+p*f-u*y)/e.tilewidth-n.x,M=(i.y+o+p*y+u*f)/e.tileheight-n.y;t.position.set(r.x+(x-h/2)*c,r.y+(l/2-M)*d),0!==m&&(t.rotation=-m)};let he=class{constructor(t,e){this.entityManager=t,this.assetManager=e,this.requestedTilemaps=new Set}onUpdate(){this.entityManager.search(te,((t,e)=>{if(t._processed&&t._animationsMapped)return;const i=this.resolveTilemap(t);if(!i)return;const s=this.entityManager.getComponent(e,ee);t._processed||(s&&(this.resolveTilesets(t,i,s),this.renderLayer(t,i,s)),t._processed=!0),t._animationsMapped||(i.tilesets&&(null==s?void 0:s.tilesets.length)>0&&this.mapAnimations(i,s.tilesets),t._animationsMapped=!0)}))}resolveTilemap(t){if(!t.tilemapPath)return;const e=this.assetManager.getJson(t.tilemapPath);if(e)return this.requestedTilemaps.delete(t.tilemapPath),t._tilemap=e,e;this.requestedTilemaps.has(t.tilemapPath)||(this.requestedTilemaps.add(t.tilemapPath),this.assetManager.loadJson(t.tilemapPath))}resolveTilesets(t,e,i){var s;if(i.tilesets.length>0&&!t._tilesetsCreated)i.tilesets.forEach(((t,i)=>{var s,o,r,n;t.firstgid=null!==(n=null!==(s=t.firstgid)&&void 0!==s?s:null===(r=null===(o=e.tilesets)||void 0===o?void 0:o[i])||void 0===r?void 0:r.firstgid)&&void 0!==n?n:1}));else{if(!((null===(s=e.tilesets)||void 0===s?void 0:s.length)>0))throw new Error(`The tilemap ${t.tilemapPath} has no embedded tilesets. Export it from Tiled with its tilesets embedded, or declare the tilesets of the TilemapRenderer`);i.tilesets=e.tilesets.map((e=>this.createTileset(e,t.tilemapPath))),t._tilesetsCreated=!0}}createTileset({firstgid:t,name:e,source:i,image:s,tilewidth:o,tileheight:r,margin:n,spacing:a,tilecount:h},l){if(!s)throw new Error(`The tileset ${null!=e?e:i} is not embedded in the tilemap, the engine does not read external tilesets. Export the tilemap with its tilesets embedded, or declare the tilesets of the TilemapRenderer`);return{image:oe(l,s),tileWidth:o,tileHeight:r,margin:n,spacing:a,firstgid:t,tileCount:h}}renderLayer(t,e,i){var s,o,r,n;let a,h,l;if(se(e.layers,((e,s,o,r,n)=>{a||"tilelayer"!==e.type||e.name!==t.layerToRender||(a=e,h=r,l=n,i.offset.set(s,-o))})),a){var c;if(i.opacity=l,a.tintcolor&&(i.tintColor=9===(c=a.tintcolor).length?`#${c.slice(3)}`:c),i.tileWidth=null!==(s=i.tileWidth)&&void 0!==s?s:e.tilewidth,i.tileHeight=null!==(o=i.tileHeight)&&void 0!==o?o:e.tileheight,!h)return i.data=[],i.chunks=[],i.width=0,void(i.height=0);if(e.infinite){const e=null!==(r=a.startx)&&void 0!==r?r:0,s=null!==(n=a.starty)&&void 0!==n?n:0;i.chunks=a.chunks.map((t=>Object.assign(Object.assign({},t),{x:t.x-e,y:t.y-s}))),i.width=a.width,i.height=a.height,t._origin.set(e,s)}else i.data=a.data,i.width=e.width,i.height=e.height,t._origin.set(0,0)}}mapAnimations(t,e){t.tilesets.forEach((({firstgid:t,tiles:i})=>{if(!i)return;const s=e.find((e=>e.firstgid===t));s&&i.forEach((({id:e,animation:i})=>{var o;if(!i||0===i.length)return;const r=t+e;(null===(o=s.animations)||void 0===o?void 0:o.has(r))||(s.animations||(s.animations=new Map),s.animations.set(r,new ie({tiles:i.map((({tileid:e})=>t+e)),fps:1e3*i.length/i.reduce(((t,{duration:e})=>t+e),0)})))}))}))}};he=Tt([l(kt.TiledWrapperSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.AssetManager))],he);const le=16;let ce=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(ee,(t=>{var e,i,s,o;t._processed||(t.chunks&&t.chunks.length>0?(t._dataFromChunks=!0,this.chunksToData(t)):t.data&&t.data.length>0&&(t._dataFromChunks=!1,this.dataToChunks(t)),t.tileWidth=null!==(e=t.tileWidth)&&void 0!==e?e:null===(i=t.tilesets[0])||void 0===i?void 0:i.tileWidth,t.tileHeight=null!==(s=t.tileHeight)&&void 0!==s?s:null===(o=t.tilesets[0])||void 0===o?void 0:o.tileHeight,t._processed=!0)}))}dataToChunks(t){t.height=t.height||Math.ceil(t.data.length/t.width);const e=Math.ceil(t.width/le),i=Math.ceil(t.height/le);for(let s=0;s<i;s++)for(let i=0;i<e;i++){const e={x:i*le,y:s*le,width:le,height:le,data:[]};for(let i=0;i<e.width*e.height;i++){const s=e.x+i%e.width,o=t.width*(e.y+Math.floor(i/e.width));e.data[i]=s<t.width&&o<t.height*t.width?t.data[o+s]:0}t.chunks.push(e)}}chunksToData(t){t.data=[],t.chunks.forEach((e=>e.data.forEach(((i,s)=>{t.data[t.width*(e.y+Math.floor(s/e.width))+e.x+s%e.width]=i})))),t.height=t.height||Math.ceil(t.data.length/t.width)}};ce=Tt([l(kt.TilemapPreProcessingSystem),Pt(0,c(Et.EntityManager))],ce);let de=class{constructor(t){this.entityManager=t}onUpdate(){this.entityManager.search(Wt).sort(((t,e)=>this.getBranchLength(t.entity)-this.getBranchLength(e.entity))).forEach((({component:t,entity:i})=>{const s=this.entityManager.getParent(i);void 0!==s&&this.entityManager.isEntityEnabled(s)&&this.entityManager.isComponentEnabled(s,Wt)?(t._parent||(t._parent=this.entityManager.getComponent(s,Wt),t._awake&&!t.ignoreParentPosition&&e.subtract(t.position,t.localPosition,t._parent.position)),t._parent?this.translateChild(t):this.updateTransform(t)):(t._parent&&this.removeParent(t),this.updateTransform(t)),t._awake=!0}))}getBranchLength(t){const e=this.entityManager.getParent(t);return void 0!==e?1+this.getBranchLength(e):0}removeParent(t){t._parent=void 0,t.position.copy(t.localPosition),t.rotation=t.localRotation}updateTransform(t){t.localPosition.copy(t.position),t.localScale.copy(t.scale),t.localRotation=t.rotation,t._parent=void 0}translateChild(t){t.localRotation=t.rotation+(t.ignoreParentRotation?0:t._parent.localRotation),t.localScale.x=t.scale.x*(t.ignoreParentScale?1:t._parent.scale.x),t.localScale.y=t.scale.y*(t.ignoreParentScale?1:t._parent.scale.y);const e=t.position.magnitude,i=Math.atan2(t.position.y,t.position.x)+(t.ignoreParentRotation?0:t._parent.localRotation);t.localPosition.set(e*Math.cos(i)+(t.ignoreParentPosition?0:t._parent.localPosition.x),e*Math.sin(i)+(t.ignoreParentPosition?0:t._parent.localPosition.y))}};de=Tt([l(kt.TransformSystem),Pt(0,c(Et.EntityManager))],de);let ge=class{constructor(t){this.inputManager=t,this.gamepads=new Map,this.eventHandler=t=>{"gamepadconnected"===t.type?this.gamepadConnected(t.gamepad):"gamepaddisconnected"===t.type&&this.gamepadDisconected(t.gamepad)},window.addEventListener("gamepadconnected",this.eventHandler),window.addEventListener("gamepaddisconnected",this.eventHandler)}gamepadConnected(t){this.gamepads.set(t.index,t),this.inputManager.gamepads[t.index]||(this.inputManager.gamepads[t.index]=new Dt,this.inputManager.gamepads[t.index].index=t.index),this.inputManager.gamepads[t.index].id=t.id,this.inputManager.gamepads[t.index].connected=!0}gamepadDisconected(t){this.gamepads.delete(t.index),this.inputManager.gamepads[t.index].connected=!1}onUpdate(){for(const t of this.getGamepadsFromBrowser())t&&(!1===this.gamepads.has(t.index)?this.gamepadConnected(t):this.gamepads.set(t.index,t));this.gamepads.forEach((t=>{const e=this.inputManager.gamepads[t.index];t.buttons.forEach(((t,i)=>e.buttons.set(i,t.pressed))),t.axes.forEach(((t,i)=>e.axes.set(i,t))),e.vibrationInput&&(t.vibrationActuator.playEffect(t.vibrationActuator.type,{duration:e.vibrationInput.duration,weakMagnitude:e.vibrationInput.weakMagnitude,strongMagnitude:e.vibrationInput.strongMagnitude,startDelay:e.vibrationInput.startDelay}).catch((()=>e.vibrating=!1)).finally((()=>e.vibrating=!1)),e.vibrating=!0,e.vibrationInput=void 0)}))}getGamepadsFromBrowser(){return navigator.getGamepads?navigator.getGamepads():navigator.webkitGetGamepads?navigator.webkitGetGamepads:[]}};ge=Tt([l(kt.GamepadSystem),Pt(0,c(Et.InputManager))],ge);let pe=class{constructor(t,{keyboard:e}){this.pressedKeys=new Set,this.eventHandler=t=>{"keydown"!==t.type||this.pressedKeys.has(t.code)||this.pressedKeys.add(t.code),"keyup"===t.type&&this.pressedKeys.has(t.code)&&this.pressedKeys.delete(t.code)},this.keyboard=e,t.addEventListener("keydown",this.eventHandler),t.addEventListener("keyup",this.eventHandler),t.addEventListener("focusout",(()=>this.pressedKeys.clear()))}onUpdate(){this.keyboard.pressedKeys=[...this.pressedKeys]}};pe=Tt([l(kt.KeyboardSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],pe);let ue=class{constructor(t,{mouse:i}){this.canvas=t,this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1,this.positionInViewport=new e,this.lastPositionInViewport=new e,this.mouse=i,this.canvas.addEventListener("mousemove",(t=>this.updatePosition(t))),this.canvas.addEventListener("mousedown",(t=>this.updateButtonDown(t))),this.canvas.addEventListener("mouseup",(t=>this.updateButtonUp(t))),this.canvas.addEventListener("wheel",(t=>this.handleWheelEvent(t))),this.canvas.addEventListener("focusout",(()=>this.onFocusOut()))}updateButtonDown(t){this.canvas.focus(),t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0===t.button||this.leftButtonPressed,this.scrollButtonPressed=1===t.button||this.scrollButtonPressed,this.rightButtonPressed=2===t.button||this.rightButtonPressed}updateButtonUp(t){t.preventDefault(),t.stopPropagation(),this.leftButtonPressed=0!==t.button&&this.leftButtonPressed,this.scrollButtonPressed=1!==t.button&&this.scrollButtonPressed,this.rightButtonPressed=2!==t.button&&this.rightButtonPressed}updatePosition(t){t.preventDefault(),t.stopPropagation(),this.positionInViewport.set(t.offsetX/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-t.offsetY/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2)}handleWheelEvent(t){t.preventDefault(),t.stopPropagation(),this.wheelEvent=t}onFocusOut(){this.leftButtonPressed=!1,this.scrollButtonPressed=!1,this.rightButtonPressed=!1}onUpdate(){this.mouse.leftButtonPressed=this.leftButtonPressed,this.mouse.rightButtonPressed=this.rightButtonPressed,this.mouse.scrollButtonPressed=this.scrollButtonPressed,this.mouse.positionInViewport.copy(this.positionInViewport),this.positionInViewport.equals(this.lastPositionInViewport)?this.mouse.hasMoved=!1:(this.mouse.hasMoved=!0,this.lastPositionInViewport.copy(this.positionInViewport)),this.wheelEvent?(this.mouse.wheelScroll.set(this.wheelEvent.deltaX,this.wheelEvent.deltaY),this.wheelEvent=void 0):this.mouse.wheelScroll.set(0,0)}};ue=Tt([l(kt.MouseSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],ue);let me=class{constructor(t,{touchScreen:e}){this.canvas=t,this.touching=!1,this.interactions=[],this.eventHandler=t=>{"touchstart"===t.type&&(this.touching=!0,this.updatePosition(t)),"touchmove"===t.type&&this.updatePosition(t),"touchend"!==t.type&&"touchcancel"!==t.type||(this.touching=!1)},this.touchScreen=e,this.canvas.addEventListener("touchstart",this.eventHandler),this.canvas.addEventListener("touchend",this.eventHandler),this.canvas.addEventListener("touchcancel",this.eventHandler),this.canvas.addEventListener("touchmove",this.eventHandler)}updatePosition(t){if(t.preventDefault(),t.stopPropagation(),this.interactions=[],0!==t.targetTouches.length)for(let i=0;i<t.targetTouches.length;i++)this.interactions[i]={positionInViewport:new e((t.targetTouches[i].clientX-this.canvas.offsetLeft)/(this.canvas.clientWidth/this.canvas.width)-this.canvas.width/2,-(t.targetTouches[i].clientY-this.canvas.offsetTop)/(this.canvas.clientHeight/this.canvas.height)+this.canvas.height/2),radius:new e(t.targetTouches[i].radiusX,t.targetTouches[i].radiusY)}}onUpdate(){this.touchScreen.touching=this.touching,this.touchScreen.interactions=this.touching?[...this.interactions]:[]}};me=Tt([l(kt.TouchScreenSystem),Pt(0,c(Et.CanvasElement)),Pt(1,c(Et.InputManager))],me);class fe{constructor(t){this.animations=new Map,this.speed=1,this.reset=!1,this.playing=!1,this.currentFrame=0,this.currentTime=0,this.ignoreTimeScale=!1,this._currentAnimation=void 0,this._assetsReady=!1,Object.assign(this,t)}play(t){void 0!==t&&t!==this.animation&&(this.animation=t,this.reset=!0),this.playing=!0}pause(){this.playing=!1}stop(){this.playing=!1,this.currentFrame=0,this.currentTime=0}}fe.componentName="Animator";class ye{constructor(t){this.layer=Ht,this.smooth=!1,this.offset=new e,this.flipHorizontally=!1,this.flipVertically=!1,this.rotation=0,this.opacity=1,this.scale=new e(1,1),this._renderData={type:lt.Sprite,position:new e,layer:void 0,image:void 0,width:void 0,height:void 0},Object.assign(this,t)}}ye.componentName="SpriteRenderer";let xe=class{constructor(t,e,i){this.entityManager=t,this.timeManager=e,this.assetManager=i}onUpdate(){this.entityManager.search(fe,((t,e)=>{if(this.processAssets(t),this.reset(t),this.animation=t.animations.get(t.animation),!this.animation)return;this.play(t),t._currentAnimation=t.animation;const i=this.entityManager.getComponent(e,ye);i&&this.renderSprite(t,i)}))}processAssets(t){t._assetsReady||(t.animations.forEach((t=>{if("string"==typeof t.image){if(t.image=this.assetManager.getImage(t.image),!t.image)throw new Error(`Asset ${t.image} not found`)}else Array.isArray(t.image)&&(t.image=t.image.map((t=>{if("string"==typeof t){const e=this.assetManager.getImage(t);if(!e)throw new Error(`Asset ${t} not found`);return e}return t})))})),t._assetsReady=!0)}reset(t){t.reset&&(t.currentFrame=0,t.currentTime=0,t.playing=void 0!==t.animation,t.reset=!1)}play(t){t.animation!==t._currentAnimation&&(t._currentAnimation=t.animation,t.currentFrame=0,t.currentTime=0,t.playing=!0),t.playing&&(t.currentTime>=1/this.animation.fps*(t.currentFrame+1)&&(t.currentFrame===this.animation.frames.length-1?this.animation.loop?(t.currentFrame=0,t.currentTime=0):t.playing=!1:t.currentFrame++),t.currentTime+=(t.ignoreTimeScale?this.timeManager.unscaledRenderDeltaTime:this.timeManager.renderDeltaTime)*t.speed)}renderSprite(t,e){if(Array.isArray(this.animation.image))e.image=this.animation.image[t.currentFrame];else{if("string"==typeof this.animation.image)return;const i=this.animation.frames[t.currentFrame],s=Math.ceil(this.animation.image.naturalWidth/this.animation.slice.size.x);e.image=this.animation.image,e.slice={x:i%s*this.animation.slice.size.x+this.animation.slice.offset.x,y:Math.floor(i/s)*this.animation.slice.size.y+this.animation.slice.offset.y,width:this.animation.slice.size.x-this.animation.slice.padding.y,height:this.animation.slice.size.y-this.animation.slice.padding.y}}}};xe=Tt([l(kt.AnimatorSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager)),Pt(2,c(Et.AssetManager))],xe);let Me=class{constructor(t,e){this.entityManager=t,this.timeManager=e,this.tilesets=new Set}onUpdate(){this.tilesets.clear(),this.entityManager.search(ee,(t=>{t.tilesets.forEach((t=>this.tilesets.add(t)))})),this.tilesets.forEach((t=>this.updateTileset(t)))}updateTileset(t){var e;t.animations&&0!==t.animations.size?(t._animationState||(t._animationState=new Map),t._animationState.forEach(((e,i)=>{t.animations.has(i)||t._animationState.delete(i)})),t.animations.forEach(((e,i)=>{this.advance(e),t._animationState.set(i,e.tiles[e.currentFrame])}))):null===(e=t._animationState)||void 0===e||e.clear()}advance(t){0!==t.tiles.length&&(t.currentTime>=1/t.fps*(t.currentFrame+1)&&(t.currentFrame===t.tiles.length-1?(t.currentFrame=0,t.currentTime=0):t.currentFrame++),t.currentTime+=this.timeManager.renderDeltaTime)}};Me=Tt([l(kt.TilemapAnimationSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager))],Me);let ve=class{constructor(t,e){this.entityManager=t,this.renderManager=e}onUpdate(){this.entityManager.search($t,((t,e)=>{const i=this.entityManager.getComponent(e,Wt);if(!i)throw new Error("Camera component needs a Transform");t._renderData.position.copy(i.localPosition),t._renderData.layers=[...t.layers],t._renderData.depth=t.depth,t._renderData.zoom=t.zoom,t.debug&&t._renderData.layers.push(Yt),this.renderManager.addCameraData(t._renderData)}))}};ve=Tt([l(kt.CameraSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],ve);let Ce=class{constructor(t,e){this.webGLManager=t,this.gameConfig=e}onUpdate(){this.webGLManager.renderCanvasColor(this.gameConfig.canvasColor)}};Ce=Tt([l(kt.ClearScreenSystem),Pt(0,c(Et.WebGLManager)),Pt(1,c(Et.GameConfig))],Ce);class be{constructor(t){this.radius=0,this.offset=new e,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}be.componentName="BallCollider";class Se{constructor(t){this.layer="",this.physics=!0,this.width=0,this.height=0,this.offset=new e,this.rotation=0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}Se.componentName="BoxCollider";class we{constructor(t){this.vertexModel=[],this.offset=new e,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}we.componentName="EdgeCollider";class Ae{constructor(t){this.vertexModel=[],this.offset=new e,this.rotation=0,this.layer="",this.physics=!0,this.ignoreCollisionsWithLayers=[],this.shapes=[],Object.assign(this,t)}}Ae.componentName="PolygonCollider";class Re{constructor(t){this.composite=!0,this.layer="",this.ignoreCollisionsWithLayers=[],this.offset=new e,this.physics=!0,this.shapes=[],Object.assign(this,t)}refresh(){this.shapes=[]}}Re.componentName="TilemapCollider";let _e=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.colliders)&&[be,Se,Ae,we,Re].forEach((t=>this.entityManager.search(t,(t=>t.shapes.forEach((t=>{const i={type:lt.Geometric,position:new e,layer:Yt,color:this.gameConfig.debug.collidersColor,shape:void 0,radius:void 0,rotation:void 0,vertexModel:void 0};t instanceof M?this.gameConfig.collisions.collisionMethod===exports.CollisionMethods.SAT?(i.shape=t.vertices.length>2?exports.GeometricShape.Polygon:exports.GeometricShape.Line,i.vertexModel=t.vertices):this.gameConfig.collisions.collisionMethod===exports.CollisionMethods.AABB&&(i.shape=exports.GeometricShape.Polygon,i.vertexModel=[new e(t.boundingBox.x,t.boundingBox.y),new e(t.boundingBox.x,t.boundingBox.y1),new e(t.boundingBox.x1,t.boundingBox.y1),new e(t.boundingBox.x1,t.boundingBox.y)]):t instanceof v&&(i.shape=exports.GeometricShape.Circumference,i.position.copy(t.position),i.radius=t.radius),this.renderManager.addRenderData(i)}))))))}};_e=Tt([l(kt.DebugColliderRenderSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],_e);let Ee=class{constructor(t,e){this.renderManager=t,this.canvas=e,this.viewport={x:0,x1:0,y:0,y1:0},this.object={x:0,x1:0,y:0,y1:0},this.culledRenderData=[]}onUpdate(){this.culledRenderData=[],this.renderManager.getCameraData().forEach((t=>{this.setViewport(t),this.renderManager.getRenderData().filter((e=>t.layers.includes(e.layer))).forEach((t=>{this.isInViewPort(t)&&(t.type===lt.Tilemap&&this.applyCullingInTiles(t),this.culledRenderData.push(t))}))})),this.renderManager.setRenderData(this.culledRenderData)}isInViewPort(t){switch(t.type){case lt.Video:case lt.Darkness:case lt.Sprite:this.setObjectForResizeable(t);break;case lt.Mask:this.setObjectForMask(t);break;case lt.Geometric:this.setObjectForGeometric(t);break;case lt.Text:this.setObjectForText(t);break;case lt.Tilemap:this.setObjectForTilemap(t)}return this.viewport.x1>=this.object.x&&this.viewport.x<=this.object.x1&&this.viewport.y1>=this.object.y&&this.viewport.y<=this.object.y1}setViewport({position:t,zoom:e}){this.viewport.x=t.x-this.canvas.width/e/2,this.viewport.x1=t.x+this.canvas.width/e/2,this.viewport.y=t.y-this.canvas.height/e/2,this.viewport.y1=t.y+this.canvas.height/e/2}setObjectForResizeable({position:t,width:e,height:i,rotation:s=0,tiled:o}){const r=Math.abs(Math.sin(s)),n=Math.abs(Math.cos(s));o&&(e*=o.x,i*=o.y);const a=r*i+n*e,h=r*e+n*i;this.object.x=t.x-a/2,this.object.x1=t.x+a/2,this.object.y=t.y-h/2,this.object.y1=t.y+h/2}setObjectForText({position:t,text:e,fontSize:i,lineHeight:s,letterSpacing:o,rotation:r}){const n=e.split("\n").reduce(((t,e)=>Math.max(t,e.length)),0)*(i+(null!=o?o:0))*2,a=e.split("\n").length*(null!=s?s:i);this.setObjectForResizeable({position:t,width:n,height:a,rotation:r})}setObjectForGeometric({position:t,vertexModel:e,shape:i,radius:s}){i===exports.GeometricShape.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)})))}setObjectForMask({position:t,vertices:e,shape:i,radius:s,rotation:o,width:r,height:n}){i===exports.MaskShape.Circumference?(this.object.x=t.x-s,this.object.y=t.y-s,this.object.x1=t.x+s,this.object.y1=t.y+s):i===exports.MaskShape.Polygon?(this.object.x=Number.MAX_SAFE_INTEGER,this.object.y=Number.MAX_SAFE_INTEGER,this.object.x1=Number.MIN_SAFE_INTEGER,this.object.y1=Number.MIN_SAFE_INTEGER,e.forEach((e=>{this.object.x=Math.min(e.x+t.x,this.object.x),this.object.y=Math.min(e.y+t.y,this.object.y),this.object.x1=Math.max(e.x+t.x,this.object.x1),this.object.y1=Math.max(e.y+t.y,this.object.y1)}))):this.setObjectForResizeable({position:t,width:r,height:n,rotation:o})}setObjectForTilemap(t){this.setObjectForResizeable({position:t.position,width:t.tilemap.realWidth,height:t.tilemap.realHeight,rotation:t.rotation})}applyCullingInTiles(t){const{tiles:e,tilemap:{width:i,tileWidth:s,tileHeight:o}}=t;t.tiles=e.map(((t,e)=>this.viewport.x1>=this.object.x+e%i*s&&this.viewport.x<=this.object.x+e%i*s+s&&this.viewport.y1>=this.object.y1-((e/i|0)*o+o)&&this.viewport.y<=this.object.y1-(e/i|0)*o?t:0))}};Ee=Tt([l(kt.CullingSystem),Pt(0,c(Et.RenderManager)),Pt(1,c(Et.CanvasElement))],Ee);class Te{constructor(t){this.width=0,this.height=0,this.radius=0,this.vertexModel=[],this.color="#000000",this.offset=new e,this.rotation=0,this.opacity=1,this.layer=Ht,this._renderData={type:lt.Mask,color:void 0,height:void 0,vertices:[],layer:void 0,opacity:void 0,position:new e,radius:void 0,rotation:void 0,shape:void 0,width:void 0},Object.assign(this,t)}}Te.componentName="MaskRenderer";let Pe=class{constructor(t,i){this.entityManager=t,this.renderManager=i,this.scaledOffset=new e}onUpdate(){this.entityManager.search(Te,((t,i)=>{const s=this.entityManager.getComponent(i,Wt);if(!s)throw new Error("MaskRenderer component needs a Transform");this.scaledOffset.set(t.offset.x*s.localScale.x,t.offset.y*s.localScale.y),e.add(t._renderData.position,s.localPosition,this.scaledOffset),t._renderData.width=t.width*Math.abs(s.localScale.x),t._renderData.height=t.height*Math.abs(s.localScale.y),t._renderData.rotation=s.localRotation+t.rotation,t._renderData.color=t.color,t._renderData.layer=t.layer,t._renderData.opacity=t.opacity,t._renderData.radius=t.radius*Math.max(Math.abs(s.localScale.x),Math.abs(s.localScale.y)),t._renderData.shape=t.shape,t.shape===exports.MaskShape.Polygon&&(t._renderData.vertices.length!==t.vertexModel.length&&(t._renderData.vertices=t.vertexModel.map((()=>new e))),t.vertexModel.forEach(((e,i)=>t._renderData.vertices[i].set(e.x*s.localScale.x,e.y*s.localScale.y))),0!==s.localRotation&&t._renderData.vertices.forEach((t=>t.set(t.x*Math.cos(s.localRotation)-t.y*Math.sin(s.localRotation),t.x*Math.sin(s.localRotation)+t.y*Math.cos(s.localRotation))))),0!==s.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,s),this.renderManager.addRenderData(t._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Pe=Tt([l(kt.MaskRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],Pe);let Be=class{constructor(t){this.renderManager=t}onUpdate(){this.renderManager.render(),this.renderManager.removeCameraData(),this.renderManager.removeRenderData()}};Be=Tt([l(kt.RenderSystem),Pt(0,c(Et.RenderManager))],Be);class De{constructor(t){this.radius=0,this.smooth=!1,this.steps=0,this.layer=Ht,this.intensity=1,this._boundingBox=new i,Object.assign(this,t)}}De.componentName="LightRenderer";class Fe{constructor(t){this.width=0,this.height=0,this.color="#000000",this.opacity=1,this.layer=Ht,this._boundingBox=new i,this._renderData={type:lt.Darkness,layer:void 0,color:void 0,opacity:void 0,width:void 0,height:void 0,position:void 0,rotation:void 0,lights:[]},Object.assign(this,t)}}Fe.componentName="DarknessRenderer";let je=class{constructor(t,e){this.entityManager=t,this.renderManager=e,this.lightRenderers=[],this.processLightRenderer=(t,e)=>{this.updateLightRendererBoundingBox(e,t),this.lightRenderers.push(t)},this.processDarknessRenderer=(t,e)=>{this.updateDarknessRendererBoundingBox(e,t),t._renderData.layer=t.layer,t._renderData.color=t.color,t._renderData.opacity=t.opacity,t._renderData.width=t._boundingBox.width,t._renderData.height=t._boundingBox.height,t._renderData.position=t._boundingBox.center,t._renderData.rotation=0,this.updateLights(t),this.renderManager.addRenderData(t._renderData)}}onUpdate(){this.lightRenderers.length=0,this.entityManager.search(De,this.processLightRenderer),this.entityManager.search(Fe,this.processDarknessRenderer)}updateLights(t){const e=t._renderData.lights;let i=0;for(let s=0;s<this.lightRenderers.length;s++){const o=this.lightRenderers[s];if(o.layer!==t.layer||!o._boundingBox.intersects(t._boundingBox))continue;i===e.length&&e.push({position:void 0,radius:0,smooth:!1,steps:0,intensity:0,color:void 0});const r=e[i++];r.position=o._boundingBox.center,r.radius=o._boundingBox.width/2,r.smooth=o.smooth,r.steps=o.steps,r.intensity=o.intensity,r.color=o.color}e.length=i}updateLightRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,Wt);if(!i)throw new Error("LightRenderer component needs a Transform");const s=e.radius*Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y));e._boundingBox.set(i.localPosition.x-s,i.localPosition.y-s,2*s,2*s)}updateDarknessRendererBoundingBox(t,e){const i=this.entityManager.getComponent(t,Wt);if(!i)throw new Error("DarknessRenderer component needs a Transform");const s=e.width*Math.abs(i.localScale.x),o=e.height*Math.abs(i.localScale.y);e._boundingBox.set(i.localPosition.x-s/2,i.localPosition.y-o/2,s,o)}};je=Tt([l(kt.DarknessLightRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],je);class Ue{constructor(t){this.shape=exports.GeometricShape.Polygon,this.color="#FFFFFF",this.layer=Ht,this.vertexModel=[],this.radius=0,this.offset=new e,this.rotation=0,this._renderData={type:lt.Geometric,position:new e,layer:Ht,color:"#FFFFFF",shape:exports.GeometricShape.Polygon,vertexModel:[],rotation:0,radius:0},Object.assign(this,t)}}Ue.componentName="GeometricRenderer";let Le=class{constructor(t,i){this.entityManager=t,this.renderManager=i,this.scaledOffset=new e}onUpdate(){this.entityManager.search(Ue,((t,i)=>{const s=this.entityManager.getComponent(i,Wt);if(!s)throw new Error("GeometricRenderer component needs a Transform");if(!this.isValidGeometry(t))return;this.scaledOffset.set(t.offset.x*s.localScale.x,t.offset.y*s.localScale.y),e.add(t._renderData.position,s.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.color=t.color,t._renderData.shape=t.shape,t._renderData.rotation=s.localRotation+t.rotation,0!==s.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,s);const o=s.localScale.x,r=s.localScale.y;t.shape===exports.GeometricShape.Circumference?(t._renderData.radius=t.radius*Math.max(Math.abs(o),Math.abs(r)),t._renderData.vertexModel.length=0):(this.ensureVertexModelLength(t,t.vertexModel.length),t.vertexModel.forEach(((e,i)=>t._renderData.vertexModel[i].set(e.x*o,e.y*r)))),this.renderManager.addRenderData(t._renderData)}))}isValidGeometry(t){switch(t.shape){case exports.GeometricShape.Circumference:return t.radius>0;case exports.GeometricShape.Polygon:return t.vertexModel.length>=3;case exports.GeometricShape.Line:return t.vertexModel.length>=2&&t.vertexModel.length%2==0;default:return!1}}ensureVertexModelLength(t,i){const s=t._renderData.vertexModel;for(;s.length<i;)s.push(new e);s.length=i}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Le=Tt([l(kt.GeometricRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager))],Le);let Ie=class{constructor(t,i,s){this.entityManager=t,this.renderManager=i,this.assetManager=s,this.scaledOffset=new e}onUpdate(){this.entityManager.search(ye,((t,i)=>{var s,o,r,n,a,h;const l=this.entityManager.getComponent(i,Wt);if(!l)throw new Error("SpriteRenderer component needs a Transform");if("string"==typeof t.image&&(t.image=this.assetManager.getImage(t.image),!t.image))throw new Error(`Asset ${t.image} not found`);t.image&&t.image.complete&&(this.scaledOffset.set(t.offset.x*l.localScale.x,t.offset.y*l.localScale.y),e.add(t._renderData.position,l.localPosition,this.scaledOffset),t._renderData.width=(null!==(r=null!==(s=t.width)&&void 0!==s?s:null===(o=t.slice)||void 0===o?void 0:o.width)&&void 0!==r?r:t.image.naturalWidth)*Math.abs(t.scale.x*l.localScale.x),t._renderData.height=(null!==(h=null!==(n=t.height)&&void 0!==n?n:null===(a=t.slice)||void 0===a?void 0:a.height)&&void 0!==h?h:t.image.naturalHeight)*Math.abs(t.scale.y*l.localScale.y),t._renderData.flipHorizontally=t.flipHorizontally!==l.scale.x<0,t._renderData.flipVertically=t.flipVertically!==l.scale.y<0,t._renderData.rotation=l.localRotation+t.rotation,0!==l.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,l),t._renderData.image=t.image,t._renderData.layer=t.layer,t._renderData.maskColor=t.maskColor,t._renderData.maskColorMix=t.maskColorMix,t._renderData.opacity=t.opacity,t._renderData.slice=t.slice,t._renderData.smooth=t.smooth,t._renderData.tintColor=t.tintColor,t._renderData.tiled=t.tiled,this.renderManager.addRenderData(t._renderData))}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Ie=Tt([l(kt.SpriteRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Ie);const Oe={charRanges:[32,132,161,255],fontSize:64,spacing:8};class ke{constructor(t){this.color="#000000",this.flipHorizontally=!1,this.flipVertically=!1,this.font="Arial",this.fontSize=16,this.height=16,this.layer=Ht,this.letterSpacing=0,this.lineHeight=void 0,this.offset=new e,this.opacity=1,this.alignment=exports.TextAlignment.Center,this.rotation=0,this.shadow=void 0,this.smooth=!1,this.text="Hello World!",this.textureAtlas=Object.assign({},Oe),this.width=192,this._renderData={color:void 0,flipHorizontally:!1,flipVertically:!1,font:void 0,fontSize:void 0,layer:void 0,letterSpacing:void 0,lineHeight:void 0,opacity:void 0,position:new e,rotation:void 0,shadow:void 0,smooth:void 0,text:void 0,textureAtlas:Object.assign({},Oe),type:lt.Text,boundingBox:{width:0,height:0},alignment:void 0},Object.assign(this,t)}}ke.componentName="TextRenderer";let Ge=class{constructor(t,i,s){this.entityManager=t,this.renderManager=i,this.assetManager=s,this.scaledOffset=new e}onUpdate(){this.entityManager.search(ke,((t,i)=>{var s;const o=this.entityManager.getComponent(i,Wt);if(!o)throw new Error("TextRenderer component needs a Transform");if("string"==typeof t.font){const e=this.assetManager.getFont(t.font);e&&(t.font=e)}if(0===t.text.length||t.font instanceof FontFace&&"loaded"!==t.font.status)return;this.scaledOffset.set(t.offset.x*o.localScale.x,t.offset.y*o.localScale.y),e.add(t._renderData.position,o.localPosition,this.scaledOffset),t._renderData.layer=t.layer,t._renderData.font=t.font,t._renderData.fontSize=t.fontSize,t._renderData.text=t.text,t._renderData.color=t.color,t._renderData.lineHeight=null!==(s=t.lineHeight)&&void 0!==s?s:t.fontSize,t._renderData.letterSpacing=t.letterSpacing,t._renderData.smooth=t.smooth,t._renderData.rotation=o.localRotation+t.rotation,t._renderData.opacity=t.opacity,t._renderData.boundingBox={width:t.width,height:t.height},t._renderData.alignment=t.alignment;const{charRanges:r,fontSize:n,spacing:a}=t.textureAtlas;r&&(t._renderData.textureAtlas.charRanges=t.textureAtlas.charRanges),n&&(t._renderData.textureAtlas.fontSize=t.textureAtlas.fontSize),a&&(t._renderData.textureAtlas.spacing=t.textureAtlas.spacing),t._renderData.flipHorizontally=t.flipHorizontally,t._renderData.flipVertically=t.flipVertically,t._renderData.shadow=t.shadow,0!==o.localRotation&&this.scaledOffset.magnitude>0&&this.translateRenderPosition(t._renderData,o),this.renderManager.addRenderData(t._renderData)}))}translateRenderPosition(t,e){const i=Math.atan2(this.scaledOffset.y,this.scaledOffset.x)+e.localRotation;t.position.set(e.localPosition.x+this.scaledOffset.magnitude*Math.cos(i),e.localPosition.y+this.scaledOffset.magnitude*Math.sin(i))}};Ge=Tt([l(kt.TextRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Ge);let Ve=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.assetManager=i}onUpdate(){this.entityManager.search(ee,((t,e)=>{const i=this.entityManager.getComponent(e,Wt);if(!i)throw new Error("TilemapRenderer component needs a Transform");t.tilesets.forEach((t=>{if("string"==typeof t.image){const e=this.assetManager.getImage(t.image);if(!e)throw new Error(`Asset ${t.image} not found`);t.image=e}})),t._processed&&t.tilesets.forEach(((e,s)=>{e.image&&e.image.complete&&t.chunks.forEach(((o,r)=>{const n=s*t.chunks.length+r;t._renderData[n]||(t._renderData[n]=Ne());const a=t._renderData[n];a.type=lt.Tilemap,a.orientation=exports.TilemapOrientation.Center,a.layer=t.layer,a.tilemap.width=o.width,a.tilemap.height=o.height,a.tilemap.tileWidth=t.tileWidth*Math.abs(i.localScale.x),a.tilemap.tileHeight=t.tileHeight*Math.abs(i.localScale.y),a.tilemap.realWidth=a.tilemap.width*a.tilemap.tileWidth,a.tilemap.realHeight=a.tilemap.height*a.tilemap.tileHeight,a.tiles=o.data,a.tileset=e,a.opacity=t.opacity,a.rotation=i.localRotation,a.tintColor=t.tintColor,a.smooth=t.smooth,a.maskColor=t.maskColor,a.maskColorMix=t.maskColorMix,a.position.x=i.localPosition.x+t.offset.x*i.localScale.x+(o.x-t.width/2+o.width/2)*a.tilemap.tileWidth,a.position.y=i.localPosition.y+t.offset.y*i.localScale.y+(t.height/2-o.y-o.height/2)*a.tilemap.tileHeight,this.renderManager.addRenderData(a)}))}))}))}};Ve=Tt([l(kt.TilemapRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.AssetManager))],Ve);const Ne=()=>({type:lt.Tilemap,layer:void 0,position:new e,tilemap:{height:void 0,realHeight:void 0,realWidth:void 0,tileHeight:void 0,tileWidth:void 0,width:void 0},tiles:void 0,tileset:void 0});var ze;exports.RigidBodyType=void 0,(ze=exports.RigidBodyType||(exports.RigidBodyType={}))[ze.Dynamic=0]="Dynamic",ze[ze.Kinematic=1]="Kinematic",ze[ze.Static=2]="Static";class We{constructor(t){this.type=exports.RigidBodyType.Dynamic,this.velocity=new e,this.gravity=0,this.acceleration=new e,this.staticForLayers=[],Object.assign(this,t)}}We.componentName="RigidBody";let He=class{constructor(t,i,s){this.entityManager=t,this.timeManager=i,this.transformSystem=s,this.types=new Set([exports.RigidBodyType.Dynamic,exports.RigidBodyType.Kinematic]),this.displacement=new e,this.totalAcceleration=new e,this.scaledAcceleration=new e,this.scaledVelocity=new e}onUpdate(){this.timeManager.timeScale<=0||(this.entityManager.search(We,(({velocity:t,acceleration:i,gravity:s,type:o},r)=>{if(!this.types.has(o))return;const{position:n}=this.entityManager.getComponent(r,Wt);o===exports.RigidBodyType.Dynamic?(this.totalAcceleration.y=i.y-s,this.totalAcceleration.x=i.x):this.totalAcceleration.copy(i),e.add(t,t,e.scale(this.scaledAcceleration,this.totalAcceleration,this.timeManager.physicsDeltaTime)),e.add(n,n,e.add(this.displacement,e.scale(this.scaledVelocity,t,this.timeManager.physicsDeltaTime),e.scale(this.scaledAcceleration,this.totalAcceleration,.5*Math.pow(this.timeManager.physicsDeltaTime,2))))})),this.transformSystem.onUpdate())}};He=Tt([l(kt.ApplyVelocitySystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.TimeManager)),Pt(2,c(kt.TransformSystem))],He);class Ye{constructor(){this.auxMin=new e,this.auxMax=new e,this.auxScaledOffset=new e}updatePositionAndVertices(t,e,i){this.translatePosition(t,e,i),t instanceof M?(this.auxAngle=t.rotation+i.localRotation,t.vertexModel.forEach(((e,s)=>t.vertices[s].set(e.x*i.localScale.x,e.y*i.localScale.y))),t.vertices.forEach((e=>e.set(e.x*Math.cos(this.auxAngle)-e.y*Math.sin(this.auxAngle)+t.position.x,e.x*Math.sin(this.auxAngle)+e.y*Math.cos(this.auxAngle)+t.position.y)))):t instanceof v&&(t.radius*=Math.max(Math.abs(i.localScale.x),Math.abs(i.localScale.y)))}translatePosition(t,i,{localPosition:s,localScale:o,localRotation:r}){if(this.auxScaledOffset.set(i.x*o.x,i.y*o.y),0!==r){const e=Math.atan2(this.auxScaledOffset.y,this.auxScaledOffset.x)+r,i=this.auxScaledOffset.magnitude;t.position.set(s.x+i*Math.cos(e),s.y+i*Math.sin(e))}else e.add(t.position,s,this.auxScaledOffset)}updateBoundingBox(t){t instanceof v?this.updateCircumferenceBoundingBox(t):t instanceof M&&this.updatePolygonBoundingBox(t)}updateCircumferenceBoundingBox(t){t.boundingBox.set(t.position.x-t.radius,t.position.y-t.radius,2*t.radius,2*t.radius)}updatePolygonBoundingBox(t){this.auxMin.x=t.vertices[0].x,this.auxMin.y=t.vertices[0].y,this.auxMax.x=t.vertices[0].x,this.auxMax.y=t.vertices[0].y,t.vertices.forEach((t=>{this.auxMin.x=Math.min(t.x,this.auxMin.x),this.auxMin.y=Math.min(t.y,this.auxMin.y),this.auxMax.x=Math.max(t.x,this.auxMax.x),this.auxMax.y=Math.max(t.y,this.auxMax.y)})),t.boundingBox.set(this.auxMin.x,this.auxMin.y,this.auxMax.x-this.auxMin.x,this.auxMax.y-this.auxMin.y)}updateProjectionAxes(t){var i;if(t.vertices.length>2){const{edgeNormals:s,projectionAxes:o}=t;o.length=0;for(let r=0;r<t.vertices.length;r++){if(e.normal(s[r],e.subtract(s[r],null!==(i=t.vertices[r+1])&&void 0!==i?i:t.vertices[0],t.vertices[r])),0===s[r].x&&0===s[r].y)continue;let n=!1;for(let t=0;t<o.length;t++)if(x(o[t],s[r])){n=!0;break}n||o.push(s[r])}}else e.normal(t.projectionAxes[0],e.subtract(t.projectionAxes[0],t.vertices[1],t.vertices[0]))}}let $e=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(be,((t,e)=>{0===t.shapes.length&&(t.shapes[0]=new v(t.radius)),t.shapes[0].radius=t.radius,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,Wt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};$e=Tt([l(kt.UpdateBallColliderShapeSystem),Pt(0,c(Et.EntityManager))],$e);let Xe=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Se,((t,i)=>{0===t.shapes.length&&(t.shapes[0]=new M([new e,new e,new e,new e])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel[0].set(-t.width/2,-t.height/2),t.shapes[0].vertexModel[1].set(-t.width/2,t.height/2),t.shapes[0].vertexModel[2].set(t.width/2,t.height/2),t.shapes[0].vertexModel[3].set(t.width/2,-t.height/2),this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(i,Wt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Xe=Tt([l(kt.UpdateBoxColliderShapeSystem),Pt(0,c(Et.EntityManager))],Xe);let qe=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(we,((t,i)=>{for(let s=0;s<t.vertexModel.length-1;s++)t.shapes[s]||(t.shapes[s]=new M([new e,new e])),t.shapes[s].rotation=t.rotation,t.shapes[s].vertexModel=[t.vertexModel[s],t.vertexModel[s+1]],this.updatePositionAndVertices(t.shapes[s],t.offset,this.entityManager.getComponent(i,Wt)),this.updateBoundingBox(t.shapes[s]),this.updateProjectionAxes(t.shapes[s])}))}};qe=Tt([l(kt.UpdateEdgeColliderShapeSystem),Pt(0,c(Et.EntityManager))],qe);let Ke=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(Ae,((t,e)=>{0===t.shapes.length&&(t.shapes[0]=new M([])),t.shapes[0].rotation=t.rotation,t.shapes[0].vertexModel=t.vertexModel,this.updatePositionAndVertices(t.shapes[0],t.offset,this.entityManager.getComponent(e,Wt)),this.updateBoundingBox(t.shapes[0]),this.updateProjectionAxes(t.shapes[0])}))}};Ke=Tt([l(kt.UpdatePolygonColliderShapeSystem),Pt(0,c(Et.EntityManager))],Ke);let Je=class extends Ye{constructor(t){super(),this.entityManager=t,this.offset=new e}onUpdate(){this.entityManager.search(Re,((t,i)=>{const s=this.entityManager.getComponent(i,ee);if(s&&0!==s.data.length){0===t.shapes.length&&(t.composite?this.useEdges(t,s):this.useBoxes(t,s)),e.add(this.offset,t.offset,s.offset);for(const e of t.shapes)this.updatePositionAndVertices(e,this.offset,this.entityManager.getComponent(i,Wt)),this.updateBoundingBox(e),this.updateProjectionAxes(e)}}))}useBoxes(t,e){t.shapes=[],e.data.forEach(((i,s)=>{if(!this.needsCollider(i,s,e))return;const o=new M(this.generateRectangleVertices(s,e));o.updateCollisions=!1,t.shapes.push(o)}))}generateRectangleVertices(t,{width:i,height:s,tileWidth:o,tileHeight:r}){const n=-i*o/2+t%i*o,a=s*r/2-Math.floor(t/i)*r;return[new e(n,a-r),new e(n,a),new e(n+o,a),new e(n+o,a-r)]}needsCollider(t,e,{data:i,width:s,height:o}){return 0!==t&&this.getNeighbors(e,s,o).some((t=>!t||!i[t]||0===i[t]))}useEdges(t,i){t.shapes=[];const s=[],o=[];let r,n;i.data.forEach(((t,e)=>{if(0===t)return;const r=e%i.width,n=Math.floor(e/i.width);s[n]||(s[n]=[]),s[n+1]||(s[n+1]=[]),o[n]||(o[n]=[]),o[n+1]||(o[n+1]=[]);const a=this.getNeighbors(e,i.width,i.height);this.hasTile(a[0],i)||(s[n][r]=!0),this.hasTile(a[2],i)||(s[n+1][r]=!0),this.hasTile(a[1],i)||(o[n][r]=!0),this.hasTile(a[3],i)||(o[n][r+1]=!0)}));for(let o=0;o<s.length;o++)if(s[o])for(let a=0;a<s[o].length;a++)!r||!n||o===n.y&&s[o][a]||(t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0),s[o][a]&&(r||(r=new e(a,o)),n=new e(a+1,o));r&&n&&t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0;for(let s=0;s<=i.width;s++)for(let a=0;a<o.length;a++)o[a]&&(!r||!n||s===n.x&&o[a][s]||(t.shapes.push(this.createEdge(r,n,i)),r=void 0,n=void 0),o[a][s]&&(r||(r=new e(s,a)),n=new e(s,a+1)));r&&n&&t.shapes.push(this.createEdge(r,n,i))}hasTile(t,{data:e}){return void 0!==t&&e[t]&&e[t]>0}createEdge(t,i,{width:s,height:o,tileWidth:r,tileHeight:n}){t.x=-s*r/2+t.x*r,t.y=o*n/2-t.y*n,i.x=-s*r/2+i.x*r,i.y=o*n/2-i.y*n;const a=new M([new e(t.x,t.y),new e(i.x,i.y)]);return a.updateCollisions=!1,a}getNeighbors(t,e,i){return[t-e>=0?t-e:void 0,t%e>0?t-1:void 0,t+e<=e*i?t+e:void 0,t%e<e-1?t+1:void 0]}};Je=Tt([l(kt.UpdateTilemapColliderShapeSystem),Pt(0,c(Et.EntityManager))],Je);let Qe=class{constructor(t,e,i,s,o,r){if(this.entityManager=t,this.broadPhaseResolver=e,this.collisionResolutionMethod=s,this.collisionRepository=o,this.collisionResolutionPool=r,this.colliderTypes=[be,Se,Ae,we,Re],this.colliders=[],this.resolvedCollisions=new Set,this.shapes=[],i){const t=new Map;for(let e=0;e<i.length;e++){const[s,o]=i[e];t.has(s)||t.set(s,new Set),t.has(o)||t.set(o,new Set),t.get(s).add(o),t.get(o).add(s)}this.layerNeighbors=t}}onUpdate(){this.collisionRepository.clear(),this.resolvedCollisions.clear(),this.collisionResolutionPool.clear(),this.colliders.length=0,this.shapes.length=0,this.colliderTypes.forEach((t=>this.entityManager.search(t,((t,e)=>{this.colliders.push(t),t.shapes.forEach((i=>{var s;i.entity=e,i.collider=this.colliders.length-1,i.id=this.shapes.length,i.ignoreCollisionsWithLayers=null!==(s=t.ignoreCollisionsWithLayers)&&void 0!==s?s:[],i.layer=t.layer,this.shapes.push(i)}))})))),this.broadPhaseResolver.update(this.shapes),this.shapes.filter((t=>t.updateCollisions)).forEach((t=>this.narrowPhase(t,this.broadPhase(t))))}broadPhase({boundingBox:t,layer:e}){const i=this.broadPhaseResolver.retrieve(t),s=i.length,o=[];if(this.layerNeighbors){const t=this.layerNeighbors.get(e);if(!t)return o;for(let e=0;e<s;e++){const s=this.shapes[i[e]];t.has(s.layer)&&o.push(s)}return o}for(let t=0;t<s;t++)o.push(this.shapes[i[t]]);return o}narrowPhase(t,e){e.filter((e=>t.entity!==e.entity&&t.id!==e.id&&!t.ignoreCollisionsWithLayers.includes(e.layer)&&!e.ignoreCollisionsWithLayers.includes(t.layer)&&!this.isResolved(t,e))).forEach((e=>{this.resolvedCollisions.add(`${t.id}-${e.id}`),this.resolvedCollisions.add(`${e.id}-${t.id}`);const i=this.collisionResolutionMethod.findCollision(t,e);i&&this.collisionRepository.persist(t.entity,this.colliders[t.collider],e.entity,this.colliders[e.collider],i)}))}isResolved(t,e){return this.resolvedCollisions.has(`${t.id}-${e.id}`)}};Qe=Tt([l(kt.ResolveCollisionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.CollisionBroadphaseResolver)),Pt(2,c(Et.CollisionMatrix)),Pt(3,c(Et.CollisionResolutionMethod)),Pt(4,c(Et.CollisionRepository)),Pt(5,c(Et.CollisionResolutionPool))],Qe);let Ze=class{constructor(t,i,s){this.entityManager=t,this.collisionRepository=i,this.transformSystem=s,this.correction=new e,this.maxCorrection=new e,this.aux=new e}onUpdate(){const t=this.collisionRepository.getCollisions().filter((({localCollider:t,remoteCollider:e,remoteEntity:i,localEntity:s})=>t.physics&&e.physics&&this.entityManager.hasComponent(s,We)&&this.entityManager.hasComponent(i,We)));0!==t.length&&(this.entityManager.search(We,((i,s)=>{if(i.type!==exports.RigidBodyType.Dynamic)return;if(this.maxCorrection.set(0,0),t.filter((({localEntity:t,remoteEntity:e})=>s===t||s===e)).forEach((t=>{const o=t.remoteEntity===s,r=this.entityManager.getComponent(o?t.localEntity:t.remoteEntity,We),n=o?t.remoteCollider.layer:t.localCollider.layer,a=o?t.localCollider.layer:t.remoteCollider.layer;if(r.type===exports.RigidBodyType.Dynamic&&i.staticForLayers.includes(a))return;const h=r.type!==exports.RigidBodyType.Dynamic||r.staticForLayers.includes(n);let l=t.resolution.penetration;const c=o?e.scale(this.aux,t.resolution.direction,-1):t.resolution.direction;h||(l/=2),e.scale(this.correction,c,-l),this.correction.magnitude>this.maxCorrection.magnitude&&this.maxCorrection.copy(this.correction)})),0===this.maxCorrection.x&&0===this.maxCorrection.y)return;const{position:o}=this.entityManager.getComponent(s,Wt);e.add(o,o,this.maxCorrection),i.gravity>0&&this.maxCorrection.y*i.velocity.y<0&&(i.velocity.y=0)})),this.transformSystem.onUpdate())}};Ze=Tt([l(kt.ApplyRepositionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.CollisionRepository)),Pt(2,c(kt.TransformSystem))],Ze);const ti=new Set([Se,be,Ae,we,Re]);let ei=class extends Ye{constructor(t){super(),this.entityManager=t}onUpdate(){this.entityManager.search(We,((t,e)=>{if(t.type!==exports.RigidBodyType.Dynamic)return;const i=this.entityManager.getComponent(e,Wt);for(const t of ti)if(this.entityManager.hasComponent(e,t)){const s=this.entityManager.getComponent(e,t);s.shapes.forEach((t=>{this.updatePositionAndVertices(t,s.offset,i),this.updateBoundingBox(t)}))}}))}};ei=Tt([l(kt.UpdateCollidersAfterRepositionSystem),Pt(0,c(Et.EntityManager))],ei);const ii=24;let si=class{constructor(t,i,s,o,r){this.entityManager=t,this.renderManager=i,this.inputManager=s,this.canvas=o,this.gameConfig=r,this.positionInViewport=new e,this.positionInCameraViewport=new e,this.positionInWorldspace=new e,this.renderDataPerCamera=new Map}onUpdate(){var t;if(!(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.mousePosition)||!this.inputManager.mouse)return;const{positionInViewport:i}=this.inputManager.mouse;this.entityManager.search($t,((t,s)=>{if(!t.debug)return;const{zoom:o}=t,r=this.entityManager.getComponent(s,Wt).position;this.renderDataPerCamera.has(s)||this.renderDataPerCamera.set(s,oi());const n=this.renderDataPerCamera.get(s);e.floor(this.positionInWorldspace,e.add(this.positionInWorldspace,r,e.scale(this.positionInWorldspace,i,1/o))),e.floor(this.positionInCameraViewport,e.scale(this.positionInCameraViewport,i,1/o)),e.round(this.positionInViewport,i),n.color=this.gameConfig.debug.textColor,n.text=`mouse_position: canvas_viewport=${this.positionInViewport}, camera_viewport=${this.positionInCameraViewport}, world_space=${this.positionInWorldspace}`,n.fontSize=ii/o,n.lineHeight=n.fontSize,n.shadow.offset.x=2/o,n.shadow.offset.y=-2/o,n.boundingBox={width:this.canvas.width/o,height:n.fontSize},this.updateRenderDataPosition(n,r,o),this.renderManager.addRenderData(n)}))}updateRenderDataPosition(t,e,i){switch(t.position.x=e.x,this.gameConfig.debug.textPosition){case"top-right":t.alignment=exports.TextAlignment.Right,t.position.y=e.y+(this.canvas.height/2-ii)/i;break;case"top-left":t.alignment=exports.TextAlignment.Left,t.position.y=e.y+(this.canvas.height/2-ii)/i;break;case"bottom-left":t.alignment=exports.TextAlignment.Left,t.position.y=e.y-(this.canvas.height/2-ii)/i;break;default:t.alignment=exports.TextAlignment.Right,t.position.y=e.y-(this.canvas.height/2-ii)/i}}};si=Tt([l(kt.DebugMousePositionSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.InputManager)),Pt(3,c(Et.CanvasElement)),Pt(4,c(Et.GameConfig))],si);const oi=(t=24)=>({type:lt.Text,text:"",position:new e,layer:Yt,color:"#00FF00",fontSize:t,font:"Arial",shadow:{color:"#000000",opacity:1,offset:new e(1,-1)},flipHorizontally:!1,flipVertically:!1,letterSpacing:0,lineHeight:t,opacity:1,rotation:0,smooth:!1,textureAtlas:Object.assign({},Oe),boundingBox:{width:0,height:0},alignment:exports.TextAlignment.Left});let ri=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.textRendererBoundingBoxes)&&this.entityManager.search(ke,(({width:t,height:i,rotation:s,layer:o,offset:r},n)=>{const a=this.entityManager.getComponent(n,Wt);if(!a)return;const h={type:lt.Geometric,shape:exports.GeometricShape.Polygon,position:e.add(new e,a.localPosition,r),layer:o,color:this.gameConfig.debug.textBoxColor,radius:void 0,rotation:s+a.localRotation,vertexModel:[new e(-t/2,-i/2),new e(-t/2,i/2),new e(t/2,i/2),new e(t/2,-i/2)]};this.renderManager.addRenderData(h)}))}};ri=Tt([l(kt.DebugTextRendererSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],ri);let ni=class{constructor(t,e,i){this.entityManager=t,this.renderManager=e,this.gameConfig=i}onUpdate(){var t;(null===(t=this.gameConfig.debug)||void 0===t?void 0:t.buttons)&&this.entityManager.search(Jt,(({shape:t,width:i,height:s,radius:o,offset:r},n)=>{if(t!==exports.ButtonShape.Rectangle&&t!==exports.ButtonShape.Circumference)return;const a=this.entityManager.getComponent(n,Wt);if(!a)return;const{localPosition:h,localScale:l}=a,c={type:lt.Geometric,shape:void 0,position:new e(h.x+r.x*l.x,h.y+r.y*l.y),layer:Yt,color:this.gameConfig.debug.buttonColor,radius:void 0,rotation:void 0,vertexModel:void 0};if(t===exports.ButtonShape.Rectangle){const t=i*l.x,o=s*l.y;c.shape=exports.GeometricShape.Polygon,c.vertexModel=[new e(-t/2,-o/2),new e(-t/2,o/2),new e(t/2,o/2),new e(t/2,-o/2)]}else t===exports.ButtonShape.Circumference&&(c.shape=exports.GeometricShape.Circumference,c.radius=o*Math.max(Math.abs(l.x),Math.abs(l.y)));this.renderManager.addRenderData(c)}))}};ni=Tt([l(kt.DebugButtonSystem),Pt(0,c(Et.EntityManager)),Pt(1,c(Et.RenderManager)),Pt(2,c(Et.GameConfig))],ni);const ai=new Map([[Nt.PreGameLogic,[{name:kt.KeyboardSystem,type:pe},{name:kt.MouseSystem,type:ue},{name:kt.TouchScreenSystem,type:me},{name:kt.GamepadSystem,type:ge},{name:kt.ButtonSystem,type:Zt},{name:kt.AudioPlayerSystem,type:Vt},{name:kt.TiledWrapperSystem,type:he},{name:kt.TilemapPreProcessingSystem,type:ce},{name:kt.TiledObjectSystem,type:re}]],[Nt.Transform,[{name:kt.TransformSystem,type:de}]],[Nt.Physics,[{name:kt.ApplyVelocitySystem,type:He},{name:kt.UpdateBallColliderShapeSystem,type:$e},{name:kt.UpdateBoxColliderShapeSystem,type:Xe},{name:kt.UpdateEdgeColliderShapeSystem,type:qe},{name:kt.UpdatePolygonColliderShapeSystem,type:Ke},{name:kt.UpdateTilemapColliderShapeSystem,type:Je},{name:kt.ResolveCollisionSystem,type:Qe},{name:kt.ApplyRepositionSystem,type:Ze},{name:kt.UpdateCollidersAfterRepositionSystem,type:ei}]],[Nt.Render,[{name:kt.AnimatorSystem,type:xe},{name:kt.TilemapAnimationSystem,type:Me},{name:kt.CameraSystem,type:ve},{name:kt.TilemapRendererSystem,type:Ve},{name:kt.SpriteRendererSystem,type:Ie},{name:kt.GeometricRendererSystem,type:Le},{name:kt.MaskRendererSystem,type:Pe},{name:kt.DarknessLightRendererSystem,type:je},{name:kt.TextRendererSystem,type:Ge},{name:kt.VideoRendererSystem,type:Kt},{name:kt.DebugColliderRenderSystem,type:_e},{name:kt.DebugMousePositionSystem,type:si},{name:kt.DebugTextRendererSystem,type:ri},{name:kt.DebugButtonSystem,type:ni},{name:kt.CullingSystem,type:Ee},{name:kt.ClearScreenSystem,type:Ce},{name:kt.RenderSystem,type:Be}]]]);let hi=class{constructor(t,e,i){this.timeManager=t,this.systemManager=e,this.sceneManager=i,this.running=!1,this.gameLoopAccumulator=0}start(){this.running||(this.running=!0,this.gameLoopAccumulator=0,this.enableSystems(),this.sceneManager.loadOpeningScene(),this.requestAnimationLoop(window.performance.now()),this.asyncPhysicsLoop())}enableSystems(){ai.forEach((t=>{t.forEach((({type:t})=>this.systemManager.enableSystem(t)))}))}stop(){var t;this.running&&(null===(t=this.systemManager.getSystem(Vt))||void 0===t||t.onGameStopped(),this.sceneManager.destroyCurrentScene(),this.systemManager.disableAllSystems(),this.running=!1)}requestAnimationLoop(t){this.running&&(this.timeManager.updateForRender(.001*t),this.sceneManager.update(),this.sceneManager.loadingScene||(this.gameLoopAccumulator+=this.timeManager.browserDeltaTime,this.sceneManager.sceneLoadedThisFrame&&(this.gameLoopAccumulator=this.timeManager.fixedGameDeltaTime),this.gameLoopAccumulator>=this.timeManager.fixedGameDeltaTime&&(this.gameLogicIteration(.001*t),this.gameLoopAccumulator-=this.timeManager.fixedGameDeltaTime),this.renderIteration()),window.requestAnimationFrame((t=>this.requestAnimationLoop(t))))}gameLogicIteration(t){this.timeManager.updateForGame(t),this.systemManager.update(Nt.PreGameLogic),this.systemManager.update(Nt.GameLogic),this.timeManager.updateIntervals(),this.systemManager.update(Nt.Transform)}renderIteration(){this.systemManager.groupHasSystems(Nt.GamePreRender)&&(this.systemManager.update(Nt.GamePreRender),this.systemManager.update(Nt.Transform)),this.systemManager.update(Nt.Render)}asyncPhysicsLoop(){this.physicsIntervalId=window.setInterval((()=>{if(!this.running)return window.clearInterval(this.physicsIntervalId);this.timeManager.updateForPhysics(.001*window.performance.now()),document.hidden||this.physicsIteration()}),1e3/this.timeManager.fixedPhysicsFramerate)}physicsIteration(){this.systemManager.groupHasSystems(Nt.GamePhysics)&&(this.systemManager.update(Nt.GamePhysics),this.systemManager.update(Nt.Transform)),this.systemManager.update(Nt.Physics)}};hi=Tt([l(Et.LoopManager),Pt(0,c(Et.TimeManager)),Pt(1,c(Et.SystemManager)),Pt(2,c(Et.SceneManager))],hi);class li{constructor(t,e){this.container=t,this.systemManager=e,this.lastSystemTypeId=0}createSystemIfNotExists(t){if(this.systemManager.hasSystem(t))return;const e="__system_"+this.lastSystemTypeId++;var i;this.container.add(t,e),this.systemManager.addSystem(this.container.get(e),null!==(i=t.prototype.__system_group)&&void 0!==i?i:Nt.GameLogic)}}let ci=class{constructor(t){this.webGLManager=t,this.renderData=[],this.cameraData=[]}addCameraData(t){this.cameraData.push(t)}addRenderData(t){this.renderData.push(t)}setRenderData(t){this.renderData=t}getCameraData(){return this.cameraData}getRenderData(){return this.renderData}removeCameraData(){this.cameraData=[]}removeRenderData(){this.renderData=[]}render(){this.cameraData.sort(((t,e)=>t.depth-e.depth)).forEach((t=>this.renderData.filter((e=>t.layers.includes(e.layer))).sort(((e,i)=>t.layers.indexOf(e.layer)-t.layers.indexOf(i.layer))).forEach((e=>this.webGLManager.render(e,t)))))}};ci=Tt([l(Et.RenderManager),Pt(0,c(Et.WebGLManager))],ci);const di=({headless:t})=>{var e;if(t)return;const i="undefined"!=typeof window?null!==(e=window.AudioContext)&&void 0!==e?e:window.webkitAudioContext:void 0;return i?new i:void 0},gi=t=>{var e,i,s,o,r,n,a,h,l,c,d,g,p;if(!(t.containerNode instanceof HTMLElement))throw new Error("GameConfig Error: Invalid containerNode");if("number"!=typeof t.width)throw new Error("GameConfig Error: Invalid width");if("number"!=typeof t.height)throw new Error("GameConfig Error: Invalid height");t.canvasColor=null!==(e=t.canvasColor)&&void 0!==e?e:"#000000",t.physicsFramerate=null!==(i=t.physicsFramerate)&&void 0!==i?i:180,t.headless=null!==(s=t.headless)&&void 0!==s&&s,t.debug=null!==(o=t.debug)&&void 0!==o?o:{colliders:!1,mousePosition:!1,textRendererBoundingBoxes:!1},t.debug.collidersColor=null!==(r=t.debug.collidersColor)&&void 0!==r?r:"#00FF00",t.debug.textColor=null!==(n=t.debug.textColor)&&void 0!==n?n:"#00FF00",t.debug.textBoxColor=null!==(a=t.debug.textBoxColor)&&void 0!==a?a:"#0000FF",t.debug.buttonColor=null!==(h=t.debug.buttonColor)&&void 0!==h?h:"#FF00FF",t.debug.textPosition=null!==(l=t.debug.textPosition)&&void 0!==l?l:"bottom-left",t.collisions=null!==(c=t.collisions)&&void 0!==c?c:{},t.collisions.collisionBroadPhaseMethod=null!==(d=t.collisions.collisionBroadPhaseMethod)&&void 0!==d?d:exports.BroadPhaseMethods.SpatialGrid,t.collisions.collisionMatrix=null!==(g=t.collisions.collisionMatrix)&&void 0!==g?g:void 0,t.collisions.collisionMethod=null!==(p=t.collisions.collisionMethod)&&void 0!==p?p:exports.CollisionMethods.SAT},pi=({containerNode:t,width:e,height:i})=>{const s=document.createElement("canvas");return s.id="angryPixelGameCanvas",s.width=Math.floor(e),s.height=Math.floor(i),s.tabIndex=0,s.addEventListener("contextmenu",(t=>t.preventDefault())),t.appendChild(s),s.focus(),s},ui=t=>{t.add(exports.EntityManager),t.add(exports.SystemManager),t.set(Et.CreateSystemService,new li(t,t.get(Et.SystemManager))),t.add(exports.TimeManager),t.add(exports.AssetManager),t.add(exports.InputManager),t.add(exports.SceneManager),t.add(exports.InputManager),t.add(hi),t.add(_t),t.add(ci)},mi=t=>{t.get(Et.GameConfig).headless&&fi(ai),ai.forEach(((e,i)=>e.forEach((({type:e,name:s})=>{t.add(e),t.get(Et.SystemManager).addSystem(t.get(s),i)}))))},fi=t=>{t.delete(Nt.Render),t.set(Nt.PreGameLogic,t.get(Nt.PreGameLogic).filter((({name:t})=>![kt.AudioPlayerSystem,kt.ButtonSystem,kt.GamepadSystem,kt.KeyboardSystem,kt.MouseSystem,kt.TouchScreenSystem].includes(t))))},yi=t=>{const{collisions:{collisionBroadPhaseMethod:e,collisionMatrix:i,collisionMethod:s}}=t.get(Et.GameConfig);t.add(I),t.add(exports.CollisionRepository),t.add(F),s===exports.CollisionMethods.AABB?(t.add(T),t.add(B)):t.add(U),t.add(e===exports.BroadPhaseMethods.QuadTree?u:y),t.add(s===exports.CollisionMethods.AABB?S:_),t.set(Et.CollisionMatrix,i)},xi=t=>{const e=t.get(Et.GameConfig);e.dependencies&&e.dependencies.forEach((([e,i])=>{t.set(e,i)}))};class Mi{onUpdate(){}onSceneLoaded(){}onSceneDestroyed(){}}Tt([c(Et.EntityManager)],Mi.prototype,"entityManager",void 0),Tt([c(Et.SystemManager)],Mi.prototype,"systemManager",void 0),Tt([c(Et.AssetManager)],Mi.prototype,"assetManager",void 0),Tt([c(Et.SceneManager)],Mi.prototype,"sceneManager",void 0),Tt([c(Et.TimeManager)],Mi.prototype,"timeManager",void 0),Tt([c(Et.InputManager)],Mi.prototype,"inputManager",void 0),Tt([c(Et.CollisionRepository)],Mi.prototype,"collisionRepository",void 0),Tt([c(Et.GameConfig)],Mi.prototype,"gameConfig",void 0);const vi={AssetManager:Et.AssetManager,CanvasElement:wt.CanvasElement,CollisionRepository:d.CollisionRepository,EntityManager:G.EntityManager,GameConfig:Et.GameConfig,InputManager:Et.InputManager,SceneManager:Et.SceneManager,SystemManager:G.SystemManager,TimeManager:Et.TimeManager};exports.Animation=class{constructor(t){var i,s,o;this.slice={size:new e,offset:new e,padding:new e},this.frames=[],this.fps=12,this.loop=!1,t&&(this.image=t.image,this.frames=null!==(i=t.frames)&&void 0!==i?i:this.frames,this.fps=null!==(s=t.fps)&&void 0!==s?s:this.fps,this.loop=null!==(o=t.loop)&&void 0!==o?o:this.loop,t.slice&&(this.slice.size.copy(t.slice.size),t.slice.offset&&this.slice.offset.copy(t.slice.offset),t.slice.padding&&this.slice.padding.copy(t.slice.padding)))}},exports.Animator=fe,exports.AudioPlayer=Ot,exports.BallCollider=be,exports.BoxCollider=Se,exports.Button=Jt,exports.Camera=$t,exports.Circumference=v,exports.DarknessRenderer=Fe,exports.EdgeCollider=we,exports.Game=class{constructor(t){this.container=(t=>{gi(t);const e=new h;return e.set(Et.GameConfig,t),e.set(Et.CanvasElement,pi(t)),e.set(Et.AudioContext,di(t)),yi(e),ui(e),mi(e),xi(e),e})(t)}get running(){return this.container.get(Et.LoopManager).running}addScene(t,e,i=!1){this.container.get(Et.SceneManager).addScene(t,e,i)}addDependencyType(t,e){this.container.add(t,e)}addDependencyInstance(t,e){this.container.set(e,t)}start(){this.container.get(Et.LoopManager).start()}stop(){this.container.get(Et.LoopManager).stop()}},exports.GameSystem=Mi,exports.GamepadController=Dt,exports.GeometricRenderer=Ue,exports.Keyboard=Ft,exports.LightRenderer=De,exports.MaskRenderer=Te,exports.Mouse=jt,exports.Polygon=M,exports.PolygonCollider=Ae,exports.Rectangle=i,exports.RigidBody=We,exports.SYMBOLS=vi,exports.Scene=class{constructor(t,e){this.entityManager=t,this.assetManager=e,this.systems=[]}loadAssets(){}setup(){}},exports.SpriteRenderer=ye,exports.TextRenderer=ke,exports.TileAnimation=ie,exports.TiledWrapper=te,exports.TilemapCollider=Re,exports.TilemapRenderer=ee,exports.TouchScreen=Ut,exports.Transform=Wt,exports.Vector2=e,exports.VideoRenderer=Xt,exports.between=n,exports.clamp=s,exports.debugRenderLayer=Yt,exports.decorate=function(t,e,i){"number"==typeof i?t(e.prototype,void 0,i):void 0!==i?t(e.prototype,i):t(e)},exports.defaultRenderLayer=Ht,exports.defaultTextureAtlasOptions=Oe,exports.degreesToRadians=a,exports.fixedRound=o,exports.gameLogicSystem=function(){return function(t){zt(t,Nt.GameLogic)}},exports.gamePhysicsSystem=function(){return function(t){zt(t,Nt.GamePhysics)}},exports.gamePreRenderSystem=function(){return function(t){zt(t,Nt.GamePreRender)}},exports.inject=c,exports.injectable=l,exports.playSfx=({audioSource:t,volume:e=1,loop:i=!1})=>{const{element:s}=t;s.volume=e,s.loop=i,s.currentTime=0,s.play().catch((t=>console.warn("playSfx error:",t)))},exports.radiansToDegrees=t=>t*(180/Math.PI),exports.randomFloat=(t,e,i=2)=>o(Math.random()*(e-t)+t,i),exports.randomInt=(t,e)=>Math.round(Math.random()*(e-t))+t,exports.range=r,exports.rgbToHex=({r:t,g:e,b:i},s="#")=>{const o=t=>t.toString(16).padStart(2,"0");return`${s}${o(t)}${o(e)}${o(i)}`},exports.stopSfx=t=>{t.element.pause(),t.element.currentTime=0};
2
2
  //# sourceMappingURL=index.cjs.js.map