import{n as f}from"./vue-vendor-CxLCUzY4.js";import{$ as y}from"./print-BOs53bBC.js";import"./antd-vue-vendor-CahNzUUa.js";class g{constructor(e){this.standards={strict:"strict",loose:"loose",html5:"html5"},this.counter=0,this.settings={standard:this.standards.html5,extraHead:"",extraCss:"",popTitle:"",endCallback:null,el:""},Object.assign(this.settings,e),this.init()}init(){this.counter++,this.settings.id=`printArea_${this.counter}`;let e=document.getElementById(this.settings.id);e&&e.parentNode.removeChild(e);let t=this.getPrintWindow();this.write(t.doc),this.settings.endCallback()}print(e){let t=e;t.focus(),t.print()}write(e,t){e.open(),e.write(`${this.docType()}<html>${this.getHead()}${this.getBody()}</html>`),e.close()}docType(){if(this.settings.standard===this.standards.html5)return"<!DOCTYPE html>";var e=this.settings.standard===this.standards.loose?" Transitional":"",t=this.settings.standard===this.standards.loose?"loose":"strict";return`<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01${e}//EN" "http://www.w3.org/TR/html4/${t}.dtd">`}getHead(){let e="",t="",l="";this.settings.extraHead&&this.settings.extraHead.replace(/([^,]+)/g,function(n){e+=n}),[].forEach.call(document.querySelectorAll("link"),function(n,o){n.href.indexOf(".css")>=0&&(t+='<link type="text/css" rel="stylesheet" href="'+n.href+'" >')});for(let n=0;n<document.styleSheets.length;n++)if(document.styleSheets[n].cssRules||document.styleSheets[n].rules){let o=document.styleSheets[n].cssRules||document.styleSheets[n].rules;for(let c=0;c<o.length;c++)try{l+=o[c].cssText}catch(d){}}return this.settings.extraCss&&this.settings.extraCss.replace(/([^,\s]+)/g,function(n){t+=`<link type="text/css" rel="stylesheet" href="${n}">`}),`<head><title>${this.settings.popTitle}</title>${e}${t}<style type="text/css">${l}</style></head>`}getBody(){return"<body>"+this.getFormData(document.querySelector(this.settings.el)).outerHTML+"</body>"}getFormData(e){let t=this,l=e.cloneNode(!0),n=l.querySelectorAll("*");[].forEach.call(n,function(s){let i=s.getAttribute("ignore-print");i=i==null?s.getAttribute("ignoreprint"):i,i!=null&&i.toString()==="true"&&(s.outerHTML="")});let o=l.querySelectorAll("input,select,textarea");[].forEach.call(o,function(s,i){let a=s.getAttribute("type"),h=o[i];a==null&&(a=s.tagName==="SELECT"?"select":s.tagName==="TEXTAREA"?"textarea":""),a==="radio"||a==="checkbox"?s.checked&&h.setAttribute("checked",s.checked):a==="select"?[].forEach.call(h.querySelectorAll("option"),function(p,E){p.selected&&p.setAttribute("selected",!0)}):a==="textarea"?h.innerHTML=s.value:(h.value=s.value,h.setAttribute("value",s.value))});var c=e.querySelectorAll("canvas"),d=l.querySelectorAll("canvas");return[].forEach.call(d,function(s,i){t.isECharts(s)&&(s.parentElement.style.width&&(s.parentElement.style.width="100%",s.parentElement.style.height="auto"),s.parentElement.parentElement.style.width&&(s.parentElement.parentElement.style.width="100%",s.parentElement.parentElement.style.height="auto"));var a=c[i].toDataURL();s.outerHTML='<img src="'+a+'" style="width:100%;"/>'}),l}isECharts(e){let t="_echarts_instance_",l=e.parentElement;return l.getAttribute(t)!=null?!0:l.parentElement?l.parentElement.getAttribute(t)!=null:!1}getPrintWindow(){var e=this.Iframe();return{win:e.contentWindow||e,doc:e.doc}}Iframe(){let e=this.settings.id,t;var l=this;try{t=document.createElement("iframe"),document.body.appendChild(t),t.style.border="0px",t.style.position="absolute",t.style.width="0px",t.style.height="0px",t.style.right="0px",t.style.top="0px",t.setAttribute("id",e),t.setAttribute("src",new Date().getTime()),t.doc=null,t.onload=function(){var n=t.contentWindow||t;l.print(n)},t.doc=t.contentDocument?t.contentDocument:t.contentWindow?t.contentWindow.document:t.document}catch(n){throw new Error(n+". iframes may not be supported in this browser.")}if(t.doc==null)throw new Error("Cannot find document.");return t}}function v(r){if((r==null?void 0:r.type)==="html")m(r.printable);else return y(r)}function m(r){r?w(r):window.print()}let u=!0;function w(r){typeof r=="string"&&!r.startsWith("#")&&(r="#"+r),f(()=>{u&&(u=!1,new g({el:r,endCallback(){u=!0}}))})}export{v as printJS,m as printNb};
