+function t(t){return new Promise(function(e,n){var r=new FileReader;r.readAsDataURL(t),r.onload=function(){e(r.result)},r.onerror=n})}function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Date.now();return new Promise(function(r){for(var i,a=t.split(","),h=a[0].match(/:(.*?);/)[1],o=atob(a[1]),u=o.length,c=new Uint8Array(u);u--;)c[u]=o.charCodeAt(u);try{i=new File([c],e,{type:h})}catch(t){(i=new Blob([c],{type:h})).name=e,i.lastModified=n}r(i)})}function n(t){return new Promise(function(e,n){var r=new Image;r.onload=function(){e(r)},r.onerror=n,r.src=t})}function r(t,e){var n=document.createElement("canvas"),r=n.getContext("2d");return Number.isInteger(e)&&(t.width>e||t.height>e)?t.width>t.height?(n.width=e,n.height=t.height/t.width*e):(n.width=t.width/t.height*e,n.height=e):(n.width=t.width,n.height=t.height),r.drawImage(t,0,0,n.width,n.height),n}function i(i){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Number.POSITIVE_INFINITY,h=arguments.length>2?arguments[2]:void 0;return new Promise(function(o,u){var c,d,f,l,g,s;return i instanceof Blob||i instanceof File?/^image/.test(i.type)?(c=5,d=1024*a*1024,t(i).then(function(t){try{return n(t).then(function(t){try{return l=r(f=t,h),g=1,e(l.toDataURL(i.type,g),i.name,i.lastModified).then(function(t){try{var n=function(){return o(s)};if(s=t,"image/png"===i.type){var r,a=function t(){return c--&&s.size>d?(l.width*=.9,l.height*=.9,l.getContext("2d").drawImage(f,0,0,l.width,l.height),e(l.toDataURL(i.type,g),i.name,i.lastModified).then(function(e){try{return s=e,t}catch(t){return u(t)}},u)):[1]},h=function(){return n.call(this)};return(r=function(t){for(;t;){if(t.then)return void t.then(r,u);try{if(t.pop){if(t.length)return t.pop()?h.call(this):t;t=a}else t=t.call(this)}catch(t){return u(t)}}}.bind(this))(a)}var w,m=function t(){return c--&&s.size>d?(l.width*=.9,l.height*=.9,l.getContext("2d").drawImage(f,0,0,l.width,l.height),g*=.9,e(l.toDataURL(i.type,g),i.name,i.lastModified).then(function(e){try{return s=e,t}catch(t){return u(t)}},u)):[1]},v=function(){return n.call(this)};return(w=function(t){for(;t;){if(t.then)return void t.then(w,u);try{if(t.pop){if(t.length)return t.pop()?v.call(this):t;t=m}else t=t.call(this)}catch(t){return u(t)}}}.bind(this))(m)}catch(t){return u(t)}}.bind(this),u)}catch(t){return u(t)}}.bind(this),u)}catch(t){return u(t)}}.bind(this),u)):u(new Error("The file given is not an image")):u(new Error("The file given is not an instance of Blob or File"))})}i.drawImageInCanvas=r,i.getDataUrlFromFile=t,i.getFilefromDataUrl=e,i.loadImage=n;export default i;
0 commit comments