retail-print-kit 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +32 -3
- package/dist/browser/retail-print-kit.js +15 -20
- package/dist/browser/retail-print-kit.js.map +4 -4
- package/dist/browser/retail-print-kit.mjs +12 -17
- package/dist/core/bitmap.js +10 -4
- package/package.json +10 -6
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
-
|
|
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&>.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,"&").replace(/</g,"<").replace(/>/g,">")}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)||" "}</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"> </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>
|
|
1
|
+
var Kt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var H=function(t,e){let i=t,a=Y[e],s=null,o=0,u=null,l=[],b={},m=function(c,g){o=i*4+17,s=function(f){let d=new Array(f);for(let p=0;p<f;p+=1){d[p]=new Array(f);for(let x=0;x<f;x+=1)d[p][x]=null}return d}(o),h(0,0),h(o-7,0),h(0,o-7),M(),B(),_(c,g),i>=7&&k(c),u==null&&(u=Yt(i,a,l)),O(u,g)},h=function(c,g){for(let f=-1;f<=7;f+=1)if(!(c+f<=-1||o<=c+f))for(let d=-1;d<=7;d+=1)g+d<=-1||o<=g+d||(0<=f&&f<=6&&(d==0||d==6)||0<=d&&d<=6&&(f==0||f==6)||2<=f&&f<=4&&2<=d&&d<=4?s[c+f][g+d]=!0:s[c+f][g+d]=!1)},w=function(){let c=0,g=0;for(let f=0;f<8;f+=1){m(!0,f);let d=S.getLostPoint(b);(f==0||c>d)&&(c=d,g=f)}return g},B=function(){for(let c=8;c<o-8;c+=1)s[c][6]==null&&(s[c][6]=c%2==0);for(let c=8;c<o-8;c+=1)s[6][c]==null&&(s[6][c]=c%2==0)},M=function(){let c=S.getPatternPosition(i);for(let g=0;g<c.length;g+=1)for(let f=0;f<c.length;f+=1){let d=c[g],p=c[f];if(s[d][p]==null)for(let x=-2;x<=2;x+=1)for(let y=-2;y<=2;y+=1)x==-2||x==2||y==-2||y==2||x==0&&y==0?s[d+x][p+y]=!0:s[d+x][p+y]=!1}},k=function(c){let g=S.getBCHTypeNumber(i);for(let f=0;f<18;f+=1){let d=!c&&(g>>f&1)==1;s[Math.floor(f/3)][f%3+o-8-3]=d}for(let f=0;f<18;f+=1){let d=!c&&(g>>f&1)==1;s[f%3+o-8-3][Math.floor(f/3)]=d}},_=function(c,g){let f=a<<3|g,d=S.getBCHTypeInfo(f);for(let p=0;p<15;p+=1){let x=!c&&(d>>p&1)==1;p<6?s[p][8]=x:p<8?s[p+1][8]=x:s[o-15+p][8]=x}for(let p=0;p<15;p+=1){let x=!c&&(d>>p&1)==1;p<8?s[8][o-p-1]=x:p<9?s[8][15-p-1+1]=x:s[8][15-p-1]=x}s[o-8][8]=!c},O=function(c,g){let f=-1,d=o-1,p=7,x=0,y=S.getMaskFunction(g);for(let A=o-1;A>0;A-=2)for(A==6&&(A-=1);;){for(let E=0;E<2;E+=1)if(s[d][A-E]==null){let T=!1;x<c.length&&(T=(c[x]>>>p&1)==1),y(d,A-E)&&(T=!T),s[d][A-E]=T,p-=1,p==-1&&(x+=1,p=7)}if(d+=f,d<0||o<=d){d-=f,f=-f;break}}},zt=function(c,g){let f=0,d=0,p=0,x=new Array(g.length),y=new Array(g.length);for(let $=0;$<g.length;$+=1){let L=g[$].dataCount,P=g[$].totalCount-L;d=Math.max(d,L),p=Math.max(p,P),x[$]=new Array(L);for(let R=0;R<x[$].length;R+=1)x[$][R]=255&c.getBuffer()[R+f];f+=L;let st=S.getErrorCorrectPolynomial(P),Mt=Z(x[$],st.getLength()-1).mod(st);y[$]=new Array(st.getLength()-1);for(let R=0;R<y[$].length;R+=1){let Et=R+Mt.getLength()-y[$].length;y[$][R]=Et>=0?Mt.getAt(Et):0}}let A=0;for(let $=0;$<g.length;$+=1)A+=g[$].totalCount;let E=new Array(A),T=0;for(let $=0;$<d;$+=1)for(let L=0;L<g.length;L+=1)$<x[L].length&&(E[T]=x[L][$],T+=1);for(let $=0;$<p;$+=1)for(let L=0;L<g.length;L+=1)$<y[L].length&&(E[T]=y[L][$],T+=1);return E},Yt=function(c,g,f){let d=Lt.getRSBlocks(c,g),p=Tt();for(let y=0;y<f.length;y+=1){let A=f[y];p.put(A.getMode(),4),p.put(A.getLength(),S.getLengthInBits(A.getMode(),c)),A.write(p)}let x=0;for(let y=0;y<d.length;y+=1)x+=d[y].dataCount;if(p.getLengthInBits()>x*8)throw"code length overflow. ("+p.getLengthInBits()+">"+x*8+")";for(p.getLengthInBits()+4<=x*8&&p.put(0,4);p.getLengthInBits()%8!=0;)p.putBit(!1);for(;!(p.getLengthInBits()>=x*8||(p.put(236,8),p.getLengthInBits()>=x*8));)p.put(17,8);return zt(p,d)};b.addData=function(c,g){g=g||"Byte";let f=null;switch(g){case"Numeric":f=Wt(c);break;case"Alphanumeric":f=Xt(c);break;case"Byte":f=Jt(c);break;case"Kanji":f=Vt(c);break;default:throw"mode:"+g}l.push(f),u=null},b.isDark=function(c,g){if(c<0||o<=c||g<0||o<=g)throw c+","+g;return s[c][g]},b.getModuleCount=function(){return o},b.make=function(){if(i<1){let c=1;for(;c<40;c++){let g=Lt.getRSBlocks(c,a),f=Tt();for(let p=0;p<l.length;p++){let x=l[p];f.put(x.getMode(),4),f.put(x.getLength(),S.getLengthInBits(x.getMode(),c)),x.write(f)}let d=0;for(let p=0;p<g.length;p++)d+=g[p].dataCount;if(f.getLengthInBits()<=d*8)break}i=c}m(!1,w())},b.createTableTag=function(c,g){c=c||2,g=typeof g>"u"?c*4:g;let f="";f+='<table style="',f+=" border-width: 0px; border-style: none;",f+=" border-collapse: collapse;",f+=" padding: 0px; margin: "+g+"px;",f+='">',f+="<tbody>";for(let d=0;d<b.getModuleCount();d+=1){f+="<tr>";for(let p=0;p<b.getModuleCount();p+=1)f+='<td style="',f+=" border-width: 0px; border-style: none;",f+=" border-collapse: collapse;",f+=" padding: 0px; margin: 0px;",f+=" width: "+c+"px;",f+=" height: "+c+"px;",f+=" background-color: ",f+=b.isDark(d,p)?"#000000":"#ffffff",f+=";",f+='"/>';f+="</tr>"}return f+="</tbody>",f+="</table>",f},b.createSvgTag=function(c,g,f,d){let p={};typeof arguments[0]=="object"&&(p=arguments[0],c=p.cellSize,g=p.margin,f=p.alt,d=p.title),c=c||2,g=typeof g>"u"?c*4:g,f=typeof f=="string"?{text:f}:f||{},f.text=f.text||null,f.id=f.text?f.id||"qrcode-description":null,d=typeof d=="string"?{text:d}:d||{},d.text=d.text||null,d.id=d.text?d.id||"qrcode-title":null;let x=b.getModuleCount()*c+g*2,y,A,E,T,$="",L;for(L="l"+c+",0 0,"+c+" -"+c+",0 0,-"+c+"z ",$+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',$+=p.scalable?"":' width="'+x+'px" height="'+x+'px"',$+=' viewBox="0 0 '+x+" "+x+'" ',$+=' preserveAspectRatio="xMinYMin meet"',$+=d.text||f.text?' role="img" aria-labelledby="'+G([d.id,f.id].join(" ").trim())+'"':"",$+=">",$+=d.text?'<title id="'+G(d.id)+'">'+G(d.text)+"</title>":"",$+=f.text?'<description id="'+G(f.id)+'">'+G(f.text)+"</description>":"",$+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',$+='<path d="',E=0;E<b.getModuleCount();E+=1)for(T=E*c+g,y=0;y<b.getModuleCount();y+=1)b.isDark(E,y)&&(A=y*c+g,$+="M"+A+","+T+L);return $+='" stroke="transparent" fill="black"/>',$+="</svg>",$},b.createDataURL=function(c,g){c=c||2,g=typeof g>"u"?c*4:g;let f=b.getModuleCount()*c+g*2,d=g,p=f-g;return re(f,f,function(x,y){if(d<=x&&x<p&&d<=y&&y<p){let A=Math.floor((x-d)/c),E=Math.floor((y-d)/c);return b.isDark(E,A)?0:1}else return 1})},b.createImgTag=function(c,g,f){c=c||2,g=typeof g>"u"?c*4:g;let d=b.getModuleCount()*c+g*2,p="";return p+="<img",p+=' src="',p+=b.createDataURL(c,g),p+='"',p+=' width="',p+=d,p+='"',p+=' height="',p+=d,p+='"',f&&(p+=' alt="',p+=G(f),p+='"'),p+="/>",p};let G=function(c){let g="";for(let f=0;f<c.length;f+=1){let d=c.charAt(f);switch(d){case"<":g+="<";break;case">":g+=">";break;case"&":g+="&";break;case'"':g+=""";break;default:g+=d;break}}return g},Zt=function(c){c=typeof c>"u"?1*2:c;let f=b.getModuleCount()*1+c*2,d=c,p=f-c,x,y,A,E,T,$={"\u2588\u2588":"\u2588","\u2588 ":"\u2580"," \u2588":"\u2584"," ":" "},L={"\u2588\u2588":"\u2580","\u2588 ":"\u2580"," \u2588":" "," ":" "},P="";for(x=0;x<f;x+=2){for(A=Math.floor((x-d)/1),E=Math.floor((x+1-d)/1),y=0;y<f;y+=1)T="\u2588",d<=y&&y<p&&d<=x&&x<p&&b.isDark(A,Math.floor((y-d)/1))&&(T=" "),d<=y&&y<p&&d<=x+1&&x+1<p&&b.isDark(E,Math.floor((y-d)/1))?T+=" ":T+="\u2588",P+=c<1&&x+1>=p?L[T]:$[T];P+=`
|
|
2
|
+
`}return f%2&&c>0?P.substring(0,P.length-f-1)+Array(f+1).join("\u2580"):P.substring(0,P.length-1)};return b.createASCII=function(c,g){if(c=c||1,c<2)return Zt(g);c-=1,g=typeof g>"u"?c*2:g;let f=b.getModuleCount()*c+g*2,d=g,p=f-g,x,y,A,E,T=Array(c+1).join("\u2588\u2588"),$=Array(c+1).join(" "),L="",P="";for(x=0;x<f;x+=1){for(A=Math.floor((x-d)/c),P="",y=0;y<f;y+=1)E=1,d<=y&&y<p&&d<=x&&x<p&&b.isDark(A,Math.floor((y-d)/c))&&(E=0),P+=E?T:$;for(A=0;A<c;A+=1)L+=P+`
|
|
3
|
+
`}return L.substring(0,L.length-1)},b.renderTo2dContext=function(c,g){g=g||2;let f=b.getModuleCount();for(let d=0;d<f;d++)for(let p=0;p<f;p++)c.fillStyle=b.isDark(d,p)?"black":"white",c.fillRect(p*g,d*g,g,g)},b};H.stringToBytes=function(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t.charCodeAt(n);e.push(r&255)}return e};H.createStringToBytes=function(t,e){let n=function(){let i=ee(t),a=function(){let u=i.read();if(u==-1)throw"eof";return u},s=0,o={};for(;;){let u=i.read();if(u==-1)break;let l=a(),b=a(),m=a(),h=String.fromCharCode(u<<8|l),w=b<<8|m;o[h]=w,s+=1}if(s!=e)throw s+" != "+e;return o}(),r=63;return function(i){let a=[];for(let s=0;s<i.length;s+=1){let o=i.charCodeAt(s);if(o<128)a.push(o);else{let u=n[i.charAt(s)];typeof u=="number"?(u&255)==u?a.push(u):(a.push(u>>>8),a.push(u&255)):a.push(r)}}return a}};var C={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},Y={L:1,M:0,Q:3,H:2},v={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},S=function(){let t=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],e=1335,n=7973,r=21522,i={},a=function(s){let o=0;for(;s!=0;)o+=1,s>>>=1;return o};return i.getBCHTypeInfo=function(s){let o=s<<10;for(;a(o)-a(e)>=0;)o^=e<<a(o)-a(e);return(s<<10|o)^r},i.getBCHTypeNumber=function(s){let o=s<<12;for(;a(o)-a(n)>=0;)o^=n<<a(o)-a(n);return s<<12|o},i.getPatternPosition=function(s){return t[s-1]},i.getMaskFunction=function(s){switch(s){case v.PATTERN000:return function(o,u){return(o+u)%2==0};case v.PATTERN001:return function(o,u){return o%2==0};case v.PATTERN010:return function(o,u){return u%3==0};case v.PATTERN011:return function(o,u){return(o+u)%3==0};case v.PATTERN100:return function(o,u){return(Math.floor(o/2)+Math.floor(u/3))%2==0};case v.PATTERN101:return function(o,u){return o*u%2+o*u%3==0};case v.PATTERN110:return function(o,u){return(o*u%2+o*u%3)%2==0};case v.PATTERN111:return function(o,u){return(o*u%3+(o+u)%2)%2==0};default:throw"bad maskPattern:"+s}},i.getErrorCorrectPolynomial=function(s){let o=Z([1],0);for(let u=0;u<s;u+=1)o=o.multiply(Z([1,N.gexp(u)],0));return o},i.getLengthInBits=function(s,o){if(1<=o&&o<10)switch(s){case C.MODE_NUMBER:return 10;case C.MODE_ALPHA_NUM:return 9;case C.MODE_8BIT_BYTE:return 8;case C.MODE_KANJI:return 8;default:throw"mode:"+s}else if(o<27)switch(s){case C.MODE_NUMBER:return 12;case C.MODE_ALPHA_NUM:return 11;case C.MODE_8BIT_BYTE:return 16;case C.MODE_KANJI:return 10;default:throw"mode:"+s}else if(o<41)switch(s){case C.MODE_NUMBER:return 14;case C.MODE_ALPHA_NUM:return 13;case C.MODE_8BIT_BYTE:return 16;case C.MODE_KANJI:return 12;default:throw"mode:"+s}else throw"type:"+o},i.getLostPoint=function(s){let o=s.getModuleCount(),u=0;for(let m=0;m<o;m+=1)for(let h=0;h<o;h+=1){let w=0,B=s.isDark(m,h);for(let M=-1;M<=1;M+=1)if(!(m+M<0||o<=m+M))for(let k=-1;k<=1;k+=1)h+k<0||o<=h+k||M==0&&k==0||B==s.isDark(m+M,h+k)&&(w+=1);w>5&&(u+=3+w-5)}for(let m=0;m<o-1;m+=1)for(let h=0;h<o-1;h+=1){let w=0;s.isDark(m,h)&&(w+=1),s.isDark(m+1,h)&&(w+=1),s.isDark(m,h+1)&&(w+=1),s.isDark(m+1,h+1)&&(w+=1),(w==0||w==4)&&(u+=3)}for(let m=0;m<o;m+=1)for(let h=0;h<o-6;h+=1)s.isDark(m,h)&&!s.isDark(m,h+1)&&s.isDark(m,h+2)&&s.isDark(m,h+3)&&s.isDark(m,h+4)&&!s.isDark(m,h+5)&&s.isDark(m,h+6)&&(u+=40);for(let m=0;m<o;m+=1)for(let h=0;h<o-6;h+=1)s.isDark(h,m)&&!s.isDark(h+1,m)&&s.isDark(h+2,m)&&s.isDark(h+3,m)&&s.isDark(h+4,m)&&!s.isDark(h+5,m)&&s.isDark(h+6,m)&&(u+=40);let l=0;for(let m=0;m<o;m+=1)for(let h=0;h<o;h+=1)s.isDark(h,m)&&(l+=1);let b=Math.abs(100*l/o/o-50)/5;return u+=b*10,u},i}(),N=function(){let t=new Array(256),e=new Array(256);for(let r=0;r<8;r+=1)t[r]=1<<r;for(let r=8;r<256;r+=1)t[r]=t[r-4]^t[r-5]^t[r-6]^t[r-8];for(let r=0;r<255;r+=1)e[t[r]]=r;let n={};return n.glog=function(r){if(r<1)throw"glog("+r+")";return e[r]},n.gexp=function(r){for(;r<0;)r+=255;for(;r>=256;)r-=255;return t[r]},n}(),Z=function(t,e){if(typeof t.length>"u")throw t.length+"/"+e;let n=function(){let i=0;for(;i<t.length&&t[i]==0;)i+=1;let a=new Array(t.length-i+e);for(let s=0;s<t.length-i;s+=1)a[s]=t[s+i];return a}(),r={};return r.getAt=function(i){return n[i]},r.getLength=function(){return n.length},r.multiply=function(i){let a=new Array(r.getLength()+i.getLength()-1);for(let s=0;s<r.getLength();s+=1)for(let o=0;o<i.getLength();o+=1)a[s+o]^=N.gexp(N.glog(r.getAt(s))+N.glog(i.getAt(o)));return Z(a,0)},r.mod=function(i){if(r.getLength()-i.getLength()<0)return r;let a=N.glog(r.getAt(0))-N.glog(i.getAt(0)),s=new Array(r.getLength());for(let o=0;o<r.getLength();o+=1)s[o]=r.getAt(o);for(let o=0;o<i.getLength();o+=1)s[o]^=N.gexp(N.glog(i.getAt(o))+a);return Z(s,0).mod(i)},r},Lt=function(){let t=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],e=function(i,a){let s={};return s.totalCount=i,s.dataCount=a,s},n={},r=function(i,a){switch(a){case Y.L:return t[(i-1)*4+0];case Y.M:return t[(i-1)*4+1];case Y.Q:return t[(i-1)*4+2];case Y.H:return t[(i-1)*4+3];default:return}};return n.getRSBlocks=function(i,a){let s=r(i,a);if(typeof s>"u")throw"bad rs block @ typeNumber:"+i+"/errorCorrectionLevel:"+a;let o=s.length/3,u=[];for(let l=0;l<o;l+=1){let b=s[l*3+0],m=s[l*3+1],h=s[l*3+2];for(let w=0;w<b;w+=1)u.push(e(m,h))}return u},n}(),Tt=function(){let t=[],e=0,n={};return n.getBuffer=function(){return t},n.getAt=function(r){let i=Math.floor(r/8);return(t[i]>>>7-r%8&1)==1},n.put=function(r,i){for(let a=0;a<i;a+=1)n.putBit((r>>>i-a-1&1)==1)},n.getLengthInBits=function(){return e},n.putBit=function(r){let i=Math.floor(e/8);t.length<=i&&t.push(0),r&&(t[i]|=128>>>e%8),e+=1},n},Wt=function(t){let e=C.MODE_NUMBER,n=t,r={};r.getMode=function(){return e},r.getLength=function(s){return n.length},r.write=function(s){let o=n,u=0;for(;u+2<o.length;)s.put(i(o.substring(u,u+3)),10),u+=3;u<o.length&&(o.length-u==1?s.put(i(o.substring(u,u+1)),4):o.length-u==2&&s.put(i(o.substring(u,u+2)),7))};let i=function(s){let o=0;for(let u=0;u<s.length;u+=1)o=o*10+a(s.charAt(u));return o},a=function(s){if("0"<=s&&s<="9")return s.charCodeAt(0)-48;throw"illegal char :"+s};return r},Xt=function(t){let e=C.MODE_ALPHA_NUM,n=t,r={};r.getMode=function(){return e},r.getLength=function(a){return n.length},r.write=function(a){let s=n,o=0;for(;o+1<s.length;)a.put(i(s.charAt(o))*45+i(s.charAt(o+1)),11),o+=2;o<s.length&&a.put(i(s.charAt(o)),6)};let i=function(a){if("0"<=a&&a<="9")return a.charCodeAt(0)-48;if("A"<=a&&a<="Z")return a.charCodeAt(0)-65+10;switch(a){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+a}};return r},Jt=function(t){let e=C.MODE_8BIT_BYTE,n=t,r=H.stringToBytes(t),i={};return i.getMode=function(){return e},i.getLength=function(a){return r.length},i.write=function(a){for(let s=0;s<r.length;s+=1)a.put(r[s],8)},i},Vt=function(t){let e=C.MODE_KANJI,n=t,r=H.stringToBytes;(function(s,o){let u=r(s);if(u.length!=2||(u[0]<<8|u[1])!=o)throw"sjis not supported."})("\u53CB",38726);let i=r(t),a={};return a.getMode=function(){return e},a.getLength=function(s){return~~(i.length/2)},a.write=function(s){let o=i,u=0;for(;u+1<o.length;){let l=(255&o[u])<<8|255&o[u+1];if(33088<=l&&l<=40956)l-=33088;else if(57408<=l&&l<=60351)l-=49472;else throw"illegal char at "+(u+1)+"/"+l;l=(l>>>8&255)*192+(l&255),s.put(l,13),u+=2}if(u<o.length)throw"illegal char at "+(u+1)},a},Ct=function(){let t=[],e={};return e.writeByte=function(n){t.push(n&255)},e.writeShort=function(n){e.writeByte(n),e.writeByte(n>>>8)},e.writeBytes=function(n,r,i){r=r||0,i=i||n.length;for(let a=0;a<i;a+=1)e.writeByte(n[a+r])},e.writeString=function(n){for(let r=0;r<n.length;r+=1)e.writeByte(n.charCodeAt(r))},e.toByteArray=function(){return t},e.toString=function(){let n="";n+="[";for(let r=0;r<t.length;r+=1)r>0&&(n+=","),n+=t[r];return n+="]",n},e},te=function(){let t=0,e=0,n=0,r="",i={},a=function(o){r+=String.fromCharCode(s(o&63))},s=function(o){if(o<0)throw"n:"+o;if(o<26)return 65+o;if(o<52)return 97+(o-26);if(o<62)return 48+(o-52);if(o==62)return 43;if(o==63)return 47;throw"n:"+o};return i.writeByte=function(o){for(t=t<<8|o&255,e+=8,n+=1;e>=6;)a(t>>>e-6),e-=6},i.flush=function(){if(e>0&&(a(t<<6-e),t=0,e=0),n%3!=0){let o=3-n%3;for(let u=0;u<o;u+=1)r+="="}},i.toString=function(){return r},i},ee=function(t){let e=t,n=0,r=0,i=0,a={};a.read=function(){for(;i<8;){if(n>=e.length){if(i==0)return-1;throw"unexpected end of file./"+i}let u=e.charAt(n);if(n+=1,u=="=")return i=0,-1;if(u.match(/^\s$/))continue;r=r<<6|s(u.charCodeAt(0)),i+=6}let o=r>>>i-8&255;return i-=8,o};let s=function(o){if(65<=o&&o<=90)return o-65;if(97<=o&&o<=122)return o-97+26;if(48<=o&&o<=57)return o-48+52;if(o==43)return 62;if(o==47)return 63;throw"c:"+o};return a},ne=function(t,e){let n=t,r=e,i=new Array(t*e),a={};a.setPixel=function(l,b,m){i[b*n+l]=m},a.write=function(l){l.writeString("GIF87a"),l.writeShort(n),l.writeShort(r),l.writeByte(128),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(0),l.writeByte(255),l.writeByte(255),l.writeByte(255),l.writeString(","),l.writeShort(0),l.writeShort(0),l.writeShort(n),l.writeShort(r),l.writeByte(0);let b=2,m=o(b);l.writeByte(b);let h=0;for(;m.length-h>255;)l.writeByte(255),l.writeBytes(m,h,255),h+=255;l.writeByte(m.length-h),l.writeBytes(m,h,m.length-h),l.writeByte(0),l.writeString(";")};let s=function(l){let b=l,m=0,h=0,w={};return w.write=function(B,M){if(B>>>M)throw"length over";for(;m+M>=8;)b.writeByte(255&(B<<m|h)),M-=8-m,B>>>=8-m,h=0,m=0;h=B<<m|h,m=m+M},w.flush=function(){m>0&&b.writeByte(h)},w},o=function(l){let b=1<<l,m=(1<<l)+1,h=l+1,w=u();for(let O=0;O<b;O+=1)w.add(String.fromCharCode(O));w.add(String.fromCharCode(b)),w.add(String.fromCharCode(m));let B=Ct(),M=s(B);M.write(b,h);let k=0,_=String.fromCharCode(i[k]);for(k+=1;k<i.length;){let O=String.fromCharCode(i[k]);k+=1,w.contains(_+O)?_=_+O:(M.write(w.indexOf(_),h),w.size()<4095&&(w.size()==1<<h&&(h+=1),w.add(_+O)),_=O)}return M.write(w.indexOf(_),h),M.write(m,h),M.flush(),B.toByteArray()},u=function(){let l={},b=0,m={};return m.add=function(h){if(m.contains(h))throw"dup key:"+h;l[h]=b,b+=1},m.size=function(){return b},m.indexOf=function(h){return l[h]},m.contains=function(h){return typeof l[h]<"u"},m};return a},re=function(t,e,n){let r=ne(t,e);for(let o=0;o<e;o+=1)for(let u=0;u<t;u+=1)r.setPixel(u,o,n(u,o));let i=Ct();r.write(i);let a=te(),s=i.toByteArray();for(let o=0;o<s.length;o+=1)a.writeByte(s[o]);return a.flush(),"data:image/gif;base64,"+a},kt=H,Ye=H.stringToBytes;var I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function U(t){if(typeof Buffer<"u")return Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64");let e="";for(let n=0;n<t.length;n+=3){let r=t[n],i=n+1<t.length?t[n+1]:0,a=n+2<t.length?t[n+2]:0,s=r<<16|i<<8|a;e+=I[s>>18&63]+I[s>>12&63],e+=n+1<t.length?I[s>>6&63]:"=",e+=n+2<t.length?I[s&63]:"="}return e}function at(t){if(typeof Buffer<"u"){let i=Buffer.from(t,"base64");return new Uint8Array(i.buffer,i.byteOffset,i.byteLength)}let e=t.replace(/[^A-Za-z0-9+/]/g,""),n=new Uint8Array(Math.floor(e.length*3/4)),r=0;for(let i=0;i<e.length;i+=4){let a=I.indexOf(e[i])<<18|I.indexOf(e[i+1])<<12|(I.indexOf(e[i+2])&63)<<6|I.indexOf(e[i+3])&63;n[r++]=a>>16&255,i+2<e.length&&(n[r++]=a>>8&255),i+3<e.length&&(n[r++]=a&255)}return n.subarray(0,r)}function Q(t,e){return{width:t,height:e,bits:new Uint8Array(Math.ceil(t/8)*e)}}function q(t,e,n,r){if(e<0||n<0||e>=t.width||n>=t.height)return;let i=n*Math.ceil(t.width/8)+(e>>3),a=128>>(e&7);r?t.bits[i]|=a:t.bits[i]&=~a}function ut(t,e,n){return e<0||n<0||e>=t.width||n>=t.height?!1:(t.bits[n*Math.ceil(t.width/8)+(e>>3)]&128>>(e&7))!==0}function Je(t,e,n,r=128){let i=Q(e,n);for(let a=0;a<n;a++)for(let s=0;s<e;s++){let o=(a*e+s)*4,u=t[o+3]/255;(.299*t[o]+.587*t[o+1]+.114*t[o+2])*u+255*(1-u)<r&&q(i,s,a,!0)}return i}function ie(t,e,n,r){for(let i=0;i<e.height;i++)for(let a=0;a<e.width;a++)ut(e,a,i)&&q(t,n+a,r+i,!0)}function Ve(t,e,n="center"){if(t.width===e)return t;let r=Q(e,t.height),i=n==="left"?0:n==="right"?e-t.width:Math.floor((e-t.width)/2);return ie(r,t,i,0),r}function j(t,e={}){let n=new TextEncoder().encode(t),r="";for(let u=0;u<n.length;u++)r+=String.fromCharCode(n[u]);let i=kt(0,e.correction??"M");i.addData(r,"Byte"),i.make();let a=i.getModuleCount(),s=Math.max(1,Math.min(16,Math.floor(e.size??6))),o=Q(a*s,a*s);for(let u=0;u<a;u++)for(let l=0;l<a;l++)if(i.isDark(u,l))for(let b=0;b<s;b++)for(let m=0;m<s;m++)q(o,l*s+m,u*s+b,!0);return o}function tn(t,e,n){let r=new Float32Array(e*n);for(let a=0;a<e*n;a++){let s=t[a*4+3]/255;r[a]=(.299*t[a*4]+.587*t[a*4+1]+.114*t[a*4+2])*s+255*(1-s)}let i=Q(e,n);for(let a=0;a<n;a++)for(let s=0;s<e;s++){let o=a*e+s,u=r[o],l=u<128;l&&q(i,s,a,!0);let b=u-(l?0:255);s+1<e&&(r[o+1]+=b*7/16),a+1<n&&(s>0&&(r[o+e-1]+=b*3/16),r[o+e]+=b*5/16,s+1<e&&(r[o+e+1]+=b/16))}return i}function en(t){return{width:t.width,height:t.height,data:U(t.bits)}}function Pt(t){let e=at(t.data),n=Math.ceil(t.width/8)*t.height;if(e.length!==n)throw new Error(`retail-print-kit: bitmap data is ${e.length} bytes, expected ${n}`);return{width:t.width,height:t.height,bits:e}}var oe={lt:"left",ct:"center",rt:"right",left:"left",center:"center",right:"right"},tt=class{constructor(e){this.profile=e;this.ops=[];this.font="a"}get operations(){return this.ops.slice()}append(e){for(let n of e)this.ops.push(n);return this}get columns(){return this.profile.columns[this.font]}push(e){return this.ops.push(e),this}raw(e){return this.push({kind:"raw",bytes:Uint8Array.from(e)})}text(e){return this.push({kind:"text",text:`${e}
|
|
4
|
+
`})}print(e){return this.push({kind:"text",text:e})}newLine(e=1){return this.push({kind:"newline",count:e})}feed(e=1){return this.push({kind:"feed",lines:e})}align(e){let n=oe[e];if(!n)throw new Error(`retail-print-kit: unknown align "${e}"`);return this.push({kind:"align",align:n})}setFont(e){return this.font=e,this.push({kind:"font",font:e})}size(e,n){return this.push({kind:"size",width:e,height:n})}style(e){let n=typeof e=="string"?se(e):e;return this.push({kind:"style",style:n})}lineSpace(e=null){return this.push({kind:"lineSpacing",dots:e})}cut(e=!1,n=3){return this.push({kind:"cut",partial:e,feed:n})}cashdraw(e=2){return this.push({kind:"drawer",pin:e})}beep(e=1,n=1){return this.push({kind:"beep",times:e,duration:n})}barcode(e,n="CODE128",r={}){return this.push({kind:"barcode",data:e,type:n,options:r})}qr(e,n={}){return this.profile.features.nativeQr||this.profile.set==="star-graphic"?this.push({kind:"qr",data:e,options:n}):this.image(j(e,n))}image(e){return this.push({kind:"raster",width:e.width,height:e.height,bits:e.bits})}qrimage(e,n={}){return this.qr(e,n)}drawLine(e="-"){return this.text(e.repeat(this.columns))}tableCustom(e,n={}){let r=n.width??this.columns,i=ae(e,r),a=n.wrap!==!1,s=e.map((u,l)=>a?ue(u.text??"",i[l]):[String(u.text??"").slice(0,i[l])]),o=Math.max(1,...s.map(u=>u.length));for(let u=0;u<o;u++){let l="";e.forEach((b,m)=>{l+=fe(s[m][u]??"",i[m],b.align??"LEFT")}),this.text(l.replace(/\s+$/,""))}return this}};function se(t){if(t==="normal")return{bold:!1,underline:0,italic:!1,invert:!1};let e=t.toLowerCase();return{bold:e.includes("b"),italic:e.includes("i"),underline:e.includes("u2")?2:e.includes("u")?1:0,invert:!1}}function ae(t,e){let n=t.map(u=>u.width===void 0?null:u.width>1?Math.floor(u.width):Math.floor(u.width*e)),r=n.reduce((u,l)=>u+(l??0),0),i=n.filter(u=>u===null).length,a=i?Math.floor(Math.max(0,e-r)/i):0,s=n.map(u=>u===null?a:u),o=s.reduce((u,l)=>u+l,0);return o<e&&(s[s.length-1]+=e-o),s}function ue(t,e){if(e<=0)return[""];let n=[];for(let r of String(t).split(`
|
|
5
|
+
`)){let i="";for(let a of r.split(/\s+/)){if(!a)continue;if(a.length>e){i&&n.push(i),i="";for(let o=0;o<a.length;o+=e)n.push(a.slice(o,o+e));continue}let s=i?`${i} ${a}`:a;s.length>e?(n.push(i),i=a):i=s}n.push(i)}return n.length?n:[""]}function fe(t,e,n){let r=t.slice(0,e),i=e-r.length;if(n==="RIGHT")return" ".repeat(i)+r;if(n==="CENTER"){let a=Math.floor(i/2);return" ".repeat(a)+r+" ".repeat(i-a)}return r+" ".repeat(i)}var ce=["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"],le=104,he=105,pe=100,de=99,ge=106;function me(t){if(!/^[\x20-\x7e]*$/.test(t)||!t.length)throw new Error("retail-print-kit: CODE128 needs printable ASCII");let e=[],n=0,r=null,i=o=>{let u=0;for(;o+u<t.length&&/[0-9]/.test(t[o+u]);)u++;return u};for(;n<t.length;){let o=i(n);if(o>=4||o>=2&&o===t.length-n){r!=="C"&&(e.push(r===null?he:de),r="C");let l=Math.floor(o/2);for(let b=0;b<l;b++)e.push(parseInt(t.slice(n,n+2),10)),n+=2;continue}r!=="B"&&(e.push(r===null?le:pe),r="B"),e.push(t.charCodeAt(n)-32),n++}let a=e[0];for(let o=1;o<e.length;o++)a+=e[o]*o;e.push(a%103,ge);let s=[];for(let o of e)for(let u of ce[o])s.push(Number(u));return s}var Dt=["0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011"],be=["0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111"],Ot=["1110010","1100110","1101100","1000010","1011100","1001110","1010000","1000100","1001000","1110100"],xe=["LLLLLL","LLGLGG","LLGGLG","LLGGGL","LGLLGG","LGGLLG","LGGGLL","LGLGLG","LGLGGL","LGGLGL"];function ft(t){let e=0;for(let n=0;n<t.length;n++){let r=(t.length-n)%2===0?1:3;e+=Number(t[n])*r}return(10-e%10)%10}function ct(t){let e=[],n="1",r=0;t[0]!=="1"&&e.push(0);for(let i of t)i===n?r++:(e.push(r),n=i,r=1);return e.push(r),e}function _t(t){let e=t.replace(/\D/g,"");if(e.length===12&&(e+=ft(e)),e.length!==13)throw new Error("retail-print-kit: EAN13 needs 12 or 13 digits");let n=xe[Number(e[0])],r="101";for(let i=1;i<=6;i++)r+=(n[i-1]==="L"?Dt:be)[Number(e[i])];r+="01010";for(let i=7;i<=12;i++)r+=Ot[Number(e[i])];return r+="101",ct(r)}function we(t){let e=t.replace(/\D/g,"");if(e.length===11&&(e+=ft(e)),e.length!==12)throw new Error("retail-print-kit: UPC-A needs 11 or 12 digits");return _t("0"+e)}function ye(t){let e=t.replace(/\D/g,"");if(e.length===7&&(e+=ft(e)),e.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+=Dt[Number(e[r])];n+="01010";for(let r=4;r<8;r++)n+=Ot[Number(e[r])];return n+="101",ct(n)}var $e={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 Ae(t){let e=`*${t.toUpperCase()}*`,n="";for(let r of e){let i=$e[r];if(!i)throw new Error(`retail-print-kit: CODE39 cannot encode "${r}"`);n+=i+"0"}return ct(n.slice(0,-1))}function Be(t,e){switch(t){case"CODE128":return me(e);case"EAN13":return _t(e);case"UPC_A":return we(e);case"EAN8":return ye(e);case"CODE39":return Ae(e);default:throw new Error(`retail-print-kit: bitmap rendering of ${t} is not implemented`)}}function et(t,e,n=2,r=80){let i=Be(t,e),a=10*n,s=i.reduce((b,m)=>b+m,0)*n+a*2,o=Q(s,r),u=a,l=!0;for(let b of i){if(l)for(let m=0;m<b*n;m++)for(let h=0;h<r;h++)q(o,u+m,h,!0);u+=b*n,l=!l}return o}var nt={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}},Rt={...nt,id:"epson-tm-t88",model:"TM-T88V / VI / VII",usb:[{vendorId:1208}]},vt={...nt,id:"epson-tm-t20",model:"TM-T20III",usb:[{vendorId:1208}]},St={...nt,id:"epson-tm-m30",model:"TM-m30II / III",usb:[{vendorId:1208}]},lt={...nt,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}},Nt={...lt,id:"generic-escpos-58",model:"ESC/POS compatible 58 mm",paper:58,dots:384,columns:{a:32,b:42}};var ht={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}]},It={...ht,id:"star-tsp650",model:"TSP650II / TSP700II (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Ut={...ht,id:"star-mc-print3",model:"mC-Print3 (Star Line Mode)",set:"star-line",features:{nativeQr:!0,raster:!0,italic:!1,invert:!0,beep:!1}},Ft={...ht,id:"star-tsp100",model:"TSP100 / TSP143 (raster)",set:"star-graphic",codepage:null,features:{nativeQr:!1,raster:!0,italic:!1,invert:!0,beep:!1}};var Me=Object.fromEntries([Rt,vt,St,lt,Nt,It,Ut,Ft].map(t=>[t.id,t]));function dn(t){let e=Me[t];if(!e)throw new Error(`retail-print-kit: unknown profile "${t}"`);return e}var Ht={upper:t=>String(t??"").toUpperCase(),lower:t=>String(t??"").toLowerCase(),trim:t=>String(t??"").trim(),money:(t,e)=>{let n=Number(t);if(!isFinite(n))return"";let r=Math.abs(n).toFixed(2);return`${n<0?"-":""}${e??""}${r}`},fixed:(t,e)=>{let n=Number(t);return isFinite(n)?n.toFixed(Number(e??2)):""},pad:(t,e)=>String(t??"").padStart(Number(e??0)),padEnd:(t,e)=>String(t??"").padEnd(Number(e??0)),default:(t,e)=>t==null||t===""?e??"":t,date:(t,e)=>{let n=t instanceof Date?t:new Date(String(t));return isNaN(n.getTime())?"":e==="time"?n.toLocaleTimeString():e==="datetime"?n.toLocaleString():n.toLocaleDateString()},count:t=>Array.isArray(t)?t.length:0};function Qt(t,e){let n=t.trim();if(n==="this")return e.current;if(n==="@index")return e.index;if(n==="@number")return e.index===void 0?void 0:e.index+1;if(/^-?\d+(\.\d+)?$/.test(n))return Number(n);if(/^'.*'$/.test(n)||/^".*"$/.test(n))return n.slice(1,-1);let r=Gt(e.current,n);return r!==void 0?r:Gt(e.root,n)}function Gt(t,e){let n=t;for(let r of e.split(".")){if(n==null)return;n=n[r]}return n}function z(t,e){let[n,...r]=t.split("|").map(a=>a.trim()),i=Qt(n,e);for(let a of r){let s=a.indexOf(":"),o=s===-1?a:a.slice(0,s),u=s===-1?void 0:a.slice(s+1),l=Ht[o];if(!l)throw new Error(`retail-print-kit: unknown template filter "${o}"`);i=l(i,u)}return i}function D(t,e){return t.replace(/\{\{([^}]+)\}\}/g,(n,r)=>{let i=z(r,e);return i==null?"":String(i)})}function K(t,e){let n=t.trim().startsWith("!"),r=z(n?t.trim().slice(1):t,e),i=Array.isArray(r)?r.length>0:!!r;return n?!i:i}var rt={left:"lt",center:"ct",right:"rt"};function Ee(t,e,n){if(t.version!==1)throw new Error(`retail-print-kit: unsupported template version ${String(t.version)}`);let r=new tt(n);return W(t.blocks,{root:e,current:e},r),r.operations}function W(t,e,n){for(let r of t)Le(r,e,n)}function Le(t,e,n){switch(t.type){case"text":{t.align&&n.align(rt[t.align]),t.font&&n.setFont(t.font),t.size&&n.size(t.size[0],t.size[1]),t.style&&n.style(t.style),n.text(D(t.value,e)),t.style&&n.style("normal"),t.size&&n.size(1,1),t.font&&n.setFont("a"),t.align&&t.align!=="left"&&n.align("lt");break}case"line":n.drawLine(t.char??"-");break;case"row":n.tableCustom(t.cells.map(r=>({text:D(r.value,e),width:r.width,align:r.align??"LEFT"})));break;case"table":{let r=z(t.rows,e);if(t.header!==!1&&t.columns.some(i=>i.header)&&n.tableCustom(t.columns.map(i=>({text:i.header??"",width:i.width,align:i.align??"LEFT"}))),!Array.isArray(r))break;r.forEach((i,a)=>{let s={root:e.root,current:i,index:a},o=t.columns.map(u=>({text:D(u.value,s),width:u.width,align:u.align??"LEFT"}));n.tableCustom(o)});break}case"feed":n.feed(t.lines??1);break;case"newline":n.newLine(t.count??1);break;case"cut":n.cut(t.partial??!1,t.feed??3);break;case"drawer":n.cashdraw(t.pin??2);break;case"qr":{t.align&&n.align(rt[t.align]),n.qr(D(t.value,e),{size:t.size}),t.align&&t.align!=="left"&&n.align("lt");break}case"barcode":{t.align&&n.align(rt[t.align]),n.barcode(D(t.value,e),t.format??"CODE128",{height:t.height,width:t.width,position:t.text===!1?"none":"below"}),t.align&&t.align!=="left"&&n.align("lt");break}case"image":{t.align&&n.align(rt[t.align]),n.image(Pt(t)),t.align&&t.align!=="left"&&n.align("lt");break}case"each":{let r=z(t.items,e);if(!Array.isArray(r))break;r.forEach((i,a)=>W(t.blocks,{root:e.root,current:i,index:a},n));break}case"if":K(t.when,e)?W(t.blocks,e,n):t.else&&W(t.else,e,n);break;default:throw new Error(`retail-print-kit: unknown template block "${t.type}"`)}}var Te=(()=>{let t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let r=0;r<8;r++)n=n&1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function Ce(t){let e=4294967295;for(let n of t)e=Te[(e^n)&255]^e>>>8;return(e^4294967295)>>>0}function X(t){return[t>>>24&255,t>>>16&255,t>>>8&255,t&255]}function it(t){let e=new Uint8Array(t.reduce((r,i)=>r+i.length,0)),n=0;for(let r of t)e.set(r,n),n+=r.length;return e}function pt(t,e){let n=it([new Uint8Array([...t].map(r=>r.charCodeAt(0))),e]);return it([new Uint8Array(X(e.length)),n,new Uint8Array(X(Ce(n)))])}function ke(t){let e=1,n=0;for(let r of t)e=(e+r)%65521,n=(n+e)%65521;return(n<<16|e)>>>0}function Pe(t){let e=[new Uint8Array([120,1])],n=65535;for(let r=0;r<t.length||r===0;r+=n){let i=t.subarray(r,Math.min(r+n,t.length)),a=r+n>=t.length?1:0,s=i.length;if(e.push(new Uint8Array([a,s&255,s>>8,~s&255,~s>>8&255]),i),t.length===0)break}return e.push(new Uint8Array(X(ke(t)))),it(e)}function De(t){try{let n=Kt("zlib").deflateSync(t);return new Uint8Array(n.buffer,n.byteOffset,n.byteLength)}catch{return Pe(t)}}function F(t){let e=Math.ceil(t.width/8),n=new Uint8Array((e+1)*t.height);for(let a=0;a<t.height;a++)for(let s=0;s<t.width;s++)ut(t,s,a)||(n[a*(e+1)+1+(s>>3)]|=128>>(s&7));let r=new Uint8Array([...X(t.width),...X(t.height),1,0,0,0,0]),i=it([new Uint8Array([137,80,78,71,13,10,26,10]),pt("IHDR",r),pt("IDAT",De(n)),pt("IEND",new Uint8Array(0))]);return typeof Buffer<"u"?Buffer.from(i.buffer,i.byteOffset,i.byteLength):i}function dt(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Oe(t,e,n={}){let r=n.cellWidth??8,i=e.columns.a*r,a={align:"left",font:"a",w:1,h:1,style:{}},s=[],o="",u=()=>{let h=[`text-align:${a.align}`];return(a.w!==1||a.h!==1)&&h.push(`transform:scale(${a.w},${a.h});transform-origin:${a.align} top`,`height:${a.h}em`),a.font==="b"&&h.push("font-size:0.78em"),a.style.bold&&h.push("font-weight:bold"),a.style.underline&&h.push(`text-decoration:underline${a.style.underline===2?" double":""}`),a.style.invert&&h.push("background:#000;color:#fff"),h.join(";")},l=h=>{if(!o&&!h)return;let w=Math.max(1,Math.floor(e.columns[a.font]/a.w)),B=[];for(let M=0;M<o.length;M+=w)B.push(o.slice(M,M+w));B.length||B.push("");for(let M of B)s.push(`<div class="l" style="${u()}">${dt(M)||" "}</div>`);o=""},b=(h,w,B)=>s.push(`<div class="l" style="text-align:${a.align}"><img alt="${dt(B)}" width="${Math.round(w/e.dots*i)}" src="data:image/png;base64,${U(h)}"></div>`);for(let h of t)switch(h.kind){case"text":{let w=h.text.split(`
|
|
6
|
+
`);for(let B=0;B<w.length;B++)o+=w[B],B<w.length-1&&l(!0);break}case"newline":for(let w=0;w<h.count;w++)l(!0);break;case"feed":l(!1);for(let w=0;w<h.lines;w++)s.push('<div class="l"> </div>');break;case"align":l(!1),a.align=h.align;break;case"font":l(!1),a.font=h.font;break;case"size":l(!1),a.w=h.width,a.h=h.height;break;case"style":l(!1),a.style=h.style;break;case"qr":{l(!1);let w=j(h.data,h.options);b(F(w),w.width,`QR ${h.data}`);break}case"barcode":{l(!1);let w=et(h.type,h.data,h.options.width??2,h.options.height??80);b(F(w),w.width,`${h.type} ${h.data}`);let B=h.options.position??"below";(B==="below"||B==="both")&&(o=h.data,l(!0));break}case"raster":{l(!1),b(F({width:h.width,height:h.height,bits:h.bits}),h.width,"image");break}case"cut":l(!1),s.push('<div class="cut"></div>');break;case"drawer":l(!1),s.push('<div class="note">[drawer kick]</div>');break;default:break}l(!1);let m=`<div class="paper" style="width:${i}px">${s.join("")}</div>`;return n.document===!1?m:`<!doctype html><html><head><meta charset="utf-8"><title>${dt(e.model)} preview</title><style>
|
|
12
7
|
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
8
|
.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
9
|
.l{white-space:pre;overflow:hidden;min-height:1.25em}
|
|
15
10
|
.cut{border-top:2px dashed #999;margin:6px -${r}px}
|
|
16
11
|
.note{color:#999;font-size:.7em;text-align:center}
|
|
17
12
|
img{image-rendering:pixelated;vertical-align:top}
|
|
18
|
-
</style></head><body>${
|
|
13
|
+
</style></head><body>${m}</body></html>`}var gt={0:"N",90:"R",180:"I",270:"B"},_e={CODE128:"BC",EAN13:"BE",EAN8:"B8",UPC_A:"BU",UPC_E:"B9",CODE39:"B3",ITF:"B2",CODABAR:"BK"};function mt(t){return t.replace(/[\^~\\]/g,e=>`\\${e}`)}function Re(t){let e=Math.ceil(t.width/8),n="";for(let r=0;r<t.bits.length;r++)n+=t.bits[r].toString(16).padStart(2,"0").toUpperCase();return`${e*t.height},${e*t.height},${e},${n}`}function ve(t){let e=`^FO${Math.round(t.x)},${Math.round(t.y)}`;switch(t.kind){case"text":{let n=Math.round(t.width??t.height*.9),r=t.invert?"^FR":"";return`${e}${r}^A0${gt[t.rotation??0]},${Math.round(t.height)},${n}^FD${mt(t.text)}^FS`}case"barcode":{let n=_e[t.type];if(!n)throw new Error(`retail-print-kit: ZPL has no ${t.type}`);let r=t.text===!1?"N":"Y",i=t.type==="CODE128"?`,${r},N,N`:`,${r},N`;return`${e}^BY${t.module??2},2,${Math.round(t.height)}^${n}${gt[t.rotation??0]},${Math.round(t.height)}${i}^FD${mt(t.data)}^FS`}case"qr":{let n=t.correction??"M";return`${e}^BQ${gt[t.rotation??0]},2,${t.module??4}^FD${n}A,${mt(t.data)}^FS`}case"box":return`${e}^GB${Math.round(t.width)},${Math.round(t.height)},${t.thickness??2}^FS`;case"rect":return`${e}^GB${Math.round(t.width)},${Math.round(t.height)},${Math.round(Math.min(t.width,t.height))}^FS`;case"image":return`${e}^GFA,${Re(t.bitmap)}^FS`}}function bt(t){let e=["^XA","^CI28",`^PW${t.width}`,`^LL${t.height}`,"^LH0,0"];t.speed!==void 0&&e.push(`^PR${Math.round(t.speed)}`),t.darkness!==void 0&&e.push(`^MD${Math.round(t.darkness*2-15)}`);for(let n of t.ops)e.push(ve(n));return e.push(`^PQ${t.copies},0,1,Y`,"^XZ"),e.join(`
|
|
19
14
|
`)+`
|
|
20
|
-
`}function
|
|
21
|
-
REVERSE ${n},${r},${Math.round(s*
|
|
22
|
-
`):
|
|
23
|
-
${
|
|
15
|
+
`}function ot(t,e){return Math.round(t/25.4*e)}function J(t,e){return t/e*25.4}var Se={CODE128:"128",EAN13:"EAN13",EAN8:"EAN8",UPC_A:"UPCA",UPC_E:"UPCE",CODE39:"39",ITF:"ITF",CODABAR:"CODA"};function xt(t){return`"${t.replace(/"/g,'\\["]')}"`}function qt(t,e){return J(t,e).toFixed(2)}function Ne(t){let e=new Uint8Array(t.bits.length);for(let n=0;n<t.bits.length;n++)e[n]=~t.bits[n]&255;return e}function Ie(t,e){let n=Math.round(t.x),r=Math.round(t.y),i=a=>a??0;switch(t.kind){case"text":{let a=Math.round(t.height),s=Math.round(t.width??t.height*.9),o=`TEXT ${n},${r},"0",${i(t.rotation)},${s},${a},${xt(t.text)}`;return t.invert?`${o}
|
|
16
|
+
REVERSE ${n},${r},${Math.round(s*t.text.length*.6)},${a}`:o}case"barcode":{let a=Se[t.type];if(!a)throw new Error(`retail-print-kit: TSPL has no ${t.type}`);let s=t.module??2;return`BARCODE ${n},${r},"${a}",${Math.round(t.height)},${t.text===!1?0:1},${i(t.rotation)},${s},${s*2},${xt(t.data)}`}case"qr":return`QRCODE ${n},${r},${t.correction??"M"},${t.module??4},A,${i(t.rotation)},${xt(t.data)}`;case"box":return`BOX ${n},${r},${n+Math.round(t.width)},${r+Math.round(t.height)},${t.thickness??2}`;case"rect":return`BAR ${n},${r},${Math.round(t.width)},${Math.round(t.height)}`;case"image":{let a=Math.ceil(t.bitmap.width/8),s=`BITMAP ${n},${r},${a},${t.bitmap.height},0,`,o=Ne(t.bitmap),u=new Uint8Array(s.length+o.length+1);for(let l=0;l<s.length;l++)u[l]=s.charCodeAt(l);return u.set(o,s.length),u[u.length-1]=10,u}}}function wt(t){let e=[`SIZE ${qt(t.width,t.dpi)} mm,${qt(t.height,t.dpi)} mm`,`GAP ${t.gap.toFixed(2)} mm,0 mm`,"DIRECTION 1,0","REFERENCE 0,0"];t.speed!==void 0&&e.push(`SPEED ${t.speed}`),t.darkness!==void 0&&e.push(`DENSITY ${Math.round(t.darkness)}`),e.push("CLS");for(let a of t.ops)e.push(Ie(a,t.dpi));e.push(`PRINT ${t.copies},1`);let n=e.map(a=>typeof a=="string"?new TextEncoder().encode(a+`
|
|
17
|
+
`):a),r=new Uint8Array(n.reduce((a,s)=>a+s.length,0)),i=0;for(let a of n)r.set(a,i),i+=a.length;return r}var yt=[["A",12],["B",16],["C",20],["D",24],["E",32],["F",40],["G",48],["H",64]],Ue={CODE39:"A",CODE128:"C",EAN13:"E",EAN8:"F",UPC_E:"G",UPC_A:"H",ITF:"I",CODABAR:"J"};function Fe(t){let e=yt[0][0],n=yt[0][1];for(let[i,a]of yt)a<=t&&(e=i,n=a);let r=Math.max(1,Math.min(9,Math.floor(t/n)));return{font:e,mul:r}}function Ge(t){let e=Math.round(t.x),n=Math.round(t.y),r=t.rotation??0;switch(t.kind){case"text":{let{font:i,mul:a}=Fe(t.height);return`A${i},${e},${n},${a},${a},${r/90},0${t.invert?"R":"E"},${t.text}`}case"barcode":{let i=Ue[t.type];if(!i)throw new Error(`retail-print-kit: EZPL has no ${t.type}`);let a=t.module??2;return`B${i},${e},${n},${a},${a*2},${Math.round(t.height)},${r/90},${t.text===!1?0:1},${t.data}`}case"qr":{let i={L:"L",M:"M",Q:"Q",H:"H"}[t.correction??"M"];return`W${e},${n},5,2,${i},${t.module??4},${r/90},${t.data.length}
|
|
18
|
+
${t.data}`}case"box":return`R${e},${n},${e+Math.round(t.width)},${n+Math.round(t.height)},${t.thickness??2},${t.thickness??2}`;case"rect":return`R${e},${n},${e+Math.round(t.width)},${n+Math.round(t.height)},${Math.round(t.width)},${Math.round(t.height)}`;case"image":throw new Error("retail-print-kit: EZPL images are not implemented yet")}}function $t(t){let e=[`^Q${J(t.height,t.dpi).toFixed(2)},${t.gap.toFixed(0)}`,`^W${J(t.width,t.dpi).toFixed(2)}`,`^H${t.darkness??10}`,`^P${t.copies}`,`^S${t.speed??2}`,"^AD","^C1","^R0","~Q+0","^O0","^D0","^E18","~R255","^L"];for(let n of t.ops)e.push(Ge(n));return e.push("E"),e.join(`
|
|
24
19
|
`)+`
|
|
25
|
-
`}var
|
|
20
|
+
`}var V=class{constructor(e){let n=e.dpi??203;this.label={width:ot(e.widthMm,n),height:ot(e.heightMm,n),dpi:n,gap:e.gapMm??3,copies:1,ops:[]}}mm(e){return ot(e,this.label.dpi)}copies(e){return this.label.copies=Math.max(1,Math.floor(e)),this}darkness(e){return this.label.darkness=e,this}speed(e){return this.label.speed=e,this}push(e){return this.label.ops.push(e),this}text(e,n,r,i,a={}){return this.push({kind:"text",x:e,y:n,text:r,height:i,...a})}barcode(e,n,r,i,a,s={}){return this.push({kind:"barcode",x:e,y:n,data:r,type:i,height:a,...s})}qr(e,n,r,i={}){return this.push({kind:"qr",x:e,y:n,data:r,...i})}box(e,n,r,i,a=2){return this.push({kind:"box",x:e,y:n,width:r,height:i,thickness:a})}rect(e,n,r,i){return this.push({kind:"rect",x:e,y:n,width:r,height:i})}image(e,n,r){return this.push({kind:"image",x:e,y:n,bitmap:r})}};function jt(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function At(t){return t.rotation?` transform="rotate(${t.rotation} ${t.x} ${t.y})"`:""}function Bt(t){return`data:image/png;base64,${U(F(t))}`}function He(t){switch(t.kind){case"text":{let e=t.width??t.height*.9,n=t.text.length*e*.62;return`${t.invert?`<rect x="${t.x}" y="${t.y}" width="${n}" height="${t.height}" fill="#000"/>`:""}<text x="${t.x}" y="${t.y+t.height*.82}" font-size="${t.height}" textLength="${n}" lengthAdjust="spacingAndGlyphs" font-family="Helvetica, Arial, sans-serif"${t.bold?' font-weight="bold"':""} fill="${t.invert?"#fff":"#000"}"${At(t)}>${jt(t.text)}</text>`}case"barcode":{let e=et(t.type,t.data,t.module??2,Math.round(t.height)),n=t.text===!1?"":`<text x="${t.x+e.width/2}" y="${t.y+t.height+14}" font-size="14" text-anchor="middle" font-family="Helvetica, Arial, sans-serif">${jt(t.data)}</text>`;return`<image x="${t.x}" y="${t.y}" width="${e.width}" height="${e.height}" href="${Bt(e)}" style="image-rendering:pixelated"${At(t)}/>${n}`}case"qr":{let e=j(t.data,{size:t.module??4,correction:t.correction});return`<image x="${t.x}" y="${t.y}" width="${e.width}" height="${e.height}" href="${Bt(e)}" style="image-rendering:pixelated"${At(t)}/>`}case"box":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="none" stroke="#000" stroke-width="${t.thickness??2}"/>`;case"rect":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" fill="#000"/>`;case"image":return`<image x="${t.x}" y="${t.y}" width="${t.bitmap.width}" height="${t.bitmap.height}" href="${Bt(t.bitmap)}" style="image-rendering:pixelated"/>`}}function Qe(t){let e=t.ops.map(He).join("");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${t.width} ${t.height}" width="${t.width}" height="${t.height}"><rect width="${t.width}" height="${t.height}" fill="#fff"/>${e}</svg>`}function qe(t,e){if(t.version!==1||t.kind!=="label")throw new Error("retail-print-kit: not a version 1 label template");let n=new V({widthMm:t.widthMm,heightMm:t.heightMm,dpi:t.dpi,gapMm:t.gapMm}),r={root:e,current:e};for(let i of t.elements)if(!(i.when&&!K(i.when,r)))switch(i.type){case"text":n.text(i.x,i.y,D(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,D(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,D(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 or(t,e){switch(e){case"zpl":return new TextEncoder().encode(bt(t));case"ezpl":return new TextEncoder().encode($t(t));case"tspl":return wt(t)}}export{V as LabelBuilder,tt as OpBuilder,et as barcodeBitmap,F as bitmapToPng,ie as blit,me as code128,Ae as code39,Pt as deserializeBitmap,tn as ditherRgba,J as dotsToMm,_t as ean13,ye as ean8,Q as emptyBitmap,$t as encodeEzpl,or as encodeLabel,wt as encodeTspl,bt as encodeZpl,St as epsonTmM30,vt as epsonTmT20,Rt as epsonTmT88,z as evaluate,Ht as filters,Ve as fitWidth,at as fromBase64,Je as fromRgba,lt as genericEscPos,Nt as genericEscPos58,ut as getPixel,D as interpolate,Qe as labelToSvg,Qt as lookup,ot as mmToDots,Oe as opsToHtml,se as parseStyle,Be as pattern,dn as profileById,Me as profiles,j as qrBitmap,Ee as render,W as renderBlocks,qe as renderLabel,en as serializeBitmap,q as setPixel,Ut as starMcPrint3,Ft as starTsp100,It as starTsp650,U as toBase64,K as truthy,we as upcA};
|
package/dist/core/bitmap.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.qrBitmap = qrBitmap;
|
|
|
13
13
|
exports.ditherRgba = ditherRgba;
|
|
14
14
|
exports.serializeBitmap = serializeBitmap;
|
|
15
15
|
exports.deserializeBitmap = deserializeBitmap;
|
|
16
|
-
const
|
|
16
|
+
const qrcode_generator_1 = __importDefault(require("qrcode-generator"));
|
|
17
17
|
const base64_1 = require("../util/base64");
|
|
18
18
|
function emptyBitmap(width, height) {
|
|
19
19
|
return { width, height, bits: new Uint8Array(Math.ceil(width / 8) * height) };
|
|
@@ -67,13 +67,19 @@ function fitWidth(src, width, align = 'center') {
|
|
|
67
67
|
}
|
|
68
68
|
/** QR code as a bitmap, each module `options.size` dots square (default 6, like Epson cell size). */
|
|
69
69
|
function qrBitmap(data, options = {}) {
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const utf8 = new TextEncoder().encode(data);
|
|
71
|
+
let bytes = '';
|
|
72
|
+
for (let i = 0; i < utf8.length; i++)
|
|
73
|
+
bytes += String.fromCharCode(utf8[i]);
|
|
74
|
+
const qr = (0, qrcode_generator_1.default)(0, options.correction ?? 'M');
|
|
75
|
+
qr.addData(bytes, 'Byte');
|
|
76
|
+
qr.make();
|
|
77
|
+
const n = qr.getModuleCount();
|
|
72
78
|
const scale = Math.max(1, Math.min(16, Math.floor(options.size ?? 6)));
|
|
73
79
|
const b = emptyBitmap(n * scale, n * scale);
|
|
74
80
|
for (let y = 0; y < n; y++) {
|
|
75
81
|
for (let x = 0; x < n; x++) {
|
|
76
|
-
if (!qr.
|
|
82
|
+
if (!qr.isDark(y, x))
|
|
77
83
|
continue;
|
|
78
84
|
for (let dy = 0; dy < scale; dy++)
|
|
79
85
|
for (let dx = 0; dx < scale; dx++)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retail-print-kit",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "ESC/POS thermal receipt printer, cash drawer and label printer (ZPL, TSPL, EZPL) library for Node.js and Electron. Epson, Star TSP100 and compatibles over USB, network or serial, with templates, previews, a visual designer and a CLI.",
|
|
5
5
|
"author": "Arkaprova Majumder <arka162@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"dist",
|
|
38
38
|
"bin",
|
|
39
39
|
"README.md",
|
|
40
|
-
"LICENSE"
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"CHANGELOG.md"
|
|
41
42
|
],
|
|
42
43
|
"engines": {
|
|
43
44
|
"node": ">=18"
|
|
@@ -47,11 +48,12 @@
|
|
|
47
48
|
"test": "npm run build && node --test test/run.js",
|
|
48
49
|
"clean": "rm -rf dist",
|
|
49
50
|
"build:browser": "esbuild src/browser.ts --bundle --format=iife --global-name=RetailPrintKit --platform=browser --external:zlib --outfile=dist/browser/retail-print-kit.js --minify --sourcemap && esbuild src/browser.ts --bundle --format=esm --platform=browser --external:zlib --outfile=dist/browser/retail-print-kit.mjs --minify",
|
|
50
|
-
"prepublishOnly": "npm test"
|
|
51
|
+
"prepublishOnly": "npm test",
|
|
52
|
+
"build:site": "node scripts/build-site.js"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"iconv-lite": "^0.6.3",
|
|
54
|
-
"qrcode": "^
|
|
56
|
+
"qrcode-generator": "^2.0.4"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
57
59
|
"@napi-rs/canvas": ">=0.1",
|
|
@@ -59,6 +61,9 @@
|
|
|
59
61
|
"usb": ">=2"
|
|
60
62
|
},
|
|
61
63
|
"peerDependenciesMeta": {
|
|
64
|
+
"@napi-rs/canvas": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
62
67
|
"serialport": {
|
|
63
68
|
"optional": true
|
|
64
69
|
},
|
|
@@ -69,7 +74,6 @@
|
|
|
69
74
|
"devDependencies": {
|
|
70
75
|
"@napi-rs/canvas": "^0.1.100",
|
|
71
76
|
"@types/node": "^18.19.0",
|
|
72
|
-
"@types/qrcode": "^1.5.6",
|
|
73
77
|
"esbuild": "^0.23.1",
|
|
74
78
|
"serialport": "^12.0.0",
|
|
75
79
|
"typescript": "^5.4.0",
|