UNPKG

imgtotext

Version:

ImgToText is a concise library that converts any image/video into customizable text!

2 lines 210 kB
// ImgToText UMD - v1.2.3 (function(factory){if(typeof define==="function"&&define.amd)define([],factory);else if(typeof module==="object"&&module.exports)module.exports=factory();else if(typeof window!=="undefined"){const{CDE,ImgToText}=factory();window.CDE=CDE;window.ImgToText=ImgToText}else{const{CDE,ImgToText}=factory();this.CDE=CDE;this.ImgToText=ImgToText}})(function(){"use strict";class CDEUtils{static DEFAULT_ACCEPTABLE_DIFFERENCE=1e-7;static CIRC=2*Math.PI;static TO_DEGREES=Math.PI/180;static getLast(arr,index=0){return arr[arr.length-1-index]}static addAt(arr,el,index=0){return arr.slice(0,index).concat(el,arr.slice(index))}static random(min,max,decimals=0){if(decimals){const precision=decimals**10;return Math.round((Math.random()*(max-min)+min)*precision)/precision}return Math.random()*(max-min)+min|0}static clamp(num,min=1/0,max=1/0){return num<min?min:num>max?max:num}static isDefined(value){return null!=value}static isFunction(value){return"function"==typeof value}static round(num,decimals=0){const precision=10**decimals;return Math.round(num*precision)/precision}static unlinkArr2(arr){return[arr[0],arr[1]]}static unlinkArr3(arr){return[arr[0],arr[1],arr[2]]}static unlinkPositions(arr){const isArray=Array.isArray,unlinkArr2=CDEUtils.unlinkArr2,o1=arr?.[0],o2=arr?.[1];return isArray(arr)?[isArray(o1)?unlinkArr2(o1):o1,isArray(o2)?unlinkArr2(o2):o2]:arr}static rotatePos(pos=[0,0],deg=0,centerPos=[0,0]){const rad=CDEUtils.toRad(deg),cos=Math.cos(rad),sin=Math.sin(rad),sx=pos[0]-centerPos[0],sy=pos[1]-centerPos[1];return[sx*cos-sy*sin+centerPos[0],sx*sin+sy*cos+centerPos[1]]}static scalePos(pos=[0,0],scale=[1,1],centerPos=[0,0]){const sx=pos[0]-centerPos[0],sy=pos[1]-centerPos[1];return[sx*scale[0]+centerPos[0],sy*scale[1]+centerPos[1]]}static getPositionsCenter(positions){return[(positions[0][0]+positions[1][0])/2,(positions[0][1]+positions[1][1])/2]}static getDist(x1,y1,x2,y2){return Math.sqrt((x1-x2)**2+(y1-y2)**2)}static getLinearFn(pos1,pos2){const a=(pos2[1]-pos1[1])/(pos2[0]-pos1[0]),b=-a*pos1[0]+pos1[1];return[a,b,x=>a*x+b,pos1]}static getPerpendicularLinearFn(linearFnResult){const a=-1/linearFnResult[0],pos=linearFnResult[3],b=-a*pos[0]+pos[1];return[a,b,x=>a*x+b,pos]}static getValueFromRange(minMax){return Array.isArray(minMax)?CDEUtils.random(minMax[0],minMax[1]):minMax}static arrayEquals(arr1,arr2){return arr1.length===arr2.length&&arr1.every(((v,i)=>v==arr2[i]))}static addPos(pos1,pos2){return[pos1[0]+pos2[0],pos1[1]+pos2[1]]}static subPos(pos1,pos2){return[pos1[0]-pos2[0],pos1[1]-pos2[1]]}static mulPos(pos1,pos2){return[pos1[0]*pos2[0],pos1[1]*pos2[1]]}static divPos(pos1,pos2){return[pos1[0]/pos2[0],pos1[1]/pos2[1]]}static posEquals(arr1,arr2){return arr2&&arr1&&arr1[0]==arr2[0]&&arr1[1]==arr2[1]}static positionsEquals(positions1,positions2){return positions1&&positions2&&positions1[0][0]==positions2[0][0]&&positions1[0][1]==positions2[0][1]&&positions1[1][0]==positions2[1][0]&&positions1[1][1]==positions2[1][1]}static mod(max,ratio,range=max){return max-ratio*range-(range<0)*max}static toRad(deg){return deg*CDEUtils.TO_DEGREES}static toDeg(rad){return rad/CDEUtils.TO_DEGREES}static getAcceptableDiff(num,acceptableDiff=CDEUtils.DEFAULT_ACCEPTABLE_DIFFERENCE){const rounded=Math.round(num);return rounded-num<=acceptableDiff?rounded:num}static getMinMax(arr,propPath=null){let min=1/0,max=-1/0,ll=arr.length;for(let i=0;i<ll;i++){const v=propPath?+arr[i][propPath]:arr[i];v<min&&(min=v),v>max&&(max=v)}return[min,max]}static repeatedTimeout(iterationCount,callback,delay=5){let at=0;for(let i=0;i<iterationCount;i++)setTimeout((()=>callback(i)),at+=delay)}static stackTraceLog(...logs){try{throw new Error("stackTraceLog")}catch(e){console.log(e,...logs)}}}class FPSCounter{constructor(avgSampleSize){this._avgSampleSize=avgSampleSize||10,this._times=[],this._avg=[],this._maxFps=0}getFpsRaw(){let fps,now=performance.now();for(;this._times.length&&this._times[0]<=now-1e3;)this._times.shift();return fps=this._times.push(now),this._maxFps<fps&&(this._maxFps=fps),fps}getFps(){return this._avg.push(this.getFpsRaw()),this._avg.length>this._avgSampleSize&&this._avg.shift(),Math.floor(Math.min(this._avg.reduce(((a,b)=>a+b),0)/this._avgSampleSize,this._maxFps))}get maxFps(){return this._maxFps-1}get avgSample(){return this._avgSampleSize}get fpsRaw(){return this._times.length}set avgSample(s){this._avgSampleSize=s}}class CanvasUtils{static SHOW_CENTERS_DOT_ID={};static toggleCenter(canvas,shape,radius=5,color=[255,0,0,1]){if(CanvasUtils.SHOW_CENTERS_DOT_ID[shape.id])canvas.remove(CanvasUtils.SHOW_CENTERS_DOT_ID[shape.id]),delete CanvasUtils.SHOW_CENTERS_DOT_ID[shape.id];else{const dot=new Dot([0,0],radius,color,null,shape);CanvasUtils.SHOW_CENTERS_DOT_ID[shape.id]=dot.id,canvas.add(dot)}}static showIntersectionPoints(canvas,res){const s_d1=new Dot(res.source.inner,3,[255,0,0,1]),s_d2=new Dot(res.source.outer,3,[255,0,0,.45]),t_d1=new Dot(res.target.outer,3,[255,0,0,.45]),t_d2=new Dot(res.target.inner,3,[255,0,0,1]);canvas.add(s_d1),canvas.add(s_d2),canvas.add(t_d1),canvas.add(t_d2)}static firstDotOnly(dot){return dot.id==dot.parent.firstDot.id}static drawOuterRing(dot,renderStyles,radiusMultiplier=1,forceBatching=!1){const color=renderStyles.colorObject??renderStyles,opacityThreshold=Color.OPACITY_VISIBILITY_THRESHOLD,filter=renderStyles._filter;color[3]<opacityThreshold||color.a<opacityThreshold||(filter&&-1!==filter.indexOf("#")&&!forceBatching?dot.render.stroke(Render.getArc(dot.pos,(dot.radius||1)*radiusMultiplier),renderStyles):dot.render.batchStroke(Render.getArc(dot.pos,(dot.radius||1)*radiusMultiplier),renderStyles))}static drawLine(dot,target,renderStyles,radiusPaddingMultiplier=0,lineType=Render.getLine,spread,forceBatching){const color=renderStyles.colorObject??renderStyles,opacityThreshold=Color.OPACITY_VISIBILITY_THRESHOLD,filter=renderStyles._filter;if(!(color[3]<opacityThreshold||color.a<opacityThreshold))if(radiusPaddingMultiplier){const res=dot.getLinearIntersectPoints(target,(target.radius??_Obj.DEFAULT_RADIUS)*radiusPaddingMultiplier,dot,dot.radius*radiusPaddingMultiplier);filter&&-1!==filter.indexOf("#")&&!forceBatching?dot.render.stroke(lineType(res[0][0],res[1][0],spread),renderStyles):dot.render.batchStroke(lineType(res[0][0],res[1][0],spread),renderStyles)}else filter&&-1!==filter.indexOf("#")&&!forceBatching?dot.render.stroke(lineType(dot.pos,target.pos??target,spread),renderStyles):dot.render.batchStroke(lineType(dot.pos,target.pos??target,spread),renderStyles)}static drawDotConnections(dot,renderStyles,radiusPaddingMultiplier=0,lineType=Render.getLine,spread,forceBatching){const render=dot.render,dotPos=dot.pos,dotConnections=dot.connections,dc_ll=dot.connections.length,color=renderStyles.colorObject??renderStyles,opacityThreshold=Color.OPACITY_VISIBILITY_THRESHOLD,filter=renderStyles._filter,hasURLFilter=filter&&-1!==filter.indexOf("#");if(lineType||(lineType=Render.getLine),dc_ll){if(color[3]<opacityThreshold||color.a<opacityThreshold)return;if(radiusPaddingMultiplier){const dotRadiusPadding=dot.radius*radiusPaddingMultiplier;for(let i=0;i<dc_ll;i++){const c=dotConnections[i],res=dot.getLinearIntersectPoints(c,c.radius*radiusPaddingMultiplier,dot,dotRadiusPadding);hasURLFilter&&!forceBatching?render.stroke(lineType(res[0][0],res[1][0],spread),renderStyles):render.batchStroke(lineType(res[0][0],res[1][0],spread),renderStyles)}}else for(let i=0;i<dc_ll;i++)hasURLFilter&&!forceBatching?render.stroke(lineType(dotPos,dotConnections[i].pos,spread),renderStyles):render.batchStroke(lineType(dotPos,dotConnections[i].pos,spread),renderStyles)}}static getDraggableDotCB(){let mouseup=!1,dragAnim=null;return(dot,mouse,dist,ratio,pickableRadius=50)=>{mouse.clicked&&dist<pickableRadius?(mouseup=!0,dot?.currentBacklogAnim?.id==dragAnim?.id&&dragAnim&&dragAnim.end(),dot.x=mouse.x,dot.y=mouse.y):mouseup&&(mouseup=!1,dragAnim=dot.addForce(Math.min(CDEUtils.mod(Math.min(mouse.speed,3e3),ratio)/4,300),mouse.dir,750+1200*ratio,Anim.easeOutQuad))}}static getTrailEffectCB(canvas,dot,length=8,moveEffectCB=null,disableDefaultMovements=!1){let trail=[],trailPos=new Array(length).fill(dot.pos),lastPos=null,equals=CDEUtils.posEquals,isDefaultMovements=!disableDefaultMovements;for(let i=0;i<length;i++){const trailObj=dot.duplicate();trail.push(trailObj),canvas.add(trailObj)}return mouse=>{let pos=CDEUtils.unlinkArr2(dot.pos),isMoving=!1;if(!equals(lastPos,pos)){if(trailPos.shift(),trailPos.push(pos),isDefaultMovements)for(let i=0;i<length;i++)trail[i].moveAt(trailPos[i]);lastPos=pos,isMoving=!0}if(moveEffectCB)for(let i=0;i<length;i++)moveEffectCB(trail[i],(i+1)/length,isMoving,mouse,trailPos[i],i)}}static rotateGradient(obj,duration=1e3,speed=1,isFillColor=!1){return obj.playAnim(new Anim((prog=>obj[isFillColor?"fillColorRaw":"colorRaw"].rotation=360*-speed*prog),duration))}static lookAt(obj,target,offset=0){const t=target?.pos??target;obj.rotation=offset-CDEUtils.toDeg(Math.atan2(obj.pos[1]-t[1],-(obj.pos[0]-t[0])))}static drawOutline(render,obj,color=[255,0,0,1]){const bounds=obj.getBounds();render.batchStroke(Render.getPositionsRect(bounds[0],bounds[1]),color?.color||color)}static drawOutlineAccurate(render,obj,color=[0,50,255,1]){render.batchStroke(obj.getBoundsAccurate(),color?.color||color)}static drawPos(render,pos,color=[255,0,0,1],radius){render.batchStroke(Render.getArc(pos,radius),color?.color||color)}static SHAPES={DEBUG_SHAPE:(pos,dots)=>new Shape(pos||[100,100],dots||[new Dot,new Dot([100]),new Dot([,100]),new Dot([100,100])]),THROWABLE_DOT:(pos,radius,color)=>{const dragAnim=CanvasUtils.getDraggableDotCB();return new Shape(pos||[10,10],new Dot,radius,color,null,((render,dot,ratio,res,m,dist,shape)=>dragAnim(shape.firstDot,m,dist,ratio)))}};static createDrawingBoard(CVS,borderPositions=[[0,0],CVS.size],renderStyles=[255,0,0,1],newLineMoveThreshold=Math.min(1,(CVS.fpsLimit||60)/15),borderColor=Color.DEFAULT_RGBA){let d_ll=0,render=CVS.render,cvsStatic=Canvas.STATIC,thresholdAt=0,obj=new Shape(null,[new Dot(borderPositions[0]),new Dot(borderPositions[1])],0,null,0,null,null,(()=>[]),(()=>{for(let i=0;i<d_ll;i++)render.batchStroke(obj.setupResults[i],renderStyles);borderColor&&(borderColor.a||borderColor[3])&&CanvasUtils.drawOutline(render,obj,borderColor)}),null,!0);CVS.add(obj);const clickListenerId=CVS.mouse.addListener(obj,Mouse.LISTENER_TYPES.DOWN,(pos=>{const path=new Path2D,x=pos[0],y=pos[1];path.moveTo(x,y),path.arc(x,y,(renderStyles.lineWidth||render.defaultProfile.lineWidth)/4,0,CDEUtils.CIRC),d_ll=obj.setupResults.push(path)})),enterListenerId=CVS.mouse.addListener(obj,Mouse.LISTENER_TYPES.ENTER,((pos,_,mouse)=>{if(mouse.clicked){const path=new Path2D,x=pos[0],y=pos[1];path.moveTo(x,y),d_ll=obj.setupResults.push(path)}})),moveListenerId=CVS.mouse.addListener(obj,Mouse.LISTENER_TYPES.MOVE,((pos,_,mouse)=>{if(++thresholdAt==newLineMoveThreshold){const lastPos=mouse.lastPos,path=obj.setupResults[d_ll-1];if(path&&mouse.clicked&&obj.isWithin(lastPos)&&(path.lineTo(pos[0],pos[1],lastPos[0],lastPos[1]),CVS.fpsLimit==cvsStatic))for(let i=0;i<d_ll;i++)render.stroke(obj.setupResults[i],renderStyles);thresholdAt=0}}));return{obj:obj,mouseListeners:{click:clickListenerId,enter:enterListenerId,move:moveListenerId}}}static createEmptyObj(CVS,setupCB,loopCB){const obj=new Shape(null,null,0,null,0,null,void 0,setupCB,loopCB,null,!0);return CVS.add(obj),obj}static FOLLOW_PATHS={INFINITY_SIGN:(width,height,progressOffset)=>(width??=100,height??=50,progressOffset??=0,[[0,prog=>{const progress=CDEUtils.CIRC*((prog+progressOffset)%1);return[width*Math.sin(progress),height*Math.sin(2*progress)]}]]),CIRCLE:(width,height,progressOffset)=>(width??=100,height??=100,progressOffset??=0,[[0,prog=>{const progress=CDEUtils.CIRC*((prog+progressOffset)%1);return[width*Math.cos(progress),height*Math.sin(progress)]}]]),RECTANGLE:(width,height,progressOffset)=>(width??=100,height??=100,progressOffset??=0,[[0,prog=>{const pos=(prog+progressOffset)%1*2*(width+height);return pos<width?[pos,0]:pos<width+height?[width,pos-width]:pos<2*width+height?[width-(pos-(width+height)),height]:[0,height-(pos-(2*width+height))]}]]),QUADRATIC:(width,height,isFliped)=>{width??=100,height??=200;const maxNaturalHeight=Math.pow(width/2,2);return[[0,prog=>{let x=(prog-.5)*width,y=height*(Math.pow(x,2)/maxNaturalHeight);return isFliped&&(y=height-y),[x,y]}]]},LINEAR:(width,a)=>(width??=100,a??=1,[[0,prog=>{const x=prog*width;return[x,a*x]}]]),SINE_WAVE:(width,height)=>(width??=100,height??=100,[[0,prog=>{const x=prog*width;return[x,height*Math.sin(CDEUtils.CIRC*x/width)]}]]),COSINE_WAVE:(width,height)=>(width??=100,height??=100,[[0,prog=>{const x=prog*width;return[x,height*Math.cos(CDEUtils.CIRC*x/width)]}]]),RELATIVE:(forceX,forceY)=>{forceX??=void 0,forceY??=void 0;let isForceXFn=!1,isForceYFn=!1;return Array.isArray(forceX)&&(forceX=forceX.flat()[1],isForceXFn=!0),Array.isArray(forceY)&&(forceY=forceY.flat()[1],isForceYFn=!0),[[0,prog=>[isForceXFn?forceX(prog)[0]:forceX,isForceYFn?forceY(prog)[1]:forceX]]]}}}class Color{static DEFAULT_COLOR="aliceblue";static DEFAULT_RGBA=[240,248,255,1];static DEFAULT_COLOR_VALUE="rgba(240, 248, 255, 1)";static CSS_COLOR_TO_RGBA_CONVERTIONS={transparent:[0,0,0,0],aliceblue:[240,248,255,1],antiquewhite:[250,235,215,1],aqua:[0,255,255,1],aquamarine:[127,255,212,1],azure:[240,255,255,1],beige:[245,245,220,1],bisque:[255,228,196,1],black:[0,0,0,1],blanchedalmond:[255,235,205,1],blue:[0,0,255,1],blueviolet:[138,43,226,1],brown:[165,42,42,1],burlywood:[222,184,135,1],cadetblue:[95,158,160,1],chartreuse:[127,255,0,1],chocolate:[210,105,30,1],coral:[255,127,80,1],cornflowerblue:[100,149,237,1],cornsilk:[255,248,220,1],crimson:[220,20,60,1],cyan:[0,255,255,1],darkblue:[0,0,139,1],darkcyan:[0,139,139,1],darkgoldenrod:[184,134,11,1],darkgray:[169,169,169,1],darkgreen:[0,100,0,1],darkkhaki:[189,183,107,1],darkmagenta:[139,0,139,1],darkolivegreen:[85,107,47,1],darkorange:[255,140,0,1],darkorchid:[153,50,204,1],darkred:[139,0,0,1],darksalmon:[233,150,122,1],darkseagreen:[143,188,143,1],darkslateblue:[72,61,139,1],darkslategray:[47,79,79,1],darkturquoise:[0,206,209,1],darkviolet:[148,0,211,1],deeppink:[255,20,147,1],deepskyblue:[0,191,255,1],dimgray:[105,105,105,1],dodgerblue:[30,144,255,1],firebrick:[178,34,34,1],floralwhite:[255,250,240,1],forestgreen:[34,139,34,1],fuchsia:[255,0,255,1],gainsboro:[220,220,220,1],ghostwhite:[248,248,255,1],gold:[255,215,0,1],goldenrod:[218,165,32,1],gray:[128,128,128,1],grey:[128,128,128,1],green:[0,128,0,1],greenyellow:[173,255,47,1],honeydew:[240,255,240,1],hotpink:[255,105,180,1],indianred:[205,92,92,1],indigo:[75,0,130,1],ivory:[255,255,240,1],khaki:[240,230,140,1],lavender:[230,230,250,1],lavenderblush:[255,240,245,1],lawngreen:[124,252,0,1],lemonchiffon:[255,250,205,1],lightblue:[173,216,230,1],lightcoral:[240,128,128,1],lightcyan:[224,255,255,1],lightgoldenrodyellow:[250,250,210,1],lightgray:[211,211,211,1],lightgreen:[144,238,144,1],lightpink:[255,182,193,1],lightsalmon:[255,160,122,1],lightseagreen:[32,178,170,1],lightskyblue:[135,206,250,1],lightslategray:[119,136,153,1],lightsteelblue:[176,224,230,1],lightyellow:[255,255,224,1],lime:[0,255,0,1],limegreen:[50,205,50,1],linen:[250,240,230,1],magenta:[255,0,255,1],maroon:[128,0,0,1],mediumaquamarine:[102,205,170,1],mediumblue:[0,0,205,1],mediumorchid:[186,85,211,1],mediumpurple:[147,112,219,1],mediumseagreen:[60,179,113,1],mediumslateblue:[123,104,238,1],mediumspringgreen:[0,250,154,1],mediumturquoise:[72,209,204,1],mediumvioletred:[199,21,133,1],midnightblue:[25,25,112,1],mintcream:[245,255,250,1],mistyrose:[255,228,225,1],moccasin:[255,228,181,1],navajowhite:[255,222,173,1],navy:[0,0,128,1],oldlace:[253,245,230,1],olive:[128,128,0,1],olivedrab:[107,142,35,1],orange:[255,165,0,1],orangered:[255,69,0,1],orchid:[218,112,214,1],palegoldenrod:[238,232,170,1],palegreen:[152,251,152,1],paleturquoise:[175,238,238,1],palevioletred:[219,112,147,1],papayawhip:[255,239,213,1],peachpuff:[255,218,185,1],peru:[205,133,63,1],pink:[255,192,203,1],plum:[221,160,221,1],powderblue:[176,224,230,1],purple:[128,0,128,1],rebeccapurple:[102,51,153,1],red:[255,0,0,1],rosybrown:[188,143,143,1],royalblue:[65,105,225,1],saddlebrown:[139,69,19,1],salmon:[250,128,114,1],sandybrown:[244,164,96,1],seagreen:[46,139,87,1],seashell:[255,245,238,1],sienna:[160,82,45,1],silver:[192,192,192,1],skyblue:[135,206,235,1],slateblue:[106,90,205,1],slategray:[112,128,144,1],snow:[255,250,250,1],springgreen:[0,255,127,1],steelblue:[70,130,180,1],tan:[210,180,140,1],teal:[0,128,128,1],thistle:[216,191,216,1],tomato:[255,99,71,1],turquoise:[64,224,208,1],violet:[238,130,238,1],wheat:[245,222,179,1],white:[255,255,255,1],whitesmoke:[245,245,245,1],yellow:[255,255,0,1],yellowgreen:[154,205,50,1]};static RGBA_TO_CSS_COLOR_CONVERTIONS={"0,0,0,0":"transparent","240,248,255,1":"aliceblue","250,235,215,1":"antiquewhite","0,255,255,1":"aqua","127,255,212,1":"aquamarine","240,255,255,1":"azure","245,245,220,1":"beige","255,228,196,1":"bisque","0,0,0,1":"black","255,235,205,1":"blanchedalmond","0,0,255,1":"blue","138,43,226,1":"blueviolet","165,42,42,1":"brown","222,184,135,1":"burlywood","95,158,160,1":"cadetblue","127,255,0,1":"chartreuse","210,105,30,1":"chocolate","255,127,80,1":"coral","100,149,237,1":"cornflowerblue","255,248,220,1":"cornsilk","220,20,60,1":"crimson","0,0,139,1":"darkblue","0,139,139,1":"darkcyan","184,134,11,1":"darkgoldenrod","169,169,169,1":"darkgray","0,100,0,1":"darkgreen","189,183,107,1":"darkkhaki","139,0,139,1":"darkmagenta","85,107,47,1":"darkolivegreen","255,140,0,1":"darkorange","153,50,204,1":"darkorchid","139,0,0,1":"darkred","233,150,122,1":"darksalmon","143,188,143,1":"darkseagreen","72,61,139,1":"darkslateblue","47,79,79,1":"darkslategray","0,206,209,1":"darkturquoise","148,0,211,1":"darkviolet","255,20,147,1":"deeppink","0,191,255,1":"deepskyblue","105,105,105,1":"dimgray","30,144,255,1":"dodgerblue","178,34,34,1":"firebrick","255,250,240,1":"floralwhite","34,139,34,1":"forestgreen","220,220,220,1":"gainsboro","248,248,255,1":"ghostwhite","255,215,0,1":"gold","218,165,32,1":"goldenrod","128,128,128,1":"gray","0,128,0,1":"green","173,255,47,1":"greenyellow","240,255,240,1":"honeydew","255,105,180,1":"hotpink","205,92,92,1":"indianred","75,0,130,1":"indigo","255,255,240,1":"ivory","240,230,140,1":"khaki","230,230,250,1":"lavender","255,240,245,1":"lavenderblush","124,252,0,1":"lawngreen","255,250,205,1":"lemonchiffon","173,216,230,1":"lightblue","240,128,128,1":"lightcoral","224,255,255,1":"lightcyan","250,250,210,1":"lightgoldenrodyellow","211,211,211,1":"lightgray","144,238,144,1":"lightgreen","255,182,193,1":"lightpink","255,160,122,1":"lightsalmon","32,178,170,1":"lightseagreen","135,206,250,1":"lightskyblue","119,136,153,1":"lightslategray","176,224,230,1":"lightsteelblue","255,255,224,1":"lightyellow","0,255,0,1":"lime","50,205,50,1":"limegreen","250,240,230,1":"linen","255,0,255,1":"magenta","128,0,0,1":"maroon","102,205,170,1":"mediumaquamarine","0,0,205,1":"mediumblue","186,85,211,1":"mediumorchid","147,112,219,1":"mediumpurple","60,179,113,1":"mediumseagreen","123,104,238,1":"mediumslateblue","0,250,154,1":"mediumspringgreen","72,209,204,1":"mediumturquoise","199,21,133,1":"mediumvioletred","25,25,112,1":"midnightblue","245,255,250,1":"mintcream","255,228,225,1":"mistyrose","255,228,181,1":"moccasin","255,222,173,1":"navajowhite","0,0,128,1":"navy","253,245,230,1":"oldlace","128,128,0,1":"olive","107,142,35,1":"olivedrab","255,165,0,1":"orange","255,69,0,1":"orangered","218,112,214,1":"orchid","238,232,170,1":"palegoldenrod","152,251,152,1":"palegreen","175,238,238,1":"paleturquoise","219,112,147,1":"palevioletred","255,239,213,1":"papayawhip","255,218,185,1":"peachpuff","205,133,63,1":"peru","255,192,203,1":"pink","221,160,221,1":"plum","128,0,128,1":"purple","102,51,153,1":"rebeccapurple","255,0,0,1":"red","188,143,143,1":"rosybrown","65,105,225,1":"royalblue","139,69,19,1":"saddlebrown","250,128,114,1":"salmon","244,164,96,1":"sandybrown","46,139,87,1":"seagreen","255,245,238,1":"seashell","160,82,45,1":"sienna","192,192,192,1":"silver","135,206,235,1":"skyblue","106,90,205,1":"slateblue","112,128,144,1":"slategray","255,250,250,1":"snow","0,255,127,1":"springgreen","70,130,180,1":"steelblue","210,180,140,1":"tan","0,128,128,1":"teal","216,191,216,1":"thistle","255,99,71,1":"tomato","64,224,208,1":"turquoise","238,130,238,1":"violet","245,222,179,1":"wheat","255,255,255,1":"white","245,245,245,1":"whitesmoke","255,255,0,1":"yellow","154,205,50,1":"yellowgreen"};static FORMATS={RGBA:"RGBA",TEXT:"TEXT",HEX:"HEX",GRADIENT:"GRADIENT",PATTERN:"PATTERN",COLOR:"COLOR",HSV:"HSVA"};static CONVERTABLE_FORMATS={RGBA:"RGBA",TEXT:"TEXT",HEX:"HEX",HSV:"HSVA"};static STRICT_FORMATS={RGBA:"RGBA",COLOR:"COLOR"};static DEFAULT_TEMPERANCE=0;static SEARCH_STARTS={TOP_LEFT:"TOP_LEFT",BOTTOM_RIGHT:"BOTTOM_RIGHT"};static DEFAULT_SEARCH_START=Color.SEARCH_STARTS.TOP_LEFT;static DEFAULT_DECIMAL_ROUNDING_POINT=3;static OPACITY_VISIBILITY_THRESHOLD=.05;#rgba=null;#hsv=null;constructor(color,isChannel=!1){const format=Color.getFormat(color);this._color=color instanceof Color?color._color:format&&color||Color.DEFAULT_COLOR,this._format=format||Color.getFormat(this._color),this.#updateCache(),this._isChannel=isChannel||!1}#updateCache(){if(this._format==Color.FORMATS.GRADIENT||this._format==Color.FORMATS.PATTERN)this.#rgba=this.#hsv=[];else{this.#rgba=this._format!==Color.FORMATS.RGBA?this.convertTo():Color.#unlinkRGBA(this._color);const rgba=this.#rgba,DDRP=Color.DEFAULT_DECIMAL_ROUNDING_POINT,round=CDEUtils.round;rgba[0]=round(rgba[0],DDRP),rgba[1]=round(rgba[1],DDRP),rgba[2]=round(rgba[2],DDRP),rgba[3]=round(rgba[3],DDRP),this.#hsv=Color.convertTo(this.#rgba,Color.FORMATS.HSV)}}static convertTo(color,format=Color.CONVERTABLE_FORMATS.RGBA){let inputFormat=Color.getFormat(color),convertedColor=color,formats=Color.CONVERTABLE_FORMATS,RGBA=formats.RGBA,HEX=formats.HEX,TEXT=formats.TEXT,HSV=formats.HSV;return inputFormat&&(format==RGBA?inputFormat==HEX?convertedColor=Color.#hexToRgba(color):inputFormat==TEXT?convertedColor=Color.#unlinkRGBA(Color.CSS_COLOR_TO_RGBA_CONVERTIONS[color]):inputFormat==HSV&&(convertedColor=Color.#hsvToRgba(color)):format==HEX?convertedColor=inputFormat==RGBA?Color.#rgbaToHex(color):Color.#rgbaToHex(Color.convertTo(color,RGBA)):format==TEXT?convertedColor=inputFormat==RGBA?Color.RGBA_TO_CSS_COLOR_CONVERTIONS[color.toString()]??color:Color.RGBA_TO_CSS_COLOR_CONVERTIONS[Color.convertTo(color,RGBA).toString()]??color:format==HSV&&(convertedColor=inputFormat==RGBA?Color.#rgbaToHsv(color):Color.#rgbaToHsv(Color.convertTo(color,RGBA)))),convertedColor}convertTo(color=this._color,format=Color.CONVERTABLE_FORMATS.RGBA){return Color.convertTo(color,format)}static random(outputFormat=Color.CONVERTABLE_FORMATS.RGBA,randomizeAlpha=!1,rRange=[0,255],gRange=[0,255],bRange=[0,255],aRange=[0,1]){const formats=Color.CONVERTABLE_FORMATS,random=CDEUtils.random,randomRGBA=[random(...rRange),random(...gRange),random(...bRange),randomizeAlpha?random(...aRange,2):1];return outputFormat==formats.HEX?Color.convertTo(randomRGBA,formats.HEX):outputFormat==formats.TEXT?Color.convertTo(randomRGBA,formats.TEXT):outputFormat==formats.HSV?Color.convertTo(randomRGBA,formats.HSV):randomRGBA}static#rgbaToHsv(rgba){let hue,r=rgba[0]/255,g=rgba[1]/255,b=rgba[2]/255,min=Math.min(r,g,b),max=Math.max(r,g,b),diff=max-min;return max==min?hue=0:(hue=max==r?(g-b)/diff:max==g?(b-r)/diff+2:(r-g)/diff+4,hue=(360+60*hue)%360),[hue,max&&diff/max*100,100*max]}static#unlinkRGBA(rgba){return rgba?[rgba[0],rgba[1],rgba[2],rgba[3]]:null}static#hsvToRgba(hsva){let r,g,b,hue=hsva[0],sat=hsva[1]/100,bright=hsva[2]/100,chro=bright*sat,x=chro*(1-Math.abs(hue/60%2-1)),dc=bright-chro;return 0<=hue&&hue<60?(r=chro,g=x,b=0):60<=hue&&hue<120?(r=x,g=chro,b=0):120<=hue&&hue<180?(r=0,g=chro,b=x):180<=hue&&hue<240?(r=0,g=x,b=chro):240<=hue&&hue<300?(r=x,g=0,b=chro):(r=chro,g=0,b=x),[Math.round(255*(r+dc)),Math.round(255*(g+dc)),Math.round(255*(b+dc)),1]}static#rgbaToHex(rgba){const hex="#"+rgba.reduce(((a,b,i)=>a+(!i||i%3?b:Math.round(255*b)).toString(16).padStart(2,"0")),"");return 1==rgba[3]?hex.slice(0,7):hex}static#hexToRgba(hex){return hex.padEnd(9,"F").match(/[a-z0-9]{2}/gi).reduce(((a,b,i)=>a.concat(parseInt(b,16)/(!i||i%3?1:255))),[])}static getFormat(color){const formats=Color.FORMATS;return color?Array.isArray(color)?4==color.length?formats.RGBA:formats.HSV:color instanceof Color?formats.COLOR:color instanceof Gradient?formats.GRADIENT:color instanceof Pattern?formats.PATTERN:"#"==color[0]?formats.HEX:Color.CSS_COLOR_TO_RGBA_CONVERTIONS[color]?formats.TEXT:null:null}static adjust(color){return color instanceof Color?color.isChannel?color:color.duplicate():new Color(color)}static formatRgba(arrayRgba){return Array.isArray(arrayRgba)?`rgba(${arrayRgba[0]}, ${arrayRgba[1]}, ${arrayRgba[2]}, ${arrayRgba[3]})`:null}static rgba(r=255,g=255,b=255,a=1){const round=CDEUtils.round,roundingPoint=Color.DEFAULT_DECIMAL_ROUNDING_POINT;return[round(r,roundingPoint),round(g,roundingPoint),round(b,roundingPoint),round(a,roundingPoint)]}static getColorValue(color){return"string"==typeof color||color instanceof CanvasGradient||color instanceof CanvasPattern?color:color instanceof _DynamicColor?color.value:Color.formatRgba(color)??color.color}static findFirstPos(canvas,color,useAlpha=!1,temperance=Color.DEFAULT_TEMPERANCE,searchStart=Color.DEFAULT_SEARCH_START,areaSize=[]){let x,y,yi,xi,currentR,currentG,currentB,width=areaSize[0]??canvas.width,height=areaSize[1]??canvas.height,data=canvas.ctx.getImageData(0,0,width,height).data,ow=4*width,r=color.r??color[0],g=color.g??color[1],b=color.b??color[2],a=255*(color.a??color[3]),br=r-temperance,bg=g-temperance,bb=b-temperance,ba=a-temperance,tr=r+temperance,tg=g+temperance,tb=b+temperance,ta=a+temperance,isSearchTL=searchStart==Color.SEARCH_STARTS.TOP_LEFT,startX=isSearchTL?0:width-1,endX=isSearchTL?width:-1,stepX=isSearchTL?1:-1,endY=isSearchTL?height:-1,stepY=isSearchTL?1:-1;for(y=isSearchTL?0:height-1;y!=endY;y+=stepY)for(yi=y*ow,x=startX;x!=endX;x+=stepX)if(xi=yi+4*x,currentR=data[xi],temperance){if(currentR>=br&&currentR<=tr&&(currentG=data[xi+1],currentB=data[xi+2],currentG>=bg&&currentG<=tg&&currentB>=bb&&currentB<=tb&&(!useAlpha||undefined>=ba&&undefined<=ta)))return[x,y]}else if(currentR==r&&data[xi+1]==g&&data[xi+2]==b&&(!useAlpha||data[xi+3]==a))return[x,y];return null}duplicate(dynamicColorPositions){const formats=Color.FORMATS,format=this._format;return format==formats.GRADIENT||format==formats.PATTERN?new Color(this._color.duplicate(dynamicColorPositions)):new Color(Color.#unlinkRGBA(this.#rgba))}toString(){let colorValue=Color.getColorValue(this._color);return(colorValue instanceof CanvasGradient||colorValue instanceof CanvasPattern)&&(colorValue=this._color.toString()),colorValue}get color(){const formats=Color.FORMATS,format=this._format;return format==formats.GRADIENT||format==formats.PATTERN?this._color.value:Color.formatRgba(this.#rgba)}get colorRaw(){return this._color}get isChannel(){return this._isChannel}get rgba(){return this.#rgba}get hsv(){return this.#hsv}get r(){return this.#rgba[0]}get g(){return this.#rgba[1]}get b(){return this.#rgba[2]}get a(){return this.#rgba[3]}get hue(){return this.#hsv[0]}get saturation(){return this.#hsv[1]}get brightness(){return this.#hsv[2]}set color(color){const colorValue=color?._color||color,format=Color.getFormat(colorValue);format&&(this._color=colorValue,this._format=format,this.#updateCache())}set r(r){this.#rgba[0]=CDEUtils.round(r,Color.DEFAULT_DECIMAL_ROUNDING_POINT)}set g(g){this.#rgba[1]=CDEUtils.round(g,Color.DEFAULT_DECIMAL_ROUNDING_POINT)}set b(b){this.#rgba[2]=CDEUtils.round(b,Color.DEFAULT_DECIMAL_ROUNDING_POINT)}set a(a){this.#rgba[3]=CDEUtils.round(a,Color.DEFAULT_DECIMAL_ROUNDING_POINT)}set rgba(rgba){this.#rgba[0]=CDEUtils.round(rgba[0],Color.DEFAULT_DECIMAL_ROUNDING_POINT),this.#rgba[1]=CDEUtils.round(rgba[1],Color.DEFAULT_DECIMAL_ROUNDING_POINT),this.#rgba[2]=CDEUtils.round(rgba[2],Color.DEFAULT_DECIMAL_ROUNDING_POINT),this.#rgba[3]=CDEUtils.round(rgba[3],Color.DEFAULT_DECIMAL_ROUNDING_POINT)}set hue(hue){hue%=360,this.#hsv[0]!=hue&&(this.#hsv[0]=hue,this.#rgba=Color.#hsvToRgba(this.#hsv))}set saturation(saturation){saturation=saturation>100?100:saturation,this.#hsv[1]!=saturation&&(this.#hsv[1]=saturation,this.#rgba=Color.#hsvToRgba(this.#hsv))}set brightness(brightness){brightness=brightness>100?100:brightness,this.#hsv[2]!=brightness&&(this.#hsv[2]=brightness,this.#rgba=Color.#hsvToRgba(this.#hsv))}}const colors=Object.entries(Color.CSS_COLOR_TO_RGBA_CONVERTIONS),c_ll=colors.length;for(let i=0;i<c_ll;i++){const color=colors[i];Object.defineProperty(Color,color[0],{get:()=>color[1]})}class _HasColor{constructor(color){this._initColor=color,this._color=this._initColor}getInitColor(){return CDEUtils.isFunction(this._initColor)?this._initColor(this):this._initColor||null}get colorObject(){return this._color}get colorRaw(){return this._color.colorRaw}get color(){return this._color?.color}get initColor(){return this._initColor}get rgba(){return this._color.rgba}get r(){return this._color.r}get g(){return this._color.g}get b(){return this._color.b}get a(){return this._color.a}get hsv(){return this._color.hsv}get hue(){return this._color.hue}get saturation(){return this._color.saturation}get brightness(){return this._color.brightness}set color(color){const c=this._color;if(!c||c?.colorRaw?.toString()!==color?.toString()){const specialColor=color?.colorRaw||color;specialColor?.positions==_DynamicColor.PLACEHOLDER&&((color=color.isChannel?specialColor:specialColor.duplicate()).initPositions=this),c instanceof Color?c.color=color:this._color=Color.adjust(color)}}set r(r){this._color.r=r}set g(g){this._color.g=g}set b(b){this._color.b=b}set a(a){this._color.a=a}set hue(hue){this._color.hue=hue}set saturation(saturation){this._color.saturation=saturation}set brightness(brightness){this._color.brightness=brightness}set initColor(initColor){this._initColor=initColor}}class GridAssets{static D=["t","r","b","l","tr","br","bl","tl","i"].reduce(((a,b,i)=>(a.places.push([a[b]=1<<i,ar=>0==i?-ar:1==i?1:2==i?ar:3==i?-1:4==i?1-ar:5==i?ar+1:6==i?ar-1:7==i?-ar-1:8==i?0:void 0]),a)),{places:[]});static DEFAULT_SOURCE=GridAssets.fontSource5x5;static get fontSource5x5(){const D=GridAssets.D;return{width:5,height:5,A:[[2,D.bl+D.br],[1,D.bl],[3,D.br],[0,D.r+D.b],[1,D.r],[2,D.r],[3,D.r],[4,D.b],[0,D.b],[4,D.b],[0],[4]],B:[[0,D.r+D.b],[,D.r],[,D.r],[,D.br],[0,D.b],[4,D.bl],[0,D.r+D.b],[,D.r],[,D.r],[,D.br],[0,D.b],[4,D.bl],[0,D.r],[,D.r],[,D.r],[]],C:[[1,D.r+D.bl],[,D.r],[,D.r],[],[0,D.b],[0,D.b],[0,D.br],[-1,D.r],[2,D.r],[,D.r],[]],D:[[0,D.r+D.b],[,D.r],[,D.r],[,D.br],[0,D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.b],[4,D.bl],[0,D.r],[,D.r],[,D.r],[]],E:[[0,D.r+D.b],[,D.r],[,D.r],[,D.r],[],[0,D.b],[0,D.b+D.r],[,D.r],[,D.r],[,D.r],[0,D.b],[0,D.r],[,D.r],[,D.r],[,D.r],[]],F:[[0,D.r+D.b],[,D.r],[,D.r],[,D.r],[],[0,D.b],[0,D.b+D.r],[,D.r],[,D.r],[],[0,D.b],[0]],G:[[1,D.r+D.bl],[,D.r],[,D.r],[],[0,D.b],[0,D.b],[3,D.r],[4,D.b],[0,D.br],[4,D.b],[1,D.r],[,D.r],[,D.r],[]],H:[[0,D.r+D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.b+D.r],[,D.r],[,D.r],[,D.r],[,D.b],[0,D.b],[4,D.b],[0],[4]],I:[[1,D.r],[,D.b+D.r],[],[2,D.b],[2,D.b],[2,D.b],[1,D.r],[,D.r],[]],J:[[1,D.r],[,D.r],[,D.b+D.r],[],[3,D.b],[3,D.b],[0,D.br],[3,D.bl],[1,D.r],[,D.r]],K:[[0,D.b],[3,D.bl],[0,D.b],[2,D.bl],[0,D.b+D.r],[,D.r+D.br],[0,D.b],[2,D.br],[0],[3,D.r]],L:[[0,D.b],[0,D.b],[0,D.b],[0,D.b],[0,D.r],[,D.r],[,D.r],[,D.r]],M:[[0,D.b+D.br],[4,D.b+D.bl],[0,D.b],[,D.br],[3,D.bl],[4,D.b],[0,D.b],[2],[4,D.b],[0,D.b],[4,D.b],[0],[4]],N:[[0,D.b+D.br],[4,D.b],[0,D.b],[,D.br],[4,D.b],[0,D.b],[2,D.br],[4,D.b],[0,D.b],[3,D.br],[4,D.b],[0],[4]],O:[[1,D.bl+D.r],[,D.r],[,D.br],[0,D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.b+D.br],[4,D.b+D.bl],[1,D.r],[,D.r],[,D.r]],P:[[0,D.r+D.b],[,D.r],[,D.br],[0,D.b],[3,D.bl],[0,D.b+D.r],[,D.r],[],[0,D.b],[0]],Q:[[1,D.bl+D.r],[,D.r],[,D.br],[0,D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.b+D.br],[3,D.br],[,D.bl],[1,D.r],[,D.r],[],[]],R:[[0,D.r+D.b],[,D.r],[,D.br],[0,D.b],[3,D.bl],[0,D.b+D.r],[,D.r+D.br],[],[0,D.b],[2,D.br],[0],[3]],S:[[1,D.r+D.bl],[,D.r],[,D.r],[],[0,D.br],[-1,D.r],[2,D.r],[,D.br],[-4,D.bl],[0,D.r+D.bl],[,D.r],[,D.r],[]],T:[[0,D.r],[,D.r],[,D.b+D.r],[,D.r],[],[2,D.b],[2,D.b],[2,D.b],[2]],U:[[0,D.r+D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.b+D.r],[4,D.b],[0,D.br],[4,D.bl],[1,D.r],[,D.r],[,D.r]],V:[[0,D.r+D.b],[4,D.b],[0,D.b],[4,D.b],[0,D.br],[4,D.bl],[1,D.br],[3,D.bl],[2,D.r]],W:[[0,D.b+D.br],[4,D.b+D.bl],[0,D.b],[4,D.b],[0,D.b],[2,D.bl+D.br],[4,D.b],[0,D.b],[,D.bl],[3,D.br],[4,D.b],[0],[4]],X:[[0,D.br],[4,D.bl],[1,D.br],[3,D.bl],[2,D.br+D.bl],[1,D.bl],[3,D.br],[0],[4]],Y:[[0,D.br],[4,D.bl],[1,D.br],[3,D.bl],[2,D.b],[2,D.b],[2]],Z:[[0,D.r],[,D.r],[,D.r],[,D.r],[,D.bl],[3,D.bl],[2,D.bl],[1,D.bl],[0,D.r],[,D.r],[,D.r],[,D.r],[]],a:[[1/0],[1,D.bl+D.r],[,D.br],[0,D.b],[3,D.b],[0,D.br],[3,D.bl+D.br],[1,D.r],[],[4]],b:[[0,D.b],[0,D.b],[0,D.b+D.r],[,D.r],[,D.br],[0,D.b],[3,D.bl],[0,D.r],[,D.r],[,D.r]],c:[[1/0],[1,D.r+D.bl],[,D.r],[],[0,D.b],[0,D.br],[-1,D.r],[2,D.r],[]],d:[[3,D.b],[3,D.b],[1,D.bl+D.r],[,D.r],[,D.b],[0,D.br],[3,D.b],[1,D.r],[,D.r],[]],e:[[1,D.r+D.bl],[,D.br],[0,D.b],[3,D.bl],[0,D.b+D.r],[,D.r],[],[0,D.br],[3,D.bl],[1,D.r],[]],f:[[1,D.b+D.r],[],[1,D.b],[0,D.r],[,D.r+D.b],[],[1,D.b],[1]],g:[[1,D.bl+D.r],[,D.br],[0,D.br],[3,D.bl],[1,D.r],[,D.br],[0,D.br],[3,D.bl],[1,D.r],[]],h:[[0,D.b],[0,D.b],[0,D.b+D.r],[,D.r],[,D.br],[0,D.b],[3,D.b],[0],[3]],i:[[1/0],[1,D.i],[1,D.b],[1,D.b],[1]],j:[[2,D.i],[2,D.b],[2,D.b],[0,D.br],[2,D.bl],[1]],k:[[0,D.b],[0,D.b],[2,D.bl],[0,D.b],[2,D.bl],[0,D.b+D.r],[,D.br],[0],[2]],l:[[0,D.b],[0,D.b],[0,D.b],[0,D.b],[0]],m:[[1/0],[1,D.bl+D.br],[3,D.bl+D.br],[0,D.b],[2,D.b],[4,D.b],[0,D.b],[2,D.b],[4,D.b],[0],[2],[4]],n:[[1/0],[0,D.b],[,D.bl+D.r],[,D.bl+D.br],[0,D.b],[3,D.b],[0,D.b],[3,D.b],[0],[3]],o:[[1/0],[1,D.bl+D.r],[,D.br],[0,D.b],[3,D.b],[0,D.br],[3,D.bl],[1,D.r],[]],p:[[1,D.r+D.bl],[,D.br],[0,D.b],[3,D.bl],[0,D.b+D.r],[,D.r],[],[0,D.b],[0]],q:[[1,D.r+D.bl],[,D.br],[0,D.br],[3,D.b],[1,D.r],[,D.r],[,D.b],[3,D.b],[3]],r:[[1/0],[0,D.b],[,D.bl+D.r],[],[0,D.b],[0,D.b],[0]],s:[[1/0],[2,D.bl+D.br],[1,D.br],[3],[1,D.br],[2,D.r],[,D.b],[2,D.r],[]],t:[[2,D.b],[1,D.r],[,D.b+D.r],[],[2,D.b],[2,D.b],[2]],u:[[1/0],[0,D.b],[2,D.b],[0,D.b],[2,D.b],[0,D.br],[2,D.bl+D.br],[1,D.r],[3]],v:[[1/0],[1,D.b],[3,D.b],[1,D.b],[3,D.b],[1,D.br],[3,D.bl],[2,D.r]],w:[[1/0],[0,D.b],[2,D.b],[4,D.b],[0,D.b],[2,D.b],[4,D.b],[0,D.br],[2,D.bl+D.br],[4,D.bl],[1],[3]],x:[[1,D.b],[3,D.b],[1,D.br],[3,D.bl],[2,D.br+D.bl],[1,D.b],[3,D.b],[1],[3]],y:[[1/0],[1,D.b],[3,D.b],[1,D.br],[3,D.bl],[2,D.b],[2]],z:[[1/0],[0,D.r],[,D.r],[,D.r],[,D.bl],[2,D.bl],[1,D.bl],[0,D.r],[,D.r],[,D.r],[]],"!":[[3,D.b],[3,D.b],[3,D.b],[3],[3,D.i]],"?":[[1,D.r+D.bl],[,D.r],[,D.br],[0],[4,D.bl],[3,D.bl],[2],[2,D.i]],"@":[[1,D.bl+D.r],[,D.r],[,D.br],[0,D.b],[2,D.bl+D.br],[4,D.b],[0,D.b],[1,D.br],[3,D.b],[4,D.b],[0,D.b+D.br],[2,D.r],[3,D.r],[4],[1,D.r],[,D.r],[,D.r]],"#":[[1,D.b],[3,D.b],[0,D.r],[1,D.b+D.r],[2,D.r],[3,D.b+D.r],[],[1,D.b],[3,D.b],[0,D.r],[1,D.b+D.r],[2,D.r],[3,D.b+D.r],[],[1],[3]],$:[[1,D.r+D.bl],[,D.r+D.b],[,D.r],[],[0,D.br],[2,D.b],[1,D.r],[2,D.r+D.b],[,D.br],[2,D.b],[4,D.bl],[0,D.r+D.bl],[,D.r],[,D.r],[]],"%":[[0,D.r+D.b],[1,D.b],[4,D.bl],[0,D.r],[],[3,D.bl],[2,D.bl],[1,D.bl],[3,D.r+D.b],[4,D.b],[0],[3,D.r],[]],"^":[[2,D.br+D.bl],[1],[3]],"&":[[0,D.r+D.br],[,D.r],[,D.r],[,D.bl],[1,D.br],[2,D.bl],[1,D.bl],[2,D.br],[0,D.br],[3,D.br],[,D.bl],[1,D.r],[2,D.r],[3],[]],"*":[[1,D.br],[,D.b],[,D.bl],[1,D.r],[,D.r],[],[1,D.tr],[,D.t],[,D.tl]],"(":[[3,D.bl],[2,D.b],[2,D.b],[2,D.br],[-3]],")":[[1,D.br],[-2,D.b],[2,D.b],[2,D.bl],[1]],"{":[[3,D.bl],[2,D.b],[1,D.r],[2,D.b],[2,D.br],[-3]],"}":[[1,D.br],[-2,D.b],[2,D.b+D.r],[],[2,D.bl],[1]],",":[[1/0],[1/0],[1/0],[1,D.bl],[0]],".":[[1/0],[1/0],[1/0],[1/0],[0,D.i]],"+":[[1/0],[2,D.b],[1,D.r],[2,D.b+D.r],[],[2]],_:[[1/0],[1/0],[1/0],[1/0],[0,D.r],[,D.r],[,D.r],[,D.r],[,D.r]],"-":[[1/0],[1/0],[1,D.r],[,D.r],[]],"=":[[1/0],[1,D.r],[,D.r],[,D.r],[1/0],[1,D.r],[,D.r],[,D.r]],";":[[2,D.r+D.b],[3,D.b],[2,D.r],[],[2,D.r+D.b],[3,D.b],[2,D.r],[,D.b],[3]],":":[[1/0],[2,D.r+D.b],[3,D.b],[2,D.r],[],[2,D.r+D.b],[3,D.b],[2,D.r],[]],"[":[[2,D.b+D.r],[3],[2,D.b],[2,D.b],[2,D.b],[2,D.r],[3]],"]":[[1,D.r],[2,D.b],[2,D.b],[2,D.b],[2,D.b],[1,D.r],[2]],"'":[[0,D.b],[0]],"|":[[2,D.b],[2,D.b],[2,D.b],[2,D.b],[2]],"/":[[4,D.bl],[3,D.bl],[2,D.bl],[1,D.bl],[0]],"\\":[[0,D.br],[-1,D.br],[-2,D.br],[-3,D.br],[-4]],0:[[1,D.bl+D.r],[,D.br],[0,D.b],[3,D.b],[0,D.b],[,D.r],[],[,D.b],[0,D.b+D.br],[3,D.b+D.bl],[1,D.r],[,D.r]],1:[[2,D.b+D.bl],[1],[,D.b],[2,D.b],[2,D.b],[1,D.r],[,D.r],[]],2:[[1,D.r+D.bl],[,D.br],[0],[3,D.bl],[2,D.bl],[1,D.bl],[0,D.r],[,D.r],[,D.r],[,D.r]],3:[[1,D.r+D.bl],[,D.br],[0],[3,D.bl],[2,D.br],[0,D.br],[3,D.bl],[1,D.r],[,D.r]],4:[[3,D.b+D.bl],[2,D.bl],[,D.b],[1,D.bl],[3,D.b],[0,D.r],[,D.r],[,D.r],[,D.r+D.b],[,D.r],[3]],5:[[1,D.r+D.b],[,D.r],[,D.r],[],[1,D.b],[-1,D.r],[2,D.r],[,D.br],[-4,D.bl],[1,D.r+D.bl],[,D.r],[]],6:[[0,D.r+D.b],[,D.r],[,D.r],[,D.r],[0,D.b],[0,D.r+D.b],[,D.r],[,D.r],[,D.r+D.b],[0,D.b],[3,D.b],[0,D.r],[,D.r],[,D.r],[,D.r]],7:[[0,D.r],[,D.r],[,D.r],[,D.b],[3,D.bl],[1,D.r],[,D.bl+D.r],[],[1,D.bl],[0]],8:[[1,D.bl+D.r],[,D.br],[0,D.br],[3,D.bl],[1,D.bl+D.r],[,D.br],[0,D.b+D.br],[3,D.b+D.bl],[1,D.r],[,D.r]],9:[[1,D.r+D.bl],[,D.br],[0,D.br],[3,D.bl+D.b],[1,D.r],[],[,D.b],[3,D.b],[3]]}}}class TypingDevice{static KEYS={A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",DIGIT_0:"0",DIGIT_1:"1",DIGIT_2:"2",DIGIT_3:"3",DIGIT_4:"4",DIGIT_5:"5",DIGIT_6:"6",DIGIT_7:"7",DIGIT_8:"8",DIGIT_9:"9",SPACE:" ",ENTER:"ENTER",TAB:"TAB",BACKSPACE:"BACKSPACE",ESCAPE:"ESCAPE",SHIFT:"SHIFT",CONTROL:"CONTROL",ALT:"ALT",ALT_GRAPH:"ALTGRAPH",META:"META",CAPS_LOCK:"CAPSLOCK",CONTEXT_MENU:"CONTEXTMENU",ARROW_UP:"ARROWUP",ARROW_DOWN:"ARROWDOWN",ARROW_LEFT:"ARROWLEFT",ARROW_RIGHT:"ARROWRIGHT",HOME:"HOME",END:"END",PAGE_UP:"PAGEUP",PAGE_DOWN:"PAGEDOWN",INSERT:"INSERT",DELETE:"DELETE",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",NUMPAD_0:"NUMPAD0",NUMPAD_1:"NUMPAD1",NUMPAD_2:"NUMPAD2",NUMPAD_3:"NUMPAD3",NUMPAD_4:"NUMPAD4",NUMPAD_5:"NUMPAD5",NUMPAD_6:"NUMPAD6",NUMPAD_7:"NUMPAD7",NUMPAD_8:"NUMPAD8",NUMPAD_9:"NUMPAD9",NUMPAD_ADD:"NUMPADADD",NUMPAD_SUBTRACT:"NUMPADSUBTRACT",NUMPAD_MULTIPLY:"NUMPADMULTIPLY",NUMPAD_DIVIDE:"NUMPADDIVIDE",NUMPAD_DECIMAL:"NUMPADDECIMAL",NUMPAD_ENTER:"NUMPADENTER",PAUSE:"PAUSE",PRINT_SCREEN:"PRINTSCREEN",SCROLL_LOCK:"SCROLLLOCK",NUM_LOCK:"NUMLOCK",LAUNCH_APPLICATION_1:"LAUNCHAPPLICATION1",LAUNCH_APPLICATION_2:"LAUNCHAPPLICATION2",BRACKET_LEFT:"BRACKETLEFT",BRACKET_RIGHT:"BRACKETRIGHT",SEMICOLON:"SEMICOLON",QUOTE:"QUOTE",COMMA:"COMMA",PERIOD:"PERIOD",SLASH:"SLASH",BACKSLASH:"BACKSLASH",EQUAL:"EQUAL",MINUS:"MINUS",BACKQUOTE:"BACKQUOTE",AUDIO_VOLUME_UP:"AUDIOVOLUMEUP",AUDIO_VOLUME_DOWN:"AUDIOVOLUMEDOWN",AUDIO_VOLUME_MUTE:"AUDIOVOLUMEMUTE",MEDIA_PLAY_PAUSE:"MEDIAPLAYPAUSE",MEDIA_NEXT_TRACK:"MEDIANEXTTRACK",MEDIA_PREVIOUS_TRACK:"MEDIAPREVIOUSTRACK",MEDIA_STOP:"MEDIASTOP",BROWSER_BACK:"BROWSERBACK",BROWSER_FORWARD:"BROWSERFORWARD",BROWSER_REFRESH:"BROWSERREFRESH",BROWSER_STOP:"BROWSERSTOP",BROWSER_SEARCH:"BROWSERSEARCH",BROWSER_FAVORITES:"BROWSERFAVORITES",BROWSER_HOME:"BROWSERHOME"};constructor(){this._keysPressed=[]}setDown(e){const key=e.key?.toUpperCase();key&&!this.isDown(key)&&this._keysPressed.push({key:key,keyCode:e.keyCode})}setUp(e){const key=e.key?.toUpperCase();key&&this.isDown(key)&&(this._keysPressed=this._keysPressed.filter((v=>v.key!==key)))}isDown(keys){const isMultipleKeys=Array.isArray(keys),keysPressed=this.keysPressed;if(!isMultipleKeys)return keysPressed.includes(keys?.toUpperCase());{const k_ll=keys.length;for(let i=0;i<k_ll;i++){const key=keys[i]?.toUpperCase();if(keysPressed.includes(key))return!0}}return!1}hasKeysDown(){return Boolean(this._keysPressed.length)}get keysPressedRaw(){return this._keysPressed}get keysPressed(){return this._keysPressed.map((v=>v.key))}get keyCodesPressed(){return this._keysPressed.map((v=>v.keyCode))}set keysPressed(keysPressed){this._keysPressed=keysPressed}}class Mouse{static DEFAULT_MOUSE_DECELERATION=.8;static DEFAULT_MOUSE_MOVE_TRESHOLD=.1;static DEFAULT_MOUSE_ANGULAR_DECELERATION=.2;static#LISTENER_ID_GIVER=0;static LISTENER_TYPES={CLICK:0,DOWN:0,UP:1,MAIN_DOWN:0,MAIN_UP:1,MIDDLE_DOWN:2,MIDDLE_UP:3,RIGHT_DOWN:4,RIGHT_UP:5,EXTRA_FOWARD_DOWN:6,EXTRA_FOWARD_UP:7,EXTRA_BACK_DOWN:8,EXTRA_BACK_UP:9,MOVE:10,ENTER:11,LEAVE:12,EXIT:12};#lastX=null;#lastY=null;#wasWithin=[];constructor(ctx){this._ctx=ctx,this._valid=!1,this._x=null,this._y=null,this._lastPos=[0,0],this._rawX=null,this._rawY=null,this._dir=null,this._speed=null,this._clicked=!1,this._rightClicked=!1,this._scrollClicked=!1,this._extraForwardClicked=!1,this._extraBackClicked=!1,this._holdValue=null,this._listeners=[],this._moveListenersOptimizationEnabled=!0}calcSpeed(deltaTime){const DECELERATION=Mouse.DEFAULT_MOUSE_DECELERATION;isFinite(this.#lastX)&&isFinite(this.#lastY)&&deltaTime?(this._speed=this._speed*DECELERATION+CDEUtils.getDist(this._x,this._y,this.#lastX,this.#lastY)/deltaTime*(1-DECELERATION),this._speed<Mouse.DEFAULT_MOUSE_MOVE_TRESHOLD&&(this._speed=0)):this._speed=0,this.#lastX=this._x,this.#lastY=this._y}calcAngle(){const dx=this._x-this.#lastX,dy=this._y-this.#lastY;if(isFinite(dx)&&isFinite(dy)&&(dx||dy)){let diff=(360-CDEUtils.toDeg(Math.atan2(dy,dx)))%360-this._dir;diff+=360*(diff<-180)-360*(diff>180),this._dir=(this._dir+diff*Mouse.DEFAULT_MOUSE_ANGULAR_DECELERATION+360)%360}else this._dir=0}updateMouseClicks(e){const isMouseDownEvent="mousedown"==e.type||"touchstart"==e.type,TYPES=Mouse.LISTENER_TYPES;0==e.button?(this._clicked=isMouseDownEvent,this.checkListeners(isMouseDownEvent?TYPES.MAIN_DOWN:TYPES.MAIN_UP)):1==e.button?(this._scrollClicked=isMouseDownEvent,this.checkListeners(isMouseDownEvent?TYPES.MIDDLE_DOWN:TYPES.MIDDLE_UP)):2==e.button?(this._rightClicked=isMouseDownEvent,this.checkListeners(isMouseDownEvent?TYPES.RIGHT_DOWN:TYPES.RIGHT_UP)):3==e.button?(this._extraBackClicked=isMouseDownEvent,this.checkListeners(isMouseDownEvent?TYPES.EXTRA_BACK_DOWN:TYPES.EXTRA_BACK_UP)):4==e.button&&(this._extraForwardClicked=isMouseDownEvent,this.checkListeners(isMouseDownEvent?TYPES.EXTRA_FOWARD_DOWN:TYPES.EXTRA_FOWARD_UP))}invalidate(){this._x=1/0,this._y=1/0,this._rawX=1/0,this._rawY=1/0}updatePos(x,y,offset){this._valid=!0,this._rawX=x,this._rawY=y,this._x=x-offset[0],this._y=y-offset[1],this._moveListenersOptimizationEnabled&&(this.checkListeners(Mouse.LISTENER_TYPES.ENTER),this.checkListeners(Mouse.LISTENER_TYPES.LEAVE)),this._lastPos[0]=this._x,this._lastPos[1]=this._y,this.checkListeners(Mouse.LISTENER_TYPES.MOVE)}checkValid(){return this._x==1/0||null==this._x||this._y==1/0||null==this._y?this._valid=!1:this._valid?void 0:this._valid=!0}addListener(obj,type,callback,useAccurateBounds=!1,forceStaticPositions=!1){const hasAccurateBounds=useAccurateBounds&&obj.getBoundsAccurate,listener=[forceStaticPositions?hasAccurateBounds?obj.getBoundsAccurate():obj.getBounds():obj,callback,hasAccurateBounds,Mouse.#LISTENER_ID_GIVER++];return this._listeners[type]||(this._listeners[type]=[]),this._listeners[type].push(listener),listener[3]}checkListeners(type){const typedListeners=this._listeners[type],typedListeners_ll=typedListeners?.length;if(typedListeners_ll){let TYPES=Mouse.LISTENER_TYPES,mousePos=this.pos,validation=!0;if(type>=TYPES.ENTER){validation=2,type==TYPES.LEAVE&&(validation=1);for(let i=0;i<typedListeners_ll;i++){const typedListener=typedListeners[i],obj=typedListener[0],callback=typedListener[1],hasAccurateBounds=typedListener[2],isPath2D=obj instanceof Path2D,isStaticBounds=Array.isArray(obj)||isPath2D,nowWithin=!isStaticBounds&&(hasAccurateBounds?obj.isWithinAccurate(mousePos):obj.isWithin(mousePos))||isStaticBounds&&this.isWithin(mousePos,obj,isPath2D);if(this._moveListenersOptimizationEnabled)2*nowWithin+(!isStaticBounds&&(hasAccurateBounds?obj.isWithinAccurate(this._lastPos):obj.isWithin(this._lastPos))||isStaticBounds&&this.isWithin(this._lastPos,obj,isPath2D))==validation&&callback(mousePos,obj,this);else{const wasWithin=this.#wasWithin[typedListener[3]];!wasWithin&&nowWithin?(this.#wasWithin[typedListener[3]]=!0,2==validation&&callback(mousePos,obj,this)):!nowWithin&&wasWithin&&(this.#wasWithin[typedListener[3]]=!1,1==validation&&callback(mousePos,obj,this))}}}else{validation=type==TYPES.MAIN_DOWN||type==TYPES.RIGHT_DOWN||type==TYPES.MIDDLE_DOWN||type==TYPES.EXTRA_BACK_DOWN||type==TYPES.EXTRA_FOWARD_DOWN?this._clicked:type!=TYPES.MAIN_UP&&type!=TYPES.RIGHT_UP&&type!=TYPES.MIDDLE_UP&&type!=TYPES.EXTRA_BACK_UP&&type!=TYPES.EXTRA_FOWARD_UP||!this._clicked;for(let i=0;i<typedListeners_ll;i++){const[obj,callback,hasAccurateBounds]=typedListeners[i],isPath2D=obj instanceof Path2D,isStaticBounds=Array.isArray(obj)||isPath2D;validation&&(!isStaticBounds&&(hasAccurateBounds?obj.isWithinAccurate(mousePos):obj.isWithin(mousePos))||isStaticBounds&&this.isWithin(mousePos,obj,isPath2D))&&callback(mousePos,obj,this)}}}}updateListener(type,id,newObj,newCallback,useAccurateBounds,forceStaticPositions=!1){const listener=this._listeners[type][this._listeners[type].findIndex((l=>l[3]==(id?.[3]??id)))];newObj&&(listener[0]=forceStaticPositions?useAccurateBounds&&obj.getBoundsAccurate?obj.getBoundsAccurate():obj.getBounds():obj),newCallback&&(listener[1]=newCallback),CDEUtils.isDefined(useAccurateBounds)&&(listener[2]=useAccurateBounds)}removeListener(type,id){this._listeners[type]="*"==id?[]:this._listeners[type].filter((l=>l[3]!==(id?.[3]??id)))}removeAllListeners(){this._listeners=[]}isWithin(pos,positions,isPath2D){const[x,y]=pos;return isPath2D?this._ctx.isPointInPath(positions,pos[0],pos[1]):x>=positions[0][0]&&x<=positions[1][0]&&y>=positions[0][1]&&y<=positions[1][1]}get ctx(){return this._ctx}get valid(){return this._valid}get x(){return this._x}get y(){return this._y}get pos(){return[this._x,this._y]}get rawX(){return this._rawX}get rawY(){return this._rawY}get rawPos(){return[this._rawX,this._rawY]}get deltaTimeLastX(){return this.#lastX}get deltaTimeLastY(){return this.#lastY}get lastX(){return this._lastPos[0]}get lastY(){return this._lastPos[0]}get lastPos(){return this._lastPos}get dir(){return this._dir}get speed(){return this._speed}get clicked(){return this._clicked}get scrollClicked(){return this._scrollClicked}get rightClicked(){return this._rightClicked}get extraBackClicked(){return this._extraBackClicked}get extraForwardClicked(){return this._extraForwardClicked}get holdValue(){return this._holdValue}get listeners(){return this._listeners}get moveListenersOptimizationEnabled(){return this._moveListenersOptimizationEnabled}set ctx(ctx){this._ctx=ctx}set valid(valid){this._valid=valid}set dir(_dir){this._dir=_dir}set speed(_speed){this._speed=_speed}set clicked(_clicked){this._clicked=_clicked}set scrollClicked(_scrollClicked){this._scrollClicked=_scrollClicked}set rightClicked(_rightClicked){this._rightClicked=_rightClicked}set extraBackClicked(_extraBackClicked){this._extraBackClicked=_extraBackClicked}set extraForwardClicked(_extraForwardClicked){this._extraForwardClicked=_extraForwardClicked}set holdValue(holdValue){this._holdValue=holdValue}}class Render{static PROFILE_ID_GIVER=-1;static TEXT_PROFILE_ID_GIVER=-1;static COMPOSITE_OPERATIONS={SOURCE_OVER:"source-over",SOURCE_IN:"source-in",SOURCE_OUT:"source-out",SOURCE_ATOP:"source-atop",DESTINATION_OVER:"destination-over",DESTINATION_IN:"destination-in",DESTINATION_OUT:"destination-out",DESTINATION_ATOP:"destination-atop",LIGHTER:"lighter",COPY:"copy",XOR:"xor",MULTIPLY:"multiply",SCREEN:"screen",OVERLAY:"overlay",DARKEN:"darken",LIGHTEN:"lighten",COLOR_DODGE:"color-dodge",COLOR_BURN:"color-burn",HARD_LIGHT:"hard-light",SOFT_LIGHT:"soft-light",DIFFERENCE:"difference",EXCLUSION:"exclusion",HUE:"hue",SATURATION:"saturation",COLOR:"color",LUMINOSITY:"luminosity"};static FILTERS={BLUR:v=>`blur(${v}px)`,BRIGHTNESS:v=>`brightness(${v})`,CONTRAST:v=>`contrast(${v})`,DROPSHADOW:value=>`drop-shadow(${value})`,GRAYSCALE:v=>`grayscale(${v})`,HUE_ROTATE:v=>`hue-rotate(${v}deg)`,INVERT:v=>`invert(${v})`,OPACITY:v=>`opacity(${v})`,SATURATE:v=>`saturate(${v})`,SEPIA:v=>`sepia(${v})`,URL:v=>`url(${v})`};static DEFAULT_COMPOSITE_OPERATION=Render.COMPOSITE_OPERATIONS.SOURCE_OVER;static DEFAULT_FILTER="none";static DEFAULT_ALPHA=1;static PATH_TYPES={LINEAR:Render.getLine,QUADRATIC:Render.getQuadCurve,CUBIC_BEZIER:Render.getBezierCurve,ARC:Render.getArc,ARC_TO:Render.getArcTo,ELLIPSE:Render.getEllispe,RECT:Render.getRect,POSITIONS_RECT:Render.getPositionsRect,ROUND_RECT:Render.getRoundRect,POSITIONS_ROUND_RECT:Render.getPositionsRoundRect};static LINE_TYPES={LINEAR:Render.getLine,QUADRATIC:Render.getQuadCurve,CUBIC_BEZIER:Render.getBezierCurve};static DRAW_METHODS={FILL:"FILL",STROKE:"STROKE"};static COLOR_TRANSFORMS={NONE:null,INVERT:1,GRAYSCALE:2,SEPIA:3,RANDOMIZE:4,STATIC:5,MULTIPLY:6,BGRA:7,TINT:8,FORCE_TINT:9};#currentCtxVisuals=[Color.DEFAULT_COLOR_VALUE,Render.DEFAULT_FILTER,Render.DEFAULT_COMPOSITE_OPERATION,Render.DEFAULT_ALPHA];#currentCtxStyles=RenderStyles.DEFAULT_PROFILE.getStyles();#currentCtxTextStyles=TextStyles.DEFAULT_PROFILE.getStyles();constructor(ctx){this._ctx=ctx,this._batchedStrokes={},this._batchedFills={},this._bactchedStandalones=[],this._defaultProfile=RenderStyles.DEFAULT_PROFILE.duplicate(this),this._profile1=this._defaultProfile.duplicate(),this._profile2=this._defaultProfile.duplicate(),this._profile3=this._defaultProfile.duplicate(),this._profile4=this._defaultProfile.duplicate(),this._profile5=this._defaultProfile.duplicate(),this._profiles=[],this._defaultTextProfile=TextStyles.DEFAULT_PROFILE.dupli