electron-pos-printer
Version:
Electron printer plugin for 80mm, 78mm, 76mm, 58mm, 57mm, 44mm printers
1 lines • 6.56 kB
JavaScript
(()=>{"use strict";var e={289:e=>{e.exports=require("jsbarcode")},482:e=>{e.exports=require("electron")},634:e=>{e.exports=require("qrcode")}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var l=t[r]={exports:{}};return e[r](l,l.exports,n),l.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const r=require("fs");var i=n.n(r);const l=require("path");var o=n.n(l),d=function(e,t,n,r){return new(n||(n=Promise))(function(i,l){function o(e){try{a(r.next(e))}catch(e){l(e)}}function d(e){try{a(r.throw(e))}catch(e){l(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,d)}a((r=r.apply(e,t||[])).next())})};const a=n(634);function s(e,t="td"){const n=e.value;let r;return r=document.createElement(t),r.innerHTML=n,r=u(r,Object.assign({padding:"7px 2px"},e.style)),r}function c(e){return new Promise((t,n)=>d(this,void 0,void 0,function*(){let r,l=document.createElement("div");const d=["apng","bmp","gif","ico","cur","jpeg","jpg","jpeg","jfif","pjpeg","pjp","png","svg","tif","tiff","webp"];if(l=u(l,{width:"100%",display:"flex",justifyContent:(null==e?void 0:e.position)||"left"}),e.url){const t=(a=e.url,Buffer.from(a,"base64").toString("base64")===a);if(!function(e){let t;try{t=new URL(e)}catch(e){return!1}return"http:"===t.protocol||"https:"===t.protocol}(e.url)&&!t)return n(`Invalid url: ${e.url}`);r=t?"data:image/png;base64,"+e.url:e.url}else if(e.path)try{const t=i().readFileSync(e.path);let l=o().extname(e.path).slice(1);-1===d.indexOf(l)&&n(new Error(l+" file type not supported, consider the types: "+d.join())),"svg"===l&&(l="svg+xml"),r="data:image/"+l+";base64,"+t.toString("base64")}catch(e){n(e)}var a;let s=document.createElement("img");s=u(s,Object.assign({height:e.height,width:e.width},e.style)),s.src=r,l.prepend(s),t(l)}))}function u(e,t){for(const n of Object.keys(t))t[n]&&(e.style[n]=t[n]);return e}var p=function(e,t,n,r){return new(n||(n=Promise))(function(i,l){function o(e){try{a(r.next(e))}catch(e){l(e)}}function d(e){try{a(r.throw(e))}catch(e){l(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,d)}a((r=r.apply(e,t||[])).next())})};const h=n(482).ipcRenderer,f=n(289),y=document.getElementById("main");h.on("body-init",function(e,t){y.style.width=(null==t?void 0:t.width)||"100%",y.style.margin=(null==t?void 0:t.margin)||0,e.sender.send("body-init-reply",{status:!0,error:null})}),h.on("render-line",function(e,t){return p(this,void 0,void 0,function*(){var n,r,i;switch(t.line.type){case"text":try{y.appendChild(function(e){const t=e.value;let n=document.createElement("div");return n.innerHTML=t,n=u(n,e.style),n}(t.line)),e.sender.send("render-line-reply",{status:!0,error:null})}catch(t){e.sender.send("render-line-reply",{status:!1,error:t.toString()})}return;case"image":try{const n=yield c(t.line);y.appendChild(n),e.sender.send("render-line-reply",{status:!0,error:null})}catch(t){e.sender.send("render-line-reply",{status:!1,error:t.toString()})}return;case"qrCode":try{const r=document.createElement("div");r.style.display="flex",r.style.justifyContent=(null===(n=t.line)||void 0===n?void 0:n.position)||"left";const i=document.createElement("canvas");i.setAttribute("id",`qrCode${t.lineIndex}`),u(i,{textAlign:t.line.position?"-webkit-"+t.line.position:"-webkit-left"}),r.appendChild(i),y.appendChild(r),yield function(e,{value:t,height:n=15,width:r=1}){return new Promise((i,l)=>{const o=document.getElementById(e),d={width:r,height:n,errorCorrectionLevel:"H",color:"#000"};a.toCanvas(o,t,d).then(i).catch(e=>{l(e)})})}(`qrCode${t.lineIndex}`,{value:t.line.value,width:t.line.width,height:t.line.height}),e.sender.send("render-line-reply",{status:!0,error:null})}catch(t){e.sender.send("render-line-reply",{status:!1,error:t.toString()})}return;case"barCode":try{const n=document.createElement("div"),l=document.createElementNS("http://www.w3.org/2000/svg","svg");l.setAttributeNS(null,"id",`barCode-${t.lineIndex}`),n.appendChild(l),y.appendChild(n),(null===(r=t.line)||void 0===r?void 0:r.style)?u(n,t.line.style):(n.style.display="flex",n.style.justifyContent=(null===(i=t.line)||void 0===i?void 0:i.position)||"left"),f(`#barCode-${t.lineIndex}`,t.line.value,{lineColor:"#000",textMargin:0,fontOptions:"bold",fontSize:t.line.fontsize||12,width:parseInt(t.line.width)||4,height:parseInt(t.line.height)||40,displayValue:!!t.line.displayValue}),e.sender.send("render-line-reply",{status:!0,error:null})}catch(t){e.sender.send("render-line-reply",{status:!1,error:t.toString()})}return;case"table":let l=document.createElement("div");l.setAttribute("id",`table-container-${t.lineIndex}`);let o=document.createElement("table");o.setAttribute("id",`table${t.lineIndex}`),o=u(o,Object.assign({},t.line.style));let d=document.createElement("thead");d=u(d,t.line.tableHeaderStyle);let p=document.createElement("tbody");p=u(p,t.line.tableBodyStyle);let h=document.createElement("tfoot");if(h=u(h,t.line.tableFooterStyle),t.line.tableHeader)for(const n of t.line.tableHeader)if("object"==typeof n)switch(n.type){case"image":yield c(n).then(e=>{const t=document.createElement("th");t.appendChild(e),d.appendChild(t)}).catch(t=>{e.sender.send("render-line-reply",{status:!1,error:t.toString()})});break;case"text":d.appendChild(s(n,"th"))}else{const e=document.createElement("th");e.innerHTML=n,d.appendChild(e)}if(t.line.tableBody)for(const n of t.line.tableBody){const t=document.createElement("tr");for(const r of n)if("object"==typeof r)switch(r.type){case"image":yield c(r).then(e=>{const n=document.createElement("td");n.appendChild(e),t.appendChild(n)}).catch(t=>{e.sender.send("render-line-reply",{status:!1,error:t.toString()})});break;case"text":t.appendChild(s(r))}else{const e=document.createElement("td");e.innerHTML=r,t.appendChild(e)}p.appendChild(t)}if(t.line.tableFooter)for(const n of t.line.tableFooter)if("object"==typeof n)switch(n.type){case"image":yield c(n).then(e=>{const t=document.createElement("th");t.appendChild(e),h.appendChild(t)}).catch(t=>{e.sender.send("render-line-reply",{status:!1,error:t.toString()})});break;case"text":h.appendChild(s(n,"th"))}else{const e=document.createElement("th");e.innerHTML=n,h.appendChild(e)}return o.appendChild(d),o.appendChild(p),o.appendChild(h),l.appendChild(o),y.appendChild(l),void e.sender.send("render-line-reply",{status:!0,error:null})}})})})();