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 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
- **[Open the designer](https://arka162.github.io/retail-print-kit/)** · [Printer matrix](docs/printer-matrix.md) · [Hardware checklist](docs/hardware-checklist.md)
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
  ![Receipt designer](https://raw.githubusercontent.com/arka162/retail-print-kit/main/docs/images/designer-receipt.png)
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
- The core is pure JavaScript. Add a transport only if you need it:
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 Vn=Object.create;var ut=Object.defineProperty;var Kn=Object.getOwnPropertyDescriptor;var Jn=Object.getOwnPropertyNames;var Yn=Object.getPrototypeOf,jn=Object.prototype.hasOwnProperty;var Zn=(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),Wn=(e,t)=>{for(var n in t)ut(e,n,{get:t[n],enumerable:!0})},$e=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Jn(t))!jn.call(e,i)&&i!==n&&ut(e,i,{get:()=>t[i],enumerable:!(r=Kn(t,i))||r.enumerable});return e};var Xn=(e,t,n)=>(n=e!=null?Vn(Yn(e)):{},$e(t||!e||!e.__esModule?ut(n,"default",{value:e,enumerable:!0}):n,e)),tr=e=>$e(ut({},"__esModule",{value:!0}),e);var Me=p((Ni,Te)=>{Te.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var $=p(I=>{var It,er=[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];I.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};I.getSymbolTotalCodewords=function(t){return er[t]};I.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};I.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');It=t};I.isKanjiModeEnabled=function(){return typeof It<"u"};I.toSJIS=function(t){return It(t)}});var ct=p(x=>{x.L={bit:1};x.M={bit:0};x.Q={bit:3};x.H={bit:2};function nr(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 nr(t)}catch{return n}}});var Pe=p((ki,Se)=>{function Le(){this.buffer=[],this.length=0}Le.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++}};Se.exports=Le});var Ie=p((Ui,Ne)=>{function j(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)}j.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)};j.prototype.get=function(e,t){return this.data[e*this.size+t]};j.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n};j.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};Ne.exports=j});var Re=p(lt=>{var rr=$().getSymbolSize;lt.getRowColCoords=function(t){if(t===1)return[];let n=Math.floor(t/7)+2,r=rr(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()};lt.getPositions=function(t){let n=[],r=lt.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 Oe=p(Ue=>{var ir=$().getSymbolSize,ke=7;Ue.getPositions=function(t){let n=ir(t);return[[0,0],[n-ke,0],[0,n-ke]]}});var De=p(m=>{m.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var R={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+=R.N1+(i-5)),s=f,i=1),f=t.get(c,u),f===a?o++:(o>=5&&(r+=R.N1+(o-5)),a=f,o=1)}i>=5&&(r+=R.N1+(i-5)),o>=5&&(r+=R.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*R.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*R.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)*R.N4};function or(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,or(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 kt=p(Rt=>{var T=ct(),ft=[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],ht=[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];Rt.getBlocksCount=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}};Rt.getTotalCodewordsCount=function(t,n){switch(n){case T.L:return ht[(t-1)*4+0];case T.M:return ht[(t-1)*4+1];case T.Q:return ht[(t-1)*4+2];case T.H:return ht[(t-1)*4+3];default:return}}});var Fe=p(gt=>{var Z=new Uint8Array(512),dt=new Uint8Array(256);(function(){let t=1;for(let n=0;n<255;n++)Z[n]=t,dt[t]=n,t<<=1,t&256&&(t^=285);for(let n=255;n<512;n++)Z[n]=Z[n-255]})();gt.log=function(t){if(t<1)throw new Error("log("+t+")");return dt[t]};gt.exp=function(t){return Z[t]};gt.mul=function(t,n){return t===0||n===0?0:Z[dt[t]+dt[n]]}});var qe=p(W=>{var Ut=Fe();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]^=Ut.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]^=Ut.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,Ut.exp(r)]));return n}});var ze=p((zi,_e)=>{var ve=qe();function Ot(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Ot.prototype.initialize=function(t){this.degree=t,this.genPoly=ve.generateECPolynomial(this.degree)};Ot.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=ve.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};_e.exports=Ot});var Dt=p(Ge=>{Ge.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}});var Ft=p(C=>{var He="[0-9]+",sr="[A-Z $%*+\\-./:]+",X="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";X=X.replace(/u/g,"\\u");var ar="(?:(?![A-Z0-9 $%*+\\-./:]|"+X+`)(?:.|[\r
2
- ]))+`;C.KANJI=new RegExp(X,"g");C.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");C.BYTE=new RegExp(ar,"g");C.NUMERIC=new RegExp(He,"g");C.ALPHANUMERIC=new RegExp(sr,"g");var ur=new RegExp("^"+X+"$"),cr=new RegExp("^"+He+"$"),lr=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");C.testKanji=function(t){return ur.test(t)};C.testNumeric=function(t){return cr.test(t)};C.testAlphanumeric=function(t){return lr.test(t)}});var M=p(b=>{var fr=Dt(),qt=Ft();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(!fr.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 qt.testNumeric(t)?b.NUMERIC:qt.testAlphanumeric(t)?b.ALPHANUMERIC:qt.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 hr(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 hr(t)}catch{return n}}});var Ye=p(k=>{var pt=$(),dr=kt(),Qe=ct(),L=M(),vt=Dt(),Ke=7973,Ve=pt.getBCHDigit(Ke);function gr(e,t,n){for(let r=1;r<=40;r++)if(t<=k.getCapacity(r,n,e))return r}function Je(e,t){return L.getCharCountIndicator(e,t)+4}function pr(e,t){let n=0;return e.forEach(function(r){let i=Je(r.mode,t);n+=i+r.getBitsLength()}),n}function mr(e,t){for(let n=1;n<=40;n++)if(pr(e,n)<=k.getCapacity(n,t,L.MIXED))return n}k.from=function(t,n){return vt.isValid(t)?parseInt(t,10):n};k.getCapacity=function(t,n,r){if(!vt.isValid(t))throw new Error("Invalid QR Code version");typeof r>"u"&&(r=L.BYTE);let i=pt.getSymbolTotalCodewords(t),o=dr.getTotalCodewordsCount(t,n),s=(i-o)*8;if(r===L.MIXED)return s;let a=s-Je(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)}};k.getBestVersionForData=function(t,n){let r,i=Qe.from(n,Qe.M);if(Array.isArray(t)){if(t.length>1)return mr(t,i);if(t.length===0)return 1;r=t[0]}else r=t;return gr(r.mode,r.getLength(),i)};k.getEncodedBits=function(t){if(!vt.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;pt.getBCHDigit(n)-Ve>=0;)n^=Ke<<pt.getBCHDigit(n)-Ve;return t<<12|n}});var Xe=p(We=>{var _t=$(),Ze=1335,wr=21522,je=_t.getBCHDigit(Ze);We.getEncodedBits=function(t,n){let r=t.bit<<3|n,i=r<<10;for(;_t.getBCHDigit(i)-je>=0;)i^=Ze<<_t.getBCHDigit(i)-je;return(r<<10|i)^wr}});var en=p((Ji,tn)=>{var br=M();function _(e){this.mode=br.NUMERIC,this.data=e.toString()}_.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};_.prototype.getLength=function(){return this.data.length};_.prototype.getBitsLength=function(){return _.getBitsLength(this.data.length)};_.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))};tn.exports=_});var rn=p((Yi,nn)=>{var yr=M(),zt=["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 z(e){this.mode=yr.ALPHANUMERIC,this.data=e}z.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};z.prototype.getLength=function(){return this.data.length};z.prototype.getBitsLength=function(){return z.getBitsLength(this.data.length)};z.prototype.write=function(t){let n;for(n=0;n+2<=this.data.length;n+=2){let r=zt.indexOf(this.data[n])*45;r+=zt.indexOf(this.data[n+1]),t.put(r,11)}this.data.length%2&&t.put(zt.indexOf(this.data[n]),6)};nn.exports=z});var sn=p((ji,on)=>{var xr=M();function G(e){this.mode=xr.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}G.getBitsLength=function(t){return t*8};G.prototype.getLength=function(){return this.data.length};G.prototype.getBitsLength=function(){return G.getBitsLength(this.data.length)};G.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};on.exports=G});var un=p((Zi,an)=>{var Er=M(),Br=$();function H(e){this.mode=Er.KANJI,this.data=e}H.getBitsLength=function(t){return t*13};H.prototype.getLength=function(){return this.data.length};H.prototype.getBitsLength=function(){return H.getBitsLength(this.data.length)};H.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=Br.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)}};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
- Suggested mode is: `+d.toString(r));switch(n===d.KANJI&&!mt.isKanjiModeEnabled()&&(n=d.BYTE),n){case d.NUMERIC:return new hn(e);case d.ALPHANUMERIC:return new dn(e);case d.KANJI:return new pn(e);case d.BYTE:return new gn(e)}}Q.fromArray=function(t){return t.reduce(function(n,r){return typeof r=="string"?n.push(fn(r,null)):r.data&&n.push(fn(r.data,r.mode)),n},[])};Q.fromString=function(t,n){let r=mn(t,mt.isKanjiModeEnabled()),i=$r(r),o=Tr(i,n),s=Ar.find_path(o.map,"start","end"),a=[];for(let u=1;u<s.length-1;u++)a.push(o.table[s[u]].node);return Q.fromArray(Cr(a))};Q.rawSplit=function(t){return Q.fromArray(mn(t,mt.isKanjiModeEnabled()))}});var yn=p(bn=>{var bt=$(),Qt=ct(),Mr=Pe(),Lr=Ie(),Sr=Re(),Pr=Oe(),Jt=De(),Yt=kt(),Nr=ze(),wt=Ye(),Ir=Xe(),Rr=M(),Vt=wn();function kr(e,t){let n=e.size,r=Pr.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 Ur(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 Or(e,t){let n=Sr.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 Dr(e,t){let n=e.size,r=wt.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 Kt(e,t,n){let r=e.size,i=Ir.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 Fr(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 qr(e,t,n){let r=new Mr;n.forEach(function(u){r.put(u.mode.bit,4),r.put(u.getLength(),Rr.getCharCountIndicator(u.mode,e)),u.write(r)});let i=bt.getSymbolTotalCodewords(e),o=Yt.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 vr(r,e,t)}function vr(e,t,n){let r=bt.getSymbolTotalCodewords(t),i=Yt.getTotalCodewordsCount(t,n),o=r-i,s=Yt.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 Nr(l),w=0,y=new Array(s),Ae=new Array(s),St=0,Qn=new Uint8Array(e.buffer);for(let v=0;v<s;v++){let Nt=v<u?f:g;y[v]=Qn.slice(w,w+Nt),Ae[v]=h.encode(y[v]),w+=Nt,St=Math.max(St,Nt)}let Pt=new Uint8Array(r),Ce=0,B,A;for(B=0;B<St;B++)for(A=0;A<s;A++)B<y[A].length&&(Pt[Ce++]=y[A][B]);for(B=0;B<l;B++)for(A=0;A<s;A++)Pt[Ce++]=Ae[A][B];return Pt}function _r(e,t,n,r){let i;if(Array.isArray(e))i=Vt.fromArray(e);else if(typeof e=="string"){let c=t;if(!c){let f=Vt.rawSplit(e);c=wt.getBestVersionForData(f,n)}i=Vt.fromString(e,c||40)}else throw new Error("Invalid data");let o=wt.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=qr(t,n,i),a=bt.getSymbolSize(t),u=new Lr(a);return kr(u,t),Ur(u),Or(u,t),Kt(u,n,0),t>=7&&Dr(u,t),Fr(u,s),isNaN(r)&&(r=Jt.getBestMask(u,Kt.bind(null,u,n))),Jt.applyMask(r,u),Kt(u,n,r),{modules:u,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}bn.create=function(t,n){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Qt.M,i,o;return typeof n<"u"&&(r=Qt.from(n.errorCorrectionLevel,Qt.M),i=wt.from(n.version),o=Jt.from(n.maskPattern),n.toSJISFunc&&bt.setToSJISFunction(n.toSJISFunc)),_r(t,i,r,o)}});var jt=p(U=>{function xn(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("")}}U.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:xn(t.color.dark||"#000000ff"),light:xn(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}};U.getScale=function(t,n){return n.width&&n.width>=t+n.margin*2?n.width/(t+n.margin*2):n.scale};U.getImageWidth=function(t,n){let r=U.getScale(t,n);return Math.floor((t+n.margin*2)*r)};U.qrToImageData=function(t,n,r){let i=n.modules.size,o=n.modules.data,s=U.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 En=p(yt=>{var Zt=jt();function zr(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 Gr(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}yt.render=function(t,n,r){let i=r,o=n;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),n||(o=Gr()),i=Zt.getOptions(i);let s=Zt.getImageWidth(t.modules.size,i),a=o.getContext("2d"),u=a.createImageData(s,s);return Zt.qrToImageData(u.data,t,i),zr(a,o,s),a.putImageData(u,0,0),o};yt.renderToDataURL=function(t,n,r){let i=r;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),i||(i={});let o=yt.render(t,n,i),s=i.type||"image/png",a=i.rendererOpts||{};return o.toDataURL(s,a.quality)}});var Cn=p(An=>{var Hr=jt();function Bn(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function Wt(e,t,n){let r=e+t;return typeof n<"u"&&(r+=" "+n),r}function Qr(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?Wt("M",u+n,.5+c+n):Wt("m",i,0),i=0,o=!1),u+1<t&&e[a+1]||(r+=Wt("h",s),s=0)):i++}return r}An.render=function(t,n,r){let i=Hr.getOptions(n),o=t.modules.size,s=t.modules.data,a=o+i.margin*2,u=i.color.light.a?"<path "+Bn(i.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",c="<path "+Bn(i.color.dark,"stroke")+' d="'+Qr(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 Tn=p(rt=>{var Vr=Me(),Xt=yn(),$n=En(),Kr=Cn();function te(e,t,n,r,i){let o=[].slice.call(arguments,1),s=o.length,a=typeof o[s-1]=="function";if(!a&&!Vr())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=Xt.create(n,r);u(e(f,t,r))}catch(f){c(f)}})}try{let u=Xt.create(n,r);i(null,e(u,t,r))}catch(u){i(u)}}rt.create=Xt.create;rt.toCanvas=te.bind(null,$n.render);rt.toDataURL=te.bind(null,$n.renderToDataURL);rt.toString=te.bind(null,function(e,t,n){return Kr.render(e,n)})});var Si={};Wn(Si,{LabelBuilder:()=>Y,OpBuilder:()=>it,barcodeBitmap:()=>ot,bitmapToPng:()=>N,blit:()=>Ln,code128:()=>Pn,code39:()=>Un,deserializeBitmap:()=>ee,ditherRgba:()=>jr,dotsToMm:()=>J,ean13:()=>ie,ean8:()=>kn,emptyBitmap:()=>O,encodeEzpl:()=>Lt,encodeLabel:()=>Li,encodeTspl:()=>Mt,encodeZpl:()=>Tt,epsonTmM30:()=>ae,epsonTmT20:()=>se,epsonTmT88:()=>oe,evaluate:()=>q,filters:()=>de,fitWidth:()=>Yr,fromBase64:()=>xt,fromRgba:()=>Jr,genericEscPos:()=>At,genericEscPos58:()=>ue,getPixel:()=>Et,interpolate:()=>E,labelToSvg:()=>Gn,lookup:()=>ge,mmToDots:()=>at,opsToHtml:()=>vn,parseStyle:()=>Sn,pattern:()=>On,profileById:()=>fi,profiles:()=>Dn,qrBitmap:()=>F,render:()=>qn,renderBlocks:()=>K,renderLabel:()=>Hn,serializeBitmap:()=>Zr,setPixel:()=>D,starMcPrint3:()=>fe,starTsp100:()=>he,starTsp650:()=>le,toBase64:()=>P,truthy:()=>V,upcA:()=>Rn});var Mn=Xn(Tn());var S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function P(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+=S[s>>18&63]+S[s>>12&63],t+=n+1<e.length?S[s>>6&63]:"=",t+=n+2<e.length?S[s&63]:"="}return t}function xt(e){if(typeof Buffer<"u"){let i=Buffer.from(e,"base64");return new Uint8Array(i.buffer,i.byteOffset,i.byteLength)}let t=e.replace(/[^A-Za-z0-9+/]/g,""),n=new Uint8Array(Math.floor(t.length*3/4)),r=0;for(let i=0;i<t.length;i+=4){let o=S.indexOf(t[i])<<18|S.indexOf(t[i+1])<<12|(S.indexOf(t[i+2])&63)<<6|S.indexOf(t[i+3])&63;n[r++]=o>>16&255,i+2<t.length&&(n[r++]=o>>8&255),i+3<t.length&&(n[r++]=o&255)}return n.subarray(0,r)}function O(e,t){return{width:e,height:t,bits:new Uint8Array(Math.ceil(e/8)*t)}}function D(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 Et(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 Jr(e,t,n,r=128){let i=O(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&&D(i,s,o,!0)}return i}function Ln(e,t,n,r){for(let i=0;i<t.height;i++)for(let o=0;o<t.width;o++)Et(t,o,i)&&D(e,n+o,r+i,!0)}function Yr(e,t,n="center"){if(e.width===t)return e;let r=O(t,e.height),i=n==="left"?0:n==="right"?t-e.width:Math.floor((t-e.width)/2);return Ln(r,e,i,0),r}function F(e,t={}){let n=Mn.default.create(e,{errorCorrectionLevel:t.correction??"M"}),r=n.modules.size,i=Math.max(1,Math.min(16,Math.floor(t.size??6))),o=O(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++)D(o,a*i+c,s*i+u,!0);return o}function jr(e,t,n){let r=new Float32Array(t*n);for(let o=0;o<t*n;o++){let s=e[o*4+3]/255;r[o]=(.299*e[o*4]+.587*e[o*4+1]+.114*e[o*4+2])*s+255*(1-s)}let i=O(t,n);for(let o=0;o<n;o++)for(let s=0;s<t;s++){let a=o*t+s,u=r[a],c=u<128;c&&D(i,s,o,!0);let f=u-(c?0:255);s+1<t&&(r[a+1]+=f*7/16),o+1<n&&(s>0&&(r[a+t-1]+=f*3/16),r[a+t]+=f*5/16,s+1<t&&(r[a+t+1]+=f/16))}return i}function Zr(e){return{width:e.width,height:e.height,data:P(e.bits)}}function ee(e){let t=xt(e.data),n=Math.ceil(e.width/8)*e.height;if(t.length!==n)throw new Error(`retail-print-kit: bitmap data is ${t.length} bytes, expected ${n}`);return{width:e.width,height:e.height,bits:t}}var Wr={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},it=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=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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}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)||"&nbsp;"}</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">&nbsp;</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+="&lt;";break;case">":g+="&gt;";break;case"&":g+="&amp;";break;case'"':g+="&quot;";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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}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)||"&nbsp;"}</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">&nbsp;</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 -${r}px}
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>${g}</body></html>`}var we={0:"N",90:"R",180:"I",270:"B"},bi={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function be(e){return e.replace(/[\^~\\]/g,t=>`\\${t}`)}function yi(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 xi(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${we[e.rotation??0]},${Math.round(e.height)},${n}^FD${be(e.text)}^FS`}case"barcode":{let n=bi[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}${we[e.rotation??0]},${Math.round(e.height)}${i}^FD${be(e.data)}^FS`}case"qr":{let n=e.correction??"M";return`${t}^BQ${we[e.rotation??0]},2,${e.module??4}^FD${n}A,${be(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,${yi(e.bitmap)}^FS`}}function Tt(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(xi(n));return t.push(`^PQ${e.copies},0,1,Y`,"^XZ"),t.join(`
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 at(e,t){return Math.round(e/25.4*t)}function J(e,t){return e/t*25.4}var Ei={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function ye(e){return`"${e.replace(/"/g,'\\["]')}"`}function _n(e,t){return J(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 Ai(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},${ye(e.text)}`;return e.invert?`${a}
21
- REVERSE ${n},${r},${Math.round(s*e.text.length*.6)},${o}`:a}case"barcode":{let o=Ei[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},${ye(e.data)}`}case"qr":return`QRCODE ${n},${r},${e.correction??"M"},${e.module??4},A,${i(e.rotation)},${ye(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 Mt(e){let t=[`SIZE ${_n(e.width,e.dpi)} mm,${_n(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(Ai(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 xe=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],Ci={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function $i(e){let t=xe[0][0],n=xe[0][1];for(let[i,o]of xe)o<=e&&(t=i,n=o);let r=Math.max(1,Math.min(9,Math.floor(e/n)));return{font:t,mul:r}}function Ti(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}=$i(e.height);return`A${i},${t},${n},${o},${o},${r/90},0${e.invert?"R":"E"},${e.text}`}case"barcode":{let i=Ci[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 Lt(e){let t=[`^Q${J(e.height,e.dpi).toFixed(2)},${e.gap.toFixed(0)}`,`^W${J(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(Ti(n));return t.push("E"),t.join(`
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 Y=class{constructor(t){let n=t.dpi??203;this.label={width:at(t.widthMm,n),height:at(t.heightMm,n),dpi:n,gap:t.gapMm??3,copies:1,ops:[]}}mm(t){return at(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 zn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function Ee(e){return e.rotation?` transform="rotate(${e.rotation} ${e.x} ${e.y})"`:""}function Be(e){return`data:image/png;base64,${P(N(e))}`}function Mi(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"}"${Ee(e)}>${zn(e.text)}</text>`}case"barcode":{let t=ot(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">${zn(e.data)}</text>`;return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${Be(t)}" style="image-rendering:pixelated"${Ee(e)}/>${n}`}case"qr":{let t=F(e.data,{size:e.module??4,correction:e.correction});return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${Be(t)}" style="image-rendering:pixelated"${Ee(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="${Be(e.bitmap)}" style="image-rendering:pixelated"/>`}}function Gn(e){let t=e.ops.map(Mi).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 Hn(e,t){if(e.version!==1||e.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new Y({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&&!V(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 Li(e,t){switch(t){case"zpl":return new TextEncoder().encode(Tt(e));case"ezpl":return new TextEncoder().encode(Lt(e));case"tspl":return Mt(e)}}return tr(Si);})();
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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}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