"use strict";var p=Object.defineProperty;var x=(f,e,t)=>e in f?p(f,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):f[e]=t;var s=(f,e,t)=>(x(f,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y={Amber:{50:[255,251,235],100:[254,243,199],200:[253,230,138],300:[252,211,77],400:[251,191,36],500:[245,158,11],600:[217,119,6],700:[180,83,9],800:[146,64,14],900:[120,53,15],950:[69,26,3]},Blue:{50:[239,246,255],100:[219,234,254],200:[191,219,254],300:[147,197,253],400:[96,165,250],500:[59,130,246],600:[37,99,235],700:[29,78,216],800:[30,64,175],900:[30,58,138],950:[23,37,84]},Cyan:{50:[236,254,255],100:[207,250,254],200:[165,243,252],300:[103,232,249],400:[34,211,238],500:[6,182,212],600:[8,145,178],700:[14,116,144],800:[21,94,117],900:[22,78,99],950:[8,51,68]},Emerald:{50:[236,253,245],100:[209,250,229],200:[167,243,208],300:[110,231,183],400:[52,211,153],500:[16,185,129],600:[5,150,105],700:[4,120,87],800:[6,95,70],900:[6,78,59],950:[2,44,34]},Fuchsia:{50:[253,244,255],100:[250,232,255],200:[245,208,254],300:[240,171,252],400:[232,121,249],500:[217,70,239],600:[192,38,211],700:[162,28,175],800:[134,25,143],900:[112,26,117],950:[74,4,78]},Gray:{50:[249,250,251],100:[243,244,246],200:[229,231,235],300:[209,213,219],400:[156,163,175],500:[107,114,128],600:[75,85,99],700:[55,65,81],800:[31,41,55],900:[17,24,39],950:[3,7,18]},Green:{50:[240,253,244],100:[220,252,231],200:[187,247,208],300:[134,239,172],400:[74,222,128],500:[34,197,94],600:[22,163,74],700:[21,128,61],800:[22,101,52],900:[20,83,45],950:[5,46,22]},Indigo:{50:[238,242,255],100:[224,231,255],200:[199,210,254],300:[165,180,252],400:[129,140,248],500:[99,102,241],600:[79,70,229],700:[67,56,202],800:[55,48,163],900:[49,46,129],950:[30,27,75]},Lime:{50:[247,254,231],100:[236,252,203],200:[217,249,157],300:[190,242,100],400:[163,230,53],500:[132,204,22],600:[101,163,13],700:[77,124,15],800:[63,98,18],900:[54,83,20],950:[26,46,5]},Neutral:{50:[250,250,250],100:[245,245,245],200:[229,229,229],300:[212,212,212],400:[163,163,163],500:[115,115,115],600:[82,82,82],700:[64,64,64],800:[38,38,38],900:[23,23,23],950:[10,10,10]},Orange:{50:[255,247,237],100:[255,237,213],200:[254,215,170],300:[253,186,116],400:[251,146,60],500:[249,115,22],600:[234,88,12],700:[194,65,12],800:[154,52,18],900:[124,45,18],950:[67,20,7]},Pink:{50:[253,242,248],100:[252,231,243],200:[251,207,232],300:[249,168,212],400:[244,114,182],500:[236,72,153],600:[219,39,119],700:[190,24,93],800:[157,23,77],900:[131,24,67],950:[80,7,36]},Purple:{50:[250,245,255],100:[243,232,255],200:[233,213,255],300:[216,180,254],400:[192,132,252],500:[168,85,247],600:[147,51,234],700:[126,34,206],800:[107,33,168],900:[88,28,135],950:[59,7,100]},Red:{50:[254,242,242],100:[254,226,226],200:[254,202,202],300:[252,165,165],400:[248,113,113],500:[239,68,68],600:[220,38,38],700:[185,28,28],800:[153,27,27],900:[127,29,29],950:[69,10,10]},Rose:{50:[255,241,242],100:[255,228,230],200:[254,205,211],300:[253,164,175],400:[251,113,133],500:[244,63,94],600:[225,29,72],700:[190,18,60],800:[159,18,57],900:[136,19,55],950:[76,5,25]},Sky:{50:[240,249,255],100:[224,242,254],200:[186,230,253],300:[125,211,252],400:[56,189,248],500:[14,165,233],600:[2,132,199],700:[3,105,161],800:[7,89,133],900:[12,74,110],950:[8,47,73]},Slate:{50:[248,250,252],100:[241,245,249],200:[226,232,240],300:[203,213,225],400:[148,163,184],500:[100,116,139],600:[71,85,105],700:[51,65,85],800:[30,41,59],900:[15,23,42],950:[2,6,23]},Stone:{50:[250,250,249],100:[245,245,244],200:[231,229,228],300:[214,211,209],400:[168,162,158],500:[120,113,108],600:[87,83,78],700:[68,64,60],800:[41,37,36],900:[28,25,23],950:[12,10,9]},Teal:{50:[240,253,250],100:[204,251,241],200:[153,246,228],300:[94,234,212],400:[45,212,191],500:[20,184,166],600:[13,148,136],700:[15,118,110],800:[17,94,89],900:[19,78,74],950:[4,47,46]},Violet:{50:[245,243,255],100:[237,233,254],200:[221,214,254],300:[196,181,253],400:[167,139,250],500:[139,92,246],600:[124,58,237],700:[109,40,217],800:[91,33,182],900:[76,29,149],950:[46,16,101]},Yellow:{50:[254,252,232],100:[254,249,195],200:[254,240,138],300:[253,224,71],400:[250,204,21],500:[234,179,8],600:[202,138,4],700:[161,98,7],800:[133,77,14],900:[113,63,18],950:[66,32,6]},Zinc:{50:[250,250,250],100:[244,244,245],200:[228,228,231],300:[212,212,216],400:[161,161,170],500:[113,113,122],600:[82,82,91],700:[63,63,70],800:[39,39,42],900:[24,24,27],950:[9,9,11]}};class d{constructor(e=0,t=0){s(this,"_x");s(this,"_y");this._x=e,this._y=t}get x(){return this._x}get y(){return this._y}getX(){return this._x}getY(){return this._y}setX(e){return this._x=e,this}setY(e){return this._y=e,this}magnitude(){return Math.hypot(this._x,this._y)}direction(){return Math.atan2(this._y,this._x)}angleInRadians(){return Math.atan2(this._y,this._x)}angleInDegrees(){const e=Math.atan2(this._y,this._x);return e<0?360+e*(180/Math.PI):e*(180/Math.PI)}normalize(){return this.div(this.magnitude()),this}normalized(){return this.clone().normalize()}add(e){return this._x+=e.x,this._y+=e.y,this}added(e){return this.clone().add(e)}addX(e){return this._x=this.x+e,this}addedX(e){return this.clone().addX(e)}subX(e){return this._x=this.x-e,this}subtractedX(e){return this.clone().subX(e)}addY(e){return this._y=this.y+e,this}addedY(e){return this.clone().addY(e)}subY(e){return this._y=this.y-e,this}subtractedY(e){return this.clone().subY(e)}sub(e){return this._x-=e.x,this._y-=e.y,this}subtracted(e){return this.clone().sub(e)}mult(e){return this._x*=e,this._y*=e,this}scale(e){return this.mult(e)}scaled(e){return this.clone().scale(e)}div(e){return this._x/=e,this._y/=e,this}divided(e){return this.clone().div(e)}dot(e){return this._x*e.x+this._y*e.y}clone(){return new d(this._x,this._y)}round(){return this._x=Math.round(this._x),this._y=Math.round(this._y),this}rounded(){return this.clone().round()}fix(e){return this._x=parseFloat(this._x.toFixed(e)),this._y=parseFloat(this._y.toFixed(e)),this}fixed(e){return this.clone().fix(e)}isEqual(e){return this._x===e.x&&this._y===e.y}set(e,t){return this._x=e,this._y=t,this}toString(e){return`(${this._x.toFixed(e)},${this._y.toFixed(e)})`}log(){console.log("X -> "+this._x+` Y -> `+this._y)}toPoint(){return{x:this._x,y:this._y}}fromPoint(e){return new d(e.x,e.y)}static fromPoint(e){return new d(e.x,e.y)}}class w{constructor(e){s(this,"draw_mode","off");this.world_math=e}mode(e){this.draw_mode=e}off(){this.draw_mode="off"}screen(){this.draw_mode="screen"}world(){this.draw_mode="world"}cartesian(){this.draw_mode="cartesian"}arc({point:e,radius:t,startAngle:i=0,endAngle:r=Math.PI*2,startAngleForHumans:h,endAngleForHumans:c,lineWidth:m=1,strokeColor:o="white",fillColor:_,clockwise:a=!1,lineDash:l,rotate:u,lineToCenter:g}){const n=this.world_math.getContext();return e=this.getPointByDrawMode(e),t=this.draw_mode==="cartesian"?t*this.world_math.getGridSize():t,i=h?-this.angleInRadians(h):i,r=c?-this.angleInRadians(c):r,g=g??!0,(this.draw_mode==="screen"||u)&&n.save(),this.draw_mode==="screen"&&n.resetTransform(),u&&(n.translate(e.x,e.y),n.rotate(u),n.translate(-e.x,-e.y)),n.beginPath(),l&&n.setLineDash(l),g&&n.lineTo(e.x,e.y),n.arc(e.x,e.y,t,i,r,c?!0:a),n.strokeStyle=o,n.lineWidth=m,g&&n.lineTo(e.x,e.y),n.stroke(),_&&(n.fillStyle=_,n.fill()),l&&n.setLineDash([]),n.closePath(),(this.draw_mode==="screen"||u)&&n.restore(),this}circle({point:e,radius:t,startAngle:i=0,endAngle:r=Math.PI*2,startAngleForHumans:h,endAngleForHumans:c,lineWidth:m=1,strokeColor:o="white",fillColor:_,clockwise:a=!1,lineDash:l,rotate:u,lineToCenter:g}){const n=this.world_math.getContext();return e=this.getPointByDrawMode(e),t=this.draw_mode==="cartesian"?t*this.world_math.getGridSize():t,i=h?-this.angleInRadians(h):i,r=c?-this.angleInRadians(c):r,g=g??!0,(this.draw_mode==="screen"||u)&&n.save(),this.draw_mode==="screen"&&n.resetTransform(),u&&(n.translate(e.x,e.y),n.rotate(u),n.translate(-e.x,-e.y)),n.beginPath(),l&&n.setLineDash(l),g&&n.lineTo(e.x,e.y),n.arc(e.x,e.y,t,i,r,c?!0:a),n.strokeStyle=o,n.lineWidth=m,g&&n.lineTo(e.x,e.y),n.stroke(),_&&(n.fillStyle=_,n.fill()),l&&n.setLineDash([]),n.closePath(),(this.draw_mode==="screen"||u)&&n.restore(),this}capsule({start:e,end:t,radius:i,lineWidth:r=1,strokeColor:h="white",fillColor:c,lineDash:m,rotate:o}){e=this.getPointByDrawMode(e),t=this.getPointByDrawMode(t),i=this.draw_mode==="cartesian"?i*this.world_math.getGridSize():i;const _=new d((Math.min(e.x,t.x)+Math.max(e.x,t.x))/2,(Math.min(e.y,t.y)+Math.max(e.y,t.y))/2),a=Math.atan2(t.y-e.y,t.x-e.x),l=this.world_math.getContext();(this.draw_mode==="screen"||o)&&l.save(),this.draw_mode==="screen"&&l.resetTransform(),o&&(l.translate(_.x,_.y),l.rotate(o),l.translate(-_.x,-_.y)),l.beginPath(),m&&l.setLineDash(m),l.arc(e.x,e.y,i,a+Math.PI/2,a-Math.PI/2),l.arc(t.x,t.y,i,a-Math.PI/2,a+Math.PI/2);const u=Math.cos(a+Math.PI/2),g=Math.sin(a+Math.PI/2),n={x:e.x+u*i,y:e.y+g*i},v={x:t.x+u*i,y:t.y+g*i};return l.moveTo(n.x,n.y),l.lineTo(v.x,v.y),l.strokeStyle=h,l.lineWidth=r,l.stroke(),c&&(l.fillStyle=c,l.fill()),m&&l.setLineDash([]),l.closePath(),(this.draw_mode==="screen"||o)&&l.restore(),this}line({startPoint:e,endPoint:t,lineWidth:i=1,strokeColor:r="white",lineDash:h,rotate:c,rotateInCenter:m}){const o=this.world_math.getContext();if(e=this.getPointByDrawMode(e),t=this.getPointByDrawMode(t),(this.draw_mode==="screen"||c||m)&&o.save(),this.draw_mode==="screen"&&o.resetTransform(),m){const _={x:e.x*.5+t.x*.5,y:e.y*.5+t.y*.5};o.save(),o.translate(_.x,_.y),o.rotate(m),o.translate(-_.x,-_.y)}return c&&!m&&(o.save(),o.rotate(c)),o.beginPath(),h&&o.setLineDash(h),o.lineWidth=i,o.strokeStyle=r,o.moveTo(e.x,e.y),o.lineTo(t.x,t.y),o.stroke(),h&&o.setLineDash([]),o.closePath(),(this.draw_mode==="screen"||c||m)&&o.restore(),this}text({point:e,text:t,textAlign:i="center",strokeWidth:r=1,strokeColor:h,textColor:c="white",textBaseline:m="middle",textSize:o=16,rotate:_}){const a=this.world_math.getContext();return e=this.getPointByDrawMode(e),(this.draw_mode==="screen"||_)&&a.save(),this.draw_mode==="screen"&&a.resetTransform(),_&&(a.translate(e.x,e.y),a.rotate(_),a.translate(-e.x,-e.y)),a.beginPath(),a.fillStyle=c,a.textAlign=i,a.textBaseline=m,a.font="bold "+o+"px arial",h&&(a.strokeStyle=h,a.lineWidth=r,a.strokeText(t,e.x,e.y)),a.fillText(t,e.x,e.y),a.closePath(),(this.draw_mode==="screen"||_)&&a.restore(),this}point({point:e,radius:t,text:i,color:r="white",fillColor:h=this.world_math.getBackgroundColor(),textSize:c=16,borderWidth:m=4,lineDash:o,rotate:_}){const a=this.world_math.getContext();return t=this.draw_mode==="cartesian"?t*this.world_math.getGridSize():t,e=this.getPointByDrawMode(e),(this.draw_mode==="screen"||_)&&a.save(),this.draw_mode==="screen"&&a.resetTransform(),_&&(a.save(),a.translate(e.x,e.y),a.rotate(_),a.translate(-e.x,-e.y)),a.beginPath(),o&&a.setLineDash(o),a.strokeStyle=r,a.fillStyle=h,a.lineWidth=m,a.arc(e.x,e.y,t,0,Math.PI*2),a.fill(),m&&a.stroke(),i&&(a.fillStyle=r,a.textAlign="center",a.textBaseline="middle",a.font="bold "+c+"px arial",a.fillText(i,e.x,e.y)),o&&a.setLineDash([]),a.closePath(),(this.draw_mode==="screen"||_)&&a.restore(),this}rect({point:e,width:t,height:i,lineWidth:r=1,strokeColor:h="white",lineDash:c,fillColor:m,rotate:o,rotateInCenter:_}){const a=this.world_math.getContext();return e=this.getPointByDrawMode(e),t=this.draw_mode==="cartesian"?t*this.world_math.getGridSize():t,i=this.draw_mode==="cartesian"?i*this.world_math.getGridSize():i,(this.draw_mode==="screen"||o||_)&&a.save(),this.draw_mode==="screen"&&a.resetTransform(),_&&(a.save(),a.translate(e.x+t/2,e.y+i/2),a.rotate(_),a.translate(-(e.x+t/2),-(e.y+i/2))),o&&!_&&(a.save(),a.rotate(o)),a.beginPath(),a.rect(e.x,e.y,t,i),c&&a.setLineDash(c),a.lineWidth=r,a.strokeStyle=h,a.stroke(),m&&(a.fillStyle=m,a.fill()),c&&a.setLineDash([]),a.closePath(),(this.draw_mode==="screen"||o||_)&&a.restore(),this}getPointByDrawMode(e){return this.draw_mode==="off"||this.draw_mode==="screen"?e:this.draw_mode==="cartesian"?this.world_math.toCartesian(e):this.draw_mode==="world"?this.world_math.toWorld(e):e}getTailwindColor(e,t="500",i=100){if(i<0||i>100)throw new Error("Opacidade é um valor de porcentagem portando deve estar entre 0% e 100%");i=i/100;const r=y[e][t];return`rgba(${r[0]},${r[1]},${r[2]},${i})`}angleInRadians(e){return e*(Math.PI/180)}angleInRadians360(e){return e*(Math.PI/360)}}class M{constructor(e){s(this,"camera_is_zoomable",!0);s(this,"camera_is_draggable",!0);s(this,"camera_zoom_max",500);s(this,"camera_zoom_min",25);s(this,"camera_zoom_current",100);s(this,"camera_zoom_factor",10);s(this,"camera_is_dragging",!1);s(this,"camera_dragging_point",new d);s(this,"camera_offset",new d);s(this,"camera_screen_origin",new d);s(this,"camera_middle_screen",new d);s(this,"mouse_current_point",new d);s(this,"mouse_current_point_in_world",new d);s(this,"mouse_current_point_in_cartesian_plane",new d);s(this,"mouse_current_point_in_screen",new d);s(this,"mouse_debug_mode","screen");s(this,"world_time_is_paused",!1);s(this,"world_time_scale",4);s(this,"world_last_timestamp",0);s(this,"world_time",0);s(this,"world_time_tolerance",.015);s(this,"world_time_precision_mode",!1);s(this,"world_time_precision_frame",1e3);s(this,"world_time_precision_frame_delay",1e3);s(this,"world_before_tab_is_running",!0);s(this,"canvas_id");s(this,"canvas_element");s(this,"canvas_element_original");s(this,"canvas_context");s(this,"canvas_time",0);s(this,"canvas_is_running",!0);s(this,"canvas_background","#111827");s(this,"canvas_width");s(this,"canvas_height");s(this,"canvas_fps",0);s(this,"canvas_max_fps",null);s(this,"canvas_fps_interval",1);s(this,"canvas_last_frame_time",0);s(this,"canvas_draw_info",!0);s(this,"canvas_paint");s(this,"canvas_fullscreen",!1);s(this,"cartesian_plane_grid_size",32);s(this,"cartesian_plane_negativeX",0);s(this,"cartesian_plane_positiveX",0);s(this,"cartesian_plane_negativeY",0);s(this,"cartesian_plane_positiveY",0);s(this,"cartesian_plane_edgeMaxX",0+this.cartesian_plane_positiveX*this.getGridSize());s(this,"cartesian_plane_edgeMinX",0-this.cartesian_plane_negativeX*this.getGridSize());s(this,"cartesian_plane_edgeMaxY",0+this.cartesian_plane_negativeY*this.getGridSize());s(this,"cartesian_plane_edgeMinY",0-this.cartesian_plane_positiveY*this.getGridSize());s(this,"cartesian_plane_draw_grid",!0);s(this,"cartesian_plane_draw_axis",!0);s(this,"math_world_loop",null);s(this,"on_start",[]);s(this,"on_play",[]);s(this,"on_pause",[]);s(this,"on_reset",[]);s(this,"on_stop",[]);s(this,"on_key_down",[]);s(this,"on_key_up",[]);s(this,"on_left_click",[]);s(this,"on_right_click",[]);s(this,"on_mouse_move",[]);s(this,"on_mouse_down",[]);s(this,"on_mouse_up",[]);s(this,"on_mouse_wheel",[]);s(this,"pressed_keys",[]);s(this,"master_key","Alt");const t=document.querySelector("#"+e);if(!t)throw new Error("Não existe nenhum canvas com o id: "+e);this.canvas_id=e,this.canvas_element=t,this.canvas_element_original=t.cloneNode(!0),this.canvas_context=this.canvas_element.getContext("2d"),this.canvas_width=this.canvas_element.width,this.canvas_height=this.canvas_element.height,this.camera_middle_screen.set(this.canvas_width/2,this.canvas_height/2),this.canvas_element.style.backgroundColor=this.canvas_background,this.moveCameraOffsetToCenter(),this.setCartesianPlaneToFullScreen(),this.canvas_paint=new w(this),this.calculateScreenOrigin(),this.setupEvents()}start(){this.canvasPlay(),this.update(),this.on_start.map(e=>e(this))}play(){this.playWorldTime(),this.on_play.map(e=>e(this)),this.world_before_tab_is_running=!0}pause(){this.pauseWorldTime(),this.on_pause.map(e=>e(this)),this.world_before_tab_is_running=!1}stop(){this.pauseWorldTime(),this.canvasStop(),this.on_stop.map(e=>e(this))}reset(){this.resetWorldTime(),this.on_reset.map(e=>e(this))}loop(e){this.math_world_loop=e}default(){return this.setFullScreen(),this.moveCameraOffsetToCenter(),this.setDebugMouseMode("screen"),this.drawAxis(!0),this.drawGrid(!0),this.drawInformation(!0),this.setGridSize(32),this.setCartesianPlaneToFullScreen(),this.setCameraMinZoom(25),this.setCameraMaxZoom(500),this.setWorldTimeScale(4),this}setMasterKey(e){return this.master_key=e,this}isPaused(){return this.world_time_is_paused}toScreen(e){const t={x:(e.x-this.getCameraOffset().getX())/this.getCameraZoomInDecimal(),y:(e.y-this.getCameraOffset().getY())/this.getCameraZoomInDecimal()};return e instanceof d?d.fromPoint(t):t}toWorld(e){const t={x:e.x,y:-e.y};return e instanceof d?d.fromPoint(t):t}toCartesian(e){const t={x:e.x*this.getGridSize(),y:e.y*-this.getGridSize()};return e instanceof d?d.fromPoint(t):t}isDraggable(e=!0){return this.camera_is_draggable=e,this}isZoomable(e=!0){return this.camera_is_zoomable=e,this}getScreenOrigin(){return this.camera_screen_origin}getCameraOffset(){return this.camera_offset}setCameraOffsetToCenter(){return this.setCameraOffsetTo({x:this.canvas_width/2,y:this.canvas_height/2}),this}moveCameraOffsetToCenter(){return this.setCameraOffsetTo({x:this.canvas_width/2,y:this.canvas_height/2}),this}getCameraZoom(){return this.camera_zoom_current}getCameraMaxZoom(){return this.camera_zoom_max}setCameraMaxZoom(e){if(ethis.camera_zoom_max)throw new Error("O zoom minímo deve ser menor que o zoom máximo");return this.camera_zoom_min=e,this}getCameraZoomFactor(){return this.camera_zoom_factor}getCameraZoomFactorInDecimal(){return this.camera_zoom_current/100}setCameraZoomFactor(e){if(e>100||e<0)throw new Error("O fator de zoom é uma porcentagem e deve ser um número entre 0 e 100");return this.camera_zoom_factor=e,this}setCameraZoomAt(e,t){return this.zoomAt(e,t)}zoom(e){return this.zoomAt(e,this.camera_offset),this}zoomAt(e,t){return this.zoomAtWithDecimal(e/100,t),this}setCameraOffsetTo(e){return this.camera_offset.setX(e.x).setY(e.y),this}moveCameraToCartesianPlane(e){return this.camera_offset.setX(-e.x*this.getGridSize()*this.getCameraZoomInDecimal()+this.getMiddleScreen().getX()),this.camera_offset.setY(e.y*this.getGridSize()*this.getCameraZoomInDecimal()+this.getMiddleScreen().getY()),this}moveCameraToWorld(e){return this.camera_offset.setX(-e.x*this.getCameraZoomInDecimal()+this.getMiddleScreen().getX()),this.camera_offset.setY(e.y*this.getCameraZoomInDecimal()+this.getMiddleScreen().getY()),this}getMiddleScreen(){return this.camera_middle_screen}moveCameraTo(e){return this.setCameraOffsetTo(e),this}getCameraZoomInDecimal(){return this.camera_zoom_current/100}setCameraZoom(e){if(!this.camera_is_dragging){if(ethis.camera_zoom_max)throw new Error(`O zoom deve estar entre o mínimo: ${this.camera_zoom_min}% e o máximo: ${this.camera_zoom_max}%.`);this.camera_zoom_current=e,this.getCameraOffset().setX(this.getCameraOffset().getX()),this.getCameraOffset().setY(this.getCameraOffset().getY())}return this}zoomAtWithDecimal(e,t){if(!this.camera_is_dragging){let i=this.camera_zoom_current*e;i>this.camera_zoom_max&&(e=this.camera_zoom_max/this.camera_zoom_current,i=this.camera_zoom_current*e),i=e&&this.getWorldInMiniTimes()=e&&this.getWorldTimeInTicks()=e&&this.getWorldTime()0)throw new Error("A fração de tempo deve ser um número que seja divisor perfeito de 100");this.world_time_precision_frame=1e3*e}return this}getWorldPrecisionTimeFrameInFraction(){return 1e3/this.world_time_precision_frame}getWorldPrecisionTimeFrameInMiniTime(){return this.world_time_precision_frame}setWorldPrecisionTimeFrameInMiniTimes(e){return this.world_time_precision_frame=e,this}setWorldPrecisionTimeFrameDelay(e){return this.world_time_precision_frame_delay=e*1e3,this}nextWorldTime(){return this.world_time=(Math.floor(this.world_time/1e3)+1)*1e3,this}nextFrameWorldTime(){return this.world_time+=this.world_time_precision_frame,this}backWoldTime(){const e=this.world_time=(Math.ceil(this.world_time/1e3)-1)*1e3;return this.world_time=e>0?e:0,this}backFrameWorldTime(){const e=this.world_time-this.world_time_precision_frame;return this.world_time=e>0?e:0,this}setWorldPrecisionTimeInMinitimes(e){return this.world_time=e,this}setWorldPrecisionTimeInSecondsMinutesAndHours(e,t=0,i=0){let r=0;return r+=e*1e3,r+=t*60*1e3,r+=i*60*60*1e3,this.world_time=r,this}getWorldInMiniTimes(){return this.world_time}getWidth(){return this.canvas_width}setWidth(e){return this.canvas_width=this.canvas_element.width=e,this.camera_middle_screen.set(this.canvas_width/2,this.canvas_height/2),this}getHeight(){return this.canvas_height}setHeight(e){return this.canvas_height=this.canvas_element.height=e,this.camera_middle_screen.set(this.canvas_width/2,this.canvas_height/2),this}getCanvas(){return this.canvas_element}getContext(){return this.canvas_context}getCanvasTime(){return this.canvas_time}getCnvasTimeInTicks(){return this.canvas_time/1e3}getCanvasTimeInHoursMinutesAndSeconds(){const e=Math.floor(this.canvas_time/1e3)%60,t=Math.floor(this.canvas_time/6e4)%60;return`${Math.floor(this.canvas_time/36e5)%24}:${t}:${e}`.replace(/\b\d\b/g,"0$&")}canvasIsRunning(){return this.canvas_is_running}canvasPlay(){return this.canvas_is_running=!0,this}canvasStop(){return this.canvas_is_running=!1,this}getBackgroundColor(){return this.canvas_background}setBackgroundColor(e){return this.canvas_background=this.canvas_element.style.backgroundColor=e,this}getFPS(){return this.canvas_fps}setMaxFPS(e){return this.canvas_max_fps=e,this.canvas_fps_interval=1e3/this.canvas_max_fps,this}drawInformation(e=!0){return this.canvas_draw_info=e,this}setFullScreen(){return this.canvas_element.style.position="fixed",this.canvas_element.style.top="0px",this.canvas_element.style.left="0px",this.canvas_element.style.padding="0px",this.canvas_element.style.margin="0px",this.setWidth(window.innerWidth).setHeight(window.innerHeight),this.calculateScreenOrigin(),this.canvas_fullscreen=!0,this}resetFullScreen(){const e=this.canvas_element.parentNode;if(e){this.canvas_element.remove();const t=this.canvas_element_original.cloneNode(!0);e==null||e.append(t),this.canvas_element=document.getElementById(this.canvas_id),this.canvas_context=this.canvas_element.getContext("2d"),this.canvas_width=this.canvas_element.width,this.canvas_height=this.canvas_element.height,this.camera_middle_screen.set(this.canvas_width/2,this.canvas_height/2),this.canvas_element.style.backgroundColor=this.canvas_background,this.setCartesianPlaneToFullScreen(),this.canvas_paint=new w(this),this.setupEvents()}return this}getGridSize(){return this.cartesian_plane_grid_size}setGridSize(e){return this.cartesian_plane_grid_size=e,this}setNegativeX(e){return this.cartesian_plane_negativeX=Math.round(Math.abs(e)),this.cartesian_plane_edgeMinX=0-this.cartesian_plane_negativeX*this.getGridSize(),this}getNegativeX(){return this.cartesian_plane_negativeX}setPositiveX(e){return this.cartesian_plane_positiveX=Math.round(Math.abs(e)),this.cartesian_plane_edgeMaxX=0+this.cartesian_plane_positiveX*this.getGridSize(),this}getPositiveX(){return this.cartesian_plane_positiveX}setNegativeY(e){return this.cartesian_plane_negativeY=Math.round(Math.abs(e)),this.cartesian_plane_edgeMaxY=0+this.cartesian_plane_negativeY*this.getGridSize(),this}getNegativeY(){return this.cartesian_plane_negativeY}setPositiveY(e){return this.cartesian_plane_positiveY=Math.round(Math.abs(e)),this.cartesian_plane_edgeMinY=0-this.cartesian_plane_positiveY*this.getGridSize(),this}getPositiveY(){return this.cartesian_plane_positiveY}setAxisLimits(e,t,i,r){return this.setNegativeX(e),this.setPositiveX(t),this.setNegativeY(i),this.setPositiveY(r),this}setCartesianPlaneToFullScreen(){let e=Math.floor(this.canvas_width/this.cartesian_plane_grid_size),t=Math.floor(this.canvas_height/this.cartesian_plane_grid_size);return e=e%2===0&&e*this.cartesian_plane_grid_size>=this.canvas_width?e:e+1,t=t%2===0&&t*this.cartesian_plane_grid_size>=this.canvas_height?t:t+1,this.setNegativeX(e/2).setPositiveX(e/2),this.setNegativeY(t/2).setPositiveY(t/2),this}drawGrid(e){return this.cartesian_plane_draw_grid=e,this}drawAxis(e){return this.cartesian_plane_draw_axis=e,this}onStart(...e){return this.on_start.push(...e),this}onPlay(...e){return this.on_play.push(...e),this}onPause(...e){return this.on_pause.push(...e),this}onReset(...e){return this.resetWorldTime(),this.on_reset.push(...e),this}onStop(...e){return this.on_stop.push(...e),this}onKeyUp(e,...t){const i=this.on_key_up.find(r=>r.key===e);return i&&i.callbacks.push(...t),i||this.on_key_up.push({key:e,callbacks:t}),this}onKeyDown(e,...t){const i=this.on_key_down.find(r=>r.key===e);return i&&i.callbacks.push(...t),i||this.on_key_down.push({key:e,callbacks:t}),this}onLeftCLick(...e){return this.on_left_click.push(...e),this}onRightClick(...e){return this.on_right_click.push(...e),this}onMouseMove(...e){return this.on_mouse_move.push(...e),this}onMouseUp(...e){return this.on_mouse_up.push(...e),this}onMouseDown(...e){return this.on_mouse_down.push(...e),this}onMouseWheel(...e){return this.on_mouse_wheel.push(...e),this}getPressedKeys(){return this.pressed_keys}keyIsPressed(e){return!!this.pressed_keys.find(t=>t.key===e||t.code===e)}drawCartesianPlan(){const e=this.cartesian_plane_negativeY+this.cartesian_plane_positiveY,t=this.cartesian_plane_negativeX+this.cartesian_plane_positiveX,i=this.getContext();if(this.cartesian_plane_draw_grid){for(let r=0;r<=e;r++)i.beginPath(),i.lineWidth=1,i.strokeStyle="rgba(255, 255, 255, 0.1)",r==e?(i.moveTo(this.cartesian_plane_edgeMinX,this.cartesian_plane_edgeMinY+this.getGridSize()*r),i.lineTo(this.cartesian_plane_edgeMaxX,this.cartesian_plane_edgeMinY+this.getGridSize()*r)):(i.moveTo(this.cartesian_plane_edgeMinX,this.cartesian_plane_edgeMinY+this.getGridSize()*r+.5),i.lineTo(this.cartesian_plane_edgeMaxX,this.cartesian_plane_edgeMinY+this.getGridSize()*r+.5)),i.stroke();for(let r=0;r<=t;r++)i.beginPath(),i.lineWidth=1,i.strokeStyle="rgba(255, 255, 255, 0.1)",r==t?(i.moveTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r,this.cartesian_plane_edgeMinY),i.lineTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r,this.cartesian_plane_edgeMaxY)):(i.moveTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r+.5,this.cartesian_plane_edgeMinY),i.lineTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r+.5,this.cartesian_plane_edgeMaxY)),i.stroke()}if(this.cartesian_plane_draw_axis){i.beginPath(),i.lineWidth=1,i.strokeStyle="rgba(255, 255, 255, 0.5)",i.moveTo(this.cartesian_plane_edgeMinX,0),i.lineTo(this.cartesian_plane_edgeMaxX,0),i.moveTo(0,this.cartesian_plane_edgeMinY),i.lineTo(0,this.cartesian_plane_edgeMaxY),i.stroke();let r=0;for(let h=-this.cartesian_plane_negativeX;h<=this.cartesian_plane_positiveX;h++)i.beginPath(),i.lineWidth=1,i.strokeStyle="rgba(255, 255, 255, 0.5)",i.moveTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r+.5,0-3),i.lineTo(this.cartesian_plane_edgeMinX+this.getGridSize()*r+.5,0+3),i.stroke(),h!=0&&(i.font="16px Arial",i.fillStyle="rgba(255, 255, 255, 0.5)",i.textAlign="start",i.fillText(h.toString(),this.cartesian_plane_edgeMinX+this.getGridSize()*r-2,0+15)),r++;r=0;for(let h=this.cartesian_plane_positiveY;h>=-this.cartesian_plane_negativeY;h--)i.beginPath(),i.lineWidth=1,i.strokeStyle="rgba(255, 255, 255, 0.5)",i.moveTo(0-3,this.cartesian_plane_edgeMinY+this.getGridSize()*r+.5),i.lineTo(0+3,this.cartesian_plane_edgeMinY+this.getGridSize()*r+.5),i.stroke(),h!=0&&(i.font="16px Arial",i.fillStyle="rgba(255, 255, 255, 0.5)",i.textAlign="start",i.fillText(h.toString(),0+15,this.cartesian_plane_edgeMinY+this.getGridSize()*r+3)),r++}i.save(),i.beginPath(),i.fillStyle="white",i.arc(0,0,5,0,Math.PI*2),i.fill(),i.restore()}drawMouseDebug(){if(this.mouse_debug_mode==="off")return;const e=this.getContext(),t=this.getMousePositionInScreen(),i=this.getMousePositionInWorld(),r=this.getMousePositionInCartesian(),h=this.mouse_debug_mode==="point"?this.getMousePositionInScreen():new d(this.canvas_width-200,this.canvas_height);e.save(),e.resetTransform(),e.beginPath(),e.strokeStyle=this.getBackgroundColor(),e.textAlign="start",e.textBaseline="middle",e.font="bold 16px arial",e.lineWidth=7,e.fillStyle="#5eead4",e.fillText("Screen "+t.toString(1),h.getX(),h.getY()-60),e.fillStyle="#a5b4fc",e.fillText("Cartesian "+r.toString(1),h.getX(),h.getY()-40),e.fillStyle="#f0abfc",e.fillText("World "+i.toString(1),h.getX(),h.getY()-20),e.closePath(),e.restore()}drawInfo(){if(!this.canvas_draw_info)return;const e=this.getContext();e.save(),e.resetTransform(),e.beginPath(),e.strokeStyle=this.getBackgroundColor(),e.textAlign="start",e.textBaseline="middle",e.font="bold 16px arial",e.lineWidth=7,e.fillStyle="white",e.fillText("FPS: "+this.canvas_fps,24,16),e.fillText(`World: ${this.getWorldTimeInHoursMinutesAndSeconds()}`,100,16),e.fillText(`Canvas: ${this.getCanvasTimeInHoursMinutesAndSeconds()}`,230,16),e.fillText(`Zoom: ${this.getCameraZoom().toFixed()}%`,370,16),e.fillStyle=this.canvas_is_running?"green":"red",e.arc(8,14,5,0,Math.PI*2),e.fill(),e.closePath(),e.restore()}keyUpHandler(e){const t=this.pressed_keys.indexOf({key:e.key,code:e.code});t&&this.pressed_keys.splice(t,1);const i=this.on_key_up.find(r=>r.key===e.key||r.key===e.code);i&&i.callbacks.map(r=>r(e))}keyDownHandler(e){if(!e.repeat){this.pressed_keys.push({key:e.key,code:e.code});const t=this.on_key_down.find(i=>i.key===e.key||i.key===e.code);t&&t.callbacks.map(i=>i(e))}}mouseWheelHandler(e){this.camera_is_zoomable&&this.keyIsPressed(this.master_key)?this.adjustZoomAtMousePoint(e):this.on_mouse_wheel.map(t=>t(e))}mouseDownHandler(e){return e.stopImmediatePropagation(),e.preventDefault(),this.camera_is_draggable&&this.keyIsPressed(this.master_key)?(this.camera_is_dragging=!0,this.camera_dragging_point.setX(e.x).setY(e.y)):(e.button==0&&this.on_left_click&&this.on_left_click.map(t=>t(e)),e.button===2&&this.on_right_click&&this.on_right_click.map(t=>t(e)),this.on_mouse_down.map(t=>t(e))),!1}mouseUpHandler(e){this.camera_is_draggable&&this.camera_is_dragging?this.camera_is_dragging=!1:this.on_mouse_up.map(t=>t(e))}mouseMoveHandler(e){this.camera_is_draggable&&this.camera_is_dragging?(this.getCameraOffset().setX(this.getCameraOffset().getX()+e.clientX-this.camera_dragging_point.getX()),this.getCameraOffset().setY(this.getCameraOffset().getY()+e.clientY-this.camera_dragging_point.getY()),this.camera_dragging_point.setX(e.clientX).setY(e.clientY)):this.on_mouse_move.map(t=>t(e))}adjustZoomAtMousePoint(e){e.preventDefault();const t=this.camera_zoom_factor/100+1;-e.deltaY>0?this.zoomAtWithDecimal(t,this.getMousePositionInScreen()):this.zoomAtWithDecimal(1/t,this.getMousePositionInScreen())}calculateScreenOrigin(){const e=this.canvas_element.getBoundingClientRect();this.camera_screen_origin.set(e.left+window.scrollX,e.top+window.scrollY)}setMousePosition(e){this.mouse_current_point.setX(e.x),this.mouse_current_point.setY(e.y),this.mouse_current_point_in_screen.setX(this.mouse_current_point.getX()-this.camera_screen_origin.getX()),this.mouse_current_point_in_screen.setY(this.mouse_current_point.getY()-this.camera_screen_origin.getY()),this.mouse_current_point_in_world.setX((this.mouse_current_point_in_screen.getX()-this.getCameraOffset().getX())/this.getCameraZoomInDecimal()),this.mouse_current_point_in_world.setY(-(this.mouse_current_point_in_screen.getY()-this.getCameraOffset().getY())/this.getCameraZoomInDecimal()),this.mouse_current_point_in_cartesian_plane.setX(this.mouse_current_point_in_world.getX()/this.getGridSize()),this.mouse_current_point_in_cartesian_plane.setY(this.mouse_current_point_in_world.getY()/this.getGridSize())}resizeScreen(){this.canvas_fullscreen&&(this.setWidth(window.innerWidth).setHeight(window.innerHeight),this.calculateScreenOrigin())}hiddenScreen(){document.hidden?(this.pauseWorldTime(),this.pressed_keys=[]):(this.world_before_tab_is_running&&this.playWorldTime(),this.pressed_keys=[])}setupEvents(){this.getCanvas().addEventListener("mousedown",e=>this.mouseDownHandler(e)),this.getCanvas().addEventListener("mousemove",e=>this.mouseMoveHandler(e)),this.getCanvas().addEventListener("mousemove",e=>this.setMousePosition(e)),this.getCanvas().addEventListener("mouseup",e=>this.mouseUpHandler(e)),this.getCanvas().addEventListener("wheel",e=>this.mouseWheelHandler(e)),document.addEventListener("keyup",e=>this.keyUpHandler(e)),document.addEventListener("keydown",e=>this.keyDownHandler(e)),document.addEventListener("visibilitychange",()=>this.hiddenScreen()),window.addEventListener("resize",()=>this.resizeScreen())}update(e=0){this.canvas_time=e;const t=performance.now();if(!this.canvasIsRunning())return;this.world_time_is_paused||(this.world_time_precision_mode?t-this.world_last_timestamp>=this.world_time_precision_frame_delay&&(this.world_time+=this.world_time_precision_frame,this.world_last_timestamp=t):(this.world_time+=(t-this.world_last_timestamp)*this.world_time_scale,this.world_last_timestamp=t));const i=t-this.canvas_last_frame_time;if(i>this.canvas_fps_interval){this.canvas_fps=Math.round(1e3/i),this.canvas_last_frame_time=t;const r=this.getContext();r.resetTransform(),r.clearRect(0,0,this.getWidth(),this.getHeight()),r.translate(this.getCameraOffset().getX(),this.getCameraOffset().getY()),r.setTransform(this.getCameraZoomInDecimal(),0,0,this.getCameraZoomInDecimal(),this.getCameraOffset().getX(),this.getCameraOffset().getY()),this.drawCartesianPlan(),this.math_world_loop&&this.math_world_loop(this),this.drawMouseDebug(),this.drawInfo()}requestAnimationFrame(this.update.bind(this))}}exports.MathWorld=M;exports.Paint=w;exports.Vector2D=d; //# sourceMappingURL=math-world.cjs.map