@levischuck/receiptline 0.1.1 → 0.1.3
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/index.js +660 -636
- package/dist/targets/html.d.ts +8 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { decodeBase64 as
|
|
1
|
+
import { decodeBase64 as Z, encodeBase64 as O } from "@levischuck/tiny-encodings";
|
|
2
2
|
import { qrCode as _, EcLevel as M } from "@levischuck/tiny-qr";
|
|
3
|
-
import { toSvgString as
|
|
3
|
+
import { toSvgString as nt } from "@levischuck/tiny-qr-svg";
|
|
4
4
|
class H {
|
|
5
5
|
locked = !1;
|
|
6
6
|
lockPromise = null;
|
|
@@ -26,20 +26,20 @@ class H {
|
|
|
26
26
|
});
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const e = new AbortController(),
|
|
29
|
+
const e = new AbortController(), n = setTimeout(() => {
|
|
30
30
|
e.abort();
|
|
31
31
|
}, t);
|
|
32
32
|
try {
|
|
33
33
|
await Promise.race([
|
|
34
34
|
this.lockPromise,
|
|
35
|
-
new Promise((a,
|
|
35
|
+
new Promise((a, r) => {
|
|
36
36
|
e.signal.addEventListener("abort", () => {
|
|
37
|
-
|
|
37
|
+
r(new Error(`Lock timeout after ${t}ms`));
|
|
38
38
|
});
|
|
39
39
|
})
|
|
40
40
|
]);
|
|
41
41
|
} finally {
|
|
42
|
-
clearTimeout(
|
|
42
|
+
clearTimeout(n);
|
|
43
43
|
}
|
|
44
44
|
this.locked = !0, this.lockPromise = new Promise((a) => {
|
|
45
45
|
this.lockResolve = a;
|
|
@@ -58,14 +58,14 @@ class H {
|
|
|
58
58
|
* @returns {number} string width
|
|
59
59
|
*/
|
|
60
60
|
measureText(t, e) {
|
|
61
|
-
let
|
|
61
|
+
let n = 0;
|
|
62
62
|
const a = Array.from(t);
|
|
63
63
|
switch (e) {
|
|
64
64
|
case "cp932":
|
|
65
65
|
case "shiftjis":
|
|
66
|
-
|
|
66
|
+
n = a.reduce((s, h) => {
|
|
67
67
|
const o = h.codePointAt(0);
|
|
68
|
-
return o === void 0 ?
|
|
68
|
+
return o === void 0 ? s : s + (o < 128 || o === 160 || o === 165 || o === 8254 || o > 65376 && o < 65440 ? 1 : 2);
|
|
69
69
|
}, 0);
|
|
70
70
|
break;
|
|
71
71
|
case "cp936":
|
|
@@ -74,23 +74,23 @@ class H {
|
|
|
74
74
|
case "ksc5601":
|
|
75
75
|
case "cp950":
|
|
76
76
|
case "big5":
|
|
77
|
-
|
|
77
|
+
n = a.reduce((s, h) => {
|
|
78
78
|
const o = h.codePointAt(0);
|
|
79
|
-
return o === void 0 ?
|
|
79
|
+
return o === void 0 ? s : s + (o < 128 || o === 160 ? 1 : 2);
|
|
80
80
|
}, 0);
|
|
81
81
|
break;
|
|
82
82
|
case "tis620":
|
|
83
|
-
const
|
|
83
|
+
const r = a.reduce((s, h) => {
|
|
84
84
|
const o = h.codePointAt(0);
|
|
85
|
-
return o === void 0 || (
|
|
85
|
+
return o === void 0 || (s.consonant ? o === 3633 || o >= 3636 && o <= 3642 || o === 3655 ? s.vowel ? (s.length += 2, s.consonant = s.vowel = s.tone = !1) : s.vowel = !0 : o >= 3656 && o <= 3659 ? s.tone ? (s.length += 2, s.consonant = s.vowel = s.tone = !1) : s.tone = !0 : o === 3635 || o >= 3660 && o <= 3662 ? s.vowel || s.tone ? (s.length += 2, s.consonant = s.vowel = s.tone = !1) : (s.length += o === 3635 ? 2 : 1, s.consonant = !1) : o >= 3585 && o <= 3630 ? (s.length++, s.vowel = s.tone = !1) : (s.length += 2, s.consonant = s.vowel = s.tone = !1) : o >= 3585 && o <= 3630 ? s.consonant = !0 : s.length++), s;
|
|
86
86
|
}, { length: 0, consonant: !1, vowel: !1, tone: !1 });
|
|
87
|
-
|
|
87
|
+
r.consonant && (r.length++, r.consonant = r.vowel = r.tone = !1), n = r.length;
|
|
88
88
|
break;
|
|
89
89
|
default:
|
|
90
|
-
|
|
90
|
+
n = a.length;
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
|
-
return
|
|
93
|
+
return n;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Create character array from string (supporting Thai combining characters).
|
|
@@ -99,19 +99,19 @@ class H {
|
|
|
99
99
|
* @returns {string[]} array instance
|
|
100
100
|
*/
|
|
101
101
|
arrayFrom(t, e) {
|
|
102
|
-
const
|
|
102
|
+
const n = Array.from(t);
|
|
103
103
|
switch (e) {
|
|
104
104
|
case "cp932":
|
|
105
105
|
case "shiftjis":
|
|
106
|
-
return
|
|
106
|
+
return n.map((r) => r.replace(/\\/g, "¥").replace(/\u203e/g, "~").replace(/\u301c/g, "~"));
|
|
107
107
|
case "tis620":
|
|
108
|
-
const a =
|
|
109
|
-
const h =
|
|
110
|
-
return h === void 0 || (
|
|
108
|
+
const a = n.reduce((r, s) => {
|
|
109
|
+
const h = s.codePointAt(0);
|
|
110
|
+
return h === void 0 || (r.consonant ? h === 3633 || h >= 3636 && h <= 3642 || h === 3655 ? r.vowel ? (r.result.push(r.consonant + r.vowel + r.tone, s), r.consonant = r.vowel = r.tone = "") : r.vowel = s : h >= 3656 && h <= 3659 ? r.tone ? (r.result.push(r.consonant + r.vowel + r.tone, s), r.consonant = r.vowel = r.tone = "") : r.tone = s : h === 3635 || h >= 3660 && h <= 3662 ? r.vowel || r.tone ? (r.result.push(r.consonant + r.vowel + r.tone, s), r.consonant = r.vowel = r.tone = "") : (r.result.push(r.consonant + s), r.consonant = "") : h >= 3585 && h <= 3630 ? (r.result.push(r.consonant + r.vowel + r.tone), r.consonant = s, r.vowel = r.tone = "") : (r.result.push(r.consonant + r.vowel + r.tone, s), r.consonant = r.vowel = r.tone = "") : h >= 3585 && h <= 3630 ? r.consonant = s : r.result.push(s)), r;
|
|
111
111
|
}, { result: [], consonant: "", vowel: "", tone: "" });
|
|
112
112
|
return a.consonant && (a.result.push(a.consonant + a.vowel + a.tone), a.consonant = a.vowel = a.tone = ""), a.result;
|
|
113
113
|
default:
|
|
114
|
-
return
|
|
114
|
+
return n;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
@@ -136,7 +136,7 @@ class H {
|
|
|
136
136
|
* @param {number} right right margin (unit: characters)
|
|
137
137
|
* @returns {Promise<string>} commands
|
|
138
138
|
*/
|
|
139
|
-
async area(t, e,
|
|
139
|
+
async area(t, e, n) {
|
|
140
140
|
return "";
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
@@ -204,7 +204,7 @@ class H {
|
|
|
204
204
|
* @param {number} dr difference in right position
|
|
205
205
|
* @returns {Promise<string>} commands
|
|
206
206
|
*/
|
|
207
|
-
async vrhr(t, e,
|
|
207
|
+
async vrhr(t, e, n, a) {
|
|
208
208
|
return "";
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
@@ -329,49 +329,49 @@ const y = {
|
|
|
329
329
|
shift: 98,
|
|
330
330
|
stop: 106
|
|
331
331
|
};
|
|
332
|
-
function
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
/^\d{4,}/.test(t) ? L(y.atoc, t, e) : a >= 0 &&
|
|
332
|
+
function j(i, t, e) {
|
|
333
|
+
i !== y.shift && e.push(i), t = t.replace(/^((?!\d{4,})[\x00-_])+/, (r) => (r.split("").forEach((s) => e.push((s.charCodeAt(0) + 64) % 96)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push((r.charCodeAt(0) + 64) % 96), ""));
|
|
334
|
+
const n = t.slice(1), a = n.search(/[^ -_]/);
|
|
335
|
+
/^\d{4,}/.test(t) ? L(y.atoc, t, e) : a >= 0 && n.charCodeAt(a) < 32 ? (e.push(y.shift, t.charCodeAt(0) - 32), j(y.shift, n, e)) : t.length > 0 && E(y.atob, t, e);
|
|
336
336
|
}
|
|
337
|
-
function
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
/^\d{4,}/.test(t) ? L(y.btoc, t, e) : a >= 0 &&
|
|
337
|
+
function E(i, t, e) {
|
|
338
|
+
i !== y.shift && e.push(i), t = t.replace(/^((?!\d{4,})[ -\x7f])+/, (r) => (r.split("").forEach((s) => e.push(s.charCodeAt(0) - 32)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push(r.charCodeAt(0) - 32), ""));
|
|
339
|
+
const n = t.slice(1), a = n.search(/[^ -_]/);
|
|
340
|
+
/^\d{4,}/.test(t) ? L(y.btoc, t, e) : a >= 0 && n.charCodeAt(a) > 95 ? (e.push(y.shift, t.charCodeAt(0) + 64), E(y.shift, n, e)) : t.length > 0 && j(y.btoa, t, e);
|
|
341
341
|
}
|
|
342
|
-
function L(
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
342
|
+
function L(i, t, e) {
|
|
343
|
+
i !== y.shift && e.push(i), t = t.replace(/^\d{4,}/g, (a) => a.replace(/\d{2}/g, (r) => (e.push(Number(r)), "")));
|
|
344
|
+
const n = t.search(/[^ -_]/);
|
|
345
|
+
n >= 0 && t.charCodeAt(n) < 32 ? j(y.ctoa, t, e) : t.length > 0 && E(y.ctob, t, e);
|
|
346
346
|
}
|
|
347
|
-
function
|
|
347
|
+
function st(i) {
|
|
348
348
|
const t = {};
|
|
349
|
-
let e =
|
|
349
|
+
let e = i.data.replace(/((?!^[\x00-\x7f]+$).)*/, "");
|
|
350
350
|
if (e.length > 0) {
|
|
351
|
-
t.hri =
|
|
352
|
-
const
|
|
353
|
-
/^\d{2}$/.test(e) ?
|
|
354
|
-
const
|
|
355
|
-
t.widths =
|
|
351
|
+
t.hri = i.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
|
|
352
|
+
const n = [], a = e.search(/[^ -_]/);
|
|
353
|
+
/^\d{2}$/.test(e) ? n.push(y.startc, Number(e)) : /^\d{4,}/.test(e) ? L(y.startc, e, n) : a >= 0 && e.charCodeAt(a) < 32 ? j(y.starta, e, n) : e.length > 0 && E(y.startb, e, n), n.push(n.reduce((h, o, c) => h + o * c) % 103, y.stop);
|
|
354
|
+
const r = i.quietZone ? "a" : "0", s = n.reduce((h, o) => h + y.element[o], r) + r;
|
|
355
|
+
t.widths = s.split("").map((h) => parseInt(h, 16) * i.width), t.length = i.width * (n.length * 11 + (i.quietZone ? 22 : 2)), t.height = i.height;
|
|
356
356
|
}
|
|
357
357
|
return t;
|
|
358
358
|
}
|
|
359
359
|
const C = {
|
|
360
360
|
escape: "cU,dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ,cA,cB,cC,cD,cE, ,sA,sB,sC,$,%,sF,sG,sH,sI,sJ,+,sL,-,.,/,0,1,2,3,4,5,6,7,8,9,sZ,cF,cG,cH,cI,cJ,cV,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,cK,cL,cM,cN,cO,cW,pA,pB,pC,pD,pE,pF,pG,pH,pI,pJ,pK,pL,pM,pN,pO,pP,pQ,pR,pS,pT,pU,pV,pW,pX,pY,pZ,cP,cQ,cR,cS,cT".split(","),
|
|
361
|
-
code: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%dcsp".split("").reduce((
|
|
361
|
+
code: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%dcsp".split("").reduce((i, t, e) => (i[t] = e, i), {}),
|
|
362
362
|
element: "131112,111213,111312,111411,121113,121212,121311,111114,131211,141111,211113,211212,211311,221112,221211,231111,112113,112212,112311,122112,132111,111123,111222,111321,121122,131121,212112,212211,211122,211221,221121,222111,112122,112221,122121,123111,121131,311112,311211,321111,112131,113121,211131,121221,312111,311121,122211,111141,1111411".split(","),
|
|
363
363
|
start: 47,
|
|
364
364
|
stop: 48
|
|
365
365
|
};
|
|
366
|
-
function
|
|
366
|
+
function rt(i) {
|
|
367
367
|
const t = {};
|
|
368
|
-
let e =
|
|
368
|
+
let e = i.data.replace(/((?!^[\x00-\x7f]+$).)*/, "");
|
|
369
369
|
if (e.length > 0) {
|
|
370
|
-
t.hri =
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
const a =
|
|
374
|
-
t.widths =
|
|
370
|
+
t.hri = i.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
|
|
371
|
+
const n = e.split("").reduce((s, h) => s + C.escape[h.charCodeAt(0)], "").split("").map((s) => C.code[s]);
|
|
372
|
+
n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 20 + 1)) % 47), n.push(n.reduceRight((s, h, o) => s + h * ((n.length - 1 - o) % 15 + 1)) % 47), n.unshift(C.start), n.push(C.stop);
|
|
373
|
+
const a = i.quietZone ? "a" : "0", r = n.reduce((s, h) => s + C.element[h], a) + a;
|
|
374
|
+
t.widths = r.split("").map((s) => parseInt(s, 16) * i.width), t.length = i.width * (n.length * 9 + (i.quietZone ? 21 : 1)), t.height = i.height;
|
|
375
375
|
}
|
|
376
376
|
return t;
|
|
377
377
|
}
|
|
@@ -397,15 +397,15 @@ const at = {
|
|
|
397
397
|
C: "2225255",
|
|
398
398
|
D: "2225552"
|
|
399
399
|
};
|
|
400
|
-
function ot(
|
|
400
|
+
function ot(i) {
|
|
401
401
|
const t = {};
|
|
402
|
-
let e =
|
|
402
|
+
let e = i.data.replace(/((?!^[A-D][0-9\-$:/.+]+[A-D]$).)*/i, "");
|
|
403
403
|
if (e.length > 0) {
|
|
404
|
-
t.hri =
|
|
405
|
-
const
|
|
406
|
-
t.widths = a.split("").map((
|
|
407
|
-
const
|
|
408
|
-
t.length = e.length *
|
|
404
|
+
t.hri = i.hri, t.text = e;
|
|
405
|
+
const n = i.quietZone ? "a" : "0", a = e.toUpperCase().split("").reduce((s, h) => s + at[h] + "2", n).slice(0, -1) + n;
|
|
406
|
+
t.widths = a.split("").map((s) => parseInt(s, 16) * i.width + 1 >> 1);
|
|
407
|
+
const r = [25, 39, 50, 3, 5, 6];
|
|
408
|
+
t.length = e.length * r[i.width - 2] - (e.match(/[\d\-$]/g) || []).length * r[i.width + 1] + i.width * (i.quietZone ? 19 : -1), t.height = i.height;
|
|
409
409
|
}
|
|
410
410
|
return t;
|
|
411
411
|
}
|
|
@@ -414,20 +414,20 @@ const q = {
|
|
|
414
414
|
start: "2222",
|
|
415
415
|
stop: "522"
|
|
416
416
|
};
|
|
417
|
-
function ht(
|
|
417
|
+
function ht(i) {
|
|
418
418
|
const t = {};
|
|
419
|
-
let e =
|
|
419
|
+
let e = i.data.replace(/((?!^(\d{2})+$).)*/, "");
|
|
420
420
|
if (e.length > 0) {
|
|
421
|
-
t.hri =
|
|
422
|
-
const
|
|
423
|
-
let
|
|
424
|
-
for (;
|
|
425
|
-
const o = q.element[
|
|
426
|
-
|
|
421
|
+
t.hri = i.hri, t.text = e;
|
|
422
|
+
const n = e.split("").map((o) => Number(o)), a = i.quietZone ? "a" : "0";
|
|
423
|
+
let r = a + q.start, s = 0;
|
|
424
|
+
for (; s < n.length; ) {
|
|
425
|
+
const o = q.element[n[s++]], c = q.element[n[s++]];
|
|
426
|
+
r += o.split("").reduce((d, u, l) => d + u + c[l], "");
|
|
427
427
|
}
|
|
428
|
-
|
|
428
|
+
r += q.stop + a, t.widths = r.split("").map((o) => parseInt(o, 16) * i.width + 1 >> 1);
|
|
429
429
|
const h = [16, 25, 32, 17, 26, 34];
|
|
430
|
-
t.length = e.length * h[
|
|
430
|
+
t.length = e.length * h[i.width - 2] + h[i.width + 1] + i.width * (i.quietZone ? 20 : 0), t.height = i.height;
|
|
431
431
|
}
|
|
432
432
|
return t;
|
|
433
433
|
}
|
|
@@ -477,15 +477,15 @@ const ct = {
|
|
|
477
477
|
"%": "222525252",
|
|
478
478
|
"*": "252252522"
|
|
479
479
|
};
|
|
480
|
-
function lt(
|
|
480
|
+
function lt(i) {
|
|
481
481
|
const t = {};
|
|
482
|
-
let e =
|
|
482
|
+
let e = i.data.replace(/((?!^\*?[0-9A-Z\-. $/+%]+\*?$).)*/, "");
|
|
483
483
|
if (e.length > 0) {
|
|
484
|
-
e = e.replace(/^\*?([^*]+)\*?$/, "*$1*"), t.hri =
|
|
485
|
-
const
|
|
486
|
-
t.widths = a.split("").map((
|
|
487
|
-
const
|
|
488
|
-
t.length = e.length *
|
|
484
|
+
e = e.replace(/^\*?([^*]+)\*?$/, "*$1*"), t.hri = i.hri, t.text = e;
|
|
485
|
+
const n = i.quietZone ? "a" : "0", a = e.split("").reduce((s, h) => s + ct[h] + "2", n).slice(0, -1) + n;
|
|
486
|
+
t.widths = a.split("").map((s) => parseInt(s, 16) * i.width + 1 >> 1);
|
|
487
|
+
const r = [29, 45, 58];
|
|
488
|
+
t.length = e.length * r[i.width - 2] + i.width * (i.quietZone ? 19 : -1), t.height = i.height;
|
|
489
489
|
}
|
|
490
490
|
return t;
|
|
491
491
|
}
|
|
@@ -497,102 +497,102 @@ const b = {
|
|
|
497
497
|
p: "aaaaaa,aababb,aabbab,aabbba,abaabb,abbaab,abbbaa,ababab,ababba,abbaba".split(","),
|
|
498
498
|
e: "bbbaaa,bbabaa,bbaaba,bbaaab,babbaa,baabba,baaabb,bababa,babaab,baabab".split(",")
|
|
499
499
|
};
|
|
500
|
-
function dt(
|
|
501
|
-
const t =
|
|
502
|
-
switch (
|
|
500
|
+
function dt(i) {
|
|
501
|
+
const t = i.slice(0, 3);
|
|
502
|
+
switch (i[6]) {
|
|
503
503
|
case 0:
|
|
504
504
|
case 1:
|
|
505
505
|
case 2:
|
|
506
|
-
t.push(
|
|
506
|
+
t.push(i[6], 0, 0, 0, 0, i[3], i[4], i[5]);
|
|
507
507
|
break;
|
|
508
508
|
case 3:
|
|
509
|
-
t.push(
|
|
509
|
+
t.push(i[3], 0, 0, 0, 0, 0, i[4], i[5]);
|
|
510
510
|
break;
|
|
511
511
|
case 4:
|
|
512
|
-
t.push(
|
|
512
|
+
t.push(i[3], i[4], 0, 0, 0, 0, 0, i[5]);
|
|
513
513
|
break;
|
|
514
514
|
default:
|
|
515
|
-
t.push(
|
|
515
|
+
t.push(i[3], i[4], i[5], 0, 0, 0, 0, i[6]);
|
|
516
516
|
break;
|
|
517
517
|
}
|
|
518
|
-
return t.push(
|
|
518
|
+
return t.push(i[7]), t;
|
|
519
519
|
}
|
|
520
|
-
function G(
|
|
521
|
-
const t = {}, e =
|
|
520
|
+
function G(i) {
|
|
521
|
+
const t = {}, e = i.data.replace(/((?!^\d{12,13}$).)*/, "").split("").map((n) => Number(n));
|
|
522
522
|
if (e.length > 0) {
|
|
523
|
-
e[12] = 0, e[12] = (10 - e.reduce((a,
|
|
524
|
-
let
|
|
525
|
-
for (let a = 1; a < 7; a++)
|
|
526
|
-
|
|
527
|
-
for (let a = 7; a < 13; a++)
|
|
528
|
-
|
|
523
|
+
e[12] = 0, e[12] = (10 - e.reduce((a, r, s) => a + r * (s % 2 * 2 + 1)) % 10) % 10, t.hri = i.hri, t.text = e.join("");
|
|
524
|
+
let n = (i.quietZone ? "b" : "0") + b.g[0];
|
|
525
|
+
for (let a = 1; a < 7; a++) n += b[b.p[e[0]][a - 1]][e[a]];
|
|
526
|
+
n += b.g[1];
|
|
527
|
+
for (let a = 7; a < 13; a++) n += b.c[e[a]];
|
|
528
|
+
n += b.g[0] + (i.quietZone ? "7" : "0"), t.widths = n.split("").map((a) => parseInt(a, 16) * i.width), t.length = i.width * (i.quietZone ? 113 : 95), t.height = i.height;
|
|
529
529
|
}
|
|
530
530
|
return t;
|
|
531
531
|
}
|
|
532
|
-
function gt(
|
|
533
|
-
const t = {}, e =
|
|
532
|
+
function gt(i) {
|
|
533
|
+
const t = {}, e = i.data.replace(/((?!^\d{7,8}$).)*/, "").split("").map((n) => Number(n));
|
|
534
534
|
if (e.length > 0) {
|
|
535
|
-
e[7] = 0, e[7] = (10 - e.reduce((
|
|
536
|
-
const
|
|
537
|
-
let a =
|
|
538
|
-
for (let
|
|
535
|
+
e[7] = 0, e[7] = (10 - e.reduce((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = i.hri, t.text = e.join("");
|
|
536
|
+
const n = i.quietZone ? "7" : "0";
|
|
537
|
+
let a = n + b.g[0];
|
|
538
|
+
for (let r = 0; r < 4; r++) a += b.a[e[r] ?? 0];
|
|
539
539
|
a += b.g[1];
|
|
540
|
-
for (let
|
|
541
|
-
a += b.g[0] +
|
|
540
|
+
for (let r = 4; r < 8; r++) a += b.c[e[r] ?? 0];
|
|
541
|
+
a += b.g[0] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 81 : 67), t.height = i.height;
|
|
542
542
|
}
|
|
543
543
|
return t;
|
|
544
544
|
}
|
|
545
|
-
function ut(
|
|
545
|
+
function ut(i) {
|
|
546
546
|
const t = {
|
|
547
|
-
data: "0" +
|
|
548
|
-
hri:
|
|
549
|
-
width:
|
|
550
|
-
height:
|
|
551
|
-
quietZone:
|
|
547
|
+
data: "0" + i.data,
|
|
548
|
+
hri: i.hri,
|
|
549
|
+
width: i.width,
|
|
550
|
+
height: i.height,
|
|
551
|
+
quietZone: i.quietZone
|
|
552
552
|
}, e = G(t);
|
|
553
553
|
return e.text && (e.text = e.text.slice(1)), e;
|
|
554
554
|
}
|
|
555
|
-
function pt(
|
|
556
|
-
const t = {}, e =
|
|
555
|
+
function pt(i) {
|
|
556
|
+
const t = {}, e = i.data.replace(/((?!^0\d{6,7}$).)*/, "").split("").map((n) => Number(n));
|
|
557
557
|
if (e.length > 0) {
|
|
558
|
-
e[7] = 0, e[7] = (10 - dt(e).reduce((
|
|
559
|
-
const
|
|
560
|
-
let a =
|
|
561
|
-
for (let
|
|
562
|
-
a += b.g[2] +
|
|
558
|
+
e[7] = 0, e[7] = (10 - dt(e).reduce((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = i.hri, t.text = e.join("");
|
|
559
|
+
const n = i.quietZone ? "7" : "0";
|
|
560
|
+
let a = n + b.g[0];
|
|
561
|
+
for (let r = 1; r < 7; r++) a += b[b.e[e[7] ?? 0][r - 1]][e[r] ?? 0];
|
|
562
|
+
a += b.g[2] + n, t.widths = a.split("").map((r) => parseInt(r, 16) * i.width), t.length = i.width * (i.quietZone ? 65 : 51), t.height = i.height;
|
|
563
563
|
}
|
|
564
564
|
return t;
|
|
565
565
|
}
|
|
566
|
-
function K(
|
|
566
|
+
function K(i) {
|
|
567
567
|
let t = {};
|
|
568
|
-
switch (
|
|
568
|
+
switch (i.type) {
|
|
569
569
|
case "upc":
|
|
570
|
-
t =
|
|
570
|
+
t = i.data.length < 9 ? pt(i) : ut(i);
|
|
571
571
|
break;
|
|
572
572
|
case "ean":
|
|
573
573
|
case "jan":
|
|
574
|
-
t =
|
|
574
|
+
t = i.data.length < 9 ? gt(i) : G(i);
|
|
575
575
|
break;
|
|
576
576
|
case "code39":
|
|
577
|
-
t = lt(
|
|
577
|
+
t = lt(i);
|
|
578
578
|
break;
|
|
579
579
|
case "itf":
|
|
580
|
-
t = ht(
|
|
580
|
+
t = ht(i);
|
|
581
581
|
break;
|
|
582
582
|
case "codabar":
|
|
583
583
|
case "nw7":
|
|
584
|
-
t = ot(
|
|
584
|
+
t = ot(i);
|
|
585
585
|
break;
|
|
586
586
|
case "code93":
|
|
587
|
-
t =
|
|
587
|
+
t = rt(i);
|
|
588
588
|
break;
|
|
589
589
|
case "code128":
|
|
590
|
-
t =
|
|
590
|
+
t = st(i);
|
|
591
591
|
break;
|
|
592
592
|
}
|
|
593
593
|
return t;
|
|
594
594
|
}
|
|
595
|
-
class
|
|
595
|
+
class F extends H {
|
|
596
596
|
charWidth = 12;
|
|
597
597
|
receiptId = "";
|
|
598
598
|
svgWidth = 576;
|
|
@@ -647,12 +647,12 @@ class I extends H {
|
|
|
647
647
|
break;
|
|
648
648
|
}
|
|
649
649
|
t.style.length > 0 && (t.style = `<style type="text/css"><![CDATA[${t.style}]]></style>`), t.lang.length > 0 && (t.lang = ` xml:lang="${t.lang}"`), this.fontSize = t.size;
|
|
650
|
-
const e = this.calculatedWidth(),
|
|
651
|
-
return `<svg width="${e}px" height="${
|
|
650
|
+
const e = this.calculatedWidth(), n = this.calculatedHeight();
|
|
651
|
+
return `<svg width="${e}px" height="${n}px" viewBox="0 0 ${e} ${n}" preserveAspectRatio="xMinYMin meet" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">${t.style}<defs><filter id="receipt-${this.receiptId}" x="0" y="0" width="100%" height="100%"><feFlood flood-color="#000"/><feComposite in2="SourceGraphic" operator="out"/></filter></defs><rect width="100%" height="100%" fill="white" /><g font-family="${t.font}" fill="#000" font-size="${t.size}" dominant-baseline="text-after-edge" text-anchor="middle"${t.lang}>${this.svgContent}</g></svg>
|
|
652
652
|
`;
|
|
653
653
|
}
|
|
654
654
|
// set print area:
|
|
655
|
-
async area(t, e,
|
|
655
|
+
async area(t, e, n) {
|
|
656
656
|
return this.lineMargin = t, this.lineWidth = e, "";
|
|
657
657
|
}
|
|
658
658
|
// set line alignment:
|
|
@@ -669,30 +669,30 @@ class I extends H {
|
|
|
669
669
|
}
|
|
670
670
|
// print horizontal rule:
|
|
671
671
|
async hr(t) {
|
|
672
|
-
const e = this.charWidth,
|
|
673
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${
|
|
672
|
+
const e = this.charWidth, n = `<path d="M0,${e}h${e * t}" fill="none" stroke="#000" stroke-width="2"/>`;
|
|
673
|
+
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${n}</g>`, "";
|
|
674
674
|
}
|
|
675
675
|
// print vertical rules:
|
|
676
676
|
async vr(t, e) {
|
|
677
|
-
const
|
|
678
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin *
|
|
677
|
+
const n = this.charWidth, a = n / 2, r = (n + n) * e, s = '<path d="' + t.reduce((h, o) => h + `m${n * o + n},${-r}v${r}`, `M${a},0v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
678
|
+
return this.svgContent += `<g transform="translate(${this.lineMargin * n},${this.svgHeight})">${s}</g>`, "";
|
|
679
679
|
}
|
|
680
680
|
// start rules:
|
|
681
681
|
async vrstart(t) {
|
|
682
|
-
const e = this.charWidth,
|
|
682
|
+
const e = this.charWidth, n = e / 2, a = '<path d="' + t.reduce((r, s) => r + `h${e * s}h${n}v${e}m0,${-e}h${n}`, `M${n},${e + e}v${-n}q0,${-n},${n},${-n}`).replace(/h\d+v\d+m0,-\d+h\d+$/, `q${n},0,${n},${n}v${n}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
683
683
|
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${a}</g>`, "";
|
|
684
684
|
}
|
|
685
685
|
// stop rules:
|
|
686
686
|
async vrstop(t) {
|
|
687
|
-
const e = this.charWidth,
|
|
687
|
+
const e = this.charWidth, n = e / 2, a = '<path d="' + t.reduce((r, s) => r + `h${e * s}h${n}v${-e}m0,${e}h${n}`, `M${n},0v${n}q0,${n},${n},${n}`).replace(/h\d+v-\d+m0,\d+h\d+$/, `q${n},0,${n},${-n}v${-n}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
688
688
|
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${a}</g>`, "";
|
|
689
689
|
}
|
|
690
690
|
// print vertical and horizontal rules:
|
|
691
|
-
async vrhr(t, e,
|
|
692
|
-
const
|
|
693
|
-
this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(-
|
|
694
|
-
const o = '<path d="' + e.reduce((c,
|
|
695
|
-
return this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(
|
|
691
|
+
async vrhr(t, e, n, a) {
|
|
692
|
+
const r = this.charWidth, s = r / 2, h = '<path d="' + t.reduce((c, d) => c + `h${r * d}h${s}v${-r}m0,${r}h${s}`, `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`)).replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
693
|
+
this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(-n, 0)) * r},${this.svgHeight})">${h}</g>`;
|
|
694
|
+
const o = '<path d="' + e.reduce((c, d) => c + `h${r * d}h${s}v${r}m0,${-r}h${s}`, `M${s},${r + r}` + (n < 0 ? `v${-s}q0,${-s},${s},${-s}` : `v${-r}h${s}`)).replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${s},0,${s},${s}v${s}` : `h${s}v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
695
|
+
return this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(n, 0)) * r},${this.svgHeight})">${o}</g>`, "";
|
|
696
696
|
}
|
|
697
697
|
// set line spacing and feed new line:
|
|
698
698
|
async vrlf(t) {
|
|
@@ -717,8 +717,8 @@ class I extends H {
|
|
|
717
717
|
}
|
|
718
718
|
// scale up text:
|
|
719
719
|
async wh(t) {
|
|
720
|
-
const e = t < 2 ? t + 1 : t - 1,
|
|
721
|
-
return this.textAttributes.transform = `scale(${e},${
|
|
720
|
+
const e = t < 2 ? t + 1 : t - 1, n = t < 3 ? t : t - 1;
|
|
721
|
+
return this.textAttributes.transform = `scale(${e},${n})`, this.lineHeight = Math.max(this.lineHeight, n), this.textScale = e, "";
|
|
722
722
|
}
|
|
723
723
|
// cancel text decoration:
|
|
724
724
|
async normal() {
|
|
@@ -726,12 +726,12 @@ class I extends H {
|
|
|
726
726
|
}
|
|
727
727
|
// print text:
|
|
728
728
|
async text(t, e) {
|
|
729
|
-
let
|
|
730
|
-
const a = this.arrayFrom(t, e).reduce((
|
|
731
|
-
const o = this.measureText(h, e) * this.textScale, c = Math.floor((
|
|
732
|
-
return
|
|
733
|
-
}, ""),
|
|
734
|
-
return this.textElement += `<text${
|
|
729
|
+
let n = this.textPosition;
|
|
730
|
+
const a = this.arrayFrom(t, e).reduce((s, h) => {
|
|
731
|
+
const o = this.measureText(h, e) * this.textScale, c = Math.floor((n + o / 2) * this.charWidth / this.textScale);
|
|
732
|
+
return n += o, s + `<tspan x="${c}">${h.replace(/[ &<>]/g, (d) => ({ " ": " ", "&": "&", "<": "<", ">": ">" })[d] || d)}</tspan>`;
|
|
733
|
+
}, ""), r = Object.keys(this.textAttributes).reduce((s, h) => s + ` ${h}="${this.textAttributes[h]}"`, "");
|
|
734
|
+
return this.textElement += `<text${r}>${a}</text>`, this.textPosition += this.measureText(t, e) * this.textScale, "";
|
|
735
735
|
}
|
|
736
736
|
// feed new line:
|
|
737
737
|
async lf() {
|
|
@@ -744,35 +744,35 @@ class I extends H {
|
|
|
744
744
|
}
|
|
745
745
|
// print image:
|
|
746
746
|
async image(t) {
|
|
747
|
-
const e =
|
|
748
|
-
return this.svgContent += `<g transform="translate(${h},${this.svgHeight})">${
|
|
747
|
+
const e = Z(t), n = new DataView(e.buffer), a = n.getUint32(16, !1), r = n.getUint32(20, !1), s = `<image href="data:image/png;base64,${O(e)}" x="0" y="0" width="${a}" height="${r}"/>`, h = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - a) * this.lineAlign / 2);
|
|
748
|
+
return this.svgContent += `<g transform="translate(${h},${this.svgHeight})">${s}</g>`, this.svgHeight += r, "";
|
|
749
749
|
}
|
|
750
750
|
// print QR Code:
|
|
751
751
|
async qrcode(t, e) {
|
|
752
|
-
const
|
|
752
|
+
const n = _({
|
|
753
753
|
data: t.data,
|
|
754
754
|
ec: t.level == "l" ? M.L : t.level == "m" ? M.M : t.level == "q" ? M.Q : M.H
|
|
755
|
-
}), a =
|
|
756
|
-
moduleSize:
|
|
755
|
+
}), a = n.width, r = t.cell, s = await nt(n, {
|
|
756
|
+
moduleSize: r,
|
|
757
757
|
margin: t.quietZone ? 4 : 0,
|
|
758
758
|
output: "path"
|
|
759
|
-
}), h = typeof
|
|
760
|
-
return this.svgContent += `<g transform="translate(${c},${
|
|
759
|
+
}), h = typeof s == "string" ? s : s.path || s.svg || String(s), o = a * r + (t.quietZone ? 8 : 0), c = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - o) * this.lineAlign / 2), d = Math.floor(this.svgHeight);
|
|
760
|
+
return this.svgContent += `<g transform="translate(${c},${d})" shape-rendering="crispEdges">
|
|
761
761
|
<path d="${h}" stroke="transparent" fill="black" shape-rendering="crispEdges" />
|
|
762
762
|
</g>`, this.svgHeight += o, "";
|
|
763
763
|
}
|
|
764
764
|
// print barcode:
|
|
765
765
|
async barcode(t, e) {
|
|
766
|
-
const
|
|
767
|
-
if (a !== void 0 && "length" in
|
|
768
|
-
const
|
|
766
|
+
const n = K(t), a = n.height;
|
|
767
|
+
if (a !== void 0 && "length" in n && n.length !== void 0 && n.widths) {
|
|
768
|
+
const r = n.length, s = a + (n.hri ? this.charWidth * 2 + 2 : 0);
|
|
769
769
|
let h = '<path d="';
|
|
770
|
-
if (
|
|
771
|
-
const c = Math.floor((
|
|
772
|
-
h += `<text y="${
|
|
770
|
+
if (n.widths.reduce((c, d, u) => (u % 2 === 1 && (h += `M${c},0h${d}v${a}h${-d}z`), c + d), 0), h += '" fill="#000"/>', n.hri && n.text) {
|
|
771
|
+
const c = Math.floor((r - (this.measureText(n.text, e) - 1) * this.charWidth) / 2), d = this.arrayFrom(n.text, e).reduce((u, l, g) => u + `<tspan x="${c + this.charWidth * g}">${l.replace(/[ &<>]/g, (p) => ({ " ": " ", "&": "&", "<": "<", ">": ">" })[p] || p)}</tspan>`, "");
|
|
772
|
+
h += `<text y="${s}">${d}</text>`;
|
|
773
773
|
}
|
|
774
|
-
const o = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth -
|
|
775
|
-
this.svgContent += `<g transform="translate(${o},${this.svgHeight})">${h}</g>`, this.svgHeight +=
|
|
774
|
+
const o = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - r) * this.lineAlign / 2);
|
|
775
|
+
this.svgContent += `<g transform="translate(${o},${this.svgHeight})">${h}</g>`, this.svgHeight += s;
|
|
776
776
|
}
|
|
777
777
|
return "";
|
|
778
778
|
}
|
|
@@ -967,163 +967,163 @@ const ft = /* @__PURE__ */ new Set([
|
|
|
967
967
|
dArr: "⇓",
|
|
968
968
|
hArr: "⇔"
|
|
969
969
|
}, T = {};
|
|
970
|
-
for (const [
|
|
971
|
-
T[t] || (T[t] =
|
|
972
|
-
function
|
|
973
|
-
if (!
|
|
974
|
-
return
|
|
975
|
-
let e =
|
|
970
|
+
for (const [i, t] of Object.entries($t))
|
|
971
|
+
T[t] || (T[t] = i);
|
|
972
|
+
function I(i, t = !1) {
|
|
973
|
+
if (!i || typeof i != "string")
|
|
974
|
+
return i;
|
|
975
|
+
let e = i;
|
|
976
976
|
return e = e.replace(/&/g, "&"), e = e.replace(/</g, "<"), e = e.replace(/>/g, ">"), t && (e = e.replace(/"/g, """)), e;
|
|
977
977
|
}
|
|
978
|
-
function mt(
|
|
979
|
-
return
|
|
978
|
+
function mt(i) {
|
|
979
|
+
return i.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
980
980
|
}
|
|
981
|
-
function yt(
|
|
982
|
-
return
|
|
981
|
+
function yt(i) {
|
|
982
|
+
return i.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
983
983
|
}
|
|
984
984
|
const vt = {
|
|
985
985
|
className: "class",
|
|
986
986
|
htmlFor: "for"
|
|
987
987
|
};
|
|
988
|
-
function bt(
|
|
989
|
-
return t === "reactName" ?
|
|
988
|
+
function bt(i, t) {
|
|
989
|
+
return t === "reactName" ? i : t === "exactName" || t === "eitherName" ? vt[i] ?? i : i;
|
|
990
990
|
}
|
|
991
|
-
function
|
|
991
|
+
function V(i, t = {}) {
|
|
992
992
|
const e = [];
|
|
993
|
-
let
|
|
994
|
-
if (
|
|
995
|
-
const
|
|
996
|
-
|
|
993
|
+
let n, a, r;
|
|
994
|
+
if (i && typeof i == "object" && "node" in i) {
|
|
995
|
+
const d = i;
|
|
996
|
+
n = d.node, a = d.xml ?? t.xml, r = d.doctype ?? t.doctype;
|
|
997
997
|
} else
|
|
998
|
-
|
|
998
|
+
n = i, a = t.xml, r = t.doctype;
|
|
999
999
|
a && (e.push(a), a.endsWith(`
|
|
1000
1000
|
`) || e.push(`
|
|
1001
|
-
`)),
|
|
1001
|
+
`)), r && (e.push(r), r.endsWith(`
|
|
1002
1002
|
`) || e.push(`
|
|
1003
1003
|
`));
|
|
1004
|
-
const
|
|
1005
|
-
return
|
|
1004
|
+
const s = t.useCDataForScripts ?? !1, h = t.useCDataForStyles ?? !1, o = t.voidTrailingSlash ?? !0, c = t.attributeNaming ?? "eitherName";
|
|
1005
|
+
return P(n, e, "HTML", s, h, o, c), e.join("");
|
|
1006
1006
|
}
|
|
1007
|
-
function
|
|
1008
|
-
if (
|
|
1009
|
-
if (typeof
|
|
1010
|
-
t.push(
|
|
1007
|
+
function P(i, t, e, n, a, r, s) {
|
|
1008
|
+
if (i != null) {
|
|
1009
|
+
if (typeof i == "string") {
|
|
1010
|
+
t.push(I(i, !1));
|
|
1011
1011
|
return;
|
|
1012
1012
|
}
|
|
1013
|
-
if (typeof
|
|
1014
|
-
t.push(String(
|
|
1013
|
+
if (typeof i == "number" || typeof i == "bigint") {
|
|
1014
|
+
t.push(String(i));
|
|
1015
1015
|
return;
|
|
1016
1016
|
}
|
|
1017
|
-
if (typeof
|
|
1018
|
-
t.push(String(
|
|
1017
|
+
if (typeof i == "boolean") {
|
|
1018
|
+
t.push(String(i));
|
|
1019
1019
|
return;
|
|
1020
1020
|
}
|
|
1021
|
-
if (Array.isArray(
|
|
1022
|
-
for (const h of
|
|
1023
|
-
|
|
1021
|
+
if (Array.isArray(i)) {
|
|
1022
|
+
for (const h of i)
|
|
1023
|
+
P(h, t, e, n, a, r, s);
|
|
1024
1024
|
return;
|
|
1025
1025
|
}
|
|
1026
|
-
if (typeof
|
|
1027
|
-
xt(
|
|
1026
|
+
if (typeof i != "function" && typeof i != "symbol" && !(i && typeof i == "object" && "then" in i && typeof i.then == "function") && i && typeof i == "object" && "type" in i && "props" in i) {
|
|
1027
|
+
xt(i, t, e, n, a, r, s);
|
|
1028
1028
|
return;
|
|
1029
1029
|
}
|
|
1030
1030
|
}
|
|
1031
1031
|
}
|
|
1032
|
-
function xt(
|
|
1032
|
+
function xt(i, t, e, n, a, r, s) {
|
|
1033
1033
|
var h;
|
|
1034
|
-
const o =
|
|
1034
|
+
const o = i.type;
|
|
1035
1035
|
let c = e;
|
|
1036
|
-
if (o === "svg" ? c = "SVG" : o === "math" && (c = "MATHML"), t.push("<"), t.push(o),
|
|
1037
|
-
for (const [
|
|
1038
|
-
if (
|
|
1036
|
+
if (o === "svg" ? c = "SVG" : o === "math" && (c = "MATHML"), t.push("<"), t.push(o), i.props)
|
|
1037
|
+
for (const [l, g] of Object.entries(i.props)) {
|
|
1038
|
+
if (l === "children" || g === !1 || g === null || g === void 0)
|
|
1039
1039
|
continue;
|
|
1040
|
-
const p = bt(
|
|
1040
|
+
const p = bt(l, s);
|
|
1041
1041
|
if (g === !0)
|
|
1042
1042
|
t.push(" "), t.push(p);
|
|
1043
|
-
else if (
|
|
1044
|
-
const f =
|
|
1045
|
-
f && (t.push(' style="'), t.push(
|
|
1043
|
+
else if (l === "style" && typeof g == "object") {
|
|
1044
|
+
const f = Wt(g);
|
|
1045
|
+
f && (t.push(' style="'), t.push(I(f, !0)), t.push('"'));
|
|
1046
1046
|
} else
|
|
1047
|
-
t.push(" "), t.push(p), t.push('="'), t.push(
|
|
1047
|
+
t.push(" "), t.push(p), t.push('="'), t.push(I(String(g), !0)), t.push('"');
|
|
1048
1048
|
}
|
|
1049
|
-
const
|
|
1049
|
+
const d = (h = i.props) == null ? void 0 : h.children;
|
|
1050
1050
|
let u;
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
1051
|
+
if (d && typeof d == "object" && "then" in d && typeof d.then == "function" ? u = !1 : u = d != null && (Array.isArray(d) && d.length > 0 || !Array.isArray(d) && d !== !1), ft.has(o))
|
|
1052
|
+
r ? t.push(" />") : t.push(">");
|
|
1053
1053
|
else if (u) {
|
|
1054
1054
|
t.push(">");
|
|
1055
|
-
const
|
|
1056
|
-
o === "script" &&
|
|
1055
|
+
const l = d;
|
|
1056
|
+
o === "script" && n || o === "style" && a ? (t.push("<![CDATA["), J(l, t, c, n, a, r, s), t.push("]]>")) : o === "script" || o === "style" ? Q(l, t) : P(l, t, c, n, a, r, s), t.push("</"), t.push(o), t.push(">");
|
|
1057
1057
|
} else wt.has(o), t.push("></"), t.push(o), t.push(">");
|
|
1058
1058
|
}
|
|
1059
|
-
function J(
|
|
1060
|
-
if (
|
|
1061
|
-
if (typeof
|
|
1062
|
-
t.push(mt(
|
|
1059
|
+
function J(i, t, e, n, a, r, s, h) {
|
|
1060
|
+
if (i != null) {
|
|
1061
|
+
if (typeof i == "string") {
|
|
1062
|
+
t.push(mt(i));
|
|
1063
1063
|
return;
|
|
1064
1064
|
}
|
|
1065
|
-
if (typeof
|
|
1066
|
-
t.push(String(
|
|
1065
|
+
if (typeof i == "number" || typeof i == "bigint" || typeof i == "boolean") {
|
|
1066
|
+
t.push(String(i));
|
|
1067
1067
|
return;
|
|
1068
1068
|
}
|
|
1069
|
-
if (Array.isArray(
|
|
1070
|
-
for (const o of
|
|
1071
|
-
J(o, t, e,
|
|
1069
|
+
if (Array.isArray(i)) {
|
|
1070
|
+
for (const o of i)
|
|
1071
|
+
J(o, t, e, n, a, r, s);
|
|
1072
1072
|
return;
|
|
1073
1073
|
}
|
|
1074
|
-
|
|
1074
|
+
P(i, t, e, n, a, r, s);
|
|
1075
1075
|
}
|
|
1076
1076
|
}
|
|
1077
|
-
function Q(
|
|
1078
|
-
if (
|
|
1079
|
-
if (typeof
|
|
1080
|
-
t.push(
|
|
1077
|
+
function Q(i, t) {
|
|
1078
|
+
if (i != null) {
|
|
1079
|
+
if (typeof i == "string") {
|
|
1080
|
+
t.push(i);
|
|
1081
1081
|
return;
|
|
1082
1082
|
}
|
|
1083
|
-
if (typeof
|
|
1084
|
-
t.push(String(
|
|
1083
|
+
if (typeof i == "number" || typeof i == "bigint" || typeof i == "boolean") {
|
|
1084
|
+
t.push(String(i));
|
|
1085
1085
|
return;
|
|
1086
1086
|
}
|
|
1087
|
-
if (Array.isArray(
|
|
1088
|
-
for (const e of
|
|
1087
|
+
if (Array.isArray(i)) {
|
|
1088
|
+
for (const e of i)
|
|
1089
1089
|
Q(e, t);
|
|
1090
1090
|
return;
|
|
1091
1091
|
}
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
-
function
|
|
1094
|
+
function Wt(i) {
|
|
1095
1095
|
const t = [];
|
|
1096
|
-
for (const [e,
|
|
1097
|
-
if (
|
|
1096
|
+
for (const [e, n] of Object.entries(i))
|
|
1097
|
+
if (n) {
|
|
1098
1098
|
const a = yt(e);
|
|
1099
|
-
t.push(`${a}: ${
|
|
1099
|
+
t.push(`${a}: ${n}`);
|
|
1100
1100
|
}
|
|
1101
1101
|
return t.join("; ");
|
|
1102
1102
|
}
|
|
1103
|
-
async function
|
|
1104
|
-
if (
|
|
1105
|
-
return
|
|
1106
|
-
if (
|
|
1107
|
-
const t = await
|
|
1108
|
-
return
|
|
1103
|
+
async function N(i) {
|
|
1104
|
+
if (i == null)
|
|
1105
|
+
return i;
|
|
1106
|
+
if (i && typeof i == "object" && "then" in i && typeof i.then == "function") {
|
|
1107
|
+
const t = await i;
|
|
1108
|
+
return N(t);
|
|
1109
1109
|
}
|
|
1110
|
-
if (typeof
|
|
1111
|
-
return
|
|
1112
|
-
if (typeof
|
|
1113
|
-
if (Array.isArray(
|
|
1110
|
+
if (typeof i == "string" || typeof i == "number" || typeof i == "boolean" || typeof i == "bigint")
|
|
1111
|
+
return i;
|
|
1112
|
+
if (typeof i != "function" && typeof i != "symbol") {
|
|
1113
|
+
if (Array.isArray(i))
|
|
1114
1114
|
return await Promise.all(
|
|
1115
|
-
|
|
1115
|
+
i.filter((t) => !(t == null || typeof t == "function" || typeof t == "symbol")).map((t) => N(t))
|
|
1116
1116
|
);
|
|
1117
|
-
if (
|
|
1118
|
-
const t =
|
|
1119
|
-
for (const [
|
|
1120
|
-
if (
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1117
|
+
if (i && typeof i == "object" && "type" in i && "props" in i) {
|
|
1118
|
+
const t = i, e = {};
|
|
1119
|
+
for (const [n, a] of Object.entries(t.props))
|
|
1120
|
+
if (n === "children") {
|
|
1121
|
+
const r = await N(a);
|
|
1122
|
+
r != null && (e.children = r);
|
|
1123
1123
|
} else {
|
|
1124
1124
|
if (typeof a == "function" || typeof a == "symbol")
|
|
1125
1125
|
continue;
|
|
1126
|
-
a != null && (e[
|
|
1126
|
+
a != null && (e[n] = a);
|
|
1127
1127
|
}
|
|
1128
1128
|
return {
|
|
1129
1129
|
type: t.type,
|
|
@@ -1132,74 +1132,74 @@ async function U(n) {
|
|
|
1132
1132
|
}
|
|
1133
1133
|
}
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1136
|
-
return
|
|
1135
|
+
function kt(i, t = {}) {
|
|
1136
|
+
return i && typeof i == "object" && "node" in i ? V(i, t) : i === void 0 ? "" : V(i, t);
|
|
1137
1137
|
}
|
|
1138
|
-
async function
|
|
1139
|
-
return await
|
|
1138
|
+
async function At(i) {
|
|
1139
|
+
return await N(i);
|
|
1140
1140
|
}
|
|
1141
|
-
function St(...
|
|
1141
|
+
function St(...i) {
|
|
1142
1142
|
const t = new Uint8Array(
|
|
1143
|
-
|
|
1143
|
+
i.reduceRight((n, a) => n + a.length, 0)
|
|
1144
1144
|
);
|
|
1145
1145
|
let e = 0;
|
|
1146
|
-
for (const
|
|
1147
|
-
t.set(
|
|
1146
|
+
for (const n of i)
|
|
1147
|
+
t.set(n, e), e += n.length;
|
|
1148
1148
|
return t;
|
|
1149
1149
|
}
|
|
1150
|
-
async function Mt(
|
|
1150
|
+
async function Mt(i) {
|
|
1151
1151
|
const t = new CompressionStream("deflate"), e = t.writable.getWriter();
|
|
1152
|
-
e.write(
|
|
1153
|
-
const
|
|
1154
|
-
let
|
|
1152
|
+
e.write(i), e.close();
|
|
1153
|
+
const n = t.readable.getReader(), a = [];
|
|
1154
|
+
let r = 0;
|
|
1155
1155
|
for (; ; ) {
|
|
1156
|
-
const { done: o, value: c } = await
|
|
1156
|
+
const { done: o, value: c } = await n.read();
|
|
1157
1157
|
if (o) break;
|
|
1158
|
-
a.push(c),
|
|
1158
|
+
a.push(c), r += c.length;
|
|
1159
1159
|
}
|
|
1160
|
-
const
|
|
1160
|
+
const s = new Uint8Array(r);
|
|
1161
1161
|
let h = 0;
|
|
1162
1162
|
for (const o of a)
|
|
1163
|
-
|
|
1164
|
-
return
|
|
1163
|
+
s.set(o, h), h += o.length;
|
|
1164
|
+
return s;
|
|
1165
1165
|
}
|
|
1166
1166
|
const X = new Uint32Array(256);
|
|
1167
|
-
for (let
|
|
1168
|
-
let t =
|
|
1167
|
+
for (let i = 0; i < 256; i++) {
|
|
1168
|
+
let t = i;
|
|
1169
1169
|
for (let e = 0; e < 8; e++)
|
|
1170
1170
|
t = t & 1 ? 3988292384 ^ t >>> 1 : t >>> 1;
|
|
1171
|
-
X[
|
|
1171
|
+
X[i] = t;
|
|
1172
1172
|
}
|
|
1173
|
-
function Ct(
|
|
1173
|
+
function Ct(i) {
|
|
1174
1174
|
let t = 4294967295;
|
|
1175
|
-
for (let e = 0; e <
|
|
1176
|
-
t = X[(t ^
|
|
1175
|
+
for (let e = 0; e < i.length; e++)
|
|
1176
|
+
t = X[(t ^ i[e]) & 255] ^ t >>> 8;
|
|
1177
1177
|
return (t ^ 4294967295) >>> 0;
|
|
1178
1178
|
}
|
|
1179
1179
|
const Ht = new TextEncoder();
|
|
1180
|
-
function
|
|
1181
|
-
const e = new Uint8Array(8 + t.length + 4),
|
|
1182
|
-
|
|
1180
|
+
function U(i, t) {
|
|
1181
|
+
const e = new Uint8Array(8 + t.length + 4), n = new DataView(e.buffer);
|
|
1182
|
+
n.setUint32(0, t.length), e.set(Ht.encode(i), 4), e.set(t, 8);
|
|
1183
1183
|
const a = Ct(e.subarray(4, e.length - 4));
|
|
1184
|
-
return
|
|
1184
|
+
return n.setUint32(e.length - 4, a), e;
|
|
1185
1185
|
}
|
|
1186
|
-
function qt(
|
|
1187
|
-
return
|
|
1186
|
+
function qt(i) {
|
|
1187
|
+
return i <= 1 ? 1 : i <= 3 ? 2 : i <= 15 ? 4 : 8;
|
|
1188
1188
|
}
|
|
1189
|
-
function
|
|
1190
|
-
const a = 8 /
|
|
1189
|
+
function Ut(i, t, e, n) {
|
|
1190
|
+
const a = 8 / n, r = Math.ceil(t / a) + 1, s = new Uint8Array(r * e), h = new DataView(s.buffer);
|
|
1191
1191
|
for (let o = 0; o < e; o++) {
|
|
1192
|
-
h.setUint8(o *
|
|
1192
|
+
h.setUint8(o * r, 0);
|
|
1193
1193
|
for (let c = 0; c < t; c++) {
|
|
1194
|
-
const
|
|
1195
|
-
h.setUint8(u, g |
|
|
1194
|
+
const d = i.getUint8(o * t + c), u = o * r + 1 + Math.floor(c / a), l = (a - 1 - c % a) * n, g = h.getUint8(u);
|
|
1195
|
+
h.setUint8(u, g | d << l);
|
|
1196
1196
|
}
|
|
1197
1197
|
}
|
|
1198
|
-
return
|
|
1198
|
+
return s;
|
|
1199
1199
|
}
|
|
1200
|
-
const
|
|
1201
|
-
function
|
|
1202
|
-
switch (
|
|
1200
|
+
const Nt = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), jt = new TextDecoder();
|
|
1201
|
+
function Et(i) {
|
|
1202
|
+
switch (i) {
|
|
1203
1203
|
case 0:
|
|
1204
1204
|
return "greyscale";
|
|
1205
1205
|
case 2:
|
|
@@ -1211,20 +1211,20 @@ function Pt(n) {
|
|
|
1211
1211
|
case 6:
|
|
1212
1212
|
return "truecolor-alpha";
|
|
1213
1213
|
default:
|
|
1214
|
-
throw new Error(`Invalid color type: ${
|
|
1214
|
+
throw new Error(`Invalid color type: ${i}`);
|
|
1215
1215
|
}
|
|
1216
1216
|
}
|
|
1217
|
-
function
|
|
1218
|
-
switch (
|
|
1217
|
+
function Pt(i) {
|
|
1218
|
+
switch (i) {
|
|
1219
1219
|
case 0:
|
|
1220
1220
|
return "none";
|
|
1221
1221
|
case 1:
|
|
1222
1222
|
return "adam7";
|
|
1223
1223
|
default:
|
|
1224
|
-
throw new Error(`Invalid interlace method: ${
|
|
1224
|
+
throw new Error(`Invalid interlace method: ${i}`);
|
|
1225
1225
|
}
|
|
1226
1226
|
}
|
|
1227
|
-
function Dt(
|
|
1227
|
+
function Dt(i, t) {
|
|
1228
1228
|
const e = {
|
|
1229
1229
|
0: [1, 2, 4, 8, 16],
|
|
1230
1230
|
// Greyscale
|
|
@@ -1239,138 +1239,138 @@ function Dt(n, t) {
|
|
|
1239
1239
|
}[t];
|
|
1240
1240
|
if (!e)
|
|
1241
1241
|
throw new Error(`Invalid color type: ${t}`);
|
|
1242
|
-
if (!e.includes(
|
|
1242
|
+
if (!e.includes(i))
|
|
1243
1243
|
throw new Error(
|
|
1244
|
-
`Invalid bit depth ${
|
|
1244
|
+
`Invalid bit depth ${i} for color type ${t}. Allowed: ${e.join(", ")}`
|
|
1245
1245
|
);
|
|
1246
1246
|
return !0;
|
|
1247
1247
|
}
|
|
1248
|
-
function zt(
|
|
1249
|
-
if (t + 12 >
|
|
1248
|
+
function zt(i, t) {
|
|
1249
|
+
if (t + 12 > i.byteLength)
|
|
1250
1250
|
throw new Error(
|
|
1251
1251
|
`Chunk at offset ${t} extends beyond data (need at least 12 bytes for header)`
|
|
1252
1252
|
);
|
|
1253
|
-
const e =
|
|
1254
|
-
if (t +
|
|
1253
|
+
const e = i.getUint32(t, !1), n = new Uint8Array(i.buffer, i.byteOffset + t + 4, 4), a = jt.decode(n), r = 8 + e + 4;
|
|
1254
|
+
if (t + r > i.byteLength)
|
|
1255
1255
|
throw new Error(
|
|
1256
|
-
`Chunk "${a}" at offset ${t} extends beyond data (chunk size: ${
|
|
1256
|
+
`Chunk "${a}" at offset ${t} extends beyond data (chunk size: ${r}, available: ${i.byteLength - t})`
|
|
1257
1257
|
);
|
|
1258
|
-
const
|
|
1258
|
+
const s = new DataView(i.buffer, i.byteOffset + t + 8, e);
|
|
1259
1259
|
return {
|
|
1260
1260
|
type: a,
|
|
1261
|
-
data:
|
|
1261
|
+
data: s,
|
|
1262
1262
|
offset: t,
|
|
1263
|
-
totalSize:
|
|
1263
|
+
totalSize: r
|
|
1264
1264
|
};
|
|
1265
1265
|
}
|
|
1266
|
-
function*
|
|
1266
|
+
function* Ft(i, t = 0) {
|
|
1267
1267
|
let e = t;
|
|
1268
|
-
for (; e <
|
|
1269
|
-
const
|
|
1270
|
-
yield
|
|
1268
|
+
for (; e < i.byteLength; ) {
|
|
1269
|
+
const n = zt(i, e);
|
|
1270
|
+
yield n, e += n.totalSize;
|
|
1271
1271
|
}
|
|
1272
1272
|
}
|
|
1273
|
-
function
|
|
1274
|
-
for (const a of
|
|
1273
|
+
function It(i, t, e, n = 0) {
|
|
1274
|
+
for (const a of Ft(i, n))
|
|
1275
1275
|
if (a.type === t)
|
|
1276
1276
|
return e(a.data);
|
|
1277
1277
|
}
|
|
1278
|
-
function Lt(
|
|
1279
|
-
if (
|
|
1280
|
-
throw new Error(`IHDR chunk must be 13 bytes, got ${
|
|
1281
|
-
const t =
|
|
1278
|
+
function Lt(i) {
|
|
1279
|
+
if (i.byteLength !== 13)
|
|
1280
|
+
throw new Error(`IHDR chunk must be 13 bytes, got ${i.byteLength}`);
|
|
1281
|
+
const t = i.getUint32(0, !1), e = i.getUint32(4, !1), n = i.getUint8(8), a = i.getUint8(9), r = i.getUint8(10), s = i.getUint8(11), h = i.getUint8(12);
|
|
1282
1282
|
if (t === 0)
|
|
1283
1283
|
throw new Error("IHDR width cannot be zero");
|
|
1284
1284
|
if (e === 0)
|
|
1285
1285
|
throw new Error("IHDR height cannot be zero");
|
|
1286
|
-
if (
|
|
1286
|
+
if (r !== 0)
|
|
1287
1287
|
throw new Error(
|
|
1288
|
-
`Invalid compression method: ${
|
|
1288
|
+
`Invalid compression method: ${r}. Only 0 (deflate) is supported.`
|
|
1289
1289
|
);
|
|
1290
|
-
if (
|
|
1290
|
+
if (s !== 0)
|
|
1291
1291
|
throw new Error(
|
|
1292
|
-
`Invalid filter method: ${
|
|
1292
|
+
`Invalid filter method: ${s}. Only 0 (adaptive) is supported.`
|
|
1293
1293
|
);
|
|
1294
|
-
Dt(
|
|
1295
|
-
const o =
|
|
1294
|
+
Dt(n, a);
|
|
1295
|
+
const o = Et(a), c = Pt(h);
|
|
1296
1296
|
return {
|
|
1297
1297
|
width: t,
|
|
1298
1298
|
height: e,
|
|
1299
|
-
bitDepth:
|
|
1299
|
+
bitDepth: n,
|
|
1300
1300
|
colorType: o,
|
|
1301
1301
|
compressionMethod: "deflate",
|
|
1302
1302
|
filterMethod: "adaptive",
|
|
1303
1303
|
interlaceMethod: c
|
|
1304
1304
|
};
|
|
1305
1305
|
}
|
|
1306
|
-
function Bt(
|
|
1307
|
-
if (
|
|
1306
|
+
function Bt(i) {
|
|
1307
|
+
if (i.byteLength < 8)
|
|
1308
1308
|
throw new Error("Data too short to contain PNG signature");
|
|
1309
1309
|
for (let t = 0; t < 8; t++)
|
|
1310
|
-
if (
|
|
1310
|
+
if (i.getUint8(t) !== Nt[t])
|
|
1311
1311
|
throw new Error("Invalid PNG signature");
|
|
1312
1312
|
return !0;
|
|
1313
1313
|
}
|
|
1314
|
-
function Tt(
|
|
1315
|
-
const t =
|
|
1314
|
+
function Tt(i) {
|
|
1315
|
+
const t = i instanceof Uint8Array ? i.buffer : i, e = i instanceof Uint8Array ? i.byteOffset : 0, n = i.byteLength, a = new DataView(t, e, n);
|
|
1316
1316
|
Bt(a);
|
|
1317
|
-
const
|
|
1318
|
-
if (
|
|
1317
|
+
const r = It(a, "IHDR", Lt, 8);
|
|
1318
|
+
if (r === void 0)
|
|
1319
1319
|
throw new Error("IHDR chunk not found in PNG");
|
|
1320
|
-
return
|
|
1320
|
+
return r;
|
|
1321
1321
|
}
|
|
1322
|
-
async function
|
|
1323
|
-
const a = new DataView(
|
|
1324
|
-
if (
|
|
1322
|
+
async function Vt(i, t, e, n) {
|
|
1323
|
+
const a = new DataView(i.buffer), r = a.byteLength;
|
|
1324
|
+
if (r === 0)
|
|
1325
1325
|
throw new Error("Received empty input");
|
|
1326
|
-
if (
|
|
1326
|
+
if (r !== t * e)
|
|
1327
1327
|
throw new Error(
|
|
1328
|
-
`Input does not match dimensions ${t}x${e}. Only ${
|
|
1328
|
+
`Input does not match dimensions ${t}x${e}. Only ${r} bytes were given when ${t * e} are expected!`
|
|
1329
1329
|
);
|
|
1330
|
-
let
|
|
1331
|
-
for (let w = 0; w <
|
|
1330
|
+
let s = 0;
|
|
1331
|
+
for (let w = 0; w < r; w++) {
|
|
1332
1332
|
const m = a.getUint8(w);
|
|
1333
|
-
m >
|
|
1333
|
+
m > s && (s = m);
|
|
1334
1334
|
}
|
|
1335
|
-
if (
|
|
1335
|
+
if (n.length <= s)
|
|
1336
1336
|
throw new Error(
|
|
1337
|
-
`Color palette does not have enough colors (${
|
|
1337
|
+
`Color palette does not have enough colors (${s + 1}). Only ${n.length} were given!`
|
|
1338
1338
|
);
|
|
1339
|
-
const h = qt(
|
|
1340
|
-
|
|
1341
|
-
const u =
|
|
1342
|
-
for (let w = 0; w <=
|
|
1343
|
-
g.setUint8(w * 3,
|
|
1344
|
-
const p =
|
|
1345
|
-
return St(o, u, p, $,
|
|
1339
|
+
const h = qt(s), o = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), c = new Uint8Array(13), d = new DataView(c.buffer);
|
|
1340
|
+
d.setUint32(0, t), d.setUint32(4, e), d.setUint8(8, h), d.setUint8(9, 3), d.setUint8(10, 0), d.setUint8(11, 0), d.setUint8(12, 0);
|
|
1341
|
+
const u = U("IHDR", c), l = new Uint8Array(n.length * 3), g = new DataView(l.buffer);
|
|
1342
|
+
for (let w = 0; w <= s; w++)
|
|
1343
|
+
g.setUint8(w * 3, n[w][0]), g.setUint8(w * 3 + 1, n[w][1]), g.setUint8(w * 3 + 2, n[w][2]);
|
|
1344
|
+
const p = U("PLTE", l), f = Ut(a, t, e, h), $ = U("IDAT", await Mt(f)), x = U("IEND", new Uint8Array(0));
|
|
1345
|
+
return St(o, u, p, $, x);
|
|
1346
1346
|
}
|
|
1347
|
-
async function
|
|
1347
|
+
async function Rt(i, t = {}) {
|
|
1348
1348
|
var e;
|
|
1349
1349
|
const {
|
|
1350
|
-
margin:
|
|
1350
|
+
margin: n = 4,
|
|
1351
1351
|
moduleSize: a = 4,
|
|
1352
|
-
backgroundColor:
|
|
1353
|
-
foregroundColor:
|
|
1354
|
-
} = t, { matrix: h } =
|
|
1355
|
-
|
|
1352
|
+
backgroundColor: r = [255, 255, 255],
|
|
1353
|
+
foregroundColor: s = [0, 0, 0]
|
|
1354
|
+
} = t, { matrix: h } = i, o = ((e = h[0]) == null ? void 0 : e.length) ?? 0, c = h.length, d = (o + n * 2) * a, u = (c + n * 2) * a, l = new Uint8Array(d * u);
|
|
1355
|
+
l.fill(0);
|
|
1356
1356
|
for (let g = 0; g < c; g++)
|
|
1357
1357
|
for (let p = 0; p < o; p++)
|
|
1358
1358
|
if (h[g][p])
|
|
1359
1359
|
for (let f = 0; f < a; f++)
|
|
1360
1360
|
for (let $ = 0; $ < a; $++) {
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1361
|
+
const x = (p + n) * a + $, w = (g + n) * a + f;
|
|
1362
|
+
l[w * d + x] = 1;
|
|
1363
1363
|
}
|
|
1364
1364
|
return {
|
|
1365
|
-
bytes: await
|
|
1366
|
-
width:
|
|
1365
|
+
bytes: await Vt(l, d, u, [r, s]),
|
|
1366
|
+
width: d,
|
|
1367
1367
|
height: u
|
|
1368
1368
|
};
|
|
1369
1369
|
}
|
|
1370
|
-
function
|
|
1370
|
+
function Zt(i) {
|
|
1371
1371
|
const t = {};
|
|
1372
|
-
for (const [e,
|
|
1373
|
-
|
|
1372
|
+
for (const [e, n] of Object.entries(i))
|
|
1373
|
+
n !== void 0 && (t[e] = n);
|
|
1374
1374
|
return t;
|
|
1375
1375
|
}
|
|
1376
1376
|
class Y extends H {
|
|
@@ -1389,6 +1389,7 @@ class Y extends H {
|
|
|
1389
1389
|
defaultFont = "'Courier Prime', monospace";
|
|
1390
1390
|
actualFontCharacterWidth = void 0;
|
|
1391
1391
|
explicitCharHeight = void 0;
|
|
1392
|
+
widthSpacingUnit = "px";
|
|
1392
1393
|
// DOM building state
|
|
1393
1394
|
contentNodes = [];
|
|
1394
1395
|
currentStyles = {};
|
|
@@ -1413,6 +1414,25 @@ class Y extends H {
|
|
|
1413
1414
|
setCharHeight(t) {
|
|
1414
1415
|
this.explicitCharHeight = t;
|
|
1415
1416
|
}
|
|
1417
|
+
setWidthSpacingUnit(t) {
|
|
1418
|
+
this.widthSpacingUnit = t;
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Converts a character width to the appropriate CSS unit based on widthSpacingUnit.
|
|
1422
|
+
* @param chars - Width in characters
|
|
1423
|
+
* @returns CSS value string (e.g., "12px", "50%", "12ch")
|
|
1424
|
+
*/
|
|
1425
|
+
toWidthUnit(t) {
|
|
1426
|
+
const e = this.actualFontCharacterWidth ?? this.charWidth;
|
|
1427
|
+
switch (this.widthSpacingUnit) {
|
|
1428
|
+
case "px":
|
|
1429
|
+
return `${Math.floor(t * e)}px`;
|
|
1430
|
+
case "%":
|
|
1431
|
+
return `${t * e / this.containerWidth * 100}%`;
|
|
1432
|
+
default:
|
|
1433
|
+
return `${t}ch`;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1416
1436
|
// finish printing (async to support Promise nodes like QR code PNGs):
|
|
1417
1437
|
async close() {
|
|
1418
1438
|
(this.lineSegments.length > 0 || this.pendingVrSvg) && await this.lf();
|
|
@@ -1456,14 +1476,14 @@ class Y extends H {
|
|
|
1456
1476
|
children: this.contentNodes
|
|
1457
1477
|
};
|
|
1458
1478
|
e && (a.lang = e);
|
|
1459
|
-
const
|
|
1479
|
+
const s = await At({
|
|
1460
1480
|
type: "div",
|
|
1461
1481
|
props: a
|
|
1462
1482
|
});
|
|
1463
|
-
return
|
|
1483
|
+
return kt(s);
|
|
1464
1484
|
}
|
|
1465
1485
|
// set print area:
|
|
1466
|
-
async area(t, e,
|
|
1486
|
+
async area(t, e, n) {
|
|
1467
1487
|
return this.lineMargin = t, this.lineWidth = e, "";
|
|
1468
1488
|
}
|
|
1469
1489
|
// set line alignment:
|
|
@@ -1485,10 +1505,10 @@ class Y extends H {
|
|
|
1485
1505
|
props: {
|
|
1486
1506
|
style: {
|
|
1487
1507
|
borderTop: "2px solid black",
|
|
1488
|
-
marginLeft:
|
|
1489
|
-
width:
|
|
1508
|
+
marginLeft: this.toWidthUnit(this.lineMargin),
|
|
1509
|
+
width: this.toWidthUnit(t),
|
|
1490
1510
|
height: "0",
|
|
1491
|
-
display: "
|
|
1511
|
+
display: "flex"
|
|
1492
1512
|
}
|
|
1493
1513
|
}
|
|
1494
1514
|
};
|
|
@@ -1496,21 +1516,21 @@ class Y extends H {
|
|
|
1496
1516
|
}
|
|
1497
1517
|
// print vertical rules:
|
|
1498
1518
|
async vr(t, e) {
|
|
1499
|
-
const
|
|
1500
|
-
let h = `M${a},0v${
|
|
1501
|
-
for (const
|
|
1502
|
-
h += `m${
|
|
1503
|
-
const o =
|
|
1519
|
+
const n = this.charWidth, a = n / 2, r = this.charHeight * e, s = t.reduce((d, u) => d + u, 0) + t.length + 1;
|
|
1520
|
+
let h = `M${a},0v${r}`;
|
|
1521
|
+
for (const d of t)
|
|
1522
|
+
h += `m${d * n + n},${-r}v${r}`;
|
|
1523
|
+
const o = s * n, c = {
|
|
1504
1524
|
type: "svg",
|
|
1505
1525
|
props: {
|
|
1506
|
-
width:
|
|
1507
|
-
height: `${
|
|
1508
|
-
viewBox: `0 0 ${o} ${
|
|
1526
|
+
width: this.toWidthUnit(s),
|
|
1527
|
+
height: `${r}`,
|
|
1528
|
+
viewBox: `0 0 ${o} ${r}`,
|
|
1509
1529
|
preserveAspectRatio: "none",
|
|
1510
1530
|
style: {
|
|
1511
1531
|
position: "absolute",
|
|
1512
1532
|
top: "0",
|
|
1513
|
-
left:
|
|
1533
|
+
left: this.toWidthUnit(this.lineMargin)
|
|
1514
1534
|
},
|
|
1515
1535
|
children: {
|
|
1516
1536
|
type: "path",
|
|
@@ -1528,21 +1548,21 @@ class Y extends H {
|
|
|
1528
1548
|
}
|
|
1529
1549
|
// start rules:
|
|
1530
1550
|
async vrstart(t) {
|
|
1531
|
-
const e = this.charWidth,
|
|
1551
|
+
const e = this.charWidth, n = t.reduce((o, c) => o + c, 0) + t.length + 1, a = n * e, r = e * 2, s = this.buildVrStartPath(t), h = {
|
|
1532
1552
|
type: "svg",
|
|
1533
1553
|
props: {
|
|
1534
|
-
width:
|
|
1535
|
-
height: `${
|
|
1536
|
-
viewBox: `0 0 ${a} ${
|
|
1554
|
+
width: this.toWidthUnit(n),
|
|
1555
|
+
height: `${r}`,
|
|
1556
|
+
viewBox: `0 0 ${a} ${r}`,
|
|
1537
1557
|
preserveAspectRatio: "none",
|
|
1538
1558
|
style: {
|
|
1539
|
-
display: "
|
|
1540
|
-
marginLeft:
|
|
1559
|
+
display: "flex",
|
|
1560
|
+
marginLeft: this.toWidthUnit(this.lineMargin)
|
|
1541
1561
|
},
|
|
1542
1562
|
children: {
|
|
1543
1563
|
type: "path",
|
|
1544
1564
|
props: {
|
|
1545
|
-
d:
|
|
1565
|
+
d: s,
|
|
1546
1566
|
fill: "none",
|
|
1547
1567
|
stroke: "black",
|
|
1548
1568
|
"stroke-width": "2",
|
|
@@ -1554,31 +1574,30 @@ class Y extends H {
|
|
|
1554
1574
|
return this.contentNodes.push(h), "";
|
|
1555
1575
|
}
|
|
1556
1576
|
buildVrStartPath(t) {
|
|
1557
|
-
const e = this.charWidth,
|
|
1558
|
-
let a = `M${
|
|
1559
|
-
for (let
|
|
1560
|
-
const
|
|
1561
|
-
a += `h${e *
|
|
1577
|
+
const e = this.charWidth, n = e / 2;
|
|
1578
|
+
let a = `M${n},${e + e}v${-n}q0,${-n},${n},${-n}`;
|
|
1579
|
+
for (let r = 0; r < t.length; r++) {
|
|
1580
|
+
const s = t[r] ?? 0;
|
|
1581
|
+
a += `h${e * s}h${n}v${e}m0,${-e}h${n}`;
|
|
1562
1582
|
}
|
|
1563
|
-
return a = a.replace(/h\d+v\d+m0,-\d+h\d+$/, `q${
|
|
1583
|
+
return a = a.replace(/h\d+v\d+m0,-\d+h\d+$/, `q${n},0,${n},${n}v${n}`), a;
|
|
1564
1584
|
}
|
|
1565
1585
|
// stop rules:
|
|
1566
1586
|
async vrstop(t) {
|
|
1567
|
-
const e = this.charWidth,
|
|
1587
|
+
const e = this.charWidth, n = t.reduce((o, c) => o + c, 0) + t.length + 1, a = n * e, r = e * 2, s = this.buildVrStopPath(t), h = {
|
|
1568
1588
|
type: "svg",
|
|
1569
1589
|
props: {
|
|
1570
|
-
width:
|
|
1571
|
-
height: `${
|
|
1572
|
-
viewBox: `0 0 ${a} ${
|
|
1590
|
+
width: this.toWidthUnit(n),
|
|
1591
|
+
height: `${r}`,
|
|
1592
|
+
viewBox: `0 0 ${a} ${r}`,
|
|
1573
1593
|
preserveAspectRatio: "none",
|
|
1574
1594
|
style: {
|
|
1575
|
-
|
|
1576
|
-
marginLeft: `${this.lineMargin}ch`
|
|
1595
|
+
marginLeft: this.toWidthUnit(this.lineMargin)
|
|
1577
1596
|
},
|
|
1578
1597
|
children: {
|
|
1579
1598
|
type: "path",
|
|
1580
1599
|
props: {
|
|
1581
|
-
d:
|
|
1600
|
+
d: s,
|
|
1582
1601
|
fill: "none",
|
|
1583
1602
|
stroke: "black",
|
|
1584
1603
|
"stroke-width": "2",
|
|
@@ -1590,38 +1609,37 @@ class Y extends H {
|
|
|
1590
1609
|
return this.contentNodes.push(h), "";
|
|
1591
1610
|
}
|
|
1592
1611
|
buildVrStopPath(t) {
|
|
1593
|
-
const e = this.charWidth,
|
|
1594
|
-
let a = `M${
|
|
1595
|
-
for (let
|
|
1596
|
-
const
|
|
1597
|
-
a += `h${e *
|
|
1612
|
+
const e = this.charWidth, n = e / 2;
|
|
1613
|
+
let a = `M${n},0v${n}q0,${n},${n},${n}`;
|
|
1614
|
+
for (let r = 0; r < t.length; r++) {
|
|
1615
|
+
const s = t[r] ?? 0;
|
|
1616
|
+
a += `h${e * s}h${n}v${-e}m0,${e}h${n}`;
|
|
1598
1617
|
}
|
|
1599
|
-
return a = a.replace(/h\d+v-\d+m0,\d+h\d+$/, `q${
|
|
1618
|
+
return a = a.replace(/h\d+v-\d+m0,\d+h\d+$/, `q${n},0,${n},${-n}v${-n}`), a;
|
|
1600
1619
|
}
|
|
1601
1620
|
// print vertical and horizontal rules:
|
|
1602
|
-
async vrhr(t, e,
|
|
1603
|
-
const
|
|
1604
|
-
let
|
|
1621
|
+
async vrhr(t, e, n, a) {
|
|
1622
|
+
const r = this.charWidth, s = r / 2, h = t.reduce((f, $) => f + $, 0) + t.length + 1, o = e.reduce((f, $) => f + $, 0) + e.length + 1, c = Math.max(h, o), d = c * r, u = r * 2;
|
|
1623
|
+
let l = `M${s},0` + (n > 0 ? `v${s}q0,${s},${s},${s}` : `v${r}h${s}`);
|
|
1605
1624
|
for (const f of t)
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
let g = `M${
|
|
1625
|
+
l += `h${r * f}h${s}v${-r}m0,${r}h${s}`;
|
|
1626
|
+
l = l.replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${s},0,${s},${-s}v${-s}` : `h${s}v${-r}`);
|
|
1627
|
+
let g = `M${s},${r + r}` + (n < 0 ? `v${-s}q0,${-s},${s},${-s}` : `v${-r}h${s}`);
|
|
1609
1628
|
for (const f of e)
|
|
1610
|
-
g += `h${
|
|
1611
|
-
g = g.replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${
|
|
1629
|
+
g += `h${r * f}h${s}v${r}m0,${-r}h${s}`;
|
|
1630
|
+
g = g.replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${s},0,${s},${s}v${s}` : `h${s}v${r}`);
|
|
1612
1631
|
const p = {
|
|
1613
1632
|
type: "svg",
|
|
1614
1633
|
props: {
|
|
1615
|
-
width:
|
|
1634
|
+
width: this.toWidthUnit(c),
|
|
1616
1635
|
height: `${u}`,
|
|
1617
|
-
viewBox: `0 0 ${
|
|
1636
|
+
viewBox: `0 0 ${d} ${u}`,
|
|
1618
1637
|
preserveAspectRatio: "none",
|
|
1619
1638
|
style: {
|
|
1620
|
-
|
|
1621
|
-
marginLeft: `${this.lineMargin + Math.max(-i, 0)}ch`
|
|
1639
|
+
marginLeft: this.toWidthUnit(this.lineMargin + Math.max(-n, 0))
|
|
1622
1640
|
},
|
|
1623
1641
|
children: [
|
|
1624
|
-
{ type: "path", props: { d, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } },
|
|
1642
|
+
{ type: "path", props: { d: l, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } },
|
|
1625
1643
|
{ type: "path", props: { d: g, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } }
|
|
1626
1644
|
]
|
|
1627
1645
|
}
|
|
@@ -1664,7 +1682,7 @@ class Y extends H {
|
|
|
1664
1682
|
style: {
|
|
1665
1683
|
flex: "1",
|
|
1666
1684
|
borderTop: "2px dashed black",
|
|
1667
|
-
display: "
|
|
1685
|
+
display: "flex"
|
|
1668
1686
|
}
|
|
1669
1687
|
}
|
|
1670
1688
|
}
|
|
@@ -1687,8 +1705,8 @@ class Y extends H {
|
|
|
1687
1705
|
}
|
|
1688
1706
|
// scale up text:
|
|
1689
1707
|
async wh(t) {
|
|
1690
|
-
const e = t < 2 ? t + 1 : t - 1,
|
|
1691
|
-
return this.currentStyles.fontSize = `${
|
|
1708
|
+
const e = t < 2 ? t + 1 : t - 1, n = t < 3 ? t : t - 1;
|
|
1709
|
+
return this.currentStyles.fontSize = `${n}em`, this.currentStyles.display = "flex", e !== n && (this.currentStyles.transform = `scaleX(${e / n})`, this.currentStyles.transformOrigin = "left"), this.lineHeight = Math.max(this.lineHeight, n), this.textScale = e, "";
|
|
1692
1710
|
}
|
|
1693
1711
|
// cancel text decoration:
|
|
1694
1712
|
async normal() {
|
|
@@ -1696,61 +1714,70 @@ class Y extends H {
|
|
|
1696
1714
|
}
|
|
1697
1715
|
// print text:
|
|
1698
1716
|
async text(t, e) {
|
|
1699
|
-
const
|
|
1717
|
+
const n = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " "), a = this.measureText(t, e), r = {
|
|
1700
1718
|
position: this.currentPosition,
|
|
1701
|
-
text:
|
|
1719
|
+
text: n,
|
|
1702
1720
|
styles: { ...this.currentStyles },
|
|
1703
1721
|
scale: this.textScale,
|
|
1704
1722
|
charWidth: a
|
|
1705
1723
|
};
|
|
1706
|
-
return this.lineSegments.push(
|
|
1724
|
+
return this.lineSegments.push(r), this.currentPosition += a * this.textScale, "";
|
|
1707
1725
|
}
|
|
1708
1726
|
// feed new line:
|
|
1709
1727
|
async lf() {
|
|
1710
|
-
const t = this.lineHeight * this.charHeight, e = Math.max(t, this.feedMinimum),
|
|
1728
|
+
const t = this.lineHeight * this.charHeight, e = Math.max(t, this.feedMinimum), n = this.lineMargin + this.lineWidth, a = [];
|
|
1711
1729
|
if (this.lineSegments.length === 0) {
|
|
1712
1730
|
if (this.pendingVrSvg) {
|
|
1713
|
-
const
|
|
1731
|
+
const s = {
|
|
1714
1732
|
type: "div",
|
|
1715
1733
|
props: {
|
|
1716
1734
|
style: {
|
|
1717
1735
|
position: "relative",
|
|
1718
1736
|
width: `${this.containerWidth}px`,
|
|
1719
1737
|
height: `${e}px`,
|
|
1720
|
-
display: "
|
|
1738
|
+
display: "flex"
|
|
1721
1739
|
},
|
|
1722
1740
|
children: this.pendingVrSvg
|
|
1723
1741
|
}
|
|
1724
1742
|
};
|
|
1725
|
-
this.contentNodes.push(
|
|
1743
|
+
this.contentNodes.push(s), this.pendingVrSvg = null, this.estimatedHeight += e;
|
|
1726
1744
|
}
|
|
1727
1745
|
return this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
|
|
1728
1746
|
} else {
|
|
1729
|
-
const
|
|
1747
|
+
const s = [...this.lineSegments].sort((u, l) => u.position - l.position);
|
|
1730
1748
|
let h = 0;
|
|
1731
|
-
const o = (u) => Math.floor(u), c = (u) =>
|
|
1732
|
-
const
|
|
1733
|
-
return
|
|
1749
|
+
const o = (u) => Math.floor(u), c = (u) => {
|
|
1750
|
+
const l = o(u);
|
|
1751
|
+
return this.toWidthUnit(l);
|
|
1752
|
+
}, d = (u) => {
|
|
1753
|
+
const l = this.actualFontCharacterWidth ?? this.charWidth, g = u.match(/^(\d+(?:\.\d+)?)px$/);
|
|
1754
|
+
if (g)
|
|
1755
|
+
return parseFloat(g[1]) / l;
|
|
1756
|
+
const p = u.match(/^(\d+(?:\.\d+)?)%$/);
|
|
1757
|
+
if (p)
|
|
1758
|
+
return parseFloat(p[1]) / 100 * this.containerWidth / l;
|
|
1759
|
+
const f = u.match(/^(\d+(?:\.\d+)?)ch$/);
|
|
1760
|
+
return f ? parseFloat(f[1]) : 0;
|
|
1734
1761
|
};
|
|
1735
|
-
for (let u = 0; u <
|
|
1736
|
-
const
|
|
1762
|
+
for (let u = 0; u < s.length; u++) {
|
|
1763
|
+
const l = s[u], g = this.lineMargin + l.position, p = l.charWidth * l.scale;
|
|
1737
1764
|
if (g > h && a.length > 0) {
|
|
1738
|
-
const
|
|
1765
|
+
const k = g - h, v = a[a.length - 1];
|
|
1739
1766
|
if (v && v.props && v.props.style && typeof v.props.style == "object" && !Array.isArray(v.props.style)) {
|
|
1740
|
-
const
|
|
1741
|
-
if (
|
|
1742
|
-
const D =
|
|
1743
|
-
|
|
1767
|
+
const A = v.props.style, W = A.flexBasis;
|
|
1768
|
+
if (W) {
|
|
1769
|
+
const D = d(W) + k;
|
|
1770
|
+
A.flexBasis = c(D);
|
|
1744
1771
|
} else
|
|
1745
|
-
|
|
1772
|
+
A.flexBasis = c(k);
|
|
1746
1773
|
}
|
|
1747
1774
|
} else if (g > h && a.length === 0) {
|
|
1748
|
-
const
|
|
1775
|
+
const k = g - h;
|
|
1749
1776
|
a.push({
|
|
1750
1777
|
type: "span",
|
|
1751
1778
|
props: {
|
|
1752
1779
|
style: {
|
|
1753
|
-
flexBasis: c(
|
|
1780
|
+
flexBasis: c(k)
|
|
1754
1781
|
}
|
|
1755
1782
|
}
|
|
1756
1783
|
});
|
|
@@ -1758,66 +1785,66 @@ class Y extends H {
|
|
|
1758
1785
|
const $ = {
|
|
1759
1786
|
flexBasis: c(p),
|
|
1760
1787
|
whiteSpace: "pre"
|
|
1761
|
-
},
|
|
1788
|
+
}, x = l.styles && Object.keys(l.styles).length > 0, w = x ? l.styles : void 0, m = {
|
|
1762
1789
|
type: "span",
|
|
1763
1790
|
props: {
|
|
1764
1791
|
style: $,
|
|
1765
|
-
children:
|
|
1792
|
+
children: x ? {
|
|
1766
1793
|
// Wrap text in inner span with content styles
|
|
1767
1794
|
type: "span",
|
|
1768
1795
|
props: {
|
|
1769
1796
|
style: w,
|
|
1770
|
-
children:
|
|
1797
|
+
children: l.text
|
|
1771
1798
|
}
|
|
1772
|
-
} :
|
|
1799
|
+
} : l.text
|
|
1773
1800
|
}
|
|
1774
1801
|
};
|
|
1775
1802
|
a.push(m), h = g + p;
|
|
1776
1803
|
}
|
|
1777
|
-
if (h <
|
|
1778
|
-
const u =
|
|
1779
|
-
if (
|
|
1780
|
-
const g =
|
|
1804
|
+
if (h < n && a.length > 0) {
|
|
1805
|
+
const u = n - h, l = a[a.length - 1];
|
|
1806
|
+
if (l && l.props && l.props.style && typeof l.props.style == "object" && !Array.isArray(l.props.style)) {
|
|
1807
|
+
const g = l.props.style, p = g.flexBasis;
|
|
1781
1808
|
if (p) {
|
|
1782
|
-
const $ =
|
|
1809
|
+
const $ = d(p) + u;
|
|
1783
1810
|
g.flexBasis = c($);
|
|
1784
1811
|
} else
|
|
1785
1812
|
g.flexBasis = c(u);
|
|
1786
1813
|
}
|
|
1787
1814
|
}
|
|
1788
1815
|
}
|
|
1789
|
-
const
|
|
1816
|
+
const r = {
|
|
1790
1817
|
type: "div",
|
|
1791
1818
|
props: {
|
|
1792
1819
|
style: {
|
|
1793
1820
|
display: "flex",
|
|
1794
1821
|
flexDirection: "row",
|
|
1795
1822
|
height: `${e}px`,
|
|
1796
|
-
width:
|
|
1823
|
+
width: this.toWidthUnit(n)
|
|
1797
1824
|
},
|
|
1798
1825
|
children: a
|
|
1799
1826
|
}
|
|
1800
1827
|
};
|
|
1801
1828
|
if (this.pendingVrSvg) {
|
|
1802
|
-
const
|
|
1829
|
+
const s = {
|
|
1803
1830
|
type: "div",
|
|
1804
1831
|
props: {
|
|
1805
1832
|
style: {
|
|
1806
1833
|
position: "relative",
|
|
1807
1834
|
width: `${this.containerWidth}px`,
|
|
1808
1835
|
minHeight: `${e}px`,
|
|
1809
|
-
display: "
|
|
1836
|
+
display: "flex"
|
|
1810
1837
|
},
|
|
1811
1838
|
children: [
|
|
1812
1839
|
// VR SVG positioned absolutely behind text
|
|
1813
1840
|
this.pendingVrSvg,
|
|
1814
1841
|
// Text line positioned relatively on top
|
|
1815
1842
|
{
|
|
1816
|
-
...
|
|
1843
|
+
...r,
|
|
1817
1844
|
props: {
|
|
1818
|
-
...
|
|
1845
|
+
...r.props,
|
|
1819
1846
|
style: {
|
|
1820
|
-
...
|
|
1847
|
+
...r.props?.style,
|
|
1821
1848
|
position: "relative"
|
|
1822
1849
|
}
|
|
1823
1850
|
}
|
|
@@ -1825,9 +1852,9 @@ class Y extends H {
|
|
|
1825
1852
|
]
|
|
1826
1853
|
}
|
|
1827
1854
|
};
|
|
1828
|
-
this.contentNodes.push(
|
|
1855
|
+
this.contentNodes.push(s), this.pendingVrSvg = null;
|
|
1829
1856
|
} else
|
|
1830
|
-
this.contentNodes.push(
|
|
1857
|
+
this.contentNodes.push(r);
|
|
1831
1858
|
return this.estimatedHeight += e, this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
|
|
1832
1859
|
}
|
|
1833
1860
|
// insert commands:
|
|
@@ -1836,24 +1863,24 @@ class Y extends H {
|
|
|
1836
1863
|
}
|
|
1837
1864
|
// print image:
|
|
1838
1865
|
async image(t) {
|
|
1839
|
-
const e = this.lineAlign === 0 ? "
|
|
1866
|
+
const e = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", n = Z(t), a = Tt(n), r = a.width, s = a.height, h = {
|
|
1840
1867
|
type: "img",
|
|
1841
1868
|
props: {
|
|
1842
1869
|
src: `data:image/png;base64,${t}`,
|
|
1843
|
-
style:
|
|
1844
|
-
maxWidth:
|
|
1870
|
+
style: Zt({
|
|
1871
|
+
maxWidth: this.toWidthUnit(this.lineWidth)
|
|
1845
1872
|
}),
|
|
1846
|
-
width: `${
|
|
1847
|
-
height: `${
|
|
1873
|
+
width: `${r}`,
|
|
1874
|
+
height: `${s}`
|
|
1848
1875
|
}
|
|
1849
1876
|
}, o = {
|
|
1850
1877
|
type: "div",
|
|
1851
1878
|
props: {
|
|
1852
1879
|
style: {
|
|
1853
|
-
|
|
1854
|
-
paddingLeft:
|
|
1855
|
-
width:
|
|
1856
|
-
display: "
|
|
1880
|
+
justifyContent: e,
|
|
1881
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1882
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1883
|
+
display: "flex"
|
|
1857
1884
|
},
|
|
1858
1885
|
children: h
|
|
1859
1886
|
}
|
|
@@ -1862,88 +1889,85 @@ class Y extends H {
|
|
|
1862
1889
|
}
|
|
1863
1890
|
// print QR Code (async version using PNG):
|
|
1864
1891
|
async qrcode(t, e) {
|
|
1865
|
-
const
|
|
1892
|
+
const n = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", a = _({
|
|
1866
1893
|
data: t.data,
|
|
1867
1894
|
ec: t.level === "l" ? M.L : t.level === "m" ? M.M : t.level === "q" ? M.Q : M.H
|
|
1868
|
-
}),
|
|
1869
|
-
moduleSize:
|
|
1895
|
+
}), r = t.cell, s = t.quietZone ? 4 : 0, { bytes: h, width: o, height: c } = await Rt(a, {
|
|
1896
|
+
moduleSize: r,
|
|
1870
1897
|
margin: s
|
|
1871
|
-
}),
|
|
1898
|
+
}), u = {
|
|
1872
1899
|
type: "img",
|
|
1873
1900
|
props: {
|
|
1874
|
-
src: `data:image/png;base64,${O(
|
|
1875
|
-
width: `${
|
|
1876
|
-
height: `${
|
|
1901
|
+
src: `data:image/png;base64,${O(h)}`,
|
|
1902
|
+
width: `${o}`,
|
|
1903
|
+
height: `${c}`,
|
|
1877
1904
|
style: {
|
|
1878
1905
|
imageRendering: "pixelated"
|
|
1879
1906
|
}
|
|
1880
1907
|
}
|
|
1881
|
-
},
|
|
1908
|
+
}, l = {
|
|
1882
1909
|
type: "div",
|
|
1883
1910
|
props: {
|
|
1884
1911
|
style: {
|
|
1885
|
-
|
|
1886
|
-
paddingLeft:
|
|
1887
|
-
width:
|
|
1888
|
-
display: "
|
|
1912
|
+
justifyContent: n,
|
|
1913
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1914
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1915
|
+
display: "flex"
|
|
1889
1916
|
},
|
|
1890
|
-
children: [
|
|
1917
|
+
children: [u]
|
|
1891
1918
|
}
|
|
1892
1919
|
};
|
|
1893
|
-
return this.contentNodes.push(
|
|
1920
|
+
return this.contentNodes.push(l), this.estimatedHeight += c, "";
|
|
1894
1921
|
}
|
|
1895
1922
|
// print barcode:
|
|
1896
1923
|
async barcode(t, e) {
|
|
1897
|
-
const
|
|
1898
|
-
if (a !== void 0 && "length" in
|
|
1899
|
-
const s =
|
|
1900
|
-
let
|
|
1901
|
-
|
|
1902
|
-
const
|
|
1924
|
+
const n = K(t), a = n.height, r = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end";
|
|
1925
|
+
if (a !== void 0 && "length" in n && n.length !== void 0 && n.widths) {
|
|
1926
|
+
const s = n.length, h = a + (n.hri ? this.charHeight + 2 : 0);
|
|
1927
|
+
let o = "";
|
|
1928
|
+
n.widths.reduce((l, g, p) => (p % 2 === 1 && (o += `M${l},0h${g}v${a}h${-g}z`), l + g), 0);
|
|
1929
|
+
const c = [
|
|
1903
1930
|
{
|
|
1904
1931
|
type: "path",
|
|
1905
1932
|
props: {
|
|
1906
|
-
d:
|
|
1933
|
+
d: o,
|
|
1907
1934
|
fill: "black"
|
|
1908
1935
|
}
|
|
1909
1936
|
}
|
|
1910
1937
|
];
|
|
1911
|
-
|
|
1938
|
+
n.hri && n.text && c.push({
|
|
1912
1939
|
type: "text",
|
|
1913
1940
|
props: {
|
|
1914
1941
|
x: `${s / 2}`,
|
|
1915
|
-
y: `${
|
|
1942
|
+
y: `${h}`,
|
|
1916
1943
|
"text-anchor": "middle",
|
|
1917
1944
|
"font-family": "monospace",
|
|
1918
1945
|
"font-size": `${this.charWidth * 2}`,
|
|
1919
1946
|
fill: "black",
|
|
1920
|
-
children:
|
|
1947
|
+
children: n.text
|
|
1921
1948
|
}
|
|
1922
1949
|
});
|
|
1923
|
-
const
|
|
1950
|
+
const d = {
|
|
1924
1951
|
type: "svg",
|
|
1925
1952
|
props: {
|
|
1926
1953
|
width: `${s}`,
|
|
1927
|
-
height: `${
|
|
1928
|
-
viewBox: `0 0 ${s} ${
|
|
1929
|
-
|
|
1930
|
-
display: "block"
|
|
1931
|
-
},
|
|
1932
|
-
children: o
|
|
1954
|
+
height: `${h}`,
|
|
1955
|
+
viewBox: `0 0 ${s} ${h}`,
|
|
1956
|
+
children: c
|
|
1933
1957
|
}
|
|
1934
1958
|
}, u = {
|
|
1935
1959
|
type: "div",
|
|
1936
1960
|
props: {
|
|
1937
1961
|
style: {
|
|
1938
|
-
|
|
1939
|
-
paddingLeft:
|
|
1940
|
-
width:
|
|
1941
|
-
display: "
|
|
1962
|
+
justifyContent: r,
|
|
1963
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1964
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1965
|
+
display: "flex"
|
|
1942
1966
|
},
|
|
1943
|
-
children:
|
|
1967
|
+
children: d
|
|
1944
1968
|
}
|
|
1945
1969
|
};
|
|
1946
|
-
this.contentNodes.push(u), this.estimatedHeight +=
|
|
1970
|
+
this.contentNodes.push(u), this.estimatedHeight += h;
|
|
1947
1971
|
}
|
|
1948
1972
|
return "";
|
|
1949
1973
|
}
|
|
@@ -1979,8 +2003,8 @@ class tt extends H {
|
|
|
1979
2003
|
* @param {number} right right margin (unit: characters)
|
|
1980
2004
|
* @returns {Promise<string>} empty string
|
|
1981
2005
|
*/
|
|
1982
|
-
async area(t, e,
|
|
1983
|
-
return this.logs.push(`area(left: ${t}, width: ${e}, right: ${
|
|
2006
|
+
async area(t, e, n) {
|
|
2007
|
+
return this.logs.push(`area(left: ${t}, width: ${e}, right: ${n})`), "";
|
|
1984
2008
|
}
|
|
1985
2009
|
/**
|
|
1986
2010
|
* Set line alignment.
|
|
@@ -2047,8 +2071,8 @@ class tt extends H {
|
|
|
2047
2071
|
* @param {number} dr difference in right position
|
|
2048
2072
|
* @returns {Promise<string>} empty string
|
|
2049
2073
|
*/
|
|
2050
|
-
async vrhr(t, e,
|
|
2051
|
-
return this.logs.push(`vrhr(widths1: [${t.join(", ")}], widths2: [${e.join(", ")}], dl: ${
|
|
2074
|
+
async vrhr(t, e, n, a) {
|
|
2075
|
+
return this.logs.push(`vrhr(widths1: [${t.join(", ")}], widths2: [${e.join(", ")}], dl: ${n}, dr: ${a})`), "";
|
|
2052
2076
|
}
|
|
2053
2077
|
/**
|
|
2054
2078
|
* Set line spacing and feed new line.
|
|
@@ -2161,63 +2185,63 @@ class tt extends H {
|
|
|
2161
2185
|
}
|
|
2162
2186
|
const z = {
|
|
2163
2187
|
base: new H(),
|
|
2164
|
-
svg: new
|
|
2188
|
+
svg: new F(),
|
|
2165
2189
|
html: new Y(),
|
|
2166
2190
|
audit: new tt()
|
|
2167
2191
|
};
|
|
2168
|
-
function Ot(
|
|
2169
|
-
const t = Object.assign({},
|
|
2170
|
-
let
|
|
2171
|
-
return
|
|
2192
|
+
function Ot(i) {
|
|
2193
|
+
const t = Object.assign({}, i), e = t.encoding && /^(cp(437|85[28]|86[0356]|1252|93[26]|949|950)|multilingual|shiftjis|gb18030|ksc5601|big5|tis620)$/.test(t.encoding) ? t.encoding : "cp437", n = typeof t.target == "string" ? t.target : void 0, r = (typeof t.target == "object" && t.target !== null ? t.target : void 0) || (n && n in z ? z[n] : z.svg);
|
|
2194
|
+
let s;
|
|
2195
|
+
return r instanceof Y || r instanceof F || r instanceof tt || r instanceof H ? s = r : s = new F(), {
|
|
2172
2196
|
cpl: t.cpl || 48,
|
|
2173
2197
|
charWidth: t.charWidth || 12,
|
|
2174
2198
|
encoding: e,
|
|
2175
2199
|
spacing: !!t.spacing,
|
|
2176
2200
|
margin: t.margin || 0,
|
|
2177
2201
|
marginRight: t.marginRight || 0,
|
|
2178
|
-
target:
|
|
2202
|
+
target: s
|
|
2179
2203
|
};
|
|
2180
2204
|
}
|
|
2181
|
-
function _t(
|
|
2182
|
-
const e =
|
|
2183
|
-
let
|
|
2205
|
+
function _t(i, t) {
|
|
2206
|
+
const e = i.replace(/^[\t ]+|[\t ]+$/g, "").replace(/\\[\\{|}]/g, (n) => "\\x" + n.charCodeAt(1).toString(16)).replace(/^[^|]*[^\t |]\|/, " $&").replace(/\|[^\t |][^|]*$/, "$& ").replace(/^\|(.*)$/, "$1").replace(/^(.*)\|$/, "$1").split("|").map((n, a, r) => {
|
|
2207
|
+
let s = {
|
|
2184
2208
|
align: 1,
|
|
2185
2209
|
wrap: t.wrap,
|
|
2186
2210
|
border: t.border,
|
|
2187
2211
|
width: 0,
|
|
2188
2212
|
alignment: t.align
|
|
2189
2213
|
};
|
|
2190
|
-
const h =
|
|
2191
|
-
if (
|
|
2192
|
-
if (
|
|
2193
|
-
const
|
|
2214
|
+
const h = n.replace(/^[\t ]+|[\t ]+$/g, "");
|
|
2215
|
+
if (s.align = 1 + Number(/^[\t ]/.test(n)) - Number(/[\t ]$/.test(n)), /^\{[^{}]*\}$/.test(h)) {
|
|
2216
|
+
if (s.property = h.slice(1, -1).replace(/\\;/g, "\\x3b").split(";").reduce((o, c) => {
|
|
2217
|
+
const d = { a: "align", b: "border", c: "code", i: "image", o: "option", t: "text", w: "width", x: "command", _: "comment" };
|
|
2194
2218
|
return /^[\t ]*$/.test(c) || c.replace(
|
|
2195
2219
|
/^[\t ]*([A-Za-z_]\w*)[\t ]*:[\t ]*([^\t ].*?)[\t ]*$/,
|
|
2196
|
-
(
|
|
2197
|
-
const f = g.replace(/^[abciotwx_]$/, ($) =>
|
|
2198
|
-
return o[f] =
|
|
2199
|
-
`)),
|
|
2220
|
+
(l, g, p) => {
|
|
2221
|
+
const f = g.replace(/^[abciotwx_]$/, ($) => d[$] || $);
|
|
2222
|
+
return o[f] = R(p.replace(/\\n/g, `
|
|
2223
|
+
`)), l;
|
|
2200
2224
|
}
|
|
2201
|
-
) === c && (
|
|
2202
|
-
}, {}),
|
|
2203
|
-
if ("text" in
|
|
2204
|
-
const o =
|
|
2225
|
+
) === c && (s.error = h), o;
|
|
2226
|
+
}, {}), r.length === 1) {
|
|
2227
|
+
if ("text" in s.property && s.property.text) {
|
|
2228
|
+
const o = s.property.text.toLowerCase();
|
|
2205
2229
|
t.wrap = !/^nowrap$/.test(o);
|
|
2206
2230
|
}
|
|
2207
|
-
if ("border" in
|
|
2208
|
-
const o =
|
|
2209
|
-
t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1,
|
|
2231
|
+
if ("border" in s.property && s.property.border) {
|
|
2232
|
+
const o = s.property.border.toLowerCase(), c = { line: -1, space: 1, none: 0 }, d = t.border;
|
|
2233
|
+
t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1, d >= 0 && t.border < 0 && (s.vr = "+"), d < 0 && t.border >= 0 && (s.vr = "-");
|
|
2210
2234
|
}
|
|
2211
|
-
if ("width" in
|
|
2212
|
-
const o =
|
|
2235
|
+
if ("width" in s.property && s.property.width) {
|
|
2236
|
+
const o = s.property.width.toLowerCase().split(/[\t ]+|,/);
|
|
2213
2237
|
t.width = o.find((c) => /^auto$/.test(c)) ? [] : o.map((c) => /^\*$/.test(c) ? -1 : /^\d+$/.test(c) ? Number(c) : 0);
|
|
2214
2238
|
}
|
|
2215
|
-
if ("align" in
|
|
2216
|
-
const o =
|
|
2239
|
+
if ("align" in s.property && s.property.align) {
|
|
2240
|
+
const o = s.property.align.toLowerCase(), c = { left: 0, center: 1, right: 2 };
|
|
2217
2241
|
t.align = /^(left|center|right)$/.test(o) ? c[o] ?? 1 : 1;
|
|
2218
2242
|
}
|
|
2219
|
-
if ("option" in
|
|
2220
|
-
const o =
|
|
2243
|
+
if ("option" in s.property && s.property.option) {
|
|
2244
|
+
const o = s.property.option.toLowerCase().split(/[\t ]+|,/);
|
|
2221
2245
|
t.option = {
|
|
2222
2246
|
type: o.find((c) => /^(upc|ean|jan|code39|itf|codabar|nw7|code93|code128|qrcode)$/.test(c)) || "code128",
|
|
2223
2247
|
width: Number(o.find((c) => /^\d+$/.test(c) && Number(c) >= 2 && Number(c) <= 4) || "2"),
|
|
@@ -2228,77 +2252,77 @@ function _t(n, t) {
|
|
|
2228
2252
|
quietZone: !1
|
|
2229
2253
|
};
|
|
2230
2254
|
}
|
|
2231
|
-
if ("code" in
|
|
2232
|
-
const o =
|
|
2255
|
+
if ("code" in s.property && s.property.code && (t.option.type === "qrcode" ? s.code = Object.assign({ data: s.property.code, type: "qrcode" }, t.option) : s.code = Object.assign({ data: s.property.code, type: t.option.type }, t.option)), "image" in s.property && s.property.image) {
|
|
2256
|
+
const o = s.property.image.replace(/=.*|[^A-Za-z0-9+/]/g, "");
|
|
2233
2257
|
switch (o.length % 4) {
|
|
2234
2258
|
case 1:
|
|
2235
|
-
|
|
2259
|
+
s.image = o.slice(0, -1);
|
|
2236
2260
|
break;
|
|
2237
2261
|
case 2:
|
|
2238
|
-
|
|
2262
|
+
s.image = o + "==";
|
|
2239
2263
|
break;
|
|
2240
2264
|
case 3:
|
|
2241
|
-
|
|
2265
|
+
s.image = o + "=";
|
|
2242
2266
|
break;
|
|
2243
2267
|
default:
|
|
2244
|
-
|
|
2268
|
+
s.image = o;
|
|
2245
2269
|
break;
|
|
2246
2270
|
}
|
|
2247
2271
|
}
|
|
2248
|
-
"command" in
|
|
2272
|
+
"command" in s.property && s.property.command && (s.command = s.property.command), "comment" in s.property && s.property.comment && (s.comment = s.property.comment);
|
|
2249
2273
|
}
|
|
2250
2274
|
} else if (/[{}]/.test(h))
|
|
2251
|
-
|
|
2252
|
-
else if (
|
|
2275
|
+
s.error = h;
|
|
2276
|
+
else if (r.length === 1 && /^-+$|^=+$/.test(h)) {
|
|
2253
2277
|
const o = h.slice(-1);
|
|
2254
|
-
|
|
2278
|
+
s.hr = o === "-" || o === "=" ? o : void 0;
|
|
2255
2279
|
} else
|
|
2256
|
-
|
|
2257
|
-
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) =>
|
|
2258
|
-
if (
|
|
2259
|
-
|
|
2260
|
-
else if ("text" in
|
|
2261
|
-
|
|
2280
|
+
s.text = h.replace(/[\x00-\x1f\x7f]|\\x[01][\dA-Fa-f]|\\x7[Ff]/g, "").replace(/\\[-=_"`^~]/g, (o) => "\\x" + o.charCodeAt(1).toString(16)).replace(/\\n/g, `
|
|
2281
|
+
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) => R(o));
|
|
2282
|
+
if (s.wrap = t.wrap, s.border = t.border, t.width.length === 0)
|
|
2283
|
+
s.width = -1;
|
|
2284
|
+
else if ("text" in s)
|
|
2285
|
+
s.width = a < t.width.length ? t.width[a] ?? 0 : 0;
|
|
2262
2286
|
else if (t.width.find((o) => o < 0))
|
|
2263
|
-
|
|
2287
|
+
s.width = -1;
|
|
2264
2288
|
else {
|
|
2265
2289
|
const o = t.width.filter((c) => c > 0);
|
|
2266
|
-
|
|
2290
|
+
s.width = o.length > 0 ? o.reduce((c, d) => c + d, s.border < 0 ? o.length + 1 : (o.length - 1) * s.border) : 0;
|
|
2267
2291
|
}
|
|
2268
|
-
return
|
|
2292
|
+
return s.alignment = t.align, s;
|
|
2269
2293
|
});
|
|
2270
|
-
if (e.every((
|
|
2294
|
+
if (e.every((n) => "text" in n) && t.width.length > 0)
|
|
2271
2295
|
for (; e.length < t.width.length; )
|
|
2272
2296
|
e.push({ align: 1, text: [""], wrap: t.wrap, border: t.border, width: t.width[e.length] ?? 0, alignment: t.align });
|
|
2273
2297
|
return e;
|
|
2274
2298
|
}
|
|
2275
|
-
function
|
|
2276
|
-
return
|
|
2299
|
+
function R(i) {
|
|
2300
|
+
return i.replace(/\\$|\\x(.?$|[^\dA-Fa-f].|.[^\dA-Fa-f])/g, "").replace(/\\[^x]/g, "").replace(/\\x([\dA-Fa-f]{2})/g, (t, e) => String.fromCharCode(parseInt(e, 16)));
|
|
2277
2301
|
}
|
|
2278
|
-
function Gt(
|
|
2302
|
+
function Gt(i, t) {
|
|
2279
2303
|
const e = [];
|
|
2280
|
-
let
|
|
2281
|
-
return
|
|
2304
|
+
let n = i.width, a = 1, r = [], s = !1, h = !1, o = !1, c = 0;
|
|
2305
|
+
return i.text.forEach((d, u) => {
|
|
2282
2306
|
if (u % 2 === 0) {
|
|
2283
|
-
let
|
|
2284
|
-
for (;
|
|
2307
|
+
let l = t.target.arrayFrom(d, t.encoding);
|
|
2308
|
+
for (; l.length > 0; ) {
|
|
2285
2309
|
let g = 0, p = 0;
|
|
2286
|
-
for (; p <
|
|
2287
|
-
|
|
2288
|
-
if (p > 0 && (
|
|
2289
|
-
|
|
2310
|
+
for (; p < l.length && (g = t.target.measureText(l[p] ?? "", t.encoding) * (c < 2 ? c + 1 : c - 1), !(g > n)); )
|
|
2311
|
+
n -= g, g = 0, p++;
|
|
2312
|
+
if (p > 0 && (r.push((s ? "1" : "0") + (h ? "1" : "0") + (o ? "1" : "0") + c), r.push(l.slice(0, p).join("")), a = Math.max(a, c < 3 ? c : c - 1), l = l.slice(p)), g > i.width) {
|
|
2313
|
+
l = l.slice(1);
|
|
2290
2314
|
continue;
|
|
2291
2315
|
}
|
|
2292
|
-
(g >
|
|
2316
|
+
(g > n || n === 0) && (e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1);
|
|
2293
2317
|
}
|
|
2294
2318
|
} else
|
|
2295
|
-
switch (
|
|
2319
|
+
switch (d) {
|
|
2296
2320
|
case `
|
|
2297
2321
|
`:
|
|
2298
|
-
e.push({ data:
|
|
2322
|
+
e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1;
|
|
2299
2323
|
break;
|
|
2300
2324
|
case "_":
|
|
2301
|
-
|
|
2325
|
+
s = !s;
|
|
2302
2326
|
break;
|
|
2303
2327
|
case '"':
|
|
2304
2328
|
h = !h;
|
|
@@ -2307,93 +2331,93 @@ function Gt(n, t) {
|
|
|
2307
2331
|
o = !o;
|
|
2308
2332
|
break;
|
|
2309
2333
|
default:
|
|
2310
|
-
const
|
|
2311
|
-
c = c ===
|
|
2334
|
+
const l = Math.min(d.length, 7);
|
|
2335
|
+
c = c === l ? 0 : l;
|
|
2312
2336
|
break;
|
|
2313
2337
|
}
|
|
2314
|
-
}),
|
|
2338
|
+
}), r.length > 0 && e.push({ data: r, margin: n * i.align / 2, height: a }), e;
|
|
2315
2339
|
}
|
|
2316
|
-
async function Kt(
|
|
2317
|
-
const
|
|
2318
|
-
let
|
|
2319
|
-
a && (
|
|
2320
|
-
const h =
|
|
2321
|
-
let c = h.reduce((f, $) => f + $.width, 0),
|
|
2322
|
-
a &&
|
|
2340
|
+
async function Kt(i, t, e) {
|
|
2341
|
+
const n = [], a = i.every((f) => "text" in f), r = i[0] ?? { align: 1, text: [""], wrap: !0, border: 0, width: 0, alignment: 1 };
|
|
2342
|
+
let s = i.filter((f) => f.width !== 0);
|
|
2343
|
+
a && (s = s.slice(0, Math.floor(r.border < 0 ? (t.target.cpl - 1) / 2 : (t.target.cpl + r.border) / (r.border + 1))));
|
|
2344
|
+
const h = s.filter((f) => f.width > 0), o = s.filter((f) => f.width < 0);
|
|
2345
|
+
let c = h.reduce((f, $) => f + $.width, 0), d = t.target.cpl - c;
|
|
2346
|
+
a && s.length > 0 && (d -= r.border < 0 ? s.length + 1 : (s.length - 1) * r.border);
|
|
2323
2347
|
const u = o.length;
|
|
2324
|
-
for (; u >
|
|
2325
|
-
const f = h.reduce(($,
|
|
2326
|
-
f.width--,
|
|
2348
|
+
for (; u > d; ) {
|
|
2349
|
+
const f = h.reduce(($, x) => $.width > x.width ? $ : x);
|
|
2350
|
+
f.width--, d++;
|
|
2327
2351
|
}
|
|
2328
|
-
u > 0 && (o.forEach((f, $) => f.width = Math.floor((
|
|
2329
|
-
const
|
|
2352
|
+
u > 0 && (o.forEach((f, $) => f.width = Math.floor((d + $) / u)), d = 0);
|
|
2353
|
+
const l = Math.floor(d * r.alignment / 2), g = t.target.cpl - d, p = d - l;
|
|
2330
2354
|
if (a) {
|
|
2331
|
-
const f =
|
|
2355
|
+
const f = s.map((w) => Gt(w, t)), $ = s.map((w) => w.width);
|
|
2332
2356
|
switch (e.line) {
|
|
2333
2357
|
case "ready":
|
|
2334
|
-
|
|
2335
|
-
await t.target.normal() + await t.target.area(
|
|
2358
|
+
n.push(
|
|
2359
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0) + await t.target.vrstart($) + await t.target.vrlf(!0)
|
|
2336
2360
|
), e.line = "running";
|
|
2337
2361
|
break;
|
|
2338
2362
|
case "horizontal":
|
|
2339
|
-
const w =
|
|
2340
|
-
|
|
2341
|
-
await t.target.normal() + await t.target.area(
|
|
2363
|
+
const w = l - e.rules.left, m = g - e.rules.width, k = Math.min(l, e.rules.left), v = Math.min(p, e.rules.right);
|
|
2364
|
+
n.push(
|
|
2365
|
+
await t.target.normal() + await t.target.area(k, t.target.cpl - k - v, v) + await t.target.align(0) + await t.target.vrhr(e.rules.widths, $, w, w + m) + await t.target.lf()
|
|
2342
2366
|
), e.line = "running";
|
|
2343
2367
|
break;
|
|
2344
2368
|
}
|
|
2345
|
-
e.rules = { left:
|
|
2346
|
-
const
|
|
2347
|
-
for (let w = 0; w <
|
|
2348
|
-
let m = await t.target.normal() + await t.target.area(
|
|
2369
|
+
e.rules = { left: l, width: g, right: p, widths: $ };
|
|
2370
|
+
const x = r.wrap ? f.reduce((w, m) => Math.max(w, m.length), 1) : 1;
|
|
2371
|
+
for (let w = 0; w < x; w++) {
|
|
2372
|
+
let m = await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0), k = 0;
|
|
2349
2373
|
if (e.line === "running") {
|
|
2350
|
-
const v = f.reduce((
|
|
2351
|
-
m += await t.target.normal() + await t.target.absolute(
|
|
2374
|
+
const v = f.reduce((A, W) => w < W.length ? Math.max(A, W[w]?.height ?? 1) : A, 1);
|
|
2375
|
+
m += await t.target.normal() + await t.target.absolute(k++) + await t.target.vr($, v);
|
|
2352
2376
|
}
|
|
2353
2377
|
for (let v = 0; v < f.length; v++) {
|
|
2354
|
-
const
|
|
2355
|
-
if (
|
|
2356
|
-
if (m += await t.target.absolute(
|
|
2357
|
-
m += await t.target.relative(
|
|
2358
|
-
const
|
|
2359
|
-
for (let S = 0; S <
|
|
2360
|
-
const D = Number(String(
|
|
2361
|
-
m += await t.target.normal(), D && (m += await t.target.ul()), et && (m += await t.target.em()),
|
|
2378
|
+
const A = f[v];
|
|
2379
|
+
if (A) {
|
|
2380
|
+
if (m += await t.target.absolute(k), w < A.length) {
|
|
2381
|
+
m += await t.target.relative(A[w]?.margin ?? 0);
|
|
2382
|
+
const W = A[w]?.data ?? [];
|
|
2383
|
+
for (let S = 0; S < W.length; S += 2) {
|
|
2384
|
+
const D = Number(String(W[S])[0]), et = Number(String(W[S])[1]), it = Number(String(W[S])[2]), B = Number(String(W[S])[3]);
|
|
2385
|
+
m += await t.target.normal(), D && (m += await t.target.ul()), et && (m += await t.target.em()), it && (m += await t.target.iv()), B && (m += await t.target.wh(B)), m += await t.target.text(String(W[S + 1]), t.encoding);
|
|
2362
2386
|
}
|
|
2363
2387
|
} else
|
|
2364
2388
|
m += await t.target.normal() + await t.target.text(" ", t.encoding);
|
|
2365
|
-
|
|
2389
|
+
k += (s[v]?.width ?? 0) + Math.abs(r.border);
|
|
2366
2390
|
}
|
|
2367
2391
|
}
|
|
2368
|
-
m += await t.target.lf(),
|
|
2392
|
+
m += await t.target.lf(), n.push(m);
|
|
2369
2393
|
}
|
|
2370
2394
|
}
|
|
2371
|
-
if ("hr" in
|
|
2372
|
-
if (
|
|
2395
|
+
if ("hr" in r)
|
|
2396
|
+
if (r.hr === "=")
|
|
2373
2397
|
switch (e.line) {
|
|
2374
2398
|
case "running":
|
|
2375
2399
|
case "horizontal":
|
|
2376
|
-
|
|
2400
|
+
n.push(
|
|
2377
2401
|
await t.target.normal() + await t.target.area(e.rules.left, e.rules.width, e.rules.right) + await t.target.align(0) + await t.target.vrstop(e.rules.widths) + await t.target.vrlf(!1)
|
|
2378
|
-
),
|
|
2402
|
+
), n.push(await t.target.cut()), e.line = "ready";
|
|
2379
2403
|
break;
|
|
2380
2404
|
default:
|
|
2381
|
-
|
|
2405
|
+
n.push(await t.target.cut());
|
|
2382
2406
|
break;
|
|
2383
2407
|
}
|
|
2384
2408
|
else
|
|
2385
2409
|
switch (e.line) {
|
|
2386
2410
|
case "waiting":
|
|
2387
|
-
|
|
2388
|
-
await t.target.normal() + await t.target.area(
|
|
2411
|
+
n.push(
|
|
2412
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(0) + await t.target.hr(g) + await t.target.lf()
|
|
2389
2413
|
);
|
|
2390
2414
|
break;
|
|
2391
2415
|
case "running":
|
|
2392
2416
|
e.line = "horizontal";
|
|
2393
2417
|
break;
|
|
2394
2418
|
}
|
|
2395
|
-
if ("vr" in
|
|
2396
|
-
if (
|
|
2419
|
+
if ("vr" in r)
|
|
2420
|
+
if (r.vr === "+")
|
|
2397
2421
|
e.line = "ready";
|
|
2398
2422
|
else
|
|
2399
2423
|
switch (e.line) {
|
|
@@ -2402,26 +2426,26 @@ async function Kt(n, t, e) {
|
|
|
2402
2426
|
break;
|
|
2403
2427
|
case "running":
|
|
2404
2428
|
case "horizontal":
|
|
2405
|
-
|
|
2429
|
+
n.push(
|
|
2406
2430
|
await t.target.normal() + await t.target.area(e.rules.left, e.rules.width, e.rules.right) + await t.target.align(0) + await t.target.vrstop(e.rules.widths) + await t.target.vrlf(!1)
|
|
2407
2431
|
), e.line = "waiting";
|
|
2408
2432
|
break;
|
|
2409
2433
|
}
|
|
2410
|
-
return "image" in
|
|
2411
|
-
await t.target.normal() + await t.target.area(
|
|
2412
|
-
), "code" in
|
|
2413
|
-
await t.target.normal() + await t.target.area(
|
|
2414
|
-
) :
|
|
2415
|
-
await t.target.normal() + await t.target.area(
|
|
2416
|
-
)), "command" in
|
|
2417
|
-
await t.target.normal() + await t.target.area(
|
|
2418
|
-
),
|
|
2434
|
+
return "image" in r && r.image && n.push(
|
|
2435
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.image(r.image)
|
|
2436
|
+
), "code" in r && r.code && (r.code.type === "qrcode" ? n.push(
|
|
2437
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.qrcode(r.code, t.encoding)
|
|
2438
|
+
) : n.push(
|
|
2439
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.barcode(r.code, t.encoding)
|
|
2440
|
+
)), "command" in r && r.command && n.push(
|
|
2441
|
+
await t.target.normal() + await t.target.area(l, g, p) + await t.target.align(r.align) + await t.target.command(r.command)
|
|
2442
|
+
), n.join("");
|
|
2419
2443
|
}
|
|
2420
|
-
async function Yt(
|
|
2444
|
+
async function Yt(i, t) {
|
|
2421
2445
|
const e = Ot(t);
|
|
2422
2446
|
await e.target.lock();
|
|
2423
2447
|
try {
|
|
2424
|
-
const
|
|
2448
|
+
const n = {
|
|
2425
2449
|
wrap: !0,
|
|
2426
2450
|
border: 1,
|
|
2427
2451
|
width: [],
|
|
@@ -2431,24 +2455,24 @@ async function Yt(n, t) {
|
|
|
2431
2455
|
rules: { left: 0, width: 0, right: 0, widths: [] }
|
|
2432
2456
|
};
|
|
2433
2457
|
let a = await e.target.open(e);
|
|
2434
|
-
|
|
2435
|
-
const
|
|
2436
|
-
for (const h of
|
|
2437
|
-
|
|
2438
|
-
switch (
|
|
2458
|
+
i[0] === "\uFEFF" && (i = i.slice(1));
|
|
2459
|
+
const r = i.normalize().split(/\n|\r\n|\r/), s = [];
|
|
2460
|
+
for (const h of r)
|
|
2461
|
+
s.push(await Kt(_t(h, n), e, n));
|
|
2462
|
+
switch (n.line) {
|
|
2439
2463
|
case "ready":
|
|
2440
|
-
|
|
2464
|
+
n.line = "waiting";
|
|
2441
2465
|
break;
|
|
2442
2466
|
case "running":
|
|
2443
2467
|
case "horizontal":
|
|
2444
|
-
|
|
2445
|
-
await e.target.normal() + await e.target.area(
|
|
2446
|
-
),
|
|
2468
|
+
s.push(
|
|
2469
|
+
await e.target.normal() + await e.target.area(n.rules.left, n.rules.width, n.rules.right) + await e.target.align(0) + await e.target.vrstop(n.rules.widths) + await e.target.vrlf(!1)
|
|
2470
|
+
), n.line = "waiting";
|
|
2447
2471
|
break;
|
|
2448
2472
|
default:
|
|
2449
2473
|
break;
|
|
2450
2474
|
}
|
|
2451
|
-
return a +=
|
|
2475
|
+
return a += s.join(""), a += await e.target.close(), {
|
|
2452
2476
|
content: a,
|
|
2453
2477
|
width: e.target.calculatedWidth(),
|
|
2454
2478
|
height: Math.round(e.target.calculatedHeight())
|
|
@@ -2461,6 +2485,6 @@ export {
|
|
|
2461
2485
|
tt as AuditTarget,
|
|
2462
2486
|
H as BaseTarget,
|
|
2463
2487
|
Y as HtmlTarget,
|
|
2464
|
-
|
|
2488
|
+
F as SvgTarget,
|
|
2465
2489
|
Yt as transform
|
|
2466
2490
|
};
|