retail-print-kit 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +209 -2
- package/bin/retail-print-kit.js +318 -0
- package/dist/browser/retail-print-kit.js +26 -0
- package/dist/browser/retail-print-kit.js.map +7 -0
- package/dist/browser/retail-print-kit.mjs +25 -0
- package/dist/browser.d.ts +15 -0
- package/dist/browser.js +35 -0
- package/dist/core/barcode1d.d.ts +12 -0
- package/dist/core/barcode1d.js +192 -0
- package/dist/core/bitmap.d.ts +31 -0
- package/dist/core/bitmap.js +126 -0
- package/dist/core/builder.d.ts +58 -0
- package/dist/core/builder.js +177 -0
- package/dist/core/encode.d.ts +8 -0
- package/dist/core/encode.js +17 -0
- package/dist/core/escpos-encoder.d.ts +4 -0
- package/dist/core/escpos-encoder.js +150 -0
- package/dist/core/identify.d.ts +22 -0
- package/dist/core/identify.js +71 -0
- package/dist/core/image.d.ts +13 -0
- package/dist/core/image.js +32 -0
- package/dist/core/ops.d.ts +78 -0
- package/dist/core/ops.js +2 -0
- package/dist/core/printer.d.ts +35 -0
- package/dist/core/printer.js +96 -0
- package/dist/core/rasterizer.d.ts +29 -0
- package/dist/core/rasterizer.js +199 -0
- package/dist/core/star-graphic-encoder.d.ts +12 -0
- package/dist/core/star-graphic-encoder.js +48 -0
- package/dist/core/star-line-encoder.d.ts +8 -0
- package/dist/core/star-line-encoder.js +119 -0
- package/dist/core/status.d.ts +22 -0
- package/dist/core/status.js +52 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +49 -0
- package/dist/label/builder.d.ts +39 -0
- package/dist/label/builder.js +37 -0
- package/dist/label/ezpl.d.ts +6 -0
- package/dist/label/ezpl.js +78 -0
- package/dist/label/index.d.ts +12 -0
- package/dist/label/index.js +42 -0
- package/dist/label/svg.d.ts +3 -0
- package/dist/label/svg.js +46 -0
- package/dist/label/template.d.ts +61 -0
- package/dist/label/template.js +33 -0
- package/dist/label/tspl.d.ts +3 -0
- package/dist/label/tspl.js +83 -0
- package/dist/label/types.d.ts +69 -0
- package/dist/label/types.js +10 -0
- package/dist/label/zpl.d.ts +3 -0
- package/dist/label/zpl.js +57 -0
- package/dist/preview/html.d.ts +14 -0
- package/dist/preview/html.js +132 -0
- package/dist/preview/index.d.ts +8 -0
- package/dist/preview/index.js +14 -0
- package/dist/preview/png.d.ts +3 -0
- package/dist/preview/png.js +89 -0
- package/dist/profiles/epson.d.ts +10 -0
- package/dist/profiles/epson.js +54 -0
- package/dist/profiles/index.d.ts +7 -0
- package/dist/profiles/index.js +36 -0
- package/dist/profiles/star.d.ts +7 -0
- package/dist/profiles/star.js +39 -0
- package/dist/profiles/types.d.ts +41 -0
- package/dist/profiles/types.js +2 -0
- package/dist/template/expr.d.ts +16 -0
- package/dist/template/expr.js +85 -0
- package/dist/template/index.d.ts +4 -0
- package/dist/template/index.js +27 -0
- package/dist/template/render.d.ts +8 -0
- package/dist/template/render.js +119 -0
- package/dist/template/types.d.ts +81 -0
- package/dist/template/types.js +2 -0
- package/dist/transports/discover.d.ts +21 -0
- package/dist/transports/discover.js +73 -0
- package/dist/transports/net.d.ts +20 -0
- package/dist/transports/net.js +72 -0
- package/dist/transports/serial.d.ts +20 -0
- package/dist/transports/serial.js +71 -0
- package/dist/transports/types.d.ts +16 -0
- package/dist/transports/types.js +41 -0
- package/dist/transports/usb.d.ts +30 -0
- package/dist/transports/usb.js +128 -0
- package/dist/util/base64.d.ts +2 -0
- package/dist/util/base64.js +38 -0
- package/package.json +133 -4
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
+
Minimum version required to store current data is: `+o+`.
|
|
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>
|
|
12
|
+
body{background:#777;margin:0;padding:16px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:${r*1.6}px;line-height:1.25}
|
|
13
|
+
.paper{background:#fff;color:#000;padding:12px ${r}px;margin:0 auto;box-shadow:0 2px 8px rgba(0,0,0,.4);box-sizing:content-box}
|
|
14
|
+
.l{white-space:pre;overflow:hidden;min-height:1.25em}
|
|
15
|
+
.cut{border-top:2px dashed #999;margin:6px -${r}px}
|
|
16
|
+
.note{color:#999;font-size:.7em;text-align:center}
|
|
17
|
+
img{image-rendering:pixelated;vertical-align:top}
|
|
18
|
+
</style></head><body>${g}</body></html>`}var 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
|
+
`)+`
|
|
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
|
+
`)+`
|
|
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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}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};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry: everything that needs no Node APIs and no printer. Receipt templates, HTML
|
|
3
|
+
* preview, label templates, label encoders and the SVG label preview, for designers and web apps.
|
|
4
|
+
*/
|
|
5
|
+
export * from './core/ops';
|
|
6
|
+
export * from './core/builder';
|
|
7
|
+
export * from './core/bitmap';
|
|
8
|
+
export * from './core/barcode1d';
|
|
9
|
+
export * from './profiles';
|
|
10
|
+
export * from './template';
|
|
11
|
+
export { opsToHtml } from './preview/html';
|
|
12
|
+
export type { HtmlPreviewOptions } from './preview/html';
|
|
13
|
+
export { bitmapToPng } from './preview/png';
|
|
14
|
+
export * from './label';
|
|
15
|
+
export { toBase64, fromBase64 } from './util/base64';
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.fromBase64 = exports.toBase64 = exports.bitmapToPng = exports.opsToHtml = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* Browser entry: everything that needs no Node APIs and no printer. Receipt templates, HTML
|
|
20
|
+
* preview, label templates, label encoders and the SVG label preview, for designers and web apps.
|
|
21
|
+
*/
|
|
22
|
+
__exportStar(require("./core/ops"), exports);
|
|
23
|
+
__exportStar(require("./core/builder"), exports);
|
|
24
|
+
__exportStar(require("./core/bitmap"), exports);
|
|
25
|
+
__exportStar(require("./core/barcode1d"), exports);
|
|
26
|
+
__exportStar(require("./profiles"), exports);
|
|
27
|
+
__exportStar(require("./template"), exports);
|
|
28
|
+
var html_1 = require("./preview/html");
|
|
29
|
+
Object.defineProperty(exports, "opsToHtml", { enumerable: true, get: function () { return html_1.opsToHtml; } });
|
|
30
|
+
var png_1 = require("./preview/png");
|
|
31
|
+
Object.defineProperty(exports, "bitmapToPng", { enumerable: true, get: function () { return png_1.bitmapToPng; } });
|
|
32
|
+
__exportStar(require("./label"), exports);
|
|
33
|
+
var base64_1 = require("./util/base64");
|
|
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; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BarcodeType } from './ops';
|
|
2
|
+
import { Bitmap } from './bitmap';
|
|
3
|
+
/** Bar/space run lengths for one symbol, starting with a bar. */
|
|
4
|
+
export type Pattern = number[];
|
|
5
|
+
export declare function code128(data: string): Pattern;
|
|
6
|
+
export declare function ean13(data: string): Pattern;
|
|
7
|
+
export declare function upcA(data: string): Pattern;
|
|
8
|
+
export declare function ean8(data: string): Pattern;
|
|
9
|
+
export declare function code39(data: string): Pattern;
|
|
10
|
+
export declare function pattern(type: BarcodeType, data: string): Pattern;
|
|
11
|
+
/** Bitmap of a 1D barcode: `module` dots per narrow bar, `height` dots, 10-module quiet zones. */
|
|
12
|
+
export declare function barcodeBitmap(type: BarcodeType, data: string, module?: number, height?: number): Bitmap;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.code128 = code128;
|
|
4
|
+
exports.ean13 = ean13;
|
|
5
|
+
exports.upcA = upcA;
|
|
6
|
+
exports.ean8 = ean8;
|
|
7
|
+
exports.code39 = code39;
|
|
8
|
+
exports.pattern = pattern;
|
|
9
|
+
exports.barcodeBitmap = barcodeBitmap;
|
|
10
|
+
const bitmap_1 = require("./bitmap");
|
|
11
|
+
const CODE128 = [
|
|
12
|
+
'212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213',
|
|
13
|
+
'221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132',
|
|
14
|
+
'221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211',
|
|
15
|
+
'212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313',
|
|
16
|
+
'231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331',
|
|
17
|
+
'231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111',
|
|
18
|
+
'314111', '221411', '431111', '111224', '111422', '121124', '121421', '141122', '141221', '112214',
|
|
19
|
+
'112412', '122114', '122411', '142112', '142211', '241211', '221114', '413111', '241112', '134111',
|
|
20
|
+
'111242', '121142', '121241', '114212', '124112', '124211', '411212', '421112', '421211', '212141',
|
|
21
|
+
'214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141',
|
|
22
|
+
'114131', '311141', '411131', '211412', '211214', '211232', '2331112',
|
|
23
|
+
];
|
|
24
|
+
const C128_START_B = 104;
|
|
25
|
+
const C128_START_C = 105;
|
|
26
|
+
const C128_CODE_B = 100;
|
|
27
|
+
const C128_CODE_C = 99;
|
|
28
|
+
const C128_STOP = 106;
|
|
29
|
+
function code128(data) {
|
|
30
|
+
if (!/^[\x20-\x7e]*$/.test(data) || !data.length)
|
|
31
|
+
throw new Error('retail-print-kit: CODE128 needs printable ASCII');
|
|
32
|
+
const codes = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
let subset = null;
|
|
35
|
+
const digitsAhead = (from) => {
|
|
36
|
+
let n = 0;
|
|
37
|
+
while (from + n < data.length && /[0-9]/.test(data[from + n]))
|
|
38
|
+
n++;
|
|
39
|
+
return n;
|
|
40
|
+
};
|
|
41
|
+
while (i < data.length) {
|
|
42
|
+
const run = digitsAhead(i);
|
|
43
|
+
const useC = run >= 4 || (run >= 2 && run === data.length - i);
|
|
44
|
+
if (useC) {
|
|
45
|
+
if (subset !== 'C') {
|
|
46
|
+
codes.push(subset === null ? C128_START_C : C128_CODE_C);
|
|
47
|
+
subset = 'C';
|
|
48
|
+
}
|
|
49
|
+
const pairs = Math.floor(run / 2);
|
|
50
|
+
for (let k = 0; k < pairs; k++) {
|
|
51
|
+
codes.push(parseInt(data.slice(i, i + 2), 10));
|
|
52
|
+
i += 2;
|
|
53
|
+
}
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (subset !== 'B') {
|
|
57
|
+
codes.push(subset === null ? C128_START_B : C128_CODE_B);
|
|
58
|
+
subset = 'B';
|
|
59
|
+
}
|
|
60
|
+
codes.push(data.charCodeAt(i) - 32);
|
|
61
|
+
i++;
|
|
62
|
+
}
|
|
63
|
+
let check = codes[0];
|
|
64
|
+
for (let k = 1; k < codes.length; k++)
|
|
65
|
+
check += codes[k] * k;
|
|
66
|
+
codes.push(check % 103, C128_STOP);
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const c of codes)
|
|
69
|
+
for (const ch of CODE128[c])
|
|
70
|
+
out.push(Number(ch));
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
const EAN_L = ['0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'];
|
|
74
|
+
const EAN_G = ['0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111'];
|
|
75
|
+
const EAN_R = ['1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100'];
|
|
76
|
+
const EAN13_PARITY = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL'];
|
|
77
|
+
function eanChecksum(digits) {
|
|
78
|
+
let sum = 0;
|
|
79
|
+
for (let i = 0; i < digits.length; i++) {
|
|
80
|
+
const weight = (digits.length - i) % 2 === 0 ? 1 : 3;
|
|
81
|
+
sum += Number(digits[i]) * weight;
|
|
82
|
+
}
|
|
83
|
+
return (10 - (sum % 10)) % 10;
|
|
84
|
+
}
|
|
85
|
+
function bitsToPattern(bits) {
|
|
86
|
+
const out = [];
|
|
87
|
+
let cur = '1';
|
|
88
|
+
let run = 0;
|
|
89
|
+
if (bits[0] !== '1')
|
|
90
|
+
out.push(0);
|
|
91
|
+
for (const b of bits) {
|
|
92
|
+
if (b === cur)
|
|
93
|
+
run++;
|
|
94
|
+
else {
|
|
95
|
+
out.push(run);
|
|
96
|
+
cur = b;
|
|
97
|
+
run = 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
out.push(run);
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function ean13(data) {
|
|
104
|
+
let d = data.replace(/\D/g, '');
|
|
105
|
+
if (d.length === 12)
|
|
106
|
+
d += eanChecksum(d);
|
|
107
|
+
if (d.length !== 13)
|
|
108
|
+
throw new Error('retail-print-kit: EAN13 needs 12 or 13 digits');
|
|
109
|
+
const parity = EAN13_PARITY[Number(d[0])];
|
|
110
|
+
let bits = '101';
|
|
111
|
+
for (let i = 1; i <= 6; i++)
|
|
112
|
+
bits += (parity[i - 1] === 'L' ? EAN_L : EAN_G)[Number(d[i])];
|
|
113
|
+
bits += '01010';
|
|
114
|
+
for (let i = 7; i <= 12; i++)
|
|
115
|
+
bits += EAN_R[Number(d[i])];
|
|
116
|
+
bits += '101';
|
|
117
|
+
return bitsToPattern(bits);
|
|
118
|
+
}
|
|
119
|
+
function upcA(data) {
|
|
120
|
+
let d = data.replace(/\D/g, '');
|
|
121
|
+
if (d.length === 11)
|
|
122
|
+
d += eanChecksum(d);
|
|
123
|
+
if (d.length !== 12)
|
|
124
|
+
throw new Error('retail-print-kit: UPC-A needs 11 or 12 digits');
|
|
125
|
+
return ean13('0' + d);
|
|
126
|
+
}
|
|
127
|
+
function ean8(data) {
|
|
128
|
+
let d = data.replace(/\D/g, '');
|
|
129
|
+
if (d.length === 7)
|
|
130
|
+
d += eanChecksum(d);
|
|
131
|
+
if (d.length !== 8)
|
|
132
|
+
throw new Error('retail-print-kit: EAN8 needs 7 or 8 digits');
|
|
133
|
+
let bits = '101';
|
|
134
|
+
for (let i = 0; i < 4; i++)
|
|
135
|
+
bits += EAN_L[Number(d[i])];
|
|
136
|
+
bits += '01010';
|
|
137
|
+
for (let i = 4; i < 8; i++)
|
|
138
|
+
bits += EAN_R[Number(d[i])];
|
|
139
|
+
bits += '101';
|
|
140
|
+
return bitsToPattern(bits);
|
|
141
|
+
}
|
|
142
|
+
const CODE39 = {
|
|
143
|
+
'0': '101001101101', '1': '110100101011', '2': '101100101011', '3': '110110010101', '4': '101001101011',
|
|
144
|
+
'5': '110100110101', '6': '101100110101', '7': '101001011011', '8': '110100101101', '9': '101100101101',
|
|
145
|
+
A: '110101001011', B: '101101001011', C: '110110100101', D: '101011001011', E: '110101100101',
|
|
146
|
+
F: '101101100101', G: '101010011011', H: '110101001101', I: '101101001101', J: '101011001101',
|
|
147
|
+
K: '110101010011', L: '101101010011', M: '110110101001', N: '101011010011', O: '110101101001',
|
|
148
|
+
P: '101101101001', Q: '101010110011', R: '110101011001', S: '101101011001', T: '101011011001',
|
|
149
|
+
U: '110010101011', V: '100110101011', W: '110011010101', X: '100101101011', Y: '110010110101',
|
|
150
|
+
Z: '100110110101', '-': '100101011011', '.': '110010101101', ' ': '100110101101', '$': '100100100101',
|
|
151
|
+
'/': '100100101001', '+': '100101001001', '%': '101001001001', '*': '100101101101',
|
|
152
|
+
};
|
|
153
|
+
function code39(data) {
|
|
154
|
+
const text = `*${data.toUpperCase()}*`;
|
|
155
|
+
let bits = '';
|
|
156
|
+
for (const ch of text) {
|
|
157
|
+
const p = CODE39[ch];
|
|
158
|
+
if (!p)
|
|
159
|
+
throw new Error(`retail-print-kit: CODE39 cannot encode "${ch}"`);
|
|
160
|
+
bits += p + '0';
|
|
161
|
+
}
|
|
162
|
+
return bitsToPattern(bits.slice(0, -1));
|
|
163
|
+
}
|
|
164
|
+
function pattern(type, data) {
|
|
165
|
+
switch (type) {
|
|
166
|
+
case 'CODE128': return code128(data);
|
|
167
|
+
case 'EAN13': return ean13(data);
|
|
168
|
+
case 'UPC_A': return upcA(data);
|
|
169
|
+
case 'EAN8': return ean8(data);
|
|
170
|
+
case 'CODE39': return code39(data);
|
|
171
|
+
default:
|
|
172
|
+
throw new Error(`retail-print-kit: bitmap rendering of ${type} is not implemented`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Bitmap of a 1D barcode: `module` dots per narrow bar, `height` dots, 10-module quiet zones. */
|
|
176
|
+
function barcodeBitmap(type, data, module = 2, height = 80) {
|
|
177
|
+
const p = pattern(type, data);
|
|
178
|
+
const quiet = 10 * module;
|
|
179
|
+
const width = p.reduce((a, b) => a + b, 0) * module + quiet * 2;
|
|
180
|
+
const b = (0, bitmap_1.emptyBitmap)(width, height);
|
|
181
|
+
let x = quiet;
|
|
182
|
+
let bar = true;
|
|
183
|
+
for (const run of p) {
|
|
184
|
+
if (bar)
|
|
185
|
+
for (let dx = 0; dx < run * module; dx++)
|
|
186
|
+
for (let y = 0; y < height; y++)
|
|
187
|
+
(0, bitmap_1.setPixel)(b, x + dx, y, true);
|
|
188
|
+
x += run * module;
|
|
189
|
+
bar = !bar;
|
|
190
|
+
}
|
|
191
|
+
return b;
|
|
192
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { QrOptions } from './ops';
|
|
2
|
+
/** 1-bit image, rows packed MSB first, 1 = black. `bits.length === ceil(width/8) * height`. */
|
|
3
|
+
export interface Bitmap {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
bits: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare function emptyBitmap(width: number, height: number): Bitmap;
|
|
9
|
+
export declare function setPixel(b: Bitmap, x: number, y: number, black: boolean): void;
|
|
10
|
+
export declare function getPixel(b: Bitmap, x: number, y: number): boolean;
|
|
11
|
+
/** RGBA pixels (as from canvas getImageData) to 1-bit by luminance threshold. */
|
|
12
|
+
export declare function fromRgba(data: Uint8ClampedArray | Uint8Array, width: number, height: number, threshold?: number): Bitmap;
|
|
13
|
+
/** Draws `src` into `dst` at (x, y); pixels outside `dst` are dropped. */
|
|
14
|
+
export declare function blit(dst: Bitmap, src: Bitmap, x: number, y: number): void;
|
|
15
|
+
/** Pads or crops to `width` dots, aligning the content left, center or right. */
|
|
16
|
+
export declare function fitWidth(src: Bitmap, width: number, align?: 'left' | 'center' | 'right'): Bitmap;
|
|
17
|
+
/** QR code as a bitmap, each module `options.size` dots square (default 6, like Epson cell size). */
|
|
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;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.emptyBitmap = emptyBitmap;
|
|
7
|
+
exports.setPixel = setPixel;
|
|
8
|
+
exports.getPixel = getPixel;
|
|
9
|
+
exports.fromRgba = fromRgba;
|
|
10
|
+
exports.blit = blit;
|
|
11
|
+
exports.fitWidth = fitWidth;
|
|
12
|
+
exports.qrBitmap = qrBitmap;
|
|
13
|
+
exports.ditherRgba = ditherRgba;
|
|
14
|
+
exports.serializeBitmap = serializeBitmap;
|
|
15
|
+
exports.deserializeBitmap = deserializeBitmap;
|
|
16
|
+
const qrcode_1 = __importDefault(require("qrcode"));
|
|
17
|
+
const base64_1 = require("../util/base64");
|
|
18
|
+
function emptyBitmap(width, height) {
|
|
19
|
+
return { width, height, bits: new Uint8Array(Math.ceil(width / 8) * height) };
|
|
20
|
+
}
|
|
21
|
+
function setPixel(b, x, y, black) {
|
|
22
|
+
if (x < 0 || y < 0 || x >= b.width || y >= b.height)
|
|
23
|
+
return;
|
|
24
|
+
const i = y * Math.ceil(b.width / 8) + (x >> 3);
|
|
25
|
+
const mask = 0x80 >> (x & 7);
|
|
26
|
+
if (black)
|
|
27
|
+
b.bits[i] |= mask;
|
|
28
|
+
else
|
|
29
|
+
b.bits[i] &= ~mask;
|
|
30
|
+
}
|
|
31
|
+
function getPixel(b, x, y) {
|
|
32
|
+
if (x < 0 || y < 0 || x >= b.width || y >= b.height)
|
|
33
|
+
return false;
|
|
34
|
+
return (b.bits[y * Math.ceil(b.width / 8) + (x >> 3)] & (0x80 >> (x & 7))) !== 0;
|
|
35
|
+
}
|
|
36
|
+
/** RGBA pixels (as from canvas getImageData) to 1-bit by luminance threshold. */
|
|
37
|
+
function fromRgba(data, width, height, threshold = 128) {
|
|
38
|
+
const b = emptyBitmap(width, height);
|
|
39
|
+
for (let y = 0; y < height; y++) {
|
|
40
|
+
for (let x = 0; x < width; x++) {
|
|
41
|
+
const i = (y * width + x) * 4;
|
|
42
|
+
const a = data[i + 3] / 255;
|
|
43
|
+
const lum = (0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2]) * a + 255 * (1 - a);
|
|
44
|
+
if (lum < threshold)
|
|
45
|
+
setPixel(b, x, y, true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return b;
|
|
49
|
+
}
|
|
50
|
+
/** Draws `src` into `dst` at (x, y); pixels outside `dst` are dropped. */
|
|
51
|
+
function blit(dst, src, x, y) {
|
|
52
|
+
for (let sy = 0; sy < src.height; sy++) {
|
|
53
|
+
for (let sx = 0; sx < src.width; sx++) {
|
|
54
|
+
if (getPixel(src, sx, sy))
|
|
55
|
+
setPixel(dst, x + sx, y + sy, true);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Pads or crops to `width` dots, aligning the content left, center or right. */
|
|
60
|
+
function fitWidth(src, width, align = 'center') {
|
|
61
|
+
if (src.width === width)
|
|
62
|
+
return src;
|
|
63
|
+
const out = emptyBitmap(width, src.height);
|
|
64
|
+
const x = align === 'left' ? 0 : align === 'right' ? width - src.width : Math.floor((width - src.width) / 2);
|
|
65
|
+
blit(out, src, x, 0);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
/** QR code as a bitmap, each module `options.size` dots square (default 6, like Epson cell size). */
|
|
69
|
+
function qrBitmap(data, options = {}) {
|
|
70
|
+
const qr = qrcode_1.default.create(data, { errorCorrectionLevel: options.correction ?? 'M' });
|
|
71
|
+
const n = qr.modules.size;
|
|
72
|
+
const scale = Math.max(1, Math.min(16, Math.floor(options.size ?? 6)));
|
|
73
|
+
const b = emptyBitmap(n * scale, n * scale);
|
|
74
|
+
for (let y = 0; y < n; y++) {
|
|
75
|
+
for (let x = 0; x < n; x++) {
|
|
76
|
+
if (!qr.modules.get(y, x))
|
|
77
|
+
continue;
|
|
78
|
+
for (let dy = 0; dy < scale; dy++)
|
|
79
|
+
for (let dx = 0; dx < scale; dx++)
|
|
80
|
+
setPixel(b, x * scale + dx, y * scale + dy, true);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return b;
|
|
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,58 @@
|
|
|
1
|
+
import { Op, Align, Font, BarcodeType, BarcodeOptions, QrOptions, StyleFlags } from './ops';
|
|
2
|
+
import { Profile } from '../profiles/types';
|
|
3
|
+
import { Bitmap } from './bitmap';
|
|
4
|
+
export type EscposAlign = 'lt' | 'ct' | 'rt' | Align;
|
|
5
|
+
export type EscposStyle = 'normal' | 'b' | 'i' | 'u' | 'u2' | 'bi' | 'biu' | 'biu2' | 'bu' | 'bu2' | 'iu' | 'iu2';
|
|
6
|
+
export interface TableCell {
|
|
7
|
+
text: string;
|
|
8
|
+
align?: 'LEFT' | 'CENTER' | 'RIGHT';
|
|
9
|
+
/** Fraction of the line (0..1) or an absolute column count when > 1. */
|
|
10
|
+
width?: number;
|
|
11
|
+
style?: EscposStyle;
|
|
12
|
+
size?: [number, number];
|
|
13
|
+
}
|
|
14
|
+
export interface TableOptions {
|
|
15
|
+
/** Line width in columns; defaults to the profile's columns for the current font. */
|
|
16
|
+
width?: number;
|
|
17
|
+
/** When false, long cells are cut instead of wrapped. Default true. */
|
|
18
|
+
wrap?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Records print operations. Method names match the `escpos` package so a host can swap the
|
|
22
|
+
* device without rewriting its receipt code. Nothing is sent from here; see `Printer`.
|
|
23
|
+
*/
|
|
24
|
+
export declare class OpBuilder {
|
|
25
|
+
readonly profile: Profile;
|
|
26
|
+
protected ops: Op[];
|
|
27
|
+
protected font: Font;
|
|
28
|
+
constructor(profile: Profile);
|
|
29
|
+
/** A copy of the recorded ops. */
|
|
30
|
+
get operations(): Op[];
|
|
31
|
+
append(ops: Op[]): this;
|
|
32
|
+
get columns(): number;
|
|
33
|
+
push(op: Op): this;
|
|
34
|
+
raw(bytes: Uint8Array | number[]): this;
|
|
35
|
+
text(content: string): this;
|
|
36
|
+
/** Text without a trailing line break. */
|
|
37
|
+
print(content: string): this;
|
|
38
|
+
newLine(count?: number): this;
|
|
39
|
+
feed(lines?: number): this;
|
|
40
|
+
align(align: EscposAlign): this;
|
|
41
|
+
setFont(font: Font): this;
|
|
42
|
+
size(width: number, height: number): this;
|
|
43
|
+
style(style: EscposStyle | StyleFlags): this;
|
|
44
|
+
lineSpace(dots?: number | null): this;
|
|
45
|
+
cut(partial?: boolean, feed?: number): this;
|
|
46
|
+
cashdraw(pin?: 2 | 5): this;
|
|
47
|
+
beep(times?: number, duration?: number): this;
|
|
48
|
+
barcode(data: string, type?: BarcodeType, options?: BarcodeOptions): this;
|
|
49
|
+
/** Native QR where the printer has one, otherwise a bitmap QR. */
|
|
50
|
+
qr(data: string, options?: QrOptions): this;
|
|
51
|
+
image(bitmap: Bitmap): this;
|
|
52
|
+
/** `escpos` name for a QR code; prints a native QR when the profile has one. */
|
|
53
|
+
qrimage(data: string, options?: QrOptions): this;
|
|
54
|
+
drawLine(char?: string): this;
|
|
55
|
+
tableCustom(cells: TableCell[], options?: TableOptions): this;
|
|
56
|
+
}
|
|
57
|
+
/** `escpos` style letters: b bold, i italic, u underline, u2 double underline. */
|
|
58
|
+
export declare function parseStyle(style: EscposStyle): StyleFlags;
|