textmode.js 0.2.0 → 0.2.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.esm.js +1145 -906
- package/dist/textmode.esm.min.js +1391 -1152
- package/dist/textmode.umd.js +21 -21
- package/dist/textmode.umd.min.js +18 -18
- package/dist/types/textmode/Textmodifier.d.ts +8 -2
- package/dist/types/textmode/keyboard/KeyboardManager.d.ts +123 -0
- package/dist/types/textmode/keyboard/index.d.ts +2 -0
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +39 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +27 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +19 -0
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +4 -0
- package/dist/types/textmode/mouse/MouseManager.d.ts +130 -0
- package/dist/types/textmode/mouse/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var
|
|
1
|
+
var re=Object.defineProperty;var ne=(T,C,P)=>C in T?re(T,C,{enumerable:!0,configurable:!0,writable:!0,value:P}):T[C]=P;var l=(T,C,P)=>ne(T,typeof C!="symbol"?C+"":C,P);var e,s;e=this,s=function(T){class C extends Error{constructor(t,i={}){super(C.i(t,i)),this.name="TextmodeError"}static i(t,i){let r=t;if(i&&Object.keys(i).length>0){r+=`
|
|
2
2
|
|
|
3
|
-
📋 Context:`;for(const[n,o]of Object.entries(
|
|
4
|
-
- ${n}: ${
|
|
3
|
+
📋 Context:`;for(const[n,o]of Object.entries(i))r+=`
|
|
4
|
+
- ${n}: ${C.o(o)}`}return r+=`
|
|
5
5
|
|
|
6
|
-
`,
|
|
7
|
-
`,
|
|
8
|
-
in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 rotateX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0,0,c,-s,0,s,c);}mat3 rotateY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s,0,1,0,-s,0,c);}mat3 rotateZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0,s,c,0,0,0,1);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return u2*u*p0+3.*u2*t*p1+3.*u*t2*p2+t2*t*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return-3.*u2*p0+3.*u2*p1-6.*u*t*p1+6.*u*t*p2-3.*t2*p2+3.*t2*p3;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 worldPosition;bool isBezier=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool isArc=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(isBezier){float t=a_position.x;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tLen=length(tangent);tangent=tLen>0.?tangent/tLen:vec2(1,0);worldPosition=curvePoint+vec2(-tangent.y,tangent.x)*a_position.y*a_instanceSize.y;}else if(isArc){float s=a_instanceArcAngles.x,e=a_instanceArcAngles.y;s=mod(s,6.28318530718);if(s<0.)s+=6.28318530718;e=mod(e,6.28318530718);if(e<0.)e+=6.28318530718;float d=s-e;if(d<=0.)d+=6.28318530718;float angle=s-a_position.x*d;vec2 local=vec2(cos(angle),sin(angle))*a_position.y;worldPosition=local*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{worldPosition=a_position*a_instanceSize+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.-1.;ndc.y=-ndc.y;if(length(a_instanceGlobalRotation)>0.){vec3 pos3D=vec3(ndc-a_instanceRotationCenter,0);pos3D.x*=u_aspectRatio;if(a_instanceGlobalRotation.x!=0.)pos3D=rotateX(-a_instanceGlobalRotation.x)*pos3D;if(a_instanceGlobalRotation.y!=0.)pos3D=rotateY(-a_instanceGlobalRotation.y)*pos3D;if(a_instanceGlobalRotation.z!=0.)pos3D=rotateZ(-a_instanceGlobalRotation.z)*pos3D;pos3D.x/=u_aspectRatio;ndc=pos3D.xy+a_instanceRotationCenter;}gl_Position=vec4(ndc,0,1);}`,
|
|
9
|
-
precision highp float;in vec2 v_uv;uniform sampler2D u_src0;uniform sampler2D u_src1;uniform sampler2D u_src2;uniform sampler2D u_src3;uniform sampler2D u_src4;uniform vec2 u_srcSize;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 uvTex=v_uv*u_srcSize;vec2 uvQ=(floor(uvTex)+0.5f)/u_srcSize;o_character=texture(u_src0,uvQ);o_primaryColor=texture(u_src1,uvQ);o_secondaryColor=texture(u_src2,uvQ);o_rotation=texture(u_src3,uvQ);o_transform=texture(u_src4,uvQ);}`)),this.Ot}te(t,r){return this.jt&&this.Ht&&this.Ht.w===t&&this.Ht.h===r||(this.jt&&this.jt.j(),this.jt=new N(this.S,t,r,5),this.Ht={w:t,h:r}),this.jt}}class at{constructor(){u(this,"se",[]);u(this,"ie",1);u(this,"re",0)}ne(t){if(this.re>=this.se.length){const i={id:this.ie++,type:t,params:{},state:{lineWeight:1,rotationX:0,rotationY:0,rotationZ:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.se.push(i)}const r=this.se[this.re];switch(r.id=this.ie++,r.type=t,t){case C.RECTANGLE:case C.ELLIPSE:r.params&&"width"in r.params||(r.params={x:0,y:0,width:0,height:0});break;case C.CUSTOM:r.params&&"shader"in r.params||(r.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case C.ARC:r.params&&"start"in r.params||(r.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case C.LINE:r.params&&"x2"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case C.TRIANGLE:r.params&&"x3"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case C.BEZIER_CURVE:r.params&&"cp2y"in r.params||(r.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:r.params||(r.params={})}return this.re++,r}oe(t,r,i,n,o){const a=this.ne(C.RECTANGLE);return a.params.x=t,a.params.y=r,a.params.width=i,a.params.height=n,o.Rt(a.state),a.id}ae(t,r,i,n,o,a,h){const l=this.ne(C.CUSTOM);return l.params.x=t,l.params.y=r,l.params.width=i,l.params.height=n,l.params.shader=o,l.params.uniforms=a,h.Rt(l.state),l.id}he(t,r,i,n,o,a){const h=this.ne(C.LINE);return h.params.x1=t,h.params.y1=r,h.params.x2=i,h.params.y2=n,h.params.thickness=o,a.Rt(h.state),h.id}ce(t,r,i,n,o){const a=this.ne(C.ELLIPSE);return a.params.x=t,a.params.y=r,a.params.width=i,a.params.height=n,o.Rt(a.state),a.id}le(t,r,i,n,o,a,h){const l=this.ne(C.ARC);return l.params.x=t,l.params.y=r,l.params.width=i,l.params.height=n,l.params.start=o,l.params.stop=a,h.Rt(l.state),l.id}ue(t,r,i,n,o,a,h){const l=this.ne(C.TRIANGLE);return l.params.x1=t,l.params.y1=r,l.params.x2=i,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.Rt(l.state),l.id}fe(t,r,i,n,o,a,h,l,f,g){const d=this.ne(C.BEZIER_CURVE);return d.params.x1=t,d.params.y1=r,d.params.cp1x=i,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=l,d.params.thickness=f,g.Rt(d.state),d.id}get length(){return this.re}get isEmpty(){return this.re===0}de(){this.re=0}[Symbol.iterator](){let t=0;const r=this.re,i=this.se;return{next:()=>t<r?{value:i[t++],done:!1}:{value:void 0,done:!0}}}}const U=class U{static pe(t,r,i=0){var a,h,l,f,g,d,p,x,m,y;const n=r||new Float32Array(U.FLOATS_PER_INSTANCE);let o=i;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.character[0],n[o++]=t.character[1],n[o++]=t.character[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=t.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=t.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((g=t.bezierControlPoint2)==null?void 0:g[0])||0,n[o++]=((d=t.bezierControlPoint2)==null?void 0:d[1])||0,n[o++]=((p=t.bezierStartPoint)==null?void 0:p[0])||0,n[o++]=((x=t.bezierStartPoint)==null?void 0:x[1])||0,n[o++]=((m=t.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((y=t.bezierEndPoint)==null?void 0:y[1])||0,n}static _e(t){const r=t.length*U.FLOATS_PER_INSTANCE,i=new Float32Array(r);for(let n=0;n<t.length;n++){const o=n*U.FLOATS_PER_INSTANCE;U.pe(t[n],i,o)}return i}};u(U,"BYTES_PER_INSTANCE",140),u(U,"FLOATS_PER_INSTANCE",35);let P=U;const S=class S{};u(S,"STRIDE",P.BYTES_PER_INSTANCE),u(S,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:132,divisor:1}});let $=S;class ht{constructor(t,r=1e3,i=1.5){u(this,"S");u(this,"ge",[]);u(this,"me");u(this,"ve");u(this,"xe",null);u(this,"Ce",!0);u(this,"ye",0);u(this,"we",new Map);u(this,"$e",null);this.S=t,this.me=r,this.ve=i,this.be()}Kt(t){const r=this.ge.length;return this.ge.push(t),this.Ce=!0,r}get count(){return this.ge.length}get isEmpty(){return this.ge.length===0}clear(){this.ge.length=0,this.Ce=!0}ze(t){if(t<=this.me)return;const r=Math.ceil(t*this.ve);this.me=r,this.be()}be(){const t=this.S;this.xe&&t.deleteBuffer(this.xe),this.xe=t.createBuffer();const r=this.me*P.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.xe),t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!0,this.ye=0}Re(){if(!this.Ce||this.ge.length===0)return;const t=this.S,r=this.ge.length;this.ze(r),(!this.$e||this.$e.length<r*P.FLOATS_PER_INSTANCE)&&(this.$e=new Float32Array(r*P.FLOATS_PER_INSTANCE));const i=P._e(this.ge);t.bindBuffer(t.ARRAY_BUFFER,this.xe),r<=this.ye?t.bufferSubData(t.ARRAY_BUFFER,0,i):t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!1,this.ye=r}Te(t){let r=this.we.get(t);if(!r){r=new Map;const i=this.S;for(const n in $.ATTRIBUTES){const o=i.getAttribLocation(t,n);o!==-1&&r.set(n,o)}this.we.set(t,r)}return r}qt(t){if(!this.xe||this.ge.length===0)return;const r=this.S,i=t.ot;this.Re();const n=this.Te(i);r.bindBuffer(r.ARRAY_BUFFER,this.xe);for(const[o,a]of n){const h=$.ATTRIBUTES[o];h&&(r.enableVertexAttribArray(a),r.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),r.vertexAttribDivisor(a,h.divisor))}}Nt(t){const r=this.S,i=this.Te(t.ot);for(const[,n]of i)r.disableVertexAttribArray(n),r.vertexAttribDivisor(n,0)}Zt(t,r){this.ge.length!==0&&this.S.drawArraysInstanced(t,0,r,this.ge.length)}j(){const t=this.S;this.xe&&(t.deleteBuffer(this.xe),this.xe=null),this.ge.length=0,this.we.clear(),this.$e=null}}class M{constructor(t,r,i,n){u(this,"S");u(this,"Se");u(this,"Me");u(this,"Fe");u(this,"Ge",null);this.S=t,this.Se=r,this.Me=i,this.Fe=n;const o=this.S.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.S.bindBuffer(this.S.ARRAY_BUFFER,o),this.S.bufferData(this.S.ARRAY_BUFFER,this.Fe.vertices,this.S.STATIC_DRAW),this.S.bindBuffer(this.S.ARRAY_BUFFER,null),this.Ge=o}get type(){return this.Me}get unitGeometry(){return this.Fe}get unitBuffer(){return this.Ge}get batch(){return this.Se}Qt(){this.Se.clear()}Yt(){return!this.Se.isEmpty}j(){this.Se.j(),this.Ge&&(this.S.deleteBuffer(this.Ge),this.Ge=null)}De(t,r,i,n,o){const a=this.Pe(t,r,i,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,r],size:[i,n],character:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}Ae(t,r){const i=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height];return{nx:t/i[2]*2-1,ny:1-r/i[3]*2}}Be(t,r,i){const n=this.Ae(r,i);t.rotationCenter=[n.nx,n.ny]}Pe(t,r,i,n,o,a,h){const l=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height],f=l[2],g=l[3];return{centerX:(t+i/2)/f*2-1,centerY:1-(r+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/g}}}const ct={vertices:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class lt extends M{constructor(t,r){super(t,r,C.RECTANGLE,ct)}Kt(t,r){const i=this.De(t.x,t.y,t.width,t.height,r);return this.Se.Kt(i)}}const ut={vertices:new Float32Array([0,-.5,0,0,1,-.5,1,0,0,.5,0,1,0,.5,0,1,1,-.5,1,0,1,.5,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class ft extends M{constructor(t,r){super(t,r,C.LINE,ut)}Kt(t,r){const i=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(i,n),a=Math.atan2(n,i),h=t.thickness||r.lineWeight||1,l=t.x1+i/2,f=t.y1+n/2,g=l-o/2,d=f,p={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotationX:r.rotationX||0,rotationY:r.rotationY||0,rotationZ:(r.rotationZ||0)+180*a/Math.PI,lineWeight:h},x=this.De(g,d,o,h,p);return this.Be(x,l,f),this.Se.Kt(x)}}const dt={vertices:function(c=32){const t=[],r=2*Math.PI/c;for(let i=0;i<c;i++){const n=i*r,o=(i+1)%c*r,a=Math.cos(n),h=Math.sin(n),l=.5*(a+1),f=.5*(h+1),g=Math.cos(o),d=Math.sin(o),p=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,a,h,l,f,g,d,p,x)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends M{constructor(t,r){super(t,r,C.ELLIPSE,dt)}Kt(t,r){const i=this.De(t.x,t.y,t.width,t.height,r);return this.Be(i,t.x,t.y),this.Se.Kt(i)}}let gt={vertices:function(c){const t=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;t.push(i,0,i,0,i,1,i,1,n,1,n,1)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class mt extends M{constructor(t,r){super(t,r,C.ARC,gt)}Kt(t,r){const i=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.De(i,n,t.width,t.height,r);return this.Be(h,t.x,t.y),h.arcAngles=[o,a],this.Se.Kt(h)}}const xt={vertices:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),vertexCount:3,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class yt extends M{constructor(t,r){super(t,r,C.TRIANGLE,xt)}Kt(t,r){const i=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),a=n-i,h=Math.max(t.y1,t.y2,t.y3)-o,l=this.De(i,o,a,h,r),f=i+.5*a,g=o+h*(1/3);return this.Be(l,f,g),this.Se.Kt(l)}}function Q(c,t,r,i,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*r+3*o*h*i+h*c*n}const Ct={vertices:function(c=16){const t=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;t.push(i,-.5,i,0),t.push(n,-.5,n,0),t.push(i,.5,i,1),t.push(i,.5,i,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class vt extends M{constructor(t,r){super(t,r,C.BEZIER_CURVE,Ct)}Kt(t,r){const i=r.lineWeight||1,n=Q(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=Q(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotationX:r.rotationX||0,rotationY:r.rotationY||0,rotationZ:r.rotationZ||0,lineWeight:i},h=this.De(0,0,1,i,a);return this.Be(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.Se.Kt(h)}}class St{constructor(t){u(this,"S");u(this,"Ie",null);u(this,"Le",null);u(this,"Ee",{});u(this,"We",null);u(this,"ke",new Map);u(this,"Ue");u(this,"Ve");u(this,"Oe");this.S=t,this.Oe=new st,this.Ue=new ot(t),this.Ve=new at,this.We=t.createBuffer(),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}je(t){let r=this.ke.get(t);if(r)return r;const i=new ht(this.S);return r=(0,{[C.RECTANGLE]:()=>new lt(this.S,i),[C.LINE]:()=>new ft(this.S,i),[C.ELLIPSE]:()=>new pt(this.S,i),[C.ARC]:()=>new mt(this.S,i),[C.TRIANGLE]:()=>new yt(this.S,i),[C.BEZIER_CURVE]:()=>new vt(this.S,i)}[t])(),this.ke.set(t,r),r}He(t){this.Ie!==t&&(this.Ie=t,t.tt())}Xe(t,r){return new V(this.S,t,r)}Ye(t){this.Le=t,t&&(this.Ee={})}qe(t,r){this.Ee[t]=r}Ze(t){Object.assign(this.Ee,t)}Ne(t){return new V(this.S,X,t)}Qe(t,r,i,n){var y;const o=this.S,a=o.canvas.width,h=o.canvas.height,l=t/a*2-1,f=(t+i)/a*2-1,g=1-r/h*2,d=1-(r+n)/h*2,p=new Float32Array([l,d,f,d,l,g,f,d,f,g,l,g]);o.bindBuffer(o.ARRAY_BUFFER,this.We),o.bufferData(o.ARRAY_BUFFER,p,o.DYNAMIC_DRAW);const x=((y=this.Ie)==null?void 0:y.ot)||o.getParameter(o.CURRENT_PROGRAM),m=x?o.getAttribLocation(x,"a_position"):-1;m!==-1&&(o.enableVertexAttribArray(m),o.vertexAttribPointer(m,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),m!==-1&&o.disableVertexAttribArray(m)}Je(t,r,i,n){this.Le?(this.Ve.ae(t,r,i,n,this.Le,{...this.Ee},this.Oe),this.Le=null,this.Ee={}):this.Ve.oe(t,r,i,n,this.Oe)}Ke(t,r,i,n){this.Ve.he(t,r,i,n,this.Oe.lineWeight,this.Oe)}ts(t,r,i,n){this.Ve.ce(t,r,i,n,this.Oe)}es(t,r,i,n,o,a){this.Ve.ue(t,r,i,n,o,a,this.Oe)}ss(t,r,i,n,o,a,h,l){const f=this.Oe.lineWeight;this.Ve.fe(t,r,i,n,o,a,h,l,f,this.Oe)}rs(t,r,i=1,n={}){return new N(this.S,t,r,i,n)}ns(t,r,i,n,o,a){this.Ve.le(t,r,i,n,o,a,this.Oe)}hs(t,r=t,i=t,n=255){this.state.Et(t,r,i,n),this.de(t/255,r/255,i/255,n/255)}de(t=0,r=0,i=0,n=0){this.S.clearColor(t,r,i,n),this.S.clear(this.S.COLOR_BUFFER_BIT)}cs(){this.S.viewport(0,0,this.S.canvas.width,this.S.canvas.height),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}get context(){return this.S}get state(){return this.Oe}ls(t){const r=t,i=D(this.S)??this.S.getParameter(this.S.VIEWPORT),n={shader:r,gl:this.S,viewport:i};this.He(r);const o=new Set;for(const a of this.Ve)a.type===C.CUSTOM?o.add(C.RECTANGLE):o.add(a.type);for(const a of o)a!==C.CUSTOM&&this.je(a);this.Ue.Xt(n,this.Ve,this.ke),this.Ve.de()}j(){this.S.deleteBuffer(this.We),this.Ve.de();for(const t of this.ke.values())t.j()}}const _={readShort:(c,t)=>(_.t.uint16[0]=c[t]<<8|c[t+1],_.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,r){const i=[];for(let n=0;n<r;n++)i.push(_.readUshort(c,t+2*n));return i},readUint(c,t){const r=_.t.uint8;return r[3]=c[t],r[2]=c[t+1],r[1]=c[t+2],r[0]=c[t+3],_.t.uint32[0]},readASCII(c,t,r){let i="";for(let n=0;n<r;n++)i+=String.fromCharCode(c[t+n]);return i},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},Rt={parseTab(c,t,r){const i={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,r),t=0;const n=_,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const p=`p${f}e${g}`;let x=h.indexOf(d);if(x===-1){let m;x=i.tables.length,h.push(d);const y=o(c,d);m=y===4?this.parse4(c,d):y===12?this.parse12(c,d):{format:y},i.tables.push(m)}i.ids[p]!=null&&console.warn("Multiple tables for one platform+encoding: "+p),i.ids[p]=x}return i},parse4(c,t){const r=_,i=r.readUshort,n=r.readUshorts,o=t,a=i(c,t+=2);t+=2;const h=i(c,t+=2)>>>1,l={format:4,searchRange:i(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,l.entrySelector=i(c,t),t+=2,l.rangeShift=i(c,t),t+=2,l.endCount=n(c,t,h),t+=2*h,t+=2,l.startCount=n(c,t,h),t+=2*h;for(let f=0;f<h;f++)l.idDelta.push(r.readShort(c,t)),t+=2;return l.idRangeOffset=n(c,t,h),t+=2*h,l.glyphIdArray=n(c,t,o+a-t>>1),l},parse12(c,t){const r=_.readUint;r(c,t+=4),r(c,t+=4);const i=r(c,t+=4);t+=4;const n=new Uint32Array(3*i);for(let o=0;o<3*i;o+=3)n[o]=r(c,t+(o<<2)),n[o+1]=r(c,t+(o<<2)+4),n[o+2]=r(c,t+(o<<2)+8);return{format:12,groups:n}}},Et={parseTab(c,t,r){const i=_;t+=18;const n=i.readUshort(c,t);t+=2,t+=16;const o=i.readShort(c,t);t+=2;const a=i.readShort(c,t);t+=2;const h=i.readShort(c,t);t+=2;const l=i.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:i.readShort(c,t)}}},bt={parseTab(c,t,r){const i=_;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],l=h==="advanceWidthMax"||h==="numberOfHMetrics"?i.readUshort:i.readShort;o[h]=l(c,t+2*a)}return o}},_t={parseTab(c,t,r,i){const n=_,o=[],a=[],h=i.maxp.numGlyphs,l=i.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<l;)f=n.readUshort(c,t+(d<<2)),g=n.readShort(c,t+(d<<2)+2),o.push(f),a.push(g),d++;for(;d<h;)o.push(f),a.push(g),d++;return{aWidth:o,lsBearing:a}}},Z={cmap:Rt,head:Et,hhea:bt,maxp:{parseTab(c,t,r){const i=_;return i.readUint(c,t),t+=4,{numGlyphs:i.readUshort(c,t)}}},hmtx:_t,loca:{parseTab(c,t,r,i){const n=_,o=[],a=i.head.indexToLocFormat,h=i.maxp.numGlyphs+1;if(a===0)for(let l=0;l<h;l++)o.push(n.readUshort(c,t+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,t+(l<<2)));return o}},glyf:{parseTab(c,t,r,i){const n=[],o=i.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},us(c,t){const r=_,i=c.fs,n=c.loca;if(n[t]===n[t+1])return null;const o=F.findTable(i,"glyf",c.ds);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=r.readShort(i,a),a+=2,h.xMin=r.readShort(i,a),a+=2,h.yMin=r.readShort(i,a),a+=2,h.xMax=r.readShort(i,a),a+=2,h.yMax=r.readShort(i,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let p=0;p<h.noc;p++)h.endPts.push(r.readUshort(i,a)),a+=2;const l=r.readUshort(i,a);if(a+=2,i.length-a<l)return null;a+=l;const f=h.endPts[h.noc-1]+1;h.flags=[];for(let p=0;p<f;p++){const x=i[a];if(a++,h.flags.push(x),8&x){const m=i[a];a++;for(let y=0;y<m;y++)h.flags.push(x),p++}}h.xs=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(16&x);2&x?(h.xs.push(m?i[a]:-i[a]),a++):m?h.xs.push(0):(h.xs.push(r.readShort(i,a)),a+=2)}h.ys=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(32&x);4&x?(h.ys.push(m?i[a]:-i[a]),a++):m?h.ys.push(0):(h.ys.push(r.readShort(i,a)),a+=2)}let g=0,d=0;for(let p=0;p<f;p++)g+=h.xs[p],d+=h.ys[p],h.xs[p]=g,h.ys[p]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},F={parse:c=>[((t,r,i,n)=>{const o=Z,a={fs:t,ps:r,ds:i};for(const h in o){const l=h,f=F.findTable(t,l,i);if(f){const[g,d]=f;let p=n[g];p==null&&(p=o[l].parseTab(t,g,d,a),n[g]=p),a[l]=p}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,r){const i=_,n=i.readUshort(c,r+4);let o=r+12;for(let a=0;a<n;a++){const h=i.readASCII(c,o,4);i.readUint(c,o+4);const l=i.readUint(c,o+8),f=i.readUint(c,o+12);if(h===t)return[l,f];o+=16}return null},T:Z,B:_};class O{constructor(){u(this,"_s",new Map);u(this,"gs",new Map)}vs(t,r){const i=`${this.Cs(t)}_${r}`;if(this._s.has(i))return this._s.get(i);const n=t.cmap;if(!n||!n.tables)return this._s.set(i,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.ws(r,a):a.format===12&&(o=this.$s(r,a)),o>0)break;return this._s.set(i,o),o}bs(t,r){const i=r.codePointAt(0);return i===void 0?0:this.vs(t,i)}zs(t,r){const i=t.hmtx;return i&&i.aWidth&&i.aWidth.length!==0?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}Rs(t,r){const i=r/t.head.unitsPerEm,n=t.hhea.ascender*i,o=t.hhea.descender*i,a=t.hhea.lineGap*i;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:i}}Ts(){this._s.clear(),this.gs.clear()}Cs(t){return`${t.ds}_${t.fs.length}`}ws(t,r){const i=r.endCount.length;let n=-1;for(let o=0;o<i;o++)if(t<=r.endCount[o]){n=o;break}if(n===-1||t<r.startCount[n])return 0;if(r.idRangeOffset[n]===0)return t+r.idDelta[n]&65535;{const o=r.idRangeOffset[n]/2+(t-r.startCount[n])-(i-n);if(o>=0&&o<r.glyphIdArray.length){const a=r.glyphIdArray[o];return a===0?0:a+r.idDelta[n]&65535}}return 0}$s(t,r){const i=r.groups.length/3;for(let n=0;n<i;n++){const o=r.groups[3*n],a=r.groups[3*n+1],h=r.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class wt{constructor(t){u(this,"Ss");this.Ss=t}Ms(t){var i;const r=[];return(i=t.cmap)!=null&&i.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.Fs(n);r.push(...o)}else if(n.format===12){const o=this.Gs(n);r.push(...o)}}),[...new Set(r)]):[]}Ds(t,r){return this.Ss.bs(t,r)>0}Ps(t,r){for(const i of r)if(!this.Ds(t,i))return!1;return!0}As(t,r){return r.filter(i=>this.Ds(t,i))}Bs(t){return t.filter(r=>this.Is(r))}Fs(t){const r=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return r;for(let i=0;i<t.startCount.length;i++){const n=t.startCount[i],o=t.endCount[i];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.Ls(t,a,i)>0)try{const h=String.fromCodePoint(a);r.push(h)}catch{}}}return r}Gs(t){const r=[];if(!t.groups)return r;for(let i=0;i<t.groups.length;i+=3){const n=t.groups[i],o=t.groups[i+1],a=t.groups[i+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const l=String.fromCodePoint(h);r.push(l)}catch{}}return r}Ls(t,r,i){if(t.idRangeOffset[i]===0)return r+t.idDelta[i]&65535;{const n=t.idRangeOffset[i]/2+(r-t.startCount[i])-(t.startCount.length-i);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[i]&65535}}return 0}Is(t){const r=t.codePointAt(0)||0;return!(r>=0&&r<=31&&r!==9&&r!==10&&r!==13||r>=127&&r<=159)}}class Tt{constructor(){u(this,"Es");const t=new O;this.Es=new wt(t)}extractCharacters(t){return this.Es.Ms(t)}filterProblematicCharacters(t){return this.Es.Bs(t)}characterExists(t,r){return this.Es.Ds(t,r)}allCharactersExist(t,r){return this.Es.Ps(t,r)}}class At{constructor(t){u(this,"Ws");u(this,"ks");u(this,"Us");u(this,"Vs");this.Us=t,this.Vs=new O,this.Ws=document.createElement("canvas"),this.ks=this.Ws.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,r,i,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),l=r.width*a,f=r.height*h,g=typeof n=="object"?n:null;this.Os(l,f),this.js(t,r,a,i,g);const d=this.Us.rs(l,f,1,{filter:"nearest"});return d.L(this.Ws),{framebuffer:d,columns:a,rows:h}}Os(t,r){this.Ws.width=t,this.Ws.height=r,this.Ws.style.width=t+"px",this.Ws.style.height=t+"px",this.ks.imageSmoothingEnabled=!1,this.Ws.style.imageRendering="pixelated",this.ks.fillStyle="black",this.ks.fillRect(0,0,t,r),this.ks.textBaseline="top",this.ks.textAlign="left",this.ks.fillStyle="white"}js(t,r,i,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const l=h%i,f=Math.floor(h/i),g=t[h].character,d=this.Hs(o,g);if(!d)continue;const p=g.codePointAt(0)||0,x=this.Vs.vs(o,p),m=this.Xs(o,x)*a,y=l*r.width,w=f*r.height,b=y+.5*r.width,T=w+.5*r.height,A=Math.round(b-.5*r.width),R=Math.round(T-.5*n),B=A+.5*(r.width-m),Jt=R+o.hhea.ascender*a;this.Ys(d,B,Jt,a)}}Hs(t,r){const i=r.codePointAt(0)||0,n=this.Vs.vs(t,i);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(F&&F.T&&F.T.glyf){const o=F.T.glyf.us(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Xs(t,r){const i=t.hmtx;return i&&i.aWidth?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}Ys(t,r,i,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return;this.ks.beginPath();let f=0;for(let g=0;g<h.length;g++){const d=h[g];if(!(d<f)){if(d>=f){const p=r+o[f]*n,x=i-a[f]*n;this.ks.moveTo(p,x);let m=f+1;for(;m<=d;)if(1&l[m]){const y=r+o[m]*n,w=i-a[m]*n;this.ks.lineTo(y,w),m++}else{const y=r+o[m]*n,w=i-a[m]*n;let b=m+1>d?f:m+1;if(1&l[b]){const T=r+o[b]*n,A=i-a[b]*n;this.ks.quadraticCurveTo(y,w,T,A),m=b+1}else{const T=(y+(r+o[b]*n))/2,A=(w+(i-a[b]*n))/2;this.ks.quadraticCurveTo(y,w,T,A),m=b}}this.ks.closePath()}f=d+1}}this.ks.fill()}}class Ft{constructor(){u(this,"Ss");this.Ss=new O}calculateMaxGlyphDimensions(t,r,i){let n=0;const o=this.Ss.Rs(i,r),a=o.lineHeight;for(const h of t){const l=this.Ss.bs(i,h);if(l===0)continue;const f=this.Ss.zs(i,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,r,i){const n=this.Ss.Rs(i,r),o=this.Ss.bs(i,t);return this.Ss.zs(i,o)*n.scale}getFontMetrics(t,r){return this.Ss.Rs(r,t)}Ts(){this.Ss.Ts()}}class Ut{constructor(){u(this,"Vs");this.Vs=new O}createCharacterObjects(t,r){return t.map((i,n)=>{const o=i.codePointAt(0)||0,a=this.qs(n);let h=0;if(r.hmtx&&r.hmtx.aWidth){const l=this.Vs.vs(r,o);l>0&&r.hmtx.aWidth[l]!==void 0&&(h=r.hmtx.aWidth[l])}return{character:i,unicode:o,color:a,advanceWidth:h}})}qs(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Zs(t,r){if(!z.m(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const i=r.find(n=>n.character===t);return i?i.color:[0,0,0]}Ns(t,r){return z.m(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(i=>this.Zs(i,r)||[0,0,0]):[[0,0,0]]}}class K{constructor(t,r=16){u(this,"Qs");u(this,"Js",[]);u(this,"Ks");u(this,"ti",16);u(this,"ei",0);u(this,"si",0);u(this,"ii",{width:0,height:0});u(this,"ri");u(this,"ni");u(this,"oi");u(this,"ai");u(this,"hi");this.ti=r,this.ni=new Tt,this.oi=new At(t),this.ai=new Ft,this.hi=new Ut}async ci(t){let r;if(!t)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(t);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);r=await i.arrayBuffer()}await this.li(r),this.Qs=F.parse(r)[0],await this.ui()}fi(t){if(t===void 0)return this.ti;this.ti=t,this.ii=this.ai.calculateMaxGlyphDimensions(this.Js.map(i=>i.character),this.ti,this.Qs);const r=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=r.framebuffer,this.ei=r.columns,this.si=r.rows}async di(t){try{const r=await fetch(t);if(!r.ok)throw new v(`Failed to load font file: ${r.status} ${r.statusText}`);const i=await r.arrayBuffer();await this.li(i);const n=F.parse(i);if(!n||n.length===0)throw Error("Failed to parse font file");this.Qs=n[0],await this.ui()}catch(r){throw new v("Failed to load font: "+(r instanceof Error?r.message:"Unknown error"),r)}}async li(t){const r=Date.now();this.ri=new FontFace("CustomFont_"+r,t),await this.ri.load(),document.fonts.add(this.ri)}async ui(){const t=this.ni.extractCharacters(this.Qs),r=this.ni.filterProblematicCharacters(t);this.Js=this.hi.createCharacterObjects(r,this.Qs),this.ii=this.ai.calculateMaxGlyphDimensions(r,this.ti,this.Qs);const i=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=i.framebuffer,this.ei=i.columns,this.si=i.rows}Zs(t){return this.hi.Zs(t,this.Js)}Ns(t){return this.hi.Ns(t,this.Js)}j(){this.Ks.j(),document.fonts.delete(this.ri)}get fontFramebuffer(){return this.Ks}get characters(){return this.Js}get textureColumns(){return this.ei}get textureRows(){return this.si}get maxGlyphDimensions(){return this.ii}get fontSize(){return this.ti}get font(){return this.Qs}}class q{constructor(t,r,i){u(this,"pi");u(this,"_i");u(this,"C");u(this,"$");u(this,"gi");u(this,"mi");u(this,"xi");u(this,"Ci");u(this,"yi");this.xi=t,this.Ci=r,this.yi=i,this.zt()}zt(){this.pi=Math.floor(this.xi.width/this.Ci),this._i=Math.floor(this.xi.height/this.yi),this.C=this.pi*this.Ci,this.$=this._i*this.yi,this.gi=Math.floor((this.xi.width-this.C)/2),this.mi=Math.floor((this.xi.height-this.$)/2)}wi(t,r){this.Ci=t,this.yi=r,this.zt()}get cellWidth(){return this.Ci}get cellHeight(){return this.yi}get cols(){return this.pi}get rows(){return this._i}get width(){return this.C}get height(){return this.$}get offsetX(){return this.gi}get offsetY(){return this.mi}}class J{constructor(t={}){u(this,"xi");u(this,"$i");u(this,"bi");t.canvas?(this.xi=t.canvas,this.bi=!1):(this.xi=this.zi(t.width,t.height),this.bi=!0),this.xi.style.imageRendering="pixelated"}zi(t,r){const i=document.createElement("canvas");return i.className="textmodeCanvas",i.style.imageRendering="pixelated",i.width=t||800,i.height=r||600,document.body.appendChild(i),i}W(t,r){this.xi.width=t??this.xi.width,this.xi.height=r??this.xi.height}Ri(){const t=this.xi.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new v("`textmode.js` requires WebGL2 support.");return t}j(){this.$i&&this.$i.disconnect();const t=this.xi.getContext("webgl")||this.xi.getContext("webgl2");if(t){const r=t.getExtension("WEBGL_lose_context");r&&r.loseContext()}this.bi&&this.xi.parentNode&&this.xi.parentNode.removeChild(this.xi)}get canvas(){return this.xi}get width(){return this.xi.width}get height(){return this.xi.height}}class Lt{constructor(t=60){u(this,"Ti");u(this,"Si");u(this,"Mi",null);u(this,"Fi",0);u(this,"Gi",!0);u(this,"Di",0);u(this,"Pi",0);u(this,"Ai",[]);u(this,"Bi",10);u(this,"Ii",0);this.Ti=t,this.Si=1e3/t}start(t){if(!this.Gi)return;this.Fi=performance.now();const r=i=>{if(!this.Gi)return void(this.Mi=null);const n=i-this.Fi;n>=this.Si&&(t(),this.Fi=i-n%this.Si),this.Gi&&(this.Mi=requestAnimationFrame(r))};this.Mi=requestAnimationFrame(r)}stop(){this.Mi&&(cancelAnimationFrame(this.Mi),this.Mi=null)}pause(){this.Gi&&(this.Gi=!1,this.stop())}resume(t){this.Gi||(this.Gi=!0,this.start(t))}frameRate(t,r){if(t===void 0)return this.Di;this.Ti=t,this.Si=1e3/t,this.Gi&&r&&(this.stop(),this.start(r))}measureFrameRate(){const t=performance.now();if(this.Pi>0){const r=t-this.Pi;this.Ai.push(r),this.Ai.length>this.Bi&&this.Ai.shift();const i=this.Ai.reduce((n,o)=>n+o,0)/this.Ai.length;this.Di=1e3/i}this.Pi=t}get isLooping(){return this.Gi}get frameRateLimit(){return this.Ti}get currentFrameRate(){return this.Di}get frameCount(){return this.Ii}set frameCount(t){this.Ii=t}incrementFrame(){this.Ii++}resetFrameCount(){this.Ii=0}}const Pt=c=>class extends c{rotate(t=0,r=0,i=0){this.Us.state.St(t),this.Us.state.Mt(r),this.Us.state.Ft(i)}rotateX(t){this.Us.state.St(t)}rotateY(t){this.Us.state.Mt(t)}rotateZ(t){this.Us.state.Ft(t)}push(){this.Us.state.$t()}pop(){this.Us.state.bt()}rect(t,r,i=1,n=1){this.Us.Je(t,r,i,n)}line(t,r,i,n){this.Us.Ke(t,r,i,n)}lineWeight(t){this.Us.state.Tt(t)}background(t,r=t,i=t,n=255){this.Us.hs(t,r,i,n)}char(t){this.Us.state.Gt(this.Qs.Zs(t))}charColor(t,r,i){this.Us.state.Dt(t,r,i)}cellColor(t,r,i){this.Us.state.Pt(t,r,i)}flipX(t){this.Us.state.At(t)}flipY(t){this.Us.state.Bt(t)}charRotation(t){this.Us.state.Lt(t)}invert(t){this.Us.state.It(t)}clear(){this.Us.hs(0,0,0,0)}ellipse(t,r,i,n){this.Us.ts(t,r,i/2,n/2)}triangle(t,r,i,n,o,a){this.Us.es(t,r,i,n,o,a)}bezierCurve(t,r,i,n,o,a,h,l){this.Us.ss(t,r,i,n,o,a,h,l)}arc(t,r,i,n,o,a){this.Us.ns(t,r,i,n,o,a)}shader(t){this.Us.Ye(t)}setUniform(t,r){this.Us.qe(t,r)}setUniforms(t){this.Us.Ze(t)}createFilterShader(t){return this.Us.Ne(t)}};class j{Li(t){const r=t.k(0),i=t.k(1),n=t.k(2),o=t.k(3);return{characterPixels:r,primaryColorPixels:i,secondaryColorPixels:n,transformPixels:t.k(4),rotationPixels:o}}Ei(t,r){return t[r]+(t[r+1]<<8)}Wi(t,r){return{r:t[r],g:t[r+1],b:t[r+2],a:t[r+3]}}}class Y{ki(t,r){return new Blob([t],{type:r})}Ui(t,r,i){try{const n=this.ki(t,i),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=r,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}Vi(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Oi(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}ji(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Hi(){return"textmode-export-"+this.Vi()}}class It extends j{Xi(t,r,i){const n=t[i]===255,o=t[i+1]===255,a=t[i+2]===255,h=r[i],l=r[i+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+l/255)/255*100)/100}}Yi(t,r,i){return{x:t,y:r,cellX:t*i.cellWidth,cellY:r*i.cellHeight}}qi(t,r){const i=[];let n=0;for(let o=0;o<r.rows;o++)for(let a=0;a<r.cols;a++){const h=4*n,l=this.Ei(t.characterPixels,h);let f=this.Wi(t.primaryColorPixels,h),g=this.Wi(t.secondaryColorPixels,h);const d=this.Xi(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const x=f;f=g,g=x}const p=this.Yi(a,o,r);i.push({charIndex:l,primaryColor:f,secondaryColor:g,transform:d,position:p}),n++}return i}}class Dt{Zi(t,r){const i=t.cmap;for(const n of i.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(r>=o.startCount[a]&&r<=o.endCount[a]){if(o.idRangeOffset[a]===0)return r+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(r-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const l=o.glyphIdArray[h];if(l!==0)return l+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],l=o.groups[a+1],f=o.groups[a+2];if(r>=h&&r<=l)return f+(r-h)}}return 0}Ni(t,r,i,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:i+r.xMin*a,y1:n+-r.yMax*a,x2:i+r.xMax*a,y2:n+-r.yMin*a}),toSVG:()=>this.Qi(r,i,n,a)}}Qi(t,r,i,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return"";let f="",g=0;for(let d=0;d<h.length;d++){const p=h[d];if(!(p<g)){if(p>=g){const x=r+o[g]*n,m=i-a[g]*n;f+=`M${x.toFixed(2)},${m.toFixed(2)}`;let y=g+1;for(;y<=p;)if(1&l[y]){const w=r+o[y]*n,b=i-a[y]*n;f+=`L${w.toFixed(2)},${b.toFixed(2)}`,y++}else{const w=r+o[y]*n,b=i-a[y]*n;let T=y+1>p?g:y+1;if(1&l[T]){const A=r+o[T]*n,R=i-a[T]*n;f+=`Q${w.toFixed(2)},${b.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T+1}else{const A=(w+(r+o[T]*n))/2,R=(b+(i-a[T]*n))/2;f+=`Q${w.toFixed(2)},${b.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T}}f+="Z"}g=p+1}}return f}Ji(t,r,i,n,o){const a=t.codePointAt(0)||0,h=this.Zi(r,a);let l=null;return r.glyf&&r.glyf[h]!==null?l=r.glyf[h]:(l=F.T.glyf.us(r,h),r.glyf[h]=l),this.Ni(r,l,i,n,o)}Ki(t,r,i,n,o,a,h,l){const f=i+(o-l*(h/r.head.unitsPerEm))/2,g=n+(a+.7*h)/2;return this.Ji(t,r,f,g,h).toSVG()||null}}class Mt{constructor(){u(this,"tr");this.tr=new Dt}er(t){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
6
|
+
`,r+="↓".repeat(24)+`
|
|
7
|
+
`,r}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>C.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>C.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${C.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${C.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var P=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(P||{});const D=class D{constructor(){l(this,"u",{globalLevel:3})}static p(){return D.l||(D.l=new D),D.l}_(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.u.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(C.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(C.i(t,i)),console.groupEnd(),!1;default:throw new C(t,i)}}m(t,i,r){return!!t||(this._(i,r),!1)}v(t){this.u.globalLevel=t}};l(D,"l",null);let N=D;const M=N.p(),Z=new WeakMap;function O(c,t){Z.set(c,t)}function I(c){return Z.get(c)}class k{constructor(t,i,r=i,n=1,o={}){l(this,"C");l(this,"$");l(this,"u");l(this,"R",null);l(this,"S");l(this,"P");l(this,"M",[]);l(this,"F");l(this,"A",null);l(this,"D",[]);this.C=i,this.$=r,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.S=t,this.F=Math.min(Math.max(1,n),8);const a=t.getParameter(t.MAX_DRAW_BUFFERS),h=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.F=Math.min(this.F,a,h),this.P=t.createFramebuffer(),this.G(),this.k(),this.D=Array(this.F).fill(null)}G(){const t=this.S,i=this.u.filter==="linear"?t.LINEAR:t.NEAREST,r=this.u.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.u.type==="float"?t.FLOAT:t.UNSIGNED_BYTE;for(let o=0;o<this.F;o++){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.C,this.$,0,t.RGBA,n,null),this.M.push(a)}t.bindTexture(t.TEXTURE_2D,null)}k(){const t=this.S;if(t.bindFramebuffer(t.FRAMEBUFFER,this.P),this.F===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.M[0],0);else{const r=[];for(let n=0;n<this.F;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.M[n],0),r.push(o)}t.drawBuffers(r)}const i=t.checkFramebufferStatus(t.FRAMEBUFFER);i!==t.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",i),t.bindFramebuffer(t.FRAMEBUFFER,null)}L(t){const i=this.S;i.bindTexture(i.TEXTURE_2D,this.M[0]),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null)}I(t,i){this.C=t,this.$=i,this.R=null,this.D=Array(this.F).fill(null);const r=this.S,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.M)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.C,this.$,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}W(t){const i=this.S;if(t<0||t>=this.F)throw Error(`GLFramebuffer: attachment index ${t} out of range (count=${this.F})`);const r=this.D[t];if(r)return r;const n=this.C,o=this.$,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.P),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,a),i.bindFramebuffer(i.READ_FRAMEBUFFER,h);const u=4*n,d=new Uint8Array(a.length);for(let p=0;p<o;p++){const f=(o-1-p)*u,g=p*u;d.set(a.subarray(f,f+u),g)}return this.D[t]=d,d}U(){for(let t=0;t<this.F;t++)this.W(t)}O(){const t=this.S;this.A={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.P),this.D=Array(this.F).fill(null);for(let i=0;i<this.F;i++)t.clearBufferfv(t.COLOR,i,new Float32Array([0,0,0,0]));t.viewport(0,0,this.C,this.$),O(t,[0,0,this.C,this.$])}V(){if(!this.A)return;const t=this.S;t.bindFramebuffer(t.FRAMEBUFFER,this.A.framebuffer),t.viewport(...this.A.viewport),O(t,this.A.viewport),this.A=null}j(){const t=this.S;this.P&&t.deleteFramebuffer(this.P);for(const i of this.M)t.deleteTexture(i);this.M=[],this.D=[]}get width(){return this.C}get height(){return this.$}get pixels(){return this.R}get options(){return{...this.u}}get framebuffer(){return this.P}get texture(){return this.M[0]}get textures(){return[...this.M]}get attachmentCount(){return this.F}getAttachmentPixels(t){return this.D[t]??null}}class X{constructor(t,i,r){l(this,"S");l(this,"H");l(this,"K",new Map);l(this,"X",new Map);l(this,"Y",0);l(this,"N");this.S=t,this.H=this.q(i,r),this.N=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.Z()}Z(){const t=this.S.getProgramParameter(this.H,this.S.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.S.getActiveUniform(this.H,i);if(r){const n=this.S.getUniformLocation(this.H,r.name);n&&(this.K.set(r.name,n),this.X.set(r.name,r.type))}}}q(t,i){const r=this.J(this.S.VERTEX_SHADER,t),n=this.J(this.S.FRAGMENT_SHADER,i),o=this.S.createProgram();if(this.S.attachShader(o,r),this.S.attachShader(o,n),this.S.linkProgram(o),!this.S.getProgramParameter(o,this.S.LINK_STATUS)){const a=this.S.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.S.deleteShader(r),this.S.deleteShader(n),o}J(t,i){const r=this.S.createShader(t);if(this.S.shaderSource(r,i),this.S.compileShader(r),!this.S.getShaderParameter(r,this.S.COMPILE_STATUS)){const n=this.S.getShaderInfoLog(r);throw this.S.deleteShader(r),Error("Shader compilation error: "+n)}return r}tt(){this.S.useProgram(this.H),this.et()}et(){this.Y=0}st(t){for(const[i,r]of Object.entries(t))this.it(i,r)}rt(t){return this.K.has(t)}it(t,i){if(this.S.getParameter(this.S.CURRENT_PROGRAM)!==this.H)return void console.warn(`Attempting to set uniform '${t}' on shader that is not currently bound`);const r=this.K.get(t);if(r)if(typeof i=="number")this.S.uniform1f(r,i);else if(typeof i=="boolean")this.S.uniform1i(r,i?1:0);else if(Array.isArray(i))switch(i.length){case 2:this.S.uniform2f(r,i[0],i[1]);break;case 3:this.S.uniform3f(r,i[0],i[1],i[2]);break;case 4:this.S.uniform4f(r,i[0],i[1],i[2],i[3]);break;default:console.warn(`Unsupported array length ${i.length} for uniform '${t}'`)}else if(i instanceof WebGLTexture){const n=this.nt();this.S.uniform1i(r,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i)}else if(i instanceof k){const n=this.nt();this.S.uniform1i(r,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i.texture)}else if(typeof i=="object"&&"texture"in i){const n=this.nt();this.S.uniform1i(r,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i.texture)}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}nt(){return this.Y>=this.N&&console.warn(`Exceeded maximum texture units (${this.N}). Texture may not render correctly.`),this.Y++}get ot(){return this.H}j(){this.S.deleteProgram(this.H)}}class rt{constructor(){l(this,"ht",1);l(this,"ct",0);l(this,"lt",0);l(this,"ut",0);l(this,"dt",[0,0,0]);l(this,"ft",[1,1,1,1]);l(this,"_t",[0,0,0,1]);l(this,"gt",!1);l(this,"vt",!1);l(this,"yt",!1);l(this,"Ct",[0,0]);l(this,"xt",[0,0,0,1]);l(this,"wt",[])}$t(){this.wt.push({lineWeight:this.ht,rotationX:this.ct,rotationY:this.lt,rotationZ:this.ut,charRotation:[...this.Ct],flipHorizontally:this.gt,flipVertically:this.vt,invert:this.yt,character:[...this.dt],charColor:[...this.ft],cellColor:[...this._t]})}bt(){const t=this.wt.pop();t?(this.ht=t.lineWeight,this.ct=t.rotationX,this.lt=t.rotationY,this.ut=t.rotationZ,this.Ct=t.charRotation,this.gt=t.flipHorizontally,this.vt=t.flipVertically,this.yt=t.invert,this.dt=t.character,this.ft=t.charColor,this._t=t.cellColor):console.warn("pop() called without matching push()")}Rt(){this.wt=[],this.ct=0,this.lt=0,this.ut=0}zt(t){t.lineWeight=this.ht,t.rotationX=this.ct,t.rotationY=this.lt,t.rotationZ=this.ut,t.character[0]=this.dt[0],t.character[1]=this.dt[1],t.character[2]=this.dt[2],t.charColor[0]=this.ft[0],t.charColor[1]=this.ft[1],t.charColor[2]=this.ft[2],t.charColor[3]=this.ft[3],t.bgColor[0]=this._t[0],t.bgColor[1]=this._t[1],t.bgColor[2]=this._t[2],t.bgColor[3]=this._t[3],t.flipHorizontally=this.gt,t.flipVertically=this.vt,t.invert=this.yt,t.charRotation[0]=this.Ct[0],t.charRotation[1]=this.Ct[1]}get lineWeight(){return this.ht}get canvasBackgroundColor(){return this.xt}St(t){this.ht=Math.abs(t)}Tt(t){this.ct=t}Pt(t){this.lt=t}Mt(t){this.ut=t}Ft(t){this.dt=t}At(t,i,r,n=255){this.ft=[t/255,i/255,r/255,n/255]}Dt(t,i,r,n=255){this._t=[t/255,i/255,r/255,n/255]}Gt(t){this.gt=t}kt(t){this.vt=t}Et(t){this.yt=t}Lt(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.Ct=[r,n]}Bt(t,i,r,n){this.xt=[t/255,i/255,r/255,n/255]}}var V=`#version 300 es
|
|
8
|
+
in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 rotateX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0,0,c,-s,0,s,c);}mat3 rotateY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s,0,1,0,-s,0,c);}mat3 rotateZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0,s,c,0,0,0,1);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return u2*u*p0+3.*u2*t*p1+3.*u*t2*p2+t2*t*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return-3.*u2*p0+3.*u2*p1-6.*u*t*p1+6.*u*t*p2-3.*t2*p2+3.*t2*p3;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 worldPosition;bool isBezier=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool isArc=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(isBezier){float t=a_position.x;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tLen=length(tangent);tangent=tLen>0.?tangent/tLen:vec2(1,0);worldPosition=curvePoint+vec2(-tangent.y,tangent.x)*a_position.y*a_instanceSize.y;}else if(isArc){float s=a_instanceArcAngles.x,e=a_instanceArcAngles.y;s=mod(s,6.28318530718);if(s<0.)s+=6.28318530718;e=mod(e,6.28318530718);if(e<0.)e+=6.28318530718;float d=s-e;if(d<=0.)d+=6.28318530718;float angle=s-a_position.x*d;vec2 local=vec2(cos(angle),sin(angle))*a_position.y;worldPosition=local*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{worldPosition=a_position*a_instanceSize+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.-1.;ndc.y=-ndc.y;if(length(a_instanceGlobalRotation)>0.){vec3 pos3D=vec3(ndc-a_instanceRotationCenter,0);pos3D.x*=u_aspectRatio;if(a_instanceGlobalRotation.x!=0.)pos3D=rotateX(-a_instanceGlobalRotation.x)*pos3D;if(a_instanceGlobalRotation.y!=0.)pos3D=rotateY(-a_instanceGlobalRotation.y)*pos3D;if(a_instanceGlobalRotation.z!=0.)pos3D=rotateZ(-a_instanceGlobalRotation.z)*pos3D;pos3D.x/=u_aspectRatio;ndc=pos3D.xy+a_instanceRotationCenter;}gl_Position=vec4(ndc,0,1);}`,v=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(v||{});class nt{constructor(t){l(this,"S");l(this,"It",new Map);this.S=t}Wt(t,i,r,n){const o=this.S;let a=this.It.get(t);a||(a=new Map,this.It.set(t,a));let h=a.get(i)||null;if(!h){h=o.createVertexArray(),a.set(i,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.attributes.position.size,o.FLOAT,!1,r.stride,r.attributes.position.offset),o.vertexAttribDivisor(u,0));const d=o.getAttribLocation(t,"a_texCoord");d!==-1&&(o.enableVertexAttribArray(d),o.vertexAttribPointer(d,r.attributes.texCoord.size,o.FLOAT,!1,r.stride,r.attributes.texCoord.offset),o.vertexAttribDivisor(d,0))}o.bindVertexArray(h)}Ut(){this.S.bindVertexArray(null)}j(){const t=this.S;for(const[,i]of this.It)for(const[,r]of i)r&&t.deleteVertexArray(r);this.It.clear()}}class ot{constructor(t){l(this,"Ot");l(this,"S");l(this,"Vt",null);l(this,"jt",null);l(this,"Ht",null);this.S=t,this.Ot=new nt(t)}Kt(t,i,r){const{shader:n}=t,o=I(this.S)||this.S.getParameter(this.S.VIEWPORT),a={u_aspectRatio:o[2]/o[3],u_viewportSize:[o[2],o[3]]},h={};for(const[f,g]of Object.entries(a))n.rt(f)&&(h[f]=g);Object.keys(h).length>0&&n.st(h);const u=f=>{if(!f||!f.Xt())return;const g=f.unitGeometry,y=f.unitBuffer;try{this.Ot.Wt(n.ot,f.type+"",g,y),f.batch.Yt(n),f.batch.Nt(g.primitiveType,g.vertexCount)}finally{f.batch.qt(n),this.Ot.Ut(),f.Zt()}};let d=null,p=null;for(const f of i){if(f.type===v.CUSTOM){p&&(u(p),d=null,p=null),this.Qt(t,f.params,f.state,r.get(v.RECTANGLE)||null);continue}d!==null&&f.type!==d&&(u(p),d=null,p=null);let g=p;g&&f.type===d||(g=r.get(f.type)||null,p=g,d=f.type),g&&g.Jt(f.params,f.state)}u(p)}Qt(t,i,r,n){if(!n)return;const{x:o,y:a,width:h,height:u,shader:d,uniforms:p}=i,f=this.S;d.tt(),n.Zt();const g=this.te(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)));g.O(),d.tt(),p&&Object.keys(p).length&&d.st(p);{const E=I(f)||f.getParameter(f.VIEWPORT);d.rt("u_aspectRatio")&&d.it("u_aspectRatio",E[2]/E[3]),d.rt("u_viewportSize")&&d.it("u_viewportSize",[E[2],E[3]])}const y={...r,rotationX:0,rotationY:0,rotationZ:0};if(n.Jt({x:0,y:0,width:g.width,height:g.height},y),n.Xt()){const E=n.unitGeometry,z=n.unitBuffer;try{this.Ot.Wt(d.ot,n.type+"",E,z),n.batch.Yt(d),n.batch.Nt(E.primitiveType,E.vertexCount)}finally{n.batch.qt(d),this.Ot.Ut(),n.Zt()}}g.V();const m=this.ee();m.tt(),m.st({u_src0:g.textures[0],u_src1:g.textures[1],u_src2:g.textures[2],u_src3:g.textures[3],u_src4:g.textures[4],u_srcSize:[g.width,g.height]});const x=I(f)||f.getParameter(f.VIEWPORT);m.rt("u_aspectRatio")&&m.it("u_aspectRatio",x[2]/x[3]),m.rt("u_viewportSize")&&m.it("u_viewportSize",[x[2],x[3]]);const b=Math.floor(o),S=Math.floor(a),_=Math.max(1,Math.floor(h)),A=Math.max(1,Math.floor(u));if(n.Jt({x:b,y:S,width:_,height:A},r),n.Xt()){const E=n.unitGeometry,z=n.unitBuffer;try{this.Ot.Wt(m.ot,n.type+"",E,z),n.batch.Yt(m),n.batch.Nt(E.primitiveType,E.vertexCount)}finally{n.batch.qt(m),this.Ot.Ut(),n.Zt()}}t.shader.tt()}ee(){return this.Vt||(this.Vt=new X(this.S,V,`#version 300 es
|
|
9
|
+
precision highp float;in vec2 v_uv;uniform sampler2D u_src0;uniform sampler2D u_src1;uniform sampler2D u_src2;uniform sampler2D u_src3;uniform sampler2D u_src4;uniform vec2 u_srcSize;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 uvTex=v_uv*u_srcSize;vec2 uvQ=(floor(uvTex)+0.5f)/u_srcSize;o_character=texture(u_src0,uvQ);o_primaryColor=texture(u_src1,uvQ);o_secondaryColor=texture(u_src2,uvQ);o_rotation=texture(u_src3,uvQ);o_transform=texture(u_src4,uvQ);}`)),this.Vt}te(t,i){return this.jt&&this.Ht&&this.Ht.w===t&&this.Ht.h===i||(this.jt&&this.jt.j(),this.jt=new k(this.S,t,i,5),this.Ht={w:t,h:i}),this.jt}}class at{constructor(){l(this,"se",[]);l(this,"ie",1);l(this,"re",0)}ne(t){if(this.re>=this.se.length){const r={id:this.ie++,type:t,params:{},state:{lineWeight:1,rotationX:0,rotationY:0,rotationZ:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.se.push(r)}const i=this.se[this.re];switch(i.id=this.ie++,i.type=t,t){case v.RECTANGLE:case v.ELLIPSE:i.params&&"width"in i.params||(i.params={x:0,y:0,width:0,height:0});break;case v.CUSTOM:i.params&&"shader"in i.params||(i.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case v.ARC:i.params&&"start"in i.params||(i.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case v.LINE:i.params&&"x2"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case v.TRIANGLE:i.params&&"x3"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case v.BEZIER_CURVE:i.params&&"cp2y"in i.params||(i.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:i.params||(i.params={})}return this.re++,i}oe(t,i,r,n,o){const a=this.ne(v.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.zt(a.state),a.id}ae(t,i,r,n,o,a,h){const u=this.ne(v.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=a,h.zt(u.state),u.id}he(t,i,r,n,o,a){const h=this.ne(v.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.zt(h.state),h.id}ce(t,i,r,n,o){const a=this.ne(v.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.zt(a.state),a.id}le(t,i,r,n,o,a,h){const u=this.ne(v.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=a,h.zt(u.state),u.id}ue(t,i,r,n,o,a,h){const u=this.ne(v.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=a,h.zt(u.state),u.id}de(t,i,r,n,o,a,h,u,d,p){const f=this.ne(v.BEZIER_CURVE);return f.params.x1=t,f.params.y1=i,f.params.cp1x=r,f.params.cp1y=n,f.params.cp2x=o,f.params.cp2y=a,f.params.x2=h,f.params.y2=u,f.params.thickness=d,p.zt(f.state),f.id}get length(){return this.re}get isEmpty(){return this.re===0}fe(){this.re=0}[Symbol.iterator](){let t=0;const i=this.re,r=this.se;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const L=class L{static pe(t,i,r=0){var a,h,u,d,p,f,g,y,m,x;const n=i||new Float32Array(L.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.character[0],n[o++]=t.character[1],n[o++]=t.character[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((u=t.bezierControlPoint1)==null?void 0:u[0])||0,n[o++]=((d=t.bezierControlPoint1)==null?void 0:d[1])||0,n[o++]=((p=t.bezierControlPoint2)==null?void 0:p[0])||0,n[o++]=((f=t.bezierControlPoint2)==null?void 0:f[1])||0,n[o++]=((g=t.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((y=t.bezierStartPoint)==null?void 0:y[1])||0,n[o++]=((m=t.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((x=t.bezierEndPoint)==null?void 0:x[1])||0,n}static _e(t){const i=t.length*L.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*L.FLOATS_PER_INSTANCE;L.pe(t[n],r,o)}return r}};l(L,"BYTES_PER_INSTANCE",140),l(L,"FLOATS_PER_INSTANCE",35);let U=L;const R=class R{};l(R,"STRIDE",U.BYTES_PER_INSTANCE),l(R,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:132,divisor:1}});let G=R;class ht{constructor(t,i=1e3,r=1.5){l(this,"S");l(this,"ge",[]);l(this,"me");l(this,"ve");l(this,"ye",null);l(this,"Ce",!0);l(this,"xe",0);l(this,"we",new Map);l(this,"$e",null);this.S=t,this.me=i,this.ve=r,this.be()}Jt(t){const i=this.ge.length;return this.ge.push(t),this.Ce=!0,i}get count(){return this.ge.length}get isEmpty(){return this.ge.length===0}clear(){this.ge.length=0,this.Ce=!0}Re(t){if(t<=this.me)return;const i=Math.ceil(t*this.ve);this.me=i,this.be()}be(){const t=this.S;this.ye&&t.deleteBuffer(this.ye),this.ye=t.createBuffer();const i=this.me*U.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ye),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!0,this.xe=0}ze(){if(!this.Ce||this.ge.length===0)return;const t=this.S,i=this.ge.length;this.Re(i),(!this.$e||this.$e.length<i*U.FLOATS_PER_INSTANCE)&&(this.$e=new Float32Array(i*U.FLOATS_PER_INSTANCE));const r=U._e(this.ge);t.bindBuffer(t.ARRAY_BUFFER,this.ye),i<=this.xe?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!1,this.xe=i}Se(t){let i=this.we.get(t);if(!i){i=new Map;const r=this.S;for(const n in G.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.we.set(t,i)}return i}Yt(t){if(!this.ye||this.ge.length===0)return;const i=this.S,r=t.ot;this.ze();const n=this.Se(r);i.bindBuffer(i.ARRAY_BUFFER,this.ye);for(const[o,a]of n){const h=G.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}qt(t){const i=this.S,r=this.Se(t.ot);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Nt(t,i){this.ge.length!==0&&this.S.drawArraysInstanced(t,0,i,this.ge.length)}j(){const t=this.S;this.ye&&(t.deleteBuffer(this.ye),this.ye=null),this.ge.length=0,this.we.clear(),this.$e=null}}class B{constructor(t,i,r,n){l(this,"S");l(this,"Te");l(this,"Pe");l(this,"Me");l(this,"Fe",null);this.S=t,this.Te=i,this.Pe=r,this.Me=n;const o=this.S.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.S.bindBuffer(this.S.ARRAY_BUFFER,o),this.S.bufferData(this.S.ARRAY_BUFFER,this.Me.vertices,this.S.STATIC_DRAW),this.S.bindBuffer(this.S.ARRAY_BUFFER,null),this.Fe=o}get type(){return this.Pe}get unitGeometry(){return this.Me}get unitBuffer(){return this.Fe}get batch(){return this.Te}Zt(){this.Te.clear()}Xt(){return!this.Te.isEmpty}j(){this.Te.j(),this.Fe&&(this.S.deleteBuffer(this.Fe),this.Fe=null)}Ae(t,i,r,n,o){const a=this.De(t,i,r,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,i],size:[r,n],character:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}Ge(t,i){const r=I(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}ke(t,i,r){const n=this.Ge(i,r);t.rotationCenter=[n.nx,n.ny]}De(t,i,r,n,o,a,h){const u=I(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height],d=u[2],p=u[3];return{centerX:(t+r/2)/d*2-1,centerY:1-(i+n/2)/p*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:d/p}}}const ct={vertices:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class lt extends B{constructor(t,i){super(t,i,v.RECTANGLE,ct)}Jt(t,i){const r=this.Ae(t.x,t.y,t.width,t.height,i);return this.Te.Jt(r)}}const ut={vertices:new Float32Array([0,-.5,0,0,1,-.5,1,0,0,.5,0,1,0,.5,0,1,1,-.5,1,0,1,.5,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class dt extends B{constructor(t,i){super(t,i,v.LINE,ut)}Jt(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=Math.atan2(n,r),h=t.thickness||i.lineWeight||1,u=t.x1+r/2,d=t.y1+n/2,p=u-o/2,f=d,g={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:(i.rotationZ||0)+180*a/Math.PI,lineWeight:h},y=this.Ae(p,f,o,h,g);return this.ke(y,u,d),this.Te.Jt(y)}}const ft={vertices:function(c=32){const t=[],i=2*Math.PI/c;for(let r=0;r<c;r++){const n=r*i,o=(r+1)%c*i,a=Math.cos(n),h=Math.sin(n),u=.5*(a+1),d=.5*(h+1),p=Math.cos(o),f=Math.sin(o),g=.5*(p+1),y=.5*(f+1);t.push(0,0,.5,.5,a,h,u,d,p,f,g,y)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends B{constructor(t,i){super(t,i,v.ELLIPSE,ft)}Jt(t,i){const r=this.Ae(t.x,t.y,t.width,t.height,i);return this.ke(r,t.x,t.y),this.Te.Jt(r)}}let gt={vertices:function(c){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class mt extends B{constructor(t,i){super(t,i,v.ARC,gt)}Jt(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.Ae(r,n,t.width,t.height,i);return this.ke(h,t.x,t.y),h.arcAngles=[o,a],this.Te.Jt(h)}}const yt={vertices:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),vertexCount:3,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class xt extends B{constructor(t,i){super(t,i,v.TRIANGLE,yt)}Jt(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),a=n-r,h=Math.max(t.y1,t.y2,t.y3)-o,u=this.Ae(r,o,a,h,i),d=r+.5*a,p=o+h*(1/3);return this.ke(u,d,p),this.Te.Jt(u)}}function H(c,t,i,r,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*i+3*o*h*r+h*c*n}const vt={vertices:function(c=16){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class Ct extends B{constructor(t,i){super(t,i,v.BEZIER_CURVE,vt)}Jt(t,i){const r=i.lineWeight||1,n=H(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=H(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:i.rotationZ||0,lineWeight:r},h=this.Ae(0,0,1,r,a);return this.ke(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.Te.Jt(h)}}class Rt{constructor(t){l(this,"S");l(this,"Ee",null);l(this,"Le",null);l(this,"Be",{});l(this,"Ie",null);l(this,"We",new Map);l(this,"Ue");l(this,"Oe");l(this,"Ve");this.S=t,this.Ve=new rt,this.Ue=new ot(t),this.Oe=new at,this.Ie=t.createBuffer(),O(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}je(t){let i=this.We.get(t);if(i)return i;const r=new ht(this.S);return i=(0,{[v.RECTANGLE]:()=>new lt(this.S,r),[v.LINE]:()=>new dt(this.S,r),[v.ELLIPSE]:()=>new pt(this.S,r),[v.ARC]:()=>new mt(this.S,r),[v.TRIANGLE]:()=>new xt(this.S,r),[v.BEZIER_CURVE]:()=>new Ct(this.S,r)}[t])(),this.We.set(t,i),i}He(t){this.Ee!==t&&(this.Ee=t,t.tt())}Ke(t,i){return new X(this.S,t,i)}Xe(t){this.Le=t,t&&(this.Be={})}Ye(t,i){this.Be[t]=i}Ne(t){Object.assign(this.Be,t)}qe(t){return new X(this.S,V,t)}Ze(t,i,r,n){var x;const o=this.S,a=o.canvas.width,h=o.canvas.height,u=t/a*2-1,d=(t+r)/a*2-1,p=1-i/h*2,f=1-(i+n)/h*2,g=new Float32Array([u,f,d,f,u,p,d,f,d,p,u,p]);o.bindBuffer(o.ARRAY_BUFFER,this.Ie),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const y=((x=this.Ee)==null?void 0:x.ot)||o.getParameter(o.CURRENT_PROGRAM),m=y?o.getAttribLocation(y,"a_position"):-1;m!==-1&&(o.enableVertexAttribArray(m),o.vertexAttribPointer(m,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),m!==-1&&o.disableVertexAttribArray(m)}Qe(t,i,r,n){this.Le?(this.Oe.ae(t,i,r,n,this.Le,{...this.Be},this.Ve),this.Le=null,this.Be={}):this.Oe.oe(t,i,r,n,this.Ve)}Je(t,i,r,n){this.Oe.he(t,i,r,n,this.Ve.lineWeight,this.Ve)}ts(t,i,r,n){this.Oe.ce(t,i,r,n,this.Ve)}es(t,i,r,n,o,a){this.Oe.ue(t,i,r,n,o,a,this.Ve)}ss(t,i,r,n,o,a,h,u){const d=this.Ve.lineWeight;this.Oe.de(t,i,r,n,o,a,h,u,d,this.Ve)}rs(t,i,r=1,n={}){return new k(this.S,t,i,r,n)}ns(t,i,r,n,o,a){this.Oe.le(t,i,r,n,o,a,this.Ve)}hs(t,i=t,r=t,n=255){this.state.Bt(t,i,r,n),this.fe(t/255,i/255,r/255,n/255)}fe(t=0,i=0,r=0,n=0){this.S.clearColor(t,i,r,n),this.S.clear(this.S.COLOR_BUFFER_BIT)}cs(){this.S.viewport(0,0,this.S.canvas.width,this.S.canvas.height),O(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}get context(){return this.S}get state(){return this.Ve}ls(t){const i=t,r=I(this.S)??this.S.getParameter(this.S.VIEWPORT),n={shader:i,gl:this.S,viewport:r};this.He(i);const o=new Set;for(const a of this.Oe)a.type===v.CUSTOM?o.add(v.RECTANGLE):o.add(a.type);for(const a of o)a!==v.CUSTOM&&this.je(a);this.Ue.Kt(n,this.Oe,this.We),this.Oe.fe()}j(){this.S.deleteBuffer(this.Ie),this.Oe.fe();for(const t of this.We.values())t.j()}}const w={readShort:(c,t)=>(w.t.uint16[0]=c[t]<<8|c[t+1],w.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,i){const r=[];for(let n=0;n<i;n++)r.push(w.readUshort(c,t+2*n));return r},readUint(c,t){const i=w.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],w.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},Et={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=w,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let u=0;u<a;u++){const d=o(c,t),p=o(c,t+=2);t+=2;const f=n.readUint(c,t);t+=4;const g=`p${d}e${p}`;let y=h.indexOf(f);if(y===-1){let m;y=r.tables.length,h.push(f);const x=o(c,f);m=x===4?this.parse4(c,f):x===12?this.parse12(c,f):{format:x},r.tables.push(m)}r.ids[g]!=null&&console.warn("Multiple tables for one platform+encoding: "+g),r.ids[g]=y}return r},parse4(c,t){const i=w,r=i.readUshort,n=i.readUshorts,o=t,a=r(c,t+=2);t+=2;const h=r(c,t+=2)>>>1,u={format:4,searchRange:r(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(c,t),t+=2,u.rangeShift=r(c,t),t+=2,u.endCount=n(c,t,h),t+=2*h,t+=2,u.startCount=n(c,t,h),t+=2*h;for(let d=0;d<h;d++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,h),t+=2*h,u.glyphIdArray=n(c,t,o+a-t>>1),u},parse12(c,t){const i=w.readUint;i(c,t+=4),i(c,t+=4);const r=i(c,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(c,t+(o<<2)),n[o+1]=i(c,t+(o<<2)+4),n[o+2]=i(c,t+(o<<2)+8);return{format:12,groups:n}}},Tt={parseTab(c,t,i){const r=w;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:u,indexToLocFormat:r.readShort(c,t)}}},St={parseTab(c,t,i){const r=w;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],u=h==="advanceWidthMax"||h==="numberOfHMetrics"?r.readUshort:r.readShort;o[h]=u(c,t+2*a)}return o}},wt={parseTab(c,t,i,r){const n=w,o=[],a=[],h=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let d=0,p=0,f=0;for(;f<u;)d=n.readUshort(c,t+(f<<2)),p=n.readShort(c,t+(f<<2)+2),o.push(d),a.push(p),f++;for(;f<h;)o.push(d),a.push(p),f++;return{aWidth:o,lsBearing:a}}},K={cmap:Et,head:Tt,hhea:St,maxp:{parseTab(c,t,i){const r=w;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:wt,loca:{parseTab(c,t,i,r){const n=w,o=[],a=r.head.indexToLocFormat,h=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<h;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(a===1)for(let u=0;u<h;u++)o.push(n.readUint(c,t+(u<<2)));return o}},glyf:{parseTab(c,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},us(c,t){const i=w,r=c.ds,n=c.loca;if(n[t]===n[t+1])return null;const o=F.findTable(r,"glyf",c.fs);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=i.readShort(r,a),a+=2,h.xMin=i.readShort(r,a),a+=2,h.yMin=i.readShort(r,a),a+=2,h.xMax=i.readShort(r,a),a+=2,h.yMax=i.readShort(r,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let g=0;g<h.noc;g++)h.endPts.push(i.readUshort(r,a)),a+=2;const u=i.readUshort(r,a);if(a+=2,r.length-a<u)return null;a+=u;const d=h.endPts[h.noc-1]+1;h.flags=[];for(let g=0;g<d;g++){const y=r[a];if(a++,h.flags.push(y),8&y){const m=r[a];a++;for(let x=0;x<m;x++)h.flags.push(y),g++}}h.xs=[];for(let g=0;g<d;g++){const y=h.flags[g],m=!!(16&y);2&y?(h.xs.push(m?r[a]:-r[a]),a++):m?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let g=0;g<d;g++){const y=h.flags[g],m=!!(32&y);4&y?(h.ys.push(m?r[a]:-r[a]),a++):m?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let p=0,f=0;for(let g=0;g<d;g++)p+=h.xs[g],f+=h.ys[g],h.xs[g]=p,h.ys[g]=f}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},F={parse:c=>[((t,i,r,n)=>{const o=K,a={ds:t,ps:i,fs:r};for(const h in o){const u=h,d=F.findTable(t,u,r);if(d){const[p,f]=d;let g=n[p];g==null&&(g=o[u].parseTab(t,p,f,a),n[p]=g),a[u]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,i){const r=w,n=r.readUshort(c,i+4);let o=i+12;for(let a=0;a<n;a++){const h=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),d=r.readUint(c,o+12);if(h===t)return[u,d];o+=16}return null},T:K,B:w};class W{constructor(){l(this,"_s",new Map);l(this,"gs",new Map)}vs(t,i){const r=`${this.Cs(t)}_${i}`;if(this._s.has(r))return this._s.get(r);const n=t.cmap;if(!n||!n.tables)return this._s.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.ws(i,a):a.format===12&&(o=this.$s(i,a)),o>0)break;return this._s.set(r,o),o}bs(t,i){const r=i.codePointAt(0);return r===void 0?0:this.vs(t,r)}Rs(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}zs(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:r}}Ss(){this._s.clear(),this.gs.clear()}Cs(t){return`${t.fs}_${t.ds.length}`}ws(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const a=i.glyphIdArray[o];return a===0?0:a+i.idDelta[n]&65535}}return 0}$s(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],a=i.groups[3*n+1],h=i.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class bt{constructor(t){l(this,"Ts");this.Ts=t}Ps(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.Ms(n);i.push(...o)}else if(n.format===12){const o=this.Fs(n);i.push(...o)}}),[...new Set(i)]):[]}As(t,i){return this.Ts.bs(t,i)>0}Ds(t,i){for(const r of i)if(!this.As(t,r))return!1;return!0}Gs(t,i){return i.filter(r=>this.As(t,r))}ks(t){return t.filter(i=>this.Es(i))}Ms(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.Ls(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}Fs(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],a=t.groups[r+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const u=String.fromCodePoint(h);i.push(u)}catch{}}return i}Ls(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}Es(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class _t{constructor(){l(this,"Bs");const t=new W;this.Bs=new bt(t)}extractCharacters(t){return this.Bs.Ps(t)}filterProblematicCharacters(t){return this.Bs.ks(t)}characterExists(t,i){return this.Bs.As(t,i)}allCharactersExist(t,i){return this.Bs.Ds(t,i)}}class At{constructor(t){l(this,"Is");l(this,"Ws");l(this,"Us");l(this,"Os");this.Us=t,this.Os=new W,this.Is=document.createElement("canvas"),this.Ws=this.Is.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),u=i.width*a,d=i.height*h,p=typeof n=="object"?n:null;this.Vs(u,d),this.js(t,i,a,r,p);const f=this.Us.rs(u,d,1,{filter:"nearest"});return f.L(this.Is),{framebuffer:f,columns:a,rows:h}}Vs(t,i){this.Is.width=t,this.Is.height=i,this.Is.style.width=t+"px",this.Is.style.height=t+"px",this.Ws.imageSmoothingEnabled=!1,this.Is.style.imageRendering="pixelated",this.Ws.fillStyle="black",this.Ws.fillRect(0,0,t,i),this.Ws.textBaseline="top",this.Ws.textAlign="left",this.Ws.fillStyle="white"}js(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const u=h%r,d=Math.floor(h/r),p=t[h].character,f=this.Hs(o,p);if(!f)continue;const g=p.codePointAt(0)||0,y=this.Os.vs(o,g),m=this.Ks(o,y)*a,x=u*i.width,b=d*i.height,S=x+.5*i.width,_=b+.5*i.height,A=Math.round(S-.5*i.width),E=Math.round(_-.5*n),z=A+.5*(i.width-m),se=E+o.hhea.ascender*a;this.Xs(f,z,se,a)}}Hs(t,i){const r=i.codePointAt(0)||0,n=this.Os.vs(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(F&&F.T&&F.T.glyf){const o=F.T.glyf.us(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Ks(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Xs(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return;this.Ws.beginPath();let d=0;for(let p=0;p<h.length;p++){const f=h[p];if(!(f<d)){if(f>=d){const g=i+o[d]*n,y=r-a[d]*n;this.Ws.moveTo(g,y);let m=d+1;for(;m<=f;)if(1&u[m]){const x=i+o[m]*n,b=r-a[m]*n;this.Ws.lineTo(x,b),m++}else{const x=i+o[m]*n,b=r-a[m]*n;let S=m+1>f?d:m+1;if(1&u[S]){const _=i+o[S]*n,A=r-a[S]*n;this.Ws.quadraticCurveTo(x,b,_,A),m=S+1}else{const _=(x+(i+o[S]*n))/2,A=(b+(r-a[S]*n))/2;this.Ws.quadraticCurveTo(x,b,_,A),m=S}}this.Ws.closePath()}d=f+1}}this.Ws.fill()}}class Ft{constructor(){l(this,"Ts");this.Ts=new W}calculateMaxGlyphDimensions(t,i,r){let n=0;const o=this.Ts.zs(r,i),a=o.lineHeight;for(const h of t){const u=this.Ts.bs(r,h);if(u===0)continue;const d=this.Ts.Rs(r,u)*o.scale;n=Math.max(n,d)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,i,r){const n=this.Ts.zs(r,i),o=this.Ts.bs(r,t);return this.Ts.Rs(r,o)*n.scale}getFontMetrics(t,i){return this.Ts.zs(i,t)}Ss(){this.Ts.Ss()}}class Lt{constructor(){l(this,"Os");this.Os=new W}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.Ys(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.Os.vs(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(h=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:a,advanceWidth:h}})}Ys(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Ns(t,i){if(!M.m(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}qs(t,i){return M.m(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Ns(r,i)||[0,0,0]):[[0,0,0]]}}class J{constructor(t,i=16){l(this,"Zs");l(this,"Qs",[]);l(this,"Js");l(this,"ti",16);l(this,"ei",0);l(this,"si",0);l(this,"ii",{width:0,height:0});l(this,"ri");l(this,"ni");l(this,"oi");l(this,"ai");l(this,"hi");this.ti=i,this.ni=new _t,this.oi=new At(t),this.ai=new Ft,this.hi=new Lt}async ci(t){let i;if(!t)throw new C("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new C(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.li(i),this.Zs=F.parse(i)[0],await this.ui()}di(t){if(t===void 0)return this.ti;this.ti=t,this.ii=this.ai.calculateMaxGlyphDimensions(this.Qs.map(r=>r.character),this.ti,this.Zs);const i=this.oi.createTextureAtlas(this.Qs,this.ii,this.ti,this.Zs);this.Js=i.framebuffer,this.ei=i.columns,this.si=i.rows}async fi(t){try{const i=await fetch(t);if(!i.ok)throw new C(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.li(r);const n=F.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Zs=n[0],await this.ui()}catch(i){throw new C("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async li(t){const i=Date.now();this.ri=new FontFace("CustomFont_"+i,t),await this.ri.load(),document.fonts.add(this.ri)}async ui(){const t=this.ni.extractCharacters(this.Zs),i=this.ni.filterProblematicCharacters(t);this.Qs=this.hi.createCharacterObjects(i,this.Zs),this.ii=this.ai.calculateMaxGlyphDimensions(i,this.ti,this.Zs);const r=this.oi.createTextureAtlas(this.Qs,this.ii,this.ti,this.Zs);this.Js=r.framebuffer,this.ei=r.columns,this.si=r.rows}Ns(t){return this.hi.Ns(t,this.Qs)}qs(t){return this.hi.qs(t,this.Qs)}j(){this.Js.j(),document.fonts.delete(this.ri)}get fontFramebuffer(){return this.Js}get characters(){return this.Qs}get textureColumns(){return this.ei}get textureRows(){return this.si}get maxGlyphDimensions(){return this.ii}get fontSize(){return this.ti}get font(){return this.Zs}}class q{constructor(t,i,r){l(this,"pi");l(this,"_i");l(this,"C");l(this,"$");l(this,"gi");l(this,"mi");l(this,"yi");l(this,"Ci");l(this,"xi");this.yi=t,this.Ci=i,this.xi=r,this.Rt()}Rt(){this.pi=Math.floor(this.yi.width/this.Ci),this._i=Math.floor(this.yi.height/this.xi),this.C=this.pi*this.Ci,this.$=this._i*this.xi,this.gi=Math.floor((this.yi.width-this.C)/2),this.mi=Math.floor((this.yi.height-this.$)/2)}wi(t,i){this.Ci=t,this.xi=i,this.Rt()}get cellWidth(){return this.Ci}get cellHeight(){return this.xi}get cols(){return this.pi}get rows(){return this._i}get width(){return this.C}get height(){return this.$}get offsetX(){return this.gi}get offsetY(){return this.mi}}class Q{constructor(t={}){l(this,"yi");l(this,"$i");l(this,"bi");t.canvas?(this.yi=t.canvas,this.bi=!1):(this.yi=this.Ri(t.width,t.height),this.bi=!0),this.yi.style.imageRendering="pixelated"}Ri(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}I(t,i){this.yi.width=t??this.yi.width,this.yi.height=i??this.yi.height}zi(){const t=this.yi.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new C("`textmode.js` requires WebGL2 support.");return t}j(){this.$i&&this.$i.disconnect();const t=this.yi.getContext("webgl")||this.yi.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.bi&&this.yi.parentNode&&this.yi.parentNode.removeChild(this.yi)}get canvas(){return this.yi}get width(){return this.yi.width}get height(){return this.yi.height}}class Pt{constructor(t=60){l(this,"Si");l(this,"Ti");l(this,"Pi",null);l(this,"Mi",0);l(this,"Fi",!0);l(this,"Ai",0);l(this,"Di",0);l(this,"Gi",[]);l(this,"ki",10);l(this,"Ei",0);this.Si=t,this.Ti=1e3/t}start(t){if(!this.Fi)return;this.Mi=performance.now();const i=r=>{if(!this.Fi)return void(this.Pi=null);const n=r-this.Mi;n>=this.Ti&&(t(),this.Mi=r-n%this.Ti),this.Fi&&(this.Pi=requestAnimationFrame(i))};this.Pi=requestAnimationFrame(i)}stop(){this.Pi&&(cancelAnimationFrame(this.Pi),this.Pi=null)}pause(){this.Fi&&(this.Fi=!1,this.stop())}resume(t){this.Fi||(this.Fi=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Ai;this.Si=t,this.Ti=1e3/t,this.Fi&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Di>0){const i=t-this.Di;this.Gi.push(i),this.Gi.length>this.ki&&this.Gi.shift();const r=this.Gi.reduce((n,o)=>n+o,0)/this.Gi.length;this.Ai=1e3/r}this.Di=t}get isLooping(){return this.Fi}get frameRateLimit(){return this.Si}get currentFrameRate(){return this.Ai}get frameCount(){return this.Ei}set frameCount(t){this.Ei=t}incrementFrame(){this.Ei++}resetFrameCount(){this.Ei=0}}class Ut{constructor(t){l(this,"yi");l(this,"Li");l(this,"Bi",{x:-1,y:-1});l(this,"Ii",{x:-1,y:-1});l(this,"Wi",null);l(this,"Ui");l(this,"Oi");l(this,"Vi");l(this,"ji");l(this,"Hi");l(this,"Ki");l(this,"Xi",!1);l(this,"Yi");l(this,"Ni");l(this,"qi");l(this,"Zi");l(this,"Qi");this.yi=t}ci(t){this.Li=t,this.Ji()}tr(){if(this.Xi)return;const t=this.yi.canvas;this.Ui=i=>{this.er(i),this.sr(i)},this.Oi=()=>{this.Ii={...this.Bi},this.Bi.x=-1,this.Bi.y=-1,this.Wi=null},this.Vi=i=>{this.er(i),this.ir(i)},this.ji=i=>{this.er(i),this.rr(i)},this.Hi=i=>{this.er(i),this.nr(i)},this.Ki=i=>{this.er(i),this.ar(i)},t.addEventListener("mousemove",this.Ui,{passive:!0}),t.addEventListener("mouseleave",this.Oi,{passive:!0}),t.addEventListener("mousedown",this.Vi,{passive:!0}),t.addEventListener("mouseup",this.ji,{passive:!0}),t.addEventListener("click",this.Hi,{passive:!0}),t.addEventListener("wheel",this.Ki,{passive:!1}),this.Xi=!0}hr(){if(!this.Xi)return;const t=this.yi.canvas;t.removeEventListener("mousemove",this.Ui),t.removeEventListener("mouseleave",this.Oi),t.removeEventListener("mousedown",this.Vi),t.removeEventListener("mouseup",this.ji),t.removeEventListener("click",this.Hi),t.removeEventListener("wheel",this.Ki),this.Xi=!1}Ji(){if(this.Xi)try{if(this.Wi){const t=new MouseEvent("mousemove",{clientX:this.Wi.x,clientY:this.Wi.y,bubbles:!1,cancelable:!1});this.er(t)}else this.Bi.x!==-1&&this.Bi.y!==-1&&(this.Bi.x>=this.Li.cols||this.Bi.y>=this.Li.rows)&&(this.Bi.x=-1,this.Bi.y=-1)}catch{this.Bi.x=-1,this.Bi.y=-1}}cr(t){this.Yi=t}lr(t){this.Ni=t}ur(t){this.qi=t}dr(t){this.Zi=t}pr(t){this.Qi=t}_r(){return{x:this.Bi.x,y:this.Bi.y}}sr(t){if(this.Zi){const i={position:{...this.Bi},previousPosition:{...this.Ii},originalEvent:t};this.Zi(i)}}ir(t){if(this.Ni){const i={position:{...this.Bi},previousPosition:{...this.Ii},button:t.button,originalEvent:t};this.Ni(i)}}rr(t){if(this.qi){const i={position:{...this.Bi},previousPosition:{...this.Ii},button:t.button,originalEvent:t};this.qi(i)}}nr(t){if(this.Yi){const i={position:{...this.Bi},previousPosition:{...this.Ii},button:t.button,originalEvent:t};this.Yi(i)}}ar(t){if(this.Qi){const i={position:{...this.Bi},previousPosition:{...this.Ii},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.Qi(i)}}er(t){const i=this.yi.canvas;this.Ii={...this.Bi},this.Wi={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,a=i.width/r.width,h=o*(i.height/r.height),u=n*a-this.Li.offsetX,d=h-this.Li.offsetY,p=Math.floor(u/this.Li.cellWidth),f=Math.floor(d/this.Li.cellHeight);p>=0&&p<this.Li.cols&&f>=0&&f<this.Li.rows?(this.Bi.x=p,this.Bi.y=f):(this.Bi.x=-1,this.Bi.y=-1)}}class Dt{constructor(){l(this,"gr",new Map);l(this,"mr",null);l(this,"vr",null);l(this,"yr");l(this,"Cr");l(this,"Xi",!1);l(this,"wr");l(this,"$r");l(this,"br",{ArrowUp:"UP_ARROW",ArrowDown:"DOWN_ARROW",ArrowLeft:"LEFT_ARROW",ArrowRight:"RIGHT_ARROW",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",Enter:"ENTER",Return:"RETURN",Tab:"TAB",Escape:"ESCAPE",Backspace:"BACKSPACE",Delete:"DELETE",Insert:"INSERT",Home:"HOME",End:"END",PageUp:"PAGE_UP",PageDown:"PAGE_DOWN",Shift:"SHIFT",Control:"CONTROL",Alt:"ALT",Meta:"META"," ":"SPACE"})}tr(){this.Xi||(this.yr=t=>{this.Rr(t)},this.Cr=t=>{this.zr(t)},window.addEventListener("keydown",this.yr,{passive:!1}),window.addEventListener("keyup",this.Cr,{passive:!1}),this.Xi=!0)}hr(){this.Xi&&(window.removeEventListener("keydown",this.yr),window.removeEventListener("keyup",this.Cr),this.Xi=!1,this.gr.clear(),this.mr=null,this.vr=null)}lr(t){this.wr=t}ur(t){this.$r=t}Sr(t){const i=this.Tr(t),r=this.gr.get(t)||this.gr.get(i);return(r==null?void 0:r.isPressed)||!1}Pr(){return this.mr}Mr(){return this.vr}Fr(){const t=[];for(const[i,r]of this.gr)r.isPressed&&t.push(i);return t}Ar(){return{ctrl:this.Sr("Control"),shift:this.Sr("Shift"),alt:this.Sr("Alt"),meta:this.Sr("Meta")}}Dr(){this.gr.clear(),this.mr=null,this.vr=null}Rr(t){const i=t.key,r=Date.now();this.gr.has(i)||this.gr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.gr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.mr=i,this.wr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.wr(o)}}zr(t){const i=t.key,r=Date.now();this.gr.has(i)||this.gr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.gr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.vr=i,this.$r){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.$r(o)}}Tr(t){return this.br[t]||t.toLowerCase()}}const It=c=>class extends c{rotate(t=0,i=0,r=0){this.Us.state.Tt(t),this.Us.state.Pt(i),this.Us.state.Mt(r)}rotateX(t){this.Us.state.Tt(t)}rotateY(t){this.Us.state.Pt(t)}rotateZ(t){this.Us.state.Mt(t)}push(){this.Us.state.$t()}pop(){this.Us.state.bt()}rect(t,i,r=1,n=1){this.Us.Qe(t,i,r,n)}point(t,i){this.Us.Qe(t,i,1,1)}line(t,i,r,n){this.Us.Je(t,i,r,n)}lineWeight(t){this.Us.state.St(t)}background(t,i=t,r=t,n=255){this.Us.hs(t,i,r,n)}char(t){this.Us.state.Ft(this.Zs.Ns(t))}charColor(t,i,r){this.Us.state.At(t,i,r)}cellColor(t,i,r){this.Us.state.Dt(t,i,r)}flipX(t){this.Us.state.Gt(t)}flipY(t){this.Us.state.kt(t)}charRotation(t){this.Us.state.Lt(t)}invert(t){this.Us.state.Et(t)}clear(){this.Us.hs(0,0,0,0)}ellipse(t,i,r,n){this.Us.ts(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.Us.es(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,u){this.Us.ss(t,i,r,n,o,a,h,u)}arc(t,i,r,n,o,a){this.Us.ns(t,i,r,n,o,a)}shader(t){this.Us.Xe(t)}setUniform(t,i){this.Us.Ye(t,i)}setUniforms(t){this.Us.Ne(t)}createFilterShader(t){return this.Us.qe(t)}};class Y{Gr(t){const i=t.W(0),r=t.W(1),n=t.W(2),o=t.W(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.W(4),rotationPixels:o}}kr(t,i){return t[i]+(t[i+1]<<8)}Er(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class j{Lr(t,i){return new Blob([t],{type:i})}Br(t,i,r){try{const n=this.Lr(t,r),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=i,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}Ir(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Wr(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}Ur(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Or(){return"textmode-export-"+this.Ir()}}class Bt extends Y{Vr(t,i,r){const n=t[r]===255,o=t[r+1]===255,a=t[r+2]===255,h=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+u/255)/255*100)/100}}jr(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Hr(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let a=0;a<i.cols;a++){const h=4*n,u=this.kr(t.characterPixels,h);let d=this.Er(t.primaryColorPixels,h),p=this.Er(t.secondaryColorPixels,h);const f=this.Vr(t.transformPixels,t.rotationPixels,h);if(f.isInverted){const y=d;d=p,p=y}const g=this.jr(a,o,i);r.push({charIndex:u,primaryColor:d,secondaryColor:p,transform:f,position:g}),n++}return r}}class Mt{Kr(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(i>=o.startCount[a]&&i<=o.endCount[a]){if(o.idRangeOffset[a]===0)return i+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(i-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const u=o.glyphIdArray[h];if(u!==0)return u+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],u=o.groups[a+1],d=o.groups[a+2];if(i>=h&&i<=u)return d+(i-h)}}return 0}Xr(t,i,r,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*a,y1:n+-i.yMax*a,x2:r+i.xMax*a,y2:n+-i.yMin*a}),toSVG:()=>this.Yr(i,r,n,a)}}Yr(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return"";let d="",p=0;for(let f=0;f<h.length;f++){const g=h[f];if(!(g<p)){if(g>=p){const y=i+o[p]*n,m=r-a[p]*n;d+=`M${y.toFixed(2)},${m.toFixed(2)}`;let x=p+1;for(;x<=g;)if(1&u[x]){const b=i+o[x]*n,S=r-a[x]*n;d+=`L${b.toFixed(2)},${S.toFixed(2)}`,x++}else{const b=i+o[x]*n,S=r-a[x]*n;let _=x+1>g?p:x+1;if(1&u[_]){const A=i+o[_]*n,E=r-a[_]*n;d+=`Q${b.toFixed(2)},${S.toFixed(2)} ${A.toFixed(2)},${E.toFixed(2)}`,x=_+1}else{const A=(b+(i+o[_]*n))/2,E=(S+(r-a[_]*n))/2;d+=`Q${b.toFixed(2)},${S.toFixed(2)} ${A.toFixed(2)},${E.toFixed(2)}`,x=_}}d+="Z"}p=g+1}}return d}Nr(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.Kr(i,a);let u=null;return i.glyf&&i.glyf[h]!==null?u=i.glyf[h]:(u=F.T.glyf.us(i,h),i.glyf[h]=u),this.Xr(i,u,r,n,o)}qr(t,i,r,n,o,a,h,u){const d=r+(o-u*(h/i.head.unitsPerEm))/2,p=n+(a+.7*h)/2;return this.Nr(t,i,d,p,h).toSVG()||null}}class zt{constructor(){l(this,"Zr");this.Zr=new Mt}Qr(t){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
10
10
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
11
11
|
<svg width="${t.width}" height="${t.height}" viewBox="0 0 ${t.width} ${t.height}"
|
|
12
12
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
13
13
|
<title>textmode art generated via textmode.js</title>
|
|
14
|
-
<desc>textmode art visualization generated by textmode.js library</desc>`}
|
|
14
|
+
<desc>textmode art visualization generated by textmode.js library</desc>`}Jr(){return`
|
|
15
15
|
</g>
|
|
16
|
-
</svg>`}
|
|
17
|
-
<rect width="${t.width}" height="${t.height}" fill="${n}" />`}
|
|
18
|
-
<rect x="${n.cellX}" y="${n.cellY}" width="${
|
|
19
|
-
<rect x="${n.cellX}" y="${n.cellY}" width="${
|
|
16
|
+
</svg>`}tn(t,i){if(!i.includeBackgroundRectangles)return"";const r=i.backgroundColor,n=`rgba(${r[0]},${r[1]},${r[2]},${r[3]/255})`;return`
|
|
17
|
+
<rect width="${t.width}" height="${t.height}" fill="${n}" />`}en(t){return`rgba(${t.r},${t.g},${t.b},${t.a/255})`}sn(t,i){const{transform:r,position:n}=t,o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,d=r.flipVertical?-1:1;h.push(`translate(${o} ${a})`),h.push(`scale(${u} ${d})`),h.push(`translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),h.length?` transform="${h.join(" ")}"`:""}rn(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,o=this.en(t.secondaryColor);return r.drawMode==="stroke"?`
|
|
18
|
+
<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${o}" fill="none" stroke-width="${r.strokeWidth}" />`:`
|
|
19
|
+
<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${o}" />`}Nr(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.Zr.qr(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const h=this.en(t.primaryColor);return n.drawMode==="stroke"?`
|
|
20
20
|
<path id="${`path-${t.charIndex}-${t.position.cellX}-${t.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${n.strokeWidth}" fill="none" />`:`
|
|
21
|
-
<path d="${a}" fill="${h}" />`}
|
|
21
|
+
<path d="${a}" fill="${h}" />`}nn(t,i,r,n){let o="";o+=this.rn(t,i,n);const a=this.sn(t,i),h=this.Nr(t,i,r,n);return h&&(a?(o+=`
|
|
22
22
|
<g${a}>`,o+=h,o+=`
|
|
23
|
-
</g>`):o+=h),o}
|
|
24
|
-
<g id="ascii-cells">`;for(const a of t)o+=this.
|
|
25
|
-
`).replace(/[ \t]+$/gm,"")}}class
|
|
23
|
+
</g>`):o+=h),o}an(t,i,r,n){let o=this.Qr(i);o+=this.tn(i,n),o+=`
|
|
24
|
+
<g id="ascii-cells">`;for(const a of t)o+=this.nn(a,i,r,n);return o+=this.Jr(),o}hn(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
25
|
+
`).replace(/[ \t]+$/gm,"")}}class Ot extends j{cn(t){return this.Lr(t,"image/svg+xml;charset=utf-8")}ln(t,i){this.Br(t,this.Ur(i)+".svg","image/svg+xml;charset=utf-8")}un(t,i){this.ln(t,i||this.Or())}}class tt{constructor(){l(this,"dn");l(this,"fn");l(this,"pn");this.dn=new Bt,this.fn=new zt,this.pn=new Ot}_n(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.pn.Or()}}gn(t,i={}){const r=this.dn.Hr(this.dn.Gr(t.pipeline),t.grid),n=this.fn.an(r,t.grid,t.font,this._n(i));return this.fn.hn(n)}un(t,i={}){this.pn.un(this.gn(t,i),i.filename)}}class Gt extends Y{mn(t,i,r,n=" "){var h;const o=[];let a=0;for(let u=0;u<i.rows;u++){const d=[];for(let p=0;p<i.cols;p++){const f=4*a,g=this.kr(t.characterPixels,f),y=((h=r.characters[g])==null?void 0:h.character)||n;d.push(y),a++}o.push(d)}return o}}class Wt{vn(t,i){const r=[];for(const o of t){let a=o.join("");i.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),r.push(a)}const n=i.lineEnding==="crlf"?`\r
|
|
26
26
|
`:`
|
|
27
|
-
`;return
|
|
28
|
-
precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`),this.
|
|
27
|
+
`;return r.join(n)}}class $t extends j{yn(t,i){const r=this.Cn(i);this.Br(t,r,"text/plain;charset=utf-8")}Cn(t){let i=this.Ur(t);return i===".txt"||i.length<=4?this.Or():i}}class et{constructor(){l(this,"dn");l(this,"fn");l(this,"pn");this.dn=new Gt,this.fn=new Wt,this.pn=new $t}_n(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.pn.Or()}}xn(t,i={}){const r=this._n(i),n=this.dn.mn(this.dn.Gr(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.fn.vn(n,r)}yn(t,i={}){this.pn.yn(this.xn(t,i),i.filename)}}class Nt extends Y{wn(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),a=o.getContext("2d"),h=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=h,o.height=u,r!=="transparent"&&(a.fillStyle=r,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(n,0,0,n.width,n.height,0,0,h,u),o}}class kt{$n(t,i){const r=this.bn(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async Rn(t,i){return new Promise((r,n)=>{const o=this.bn(i.format),a=h=>{h?r(h):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(a,o):t.toBlob(a,o,i.quality)})}bn(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const Xt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},it={png:".png",jpg:".jpg",webp:".webp"};class Vt extends j{zn(t,i,r){this.Sn(t,this.Ur(i)+it[r])}Sn(t,i){const r=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=r,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(r)}}Tn(t){return t in Xt&&t in it}}class Yt{constructor(){l(this,"dn");l(this,"fn");l(this,"pn");this.dn=new Nt,this.fn=new kt,this.pn=new Vt}_n(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.pn.Or()}}Pn(t){if(!this.pn.Tn(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async Rn(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.fn.Rn(t.canvas,i);const r=this.dn.wn(t,i.scale,i.backgroundColor);return await this.fn.Rn(r,i)}async zn(t,i={}){const r=this._n(i);this.Pn(r);const n=await this.Rn(t,r);this.pn.zn(n,r.filename,r.format)}}const jt=c=>class extends c{Mn(){this.Us.ls(this.Fn)}toString(t={}){return this.Mn(),new et().xn({pipeline:this.An,grid:this.Li,font:this.Zs},t)}saveStrings(t={}){this.Mn(),new et().yn({pipeline:this.An,grid:this.Li,font:this.Zs},t)}toSVG(t={}){return this.Mn(),new tt().gn({pipeline:this.An,grid:this.Li,font:this.Zs},t)}saveSVG(t={}){this.Mn(),new tt().un({pipeline:this.An,grid:this.Li,font:this.Zs},t)}async saveCanvas(t={}){await new Yt().zn(this.yi,t)}},Zt=c=>class extends c{async loadFont(t){return this.Zs.fi(t).then(()=>{const i=this.Zs.maxGlyphDimensions;this.Li.wi(i.width,i.height),this.An.I(this.Li.cols,this.Li.rows),this.Us.cs(),this.Dn.Ji()})}fontSize(t){if(!M.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Zs.fontSize===t)return;this.Zs.di(t);const i=this.Zs.maxGlyphDimensions;this.Li.wi(i.width,i.height),this.An.I(this.Li.cols,this.Li.rows),this.Us.cs(),this.Dn.Ji()}},Ht=c=>class extends c{get frameCount(){return this.Gn.frameCount}set frameCount(t){this.Gn.frameCount=t}frameRate(t){return t===void 0?this.Gn.currentFrameRate:this.Gn.frameRate(t,()=>this.kn())}noLoop(){this.Gn.pause()}loop(){this.Gn.resume(()=>this.kn())}redraw(t=1){if(M.m(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.kn()}isLooping(){return this.Gn.isLooping}},Kt=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.Dn.cr(t)}mousePressed(t){this.Dn.lr(t)}mouseReleased(t){this.Dn.ur(t)}mouseMoved(t){this.Dn.dr(t)}mouseScrolled(t){this.Dn.pr(t)}get mouse(){return this.Dn._r()}},Jt=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.En.lr(t)}keyReleased(t){this.En.ur(t)}isKeyPressed(t){return this.En.Sr(t)}clearKeyStates(){this.En.Dr()}get lastKeyPressed(){return this.En.Pr()}get lastKeyReleased(){return this.En.Mr()}get pressedKeys(){return this.En.Fr()}get modifierState(){return this.En.Ar()}};class qt{constructor(){l(this,"Us");l(this,"Zs");l(this,"yi");l(this,"Li");l(this,"Gn");l(this,"Dn");l(this,"En");l(this,"Fn");l(this,"An");l(this,"Ln")}kn(){}}class st extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(qt,It,jt,Zt,Ht,Kt,Jt){constructor(i={}){super();l(this,"Bn",!1);l(this,"In",()=>{});l(this,"Wn",()=>{});l(this,"Un",()=>{});l(this,"On");this.yi=new Q(i),this.Us=new Rt(this.yi.zi()),this.Zs=new J(this.Us,i.fontSize??16),this.Gn=new Pt(i.frameRate??60),this.Dn=new Ut(this.yi),this.En=new Dt,this.Fn=this.Us.Ke(V,`#version 300 es
|
|
28
|
+
precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`),this.Ln=this.Us.Ke("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}","precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"),this.Vn(i)}async Vn(i){await this.Zs.ci(i.fontSource);const r=this.Zs.maxGlyphDimensions;this.Li=new q(this.yi.canvas,r.width,r.height),this.Dn.ci(this.Li),this.An=this.Us.rs(this.Li.cols,this.Li.rows,5),this.jn(),this.In(),this.Gn.start(()=>this.kn())}jn(){this.On=()=>{this.Un()},window.addEventListener("resize",this.On),this.Dn.tr(),this.En.tr(),window.addEventListener("blur",()=>{this.En.Dr()})}kn(){if(this.Gn.measureFrameRate(),this.Gn.incrementFrame(),this.Bn)return;this.An.O(),this.Us.He(this.Fn),this.Wn(),this.Us.ls(this.Fn),this.An.V();const i=this.Us.state.canvasBackgroundColor;this.Us.fe(i[0],i[1],i[2],i[3]),this.Us.He(this.Ln),this.Ln.st({u_characterTexture:this.Zs.fontFramebuffer,u_charsetDimensions:[this.Zs.textureColumns,this.Zs.textureRows],u_asciiCharacterTexture:this.An.textures[0],u_primaryColorTexture:this.An.textures[1],u_secondaryColorTexture:this.An.textures[2],u_transformTexture:this.An.textures[4],u_rotationTexture:this.An.textures[3],u_gridCellDimensions:[this.Li.cols,this.Li.rows],u_gridPixelDimensions:[this.Li.width,this.Li.height],u_gridOffsetPixels:[this.Li.offsetX,this.Li.offsetY],u_aspectRatio:this.Li.width/this.Li.height}),this.Us.Ze(this.Li.offsetX,this.Li.offsetY,this.Li.width,this.Li.height)}setup(i){this.In=i}draw(i){this.Wn=i}windowResized(i){this.Un=i}resizeCanvas(i,r){this.yi.I(i,r),this.Li.Rt(),this.An.I(this.Li.cols,this.Li.rows),this.Us.cs(),this.Dn.Ji(),this.kn()}destroy(){this.Bn||(this.Gn.stop(),window.removeEventListener("resize",this.On),this.Dn.hr(),this.En.hr(),this.Zs.j(),this.Us.j(),this.Bn=!0)}get grid(){return this.Li}get font(){return this.Zs}get width(){return this.yi.width}get height(){return this.yi.height}get canvas(){return this.yi.canvas}get isDisposed(){return this.Bn}get drawFramebuffer(){return this.An}}class ${constructor(){}static create(t={}){return new st(t)}static setErrorLevel(t){M.v(t)}static get version(){return"0.2.1-beta.1"}}const Qt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),te=$.create,ee=$.setErrorLevel,ie=$.version;T.TextmodeCanvas=Q,T.TextmodeErrorLevel=P,T.TextmodeFont=J,T.TextmodeGrid=q,T.Textmodifier=st,T.create=te,T.export=Qt,T.setErrorLevel=ee,T.textmode=$,T.version=ie,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
|
|
@@ -3,11 +3,15 @@ import { TextmodeFont } from './font';
|
|
|
3
3
|
import { TextmodeGrid } from './Grid';
|
|
4
4
|
import { TextmodeCanvas } from './Canvas';
|
|
5
5
|
import { AnimationController } from './AnimationController';
|
|
6
|
+
import { MouseManager } from './mouse';
|
|
7
|
+
import { KeyboardManager } from './keyboard';
|
|
6
8
|
import { type TextmodifierContext } from './mixins';
|
|
7
9
|
import type { RenderingCapabilities } from './mixins/RenderingMixin';
|
|
8
10
|
import type { ExportCapabilities } from './mixins/ExportMixin';
|
|
9
11
|
import type { FontCapabilities } from './mixins/FontMixin';
|
|
10
12
|
import type { AnimationCapabilities } from './mixins/AnimationMixin';
|
|
13
|
+
import type { MouseCapabilities } from './mixins/MouseMixin';
|
|
14
|
+
import type { KeyboardCapabilities } from './mixins/KeyboardMixin';
|
|
11
15
|
import type { GLFramebuffer, Shader } from '../rendering';
|
|
12
16
|
/**
|
|
13
17
|
* Options for creating a {@link Textmodifier} instance.
|
|
@@ -41,6 +45,8 @@ declare class TextmodifierCore implements TextmodifierContext {
|
|
|
41
45
|
_canvas: TextmodeCanvas;
|
|
42
46
|
_grid: TextmodeGrid;
|
|
43
47
|
_animationController: AnimationController;
|
|
48
|
+
_mouseManager: MouseManager;
|
|
49
|
+
_keyboardManager: KeyboardManager;
|
|
44
50
|
_textmodeDrawShader: Shader;
|
|
45
51
|
_textmodeDrawFramebuffer: GLFramebuffer;
|
|
46
52
|
_textmodeConversionShader: Shader;
|
|
@@ -211,8 +217,8 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
211
217
|
/** Check if the instance has been disposed/destroyed. */
|
|
212
218
|
get isDisposed(): boolean;
|
|
213
219
|
/** Get the draw framebuffer used for offscreen rendering. @ignore */
|
|
214
|
-
get drawFramebuffer():
|
|
220
|
+
get drawFramebuffer(): GLFramebuffer;
|
|
215
221
|
}
|
|
216
|
-
export interface Textmodifier extends RenderingCapabilities, ExportCapabilities, FontCapabilities, AnimationCapabilities {
|
|
222
|
+
export interface Textmodifier extends RenderingCapabilities, ExportCapabilities, FontCapabilities, AnimationCapabilities, MouseCapabilities, KeyboardCapabilities {
|
|
217
223
|
}
|
|
218
224
|
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key event data passed to event handlers
|
|
3
|
+
*/
|
|
4
|
+
export interface KeyboardEventData {
|
|
5
|
+
/** The key that was pressed/released (e.g., 'a', 'Enter', 'ArrowLeft') */
|
|
6
|
+
key: string;
|
|
7
|
+
/** The key code (for compatibility) */
|
|
8
|
+
keyCode: number;
|
|
9
|
+
/** Whether Ctrl key is held down */
|
|
10
|
+
ctrlKey: boolean;
|
|
11
|
+
/** Whether Shift key is held down */
|
|
12
|
+
shiftKey: boolean;
|
|
13
|
+
/** Whether Alt key is held down */
|
|
14
|
+
altKey: boolean;
|
|
15
|
+
/** Whether Meta key (Windows/Cmd) is held down */
|
|
16
|
+
metaKey: boolean;
|
|
17
|
+
/** Whether this key is currently being held down (for keyPressed) or was released (for keyReleased) */
|
|
18
|
+
isPressed: boolean;
|
|
19
|
+
/** Original DOM keyboard event */
|
|
20
|
+
originalEvent: KeyboardEvent;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Keyboard event handler function type
|
|
24
|
+
*/
|
|
25
|
+
export type KeyboardEventHandler = (data: KeyboardEventData) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Key state information
|
|
28
|
+
*/
|
|
29
|
+
export interface KeyState {
|
|
30
|
+
/** Whether the key is currently pressed */
|
|
31
|
+
isPressed: boolean;
|
|
32
|
+
/** Timestamp when the key was last pressed */
|
|
33
|
+
lastPressTime: number;
|
|
34
|
+
/** Timestamp when the key was last released */
|
|
35
|
+
lastReleaseTime: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Manages all keyboard interaction for a Textmodifier instance.
|
|
39
|
+
* Handles event listeners, key state tracking, and event dispatching.
|
|
40
|
+
*
|
|
41
|
+
* Provides p5.js-like keyboard functionality including:
|
|
42
|
+
* - keyPressed() and keyReleased() callbacks
|
|
43
|
+
* - Current key state tracking
|
|
44
|
+
* - Special key handling (arrows, function keys, etc.)
|
|
45
|
+
* - Modifier key support (Ctrl, Shift, Alt, Meta)
|
|
46
|
+
*/
|
|
47
|
+
export declare class KeyboardManager {
|
|
48
|
+
private _keyStates;
|
|
49
|
+
private _lastKeyPressed;
|
|
50
|
+
private _lastKeyReleased;
|
|
51
|
+
private _keyDownListener;
|
|
52
|
+
private _keyUpListener;
|
|
53
|
+
private _areListenersSetup;
|
|
54
|
+
private _keyPressedCallback?;
|
|
55
|
+
private _keyReleasedCallback?;
|
|
56
|
+
private readonly _specialKeyMap;
|
|
57
|
+
constructor();
|
|
58
|
+
/**
|
|
59
|
+
* Setup keyboard event listeners.
|
|
60
|
+
*/
|
|
61
|
+
$setupListeners(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Remove keyboard event listeners.
|
|
64
|
+
*/
|
|
65
|
+
$cleanupListeners(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Set a callback function that will be called when a key is pressed down.
|
|
68
|
+
* @param callback The function to call when a key is pressed
|
|
69
|
+
*/
|
|
70
|
+
$setPressedCallback(callback: KeyboardEventHandler): void;
|
|
71
|
+
/**
|
|
72
|
+
* Set a callback function that will be called when a key is released.
|
|
73
|
+
* @param callback The function to call when a key is released
|
|
74
|
+
*/
|
|
75
|
+
$setReleasedCallback(callback: KeyboardEventHandler): void;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a specific key is currently being pressed.
|
|
78
|
+
* @param key The key to check (e.g., 'a', 'Enter', 'ArrowLeft', or special constants like 'SPACE')
|
|
79
|
+
* @returns true if the key is currently pressed, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
$isKeyPressed(key: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Get the last key that was pressed.
|
|
84
|
+
* @returns The key string of the last pressed key, or null if no key has been pressed
|
|
85
|
+
*/
|
|
86
|
+
$getLastKeyPressed(): string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Get the last key that was released.
|
|
89
|
+
* @returns The key string of the last released key, or null if no key has been released
|
|
90
|
+
*/
|
|
91
|
+
$getLastKeyReleased(): string | null;
|
|
92
|
+
/**
|
|
93
|
+
* Get all currently pressed keys.
|
|
94
|
+
* @returns Array of key strings that are currently pressed
|
|
95
|
+
*/
|
|
96
|
+
$getPressedKeys(): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Check if any modifier key is currently pressed.
|
|
99
|
+
* @returns Object with boolean properties for each modifier key
|
|
100
|
+
*/
|
|
101
|
+
$getModifierState(): {
|
|
102
|
+
ctrl: boolean;
|
|
103
|
+
shift: boolean;
|
|
104
|
+
alt: boolean;
|
|
105
|
+
meta: boolean;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Clear all key states (useful for focus loss scenarios).
|
|
109
|
+
*/
|
|
110
|
+
$clearKeyStates(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Handle key down events
|
|
113
|
+
*/
|
|
114
|
+
private _handleKeyDown;
|
|
115
|
+
/**
|
|
116
|
+
* Handle key up events
|
|
117
|
+
*/
|
|
118
|
+
private _handleKeyUp;
|
|
119
|
+
/**
|
|
120
|
+
* Normalize key names for consistency (map to p5.js-like constants where applicable)
|
|
121
|
+
*/
|
|
122
|
+
private _normalizeKey;
|
|
123
|
+
}
|