download-c6c2acd3.js 1.9 KB

1
  1. import{D as d}from"./index.js";function c(e){const o=e.split(","),r=o[0].match(/:(.*?);/)[1],t=window.atob(o[1]);let n=t.length;const a=new Uint8Array(n);for(;n--;)a[n]=t.charCodeAt(n);return o.length==1?new Blob([a],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}):new Blob([a],{type:r})}function m(e){return new Promise((o,i)=>{e||i();const r=new FileReader;r.readAsDataURL(e),r.onload=function(t){const n=t.target.result;o(n)}})}function l(e,o){return new Promise((i,r)=>{let t=document.createElement("CANVAS");const n=t.getContext("2d"),a=new Image;a.crossOrigin="",a.onload=function(){if(!t||!n)return r();t.height=a.height,t.width=a.width,n.drawImage(a,0,0);const s=t.toDataURL(o||"image/png");t=null,i(s)},a.src=e})}function p(e,o,i,r){l(e).then(t=>{u(t,o,i,r)})}function u(e,o,i,r){const t=c(e);w(t,o,i,r)}function w(e,o,i,r){const t=typeof r!="undefined"?[r,e]:[e],n=new Blob(t,{type:i||"application/octet-stream"}),a=window.URL.createObjectURL(n),s=document.createElement("a");s.style.display="none",s.href=a,s.setAttribute("download",o),typeof s.download=="undefined"&&s.setAttribute("target","_blank"),document.body.appendChild(s),s.click(),document.body.removeChild(s),window.URL.revokeObjectURL(a)}function b({url:e,target:o="_blank",fileName:i}){const r=window.navigator.userAgent.toLowerCase().indexOf("chrome")>-1,t=window.navigator.userAgent.toLowerCase().indexOf("safari")>-1;if(/(iP)/g.test(window.navigator.userAgent))return console.error("Your browser does not support download!"),!1;if(r||t){const n=document.createElement("a");if(n.href=e,n.target=o,n.download!==void 0&&(n.download=i||e.substring(e.lastIndexOf("/")+1,e.length)),document.createEvent){const a=document.createEvent("MouseEvents");return a.initEvent("click",!0,!0),n.dispatchEvent(a),!0}}return e.indexOf("?")===-1&&(e+="?download"),d(e,{target:o}),!0}export{c as a,u as b,p as c,b as d,w as e,m as f};