@levischuck/receiptline 0.0.5 → 0.1.0
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/README.md +315 -278
- package/dist/index.d.ts +8 -5
- package/dist/index.js +1777 -444
- package/dist/parse.d.ts +1 -1
- package/dist/targets/audit.d.ts +157 -0
- package/dist/targets/base.d.ts +68 -48
- package/dist/targets/html.d.ts +72 -0
- package/dist/targets/index.d.ts +4 -0
- package/dist/targets/svg.d.ts +24 -24
- package/dist/types.d.ts +27 -24
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
|
-
import { decodeBase64 as
|
|
2
|
-
import { qrCode as
|
|
3
|
-
import { toSvgString as
|
|
4
|
-
class
|
|
1
|
+
import { decodeBase64 as it, encodeBase64 as V } from "@levischuck/tiny-encodings";
|
|
2
|
+
import { qrCode as O, EcLevel as C } from "@levischuck/tiny-qr";
|
|
3
|
+
import { toSvgString as nt } from "@levischuck/tiny-qr-svg";
|
|
4
|
+
class q {
|
|
5
|
+
locked = !1;
|
|
6
|
+
lockPromise = null;
|
|
7
|
+
lockResolve = null;
|
|
8
|
+
_cpl = 48;
|
|
9
|
+
/**
|
|
10
|
+
* Get characters per line.
|
|
11
|
+
* @returns {number} characters per line
|
|
12
|
+
*/
|
|
13
|
+
get cpl() {
|
|
14
|
+
return this._cpl;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lock the target for exclusive use.
|
|
18
|
+
* @param {number} [timeout] timeout in milliseconds (default: 5000)
|
|
19
|
+
* @returns {Promise<void>} resolves when lock is acquired
|
|
20
|
+
* @throws {Error} if timeout occurs
|
|
21
|
+
*/
|
|
22
|
+
async lock(t = 5e3) {
|
|
23
|
+
if (!this.locked) {
|
|
24
|
+
this.locked = !0, this.lockPromise = new Promise((a) => {
|
|
25
|
+
this.lockResolve = a;
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const e = new AbortController(), i = setTimeout(() => {
|
|
30
|
+
e.abort();
|
|
31
|
+
}, t);
|
|
32
|
+
try {
|
|
33
|
+
await Promise.race([
|
|
34
|
+
this.lockPromise,
|
|
35
|
+
new Promise((a, r) => {
|
|
36
|
+
e.signal.addEventListener("abort", () => {
|
|
37
|
+
r(new Error(`Lock timeout after ${t}ms`));
|
|
38
|
+
});
|
|
39
|
+
})
|
|
40
|
+
]);
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(i);
|
|
43
|
+
}
|
|
44
|
+
this.locked = !0, this.lockPromise = new Promise((a) => {
|
|
45
|
+
this.lockResolve = a;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Unlock the target.
|
|
50
|
+
*/
|
|
51
|
+
unlock() {
|
|
52
|
+
this.locked && this.lockResolve && (this.locked = !1, this.lockResolve(), this.lockResolve = null, this.lockPromise = null);
|
|
53
|
+
}
|
|
5
54
|
/**
|
|
6
55
|
* Measure text width.
|
|
7
56
|
* @param {string} text string to measure
|
|
8
57
|
* @param {string} encoding codepage
|
|
9
58
|
* @returns {number} string width
|
|
10
59
|
*/
|
|
11
|
-
measureText(t,
|
|
12
|
-
let
|
|
13
|
-
const
|
|
14
|
-
switch (
|
|
60
|
+
measureText(t, e) {
|
|
61
|
+
let i = 0;
|
|
62
|
+
const a = Array.from(t);
|
|
63
|
+
switch (e) {
|
|
15
64
|
case "cp932":
|
|
16
65
|
case "shiftjis":
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
return
|
|
66
|
+
i = a.reduce((n, h) => {
|
|
67
|
+
const o = h.codePointAt(0);
|
|
68
|
+
return o === void 0 ? n : n + (o < 128 || o === 160 || o === 165 || o === 8254 || o > 65376 && o < 65440 ? 1 : 2);
|
|
20
69
|
}, 0);
|
|
21
70
|
break;
|
|
22
71
|
case "cp936":
|
|
@@ -25,23 +74,23 @@ class F {
|
|
|
25
74
|
case "ksc5601":
|
|
26
75
|
case "cp950":
|
|
27
76
|
case "big5":
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
return
|
|
77
|
+
i = a.reduce((n, h) => {
|
|
78
|
+
const o = h.codePointAt(0);
|
|
79
|
+
return o === void 0 ? n : n + (o < 128 || o === 160 ? 1 : 2);
|
|
31
80
|
}, 0);
|
|
32
81
|
break;
|
|
33
82
|
case "tis620":
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
return
|
|
83
|
+
const r = a.reduce((n, h) => {
|
|
84
|
+
const o = h.codePointAt(0);
|
|
85
|
+
return o === void 0 || (n.consonant ? o === 3633 || o >= 3636 && o <= 3642 || o === 3655 ? n.vowel ? (n.length += 2, n.consonant = n.vowel = n.tone = !1) : n.vowel = !0 : o >= 3656 && o <= 3659 ? n.tone ? (n.length += 2, n.consonant = n.vowel = n.tone = !1) : n.tone = !0 : o === 3635 || o >= 3660 && o <= 3662 ? n.vowel || n.tone ? (n.length += 2, n.consonant = n.vowel = n.tone = !1) : (n.length += o === 3635 ? 2 : 1, n.consonant = !1) : o >= 3585 && o <= 3630 ? (n.length++, n.vowel = n.tone = !1) : (n.length += 2, n.consonant = n.vowel = n.tone = !1) : o >= 3585 && o <= 3630 ? n.consonant = !0 : n.length++), n;
|
|
37
86
|
}, { length: 0, consonant: !1, vowel: !1, tone: !1 });
|
|
38
|
-
|
|
87
|
+
r.consonant && (r.length++, r.consonant = r.vowel = r.tone = !1), i = r.length;
|
|
39
88
|
break;
|
|
40
89
|
default:
|
|
41
|
-
|
|
90
|
+
i = a.length;
|
|
42
91
|
break;
|
|
43
92
|
}
|
|
44
|
-
return
|
|
93
|
+
return i;
|
|
45
94
|
}
|
|
46
95
|
/**
|
|
47
96
|
* Create character array from string (supporting Thai combining characters).
|
|
@@ -49,35 +98,35 @@ class F {
|
|
|
49
98
|
* @param {string} encoding codepage
|
|
50
99
|
* @returns {string[]} array instance
|
|
51
100
|
*/
|
|
52
|
-
arrayFrom(t,
|
|
53
|
-
const
|
|
54
|
-
switch (
|
|
101
|
+
arrayFrom(t, e) {
|
|
102
|
+
const i = Array.from(t);
|
|
103
|
+
switch (e) {
|
|
55
104
|
case "cp932":
|
|
56
105
|
case "shiftjis":
|
|
57
|
-
return
|
|
106
|
+
return i.map((r) => r.replace(/\\/g, "¥").replace(/\u203e/g, "~").replace(/\u301c/g, "~"));
|
|
58
107
|
case "tis620":
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
return
|
|
108
|
+
const a = i.reduce((r, n) => {
|
|
109
|
+
const h = n.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, n), r.consonant = r.vowel = r.tone = "") : r.vowel = n : h >= 3656 && h <= 3659 ? r.tone ? (r.result.push(r.consonant + r.vowel + r.tone, n), r.consonant = r.vowel = r.tone = "") : r.tone = n : h === 3635 || h >= 3660 && h <= 3662 ? r.vowel || r.tone ? (r.result.push(r.consonant + r.vowel + r.tone, n), r.consonant = r.vowel = r.tone = "") : (r.result.push(r.consonant + n), r.consonant = "") : h >= 3585 && h <= 3630 ? (r.result.push(r.consonant + r.vowel + r.tone), r.consonant = n, r.vowel = r.tone = "") : (r.result.push(r.consonant + r.vowel + r.tone, n), r.consonant = r.vowel = r.tone = "") : h >= 3585 && h <= 3630 ? r.consonant = n : r.result.push(n)), r;
|
|
62
111
|
}, { result: [], consonant: "", vowel: "", tone: "" });
|
|
63
|
-
return
|
|
112
|
+
return a.consonant && (a.result.push(a.consonant + a.vowel + a.tone), a.consonant = a.vowel = a.tone = ""), a.result;
|
|
64
113
|
default:
|
|
65
|
-
return
|
|
114
|
+
return i;
|
|
66
115
|
}
|
|
67
116
|
}
|
|
68
117
|
/**
|
|
69
118
|
* Start printing.
|
|
70
119
|
* @param {object} printer printer configuration
|
|
71
|
-
* @returns {string} commands
|
|
120
|
+
* @returns {Promise<string>} commands
|
|
72
121
|
*/
|
|
73
|
-
open(t) {
|
|
74
|
-
return "";
|
|
122
|
+
async open(t) {
|
|
123
|
+
return this._cpl = t.cpl, "";
|
|
75
124
|
}
|
|
76
125
|
/**
|
|
77
126
|
* Finish printing.
|
|
78
|
-
* @returns {string} commands
|
|
127
|
+
* @returns {Promise<string>} commands
|
|
79
128
|
*/
|
|
80
|
-
close() {
|
|
129
|
+
async close() {
|
|
81
130
|
return "";
|
|
82
131
|
}
|
|
83
132
|
/**
|
|
@@ -85,66 +134,66 @@ class F {
|
|
|
85
134
|
* @param {number} left left margin (unit: characters)
|
|
86
135
|
* @param {number} width print area (unit: characters)
|
|
87
136
|
* @param {number} right right margin (unit: characters)
|
|
88
|
-
* @returns {string} commands
|
|
137
|
+
* @returns {Promise<string>} commands
|
|
89
138
|
*/
|
|
90
|
-
area(t,
|
|
139
|
+
async area(t, e, i) {
|
|
91
140
|
return "";
|
|
92
141
|
}
|
|
93
142
|
/**
|
|
94
143
|
* Set line alignment.
|
|
95
144
|
* @param {number} align line alignment (0: left, 1: center, 2: right)
|
|
96
|
-
* @returns {string} commands
|
|
145
|
+
* @returns {Promise<string>} commands
|
|
97
146
|
*/
|
|
98
|
-
align(t) {
|
|
147
|
+
async align(t) {
|
|
99
148
|
return "";
|
|
100
149
|
}
|
|
101
150
|
/**
|
|
102
151
|
* Set absolute print position.
|
|
103
152
|
* @param {number} position absolute position (unit: characters)
|
|
104
|
-
* @returns {string} commands
|
|
153
|
+
* @returns {Promise<string>} commands
|
|
105
154
|
*/
|
|
106
|
-
absolute(t) {
|
|
155
|
+
async absolute(t) {
|
|
107
156
|
return "";
|
|
108
157
|
}
|
|
109
158
|
/**
|
|
110
159
|
* Set relative print position.
|
|
111
160
|
* @param {number} position relative position (unit: characters)
|
|
112
|
-
* @returns {string} commands
|
|
161
|
+
* @returns {Promise<string>} commands
|
|
113
162
|
*/
|
|
114
|
-
relative(t) {
|
|
163
|
+
async relative(t) {
|
|
115
164
|
return "";
|
|
116
165
|
}
|
|
117
166
|
/**
|
|
118
167
|
* Print horizontal rule.
|
|
119
168
|
* @param {number} width line width (unit: characters)
|
|
120
|
-
* @returns {string} commands
|
|
169
|
+
* @returns {Promise<string>} commands
|
|
121
170
|
*/
|
|
122
|
-
hr(t) {
|
|
171
|
+
async hr(t) {
|
|
123
172
|
return "";
|
|
124
173
|
}
|
|
125
174
|
/**
|
|
126
175
|
* Print vertical rules.
|
|
127
176
|
* @param {number[]} widths vertical line spacing
|
|
128
177
|
* @param {number} height text height (1-6)
|
|
129
|
-
* @returns {string} commands
|
|
178
|
+
* @returns {Promise<string>} commands
|
|
130
179
|
*/
|
|
131
|
-
vr(t,
|
|
180
|
+
async vr(t, e) {
|
|
132
181
|
return "";
|
|
133
182
|
}
|
|
134
183
|
/**
|
|
135
184
|
* Start rules.
|
|
136
185
|
* @param {number[]} widths vertical line spacing
|
|
137
|
-
* @returns {string} commands
|
|
186
|
+
* @returns {Promise<string>} commands
|
|
138
187
|
*/
|
|
139
|
-
vrstart(t) {
|
|
188
|
+
async vrstart(t) {
|
|
140
189
|
return "";
|
|
141
190
|
}
|
|
142
191
|
/**
|
|
143
192
|
* Stop rules.
|
|
144
193
|
* @param {number[]} widths vertical line spacing
|
|
145
|
-
* @returns {string} commands
|
|
194
|
+
* @returns {Promise<string>} commands
|
|
146
195
|
*/
|
|
147
|
-
vrstop(t) {
|
|
196
|
+
async vrstop(t) {
|
|
148
197
|
return "";
|
|
149
198
|
}
|
|
150
199
|
/**
|
|
@@ -153,110 +202,110 @@ class F {
|
|
|
153
202
|
* @param {number[]} widths2 vertical line spacing (start)
|
|
154
203
|
* @param {number} dl difference in left position
|
|
155
204
|
* @param {number} dr difference in right position
|
|
156
|
-
* @returns {string} commands
|
|
205
|
+
* @returns {Promise<string>} commands
|
|
157
206
|
*/
|
|
158
|
-
vrhr(t,
|
|
207
|
+
async vrhr(t, e, i, a) {
|
|
159
208
|
return "";
|
|
160
209
|
}
|
|
161
210
|
/**
|
|
162
211
|
* Set line spacing and feed new line.
|
|
163
212
|
* @param {boolean} vr whether vertical ruled lines are printed
|
|
164
|
-
* @returns {string} commands
|
|
213
|
+
* @returns {Promise<string>} commands
|
|
165
214
|
*/
|
|
166
|
-
vrlf(t) {
|
|
215
|
+
async vrlf(t) {
|
|
167
216
|
return "";
|
|
168
217
|
}
|
|
169
218
|
/**
|
|
170
219
|
* Cut paper.
|
|
171
|
-
* @returns {string} commands
|
|
220
|
+
* @returns {Promise<string>} commands
|
|
172
221
|
*/
|
|
173
|
-
cut() {
|
|
222
|
+
async cut() {
|
|
174
223
|
return "";
|
|
175
224
|
}
|
|
176
225
|
/**
|
|
177
226
|
* Underline text.
|
|
178
|
-
* @returns {string} commands
|
|
227
|
+
* @returns {Promise<string>} commands
|
|
179
228
|
*/
|
|
180
|
-
ul() {
|
|
229
|
+
async ul() {
|
|
181
230
|
return "";
|
|
182
231
|
}
|
|
183
232
|
/**
|
|
184
233
|
* Emphasize text.
|
|
185
|
-
* @returns {string} commands
|
|
234
|
+
* @returns {Promise<string>} commands
|
|
186
235
|
*/
|
|
187
|
-
em() {
|
|
236
|
+
async em() {
|
|
188
237
|
return "";
|
|
189
238
|
}
|
|
190
239
|
/**
|
|
191
240
|
* Invert text.
|
|
192
|
-
* @returns {string} commands
|
|
241
|
+
* @returns {Promise<string>} commands
|
|
193
242
|
*/
|
|
194
|
-
iv() {
|
|
243
|
+
async iv() {
|
|
195
244
|
return "";
|
|
196
245
|
}
|
|
197
246
|
/**
|
|
198
247
|
* Scale up text.
|
|
199
248
|
* @param {number} wh number of special character '^' (1-7)
|
|
200
|
-
* @returns {string} commands
|
|
249
|
+
* @returns {Promise<string>} commands
|
|
201
250
|
*/
|
|
202
|
-
wh(t) {
|
|
251
|
+
async wh(t) {
|
|
203
252
|
return "";
|
|
204
253
|
}
|
|
205
254
|
/**
|
|
206
255
|
* Cancel text decoration.
|
|
207
|
-
* @returns {string} commands
|
|
256
|
+
* @returns {Promise<string>} commands
|
|
208
257
|
*/
|
|
209
|
-
normal() {
|
|
258
|
+
async normal() {
|
|
210
259
|
return "";
|
|
211
260
|
}
|
|
212
261
|
/**
|
|
213
262
|
* Print text.
|
|
214
263
|
* @param {string} text string to print
|
|
215
264
|
* @param {string} encoding codepage
|
|
216
|
-
* @returns {string} commands
|
|
265
|
+
* @returns {Promise<string>} commands
|
|
217
266
|
*/
|
|
218
|
-
text(t,
|
|
267
|
+
async text(t, e) {
|
|
219
268
|
return "";
|
|
220
269
|
}
|
|
221
270
|
/**
|
|
222
271
|
* Feed new line.
|
|
223
|
-
* @returns {string} commands
|
|
272
|
+
* @returns {Promise<string>} commands
|
|
224
273
|
*/
|
|
225
|
-
lf() {
|
|
274
|
+
async lf() {
|
|
226
275
|
return "";
|
|
227
276
|
}
|
|
228
277
|
/**
|
|
229
278
|
* Insert commands.
|
|
230
279
|
* @param {string} command commands to insert
|
|
231
|
-
* @returns {string} commands
|
|
280
|
+
* @returns {Promise<string>} commands
|
|
232
281
|
*/
|
|
233
|
-
command(t) {
|
|
282
|
+
async command(t) {
|
|
234
283
|
return "";
|
|
235
284
|
}
|
|
236
285
|
/**
|
|
237
286
|
* Print image.
|
|
238
287
|
* @param {string} image image data (base64 png format)
|
|
239
|
-
* @returns {string} commands
|
|
288
|
+
* @returns {Promise<string>} commands
|
|
240
289
|
*/
|
|
241
|
-
image(t) {
|
|
290
|
+
async image(t) {
|
|
242
291
|
return "";
|
|
243
292
|
}
|
|
244
293
|
/**
|
|
245
294
|
* Print QR Code.
|
|
246
295
|
* @param {object} symbol QR Code information (data, type, cell, level)
|
|
247
296
|
* @param {string} encoding codepage
|
|
248
|
-
* @returns {string} commands
|
|
297
|
+
* @returns {Promise<string>} commands
|
|
249
298
|
*/
|
|
250
|
-
qrcode(t,
|
|
299
|
+
async qrcode(t, e) {
|
|
251
300
|
return "";
|
|
252
301
|
}
|
|
253
302
|
/**
|
|
254
303
|
* Print barcode.
|
|
255
304
|
* @param {object} symbol barcode information (data, type, width, height, hri)
|
|
256
305
|
* @param {string} encoding codepage
|
|
257
|
-
* @returns {string} commands
|
|
306
|
+
* @returns {Promise<string>} commands
|
|
258
307
|
*/
|
|
259
|
-
barcode(t,
|
|
308
|
+
async barcode(t, e) {
|
|
260
309
|
return "";
|
|
261
310
|
}
|
|
262
311
|
calculatedWidth() {
|
|
@@ -266,7 +315,7 @@ class F {
|
|
|
266
315
|
return 0;
|
|
267
316
|
}
|
|
268
317
|
}
|
|
269
|
-
const
|
|
318
|
+
const v = {
|
|
270
319
|
element: "212222,222122,222221,121223,121322,131222,122213,122312,132212,221213,221312,231212,112232,122132,122231,113222,123122,123221,223211,221132,221231,213212,223112,312131,311222,321122,321221,312212,322112,322211,212123,212321,232121,111323,131123,131321,112313,132113,132311,211313,231113,231311,112133,112331,132131,113123,113321,133121,313121,211331,231131,213113,213311,213131,311123,311321,331121,312113,312311,332111,314111,221411,431111,111224,111422,121124,121421,141122,141221,112214,112412,122114,122411,142112,142211,241211,221114,413111,241112,134111,111242,121142,121241,114212,124112,124211,411212,421112,421211,212141,214121,412121,111143,111341,131141,114113,114311,411113,411311,113141,114131,311141,411131,211412,211214,211232,2331112".split(","),
|
|
271
320
|
starta: 103,
|
|
272
321
|
startb: 104,
|
|
@@ -280,53 +329,53 @@ const f = {
|
|
|
280
329
|
shift: 98,
|
|
281
330
|
stop: 106
|
|
282
331
|
};
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
/^\d{4,}/.test(t) ?
|
|
287
|
-
}
|
|
288
|
-
function
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
/^\d{4,}/.test(t) ?
|
|
292
|
-
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
function
|
|
332
|
+
function P(s, t, e) {
|
|
333
|
+
s !== v.shift && e.push(s), t = t.replace(/^((?!\d{4,})[\x00-_])+/, (r) => (r.split("").forEach((n) => e.push((n.charCodeAt(0) + 64) % 96)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push((r.charCodeAt(0) + 64) % 96), ""));
|
|
334
|
+
const i = t.slice(1), a = i.search(/[^ -_]/);
|
|
335
|
+
/^\d{4,}/.test(t) ? T(v.atoc, t, e) : a >= 0 && i.charCodeAt(a) < 32 ? (e.push(v.shift, t.charCodeAt(0) - 32), P(v.shift, i, e)) : t.length > 0 && U(v.atob, t, e);
|
|
336
|
+
}
|
|
337
|
+
function U(s, t, e) {
|
|
338
|
+
s !== v.shift && e.push(s), t = t.replace(/^((?!\d{4,})[ -\x7f])+/, (r) => (r.split("").forEach((n) => e.push(n.charCodeAt(0) - 32)), "")), t = t.replace(/^\d(?=(\d\d){2,}(\D|$))/, (r) => (e.push(r.charCodeAt(0) - 32), ""));
|
|
339
|
+
const i = t.slice(1), a = i.search(/[^ -_]/);
|
|
340
|
+
/^\d{4,}/.test(t) ? T(v.btoc, t, e) : a >= 0 && i.charCodeAt(a) > 95 ? (e.push(v.shift, t.charCodeAt(0) + 64), U(v.shift, i, e)) : t.length > 0 && P(v.btoa, t, e);
|
|
341
|
+
}
|
|
342
|
+
function T(s, t, e) {
|
|
343
|
+
s !== v.shift && e.push(s), t = t.replace(/^\d{4,}/g, (a) => a.replace(/\d{2}/g, (r) => (e.push(Number(r)), "")));
|
|
344
|
+
const i = t.search(/[^ -_]/);
|
|
345
|
+
i >= 0 && t.charCodeAt(i) < 32 ? P(v.ctoa, t, e) : t.length > 0 && U(v.ctob, t, e);
|
|
346
|
+
}
|
|
347
|
+
function st(s) {
|
|
299
348
|
const t = {};
|
|
300
|
-
let
|
|
301
|
-
if (
|
|
302
|
-
t.hri =
|
|
303
|
-
const
|
|
304
|
-
/^\d{2}$/.test(
|
|
305
|
-
const
|
|
306
|
-
t.widths =
|
|
349
|
+
let e = s.data.replace(/((?!^[\x00-\x7f]+$).)*/, "");
|
|
350
|
+
if (e.length > 0) {
|
|
351
|
+
t.hri = s.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
|
|
352
|
+
const i = [], a = e.search(/[^ -_]/);
|
|
353
|
+
/^\d{2}$/.test(e) ? i.push(v.startc, Number(e)) : /^\d{4,}/.test(e) ? T(v.startc, e, i) : a >= 0 && e.charCodeAt(a) < 32 ? P(v.starta, e, i) : e.length > 0 && U(v.startb, e, i), i.push(i.reduce((h, o, c) => h + o * c) % 103, v.stop);
|
|
354
|
+
const r = s.quietZone ? "a" : "0", n = i.reduce((h, o) => h + v.element[o], r) + r;
|
|
355
|
+
t.widths = n.split("").map((h) => parseInt(h, 16) * s.width), t.length = s.width * (i.length * 11 + (s.quietZone ? 22 : 2)), t.height = s.height;
|
|
307
356
|
}
|
|
308
357
|
return t;
|
|
309
358
|
}
|
|
310
|
-
const
|
|
359
|
+
const M = {
|
|
311
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(","),
|
|
312
|
-
code: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%dcsp".split("").reduce((
|
|
361
|
+
code: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%dcsp".split("").reduce((s, t, e) => (s[t] = e, s), {}),
|
|
313
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(","),
|
|
314
363
|
start: 47,
|
|
315
364
|
stop: 48
|
|
316
365
|
};
|
|
317
|
-
function
|
|
366
|
+
function rt(s) {
|
|
318
367
|
const t = {};
|
|
319
|
-
let
|
|
320
|
-
if (
|
|
321
|
-
t.hri =
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
t.widths =
|
|
368
|
+
let e = s.data.replace(/((?!^[\x00-\x7f]+$).)*/, "");
|
|
369
|
+
if (e.length > 0) {
|
|
370
|
+
t.hri = s.hri, t.text = e.replace(/[\x00- \x7f]/g, " ");
|
|
371
|
+
const i = e.split("").reduce((n, h) => n + M.escape[h.charCodeAt(0)], "").split("").map((n) => M.code[n]);
|
|
372
|
+
i.push(i.reduceRight((n, h, o) => n + h * ((i.length - 1 - o) % 20 + 1)) % 47), i.push(i.reduceRight((n, h, o) => n + h * ((i.length - 1 - o) % 15 + 1)) % 47), i.unshift(M.start), i.push(M.stop);
|
|
373
|
+
const a = s.quietZone ? "a" : "0", r = i.reduce((n, h) => n + M.element[h], a) + a;
|
|
374
|
+
t.widths = r.split("").map((n) => parseInt(n, 16) * s.width), t.length = s.width * (i.length * 9 + (s.quietZone ? 21 : 1)), t.height = s.height;
|
|
326
375
|
}
|
|
327
376
|
return t;
|
|
328
377
|
}
|
|
329
|
-
const
|
|
378
|
+
const at = {
|
|
330
379
|
0: "2222255",
|
|
331
380
|
1: "2222552",
|
|
332
381
|
2: "2225225",
|
|
@@ -348,41 +397,41 @@ const V = {
|
|
|
348
397
|
C: "2225255",
|
|
349
398
|
D: "2225552"
|
|
350
399
|
};
|
|
351
|
-
function
|
|
400
|
+
function ot(s) {
|
|
352
401
|
const t = {};
|
|
353
|
-
let
|
|
354
|
-
if (
|
|
355
|
-
t.hri =
|
|
356
|
-
const
|
|
357
|
-
t.widths =
|
|
358
|
-
const
|
|
359
|
-
t.length =
|
|
402
|
+
let e = s.data.replace(/((?!^[A-D][0-9\-$:/.+]+[A-D]$).)*/i, "");
|
|
403
|
+
if (e.length > 0) {
|
|
404
|
+
t.hri = s.hri, t.text = e;
|
|
405
|
+
const i = s.quietZone ? "a" : "0", a = e.toUpperCase().split("").reduce((n, h) => n + at[h] + "2", i).slice(0, -1) + i;
|
|
406
|
+
t.widths = a.split("").map((n) => parseInt(n, 16) * s.width + 1 >> 1);
|
|
407
|
+
const r = [25, 39, 50, 3, 5, 6];
|
|
408
|
+
t.length = e.length * r[s.width - 2] - (e.match(/[\d\-$]/g) || []).length * r[s.width + 1] + s.width * (s.quietZone ? 19 : -1), t.height = s.height;
|
|
360
409
|
}
|
|
361
410
|
return t;
|
|
362
411
|
}
|
|
363
|
-
const
|
|
412
|
+
const H = {
|
|
364
413
|
element: "22552,52225,25225,55222,22525,52522,25522,22255,52252,25252".split(","),
|
|
365
414
|
start: "2222",
|
|
366
415
|
stop: "522"
|
|
367
416
|
};
|
|
368
|
-
function
|
|
417
|
+
function ht(s) {
|
|
369
418
|
const t = {};
|
|
370
|
-
let
|
|
371
|
-
if (
|
|
372
|
-
t.hri =
|
|
373
|
-
const
|
|
374
|
-
let
|
|
375
|
-
for (;
|
|
376
|
-
const
|
|
377
|
-
|
|
419
|
+
let e = s.data.replace(/((?!^(\d{2})+$).)*/, "");
|
|
420
|
+
if (e.length > 0) {
|
|
421
|
+
t.hri = s.hri, t.text = e;
|
|
422
|
+
const i = e.split("").map((o) => Number(o)), a = s.quietZone ? "a" : "0";
|
|
423
|
+
let r = a + H.start, n = 0;
|
|
424
|
+
for (; n < i.length; ) {
|
|
425
|
+
const o = H.element[i[n++]], c = H.element[i[n++]];
|
|
426
|
+
r += o.split("").reduce((l, p, d) => l + p + c[d], "");
|
|
378
427
|
}
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
t.length =
|
|
428
|
+
r += H.stop + a, t.widths = r.split("").map((o) => parseInt(o, 16) * s.width + 1 >> 1);
|
|
429
|
+
const h = [16, 25, 32, 17, 26, 34];
|
|
430
|
+
t.length = e.length * h[s.width - 2] + h[s.width + 1] + s.width * (s.quietZone ? 20 : 0), t.height = s.height;
|
|
382
431
|
}
|
|
383
432
|
return t;
|
|
384
433
|
}
|
|
385
|
-
const
|
|
434
|
+
const ct = {
|
|
386
435
|
0: "222552522",
|
|
387
436
|
1: "522522225",
|
|
388
437
|
2: "225522225",
|
|
@@ -428,19 +477,19 @@ const Y = {
|
|
|
428
477
|
"%": "222525252",
|
|
429
478
|
"*": "252252522"
|
|
430
479
|
};
|
|
431
|
-
function
|
|
480
|
+
function lt(s) {
|
|
432
481
|
const t = {};
|
|
433
|
-
let
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
t.widths =
|
|
438
|
-
const
|
|
439
|
-
t.length =
|
|
482
|
+
let e = s.data.replace(/((?!^\*?[0-9A-Z\-. $/+%]+\*?$).)*/, "");
|
|
483
|
+
if (e.length > 0) {
|
|
484
|
+
e = e.replace(/^\*?([^*]+)\*?$/, "*$1*"), t.hri = s.hri, t.text = e;
|
|
485
|
+
const i = s.quietZone ? "a" : "0", a = e.split("").reduce((n, h) => n + ct[h] + "2", i).slice(0, -1) + i;
|
|
486
|
+
t.widths = a.split("").map((n) => parseInt(n, 16) * s.width + 1 >> 1);
|
|
487
|
+
const r = [29, 45, 58];
|
|
488
|
+
t.length = e.length * r[s.width - 2] + s.width * (s.quietZone ? 19 : -1), t.height = s.height;
|
|
440
489
|
}
|
|
441
490
|
return t;
|
|
442
491
|
}
|
|
443
|
-
const
|
|
492
|
+
const b = {
|
|
444
493
|
a: "3211,2221,2122,1411,1132,1231,1114,1312,1213,3112".split(","),
|
|
445
494
|
b: "1123,1222,2212,1141,2311,1321,4111,2131,3121,2113".split(","),
|
|
446
495
|
c: "3211,2221,2122,1411,1132,1231,1114,1312,1213,3112".split(","),
|
|
@@ -448,102 +497,102 @@ const m = {
|
|
|
448
497
|
p: "aaaaaa,aababb,aabbab,aabbba,abaabb,abbaab,abbbaa,ababab,ababba,abbaba".split(","),
|
|
449
498
|
e: "bbbaaa,bbabaa,bbaaba,bbaaab,babbaa,baabba,baaabb,bababa,babaab,baabab".split(",")
|
|
450
499
|
};
|
|
451
|
-
function
|
|
452
|
-
const t =
|
|
453
|
-
switch (
|
|
500
|
+
function dt(s) {
|
|
501
|
+
const t = s.slice(0, 3);
|
|
502
|
+
switch (s[6]) {
|
|
454
503
|
case 0:
|
|
455
504
|
case 1:
|
|
456
505
|
case 2:
|
|
457
|
-
t.push(
|
|
506
|
+
t.push(s[6], 0, 0, 0, 0, s[3], s[4], s[5]);
|
|
458
507
|
break;
|
|
459
508
|
case 3:
|
|
460
|
-
t.push(
|
|
509
|
+
t.push(s[3], 0, 0, 0, 0, 0, s[4], s[5]);
|
|
461
510
|
break;
|
|
462
511
|
case 4:
|
|
463
|
-
t.push(
|
|
512
|
+
t.push(s[3], s[4], 0, 0, 0, 0, 0, s[5]);
|
|
464
513
|
break;
|
|
465
514
|
default:
|
|
466
|
-
t.push(
|
|
515
|
+
t.push(s[3], s[4], s[5], 0, 0, 0, 0, s[6]);
|
|
467
516
|
break;
|
|
468
517
|
}
|
|
469
|
-
return t.push(
|
|
518
|
+
return t.push(s[7]), t;
|
|
470
519
|
}
|
|
471
|
-
function
|
|
472
|
-
const t = {},
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
let
|
|
476
|
-
for (let
|
|
477
|
-
|
|
478
|
-
for (let
|
|
479
|
-
|
|
520
|
+
function _(s) {
|
|
521
|
+
const t = {}, e = s.data.replace(/((?!^\d{12,13}$).)*/, "").split("").map((i) => Number(i));
|
|
522
|
+
if (e.length > 0) {
|
|
523
|
+
e[12] = 0, e[12] = (10 - e.reduce((a, r, n) => a + r * (n % 2 * 2 + 1)) % 10) % 10, t.hri = s.hri, t.text = e.join("");
|
|
524
|
+
let i = (s.quietZone ? "b" : "0") + b.g[0];
|
|
525
|
+
for (let a = 1; a < 7; a++) i += b[b.p[e[0]][a - 1]][e[a]];
|
|
526
|
+
i += b.g[1];
|
|
527
|
+
for (let a = 7; a < 13; a++) i += b.c[e[a]];
|
|
528
|
+
i += b.g[0] + (s.quietZone ? "7" : "0"), t.widths = i.split("").map((a) => parseInt(a, 16) * s.width), t.length = s.width * (s.quietZone ? 113 : 95), t.height = s.height;
|
|
480
529
|
}
|
|
481
530
|
return t;
|
|
482
531
|
}
|
|
483
|
-
function
|
|
484
|
-
const t = {},
|
|
485
|
-
if (
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
let
|
|
489
|
-
for (let
|
|
490
|
-
|
|
491
|
-
for (let
|
|
492
|
-
|
|
532
|
+
function gt(s) {
|
|
533
|
+
const t = {}, e = s.data.replace(/((?!^\d{7,8}$).)*/, "").split("").map((i) => Number(i));
|
|
534
|
+
if (e.length > 0) {
|
|
535
|
+
e[7] = 0, e[7] = (10 - e.reduce((r, n, h) => r + n * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = s.hri, t.text = e.join("");
|
|
536
|
+
const i = s.quietZone ? "7" : "0";
|
|
537
|
+
let a = i + b.g[0];
|
|
538
|
+
for (let r = 0; r < 4; r++) a += b.a[e[r] ?? 0];
|
|
539
|
+
a += b.g[1];
|
|
540
|
+
for (let r = 4; r < 8; r++) a += b.c[e[r] ?? 0];
|
|
541
|
+
a += b.g[0] + i, t.widths = a.split("").map((r) => parseInt(r, 16) * s.width), t.length = s.width * (s.quietZone ? 81 : 67), t.height = s.height;
|
|
493
542
|
}
|
|
494
543
|
return t;
|
|
495
544
|
}
|
|
496
|
-
function
|
|
545
|
+
function pt(s) {
|
|
497
546
|
const t = {
|
|
498
|
-
data: "0" +
|
|
499
|
-
hri:
|
|
500
|
-
width:
|
|
501
|
-
height:
|
|
502
|
-
quietZone:
|
|
503
|
-
},
|
|
504
|
-
return
|
|
505
|
-
}
|
|
506
|
-
function
|
|
507
|
-
const t = {},
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
let
|
|
512
|
-
for (let
|
|
513
|
-
|
|
547
|
+
data: "0" + s.data,
|
|
548
|
+
hri: s.hri,
|
|
549
|
+
width: s.width,
|
|
550
|
+
height: s.height,
|
|
551
|
+
quietZone: s.quietZone
|
|
552
|
+
}, e = _(t);
|
|
553
|
+
return e.text && (e.text = e.text.slice(1)), e;
|
|
554
|
+
}
|
|
555
|
+
function ut(s) {
|
|
556
|
+
const t = {}, e = s.data.replace(/((?!^0\d{6,7}$).)*/, "").split("").map((i) => Number(i));
|
|
557
|
+
if (e.length > 0) {
|
|
558
|
+
e[7] = 0, e[7] = (10 - dt(e).reduce((r, n, h) => r + n * (3 - h % 2 * 2), 0) % 10) % 10, t.hri = s.hri, t.text = e.join("");
|
|
559
|
+
const i = s.quietZone ? "7" : "0";
|
|
560
|
+
let a = i + 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] + i, t.widths = a.split("").map((r) => parseInt(r, 16) * s.width), t.length = s.width * (s.quietZone ? 65 : 51), t.height = s.height;
|
|
514
563
|
}
|
|
515
564
|
return t;
|
|
516
565
|
}
|
|
517
|
-
function
|
|
566
|
+
function G(s) {
|
|
518
567
|
let t = {};
|
|
519
|
-
switch (
|
|
568
|
+
switch (s.type) {
|
|
520
569
|
case "upc":
|
|
521
|
-
t =
|
|
570
|
+
t = s.data.length < 9 ? ut(s) : pt(s);
|
|
522
571
|
break;
|
|
523
572
|
case "ean":
|
|
524
573
|
case "jan":
|
|
525
|
-
t =
|
|
574
|
+
t = s.data.length < 9 ? gt(s) : _(s);
|
|
526
575
|
break;
|
|
527
576
|
case "code39":
|
|
528
|
-
t =
|
|
577
|
+
t = lt(s);
|
|
529
578
|
break;
|
|
530
579
|
case "itf":
|
|
531
|
-
t =
|
|
580
|
+
t = ht(s);
|
|
532
581
|
break;
|
|
533
582
|
case "codabar":
|
|
534
583
|
case "nw7":
|
|
535
|
-
t =
|
|
584
|
+
t = ot(s);
|
|
536
585
|
break;
|
|
537
586
|
case "code93":
|
|
538
|
-
t =
|
|
587
|
+
t = rt(s);
|
|
539
588
|
break;
|
|
540
589
|
case "code128":
|
|
541
|
-
t =
|
|
590
|
+
t = st(s);
|
|
542
591
|
break;
|
|
543
592
|
}
|
|
544
593
|
return t;
|
|
545
594
|
}
|
|
546
|
-
class E extends
|
|
595
|
+
class E extends q {
|
|
547
596
|
charWidth = 12;
|
|
548
597
|
receiptId = "";
|
|
549
598
|
svgWidth = 576;
|
|
@@ -564,14 +613,14 @@ class E extends F {
|
|
|
564
613
|
defaultFont = "monospace";
|
|
565
614
|
fontSize = 12;
|
|
566
615
|
// start printing:
|
|
567
|
-
open(t) {
|
|
568
|
-
return this.receiptId = crypto.randomUUID(), this.charWidth = t.charWidth, this.svgWidth =
|
|
616
|
+
async open(t) {
|
|
617
|
+
return await super.open(t), this.receiptId = crypto.randomUUID(), this.charWidth = t.charWidth, this.svgWidth = this.cpl * t.charWidth, this.svgHeight = 0, this.svgContent = "", this.lineMargin = 0, this.lineAlign = 0, this.lineWidth = this.cpl, this.lineHeight = 1, this.textElement = "", this.textAttributes = {}, this.textPosition = 0, this.textScale = 1, this.textEncoding = t.encoding, this.feedMinimum = Number(t.charWidth * (t.spacing ? 2.5 : 2)), this.spacing = t.spacing, "";
|
|
569
618
|
}
|
|
570
619
|
setDefaultFont(t) {
|
|
571
620
|
return this.defaultFont = t, "'Courier Prime'";
|
|
572
621
|
}
|
|
573
622
|
// finish printing:
|
|
574
|
-
close() {
|
|
623
|
+
async close() {
|
|
575
624
|
const t = { font: "monospace", size: this.charWidth * 2, style: "", lang: "" };
|
|
576
625
|
switch (this.textEncoding) {
|
|
577
626
|
case "cp932":
|
|
@@ -598,132 +647,132 @@ class E extends F {
|
|
|
598
647
|
break;
|
|
599
648
|
}
|
|
600
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;
|
|
601
|
-
const
|
|
602
|
-
return `<svg width="${
|
|
650
|
+
const e = this.calculatedWidth(), i = this.calculatedHeight();
|
|
651
|
+
return `<svg width="${e}px" height="${i}px" viewBox="0 0 ${e} ${i}" 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>
|
|
603
652
|
`;
|
|
604
653
|
}
|
|
605
654
|
// set print area:
|
|
606
|
-
area(t,
|
|
607
|
-
return this.lineMargin = t, this.lineWidth =
|
|
655
|
+
async area(t, e, i) {
|
|
656
|
+
return this.lineMargin = t, this.lineWidth = e, "";
|
|
608
657
|
}
|
|
609
658
|
// set line alignment:
|
|
610
|
-
align(t) {
|
|
659
|
+
async align(t) {
|
|
611
660
|
return this.lineAlign = t, "";
|
|
612
661
|
}
|
|
613
662
|
// set absolute print position:
|
|
614
|
-
absolute(t) {
|
|
663
|
+
async absolute(t) {
|
|
615
664
|
return this.textPosition = t, "";
|
|
616
665
|
}
|
|
617
666
|
// set relative print position:
|
|
618
|
-
relative(t) {
|
|
667
|
+
async relative(t) {
|
|
619
668
|
return this.textPosition += t, "";
|
|
620
669
|
}
|
|
621
670
|
// print horizontal rule:
|
|
622
|
-
hr(t) {
|
|
623
|
-
const
|
|
624
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin *
|
|
671
|
+
async hr(t) {
|
|
672
|
+
const e = this.charWidth, i = `<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})">${i}</g>`, "";
|
|
625
674
|
}
|
|
626
675
|
// print vertical rules:
|
|
627
|
-
vr(t,
|
|
628
|
-
const
|
|
629
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin *
|
|
676
|
+
async vr(t, e) {
|
|
677
|
+
const i = this.charWidth, a = i / 2, r = (i + i) * e, n = '<path d="' + t.reduce((h, o) => h + `m${i * o + i},${-r}v${r}`, `M${a},0v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
678
|
+
return this.svgContent += `<g transform="translate(${this.lineMargin * i},${this.svgHeight})">${n}</g>`, "";
|
|
630
679
|
}
|
|
631
680
|
// start rules:
|
|
632
|
-
vrstart(t) {
|
|
633
|
-
const
|
|
634
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin *
|
|
681
|
+
async vrstart(t) {
|
|
682
|
+
const e = this.charWidth, i = e / 2, a = '<path d="' + t.reduce((r, n) => r + `h${e * n}h${i}v${e}m0,${-e}h${i}`, `M${i},${e + e}v${-i}q0,${-i},${i},${-i}`).replace(/h\d+v\d+m0,-\d+h\d+$/, `q${i},0,${i},${i}v${i}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
683
|
+
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${a}</g>`, "";
|
|
635
684
|
}
|
|
636
685
|
// stop rules:
|
|
637
|
-
vrstop(t) {
|
|
638
|
-
const
|
|
639
|
-
return this.svgContent += `<g transform="translate(${this.lineMargin *
|
|
686
|
+
async vrstop(t) {
|
|
687
|
+
const e = this.charWidth, i = e / 2, a = '<path d="' + t.reduce((r, n) => r + `h${e * n}h${i}v${-e}m0,${e}h${i}`, `M${i},0v${i}q0,${i},${i},${i}`).replace(/h\d+v-\d+m0,\d+h\d+$/, `q${i},0,${i},${-i}v${-i}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
688
|
+
return this.svgContent += `<g transform="translate(${this.lineMargin * e},${this.svgHeight})">${a}</g>`, "";
|
|
640
689
|
}
|
|
641
690
|
// print vertical and horizontal rules:
|
|
642
|
-
vrhr(t,
|
|
643
|
-
const
|
|
644
|
-
this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(-
|
|
645
|
-
const
|
|
646
|
-
return this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(
|
|
691
|
+
async vrhr(t, e, i, a) {
|
|
692
|
+
const r = this.charWidth, n = r / 2, h = '<path d="' + t.reduce((c, l) => c + `h${r * l}h${n}v${-r}m0,${r}h${n}`, `M${n},0` + (i > 0 ? `v${n}q0,${n},${n},${n}` : `v${r}h${n}`)).replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${n},0,${n},${-n}v${-n}` : `h${n}v${-r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
693
|
+
this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(-i, 0)) * r},${this.svgHeight})">${h}</g>`;
|
|
694
|
+
const o = '<path d="' + e.reduce((c, l) => c + `h${r * l}h${n}v${r}m0,${-r}h${n}`, `M${n},${r + r}` + (i < 0 ? `v${-n}q0,${-n},${n},${-n}` : `v${-r}h${n}`)).replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${n},0,${n},${n}v${n}` : `h${n}v${r}`) + '" fill="none" stroke="#000" stroke-width="2"/>';
|
|
695
|
+
return this.svgContent += `<g transform="translate(${(this.lineMargin + Math.max(i, 0)) * r},${this.svgHeight})">${o}</g>`, "";
|
|
647
696
|
}
|
|
648
697
|
// set line spacing and feed new line:
|
|
649
|
-
vrlf(t) {
|
|
650
|
-
return this.feedMinimum = Number(this.charWidth * (!t && this.spacing ? 2.5 : 2)), this.lf();
|
|
698
|
+
async vrlf(t) {
|
|
699
|
+
return this.feedMinimum = Number(this.charWidth * (!t && this.spacing ? 2.5 : 2)), await this.lf();
|
|
651
700
|
}
|
|
652
701
|
// cut paper:
|
|
653
|
-
cut() {
|
|
702
|
+
async cut() {
|
|
654
703
|
const t = `<path d="M12,12.5l-7.5,-3a2,2,0,1,1,.5,0M12,11.5l-7.5,3a2,2,0,1,0,.5,0" fill="none" stroke="#000" stroke-width="1"/><path d="M12,12l10,-4q-1,-1,-2.5,-1l-10,4v2l10,4q1.5,0,2.5,-1z" fill="#000"/><path d="M24,12h${this.svgWidth - 24}" fill="none" stroke="#000" stroke-width="2" stroke-dasharray="2"/>`;
|
|
655
|
-
return this.svgContent += `<g transform="translate(0,${this.svgHeight})">${t}</g>`, this.lf();
|
|
704
|
+
return this.svgContent += `<g transform="translate(0,${this.svgHeight})">${t}</g>`, await this.lf();
|
|
656
705
|
}
|
|
657
706
|
// underline text:
|
|
658
|
-
ul() {
|
|
707
|
+
async ul() {
|
|
659
708
|
return this.textAttributes["text-decoration"] = "underline", "";
|
|
660
709
|
}
|
|
661
710
|
// emphasize text:
|
|
662
|
-
em() {
|
|
711
|
+
async em() {
|
|
663
712
|
return this.textAttributes.stroke = "#000", "";
|
|
664
713
|
}
|
|
665
714
|
// invert text:
|
|
666
|
-
iv() {
|
|
715
|
+
async iv() {
|
|
667
716
|
return this.textAttributes.filter = `url(#receipt-${this.receiptId})`, "";
|
|
668
717
|
}
|
|
669
718
|
// scale up text:
|
|
670
|
-
wh(t) {
|
|
671
|
-
const
|
|
672
|
-
return this.textAttributes.transform = `scale(${
|
|
719
|
+
async wh(t) {
|
|
720
|
+
const e = t < 2 ? t + 1 : t - 1, i = t < 3 ? t : t - 1;
|
|
721
|
+
return this.textAttributes.transform = `scale(${e},${i})`, this.lineHeight = Math.max(this.lineHeight, i), this.textScale = e, "";
|
|
673
722
|
}
|
|
674
723
|
// cancel text decoration:
|
|
675
|
-
normal() {
|
|
724
|
+
async normal() {
|
|
676
725
|
return this.textAttributes = {}, this.textScale = 1, "";
|
|
677
726
|
}
|
|
678
727
|
// print text:
|
|
679
|
-
text(t,
|
|
680
|
-
let
|
|
681
|
-
const
|
|
682
|
-
const
|
|
683
|
-
return
|
|
684
|
-
}, ""),
|
|
685
|
-
return this.textElement += `<text${
|
|
728
|
+
async text(t, e) {
|
|
729
|
+
let i = this.textPosition;
|
|
730
|
+
const a = this.arrayFrom(t, e).reduce((n, h) => {
|
|
731
|
+
const o = this.measureText(h, e) * this.textScale, c = Math.floor((i + o / 2) * this.charWidth / this.textScale);
|
|
732
|
+
return i += o, n + `<tspan x="${c}">${h.replace(/[ &<>]/g, (l) => ({ " ": " ", "&": "&", "<": "<", ">": ">" })[l] || l)}</tspan>`;
|
|
733
|
+
}, ""), r = Object.keys(this.textAttributes).reduce((n, h) => n + ` ${h}="${this.textAttributes[h]}"`, "");
|
|
734
|
+
return this.textElement += `<text${r}>${a}</text>`, this.textPosition += this.measureText(t, e) * this.textScale, "";
|
|
686
735
|
}
|
|
687
736
|
// feed new line:
|
|
688
|
-
lf() {
|
|
737
|
+
async lf() {
|
|
689
738
|
const t = this.lineHeight * this.charWidth * 2;
|
|
690
739
|
return this.textElement.length > 0 && (this.svgContent += `<g transform="translate(${this.lineMargin * this.charWidth},${this.svgHeight + t})">${this.textElement}</g>`), this.svgHeight += Math.max(t, this.feedMinimum), this.lineHeight = 1, this.textElement = "", this.textPosition = 0, "";
|
|
691
740
|
}
|
|
692
741
|
// insert commands:
|
|
693
|
-
command(t) {
|
|
742
|
+
async command(t) {
|
|
694
743
|
return "";
|
|
695
744
|
}
|
|
696
745
|
// print image:
|
|
697
|
-
image(t) {
|
|
698
|
-
const
|
|
699
|
-
return this.svgContent += `<g transform="translate(${
|
|
746
|
+
async image(t) {
|
|
747
|
+
const e = it(t), i = new DataView(e.buffer), a = i.getUint32(16, !1), r = i.getUint32(20, !1), n = `<image href="data:image/png;base64,${V(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})">${n}</g>`, this.svgHeight += r, "";
|
|
700
749
|
}
|
|
701
750
|
// print QR Code:
|
|
702
|
-
qrcode(t,
|
|
703
|
-
const
|
|
751
|
+
async qrcode(t, e) {
|
|
752
|
+
const i = O({
|
|
704
753
|
data: t.data,
|
|
705
|
-
ec: t.level == "l" ?
|
|
706
|
-
}),
|
|
707
|
-
moduleSize:
|
|
754
|
+
ec: t.level == "l" ? C.L : t.level == "m" ? C.M : t.level == "q" ? C.Q : C.H
|
|
755
|
+
}), a = i.width, r = t.cell, n = await nt(i, {
|
|
756
|
+
moduleSize: r,
|
|
708
757
|
margin: t.quietZone ? 4 : 0,
|
|
709
758
|
output: "path"
|
|
710
|
-
}), o = Math.floor(this.lineMargin * this.charWidth),
|
|
711
|
-
return this.svgContent += `<g transform="translate(${
|
|
712
|
-
<path d="${
|
|
713
|
-
</g>`, this.svgHeight +=
|
|
759
|
+
}), h = typeof n == "string" ? n : n.path || n.svg || String(n), o = a * r + (t.quietZone ? 8 : 0), c = Math.floor(this.lineMargin * this.charWidth + (this.lineWidth * this.charWidth - o) * this.lineAlign / 2), l = Math.floor(this.svgHeight);
|
|
760
|
+
return this.svgContent += `<g transform="translate(${c},${l})" shape-rendering="crispEdges">
|
|
761
|
+
<path d="${h}" stroke="transparent" fill="black" shape-rendering="crispEdges" />
|
|
762
|
+
</g>`, this.svgHeight += o, "";
|
|
714
763
|
}
|
|
715
764
|
// print barcode:
|
|
716
|
-
barcode(t,
|
|
717
|
-
const
|
|
718
|
-
if (
|
|
719
|
-
const
|
|
720
|
-
let
|
|
721
|
-
if (
|
|
722
|
-
const c = Math.floor((
|
|
723
|
-
|
|
765
|
+
async barcode(t, e) {
|
|
766
|
+
const i = G(t), a = i.height;
|
|
767
|
+
if (a !== void 0 && "length" in i && i.length !== void 0 && i.widths) {
|
|
768
|
+
const r = i.length, n = a + (i.hri ? this.charWidth * 2 + 2 : 0);
|
|
769
|
+
let h = '<path d="';
|
|
770
|
+
if (i.widths.reduce((c, l, p) => (p % 2 === 1 && (h += `M${c},0h${l}v${a}h${-l}z`), c + l), 0), h += '" fill="#000"/>', i.hri && i.text) {
|
|
771
|
+
const c = Math.floor((r - (this.measureText(i.text, e) - 1) * this.charWidth) / 2), l = this.arrayFrom(i.text, e).reduce((p, d, g) => p + `<tspan x="${c + this.charWidth * g}">${d.replace(/[ &<>]/g, (u) => ({ " ": " ", "&": "&", "<": "<", ">": ">" })[u] || u)}</tspan>`, "");
|
|
772
|
+
h += `<text y="${n}">${l}</text>`;
|
|
724
773
|
}
|
|
725
|
-
const
|
|
726
|
-
this.svgContent += `<g transform="translate(${
|
|
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 += n;
|
|
727
776
|
}
|
|
728
777
|
return "";
|
|
729
778
|
}
|
|
@@ -734,270 +783,1554 @@ class E extends F {
|
|
|
734
783
|
return this.svgHeight + this.fontSize / 2;
|
|
735
784
|
}
|
|
736
785
|
}
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
|
|
786
|
+
const ft = /* @__PURE__ */ new Set([
|
|
787
|
+
"area",
|
|
788
|
+
"base",
|
|
789
|
+
"br",
|
|
790
|
+
"col",
|
|
791
|
+
"embed",
|
|
792
|
+
"hr",
|
|
793
|
+
"img",
|
|
794
|
+
"input",
|
|
795
|
+
"link",
|
|
796
|
+
"meta",
|
|
797
|
+
"param",
|
|
798
|
+
"source",
|
|
799
|
+
"track",
|
|
800
|
+
"wbr"
|
|
801
|
+
]), wt = /* @__PURE__ */ new Set([
|
|
802
|
+
// Containers
|
|
803
|
+
"div",
|
|
804
|
+
"span",
|
|
805
|
+
"p",
|
|
806
|
+
"section",
|
|
807
|
+
"article",
|
|
808
|
+
"aside",
|
|
809
|
+
"header",
|
|
810
|
+
"footer",
|
|
811
|
+
"nav",
|
|
812
|
+
"main",
|
|
813
|
+
// Forms
|
|
814
|
+
"button",
|
|
815
|
+
"textarea",
|
|
816
|
+
"select",
|
|
817
|
+
"label",
|
|
818
|
+
"form",
|
|
819
|
+
"fieldset",
|
|
820
|
+
"legend",
|
|
821
|
+
"optgroup",
|
|
822
|
+
// Lists
|
|
823
|
+
"ul",
|
|
824
|
+
"ol",
|
|
825
|
+
"li",
|
|
826
|
+
"dl",
|
|
827
|
+
"dt",
|
|
828
|
+
"dd",
|
|
829
|
+
// Script/style
|
|
830
|
+
"script",
|
|
831
|
+
"style",
|
|
832
|
+
// Formatting
|
|
833
|
+
"a",
|
|
834
|
+
"b",
|
|
835
|
+
"i",
|
|
836
|
+
"strong",
|
|
837
|
+
"em",
|
|
838
|
+
"u",
|
|
839
|
+
"s",
|
|
840
|
+
"del",
|
|
841
|
+
"ins",
|
|
842
|
+
"mark",
|
|
843
|
+
"small",
|
|
844
|
+
"sub",
|
|
845
|
+
"sup",
|
|
846
|
+
"code",
|
|
847
|
+
"kbd",
|
|
848
|
+
"samp",
|
|
849
|
+
"var",
|
|
850
|
+
"abbr",
|
|
851
|
+
"cite",
|
|
852
|
+
"dfn",
|
|
853
|
+
"q",
|
|
854
|
+
"time",
|
|
855
|
+
// Graphics
|
|
856
|
+
"canvas",
|
|
857
|
+
"svg",
|
|
858
|
+
// Tables
|
|
859
|
+
"table",
|
|
860
|
+
"tr",
|
|
861
|
+
"td",
|
|
862
|
+
"th",
|
|
863
|
+
"thead",
|
|
864
|
+
"tbody",
|
|
865
|
+
"tfoot",
|
|
866
|
+
"caption",
|
|
867
|
+
"colgroup",
|
|
868
|
+
// Headings
|
|
869
|
+
"h1",
|
|
870
|
+
"h2",
|
|
871
|
+
"h3",
|
|
872
|
+
"h4",
|
|
873
|
+
"h5",
|
|
874
|
+
"h6",
|
|
875
|
+
// Media
|
|
876
|
+
"video",
|
|
877
|
+
"audio",
|
|
878
|
+
"picture",
|
|
879
|
+
"figure",
|
|
880
|
+
"figcaption",
|
|
881
|
+
// Interactive
|
|
882
|
+
"details",
|
|
883
|
+
"summary",
|
|
884
|
+
"dialog",
|
|
885
|
+
// Other
|
|
886
|
+
"blockquote",
|
|
887
|
+
"pre",
|
|
888
|
+
"address",
|
|
889
|
+
"noscript",
|
|
890
|
+
"iframe",
|
|
891
|
+
"object",
|
|
892
|
+
"map",
|
|
893
|
+
"html",
|
|
894
|
+
"head",
|
|
895
|
+
"body",
|
|
896
|
+
"title",
|
|
897
|
+
"meta"
|
|
898
|
+
]), $t = {
|
|
899
|
+
lt: "<",
|
|
900
|
+
gt: ">",
|
|
901
|
+
amp: "&",
|
|
902
|
+
quot: '"',
|
|
903
|
+
apos: "'",
|
|
904
|
+
nbsp: " ",
|
|
905
|
+
iexcl: "¡",
|
|
906
|
+
cent: "¢",
|
|
907
|
+
pound: "£",
|
|
908
|
+
curren: "¤",
|
|
909
|
+
yen: "¥",
|
|
910
|
+
brvbar: "¦",
|
|
911
|
+
sect: "§",
|
|
912
|
+
uml: "¨",
|
|
913
|
+
copy: "©",
|
|
914
|
+
ordf: "ª",
|
|
915
|
+
laquo: "«",
|
|
916
|
+
not: "¬",
|
|
917
|
+
shy: "",
|
|
918
|
+
reg: "®",
|
|
919
|
+
macr: "¯",
|
|
920
|
+
deg: "°",
|
|
921
|
+
plusmn: "±",
|
|
922
|
+
sup2: "²",
|
|
923
|
+
sup3: "³",
|
|
924
|
+
acute: "´",
|
|
925
|
+
micro: "µ",
|
|
926
|
+
para: "¶",
|
|
927
|
+
middot: "·",
|
|
928
|
+
cedil: "¸",
|
|
929
|
+
sup1: "¹",
|
|
930
|
+
ordm: "º",
|
|
931
|
+
raquo: "»",
|
|
932
|
+
frac14: "¼",
|
|
933
|
+
frac12: "½",
|
|
934
|
+
frac34: "¾",
|
|
935
|
+
iquest: "¿",
|
|
936
|
+
times: "×",
|
|
937
|
+
divide: "÷",
|
|
938
|
+
ndash: "–",
|
|
939
|
+
mdash: "—",
|
|
940
|
+
lsquo: "‘",
|
|
941
|
+
rsquo: "’",
|
|
942
|
+
sbquo: "‚",
|
|
943
|
+
ldquo: "“",
|
|
944
|
+
rdquo: "”",
|
|
945
|
+
bdquo: "„",
|
|
946
|
+
dagger: "†",
|
|
947
|
+
Dagger: "‡",
|
|
948
|
+
bull: "•",
|
|
949
|
+
hellip: "…",
|
|
950
|
+
permil: "‰",
|
|
951
|
+
prime: "′",
|
|
952
|
+
Prime: "″",
|
|
953
|
+
lsaquo: "‹",
|
|
954
|
+
rsaquo: "›",
|
|
955
|
+
oline: "‾",
|
|
956
|
+
frasl: "⁄",
|
|
957
|
+
euro: "€",
|
|
958
|
+
trade: "™",
|
|
959
|
+
larr: "←",
|
|
960
|
+
uarr: "↑",
|
|
961
|
+
rarr: "→",
|
|
962
|
+
darr: "↓",
|
|
963
|
+
harr: "↔",
|
|
964
|
+
lArr: "⇐",
|
|
965
|
+
uArr: "⇑",
|
|
966
|
+
rArr: "⇒",
|
|
967
|
+
dArr: "⇓",
|
|
968
|
+
hArr: "⇔"
|
|
969
|
+
}, L = {};
|
|
970
|
+
for (const [s, t] of Object.entries($t))
|
|
971
|
+
L[t] || (L[t] = s);
|
|
972
|
+
function D(s, t = !1) {
|
|
973
|
+
if (!s || typeof s != "string")
|
|
974
|
+
return s;
|
|
975
|
+
let e = s;
|
|
976
|
+
return e = e.replace(/&/g, "&"), e = e.replace(/</g, "<"), e = e.replace(/>/g, ">"), t && (e = e.replace(/"/g, """)), e;
|
|
977
|
+
}
|
|
978
|
+
function mt(s) {
|
|
979
|
+
return s.replace(/\]\]>/g, "]]]]><![CDATA[>");
|
|
980
|
+
}
|
|
981
|
+
function vt(s) {
|
|
982
|
+
return s.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
983
|
+
}
|
|
984
|
+
const yt = {
|
|
985
|
+
className: "class",
|
|
986
|
+
htmlFor: "for"
|
|
740
987
|
};
|
|
741
|
-
function
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
988
|
+
function bt(s, t) {
|
|
989
|
+
return t === "reactName" ? s : t === "exactName" || t === "eitherName" ? yt[s] ?? s : s;
|
|
990
|
+
}
|
|
991
|
+
function R(s, t = {}) {
|
|
992
|
+
const e = [];
|
|
993
|
+
let i, a, r;
|
|
994
|
+
if (s && typeof s == "object" && "node" in s) {
|
|
995
|
+
const l = s;
|
|
996
|
+
i = l.node, a = l.xml ?? t.xml, r = l.doctype ?? t.doctype;
|
|
997
|
+
} else
|
|
998
|
+
i = s, a = t.xml, r = t.doctype;
|
|
999
|
+
a && (e.push(a), a.endsWith(`
|
|
1000
|
+
`) || e.push(`
|
|
1001
|
+
`)), r && (e.push(r), r.endsWith(`
|
|
1002
|
+
`) || e.push(`
|
|
1003
|
+
`));
|
|
1004
|
+
const n = t.useCDataForScripts ?? !1, h = t.useCDataForStyles ?? !1, o = t.voidTrailingSlash ?? !0, c = t.attributeNaming ?? "eitherName";
|
|
1005
|
+
return z(i, e, "HTML", n, h, o, c), e.join("");
|
|
1006
|
+
}
|
|
1007
|
+
function z(s, t, e, i, a, r, n) {
|
|
1008
|
+
if (s != null) {
|
|
1009
|
+
if (typeof s == "string") {
|
|
1010
|
+
t.push(D(s, !1));
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
if (typeof s == "number" || typeof s == "bigint") {
|
|
1014
|
+
t.push(String(s));
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (typeof s == "boolean") {
|
|
1018
|
+
t.push(String(s));
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (Array.isArray(s)) {
|
|
1022
|
+
for (const h of s)
|
|
1023
|
+
z(h, t, e, i, a, r, n);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
1026
|
+
if (typeof s != "function" && typeof s != "symbol" && !(s && typeof s == "object" && "then" in s && typeof s.then == "function") && s && typeof s == "object" && "type" in s && "props" in s) {
|
|
1027
|
+
xt(s, t, e, i, a, r, n);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
function xt(s, t, e, i, a, r, n) {
|
|
1033
|
+
var h;
|
|
1034
|
+
const o = s.type;
|
|
1035
|
+
let c = e;
|
|
1036
|
+
if (o === "svg" ? c = "SVG" : o === "math" && (c = "MATHML"), t.push("<"), t.push(o), s.props)
|
|
1037
|
+
for (const [d, g] of Object.entries(s.props)) {
|
|
1038
|
+
if (d === "children" || g === !1 || g === null || g === void 0)
|
|
1039
|
+
continue;
|
|
1040
|
+
const u = bt(d, n);
|
|
1041
|
+
if (g === !0)
|
|
1042
|
+
t.push(" "), t.push(u);
|
|
1043
|
+
else if (d === "style" && typeof g == "object") {
|
|
1044
|
+
const f = kt(g);
|
|
1045
|
+
f && (t.push(' style="'), t.push(D(f, !0)), t.push('"'));
|
|
1046
|
+
} else
|
|
1047
|
+
t.push(" "), t.push(u), t.push('="'), t.push(D(String(g), !0)), t.push('"');
|
|
1048
|
+
}
|
|
1049
|
+
const l = (h = s.props) == null ? void 0 : h.children;
|
|
1050
|
+
let p;
|
|
1051
|
+
if (l && typeof l == "object" && "then" in l && typeof l.then == "function" ? p = !1 : p = l != null && (Array.isArray(l) && l.length > 0 || !Array.isArray(l) && l !== !1), ft.has(o))
|
|
1052
|
+
r ? t.push(" />") : t.push(">");
|
|
1053
|
+
else if (p) {
|
|
1054
|
+
t.push(">");
|
|
1055
|
+
const d = l;
|
|
1056
|
+
o === "script" && i || o === "style" && a ? (t.push("<![CDATA["), K(d, t, c, i, a, r, n), t.push("]]>")) : o === "script" || o === "style" ? J(d, t) : z(d, t, c, i, a, r, n), t.push("</"), t.push(o), t.push(">");
|
|
1057
|
+
} else wt.has(o), t.push("></"), t.push(o), t.push(">");
|
|
1058
|
+
}
|
|
1059
|
+
function K(s, t, e, i, a, r, n, h) {
|
|
1060
|
+
if (s != null) {
|
|
1061
|
+
if (typeof s == "string") {
|
|
1062
|
+
t.push(mt(s));
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (typeof s == "number" || typeof s == "bigint" || typeof s == "boolean") {
|
|
1066
|
+
t.push(String(s));
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (Array.isArray(s)) {
|
|
1070
|
+
for (const o of s)
|
|
1071
|
+
K(o, t, e, i, a, r, n);
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
z(s, t, e, i, a, r, n);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
function J(s, t) {
|
|
1078
|
+
if (s != null) {
|
|
1079
|
+
if (typeof s == "string") {
|
|
1080
|
+
t.push(s);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (typeof s == "number" || typeof s == "bigint" || typeof s == "boolean") {
|
|
1084
|
+
t.push(String(s));
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
if (Array.isArray(s)) {
|
|
1088
|
+
for (const e of s)
|
|
1089
|
+
J(e, t);
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function kt(s) {
|
|
1095
|
+
const t = [];
|
|
1096
|
+
for (const [e, i] of Object.entries(s))
|
|
1097
|
+
if (i) {
|
|
1098
|
+
const a = vt(e);
|
|
1099
|
+
t.push(`${a}: ${i}`);
|
|
1100
|
+
}
|
|
1101
|
+
return t.join("; ");
|
|
1102
|
+
}
|
|
1103
|
+
async function j(s) {
|
|
1104
|
+
if (s == null)
|
|
1105
|
+
return s;
|
|
1106
|
+
if (s && typeof s == "object" && "then" in s && typeof s.then == "function") {
|
|
1107
|
+
const t = await s;
|
|
1108
|
+
return j(t);
|
|
1109
|
+
}
|
|
1110
|
+
if (typeof s == "string" || typeof s == "number" || typeof s == "boolean" || typeof s == "bigint")
|
|
1111
|
+
return s;
|
|
1112
|
+
if (typeof s != "function" && typeof s != "symbol") {
|
|
1113
|
+
if (Array.isArray(s))
|
|
1114
|
+
return await Promise.all(
|
|
1115
|
+
s.filter((t) => !(t == null || typeof t == "function" || typeof t == "symbol")).map((t) => j(t))
|
|
1116
|
+
);
|
|
1117
|
+
if (s && typeof s == "object" && "type" in s && "props" in s) {
|
|
1118
|
+
const t = s, e = {};
|
|
1119
|
+
for (const [i, a] of Object.entries(t.props))
|
|
1120
|
+
if (i === "children") {
|
|
1121
|
+
const r = await j(a);
|
|
1122
|
+
r != null && (e.children = r);
|
|
1123
|
+
} else {
|
|
1124
|
+
if (typeof a == "function" || typeof a == "symbol")
|
|
1125
|
+
continue;
|
|
1126
|
+
a != null && (e[i] = a);
|
|
1127
|
+
}
|
|
1128
|
+
return {
|
|
1129
|
+
type: t.type,
|
|
1130
|
+
props: e
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
function Wt(s, t = {}) {
|
|
1136
|
+
return s && typeof s == "object" && "node" in s ? R(s, t) : s === void 0 ? "" : R(s, t);
|
|
1137
|
+
}
|
|
1138
|
+
async function At(s) {
|
|
1139
|
+
return await j(s);
|
|
1140
|
+
}
|
|
1141
|
+
function St(...s) {
|
|
1142
|
+
const t = new Uint8Array(
|
|
1143
|
+
s.reduceRight((i, a) => i + a.length, 0)
|
|
1144
|
+
);
|
|
1145
|
+
let e = 0;
|
|
1146
|
+
for (const i of s)
|
|
1147
|
+
t.set(i, e), e += i.length;
|
|
1148
|
+
return t;
|
|
1149
|
+
}
|
|
1150
|
+
async function Ct(s) {
|
|
1151
|
+
const t = new CompressionStream("deflate"), e = t.writable.getWriter();
|
|
1152
|
+
e.write(s), e.close();
|
|
1153
|
+
const i = t.readable.getReader(), a = [];
|
|
1154
|
+
let r = 0;
|
|
1155
|
+
for (; ; ) {
|
|
1156
|
+
const { done: o, value: c } = await i.read();
|
|
1157
|
+
if (o) break;
|
|
1158
|
+
a.push(c), r += c.length;
|
|
1159
|
+
}
|
|
1160
|
+
const n = new Uint8Array(r);
|
|
1161
|
+
let h = 0;
|
|
1162
|
+
for (const o of a)
|
|
1163
|
+
n.set(o, h), h += o.length;
|
|
1164
|
+
return n;
|
|
1165
|
+
}
|
|
1166
|
+
const Q = new Uint32Array(256);
|
|
1167
|
+
for (let s = 0; s < 256; s++) {
|
|
1168
|
+
let t = s;
|
|
1169
|
+
for (let e = 0; e < 8; e++)
|
|
1170
|
+
t = t & 1 ? 3988292384 ^ t >>> 1 : t >>> 1;
|
|
1171
|
+
Q[s] = t;
|
|
1172
|
+
}
|
|
1173
|
+
function Mt(s) {
|
|
1174
|
+
let t = 4294967295;
|
|
1175
|
+
for (let e = 0; e < s.length; e++)
|
|
1176
|
+
t = Q[(t ^ s[e]) & 255] ^ t >>> 8;
|
|
1177
|
+
return (t ^ 4294967295) >>> 0;
|
|
1178
|
+
}
|
|
1179
|
+
const qt = new TextEncoder();
|
|
1180
|
+
function N(s, t) {
|
|
1181
|
+
const e = new Uint8Array(8 + t.length + 4), i = new DataView(e.buffer);
|
|
1182
|
+
i.setUint32(0, t.length), e.set(qt.encode(s), 4), e.set(t, 8);
|
|
1183
|
+
const a = Mt(e.subarray(4, e.length - 4));
|
|
1184
|
+
return i.setUint32(e.length - 4, a), e;
|
|
1185
|
+
}
|
|
1186
|
+
function Ht(s) {
|
|
1187
|
+
return s <= 1 ? 1 : s <= 3 ? 2 : s <= 15 ? 4 : 8;
|
|
1188
|
+
}
|
|
1189
|
+
function Nt(s, t, e, i) {
|
|
1190
|
+
const a = 8 / i, r = Math.ceil(t / a) + 1, n = new Uint8Array(r * e), h = new DataView(n.buffer);
|
|
1191
|
+
for (let o = 0; o < e; o++) {
|
|
1192
|
+
h.setUint8(o * r, 0);
|
|
1193
|
+
for (let c = 0; c < t; c++) {
|
|
1194
|
+
const l = s.getUint8(o * t + c), p = o * r + 1 + Math.floor(c / a), d = (a - 1 - c % a) * i, g = h.getUint8(p);
|
|
1195
|
+
h.setUint8(p, g | l << d);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
return n;
|
|
1199
|
+
}
|
|
1200
|
+
new TextDecoder();
|
|
1201
|
+
async function jt(s, t, e, i) {
|
|
1202
|
+
const a = new DataView(s.buffer), r = a.byteLength;
|
|
1203
|
+
if (r === 0)
|
|
1204
|
+
throw new Error("Received empty input");
|
|
1205
|
+
if (r !== t * e)
|
|
1206
|
+
throw new Error(
|
|
1207
|
+
`Input does not match dimensions ${t}x${e}. Only ${r} bytes were given when ${t * e} are expected!`
|
|
1208
|
+
);
|
|
1209
|
+
let n = 0;
|
|
1210
|
+
for (let w = 0; w < r; w++) {
|
|
1211
|
+
const m = a.getUint8(w);
|
|
1212
|
+
m > n && (n = m);
|
|
1213
|
+
}
|
|
1214
|
+
if (i.length <= n)
|
|
1215
|
+
throw new Error(
|
|
1216
|
+
`Color palette does not have enough colors (${n + 1}). Only ${i.length} were given!`
|
|
1217
|
+
);
|
|
1218
|
+
const h = Ht(n), o = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), c = new Uint8Array(13), l = new DataView(c.buffer);
|
|
1219
|
+
l.setUint32(0, t), l.setUint32(4, e), l.setUint8(8, h), l.setUint8(9, 3), l.setUint8(10, 0), l.setUint8(11, 0), l.setUint8(12, 0);
|
|
1220
|
+
const p = N("IHDR", c), d = new Uint8Array(i.length * 3), g = new DataView(d.buffer);
|
|
1221
|
+
for (let w = 0; w <= n; w++)
|
|
1222
|
+
g.setUint8(w * 3, i[w][0]), g.setUint8(w * 3 + 1, i[w][1]), g.setUint8(w * 3 + 2, i[w][2]);
|
|
1223
|
+
const u = N("PLTE", d), f = Nt(a, t, e, h), $ = N("IDAT", await Ct(f)), k = N("IEND", new Uint8Array(0));
|
|
1224
|
+
return St(o, p, u, $, k);
|
|
1225
|
+
}
|
|
1226
|
+
async function Pt(s, t = {}) {
|
|
1227
|
+
var e;
|
|
1228
|
+
const {
|
|
1229
|
+
margin: i = 4,
|
|
1230
|
+
moduleSize: a = 4,
|
|
1231
|
+
backgroundColor: r = [255, 255, 255],
|
|
1232
|
+
foregroundColor: n = [0, 0, 0]
|
|
1233
|
+
} = t, { matrix: h } = s, o = ((e = h[0]) == null ? void 0 : e.length) ?? 0, c = h.length, l = (o + i * 2) * a, p = (c + i * 2) * a, d = new Uint8Array(l * p);
|
|
1234
|
+
d.fill(0);
|
|
1235
|
+
for (let g = 0; g < c; g++)
|
|
1236
|
+
for (let u = 0; u < o; u++)
|
|
1237
|
+
if (h[g][u])
|
|
1238
|
+
for (let f = 0; f < a; f++)
|
|
1239
|
+
for (let $ = 0; $ < a; $++) {
|
|
1240
|
+
const k = (u + i) * a + $, w = (g + i) * a + f;
|
|
1241
|
+
d[w * l + k] = 1;
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
bytes: await jt(d, l, p, [r, n]),
|
|
1245
|
+
width: l,
|
|
1246
|
+
height: p
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
function Ut(s) {
|
|
1250
|
+
const t = {};
|
|
1251
|
+
for (const [e, i] of Object.entries(s))
|
|
1252
|
+
i !== void 0 && (t[e] = i);
|
|
1253
|
+
return t;
|
|
1254
|
+
}
|
|
1255
|
+
class X extends q {
|
|
1256
|
+
charWidth = 12;
|
|
1257
|
+
charHeight = 24;
|
|
1258
|
+
// Default to charWidth * 2, can be overridden
|
|
1259
|
+
containerWidth = 576;
|
|
1260
|
+
estimatedHeight = 0;
|
|
1261
|
+
lineMargin = 0;
|
|
1262
|
+
lineAlign = 0;
|
|
1263
|
+
lineWidth = 48;
|
|
1264
|
+
lineHeight = 1;
|
|
1265
|
+
textEncoding = "multilingual";
|
|
1266
|
+
feedMinimum = 24;
|
|
1267
|
+
spacing = !1;
|
|
1268
|
+
defaultFont = "'Courier Prime', monospace";
|
|
1269
|
+
actualFontCharacterWidth = void 0;
|
|
1270
|
+
explicitCharHeight = void 0;
|
|
1271
|
+
// DOM building state
|
|
1272
|
+
contentNodes = [];
|
|
1273
|
+
currentStyles = {};
|
|
1274
|
+
textScale = 1;
|
|
1275
|
+
// Line building state - receipt printers queue commands until linefeed
|
|
1276
|
+
currentPosition = 0;
|
|
1277
|
+
// Current cursor position in characters
|
|
1278
|
+
lineSegments = [];
|
|
1279
|
+
// Queued text segments for current line
|
|
1280
|
+
pendingVrSvg = null;
|
|
1281
|
+
// Pending vertical rules SVG for overlay with text
|
|
1282
|
+
// start printing:
|
|
1283
|
+
async open(t) {
|
|
1284
|
+
return await super.open(t), this.charWidth = t.charWidth, this.charHeight = this.explicitCharHeight ?? t.charWidth * 2, this.actualFontCharacterWidth !== void 0 && this.actualFontCharacterWidth > 0 && (this._cpl = Math.floor(t.cpl * t.charWidth / this.actualFontCharacterWidth)), this.containerWidth = t.cpl * t.charWidth, this.estimatedHeight = 0, this.lineMargin = 0, this.lineAlign = 0, this.lineWidth = this.cpl, this.lineHeight = 1, this.textEncoding = t.encoding, this.feedMinimum = Number(t.spacing ? this.charHeight * 1.25 : this.charHeight), this.spacing = t.spacing, this.contentNodes = [], this.currentStyles = {}, this.textScale = 1, this.currentPosition = 0, this.lineSegments = [], this.pendingVrSvg = null, "";
|
|
1285
|
+
}
|
|
1286
|
+
setDefaultFont(t) {
|
|
1287
|
+
return this.defaultFont = t, this.defaultFont;
|
|
1288
|
+
}
|
|
1289
|
+
setActualFontCharacterWidth(t) {
|
|
1290
|
+
this.actualFontCharacterWidth = t;
|
|
1291
|
+
}
|
|
1292
|
+
setCharHeight(t) {
|
|
1293
|
+
this.explicitCharHeight = t;
|
|
1294
|
+
}
|
|
1295
|
+
// finish printing (async to support Promise nodes like QR code PNGs):
|
|
1296
|
+
async close() {
|
|
1297
|
+
(this.lineSegments.length > 0 || this.pendingVrSvg) && await this.lf();
|
|
1298
|
+
let t = `${this.defaultFont}, monospace`, e;
|
|
1299
|
+
switch (this.textEncoding) {
|
|
1300
|
+
case "cp932":
|
|
1301
|
+
case "shiftjis":
|
|
1302
|
+
t = "'BIZ UDGothic', monospace", e = "ja";
|
|
1303
|
+
break;
|
|
1304
|
+
case "cp936":
|
|
1305
|
+
case "gb18030":
|
|
1306
|
+
e = "zh-Hans";
|
|
1307
|
+
break;
|
|
1308
|
+
case "cp949":
|
|
1309
|
+
case "ksc5601":
|
|
1310
|
+
e = "ko";
|
|
1311
|
+
break;
|
|
1312
|
+
case "cp950":
|
|
1313
|
+
case "big5":
|
|
1314
|
+
e = "zh-Hant";
|
|
1315
|
+
break;
|
|
1316
|
+
case "tis620":
|
|
1317
|
+
t = "'Sarabun', monospace", e = "th";
|
|
1318
|
+
break;
|
|
1319
|
+
}
|
|
1320
|
+
const a = {
|
|
1321
|
+
style: {
|
|
1322
|
+
fontFamily: t,
|
|
1323
|
+
fontSize: `${this.charWidth * 2 - 2}px`,
|
|
1324
|
+
lineHeight: "1.2",
|
|
1325
|
+
width: `${this.containerWidth}px`,
|
|
1326
|
+
backgroundColor: "white",
|
|
1327
|
+
color: "black",
|
|
1328
|
+
boxSizing: "border-box",
|
|
1329
|
+
wordWrap: "break-word",
|
|
1330
|
+
overflowWrap: "break-word",
|
|
1331
|
+
overflow: "hidden"
|
|
1332
|
+
},
|
|
1333
|
+
children: this.contentNodes
|
|
1334
|
+
};
|
|
1335
|
+
e && (a.lang = e);
|
|
1336
|
+
const n = await At({
|
|
1337
|
+
type: "div",
|
|
1338
|
+
props: a
|
|
1339
|
+
});
|
|
1340
|
+
return Wt(n);
|
|
1341
|
+
}
|
|
1342
|
+
// set print area:
|
|
1343
|
+
async area(t, e, i) {
|
|
1344
|
+
return this.lineMargin = t, this.lineWidth = e, "";
|
|
1345
|
+
}
|
|
1346
|
+
// set line alignment:
|
|
1347
|
+
async align(t) {
|
|
1348
|
+
return this.lineAlign = t, "";
|
|
1349
|
+
}
|
|
1350
|
+
// set absolute print position:
|
|
1351
|
+
async absolute(t) {
|
|
1352
|
+
return this.currentPosition = t, "";
|
|
1353
|
+
}
|
|
1354
|
+
// set relative print position:
|
|
1355
|
+
async relative(t) {
|
|
1356
|
+
return this.currentPosition += t, "";
|
|
1357
|
+
}
|
|
1358
|
+
// print horizontal rule:
|
|
1359
|
+
async hr(t) {
|
|
1360
|
+
const e = {
|
|
1361
|
+
type: "div",
|
|
1362
|
+
props: {
|
|
1363
|
+
style: {
|
|
1364
|
+
borderTop: "2px solid black",
|
|
1365
|
+
marginLeft: `${this.lineMargin}ch`,
|
|
1366
|
+
width: `${t}ch`,
|
|
1367
|
+
height: "0"
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
return this.contentNodes.push(e), "";
|
|
1372
|
+
}
|
|
1373
|
+
// print vertical rules:
|
|
1374
|
+
async vr(t, e) {
|
|
1375
|
+
const i = this.charWidth, a = i / 2, r = this.charHeight * e, n = t.reduce((l, p) => l + p, 0) + t.length + 1;
|
|
1376
|
+
let h = `M${a},0v${r}`;
|
|
1377
|
+
for (const l of t)
|
|
1378
|
+
h += `m${l * i + i},${-r}v${r}`;
|
|
1379
|
+
const o = n * i, c = {
|
|
1380
|
+
type: "svg",
|
|
1381
|
+
props: {
|
|
1382
|
+
width: `${n}ch`,
|
|
1383
|
+
height: `${r}`,
|
|
1384
|
+
viewBox: `0 0 ${o} ${r}`,
|
|
1385
|
+
preserveAspectRatio: "none",
|
|
1386
|
+
style: {
|
|
1387
|
+
position: "absolute",
|
|
1388
|
+
top: "0",
|
|
1389
|
+
left: `${this.lineMargin}ch`
|
|
1390
|
+
},
|
|
1391
|
+
children: {
|
|
1392
|
+
type: "path",
|
|
1393
|
+
props: {
|
|
1394
|
+
d: h,
|
|
1395
|
+
fill: "none",
|
|
1396
|
+
stroke: "black",
|
|
1397
|
+
"stroke-width": "2",
|
|
1398
|
+
"vector-effect": "non-scaling-stroke"
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
return this.pendingVrSvg = c, "";
|
|
1404
|
+
}
|
|
1405
|
+
// start rules:
|
|
1406
|
+
async vrstart(t) {
|
|
1407
|
+
const e = this.charWidth, i = t.reduce((o, c) => o + c, 0) + t.length + 1, a = i * e, r = e * 2, n = this.buildVrStartPath(t), h = {
|
|
1408
|
+
type: "svg",
|
|
1409
|
+
props: {
|
|
1410
|
+
width: `${i}ch`,
|
|
1411
|
+
height: `${r}`,
|
|
1412
|
+
viewBox: `0 0 ${a} ${r}`,
|
|
1413
|
+
preserveAspectRatio: "none",
|
|
1414
|
+
style: {
|
|
1415
|
+
display: "block",
|
|
1416
|
+
marginLeft: `${this.lineMargin}ch`
|
|
1417
|
+
},
|
|
1418
|
+
children: {
|
|
1419
|
+
type: "path",
|
|
1420
|
+
props: {
|
|
1421
|
+
d: n,
|
|
1422
|
+
fill: "none",
|
|
1423
|
+
stroke: "black",
|
|
1424
|
+
"stroke-width": "2",
|
|
1425
|
+
"vector-effect": "non-scaling-stroke"
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
return this.contentNodes.push(h), "";
|
|
1431
|
+
}
|
|
1432
|
+
buildVrStartPath(t) {
|
|
1433
|
+
const e = this.charWidth, i = e / 2;
|
|
1434
|
+
let a = `M${i},${e + e}v${-i}q0,${-i},${i},${-i}`;
|
|
1435
|
+
for (let r = 0; r < t.length; r++) {
|
|
1436
|
+
const n = t[r] ?? 0;
|
|
1437
|
+
a += `h${e * n}h${i}v${e}m0,${-e}h${i}`;
|
|
1438
|
+
}
|
|
1439
|
+
return a = a.replace(/h\d+v\d+m0,-\d+h\d+$/, `q${i},0,${i},${i}v${i}`), a;
|
|
1440
|
+
}
|
|
1441
|
+
// stop rules:
|
|
1442
|
+
async vrstop(t) {
|
|
1443
|
+
const e = this.charWidth, i = t.reduce((o, c) => o + c, 0) + t.length + 1, a = i * e, r = e * 2, n = this.buildVrStopPath(t), h = {
|
|
1444
|
+
type: "svg",
|
|
1445
|
+
props: {
|
|
1446
|
+
width: `${i}ch`,
|
|
1447
|
+
height: `${r}`,
|
|
1448
|
+
viewBox: `0 0 ${a} ${r}`,
|
|
1449
|
+
preserveAspectRatio: "none",
|
|
1450
|
+
style: {
|
|
1451
|
+
display: "block",
|
|
1452
|
+
marginLeft: `${this.lineMargin}ch`
|
|
1453
|
+
},
|
|
1454
|
+
children: {
|
|
1455
|
+
type: "path",
|
|
1456
|
+
props: {
|
|
1457
|
+
d: n,
|
|
1458
|
+
fill: "none",
|
|
1459
|
+
stroke: "black",
|
|
1460
|
+
"stroke-width": "2",
|
|
1461
|
+
"vector-effect": "non-scaling-stroke"
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
1466
|
+
return this.contentNodes.push(h), "";
|
|
1467
|
+
}
|
|
1468
|
+
buildVrStopPath(t) {
|
|
1469
|
+
const e = this.charWidth, i = e / 2;
|
|
1470
|
+
let a = `M${i},0v${i}q0,${i},${i},${i}`;
|
|
1471
|
+
for (let r = 0; r < t.length; r++) {
|
|
1472
|
+
const n = t[r] ?? 0;
|
|
1473
|
+
a += `h${e * n}h${i}v${-e}m0,${e}h${i}`;
|
|
1474
|
+
}
|
|
1475
|
+
return a = a.replace(/h\d+v-\d+m0,\d+h\d+$/, `q${i},0,${i},${-i}v${-i}`), a;
|
|
1476
|
+
}
|
|
1477
|
+
// print vertical and horizontal rules:
|
|
1478
|
+
async vrhr(t, e, i, a) {
|
|
1479
|
+
const r = this.charWidth, n = 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), l = c * r, p = r * 2;
|
|
1480
|
+
let d = `M${n},0` + (i > 0 ? `v${n}q0,${n},${n},${n}` : `v${r}h${n}`);
|
|
1481
|
+
for (const f of t)
|
|
1482
|
+
d += `h${r * f}h${n}v${-r}m0,${r}h${n}`;
|
|
1483
|
+
d = d.replace(/h\d+v-\d+m0,\d+h\d+$/, a < 0 ? `q${n},0,${n},${-n}v${-n}` : `h${n}v${-r}`);
|
|
1484
|
+
let g = `M${n},${r + r}` + (i < 0 ? `v${-n}q0,${-n},${n},${-n}` : `v${-r}h${n}`);
|
|
1485
|
+
for (const f of e)
|
|
1486
|
+
g += `h${r * f}h${n}v${r}m0,${-r}h${n}`;
|
|
1487
|
+
g = g.replace(/h\d+v\d+m0,-\d+h\d+$/, a > 0 ? `q${n},0,${n},${n}v${n}` : `h${n}v${r}`);
|
|
1488
|
+
const u = {
|
|
1489
|
+
type: "svg",
|
|
1490
|
+
props: {
|
|
1491
|
+
width: `${c}ch`,
|
|
1492
|
+
height: `${p}`,
|
|
1493
|
+
viewBox: `0 0 ${l} ${p}`,
|
|
1494
|
+
preserveAspectRatio: "none",
|
|
1495
|
+
style: {
|
|
1496
|
+
display: "block",
|
|
1497
|
+
marginLeft: `${this.lineMargin + Math.max(-i, 0)}ch`
|
|
1498
|
+
},
|
|
1499
|
+
children: [
|
|
1500
|
+
{ type: "path", props: { d, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } },
|
|
1501
|
+
{ type: "path", props: { d: g, fill: "none", stroke: "black", "stroke-width": "2", "vector-effect": "non-scaling-stroke" } }
|
|
1502
|
+
]
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
return this.contentNodes.push(u), "";
|
|
1506
|
+
}
|
|
1507
|
+
// set line spacing and feed new line:
|
|
1508
|
+
async vrlf(t) {
|
|
1509
|
+
return this.feedMinimum = Number(!t && this.spacing ? this.charHeight * 1.25 : this.charHeight), await this.lf();
|
|
1510
|
+
}
|
|
1511
|
+
// cut paper:
|
|
1512
|
+
async cut() {
|
|
1513
|
+
const t = {
|
|
1514
|
+
type: "div",
|
|
1515
|
+
props: {
|
|
1516
|
+
style: {
|
|
1517
|
+
display: "flex",
|
|
1518
|
+
alignItems: "center",
|
|
1519
|
+
height: `${this.charHeight}px`,
|
|
1520
|
+
marginTop: "4px",
|
|
1521
|
+
marginBottom: "4px"
|
|
1522
|
+
},
|
|
1523
|
+
children: [
|
|
1524
|
+
// Scissors icon (simple representation)
|
|
1525
|
+
{
|
|
1526
|
+
type: "span",
|
|
1527
|
+
props: {
|
|
1528
|
+
style: {
|
|
1529
|
+
fontSize: "16px",
|
|
1530
|
+
marginRight: "8px"
|
|
1531
|
+
},
|
|
1532
|
+
children: "✂"
|
|
1533
|
+
// Scissors unicode
|
|
1534
|
+
}
|
|
1535
|
+
},
|
|
1536
|
+
// Dashed line
|
|
1537
|
+
{
|
|
1538
|
+
type: "div",
|
|
1539
|
+
props: {
|
|
1540
|
+
style: {
|
|
1541
|
+
flex: "1",
|
|
1542
|
+
borderTop: "2px dashed black"
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
]
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
return this.contentNodes.push(t), this.estimatedHeight += this.charHeight, "";
|
|
1550
|
+
}
|
|
1551
|
+
// underline text:
|
|
1552
|
+
async ul() {
|
|
1553
|
+
return this.currentStyles.textDecoration = "underline", "";
|
|
1554
|
+
}
|
|
1555
|
+
// emphasize text:
|
|
1556
|
+
async em() {
|
|
1557
|
+
return this.currentStyles.fontWeight = "bold", "";
|
|
1558
|
+
}
|
|
1559
|
+
// invert text:
|
|
1560
|
+
async iv() {
|
|
1561
|
+
return this.currentStyles.backgroundColor = "black", this.currentStyles.color = "white", "";
|
|
1562
|
+
}
|
|
1563
|
+
// scale up text:
|
|
1564
|
+
async wh(t) {
|
|
1565
|
+
const e = t < 2 ? t + 1 : t - 1, i = t < 3 ? t : t - 1;
|
|
1566
|
+
return this.currentStyles.fontSize = `${i}em`, this.currentStyles.display = "inline-block", e !== i && (this.currentStyles.transform = `scaleX(${e / i})`, this.currentStyles.transformOrigin = "left"), this.lineHeight = Math.max(this.lineHeight, i), this.textScale = e, "";
|
|
1567
|
+
}
|
|
1568
|
+
// cancel text decoration:
|
|
1569
|
+
async normal() {
|
|
1570
|
+
return this.currentStyles = {}, this.textScale = 1, "";
|
|
1571
|
+
}
|
|
1572
|
+
// print text:
|
|
1573
|
+
async text(t, e) {
|
|
1574
|
+
const i = t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, " "), a = this.measureText(t, e), r = {
|
|
1575
|
+
position: this.currentPosition,
|
|
1576
|
+
text: i,
|
|
1577
|
+
styles: { ...this.currentStyles },
|
|
1578
|
+
scale: this.textScale,
|
|
1579
|
+
charWidth: a
|
|
1580
|
+
};
|
|
1581
|
+
return this.lineSegments.push(r), this.currentPosition += a * this.textScale, "";
|
|
1582
|
+
}
|
|
1583
|
+
// feed new line:
|
|
1584
|
+
async lf() {
|
|
1585
|
+
const t = this.lineHeight * this.charHeight, e = Math.max(t, this.feedMinimum), i = this.lineMargin + this.lineWidth, a = [];
|
|
1586
|
+
if (this.lineSegments.length === 0) {
|
|
1587
|
+
if (this.pendingVrSvg) {
|
|
1588
|
+
const n = {
|
|
1589
|
+
type: "div",
|
|
1590
|
+
props: {
|
|
1591
|
+
style: {
|
|
1592
|
+
position: "relative",
|
|
1593
|
+
width: `${this.containerWidth}px`,
|
|
1594
|
+
height: `${e}px`
|
|
1595
|
+
},
|
|
1596
|
+
children: this.pendingVrSvg
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
this.contentNodes.push(n), this.pendingVrSvg = null, this.estimatedHeight += e;
|
|
1600
|
+
}
|
|
1601
|
+
return this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
|
|
1602
|
+
} else {
|
|
1603
|
+
const n = [...this.lineSegments].sort((p, d) => p.position - d.position);
|
|
1604
|
+
let h = 0;
|
|
1605
|
+
const o = (p) => Math.floor(p), c = (p) => `${o(p)}ch`, l = (p) => {
|
|
1606
|
+
const d = p.match(/^(\d+(?:\.\d+)?)ch$/);
|
|
1607
|
+
return d ? parseFloat(d[1]) : 0;
|
|
1608
|
+
};
|
|
1609
|
+
for (let p = 0; p < n.length; p++) {
|
|
1610
|
+
const d = n[p], g = this.lineMargin + d.position, u = d.charWidth * d.scale;
|
|
1611
|
+
if (g > h && a.length > 0) {
|
|
1612
|
+
const W = g - h, y = a[a.length - 1];
|
|
1613
|
+
if (y && y.props && y.props.style && typeof y.props.style == "object" && !Array.isArray(y.props.style)) {
|
|
1614
|
+
const A = y.props.style, x = A.flexBasis;
|
|
1615
|
+
if (x) {
|
|
1616
|
+
const F = l(x) + W;
|
|
1617
|
+
A.flexBasis = c(F);
|
|
1618
|
+
} else
|
|
1619
|
+
A.flexBasis = c(W);
|
|
1620
|
+
}
|
|
1621
|
+
} else if (g > h && a.length === 0) {
|
|
1622
|
+
const W = g - h;
|
|
1623
|
+
a.push({
|
|
1624
|
+
type: "span",
|
|
1625
|
+
props: {
|
|
1626
|
+
style: {
|
|
1627
|
+
flexBasis: c(W)
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
const $ = {
|
|
1633
|
+
flexBasis: c(u),
|
|
1634
|
+
whiteSpace: "pre"
|
|
1635
|
+
}, k = d.styles && Object.keys(d.styles).length > 0, w = k ? d.styles : void 0, m = {
|
|
1636
|
+
type: "span",
|
|
1637
|
+
props: {
|
|
1638
|
+
style: $,
|
|
1639
|
+
children: k ? {
|
|
1640
|
+
// Wrap text in inner span with content styles
|
|
1641
|
+
type: "span",
|
|
1642
|
+
props: {
|
|
1643
|
+
style: w,
|
|
1644
|
+
children: d.text
|
|
1645
|
+
}
|
|
1646
|
+
} : d.text
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
a.push(m), h = g + u;
|
|
1650
|
+
}
|
|
1651
|
+
if (h < i && a.length > 0) {
|
|
1652
|
+
const p = i - h, d = a[a.length - 1];
|
|
1653
|
+
if (d && d.props && d.props.style && typeof d.props.style == "object" && !Array.isArray(d.props.style)) {
|
|
1654
|
+
const g = d.props.style, u = g.flexBasis;
|
|
1655
|
+
if (u) {
|
|
1656
|
+
const $ = l(u) + p;
|
|
1657
|
+
g.flexBasis = c($);
|
|
1658
|
+
} else
|
|
1659
|
+
g.flexBasis = c(p);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
const r = {
|
|
1664
|
+
type: "div",
|
|
1665
|
+
props: {
|
|
1666
|
+
style: {
|
|
1667
|
+
display: "flex",
|
|
1668
|
+
flexDirection: "row",
|
|
1669
|
+
height: `${e}px`,
|
|
1670
|
+
width: `${i}ch`
|
|
1671
|
+
},
|
|
1672
|
+
children: a
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
if (this.pendingVrSvg) {
|
|
1676
|
+
const n = {
|
|
1677
|
+
type: "div",
|
|
1678
|
+
props: {
|
|
1679
|
+
style: {
|
|
1680
|
+
position: "relative",
|
|
1681
|
+
width: `${this.containerWidth}px`,
|
|
1682
|
+
minHeight: `${e}px`
|
|
1683
|
+
},
|
|
1684
|
+
children: [
|
|
1685
|
+
// VR SVG positioned absolutely behind text
|
|
1686
|
+
this.pendingVrSvg,
|
|
1687
|
+
// Text line positioned relatively on top
|
|
1688
|
+
{
|
|
1689
|
+
...r,
|
|
1690
|
+
props: {
|
|
1691
|
+
...r.props,
|
|
1692
|
+
style: {
|
|
1693
|
+
...r.props?.style,
|
|
1694
|
+
position: "relative"
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
]
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
this.contentNodes.push(n), this.pendingVrSvg = null;
|
|
1702
|
+
} else
|
|
1703
|
+
this.contentNodes.push(r);
|
|
1704
|
+
return this.estimatedHeight += e, this.lineHeight = 1, this.lineSegments = [], this.currentPosition = 0, "";
|
|
1705
|
+
}
|
|
1706
|
+
// insert commands:
|
|
1707
|
+
async command(t) {
|
|
1708
|
+
return "";
|
|
1709
|
+
}
|
|
1710
|
+
// print image:
|
|
1711
|
+
async image(t) {
|
|
1712
|
+
const e = this.lineAlign === 0 ? "left" : this.lineAlign === 1 ? "center" : "right", i = {
|
|
1713
|
+
type: "img",
|
|
1714
|
+
props: {
|
|
1715
|
+
src: `data:image/png;base64,${t}`,
|
|
1716
|
+
style: Ut({
|
|
1717
|
+
display: "block",
|
|
1718
|
+
maxWidth: `${this.lineWidth}ch`
|
|
1719
|
+
})
|
|
1720
|
+
}
|
|
1721
|
+
}, a = {
|
|
1722
|
+
type: "div",
|
|
1723
|
+
props: {
|
|
1724
|
+
style: {
|
|
1725
|
+
textAlign: e,
|
|
1726
|
+
paddingLeft: `${this.lineMargin}ch`,
|
|
1727
|
+
width: `${this.lineWidth}ch`
|
|
1728
|
+
},
|
|
1729
|
+
children: i
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
return this.contentNodes.push(a), "";
|
|
1733
|
+
}
|
|
1734
|
+
// print QR Code (async version using PNG):
|
|
1735
|
+
async qrcode(t, e) {
|
|
1736
|
+
const i = O({
|
|
1737
|
+
data: t.data,
|
|
1738
|
+
ec: t.level === "l" ? C.L : t.level === "m" ? C.M : t.level === "q" ? C.Q : C.H
|
|
1739
|
+
}), a = t.cell, r = t.quietZone ? 4 : 0, { bytes: n, width: h, height: o } = await Pt(i, {
|
|
1740
|
+
moduleSize: a,
|
|
1741
|
+
margin: r
|
|
1742
|
+
}), l = {
|
|
1743
|
+
type: "img",
|
|
1744
|
+
props: {
|
|
1745
|
+
src: `data:image/png;base64,${V(n)}`,
|
|
1746
|
+
width: `${h}`,
|
|
1747
|
+
height: `${o}`,
|
|
1748
|
+
style: {
|
|
1749
|
+
display: "inline-block",
|
|
1750
|
+
imageRendering: "pixelated"
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}, d = {
|
|
1754
|
+
type: "div",
|
|
1755
|
+
props: {
|
|
1756
|
+
style: {
|
|
1757
|
+
textAlign: this.lineAlign === 0 ? "left" : this.lineAlign === 1 ? "center" : "right",
|
|
1758
|
+
paddingLeft: `${this.lineMargin}ch`,
|
|
1759
|
+
width: `${this.lineWidth}ch`
|
|
1760
|
+
},
|
|
1761
|
+
children: [l]
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
return this.contentNodes.push(d), this.estimatedHeight += o, "";
|
|
1765
|
+
}
|
|
1766
|
+
// print barcode:
|
|
1767
|
+
async barcode(t, e) {
|
|
1768
|
+
const i = G(t), a = i.height;
|
|
1769
|
+
if (a !== void 0 && "length" in i && i.length !== void 0 && i.widths) {
|
|
1770
|
+
const r = i.length, n = a + (i.hri ? this.charHeight + 2 : 0);
|
|
1771
|
+
let h = "";
|
|
1772
|
+
i.widths.reduce((d, g, u) => (u % 2 === 1 && (h += `M${d},0h${g}v${a}h${-g}z`), d + g), 0);
|
|
1773
|
+
const o = [
|
|
1774
|
+
{
|
|
1775
|
+
type: "path",
|
|
1776
|
+
props: {
|
|
1777
|
+
d: h,
|
|
1778
|
+
fill: "black"
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
];
|
|
1782
|
+
i.hri && i.text && o.push({
|
|
1783
|
+
type: "text",
|
|
1784
|
+
props: {
|
|
1785
|
+
x: `${r / 2}`,
|
|
1786
|
+
y: `${n}`,
|
|
1787
|
+
"text-anchor": "middle",
|
|
1788
|
+
"font-family": "monospace",
|
|
1789
|
+
"font-size": `${this.charWidth * 2}`,
|
|
1790
|
+
fill: "black",
|
|
1791
|
+
children: i.text
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
const c = {
|
|
1795
|
+
type: "svg",
|
|
1796
|
+
props: {
|
|
1797
|
+
width: `${r}`,
|
|
1798
|
+
height: `${n}`,
|
|
1799
|
+
viewBox: `0 0 ${r} ${n}`,
|
|
1800
|
+
style: {
|
|
1801
|
+
display: "inline-block"
|
|
1802
|
+
},
|
|
1803
|
+
children: o
|
|
1804
|
+
}
|
|
1805
|
+
}, p = {
|
|
1806
|
+
type: "div",
|
|
1807
|
+
props: {
|
|
1808
|
+
style: {
|
|
1809
|
+
textAlign: this.lineAlign === 0 ? "left" : this.lineAlign === 1 ? "center" : "right",
|
|
1810
|
+
paddingLeft: `${this.lineMargin}ch`,
|
|
1811
|
+
width: `${this.lineWidth}ch`
|
|
1812
|
+
},
|
|
1813
|
+
children: c
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
this.contentNodes.push(p), this.estimatedHeight += n;
|
|
1817
|
+
}
|
|
1818
|
+
return "";
|
|
1819
|
+
}
|
|
1820
|
+
calculatedWidth() {
|
|
1821
|
+
return this.containerWidth;
|
|
1822
|
+
}
|
|
1823
|
+
calculatedHeight() {
|
|
1824
|
+
return this.estimatedHeight;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
class Y extends q {
|
|
1828
|
+
logs = [];
|
|
1829
|
+
/**
|
|
1830
|
+
* Start printing.
|
|
1831
|
+
* @param {object} printer printer configuration
|
|
1832
|
+
* @returns {Promise<string>} empty string
|
|
1833
|
+
*/
|
|
1834
|
+
async open(t) {
|
|
1835
|
+
return await super.open(t), this.logs = [], this.logs.push(`open(cpl: ${this.cpl}, charWidth: ${t.charWidth}, encoding: ${t.encoding}, spacing: ${t.spacing}, margin: ${t.margin}, marginRight: ${t.marginRight})`), "";
|
|
1836
|
+
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Finish printing.
|
|
1839
|
+
* @returns {Promise<string>} all logs joined with newlines
|
|
1840
|
+
*/
|
|
1841
|
+
async close() {
|
|
1842
|
+
return this.logs.push("close"), this.logs.join(`
|
|
1843
|
+
`);
|
|
1844
|
+
}
|
|
1845
|
+
/**
|
|
1846
|
+
* Set print area.
|
|
1847
|
+
* @param {number} left left margin (unit: characters)
|
|
1848
|
+
* @param {number} width print area (unit: characters)
|
|
1849
|
+
* @param {number} right right margin (unit: characters)
|
|
1850
|
+
* @returns {Promise<string>} empty string
|
|
1851
|
+
*/
|
|
1852
|
+
async area(t, e, i) {
|
|
1853
|
+
return this.logs.push(`area(left: ${t}, width: ${e}, right: ${i})`), "";
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Set line alignment.
|
|
1857
|
+
* @param {number} align line alignment (0: left, 1: center, 2: right)
|
|
1858
|
+
* @returns {Promise<string>} empty string
|
|
1859
|
+
*/
|
|
1860
|
+
async align(t) {
|
|
1861
|
+
return this.logs.push(`align(${t})`), "";
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Set absolute print position.
|
|
1865
|
+
* @param {number} position absolute position (unit: characters)
|
|
1866
|
+
* @returns {Promise<string>} empty string
|
|
1867
|
+
*/
|
|
1868
|
+
async absolute(t) {
|
|
1869
|
+
return this.logs.push(`absolute(${t})`), "";
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* Set relative print position.
|
|
1873
|
+
* @param {number} position relative position (unit: characters)
|
|
1874
|
+
* @returns {Promise<string>} empty string
|
|
1875
|
+
*/
|
|
1876
|
+
async relative(t) {
|
|
1877
|
+
return this.logs.push(`relative(${t})`), "";
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Print horizontal rule.
|
|
1881
|
+
* @param {number} width line width (unit: characters)
|
|
1882
|
+
* @returns {Promise<string>} empty string
|
|
1883
|
+
*/
|
|
1884
|
+
async hr(t) {
|
|
1885
|
+
return this.logs.push(`hr(${t})`), "";
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Print vertical rules.
|
|
1889
|
+
* @param {number[]} widths vertical line spacing
|
|
1890
|
+
* @param {number} height text height (1-6)
|
|
1891
|
+
* @returns {Promise<string>} empty string
|
|
1892
|
+
*/
|
|
1893
|
+
async vr(t, e) {
|
|
1894
|
+
return this.logs.push(`vr(widths: [${t.join(", ")}], height: ${e})`), "";
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Start rules.
|
|
1898
|
+
* @param {number[]} widths vertical line spacing
|
|
1899
|
+
* @returns {Promise<string>} empty string
|
|
1900
|
+
*/
|
|
1901
|
+
async vrstart(t) {
|
|
1902
|
+
return this.logs.push(`vrstart([${t.join(", ")}])`), "";
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Stop rules.
|
|
1906
|
+
* @param {number[]} widths vertical line spacing
|
|
1907
|
+
* @returns {Promise<string>} empty string
|
|
1908
|
+
*/
|
|
1909
|
+
async vrstop(t) {
|
|
1910
|
+
return this.logs.push(`vrstop([${t.join(", ")}])`), "";
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Print vertical and horizontal rules.
|
|
1914
|
+
* @param {number[]} widths1 vertical line spacing (stop)
|
|
1915
|
+
* @param {number[]} widths2 vertical line spacing (start)
|
|
1916
|
+
* @param {number} dl difference in left position
|
|
1917
|
+
* @param {number} dr difference in right position
|
|
1918
|
+
* @returns {Promise<string>} empty string
|
|
1919
|
+
*/
|
|
1920
|
+
async vrhr(t, e, i, a) {
|
|
1921
|
+
return this.logs.push(`vrhr(widths1: [${t.join(", ")}], widths2: [${e.join(", ")}], dl: ${i}, dr: ${a})`), "";
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Set line spacing and feed new line.
|
|
1925
|
+
* @param {boolean} vr whether vertical ruled lines are printed
|
|
1926
|
+
* @returns {Promise<string>} empty string
|
|
1927
|
+
*/
|
|
1928
|
+
async vrlf(t) {
|
|
1929
|
+
return this.logs.push(`vrlf(${t})`), "";
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Cut paper.
|
|
1933
|
+
* @returns {Promise<string>} empty string
|
|
1934
|
+
*/
|
|
1935
|
+
async cut() {
|
|
1936
|
+
return this.logs.push("cut"), "";
|
|
1937
|
+
}
|
|
1938
|
+
/**
|
|
1939
|
+
* Underline text.
|
|
1940
|
+
* @returns {Promise<string>} empty string
|
|
1941
|
+
*/
|
|
1942
|
+
async ul() {
|
|
1943
|
+
return this.logs.push("ul"), "";
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Emphasize text.
|
|
1947
|
+
* @returns {Promise<string>} empty string
|
|
1948
|
+
*/
|
|
1949
|
+
async em() {
|
|
1950
|
+
return this.logs.push("em"), "";
|
|
1951
|
+
}
|
|
1952
|
+
/**
|
|
1953
|
+
* Invert text.
|
|
1954
|
+
* @returns {Promise<string>} empty string
|
|
1955
|
+
*/
|
|
1956
|
+
async iv() {
|
|
1957
|
+
return this.logs.push("iv"), "";
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Scale up text.
|
|
1961
|
+
* @param {number} wh number of special character '^' (1-7)
|
|
1962
|
+
* @returns {Promise<string>} empty string
|
|
1963
|
+
*/
|
|
1964
|
+
async wh(t) {
|
|
1965
|
+
return this.logs.push(`wh(${t})`), "";
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Cancel text decoration.
|
|
1969
|
+
* @returns {Promise<string>} empty string
|
|
1970
|
+
*/
|
|
1971
|
+
async normal() {
|
|
1972
|
+
return this.logs.push("normal"), "";
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Print text.
|
|
1976
|
+
* @param {string} text string to print
|
|
1977
|
+
* @param {string} encoding codepage
|
|
1978
|
+
* @returns {Promise<string>} empty string
|
|
1979
|
+
*/
|
|
1980
|
+
async text(t, e) {
|
|
1981
|
+
return this.logs.push(`text("${t}", encoding: ${e})`), "";
|
|
1982
|
+
}
|
|
1983
|
+
/**
|
|
1984
|
+
* Feed new line.
|
|
1985
|
+
* @returns {Promise<string>} empty string
|
|
1986
|
+
*/
|
|
1987
|
+
async lf() {
|
|
1988
|
+
return this.logs.push("lf"), "";
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Insert commands.
|
|
1992
|
+
* @param {string} command commands to insert
|
|
1993
|
+
* @returns {Promise<string>} empty string
|
|
1994
|
+
*/
|
|
1995
|
+
async command(t) {
|
|
1996
|
+
return this.logs.push(`command("${t}")`), "";
|
|
1997
|
+
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Print image.
|
|
2000
|
+
* @param {string} image image data (base64 png format)
|
|
2001
|
+
* @returns {Promise<string>} empty string
|
|
2002
|
+
*/
|
|
2003
|
+
async image(t) {
|
|
2004
|
+
const e = t.length > 50 ? t.substring(0, 50) + "..." : t;
|
|
2005
|
+
return this.logs.push(`image(base64: ${e})`), "";
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* Print QR Code.
|
|
2009
|
+
* @param {object} symbol QR Code information (data, type, cell, level)
|
|
2010
|
+
* @param {string} encoding codepage
|
|
2011
|
+
* @returns {Promise<string>} empty string
|
|
2012
|
+
*/
|
|
2013
|
+
async qrcode(t, e) {
|
|
2014
|
+
return this.logs.push(`qrcode(data: "${t.data}", type: ${t.type}, cell: ${t.cell}, level: ${t.level}, encoding: ${e})`), "";
|
|
2015
|
+
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Print barcode.
|
|
2018
|
+
* @param {object} symbol barcode information (data, type, width, height, hri)
|
|
2019
|
+
* @param {string} encoding codepage
|
|
2020
|
+
* @returns {Promise<string>} empty string
|
|
2021
|
+
*/
|
|
2022
|
+
async barcode(t, e) {
|
|
2023
|
+
return this.logs.push(`barcode(data: "${t.data}", type: ${t.type}, width: ${t.width}, height: ${t.height}, hri: ${t.hri}, encoding: ${e})`), "";
|
|
2024
|
+
}
|
|
2025
|
+
calculatedWidth() {
|
|
2026
|
+
return 0;
|
|
2027
|
+
}
|
|
2028
|
+
calculatedHeight() {
|
|
2029
|
+
return 0;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
const B = {
|
|
2033
|
+
base: new q(),
|
|
2034
|
+
svg: new E(),
|
|
2035
|
+
html: new X(),
|
|
2036
|
+
audit: new Y()
|
|
2037
|
+
};
|
|
2038
|
+
function zt(s) {
|
|
2039
|
+
const t = Object.assign({}, s), 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", i = typeof t.target == "string" ? t.target : void 0, r = (typeof t.target == "object" && t.target !== null ? t.target : void 0) || (i && i in B ? B[i] : B.svg);
|
|
2040
|
+
let n;
|
|
2041
|
+
return r instanceof X || r instanceof E || r instanceof Y || r instanceof q ? n = r : n = new E(), {
|
|
745
2042
|
cpl: t.cpl || 48,
|
|
746
2043
|
charWidth: t.charWidth || 12,
|
|
747
|
-
encoding:
|
|
2044
|
+
encoding: e,
|
|
748
2045
|
spacing: !!t.spacing,
|
|
749
2046
|
margin: t.margin || 0,
|
|
750
2047
|
marginRight: t.marginRight || 0,
|
|
751
|
-
target:
|
|
2048
|
+
target: n
|
|
752
2049
|
};
|
|
753
2050
|
}
|
|
754
|
-
function
|
|
755
|
-
const
|
|
756
|
-
let
|
|
2051
|
+
function Ft(s, t) {
|
|
2052
|
+
const e = s.replace(/^[\t ]+|[\t ]+$/g, "").replace(/\\[\\{|}]/g, (i) => "\\x" + i.charCodeAt(1).toString(16)).replace(/^[^|]*[^\t |]\|/, " $&").replace(/\|[^\t |][^|]*$/, "$& ").replace(/^\|(.*)$/, "$1").replace(/^(.*)\|$/, "$1").split("|").map((i, a, r) => {
|
|
2053
|
+
let n = {
|
|
757
2054
|
align: 1,
|
|
758
2055
|
wrap: t.wrap,
|
|
759
2056
|
border: t.border,
|
|
760
2057
|
width: 0,
|
|
761
2058
|
alignment: t.align
|
|
762
2059
|
};
|
|
763
|
-
const
|
|
764
|
-
if (
|
|
765
|
-
if (
|
|
2060
|
+
const h = i.replace(/^[\t ]+|[\t ]+$/g, "");
|
|
2061
|
+
if (n.align = 1 + Number(/^[\t ]/.test(i)) - Number(/[\t ]$/.test(i)), /^\{[^{}]*\}$/.test(h)) {
|
|
2062
|
+
if (n.property = h.slice(1, -1).replace(/\\;/g, "\\x3b").split(";").reduce((o, c) => {
|
|
766
2063
|
const l = { a: "align", b: "border", c: "code", i: "image", o: "option", t: "text", w: "width", x: "command", _: "comment" };
|
|
767
2064
|
return /^[\t ]*$/.test(c) || c.replace(
|
|
768
2065
|
/^[\t ]*([A-Za-z_]\w*)[\t ]*:[\t ]*([^\t ].*?)[\t ]*$/,
|
|
769
|
-
(
|
|
770
|
-
const
|
|
771
|
-
return
|
|
772
|
-
`)),
|
|
2066
|
+
(d, g, u) => {
|
|
2067
|
+
const f = g.replace(/^[abciotwx_]$/, ($) => l[$] || $);
|
|
2068
|
+
return o[f] = I(u.replace(/\\n/g, `
|
|
2069
|
+
`)), d;
|
|
773
2070
|
}
|
|
774
|
-
) === c && (
|
|
775
|
-
}, {}),
|
|
776
|
-
if ("text" in
|
|
777
|
-
const
|
|
778
|
-
t.wrap = !/^nowrap$/.test(
|
|
2071
|
+
) === c && (n.error = h), o;
|
|
2072
|
+
}, {}), r.length === 1) {
|
|
2073
|
+
if ("text" in n.property && n.property.text) {
|
|
2074
|
+
const o = n.property.text.toLowerCase();
|
|
2075
|
+
t.wrap = !/^nowrap$/.test(o);
|
|
779
2076
|
}
|
|
780
|
-
if ("border" in
|
|
781
|
-
const
|
|
782
|
-
t.border = /^(line|space|none)$/.test(
|
|
2077
|
+
if ("border" in n.property && n.property.border) {
|
|
2078
|
+
const o = n.property.border.toLowerCase(), c = { line: -1, space: 1, none: 0 }, l = t.border;
|
|
2079
|
+
t.border = /^(line|space|none)$/.test(o) ? c[o] ?? 1 : /^\d+$/.test(o) && Number(o) <= 2 ? Number(o) : 1, l >= 0 && t.border < 0 && (n.vr = "+"), l < 0 && t.border >= 0 && (n.vr = "-");
|
|
783
2080
|
}
|
|
784
|
-
if ("width" in
|
|
785
|
-
const
|
|
786
|
-
t.width =
|
|
2081
|
+
if ("width" in n.property && n.property.width) {
|
|
2082
|
+
const o = n.property.width.toLowerCase().split(/[\t ]+|,/);
|
|
2083
|
+
t.width = o.find((c) => /^auto$/.test(c)) ? [] : o.map((c) => /^\*$/.test(c) ? -1 : /^\d+$/.test(c) ? Number(c) : 0);
|
|
787
2084
|
}
|
|
788
|
-
if ("align" in
|
|
789
|
-
const
|
|
790
|
-
t.align = /^(left|center|right)$/.test(
|
|
2085
|
+
if ("align" in n.property && n.property.align) {
|
|
2086
|
+
const o = n.property.align.toLowerCase(), c = { left: 0, center: 1, right: 2 };
|
|
2087
|
+
t.align = /^(left|center|right)$/.test(o) ? c[o] ?? 1 : 1;
|
|
791
2088
|
}
|
|
792
|
-
if ("option" in
|
|
793
|
-
const
|
|
2089
|
+
if ("option" in n.property && n.property.option) {
|
|
2090
|
+
const o = n.property.option.toLowerCase().split(/[\t ]+|,/);
|
|
794
2091
|
t.option = {
|
|
795
|
-
type:
|
|
796
|
-
width: Number(
|
|
797
|
-
height: Number(
|
|
798
|
-
hri: !!
|
|
799
|
-
cell: Number(
|
|
800
|
-
level:
|
|
2092
|
+
type: o.find((c) => /^(upc|ean|jan|code39|itf|codabar|nw7|code93|code128|qrcode)$/.test(c)) || "code128",
|
|
2093
|
+
width: Number(o.find((c) => /^\d+$/.test(c) && Number(c) >= 2 && Number(c) <= 4) || "2"),
|
|
2094
|
+
height: Number(o.find((c) => /^\d+$/.test(c) && Number(c) >= 24 && Number(c) <= 240) || "72"),
|
|
2095
|
+
hri: !!o.find((c) => /^hri$/.test(c)),
|
|
2096
|
+
cell: Number(o.find((c) => /^\d+$/.test(c) && Number(c) >= 3 && Number(c) <= 8) || "3"),
|
|
2097
|
+
level: o.find((c) => /^[lmqh]$/.test(c)) || "l",
|
|
801
2098
|
quietZone: !1
|
|
802
2099
|
};
|
|
803
2100
|
}
|
|
804
|
-
if ("code" in
|
|
805
|
-
const
|
|
806
|
-
switch (
|
|
2101
|
+
if ("code" in n.property && n.property.code && (t.option.type === "qrcode" ? n.code = Object.assign({ data: n.property.code, type: "qrcode" }, t.option) : n.code = Object.assign({ data: n.property.code, type: t.option.type }, t.option)), "image" in n.property && n.property.image) {
|
|
2102
|
+
const o = n.property.image.replace(/=.*|[^A-Za-z0-9+/]/g, "");
|
|
2103
|
+
switch (o.length % 4) {
|
|
807
2104
|
case 1:
|
|
808
|
-
|
|
2105
|
+
n.image = o.slice(0, -1);
|
|
809
2106
|
break;
|
|
810
2107
|
case 2:
|
|
811
|
-
|
|
2108
|
+
n.image = o + "==";
|
|
812
2109
|
break;
|
|
813
2110
|
case 3:
|
|
814
|
-
|
|
2111
|
+
n.image = o + "=";
|
|
815
2112
|
break;
|
|
816
2113
|
default:
|
|
817
|
-
|
|
2114
|
+
n.image = o;
|
|
818
2115
|
break;
|
|
819
2116
|
}
|
|
820
2117
|
}
|
|
821
|
-
"command" in
|
|
2118
|
+
"command" in n.property && n.property.command && (n.command = n.property.command), "comment" in n.property && n.property.comment && (n.comment = n.property.comment);
|
|
822
2119
|
}
|
|
823
|
-
} else if (/[{}]/.test(
|
|
824
|
-
|
|
825
|
-
else if (
|
|
826
|
-
const
|
|
827
|
-
|
|
2120
|
+
} else if (/[{}]/.test(h))
|
|
2121
|
+
n.error = h;
|
|
2122
|
+
else if (r.length === 1 && /^-+$|^=+$/.test(h)) {
|
|
2123
|
+
const o = h.slice(-1);
|
|
2124
|
+
n.hr = o === "-" || o === "=" ? o : void 0;
|
|
828
2125
|
} else
|
|
829
|
-
|
|
830
|
-
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((
|
|
831
|
-
if (
|
|
832
|
-
|
|
833
|
-
else if ("text" in
|
|
834
|
-
|
|
835
|
-
else if (t.width.find((
|
|
836
|
-
|
|
2126
|
+
n.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, `
|
|
2127
|
+
`).replace(/~/g, " ").split(/([_"`\n]|\^+)/).map((o) => I(o));
|
|
2128
|
+
if (n.wrap = t.wrap, n.border = t.border, t.width.length === 0)
|
|
2129
|
+
n.width = -1;
|
|
2130
|
+
else if ("text" in n)
|
|
2131
|
+
n.width = a < t.width.length ? t.width[a] ?? 0 : 0;
|
|
2132
|
+
else if (t.width.find((o) => o < 0))
|
|
2133
|
+
n.width = -1;
|
|
837
2134
|
else {
|
|
838
|
-
const
|
|
839
|
-
|
|
2135
|
+
const o = t.width.filter((c) => c > 0);
|
|
2136
|
+
n.width = o.length > 0 ? o.reduce((c, l) => c + l, n.border < 0 ? o.length + 1 : (o.length - 1) * n.border) : 0;
|
|
840
2137
|
}
|
|
841
|
-
return
|
|
2138
|
+
return n.alignment = t.align, n;
|
|
842
2139
|
});
|
|
843
|
-
if (
|
|
844
|
-
for (;
|
|
845
|
-
|
|
846
|
-
return
|
|
847
|
-
}
|
|
848
|
-
function
|
|
849
|
-
return
|
|
850
|
-
}
|
|
851
|
-
function
|
|
852
|
-
const
|
|
853
|
-
let
|
|
854
|
-
return
|
|
855
|
-
if (
|
|
856
|
-
let
|
|
857
|
-
for (;
|
|
858
|
-
let
|
|
859
|
-
for (; u <
|
|
860
|
-
|
|
861
|
-
if (u > 0 && (
|
|
862
|
-
|
|
2140
|
+
if (e.every((i) => "text" in i) && t.width.length > 0)
|
|
2141
|
+
for (; e.length < t.width.length; )
|
|
2142
|
+
e.push({ align: 1, text: [""], wrap: t.wrap, border: t.border, width: t.width[e.length] ?? 0, alignment: t.align });
|
|
2143
|
+
return e;
|
|
2144
|
+
}
|
|
2145
|
+
function I(s) {
|
|
2146
|
+
return s.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)));
|
|
2147
|
+
}
|
|
2148
|
+
function Bt(s, t) {
|
|
2149
|
+
const e = [];
|
|
2150
|
+
let i = s.width, a = 1, r = [], n = !1, h = !1, o = !1, c = 0;
|
|
2151
|
+
return s.text.forEach((l, p) => {
|
|
2152
|
+
if (p % 2 === 0) {
|
|
2153
|
+
let d = t.target.arrayFrom(l, t.encoding);
|
|
2154
|
+
for (; d.length > 0; ) {
|
|
2155
|
+
let g = 0, u = 0;
|
|
2156
|
+
for (; u < d.length && (g = t.target.measureText(d[u] ?? "", t.encoding) * (c < 2 ? c + 1 : c - 1), !(g > i)); )
|
|
2157
|
+
i -= g, g = 0, u++;
|
|
2158
|
+
if (u > 0 && (r.push((n ? "1" : "0") + (h ? "1" : "0") + (o ? "1" : "0") + c), r.push(d.slice(0, u).join("")), a = Math.max(a, c < 3 ? c : c - 1), d = d.slice(u)), g > s.width) {
|
|
2159
|
+
d = d.slice(1);
|
|
863
2160
|
continue;
|
|
864
2161
|
}
|
|
865
|
-
(
|
|
2162
|
+
(g > i || i === 0) && (e.push({ data: r, margin: i * s.align / 2, height: a }), i = s.width, r = [], a = 1);
|
|
866
2163
|
}
|
|
867
2164
|
} else
|
|
868
2165
|
switch (l) {
|
|
869
2166
|
case `
|
|
870
2167
|
`:
|
|
871
|
-
|
|
2168
|
+
e.push({ data: r, margin: i * s.align / 2, height: a }), i = s.width, r = [], a = 1;
|
|
872
2169
|
break;
|
|
873
2170
|
case "_":
|
|
874
|
-
|
|
2171
|
+
n = !n;
|
|
875
2172
|
break;
|
|
876
2173
|
case '"':
|
|
877
|
-
|
|
2174
|
+
h = !h;
|
|
878
2175
|
break;
|
|
879
2176
|
case "`":
|
|
880
|
-
|
|
2177
|
+
o = !o;
|
|
881
2178
|
break;
|
|
882
2179
|
default:
|
|
883
|
-
const
|
|
884
|
-
c = c ===
|
|
2180
|
+
const d = Math.min(l.length, 7);
|
|
2181
|
+
c = c === d ? 0 : d;
|
|
885
2182
|
break;
|
|
886
2183
|
}
|
|
887
|
-
}),
|
|
888
|
-
}
|
|
889
|
-
function
|
|
890
|
-
const
|
|
891
|
-
let
|
|
892
|
-
|
|
893
|
-
const
|
|
894
|
-
let c =
|
|
895
|
-
|
|
896
|
-
const
|
|
897
|
-
for (;
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
904
|
-
const
|
|
905
|
-
switch (
|
|
2184
|
+
}), r.length > 0 && e.push({ data: r, margin: i * s.align / 2, height: a }), e;
|
|
2185
|
+
}
|
|
2186
|
+
async function Et(s, t, e) {
|
|
2187
|
+
const i = [], a = s.every((f) => "text" in f), r = s[0] ?? { align: 1, text: [""], wrap: !0, border: 0, width: 0, alignment: 1 };
|
|
2188
|
+
let n = s.filter((f) => f.width !== 0);
|
|
2189
|
+
a && (n = n.slice(0, Math.floor(r.border < 0 ? (t.target.cpl - 1) / 2 : (t.target.cpl + r.border) / (r.border + 1))));
|
|
2190
|
+
const h = n.filter((f) => f.width > 0), o = n.filter((f) => f.width < 0);
|
|
2191
|
+
let c = h.reduce((f, $) => f + $.width, 0), l = t.target.cpl - c;
|
|
2192
|
+
a && n.length > 0 && (l -= r.border < 0 ? n.length + 1 : (n.length - 1) * r.border);
|
|
2193
|
+
const p = o.length;
|
|
2194
|
+
for (; p > l; ) {
|
|
2195
|
+
const f = h.reduce(($, k) => $.width > k.width ? $ : k);
|
|
2196
|
+
f.width--, l++;
|
|
2197
|
+
}
|
|
2198
|
+
p > 0 && (o.forEach((f, $) => f.width = Math.floor((l + $) / p)), l = 0);
|
|
2199
|
+
const d = Math.floor(l * r.alignment / 2), g = t.target.cpl - l, u = l - d;
|
|
2200
|
+
if (a) {
|
|
2201
|
+
const f = n.map((w) => Bt(w, t)), $ = n.map((w) => w.width);
|
|
2202
|
+
switch (e.line) {
|
|
906
2203
|
case "ready":
|
|
907
|
-
|
|
2204
|
+
i.push(
|
|
2205
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0) + await t.target.vrstart($) + await t.target.vrlf(!0)
|
|
2206
|
+
), e.line = "running";
|
|
908
2207
|
break;
|
|
909
2208
|
case "horizontal":
|
|
910
|
-
const w =
|
|
911
|
-
|
|
2209
|
+
const w = d - e.rules.left, m = g - e.rules.width, W = Math.min(d, e.rules.left), y = Math.min(u, e.rules.right);
|
|
2210
|
+
i.push(
|
|
2211
|
+
await t.target.normal() + await t.target.area(W, t.target.cpl - W - y, y) + await t.target.align(0) + await t.target.vrhr(e.rules.widths, $, w, w + m) + await t.target.lf()
|
|
2212
|
+
), e.line = "running";
|
|
912
2213
|
break;
|
|
913
2214
|
}
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
for (let w = 0; w <
|
|
917
|
-
let
|
|
918
|
-
if (
|
|
919
|
-
const
|
|
920
|
-
|
|
2215
|
+
e.rules = { left: d, width: g, right: u, widths: $ };
|
|
2216
|
+
const k = r.wrap ? f.reduce((w, m) => Math.max(w, m.length), 1) : 1;
|
|
2217
|
+
for (let w = 0; w < k; w++) {
|
|
2218
|
+
let m = await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0), W = 0;
|
|
2219
|
+
if (e.line === "running") {
|
|
2220
|
+
const y = f.reduce((A, x) => w < x.length ? Math.max(A, x[w]?.height ?? 1) : A, 1);
|
|
2221
|
+
m += await t.target.normal() + await t.target.absolute(W++) + await t.target.vr($, y);
|
|
921
2222
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
2223
|
+
for (let y = 0; y < f.length; y++) {
|
|
2224
|
+
const A = f[y];
|
|
2225
|
+
if (A) {
|
|
2226
|
+
if (m += await t.target.absolute(W), w < A.length) {
|
|
2227
|
+
m += await t.target.relative(A[w]?.margin ?? 0);
|
|
2228
|
+
const x = A[w]?.data ?? [];
|
|
2229
|
+
for (let S = 0; S < x.length; S += 2) {
|
|
2230
|
+
const F = Number(String(x[S])[0]), tt = Number(String(x[S])[1]), et = Number(String(x[S])[2]), Z = Number(String(x[S])[3]);
|
|
2231
|
+
m += await t.target.normal(), F && (m += await t.target.ul()), tt && (m += await t.target.em()), et && (m += await t.target.iv()), Z && (m += await t.target.wh(Z)), m += await t.target.text(String(x[S + 1]), t.encoding);
|
|
2232
|
+
}
|
|
2233
|
+
} else
|
|
2234
|
+
m += await t.target.normal() + await t.target.text(" ", t.encoding);
|
|
2235
|
+
W += (n[y]?.width ?? 0) + Math.abs(r.border);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
m += await t.target.lf(), i.push(m);
|
|
934
2239
|
}
|
|
935
2240
|
}
|
|
936
|
-
if ("hr" in
|
|
937
|
-
if (
|
|
938
|
-
switch (
|
|
2241
|
+
if ("hr" in r)
|
|
2242
|
+
if (r.hr === "=")
|
|
2243
|
+
switch (e.line) {
|
|
939
2244
|
case "running":
|
|
940
2245
|
case "horizontal":
|
|
941
|
-
|
|
2246
|
+
i.push(
|
|
2247
|
+
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)
|
|
2248
|
+
), i.push(await t.target.cut()), e.line = "ready";
|
|
942
2249
|
break;
|
|
943
2250
|
default:
|
|
944
|
-
|
|
2251
|
+
i.push(await t.target.cut());
|
|
945
2252
|
break;
|
|
946
2253
|
}
|
|
947
2254
|
else
|
|
948
|
-
switch (
|
|
2255
|
+
switch (e.line) {
|
|
949
2256
|
case "waiting":
|
|
950
|
-
|
|
2257
|
+
i.push(
|
|
2258
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(0) + await t.target.hr(g) + await t.target.lf()
|
|
2259
|
+
);
|
|
951
2260
|
break;
|
|
952
2261
|
case "running":
|
|
953
|
-
|
|
2262
|
+
e.line = "horizontal";
|
|
954
2263
|
break;
|
|
955
2264
|
}
|
|
956
|
-
if ("vr" in
|
|
957
|
-
if (
|
|
958
|
-
|
|
2265
|
+
if ("vr" in r)
|
|
2266
|
+
if (r.vr === "+")
|
|
2267
|
+
e.line = "ready";
|
|
959
2268
|
else
|
|
960
|
-
switch (
|
|
2269
|
+
switch (e.line) {
|
|
961
2270
|
case "ready":
|
|
962
|
-
|
|
2271
|
+
e.line = "waiting";
|
|
963
2272
|
break;
|
|
964
2273
|
case "running":
|
|
965
2274
|
case "horizontal":
|
|
966
|
-
|
|
2275
|
+
i.push(
|
|
2276
|
+
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)
|
|
2277
|
+
), e.line = "waiting";
|
|
967
2278
|
break;
|
|
968
2279
|
}
|
|
969
|
-
return "image" in
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
align
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
2280
|
+
return "image" in r && r.image && i.push(
|
|
2281
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.image(r.image)
|
|
2282
|
+
), "code" in r && r.code && (r.code.type === "qrcode" ? i.push(
|
|
2283
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.qrcode(r.code, t.encoding)
|
|
2284
|
+
) : i.push(
|
|
2285
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.barcode(r.code, t.encoding)
|
|
2286
|
+
)), "command" in r && r.command && i.push(
|
|
2287
|
+
await t.target.normal() + await t.target.area(d, g, u) + await t.target.align(r.align) + await t.target.command(r.command)
|
|
2288
|
+
), i.join("");
|
|
2289
|
+
}
|
|
2290
|
+
async function Lt(s, t) {
|
|
2291
|
+
const e = zt(t);
|
|
2292
|
+
await e.target.lock();
|
|
2293
|
+
try {
|
|
2294
|
+
const i = {
|
|
2295
|
+
wrap: !0,
|
|
2296
|
+
border: 1,
|
|
2297
|
+
width: [],
|
|
2298
|
+
align: 1,
|
|
2299
|
+
option: { type: "code128", width: 2, height: 72, hri: !1, cell: 3, level: "l", quietZone: !1 },
|
|
2300
|
+
line: "waiting",
|
|
2301
|
+
rules: { left: 0, width: 0, right: 0, widths: [] }
|
|
2302
|
+
};
|
|
2303
|
+
let a = await e.target.open(e);
|
|
2304
|
+
s[0] === "\uFEFF" && (s = s.slice(1));
|
|
2305
|
+
const r = s.normalize().split(/\n|\r\n|\r/), n = [];
|
|
2306
|
+
for (const h of r)
|
|
2307
|
+
n.push(await Et(Ft(h, i), e, i));
|
|
2308
|
+
switch (i.line) {
|
|
2309
|
+
case "ready":
|
|
2310
|
+
i.line = "waiting";
|
|
2311
|
+
break;
|
|
2312
|
+
case "running":
|
|
2313
|
+
case "horizontal":
|
|
2314
|
+
n.push(
|
|
2315
|
+
await e.target.normal() + await e.target.area(i.rules.left, i.rules.width, i.rules.right) + await e.target.align(0) + await e.target.vrstop(i.rules.widths) + await e.target.vrlf(!1)
|
|
2316
|
+
), i.line = "waiting";
|
|
2317
|
+
break;
|
|
2318
|
+
default:
|
|
2319
|
+
break;
|
|
2320
|
+
}
|
|
2321
|
+
return a += n.join(""), a += await e.target.close(), {
|
|
2322
|
+
content: a,
|
|
2323
|
+
width: e.target.calculatedWidth(),
|
|
2324
|
+
height: Math.round(e.target.calculatedHeight())
|
|
2325
|
+
};
|
|
2326
|
+
} finally {
|
|
2327
|
+
e.target.unlock();
|
|
992
2328
|
}
|
|
993
|
-
return h += n.join(""), h += r.target.close(), {
|
|
994
|
-
svg: h,
|
|
995
|
-
width: r.target.calculatedWidth(),
|
|
996
|
-
height: r.target.calculatedHeight()
|
|
997
|
-
};
|
|
998
2329
|
}
|
|
999
2330
|
export {
|
|
1000
|
-
|
|
2331
|
+
Y as AuditTarget,
|
|
2332
|
+
q as BaseTarget,
|
|
2333
|
+
X as HtmlTarget,
|
|
1001
2334
|
E as SvgTarget,
|
|
1002
|
-
|
|
2335
|
+
Lt as transform
|
|
1003
2336
|
};
|