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