import{r as e}from"./pinia-CCBcvzH1.js";import{n as t,t as n}from"./es-CGMBJHcJ.js";var r=class{constructor(e,t){this.pdfBytes=e,this.pdfOriginal=e,this.pdfFile=t}async loadPdfFromFile(e){return this.pdfFile=e,this.pdfBytes=await e.arrayBuffer(),!0}async loadPdfFromUrl(e){let t=await(await fetch(e)).arrayBuffer();return this.pdfBytes=t,this.pdfFile=new File([t],`document.pdf`,{type:`application/pdf`}),!0}getPositionForText(e,t,n,r=12,i=0){let a=r*.6*i;switch(e){case`top-left`:return{x:2,y:n-2-r};case`top-center`:return{x:(t-a)/2,y:n-2-r};case`top-right`:return{x:t-2-a,y:n-2-r};case`middle-left`:return{x:2,y:(n+r)/2};case`middle-center`:return{x:(t-a)/2,y:n/2};case`middle-right`:return{x:t-2-a,y:(n+r)/2};case`bottom-left`:return{x:2,y:2+r};case`bottom-center`:return{x:(t-a)/2,y:2+r};case`bottom-right`:return{x:t-2-a,y:2+r};default:return null}}getPositionForImage(e,t,n,r=100,i=100){switch(e){case`top-left`:return{x:2,y:n-2-i};case`top-center`:return{x:(t-r)/2,y:n-2-i};case`top-right`:return{x:t-2-r,y:n-2-i};case`middle-left`:return{x:2,y:(n-i)/2};case`middle-center`:return{x:(t-r)/2,y:(n-i)/2};case`middle-right`:return{x:t-2-r,y:(n-i)/2};case`bottom-left`:return{x:2,y:2};case`bottom-center`:return{x:(t-r)/2,y:2};case`bottom-right`:return{x:t-2-r,y:2};default:return null}}async addConfigContent(e){let r=await n.load(this.pdfBytes),i=r.getPages(),a=e.text,o=e.image;if(a&&a.active&&a.content){let e=a.fontSize||12,n=await r.embedFont(a.isBold?`Helvetica-Bold`:`Helvetica`),{position:o,content:s}=a;i.forEach(r=>{let{width:i,height:c}=r.getSize(),l;l=o===`custom`?{x:a.x,y:c-a.y}:this.getPositionForText(o,i,c,e,s.length),l&&r.drawText(s,{x:l.x,y:l.y,size:e,font:n,color:t(0,0,0)})})}if(o&&o.active&&o.data){o.base64&&(o.data=await this.base64ToFile(o.base64));let e=await o.data.arrayBuffer(),t,n=o.data.type.toLowerCase();if(n===`image/png`)t=await r.embedPng(e);else if(n===`image/jpeg`||n===`image/jpg`)t=await r.embedJpg(e);else throw Error(`Unsupported image type`);i.forEach(e=>{let{width:n,height:r}=e.getSize(),i;i=o.position===`custom`?{x:o.x,y:r-o.y}:this.getPositionForImage(o.position,n,r,o.width||100,o.height||100),i&&e.drawImage(t,{x:i.x,y:i.y,width:o.width||100,height:o.height||100})})}return r.save()}async addFooterContent(e){let r=await n.load(this.pdfBytes),i=r.getPages(),a=await r.embedFont(`Helvetica-Bold`),{fontSize:o,position:s,isPagging:c,isTimestamp:l,content:u}=e;return i.forEach((n,r)=>{let{width:d,height:f}=n.getSize(),p=c?`${u} (${r+1}/${i.length})`:u,m;if(m=s===`custom`?{x:e.x,y:f-e.y}:this.getPositionForText(s,d,f,o,p.length),n.drawText(p,{x:m.x,y:m.y,size:o,font:a,color:t(0,0,0)}),l){let e=new Date().toLocaleString();n.drawText(e,{x:m.x,y:m.y-o,size:10,font:a,color:t(0,0,0)})}}),r.save()}getPdfPreviewUrl(e){let t=new Blob([e||this.pdfBytes],{type:`application/pdf`});return URL.createObjectURL(t)}getPdfFile(){return this.pdfFile}getPdfBytes(){return this.pdfBytes}setPdfBytes(e){return this.pdfBytes=e,this.pdfOriginal=e,this.pdfBytes}resetOriginal(){this.pdfBytes=this.pdfOriginal}base64ToFile(e,t){let n=e.split(`,`),r=n[0].match(/:(.*?);/)[1],i=atob(n[1]),a=i.length,o=new Uint8Array(a);for(;a--;)o[a]=i.charCodeAt(a);return new File([o],t,{type:r})}},i=e(`printer`,{state(){return{sessionPrint:{active:!0,content:``,position:`bottom-right`,x:100,y:100,fontSize:12,isBold:!0,isPagging:!0,isTimestamp:!0},saveFilePrint:!1,listPosition:[{value:`top-left`,label:`POSITION_TOP_LEFT`,emoji:`↖️`},{value:`top-center`,label:`POSITION_TOP_CENTER`,emoji:`⬆️`},{value:`top-right`,label:`POSITION_TOP_RIGHT`,emoji:`↗️`},{value:`middle-left`,label:`POSITION_MIDDLE_LEFT`,emoji:`⬅️`},{value:`middle-center`,label:`POSITION_MIDDLE_CENTER`,emoji:`⏺️`},{value:`middle-right`,label:`POSITION_MIDDLE_RIGHT`,emoji:`➡️`},{value:`bottom-left`,label:`POSITION_BOTTOM_LEFT`,emoji:`↙️`},{value:`bottom-center`,label:`POSITION_BOTTOM_CENTER`,emoji:`⬇️`},{value:`bottom-right`,label:`POSITION_BOTTOM_RIGHT`,emoji:`↘️`},{value:`custom`,label:`POSITION_CUSTOM`,emoji:`✏️`}]}},persist:{enabled:!0,key:`pinia-persist-printer`}});export{r as n,i as t};