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