@levischuck/receiptline 0.1.2 → 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 +515 -486
- 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
|
|
2
|
-
import { qrCode as _, EcLevel as
|
|
3
|
-
import { toSvgString as
|
|
1
|
+
import { decodeBase64 as Z, encodeBase64 as O } from "@levischuck/tiny-encodings";
|
|
2
|
+
import { qrCode as _, EcLevel as M } from "@levischuck/tiny-qr";
|
|
3
|
+
import { toSvgString as nt } from "@levischuck/tiny-qr-svg";
|
|
4
4
|
class H {
|
|
5
5
|
locked = !1;
|
|
6
6
|
lockPromise = null;
|
|
@@ -26,7 +26,7 @@ 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 {
|
|
@@ -39,7 +39,7 @@ class H {
|
|
|
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,12 +58,12 @@ 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
68
|
return o === void 0 ? s : s + (o < 128 || o === 160 || o === 165 || o === 8254 || o > 65376 && o < 65440 ? 1 : 2);
|
|
69
69
|
}, 0);
|
|
@@ -74,7 +74,7 @@ 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
79
|
return o === void 0 ? s : s + (o < 128 || o === 160 ? 1 : 2);
|
|
80
80
|
}, 0);
|
|
@@ -84,13 +84,13 @@ class H {
|
|
|
84
84
|
const o = h.codePointAt(0);
|
|
85
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
|
-
r.consonant && (r.length++, r.consonant = r.vowel = r.tone = !1),
|
|
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 =
|
|
108
|
+
const a = n.reduce((r, s) => {
|
|
109
109
|
const h = s.codePointAt(0);
|
|
110
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 j(
|
|
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 E(
|
|
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 st(
|
|
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 r =
|
|
355
|
-
t.widths = s.split("").map((h) => parseInt(h, 16) *
|
|
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
|
-
const
|
|
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 rt(
|
|
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 = r.split("").map((s) => parseInt(s, 16) *
|
|
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((s) => parseInt(s, 16) *
|
|
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
407
|
const r = [25, 39, 50, 3, 5, 6];
|
|
408
|
-
t.length = e.length * r[
|
|
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
|
|
421
|
+
t.hri = i.hri, t.text = e;
|
|
422
|
+
const n = e.split("").map((o) => Number(o)), a = i.quietZone ? "a" : "0";
|
|
423
423
|
let r = a + q.start, s = 0;
|
|
424
|
-
for (; s <
|
|
425
|
-
const o = q.element[
|
|
426
|
-
r += o.split("").reduce((
|
|
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
|
-
r += q.stop + a, t.widths = r.split("").map((o) => parseInt(o, 16) *
|
|
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((s) => parseInt(s, 16) *
|
|
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
487
|
const r = [29, 45, 58];
|
|
488
|
-
t.length = e.length * r[
|
|
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, r, s) => a + r * (s % 2 * 2 + 1)) % 10) % 10, t.hri =
|
|
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((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri =
|
|
536
|
-
const
|
|
537
|
-
let a =
|
|
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
538
|
for (let r = 0; r < 4; r++) a += b.a[e[r] ?? 0];
|
|
539
539
|
a += b.g[1];
|
|
540
540
|
for (let r = 4; r < 8; r++) a += b.c[e[r] ?? 0];
|
|
541
|
-
a += b.g[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((r, s, h) => r + s * (3 - h % 2 * 2), 0) % 10) % 10, t.hri =
|
|
559
|
-
const
|
|
560
|
-
let a =
|
|
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
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] +
|
|
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 = rt(
|
|
587
|
+
t = rt(i);
|
|
588
588
|
break;
|
|
589
589
|
case "code128":
|
|
590
|
-
t = st(
|
|
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 r = this.charWidth, s = r / 2, h = '<path d="' + t.reduce((c,
|
|
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,10 +726,10 @@ class I extends H {
|
|
|
726
726
|
}
|
|
727
727
|
// print text:
|
|
728
728
|
async text(t, e) {
|
|
729
|
-
let
|
|
729
|
+
let n = this.textPosition;
|
|
730
730
|
const a = this.arrayFrom(t, e).reduce((s, h) => {
|
|
731
|
-
const o = this.measureText(h, e) * this.textScale, c = Math.floor((
|
|
732
|
-
return
|
|
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
733
|
}, ""), r = Object.keys(this.textAttributes).reduce((s, h) => s + ` ${h}="${this.textAttributes[h]}"`, "");
|
|
734
734
|
return this.textElement += `<text${r}>${a}</text>`, this.textPosition += this.measureText(t, e) * this.textScale, "";
|
|
735
735
|
}
|
|
@@ -744,32 +744,32 @@ class I extends H {
|
|
|
744
744
|
}
|
|
745
745
|
// print image:
|
|
746
746
|
async image(t) {
|
|
747
|
-
const e =
|
|
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
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
|
-
ec: t.level == "l" ?
|
|
755
|
-
}), a =
|
|
754
|
+
ec: t.level == "l" ? M.L : t.level == "m" ? M.M : t.level == "q" ? M.Q : M.H
|
|
755
|
+
}), a = n.width, r = t.cell, s = await nt(n, {
|
|
756
756
|
moduleSize: r,
|
|
757
757
|
margin: t.quietZone ? 4 : 0,
|
|
758
758
|
output: "path"
|
|
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),
|
|
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 r =
|
|
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((r - (this.measureText(
|
|
772
|
-
h += `<text y="${s}">${
|
|
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
774
|
const o = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - r) * this.lineAlign / 2);
|
|
775
775
|
this.svgContent += `<g transform="translate(${o},${this.svgHeight})">${h}</g>`, this.svgHeight += s;
|
|
@@ -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
1004
|
const s = t.useCDataForScripts ?? !1, h = t.useCDataForStyles ?? !1, o = t.voidTrailingSlash ?? !0, c = t.attributeNaming ?? "eitherName";
|
|
1005
|
-
return P(
|
|
1005
|
+
return P(n, e, "HTML", s, h, o, c), e.join("");
|
|
1006
1006
|
}
|
|
1007
|
-
function P(
|
|
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
|
-
P(h, t, e,
|
|
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 (
|
|
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
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
|
-
P(
|
|
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 r = await
|
|
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
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,28 +1132,28 @@ 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 At(
|
|
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
|
|
1150
|
+
async function Mt(i) {
|
|
1151
1151
|
const t = new CompressionStream("deflate"), e = t.writable.getWriter();
|
|
1152
|
-
e.write(
|
|
1153
|
-
const
|
|
1152
|
+
e.write(i), e.close();
|
|
1153
|
+
const n = t.readable.getReader(), a = [];
|
|
1154
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
1158
|
a.push(c), r += c.length;
|
|
1159
1159
|
}
|
|
@@ -1164,42 +1164,42 @@ async function Ct(n) {
|
|
|
1164
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
|
|
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
|
-
|
|
1183
|
-
const a =
|
|
1184
|
-
return
|
|
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
|
+
const a = Ct(e.subarray(4, e.length - 4));
|
|
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
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
1198
|
return s;
|
|
1199
1199
|
}
|
|
1200
|
-
const
|
|
1201
|
-
function Et(
|
|
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 Et(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 Pt(
|
|
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,23 +1239,23 @@ 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 + r >
|
|
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: ${r}, available: ${
|
|
1256
|
+
`Chunk "${a}" at offset ${t} extends beyond data (chunk size: ${r}, available: ${i.byteLength - t})`
|
|
1257
1257
|
);
|
|
1258
|
-
const s = new DataView(
|
|
1258
|
+
const s = new DataView(i.buffer, i.byteOffset + t + 8, e);
|
|
1259
1259
|
return {
|
|
1260
1260
|
type: a,
|
|
1261
1261
|
data: s,
|
|
@@ -1263,22 +1263,22 @@ function zt(n, t) {
|
|
|
1263
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)
|
|
@@ -1291,36 +1291,36 @@ function Lt(n) {
|
|
|
1291
1291
|
throw new Error(
|
|
1292
1292
|
`Invalid filter method: ${s}. Only 0 (adaptive) is supported.`
|
|
1293
1293
|
);
|
|
1294
|
-
Dt(
|
|
1294
|
+
Dt(n, a);
|
|
1295
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 r =
|
|
1317
|
+
const r = It(a, "IHDR", Lt, 8);
|
|
1318
1318
|
if (r === void 0)
|
|
1319
1319
|
throw new Error("IHDR chunk not found in PNG");
|
|
1320
1320
|
return r;
|
|
1321
1321
|
}
|
|
1322
|
-
async function
|
|
1323
|
-
const a = new DataView(
|
|
1322
|
+
async function Vt(i, t, e, n) {
|
|
1323
|
+
const a = new DataView(i.buffer), r = a.byteLength;
|
|
1324
1324
|
if (r === 0)
|
|
1325
1325
|
throw new Error("Received empty input");
|
|
1326
1326
|
if (r !== t * e)
|
|
@@ -1332,45 +1332,45 @@ async function Rt(n, t, e, i) {
|
|
|
1332
1332
|
const m = a.getUint8(w);
|
|
1333
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 (${s + 1}). Only ${
|
|
1337
|
+
`Color palette does not have enough colors (${s + 1}). Only ${n.length} were given!`
|
|
1338
1338
|
);
|
|
1339
|
-
const h = qt(s), o = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), c = new Uint8Array(13),
|
|
1340
|
-
|
|
1341
|
-
const u =
|
|
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
1342
|
for (let w = 0; w <= s; w++)
|
|
1343
|
-
g.setUint8(w * 3,
|
|
1344
|
-
const p =
|
|
1345
|
-
return St(o, u, p, $,
|
|
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
1352
|
backgroundColor: r = [255, 255, 255],
|
|
1353
1353
|
foregroundColor: s = [0, 0, 0]
|
|
1354
|
-
} = t, { matrix: h } =
|
|
1355
|
-
|
|
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();
|
|
@@ -1460,10 +1480,10 @@ class Y extends H {
|
|
|
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,8 +1505,8 @@ 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
1511
|
display: "flex"
|
|
1492
1512
|
}
|
|
@@ -1496,21 +1516,21 @@ class Y extends H {
|
|
|
1496
1516
|
}
|
|
1497
1517
|
// print vertical rules:
|
|
1498
1518
|
async vr(t, e) {
|
|
1499
|
-
const
|
|
1519
|
+
const n = this.charWidth, a = n / 2, r = this.charHeight * e, s = t.reduce((d, u) => d + u, 0) + t.length + 1;
|
|
1500
1520
|
let h = `M${a},0v${r}`;
|
|
1501
|
-
for (const
|
|
1502
|
-
h += `m${
|
|
1503
|
-
const o = s *
|
|
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:
|
|
1526
|
+
width: this.toWidthUnit(s),
|
|
1507
1527
|
height: `${r}`,
|
|
1508
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,16 +1548,16 @@ 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:
|
|
1554
|
+
width: this.toWidthUnit(n),
|
|
1535
1555
|
height: `${r}`,
|
|
1536
1556
|
viewBox: `0 0 ${a} ${r}`,
|
|
1537
1557
|
preserveAspectRatio: "none",
|
|
1538
1558
|
style: {
|
|
1539
1559
|
display: "flex",
|
|
1540
|
-
marginLeft:
|
|
1560
|
+
marginLeft: this.toWidthUnit(this.lineMargin)
|
|
1541
1561
|
},
|
|
1542
1562
|
children: {
|
|
1543
1563
|
type: "path",
|
|
@@ -1554,25 +1574,25 @@ 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${
|
|
1577
|
+
const e = this.charWidth, n = e / 2;
|
|
1578
|
+
let a = `M${n},${e + e}v${-n}q0,${-n},${n},${-n}`;
|
|
1559
1579
|
for (let r = 0; r < t.length; r++) {
|
|
1560
1580
|
const s = t[r] ?? 0;
|
|
1561
|
-
a += `h${e * s}h${
|
|
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:
|
|
1590
|
+
width: this.toWidthUnit(n),
|
|
1571
1591
|
height: `${r}`,
|
|
1572
1592
|
viewBox: `0 0 ${a} ${r}`,
|
|
1573
1593
|
preserveAspectRatio: "none",
|
|
1574
1594
|
style: {
|
|
1575
|
-
marginLeft:
|
|
1595
|
+
marginLeft: this.toWidthUnit(this.lineMargin)
|
|
1576
1596
|
},
|
|
1577
1597
|
children: {
|
|
1578
1598
|
type: "path",
|
|
@@ -1589,37 +1609,37 @@ class Y extends H {
|
|
|
1589
1609
|
return this.contentNodes.push(h), "";
|
|
1590
1610
|
}
|
|
1591
1611
|
buildVrStopPath(t) {
|
|
1592
|
-
const e = this.charWidth,
|
|
1593
|
-
let a = `M${
|
|
1612
|
+
const e = this.charWidth, n = e / 2;
|
|
1613
|
+
let a = `M${n},0v${n}q0,${n},${n},${n}`;
|
|
1594
1614
|
for (let r = 0; r < t.length; r++) {
|
|
1595
1615
|
const s = t[r] ?? 0;
|
|
1596
|
-
a += `h${e * s}h${
|
|
1616
|
+
a += `h${e * s}h${n}v${-e}m0,${e}h${n}`;
|
|
1597
1617
|
}
|
|
1598
|
-
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;
|
|
1599
1619
|
}
|
|
1600
1620
|
// print vertical and horizontal rules:
|
|
1601
|
-
async vrhr(t, e,
|
|
1602
|
-
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),
|
|
1603
|
-
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}`);
|
|
1604
1624
|
for (const f of t)
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
let g = `M${s},${r + r}` + (
|
|
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}`);
|
|
1608
1628
|
for (const f of e)
|
|
1609
1629
|
g += `h${r * f}h${s}v${r}m0,${-r}h${s}`;
|
|
1610
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}`);
|
|
1611
1631
|
const p = {
|
|
1612
1632
|
type: "svg",
|
|
1613
1633
|
props: {
|
|
1614
|
-
width:
|
|
1634
|
+
width: this.toWidthUnit(c),
|
|
1615
1635
|
height: `${u}`,
|
|
1616
|
-
viewBox: `0 0 ${
|
|
1636
|
+
viewBox: `0 0 ${d} ${u}`,
|
|
1617
1637
|
preserveAspectRatio: "none",
|
|
1618
1638
|
style: {
|
|
1619
|
-
marginLeft:
|
|
1639
|
+
marginLeft: this.toWidthUnit(this.lineMargin + Math.max(-n, 0))
|
|
1620
1640
|
},
|
|
1621
1641
|
children: [
|
|
1622
|
-
{ 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" } },
|
|
1623
1643
|
{ type: "path", props: { d: g, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } }
|
|
1624
1644
|
]
|
|
1625
1645
|
}
|
|
@@ -1685,8 +1705,8 @@ class Y extends H {
|
|
|
1685
1705
|
}
|
|
1686
1706
|
// scale up text:
|
|
1687
1707
|
async wh(t) {
|
|
1688
|
-
const e = t < 2 ? t + 1 : t - 1,
|
|
1689
|
-
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, "";
|
|
1690
1710
|
}
|
|
1691
1711
|
// cancel text decoration:
|
|
1692
1712
|
async normal() {
|
|
@@ -1694,9 +1714,9 @@ class Y extends H {
|
|
|
1694
1714
|
}
|
|
1695
1715
|
// print text:
|
|
1696
1716
|
async text(t, e) {
|
|
1697
|
-
const
|
|
1717
|
+
const n = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " "), a = this.measureText(t, e), r = {
|
|
1698
1718
|
position: this.currentPosition,
|
|
1699
|
-
text:
|
|
1719
|
+
text: n,
|
|
1700
1720
|
styles: { ...this.currentStyles },
|
|
1701
1721
|
scale: this.textScale,
|
|
1702
1722
|
charWidth: a
|
|
@@ -1705,7 +1725,7 @@ class Y extends H {
|
|
|
1705
1725
|
}
|
|
1706
1726
|
// feed new line:
|
|
1707
1727
|
async lf() {
|
|
1708
|
-
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 = [];
|
|
1709
1729
|
if (this.lineSegments.length === 0) {
|
|
1710
1730
|
if (this.pendingVrSvg) {
|
|
1711
1731
|
const s = {
|
|
@@ -1724,31 +1744,40 @@ class Y extends H {
|
|
|
1724
1744
|
}
|
|
1725
1745
|
return this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
|
|
1726
1746
|
} else {
|
|
1727
|
-
const s = [...this.lineSegments].sort((u,
|
|
1747
|
+
const s = [...this.lineSegments].sort((u, l) => u.position - l.position);
|
|
1728
1748
|
let h = 0;
|
|
1729
|
-
const o = (u) => Math.floor(u), c = (u) =>
|
|
1730
|
-
const
|
|
1731
|
-
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;
|
|
1732
1761
|
};
|
|
1733
1762
|
for (let u = 0; u < s.length; u++) {
|
|
1734
|
-
const
|
|
1763
|
+
const l = s[u], g = this.lineMargin + l.position, p = l.charWidth * l.scale;
|
|
1735
1764
|
if (g > h && a.length > 0) {
|
|
1736
|
-
const
|
|
1765
|
+
const k = g - h, v = a[a.length - 1];
|
|
1737
1766
|
if (v && v.props && v.props.style && typeof v.props.style == "object" && !Array.isArray(v.props.style)) {
|
|
1738
|
-
const A = v.props.style,
|
|
1739
|
-
if (
|
|
1740
|
-
const D =
|
|
1767
|
+
const A = v.props.style, W = A.flexBasis;
|
|
1768
|
+
if (W) {
|
|
1769
|
+
const D = d(W) + k;
|
|
1741
1770
|
A.flexBasis = c(D);
|
|
1742
1771
|
} else
|
|
1743
|
-
A.flexBasis = c(
|
|
1772
|
+
A.flexBasis = c(k);
|
|
1744
1773
|
}
|
|
1745
1774
|
} else if (g > h && a.length === 0) {
|
|
1746
|
-
const
|
|
1775
|
+
const k = g - h;
|
|
1747
1776
|
a.push({
|
|
1748
1777
|
type: "span",
|
|
1749
1778
|
props: {
|
|
1750
1779
|
style: {
|
|
1751
|
-
flexBasis: c(
|
|
1780
|
+
flexBasis: c(k)
|
|
1752
1781
|
}
|
|
1753
1782
|
}
|
|
1754
1783
|
});
|
|
@@ -1756,28 +1785,28 @@ class Y extends H {
|
|
|
1756
1785
|
const $ = {
|
|
1757
1786
|
flexBasis: c(p),
|
|
1758
1787
|
whiteSpace: "pre"
|
|
1759
|
-
},
|
|
1788
|
+
}, x = l.styles && Object.keys(l.styles).length > 0, w = x ? l.styles : void 0, m = {
|
|
1760
1789
|
type: "span",
|
|
1761
1790
|
props: {
|
|
1762
1791
|
style: $,
|
|
1763
|
-
children:
|
|
1792
|
+
children: x ? {
|
|
1764
1793
|
// Wrap text in inner span with content styles
|
|
1765
1794
|
type: "span",
|
|
1766
1795
|
props: {
|
|
1767
1796
|
style: w,
|
|
1768
|
-
children:
|
|
1797
|
+
children: l.text
|
|
1769
1798
|
}
|
|
1770
|
-
} :
|
|
1799
|
+
} : l.text
|
|
1771
1800
|
}
|
|
1772
1801
|
};
|
|
1773
1802
|
a.push(m), h = g + p;
|
|
1774
1803
|
}
|
|
1775
|
-
if (h <
|
|
1776
|
-
const u =
|
|
1777
|
-
if (
|
|
1778
|
-
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;
|
|
1779
1808
|
if (p) {
|
|
1780
|
-
const $ =
|
|
1809
|
+
const $ = d(p) + u;
|
|
1781
1810
|
g.flexBasis = c($);
|
|
1782
1811
|
} else
|
|
1783
1812
|
g.flexBasis = c(u);
|
|
@@ -1791,7 +1820,7 @@ class Y extends H {
|
|
|
1791
1820
|
display: "flex",
|
|
1792
1821
|
flexDirection: "row",
|
|
1793
1822
|
height: `${e}px`,
|
|
1794
|
-
width:
|
|
1823
|
+
width: this.toWidthUnit(n)
|
|
1795
1824
|
},
|
|
1796
1825
|
children: a
|
|
1797
1826
|
}
|
|
@@ -1834,12 +1863,12 @@ class Y extends H {
|
|
|
1834
1863
|
}
|
|
1835
1864
|
// print image:
|
|
1836
1865
|
async image(t) {
|
|
1837
|
-
const e = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end",
|
|
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 = {
|
|
1838
1867
|
type: "img",
|
|
1839
1868
|
props: {
|
|
1840
1869
|
src: `data:image/png;base64,${t}`,
|
|
1841
|
-
style:
|
|
1842
|
-
maxWidth:
|
|
1870
|
+
style: Zt({
|
|
1871
|
+
maxWidth: this.toWidthUnit(this.lineWidth)
|
|
1843
1872
|
}),
|
|
1844
1873
|
width: `${r}`,
|
|
1845
1874
|
height: `${s}`
|
|
@@ -1849,8 +1878,8 @@ class Y extends H {
|
|
|
1849
1878
|
props: {
|
|
1850
1879
|
style: {
|
|
1851
1880
|
justifyContent: e,
|
|
1852
|
-
paddingLeft:
|
|
1853
|
-
width:
|
|
1881
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1882
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1854
1883
|
display: "flex"
|
|
1855
1884
|
},
|
|
1856
1885
|
children: h
|
|
@@ -1860,10 +1889,10 @@ class Y extends H {
|
|
|
1860
1889
|
}
|
|
1861
1890
|
// print QR Code (async version using PNG):
|
|
1862
1891
|
async qrcode(t, e) {
|
|
1863
|
-
const
|
|
1892
|
+
const n = this.lineAlign === 0 ? "flex-start" : this.lineAlign === 1 ? "center" : "flex-end", a = _({
|
|
1864
1893
|
data: t.data,
|
|
1865
|
-
ec: t.level === "l" ?
|
|
1866
|
-
}), r = t.cell, s = t.quietZone ? 4 : 0, { bytes: h, width: o, height: c } = await
|
|
1894
|
+
ec: t.level === "l" ? M.L : t.level === "m" ? M.M : t.level === "q" ? M.Q : M.H
|
|
1895
|
+
}), r = t.cell, s = t.quietZone ? 4 : 0, { bytes: h, width: o, height: c } = await Rt(a, {
|
|
1867
1896
|
moduleSize: r,
|
|
1868
1897
|
margin: s
|
|
1869
1898
|
}), u = {
|
|
@@ -1876,27 +1905,27 @@ class Y extends H {
|
|
|
1876
1905
|
imageRendering: "pixelated"
|
|
1877
1906
|
}
|
|
1878
1907
|
}
|
|
1879
|
-
},
|
|
1908
|
+
}, l = {
|
|
1880
1909
|
type: "div",
|
|
1881
1910
|
props: {
|
|
1882
1911
|
style: {
|
|
1883
|
-
justifyContent:
|
|
1884
|
-
paddingLeft:
|
|
1885
|
-
width:
|
|
1912
|
+
justifyContent: n,
|
|
1913
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1914
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1886
1915
|
display: "flex"
|
|
1887
1916
|
},
|
|
1888
1917
|
children: [u]
|
|
1889
1918
|
}
|
|
1890
1919
|
};
|
|
1891
|
-
return this.contentNodes.push(
|
|
1920
|
+
return this.contentNodes.push(l), this.estimatedHeight += c, "";
|
|
1892
1921
|
}
|
|
1893
1922
|
// print barcode:
|
|
1894
1923
|
async barcode(t, e) {
|
|
1895
|
-
const
|
|
1896
|
-
if (a !== void 0 && "length" in
|
|
1897
|
-
const s =
|
|
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);
|
|
1898
1927
|
let o = "";
|
|
1899
|
-
|
|
1928
|
+
n.widths.reduce((l, g, p) => (p % 2 === 1 && (o += `M${l},0h${g}v${a}h${-g}z`), l + g), 0);
|
|
1900
1929
|
const c = [
|
|
1901
1930
|
{
|
|
1902
1931
|
type: "path",
|
|
@@ -1906,7 +1935,7 @@ class Y extends H {
|
|
|
1906
1935
|
}
|
|
1907
1936
|
}
|
|
1908
1937
|
];
|
|
1909
|
-
|
|
1938
|
+
n.hri && n.text && c.push({
|
|
1910
1939
|
type: "text",
|
|
1911
1940
|
props: {
|
|
1912
1941
|
x: `${s / 2}`,
|
|
@@ -1915,10 +1944,10 @@ class Y extends H {
|
|
|
1915
1944
|
"font-family": "monospace",
|
|
1916
1945
|
"font-size": `${this.charWidth * 2}`,
|
|
1917
1946
|
fill: "black",
|
|
1918
|
-
children:
|
|
1947
|
+
children: n.text
|
|
1919
1948
|
}
|
|
1920
1949
|
});
|
|
1921
|
-
const
|
|
1950
|
+
const d = {
|
|
1922
1951
|
type: "svg",
|
|
1923
1952
|
props: {
|
|
1924
1953
|
width: `${s}`,
|
|
@@ -1931,11 +1960,11 @@ class Y extends H {
|
|
|
1931
1960
|
props: {
|
|
1932
1961
|
style: {
|
|
1933
1962
|
justifyContent: r,
|
|
1934
|
-
paddingLeft:
|
|
1935
|
-
width:
|
|
1963
|
+
paddingLeft: this.toWidthUnit(this.lineMargin),
|
|
1964
|
+
width: this.toWidthUnit(this.lineWidth),
|
|
1936
1965
|
display: "flex"
|
|
1937
1966
|
},
|
|
1938
|
-
children:
|
|
1967
|
+
children: d
|
|
1939
1968
|
}
|
|
1940
1969
|
};
|
|
1941
1970
|
this.contentNodes.push(u), this.estimatedHeight += h;
|
|
@@ -1974,8 +2003,8 @@ class tt extends H {
|
|
|
1974
2003
|
* @param {number} right right margin (unit: characters)
|
|
1975
2004
|
* @returns {Promise<string>} empty string
|
|
1976
2005
|
*/
|
|
1977
|
-
async area(t, e,
|
|
1978
|
-
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})`), "";
|
|
1979
2008
|
}
|
|
1980
2009
|
/**
|
|
1981
2010
|
* Set line alignment.
|
|
@@ -2042,8 +2071,8 @@ class tt extends H {
|
|
|
2042
2071
|
* @param {number} dr difference in right position
|
|
2043
2072
|
* @returns {Promise<string>} empty string
|
|
2044
2073
|
*/
|
|
2045
|
-
async vrhr(t, e,
|
|
2046
|
-
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})`), "";
|
|
2047
2076
|
}
|
|
2048
2077
|
/**
|
|
2049
2078
|
* Set line spacing and feed new line.
|
|
@@ -2156,14 +2185,14 @@ class tt extends H {
|
|
|
2156
2185
|
}
|
|
2157
2186
|
const z = {
|
|
2158
2187
|
base: new H(),
|
|
2159
|
-
svg: new
|
|
2188
|
+
svg: new F(),
|
|
2160
2189
|
html: new Y(),
|
|
2161
2190
|
audit: new tt()
|
|
2162
2191
|
};
|
|
2163
|
-
function Ot(
|
|
2164
|
-
const t = Object.assign({},
|
|
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);
|
|
2165
2194
|
let s;
|
|
2166
|
-
return r instanceof Y || r instanceof
|
|
2195
|
+
return r instanceof Y || r instanceof F || r instanceof tt || r instanceof H ? s = r : s = new F(), {
|
|
2167
2196
|
cpl: t.cpl || 48,
|
|
2168
2197
|
charWidth: t.charWidth || 12,
|
|
2169
2198
|
encoding: e,
|
|
@@ -2173,8 +2202,8 @@ function Ot(n) {
|
|
|
2173
2202
|
target: s
|
|
2174
2203
|
};
|
|
2175
2204
|
}
|
|
2176
|
-
function _t(
|
|
2177
|
-
const e =
|
|
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) => {
|
|
2178
2207
|
let s = {
|
|
2179
2208
|
align: 1,
|
|
2180
2209
|
wrap: t.wrap,
|
|
@@ -2182,16 +2211,16 @@ function _t(n, t) {
|
|
|
2182
2211
|
width: 0,
|
|
2183
2212
|
alignment: t.align
|
|
2184
2213
|
};
|
|
2185
|
-
const h =
|
|
2186
|
-
if (s.align = 1 + Number(/^[\t ]/.test(
|
|
2214
|
+
const h = n.replace(/^[\t ]+|[\t ]+$/g, "");
|
|
2215
|
+
if (s.align = 1 + Number(/^[\t ]/.test(n)) - Number(/[\t ]$/.test(n)), /^\{[^{}]*\}$/.test(h)) {
|
|
2187
2216
|
if (s.property = h.slice(1, -1).replace(/\\;/g, "\\x3b").split(";").reduce((o, c) => {
|
|
2188
|
-
const
|
|
2217
|
+
const d = { a: "align", b: "border", c: "code", i: "image", o: "option", t: "text", w: "width", x: "command", _: "comment" };
|
|
2189
2218
|
return /^[\t ]*$/.test(c) || c.replace(
|
|
2190
2219
|
/^[\t ]*([A-Za-z_]\w*)[\t ]*:[\t ]*([^\t ].*?)[\t ]*$/,
|
|
2191
|
-
(
|
|
2192
|
-
const f = g.replace(/^[abciotwx_]$/, ($) =>
|
|
2193
|
-
return o[f] =
|
|
2194
|
-
`)),
|
|
2220
|
+
(l, g, p) => {
|
|
2221
|
+
const f = g.replace(/^[abciotwx_]$/, ($) => d[$] || $);
|
|
2222
|
+
return o[f] = R(p.replace(/\\n/g, `
|
|
2223
|
+
`)), l;
|
|
2195
2224
|
}
|
|
2196
2225
|
) === c && (s.error = h), o;
|
|
2197
2226
|
}, {}), r.length === 1) {
|
|
@@ -2200,8 +2229,8 @@ function _t(n, t) {
|
|
|
2200
2229
|
t.wrap = !/^nowrap$/.test(o);
|
|
2201
2230
|
}
|
|
2202
2231
|
if ("border" in s.property && s.property.border) {
|
|
2203
|
-
const o = s.property.border.toLowerCase(), c = { line: -1, space: 1, none: 0 },
|
|
2204
|
-
t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1,
|
|
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 = "-");
|
|
2205
2234
|
}
|
|
2206
2235
|
if ("width" in s.property && s.property.width) {
|
|
2207
2236
|
const o = s.property.width.toLowerCase().split(/[\t ]+|,/);
|
|
@@ -2249,7 +2278,7 @@ function _t(n, t) {
|
|
|
2249
2278
|
s.hr = o === "-" || o === "=" ? o : void 0;
|
|
2250
2279
|
} else
|
|
2251
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, `
|
|
2252
|
-
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) =>
|
|
2281
|
+
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) => R(o));
|
|
2253
2282
|
if (s.wrap = t.wrap, s.border = t.border, t.width.length === 0)
|
|
2254
2283
|
s.width = -1;
|
|
2255
2284
|
else if ("text" in s)
|
|
@@ -2258,39 +2287,39 @@ function _t(n, t) {
|
|
|
2258
2287
|
s.width = -1;
|
|
2259
2288
|
else {
|
|
2260
2289
|
const o = t.width.filter((c) => c > 0);
|
|
2261
|
-
s.width = o.length > 0 ? o.reduce((c,
|
|
2290
|
+
s.width = o.length > 0 ? o.reduce((c, d) => c + d, s.border < 0 ? o.length + 1 : (o.length - 1) * s.border) : 0;
|
|
2262
2291
|
}
|
|
2263
2292
|
return s.alignment = t.align, s;
|
|
2264
2293
|
});
|
|
2265
|
-
if (e.every((
|
|
2294
|
+
if (e.every((n) => "text" in n) && t.width.length > 0)
|
|
2266
2295
|
for (; e.length < t.width.length; )
|
|
2267
2296
|
e.push({ align: 1, text: [""], wrap: t.wrap, border: t.border, width: t.width[e.length] ?? 0, alignment: t.align });
|
|
2268
2297
|
return e;
|
|
2269
2298
|
}
|
|
2270
|
-
function
|
|
2271
|
-
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)));
|
|
2272
2301
|
}
|
|
2273
|
-
function Gt(
|
|
2302
|
+
function Gt(i, t) {
|
|
2274
2303
|
const e = [];
|
|
2275
|
-
let
|
|
2276
|
-
return
|
|
2304
|
+
let n = i.width, a = 1, r = [], s = !1, h = !1, o = !1, c = 0;
|
|
2305
|
+
return i.text.forEach((d, u) => {
|
|
2277
2306
|
if (u % 2 === 0) {
|
|
2278
|
-
let
|
|
2279
|
-
for (;
|
|
2307
|
+
let l = t.target.arrayFrom(d, t.encoding);
|
|
2308
|
+
for (; l.length > 0; ) {
|
|
2280
2309
|
let g = 0, p = 0;
|
|
2281
|
-
for (; p <
|
|
2282
|
-
|
|
2283
|
-
if (p > 0 && (r.push((s ? "1" : "0") + (h ? "1" : "0") + (o ? "1" : "0") + c), r.push(
|
|
2284
|
-
|
|
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);
|
|
2285
2314
|
continue;
|
|
2286
2315
|
}
|
|
2287
|
-
(g >
|
|
2316
|
+
(g > n || n === 0) && (e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1);
|
|
2288
2317
|
}
|
|
2289
2318
|
} else
|
|
2290
|
-
switch (
|
|
2319
|
+
switch (d) {
|
|
2291
2320
|
case `
|
|
2292
2321
|
`:
|
|
2293
|
-
e.push({ data: r, margin:
|
|
2322
|
+
e.push({ data: r, margin: n * i.align / 2, height: a }), n = i.width, r = [], a = 1;
|
|
2294
2323
|
break;
|
|
2295
2324
|
case "_":
|
|
2296
2325
|
s = !s;
|
|
@@ -2302,65 +2331,65 @@ function Gt(n, t) {
|
|
|
2302
2331
|
o = !o;
|
|
2303
2332
|
break;
|
|
2304
2333
|
default:
|
|
2305
|
-
const
|
|
2306
|
-
c = c ===
|
|
2334
|
+
const l = Math.min(d.length, 7);
|
|
2335
|
+
c = c === l ? 0 : l;
|
|
2307
2336
|
break;
|
|
2308
2337
|
}
|
|
2309
|
-
}), r.length > 0 && e.push({ data: r, margin:
|
|
2338
|
+
}), r.length > 0 && e.push({ data: r, margin: n * i.align / 2, height: a }), e;
|
|
2310
2339
|
}
|
|
2311
|
-
async function Kt(
|
|
2312
|
-
const
|
|
2313
|
-
let s =
|
|
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);
|
|
2314
2343
|
a && (s = s.slice(0, Math.floor(r.border < 0 ? (t.target.cpl - 1) / 2 : (t.target.cpl + r.border) / (r.border + 1))));
|
|
2315
2344
|
const h = s.filter((f) => f.width > 0), o = s.filter((f) => f.width < 0);
|
|
2316
|
-
let c = h.reduce((f, $) => f + $.width, 0),
|
|
2317
|
-
a && s.length > 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);
|
|
2318
2347
|
const u = o.length;
|
|
2319
|
-
for (; u >
|
|
2320
|
-
const f = h.reduce(($,
|
|
2321
|
-
f.width--,
|
|
2348
|
+
for (; u > d; ) {
|
|
2349
|
+
const f = h.reduce(($, x) => $.width > x.width ? $ : x);
|
|
2350
|
+
f.width--, d++;
|
|
2322
2351
|
}
|
|
2323
|
-
u > 0 && (o.forEach((f, $) => f.width = Math.floor((
|
|
2324
|
-
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;
|
|
2325
2354
|
if (a) {
|
|
2326
2355
|
const f = s.map((w) => Gt(w, t)), $ = s.map((w) => w.width);
|
|
2327
2356
|
switch (e.line) {
|
|
2328
2357
|
case "ready":
|
|
2329
|
-
|
|
2330
|
-
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)
|
|
2331
2360
|
), e.line = "running";
|
|
2332
2361
|
break;
|
|
2333
2362
|
case "horizontal":
|
|
2334
|
-
const w =
|
|
2335
|
-
|
|
2336
|
-
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()
|
|
2337
2366
|
), e.line = "running";
|
|
2338
2367
|
break;
|
|
2339
2368
|
}
|
|
2340
|
-
e.rules = { left:
|
|
2341
|
-
const
|
|
2342
|
-
for (let w = 0; w <
|
|
2343
|
-
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;
|
|
2344
2373
|
if (e.line === "running") {
|
|
2345
|
-
const v = f.reduce((A,
|
|
2346
|
-
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);
|
|
2347
2376
|
}
|
|
2348
2377
|
for (let v = 0; v < f.length; v++) {
|
|
2349
2378
|
const A = f[v];
|
|
2350
2379
|
if (A) {
|
|
2351
|
-
if (m += await t.target.absolute(
|
|
2380
|
+
if (m += await t.target.absolute(k), w < A.length) {
|
|
2352
2381
|
m += await t.target.relative(A[w]?.margin ?? 0);
|
|
2353
|
-
const
|
|
2354
|
-
for (let S = 0; S <
|
|
2355
|
-
const D = Number(String(
|
|
2356
|
-
m += await t.target.normal(), D && (m += await t.target.ul()), et && (m += await t.target.em()),
|
|
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);
|
|
2357
2386
|
}
|
|
2358
2387
|
} else
|
|
2359
2388
|
m += await t.target.normal() + await t.target.text(" ", t.encoding);
|
|
2360
|
-
|
|
2389
|
+
k += (s[v]?.width ?? 0) + Math.abs(r.border);
|
|
2361
2390
|
}
|
|
2362
2391
|
}
|
|
2363
|
-
m += await t.target.lf(),
|
|
2392
|
+
m += await t.target.lf(), n.push(m);
|
|
2364
2393
|
}
|
|
2365
2394
|
}
|
|
2366
2395
|
if ("hr" in r)
|
|
@@ -2368,19 +2397,19 @@ async function Kt(n, t, e) {
|
|
|
2368
2397
|
switch (e.line) {
|
|
2369
2398
|
case "running":
|
|
2370
2399
|
case "horizontal":
|
|
2371
|
-
|
|
2400
|
+
n.push(
|
|
2372
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)
|
|
2373
|
-
),
|
|
2402
|
+
), n.push(await t.target.cut()), e.line = "ready";
|
|
2374
2403
|
break;
|
|
2375
2404
|
default:
|
|
2376
|
-
|
|
2405
|
+
n.push(await t.target.cut());
|
|
2377
2406
|
break;
|
|
2378
2407
|
}
|
|
2379
2408
|
else
|
|
2380
2409
|
switch (e.line) {
|
|
2381
2410
|
case "waiting":
|
|
2382
|
-
|
|
2383
|
-
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()
|
|
2384
2413
|
);
|
|
2385
2414
|
break;
|
|
2386
2415
|
case "running":
|
|
@@ -2397,26 +2426,26 @@ async function Kt(n, t, e) {
|
|
|
2397
2426
|
break;
|
|
2398
2427
|
case "running":
|
|
2399
2428
|
case "horizontal":
|
|
2400
|
-
|
|
2429
|
+
n.push(
|
|
2401
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)
|
|
2402
2431
|
), e.line = "waiting";
|
|
2403
2432
|
break;
|
|
2404
2433
|
}
|
|
2405
|
-
return "image" in r && r.image &&
|
|
2406
|
-
await t.target.normal() + await t.target.area(
|
|
2407
|
-
), "code" in r && r.code && (r.code.type === "qrcode" ?
|
|
2408
|
-
await t.target.normal() + await t.target.area(
|
|
2409
|
-
) :
|
|
2410
|
-
await t.target.normal() + await t.target.area(
|
|
2411
|
-
)), "command" in r && r.command &&
|
|
2412
|
-
await t.target.normal() + await t.target.area(
|
|
2413
|
-
),
|
|
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("");
|
|
2414
2443
|
}
|
|
2415
|
-
async function Yt(
|
|
2444
|
+
async function Yt(i, t) {
|
|
2416
2445
|
const e = Ot(t);
|
|
2417
2446
|
await e.target.lock();
|
|
2418
2447
|
try {
|
|
2419
|
-
const
|
|
2448
|
+
const n = {
|
|
2420
2449
|
wrap: !0,
|
|
2421
2450
|
border: 1,
|
|
2422
2451
|
width: [],
|
|
@@ -2426,19 +2455,19 @@ async function Yt(n, t) {
|
|
|
2426
2455
|
rules: { left: 0, width: 0, right: 0, widths: [] }
|
|
2427
2456
|
};
|
|
2428
2457
|
let a = await e.target.open(e);
|
|
2429
|
-
|
|
2430
|
-
const r =
|
|
2458
|
+
i[0] === "\uFEFF" && (i = i.slice(1));
|
|
2459
|
+
const r = i.normalize().split(/\n|\r\n|\r/), s = [];
|
|
2431
2460
|
for (const h of r)
|
|
2432
|
-
s.push(await Kt(_t(h,
|
|
2433
|
-
switch (
|
|
2461
|
+
s.push(await Kt(_t(h, n), e, n));
|
|
2462
|
+
switch (n.line) {
|
|
2434
2463
|
case "ready":
|
|
2435
|
-
|
|
2464
|
+
n.line = "waiting";
|
|
2436
2465
|
break;
|
|
2437
2466
|
case "running":
|
|
2438
2467
|
case "horizontal":
|
|
2439
2468
|
s.push(
|
|
2440
|
-
await e.target.normal() + await e.target.area(
|
|
2441
|
-
),
|
|
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";
|
|
2442
2471
|
break;
|
|
2443
2472
|
default:
|
|
2444
2473
|
break;
|
|
@@ -2456,6 +2485,6 @@ export {
|
|
|
2456
2485
|
tt as AuditTarget,
|
|
2457
2486
|
H as BaseTarget,
|
|
2458
2487
|
Y as HtmlTarget,
|
|
2459
|
-
|
|
2488
|
+
F as SvgTarget,
|
|
2460
2489
|
Yt as transform
|
|
2461
2490
|
};
|