textmode.js 0.1.9 → 0.2.0-beta.2

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