!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e="undefined"!=typeof globalThis?globalThis:e||self)}(this,(function(e){"use strict";e.still="still",e.update="update",e.mesh="mesh",e.customMesh="customMesh",e.canvasShape=mesh,e.sprite="sprite",e.lineRndr="lineRenderer",e.line=lineRndr,e.text="text",e.texture="texture",e.rect="rect",e.circle="circle",e.paths="paths",e.plainText="plainText",e.hitbox="hitbox",e.down="down",e.up="up",e.left="left",e.right="right",e.bottom="bottom",e.drag="drag",e.nill=null,e.yes=!0,e.no=!1,e.Arrow={left:left,up:up,right:right,down:down},e.keys={left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",down:"ArrowDown"},e.defaultFont="30px Arial",e.error={noSupport:"Your browser dose not support canvas"};class t{constructor(e){this.bgColor=e.bgColor,this.canvasId=e.canvasId,this._drawers=this._theDrawers(),this.campos=[0,0],this.lastUpdate=null,this.deltaTime=0,this.noUpdate={}}setUpImageCacher(){let e=document.createElement("div");return e.style.display="none",e.id="caveImageCache"+Math.round(Math.floor(9999*Math.random())+1e3),document.body.append(e),e.id}zeroToCenter(e){let t=document.getElementById(this.canvasId);if(!t.getContext)return[!1,error.noSupport];var s=t.getContext("2d");if(!0===e)s.translate(t.width/2,t.height/2);else{if(!1!==e)return[!1,"no given boolen"];s.translate(0,0)}}draw(e,t,s,i,n,h,o,a,l,c,d){null==this.lastUpdate&&(this.lastUpdate=Date.now());let u=Date.now();this.fps=t,this.scene=e;let p=a()||document.getElementById(this.canvasId);if(!p.getContext)return[!1,error.noSupport];var y=p.getContext("2d",{alpha:!1});l({scene:e,fps:t,antiAliasing:s,campos:i,imgStore:n,shader:h,renderer:o,canvasObj:a});let v=d.event.keyStroke;d.callback({key:v,event:d.event,delta:this.deltaTime,scene:e,onDirection:e=>{let t=r(v);return t.indexOf(left)>-1&&e==left||(t.indexOf(right)>-1&&e==right||(t.indexOf(down)>-1&&e==down||(t.indexOf(up)>-1&&e==up||(t.indexOf("a")>-1&&e==left||(t.indexOf("d")>-1&&e==right||(t.indexOf("s")>-1&&e==down||t.indexOf("w")>-1&&e==up))))))}}),y.font=defaultFont,y.imageSmoothingEnabled=s,y.fillStyle=this.bgColor,y.clearRect(-50,-50,p.width+100,p.height+100),y.fillRect(-50,-50,p.width+100,p.height+100);let m=[i.x,i.y];m[0]==this.campos[0]&&m[1]==this.campos[1]||(y.translate(m[0]-this.campos[0],m[1]-this.campos[1]),this.campos=m),null==h&&null==h||h(y,{fps:this.fps,screen:p,camera:this.campos});for(var f=0;fe.x&&g.x+g.widthe.y&&g.x!=e.x&&(t.collision.push(left),1==t.collideReact&&(t.x-=g.x+g.width-e.x)),g.x>e.x+.75*e.width&&g.x+g.width>e.x+e.width&&g.xe.y&&g.x!=e.x&&(t.collision.push(right),1==t.collideReact&&(t.x+=e.x+e.width-g.x)),g.ye.y&&g.y+g.heighte.x&&g.y!=e.y&&(t.collision.push(up),1==t.collideReact&&(t.y-=g.y+g.height-e.y)),g.y>e.y+.75*e.height&&g.y+g.height>e.y+e.height&&g.ye.x&&g.y!=e.y&&(t.collision.push(down),1==t.collideReact&&(t.y+=e.y+e.height-g.y))}}}if(null!=t.scripts){let e,s=t.scripts;for(var x=0;x=e.length)for(var i=s-e.length+1;i--;)e.push(void 0);return e.splice(s,0,e.splice(t,1)[0]),e}(this.vScene,e,t)}getObj(e){for(var t=0;tnull,this.onBeforeRender=()=>null,this.onAfterRender=()=>null,this.onKeyboardEvent=()=>null,this.imgStore={},this.bgColor=e.bgColor||"#ffffff",this.fps=e.fps||30,this.loop=()=>null,this.renderState=e.renderState||still,this.dynamicCamera=e.dynamicCamera||!1,this.cameraPos=e.camPos||{x:0,y:0},this.shader=null,this.renderState==still?this.updater=!1:this.renderState==update?this.updater=!0:console.error("no proper given renderState.\noptions:( update | still )"),this.scene=e.scene||new s,this.cave=new t({bgColor:this.bgColor,canvasId:this.canvasId}),1==e.disableImageCache||(this.storeId=this.cave.setUpImageCacher())}startRenderCycle(){let e=this.cave;this.onRender(this,this.scene),setInterval((()=>function(e,t,s,i,n,h,r,o,a,l,c,d,u,p,y){if(!0===n){s({fps:h,screen:document.getElementById(l),camera:a});let n=e.draw(i,h,r,a,o,c,d,t,u,p,y);!1===n[0]&&(alert(n[1]),console.alert(n[1]))}}(e,this.canvasObj,this.loop,this.scene,this.updater,this.fps,this.antiAliasing,this.imaStore,this.cameraPos,this.canvasId,this.shader,this,this.onBeforeRender,this.onAfterRender,{callback:this.onKeyboardEvent,event:this.events.keyBoard})),1e3/this.fps)}zeroToCenter(e){this.cave.zeroToCenter(e)}attachCanvas(e){this.canvas=e,this.canvasId=this.canvas.id}addToImgCache(e,t){if(1==e.isImgObj)this.imgStore[t]=e;else{let s=new h(e,t);this.imgStore[t]=s}}setRenderState(e){this.renderState=e||still,this.renderState==still?this.updater=!1:this.renderState==update?this.updater=!0:console.error("no proper given renderState.\noptions:( update | still )")}setSize(e,t){this.canvas.width=e,this.canvas.height=t}setBgColor(e){this.bgColor=e}setScene(e){this.scene=e}draw(e){this.tempScene=e}translateCamera(e){this.cameraPos=e}onLoop(e){this.loop=e}canvasAttactToDom(e,t){"prepend"==t?e.prepend(this.canvas):"append"==t&&e.append(this.canvas),this.canvasObj=()=>document.getElementById(this.canvas.id),document.getElementById(this.canvasId).addEventListener("mouseleave",(e=>{this.events.hoverOver=!0})),document.getElementById(this.canvasId).addEventListener("mousemove",(e=>{this.events.mouse.x=e.offsetX-this.cameraPos.x,this.events.mouse.y=e.offsetY-this.cameraPos.y;for(var t=0;tthis.scene.vScene[t].x-this.scene.vScene[t].width/2&&this.events.mouse.ythis.scene.vScene[t].y-(this.scene.vScene[t].height||this.scene.vScene[t].width/2)?this.scene.vScene[t].events.mouse.hover=!0:this.scene.vScene[t].events.mouse.hover=!1;if(this.events.mouse.primaryBtn==down){this.events.mouse.drag=!0;for(t=0;t{this.mouseDown();for(var t=0;tthis.scene.vScene[t].x-this.scene.vScene[t].width/2&&this.events.mouse.ythis.scene.vScene[t].y-(this.scene.vScene[t].height||this.scene.vScene[t].width/2)&&(this.scene.vScene[t].events.mouse.primaryBtn=down)})),document.getElementById(this.canvasId).addEventListener("mouseup",(e=>{this.mouseUp();for(var t=0;t{let t="";1==e.ctrlKey&&(t+="Ctrl+"),1==e.shiftKey&&(t+="Shift+"),1==e.altKey&&(t+="Shift+"),t+=e.key.replaceAll(keys.left,left).replaceAll(keys.right,right).replaceAll(keys.up,up).replaceAll(keys.down,down),this.events.keyBoard={key:e.key,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,keysDown:down},this.events.keyBoard.keyStroke=t})),document.body.addEventListener("keyup",(e=>{this.events.keyBoard={key:"",ctrlKey:!1,shiftKey:!1,altKey:!1},this.events.keyBoard.keyStroke=""}))}mouseDown(){this.events.mouse.primaryBtn=down}mouseUp(){this.events.mouse.primaryBtn=up}shaderSet(e){this.shader=e}exportSelf(){return this}on(e,t){"render"==e&&(this.onRender=t),"beforeRender"==e&&(this.onBeforeRender=t),"afterRender"==e&&(this.onAfterRender=t),"mouseEvent"==e&&(this.onMouseEvent=t),"keyboardEvent"==e&&(this.onKeyboardEvent=t)}}class n{constructor(e,t,s,i){this.isVectObj=!0,this.x=e||null,this.y=t||null,this.scale=s||null,this.rot=i||null}_giveVector(){return[this.x,this.y,this.scale,this.rot]}}class h{constructor(e,t){this.isImgObj=!0;let s=new Image;s.src=e,this.img=s,this.name=t,this.url=e}}function r(e){return e.split("+")}e.ORBS={setFullScreenGameCss:function(){document.body.setAttribute("style","padding: 0;\n\t\tmargin: 0;\n\t\theight: 100vh")},_:function(){return[new i,new s]},keyEvent:r,renderer:i,scene:s,obj:class{constructor(e){this.name=e.name||Math.round(Math.floor(9999*Math.random())+1e3),this.type=e.type||mesh,this.type==mesh&&(this.drawType=e.drawType),this.drawType=e.drawType||texture,this.type!=line&&this.type!=customMesh||(this.drawType=null),this.scripts=[],this.x=e.x||0,this.y=e.y||0,this.width=e.width||0,this.height=e.height||0,this.color=e.color||"#000",this.scale=e.scale||1,this.rotation=e.rotation||0,this.texture=null,e.vars&&this.vars(e.vars),this.events={mouse:{hover:!1,primaryBtn:up,drag:!1}}}_giveCodec(){return{type:this.type,drawType:this.drawType,x:this.x,y:this.y,width:this.width,height:this.height,color:this.color}}attachScript(e){this.scripts.push(e)}setVars(e,t){this[e]=t}vars(e){for(let t=0;t-1:e==down||e==bottom?this.collision.indexOf(down)>-1:e==left?this.collision.indexOf(left)>-1:e==right?this.collision.indexOf(right)>-1:e?void 0:this.collision.length>0}exportSelf(){return JSON.parse(JSON.stringify(this))}},scriptComponent:class{constructor(e){this.script=e||function(){return null}}attachScript(e){this.script=e}imports(e){this.importScript=e}},Vector:n,Sprite:h,Image:h,Texture:h}}));