/*! * Compressor.js v1.2.1 * https://fengyuanchen.github.io/compressorjs * * Copyright 2018-present Chen Fengyuan * Released under the MIT license * * Date: 2023-02-28T14:09:41.732Z */function oe(a,e){var t=Object.keys(a);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(a);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),t.push.apply(t,r)}return t}function F(a){for(var e=1;e"u"||function(e){var t=e.HTMLCanvasElement&&e.HTMLCanvasElement.prototype,r=e.Blob&&function(){try{return!!new Blob}catch{return!1}}(),i=r&&e.Uint8Array&&function(){try{return new Blob([new Uint8Array(100)]).size===100}catch{return!1}}(),n=e.BlobBuilder||e.WebKitBlobBuilder||e.MozBlobBuilder||e.MSBlobBuilder,u=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,f=(r||n)&&e.atob&&e.ArrayBuffer&&e.Uint8Array&&function(s){var l,c,h,p,v,o,b,m,x;if(l=s.match(u),!l)throw new Error("invalid data URI");for(c=l[2]?l[1]:"text/plain"+(l[3]||";charset=US-ASCII"),h=!!l[4],p=s.slice(l[0].length),h?v=atob(p):v=decodeURIComponent(p),o=new ArrayBuffer(v.length),b=new Uint8Array(o),m=0;m"u"?!1:e instanceof Blob||Object.prototype.toString.call(e)==="[object Blob]"},fe={strict:!0,checkOrientation:!0,retainExif:!1,maxWidth:1/0,maxHeight:1/0,minWidth:0,minHeight:0,width:void 0,height:void 0,resize:"none",quality:.8,mimeType:"auto",convertTypes:["image/png"],convertSize:5e6,beforeDraw:null,drew:null,success:null,error:null},Re=typeof window<"u"&&typeof window.document<"u",y=Re?window:{},j=function(e){return e>0&&e<1/0},Ue=Array.prototype.slice;function S(a){return Array.from?Array.from(a):Ue.call(a)}var Te=/^image\/.+$/;function H(a){return Te.test(a)}function Ae(a){var e=H(a)?a.substr(6):"";return e==="jpeg"&&(e="jpg"),".".concat(e)}var me=String.fromCharCode;function Oe(a,e,t){var r="",i;for(t+=e,i=e;i0;)t.push(me.apply(null,S(i.subarray(0,r)))),i=i.subarray(r);return"data:".concat(e,";base64,").concat(De(t.join("")))}function Pe(a){var e=new DataView(a),t;try{var r,i,n;if(e.getUint8(0)===255&&e.getUint8(1)===216)for(var u=e.byteLength,f=2;f+1=8&&(n=l+h)}}}if(n){var p=e.getUint16(n,r),v,o;for(o=0;o1&&arguments[1]!==void 0?arguments[1]:1e11;return Me.test(a)?Math.round(a*e)/e:a}function P(a){var e=a.aspectRatio,t=a.height,r=a.width,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"none",n=j(r),u=j(t);if(n&&u){var f=t*e;(i==="contain"||i==="none")&&f>r||i==="cover"&&f1&&M(v,Fe(o))),s&&(t.exif=je(p)),f||s?!w||o>1?v.url=ue(p,n):v.url=w.createObjectURL(r):v.url=p,t.load(v)},l.onabort=function(){t.fail(new Error("Aborted to read the image with FileReader."))},l.onerror=function(){t.fail(new Error("Failed to read the image with FileReader."))},l.onloadend=function(){t.reader=null},f||s?l.readAsArrayBuffer(r):l.readAsDataURL(r)}}},{key:"load",value:function(t){var r=this,i=this.file,n=this.image;n.onload=function(){r.draw(F(F({},t),{},{naturalWidth:n.naturalWidth,naturalHeight:n.naturalHeight}))},n.onabort=function(){r.fail(new Error("Aborted to load the image."))},n.onerror=function(){r.fail(new Error("Failed to load the image."))},y.navigator&&/(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(y.navigator.userAgent)&&(n.crossOrigin="anonymous"),n.alt=i.name,n.src=t.url}},{key:"draw",value:function(t){var r=this,i=t.naturalWidth,n=t.naturalHeight,u=t.rotate,f=u===void 0?0:u,s=t.scaleX,l=s===void 0?1:s,c=t.scaleY,h=c===void 0?1:c,p=this.file,v=this.image,o=this.options,b=document.createElement("canvas"),m=b.getContext("2d"),x=Math.abs(f)%180===90,L=(o.resize==="contain"||o.resize==="cover")&&j(o.width)&&j(o.height),R=Math.max(o.maxWidth,0)||1/0,U=Math.max(o.maxHeight,0)||1/0,T=Math.max(o.minWidth,0)||0,A=Math.max(o.minHeight,0)||0,B=i/n,g=o.width,d=o.height;if(x){var G=[U,R];R=G[0],U=G[1];var X=[A,T];T=X[0],A=X[1];var $=[d,g];g=$[0],d=$[1]}L&&(B=g/d);var N=P({aspectRatio:B,width:R,height:U},"contain");R=N.width,U=N.height;var Y=P({aspectRatio:B,width:T,height:A},"cover");if(T=Y.width,A=Y.height,L){var K=P({aspectRatio:B,width:g,height:d},o.resize);g=K.width,d=K.height}else{var V=P({aspectRatio:B,width:g,height:d}),q=V.width;g=q===void 0?i:q;var J=V.height;d=J===void 0?n:J}g=Math.floor(ce(Math.min(Math.max(g,T),R))),d=Math.floor(ce(Math.min(Math.max(d,A),U)));var ge=-g/2,de=-d/2,pe=g,be=d,C=[];if(L){var Q=0,Z=0,k=i,I=n,_=P({aspectRatio:B,width:i,height:n},{contain:"cover",cover:"contain"}[o.resize]);k=_.width,I=_.height,Q=(i-k)/2,Z=(n-I)/2,C.push(Q,Z,k,I)}if(C.push(ge,de,pe,be),x){var ee=[d,g];g=ee[0],d=ee[1]}b.width=g,b.height=d,H(o.mimeType)||(o.mimeType=p.type);var te="transparent";p.size>o.convertSize&&o.convertTypes.indexOf(o.mimeType)>=0&&(o.mimeType="image/jpeg");var re=o.mimeType==="image/jpeg";if(re&&(te="#fff"),m.fillStyle=te,m.fillRect(0,0,g,d),o.beforeDraw&&o.beforeDraw.call(this,m,b),!this.aborted&&(m.save(),m.translate(g/2,d/2),m.rotate(f*Math.PI/180),m.scale(l,h),m.drawImage.apply(m,[v].concat(C)),m.restore(),o.drew&&o.drew.call(this,m,b),!this.aborted)){var ae=function(O){if(!r.aborted){var ie=function(D){return r.done({naturalWidth:i,naturalHeight:n,result:D})};if(O&&re&&o.retainExif&&r.exif&&r.exif.length>0){var ne=function(D){return ie(le(ue(Le(D,r.exif),o.mimeType)))};if(O.arrayBuffer)O.arrayBuffer().then(ne).catch(function(){r.fail(new Error("Failed to read the compressed image with Blob.arrayBuffer()."))});else{var E=new W;r.reader=E,E.onload=function(z){var D=z.target;ne(D.result)},E.onabort=function(){r.fail(new Error("Aborted to read the compressed image with FileReader."))},E.onerror=function(){r.fail(new Error("Failed to read the compressed image with FileReader."))},E.onloadend=function(){r.reader=null},E.readAsArrayBuffer(O)}}else ie(O)}};b.toBlob?b.toBlob(ae,o.mimeType,o.quality):ae(le(b.toDataURL(o.mimeType,o.quality)))}}},{key:"done",value:function(t){var r=t.naturalWidth,i=t.naturalHeight,n=t.result,u=this.file,f=this.image,s=this.options;if(w&&f.src.indexOf("blob:")===0&&w.revokeObjectURL(f.src),n)if(s.strict&&!s.retainExif&&n.size>u.size&&s.mimeType===u.type&&!(s.width>r||s.height>i||s.minWidth>r||s.minHeight>i||s.maxWidth{const i=new FileReader;i.readAsDataURL(a),i.onload=()=>{if(e){const n=i.result;t(n)}else{const n=i.result.split(",")[1];t(n)}},i.onerror=r})}function Xe(a,e={}){return new Promise((t,r)=>{a.size<(e.convertSize||1024*1024)&&t(a),new ze(a,{quality:e.quality||.8,mimeType:"image/jpeg",success(i){t(i)},error(i){r(i)}})})}export{Se as a,Xe as c,Ge as f,He as g};