var e=globalThis,e=globalThis,t=typeof globalThis<`u`?globalThis:typeof window<`u`?window:e===void 0?typeof self<`u`?self:{}:e;function n(e,t){return t={exports:{}},e(t,t.exports),t.exports}var r=n(function(e,n){(function(t,n){e.exports=n()})(t,function(){return function e(t,n,r){var i=window,a=`application/octet-stream`,o=r||a,s=t,c=!n&&!r&&s,l=document.createElement(`a`),u=function(e){return String(e)},d=i.Blob||i.MozBlob||i.WebKitBlob||u,f=n||`download`,p,m;if(d=d.call?d.bind(i):Blob,String(this)===`true`&&(s=[s,o],o=s[0],s=s[1]),c&&c.length<2048&&(f=c.split(`/`).pop().split(`?`)[0],l.href=c,l.href.indexOf(c)!==-1)){var h=new XMLHttpRequest;return h.open(`GET`,c,!0),h.responseType=`blob`,h.onload=function(t){e(t.target.response,f,a)},setTimeout(function(){h.send()},0),h}if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(s))if(s.length>1024*1024*1.999&&d!==u)s=y(s),o=s.type||a;else return navigator.msSaveBlob?navigator.msSaveBlob(y(s),f):b(s);else if(/([\x80-\xff])/.test(s)){for(var g=0,_=new Uint8Array(s.length),v=_.length;g<v;++g)_[g]=s.charCodeAt(g);s=new d([_],{type:o})}p=s instanceof d?s:new d([s],{type:o});function y(e){for(var t=e.split(/[:;,]/),n=t[1],r=(t[2]==`base64`?atob:decodeURIComponent)(t.pop()),i=r.length,a=0,o=new Uint8Array(i);a<i;++a)o[a]=r.charCodeAt(a);return new d([o],{type:n})}function b(e,t){if(`download`in l)return l.href=e,l.setAttribute(`download`,f),l.className=`download-js-link`,l.innerHTML=`downloading...`,l.style.display=`none`,document.body.appendChild(l),setTimeout(function(){l.click(),document.body.removeChild(l),t===!0&&setTimeout(function(){i.URL.revokeObjectURL(l.href)},250)},66),!0;if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent))return/^data:/.test(e)&&(e=`data:`+e.replace(/^data:([\w\/\-\+]+)/,a)),window.open(e)||confirm(`Displaying New Document

Use Save As... to download, then click back to return to this page.`)&&(location.href=e),!0;var n=document.createElement(`iframe`);document.body.appendChild(n),!t&&/^data:/.test(e)&&(e=`data:`+e.replace(/^data:([\w\/\-\+]+)/,a)),n.src=e,setTimeout(function(){document.body.removeChild(n)},333)}if(navigator.msSaveBlob)return navigator.msSaveBlob(p,f);if(i.URL)b(i.URL.createObjectURL(p),!0);else{if(typeof p==`string`||p.constructor===u)try{return b(`data:`+o+`;base64,`+i.btoa(p))}catch{return b(`data:`+o+`,`+encodeURIComponent(p))}m=new FileReader,m.onload=function(e){b(this.result)},m.readAsDataURL(p)}return!0}})}),i={props:{type:{type:String,default:`xls`},data:{type:Array,required:!1,default:null},fields:{type:Object,default:()=>null},exportFields:{type:Object,default:()=>null},defaultValue:{type:String,required:!1,default:``},header:{default:null},footer:{default:null},name:{type:String,default:`data.xls`},fetch:{type:Function},meta:{type:Array,default:()=>[]},worksheet:{type:String,default:`Sheet1`},beforeGenerate:{type:Function},beforeFinish:{type:Function},escapeCsv:{type:Boolean,default:!0},stringifyLongNum:{type:Boolean,default:!1}},computed:{idName(){return`export_`+new Date().getTime()},downloadFields(){if(this.fields)return this.fields;if(this.exportFields)return this.exportFields}},methods:{async generate(){typeof this.beforeGenerate==`function`&&await this.beforeGenerate();let e=this.data;if((typeof this.fetch==`function`||!e)&&(e=await this.fetch()),!e||!e.length)return;let t=this.getProcessedJson(e,this.downloadFields);return this.type===`html`?this.export(this.jsonToXLS(t),this.name.replace(`.xls`,`.html`),`text/html`):this.type===`csv`?this.export(this.jsonToCSV(t),this.name.replace(`.xls`,`.csv`),`application/csv`):this.export(this.jsonToXLS(t),this.name,`application/vnd.ms-excel`)},export:async function(e,t,n){let i=this.base64ToBlob(e,n);typeof this.beforeFinish==`function`&&await this.beforeFinish(),r(i,t,n)},jsonToXLS(e){let t=`<thead>`,n=Object.keys(e[0]).length,r=this,i=this.header||this.$attrs.title;i&&(t+=this.parseExtraData(i,`<tr><th colspan="`+n+'">${data}</th></tr>')),t+=`<tr>`;for(let n in e[0])t+=`<th>`+n+`</th>`;return t+=`</tr>`,t+=`</thead>`,t+=`<tbody>`,e.map(function(e,n){t+=`<tr>`;for(let n in e)t+=`<td>`+r.preprocessLongNum(r.valueReformattedForMultilines(e[n]))+`</td>`;t+=`</tr>`}),t+=`</tbody>`,this.footer!=null&&(t+=`<tfoot>`,t+=this.parseExtraData(this.footer,`<tr><td colspan="`+n+'">${data}</td></tr>'),t+=`</tfoot>`),'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>${worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><style>br {mso-data-placement: same-cell;}</style></head><body><table>${table}</table></body></html>'.replace("${table}",t).replace("${worksheet}",this.worksheet)},jsonToCSV(e){let t=this;var n=[];let r=this.header||this.$attrs.title;r&&n.push(this.parseExtraData(r,`\${data}\r
`));for(let t in e[0])n.push(t),n.push(`,`);return n.pop(),n.push(`\r
`),e.map(function(e){for(let r in e){let i=e[r]+``;t.escapeCsv&&(i=`="`+i+`"`,i.match(/[,"\n]/)&&(i=`"`+i.replace(/\"/g,`""`)+`"`)),n.push(i),n.push(`,`)}n.pop(),n.push(`\r
`)}),this.footer!=null&&n.push(this.parseExtraData(this.footer,`\${data}\r
`)),n.join(``)},getProcessedJson(e,t){let n=this.getKeys(e,t),r=[],i=this;return e.map(function(e,t){let a={};for(let t in n){let r=n[t];a[t]=i.getValue(r,e)}r.push(a)}),r},getKeys(e,t){if(t)return t;let n={};for(let t in e[0])n[t]=t;return n},parseExtraData(e,t){let n=``;if(Array.isArray(e))for(var r=0;r<e.length;r++)e[r]&&(n+=t.replace("${data}",e[r]));else n+=t.replace("${data}",e);return n},getValue(e,t){let n=typeof e==`object`?e.field:e,r=typeof n==`string`?n.split(`.`):[],i=this.defaultValue;return i=n?r.length>1?this.getValueFromNestedItem(t,r):this.parseValue(t[n]):t,e.hasOwnProperty(`callback`)&&(i=this.getValueFromCallback(i,e.callback)),i},valueReformattedForMultilines(e){return typeof e==`string`?e.replace(/\n/gi,`<br/>`):e},preprocessLongNum(e){if(this.stringifyLongNum){if(String(e).startsWith(`0x`))return e;if(!isNaN(e)&&e!=``&&(e>99999999999||e<1e-13))return`="`+e+`"`}return e},getValueFromNestedItem(e,t){let n=e;for(let e of t)n&&=n[e];return this.parseValue(n)},getValueFromCallback(e,t){if(typeof t!=`function`)return this.defaultValue;let n=t(e);return this.parseValue(n)},parseValue(e){return e||e===0||typeof e==`boolean`?e:this.defaultValue},base64ToBlob(e,t){let n=window.btoa(window.unescape(encodeURIComponent(e))),r=atob(n),i=r.length,a=new Uint8ClampedArray(i);for(;i--;)a[i]=r.charCodeAt(i);return new Blob([a],{type:t})}}};function a(e,t,n,r,i,a,o,s,c,l){typeof o!=`boolean`&&(c=s,s=o,o=!1);var u=typeof n==`function`?n.options:n;e&&e.render&&(u.render=e.render,u.staticRenderFns=e.staticRenderFns,u._compiled=!0,i&&(u.functional=!0)),r&&(u._scopeId=r);var d;if(a?(d=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!e&&typeof __VUE_SSR_CONTEXT__<`u`&&(e=__VUE_SSR_CONTEXT__),t&&t.call(this,c(e)),e&&e._registeredComponents&&e._registeredComponents.add(a)},u._ssrRegister=d):t&&(d=o?function(){t.call(this,l(this.$root.$options.shadowRoot))}:function(e){t.call(this,s(e))}),d)if(u.functional){var f=u.render;u.render=function(e,t){return d.call(t),f(e,t)}}else{var p=u.beforeCreate;u.beforeCreate=p?[].concat(p,d):[d]}return n}var o=a,s=i,c=function(){var e=this,t=e.$createElement;return(e._self._c||t)(`div`,{attrs:{id:e.idName},on:{click:e.generate}},[e._t(`default`,[e._v(` Download `+e._s(e.name)+` `)])],2)},l=[];c._withStripped=!0;var u=o({render:c,staticRenderFns:l},void 0,s,void 0,!1,void 0,void 0,void 0);export{u as t};