!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TileMapHelper={})}(this,(function(t){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}function n(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}var r=function(){function t(t,e,i,n,r){this.tileWidth=t,this.tileHeight=e,this.dimX=i,this.dimY=n,this._tileSet=r,this._layers=[]}return t.prototype.getWidth=function(){return this.tileWidth*this.dimX},t.prototype.getHeight=function(){return this.tileHeight*this.dimY},t.prototype.getTileHeight=function(){return this.tileWidth},t.prototype.getTileWidth=function(){return this.tileHeight},t.prototype.getDimensionX=function(){return this.dimX},t.prototype.getDimensionY=function(){return this.dimY},t.prototype.getTileDefinition=function(t){return this._tileSet.get(t)},t.prototype.getTileDefinitions=function(){return this._tileSet.values()},t.prototype.addTileLayer=function(t){var e=new p(this,t);return this._layers.push(e),e},t.prototype.addObjectLayer=function(t){var e=new o(this,t);return this._layers.push(e),e},t.prototype.getLayers=function(){return this._layers},t.prototype.pointIsInsideTile=function(t,e,i){var r,l,o=Math.floor(t/this.tileWidth),a=Math.floor(e/this.tileHeight);try{for(var s=n(this._layers),p=s.next();!p.done;p=s.next()){var d=p.value;if(d){var u=d.get(o,a);if(void 0===u)return!1;if(this._tileSet.get(u).hasTag(i))return!0}}}catch(t){r={error:t}}finally{try{p&&!p.done&&(l=s.return)&&l.call(s)}finally{if(r)throw r.error}}return!1},t}(),l=function(){function t(t,e){this.visible=!0,this.tileMap=t,this.id=e}return t.prototype.setVisible=function(t){this.visible=t},t.prototype.isVisible=function(){return this.visible},t}(),o=function(t){function e(e,i){var n=t.call(this,e,i)||this;return n.objects=[],n}return i(e,t),e.prototype.add=function(t){this.objects.push(t)},e}(l),a=function(){function t(t,e,i){this.tileId=i,this.x=t,this.y=e}return t.prototype.getTileId=function(){return s.getTileId(this.tileId)},t.prototype.setFlippedHorizontally=function(t){this.tileId=s.setFlippedHorizontally(this.tileId,t)},t.prototype.setFlippedVertically=function(t){this.tileId=s.setFlippedVertically(this.tileId,t)},t.prototype.setFlippedDiagonally=function(t){this.tileId=s.setFlippedDiagonally(this.tileId,t)},t.prototype.isFlippedHorizontally=function(){return s.isFlippedHorizontally(this.tileId)},t.prototype.isFlippedVertically=function(){return s.isFlippedVertically(this.tileId)},t.prototype.isFlippedDiagonally=function(){return s.isFlippedDiagonally(this.tileId)},t}(),s=function(){function t(){}return t.getTileId=function(e){return e&t.tileIdMask},t.setFlippedHorizontally=function(e,i){return e&=~t.flippedHorizontallyFlag,i&&(e|=t.flippedHorizontallyFlag),e},t.setFlippedVertically=function(e,i){return e&=~t.flippedVerticallyFlag,i&&(e|=t.flippedVerticallyFlag),e},t.setFlippedDiagonally=function(e,i){return e&=~t.flippedDiagonallyFlag,i&&(e|=t.flippedDiagonallyFlag),e},t.isFlippedHorizontally=function(e){return 0!=(e&t.flippedHorizontallyFlag)},t.isFlippedVertically=function(e){return 0!=(e&t.flippedVerticallyFlag)},t.isFlippedDiagonally=function(e){return 0!=(e&t.flippedDiagonallyFlag)},t.flippedHorizontallyFlag=2147483648,t.flippedVerticallyFlag=1073741824,t.flippedDiagonallyFlag=536870912,t.tileIdMask=~(t.flippedHorizontallyFlag|t.flippedVerticallyFlag|t.flippedDiagonallyFlag),t}(),p=function(t){function e(e,i){var n=t.call(this,e,i)||this;n._tiles=[],n._tiles.length=n.tileMap.getDimensionY();for(var r=0;r>>0};if("zlib"===n)for(var s=new Uint8Array(o),p=t.inflate(s);r<=p.length;)l.push(a(p,r-4)),r+=4;else{if("zstd"===n)return console.error("Zstandard compression is not supported for layers in a Tilemap. Use instead zlib compression or no compression."),null;for(;r<=o.length;)l.push(a(o,r-4)),r+=4}return l}catch(t){return console.error("Failed to decompress and unzip base64 layer.data string",t),null}},f=function(t){var e=2147483648,i=1073741824,n=536870912,r=t&e,l=t&i,o=t&n;return{id:h(536870911&t),flippedHorizontally:!!r,flippedVertically:!!l,flippedDiagonally:!!o}},h=function(t){return 0===t?void 0:t-1},y=function(){function t(){}return t.load=function(t,e){var i,l,o,s,p,u,y,g,v,x;if(!e.tiledversion)return console.warn("The loaded Tiled map does not contain a 'tiledversion' key. Are you sure this file has been exported from Tiled (mapeditor.org)?"),null;var F=new Map;try{for(var w=n(e.tilesets),T=w.next();!T.done;T=w.next()){var b=T.value,_=void 0===b.firstgid?1:b.firstgid;if(b.tiles)try{for(var m=(o=void 0,n(b.tiles)),M=m.next();!M.done;M=m.next()){var H=M.value,D=new d(H.animation?H.animation.length:0);if(H.objectgroup){var I=function(t){var e=t.class||H.class;if(!e||0===e.length)return"continue";var i=null;if(t.polygon){var n=t.rotation*Math.PI/180,r=Math.cos(n),l=Math.sin(n);-1!==r&&1!==r||(l=0),-1!==l&&1!==l||(r=0),i=t.polygon.map((function(e){return[t.x+e.x*r-e.y*l,t.y+e.x*l+e.y*r]}))}else void 0!==t.x&&void 0!==t.y&&void 0!==t.width&&void 0!==t.height&&(i=[[t.x,t.y],[t.x,t.y+t.height],[t.x+t.width,t.y+t.height],[t.x+t.width,t.y]]);i&&D.add(e,i)};try{for(var V=(p=void 0,n(H.objectgroup.objects)),z=V.next();!z.done;z=V.next()){I(G=z.value)}}catch(t){p={error:t}}finally{try{z&&!z.done&&(u=V.return)&&u.call(V)}finally{if(p)throw p.error}}}else if(H.class&&H.class.length>0){var L=[[0,0],[0,e.tileheight],[e.tilewidth,e.tileheight],[e.tilewidth,0]];D.add(H.class,L)}F.set(h(_+H.id),D)}}catch(t){o={error:t}}finally{try{M&&!M.done&&(s=m.return)&&s.call(m)}finally{if(o)throw o.error}}for(var j=0;j=f+p+r||1!==e.height&&e.height=y+p+l)return console.error("It seems the atlas file was resized, which is not supported. "+"It should be ".concat(f,"x").concat(y," px, ")+"but it's ".concat(e.width,"x").concat(e.height," px.")),null;if(1!==e.width&&e.width!==f||1!==e.height&&e.height!==y)return console.warn("It seems the atlas file has unused pixels. "+"It should be ".concat(f,"x").concat(y," px, ")+"but it's ".concat(e.width,"x").concat(e.height," px.")),null;for(var g=new v,F=0;F0&&j.tileAnimX(b,k.getAnimationLength())}else console.warn("Unknown tile id: ".concat(z," at (").concat(D,", ").concat(H,")"))}}}}catch(t){a={error:t}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(a)throw a.error}}}},t.updatePixiCollisionMask=function(t,e,i,r,l,o,a,s){var d,u,c,f;if(t){t.clear(),t.lineStyle(r,l,o),t.drawRect(0,0,e.getWidth(),e.getHeight());try{for(var h=n(e.getLayers()),y=h.next();!y.done;y=h.next()){var g=y.value,v=e.getTileWidth(),x=e.getTileHeight();if(g instanceof p)for(var F=g,w=0;w