-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtily.min.js
1 lines (1 loc) · 41 KB
/
tily.min.js
1
!function(){const t={};t.utility={clamp:function(t,i,e){return void 0===i&&(i=0),void 0===e&&(e=1),t<i?i:t>e?e:t},lerp:function(t,i,e){return t*(1-e)+i*e},colour:function(t){return`rgba(${Math.round(t.r)},${Math.round(t.g)},${Math.round(t.b)},${Math.round(100*t.a)/100})`},outline:function(t){const i=t.split(" ");return{width:parseFloat(i[0])||.1,colour:i[1]||"transparent"}},shadow:function(t){const i=t.split(" ");return{blur:parseFloat(i[0]||1),xOffset:parseFloat(i[1]||0),yOffset:parseFloat(i[2]||0),colour:i[3]}},parseColor:function(){const t={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32",transparent:"00000000"},i=(t,i,e)=>t<i?i:t>e?e:t,e=(t,i)=>{var e=Math.pow(10,i||0);return Math.round(t*e)/e},s=t=>i(parseInt(t,16),0,255),n=t=>i(e(parseFloat(t)),0,255),o=t=>i(e(parseFloat(t),2),0,1),a=t=>i(e(parseFloat(t)/100*255),0,255),r=t=>i(parseFloat(t)/360,0,1),l=t=>i(parseFloat(t)/100,0,1);function h(t,i,s,n){var o,a,r,l=function(t,i,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?t+6*(i-t)*e:e<.5?i:e<2/3?t+(i-t)*(2/3-e)*6:t};if(0==i)o=a=r=s;else{var h=s<.5?s*(1+i):s+i-s*i,c=2*s-h;o=l(c,h,t+1/3),a=l(c,h,t),r=l(c,h,t-1/3)}return{r:e(255*o),g:e(255*a),b:e(255*r),a:n}}return function(c){var u,f={r:0,g:0,b:0,a:0},d=null;return"string"==typeof c?(c in t&&(c="#"+t[c]),null!==(d=c.match(/#([a-f0-9])([a-f0-9])([a-f0-9])$/i))?f={r:s(d[1]+d[1]),g:s(d[2]+d[2]),b:s(d[3]+d[3]),a:1}:null!==(d=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))?f={r:s(d[1]),g:s(d[2]),b:s(d[3]),a:1}:null!==(d=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))?f={r:s(d[1]),g:s(d[2]),b:s(d[3]),a:(u=d[4],i(e(parseInt(u,16)/255,2),0,1))}:null!==(d=c.match(/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/))?f={r:n(d[1]),g:n(d[2]),b:n(d[3]),a:1}:null!==(d=c.match(/rgb\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))?f={r:a(d[1]),g:a(d[2]),b:a(d[3]),a:1}:null!==(d=c.match(/rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d?\.?\d*?)?\s*\)/))?f={r:n(d[1]),g:n(d[2]),b:n(d[3]),a:o(d[4])}:null!==(d=c.match(/rgba\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))?f={r:a(d[1]),g:a(d[2]),b:a(d[3]),a:o(d[4])}:null!==(d=c.match(/hsl\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))?f=h(r(d[1]),l(d[2]),l(d[3]),1):null!==(d=c.match(/hsla\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))&&(f=h(r(d[1]),l(d[2]),l(d[3]),o(d[4])))):"object"==typeof c&&(void 0!==c.r&&null!=c.g&&void 0!==c.b?f={r:n(c.r),g:n(c.g),b:n(c.b),a:o(c.a||1)}:void 0!==c.h&&void 0!==c.s&&void 0!==c.l&&(f=h(r(c.h),l(c.s),l(c.l),o(c.a||1)))),f}}()},t.utility.__extends=this&&this.__extends||function(t,i){for(var e in i)i.hasOwnProperty(e)&&(t[e]=i[e]);function s(){this.constructor=t}t.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)},t.utility.vec2=function(t,i){return 1==arguments.length?t instanceof Array&&t.length>1?{x:t[0],y:t[1]}:void 0!==t.x&&void 0!==t.y?{x:t.x,y:t.y}:{x:0,y:0}:{x:t||0,y:i||0}},t.utility.vec2.map=function(i,e){var s=1==arguments.length?[arguments[0]]:Array.apply(null,arguments);return s=Array.prototype.slice.call(s,2),t.utility.vec2(e.apply(this,[i.x].concat(s)),e.apply(this,[i.y].concat(s)))},t.utility.vec2.len=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},t.utility.vec2.rad=function(t){return Math.atan2(t.y,t.x)},t.utility.vec2.dot=function(t,i){return t.x*i.x+t.y*i.y},t.utility.vec2.norm=function(i){var e=t.utility.vec2.len(i);return e?t.utility.vec2.div(i,e):t.utility.vec2()},t.utility.vec2.reflect=function(i,e){return t.utility.vec2.add(i,t.utility.vec2.mul(t.utility.vec2.mul(e,t.utility.vec2.dot(i,e)),-2))},t.utility.vec2.cross=function(t,i){return t.x*i.y-t.y*i.x},t.utility.vec2.rot=function(i,e){var s=Math.sin(e),n=Math.cos(e),o=n*i.x-s*i.y,a=s*i.x+n*i.y;return t.utility.vec2(o,a)},t.utility.vec2.add=function(i,e){return void 0!==e.x&&void 0!==e.y?t.utility.vec2(i.x+e.x,i.y+e.y):t.utility.vec2(i.x+e,i.y+e)},t.utility.vec2.sub=function(i,e){return void 0!==e.x&&void 0!==e.y?t.utility.vec2(i.x-e.x,i.y-e.y):t.utility.vec2(i.x-e,i.y-e)},t.utility.vec2.mul=function(i,e){return void 0!==e.x&&void 0!==e.y?t.utility.vec2(i.x*e.x,i.y*e.y):t.utility.vec2(i.x*e,i.y*e)},t.utility.vec2.div=function(i,e){return void 0!==e.x&&void 0!==e.y?t.utility.vec2(i.x/e.x,i.y/e.y):t.utility.vec2(i.x/e,i.y/e)},t.utility.vec2.eq=function(t,i){return t.x==i.x&&t.y==i.y},t.utility.vec2.fromString=function(i){var e=i.split(",",2);if(2==e.length){var s=parseFloat(e[0]),n=parseFloat(e[1]);return t.utility.vec2(s,n)}return t.utility.vec2(0,0)},t.utility.vec2.toString=function(t,i){return t.x+(void 0!==i?i:",")+t.y},t.Main=function(){"use strict";const i={size:null,handleResize:!0,showFPS:!1,renderLoop:!0,beforeDrawFunction:null,afterDrawFunction:null};function e(t,e){if(window)if(t.getContext){if(this.options={...i,...e||{}},this.canvas=t,this.context=t.getContext("2d"),this.width=0,this.height=0,this.activeBuffer=null,this.bufferTransition=null,this.loop=null,this.lastFrameTime=new Date,this.frameCount=0,this.frameTime=0,this.frameRate=0,!this.options.size||this.options.handleResize){const i=this;function n(){i.canvas.width=i.width=t.clientWidth*window.devicePixelRatio,i.canvas.height=i.height=t.clientHeight*window.devicePixelRatio}window.addEventListener("resize",n,!1),n()}else this.canvas.width=this.width=this.options.size.width,this.canvas.height=this.height=this.options.size.height;this.options.renderLoop&&s(this)}else console.log("Canvas not supported!");else console.log("Couldn't find window. Tily.Main can only be created in the browser!")}function s(t){const i=new Date,e=(i-t.lastFrameTime)/1e3;t.lastFrameTime=i,t.frameTime+=e,t.frameCount++,t.frameTime>1&&(t.frameRate=t.frameCount,t.frameTime=0,t.frameCount=0),t.draw(e),t.loop=window.requestAnimationFrame((function(){s(t)}))}return e.prototype.draw=function(t){this.context.save(),this.context.clearRect(0,0,this.width,this.height),"function"==typeof this.options.beforeDrawFunction&&this.options.beforeDrawFunction.call(this,this.canvas,this.context,this.width,this.height,t);const i=this.width,e=this.height;if(this.bufferTransition){const s=this.bufferTransition.update(t);this.bufferTransition.start&&(this.context.globalAlpha=1-s,this.bufferTransition.start.draw(this.context,t,i,e)),this.bufferTransition.finish&&(this.context.globalAlpha=s,this.bufferTransition.finish.draw(this.context,t,i,e)),this.bufferTransition.finished&&(this.bufferTransition=null)}else this.activeBuffer&&(this.context.globalAlpha=1,this.activeBuffer.draw(this.context,t,i,e));"function"==typeof this.options.afterDrawFunction&&this.options.afterDrawFunction.call(this,this.canvas,this.context,this.width,this.height,t),this.context.restore(),this.options.showFPS&&(this.context.save(),this.context.font="20px monospace",this.context.fillStyle="rgba(0, 0, 0, 0.5)",this.context.fillRect(this.width-90,10,80,30),this.context.fillStyle="white",this.context.textBaseline="top",this.context.textAlign="right",this.context.fillText(this.frameRate,this.width-15,15),this.context.restore())},e.prototype.activateBuffer=function(i,e){const s=new t.BufferTransition(this.activeBuffer,i,e);return this.bufferTransition=s,this.activeBuffer=i,new Promise((function(t,i){s.finishedCallback=t}))},Object.defineProperty(e.prototype,"size",{get:function(){return{width:this.width,height:this.height}}}),e}(),t.Transition=function(){"use strict";const i={time:0,easeFunction:null,finishedCallback:null};function e(e,s,n){n={...i,...n||{}},this.start=e,this.finish=s,this.totalTime=n.time,this.currentTime=0,this.easeFunction=n.easeFunction||t.utility.lerp,this.finishedCallback=n.finishedCallback||function(t,i){},this.finished=!1}return e.prototype.update=function(t){return this.currentTime+=t,this.currentTime<this.totalTime?this.easeFunction(this.start,this.finish,this.amount):(this.finishedCallback&&!this.finished&&this.finishedCallback(this.start,this.finish),this.finished=!0,this.finish)},Object.defineProperty(e.prototype,"amount",{get:function(){return t.utility.clamp(this.currentTime/this.totalTime)}}),e}(),t.BufferTransition=function(i){"use strict";function e(t,e,s){i.call(this,t,e,s)}return t.utility.__extends(e,i),e.prototype.update=function(t){return this.currentTime+=t,this.currentTime<this.totalTime?this.easeFunction(0,1,this.amount):(this.finishedCallback&&!this.finished&&this.finishedCallback(this.start,this.finish),this.finished=!0,1)},e}(t.Transition),t.OffsetTransition=function(i){"use strict";function e(t,e,s){i.call(this,t,e,s)}return t.utility.__extends(e,i),e.prototype.update=function(i){if(this.currentTime+=i,this.currentTime<this.totalTime){const i=this.amount;return t.utility.vec2(this.easeFunction(this.start.x,this.finish.x,i),this.easeFunction(this.start.y,this.finish.y,i))}return this.finishedCallback&&!this.finished&&this.finishedCallback(this.start,this.finish),this.finished=!0,this.finish},e}(t.Transition),t.ScaleTransition=function(i){"use strict";function e(t,e,s){i.call(this,t,e,s)}return t.utility.__extends(e,i),e.prototype.update=function(t){return i.prototype.update.call(this,t)},e}(t.Transition),t.BufferBase=function(){"use strict";const i={lockedAxis:"x",initialOffsetX:0,initialOffsetY:0,initialScale:16,maximumScale:32,minimumScale:4,clampCamera:!1};function e(e){this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"),this.activeTiles=[],this.activeTilesMap={},this.options={...i,...e||{}},this.offset=t.utility.vec2(this.options.initialOffsetX,this.options.initialOffsetY),this.offsetTransition=null,this.scale=this.options.initialScale,this.scaleTransition=null,this.size={width:0,height:0},this.tileSize=0,this.viewSize={width:0,height:0}}function s(t,i,e){return t.x>=i.x&&t.x<=e.x&&t.y>=i.y&&t.y<=e.y}function n(i){return t.utility.vec2.toString(i,"_")}return e.prototype.addActiveTile=function(...t){return this.activeTiles.push(...t),1==t.length?t[0]:t},e.prototype.removeActiveTile=function(t){t.destroyed=!0},e.prototype.removeAllActiveTiles=function(){this.activeTiles=[]},e.prototype.moveOffset=function(i,e,s){s={unit:"",relative:!1,...s};var n=t.utility.vec2(i,e);s&&"px"==s.unit&&(n=t.utility.vec2.div(n,this.tileSize)),this.offsetTransition&&(this.offset=this.offsetTransition.update(0)),s&&!0===s.relative&&(n=t.utility.vec2.add(this.offset,n));const o=new t.OffsetTransition(t.utility.vec2(this.offset),t.utility.vec2(n),s);return this.offsetTransition=o,this.offset=n,new Promise((function(t,i){o.finishedCallback=t}))},Object.defineProperty(e.prototype,"offsetPixels",{get:function(){return t.utility.vec2.mul(this.offset,this.tileSize)}}),e.prototype.zoom=function(i,e){this.scaleTransition&&(this.scale=this.scaleTransition.update(0));const s=new t.ScaleTransition(this.scale,i,e);return this.scaleTransition=s,this.scale=i,new Promise((function(t,i){s.finishedCallback=t}))},e.prototype.getPosition=function(i,e){const s=t.utility.vec2.sub(t.utility.vec2.add(this.offset,.5),t.utility.vec2.div(t.utility.vec2(this.viewSize.width,this.viewSize.height),2));return t.utility.vec2.map(t.utility.vec2.add(s,t.utility.vec2.div(t.utility.vec2(i,e),this.tileSize)),Math.floor)},e.prototype.getTileInfo=function(i,e){const s=t.utility.vec2(i,e);return{position:s,activeTiles:this.activeTilesMap[n(s)]||[]}},e.prototype.updateTransitions=function(t){var i=this.offset;return this.offsetTransition&&(i=this.offsetTransition.update(t),this.offsetTransition.finished&&(this.offsetTransition=null)),this.scaleTransition&&(this.scale=this.scaleTransition.update(t),this.scaleTransition.finished&&(this.scaleTransition=null)),i},e.prototype.updateActiveTilesMap=function(i,e){const o=[];var a=null;this.activeTilesMap={},this.activeTiles=this.activeTiles.filter((t=>!t.destroyed));for(let r=0,l=this.activeTiles.length;r<l;r++)s(t.utility.vec2.add(this.activeTiles[r].position,this.activeTiles[r].offset),i,e)&&o.push(this.activeTiles[r]),a=n(this.activeTiles[r].position),void 0===this.activeTilesMap[a]&&(this.activeTilesMap[a]=[]),this.activeTilesMap[a].push(this.activeTiles[r]);return o.sort(((t,i)=>t.zIndex-i.zIndex)),o},e}(),t.Buffer=function(i){"use strict";function e(t,e,s){i.call(this,s),this.layers=[],this.size.width=t,this.size.height=e}return t.utility.__extends(e,i),e.prototype.addLayer=function(i,e){return(i=i||new t.TileLayer(this)).container=this,void 0===e?this.layers.push(i):-1==e?this.layers.unshift(i):this.layers.splice(e,0,i),i},e.prototype.removeLayer=function(t){return this.layers.length<1?null:void 0===t?this.layers.pop():-1==t?this.layers.shift():this.layers.splice(t,1)[0]},e.prototype.removeAllLayers=function(){this.layers=[]},e.prototype.moveLayer=function(i,e,s){if(this.layers.length<2)return!1;if(i<0||i>=this.layers.length)return!1;const n=this.layers.splice(i,1)[0],o=t.utility.clamp(s?i+e:e,0,this.layers.length);return this.layers.splice(o,0,n),!0},e.prototype.resize=function(t,i){for(let e=this.layers.length;e--;)this.layers[e].resize(t,i);this.size.width=t,this.size.height=i},e.prototype.getTileInfo=function(t,e){const s=i.prototype.getTileInfo.call(this,t,e);return s.layers=this.layers.map((i=>i.getTile(t,e))),s},e.prototype.draw=function(i,e,s,n){this.canvas.width=s,this.canvas.height=n,this.context.save(),this.context.clearRect(0,0,s,n);var o=this.updateTransitions(e),a=this.options.lockedAxis,r=this.options.maximumScale;if(this.options.clampCamera&&(r=Math.min(r,this.size.width,this.size.height),s>n?a="x":n>s&&(a="y")),this.scale=t.utility.clamp(this.scale,Math.max(this.options.minimumScale,1),r),this.tileSize=("y"==a?n:s)/this.scale,this.viewSize.width=s/this.tileSize,this.viewSize.height=n/this.tileSize,this.options.clampCamera){const i=.5*this.viewSize.width-.5,e=.5*this.viewSize.height-.5;this.offset=o=t.utility.vec2(t.utility.clamp(o.x,i,this.size.width-i-1),t.utility.clamp(o.y,e,this.size.height-e-1))}this.context.translate(.5*s-o.x*this.tileSize-.5*this.tileSize,.5*n-o.y*this.tileSize-.5*this.tileSize);const l=t.utility.vec2(.5*this.viewSize.width+1,.5*this.viewSize.height+1),h=t.utility.vec2.map(t.utility.vec2.sub(o,l),Math.floor),c=t.utility.vec2.map(t.utility.vec2.add(o,l),Math.ceil),u=this.updateActiveTilesMap(h,c);var f=0;for(let t=0,i=this.layers.length;t<i;t++)for(this.layers[t].draw(this.context,this.tileSize,h,c);f<u.length&&u[f].zIndex<t+1;)u[f].draw(this.context,e,this.tileSize),f++;for(;f<u.length;)u[f].draw(this.context,e,this.tileSize),f++;this.context.restore(),i.drawImage(this.canvas,0,0)},e.prototype.getData=function(){return{layers:this.layers.map((t=>t.getData())),activeTiles:this.activeTiles.map((t=>t.getData())),options:this.options,size:this.size,offset:this.offset,scale:this.scale}},e.fromData=function(i){const e=new t.Buffer(i.size.width,i.size.height,i.options);return e.size=i.size,e.offset=i.offset,e.scale=i.scale,e.layers=i.layers.map((i=>t.TileLayer.fromData(e,i))),e.activeTiles=i.activeTiles.map((i=>t.ActiveTile.fromData(i))),e},e.prototype.serialize=function(){return JSON.stringify(this.getData())},e.deserialize=function(i){var e=null;try{e=JSON.parse(i)}catch(t){return console.log("Couldn't deserialize data: %O",t),null}return t.Buffer.fromData(e)},e}(t.BufferBase),t.CellBuffer=function(i){"use strict";t.utility.__extends(s,i);const e={cellWidth:16,cellHeight:16,minimumX:null,minimumY:null,maximumX:null,maximumY:null,cellFunction:null};function s(t){i.call(this,t),this.cellCache={},this.options={...e,...this.options,...t||{}}}function n(i){return t.utility.vec2.toString(i,"_")}return s.prototype.getTileInfo=function(e,s){const o=i.prototype.getTileInfo.call(this,e,s),a=t.utility.vec2.map(t.utility.vec2(e/this.options.cellWidth,s/this.options.cellHeight),Math.floor),r=t.utility.vec2(e-a.x*this.options.cellWidth,s-a.y*this.options.cellHeight),l=n(a);var h=[];return this.cellCache[l]&&(h=this.cellCache[l].layers.map((t=>t.getTile(r.x,r.y)))),o.cell=a,o.layers=h,o},s.prototype.draw=function(i,e,s,o){this.canvas.width=s,this.canvas.height=o,this.context.save(),this.context.clearRect(0,0,s,o);const a=this.updateTransitions(e);var r=this.options.lockedAxis,l=this.options.maximumScale;const h={width:1/0,height:1/0};if(this.options.minimumX&&this.options.maximumX&&(h.width=(this.options.maximumX-this.options.minimumX)*this.options.cellWidth),this.options.minimumY&&this.options.maximumY&&(h.height=(this.options.maximumY-this.options.minimumY)*this.options.cellHeight),this.options.clampCamera&&(l=Math.min(l,h.width,h.height),s>o?r="x":o>s&&(r="y")),this.scale=t.utility.clamp(this.scale,Math.max(this.options.minimumScale,1),l),this.tileSize=("y"==r?o:s)/this.scale,this.viewSize.width=s/this.tileSize,this.viewSize.height=o/this.tileSize,this.options.clampCamera){const i=.5*this.viewSize.width-.5,e=.5*this.viewSize.height-.5;isFinite(h.width)&&(this.offset.x=a.x=t.utility.clamp(a.x,i,h.width-i-1)),isFinite(h.height)&&(this.offset.y=a.y=t.utility.clamp(a.y,e,h.height-e-1))}this.context.translate(.5*s-a.x*this.tileSize-.5*this.tileSize,.5*o-a.y*this.tileSize-.5*this.tileSize);const c=t.utility.vec2(.5*this.viewSize.width+1,.5*this.viewSize.height+1),u=t.utility.vec2.map(t.utility.vec2.sub(a,c),Math.floor),f=t.utility.vec2.map(t.utility.vec2.add(a,c),Math.ceil),d=this.updateActiveTilesMap(u,f),p=t.utility.vec2(this.options.cellWidth,this.options.cellHeight),y=t.utility.vec2.map(t.utility.vec2.div(u,p),Math.floor),m=t.utility.vec2.map(t.utility.vec2.div(f,p),Math.ceil),g=this.cellCache,v=function(i,e){return function(s){g[n(t.utility.vec2(i,e))]=s}},w=function(t,i){return function(e){console.log("Couldn't generate cell (%i, %i): %s",t,i,e)}};var b=null;for(let i=y.x;i<m.x;i++)for(let s=y.y;s<m.y;s++)b=n(t.utility.vec2(i,s)),void 0===this.cellCache[b]?(this.cellCache[b]=!0,this.options.cellFunction&&this.options.cellFunction(this,i,s,v(i,s),w(i,s))):!0!==this.cellCache[b]&&this.cellCache[b].draw(this.context,e,i,s,this.tileSize,u,f,d);this.context.restore(),i.drawImage(this.canvas,0,0)},s.prototype.serialize=function(){const t={};for(let i in this.cellCache)this.cellCache.hasOwnProperty(i)&&(t[i]=this.cellCache[i].getData());return JSON.stringify({cellCache:t,activeTiles:this.activeTiles.map((t=>t.getData())),options:this.options,offset:this.offset,scale:this.scale})},s.deserialize=function(i){var e=null;const s={};try{e=JSON.parse(i)}catch(t){return console.log("Couldn't deserialize data: %O",t),null}for(let i in e.cellCache)e.cellCache.hasOwnProperty(i)&&(s[i]=t.Cell.fromData(e.cellCache[i]));const n=new t.CellBuffer(e.options);return n.offset=e.offset,n.scale=e.scale,n.cellCache=s,n.activeTiles=e.activeTiles.map((i=>t.ActiveTile.fromData(i))),n},s}(t.BufferBase),t.Cell=function(){"use strict";function i(t){this.buffer=t,this.layers=[]}return i.prototype.addLayer=function(i,e){return(i=i||new t.TileLayer(this)).container=this,void 0===e?this.layers.push(i):-1==e?this.layers.unshift(i):this.layers.splice(e,0,i),i},i.prototype.removeLayer=function(t){return this.layers.length<1?null:void 0===t?this.layers.pop():-1==t?this.layers.shift():this.layers.splice(t,1)[0]},i.prototype.removeAllLayers=function(){this.layers=[]},i.prototype.moveLayer=function(i,e,s){if(this.layers.length<2)return!1;if(i<0||i>=this.layers.length)return!1;const n=this.layers.splice(i,1)[0],o=t.utility.clamp(s?i+e:e,0,this.layers.length);return this.layers.splice(o,0,n),!0},Object.defineProperty(i.prototype,"size",{get:function(){return{width:this.buffer.options.cellWidth,height:this.buffer.options.cellHeight}}}),i.prototype.draw=function(i,e,s,n,o,a,r,l){i.save();const h=this.size;i.translate(s*o*h.width,n*o*h.height);const c=l.filter((i=>function(t,i,e){return t.x>=i.x&&t.x<=e.x&&t.y>=i.y&&t.y<=e.y}(t.utility.vec2.add(i.position,i.offset),t.utility.vec2(s*h.width,n*h.height),t.utility.vec2((s+1)*h.width,(n+1)*h.height)))),u=t.utility.vec2(s*h.width,n*h.height),f=t.utility.vec2.sub(a,u),d=t.utility.vec2.sub(r,u);var p=0;for(let t=0,s=this.layers.length;t<s;t++)for(this.layers[t].draw(i,o,f,d);p<c.length&&c[p].zIndex<t+1;)c[p].draw(i,e,o),p++;for(;p<c.length;)c[p].draw(i,e,o),p++;i.restore()},i.prototype.getData=function(){return{layers:this.layers.map((t=>t.getData()))}},i.fromData=function(i,e){const s=new t.Cell(i);return s.layers=e.layers.map((i=>t.TileLayer.fromData(s,i))),s},i.prototype.serialize=function(){return JSON.stringify(this.getData())},i.deserialize=function(i,e){var s=null;try{s=JSON.parse(e)}catch(t){return console.log("Couldn't deserialize data: %O",t),null}return t.Cell.fromData(i,s)},i}(),t.TileLayer=function(){"use strict";function i(t){this.container=t,this.font="sans-serif",this.foreground="white",this.background="",this.foregroundMap=null,this.backgroundMap=null,this.opacity=1,this.compositeMode="source-over",this.clip=!1,this.centered=!1,this.tiles=[]}function e(t,i,e){return e*i+t}function s(i,e){return t.utility.vec2(i%e,Math.floor(i/e))}function n(i,s,n,o,a,r){i=i||0,s=s||0,n=n||a,o=o||r,n=Math.max(i,n),o=Math.max(s,o),i=t.utility.clamp(i,0,a),s=t.utility.clamp(s,0,r),n=t.utility.clamp(n,0,a),o=t.utility.clamp(o,0,r);const l=n-i;return{start:e(i,s,a),width:Math.abs(l),height:Math.abs(o-s),gap:a-l}}return i.prototype.getTile=function(t,i){return t>=0&&t<this.container.size.width&&i>=0&&i<this.container.size.height&&this.tiles[e(t,i,this.container.size.width)]||""},i.prototype.getForeground=function(t,i){return null!==this.foregroundMap&&t>=0&&t<this.container.size.width&&i>=0&&i<this.container.size.height&&this.foregroundMap[e(t,i,this.container.size.width)]||this.foreground},i.prototype.getBackground=function(t,i){return null!==this.backgroundMap&&t>=0&&t<this.container.size.width&&i>=0&&i<this.container.size.height&&this.backgroundMap[e(t,i,this.container.size.width)]||this.background},i.prototype.setTile=function(t,i,s,n=null,o=null){return t>=0&&t<this.container.size.width&&i>=0&&i<this.container.size.height&&(this.tiles[e(t,i,this.container.size.width)]=s,null!==n&&(null===this.foregroundMap&&(this.foregroundMap=[]),this.foregroundMap[e(t,i,this.container.size.width)]=n),null!==o&&(null===this.backgroundMap&&(this.backgroundMap=[]),this.backgroundMap[e(t,i,this.container.size.width)]=o),!0)},i.prototype.fill=function(t,i,e,s,o,a=null,r=null){const l=n(i,e,s,o,this.container.size.width,this.container.size.height);for(let i=l.start,e=l.height;e--;i+=l.gap)for(let e=l.width;e--;i++)this.tiles[i]=t,null!==a&&(null===this.foregroundMap&&(this.foregroundMap=[]),this.foregroundMap[i]=a),null!==r&&(null===this.backgroundMap&&(this.backgroundMap=[]),this.backgroundMap[i]=r)},i.prototype.clear=function(t,i,e,s){const o=n(t,i,e,s,this.container.size.width,this.container.size.height);for(let t=o.start,i=o.height;i--;t+=o.gap)for(let i=o.width;i--;t++)this.tiles[t]="",null!==this.foregroundMap&&(this.foregroundMap[t]=null),null!==this.backgroundMap&&(this.backgroundMap[t]=null)},i.prototype.resize=function(t,i){if(t==this.container.size.width&&i==this.container.size.height)return;const s=[],n=[],o=[];for(let a=0;a<t;a++)for(let r=0;r<i;r++){const i=e(a,r,t);s[i]=this.getTile(a,r),n[i]=this.getForeground(a,r),o[i]=this.getBackground(a,r)}this.tiles=s,this.foregroundMap&&(this.foregroundMap=n),this.backgroundMap&&(this.backgroundMap=o)},i.prototype.draw=function(i,e,o,a){if(!this.container||!this.tiles)return;const r=this.container.size.width,l=this.container.size.height,h=n(o.x,o.y,a.x,a.y,r,l);var c=null;if(i.save(),i.font=e+1+"px "+this.font,i.globalAlpha=this.opacity,i.globalCompositeOperation=this.compositeMode,this.background||this.backgroundMap){i.fillStyle=this.background;for(let t=h.start,n=h.height;n--;t+=h.gap)for(let n=h.width;n--;t++)this.tiles[t]&&(c=s(t,r),i.save(),this.backgroundMap&&this.backgroundMap[t]&&(i.fillStyle=this.backgroundMap[t]),i.fillRect(c.x*e-.5,c.y*e-.5,e+1,e+1),i.restore())}let u;!0===this.centered?(u=t.utility.vec2.mul(t.utility.vec2(.5,.5),e),i.textAlign="center",i.textBaseline="middle"):(u=t.utility.vec2.mul(t.utility.vec2(0,0),e),i.textAlign="left",i.textBaseline="top"),i.fillStyle=this.foreground;for(let t=h.start,n=h.height;n--;t+=h.gap)for(let n=h.width;n--;t++)if(this.tiles[t]){c=s(t,r),i.save(),this.foregroundMap&&this.foregroundMap[t]&&(i.fillStyle=this.foregroundMap[t]),this.clip&&(i.rect(c.x*e,c.y*e,e,e),i.clip());for(let s=0,n=this.tiles[t].length;s<n;s++)i.fillText(this.tiles[t][s],c.x*e+u.x,c.y*e+u.y);i.restore()}i.restore()},i.prototype.getData=function(){return{font:this.font,foreground:this.foreground,background:this.background,foregroundMap:this.foregroundMap,backgroundMap:this.backgroundMap,opacity:this.opacity,compositeMode:this.compositeMode,clip:this.clip,centered:this.centered,tiles:this.tiles}},i.fromData=function(i,e){const s=new t.TileLayer(i);return s.font=e.font,s.foreground=e.foreground,s.background=e.background,s.foregroundMap=e.foregroundMap,s.backgroundMap=e.backgroundMap,s.opacity=e.opacity,s.compositeMode=e.compositeMode,s.clip=e.clip,s.centered=e.centered,s.tiles=e.tiles,s},i}(),t.ActiveTileBase=function(){"use strict";function i(){this.layers=[],this.animations=[],this.font=null,this.fontStyle=null,this.fontSize=null,this.foreground=null,this.outline=null,this.shadow=null,this.opacity=null,this.compositeMode="source-over",this.offset=null,this.scale=null,this.rotation=null,this.centered=null}function e(e,s){Object.defineProperty(i.prototype,s,{get:function(){return null!==this[e]?this[e]:this.parent instanceof t.ActiveTile?this.parent[e]:this.parent[s]}})}return e("font","inheritedFont"),e("fontStyle","inheritedFontStyle"),e("fontSize","inheritedFontSize"),e("foreground","inheritedForeground"),e("outline","inheritedOutline"),e("shadow","inheritedShadow"),e("opacity","inheritedOpacity"),e("compositeMode","inheritedCompositeMode"),e("offset","inheritedOffset"),e("scale","inheritedScale"),e("rotation","inheritedRotation"),e("centered","inheritedCentered"),i.prototype.pauseAnimations=function(t=!0){this.animations.forEach((t=>t.pause())),t&&this.layers.forEach((i=>i.pauseAnimations(t)))},i.prototype.runAnimations=function(t=!0){this.animations.forEach((t=>t.run())),t&&this.layers.forEach((i=>i.runAnimations(t)))},i.prototype.resetAnimations=function(t=!0){this.animations.forEach((t=>t.reset())),t&&this.layers.forEach((i=>i.resetAnimations(t)))},i.prototype.stopAnimations=function(t=!0){this.animations=[],t&&this.layers.forEach((t=>{t.animations=[]}))},i.prototype.animateForeground=function(i,e){const s=t.utility.parseColor(this.inheritedForeground),n=t.utility.parseColor(i),o=new t.ForegroundAnimation(this,s,n,e);return this.animations.push(o),new Promise((function(t,i){o.finishedCallback=t}))},i.prototype.animateOutline=function(i,e){const s=this.inheritedOutline,n=i,o=new t.OutlineAnimation(this,s,n,e);return this.animations.push(o),new Promise((function(t,i){o.finishedCallback=t}))},i.prototype.animateShadow=function(i,e){const s=this.inheritedShadow,n=i,o=new t.ShadowAnimation(this,s,n,e);return this.animations.push(o),new Promise((function(t,i){o.finishedCallback=t}))},i.prototype.animateOpacity=function(i,e){const s=this.inheritedOpacity,n=new t.OpacityAnimation(this,s,i,e);return this.animations.push(n),new Promise((function(t,i){n.finishedCallback=t}))},i.prototype.animateScale=function(i,e,s){const n=t.utility.vec2(this.inheritedScale),o=t.utility.vec2(i,e),a=new t.ScaleAnimation(this,n,t.utility.vec2(o),s);return this.animations.push(a),new Promise((function(t,i){a.finishedCallback=t}))},i.prototype.animateOffset=function(i,e,s){const n=t.utility.vec2(this.inheritedOffset);var o=t.utility.vec2(i,e);s&&!0===s.relative&&(o=t.utility.vec2.add(n,o));const a=new t.OffsetAnimation(this,n,t.utility.vec2(o),s);return this.animations.push(a),new Promise((function(t,i){a.finishedCallback=t}))},i.prototype.animateRotation=function(i,e){const s=this.inheritedRotation;e&&!0===e.relative&&(i+=s);const n=new t.RotationAnimation(this,s,i,e);return this.animations.push(n),new Promise((function(t,i){n.finishedCallback=t}))},i.prototype.addLayer=function(t,i){return void 0===i?this.layers.push(t):-1==i?this.layers.unshift(t):this.layers.splice(i,0,t),t},i.prototype.removeLayer=function(t){return this.layers.length<1?null:void 0===t?this.layers.pop():-1==t?this.layers.shift():this.layers.splice(t,1)[0]},i.prototype.removeAllLayers=function(){this.layers=[]},i.prototype.moveLayer=function(i,e,s){if(this.layers.length<2)return!1;if(i<0||i>=this.layers.length)return!1;const n=this.layers.splice(i,1)[0],o=t.utility.clamp(s?i+e:e,0,this.layers.length);return this.layers.splice(o,0,n),!0},i.prototype.draw=function(t){for(let i=0,e=this.animations.length;i<e;i++)this.animations[i].update(t);this.animations=this.animations.filter((t=>!t.finished))},i}(),t.ActiveTile=function(i){"use strict";function e(e,s,n){i.call(this),this.position=t.utility.vec2(e||0,s||0),this.zIndex=n||0,this.clip=!1,this.wrap=!1,this.flip=!1,this.font="sans-serif",this.fontStyle="normal",this.fontSize=null,this.foreground="white",this.outline=null,this.shadow=null,this.opacity=1,this.compositeMode="source-over",this.offset=t.utility.vec2(),this.scale=t.utility.vec2(1,1),this.rotation=0,this.centered=!1,this.destroyed=!1}function s(t,i,e,s){for(let n=0,o=t.length;n<o;n++)t[n].draw(i,e,s)}return t.utility.__extends(e,i),e.prototype.move=function(i,e){const s={up:t.utility.vec2(0,-1),down:t.utility.vec2(0,1),left:t.utility.vec2(-1,0),right:t.utility.vec2(1,0)};this.position=t.utility.vec2.add(this.position,s[i]);const n=new t.OffsetAnimation(this,t.utility.vec2.mul(s[i],-1),t.utility.vec2(),e);return this.animations.push(n),new Promise((function(t,i){n.finishedCallback=t}))},e.prototype.addLayer=function(e,s){return(e=e||new t.ActiveTileLayer(this)).activeTile=this,e.parent=this,i.prototype.addLayer.call(this,e,s)},e.prototype.draw=function(e,n,o){if(!this.layers)return;i.prototype.draw.call(this,n),e.save();const a=this.fontSize||o+1+"px";if(e.font=`${this.fontStyle} ${a} ${this.font}`,e.fillStyle=this.foreground,e.globalAlpha=this.opacity,e.globalCompositeOperation=this.compositeMode,this.outline){const{width:i,colour:s}=t.utility.outline(this.outline);e.lineWidth=Math.floor(i*o),e.strokeStyle=s}if(this.shadow){const{blur:i,xOffset:s,yOffset:n,colour:a}=t.utility.shadow(this.shadow);e.shadowBlur=i*o,e.shadowOffsetX=Math.floor(s*o),e.shadowOffsetY=Math.floor(n*o),e.shadowColor=a}if(e.translate(this.position.x*o-.5,this.position.y*o-.5),this.clip&&(e.rect(0,0,o+1,o+1),e.clip()),e.translate((this.offset.x+.5)*o,(this.offset.y+.5)*o),e.rotate(this.rotation),e.scale(this.scale.x*(this.flip?-1:1),this.scale.y),s(this.layers,e,n,o),this.clip&&this.wrap){const t=o*(this.offset.x>0?-1:1)*(this.flip?-1:1),i=o*(this.offset.y>0?-1:1);0!=this.offset.x&&(e.save(),e.translate(this.offset.x+t,0),s(this.layers,e,n,o),e.restore()),0!=this.offset.y&&(e.save(),e.translate(0,this.offset.y+i,0),s(this.layers,e,n,o),e.restore()),0!=this.offset.x&&0!=this.offset.y&&(e.save(),e.translate(this.offset.x+t,this.offset.y+i),s(this.layers,e,n,o),e.restore())}e.restore()},e.prototype.getData=function(){return{layers:this.layers.map((t=>t.getData())),position:this.position,zIndex:this.zIndex,clip:this.clip,wrap:this.wrap,flip:this.flip,font:this.font,fontStyle:this.fontStyle,fontSize:this.fontSize,foreground:this.foreground,outline:this.outline,shadow:this.shadow,opacity:this.opacity,compositeMode:this.compositeMode,offset:this.offset,scale:this.scale,rotation:this.rotation,centered:this.centered}},e.fromData=function(i){const e=new t.ActiveTile(i.position.x,i.position.y,i.zIndex);return e.layers=i.layers.map((i=>t.ActiveTileLayer.fromData(e,e,i))),e.clip=i.clip,e.wrap=i.wrap,e.flip=i.flip,e.font=i.font,e.fontStyle=i.fontStyle,e.fontSize=i.fontSize,e.foreground=i.foreground,e.outline=i.outline,e.shadow=i.shadow,e.opacity=i.opacity,e.compositeMode=i.compositeMode,e.offset=i.offset,e.scale=i.scale,e.rotation=i.rotation,e.centered=i.centered,e},e}(t.ActiveTileBase),t.ActiveTileLayer=function(i){"use strict";function e(t,e){i.call(this),this.activeTile=t,this.parent=e,this.text=""}return t.utility.__extends(e,i),e.prototype.animateText=function(i,e){const s=new t.TextAnimation(this,this.text,i,e);return this.animations.push(s),new Promise((function(t,i){s.finishedCallback=t}))},e.prototype.addLayer=function(e,s){return(e=e||new t.ActiveTileLayer(this.activeTile)).activeTile=this.activeTile,e.parent=this,i.prototype.addLayer.call(this,e,s)},e.prototype.draw=function(e,s,n){if(!this.parent)return;if(i.prototype.draw.call(this,s),e.save(),null!==this.font||null!==this.fontStyle||null!==this.fontSize){const t=this.font||this.inheritedFont,i=this.fontStyle||this.inheritedFontStyle,s=this.fontSize||this.inheritedFontSize||n+1+"px";e.font=`${i} ${s} ${t}`}if(null!==this.foreground&&(e.fillStyle=this.foreground),null!==this.opacity&&(e.globalAlpha=this.opacity),null!==this.compositeMode&&(e.globalCompositeOperation=this.compositeMode),null!==this.outline){const{width:i,colour:s}=t.utility.outline(this.outline);e.lineWidth=Math.floor(i*n),e.strokeStyle=s}if(null!==this.shadow){const{blur:i,xOffset:s,yOffset:o,colour:a}=t.utility.shadow(this.shadow);e.shadowBlur=i*n,e.shadowOffsetX=Math.floor(s*n),e.shadowOffsetY=Math.floor(o*n),e.shadowColor=a}let o;null!==this.offset&&e.translate(this.offset.x*n,this.offset.y*n),null!==this.rotation&&e.rotate(this.rotation),null!==this.scale&&e.scale(this.scale.x,this.scale.y),!0===this.centered?(o=t.utility.vec2(0,0),e.textAlign="center",e.textBaseline="middle"):(o=t.utility.vec2(.5*-n,.5*-n),e.textAlign="left",e.textBaseline="top"),null!==this.inheritedOutline&&(e.miterLimit=2,e.strokeText(this.text,o.x,o.y)),e.fillText(this.text,o.x,o.y);for(let t=0,i=this.layers.length;t<i;t++)this.layers[t].draw(e,s,n);e.restore()},e.prototype.getData=function(){return{layers:this.layers.map((t=>t.getData())),text:this.text,font:this.font,fontStyle:this.fontStyle,fontSize:this.fontSize,foreground:this.foreground,outline:this.outline,shadow:this.shadow,opacity:this.opacity,compositeMode:this.compositeMode,offset:this.offset,scale:this.scale,rotation:this.rotation,centered:this.centered}},e.fromData=function(i,e,s){const n=new t.ActiveTileLayer(i,e);return n.layers=s.layers.map((e=>t.ActiveTileLayer.fromData(i,n,e))),n.text=s.text,n.font=s.font,n.fontStyle=s.fontStyle,n.fontSize=s.fontSize,n.foreground=s.foreground,n.outline=s.outline,n.shadow=s.shadow,n.opacity=s.opacity,n.compositeMode=s.compositeMode,n.offset=s.offset,n.scale=s.scale,n.rotation=s.rotation,n.centered=s.centered,n},e}(t.ActiveTileBase),t.Animation=function(i){"use strict";t.utility.__extends(s,i);const e={repeat:!1,reverse:!1,alternate:!1,repeatCallback:null};function s(t,s,n,o){o={...e,...o||{}},i.call(this,s,n,o),this.activeTile=t,this.repeat=!!o.repeat,this.reverse=!!o.reverse,this.alternate=!!o.alternate,this.repeatCallback=o.repeatCallback,this.running=!0}return s.prototype.pause=function(){this.running=!1},s.prototype.run=function(){this.running=!0},s.prototype.reset=function(){this.currentTime=0},s.prototype.update=function(t){return this.running&&(this.currentTime+=t),this.currentTime<this.totalTime?this.reverse?1-this.amount:this.amount:(this.repeatCallback&&this.repeatCallback(),this.repeat?(this.alternate&&(this.reverse=!this.reverse),this.currentTime=0,this.reverse?1:0):(this.finishedCallback&&!this.finished&&this.finishedCallback(this.start,this.finish),this.finished=!0,1))},s}(t.Transition),t.OffsetAnimation=function(i){"use strict";function e(e,s,n,o){o.easeFunction||(o.easeFunction=(i,e,s)=>t.utility.vec2(t.utility.lerp(i.x,e.x,s),t.utility.lerp(i.y,e.y,s))),i.call(this,e,s,n,o)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.offset=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),t.ScaleAnimation=function(i){"use strict";function e(e,s,n,o){o.easeFunction||(o.easeFunction=(i,e,s)=>t.utility.vec2(t.utility.lerp(i.x,e.x,s),t.utility.lerp(i.y,e.y,s))),i.call(this,e,s,n,o)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.scale=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),t.ForegroundAnimation=function(i){"use strict";function e(e,s,n,o){o.easeFunction||(o.easeFunction=(i,e,s)=>({r:t.utility.lerp(i.r,e.r,s),g:t.utility.lerp(i.g,e.g,s),b:t.utility.lerp(i.b,e.b,s),a:t.utility.lerp(i.a,e.a,s)})),i.call(this,e,s,n,o)}return t.utility.__extends(e,i),e.prototype.update=function(e){const s=i.prototype.update.call(this,e);this.activeTile.foreground=t.utility.colour(this.easeFunction(this.start,this.finish,s))},e}(t.Animation),t.OpacityAnimation=function(i){"use strict";function e(t,e,s,n){i.call(this,t,e,s,n)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.opacity=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),t.RotationAnimation=function(i){"use strict";function e(t,e,s,n){if(this.direction=n.direction,"cw"==this.direction)for(;e>=s;)s+=2*Math.PI;else if("ccw"==this.direction)for(;e<=s;)e+=2*Math.PI;else{const t=(t,i)=>t-Math.floor(t/i)*i,i=2*Math.PI;var o=s-e;o=t(o+Math.PI,i)-Math.PI,s=(e=t(e,i))+o}i.call(this,t,e,s,n)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.rotation=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),t.TextAnimation=function(i){"use strict";function e(t,e,s,n){i.call(this,t,e,s,n),this.finishType=typeof s}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);var s=this.start;s="function"==this.finishType?this.finish(this.start,e):this.finish[Math.max(0,Math.ceil(e*this.finish.length)-1)],this.activeTile.text=s},e}(t.Animation),t.OutlineAnimation=function(i){"use strict";function e(e,s,n,o){o.easeFunction||(o.easeFunction=(i,e,s)=>{const n=t.utility.outline(i),o=t.utility.outline(e);n.colour=t.utility.parseColor(n.colour),o.colour=t.utility.parseColor(o.colour);return`${t.utility.lerp(n.width,o.width,s)} ${t.utility.colour({r:t.utility.lerp(n.colour.r,o.colour.r,s),g:t.utility.lerp(n.colour.g,o.colour.g,s),b:t.utility.lerp(n.colour.b,o.colour.b,s),a:t.utility.lerp(n.colour.a,o.colour.a,s)})}`}),i.call(this,e,s,n,o)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.outline=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),t.ShadowAnimation=function(i){"use strict";function e(e,s,n,o){o.easeFunction||(o.easeFunction=(i,e,s)=>{const n=t.utility.shadow(i),o=t.utility.shadow(e);n.colour=t.utility.parseColor(n.colour),o.colour=t.utility.parseColor(o.colour);return`${t.utility.lerp(n.blur,o.blur,s)} ${t.utility.lerp(n.xOffset,o.xOffset,s)} ${t.utility.lerp(n.yOffset,o.yOffset,s)} ${t.utility.colour({r:t.utility.lerp(n.colour.r,o.colour.r,s),g:t.utility.lerp(n.colour.g,o.colour.g,s),b:t.utility.lerp(n.colour.b,o.colour.b,s),a:t.utility.lerp(n.colour.a,o.colour.a,s)})}`}),i.call(this,e,s,n,o)}return t.utility.__extends(e,i),e.prototype.update=function(t){const e=i.prototype.update.call(this,t);this.activeTile.shadow=this.easeFunction(this.start,this.finish,e)},e}(t.Animation),"undefined"!=typeof module&&(module.exports=t),"undefined"!=typeof window&&(window.Tily=t)}();