textmode.js 0.2.1-beta.5 → 0.2.1-beta.6
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
CHANGED
|
@@ -2665,6 +2665,7 @@ class de extends function(e, ...i) {
|
|
|
2665
2665
|
h(this, "Ho", () => {
|
|
2666
2666
|
});
|
|
2667
2667
|
h(this, "Io");
|
|
2668
|
+
h(this, "hr");
|
|
2668
2669
|
h(this, "ar", !1);
|
|
2669
2670
|
h(this, "No");
|
|
2670
2671
|
this.ar = e.overlay ?? !1, this.tr = new kt(e), this.xt = new St(this.tr.gr()), this.Si = new Wt(this.xt, e.fontSize ?? 16), this.To = new Yt(e.frameRate ?? 60), this.Po = new jt(this.tr), this.Eo = new Vt(), this.Ro = this.xt.Tt(), this.Bo = this.xt.re(), this.Xo(e);
|
|
@@ -2679,7 +2680,9 @@ class de extends function(e, ...i) {
|
|
|
2679
2680
|
this.ar && this.resizeCanvas(this.tr.width, this.tr.height), this.Ho();
|
|
2680
2681
|
}, window.addEventListener("resize", this.Io), this.Po.Xr(), this.Eo.Xr(), window.addEventListener("blur", () => {
|
|
2681
2682
|
this.Eo.sn();
|
|
2682
|
-
})
|
|
2683
|
+
}), window.ResizeObserver && this.ar && (this.hr = new ResizeObserver(() => {
|
|
2684
|
+
this.resizeCanvas(this.tr.targetCanvas.width, this.tr.targetCanvas.height);
|
|
2685
|
+
}), this.hr.observe(this.tr.targetCanvas));
|
|
2683
2686
|
}
|
|
2684
2687
|
So() {
|
|
2685
2688
|
if (this.To.measureFrameRate(), this.To.incrementFrame(), this.Lo) return;
|
|
@@ -2738,7 +2741,7 @@ class Q {
|
|
|
2738
2741
|
N.A(t);
|
|
2739
2742
|
}
|
|
2740
2743
|
static get version() {
|
|
2741
|
-
return "0.2.1-beta.
|
|
2744
|
+
return "0.2.1-beta.6";
|
|
2742
2745
|
}
|
|
2743
2746
|
}
|
|
2744
2747
|
const pe = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), me = Q.create, ve = Q.setErrorLevel, Ae = Q.version;
|
package/dist/textmode.esm.min.js
CHANGED
|
@@ -57,7 +57,7 @@ const I = class I {
|
|
|
57
57
|
};
|
|
58
58
|
a(I, "l", null);
|
|
59
59
|
let j = I;
|
|
60
|
-
const
|
|
60
|
+
const z = j._(), ot = /* @__PURE__ */ new WeakMap();
|
|
61
61
|
function W(h, t) {
|
|
62
62
|
ot.set(h, t);
|
|
63
63
|
}
|
|
@@ -363,7 +363,7 @@ class M {
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
const k = `#version 300 es
|
|
366
|
-
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 U9;uniform vec2
|
|
366
|
+
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 U9;uniform vec2 Uy;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 A(float B){float C=sin(B),D=cos(B);return mat3(1,0,0,0,D,-C,0,C,D);}mat3 E(float B){float C=sin(B),D=cos(B);return mat3(D,0,C,0,1,0,-C,0,D);}mat3 F(float B){float C=sin(B),D=cos(B);return mat3(D,-C,0,C,D,0,0,0,1);}vec2 G(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return N*M*I+3.*N*H*J+3.*M*O*K+O*H*L;}vec2 P(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return-3.*N*I+3.*N*J-6.*M*H*J+6.*M*H*K-3.*O*K+3.*O*L;}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 Q;bool R=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool S=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(R){float H=a_position.x;vec2 T=G(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 U=P(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float V=length(U);U=V>0.?U/V:vec2(1,0);Q=T+vec2(-U.y,U.x)*a_position.y*a_instanceSize.y;}else if(S){float C=a_instanceArcAngles.x,W=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;W=mod(W,6.28318530718);if(W<0.)W+=6.28318530718;float X=C-W;if(X<=0.)X+=6.28318530718;float Y=C-a_position.x*X;vec2 Z=vec2(cos(Y),sin(Y))*a_position.y;Q=Z*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{Q=a_position*a_instanceSize+a_instancePosition;}vec2 a=(Q/Uy)*2.-1.;a.y=-a.y;if(length(a_instanceGlobalRotation)>0.){vec3 b=vec3(a-a_instanceRotationCenter,0);b.x*=U9;if(a_instanceGlobalRotation.x!=0.)b=A(-a_instanceGlobalRotation.x)*b;if(a_instanceGlobalRotation.y!=0.)b=E(-a_instanceGlobalRotation.y)*b;if(a_instanceGlobalRotation.z!=0.)b=F(-a_instanceGlobalRotation.z)*b;b.x/=U9;a=b.xy+a_instanceRotationCenter;}gl_Position=vec4(a,0,1);}`, at = "attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}";
|
|
367
367
|
class ft {
|
|
368
368
|
constructor(t) {
|
|
369
369
|
a(this, "vt");
|
|
@@ -437,7 +437,7 @@ class gt {
|
|
|
437
437
|
}
|
|
438
438
|
ve(t, e, i) {
|
|
439
439
|
const { shader: s } = t, r = X(this.vt) || this.vt.getParameter(this.vt.VIEWPORT);
|
|
440
|
-
s.Nt({ U9: r[2] / r[3],
|
|
440
|
+
s.Nt({ U9: r[2] / r[3], Uy: [r[2], r[3]] });
|
|
441
441
|
const n = (l) => {
|
|
442
442
|
if (!l || !l.ye()) return;
|
|
443
443
|
const f = l.unitGeometry, u = l.unitBuffer;
|
|
@@ -468,7 +468,7 @@ class gt {
|
|
|
468
468
|
Ae(t, e, i, s, r, n, o, c) {
|
|
469
469
|
e.Vt(), e.Nt(i);
|
|
470
470
|
const l = this.vt.getParameter(this.vt.VIEWPORT);
|
|
471
|
-
if (e.Nt({ U9: l[2] / l[3],
|
|
471
|
+
if (e.Nt({ U9: l[2] / l[3], Uy: [l[2], l[3]] }), t.Fe(), t.Re({ x: s, y: r, width: n, height: o }, c), t.ye()) {
|
|
472
472
|
const f = t.unitGeometry, u = t.unitBuffer;
|
|
473
473
|
try {
|
|
474
474
|
this.pe.ce(e.Jt, t.type + "", f, u), t.batch.Ce(e), t.batch.we(f.$e, f.be);
|
|
@@ -1396,7 +1396,7 @@ class q {
|
|
|
1396
1396
|
return 0;
|
|
1397
1397
|
}
|
|
1398
1398
|
}
|
|
1399
|
-
class
|
|
1399
|
+
class zt {
|
|
1400
1400
|
constructor(t) {
|
|
1401
1401
|
a(this, "yi");
|
|
1402
1402
|
a(this, "Ci");
|
|
@@ -1472,7 +1472,7 @@ class $t {
|
|
|
1472
1472
|
this.Ci.fill();
|
|
1473
1473
|
}
|
|
1474
1474
|
}
|
|
1475
|
-
class
|
|
1475
|
+
class $t {
|
|
1476
1476
|
constructor() {
|
|
1477
1477
|
a(this, "Ri");
|
|
1478
1478
|
this.Ri = new q();
|
|
@@ -1512,12 +1512,12 @@ class kt {
|
|
|
1512
1512
|
return [t % 256 / 255, Math.floor(t / 256) % 256 / 255, Math.floor(t / 65536) % 256 / 255];
|
|
1513
1513
|
}
|
|
1514
1514
|
zi(t, e) {
|
|
1515
|
-
if (
|
|
1515
|
+
if (!z.v(typeof t == "string", "Character must be a string.", { method: "getCharacterColor", providedValue: t })) return [0, 0, 0];
|
|
1516
1516
|
const i = e.find((s) => s.character === t);
|
|
1517
1517
|
return i ? i.color : [0, 0, 0];
|
|
1518
1518
|
}
|
|
1519
1519
|
Ti(t, e) {
|
|
1520
|
-
return
|
|
1520
|
+
return z.v(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.zi(i, e) || [0, 0, 0]) : [[0, 0, 0]];
|
|
1521
1521
|
}
|
|
1522
1522
|
}
|
|
1523
1523
|
class Nt {
|
|
@@ -1534,7 +1534,7 @@ class Nt {
|
|
|
1534
1534
|
a(this, "Oi");
|
|
1535
1535
|
a(this, "Hi");
|
|
1536
1536
|
a(this, "Vi");
|
|
1537
|
-
this.Pi = e, this.Wi = new Ot(), this.Oi = new
|
|
1537
|
+
this.Pi = e, this.Wi = new Ot(), this.Oi = new zt(t), this.Hi = new $t(), this.Vi = new kt();
|
|
1538
1538
|
}
|
|
1539
1539
|
async Ki(t) {
|
|
1540
1540
|
let e;
|
|
@@ -1732,7 +1732,7 @@ class Xt {
|
|
|
1732
1732
|
return this.tr.height;
|
|
1733
1733
|
}
|
|
1734
1734
|
}
|
|
1735
|
-
class
|
|
1735
|
+
class $ {
|
|
1736
1736
|
constructor(t, e, i, s) {
|
|
1737
1737
|
a(this, "texture");
|
|
1738
1738
|
a(this, "width");
|
|
@@ -1808,7 +1808,7 @@ class z {
|
|
|
1808
1808
|
static fromSource(t, e, i) {
|
|
1809
1809
|
const s = t.context, r = s.createTexture();
|
|
1810
1810
|
s.bindTexture(s.TEXTURE_2D, r), s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL, 1), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, s.NEAREST), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, s.NEAREST), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, s.CLAMP_TO_EDGE), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, s.RGBA, s.UNSIGNED_BYTE, e), s.bindTexture(s.TEXTURE_2D, null);
|
|
1811
|
-
const n = e.naturalWidth ?? e.width ?? e.videoWidth ?? 0, o = e.naturalHeight ?? e.height ?? e.videoHeight ?? 0, c = new
|
|
1811
|
+
const n = e.naturalWidth ?? e.width ?? e.videoWidth ?? 0, o = e.naturalHeight ?? e.height ?? e.videoHeight ?? 0, c = new $(s, r, n, o);
|
|
1812
1812
|
return c.wr = i, c;
|
|
1813
1813
|
}
|
|
1814
1814
|
}
|
|
@@ -2158,12 +2158,12 @@ const jt = (h) => class extends h {
|
|
|
2158
2158
|
}
|
|
2159
2159
|
}
|
|
2160
2160
|
async loadImage(t) {
|
|
2161
|
-
if (typeof t != "string") return
|
|
2161
|
+
if (typeof t != "string") return $.fromSource(this.xt, t, (s) => this.Ei.Ti(s));
|
|
2162
2162
|
const e = t, i = await new Promise((s, r) => {
|
|
2163
2163
|
const n = new Image();
|
|
2164
2164
|
n.crossOrigin = "anonymous", n.onload = () => s(n), n.onerror = (o) => r(o), n.src = e;
|
|
2165
2165
|
});
|
|
2166
|
-
return
|
|
2166
|
+
return $.fromSource(this.xt, i, (s) => this.Ei.Ti(s));
|
|
2167
2167
|
}
|
|
2168
2168
|
};
|
|
2169
2169
|
class J {
|
|
@@ -2553,7 +2553,7 @@ const he = (h) => class extends h {
|
|
|
2553
2553
|
});
|
|
2554
2554
|
}
|
|
2555
2555
|
fontSize(t) {
|
|
2556
|
-
if (
|
|
2556
|
+
if (!z.v(typeof t == "number" && t > 0, "Font size must be a positive number greater than 0.", { method: "fontSize", providedValue: t }) || this.Ei.fontSize === t) return;
|
|
2557
2557
|
this.Ei.ji(t);
|
|
2558
2558
|
const e = this.Ei.maxGlyphDimensions;
|
|
2559
2559
|
this.rn.rr(e.width, e.height), this.Ao.resize(this.rn.cols, this.rn.rows), this.xt.Zs(), this.zo.Cn();
|
|
@@ -2581,7 +2581,7 @@ const he = (h) => class extends h {
|
|
|
2581
2581
|
this.To.resume(() => this.Eo());
|
|
2582
2582
|
}
|
|
2583
2583
|
redraw(t = 1) {
|
|
2584
|
-
if (
|
|
2584
|
+
if (z.v(typeof t == "number" && t > 0 && Number.isInteger(t), "Redraw count must be a positive integer.", { method: "redraw", providedValue: t })) for (let e = 0; e < t; e++) this.Eo();
|
|
2585
2585
|
}
|
|
2586
2586
|
isLooping() {
|
|
2587
2587
|
return this.To.isLooping;
|
|
@@ -2665,6 +2665,7 @@ class de extends function(e, ...i) {
|
|
|
2665
2665
|
a(this, "Wo", () => {
|
|
2666
2666
|
});
|
|
2667
2667
|
a(this, "Oo");
|
|
2668
|
+
a(this, "hr");
|
|
2668
2669
|
a(this, "ar", !1);
|
|
2669
2670
|
a(this, "Ho");
|
|
2670
2671
|
this.ar = e.overlay ?? !1, this.tr = new Xt(e), this.xt = new Ft(this.tr.mr()), this.Ei = new Nt(this.xt, e.fontSize ?? 16), this.To = new Ht(e.frameRate ?? 60), this.zo = new Vt(this.tr), this.Lo = new Yt(), this.So = this.xt.Tt(), this.ko = this.xt.re(), this.Vo(e);
|
|
@@ -2672,14 +2673,16 @@ class de extends function(e, ...i) {
|
|
|
2672
2673
|
async Vo(e) {
|
|
2673
2674
|
await this.Ei.Ki(e.fontSource);
|
|
2674
2675
|
const i = this.Ei.maxGlyphDimensions;
|
|
2675
|
-
this.rn = new Wt(this.tr.canvas, i.width, i.height), this.zo.Ki(this.rn), this.Ao = this.xt.js(this.rn.cols, this.rn.rows, 5), this.Po = this.xt.js(this.rn.width, this.rn.height, 1), this.ar && (this.Ho =
|
|
2676
|
+
this.rn = new Wt(this.tr.canvas, i.width, i.height), this.zo.Ki(this.rn), this.Ao = this.xt.js(this.rn.cols, this.rn.rows, 5), this.Po = this.xt.js(this.rn.width, this.rn.height, 1), this.ar && (this.Ho = $.fromSource(this.xt, this.tr.targetCanvas, (s) => this.Ei.Ti(s))), this.Go = this.xt.ae(at, "precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"), this.Ko(), this.Do(), this.To.start(() => this.Eo());
|
|
2676
2677
|
}
|
|
2677
2678
|
Ko() {
|
|
2678
2679
|
this.Oo = () => {
|
|
2679
2680
|
this.ar && this.resizeCanvas(this.tr.width, this.tr.height), this.Wo();
|
|
2680
2681
|
}, window.addEventListener("resize", this.Oo), this.zo.Vr(), this.Lo.Vr(), window.addEventListener("blur", () => {
|
|
2681
2682
|
this.Lo.sn();
|
|
2682
|
-
})
|
|
2683
|
+
}), window.ResizeObserver && this.ar && (this.hr = new ResizeObserver(() => {
|
|
2684
|
+
this.resizeCanvas(this.tr.targetCanvas.width, this.tr.targetCanvas.height);
|
|
2685
|
+
}), this.hr.observe(this.tr.targetCanvas));
|
|
2683
2686
|
}
|
|
2684
2687
|
Eo() {
|
|
2685
2688
|
if (this.To.measureFrameRate(), this.To.incrementFrame(), this.Bo) return;
|
|
@@ -2735,10 +2738,10 @@ class Q {
|
|
|
2735
2738
|
return new de(t);
|
|
2736
2739
|
}
|
|
2737
2740
|
static setErrorLevel(t) {
|
|
2738
|
-
|
|
2741
|
+
z.C(t);
|
|
2739
2742
|
}
|
|
2740
2743
|
static get version() {
|
|
2741
|
-
return "0.2.1-beta.
|
|
2744
|
+
return "0.2.1-beta.6";
|
|
2742
2745
|
}
|
|
2743
2746
|
}
|
|
2744
2747
|
const pe = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), me = Q.create, ve = Q.setErrorLevel, xe = Q.version;
|
|
@@ -2748,7 +2751,7 @@ export {
|
|
|
2748
2751
|
Nt as TextmodeFont,
|
|
2749
2752
|
K as TextmodeFramebuffer,
|
|
2750
2753
|
Wt as TextmodeGrid,
|
|
2751
|
-
|
|
2754
|
+
$ as TextmodeImage,
|
|
2752
2755
|
de as Textmodifier,
|
|
2753
2756
|
me as create,
|
|
2754
2757
|
pe as export,
|
package/dist/textmode.umd.js
CHANGED
|
@@ -4,10 +4,10 @@ var xe=Object.defineProperty;var ye=(C,R,_)=>R in C?xe(C,R,{enumerable:!0,config
|
|
|
4
4
|
- ${r}: ${R.o(n)}`).join(""):""}
|
|
5
5
|
|
|
6
6
|
${"↓".repeat(24)}
|
|
7
|
-
`}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=>R.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>R.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}: ${R.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${R.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var _=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(_||{});const
|
|
7
|
+
`}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=>R.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>R.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}: ${R.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${R.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var _=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(_||{});const G=class G{constructor(){l(this,"u",{globalLevel:3})}static m(){return G.l||(G.l=new G),G.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(R.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(R.i(t,i)),console.groupEnd(),!1;default:throw new R(t,i)}}v(t,i,r){return!!t||(this._(i,r),!1)}A(t){this.u.globalLevel=t}};l(G,"l",null);let J=G;const W=J.m(),rt=new WeakMap;function Y(c,t){rt.set(c,t)}function V(c){return rt.get(c)}class nt{constructor(){l(this,"C",1);l(this,"U",0);l(this,"$",0);l(this,"M",0);l(this,"F",[0,0,0]);l(this,"R",[1,1,1,1]);l(this,"P",[0,0,0,1]);l(this,"S",!1);l(this,"G",!1);l(this,"D",!1);l(this,"L",[0,0]);l(this,"O",[0,0,0,1]);l(this,"k",[])}H(){this.k.push({I:this.C,N:this.U,X:this.$,W:this.M,L:[...this.L],V:this.S,K:this.G,D:this.D,j:[...this.F],Y:[...this.R],q:[...this.P]})}Z(){const t=this.k.pop();t?(this.C=t.I,this.U=t.N,this.$=t.X,this.M=t.W,this.L=t.L,this.S=t.V,this.G=t.K,this.D=t.D,this.F=t.j,this.R=t.Y,this.P=t.q):console.warn("pop() called without matching push()")}J(t){t.I=this.C,t.N=this.U,t.X=this.$,t.W=this.M,t.j[0]=this.F[0],t.j[1]=this.F[1],t.j[2]=this.F[2],t.Y[0]=this.R[0],t.Y[1]=this.R[1],t.Y[2]=this.R[2],t.Y[3]=this.R[3],t.q[0]=this.P[0],t.q[1]=this.P[1],t.q[2]=this.P[2],t.q[3]=this.P[3],t.V=this.S,t.K=this.G,t.D=this.D,t.L[0]=this.L[0],t.L[1]=this.L[1]}get lineWeight(){return this.C}get canvasBackgroundColor(){return this.O}tt(t){this.C=Math.abs(t)}et(t){this.U=t}st(t){this.$=t}it(t){this.M=t}rt(t){this.F=t}nt(t,i,r,n=255){this.R=[t/255,i/255,r/255,n/255]}ot(t,i,r,n=255){this.P=[t/255,i/255,r/255,n/255]}ht(t){this.S=t}ct(t){this.G=t}lt(t){this.D=t}ut(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.L=[r,n]}ft(t,i,r,n){this.O=[t/255,i/255,r/255,n/255]}}class j{constructor(t,i,r=i,n=1,o={},a=null,h=!1){l(this,"dt");l(this,"gt");l(this,"u");l(this,"_t",null);l(this,"vt");l(this,"yt");l(this,"At",[]);l(this,"wt");l(this,"Ct",null);l(this,"bt",[]);l(this,"xt",null);l(this,"$t",!1);l(this,"Mt",null);this.dt=i,this.gt=r,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.vt=t,this.wt=Math.min(Math.max(1,n),8),this.xt=a,this.$t=!!h,this.Mt=this.$t?new nt:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.wt=Math.min(this.wt,u,f),this.yt=t.createFramebuffer(),this.Ft(),this.Rt(),this.bt=Array(this.wt).fill(null)}Ft(){const t=this.vt,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.wt;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.dt,this.gt,0,t.RGBA,n,null),this.At.push(a)}t.bindTexture(t.TEXTURE_2D,null)}Rt(){const t=this.vt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.wt===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.At[0],0);else{const r=[];for(let n=0;n<this.wt;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.At[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)}zt(t){const i=this.vt;i.bindTexture(i.TEXTURE_2D,this.At[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)}resize(t,i){this.dt=t,this.gt=i,this._t=null,this.bt=Array(this.wt).fill(null);const r=this.vt,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.At)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.dt,this.gt,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}Pt(t){const i=this.vt,r=this.bt[t];if(r)return r;const n=this.dt,o=this.gt,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.yt),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,f=new Uint8Array(a.length);for(let g=0;g<o;g++){const d=(o-1-g)*u,m=g*u;f.set(a.subarray(d,d+u),m)}return this.bt[t]=f,f}begin(){var i,r,n,o;const t=this.vt;if(this.xt){const a=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;a&&this.xt.St(a),this.$t&&this.Mt&&((o=(n=this.xt).Et)==null||o.call(n,this.Mt))}this.Ct={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.bt=Array(this.wt).fill(null);for(let a=0;a<this.wt;a++)t.clearBufferfv(t.COLOR,a,new Float32Array([0,0,0,0]));t.viewport(0,0,this.dt,this.gt),Y(t,[0,0,this.dt,this.gt])}end(){var i,r,n,o;if(!this.Ct)return;const t=this.vt;if(this.xt){const a=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;a&&this.xt.St(a)}t.bindFramebuffer(t.FRAMEBUFFER,this.Ct.framebuffer),t.viewport(...this.Ct.viewport),Y(t,this.Ct.viewport),this.Ct=null,this.xt&&this.$t&&this.Mt&&((o=(n=this.xt).Bt)==null||o.call(n))}Gt(){const t=this.vt;t.deleteFramebuffer(this.yt);for(const i of this.At)t.deleteTexture(i)}get width(){return this.dt}get height(){return this.gt}get textures(){return[...this.At]}}class N{constructor(t,i,r){l(this,"vt");l(this,"Dt");l(this,"Lt",new Map);l(this,"Ot",new Map);l(this,"kt",0);this.vt=t,this.Dt=this.Ht(i,r),this.It()}It(){const t=this.vt.getProgramParameter(this.Dt,this.vt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.vt.getActiveUniform(this.Dt,i);if(r){const n=this.vt.getUniformLocation(this.Dt,r.name);if(n&&(this.Lt.set(r.name,n),this.Ot.set(r.name,{type:r.type,size:r.size}),r.size>1)){const o=r.name.replace(/\[.*\]$/,"");this.Lt.has(o)||(this.Lt.set(o,n),this.Ot.set(o,{type:r.type,size:r.size}))}}}}Ht(t,i){const r=this.Nt(this.vt.VERTEX_SHADER,t),n=this.Nt(this.vt.FRAGMENT_SHADER,i),o=this.vt.createProgram();if(this.vt.attachShader(o,r),this.vt.attachShader(o,n),this.vt.linkProgram(o),!this.vt.getProgramParameter(o,this.vt.LINK_STATUS)){const a=this.vt.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.vt.deleteShader(r),this.vt.deleteShader(n),o}Nt(t,i){const r=this.vt.createShader(t);if(this.vt.shaderSource(r,i),this.vt.compileShader(r),!this.vt.getShaderParameter(r,this.vt.COMPILE_STATUS)){const n=this.vt.getShaderInfoLog(r);throw this.vt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Xt(){this.vt.useProgram(this.Dt),this.Wt()}Wt(){this.kt=0}Vt(t){for(const[i,r]of Object.entries(t))this.Kt(i,r)}jt(t){return this.Lt.has(t)}Yt(t){return this.Ot.get(t)||null}qt(){const t=[];for(const[i,r]of this.Ot.entries())t.push({name:i,...r});return t}Kt(t,i){var u;const r=this.Lt.get(t);if(!r)return;const n=this.Ot.get(t);if(!n)return void console.warn(`No type information found for uniform '${t}'`);const{type:o,size:a}=n,h=this.vt;if(typeof i=="number")switch(o){case h.INT:case h.BOOL:h.uniform1i(r,i);break;case h.FLOAT:h.uniform1f(r,i);break;default:console.warn(`Unexpected uniform type for scalar '${t}': ${o}`),h.uniform1f(r,i)}else if(typeof i=="boolean")h.uniform1i(r,i?1:0);else if(Array.isArray(i))if(Array.isArray(i[0])){const f=i,g=((u=f[0])==null?void 0:u.length)||0,d=f.flat();switch(o){case h.FLOAT_VEC2:g===2?h.uniform2fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 2, got ${g}`);break;case h.FLOAT_VEC3:g===3?h.uniform3fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 3, got ${g}`);break;case h.FLOAT_VEC4:g===4?h.uniform4fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 4, got ${g}`);break;default:console.warn(`Unsupported uniform type for vector array '${t}': ${o}`)}}else switch(o){case h.FLOAT_VEC2:i.length===2?h.uniform2f(r,i[0],i[1]):console.warn(`Vector length mismatch for '${t}': expected 2, got ${i.length}`);break;case h.FLOAT_VEC3:i.length===3?h.uniform3f(r,i[0],i[1],i[2]):console.warn(`Vector length mismatch for '${t}': expected 3, got ${i.length}`);break;case h.FLOAT_VEC4:i.length===4?h.uniform4f(r,i[0],i[1],i[2],i[3]):console.warn(`Vector length mismatch for '${t}': expected 4, got ${i.length}`);break;case h.INT:a>1?h.uniform1iv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;case h.FLOAT:a>1?h.uniform1fv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;default:console.warn(`Unsupported uniform type for array '${t}': ${o}`)}else if(i instanceof WebGLTexture){const f=this.Zt();h.uniform1i(r,f),h.activeTexture(h.TEXTURE0+f),h.bindTexture(h.TEXTURE_2D,i)}else if(i instanceof j){const f=this.Zt();h.uniform1i(r,f),h.activeTexture(h.TEXTURE0+f),h.bindTexture(h.TEXTURE_2D,i.textures[0])}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}Zt(){return this.kt++}get Qt(){return this.Dt}Gt(){this.vt.deleteProgram(this.Dt)}}const K=`#version 300 es
|
|
8
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 U9;uniform vec2 Uy;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 A(float B){float C=sin(B),D=cos(B);return mat3(1,0,0,0,D,-C,0,C,D);}mat3 E(float B){float C=sin(B),D=cos(B);return mat3(D,0,C,0,1,0,-C,0,D);}mat3 F(float B){float C=sin(B),D=cos(B);return mat3(D,-C,0,C,D,0,0,0,1);}vec2 G(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return N*M*I+3.*N*H*J+3.*M*O*K+O*H*L;}vec2 P(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return-3.*N*I+3.*N*J-6.*M*H*J+6.*M*H*K-3.*O*K+3.*O*L;}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 Q;bool R=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool S=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(R){float H=a_position.x;vec2 T=G(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 U=P(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float V=length(U);U=V>0.?U/V:vec2(1,0);Q=T+vec2(-U.y,U.x)*a_position.y*a_instanceSize.y;}else if(S){float C=a_instanceArcAngles.x,W=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;W=mod(W,6.28318530718);if(W<0.)W+=6.28318530718;float X=C-W;if(X<=0.)X+=6.28318530718;float Y=C-a_position.x*X;vec2 Z=vec2(cos(Y),sin(Y))*a_position.y;Q=Z*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{Q=a_position*a_instanceSize+a_instancePosition;}vec2 a=(Q/Uy)*2.-1.;a.y=-a.y;if(length(a_instanceGlobalRotation)>0.){vec3 b=vec3(a-a_instanceRotationCenter,0);b.x*=U9;if(a_instanceGlobalRotation.x!=0.)b=A(-a_instanceGlobalRotation.x)*b;if(a_instanceGlobalRotation.y!=0.)b=E(-a_instanceGlobalRotation.y)*b;if(a_instanceGlobalRotation.z!=0.)b=F(-a_instanceGlobalRotation.z)*b;b.x/=U9;a=b.xy+a_instanceRotationCenter;}gl_Position=vec4(a,0,1);}`,ot="attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}";class vt{constructor(t){l(this,"vt");l(this,"Jt");l(this,"te");l(this,"ee");l(this,"se");this.vt=t,this.te=new N(this.vt,K,`#version 300 es
|
|
9
9
|
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.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`),this.Jt=new N(this.vt,K,`#version 300 es
|
|
10
10
|
precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;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 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ee=new N(this.vt,ot,"precision mediump float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U2;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;mat2 A(float B){float C=sin(B);float D=cos(B);return mat2(D,-C,C,D);}void main(){vec2 E=gl_FragCoord.xy/U8;vec2 F=E*U7;vec2 G=floor(F);vec2 H=(G+0.5)/U7;vec4 I=texture2D(U3,H);vec4 J=texture2D(U4,H);vec4 K=texture2D(U5,H);bool L=K.r>0.5;bool M=K.g>0.5;bool N=K.b>0.5;vec4 O=texture2D(U2,H);int P=int(O.r*255.+0.5)+int(O.g*255.+0.5)*256;int Q=int(mod(float(P),U1.x));int R=P/int(U1.x);float S=(U1.y-1.)-float(R);vec2 T=vec2(float(Q),S)/U1;vec4 U=texture2D(U6,H);float V=U.r*255.+U.g;float W=-(V*360./255.)*0.017453292;vec2 X=fract(F)-0.5;if(M)X.x=-X.x;if(N)X.y=-X.y;X=A(W)*X+0.5;vec2 Y=1./U1;vec2 Z=T+X*Y;vec2 a=T+Y;if(any(lessThan(Z,T))||any(greaterThan(Z,a))){gl_FragColor=L?I:J;return;}vec4 b=texture2D(U0,Z);if(L)b.rgb=1.-b.rgb;gl_FragColor=mix(J,I,b);}"),this.se=new N(this.vt,K,`#version 300 es
|
|
11
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec3 Uq;uniform bool Ur;uniform vec3 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];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;float A(vec3 B){return dot(B,vec3(0.299,0.587,0.114));}void main(){vec2 C=vec2(v_uv.x,1.-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.),0.,F-1.);int H=int(floor(G+0.5));vec3 I=Uv[H];o_character=vec4(I,1.);}else{o_character=vec4(E,0.,0.,1.);}vec3 J=D.rgb;vec3 K=Up?Uq:J;vec3 L=Ur?Us:J;float M=Up?1.:D.a;float N;if(D.a<0.01){K=Ut.rgb;L=Ut.rgb;M=Ut.a;N=Ut.a;}else{N=Ur?1.:D.a;}o_primaryColor=vec4(K,M);o_secondaryColor=vec4(L,N);o_rotation=vec4(Uo.xy,0.,1.);o_transform=vec4(float(Ul),float(Um),float(Un),1.);}`)}ie(){return this.Jt}Tt(){return this.te}re(){return this.ee}ne(){return this.se}oe(t){return new N(this.vt,K,t)}ae(t,i){return new N(this.vt,t,i)}Gt(){this.Jt.Gt(),this.te.Gt(),this.ee.Gt(),this.se.Gt()}}var b=(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))(b||{});class At{constructor(t){l(this,"vt");l(this,"he",new Map);this.vt=t}ce(t,i,r,n){const o=this.vt;let a=this.he.get(t);a||(a=new Map,this.he.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.ue.le.size,o.FLOAT,!1,r.fe,r.ue.le.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ue.de.size,o.FLOAT,!1,r.fe,r.ue.de.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}pe(){this.vt.bindVertexArray(null)}Gt(){for(const[,t]of this.he)for(const[,i]of t)i&&this.vt.deleteVertexArray(i)}}class xt{constructor(t,i){l(this,"me");l(this,"vt");l(this,"xt");l(this,"ge",null);l(this,"_e",null);this.vt=t,this.me=new At(t),this.xt=i}ve(t,i,r){const{shader:n}=t,o=V(this.vt)||this.vt.getParameter(this.vt.VIEWPORT);n.Vt({U9:o[2]/o[3],Uy:[o[2],o[3]]});const a=f=>{if(!f||!f.ye())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.me.ce(n.Qt,f.type+"",g,d),f.batch.Ae(n),f.batch.we(g.Ce,g.be)}finally{f.batch.xe(n),this.me.pe(),f.$e()}};let h=null,u=null;for(const f of i){if(f.type===b.CUSTOM){u&&(a(u),h=null,u=null),this.Me(t,f.params,f.state,r.get(b.RECTANGLE));continue}h!==null&&f.type!==h&&(a(u),h=null,u=null);let g=u;g&&f.type===h||(g=r.get(f.type)||null,u=g,h=f.type),g&&g.Fe(f.params,f.state)}a(u)}Me(t,i,r,n){const{x:o,y:a,width:h,height:u,shader:f,uniforms:g}=i,d=this.Re(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)));d.begin(),this.ze(n,f,g,0,0,d.width,d.height,{}),d.end();const m=this.Pe(),x={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.ze(n,m,x,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),t.shader.Xt()}ze(t,i,r,n,o,a,h,u){i.Xt(),i.Vt(r);const f=this.vt.getParameter(this.vt.VIEWPORT);if(i.Vt({U9:f[2]/f[3],Uy:[f[2],f[3]]}),t.$e(),t.Fe({x:n,y:o,width:a,height:h},u),t.ye()){const g=t.unitGeometry,d=t.unitBuffer;try{this.me.ce(i.Qt,t.type+"",g,d),t.batch.Ae(i),t.batch.we(g.Ce,g.be)}finally{t.batch.xe(i),this.me.pe(),t.$e()}}}Pe(){return this.xt.ie()}Re(t,i){return this.ge&&this._e&&this._e.w===t&&this._e.h===i||(this.ge&&this.ge.Gt(),this.ge=new j(this.vt,t,i,5),this._e={w:t,h:i}),this.ge}Gt(){this.me.Gt(),this.ge&&this.ge.Gt()}}class yt{constructor(){l(this,"Te",[]);l(this,"Se",1);l(this,"Ee",0)}Be(t){if(this.Ee>=this.Te.length){const r={id:this.Se++,type:t,params:{},state:{I:1,N:0,X:0,W:0,j:[0,0,0],Y:[1,1,1,1],q:[0,0,0,1],V:!1,K:!1,D:!1,L:[0,0]}};this.Te.push(r)}const i=this.Te[this.Ee];return i.id=this.Se++,i.type=t,this.Ee++,i}Ge(t,i,r,n,o){const a=this.Be(b.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.J(a.state),a.id}De(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}Le(t,i,r,n,o,a){const h=this.Be(b.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.J(h.state),h.id}ke(t,i,r,n,o){const a=this.Be(b.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.J(a.state),a.id}Oe(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}He(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}Ie(t,i,r,n,o,a,h,u,f,g){const d=this.Be(b.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Ee}get isEmpty(){return this.Ee===0}Ne(){this.Ee=0}[Symbol.iterator](){let t=0;const i=this.Ee,r=this.Te;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const D=class D{static Xe(t,i,r=0){var a,h,u,f,g,d,m,x,A,p;const n=i||new Float32Array(D.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.le[0],n[o++]=t.le[1],n[o++]=t.Ee[0],n[o++]=t.Ee[1],n[o++]=t.j[0],n[o++]=t.j[1],n[o++]=t.j[2],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.Y[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.L[0],n[o++]=t.L[1],n[o++]=t.We[0],n[o++]=t.We[1],n[o++]=t.We[2],n[o++]=t.N,n[o++]=t.X,n[o++]=t.W,n[o++]=t.Ve[0],n[o++]=t.Ve[1],n[o++]=((a=t.Ke)==null?void 0:a[0])||0,n[o++]=((h=t.Ke)==null?void 0:h[1])||0,n[o++]=((u=t.je)==null?void 0:u[0])||0,n[o++]=((f=t.je)==null?void 0:f[1])||0,n[o++]=((g=t.Ye)==null?void 0:g[0])||0,n[o++]=((d=t.Ye)==null?void 0:d[1])||0,n[o++]=((m=t.qe)==null?void 0:m[0])||0,n[o++]=((x=t.qe)==null?void 0:x[1])||0,n[o++]=((A=t.Ze)==null?void 0:A[0])||0,n[o++]=((p=t.Ze)==null?void 0:p[1])||0,n}static Qe(t){const i=t.length*D.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*D.FLOATS_PER_INSTANCE;D.Xe(t[n],r,o)}return r}};l(D,"BYTES_PER_INSTANCE",140),l(D,"FLOATS_PER_INSTANCE",35);let I=D;const U=class U{};l(U,"STRIDE",I.BYTES_PER_INSTANCE),l(U,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let q=U;class Et{constructor(t,i=1e3,r=1.5){l(this,"vt");l(this,"Je",[]);l(this,"ts");l(this,"es");l(this,"ss",null);l(this,"rs",!0);l(this,"ns",0);l(this,"hs",new Map);l(this,"cs",null);this.vt=t,this.ts=i,this.es=r,this.ls()}Fe(t){const i=this.Je.length;return this.Je.push(t),this.rs=!0,i}get count(){return this.Je.length}get isEmpty(){return this.Je.length===0}clear(){this.Je.length=0,this.rs=!0}us(t){if(t<=this.ts)return;const i=Math.ceil(t*this.es);this.ts=i,this.ls()}ls(){const t=this.vt;this.ss&&t.deleteBuffer(this.ss),this.ss=t.createBuffer();const i=this.ts*I.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ss),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!0,this.ns=0}fs(){if(!this.rs||this.Je.length===0)return;const t=this.vt,i=this.Je.length;this.us(i),(!this.cs||this.cs.length<i*I.FLOATS_PER_INSTANCE)&&(this.cs=new Float32Array(i*I.FLOATS_PER_INSTANCE));const r=I.Qe(this.Je);t.bindBuffer(t.ARRAY_BUFFER,this.ss),i<=this.ns?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!1,this.ns=i}ds(t){let i=this.hs.get(t);if(!i){i=new Map;const r=this.vt;for(const n in q.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.hs.set(t,i)}return i}Ae(t){if(!this.ss||this.Je.length===0)return;const i=this.vt,r=t.Qt;this.fs();const n=this.ds(r);i.bindBuffer(i.ARRAY_BUFFER,this.ss);for(const[o,a]of n){const h=q.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}xe(t){const i=this.vt,r=this.ds(t.Qt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}we(t,i){this.Je.length!==0&&this.vt.drawArraysInstanced(t,0,i,this.Je.length)}Gt(){this.ss&&this.vt.deleteBuffer(this.ss)}}class z{constructor(t,i,r,n){l(this,"vt");l(this,"ps");l(this,"gs");l(this,"_s");l(this,"vs",null);this.vt=t,this.ps=i,this.gs=r,this._s=n;const o=this.vt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.vt.bindBuffer(this.vt.ARRAY_BUFFER,o),this.vt.bufferData(this.vt.ARRAY_BUFFER,this._s.As,this.vt.STATIC_DRAW),this.vt.bindBuffer(this.vt.ARRAY_BUFFER,null),this.vs=o}get type(){return this.gs}get unitGeometry(){return this._s}get unitBuffer(){return this.vs}get batch(){return this.ps}$e(){this.ps.clear()}ye(){return!this.ps.isEmpty}Gt(){this.ps.Gt(),this.vt.deleteBuffer(this.vs)}ws(t,i,r,n,o){const a=this.Cs(t,i,r,n,o.N||0,o.X||0,o.W||0);return{le:[t,i],Ee:[r,n],j:o.j||[0,0,0],Y:o.Y||[1,1,1,1],q:o.q||[0,0,0,1],L:o.L||[0,0],We:[o.D?1:0,o.V?1:0,o.K?1:0],N:a.radiansX,X:a.radiansY,W:a.radiansZ,Ve:[a.centerX,a.centerY]}}bs(t,i){const r=V(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}$s(t,i,r){const n=this.bs(i,r);t.Ve=[n.nx,n.ny]}Cs(t,i,r,n,o,a,h){const u=V(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/g}}}const wt={As: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]),be:6,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class bt extends z{constructor(t,i){super(t,i,b.RECTANGLE,wt)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.ps.Fe(r)}}const Rt={As: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]),be:6,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Tt extends z{constructor(t,i){super(t,i,b.LINE,Rt)}Fe(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=t.thickness||i.I||1,h=t.x1+r/2,u=t.y1+n/2,f=h-o/2,g=u,d=this.ws(f,g,o,a,i);return this.$s(d,h,u),this.ps.Fe(d)}}const Ct={As: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),f=.5*(h+1),g=Math.cos(o),d=Math.sin(o),m=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,a,h,u,f,g,d,m,x)}return new Float32Array(t)}(32),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ut extends z{constructor(t,i){super(t,i,b.ELLIPSE,Ct)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.$s(r,t.x,t.y),this.ps.Fe(r)}}let Ft={As: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),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class St extends z{constructor(t,i){super(t,i,b.ARC,Ft)}Fe(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.ws(r,n,t.width,t.height,i);return this.$s(h,t.x,t.y),h.Ke=[o,a],this.ps.Fe(h)}}const Bt={As:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),be:3,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Pt extends z{constructor(t,i){super(t,i,b.TRIANGLE,Bt)}Fe(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.ws(r,o,a,h,i),f=r+.5*a,g=o+h*(1/3);return this.$s(u,f,g),this.ps.Fe(u)}}function at(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 Lt={As: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),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Mt extends z{constructor(t,i){super(t,i,b.BEZIER_CURVE,Lt)}Fe(t,i){const r=i.I||1,n=at(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=at(.5,t.y1,t.cp1y,t.cp2y,t.y2),a=this.ws(0,0,1,r,i);return this.$s(a,n,o),a.qe=[t.x1,t.y1],a.je=[t.cp1x,t.cp1y],a.Ye=[t.cp2x,t.cp2y],a.Ze=[t.x2,t.y2],this.ps.Fe(a)}}class Dt{constructor(t){l(this,"vt");l(this,"Ms",null);l(this,"Fs");l(this,"Rs",null);l(this,"zs",{});l(this,"Ps",null);l(this,"Ts",new Map);l(this,"Ss");l(this,"Es");l(this,"Bs");l(this,"O",[]);this.vt=t,this.Fs=new vt(t),this.Bs=new nt,this.Ss=new xt(t,this),this.Es=new yt,this.Ps=t.createBuffer(),Y(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}Gs(t){let i=this.Ts.get(t);if(i)return i;const r=new Et(this.vt);return i=(0,{[b.RECTANGLE]:()=>new bt(this.vt,r),[b.LINE]:()=>new Tt(this.vt,r),[b.ELLIPSE]:()=>new Ut(this.vt,r),[b.ARC]:()=>new St(this.vt,r),[b.TRIANGLE]:()=>new Pt(this.vt,r),[b.BEZIER_CURVE]:()=>new Mt(this.vt,r)}[t])(),this.Ts.set(t,i),i}Ds(t){this.Ms!==t&&(this.Ms=t,t.Xt())}ae(t,i){return this.Fs.ae(t,i)}ie(){return this.Fs.ie()}Tt(){return this.Fs.Tt()}re(){return this.Fs.re()}ne(){return this.Fs.ne()}Ls(t){this.Rs=t,t&&(this.zs={})}Kt(t,i){this.zs[t]=i}ks(t){Object.assign(this.zs,t)}oe(t){return this.Fs.oe(t)}Os(t,i,r,n,o){const a=this.ie(),h={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.Es.De(i,r,n,o,a,h,this.Bs)}Hs(t,i,r,n,o){const a=this.ne(),h=t.texture,u=t.flags,f=t.charRotationRG,g=[f[0],f[1]],d=t.colorUniforms??{charColorFixed:!1,Y:[1,1,1],cellColorFixed:!1,cellColor:[0,0,0],backgroundColor:[0,0,0,1]},m=t.characterListUniforms,x={Uk:h,Ul:!!u.invert,Um:!!u.flipX,Un:!!u.flipY,Uo:g,Up:!!d.charColorFixed,Uq:d.Y,Ur:!!d.cellColorFixed,Us:d.cellColor,Ut:d.backgroundColor,Uu:m.count,Uv:m.list};this.Es.De(i,r,n,o,a,x,this.Bs)}Is(t,i,r,n){var p;const o=this.vt,a=o.canvas.width,h=o.canvas.height,u=t/a*2-1,f=(t+r)/a*2-1,g=1-i/h*2,d=1-(i+n)/h*2,m=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.Ps),o.bufferData(o.ARRAY_BUFFER,m,o.DYNAMIC_DRAW);const x=((p=this.Ms)==null?void 0:p.Qt)||o.getParameter(o.CURRENT_PROGRAM),A=x?o.getAttribLocation(x,"a_position"):-1;A!==-1&&(o.enableVertexAttribArray(A),o.vertexAttribPointer(A,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),A!==-1&&o.disableVertexAttribArray(A)}Ns(t,i,r,n){this.Rs?(this.Es.De(t,i,r,n,this.Rs,{...this.zs},this.Bs),this.Rs=null,this.zs={}):this.Es.Ge(t,i,r,n,this.Bs)}Xs(t,i,r,n){this.Es.Le(t,i,r,n,this.Bs.lineWeight,this.Bs)}Ws(t,i,r,n){this.Es.ke(t,i,r,n,this.Bs)}Vs(t,i,r,n,o,a){this.Es.He(t,i,r,n,o,a,this.Bs)}Ks(t,i,r,n,o,a,h,u){const f=this.Bs.lineWeight;this.Es.Ie(t,i,r,n,o,a,h,u,f,this.Bs)}js(t,i,r=1,n={}){return new j(this.vt,t,i,r,n,this,!0)}Ys(t,i,r,n,o,a){this.Es.Oe(t,i,r,n,o,a,this.Bs)}qs(t,i=t,r=t,n=255){this.state.ft(t,i,r,n),this.Ne(t/255,i/255,r/255,n/255)}Ne(t=0,i=0,r=0,n=0){this.vt.clearColor(t,i,r,n),this.vt.clear(this.vt.COLOR_BUFFER_BIT)}Zs(){this.vt.viewport(0,0,this.vt.canvas.width,this.vt.canvas.height),Y(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}get context(){return this.vt}get state(){return this.Bs}Et(t){this.O.push(this.Bs),this.Bs=t}Bt(){const t=this.O.pop();t&&(this.Bs=t)}St(t){const i=t,r=V(this.vt)??this.vt.getParameter(this.vt.VIEWPORT),n={shader:i,gl:this.vt,viewport:r};this.Ds(i);const o=new Set;for(const a of this.Es)a.type===b.CUSTOM?o.add(b.RECTANGLE):o.add(a.type);for(const a of o)a!==b.CUSTOM&&this.Gs(a);this.Ss.ve(n,this.Es,this.Ts),this.Es.Ne()}Gt(){this.vt.deleteBuffer(this.Ps),this.Es.Ne();for(const t of this.Ts.values())t.Gt();this.Fs.Gt(),this.Ss.Gt()}}const T={readShort:(c,t)=>(T.t.uint16[0]=c[t]<<8|c[t+1],T.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(T.readUshort(c,t+2*n));return r},readUint(c,t){const i=T.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],T.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},writeUshort(c,t,i){c[t]=i>>>8&255,c[t+1]=255&i},writeUint(c,t,i){c[t]=i>>>24&255,c[t+1]=i>>>16&255,c[t+2]=i>>>8&255,c[t+3]=255&i},writeASCII(c,t,i){for(let r=0;r<i.length;r++)c[t+r]=255&i.charCodeAt(r)},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()};function Z(c){return c+3&-4}function Q(c,t,i){const r=t+i;let n=0;const o=T.t;for(let a=t;a<r;a+=4)o.uint8[3]=c[a]||0,o.uint8[2]=c[a+1]||0,o.uint8[1]=c[a+2]||0,o.uint8[0]=c[a+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class _t{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function H(c){let t=32,i=0;for(const h of c)h&&(h<t&&(t=h),h>i&&(i=h));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const h of c)h&&r[h]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let h=1;h<=i;h++)o=o+r[h-1]<<1,n[h]=o;const a=new Map;for(let h=0;h<c.length;h++){const u=c[h];if(!u)continue;const f=n[u]++;let g=a.get(u);g||(g=[],a.set(u,g)),g[It(f,u)]=h}return{min:t,max:i,table:a}}function tt(c,t){let i=0;for(let r=1;r<=t.max;r++){i|=c.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function It(c,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&c,c>>>=1;return i>>>0}function Ot(c){if(c.length<2)throw Error("ZLIB data too short");const t=c[0],i=c[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,a){const h=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const m=o.readBits(2);if(m===0){o.alignToByte();const x=o.readBits(16);if((65535&(65535^x))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let A=0;A<x;A++)a.push(o.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let x,A;if(m===1){const p=Array(288).fill(0);for(let y=0;y<=143;y++)p[y]=8;for(let y=144;y<=255;y++)p[y]=9;for(let y=256;y<=279;y++)p[y]=7;for(let y=280;y<=287;y++)p[y]=8;x=H(p),A=H(Array(32).fill(5))}else{const p=o.readBits(5)+257,y=o.readBits(5)+1,v=o.readBits(4)+4,w=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],E=Array(19).fill(0);for(let P=0;P<v;P++)E[w[P]]=o.readBits(3);const B=H(E),F=[];for(;F.length<p+y;){const P=tt(o,B);if(P<=15)F.push(P);else if(P===16){const k=o.readBits(2)+3,G=F[F.length-1]||0;for(let mt=0;mt<k;mt++)F.push(G)}else if(P===17){const k=o.readBits(3)+3;for(let G=0;G<k;G++)F.push(0)}else{if(P!==18)throw Error("Invalid code length symbol");{const k=o.readBits(7)+11;for(let G=0;G<k;G++)F.push(0)}}}const S=F.slice(0,p),L=F.slice(p,p+y);x=H(S),A=H(L)}for(;;){const p=tt(o,x);if(p<256)a.push(p);else{if(p===256)break;if(p>256&&p<286){const y=p-257;let v=h[y];const w=u[y];w&&(v+=o.readBits(w));const E=tt(o,A);if(E>=30)throw Error("Invalid distance symbol");let B=f[E];const F=g[E];F&&(B+=o.readBits(F));const S=a.length-B;if(S<0)throw Error("Invalid distance");for(let L=0;L<v;L++)a.push(a[S+L]||0)}else if(p===286||p===287)throw Error("Reserved length symbol")}}}}}}(new _t(c.subarray(r)),n),new Uint8Array(n)}function Gt(c){const t=T,i=new Uint8Array(c);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),a=[];let h=44;for(let v=0;v<n;v++){const w=t.readASCII(i,h,4),E=t.readUint(i,h+4),B=t.readUint(i,h+8),F=t.readUint(i,h+12),S=t.readUint(i,h+16);a.push({tag:w,offset:E,compLength:B,origLength:F,checksum:S}),h+=20}for(const v of a){const w=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(w);else if(v.data=Ot(w),v.data.length!==v.origLength)if(v.data.length<v.origLength){const E=new Uint8Array(v.origLength);E.set(v.data),v.data=E}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,m=16*u-d;let x=12+16*u;const A={};for(const v of a)A[v.tag]=x,x=Z(x+v.data.length);const p=new Uint8Array(Math.max(o||0,x));t.writeUint(p,0,r),t.writeUshort(p,4,u),t.writeUshort(p,6,d),t.writeUshort(p,8,g),t.writeUshort(p,10,m);let y=12;for(const v of a){t.writeASCII(p,y,v.tag),y+=4;let w=v.data;if(v.tag==="head"&&w.length>=12){const E=new Uint8Array(w);t.writeUint(E,8,0);const B=Q(E,0,Z(E.length));t.writeUint(p,y,B),y+=4}else{const E=Q(w,0,Z(w.length));t.writeUint(p,y,E),y+=4}t.writeUint(p,y,A[v.tag]),y+=4,t.writeUint(p,y,v.data.length),y+=4}for(const v of a){const w=A[v.tag];p.set(v.data,w)}if(a.find(v=>v.tag==="head")){const v=A.head,w=function(E,B){const F=T,S=B+8,L=[E[S],E[S+1],E[S+2],E[S+3]];F.writeUint(E,S,0);const P=2981146554-(Q(E,0,Z(E.length))>>>0)>>>0;return E[S]=L[0],E[S+1]=L[1],E[S+2]=L[2],E[S+3]=L[3],P>>>0}(p,v);t.writeUint(p,v+8,w)}return p.buffer}const Nt={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=T,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let u=0;u<a;u++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const m=`p${f}e${g}`;let x=h.indexOf(d);if(x===-1){let A;x=r.tables.length,h.push(d);const p=o(c,d);A=p===4?this.parse4(c,d):p===12?this.parse12(c,d):{format:p},r.tables.push(A)}r.ids[m]=x}return r},parse4(c,t){const i=T,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 f=0;f<h;f++)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=T.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}}},zt={parseTab(c,t,i){const r=T;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)}}},Xt={parseTab(c,t,i){const r=T;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=T,o=[],a=[],h=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)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}}},ht={cmap:Nt,head:zt,hhea:Xt,maxp:{parseTab(c,t,i){const r=T;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Wt,loca:{parseTab(c,t,i,r){const n=T,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},Qs(c,t){const i=T,r=c.Js,n=c.loca;if(n[t]===n[t+1])return null;const o=M.findTable(r,"glyf",c.ti);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 m=0;m<h.noc;m++)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 f=h.endPts[h.noc-1]+1;h.flags=[];for(let m=0;m<f;m++){const x=r[a];if(a++,h.flags.push(x),8&x){const A=r[a];a++;for(let p=0;p<A;p++)h.flags.push(x),m++}}h.xs=[];for(let m=0;m<f;m++){const x=h.flags[m],A=!!(16&x);2&x?(h.xs.push(A?r[a]:-r[a]),a++):A?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let m=0;m<f;m++){const x=h.flags[m],A=!!(32&x);4&x?(h.ys.push(A?r[a]:-r[a]),a++):A?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let g=0,d=0;for(let m=0;m<f;m++)g+=h.xs[m],d+=h.ys[m],h.xs[m]=g,h.ys[m]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},M={parse(c){const t=new Uint8Array(c),i=T.readASCII(t,0,4);if(i==="wOFF")c=Gt(c);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,a)=>{const h=ht,u={Js:r,ei:n,ti:o};for(const f in h){const g=f,d=M.findTable(r,g,o);if(d){const[m,x]=d;let A=a[m];A==null&&(A=h[g].parseTab(r,m,x,u),a[m]=A),u[g]=A}}return u})(new Uint8Array(c),0,0,{})]},findTable(c,t,i){const r=T,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),f=r.readUint(c,o+12);if(h===t)return[u,f];o+=16}return null},T:ht,B:T};class Ht{si(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(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.ai(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}ri(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}ai(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}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){l(this,"hi",new Map);l(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.hi.has(r))return this.hi.get(r);const n=t.cmap;if(!n||!n.tables)return this.hi.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.fi(i,a):a.format===12&&(o=this.di(i,a)),o>0)break;return this.hi.set(r,o),o}pi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}mi(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}gi(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}}_i(){this.hi.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Js.length}`}fi(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}di(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 kt{constructor(t){l(this,"yi");l(this,"Ai");l(this,"xt");l(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ai=this.yi.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,f=i.height*h,g=typeof n=="object"?n:null;this.Ci(u,f),this.bi(t,i,a,r,g);const d=this.xt.js(u,f,1,{filter:"nearest"});return d.zt(this.yi),{framebuffer:d,columns:a,rows:h}}Ci(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=t+"px",this.Ai.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ai.fillStyle="black",this.Ai.fillRect(0,0,t,i),this.Ai.textBaseline="top",this.Ai.textAlign="left",this.Ai.fillStyle="white"}bi(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const u=h%r,f=Math.floor(h/r),g=t[h].character,d=this.xi(o,g);if(!d)continue;const m=g.codePointAt(0)||0,x=this.wi.li(o,m),A=this.$i(o,x)*a,p=u*i.width,y=f*i.height,v=p+.5*i.width,w=y+.5*i.height,E=Math.round(v-.5*i.width),B=Math.round(w-.5*n),F=E+.5*(i.width-A),S=B+o.hhea.ascender*a;this.Mi(d,F,S,a)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(M&&M.T&&M.T.glyf){const o=M.T.glyf.Qs(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}$i(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Mi(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.Ai.beginPath();let f=0;for(let g=0;g<h.length;g++){const d=h[g];if(!(d<f)){if(d>=f){const m=i+o[f]*n,x=r-a[f]*n;this.Ai.moveTo(m,x);let A=f+1;for(;A<=d;)if(1&u[A]){const p=i+o[A]*n,y=r-a[A]*n;this.Ai.lineTo(p,y),A++}else{const p=i+o[A]*n,y=r-a[A]*n;let v=A+1>d?f:A+1;if(1&u[v]){const w=i+o[v]*n,E=r-a[v]*n;this.Ai.quadraticCurveTo(p,y,w,E),A=v+1}else{const w=(p+(i+o[v]*n))/2,E=(y+(r-a[v]*n))/2;this.Ai.quadraticCurveTo(p,y,w,E),A=v}}this.Ai.closePath()}f=d+1}}this.Ai.fill()}}class Yt{constructor(){l(this,"Fi");this.Fi=new et}Ri(t,i,r){let n=0;const o=this.Fi.gi(r,i),a=o.lineHeight;for(const h of t){const u=this.Fi.pi(r,h);if(u===0)continue;const f=this.Fi.mi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}_i(){this.Fi._i()}}class Vt{constructor(){l(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.zi(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(h=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:a,advanceWidth:h}})}zi(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Pi(t,i){if(!W.v(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]}Ti(t,i){return W.v(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.Pi(r,i)||[0,0,0]):[[0,0,0]]}}class ct{constructor(t,i=16){l(this,"Si");l(this,"Ei",[]);l(this,"Bi");l(this,"Gi",16);l(this,"Di",0);l(this,"Li",0);l(this,"ki",{width:0,height:0});l(this,"Oi");l(this,"Hi");l(this,"Ii");l(this,"Ni");l(this,"Xi");this.Gi=i,this.Hi=new Ht,this.Ii=new kt(t),this.Ni=new Yt,this.Xi=new Vt}async Wi(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new R(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,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")).arrayBuffer();await this.Vi(i),this.Si=M.parse(i)[0],await this.Ki()}ji(t){if(t===void 0)return this.Gi;this.Gi=t,this.ki=this.Ni.Ri(this.Ei.map(r=>r.character),this.Gi,this.Si);const i=this.Ii.createTextureAtlas(this.Ei,this.ki,this.Gi,this.Si);this.Bi=i.framebuffer,this.Di=i.columns,this.Li=i.rows}async Yi(t){try{const i=await fetch(t);if(!i.ok)throw new R(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Vi(r);const n=M.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Si=n[0],await this.Ki()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Vi(t){const i=Date.now();this.Oi=new FontFace("CustomFont_"+i,t),await this.Oi.load(),document.fonts.add(this.Oi)}async Ki(){const t=this.Hi.si(this.Si),i=this.Hi.ni(t);this.Ei=this.Xi.createCharacterObjects(i,this.Si),this.ki=this.Ni.Ri(i,this.Gi,this.Si);const r=this.Ii.createTextureAtlas(this.Ei,this.ki,this.Gi,this.Si);this.Bi=r.framebuffer,this.Di=r.columns,this.Li=r.rows}Pi(t){return this.Xi.Pi(t,this.Ei)}Ti(t){return this.Xi.Ti(t,this.Ei)}Gt(){this.Bi.Gt(),document.fonts.delete(this.Oi)}get fontFramebuffer(){return this.Bi}get characters(){return this.Ei}get textureColumns(){return this.Di}get textureRows(){return this.Li}get maxGlyphDimensions(){return this.ki}get fontSize(){return this.Gi}get font(){return this.Si}}class lt{constructor(t,i,r){l(this,"qi");l(this,"Zi");l(this,"dt");l(this,"gt");l(this,"Qi");l(this,"Ji");l(this,"tr");l(this,"er");l(this,"sr");this.tr=t,this.er=i,this.sr=r,this.ir()}ir(){this.qi=Math.floor(this.tr.width/this.er),this.Zi=Math.floor(this.tr.height/this.sr),this.dt=this.qi*this.er,this.gt=this.Zi*this.sr,this.Qi=Math.floor((this.tr.width-this.dt)/2),this.Ji=Math.floor((this.tr.height-this.gt)/2)}rr(t,i){this.er=t,this.sr=i,this.ir()}get cellWidth(){return this.er}get cellHeight(){return this.sr}get cols(){return this.qi}get rows(){return this.Zi}get width(){return this.dt}get height(){return this.gt}get offsetX(){return this.Qi}get offsetY(){return this.Ji}}class ut{constructor(t={}){l(this,"tr");l(this,"nr",null);l(this,"ar",!1);l(this,"hr");l(this,"cr");this.ar=t.overlay??!1,this.ar&&t.canvas?(this.nr=t.canvas,this.tr=this.lr(),this.cr=!0,this.ur()):t.canvas?(this.tr=t.canvas,this.cr=!1):(this.tr=this.dr(t.width,t.height),this.cr=!0),this.tr.style.imageRendering="pixelated"}dr(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}lr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.nr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.nr instanceof HTMLVideoElement){const h=this.nr;(r===0||n===0)&&h.videoWidth>0&&h.videoHeight>0&&(r=h.videoWidth,n=h.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.nr);let a=parseInt(o.zIndex||"0",10);return isNaN(a)&&(a=0),t.style.zIndex=""+(a+1),t}ur(){var t;this.pr(),(t=this.nr.parentNode)==null||t.insertBefore(this.tr,this.nr.nextSibling),window.ResizeObserver&&(this.hr=new ResizeObserver(()=>{this.mr()}),this.hr.observe(this.nr)),window.addEventListener("resize",()=>{this.mr()})}pr(){if(!this.nr)return;const t=this.nr.getBoundingClientRect();let i=this.nr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.tr.style.top=t.top-r.top+"px",this.tr.style.left=t.left-r.left+"px"}else this.tr.style.top=t.top+window.scrollY+"px",this.tr.style.left=t.left+window.scrollX+"px"}mr(t,i){if(this.ar){const r=this.nr.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.nr instanceof HTMLVideoElement){const a=this.nr;(n===0||o===0)&&a.videoWidth>0&&a.videoHeight>0&&(n=a.videoWidth,o=a.videoHeight)}this.tr.width=n,this.tr.height=o,this.pr()}else this.tr.width=t??this.tr.width,this.tr.height=i??this.tr.height}gr(){const t=this.tr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new R("`textmode.js` requires WebGL2 support.");return t}Gt(){this.hr&&this.hr.disconnect();const t=this.tr.getContext("webgl")||this.tr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.cr&&this.tr.parentNode&&this.tr.parentNode.removeChild(this.tr)}get canvas(){return this.tr}get targetCanvas(){return this.nr}get width(){return this.tr.width}get height(){return this.tr.height}}class X{constructor(t,i,r,n){l(this,"texture");l(this,"width");l(this,"height");l(this,"vt");l(this,"D",0);l(this,"V",0);l(this,"K",0);l(this,"L",[0,0]);l(this,"_r","sampled");l(this,"vr","fixed");l(this,"Y",[1,1,1]);l(this,"q",[0,0,0]);l(this,"yr",[0,0,0,1]);l(this,"Ar",[[.1,0,0]]);l(this,"wr");this.vt=t,this.texture=i,this.width=r,this.height=n}Gt(){this.vt.deleteTexture(this.texture)}Cr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.D=this.Cr(t),this}flipX(t=!0){return this.V=this.Cr(t),this}flipY(t=!0){return this.K=this.Cr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.L=[r,n],this}get flags(){return{invert:this.D,flipX:this.V,flipY:this.K}}get charRotationRG(){return this.L}charColorMode(t){return this._r=t,this}cellColorMode(t){return this.vr=t,this}charColor(t,i,r){return this.Y=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}cellColor(t,i,r){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}background(t,i,r,n){return this.yr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}charactersFromColors(t){const i=t.filter(r=>Array.isArray(r)).slice(0,64);return this.Ar=i,this}characters(t){const i=this.wr(t);return this.charactersFromColors(i),this}get characterListUniforms(){return{count:this.Ar.length,list:this.Ar}}get colorUniforms(){return{charColorFixed:this._r==="fixed",Y:this.Y,cellColorFixed:this.vr==="fixed",cellColor:this.q,backgroundColor:this.yr}}static fromSource(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const a=i.naturalWidth??i.width??i.videoWidth??0,h=i.naturalHeight??i.height??i.videoHeight??0,u=new X(n,o,a,h);return u.wr=r,u}}class jt{constructor(t=60){l(this,"br");l(this,"$r");l(this,"Mr",null);l(this,"Fr",0);l(this,"Rr",!0);l(this,"zr",0);l(this,"Pr",0);l(this,"Tr",[]);l(this,"Sr",10);l(this,"Er",0);this.br=t,this.$r=1e3/t}start(t){if(!this.Rr)return;this.Fr=performance.now();const i=r=>{if(!this.Rr)return void(this.Mr=null);const n=r-this.Fr;n>=this.$r&&(t(),this.Fr=r-n%this.$r),this.Rr&&(this.Mr=requestAnimationFrame(i))};this.Mr=requestAnimationFrame(i)}stop(){this.Mr&&(cancelAnimationFrame(this.Mr),this.Mr=null)}pause(){this.Rr&&(this.Rr=!1,this.stop())}resume(t){this.Rr||(this.Rr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.zr;this.br=t,this.$r=1e3/t,this.Rr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Pr>0){const i=t-this.Pr;this.Tr.push(i),this.Tr.length>this.Sr&&this.Tr.shift();const r=this.Tr.reduce((n,o)=>n+o,0)/this.Tr.length;this.zr=1e3/r}this.Pr=t}get isLooping(){return this.Rr}get frameRateLimit(){return this.br}get currentFrameRate(){return this.zr}get frameCount(){return this.Er}set frameCount(t){this.Er=t}incrementFrame(){this.Er++}resetFrameCount(){this.Er=0}}class Kt{constructor(){l(this,"Br",new Map);l(this,"Gr",null);l(this,"Dr",null);l(this,"Lr");l(this,"kr");l(this,"Or",!1);l(this,"Hr");l(this,"Ir");l(this,"Nr",{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"})}Xr(){this.Or||(this.Lr=t=>{this.Wr(t)},this.kr=t=>{this.Vr(t)},window.addEventListener("keydown",this.Lr,{passive:!1}),window.addEventListener("keyup",this.kr,{passive:!1}),this.Or=!0)}Kr(){this.Or&&(window.removeEventListener("keydown",this.Lr),window.removeEventListener("keyup",this.kr),this.Or=!1,this.Br.clear(),this.Gr=null,this.Dr=null)}jr(t){this.Hr=t}Yr(t){this.Ir=t}qr(t){const i=this.Zr(t),r=this.Br.get(t)||this.Br.get(i);return(r==null?void 0:r.isPressed)||!1}Qr(){return this.Gr}Jr(){return this.Dr}tn(){const t=[];for(const[i,r]of this.Br)r.isPressed&&t.push(i);return t}en(){return{ctrl:this.qr("Control"),shift:this.qr("Shift"),alt:this.qr("Alt"),meta:this.qr("Meta")}}sn(){this.Br.clear(),this.Gr=null,this.Dr=null}Wr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Gr=i,this.Hr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Hr(o)}}Vr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.Dr=i,this.Ir){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Ir(o)}}Zr(t){return this.Nr[t]||t.toLowerCase()}}class qt{constructor(t){l(this,"tr");l(this,"rn");l(this,"nn",{x:-1,y:-1});l(this,"an",{x:-1,y:-1});l(this,"hn",null);l(this,"cn");l(this,"ln");l(this,"un");l(this,"fn");l(this,"dn");l(this,"pn");l(this,"Or",!1);l(this,"mn");l(this,"gn");l(this,"_n");l(this,"vn");l(this,"yn");this.tr=t}Wi(t){this.rn=t,this.An()}Xr(){if(this.Or)return;const t=this.tr.canvas;this.cn=i=>{this.wn(i),this.Cn(i)},this.ln=()=>{this.an={...this.nn},this.nn.x=-1,this.nn.y=-1,this.hn=null},this.un=i=>{this.wn(i),this.bn(i)},this.fn=i=>{this.wn(i),this.xn(i)},this.dn=i=>{this.wn(i),this.$n(i)},this.pn=i=>{this.wn(i),this.Mn(i)},t.addEventListener("mousemove",this.cn,{passive:!0}),t.addEventListener("mouseleave",this.ln,{passive:!0}),t.addEventListener("mousedown",this.un,{passive:!0}),t.addEventListener("mouseup",this.fn,{passive:!0}),t.addEventListener("click",this.dn,{passive:!0}),t.addEventListener("wheel",this.pn,{passive:!1}),this.Or=!0}Kr(){if(!this.Or)return;const t=this.tr.canvas;t.removeEventListener("mousemove",this.cn),t.removeEventListener("mouseleave",this.ln),t.removeEventListener("mousedown",this.un),t.removeEventListener("mouseup",this.fn),t.removeEventListener("click",this.dn),t.removeEventListener("wheel",this.pn),this.Or=!1}An(){if(this.Or)try{if(this.hn){const t=new MouseEvent("mousemove",{clientX:this.hn.x,clientY:this.hn.y,bubbles:!1,cancelable:!1});this.wn(t)}else this.nn.x!==-1&&this.nn.y!==-1&&(this.nn.x>=this.rn.cols||this.nn.y>=this.rn.rows)&&(this.nn.x=-1,this.nn.y=-1)}catch{this.nn.x=-1,this.nn.y=-1}}Fn(t){this.mn=t}jr(t){this.gn=t}Yr(t){this._n=t}Rn(t){this.vn=t}zn(t){this.yn=t}Pn(){return{x:this.nn.x,y:this.nn.y}}Cn(t){if(this.vn){const i={position:{...this.nn},previousPosition:{...this.an},originalEvent:t};this.vn(i)}}bn(t){if(this.gn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.gn(i)}}xn(t){if(this._n){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this._n(i)}}$n(t){if(this.mn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.mn(i)}}Mn(t){if(this.yn){const i={position:{...this.nn},previousPosition:{...this.an},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.yn(i)}}wn(t){const i=this.tr.canvas;this.an={...this.nn},this.hn={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.rn.offsetX,f=h-this.rn.offsetY,g=Math.floor(u/this.rn.cellWidth),d=Math.floor(f/this.rn.cellHeight);g>=0&&g<this.rn.cols&&d>=0&&d<this.rn.rows?(this.nn.x=g,this.nn.y=d):(this.nn.x=-1,this.nn.y=-1)}}const Zt=c=>class extends c{rotate(t=0,i=0,r=0){this.xt.state.et(t),this.xt.state.st(i),this.xt.state.it(r)}rotateX(t){this.xt.state.et(t)}rotateY(t){this.xt.state.st(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.H()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Ns(t,i,r,n)}point(t,i){this.xt.Ns(t,i,1,1)}line(t,i,r,n){this.xt.Xs(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qs(t,i,r,n)}char(t){this.xt.state.rt(this.Si.Pi(t))}charColor(t,i,r){this.xt.state.nt(t,i,r)}cellColor(t,i,r){this.xt.state.ot(t,i,r)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qs(0,0,0,0)}ellipse(t,i,r,n){this.xt.Ws(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.xt.Vs(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,u){this.xt.Ks(t,i,r,n,o,a,h,u)}arc(t,i,r,n,o,a){this.xt.Ys(t,i,r,n,o,a)}shader(t){this.xt.Ls(t)}setUniform(t,i){this.xt.Kt(t,i)}setUniforms(t){this.xt.ks(t)}createFilterShader(t){return this.xt.oe(t)}createFramebuffer(t){return this.xt.js(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const a=t;this.xt.Os(a,i,r,n??a.width,o??a.height)}else{const a=t;this.xt.Hs(a,i,r,n??a.width,o??a.height)}}async loadImage(t){if(typeof t!="string")return X.fromSource(this.xt,t,n=>this.Si.Ti(n));const i=t,r=await new Promise((n,o)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>n(a),a.onerror=h=>o(h),a.src=i});return X.fromSource(this.xt,r,n=>this.Si.Ti(n))}};class it{Tn(t){const i=t.Pt(0),r=t.Pt(1),n=t.Pt(2),o=t.Pt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.Pt(4),rotationPixels:o}}Sn(t,i){return t[i]+(t[i+1]<<8)}En(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class st{Bn(t,i){return new Blob([t],{type:i})}Gn(t,i,r){try{const n=this.Bn(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){console.error("Failed to download file:",n)}}Dn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Ln(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}kn(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}On(){return"textmode-export-"+this.Dn()}}class $t extends it{Hn(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}}In(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Nn(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.Sn(t.characterPixels,h);let f=this.En(t.primaryColorPixels,h),g=this.En(t.secondaryColorPixels,h);const d=this.Hn(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const x=f;f=g,g=x}const m=this.In(a,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:g,transform:d,position:m}),n++}return r}}class Jt{Xn(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],f=o.groups[a+2];if(i>=h&&i<=u)return f+(i-h)}}return 0}Wn(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.Vn(i,r,n,a)}}Vn(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 f="",g=0;for(let d=0;d<h.length;d++){const m=h[d];if(!(m<g)){if(m>=g){const x=i+o[g]*n,A=r-a[g]*n;f+=`M${x.toFixed(2)},${A.toFixed(2)}`;let p=g+1;for(;p<=m;)if(1&u[p]){const y=i+o[p]*n,v=r-a[p]*n;f+=`L${y.toFixed(2)},${v.toFixed(2)}`,p++}else{const y=i+o[p]*n,v=r-a[p]*n;let w=p+1>m?g:p+1;if(1&u[w]){const E=i+o[w]*n,B=r-a[w]*n;f+=`Q${y.toFixed(2)},${v.toFixed(2)} ${E.toFixed(2)},${B.toFixed(2)}`,p=w+1}else{const E=(y+(i+o[w]*n))/2,B=(v+(r-a[w]*n))/2;f+=`Q${y.toFixed(2)},${v.toFixed(2)} ${E.toFixed(2)},${B.toFixed(2)}`,p=w}}f+="Z"}g=m+1}}return f}Kn(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.Xn(i,a);let u=null;return i.glyf&&i.glyf[h]!==null?u=i.glyf[h]:(u=M.T.glyf.Qs(i,h),i.glyf[h]=u),this.Wn(i,u,r,n,o)}jn(t,i,r,n,o,a,h,u){const f=r+(o-u*(h/i.head.unitsPerEm))/2,g=n+(a+.7*h)/2;return this.Kn(t,i,f,g,h).toSVG()||null}}class Qt{constructor(){l(this,"Yn");this.Yn=new Jt}qn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}Zn(){return"</g></svg>"}Qn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,a]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${a/255})"/>`}Jn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;h.push(`translate(${o} ${a})scale(${u} ${f})translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),` transform="${h.join(" ")}"`}eo(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:a,b:h,a:u}=t.secondaryColor,f=`rgba(${o},${a},${h},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Kn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.Yn.jn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const{r:h,g:u,b:f,a:g}=t.primaryColor,d=`rgba(${h},${u},${f},${g/255})`;return n.drawMode==="stroke"?`<path d="${a}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${a}" fill="${d}"/>`}so(t,i,r,n){const o=[],a=this.eo(t,i,n);a&&o.push(a);const h=this.Kn(t,i,r,n);if(h){const u=this.Jn(t,i);o.push(u?`<g${u}>${h}</g>`:h)}return o.join("")}io(t,i,r,n){const o=[this.qn(i),this.Qn(i,n),'<g id="ascii-cells">'];for(const a of t)o.push(this.so(a,i,r,n));return o.push(this.Zn()),o.join("")}ro(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class te extends st{no(t){return this.Bn(t,"image/svg+xml;charset=utf-8")}oo(t,i){this.Gn(t,this.kn(i)+".svg","image/svg+xml;charset=utf-8")}ao(t,i){this.oo(t,i||this.On())}}class ft{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new $t,this.co=new Qt,this.lo=new te}uo(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.lo.On()}}fo(t,i={}){const r=this.ho.Nn(this.ho.Tn(t.pipeline),t.grid),n=this.co.io(r,t.grid,t.font,this.uo(i));return this.co.ro(n)}ao(t,i={}){this.lo.ao(this.fo(t,i),i.filename)}}class ee extends it{do(t,i,r,n=" "){var h;const o=[];let a=0;for(let u=0;u<i.rows;u++){const f=[];for(let g=0;g<i.cols;g++){const d=4*a,m=this.Sn(t.characterPixels,d),x=((h=r.characters[m])==null?void 0:h.character)||n;f.push(x),a++}o.push(f)}return o}}class ie{po(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
|
|
11
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec3 Uq;uniform bool Ur;uniform vec3 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];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;float A(vec3 B){return dot(B,vec3(0.299,0.587,0.114));}void main(){vec2 C=vec2(v_uv.x,1.-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.),0.,F-1.);int H=int(floor(G+0.5));vec3 I=Uv[H];o_character=vec4(I,1.);}else{o_character=vec4(E,0.,0.,1.);}vec3 J=D.rgb;vec3 K=Up?Uq:J;vec3 L=Ur?Us:J;float M=Up?1.:D.a;float N;if(D.a<0.01){K=Ut.rgb;L=Ut.rgb;M=Ut.a;N=Ut.a;}else{N=Ur?1.:D.a;}o_primaryColor=vec4(K,M);o_secondaryColor=vec4(L,N);o_rotation=vec4(Uo.xy,0.,1.);o_transform=vec4(float(Ul),float(Um),float(Un),1.);}`)}ie(){return this.Jt}Tt(){return this.te}re(){return this.ee}ne(){return this.se}oe(t){return new N(this.vt,K,t)}ae(t,i){return new N(this.vt,t,i)}Gt(){this.Jt.Gt(),this.te.Gt(),this.ee.Gt(),this.se.Gt()}}var b=(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))(b||{});class At{constructor(t){l(this,"vt");l(this,"he",new Map);this.vt=t}ce(t,i,r,n){const o=this.vt;let a=this.he.get(t);a||(a=new Map,this.he.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.ue.le.size,o.FLOAT,!1,r.fe,r.ue.le.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ue.de.size,o.FLOAT,!1,r.fe,r.ue.de.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}pe(){this.vt.bindVertexArray(null)}Gt(){for(const[,t]of this.he)for(const[,i]of t)i&&this.vt.deleteVertexArray(i)}}class xt{constructor(t,i){l(this,"me");l(this,"vt");l(this,"xt");l(this,"ge",null);l(this,"_e",null);this.vt=t,this.me=new At(t),this.xt=i}ve(t,i,r){const{shader:n}=t,o=V(this.vt)||this.vt.getParameter(this.vt.VIEWPORT);n.Vt({U9:o[2]/o[3],Uy:[o[2],o[3]]});const a=f=>{if(!f||!f.ye())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.me.ce(n.Qt,f.type+"",g,d),f.batch.Ae(n),f.batch.we(g.Ce,g.be)}finally{f.batch.xe(n),this.me.pe(),f.$e()}};let h=null,u=null;for(const f of i){if(f.type===b.CUSTOM){u&&(a(u),h=null,u=null),this.Me(t,f.params,f.state,r.get(b.RECTANGLE));continue}h!==null&&f.type!==h&&(a(u),h=null,u=null);let g=u;g&&f.type===h||(g=r.get(f.type)||null,u=g,h=f.type),g&&g.Fe(f.params,f.state)}a(u)}Me(t,i,r,n){const{x:o,y:a,width:h,height:u,shader:f,uniforms:g}=i,d=this.Re(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)));d.begin(),this.ze(n,f,g,0,0,d.width,d.height,{}),d.end();const m=this.Pe(),x={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.ze(n,m,x,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),t.shader.Xt()}ze(t,i,r,n,o,a,h,u){i.Xt(),i.Vt(r);const f=this.vt.getParameter(this.vt.VIEWPORT);if(i.Vt({U9:f[2]/f[3],Uy:[f[2],f[3]]}),t.$e(),t.Fe({x:n,y:o,width:a,height:h},u),t.ye()){const g=t.unitGeometry,d=t.unitBuffer;try{this.me.ce(i.Qt,t.type+"",g,d),t.batch.Ae(i),t.batch.we(g.Ce,g.be)}finally{t.batch.xe(i),this.me.pe(),t.$e()}}}Pe(){return this.xt.ie()}Re(t,i){return this.ge&&this._e&&this._e.w===t&&this._e.h===i||(this.ge&&this.ge.Gt(),this.ge=new j(this.vt,t,i,5),this._e={w:t,h:i}),this.ge}Gt(){this.me.Gt(),this.ge&&this.ge.Gt()}}class yt{constructor(){l(this,"Te",[]);l(this,"Se",1);l(this,"Ee",0)}Be(t){if(this.Ee>=this.Te.length){const r={id:this.Se++,type:t,params:{},state:{I:1,N:0,X:0,W:0,j:[0,0,0],Y:[1,1,1,1],q:[0,0,0,1],V:!1,K:!1,D:!1,L:[0,0]}};this.Te.push(r)}const i=this.Te[this.Ee];return i.id=this.Se++,i.type=t,this.Ee++,i}Ge(t,i,r,n,o){const a=this.Be(b.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.J(a.state),a.id}De(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}Le(t,i,r,n,o,a){const h=this.Be(b.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.J(h.state),h.id}Oe(t,i,r,n,o){const a=this.Be(b.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.J(a.state),a.id}ke(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}He(t,i,r,n,o,a,h){const u=this.Be(b.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.J(u.state),u.id}Ie(t,i,r,n,o,a,h,u,f,g){const d=this.Be(b.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Ee}get isEmpty(){return this.Ee===0}Ne(){this.Ee=0}[Symbol.iterator](){let t=0;const i=this.Ee,r=this.Te;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const D=class D{static Xe(t,i,r=0){var a,h,u,f,g,d,m,x,A,p;const n=i||new Float32Array(D.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.le[0],n[o++]=t.le[1],n[o++]=t.Ee[0],n[o++]=t.Ee[1],n[o++]=t.j[0],n[o++]=t.j[1],n[o++]=t.j[2],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.Y[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.L[0],n[o++]=t.L[1],n[o++]=t.We[0],n[o++]=t.We[1],n[o++]=t.We[2],n[o++]=t.N,n[o++]=t.X,n[o++]=t.W,n[o++]=t.Ve[0],n[o++]=t.Ve[1],n[o++]=((a=t.Ke)==null?void 0:a[0])||0,n[o++]=((h=t.Ke)==null?void 0:h[1])||0,n[o++]=((u=t.je)==null?void 0:u[0])||0,n[o++]=((f=t.je)==null?void 0:f[1])||0,n[o++]=((g=t.Ye)==null?void 0:g[0])||0,n[o++]=((d=t.Ye)==null?void 0:d[1])||0,n[o++]=((m=t.qe)==null?void 0:m[0])||0,n[o++]=((x=t.qe)==null?void 0:x[1])||0,n[o++]=((A=t.Ze)==null?void 0:A[0])||0,n[o++]=((p=t.Ze)==null?void 0:p[1])||0,n}static Qe(t){const i=t.length*D.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*D.FLOATS_PER_INSTANCE;D.Xe(t[n],r,o)}return r}};l(D,"BYTES_PER_INSTANCE",140),l(D,"FLOATS_PER_INSTANCE",35);let I=D;const U=class U{};l(U,"STRIDE",I.BYTES_PER_INSTANCE),l(U,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let q=U;class Et{constructor(t,i=1e3,r=1.5){l(this,"vt");l(this,"Je",[]);l(this,"ts");l(this,"es");l(this,"ss",null);l(this,"rs",!0);l(this,"ns",0);l(this,"hs",new Map);l(this,"cs",null);this.vt=t,this.ts=i,this.es=r,this.ls()}Fe(t){const i=this.Je.length;return this.Je.push(t),this.rs=!0,i}get count(){return this.Je.length}get isEmpty(){return this.Je.length===0}clear(){this.Je.length=0,this.rs=!0}us(t){if(t<=this.ts)return;const i=Math.ceil(t*this.es);this.ts=i,this.ls()}ls(){const t=this.vt;this.ss&&t.deleteBuffer(this.ss),this.ss=t.createBuffer();const i=this.ts*I.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ss),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!0,this.ns=0}fs(){if(!this.rs||this.Je.length===0)return;const t=this.vt,i=this.Je.length;this.us(i),(!this.cs||this.cs.length<i*I.FLOATS_PER_INSTANCE)&&(this.cs=new Float32Array(i*I.FLOATS_PER_INSTANCE));const r=I.Qe(this.Je);t.bindBuffer(t.ARRAY_BUFFER,this.ss),i<=this.ns?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!1,this.ns=i}ds(t){let i=this.hs.get(t);if(!i){i=new Map;const r=this.vt;for(const n in q.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.hs.set(t,i)}return i}Ae(t){if(!this.ss||this.Je.length===0)return;const i=this.vt,r=t.Qt;this.fs();const n=this.ds(r);i.bindBuffer(i.ARRAY_BUFFER,this.ss);for(const[o,a]of n){const h=q.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}xe(t){const i=this.vt,r=this.ds(t.Qt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}we(t,i){this.Je.length!==0&&this.vt.drawArraysInstanced(t,0,i,this.Je.length)}Gt(){this.ss&&this.vt.deleteBuffer(this.ss)}}class z{constructor(t,i,r,n){l(this,"vt");l(this,"ps");l(this,"gs");l(this,"_s");l(this,"vs",null);this.vt=t,this.ps=i,this.gs=r,this._s=n;const o=this.vt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.vt.bindBuffer(this.vt.ARRAY_BUFFER,o),this.vt.bufferData(this.vt.ARRAY_BUFFER,this._s.As,this.vt.STATIC_DRAW),this.vt.bindBuffer(this.vt.ARRAY_BUFFER,null),this.vs=o}get type(){return this.gs}get unitGeometry(){return this._s}get unitBuffer(){return this.vs}get batch(){return this.ps}$e(){this.ps.clear()}ye(){return!this.ps.isEmpty}Gt(){this.ps.Gt(),this.vt.deleteBuffer(this.vs)}ws(t,i,r,n,o){const a=this.Cs(t,i,r,n,o.N||0,o.X||0,o.W||0);return{le:[t,i],Ee:[r,n],j:o.j||[0,0,0],Y:o.Y||[1,1,1,1],q:o.q||[0,0,0,1],L:o.L||[0,0],We:[o.D?1:0,o.V?1:0,o.K?1:0],N:a.radiansX,X:a.radiansY,W:a.radiansZ,Ve:[a.centerX,a.centerY]}}bs(t,i){const r=V(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}$s(t,i,r){const n=this.bs(i,r);t.Ve=[n.nx,n.ny]}Cs(t,i,r,n,o,a,h){const u=V(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/g}}}const wt={As: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]),be:6,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class bt extends z{constructor(t,i){super(t,i,b.RECTANGLE,wt)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.ps.Fe(r)}}const Rt={As: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]),be:6,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Tt extends z{constructor(t,i){super(t,i,b.LINE,Rt)}Fe(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=t.thickness||i.I||1,h=t.x1+r/2,u=t.y1+n/2,f=h-o/2,g=u,d=this.ws(f,g,o,a,i);return this.$s(d,h,u),this.ps.Fe(d)}}const Ct={As: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),f=.5*(h+1),g=Math.cos(o),d=Math.sin(o),m=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,a,h,u,f,g,d,m,x)}return new Float32Array(t)}(32),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ut extends z{constructor(t,i){super(t,i,b.ELLIPSE,Ct)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.$s(r,t.x,t.y),this.ps.Fe(r)}}let Ft={As: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),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class St extends z{constructor(t,i){super(t,i,b.ARC,Ft)}Fe(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.ws(r,n,t.width,t.height,i);return this.$s(h,t.x,t.y),h.Ke=[o,a],this.ps.Fe(h)}}const Bt={As:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),be:3,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Pt extends z{constructor(t,i){super(t,i,b.TRIANGLE,Bt)}Fe(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.ws(r,o,a,h,i),f=r+.5*a,g=o+h*(1/3);return this.$s(u,f,g),this.ps.Fe(u)}}function at(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 Lt={As: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),be:96,Ce:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Mt extends z{constructor(t,i){super(t,i,b.BEZIER_CURVE,Lt)}Fe(t,i){const r=i.I||1,n=at(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=at(.5,t.y1,t.cp1y,t.cp2y,t.y2),a=this.ws(0,0,1,r,i);return this.$s(a,n,o),a.qe=[t.x1,t.y1],a.je=[t.cp1x,t.cp1y],a.Ye=[t.cp2x,t.cp2y],a.Ze=[t.x2,t.y2],this.ps.Fe(a)}}class Dt{constructor(t){l(this,"vt");l(this,"Ms",null);l(this,"Fs");l(this,"Rs",null);l(this,"zs",{});l(this,"Ps",null);l(this,"Ts",new Map);l(this,"Ss");l(this,"Es");l(this,"Bs");l(this,"k",[]);this.vt=t,this.Fs=new vt(t),this.Bs=new nt,this.Ss=new xt(t,this),this.Es=new yt,this.Ps=t.createBuffer(),Y(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}Gs(t){let i=this.Ts.get(t);if(i)return i;const r=new Et(this.vt);return i=(0,{[b.RECTANGLE]:()=>new bt(this.vt,r),[b.LINE]:()=>new Tt(this.vt,r),[b.ELLIPSE]:()=>new Ut(this.vt,r),[b.ARC]:()=>new St(this.vt,r),[b.TRIANGLE]:()=>new Pt(this.vt,r),[b.BEZIER_CURVE]:()=>new Mt(this.vt,r)}[t])(),this.Ts.set(t,i),i}Ds(t){this.Ms!==t&&(this.Ms=t,t.Xt())}ae(t,i){return this.Fs.ae(t,i)}ie(){return this.Fs.ie()}Tt(){return this.Fs.Tt()}re(){return this.Fs.re()}ne(){return this.Fs.ne()}Ls(t){this.Rs=t,t&&(this.zs={})}Kt(t,i){this.zs[t]=i}Os(t){Object.assign(this.zs,t)}oe(t){return this.Fs.oe(t)}ks(t,i,r,n,o){const a=this.ie(),h={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.Es.De(i,r,n,o,a,h,this.Bs)}Hs(t,i,r,n,o){const a=this.ne(),h=t.texture,u=t.flags,f=t.charRotationRG,g=[f[0],f[1]],d=t.colorUniforms??{charColorFixed:!1,Y:[1,1,1],cellColorFixed:!1,cellColor:[0,0,0],backgroundColor:[0,0,0,1]},m=t.characterListUniforms,x={Uk:h,Ul:!!u.invert,Um:!!u.flipX,Un:!!u.flipY,Uo:g,Up:!!d.charColorFixed,Uq:d.Y,Ur:!!d.cellColorFixed,Us:d.cellColor,Ut:d.backgroundColor,Uu:m.count,Uv:m.list};this.Es.De(i,r,n,o,a,x,this.Bs)}Is(t,i,r,n){var p;const o=this.vt,a=o.canvas.width,h=o.canvas.height,u=t/a*2-1,f=(t+r)/a*2-1,g=1-i/h*2,d=1-(i+n)/h*2,m=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.Ps),o.bufferData(o.ARRAY_BUFFER,m,o.DYNAMIC_DRAW);const x=((p=this.Ms)==null?void 0:p.Qt)||o.getParameter(o.CURRENT_PROGRAM),A=x?o.getAttribLocation(x,"a_position"):-1;A!==-1&&(o.enableVertexAttribArray(A),o.vertexAttribPointer(A,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),A!==-1&&o.disableVertexAttribArray(A)}Ns(t,i,r,n){this.Rs?(this.Es.De(t,i,r,n,this.Rs,{...this.zs},this.Bs),this.Rs=null,this.zs={}):this.Es.Ge(t,i,r,n,this.Bs)}Xs(t,i,r,n){this.Es.Le(t,i,r,n,this.Bs.lineWeight,this.Bs)}Ws(t,i,r,n){this.Es.Oe(t,i,r,n,this.Bs)}Vs(t,i,r,n,o,a){this.Es.He(t,i,r,n,o,a,this.Bs)}Ks(t,i,r,n,o,a,h,u){const f=this.Bs.lineWeight;this.Es.Ie(t,i,r,n,o,a,h,u,f,this.Bs)}js(t,i,r=1,n={}){return new j(this.vt,t,i,r,n,this,!0)}Ys(t,i,r,n,o,a){this.Es.ke(t,i,r,n,o,a,this.Bs)}qs(t,i=t,r=t,n=255){this.state.ft(t,i,r,n),this.Ne(t/255,i/255,r/255,n/255)}Ne(t=0,i=0,r=0,n=0){this.vt.clearColor(t,i,r,n),this.vt.clear(this.vt.COLOR_BUFFER_BIT)}Zs(){this.vt.viewport(0,0,this.vt.canvas.width,this.vt.canvas.height),Y(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}get context(){return this.vt}get state(){return this.Bs}Et(t){this.k.push(this.Bs),this.Bs=t}Bt(){const t=this.k.pop();t&&(this.Bs=t)}St(t){const i=t,r=V(this.vt)??this.vt.getParameter(this.vt.VIEWPORT),n={shader:i,gl:this.vt,viewport:r};this.Ds(i);const o=new Set;for(const a of this.Es)a.type===b.CUSTOM?o.add(b.RECTANGLE):o.add(a.type);for(const a of o)a!==b.CUSTOM&&this.Gs(a);this.Ss.ve(n,this.Es,this.Ts),this.Es.Ne()}Gt(){this.vt.deleteBuffer(this.Ps),this.Es.Ne();for(const t of this.Ts.values())t.Gt();this.Fs.Gt(),this.Ss.Gt()}}const T={readShort:(c,t)=>(T.t.uint16[0]=c[t]<<8|c[t+1],T.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(T.readUshort(c,t+2*n));return r},readUint(c,t){const i=T.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],T.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},writeUshort(c,t,i){c[t]=i>>>8&255,c[t+1]=255&i},writeUint(c,t,i){c[t]=i>>>24&255,c[t+1]=i>>>16&255,c[t+2]=i>>>8&255,c[t+3]=255&i},writeASCII(c,t,i){for(let r=0;r<i.length;r++)c[t+r]=255&i.charCodeAt(r)},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()};function Z(c){return c+3&-4}function Q(c,t,i){const r=t+i;let n=0;const o=T.t;for(let a=t;a<r;a+=4)o.uint8[3]=c[a]||0,o.uint8[2]=c[a+1]||0,o.uint8[1]=c[a+2]||0,o.uint8[0]=c[a+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class _t{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function k(c){let t=32,i=0;for(const h of c)h&&(h<t&&(t=h),h>i&&(i=h));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const h of c)h&&r[h]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let h=1;h<=i;h++)o=o+r[h-1]<<1,n[h]=o;const a=new Map;for(let h=0;h<c.length;h++){const u=c[h];if(!u)continue;const f=n[u]++;let g=a.get(u);g||(g=[],a.set(u,g)),g[It(f,u)]=h}return{min:t,max:i,table:a}}function tt(c,t){let i=0;for(let r=1;r<=t.max;r++){i|=c.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function It(c,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&c,c>>>=1;return i>>>0}function Gt(c){if(c.length<2)throw Error("ZLIB data too short");const t=c[0],i=c[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,a){const h=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const m=o.readBits(2);if(m===0){o.alignToByte();const x=o.readBits(16);if((65535&(65535^x))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let A=0;A<x;A++)a.push(o.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let x,A;if(m===1){const p=Array(288).fill(0);for(let y=0;y<=143;y++)p[y]=8;for(let y=144;y<=255;y++)p[y]=9;for(let y=256;y<=279;y++)p[y]=7;for(let y=280;y<=287;y++)p[y]=8;x=k(p),A=k(Array(32).fill(5))}else{const p=o.readBits(5)+257,y=o.readBits(5)+1,v=o.readBits(4)+4,w=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],E=Array(19).fill(0);for(let P=0;P<v;P++)E[w[P]]=o.readBits(3);const B=k(E),F=[];for(;F.length<p+y;){const P=tt(o,B);if(P<=15)F.push(P);else if(P===16){const H=o.readBits(2)+3,O=F[F.length-1]||0;for(let mt=0;mt<H;mt++)F.push(O)}else if(P===17){const H=o.readBits(3)+3;for(let O=0;O<H;O++)F.push(0)}else{if(P!==18)throw Error("Invalid code length symbol");{const H=o.readBits(7)+11;for(let O=0;O<H;O++)F.push(0)}}}const S=F.slice(0,p),L=F.slice(p,p+y);x=k(S),A=k(L)}for(;;){const p=tt(o,x);if(p<256)a.push(p);else{if(p===256)break;if(p>256&&p<286){const y=p-257;let v=h[y];const w=u[y];w&&(v+=o.readBits(w));const E=tt(o,A);if(E>=30)throw Error("Invalid distance symbol");let B=f[E];const F=g[E];F&&(B+=o.readBits(F));const S=a.length-B;if(S<0)throw Error("Invalid distance");for(let L=0;L<v;L++)a.push(a[S+L]||0)}else if(p===286||p===287)throw Error("Reserved length symbol")}}}}}}(new _t(c.subarray(r)),n),new Uint8Array(n)}function Ot(c){const t=T,i=new Uint8Array(c);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),a=[];let h=44;for(let v=0;v<n;v++){const w=t.readASCII(i,h,4),E=t.readUint(i,h+4),B=t.readUint(i,h+8),F=t.readUint(i,h+12),S=t.readUint(i,h+16);a.push({tag:w,offset:E,compLength:B,origLength:F,checksum:S}),h+=20}for(const v of a){const w=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(w);else if(v.data=Gt(w),v.data.length!==v.origLength)if(v.data.length<v.origLength){const E=new Uint8Array(v.origLength);E.set(v.data),v.data=E}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,m=16*u-d;let x=12+16*u;const A={};for(const v of a)A[v.tag]=x,x=Z(x+v.data.length);const p=new Uint8Array(Math.max(o||0,x));t.writeUint(p,0,r),t.writeUshort(p,4,u),t.writeUshort(p,6,d),t.writeUshort(p,8,g),t.writeUshort(p,10,m);let y=12;for(const v of a){t.writeASCII(p,y,v.tag),y+=4;let w=v.data;if(v.tag==="head"&&w.length>=12){const E=new Uint8Array(w);t.writeUint(E,8,0);const B=Q(E,0,Z(E.length));t.writeUint(p,y,B),y+=4}else{const E=Q(w,0,Z(w.length));t.writeUint(p,y,E),y+=4}t.writeUint(p,y,A[v.tag]),y+=4,t.writeUint(p,y,v.data.length),y+=4}for(const v of a){const w=A[v.tag];p.set(v.data,w)}if(a.find(v=>v.tag==="head")){const v=A.head,w=function(E,B){const F=T,S=B+8,L=[E[S],E[S+1],E[S+2],E[S+3]];F.writeUint(E,S,0);const P=2981146554-(Q(E,0,Z(E.length))>>>0)>>>0;return E[S]=L[0],E[S+1]=L[1],E[S+2]=L[2],E[S+3]=L[3],P>>>0}(p,v);t.writeUint(p,v+8,w)}return p.buffer}const Nt={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=T,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let u=0;u<a;u++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const m=`p${f}e${g}`;let x=h.indexOf(d);if(x===-1){let A;x=r.tables.length,h.push(d);const p=o(c,d);A=p===4?this.parse4(c,d):p===12?this.parse12(c,d):{format:p},r.tables.push(A)}r.ids[m]=x}return r},parse4(c,t){const i=T,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 f=0;f<h;f++)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=T.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}}},zt={parseTab(c,t,i){const r=T;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)}}},Xt={parseTab(c,t,i){const r=T;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=T,o=[],a=[],h=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)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}}},ht={cmap:Nt,head:zt,hhea:Xt,maxp:{parseTab(c,t,i){const r=T;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Wt,loca:{parseTab(c,t,i,r){const n=T,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},Qs(c,t){const i=T,r=c.Js,n=c.loca;if(n[t]===n[t+1])return null;const o=M.findTable(r,"glyf",c.ti);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 m=0;m<h.noc;m++)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 f=h.endPts[h.noc-1]+1;h.flags=[];for(let m=0;m<f;m++){const x=r[a];if(a++,h.flags.push(x),8&x){const A=r[a];a++;for(let p=0;p<A;p++)h.flags.push(x),m++}}h.xs=[];for(let m=0;m<f;m++){const x=h.flags[m],A=!!(16&x);2&x?(h.xs.push(A?r[a]:-r[a]),a++):A?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let m=0;m<f;m++){const x=h.flags[m],A=!!(32&x);4&x?(h.ys.push(A?r[a]:-r[a]),a++):A?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let g=0,d=0;for(let m=0;m<f;m++)g+=h.xs[m],d+=h.ys[m],h.xs[m]=g,h.ys[m]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},M={parse(c){const t=new Uint8Array(c),i=T.readASCII(t,0,4);if(i==="wOFF")c=Ot(c);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,a)=>{const h=ht,u={Js:r,ei:n,ti:o};for(const f in h){const g=f,d=M.findTable(r,g,o);if(d){const[m,x]=d;let A=a[m];A==null&&(A=h[g].parseTab(r,m,x,u),a[m]=A),u[g]=A}}return u})(new Uint8Array(c),0,0,{})]},findTable(c,t,i){const r=T,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),f=r.readUint(c,o+12);if(h===t)return[u,f];o+=16}return null},T:ht,B:T};class kt{si(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(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.ai(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}ri(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}ai(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}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){l(this,"hi",new Map);l(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.hi.has(r))return this.hi.get(r);const n=t.cmap;if(!n||!n.tables)return this.hi.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.fi(i,a):a.format===12&&(o=this.di(i,a)),o>0)break;return this.hi.set(r,o),o}pi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}mi(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}gi(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}}_i(){this.hi.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Js.length}`}fi(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}di(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 Ht{constructor(t){l(this,"yi");l(this,"Ai");l(this,"xt");l(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ai=this.yi.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,f=i.height*h,g=typeof n=="object"?n:null;this.Ci(u,f),this.bi(t,i,a,r,g);const d=this.xt.js(u,f,1,{filter:"nearest"});return d.zt(this.yi),{framebuffer:d,columns:a,rows:h}}Ci(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=t+"px",this.Ai.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ai.fillStyle="black",this.Ai.fillRect(0,0,t,i),this.Ai.textBaseline="top",this.Ai.textAlign="left",this.Ai.fillStyle="white"}bi(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const u=h%r,f=Math.floor(h/r),g=t[h].character,d=this.xi(o,g);if(!d)continue;const m=g.codePointAt(0)||0,x=this.wi.li(o,m),A=this.$i(o,x)*a,p=u*i.width,y=f*i.height,v=p+.5*i.width,w=y+.5*i.height,E=Math.round(v-.5*i.width),B=Math.round(w-.5*n),F=E+.5*(i.width-A),S=B+o.hhea.ascender*a;this.Mi(d,F,S,a)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(M&&M.T&&M.T.glyf){const o=M.T.glyf.Qs(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}$i(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Mi(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.Ai.beginPath();let f=0;for(let g=0;g<h.length;g++){const d=h[g];if(!(d<f)){if(d>=f){const m=i+o[f]*n,x=r-a[f]*n;this.Ai.moveTo(m,x);let A=f+1;for(;A<=d;)if(1&u[A]){const p=i+o[A]*n,y=r-a[A]*n;this.Ai.lineTo(p,y),A++}else{const p=i+o[A]*n,y=r-a[A]*n;let v=A+1>d?f:A+1;if(1&u[v]){const w=i+o[v]*n,E=r-a[v]*n;this.Ai.quadraticCurveTo(p,y,w,E),A=v+1}else{const w=(p+(i+o[v]*n))/2,E=(y+(r-a[v]*n))/2;this.Ai.quadraticCurveTo(p,y,w,E),A=v}}this.Ai.closePath()}f=d+1}}this.Ai.fill()}}class Yt{constructor(){l(this,"Fi");this.Fi=new et}Ri(t,i,r){let n=0;const o=this.Fi.gi(r,i),a=o.lineHeight;for(const h of t){const u=this.Fi.pi(r,h);if(u===0)continue;const f=this.Fi.mi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}_i(){this.Fi._i()}}class Vt{constructor(){l(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.zi(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(h=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:a,advanceWidth:h}})}zi(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Pi(t,i){if(!W.v(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]}Ti(t,i){return W.v(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.Pi(r,i)||[0,0,0]):[[0,0,0]]}}class ct{constructor(t,i=16){l(this,"Si");l(this,"Ei",[]);l(this,"Bi");l(this,"Gi",16);l(this,"Di",0);l(this,"Li",0);l(this,"Oi",{width:0,height:0});l(this,"ki");l(this,"Hi");l(this,"Ii");l(this,"Ni");l(this,"Xi");this.Gi=i,this.Hi=new kt,this.Ii=new Ht(t),this.Ni=new Yt,this.Xi=new Vt}async Wi(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new R(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,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")).arrayBuffer();await this.Vi(i),this.Si=M.parse(i)[0],await this.Ki()}ji(t){if(t===void 0)return this.Gi;this.Gi=t,this.Oi=this.Ni.Ri(this.Ei.map(r=>r.character),this.Gi,this.Si);const i=this.Ii.createTextureAtlas(this.Ei,this.Oi,this.Gi,this.Si);this.Bi=i.framebuffer,this.Di=i.columns,this.Li=i.rows}async Yi(t){try{const i=await fetch(t);if(!i.ok)throw new R(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Vi(r);const n=M.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Si=n[0],await this.Ki()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Vi(t){const i=Date.now();this.ki=new FontFace("CustomFont_"+i,t),await this.ki.load(),document.fonts.add(this.ki)}async Ki(){const t=this.Hi.si(this.Si),i=this.Hi.ni(t);this.Ei=this.Xi.createCharacterObjects(i,this.Si),this.Oi=this.Ni.Ri(i,this.Gi,this.Si);const r=this.Ii.createTextureAtlas(this.Ei,this.Oi,this.Gi,this.Si);this.Bi=r.framebuffer,this.Di=r.columns,this.Li=r.rows}Pi(t){return this.Xi.Pi(t,this.Ei)}Ti(t){return this.Xi.Ti(t,this.Ei)}Gt(){this.Bi.Gt(),document.fonts.delete(this.ki)}get fontFramebuffer(){return this.Bi}get characters(){return this.Ei}get textureColumns(){return this.Di}get textureRows(){return this.Li}get maxGlyphDimensions(){return this.Oi}get fontSize(){return this.Gi}get font(){return this.Si}}class lt{constructor(t,i,r){l(this,"qi");l(this,"Zi");l(this,"dt");l(this,"gt");l(this,"Qi");l(this,"Ji");l(this,"tr");l(this,"er");l(this,"sr");this.tr=t,this.er=i,this.sr=r,this.ir()}ir(){this.qi=Math.floor(this.tr.width/this.er),this.Zi=Math.floor(this.tr.height/this.sr),this.dt=this.qi*this.er,this.gt=this.Zi*this.sr,this.Qi=Math.floor((this.tr.width-this.dt)/2),this.Ji=Math.floor((this.tr.height-this.gt)/2)}rr(t,i){this.er=t,this.sr=i,this.ir()}get cellWidth(){return this.er}get cellHeight(){return this.sr}get cols(){return this.qi}get rows(){return this.Zi}get width(){return this.dt}get height(){return this.gt}get offsetX(){return this.Qi}get offsetY(){return this.Ji}}class ut{constructor(t={}){l(this,"tr");l(this,"nr",null);l(this,"ar",!1);l(this,"hr");l(this,"cr");this.ar=t.overlay??!1,this.ar&&t.canvas?(this.nr=t.canvas,this.tr=this.lr(),this.cr=!0,this.ur()):t.canvas?(this.tr=t.canvas,this.cr=!1):(this.tr=this.dr(t.width,t.height),this.cr=!0),this.tr.style.imageRendering="pixelated"}dr(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}lr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.nr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.nr instanceof HTMLVideoElement){const h=this.nr;(r===0||n===0)&&h.videoWidth>0&&h.videoHeight>0&&(r=h.videoWidth,n=h.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.nr);let a=parseInt(o.zIndex||"0",10);return isNaN(a)&&(a=0),t.style.zIndex=""+(a+1),t}ur(){var t;this.pr(),(t=this.nr.parentNode)==null||t.insertBefore(this.tr,this.nr.nextSibling),window.ResizeObserver&&(this.hr=new ResizeObserver(()=>{this.mr()}),this.hr.observe(this.nr)),window.addEventListener("resize",()=>{this.mr()})}pr(){if(!this.nr)return;const t=this.nr.getBoundingClientRect();let i=this.nr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.tr.style.top=t.top-r.top+"px",this.tr.style.left=t.left-r.left+"px"}else this.tr.style.top=t.top+window.scrollY+"px",this.tr.style.left=t.left+window.scrollX+"px"}mr(t,i){if(this.ar){const r=this.nr.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.nr instanceof HTMLVideoElement){const a=this.nr;(n===0||o===0)&&a.videoWidth>0&&a.videoHeight>0&&(n=a.videoWidth,o=a.videoHeight)}this.tr.width=n,this.tr.height=o,this.pr()}else this.tr.width=t??this.tr.width,this.tr.height=i??this.tr.height}gr(){const t=this.tr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new R("`textmode.js` requires WebGL2 support.");return t}Gt(){this.hr&&this.hr.disconnect();const t=this.tr.getContext("webgl")||this.tr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.cr&&this.tr.parentNode&&this.tr.parentNode.removeChild(this.tr)}get canvas(){return this.tr}get targetCanvas(){return this.nr}get width(){return this.tr.width}get height(){return this.tr.height}}class X{constructor(t,i,r,n){l(this,"texture");l(this,"width");l(this,"height");l(this,"vt");l(this,"D",0);l(this,"V",0);l(this,"K",0);l(this,"L",[0,0]);l(this,"_r","sampled");l(this,"vr","fixed");l(this,"Y",[1,1,1]);l(this,"q",[0,0,0]);l(this,"yr",[0,0,0,1]);l(this,"Ar",[[.1,0,0]]);l(this,"wr");this.vt=t,this.texture=i,this.width=r,this.height=n}Gt(){this.vt.deleteTexture(this.texture)}Cr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.D=this.Cr(t),this}flipX(t=!0){return this.V=this.Cr(t),this}flipY(t=!0){return this.K=this.Cr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.L=[r,n],this}get flags(){return{invert:this.D,flipX:this.V,flipY:this.K}}get charRotationRG(){return this.L}charColorMode(t){return this._r=t,this}cellColorMode(t){return this.vr=t,this}charColor(t,i,r){return this.Y=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}cellColor(t,i,r){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}background(t,i,r,n){return this.yr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}charactersFromColors(t){const i=t.filter(r=>Array.isArray(r)).slice(0,64);return this.Ar=i,this}characters(t){const i=this.wr(t);return this.charactersFromColors(i),this}get characterListUniforms(){return{count:this.Ar.length,list:this.Ar}}get colorUniforms(){return{charColorFixed:this._r==="fixed",Y:this.Y,cellColorFixed:this.vr==="fixed",cellColor:this.q,backgroundColor:this.yr}}static fromSource(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const a=i.naturalWidth??i.width??i.videoWidth??0,h=i.naturalHeight??i.height??i.videoHeight??0,u=new X(n,o,a,h);return u.wr=r,u}}class jt{constructor(t=60){l(this,"br");l(this,"$r");l(this,"Mr",null);l(this,"Fr",0);l(this,"Rr",!0);l(this,"zr",0);l(this,"Pr",0);l(this,"Tr",[]);l(this,"Sr",10);l(this,"Er",0);this.br=t,this.$r=1e3/t}start(t){if(!this.Rr)return;this.Fr=performance.now();const i=r=>{if(!this.Rr)return void(this.Mr=null);const n=r-this.Fr;n>=this.$r&&(t(),this.Fr=r-n%this.$r),this.Rr&&(this.Mr=requestAnimationFrame(i))};this.Mr=requestAnimationFrame(i)}stop(){this.Mr&&(cancelAnimationFrame(this.Mr),this.Mr=null)}pause(){this.Rr&&(this.Rr=!1,this.stop())}resume(t){this.Rr||(this.Rr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.zr;this.br=t,this.$r=1e3/t,this.Rr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Pr>0){const i=t-this.Pr;this.Tr.push(i),this.Tr.length>this.Sr&&this.Tr.shift();const r=this.Tr.reduce((n,o)=>n+o,0)/this.Tr.length;this.zr=1e3/r}this.Pr=t}get isLooping(){return this.Rr}get frameRateLimit(){return this.br}get currentFrameRate(){return this.zr}get frameCount(){return this.Er}set frameCount(t){this.Er=t}incrementFrame(){this.Er++}resetFrameCount(){this.Er=0}}class Kt{constructor(){l(this,"Br",new Map);l(this,"Gr",null);l(this,"Dr",null);l(this,"Lr");l(this,"Or");l(this,"kr",!1);l(this,"Hr");l(this,"Ir");l(this,"Nr",{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"})}Xr(){this.kr||(this.Lr=t=>{this.Wr(t)},this.Or=t=>{this.Vr(t)},window.addEventListener("keydown",this.Lr,{passive:!1}),window.addEventListener("keyup",this.Or,{passive:!1}),this.kr=!0)}Kr(){this.kr&&(window.removeEventListener("keydown",this.Lr),window.removeEventListener("keyup",this.Or),this.kr=!1,this.Br.clear(),this.Gr=null,this.Dr=null)}jr(t){this.Hr=t}Yr(t){this.Ir=t}qr(t){const i=this.Zr(t),r=this.Br.get(t)||this.Br.get(i);return(r==null?void 0:r.isPressed)||!1}Qr(){return this.Gr}Jr(){return this.Dr}tn(){const t=[];for(const[i,r]of this.Br)r.isPressed&&t.push(i);return t}en(){return{ctrl:this.qr("Control"),shift:this.qr("Shift"),alt:this.qr("Alt"),meta:this.qr("Meta")}}sn(){this.Br.clear(),this.Gr=null,this.Dr=null}Wr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Gr=i,this.Hr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Hr(o)}}Vr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.Dr=i,this.Ir){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Ir(o)}}Zr(t){return this.Nr[t]||t.toLowerCase()}}class qt{constructor(t){l(this,"tr");l(this,"rn");l(this,"nn",{x:-1,y:-1});l(this,"an",{x:-1,y:-1});l(this,"hn",null);l(this,"cn");l(this,"ln");l(this,"un");l(this,"fn");l(this,"dn");l(this,"pn");l(this,"kr",!1);l(this,"mn");l(this,"gn");l(this,"_n");l(this,"vn");l(this,"yn");this.tr=t}Wi(t){this.rn=t,this.An()}Xr(){if(this.kr)return;const t=this.tr.canvas;this.cn=i=>{this.wn(i),this.Cn(i)},this.ln=()=>{this.an={...this.nn},this.nn.x=-1,this.nn.y=-1,this.hn=null},this.un=i=>{this.wn(i),this.bn(i)},this.fn=i=>{this.wn(i),this.xn(i)},this.dn=i=>{this.wn(i),this.$n(i)},this.pn=i=>{this.wn(i),this.Mn(i)},t.addEventListener("mousemove",this.cn,{passive:!0}),t.addEventListener("mouseleave",this.ln,{passive:!0}),t.addEventListener("mousedown",this.un,{passive:!0}),t.addEventListener("mouseup",this.fn,{passive:!0}),t.addEventListener("click",this.dn,{passive:!0}),t.addEventListener("wheel",this.pn,{passive:!1}),this.kr=!0}Kr(){if(!this.kr)return;const t=this.tr.canvas;t.removeEventListener("mousemove",this.cn),t.removeEventListener("mouseleave",this.ln),t.removeEventListener("mousedown",this.un),t.removeEventListener("mouseup",this.fn),t.removeEventListener("click",this.dn),t.removeEventListener("wheel",this.pn),this.kr=!1}An(){if(this.kr)try{if(this.hn){const t=new MouseEvent("mousemove",{clientX:this.hn.x,clientY:this.hn.y,bubbles:!1,cancelable:!1});this.wn(t)}else this.nn.x!==-1&&this.nn.y!==-1&&(this.nn.x>=this.rn.cols||this.nn.y>=this.rn.rows)&&(this.nn.x=-1,this.nn.y=-1)}catch{this.nn.x=-1,this.nn.y=-1}}Fn(t){this.mn=t}jr(t){this.gn=t}Yr(t){this._n=t}Rn(t){this.vn=t}zn(t){this.yn=t}Pn(){return{x:this.nn.x,y:this.nn.y}}Cn(t){if(this.vn){const i={position:{...this.nn},previousPosition:{...this.an},originalEvent:t};this.vn(i)}}bn(t){if(this.gn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.gn(i)}}xn(t){if(this._n){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this._n(i)}}$n(t){if(this.mn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.mn(i)}}Mn(t){if(this.yn){const i={position:{...this.nn},previousPosition:{...this.an},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.yn(i)}}wn(t){const i=this.tr.canvas;this.an={...this.nn},this.hn={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.rn.offsetX,f=h-this.rn.offsetY,g=Math.floor(u/this.rn.cellWidth),d=Math.floor(f/this.rn.cellHeight);g>=0&&g<this.rn.cols&&d>=0&&d<this.rn.rows?(this.nn.x=g,this.nn.y=d):(this.nn.x=-1,this.nn.y=-1)}}const Zt=c=>class extends c{rotate(t=0,i=0,r=0){this.xt.state.et(t),this.xt.state.st(i),this.xt.state.it(r)}rotateX(t){this.xt.state.et(t)}rotateY(t){this.xt.state.st(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.H()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Ns(t,i,r,n)}point(t,i){this.xt.Ns(t,i,1,1)}line(t,i,r,n){this.xt.Xs(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qs(t,i,r,n)}char(t){this.xt.state.rt(this.Si.Pi(t))}charColor(t,i,r){this.xt.state.nt(t,i,r)}cellColor(t,i,r){this.xt.state.ot(t,i,r)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qs(0,0,0,0)}ellipse(t,i,r,n){this.xt.Ws(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.xt.Vs(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,u){this.xt.Ks(t,i,r,n,o,a,h,u)}arc(t,i,r,n,o,a){this.xt.Ys(t,i,r,n,o,a)}shader(t){this.xt.Ls(t)}setUniform(t,i){this.xt.Kt(t,i)}setUniforms(t){this.xt.Os(t)}createFilterShader(t){return this.xt.oe(t)}createFramebuffer(t){return this.xt.js(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const a=t;this.xt.ks(a,i,r,n??a.width,o??a.height)}else{const a=t;this.xt.Hs(a,i,r,n??a.width,o??a.height)}}async loadImage(t){if(typeof t!="string")return X.fromSource(this.xt,t,n=>this.Si.Ti(n));const i=t,r=await new Promise((n,o)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>n(a),a.onerror=h=>o(h),a.src=i});return X.fromSource(this.xt,r,n=>this.Si.Ti(n))}};class it{Tn(t){const i=t.Pt(0),r=t.Pt(1),n=t.Pt(2),o=t.Pt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.Pt(4),rotationPixels:o}}Sn(t,i){return t[i]+(t[i+1]<<8)}En(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class st{Bn(t,i){return new Blob([t],{type:i})}Gn(t,i,r){try{const n=this.Bn(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){console.error("Failed to download file:",n)}}Dn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Ln(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}On(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}kn(){return"textmode-export-"+this.Dn()}}class $t extends it{Hn(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}}In(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Nn(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.Sn(t.characterPixels,h);let f=this.En(t.primaryColorPixels,h),g=this.En(t.secondaryColorPixels,h);const d=this.Hn(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const x=f;f=g,g=x}const m=this.In(a,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:g,transform:d,position:m}),n++}return r}}class Jt{Xn(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],f=o.groups[a+2];if(i>=h&&i<=u)return f+(i-h)}}return 0}Wn(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.Vn(i,r,n,a)}}Vn(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 f="",g=0;for(let d=0;d<h.length;d++){const m=h[d];if(!(m<g)){if(m>=g){const x=i+o[g]*n,A=r-a[g]*n;f+=`M${x.toFixed(2)},${A.toFixed(2)}`;let p=g+1;for(;p<=m;)if(1&u[p]){const y=i+o[p]*n,v=r-a[p]*n;f+=`L${y.toFixed(2)},${v.toFixed(2)}`,p++}else{const y=i+o[p]*n,v=r-a[p]*n;let w=p+1>m?g:p+1;if(1&u[w]){const E=i+o[w]*n,B=r-a[w]*n;f+=`Q${y.toFixed(2)},${v.toFixed(2)} ${E.toFixed(2)},${B.toFixed(2)}`,p=w+1}else{const E=(y+(i+o[w]*n))/2,B=(v+(r-a[w]*n))/2;f+=`Q${y.toFixed(2)},${v.toFixed(2)} ${E.toFixed(2)},${B.toFixed(2)}`,p=w}}f+="Z"}g=m+1}}return f}Kn(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.Xn(i,a);let u=null;return i.glyf&&i.glyf[h]!==null?u=i.glyf[h]:(u=M.T.glyf.Qs(i,h),i.glyf[h]=u),this.Wn(i,u,r,n,o)}jn(t,i,r,n,o,a,h,u){const f=r+(o-u*(h/i.head.unitsPerEm))/2,g=n+(a+.7*h)/2;return this.Kn(t,i,f,g,h).toSVG()||null}}class Qt{constructor(){l(this,"Yn");this.Yn=new Jt}qn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}Zn(){return"</g></svg>"}Qn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,a]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${a/255})"/>`}Jn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;h.push(`translate(${o} ${a})scale(${u} ${f})translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),` transform="${h.join(" ")}"`}eo(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:a,b:h,a:u}=t.secondaryColor,f=`rgba(${o},${a},${h},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Kn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.Yn.jn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const{r:h,g:u,b:f,a:g}=t.primaryColor,d=`rgba(${h},${u},${f},${g/255})`;return n.drawMode==="stroke"?`<path d="${a}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${a}" fill="${d}"/>`}so(t,i,r,n){const o=[],a=this.eo(t,i,n);a&&o.push(a);const h=this.Kn(t,i,r,n);if(h){const u=this.Jn(t,i);o.push(u?`<g${u}>${h}</g>`:h)}return o.join("")}io(t,i,r,n){const o=[this.qn(i),this.Qn(i,n),'<g id="ascii-cells">'];for(const a of t)o.push(this.so(a,i,r,n));return o.push(this.Zn()),o.join("")}ro(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class te extends st{no(t){return this.Bn(t,"image/svg+xml;charset=utf-8")}oo(t,i){this.Gn(t,this.On(i)+".svg","image/svg+xml;charset=utf-8")}ao(t,i){this.oo(t,i||this.kn())}}class ft{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new $t,this.co=new Qt,this.lo=new te}uo(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.lo.kn()}}fo(t,i={}){const r=this.ho.Nn(this.ho.Tn(t.pipeline),t.grid),n=this.co.io(r,t.grid,t.font,this.uo(i));return this.co.ro(n)}ao(t,i={}){this.lo.ao(this.fo(t,i),i.filename)}}class ee extends it{do(t,i,r,n=" "){var h;const o=[];let a=0;for(let u=0;u<i.rows;u++){const f=[];for(let g=0;g<i.cols;g++){const d=4*a,m=this.Sn(t.characterPixels,d),x=((h=r.characters[m])==null?void 0:h.character)||n;f.push(x),a++}o.push(f)}return o}}class ie{po(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
|
|
12
12
|
`:`
|
|
13
|
-
`;return r.join(n)}}class se extends st{mo(t,i){const r=this._o(i);this.Gn(t,r,"text/plain;charset=utf-8")}_o(t){let i=this.
|
|
13
|
+
`;return r.join(n)}}class se extends st{mo(t,i){const r=this._o(i);this.Gn(t,r,"text/plain;charset=utf-8")}_o(t){let i=this.On(t);return i===".txt"||i.length<=4?this.kn():i}}class dt{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new ee,this.co=new ie,this.lo=new se}uo(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.lo.kn()}}vo(t,i={}){const r=this.uo(i),n=this.ho.do(this.ho.Tn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.co.po(n,r)}mo(t,i={}){this.lo.mo(this.vo(t,i),i.filename)}}class re extends it{yo(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 ne{Ao(t,i){const r=this.wo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async Co(t,i){return new Promise((r,n)=>{const o=this.wo(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)})}wo(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 oe={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gt={png:".png",jpg:".jpg",webp:".webp"};class ae extends st{bo(t,i,r){this.xo(t,this.On(i)+gt[r])}xo(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)}}$o(t){return t in oe&&t in gt}}class he{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new re,this.co=new ne,this.lo=new ae}uo(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.lo.kn()}}Mo(t){if(!this.lo.$o(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 Co(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.co.Co(t.canvas,i);const r=this.ho.yo(t,i.scale,i.backgroundColor);return await this.co.Co(r,i)}async bo(t,i={}){const r=this.uo(i);this.Mo(r);const n=await this.Co(t,r);this.lo.bo(n,r.filename,r.format)}}const ce=c=>class extends c{Fo(){this.xt.St(this.Ro)}toString(t={}){return this.Fo(),new dt().vo({pipeline:this.zo,grid:this.rn,font:this.Si},t)}saveStrings(t={}){this.Fo(),new dt().mo({pipeline:this.zo,grid:this.rn,font:this.Si},t)}toSVG(t={}){return this.Fo(),new ft().fo({pipeline:this.zo,grid:this.rn,font:this.Si},t)}saveSVG(t={}){this.Fo(),new ft().ao({pipeline:this.zo,grid:this.rn,font:this.Si},t)}async saveCanvas(t={}){await new he().bo(this.tr,t)}},le=c=>class extends c{async loadFont(t){return this.Si.Yi(t).then(()=>{const i=this.Si.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.zo.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.Po.An()})}fontSize(t){if(!W.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Si.fontSize===t)return;this.Si.ji(t);const i=this.Si.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.zo.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.Po.An()}glyphColor(t){return this.Si.Pi(t)}glyphColors(t){return this.Si.Ti(t)}},ue=c=>class extends c{get frameCount(){return this.To.frameCount}set frameCount(t){this.To.frameCount=t}frameRate(t){return t===void 0?this.To.currentFrameRate:this.To.frameRate(t,()=>this.So())}noLoop(){this.To.pause()}loop(){this.To.resume(()=>this.So())}redraw(t=1){if(W.v(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.So()}isLooping(){return this.To.isLooping}},fe=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.Po.Fn(t)}mousePressed(t){this.Po.jr(t)}mouseReleased(t){this.Po.Yr(t)}mouseMoved(t){this.Po.Rn(t)}mouseScrolled(t){this.Po.zn(t)}get mouse(){return this.Po.Pn()}},de=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.Eo.jr(t)}keyReleased(t){this.Eo.Yr(t)}isKeyPressed(t){return this.Eo.qr(t)}get lastKeyPressed(){return this.Eo.Qr()}get lastKeyReleased(){return this.Eo.Jr()}get pressedKeys(){return this.Eo.tn()}get modifierState(){return this.Eo.en()}};class ge{constructor(){l(this,"xt");l(this,"Si");l(this,"tr");l(this,"rn");l(this,"To");l(this,"Po");l(this,"Eo");l(this,"Ro");l(this,"zo");l(this,"Bo");l(this,"Go");l(this,"Do")}So(){}}class pt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ge,Zt,ce,le,ue,fe,de){constructor(i={}){super();l(this,"Lo",!1);l(this,"Oo",()=>{});l(this,"ko",()=>{});l(this,"Ho",()=>{});l(this,"Io");l(this,"hr");l(this,"ar",!1);l(this,"No");this.ar=i.overlay??!1,this.tr=new ut(i),this.xt=new Dt(this.tr.gr()),this.Si=new ct(this.xt,i.fontSize??16),this.To=new jt(i.frameRate??60),this.Po=new qt(this.tr),this.Eo=new Kt,this.Ro=this.xt.Tt(),this.Bo=this.xt.re(),this.Xo(i)}async Xo(i){await this.Si.Wi(i.fontSource);const r=this.Si.maxGlyphDimensions;this.rn=new lt(this.tr.canvas,r.width,r.height),this.Po.Wi(this.rn),this.zo=this.xt.js(this.rn.cols,this.rn.rows,5),this.Go=this.xt.js(this.rn.width,this.rn.height,1),this.ar&&(this.No=X.fromSource(this.xt,this.tr.targetCanvas,n=>this.Si.Ti(n))),this.Do=this.xt.ae(ot,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Wo(),this.Oo(),this.To.start(()=>this.So())}Wo(){this.Io=()=>{this.ar&&this.resizeCanvas(this.tr.width,this.tr.height),this.Ho()},window.addEventListener("resize",this.Io),this.Po.Xr(),this.Eo.Xr(),window.addEventListener("blur",()=>{this.Eo.sn()}),window.ResizeObserver&&this.ar&&(this.hr=new ResizeObserver(()=>{this.resizeCanvas(this.tr.targetCanvas.width,this.tr.targetCanvas.height)}),this.hr.observe(this.tr.targetCanvas))}So(){if(this.To.measureFrameRate(),this.To.incrementFrame(),this.Lo)return;if(this.ar){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.No.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.tr.targetCanvas),r.bindTexture(r.TEXTURE_2D,null),this.zo.begin(),this.xt.Hs(this.No,0,0,this.rn.cols,this.rn.rows),this.xt.Ds(this.Ro),this.ko(),this.xt.St(this.Ro),this.zo.end()}else this.zo.begin(),this.xt.Ds(this.Ro),this.ko(),this.xt.St(this.Ro),this.zo.end();this.Go.begin(),this.xt.Ds(this.Bo),this.Bo.Vt({U0:this.Si.fontFramebuffer,U1:[this.Si.textureColumns,this.Si.textureRows],U2:this.zo.textures[0],U3:this.zo.textures[1],U4:this.zo.textures[2],U5:this.zo.textures[4],U6:this.zo.textures[3],U7:[this.rn.cols,this.rn.rows],U8:[this.Go.width,this.Go.height],U9:this.Go.width/this.Go.height}),this.xt.Is(0,0,this.tr.width,this.tr.height),this.Go.end();const i=this.xt.state.canvasBackgroundColor;this.xt.Ne(i[0],i[1],i[2],i[3]),this.xt.Ds(this.Do),this.Do.Vt({Ua:this.Go.textures[0],Ub:[this.Go.width,this.Go.height],Uc:[this.rn.offsetX,this.rn.offsetY],Ud:[this.rn.width,this.rn.height]}),this.xt.Is(this.rn.offsetX,this.rn.offsetY,this.rn.width,this.rn.height)}setup(i){this.Oo=i}draw(i){this.ko=i}windowResized(i){this.Ho=i}resizeCanvas(i,r){this.tr.mr(i,r),this.rn.ir(),this.zo.resize(this.rn.cols,this.rn.rows),this.Go.resize(this.rn.width,this.rn.height),this.xt.Zs(),this.Po.An(),this.So()}destroy(){this.Lo||(this.To.stop(),window.removeEventListener("resize",this.Io),this.Po.Kr(),this.Eo.Kr(),this.Si.Gt(),this.xt.Gt(),this.Go.Gt(),this.Do.Gt(),this.No&&this.No.Gt(),this.Lo=!0)}get grid(){return this.rn}get font(){return this.Si}get width(){return this.tr.width}get height(){return this.tr.height}get canvas(){return this.tr.canvas}get isDisposed(){return this.Lo}get overlay(){return this.No}}class ${constructor(){}static create(t={}){return new pt(t)}static setErrorLevel(t){W.A(t)}static get version(){return"0.2.1-beta.6"}}const pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),me=$.create,ve=$.setErrorLevel,Ae=$.version;C.TextmodeCanvas=ut,C.TextmodeErrorLevel=_,C.TextmodeFont=ct,C.TextmodeFramebuffer=j,C.TextmodeGrid=lt,C.TextmodeImage=X,C.Textmodifier=pt,C.create=me,C.export=pe,C.setErrorLevel=ve,C.textmode=$,C.version=Ae,Object.defineProperty(C,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={});
|
package/dist/textmode.umd.min.js
CHANGED
|
@@ -4,10 +4,10 @@ var ye=Object.defineProperty;var Ee=(C,T,M)=>T in C?ye(C,T,{enumerable:!0,config
|
|
|
4
4
|
- ${r}: ${T.o(n)}`).join(""):""}
|
|
5
5
|
|
|
6
6
|
${"↓".repeat(24)}
|
|
7
|
-
`}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=>T.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>T.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}: ${T.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${T.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var M=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(M||{});const G=class G{constructor(){l(this,"u",{globalLevel:3})}static _(){return G.l||(G.l=new G),G.l}m(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(T.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(T.i(t,i)),console.groupEnd(),!1;default:throw new T(t,i)}}v(t,i,r){return!!t||(this.m(i,r),!1)}C(t){this.u.globalLevel=t}};l(G,"l",null);let Z=G;const N=Z._(),rt=new WeakMap;function H(c,t){rt.set(c,t)}function Y(c){return rt.get(c)}class nt{constructor(){l(this,"$",1);l(this,"U",0);l(this,"M",0);l(this,"F",0);l(this,"R",[0,0,0]);l(this,"S",[1,1,1,1]);l(this,"A",[0,0,0,1]);l(this,"L",!1);l(this,"k",!1);l(this,"P",!1);l(this,"G",[0,0]);l(this,"D",[0,0,0,1]);l(this,"I",[])}W(){this.I.push({O:this.$,H:this.U,V:this.M,K:this.F,G:[...this.G],N:this.L,X:this.k,P:this.P,j:[...this.R],Y:[...this.S],q:[...this.A]})}Z(){const t=this.I.pop();t?(this.$=t.O,this.U=t.H,this.M=t.V,this.F=t.K,this.G=t.G,this.L=t.N,this.k=t.X,this.P=t.P,this.R=t.j,this.S=t.Y,this.A=t.q):console.warn("pop() called without matching push()")}J(t){t.O=this.$,t.H=this.U,t.V=this.M,t.K=this.F,t.j[0]=this.R[0],t.j[1]=this.R[1],t.j[2]=this.R[2],t.Y[0]=this.S[0],t.Y[1]=this.S[1],t.Y[2]=this.S[2],t.Y[3]=this.S[3],t.q[0]=this.A[0],t.q[1]=this.A[1],t.q[2]=this.A[2],t.q[3]=this.A[3],t.N=this.L,t.X=this.k,t.P=this.P,t.G[0]=this.G[0],t.G[1]=this.G[1]}get lineWeight(){return this.$}get canvasBackgroundColor(){return this.D}tt(t){this.$=Math.abs(t)}et(t){this.U=t}st(t){this.M=t}it(t){this.F=t}rt(t){this.R=t}nt(t,i,r,n=255){this.S=[t/255,i/255,r/255,n/255]}ot(t,i,r,n=255){this.A=[t/255,i/255,r/255,n/255]}ht(t){this.L=t}ct(t){this.k=t}lt(t){this.P=t}ut(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.G=[r,n]}ft(t,i,r,n){this.D=[t/255,i/255,r/255,n/255]}}class V{constructor(t,i,r=i,n=1,o={},h=null,a=!1){l(this,"dt");l(this,"_t");l(this,"u");l(this,"gt",null);l(this,"vt");l(this,"yt");l(this,"Ct",[]);l(this,"wt");l(this,"$t",null);l(this,"bt",[]);l(this,"xt",null);l(this,"Mt",!1);l(this,"Ft",null);this.dt=i,this._t=r,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.vt=t,this.wt=Math.min(Math.max(1,n),8),this.xt=h,this.Mt=!!a,this.Ft=this.Mt?new nt:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.wt=Math.min(this.wt,u,f),this.yt=t.createFramebuffer(),this.Rt(),this.St(),this.bt=Array(this.wt).fill(null)}Rt(){const t=this.vt,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.wt;o++){const h=t.createTexture();t.bindTexture(t.TEXTURE_2D,h),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.dt,this._t,0,t.RGBA,n,null),this.Ct.push(h)}t.bindTexture(t.TEXTURE_2D,null)}St(){const t=this.vt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.wt===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Ct[0],0);else{const r=[];for(let n=0;n<this.wt;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Ct[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)}At(t){const i=this.vt;i.bindTexture(i.TEXTURE_2D,this.Ct[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)}resize(t,i){this.dt=t,this._t=i,this.gt=null,this.bt=Array(this.wt).fill(null);const r=this.vt,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Ct)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.dt,this._t,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}zt(t){const i=this.vt,r=this.bt[t];if(r)return r;const n=this.dt,o=this._t,h=new Uint8Array(n*o*4),a=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.yt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,h),i.bindFramebuffer(i.READ_FRAMEBUFFER,a);const u=4*n,f=new Uint8Array(h.length);for(let g=0;g<o;g++){const d=(o-1-g)*u,m=g*u;f.set(h.subarray(d,d+u),m)}return this.bt[t]=f,f}begin(){var i,r,n,o;const t=this.vt;if(this.xt){const h=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;h&&this.xt.Et(h),this.Mt&&this.Ft&&((o=(n=this.xt).Lt)==null||o.call(n,this.Ft))}this.$t={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.bt=Array(this.wt).fill(null);for(let h=0;h<this.wt;h++)t.clearBufferfv(t.COLOR,h,new Float32Array([0,0,0,0]));t.viewport(0,0,this.dt,this._t),H(t,[0,0,this.dt,this._t])}end(){var i,r,n,o;if(!this.$t)return;const t=this.vt;if(this.xt){const h=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;h&&this.xt.Et(h)}t.bindFramebuffer(t.FRAMEBUFFER,this.$t.framebuffer),t.viewport(...this.$t.viewport),H(t,this.$t.viewport),this.$t=null,this.xt&&this.Mt&&this.Ft&&((o=(n=this.xt).kt)==null||o.call(n))}Pt(){const t=this.vt;t.deleteFramebuffer(this.yt);for(const i of this.Ct)t.deleteTexture(i)}get width(){return this.dt}get height(){return this._t}get textures(){return[...this.Ct]}}class
|
|
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 U9;uniform vec2
|
|
9
|
-
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.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`),this.Qt=new
|
|
10
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;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 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ee=new
|
|
11
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec3 Uq;uniform bool Ur;uniform vec3 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];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;float A(vec3 B){return dot(B,vec3(0.299,0.587,0.114));}void main(){vec2 C=vec2(v_uv.x,1.-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.),0.,F-1.);int H=int(floor(G+0.5));vec3 I=Uv[H];o_character=vec4(I,1.);}else{o_character=vec4(E,0.,0.,1.);}vec3 J=D.rgb;vec3 K=Up?Uq:J;vec3 L=Ur?Us:J;float M=Up?1.:D.a;float N;if(D.a<0.01){K=Ut.rgb;L=Ut.rgb;M=Ut.a;N=Ut.a;}else{N=Ur?1.:D.a;}o_primaryColor=vec4(K,M);o_secondaryColor=vec4(L,N);o_rotation=vec4(Uo.xy,0.,1.);o_transform=vec4(float(Ul),float(Um),float(Un),1.);}`)}ie(){return this.Qt}Tt(){return this.te}re(){return this.ee}ne(){return this.se}oe(t){return new $(this.vt,j,t)}ae(t,i){return new $(this.vt,t,i)}Pt(){this.Qt.Pt(),this.te.Pt(),this.ee.Pt(),this.se.Pt()}}var b=(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))(b||{});class xt{constructor(t){l(this,"vt");l(this,"he",new Map);this.vt=t}ce(t,i,r,n){const o=this.vt;let h=this.he.get(t);h||(h=new Map,this.he.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ue.le.size,o.FLOAT,!1,r.fe,r.ue.le.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ue.de.size,o.FLOAT,!1,r.fe,r.ue.de.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}_e(){this.vt.bindVertexArray(null)}Pt(){for(const[,t]of this.he)for(const[,i]of t)i&&this.vt.deleteVertexArray(i)}}class yt{constructor(t,i){l(this,"pe");l(this,"vt");l(this,"xt");l(this,"me",null);l(this,"ge",null);this.vt=t,this.pe=new xt(t),this.xt=i}ve(t,i,r){const{shader:n}=t,o=Y(this.vt)||this.vt.getParameter(this.vt.VIEWPORT);n.Nt({U9:o[2]/o[3],Uw:[o[2],o[3]]});const h=f=>{if(!f||!f.ye())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.pe.ce(n.Jt,f.type+"",g,d),f.batch.Ce(n),f.batch.we(g.$e,g.be)}finally{f.batch.xe(n),this.pe._e(),f.Me()}};let a=null,u=null;for(const f of i){if(f.type===b.CUSTOM){u&&(h(u),a=null,u=null),this.Fe(t,f.params,f.state,r.get(b.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let g=u;g&&f.type===a||(g=r.get(f.type)||null,u=g,a=f.type),g&&g.Re(f.params,f.state)}h(u)}Fe(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:g}=i,d=this.Se(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));d.begin(),this.Ae(n,f,g,0,0,d.width,d.height,{}),d.end();const m=this.ze(),y={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.Ae(n,m,y,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Vt()}Ae(t,i,r,n,o,h,a,u){i.Vt(),i.Nt(r);const f=this.vt.getParameter(this.vt.VIEWPORT);if(i.Nt({U9:f[2]/f[3],Uw:[f[2],f[3]]}),t.Me(),t.Re({x:n,y:o,width:h,height:a},u),t.ye()){const g=t.unitGeometry,d=t.unitBuffer;try{this.pe.ce(i.Jt,t.type+"",g,d),t.batch.Ce(i),t.batch.we(g.$e,g.be)}finally{t.batch.xe(i),this.pe._e(),t.Me()}}}ze(){return this.xt.ie()}Se(t,i){return this.me&&this.ge&&this.ge.w===t&&this.ge.h===i||(this.me&&this.me.Pt(),this.me=new V(this.vt,t,i,5),this.ge={w:t,h:i}),this.me}Pt(){this.pe.Pt(),this.me&&this.me.Pt()}}class Et{constructor(){l(this,"Te",[]);l(this,"Ee",1);l(this,"Le",0)}ke(t){if(this.Le>=this.Te.length){const r={id:this.Ee++,type:t,params:{},state:{O:1,H:0,V:0,K:0,j:[0,0,0],Y:[1,1,1,1],q:[0,0,0,1],N:!1,X:!1,P:!1,G:[0,0]}};this.Te.push(r)}const i=this.Te[this.Le];return i.id=this.Ee++,i.type=t,this.Le++,i}Pe(t,i,r,n,o){const h=this.ke(b.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ge(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}Be(t,i,r,n,o,h){const a=this.ke(b.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}De(t,i,r,n,o){const h=this.ke(b.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ie(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}We(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}Oe(t,i,r,n,o,h,a,u,f,g){const d=this.ke(b.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=h,d.params.x2=a,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Le}get isEmpty(){return this.Le===0}He(){this.Le=0}[Symbol.iterator](){let t=0;const i=this.Le,r=this.Te;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const B=class B{static Ve(t,i,r=0){var h,a,u,f,g,d,m,y,x,p;const n=i||new Float32Array(B.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.le[0],n[o++]=t.le[1],n[o++]=t.Le[0],n[o++]=t.Le[1],n[o++]=t.j[0],n[o++]=t.j[1],n[o++]=t.j[2],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.Y[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.G[0],n[o++]=t.G[1],n[o++]=t.Ke[0],n[o++]=t.Ke[1],n[o++]=t.Ke[2],n[o++]=t.H,n[o++]=t.V,n[o++]=t.K,n[o++]=t.Ne[0],n[o++]=t.Ne[1],n[o++]=((h=t.Xe)==null?void 0:h[0])||0,n[o++]=((a=t.Xe)==null?void 0:a[1])||0,n[o++]=((u=t.je)==null?void 0:u[0])||0,n[o++]=((f=t.je)==null?void 0:f[1])||0,n[o++]=((g=t.Ye)==null?void 0:g[0])||0,n[o++]=((d=t.Ye)==null?void 0:d[1])||0,n[o++]=((m=t.qe)==null?void 0:m[0])||0,n[o++]=((y=t.qe)==null?void 0:y[1])||0,n[o++]=((x=t.Ze)==null?void 0:x[0])||0,n[o++]=((p=t.Ze)==null?void 0:p[1])||0,n}static Je(t){const i=t.length*B.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*B.FLOATS_PER_INSTANCE;B.Ve(t[n],r,o)}return r}};l(B,"BYTES_PER_INSTANCE",140),l(B,"FLOATS_PER_INSTANCE",35);let D=B;const U=class U{};l(U,"STRIDE",D.BYTES_PER_INSTANCE),l(U,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let K=U;class wt{constructor(t,i=1e3,r=1.5){l(this,"vt");l(this,"Qe",[]);l(this,"ts");l(this,"es");l(this,"ss",null);l(this,"rs",!0);l(this,"ns",0);l(this,"hs",new Map);l(this,"cs",null);this.vt=t,this.ts=i,this.es=r,this.ls()}Re(t){const i=this.Qe.length;return this.Qe.push(t),this.rs=!0,i}get count(){return this.Qe.length}get isEmpty(){return this.Qe.length===0}clear(){this.Qe.length=0,this.rs=!0}us(t){if(t<=this.ts)return;const i=Math.ceil(t*this.es);this.ts=i,this.ls()}ls(){const t=this.vt;this.ss&&t.deleteBuffer(this.ss),this.ss=t.createBuffer();const i=this.ts*D.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ss),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!0,this.ns=0}fs(){if(!this.rs||this.Qe.length===0)return;const t=this.vt,i=this.Qe.length;this.us(i),(!this.cs||this.cs.length<i*D.FLOATS_PER_INSTANCE)&&(this.cs=new Float32Array(i*D.FLOATS_PER_INSTANCE));const r=D.Je(this.Qe);t.bindBuffer(t.ARRAY_BUFFER,this.ss),i<=this.ns?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!1,this.ns=i}ds(t){let i=this.hs.get(t);if(!i){i=new Map;const r=this.vt;for(const n in K.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.hs.set(t,i)}return i}Ce(t){if(!this.ss||this.Qe.length===0)return;const i=this.vt,r=t.Jt;this.fs();const n=this.ds(r);i.bindBuffer(i.ARRAY_BUFFER,this.ss);for(const[o,h]of n){const a=K.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}xe(t){const i=this.vt,r=this.ds(t.Jt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}we(t,i){this.Qe.length!==0&&this.vt.drawArraysInstanced(t,0,i,this.Qe.length)}Pt(){this.ss&&this.vt.deleteBuffer(this.ss)}}class z{constructor(t,i,r,n){l(this,"vt");l(this,"_s");l(this,"ps");l(this,"gs");l(this,"vs",null);this.vt=t,this._s=i,this.ps=r,this.gs=n;const o=this.vt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.vt.bindBuffer(this.vt.ARRAY_BUFFER,o),this.vt.bufferData(this.vt.ARRAY_BUFFER,this.gs.Cs,this.vt.STATIC_DRAW),this.vt.bindBuffer(this.vt.ARRAY_BUFFER,null),this.vs=o}get type(){return this.ps}get unitGeometry(){return this.gs}get unitBuffer(){return this.vs}get batch(){return this._s}Me(){this._s.clear()}ye(){return!this._s.isEmpty}Pt(){this._s.Pt(),this.vt.deleteBuffer(this.vs)}ws(t,i,r,n,o){const h=this.$s(t,i,r,n,o.H||0,o.V||0,o.K||0);return{le:[t,i],Le:[r,n],j:o.j||[0,0,0],Y:o.Y||[1,1,1,1],q:o.q||[0,0,0,1],G:o.G||[0,0],Ke:[o.P?1:0,o.N?1:0,o.X?1:0],H:h.radiansX,V:h.radiansY,K:h.radiansZ,Ne:[h.centerX,h.centerY]}}bs(t,i){const r=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}Ms(t,i,r){const n=this.bs(i,r);t.Ne=[n.nx,n.ny]}$s(t,i,r,n,o,h,a){const u=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/g}}}const Rt={Cs: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]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class bt extends z{constructor(t,i){super(t,i,b.RECTANGLE,Rt)}Re(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this._s.Re(r)}}const Tt={Cs: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]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class At extends z{constructor(t,i){super(t,i,b.LINE,Tt)}Re(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.O||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,g=u,d=this.ws(f,g,o,h,i);return this.Ms(d,a,u),this._s.Re(d)}}const Ct={Cs: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,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),g=Math.cos(o),d=Math.sin(o),m=.5*(g+1),y=.5*(d+1);t.push(0,0,.5,.5,h,a,u,f,g,d,m,y)}return new Float32Array(t)}(32),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ut extends z{constructor(t,i){super(t,i,b.ELLIPSE,Ct)}Re(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.Ms(r,t.x,t.y),this._s.Re(r)}}let _t={Cs: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),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ft extends z{constructor(t,i){super(t,i,b.ARC,_t)}Re(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.ws(r,n,t.width,t.height,i);return this.Ms(a,t.x,t.y),a.Xe=[o,h],this._s.Re(a)}}const Lt={Cs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),be:3,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Pt extends z{constructor(t,i){super(t,i,b.TRIANGLE,Lt)}Re(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),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.ws(r,o,h,a,i),f=r+.5*h,g=o+a*(1/3);return this.Ms(u,f,g),this._s.Re(u)}}function ht(c,t,i,r,n){const o=1-c,h=o*o,a=c*c;return h*o*t+3*h*c*i+3*o*a*r+a*c*n}const St={Cs: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),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class It extends z{constructor(t,i){super(t,i,b.BEZIER_CURVE,St)}Re(t,i){const r=i.O||1,n=ht(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=ht(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.ws(0,0,1,r,i);return this.Ms(h,n,o),h.qe=[t.x1,t.y1],h.je=[t.cp1x,t.cp1y],h.Ye=[t.cp2x,t.cp2y],h.Ze=[t.x2,t.y2],this._s.Re(h)}}class Bt{constructor(t){l(this,"vt");l(this,"Fs",null);l(this,"Rs");l(this,"Ss",null);l(this,"As",{});l(this,"zs",null);l(this,"Ts",new Map);l(this,"Es");l(this,"Ls");l(this,"ks");l(this,"I",[]);this.vt=t,this.Rs=new vt(t),this.ks=new nt,this.Es=new yt(t,this),this.Ls=new Et,this.zs=t.createBuffer(),H(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}Ps(t){let i=this.Ts.get(t);if(i)return i;const r=new wt(this.vt);return i=(0,{[b.RECTANGLE]:()=>new bt(this.vt,r),[b.LINE]:()=>new At(this.vt,r),[b.ELLIPSE]:()=>new Ut(this.vt,r),[b.ARC]:()=>new Ft(this.vt,r),[b.TRIANGLE]:()=>new Pt(this.vt,r),[b.BEZIER_CURVE]:()=>new It(this.vt,r)}[t])(),this.Ts.set(t,i),i}Gs(t){this.Fs!==t&&(this.Fs=t,t.Vt())}ae(t,i){return this.Rs.ae(t,i)}ie(){return this.Rs.ie()}Tt(){return this.Rs.Tt()}re(){return this.Rs.re()}ne(){return this.Rs.ne()}Bs(t){this.Ss=t,t&&(this.As={})}Xt(t,i){this.As[t]=i}Ds(t){Object.assign(this.As,t)}oe(t){return this.Rs.oe(t)}Is(t,i,r,n,o){const h=this.ie(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.Ls.Ge(i,r,n,o,h,a,this.ks)}Ws(t,i,r,n,o){const h=this.ne(),a=t.texture,u=t.flags,f=t.charRotationRG,g=[f[0],f[1]],d=t.colorUniforms??{charColorFixed:!1,Y:[1,1,1],cellColorFixed:!1,cellColor:[0,0,0],backgroundColor:[0,0,0,1]},m=t.characterListUniforms,y={Uk:a,Ul:!!u.invert,Um:!!u.flipX,Un:!!u.flipY,Uo:g,Up:!!d.charColorFixed,Uq:d.Y,Ur:!!d.cellColorFixed,Us:d.cellColor,Ut:d.backgroundColor,Uu:m.count,Uv:m.list};this.Ls.Ge(i,r,n,o,h,y,this.ks)}Os(t,i,r,n){var p;const o=this.vt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,g=1-i/a*2,d=1-(i+n)/a*2,m=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.zs),o.bufferData(o.ARRAY_BUFFER,m,o.DYNAMIC_DRAW);const y=((p=this.Fs)==null?void 0:p.Jt)||o.getParameter(o.CURRENT_PROGRAM),x=y?o.getAttribLocation(y,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Hs(t,i,r,n){this.Ss?(this.Ls.Ge(t,i,r,n,this.Ss,{...this.As},this.ks),this.Ss=null,this.As={}):this.Ls.Pe(t,i,r,n,this.ks)}Vs(t,i,r,n){this.Ls.Be(t,i,r,n,this.ks.lineWeight,this.ks)}Ks(t,i,r,n){this.Ls.De(t,i,r,n,this.ks)}Ns(t,i,r,n,o,h){this.Ls.We(t,i,r,n,o,h,this.ks)}Xs(t,i,r,n,o,h,a,u){const f=this.ks.lineWeight;this.Ls.Oe(t,i,r,n,o,h,a,u,f,this.ks)}js(t,i,r=1,n={}){return new V(this.vt,t,i,r,n,this,!0)}Ys(t,i,r,n,o,h){this.Ls.Ie(t,i,r,n,o,h,this.ks)}qs(t,i=t,r=t,n=255){this.state.ft(t,i,r,n),this.He(t/255,i/255,r/255,n/255)}He(t=0,i=0,r=0,n=0){this.vt.clearColor(t,i,r,n),this.vt.clear(this.vt.COLOR_BUFFER_BIT)}Zs(){this.vt.viewport(0,0,this.vt.canvas.width,this.vt.canvas.height),H(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}get context(){return this.vt}get state(){return this.ks}Lt(t){this.I.push(this.ks),this.ks=t}kt(){const t=this.I.pop();t&&(this.ks=t)}Et(t){const i=t,r=Y(this.vt)??this.vt.getParameter(this.vt.VIEWPORT),n={shader:i,gl:this.vt,viewport:r};this.Gs(i);const o=new Set;for(const h of this.Ls)h.type===b.CUSTOM?o.add(b.RECTANGLE):o.add(h.type);for(const h of o)h!==b.CUSTOM&&this.Ps(h);this.Es.ve(n,this.Ls,this.Ts),this.Ls.He()}Pt(){this.vt.deleteBuffer(this.zs),this.Ls.He();for(const t of this.Ts.values())t.Pt();this.Rs.Pt(),this.Es.Pt()}}const A={readShort:(c,t)=>(A.t.uint16[0]=c[t]<<8|c[t+1],A.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(A.readUshort(c,t+2*n));return r},readUint(c,t){const i=A.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],A.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},writeUshort(c,t,i){c[t]=i>>>8&255,c[t+1]=255&i},writeUint(c,t,i){c[t]=i>>>24&255,c[t+1]=i>>>16&255,c[t+2]=i>>>8&255,c[t+3]=255&i},writeASCII(c,t,i){for(let r=0;r<i.length;r++)c[t+r]=255&i.charCodeAt(r)},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()};function q(c){return c+3&-4}function Q(c,t,i){const r=t+i;let n=0;const o=A.t;for(let h=t;h<r;h+=4)o.uint8[3]=c[h]||0,o.uint8[2]=c[h+1]||0,o.uint8[1]=c[h+2]||0,o.uint8[0]=c[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class Mt{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function W(c){let t=32,i=0;for(const a of c)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of c)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<c.length;a++){const u=c[a];if(!u)continue;const f=n[u]++;let g=h.get(u);g||(g=[],h.set(u,g)),g[Dt(f,u)]=a}return{min:t,max:i,table:h}}function tt(c,t){let i=0;for(let r=1;r<=t.max;r++){i|=c.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function Dt(c,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&c,c>>>=1;return i>>>0}function Gt(c){if(c.length<2)throw Error("ZLIB data too short");const t=c[0],i=c[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const m=o.readBits(2);if(m===0){o.alignToByte();const y=o.readBits(16);if((65535&(65535^y))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let x=0;x<y;x++)h.push(o.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let y,x;if(m===1){const p=Array(288).fill(0);for(let E=0;E<=143;E++)p[E]=8;for(let E=144;E<=255;E++)p[E]=9;for(let E=256;E<=279;E++)p[E]=7;for(let E=280;E<=287;E++)p[E]=8;y=W(p),x=W(Array(32).fill(5))}else{const p=o.readBits(5)+257,E=o.readBits(5)+1,v=o.readBits(4)+4,R=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let P=0;P<v;P++)w[R[P]]=o.readBits(3);const L=W(w),_=[];for(;_.length<p+E;){const P=tt(o,L);if(P<=15)_.push(P);else if(P===16){const X=o.readBits(2)+3,O=_[_.length-1]||0;for(let mt=0;mt<X;mt++)_.push(O)}else if(P===17){const X=o.readBits(3)+3;for(let O=0;O<X;O++)_.push(0)}else{if(P!==18)throw Error("Invalid code length symbol");{const X=o.readBits(7)+11;for(let O=0;O<X;O++)_.push(0)}}}const F=_.slice(0,p),S=_.slice(p,p+E);y=W(F),x=W(S)}for(;;){const p=tt(o,y);if(p<256)h.push(p);else{if(p===256)break;if(p>256&&p<286){const E=p-257;let v=a[E];const R=u[E];R&&(v+=o.readBits(R));const w=tt(o,x);if(w>=30)throw Error("Invalid distance symbol");let L=f[w];const _=g[w];_&&(L+=o.readBits(_));const F=h.length-L;if(F<0)throw Error("Invalid distance");for(let S=0;S<v;S++)h.push(h[F+S]||0)}else if(p===286||p===287)throw Error("Reserved length symbol")}}}}}}(new Mt(c.subarray(r)),n),new Uint8Array(n)}function Ot(c){const t=A,i=new Uint8Array(c);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let v=0;v<n;v++){const R=t.readASCII(i,a,4),w=t.readUint(i,a+4),L=t.readUint(i,a+8),_=t.readUint(i,a+12),F=t.readUint(i,a+16);h.push({tag:R,offset:w,compLength:L,origLength:_,checksum:F}),a+=20}for(const v of h){const R=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(R);else if(v.data=Gt(R),v.data.length!==v.origLength)if(v.data.length<v.origLength){const w=new Uint8Array(v.origLength);w.set(v.data),v.data=w}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,m=16*u-d;let y=12+16*u;const x={};for(const v of h)x[v.tag]=y,y=q(y+v.data.length);const p=new Uint8Array(Math.max(o||0,y));t.writeUint(p,0,r),t.writeUshort(p,4,u),t.writeUshort(p,6,d),t.writeUshort(p,8,g),t.writeUshort(p,10,m);let E=12;for(const v of h){t.writeASCII(p,E,v.tag),E+=4;let R=v.data;if(v.tag==="head"&&R.length>=12){const w=new Uint8Array(R);t.writeUint(w,8,0);const L=Q(w,0,q(w.length));t.writeUint(p,E,L),E+=4}else{const w=Q(R,0,q(R.length));t.writeUint(p,E,w),E+=4}t.writeUint(p,E,x[v.tag]),E+=4,t.writeUint(p,E,v.data.length),E+=4}for(const v of h){const R=x[v.tag];p.set(v.data,R)}if(h.find(v=>v.tag==="head")){const v=x.head,R=function(w,L){const _=A,F=L+8,S=[w[F],w[F+1],w[F+2],w[F+3]];_.writeUint(w,F,0);const P=2981146554-(Q(w,0,q(w.length))>>>0)>>>0;return w[F]=S[0],w[F+1]=S[1],w[F+2]=S[2],w[F+3]=S[3],P>>>0}(p,v);t.writeUint(p,v+8,R)}return p.buffer}const $t={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=A,o=n.readUshort,h=o(c,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const m=`p${f}e${g}`;let y=a.indexOf(d);if(y===-1){let x;y=r.tables.length,a.push(d);const p=o(c,d);x=p===4?this.parse4(c,d):p===12?this.parse12(c,d):{format:p},r.tables.push(x)}r.ids[m]=y}return r},parse4(c,t){const i=A,r=i.readUshort,n=i.readUshorts,o=t,h=r(c,t+=2);t+=2;const a=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,a),t+=2*a,t+=2,u.startCount=n(c,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,a),t+=2*a,u.glyphIdArray=n(c,t,o+h-t>>1),u},parse12(c,t){const i=A.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}}},zt={parseTab(c,t,i){const r=A;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(c,t)}}},kt={parseTab(c,t,i){const r=A;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(c,t+2*h)}return o}},Nt={parseTab(c,t,i,r){const n=A,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)f=n.readUshort(c,t+(d<<2)),g=n.readShort(c,t+(d<<2)+2),o.push(f),h.push(g),d++;for(;d<a;)o.push(f),h.push(g),d++;return{aWidth:o,lsBearing:h}}},at={cmap:$t,head:zt,hhea:kt,maxp:{parseTab(c,t,i){const r=A;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Nt,loca:{parseTab(c,t,i,r){const n=A,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;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 h=0;h<o;h++)n.push(null);return n},Js(c,t){const i=A,r=c.Qs,n=c.loca;if(n[t]===n[t+1])return null;const o=I.findTable(r,"glyf",c.ti);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let m=0;m<a.noc;m++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let m=0;m<f;m++){const y=r[h];if(h++,a.flags.push(y),8&y){const x=r[h];h++;for(let p=0;p<x;p++)a.flags.push(y),m++}}a.xs=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(16&y);2&y?(a.xs.push(x?r[h]:-r[h]),h++):x?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(32&y);4&y?(a.ys.push(x?r[h]:-r[h]),h++):x?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let g=0,d=0;for(let m=0;m<f;m++)g+=a.xs[m],d+=a.ys[m],a.xs[m]=g,a.ys[m]=d}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},I={parse(c){const t=new Uint8Array(c),i=A.readASCII(t,0,4);if(i==="wOFF")c=Ot(c);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=at,u={Qs:r,ei:n,ti:o};for(const f in a){const g=f,d=I.findTable(r,g,o);if(d){const[m,y]=d;let x=h[m];x==null&&(x=a[g].parseTab(r,m,y,u),h[m]=x),u[g]=x}}return u})(new Uint8Array(c),0,0,{})]},findTable(c,t,i){const r=A,n=r.readUshort(c,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),f=r.readUint(c,o+12);if(a===t)return[u,f];o+=16}return null},T:at,B:A};class Wt{si(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(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 h=n;h<=o;h++)if(this.ai(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ri(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],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}ai(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}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){l(this,"hi",new Map);l(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.hi.has(r))return this.hi.get(r);const n=t.cmap;if(!n||!n.tables)return this.hi.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.fi(i,h):h.format===12&&(o=this.di(i,h)),o>0)break;return this.hi.set(r,o),o}_i(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}pi(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}mi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}gi(){this.hi.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Qs.length}`}fi(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 h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}di(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Xt{constructor(t){l(this,"yi");l(this,"Ci");l(this,"xt");l(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ci=this.yi.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,g=typeof n=="object"?n:null;this.$i(u,f),this.bi(t,i,h,r,g);const d=this.xt.js(u,f,1,{filter:"nearest"});return d.At(this.yi),{framebuffer:d,columns:h,rows:a}}$i(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=t+"px",this.Ci.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ci.fillStyle="black",this.Ci.fillRect(0,0,t,i),this.Ci.textBaseline="top",this.Ci.textAlign="left",this.Ci.fillStyle="white"}bi(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),g=t[a].character,d=this.xi(o,g);if(!d)continue;const m=g.codePointAt(0)||0,y=this.wi.li(o,m),x=this.Mi(o,y)*h,p=u*i.width,E=f*i.height,v=p+.5*i.width,R=E+.5*i.height,w=Math.round(v-.5*i.width),L=Math.round(R-.5*n),_=w+.5*(i.width-x),F=L+o.hhea.ascender*h;this.Fi(d,_,F,h)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(I&&I.T&&I.T.glyf){const o=I.T.glyf.Js(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Mi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Fi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.Ci.beginPath();let f=0;for(let g=0;g<a.length;g++){const d=a[g];if(!(d<f)){if(d>=f){const m=i+o[f]*n,y=r-h[f]*n;this.Ci.moveTo(m,y);let x=f+1;for(;x<=d;)if(1&u[x]){const p=i+o[x]*n,E=r-h[x]*n;this.Ci.lineTo(p,E),x++}else{const p=i+o[x]*n,E=r-h[x]*n;let v=x+1>d?f:x+1;if(1&u[v]){const R=i+o[v]*n,w=r-h[v]*n;this.Ci.quadraticCurveTo(p,E,R,w),x=v+1}else{const R=(p+(i+o[v]*n))/2,w=(E+(r-h[v]*n))/2;this.Ci.quadraticCurveTo(p,E,R,w),x=v}}this.Ci.closePath()}f=d+1}}this.Ci.fill()}}class Ht{constructor(){l(this,"Ri");this.Ri=new et}Si(t,i,r){let n=0;const o=this.Ri.mi(r,i),h=o.lineHeight;for(const a of t){const u=this.Ri._i(r,a);if(u===0)continue;const f=this.Ri.pi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}gi(){this.Ri.gi()}}class Yt{constructor(){l(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.Ai(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}Ai(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}zi(t,i){if(!N.v(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]}Ti(t,i){return N.v(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.zi(r,i)||[0,0,0]):[[0,0,0]]}}class ct{constructor(t,i=16){l(this,"Ei");l(this,"Li",[]);l(this,"ki");l(this,"Pi",16);l(this,"Gi",0);l(this,"Bi",0);l(this,"Di",{width:0,height:0});l(this,"Ii");l(this,"Wi");l(this,"Oi");l(this,"Hi");l(this,"Vi");this.Pi=i,this.Wi=new Wt,this.Oi=new Xt(t),this.Hi=new Ht,this.Vi=new Yt}async Ki(t){let i;if(!t)throw new T("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new T(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Ni(i),this.Ei=I.parse(i)[0],await this.Xi()}ji(t){if(t===void 0)return this.Pi;this.Pi=t,this.Di=this.Hi.Si(this.Li.map(r=>r.character),this.Pi,this.Ei);const i=this.Oi.createTextureAtlas(this.Li,this.Di,this.Pi,this.Ei);this.ki=i.framebuffer,this.Gi=i.columns,this.Bi=i.rows}async Yi(t){try{const i=await fetch(t);if(!i.ok)throw new T(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ni(r);const n=I.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Ei=n[0],await this.Xi()}catch(i){throw new T("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ni(t){const i=Date.now();this.Ii=new FontFace("CustomFont_"+i,t),await this.Ii.load(),document.fonts.add(this.Ii)}async Xi(){const t=this.Wi.si(this.Ei),i=this.Wi.ni(t);this.Li=this.Vi.createCharacterObjects(i,this.Ei),this.Di=this.Hi.Si(i,this.Pi,this.Ei);const r=this.Oi.createTextureAtlas(this.Li,this.Di,this.Pi,this.Ei);this.ki=r.framebuffer,this.Gi=r.columns,this.Bi=r.rows}zi(t){return this.Vi.zi(t,this.Li)}Ti(t){return this.Vi.Ti(t,this.Li)}Pt(){this.ki.Pt(),document.fonts.delete(this.Ii)}get fontFramebuffer(){return this.ki}get characters(){return this.Li}get textureColumns(){return this.Gi}get textureRows(){return this.Bi}get maxGlyphDimensions(){return this.Di}get fontSize(){return this.Pi}get font(){return this.Ei}}class lt{constructor(t,i,r){l(this,"qi");l(this,"Zi");l(this,"dt");l(this,"_t");l(this,"Ji");l(this,"Qi");l(this,"tr");l(this,"er");l(this,"sr");this.tr=t,this.er=i,this.sr=r,this.ir()}ir(){this.qi=Math.floor(this.tr.width/this.er),this.Zi=Math.floor(this.tr.height/this.sr),this.dt=this.qi*this.er,this._t=this.Zi*this.sr,this.Ji=Math.floor((this.tr.width-this.dt)/2),this.Qi=Math.floor((this.tr.height-this._t)/2)}rr(t,i){this.er=t,this.sr=i,this.ir()}get cellWidth(){return this.er}get cellHeight(){return this.sr}get cols(){return this.qi}get rows(){return this.Zi}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.Ji}get offsetY(){return this.Qi}}class ut{constructor(t={}){l(this,"tr");l(this,"nr",null);l(this,"ar",!1);l(this,"hr");l(this,"cr");this.ar=t.overlay??!1,this.ar&&t.canvas?(this.nr=t.canvas,this.tr=this.lr(),this.cr=!0,this.ur()):t.canvas?(this.tr=t.canvas,this.cr=!1):(this.tr=this.dr(t.width,t.height),this.cr=!0),this.tr.style.imageRendering="pixelated"}dr(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}lr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.nr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.nr instanceof HTMLVideoElement){const a=this.nr;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.nr);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}ur(){var t;this._r(),(t=this.nr.parentNode)==null||t.insertBefore(this.tr,this.nr.nextSibling),window.ResizeObserver&&(this.hr=new ResizeObserver(()=>{this.pr()}),this.hr.observe(this.nr)),window.addEventListener("resize",()=>{this.pr()})}_r(){if(!this.nr)return;const t=this.nr.getBoundingClientRect();let i=this.nr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.tr.style.top=t.top-r.top+"px",this.tr.style.left=t.left-r.left+"px"}else this.tr.style.top=t.top+window.scrollY+"px",this.tr.style.left=t.left+window.scrollX+"px"}pr(t,i){if(this.ar){const r=this.nr.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.nr instanceof HTMLVideoElement){const h=this.nr;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.tr.width=n,this.tr.height=o,this._r()}else this.tr.width=t??this.tr.width,this.tr.height=i??this.tr.height}mr(){const t=this.tr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new T("`textmode.js` requires WebGL2 support.");return t}Pt(){this.hr&&this.hr.disconnect();const t=this.tr.getContext("webgl")||this.tr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.cr&&this.tr.parentNode&&this.tr.parentNode.removeChild(this.tr)}get canvas(){return this.tr}get targetCanvas(){return this.nr}get width(){return this.tr.width}get height(){return this.tr.height}}class k{constructor(t,i,r,n){l(this,"texture");l(this,"width");l(this,"height");l(this,"vt");l(this,"P",0);l(this,"N",0);l(this,"X",0);l(this,"G",[0,0]);l(this,"gr","sampled");l(this,"vr","fixed");l(this,"Y",[1,1,1]);l(this,"q",[0,0,0]);l(this,"yr",[0,0,0,1]);l(this,"Cr",[[.1,0,0]]);l(this,"wr");this.vt=t,this.texture=i,this.width=r,this.height=n}Pt(){this.vt.deleteTexture(this.texture)}$r(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.P=this.$r(t),this}flipX(t=!0){return this.N=this.$r(t),this}flipY(t=!0){return this.X=this.$r(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.G=[r,n],this}get flags(){return{invert:this.P,flipX:this.N,flipY:this.X}}get charRotationRG(){return this.G}charColorMode(t){return this.gr=t,this}cellColorMode(t){return this.vr=t,this}charColor(t,i,r){return this.Y=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}cellColor(t,i,r){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}background(t,i,r,n){return this.yr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}charactersFromColors(t){const i=t.filter(r=>Array.isArray(r)).slice(0,64);return this.Cr=i,this}characters(t){const i=this.wr(t);return this.charactersFromColors(i),this}get characterListUniforms(){return{count:this.Cr.length,list:this.Cr}}get colorUniforms(){return{charColorFixed:this.gr==="fixed",Y:this.Y,cellColorFixed:this.vr==="fixed",cellColor:this.q,backgroundColor:this.yr}}static fromSource(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new k(n,o,h,a);return u.wr=r,u}}class Vt{constructor(t=60){l(this,"br");l(this,"Mr");l(this,"Fr",null);l(this,"Rr",0);l(this,"Sr",!0);l(this,"Ar",0);l(this,"zr",0);l(this,"Tr",[]);l(this,"Er",10);l(this,"Lr",0);this.br=t,this.Mr=1e3/t}start(t){if(!this.Sr)return;this.Rr=performance.now();const i=r=>{if(!this.Sr)return void(this.Fr=null);const n=r-this.Rr;n>=this.Mr&&(t(),this.Rr=r-n%this.Mr),this.Sr&&(this.Fr=requestAnimationFrame(i))};this.Fr=requestAnimationFrame(i)}stop(){this.Fr&&(cancelAnimationFrame(this.Fr),this.Fr=null)}pause(){this.Sr&&(this.Sr=!1,this.stop())}resume(t){this.Sr||(this.Sr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Ar;this.br=t,this.Mr=1e3/t,this.Sr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.zr>0){const i=t-this.zr;this.Tr.push(i),this.Tr.length>this.Er&&this.Tr.shift();const r=this.Tr.reduce((n,o)=>n+o,0)/this.Tr.length;this.Ar=1e3/r}this.zr=t}get isLooping(){return this.Sr}get frameRateLimit(){return this.br}get currentFrameRate(){return this.Ar}get frameCount(){return this.Lr}set frameCount(t){this.Lr=t}incrementFrame(){this.Lr++}resetFrameCount(){this.Lr=0}}class jt{constructor(){l(this,"kr",new Map);l(this,"Pr",null);l(this,"Gr",null);l(this,"Br");l(this,"Dr");l(this,"Ir",!1);l(this,"Wr");l(this,"Or");l(this,"Hr",{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"})}Vr(){this.Ir||(this.Br=t=>{this.Kr(t)},this.Dr=t=>{this.Nr(t)},window.addEventListener("keydown",this.Br,{passive:!1}),window.addEventListener("keyup",this.Dr,{passive:!1}),this.Ir=!0)}Xr(){this.Ir&&(window.removeEventListener("keydown",this.Br),window.removeEventListener("keyup",this.Dr),this.Ir=!1,this.kr.clear(),this.Pr=null,this.Gr=null)}jr(t){this.Wr=t}Yr(t){this.Or=t}qr(t){const i=this.Zr(t),r=this.kr.get(t)||this.kr.get(i);return(r==null?void 0:r.isPressed)||!1}Jr(){return this.Pr}Qr(){return this.Gr}tn(){const t=[];for(const[i,r]of this.kr)r.isPressed&&t.push(i);return t}en(){return{ctrl:this.qr("Control"),shift:this.qr("Shift"),alt:this.qr("Alt"),meta:this.qr("Meta")}}sn(){this.kr.clear(),this.Pr=null,this.Gr=null}Kr(t){const i=t.key,r=Date.now();this.kr.has(i)||this.kr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.kr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Pr=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)}}Nr(t){const i=t.key,r=Date.now();this.kr.has(i)||this.kr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.kr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.Gr=i,this.Or){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Or(o)}}Zr(t){return this.Hr[t]||t.toLowerCase()}}class Kt{constructor(t){l(this,"tr");l(this,"rn");l(this,"nn",{x:-1,y:-1});l(this,"an",{x:-1,y:-1});l(this,"hn",null);l(this,"cn");l(this,"ln");l(this,"un");l(this,"fn");l(this,"dn");l(this,"_n");l(this,"Ir",!1);l(this,"pn");l(this,"mn");l(this,"gn");l(this,"vn");l(this,"yn");this.tr=t}Ki(t){this.rn=t,this.Cn()}Vr(){if(this.Ir)return;const t=this.tr.canvas;this.cn=i=>{this.wn(i),this.$n(i)},this.ln=()=>{this.an={...this.nn},this.nn.x=-1,this.nn.y=-1,this.hn=null},this.un=i=>{this.wn(i),this.bn(i)},this.fn=i=>{this.wn(i),this.xn(i)},this.dn=i=>{this.wn(i),this.Mn(i)},this._n=i=>{this.wn(i),this.Fn(i)},t.addEventListener("mousemove",this.cn,{passive:!0}),t.addEventListener("mouseleave",this.ln,{passive:!0}),t.addEventListener("mousedown",this.un,{passive:!0}),t.addEventListener("mouseup",this.fn,{passive:!0}),t.addEventListener("click",this.dn,{passive:!0}),t.addEventListener("wheel",this._n,{passive:!1}),this.Ir=!0}Xr(){if(!this.Ir)return;const t=this.tr.canvas;t.removeEventListener("mousemove",this.cn),t.removeEventListener("mouseleave",this.ln),t.removeEventListener("mousedown",this.un),t.removeEventListener("mouseup",this.fn),t.removeEventListener("click",this.dn),t.removeEventListener("wheel",this._n),this.Ir=!1}Cn(){if(this.Ir)try{if(this.hn){const t=new MouseEvent("mousemove",{clientX:this.hn.x,clientY:this.hn.y,bubbles:!1,cancelable:!1});this.wn(t)}else this.nn.x!==-1&&this.nn.y!==-1&&(this.nn.x>=this.rn.cols||this.nn.y>=this.rn.rows)&&(this.nn.x=-1,this.nn.y=-1)}catch{this.nn.x=-1,this.nn.y=-1}}Rn(t){this.pn=t}jr(t){this.mn=t}Yr(t){this.gn=t}Sn(t){this.vn=t}An(t){this.yn=t}zn(){return{x:this.nn.x,y:this.nn.y}}$n(t){if(this.vn){const i={position:{...this.nn},previousPosition:{...this.an},originalEvent:t};this.vn(i)}}bn(t){if(this.mn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.mn(i)}}xn(t){if(this.gn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.gn(i)}}Mn(t){if(this.pn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.pn(i)}}Fn(t){if(this.yn){const i={position:{...this.nn},previousPosition:{...this.an},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.yn(i)}}wn(t){const i=this.tr.canvas;this.an={...this.nn},this.hn={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.rn.offsetX,f=a-this.rn.offsetY,g=Math.floor(u/this.rn.cellWidth),d=Math.floor(f/this.rn.cellHeight);g>=0&&g<this.rn.cols&&d>=0&&d<this.rn.rows?(this.nn.x=g,this.nn.y=d):(this.nn.x=-1,this.nn.y=-1)}}const qt=c=>class extends c{rotate(t=0,i=0,r=0){this.xt.state.et(t),this.xt.state.st(i),this.xt.state.it(r)}rotateX(t){this.xt.state.et(t)}rotateY(t){this.xt.state.st(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.W()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Hs(t,i,r,n)}point(t,i){this.xt.Hs(t,i,1,1)}line(t,i,r,n){this.xt.Vs(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qs(t,i,r,n)}char(t){this.xt.state.rt(this.Ei.zi(t))}charColor(t,i,r){this.xt.state.nt(t,i,r)}cellColor(t,i,r){this.xt.state.ot(t,i,r)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qs(0,0,0,0)}ellipse(t,i,r,n){this.xt.Ks(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.Ns(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.Xs(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.Ys(t,i,r,n,o,h)}shader(t){this.xt.Bs(t)}setUniform(t,i){this.xt.Xt(t,i)}setUniforms(t){this.xt.Ds(t)}createFilterShader(t){return this.xt.oe(t)}createFramebuffer(t){return this.xt.js(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Is(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.Ws(h,i,r,n??h.width,o??h.height)}}async loadImage(t){if(typeof t!="string")return k.fromSource(this.xt,t,n=>this.Ei.Ti(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return k.fromSource(this.xt,r,n=>this.Ei.Ti(n))}};class it{Tn(t){const i=t.zt(0),r=t.zt(1),n=t.zt(2),o=t.zt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.zt(4),rotationPixels:o}}En(t,i){return t[i]+(t[i+1]<<8)}Ln(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class st{kn(t,i){return new Blob([t],{type:i})}Pn(t,i,r){try{const n=this.kn(t,r),o=URL.createObjectURL(n),h=document.createElement("a");h.href=o,h.download=i,h.style.display="none",h.rel="noopener",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(o)}catch(n){console.error("Failed to download file:",n)}}Gn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Bn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}Dn(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}In(){return"textmode-export-"+this.Gn()}}class Jt extends it{Wn(t,i,r){const n=t[r]===255,o=t[r+1]===255,h=t[r+2]===255,a=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:h,rotation:Math.round(360*(a+u/255)/255*100)/100}}On(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Hn(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let h=0;h<i.cols;h++){const a=4*n,u=this.En(t.characterPixels,a);let f=this.Ln(t.primaryColorPixels,a),g=this.Ln(t.secondaryColorPixels,a);const d=this.Wn(t.transformPixels,t.rotationPixels,a);if(d.isInverted){const y=f;f=g,g=y}const m=this.On(h,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:g,transform:d,position:m}),n++}return r}}class Zt{Vn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let h=0;h<o.startCount.length;h++)if(i>=o.startCount[h]&&i<=o.endCount[h]){if(o.idRangeOffset[h]===0)return i+o.idDelta[h]&65535;{const a=o.idRangeOffset[h]/2+(i-o.startCount[h])-(o.startCount.length-h);if(a>=0&&a<o.glyphIdArray.length){const u=o.glyphIdArray[a];if(u!==0)return u+o.idDelta[h]&65535}}}}else if(n.format===12){const o=n;for(let h=0;h<o.groups.length;h+=3){const a=o.groups[h],u=o.groups[h+1],f=o.groups[h+2];if(i>=a&&i<=u)return f+(i-a)}}return 0}Kn(t,i,r,n,o){const h=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*h,y1:n+-i.yMax*h,x2:r+i.xMax*h,y2:n+-i.yMin*h}),toSVG:()=>this.Nn(i,r,n,h)}}Nn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return"";let f="",g=0;for(let d=0;d<a.length;d++){const m=a[d];if(!(m<g)){if(m>=g){const y=i+o[g]*n,x=r-h[g]*n;f+=`M${y.toFixed(2)},${x.toFixed(2)}`;let p=g+1;for(;p<=m;)if(1&u[p]){const E=i+o[p]*n,v=r-h[p]*n;f+=`L${E.toFixed(2)},${v.toFixed(2)}`,p++}else{const E=i+o[p]*n,v=r-h[p]*n;let R=p+1>m?g:p+1;if(1&u[R]){const w=i+o[R]*n,L=r-h[R]*n;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${L.toFixed(2)}`,p=R+1}else{const w=(E+(i+o[R]*n))/2,L=(v+(r-h[R]*n))/2;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${L.toFixed(2)}`,p=R}}f+="Z"}g=m+1}}return f}Xn(t,i,r,n,o){const h=t.codePointAt(0)||0,a=this.Vn(i,h);let u=null;return i.glyf&&i.glyf[a]!==null?u=i.glyf[a]:(u=I.T.glyf.Js(i,a),i.glyf[a]=u),this.Kn(i,u,r,n,o)}jn(t,i,r,n,o,h,a,u){const f=r+(o-u*(a/i.head.unitsPerEm))/2,g=n+(h+.7*a)/2;return this.Xn(t,i,f,g,a).toSVG()||null}}class Qt{constructor(){l(this,"Yn");this.Yn=new Zt}qn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}Zn(){return"</g></svg>"}Jn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,h]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${h/255})"/>`}Qn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,h=n.cellY+i.cellHeight/2,a=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;a.push(`translate(${o} ${h})scale(${u} ${f})translate(${-o} ${-h})`)}return r.rotation&&a.push(`rotate(${r.rotation} ${o} ${h})`),` transform="${a.join(" ")}"`}eo(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:h,b:a,a:u}=t.secondaryColor,f=`rgba(${o},${h},${a},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Xn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const h=this.Yn.jn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!h)return"";const{r:a,g:u,b:f,a:g}=t.primaryColor,d=`rgba(${a},${u},${f},${g/255})`;return n.drawMode==="stroke"?`<path d="${h}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${h}" fill="${d}"/>`}so(t,i,r,n){const o=[],h=this.eo(t,i,n);h&&o.push(h);const a=this.Xn(t,i,r,n);if(a){const u=this.Qn(t,i);o.push(u?`<g${u}>${a}</g>`:a)}return o.join("")}io(t,i,r,n){const o=[this.qn(i),this.Jn(i,n),'<g id="ascii-cells">'];for(const h of t)o.push(this.so(h,i,r,n));return o.push(this.Zn()),o.join("")}ro(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class te extends st{no(t){return this.kn(t,"image/svg+xml;charset=utf-8")}oo(t,i){this.Pn(t,this.Dn(i)+".svg","image/svg+xml;charset=utf-8")}ao(t,i){this.oo(t,i||this.In())}}class ft{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new Jt,this.co=new Qt,this.lo=new te}uo(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.lo.In()}}fo(t,i={}){const r=this.ho.Hn(this.ho.Tn(t.pipeline),t.grid),n=this.co.io(r,t.grid,t.font,this.uo(i));return this.co.ro(n)}ao(t,i={}){this.lo.ao(this.fo(t,i),i.filename)}}class ee extends it{do(t,i,r,n=" "){var a;const o=[];let h=0;for(let u=0;u<i.rows;u++){const f=[];for(let g=0;g<i.cols;g++){const d=4*h,m=this.En(t.characterPixels,d),y=((a=r.characters[m])==null?void 0:a.character)||n;f.push(y),h++}o.push(f)}return o}}class ie{_o(t,i){const r=[];for(const o of t){let h=o.join("");i.preserveTrailingSpaces||(h=h.replace(/\s+$/,"")),r.push(h)}const n=i.lineEnding==="crlf"?`\r
|
|
7
|
+
`}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=>T.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>T.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}: ${T.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${T.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var M=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(M||{});const G=class G{constructor(){l(this,"u",{globalLevel:3})}static _(){return G.l||(G.l=new G),G.l}m(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(T.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(T.i(t,i)),console.groupEnd(),!1;default:throw new T(t,i)}}v(t,i,r){return!!t||(this.m(i,r),!1)}C(t){this.u.globalLevel=t}};l(G,"l",null);let Z=G;const N=Z._(),rt=new WeakMap;function H(c,t){rt.set(c,t)}function Y(c){return rt.get(c)}class nt{constructor(){l(this,"$",1);l(this,"U",0);l(this,"M",0);l(this,"F",0);l(this,"R",[0,0,0]);l(this,"S",[1,1,1,1]);l(this,"A",[0,0,0,1]);l(this,"L",!1);l(this,"k",!1);l(this,"P",!1);l(this,"G",[0,0]);l(this,"D",[0,0,0,1]);l(this,"I",[])}W(){this.I.push({O:this.$,H:this.U,V:this.M,K:this.F,G:[...this.G],N:this.L,X:this.k,P:this.P,j:[...this.R],Y:[...this.S],q:[...this.A]})}Z(){const t=this.I.pop();t?(this.$=t.O,this.U=t.H,this.M=t.V,this.F=t.K,this.G=t.G,this.L=t.N,this.k=t.X,this.P=t.P,this.R=t.j,this.S=t.Y,this.A=t.q):console.warn("pop() called without matching push()")}J(t){t.O=this.$,t.H=this.U,t.V=this.M,t.K=this.F,t.j[0]=this.R[0],t.j[1]=this.R[1],t.j[2]=this.R[2],t.Y[0]=this.S[0],t.Y[1]=this.S[1],t.Y[2]=this.S[2],t.Y[3]=this.S[3],t.q[0]=this.A[0],t.q[1]=this.A[1],t.q[2]=this.A[2],t.q[3]=this.A[3],t.N=this.L,t.X=this.k,t.P=this.P,t.G[0]=this.G[0],t.G[1]=this.G[1]}get lineWeight(){return this.$}get canvasBackgroundColor(){return this.D}tt(t){this.$=Math.abs(t)}et(t){this.U=t}st(t){this.M=t}it(t){this.F=t}rt(t){this.R=t}nt(t,i,r,n=255){this.S=[t/255,i/255,r/255,n/255]}ot(t,i,r,n=255){this.A=[t/255,i/255,r/255,n/255]}ht(t){this.L=t}ct(t){this.k=t}lt(t){this.P=t}ut(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.G=[r,n]}ft(t,i,r,n){this.D=[t/255,i/255,r/255,n/255]}}class V{constructor(t,i,r=i,n=1,o={},h=null,a=!1){l(this,"dt");l(this,"_t");l(this,"u");l(this,"gt",null);l(this,"vt");l(this,"yt");l(this,"Ct",[]);l(this,"wt");l(this,"$t",null);l(this,"bt",[]);l(this,"xt",null);l(this,"Mt",!1);l(this,"Ft",null);this.dt=i,this._t=r,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.vt=t,this.wt=Math.min(Math.max(1,n),8),this.xt=h,this.Mt=!!a,this.Ft=this.Mt?new nt:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.wt=Math.min(this.wt,u,f),this.yt=t.createFramebuffer(),this.Rt(),this.St(),this.bt=Array(this.wt).fill(null)}Rt(){const t=this.vt,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.wt;o++){const h=t.createTexture();t.bindTexture(t.TEXTURE_2D,h),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.dt,this._t,0,t.RGBA,n,null),this.Ct.push(h)}t.bindTexture(t.TEXTURE_2D,null)}St(){const t=this.vt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.wt===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Ct[0],0);else{const r=[];for(let n=0;n<this.wt;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Ct[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)}At(t){const i=this.vt;i.bindTexture(i.TEXTURE_2D,this.Ct[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)}resize(t,i){this.dt=t,this._t=i,this.gt=null,this.bt=Array(this.wt).fill(null);const r=this.vt,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Ct)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.dt,this._t,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}zt(t){const i=this.vt,r=this.bt[t];if(r)return r;const n=this.dt,o=this._t,h=new Uint8Array(n*o*4),a=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.yt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,h),i.bindFramebuffer(i.READ_FRAMEBUFFER,a);const u=4*n,f=new Uint8Array(h.length);for(let g=0;g<o;g++){const d=(o-1-g)*u,m=g*u;f.set(h.subarray(d,d+u),m)}return this.bt[t]=f,f}begin(){var i,r,n,o;const t=this.vt;if(this.xt){const h=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;h&&this.xt.Et(h),this.Mt&&this.Ft&&((o=(n=this.xt).Lt)==null||o.call(n,this.Ft))}this.$t={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.bt=Array(this.wt).fill(null);for(let h=0;h<this.wt;h++)t.clearBufferfv(t.COLOR,h,new Float32Array([0,0,0,0]));t.viewport(0,0,this.dt,this._t),H(t,[0,0,this.dt,this._t])}end(){var i,r,n,o;if(!this.$t)return;const t=this.vt;if(this.xt){const h=((r=(i=this.xt).Tt)==null?void 0:r.call(i))??null;h&&this.xt.Et(h)}t.bindFramebuffer(t.FRAMEBUFFER,this.$t.framebuffer),t.viewport(...this.$t.viewport),H(t,this.$t.viewport),this.$t=null,this.xt&&this.Mt&&this.Ft&&((o=(n=this.xt).kt)==null||o.call(n))}Pt(){const t=this.vt;t.deleteFramebuffer(this.yt);for(const i of this.Ct)t.deleteTexture(i)}get width(){return this.dt}get height(){return this._t}get textures(){return[...this.Ct]}}class z{constructor(t,i,r){l(this,"vt");l(this,"Gt");l(this,"Bt",new Map);l(this,"Dt",new Map);l(this,"It",0);this.vt=t,this.Gt=this.Wt(i,r),this.Ot()}Ot(){const t=this.vt.getProgramParameter(this.Gt,this.vt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.vt.getActiveUniform(this.Gt,i);if(r){const n=this.vt.getUniformLocation(this.Gt,r.name);if(n&&(this.Bt.set(r.name,n),this.Dt.set(r.name,{type:r.type,size:r.size}),r.size>1)){const o=r.name.replace(/\[.*\]$/,"");this.Bt.has(o)||(this.Bt.set(o,n),this.Dt.set(o,{type:r.type,size:r.size}))}}}}Wt(t,i){const r=this.Ht(this.vt.VERTEX_SHADER,t),n=this.Ht(this.vt.FRAGMENT_SHADER,i),o=this.vt.createProgram();if(this.vt.attachShader(o,r),this.vt.attachShader(o,n),this.vt.linkProgram(o),!this.vt.getProgramParameter(o,this.vt.LINK_STATUS)){const h=this.vt.getProgramInfoLog(o);throw Error("Shader program link error: "+h)}return this.vt.deleteShader(r),this.vt.deleteShader(n),o}Ht(t,i){const r=this.vt.createShader(t);if(this.vt.shaderSource(r,i),this.vt.compileShader(r),!this.vt.getShaderParameter(r,this.vt.COMPILE_STATUS)){const n=this.vt.getShaderInfoLog(r);throw this.vt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Vt(){this.vt.useProgram(this.Gt),this.Kt()}Kt(){this.It=0}Nt(t){for(const[i,r]of Object.entries(t))this.Xt(i,r)}jt(t){return this.Bt.has(t)}Yt(t){return this.Dt.get(t)||null}qt(){const t=[];for(const[i,r]of this.Dt.entries())t.push({name:i,...r});return t}Xt(t,i){var u;const r=this.Bt.get(t);if(!r)return;const n=this.Dt.get(t);if(!n)return void console.warn(`No type information found for uniform '${t}'`);const{type:o,size:h}=n,a=this.vt;if(typeof i=="number")switch(o){case a.INT:case a.BOOL:a.uniform1i(r,i);break;case a.FLOAT:a.uniform1f(r,i);break;default:console.warn(`Unexpected uniform type for scalar '${t}': ${o}`),a.uniform1f(r,i)}else if(typeof i=="boolean")a.uniform1i(r,i?1:0);else if(Array.isArray(i))if(Array.isArray(i[0])){const f=i,g=((u=f[0])==null?void 0:u.length)||0,d=f.flat();switch(o){case a.FLOAT_VEC2:g===2?a.uniform2fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 2, got ${g}`);break;case a.FLOAT_VEC3:g===3?a.uniform3fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 3, got ${g}`);break;case a.FLOAT_VEC4:g===4?a.uniform4fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 4, got ${g}`);break;default:console.warn(`Unsupported uniform type for vector array '${t}': ${o}`)}}else switch(o){case a.FLOAT_VEC2:i.length===2?a.uniform2f(r,i[0],i[1]):console.warn(`Vector length mismatch for '${t}': expected 2, got ${i.length}`);break;case a.FLOAT_VEC3:i.length===3?a.uniform3f(r,i[0],i[1],i[2]):console.warn(`Vector length mismatch for '${t}': expected 3, got ${i.length}`);break;case a.FLOAT_VEC4:i.length===4?a.uniform4f(r,i[0],i[1],i[2],i[3]):console.warn(`Vector length mismatch for '${t}': expected 4, got ${i.length}`);break;case a.INT:h>1?a.uniform1iv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;case a.FLOAT:h>1?a.uniform1fv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;default:console.warn(`Unsupported uniform type for array '${t}': ${o}`)}else if(i instanceof WebGLTexture){const f=this.Zt();a.uniform1i(r,f),a.activeTexture(a.TEXTURE0+f),a.bindTexture(a.TEXTURE_2D,i)}else if(i instanceof V){const f=this.Zt();a.uniform1i(r,f),a.activeTexture(a.TEXTURE0+f),a.bindTexture(a.TEXTURE_2D,i.textures[0])}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}Zt(){return this.It++}get Jt(){return this.Gt}Pt(){this.vt.deleteProgram(this.Gt)}}const j=`#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 U9;uniform vec2 Uy;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 A(float B){float C=sin(B),D=cos(B);return mat3(1,0,0,0,D,-C,0,C,D);}mat3 E(float B){float C=sin(B),D=cos(B);return mat3(D,0,C,0,1,0,-C,0,D);}mat3 F(float B){float C=sin(B),D=cos(B);return mat3(D,-C,0,C,D,0,0,0,1);}vec2 G(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return N*M*I+3.*N*H*J+3.*M*O*K+O*H*L;}vec2 P(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return-3.*N*I+3.*N*J-6.*M*H*J+6.*M*H*K-3.*O*K+3.*O*L;}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 Q;bool R=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool S=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(R){float H=a_position.x;vec2 T=G(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 U=P(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float V=length(U);U=V>0.?U/V:vec2(1,0);Q=T+vec2(-U.y,U.x)*a_position.y*a_instanceSize.y;}else if(S){float C=a_instanceArcAngles.x,W=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;W=mod(W,6.28318530718);if(W<0.)W+=6.28318530718;float X=C-W;if(X<=0.)X+=6.28318530718;float Y=C-a_position.x*X;vec2 Z=vec2(cos(Y),sin(Y))*a_position.y;Q=Z*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{Q=a_position*a_instanceSize+a_instancePosition;}vec2 a=(Q/Uy)*2.-1.;a.y=-a.y;if(length(a_instanceGlobalRotation)>0.){vec3 b=vec3(a-a_instanceRotationCenter,0);b.x*=U9;if(a_instanceGlobalRotation.x!=0.)b=A(-a_instanceGlobalRotation.x)*b;if(a_instanceGlobalRotation.y!=0.)b=E(-a_instanceGlobalRotation.y)*b;if(a_instanceGlobalRotation.z!=0.)b=F(-a_instanceGlobalRotation.z)*b;b.x/=U9;a=b.xy+a_instanceRotationCenter;}gl_Position=vec4(a,0,1);}`,ot="attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}";class vt{constructor(t){l(this,"vt");l(this,"Qt");l(this,"te");l(this,"ee");l(this,"se");this.vt=t,this.te=new z(this.vt,j,`#version 300 es
|
|
9
|
+
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.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`),this.Qt=new z(this.vt,j,`#version 300 es
|
|
10
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;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 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ee=new z(this.vt,ot,"precision mediump float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U2;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;mat2 A(float B){float C=sin(B);float D=cos(B);return mat2(D,-C,C,D);}void main(){vec2 E=gl_FragCoord.xy/U8;vec2 F=E*U7;vec2 G=floor(F);vec2 H=(G+0.5)/U7;vec4 I=texture2D(U3,H);vec4 J=texture2D(U4,H);vec4 K=texture2D(U5,H);bool L=K.r>0.5;bool M=K.g>0.5;bool N=K.b>0.5;vec4 O=texture2D(U2,H);int P=int(O.r*255.+0.5)+int(O.g*255.+0.5)*256;int Q=int(mod(float(P),U1.x));int R=P/int(U1.x);float S=(U1.y-1.)-float(R);vec2 T=vec2(float(Q),S)/U1;vec4 U=texture2D(U6,H);float V=U.r*255.+U.g;float W=-(V*360./255.)*0.017453292;vec2 X=fract(F)-0.5;if(M)X.x=-X.x;if(N)X.y=-X.y;X=A(W)*X+0.5;vec2 Y=1./U1;vec2 Z=T+X*Y;vec2 a=T+Y;if(any(lessThan(Z,T))||any(greaterThan(Z,a))){gl_FragColor=L?I:J;return;}vec4 b=texture2D(U0,Z);if(L)b.rgb=1.-b.rgb;gl_FragColor=mix(J,I,b);}"),this.se=new z(this.vt,j,`#version 300 es
|
|
11
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec3 Uq;uniform bool Ur;uniform vec3 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];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;float A(vec3 B){return dot(B,vec3(0.299,0.587,0.114));}void main(){vec2 C=vec2(v_uv.x,1.-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.),0.,F-1.);int H=int(floor(G+0.5));vec3 I=Uv[H];o_character=vec4(I,1.);}else{o_character=vec4(E,0.,0.,1.);}vec3 J=D.rgb;vec3 K=Up?Uq:J;vec3 L=Ur?Us:J;float M=Up?1.:D.a;float N;if(D.a<0.01){K=Ut.rgb;L=Ut.rgb;M=Ut.a;N=Ut.a;}else{N=Ur?1.:D.a;}o_primaryColor=vec4(K,M);o_secondaryColor=vec4(L,N);o_rotation=vec4(Uo.xy,0.,1.);o_transform=vec4(float(Ul),float(Um),float(Un),1.);}`)}ie(){return this.Qt}Tt(){return this.te}re(){return this.ee}ne(){return this.se}oe(t){return new z(this.vt,j,t)}ae(t,i){return new z(this.vt,t,i)}Pt(){this.Qt.Pt(),this.te.Pt(),this.ee.Pt(),this.se.Pt()}}var b=(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))(b||{});class xt{constructor(t){l(this,"vt");l(this,"he",new Map);this.vt=t}ce(t,i,r,n){const o=this.vt;let h=this.he.get(t);h||(h=new Map,this.he.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ue.le.size,o.FLOAT,!1,r.fe,r.ue.le.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ue.de.size,o.FLOAT,!1,r.fe,r.ue.de.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}_e(){this.vt.bindVertexArray(null)}Pt(){for(const[,t]of this.he)for(const[,i]of t)i&&this.vt.deleteVertexArray(i)}}class yt{constructor(t,i){l(this,"pe");l(this,"vt");l(this,"xt");l(this,"me",null);l(this,"ge",null);this.vt=t,this.pe=new xt(t),this.xt=i}ve(t,i,r){const{shader:n}=t,o=Y(this.vt)||this.vt.getParameter(this.vt.VIEWPORT);n.Nt({U9:o[2]/o[3],Uy:[o[2],o[3]]});const h=f=>{if(!f||!f.ye())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.pe.ce(n.Jt,f.type+"",g,d),f.batch.Ce(n),f.batch.we(g.$e,g.be)}finally{f.batch.xe(n),this.pe._e(),f.Me()}};let a=null,u=null;for(const f of i){if(f.type===b.CUSTOM){u&&(h(u),a=null,u=null),this.Fe(t,f.params,f.state,r.get(b.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let g=u;g&&f.type===a||(g=r.get(f.type)||null,u=g,a=f.type),g&&g.Re(f.params,f.state)}h(u)}Fe(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:g}=i,d=this.Se(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));d.begin(),this.Ae(n,f,g,0,0,d.width,d.height,{}),d.end();const m=this.ze(),y={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.Ae(n,m,y,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Vt()}Ae(t,i,r,n,o,h,a,u){i.Vt(),i.Nt(r);const f=this.vt.getParameter(this.vt.VIEWPORT);if(i.Nt({U9:f[2]/f[3],Uy:[f[2],f[3]]}),t.Me(),t.Re({x:n,y:o,width:h,height:a},u),t.ye()){const g=t.unitGeometry,d=t.unitBuffer;try{this.pe.ce(i.Jt,t.type+"",g,d),t.batch.Ce(i),t.batch.we(g.$e,g.be)}finally{t.batch.xe(i),this.pe._e(),t.Me()}}}ze(){return this.xt.ie()}Se(t,i){return this.me&&this.ge&&this.ge.w===t&&this.ge.h===i||(this.me&&this.me.Pt(),this.me=new V(this.vt,t,i,5),this.ge={w:t,h:i}),this.me}Pt(){this.pe.Pt(),this.me&&this.me.Pt()}}class Et{constructor(){l(this,"Te",[]);l(this,"Ee",1);l(this,"Le",0)}ke(t){if(this.Le>=this.Te.length){const r={id:this.Ee++,type:t,params:{},state:{O:1,H:0,V:0,K:0,j:[0,0,0],Y:[1,1,1,1],q:[0,0,0,1],N:!1,X:!1,P:!1,G:[0,0]}};this.Te.push(r)}const i=this.Te[this.Le];return i.id=this.Ee++,i.type=t,this.Le++,i}Pe(t,i,r,n,o){const h=this.ke(b.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ge(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}Be(t,i,r,n,o,h){const a=this.ke(b.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}De(t,i,r,n,o){const h=this.ke(b.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ie(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}We(t,i,r,n,o,h,a){const u=this.ke(b.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=h,a.J(u.state),u.id}Oe(t,i,r,n,o,h,a,u,f,g){const d=this.ke(b.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=h,d.params.x2=a,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Le}get isEmpty(){return this.Le===0}He(){this.Le=0}[Symbol.iterator](){let t=0;const i=this.Le,r=this.Te;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const B=class B{static Ve(t,i,r=0){var h,a,u,f,g,d,m,y,x,p;const n=i||new Float32Array(B.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.le[0],n[o++]=t.le[1],n[o++]=t.Le[0],n[o++]=t.Le[1],n[o++]=t.j[0],n[o++]=t.j[1],n[o++]=t.j[2],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.Y[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.G[0],n[o++]=t.G[1],n[o++]=t.Ke[0],n[o++]=t.Ke[1],n[o++]=t.Ke[2],n[o++]=t.H,n[o++]=t.V,n[o++]=t.K,n[o++]=t.Ne[0],n[o++]=t.Ne[1],n[o++]=((h=t.Xe)==null?void 0:h[0])||0,n[o++]=((a=t.Xe)==null?void 0:a[1])||0,n[o++]=((u=t.je)==null?void 0:u[0])||0,n[o++]=((f=t.je)==null?void 0:f[1])||0,n[o++]=((g=t.Ye)==null?void 0:g[0])||0,n[o++]=((d=t.Ye)==null?void 0:d[1])||0,n[o++]=((m=t.qe)==null?void 0:m[0])||0,n[o++]=((y=t.qe)==null?void 0:y[1])||0,n[o++]=((x=t.Ze)==null?void 0:x[0])||0,n[o++]=((p=t.Ze)==null?void 0:p[1])||0,n}static Je(t){const i=t.length*B.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*B.FLOATS_PER_INSTANCE;B.Ve(t[n],r,o)}return r}};l(B,"BYTES_PER_INSTANCE",140),l(B,"FLOATS_PER_INSTANCE",35);let D=B;const U=class U{};l(U,"STRIDE",D.BYTES_PER_INSTANCE),l(U,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let K=U;class wt{constructor(t,i=1e3,r=1.5){l(this,"vt");l(this,"Qe",[]);l(this,"ts");l(this,"es");l(this,"ss",null);l(this,"rs",!0);l(this,"ns",0);l(this,"hs",new Map);l(this,"cs",null);this.vt=t,this.ts=i,this.es=r,this.ls()}Re(t){const i=this.Qe.length;return this.Qe.push(t),this.rs=!0,i}get count(){return this.Qe.length}get isEmpty(){return this.Qe.length===0}clear(){this.Qe.length=0,this.rs=!0}us(t){if(t<=this.ts)return;const i=Math.ceil(t*this.es);this.ts=i,this.ls()}ls(){const t=this.vt;this.ss&&t.deleteBuffer(this.ss),this.ss=t.createBuffer();const i=this.ts*D.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ss),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!0,this.ns=0}fs(){if(!this.rs||this.Qe.length===0)return;const t=this.vt,i=this.Qe.length;this.us(i),(!this.cs||this.cs.length<i*D.FLOATS_PER_INSTANCE)&&(this.cs=new Float32Array(i*D.FLOATS_PER_INSTANCE));const r=D.Je(this.Qe);t.bindBuffer(t.ARRAY_BUFFER,this.ss),i<=this.ns?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!1,this.ns=i}ds(t){let i=this.hs.get(t);if(!i){i=new Map;const r=this.vt;for(const n in K.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.hs.set(t,i)}return i}Ce(t){if(!this.ss||this.Qe.length===0)return;const i=this.vt,r=t.Jt;this.fs();const n=this.ds(r);i.bindBuffer(i.ARRAY_BUFFER,this.ss);for(const[o,h]of n){const a=K.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}xe(t){const i=this.vt,r=this.ds(t.Jt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}we(t,i){this.Qe.length!==0&&this.vt.drawArraysInstanced(t,0,i,this.Qe.length)}Pt(){this.ss&&this.vt.deleteBuffer(this.ss)}}class ${constructor(t,i,r,n){l(this,"vt");l(this,"_s");l(this,"ps");l(this,"gs");l(this,"vs",null);this.vt=t,this._s=i,this.ps=r,this.gs=n;const o=this.vt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.vt.bindBuffer(this.vt.ARRAY_BUFFER,o),this.vt.bufferData(this.vt.ARRAY_BUFFER,this.gs.Cs,this.vt.STATIC_DRAW),this.vt.bindBuffer(this.vt.ARRAY_BUFFER,null),this.vs=o}get type(){return this.ps}get unitGeometry(){return this.gs}get unitBuffer(){return this.vs}get batch(){return this._s}Me(){this._s.clear()}ye(){return!this._s.isEmpty}Pt(){this._s.Pt(),this.vt.deleteBuffer(this.vs)}ws(t,i,r,n,o){const h=this.$s(t,i,r,n,o.H||0,o.V||0,o.K||0);return{le:[t,i],Le:[r,n],j:o.j||[0,0,0],Y:o.Y||[1,1,1,1],q:o.q||[0,0,0,1],G:o.G||[0,0],Ke:[o.P?1:0,o.N?1:0,o.X?1:0],H:h.radiansX,V:h.radiansY,K:h.radiansZ,Ne:[h.centerX,h.centerY]}}bs(t,i){const r=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}Ms(t,i,r){const n=this.bs(i,r);t.Ne=[n.nx,n.ny]}$s(t,i,r,n,o,h,a){const u=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/g}}}const Rt={Cs: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]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class bt extends ${constructor(t,i){super(t,i,b.RECTANGLE,Rt)}Re(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this._s.Re(r)}}const Tt={Cs: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]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class At extends ${constructor(t,i){super(t,i,b.LINE,Tt)}Re(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.O||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,g=u,d=this.ws(f,g,o,h,i);return this.Ms(d,a,u),this._s.Re(d)}}const Ct={Cs: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,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),g=Math.cos(o),d=Math.sin(o),m=.5*(g+1),y=.5*(d+1);t.push(0,0,.5,.5,h,a,u,f,g,d,m,y)}return new Float32Array(t)}(32),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ut extends ${constructor(t,i){super(t,i,b.ELLIPSE,Ct)}Re(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.Ms(r,t.x,t.y),this._s.Re(r)}}let _t={Cs: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),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Ft extends ${constructor(t,i){super(t,i,b.ARC,_t)}Re(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.ws(r,n,t.width,t.height,i);return this.Ms(a,t.x,t.y),a.Xe=[o,h],this._s.Re(a)}}const Lt={Cs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),be:3,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Pt extends ${constructor(t,i){super(t,i,b.TRIANGLE,Lt)}Re(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),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.ws(r,o,h,a,i),f=r+.5*h,g=o+a*(1/3);return this.Ms(u,f,g),this._s.Re(u)}}function ht(c,t,i,r,n){const o=1-c,h=o*o,a=c*c;return h*o*t+3*h*c*i+3*o*a*r+a*c*n}const St={Cs: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),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class It extends ${constructor(t,i){super(t,i,b.BEZIER_CURVE,St)}Re(t,i){const r=i.O||1,n=ht(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=ht(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.ws(0,0,1,r,i);return this.Ms(h,n,o),h.qe=[t.x1,t.y1],h.je=[t.cp1x,t.cp1y],h.Ye=[t.cp2x,t.cp2y],h.Ze=[t.x2,t.y2],this._s.Re(h)}}class Bt{constructor(t){l(this,"vt");l(this,"Fs",null);l(this,"Rs");l(this,"Ss",null);l(this,"As",{});l(this,"zs",null);l(this,"Ts",new Map);l(this,"Es");l(this,"Ls");l(this,"ks");l(this,"I",[]);this.vt=t,this.Rs=new vt(t),this.ks=new nt,this.Es=new yt(t,this),this.Ls=new Et,this.zs=t.createBuffer(),H(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}Ps(t){let i=this.Ts.get(t);if(i)return i;const r=new wt(this.vt);return i=(0,{[b.RECTANGLE]:()=>new bt(this.vt,r),[b.LINE]:()=>new At(this.vt,r),[b.ELLIPSE]:()=>new Ut(this.vt,r),[b.ARC]:()=>new Ft(this.vt,r),[b.TRIANGLE]:()=>new Pt(this.vt,r),[b.BEZIER_CURVE]:()=>new It(this.vt,r)}[t])(),this.Ts.set(t,i),i}Gs(t){this.Fs!==t&&(this.Fs=t,t.Vt())}ae(t,i){return this.Rs.ae(t,i)}ie(){return this.Rs.ie()}Tt(){return this.Rs.Tt()}re(){return this.Rs.re()}ne(){return this.Rs.ne()}Bs(t){this.Ss=t,t&&(this.As={})}Xt(t,i){this.As[t]=i}Ds(t){Object.assign(this.As,t)}oe(t){return this.Rs.oe(t)}Is(t,i,r,n,o){const h=this.ie(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.Ls.Ge(i,r,n,o,h,a,this.ks)}Ws(t,i,r,n,o){const h=this.ne(),a=t.texture,u=t.flags,f=t.charRotationRG,g=[f[0],f[1]],d=t.colorUniforms??{charColorFixed:!1,Y:[1,1,1],cellColorFixed:!1,cellColor:[0,0,0],backgroundColor:[0,0,0,1]},m=t.characterListUniforms,y={Uk:a,Ul:!!u.invert,Um:!!u.flipX,Un:!!u.flipY,Uo:g,Up:!!d.charColorFixed,Uq:d.Y,Ur:!!d.cellColorFixed,Us:d.cellColor,Ut:d.backgroundColor,Uu:m.count,Uv:m.list};this.Ls.Ge(i,r,n,o,h,y,this.ks)}Os(t,i,r,n){var p;const o=this.vt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,g=1-i/a*2,d=1-(i+n)/a*2,m=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.zs),o.bufferData(o.ARRAY_BUFFER,m,o.DYNAMIC_DRAW);const y=((p=this.Fs)==null?void 0:p.Jt)||o.getParameter(o.CURRENT_PROGRAM),x=y?o.getAttribLocation(y,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Hs(t,i,r,n){this.Ss?(this.Ls.Ge(t,i,r,n,this.Ss,{...this.As},this.ks),this.Ss=null,this.As={}):this.Ls.Pe(t,i,r,n,this.ks)}Vs(t,i,r,n){this.Ls.Be(t,i,r,n,this.ks.lineWeight,this.ks)}Ks(t,i,r,n){this.Ls.De(t,i,r,n,this.ks)}Ns(t,i,r,n,o,h){this.Ls.We(t,i,r,n,o,h,this.ks)}Xs(t,i,r,n,o,h,a,u){const f=this.ks.lineWeight;this.Ls.Oe(t,i,r,n,o,h,a,u,f,this.ks)}js(t,i,r=1,n={}){return new V(this.vt,t,i,r,n,this,!0)}Ys(t,i,r,n,o,h){this.Ls.Ie(t,i,r,n,o,h,this.ks)}qs(t,i=t,r=t,n=255){this.state.ft(t,i,r,n),this.He(t/255,i/255,r/255,n/255)}He(t=0,i=0,r=0,n=0){this.vt.clearColor(t,i,r,n),this.vt.clear(this.vt.COLOR_BUFFER_BIT)}Zs(){this.vt.viewport(0,0,this.vt.canvas.width,this.vt.canvas.height),H(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}get context(){return this.vt}get state(){return this.ks}Lt(t){this.I.push(this.ks),this.ks=t}kt(){const t=this.I.pop();t&&(this.ks=t)}Et(t){const i=t,r=Y(this.vt)??this.vt.getParameter(this.vt.VIEWPORT),n={shader:i,gl:this.vt,viewport:r};this.Gs(i);const o=new Set;for(const h of this.Ls)h.type===b.CUSTOM?o.add(b.RECTANGLE):o.add(h.type);for(const h of o)h!==b.CUSTOM&&this.Ps(h);this.Es.ve(n,this.Ls,this.Ts),this.Ls.He()}Pt(){this.vt.deleteBuffer(this.zs),this.Ls.He();for(const t of this.Ts.values())t.Pt();this.Rs.Pt(),this.Es.Pt()}}const A={readShort:(c,t)=>(A.t.uint16[0]=c[t]<<8|c[t+1],A.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(A.readUshort(c,t+2*n));return r},readUint(c,t){const i=A.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],A.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},writeUshort(c,t,i){c[t]=i>>>8&255,c[t+1]=255&i},writeUint(c,t,i){c[t]=i>>>24&255,c[t+1]=i>>>16&255,c[t+2]=i>>>8&255,c[t+3]=255&i},writeASCII(c,t,i){for(let r=0;r<i.length;r++)c[t+r]=255&i.charCodeAt(r)},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()};function q(c){return c+3&-4}function Q(c,t,i){const r=t+i;let n=0;const o=A.t;for(let h=t;h<r;h+=4)o.uint8[3]=c[h]||0,o.uint8[2]=c[h+1]||0,o.uint8[1]=c[h+2]||0,o.uint8[0]=c[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class Mt{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function W(c){let t=32,i=0;for(const a of c)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of c)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<c.length;a++){const u=c[a];if(!u)continue;const f=n[u]++;let g=h.get(u);g||(g=[],h.set(u,g)),g[Dt(f,u)]=a}return{min:t,max:i,table:h}}function tt(c,t){let i=0;for(let r=1;r<=t.max;r++){i|=c.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function Dt(c,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&c,c>>>=1;return i>>>0}function Gt(c){if(c.length<2)throw Error("ZLIB data too short");const t=c[0],i=c[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const m=o.readBits(2);if(m===0){o.alignToByte();const y=o.readBits(16);if((65535&(65535^y))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let x=0;x<y;x++)h.push(o.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let y,x;if(m===1){const p=Array(288).fill(0);for(let E=0;E<=143;E++)p[E]=8;for(let E=144;E<=255;E++)p[E]=9;for(let E=256;E<=279;E++)p[E]=7;for(let E=280;E<=287;E++)p[E]=8;y=W(p),x=W(Array(32).fill(5))}else{const p=o.readBits(5)+257,E=o.readBits(5)+1,v=o.readBits(4)+4,R=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let P=0;P<v;P++)w[R[P]]=o.readBits(3);const L=W(w),_=[];for(;_.length<p+E;){const P=tt(o,L);if(P<=15)_.push(P);else if(P===16){const X=o.readBits(2)+3,O=_[_.length-1]||0;for(let mt=0;mt<X;mt++)_.push(O)}else if(P===17){const X=o.readBits(3)+3;for(let O=0;O<X;O++)_.push(0)}else{if(P!==18)throw Error("Invalid code length symbol");{const X=o.readBits(7)+11;for(let O=0;O<X;O++)_.push(0)}}}const F=_.slice(0,p),S=_.slice(p,p+E);y=W(F),x=W(S)}for(;;){const p=tt(o,y);if(p<256)h.push(p);else{if(p===256)break;if(p>256&&p<286){const E=p-257;let v=a[E];const R=u[E];R&&(v+=o.readBits(R));const w=tt(o,x);if(w>=30)throw Error("Invalid distance symbol");let L=f[w];const _=g[w];_&&(L+=o.readBits(_));const F=h.length-L;if(F<0)throw Error("Invalid distance");for(let S=0;S<v;S++)h.push(h[F+S]||0)}else if(p===286||p===287)throw Error("Reserved length symbol")}}}}}}(new Mt(c.subarray(r)),n),new Uint8Array(n)}function Ot(c){const t=A,i=new Uint8Array(c);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let v=0;v<n;v++){const R=t.readASCII(i,a,4),w=t.readUint(i,a+4),L=t.readUint(i,a+8),_=t.readUint(i,a+12),F=t.readUint(i,a+16);h.push({tag:R,offset:w,compLength:L,origLength:_,checksum:F}),a+=20}for(const v of h){const R=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(R);else if(v.data=Gt(R),v.data.length!==v.origLength)if(v.data.length<v.origLength){const w=new Uint8Array(v.origLength);w.set(v.data),v.data=w}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,m=16*u-d;let y=12+16*u;const x={};for(const v of h)x[v.tag]=y,y=q(y+v.data.length);const p=new Uint8Array(Math.max(o||0,y));t.writeUint(p,0,r),t.writeUshort(p,4,u),t.writeUshort(p,6,d),t.writeUshort(p,8,g),t.writeUshort(p,10,m);let E=12;for(const v of h){t.writeASCII(p,E,v.tag),E+=4;let R=v.data;if(v.tag==="head"&&R.length>=12){const w=new Uint8Array(R);t.writeUint(w,8,0);const L=Q(w,0,q(w.length));t.writeUint(p,E,L),E+=4}else{const w=Q(R,0,q(R.length));t.writeUint(p,E,w),E+=4}t.writeUint(p,E,x[v.tag]),E+=4,t.writeUint(p,E,v.data.length),E+=4}for(const v of h){const R=x[v.tag];p.set(v.data,R)}if(h.find(v=>v.tag==="head")){const v=x.head,R=function(w,L){const _=A,F=L+8,S=[w[F],w[F+1],w[F+2],w[F+3]];_.writeUint(w,F,0);const P=2981146554-(Q(w,0,q(w.length))>>>0)>>>0;return w[F]=S[0],w[F+1]=S[1],w[F+2]=S[2],w[F+3]=S[3],P>>>0}(p,v);t.writeUint(p,v+8,R)}return p.buffer}const zt={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=A,o=n.readUshort,h=o(c,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const m=`p${f}e${g}`;let y=a.indexOf(d);if(y===-1){let x;y=r.tables.length,a.push(d);const p=o(c,d);x=p===4?this.parse4(c,d):p===12?this.parse12(c,d):{format:p},r.tables.push(x)}r.ids[m]=y}return r},parse4(c,t){const i=A,r=i.readUshort,n=i.readUshorts,o=t,h=r(c,t+=2);t+=2;const a=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,a),t+=2*a,t+=2,u.startCount=n(c,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,a),t+=2*a,u.glyphIdArray=n(c,t,o+h-t>>1),u},parse12(c,t){const i=A.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}}},$t={parseTab(c,t,i){const r=A;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(c,t)}}},kt={parseTab(c,t,i){const r=A;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(c,t+2*h)}return o}},Nt={parseTab(c,t,i,r){const n=A,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)f=n.readUshort(c,t+(d<<2)),g=n.readShort(c,t+(d<<2)+2),o.push(f),h.push(g),d++;for(;d<a;)o.push(f),h.push(g),d++;return{aWidth:o,lsBearing:h}}},at={cmap:zt,head:$t,hhea:kt,maxp:{parseTab(c,t,i){const r=A;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Nt,loca:{parseTab(c,t,i,r){const n=A,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;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 h=0;h<o;h++)n.push(null);return n},Js(c,t){const i=A,r=c.Qs,n=c.loca;if(n[t]===n[t+1])return null;const o=I.findTable(r,"glyf",c.ti);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let m=0;m<a.noc;m++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let m=0;m<f;m++){const y=r[h];if(h++,a.flags.push(y),8&y){const x=r[h];h++;for(let p=0;p<x;p++)a.flags.push(y),m++}}a.xs=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(16&y);2&y?(a.xs.push(x?r[h]:-r[h]),h++):x?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(32&y);4&y?(a.ys.push(x?r[h]:-r[h]),h++):x?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let g=0,d=0;for(let m=0;m<f;m++)g+=a.xs[m],d+=a.ys[m],a.xs[m]=g,a.ys[m]=d}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},I={parse(c){const t=new Uint8Array(c),i=A.readASCII(t,0,4);if(i==="wOFF")c=Ot(c);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=at,u={Qs:r,ei:n,ti:o};for(const f in a){const g=f,d=I.findTable(r,g,o);if(d){const[m,y]=d;let x=h[m];x==null&&(x=a[g].parseTab(r,m,y,u),h[m]=x),u[g]=x}}return u})(new Uint8Array(c),0,0,{})]},findTable(c,t,i){const r=A,n=r.readUshort(c,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),f=r.readUint(c,o+12);if(a===t)return[u,f];o+=16}return null},T:at,B:A};class Wt{si(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(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 h=n;h<=o;h++)if(this.ai(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ri(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],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}ai(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}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){l(this,"hi",new Map);l(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.hi.has(r))return this.hi.get(r);const n=t.cmap;if(!n||!n.tables)return this.hi.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.fi(i,h):h.format===12&&(o=this.di(i,h)),o>0)break;return this.hi.set(r,o),o}_i(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}pi(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}mi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}gi(){this.hi.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Qs.length}`}fi(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 h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}di(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Xt{constructor(t){l(this,"yi");l(this,"Ci");l(this,"xt");l(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ci=this.yi.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,g=typeof n=="object"?n:null;this.$i(u,f),this.bi(t,i,h,r,g);const d=this.xt.js(u,f,1,{filter:"nearest"});return d.At(this.yi),{framebuffer:d,columns:h,rows:a}}$i(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=t+"px",this.Ci.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ci.fillStyle="black",this.Ci.fillRect(0,0,t,i),this.Ci.textBaseline="top",this.Ci.textAlign="left",this.Ci.fillStyle="white"}bi(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),g=t[a].character,d=this.xi(o,g);if(!d)continue;const m=g.codePointAt(0)||0,y=this.wi.li(o,m),x=this.Mi(o,y)*h,p=u*i.width,E=f*i.height,v=p+.5*i.width,R=E+.5*i.height,w=Math.round(v-.5*i.width),L=Math.round(R-.5*n),_=w+.5*(i.width-x),F=L+o.hhea.ascender*h;this.Fi(d,_,F,h)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(I&&I.T&&I.T.glyf){const o=I.T.glyf.Js(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Mi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Fi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.Ci.beginPath();let f=0;for(let g=0;g<a.length;g++){const d=a[g];if(!(d<f)){if(d>=f){const m=i+o[f]*n,y=r-h[f]*n;this.Ci.moveTo(m,y);let x=f+1;for(;x<=d;)if(1&u[x]){const p=i+o[x]*n,E=r-h[x]*n;this.Ci.lineTo(p,E),x++}else{const p=i+o[x]*n,E=r-h[x]*n;let v=x+1>d?f:x+1;if(1&u[v]){const R=i+o[v]*n,w=r-h[v]*n;this.Ci.quadraticCurveTo(p,E,R,w),x=v+1}else{const R=(p+(i+o[v]*n))/2,w=(E+(r-h[v]*n))/2;this.Ci.quadraticCurveTo(p,E,R,w),x=v}}this.Ci.closePath()}f=d+1}}this.Ci.fill()}}class Ht{constructor(){l(this,"Ri");this.Ri=new et}Si(t,i,r){let n=0;const o=this.Ri.mi(r,i),h=o.lineHeight;for(const a of t){const u=this.Ri._i(r,a);if(u===0)continue;const f=this.Ri.pi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}gi(){this.Ri.gi()}}class Yt{constructor(){l(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.Ai(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}Ai(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}zi(t,i){if(!N.v(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]}Ti(t,i){return N.v(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.zi(r,i)||[0,0,0]):[[0,0,0]]}}class ct{constructor(t,i=16){l(this,"Ei");l(this,"Li",[]);l(this,"ki");l(this,"Pi",16);l(this,"Gi",0);l(this,"Bi",0);l(this,"Di",{width:0,height:0});l(this,"Ii");l(this,"Wi");l(this,"Oi");l(this,"Hi");l(this,"Vi");this.Pi=i,this.Wi=new Wt,this.Oi=new Xt(t),this.Hi=new Ht,this.Vi=new Yt}async Ki(t){let i;if(!t)throw new T("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new T(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Ni(i),this.Ei=I.parse(i)[0],await this.Xi()}ji(t){if(t===void 0)return this.Pi;this.Pi=t,this.Di=this.Hi.Si(this.Li.map(r=>r.character),this.Pi,this.Ei);const i=this.Oi.createTextureAtlas(this.Li,this.Di,this.Pi,this.Ei);this.ki=i.framebuffer,this.Gi=i.columns,this.Bi=i.rows}async Yi(t){try{const i=await fetch(t);if(!i.ok)throw new T(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ni(r);const n=I.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Ei=n[0],await this.Xi()}catch(i){throw new T("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ni(t){const i=Date.now();this.Ii=new FontFace("CustomFont_"+i,t),await this.Ii.load(),document.fonts.add(this.Ii)}async Xi(){const t=this.Wi.si(this.Ei),i=this.Wi.ni(t);this.Li=this.Vi.createCharacterObjects(i,this.Ei),this.Di=this.Hi.Si(i,this.Pi,this.Ei);const r=this.Oi.createTextureAtlas(this.Li,this.Di,this.Pi,this.Ei);this.ki=r.framebuffer,this.Gi=r.columns,this.Bi=r.rows}zi(t){return this.Vi.zi(t,this.Li)}Ti(t){return this.Vi.Ti(t,this.Li)}Pt(){this.ki.Pt(),document.fonts.delete(this.Ii)}get fontFramebuffer(){return this.ki}get characters(){return this.Li}get textureColumns(){return this.Gi}get textureRows(){return this.Bi}get maxGlyphDimensions(){return this.Di}get fontSize(){return this.Pi}get font(){return this.Ei}}class lt{constructor(t,i,r){l(this,"qi");l(this,"Zi");l(this,"dt");l(this,"_t");l(this,"Ji");l(this,"Qi");l(this,"tr");l(this,"er");l(this,"sr");this.tr=t,this.er=i,this.sr=r,this.ir()}ir(){this.qi=Math.floor(this.tr.width/this.er),this.Zi=Math.floor(this.tr.height/this.sr),this.dt=this.qi*this.er,this._t=this.Zi*this.sr,this.Ji=Math.floor((this.tr.width-this.dt)/2),this.Qi=Math.floor((this.tr.height-this._t)/2)}rr(t,i){this.er=t,this.sr=i,this.ir()}get cellWidth(){return this.er}get cellHeight(){return this.sr}get cols(){return this.qi}get rows(){return this.Zi}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.Ji}get offsetY(){return this.Qi}}class ut{constructor(t={}){l(this,"tr");l(this,"nr",null);l(this,"ar",!1);l(this,"hr");l(this,"cr");this.ar=t.overlay??!1,this.ar&&t.canvas?(this.nr=t.canvas,this.tr=this.lr(),this.cr=!0,this.ur()):t.canvas?(this.tr=t.canvas,this.cr=!1):(this.tr=this.dr(t.width,t.height),this.cr=!0),this.tr.style.imageRendering="pixelated"}dr(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}lr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.nr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.nr instanceof HTMLVideoElement){const a=this.nr;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.nr);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}ur(){var t;this._r(),(t=this.nr.parentNode)==null||t.insertBefore(this.tr,this.nr.nextSibling),window.ResizeObserver&&(this.hr=new ResizeObserver(()=>{this.pr()}),this.hr.observe(this.nr)),window.addEventListener("resize",()=>{this.pr()})}_r(){if(!this.nr)return;const t=this.nr.getBoundingClientRect();let i=this.nr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.tr.style.top=t.top-r.top+"px",this.tr.style.left=t.left-r.left+"px"}else this.tr.style.top=t.top+window.scrollY+"px",this.tr.style.left=t.left+window.scrollX+"px"}pr(t,i){if(this.ar){const r=this.nr.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.nr instanceof HTMLVideoElement){const h=this.nr;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.tr.width=n,this.tr.height=o,this._r()}else this.tr.width=t??this.tr.width,this.tr.height=i??this.tr.height}mr(){const t=this.tr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new T("`textmode.js` requires WebGL2 support.");return t}Pt(){this.hr&&this.hr.disconnect();const t=this.tr.getContext("webgl")||this.tr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.cr&&this.tr.parentNode&&this.tr.parentNode.removeChild(this.tr)}get canvas(){return this.tr}get targetCanvas(){return this.nr}get width(){return this.tr.width}get height(){return this.tr.height}}class k{constructor(t,i,r,n){l(this,"texture");l(this,"width");l(this,"height");l(this,"vt");l(this,"P",0);l(this,"N",0);l(this,"X",0);l(this,"G",[0,0]);l(this,"gr","sampled");l(this,"vr","fixed");l(this,"Y",[1,1,1]);l(this,"q",[0,0,0]);l(this,"yr",[0,0,0,1]);l(this,"Cr",[[.1,0,0]]);l(this,"wr");this.vt=t,this.texture=i,this.width=r,this.height=n}Pt(){this.vt.deleteTexture(this.texture)}$r(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.P=this.$r(t),this}flipX(t=!0){return this.N=this.$r(t),this}flipY(t=!0){return this.X=this.$r(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.G=[r,n],this}get flags(){return{invert:this.P,flipX:this.N,flipY:this.X}}get charRotationRG(){return this.G}charColorMode(t){return this.gr=t,this}cellColorMode(t){return this.vr=t,this}charColor(t,i,r){return this.Y=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}cellColor(t,i,r){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}background(t,i,r,n){return this.yr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}charactersFromColors(t){const i=t.filter(r=>Array.isArray(r)).slice(0,64);return this.Cr=i,this}characters(t){const i=this.wr(t);return this.charactersFromColors(i),this}get characterListUniforms(){return{count:this.Cr.length,list:this.Cr}}get colorUniforms(){return{charColorFixed:this.gr==="fixed",Y:this.Y,cellColorFixed:this.vr==="fixed",cellColor:this.q,backgroundColor:this.yr}}static fromSource(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new k(n,o,h,a);return u.wr=r,u}}class Vt{constructor(t=60){l(this,"br");l(this,"Mr");l(this,"Fr",null);l(this,"Rr",0);l(this,"Sr",!0);l(this,"Ar",0);l(this,"zr",0);l(this,"Tr",[]);l(this,"Er",10);l(this,"Lr",0);this.br=t,this.Mr=1e3/t}start(t){if(!this.Sr)return;this.Rr=performance.now();const i=r=>{if(!this.Sr)return void(this.Fr=null);const n=r-this.Rr;n>=this.Mr&&(t(),this.Rr=r-n%this.Mr),this.Sr&&(this.Fr=requestAnimationFrame(i))};this.Fr=requestAnimationFrame(i)}stop(){this.Fr&&(cancelAnimationFrame(this.Fr),this.Fr=null)}pause(){this.Sr&&(this.Sr=!1,this.stop())}resume(t){this.Sr||(this.Sr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Ar;this.br=t,this.Mr=1e3/t,this.Sr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.zr>0){const i=t-this.zr;this.Tr.push(i),this.Tr.length>this.Er&&this.Tr.shift();const r=this.Tr.reduce((n,o)=>n+o,0)/this.Tr.length;this.Ar=1e3/r}this.zr=t}get isLooping(){return this.Sr}get frameRateLimit(){return this.br}get currentFrameRate(){return this.Ar}get frameCount(){return this.Lr}set frameCount(t){this.Lr=t}incrementFrame(){this.Lr++}resetFrameCount(){this.Lr=0}}class jt{constructor(){l(this,"kr",new Map);l(this,"Pr",null);l(this,"Gr",null);l(this,"Br");l(this,"Dr");l(this,"Ir",!1);l(this,"Wr");l(this,"Or");l(this,"Hr",{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"})}Vr(){this.Ir||(this.Br=t=>{this.Kr(t)},this.Dr=t=>{this.Nr(t)},window.addEventListener("keydown",this.Br,{passive:!1}),window.addEventListener("keyup",this.Dr,{passive:!1}),this.Ir=!0)}Xr(){this.Ir&&(window.removeEventListener("keydown",this.Br),window.removeEventListener("keyup",this.Dr),this.Ir=!1,this.kr.clear(),this.Pr=null,this.Gr=null)}jr(t){this.Wr=t}Yr(t){this.Or=t}qr(t){const i=this.Zr(t),r=this.kr.get(t)||this.kr.get(i);return(r==null?void 0:r.isPressed)||!1}Jr(){return this.Pr}Qr(){return this.Gr}tn(){const t=[];for(const[i,r]of this.kr)r.isPressed&&t.push(i);return t}en(){return{ctrl:this.qr("Control"),shift:this.qr("Shift"),alt:this.qr("Alt"),meta:this.qr("Meta")}}sn(){this.kr.clear(),this.Pr=null,this.Gr=null}Kr(t){const i=t.key,r=Date.now();this.kr.has(i)||this.kr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.kr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Pr=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)}}Nr(t){const i=t.key,r=Date.now();this.kr.has(i)||this.kr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.kr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.Gr=i,this.Or){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Or(o)}}Zr(t){return this.Hr[t]||t.toLowerCase()}}class Kt{constructor(t){l(this,"tr");l(this,"rn");l(this,"nn",{x:-1,y:-1});l(this,"an",{x:-1,y:-1});l(this,"hn",null);l(this,"cn");l(this,"ln");l(this,"un");l(this,"fn");l(this,"dn");l(this,"_n");l(this,"Ir",!1);l(this,"pn");l(this,"mn");l(this,"gn");l(this,"vn");l(this,"yn");this.tr=t}Ki(t){this.rn=t,this.Cn()}Vr(){if(this.Ir)return;const t=this.tr.canvas;this.cn=i=>{this.wn(i),this.$n(i)},this.ln=()=>{this.an={...this.nn},this.nn.x=-1,this.nn.y=-1,this.hn=null},this.un=i=>{this.wn(i),this.bn(i)},this.fn=i=>{this.wn(i),this.xn(i)},this.dn=i=>{this.wn(i),this.Mn(i)},this._n=i=>{this.wn(i),this.Fn(i)},t.addEventListener("mousemove",this.cn,{passive:!0}),t.addEventListener("mouseleave",this.ln,{passive:!0}),t.addEventListener("mousedown",this.un,{passive:!0}),t.addEventListener("mouseup",this.fn,{passive:!0}),t.addEventListener("click",this.dn,{passive:!0}),t.addEventListener("wheel",this._n,{passive:!1}),this.Ir=!0}Xr(){if(!this.Ir)return;const t=this.tr.canvas;t.removeEventListener("mousemove",this.cn),t.removeEventListener("mouseleave",this.ln),t.removeEventListener("mousedown",this.un),t.removeEventListener("mouseup",this.fn),t.removeEventListener("click",this.dn),t.removeEventListener("wheel",this._n),this.Ir=!1}Cn(){if(this.Ir)try{if(this.hn){const t=new MouseEvent("mousemove",{clientX:this.hn.x,clientY:this.hn.y,bubbles:!1,cancelable:!1});this.wn(t)}else this.nn.x!==-1&&this.nn.y!==-1&&(this.nn.x>=this.rn.cols||this.nn.y>=this.rn.rows)&&(this.nn.x=-1,this.nn.y=-1)}catch{this.nn.x=-1,this.nn.y=-1}}Rn(t){this.pn=t}jr(t){this.mn=t}Yr(t){this.gn=t}Sn(t){this.vn=t}An(t){this.yn=t}zn(){return{x:this.nn.x,y:this.nn.y}}$n(t){if(this.vn){const i={position:{...this.nn},previousPosition:{...this.an},originalEvent:t};this.vn(i)}}bn(t){if(this.mn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.mn(i)}}xn(t){if(this.gn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.gn(i)}}Mn(t){if(this.pn){const i={position:{...this.nn},previousPosition:{...this.an},button:t.button,originalEvent:t};this.pn(i)}}Fn(t){if(this.yn){const i={position:{...this.nn},previousPosition:{...this.an},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.yn(i)}}wn(t){const i=this.tr.canvas;this.an={...this.nn},this.hn={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.rn.offsetX,f=a-this.rn.offsetY,g=Math.floor(u/this.rn.cellWidth),d=Math.floor(f/this.rn.cellHeight);g>=0&&g<this.rn.cols&&d>=0&&d<this.rn.rows?(this.nn.x=g,this.nn.y=d):(this.nn.x=-1,this.nn.y=-1)}}const qt=c=>class extends c{rotate(t=0,i=0,r=0){this.xt.state.et(t),this.xt.state.st(i),this.xt.state.it(r)}rotateX(t){this.xt.state.et(t)}rotateY(t){this.xt.state.st(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.W()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Hs(t,i,r,n)}point(t,i){this.xt.Hs(t,i,1,1)}line(t,i,r,n){this.xt.Vs(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qs(t,i,r,n)}char(t){this.xt.state.rt(this.Ei.zi(t))}charColor(t,i,r){this.xt.state.nt(t,i,r)}cellColor(t,i,r){this.xt.state.ot(t,i,r)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qs(0,0,0,0)}ellipse(t,i,r,n){this.xt.Ks(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.Ns(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.Xs(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.Ys(t,i,r,n,o,h)}shader(t){this.xt.Bs(t)}setUniform(t,i){this.xt.Xt(t,i)}setUniforms(t){this.xt.Ds(t)}createFilterShader(t){return this.xt.oe(t)}createFramebuffer(t){return this.xt.js(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Is(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.Ws(h,i,r,n??h.width,o??h.height)}}async loadImage(t){if(typeof t!="string")return k.fromSource(this.xt,t,n=>this.Ei.Ti(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return k.fromSource(this.xt,r,n=>this.Ei.Ti(n))}};class it{Tn(t){const i=t.zt(0),r=t.zt(1),n=t.zt(2),o=t.zt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.zt(4),rotationPixels:o}}En(t,i){return t[i]+(t[i+1]<<8)}Ln(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class st{kn(t,i){return new Blob([t],{type:i})}Pn(t,i,r){try{const n=this.kn(t,r),o=URL.createObjectURL(n),h=document.createElement("a");h.href=o,h.download=i,h.style.display="none",h.rel="noopener",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(o)}catch(n){console.error("Failed to download file:",n)}}Gn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Bn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}Dn(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}In(){return"textmode-export-"+this.Gn()}}class Jt extends it{Wn(t,i,r){const n=t[r]===255,o=t[r+1]===255,h=t[r+2]===255,a=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:h,rotation:Math.round(360*(a+u/255)/255*100)/100}}On(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Hn(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let h=0;h<i.cols;h++){const a=4*n,u=this.En(t.characterPixels,a);let f=this.Ln(t.primaryColorPixels,a),g=this.Ln(t.secondaryColorPixels,a);const d=this.Wn(t.transformPixels,t.rotationPixels,a);if(d.isInverted){const y=f;f=g,g=y}const m=this.On(h,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:g,transform:d,position:m}),n++}return r}}class Zt{Vn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let h=0;h<o.startCount.length;h++)if(i>=o.startCount[h]&&i<=o.endCount[h]){if(o.idRangeOffset[h]===0)return i+o.idDelta[h]&65535;{const a=o.idRangeOffset[h]/2+(i-o.startCount[h])-(o.startCount.length-h);if(a>=0&&a<o.glyphIdArray.length){const u=o.glyphIdArray[a];if(u!==0)return u+o.idDelta[h]&65535}}}}else if(n.format===12){const o=n;for(let h=0;h<o.groups.length;h+=3){const a=o.groups[h],u=o.groups[h+1],f=o.groups[h+2];if(i>=a&&i<=u)return f+(i-a)}}return 0}Kn(t,i,r,n,o){const h=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*h,y1:n+-i.yMax*h,x2:r+i.xMax*h,y2:n+-i.yMin*h}),toSVG:()=>this.Nn(i,r,n,h)}}Nn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return"";let f="",g=0;for(let d=0;d<a.length;d++){const m=a[d];if(!(m<g)){if(m>=g){const y=i+o[g]*n,x=r-h[g]*n;f+=`M${y.toFixed(2)},${x.toFixed(2)}`;let p=g+1;for(;p<=m;)if(1&u[p]){const E=i+o[p]*n,v=r-h[p]*n;f+=`L${E.toFixed(2)},${v.toFixed(2)}`,p++}else{const E=i+o[p]*n,v=r-h[p]*n;let R=p+1>m?g:p+1;if(1&u[R]){const w=i+o[R]*n,L=r-h[R]*n;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${L.toFixed(2)}`,p=R+1}else{const w=(E+(i+o[R]*n))/2,L=(v+(r-h[R]*n))/2;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${L.toFixed(2)}`,p=R}}f+="Z"}g=m+1}}return f}Xn(t,i,r,n,o){const h=t.codePointAt(0)||0,a=this.Vn(i,h);let u=null;return i.glyf&&i.glyf[a]!==null?u=i.glyf[a]:(u=I.T.glyf.Js(i,a),i.glyf[a]=u),this.Kn(i,u,r,n,o)}jn(t,i,r,n,o,h,a,u){const f=r+(o-u*(a/i.head.unitsPerEm))/2,g=n+(h+.7*a)/2;return this.Xn(t,i,f,g,a).toSVG()||null}}class Qt{constructor(){l(this,"Yn");this.Yn=new Zt}qn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}Zn(){return"</g></svg>"}Jn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,h]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${h/255})"/>`}Qn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,h=n.cellY+i.cellHeight/2,a=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;a.push(`translate(${o} ${h})scale(${u} ${f})translate(${-o} ${-h})`)}return r.rotation&&a.push(`rotate(${r.rotation} ${o} ${h})`),` transform="${a.join(" ")}"`}eo(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:h,b:a,a:u}=t.secondaryColor,f=`rgba(${o},${h},${a},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Xn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const h=this.Yn.jn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!h)return"";const{r:a,g:u,b:f,a:g}=t.primaryColor,d=`rgba(${a},${u},${f},${g/255})`;return n.drawMode==="stroke"?`<path d="${h}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${h}" fill="${d}"/>`}so(t,i,r,n){const o=[],h=this.eo(t,i,n);h&&o.push(h);const a=this.Xn(t,i,r,n);if(a){const u=this.Qn(t,i);o.push(u?`<g${u}>${a}</g>`:a)}return o.join("")}io(t,i,r,n){const o=[this.qn(i),this.Jn(i,n),'<g id="ascii-cells">'];for(const h of t)o.push(this.so(h,i,r,n));return o.push(this.Zn()),o.join("")}ro(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class te extends st{no(t){return this.kn(t,"image/svg+xml;charset=utf-8")}oo(t,i){this.Pn(t,this.Dn(i)+".svg","image/svg+xml;charset=utf-8")}ao(t,i){this.oo(t,i||this.In())}}class ft{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new Jt,this.co=new Qt,this.lo=new te}uo(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.lo.In()}}fo(t,i={}){const r=this.ho.Hn(this.ho.Tn(t.pipeline),t.grid),n=this.co.io(r,t.grid,t.font,this.uo(i));return this.co.ro(n)}ao(t,i={}){this.lo.ao(this.fo(t,i),i.filename)}}class ee extends it{do(t,i,r,n=" "){var a;const o=[];let h=0;for(let u=0;u<i.rows;u++){const f=[];for(let g=0;g<i.cols;g++){const d=4*h,m=this.En(t.characterPixels,d),y=((a=r.characters[m])==null?void 0:a.character)||n;f.push(y),h++}o.push(f)}return o}}class ie{_o(t,i){const r=[];for(const o of t){let h=o.join("");i.preserveTrailingSpaces||(h=h.replace(/\s+$/,"")),r.push(h)}const n=i.lineEnding==="crlf"?`\r
|
|
12
12
|
`:`
|
|
13
|
-
`;return r.join(n)}}class se extends st{po(t,i){const r=this.mo(i);this.Pn(t,r,"text/plain;charset=utf-8")}mo(t){let i=this.Dn(t);return i===".txt"||i.length<=4?this.In():i}}class dt{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new ee,this.co=new ie,this.lo=new se}uo(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.lo.In()}}vo(t,i={}){const r=this.uo(i),n=this.ho.do(this.ho.Tn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.co._o(n,r)}po(t,i={}){this.lo.po(this.vo(t,i),i.filename)}}class re extends it{yo(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),h=o.getContext("2d"),a=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=a,o.height=u,r!=="transparent"&&(h.fillStyle=r,h.fillRect(0,0,a,u)),h.imageSmoothingEnabled=!1,h.drawImage(n,0,0,n.width,n.height,0,0,a,u),o}}class ne{Co(t,i){const r=this.wo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async $o(t,i){return new Promise((r,n)=>{const o=this.wo(i.format),h=a=>{a?r(a):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(h,o):t.toBlob(h,o,i.quality)})}wo(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 oe={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gt={png:".png",jpg:".jpg",webp:".webp"};class he extends st{bo(t,i,r){this.xo(t,this.Dn(i)+gt[r])}xo(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)}}Mo(t){return t in oe&&t in gt}}class ae{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new re,this.co=new ne,this.lo=new he}uo(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.lo.In()}}Fo(t){if(!this.lo.Mo(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 $o(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.co.$o(t.canvas,i);const r=this.ho.yo(t,i.scale,i.backgroundColor);return await this.co.$o(r,i)}async bo(t,i={}){const r=this.uo(i);this.Fo(r);const n=await this.$o(t,r);this.lo.bo(n,r.filename,r.format)}}const ce=c=>class extends c{Ro(){this.xt.Et(this.So)}toString(t={}){return this.Ro(),new dt().vo({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}saveStrings(t={}){this.Ro(),new dt().po({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}toSVG(t={}){return this.Ro(),new ft().fo({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}saveSVG(t={}){this.Ro(),new ft().ao({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}async saveCanvas(t={}){await new ae().bo(this.tr,t)}},le=c=>class extends c{async loadFont(t){return this.Ei.Yi(t).then(()=>{const i=this.Ei.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.Ao.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.zo.Cn()})}fontSize(t){if(!N.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Ei.fontSize===t)return;this.Ei.ji(t);const i=this.Ei.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.Ao.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.zo.Cn()}glyphColor(t){return this.Ei.zi(t)}glyphColors(t){return this.Ei.Ti(t)}},ue=c=>class extends c{get frameCount(){return this.To.frameCount}set frameCount(t){this.To.frameCount=t}frameRate(t){return t===void 0?this.To.currentFrameRate:this.To.frameRate(t,()=>this.Eo())}noLoop(){this.To.pause()}loop(){this.To.resume(()=>this.Eo())}redraw(t=1){if(N.v(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.Eo()}isLooping(){return this.To.isLooping}},fe=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.zo.Rn(t)}mousePressed(t){this.zo.jr(t)}mouseReleased(t){this.zo.Yr(t)}mouseMoved(t){this.zo.Sn(t)}mouseScrolled(t){this.zo.An(t)}get mouse(){return this.zo.zn()}},de=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.Lo.jr(t)}keyReleased(t){this.Lo.Yr(t)}isKeyPressed(t){return this.Lo.qr(t)}get lastKeyPressed(){return this.Lo.Jr()}get lastKeyReleased(){return this.Lo.Qr()}get pressedKeys(){return this.Lo.tn()}get modifierState(){return this.Lo.en()}};class ge{constructor(){l(this,"xt");l(this,"Ei");l(this,"tr");l(this,"rn");l(this,"To");l(this,"zo");l(this,"Lo");l(this,"So");l(this,"Ao");l(this,"ko");l(this,"Po");l(this,"Go")}Eo(){}}class pt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ge,qt,ce,le,ue,fe,de){constructor(i={}){super();l(this,"Bo",!1);l(this,"Do",()=>{});l(this,"Io",()=>{});l(this,"Wo",()=>{});l(this,"Oo");l(this,"ar",!1);l(this,"Ho");this.ar=i.overlay??!1,this.tr=new ut(i),this.xt=new Bt(this.tr.mr()),this.Ei=new ct(this.xt,i.fontSize??16),this.To=new Vt(i.frameRate??60),this.zo=new Kt(this.tr),this.Lo=new jt,this.So=this.xt.Tt(),this.ko=this.xt.re(),this.Vo(i)}async Vo(i){await this.Ei.Ki(i.fontSource);const r=this.Ei.maxGlyphDimensions;this.rn=new lt(this.tr.canvas,r.width,r.height),this.zo.Ki(this.rn),this.Ao=this.xt.js(this.rn.cols,this.rn.rows,5),this.Po=this.xt.js(this.rn.width,this.rn.height,1),this.ar&&(this.Ho=k.fromSource(this.xt,this.tr.targetCanvas,n=>this.Ei.Ti(n))),this.Go=this.xt.ae(ot,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Ko(),this.Do(),this.To.start(()=>this.Eo())}Ko(){this.Oo=()=>{this.ar&&this.resizeCanvas(this.tr.width,this.tr.height),this.Wo()},window.addEventListener("resize",this.Oo),this.zo.Vr(),this.Lo.Vr(),window.addEventListener("blur",()=>{this.Lo.sn()})}Eo(){if(this.To.measureFrameRate(),this.To.incrementFrame(),this.Bo)return;if(this.ar){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.Ho.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.tr.targetCanvas),r.bindTexture(r.TEXTURE_2D,null),this.Ao.begin(),this.xt.Ws(this.Ho,0,0,this.rn.cols,this.rn.rows),this.xt.Gs(this.So),this.Io(),this.xt.Et(this.So),this.Ao.end()}else this.Ao.begin(),this.xt.Gs(this.So),this.Io(),this.xt.Et(this.So),this.Ao.end();this.Po.begin(),this.xt.Gs(this.ko),this.ko.Nt({U0:this.Ei.fontFramebuffer,U1:[this.Ei.textureColumns,this.Ei.textureRows],U2:this.Ao.textures[0],U3:this.Ao.textures[1],U4:this.Ao.textures[2],U5:this.Ao.textures[4],U6:this.Ao.textures[3],U7:[this.rn.cols,this.rn.rows],U8:[this.Po.width,this.Po.height],U9:this.Po.width/this.Po.height}),this.xt.Os(0,0,this.tr.width,this.tr.height),this.Po.end();const i=this.xt.state.canvasBackgroundColor;this.xt.He(i[0],i[1],i[2],i[3]),this.xt.Gs(this.Go),this.Go.Nt({Ua:this.Po.textures[0],Ub:[this.Po.width,this.Po.height],Uc:[this.rn.offsetX,this.rn.offsetY],Ud:[this.rn.width,this.rn.height]}),this.xt.Os(this.rn.offsetX,this.rn.offsetY,this.rn.width,this.rn.height)}setup(i){this.Do=i}draw(i){this.Io=i}windowResized(i){this.Wo=i}resizeCanvas(i,r){this.tr.pr(i,r),this.rn.ir(),this.Ao.resize(this.rn.cols,this.rn.rows),this.Po.resize(this.rn.width,this.rn.height),this.xt.Zs(),this.zo.Cn(),this.Eo()}destroy(){this.Bo||(this.To.stop(),window.removeEventListener("resize",this.Oo),this.zo.Xr(),this.Lo.Xr(),this.Ei.Pt(),this.xt.Pt(),this.Po.Pt(),this.Go.Pt(),this.Ho&&this.Ho.Pt(),this.Bo=!0)}get grid(){return this.rn}get font(){return this.Ei}get width(){return this.tr.width}get height(){return this.tr.height}get canvas(){return this.tr.canvas}get isDisposed(){return this.Bo}get overlay(){return this.Ho}}class J{constructor(){}static create(t={}){return new pt(t)}static setErrorLevel(t){N.C(t)}static get version(){return"0.2.1-beta.
|
|
13
|
+
`;return r.join(n)}}class se extends st{po(t,i){const r=this.mo(i);this.Pn(t,r,"text/plain;charset=utf-8")}mo(t){let i=this.Dn(t);return i===".txt"||i.length<=4?this.In():i}}class dt{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new ee,this.co=new ie,this.lo=new se}uo(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.lo.In()}}vo(t,i={}){const r=this.uo(i),n=this.ho.do(this.ho.Tn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.co._o(n,r)}po(t,i={}){this.lo.po(this.vo(t,i),i.filename)}}class re extends it{yo(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),h=o.getContext("2d"),a=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=a,o.height=u,r!=="transparent"&&(h.fillStyle=r,h.fillRect(0,0,a,u)),h.imageSmoothingEnabled=!1,h.drawImage(n,0,0,n.width,n.height,0,0,a,u),o}}class ne{Co(t,i){const r=this.wo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async $o(t,i){return new Promise((r,n)=>{const o=this.wo(i.format),h=a=>{a?r(a):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(h,o):t.toBlob(h,o,i.quality)})}wo(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 oe={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gt={png:".png",jpg:".jpg",webp:".webp"};class he extends st{bo(t,i,r){this.xo(t,this.Dn(i)+gt[r])}xo(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)}}Mo(t){return t in oe&&t in gt}}class ae{constructor(){l(this,"ho");l(this,"co");l(this,"lo");this.ho=new re,this.co=new ne,this.lo=new he}uo(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.lo.In()}}Fo(t){if(!this.lo.Mo(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 $o(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.co.$o(t.canvas,i);const r=this.ho.yo(t,i.scale,i.backgroundColor);return await this.co.$o(r,i)}async bo(t,i={}){const r=this.uo(i);this.Fo(r);const n=await this.$o(t,r);this.lo.bo(n,r.filename,r.format)}}const ce=c=>class extends c{Ro(){this.xt.Et(this.So)}toString(t={}){return this.Ro(),new dt().vo({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}saveStrings(t={}){this.Ro(),new dt().po({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}toSVG(t={}){return this.Ro(),new ft().fo({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}saveSVG(t={}){this.Ro(),new ft().ao({pipeline:this.Ao,grid:this.rn,font:this.Ei},t)}async saveCanvas(t={}){await new ae().bo(this.tr,t)}},le=c=>class extends c{async loadFont(t){return this.Ei.Yi(t).then(()=>{const i=this.Ei.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.Ao.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.zo.Cn()})}fontSize(t){if(!N.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Ei.fontSize===t)return;this.Ei.ji(t);const i=this.Ei.maxGlyphDimensions;this.rn.rr(i.width,i.height),this.Ao.resize(this.rn.cols,this.rn.rows),this.xt.Zs(),this.zo.Cn()}glyphColor(t){return this.Ei.zi(t)}glyphColors(t){return this.Ei.Ti(t)}},ue=c=>class extends c{get frameCount(){return this.To.frameCount}set frameCount(t){this.To.frameCount=t}frameRate(t){return t===void 0?this.To.currentFrameRate:this.To.frameRate(t,()=>this.Eo())}noLoop(){this.To.pause()}loop(){this.To.resume(()=>this.Eo())}redraw(t=1){if(N.v(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.Eo()}isLooping(){return this.To.isLooping}},fe=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.zo.Rn(t)}mousePressed(t){this.zo.jr(t)}mouseReleased(t){this.zo.Yr(t)}mouseMoved(t){this.zo.Sn(t)}mouseScrolled(t){this.zo.An(t)}get mouse(){return this.zo.zn()}},de=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.Lo.jr(t)}keyReleased(t){this.Lo.Yr(t)}isKeyPressed(t){return this.Lo.qr(t)}get lastKeyPressed(){return this.Lo.Jr()}get lastKeyReleased(){return this.Lo.Qr()}get pressedKeys(){return this.Lo.tn()}get modifierState(){return this.Lo.en()}};class ge{constructor(){l(this,"xt");l(this,"Ei");l(this,"tr");l(this,"rn");l(this,"To");l(this,"zo");l(this,"Lo");l(this,"So");l(this,"Ao");l(this,"ko");l(this,"Po");l(this,"Go")}Eo(){}}class pt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ge,qt,ce,le,ue,fe,de){constructor(i={}){super();l(this,"Bo",!1);l(this,"Do",()=>{});l(this,"Io",()=>{});l(this,"Wo",()=>{});l(this,"Oo");l(this,"hr");l(this,"ar",!1);l(this,"Ho");this.ar=i.overlay??!1,this.tr=new ut(i),this.xt=new Bt(this.tr.mr()),this.Ei=new ct(this.xt,i.fontSize??16),this.To=new Vt(i.frameRate??60),this.zo=new Kt(this.tr),this.Lo=new jt,this.So=this.xt.Tt(),this.ko=this.xt.re(),this.Vo(i)}async Vo(i){await this.Ei.Ki(i.fontSource);const r=this.Ei.maxGlyphDimensions;this.rn=new lt(this.tr.canvas,r.width,r.height),this.zo.Ki(this.rn),this.Ao=this.xt.js(this.rn.cols,this.rn.rows,5),this.Po=this.xt.js(this.rn.width,this.rn.height,1),this.ar&&(this.Ho=k.fromSource(this.xt,this.tr.targetCanvas,n=>this.Ei.Ti(n))),this.Go=this.xt.ae(ot,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Ko(),this.Do(),this.To.start(()=>this.Eo())}Ko(){this.Oo=()=>{this.ar&&this.resizeCanvas(this.tr.width,this.tr.height),this.Wo()},window.addEventListener("resize",this.Oo),this.zo.Vr(),this.Lo.Vr(),window.addEventListener("blur",()=>{this.Lo.sn()}),window.ResizeObserver&&this.ar&&(this.hr=new ResizeObserver(()=>{this.resizeCanvas(this.tr.targetCanvas.width,this.tr.targetCanvas.height)}),this.hr.observe(this.tr.targetCanvas))}Eo(){if(this.To.measureFrameRate(),this.To.incrementFrame(),this.Bo)return;if(this.ar){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.Ho.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.tr.targetCanvas),r.bindTexture(r.TEXTURE_2D,null),this.Ao.begin(),this.xt.Ws(this.Ho,0,0,this.rn.cols,this.rn.rows),this.xt.Gs(this.So),this.Io(),this.xt.Et(this.So),this.Ao.end()}else this.Ao.begin(),this.xt.Gs(this.So),this.Io(),this.xt.Et(this.So),this.Ao.end();this.Po.begin(),this.xt.Gs(this.ko),this.ko.Nt({U0:this.Ei.fontFramebuffer,U1:[this.Ei.textureColumns,this.Ei.textureRows],U2:this.Ao.textures[0],U3:this.Ao.textures[1],U4:this.Ao.textures[2],U5:this.Ao.textures[4],U6:this.Ao.textures[3],U7:[this.rn.cols,this.rn.rows],U8:[this.Po.width,this.Po.height],U9:this.Po.width/this.Po.height}),this.xt.Os(0,0,this.tr.width,this.tr.height),this.Po.end();const i=this.xt.state.canvasBackgroundColor;this.xt.He(i[0],i[1],i[2],i[3]),this.xt.Gs(this.Go),this.Go.Nt({Ua:this.Po.textures[0],Ub:[this.Po.width,this.Po.height],Uc:[this.rn.offsetX,this.rn.offsetY],Ud:[this.rn.width,this.rn.height]}),this.xt.Os(this.rn.offsetX,this.rn.offsetY,this.rn.width,this.rn.height)}setup(i){this.Do=i}draw(i){this.Io=i}windowResized(i){this.Wo=i}resizeCanvas(i,r){this.tr.pr(i,r),this.rn.ir(),this.Ao.resize(this.rn.cols,this.rn.rows),this.Po.resize(this.rn.width,this.rn.height),this.xt.Zs(),this.zo.Cn(),this.Eo()}destroy(){this.Bo||(this.To.stop(),window.removeEventListener("resize",this.Oo),this.zo.Xr(),this.Lo.Xr(),this.Ei.Pt(),this.xt.Pt(),this.Po.Pt(),this.Go.Pt(),this.Ho&&this.Ho.Pt(),this.Bo=!0)}get grid(){return this.rn}get font(){return this.Ei}get width(){return this.tr.width}get height(){return this.tr.height}get canvas(){return this.tr.canvas}get isDisposed(){return this.Bo}get overlay(){return this.Ho}}class J{constructor(){}static create(t={}){return new pt(t)}static setErrorLevel(t){N.C(t)}static get version(){return"0.2.1-beta.6"}}const pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),me=J.create,ve=J.setErrorLevel,xe=J.version;C.TextmodeCanvas=ut,C.TextmodeErrorLevel=M,C.TextmodeFont=ct,C.TextmodeFramebuffer=V,C.TextmodeGrid=lt,C.TextmodeImage=k,C.Textmodifier=pt,C.create=me,C.export=pe,C.setErrorLevel=ve,C.textmode=J,C.version=xe,Object.defineProperty(C,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={});
|
package/package.json
CHANGED