retail-print-kit 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +106 -2
- package/bin/retail-print-kit.js +218 -0
- package/dist/browser/retail-print-kit.js +26 -0
- package/dist/browser/retail-print-kit.js.map +7 -0
- package/dist/browser/retail-print-kit.mjs +25 -0
- package/dist/browser.d.ts +15 -0
- package/dist/browser.js +34 -0
- package/dist/core/barcode1d.d.ts +12 -0
- package/dist/core/barcode1d.js +192 -0
- package/dist/core/bitmap.d.ts +18 -0
- package/dist/core/bitmap.js +80 -0
- package/dist/core/builder.d.ts +58 -0
- package/dist/core/builder.js +177 -0
- package/dist/core/encode.d.ts +8 -0
- package/dist/core/encode.js +17 -0
- package/dist/core/escpos-encoder.d.ts +4 -0
- package/dist/core/escpos-encoder.js +150 -0
- package/dist/core/identify.d.ts +22 -0
- package/dist/core/identify.js +71 -0
- package/dist/core/ops.d.ts +78 -0
- package/dist/core/ops.js +2 -0
- package/dist/core/printer.d.ts +35 -0
- package/dist/core/printer.js +96 -0
- package/dist/core/rasterizer.d.ts +29 -0
- package/dist/core/rasterizer.js +199 -0
- package/dist/core/star-graphic-encoder.d.ts +12 -0
- package/dist/core/star-graphic-encoder.js +48 -0
- package/dist/core/star-line-encoder.d.ts +8 -0
- package/dist/core/star-line-encoder.js +119 -0
- package/dist/core/status.d.ts +22 -0
- package/dist/core/status.js +52 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +42 -0
- package/dist/label/builder.d.ts +39 -0
- package/dist/label/builder.js +37 -0
- package/dist/label/ezpl.d.ts +6 -0
- package/dist/label/ezpl.js +78 -0
- package/dist/label/index.d.ts +12 -0
- package/dist/label/index.js +42 -0
- package/dist/label/svg.d.ts +3 -0
- package/dist/label/svg.js +46 -0
- package/dist/label/template.d.ts +61 -0
- package/dist/label/template.js +33 -0
- package/dist/label/tspl.d.ts +3 -0
- package/dist/label/tspl.js +83 -0
- package/dist/label/types.d.ts +69 -0
- package/dist/label/types.js +10 -0
- package/dist/label/zpl.d.ts +3 -0
- package/dist/label/zpl.js +57 -0
- package/dist/preview/html.d.ts +14 -0
- package/dist/preview/html.js +132 -0
- package/dist/preview/index.d.ts +8 -0
- package/dist/preview/index.js +14 -0
- package/dist/preview/png.d.ts +3 -0
- package/dist/preview/png.js +89 -0
- package/dist/profiles/epson.d.ts +10 -0
- package/dist/profiles/epson.js +54 -0
- package/dist/profiles/index.d.ts +7 -0
- package/dist/profiles/index.js +36 -0
- package/dist/profiles/star.d.ts +7 -0
- package/dist/profiles/star.js +39 -0
- package/dist/profiles/types.d.ts +41 -0
- package/dist/profiles/types.js +2 -0
- package/dist/template/expr.d.ts +16 -0
- package/dist/template/expr.js +85 -0
- package/dist/template/index.d.ts +4 -0
- package/dist/template/index.js +27 -0
- package/dist/template/render.d.ts +8 -0
- package/dist/template/render.js +110 -0
- package/dist/template/types.d.ts +75 -0
- package/dist/template/types.js +2 -0
- package/dist/transports/net.d.ts +20 -0
- package/dist/transports/net.js +72 -0
- package/dist/transports/serial.d.ts +20 -0
- package/dist/transports/serial.js +71 -0
- package/dist/transports/types.d.ts +16 -0
- package/dist/transports/types.js +41 -0
- package/dist/transports/usb.d.ts +30 -0
- package/dist/transports/usb.js +128 -0
- package/dist/util/base64.d.ts +1 -0
- package/dist/util/base64.js +19 -0
- package/package.json +99 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arkaprova Majumder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
#
|
|
1
|
+
# retail-print-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Receipt printer and cash drawer driver for Node and Electron. ESC/POS and Star command sets,
|
|
4
|
+
printer profiles, USB / network / serial transports, no native dependency in the core.
|
|
5
|
+
|
|
6
|
+
Status: early development. Not published yet.
|
|
7
|
+
|
|
8
|
+
* Receipt command sets: ESC/POS (Epson and compatibles), Star Line Mode (TSP650 / mC-Print), Star raster (TSP100 / TSP143).
|
|
9
|
+
* Label languages: ZPL (Zebra), TSPL (TSC, Xprinter, Rongta), EZPL (Godex).
|
|
10
|
+
* Browser bundle (`retail-print-kit/browser`) with templates, previews and label encoders; a designer app in `apps/designer`.
|
|
11
|
+
* Transports: `retail-print-kit/net` (raw TCP :9100, no deps), `retail-print-kit/usb` (needs `usb`), `retail-print-kit/serial` (needs `serialport`).
|
|
12
|
+
* QR: native where the printer has it, bitmap fallback otherwise. Images: 1-bit `Bitmap` from RGBA.
|
|
13
|
+
* Status: `printer.status()` reads ESC/POS DLE EOT (online, cover, paper, cutter, drawer pin).
|
|
14
|
+
* Bitmap-only printers render through a canvas (`@napi-rs/canvas`, or pass your own factory in Electron).
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
const { Printer, profiles } = require('retail-print-kit');
|
|
18
|
+
const { NetTransport } = require('retail-print-kit/net');
|
|
19
|
+
|
|
20
|
+
const printer = new Printer(new NetTransport('192.168.1.50'), profiles.epsonTmT88);
|
|
21
|
+
await printer.open();
|
|
22
|
+
printer
|
|
23
|
+
.align('ct').style('b').size(2, 2).text('MY STORE')
|
|
24
|
+
.size(1, 1).style('normal').align('lt')
|
|
25
|
+
.tableCustom([{ text: 'Coffee', align: 'LEFT', width: 0.7 }, { text: '$2.50', align: 'RIGHT', width: 0.3 }])
|
|
26
|
+
.drawLine()
|
|
27
|
+
.feed(2).cut().cashdraw();
|
|
28
|
+
await printer.close();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Templates
|
|
32
|
+
|
|
33
|
+
A receipt can be a JSON layout rendered with data, which is what a visual designer will produce:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const { render } = require('retail-print-kit');
|
|
37
|
+
const template = {
|
|
38
|
+
name: 'receipt', version: 1,
|
|
39
|
+
blocks: [
|
|
40
|
+
{ type: 'text', value: '{{store.name | upper}}', align: 'center', style: 'b', size: [2, 2] },
|
|
41
|
+
{ type: 'table', rows: 'items', columns: [
|
|
42
|
+
{ value: '{{name}}', header: 'Item', width: 0.6 },
|
|
43
|
+
{ value: '{{qty}}', header: 'Qty', width: 0.1, align: 'CENTER' },
|
|
44
|
+
{ value: '{{total | money:$}}', header: 'Amount', width: 0.3, align: 'RIGHT' },
|
|
45
|
+
] },
|
|
46
|
+
{ type: 'row', cells: [{ value: 'TOTAL', width: 0.7 }, { value: '{{total | money:$}}', width: 0.3, align: 'RIGHT' }] },
|
|
47
|
+
{ type: 'if', when: 'customer', blocks: [{ type: 'text', value: 'Thanks {{customer.name}}' }] },
|
|
48
|
+
{ type: 'qr', value: 'https://example.com/r/{{id}}', align: 'center' },
|
|
49
|
+
{ type: 'cut' }, { type: 'drawer' },
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
printer.render(template, data); // appends to a Printer
|
|
53
|
+
const ops = render(template, data, profiles.epsonTmT88); // or just the ops
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Blocks: `text`, `line`, `row`, `table`, `feed`, `newline`, `cut`, `drawer`, `qr`, `barcode`, `each`, `if`.
|
|
57
|
+
Values use `{{path | filter}}`; filters: `upper`, `lower`, `trim`, `money[:prefix]`, `fixed[:n]`,
|
|
58
|
+
`pad:n`, `padEnd:n`, `default:x`, `date[:time|datetime]`, `count`. Inside `each`/`table` rows, `this`,
|
|
59
|
+
`@index` and `@number` refer to the current item.
|
|
60
|
+
|
|
61
|
+
## Labels
|
|
62
|
+
|
|
63
|
+
Labels are positioned elements on a fixed page, encoded for Zebra (ZPL), TSC and clones (TSPL) or
|
|
64
|
+
Godex (EZPL). Positions are in dots at the label's dpi; `mm()` converts.
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const { LabelBuilder, encodeZpl, encodeTspl, encodeEzpl, labelToSvg, renderLabel } = require('retail-print-kit');
|
|
68
|
+
const b = new LabelBuilder({ widthMm: 50.8, heightMm: 25.4, dpi: 203 });
|
|
69
|
+
b.text(18, 14, 'Coffee Beans 1lb', 26).text(92, 65, '$12.99', 85, { bold: true })
|
|
70
|
+
.barcode(35, 140, '036000291452', 'UPC_A', 35).qr(330, 20, 'https://x.io/i/1', { module: 3 });
|
|
71
|
+
const zpl = encodeZpl(b.label); // string
|
|
72
|
+
const svg = labelToSvg(b.label); // preview
|
|
73
|
+
const label = renderLabel(labelTemplate, data); // from a designer JSON
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Designer
|
|
77
|
+
|
|
78
|
+
`apps/designer/index.html` is a browser app (no build, no server) that edits receipt and label
|
|
79
|
+
templates with a live preview, drag-to-position for labels, sample data, and exports the JSON that
|
|
80
|
+
`render()` / `renderLabel()` and the CLI's `print --template` consume. Open it after `npm run build`.
|
|
81
|
+
|
|
82
|
+
## Preview and identify
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
printer.toHtml(); // paper-like HTML of the recorded ops
|
|
86
|
+
opsToHtml(ops, profile); opsToPng(ops, profile); // same without a Printer (PNG needs a canvas)
|
|
87
|
+
const id = await identify(transport); // { maker, model, firmware, set, profile }
|
|
88
|
+
profileForUsb(0x04b8); // profile from a USB vendor/product id
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## CLI
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
npx retail-print-kit test --net 192.168.1.50 --profile epson-tm-t20 # test page + status
|
|
95
|
+
npx retail-print-kit drawer --usb # kick the drawer
|
|
96
|
+
npx retail-print-kit status --serial /dev/ttyUSB0
|
|
97
|
+
npx retail-print-kit identify --net 192.168.1.50 # maker/model/firmware + suggested profile
|
|
98
|
+
npx retail-print-kit preview --profile star-tsp100 --out page.png # or .html, no printer needed
|
|
99
|
+
npx retail-print-kit print --template receipt.json --data sale.json --net 192.168.1.50
|
|
100
|
+
npx retail-print-kit print --template shelf.json --data item.json --language zpl --net 192.168.1.60
|
|
101
|
+
npx retail-print-kit profiles
|
|
102
|
+
npx retail-print-kit test --dry --profile star-tsp100 | head -c 200 # bytes only, no printer
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Docs: [ADR 0001](docs/adr/0001-replace-escpos.md), [printer matrix](docs/printer-matrix.md).
|
|
106
|
+
|
|
107
|
+
License: MIT, Arkaprova Majumder.
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { Printer, profiles, profileById, NetTransport, identify, opsToHtml, opsToPng, OpBuilder, render, renderLabel, encodeLabel, labelToSvg } = require('../dist');
|
|
5
|
+
|
|
6
|
+
process.stdout.on('error', (err) => {
|
|
7
|
+
if (err.code === 'EPIPE') process.exit(0);
|
|
8
|
+
throw err;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const USAGE = `retail-print-kit <command> [options]
|
|
12
|
+
|
|
13
|
+
Commands
|
|
14
|
+
test print a test page (text styles, table, barcode, QR) and show status
|
|
15
|
+
drawer kick the cash drawer
|
|
16
|
+
status print the printer status as JSON
|
|
17
|
+
identify ask the printer its maker, model and firmware; suggest a profile
|
|
18
|
+
preview write the test page as HTML (--out page.html) or PNG (--out page.png)
|
|
19
|
+
print print a template: --template t.json --data d.json (receipt or label)
|
|
20
|
+
a label needs --language zpl|tspl|ezpl; --out file.svg|.html|.txt previews instead
|
|
21
|
+
profiles list printer profiles
|
|
22
|
+
list list USB printers and serial ports
|
|
23
|
+
|
|
24
|
+
Connection (one of)
|
|
25
|
+
--net <host[:port]> raw TCP, port 9100 by default
|
|
26
|
+
--usb [<vid:pid>] first USB printer-class device, or the given ids (hex)
|
|
27
|
+
--serial <path> [--baud n] serial port, 9600 baud by default
|
|
28
|
+
|
|
29
|
+
Options
|
|
30
|
+
--profile <id> printer profile (default epson-tm-t88)
|
|
31
|
+
--pin 2|5 drawer pin for "drawer" (default 2)
|
|
32
|
+
--dry print the bytes as hex instead of sending
|
|
33
|
+
|
|
34
|
+
Examples
|
|
35
|
+
retail-print-kit test --net 192.168.1.50 --profile epson-tm-t20
|
|
36
|
+
retail-print-kit drawer --usb
|
|
37
|
+
retail-print-kit status --serial /dev/ttyUSB0`;
|
|
38
|
+
|
|
39
|
+
function parse(argv) {
|
|
40
|
+
const args = { _: [] };
|
|
41
|
+
for (let i = 0; i < argv.length; i++) {
|
|
42
|
+
const a = argv[i];
|
|
43
|
+
if (!a.startsWith('--')) {
|
|
44
|
+
args._.push(a);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const key = a.slice(2);
|
|
48
|
+
const next = argv[i + 1];
|
|
49
|
+
if (next !== undefined && !next.startsWith('--')) {
|
|
50
|
+
args[key] = next;
|
|
51
|
+
i++;
|
|
52
|
+
} else {
|
|
53
|
+
args[key] = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return args;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function transportFor(args) {
|
|
60
|
+
if (args.dry) {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
return {
|
|
63
|
+
name: 'dry',
|
|
64
|
+
chunks,
|
|
65
|
+
async open() {},
|
|
66
|
+
async write(b) { chunks.push(Buffer.from(b)); },
|
|
67
|
+
async close() { process.stdout.write(Buffer.concat(chunks).toString('hex') + '\n'); },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (args.net) {
|
|
71
|
+
const [host, port] = String(args.net).split(':');
|
|
72
|
+
return new NetTransport(host, { port: port ? Number(port) : undefined });
|
|
73
|
+
}
|
|
74
|
+
if (args.usb !== undefined) {
|
|
75
|
+
const { UsbTransport } = require('../dist/transports/usb');
|
|
76
|
+
if (args.usb === true) return new UsbTransport();
|
|
77
|
+
const [vid, pid] = String(args.usb).split(':');
|
|
78
|
+
return new UsbTransport({ vendorId: parseInt(vid, 16), productId: pid ? parseInt(pid, 16) : undefined });
|
|
79
|
+
}
|
|
80
|
+
if (args.serial) {
|
|
81
|
+
const { SerialTransport } = require('../dist/transports/serial');
|
|
82
|
+
return new SerialTransport(String(args.serial), { baudRate: args.baud ? Number(args.baud) : undefined });
|
|
83
|
+
}
|
|
84
|
+
throw new Error('give a connection: --net, --usb or --serial (or --dry)');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function withPrinter(args, fn) {
|
|
88
|
+
const profile = profileById(String(args.profile || 'epson-tm-t88'));
|
|
89
|
+
const printer = new Printer(transportFor(args), profile);
|
|
90
|
+
await printer.open();
|
|
91
|
+
try {
|
|
92
|
+
await fn(printer, profile);
|
|
93
|
+
} finally {
|
|
94
|
+
await printer.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function testPage(printer, profile) {
|
|
99
|
+
const now = new Date();
|
|
100
|
+
printer
|
|
101
|
+
.align('ct').style('b').size(2, 2).text('retail-print-kit').size(1, 1).style('normal')
|
|
102
|
+
.text(`${profile.vendor} ${profile.model}`)
|
|
103
|
+
.text(`profile ${profile.id} / ${profile.set} / ${profile.columns.a} cols`)
|
|
104
|
+
.text(now.toLocaleString())
|
|
105
|
+
.align('lt').drawLine()
|
|
106
|
+
.text('normal text')
|
|
107
|
+
.style('b').text('bold text').style('normal')
|
|
108
|
+
.style('u').text('underlined text').style('normal')
|
|
109
|
+
.size(2, 1).text('double width').size(1, 1)
|
|
110
|
+
.size(1, 2).text('double height').size(1, 1)
|
|
111
|
+
.setFont('b').text('font B: ' + '0123456789'.repeat(5)).setFont('a')
|
|
112
|
+
.drawLine()
|
|
113
|
+
.tableCustom([{ text: 'Item', width: 0.6 }, { text: 'Qty', width: 0.1, align: 'CENTER' }, { text: 'Amount', width: 0.3, align: 'RIGHT' }])
|
|
114
|
+
.tableCustom([{ text: 'Coffee, large, oat milk', width: 0.6 }, { text: '2', width: 0.1, align: 'CENTER' }, { text: '$5.00', width: 0.3, align: 'RIGHT' }])
|
|
115
|
+
.tableCustom([{ text: 'Bagel', width: 0.6 }, { text: '1', width: 0.1, align: 'CENTER' }, { text: '$7.50', width: 0.3, align: 'RIGHT' }])
|
|
116
|
+
.drawLine()
|
|
117
|
+
.tableCustom([{ text: 'TOTAL', width: 0.7, style: 'b' }, { text: '$12.50', width: 0.3, align: 'RIGHT' }])
|
|
118
|
+
.newLine()
|
|
119
|
+
.align('ct').barcode('036000291452', 'UPC_A', { height: 60, width: 2 }).newLine()
|
|
120
|
+
.qr('https://github.com/arka162/thermal-print', { size: 5 }).newLine()
|
|
121
|
+
.align('lt').text(`${'='.repeat(10)} end of test ${'='.repeat(10)}`)
|
|
122
|
+
.cut();
|
|
123
|
+
await printer.flush();
|
|
124
|
+
await showStatus(printer);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function showStatus(printer) {
|
|
128
|
+
if (!printer.transport.read) return;
|
|
129
|
+
try {
|
|
130
|
+
const s = await printer.status();
|
|
131
|
+
console.log(JSON.stringify(s));
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.log(`status: ${err.message}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function main() {
|
|
138
|
+
const args = parse(process.argv.slice(2));
|
|
139
|
+
const cmd = args._[0];
|
|
140
|
+
switch (cmd) {
|
|
141
|
+
case 'test':
|
|
142
|
+
return withPrinter(args, testPage);
|
|
143
|
+
case 'drawer':
|
|
144
|
+
return withPrinter(args, async (p) => { p.cashdraw(args.pin === '5' ? 5 : 2); });
|
|
145
|
+
case 'status':
|
|
146
|
+
return withPrinter(args, showStatus);
|
|
147
|
+
case 'identify': {
|
|
148
|
+
const t = transportFor(args);
|
|
149
|
+
await t.open();
|
|
150
|
+
try {
|
|
151
|
+
const id = await identify(t);
|
|
152
|
+
console.log(JSON.stringify({ ...id, profile: id.profile ? id.profile.id : null }));
|
|
153
|
+
} finally {
|
|
154
|
+
await t.close();
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
case 'print': {
|
|
159
|
+
const tpl = JSON.parse(fs.readFileSync(String(args.template), 'utf8'));
|
|
160
|
+
const data = args.data ? JSON.parse(fs.readFileSync(String(args.data), 'utf8')) : {};
|
|
161
|
+
if (tpl.kind === 'label') {
|
|
162
|
+
const label = renderLabel(tpl, data);
|
|
163
|
+
const language = String(args.language || 'zpl');
|
|
164
|
+
if (args.out) {
|
|
165
|
+
const out = String(args.out);
|
|
166
|
+
fs.writeFileSync(out, out.endsWith('.svg') ? labelToSvg(label) : Buffer.from(encodeLabel(label, language)));
|
|
167
|
+
console.log(`wrote ${out}`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const t = transportFor(args);
|
|
171
|
+
await t.open();
|
|
172
|
+
try { await t.write(Buffer.from(encodeLabel(label, language))); } finally { await t.close(); }
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const profile = profileById(String(args.profile || 'epson-tm-t88'));
|
|
176
|
+
if (args.out) {
|
|
177
|
+
const out = String(args.out);
|
|
178
|
+
const ops = render(tpl, data, profile);
|
|
179
|
+
fs.writeFileSync(out, out.endsWith('.png') ? opsToPng(ops, profile) : opsToHtml(ops, profile));
|
|
180
|
+
console.log(`wrote ${out}`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
return withPrinter(args, async (p) => { p.render(tpl, data); });
|
|
184
|
+
}
|
|
185
|
+
case 'preview': {
|
|
186
|
+
const profile = profileById(String(args.profile || 'epson-tm-t88'));
|
|
187
|
+
const out = String(args.out || 'preview.html');
|
|
188
|
+
const b = new OpBuilder(profile);
|
|
189
|
+
await testPage(Object.assign(b, { flush: async () => {}, transport: {} }), profile);
|
|
190
|
+
const ops = b.operations;
|
|
191
|
+
fs.writeFileSync(out, out.endsWith('.png') ? opsToPng(ops, profile) : opsToHtml(ops, profile));
|
|
192
|
+
console.log(`wrote ${out}`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
case 'profiles':
|
|
196
|
+
for (const p of Object.values(profiles)) console.log(`${p.id.padEnd(20)} ${p.set.padEnd(13)} ${p.paper}mm ${String(p.columns.a).padStart(3)} cols ${p.vendor} ${p.model}`);
|
|
197
|
+
return;
|
|
198
|
+
case 'list': {
|
|
199
|
+
try {
|
|
200
|
+
const { UsbTransport } = require('../dist/transports/usb');
|
|
201
|
+
for (const d of UsbTransport.list()) console.log(`usb ${d.vendorId.toString(16).padStart(4, '0')}:${d.productId.toString(16).padStart(4, '0')}`);
|
|
202
|
+
} catch (err) { console.log(`usb ${err.message}`); }
|
|
203
|
+
try {
|
|
204
|
+
const { SerialTransport } = require('../dist/transports/serial');
|
|
205
|
+
for (const p of await SerialTransport.list()) console.log(`serial ${p}`);
|
|
206
|
+
} catch (err) { console.log(`serial ${err.message}`); }
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
default:
|
|
210
|
+
console.log(USAGE);
|
|
211
|
+
process.exitCode = cmd ? 1 : 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
main().catch((err) => {
|
|
216
|
+
console.error(err.message || err);
|
|
217
|
+
process.exitCode = 1;
|
|
218
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";var RetailPrintKit=(()=>{var Hn=Object.create;var at=Object.defineProperty;var Qn=Object.getOwnPropertyDescriptor;var Vn=Object.getOwnPropertyNames;var Kn=Object.getPrototypeOf,Jn=Object.prototype.hasOwnProperty;var Yn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),jn=(e,t)=>{for(var n in t)at(e,n,{get:t[n],enumerable:!0})},Ce=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Vn(t))!Jn.call(e,i)&&i!==n&&at(e,i,{get:()=>t[i],enumerable:!(r=Qn(t,i))||r.enumerable});return e};var Wn=(e,t,n)=>(n=e!=null?Hn(Kn(e)):{},Ce(t||!e||!e.__esModule?at(n,"default",{value:e,enumerable:!0}):n,e)),Zn=e=>Ce(at({},"__esModule",{value:!0}),e);var Be=p((Mi,$e)=>{$e.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var B=p(P=>{var Pt,Xn=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];P.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};P.getSymbolTotalCodewords=function(t){return Xn[t]};P.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};P.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');Pt=t};P.isKanjiModeEnabled=function(){return typeof Pt<"u"};P.toSJIS=function(t){return Pt(t)}});var ut=p(x=>{x.L={bit:1};x.M={bit:0};x.Q={bit:3};x.H={bit:2};function tr(e){if(typeof e!="string")throw new Error("Param is not a string");switch(e.toLowerCase()){case"l":case"low":return x.L;case"m":case"medium":return x.M;case"q":case"quartile":return x.Q;case"h":case"high":return x.H;default:throw new Error("Unknown EC Level: "+e)}}x.isValid=function(t){return t&&typeof t.bit<"u"&&t.bit>=0&&t.bit<4};x.from=function(t,n){if(x.isValid(t))return t;try{return tr(t)}catch{return n}}});var Le=p((Pi,Me)=>{function Te(){this.buffer=[],this.length=0}Te.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};Me.exports=Te});var Pe=p((Ni,Se)=>{function Y(e){if(!e||e<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}Y.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)};Y.prototype.get=function(e,t){return this.data[e*this.size+t]};Y.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n};Y.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};Se.exports=Y});var Ne=p(ct=>{var er=B().getSymbolSize;ct.getRowColCoords=function(t){if(t===1)return[];let n=Math.floor(t/7)+2,r=er(t),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,o=[r-7];for(let s=1;s<n-1;s++)o[s]=o[s-1]-i;return o.push(6),o.reverse()};ct.getPositions=function(t){let n=[],r=ct.getRowColCoords(t),i=r.length;for(let o=0;o<i;o++)for(let s=0;s<i;s++)o===0&&s===0||o===0&&s===i-1||o===i-1&&s===0||n.push([r[o],r[s]]);return n}});var ke=p(Re=>{var nr=B().getSymbolSize,Ie=7;Re.getPositions=function(t){let n=nr(t);return[[0,0],[n-Ie,0],[0,n-Ie]]}});var Ue=p(m=>{m.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var N={N1:3,N2:3,N3:40,N4:10};m.isValid=function(t){return t!=null&&t!==""&&!isNaN(t)&&t>=0&&t<=7};m.from=function(t){return m.isValid(t)?parseInt(t,10):void 0};m.getPenaltyN1=function(t){let n=t.size,r=0,i=0,o=0,s=null,a=null;for(let u=0;u<n;u++){i=o=0,s=a=null;for(let c=0;c<n;c++){let f=t.get(u,c);f===s?i++:(i>=5&&(r+=N.N1+(i-5)),s=f,i=1),f=t.get(c,u),f===a?o++:(o>=5&&(r+=N.N1+(o-5)),a=f,o=1)}i>=5&&(r+=N.N1+(i-5)),o>=5&&(r+=N.N1+(o-5))}return r};m.getPenaltyN2=function(t){let n=t.size,r=0;for(let i=0;i<n-1;i++)for(let o=0;o<n-1;o++){let s=t.get(i,o)+t.get(i,o+1)+t.get(i+1,o)+t.get(i+1,o+1);(s===4||s===0)&&r++}return r*N.N2};m.getPenaltyN3=function(t){let n=t.size,r=0,i=0,o=0;for(let s=0;s<n;s++){i=o=0;for(let a=0;a<n;a++)i=i<<1&2047|t.get(s,a),a>=10&&(i===1488||i===93)&&r++,o=o<<1&2047|t.get(a,s),a>=10&&(o===1488||o===93)&&r++}return r*N.N3};m.getPenaltyN4=function(t){let n=0,r=t.data.length;for(let o=0;o<r;o++)n+=t.data[o];return Math.abs(Math.ceil(n*100/r/5)-10)*N.N4};function rr(e,t,n){switch(e){case m.Patterns.PATTERN000:return(t+n)%2===0;case m.Patterns.PATTERN001:return t%2===0;case m.Patterns.PATTERN010:return n%3===0;case m.Patterns.PATTERN011:return(t+n)%3===0;case m.Patterns.PATTERN100:return(Math.floor(t/2)+Math.floor(n/3))%2===0;case m.Patterns.PATTERN101:return t*n%2+t*n%3===0;case m.Patterns.PATTERN110:return(t*n%2+t*n%3)%2===0;case m.Patterns.PATTERN111:return(t*n%3+(t+n)%2)%2===0;default:throw new Error("bad maskPattern:"+e)}}m.applyMask=function(t,n){let r=n.size;for(let i=0;i<r;i++)for(let o=0;o<r;o++)n.isReserved(o,i)||n.xor(o,i,rr(t,o,i))};m.getBestMask=function(t,n){let r=Object.keys(m.Patterns).length,i=0,o=1/0;for(let s=0;s<r;s++){n(s),m.applyMask(s,t);let a=m.getPenaltyN1(t)+m.getPenaltyN2(t)+m.getPenaltyN3(t)+m.getPenaltyN4(t);m.applyMask(s,t),a<o&&(o=a,i=s)}return i}});var It=p(Nt=>{var T=ut(),lt=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],ft=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];Nt.getBlocksCount=function(t,n){switch(n){case T.L:return lt[(t-1)*4+0];case T.M:return lt[(t-1)*4+1];case T.Q:return lt[(t-1)*4+2];case T.H:return lt[(t-1)*4+3];default:return}};Nt.getTotalCodewordsCount=function(t,n){switch(n){case T.L:return ft[(t-1)*4+0];case T.M:return ft[(t-1)*4+1];case T.Q:return ft[(t-1)*4+2];case T.H:return ft[(t-1)*4+3];default:return}}});var De=p(dt=>{var j=new Uint8Array(512),ht=new Uint8Array(256);(function(){let t=1;for(let n=0;n<255;n++)j[n]=t,ht[t]=n,t<<=1,t&256&&(t^=285);for(let n=255;n<512;n++)j[n]=j[n-255]})();dt.log=function(t){if(t<1)throw new Error("log("+t+")");return ht[t]};dt.exp=function(t){return j[t]};dt.mul=function(t,n){return t===0||n===0?0:j[ht[t]+ht[n]]}});var Fe=p(W=>{var Rt=De();W.mul=function(t,n){let r=new Uint8Array(t.length+n.length-1);for(let i=0;i<t.length;i++)for(let o=0;o<n.length;o++)r[i+o]^=Rt.mul(t[i],n[o]);return r};W.mod=function(t,n){let r=new Uint8Array(t);for(;r.length-n.length>=0;){let i=r[0];for(let s=0;s<n.length;s++)r[s]^=Rt.mul(n[s],i);let o=0;for(;o<r.length&&r[o]===0;)o++;r=r.slice(o)}return r};W.generateECPolynomial=function(t){let n=new Uint8Array([1]);for(let r=0;r<t;r++)n=W.mul(n,new Uint8Array([1,Rt.exp(r)]));return n}});var ve=p((Oi,qe)=>{var Oe=Fe();function kt(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}kt.prototype.initialize=function(t){this.degree=t,this.genPoly=Oe.generateECPolynomial(this.degree)};kt.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");let n=new Uint8Array(t.length+this.degree);n.set(t);let r=Oe.mod(n,this.genPoly),i=this.degree-r.length;if(i>0){let o=new Uint8Array(this.degree);return o.set(r,i),o}return r};qe.exports=kt});var Ut=p(_e=>{_e.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}});var Dt=p($=>{var ze="[0-9]+",ir="[A-Z $%*+\\-./:]+",Z="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Z=Z.replace(/u/g,"\\u");var or="(?:(?![A-Z0-9 $%*+\\-./:]|"+Z+`)(?:.|[\r
|
|
2
|
+
]))+`;$.KANJI=new RegExp(Z,"g");$.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");$.BYTE=new RegExp(or,"g");$.NUMERIC=new RegExp(ze,"g");$.ALPHANUMERIC=new RegExp(ir,"g");var sr=new RegExp("^"+Z+"$"),ar=new RegExp("^"+ze+"$"),ur=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");$.testKanji=function(t){return sr.test(t)};$.testNumeric=function(t){return ar.test(t)};$.testAlphanumeric=function(t){return ur.test(t)}});var M=p(b=>{var cr=Ut(),Ft=Dt();b.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]};b.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]};b.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]};b.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]};b.MIXED={bit:-1};b.getCharCountIndicator=function(t,n){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!cr.isValid(n))throw new Error("Invalid version: "+n);return n>=1&&n<10?t.ccBits[0]:n<27?t.ccBits[1]:t.ccBits[2]};b.getBestModeForData=function(t){return Ft.testNumeric(t)?b.NUMERIC:Ft.testAlphanumeric(t)?b.ALPHANUMERIC:Ft.testKanji(t)?b.KANJI:b.BYTE};b.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")};b.isValid=function(t){return t&&t.bit&&t.ccBits};function lr(e){if(typeof e!="string")throw new Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return b.NUMERIC;case"alphanumeric":return b.ALPHANUMERIC;case"kanji":return b.KANJI;case"byte":return b.BYTE;default:throw new Error("Unknown mode: "+e)}}b.from=function(t,n){if(b.isValid(t))return t;try{return lr(t)}catch{return n}}});var Ke=p(I=>{var gt=B(),fr=It(),Ge=ut(),L=M(),Ot=Ut(),Qe=7973,He=gt.getBCHDigit(Qe);function hr(e,t,n){for(let r=1;r<=40;r++)if(t<=I.getCapacity(r,n,e))return r}function Ve(e,t){return L.getCharCountIndicator(e,t)+4}function dr(e,t){let n=0;return e.forEach(function(r){let i=Ve(r.mode,t);n+=i+r.getBitsLength()}),n}function gr(e,t){for(let n=1;n<=40;n++)if(dr(e,n)<=I.getCapacity(n,t,L.MIXED))return n}I.from=function(t,n){return Ot.isValid(t)?parseInt(t,10):n};I.getCapacity=function(t,n,r){if(!Ot.isValid(t))throw new Error("Invalid QR Code version");typeof r>"u"&&(r=L.BYTE);let i=gt.getSymbolTotalCodewords(t),o=fr.getTotalCodewordsCount(t,n),s=(i-o)*8;if(r===L.MIXED)return s;let a=s-Ve(r,t);switch(r){case L.NUMERIC:return Math.floor(a/10*3);case L.ALPHANUMERIC:return Math.floor(a/11*2);case L.KANJI:return Math.floor(a/13);case L.BYTE:default:return Math.floor(a/8)}};I.getBestVersionForData=function(t,n){let r,i=Ge.from(n,Ge.M);if(Array.isArray(t)){if(t.length>1)return gr(t,i);if(t.length===0)return 1;r=t[0]}else r=t;return hr(r.mode,r.getLength(),i)};I.getEncodedBits=function(t){if(!Ot.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;gt.getBCHDigit(n)-He>=0;)n^=Qe<<gt.getBCHDigit(n)-He;return t<<12|n}});var We=p(je=>{var qt=B(),Ye=1335,pr=21522,Je=qt.getBCHDigit(Ye);je.getEncodedBits=function(t,n){let r=t.bit<<3|n,i=r<<10;for(;qt.getBCHDigit(i)-Je>=0;)i^=Ye<<qt.getBCHDigit(i)-Je;return(r<<10|i)^pr}});var Xe=p((Hi,Ze)=>{var mr=M();function F(e){this.mode=mr.NUMERIC,this.data=e.toString()}F.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};F.prototype.getLength=function(){return this.data.length};F.prototype.getBitsLength=function(){return F.getBitsLength(this.data.length)};F.prototype.write=function(t){let n,r,i;for(n=0;n+3<=this.data.length;n+=3)r=this.data.substr(n,3),i=parseInt(r,10),t.put(i,10);let o=this.data.length-n;o>0&&(r=this.data.substr(n),i=parseInt(r,10),t.put(i,o*3+1))};Ze.exports=F});var en=p((Qi,tn)=>{var wr=M(),vt=["0","1","2","3","4","5","6","7","8","9","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"," ","$","%","*","+","-",".","/",":"];function O(e){this.mode=wr.ALPHANUMERIC,this.data=e}O.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};O.prototype.getLength=function(){return this.data.length};O.prototype.getBitsLength=function(){return O.getBitsLength(this.data.length)};O.prototype.write=function(t){let n;for(n=0;n+2<=this.data.length;n+=2){let r=vt.indexOf(this.data[n])*45;r+=vt.indexOf(this.data[n+1]),t.put(r,11)}this.data.length%2&&t.put(vt.indexOf(this.data[n]),6)};tn.exports=O});var rn=p((Vi,nn)=>{var br=M();function q(e){this.mode=br.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}q.getBitsLength=function(t){return t*8};q.prototype.getLength=function(){return this.data.length};q.prototype.getBitsLength=function(){return q.getBitsLength(this.data.length)};q.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};nn.exports=q});var sn=p((Ki,on)=>{var yr=M(),xr=B();function v(e){this.mode=yr.KANJI,this.data=e}v.getBitsLength=function(t){return t*13};v.prototype.getLength=function(){return this.data.length};v.prototype.getBitsLength=function(){return v.getBitsLength(this.data.length)};v.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=xr.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
|
|
3
|
+
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}};on.exports=v});var an=p((Ji,_t)=>{"use strict";var X={single_source_shortest_paths:function(e,t,n){var r={},i={};i[t]=0;var o=X.PriorityQueue.make();o.push(t,0);for(var s,a,u,c,f,g,l,h,w;!o.empty();){s=o.pop(),a=s.value,c=s.cost,f=e[a]||{};for(u in f)f.hasOwnProperty(u)&&(g=f[u],l=c+g,h=i[u],w=typeof i[u]>"u",(w||h>l)&&(i[u]=l,o.push(u,l),r[u]=a))}if(typeof n<"u"&&typeof i[n]>"u"){var y=["Could not find a path from ",t," to ",n,"."].join("");throw new Error(y)}return r},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t,i;r;)n.push(r),i=e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,n){var r=X.single_source_shortest_paths(e,t,n);return X.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(e){var t=X.PriorityQueue,n={},r;e=e||{};for(r in t)t.hasOwnProperty(r)&&(n[r]=t[r]);return n.queue=[],n.sorter=e.sorter||t.default_sorter,n},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};typeof _t<"u"&&(_t.exports=X)});var pn=p(_=>{var d=M(),ln=Xe(),fn=en(),hn=rn(),dn=sn(),tt=Dt(),pt=B(),Er=an();function un(e){return unescape(encodeURIComponent(e)).length}function et(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function gn(e){let t=et(tt.NUMERIC,d.NUMERIC,e),n=et(tt.ALPHANUMERIC,d.ALPHANUMERIC,e),r,i;return pt.isKanjiModeEnabled()?(r=et(tt.BYTE,d.BYTE,e),i=et(tt.KANJI,d.KANJI,e)):(r=et(tt.BYTE_KANJI,d.BYTE,e),i=[]),t.concat(n,r,i).sort(function(s,a){return s.index-a.index}).map(function(s){return{data:s.data,mode:s.mode,length:s.length}})}function zt(e,t){switch(t){case d.NUMERIC:return ln.getBitsLength(e);case d.ALPHANUMERIC:return fn.getBitsLength(e);case d.KANJI:return dn.getBitsLength(e);case d.BYTE:return hn.getBitsLength(e)}}function Ar(e){return e.reduce(function(t,n){let r=t.length-1>=0?t[t.length-1]:null;return r&&r.mode===n.mode?(t[t.length-1].data+=n.data,t):(t.push(n),t)},[])}function Cr(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];switch(r.mode){case d.NUMERIC:t.push([r,{data:r.data,mode:d.ALPHANUMERIC,length:r.length},{data:r.data,mode:d.BYTE,length:r.length}]);break;case d.ALPHANUMERIC:t.push([r,{data:r.data,mode:d.BYTE,length:r.length}]);break;case d.KANJI:t.push([r,{data:r.data,mode:d.BYTE,length:un(r.data)}]);break;case d.BYTE:t.push([{data:r.data,mode:d.BYTE,length:un(r.data)}])}}return t}function $r(e,t){let n={},r={start:{}},i=["start"];for(let o=0;o<e.length;o++){let s=e[o],a=[];for(let u=0;u<s.length;u++){let c=s[u],f=""+o+u;a.push(f),n[f]={node:c,lastCount:0},r[f]={};for(let g=0;g<i.length;g++){let l=i[g];n[l]&&n[l].node.mode===c.mode?(r[l][f]=zt(n[l].lastCount+c.length,c.mode)-zt(n[l].lastCount,c.mode),n[l].lastCount+=c.length):(n[l]&&(n[l].lastCount=c.length),r[l][f]=zt(c.length,c.mode)+4+d.getCharCountIndicator(c.mode,t))}}i=a}for(let o=0;o<i.length;o++)r[i[o]].end=0;return{map:r,table:n}}function cn(e,t){let n,r=d.getBestModeForData(e);if(n=d.from(t,r),n!==d.BYTE&&n.bit<r.bit)throw new Error('"'+e+'" cannot be encoded with mode '+d.toString(n)+`.
|
|
4
|
+
Suggested mode is: `+d.toString(r));switch(n===d.KANJI&&!pt.isKanjiModeEnabled()&&(n=d.BYTE),n){case d.NUMERIC:return new ln(e);case d.ALPHANUMERIC:return new fn(e);case d.KANJI:return new dn(e);case d.BYTE:return new hn(e)}}_.fromArray=function(t){return t.reduce(function(n,r){return typeof r=="string"?n.push(cn(r,null)):r.data&&n.push(cn(r.data,r.mode)),n},[])};_.fromString=function(t,n){let r=gn(t,pt.isKanjiModeEnabled()),i=Cr(r),o=$r(i,n),s=Er.find_path(o.map,"start","end"),a=[];for(let u=1;u<s.length-1;u++)a.push(o.table[s[u]].node);return _.fromArray(Ar(a))};_.rawSplit=function(t){return _.fromArray(gn(t,pt.isKanjiModeEnabled()))}});var wn=p(mn=>{var wt=B(),Gt=ut(),Br=Le(),Tr=Pe(),Mr=Ne(),Lr=ke(),Vt=Ue(),Kt=It(),Sr=ve(),mt=Ke(),Pr=We(),Nr=M(),Ht=pn();function Ir(e,t){let n=e.size,r=Lr.getPositions(t);for(let i=0;i<r.length;i++){let o=r[i][0],s=r[i][1];for(let a=-1;a<=7;a++)if(!(o+a<=-1||n<=o+a))for(let u=-1;u<=7;u++)s+u<=-1||n<=s+u||(a>=0&&a<=6&&(u===0||u===6)||u>=0&&u<=6&&(a===0||a===6)||a>=2&&a<=4&&u>=2&&u<=4?e.set(o+a,s+u,!0,!0):e.set(o+a,s+u,!1,!0))}}function Rr(e){let t=e.size;for(let n=8;n<t-8;n++){let r=n%2===0;e.set(n,6,r,!0),e.set(6,n,r,!0)}}function kr(e,t){let n=Mr.getPositions(t);for(let r=0;r<n.length;r++){let i=n[r][0],o=n[r][1];for(let s=-2;s<=2;s++)for(let a=-2;a<=2;a++)s===-2||s===2||a===-2||a===2||s===0&&a===0?e.set(i+s,o+a,!0,!0):e.set(i+s,o+a,!1,!0)}}function Ur(e,t){let n=e.size,r=mt.getEncodedBits(t),i,o,s;for(let a=0;a<18;a++)i=Math.floor(a/3),o=a%3+n-8-3,s=(r>>a&1)===1,e.set(i,o,s,!0),e.set(o,i,s,!0)}function Qt(e,t,n){let r=e.size,i=Pr.getEncodedBits(t,n),o,s;for(o=0;o<15;o++)s=(i>>o&1)===1,o<6?e.set(o,8,s,!0):o<8?e.set(o+1,8,s,!0):e.set(r-15+o,8,s,!0),o<8?e.set(8,r-o-1,s,!0):o<9?e.set(8,15-o-1+1,s,!0):e.set(8,15-o-1,s,!0);e.set(r-8,8,1,!0)}function Dr(e,t){let n=e.size,r=-1,i=n-1,o=7,s=0;for(let a=n-1;a>0;a-=2)for(a===6&&a--;;){for(let u=0;u<2;u++)if(!e.isReserved(i,a-u)){let c=!1;s<t.length&&(c=(t[s]>>>o&1)===1),e.set(i,a-u,c),o--,o===-1&&(s++,o=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function Fr(e,t,n){let r=new Br;n.forEach(function(u){r.put(u.mode.bit,4),r.put(u.getLength(),Nr.getCharCountIndicator(u.mode,e)),u.write(r)});let i=wt.getSymbolTotalCodewords(e),o=Kt.getTotalCodewordsCount(e,t),s=(i-o)*8;for(r.getLengthInBits()+4<=s&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);let a=(s-r.getLengthInBits())/8;for(let u=0;u<a;u++)r.put(u%2?17:236,8);return Or(r,e,t)}function Or(e,t,n){let r=wt.getSymbolTotalCodewords(t),i=Kt.getTotalCodewordsCount(t,n),o=r-i,s=Kt.getBlocksCount(t,n),a=r%s,u=s-a,c=Math.floor(r/s),f=Math.floor(o/s),g=f+1,l=c-f,h=new Sr(l),w=0,y=new Array(s),Ee=new Array(s),Mt=0,Gn=new Uint8Array(e.buffer);for(let D=0;D<s;D++){let St=D<u?f:g;y[D]=Gn.slice(w,w+St),Ee[D]=h.encode(y[D]),w+=St,Mt=Math.max(Mt,St)}let Lt=new Uint8Array(r),Ae=0,A,C;for(A=0;A<Mt;A++)for(C=0;C<s;C++)A<y[C].length&&(Lt[Ae++]=y[C][A]);for(A=0;A<l;A++)for(C=0;C<s;C++)Lt[Ae++]=Ee[C][A];return Lt}function qr(e,t,n,r){let i;if(Array.isArray(e))i=Ht.fromArray(e);else if(typeof e=="string"){let c=t;if(!c){let f=Ht.rawSplit(e);c=mt.getBestVersionForData(f,n)}i=Ht.fromString(e,c||40)}else throw new Error("Invalid data");let o=mt.getBestVersionForData(i,n);if(!o)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=o;else if(t<o)throw new Error(`
|
|
5
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
+
Minimum version required to store current data is: `+o+`.
|
|
7
|
+
`);let s=Fr(t,n,i),a=wt.getSymbolSize(t),u=new Tr(a);return Ir(u,t),Rr(u),kr(u,t),Qt(u,n,0),t>=7&&Ur(u,t),Dr(u,s),isNaN(r)&&(r=Vt.getBestMask(u,Qt.bind(null,u,n))),Vt.applyMask(r,u),Qt(u,n,r),{modules:u,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}mn.create=function(t,n){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Gt.M,i,o;return typeof n<"u"&&(r=Gt.from(n.errorCorrectionLevel,Gt.M),i=mt.from(n.version),o=Vt.from(n.maskPattern),n.toSJISFunc&&wt.setToSJISFunction(n.toSJISFunc)),qr(t,i,r,o)}});var Jt=p(R=>{function bn(e){if(typeof e=="number"&&(e=e.toString()),typeof e!="string")throw new Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||t.length===5||t.length>8)throw new Error("Invalid hex color: "+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(r){return[r,r]}))),t.length===6&&t.push("F","F");let n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:"#"+t.slice(0,6).join("")}}R.getOptions=function(t){t||(t={}),t.color||(t.color={});let n=typeof t.margin>"u"||t.margin===null||t.margin<0?4:t.margin,r=t.width&&t.width>=21?t.width:void 0,i=t.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:bn(t.color.dark||"#000000ff"),light:bn(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}};R.getScale=function(t,n){return n.width&&n.width>=t+n.margin*2?n.width/(t+n.margin*2):n.scale};R.getImageWidth=function(t,n){let r=R.getScale(t,n);return Math.floor((t+n.margin*2)*r)};R.qrToImageData=function(t,n,r){let i=n.modules.size,o=n.modules.data,s=R.getScale(i,r),a=Math.floor((i+r.margin*2)*s),u=r.margin*s,c=[r.color.light,r.color.dark];for(let f=0;f<a;f++)for(let g=0;g<a;g++){let l=(f*a+g)*4,h=r.color.light;if(f>=u&&g>=u&&f<a-u&&g<a-u){let w=Math.floor((f-u)/s),y=Math.floor((g-u)/s);h=c[o[w*i+y]?1:0]}t[l++]=h.r,t[l++]=h.g,t[l++]=h.b,t[l]=h.a}}});var yn=p(bt=>{var Yt=Jt();function vr(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||(t.style={}),t.height=n,t.width=n,t.style.height=n+"px",t.style.width=n+"px"}function _r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}bt.render=function(t,n,r){let i=r,o=n;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),n||(o=_r()),i=Yt.getOptions(i);let s=Yt.getImageWidth(t.modules.size,i),a=o.getContext("2d"),u=a.createImageData(s,s);return Yt.qrToImageData(u.data,t,i),vr(a,o,s),a.putImageData(u,0,0),o};bt.renderToDataURL=function(t,n,r){let i=r;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),i||(i={});let o=bt.render(t,n,i),s=i.type||"image/png",a=i.rendererOpts||{};return o.toDataURL(s,a.quality)}});var An=p(En=>{var zr=Jt();function xn(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function jt(e,t,n){let r=e+t;return typeof n<"u"&&(r+=" "+n),r}function Gr(e,t,n){let r="",i=0,o=!1,s=0;for(let a=0;a<e.length;a++){let u=Math.floor(a%t),c=Math.floor(a/t);!u&&!o&&(o=!0),e[a]?(s++,a>0&&u>0&&e[a-1]||(r+=o?jt("M",u+n,.5+c+n):jt("m",i,0),i=0,o=!1),u+1<t&&e[a+1]||(r+=jt("h",s),s=0)):i++}return r}En.render=function(t,n,r){let i=zr.getOptions(n),o=t.modules.size,s=t.modules.data,a=o+i.margin*2,u=i.color.light.a?"<path "+xn(i.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",c="<path "+xn(i.color.dark,"stroke")+' d="'+Gr(s,o,i.margin)+'"/>',f='viewBox="0 0 '+a+" "+a+'"',l='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+f+' shape-rendering="crispEdges">'+u+c+`</svg>
|
|
8
|
+
`;return typeof r=="function"&&r(null,l),l}});var $n=p(nt=>{var Hr=Be(),Wt=wn(),Cn=yn(),Qr=An();function Zt(e,t,n,r,i){let o=[].slice.call(arguments,1),s=o.length,a=typeof o[s-1]=="function";if(!a&&!Hr())throw new Error("Callback required as last argument");if(a){if(s<2)throw new Error("Too few arguments provided");s===2?(i=n,n=t,t=r=void 0):s===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=n,n=t,t=void 0))}else{if(s<1)throw new Error("Too few arguments provided");return s===1?(n=t,t=r=void 0):s===2&&!t.getContext&&(r=n,n=t,t=void 0),new Promise(function(u,c){try{let f=Wt.create(n,r);u(e(f,t,r))}catch(f){c(f)}})}try{let u=Wt.create(n,r);i(null,e(u,t,r))}catch(u){i(u)}}nt.create=Wt.create;nt.toCanvas=Zt.bind(null,Cn.render);nt.toDataURL=Zt.bind(null,Cn.renderToDataURL);nt.toString=Zt.bind(null,function(e,t,n){return Qr.render(e,n)})});var Bi={};jn(Bi,{LabelBuilder:()=>J,OpBuilder:()=>rt,barcodeBitmap:()=>it,bitmapToPng:()=>S,blit:()=>Tn,code128:()=>Ln,code39:()=>Rn,dotsToMm:()=>K,ean13:()=>ee,ean8:()=>In,emptyBitmap:()=>z,encodeEzpl:()=>Tt,encodeLabel:()=>$i,encodeTspl:()=>Bt,encodeZpl:()=>$t,epsonTmM30:()=>ie,epsonTmT20:()=>re,epsonTmT88:()=>ne,evaluate:()=>U,filters:()=>le,fitWidth:()=>Kr,fromRgba:()=>Vr,genericEscPos:()=>Et,genericEscPos58:()=>oe,getPixel:()=>yt,interpolate:()=>E,labelToSvg:()=>_n,lookup:()=>fe,mmToDots:()=>st,opsToHtml:()=>On,parseStyle:()=>Mn,pattern:()=>kn,profileById:()=>ai,profiles:()=>Un,qrBitmap:()=>k,render:()=>Fn,renderBlocks:()=>Q,renderLabel:()=>zn,setPixel:()=>G,starMcPrint3:()=>ue,starTsp100:()=>ce,starTsp650:()=>ae,toBase64:()=>V,truthy:()=>H,upcA:()=>Nn});var Bn=Wn($n());function z(e,t){return{width:e,height:t,bits:new Uint8Array(Math.ceil(e/8)*t)}}function G(e,t,n,r){if(t<0||n<0||t>=e.width||n>=e.height)return;let i=n*Math.ceil(e.width/8)+(t>>3),o=128>>(t&7);r?e.bits[i]|=o:e.bits[i]&=~o}function yt(e,t,n){return t<0||n<0||t>=e.width||n>=e.height?!1:(e.bits[n*Math.ceil(e.width/8)+(t>>3)]&128>>(t&7))!==0}function Vr(e,t,n,r=128){let i=z(t,n);for(let o=0;o<n;o++)for(let s=0;s<t;s++){let a=(o*t+s)*4,u=e[a+3]/255;(.299*e[a]+.587*e[a+1]+.114*e[a+2])*u+255*(1-u)<r&&G(i,s,o,!0)}return i}function Tn(e,t,n,r){for(let i=0;i<t.height;i++)for(let o=0;o<t.width;o++)yt(t,o,i)&&G(e,n+o,r+i,!0)}function Kr(e,t,n="center"){if(e.width===t)return e;let r=z(t,e.height),i=n==="left"?0:n==="right"?t-e.width:Math.floor((t-e.width)/2);return Tn(r,e,i,0),r}function k(e,t={}){let n=Bn.default.create(e,{errorCorrectionLevel:t.correction??"M"}),r=n.modules.size,i=Math.max(1,Math.min(16,Math.floor(t.size??6))),o=z(r*i,r*i);for(let s=0;s<r;s++)for(let a=0;a<r;a++)if(n.modules.get(s,a))for(let u=0;u<i;u++)for(let c=0;c<i;c++)G(o,a*i+c,s*i+u,!0);return o}var Jr={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},rt=class{constructor(t){this.profile=t;this.ops=[];this.font="a"}get operations(){return this.ops.slice()}append(t){for(let n of t)this.ops.push(n);return this}get columns(){return this.profile.columns[this.font]}push(t){return this.ops.push(t),this}raw(t){return this.push({kind:"raw",bytes:Uint8Array.from(t)})}text(t){return this.push({kind:"text",text:`${t}
|
|
9
|
+
`})}print(t){return this.push({kind:"text",text:t})}newLine(t=1){return this.push({kind:"newline",count:t})}feed(t=1){return this.push({kind:"feed",lines:t})}align(t){let n=Jr[t];if(!n)throw new Error(`retail-print-kit: unknown align "${t}"`);return this.push({kind:"align",align:n})}setFont(t){return this.font=t,this.push({kind:"font",font:t})}size(t,n){return this.push({kind:"size",width:t,height:n})}style(t){let n=typeof t=="string"?Mn(t):t;return this.push({kind:"style",style:n})}lineSpace(t=null){return this.push({kind:"lineSpacing",dots:t})}cut(t=!1,n=3){return this.push({kind:"cut",partial:t,feed:n})}cashdraw(t=2){return this.push({kind:"drawer",pin:t})}beep(t=1,n=1){return this.push({kind:"beep",times:t,duration:n})}barcode(t,n="CODE128",r={}){return this.push({kind:"barcode",data:t,type:n,options:r})}qr(t,n={}){return this.profile.features.nativeQr||this.profile.set==="star-graphic"?this.push({kind:"qr",data:t,options:n}):this.image(k(t,n))}image(t){return this.push({kind:"raster",width:t.width,height:t.height,bits:t.bits})}qrimage(t,n={}){return this.qr(t,n)}drawLine(t="-"){return this.text(t.repeat(this.columns))}tableCustom(t,n={}){let r=n.width??this.columns,i=Yr(t,r),o=n.wrap!==!1,s=t.map((u,c)=>o?jr(u.text??"",i[c]):[String(u.text??"").slice(0,i[c])]),a=Math.max(1,...s.map(u=>u.length));for(let u=0;u<a;u++){let c="";t.forEach((f,g)=>{c+=Wr(s[g][u]??"",i[g],f.align??"LEFT")}),this.text(c.replace(/\s+$/,""))}return this}};function Mn(e){if(e==="normal")return{bold:!1,underline:0,italic:!1,invert:!1};let t=e.toLowerCase();return{bold:t.includes("b"),italic:t.includes("i"),underline:t.includes("u2")?2:t.includes("u")?1:0,invert:!1}}function Yr(e,t){let n=e.map(u=>u.width===void 0?null:u.width>1?Math.floor(u.width):Math.floor(u.width*t)),r=n.reduce((u,c)=>u+(c??0),0),i=n.filter(u=>u===null).length,o=i?Math.floor(Math.max(0,t-r)/i):0,s=n.map(u=>u===null?o:u),a=s.reduce((u,c)=>u+c,0);return a<t&&(s[s.length-1]+=t-a),s}function jr(e,t){if(t<=0)return[""];let n=[];for(let r of String(e).split(`
|
|
10
|
+
`)){let i="";for(let o of r.split(/\s+/)){if(!o)continue;if(o.length>t){i&&n.push(i),i="";for(let a=0;a<o.length;a+=t)n.push(o.slice(a,a+t));continue}let s=i?`${i} ${o}`:o;s.length>t?(n.push(i),i=o):i=s}n.push(i)}return n.length?n:[""]}function Wr(e,t,n){let r=e.slice(0,t),i=t-r.length;if(n==="RIGHT")return" ".repeat(i)+r;if(n==="CENTER"){let o=Math.floor(i/2);return" ".repeat(o)+r+" ".repeat(i-o)}return r+" ".repeat(i)}var Zr=["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"],Xr=104,ti=105,ei=100,ni=99,ri=106;function Ln(e){if(!/^[\x20-\x7e]*$/.test(e)||!e.length)throw new Error("retail-print-kit: CODE128 needs printable ASCII");let t=[],n=0,r=null,i=a=>{let u=0;for(;a+u<e.length&&/[0-9]/.test(e[a+u]);)u++;return u};for(;n<e.length;){let a=i(n);if(a>=4||a>=2&&a===e.length-n){r!=="C"&&(t.push(r===null?ti:ni),r="C");let c=Math.floor(a/2);for(let f=0;f<c;f++)t.push(parseInt(e.slice(n,n+2),10)),n+=2;continue}r!=="B"&&(t.push(r===null?Xr:ei),r="B"),t.push(e.charCodeAt(n)-32),n++}let o=t[0];for(let a=1;a<t.length;a++)o+=t[a]*a;t.push(o%103,ri);let s=[];for(let a of t)for(let u of Zr[a])s.push(Number(u));return s}var Sn=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],ii=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],Pn=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],oi=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function Xt(e){let t=0;for(let n=0;n<e.length;n++){let r=(e.length-n)%2===0?1:3;t+=Number(e[n])*r}return(10-t%10)%10}function te(e){let t=[],n="1",r=0;e[0]!=="1"&&t.push(0);for(let i of e)i===n?r++:(t.push(r),n=i,r=1);return t.push(r),t}function ee(e){let t=e.replace(/\D/g,"");if(t.length===12&&(t+=Xt(t)),t.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=oi[Number(t[0])],r="101";for(let i=1;i<=6;i++)r+=(n[i-1]==="L"?Sn:ii)[Number(t[i])];r+="01010";for(let i=7;i<=12;i++)r+=Pn[Number(t[i])];return r+="101",te(r)}function Nn(e){let t=e.replace(/\D/g,"");if(t.length===11&&(t+=Xt(t)),t.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return ee("0"+t)}function In(e){let t=e.replace(/\D/g,"");if(t.length===7&&(t+=Xt(t)),t.length!==8)throw new Error("retail-print-kit: EAN8 needs 7 or 8 digits");let n="101";for(let r=0;r<4;r++)n+=Sn[Number(t[r])];n+="01010";for(let r=4;r<8;r++)n+=Pn[Number(t[r])];return n+="101",te(n)}var si={0:"101001101101",1:"110100101011",2:"101100101011",3:"110110010101",4:"101001101011",5:"110100110101",6:"101100110101",7:"101001011011",8:"110100101101",9:"101100101101",A:"110101001011",B:"101101001011",C:"110110100101",D:"101011001011",E:"110101100101",F:"101101100101",G:"101010011011",H:"110101001101",I:"101101001101",J:"101011001101",K:"110101010011",L:"101101010011",M:"110110101001",N:"101011010011",O:"110101101001",P:"101101101001",Q:"101010110011",R:"110101011001",S:"101101011001",T:"101011011001",U:"110010101011",V:"100110101011",W:"110011010101",X:"100101101011",Y:"110010110101",Z:"100110110101","-":"100101011011",".":"110010101101"," ":"100110101101",$:"100100100101","/":"100100101001","+":"100101001001","%":"101001001001","*":"100101101101"};function Rn(e){let t=`*${e.toUpperCase()}*`,n="";for(let r of t){let i=si[r];if(!i)throw new Error(`retail-print-kit: CODE39 cannot encode "${r}"`);n+=i+"0"}return te(n.slice(0,-1))}function kn(e,t){switch(e){case"CODE128":return Ln(t);case"EAN13":return ee(t);case"UPC_A":return Nn(t);case"EAN8":return In(t);case"CODE39":return Rn(t);default:throw new Error(`retail-print-kit: bitmap rendering of ${e} is not implemented`)}}function it(e,t,n=2,r=80){let i=kn(e,t),o=10*n,s=i.reduce((f,g)=>f+g,0)*n+o*2,a=z(s,r),u=o,c=!0;for(let f of i){if(c)for(let g=0;g<f*n;g++)for(let l=0;l<r;l++)G(a,u+g,l,!0);u+=f*n,c=!c}return a}var xt={vendor:"Epson",set:"escpos",paper:80,dots:576,columns:{a:48,b:64},encoding:"cp437",codepage:0,cut:"feed-and-cut",drawer:{on:25,off:250},features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},ne={...xt,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},re={...xt,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},ie={...xt,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},Et={...xt,vendor:"Generic",id:"generic-escpos",model:"ESC/POS compatible 80 mm",cut:"legacy",drawer:{on:60,off:120},features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!0}},oe={...Et,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var se={vendor:"Star Micronics",paper:80,dots:576,columns:{a:48,b:64},encoding:"cp437",codepage:1,cut:"feed-and-cut",drawer:{on:100,off:100},usb:[{vendorId:1305}]},ae={...se,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},ue={...se,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},ce={...se,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var Un=Object.fromEntries([ne,re,ie,Et,oe,ae,ue,ce].map(e=>[e.id,e]));function ai(e){let t=Un[e];if(!t)throw new Error(`retail-print-kit: unknown profile "${e}"`);return t}var le={upper:e=>String(e??"").toUpperCase(),lower:e=>String(e??"").toLowerCase(),trim:e=>String(e??"").trim(),money:(e,t)=>{let n=Number(e);if(!isFinite(n))return"";let r=Math.abs(n).toFixed(2);return`${n<0?"-":""}${t??""}${r}`},fixed:(e,t)=>{let n=Number(e);return isFinite(n)?n.toFixed(Number(t??2)):""},pad:(e,t)=>String(e??"").padStart(Number(t??0)),padEnd:(e,t)=>String(e??"").padEnd(Number(t??0)),default:(e,t)=>e==null||e===""?t??"":e,date:(e,t)=>{let n=e instanceof Date?e:new Date(String(e));return isNaN(n.getTime())?"":t==="time"?n.toLocaleTimeString():t==="datetime"?n.toLocaleString():n.toLocaleDateString()},count:e=>Array.isArray(e)?e.length:0};function fe(e,t){let n=e.trim();if(n==="this")return t.current;if(n==="@index")return t.index;if(n==="@number")return t.index===void 0?void 0:t.index+1;if(/^-?\d+(\.\d+)?$/.test(n))return Number(n);if(/^'.*'$/.test(n)||/^".*"$/.test(n))return n.slice(1,-1);let r=Dn(t.current,n);return r!==void 0?r:Dn(t.root,n)}function Dn(e,t){let n=e;for(let r of t.split(".")){if(n==null)return;n=n[r]}return n}function U(e,t){let[n,...r]=e.split("|").map(o=>o.trim()),i=fe(n,t);for(let o of r){let s=o.indexOf(":"),a=s===-1?o:o.slice(0,s),u=s===-1?void 0:o.slice(s+1),c=le[a];if(!c)throw new Error(`retail-print-kit: unknown template filter "${a}"`);i=c(i,u)}return i}function E(e,t){return e.replace(/\{\{([^}]+)\}\}/g,(n,r)=>{let i=U(r,t);return i==null?"":String(i)})}function H(e,t){let n=e.trim().startsWith("!"),r=U(n?e.trim().slice(1):e,t),i=Array.isArray(r)?r.length>0:!!r;return n?!i:i}var he={left:"lt",center:"ct",right:"rt"};function Fn(e,t,n){if(e.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(e.version)}`);let r=new rt(n);return Q(e.blocks,{root:t,current:t},r),r.operations}function Q(e,t,n){for(let r of e)ui(r,t,n)}function ui(e,t,n){switch(e.type){case"text":{e.align&&n.align(he[e.align]),e.font&&n.setFont(e.font),e.size&&n.size(e.size[0],e.size[1]),e.style&&n.style(e.style),n.text(E(e.value,t)),e.style&&n.style("normal"),e.size&&n.size(1,1),e.font&&n.setFont("a"),e.align&&e.align!=="left"&&n.align("lt");break}case"line":n.drawLine(e.char??"-");break;case"row":n.tableCustom(e.cells.map(r=>({text:E(r.value,t),width:r.width,align:r.align??"LEFT"})));break;case"table":{let r=U(e.rows,t);if(e.header!==!1&&e.columns.some(i=>i.header)&&n.tableCustom(e.columns.map(i=>({text:i.header??"",width:i.width,align:i.align??"LEFT"}))),!Array.isArray(r))break;r.forEach((i,o)=>{let s={root:t.root,current:i,index:o},a=e.columns.map(u=>({text:E(u.value,s),width:u.width,align:u.align??"LEFT"}));n.tableCustom(a)});break}case"feed":n.feed(e.lines??1);break;case"newline":n.newLine(e.count??1);break;case"cut":n.cut(e.partial??!1,e.feed??3);break;case"drawer":n.cashdraw(e.pin??2);break;case"qr":{e.align&&n.align(he[e.align]),n.qr(E(e.value,t),{size:e.size}),e.align&&e.align!=="left"&&n.align("lt");break}case"barcode":{e.align&&n.align(he[e.align]),n.barcode(E(e.value,t),e.format??"CODE128",{height:e.height,width:e.width,position:e.text===!1?"none":"below"}),e.align&&e.align!=="left"&&n.align("lt");break}case"each":{let r=U(e.items,t);if(!Array.isArray(r))break;r.forEach((i,o)=>Q(e.blocks,{root:t.root,current:i,index:o},n));break}case"if":H(e.when,t)?Q(e.blocks,t,n):e.else&&Q(e.else,t,n);break;default:throw new Error(`retail-print-kit: unknown template block "${e.type}"`)}}var ci=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})();function li(e){let t=4294967295;for(let n of e)t=ci[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function ot(e){return[e>>>24&255,e>>>16&255,e>>>8&255,e&255]}function At(e){let t=new Uint8Array(e.reduce((r,i)=>r+i.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}function de(e,t){let n=At([new Uint8Array([...e].map(r=>r.charCodeAt(0))),t]);return At([new Uint8Array(ot(t.length)),n,new Uint8Array(ot(li(n)))])}function fi(e){let t=1,n=0;for(let r of e)t=(t+r)%65521,n=(n+t)%65521;return(n<<16|t)>>>0}function hi(e){let t=[new Uint8Array([120,1])],n=65535;for(let r=0;r<e.length||r===0;r+=n){let i=e.subarray(r,Math.min(r+n,e.length)),o=r+n>=e.length?1:0,s=i.length;if(t.push(new Uint8Array([o,s&255,s>>8,~s&255,~s>>8&255]),i),e.length===0)break}return t.push(new Uint8Array(ot(fi(e)))),At(t)}function di(e){try{let n=Yn("zlib").deflateSync(e);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return hi(e)}}function S(e){let t=Math.ceil(e.width/8),n=new Uint8Array((t+1)*e.height);for(let o=0;o<e.height;o++)for(let s=0;s<e.width;s++)yt(e,s,o)||(n[o*(t+1)+1+(s>>3)]|=128>>(s&7));let r=new Uint8Array([...ot(e.width),...ot(e.height),1,0,0,0,0]),i=At([new Uint8Array([137,80,78,71,13,10,26,10]),de("IHDR",r),de("IDAT",di(n)),de("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i}var Ct="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function V(e){if(typeof Buffer<"u")return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64");let t="";for(let n=0;n<e.length;n+=3){let r=e[n],i=n+1<e.length?e[n+1]:0,o=n+2<e.length?e[n+2]:0,s=r<<16|i<<8|o;t+=Ct[s>>18&63]+Ct[s>>12&63],t+=n+1<e.length?Ct[s>>6&63]:"=",t+=n+2<e.length?Ct[s&63]:"="}return t}function ge(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function On(e,t,n={}){let r=n.cellWidth??8,i=t.columns.a*r,o={align:"left",font:"a",w:1,h:1,style:{}},s=[],a="",u=()=>{let l=[`text-align:${o.align}`];return(o.w!==1||o.h!==1)&&l.push(`transform:scale(${o.w},${o.h});transform-origin:${o.align} top`,`height:${o.h}em`),o.font==="b"&&l.push("font-size:0.78em"),o.style.bold&&l.push("font-weight:bold"),o.style.underline&&l.push(`text-decoration:underline${o.style.underline===2?" double":""}`),o.style.invert&&l.push("background:#000;color:#fff"),l.join(";")},c=l=>{if(!a&&!l)return;let h=Math.max(1,Math.floor(t.columns[o.font]/o.w)),w=[];for(let y=0;y<a.length;y+=h)w.push(a.slice(y,y+h));w.length||w.push("");for(let y of w)s.push(`<div class="l" style="${u()}">${ge(y)||" "}</div>`);a=""},f=(l,h,w)=>s.push(`<div class="l" style="text-align:${o.align}"><img alt="${ge(w)}" width="${Math.round(h/t.dots*i)}" src="data:image/png;base64,${V(l)}"></div>`);for(let l of e)switch(l.kind){case"text":{let h=l.text.split(`
|
|
11
|
+
`);for(let w=0;w<h.length;w++)a+=h[w],w<h.length-1&&c(!0);break}case"newline":for(let h=0;h<l.count;h++)c(!0);break;case"feed":c(!1);for(let h=0;h<l.lines;h++)s.push('<div class="l"> </div>');break;case"align":c(!1),o.align=l.align;break;case"font":c(!1),o.font=l.font;break;case"size":c(!1),o.w=l.width,o.h=l.height;break;case"style":c(!1),o.style=l.style;break;case"qr":{c(!1);let h=k(l.data,l.options);f(S(h),h.width,`QR ${l.data}`);break}case"barcode":{c(!1);let h=it(l.type,l.data,l.options.width??2,l.options.height??80);f(S(h),h.width,`${l.type} ${l.data}`);let w=l.options.position??"below";(w==="below"||w==="both")&&(a=l.data,c(!0));break}case"raster":{c(!1),f(S({width:l.width,height:l.height,bits:l.bits}),l.width,"image");break}case"cut":c(!1),s.push('<div class="cut"></div>');break;case"drawer":c(!1),s.push('<div class="note">[drawer kick]</div>');break;default:break}c(!1);let g=`<div class="paper" style="width:${i}px">${s.join("")}</div>`;return n.document===!1?g:`<!doctype html><html><head><meta charset="utf-8"><title>${ge(t.model)} preview</title><style>
|
|
12
|
+
body{background:#777;margin:0;padding:16px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:${r*1.6}px;line-height:1.25}
|
|
13
|
+
.paper{background:#fff;color:#000;padding:12px ${r}px;margin:0 auto;box-shadow:0 2px 8px rgba(0,0,0,.4);box-sizing:content-box}
|
|
14
|
+
.l{white-space:pre;overflow:hidden;min-height:1.25em}
|
|
15
|
+
.cut{border-top:2px dashed #999;margin:6px -${r}px}
|
|
16
|
+
.note{color:#999;font-size:.7em;text-align:center}
|
|
17
|
+
img{image-rendering:pixelated;vertical-align:top}
|
|
18
|
+
</style></head><body>${g}</body></html>`}var pe={0:"N",90:"R",180:"I",270:"B"},gi={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function me(e){return e.replace(/[\^~\\]/g,t=>`\\${t}`)}function pi(e){let t=Math.ceil(e.width/8),n="";for(let r=0;r<e.bits.length;r++)n+=e.bits[r].toString(16).padStart(2,"0").toUpperCase();return`${t*e.height},${t*e.height},${t},${n}`}function mi(e){let t=`^FO${Math.round(e.x)},${Math.round(e.y)}`;switch(e.kind){case"text":{let n=Math.round(e.width??e.height*.9),r=e.invert?"^FR":"";return`${t}${r}^A0${pe[e.rotation??0]},${Math.round(e.height)},${n}^FD${me(e.text)}^FS`}case"barcode":{let n=gi[e.type];if(!n)throw new Error(`retail-print-kit: ZPL has no ${e.type}`);let r=e.text===!1?"N":"Y",i=e.type==="CODE128"?`,${r},N,N`:`,${r},N`;return`${t}^BY${e.module??2},2,${Math.round(e.height)}^${n}${pe[e.rotation??0]},${Math.round(e.height)}${i}^FD${me(e.data)}^FS`}case"qr":{let n=e.correction??"M";return`${t}^BQ${pe[e.rotation??0]},2,${e.module??4}^FD${n}A,${me(e.data)}^FS`}case"box":return`${t}^GB${Math.round(e.width)},${Math.round(e.height)},${e.thickness??2}^FS`;case"rect":return`${t}^GB${Math.round(e.width)},${Math.round(e.height)},${Math.round(Math.min(e.width,e.height))}^FS`;case"image":return`${t}^GFA,${pi(e.bitmap)}^FS`}}function $t(e){let t=["^XA","^CI28",`^PW${e.width}`,`^LL${e.height}`,"^LH0,0"];e.speed!==void 0&&t.push(`^PR${Math.round(e.speed)}`),e.darkness!==void 0&&t.push(`^MD${Math.round(e.darkness*2-15)}`);for(let n of e.ops)t.push(mi(n));return t.push(`^PQ${e.copies},0,1,Y`,"^XZ"),t.join(`
|
|
19
|
+
`)+`
|
|
20
|
+
`}function st(e,t){return Math.round(e/25.4*t)}function K(e,t){return e/t*25.4}var wi={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function we(e){return`"${e.replace(/"/g,'\\["]')}"`}function qn(e,t){return K(e,t).toFixed(2)}function bi(e){let t=new Uint8Array(e.bits.length);for(let n=0;n<e.bits.length;n++)t[n]=~e.bits[n]&255;return t}function yi(e,t){let n=Math.round(e.x),r=Math.round(e.y),i=o=>o??0;switch(e.kind){case"text":{let o=Math.round(e.height),s=Math.round(e.width??e.height*.9),a=`TEXT ${n},${r},"0",${i(e.rotation)},${s},${o},${we(e.text)}`;return e.invert?`${a}
|
|
21
|
+
REVERSE ${n},${r},${Math.round(s*e.text.length*.6)},${o}`:a}case"barcode":{let o=wi[e.type];if(!o)throw new Error(`retail-print-kit: TSPL has no ${e.type}`);let s=e.module??2;return`BARCODE ${n},${r},"${o}",${Math.round(e.height)},${e.text===!1?0:1},${i(e.rotation)},${s},${s*2},${we(e.data)}`}case"qr":return`QRCODE ${n},${r},${e.correction??"M"},${e.module??4},A,${i(e.rotation)},${we(e.data)}`;case"box":return`BOX ${n},${r},${n+Math.round(e.width)},${r+Math.round(e.height)},${e.thickness??2}`;case"rect":return`BAR ${n},${r},${Math.round(e.width)},${Math.round(e.height)}`;case"image":{let o=Math.ceil(e.bitmap.width/8),s=`BITMAP ${n},${r},${o},${e.bitmap.height},0,`,a=bi(e.bitmap),u=new Uint8Array(s.length+a.length+1);for(let c=0;c<s.length;c++)u[c]=s.charCodeAt(c);return u.set(a,s.length),u[u.length-1]=10,u}}}function Bt(e){let t=[`SIZE ${qn(e.width,e.dpi)} mm,${qn(e.height,e.dpi)} mm`,`GAP ${e.gap.toFixed(2)} mm,0 mm`,"DIRECTION 1,0","REFERENCE 0,0"];e.speed!==void 0&&t.push(`SPEED ${e.speed}`),e.darkness!==void 0&&t.push(`DENSITY ${Math.round(e.darkness)}`),t.push("CLS");for(let o of e.ops)t.push(yi(o,e.dpi));t.push(`PRINT ${e.copies},1`);let n=t.map(o=>typeof o=="string"?new TextEncoder().encode(o+`
|
|
22
|
+
`):o),r=new Uint8Array(n.reduce((o,s)=>o+s.length,0)),i=0;for(let o of n)r.set(o,i),i+=o.length;return r}var be=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],xi={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function Ei(e){let t=be[0][0],n=be[0][1];for(let[i,o]of be)o<=e&&(t=i,n=o);let r=Math.max(1,Math.min(9,Math.floor(e/n)));return{font:t,mul:r}}function Ai(e){let t=Math.round(e.x),n=Math.round(e.y),r=e.rotation??0;switch(e.kind){case"text":{let{font:i,mul:o}=Ei(e.height);return`A${i},${t},${n},${o},${o},${r/90},0${e.invert?"R":"E"},${e.text}`}case"barcode":{let i=xi[e.type];if(!i)throw new Error(`retail-print-kit: EZPL has no ${e.type}`);let o=e.module??2;return`B${i},${t},${n},${o},${o*2},${Math.round(e.height)},${r/90},${e.text===!1?0:1},${e.data}`}case"qr":{let i={L:"L",M:"M",Q:"Q",H:"H"}[e.correction??"M"];return`W${t},${n},5,2,${i},${e.module??4},${r/90},${e.data.length}
|
|
23
|
+
${e.data}`}case"box":return`R${t},${n},${t+Math.round(e.width)},${n+Math.round(e.height)},${e.thickness??2},${e.thickness??2}`;case"rect":return`R${t},${n},${t+Math.round(e.width)},${n+Math.round(e.height)},${Math.round(e.width)},${Math.round(e.height)}`;case"image":throw new Error("retail-print-kit: EZPL images are not implemented yet")}}function Tt(e){let t=[`^Q${K(e.height,e.dpi).toFixed(2)},${e.gap.toFixed(0)}`,`^W${K(e.width,e.dpi).toFixed(2)}`,`^H${e.darkness??10}`,`^P${e.copies}`,`^S${e.speed??2}`,"^AD","^C1","^R0","~Q+0","^O0","^D0","^E18","~R255","^L"];for(let n of e.ops)t.push(Ai(n));return t.push("E"),t.join(`
|
|
24
|
+
`)+`
|
|
25
|
+
`}var J=class{constructor(t){let n=t.dpi??203;this.label={width:st(t.widthMm,n),height:st(t.heightMm,n),dpi:n,gap:t.gapMm??3,copies:1,ops:[]}}mm(t){return st(t,this.label.dpi)}copies(t){return this.label.copies=Math.max(1,Math.floor(t)),this}darkness(t){return this.label.darkness=t,this}speed(t){return this.label.speed=t,this}push(t){return this.label.ops.push(t),this}text(t,n,r,i,o={}){return this.push({kind:"text",x:t,y:n,text:r,height:i,...o})}barcode(t,n,r,i,o,s={}){return this.push({kind:"barcode",x:t,y:n,data:r,type:i,height:o,...s})}qr(t,n,r,i={}){return this.push({kind:"qr",x:t,y:n,data:r,...i})}box(t,n,r,i,o=2){return this.push({kind:"box",x:t,y:n,width:r,height:i,thickness:o})}rect(t,n,r,i){return this.push({kind:"rect",x:t,y:n,width:r,height:i})}image(t,n,r){return this.push({kind:"image",x:t,y:n,bitmap:r})}};function vn(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function ye(e){return e.rotation?` transform="rotate(${e.rotation} ${e.x} ${e.y})"`:""}function xe(e){return`data:image/png;base64,${V(S(e))}`}function Ci(e){switch(e.kind){case"text":{let t=e.width??e.height*.9,n=e.text.length*t*.62;return`${e.invert?`<rect x="${e.x}" y="${e.y}" width="${n}" height="${e.height}" fill="#000"/>`:""}<text x="${e.x}" y="${e.y+e.height*.82}" font-size="${e.height}" textLength="${n}" lengthAdjust="spacingAndGlyphs" font-family="Helvetica, Arial, sans-serif"${e.bold?' font-weight="bold"':""} fill="${e.invert?"#fff":"#000"}"${ye(e)}>${vn(e.text)}</text>`}case"barcode":{let t=it(e.type,e.data,e.module??2,Math.round(e.height)),n=e.text===!1?"":`<text x="${e.x+t.width/2}" y="${e.y+e.height+14}" font-size="14" text-anchor="middle" font-family="Helvetica, Arial, sans-serif">${vn(e.data)}</text>`;return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${xe(t)}" style="image-rendering:pixelated"${ye(e)}/>${n}`}case"qr":{let t=k(e.data,{size:e.module??4,correction:e.correction});return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${xe(t)}" style="image-rendering:pixelated"${ye(e)}/>`}case"box":return`<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="none" stroke="#000" stroke-width="${e.thickness??2}"/>`;case"rect":return`<rect x="${e.x}" y="${e.y}" width="${e.width}" height="${e.height}" fill="#000"/>`;case"image":return`<image x="${e.x}" y="${e.y}" width="${e.bitmap.width}" height="${e.bitmap.height}" href="${xe(e.bitmap)}" style="image-rendering:pixelated"/>`}}function _n(e){let t=e.ops.map(Ci).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${e.width} ${e.height}" width="${e.width}" height="${e.height}"><rect width="${e.width}" height="${e.height}" fill="#fff"/>${t}</svg>`}function zn(e,t){if(e.version!==1||e.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new J({widthMm:e.widthMm,heightMm:e.heightMm,dpi:e.dpi,gapMm:e.gapMm}),r={root:t,current:t};for(let i of e.elements)if(!(i.when&&!H(i.when,r)))switch(i.type){case"text":n.text(i.x,i.y,E(i.value,r),i.height,{width:i.width,rotation:i.rotation,bold:i.bold,invert:i.invert});break;case"barcode":n.barcode(i.x,i.y,E(i.value,r),i.format??"CODE128",i.height,{module:i.module,rotation:i.rotation,text:i.text});break;case"qr":n.qr(i.x,i.y,E(i.value,r),{module:i.module,correction:i.correction,rotation:i.rotation});break;case"box":n.box(i.x,i.y,i.width,i.height,i.thickness);break;case"rect":n.rect(i.x,i.y,i.width,i.height);break}return n.label}function $i(e,t){switch(t){case"zpl":return new TextEncoder().encode($t(e));case"ezpl":return new TextEncoder().encode(Tt(e));case"tspl":return Bt(e)}}return Zn(Bi);})();
|
|
26
|
+
//# sourceMappingURL=retail-print-kit.js.map
|