/** * html2pdf.js v0.9.0 * Copyright (c) 2018 Erik Koopmans * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("es6-promise/auto"),require("jspdf"),require("html2canvas")):"function"==typeof define&&define.amd?define(["es6-promise/auto","jspdf","html2canvas"],e):t.html2pdf=e(null,t.jsPDF,t.html2canvas)}(this,function(t,e,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,r=r&&r.hasOwnProperty("default")?r.default:r;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.assign||function(t){for(var e=1;e0;null)n[o].parentNode.removeChild(n[o])}for(var i in e.style)r.style[i]=e.style[i];return r},s=function(t,e){var r={};for(var n in t)r[n]=72*t[n]/96/e;return r},p=function t(e){var r=o(t.convert(Promise.resolve()),JSON.parse(JSON.stringify(t.template))),n=t.convert(Promise.resolve(),r);return n=n.setProgress(1,t,1,[t]),n=n.set(e)};(p.prototype=Object.create(Promise.prototype)).constructor=p,p.convert=function(t,e){return t.__proto__=e||p.prototype,t},p.template={prop:{src:null,container:null,overlay:null,canvas:null,img:null,pdf:null,pageSize:null},progress:{val:0,state:null,n:0,stack:[]},opt:{filename:"file.pdf",margin:[0,0,0,0],image:{type:"jpeg",quality:.95},enableLinks:!0,html2canvas:{},jsPDF:{}}},p.prototype.from=function(t,e){return this.then(function(){switch(e=e||function(t){switch(i(t)){case"string":return"string";case"element":return"canvas"===t.nodeName.toLowerCase?"canvas":"element";default:return"unknown"}}(t)){case"string":return this.set({src:a("div",{innerHTML:t})});case"element":return this.set({src:t});case"canvas":return this.set({canvas:t});case"img":return this.set({img:t});default:return this.error("Unknown source type.")}})},p.prototype.to=function(t){switch(t){case"container":return this.toContainer();case"canvas":return this.toCanvas();case"img":return this.toImg();case"pdf":return this.toPdf();default:return this.error("Invalid target.")}},p.prototype.toContainer=function(){return this.thenList([function(){return this.prop.src||this.error("Cannot duplicate - no source HTML.")},function(){return this.prop.pageSize||this.setPageSize()}]).then(function(){var t={position:"fixed",overflow:"hidden",zIndex:1e3,left:0,right:0,bottom:0,top:0,backgroundColor:"rgba(0,0,0,0.8)"},e={position:"absolute",width:this.prop.pageSize.inner.width+this.prop.pageSize.unit,left:0,right:0,top:0,height:"auto",margin:"auto",backgroundColor:"white"};t.opacity=0;var r=function t(e,r){for(var n=3===e.nodeType?document.createTextNode(e.nodeValue):e.cloneNode(!1),o=e.firstChild;o;o=o.nextSibling)!0!==r&&1===o.nodeType&&"SCRIPT"===o.nodeName||n.appendChild(t(o,r));return 1===e.nodeType&&("CANVAS"===e.nodeName?(n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0)):"TEXTAREA"!==e.nodeName&&"SELECT"!==e.nodeName||(n.value=e.value),n.addEventListener("load",function(){n.scrollTop=e.scrollTop,n.scrollLeft=e.scrollLeft},!0)),n}(this.prop.src,this.opt.html2canvas.javascriptEnabled);this.prop.overlay=a("div",{className:"html2pdf__overlay",style:t}),this.prop.container=a("div",{className:"html2pdf__container",style:e}),this.prop.container.appendChild(r),this.prop.overlay.appendChild(this.prop.container),document.body.appendChild(this.prop.overlay)})},p.prototype.toCanvas=function(){var t=[function(){return document.body.contains(this.prop.container)||this.toContainer()}];return this.thenList(t).then(function(){var t=o({},this.opt.html2canvas);return delete t.onrendered,r(this.prop.container,t)}).then(function(t){(this.opt.html2canvas.onrendered||function(){})(t),this.prop.canvas=t,document.body.removeChild(this.prop.overlay)})},p.prototype.toImg=function(){return this.thenList([function(){return this.prop.canvas||this.toCanvas()}]).then(function(){var t=this.prop.canvas.toDataURL("image/"+this.opt.image.type,this.opt.image.quality);this.prop.img=document.createElement("img"),this.prop.img.src=t})},p.prototype.toPdf=function(){return this.thenList([function(){return this.prop.canvas||this.toCanvas()}]).then(function(){var t=this.prop.canvas,r=this.opt,n=(t.getContext("2d"),t.height),o=Math.floor(t.width*this.prop.pageSize.inner.ratio),i=Math.ceil(n/o),a=this.prop.pageSize.inner.height,s=document.createElement("canvas"),p=s.getContext("2d");s.width=t.width,s.height=o,this.prop.pdf=this.prop.pdf||new e(r.jsPDF);for(var h=0;hp){u=h;h=p,p=u}}else{if("l"!==t&&"landscape"!==t)throw"Invalid orientation: "+t;if(t="l",p>h){var u=h;h=p,p=u}}return{width:h,height:p,unit:e,k:s}};var h={toContainer:p.prototype.toContainer};p.prototype.toContainer=function(){return h.toContainer.call(this).then(function(){var t=this.prop.container.querySelectorAll(".html2pdf__page-break"),e=this.prop.pageSize.inner.px.height;Array.prototype.forEach.call(t,function(t){t.style.display="block";var r=t.getBoundingClientRect();t.style.height=e-r.top%e+"px"},this)})};var u=[],c={toContainer:p.prototype.toContainer,toPdf:p.prototype.toPdf};p.prototype.toContainer=function(){return c.toContainer.call(this).then(function(){if(this.opt.enableLinks){var t=this.prop.container,e=t.querySelectorAll("a"),r=s(t.getBoundingClientRect(),this.prop.pageSize.k);u=[],Array.prototype.forEach.call(e,function(t){for(var e=t.getClientRects(),n=0;n