import{h as m}from"./vendor-html2pdf.js-B-tok4Ns.js";import{w,T as P}from"./vendor-vue-runtime-dom-B2rky8vu.js";import{f as u,i as c,x as o,j as b,p as C,m as _,t as B}from"./vendor-vue-runtime-core-DwK6Ry68.js";import{b as v,a as E}from"./vendor-vue-shared-DrzsEcag.js";const O=(s,n)=>{const t=s.__vccOpts||s;for(const[e,a]of n)t[e]=a;return t},$={props:{showLayout:{type:Boolean,default:!1},floatLayout:{type:Boolean,default:!0},enableDownload:{type:Boolean,default:!0},previewModal:{type:Boolean,default:!1},paginateElementsByHeight:{type:Number},filename:{type:String,default:`${new Date().getTime()}`},pdfQuality:{type:Number,default:2},pdfFormat:{default:"a4"},pdfOrientation:{type:String,default:"portrait"},pdfContentWidth:{default:"800px"},htmlToPdfOptions:{type:Object},manualPagination:{type:Boolean,default:!1}},data(){return{hasAlreadyParsed:!1,progress:0,pdfWindow:null,pdfFile:null}},watch:{progress(s){this.$emit("progress",s)},paginateElementsByHeight(){this.resetPagination()},$props:{handler(){this.validateProps()},deep:!0,immediate:!0}},methods:{validateProps(){this.manualPagination||this.paginateElementsByHeight===void 0&&console.error("Error: paginate-elements-by-height is required if manual-pagination is false")},resetPagination(){const n=this.$refs.pdfContent.getElementsByClassName("html2pdf__page-break"),t=n.length-1;if(t!==-1){this.hasAlreadyParsed=!1;for(let e=t;e>=0;e--)n[e].parentNode.removeChild(n[e])}},generatePdf(){this.$emit("startPagination"),this.progress=0,this.paginationOfElements()},paginationOfElements(){if(this.progress=25,this.manualPagination){this.progress=70,this.$emit("hasPaginated"),this.downloadPdf();return}if(this.hasAlreadyParsed)this.progress=70;else{const s=this.$refs.pdfContent,n=Array.from(this.$refs.pdfContent.children);let t=0;for(const e of n)if(e.classList[0]==="html2pdf__page-break")t=0;else{const d=e.clientHeight,f=e.currentStyle||window.getComputedStyle(e),y=parseInt(f.marginTop)+parseInt(f.marginBottom),p=d+y;if(t+d<this.paginateElementsByHeight)t+=p;else{const h=document.createElement("div");h.classList.add("html2pdf__page-break"),s.insertBefore(h,e),t=p}}this.progress=70,this.hasAlreadyParsed=!0}this.$emit("hasPaginated"),this.downloadPdf()},async downloadPdf(){const s=this.$refs.pdfContent,n=this.setOptions();this.$emit("beforeDownload",{html2pdf:m,options:n,pdfContent:s});const t=m().set(n).from(s);let e=null;if(this.previewModal&&(this.pdfFile=await t.output("bloburl"),e=this.pdfFile),this.enableDownload&&(e=await t.save().output("bloburl")),e){const i=await(await fetch(e)).blob();this.$emit("hasDownloaded",i)}this.progress=100},setOptions(){return this.htmlToPdfOptions!==void 0&&this.htmlToPdfOptions!==null?this.htmlToPdfOptions:{margin:0,filename:`${this.filename}.pdf`,image:{type:"jpeg",quality:.98},enableLinks:!1,html2canvas:{scale:this.pdfQuality,useCORS:!0},jsPDF:{unit:"in",format:this.pdfFormat,orientation:this.pdfOrientation}}},closePreview(){this.pdfFile=null}}},k={class:"vue-html2pdf"},F={key:0,class:"pdf-preview"},H=["src"];function S(s,n,t,e,a,i){return c(),u("div",k,[o("section",{class:E(["layout-container",{"show-layout":t.showLayout,"unset-all":!t.floatLayout}])},[o("section",{class:"content-wrapper",style:v(`width: ${t.pdfContentWidth};`),ref:"pdfContent"},[C(s.$slots,"pdf-content",{},void 0,!0)],4)],2),b(P,{name:"transition-anim"},{default:_(()=>[a.pdfFile?(c(),u("section",F,[o("button",{onClick:n[0]||(n[0]=w(d=>i.closePreview(),["self"]))},"×"),o("iframe",{src:a.pdfFile,width:"100%",height:"100%"},null,8,H)])):B("",!0)]),_:1})])}const g=O($,[["render",S],["__scopeId","data-v-8835b5b4"]]);function l(s){l.installed||(l.installed=!0,s.component("Vue3Html2pdf",g))}const T={install:l};let r=null;typeof window<"u"?r=window.Vue:typeof global<"u"&&(r=global.Vue);r&&r.use(T);g.install=l;export{O as _,g as c};
//# sourceMappingURL=vendor-vue3-html2pdf-KR020wX8.js.map
