UNPKG

textmode.js

Version:

textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.

1,231 lines (1,229 loc) 149 kB
var Kt = Object.defineProperty; var Jt = (n, t, e) => t in n ? Kt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; var a = (n, t, e) => Jt(n, typeof t != "symbol" ? t + "" : t, e); class U extends Error { constructor(t, e = {}) { super(U.i(t, e)), this.name = "TextmodeError"; } static i(t, e) { return `${t}${e && Object.keys(e).length > 0 ? ` 📋 Context:` + Object.entries(e).map(([i, r]) => ` - ${i}: ${U.o(r)}`).join("") : ""} ${"↓".repeat(24)} `; } 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((e) => U.o(e)).join(", ")}]` : `[${t.slice(0, 3).map((e) => U.o(e)).join(", ")}, ... +${t.length - 3} more]`; if (typeof t == "object") { const e = Object.keys(t); return e.length === 0 ? "{}" : e.length <= 3 ? `{ ${e.map((i) => `${i}: ${U.o(t[i])}`).join(", ")} }` : `{ ${e.slice(0, 2).map((i) => `${i}: ${U.o(t[i])}`).join(", ")}, ... +${e.length - 2} more }`; } return t + ""; } } var $t = ((n) => (n[n.SILENT = 0] = "SILENT", n[n.WARNING = 1] = "WARNING", n[n.ERROR = 2] = "ERROR", n[n.THROW = 3] = "THROW", n))($t || {}); const _ = class _ { constructor() { a(this, "l", { globalLevel: 3 }); } static u() { return _.h || (_.h = new _()), _.h; } v(t, e) { const i = "%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.", r = "color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"; switch (this.l.globalLevel) { case 0: return !1; case 1: return console.group(i, r), console.warn(U.i(t, e)), console.groupEnd(), !1; case 2: return console.group(i, r), console.error(U.i(t, e)), console.groupEnd(), !1; default: throw new U(t, e); } } m(t, e, i) { return !!t || (this.v(e, i), !1); } _(t) { this.l.globalLevel = t; } }; a(_, "h", null); let ut = _; const vt = ut.u(); class W { constructor(t, e, i) { a(this, "A"); a(this, "C"); a(this, "M", /* @__PURE__ */ new Map()); a(this, "F", /* @__PURE__ */ new Map()); a(this, "$", 0); a(this, "P", /* @__PURE__ */ new Map()); a(this, "U"); this.A = t, this.U = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS) ?? 16, this.C = this.R(e, i), this.S(); } S() { const t = this.A.getProgramParameter(this.C, this.A.ACTIVE_UNIFORMS); for (let e = 0; e < t; e++) { const i = this.A.getActiveUniform(this.C, e); if (i) { const r = i.name.replace(/\[0\]$/, ""), s = this.A.getUniformLocation(this.C, r); s && (this.M.set(r, s), this.F.set(r, { type: i.type, size: i.size })); } } } R(t, e) { const i = this.k(this.A.VERTEX_SHADER, t), r = this.k(this.A.FRAGMENT_SHADER, e), s = this.A.createProgram(); if (this.A.attachShader(s, i), this.A.attachShader(s, r), this.A.linkProgram(s), !this.A.getProgramParameter(s, this.A.LINK_STATUS)) { const h = this.A.getProgramInfoLog(s); throw Error("Shader program link error: " + h); } return this.A.deleteShader(i), this.A.deleteShader(r), s; } k(t, e) { const i = this.A.createShader(t); if (this.A.shaderSource(i, e), this.A.compileShader(i), !this.A.getShaderParameter(i, this.A.COMPILE_STATUS)) { const r = this.A.getShaderInfoLog(i); throw this.A.deleteShader(i), Error("Shader compilation error: " + r); } return i; } D() { this.A.useProgram(this.C), this.L(); } L() { this.$ = 0, this.P.clear(); } O(t) { for (const e in t) this.I(e, t[e]); } I(t, e) { var c, l; const i = this.M.get(t); if (!i) return; const r = this.F.get(t); if (!r) return; const { type: s, size: h } = r, o = this.A; if (e instanceof WebGLTexture) { const u = this.H(t); return o.uniform1i(i, u), o.activeTexture(o.TEXTURE0 + u), void o.bindTexture(o.TEXTURE_2D, e); } if (e instanceof X) { const u = this.H(t); return o.uniform1i(i, u), o.activeTexture(o.TEXTURE0 + u), void o.bindTexture(o.TEXTURE_2D, e.textures[0]); } if (typeof e == "number") return void (s === o.INT || s === o.BOOL ? o.uniform1i(i, e) : o.uniform1f(i, e)); if (typeof e == "boolean") return void o.uniform1i(i, e ? 1 : 0); if (Array.isArray(e[0])) { const u = e.flat(), f = { [o.FLOAT_VEC2]: () => o.uniform2fv(i, u), [o.FLOAT_VEC3]: () => o.uniform3fv(i, u), [o.FLOAT_VEC4]: () => o.uniform4fv(i, u) }; (c = f[s]) == null || c.call(f); } else { const u = e, f = { [o.FLOAT]: () => h > 1 ? o.uniform1fv(i, u) : o.uniform1f(i, u[0]), [o.FLOAT_VEC2]: () => o.uniform2fv(i, u), [o.FLOAT_VEC3]: () => o.uniform3fv(i, u), [o.FLOAT_VEC4]: () => o.uniform4fv(i, u), [o.INT]: () => h > 1 ? o.uniform1iv(i, u) : o.uniform1i(i, u[0]), [o.INT_VEC2]: () => o.uniform2iv(i, u), [o.INT_VEC3]: () => o.uniform3iv(i, u), [o.INT_VEC4]: () => o.uniform4iv(i, u), [o.BOOL]: () => o.uniform1iv(i, u), [o.FLOAT_MAT2]: () => o.uniformMatrix2fv(i, !1, u), [o.FLOAT_MAT3]: () => o.uniformMatrix3fv(i, !1, u), [o.FLOAT_MAT4]: () => o.uniformMatrix4fv(i, !1, u) }; (l = f[s]) == null || l.call(f); } } H(t) { const e = this.P.get(t); if (e !== void 0) return e; if (this.$ >= this.U) throw Error(`[textmode.js] Shader attempted to bind more than ${this.U} texture samplers. Uniform "${t}" cannot be assigned.`); const i = this.$++; return this.P.set(t, i), i; } get G() { return this.C; } dispose() { this.A.deleteProgram(this.C); } } function mt(n, t, e, i) { return 180 * Math.atan2(i - t, e - n) / Math.PI; } function k(n, t, e, i) { return Math.hypot(e - n, i - t); } function Z(n, t, e) { return Math.min(Math.max(n, t), e); } function xt(n) { return (n % 360 + 360) % 360 / 360; } function Tt(n, t, e) { n.bindTexture(n.TEXTURE_2D, t), n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL, 1), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, n.RGBA, n.UNSIGNED_BYTE, e), n.bindTexture(n.TEXTURE_2D, null); } function pt(n, t, e, i, r) { n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, t), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, i), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, r); } function ft(n, t, e, i, r, s = 0, h = WebGL2RenderingContext.FLOAT, o = !1) { n.enableVertexAttribArray(t), n.vertexAttribPointer(t, e, h, o, i, r), n.vertexAttribDivisor(t, s); } function Rt(n, t, e, i, r) { n.bindBuffer(t, e), n.bufferData(t, i, r), n.bindBuffer(t, null); } const rt = `#version 300 es in vec2 A0;in vec2 A1;in vec2 A2;in vec2 A3;in vec3 A4;in vec4 A5;in vec4 A6;in vec4 A7;in vec3 A8;in vec3 A9;in vec4 Aa;in vec4 Ab;in vec3 Ac;uniform vec2 Ur;uniform float Us;uniform float Ut;out vec2 v_uv;out vec3 v_glyphIndex;out vec4 v_glyphColor;out vec4 v_cellColor;out vec4 v_glyphFlags;out vec3 v_worldPosition;out vec3 v_normal;out float v_geometryType;const float A=6.28318530718f;const int B=2;const int C=3;const int D=4;vec2 E(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float M=L*K;float N=F*F;float O=N*F;return M*G+3.0f*L*F*H+3.0f*K*N*I+O*J;}vec2 P(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float N=F*F;return-3.0f*L*G+3.0f*(L-2.0f*K*F)*H+3.0f*(2.0f*K*F-N)*I+3.0f*N*J;}vec3 Q(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x,R.y*T-R.z*U,R.y*U+R.z*T);}vec3 V(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T+R.z*U,R.y,-R.x*U+R.z*T);}vec3 W(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T-R.y*U,R.x*U+R.y*T,R.z);}vec3 X(vec3 R,vec3 Y){vec3 Z=R;if(Y.z!=0.0f){Z=W(Z,Y.z);}if(Y.y!=0.0f){Z=V(Z,Y.y);}if(Y.x!=0.0f){Z=Q(Z,Y.x);}return Z;}void main(){v_uv=A1;v_glyphIndex=A4;v_glyphColor=A5;v_cellColor=A6;v_glyphFlags=A7;vec4 a=Aa;vec4 b=Ab;vec2 c=A3;vec2 d=A2;float e=Ac.x;float f=Ac.y;int g=int(Ac.z);vec2 h=d;vec2 i=h+c*0.5f;float j=f+e*0.5f;vec3 k=vec3(i,j);vec3 l;if(g==D){float F=clamp(A0.x,0.0f,1.0f);vec2 G=b.xy;vec2 H=a.xy;vec2 I=a.zw;vec2 J=b.zw;vec2 m=E(F,G,H,I,J);vec2 n=P(F,G,H,I,J);float o=length(n);vec2 p=o>0.0f?n/o:vec2(1.0f,0.0f);vec2 q=vec2(-p.y,p.x);vec2 r=m;vec2 s=r+q*A0.y*c.y;l=vec3(s,f);}else if(g==C){float t=mod(a.x,A);if(t<0.0f){t+=A;}float u=mod(a.y,A);if(u<0.0f){u+=A;}float v=t-u;if(v<=0.0f){v+=A;}float S=t-A0.x*v;vec2 w=vec2(cos(S),sin(S))*A0.y;vec2 s=w*c+h;l=vec3(s,f);}else if(g==B){vec2 s=A0.xy*c+h;l=vec3(s,f);}vec3 x=X(l,A9);vec3 y=x+A8;vec3 z=vec3(0.0f,0.0f,1.0f);v_worldPosition=y;v_normal=z;v_geometryType=float(g);vec2 AA=(y.xy/Ur)*2.0f;AA.y=-AA.y;float AB=y.z/Ur.y;float AC=clamp(-AB*Us,-0.99f,0.99f);if(Ut>0.5f){gl_Position=vec4(AA,AC,1.0f);}else{float AD=0.5f;float AE=1.0f/(1.0f-AB*AD);AA*=AE;gl_Position=vec4(AA,AC,1.0f);}}`, I = class I { constructor(t, e, i = e, r = 1, s = {}, h) { a(this, "N"); a(this, "X"); a(this, "l"); a(this, "A"); a(this, "Y"); a(this, "j", []); a(this, "K", null); a(this, "W"); a(this, "Z"); a(this, "q", null); a(this, "V", /* @__PURE__ */ new Map()); this.N = e, this.X = i, this.A = t, this.W = Z(r, 1, 8), this.Z = h, this.l = { filter: "nearest", wrap: "clamp", format: "rgba", type: "unsigned_byte", depth: !0, ...s }, I.J || (I.J = new W(t, rt, `#version 300 es precision highp float;in vec2 v_uv;uniform sampler2D U5;uniform sampler2D U6;uniform sampler2D U7;uniform sampler2D U8;uniform vec2 U9;uniform bool Ua;uniform bool Ub;uniform bool Uc;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 A;void main(){vec2 B=vec2(v_uv.x,1.-v_uv.y);vec2 C=B*U9;vec2 D=(floor(C)+0.5f)/U9;vec4 E=texture(U5,D);vec4 F=Ua?texture(U6,D):vec4(0.);if(Ua&&F.a==0.){discard;}vec4 G=Ub?texture(U7,D):vec4(0.);vec4 H=Uc?texture(U8,D):vec4(0.);o_character=E;o_primaryColor=F;o_secondaryColor=G;A=H;}`)); const o = t.getParameter(t.MAX_DRAW_BUFFERS), c = t.getParameter(t.MAX_COLOR_ATTACHMENTS); this.W = Math.min(this.W, o, c), this.Y = t.createFramebuffer(), this.tt(), this.st(), this.l.depth && this.it(); } tt() { const t = this.A, e = this.l.filter === "linear" ? t.LINEAR : t.NEAREST, i = this.l.wrap === "repeat" ? t.REPEAT : t.CLAMP_TO_EDGE, r = this.l.type === "float" ? t.FLOAT : t.UNSIGNED_BYTE, s = r === t.FLOAT ? t.RGBA32F : t.RGBA8, h = t.RGBA; for (let o = 0; o < this.W; o++) { const c = t.createTexture(); t.bindTexture(t.TEXTURE_2D, c), pt(t, e, e, i, i), t.texImage2D(t.TEXTURE_2D, 0, s, this.N, this.X, 0, h, r, null), this.j.push(c); } t.bindTexture(t.TEXTURE_2D, null); } st() { const t = this.A; if (t.bindFramebuffer(t.FRAMEBUFFER, this.Y), this.W === 1) t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, this.j[0], 0); else { const e = []; for (let i = 0; i < this.W; i++) { const r = t.COLOR_ATTACHMENT0 + i; t.framebufferTexture2D(t.FRAMEBUFFER, r, t.TEXTURE_2D, this.j[i], 0), e.push(r); } t.drawBuffers(e); } t.bindFramebuffer(t.FRAMEBUFFER, null); } it() { const t = this.A; this.K = t.createRenderbuffer(), t.bindRenderbuffer(t.RENDERBUFFER, this.K), t.renderbufferStorage(t.RENDERBUFFER, t.DEPTH_COMPONENT24, this.N, this.X), t.bindFramebuffer(t.FRAMEBUFFER, this.Y), t.framebufferRenderbuffer(t.FRAMEBUFFER, t.DEPTH_ATTACHMENT, t.RENDERBUFFER, this.K), t.bindFramebuffer(t.FRAMEBUFFER, null), t.bindRenderbuffer(t.RENDERBUFFER, null); } et(t) { Tt(this.A, this.j[0], t); } resize(t, e) { this.N = t, this.X = e, this.V.clear(); const i = this.A, r = this.l.type === "float" ? i.FLOAT : i.UNSIGNED_BYTE, s = r === i.FLOAT ? i.RGBA32F : i.RGBA8, h = i.RGBA; for (const o of this.j) i.bindTexture(i.TEXTURE_2D, o), i.texImage2D(i.TEXTURE_2D, 0, s, this.N, this.X, 0, h, r, null); i.bindTexture(i.TEXTURE_2D, null), this.K && (i.bindRenderbuffer(i.RENDERBUFFER, this.K), i.renderbufferStorage(i.RENDERBUFFER, i.DEPTH_COMPONENT24, this.N, this.X), i.bindRenderbuffer(i.RENDERBUFFER, null)); } readPixels(t) { const e = this.V.get(t); if (e) return e; const i = this.A, r = this.N, s = this.X, h = new Uint8Array(r * s * 4), o = i.getParameter(i.READ_FRAMEBUFFER_BINDING); i.bindFramebuffer(i.READ_FRAMEBUFFER, this.Y), i.readBuffer(i.COLOR_ATTACHMENT0 + t), i.readPixels(0, 0, r, s, i.RGBA, i.UNSIGNED_BYTE, h), i.bindFramebuffer(i.READ_FRAMEBUFFER, o); const c = 4 * r, l = new Uint8Array(h.length); for (let u = 0; u < s; u++) { const f = (s - 1 - u) * c, d = u * c; l.set(h.subarray(f, f + c), d); } return this.V.set(t, l), l; } begin() { const t = this.A; this.V.clear(), this.Z.rt(), this.Z.nt(this.Y, this.N, this.X, this.W), this.l.depth && t.clear(t.DEPTH_BUFFER_BIT), this.Z.state.ot(); } end() { this.Z.state.ht(), this.Z.ct(), this.Z.lt(); } ut() { return this.q || this.ft(), this.q; } ft() { if (!this.Z) return; const t = this.W > 1, e = this.W > 2, i = this.W > 3, r = { U5: this.j[0], U6: t ? this.j[1] : this.j[0], U7: e ? this.j[2] : this.j[0], U8: i ? this.j[3] : this.j[0], U9: [this.N, this.X], Ua: t, Ub: e, Uc: i }, s = I.J; this.q = this.Z.vt.dt(s, r, !0); } gt() { const t = this.A; t.deleteFramebuffer(this.Y), this.j.forEach((e) => { t.deleteTexture(e); }), this.K && t.deleteRenderbuffer(this.K); } get width() { return this.N; } get height() { return this.X; } get textures() { return this.j; } get attachmentCount() { return this.W; } }; a(I, "J", null); let X = I; const Ft = /* @__PURE__ */ new WeakMap(); function ht(n, t) { Ft.set(n, t); } function Ct(n) { return Ft.get(n); } function tt(n, t, e, i, r = 255) { n[0] = t / 255, n[1] = (e ?? t) / 255, n[2] = (i ?? t) / 255, n[3] = r / 255; } class st { constructor() { a(this, "_t", 1); a(this, "yt", 0); a(this, "At", 0); a(this, "wt", 0); a(this, "bt", 0); a(this, "Ct", 0); a(this, "xt", 0); a(this, "Mt", [0, 0, 0]); a(this, "Ft", [1, 1, 1, 1]); a(this, "$t", [0, 0, 0, 1]); a(this, "Pt", !1); a(this, "Tt", !1); a(this, "Et", !1); a(this, "Rt", 0); a(this, "St", [0, 0, 0, 1]); a(this, "zt", !1); a(this, "kt", []); a(this, "Dt", []); } static Lt() { return { Ot: 1, Bt: 0, It: 0, Ht: 0, bt: 0, Ct: 0, xt: 0, Rt: 0, Gt: !1, Qt: !1, Et: !1, zt: !1, Nt: [0, 0, 0], Xt: [1, 1, 1, 1], Yt: [0, 0, 0, 1] }; } jt(t) { t.Ot = this._t, t.Bt = this.yt, t.It = this.At, t.Ht = this.wt, t.bt = this.bt, t.Ct = this.Ct, t.xt = this.xt, t.Gt = this.Pt, t.Qt = this.Tt, t.Et = this.Et, t.Rt = this.Rt, t.zt = this.zt, t.Nt[0] = this.Mt[0], t.Nt[1] = this.Mt[1], t.Nt[2] = this.Mt[2], t.Xt[0] = this.Ft[0], t.Xt[1] = this.Ft[1], t.Xt[2] = this.Ft[2], t.Xt[3] = this.Ft[3], t.Yt[0] = this.$t[0], t.Yt[1] = this.$t[1], t.Yt[2] = this.$t[2], t.Yt[3] = this.$t[3]; } Kt(t) { this._t = t.Ot, this.yt = t.Bt, this.At = t.It, this.wt = t.Ht, this.bt = t.bt, this.Ct = t.Ct, this.xt = t.xt, this.Pt = t.Gt, this.Tt = t.Qt, this.Et = t.Et, this.Rt = t.Rt, this.zt = t.zt, this.Mt[0] = t.Nt[0], this.Mt[1] = t.Nt[1], this.Mt[2] = t.Nt[2], this.Ft[0] = t.Xt[0], this.Ft[1] = t.Xt[1], this.Ft[2] = t.Xt[2], this.Ft[3] = t.Xt[3], this.$t[0] = t.Yt[0], this.$t[1] = t.Yt[1], this.$t[2] = t.Yt[2], this.$t[3] = t.Yt[3]; } ot() { let t = this.Dt.pop(); t || (t = st.Lt()), this.jt(t), this.kt.push(t); } ht() { const t = this.kt.pop(); t ? (this.Kt(t), this.Dt.push(t)) : console.warn("pop() called without matching push()"); } Wt(t) { this.jt(t); } Zt(t) { this._t = Math.abs(t); } qt() { this.yt = 0, this.At = 0, this.wt = 0, this.bt = 0, this.Ct = 0, this.xt = 0, this.zt = !1; } Vt(t) { t !== 0 && (this.bt += t * Math.PI / 180); } Jt(t) { t !== 0 && (this.Ct += t * Math.PI / 180); } ts(t) { t !== 0 && (this.xt += t * Math.PI / 180); } ss(t = 0, e = 0, i = 0) { t === 0 && e === 0 && i === 0 || (this.yt += t, this.At += e, this.wt += i); } es(t) { this.ss(t, 0, 0); } rs(t) { this.ss(0, t, 0); } ns(t) { this.ss(0, 0, t); } hs(t) { this.Mt[0] = t[0], this.Mt[1] = t[1], this.Mt[2] = t[2]; } cs(t, e, i, r = 255) { tt(this.Ft, t, e, i, r); } ls(t, e, i, r = 255) { tt(this.$t, t, e, i, r); } us(t) { this.Pt = t; } fs(t) { this.Tt = t; } ds(t) { this.Et = t; } vs(t) { this.Rt = xt(t); } ps(t, e, i, r) { tt(this.St, t, e, i, r); } gs(t) { this.zt = t; } get canvasBackgroundColor() { return this.St; } get useOrtho() { return this.zt; } get rotationX() { return this.bt; } get rotationY() { return this.Ct; } get rotationZ() { return this.xt; } } const dt = new Float32Array([-0.5, -0.5, 0, 0, 0.5, -0.5, 1, 0, -0.5, 0.5, 0, 1, -0.5, 0.5, 0, 1, 0.5, -0.5, 1, 0, 0.5, 0.5, 1, 1]), Y = { _s: 16, As: WebGL2RenderingContext.TRIANGLES, ws: { bs: { size: 2, offset: 0 }, Cs: { size: 2, offset: 8 } } }; class te { constructor(t) { a(this, "A"); a(this, "Ms"); a(this, "Fs"); this.A = t, this.Ms = t.createBuffer(), this.Fs = new Float32Array(dt.length); } $s(t, e, i, r) { const s = this.A, h = Ct(this.A), o = h[2], c = h[3], l = t / o * 2 - 1, u = (t + i) / o * 2 - 1, f = 1 - (e + r) / c * 2, d = 1 - e / c * 2, g = dt, p = this.Fs; for (let v = 0; v < g.length; v += 4) { const A = g[v], m = g[v + 1], w = g[v + 2], y = g[v + 3], x = l + (A + 0.5) * (u - l), E = f + (m + 0.5) * (d - f); p[v] = x, p[v + 1] = E, p[v + 2] = w, p[v + 3] = y; } s.bindBuffer(s.ARRAY_BUFFER, this.Ms), s.bufferData(s.ARRAY_BUFFER, p, s.DYNAMIC_DRAW), s.enableVertexAttribArray(0), s.vertexAttribPointer(0, 2, s.FLOAT, !1, 16, 0), s.enableVertexAttribArray(1), s.vertexAttribPointer(1, 2, s.FLOAT, !1, 16, 8), s.drawArrays(s.TRIANGLES, 0, 6), s.disableVertexAttribArray(1), s.disableVertexAttribArray(0), s.bindBuffer(s.ARRAY_BUFFER, null); } gt() { this.A.deleteBuffer(this.Ms); } } var b = ((n) => (n.RECTANGLE = "rectangle", n.LINE = "line", n.ELLIPSE = "ellipse", n.ARC = "arc", n.TRIANGLE = "triangle", n.BEZIER_CURVE = "bezier_curve", n))(b || {}); const ee = { rectangle: 2, line: 2, ellipse: 2, triangle: 2, arc: 3, bezier_curve: 4 }; class ie { constructor(t) { a(this, "A"); a(this, "Ps", /* @__PURE__ */ new Map()); this.A = t; } Ts(t, e, i, r) { const s = this.A; let h = this.Ps.get(t); h || (h = /* @__PURE__ */ new Map(), this.Ps.set(t, h)); let o = h.get(e) || null; if (!o) { o = s.createVertexArray(), h.set(e, o), s.bindVertexArray(o), s.bindBuffer(s.ARRAY_BUFFER, r); const c = s.getAttribLocation(t, "A0"); c !== -1 && ft(s, c, i.ws.bs.size, i._s, i.ws.bs.offset, 0, s.FLOAT, !1); const l = s.getAttribLocation(t, "A1"); l !== -1 && ft(s, l, i.ws.Cs.size, i._s, i.ws.Cs.offset, 0, s.FLOAT, !1); } s.bindVertexArray(o); } Es() { this.A.bindVertexArray(null); } gt() { for (const [, t] of this.Ps) for (const [, e] of t) e && this.A.deleteVertexArray(e); } } const D = class D { static Rs(t, e, i = 0) { const r = e || new Float32Array(D.FLOATS_PER_INSTANCE); let s = i; r[s++] = t.bs[0], r[s++] = t.bs[1], r[s++] = t.Ss[0], r[s++] = t.Ss[1], r[s++] = t.Nt[0], r[s++] = t.Nt[1], r[s++] = t.Nt[2], r[s++] = t.Xt[0], r[s++] = t.Xt[1], r[s++] = t.Xt[2], r[s++] = t.Xt[3], r[s++] = t.Yt[0], r[s++] = t.Yt[1], r[s++] = t.Yt[2], r[s++] = t.Yt[3], r[s++] = t.zs[0], r[s++] = t.zs[1], r[s++] = t.zs[2], r[s++] = t.Rt; const h = t.ks; r[s++] = (h == null ? void 0 : h[0]) ?? 0, r[s++] = (h == null ? void 0 : h[1]) ?? 0, r[s++] = (h == null ? void 0 : h[2]) ?? 0; const o = t.Ds; r[s++] = (o == null ? void 0 : o[0]) ?? 0, r[s++] = (o == null ? void 0 : o[1]) ?? 0, r[s++] = (o == null ? void 0 : o[2]) ?? 0; const c = t.Ls, l = t.Os, u = t.Bs, f = t.Is, d = t.Hs, g = !(!l || !u); return g ? (r[s++] = (f == null ? void 0 : f[0]) ?? 0, r[s++] = (f == null ? void 0 : f[1]) ?? 0, r[s++] = (d == null ? void 0 : d[0]) ?? 0, r[s++] = (d == null ? void 0 : d[1]) ?? 0, r[s++] = l[0], r[s++] = l[1], r[s++] = u[0], r[s++] = u[1]) : !g && !!c ? (r[s++] = c[0], r[s++] = c[1], r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0) : (r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0, r[s++] = 0), r[s++] = t.Gs ?? 0, r[s++] = t.Qs ?? 0, r[s++] = t.Ns ?? 0, r; } static Xs(t, e) { const i = t.length * D.FLOATS_PER_INSTANCE, r = e || new Float32Array(i); for (let s = 0; s < t.length; s++) { const h = s * D.FLOATS_PER_INSTANCE; D.Rs(t[s], r, h); } return r; } }; a(D, "BYTES_PER_INSTANCE", 144), a(D, "FLOATS_PER_INSTANCE", 36); let N = D; const M = class M { }; a(M, "STRIDE", N.BYTES_PER_INSTANCE), a(M, "ATTRIBUTES", { A2: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 0, divisor: 1 }, A3: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 8, divisor: 1 }, A4: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 16, divisor: 1 }, A5: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 28, divisor: 1 }, A6: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 44, divisor: 1 }, A7: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 60, divisor: 1 }, A8: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 76, divisor: 1 }, A9: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 88, divisor: 1 }, Aa: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 100, divisor: 1 }, Ab: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 116, divisor: 1 }, Ac: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: M.STRIDE, offset: 132, divisor: 1 } }); let q = M; class re { constructor(t = 1e3, e = 1.5) { a(this, "Ys"); a(this, "js"); a(this, "Ks"); a(this, "Ws", 0); a(this, "Zs", 0); this.js = t, this.Ks = e; const i = t * N.FLOATS_PER_INSTANCE; this.Ys = new Float32Array(i); } qs(t) { if (t <= this.js) return; const e = Math.ceil(t * this.Ks), i = this.js; this.js = e; const r = e * N.FLOATS_PER_INSTANCE, s = new Float32Array(r), h = i * N.FLOATS_PER_INSTANCE; s.set(this.Ys.subarray(0, Math.min(h, this.Ws))), this.Ys = s; } Vs() { return { buffer: this.Ys, offset: this.Ws }; } Js(t) { this.Ws += t, this.Zs++; } ti() { this.Ws = 0, this.Zs = 0; } si(t = 0, e) { return this.Ys.subarray(t, e ?? this.Ws); } get ii() { return this.Zs; } get ei() { return this.js; } get ri() { return this.Ws; } get ni() { return this.Zs === 0; } } class se { constructor(t) { a(this, "Ys"); this.Ys = t; } oi(t) { this.Ys.qs(this.Ys.ii + 1); const { buffer: e, offset: i } = this.Ys.Vs(); e[i + 0] = t.x, e[i + 1] = t.y, e[i + 2] = t.width, e[i + 3] = t.height, e[i + 4] = t.char0, e[i + 5] = t.char1, e[i + 6] = t.char2, e[i + 7] = t.r1, e[i + 8] = t.g1, e[i + 9] = t.b1, e[i + 10] = t.a1, e[i + 11] = t.r2, e[i + 12] = t.g2, e[i + 13] = t.b2, e[i + 14] = t.a2, e[i + 15] = t.invert, e[i + 16] = t.flipX, e[i + 17] = t.flipY, e[i + 18] = t.charRot, e[i + 19] = t.translationX, e[i + 20] = t.translationY, e[i + 21] = t.translationZ, e[i + 22] = t.rotationX, e[i + 23] = t.rotationY, e[i + 24] = t.rotationZ; const r = t.curveParams0, s = t.curveParams1; return e[i + 25] = r[0], e[i + 26] = r[1], e[i + 27] = r[2], e[i + 28] = r[3], e[i + 29] = s[0], e[i + 30] = s[1], e[i + 31] = s[2], e[i + 32] = s[3], e[i + 33] = t.depth, e[i + 34] = t.baseZ, e[i + 35] = t.geometryType, this.Ys.Js(N.FLOATS_PER_INSTANCE), this.Ys.ii - 1; } get ii() { return this.Ys.ii; } } class ne { constructor(t, e = 1e3) { a(this, "A"); a(this, "hi", null); a(this, "ai", 0); a(this, "ci", /* @__PURE__ */ new Map()); this.A = t, this.li(e); } li(t) { const e = this.A; this.hi && e.deleteBuffer(this.hi), this.hi = e.createBuffer(); const i = t * N.BYTES_PER_INSTANCE; Rt(e, e.ARRAY_BUFFER, this.hi, i, e.DYNAMIC_DRAW), this.ai = t; } ui(t) { this.li(t); } get ei() { return this.ai; } fi(t, e) { if (e === 0) return; const i = this.A; i.bindBuffer(i.ARRAY_BUFFER, this.hi); const r = e * N.FLOATS_PER_INSTANCE; i.bufferSubData(i.ARRAY_BUFFER, 0, t, 0, r); } di(t) { let e = this.ci.get(t); if (!e) { e = /* @__PURE__ */ new Map(); const i = this.A; for (const r in q.ATTRIBUTES) { const s = i.getAttribLocation(t, r); s !== -1 && e.set(r, s); } this.ci.set(t, e); } return e; } pi(t) { const e = this.A, i = t.G, r = this.di(i); for (const [s, h] of r) { const o = q.ATTRIBUTES[s]; o && ft(e, h, o.size, o.stride, o.offset, o.divisor, o.type, o.normalized); } } gi(t) { const e = this.A, i = this.di(t.G); for (const [r, s] of i) q.ATTRIBUTES[r] && (e.disableVertexAttribArray(s), e.vertexAttribDivisor(s, 0)); } gt() { this.hi && (this.A.deleteBuffer(this.hi), this.hi = null), this.ci.clear(); } } class he { constructor(t, e = 1e3, i = 1.5) { a(this, "A"); a(this, "Ys"); a(this, "mi"); a(this, "_i"); this.A = t, this.Ys = new re(e, i), this.mi = new se(this.Ys), this._i = new ne(t, e); } yi(t) { var r, s, h, o, c, l, u, f, d, g; const e = [0, 0, 0, 0], i = [0, 0, 0, 0]; return t.Os && t.Bs ? (e[0] = ((r = t.Is) == null ? void 0 : r[0]) ?? 0, e[1] = ((s = t.Is) == null ? void 0 : s[1]) ?? 0, e[2] = ((h = t.Hs) == null ? void 0 : h[0]) ?? 0, e[3] = ((o = t.Hs) == null ? void 0 : o[1]) ?? 0, i[0] = t.Os[0], i[1] = t.Os[1], i[2] = t.Bs[0], i[3] = t.Bs[1]) : t.Ls && (e[0] = t.Ls[0], e[1] = t.Ls[1]), this.oi({ x: t.bs[0], y: t.bs[1], width: t.Ss[0], height: t.Ss[1], char0: t.Nt[0], char1: t.Nt[1], char2: t.Nt[2], r1: t.Xt[0], g1: t.Xt[1], b1: t.Xt[2], a1: t.Xt[3], r2: t.Yt[0], g2: t.Yt[1], b2: t.Yt[2], a2: t.Yt[3], invert: t.zs[0], flipX: t.zs[1], flipY: t.zs[2], charRot: t.Rt, translationX: ((c = t.ks) == null ? void 0 : c[0]) ?? 0, translationY: ((l = t.ks) == null ? void 0 : l[1]) ?? 0, translationZ: ((u = t.ks) == null ? void 0 : u[2]) ?? 0, rotationX: ((f = t.Ds) == null ? void 0 : f[0]) ?? 0, rotationY: ((d = t.Ds) == null ? void 0 : d[1]) ?? 0, rotationZ: ((g = t.Ds) == null ? void 0 : g[2]) ?? 0, curveParams0: e, curveParams1: i, depth: t.Gs || 0, baseZ: t.Qs || 0, geometryType: t.Ns || 0 }); } oi(t) { const e = this.mi.oi(t); return this.Ys.ei > this._i.ei && this._i.ui(this.Ys.ei), e; } get Ai() { return this.Ys.ii; } get ni() { return this.Ys.ni; } wi() { this.Ys.ti(); } pi(t) { const e = this.Ys.ii; if (e === 0) return; const i = this.Ys.si(); this._i.fi(i, e), this._i.pi(t); } gi(t) { this._i.gi(t); } $s(t, e) { const i = this.Ys.ii; i !== 0 && this.A.drawArraysInstanced(t, 0, e, i); } gt() { this._i.gt(); } } class O { constructor(t, e, i, r) { a(this, "A"); a(this, "bi"); a(this, "Ci"); a(this, "xi"); a(this, "Mi", null); this.A = t, this.bi = e, this.Ci = i, this.xi = r; const s = this.A.createBuffer(); Rt(this.A, this.A.ARRAY_BUFFER, s, this.xi.Fi, this.A.STATIC_DRAW), this.Mi = s; } get type() { return this.Ci; } get unitGeometry() { return this.xi; } get unitBuffer() { return this.Mi; } get batch() { return this.bi; } $i() { this.bi.wi(); } Pi() { return !this.bi.ni; } gt() { this.bi.gt(), this.A.deleteBuffer(this.Mi); } Ti(t, e, i) { return this.bi.yi(t); } Ei(t, e, i, r, s, h) { const o = s.Bt ?? 0, c = s.It ?? 0, l = s.Ht ?? 0, u = s.bt ?? 0, f = s.Ct ?? 0, d = s.xt ?? 0, g = [0, 0, 0, 0], p = [0, 0, 0, 0]; h && (h.bezStartX !== void 0 && h.bezStartY !== void 0 && h.bezEndX !== void 0 && h.bezEndY !== void 0 ? (g[0] = h.cp1x ?? 0, g[1] = h.cp1y ?? 0, g[2] = h.cp2x ?? 0, g[3] = h.cp2y ?? 0, p[0] = h.bezStartX ?? 0, p[1] = h.bezStartY ?? 0, p[2] = h.bezEndX ?? 0, p[3] = h.bezEndY ?? 0) : h.arcStart === void 0 && h.arcStop === void 0 || (g[0] = h.arcStart ?? 0, g[1] = h.arcStop ?? 0)); const v = { x: t, y: e, width: i, height: r, char0: s.Nt[0], char1: s.Nt[1], char2: s.Nt[2], r1: s.Xt[0], g1: s.Xt[1], b1: s.Xt[2], a1: s.Xt[3], r2: s.Yt[0], g2: s.Yt[1], b2: s.Yt[2], a2: s.Yt[3], invert: s.Et ? 1 : 0, flipX: s.Gt ? 1 : 0, flipY: s.Qt ? 1 : 0, charRot: s.Rt, translationX: o, translationY: c, translationZ: l, rotationX: u, rotationY: f, rotationZ: d, curveParams0: g, curveParams1: p, depth: (h == null ? void 0 : h.depth) ?? 0, baseZ: (h == null ? void 0 : h.baseZ) ?? 0, geometryType: ee[this.Ci] ?? 0 }; return this.bi.oi(v); } } const oe = { Fi: dt, Ri: 6, ...Y }, ae = { Fi: new Float32Array([0, -0.5, 0, 0, 1, -0.5, 1, 0, 0, 0.5, 0, 1, 0, 0.5, 0, 1, 1, -0.5, 1, 0, 1, 0.5, 1, 1]), Ri: 6, ...Y }, ce = { Fi: function(n = 32) { const t = [], e = 2 * Math.PI / n; for (let i = 0; i < n; i++) { const r = i * e, s = (i + 1) % n * e, h = Math.cos(r), o = Math.sin(r), c = 0.5 * (h + 1), l = 0.5 * (o + 1), u = Math.cos(s), f = Math.sin(s), d = 0.5 * (u + 1), g = 0.5 * (f + 1); t.push(0, 0, 0.5, 0.5, h, o, c, l, u, f, d, g); } return new Float32Array(t); }(32), Ri: 96, ...Y }; let le = { Fi: function(n) { const t = []; for (let e = 0; e < n; e++) { const i = e / n, r = (e + 1) / n; t.push(i, 0, i, 0, i, 1, i, 1, r, 1, r, 1); } return new Float32Array(t); }(32), Ri: 96, ...Y }; const ue = { Fi: new Float32Array([0, 0, 0, 0, 1, 0, 1, 0, 0.5, 1, 0.5, 1]), Ri: 3, ...Y }, fe = { Fi: function(n = 16) { const t = []; for (let e = 0; e < n; e++) { const i = e / n, r = (e + 1) / n; t.push(i, -0.5, i, 0, r, -0.5, r, 0, i, 0.5, i, 1, i, 0.5, i, 1, r, -0.5, r, 0, r, 0.5, r, 1); } return new Float32Array(t); }(16), Ri: 96, ...Y }, de = { [b.RECTANGLE]: class extends O { constructor(n, t) { super(n, t, b.RECTANGLE, oe); } yi(n, t) { return this.Ei(0, 0, n.width, n.height, t); } }, [b.LINE]: class extends O { constructor(n, t) { super(n, t, b.LINE, ae); } yi(n, t) { const e = n.x2 - n.x1, i = n.y2 - n.y1, r = Math.hypot(e, i), s = Math.atan2(i, e), h = t.Ot || 1, o = n.x1 + e / 2 - r / 2, c = n.y1 + i / 2, l = { ...t, xt: (t.xt || 0) + s }; return this.Ei(o, c, r, h, l); } }, [b.ELLIPSE]: class extends O { constructor(n, t) { super(n, t, b.ELLIPSE, ce); } yi(n, t) { return this.Ei(0, 0, n.width, n.height, t); } }, [b.ARC]: class extends O { constructor(n, t) { super(n, t, b.ARC, le); } yi(n, t) { const e = n.start * Math.PI / 180, i = n.stop * Math.PI / 180; return this.Ei(0, 0, n.width, n.height, t, { arcStart: e, arcStop: i }); } }, [b.TRIANGLE]: class extends O { constructor(n, t) { super(n, t, b.TRIANGLE, ue); } yi(n, t) { const e = Math.min(n.x1, n.x2, n.x3), i = Math.max(n.x1, n.x2, n.x3), r = Math.min(n.y1, n.y2, n.y3), s = i - e, h = Math.max(n.y1, n.y2, n.y3) - r; return this.Ei(e, r, s, h, t); } }, [b.BEZIER_CURVE]: class extends O { constructor(n, t) { super(n, t, b.BEZIER_CURVE, fe); } yi(n, t) { return this.Ei(0, 0, 1, t.Ot || 1, t, { cp1x: n.cp1x, cp1y: n.cp1y, cp2x: n.cp2x, cp2y: n.cp2y, bezStartX: n.x1, bezStartY: n.y1, bezEndX: n.x2, bezEndY: n.y2 }); } } }; class ge { constructor(t) { a(this, "A"); a(this, "Si"); a(this, "zi"); this.A = t, this.zi = new ie(t), this.Si = /* @__PURE__ */ new Map(); for (const e of Object.values(b)) { const i = new he(t), r = new de[e](t, i); this.Si.set(e, r); } } ki(t) { this.Di(t).forEach((e) => { this.Li(e); }); } Di(t) { const e = []; let i = null, r = null, s = null; for (const h of t) r !== h.material || s !== h.type ? (i && i.length > 0 && e.push({ material: r, type: s, commands: i }), i = [h], r = h.material, s = h.type) : i.push(h); return i && i.length > 0 && e.push({ material: r, type: s, commands: i }), e; } Li(t) { const { material: e, type: i, commands: r } = t, s = this.Si.get(i); e.shader.D(), e.shader.O(e.uniforms); const h = Ct(this.A), o = r.length > 0 && r[0].state.zt; if (e.shader.O({ Uu: h[2] / h[3], Ur: [h[2], h[3]], Us: 1, Ut: o ? 1 : 0 }), s.$i(), r.forEach((c) => { s.yi(c.params, c.state); }), s.Pi()) { const c = s.unitGeometry, l = s.unitBuffer; try { this.zi.Ts(e.shader.G, i + "", c, l), s.batch.pi(e.shader), s.batch.$s(c.As, c.Ri); } finally { s.batch.gi(e.shader), this.zi.Es(), s.$i(); } } } gt() { for (const t of this.Si.values()) t.gt(); this.Si.clear(), this.zi.gt(); } } function Mt(n) { let t = 0; for (let e = 0; e < n.length; e++) t = (t << 5) - t + n.charCodeAt(e), t &= t; return t; } const yt = /* @__PURE__ */ new WeakMap(); let ve = 1; function wt(n) { if (n == null) return 0; if (typeof n != "object" && typeof n != "function") return Mt(n + ""); let t = yt.get(n); return t || (t = ve++, yt.set(n, t)), t; } function H(n, t) { return (n << 5) - n + t; } class pe { constructor(t) { a(this, "Oi", 0); a(this, "Bi"); a(this, "Ii"); a(this, "Hi", /* @__PURE__ */ new Map()); this.Bi = new W(t, rt, `#version 300 es precision highp float;in vec3 v_glyphIndex;in vec4 v_glyphColor;in vec4 v_cellColor;in vec4 v_glyphFlags;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 A;void main(){int B=int(v_glyphFlags.r>0.5?1:0);int C=int(v_glyphFlags.g>0.5?1:0);int D=int(v_glyphFlags.b>0.5?1:0);float E=float(B|(C<<1)|(D<<2))/255.;o_character=vec4(v_glyphIndex.xy,E,clamp(v_glyphFlags.a,0.,1.));o_primaryColor=vec4(v_glyphColor.rgb,v_glyphColor.a);o_secondaryColor=vec4(v_cellColor.rgb,v_cellColor.a);A=vec4(0.);}`), this.Ii = { id: this.Oi++, shader: this.Bi, uniforms: Object.freeze({}), hash: this.Gi(this.Bi, {}), isBuiltIn: !0 }; } get Qi() { return this.Ii; } dt(t, e = {}, i = !1) { const r = this.Gi(t, e), s = this.Hi.get(r); if (s) return s; const h = { id: this.Oi++, shader: t, uniforms: Object.freeze({ ...e }), hash: r, isBuiltIn: i }; return this.Hi.set(r, h), h; } Ni(t, e = {}) { return { id: this.Oi++, shader: t, uniforms: Object.freeze({ ...e }), hash: 0, isBuiltIn: !1 }; } Gi(t, e) { const i = wt(t.G), r = function(s, h) { let o = 0; const c = Object.keys(s).sort(); for (const l of c) o = H(o, Mt(l)), o = H(o, h(s[l])); return o; }(e, this.Xi.bind(this)); return H(i, r); } Xi(t) { return typeof t == "number" || typeof t == "boolean" ? function(e) { return typeof e == "boolean" ? e ? 1 : 0 : Math.floor(e); }(t) : Array.isArray(t) ? function(e) { let i = 0; const r = Array.isArray(e[0]) ? e.flat() : e; for (const s of r) i = H(i, typeof s == "number" ? s : 0); return i; }(t) : t instanceof Float32Array || t instanceof Int32Array ? function(e) { let i = 0; const r = Math.min(e.length, 16); for (let s = 0; s < r; s++) i = H(i, e[s]); return i; }(t) : t instanceof WebGLTexture ? wt(t) : 0; } gt() { this.Bi != this.Bi && this.Bi.dispose(), this.Bi.dispose(), this.Hi.clear(); } } class Ae { constructor() { a(this, "Yi", []); a(this, "ji", 1); a(this, "Ss", 0); } Ki(t, e) { if (this.Ss >= this.Yi.length) { const r = { id: this.ji++, type: t, params: {}, state: st.Lt(), material: e }; this.Yi.push(r); } const i = this.Yi[this.Ss]; return i.id = this.ji++, i.type = t, i.material = e, this.Ss++, i; } Wi(t, e, i) { const r = this.Ki(b.RECTANGLE, i), s = r.params; return s.width = t.width, s.height = t.height, e.Wt(r.state), r.id; } Zi(t, e, i) { const r = this.Ki(b.LINE, i), s = r.params; return s.x1 = t.x1, s.y1 = t.y1, s.x2 = t.x2, s.y2 = t.y2, s.thickness = t.thickness, e.Wt(r.state), r.id; } qi(t, e, i) { const r = this.Ki(b.ELLIPSE, i), s = r.params; return s.width = t.width, s.height = t.height, s.startAngle = t.startAngle, s.endAngle = t.endAngle, s.segments = t.segments, e.Wt(r.state), r.id; } Vi(t, e, i) { const r = this.Ki(b.ARC, i), s = r.params; return s.width = t.width, s.height = t.height, s.start = t.start, s.stop = t.stop, e.Wt(r.state), r.id; } Ji(t, e, i) { const r = this.Ki(b.TRIANGLE, i), s = r.params; return s.x1 = t.x1, s.y1 = t.y1, s.x2 = t.x2, s.y2 = t.y2, s.x3 = t.x3, s.y3 = t.y3, e.Wt(r.state), r.id; } te(t, e, i) { const r = this.Ki(b.BEZIER_CURVE, i), s = r.params; return s.x1 = t.x1, s.y1 = t.y1, s.cp1x = t.cp1x, s.cp1y = t.cp1y, s.cp2x = t.cp2x, s.cp2y = t.cp2y, s.x2 = t.x2, s.y2 = t.y2, s.thickness = t.thickness, s.segments = t.segments, e.Wt(r.state), r.id; } wi() { this.Ss = 0; } [Symbol.iterator]() { let t = 0; const e = this.Ss, i = this.Yi; return { next: () => t < e ? { value: i[t++], done: !1 } : { value: void 0, done: !0 } }; } } class me { constructor(t) { a(this, "A"); a(this, "se", null); a(this, "ie"); a(this, "vt"); a(this, "ee"); a(this, "re"); a(this, "ne"); a(this, "oe", null); a(this, "he", {}); a(this, "ae", []); a(this, "ce", []); a(this, "le", []); a(this, "ue", null); a(this, "fe", [0, 0, 0, 0]); a(this, "de", 1); this.A = t, t.enable(t.DEPTH_TEST), t.depthFunc(t.LEQUAL), t.clearDepth(1), t.depthMask(!0), t.disable(t.CULL_FACE), this.ee = new st(), this.vt = new pe(t), this.re = new Ae(), this.ie = new ge(t), this.ne = new te(t); const e = [0, 0, t.canvas.width, t.canvas.height]; ht(t, e), this.ae.push(null), this.ce.push(e), this.le.push(1), this.ue = null, this.fe = e, this.de = 1; } rt() { this.ae.push(this.ue), this.ce.push([...this.fe]), this.le.push(this.de); } lt() { const t = this.ae.pop() ?? null, e = this.ce.pop() ?? [0, 0, this.A.canvas.width, this.A.canvas.height], i = this.le.pop() ?? 1; this.nt(t, e[2], e[3], i); } nt(t, e, i, r = 1) { const s = this.A; this.ue !== t && (s.bindFramebuffer(s.FRAMEBUFFER, t), this.ue = t), this.de = r; const h = [0, 0, e, i]; this.fe[0] === h[0] && this.fe[1] === h[1] && this.fe[2] === h[2] && this.fe[3] === h[3] || (s.viewport(...h), ht(s, h), this.fe = h); } ve(t) { this.se !== t && (this.se = t, t.D()); } pe(t, e) { return new W(this.A, t, e); } ge(t) { this.oe = t, t && (this.he = {}); } I(t, e) { this.he[t] = e; } me(t) { Object.assign(this.he, t); } _e(t) { return new W(this.A, rt, t); } ye(t, e, i, r) { t instanceof X || !r || t.Ae(r), this.re.Wi({ width: e ?? t.width, height: i ?? t.height }, this.ee, t.ut()); } we(t, e, i, r) { this.ne.$s(t, e, i, r); } be(t, e) { if (this.oe) { const i = this.vt.Ni(this.oe, this.he); this.re.Wi({ width: t, height: e }, this.ee, i), this.oe = null, this.he = {}; } else this.re.Wi({ width: t, height: e }, this.ee, this.vt.Qi); } Ce(t, e, i, r) { this.re.Zi({ x1: t, y1: e, x2: i, y2: r }, this.ee, this.vt.Qi); } xe(t, e) { this.re.qi({ width: t, height: e }, this.ee, this.vt.Qi); } Me(t, e, i, r, s, h) { this.re.Ji({ x1: t, y1: e, x2: i, y2: r, x3: s, y3: h }, this.ee, this.vt.Qi); } Fe(t, e, i, r, s, h, o, c) { this.re.te({ x1: t, y1: e, cp1x: i, cp1y: r, cp2x: s, cp2y: h, x2: o, y2: c }, this.ee, this.vt.Qi); } $e(t, e, i, r) { this.re.Vi({ width: t, height: e, start: i, stop: r }, this.ee, this.vt.Qi); } Pe(t, e, i = 1, r = {}) { return new X(this.A, t, e, i, r, this); } Te(t, e = t, i = t, r = 255) { this.ee.ps(t, e ?? t, i ?? t, r); const [s, h, o, c] = this.ee.canvasBackgroundColor; this.Ee(s, h, o, c, !1); } wi(t = 0, e = 0, i = 0, r = 0) { this.Ee(t, e, i, r, !0); } Ee(t, e, i, r, s) { const h = this.A; if (this.de > 1) { const o = s ? [1, 1, 0, 0] : [0, 0, 0, 0]; h.clearBufferfv(h.COLOR, 0, new Float32Array(o)), h.clearBufferfv(h.COLOR, 1, new Float32Array([0, 0, 0, 0])), this.de >= 3 && h.clearBufferfv(h.COLOR, 2, new Float32Array([t, e, i, r])); for (let c = 3; c < this.de; c++) h.clearBufferfv(h.COLOR, c, new Float32Array([0, 0, 0, 0])); } else h.clearColor(t, e, i, r), h.clear(h.COLOR_BUFFER_BIT); } Re() { const t = [0, 0, this.A.canvas.width, this.A.canvas.height]; this.A.viewport(...t), ht(this.A, t), this.fe = t, this.ce.length > 0 && (this.ce[0] = t); } ct() { const t = this.re; this.ie.ki(t), t.wi(), this.se = null; } gt() { this.vt.gt(), this.ie.gt(), this.ne.gt(); } get context() { return this.A; } get state() { return this.ee; } get materialManager() { return this.vt; } } const R = { readShort: (n, t) => (R.t.uint16[0] = n[t] << 8 | n[t + 1], R.t.int16[0]), readUshort: (n, t) => n[t] << 8 | n[t + 1], readUshorts(n, t, e) { const i = []; for (let r = 0; r < e; r++) i.push(R.readUshort(n, t + 2 * r)); return i; }, readUint(n, t) { const e = R.t.uint8; return e[3] = n[t], e[2] = n[t + 1], e[1] = n[t + 2], e[0] = n[t + 3], R.t.uint32[0]; }, readASCII(n, t, e) { let i = ""; for (let r = 0; r < e; r++) i += String.fromCharCode(n[t + r]); return i; }, t: (() => { const n = new ArrayBuffer(8); return { uint8: new Uint8Array(n), int16: new Int16Array(n), uint16: new Uint16Array(n), uint32: new Uint32Array(n) }; })() }; function K(n) { return n + 3 & -4; } function J(n, t, e) { n[t] = e >>> 8 & 255, n[t + 1] = 255 & e; } function B(n, t, e) { n[t] = e >>> 24 & 255, n[t + 1] = e >>> 16 & 255, n[t + 2] = e >>> 8 & 255, n[t + 3] = 255 & e; } function ye(n, t, e) { for (let i = 0; i < e.length; i++) n[t + i] = 255 & e.charCodeAt(i); } function ot(n, t, e) { const i = t + e; let r = 0; const s = R.t; for (let h = t; h < i; h += 4) s.uint8[3] = n[h] || 0, s.uint8[2] = n[h + 1] || 0, s.uint8[1] = n[h + 2] || 0, s.uint8[0] = n[h + 3] || 0, r = r + (s.uint32[0] >>> 0) >>> 0; return r >>> 0; } class we { constructor(t) { a(this, "b"); a(this, "p", 0); a(this, "bitbuf", 0); a(this, "bitcnt", 0); this.b = t; } readBits(t) { for (; this.bitcnt < t; ) { const i = this.b[this.p++] || 0; this.bitbuf |= i << this.bitcnt, this.bitcnt += 8; } const e = this.bitbuf & (1 << t) - 1; return this.bitbuf >>>= t, this.bitcnt -= t, e; } alignToByte() { this.bitbuf = 0, this.bitcnt = 0; } get offset() { return this.p; } } function G(n) { let t = 32, e = 0; for (const o of n) o && (o < t && (t = o), o > e && (e = o)); if (e === 0) return { min: 0, max: 0, table: /* @__PURE__ */ new Map() }; const i = new Uint32Array(e + 1); for (const o of n) o && i[o]++; const r = new Uint32Array(e + 1); let s = 0; i[0] = 0; for (let o = 1; o <= e; o++) s = s + i[o - 1] << 1, r[o] = s; const h = /* @__PURE__ */ new Map(); for (let o = 0; o < n.length; o++) { const c = n[o]; if (!c) continue; const l = r[c]++; let u = h.get(c); u || (u = [], h.set(c, u)), u[Ee(l, c)] = o; } return { min: t, max: e, table: h }; } function at(n, t) { let e = 0; for (let i = 1; i <= t.max; i++) { e |= n.readBits(1) << i - 1; const r = t.table.get(i); if (r && e < r.length) { const s = r[e]; if (s !== void 0) return s; } } throw Error("Invalid Huffman code"); } function Ee(n, t) { let e = 0; for (let i = 0; i < t; i++) e = e << 1 | 1 & n, n >>>= 1; return e >>> 0; } function be(n) { if (n.length < 2) throw Error("ZLIB data too short"); const t = n[0], e = n[1]; if ((15 & t) != 8) throw Error("Unsupported ZLIB compression method"); if (((t << 8) + e) % 31 != 0) throw Error("Bad ZLIB header check"); let i = 2; 32 & e && (i += 4); const r = []; return function(s, h) { const o = [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], c = [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], l = [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], u = [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 f = 0; for (; !f; ) { f = s.readBits(1); const d = s.readBits(2); if (d === 0) { s.alignToByte(); const g = s.readBits(16); if ((65535 & (65535 ^ g)) !== s.readBits(16)) throw Error("DEFLATE uncompressed LEN/NLEN mismatch"); for (let p = 0; p < g; p++) h.push(s.readBits(8)); } else { if (d !== 1 && d !== 2) throw Error("Unsupported DEFLATE type"); { let g, p; if (d === 1) { const v = Array(288).fill(0); for (let A = 0; A <= 143; A++) v[A] = 8; for (let A = 144; A <= 255; A++) v[A] = 9; for (let A = 256; A <= 279; A++) v[A] = 7; for (let A = 280; A <= 287; A++) v[A] = 8; g = G(v), p = G(Array(32).fill(5)); } else { const v = s.readBits(5) + 257, A = s.readBits(5) + 1, m = s.readBits(4) + 4, w = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], y = Array(19).fill(0); for (let T = 0; T < m; T++) y[w[T]] = s.readBits(3); const x = G(y), E = []; for (; E.length < v + A; ) { const T = at(s, x); if (T <= 15) E.push(T); else if (T === 16) { const L = s.readBits(2) + 3, C = E[E.length - 1] || 0; for (let Q = 0; Q < L; Q++) E.push(C); } else if (T === 17) { const L = s.readBits(3) + 3; for (let C = 0; C < L; C++) E.push(0); } else { if (T !== 18) throw Error("Invalid code length symbol"); { const L = s.readBits(7) + 11; for (let C = 0; C < L; C++) E.push(0); } } } const F = E.slice(0, v), P = E.slice(v, v + A); g = G(F), p = G(P); } for (; ; ) { const v = at(s, g); if (v < 256) h.push(v); else { if (v === 256) break; if (v > 256 && v < 286) { const A = v - 257; let m = o[A]; const w = c[A]; w && (m += s.readBits(w)); const y = at(s, p); if (y >= 30) throw Error("Invalid distance symbol"); let x = l[y]; const E = u[y]; E && (x += s.readBits(E)); const F = h.length - x; if (F < 0) throw Error("Invalid distance"); for (let P = 0; P < m; P++) h.push(h[F + P] || 0); } else if (v === 286 || v === 287) throw Error("Reserved length symbol"); } } } } } }(new we(n.subarray(i)), r), new Uint8Array(r); } function xe(n) { const t = R, e = new Uint8Array(n); if (t.readASCII(e, 0, 4) !== "wOFF") throw Error("Invalid WOFF signature"); const i = t.readUint(e, 4), r = t.readUshort(e, 12), s = t.readUint(e, 16), h = []; let o = 44; for (let m = 0; m < r; m++) { const w = t.readASCII(e, o, 4), y = t.readUint(e, o + 4), x = t.readUint(e, o + 8), E = t.readUint(e, o + 12), F = t.readUint(e, o + 16); h.push({ tag: w, offset: y, compLength: x, origLength: E, checksum: F }), o += 20; } for (const m of h) { const w = new Uint8Array(e.buffer, m.offset, m.compLength); if (m.compLength === m.origLength) m.data = new Uint8Array(w); else if (m.data = be(w), m.data.length !== m.origLength) if (m.data.length < m.origLength) { const y = new Uint8Array(m.origLength); y.set(m.data), m.data = y; } else m.data = m.data.subarray(0, m.origLength); } const c = r; let l = 1, u = 0; for (; l << 1 <= c; ) l <<= 1, u++; const f = 16 * l, d = 16 * c - f; let g = 12 + 16 * c; const p = {}; for (const m of h) p[m.tag] = g, g = K(g + m.data.length); const v = new Uint8Array(Math.max(s || 0, g)); B(v, 0, i), J(v, 4, c), J(v, 6, f), J(v, 8, u), J(v, 10, d); let A = 12; for (const m of h) { ye(v, A, m.tag), A += 4; let w = m.data; if (m.tag === "head" && w.length >= 12) { const y = new Uint8Array(w); B(y, 8, 0), B(v, A, ot(y, 0, K(y.length))), A += 4; } else B(v, A, ot(w, 0, K(w.length))), A += 4; B(v, A, p[m.tag]), A += 4, B(v, A, m.data.length), A += 4; } for (const m of h) { const w = p[m.tag]; v.set(m.data, w); } if (h.find((m) => m.tag === "head")) { const m = p.head, w = function(y, x) { const E = x + 8, F = [y[E], y[E + 1], y[E + 2], y[E + 3]]; B(y, E, 0); const P = 2981146554 - (ot(y, 0, K(y.length)) >>> 0) >>> 0; return y[E]