retail-print-kit 0.1.0 → 0.2.1

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.
@@ -1,25 +1,25 @@
1
- var Nn=Object.create;var he=Object.defineProperty;var In=Object.getOwnPropertyDescriptor;var Rn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,Un=Object.prototype.hasOwnProperty;var Dn=(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);var Fn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Rn(t))!Un.call(e,i)&&i!==n&&he(e,i,{get:()=>t[i],enumerable:!(r=In(t,i))||r.enumerable});return e};var On=(e,t,n)=>(n=e!=null?Nn(kn(e)):{},Fn(t||!e||!e.__esModule?he(n,"default",{value:e,enumerable:!0}):n,e));var ge=p((xi,de)=>{de.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var B=p(S=>{var $t,qn=[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];S.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};S.getSymbolTotalCodewords=function(t){return qn[t]};S.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};S.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');$t=t};S.isKanjiModeEnabled=function(){return typeof $t<"u"};S.toSJIS=function(t){return $t(t)}});var it=p(x=>{x.L={bit:1};x.M={bit:0};x.Q={bit:3};x.H={bit:2};function vn(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 vn(t)}catch{return n}}});var we=p((Ci,me)=>{function pe(){this.buffer=[],this.length=0}pe.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};me.exports=pe});var ye=p(($i,be)=>{function z(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)}z.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)};z.prototype.get=function(e,t){return this.data[e*this.size+t]};z.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n};z.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};be.exports=z});var xe=p(ot=>{var _n=B().getSymbolSize;ot.getRowColCoords=function(t){if(t===1)return[];let n=Math.floor(t/7)+2,r=_n(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()};ot.getPositions=function(t){let n=[],r=ot.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 Ce=p(Ae=>{var zn=B().getSymbolSize,Ee=7;Ae.getPositions=function(t){let n=zn(t);return[[0,0],[n-Ee,0],[0,n-Ee]]}});var $e=p(m=>{m.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var P={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+=P.N1+(i-5)),s=f,i=1),f=t.get(c,u),f===a?o++:(o>=5&&(r+=P.N1+(o-5)),a=f,o=1)}i>=5&&(r+=P.N1+(i-5)),o>=5&&(r+=P.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*P.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*P.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)*P.N4};function Gn(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,Gn(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 Tt=p(Bt=>{var T=it(),st=[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],at=[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];Bt.getBlocksCount=function(t,n){switch(n){case T.L:return st[(t-1)*4+0];case T.M:return st[(t-1)*4+1];case T.Q:return st[(t-1)*4+2];case T.H:return st[(t-1)*4+3];default:return}};Bt.getTotalCodewordsCount=function(t,n){switch(n){case T.L:return at[(t-1)*4+0];case T.M:return at[(t-1)*4+1];case T.Q:return at[(t-1)*4+2];case T.H:return at[(t-1)*4+3];default:return}}});var Be=p(ct=>{var G=new Uint8Array(512),ut=new Uint8Array(256);(function(){let t=1;for(let n=0;n<255;n++)G[n]=t,ut[t]=n,t<<=1,t&256&&(t^=285);for(let n=255;n<512;n++)G[n]=G[n-255]})();ct.log=function(t){if(t<1)throw new Error("log("+t+")");return ut[t]};ct.exp=function(t){return G[t]};ct.mul=function(t,n){return t===0||n===0?0:G[ut[t]+ut[n]]}});var Te=p(H=>{var Mt=Be();H.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]^=Mt.mul(t[i],n[o]);return r};H.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]^=Mt.mul(n[s],i);let o=0;for(;o<r.length&&r[o]===0;)o++;r=r.slice(o)}return r};H.generateECPolynomial=function(t){let n=new Uint8Array([1]);for(let r=0;r<t;r++)n=H.mul(n,new Uint8Array([1,Mt.exp(r)]));return n}});var Se=p((Ni,Le)=>{var Me=Te();function Lt(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Lt.prototype.initialize=function(t){this.degree=t,this.genPoly=Me.generateECPolynomial(this.degree)};Lt.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=Me.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};Le.exports=Lt});var St=p(Pe=>{Pe.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}});var Pt=p($=>{var Ne="[0-9]+",Hn="[A-Z $%*+\\-./:]+",Q="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Q=Q.replace(/u/g,"\\u");var Qn="(?:(?![A-Z0-9 $%*+\\-./:]|"+Q+`)(?:.|[\r
2
- ]))+`;$.KANJI=new RegExp(Q,"g");$.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");$.BYTE=new RegExp(Qn,"g");$.NUMERIC=new RegExp(Ne,"g");$.ALPHANUMERIC=new RegExp(Hn,"g");var Vn=new RegExp("^"+Q+"$"),Kn=new RegExp("^"+Ne+"$"),Jn=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");$.testKanji=function(t){return Vn.test(t)};$.testNumeric=function(t){return Kn.test(t)};$.testAlphanumeric=function(t){return Jn.test(t)}});var M=p(b=>{var Yn=St(),Nt=Pt();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(!Yn.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 Nt.testNumeric(t)?b.NUMERIC:Nt.testAlphanumeric(t)?b.ALPHANUMERIC:Nt.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 jn(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 jn(t)}catch{return n}}});var De=p(N=>{var lt=B(),Wn=Tt(),Ie=it(),L=M(),It=St(),ke=7973,Re=lt.getBCHDigit(ke);function Zn(e,t,n){for(let r=1;r<=40;r++)if(t<=N.getCapacity(r,n,e))return r}function Ue(e,t){return L.getCharCountIndicator(e,t)+4}function Xn(e,t){let n=0;return e.forEach(function(r){let i=Ue(r.mode,t);n+=i+r.getBitsLength()}),n}function tr(e,t){for(let n=1;n<=40;n++)if(Xn(e,n)<=N.getCapacity(n,t,L.MIXED))return n}N.from=function(t,n){return It.isValid(t)?parseInt(t,10):n};N.getCapacity=function(t,n,r){if(!It.isValid(t))throw new Error("Invalid QR Code version");typeof r>"u"&&(r=L.BYTE);let i=lt.getSymbolTotalCodewords(t),o=Wn.getTotalCodewordsCount(t,n),s=(i-o)*8;if(r===L.MIXED)return s;let a=s-Ue(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)}};N.getBestVersionForData=function(t,n){let r,i=Ie.from(n,Ie.M);if(Array.isArray(t)){if(t.length>1)return tr(t,i);if(t.length===0)return 1;r=t[0]}else r=t;return Zn(r.mode,r.getLength(),i)};N.getEncodedBits=function(t){if(!It.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;lt.getBCHDigit(n)-Re>=0;)n^=ke<<lt.getBCHDigit(n)-Re;return t<<12|n}});var ve=p(qe=>{var Rt=B(),Oe=1335,er=21522,Fe=Rt.getBCHDigit(Oe);qe.getEncodedBits=function(t,n){let r=t.bit<<3|n,i=r<<10;for(;Rt.getBCHDigit(i)-Fe>=0;)i^=Oe<<Rt.getBCHDigit(i)-Fe;return(r<<10|i)^er}});var ze=p((Fi,_e)=>{var nr=M();function U(e){this.mode=nr.NUMERIC,this.data=e.toString()}U.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};U.prototype.getLength=function(){return this.data.length};U.prototype.getBitsLength=function(){return U.getBitsLength(this.data.length)};U.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))};_e.exports=U});var He=p((Oi,Ge)=>{var rr=M(),kt=["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 D(e){this.mode=rr.ALPHANUMERIC,this.data=e}D.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};D.prototype.getLength=function(){return this.data.length};D.prototype.getBitsLength=function(){return D.getBitsLength(this.data.length)};D.prototype.write=function(t){let n;for(n=0;n+2<=this.data.length;n+=2){let r=kt.indexOf(this.data[n])*45;r+=kt.indexOf(this.data[n+1]),t.put(r,11)}this.data.length%2&&t.put(kt.indexOf(this.data[n]),6)};Ge.exports=D});var Ve=p((qi,Qe)=>{var ir=M();function F(e){this.mode=ir.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}F.getBitsLength=function(t){return t*8};F.prototype.getLength=function(){return this.data.length};F.prototype.getBitsLength=function(){return F.getBitsLength(this.data.length)};F.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};Qe.exports=F});var Je=p((vi,Ke)=>{var or=M(),sr=B();function O(e){this.mode=or.KANJI,this.data=e}O.getBitsLength=function(t){return t*13};O.prototype.getLength=function(){return this.data.length};O.prototype.getBitsLength=function(){return O.getBitsLength(this.data.length)};O.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=sr.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)}};Ke.exports=O});var Ye=p((_i,Ut)=>{"use strict";var V={single_source_shortest_paths:function(e,t,n){var r={},i={};i[t]=0;var o=V.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=V.single_source_shortest_paths(e,t,n);return V.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(e){var t=V.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 Ut<"u"&&(Ut.exports=V)});var rn=p(q=>{var d=M(),Ze=ze(),Xe=He(),tn=Ve(),en=Je(),K=Pt(),ft=B(),ar=Ye();function je(e){return unescape(encodeURIComponent(e)).length}function J(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 nn(e){let t=J(K.NUMERIC,d.NUMERIC,e),n=J(K.ALPHANUMERIC,d.ALPHANUMERIC,e),r,i;return ft.isKanjiModeEnabled()?(r=J(K.BYTE,d.BYTE,e),i=J(K.KANJI,d.KANJI,e)):(r=J(K.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 Dt(e,t){switch(t){case d.NUMERIC:return Ze.getBitsLength(e);case d.ALPHANUMERIC:return Xe.getBitsLength(e);case d.KANJI:return en.getBitsLength(e);case d.BYTE:return tn.getBitsLength(e)}}function ur(e){return e.reduce(function(t,n){let r=t.length-1>=0?t[t.length-1]:null;return r&&r.mode===n.mode?(t[t.length-1].data+=n.data,t):(t.push(n),t)},[])}function cr(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];switch(r.mode){case d.NUMERIC:t.push([r,{data:r.data,mode:d.ALPHANUMERIC,length:r.length},{data:r.data,mode:d.BYTE,length:r.length}]);break;case d.ALPHANUMERIC:t.push([r,{data:r.data,mode:d.BYTE,length:r.length}]);break;case d.KANJI:t.push([r,{data:r.data,mode:d.BYTE,length:je(r.data)}]);break;case d.BYTE:t.push([{data:r.data,mode:d.BYTE,length:je(r.data)}])}}return t}function lr(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]=Dt(n[l].lastCount+c.length,c.mode)-Dt(n[l].lastCount,c.mode),n[l].lastCount+=c.length):(n[l]&&(n[l].lastCount=c.length),r[l][f]=Dt(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 We(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&&!ft.isKanjiModeEnabled()&&(n=d.BYTE),n){case d.NUMERIC:return new Ze(e);case d.ALPHANUMERIC:return new Xe(e);case d.KANJI:return new en(e);case d.BYTE:return new tn(e)}}q.fromArray=function(t){return t.reduce(function(n,r){return typeof r=="string"?n.push(We(r,null)):r.data&&n.push(We(r.data,r.mode)),n},[])};q.fromString=function(t,n){let r=nn(t,ft.isKanjiModeEnabled()),i=cr(r),o=lr(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(ur(a))};q.rawSplit=function(t){return q.fromArray(nn(t,ft.isKanjiModeEnabled()))}});var sn=p(on=>{var dt=B(),Ft=it(),fr=we(),hr=ye(),dr=xe(),gr=Ce(),vt=$e(),_t=Tt(),pr=Se(),ht=De(),mr=ve(),wr=M(),Ot=rn();function br(e,t){let n=e.size,r=gr.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 yr(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 xr(e,t){let n=dr.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 Er(e,t){let n=e.size,r=ht.getEncodedBits(t),i,o,s;for(let a=0;a<18;a++)i=Math.floor(a/3),o=a%3+n-8-3,s=(r>>a&1)===1,e.set(i,o,s,!0),e.set(o,i,s,!0)}function qt(e,t,n){let r=e.size,i=mr.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 Ar(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 Cr(e,t,n){let r=new fr;n.forEach(function(u){r.put(u.mode.bit,4),r.put(u.getLength(),wr.getCharCountIndicator(u.mode,e)),u.write(r)});let i=dt.getSymbolTotalCodewords(e),o=_t.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 $r(r,e,t)}function $r(e,t,n){let r=dt.getSymbolTotalCodewords(t),i=_t.getTotalCodewordsCount(t,n),o=r-i,s=_t.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 pr(l),w=0,y=new Array(s),le=new Array(s),Et=0,Pn=new Uint8Array(e.buffer);for(let k=0;k<s;k++){let Ct=k<u?f:g;y[k]=Pn.slice(w,w+Ct),le[k]=h.encode(y[k]),w+=Ct,Et=Math.max(Et,Ct)}let At=new Uint8Array(r),fe=0,A,C;for(A=0;A<Et;A++)for(C=0;C<s;C++)A<y[C].length&&(At[fe++]=y[C][A]);for(A=0;A<l;A++)for(C=0;C<s;C++)At[fe++]=le[C][A];return At}function Br(e,t,n,r){let i;if(Array.isArray(e))i=Ot.fromArray(e);else if(typeof e=="string"){let c=t;if(!c){let f=Ot.rawSplit(e);c=ht.getBestVersionForData(f,n)}i=Ot.fromString(e,c||40)}else throw new Error("Invalid data");let o=ht.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(`
1
+ var Rn=Object.create;var de=Object.defineProperty;var kn=Object.getOwnPropertyDescriptor;var Un=Object.getOwnPropertyNames;var On=Object.getPrototypeOf,Dn=Object.prototype.hasOwnProperty;var Fn=(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);var qn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Un(t))!Dn.call(e,i)&&i!==n&&de(e,i,{get:()=>t[i],enumerable:!(r=kn(t,i))||r.enumerable});return e};var vn=(e,t,n)=>(n=e!=null?Rn(On(e)):{},qn(t||!e||!e.__esModule?de(n,"default",{value:e,enumerable:!0}):n,e));var pe=p((Bi,ge)=>{ge.exports=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}});var $=p(P=>{var $t,_n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];P.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};P.getSymbolTotalCodewords=function(t){return _n[t]};P.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};P.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');$t=t};P.isKanjiModeEnabled=function(){return typeof $t<"u"};P.toSJIS=function(t){return $t(t)}});var ot=p(x=>{x.L={bit:1};x.M={bit:0};x.Q={bit:3};x.H={bit:2};function zn(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 zn(t)}catch{return n}}});var be=p(($i,we)=>{function me(){this.buffer=[],this.length=0}me.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++}};we.exports=me});var xe=p((Ti,ye)=>{function V(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)}V.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)};V.prototype.get=function(e,t){return this.data[e*this.size+t]};V.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n};V.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};ye.exports=V});var Ee=p(st=>{var Gn=$().getSymbolSize;st.getRowColCoords=function(t){if(t===1)return[];let n=Math.floor(t/7)+2,r=Gn(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()};st.getPositions=function(t){let n=[],r=st.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 Ce=p(Ae=>{var Hn=$().getSymbolSize,Be=7;Ae.getPositions=function(t){let n=Hn(t);return[[0,0],[n-Be,0],[0,n-Be]]}});var $e=p(m=>{m.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var N={N1:3,N2:3,N3:40,N4:10};m.isValid=function(t){return t!=null&&t!==""&&!isNaN(t)&&t>=0&&t<=7};m.from=function(t){return m.isValid(t)?parseInt(t,10):void 0};m.getPenaltyN1=function(t){let n=t.size,r=0,i=0,o=0,s=null,a=null;for(let u=0;u<n;u++){i=o=0,s=a=null;for(let c=0;c<n;c++){let f=t.get(u,c);f===s?i++:(i>=5&&(r+=N.N1+(i-5)),s=f,i=1),f=t.get(c,u),f===a?o++:(o>=5&&(r+=N.N1+(o-5)),a=f,o=1)}i>=5&&(r+=N.N1+(i-5)),o>=5&&(r+=N.N1+(o-5))}return r};m.getPenaltyN2=function(t){let n=t.size,r=0;for(let i=0;i<n-1;i++)for(let o=0;o<n-1;o++){let s=t.get(i,o)+t.get(i,o+1)+t.get(i+1,o)+t.get(i+1,o+1);(s===4||s===0)&&r++}return r*N.N2};m.getPenaltyN3=function(t){let n=t.size,r=0,i=0,o=0;for(let s=0;s<n;s++){i=o=0;for(let a=0;a<n;a++)i=i<<1&2047|t.get(s,a),a>=10&&(i===1488||i===93)&&r++,o=o<<1&2047|t.get(a,s),a>=10&&(o===1488||o===93)&&r++}return r*N.N3};m.getPenaltyN4=function(t){let n=0,r=t.data.length;for(let o=0;o<r;o++)n+=t.data[o];return Math.abs(Math.ceil(n*100/r/5)-10)*N.N4};function Qn(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,Qn(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 Mt=p(Tt=>{var T=ot(),at=[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],ut=[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];Tt.getBlocksCount=function(t,n){switch(n){case T.L:return at[(t-1)*4+0];case T.M:return at[(t-1)*4+1];case T.Q:return at[(t-1)*4+2];case T.H:return at[(t-1)*4+3];default:return}};Tt.getTotalCodewordsCount=function(t,n){switch(n){case T.L:return ut[(t-1)*4+0];case T.M:return ut[(t-1)*4+1];case T.Q:return ut[(t-1)*4+2];case T.H:return ut[(t-1)*4+3];default:return}}});var Te=p(lt=>{var K=new Uint8Array(512),ct=new Uint8Array(256);(function(){let t=1;for(let n=0;n<255;n++)K[n]=t,ct[t]=n,t<<=1,t&256&&(t^=285);for(let n=255;n<512;n++)K[n]=K[n-255]})();lt.log=function(t){if(t<1)throw new Error("log("+t+")");return ct[t]};lt.exp=function(t){return K[t]};lt.mul=function(t,n){return t===0||n===0?0:K[ct[t]+ct[n]]}});var Me=p(J=>{var Lt=Te();J.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]^=Lt.mul(t[i],n[o]);return r};J.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]^=Lt.mul(n[s],i);let o=0;for(;o<r.length&&r[o]===0;)o++;r=r.slice(o)}return r};J.generateECPolynomial=function(t){let n=new Uint8Array([1]);for(let r=0;r<t;r++)n=J.mul(n,new Uint8Array([1,Lt.exp(r)]));return n}});var Pe=p((Ri,Se)=>{var Le=Me();function St(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}St.prototype.initialize=function(t){this.degree=t,this.genPoly=Le.generateECPolynomial(this.degree)};St.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=Le.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};Se.exports=St});var Pt=p(Ne=>{Ne.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}});var Nt=p(C=>{var Ie="[0-9]+",Vn="[A-Z $%*+\\-./:]+",Y="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Y=Y.replace(/u/g,"\\u");var Kn="(?:(?![A-Z0-9 $%*+\\-./:]|"+Y+`)(?:.|[\r
2
+ ]))+`;C.KANJI=new RegExp(Y,"g");C.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");C.BYTE=new RegExp(Kn,"g");C.NUMERIC=new RegExp(Ie,"g");C.ALPHANUMERIC=new RegExp(Vn,"g");var Jn=new RegExp("^"+Y+"$"),Yn=new RegExp("^"+Ie+"$"),jn=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");C.testKanji=function(t){return Jn.test(t)};C.testNumeric=function(t){return Yn.test(t)};C.testAlphanumeric=function(t){return jn.test(t)}});var M=p(b=>{var Zn=Pt(),It=Nt();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(!Zn.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 It.testNumeric(t)?b.NUMERIC:It.testAlphanumeric(t)?b.ALPHANUMERIC:It.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 Wn(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 Wn(t)}catch{return n}}});var De=p(I=>{var ft=$(),Xn=Mt(),Re=ot(),L=M(),Rt=Pt(),Ue=7973,ke=ft.getBCHDigit(Ue);function tr(e,t,n){for(let r=1;r<=40;r++)if(t<=I.getCapacity(r,n,e))return r}function Oe(e,t){return L.getCharCountIndicator(e,t)+4}function er(e,t){let n=0;return e.forEach(function(r){let i=Oe(r.mode,t);n+=i+r.getBitsLength()}),n}function nr(e,t){for(let n=1;n<=40;n++)if(er(e,n)<=I.getCapacity(n,t,L.MIXED))return n}I.from=function(t,n){return Rt.isValid(t)?parseInt(t,10):n};I.getCapacity=function(t,n,r){if(!Rt.isValid(t))throw new Error("Invalid QR Code version");typeof r>"u"&&(r=L.BYTE);let i=ft.getSymbolTotalCodewords(t),o=Xn.getTotalCodewordsCount(t,n),s=(i-o)*8;if(r===L.MIXED)return s;let a=s-Oe(r,t);switch(r){case L.NUMERIC:return Math.floor(a/10*3);case L.ALPHANUMERIC:return Math.floor(a/11*2);case L.KANJI:return Math.floor(a/13);case L.BYTE:default:return Math.floor(a/8)}};I.getBestVersionForData=function(t,n){let r,i=Re.from(n,Re.M);if(Array.isArray(t)){if(t.length>1)return nr(t,i);if(t.length===0)return 1;r=t[0]}else r=t;return tr(r.mode,r.getLength(),i)};I.getEncodedBits=function(t){if(!Rt.isValid(t)||t<7)throw new Error("Invalid QR Code version");let n=t<<12;for(;ft.getBCHDigit(n)-ke>=0;)n^=Ue<<ft.getBCHDigit(n)-ke;return t<<12|n}});var _e=p(ve=>{var kt=$(),qe=1335,rr=21522,Fe=kt.getBCHDigit(qe);ve.getEncodedBits=function(t,n){let r=t.bit<<3|n,i=r<<10;for(;kt.getBCHDigit(i)-Fe>=0;)i^=qe<<kt.getBCHDigit(i)-Fe;return(r<<10|i)^rr}});var Ge=p((qi,ze)=>{var ir=M();function D(e){this.mode=ir.NUMERIC,this.data=e.toString()}D.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};D.prototype.getLength=function(){return this.data.length};D.prototype.getBitsLength=function(){return D.getBitsLength(this.data.length)};D.prototype.write=function(t){let n,r,i;for(n=0;n+3<=this.data.length;n+=3)r=this.data.substr(n,3),i=parseInt(r,10),t.put(i,10);let o=this.data.length-n;o>0&&(r=this.data.substr(n),i=parseInt(r,10),t.put(i,o*3+1))};ze.exports=D});var Qe=p((vi,He)=>{var or=M(),Ut=["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 F(e){this.mode=or.ALPHANUMERIC,this.data=e}F.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};F.prototype.getLength=function(){return this.data.length};F.prototype.getBitsLength=function(){return F.getBitsLength(this.data.length)};F.prototype.write=function(t){let n;for(n=0;n+2<=this.data.length;n+=2){let r=Ut.indexOf(this.data[n])*45;r+=Ut.indexOf(this.data[n+1]),t.put(r,11)}this.data.length%2&&t.put(Ut.indexOf(this.data[n]),6)};He.exports=F});var Ke=p((_i,Ve)=>{var sr=M();function q(e){this.mode=sr.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}q.getBitsLength=function(t){return t*8};q.prototype.getLength=function(){return this.data.length};q.prototype.getBitsLength=function(){return q.getBitsLength(this.data.length)};q.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)};Ve.exports=q});var Ye=p((zi,Je)=>{var ar=M(),ur=$();function v(e){this.mode=ar.KANJI,this.data=e}v.getBitsLength=function(t){return t*13};v.prototype.getLength=function(){return this.data.length};v.prototype.getBitsLength=function(){return v.getBitsLength(this.data.length)};v.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=ur.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)}};Je.exports=v});var je=p((Gi,Ot)=>{"use strict";var j={single_source_shortest_paths:function(e,t,n){var r={},i={};i[t]=0;var o=j.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=j.single_source_shortest_paths(e,t,n);return j.extract_shortest_path_from_predecessor_list(r,n)},PriorityQueue:{make:function(e){var t=j.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 Ot<"u"&&(Ot.exports=j)});var on=p(_=>{var d=M(),Xe=Ge(),tn=Qe(),en=Ke(),nn=Ye(),Z=Nt(),ht=$(),cr=je();function Ze(e){return unescape(encodeURIComponent(e)).length}function W(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 rn(e){let t=W(Z.NUMERIC,d.NUMERIC,e),n=W(Z.ALPHANUMERIC,d.ALPHANUMERIC,e),r,i;return ht.isKanjiModeEnabled()?(r=W(Z.BYTE,d.BYTE,e),i=W(Z.KANJI,d.KANJI,e)):(r=W(Z.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 Dt(e,t){switch(t){case d.NUMERIC:return Xe.getBitsLength(e);case d.ALPHANUMERIC:return tn.getBitsLength(e);case d.KANJI:return nn.getBitsLength(e);case d.BYTE:return en.getBitsLength(e)}}function lr(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 fr(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:Ze(r.data)}]);break;case d.BYTE:t.push([{data:r.data,mode:d.BYTE,length:Ze(r.data)}])}}return t}function hr(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]=Dt(n[l].lastCount+c.length,c.mode)-Dt(n[l].lastCount,c.mode),n[l].lastCount+=c.length):(n[l]&&(n[l].lastCount=c.length),r[l][f]=Dt(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 We(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&&!ht.isKanjiModeEnabled()&&(n=d.BYTE),n){case d.NUMERIC:return new Xe(e);case d.ALPHANUMERIC:return new tn(e);case d.KANJI:return new nn(e);case d.BYTE:return new en(e)}}_.fromArray=function(t){return t.reduce(function(n,r){return typeof r=="string"?n.push(We(r,null)):r.data&&n.push(We(r.data,r.mode)),n},[])};_.fromString=function(t,n){let r=rn(t,ht.isKanjiModeEnabled()),i=fr(r),o=hr(i,n),s=cr.find_path(o.map,"start","end"),a=[];for(let u=1;u<s.length-1;u++)a.push(o.table[s[u]].node);return _.fromArray(lr(a))};_.rawSplit=function(t){return _.fromArray(rn(t,ht.isKanjiModeEnabled()))}});var an=p(sn=>{var gt=$(),Ft=ot(),dr=be(),gr=xe(),pr=Ee(),mr=Ce(),_t=$e(),zt=Mt(),wr=Pe(),dt=De(),br=_e(),yr=M(),qt=on();function xr(e,t){let n=e.size,r=mr.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 Er(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 Br(e,t){let n=pr.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 Ar(e,t){let n=e.size,r=dt.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 vt(e,t,n){let r=e.size,i=br.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 Cr(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 $r(e,t,n){let r=new dr;n.forEach(function(u){r.put(u.mode.bit,4),r.put(u.getLength(),yr.getCharCountIndicator(u.mode,e)),u.write(r)});let i=gt.getSymbolTotalCodewords(e),o=zt.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 Tr(r,e,t)}function Tr(e,t,n){let r=gt.getSymbolTotalCodewords(t),i=zt.getTotalCodewordsCount(t,n),o=r-i,s=zt.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 wr(l),w=0,y=new Array(s),fe=new Array(s),Bt=0,In=new Uint8Array(e.buffer);for(let O=0;O<s;O++){let Ct=O<u?f:g;y[O]=In.slice(w,w+Ct),fe[O]=h.encode(y[O]),w+=Ct,Bt=Math.max(Bt,Ct)}let At=new Uint8Array(r),he=0,B,A;for(B=0;B<Bt;B++)for(A=0;A<s;A++)B<y[A].length&&(At[he++]=y[A][B]);for(B=0;B<l;B++)for(A=0;A<s;A++)At[he++]=fe[A][B];return At}function Mr(e,t,n,r){let i;if(Array.isArray(e))i=qt.fromArray(e);else if(typeof e=="string"){let c=t;if(!c){let f=qt.rawSplit(e);c=dt.getBestVersionForData(f,n)}i=qt.fromString(e,c||40)}else throw new Error("Invalid data");let o=dt.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
5
  The chosen QR Code version cannot contain this amount of data.
6
6
  Minimum version required to store current data is: `+o+`.
7
- `);let s=Cr(t,n,i),a=dt.getSymbolSize(t),u=new hr(a);return br(u,t),yr(u),xr(u,t),qt(u,n,0),t>=7&&Er(u,t),Ar(u,s),isNaN(r)&&(r=vt.getBestMask(u,qt.bind(null,u,n))),vt.applyMask(r,u),qt(u,n,r),{modules:u,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}on.create=function(t,n){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Ft.M,i,o;return typeof n<"u"&&(r=Ft.from(n.errorCorrectionLevel,Ft.M),i=ht.from(n.version),o=vt.from(n.maskPattern),n.toSJISFunc&&dt.setToSJISFunction(n.toSJISFunc)),Br(t,i,r,o)}});var zt=p(I=>{function an(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("")}}I.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:an(t.color.dark||"#000000ff"),light:an(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}};I.getScale=function(t,n){return n.width&&n.width>=t+n.margin*2?n.width/(t+n.margin*2):n.scale};I.getImageWidth=function(t,n){let r=I.getScale(t,n);return Math.floor((t+n.margin*2)*r)};I.qrToImageData=function(t,n,r){let i=n.modules.size,o=n.modules.data,s=I.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 un=p(gt=>{var Gt=zt();function Tr(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 Mr(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}gt.render=function(t,n,r){let i=r,o=n;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),n||(o=Mr()),i=Gt.getOptions(i);let s=Gt.getImageWidth(t.modules.size,i),a=o.getContext("2d"),u=a.createImageData(s,s);return Gt.qrToImageData(u.data,t,i),Tr(a,o,s),a.putImageData(u,0,0),o};gt.renderToDataURL=function(t,n,r){let i=r;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),i||(i={});let o=gt.render(t,n,i),s=i.type||"image/png",a=i.rendererOpts||{};return o.toDataURL(s,a.quality)}});var fn=p(ln=>{var Lr=zt();function cn(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function Ht(e,t,n){let r=e+t;return typeof n<"u"&&(r+=" "+n),r}function Sr(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?Ht("M",u+n,.5+c+n):Ht("m",i,0),i=0,o=!1),u+1<t&&e[a+1]||(r+=Ht("h",s),s=0)):i++}return r}ln.render=function(t,n,r){let i=Lr.getOptions(n),o=t.modules.size,s=t.modules.data,a=o+i.margin*2,u=i.color.light.a?"<path "+cn(i.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",c="<path "+cn(i.color.dark,"stroke")+' d="'+Sr(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 dn=p(Y=>{var Pr=ge(),Qt=sn(),hn=un(),Nr=fn();function Vt(e,t,n,r,i){let o=[].slice.call(arguments,1),s=o.length,a=typeof o[s-1]=="function";if(!a&&!Pr())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=Qt.create(n,r);u(e(f,t,r))}catch(f){c(f)}})}try{let u=Qt.create(n,r);i(null,e(u,t,r))}catch(u){i(u)}}Y.create=Qt.create;Y.toCanvas=Vt.bind(null,hn.render);Y.toDataURL=Vt.bind(null,hn.renderToDataURL);Y.toString=Vt.bind(null,function(e,t,n){return Nr.render(e,n)})});var gn=On(dn());function j(e,t){return{width:e,height:t,bits:new Uint8Array(Math.ceil(e/8)*t)}}function W(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 Kt(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 Ji(e,t,n,r=128){let i=j(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&&W(i,s,o,!0)}return i}function Ir(e,t,n,r){for(let i=0;i<t.height;i++)for(let o=0;o<t.width;o++)Kt(t,o,i)&&W(e,n+o,r+i,!0)}function Yi(e,t,n="center"){if(e.width===t)return e;let r=j(t,e.height),i=n==="left"?0:n==="right"?t-e.width:Math.floor((t-e.width)/2);return Ir(r,e,i,0),r}function v(e,t={}){let n=gn.default.create(e,{errorCorrectionLevel:t.correction??"M"}),r=n.modules.size,i=Math.max(1,Math.min(16,Math.floor(t.size??6))),o=j(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++)W(o,a*i+c,s*i+u,!0);return o}var Rr={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},pt=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=Rr[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"?kr(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(v(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=Ur(t,r),o=n.wrap!==!1,s=t.map((u,c)=>o?Dr(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+=Fr(s[g][u]??"",i[g],f.align??"LEFT")}),this.text(c.replace(/\s+$/,""))}return this}};function kr(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 Ur(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 Dr(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 Fr(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 Or=["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"],qr=104,vr=105,_r=100,zr=99,Gr=106;function Hr(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?vr:zr),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?qr:_r),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,Gr);let s=[];for(let a of t)for(let u of Or[a])s.push(Number(u));return s}var pn=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],Qr=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],mn=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],Vr=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function Jt(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 Yt(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 wn(e){let t=e.replace(/\D/g,"");if(t.length===12&&(t+=Jt(t)),t.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=Vr[Number(t[0])],r="101";for(let i=1;i<=6;i++)r+=(n[i-1]==="L"?pn:Qr)[Number(t[i])];r+="01010";for(let i=7;i<=12;i++)r+=mn[Number(t[i])];return r+="101",Yt(r)}function Kr(e){let t=e.replace(/\D/g,"");if(t.length===11&&(t+=Jt(t)),t.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return wn("0"+t)}function Jr(e){let t=e.replace(/\D/g,"");if(t.length===7&&(t+=Jt(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+=pn[Number(t[r])];n+="01010";for(let r=4;r<8;r++)n+=mn[Number(t[r])];return n+="101",Yt(n)}var Yr={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 jr(e){let t=`*${e.toUpperCase()}*`,n="";for(let r of t){let i=Yr[r];if(!i)throw new Error(`retail-print-kit: CODE39 cannot encode "${r}"`);n+=i+"0"}return Yt(n.slice(0,-1))}function Wr(e,t){switch(e){case"CODE128":return Hr(t);case"EAN13":return wn(t);case"UPC_A":return Kr(t);case"EAN8":return Jr(t);case"CODE39":return jr(t);default:throw new Error(`retail-print-kit: bitmap rendering of ${e} is not implemented`)}}function mt(e,t,n=2,r=80){let i=Wr(e,t),o=10*n,s=i.reduce((f,g)=>f+g,0)*n+o*2,a=j(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++)W(a,u+g,l,!0);u+=f*n,c=!c}return a}var wt={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}},bn={...wt,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},yn={...wt,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},xn={...wt,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},jt={...wt,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}},En={...jt,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var Wt={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}]},An={...Wt,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Cn={...Wt,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},$n={...Wt,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var Zr=Object.fromEntries([bn,yn,xn,jt,En,An,Cn,$n].map(e=>[e.id,e]));function ao(e){let t=Zr[e];if(!t)throw new Error(`retail-print-kit: unknown profile "${e}"`);return t}var Tn={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 Mn(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=Bn(t.current,n);return r!==void 0?r:Bn(t.root,n)}function Bn(e,t){let n=e;for(let r of t.split(".")){if(n==null)return;n=n[r]}return n}function _(e,t){let[n,...r]=e.split("|").map(o=>o.trim()),i=Mn(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=Tn[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=_(r,t);return i==null?"":String(i)})}function Z(e,t){let n=e.trim().startsWith("!"),r=_(n?e.trim().slice(1):e,t),i=Array.isArray(r)?r.length>0:!!r;return n?!i:i}var Zt={left:"lt",center:"ct",right:"rt"};function Xr(e,t,n){if(e.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(e.version)}`);let r=new pt(n);return X(e.blocks,{root:t,current:t},r),r.operations}function X(e,t,n){for(let r of e)ti(r,t,n)}function ti(e,t,n){switch(e.type){case"text":{e.align&&n.align(Zt[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=_(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(Zt[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(Zt[e.align]),n.barcode(E(e.value,t),e.format??"CODE128",{height:e.height,width:e.width,position:e.text===!1?"none":"below"}),e.align&&e.align!=="left"&&n.align("lt");break}case"each":{let r=_(e.items,t);if(!Array.isArray(r))break;r.forEach((i,o)=>X(e.blocks,{root:t.root,current:i,index:o},n));break}case"if":Z(e.when,t)?X(e.blocks,t,n):e.else&&X(e.else,t,n);break;default:throw new Error(`retail-print-kit: unknown template block "${e.type}"`)}}var ei=(()=>{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 ni(e){let t=4294967295;for(let n of e)t=ei[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function tt(e){return[e>>>24&255,e>>>16&255,e>>>8&255,e&255]}function bt(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 Xt(e,t){let n=bt([new Uint8Array([...e].map(r=>r.charCodeAt(0))),t]);return bt([new Uint8Array(tt(t.length)),n,new Uint8Array(tt(ni(n)))])}function ri(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 ii(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(tt(ri(e)))),bt(t)}function oi(e){try{let n=Dn("zlib").deflateSync(e);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return ii(e)}}function R(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++)Kt(e,s,o)||(n[o*(t+1)+1+(s>>3)]|=128>>(s&7));let r=new Uint8Array([...tt(e.width),...tt(e.height),1,0,0,0,0]),i=bt([new Uint8Array([137,80,78,71,13,10,26,10]),Xt("IHDR",r),Xt("IDAT",oi(n)),Xt("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i}var yt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function et(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+=yt[s>>18&63]+yt[s>>12&63],t+=n+1<e.length?yt[s>>6&63]:"=",t+=n+2<e.length?yt[s&63]:"="}return t}function te(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function si(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()}">${te(y)||"&nbsp;"}</div>`);a=""},f=(l,h,w)=>s.push(`<div class="l" style="text-align:${o.align}"><img alt="${te(w)}" width="${Math.round(h/t.dots*i)}" src="data:image/png;base64,${et(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=v(l.data,l.options);f(R(h),h.width,`QR ${l.data}`);break}case"barcode":{c(!1);let h=mt(l.type,l.data,l.options.width??2,l.options.height??80);f(R(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(R({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>${te(t.model)} preview</title><style>
7
+ `);let s=$r(t,n,i),a=gt.getSymbolSize(t),u=new gr(a);return xr(u,t),Er(u),Br(u,t),vt(u,n,0),t>=7&&Ar(u,t),Cr(u,s),isNaN(r)&&(r=_t.getBestMask(u,vt.bind(null,u,n))),_t.applyMask(r,u),vt(u,n,r),{modules:u,version:t,errorCorrectionLevel:n,maskPattern:r,segments:i}}sn.create=function(t,n){if(typeof t>"u"||t==="")throw new Error("No input text");let r=Ft.M,i,o;return typeof n<"u"&&(r=Ft.from(n.errorCorrectionLevel,Ft.M),i=dt.from(n.version),o=_t.from(n.maskPattern),n.toSJISFunc&&gt.setToSJISFunction(n.toSJISFunc)),Mr(t,i,r,o)}});var Gt=p(R=>{function un(e){if(typeof e=="number"&&(e=e.toString()),typeof e!="string")throw new Error("Color should be defined as hex string");let t=e.slice().replace("#","").split("");if(t.length<3||t.length===5||t.length>8)throw new Error("Invalid hex color: "+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(r){return[r,r]}))),t.length===6&&t.push("F","F");let n=parseInt(t.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:"#"+t.slice(0,6).join("")}}R.getOptions=function(t){t||(t={}),t.color||(t.color={});let n=typeof t.margin>"u"||t.margin===null||t.margin<0?4:t.margin,r=t.width&&t.width>=21?t.width:void 0,i=t.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:un(t.color.dark||"#000000ff"),light:un(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}};R.getScale=function(t,n){return n.width&&n.width>=t+n.margin*2?n.width/(t+n.margin*2):n.scale};R.getImageWidth=function(t,n){let r=R.getScale(t,n);return Math.floor((t+n.margin*2)*r)};R.qrToImageData=function(t,n,r){let i=n.modules.size,o=n.modules.data,s=R.getScale(i,r),a=Math.floor((i+r.margin*2)*s),u=r.margin*s,c=[r.color.light,r.color.dark];for(let f=0;f<a;f++)for(let g=0;g<a;g++){let l=(f*a+g)*4,h=r.color.light;if(f>=u&&g>=u&&f<a-u&&g<a-u){let w=Math.floor((f-u)/s),y=Math.floor((g-u)/s);h=c[o[w*i+y]?1:0]}t[l++]=h.r,t[l++]=h.g,t[l++]=h.b,t[l]=h.a}}});var cn=p(pt=>{var Ht=Gt();function Lr(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 Sr(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}pt.render=function(t,n,r){let i=r,o=n;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),n||(o=Sr()),i=Ht.getOptions(i);let s=Ht.getImageWidth(t.modules.size,i),a=o.getContext("2d"),u=a.createImageData(s,s);return Ht.qrToImageData(u.data,t,i),Lr(a,o,s),a.putImageData(u,0,0),o};pt.renderToDataURL=function(t,n,r){let i=r;typeof i>"u"&&(!n||!n.getContext)&&(i=n,n=void 0),i||(i={});let o=pt.render(t,n,i),s=i.type||"image/png",a=i.rendererOpts||{};return o.toDataURL(s,a.quality)}});var hn=p(fn=>{var Pr=Gt();function ln(e,t){let n=e.a/255,r=t+'="'+e.hex+'"';return n<1?r+" "+t+'-opacity="'+n.toFixed(2).slice(1)+'"':r}function Qt(e,t,n){let r=e+t;return typeof n<"u"&&(r+=" "+n),r}function Nr(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?Qt("M",u+n,.5+c+n):Qt("m",i,0),i=0,o=!1),u+1<t&&e[a+1]||(r+=Qt("h",s),s=0)):i++}return r}fn.render=function(t,n,r){let i=Pr.getOptions(n),o=t.modules.size,s=t.modules.data,a=o+i.margin*2,u=i.color.light.a?"<path "+ln(i.color.light,"fill")+' d="M0 0h'+a+"v"+a+'H0z"/>':"",c="<path "+ln(i.color.dark,"stroke")+' d="'+Nr(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 gn=p(X=>{var Ir=pe(),Vt=an(),dn=cn(),Rr=hn();function Kt(e,t,n,r,i){let o=[].slice.call(arguments,1),s=o.length,a=typeof o[s-1]=="function";if(!a&&!Ir())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=Vt.create(n,r);u(e(f,t,r))}catch(f){c(f)}})}try{let u=Vt.create(n,r);i(null,e(u,t,r))}catch(u){i(u)}}X.create=Vt.create;X.toCanvas=Kt.bind(null,dn.render);X.toDataURL=Kt.bind(null,dn.renderToDataURL);X.toString=Kt.bind(null,function(e,t,n){return Rr.render(e,n)})});var pn=vn(gn());var S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function k(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 Jt(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 z(e,t){return{width:e,height:t,bits:new Uint8Array(Math.ceil(e/8)*t)}}function G(e,t,n,r){if(t<0||n<0||t>=e.width||n>=e.height)return;let i=n*Math.ceil(e.width/8)+(t>>3),o=128>>(t&7);r?e.bits[i]|=o:e.bits[i]&=~o}function Yt(e,t,n){return t<0||n<0||t>=e.width||n>=e.height?!1:(e.bits[n*Math.ceil(e.width/8)+(t>>3)]&128>>(t&7))!==0}function Wi(e,t,n,r=128){let i=z(t,n);for(let o=0;o<n;o++)for(let s=0;s<t;s++){let a=(o*t+s)*4,u=e[a+3]/255;(.299*e[a]+.587*e[a+1]+.114*e[a+2])*u+255*(1-u)<r&&G(i,s,o,!0)}return i}function kr(e,t,n,r){for(let i=0;i<t.height;i++)for(let o=0;o<t.width;o++)Yt(t,o,i)&&G(e,n+o,r+i,!0)}function Xi(e,t,n="center"){if(e.width===t)return e;let r=z(t,e.height),i=n==="left"?0:n==="right"?t-e.width:Math.floor((t-e.width)/2);return kr(r,e,i,0),r}function H(e,t={}){let n=pn.default.create(e,{errorCorrectionLevel:t.correction??"M"}),r=n.modules.size,i=Math.max(1,Math.min(16,Math.floor(t.size??6))),o=z(r*i,r*i);for(let s=0;s<r;s++)for(let a=0;a<r;a++)if(n.modules.get(s,a))for(let u=0;u<i;u++)for(let c=0;c<i;c++)G(o,a*i+c,s*i+u,!0);return o}function to(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=z(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&&G(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 eo(e){return{width:e.width,height:e.height,data:k(e.bits)}}function mn(e){let t=Jt(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 Ur={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},mt=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=Ur[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"?Or(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(H(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=Dr(t,r),o=n.wrap!==!1,s=t.map((u,c)=>o?Fr(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+=qr(s[g][u]??"",i[g],f.align??"LEFT")}),this.text(c.replace(/\s+$/,""))}return this}};function Or(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 Dr(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 Fr(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 qr(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 vr=["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"],_r=104,zr=105,Gr=100,Hr=99,Qr=106;function Vr(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?zr:Hr),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?_r:Gr),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,Qr);let s=[];for(let a of t)for(let u of vr[a])s.push(Number(u));return s}var wn=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],Kr=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],bn=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],Jr=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function jt(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 Zt(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 yn(e){let t=e.replace(/\D/g,"");if(t.length===12&&(t+=jt(t)),t.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=Jr[Number(t[0])],r="101";for(let i=1;i<=6;i++)r+=(n[i-1]==="L"?wn:Kr)[Number(t[i])];r+="01010";for(let i=7;i<=12;i++)r+=bn[Number(t[i])];return r+="101",Zt(r)}function Yr(e){let t=e.replace(/\D/g,"");if(t.length===11&&(t+=jt(t)),t.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return yn("0"+t)}function jr(e){let t=e.replace(/\D/g,"");if(t.length===7&&(t+=jt(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+=wn[Number(t[r])];n+="01010";for(let r=4;r<8;r++)n+=bn[Number(t[r])];return n+="101",Zt(n)}var Zr={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 Wr(e){let t=`*${e.toUpperCase()}*`,n="";for(let r of t){let i=Zr[r];if(!i)throw new Error(`retail-print-kit: CODE39 cannot encode "${r}"`);n+=i+"0"}return Zt(n.slice(0,-1))}function Xr(e,t){switch(e){case"CODE128":return Vr(t);case"EAN13":return yn(t);case"UPC_A":return Yr(t);case"EAN8":return jr(t);case"CODE39":return Wr(t);default:throw new Error(`retail-print-kit: bitmap rendering of ${e} is not implemented`)}}function wt(e,t,n=2,r=80){let i=Xr(e,t),o=10*n,s=i.reduce((f,g)=>f+g,0)*n+o*2,a=z(s,r),u=o,c=!0;for(let f of i){if(c)for(let g=0;g<f*n;g++)for(let l=0;l<r;l++)G(a,u+g,l,!0);u+=f*n,c=!c}return a}var 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}},xn={...bt,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},En={...bt,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},Bn={...bt,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},Wt={...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}},An={...Wt,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var Xt={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}]},Cn={...Xt,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},$n={...Xt,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Tn={...Xt,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var ti=Object.fromEntries([xn,En,Bn,Wt,An,Cn,$n,Tn].map(e=>[e.id,e]));function go(e){let t=ti[e];if(!t)throw new Error(`retail-print-kit: unknown profile "${e}"`);return t}var Ln={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 Sn(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=Mn(t.current,n);return r!==void 0?r:Mn(t.root,n)}function Mn(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=Sn(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=Ln[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 tt(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 yt={left:"lt",center:"ct",right:"rt"};function ei(e,t,n){if(e.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(e.version)}`);let r=new mt(n);return et(e.blocks,{root:t,current:t},r),r.operations}function et(e,t,n){for(let r of e)ni(r,t,n)}function ni(e,t,n){switch(e.type){case"text":{e.align&&n.align(yt[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(yt[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(yt[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(yt[e.align]),n.image(mn(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)=>et(e.blocks,{root:t.root,current:i,index:o},n));break}case"if":tt(e.when,t)?et(e.blocks,t,n):e.else&&et(e.else,t,n);break;default:throw new Error(`retail-print-kit: unknown template block "${e.type}"`)}}var ri=(()=>{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 ii(e){let t=4294967295;for(let n of e)t=ri[(t^n)&255]^t>>>8;return(t^4294967295)>>>0}function nt(e){return[e>>>24&255,e>>>16&255,e>>>8&255,e&255]}function xt(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 te(e,t){let n=xt([new Uint8Array([...e].map(r=>r.charCodeAt(0))),t]);return xt([new Uint8Array(nt(t.length)),n,new Uint8Array(nt(ii(n)))])}function oi(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 si(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(nt(oi(e)))),xt(t)}function ai(e){try{let n=Fn("zlib").deflateSync(e);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return si(e)}}function U(e){let t=Math.ceil(e.width/8),n=new Uint8Array((t+1)*e.height);for(let o=0;o<e.height;o++)for(let s=0;s<e.width;s++)Yt(e,s,o)||(n[o*(t+1)+1+(s>>3)]|=128>>(s&7));let r=new Uint8Array([...nt(e.width),...nt(e.height),1,0,0,0,0]),i=xt([new Uint8Array([137,80,78,71,13,10,26,10]),te("IHDR",r),te("IDAT",ai(n)),te("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i}function ee(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function ui(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()}">${ee(y)||"&nbsp;"}</div>`);a=""},f=(l,h,w)=>s.push(`<div class="l" style="text-align:${o.align}"><img alt="${ee(w)}" width="${Math.round(h/t.dots*i)}" src="data:image/png;base64,${k(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=H(l.data,l.options);f(U(h),h.width,`QR ${l.data}`);break}case"barcode":{c(!1);let h=wt(l.type,l.data,l.options.width??2,l.options.height??80);f(U(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(U({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>${ee(t.model)} preview</title><style>
12
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
13
  .paper{background:#fff;color:#000;padding:12px ${r}px;margin:0 auto;box-shadow:0 2px 8px rgba(0,0,0,.4);box-sizing:content-box}
14
14
  .l{white-space:pre;overflow:hidden;min-height:1.25em}
15
15
  .cut{border-top:2px dashed #999;margin:6px -${r}px}
16
16
  .note{color:#999;font-size:.7em;text-align:center}
17
17
  img{image-rendering:pixelated;vertical-align:top}
18
- </style></head><body>${g}</body></html>`}var ee={0:"N",90:"R",180:"I",270:"B"},ai={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function ne(e){return e.replace(/[\^~\\]/g,t=>`\\${t}`)}function ui(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 ci(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${ee[e.rotation??0]},${Math.round(e.height)},${n}^FD${ne(e.text)}^FS`}case"barcode":{let n=ai[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}${ee[e.rotation??0]},${Math.round(e.height)}${i}^FD${ne(e.data)}^FS`}case"qr":{let n=e.correction??"M";return`${t}^BQ${ee[e.rotation??0]},2,${e.module??4}^FD${n}A,${ne(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,${ui(e.bitmap)}^FS`}}function re(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(ci(n));return t.push(`^PQ${e.copies},0,1,Y`,"^XZ"),t.join(`
18
+ </style></head><body>${g}</body></html>`}var ne={0:"N",90:"R",180:"I",270:"B"},ci={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function re(e){return e.replace(/[\^~\\]/g,t=>`\\${t}`)}function li(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 fi(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${ne[e.rotation??0]},${Math.round(e.height)},${n}^FD${re(e.text)}^FS`}case"barcode":{let n=ci[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}${ne[e.rotation??0]},${Math.round(e.height)}${i}^FD${re(e.data)}^FS`}case"qr":{let n=e.correction??"M";return`${t}^BQ${ne[e.rotation??0]},2,${e.module??4}^FD${n}A,${re(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,${li(e.bitmap)}^FS`}}function ie(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(fi(n));return t.push(`^PQ${e.copies},0,1,Y`,"^XZ"),t.join(`
19
19
  `)+`
20
- `}function xt(e,t){return Math.round(e/25.4*t)}function nt(e,t){return e/t*25.4}var li={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function ie(e){return`"${e.replace(/"/g,'\\["]')}"`}function Ln(e,t){return nt(e,t).toFixed(2)}function fi(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 hi(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},${ie(e.text)}`;return e.invert?`${a}
21
- REVERSE ${n},${r},${Math.round(s*e.text.length*.6)},${o}`:a}case"barcode":{let o=li[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},${ie(e.data)}`}case"qr":return`QRCODE ${n},${r},${e.correction??"M"},${e.module??4},A,${i(e.rotation)},${ie(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=fi(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 oe(e){let t=[`SIZE ${Ln(e.width,e.dpi)} mm,${Ln(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(hi(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 se=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],di={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function gi(e){let t=se[0][0],n=se[0][1];for(let[i,o]of se)o<=e&&(t=i,n=o);let r=Math.max(1,Math.min(9,Math.floor(e/n)));return{font:t,mul:r}}function pi(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}=gi(e.height);return`A${i},${t},${n},${o},${o},${r/90},0${e.invert?"R":"E"},${e.text}`}case"barcode":{let i=di[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 ae(e){let t=[`^Q${nt(e.height,e.dpi).toFixed(2)},${e.gap.toFixed(0)}`,`^W${nt(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(pi(n));return t.push("E"),t.join(`
20
+ `}function Et(e,t){return Math.round(e/25.4*t)}function rt(e,t){return e/t*25.4}var hi={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function oe(e){return`"${e.replace(/"/g,'\\["]')}"`}function Pn(e,t){return rt(e,t).toFixed(2)}function di(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 gi(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},${oe(e.text)}`;return e.invert?`${a}
21
+ REVERSE ${n},${r},${Math.round(s*e.text.length*.6)},${o}`:a}case"barcode":{let o=hi[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},${oe(e.data)}`}case"qr":return`QRCODE ${n},${r},${e.correction??"M"},${e.module??4},A,${i(e.rotation)},${oe(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=di(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 se(e){let t=[`SIZE ${Pn(e.width,e.dpi)} mm,${Pn(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(gi(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 ae=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],pi={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function mi(e){let t=ae[0][0],n=ae[0][1];for(let[i,o]of ae)o<=e&&(t=i,n=o);let r=Math.max(1,Math.min(9,Math.floor(e/n)));return{font:t,mul:r}}function wi(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}=mi(e.height);return`A${i},${t},${n},${o},${o},${r/90},0${e.invert?"R":"E"},${e.text}`}case"barcode":{let i=pi[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 ue(e){let t=[`^Q${rt(e.height,e.dpi).toFixed(2)},${e.gap.toFixed(0)}`,`^W${rt(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(wi(n));return t.push("E"),t.join(`
24
24
  `)+`
25
- `}var rt=class{constructor(t){let n=t.dpi??203;this.label={width:xt(t.widthMm,n),height:xt(t.heightMm,n),dpi:n,gap:t.gapMm??3,copies:1,ops:[]}}mm(t){return xt(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 Sn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ue(e){return e.rotation?` transform="rotate(${e.rotation} ${e.x} ${e.y})"`:""}function ce(e){return`data:image/png;base64,${et(R(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"}"${ue(e)}>${Sn(e.text)}</text>`}case"barcode":{let t=mt(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">${Sn(e.data)}</text>`;return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${ce(t)}" style="image-rendering:pixelated"${ue(e)}/>${n}`}case"qr":{let t=v(e.data,{size:e.module??4,correction:e.correction});return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${ce(t)}" style="image-rendering:pixelated"${ue(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="${ce(e.bitmap)}" style="image-rendering:pixelated"/>`}}function wi(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 bi(e,t){if(e.version!==1||e.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new rt({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&&!Z(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 Xo(e,t){switch(t){case"zpl":return new TextEncoder().encode(re(e));case"ezpl":return new TextEncoder().encode(ae(e));case"tspl":return oe(e)}}export{rt as LabelBuilder,pt as OpBuilder,mt as barcodeBitmap,R as bitmapToPng,Ir as blit,Hr as code128,jr as code39,nt as dotsToMm,wn as ean13,Jr as ean8,j as emptyBitmap,ae as encodeEzpl,Xo as encodeLabel,oe as encodeTspl,re as encodeZpl,xn as epsonTmM30,yn as epsonTmT20,bn as epsonTmT88,_ as evaluate,Tn as filters,Yi as fitWidth,Ji as fromRgba,jt as genericEscPos,En as genericEscPos58,Kt as getPixel,E as interpolate,wi as labelToSvg,Mn as lookup,xt as mmToDots,si as opsToHtml,kr as parseStyle,Wr as pattern,ao as profileById,Zr as profiles,v as qrBitmap,Xr as render,X as renderBlocks,bi as renderLabel,W as setPixel,Cn as starMcPrint3,$n as starTsp100,An as starTsp650,et as toBase64,Z as truthy,Kr as upcA};
25
+ `}var it=class{constructor(t){let n=t.dpi??203;this.label={width:Et(t.widthMm,n),height:Et(t.heightMm,n),dpi:n,gap:t.gapMm??3,copies:1,ops:[]}}mm(t){return Et(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 Nn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function ce(e){return e.rotation?` transform="rotate(${e.rotation} ${e.x} ${e.y})"`:""}function le(e){return`data:image/png;base64,${k(U(e))}`}function bi(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"}"${ce(e)}>${Nn(e.text)}</text>`}case"barcode":{let t=wt(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">${Nn(e.data)}</text>`;return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${le(t)}" style="image-rendering:pixelated"${ce(e)}/>${n}`}case"qr":{let t=H(e.data,{size:e.module??4,correction:e.correction});return`<image x="${e.x}" y="${e.y}" width="${t.width}" height="${t.height}" href="${le(t)}" style="image-rendering:pixelated"${ce(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="${le(e.bitmap)}" style="image-rendering:pixelated"/>`}}function yi(e){let t=e.ops.map(bi).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 xi(e,t){if(e.version!==1||e.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new it({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&&!tt(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 os(e,t){switch(t){case"zpl":return new TextEncoder().encode(ie(e));case"ezpl":return new TextEncoder().encode(ue(e));case"tspl":return se(e)}}export{it as LabelBuilder,mt as OpBuilder,wt as barcodeBitmap,U as bitmapToPng,kr as blit,Vr as code128,Wr as code39,mn as deserializeBitmap,to as ditherRgba,rt as dotsToMm,yn as ean13,jr as ean8,z as emptyBitmap,ue as encodeEzpl,os as encodeLabel,se as encodeTspl,ie as encodeZpl,Bn as epsonTmM30,En as epsonTmT20,xn as epsonTmT88,Q as evaluate,Ln as filters,Xi as fitWidth,Jt as fromBase64,Wi as fromRgba,Wt as genericEscPos,An as genericEscPos58,Yt as getPixel,E as interpolate,yi as labelToSvg,Sn as lookup,Et as mmToDots,ui as opsToHtml,Or as parseStyle,Xr as pattern,go as profileById,ti as profiles,H as qrBitmap,ei as render,et as renderBlocks,xi as renderLabel,eo as serializeBitmap,G as setPixel,$n as starMcPrint3,Tn as starTsp100,Cn as starTsp650,k as toBase64,tt as truthy,Yr as upcA};
package/dist/browser.d.ts CHANGED
@@ -12,4 +12,4 @@ export { opsToHtml } from './preview/html';
12
12
  export type { HtmlPreviewOptions } from './preview/html';
13
13
  export { bitmapToPng } from './preview/png';
14
14
  export * from './label';
15
- export { toBase64 } from './util/base64';
15
+ export { toBase64, fromBase64 } from './util/base64';
package/dist/browser.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.toBase64 = exports.bitmapToPng = exports.opsToHtml = void 0;
17
+ exports.fromBase64 = exports.toBase64 = exports.bitmapToPng = exports.opsToHtml = void 0;
18
18
  /**
19
19
  * Browser entry: everything that needs no Node APIs and no printer. Receipt templates, HTML
20
20
  * preview, label templates, label encoders and the SVG label preview, for designers and web apps.
@@ -32,3 +32,4 @@ Object.defineProperty(exports, "bitmapToPng", { enumerable: true, get: function
32
32
  __exportStar(require("./label"), exports);
33
33
  var base64_1 = require("./util/base64");
34
34
  Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_1.toBase64; } });
35
+ Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_1.fromBase64; } });
@@ -16,3 +16,16 @@ export declare function blit(dst: Bitmap, src: Bitmap, x: number, y: number): vo
16
16
  export declare function fitWidth(src: Bitmap, width: number, align?: 'left' | 'center' | 'right'): Bitmap;
17
17
  /** QR code as a bitmap, each module `options.size` dots square (default 6, like Epson cell size). */
18
18
  export declare function qrBitmap(data: string, options?: QrOptions): Bitmap;
19
+ /**
20
+ * RGBA pixels to 1-bit with Floyd-Steinberg error diffusion. Use for photos and logos with
21
+ * gradients; `fromRgba` (plain threshold) is sharper for line art and text.
22
+ */
23
+ export declare function ditherRgba(data: Uint8ClampedArray | Uint8Array, width: number, height: number): Bitmap;
24
+ /** A bitmap as plain JSON (`{ width, height, data }`, bits in base64), for templates and storage. */
25
+ export interface SerializedBitmap {
26
+ width: number;
27
+ height: number;
28
+ data: string;
29
+ }
30
+ export declare function serializeBitmap(b: Bitmap): SerializedBitmap;
31
+ export declare function deserializeBitmap(s: SerializedBitmap): Bitmap;
@@ -10,7 +10,11 @@ exports.fromRgba = fromRgba;
10
10
  exports.blit = blit;
11
11
  exports.fitWidth = fitWidth;
12
12
  exports.qrBitmap = qrBitmap;
13
+ exports.ditherRgba = ditherRgba;
14
+ exports.serializeBitmap = serializeBitmap;
15
+ exports.deserializeBitmap = deserializeBitmap;
13
16
  const qrcode_1 = __importDefault(require("qrcode"));
17
+ const base64_1 = require("../util/base64");
14
18
  function emptyBitmap(width, height) {
15
19
  return { width, height, bits: new Uint8Array(Math.ceil(width / 8) * height) };
16
20
  }
@@ -78,3 +82,45 @@ function qrBitmap(data, options = {}) {
78
82
  }
79
83
  return b;
80
84
  }
85
+ /**
86
+ * RGBA pixels to 1-bit with Floyd-Steinberg error diffusion. Use for photos and logos with
87
+ * gradients; `fromRgba` (plain threshold) is sharper for line art and text.
88
+ */
89
+ function ditherRgba(data, width, height) {
90
+ const lum = new Float32Array(width * height);
91
+ for (let i = 0; i < width * height; i++) {
92
+ const a = data[i * 4 + 3] / 255;
93
+ lum[i] = (0.299 * data[i * 4] + 0.587 * data[i * 4 + 1] + 0.114 * data[i * 4 + 2]) * a + 255 * (1 - a);
94
+ }
95
+ const b = emptyBitmap(width, height);
96
+ for (let y = 0; y < height; y++) {
97
+ for (let x = 0; x < width; x++) {
98
+ const i = y * width + x;
99
+ const old = lum[i];
100
+ const black = old < 128;
101
+ if (black)
102
+ setPixel(b, x, y, true);
103
+ const err = old - (black ? 0 : 255);
104
+ if (x + 1 < width)
105
+ lum[i + 1] += (err * 7) / 16;
106
+ if (y + 1 < height) {
107
+ if (x > 0)
108
+ lum[i + width - 1] += (err * 3) / 16;
109
+ lum[i + width] += (err * 5) / 16;
110
+ if (x + 1 < width)
111
+ lum[i + width + 1] += err / 16;
112
+ }
113
+ }
114
+ }
115
+ return b;
116
+ }
117
+ function serializeBitmap(b) {
118
+ return { width: b.width, height: b.height, data: (0, base64_1.toBase64)(b.bits) };
119
+ }
120
+ function deserializeBitmap(s) {
121
+ const bits = (0, base64_1.fromBase64)(s.data);
122
+ const expected = Math.ceil(s.width / 8) * s.height;
123
+ if (bits.length !== expected)
124
+ throw new Error(`retail-print-kit: bitmap data is ${bits.length} bytes, expected ${expected}`);
125
+ return { width: s.width, height: s.height, bits };
126
+ }
@@ -0,0 +1,13 @@
1
+ import { Bitmap } from './bitmap';
2
+ export interface LoadImageOptions {
3
+ /** Target width in dots; the height keeps the aspect ratio. Defaults to the image's own width. */
4
+ width?: number;
5
+ /** Floyd-Steinberg dithering (photos, gradients). Default false: plain threshold. */
6
+ dither?: boolean;
7
+ threshold?: number;
8
+ }
9
+ /**
10
+ * Loads a PNG / JPEG / WebP / GIF file or buffer and converts it to a 1-bit bitmap, scaled to
11
+ * `width` dots. Node only; needs the optional `@napi-rs/canvas` (or `canvas`) package.
12
+ */
13
+ export declare function loadImage(source: string | Uint8Array, options?: LoadImageOptions): Promise<Bitmap>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadImage = loadImage;
4
+ const bitmap_1 = require("./bitmap");
5
+ /**
6
+ * Loads a PNG / JPEG / WebP / GIF file or buffer and converts it to a 1-bit bitmap, scaled to
7
+ * `width` dots. Node only; needs the optional `@napi-rs/canvas` (or `canvas`) package.
8
+ */
9
+ async function loadImage(source, options = {}) {
10
+ let mod = null;
11
+ for (const name of ['@napi-rs/canvas', 'canvas']) {
12
+ try {
13
+ mod = require(name);
14
+ break;
15
+ }
16
+ catch {
17
+ /* try the next */
18
+ }
19
+ }
20
+ if (!mod)
21
+ throw new Error('retail-print-kit: loadImage needs @napi-rs/canvas; run `npm install @napi-rs/canvas`');
22
+ const img = await mod.loadImage(source);
23
+ const width = Math.max(1, Math.round(options.width ?? img.width));
24
+ const height = Math.max(1, Math.round((img.height * width) / img.width));
25
+ const canvas = mod.createCanvas(width, height);
26
+ const ctx = canvas.getContext('2d');
27
+ ctx.fillStyle = '#fff';
28
+ ctx.fillRect(0, 0, width, height);
29
+ ctx.drawImage(img, 0, 0, width, height);
30
+ const data = ctx.getImageData(0, 0, width, height).data;
31
+ return options.dither ? (0, bitmap_1.ditherRgba)(data, width, height) : (0, bitmap_1.fromRgba)(data, width, height, options.threshold ?? 128);
32
+ }
package/dist/index.d.ts CHANGED
@@ -19,3 +19,8 @@ export * from './preview';
19
19
  export * from './core/identify';
20
20
  export * from './label';
21
21
  export { toBase64 } from './util/base64';
22
+ export { loadImage } from './core/image';
23
+ export type { LoadImageOptions } from './core/image';
24
+ export { discoverNetworkPrinters, localSubnets } from './transports/discover';
25
+ export type { DiscoverOptions, DiscoveredPrinter } from './transports/discover';
26
+ export { fromBase64 } from './util/base64';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.toBase64 = exports.encodeStarGraphic = exports.encodeStarLine = exports.loadCanvasFactory = exports.CanvasRasterizer = exports.NetTransport = exports.encodeEscPos = exports.encode = void 0;
17
+ exports.fromBase64 = exports.localSubnets = exports.discoverNetworkPrinters = exports.loadImage = exports.toBase64 = exports.encodeStarGraphic = exports.encodeStarLine = exports.loadCanvasFactory = exports.CanvasRasterizer = exports.NetTransport = exports.encodeEscPos = exports.encode = void 0;
18
18
  __exportStar(require("./core/ops"), exports);
19
19
  __exportStar(require("./core/printer"), exports);
20
20
  var encode_1 = require("./core/encode");
@@ -40,3 +40,10 @@ __exportStar(require("./core/identify"), exports);
40
40
  __exportStar(require("./label"), exports);
41
41
  var base64_1 = require("./util/base64");
42
42
  Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_1.toBase64; } });
43
+ var image_1 = require("./core/image");
44
+ Object.defineProperty(exports, "loadImage", { enumerable: true, get: function () { return image_1.loadImage; } });
45
+ var discover_1 = require("./transports/discover");
46
+ Object.defineProperty(exports, "discoverNetworkPrinters", { enumerable: true, get: function () { return discover_1.discoverNetworkPrinters; } });
47
+ Object.defineProperty(exports, "localSubnets", { enumerable: true, get: function () { return discover_1.localSubnets; } });
48
+ var base64_2 = require("./util/base64");
49
+ Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_2.fromBase64; } });
@@ -4,6 +4,7 @@ exports.render = render;
4
4
  exports.renderBlocks = renderBlocks;
5
5
  const builder_1 = require("../core/builder");
6
6
  const expr_1 = require("./expr");
7
+ const bitmap_1 = require("../core/bitmap");
7
8
  const ALIGN = { left: 'lt', center: 'ct', right: 'rt' };
8
9
  /** Renders a template with data into ops for the given profile. */
9
10
  function render(template, data, profile) {
@@ -91,6 +92,14 @@ function renderBlock(block, scope, b) {
91
92
  b.align('lt');
92
93
  break;
93
94
  }
95
+ case 'image': {
96
+ if (block.align)
97
+ b.align(ALIGN[block.align]);
98
+ b.image((0, bitmap_1.deserializeBitmap)(block));
99
+ if (block.align && block.align !== 'left')
100
+ b.align('lt');
101
+ break;
102
+ }
94
103
  case 'each': {
95
104
  const items = (0, expr_1.evaluate)(block.items, scope);
96
105
  if (!Array.isArray(items))
@@ -57,6 +57,12 @@ export type Block = {
57
57
  width?: number;
58
58
  align?: TAlign;
59
59
  text?: boolean;
60
+ } | {
61
+ type: 'image';
62
+ width: number;
63
+ height: number;
64
+ data: string;
65
+ align?: TAlign;
60
66
  } | {
61
67
  type: 'each';
62
68
  items: string;
@@ -0,0 +1,21 @@
1
+ import { Identity } from '../core/identify';
2
+ export interface DiscoverOptions {
3
+ /** TCP port to probe. Default 9100 (raw printing). */
4
+ port?: number;
5
+ /** Per-host connect timeout in milliseconds. Default 400. */
6
+ timeout?: number;
7
+ /** Simultaneous probes. Default 64. */
8
+ concurrency?: number;
9
+ /** Subnets as "192.168.1" prefixes; defaults to every private IPv4 /24 this machine is on. */
10
+ subnets?: string[];
11
+ /** Ask each printer found for its maker and model. Default false. */
12
+ identify?: boolean;
13
+ }
14
+ export interface DiscoveredPrinter {
15
+ host: string;
16
+ port: number;
17
+ identity?: Identity;
18
+ }
19
+ export declare function localSubnets(): string[];
20
+ /** Sweeps the local /24 networks for hosts that accept raw printing connections. */
21
+ export declare function discoverNetworkPrinters(options?: DiscoverOptions): Promise<DiscoveredPrinter[]>;