textmode.js 0.1.6-beta.5 → 0.1.6-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.esm.js +1845 -0
- package/dist/textmode.esm.min.js +1844 -0
- package/dist/textmode.umd.js +26 -0
- package/dist/textmode.umd.min.js +25 -0
- package/dist/types/ColorPalette.d.ts +1 -5
- package/dist/types/Textmode.d.ts +0 -10
- package/dist/types/export/image/ImageDataExtractor.d.ts +1 -1
- package/dist/types/export/image/ImageExporter.d.ts +1 -1
- package/dist/types/export/image/ImageFileHandler.d.ts +1 -7
- package/dist/types/export/svg/SVGContentGenerator.d.ts +1 -1
- package/dist/types/export/svg/SVGDataExtractor.d.ts +1 -1
- package/dist/types/export/svg/SVGPathGenerator.d.ts +0 -5
- package/dist/types/export/txt/TXTDataExtractor.d.ts +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/textmode/Canvas.d.ts +0 -11
- package/dist/types/textmode/ConversionPipeline.d.ts +12 -9
- package/dist/types/textmode/Grid.d.ts +1 -6
- package/dist/types/textmode/Textmodifier.d.ts +5 -25
- package/dist/types/textmode/converters/FeatureConverter.d.ts +24 -0
- package/dist/types/textmode/mixins/ConversionMixin.d.ts +63 -0
- package/dist/types/textmode/mixins/ExportMixin.d.ts +112 -1
- package/dist/types/textmode/mixins/FontMixin.d.ts +1 -1
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +304 -1
- package/dist/types/textmode/mixins/{MixinBase.d.ts → TextmodifierMixin.d.ts} +4 -4
- package/dist/types/textmode/mixins/index.d.ts +2 -1
- package/package.json +16 -2
- package/dist/textmode.js +0 -26
- package/dist/textmode.min.js +0 -25
- package/dist/types/types/index.d.ts +0 -4
|
@@ -0,0 +1,1844 @@
|
|
|
1
|
+
var Z = Object.defineProperty;
|
|
2
|
+
var J = (h, t, e) => t in h ? Z(h, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[t] = e;
|
|
3
|
+
var a = (h, t, e) => J(h, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
class v extends Error {
|
|
5
|
+
constructor(e, s, i = {}) {
|
|
6
|
+
super(v.i(e, i));
|
|
7
|
+
a(this, "t");
|
|
8
|
+
a(this, "context");
|
|
9
|
+
this.name = "TextmodeError", this.t = s, this.context = i;
|
|
10
|
+
}
|
|
11
|
+
static i(e, s) {
|
|
12
|
+
let i = e;
|
|
13
|
+
if (s && Object.keys(s).length > 0) {
|
|
14
|
+
i += `
|
|
15
|
+
|
|
16
|
+
📋 Context:`;
|
|
17
|
+
for (const [r, o] of Object.entries(s))
|
|
18
|
+
i += `
|
|
19
|
+
- ${r}: ${v.o(o)}`;
|
|
20
|
+
}
|
|
21
|
+
return i += `
|
|
22
|
+
|
|
23
|
+
`, i += "↓".repeat(24) + `
|
|
24
|
+
`, i;
|
|
25
|
+
}
|
|
26
|
+
static o(e) {
|
|
27
|
+
if (e === null) return "null";
|
|
28
|
+
if (e === void 0) return "undefined";
|
|
29
|
+
if (typeof e == "string") return `"${e}"`;
|
|
30
|
+
if (typeof e == "number" || typeof e == "boolean") return e + "";
|
|
31
|
+
if (Array.isArray(e)) return e.length === 0 ? "[]" : e.length <= 5 ? `[${e.map((s) => v.o(s)).join(", ")}]` : `[${e.slice(0, 3).map((s) => v.o(s)).join(", ")}, ... +${e.length - 3} more]`;
|
|
32
|
+
if (typeof e == "object") {
|
|
33
|
+
const s = Object.keys(e);
|
|
34
|
+
return s.length === 0 ? "{}" : s.length <= 3 ? `{ ${s.map((i) => `${i}: ${v.o(e[i])}`).join(", ")} }` : `{ ${s.slice(0, 2).map((i) => `${i}: ${v.o(e[i])}`).join(", ")}, ... +${s.length - 2} more }`;
|
|
35
|
+
}
|
|
36
|
+
return e + "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var tt = ((h) => (h[h.SILENT = 0] = "SILENT", h[h.WARNING = 1] = "WARNING", h[h.ERROR = 2] = "ERROR", h[h.THROW = 3] = "THROW", h))(tt || {});
|
|
40
|
+
const F = class F {
|
|
41
|
+
constructor() {
|
|
42
|
+
a(this, "l", { u: 3 });
|
|
43
|
+
}
|
|
44
|
+
static m() {
|
|
45
|
+
return F.h || (F.h = new F()), F.h;
|
|
46
|
+
}
|
|
47
|
+
p(t, e, s) {
|
|
48
|
+
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;";
|
|
49
|
+
switch (this.l.u) {
|
|
50
|
+
case 0:
|
|
51
|
+
return !1;
|
|
52
|
+
case 1:
|
|
53
|
+
return console.group(i, r), console.warn(v.i(t, e)), console.groupEnd(), !1;
|
|
54
|
+
case 2:
|
|
55
|
+
return console.group(i, r), console.error(v.i(t, e)), console.groupEnd(), !1;
|
|
56
|
+
default:
|
|
57
|
+
throw new v(t, s, e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
validate(t, e, s) {
|
|
61
|
+
return !!t || (this.p(e, s), !1);
|
|
62
|
+
}
|
|
63
|
+
v(t) {
|
|
64
|
+
this.l.u = t;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
a(F, "h", null);
|
|
68
|
+
let P = F;
|
|
69
|
+
const w = P.m(), W = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
function U(h, t) {
|
|
71
|
+
W.set(h, t);
|
|
72
|
+
}
|
|
73
|
+
function X(h) {
|
|
74
|
+
return W.get(h);
|
|
75
|
+
}
|
|
76
|
+
class q {
|
|
77
|
+
constructor(t, e, s = e, i = {}) {
|
|
78
|
+
a(this, "_");
|
|
79
|
+
a(this, "C");
|
|
80
|
+
a(this, "F");
|
|
81
|
+
a(this, "$");
|
|
82
|
+
a(this, "D");
|
|
83
|
+
a(this, "options");
|
|
84
|
+
a(this, "M", null);
|
|
85
|
+
a(this, "S", null);
|
|
86
|
+
this._ = t, this.$ = e, this.D = s, this.options = { filter: "nearest", wrap: "clamp", format: "rgba", type: "unsigned_byte", ...i }, this.F = this.createTexture(), this.C = t.createFramebuffer(), this.V();
|
|
87
|
+
}
|
|
88
|
+
R(t) {
|
|
89
|
+
const { _: e } = this, s = e.getParameter(e.FRAMEBUFFER_BINDING);
|
|
90
|
+
e.bindFramebuffer(e.FRAMEBUFFER, this.C);
|
|
91
|
+
try {
|
|
92
|
+
return t();
|
|
93
|
+
} finally {
|
|
94
|
+
e.bindFramebuffer(e.FRAMEBUFFER, s);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
createTexture() {
|
|
98
|
+
const { _: t } = this, e = t.createTexture();
|
|
99
|
+
t.bindTexture(t.TEXTURE_2D, e);
|
|
100
|
+
const s = this.options.filter === "linear" ? t.LINEAR : t.NEAREST, i = this.options.wrap === "repeat" ? t.REPEAT : t.CLAMP_TO_EDGE;
|
|
101
|
+
return t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, s), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, s), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, i), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, i), this.k(), e;
|
|
102
|
+
}
|
|
103
|
+
k() {
|
|
104
|
+
const { _: t } = this, e = this.options.type === "float" ? t.FLOAT : t.UNSIGNED_BYTE;
|
|
105
|
+
t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, this.$, this.D, 0, t.RGBA, e, null);
|
|
106
|
+
}
|
|
107
|
+
V() {
|
|
108
|
+
const { _: t } = this;
|
|
109
|
+
t.bindFramebuffer(t.FRAMEBUFFER, this.C), t.framebufferTexture2D(t.FRAMEBUFFER, t.COLOR_ATTACHMENT0, t.TEXTURE_2D, this.F, 0), t.bindFramebuffer(t.FRAMEBUFFER, null);
|
|
110
|
+
}
|
|
111
|
+
update(t) {
|
|
112
|
+
const { _: e } = this;
|
|
113
|
+
e.bindTexture(e.TEXTURE_2D, this.F), 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
|
+
I(t, e, s) {
|
|
116
|
+
const { _: i } = this;
|
|
117
|
+
i.bindTexture(i.TEXTURE_2D, this.F), i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, e, s, 0, i.RGBA, i.UNSIGNED_BYTE, t), i.bindTexture(i.TEXTURE_2D, null);
|
|
118
|
+
}
|
|
119
|
+
resize(t, e) {
|
|
120
|
+
const { _: s } = this;
|
|
121
|
+
this.$ = t, this.D = e, this.S = null, s.bindTexture(s.TEXTURE_2D, this.F), this.k(), s.bindTexture(s.TEXTURE_2D, null);
|
|
122
|
+
}
|
|
123
|
+
P() {
|
|
124
|
+
const { _: t } = this;
|
|
125
|
+
this.M = { framebuffer: t.getParameter(t.FRAMEBUFFER_BINDING), viewport: t.getParameter(t.VIEWPORT) }, t.bindFramebuffer(t.FRAMEBUFFER, this.C), t.viewport(0, 0, this.$, this.D), U(t, [0, 0, this.$, this.D]);
|
|
126
|
+
}
|
|
127
|
+
end() {
|
|
128
|
+
if (!this.M) return;
|
|
129
|
+
const { _: t } = this;
|
|
130
|
+
t.bindFramebuffer(t.FRAMEBUFFER, this.M.framebuffer), t.viewport(...this.M.viewport), U(t, this.M.viewport), this.M = null;
|
|
131
|
+
}
|
|
132
|
+
A() {
|
|
133
|
+
const { _: t } = this;
|
|
134
|
+
this.S || (this.S = new Uint8Array(this.$ * this.D * 4)), this.R(() => {
|
|
135
|
+
t.readPixels(0, 0, this.$, this.D, t.RGBA, t.UNSIGNED_BYTE, this.S);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
get(t, e, s, i) {
|
|
139
|
+
const { _: r } = this;
|
|
140
|
+
if (t === void 0 && e === void 0) {
|
|
141
|
+
const o = new Uint8Array(this.$ * this.D * 4);
|
|
142
|
+
return this.R(() => (r.readPixels(0, 0, this.$, this.D, r.RGBA, r.UNSIGNED_BYTE, o), o));
|
|
143
|
+
}
|
|
144
|
+
if (s === void 0 && i === void 0) {
|
|
145
|
+
(t < 0 || e < 0 || t >= this.$ || e >= this.D) && (console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."), t = Math.max(0, Math.min(t, this.$ - 1)), e = Math.max(0, Math.min(e, this.D - 1)));
|
|
146
|
+
const o = new Uint8Array(4);
|
|
147
|
+
return this.R(() => (r.readPixels(t, e, 1, 1, r.RGBA, r.UNSIGNED_BYTE, o), [o[0], o[1], o[2], o[3]]));
|
|
148
|
+
}
|
|
149
|
+
{
|
|
150
|
+
t = Math.max(0, Math.min(t, this.$ - 1)), e = Math.max(0, Math.min(e, this.D - 1)), s = Math.max(1, Math.min(s, this.$ - t)), i = Math.max(1, Math.min(i, this.D - e));
|
|
151
|
+
const o = new Uint8Array(s * i * 4);
|
|
152
|
+
return this.R(() => (r.readPixels(t, e, s, i, r.RGBA, r.UNSIGNED_BYTE, o), o));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
dispose() {
|
|
156
|
+
this.C && this._.deleteFramebuffer(this.C), this.F && this._.deleteTexture(this.F);
|
|
157
|
+
}
|
|
158
|
+
get framebuffer() {
|
|
159
|
+
return this.C;
|
|
160
|
+
}
|
|
161
|
+
get texture() {
|
|
162
|
+
return this.F;
|
|
163
|
+
}
|
|
164
|
+
get width() {
|
|
165
|
+
return this.$;
|
|
166
|
+
}
|
|
167
|
+
get height() {
|
|
168
|
+
return this.D;
|
|
169
|
+
}
|
|
170
|
+
get U() {
|
|
171
|
+
return this.S;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class T {
|
|
175
|
+
constructor(t, e, s) {
|
|
176
|
+
a(this, "_");
|
|
177
|
+
a(this, "G");
|
|
178
|
+
a(this, "L", /* @__PURE__ */ new Map());
|
|
179
|
+
a(this, "H", /* @__PURE__ */ new Map());
|
|
180
|
+
a(this, "O", 0);
|
|
181
|
+
a(this, "j");
|
|
182
|
+
this._ = t, this.G = this.createProgram(e, s), this.j = t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS), this.W();
|
|
183
|
+
}
|
|
184
|
+
W() {
|
|
185
|
+
const t = this._.getProgramParameter(this.G, this._.ACTIVE_UNIFORMS);
|
|
186
|
+
for (let e = 0; e < t; e++) {
|
|
187
|
+
const s = this._.getActiveUniform(this.G, e);
|
|
188
|
+
if (s) {
|
|
189
|
+
const i = this._.getUniformLocation(this.G, s.name);
|
|
190
|
+
i && (this.L.set(s.name, i), this.H.set(s.name, s.type));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
createProgram(t, e) {
|
|
195
|
+
const s = this.createShader(this._.VERTEX_SHADER, t), i = this.createShader(this._.FRAGMENT_SHADER, e), r = this._.createProgram();
|
|
196
|
+
if (this._.attachShader(r, s), this._.attachShader(r, i), this._.linkProgram(r), !this._.getProgramParameter(r, this._.LINK_STATUS)) {
|
|
197
|
+
const o = this._.getProgramInfoLog(r);
|
|
198
|
+
throw Error("Shader program link error: " + o);
|
|
199
|
+
}
|
|
200
|
+
return this._.deleteShader(s), this._.deleteShader(i), r;
|
|
201
|
+
}
|
|
202
|
+
createShader(t, e) {
|
|
203
|
+
const s = this._.createShader(t);
|
|
204
|
+
if (this._.shaderSource(s, e), this._.compileShader(s), !this._.getShaderParameter(s, this._.COMPILE_STATUS)) {
|
|
205
|
+
const i = this._.getShaderInfoLog(s);
|
|
206
|
+
throw this._.deleteShader(s), Error("Shader compilation error: " + i);
|
|
207
|
+
}
|
|
208
|
+
return s;
|
|
209
|
+
}
|
|
210
|
+
N() {
|
|
211
|
+
this._.useProgram(this.G), this.X();
|
|
212
|
+
}
|
|
213
|
+
Y(t, e) {
|
|
214
|
+
const s = this.L.get(t);
|
|
215
|
+
if (s) if (typeof e == "number")
|
|
216
|
+
this.q(t) ? this._.uniform1i(s, Math.floor(e)) : this._.uniform1f(s, e);
|
|
217
|
+
else if (typeof e == "boolean") this._.uniform1i(s, e ? 1 : 0);
|
|
218
|
+
else if (Array.isArray(e)) switch (e.length) {
|
|
219
|
+
case 2:
|
|
220
|
+
this._.uniform2f(s, e[0], e[1]);
|
|
221
|
+
break;
|
|
222
|
+
case 3:
|
|
223
|
+
this._.uniform3f(s, e[0], e[1], e[2]);
|
|
224
|
+
break;
|
|
225
|
+
case 4:
|
|
226
|
+
this._.uniform4f(s, e[0], e[1], e[2], e[3]);
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
console.warn(`Unsupported array length ${e.length} for uniform '${t}'`);
|
|
230
|
+
}
|
|
231
|
+
else if (e instanceof WebGLTexture) {
|
|
232
|
+
const i = this.Z();
|
|
233
|
+
this._.uniform1i(s, i), this._.activeTexture(this._.TEXTURE0 + i), this._.bindTexture(this._.TEXTURE_2D, e);
|
|
234
|
+
} else if (e instanceof q) {
|
|
235
|
+
const i = this.Z();
|
|
236
|
+
this._.uniform1i(s, i), this._.activeTexture(this._.TEXTURE0 + i), this._.bindTexture(this._.TEXTURE_2D, e.texture);
|
|
237
|
+
} else console.warn(`Unsupported uniform type for '${t}':`, typeof e);
|
|
238
|
+
}
|
|
239
|
+
Z() {
|
|
240
|
+
return this.O >= this.j && console.warn(`Exceeded maximum texture units (${this.j}). Texture may not render correctly.`), this.O++;
|
|
241
|
+
}
|
|
242
|
+
q(t) {
|
|
243
|
+
const e = this.H.get(t);
|
|
244
|
+
return !!e && (e === this._.INT || e === this._.INT_VEC2 || e === this._.INT_VEC3 || e === this._.INT_VEC4 || e === this._.SAMPLER_2D || e === this._.SAMPLER_CUBE);
|
|
245
|
+
}
|
|
246
|
+
get J() {
|
|
247
|
+
return this.G;
|
|
248
|
+
}
|
|
249
|
+
dispose() {
|
|
250
|
+
this._.deleteProgram(this.G);
|
|
251
|
+
}
|
|
252
|
+
X() {
|
|
253
|
+
this.O = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
class Q {
|
|
257
|
+
constructor(t) {
|
|
258
|
+
a(this, "_");
|
|
259
|
+
a(this, "K", null);
|
|
260
|
+
a(this, "tt", 16);
|
|
261
|
+
a(this, "et", /* @__PURE__ */ new Map());
|
|
262
|
+
this._ = t;
|
|
263
|
+
}
|
|
264
|
+
st() {
|
|
265
|
+
if (this.K) return;
|
|
266
|
+
const t = this._;
|
|
267
|
+
this.K = t.createBuffer(), t.bindBuffer(t.ARRAY_BUFFER, this.K);
|
|
268
|
+
}
|
|
269
|
+
rt() {
|
|
270
|
+
const t = this._, e = t.getParameter(t.CURRENT_PROGRAM);
|
|
271
|
+
let s = this.et.get(e);
|
|
272
|
+
return s || (s = { it: t.getAttribLocation(e, "a_position"), ot: t.getAttribLocation(e, "a_texCoord") }, this.et.set(e, s)), t.enableVertexAttribArray(s.it), t.vertexAttribPointer(s.it, 2, t.FLOAT, !1, this.tt, 0), t.enableVertexAttribArray(s.ot), t.vertexAttribPointer(s.ot, 2, t.FLOAT, !1, this.tt, 8), { nt: s.it, ht: s.ot };
|
|
273
|
+
}
|
|
274
|
+
lt(t, e) {
|
|
275
|
+
const s = this._;
|
|
276
|
+
s.disableVertexAttribArray(t), s.disableVertexAttribArray(e);
|
|
277
|
+
}
|
|
278
|
+
ct(t, e) {
|
|
279
|
+
const s = this._, i = X(s) || [0, 0, s.canvas.width, s.canvas.height];
|
|
280
|
+
return { ut: t / i[2] * 2 - 1, ft: 1 - e / i[3] * 2 };
|
|
281
|
+
}
|
|
282
|
+
dt(t, e, s, i) {
|
|
283
|
+
const r = this._;
|
|
284
|
+
this.st(), r.bindBuffer(r.ARRAY_BUFFER, this.K);
|
|
285
|
+
const o = new Float32Array([t, i, 0, 0, s, i, 1, 0, t, e, 0, 1, t, e, 0, 1, s, i, 1, 0, s, e, 1, 1]);
|
|
286
|
+
r.bufferData(r.ARRAY_BUFFER, o, r.DYNAMIC_DRAW);
|
|
287
|
+
}
|
|
288
|
+
dispose() {
|
|
289
|
+
this.K && this._.deleteBuffer(this.K);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
class et extends Q {
|
|
293
|
+
constructor(t) {
|
|
294
|
+
super(t);
|
|
295
|
+
}
|
|
296
|
+
gt(t, e, s, i) {
|
|
297
|
+
const r = this.ct(t, e), o = this.ct(t + s, e + i);
|
|
298
|
+
this.dt(r.ut, r.ft, o.ut, o.ft);
|
|
299
|
+
const n = this.rt();
|
|
300
|
+
this._.drawArrays(this._.TRIANGLES, 0, 6), this.lt(n.nt, n.ht);
|
|
301
|
+
}
|
|
302
|
+
vt(t, e, s, i, r) {
|
|
303
|
+
this.gt(t, e, s, r), this.gt(t + s - r, e, r, i), this.gt(t, e + i - r, s, r), this.gt(t, e, r, i);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
class st extends Q {
|
|
307
|
+
constructor(t) {
|
|
308
|
+
super(t);
|
|
309
|
+
}
|
|
310
|
+
draw(t, e, s, i, r) {
|
|
311
|
+
const o = s - t, n = i - e, l = Math.hypot(o, n);
|
|
312
|
+
if (l === 0) {
|
|
313
|
+
const u = r / 2, d = this.ct(t - u, e - u), f = this.ct(t + u, e + u);
|
|
314
|
+
this.dt(d.ut, d.ft, f.ut, f.ft);
|
|
315
|
+
} else {
|
|
316
|
+
const u = -n / l, d = o / l, f = r / 2, p = t + u * f, _ = e + d * f, m = t - u * f, x = e - d * f, y = s + u * f, b = i + d * f, R = s - u * f, E = i - d * f, S = this.ct(p, _), M = this.ct(m, x), L = this.ct(y, b), k = this.ct(R, E), D = this._;
|
|
317
|
+
this.st(), D.bindBuffer(D.ARRAY_BUFFER, this.K);
|
|
318
|
+
const K = new Float32Array([S.ut, S.ft, 0, 0, M.ut, M.ft, 0, 1, L.ut, L.ft, 1, 0, M.ut, M.ft, 0, 1, k.ut, k.ft, 1, 1, L.ut, L.ft, 1, 0]);
|
|
319
|
+
D.bufferData(D.ARRAY_BUFFER, K, D.DYNAMIC_DRAW);
|
|
320
|
+
}
|
|
321
|
+
const c = this.rt();
|
|
322
|
+
this._.drawArrays(this._.TRIANGLES, 0, 6), this.lt(c.nt, c.ht);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
var C = "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);}";
|
|
326
|
+
class it {
|
|
327
|
+
constructor(t) {
|
|
328
|
+
a(this, "_");
|
|
329
|
+
a(this, "_t");
|
|
330
|
+
a(this, "xt");
|
|
331
|
+
a(this, "bt", null);
|
|
332
|
+
a(this, "wt");
|
|
333
|
+
a(this, "Ct");
|
|
334
|
+
a(this, "yt", [1, 1, 1, 1]);
|
|
335
|
+
a(this, "Ft", !0);
|
|
336
|
+
a(this, "Tt", [0, 0, 0, 1]);
|
|
337
|
+
a(this, "$t", 1);
|
|
338
|
+
a(this, "Dt", !0);
|
|
339
|
+
a(this, "Mt", 0);
|
|
340
|
+
a(this, "St", []);
|
|
341
|
+
this._ = t, this._t = new T(this._, C, "precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"), this.xt = new T(this._, C, "precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"), this.wt = new et(this._), this.Ct = new st(this._), this._.enable(this._.BLEND), this._.blendEquation(this._.FUNC_ADD), this._.blendFunc(this._.ONE, this._.ONE_MINUS_SRC_ALPHA), U(this._, [0, 0, this._.canvas.width, this._.canvas.height]);
|
|
342
|
+
}
|
|
343
|
+
Vt(t) {
|
|
344
|
+
this.bt !== t && (this.bt = t, t.N());
|
|
345
|
+
}
|
|
346
|
+
fill(t, e, s, i) {
|
|
347
|
+
if (this.Ft = !0, e === void 0 && s === void 0 && i === void 0) {
|
|
348
|
+
const r = t / 255;
|
|
349
|
+
this.yt = [r, r, r, 1];
|
|
350
|
+
} else if (s !== void 0 && i === void 0) this.yt = [t / 255, e / 255, s / 255, 1];
|
|
351
|
+
else {
|
|
352
|
+
if (s === void 0 || i === void 0) throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");
|
|
353
|
+
this.yt = [t / 255, e / 255, s / 255, i / 255];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
stroke(t, e, s, i) {
|
|
357
|
+
if (this.Dt = !0, e === void 0 && s === void 0 && i === void 0) {
|
|
358
|
+
const r = t / 255;
|
|
359
|
+
this.Tt = [r, r, r, 1];
|
|
360
|
+
} else if (s !== void 0 && i === void 0) this.Tt = [t / 255, e / 255, s / 255, 1];
|
|
361
|
+
else {
|
|
362
|
+
if (s === void 0 || i === void 0) throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");
|
|
363
|
+
this.Tt = [t / 255, e / 255, s / 255, i / 255];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
Rt(t) {
|
|
367
|
+
if (t < 0) throw Error("Stroke weight must be non-negative");
|
|
368
|
+
this.$t = t;
|
|
369
|
+
}
|
|
370
|
+
kt() {
|
|
371
|
+
this.Dt = !1;
|
|
372
|
+
}
|
|
373
|
+
zt() {
|
|
374
|
+
this.Ft = !1;
|
|
375
|
+
}
|
|
376
|
+
rotate(t) {
|
|
377
|
+
this.Mt = t;
|
|
378
|
+
}
|
|
379
|
+
push() {
|
|
380
|
+
this.St.push({ It: [...this.yt], Ft: this.Ft, Pt: [...this.Tt], Rt: this.$t, Dt: this.Dt, rotation: this.Mt });
|
|
381
|
+
}
|
|
382
|
+
pop() {
|
|
383
|
+
const t = this.St.pop();
|
|
384
|
+
t ? (this.yt = t.It, this.Ft = t.Ft, this.Tt = t.Pt, this.$t = t.Rt, this.Dt = t.Dt, this.Mt = t.rotation) : console.warn("pop() called without matching push()");
|
|
385
|
+
}
|
|
386
|
+
reset() {
|
|
387
|
+
this.bt = null, this.St = [], this.Mt = 0;
|
|
388
|
+
}
|
|
389
|
+
createShader(t, e) {
|
|
390
|
+
return new T(this._, t, e);
|
|
391
|
+
}
|
|
392
|
+
At(t) {
|
|
393
|
+
return new T(this._, C, t);
|
|
394
|
+
}
|
|
395
|
+
Y(t, e) {
|
|
396
|
+
this.bt.Y(t, e);
|
|
397
|
+
}
|
|
398
|
+
rect(t, e, s, i) {
|
|
399
|
+
if (this.bt !== null) {
|
|
400
|
+
const { Ut: d, Gt: f, Et: p, aspectRatio: _ } = this.Lt(t, e, s, i);
|
|
401
|
+
return this.Y("u_rotation", p), this.Y("u_center", [d, f]), this.Y("u_aspectRatio", _), this.wt.gt(t, e, s, i), void (this.bt = null);
|
|
402
|
+
}
|
|
403
|
+
const r = this.xt;
|
|
404
|
+
let o = 0, n = 0, l = 0, c = 1;
|
|
405
|
+
const u = this.Lt(t, e, s, i);
|
|
406
|
+
o = u.Ut, n = u.Gt, l = u.Et, c = u.aspectRatio, this.Ft && (this.Vt(r), this.Y("u_color", this.yt), this.Y("u_rotation", l), this.Y("u_center", [o, n]), this.Y("u_aspectRatio", c), this.wt.gt(t, e, s, i)), this.Dt && this.$t > 0 && (this.Vt(r), this.Y("u_color", this.Tt), this.Y("u_rotation", l), this.Y("u_center", [o, n]), this.Y("u_aspectRatio", c), this.wt.vt(t, e, s, i, this.$t)), this.bt = null;
|
|
407
|
+
}
|
|
408
|
+
line(t, e, s, i) {
|
|
409
|
+
if (this.bt !== null) {
|
|
410
|
+
const m = (t + s) / 2, x = (e + i) / 2, y = Math.abs(s - t) || 1, b = Math.abs(i - e) || 1, { Ut: R, Gt: E, Et: S, aspectRatio: M } = this.Lt(m - y / 2, x - b / 2, y, b);
|
|
411
|
+
this.Y("u_rotation", S), this.Y("u_center", [R, E]), this.Y("u_aspectRatio", M);
|
|
412
|
+
const L = this.$t > 0 ? this.$t : 1;
|
|
413
|
+
return this.Ct.draw(t, e, s, i, L), void (this.bt = null);
|
|
414
|
+
}
|
|
415
|
+
if (!this.Dt || this.$t <= 0) return;
|
|
416
|
+
const r = this.xt, o = (t + s) / 2, n = (e + i) / 2, l = Math.abs(s - t) || 1, c = Math.abs(i - e) || 1, u = this.Mt !== 0;
|
|
417
|
+
let d = 0, f = 0, p = 0, _ = 1;
|
|
418
|
+
if (u) {
|
|
419
|
+
const m = this.Lt(o - l / 2, n - c / 2, l, c);
|
|
420
|
+
d = m.Ut, f = m.Gt, p = m.Et, _ = m.aspectRatio;
|
|
421
|
+
}
|
|
422
|
+
this.Vt(r), this.Y("u_color", this.Tt), u && (this.Y("u_rotation", p), this.Y("u_center", [d, f]), this.Y("u_aspectRatio", _)), this.Ct.draw(t, e, s, i, this.$t);
|
|
423
|
+
}
|
|
424
|
+
Lt(t, e, s, i) {
|
|
425
|
+
const r = X(this._) || [0, 0, this._.canvas.width, this._.canvas.height], o = r[2], n = r[3], l = o / n;
|
|
426
|
+
return { Ut: (t + s / 2) / o * 2 - 1, Gt: 1 - (e + i / 2) / n * 2, Et: this.Mt * Math.PI / 180, aspectRatio: l };
|
|
427
|
+
}
|
|
428
|
+
createFramebuffer(t, e, s = {}) {
|
|
429
|
+
return new q(this._, t, e, s);
|
|
430
|
+
}
|
|
431
|
+
background(t, e = t, s = t, i = 255) {
|
|
432
|
+
this.clear(t / 255, e / 255, s / 255, i / 255);
|
|
433
|
+
}
|
|
434
|
+
clear(t = 0, e = 0, s = 0, i = 0) {
|
|
435
|
+
this._.clearColor(t, e, s, i), this._.clear(this._.COLOR_BUFFER_BIT);
|
|
436
|
+
}
|
|
437
|
+
Bt() {
|
|
438
|
+
this._.viewport(0, 0, this._.canvas.width, this._.canvas.height), U(this._, [0, 0, this._.canvas.width, this._.canvas.height]);
|
|
439
|
+
}
|
|
440
|
+
get context() {
|
|
441
|
+
return this._;
|
|
442
|
+
}
|
|
443
|
+
dispose() {
|
|
444
|
+
this._t.dispose(), this.xt.dispose(), this.wt.dispose(), this.Ct.dispose();
|
|
445
|
+
}
|
|
446
|
+
image(t, e, s, i, r) {
|
|
447
|
+
const o = this._, n = i ?? t.width, l = r ?? t.height;
|
|
448
|
+
this.Vt(this._t), this.Y("u_texture", t.texture);
|
|
449
|
+
const c = this.Lt(e, s, n, l);
|
|
450
|
+
this.Y("u_rotation", c.Et), this.Y("u_center", [c.Ut, c.Gt]), this.Y("u_aspectRatio", c.aspectRatio), this.wt.gt(e, s, n, l), o.bindTexture(o.TEXTURE_2D, null), this.bt = null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
var A, g = {};
|
|
454
|
+
g.parse = function(h) {
|
|
455
|
+
var t = function(e, s, i, r) {
|
|
456
|
+
var o = g.T, n = { cmap: o.cmap, head: o.head, hhea: o.hhea, maxp: o.maxp, hmtx: o.hmtx, loca: o.loca, glyf: o.glyf }, l = { _data: e, _index: s, _offset: i };
|
|
457
|
+
for (var c in n) {
|
|
458
|
+
var u = g.findTable(e, c, i);
|
|
459
|
+
if (u) {
|
|
460
|
+
var d = u[0], f = r[d];
|
|
461
|
+
f == null && (f = n[c].Ht(e, d, u[1], l)), l[c] = r[d] = f;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return l;
|
|
465
|
+
}(new Uint8Array(h), 0, 0, {});
|
|
466
|
+
return [t];
|
|
467
|
+
}, g.findTable = function(h, t, e) {
|
|
468
|
+
for (var s = g.B, i = s.Ot(h, e + 4), r = e + 12, o = 0; o < i; o++) {
|
|
469
|
+
var n = s.jt(h, r, 4);
|
|
470
|
+
s.Wt(h, r + 4);
|
|
471
|
+
var l = s.Wt(h, r + 8), c = s.Wt(h, r + 12);
|
|
472
|
+
if (n == t) return [l, c];
|
|
473
|
+
r += 16;
|
|
474
|
+
}
|
|
475
|
+
return null;
|
|
476
|
+
}, g.T = {}, g.B = { Nt: function(h, t) {
|
|
477
|
+
return g.B.Xt.uint16[0] = h[t] << 8 | h[t + 1], g.B.Xt.int16[0];
|
|
478
|
+
}, Ot: function(h, t) {
|
|
479
|
+
return h[t] << 8 | h[t + 1];
|
|
480
|
+
}, Yt: function(h, t, e) {
|
|
481
|
+
for (var s = [], i = 0; i < e; i++) s.push(g.B.Ot(h, t + 2 * i));
|
|
482
|
+
return s;
|
|
483
|
+
}, Wt: function(h, t) {
|
|
484
|
+
var e = g.B.Xt.uint8;
|
|
485
|
+
return e[3] = h[t], e[2] = h[t + 1], e[1] = h[t + 2], e[0] = h[t + 3], g.B.Xt.uint32[0];
|
|
486
|
+
}, jt: function(h, t, e) {
|
|
487
|
+
for (var s = "", i = 0; i < e; i++) s += String.fromCharCode(h[t + i]);
|
|
488
|
+
return s;
|
|
489
|
+
}, Xt: (A = new ArrayBuffer(8), { uint8: new Uint8Array(A), int16: new Int16Array(A), uint16: new Uint16Array(A), uint32: new Uint32Array(A) }) }, g.T.cmap = { Ht: function(h, t, e) {
|
|
490
|
+
var s = { qt: [], Qt: {}, off: t };
|
|
491
|
+
h = new Uint8Array(h.buffer, t, e), t = 0;
|
|
492
|
+
var i = g.B, r = i.Ot, o = g.T.cmap;
|
|
493
|
+
r(h, t);
|
|
494
|
+
var n = r(h, t += 2);
|
|
495
|
+
t += 2;
|
|
496
|
+
for (var l = [], c = 0; c < n; c++) {
|
|
497
|
+
var u = r(h, t), d = r(h, t += 2);
|
|
498
|
+
t += 2;
|
|
499
|
+
var f = i.Wt(h, t);
|
|
500
|
+
t += 4;
|
|
501
|
+
var p = "p" + u + "e" + d, _ = l.indexOf(f);
|
|
502
|
+
if (_ == -1) {
|
|
503
|
+
_ = s.qt.length;
|
|
504
|
+
var m = {};
|
|
505
|
+
l.push(f);
|
|
506
|
+
var x = m.format = r(h, f);
|
|
507
|
+
x == 4 ? m = o.Zt(h, f, m) : x == 12 && (m = o.Jt(h, f, m)), s.qt.push(m);
|
|
508
|
+
}
|
|
509
|
+
s.Qt[p] != null && console.log("multiple tables for one platform+encoding: " + p), s.Qt[p] = _;
|
|
510
|
+
}
|
|
511
|
+
return s;
|
|
512
|
+
}, Zt: function(h, t, e) {
|
|
513
|
+
var s = g.B, i = s.Ot, r = s.Yt, o = t, n = i(h, t += 2);
|
|
514
|
+
i(h, t += 2);
|
|
515
|
+
var l = i(h, t += 2);
|
|
516
|
+
t += 2;
|
|
517
|
+
var c = l >>> 1;
|
|
518
|
+
e.Kt = i(h, t), t += 2, e.te = i(h, t), t += 2, e.ee = i(h, t), t += 2, e.se = r(h, t, c), t += 2 * c, t += 2, e.re = r(h, t, c), t += 2 * c, e.ie = [];
|
|
519
|
+
for (var u = 0; u < c; u++) e.ie.push(s.Nt(h, t)), t += 2;
|
|
520
|
+
return e.oe = r(h, t, c), t += 2 * c, e.ne = r(h, t, o + n - t >> 1), e;
|
|
521
|
+
}, Jt: function(h, t, e) {
|
|
522
|
+
var s = g.B.Wt;
|
|
523
|
+
s(h, t += 4), s(h, t += 4);
|
|
524
|
+
var i = 3 * s(h, t += 4);
|
|
525
|
+
t += 4;
|
|
526
|
+
for (var r = e.groups = new Uint32Array(i), o = 0; o < i; o += 3) r[o] = s(h, t + (o << 2)), r[o + 1] = s(h, t + (o << 2) + 4), r[o + 2] = s(h, t + (o << 2) + 8);
|
|
527
|
+
return e;
|
|
528
|
+
} }, g.T.head = { Ht: function(h, t, e) {
|
|
529
|
+
var s = g.B, i = {};
|
|
530
|
+
return t += 18, i.unitsPerEm = s.Ot(h, t), t += 2, t += 16, i.xMin = s.Nt(h, t), t += 2, i.yMin = s.Nt(h, t), t += 2, i.xMax = s.Nt(h, t), t += 2, i.yMax = s.Nt(h, t), t += 2, t += 6, i.indexToLocFormat = s.Nt(h, t), i;
|
|
531
|
+
} }, g.T.hhea = { Ht: function(h, t, e) {
|
|
532
|
+
var s = g.B, i = {};
|
|
533
|
+
t += 4;
|
|
534
|
+
for (var r = ["ascender", "descender", "lineGap", "advanceWidthMax", "minLeftSideBearing", "minRightSideBearing", "xMaxExtent", "caretSlopeRise", "caretSlopeRun", "caretOffset", "res0", "res1", "res2", "res3", "metricDataFormat", "numberOfHMetrics"], o = 0; o < r.length; o++) {
|
|
535
|
+
var n = r[o], l = n == "advanceWidthMax" || n == "numberOfHMetrics" ? s.Ot : s.Nt;
|
|
536
|
+
i[n] = l(h, t + 2 * o);
|
|
537
|
+
}
|
|
538
|
+
return i;
|
|
539
|
+
} }, g.T.hmtx = { Ht: function(h, t, e, s) {
|
|
540
|
+
for (var i = g.B, r = [], o = [], n = s.maxp.numGlyphs, l = s.hhea.numberOfHMetrics, c = 0, u = 0, d = 0; d < l; ) c = i.Ot(h, t + (d << 2)), u = i.Nt(h, t + (d << 2) + 2), r.push(c), o.push(u), d++;
|
|
541
|
+
for (; d < n; ) r.push(c), o.push(u), d++;
|
|
542
|
+
return { he: r, ae: o };
|
|
543
|
+
} }, g.T.maxp = { Ht: function(h, t, e) {
|
|
544
|
+
var s = g.B, i = s.Ot, r = {};
|
|
545
|
+
return s.Wt(h, t), t += 4, r.numGlyphs = i(h, t), t += 2, r;
|
|
546
|
+
} }, g.T.loca = { Ht: function(h, t, e, s) {
|
|
547
|
+
var i = g.B, r = [], o = s.head.indexToLocFormat, n = s.maxp.numGlyphs + 1;
|
|
548
|
+
if (o == 0) for (var l = 0; l < n; l++) r.push(i.Ot(h, t + (l << 1)) << 1);
|
|
549
|
+
if (o == 1) for (l = 0; l < n; l++) r.push(i.Wt(h, t + (l << 2)));
|
|
550
|
+
return r;
|
|
551
|
+
} }, g.T.glyf = { Ht: function(h, t, e, s) {
|
|
552
|
+
for (var i = [], r = s.maxp.numGlyphs, o = 0; o < r; o++) i.push(null);
|
|
553
|
+
return i;
|
|
554
|
+
}, le: function(h, t) {
|
|
555
|
+
var e = g.B, s = h._data, i = h.loca;
|
|
556
|
+
if (i[t] == i[t + 1]) return null;
|
|
557
|
+
var r = g.findTable(s, "glyf", h._offset)[0] + i[t], o = {};
|
|
558
|
+
if (o.ce = e.Nt(s, r), r += 2, o.xMin = e.Nt(s, r), r += 2, o.yMin = e.Nt(s, r), r += 2, o.xMax = e.Nt(s, r), r += 2, o.yMax = e.Nt(s, r), r += 2, o.xMin >= o.xMax || o.yMin >= o.yMax) return null;
|
|
559
|
+
if (o.ce > 0) {
|
|
560
|
+
o.ue = [];
|
|
561
|
+
for (var n = 0; n < o.ce; n++) o.ue.push(e.Ot(s, r)), r += 2;
|
|
562
|
+
var l = e.Ot(s, r);
|
|
563
|
+
if (r += 2, s.length - r < l) return null;
|
|
564
|
+
r += l;
|
|
565
|
+
var c = o.ue[o.ce - 1] + 1;
|
|
566
|
+
for (o.flags = [], n = 0; n < c; n++) {
|
|
567
|
+
var u = s[r];
|
|
568
|
+
if (r++, o.flags.push(u), 8 & u) {
|
|
569
|
+
var d = s[r];
|
|
570
|
+
r++;
|
|
571
|
+
for (var f = 0; f < d; f++) o.flags.push(u), n++;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
for (o.fe = [], n = 0; n < c; n++) {
|
|
575
|
+
var p = !!(2 & o.flags[n]), _ = !!(16 & o.flags[n]);
|
|
576
|
+
p ? (o.fe.push(_ ? s[r] : -s[r]), r++) : _ ? o.fe.push(0) : (o.fe.push(e.Nt(s, r)), r += 2);
|
|
577
|
+
}
|
|
578
|
+
for (o.de = [], n = 0; n < c; n++)
|
|
579
|
+
p = !!(4 & o.flags[n]), _ = !!(32 & o.flags[n]), p ? (o.de.push(_ ? s[r] : -s[r]), r++) : _ ? o.de.push(0) : (o.de.push(e.Nt(s, r)), r += 2);
|
|
580
|
+
var m = 0, x = 0;
|
|
581
|
+
for (n = 0; n < c; n++) m += o.fe[n], x += o.de[n], o.fe[n] = m, o.de[n] = x;
|
|
582
|
+
} else o.me = [];
|
|
583
|
+
return o;
|
|
584
|
+
} }, typeof module < "u" && module.exports ? module.exports = g : typeof window < "u" && (window.Typr = g);
|
|
585
|
+
class rt {
|
|
586
|
+
ge(t) {
|
|
587
|
+
var s;
|
|
588
|
+
const e = [];
|
|
589
|
+
return (s = t == null ? void 0 : t.cmap) != null && s.qt ? (t.cmap.qt.forEach((i) => {
|
|
590
|
+
if (i.format === 4) {
|
|
591
|
+
const r = this.pe(i);
|
|
592
|
+
e.push(...r);
|
|
593
|
+
} else if (i.format === 12) {
|
|
594
|
+
const r = this.ve(i);
|
|
595
|
+
e.push(...r);
|
|
596
|
+
}
|
|
597
|
+
}), [...new Set(e)]) : [];
|
|
598
|
+
}
|
|
599
|
+
pe(t) {
|
|
600
|
+
const e = [];
|
|
601
|
+
if (!(t.re && t.se && t.oe && t.ie)) return e;
|
|
602
|
+
for (let s = 0; s < t.re.length; s++) {
|
|
603
|
+
const i = t.re[s], r = t.se[s];
|
|
604
|
+
if (i !== 65535 || r !== 65535) {
|
|
605
|
+
for (let o = i; o <= r; o++)
|
|
606
|
+
if (this._e(t, o, s) > 0) {
|
|
607
|
+
const n = String.fromCodePoint(o);
|
|
608
|
+
e.push(n);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return e;
|
|
613
|
+
}
|
|
614
|
+
ve(t) {
|
|
615
|
+
const e = [];
|
|
616
|
+
if (!t.groups) return e;
|
|
617
|
+
for (let s = 0; s < t.groups.length; s += 3) {
|
|
618
|
+
const i = t.groups[s], r = t.groups[s + 1], o = t.groups[s + 2];
|
|
619
|
+
for (let n = i; n <= r; n++)
|
|
620
|
+
if (o + (n - i) > 0) {
|
|
621
|
+
const l = String.fromCodePoint(n);
|
|
622
|
+
e.push(l);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return e;
|
|
626
|
+
}
|
|
627
|
+
_e(t, e, s) {
|
|
628
|
+
if (t.oe[s] === 0) return e + t.ie[s] & 65535;
|
|
629
|
+
{
|
|
630
|
+
const i = t.oe[s] / 2 + (e - t.re[s]) - (t.re.length - s);
|
|
631
|
+
if (i >= 0 && t.ne && i < t.ne.length) {
|
|
632
|
+
const r = t.ne[i];
|
|
633
|
+
if (r !== 0) return r + t.ie[s] & 65535;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return 0;
|
|
637
|
+
}
|
|
638
|
+
xe(t) {
|
|
639
|
+
return t.filter((e) => this.be(e));
|
|
640
|
+
}
|
|
641
|
+
be(t) {
|
|
642
|
+
const e = t.codePointAt(0) || 0;
|
|
643
|
+
return !(e >= 0 && e <= 31 && e !== 9 && e !== 10 && e !== 13 || e >= 127 && e <= 159);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
class ot {
|
|
647
|
+
constructor(t) {
|
|
648
|
+
a(this, "we");
|
|
649
|
+
a(this, "Ce");
|
|
650
|
+
a(this, "ye");
|
|
651
|
+
this.ye = t, this.we = document.createElement("canvas"), this.Ce = this.we.getContext("2d", { Fe: !0, alpha: !1 });
|
|
652
|
+
}
|
|
653
|
+
Te(t, e, s, i) {
|
|
654
|
+
const r = t.length, o = Math.ceil(Math.sqrt(r)), n = Math.ceil(r / o), l = e.width * o, c = e.height * n;
|
|
655
|
+
this.$e(l, c, s, i), this.De(t, e, o, s), this.Me();
|
|
656
|
+
const u = this.ye.createFramebuffer(l, c, { filter: "nearest" });
|
|
657
|
+
return u.update(this.we), { framebuffer: u, columns: o, rows: n };
|
|
658
|
+
}
|
|
659
|
+
$e(t, e, s, i) {
|
|
660
|
+
this.we.width = t, this.we.height = e, this.we.style.width = t + "px", this.we.style.height = t + "px", this.Ce.imageSmoothingEnabled = !1, this.we.style.imageRendering = "pixelated", this.Ce.fillStyle = "black", this.Ce.fillRect(0, 0, t, e), this.Ce.font = `${s}px ${i}`, this.Ce.textBaseline = "top", this.Ce.textAlign = "left", this.Ce.fillStyle = "white";
|
|
661
|
+
}
|
|
662
|
+
De(t, e, s, i) {
|
|
663
|
+
for (let r = 0; r < t.length; r++) {
|
|
664
|
+
const o = r % s, n = Math.floor(r / s), l = o * e.width + 0.5 * e.width, c = n * e.height + 0.5 * e.height, u = Math.round(l - 0.5 * e.width), d = Math.round(c - 0.5 * i);
|
|
665
|
+
this.Ce.fillText(t[r].Se, u, d);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
Me(t = 128) {
|
|
669
|
+
const e = this.Ce.getImageData(0, 0, this.we.width, this.we.height), s = e.data;
|
|
670
|
+
for (let i = 0; i < s.length; i += 4) {
|
|
671
|
+
const r = 0.299 * s[i] + 0.587 * s[i + 1] + 0.114 * s[i + 2] > t + 32 ? 255 : 0;
|
|
672
|
+
s[i] = r, s[i + 1] = r, s[i + 2] = r;
|
|
673
|
+
}
|
|
674
|
+
this.Ce.putImageData(e, 0, 0);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
class nt {
|
|
678
|
+
constructor() {
|
|
679
|
+
a(this, "Ve");
|
|
680
|
+
a(this, "Re");
|
|
681
|
+
this.Ve = document.createElement("canvas"), this.Re = this.Ve.getContext("2d");
|
|
682
|
+
}
|
|
683
|
+
ke(t, e, s) {
|
|
684
|
+
this.Re.font = `${e}px ${s}`;
|
|
685
|
+
let i = 0, r = 0;
|
|
686
|
+
for (const o of t) {
|
|
687
|
+
const n = this.Re.measureText(o);
|
|
688
|
+
i = Math.max(i, n.width), r = Math.max(r, n.actualBoundingBoxAscent + n.actualBoundingBoxDescent);
|
|
689
|
+
}
|
|
690
|
+
return { width: i, height: r };
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
class ht {
|
|
694
|
+
ze(t, e) {
|
|
695
|
+
return t.map((s, i) => {
|
|
696
|
+
const r = s.codePointAt(0) || 0, o = this.Ie(i);
|
|
697
|
+
let n = 0;
|
|
698
|
+
if (e.hmtx && e.hmtx.he) {
|
|
699
|
+
const l = this.Pe(e, r);
|
|
700
|
+
l > 0 && e.hmtx.he[l] !== void 0 && (n = e.hmtx.he[l]);
|
|
701
|
+
}
|
|
702
|
+
return { Se: s, unicode: r, color: o, Ae: n };
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
Pe(t, e) {
|
|
706
|
+
const s = t.cmap;
|
|
707
|
+
if (!s || !s.qt) return 0;
|
|
708
|
+
for (const i of s.qt) if (i.format === 4) {
|
|
709
|
+
for (let r = 0; r < i.re.length; r++) if (e >= i.re[r] && e <= i.se[r]) {
|
|
710
|
+
if (i.oe[r] === 0) return e + i.ie[r] & 65535;
|
|
711
|
+
{
|
|
712
|
+
const o = i.oe[r] / 2 + (e - i.re[r]) - (i.re.length - r);
|
|
713
|
+
if (o >= 0 && o < i.ne.length) {
|
|
714
|
+
const n = i.ne[o];
|
|
715
|
+
if (n !== 0) return n + i.ie[r] & 65535;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
Ie(t) {
|
|
723
|
+
return [t % 256, Math.floor(t / 256) % 256, Math.floor(t / 65536) % 256];
|
|
724
|
+
}
|
|
725
|
+
Ue(t, e) {
|
|
726
|
+
if (!w.validate(typeof t == "string", "Character must be a string.", { method: "getCharacterColor", Ge: t })) return [0, 0, 0];
|
|
727
|
+
const s = e.find((i) => i.Se === t);
|
|
728
|
+
return s ? s.color : [0, 0, 0];
|
|
729
|
+
}
|
|
730
|
+
Ee(t, e) {
|
|
731
|
+
return w.validate(typeof t == "string" && t.length > 0, "Characters must be a string with at least one character.", { method: "getCharacterColors", Ge: t }) ? t.split("").map((s) => this.Ue(s, e) || [0, 0, 0]) : [[0, 0, 0]];
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
class at {
|
|
735
|
+
constructor(t, e = 16) {
|
|
736
|
+
a(this, "Le");
|
|
737
|
+
a(this, "Be", []);
|
|
738
|
+
a(this, "He");
|
|
739
|
+
a(this, "Oe", 16);
|
|
740
|
+
a(this, "je", 0);
|
|
741
|
+
a(this, "We", 0);
|
|
742
|
+
a(this, "Ne", { width: 0, height: 0 });
|
|
743
|
+
a(this, "Xe");
|
|
744
|
+
a(this, "Ye", "UrsaFont");
|
|
745
|
+
a(this, "qe");
|
|
746
|
+
a(this, "Qe");
|
|
747
|
+
a(this, "Ze");
|
|
748
|
+
a(this, "Je");
|
|
749
|
+
this.Oe = e, this.qe = new rt(), this.Qe = new ot(t), this.Ze = new nt(), this.Je = new ht();
|
|
750
|
+
}
|
|
751
|
+
async initialize(t) {
|
|
752
|
+
let e;
|
|
753
|
+
if (!t) throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");
|
|
754
|
+
{
|
|
755
|
+
const s = await fetch(t);
|
|
756
|
+
if (!s.ok) throw new v(`Failed to load font file: ${s.status} ${s.statusText}`);
|
|
757
|
+
e = await s.arrayBuffer();
|
|
758
|
+
}
|
|
759
|
+
await this.Ke(e), this.Le = g.parse(e)[0], await this.ts();
|
|
760
|
+
}
|
|
761
|
+
es(t) {
|
|
762
|
+
if (t === void 0) return this.Oe;
|
|
763
|
+
this.Oe = t, this.Ne = this.Ze.ke(this.Be.map((s) => s.Se), this.Oe, this.Ye);
|
|
764
|
+
const e = this.Qe.Te(this.Be, this.Ne, this.Oe, this.Ye);
|
|
765
|
+
this.He = e.framebuffer, this.je = e.columns, this.We = e.rows;
|
|
766
|
+
}
|
|
767
|
+
async ss(t) {
|
|
768
|
+
try {
|
|
769
|
+
const e = await fetch(t);
|
|
770
|
+
if (!e.ok) throw new v(`Failed to load font file: ${e.status} ${e.statusText}`);
|
|
771
|
+
const s = await e.arrayBuffer();
|
|
772
|
+
await this.Ke(s);
|
|
773
|
+
const i = g.parse(s);
|
|
774
|
+
if (!i || i.length === 0) throw Error("Failed to parse font file");
|
|
775
|
+
this.Le = i[0], await this.ts();
|
|
776
|
+
} catch (e) {
|
|
777
|
+
throw new v("Failed to load font: " + (e instanceof Error ? e.message : "Unknown error"), e);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
async Ke(t) {
|
|
781
|
+
const e = Date.now();
|
|
782
|
+
this.Ye = this.Ye === "UrsaFont" ? "UrsaFont" : "CustomFont_" + e, this.Xe = new FontFace(this.Ye, t), await this.Xe.load(), document.fonts.add(this.Xe);
|
|
783
|
+
}
|
|
784
|
+
async ts() {
|
|
785
|
+
const t = this.qe.ge(this.Le), e = this.qe.xe(t);
|
|
786
|
+
this.Be = this.Je.ze(e, this.Le), this.Ne = this.Ze.ke(e, this.Oe, this.Ye);
|
|
787
|
+
const s = this.Qe.Te(this.Be, this.Ne, this.Oe, this.Ye);
|
|
788
|
+
this.He = s.framebuffer, this.je = s.columns, this.We = s.rows;
|
|
789
|
+
}
|
|
790
|
+
Ue(t) {
|
|
791
|
+
return this.Je.Ue(t, this.Be);
|
|
792
|
+
}
|
|
793
|
+
Ee(t) {
|
|
794
|
+
return this.Je.Ee(t, this.Be);
|
|
795
|
+
}
|
|
796
|
+
rs(t) {
|
|
797
|
+
if (typeof t != "string" || t.length === 0) return !1;
|
|
798
|
+
const e = new Set(this.Be.map((s) => s.Se));
|
|
799
|
+
for (const s of t) if (!e.has(s)) return !1;
|
|
800
|
+
return !0;
|
|
801
|
+
}
|
|
802
|
+
get ns() {
|
|
803
|
+
return this.He;
|
|
804
|
+
}
|
|
805
|
+
get hs() {
|
|
806
|
+
return this.Be;
|
|
807
|
+
}
|
|
808
|
+
get ls() {
|
|
809
|
+
return this.je;
|
|
810
|
+
}
|
|
811
|
+
get cs() {
|
|
812
|
+
return this.We;
|
|
813
|
+
}
|
|
814
|
+
get us() {
|
|
815
|
+
return this.Ne;
|
|
816
|
+
}
|
|
817
|
+
dispose() {
|
|
818
|
+
this.He.dispose(), document.fonts.delete(this.Xe);
|
|
819
|
+
}
|
|
820
|
+
get fontSize() {
|
|
821
|
+
return this.Oe;
|
|
822
|
+
}
|
|
823
|
+
get font() {
|
|
824
|
+
return this.Le;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
class lt {
|
|
828
|
+
constructor(t, e, s) {
|
|
829
|
+
a(this, "fs");
|
|
830
|
+
a(this, "ds");
|
|
831
|
+
a(this, "$");
|
|
832
|
+
a(this, "D");
|
|
833
|
+
a(this, "gs");
|
|
834
|
+
a(this, "ps");
|
|
835
|
+
a(this, "vs", !1);
|
|
836
|
+
a(this, "_s");
|
|
837
|
+
a(this, "xs");
|
|
838
|
+
a(this, "bs");
|
|
839
|
+
this._s = t, this.xs = e, this.bs = s, this.reset();
|
|
840
|
+
}
|
|
841
|
+
reset() {
|
|
842
|
+
this.vs || (this.fs = Math.floor(this._s.width / this.xs), this.ds = Math.floor(this._s.height / this.bs)), this.ws();
|
|
843
|
+
}
|
|
844
|
+
ws() {
|
|
845
|
+
this.$ = this.fs * this.xs, this.D = this.ds * this.bs, this.gs = Math.floor((this._s.width - this.$) / 2), this.ps = Math.floor((this._s.height - this.D) / 2);
|
|
846
|
+
}
|
|
847
|
+
Cs(t, e) {
|
|
848
|
+
this.xs = t, this.bs = e, this.reset();
|
|
849
|
+
}
|
|
850
|
+
ys(t, e) {
|
|
851
|
+
this.vs = !0, this.fs = t, this.ds = e, this.ws();
|
|
852
|
+
}
|
|
853
|
+
Fs() {
|
|
854
|
+
this.vs = !1, this.reset();
|
|
855
|
+
}
|
|
856
|
+
resize() {
|
|
857
|
+
this.vs ? this.ws() : this.reset();
|
|
858
|
+
}
|
|
859
|
+
Ts(t) {
|
|
860
|
+
if (t === void 0) return this.vs;
|
|
861
|
+
this.vs = t;
|
|
862
|
+
}
|
|
863
|
+
get $s() {
|
|
864
|
+
return this.xs;
|
|
865
|
+
}
|
|
866
|
+
get Ds() {
|
|
867
|
+
return this.bs;
|
|
868
|
+
}
|
|
869
|
+
get cols() {
|
|
870
|
+
return this.fs;
|
|
871
|
+
}
|
|
872
|
+
get rows() {
|
|
873
|
+
return this.ds;
|
|
874
|
+
}
|
|
875
|
+
get width() {
|
|
876
|
+
return this.$;
|
|
877
|
+
}
|
|
878
|
+
get height() {
|
|
879
|
+
return this.D;
|
|
880
|
+
}
|
|
881
|
+
get offsetX() {
|
|
882
|
+
return this.gs;
|
|
883
|
+
}
|
|
884
|
+
get offsetY() {
|
|
885
|
+
return this.ps;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
class ct {
|
|
889
|
+
constructor(t, e = !1, s = {}) {
|
|
890
|
+
a(this, "_s");
|
|
891
|
+
a(this, "Ms");
|
|
892
|
+
a(this, "Ss");
|
|
893
|
+
a(this, "Vs");
|
|
894
|
+
a(this, "Rs");
|
|
895
|
+
this.Ms = t, this.Ss = e, this._s = this.ks(s.width, s.height), e && this.zs();
|
|
896
|
+
}
|
|
897
|
+
ks(t, e) {
|
|
898
|
+
var i;
|
|
899
|
+
const s = document.createElement("canvas");
|
|
900
|
+
if (s.className = "textmodeCanvas", s.style.imageRendering = "pixelated", this.Ss) s.width = t || 800, s.height = e || 600, document.body.appendChild(s);
|
|
901
|
+
else {
|
|
902
|
+
const r = this.Ms.getBoundingClientRect();
|
|
903
|
+
let o = Math.round(r.width), n = Math.round(r.height);
|
|
904
|
+
if (this.Ms instanceof HTMLVideoElement) {
|
|
905
|
+
const u = this.Ms;
|
|
906
|
+
(o === 0 || n === 0) && u.videoWidth > 0 && u.videoHeight > 0 && (o = u.videoWidth, n = u.videoHeight);
|
|
907
|
+
}
|
|
908
|
+
s.width = o, s.height = n, s.style.position = "absolute", s.style.pointerEvents = "none";
|
|
909
|
+
const l = window.getComputedStyle(this.Ms);
|
|
910
|
+
let c = parseInt(l.zIndex || "0", 10);
|
|
911
|
+
isNaN(c) && (c = 0), s.style.zIndex = "" + (c + 1), this.Is(s), (i = this.Ms.parentNode) == null || i.insertBefore(s, this.Ms.nextSibling);
|
|
912
|
+
}
|
|
913
|
+
return s;
|
|
914
|
+
}
|
|
915
|
+
Is(t) {
|
|
916
|
+
const e = this.Ms.getBoundingClientRect();
|
|
917
|
+
let s = this.Ms.offsetParent;
|
|
918
|
+
if (s && s !== document.body) {
|
|
919
|
+
const i = s.getBoundingClientRect();
|
|
920
|
+
t.style.top = e.top - i.top + "px", t.style.left = e.left - i.left + "px";
|
|
921
|
+
} else t.style.top = e.top + window.scrollY + "px", t.style.left = e.left + window.scrollX + "px";
|
|
922
|
+
}
|
|
923
|
+
resize(t, e) {
|
|
924
|
+
if (this.Ss) this._s.width = t ?? this._s.width, this._s.height = e ?? this._s.height;
|
|
925
|
+
else {
|
|
926
|
+
const s = this.Ms.getBoundingClientRect();
|
|
927
|
+
let i = Math.round(s.width), r = Math.round(s.height);
|
|
928
|
+
if (this.Ms instanceof HTMLVideoElement) {
|
|
929
|
+
const o = this.Ms;
|
|
930
|
+
(i === 0 || r === 0) && o.videoWidth > 0 && o.videoHeight > 0 && (i = o.videoWidth, r = o.videoHeight);
|
|
931
|
+
}
|
|
932
|
+
this._s.width = i, this._s.height = r, this.Is(this._s);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
Ps() {
|
|
936
|
+
const t = { alpha: !1, premultipliedAlpha: !1, As: !0, antialias: !1, Us: !1, Gs: !1, powerPreference: "high-performance" }, e = this._s.getContext("webgl2", t) || this._s.getContext("webgl", t);
|
|
937
|
+
if (!e) throw new v("WebGL context could not be created. Ensure your browser supports WebGL.");
|
|
938
|
+
return e;
|
|
939
|
+
}
|
|
940
|
+
zs() {
|
|
941
|
+
this.Vs = new ResizeObserver((t) => {
|
|
942
|
+
for (const e of t) {
|
|
943
|
+
const s = e.contentRect;
|
|
944
|
+
!this.Rs || Math.round(s.width) === this._s.width && Math.round(s.height) === this._s.height || this.Rs();
|
|
945
|
+
}
|
|
946
|
+
}), this.Vs.observe(this._s);
|
|
947
|
+
}
|
|
948
|
+
dispose() {
|
|
949
|
+
if (this.Vs && this.Vs.disconnect(), this._s) {
|
|
950
|
+
const t = this._s.getContext("webgl") || this._s.getContext("webgl2");
|
|
951
|
+
if (t) {
|
|
952
|
+
const e = t.getExtension("WEBGL_lose_context");
|
|
953
|
+
e && e.Es();
|
|
954
|
+
}
|
|
955
|
+
this._s.parentNode && this._s.parentNode.removeChild(this._s);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
get canvas() {
|
|
959
|
+
return this._s;
|
|
960
|
+
}
|
|
961
|
+
get width() {
|
|
962
|
+
return this._s.width;
|
|
963
|
+
}
|
|
964
|
+
get height() {
|
|
965
|
+
return this._s.height;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
class $ {
|
|
969
|
+
constructor(t, e, s, i = {}) {
|
|
970
|
+
a(this, "Ls");
|
|
971
|
+
a(this, "Bs");
|
|
972
|
+
a(this, "grid");
|
|
973
|
+
a(this, "Hs");
|
|
974
|
+
a(this, "Os");
|
|
975
|
+
a(this, "js");
|
|
976
|
+
a(this, "Ws");
|
|
977
|
+
a(this, "Ns");
|
|
978
|
+
a(this, "l");
|
|
979
|
+
this.Ls = t, this.Bs = e, this.grid = s, this.l = i;
|
|
980
|
+
const r = this.grid.cols, o = this.grid.rows;
|
|
981
|
+
this.Hs = this.Ls.createFramebuffer(r, o), this.Os = this.Ls.createFramebuffer(r, o), this.js = this.Ls.createFramebuffer(r, o), this.Ws = this.Ls.createFramebuffer(r, o), this.Ns = this.Ls.createFramebuffer(r, o);
|
|
982
|
+
}
|
|
983
|
+
resize() {
|
|
984
|
+
const t = this.grid.cols, e = this.grid.rows;
|
|
985
|
+
this.Hs.resize(t, e), this.Os.resize(t, e), this.js.resize(t, e), this.Ws.resize(t, e), this.Ns.resize(t, e);
|
|
986
|
+
}
|
|
987
|
+
enabled(t) {
|
|
988
|
+
this.l.enabled = t;
|
|
989
|
+
}
|
|
990
|
+
enable() {
|
|
991
|
+
this.enabled(!0);
|
|
992
|
+
}
|
|
993
|
+
disable() {
|
|
994
|
+
this.enabled(!1);
|
|
995
|
+
}
|
|
996
|
+
dispose() {
|
|
997
|
+
this.Hs.dispose(), this.Os.dispose(), this.js.dispose(), this.Ws.dispose(), this.Ns.dispose();
|
|
998
|
+
}
|
|
999
|
+
get Xs() {
|
|
1000
|
+
return this.Hs;
|
|
1001
|
+
}
|
|
1002
|
+
get Ys() {
|
|
1003
|
+
return this.Os;
|
|
1004
|
+
}
|
|
1005
|
+
get qs() {
|
|
1006
|
+
return this.js;
|
|
1007
|
+
}
|
|
1008
|
+
get Qs() {
|
|
1009
|
+
return this.Ws;
|
|
1010
|
+
}
|
|
1011
|
+
get Zs() {
|
|
1012
|
+
return this.Ns;
|
|
1013
|
+
}
|
|
1014
|
+
get options() {
|
|
1015
|
+
return this.l;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
class ut {
|
|
1019
|
+
constructor(t, e) {
|
|
1020
|
+
a(this, "C");
|
|
1021
|
+
a(this, "ye");
|
|
1022
|
+
a(this, "Js");
|
|
1023
|
+
this.ye = t, this.Js = e;
|
|
1024
|
+
const s = Math.max(this.Js.length, 1);
|
|
1025
|
+
this.C = this.ye.createFramebuffer(s, 1), this.Ks();
|
|
1026
|
+
}
|
|
1027
|
+
Ks() {
|
|
1028
|
+
const t = this.Js.length;
|
|
1029
|
+
this.C.width !== t && this.C.resize(t, 1);
|
|
1030
|
+
const e = new Uint8Array(1 * t * 4);
|
|
1031
|
+
for (let s = 0; s < t; s++) {
|
|
1032
|
+
const i = this.Js[s], r = 4 * s;
|
|
1033
|
+
e[r] = i[0], e[r + 1] = i[1], e[r + 2] = i[2], e[r + 3] = 255;
|
|
1034
|
+
}
|
|
1035
|
+
this.C.I(e, t, 1);
|
|
1036
|
+
}
|
|
1037
|
+
tr(t) {
|
|
1038
|
+
this.Js = t, this.Ks();
|
|
1039
|
+
}
|
|
1040
|
+
get er() {
|
|
1041
|
+
return this.Js;
|
|
1042
|
+
}
|
|
1043
|
+
get framebuffer() {
|
|
1044
|
+
return this.C;
|
|
1045
|
+
}
|
|
1046
|
+
get texture() {
|
|
1047
|
+
return this.C.texture;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
class N extends $ {
|
|
1051
|
+
constructor(e, s, i, r = {}) {
|
|
1052
|
+
super(e, s, i, r);
|
|
1053
|
+
a(this, "palette");
|
|
1054
|
+
this.palette = new ut(this.Ls, this.Bs.Ee(" .:-=+*%@#"));
|
|
1055
|
+
}
|
|
1056
|
+
hs(e) {
|
|
1057
|
+
w.validate(this.Bs.rs(e), "One or more characters do not exist in the current font.", { method: "characters", Ge: e }) && (this.l.hs = e, this.palette.tr(this.Bs.Ee(e)));
|
|
1058
|
+
}
|
|
1059
|
+
sr(e, s, i, r = 255) {
|
|
1060
|
+
const o = this.rr(e, "characterColor", s, i, r);
|
|
1061
|
+
o && (this.l.sr = o);
|
|
1062
|
+
}
|
|
1063
|
+
ir(e) {
|
|
1064
|
+
this.nr(e, "characterColorMode");
|
|
1065
|
+
}
|
|
1066
|
+
hr(e, s, i, r = 255) {
|
|
1067
|
+
const o = this.rr(e, "cellColor", s, i, r);
|
|
1068
|
+
o && (this.l.hr = o);
|
|
1069
|
+
}
|
|
1070
|
+
ar(e) {
|
|
1071
|
+
this.nr(e, "cellColorMode");
|
|
1072
|
+
}
|
|
1073
|
+
lr(e) {
|
|
1074
|
+
this.cr(e, "invert", "Invert");
|
|
1075
|
+
}
|
|
1076
|
+
rotation(e) {
|
|
1077
|
+
if (!w.validate(typeof e == "number", "Rotation angle must be a number.", { method: "rotation", Ge: e })) return;
|
|
1078
|
+
(e %= 360) < 0 && (e += 360);
|
|
1079
|
+
const s = 255 * e / 360, i = Math.floor(s) / 255, r = Math.round(s - i);
|
|
1080
|
+
this.l.rotation = [i, r, 0, 1];
|
|
1081
|
+
}
|
|
1082
|
+
ur(e) {
|
|
1083
|
+
this.cr(e, "flipHorizontally", "Flip horizontally");
|
|
1084
|
+
}
|
|
1085
|
+
dr(e) {
|
|
1086
|
+
this.cr(e, "flipVertically", "Flip vertically");
|
|
1087
|
+
}
|
|
1088
|
+
rr(e, s, i, r, o = 255) {
|
|
1089
|
+
let n, l, c, u;
|
|
1090
|
+
if (typeof e == "string") {
|
|
1091
|
+
const d = this.mr(e);
|
|
1092
|
+
if (!d) return w.validate(!1, "Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.", { method: s, Ge: e }), null;
|
|
1093
|
+
[n, l, c, u] = d;
|
|
1094
|
+
} else if (n = e, l = i !== void 0 ? i : e, c = r !== void 0 ? r : e, u = o, !w.validate([n, l, c, u].every((d) => d >= 0 && d <= 255), s.charAt(0).toUpperCase() + s.slice(1) + " color values must be between 0 and 255", { method: s, gr: { r: n, g: l, b: c, a: u } })) return null;
|
|
1095
|
+
return [n / 255, l / 255, c / 255, u / 255];
|
|
1096
|
+
}
|
|
1097
|
+
nr(e, s) {
|
|
1098
|
+
w.validate(["sampled", "fixed"].includes(e), "Invalid color mode. Must be 'sampled' or 'fixed'.", { method: s, Ge: e }) && (this.l[s] = e);
|
|
1099
|
+
}
|
|
1100
|
+
cr(e, s, i) {
|
|
1101
|
+
w.validate(typeof e == "boolean" || typeof e == "number" && Number.isInteger(e), i + " must be a boolean value or an integer (0 for false, any other number for true).", { method: s, Ge: e }) && (this.l[s] = !!e);
|
|
1102
|
+
}
|
|
1103
|
+
mr(e) {
|
|
1104
|
+
return e = e.replace(/^#/, ""), /^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(e) ? (e.length === 3 && (e = e.split("").map((s) => s + s).join("")), [parseInt(e.slice(0, 2), 16), parseInt(e.slice(2, 4), 16), parseInt(e.slice(4, 6), 16), 255]) : null;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
const dt = { enabled: !0, hs: " .:-=+*%@#", sr: [1, 1, 1, 1], ir: "sampled", hr: [0, 0, 0, 1], ar: "fixed", lr: !1, rotation: [0, 0, 0, 255], ur: !1, dr: !1, pr: [0, 255] };
|
|
1108
|
+
class Y extends N {
|
|
1109
|
+
constructor(e, s, i) {
|
|
1110
|
+
super(e, s, i, { ...dt });
|
|
1111
|
+
a(this, "vr");
|
|
1112
|
+
a(this, "_r");
|
|
1113
|
+
a(this, "br");
|
|
1114
|
+
a(this, "wr");
|
|
1115
|
+
a(this, "Cr");
|
|
1116
|
+
a(this, "yr");
|
|
1117
|
+
this.vr = new T(e.context, C, "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._r = new T(e.context, C, "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.wr = new T(e.context, C, "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.Cr = new T(e.context, C, "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.br = new T(e.context, C, "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.yr = this.Ls.createFramebuffer(this.grid.cols, this.grid.rows);
|
|
1118
|
+
}
|
|
1119
|
+
Fr(e) {
|
|
1120
|
+
const s = this.grid.cols, i = this.grid.rows;
|
|
1121
|
+
this.yr.P(), this.Ls.clear(), this.Ls.Vt(this.vr), this.Ls.Y("u_sketchTexture", e), this.Ls.Y("u_gridCellDimensions", [s, i]), this.Ls.Y("u_brightnessRange", this.l.pr), this.Ls.rect(0, 0, s, i), this.yr.end(), this.Os.P(), this.Ls.clear(), this.Ls.Vt(this._r), this.Ls.Y("u_sampleTexture", this.yr), this.Ls.Y("u_fillColor", this.l.sr), this.Ls.Y("u_useFixedColor", this.l.ir === "fixed"), this.Ls.rect(0, 0, s, i), this.Os.end(), this.js.P(), this.Ls.clear(), this.Ls.Vt(this._r), this.Ls.Y("u_sampleTexture", this.yr), this.Ls.Y("u_fillColor", this.l.hr), this.Ls.Y("u_useFixedColor", this.l.ar === "fixed"), this.Ls.rect(0, 0, s, i), this.js.end(), this.Ns.P(), this.Ls.clear(), this.Ls.Vt(this.wr), this.Ls.Y("u_sampleTexture", this.yr), this.Ls.Y("u_invert", this.l.lr), this.Ls.Y("u_flipHorizontally", this.l.ur), this.Ls.Y("u_flipVertically", this.l.dr), this.Ls.rect(0, 0, s, i), this.Ns.end(), this.Ws.P(), this.Ls.clear(), this.Ls.Vt(this.Cr), this.Ls.Y("u_sampleTexture", this.yr), this.Ls.Y("u_rotationColor", this.l.rotation), this.Ls.rect(0, 0, s, i), this.Ws.end(), this.Hs.P(), this.Ls.clear(), this.Ls.Vt(this.br), this.Ls.Y("u_colorSampleFramebuffer", this.yr), this.Ls.Y("u_charPaletteTexture", this.palette.texture), this.Ls.Y("u_charPaletteSize", [this.palette.er.length, 1]), this.Ls.Y("u_brightnessRange", this.l.pr), this.Ls.rect(0, 0, s, i), this.Hs.end();
|
|
1122
|
+
}
|
|
1123
|
+
resize() {
|
|
1124
|
+
super.resize(), this.yr.resize(this.grid.cols, this.grid.rows);
|
|
1125
|
+
}
|
|
1126
|
+
pr(e) {
|
|
1127
|
+
w.validate(Array.isArray(e) && e.length === 2 && e.every((s) => typeof s == "number" && s >= 0 && s <= 255), "Brightness range must be an array of two numbers between 0 and 255.", { method: "brightnessRange", Ge: e }) && (this.l.pr = e);
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
const At = Object.freeze(Object.defineProperty({ __proto__: null, Tr: Y, $r: $, Dr: N }, Symbol.toStringTag, { value: "Module" }));
|
|
1131
|
+
class ft {
|
|
1132
|
+
constructor(t, e, s) {
|
|
1133
|
+
a(this, "Ls");
|
|
1134
|
+
a(this, "font");
|
|
1135
|
+
a(this, "grid");
|
|
1136
|
+
a(this, "Mr");
|
|
1137
|
+
a(this, "Sr");
|
|
1138
|
+
a(this, "Vr");
|
|
1139
|
+
a(this, "Rr");
|
|
1140
|
+
a(this, "kr");
|
|
1141
|
+
a(this, "Hs");
|
|
1142
|
+
a(this, "Os");
|
|
1143
|
+
a(this, "js");
|
|
1144
|
+
a(this, "Ws");
|
|
1145
|
+
a(this, "Ns");
|
|
1146
|
+
this.Ls = t, this.font = e, this.grid = s, this.kr = this.Ls.createShader(C, "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.Sr = new Y(t, e, s), this.Vr = new $(t, e, s), this.Mr = [this.Sr, this.Vr], this.Hs = this.Ls.createFramebuffer(s.cols, s.rows), this.Os = this.Ls.createFramebuffer(s.cols, s.rows), this.js = this.Ls.createFramebuffer(s.cols, s.rows), this.Ws = this.Ls.createFramebuffer(s.cols, s.rows), this.Ns = this.Ls.createFramebuffer(s.cols, s.rows), this.Rr = this.Ls.createFramebuffer(this.grid.width, this.grid.height);
|
|
1147
|
+
}
|
|
1148
|
+
zr(t) {
|
|
1149
|
+
for (const s of this.Mr) s.options.enabled && s instanceof N && s.Fr(t);
|
|
1150
|
+
const e = (s, i) => {
|
|
1151
|
+
s.P(), this.Ls.clear();
|
|
1152
|
+
for (const r of this.Mr) r.options.enabled && this.Ls.image(i(r), 0, 0);
|
|
1153
|
+
s.end();
|
|
1154
|
+
};
|
|
1155
|
+
e(this.Hs, (s) => s.Xs), e(this.Os, (s) => s.Ys), e(this.js, (s) => s.qs), e(this.Ws, (s) => s.Qs), e(this.Ns, (s) => s.Zs), this.Rr.P(), this.Ls.clear(), this.Ls.Vt(this.kr), this.Ls.Y("u_characterTexture", this.font.ns), this.Ls.Y("u_charsetDimensions", [this.font.ls, this.font.cs]), this.Ls.Y("u_asciiCharacterTexture", this.Hs.texture), this.Ls.Y("u_primaryColorTexture", this.Os.texture), this.Ls.Y("u_secondaryColorTexture", this.js.texture), this.Ls.Y("u_transformTexture", this.Ns.texture), this.Ls.Y("u_rotationTexture", this.Ws.texture), this.Ls.Y("u_captureTexture", t.texture), this.Ls.Y("u_backgroundMode", !1), this.Ls.Y("u_captureDimensions", [t.width, t.height]), this.Ls.Y("u_gridCellDimensions", [this.grid.cols, this.grid.rows]), this.Ls.Y("u_gridPixelDimensions", [this.grid.width, this.grid.height]), this.Ls.rect(0, 0, this.Rr.width, this.Rr.height), this.Rr.end();
|
|
1156
|
+
}
|
|
1157
|
+
add(t) {
|
|
1158
|
+
if (!w.validate(t === "brightness" || t === "custom", 'Converter type must be either "brightness" or "custom". Provided: ' + t, { method: "add", Ge: t })) return;
|
|
1159
|
+
let e;
|
|
1160
|
+
return e = t === "brightness" ? new Y(this.Ls, this.font, this.grid) : new $(this.Ls, this.font, this.grid), this.Mr.push(e), e;
|
|
1161
|
+
}
|
|
1162
|
+
remove(t) {
|
|
1163
|
+
if (!w.validate(t instanceof $, "Parameter must be a TextmodeConverter instance.", { method: "remove", Ge: t })) return;
|
|
1164
|
+
const e = this.Mr.indexOf(t);
|
|
1165
|
+
w.validate(e !== -1, "Converter instance not found in pipeline.", { method: "remove", Ge: t, Ir: this.Mr.length }) && this.Mr.splice(e, 1);
|
|
1166
|
+
}
|
|
1167
|
+
get texture() {
|
|
1168
|
+
return this.Rr;
|
|
1169
|
+
}
|
|
1170
|
+
resize() {
|
|
1171
|
+
this.Rr.resize(this.grid.width, this.grid.height);
|
|
1172
|
+
const t = this.grid.cols, e = this.grid.rows;
|
|
1173
|
+
this.Hs.resize(t, e), this.Os.resize(t, e), this.js.resize(t, e), this.Ws.resize(t, e), this.Ns.resize(t, e);
|
|
1174
|
+
for (const s of this.Mr) s.resize();
|
|
1175
|
+
}
|
|
1176
|
+
Pr() {
|
|
1177
|
+
return this.Mr.some((t) => t.options.enabled);
|
|
1178
|
+
}
|
|
1179
|
+
disable() {
|
|
1180
|
+
for (const t of this.Mr) t.disable();
|
|
1181
|
+
}
|
|
1182
|
+
enable() {
|
|
1183
|
+
for (const t of this.Mr) t.enable();
|
|
1184
|
+
}
|
|
1185
|
+
dispose() {
|
|
1186
|
+
for (const t of this.Mr) t.dispose();
|
|
1187
|
+
this.Hs.dispose(), this.Os.dispose(), this.js.dispose(), this.Ws.dispose(), this.Ns.dispose(), this.Rr.dispose(), this.kr.dispose();
|
|
1188
|
+
}
|
|
1189
|
+
get Xs() {
|
|
1190
|
+
return this.Hs;
|
|
1191
|
+
}
|
|
1192
|
+
get Ys() {
|
|
1193
|
+
return this.Os;
|
|
1194
|
+
}
|
|
1195
|
+
get qs() {
|
|
1196
|
+
return this.js;
|
|
1197
|
+
}
|
|
1198
|
+
get Qs() {
|
|
1199
|
+
return this.Ws;
|
|
1200
|
+
}
|
|
1201
|
+
get Zs() {
|
|
1202
|
+
return this.Ns;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
const gt = (h) => class extends h {
|
|
1206
|
+
fill(t, e, s, i) {
|
|
1207
|
+
this.ye.fill(t, e, s, i);
|
|
1208
|
+
}
|
|
1209
|
+
stroke(t, e, s, i) {
|
|
1210
|
+
this.ye.stroke(t, e, s, i);
|
|
1211
|
+
}
|
|
1212
|
+
Rt(t) {
|
|
1213
|
+
this.ye.Rt(t);
|
|
1214
|
+
}
|
|
1215
|
+
kt() {
|
|
1216
|
+
this.ye.kt();
|
|
1217
|
+
}
|
|
1218
|
+
zt() {
|
|
1219
|
+
this.ye.zt();
|
|
1220
|
+
}
|
|
1221
|
+
rotate(t) {
|
|
1222
|
+
this.ye.rotate(t);
|
|
1223
|
+
}
|
|
1224
|
+
push() {
|
|
1225
|
+
this.ye.push();
|
|
1226
|
+
}
|
|
1227
|
+
pop() {
|
|
1228
|
+
this.ye.pop();
|
|
1229
|
+
}
|
|
1230
|
+
rect(t, e, s = 1, i = 1) {
|
|
1231
|
+
this.ye.rect(t, e, s, i);
|
|
1232
|
+
}
|
|
1233
|
+
line(t, e, s, i) {
|
|
1234
|
+
this.ye.line(t, e, s, i);
|
|
1235
|
+
}
|
|
1236
|
+
background(t, e = t, s = t, i = 255) {
|
|
1237
|
+
this.ye.background(t, e, s, i);
|
|
1238
|
+
}
|
|
1239
|
+
createShader(t, e) {
|
|
1240
|
+
return this.ye.createShader(t, e);
|
|
1241
|
+
}
|
|
1242
|
+
At(t) {
|
|
1243
|
+
return this.ye.At(t);
|
|
1244
|
+
}
|
|
1245
|
+
Vt(t) {
|
|
1246
|
+
this.ye.Vt(t);
|
|
1247
|
+
}
|
|
1248
|
+
Y(t, e) {
|
|
1249
|
+
this.ye.Y(t, e);
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
class I {
|
|
1253
|
+
Ar(t) {
|
|
1254
|
+
const e = t.get("brightness"), s = e == null ? void 0 : e.Xs, i = e == null ? void 0 : e.Ys, r = e == null ? void 0 : e.qs, o = e == null ? void 0 : e.Zs, n = e == null ? void 0 : e.Qs;
|
|
1255
|
+
return s == null || s.A(), i == null || i.A(), r == null || r.A(), o == null || o.A(), n == null || n.A(), { Ur: (s == null ? void 0 : s.U) || new Uint8Array(0), Gr: (i == null ? void 0 : i.U) || new Uint8Array(0), Er: (r == null ? void 0 : r.U) || new Uint8Array(0), Lr: (o == null ? void 0 : o.U) || new Uint8Array(0), Br: (n == null ? void 0 : n.U) || new Uint8Array(0) };
|
|
1256
|
+
}
|
|
1257
|
+
Hr(t, e) {
|
|
1258
|
+
return t[e] + (t[e + 1] << 8);
|
|
1259
|
+
}
|
|
1260
|
+
Or(t, e) {
|
|
1261
|
+
return { r: t[e], g: t[e + 1], b: t[e + 2], a: t[e + 3] };
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
class z {
|
|
1265
|
+
jr(t, e) {
|
|
1266
|
+
return new Blob([t], { type: e });
|
|
1267
|
+
}
|
|
1268
|
+
Wr(t, e, s) {
|
|
1269
|
+
try {
|
|
1270
|
+
const i = this.jr(t, s), r = URL.createObjectURL(i), o = document.createElement("a");
|
|
1271
|
+
o.href = r, o.download = e, o.style.display = "none", o.rel = "noopener", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(r);
|
|
1272
|
+
} catch (i) {
|
|
1273
|
+
throw console.error("Failed to download file:", i), Error("File download failed: " + (i instanceof Error ? i.message : "Unknown error"));
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
Nr() {
|
|
1277
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/:/g, "-");
|
|
1278
|
+
}
|
|
1279
|
+
Xr() {
|
|
1280
|
+
const t = /* @__PURE__ */ new Date();
|
|
1281
|
+
return { Yr: t.toISOString().split("T")[0], time: t.toTimeString().split(" ")[0].replace(/:/g, "-") };
|
|
1282
|
+
}
|
|
1283
|
+
qr(t) {
|
|
1284
|
+
return t.replace(/[<>:"/\\|?*]/g, "_").replace(/\s+/g, "_").replace(/_{2,}/g, "_").replace(/^_+|_+$/g, "").substring(0, 255);
|
|
1285
|
+
}
|
|
1286
|
+
Qr() {
|
|
1287
|
+
return "'textmode-export'-" + this.Nr();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
class mt extends I {
|
|
1291
|
+
Zr(t, e, s) {
|
|
1292
|
+
const i = t[s] === 255, r = t[s + 1] === 255, o = t[s + 2] === 255, n = e[s], l = e[s + 1];
|
|
1293
|
+
return { Jr: i, Kr: r, ti: o, rotation: Math.round(360 * (n + l / 255) / 255 * 100) / 100 };
|
|
1294
|
+
}
|
|
1295
|
+
ei(t, e, s) {
|
|
1296
|
+
return { x: t, y: e, si: t * s.$s, ri: e * s.Ds };
|
|
1297
|
+
}
|
|
1298
|
+
ii(t, e) {
|
|
1299
|
+
const s = [];
|
|
1300
|
+
let i = 0;
|
|
1301
|
+
for (let r = 0; r < e.rows; r++) for (let o = 0; o < e.cols; o++) {
|
|
1302
|
+
const n = 4 * i, l = this.Hr(t.Ur, n);
|
|
1303
|
+
let c = this.Or(t.Gr, n), u = this.Or(t.Er, n);
|
|
1304
|
+
const d = this.Zr(t.Lr, t.Br, n);
|
|
1305
|
+
if (d.Jr) {
|
|
1306
|
+
const p = c;
|
|
1307
|
+
c = u, u = p;
|
|
1308
|
+
}
|
|
1309
|
+
const f = this.ei(o, r, e);
|
|
1310
|
+
s.push({ charIndex: l, oi: c, ni: u, transform: d, position: f }), i++;
|
|
1311
|
+
}
|
|
1312
|
+
return s;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
class pt {
|
|
1316
|
+
hi(t, e) {
|
|
1317
|
+
const s = t.cmap;
|
|
1318
|
+
for (const i of s.qt) if (i.format === 4) {
|
|
1319
|
+
for (let r = 0; r < i.re.length; r++) if (e >= i.re[r] && e <= i.se[r]) {
|
|
1320
|
+
if (i.oe[r] === 0) return e + i.ie[r] & 65535;
|
|
1321
|
+
{
|
|
1322
|
+
const o = i.oe[r] / 2 + (e - i.re[r]) - (i.re.length - r);
|
|
1323
|
+
if (o >= 0 && o < i.ne.length) {
|
|
1324
|
+
const n = i.ne[o];
|
|
1325
|
+
if (n !== 0) return n + i.ie[r] & 65535;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
return 0;
|
|
1331
|
+
}
|
|
1332
|
+
ai(t, e, s, i, r) {
|
|
1333
|
+
const o = r / t.head.unitsPerEm;
|
|
1334
|
+
return { li: () => ({ x1: s + e.xMin * o, y1: i + -e.yMax * o, x2: s + e.xMax * o, y2: i + -e.yMin * o }), ci: () => this.ui(e, s, i, o) };
|
|
1335
|
+
}
|
|
1336
|
+
ui(t, e, s, i) {
|
|
1337
|
+
if (!t || !t.fe) return "";
|
|
1338
|
+
const { fe: r, de: o, ue: n, flags: l } = t;
|
|
1339
|
+
if (!(r && o && n && l)) return "";
|
|
1340
|
+
let c = "", u = 0;
|
|
1341
|
+
for (let d = 0; d < n.length; d++) {
|
|
1342
|
+
const f = n[d];
|
|
1343
|
+
if (!(f < u)) {
|
|
1344
|
+
if (f >= u) {
|
|
1345
|
+
const p = e + r[u] * i, _ = s - o[u] * i;
|
|
1346
|
+
c += `M${p.toFixed(2)},${_.toFixed(2)}`;
|
|
1347
|
+
let m = u + 1;
|
|
1348
|
+
for (; m <= f; )
|
|
1349
|
+
if (1 & l[m]) {
|
|
1350
|
+
const x = e + r[m] * i, y = s - o[m] * i;
|
|
1351
|
+
c += `L${x.toFixed(2)},${y.toFixed(2)}`, m++;
|
|
1352
|
+
} else {
|
|
1353
|
+
const x = e + r[m] * i, y = s - o[m] * i;
|
|
1354
|
+
let b = m + 1 > f ? u : m + 1;
|
|
1355
|
+
if (1 & l[b]) {
|
|
1356
|
+
const R = e + r[b] * i, E = s - o[b] * i;
|
|
1357
|
+
c += `Q${x.toFixed(2)},${y.toFixed(2)} ${R.toFixed(2)},${E.toFixed(2)}`, m = b + 1;
|
|
1358
|
+
} else {
|
|
1359
|
+
const R = (x + (e + r[b] * i)) / 2, E = (y + (s - o[b] * i)) / 2;
|
|
1360
|
+
c += `Q${x.toFixed(2)},${y.toFixed(2)} ${R.toFixed(2)},${E.toFixed(2)}`, m = b;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
c += "Z";
|
|
1364
|
+
}
|
|
1365
|
+
u = f + 1;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
return c;
|
|
1369
|
+
}
|
|
1370
|
+
fi(t, e, s, i, r) {
|
|
1371
|
+
const o = t.codePointAt(0) || 0, n = this.hi(e, o);
|
|
1372
|
+
let l = null;
|
|
1373
|
+
return e.glyf && e.glyf[n] !== null ? l = e.glyf[n] : g && g.T && g.T.glyf && g.T.glyf.le && (l = g.T.glyf.le(e, n), e.glyf && l && (e.glyf[n] = l)), this.ai(e, l, s, i, r);
|
|
1374
|
+
}
|
|
1375
|
+
di(t, e, s, i, r, o, n, l) {
|
|
1376
|
+
const c = s + (r - l * (n / e.head.unitsPerEm)) / 2, u = i + (o + 0.7 * n) / 2;
|
|
1377
|
+
return this.fi(t, e, c, u, n).ci() || null;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
class _t {
|
|
1381
|
+
constructor() {
|
|
1382
|
+
a(this, "mi");
|
|
1383
|
+
this.mi = new pt();
|
|
1384
|
+
}
|
|
1385
|
+
gi(t) {
|
|
1386
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
1387
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
1388
|
+
<svg width="${t.width}" height="${t.height}" viewBox="0 0 ${t.width} ${t.height}"
|
|
1389
|
+
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
1390
|
+
<title>textmode art generated via textmode.js</title>
|
|
1391
|
+
<desc>textmode art visualization generated by textmode.js library</desc>`;
|
|
1392
|
+
}
|
|
1393
|
+
pi() {
|
|
1394
|
+
return `
|
|
1395
|
+
</g>
|
|
1396
|
+
</svg>`;
|
|
1397
|
+
}
|
|
1398
|
+
_i(t, e) {
|
|
1399
|
+
if (!e.xi) return "";
|
|
1400
|
+
const s = e.backgroundColor, i = `rgba(${s[0]},${s[1]},${s[2]},${s[3] / 255})`;
|
|
1401
|
+
return `
|
|
1402
|
+
<rect width="${t.width}" height="${t.height}" fill="${i}" />`;
|
|
1403
|
+
}
|
|
1404
|
+
bi(t) {
|
|
1405
|
+
return `rgba(${t.r},${t.g},${t.b},${t.a / 255})`;
|
|
1406
|
+
}
|
|
1407
|
+
wi(t, e) {
|
|
1408
|
+
const { transform: s, position: i } = t, r = i.si + e.$s / 2, o = i.ri + e.Ds / 2, n = [];
|
|
1409
|
+
if (s.Kr || s.ti) {
|
|
1410
|
+
const l = s.Kr ? -1 : 1, c = s.ti ? -1 : 1;
|
|
1411
|
+
n.push(`translate(${r} ${o})`), n.push(`scale(${l} ${c})`), n.push(`translate(${-r} ${-o})`);
|
|
1412
|
+
}
|
|
1413
|
+
return s.rotation && n.push(`rotate(${s.rotation} ${r} ${o})`), n.length ? ` transform="${n.join(" ")}"` : "";
|
|
1414
|
+
}
|
|
1415
|
+
Ci(t, e, s) {
|
|
1416
|
+
if (!s.xi || t.ni.a === 0) return "";
|
|
1417
|
+
const { position: i } = t, r = this.bi(t.ni);
|
|
1418
|
+
return s.yi === "stroke" ? `
|
|
1419
|
+
<rect x="${i.si}" y="${i.ri}" width="${e.$s}" height="${e.Ds}" stroke="${r}" fill="none" stroke-width="${s.strokeWidth}" />` : `
|
|
1420
|
+
<rect x="${i.si}" y="${i.ri}" width="${e.$s}" height="${e.Ds}" fill="${r}" />`;
|
|
1421
|
+
}
|
|
1422
|
+
fi(t, e, s, i) {
|
|
1423
|
+
const r = s.hs[t.charIndex];
|
|
1424
|
+
if (!r) return "";
|
|
1425
|
+
const o = this.mi.di(r.Se, s.font, t.position.si, t.position.ri, e.$s, e.Ds, s.fontSize, r.Ae);
|
|
1426
|
+
if (!o) return "";
|
|
1427
|
+
const n = this.bi(t.oi);
|
|
1428
|
+
return i.yi === "stroke" ? `
|
|
1429
|
+
<path id="${`path-${t.charIndex}-${t.position.si}-${t.position.ri}`.replace(/\./g, "-")}" d="${o}" stroke="${n}" stroke-width="${i.strokeWidth}" fill="none" />` : `
|
|
1430
|
+
<path d="${o}" fill="${n}" />`;
|
|
1431
|
+
}
|
|
1432
|
+
Fi(t, e, s, i) {
|
|
1433
|
+
let r = "";
|
|
1434
|
+
r += this.Ci(t, e, i);
|
|
1435
|
+
const o = this.wi(t, e), n = this.fi(t, e, s, i);
|
|
1436
|
+
return n && (o ? (r += `
|
|
1437
|
+
<g${o}>`, r += n, r += `
|
|
1438
|
+
</g>`) : r += n), r;
|
|
1439
|
+
}
|
|
1440
|
+
Ti(t, e, s, i) {
|
|
1441
|
+
let r = this.gi(e);
|
|
1442
|
+
r += this._i(e, i), r += `
|
|
1443
|
+
<g id="ascii-cells">`;
|
|
1444
|
+
for (const o of t) r += this.Fi(o, e, s, i);
|
|
1445
|
+
return r += this.pi(), r;
|
|
1446
|
+
}
|
|
1447
|
+
$i(t) {
|
|
1448
|
+
return t.replace(/<path[^>]*d=""[^>]*\/>/g, "").replace(/\n\s*\n/g, `
|
|
1449
|
+
`).replace(/[ \t]+$/gm, "");
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
class xt extends z {
|
|
1453
|
+
Di(t) {
|
|
1454
|
+
return this.jr(t, "image/svg+xml;charset=utf-8");
|
|
1455
|
+
}
|
|
1456
|
+
Mi(t, e) {
|
|
1457
|
+
this.Wr(t, this.qr(e) + ".svg", "image/svg+xml;charset=utf-8");
|
|
1458
|
+
}
|
|
1459
|
+
Si(t, e) {
|
|
1460
|
+
this.Mi(t, e || this.Qr());
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
class V {
|
|
1464
|
+
constructor() {
|
|
1465
|
+
a(this, "Vi");
|
|
1466
|
+
a(this, "Ri");
|
|
1467
|
+
a(this, "ki");
|
|
1468
|
+
this.Vi = new mt(), this.Ri = new _t(), this.ki = new xt();
|
|
1469
|
+
}
|
|
1470
|
+
zi(t) {
|
|
1471
|
+
return { xi: t.xi ?? !0, yi: t.yi ?? "fill", strokeWidth: t.strokeWidth ?? 1, backgroundColor: t.backgroundColor ?? [0, 0, 0, 0] };
|
|
1472
|
+
}
|
|
1473
|
+
Ii(t, e = {}) {
|
|
1474
|
+
const s = this.zi(e), i = this.Vi.Ar(t.Pi), r = this.Vi.ii(i, t.grid), o = this.Ri.Ti(r, t.grid, t.font, s);
|
|
1475
|
+
return this.Ri.$i(o);
|
|
1476
|
+
}
|
|
1477
|
+
Si(t, e = {}) {
|
|
1478
|
+
const s = this.Ii(t, e), i = e.filename || this.ki.Qr();
|
|
1479
|
+
this.ki.Si(s, i);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
class vt extends I {
|
|
1483
|
+
Ai(t, e, s, i = " ") {
|
|
1484
|
+
var n;
|
|
1485
|
+
const r = [];
|
|
1486
|
+
let o = 0;
|
|
1487
|
+
for (let l = 0; l < e.rows; l++) {
|
|
1488
|
+
const c = [];
|
|
1489
|
+
for (let u = 0; u < e.cols; u++) {
|
|
1490
|
+
const d = 4 * o, f = this.Hr(t.Ur, d), p = ((n = s.hs[f]) == null ? void 0 : n.Se) || i;
|
|
1491
|
+
c.push(p), o++;
|
|
1492
|
+
}
|
|
1493
|
+
r.push(c);
|
|
1494
|
+
}
|
|
1495
|
+
return r;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
class wt {
|
|
1499
|
+
Ui(t, e) {
|
|
1500
|
+
const s = [];
|
|
1501
|
+
for (const r of t) {
|
|
1502
|
+
let o = r.join("");
|
|
1503
|
+
e.Gi || (o = o.replace(/\s+$/, "")), s.push(o);
|
|
1504
|
+
}
|
|
1505
|
+
const i = e.Ei === "crlf" ? `\r
|
|
1506
|
+
` : `
|
|
1507
|
+
`;
|
|
1508
|
+
return s.join(i);
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
class bt extends z {
|
|
1512
|
+
Li(t, e) {
|
|
1513
|
+
const s = this.Bi(e);
|
|
1514
|
+
this.Wr(t, s, "text/plain;charset=utf-8");
|
|
1515
|
+
}
|
|
1516
|
+
Bi(t) {
|
|
1517
|
+
let e = this.qr(t);
|
|
1518
|
+
return e === ".txt" || e.length <= 4 ? this.Qr() : e;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
class G {
|
|
1522
|
+
constructor() {
|
|
1523
|
+
a(this, "Vi");
|
|
1524
|
+
a(this, "Ri");
|
|
1525
|
+
a(this, "ki");
|
|
1526
|
+
this.Vi = new vt(), this.Ri = new wt(), this.ki = new bt();
|
|
1527
|
+
}
|
|
1528
|
+
zi(t) {
|
|
1529
|
+
return { Gi: t.Gi ?? !1, Ei: t.Ei ?? "lf", Hi: t.Hi ?? " " };
|
|
1530
|
+
}
|
|
1531
|
+
Oi(t, e = {}) {
|
|
1532
|
+
const s = this.zi(e), i = this.Vi.Ar(t.Pi), r = this.Vi.Ai(i, t.grid, t.font, s.Hi);
|
|
1533
|
+
return this.Ri.Ui(r, s);
|
|
1534
|
+
}
|
|
1535
|
+
Li(t, e = {}) {
|
|
1536
|
+
const s = this.Oi(t, e), i = e.filename || this.ki.Qr();
|
|
1537
|
+
this.ki.Li(s, i);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
class yt extends I {
|
|
1541
|
+
ji(t, e = 1, s = "transparent") {
|
|
1542
|
+
const i = t.canvas;
|
|
1543
|
+
if (e === 1 && s === "transparent") return i;
|
|
1544
|
+
const r = document.createElement("canvas"), o = r.getContext("2d"), n = Math.round(i.width * e), l = Math.round(i.height * e);
|
|
1545
|
+
return r.width = n, r.height = l, s !== "transparent" && (o.fillStyle = s, o.fillRect(0, 0, n, l)), o.imageSmoothingEnabled = !1, o.drawImage(i, 0, 0, i.width, i.height, 0, 0, n, l), r;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
class Tt {
|
|
1549
|
+
Wi(t, e) {
|
|
1550
|
+
const s = this.Ni(e.format);
|
|
1551
|
+
return e.format === "png" ? t.toDataURL(s) : t.toDataURL(s, e.Xi);
|
|
1552
|
+
}
|
|
1553
|
+
async Yi(t, e) {
|
|
1554
|
+
return new Promise((s, i) => {
|
|
1555
|
+
const r = this.Ni(e.format), o = (n) => {
|
|
1556
|
+
n ? s(n) : i(Error(`Failed to generate ${e.format.toUpperCase()} blob`));
|
|
1557
|
+
};
|
|
1558
|
+
e.format === "png" ? t.toBlob(o, r) : t.toBlob(o, r, e.Xi);
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
Ni(t) {
|
|
1562
|
+
switch (t) {
|
|
1563
|
+
case "png":
|
|
1564
|
+
return "image/png";
|
|
1565
|
+
case "jpg":
|
|
1566
|
+
return "image/jpeg";
|
|
1567
|
+
case "webp":
|
|
1568
|
+
return "image/webp";
|
|
1569
|
+
default:
|
|
1570
|
+
throw Error("Unsupported image format: " + t);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
const j = { qi: "image/png", Qi: "image/jpeg", Zi: "image/webp" }, B = { qi: ".png", Qi: ".jpg", Zi: ".webp" };
|
|
1575
|
+
class Ct extends z {
|
|
1576
|
+
Ji(t, e, s) {
|
|
1577
|
+
this.Ki(t, this.qr(e) + B[s]);
|
|
1578
|
+
}
|
|
1579
|
+
Ki(t, e) {
|
|
1580
|
+
const s = URL.createObjectURL(t);
|
|
1581
|
+
try {
|
|
1582
|
+
const i = document.createElement("a");
|
|
1583
|
+
i.href = s, i.download = e, i.style.display = "none", i.rel = "noopener", document.body.appendChild(i), i.click(), document.body.removeChild(i);
|
|
1584
|
+
} finally {
|
|
1585
|
+
URL.revokeObjectURL(s);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
eo(t) {
|
|
1589
|
+
return t in j && t in B;
|
|
1590
|
+
}
|
|
1591
|
+
Ni(t) {
|
|
1592
|
+
return j[t];
|
|
1593
|
+
}
|
|
1594
|
+
so(t) {
|
|
1595
|
+
return B[t];
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
class Rt {
|
|
1599
|
+
constructor() {
|
|
1600
|
+
a(this, "Vi");
|
|
1601
|
+
a(this, "Ri");
|
|
1602
|
+
a(this, "ki");
|
|
1603
|
+
this.Vi = new yt(), this.Ri = new Tt(), this.ki = new Ct();
|
|
1604
|
+
}
|
|
1605
|
+
zi(t) {
|
|
1606
|
+
return { format: t.format ?? "png", Xi: t.Xi ?? 1, scale: t.scale ?? 1, backgroundColor: t.backgroundColor ?? "transparent" };
|
|
1607
|
+
}
|
|
1608
|
+
ro(t) {
|
|
1609
|
+
if (console.log("Validating image export options:", t), !this.ki.eo(t.format)) throw Error(`Saving '${t.format}' files is not supported`);
|
|
1610
|
+
if (t.Xi < 0 || t.Xi > 1) throw Error("Image quality must be between 0.0 and 1.0");
|
|
1611
|
+
if (t.scale <= 0) throw Error("Scale factor must be greater than 0");
|
|
1612
|
+
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");
|
|
1613
|
+
}
|
|
1614
|
+
io(t, e = {}) {
|
|
1615
|
+
const s = this.zi(e);
|
|
1616
|
+
if (this.ro(s), s.scale === 1 && s.backgroundColor === "transparent") return this.Ri.Wi(t.canvas, s);
|
|
1617
|
+
const i = this.Vi.ji(t, s.scale, s.backgroundColor);
|
|
1618
|
+
return this.Ri.Wi(i, s);
|
|
1619
|
+
}
|
|
1620
|
+
async Yi(t, e = {}) {
|
|
1621
|
+
const s = this.zi(e);
|
|
1622
|
+
if (this.ro(s), s.scale === 1 && s.backgroundColor === "transparent") return await this.Ri.Yi(t.canvas, s);
|
|
1623
|
+
const i = this.Vi.ji(t, s.scale, s.backgroundColor);
|
|
1624
|
+
return await this.Ri.Yi(i, s);
|
|
1625
|
+
}
|
|
1626
|
+
async Ji(t, e = {}) {
|
|
1627
|
+
const s = await this.Yi(t, e), i = e.format ?? "png", r = e.filename || this.ki.Qr();
|
|
1628
|
+
this.ki.Ji(s, r, i);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
const Et = (h) => class extends h {
|
|
1632
|
+
toString(t = {}) {
|
|
1633
|
+
return new G().Oi(this, t);
|
|
1634
|
+
}
|
|
1635
|
+
oo(t = {}) {
|
|
1636
|
+
new G().Li(this, t);
|
|
1637
|
+
}
|
|
1638
|
+
ci(t = {}) {
|
|
1639
|
+
return new V().Ii(this, t);
|
|
1640
|
+
}
|
|
1641
|
+
Si(t = {}) {
|
|
1642
|
+
new V().Si(this, t);
|
|
1643
|
+
}
|
|
1644
|
+
async no(t, e = "png", s = {}) {
|
|
1645
|
+
await new Rt().Ji(this.ho, { ...s, filename: t, format: e });
|
|
1646
|
+
}
|
|
1647
|
+
}, Ft = (h) => class extends h {
|
|
1648
|
+
async ss(t) {
|
|
1649
|
+
return this.Le.ss(t).then(() => {
|
|
1650
|
+
const e = this.Le.us;
|
|
1651
|
+
this.ao.Cs(e.width, e.height), this.lo.resize();
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
fontSize(t) {
|
|
1655
|
+
if (!w.validate(typeof t == "number" && t > 0, "Font size must be a positive number greater than 0.", { method: "fontSize", Ge: t }) || this.Le.fontSize === t) return;
|
|
1656
|
+
this.Le.es(t);
|
|
1657
|
+
const e = this.Le.us;
|
|
1658
|
+
this.ao.Cs(e.width, e.height), this.lo.resize(), this.ye.Bt();
|
|
1659
|
+
}
|
|
1660
|
+
}, Mt = (h) => class extends h {
|
|
1661
|
+
co(t) {
|
|
1662
|
+
return this.lo.add(t);
|
|
1663
|
+
}
|
|
1664
|
+
uo(t) {
|
|
1665
|
+
this.lo.remove(t);
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
class Lt {
|
|
1669
|
+
constructor() {
|
|
1670
|
+
a(this, "ye");
|
|
1671
|
+
a(this, "Le");
|
|
1672
|
+
a(this, "lo");
|
|
1673
|
+
a(this, "ho");
|
|
1674
|
+
a(this, "ao");
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
class H extends function(e, ...s) {
|
|
1678
|
+
return s.reduce((i, r) => r(i), e);
|
|
1679
|
+
}(Lt, gt, Et, Ft, Mt) {
|
|
1680
|
+
constructor(e = null, s = {}) {
|
|
1681
|
+
super();
|
|
1682
|
+
a(this, "Ms");
|
|
1683
|
+
a(this, "fo");
|
|
1684
|
+
a(this, "Vs");
|
|
1685
|
+
a(this, "do");
|
|
1686
|
+
a(this, "mo");
|
|
1687
|
+
a(this, "po", null);
|
|
1688
|
+
a(this, "vo", 0);
|
|
1689
|
+
a(this, "_o");
|
|
1690
|
+
a(this, "xo", !0);
|
|
1691
|
+
a(this, "bo", 0);
|
|
1692
|
+
a(this, "wo", 0);
|
|
1693
|
+
a(this, "Co", 0);
|
|
1694
|
+
a(this, "yo", []);
|
|
1695
|
+
a(this, "Fo", 10);
|
|
1696
|
+
a(this, "To", !1);
|
|
1697
|
+
a(this, "$o", !1);
|
|
1698
|
+
a(this, "Do", () => {
|
|
1699
|
+
});
|
|
1700
|
+
a(this, "Mo", () => {
|
|
1701
|
+
});
|
|
1702
|
+
a(this, "So");
|
|
1703
|
+
a(this, "Vo", !1);
|
|
1704
|
+
this.Ms = e, this.$o = e === null, this.do = s.Ro ?? "auto", this.mo = s.ko ?? 60, this._o = 1e3 / this.mo;
|
|
1705
|
+
}
|
|
1706
|
+
static async create(e = null, s = {}) {
|
|
1707
|
+
const i = new this(e, s), r = i.$o ? s : void 0;
|
|
1708
|
+
let o, n;
|
|
1709
|
+
i.ho = new ct(i.Ms, i.$o, r), i.ye = new it(i.ho.Ps()), i.$o ? (o = s.width || 800, n = s.height || 600) : (o = i.ho.width || 800, n = i.ho.height || 600), i.fo = i.ye.createFramebuffer(o, n), i.Le = new at(i.ye, s.fontSize ?? 16), await i.Le.initialize(s.zo);
|
|
1710
|
+
const l = i.Le.us;
|
|
1711
|
+
return i.ao = new lt(i.ho.canvas, l.width, l.height), i.lo = new ft(i.ye, i.Le, i.ao), i.Io(), i.Po(), i;
|
|
1712
|
+
}
|
|
1713
|
+
Io() {
|
|
1714
|
+
this.So = () => {
|
|
1715
|
+
this.$o ? this.Mo() : this.resize();
|
|
1716
|
+
}, window.addEventListener("resize", this.So), window.ResizeObserver && this.Ms && !this.$o && (this.Vs = new ResizeObserver(() => {
|
|
1717
|
+
this.resize();
|
|
1718
|
+
}), this.Vs.observe(this.Ms));
|
|
1719
|
+
}
|
|
1720
|
+
zr() {
|
|
1721
|
+
if (this.Ao(), this.Co++, this.To) console.warn("Cannot render: Required resources have been disposed");
|
|
1722
|
+
else if (this.$o ? (this.fo.P(), this.Do(), this.fo.end()) : this.fo.update(this.Ms), this.lo.Pr() ? (this.lo.zr(this.fo), this.ye.background(0), this.ye.image(this.lo.texture, this.ao.offsetX, this.ao.offsetY, this.lo.texture.width, this.lo.texture.height)) : (this.ye.clear(), this.ye.image(this.fo, this.ao.offsetX, this.ao.offsetY, this.fo.width, this.fo.height)), this.Vo) {
|
|
1723
|
+
let e = 0;
|
|
1724
|
+
this.ye.image(this.lo.Xs, e, 0, this.lo.Xs.width, this.lo.Xs.height), e += this.lo.Xs.width, this.ye.image(this.lo.Ys, e, 0, this.lo.Ys.width, this.lo.Ys.height), e += this.lo.Ys.width, this.ye.image(this.lo.qs, e, 0, this.lo.qs.width, this.lo.qs.height), e += this.lo.qs.width, this.ye.image(this.lo.Zs, e, 0, this.lo.Zs.width, this.lo.Zs.height), e += this.lo.Zs.width, this.ye.image(this.lo.Qs, e, 0, this.lo.Qs.width, this.lo.Qs.height);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
resize() {
|
|
1728
|
+
this.ho.resize(), this.fo.resize(this.ho.width, this.ho.height), this.ao.resize(), this.lo.resize(), this.ye.Bt(), this.do !== "manual" && this.zr();
|
|
1729
|
+
}
|
|
1730
|
+
Po() {
|
|
1731
|
+
if (this.do !== "auto" || !this.xo) return;
|
|
1732
|
+
this.vo = performance.now();
|
|
1733
|
+
const e = (s) => {
|
|
1734
|
+
if (!this.xo) return void (this.po = null);
|
|
1735
|
+
const i = s - this.vo;
|
|
1736
|
+
i >= this._o && (this.zr(), this.vo = s - i % this._o), this.xo && (this.po = requestAnimationFrame(e));
|
|
1737
|
+
};
|
|
1738
|
+
this.po = requestAnimationFrame(e);
|
|
1739
|
+
}
|
|
1740
|
+
Ao() {
|
|
1741
|
+
const e = performance.now();
|
|
1742
|
+
if (this.wo > 0) {
|
|
1743
|
+
const s = e - this.wo;
|
|
1744
|
+
this.yo.push(s), this.yo.length > this.Fo && this.yo.shift();
|
|
1745
|
+
const i = this.yo.reduce((r, o) => r + o, 0) / this.yo.length;
|
|
1746
|
+
this.bo = 1e3 / i;
|
|
1747
|
+
}
|
|
1748
|
+
this.wo = e;
|
|
1749
|
+
}
|
|
1750
|
+
Uo() {
|
|
1751
|
+
this.po && (cancelAnimationFrame(this.po), this.po = null);
|
|
1752
|
+
}
|
|
1753
|
+
Ro(e) {
|
|
1754
|
+
this.do !== e && (this.Uo(), this.do = e, e === "auto" && this.xo && this.Po());
|
|
1755
|
+
}
|
|
1756
|
+
ko(e) {
|
|
1757
|
+
if (e === void 0) return this.bo;
|
|
1758
|
+
this.mo = e, this._o = 1e3 / e, this.do === "auto" && this.xo && (this.Uo(), this.Po());
|
|
1759
|
+
}
|
|
1760
|
+
Go() {
|
|
1761
|
+
this.xo && (this.xo = !1, this.po && (cancelAnimationFrame(this.po), this.po = null));
|
|
1762
|
+
}
|
|
1763
|
+
loop() {
|
|
1764
|
+
this.xo || (this.xo = !0, this.do === "auto" && this.Po());
|
|
1765
|
+
}
|
|
1766
|
+
Eo(e = 1) {
|
|
1767
|
+
if (w.validate(typeof e == "number" && e > 0 && Number.isInteger(e), "Redraw count must be a positive integer.", { method: "redraw", Ge: e })) for (let s = 0; s < e; s++) this.zr();
|
|
1768
|
+
}
|
|
1769
|
+
Lo() {
|
|
1770
|
+
return this.do === "auto" && this.xo;
|
|
1771
|
+
}
|
|
1772
|
+
draw(e) {
|
|
1773
|
+
this.Do = e;
|
|
1774
|
+
}
|
|
1775
|
+
Bo(e) {
|
|
1776
|
+
this.Mo = e;
|
|
1777
|
+
}
|
|
1778
|
+
Ho(e, s) {
|
|
1779
|
+
this.ho.resize(e, s), this.fo.resize(this.ho.width, this.ho.height), this.ao.resize(), this.lo.resize(), this.ye.Bt(), this.do !== "manual" && this.zr();
|
|
1780
|
+
}
|
|
1781
|
+
destroy() {
|
|
1782
|
+
this.To || (this.Uo(), window.removeEventListener("resize", this.So), this.Vs && this.Vs.disconnect(), this.lo.dispose(), this.Le.dispose(), this.fo.dispose(), this.ye.dispose(), this.To = !0);
|
|
1783
|
+
}
|
|
1784
|
+
debug(e) {
|
|
1785
|
+
this.Vo = e;
|
|
1786
|
+
}
|
|
1787
|
+
get grid() {
|
|
1788
|
+
return this.ao;
|
|
1789
|
+
}
|
|
1790
|
+
get font() {
|
|
1791
|
+
return this.Le;
|
|
1792
|
+
}
|
|
1793
|
+
get mode() {
|
|
1794
|
+
return this.do;
|
|
1795
|
+
}
|
|
1796
|
+
get Pi() {
|
|
1797
|
+
return this.lo;
|
|
1798
|
+
}
|
|
1799
|
+
get frameCount() {
|
|
1800
|
+
return this.Co;
|
|
1801
|
+
}
|
|
1802
|
+
set frameCount(e) {
|
|
1803
|
+
this.Co = e;
|
|
1804
|
+
}
|
|
1805
|
+
get width() {
|
|
1806
|
+
return this.ho.width;
|
|
1807
|
+
}
|
|
1808
|
+
get height() {
|
|
1809
|
+
return this.ho.height;
|
|
1810
|
+
}
|
|
1811
|
+
get Oo() {
|
|
1812
|
+
return this.To;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
class O {
|
|
1816
|
+
static async create(t, e = {}) {
|
|
1817
|
+
if (t instanceof HTMLCanvasElement || t instanceof HTMLVideoElement) return H.create(t, e);
|
|
1818
|
+
{
|
|
1819
|
+
const s = t || {};
|
|
1820
|
+
return H.create(null, s);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
static jo(t) {
|
|
1824
|
+
w.v(t);
|
|
1825
|
+
}
|
|
1826
|
+
static get version() {
|
|
1827
|
+
return "0.1.6-beta.6";
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
const $t = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), St = O.create, Ut = O.jo, Bt = O.version;
|
|
1831
|
+
export {
|
|
1832
|
+
ct as TextmodeCanvas,
|
|
1833
|
+
ft as TextmodeConversionPipeline,
|
|
1834
|
+
tt as TextmodeErrorLevel,
|
|
1835
|
+
at as TextmodeFont,
|
|
1836
|
+
lt as TextmodeGrid,
|
|
1837
|
+
H as Textmodifier,
|
|
1838
|
+
At as converters,
|
|
1839
|
+
St as create,
|
|
1840
|
+
$t as export,
|
|
1841
|
+
Ut as setErrorLevel,
|
|
1842
|
+
O as textmode,
|
|
1843
|
+
Bt as version
|
|
1844
|
+
};
|