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