textmode.js 0.1.9-beta.6 → 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +14 -13
  2. package/dist/textmode.esm.js +1408 -1419
  3. package/dist/textmode.esm.min.js +1488 -1499
  4. package/dist/textmode.umd.js +19 -56
  5. package/dist/textmode.umd.min.js +19 -56
  6. package/dist/types/Textmode.d.ts +10 -38
  7. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  8. package/dist/types/export/image/ImageExporter.d.ts +4 -11
  9. package/dist/types/export/image/types.d.ts +2 -3
  10. package/dist/types/export/svg/SVGExporter.d.ts +1 -1
  11. package/dist/types/export/svg/types.d.ts +1 -0
  12. package/dist/types/export/txt/TXTDataExtractor.d.ts +3 -3
  13. package/dist/types/export/txt/TXTExporter.d.ts +1 -1
  14. package/dist/types/export/txt/types.d.ts +4 -2
  15. package/dist/types/index.d.ts +1 -6
  16. package/dist/types/rendering/index.d.ts +2 -2
  17. package/dist/types/rendering/webgl/DrawQueue.d.ts +26 -0
  18. package/dist/types/rendering/webgl/Framebuffer.d.ts +38 -52
  19. package/dist/types/rendering/webgl/InstanceBatch.d.ts +91 -0
  20. package/dist/types/rendering/webgl/InstanceData.d.ts +65 -0
  21. package/dist/types/rendering/webgl/RenderPipeline.d.ts +15 -0
  22. package/dist/types/rendering/webgl/RenderState.d.ts +76 -0
  23. package/dist/types/rendering/webgl/Renderer.d.ts +58 -83
  24. package/dist/types/rendering/webgl/Shader.d.ts +23 -12
  25. package/dist/types/rendering/webgl/VAOManager.d.ts +15 -0
  26. package/dist/types/rendering/webgl/geometries/Arc.d.ts +16 -0
  27. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +35 -29
  28. package/dist/types/rendering/webgl/geometries/BezierCurve.d.ts +22 -0
  29. package/dist/types/rendering/webgl/geometries/Ellipse.d.ts +20 -0
  30. package/dist/types/rendering/webgl/geometries/Line.d.ts +13 -4
  31. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +13 -8
  32. package/dist/types/rendering/webgl/geometries/Triangle.d.ts +20 -0
  33. package/dist/types/rendering/webgl/geometries/index.d.ts +4 -1
  34. package/dist/types/rendering/webgl/index.d.ts +17 -1
  35. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +9 -0
  36. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +144 -0
  37. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +12 -0
  38. package/dist/types/textmode/AnimationController.d.ts +81 -0
  39. package/dist/types/textmode/Canvas.d.ts +18 -19
  40. package/dist/types/textmode/Grid.d.ts +1 -34
  41. package/dist/types/textmode/Textmodifier.d.ts +36 -277
  42. package/dist/types/textmode/font/CharacterColorMapper.d.ts +3 -3
  43. package/dist/types/textmode/font/TextmodeFont.d.ts +8 -13
  44. package/dist/types/textmode/font/TextureAtlas.d.ts +2 -2
  45. package/dist/types/textmode/font/types.d.ts +1 -1
  46. package/dist/types/textmode/font/typr/types.d.ts +1 -1
  47. package/dist/types/textmode/font/utils/index.d.ts +0 -1
  48. package/dist/types/textmode/mixins/AnimationMixin.d.ts +120 -0
  49. package/dist/types/textmode/mixins/ExportMixin.d.ts +4 -6
  50. package/dist/types/textmode/mixins/FontMixin.d.ts +4 -10
  51. package/dist/types/textmode/mixins/RenderingMixin.d.ts +224 -246
  52. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +13 -4
  53. package/dist/types/textmode/mixins/index.d.ts +2 -2
  54. package/package.json +1 -1
  55. package/dist/types/ColorPalette.d.ts +0 -38
  56. package/dist/types/rendering/core/AbstractFramebuffer.d.ts +0 -1
  57. package/dist/types/rendering/core/AbstractGeometry.d.ts +0 -1
  58. package/dist/types/rendering/core/AbstractShader.d.ts +0 -1
  59. package/dist/types/rendering/core/AbstractTexture.d.ts +0 -1
  60. package/dist/types/rendering/core/GraphicsContext.d.ts +0 -1
  61. package/dist/types/textmode/ConversionPipeline.d.ts +0 -110
  62. package/dist/types/textmode/converters/BrightnessConverter.d.ts +0 -58
  63. package/dist/types/textmode/converters/Converter.d.ts +0 -62
  64. package/dist/types/textmode/converters/FeatureConverter.d.ts +0 -106
  65. package/dist/types/textmode/converters/index.d.ts +0 -3
  66. package/dist/types/textmode/font/utils/FontConstants.d.ts +0 -60
  67. package/dist/types/textmode/mixins/ConversionMixin.d.ts +0 -62
@@ -1,1616 +1,1672 @@
1
- var tt = Object.defineProperty;
2
- var et = (a, t, e) => t in a ? tt(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
- var h = (a, t, e) => et(a, typeof t != "symbol" ? t + "" : t, e);
4
- class w extends Error {
1
+ var J = Object.defineProperty;
2
+ var q = (a, t, e) => t in a ? J(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
+ var c = (a, t, e) => q(a, typeof t != "symbol" ? t + "" : t, e);
4
+ class C extends Error {
5
5
  constructor(t, e = {}) {
6
- super(w.i(t, e)), this.name = "TextmodeError";
6
+ super(C.i(t, e)), this.name = "TextmodeError";
7
7
  }
8
8
  static i(t, e) {
9
- let r = t;
9
+ let s = t;
10
10
  if (e && Object.keys(e).length > 0) {
11
- r += `
11
+ s += `
12
12
 
13
13
  📋 Context:`;
14
- for (const [s, i] of Object.entries(e))
15
- r += `
16
- - ${s}: ${w.o(i)}`;
14
+ for (const [r, i] of Object.entries(e))
15
+ s += `
16
+ - ${r}: ${C.o(i)}`;
17
17
  }
18
- return r += `
18
+ return s += `
19
19
 
20
- `, r += "↓".repeat(24) + `
21
- `, r;
20
+ `, s += "↓".repeat(24) + `
21
+ `, s;
22
22
  }
23
23
  static o(t) {
24
24
  if (t === null) return "null";
25
25
  if (t === void 0) return "undefined";
26
26
  if (typeof t == "string") return `"${t}"`;
27
27
  if (typeof t == "number" || typeof t == "boolean") return t + "";
28
- if (Array.isArray(t)) return t.length === 0 ? "[]" : t.length <= 5 ? `[${t.map((e) => w.o(e)).join(", ")}]` : `[${t.slice(0, 3).map((e) => w.o(e)).join(", ")}, ... +${t.length - 3} more]`;
28
+ if (Array.isArray(t)) return t.length === 0 ? "[]" : t.length <= 5 ? `[${t.map((e) => C.o(e)).join(", ")}]` : `[${t.slice(0, 3).map((e) => C.o(e)).join(", ")}, ... +${t.length - 3} more]`;
29
29
  if (typeof t == "object") {
30
30
  const e = Object.keys(t);
31
- return e.length === 0 ? "{}" : e.length <= 3 ? `{ ${e.map((r) => `${r}: ${w.o(t[r])}`).join(", ")} }` : `{ ${e.slice(0, 2).map((r) => `${r}: ${w.o(t[r])}`).join(", ")}, ... +${e.length - 2} more }`;
31
+ return e.length === 0 ? "{}" : e.length <= 3 ? `{ ${e.map((s) => `${s}: ${C.o(t[s])}`).join(", ")} }` : `{ ${e.slice(0, 2).map((s) => `${s}: ${C.o(t[s])}`).join(", ")}, ... +${e.length - 2} more }`;
32
32
  }
33
33
  return t + "";
34
34
  }
35
35
  }
36
- var rt = ((a) => (a[a.SILENT = 0] = "SILENT", a[a.WARNING = 1] = "WARNING", a[a.ERROR = 2] = "ERROR", a[a.THROW = 3] = "THROW", a))(rt || {});
37
- const P = class P {
36
+ var Z = ((a) => (a[a.SILENT = 0] = "SILENT", a[a.WARNING = 1] = "WARNING", a[a.ERROR = 2] = "ERROR", a[a.THROW = 3] = "THROW", a))(Z || {});
37
+ const w = class w {
38
38
  constructor() {
39
- h(this, "l", { globalLevel: 3 });
39
+ c(this, "l", { globalLevel: 3 });
40
40
  }
41
41
  static u() {
42
- return P.h || (P.h = new P()), P.h;
42
+ return w.h || (w.h = new w()), w.h;
43
43
  }
44
44
  p(t, e) {
45
- const r = "%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.", s = "color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";
45
+ const s = "%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.", r = "color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";
46
46
  switch (this.l.globalLevel) {
47
47
  case 0:
48
48
  return !1;
49
49
  case 1:
50
- return console.group(r, s), console.warn(w.i(t, e)), console.groupEnd(), !1;
50
+ return console.group(s, r), console.warn(C.i(t, e)), console.groupEnd(), !1;
51
51
  case 2:
52
- return console.group(r, s), console.error(w.i(t, e)), console.groupEnd(), !1;
52
+ return console.group(s, r), console.error(C.i(t, e)), console.groupEnd(), !1;
53
53
  default:
54
- throw new w(t, e);
54
+ throw new C(t, e);
55
55
  }
56
56
  }
57
- m(t, e, r) {
58
- return !!t || (this.p(e, r), !1);
57
+ _(t, e, s) {
58
+ return !!t || (this.p(e, s), !1);
59
59
  }
60
- _(t) {
60
+ m(t) {
61
61
  this.l.globalLevel = t;
62
62
  }
63
63
  };
64
- h(P, "h", null);
65
- let L = P;
66
- const x = L.u(), q = /* @__PURE__ */ new WeakMap();
67
- function I(a, t) {
68
- q.set(a, t);
64
+ c(w, "h", null);
65
+ let z = w;
66
+ const I = z.u(), X = /* @__PURE__ */ new WeakMap();
67
+ function D(a, t) {
68
+ X.set(a, t);
69
69
  }
70
- function Z(a) {
71
- return q.get(a);
70
+ function L(a) {
71
+ return X.get(a);
72
72
  }
73
- class J {
74
- constructor(t, e, r = e, s = {}) {
75
- h(this, "v");
76
- h(this, "C");
77
- h(this, "$");
78
- h(this, "F");
79
- h(this, "M");
80
- h(this, "l");
81
- h(this, "D", null);
82
- h(this, "S", null);
83
- this.v = t, this.F = e, this.M = r, this.l = { filter: "nearest", wrap: "clamp", format: "rgba", type: "unsigned_byte", ...s }, this.$ = this.R(), this.C = t.createFramebuffer(), this.V();
84
- }
85
- k(t) {
86
- const { v: e } = this, r = e.getParameter(e.FRAMEBUFFER_BINDING);
87
- e.bindFramebuffer(e.FRAMEBUFFER, this.C);
88
- try {
89
- return t();
90
- } finally {
91
- e.bindFramebuffer(e.FRAMEBUFFER, r);
73
+ class Y {
74
+ constructor(t, e, s = e, r = 1, i = {}) {
75
+ c(this, "v");
76
+ c(this, "C");
77
+ c(this, "l");
78
+ c(this, "$", null);
79
+ c(this, "R");
80
+ c(this, "M");
81
+ c(this, "S", []);
82
+ c(this, "A");
83
+ c(this, "P", null);
84
+ c(this, "F", []);
85
+ this.v = e, this.C = s, this.l = { filter: "nearest", wrap: "clamp", format: "rgba", type: "unsigned_byte", ...i }, this.R = t, this.A = Math.min(Math.max(1, r), 8);
86
+ const n = t.getParameter(t.MAX_DRAW_BUFFERS), o = t.getParameter(t.MAX_COLOR_ATTACHMENTS);
87
+ this.A = Math.min(this.A, n, o), this.M = t.createFramebuffer(), this.G(), this.D(), this.F = Array(this.A).fill(null);
88
+ }
89
+ G() {
90
+ const t = this.R, e = this.l.filter === "linear" ? t.LINEAR : t.NEAREST, s = this.l.wrap === "repeat" ? t.REPEAT : t.CLAMP_TO_EDGE, r = this.l.type === "float" ? t.FLOAT : t.UNSIGNED_BYTE;
91
+ for (let i = 0; i < this.A; i++) {
92
+ const n = t.createTexture();
93
+ t.bindTexture(t.TEXTURE_2D, n), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, e), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, e), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, s), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, s), t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, this.v, this.C, 0, t.RGBA, r, null), this.S.push(n);
92
94
  }
95
+ t.bindTexture(t.TEXTURE_2D, null);
93
96
  }
94
- R() {
95
- const { v: t } = this, e = t.createTexture();
96
- t.bindTexture(t.TEXTURE_2D, e);
97
- const r = this.l.filter === "linear" ? t.LINEAR : t.NEAREST, s = this.l.wrap === "repeat" ? t.REPEAT : t.CLAMP_TO_EDGE;
98
- return t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, r), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, r), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, s), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, s), this.I(), e;
97
+ D() {
98
+ const t = this.R;
99
+ if (t.bindFramebuffer(t.FRAMEBUFFER, this.M), this.A === 1) t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, this.S[0], 0);
100
+ else {
101
+ const s = [];
102
+ for (let r = 0; r < this.A; r++) {
103
+ const i = t.COLOR_ATTACHMENT0 + r;
104
+ t.framebufferTexture2D(t.FRAMEBUFFER, i, t.TEXTURE_2D, this.S[r], 0), s.push(i);
105
+ }
106
+ t.drawBuffers(s);
107
+ }
108
+ const e = t.checkFramebufferStatus(t.FRAMEBUFFER);
109
+ e !== t.FRAMEBUFFER_COMPLETE && console.error("GLFramebuffer is not complete:", e), t.bindFramebuffer(t.FRAMEBUFFER, null);
110
+ }
111
+ I(t) {
112
+ const e = this.R;
113
+ e.bindTexture(e.TEXTURE_2D, this.S[0]), e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, 1), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, t), e.bindTexture(e.TEXTURE_2D, null);
114
+ }
115
+ L(t, e) {
116
+ this.v = t, this.C = e, this.$ = null, this.F = Array(this.A).fill(null);
117
+ const s = this.R, r = this.l.type === "float" ? s.FLOAT : s.UNSIGNED_BYTE;
118
+ for (const i of this.S) s.bindTexture(s.TEXTURE_2D, i), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, this.v, this.C, 0, s.RGBA, r, null);
119
+ s.bindTexture(s.TEXTURE_2D, null);
120
+ }
121
+ W(t) {
122
+ const e = this.R;
123
+ if (t < 0 || t >= this.A) throw Error(`GLFramebuffer: attachment index ${t} out of range (count=${this.A})`);
124
+ const s = this.F[t];
125
+ if (s) return s;
126
+ const r = this.v, i = this.C, n = new Uint8Array(r * i * 4), o = e.getParameter(e.READ_FRAMEBUFFER_BINDING);
127
+ e.bindFramebuffer(e.READ_FRAMEBUFFER, this.M), e.readBuffer(e.COLOR_ATTACHMENT0 + t), e.readPixels(0, 0, r, i, e.RGBA, e.UNSIGNED_BYTE, n), e.bindFramebuffer(e.READ_FRAMEBUFFER, o);
128
+ const h = 4 * r, l = new Uint8Array(n.length);
129
+ for (let u = 0; u < i; u++) {
130
+ const f = (i - 1 - u) * h, d = u * h;
131
+ l.set(n.subarray(f, f + h), d);
132
+ }
133
+ return this.F[t] = l, l;
99
134
  }
100
- I() {
101
- const { v: t } = this, e = this.l.type === "float" ? t.FLOAT : t.UNSIGNED_BYTE;
102
- t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, this.F, this.M, 0, t.RGBA, e, null);
135
+ k() {
136
+ for (let t = 0; t < this.A; t++) this.W(t);
103
137
  }
104
138
  V() {
105
- const { v: t } = this;
106
- t.bindFramebuffer(t.FRAMEBUFFER, this.C), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, this.$, 0), t.bindFramebuffer(t.FRAMEBUFFER, null);
107
- }
108
- update(t) {
109
- const { v: e } = this;
110
- e.bindTexture(e.TEXTURE_2D, this.$), e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL, 1), e.texImage2D(e.TEXTURE_2D, 0, e.RGBA, e.RGBA, e.UNSIGNED_BYTE, t), e.bindTexture(e.TEXTURE_2D, null);
111
- }
112
- updatePixels(t, e, r) {
113
- const { v: s } = this;
114
- s.bindTexture(s.TEXTURE_2D, this.$), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, e, r, 0, s.RGBA, s.UNSIGNED_BYTE, t), s.bindTexture(s.TEXTURE_2D, null);
115
- }
116
- resize(t, e) {
117
- const { v: r } = this;
118
- this.F = t, this.M = e, this.S = null, r.bindTexture(r.TEXTURE_2D, this.$), this.I(), r.bindTexture(r.TEXTURE_2D, null);
119
- }
120
- begin() {
121
- const { v: t } = this;
122
- this.D = { framebuffer: t.getParameter(t.FRAMEBUFFER_BINDING), viewport: t.getParameter(t.VIEWPORT) }, t.bindFramebuffer(t.FRAMEBUFFER, this.C), t.viewport(0, 0, this.F, this.M), I(t, [0, 0, this.F, this.M]);
123
- }
124
- end() {
125
- if (!this.D) return;
126
- const { v: t } = this;
127
- t.bindFramebuffer(t.FRAMEBUFFER, this.D.framebuffer), t.viewport(...this.D.viewport), I(t, this.D.viewport), this.D = null;
128
- }
129
- loadPixels() {
130
- const { v: t } = this;
131
- this.S || (this.S = new Uint8Array(this.F * this.M * 4)), this.k(() => {
132
- t.readPixels(0, 0, this.F, this.M, t.RGBA, t.UNSIGNED_BYTE, this.S);
133
- });
139
+ const t = this.R;
140
+ this.P = { framebuffer: t.getParameter(t.FRAMEBUFFER_BINDING), viewport: t.getParameter(t.VIEWPORT) }, t.bindFramebuffer(t.FRAMEBUFFER, this.M), this.F = Array(this.A).fill(null);
141
+ for (let e = 0; e < this.A; e++) t.clearBufferfv(t.COLOR, e, new Float32Array([0, 0, 0, 0]));
142
+ t.viewport(0, 0, this.v, this.C), D(t, [0, 0, this.v, this.C]);
134
143
  }
135
- get(t, e, r, s) {
136
- const { v: i } = this;
137
- if (t === void 0 && e === void 0) {
138
- const o = new Uint8Array(this.F * this.M * 4);
139
- return this.k(() => (i.readPixels(0, 0, this.F, this.M, i.RGBA, i.UNSIGNED_BYTE, o), o));
140
- }
141
- if (r === void 0 && s === void 0) {
142
- (t < 0 || e < 0 || t >= this.F || e >= this.M) && (console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."), t = Math.max(0, Math.min(t, this.F - 1)), e = Math.max(0, Math.min(e, this.M - 1)));
143
- const o = new Uint8Array(4);
144
- return this.k(() => (i.readPixels(t, e, 1, 1, i.RGBA, i.UNSIGNED_BYTE, o), [o[0], o[1], o[2], o[3]]));
145
- }
146
- {
147
- t = Math.max(0, Math.min(t, this.F - 1)), e = Math.max(0, Math.min(e, this.M - 1)), r = Math.max(1, Math.min(r, this.F - t)), s = Math.max(1, Math.min(s, this.M - e));
148
- const o = new Uint8Array(r * s * 4);
149
- return this.k(() => (i.readPixels(t, e, r, s, i.RGBA, i.UNSIGNED_BYTE, o), o));
150
- }
144
+ O() {
145
+ if (!this.P) return;
146
+ const t = this.R;
147
+ t.bindFramebuffer(t.FRAMEBUFFER, this.P.framebuffer), t.viewport(...this.P.viewport), D(t, this.P.viewport), this.P = null;
151
148
  }
152
- P() {
153
- this.C && this.v.deleteFramebuffer(this.C), this.$ && this.v.deleteTexture(this.$);
149
+ U() {
150
+ const t = this.R;
151
+ this.M && t.deleteFramebuffer(this.M);
152
+ for (const e of this.S) t.deleteTexture(e);
153
+ this.S = [], this.F = [];
154
154
  }
155
- get framebuffer() {
155
+ get width() {
156
+ return this.v;
157
+ }
158
+ get height() {
156
159
  return this.C;
157
160
  }
158
- get texture() {
161
+ get pixels() {
159
162
  return this.$;
160
163
  }
161
- get width() {
162
- return this.F;
164
+ get options() {
165
+ return { ...this.l };
163
166
  }
164
- get height() {
167
+ get framebuffer() {
165
168
  return this.M;
166
169
  }
167
- get pixels() {
168
- return this.S;
170
+ get texture() {
171
+ return this.S[0];
169
172
  }
170
- }
171
- class R {
172
- constructor(t, e, r) {
173
- h(this, "v");
174
- h(this, "G");
175
- h(this, "A", /* @__PURE__ */ new Map());
176
- h(this, "U", /* @__PURE__ */ new Map());
177
- h(this, "L", 0);
178
- h(this, "H");
179
- this.v = t, this.G = this.j(e, r), this.H = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS), this.O();
173
+ get textures() {
174
+ return [...this.S];
180
175
  }
181
- O() {
182
- const t = this.v.getProgramParameter(this.G, this.v.ACTIVE_UNIFORMS);
176
+ get attachmentCount() {
177
+ return this.A;
178
+ }
179
+ getAttachmentPixels(t) {
180
+ return this.F[t] ?? null;
181
+ }
182
+ }
183
+ class K {
184
+ constructor(t, e, s) {
185
+ c(this, "R");
186
+ c(this, "j");
187
+ c(this, "H", /* @__PURE__ */ new Map());
188
+ c(this, "q", /* @__PURE__ */ new Map());
189
+ c(this, "N", 0);
190
+ c(this, "X");
191
+ this.R = t, this.j = this.Y(e, s), this.X = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS), this.Z();
192
+ }
193
+ Z() {
194
+ const t = this.R.getProgramParameter(this.j, this.R.ACTIVE_UNIFORMS);
183
195
  for (let e = 0; e < t; e++) {
184
- const r = this.v.getActiveUniform(this.G, e);
185
- if (r) {
186
- const s = this.v.getUniformLocation(this.G, r.name);
187
- s && (this.A.set(r.name, s), this.U.set(r.name, r.type));
196
+ const s = this.R.getActiveUniform(this.j, e);
197
+ if (s) {
198
+ const r = this.R.getUniformLocation(this.j, s.name);
199
+ r && (this.H.set(s.name, r), this.q.set(s.name, s.type));
188
200
  }
189
201
  }
190
202
  }
191
- j(t, e) {
192
- const r = this.W(this.v.VERTEX_SHADER, t), s = this.W(this.v.FRAGMENT_SHADER, e), i = this.v.createProgram();
193
- if (this.v.attachShader(i, r), this.v.attachShader(i, s), this.v.linkProgram(i), !this.v.getProgramParameter(i, this.v.LINK_STATUS)) {
194
- const o = this.v.getProgramInfoLog(i);
195
- throw Error("Shader program link error: " + o);
203
+ Y(t, e) {
204
+ const s = this.J(this.R.VERTEX_SHADER, t), r = this.J(this.R.FRAGMENT_SHADER, e), i = this.R.createProgram();
205
+ if (this.R.attachShader(i, s), this.R.attachShader(i, r), this.R.linkProgram(i), !this.R.getProgramParameter(i, this.R.LINK_STATUS)) {
206
+ const n = this.R.getProgramInfoLog(i);
207
+ throw Error("Shader program link error: " + n);
196
208
  }
197
- return this.v.deleteShader(r), this.v.deleteShader(s), i;
209
+ return this.R.deleteShader(s), this.R.deleteShader(r), i;
198
210
  }
199
- W(t, e) {
200
- const r = this.v.createShader(t);
201
- if (this.v.shaderSource(r, e), this.v.compileShader(r), !this.v.getShaderParameter(r, this.v.COMPILE_STATUS)) {
202
- const s = this.v.getShaderInfoLog(r);
203
- throw this.v.deleteShader(r), Error("Shader compilation error: " + s);
211
+ J(t, e) {
212
+ const s = this.R.createShader(t);
213
+ if (this.R.shaderSource(s, e), this.R.compileShader(s), !this.R.getShaderParameter(s, this.R.COMPILE_STATUS)) {
214
+ const r = this.R.getShaderInfoLog(s);
215
+ throw this.R.deleteShader(s), Error("Shader compilation error: " + r);
204
216
  }
205
- return r;
217
+ return s;
218
+ }
219
+ K() {
220
+ this.R.useProgram(this.j), this.tt();
206
221
  }
207
- N() {
208
- this.v.useProgram(this.G), this.X();
222
+ tt() {
223
+ this.N = 0;
224
+ }
225
+ et(t) {
226
+ for (const [e, s] of Object.entries(t)) this.st(e, s);
209
227
  }
210
- setUniform(t, e) {
211
- const r = this.A.get(t);
212
- if (r) if (typeof e == "number")
213
- this.q(t) ? this.v.uniform1i(r, Math.floor(e)) : this.v.uniform1f(r, e);
214
- else if (typeof e == "boolean") this.v.uniform1i(r, e ? 1 : 0);
228
+ st(t, e) {
229
+ const s = this.H.get(t);
230
+ if (s) if (typeof e == "number") this.R.uniform1f(s, e);
231
+ else if (typeof e == "boolean") this.R.uniform1i(s, e ? 1 : 0);
215
232
  else if (Array.isArray(e)) switch (e.length) {
216
233
  case 2:
217
- this.v.uniform2f(r, e[0], e[1]);
234
+ this.R.uniform2f(s, e[0], e[1]);
218
235
  break;
219
236
  case 3:
220
- this.v.uniform3f(r, e[0], e[1], e[2]);
237
+ this.R.uniform3f(s, e[0], e[1], e[2]);
221
238
  break;
222
239
  case 4:
223
- this.v.uniform4f(r, e[0], e[1], e[2], e[3]);
240
+ this.R.uniform4f(s, e[0], e[1], e[2], e[3]);
224
241
  break;
225
242
  default:
226
243
  console.warn(`Unsupported array length ${e.length} for uniform '${t}'`);
227
244
  }
228
245
  else if (e instanceof WebGLTexture) {
229
- const s = this.Y();
230
- this.v.uniform1i(r, s), this.v.activeTexture(this.v.TEXTURE0 + s), this.v.bindTexture(this.v.TEXTURE_2D, e);
231
- } else if (e instanceof J) {
232
- const s = this.Y();
233
- this.v.uniform1i(r, s), this.v.activeTexture(this.v.TEXTURE0 + s), this.v.bindTexture(this.v.TEXTURE_2D, e.texture);
246
+ const r = this.it();
247
+ this.R.uniform1i(s, r), this.R.activeTexture(this.R.TEXTURE0 + r), this.R.bindTexture(this.R.TEXTURE_2D, e);
248
+ } else if (e instanceof Y) {
249
+ const r = this.it();
250
+ this.R.uniform1i(s, r), this.R.activeTexture(this.R.TEXTURE0 + r), this.R.bindTexture(this.R.TEXTURE_2D, e.texture);
251
+ } else if (typeof e == "object" && "texture" in e) {
252
+ const r = this.it();
253
+ this.R.uniform1i(s, r), this.R.activeTexture(this.R.TEXTURE0 + r), this.R.bindTexture(this.R.TEXTURE_2D, e.texture);
234
254
  } else console.warn(`Unsupported uniform type for '${t}':`, typeof e);
235
255
  }
236
- Y() {
237
- return this.L >= this.H && console.warn(`Exceeded maximum texture units (${this.H}). Texture may not render correctly.`), this.L++;
238
- }
239
- q(t) {
240
- const e = this.U.get(t);
241
- return !!e && (e === this.v.INT || e === this.v.INT_VEC2 || e === this.v.INT_VEC3 || e === this.v.INT_VEC4 || e === this.v.SAMPLER_2D || e === this.v.SAMPLER_CUBE);
242
- }
243
- get glProgram() {
244
- return this.G;
256
+ it() {
257
+ return this.N >= this.X && console.warn(`Exceeded maximum texture units (${this.X}). Texture may not render correctly.`), this.N++;
245
258
  }
246
- P() {
247
- this.v.deleteProgram(this.G);
259
+ get rt() {
260
+ return this.j;
248
261
  }
249
- X() {
250
- this.L = 0;
262
+ U() {
263
+ this.R.deleteProgram(this.j);
251
264
  }
252
265
  }
253
266
  class Q {
254
- constructor(t) {
255
- h(this, "v");
256
- h(this, "Z", null);
257
- h(this, "J", 16);
258
- h(this, "K", /* @__PURE__ */ new Map());
259
- this.v = t;
267
+ constructor() {
268
+ c(this, "nt", 1);
269
+ c(this, "ot", 0);
270
+ c(this, "ht", [0, 0, 0]);
271
+ c(this, "ct", [1, 1, 1, 1]);
272
+ c(this, "lt", [0, 0, 0, 1]);
273
+ c(this, "ut", !1);
274
+ c(this, "ft", !1);
275
+ c(this, "dt", !1);
276
+ c(this, "gt", [0, 0]);
277
+ c(this, "_t", []);
278
+ }
279
+ vt() {
280
+ this._t.push({ lineWeight: this.nt, rotation: this.ot, charRotation: [...this.gt], flipHorizontally: this.ut, flipVertically: this.ft, invert: this.dt, character: [...this.ht], charColor: [...this.ct], cellColor: [...this.lt] });
281
+ }
282
+ xt() {
283
+ const t = this._t.pop();
284
+ t ? (this.nt = t.lineWeight, this.ot = t.rotation, this.gt = t.charRotation, this.ut = t.flipHorizontally, this.ft = t.flipVertically, this.dt = t.invert, this.ht = t.character, this.ct = t.charColor, this.lt = t.cellColor) : console.warn("pop() called without matching push()");
285
+ }
286
+ Ct() {
287
+ this._t = [], this.ot = 0;
260
288
  }
261
- tt() {
262
- if (this.Z) return;
263
- const t = this.v;
264
- this.Z = t.createBuffer(), t.bindBuffer(t.ARRAY_BUFFER, this.Z);
289
+ yt(t) {
290
+ t.lineWeight = this.nt, t.rotation = this.ot, t.character[0] = this.ht[0], t.character[1] = this.ht[1], t.character[2] = this.ht[2], t.charColor[0] = this.ct[0], t.charColor[1] = this.ct[1], t.charColor[2] = this.ct[2], t.charColor[3] = this.ct[3], t.bgColor[0] = this.lt[0], t.bgColor[1] = this.lt[1], t.bgColor[2] = this.lt[2], t.bgColor[3] = this.lt[3], t.flipHorizontally = this.ut, t.flipVertically = this.ft, t.invert = this.dt, t.charRotation[0] = this.gt[0], t.charRotation[1] = this.gt[1];
265
291
  }
266
- et() {
267
- const t = this.v, e = t.getParameter(t.CURRENT_PROGRAM);
268
- let r = this.K.get(e);
269
- return r || (r = { a_position: t.getAttribLocation(e, "a_position"), a_texCoord: t.getAttribLocation(e, "a_texCoord") }, this.K.set(e, r)), t.enableVertexAttribArray(r.a_position), t.vertexAttribPointer(r.a_position, 2, t.FLOAT, !1, this.J, 0), t.enableVertexAttribArray(r.a_texCoord), t.vertexAttribPointer(r.a_texCoord, 2, t.FLOAT, !1, this.J, 8), { positionLoc: r.a_position, texLoc: r.a_texCoord };
292
+ get lineWeight() {
293
+ return this.nt;
270
294
  }
271
- rt(t, e) {
272
- const r = this.v;
273
- r.disableVertexAttribArray(t), r.disableVertexAttribArray(e);
295
+ get rotation() {
296
+ return this.ot;
274
297
  }
275
- st(t, e) {
276
- const r = this.v, s = Z(r) || [0, 0, r.canvas.width, r.canvas.height];
277
- return { nx: t / s[2] * 2 - 1, ny: 1 - e / s[3] * 2 };
298
+ get character() {
299
+ return this.ht;
300
+ }
301
+ get charColor() {
302
+ return this.ct;
303
+ }
304
+ get bgColor() {
305
+ return this.lt;
306
+ }
307
+ get flipHorizontally() {
308
+ return this.ut;
309
+ }
310
+ get flipVertically() {
311
+ return this.ft;
312
+ }
313
+ get invert() {
314
+ return this.dt;
315
+ }
316
+ get charRotation() {
317
+ return this.gt;
318
+ }
319
+ wt(t) {
320
+ this.nt = Math.abs(t);
321
+ }
322
+ $t(t) {
323
+ this.ot = t;
324
+ }
325
+ bt(t) {
326
+ this.ht = t;
278
327
  }
279
- it(t, e, r, s) {
280
- const i = this.v;
281
- this.tt(), i.bindBuffer(i.ARRAY_BUFFER, this.Z);
282
- const o = new Float32Array([t, s, 0, 0, r, s, 1, 0, t, e, 0, 1, t, e, 0, 1, r, s, 1, 0, r, e, 1, 1]);
283
- i.bufferData(i.ARRAY_BUFFER, o, i.DYNAMIC_DRAW);
328
+ Tt(t, e, s, r = 255) {
329
+ this.ct = [t / 255, e / 255, s / 255, r / 255];
284
330
  }
285
- P() {
286
- this.Z && this.v.deleteBuffer(this.Z);
331
+ zt(t, e, s, r = 255) {
332
+ this.lt = [t / 255, e / 255, s / 255, r / 255];
333
+ }
334
+ Rt(t) {
335
+ this.ut = t;
336
+ }
337
+ Mt(t) {
338
+ this.ft = t;
339
+ }
340
+ St(t) {
341
+ this.dt = t;
342
+ }
343
+ At(t) {
344
+ const e = 255 * t / 360, s = Math.floor(e) / 255, r = Math.round(e - Math.floor(e));
345
+ this.gt = [s, r];
287
346
  }
288
347
  }
289
- class st extends Q {
348
+ var R = ((a) => (a.RECTANGLE = "rectangle", a.LINE = "line", a.ELLIPSE = "ellipse", a.ARC = "arc", a.TRIANGLE = "triangle", a.BEZIER_CURVE = "bezier_curve", a.CUSTOM = "custom", a))(R || {});
349
+ class tt {
290
350
  constructor(t) {
291
- super(t);
351
+ c(this, "R");
352
+ c(this, "Pt", /* @__PURE__ */ new Map());
353
+ this.R = t;
354
+ }
355
+ Ft(t, e, s, r) {
356
+ const i = this.R;
357
+ let n = this.Pt.get(t);
358
+ n || (n = /* @__PURE__ */ new Map(), this.Pt.set(t, n));
359
+ let o = n.get(e) || null;
360
+ if (!o) {
361
+ o = i.createVertexArray(), n.set(e, o), i.bindVertexArray(o), i.bindBuffer(i.ARRAY_BUFFER, r);
362
+ const h = i.getAttribLocation(t, "a_position");
363
+ h !== -1 && (i.enableVertexAttribArray(h), i.vertexAttribPointer(h, s.attributes.position.size, i.FLOAT, !1, s.stride, s.attributes.position.offset), i.vertexAttribDivisor(h, 0));
364
+ const l = i.getAttribLocation(t, "a_texCoord");
365
+ l !== -1 && (i.enableVertexAttribArray(l), i.vertexAttribPointer(l, s.attributes.texCoord.size, i.FLOAT, !1, s.stride, s.attributes.texCoord.offset), i.vertexAttribDivisor(l, 0));
366
+ }
367
+ i.bindVertexArray(o);
292
368
  }
293
- ot(t, e, r, s) {
294
- const i = this.st(t, e), o = this.st(t + r, e + s);
295
- this.it(i.nx, i.ny, o.nx, o.ny);
296
- const n = this.et();
297
- this.v.drawArrays(this.v.TRIANGLES, 0, 6), this.rt(n.positionLoc, n.texLoc);
369
+ Gt() {
370
+ this.R.bindVertexArray(null);
298
371
  }
299
- nt(t, e, r, s, i) {
300
- this.ot(t, e, r, i), this.ot(t + r - i, e, i, s), this.ot(t, e + s - i, r, i), this.ot(t, e, i, s);
372
+ U() {
373
+ const t = this.R;
374
+ for (const [, e] of this.Pt) for (const [, s] of e) s && t.deleteVertexArray(s);
375
+ this.Pt.clear();
301
376
  }
302
377
  }
303
- class it extends Q {
378
+ class et {
304
379
  constructor(t) {
305
- super(t);
306
- }
307
- ht(t, e, r, s, i) {
308
- const o = r - t, n = s - e, l = Math.hypot(o, n);
309
- if (l === 0) {
310
- const u = i / 2, f = this.st(t - u, e - u), d = this.st(t + u, e + u);
311
- this.it(f.nx, f.ny, d.nx, d.ny);
312
- } else {
313
- const u = -n / l, f = o / l, d = i / 2, m = t + u * d, p = e + f * d, g = t - u * d, C = e - f * d, v = r + u * d, b = s + f * d, T = r - u * d, E = s - f * d, M = this.st(m, p), F = this.st(g, C), A = this.st(v, b), W = this.st(T, E), S = this.v;
314
- this.tt(), S.bindBuffer(S.ARRAY_BUFFER, this.Z);
315
- const K = new Float32Array([M.nx, M.ny, 0, 0, F.nx, F.ny, 0, 1, A.nx, A.ny, 1, 0, F.nx, F.ny, 0, 1, W.nx, W.ny, 1, 1, A.nx, A.ny, 1, 0]);
316
- S.bufferData(S.ARRAY_BUFFER, K, S.DYNAMIC_DRAW);
380
+ c(this, "Dt");
381
+ c(this, "R");
382
+ this.R = t, this.Dt = new tt(t);
383
+ }
384
+ It(t, e, s) {
385
+ const { shader: r } = t, i = L(this.R) || this.R.getParameter(this.R.VIEWPORT);
386
+ r.et({ u_aspectRatio: i[2] / i[3], u_viewportSize: [i[2], i[3]] });
387
+ const n = (l) => {
388
+ if (!l || !l.Bt()) return;
389
+ const u = l.unitGeometry, f = l.unitBuffer;
390
+ try {
391
+ this.Dt.Ft(r.rt, l.type + "", u, f), l.batch.Lt(r), l.batch.Et(u.primitiveType, u.vertexCount);
392
+ } finally {
393
+ l.batch.Wt(r), this.Dt.Gt(), l.kt();
394
+ }
395
+ };
396
+ let o = null, h = null;
397
+ for (const l of e) {
398
+ o !== null && l.type !== o && (n(h), o = null, h = null);
399
+ let u = h;
400
+ u && l.type === o || (u = s.get(l.type) || null, h = u, o = l.type), u && u.Vt(l.params, l.state);
317
401
  }
318
- const c = this.et();
319
- this.v.drawArrays(this.v.TRIANGLES, 0, 6), this.rt(c.positionLoc, c.texLoc);
402
+ n(h);
320
403
  }
321
404
  }
322
- var $ = "attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}";
323
- class ot {
324
- constructor(t) {
325
- h(this, "v");
326
- h(this, "lt");
327
- h(this, "ct");
328
- h(this, "ut", null);
329
- h(this, "ft");
330
- h(this, "dt");
331
- h(this, "gt", [1, 1, 1, 1]);
332
- h(this, "_t", !0);
333
- h(this, "vt", [0, 0, 0, 1]);
334
- h(this, "xt", 1);
335
- h(this, "bt", !0);
336
- h(this, "wt", 0);
337
- h(this, "Ct", []);
338
- this.v = t, this.lt = new R(this.v, $, "precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"), this.ct = new R(this.v, $, "precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"), this.ft = new st(this.v), this.dt = new it(this.v), this.v.enable(this.v.BLEND), this.v.blendEquation(this.v.FUNC_ADD), this.v.blendFunc(this.v.ONE, this.v.ONE_MINUS_SRC_ALPHA), I(this.v, [0, 0, this.v.canvas.width, this.v.canvas.height]);
405
+ class st {
406
+ constructor() {
407
+ c(this, "Ot", []);
408
+ c(this, "Ut", 1);
409
+ c(this, "jt", 0);
410
+ }
411
+ Ht(t) {
412
+ if (this.jt >= this.Ot.length) {
413
+ const s = { id: this.Ut++, type: t, params: {}, state: { lineWeight: 1, rotation: 0, character: [0, 0, 0], charColor: [1, 1, 1, 1], bgColor: [0, 0, 0, 1], flipHorizontally: !1, flipVertically: !1, invert: !1, charRotation: [0, 0] } };
414
+ this.Ot.push(s);
415
+ }
416
+ const e = this.Ot[this.jt];
417
+ switch (e.id = this.Ut++, e.type = t, t) {
418
+ case R.RECTANGLE:
419
+ case R.ELLIPSE:
420
+ e.params && "width" in e.params || (e.params = { x: 0, y: 0, width: 0, height: 0 });
421
+ break;
422
+ case R.ARC:
423
+ e.params && "start" in e.params || (e.params = { x: 0, y: 0, width: 0, height: 0, start: 0, stop: 0 });
424
+ break;
425
+ case R.LINE:
426
+ e.params && "x2" in e.params || (e.params = { x1: 0, y1: 0, x2: 0, y2: 0, thickness: void 0 });
427
+ break;
428
+ case R.TRIANGLE:
429
+ e.params && "x3" in e.params || (e.params = { x1: 0, y1: 0, x2: 0, y2: 0, x3: 0, y3: 0 });
430
+ break;
431
+ case R.BEZIER_CURVE:
432
+ e.params && "cp2y" in e.params || (e.params = { x1: 0, y1: 0, cp1x: 0, cp1y: 0, cp2x: 0, cp2y: 0, x2: 0, y2: 0, thickness: void 0 });
433
+ break;
434
+ default:
435
+ e.params || (e.params = {});
436
+ }
437
+ return this.jt++, e;
339
438
  }
340
- yt(t) {
341
- this.ut !== t && (this.ut = t, t.N());
439
+ qt(t, e, s, r, i) {
440
+ const n = this.Ht(R.RECTANGLE);
441
+ return n.params.x = t, n.params.y = e, n.params.width = s, n.params.height = r, i.yt(n.state), n.id;
342
442
  }
343
- $t(t, e, r, s) {
344
- if (this._t = !0, e === void 0 && r === void 0 && s === void 0) {
345
- const i = t / 255;
346
- this.gt = [i, i, i, 1];
347
- } else if (r !== void 0 && s === void 0) this.gt = [t / 255, e / 255, r / 255, 1];
348
- else {
349
- if (r === void 0 || s === void 0) throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");
350
- this.gt = [t / 255, e / 255, r / 255, s / 255];
351
- }
443
+ Nt(t, e, s, r, i, n) {
444
+ const o = this.Ht(R.LINE);
445
+ return o.params.x1 = t, o.params.y1 = e, o.params.x2 = s, o.params.y2 = r, o.params.thickness = i, n.yt(o.state), o.id;
352
446
  }
353
- Ft(t, e, r, s) {
354
- if (this.bt = !0, e === void 0 && r === void 0 && s === void 0) {
355
- const i = t / 255;
356
- this.vt = [i, i, i, 1];
357
- } else if (r !== void 0 && s === void 0) this.vt = [t / 255, e / 255, r / 255, 1];
358
- else {
359
- if (r === void 0 || s === void 0) throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");
360
- this.vt = [t / 255, e / 255, r / 255, s / 255];
447
+ Xt(t, e, s, r, i) {
448
+ const n = this.Ht(R.ELLIPSE);
449
+ return n.params.x = t, n.params.y = e, n.params.width = s, n.params.height = r, i.yt(n.state), n.id;
450
+ }
451
+ Yt(t, e, s, r, i, n, o) {
452
+ const h = this.Ht(R.ARC);
453
+ return h.params.x = t, h.params.y = e, h.params.width = s, h.params.height = r, h.params.start = i, h.params.stop = n, o.yt(h.state), h.id;
454
+ }
455
+ Qt(t, e, s, r, i, n, o) {
456
+ const h = this.Ht(R.TRIANGLE);
457
+ return h.params.x1 = t, h.params.y1 = e, h.params.x2 = s, h.params.y2 = r, h.params.x3 = i, h.params.y3 = n, o.yt(h.state), h.id;
458
+ }
459
+ Zt(t, e, s, r, i, n, o, h, l, u) {
460
+ const f = this.Ht(R.BEZIER_CURVE);
461
+ return f.params.x1 = t, f.params.y1 = e, f.params.cp1x = s, f.params.cp1y = r, f.params.cp2x = i, f.params.cp2y = n, f.params.x2 = o, f.params.y2 = h, f.params.thickness = l, u.yt(f.state), f.id;
462
+ }
463
+ get length() {
464
+ return this.jt;
465
+ }
466
+ get isEmpty() {
467
+ return this.jt === 0;
468
+ }
469
+ Jt() {
470
+ this.jt = 0;
471
+ }
472
+ [Symbol.iterator]() {
473
+ let t = 0;
474
+ const e = this.jt, s = this.Ot;
475
+ return { next: () => t < e ? { value: s[t++], done: !1 } : { value: void 0, done: !0 } };
476
+ }
477
+ }
478
+ const A = class A {
479
+ static Kt(t, e, s = 0) {
480
+ var n, o, h, l, u, f, d, p, g, m;
481
+ const r = e || new Float32Array(A.FLOATS_PER_INSTANCE);
482
+ let i = s;
483
+ return r[i++] = t.position[0], r[i++] = t.position[1], r[i++] = t.size[0], r[i++] = t.size[1], r[i++] = t.character[0], r[i++] = t.character[1], r[i++] = t.character[2], r[i++] = t.primaryColor[0], r[i++] = t.primaryColor[1], r[i++] = t.primaryColor[2], r[i++] = t.primaryColor[3], r[i++] = t.secondaryColor[0], r[i++] = t.secondaryColor[1], r[i++] = t.secondaryColor[2], r[i++] = t.secondaryColor[3], r[i++] = t.rotation[0], r[i++] = t.rotation[1], r[i++] = t.transform[0], r[i++] = t.transform[1], r[i++] = t.transform[2], r[i++] = t.globalRotation, r[i++] = t.rotationCenter[0], r[i++] = t.rotationCenter[1], r[i++] = ((n = t.arcAngles) == null ? void 0 : n[0]) || 0, r[i++] = ((o = t.arcAngles) == null ? void 0 : o[1]) || 0, r[i++] = ((h = t.bezierControlPoint1) == null ? void 0 : h[0]) || 0, r[i++] = ((l = t.bezierControlPoint1) == null ? void 0 : l[1]) || 0, r[i++] = ((u = t.bezierControlPoint2) == null ? void 0 : u[0]) || 0, r[i++] = ((f = t.bezierControlPoint2) == null ? void 0 : f[1]) || 0, r[i++] = ((d = t.bezierStartPoint) == null ? void 0 : d[0]) || 0, r[i++] = ((p = t.bezierStartPoint) == null ? void 0 : p[1]) || 0, r[i++] = ((g = t.bezierEndPoint) == null ? void 0 : g[0]) || 0, r[i++] = ((m = t.bezierEndPoint) == null ? void 0 : m[1]) || 0, r;
484
+ }
485
+ static te(t) {
486
+ const e = t.length * A.FLOATS_PER_INSTANCE, s = new Float32Array(e);
487
+ for (let r = 0; r < t.length; r++) {
488
+ const i = r * A.FLOATS_PER_INSTANCE;
489
+ A.Kt(t[r], s, i);
361
490
  }
491
+ return s;
362
492
  }
363
- Tt(t) {
364
- if (t < 0) throw Error("Stroke weight must be non-negative");
365
- this.xt = t;
493
+ };
494
+ c(A, "BYTES_PER_INSTANCE", 132), c(A, "FLOATS_PER_INSTANCE", 33);
495
+ let P = A;
496
+ const x = class x {
497
+ };
498
+ c(x, "STRIDE", P.BYTES_PER_INSTANCE), c(x, "ATTRIBUTES", { a_instancePosition: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 0, divisor: 1 }, a_instanceSize: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 8, divisor: 1 }, a_instanceCharacter: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 16, divisor: 1 }, a_instancePrimaryColor: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 28, divisor: 1 }, a_instanceSecondaryColor: { location: -1, size: 4, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 44, divisor: 1 }, a_instanceRotation: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 60, divisor: 1 }, a_instanceTransform: { location: -1, size: 3, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 68, divisor: 1 }, a_instanceGlobalRotation: { location: -1, size: 1, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 80, divisor: 1 }, a_instanceRotationCenter: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 84, divisor: 1 }, a_instanceArcAngles: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 92, divisor: 1 }, a_instanceBezierCP1: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 100, divisor: 1 }, a_instanceBezierCP2: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 108, divisor: 1 }, a_instanceBezierStart: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 116, divisor: 1 }, a_instanceBezierEnd: { location: -1, size: 2, type: WebGL2RenderingContext.FLOAT, normalized: !1, stride: x.STRIDE, offset: 124, divisor: 1 } });
499
+ let M = x;
500
+ class rt {
501
+ constructor(t, e = 1e3, s = 1.5) {
502
+ c(this, "R");
503
+ c(this, "ee", []);
504
+ c(this, "se");
505
+ c(this, "ie");
506
+ c(this, "re", null);
507
+ c(this, "ne", !0);
508
+ c(this, "oe", 0);
509
+ c(this, "ae", /* @__PURE__ */ new Map());
510
+ c(this, "he", null);
511
+ this.R = t, this.se = e, this.ie = s, this.ce();
512
+ }
513
+ Vt(t) {
514
+ const e = this.ee.length;
515
+ return this.ee.push(t), this.ne = !0, e;
516
+ }
517
+ get count() {
518
+ return this.ee.length;
519
+ }
520
+ get isEmpty() {
521
+ return this.ee.length === 0;
366
522
  }
367
- Mt() {
368
- this.bt = !1;
523
+ clear() {
524
+ this.ee.length = 0, this.ne = !0;
525
+ }
526
+ le(t) {
527
+ if (t <= this.se) return;
528
+ const e = Math.ceil(t * this.ie);
529
+ this.se = e, this.ce(), console.log(`InstanceBatch: Grew buffer capacity to ${e} instances`);
530
+ }
531
+ ce() {
532
+ const t = this.R;
533
+ if (this.re && t.deleteBuffer(this.re), this.re = t.createBuffer(), !this.re) throw Error("Failed to create instance buffer");
534
+ const e = this.se * P.BYTES_PER_INSTANCE;
535
+ t.bindBuffer(t.ARRAY_BUFFER, this.re), t.bufferData(t.ARRAY_BUFFER, e, t.DYNAMIC_DRAW), t.bindBuffer(t.ARRAY_BUFFER, null), this.ne = !0, this.oe = 0;
536
+ }
537
+ ue() {
538
+ if (!this.ne || this.ee.length === 0) return;
539
+ const t = this.R, e = this.ee.length;
540
+ this.le(e), (!this.he || this.he.length < e * P.FLOATS_PER_INSTANCE) && (this.he = new Float32Array(e * P.FLOATS_PER_INSTANCE));
541
+ const s = P.te(this.ee);
542
+ t.bindBuffer(t.ARRAY_BUFFER, this.re), e <= this.oe ? t.bufferSubData(t.ARRAY_BUFFER, 0, s) : t.bufferData(t.ARRAY_BUFFER, s, t.DYNAMIC_DRAW), t.bindBuffer(t.ARRAY_BUFFER, null), this.ne = !1, this.oe = e;
369
543
  }
370
- Dt() {
371
- this._t = !1;
544
+ fe(t) {
545
+ let e = this.ae.get(t);
546
+ if (!e) {
547
+ e = /* @__PURE__ */ new Map();
548
+ const s = this.R;
549
+ for (const r in M.ATTRIBUTES) {
550
+ const i = s.getAttribLocation(t, r);
551
+ i !== -1 && e.set(r, i);
552
+ }
553
+ this.ae.set(t, e);
554
+ }
555
+ return e;
372
556
  }
373
- St(t) {
374
- this.wt = t;
557
+ Lt(t) {
558
+ if (!this.re || this.ee.length === 0) return;
559
+ const e = this.R, s = t.rt;
560
+ if (!s) return void console.warn("InstanceBatch: Cannot bind attributes - invalid shader program");
561
+ this.ue();
562
+ const r = this.fe(s);
563
+ e.bindBuffer(e.ARRAY_BUFFER, this.re);
564
+ for (const [i, n] of r) {
565
+ const o = M.ATTRIBUTES[i];
566
+ o && (e.enableVertexAttribArray(n), e.vertexAttribPointer(n, o.size, o.type, o.normalized, o.stride, o.offset), e.vertexAttribDivisor(n, o.divisor));
567
+ }
375
568
  }
376
- Rt() {
377
- this.Ct.push({ fillColor: [...this.gt], fillMode: this._t, strokeColor: [...this.vt], strokeWeight: this.xt, strokeMode: this.bt, rotation: this.wt });
569
+ Wt(t) {
570
+ const e = this.R, s = this.fe(t.rt);
571
+ for (const [, r] of s) e.disableVertexAttribArray(r), e.vertexAttribDivisor(r, 0);
378
572
  }
379
- Vt() {
380
- const t = this.Ct.pop();
381
- t ? (this.gt = t.fillColor, this._t = t.fillMode, this.vt = t.strokeColor, this.xt = t.strokeWeight, this.bt = t.strokeMode, this.wt = t.rotation) : console.warn("pop() called without matching push()");
573
+ Et(t, e) {
574
+ this.ee.length !== 0 && this.R.drawArraysInstanced(t, 0, e, this.ee.length);
575
+ }
576
+ U() {
577
+ const t = this.R;
578
+ this.re && (t.deleteBuffer(this.re), this.re = null), this.ee.length = 0, this.ae.clear(), this.he = null;
579
+ }
580
+ }
581
+ class F {
582
+ constructor(t, e, s, r) {
583
+ c(this, "R");
584
+ c(this, "de");
585
+ c(this, "pe");
586
+ c(this, "ge");
587
+ c(this, "_e", null);
588
+ this.R = t, this.de = e, this.pe = s, this.ge = r;
589
+ const i = this.R.createBuffer();
590
+ if (!i) throw Error("Failed to create unit geometry buffer");
591
+ this.R.bindBuffer(this.R.ARRAY_BUFFER, i), this.R.bufferData(this.R.ARRAY_BUFFER, this.ge.vertices, this.R.STATIC_DRAW), this.R.bindBuffer(this.R.ARRAY_BUFFER, null), this._e = i;
592
+ }
593
+ get type() {
594
+ return this.pe;
595
+ }
596
+ get unitGeometry() {
597
+ return this.ge;
598
+ }
599
+ get unitBuffer() {
600
+ return this._e;
601
+ }
602
+ get batch() {
603
+ return this.de;
382
604
  }
383
605
  kt() {
384
- this.ut = null, this.Ct = [], this.wt = 0;
606
+ this.de.clear();
385
607
  }
386
- It(t) {
387
- const e = t.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").trim().match(/^#version\s+(\d+)\s+(es)?/i);
388
- return e ? parseInt(e[1], 10) >= 300 : !1;
608
+ Bt() {
609
+ return !this.de.isEmpty;
389
610
  }
390
- Pt(t, e) {
391
- return new R(this.v, t, e);
611
+ U() {
612
+ this.de.U(), this._e && (this.R.deleteBuffer(this._e), this._e = null);
392
613
  }
393
- zt(t) {
394
- const e = this.It(t) ? `#version 300 es
395
- in vec2 a_position;in vec2 a_texCoord;out vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}` : $;
396
- return new R(this.v, e, t);
614
+ me(t, e, s, r, i) {
615
+ const n = this.ve(t, e, s, r, i.rotation || 0);
616
+ return { position: [t, e], size: [s, r], character: i.character || [0, 0, 0], primaryColor: i.charColor || [1, 1, 1, 1], secondaryColor: i.bgColor || [0, 0, 0, 1], rotation: i.charRotation || [0, 0], transform: [i.invert ? 1 : 0, i.flipHorizontally ? 1 : 0, i.flipVertically ? 1 : 0], globalRotation: n.radians, rotationCenter: [n.centerX, n.centerY] };
397
617
  }
398
- Et(t, e) {
399
- this.ut.setUniform(t, e);
618
+ xe(t, e) {
619
+ const s = L(this.R) || [0, 0, this.R.canvas.width, this.R.canvas.height];
620
+ return { nx: t / s[2] * 2 - 1, ny: 1 - e / s[3] * 2 };
400
621
  }
401
- Gt(t, e, r, s) {
402
- if (this.ut !== null) {
403
- const { centerX: f, centerY: d, radians: m, aspectRatio: p } = this.At(t, e, r, s);
404
- return this.Et("u_rotation", m), this.Et("u_center", [f, d]), this.Et("u_aspectRatio", p), this.ft.ot(t, e, r, s), void (this.ut = null);
405
- }
406
- const i = this.ct;
407
- let o = 0, n = 0, l = 0, c = 1;
408
- const u = this.At(t, e, r, s);
409
- o = u.centerX, n = u.centerY, l = u.radians, c = u.aspectRatio, this._t && (this.yt(i), this.Et("u_color", this.gt), this.Et("u_rotation", l), this.Et("u_center", [o, n]), this.Et("u_aspectRatio", c), this.ft.ot(t, e, r, s)), this.bt && this.xt > 0 && (this.yt(i), this.Et("u_color", this.vt), this.Et("u_rotation", l), this.Et("u_center", [o, n]), this.Et("u_aspectRatio", c), this.ft.nt(t, e, r, s, this.xt)), this.ut = null;
410
- }
411
- Ut(t, e, r, s) {
412
- if (this.ut !== null) {
413
- const g = (t + r) / 2, C = (e + s) / 2, v = Math.abs(r - t) || 1, b = Math.abs(s - e) || 1, { centerX: T, centerY: E, radians: M, aspectRatio: F } = this.At(g - v / 2, C - b / 2, v, b);
414
- this.Et("u_rotation", M), this.Et("u_center", [T, E]), this.Et("u_aspectRatio", F);
415
- const A = this.xt > 0 ? this.xt : 1;
416
- return this.dt.ht(t, e, r, s, A), void (this.ut = null);
417
- }
418
- if (!this.bt || this.xt <= 0) return;
419
- const i = this.ct, o = (t + r) / 2, n = (e + s) / 2, l = Math.abs(r - t) || 1, c = Math.abs(s - e) || 1, u = this.wt !== 0;
420
- let f = 0, d = 0, m = 0, p = 1;
421
- if (u) {
422
- const g = this.At(o - l / 2, n - c / 2, l, c);
423
- f = g.centerX, d = g.centerY, m = g.radians, p = g.aspectRatio;
424
- }
425
- this.yt(i), this.Et("u_color", this.vt), u && (this.Et("u_rotation", m), this.Et("u_center", [f, d]), this.Et("u_aspectRatio", p)), this.dt.ht(t, e, r, s, this.xt);
622
+ Ce(t, e, s) {
623
+ const r = this.xe(e, s);
624
+ t.rotationCenter = [r.nx, r.ny];
426
625
  }
427
- At(t, e, r, s) {
428
- const i = Z(this.v) || [0, 0, this.v.canvas.width, this.v.canvas.height], o = i[2], n = i[3], l = o / n;
429
- return { centerX: (t + r / 2) / o * 2 - 1, centerY: 1 - (e + s / 2) / n * 2, radians: this.wt * Math.PI / 180, aspectRatio: l };
626
+ ve(t, e, s, r, i) {
627
+ const n = L(this.R) || [0, 0, this.R.canvas.width, this.R.canvas.height], o = n[2], h = n[3];
628
+ return { centerX: (t + s / 2) / o * 2 - 1, centerY: 1 - (e + r / 2) / h * 2, radians: -i * Math.PI / 180, aspectRatio: o / h };
430
629
  }
431
- Lt(t, e, r = {}) {
432
- return new J(this.v, t, e, r);
630
+ }
631
+ const it = { vertices: new Float32Array([0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1]), vertexCount: 6, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
632
+ class nt extends F {
633
+ constructor(t, e) {
634
+ super(t, e, R.RECTANGLE, it);
433
635
  }
434
- Ht(t, e = t, r = t, s = 255) {
435
- this.jt(t / 255, e / 255, r / 255, s / 255);
636
+ Vt(t, e) {
637
+ const s = this.me(t.x, t.y, t.width, t.height, e);
638
+ return this.de.Vt(s);
436
639
  }
437
- jt(t = 0, e = 0, r = 0, s = 0) {
438
- this.v.clearColor(t, e, r, s), this.v.clear(this.v.COLOR_BUFFER_BIT);
640
+ }
641
+ const ot = { vertices: 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]), vertexCount: 6, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
642
+ class at extends F {
643
+ constructor(t, e) {
644
+ super(t, e, R.LINE, ot);
645
+ }
646
+ Vt(t, e) {
647
+ const s = t.x2 - t.x1, r = t.y2 - t.y1, i = Math.hypot(s, r), n = Math.atan2(r, s), o = t.thickness || e.lineWeight || 1, h = t.x1 + s / 2, l = t.y1 + r / 2, u = h - i / 2, f = l, d = { character: e.character, charColor: e.charColor, bgColor: e.bgColor, charRotation: e.charRotation, flipHorizontally: e.flipHorizontally, flipVertically: e.flipVertically, invert: e.invert, rotation: (e.rotation || 0) + 180 * n / Math.PI, lineWeight: o }, p = this.me(u, f, i, o, d);
648
+ return this.Ce(p, h, l), this.de.Vt(p);
649
+ }
650
+ }
651
+ const ht = { vertices: function(a = 32) {
652
+ const t = [], e = 2 * Math.PI / a;
653
+ for (let s = 0; s < a; s++) {
654
+ const r = s * e, i = (s + 1) % a * e, n = Math.cos(r), o = Math.sin(r), h = 0.5 * (n + 1), l = 0.5 * (o + 1), u = Math.cos(i), f = Math.sin(i), d = 0.5 * (u + 1), p = 0.5 * (f + 1);
655
+ t.push(0, 0, 0.5, 0.5, n, o, h, l, u, f, d, p);
656
+ }
657
+ return new Float32Array(t);
658
+ }(32), vertexCount: 96, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
659
+ class ct extends F {
660
+ constructor(t, e) {
661
+ super(t, e, R.ELLIPSE, ht);
662
+ }
663
+ Vt(t, e) {
664
+ const s = this.me(t.x, t.y, t.width, t.height, e);
665
+ return this.Ce(s, t.x, t.y), this.de.Vt(s);
666
+ }
667
+ }
668
+ let lt = { vertices: function(a) {
669
+ const t = [];
670
+ for (let e = 0; e < a; e++) {
671
+ const s = e / a, r = (e + 1) / a;
672
+ t.push(s, 0, s, 0, s, 1, s, 1, r, 1, r, 1);
673
+ }
674
+ return new Float32Array(t);
675
+ }(32), vertexCount: 96, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
676
+ class ut extends F {
677
+ constructor(t, e) {
678
+ super(t, e, R.ARC, lt);
439
679
  }
440
- Ot() {
441
- this.v.viewport(0, 0, this.v.canvas.width, this.v.canvas.height), I(this.v, [0, 0, this.v.canvas.width, this.v.canvas.height]);
680
+ Vt(t, e) {
681
+ const s = t.x - t.width / 2, r = t.y - t.height / 2, i = t.start * Math.PI / 180, n = t.stop * Math.PI / 180, o = this.me(s, r, t.width, t.height, e);
682
+ return this.Ce(o, t.x, t.y), o.arcAngles = [i, n], this.de.Vt(o);
683
+ }
684
+ }
685
+ const ft = { vertices: new Float32Array([0, 0, 0, 0, 1, 0, 1, 0, 0.5, 1, 0.5, 1]), vertexCount: 3, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
686
+ class dt extends F {
687
+ constructor(t, e) {
688
+ super(t, e, R.TRIANGLE, ft);
689
+ }
690
+ Vt(t, e) {
691
+ const s = Math.min(t.x1, t.x2, t.x3), r = Math.max(t.x1, t.x2, t.x3), i = Math.min(t.y1, t.y2, t.y3), n = r - s, o = Math.max(t.y1, t.y2, t.y3) - i, h = this.me(s, i, n, o, e), l = s + 0.5 * n, u = i + o * (1 / 3);
692
+ return this.Ce(h, l, u), this.de.Vt(h);
693
+ }
694
+ }
695
+ function W(a, t, e, s, r) {
696
+ const i = 1 - a, n = i * i, o = a * a;
697
+ return n * i * t + 3 * n * a * e + 3 * i * o * s + o * a * r;
698
+ }
699
+ const gt = { vertices: function(a = 16) {
700
+ const t = [];
701
+ for (let e = 0; e < a; e++) {
702
+ const s = e / a, r = (e + 1) / a;
703
+ t.push(s, -0.5, s, 0), t.push(r, -0.5, r, 0), t.push(s, 0.5, s, 1), t.push(s, 0.5, s, 1), t.push(r, -0.5, r, 0), t.push(r, 0.5, r, 1);
704
+ }
705
+ return new Float32Array(t);
706
+ }(16), vertexCount: 96, primitiveType: WebGL2RenderingContext.TRIANGLES, stride: 16, attributes: { position: { size: 2, offset: 0 }, texCoord: { size: 2, offset: 8 } } };
707
+ class pt extends F {
708
+ constructor(t, e) {
709
+ super(t, e, R.BEZIER_CURVE, gt);
710
+ }
711
+ Vt(t, e) {
712
+ const s = e.lineWeight || 1, r = W(0.5, t.x1, t.cp1x, t.cp2x, t.x2), i = W(0.5, t.y1, t.cp1y, t.cp2y, t.y2), n = { character: e.character, charColor: e.charColor, bgColor: e.bgColor, charRotation: e.charRotation, flipHorizontally: e.flipHorizontally, flipVertically: e.flipVertically, invert: e.invert, rotation: e.rotation || 0, lineWeight: s }, o = this.me(0, 0, 1, s, n);
713
+ return this.Ce(o, r, i), o.bezierStartPoint = [t.x1, t.y1], o.bezierControlPoint1 = [t.cp1x, t.cp1y], o.bezierControlPoint2 = [t.cp2x, t.cp2y], o.bezierEndPoint = [t.x2, t.y2], this.de.Vt(o);
714
+ }
715
+ }
716
+ class mt {
717
+ constructor(t) {
718
+ c(this, "R");
719
+ c(this, "ye", null);
720
+ c(this, "we", null);
721
+ c(this, "$e", null);
722
+ c(this, "be", /* @__PURE__ */ new Map());
723
+ c(this, "Te");
724
+ c(this, "ze");
725
+ c(this, "Re");
726
+ this.R = t, this.Re = new Q(), this.Te = new et(t), this.ze = new st(), this.we = t.createBuffer(), t.bindBuffer(t.ARRAY_BUFFER, this.we), t.bufferData(t.ARRAY_BUFFER, new Float32Array([-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, -1, 1, 0, 1, 1, 1, 1, -1, 1, 0, 1]), t.STATIC_DRAW), this.$e = t.createBuffer(), this.R.enable(this.R.BLEND), this.R.blendEquation(this.R.FUNC_ADD), this.R.blendFunc(this.R.ONE, this.R.ONE_MINUS_SRC_ALPHA), D(this.R, [0, 0, this.R.canvas.width, this.R.canvas.height]);
727
+ }
728
+ Me(t) {
729
+ let e = this.be.get(t);
730
+ if (e) return e;
731
+ const s = new rt(this.R);
732
+ return e = (0, { [R.RECTANGLE]: () => new nt(this.R, s), [R.LINE]: () => new at(this.R, s), [R.ELLIPSE]: () => new ct(this.R, s), [R.ARC]: () => new ut(this.R, s), [R.TRIANGLE]: () => new dt(this.R, s), [R.BEZIER_CURVE]: () => new pt(this.R, s) }[t])(), this.be.set(t, e), e;
733
+ }
734
+ Se(t) {
735
+ this.ye !== t && (this.ye = t, t.K());
736
+ }
737
+ Ae(t, e) {
738
+ return new K(this.R, t, e);
739
+ }
740
+ Pe(t, e, s, r) {
741
+ var m;
742
+ const i = this.R, n = i.canvas.width, o = i.canvas.height, h = t / n * 2 - 1, l = (t + s) / n * 2 - 1, u = 1 - e / o * 2, f = 1 - (e + r) / o * 2, d = new Float32Array([h, f, l, f, h, u, l, f, l, u, h, u]);
743
+ i.bindBuffer(i.ARRAY_BUFFER, this.$e), i.bufferData(i.ARRAY_BUFFER, d, i.DYNAMIC_DRAW);
744
+ const p = ((m = this.ye) == null ? void 0 : m.rt) || i.getParameter(i.CURRENT_PROGRAM), g = p ? i.getAttribLocation(p, "a_position") : -1;
745
+ g !== -1 && (i.enableVertexAttribArray(g), i.vertexAttribPointer(g, 2, i.FLOAT, !1, 8, 0)), i.drawArrays(i.TRIANGLES, 0, 6), g !== -1 && i.disableVertexAttribArray(g);
746
+ }
747
+ Fe(t, e, s, r) {
748
+ this.ze.qt(t, e, s, r, this.Re);
749
+ }
750
+ Ge(t, e, s, r) {
751
+ this.ze.Nt(t, e, s, r, this.Re.lineWeight, this.Re);
752
+ }
753
+ De(t, e, s, r) {
754
+ this.ze.Xt(t, e, s, r, this.Re);
755
+ }
756
+ Ie(t, e, s, r, i, n) {
757
+ this.ze.Qt(t, e, s, r, i, n, this.Re);
758
+ }
759
+ Be(t, e, s, r, i, n, o, h) {
760
+ const l = this.Re.lineWeight;
761
+ this.ze.Zt(t, e, s, r, i, n, o, h, l, this.Re);
762
+ }
763
+ Le(t, e, s = 1, r = {}) {
764
+ return new Y(this.R, t, e, s, r);
765
+ }
766
+ Ee(t, e, s, r, i, n) {
767
+ this.ze.Yt(t, e, s, r, i, n, this.Re);
768
+ }
769
+ We(t, e = t, s = t, r = 255) {
770
+ this.Jt(t / 255, e / 255, s / 255, r / 255);
771
+ }
772
+ Jt(t = 0, e = 0, s = 0, r = 0) {
773
+ this.R.clearColor(t, e, s, r), this.R.clear(this.R.COLOR_BUFFER_BIT);
774
+ }
775
+ ke() {
776
+ this.R.viewport(0, 0, this.R.canvas.width, this.R.canvas.height), D(this.R, [0, 0, this.R.canvas.width, this.R.canvas.height]);
442
777
  }
443
778
  get context() {
444
- return this.v;
779
+ return this.R;
780
+ }
781
+ get state() {
782
+ return this.Re;
445
783
  }
446
- P() {
447
- this.lt.P(), this.ct.P(), this.ft.P(), this.dt.P();
784
+ Ve(t) {
785
+ const e = L(this.R) ?? this.R.getParameter(this.R.VIEWPORT), s = { shader: t, gl: this.R, viewport: e }, r = /* @__PURE__ */ new Set();
786
+ for (const i of this.ze) r.add(i.type);
787
+ for (const i of r) this.Me(i);
788
+ this.Te.It(s, this.ze, this.be), this.ze.Jt();
448
789
  }
449
- Bt(t, e, r, s, i) {
450
- const o = this.v, n = s ?? t.width, l = i ?? t.height;
451
- this.yt(this.lt), this.Et("u_texture", t.texture);
452
- const c = this.At(e, r, n, l);
453
- this.Et("u_rotation", c.radians), this.Et("u_center", [c.centerX, c.centerY]), this.Et("u_aspectRatio", c.aspectRatio), this.ft.ot(e, r, n, l), o.bindTexture(o.TEXTURE_2D, null), this.ut = null;
790
+ U() {
791
+ this.R.deleteBuffer(this.we), this.R.deleteBuffer(this.$e), this.ze.Jt();
792
+ for (const t of this.be.values()) t.U();
454
793
  }
455
794
  }
456
- const _ = { readShort: (a, t) => (_.t.uint16[0] = a[t] << 8 | a[t + 1], _.t.int16[0]), readUshort: (a, t) => a[t] << 8 | a[t + 1], readUshorts(a, t, e) {
457
- const r = [];
458
- for (let s = 0; s < e; s++) r.push(_.readUshort(a, t + 2 * s));
459
- return r;
795
+ const y = { readShort: (a, t) => (y.t.uint16[0] = a[t] << 8 | a[t + 1], y.t.int16[0]), readUshort: (a, t) => a[t] << 8 | a[t + 1], readUshorts(a, t, e) {
796
+ const s = [];
797
+ for (let r = 0; r < e; r++) s.push(y.readUshort(a, t + 2 * r));
798
+ return s;
460
799
  }, readUint(a, t) {
461
- const e = _.t.uint8;
462
- return e[3] = a[t], e[2] = a[t + 1], e[1] = a[t + 2], e[0] = a[t + 3], _.t.uint32[0];
800
+ const e = y.t.uint8;
801
+ return e[3] = a[t], e[2] = a[t + 1], e[1] = a[t + 2], e[0] = a[t + 3], y.t.uint32[0];
463
802
  }, readASCII(a, t, e) {
464
- let r = "";
465
- for (let s = 0; s < e; s++) r += String.fromCharCode(a[t + s]);
466
- return r;
803
+ let s = "";
804
+ for (let r = 0; r < e; r++) s += String.fromCharCode(a[t + r]);
805
+ return s;
467
806
  }, t: (() => {
468
807
  const a = new ArrayBuffer(8);
469
808
  return { uint8: new Uint8Array(a), int16: new Int16Array(a), uint16: new Uint16Array(a), uint32: new Uint32Array(a) };
470
- })() }, nt = { parseTab(a, t, e) {
471
- const r = { tables: [], ids: {}, off: t };
809
+ })() }, Rt = { parseTab(a, t, e) {
810
+ const s = { tables: [], ids: {}, off: t };
472
811
  a = new Uint8Array(a.buffer, t, e), t = 0;
473
- const s = _, i = s.readUshort, o = i(a, t += 2);
812
+ const r = y, i = r.readUshort, n = i(a, t += 2);
474
813
  t += 2;
475
- const n = [];
476
- for (let l = 0; l < o; l++) {
477
- const c = i(a, t), u = i(a, t += 2);
814
+ const o = [];
815
+ for (let h = 0; h < n; h++) {
816
+ const l = i(a, t), u = i(a, t += 2);
478
817
  t += 2;
479
- const f = s.readUint(a, t);
818
+ const f = r.readUint(a, t);
480
819
  t += 4;
481
- const d = `p${c}e${u}`;
482
- let m = n.indexOf(f);
483
- if (m === -1) {
484
- let p;
485
- m = r.tables.length, n.push(f);
486
- const g = i(a, f);
487
- p = g === 4 ? this.parse4(a, f) : g === 12 ? this.parse12(a, f) : { format: g }, r.tables.push(p);
820
+ const d = `p${l}e${u}`;
821
+ let p = o.indexOf(f);
822
+ if (p === -1) {
823
+ let g;
824
+ p = s.tables.length, o.push(f);
825
+ const m = i(a, f);
826
+ g = m === 4 ? this.parse4(a, f) : m === 12 ? this.parse12(a, f) : { format: m }, s.tables.push(g);
488
827
  }
489
- r.ids[d] != null && console.warn("Multiple tables for one platform+encoding: " + d), r.ids[d] = m;
828
+ s.ids[d] != null && console.warn("Multiple tables for one platform+encoding: " + d), s.ids[d] = p;
490
829
  }
491
- return r;
830
+ return s;
492
831
  }, parse4(a, t) {
493
- const e = _, r = e.readUshort, s = e.readUshorts, i = t, o = r(a, t += 2);
832
+ const e = y, s = e.readUshort, r = e.readUshorts, i = t, n = s(a, t += 2);
494
833
  t += 2;
495
- const n = r(a, t += 2) >>> 1, l = { format: 4, searchRange: r(a, t += 2), entrySelector: 0, rangeShift: 0, endCount: [], startCount: [], idDelta: [], idRangeOffset: [], glyphIdArray: [] };
496
- t += 2, l.entrySelector = r(a, t), t += 2, l.rangeShift = r(a, t), t += 2, l.endCount = s(a, t, n), t += 2 * n, t += 2, l.startCount = s(a, t, n), t += 2 * n;
497
- for (let c = 0; c < n; c++) l.idDelta.push(e.readShort(a, t)), t += 2;
498
- return l.idRangeOffset = s(a, t, n), t += 2 * n, l.glyphIdArray = s(a, t, i + o - t >> 1), l;
834
+ const o = s(a, t += 2) >>> 1, h = { format: 4, searchRange: s(a, t += 2), entrySelector: 0, rangeShift: 0, endCount: [], startCount: [], idDelta: [], idRangeOffset: [], glyphIdArray: [] };
835
+ t += 2, h.entrySelector = s(a, t), t += 2, h.rangeShift = s(a, t), t += 2, h.endCount = r(a, t, o), t += 2 * o, t += 2, h.startCount = r(a, t, o), t += 2 * o;
836
+ for (let l = 0; l < o; l++) h.idDelta.push(e.readShort(a, t)), t += 2;
837
+ return h.idRangeOffset = r(a, t, o), t += 2 * o, h.glyphIdArray = r(a, t, i + n - t >> 1), h;
499
838
  }, parse12(a, t) {
500
- const e = _.readUint;
839
+ const e = y.readUint;
501
840
  e(a, t += 4), e(a, t += 4);
502
- const r = e(a, t += 4);
841
+ const s = e(a, t += 4);
503
842
  t += 4;
504
- const s = new Uint32Array(3 * r);
505
- for (let i = 0; i < 3 * r; i += 3) s[i] = e(a, t + (i << 2)), s[i + 1] = e(a, t + (i << 2) + 4), s[i + 2] = e(a, t + (i << 2) + 8);
506
- return { format: 12, groups: s };
507
- } }, at = { parseTab(a, t, e) {
508
- const r = _;
843
+ const r = new Uint32Array(3 * s);
844
+ for (let i = 0; i < 3 * s; i += 3) r[i] = e(a, t + (i << 2)), r[i + 1] = e(a, t + (i << 2) + 4), r[i + 2] = e(a, t + (i << 2) + 8);
845
+ return { format: 12, groups: r };
846
+ } }, xt = { parseTab(a, t, e) {
847
+ const s = y;
509
848
  t += 18;
510
- const s = r.readUshort(a, t);
849
+ const r = s.readUshort(a, t);
511
850
  t += 2, t += 16;
512
- const i = r.readShort(a, t);
851
+ const i = s.readShort(a, t);
513
852
  t += 2;
514
- const o = r.readShort(a, t);
853
+ const n = s.readShort(a, t);
515
854
  t += 2;
516
- const n = r.readShort(a, t);
855
+ const o = s.readShort(a, t);
517
856
  t += 2;
518
- const l = r.readShort(a, t);
519
- return t += 2, t += 6, { unitsPerEm: s, xMin: i, yMin: o, xMax: n, yMax: l, indexToLocFormat: r.readShort(a, t) };
520
- } }, ht = { parseTab(a, t, e) {
521
- const r = _;
857
+ const h = s.readShort(a, t);
858
+ return t += 2, t += 6, { unitsPerEm: r, xMin: i, yMin: n, xMax: o, yMax: h, indexToLocFormat: s.readShort(a, t) };
859
+ } }, Ct = { parseTab(a, t, e) {
860
+ const s = y;
522
861
  t += 4;
523
- const s = ["ascender", "descender", "lineGap", "advanceWidthMax", "minLeftSideBearing", "minRightSideBearing", "xMaxExtent", "caretSlopeRise", "caretSlopeRun", "caretOffset", "res0", "res1", "res2", "res3", "metricDataFormat", "numberOfHMetrics"], i = {};
524
- for (let o = 0; o < s.length; o++) {
525
- const n = s[o], l = n === "advanceWidthMax" || n === "numberOfHMetrics" ? r.readUshort : r.readShort;
526
- i[n] = l(a, t + 2 * o);
862
+ const r = ["ascender", "descender", "lineGap", "advanceWidthMax", "minLeftSideBearing", "minRightSideBearing", "xMaxExtent", "caretSlopeRise", "caretSlopeRun", "caretOffset", "res0", "res1", "res2", "res3", "metricDataFormat", "numberOfHMetrics"], i = {};
863
+ for (let n = 0; n < r.length; n++) {
864
+ const o = r[n], h = o === "advanceWidthMax" || o === "numberOfHMetrics" ? s.readUshort : s.readShort;
865
+ i[o] = h(a, t + 2 * n);
527
866
  }
528
867
  return i;
529
- } }, lt = { parseTab(a, t, e, r) {
530
- if (!r) throw Error("Font object required for hmtx parsing");
531
- const s = _, i = [], o = [], n = r.maxp.numGlyphs, l = r.hhea.numberOfHMetrics;
532
- let c = 0, u = 0, f = 0;
533
- for (; f < l; ) c = s.readUshort(a, t + (f << 2)), u = s.readShort(a, t + (f << 2) + 2), i.push(c), o.push(u), f++;
534
- for (; f < n; ) i.push(c), o.push(u), f++;
535
- return { aWidth: i, lsBearing: o };
536
- } }, j = { cmap: nt, head: at, hhea: ht, maxp: { parseTab(a, t, e) {
537
- const r = _;
538
- return r.readUint(a, t), t += 4, { numGlyphs: r.readUshort(a, t) };
539
- } }, hmtx: lt, loca: { parseTab(a, t, e, r) {
540
- if (!r) throw Error("Font object required for loca parsing");
541
- const s = _, i = [], o = r.head.indexToLocFormat, n = r.maxp.numGlyphs + 1;
542
- if (o === 0) for (let l = 0; l < n; l++) i.push(s.readUshort(a, t + (l << 1)) << 1);
543
- else if (o === 1) for (let l = 0; l < n; l++) i.push(s.readUint(a, t + (l << 2)));
868
+ } }, yt = { parseTab(a, t, e, s) {
869
+ const r = y, i = [], n = [], o = s.maxp.numGlyphs, h = s.hhea.numberOfHMetrics;
870
+ let l = 0, u = 0, f = 0;
871
+ for (; f < h; ) l = r.readUshort(a, t + (f << 2)), u = r.readShort(a, t + (f << 2) + 2), i.push(l), n.push(u), f++;
872
+ for (; f < o; ) i.push(l), n.push(u), f++;
873
+ return { aWidth: i, lsBearing: n };
874
+ } }, G = { cmap: Rt, head: xt, hhea: Ct, maxp: { parseTab(a, t, e) {
875
+ const s = y;
876
+ return s.readUint(a, t), t += 4, { numGlyphs: s.readUshort(a, t) };
877
+ } }, hmtx: yt, loca: { parseTab(a, t, e, s) {
878
+ const r = y, i = [], n = s.head.indexToLocFormat, o = s.maxp.numGlyphs + 1;
879
+ if (n === 0) for (let h = 0; h < o; h++) i.push(r.readUshort(a, t + (h << 1)) << 1);
880
+ else if (n === 1) for (let h = 0; h < o; h++) i.push(r.readUint(a, t + (h << 2)));
544
881
  return i;
545
- } }, glyf: { parseTab(a, t, e, r) {
546
- if (!r) throw Error("Font object required for glyf parsing");
547
- const s = [], i = r.maxp.numGlyphs;
548
- for (let o = 0; o < i; o++) s.push(null);
549
- return s;
550
- }, Wt(a, t) {
551
- const e = _, r = a.Nt, s = a.loca;
552
- if (s[t] === s[t + 1]) return null;
553
- const i = y.findTable(r, "glyf", a.Xt);
882
+ } }, glyf: { parseTab(a, t, e, s) {
883
+ const r = [], i = s.maxp.numGlyphs;
884
+ for (let n = 0; n < i; n++) r.push(null);
885
+ return r;
886
+ }, Oe(a, t) {
887
+ const e = y, s = a.Ue, r = a.loca;
888
+ if (r[t] === r[t + 1]) return null;
889
+ const i = E.findTable(s, "glyf", a.je);
554
890
  if (!i) return null;
555
- let o = i[0] + s[t];
556
- const n = {};
557
- if (n.noc = e.readShort(r, o), o += 2, n.xMin = e.readShort(r, o), o += 2, n.yMin = e.readShort(r, o), o += 2, n.xMax = e.readShort(r, o), o += 2, n.yMax = e.readShort(r, o), o += 2, n.xMin >= n.xMax || n.yMin >= n.yMax) return null;
558
- if (n.noc > 0) {
559
- n.endPts = [];
560
- for (let d = 0; d < n.noc; d++) n.endPts.push(e.readUshort(r, o)), o += 2;
561
- const l = e.readUshort(r, o);
562
- if (o += 2, r.length - o < l) return null;
563
- o += l;
564
- const c = n.endPts[n.noc - 1] + 1;
565
- n.flags = [];
566
- for (let d = 0; d < c; d++) {
567
- const m = r[o];
568
- if (o++, n.flags.push(m), 8 & m) {
569
- const p = r[o];
570
- o++;
571
- for (let g = 0; g < p; g++) n.flags.push(m), d++;
891
+ let n = i[0] + r[t];
892
+ const o = {};
893
+ if (o.noc = e.readShort(s, n), n += 2, o.xMin = e.readShort(s, n), n += 2, o.yMin = e.readShort(s, n), n += 2, o.xMax = e.readShort(s, n), n += 2, o.yMax = e.readShort(s, n), n += 2, o.xMin >= o.xMax || o.yMin >= o.yMax) return null;
894
+ if (o.noc > 0) {
895
+ o.endPts = [];
896
+ for (let d = 0; d < o.noc; d++) o.endPts.push(e.readUshort(s, n)), n += 2;
897
+ const h = e.readUshort(s, n);
898
+ if (n += 2, s.length - n < h) return null;
899
+ n += h;
900
+ const l = o.endPts[o.noc - 1] + 1;
901
+ o.flags = [];
902
+ for (let d = 0; d < l; d++) {
903
+ const p = s[n];
904
+ if (n++, o.flags.push(p), 8 & p) {
905
+ const g = s[n];
906
+ n++;
907
+ for (let m = 0; m < g; m++) o.flags.push(p), d++;
572
908
  }
573
909
  }
574
- n.xs = [];
575
- for (let d = 0; d < c; d++) {
576
- const m = n.flags[d], p = !!(16 & m);
577
- 2 & m ? (n.xs.push(p ? r[o] : -r[o]), o++) : p ? n.xs.push(0) : (n.xs.push(e.readShort(r, o)), o += 2);
910
+ o.xs = [];
911
+ for (let d = 0; d < l; d++) {
912
+ const p = o.flags[d], g = !!(16 & p);
913
+ 2 & p ? (o.xs.push(g ? s[n] : -s[n]), n++) : g ? o.xs.push(0) : (o.xs.push(e.readShort(s, n)), n += 2);
578
914
  }
579
- n.ys = [];
580
- for (let d = 0; d < c; d++) {
581
- const m = n.flags[d], p = !!(32 & m);
582
- 4 & m ? (n.ys.push(p ? r[o] : -r[o]), o++) : p ? n.ys.push(0) : (n.ys.push(e.readShort(r, o)), o += 2);
915
+ o.ys = [];
916
+ for (let d = 0; d < l; d++) {
917
+ const p = o.flags[d], g = !!(32 & p);
918
+ 4 & p ? (o.ys.push(g ? s[n] : -s[n]), n++) : g ? o.ys.push(0) : (o.ys.push(e.readShort(s, n)), n += 2);
583
919
  }
584
920
  let u = 0, f = 0;
585
- for (let d = 0; d < c; d++) u += n.xs[d], f += n.ys[d], n.xs[d] = u, n.ys[d] = f;
586
- } else n.parts = [], n.endPts = [], n.flags = [], n.xs = [], n.ys = [];
587
- return n;
588
- } } }, y = { parse: (a) => [((t, e, r, s) => {
589
- const i = j, o = { Nt: t, qt: e, Xt: r };
590
- for (const n in i) {
591
- const l = n, c = y.findTable(t, l, r);
592
- if (c) {
593
- const [u, f] = c;
594
- let d = s[u];
595
- d == null && (d = i[l].parseTab(t, u, f, o), s[u] = d), o[l] = d;
921
+ for (let d = 0; d < l; d++) u += o.xs[d], f += o.ys[d], o.xs[d] = u, o.ys[d] = f;
922
+ } else o.parts = [], o.endPts = [], o.flags = [], o.xs = [], o.ys = [];
923
+ return o;
924
+ } } }, E = { parse: (a) => [((t, e, s, r) => {
925
+ const i = G, n = { Ue: t, He: e, je: s };
926
+ for (const o in i) {
927
+ const h = o, l = E.findTable(t, h, s);
928
+ if (l) {
929
+ const [u, f] = l;
930
+ let d = r[u];
931
+ d == null && (d = i[h].parseTab(t, u, f, n), r[u] = d), n[h] = d;
596
932
  }
597
933
  }
598
- return o;
934
+ return n;
599
935
  })(new Uint8Array(a), 0, 0, {})], findTable(a, t, e) {
600
- const r = _, s = r.readUshort(a, e + 4);
936
+ const s = y, r = s.readUshort(a, e + 4);
601
937
  let i = e + 12;
602
- for (let o = 0; o < s; o++) {
603
- const n = r.readASCII(a, i, 4);
604
- r.readUint(a, i + 4);
605
- const l = r.readUint(a, i + 8), c = r.readUint(a, i + 12);
606
- if (n === t) return [l, c];
938
+ for (let n = 0; n < r; n++) {
939
+ const o = s.readASCII(a, i, 4);
940
+ s.readUint(a, i + 4);
941
+ const h = s.readUint(a, i + 8), l = s.readUint(a, i + 12);
942
+ if (o === t) return [h, l];
607
943
  i += 16;
608
944
  }
609
945
  return null;
610
- }, T: j, B: _ };
611
- class k {
946
+ }, T: G, B: y };
947
+ class U {
612
948
  constructor() {
613
- h(this, "Yt", /* @__PURE__ */ new Map());
614
- h(this, "Qt", /* @__PURE__ */ new Map());
949
+ c(this, "qe", /* @__PURE__ */ new Map());
950
+ c(this, "Ne", /* @__PURE__ */ new Map());
615
951
  }
616
- Zt(t, e) {
617
- const r = `${this.Jt(t)}_${e}`;
618
- if (this.Yt.has(r)) return this.Yt.get(r);
619
- const s = t.cmap;
620
- if (!s || !s.tables) return this.Yt.set(r, 0), 0;
952
+ Xe(t, e) {
953
+ const s = `${this.Ye(t)}_${e}`;
954
+ if (this.qe.has(s)) return this.qe.get(s);
955
+ const r = t.cmap;
956
+ if (!r || !r.tables) return this.qe.set(s, 0), 0;
621
957
  let i = 0;
622
- for (const o of s.tables) if (o.format === 4 ? i = this.Kt(e, o) : o.format === 12 && (i = this.te(e, o)), i > 0) break;
623
- return this.Yt.set(r, i), i;
958
+ for (const n of r.tables) if (n.format === 4 ? i = this.Qe(e, n) : n.format === 12 && (i = this.Ze(e, n)), i > 0) break;
959
+ return this.qe.set(s, i), i;
624
960
  }
625
- ee(t, e) {
626
- const r = e.codePointAt(0);
627
- return r === void 0 ? 0 : this.Zt(t, r);
961
+ Je(t, e) {
962
+ const s = e.codePointAt(0);
963
+ return s === void 0 ? 0 : this.Xe(t, s);
628
964
  }
629
- re(t, e) {
630
- const r = t.hmtx;
631
- return r && r.aWidth && r.aWidth.length !== 0 ? e < r.aWidth.length ? r.aWidth[e] : r.aWidth[r.aWidth.length - 1] : 0;
965
+ Ke(t, e) {
966
+ const s = t.hmtx;
967
+ return s && s.aWidth && s.aWidth.length !== 0 ? e < s.aWidth.length ? s.aWidth[e] : s.aWidth[s.aWidth.length - 1] : 0;
632
968
  }
633
- se(t, e) {
634
- const r = e / t.head.unitsPerEm, s = t.hhea.ascender * r, i = t.hhea.descender * r, o = t.hhea.lineGap * r;
635
- return { ascender: s, descender: i, lineGap: o, lineHeight: s - i + o, unitsPerEm: t.head.unitsPerEm, scale: r };
969
+ ts(t, e) {
970
+ const s = e / t.head.unitsPerEm, r = t.hhea.ascender * s, i = t.hhea.descender * s, n = t.hhea.lineGap * s;
971
+ return { ascender: r, descender: i, lineGap: n, lineHeight: r - i + n, unitsPerEm: t.head.unitsPerEm, scale: s };
636
972
  }
637
- ie() {
638
- this.Yt.clear(), this.Qt.clear();
973
+ es() {
974
+ this.qe.clear(), this.Ne.clear();
639
975
  }
640
- Jt(t) {
641
- return `${t.Xt}_${t.Nt.length}`;
976
+ Ye(t) {
977
+ return `${t.je}_${t.Ue.length}`;
642
978
  }
643
- Kt(t, e) {
644
- const r = e.endCount.length;
645
- let s = -1;
646
- for (let i = 0; i < r; i++) if (t <= e.endCount[i]) {
647
- s = i;
979
+ Qe(t, e) {
980
+ const s = e.endCount.length;
981
+ let r = -1;
982
+ for (let i = 0; i < s; i++) if (t <= e.endCount[i]) {
983
+ r = i;
648
984
  break;
649
985
  }
650
- if (s === -1 || t < e.startCount[s]) return 0;
651
- if (e.idRangeOffset[s] === 0) return t + e.idDelta[s] & 65535;
986
+ if (r === -1 || t < e.startCount[r]) return 0;
987
+ if (e.idRangeOffset[r] === 0) return t + e.idDelta[r] & 65535;
652
988
  {
653
- const i = e.idRangeOffset[s] / 2 + (t - e.startCount[s]) - (r - s);
989
+ const i = e.idRangeOffset[r] / 2 + (t - e.startCount[r]) - (s - r);
654
990
  if (i >= 0 && i < e.glyphIdArray.length) {
655
- const o = e.glyphIdArray[i];
656
- return o === 0 ? 0 : o + e.idDelta[s] & 65535;
991
+ const n = e.glyphIdArray[i];
992
+ return n === 0 ? 0 : n + e.idDelta[r] & 65535;
657
993
  }
658
994
  }
659
995
  return 0;
660
996
  }
661
- te(t, e) {
662
- const r = e.groups.length / 3;
663
- for (let s = 0; s < r; s++) {
664
- const i = e.groups[3 * s], o = e.groups[3 * s + 1], n = e.groups[3 * s + 2];
665
- if (t >= i && t <= o) return n + (t - i);
997
+ Ze(t, e) {
998
+ const s = e.groups.length / 3;
999
+ for (let r = 0; r < s; r++) {
1000
+ const i = e.groups[3 * r], n = e.groups[3 * r + 1], o = e.groups[3 * r + 2];
1001
+ if (t >= i && t <= n) return o + (t - i);
666
1002
  }
667
1003
  return 0;
668
1004
  }
669
1005
  }
670
- class ct {
1006
+ class vt {
671
1007
  constructor(t) {
672
- h(this, "oe");
673
- this.oe = t;
1008
+ c(this, "ss");
1009
+ this.ss = t;
674
1010
  }
675
- ne(t) {
676
- var r;
1011
+ rs(t) {
1012
+ var s;
677
1013
  const e = [];
678
- return (r = t == null ? void 0 : t.cmap) != null && r.tables ? (t.cmap.tables.forEach((s) => {
679
- if (s.format === 4) {
680
- const i = this.ae(s);
1014
+ return (s = t.cmap) != null && s.tables ? (t.cmap.tables.forEach((r) => {
1015
+ if (r.format === 4) {
1016
+ const i = this.ns(r);
681
1017
  e.push(...i);
682
- } else if (s.format === 12) {
683
- const i = this.he(s);
1018
+ } else if (r.format === 12) {
1019
+ const i = this.hs(r);
684
1020
  e.push(...i);
685
1021
  }
686
1022
  }), [...new Set(e)]) : [];
687
1023
  }
688
- le(t, e) {
689
- return this.oe.ee(t, e) > 0;
1024
+ cs(t, e) {
1025
+ return this.ss.Je(t, e) > 0;
690
1026
  }
691
- ce(t, e) {
692
- for (const r of e) if (!this.le(t, r)) return !1;
1027
+ ls(t, e) {
1028
+ for (const s of e) if (!this.cs(t, s)) return !1;
693
1029
  return !0;
694
1030
  }
695
- ue(t, e) {
696
- return e.filter((r) => this.le(t, r));
1031
+ us(t, e) {
1032
+ return e.filter((s) => this.cs(t, s));
697
1033
  }
698
- fe(t) {
699
- return t.filter((e) => this.de(e));
1034
+ fs(t) {
1035
+ return t.filter((e) => this.ds(e));
700
1036
  }
701
- ae(t) {
1037
+ ns(t) {
702
1038
  const e = [];
703
1039
  if (!(t.startCount && t.endCount && t.idRangeOffset && t.idDelta)) return e;
704
- for (let r = 0; r < t.startCount.length; r++) {
705
- const s = t.startCount[r], i = t.endCount[r];
706
- if (s !== 65535 || i !== 65535) {
707
- for (let o = s; o <= i; o++)
708
- if (this.pe(t, o, r) > 0) try {
709
- const n = String.fromCodePoint(o);
710
- e.push(n);
1040
+ for (let s = 0; s < t.startCount.length; s++) {
1041
+ const r = t.startCount[s], i = t.endCount[s];
1042
+ if (r !== 65535 || i !== 65535) {
1043
+ for (let n = r; n <= i; n++)
1044
+ if (this.ps(t, n, s) > 0) try {
1045
+ const o = String.fromCodePoint(n);
1046
+ e.push(o);
711
1047
  } catch {
712
1048
  }
713
1049
  }
714
1050
  }
715
1051
  return e;
716
1052
  }
717
- he(t) {
1053
+ hs(t) {
718
1054
  const e = [];
719
1055
  if (!t.groups) return e;
720
- for (let r = 0; r < t.groups.length; r += 3) {
721
- const s = t.groups[r], i = t.groups[r + 1], o = t.groups[r + 2];
722
- for (let n = s; n <= i; n++)
723
- if (o + (n - s) > 0) try {
724
- const l = String.fromCodePoint(n);
725
- e.push(l);
1056
+ for (let s = 0; s < t.groups.length; s += 3) {
1057
+ const r = t.groups[s], i = t.groups[s + 1], n = t.groups[s + 2];
1058
+ for (let o = r; o <= i; o++)
1059
+ if (n + (o - r) > 0) try {
1060
+ const h = String.fromCodePoint(o);
1061
+ e.push(h);
726
1062
  } catch {
727
1063
  }
728
1064
  }
729
1065
  return e;
730
1066
  }
731
- pe(t, e, r) {
732
- if (t.idRangeOffset[r] === 0) return e + t.idDelta[r] & 65535;
1067
+ ps(t, e, s) {
1068
+ if (t.idRangeOffset[s] === 0) return e + t.idDelta[s] & 65535;
733
1069
  {
734
- const s = t.idRangeOffset[r] / 2 + (e - t.startCount[r]) - (t.startCount.length - r);
735
- if (s >= 0 && t.glyphIdArray && s < t.glyphIdArray.length) {
736
- const i = t.glyphIdArray[s];
737
- if (i !== 0) return i + t.idDelta[r] & 65535;
1070
+ const r = t.idRangeOffset[s] / 2 + (e - t.startCount[s]) - (t.startCount.length - s);
1071
+ if (r >= 0 && t.glyphIdArray && r < t.glyphIdArray.length) {
1072
+ const i = t.glyphIdArray[r];
1073
+ if (i !== 0) return i + t.idDelta[s] & 65535;
738
1074
  }
739
1075
  }
740
1076
  return 0;
741
1077
  }
742
- de(t) {
1078
+ ds(t) {
743
1079
  const e = t.codePointAt(0) || 0;
744
1080
  return !(e >= 0 && e <= 31 && e !== 9 && e !== 10 && e !== 13 || e >= 127 && e <= 159);
745
1081
  }
746
1082
  }
747
- class ut {
1083
+ class Tt {
748
1084
  constructor() {
749
- h(this, "me");
750
- const t = new k();
751
- this.me = new ct(t);
1085
+ c(this, "gs");
1086
+ const t = new U();
1087
+ this.gs = new vt(t);
752
1088
  }
753
1089
  extractCharacters(t) {
754
- return this.me.ne(t);
1090
+ return this.gs.rs(t);
755
1091
  }
756
1092
  filterProblematicCharacters(t) {
757
- return this.me.fe(t);
1093
+ return this.gs.fs(t);
758
1094
  }
759
1095
  characterExists(t, e) {
760
- return this.me.le(t, e);
1096
+ return this.gs.cs(t, e);
761
1097
  }
762
1098
  allCharactersExist(t, e) {
763
- return this.me.ce(t, e);
1099
+ return this.gs.ls(t, e);
764
1100
  }
765
1101
  }
766
- class dt {
1102
+ class bt {
767
1103
  constructor(t) {
768
- h(this, "ge");
769
- h(this, "_e");
770
- h(this, "ve");
771
- h(this, "xe");
772
- this.ve = t, this.xe = new k(), this.ge = document.createElement("canvas"), this._e = this.ge.getContext("2d", { willReadFrequently: !0, alpha: !1 });
773
- }
774
- createTextureAtlas(t, e, r, s) {
775
- const i = t.length, o = Math.ceil(Math.sqrt(i)), n = Math.ceil(i / o), l = e.width * o, c = e.height * n, u = typeof s == "object" ? s : null;
776
- this.be(l, c), this.we(t, e, o, r, u);
777
- const f = this.ve.Lt(l, c, { filter: "nearest" });
778
- return f.update(this.ge), { framebuffer: f, columns: o, rows: n };
779
- }
780
- be(t, e) {
781
- this.ge.width = t, this.ge.height = e, this.ge.style.width = t + "px", this.ge.style.height = t + "px", this._e.imageSmoothingEnabled = !1, this.ge.style.imageRendering = "pixelated", this._e.fillStyle = "black", this._e.fillRect(0, 0, t, e), this._e.textBaseline = "top", this._e.textAlign = "left", this._e.fillStyle = "white";
782
- }
783
- we(t, e, r, s, i) {
784
- const o = s / i.head.unitsPerEm;
785
- for (let n = 0; n < t.length; n++) {
786
- const l = n % r, c = Math.floor(n / r), u = t[n].character, f = this.Ce(i, u);
1104
+ c(this, "_s");
1105
+ c(this, "vs");
1106
+ c(this, "Cs");
1107
+ c(this, "ws");
1108
+ this.Cs = t, this.ws = new U(), this._s = document.createElement("canvas"), this.vs = this._s.getContext("2d", { willReadFrequently: !0, alpha: !1 });
1109
+ }
1110
+ createTextureAtlas(t, e, s, r) {
1111
+ const i = t.length, n = Math.ceil(Math.sqrt(i)), o = Math.ceil(i / n), h = e.width * n, l = e.height * o, u = typeof r == "object" ? r : null;
1112
+ this.$s(h, l), this.bs(t, e, n, s, u);
1113
+ const f = this.Cs.Le(h, l, 1, { filter: "nearest" });
1114
+ return f.I(this._s), { framebuffer: f, columns: n, rows: o };
1115
+ }
1116
+ $s(t, e) {
1117
+ this._s.width = t, this._s.height = e, this._s.style.width = t + "px", this._s.style.height = t + "px", this.vs.imageSmoothingEnabled = !1, this._s.style.imageRendering = "pixelated", this.vs.fillStyle = "black", this.vs.fillRect(0, 0, t, e), this.vs.textBaseline = "top", this.vs.textAlign = "left", this.vs.fillStyle = "white";
1118
+ }
1119
+ bs(t, e, s, r, i) {
1120
+ const n = r / i.head.unitsPerEm;
1121
+ for (let o = 0; o < t.length; o++) {
1122
+ const h = o % s, l = Math.floor(o / s), u = t[o].character, f = this.Ts(i, u);
787
1123
  if (!f) continue;
788
- const d = u.codePointAt(0) || 0, m = this.xe.Zt(i, d), p = this.ye(i, m) * o, g = l * e.width, C = c * e.height, v = g + 0.5 * e.width, b = C + 0.5 * e.height, T = Math.round(v - 0.5 * e.width), E = Math.round(b - 0.5 * s), M = T + 0.5 * (e.width - p), F = E + i.hhea.ascender * o;
789
- this.$e(f, M, F, o);
1124
+ const d = u.codePointAt(0) || 0, p = this.ws.Xe(i, d), g = this.zs(i, p) * n, m = h * e.width, T = l * e.height, v = m + 0.5 * e.width, b = T + 0.5 * e.height, _ = Math.round(v - 0.5 * e.width), S = Math.round(b - 0.5 * r), j = _ + 0.5 * (e.width - g), H = S + i.hhea.ascender * n;
1125
+ this.Rs(f, j, H, n);
790
1126
  }
791
1127
  }
792
- Ce(t, e) {
793
- const r = e.codePointAt(0) || 0, s = this.xe.Zt(t, r);
794
- if (s === 0) return null;
795
- if (t.glyf && t.glyf[s] !== null) return t.glyf[s];
796
- if (y && y.T && y.T.glyf && y.T.glyf.Wt) {
797
- const i = y.T.glyf.Wt(t, s);
798
- return t.glyf && i && (t.glyf[s] = i), i;
1128
+ Ts(t, e) {
1129
+ const s = e.codePointAt(0) || 0, r = this.ws.Xe(t, s);
1130
+ if (r === 0) return null;
1131
+ if (t.glyf && t.glyf[r] !== null) return t.glyf[r];
1132
+ if (E && E.T && E.T.glyf) {
1133
+ const i = E.T.glyf.Oe(t, r);
1134
+ return t.glyf && i && (t.glyf[r] = i), i;
799
1135
  }
800
1136
  return null;
801
1137
  }
802
- ye(t, e) {
803
- const r = t.hmtx;
804
- return r && r.aWidth ? e < r.aWidth.length ? r.aWidth[e] : r.aWidth[r.aWidth.length - 1] : 0;
1138
+ zs(t, e) {
1139
+ const s = t.hmtx;
1140
+ return s && s.aWidth ? e < s.aWidth.length ? s.aWidth[e] : s.aWidth[s.aWidth.length - 1] : 0;
805
1141
  }
806
- $e(t, e, r, s) {
1142
+ Rs(t, e, s, r) {
807
1143
  if (!t || !t.xs || t.noc === 0) return;
808
- const { xs: i, ys: o, endPts: n, flags: l } = t;
809
- if (!(i && o && n && l)) return;
810
- this._e.beginPath();
811
- let c = 0;
812
- for (let u = 0; u < n.length; u++) {
813
- const f = n[u];
814
- if (!(f < c)) {
815
- if (f >= c) {
816
- const d = e + i[c] * s, m = r - o[c] * s;
817
- this._e.moveTo(d, m);
818
- let p = c + 1;
819
- for (; p <= f; )
820
- if (1 & l[p]) {
821
- const g = e + i[p] * s, C = r - o[p] * s;
822
- this._e.lineTo(g, C), p++;
1144
+ const { xs: i, ys: n, endPts: o, flags: h } = t;
1145
+ if (!(i && n && o && h)) return;
1146
+ this.vs.beginPath();
1147
+ let l = 0;
1148
+ for (let u = 0; u < o.length; u++) {
1149
+ const f = o[u];
1150
+ if (!(f < l)) {
1151
+ if (f >= l) {
1152
+ const d = e + i[l] * r, p = s - n[l] * r;
1153
+ this.vs.moveTo(d, p);
1154
+ let g = l + 1;
1155
+ for (; g <= f; )
1156
+ if (1 & h[g]) {
1157
+ const m = e + i[g] * r, T = s - n[g] * r;
1158
+ this.vs.lineTo(m, T), g++;
823
1159
  } else {
824
- const g = e + i[p] * s, C = r - o[p] * s;
825
- let v = p + 1 > f ? c : p + 1;
826
- if (1 & l[v]) {
827
- const b = e + i[v] * s, T = r - o[v] * s;
828
- this._e.quadraticCurveTo(g, C, b, T), p = v + 1;
1160
+ const m = e + i[g] * r, T = s - n[g] * r;
1161
+ let v = g + 1 > f ? l : g + 1;
1162
+ if (1 & h[v]) {
1163
+ const b = e + i[v] * r, _ = s - n[v] * r;
1164
+ this.vs.quadraticCurveTo(m, T, b, _), g = v + 1;
829
1165
  } else {
830
- const b = (g + (e + i[v] * s)) / 2, T = (C + (r - o[v] * s)) / 2;
831
- this._e.quadraticCurveTo(g, C, b, T), p = v;
1166
+ const b = (m + (e + i[v] * r)) / 2, _ = (T + (s - n[v] * r)) / 2;
1167
+ this.vs.quadraticCurveTo(m, T, b, _), g = v;
832
1168
  }
833
1169
  }
834
- this._e.closePath();
1170
+ this.vs.closePath();
835
1171
  }
836
- c = f + 1;
1172
+ l = f + 1;
837
1173
  }
838
1174
  }
839
- this._e.fill();
1175
+ this.vs.fill();
840
1176
  }
841
1177
  }
842
- class ft {
1178
+ class _t {
843
1179
  constructor() {
844
- h(this, "oe");
845
- this.oe = new k();
846
- }
847
- calculateMaxGlyphDimensions(t, e, r) {
848
- let s = 0;
849
- const i = this.oe.se(r, e), o = i.lineHeight;
850
- for (const n of t) {
851
- const l = this.oe.ee(r, n);
852
- if (l === 0) continue;
853
- const c = this.oe.re(r, l) * i.scale;
854
- s = Math.max(s, c);
1180
+ c(this, "ss");
1181
+ this.ss = new U();
1182
+ }
1183
+ calculateMaxGlyphDimensions(t, e, s) {
1184
+ let r = 0;
1185
+ const i = this.ss.ts(s, e), n = i.lineHeight;
1186
+ for (const o of t) {
1187
+ const h = this.ss.Je(s, o);
1188
+ if (h === 0) continue;
1189
+ const l = this.ss.Ke(s, h) * i.scale;
1190
+ r = Math.max(r, l);
855
1191
  }
856
- return { width: Math.ceil(s), height: Math.ceil(o) };
1192
+ return { width: Math.ceil(r), height: Math.ceil(n) };
857
1193
  }
858
- getCharacterAdvanceWidth(t, e, r) {
859
- const s = this.oe.se(r, e), i = this.oe.ee(r, t);
860
- return this.oe.re(r, i) * s.scale;
1194
+ getCharacterAdvanceWidth(t, e, s) {
1195
+ const r = this.ss.ts(s, e), i = this.ss.Je(s, t);
1196
+ return this.ss.Ke(s, i) * r.scale;
861
1197
  }
862
1198
  getFontMetrics(t, e) {
863
- return this.oe.se(e, t);
1199
+ return this.ss.ts(e, t);
864
1200
  }
865
- ie() {
866
- this.oe.ie();
1201
+ es() {
1202
+ this.ss.es();
867
1203
  }
868
1204
  }
869
- class gt {
1205
+ class Et {
870
1206
  constructor() {
871
- h(this, "xe");
872
- this.xe = new k();
1207
+ c(this, "ws");
1208
+ this.ws = new U();
873
1209
  }
874
1210
  createCharacterObjects(t, e) {
875
- return t.map((r, s) => {
876
- const i = r.codePointAt(0) || 0, o = this.Fe(s);
877
- let n = 0;
1211
+ return t.map((s, r) => {
1212
+ const i = s.codePointAt(0) || 0, n = this.Ms(r);
1213
+ let o = 0;
878
1214
  if (e.hmtx && e.hmtx.aWidth) {
879
- const l = this.xe.Zt(e, i);
880
- l > 0 && e.hmtx.aWidth[l] !== void 0 && (n = e.hmtx.aWidth[l]);
1215
+ const h = this.ws.Xe(e, i);
1216
+ h > 0 && e.hmtx.aWidth[h] !== void 0 && (o = e.hmtx.aWidth[h]);
881
1217
  }
882
- return { character: r, unicode: i, color: o, advanceWidth: n };
1218
+ return { character: s, unicode: i, color: n, advanceWidth: o };
883
1219
  });
884
1220
  }
885
- Fe(t) {
886
- return [t % 256, Math.floor(t / 256) % 256, Math.floor(t / 65536) % 256];
1221
+ Ms(t) {
1222
+ return [t % 256 / 255, Math.floor(t / 256) % 256 / 255, Math.floor(t / 65536) % 256 / 255];
887
1223
  }
888
- getCharacterColor(t, e) {
889
- if (!x.m(typeof t == "string", "Character must be a string.", { method: "getCharacterColor", providedValue: t })) return [0, 0, 0];
890
- const r = e.find((s) => s.character === t);
891
- return r ? r.color : [0, 0, 0];
1224
+ Ss(t, e) {
1225
+ if (!I._(typeof t == "string", "Character must be a string.", { method: "getCharacterColor", providedValue: t })) return [0, 0, 0];
1226
+ const s = e.find((r) => r.character === t);
1227
+ return s ? s.color : [0, 0, 0];
892
1228
  }
893
- getCharacterColors(t, e) {
894
- return x.m(typeof t == "string" && t.length > 0, "Characters must be a string with at least one character.", { method: "getCharacterColors", providedValue: t }) ? Array.from(t).map((r) => this.getCharacterColor(r, e) || [0, 0, 0]) : [[0, 0, 0]];
1229
+ As(t, e) {
1230
+ return I._(typeof t == "string" && t.length > 0, "Characters must be a string with at least one character.", { method: "getCharacterColors", providedValue: t }) ? Array.from(t).map((s) => this.Ss(s, e) || [0, 0, 0]) : [[0, 0, 0]];
895
1231
  }
896
1232
  }
897
- class pt {
1233
+ class At {
898
1234
  constructor(t, e = 16) {
899
- h(this, "Te");
900
- h(this, "Me", []);
901
- h(this, "De");
902
- h(this, "Se", 16);
903
- h(this, "Re", 0);
904
- h(this, "Ve", 0);
905
- h(this, "ke", { width: 0, height: 0 });
906
- h(this, "Ie");
907
- h(this, "Pe", "UrsaFont");
908
- h(this, "ze");
909
- h(this, "Ee");
910
- h(this, "Ge");
911
- h(this, "Ae");
912
- this.Se = e, this.ze = new ut(), this.Ee = new dt(t), this.Ge = new ft(), this.Ae = new gt();
913
- }
914
- async Ue(t) {
1235
+ c(this, "Ps");
1236
+ c(this, "Fs", []);
1237
+ c(this, "Gs");
1238
+ c(this, "Ds", 16);
1239
+ c(this, "Is", 0);
1240
+ c(this, "Bs", 0);
1241
+ c(this, "Ls", { width: 0, height: 0 });
1242
+ c(this, "Es");
1243
+ c(this, "Ws");
1244
+ c(this, "ks");
1245
+ c(this, "Vs");
1246
+ c(this, "Os");
1247
+ this.Ds = e, this.Ws = new Tt(), this.ks = new bt(t), this.Vs = new _t(), this.Os = new Et();
1248
+ }
1249
+ async Us(t) {
915
1250
  let e;
916
- if (!t) throw new w("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");
1251
+ if (!t) throw new C("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");
917
1252
  {
918
- const r = await fetch(t);
919
- if (!r.ok) throw new w(`Failed to load font file: ${r.status} ${r.statusText}`);
920
- e = await r.arrayBuffer();
1253
+ const s = await fetch(t);
1254
+ if (!s.ok) throw new C(`Failed to load font file: ${s.status} ${s.statusText}`);
1255
+ e = await s.arrayBuffer();
921
1256
  }
922
- await this.Le(e), this.Te = y.parse(e)[0], await this.He();
1257
+ await this.js(e), this.Ps = E.parse(e)[0], await this.Hs();
923
1258
  }
924
- je(t) {
925
- if (t === void 0) return this.Se;
926
- this.Se = t, this.ke = this.Ge.calculateMaxGlyphDimensions(this.Me.map((r) => r.character), this.Se, this.Te);
927
- const e = this.Ee.createTextureAtlas(this.Me, this.ke, this.Se, this.Te);
928
- this.De = e.framebuffer, this.Re = e.columns, this.Ve = e.rows;
1259
+ qs(t) {
1260
+ if (t === void 0) return this.Ds;
1261
+ this.Ds = t, this.Ls = this.Vs.calculateMaxGlyphDimensions(this.Fs.map((s) => s.character), this.Ds, this.Ps);
1262
+ const e = this.ks.createTextureAtlas(this.Fs, this.Ls, this.Ds, this.Ps);
1263
+ this.Gs = e.framebuffer, this.Is = e.columns, this.Bs = e.rows;
929
1264
  }
930
- async Oe(t) {
1265
+ async Ns(t) {
931
1266
  try {
932
1267
  const e = await fetch(t);
933
- if (!e.ok) throw new w(`Failed to load font file: ${e.status} ${e.statusText}`);
934
- const r = await e.arrayBuffer();
935
- await this.Le(r);
936
- const s = y.parse(r);
937
- if (!s || s.length === 0) throw Error("Failed to parse font file");
938
- this.Te = s[0], await this.He();
1268
+ if (!e.ok) throw new C(`Failed to load font file: ${e.status} ${e.statusText}`);
1269
+ const s = await e.arrayBuffer();
1270
+ await this.js(s);
1271
+ const r = E.parse(s);
1272
+ if (!r || r.length === 0) throw Error("Failed to parse font file");
1273
+ this.Ps = r[0], await this.Hs();
939
1274
  } catch (e) {
940
- throw new w("Failed to load font: " + (e instanceof Error ? e.message : "Unknown error"), e);
1275
+ throw new C("Failed to load font: " + (e instanceof Error ? e.message : "Unknown error"), e);
941
1276
  }
942
1277
  }
943
- async Le(t) {
1278
+ async js(t) {
944
1279
  const e = Date.now();
945
- this.Pe = this.Pe === "UrsaFont" ? "UrsaFont" : "CustomFont_" + e, this.Ie = new FontFace(this.Pe, t), await this.Ie.load(), document.fonts.add(this.Ie);
946
- }
947
- async He() {
948
- const t = this.ze.extractCharacters(this.Te), e = this.ze.filterProblematicCharacters(t);
949
- this.Me = this.Ae.createCharacterObjects(e, this.Te), this.ke = this.Ge.calculateMaxGlyphDimensions(e, this.Se, this.Te);
950
- const r = this.Ee.createTextureAtlas(this.Me, this.ke, this.Se, this.Te);
951
- this.De = r.framebuffer, this.Re = r.columns, this.Ve = r.rows;
1280
+ this.Es = new FontFace("CustomFont_" + e, t), await this.Es.load(), document.fonts.add(this.Es);
952
1281
  }
953
- getCharacterColor(t) {
954
- return this.Ae.getCharacterColor(t, this.Me);
1282
+ async Hs() {
1283
+ const t = this.Ws.extractCharacters(this.Ps), e = this.Ws.filterProblematicCharacters(t);
1284
+ this.Fs = this.Os.createCharacterObjects(e, this.Ps), this.Ls = this.Vs.calculateMaxGlyphDimensions(e, this.Ds, this.Ps);
1285
+ const s = this.ks.createTextureAtlas(this.Fs, this.Ls, this.Ds, this.Ps);
1286
+ this.Gs = s.framebuffer, this.Is = s.columns, this.Bs = s.rows;
955
1287
  }
956
- getCharacterColors(t) {
957
- return this.Ae.getCharacterColors(t, this.Me);
1288
+ Ss(t) {
1289
+ return this.Os.Ss(t, this.Fs);
958
1290
  }
959
- hasAllCharacters(t) {
960
- if (typeof t != "string" || t.length === 0) return !1;
961
- const e = new Set(this.Me.map((r) => r.character));
962
- for (const r of t) if (!e.has(r)) return !1;
963
- return !0;
1291
+ As(t) {
1292
+ return this.Os.As(t, this.Fs);
964
1293
  }
965
- P() {
966
- this.De.P(), document.fonts.delete(this.Ie);
1294
+ U() {
1295
+ this.Gs.U(), document.fonts.delete(this.Es);
967
1296
  }
968
1297
  get fontFramebuffer() {
969
- return this.De;
1298
+ return this.Gs;
970
1299
  }
971
1300
  get characters() {
972
- return this.Me;
1301
+ return this.Fs;
973
1302
  }
974
1303
  get textureColumns() {
975
- return this.Re;
1304
+ return this.Is;
976
1305
  }
977
1306
  get textureRows() {
978
- return this.Ve;
1307
+ return this.Bs;
979
1308
  }
980
1309
  get maxGlyphDimensions() {
981
- return this.ke;
1310
+ return this.Ls;
982
1311
  }
983
1312
  get fontSize() {
984
- return this.Se;
1313
+ return this.Ds;
985
1314
  }
986
1315
  get font() {
987
- return this.Te;
1316
+ return this.Ps;
988
1317
  }
989
1318
  }
990
- class mt {
991
- constructor(t, e, r) {
992
- h(this, "Be");
993
- h(this, "We");
994
- h(this, "F");
995
- h(this, "M");
996
- h(this, "Ne");
997
- h(this, "Xe");
998
- h(this, "qe", !1);
999
- h(this, "Ye");
1000
- h(this, "Qe");
1001
- h(this, "Ze");
1002
- this.Ye = t, this.Qe = e, this.Ze = r, this.kt();
1003
- }
1004
- kt() {
1005
- this.qe || (this.Be = Math.floor(this.Ye.width / this.Qe), this.We = Math.floor(this.Ye.height / this.Ze)), this.Je();
1006
- }
1007
- Je() {
1008
- this.F = this.Be * this.Qe, this.M = this.We * this.Ze, this.Ne = Math.floor((this.Ye.width - this.F) / 2), this.Xe = Math.floor((this.Ye.height - this.M) / 2);
1009
- }
1010
- Ke(t, e) {
1011
- this.Qe = t, this.Ze = e, this.kt();
1012
- }
1013
- tr(t, e) {
1014
- this.qe = !0, this.Be = t, this.We = e, this.Je();
1015
- }
1016
- er() {
1017
- this.qe = !1, this.kt();
1018
- }
1019
- rr() {
1020
- this.qe ? this.Je() : this.kt();
1021
- }
1022
- sr(t) {
1023
- if (t === void 0) return this.qe;
1024
- this.qe = t;
1319
+ class wt {
1320
+ constructor(t, e, s) {
1321
+ c(this, "Xs");
1322
+ c(this, "Ys");
1323
+ c(this, "v");
1324
+ c(this, "C");
1325
+ c(this, "Qs");
1326
+ c(this, "Zs");
1327
+ c(this, "Js");
1328
+ c(this, "Ks");
1329
+ c(this, "ti");
1330
+ this.Js = t, this.Ks = e, this.ti = s, this.Ct();
1331
+ }
1332
+ Ct() {
1333
+ this.Xs = Math.floor(this.Js.width / this.Ks), this.Ys = Math.floor(this.Js.height / this.ti), this.v = this.Xs * this.Ks, this.C = this.Ys * this.ti, this.Qs = Math.floor((this.Js.width - this.v) / 2), this.Zs = Math.floor((this.Js.height - this.C) / 2);
1334
+ }
1335
+ ei(t, e) {
1336
+ this.Ks = t, this.ti = e, this.Ct();
1025
1337
  }
1026
1338
  get cellWidth() {
1027
- return this.Qe;
1339
+ return this.Ks;
1028
1340
  }
1029
1341
  get cellHeight() {
1030
- return this.Ze;
1342
+ return this.ti;
1031
1343
  }
1032
1344
  get cols() {
1033
- return this.Be;
1345
+ return this.Xs;
1034
1346
  }
1035
1347
  get rows() {
1036
- return this.We;
1348
+ return this.Ys;
1037
1349
  }
1038
1350
  get width() {
1039
- return this.F;
1351
+ return this.v;
1040
1352
  }
1041
1353
  get height() {
1042
- return this.M;
1354
+ return this.C;
1043
1355
  }
1044
1356
  get offsetX() {
1045
- return this.Ne;
1357
+ return this.Qs;
1046
1358
  }
1047
1359
  get offsetY() {
1048
- return this.Xe;
1360
+ return this.Zs;
1049
1361
  }
1050
1362
  }
1051
- class vt {
1052
- constructor(t, e = !1, r = {}) {
1053
- h(this, "Ye");
1054
- h(this, "ir");
1055
- h(this, "nr");
1056
- h(this, "ar");
1057
- h(this, "onTransformChange");
1058
- this.ir = t, this.nr = e, this.Ye = this.hr(r.width, r.height), e && this.setupTransformObserver();
1059
- }
1060
- hr(t, e) {
1061
- var s;
1062
- const r = document.createElement("canvas");
1063
- if (r.className = "textmodeCanvas", r.style.imageRendering = "pixelated", this.nr) r.width = t || 800, r.height = e || 600, document.body.appendChild(r);
1064
- else {
1065
- const i = this.ir.getBoundingClientRect();
1066
- let o = Math.round(i.width), n = Math.round(i.height);
1067
- if (this.ir instanceof HTMLVideoElement) {
1068
- const u = this.ir;
1069
- (o === 0 || n === 0) && u.videoWidth > 0 && u.videoHeight > 0 && (o = u.videoWidth, n = u.videoHeight);
1070
- }
1071
- r.width = o, r.height = n, r.style.position = "absolute", r.style.pointerEvents = "none";
1072
- const l = window.getComputedStyle(this.ir);
1073
- let c = parseInt(l.zIndex || "0", 10);
1074
- isNaN(c) && (c = 0), r.style.zIndex = "" + (c + 1), this.lr(r), (s = this.ir.parentNode) == null || s.insertBefore(r, this.ir.nextSibling);
1075
- }
1076
- return r;
1077
- }
1078
- lr(t) {
1079
- const e = this.ir.getBoundingClientRect();
1080
- let r = this.ir.offsetParent;
1081
- if (r && r !== document.body) {
1082
- const s = r.getBoundingClientRect();
1083
- t.style.top = e.top - s.top + "px", t.style.left = e.left - s.left + "px";
1084
- } else t.style.top = e.top + window.scrollY + "px", t.style.left = e.left + window.scrollX + "px";
1363
+ class Pt {
1364
+ constructor(t = {}) {
1365
+ c(this, "Js");
1366
+ c(this, "si");
1367
+ c(this, "ii");
1368
+ t.canvas ? (this.Js = t.canvas, this.ii = !1) : (this.Js = this.ri(t.width, t.height), this.ii = !0), this.Js.style.imageRendering = "pixelated";
1085
1369
  }
1086
- rr(t, e) {
1087
- if (this.nr) this.Ye.width = t ?? this.Ye.width, this.Ye.height = e ?? this.Ye.height;
1088
- else {
1089
- const r = this.ir.getBoundingClientRect();
1090
- let s = Math.round(r.width), i = Math.round(r.height);
1091
- if (this.ir instanceof HTMLVideoElement) {
1092
- const o = this.ir;
1093
- (s === 0 || i === 0) && o.videoWidth > 0 && o.videoHeight > 0 && (s = o.videoWidth, i = o.videoHeight);
1094
- }
1095
- this.Ye.width = s, this.Ye.height = i, this.lr(this.Ye);
1096
- }
1370
+ ri(t, e) {
1371
+ const s = document.createElement("canvas");
1372
+ return s.className = "textmodeCanvas", s.style.imageRendering = "pixelated", s.width = t || 800, s.height = e || 600, document.body.appendChild(s), s;
1097
1373
  }
1098
- cr() {
1099
- const t = { alpha: !1, premultipliedAlpha: !1, preserveDrawingBuffer: !0, antialias: !1, depth: !1, stencil: !1, powerPreference: "high-performance" }, e = this.Ye.getContext("webgl2", t) || this.Ye.getContext("webgl", t);
1100
- if (!e) throw new w("WebGL context could not be created. Ensure your browser supports WebGL.");
1101
- return e;
1374
+ L(t, e) {
1375
+ this.Js.width = t ?? this.Js.width, this.Js.height = e ?? this.Js.height;
1102
1376
  }
1103
- setupTransformObserver() {
1104
- this.ar = new ResizeObserver((t) => {
1105
- for (const e of t) {
1106
- const r = e.contentRect;
1107
- !this.onTransformChange || Math.round(r.width) === this.Ye.width && Math.round(r.height) === this.Ye.height || this.onTransformChange();
1108
- }
1109
- }), this.ar.observe(this.Ye);
1377
+ ni() {
1378
+ const t = this.Js.getContext("webgl2", { alpha: !1, premultipliedAlpha: !1, preserveDrawingBuffer: !0, antialias: !1, depth: !1, stencil: !1, powerPreference: "high-performance" });
1379
+ if (!t) throw new C("`textmode.js` requires WebGL2 support.");
1380
+ return t;
1110
1381
  }
1111
- P() {
1112
- this.ar && this.ar.disconnect();
1113
- const t = this.Ye.getContext("webgl") || this.Ye.getContext("webgl2");
1382
+ U() {
1383
+ this.si && this.si.disconnect();
1384
+ const t = this.Js.getContext("webgl") || this.Js.getContext("webgl2");
1114
1385
  if (t) {
1115
1386
  const e = t.getExtension("WEBGL_lose_context");
1116
1387
  e && e.loseContext();
1117
1388
  }
1118
- this.Ye.parentNode && this.Ye.parentNode.removeChild(this.Ye);
1389
+ this.ii && this.Js.parentNode && this.Js.parentNode.removeChild(this.Js);
1119
1390
  }
1120
1391
  get canvas() {
1121
- return this.Ye;
1392
+ return this.Js;
1122
1393
  }
1123
1394
  get width() {
1124
- return this.Ye.width;
1395
+ return this.Js.width;
1125
1396
  }
1126
1397
  get height() {
1127
- return this.Ye.height;
1398
+ return this.Js.height;
1128
1399
  }
1129
1400
  }
1130
- class D {
1131
- constructor(t, e, r, s = {}) {
1132
- h(this, "ve");
1133
- h(this, "ur");
1134
- h(this, "dr");
1135
- h(this, "pr");
1136
- h(this, "mr");
1137
- h(this, "gr");
1138
- h(this, "_r");
1139
- h(this, "vr");
1140
- h(this, "l");
1141
- this.ve = t, this.ur = e, this.dr = r, this.l = s;
1142
- const i = this.dr.cols, o = this.dr.rows;
1143
- this.pr = this.ve.Lt(i, o), this.mr = this.ve.Lt(i, o), this.gr = this.ve.Lt(i, o), this._r = this.ve.Lt(i, o), this.vr = this.ve.Lt(i, o);
1144
- }
1145
- rr() {
1146
- const t = this.dr.cols, e = this.dr.rows;
1147
- this.pr.resize(t, e), this.mr.resize(t, e), this.gr.resize(t, e), this._r.resize(t, e), this.vr.resize(t, e);
1148
- }
1149
- enabled(t) {
1150
- x.m(typeof t == "boolean" || typeof t == "number" && Number.isInteger(t), "Enabled must be a boolean value or an integer (0 for false, any other number for true).", { method: "enabled", providedValue: t }) && (this.l.enabled = !!t);
1151
- }
1152
- enable() {
1153
- this.enabled(!0);
1154
- }
1155
- disable() {
1156
- this.enabled(!1);
1157
- }
1158
- P() {
1159
- this.pr.P(), this.mr.P(), this.gr.P(), this._r.P(), this.vr.P();
1160
- }
1161
- get characterFramebuffer() {
1162
- return this.pr;
1163
- }
1164
- get primaryColorFramebuffer() {
1165
- return this.mr;
1166
- }
1167
- get secondaryColorFramebuffer() {
1168
- return this.gr;
1169
- }
1170
- get rotationFramebuffer() {
1171
- return this._r;
1172
- }
1173
- get transformFramebuffer() {
1174
- return this.vr;
1175
- }
1176
- get options() {
1177
- return this.l;
1178
- }
1179
- }
1180
- class xt {
1181
- constructor(t, e) {
1182
- h(this, "C");
1183
- h(this, "ve");
1184
- h(this, "br");
1185
- this.ve = t, this.br = e;
1186
- const r = Math.max(this.br.length, 1);
1187
- this.C = this.ve.Lt(r, 1), this.wr();
1188
- }
1189
- wr() {
1190
- const t = this.br.length;
1191
- this.C.width !== t && this.C.resize(t, 1);
1192
- const e = new Uint8Array(1 * t * 4);
1193
- for (let r = 0; r < t; r++) {
1194
- const s = this.br[r], i = 4 * r;
1195
- e[i] = s[0], e[i + 1] = s[1], e[i + 2] = s[2], e[i + 3] = 255;
1196
- }
1197
- this.C.updatePixels(e, t, 1);
1198
- }
1199
- setColors(t) {
1200
- this.br = t, this.wr();
1201
- }
1202
- get colors() {
1203
- return this.br;
1204
- }
1205
- get framebuffer() {
1206
- return this.C;
1207
- }
1208
- get texture() {
1209
- return this.C.texture;
1210
- }
1211
- }
1212
- class B extends D {
1213
- constructor(e, r, s, i = {}) {
1214
- super(e, r, s, i);
1215
- h(this, "Cr");
1216
- this.Cr = new xt(this.ve, this.ur.getCharacterColors(" .:-=+*%@#"));
1217
- }
1218
- characters(e) {
1219
- x.m(this.ur.hasAllCharacters(e), "One or more characters do not exist in the current font.", { method: "characters", providedValue: e }) && (this.l.characters = e, this.Cr.setColors(this.ur.getCharacterColors(e)));
1220
- }
1221
- characterColor(e, r, s, i = 255) {
1222
- const o = this.yr(e, "characterColor", r, s, i);
1223
- o && (this.l.characterColor = o);
1224
- }
1225
- characterColorMode(e) {
1226
- this.$r(e, "characterColorMode");
1227
- }
1228
- cellColor(e, r, s, i = 255) {
1229
- const o = this.yr(e, "cellColor", r, s, i);
1230
- o && (this.l.cellColor = o);
1231
- }
1232
- cellColorMode(e) {
1233
- this.$r(e, "cellColorMode");
1234
- }
1235
- invert(e) {
1236
- this.Fr(e, "invert", "Invert");
1237
- }
1238
- rotation(e) {
1239
- if (!x.m(typeof e == "number", "Rotation angle must be a number.", { method: "rotation", providedValue: e })) return;
1240
- (e %= 360) < 0 && (e += 360);
1241
- const r = 255 * e / 360, s = Math.floor(r) / 255, i = Math.round(r - s);
1242
- this.l.rotation = [s, i, 0, 1];
1243
- }
1244
- flipHorizontally(e) {
1245
- this.Fr(e, "flipHorizontally", "Flip horizontally");
1246
- }
1247
- flipVertically(e) {
1248
- this.Fr(e, "flipVertically", "Flip vertically");
1249
- }
1250
- yr(e, r, s, i, o = 255) {
1251
- let n, l, c, u;
1252
- if (typeof e == "string") {
1253
- const f = this.Tr(e);
1254
- if (!f) return x.m(!1, "Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.", { method: r, providedValue: e }), null;
1255
- [n, l, c, u] = f;
1256
- } else if (n = e, l = s !== void 0 ? s : e, c = i !== void 0 ? i : e, u = o, !x.m([n, l, c, u].every((f) => f >= 0 && f <= 255), r.charAt(0).toUpperCase() + r.slice(1) + " color values must be between 0 and 255", { method: r, providedValues: { r: n, g: l, b: c, a: u } })) return null;
1257
- return [n / 255, l / 255, c / 255, u / 255];
1258
- }
1259
- $r(e, r) {
1260
- x.m(["sampled", "fixed"].includes(e), "Invalid color mode. Must be 'sampled' or 'fixed'.", { method: r, providedValue: e }) && (this.l[r] = e);
1261
- }
1262
- Fr(e, r, s) {
1263
- x.m(typeof e == "boolean" || typeof e == "number" && Number.isInteger(e), s + " must be a boolean value or an integer (0 for false, any other number for true).", { method: r, providedValue: e }) && (this.l[r] = !!e);
1264
- }
1265
- Tr(e) {
1266
- return e = e.replace(/^#/, ""), /^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(e) ? (e.length === 3 && (e = e.split("").map((r) => r + r).join("")), [parseInt(e.slice(0, 2), 16), parseInt(e.slice(2, 4), 16), parseInt(e.slice(4, 6), 16), 255]) : null;
1267
- }
1268
- }
1269
- const U = `attribute vec2 a_position;\r
1270
- attribute vec2 a_texCoord;\r
1271
- varying vec2 v_uv;\r
1272
- \r
1273
- uniform float u_rotation; // rotation angle in radians\r
1274
- uniform vec2 u_center; // rotation center in normalized coordinates\r
1275
- uniform float u_aspectRatio; // canvas width / canvas height\r
1276
- \r
1277
- mat2 rotate2D(float angle) {\r
1278
- float s = sin(angle);\r
1279
- float c = cos(angle);\r
1280
- return mat2(c, -s, s, c);\r
1281
- }\r
1282
- \r
1283
- void main() {\r
1284
- v_uv = a_texCoord;\r
1285
- \r
1286
- // Use the position directly (it's already in normalized device coordinates)\r
1287
- vec2 pos = a_position;\r
1288
- \r
1289
- // Translate to origin for rotation\r
1290
- pos -= u_center;\r
1291
- \r
1292
- // Correct for aspect ratio: scale X coordinate to make space square\r
1293
- pos.x *= u_aspectRatio;\r
1294
- \r
1295
- // Rotate in corrected space\r
1296
- // Negate rotation to make positive values rotate clockwise (like p5.js)\r
1297
- pos = rotate2D(-u_rotation) * pos;\r
1298
- \r
1299
- // Restore aspect ratio: scale X coordinate back\r
1300
- pos.x /= u_aspectRatio;\r
1301
- \r
1302
- // Translate back from origin\r
1303
- pos += u_center;\r
1304
- \r
1305
- gl_Position = vec4(pos, 0.0, 1.0);\r
1306
- }\r
1307
- `, bt = { enabled: !0, characters: " .:-=+*%@#", characterColor: [1, 1, 1, 1], characterColorMode: "sampled", cellColor: [0, 0, 0, 1], cellColorMode: "fixed", invert: !1, rotation: [0, 0, 0, 255], flipHorizontally: !1, flipVertically: !1, brightnessRange: [0, 255] };
1308
- class Y extends B {
1309
- constructor(e, r, s) {
1310
- super(e, r, s, { ...bt });
1311
- h(this, "Mr");
1312
- h(this, "Dr");
1313
- h(this, "Sr");
1314
- h(this, "Rr");
1315
- h(this, "Vr");
1316
- h(this, "kr");
1317
- this.Mr = new R(e.context, U, "precision lowp float;uniform sampler2D u_sketchTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec2 cellCenter=(floor(v_uv*u_gridCellDimensions)+vec2(0.5))/u_gridCellDimensions;vec4 color=texture2D(u_sketchTexture,cellCenter);float brightness=dot(color.rgb,vec3(0.299,0.587,0.114));float brightnessValue=brightness*255.0;if(brightnessValue>=u_brightnessRange.x&&brightnessValue<=u_brightnessRange.y){gl_FragColor=color;}else{gl_FragColor=vec4(0.0);}}"), this.Dr = new R(e.context, U, "precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_fillColor;uniform bool u_useFixedColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){if(u_useFixedColor){gl_FragColor=u_fillColor;}else{gl_FragColor=sampleColor;}}else{gl_FragColor=vec4(0.0);}}"), this.Rr = new R(e.context, U, "precision lowp float;uniform sampler2D u_sampleTexture;uniform bool u_invert;uniform bool u_flipHorizontally;uniform bool u_flipVertically;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){float invertValue=u_invert ? 1.0 : 0.0;float flipHValue=u_flipHorizontally ? 1.0 : 0.0;float flipVValue=u_flipVertically ? 1.0 : 0.0;gl_FragColor=vec4(invertValue,flipHValue,flipVValue,1.0);}else{gl_FragColor=vec4(0.0);}}"), this.Vr = new R(e.context, U, "precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_rotationColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){gl_FragColor=u_rotationColor;}else{gl_FragColor=vec4(0.0);}}"), this.Sr = new R(e.context, U, "precision lowp float;uniform sampler2D u_colorSampleFramebuffer;uniform sampler2D u_charPaletteTexture;uniform vec2 u_charPaletteSize;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec4 color=texture2D(u_colorSampleFramebuffer,v_uv);if(color.a==0.0){gl_FragColor=vec4(0.0);return;}float brightness=dot(color.rgb,vec3(0.299,0.587,0.114))*255.0;vec2 range=u_brightnessRange;if(brightness<range.x||brightness>range.y){gl_FragColor=vec4(0.0);return;}float t=(brightness-range.x)/(range.y-range.x);float idx=clamp(floor(t*u_charPaletteSize.x),0.0,u_charPaletteSize.x-1.0);vec3 charColor=texture2D(u_charPaletteTexture,vec2((idx+0.5)/u_charPaletteSize.x,0.0)).rgb;gl_FragColor=vec4(charColor,1.0);}"), this.kr = this.ve.Lt(this.dr.cols, this.dr.rows);
1318
- }
1319
- Ir(e) {
1320
- const r = this.dr.cols, s = this.dr.rows;
1321
- this.kr.begin(), this.ve.jt(), this.ve.yt(this.Mr), this.ve.Et("u_sketchTexture", e), this.ve.Et("u_gridCellDimensions", [r, s]), this.ve.Et("u_brightnessRange", this.l.brightnessRange), this.ve.Gt(0, 0, r, s), this.kr.end(), this.mr.begin(), this.ve.jt(), this.ve.yt(this.Dr), this.ve.Et("u_sampleTexture", this.kr), this.ve.Et("u_fillColor", this.l.characterColor), this.ve.Et("u_useFixedColor", this.l.characterColorMode === "fixed"), this.ve.Gt(0, 0, r, s), this.mr.end(), this.gr.begin(), this.ve.jt(), this.ve.yt(this.Dr), this.ve.Et("u_sampleTexture", this.kr), this.ve.Et("u_fillColor", this.l.cellColor), this.ve.Et("u_useFixedColor", this.l.cellColorMode === "fixed"), this.ve.Gt(0, 0, r, s), this.gr.end(), this.vr.begin(), this.ve.jt(), this.ve.yt(this.Rr), this.ve.Et("u_sampleTexture", this.kr), this.ve.Et("u_invert", this.l.invert), this.ve.Et("u_flipHorizontally", this.l.flipHorizontally), this.ve.Et("u_flipVertically", this.l.flipVertically), this.ve.Gt(0, 0, r, s), this.vr.end(), this._r.begin(), this.ve.jt(), this.ve.yt(this.Vr), this.ve.Et("u_sampleTexture", this.kr), this.ve.Et("u_rotationColor", this.l.rotation), this.ve.Gt(0, 0, r, s), this._r.end(), this.pr.begin(), this.ve.jt(), this.ve.yt(this.Sr), this.ve.Et("u_colorSampleFramebuffer", this.kr), this.ve.Et("u_charPaletteTexture", this.Cr.texture), this.ve.Et("u_charPaletteSize", [this.Cr.colors.length, 1]), this.ve.Et("u_brightnessRange", this.l.brightnessRange), this.ve.Gt(0, 0, r, s), this.pr.end();
1322
- }
1323
- rr() {
1324
- super.rr(), this.kr.resize(this.dr.cols, this.dr.rows);
1325
- }
1326
- brightnessRange(e) {
1327
- x.m(Array.isArray(e) && e.length === 2 && e.every((r) => typeof r == "number" && r >= 0 && r <= 255), "Brightness range must be an array of two numbers between 0 and 255.", { method: "brightnessRange", providedValue: e }) && (this.l.brightnessRange = e);
1328
- }
1329
- }
1330
- const Bt = Object.freeze(Object.defineProperty({ __proto__: null, TextmodeBrightnessConverter: Y, TextmodeConverter: D, TextmodeFeatureConverter: B }, Symbol.toStringTag, { value: "Module" }));
1331
- class wt {
1332
- constructor(t, e, r) {
1333
- h(this, "ve");
1334
- h(this, "Te");
1335
- h(this, "dr");
1336
- h(this, "Pr");
1337
- h(this, "zr");
1338
- h(this, "Er");
1339
- h(this, "Gr");
1340
- h(this, "Ar");
1341
- h(this, "pr");
1342
- h(this, "mr");
1343
- h(this, "gr");
1344
- h(this, "_r");
1345
- h(this, "vr");
1346
- this.ve = t, this.Te = e, this.dr = r, this.Ar = this.ve.Pt($, "precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform sampler2D u_captureTexture;uniform vec2 u_captureDimensions;uniform int u_backgroundMode;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=gl_FragCoord.xy/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);if(encodedIndexVec.a<0.01){gl_FragColor=(u_backgroundMode==0)? vec4(0.0):texture2D(u_captureTexture,gl_FragCoord.xy/u_captureDimensions);return;}int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"), this.zr = new Y(t, e, r), this.Er = new D(t, e, r), this.Pr = [this.zr, this.Er], this.pr = this.ve.Lt(r.cols, r.rows), this.mr = this.ve.Lt(r.cols, r.rows), this.gr = this.ve.Lt(r.cols, r.rows), this._r = this.ve.Lt(r.cols, r.rows), this.vr = this.ve.Lt(r.cols, r.rows), this.Gr = this.ve.Lt(this.dr.width, this.dr.height);
1347
- }
1348
- Ur(t) {
1349
- for (const r of this.Pr) r.options.enabled && r instanceof B && r.Ir(t);
1350
- const e = (r, s) => {
1351
- r.begin(), this.ve.jt();
1352
- for (const i of this.Pr) i.options.enabled && this.ve.Bt(s(i), 0, 0);
1353
- r.end();
1401
+ class Ft {
1402
+ constructor(t = 60) {
1403
+ c(this, "oi");
1404
+ c(this, "ai");
1405
+ c(this, "hi", null);
1406
+ c(this, "ci", 0);
1407
+ c(this, "li", !0);
1408
+ c(this, "ui", 0);
1409
+ c(this, "fi", 0);
1410
+ c(this, "di", []);
1411
+ c(this, "pi", 10);
1412
+ c(this, "gi", 0);
1413
+ this.oi = t, this.ai = 1e3 / t;
1414
+ }
1415
+ start(t) {
1416
+ if (!this.li) return;
1417
+ this.ci = performance.now();
1418
+ const e = (s) => {
1419
+ if (!this.li) return void (this.hi = null);
1420
+ const r = s - this.ci;
1421
+ r >= this.ai && (t(), this.ci = s - r % this.ai), this.li && (this.hi = requestAnimationFrame(e));
1354
1422
  };
1355
- e(this.pr, (r) => r.characterFramebuffer), e(this.mr, (r) => r.primaryColorFramebuffer), e(this.gr, (r) => r.secondaryColorFramebuffer), e(this._r, (r) => r.rotationFramebuffer), e(this.vr, (r) => r.transformFramebuffer), this.Gr.begin(), this.ve.jt(), this.ve.yt(this.Ar), this.ve.Et("u_characterTexture", this.Te.fontFramebuffer), this.ve.Et("u_charsetDimensions", [this.Te.textureColumns, this.Te.textureRows]), this.ve.Et("u_asciiCharacterTexture", this.pr.texture), this.ve.Et("u_primaryColorTexture", this.mr.texture), this.ve.Et("u_secondaryColorTexture", this.gr.texture), this.ve.Et("u_transformTexture", this.vr.texture), this.ve.Et("u_rotationTexture", this._r.texture), this.ve.Et("u_captureTexture", t.texture), this.ve.Et("u_backgroundMode", !1), this.ve.Et("u_captureDimensions", [t.width, t.height]), this.ve.Et("u_gridCellDimensions", [this.dr.cols, this.dr.rows]), this.ve.Et("u_gridPixelDimensions", [this.dr.width, this.dr.height]), this.ve.Gt(0, 0, this.Gr.width, this.Gr.height), this.Gr.end();
1356
- }
1357
- add(t) {
1358
- if (!x.m(t === "brightness" || t === "custom", 'Converter type must be either "brightness" or "custom".', { method: "add", providedValue: t })) return;
1359
- let e;
1360
- return e = t === "brightness" ? new Y(this.ve, this.Te, this.dr) : new D(this.ve, this.Te, this.dr), this.Pr.push(e), e;
1361
- }
1362
- remove(t) {
1363
- if (!x.m(t instanceof D, "Parameter must be a TextmodeConverter instance.", { method: "remove", providedValue: t })) return;
1364
- const e = this.Pr.indexOf(t);
1365
- x.m(e !== -1, "Converter instance not found in pipeline.", { method: "remove", providedValue: t, convertersCount: this.Pr.length }) && this.Pr.splice(e, 1);
1366
- }
1367
- swap(t, e) {
1368
- const r = (n, l) => {
1369
- if (typeof n == "number") return x.m(Number.isInteger(n) && n >= 0 && n < this.Pr.length, l + " index must be a valid integer within the converter array bounds.", { method: "swap", providedValue: n, convertersCount: this.Pr.length }) ? n : null;
1370
- if (n instanceof D) {
1371
- const c = this.Pr.indexOf(n);
1372
- return x.m(c !== -1, l + " converter instance not found in pipeline.", { method: "swap", providedValue: n, convertersCount: this.Pr.length }) ? c : null;
1373
- }
1374
- return x.m(!1, l + " parameter must be either an integer index or a TextmodeConverter instance.", { method: "swap", providedValue: n }), null;
1375
- }, s = r(t, "First"), i = r(e, "Second");
1376
- if (s === null || i === null || !x.m(s !== i, "Cannot swap a converter with itself.", { method: "swap", firstIndex: s, secondIndex: i })) return;
1377
- const o = this.Pr[s];
1378
- this.Pr[s] = this.Pr[i], this.Pr[i] = o;
1379
- }
1380
- rr() {
1381
- this.Gr.resize(this.dr.width, this.dr.height);
1382
- const t = this.dr.cols, e = this.dr.rows;
1383
- this.pr.resize(t, e), this.mr.resize(t, e), this.gr.resize(t, e), this._r.resize(t, e), this.vr.resize(t, e);
1384
- for (const r of this.Pr) r.rr();
1423
+ this.hi = requestAnimationFrame(e);
1385
1424
  }
1386
- hasEnabledConverters() {
1387
- return this.Pr.some((t) => t.options.enabled);
1425
+ stop() {
1426
+ this.hi && (cancelAnimationFrame(this.hi), this.hi = null);
1388
1427
  }
1389
- disable() {
1390
- for (const t of this.Pr) t.disable();
1428
+ pause() {
1429
+ this.li && (this.li = !1, this.stop());
1391
1430
  }
1392
- enable() {
1393
- for (const t of this.Pr) t.enable();
1431
+ resume(t) {
1432
+ this.li || (this.li = !0, this.start(t));
1394
1433
  }
1395
- P() {
1396
- for (const t of this.Pr) t.P();
1397
- this.pr.P(), this.mr.P(), this.gr.P(), this._r.P(), this.vr.P(), this.Gr.P(), this.Ar.P();
1434
+ frameRate(t, e) {
1435
+ if (t === void 0) return this.ui;
1436
+ this.oi = t, this.ai = 1e3 / t, this.li && e && (this.stop(), this.start(e));
1398
1437
  }
1399
- get texture() {
1400
- return this.Gr;
1438
+ measureFrameRate() {
1439
+ const t = performance.now();
1440
+ if (this.fi > 0) {
1441
+ const e = t - this.fi;
1442
+ this.di.push(e), this.di.length > this.pi && this.di.shift();
1443
+ const s = this.di.reduce((r, i) => r + i, 0) / this.di.length;
1444
+ this.ui = 1e3 / s;
1445
+ }
1446
+ this.fi = t;
1401
1447
  }
1402
- get characterFramebuffer() {
1403
- return this.pr;
1448
+ get isLooping() {
1449
+ return this.li;
1404
1450
  }
1405
- get primaryColorFramebuffer() {
1406
- return this.mr;
1451
+ get frameRateLimit() {
1452
+ return this.oi;
1407
1453
  }
1408
- get secondaryColorFramebuffer() {
1409
- return this.gr;
1454
+ get currentFrameRate() {
1455
+ return this.ui;
1410
1456
  }
1411
- get rotationFramebuffer() {
1412
- return this._r;
1457
+ get frameCount() {
1458
+ return this.gi;
1413
1459
  }
1414
- get transformFramebuffer() {
1415
- return this.vr;
1460
+ set frameCount(t) {
1461
+ this.gi = t;
1416
1462
  }
1417
- get brightness() {
1418
- return this.zr;
1463
+ incrementFrame() {
1464
+ this.gi++;
1419
1465
  }
1420
- get custom() {
1421
- return this.Er;
1466
+ resetFrameCount() {
1467
+ this.gi = 0;
1422
1468
  }
1423
1469
  }
1424
- const Ct = (a) => class extends a {
1425
- fill(t, e, r, s) {
1426
- this.ve.$t(t, e, r, s);
1470
+ const St = (a) => class extends a {
1471
+ rotate(t) {
1472
+ this.Cs.state.$t(t);
1427
1473
  }
1428
- stroke(t, e, r, s) {
1429
- this.ve.Ft(t, e, r, s);
1474
+ push() {
1475
+ this.Cs.state.vt();
1430
1476
  }
1431
- strokeWeight(t) {
1432
- this.ve.Tt(t);
1477
+ pop() {
1478
+ this.Cs.state.xt();
1433
1479
  }
1434
- noStroke() {
1435
- this.ve.Mt();
1480
+ rect(t, e, s = 1, r = 1) {
1481
+ this.Cs.Fe(t, e, s, r);
1436
1482
  }
1437
- noFill() {
1438
- this.ve.Dt();
1483
+ line(t, e, s, r) {
1484
+ this.Cs.Ge(t, e, s, r);
1439
1485
  }
1440
- rotate(t) {
1441
- this.ve.St(t);
1486
+ lineWeight(t) {
1487
+ this.Cs.state.wt(t);
1442
1488
  }
1443
- push() {
1444
- this.ve.Rt();
1489
+ background(t, e = t, s = t, r = 255) {
1490
+ this.Cs.We(t, e, s, r);
1445
1491
  }
1446
- pop() {
1447
- this.ve.Vt();
1492
+ char(t) {
1493
+ this.Cs.state.bt(this.Ps.Ss(t));
1448
1494
  }
1449
- rect(t, e, r = 1, s = 1) {
1450
- this.ve.Gt(t, e, r, s);
1495
+ charColor(t, e, s, r) {
1496
+ this.Cs.state.Tt(t, e, s, r);
1451
1497
  }
1452
- line(t, e, r, s) {
1453
- this.ve.Ut(t, e, r, s);
1498
+ cellColor(t, e, s, r) {
1499
+ this.Cs.state.zt(t, e, s, r);
1454
1500
  }
1455
- background(t, e = t, r = t, s = 255) {
1456
- this.ve.Ht(t, e, r, s);
1501
+ flipHorizontally(t) {
1502
+ this.Cs.state.Rt(t);
1457
1503
  }
1458
- createShader(t, e) {
1459
- return this.ve.Pt(t, e);
1504
+ flipVertically(t) {
1505
+ this.Cs.state.Mt(t);
1460
1506
  }
1461
- createFilterShader(t) {
1462
- return this.ve.zt(t);
1507
+ charRotation(t) {
1508
+ this.Cs.state.At(t);
1463
1509
  }
1464
- shader(t) {
1465
- this.ve.yt(t);
1510
+ invert(t) {
1511
+ this.Cs.state.St(t);
1466
1512
  }
1467
- setUniform(t, e) {
1468
- this.ve.Et(t, e);
1513
+ clear() {
1514
+ this.Cs.Jt();
1469
1515
  }
1470
- image(t, e, r, s, i) {
1471
- this.ve.Bt(t, e, r, s, i);
1516
+ ellipse(t, e, s, r) {
1517
+ this.Cs.De(t, e, s / 2, r / 2);
1472
1518
  }
1473
- clear() {
1474
- this.ve.jt();
1519
+ triangle(t, e, s, r, i, n) {
1520
+ this.Cs.Ie(t, e, s, r, i, n);
1521
+ }
1522
+ bezierCurve(t, e, s, r, i, n, o, h) {
1523
+ this.Cs.Be(t, e, s, r, i, n, o, h);
1475
1524
  }
1476
- createFramebuffer(t, e, r = {}) {
1477
- return this.ve.Lt(t, e, r);
1525
+ arc(t, e, s, r, i, n) {
1526
+ this.Cs.Ee(t, e, s, r, i, n);
1478
1527
  }
1479
1528
  };
1480
- class G {
1481
- Lr(t) {
1482
- const e = t.characterFramebuffer, r = t.primaryColorFramebuffer, s = t.secondaryColorFramebuffer, i = t.transformFramebuffer, o = t.rotationFramebuffer;
1483
- return e == null || e.loadPixels(), r == null || r.loadPixels(), s == null || s.loadPixels(), i == null || i.loadPixels(), o == null || o.loadPixels(), { characterPixels: (e == null ? void 0 : e.pixels) || new Uint8Array(0), primaryColorPixels: (r == null ? void 0 : r.pixels) || new Uint8Array(0), secondaryColorPixels: (s == null ? void 0 : s.pixels) || new Uint8Array(0), transformPixels: (i == null ? void 0 : i.pixels) || new Uint8Array(0), rotationPixels: (o == null ? void 0 : o.pixels) || new Uint8Array(0) };
1529
+ class B {
1530
+ _i(t) {
1531
+ const e = t.W(0), s = t.W(1), r = t.W(2), i = t.W(3);
1532
+ return { characterPixels: e, primaryColorPixels: s, secondaryColorPixels: r, transformPixels: t.W(4), rotationPixels: i };
1484
1533
  }
1485
- Hr(t, e) {
1534
+ mi(t, e) {
1486
1535
  return t[e] + (t[e + 1] << 8);
1487
1536
  }
1488
- jr(t, e) {
1537
+ xi(t, e) {
1489
1538
  return { r: t[e], g: t[e + 1], b: t[e + 2], a: t[e + 3] };
1490
1539
  }
1491
1540
  }
1492
- class V {
1493
- Or(t, e) {
1541
+ class O {
1542
+ Ci(t, e) {
1494
1543
  return new Blob([t], { type: e });
1495
1544
  }
1496
- Br(t, e, r) {
1545
+ yi(t, e, s) {
1497
1546
  try {
1498
- const s = this.Or(t, r), i = URL.createObjectURL(s), o = document.createElement("a");
1499
- o.href = i, o.download = e, o.style.display = "none", o.rel = "noopener", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(i);
1500
- } catch (s) {
1501
- throw console.error("Failed to download file:", s), Error("File download failed: " + (s instanceof Error ? s.message : "Unknown error"));
1547
+ const r = this.Ci(t, s), i = URL.createObjectURL(r), n = document.createElement("a");
1548
+ n.href = i, n.download = e, n.style.display = "none", n.rel = "noopener", document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(i);
1549
+ } catch (r) {
1550
+ throw console.error("Failed to download file:", r), Error("File download failed: " + (r instanceof Error ? r.message : "Unknown error"));
1502
1551
  }
1503
1552
  }
1504
- Wr() {
1553
+ wi() {
1505
1554
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/:/g, "-");
1506
1555
  }
1507
- Nr() {
1556
+ $i() {
1508
1557
  const t = /* @__PURE__ */ new Date();
1509
1558
  return { date: t.toISOString().split("T")[0], time: t.toTimeString().split(" ")[0].replace(/:/g, "-") };
1510
1559
  }
1511
- Xr(t) {
1560
+ bi(t) {
1512
1561
  return t.replace(/[<>:"/\\|?*]/g, "_").replace(/\s+/g, "_").replace(/_{2,}/g, "_").replace(/^_+|_+$/g, "").substring(0, 255);
1513
1562
  }
1514
- qr() {
1515
- return "'textmode-export'-" + this.Wr();
1563
+ Ti() {
1564
+ return "'textmode-export'-" + this.wi();
1516
1565
  }
1517
1566
  }
1518
- class _t extends G {
1519
- Yr(t, e, r) {
1520
- const s = t[r] === 255, i = t[r + 1] === 255, o = t[r + 2] === 255, n = e[r], l = e[r + 1];
1521
- return { isInverted: s, flipHorizontal: i, flipVertical: o, rotation: Math.round(360 * (n + l / 255) / 255 * 100) / 100 };
1522
- }
1523
- Qr(t, e, r) {
1524
- return { x: t, y: e, cellX: t * r.cellWidth, cellY: e * r.cellHeight };
1525
- }
1526
- Zr(t, e) {
1527
- const r = [];
1528
- let s = 0;
1529
- for (let i = 0; i < e.rows; i++) for (let o = 0; o < e.cols; o++) {
1530
- const n = 4 * s, l = this.Hr(t.characterPixels, n);
1531
- let c = this.jr(t.primaryColorPixels, n), u = this.jr(t.secondaryColorPixels, n);
1532
- const f = this.Yr(t.transformPixels, t.rotationPixels, n);
1567
+ class It extends B {
1568
+ zi(t, e, s) {
1569
+ const r = t[s] === 255, i = t[s + 1] === 255, n = t[s + 2] === 255, o = e[s], h = e[s + 1];
1570
+ return { isInverted: r, flipHorizontal: i, flipVertical: n, rotation: Math.round(360 * (o + h / 255) / 255 * 100) / 100 };
1571
+ }
1572
+ Ri(t, e, s) {
1573
+ return { x: t, y: e, cellX: t * s.cellWidth, cellY: e * s.cellHeight };
1574
+ }
1575
+ Mi(t, e) {
1576
+ const s = [];
1577
+ let r = 0;
1578
+ for (let i = 0; i < e.rows; i++) for (let n = 0; n < e.cols; n++) {
1579
+ const o = 4 * r, h = this.mi(t.characterPixels, o);
1580
+ let l = this.xi(t.primaryColorPixels, o), u = this.xi(t.secondaryColorPixels, o);
1581
+ const f = this.zi(t.transformPixels, t.rotationPixels, o);
1533
1582
  if (f.isInverted) {
1534
- const m = c;
1535
- c = u, u = m;
1583
+ const p = l;
1584
+ l = u, u = p;
1536
1585
  }
1537
- const d = this.Qr(o, i, e);
1538
- r.push({ charIndex: l, primaryColor: c, secondaryColor: u, transform: f, position: d }), s++;
1586
+ const d = this.Ri(n, i, e);
1587
+ s.push({ charIndex: h, primaryColor: l, secondaryColor: u, transform: f, position: d }), r++;
1539
1588
  }
1540
- return r;
1589
+ return s;
1541
1590
  }
1542
1591
  }
1543
- class yt {
1544
- Jr(t, e) {
1545
- const r = t.cmap;
1546
- for (const s of r.tables) if (s.format === 4) {
1547
- for (let i = 0; i < s.startCount.length; i++) if (e >= s.startCount[i] && e <= s.endCount[i]) {
1548
- if (s.idRangeOffset[i] === 0) return e + s.idDelta[i] & 65535;
1592
+ class Dt {
1593
+ Si(t, e) {
1594
+ const s = t.cmap;
1595
+ for (const r of s.tables) if (r.format === 4) {
1596
+ const i = r;
1597
+ for (let n = 0; n < i.startCount.length; n++) if (e >= i.startCount[n] && e <= i.endCount[n]) {
1598
+ if (i.idRangeOffset[n] === 0) return e + i.idDelta[n] & 65535;
1549
1599
  {
1550
- const o = s.idRangeOffset[i] / 2 + (e - s.startCount[i]) - (s.startCount.length - i);
1551
- if (o >= 0 && o < s.glyphIdArray.length) {
1552
- const n = s.glyphIdArray[o];
1553
- if (n !== 0) return n + s.idDelta[i] & 65535;
1600
+ const o = i.idRangeOffset[n] / 2 + (e - i.startCount[n]) - (i.startCount.length - n);
1601
+ if (o >= 0 && o < i.glyphIdArray.length) {
1602
+ const h = i.glyphIdArray[o];
1603
+ if (h !== 0) return h + i.idDelta[n] & 65535;
1554
1604
  }
1555
1605
  }
1556
1606
  }
1607
+ } else if (r.format === 12) {
1608
+ const i = r;
1609
+ for (let n = 0; n < i.groups.length; n += 3) {
1610
+ const o = i.groups[n], h = i.groups[n + 1], l = i.groups[n + 2];
1611
+ if (e >= o && e <= h) return l + (e - o);
1612
+ }
1557
1613
  }
1558
1614
  return 0;
1559
1615
  }
1560
- Kr(t, e, r, s, i) {
1561
- const o = i / t.head.unitsPerEm;
1562
- return { getBoundingBox: () => ({ x1: r + e.xMin * o, y1: s + -e.yMax * o, x2: r + e.xMax * o, y2: s + -e.yMin * o }), toSVG: () => this.ts(e, r, s, o) };
1616
+ Ai(t, e, s, r, i) {
1617
+ const n = i / t.head.unitsPerEm;
1618
+ return { getBoundingBox: () => ({ x1: s + e.xMin * n, y1: r + -e.yMax * n, x2: s + e.xMax * n, y2: r + -e.yMin * n }), toSVG: () => this.Pi(e, s, r, n) };
1563
1619
  }
1564
- ts(t, e, r, s) {
1620
+ Pi(t, e, s, r) {
1565
1621
  if (!t || !t.xs) return "";
1566
- const { xs: i, ys: o, endPts: n, flags: l } = t;
1567
- if (!(i && o && n && l)) return "";
1568
- let c = "", u = 0;
1569
- for (let f = 0; f < n.length; f++) {
1570
- const d = n[f];
1622
+ const { xs: i, ys: n, endPts: o, flags: h } = t;
1623
+ if (!(i && n && o && h)) return "";
1624
+ let l = "", u = 0;
1625
+ for (let f = 0; f < o.length; f++) {
1626
+ const d = o[f];
1571
1627
  if (!(d < u)) {
1572
1628
  if (d >= u) {
1573
- const m = e + i[u] * s, p = r - o[u] * s;
1574
- c += `M${m.toFixed(2)},${p.toFixed(2)}`;
1575
- let g = u + 1;
1576
- for (; g <= d; )
1577
- if (1 & l[g]) {
1578
- const C = e + i[g] * s, v = r - o[g] * s;
1579
- c += `L${C.toFixed(2)},${v.toFixed(2)}`, g++;
1629
+ const p = e + i[u] * r, g = s - n[u] * r;
1630
+ l += `M${p.toFixed(2)},${g.toFixed(2)}`;
1631
+ let m = u + 1;
1632
+ for (; m <= d; )
1633
+ if (1 & h[m]) {
1634
+ const T = e + i[m] * r, v = s - n[m] * r;
1635
+ l += `L${T.toFixed(2)},${v.toFixed(2)}`, m++;
1580
1636
  } else {
1581
- const C = e + i[g] * s, v = r - o[g] * s;
1582
- let b = g + 1 > d ? u : g + 1;
1583
- if (1 & l[b]) {
1584
- const T = e + i[b] * s, E = r - o[b] * s;
1585
- c += `Q${C.toFixed(2)},${v.toFixed(2)} ${T.toFixed(2)},${E.toFixed(2)}`, g = b + 1;
1637
+ const T = e + i[m] * r, v = s - n[m] * r;
1638
+ let b = m + 1 > d ? u : m + 1;
1639
+ if (1 & h[b]) {
1640
+ const _ = e + i[b] * r, S = s - n[b] * r;
1641
+ l += `Q${T.toFixed(2)},${v.toFixed(2)} ${_.toFixed(2)},${S.toFixed(2)}`, m = b + 1;
1586
1642
  } else {
1587
- const T = (C + (e + i[b] * s)) / 2, E = (v + (r - o[b] * s)) / 2;
1588
- c += `Q${C.toFixed(2)},${v.toFixed(2)} ${T.toFixed(2)},${E.toFixed(2)}`, g = b;
1643
+ const _ = (T + (e + i[b] * r)) / 2, S = (v + (s - n[b] * r)) / 2;
1644
+ l += `Q${T.toFixed(2)},${v.toFixed(2)} ${_.toFixed(2)},${S.toFixed(2)}`, m = b;
1589
1645
  }
1590
1646
  }
1591
- c += "Z";
1647
+ l += "Z";
1592
1648
  }
1593
1649
  u = d + 1;
1594
1650
  }
1595
1651
  }
1596
- return c;
1652
+ return l;
1597
1653
  }
1598
- es(t, e, r, s, i) {
1599
- const o = t.codePointAt(0) || 0, n = this.Jr(e, o);
1600
- let l = null;
1601
- return e.glyf && e.glyf[n] !== null ? l = e.glyf[n] : y && y.T && y.T.glyf && y.T.glyf.Wt && (l = y.T.glyf.Wt(e, n), e.glyf && l && (e.glyf[n] = l)), this.Kr(e, l, r, s, i);
1654
+ Fi(t, e, s, r, i) {
1655
+ const n = t.codePointAt(0) || 0, o = this.Si(e, n);
1656
+ let h = null;
1657
+ return e.glyf && e.glyf[o] !== null ? h = e.glyf[o] : (h = E.T.glyf.Oe(e, o), e.glyf[o] = h), this.Ai(e, h, s, r, i);
1602
1658
  }
1603
- rs(t, e, r, s, i, o, n, l) {
1604
- const c = r + (i - l * (n / e.head.unitsPerEm)) / 2, u = s + (o + 0.7 * n) / 2;
1605
- return this.es(t, e, c, u, n).toSVG() || null;
1659
+ Gi(t, e, s, r, i, n, o, h) {
1660
+ const l = s + (i - h * (o / e.head.unitsPerEm)) / 2, u = r + (n + 0.7 * o) / 2;
1661
+ return this.Fi(t, e, l, u, o).toSVG() || null;
1606
1662
  }
1607
1663
  }
1608
- class Tt {
1664
+ class Lt {
1609
1665
  constructor() {
1610
- h(this, "ss");
1611
- this.ss = new yt();
1666
+ c(this, "Di");
1667
+ this.Di = new Dt();
1612
1668
  }
1613
- ns(t) {
1669
+ Ii(t) {
1614
1670
  return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
1615
1671
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
1616
1672
  <svg width="${t.width}" height="${t.height}" viewBox="0 0 ${t.width} ${t.height}"
@@ -1618,175 +1674,173 @@ class Tt {
1618
1674
  <title>textmode art generated via textmode.js</title>
1619
1675
  <desc>textmode art visualization generated by textmode.js library</desc>`;
1620
1676
  }
1621
- hs() {
1677
+ Bi() {
1622
1678
  return `
1623
1679
  </g>
1624
1680
  </svg>`;
1625
1681
  }
1626
- ls(t, e) {
1682
+ Li(t, e) {
1627
1683
  if (!e.includeBackgroundRectangles) return "";
1628
- const r = e.backgroundColor, s = `rgba(${r[0]},${r[1]},${r[2]},${r[3] / 255})`;
1684
+ const s = e.backgroundColor, r = `rgba(${s[0]},${s[1]},${s[2]},${s[3] / 255})`;
1629
1685
  return `
1630
- <rect width="${t.width}" height="${t.height}" fill="${s}" />`;
1686
+ <rect width="${t.width}" height="${t.height}" fill="${r}" />`;
1631
1687
  }
1632
- cs(t) {
1688
+ Ei(t) {
1633
1689
  return `rgba(${t.r},${t.g},${t.b},${t.a / 255})`;
1634
1690
  }
1635
- us(t, e) {
1636
- const { transform: r, position: s } = t, i = s.cellX + e.cellWidth / 2, o = s.cellY + e.cellHeight / 2, n = [];
1637
- if (r.flipHorizontal || r.flipVertical) {
1638
- const l = r.flipHorizontal ? -1 : 1, c = r.flipVertical ? -1 : 1;
1639
- n.push(`translate(${i} ${o})`), n.push(`scale(${l} ${c})`), n.push(`translate(${-i} ${-o})`);
1691
+ Wi(t, e) {
1692
+ const { transform: s, position: r } = t, i = r.cellX + e.cellWidth / 2, n = r.cellY + e.cellHeight / 2, o = [];
1693
+ if (s.flipHorizontal || s.flipVertical) {
1694
+ const h = s.flipHorizontal ? -1 : 1, l = s.flipVertical ? -1 : 1;
1695
+ o.push(`translate(${i} ${n})`), o.push(`scale(${h} ${l})`), o.push(`translate(${-i} ${-n})`);
1640
1696
  }
1641
- return r.rotation && n.push(`rotate(${r.rotation} ${i} ${o})`), n.length ? ` transform="${n.join(" ")}"` : "";
1697
+ return s.rotation && o.push(`rotate(${s.rotation} ${i} ${n})`), o.length ? ` transform="${o.join(" ")}"` : "";
1642
1698
  }
1643
- fs(t, e, r) {
1644
- if (!r.includeBackgroundRectangles || t.secondaryColor.a === 0) return "";
1645
- const { position: s } = t, i = this.cs(t.secondaryColor);
1646
- return r.drawMode === "stroke" ? `
1647
- <rect x="${s.cellX}" y="${s.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" stroke="${i}" fill="none" stroke-width="${r.strokeWidth}" />` : `
1648
- <rect x="${s.cellX}" y="${s.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" fill="${i}" />`;
1699
+ ki(t, e, s) {
1700
+ if (!s.includeBackgroundRectangles || t.secondaryColor.a === 0) return "";
1701
+ const { position: r } = t, i = this.Ei(t.secondaryColor);
1702
+ return s.drawMode === "stroke" ? `
1703
+ <rect x="${r.cellX}" y="${r.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" stroke="${i}" fill="none" stroke-width="${s.strokeWidth}" />` : `
1704
+ <rect x="${r.cellX}" y="${r.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" fill="${i}" />`;
1649
1705
  }
1650
- es(t, e, r, s) {
1651
- const i = r.characters[t.charIndex];
1706
+ Fi(t, e, s, r) {
1707
+ const i = s.characters[t.charIndex];
1652
1708
  if (!i) return "";
1653
- const o = this.ss.rs(i.character, r.font, t.position.cellX, t.position.cellY, e.cellWidth, e.cellHeight, r.fontSize, i.advanceWidth);
1654
- if (!o) return "";
1655
- const n = this.cs(t.primaryColor);
1656
- return s.drawMode === "stroke" ? `
1657
- <path id="${`path-${t.charIndex}-${t.position.cellX}-${t.position.cellY}`.replace(/\./g, "-")}" d="${o}" stroke="${n}" stroke-width="${s.strokeWidth}" fill="none" />` : `
1658
- <path d="${o}" fill="${n}" />`;
1709
+ const n = this.Di.Gi(i.character, s.font, t.position.cellX, t.position.cellY, e.cellWidth, e.cellHeight, s.fontSize, i.advanceWidth);
1710
+ if (!n) return "";
1711
+ const o = this.Ei(t.primaryColor);
1712
+ return r.drawMode === "stroke" ? `
1713
+ <path id="${`path-${t.charIndex}-${t.position.cellX}-${t.position.cellY}`.replace(/\./g, "-")}" d="${n}" stroke="${o}" stroke-width="${r.strokeWidth}" fill="none" />` : `
1714
+ <path d="${n}" fill="${o}" />`;
1659
1715
  }
1660
- ds(t, e, r, s) {
1716
+ Vi(t, e, s, r) {
1661
1717
  let i = "";
1662
- i += this.fs(t, e, s);
1663
- const o = this.us(t, e), n = this.es(t, e, r, s);
1664
- return n && (o ? (i += `
1665
- <g${o}>`, i += n, i += `
1666
- </g>`) : i += n), i;
1667
- }
1668
- ps(t, e, r, s) {
1669
- let i = this.ns(e);
1670
- i += this.ls(e, s), i += `
1718
+ i += this.ki(t, e, r);
1719
+ const n = this.Wi(t, e), o = this.Fi(t, e, s, r);
1720
+ return o && (n ? (i += `
1721
+ <g${n}>`, i += o, i += `
1722
+ </g>`) : i += o), i;
1723
+ }
1724
+ Oi(t, e, s, r) {
1725
+ let i = this.Ii(e);
1726
+ i += this.Li(e, r), i += `
1671
1727
  <g id="ascii-cells">`;
1672
- for (const o of t) i += this.ds(o, e, r, s);
1673
- return i += this.hs(), i;
1728
+ for (const n of t) i += this.Vi(n, e, s, r);
1729
+ return i += this.Bi(), i;
1674
1730
  }
1675
- gs(t) {
1731
+ Ui(t) {
1676
1732
  return t.replace(/<path[^>]*d=""[^>]*\/>/g, "").replace(/\n\s*\n/g, `
1677
1733
  `).replace(/[ \t]+$/gm, "");
1678
1734
  }
1679
1735
  }
1680
- class Et extends V {
1681
- _s(t) {
1682
- return this.Or(t, "image/svg+xml;charset=utf-8");
1736
+ class Mt extends O {
1737
+ ji(t) {
1738
+ return this.Ci(t, "image/svg+xml;charset=utf-8");
1683
1739
  }
1684
- vs(t, e) {
1685
- this.Br(t, this.Xr(e) + ".svg", "image/svg+xml;charset=utf-8");
1740
+ Hi(t, e) {
1741
+ this.yi(t, this.bi(e) + ".svg", "image/svg+xml;charset=utf-8");
1686
1742
  }
1687
- bs(t, e) {
1688
- this.vs(t, e || this.qr());
1743
+ qi(t, e) {
1744
+ this.Hi(t, e || this.Ti());
1689
1745
  }
1690
1746
  }
1691
- class z {
1747
+ class N {
1692
1748
  constructor() {
1693
- h(this, "ws");
1694
- h(this, "Cs");
1695
- h(this, "$s");
1696
- this.ws = new _t(), this.Cs = new Tt(), this.$s = new Et();
1749
+ c(this, "Ni");
1750
+ c(this, "Xi");
1751
+ c(this, "Yi");
1752
+ this.Ni = new It(), this.Xi = new Lt(), this.Yi = new Mt();
1697
1753
  }
1698
- Fs(t) {
1699
- return { includeBackgroundRectangles: t.includeBackgroundRectangles ?? !0, drawMode: t.drawMode ?? "fill", strokeWidth: t.strokeWidth ?? 1, backgroundColor: t.backgroundColor ?? [0, 0, 0, 0] };
1754
+ Qi(t) {
1755
+ return { includeBackgroundRectangles: t.includeBackgroundRectangles ?? !0, drawMode: t.drawMode ?? "fill", strokeWidth: t.strokeWidth ?? 1, backgroundColor: t.backgroundColor ?? [0, 0, 0, 0], filename: t.filename || this.Yi.Ti() };
1700
1756
  }
1701
- Ts(t, e = {}) {
1702
- const r = this.Fs(e), s = this.ws.Lr(t.pipeline), i = this.ws.Zr(s, t.grid), o = this.Cs.ps(i, t.grid, t.font, r);
1703
- return this.Cs.gs(o);
1757
+ Zi(t, e = {}) {
1758
+ const s = this.Ni.Mi(this.Ni._i(t.pipeline), t.grid), r = this.Xi.Oi(s, t.grid, t.font, this.Qi(e));
1759
+ return this.Xi.Ui(r);
1704
1760
  }
1705
- bs(t, e = {}) {
1706
- const r = this.Ts(t, e), s = e.filename || this.$s.qr();
1707
- this.$s.bs(r, s);
1761
+ qi(t, e = {}) {
1762
+ this.Yi.qi(this.Zi(t, e), e.filename);
1708
1763
  }
1709
1764
  }
1710
- class Rt extends G {
1711
- Ms(t, e, r, s = " ") {
1712
- var n;
1765
+ class Ut extends B {
1766
+ Ji(t, e, s, r = " ") {
1767
+ var o;
1713
1768
  const i = [];
1714
- let o = 0;
1715
- for (let l = 0; l < e.rows; l++) {
1716
- const c = [];
1769
+ let n = 0;
1770
+ for (let h = 0; h < e.rows; h++) {
1771
+ const l = [];
1717
1772
  for (let u = 0; u < e.cols; u++) {
1718
- const f = 4 * o, d = this.Hr(t.characterPixels, f), m = ((n = r.characters[d]) == null ? void 0 : n.character) || s;
1719
- c.push(m), o++;
1773
+ const f = 4 * n, d = this.mi(t.characterPixels, f), p = ((o = s.characters[d]) == null ? void 0 : o.character) || r;
1774
+ l.push(p), n++;
1720
1775
  }
1721
- i.push(c);
1776
+ i.push(l);
1722
1777
  }
1723
1778
  return i;
1724
1779
  }
1725
1780
  }
1726
- class Ft {
1727
- Ds(t, e) {
1728
- const r = [];
1781
+ class zt {
1782
+ Ki(t, e) {
1783
+ const s = [];
1729
1784
  for (const i of t) {
1730
- let o = i.join("");
1731
- e.preserveTrailingSpaces || (o = o.replace(/\s+$/, "")), r.push(o);
1785
+ let n = i.join("");
1786
+ e.preserveTrailingSpaces || (n = n.replace(/\s+$/, "")), s.push(n);
1732
1787
  }
1733
- const s = e.lineEnding === "crlf" ? `\r
1788
+ const r = e.lineEnding === "crlf" ? `\r
1734
1789
  ` : `
1735
1790
  `;
1736
- return r.join(s);
1791
+ return s.join(r);
1737
1792
  }
1738
1793
  }
1739
- class Pt extends V {
1740
- Ss(t, e) {
1741
- const r = this.Rs(e);
1742
- this.Br(t, r, "text/plain;charset=utf-8");
1794
+ class Bt extends O {
1795
+ tr(t, e) {
1796
+ const s = this.er(e);
1797
+ this.yi(t, s, "text/plain;charset=utf-8");
1743
1798
  }
1744
- Rs(t) {
1745
- let e = this.Xr(t);
1746
- return e === ".txt" || e.length <= 4 ? this.qr() : e;
1799
+ er(t) {
1800
+ let e = this.bi(t);
1801
+ return e === ".txt" || e.length <= 4 ? this.Ti() : e;
1747
1802
  }
1748
1803
  }
1749
- class H {
1804
+ class V {
1750
1805
  constructor() {
1751
- h(this, "ws");
1752
- h(this, "Cs");
1753
- h(this, "$s");
1754
- this.ws = new Rt(), this.Cs = new Ft(), this.$s = new Pt();
1806
+ c(this, "Ni");
1807
+ c(this, "Xi");
1808
+ c(this, "Yi");
1809
+ this.Ni = new Ut(), this.Xi = new zt(), this.Yi = new Bt();
1755
1810
  }
1756
- Fs(t) {
1757
- return { preserveTrailingSpaces: t.preserveTrailingSpaces ?? !1, lineEnding: t.lineEnding ?? "lf", emptyCharacter: t.emptyCharacter ?? " " };
1811
+ Qi(t) {
1812
+ return { preserveTrailingSpaces: t.preserveTrailingSpaces ?? !1, lineEnding: t.lineEnding ?? "lf", emptyCharacter: t.emptyCharacter ?? " ", filename: t.filename || this.Yi.Ti() };
1758
1813
  }
1759
- Vs(t, e = {}) {
1760
- const r = this.Fs(e), s = this.ws.Lr(t.pipeline), i = this.ws.Ms(s, t.grid, t.font, r.emptyCharacter);
1761
- return this.Cs.Ds(i, r);
1814
+ sr(t, e = {}) {
1815
+ const s = this.Qi(e), r = this.Ni.Ji(this.Ni._i(t.pipeline), t.grid, t.font, s.emptyCharacter);
1816
+ return this.Xi.Ki(r, s);
1762
1817
  }
1763
- Ss(t, e = {}) {
1764
- const r = this.Vs(t, e), s = e.filename || this.$s.qr();
1765
- this.$s.Ss(r, s);
1818
+ tr(t, e = {}) {
1819
+ this.Yi.tr(this.sr(t, e), e.filename);
1766
1820
  }
1767
1821
  }
1768
- class Mt extends G {
1769
- ks(t, e = 1, r = "transparent") {
1770
- const s = t.canvas;
1771
- if (e === 1 && r === "transparent") return s;
1772
- const i = document.createElement("canvas"), o = i.getContext("2d"), n = Math.round(s.width * e), l = Math.round(s.height * e);
1773
- return i.width = n, i.height = l, r !== "transparent" && (o.fillStyle = r, o.fillRect(0, 0, n, l)), o.imageSmoothingEnabled = !1, o.drawImage(s, 0, 0, s.width, s.height, 0, 0, n, l), i;
1822
+ class Ot extends B {
1823
+ ir(t, e = 1, s = "transparent") {
1824
+ const r = t.canvas;
1825
+ if (e === 1 && s === "transparent") return r;
1826
+ const i = document.createElement("canvas"), n = i.getContext("2d"), o = Math.round(r.width * e), h = Math.round(r.height * e);
1827
+ return i.width = o, i.height = h, s !== "transparent" && (n.fillStyle = s, n.fillRect(0, 0, o, h)), n.imageSmoothingEnabled = !1, n.drawImage(r, 0, 0, r.width, r.height, 0, 0, o, h), i;
1774
1828
  }
1775
1829
  }
1776
- class At {
1777
- Is(t, e) {
1778
- const r = this.Ps(e.format);
1779
- return e.format === "png" ? t.toDataURL(r) : t.toDataURL(r, e.quality);
1780
- }
1781
- async zs(t, e) {
1782
- return new Promise((r, s) => {
1783
- const i = this.Ps(e.format), o = (n) => {
1784
- n ? r(n) : s(Error(`Failed to generate ${e.format.toUpperCase()} blob`));
1830
+ class $t {
1831
+ rr(t, e) {
1832
+ const s = this.nr(e.format);
1833
+ return e.format === "png" ? t.toDataURL(s) : t.toDataURL(s, e.quality);
1834
+ }
1835
+ async ar(t, e) {
1836
+ return new Promise((s, r) => {
1837
+ const i = this.nr(e.format), n = (o) => {
1838
+ o ? s(o) : r(Error(`Failed to generate ${e.format.toUpperCase()} blob`));
1785
1839
  };
1786
- e.format === "png" ? t.toBlob(o, i) : t.toBlob(o, i, e.quality);
1840
+ e.format === "png" ? t.toBlob(n, i) : t.toBlob(n, i, e.quality);
1787
1841
  });
1788
1842
  }
1789
- Ps(t) {
1843
+ nr(t) {
1790
1844
  switch (t) {
1791
1845
  case "png":
1792
1846
  return "image/png";
@@ -1799,273 +1853,208 @@ class At {
1799
1853
  }
1800
1854
  }
1801
1855
  }
1802
- const Dt = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" }, N = { png: ".png", jpg: ".jpg", webp: ".webp" };
1803
- class St extends V {
1804
- Es(t, e, r) {
1805
- this.Gs(t, this.Xr(e) + N[r]);
1856
+ const Wt = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" }, k = { png: ".png", jpg: ".jpg", webp: ".webp" };
1857
+ class Gt extends O {
1858
+ hr(t, e, s) {
1859
+ this.cr(t, this.bi(e) + k[s]);
1806
1860
  }
1807
- Gs(t, e) {
1808
- const r = URL.createObjectURL(t);
1861
+ cr(t, e) {
1862
+ const s = URL.createObjectURL(t);
1809
1863
  try {
1810
- const s = document.createElement("a");
1811
- s.href = r, s.download = e, s.style.display = "none", s.rel = "noopener", document.body.appendChild(s), s.click(), document.body.removeChild(s);
1864
+ const r = document.createElement("a");
1865
+ r.href = s, r.download = e, r.style.display = "none", r.rel = "noopener", document.body.appendChild(r), r.click(), document.body.removeChild(r);
1812
1866
  } finally {
1813
- URL.revokeObjectURL(r);
1867
+ URL.revokeObjectURL(s);
1814
1868
  }
1815
1869
  }
1816
- As(t) {
1817
- return t in Dt && t in N;
1870
+ lr(t) {
1871
+ return t in Wt && t in k;
1818
1872
  }
1819
1873
  }
1820
- class Ut {
1874
+ class Nt {
1821
1875
  constructor() {
1822
- h(this, "ws");
1823
- h(this, "Cs");
1824
- h(this, "$s");
1825
- this.ws = new Mt(), this.Cs = new At(), this.$s = new St();
1876
+ c(this, "Ni");
1877
+ c(this, "Xi");
1878
+ c(this, "Yi");
1879
+ this.Ni = new Ot(), this.Xi = new $t(), this.Yi = new Gt();
1826
1880
  }
1827
- Fs(t) {
1828
- return { format: t.format ?? "png", quality: t.quality ?? 1, scale: t.scale ?? 1, backgroundColor: t.backgroundColor ?? "transparent" };
1881
+ Qi(t) {
1882
+ return { format: t.format ?? "png", quality: t.quality ?? 1, scale: t.scale ?? 1, backgroundColor: t.backgroundColor ?? "transparent", filename: t.filename || this.Yi.Ti() };
1829
1883
  }
1830
- Us(t) {
1831
- if (console.log("Validating image export options:", t), !this.$s.As(t.format)) throw Error(`Saving '${t.format}' files is not supported`);
1884
+ ur(t) {
1885
+ if (!this.Yi.lr(t.format)) throw Error(`Saving '${t.format}' files is not supported`);
1832
1886
  if (t.quality < 0 || t.quality > 1) throw Error("Image quality must be between 0.0 and 1.0");
1833
1887
  if (t.scale <= 0) throw Error("Scale factor must be greater than 0");
1834
- t.scale > 10 && console.warn("Large scale factors may result in very large files and slow performance"), t.format === "jpg" && t.backgroundColor === "transparent" && (t.backgroundColor = "black");
1835
- }
1836
- Ls(t, e = {}) {
1837
- const r = this.Fs(e);
1838
- if (this.Us(r), r.scale === 1 && r.backgroundColor === "transparent") return this.Cs.Is(t.canvas, r);
1839
- const s = this.ws.ks(t, r.scale, r.backgroundColor);
1840
- return this.Cs.Is(s, r);
1888
+ t.format === "jpg" && t.backgroundColor === "transparent" && (t.backgroundColor = "black");
1841
1889
  }
1842
- async zs(t, e = {}) {
1843
- const r = this.Fs(e);
1844
- if (this.Us(r), r.scale === 1 && r.backgroundColor === "transparent") return await this.Cs.zs(t.canvas, r);
1845
- const s = this.ws.ks(t, r.scale, r.backgroundColor);
1846
- return await this.Cs.zs(s, r);
1890
+ async ar(t, e) {
1891
+ if (e.scale === 1 && e.backgroundColor === "transparent") return await this.Xi.ar(t.canvas, e);
1892
+ const s = this.Ni.ir(t, e.scale, e.backgroundColor);
1893
+ return await this.Xi.ar(s, e);
1847
1894
  }
1848
- async Es(t, e = {}) {
1849
- const r = await this.zs(t, e), s = e.format ?? "png", i = e.filename || this.$s.qr();
1850
- this.$s.Es(r, i, s);
1895
+ async hr(t, e = {}) {
1896
+ const s = this.Qi(e);
1897
+ this.ur(s);
1898
+ const r = await this.ar(t, s);
1899
+ this.Yi.hr(r, s.filename, s.format);
1851
1900
  }
1852
1901
  }
1853
- const $t = (a) => class extends a {
1902
+ const Vt = (a) => class extends a {
1903
+ dr() {
1904
+ this.Cs.Ve(this.pr);
1905
+ }
1854
1906
  toString(t = {}) {
1855
- return new H().Vs({ pipeline: this.Hs, grid: this.dr, font: this.Te }, t);
1907
+ return this.dr(), new V().sr({ pipeline: this.gr, grid: this._r, font: this.Ps }, t);
1856
1908
  }
1857
1909
  saveStrings(t = {}) {
1858
- new H().Ss({ pipeline: this.Hs, grid: this.dr, font: this.Te }, t);
1910
+ this.dr(), new V().tr({ pipeline: this.gr, grid: this._r, font: this.Ps }, t);
1859
1911
  }
1860
1912
  toSVG(t = {}) {
1861
- return new z().Ts(this, t);
1913
+ return this.dr(), new N().Zi(this, t);
1862
1914
  }
1863
1915
  saveSVG(t = {}) {
1864
- new z().bs(this, t);
1916
+ this.dr(), new N().qi(this, t);
1865
1917
  }
1866
- async saveCanvas(t, e = "png", r = {}) {
1867
- await new Ut().Es(this.Ye, { ...r, filename: t, format: e });
1918
+ async saveCanvas(t = {}) {
1919
+ await new Nt().hr(this.Js, t);
1868
1920
  }
1869
- }, It = (a) => class extends a {
1921
+ }, kt = (a) => class extends a {
1870
1922
  async loadFont(t) {
1871
- return this.Te.Oe(t).then(() => {
1872
- const e = this.Te.maxGlyphDimensions;
1873
- this.dr.Ke(e.width, e.height), this.Hs.rr();
1923
+ return this.Ps.Ns(t).then(() => {
1924
+ const e = this.Ps.maxGlyphDimensions;
1925
+ this._r.ei(e.width, e.height), this.Cs.ke();
1874
1926
  });
1875
1927
  }
1876
1928
  fontSize(t) {
1877
- if (!x.m(typeof t == "number" && t > 0, "Font size must be a positive number greater than 0.", { method: "fontSize", providedValue: t }) || this.Te.fontSize === t) return;
1878
- this.Te.je(t);
1879
- const e = this.Te.maxGlyphDimensions;
1880
- this.dr.Ke(e.width, e.height), this.Hs.rr(), this.ve.Ot();
1929
+ if (!I._(typeof t == "number" && t > 0, "Font size must be a positive number greater than 0.", { method: "fontSize", providedValue: t }) || this.Ps.fontSize === t) return;
1930
+ this.Ps.qs(t);
1931
+ const e = this.Ps.maxGlyphDimensions;
1932
+ this._r.ei(e.width, e.height), this.Cs.ke();
1881
1933
  }
1882
- }, kt = (a) => class extends a {
1883
- addConverter(t) {
1884
- return this.Hs.add(t);
1885
- }
1886
- removeConverter(t) {
1887
- this.Hs.remove(t);
1888
- }
1889
- };
1890
- class Lt {
1891
- constructor() {
1892
- h(this, "ve");
1893
- h(this, "Te");
1894
- h(this, "Hs");
1895
- h(this, "Ye");
1896
- h(this, "dr");
1897
- }
1898
- }
1899
- class X extends function(e, ...r) {
1900
- return r.reduce((s, i) => i(s), e);
1901
- }(Lt, Ct, $t, It, kt) {
1902
- constructor(e = null, r = {}) {
1903
- super();
1904
- h(this, "ir");
1905
- h(this, "js");
1906
- h(this, "ar");
1907
- h(this, "Os");
1908
- h(this, "Bs");
1909
- h(this, "Ws", null);
1910
- h(this, "Ns", 0);
1911
- h(this, "Xs");
1912
- h(this, "qs", !0);
1913
- h(this, "Ys", 0);
1914
- h(this, "Qs", 0);
1915
- h(this, "Zs", 0);
1916
- h(this, "Js", []);
1917
- h(this, "Ks", 10);
1918
- h(this, "ti", !1);
1919
- h(this, "ei", !1);
1920
- h(this, "ri", () => {
1921
- });
1922
- h(this, "si", () => {
1923
- });
1924
- h(this, "ii");
1925
- this.ir = e, this.ei = e === null, this.Os = r.renderMode ?? "auto", this.Bs = r.frameRate ?? 60, this.Xs = 1e3 / this.Bs;
1934
+ }, Xt = (a) => class extends a {
1935
+ get frameCount() {
1936
+ return this.mr.frameCount;
1926
1937
  }
1927
- static async create(e = null, r = {}) {
1928
- const s = new this(e, r), i = s.ei ? r : void 0;
1929
- let o, n;
1930
- s.Ye = new vt(s.ir, s.ei, i), s.ve = new ot(s.Ye.cr()), s.ei ? (o = r.width || 800, n = r.height || 600) : (o = s.Ye.width || 800, n = s.Ye.height || 600), s.js = s.ve.Lt(o, n), s.Te = new pt(s.ve, r.fontSize ?? 16), await s.Te.Ue(r.fontSource);
1931
- const l = s.Te.maxGlyphDimensions;
1932
- return s.dr = new mt(s.Ye.canvas, l.width, l.height), s.Hs = new wt(s.ve, s.Te, s.dr), s.oi(), s.ni(), s;
1938
+ set frameCount(t) {
1939
+ this.mr.frameCount = t;
1933
1940
  }
1934
- oi() {
1935
- this.ii = () => {
1936
- this.ei ? this.si() : this.ai();
1937
- }, window.addEventListener("resize", this.ii), window.ResizeObserver && this.ir && !this.ei && (this.ar = new ResizeObserver(() => {
1938
- this.ai();
1939
- }), this.ar.observe(this.ir));
1941
+ frameRate(t) {
1942
+ return t === void 0 ? this.mr.currentFrameRate : this.mr.frameRate(t, () => this.vr());
1940
1943
  }
1941
- render() {
1942
- this.hi(), this.Zs++, this.ti ? console.warn("Cannot render: Required resources have been disposed") : (this.ei ? (this.js.begin(), this.ri(), this.js.end()) : this.js.update(this.ir), this.Hs.hasEnabledConverters() ? (this.Hs.Ur(this.js), this.ve.Ht(0), this.ve.Bt(this.Hs.texture, this.dr.offsetX, this.dr.offsetY, this.Hs.texture.width, this.Hs.texture.height)) : (this.ve.jt(), this.ve.Bt(this.js, this.dr.offsetX, this.dr.offsetY, this.js.width, this.js.height)));
1944
+ noLoop() {
1945
+ this.mr.pause();
1943
1946
  }
1944
- ai() {
1945
- this.Ye.rr(), this.js.resize(this.Ye.width, this.Ye.height), this.dr.rr(), this.Hs.rr(), this.ve.Ot(), this.Os !== "manual" && this.render();
1947
+ loop() {
1948
+ this.mr.resume(() => this.vr());
1946
1949
  }
1947
- ni() {
1948
- if (this.Os !== "auto" || !this.qs) return;
1949
- this.Ns = performance.now();
1950
- const e = (r) => {
1951
- if (!this.qs) return void (this.Ws = null);
1952
- const s = r - this.Ns;
1953
- s >= this.Xs && (this.render(), this.Ns = r - s % this.Xs), this.qs && (this.Ws = requestAnimationFrame(e));
1954
- };
1955
- this.Ws = requestAnimationFrame(e);
1956
- }
1957
- hi() {
1958
- const e = performance.now();
1959
- if (this.Qs > 0) {
1960
- const r = e - this.Qs;
1961
- this.Js.push(r), this.Js.length > this.Ks && this.Js.shift();
1962
- const s = this.Js.reduce((i, o) => i + o, 0) / this.Js.length;
1963
- this.Ys = 1e3 / s;
1964
- }
1965
- this.Qs = e;
1950
+ redraw(t = 1) {
1951
+ if (I._(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.vr();
1966
1952
  }
1967
- li() {
1968
- this.Ws && (cancelAnimationFrame(this.Ws), this.Ws = null);
1953
+ isLooping() {
1954
+ return this.mr.isLooping;
1969
1955
  }
1970
- renderMode(e) {
1971
- this.Os !== e && (this.li(), this.Os = e, e === "auto" && this.qs && this.ni());
1956
+ };
1957
+ class Yt {
1958
+ constructor() {
1959
+ c(this, "Cs");
1960
+ c(this, "Ps");
1961
+ c(this, "Js");
1962
+ c(this, "_r");
1963
+ c(this, "mr");
1964
+ c(this, "pr");
1965
+ c(this, "gr");
1966
+ c(this, "Cr");
1972
1967
  }
1973
- frameRate(e) {
1974
- if (e === void 0) return this.Ys;
1975
- this.Bs = e, this.Xs = 1e3 / e, this.Os === "auto" && this.qs && (this.li(), this.ni());
1968
+ vr() {
1976
1969
  }
1977
- noLoop() {
1978
- this.qs && (this.qs = !1, this.Ws && (cancelAnimationFrame(this.Ws), this.Ws = null));
1970
+ }
1971
+ class jt extends function(e, ...s) {
1972
+ return s.reduce((r, i) => i(r), e);
1973
+ }(Yt, St, Vt, kt, Xt) {
1974
+ constructor(e = {}) {
1975
+ super();
1976
+ c(this, "yr", !1);
1977
+ c(this, "wr", () => {
1978
+ });
1979
+ c(this, "$r", () => {
1980
+ });
1981
+ c(this, "br");
1982
+ this.Js = new Pt(e), this.Cs = new mt(this.Js.ni()), this.Ps = new At(this.Cs, e.fontSize ?? 16), this.mr = new Ft(e.frameRate ?? 60), this.pr = this.Cs.Ae(`#version 300 es
1983
+ 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 float a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float oneMinusT=1.0-t;float oneMinusT2=oneMinusT*oneMinusT;float oneMinusT3=oneMinusT2*oneMinusT;float t2=t*t;float t3=t2*t;return oneMinusT3*p0+3.0*oneMinusT2*t*p1+3.0*oneMinusT*t2*p2+t3*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float oneMinusT=1.0-t;float oneMinusT2=oneMinusT*oneMinusT;float t2=t*t;return-3.0*oneMinusT2*p0+3.0*oneMinusT2*p1-6.0*oneMinusT*t*p1+6.0*oneMinusT*t*p2-3.0*t2*p2+3.0*t2*p3;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 worldPosition;bool isBezierCurve=length(a_instanceBezierCP1)>0.0||length(a_instanceBezierCP2)>0.0||length(a_instanceBezierStart)>0.0||length(a_instanceBezierEnd)>0.0;bool isArc=a_instanceArcAngles.x!=0.0||a_instanceArcAngles.y!=0.0;if(isBezierCurve){float t=a_position.x;float thicknessOffset=a_position.y;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tangentLength=length(tangent);if(tangentLength>0.0){tangent=tangent/tangentLength;}else{tangent=vec2(1.0,0.0);}vec2 normal=vec2(-tangent.y,tangent.x);float thickness=a_instanceSize.y;vec2 thicknessVector=normal*thicknessOffset*thickness;worldPosition=curvePoint+thicknessVector;}else if(isArc){float startA=a_instanceArcAngles.x;float stopA=a_instanceArcAngles.y;float TWO_PI=6.28318530718;startA=mod(startA,TWO_PI);if(startA<0.0)startA+=TWO_PI;stopA=mod(stopA,TWO_PI);if(stopA<0.0)stopA+=TWO_PI;float cwDelta=startA-stopA;if(cwDelta<=0.0)cwDelta+=TWO_PI;float angle=startA-a_position.x*cwDelta;float r=a_position.y;vec2 local=vec2(cos(angle),sin(angle))*r;vec2 scaledPosition=local*a_instanceSize*0.5+vec2(a_instanceSize.x*0.5,a_instanceSize.y*0.5);worldPosition=scaledPosition+a_instancePosition;}else{vec2 scaledPosition=a_position*a_instanceSize;worldPosition=scaledPosition+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.0-1.0;ndc.y=-ndc.y;if(a_instanceGlobalRotation!=0.0){ndc-=a_instanceRotationCenter;ndc.x*=u_aspectRatio;ndc=rotate2D(-a_instanceGlobalRotation)*ndc;ndc.x/=u_aspectRatio;ndc+=a_instanceRotationCenter;}gl_Position=vec4(ndc,0.0,1.0);}`, `#version 300 es
1984
+ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`), this.Cr = this.Cs.Ae("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}", "precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}");
1979
1985
  }
1980
- loop() {
1981
- this.qs || (this.qs = !0, this.Os === "auto" && this.ni());
1986
+ static async create(e = {}) {
1987
+ const s = new this(e);
1988
+ await s.Ps.Us(e.fontSource);
1989
+ const r = s.Ps.maxGlyphDimensions;
1990
+ return s._r = new wt(s.Js.canvas, r.width, r.height), s.gr = s.Cs.Le(s._r.cols, s._r.rows, 5), s.Tr(), s.mr.start(() => s.vr()), s;
1982
1991
  }
1983
- redraw(e = 1) {
1984
- if (x.m(typeof e == "number" && e > 0 && Number.isInteger(e), "Redraw count must be a positive integer.", { method: "redraw", providedValue: e })) for (let r = 0; r < e; r++) this.render();
1992
+ Tr() {
1993
+ this.br = () => {
1994
+ this.$r();
1995
+ }, window.addEventListener("resize", this.br);
1985
1996
  }
1986
- isLooping() {
1987
- return this.Os === "auto" && this.qs;
1997
+ vr() {
1998
+ this.mr.measureFrameRate(), this.mr.incrementFrame(), this.yr || (this.gr.V(), this.Cs.Se(this.pr), this.wr(), this.Cs.Ve(this.pr), this.gr.O(), this.Cs.We(0), this.Cs.Se(this.Cr), this.Cr.et({ u_characterTexture: this.Ps.fontFramebuffer, u_charsetDimensions: [this.Ps.textureColumns, this.Ps.textureRows], u_asciiCharacterTexture: this.gr.textures[0], u_primaryColorTexture: this.gr.textures[1], u_secondaryColorTexture: this.gr.textures[2], u_transformTexture: this.gr.textures[4], u_rotationTexture: this.gr.textures[3], u_gridCellDimensions: [this._r.cols, this._r.rows], u_gridPixelDimensions: [this._r.width, this._r.height], u_gridOffsetPixels: [this._r.offsetX, this._r.offsetY], u_aspectRatio: this._r.width / this._r.height }), this.Cs.Pe(this._r.offsetX, this._r.offsetY, this._r.width, this._r.height));
1988
1999
  }
1989
2000
  draw(e) {
1990
- this.ri = e;
2001
+ this.wr = e;
1991
2002
  }
1992
2003
  windowResized(e) {
1993
- this.si = e;
2004
+ this.$r = e;
1994
2005
  }
1995
- resizeCanvas(e, r) {
1996
- this.ei && (this.Ye.rr(e, r), this.js.resize(this.Ye.width, this.Ye.height), this.dr.rr(), this.Hs.rr(), this.ve.Ot(), this.Os !== "manual" && this.render());
2006
+ resizeCanvas(e, s) {
2007
+ this.Js.L(e, s), this._r.Ct(), this.gr.L(this._r.cols, this._r.rows), this.Cs.ke(), this.vr();
1997
2008
  }
1998
2009
  destroy() {
1999
- this.ti || (this.li(), window.removeEventListener("resize", this.ii), this.ar && this.ar.disconnect(), this.Hs.P(), this.Te.P(), this.js.P(), this.ve.P(), this.ti = !0);
2010
+ this.yr || (this.mr.stop(), window.removeEventListener("resize", this.br), this.Ps.U(), this.Cs.U(), this.yr = !0);
2000
2011
  }
2001
2012
  get grid() {
2002
- return this.dr;
2013
+ return this._r;
2003
2014
  }
2004
2015
  get font() {
2005
- return this.Te;
2006
- }
2007
- get mode() {
2008
- return this.Os;
2009
- }
2010
- get pipeline() {
2011
- return this.Hs;
2012
- }
2013
- get frameCount() {
2014
- return this.Zs;
2015
- }
2016
- get renderer() {
2017
- return this.ve;
2018
- }
2019
- set frameCount(e) {
2020
- this.Zs = e;
2016
+ return this.Ps;
2021
2017
  }
2022
2018
  get width() {
2023
- return this.Ye.width;
2019
+ return this.Js.width;
2024
2020
  }
2025
2021
  get height() {
2026
- return this.Ye.height;
2022
+ return this.Js.height;
2027
2023
  }
2028
2024
  get canvas() {
2029
- return this.Ye;
2025
+ return this.Js.canvas;
2030
2026
  }
2031
2027
  get isDisposed() {
2032
- return this.ti;
2028
+ return this.yr;
2029
+ }
2030
+ get drawFramebuffer() {
2031
+ return this.gr;
2033
2032
  }
2034
2033
  }
2035
- class O {
2034
+ class $ {
2036
2035
  constructor() {
2037
- throw new w("Textmode is a static class and cannot be instantiated.");
2036
+ throw new C("Textmode is a static class and cannot be instantiated.");
2038
2037
  }
2039
- static async create(t, e = {}) {
2040
- if (!(t == null || t instanceof HTMLCanvasElement || t instanceof HTMLVideoElement || typeof t == "object")) throw new w("First parameter must be HTMLCanvasElement, HTMLVideoElement, or options object.");
2041
- if (typeof e != "object") throw new w("Second parameter must be an options object.");
2042
- if (t instanceof HTMLCanvasElement || t instanceof HTMLVideoElement) return X.create(t, e);
2043
- {
2044
- const r = t || {};
2045
- return X.create(null, r);
2046
- }
2038
+ static async create(t) {
2039
+ return jt.create(t);
2047
2040
  }
2048
2041
  static setErrorLevel(t) {
2049
- x._(t);
2042
+ I.m(t);
2050
2043
  }
2051
2044
  static get version() {
2052
- return "0.1.9-beta.6";
2045
+ return "0.2.0-beta.1";
2053
2046
  }
2054
2047
  }
2055
- const Gt = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), Vt = O.create, Ot = O.setErrorLevel, Wt = O.version;
2048
+ const Jt = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), qt = $.create, Zt = $.setErrorLevel, Kt = $.version;
2056
2049
  export {
2057
- vt as TextmodeCanvas,
2058
- xt as TextmodeColorPalette,
2059
- wt as TextmodeConversionPipeline,
2060
- rt as TextmodeErrorLevel,
2061
- pt as TextmodeFont,
2062
- mt as TextmodeGrid,
2063
- X as Textmodifier,
2064
- Bt as converters,
2065
- Vt as create,
2066
- O as default,
2067
- Gt as export,
2068
- Ot as setErrorLevel,
2069
- O as textmode,
2070
- Wt as version
2050
+ Pt as TextmodeCanvas,
2051
+ Z as TextmodeErrorLevel,
2052
+ At as TextmodeFont,
2053
+ wt as TextmodeGrid,
2054
+ jt as Textmodifier,
2055
+ qt as create,
2056
+ Jt as export,
2057
+ Zt as setErrorLevel,
2058
+ $ as textmode,
2059
+ Kt as version
2071
2060
  };