retail-print-kit 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +32 -3
- package/dist/browser/retail-print-kit.js +15 -20
- package/dist/browser/retail-print-kit.js.map +4 -4
- package/dist/browser/retail-print-kit.mjs +12 -17
- package/dist/core/bitmap.js +10 -4
- package/package.json +10 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.3 (2026-10-05)
|
|
4
|
+
|
|
5
|
+
* Website with a landing page and ten task guides (receipts, Electron, cash drawer, Star TSP100, labels, templates, QR and barcodes, logos, discovery and status, migration from escpos / node-thermal-printer).
|
|
6
|
+
* The designer moved to `/designer/` on the site; `sitemap.xml`, `robots.txt`, `llms.txt` and `llms-full.txt` are published.
|
|
7
|
+
* README: guides and FAQ sections. Package description leads with the printer families.
|
|
8
|
+
|
|
9
|
+
## 0.2.2 (2026-10-05)
|
|
10
|
+
|
|
11
|
+
* A plain install is now 4 packages and under 2 MB with no native modules (was 34 packages and 30 MB).
|
|
12
|
+
* `@napi-rs/canvas` is an optional peer, as intended; it was being installed for everyone.
|
|
13
|
+
* QR codes are generated with the dependency-free `qrcode-generator`; text is encoded as UTF-8.
|
|
14
|
+
|
|
15
|
+
## 0.2.1 (2026-10-03)
|
|
16
|
+
|
|
17
|
+
* The repository and the designer address were renamed to `retail-print-kit`; all links follow.
|
|
18
|
+
|
|
19
|
+
## 0.2.0 (2026-10-03)
|
|
20
|
+
|
|
21
|
+
* Images and logos: `loadImage` with optional Floyd-Steinberg dithering, `ditherRgba`, `serializeBitmap`, a template `image` block, logo upload in the designer.
|
|
22
|
+
* `discoverNetworkPrinters` finds raw-printing hosts on the local networks and can identify each.
|
|
23
|
+
* CLI: `verify`, `verify-label`, `discover`, `image`. A hardware checklist documents what to confirm on real units.
|
|
24
|
+
|
|
25
|
+
## 0.1.0 (2026-10-03)
|
|
26
|
+
|
|
27
|
+
First release.
|
|
28
|
+
|
|
29
|
+
* ESC/POS, Star Line Mode and Star raster encoders with printer profiles.
|
|
30
|
+
* Network, USB and serial transports; printer status and `identify`.
|
|
31
|
+
* Receipt templates, HTML and PNG previews.
|
|
32
|
+
* Label printing in ZPL, TSPL and EZPL with an SVG preview and label templates.
|
|
33
|
+
* Browser bundle and the template designer.
|
|
34
|
+
* CLI: `test`, `drawer`, `status`, `identify`, `preview`, `print`, `profiles`, `list`.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A modern replacement for `escpos` / `node-thermal-printer`: ESC/POS **and** Star
|
|
|
10
10
|
network / serial, printer profiles instead of model `if`s, receipt and label **templates**, live
|
|
11
11
|
**previews**, a visual **designer**, and a CLI for testing hardware in the field.
|
|
12
12
|
|
|
13
|
-
**[
|
|
13
|
+
**[Website](https://arka162.github.io/retail-print-kit/)** · **[Designer](https://arka162.github.io/retail-print-kit/designer/)** · [Guides](https://arka162.github.io/retail-print-kit/guides/) · [Printer matrix](docs/printer-matrix.md) · [Changelog](CHANGELOG.md)
|
|
14
14
|
|
|
15
15
|

|
|
16
16
|
|
|
@@ -27,6 +27,7 @@ network / serial, printer profiles instead of model `if`s, receipt and label **t
|
|
|
27
27
|
| HTML / PNG / SVG preview without a printer | yes | no | no |
|
|
28
28
|
| Status (paper, cover, drawer) and model detection | yes | no | partly |
|
|
29
29
|
| Native dependencies in the core | none | none | none |
|
|
30
|
+
| Packages a plain install adds (measured Oct 2026) | 4 | 66 | 7 |
|
|
30
31
|
| TypeScript types | built in | community | built in |
|
|
31
32
|
|
|
32
33
|
## Install
|
|
@@ -35,7 +36,8 @@ network / serial, printer profiles instead of model `if`s, receipt and label **t
|
|
|
35
36
|
npm install retail-print-kit
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
A plain install is 4 packages and under 2 MB, with no native modules: network printing, templates,
|
|
40
|
+
HTML and SVG previews, labels and the CLI all work from that. Add a native piece only if you need it:
|
|
39
41
|
|
|
40
42
|
```
|
|
41
43
|
npm install usb # USB printers
|
|
@@ -75,6 +77,19 @@ const { UsbTransport } = require('retail-print-kit/usb'); // new UsbTransp
|
|
|
75
77
|
const { SerialTransport } = require('retail-print-kit/serial'); // new SerialTransport('COM3', { baudRate: 9600 })
|
|
76
78
|
```
|
|
77
79
|
|
|
80
|
+
## Guides
|
|
81
|
+
|
|
82
|
+
* [Print a receipt from Node.js on an ESC/POS thermal printer](https://arka162.github.io/retail-print-kit/guides/print-receipt-nodejs.html)
|
|
83
|
+
* [Print receipts from an Electron app](https://arka162.github.io/retail-print-kit/guides/electron-receipt-printing.html)
|
|
84
|
+
* [Open a cash drawer](https://arka162.github.io/retail-print-kit/guides/open-cash-drawer-nodejs.html)
|
|
85
|
+
* [Print to a Star TSP100 or TSP143](https://arka162.github.io/retail-print-kit/guides/star-tsp100-nodejs.html)
|
|
86
|
+
* [Print ZPL, TSPL and EZPL labels](https://arka162.github.io/retail-print-kit/guides/zpl-tspl-ezpl-label-printing-nodejs.html)
|
|
87
|
+
* [Receipt and label templates and the visual designer](https://arka162.github.io/retail-print-kit/guides/receipt-template-designer.html)
|
|
88
|
+
* [QR codes and barcodes](https://arka162.github.io/retail-print-kit/guides/print-qr-code-barcode-receipt.html)
|
|
89
|
+
* [Print a logo or image](https://arka162.github.io/retail-print-kit/guides/print-logo-image-thermal-printer.html)
|
|
90
|
+
* [Find printers on the network and read status](https://arka162.github.io/retail-print-kit/guides/network-printer-discovery-status.html)
|
|
91
|
+
* [Migrating from escpos or node-thermal-printer](https://arka162.github.io/retail-print-kit/guides/escpos-node-thermal-printer-alternative.html)
|
|
92
|
+
|
|
78
93
|
## Supported printers
|
|
79
94
|
|
|
80
95
|
| Family | Profile ids | Command set |
|
|
@@ -157,7 +172,7 @@ const label = renderLabel(labelTemplate, data); // from a designer JSON
|
|
|
157
172
|
|
|
158
173
|
## Designer
|
|
159
174
|
|
|
160
|
-
**https://arka162.github.io/retail-print-kit/** edits receipt and label templates in the browser:
|
|
175
|
+
**https://arka162.github.io/retail-print-kit/designer/** edits receipt and label templates in the browser:
|
|
161
176
|
block palette, nested `each` / `if`, property editor, sample data, live preview, drag-to-position
|
|
162
177
|
on labels, logo upload with dithering, JSON import and export. It runs entirely in the page from
|
|
163
178
|
the browser bundle (`retail-print-kit/browser`); nothing is uploaded.
|
|
@@ -199,6 +214,20 @@ npx retail-print-kit profiles
|
|
|
199
214
|
|
|
200
215
|
Add `--dry` to any printing command to dump the bytes as hex instead of sending them.
|
|
201
216
|
|
|
217
|
+
## FAQ
|
|
218
|
+
|
|
219
|
+
**Does it work in Electron?** Yes, in the main process; the renderer asks for prints over IPC and the
|
|
220
|
+
browser build renders previews.
|
|
221
|
+
|
|
222
|
+
**Does it need a printer driver?** No. It sends the printer's own commands over TCP, USB or serial,
|
|
223
|
+
so there is no OS print dialog and nothing to install on the machine.
|
|
224
|
+
|
|
225
|
+
**Why does a Star TSP100 print nothing with other libraries?** It is raster-only and ignores ESC/POS
|
|
226
|
+
text. Use the `star-tsp100` profile.
|
|
227
|
+
|
|
228
|
+
**Can I print without a printer attached?** `--dry` dumps the bytes, and the HTML, PNG and SVG
|
|
229
|
+
previews show the result.
|
|
230
|
+
|
|
202
231
|
## Status of hardware verification
|
|
203
232
|
|
|
204
233
|
Encoders are covered by byte-exact tests. Items still to be confirmed on real units are listed in
|
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
"use strict";var RetailPrintKit=(()=>{var
|
|
2
|
-
|
|
3
|
-
Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}};an.exports=H});var cn=p((Wi,Gt)=>{"use strict";var tt={single_source_shortest_paths:function(e,t,n){var r={},i={};i[t]=0;var o=tt.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=tt.single_source_shortest_paths(e,t,n);return tt.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(e){var t=tt.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 Gt<"u"&&(Gt.exports=tt)});var wn=p(Q=>{var d=M(),hn=en(),dn=rn(),gn=sn(),pn=un(),et=Ft(),mt=$(),Ar=cn();function ln(e){return unescape(encodeURIComponent(e)).length}function nt(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 mn(e){let t=nt(et.NUMERIC,d.NUMERIC,e),n=nt(et.ALPHANUMERIC,d.ALPHANUMERIC,e),r,i;return mt.isKanjiModeEnabled()?(r=nt(et.BYTE,d.BYTE,e),i=nt(et.KANJI,d.KANJI,e)):(r=nt(et.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 Ht(e,t){switch(t){case d.NUMERIC:return hn.getBitsLength(e);case d.ALPHANUMERIC:return dn.getBitsLength(e);case d.KANJI:return pn.getBitsLength(e);case d.BYTE:return gn.getBitsLength(e)}}function Cr(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 $r(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:ln(r.data)}]);break;case d.BYTE:t.push([{data:r.data,mode:d.BYTE,length:ln(r.data)}])}}return t}function Tr(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]=Ht(n[l].lastCount+c.length,c.mode)-Ht(n[l].lastCount,c.mode),n[l].lastCount+=c.length):(n[l]&&(n[l].lastCount=c.length),r[l][f]=Ht(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 fn(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
|
-
|
|
5
|
-
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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=Wr[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"?Sn(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(F(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=Xr(t,r),o=n.wrap!==!1,s=t.map((u,c)=>o?ti(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+=ei(s[g][u]??"",i[g],f.align??"LEFT")}),this.text(c.replace(/\s+$/,""))}return this}};function Sn(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 Xr(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 ti(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 ei(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 ni=["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"],ri=104,ii=105,oi=100,si=99,ai=106;function Pn(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?ii:si),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?ri:oi),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,ai);let s=[];for(let a of t)for(let u of ni[a])s.push(Number(u));return s}var Nn=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],ui=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],In=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],ci=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function ne(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 re(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 ie(e){let t=e.replace(/\D/g,"");if(t.length===12&&(t+=ne(t)),t.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=ci[Number(t[0])],r="101";for(let i=1;i<=6;i++)r+=(n[i-1]==="L"?Nn:ui)[Number(t[i])];r+="01010";for(let i=7;i<=12;i++)r+=In[Number(t[i])];return r+="101",re(r)}function Rn(e){let t=e.replace(/\D/g,"");if(t.length===11&&(t+=ne(t)),t.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return ie("0"+t)}function kn(e){let t=e.replace(/\D/g,"");if(t.length===7&&(t+=ne(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+=Nn[Number(t[r])];n+="01010";for(let r=4;r<8;r++)n+=In[Number(t[r])];return n+="101",re(n)}var li={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 Un(e){let t=`*${e.toUpperCase()}*`,n="";for(let r of t){let i=li[r];if(!i)throw new Error(`retail-print-kit: CODE39 cannot encode "${r}"`);n+=i+"0"}return re(n.slice(0,-1))}function On(e,t){switch(e){case"CODE128":return Pn(t);case"EAN13":return ie(t);case"UPC_A":return Rn(t);case"EAN8":return kn(t);case"CODE39":return Un(t);default:throw new Error(`retail-print-kit: bitmap rendering of ${e} is not implemented`)}}function ot(e,t,n=2,r=80){let i=On(e,t),o=10*n,s=i.reduce((f,g)=>f+g,0)*n+o*2,a=O(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++)D(a,u+g,l,!0);u+=f*n,c=!c}return a}var Bt={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}},oe={...Bt,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},se={...Bt,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},ae={...Bt,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},At={...Bt,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}},ue={...At,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var ce={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}]},le={...ce,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},fe={...ce,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},he={...ce,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var Dn=Object.fromEntries([oe,se,ae,At,ue,le,fe,he].map(e=>[e.id,e]));function fi(e){let t=Dn[e];if(!t)throw new Error(`retail-print-kit: unknown profile "${e}"`);return t}var de={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 ge(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=Fn(t.current,n);return r!==void 0?r:Fn(t.root,n)}function Fn(e,t){let n=e;for(let r of t.split(".")){if(n==null)return;n=n[r]}return n}function q(e,t){let[n,...r]=e.split("|").map(o=>o.trim()),i=ge(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=de[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=q(r,t);return i==null?"":String(i)})}function V(e,t){let n=e.trim().startsWith("!"),r=q(n?e.trim().slice(1):e,t),i=Array.isArray(r)?r.length>0:!!r;return n?!i:i}var Ct={left:"lt",center:"ct",right:"rt"};function qn(e,t,n){if(e.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(e.version)}`);let r=new it(n);return K(e.blocks,{root:t,current:t},r),r.operations}function K(e,t,n){for(let r of e)hi(r,t,n)}function hi(e,t,n){switch(e.type){case"text":{e.align&&n.align(Ct[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=q(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(Ct[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(Ct[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"image":{e.align&&n.align(Ct[e.align]),n.image(ee(e)),e.align&&e.align!=="left"&&n.align("lt");break}case"each":{let r=q(e.items,t);if(!Array.isArray(r))break;r.forEach((i,o)=>K(e.blocks,{root:t.root,current:i,index:o},n));break}case"if":V(e.when,t)?K(e.blocks,t,n):e.else&&K(e.else,t,n);break;default:throw new Error(`retail-print-kit: unknown template block "${e.type}"`)}}var di=(()=>{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 gi(e){let t=4294967295;for(let n of e)t=di[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function st(e){return[e>>>24&255,e>>>16&255,e>>>8&255,e&255]}function $t(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 pe(e,t){let n=$t([new Uint8Array([...e].map(r=>r.charCodeAt(0))),t]);return $t([new Uint8Array(st(t.length)),n,new Uint8Array(st(gi(n)))])}function pi(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 mi(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(st(pi(e)))),$t(t)}function wi(e){try{let n=Zn("zlib").deflateSync(e);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return mi(e)}}function N(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++)Et(e,s,o)||(n[o*(t+1)+1+(s>>3)]|=128>>(s&7));let r=new Uint8Array([...st(e.width),...st(e.height),1,0,0,0,0]),i=$t([new Uint8Array([137,80,78,71,13,10,26,10]),pe("IHDR",r),pe("IDAT",wi(n)),pe("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i}function me(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function vn(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()}">${me(y)||" "}</div>`);a=""},f=(l,h,w)=>s.push(`<div class="l" style="text-align:${o.align}"><img alt="${me(w)}" width="${Math.round(h/t.dots*i)}" src="data:image/png;base64,${P(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=F(l.data,l.options);f(N(h),h.width,`QR ${l.data}`);break}case"barcode":{c(!1);let h=ot(l.type,l.data,l.options.width??2,l.options.height??80);f(N(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(N({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>${me(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}
|
|
1
|
+
"use strict";var RetailPrintKit=(()=>{var pt=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var he=(t,e)=>{for(var n in e)pt(t,n,{get:e[n],enumerable:!0})},pe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of fe(e))!ce.call(t,r)&&r!==n&&pt(t,r,{get:()=>e[r],enumerable:!(i=ue(e,r))||i.enumerable});return t};var de=t=>pe(pt({},"__esModule",{value:!0}),t);var on={};he(on,{LabelBuilder:()=>W,OpBuilder:()=>V,barcodeBitmap:()=>tt,bitmapToPng:()=>F,blit:()=>Ht,code128:()=>qt,code39:()=>Kt,deserializeBitmap:()=>dt,ditherRgba:()=>Ee,dotsToMm:()=>K,ean13:()=>bt,ean8:()=>Zt,emptyBitmap:()=>G,encodeEzpl:()=>lt,encodeLabel:()=>rn,encodeTspl:()=>ct,encodeZpl:()=>ft,epsonTmM30:()=>yt,epsonTmT20:()=>wt,epsonTmT88:()=>xt,evaluate:()=>q,filters:()=>Lt,fitWidth:()=>Me,fromBase64:()=>rt,fromRgba:()=>Be,genericEscPos:()=>st,genericEscPos58:()=>$t,getPixel:()=>it,interpolate:()=>D,labelToSvg:()=>re,lookup:()=>Tt,mmToDots:()=>nt,opsToHtml:()=>te,parseStyle:()=>Qt,pattern:()=>Wt,profileById:()=>Fe,profiles:()=>Xt,qrBitmap:()=>Q,render:()=>Vt,renderBlocks:()=>Z,renderLabel:()=>ie,serializeBitmap:()=>Le,setPixel:()=>H,starMcPrint3:()=>Mt,starTsp100:()=>Et,starTsp650:()=>Bt,toBase64:()=>U,truthy:()=>Y,upcA:()=>Yt});var z=function(t,e){let r=t,a=X[e],s=null,o=0,u=null,l=[],b={},m=function(c,g){o=r*4+17,s=function(f){let d=new Array(f);for(let p=0;p<f;p+=1){d[p]=new Array(f);for(let x=0;x<f;x+=1)d[p][x]=null}return d}(o),h(0,0),h(o-7,0),h(0,o-7),M(),B(),_(c,g),r>=7&&k(c),u==null&&(u=se(r,a,l)),O(u,g)},h=function(c,g){for(let f=-1;f<=7;f+=1)if(!(c+f<=-1||o<=c+f))for(let d=-1;d<=7;d+=1)g+d<=-1||o<=g+d||(0<=f&&f<=6&&(d==0||d==6)||0<=d&&d<=6&&(f==0||f==6)||2<=f&&f<=4&&2<=d&&d<=4?s[c+f][g+d]=!0:s[c+f][g+d]=!1)},w=function(){let c=0,g=0;for(let f=0;f<8;f+=1){m(!0,f);let d=S.getLostPoint(b);(f==0||c>d)&&(c=d,g=f)}return g},B=function(){for(let c=8;c<o-8;c+=1)s[c][6]==null&&(s[c][6]=c%2==0);for(let c=8;c<o-8;c+=1)s[6][c]==null&&(s[6][c]=c%2==0)},M=function(){let c=S.getPatternPosition(r);for(let g=0;g<c.length;g+=1)for(let f=0;f<c.length;f+=1){let d=c[g],p=c[f];if(s[d][p]==null)for(let x=-2;x<=2;x+=1)for(let y=-2;y<=2;y+=1)x==-2||x==2||y==-2||y==2||x==0&&y==0?s[d+x][p+y]=!0:s[d+x][p+y]=!1}},k=function(c){let g=S.getBCHTypeNumber(r);for(let f=0;f<18;f+=1){let d=!c&&(g>>f&1)==1;s[Math.floor(f/3)][f%3+o-8-3]=d}for(let f=0;f<18;f+=1){let d=!c&&(g>>f&1)==1;s[f%3+o-8-3][Math.floor(f/3)]=d}},_=function(c,g){let f=a<<3|g,d=S.getBCHTypeInfo(f);for(let p=0;p<15;p+=1){let x=!c&&(d>>p&1)==1;p<6?s[p][8]=x:p<8?s[p+1][8]=x:s[o-15+p][8]=x}for(let p=0;p<15;p+=1){let x=!c&&(d>>p&1)==1;p<8?s[8][o-p-1]=x:p<9?s[8][15-p-1+1]=x:s[8][15-p-1]=x}s[o-8][8]=!c},O=function(c,g){let f=-1,d=o-1,p=7,x=0,y=S.getMaskFunction(g);for(let A=o-1;A>0;A-=2)for(A==6&&(A-=1);;){for(let E=0;E<2;E+=1)if(s[d][A-E]==null){let T=!1;x<c.length&&(T=(c[x]>>>p&1)==1),y(d,A-E)&&(T=!T),s[d][A-E]=T,p-=1,p==-1&&(x+=1,p=7)}if(d+=f,d<0||o<=d){d-=f,f=-f;break}}},oe=function(c,g){let f=0,d=0,p=0,x=new Array(g.length),y=new Array(g.length);for(let $=0;$<g.length;$+=1){let L=g[$].dataCount,P=g[$].totalCount-L;d=Math.max(d,L),p=Math.max(p,P),x[$]=new Array(L);for(let R=0;R<x[$].length;R+=1)x[$][R]=255&c.getBuffer()[R+f];f+=L;let ht=S.getErrorCorrectPolynomial(P),St=J(x[$],ht.getLength()-1).mod(ht);y[$]=new Array(ht.getLength()-1);for(let R=0;R<y[$].length;R+=1){let Nt=R+St.getLength()-y[$].length;y[$][R]=Nt>=0?St.getAt(Nt):0}}let A=0;for(let $=0;$<g.length;$+=1)A+=g[$].totalCount;let E=new Array(A),T=0;for(let $=0;$<d;$+=1)for(let L=0;L<g.length;L+=1)$<x[L].length&&(E[T]=x[L][$],T+=1);for(let $=0;$<p;$+=1)for(let L=0;L<g.length;L+=1)$<y[L].length&&(E[T]=y[L][$],T+=1);return E},se=function(c,g,f){let d=It.getRSBlocks(c,g),p=Ut();for(let y=0;y<f.length;y+=1){let A=f[y];p.put(A.getMode(),4),p.put(A.getLength(),S.getLengthInBits(A.getMode(),c)),A.write(p)}let x=0;for(let y=0;y<d.length;y+=1)x+=d[y].dataCount;if(p.getLengthInBits()>x*8)throw"code length overflow. ("+p.getLengthInBits()+">"+x*8+")";for(p.getLengthInBits()+4<=x*8&&p.put(0,4);p.getLengthInBits()%8!=0;)p.putBit(!1);for(;!(p.getLengthInBits()>=x*8||(p.put(236,8),p.getLengthInBits()>=x*8));)p.put(17,8);return oe(p,d)};b.addData=function(c,g){g=g||"Byte";let f=null;switch(g){case"Numeric":f=ge(c);break;case"Alphanumeric":f=me(c);break;case"Byte":f=be(c);break;case"Kanji":f=xe(c);break;default:throw"mode:"+g}l.push(f),u=null},b.isDark=function(c,g){if(c<0||o<=c||g<0||o<=g)throw c+","+g;return s[c][g]},b.getModuleCount=function(){return o},b.make=function(){if(r<1){let c=1;for(;c<40;c++){let g=It.getRSBlocks(c,a),f=Ut();for(let p=0;p<l.length;p++){let x=l[p];f.put(x.getMode(),4),f.put(x.getLength(),S.getLengthInBits(x.getMode(),c)),x.write(f)}let d=0;for(let p=0;p<g.length;p++)d+=g[p].dataCount;if(f.getLengthInBits()<=d*8)break}r=c}m(!1,w())},b.createTableTag=function(c,g){c=c||2,g=typeof g>"u"?c*4:g;let f="";f+='<table style="',f+=" border-width: 0px; border-style: none;",f+=" border-collapse: collapse;",f+=" padding: 0px; margin: "+g+"px;",f+='">',f+="<tbody>";for(let d=0;d<b.getModuleCount();d+=1){f+="<tr>";for(let p=0;p<b.getModuleCount();p+=1)f+='<td style="',f+=" border-width: 0px; border-style: none;",f+=" border-collapse: collapse;",f+=" padding: 0px; margin: 0px;",f+=" width: "+c+"px;",f+=" height: "+c+"px;",f+=" background-color: ",f+=b.isDark(d,p)?"#000000":"#ffffff",f+=";",f+='"/>';f+="</tr>"}return f+="</tbody>",f+="</table>",f},b.createSvgTag=function(c,g,f,d){let p={};typeof arguments[0]=="object"&&(p=arguments[0],c=p.cellSize,g=p.margin,f=p.alt,d=p.title),c=c||2,g=typeof g>"u"?c*4:g,f=typeof f=="string"?{text:f}:f||{},f.text=f.text||null,f.id=f.text?f.id||"qrcode-description":null,d=typeof d=="string"?{text:d}:d||{},d.text=d.text||null,d.id=d.text?d.id||"qrcode-title":null;let x=b.getModuleCount()*c+g*2,y,A,E,T,$="",L;for(L="l"+c+",0 0,"+c+" -"+c+",0 0,-"+c+"z ",$+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',$+=p.scalable?"":' width="'+x+'px" height="'+x+'px"',$+=' viewBox="0 0 '+x+" "+x+'" ',$+=' preserveAspectRatio="xMinYMin meet"',$+=d.text||f.text?' role="img" aria-labelledby="'+j([d.id,f.id].join(" ").trim())+'"':"",$+=">",$+=d.text?'<title id="'+j(d.id)+'">'+j(d.text)+"</title>":"",$+=f.text?'<description id="'+j(f.id)+'">'+j(f.text)+"</description>":"",$+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',$+='<path d="',E=0;E<b.getModuleCount();E+=1)for(T=E*c+g,y=0;y<b.getModuleCount();y+=1)b.isDark(E,y)&&(A=y*c+g,$+="M"+A+","+T+L);return $+='" stroke="transparent" fill="black"/>',$+="</svg>",$},b.createDataURL=function(c,g){c=c||2,g=typeof g>"u"?c*4:g;let f=b.getModuleCount()*c+g*2,d=g,p=f-g;return Ae(f,f,function(x,y){if(d<=x&&x<p&&d<=y&&y<p){let A=Math.floor((x-d)/c),E=Math.floor((y-d)/c);return b.isDark(E,A)?0:1}else return 1})},b.createImgTag=function(c,g,f){c=c||2,g=typeof g>"u"?c*4:g;let d=b.getModuleCount()*c+g*2,p="";return p+="<img",p+=' src="',p+=b.createDataURL(c,g),p+='"',p+=' width="',p+=d,p+='"',p+=' height="',p+=d,p+='"',f&&(p+=' alt="',p+=j(f),p+='"'),p+="/>",p};let j=function(c){let g="";for(let f=0;f<c.length;f+=1){let d=c.charAt(f);switch(d){case"<":g+="<";break;case">":g+=">";break;case"&":g+="&";break;case'"':g+=""";break;default:g+=d;break}}return g},ae=function(c){c=typeof c>"u"?1*2:c;let f=b.getModuleCount()*1+c*2,d=c,p=f-c,x,y,A,E,T,$={"\u2588\u2588":"\u2588","\u2588 ":"\u2580"," \u2588":"\u2584"," ":" "},L={"\u2588\u2588":"\u2580","\u2588 ":"\u2580"," \u2588":" "," ":" "},P="";for(x=0;x<f;x+=2){for(A=Math.floor((x-d)/1),E=Math.floor((x+1-d)/1),y=0;y<f;y+=1)T="\u2588",d<=y&&y<p&&d<=x&&x<p&&b.isDark(A,Math.floor((y-d)/1))&&(T=" "),d<=y&&y<p&&d<=x+1&&x+1<p&&b.isDark(E,Math.floor((y-d)/1))?T+=" ":T+="\u2588",P+=c<1&&x+1>=p?L[T]:$[T];P+=`
|
|
2
|
+
`}return f%2&&c>0?P.substring(0,P.length-f-1)+Array(f+1).join("\u2580"):P.substring(0,P.length-1)};return b.createASCII=function(c,g){if(c=c||1,c<2)return ae(g);c-=1,g=typeof g>"u"?c*2:g;let f=b.getModuleCount()*c+g*2,d=g,p=f-g,x,y,A,E,T=Array(c+1).join("\u2588\u2588"),$=Array(c+1).join(" "),L="",P="";for(x=0;x<f;x+=1){for(A=Math.floor((x-d)/c),P="",y=0;y<f;y+=1)E=1,d<=y&&y<p&&d<=x&&x<p&&b.isDark(A,Math.floor((y-d)/c))&&(E=0),P+=E?T:$;for(A=0;A<c;A+=1)L+=P+`
|
|
3
|
+
`}return L.substring(0,L.length-1)},b.renderTo2dContext=function(c,g){g=g||2;let f=b.getModuleCount();for(let d=0;d<f;d++)for(let p=0;p<f;p++)c.fillStyle=b.isDark(d,p)?"black":"white",c.fillRect(p*g,d*g,g,g)},b};z.stringToBytes=function(t){let e=[];for(let n=0;n<t.length;n+=1){let i=t.charCodeAt(n);e.push(i&255)}return e};z.createStringToBytes=function(t,e){let n=function(){let r=ye(t),a=function(){let u=r.read();if(u==-1)throw"eof";return u},s=0,o={};for(;;){let u=r.read();if(u==-1)break;let l=a(),b=a(),m=a(),h=String.fromCharCode(u<<8|l),w=b<<8|m;o[h]=w,s+=1}if(s!=e)throw s+" != "+e;return o}(),i=63;return function(r){let a=[];for(let s=0;s<r.length;s+=1){let o=r.charCodeAt(s);if(o<128)a.push(o);else{let u=n[r.charAt(s)];typeof u=="number"?(u&255)==u?a.push(u):(a.push(u>>>8),a.push(u&255)):a.push(i)}}return a}};var C={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},X={L:1,M:0,Q:3,H:2},v={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},S=function(){let t=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],e=1335,n=7973,i=21522,r={},a=function(s){let o=0;for(;s!=0;)o+=1,s>>>=1;return o};return r.getBCHTypeInfo=function(s){let o=s<<10;for(;a(o)-a(e)>=0;)o^=e<<a(o)-a(e);return(s<<10|o)^i},r.getBCHTypeNumber=function(s){let o=s<<12;for(;a(o)-a(n)>=0;)o^=n<<a(o)-a(n);return s<<12|o},r.getPatternPosition=function(s){return t[s-1]},r.getMaskFunction=function(s){switch(s){case v.PATTERN000:return function(o,u){return(o+u)%2==0};case v.PATTERN001:return function(o,u){return o%2==0};case v.PATTERN010:return function(o,u){return u%3==0};case v.PATTERN011:return function(o,u){return(o+u)%3==0};case v.PATTERN100:return function(o,u){return(Math.floor(o/2)+Math.floor(u/3))%2==0};case v.PATTERN101:return function(o,u){return o*u%2+o*u%3==0};case v.PATTERN110:return function(o,u){return(o*u%2+o*u%3)%2==0};case v.PATTERN111:return function(o,u){return(o*u%3+(o+u)%2)%2==0};default:throw"bad maskPattern:"+s}},r.getErrorCorrectPolynomial=function(s){let o=J([1],0);for(let u=0;u<s;u+=1)o=o.multiply(J([1,N.gexp(u)],0));return o},r.getLengthInBits=function(s,o){if(1<=o&&o<10)switch(s){case C.MODE_NUMBER:return 10;case C.MODE_ALPHA_NUM:return 9;case C.MODE_8BIT_BYTE:return 8;case C.MODE_KANJI:return 8;default:throw"mode:"+s}else if(o<27)switch(s){case C.MODE_NUMBER:return 12;case C.MODE_ALPHA_NUM:return 11;case C.MODE_8BIT_BYTE:return 16;case C.MODE_KANJI:return 10;default:throw"mode:"+s}else if(o<41)switch(s){case C.MODE_NUMBER:return 14;case C.MODE_ALPHA_NUM:return 13;case C.MODE_8BIT_BYTE:return 16;case C.MODE_KANJI:return 12;default:throw"mode:"+s}else throw"type:"+o},r.getLostPoint=function(s){let o=s.getModuleCount(),u=0;for(let m=0;m<o;m+=1)for(let h=0;h<o;h+=1){let w=0,B=s.isDark(m,h);for(let M=-1;M<=1;M+=1)if(!(m+M<0||o<=m+M))for(let k=-1;k<=1;k+=1)h+k<0||o<=h+k||M==0&&k==0||B==s.isDark(m+M,h+k)&&(w+=1);w>5&&(u+=3+w-5)}for(let m=0;m<o-1;m+=1)for(let h=0;h<o-1;h+=1){let w=0;s.isDark(m,h)&&(w+=1),s.isDark(m+1,h)&&(w+=1),s.isDark(m,h+1)&&(w+=1),s.isDark(m+1,h+1)&&(w+=1),(w==0||w==4)&&(u+=3)}for(let m=0;m<o;m+=1)for(let h=0;h<o-6;h+=1)s.isDark(m,h)&&!s.isDark(m,h+1)&&s.isDark(m,h+2)&&s.isDark(m,h+3)&&s.isDark(m,h+4)&&!s.isDark(m,h+5)&&s.isDark(m,h+6)&&(u+=40);for(let m=0;m<o;m+=1)for(let h=0;h<o-6;h+=1)s.isDark(h,m)&&!s.isDark(h+1,m)&&s.isDark(h+2,m)&&s.isDark(h+3,m)&&s.isDark(h+4,m)&&!s.isDark(h+5,m)&&s.isDark(h+6,m)&&(u+=40);let l=0;for(let m=0;m<o;m+=1)for(let h=0;h<o;h+=1)s.isDark(h,m)&&(l+=1);let b=Math.abs(100*l/o/o-50)/5;return u+=b*10,u},r}(),N=function(){let t=new Array(256),e=new Array(256);for(let i=0;i<8;i+=1)t[i]=1<<i;for(let i=8;i<256;i+=1)t[i]=t[i-4]^t[i-5]^t[i-6]^t[i-8];for(let i=0;i<255;i+=1)e[t[i]]=i;let n={};return n.glog=function(i){if(i<1)throw"glog("+i+")";return e[i]},n.gexp=function(i){for(;i<0;)i+=255;for(;i>=256;)i-=255;return t[i]},n}(),J=function(t,e){if(typeof t.length>"u")throw t.length+"/"+e;let n=function(){let r=0;for(;r<t.length&&t[r]==0;)r+=1;let a=new Array(t.length-r+e);for(let s=0;s<t.length-r;s+=1)a[s]=t[s+r];return a}(),i={};return i.getAt=function(r){return n[r]},i.getLength=function(){return n.length},i.multiply=function(r){let a=new Array(i.getLength()+r.getLength()-1);for(let s=0;s<i.getLength();s+=1)for(let o=0;o<r.getLength();o+=1)a[s+o]^=N.gexp(N.glog(i.getAt(s))+N.glog(r.getAt(o)));return J(a,0)},i.mod=function(r){if(i.getLength()-r.getLength()<0)return i;let a=N.glog(i.getAt(0))-N.glog(r.getAt(0)),s=new Array(i.getLength());for(let o=0;o<i.getLength();o+=1)s[o]=i.getAt(o);for(let o=0;o<r.getLength();o+=1)s[o]^=N.gexp(N.glog(r.getAt(o))+a);return J(s,0).mod(r)},i},It=function(){let t=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],e=function(r,a){let s={};return s.totalCount=r,s.dataCount=a,s},n={},i=function(r,a){switch(a){case X.L:return t[(r-1)*4+0];case X.M:return t[(r-1)*4+1];case X.Q:return t[(r-1)*4+2];case X.H:return t[(r-1)*4+3];default:return}};return n.getRSBlocks=function(r,a){let s=i(r,a);if(typeof s>"u")throw"bad rs block @ typeNumber:"+r+"/errorCorrectionLevel:"+a;let o=s.length/3,u=[];for(let l=0;l<o;l+=1){let b=s[l*3+0],m=s[l*3+1],h=s[l*3+2];for(let w=0;w<b;w+=1)u.push(e(m,h))}return u},n}(),Ut=function(){let t=[],e=0,n={};return n.getBuffer=function(){return t},n.getAt=function(i){let r=Math.floor(i/8);return(t[r]>>>7-i%8&1)==1},n.put=function(i,r){for(let a=0;a<r;a+=1)n.putBit((i>>>r-a-1&1)==1)},n.getLengthInBits=function(){return e},n.putBit=function(i){let r=Math.floor(e/8);t.length<=r&&t.push(0),i&&(t[r]|=128>>>e%8),e+=1},n},ge=function(t){let e=C.MODE_NUMBER,n=t,i={};i.getMode=function(){return e},i.getLength=function(s){return n.length},i.write=function(s){let o=n,u=0;for(;u+2<o.length;)s.put(r(o.substring(u,u+3)),10),u+=3;u<o.length&&(o.length-u==1?s.put(r(o.substring(u,u+1)),4):o.length-u==2&&s.put(r(o.substring(u,u+2)),7))};let r=function(s){let o=0;for(let u=0;u<s.length;u+=1)o=o*10+a(s.charAt(u));return o},a=function(s){if("0"<=s&&s<="9")return s.charCodeAt(0)-48;throw"illegal char :"+s};return i},me=function(t){let e=C.MODE_ALPHA_NUM,n=t,i={};i.getMode=function(){return e},i.getLength=function(a){return n.length},i.write=function(a){let s=n,o=0;for(;o+1<s.length;)a.put(r(s.charAt(o))*45+r(s.charAt(o+1)),11),o+=2;o<s.length&&a.put(r(s.charAt(o)),6)};let r=function(a){if("0"<=a&&a<="9")return a.charCodeAt(0)-48;if("A"<=a&&a<="Z")return a.charCodeAt(0)-65+10;switch(a){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+a}};return i},be=function(t){let e=C.MODE_8BIT_BYTE,n=t,i=z.stringToBytes(t),r={};return r.getMode=function(){return e},r.getLength=function(a){return i.length},r.write=function(a){for(let s=0;s<i.length;s+=1)a.put(i[s],8)},r},xe=function(t){let e=C.MODE_KANJI,n=t,i=z.stringToBytes;(function(s,o){let u=i(s);if(u.length!=2||(u[0]<<8|u[1])!=o)throw"sjis not supported."})("\u53CB",38726);let r=i(t),a={};return a.getMode=function(){return e},a.getLength=function(s){return~~(r.length/2)},a.write=function(s){let o=r,u=0;for(;u+1<o.length;){let l=(255&o[u])<<8|255&o[u+1];if(33088<=l&&l<=40956)l-=33088;else if(57408<=l&&l<=60351)l-=49472;else throw"illegal char at "+(u+1)+"/"+l;l=(l>>>8&255)*192+(l&255),s.put(l,13),u+=2}if(u<o.length)throw"illegal char at "+(u+1)},a},Ft=function(){let t=[],e={};return e.writeByte=function(n){t.push(n&255)},e.writeShort=function(n){e.writeByte(n),e.writeByte(n>>>8)},e.writeBytes=function(n,i,r){i=i||0,r=r||n.length;for(let a=0;a<r;a+=1)e.writeByte(n[a+i])},e.writeString=function(n){for(let i=0;i<n.length;i+=1)e.writeByte(n.charCodeAt(i))},e.toByteArray=function(){return t},e.toString=function(){let n="";n+="[";for(let i=0;i<t.length;i+=1)i>0&&(n+=","),n+=t[i];return n+="]",n},e},we=function(){let t=0,e=0,n=0,i="",r={},a=function(o){i+=String.fromCharCode(s(o&63))},s=function(o){if(o<0)throw"n:"+o;if(o<26)return 65+o;if(o<52)return 97+(o-26);if(o<62)return 48+(o-52);if(o==62)return 43;if(o==63)return 47;throw"n:"+o};return r.writeByte=function(o){for(t=t<<8|o&255,e+=8,n+=1;e>=6;)a(t>>>e-6),e-=6},r.flush=function(){if(e>0&&(a(t<<6-e),t=0,e=0),n%3!=0){let o=3-n%3;for(let u=0;u<o;u+=1)i+="="}},r.toString=function(){return i},r},ye=function(t){let e=t,n=0,i=0,r=0,a={};a.read=function(){for(;r<8;){if(n>=e.length){if(r==0)return-1;throw"unexpected end of file./"+r}let u=e.charAt(n);if(n+=1,u=="=")return r=0,-1;if(u.match(/^\s$/))continue;i=i<<6|s(u.charCodeAt(0)),r+=6}let o=i>>>r-8&255;return r-=8,o};let s=function(o){if(65<=o&&o<=90)return o-65;if(97<=o&&o<=122)return o-97+26;if(48<=o&&o<=57)return o-48+52;if(o==43)return 62;if(o==47)return 63;throw"c:"+o};return a},$e=function(t,e){let n=t,i=e,r=new Array(t*e),a={};a.setPixel=function(l,b,m){r[b*n+l]=m},a.write=function(l){l.writeString("GIF87a"),l.writeShort(n),l.writeShort(i),l.writeByte(128),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(255),l.writeByte(255),l.writeByte(255),l.writeString(","),l.writeShort(0),l.writeShort(0),l.writeShort(n),l.writeShort(i),l.writeByte(0);let b=2,m=o(b);l.writeByte(b);let h=0;for(;m.length-h>255;)l.writeByte(255),l.writeBytes(m,h,255),h+=255;l.writeByte(m.length-h),l.writeBytes(m,h,m.length-h),l.writeByte(0),l.writeString(";")};let s=function(l){let b=l,m=0,h=0,w={};return w.write=function(B,M){if(B>>>M)throw"length over";for(;m+M>=8;)b.writeByte(255&(B<<m|h)),M-=8-m,B>>>=8-m,h=0,m=0;h=B<<m|h,m=m+M},w.flush=function(){m>0&&b.writeByte(h)},w},o=function(l){let b=1<<l,m=(1<<l)+1,h=l+1,w=u();for(let O=0;O<b;O+=1)w.add(String.fromCharCode(O));w.add(String.fromCharCode(b)),w.add(String.fromCharCode(m));let B=Ft(),M=s(B);M.write(b,h);let k=0,_=String.fromCharCode(r[k]);for(k+=1;k<r.length;){let O=String.fromCharCode(r[k]);k+=1,w.contains(_+O)?_=_+O:(M.write(w.indexOf(_),h),w.size()<4095&&(w.size()==1<<h&&(h+=1),w.add(_+O)),_=O)}return M.write(w.indexOf(_),h),M.write(m,h),M.flush(),B.toByteArray()},u=function(){let l={},b=0,m={};return m.add=function(h){if(m.contains(h))throw"dup key:"+h;l[h]=b,b+=1},m.size=function(){return b},m.indexOf=function(h){return l[h]},m.contains=function(h){return typeof l[h]<"u"},m};return a},Ae=function(t,e,n){let i=$e(t,e);for(let o=0;o<e;o+=1)for(let u=0;u<t;u+=1)i.setPixel(u,o,n(u,o));let r=Ft();i.write(r);let a=we(),s=r.toByteArray();for(let o=0;o<s.length;o+=1)a.writeByte(s[o]);return a.flush(),"data:image/gif;base64,"+a},Gt=z,un=z.stringToBytes;var I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function U(t){if(typeof Buffer<"u")return Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64");let e="";for(let n=0;n<t.length;n+=3){let i=t[n],r=n+1<t.length?t[n+1]:0,a=n+2<t.length?t[n+2]:0,s=i<<16|r<<8|a;e+=I[s>>18&63]+I[s>>12&63],e+=n+1<t.length?I[s>>6&63]:"=",e+=n+2<t.length?I[s&63]:"="}return e}function rt(t){if(typeof Buffer<"u"){let r=Buffer.from(t,"base64");return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}let e=t.replace(/[^A-Za-z0-9+/]/g,""),n=new Uint8Array(Math.floor(e.length*3/4)),i=0;for(let r=0;r<e.length;r+=4){let a=I.indexOf(e[r])<<18|I.indexOf(e[r+1])<<12|(I.indexOf(e[r+2])&63)<<6|I.indexOf(e[r+3])&63;n[i++]=a>>16&255,r+2<e.length&&(n[i++]=a>>8&255),r+3<e.length&&(n[i++]=a&255)}return n.subarray(0,i)}function G(t,e){return{width:t,height:e,bits:new Uint8Array(Math.ceil(t/8)*e)}}function H(t,e,n,i){if(e<0||n<0||e>=t.width||n>=t.height)return;let r=n*Math.ceil(t.width/8)+(e>>3),a=128>>(e&7);i?t.bits[r]|=a:t.bits[r]&=~a}function it(t,e,n){return e<0||n<0||e>=t.width||n>=t.height?!1:(t.bits[n*Math.ceil(t.width/8)+(e>>3)]&128>>(e&7))!==0}function Be(t,e,n,i=128){let r=G(e,n);for(let a=0;a<n;a++)for(let s=0;s<e;s++){let o=(a*e+s)*4,u=t[o+3]/255;(.299*t[o]+.587*t[o+1]+.114*t[o+2])*u+255*(1-u)<i&&H(r,s,a,!0)}return r}function Ht(t,e,n,i){for(let r=0;r<e.height;r++)for(let a=0;a<e.width;a++)it(e,a,r)&&H(t,n+a,i+r,!0)}function Me(t,e,n="center"){if(t.width===e)return t;let i=G(e,t.height),r=n==="left"?0:n==="right"?e-t.width:Math.floor((e-t.width)/2);return Ht(i,t,r,0),i}function Q(t,e={}){let n=new TextEncoder().encode(t),i="";for(let u=0;u<n.length;u++)i+=String.fromCharCode(n[u]);let r=Gt(0,e.correction??"M");r.addData(i,"Byte"),r.make();let a=r.getModuleCount(),s=Math.max(1,Math.min(16,Math.floor(e.size??6))),o=G(a*s,a*s);for(let u=0;u<a;u++)for(let l=0;l<a;l++)if(r.isDark(u,l))for(let b=0;b<s;b++)for(let m=0;m<s;m++)H(o,l*s+m,u*s+b,!0);return o}function Ee(t,e,n){let i=new Float32Array(e*n);for(let a=0;a<e*n;a++){let s=t[a*4+3]/255;i[a]=(.299*t[a*4]+.587*t[a*4+1]+.114*t[a*4+2])*s+255*(1-s)}let r=G(e,n);for(let a=0;a<n;a++)for(let s=0;s<e;s++){let o=a*e+s,u=i[o],l=u<128;l&&H(r,s,a,!0);let b=u-(l?0:255);s+1<e&&(i[o+1]+=b*7/16),a+1<n&&(s>0&&(i[o+e-1]+=b*3/16),i[o+e]+=b*5/16,s+1<e&&(i[o+e+1]+=b/16))}return r}function Le(t){return{width:t.width,height:t.height,data:U(t.bits)}}function dt(t){let e=rt(t.data),n=Math.ceil(t.width/8)*t.height;if(e.length!==n)throw new Error(`retail-print-kit: bitmap data is ${e.length} bytes, expected ${n}`);return{width:t.width,height:t.height,bits:e}}var Te={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},V=class{constructor(e){this.profile=e;this.ops=[];this.font="a"}get operations(){return this.ops.slice()}append(e){for(let n of e)this.ops.push(n);return this}get columns(){return this.profile.columns[this.font]}push(e){return this.ops.push(e),this}raw(e){return this.push({kind:"raw",bytes:Uint8Array.from(e)})}text(e){return this.push({kind:"text",text:`${e}
|
|
4
|
+
`})}print(e){return this.push({kind:"text",text:e})}newLine(e=1){return this.push({kind:"newline",count:e})}feed(e=1){return this.push({kind:"feed",lines:e})}align(e){let n=Te[e];if(!n)throw new Error(`retail-print-kit: unknown align "${e}"`);return this.push({kind:"align",align:n})}setFont(e){return this.font=e,this.push({kind:"font",font:e})}size(e,n){return this.push({kind:"size",width:e,height:n})}style(e){let n=typeof e=="string"?Qt(e):e;return this.push({kind:"style",style:n})}lineSpace(e=null){return this.push({kind:"lineSpacing",dots:e})}cut(e=!1,n=3){return this.push({kind:"cut",partial:e,feed:n})}cashdraw(e=2){return this.push({kind:"drawer",pin:e})}beep(e=1,n=1){return this.push({kind:"beep",times:e,duration:n})}barcode(e,n="CODE128",i={}){return this.push({kind:"barcode",data:e,type:n,options:i})}qr(e,n={}){return this.profile.features.nativeQr||this.profile.set==="star-graphic"?this.push({kind:"qr",data:e,options:n}):this.image(Q(e,n))}image(e){return this.push({kind:"raster",width:e.width,height:e.height,bits:e.bits})}qrimage(e,n={}){return this.qr(e,n)}drawLine(e="-"){return this.text(e.repeat(this.columns))}tableCustom(e,n={}){let i=n.width??this.columns,r=Ce(e,i),a=n.wrap!==!1,s=e.map((u,l)=>a?ke(u.text??"",r[l]):[String(u.text??"").slice(0,r[l])]),o=Math.max(1,...s.map(u=>u.length));for(let u=0;u<o;u++){let l="";e.forEach((b,m)=>{l+=Pe(s[m][u]??"",r[m],b.align??"LEFT")}),this.text(l.replace(/\s+$/,""))}return this}};function Qt(t){if(t==="normal")return{bold:!1,underline:0,italic:!1,invert:!1};let e=t.toLowerCase();return{bold:e.includes("b"),italic:e.includes("i"),underline:e.includes("u2")?2:e.includes("u")?1:0,invert:!1}}function Ce(t,e){let n=t.map(u=>u.width===void 0?null:u.width>1?Math.floor(u.width):Math.floor(u.width*e)),i=n.reduce((u,l)=>u+(l??0),0),r=n.filter(u=>u===null).length,a=r?Math.floor(Math.max(0,e-i)/r):0,s=n.map(u=>u===null?a:u),o=s.reduce((u,l)=>u+l,0);return o<e&&(s[s.length-1]+=e-o),s}function ke(t,e){if(e<=0)return[""];let n=[];for(let i of String(t).split(`
|
|
5
|
+
`)){let r="";for(let a of i.split(/\s+/)){if(!a)continue;if(a.length>e){r&&n.push(r),r="";for(let o=0;o<a.length;o+=e)n.push(a.slice(o,o+e));continue}let s=r?`${r} ${a}`:a;s.length>e?(n.push(r),r=a):r=s}n.push(r)}return n.length?n:[""]}function Pe(t,e,n){let i=t.slice(0,e),r=e-i.length;if(n==="RIGHT")return" ".repeat(r)+i;if(n==="CENTER"){let a=Math.floor(r/2);return" ".repeat(a)+i+" ".repeat(r-a)}return i+" ".repeat(r)}var De=["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"],Oe=104,_e=105,Re=100,ve=99,Se=106;function qt(t){if(!/^[\x20-\x7e]*$/.test(t)||!t.length)throw new Error("retail-print-kit: CODE128 needs printable ASCII");let e=[],n=0,i=null,r=o=>{let u=0;for(;o+u<t.length&&/[0-9]/.test(t[o+u]);)u++;return u};for(;n<t.length;){let o=r(n);if(o>=4||o>=2&&o===t.length-n){i!=="C"&&(e.push(i===null?_e:ve),i="C");let l=Math.floor(o/2);for(let b=0;b<l;b++)e.push(parseInt(t.slice(n,n+2),10)),n+=2;continue}i!=="B"&&(e.push(i===null?Oe:Re),i="B"),e.push(t.charCodeAt(n)-32),n++}let a=e[0];for(let o=1;o<e.length;o++)a+=e[o]*o;e.push(a%103,Se);let s=[];for(let o of e)for(let u of De[o])s.push(Number(u));return s}var jt=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],Ne=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],zt=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],Ie=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function gt(t){let e=0;for(let n=0;n<t.length;n++){let i=(t.length-n)%2===0?1:3;e+=Number(t[n])*i}return(10-e%10)%10}function mt(t){let e=[],n="1",i=0;t[0]!=="1"&&e.push(0);for(let r of t)r===n?i++:(e.push(i),n=r,i=1);return e.push(i),e}function bt(t){let e=t.replace(/\D/g,"");if(e.length===12&&(e+=gt(e)),e.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=Ie[Number(e[0])],i="101";for(let r=1;r<=6;r++)i+=(n[r-1]==="L"?jt:Ne)[Number(e[r])];i+="01010";for(let r=7;r<=12;r++)i+=zt[Number(e[r])];return i+="101",mt(i)}function Yt(t){let e=t.replace(/\D/g,"");if(e.length===11&&(e+=gt(e)),e.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return bt("0"+e)}function Zt(t){let e=t.replace(/\D/g,"");if(e.length===7&&(e+=gt(e)),e.length!==8)throw new Error("retail-print-kit: EAN8 needs 7 or 8 digits");let n="101";for(let i=0;i<4;i++)n+=jt[Number(e[i])];n+="01010";for(let i=4;i<8;i++)n+=zt[Number(e[i])];return n+="101",mt(n)}var Ue={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 Kt(t){let e=`*${t.toUpperCase()}*`,n="";for(let i of e){let r=Ue[i];if(!r)throw new Error(`retail-print-kit: CODE39 cannot encode "${i}"`);n+=r+"0"}return mt(n.slice(0,-1))}function Wt(t,e){switch(t){case"CODE128":return qt(e);case"EAN13":return bt(e);case"UPC_A":return Yt(e);case"EAN8":return Zt(e);case"CODE39":return Kt(e);default:throw new Error(`retail-print-kit: bitmap rendering of ${t} is not implemented`)}}function tt(t,e,n=2,i=80){let r=Wt(t,e),a=10*n,s=r.reduce((b,m)=>b+m,0)*n+a*2,o=G(s,i),u=a,l=!0;for(let b of r){if(l)for(let m=0;m<b*n;m++)for(let h=0;h<i;h++)H(o,u+m,h,!0);u+=b*n,l=!l}return o}var ot={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}},xt={...ot,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},wt={...ot,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},yt={...ot,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},st={...ot,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}},$t={...st,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var At={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}]},Bt={...At,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Mt={...At,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Et={...At,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var Xt=Object.fromEntries([xt,wt,yt,st,$t,Bt,Mt,Et].map(t=>[t.id,t]));function Fe(t){let e=Xt[t];if(!e)throw new Error(`retail-print-kit: unknown profile "${t}"`);return e}var Lt={upper:t=>String(t??"").toUpperCase(),lower:t=>String(t??"").toLowerCase(),trim:t=>String(t??"").trim(),money:(t,e)=>{let n=Number(t);if(!isFinite(n))return"";let i=Math.abs(n).toFixed(2);return`${n<0?"-":""}${e??""}${i}`},fixed:(t,e)=>{let n=Number(t);return isFinite(n)?n.toFixed(Number(e??2)):""},pad:(t,e)=>String(t??"").padStart(Number(e??0)),padEnd:(t,e)=>String(t??"").padEnd(Number(e??0)),default:(t,e)=>t==null||t===""?e??"":t,date:(t,e)=>{let n=t instanceof Date?t:new Date(String(t));return isNaN(n.getTime())?"":e==="time"?n.toLocaleTimeString():e==="datetime"?n.toLocaleString():n.toLocaleDateString()},count:t=>Array.isArray(t)?t.length:0};function Tt(t,e){let n=t.trim();if(n==="this")return e.current;if(n==="@index")return e.index;if(n==="@number")return e.index===void 0?void 0:e.index+1;if(/^-?\d+(\.\d+)?$/.test(n))return Number(n);if(/^'.*'$/.test(n)||/^".*"$/.test(n))return n.slice(1,-1);let i=Jt(e.current,n);return i!==void 0?i:Jt(e.root,n)}function Jt(t,e){let n=t;for(let i of e.split(".")){if(n==null)return;n=n[i]}return n}function q(t,e){let[n,...i]=t.split("|").map(a=>a.trim()),r=Tt(n,e);for(let a of i){let s=a.indexOf(":"),o=s===-1?a:a.slice(0,s),u=s===-1?void 0:a.slice(s+1),l=Lt[o];if(!l)throw new Error(`retail-print-kit: unknown template filter "${o}"`);r=l(r,u)}return r}function D(t,e){return t.replace(/\{\{([^}]+)\}\}/g,(n,i)=>{let r=q(i,e);return r==null?"":String(r)})}function Y(t,e){let n=t.trim().startsWith("!"),i=q(n?t.trim().slice(1):t,e),r=Array.isArray(i)?i.length>0:!!i;return n?!r:r}var at={left:"lt",center:"ct",right:"rt"};function Vt(t,e,n){if(t.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(t.version)}`);let i=new V(n);return Z(t.blocks,{root:e,current:e},i),i.operations}function Z(t,e,n){for(let i of t)Ge(i,e,n)}function Ge(t,e,n){switch(t.type){case"text":{t.align&&n.align(at[t.align]),t.font&&n.setFont(t.font),t.size&&n.size(t.size[0],t.size[1]),t.style&&n.style(t.style),n.text(D(t.value,e)),t.style&&n.style("normal"),t.size&&n.size(1,1),t.font&&n.setFont("a"),t.align&&t.align!=="left"&&n.align("lt");break}case"line":n.drawLine(t.char??"-");break;case"row":n.tableCustom(t.cells.map(i=>({text:D(i.value,e),width:i.width,align:i.align??"LEFT"})));break;case"table":{let i=q(t.rows,e);if(t.header!==!1&&t.columns.some(r=>r.header)&&n.tableCustom(t.columns.map(r=>({text:r.header??"",width:r.width,align:r.align??"LEFT"}))),!Array.isArray(i))break;i.forEach((r,a)=>{let s={root:e.root,current:r,index:a},o=t.columns.map(u=>({text:D(u.value,s),width:u.width,align:u.align??"LEFT"}));n.tableCustom(o)});break}case"feed":n.feed(t.lines??1);break;case"newline":n.newLine(t.count??1);break;case"cut":n.cut(t.partial??!1,t.feed??3);break;case"drawer":n.cashdraw(t.pin??2);break;case"qr":{t.align&&n.align(at[t.align]),n.qr(D(t.value,e),{size:t.size}),t.align&&t.align!=="left"&&n.align("lt");break}case"barcode":{t.align&&n.align(at[t.align]),n.barcode(D(t.value,e),t.format??"CODE128",{height:t.height,width:t.width,position:t.text===!1?"none":"below"}),t.align&&t.align!=="left"&&n.align("lt");break}case"image":{t.align&&n.align(at[t.align]),n.image(dt(t)),t.align&&t.align!=="left"&&n.align("lt");break}case"each":{let i=q(t.items,e);if(!Array.isArray(i))break;i.forEach((r,a)=>Z(t.blocks,{root:e.root,current:r,index:a},n));break}case"if":Y(t.when,e)?Z(t.blocks,e,n):t.else&&Z(t.else,e,n);break;default:throw new Error(`retail-print-kit: unknown template block "${t.type}"`)}}var He=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let i=0;i<8;i++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function Qe(t){let e=4294967295;for(let n of t)e=He[(e^n)&255]^e>>>8;return(e^4294967295)>>>0}function et(t){return[t>>>24&255,t>>>16&255,t>>>8&255,t&255]}function ut(t){let e=new Uint8Array(t.reduce((i,r)=>i+r.length,0)),n=0;for(let i of t)e.set(i,n),n+=i.length;return e}function Ct(t,e){let n=ut([new Uint8Array([...t].map(i=>i.charCodeAt(0))),e]);return ut([new Uint8Array(et(e.length)),n,new Uint8Array(et(Qe(n)))])}function qe(t){let e=1,n=0;for(let i of t)e=(e+i)%65521,n=(n+e)%65521;return(n<<16|e)>>>0}function je(t){let e=[new Uint8Array([120,1])],n=65535;for(let i=0;i<t.length||i===0;i+=n){let r=t.subarray(i,Math.min(i+n,t.length)),a=i+n>=t.length?1:0,s=r.length;if(e.push(new Uint8Array([a,s&255,s>>8,~s&255,~s>>8&255]),r),t.length===0)break}return e.push(new Uint8Array(et(qe(t)))),ut(e)}function ze(t){try{let n=le("zlib").deflateSync(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return je(t)}}function F(t){let e=Math.ceil(t.width/8),n=new Uint8Array((e+1)*t.height);for(let a=0;a<t.height;a++)for(let s=0;s<t.width;s++)it(t,s,a)||(n[a*(e+1)+1+(s>>3)]|=128>>(s&7));let i=new Uint8Array([...et(t.width),...et(t.height),1,0,0,0,0]),r=ut([new Uint8Array([137,80,78,71,13,10,26,10]),Ct("IHDR",i),Ct("IDAT",ze(n)),Ct("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(r.buffer,r.byteOffset,r.byteLength):r}function kt(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function te(t,e,n={}){let i=n.cellWidth??8,r=e.columns.a*i,a={align:"left",font:"a",w:1,h:1,style:{}},s=[],o="",u=()=>{let h=[`text-align:${a.align}`];return(a.w!==1||a.h!==1)&&h.push(`transform:scale(${a.w},${a.h});transform-origin:${a.align} top`,`height:${a.h}em`),a.font==="b"&&h.push("font-size:0.78em"),a.style.bold&&h.push("font-weight:bold"),a.style.underline&&h.push(`text-decoration:underline${a.style.underline===2?" double":""}`),a.style.invert&&h.push("background:#000;color:#fff"),h.join(";")},l=h=>{if(!o&&!h)return;let w=Math.max(1,Math.floor(e.columns[a.font]/a.w)),B=[];for(let M=0;M<o.length;M+=w)B.push(o.slice(M,M+w));B.length||B.push("");for(let M of B)s.push(`<div class="l" style="${u()}">${kt(M)||" "}</div>`);o=""},b=(h,w,B)=>s.push(`<div class="l" style="text-align:${a.align}"><img alt="${kt(B)}" width="${Math.round(w/e.dots*r)}" src="data:image/png;base64,${U(h)}"></div>`);for(let h of t)switch(h.kind){case"text":{let w=h.text.split(`
|
|
6
|
+
`);for(let B=0;B<w.length;B++)o+=w[B],B<w.length-1&&l(!0);break}case"newline":for(let w=0;w<h.count;w++)l(!0);break;case"feed":l(!1);for(let w=0;w<h.lines;w++)s.push('<div class="l"> </div>');break;case"align":l(!1),a.align=h.align;break;case"font":l(!1),a.font=h.font;break;case"size":l(!1),a.w=h.width,a.h=h.height;break;case"style":l(!1),a.style=h.style;break;case"qr":{l(!1);let w=Q(h.data,h.options);b(F(w),w.width,`QR ${h.data}`);break}case"barcode":{l(!1);let w=tt(h.type,h.data,h.options.width??2,h.options.height??80);b(F(w),w.width,`${h.type} ${h.data}`);let B=h.options.position??"below";(B==="below"||B==="both")&&(o=h.data,l(!0));break}case"raster":{l(!1),b(F({width:h.width,height:h.height,bits:h.bits}),h.width,"image");break}case"cut":l(!1),s.push('<div class="cut"></div>');break;case"drawer":l(!1),s.push('<div class="note">[drawer kick]</div>');break;default:break}l(!1);let m=`<div class="paper" style="width:${r}px">${s.join("")}</div>`;return n.document===!1?m:`<!doctype html><html><head><meta charset="utf-8"><title>${kt(e.model)} preview</title><style>
|
|
7
|
+
body{background:#777;margin:0;padding:16px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:${i*1.6}px;line-height:1.25}
|
|
8
|
+
.paper{background:#fff;color:#000;padding:12px ${i}px;margin:0 auto;box-shadow:0 2px 8px rgba(0,0,0,.4);box-sizing:content-box}
|
|
14
9
|
.l{white-space:pre;overflow:hidden;min-height:1.25em}
|
|
15
|
-
.cut{border-top:2px dashed #999;margin:6px -${
|
|
10
|
+
.cut{border-top:2px dashed #999;margin:6px -${i}px}
|
|
16
11
|
.note{color:#999;font-size:.7em;text-align:center}
|
|
17
12
|
img{image-rendering:pixelated;vertical-align:top}
|
|
18
|
-
</style></head><body>${
|
|
13
|
+
</style></head><body>${m}</body></html>`}var Pt={0:"N",90:"R",180:"I",270:"B"},Ye={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function Dt(t){return t.replace(/[\^~\\]/g,e=>`\\${e}`)}function Ze(t){let e=Math.ceil(t.width/8),n="";for(let i=0;i<t.bits.length;i++)n+=t.bits[i].toString(16).padStart(2,"0").toUpperCase();return`${e*t.height},${e*t.height},${e},${n}`}function Ke(t){let e=`^FO${Math.round(t.x)},${Math.round(t.y)}`;switch(t.kind){case"text":{let n=Math.round(t.width??t.height*.9),i=t.invert?"^FR":"";return`${e}${i}^A0${Pt[t.rotation??0]},${Math.round(t.height)},${n}^FD${Dt(t.text)}^FS`}case"barcode":{let n=Ye[t.type];if(!n)throw new Error(`retail-print-kit: ZPL has no ${t.type}`);let i=t.text===!1?"N":"Y",r=t.type==="CODE128"?`,${i},N,N`:`,${i},N`;return`${e}^BY${t.module??2},2,${Math.round(t.height)}^${n}${Pt[t.rotation??0]},${Math.round(t.height)}${r}^FD${Dt(t.data)}^FS`}case"qr":{let n=t.correction??"M";return`${e}^BQ${Pt[t.rotation??0]},2,${t.module??4}^FD${n}A,${Dt(t.data)}^FS`}case"box":return`${e}^GB${Math.round(t.width)},${Math.round(t.height)},${t.thickness??2}^FS`;case"rect":return`${e}^GB${Math.round(t.width)},${Math.round(t.height)},${Math.round(Math.min(t.width,t.height))}^FS`;case"image":return`${e}^GFA,${Ze(t.bitmap)}^FS`}}function ft(t){let e=["^XA","^CI28",`^PW${t.width}`,`^LL${t.height}`,"^LH0,0"];t.speed!==void 0&&e.push(`^PR${Math.round(t.speed)}`),t.darkness!==void 0&&e.push(`^MD${Math.round(t.darkness*2-15)}`);for(let n of t.ops)e.push(Ke(n));return e.push(`^PQ${t.copies},0,1,Y`,"^XZ"),e.join(`
|
|
19
14
|
`)+`
|
|
20
|
-
`}function
|
|
21
|
-
REVERSE ${n},${
|
|
22
|
-
`):
|
|
23
|
-
${
|
|
15
|
+
`}function nt(t,e){return Math.round(t/25.4*e)}function K(t,e){return t/e*25.4}var We={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function Ot(t){return`"${t.replace(/"/g,'\\["]')}"`}function ee(t,e){return K(t,e).toFixed(2)}function Xe(t){let e=new Uint8Array(t.bits.length);for(let n=0;n<t.bits.length;n++)e[n]=~t.bits[n]&255;return e}function Je(t,e){let n=Math.round(t.x),i=Math.round(t.y),r=a=>a??0;switch(t.kind){case"text":{let a=Math.round(t.height),s=Math.round(t.width??t.height*.9),o=`TEXT ${n},${i},"0",${r(t.rotation)},${s},${a},${Ot(t.text)}`;return t.invert?`${o}
|
|
16
|
+
REVERSE ${n},${i},${Math.round(s*t.text.length*.6)},${a}`:o}case"barcode":{let a=We[t.type];if(!a)throw new Error(`retail-print-kit: TSPL has no ${t.type}`);let s=t.module??2;return`BARCODE ${n},${i},"${a}",${Math.round(t.height)},${t.text===!1?0:1},${r(t.rotation)},${s},${s*2},${Ot(t.data)}`}case"qr":return`QRCODE ${n},${i},${t.correction??"M"},${t.module??4},A,${r(t.rotation)},${Ot(t.data)}`;case"box":return`BOX ${n},${i},${n+Math.round(t.width)},${i+Math.round(t.height)},${t.thickness??2}`;case"rect":return`BAR ${n},${i},${Math.round(t.width)},${Math.round(t.height)}`;case"image":{let a=Math.ceil(t.bitmap.width/8),s=`BITMAP ${n},${i},${a},${t.bitmap.height},0,`,o=Xe(t.bitmap),u=new Uint8Array(s.length+o.length+1);for(let l=0;l<s.length;l++)u[l]=s.charCodeAt(l);return u.set(o,s.length),u[u.length-1]=10,u}}}function ct(t){let e=[`SIZE ${ee(t.width,t.dpi)} mm,${ee(t.height,t.dpi)} mm`,`GAP ${t.gap.toFixed(2)} mm,0 mm`,"DIRECTION 1,0","REFERENCE 0,0"];t.speed!==void 0&&e.push(`SPEED ${t.speed}`),t.darkness!==void 0&&e.push(`DENSITY ${Math.round(t.darkness)}`),e.push("CLS");for(let a of t.ops)e.push(Je(a,t.dpi));e.push(`PRINT ${t.copies},1`);let n=e.map(a=>typeof a=="string"?new TextEncoder().encode(a+`
|
|
17
|
+
`):a),i=new Uint8Array(n.reduce((a,s)=>a+s.length,0)),r=0;for(let a of n)i.set(a,r),r+=a.length;return i}var _t=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],Ve={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function tn(t){let e=_t[0][0],n=_t[0][1];for(let[r,a]of _t)a<=t&&(e=r,n=a);let i=Math.max(1,Math.min(9,Math.floor(t/n)));return{font:e,mul:i}}function en(t){let e=Math.round(t.x),n=Math.round(t.y),i=t.rotation??0;switch(t.kind){case"text":{let{font:r,mul:a}=tn(t.height);return`A${r},${e},${n},${a},${a},${i/90},0${t.invert?"R":"E"},${t.text}`}case"barcode":{let r=Ve[t.type];if(!r)throw new Error(`retail-print-kit: EZPL has no ${t.type}`);let a=t.module??2;return`B${r},${e},${n},${a},${a*2},${Math.round(t.height)},${i/90},${t.text===!1?0:1},${t.data}`}case"qr":{let r={L:"L",M:"M",Q:"Q",H:"H"}[t.correction??"M"];return`W${e},${n},5,2,${r},${t.module??4},${i/90},${t.data.length}
|
|
18
|
+
${t.data}`}case"box":return`R${e},${n},${e+Math.round(t.width)},${n+Math.round(t.height)},${t.thickness??2},${t.thickness??2}`;case"rect":return`R${e},${n},${e+Math.round(t.width)},${n+Math.round(t.height)},${Math.round(t.width)},${Math.round(t.height)}`;case"image":throw new Error("retail-print-kit: EZPL images are not implemented yet")}}function lt(t){let e=[`^Q${K(t.height,t.dpi).toFixed(2)},${t.gap.toFixed(0)}`,`^W${K(t.width,t.dpi).toFixed(2)}`,`^H${t.darkness??10}`,`^P${t.copies}`,`^S${t.speed??2}`,"^AD","^C1","^R0","~Q+0","^O0","^D0","^E18","~R255","^L"];for(let n of t.ops)e.push(en(n));return e.push("E"),e.join(`
|
|
24
19
|
`)+`
|
|
25
|
-
`}var
|
|
20
|
+
`}var W=class{constructor(e){let n=e.dpi??203;this.label={width:nt(e.widthMm,n),height:nt(e.heightMm,n),dpi:n,gap:e.gapMm??3,copies:1,ops:[]}}mm(e){return nt(e,this.label.dpi)}copies(e){return this.label.copies=Math.max(1,Math.floor(e)),this}darkness(e){return this.label.darkness=e,this}speed(e){return this.label.speed=e,this}push(e){return this.label.ops.push(e),this}text(e,n,i,r,a={}){return this.push({kind:"text",x:e,y:n,text:i,height:r,...a})}barcode(e,n,i,r,a,s={}){return this.push({kind:"barcode",x:e,y:n,data:i,type:r,height:a,...s})}qr(e,n,i,r={}){return this.push({kind:"qr",x:e,y:n,data:i,...r})}box(e,n,i,r,a=2){return this.push({kind:"box",x:e,y:n,width:i,height:r,thickness:a})}rect(e,n,i,r){return this.push({kind:"rect",x:e,y:n,width:i,height:r})}image(e,n,i){return this.push({kind:"image",x:e,y:n,bitmap:i})}};function ne(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Rt(t){return t.rotation?` transform="rotate(${t.rotation} ${t.x} ${t.y})"`:""}function vt(t){return`data:image/png;base64,${U(F(t))}`}function nn(t){switch(t.kind){case"text":{let e=t.width??t.height*.9,n=t.text.length*e*.62;return`${t.invert?`<rect x="${t.x}" y="${t.y}" width="${n}" height="${t.height}" fill="#000"/>`:""}<text x="${t.x}" y="${t.y+t.height*.82}" font-size="${t.height}" textLength="${n}" lengthAdjust="spacingAndGlyphs" font-family="Helvetica, Arial, sans-serif"${t.bold?' font-weight="bold"':""} fill="${t.invert?"#fff":"#000"}"${Rt(t)}>${ne(t.text)}</text>`}case"barcode":{let e=tt(t.type,t.data,t.module??2,Math.round(t.height)),n=t.text===!1?"":`<text x="${t.x+e.width/2}" y="${t.y+t.height+14}" font-size="14" text-anchor="middle" font-family="Helvetica, Arial, sans-serif">${ne(t.data)}</text>`;return`<image x="${t.x}" y="${t.y}" width="${e.width}" height="${e.height}" href="${vt(e)}" style="image-rendering:pixelated"${Rt(t)}/>${n}`}case"qr":{let e=Q(t.data,{size:t.module??4,correction:t.correction});return`<image x="${t.x}" y="${t.y}" width="${e.width}" height="${e.height}" href="${vt(e)}" style="image-rendering:pixelated"${Rt(t)}/>`}case"box":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="none" stroke="#000" stroke-width="${t.thickness??2}"/>`;case"rect":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="#000"/>`;case"image":return`<image x="${t.x}" y="${t.y}" width="${t.bitmap.width}" height="${t.bitmap.height}" href="${vt(t.bitmap)}" style="image-rendering:pixelated"/>`}}function re(t){let e=t.ops.map(nn).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${t.width} ${t.height}" width="${t.width}" height="${t.height}"><rect width="${t.width}" height="${t.height}" fill="#fff"/>${e}</svg>`}function ie(t,e){if(t.version!==1||t.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new W({widthMm:t.widthMm,heightMm:t.heightMm,dpi:t.dpi,gapMm:t.gapMm}),i={root:e,current:e};for(let r of t.elements)if(!(r.when&&!Y(r.when,i)))switch(r.type){case"text":n.text(r.x,r.y,D(r.value,i),r.height,{width:r.width,rotation:r.rotation,bold:r.bold,invert:r.invert});break;case"barcode":n.barcode(r.x,r.y,D(r.value,i),r.format??"CODE128",r.height,{module:r.module,rotation:r.rotation,text:r.text});break;case"qr":n.qr(r.x,r.y,D(r.value,i),{module:r.module,correction:r.correction,rotation:r.rotation});break;case"box":n.box(r.x,r.y,r.width,r.height,r.thickness);break;case"rect":n.rect(r.x,r.y,r.width,r.height);break}return n.label}function rn(t,e){switch(e){case"zpl":return new TextEncoder().encode(ft(t));case"ezpl":return new TextEncoder().encode(lt(t));case"tspl":return ct(t)}}return de(on);})();
|
|
26
21
|
//# sourceMappingURL=retail-print-kit.js.map
|