compressorjs 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * Compressor.js v1.1.0
2
+ * Compressor.js v1.2.0
3
3
  * https://fengyuanchen.github.io/compressorjs
4
4
  *
5
5
  * Copyright 2018-present Chen Fengyuan
6
6
  * Released under the MIT license
7
7
  *
8
- * Date: 2021-10-01T06:37:01.455Z
8
+ * Date: 2023-02-25T11:35:56.625Z
9
9
  */
10
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Compressor=t()}(this,function(){"use strict";function t(t,e){var r,i=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),i.push.apply(i,r)),i}function a(i){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{};e%2?t(Object(a),!0).forEach(function(e){var t,r;t=i,e=a[r=e],r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(a)):t(Object(a)).forEach(function(e){Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(a,e))})}return i}function n(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r,i=arguments[t];for(r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e}).apply(this,arguments)}var e,r,o,l,c,h,u,f,i={exports:{}};e=i,r=window,o=r.HTMLCanvasElement&&r.HTMLCanvasElement.prototype,l=r.Blob&&function(){try{return Boolean(new Blob)}catch(e){return!1}}(),c=l&&r.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(e){return!1}}(),h=r.BlobBuilder||r.WebKitBlobBuilder||r.MozBlobBuilder||r.MSBlobBuilder,u=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,f=(l||h)&&r.atob&&r.ArrayBuffer&&r.Uint8Array&&function(e){var t,r,i,a,n,o=e.match(u);if(!o)throw new Error("invalid data URI");for(t=o[2]?o[1]:"text/plain"+(o[3]||";charset=US-ASCII"),i=!!o[4],o=e.slice(o[0].length),r=(i?atob:decodeURIComponent)(o),i=new ArrayBuffer(r.length),a=new Uint8Array(i),n=0;n<r.length;n+=1)a[n]=r.charCodeAt(n);return l?new Blob([c?a:i],{type:t}):((o=new h).append(i),o.getBlob(t))},r.HTMLCanvasElement&&!o.toBlob&&(o.mozGetAsFile?o.toBlob=function(e,t,r){var i=this;setTimeout(function(){r&&o.toDataURL&&f?e(f(i.toDataURL(t,r))):e(i.mozGetAsFile("blob",t))})}:o.toDataURL&&f&&(o.msToBlob?o.toBlob=function(e,t,r){var i=this;setTimeout(function(){(t&&"image/png"!==t||r)&&o.toDataURL&&f?e(f(i.toDataURL(t,r))):e(i.msToBlob(t))})}:o.toBlob=function(e,t,r){var i=this;setTimeout(function(){e(f(i.toDataURL(t,r)))})})),e.exports?e.exports=f:r.dataURLtoBlob=f;function j(e){return 0<e&&e<1/0}var T=i.exports,d={strict:!0,checkOrientation:!0,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},m="undefined"!=typeof window&&void 0!==window.document?window:{},p=Array.prototype.slice;var b=/^image\/.+$/;function R(e){return b.test(e)}var g=String.fromCharCode;var y=m.btoa;function w(e,t){for(var r,i=[],a=new Uint8Array(e);0<a.length;)i.push(g.apply(null,(r=a.subarray(0,8192),Array.from?Array.from(r):p.call(r)))),a=a.subarray(8192);return"data:".concat(t,";base64,").concat(y(i.join("")))}function v(e){var t,r,i,a,n,o,s,l=new DataView(e);try{if(255===l.getUint8(0)&&216===l.getUint8(1))for(var c=l.byteLength,h=2;h+1<c;){if(255===l.getUint8(h)&&225===l.getUint8(h+1)){r=h;break}h+=1}if(r&&(a=r+10,"Exif"===function(e,t,r){var i,a="";for(r+=t,i=t;i<r;i+=1)a+=g(e.getUint8(i));return a}(l,r+4,4)&&(!(s=18761===(n=l.getUint16(a)))&&19789!==n||42!==l.getUint16(a+2,s)||8<=(o=l.getUint32(a+4,s))&&(i=a+o))),i)for(var u,f=l.getUint16(i,s),d=0;d<f;d+=1)if(u=i+12*d+2,274===l.getUint16(u,s)){u+=8,t=l.getUint16(u,s),l.setUint16(u,1,s);break}}catch(e){t=1}return t}var U=/\.\d*(?:0|9){12}\d*$/;function k(e,t){t=1<arguments.length&&void 0!==t?t:1e11;return U.test(e)?Math.round(e*t)/t:e}function x(e,t){var r=e.aspectRatio,i=e.height,a=e.width,n=1<arguments.length&&void 0!==t?t:"none",o=j(a),e=j(i);return o&&e?(t=i*r,("contain"===n||"none"===n)&&a<t||"cover"===n&&t<a?i=a/r:a=i*r):o?i=a/r:e&&(a=i*r),{width:a,height:i}}var O=m.ArrayBuffer,B=m.FileReader,A=m.URL||m.webkitURL,M=/\.\w+$/,D=m.Compressor;return function(){function r(e,t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.file=e,this.image=new Image,this.options=a(a({},d),t),this.aborted=!1,this.result=null,this.init()}var e,t,i;return e=r,i=[{key:"noConflict",value:function(){return window.Compressor=D,r}},{key:"setDefaults",value:function(e){s(d,e)}}],(t=[{key:"init",value:function(){var i,e,a,n=this,o=this.file,t=this.options;e=o,"undefined"!=typeof Blob&&(e instanceof Blob||"[object Blob]"===Object.prototype.toString.call(e))?R(i=o.type)?A&&B?(O||(t.checkOrientation=!1),A&&!t.checkOrientation?this.load({url:A.createObjectURL(o)}):(e=new B,a=t.checkOrientation&&"image/jpeg"===i,(this.reader=e).onload=function(e){var t=e.target.result,r={};a?1<(e=v(t))||!A?(r.url=w(t,i),1<e&&s(r,function(e){var t=0,r=1,i=1;switch(e){case 2:r=-1;break;case 3:t=-180;break;case 4:i=-1;break;case 5:t=90,i=-1;break;case 6:t=90;break;case 7:t=90,r=-1;break;case 8:t=-90}return{rotate:t,scaleX:r,scaleY:i}}(e))):r.url=A.createObjectURL(o):r.url=t,n.load(r)},e.onabort=function(){n.fail(new Error("Aborted to read the image with FileReader."))},e.onerror=function(){n.fail(new Error("Failed to read the image with FileReader."))},e.onloadend=function(){n.reader=null},a?e.readAsArrayBuffer(o):e.readAsDataURL(o))):this.fail(new Error("The current browser does not support image compression.")):this.fail(new Error("The first argument must be an image File or Blob object.")):this.fail(new Error("The first argument must be a File or Blob object."))}},{key:"load",value:function(e){var t=this,r=this.file,i=this.image;i.onload=function(){t.draw(a(a({},e),{},{naturalWidth:i.naturalWidth,naturalHeight:i.naturalHeight}))},i.onabort=function(){t.fail(new Error("Aborted to load the image."))},i.onerror=function(){t.fail(new Error("Failed to load the image."))},m.navigator&&/(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(m.navigator.userAgent)&&(i.crossOrigin="anonymous"),i.alt=r.name,i.src=e.url}},{key:"draw",value:function(e){var t=this,r=e.naturalWidth,i=e.naturalHeight,a=e.rotate,n=void 0===a?0:a,o=e.scaleX,s=void 0===o?1:o,l=e.scaleY,c=void 0===l?1:l,h=this.file,u=this.image,f=this.options,d=document.createElement("canvas"),m=d.getContext("2d"),p=Math.abs(n)%180==90,b=("contain"===f.resize||"cover"===f.resize)&&j(f.width)&&j(f.height),g=Math.max(f.maxWidth,0)||1/0,y=Math.max(f.maxHeight,0)||1/0,w=Math.max(f.minWidth,0)||0,a=Math.max(f.minHeight,0)||0,o=r/i,e=f.width,l=f.height;p&&(g=(v=[y,g])[0],y=v[1],w=(v=[a,w])[0],a=v[1],e=(v=[l,e])[0],l=v[1]);var v=x({aspectRatio:o=b?e/l:o,width:g,height:y},"contain");g=v.width,y=v.height;v=x({aspectRatio:o,width:w,height:a},"cover");w=v.width,a=v.height,l=b?(e=(v=x({aspectRatio:o,width:e,height:l},f.resize)).width,v.height):(e=void 0===(O=(U=x({aspectRatio:o,width:e,height:l})).width)?r:O,void 0===(O=U.height)?i:O);var U=-(e=Math.floor(k(Math.min(Math.max(e,w),g))))/2,O=-(l=Math.floor(k(Math.min(Math.max(l,a),y))))/2,w=e,g=l,a=[];b&&(y=(o=x({aspectRatio:o,width:y=r,height:b=i},{contain:"cover",cover:"contain"}[f.resize])).width,b=o.height,a.push((r-y)/2,(i-b)/2,y,b)),a.push(U,O,w,g),p&&(e=(B=[l,e])[0],l=B[1]),d.width=e,d.height=l,R(f.mimeType)||(f.mimeType=h.type);var B="transparent";h.size>f.convertSize&&0<=f.convertTypes.indexOf(f.mimeType)&&(f.mimeType="image/jpeg"),"image/jpeg"===f.mimeType&&(B="#fff"),m.fillStyle=B,m.fillRect(0,0,e,l),f.beforeDraw&&f.beforeDraw.call(this,m,d),this.aborted||(m.save(),m.translate(e/2,l/2),m.rotate(n*Math.PI/180),m.scale(s,c),m.drawImage.apply(m,[u].concat(a)),m.restore(),f.drew&&f.drew.call(this,m,d),this.aborted||(m=function(e){t.aborted||t.done({naturalWidth:r,naturalHeight:i,result:e})},d.toBlob?d.toBlob(m,f.mimeType,f.quality):m(T(d.toDataURL(f.mimeType,f.quality)))))}},{key:"done",value:function(e){var t=e.naturalWidth,r=e.naturalHeight,i=e.result,a=this.file,n=this.image,e=this.options;A&&!e.checkOrientation&&A.revokeObjectURL(n.src),!i||e.strict&&i.size>a.size&&e.mimeType===a.type&&!(e.width>t||e.height>r||e.minWidth>t||e.minHeight>r||e.maxWidth<t||e.maxHeight<r)?i=a:(r=new Date,i.lastModified=r.getTime(),i.lastModifiedDate=r,i.name=a.name,i.name&&i.type!==a.type&&(i.name=i.name.replace(M,(a=R(a=i.type)?a.substr(6):"",".".concat(a="jpeg"===a?"jpg":a))))),this.result=i,e.success&&e.success.call(this,i)}},{key:"fail",value:function(e){var t=this.options;if(!t.error)throw e;t.error.call(this,e)}},{key:"abort",value:function(){this.aborted||(this.aborted=!0,this.reader?this.reader.abort():this.image.complete?this.fail(new Error("The compression process has been aborted.")):(this.image.onload=null,this.image.onabort()))}}])&&n(e.prototype,t),i&&n(e,i),r}()});
10
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Compressor=t()}(this,function(){"use strict";function s(){return(s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i,r=arguments[t];for(i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e}).apply(this,arguments)}var e,t,a,l,h,c,d,o,i={exports:{}},L=(e=i,"undefined"!=typeof window&&(a=(t=window).HTMLCanvasElement&&t.HTMLCanvasElement.prototype,l=t.Blob&&function(){try{return Boolean(new Blob)}catch(e){return!1}}(),h=l&&t.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(e){return!1}}(),c=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,d=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,o=(l||c)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(e){var t,i,r,a,o,n=e.match(d);if(!n)throw new Error("invalid data URI");for(t=n[2]?n[1]:"text/plain"+(n[3]||";charset=US-ASCII"),o=!!n[4],e=e.slice(n[0].length),i=(o?atob:decodeURIComponent)(e),n=new ArrayBuffer(i.length),r=new Uint8Array(n),a=0;a<i.length;a+=1)r[a]=i.charCodeAt(a);return l?new Blob([h?r:n],{type:t}):((o=new c).append(n),o.getBlob(t))},t.HTMLCanvasElement&&!a.toBlob&&(a.mozGetAsFile?a.toBlob=function(e,t,i){var r=this;setTimeout(function(){i&&a.toDataURL&&o?e(o(r.toDataURL(t,i))):e(r.mozGetAsFile("blob",t))})}:a.toDataURL&&o&&(a.msToBlob?a.toBlob=function(e,t,i){var r=this;setTimeout(function(){(t&&"image/png"!==t||i)&&a.toDataURL&&o?e(o(r.toDataURL(t,i))):e(r.msToBlob(t))})}:a.toBlob=function(e,t,i){var r=this;setTimeout(function(){e(o(r.toDataURL(t,i)))})})),e.exports?e.exports=o:t.dataURLtoBlob=o),i.exports),r={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};const n="undefined"!=typeof window&&void 0!==window.document?window:{},j=e=>0<e&&e<1/0,f=Array.prototype["slice"];function D(e){return Array.from?Array.from(e):f.call(e)}const u=/^image\/.+$/;function k(e){return u.test(e)}const m=String["fromCharCode"];const g=n["btoa"];function z(e,t){var i=[];let r=new Uint8Array(e);for(;0<r.length;)i.push(m.apply(null,D(r.subarray(0,8192)))),r=r.subarray(8192);return`data:${t};base64,`+g(i.join(""))}function b(e){var a,o,n,s,l=new DataView(e);let h;try{let t,i,r;if(255===l.getUint8(0)&&216===l.getUint8(1)){var c=l.byteLength;let e=2;for(;e+1<c;){if(255===l.getUint8(e)&&225===l.getUint8(e+1)){i=e;break}e+=1}}if(r=i&&(a=i+4,o=i+10,"Exif"===function(e,t,i){let r="",a;for(i+=t,a=t;a<i;a+=1)r+=m(e.getUint8(a));return r}(l,a,4))&&(n=l.getUint16(o),(t=18761===n)||19789===n)&&42===l.getUint16(o+2,t)&&8<=(s=l.getUint32(o+4,t))?o+s:r){var d,f=l.getUint16(r,t);let e;for(e=0;e<f;e+=1)if(d=r+12*e+2,274===l.getUint16(d,t)){d+=8,h=l.getUint16(d,t),l.setUint16(d,1,t);break}}}catch(e){h=1}return h}const p=/\.\d*(?:0|9){12}\d*$/;function H(e,t){t=1<arguments.length&&void 0!==t?t:1e11;return p.test(e)?Math.round(e*t)/t:e}function O(e,t){let{aspectRatio:i,height:r,width:a}=e;var o,e=1<arguments.length&&void 0!==t?t:"none",t=j(a),n=j(r);return t&&n?(o=r*i,("contain"===e||"none"===e)&&o>a||"cover"===e&&o<a?r=a/i:a=r*i):t?r=a/i:n&&(a=r*i),{width:a,height:r}}const{ArrayBuffer:w,FileReader:C}=n,y=n.URL||n.webkitURL,v=/\.\w+$/,B=n.Compressor;return class U{constructor(e,t){this.file=e,this.exif=[],this.image=new Image,this.options={...r,...t},this.aborted=!1,this.result=null,this.init()}init(){const{file:r,options:e}=this;if(t=r,"undefined"!=typeof Blob&&(t instanceof Blob||"[object Blob]"===Object.prototype.toString.call(t))){const a=r.type;if(k(a))if(y&&C){w||(e.checkOrientation=!1,e.retainExif=!1);var t="image/jpeg"===a;const o=t&&e.checkOrientation,n=t&&e.retainExif;!y||o||n?(t=new C,(this.reader=t).onload=e=>{var e=(e=e.target).result,t={};let i=1;o&&1<(i=b(e))&&s(t,function(e){let t=0,i=1,r=1;switch(e){case 2:i=-1;break;case 3:t=-180;break;case 4:r=-1;break;case 5:t=90,r=-1;break;case 6:t=90;break;case 7:t=90,i=-1;break;case 8:t=-90}return{rotate:t,scaleX:i,scaleY:r}}(i)),n&&(this.exif=function(e){var t=D(new Uint8Array(e)),i=t.length,r=[];let a=0;for(;a+3<i;){var o=t[a],n=t[a+1];if(255===o&&218===n)break;255===o&&216===n?a+=2:(o=256*t[a+2]+t[a+3],n=a+o+2,o=t.slice(a,n),r.push(o),a=n)}return r.reduce((e,t)=>255===t[0]&&225===t[1]?e.concat(t):e,[])}(e)),o||n?!y||1<i?t.url=z(e,a):t.url=y.createObjectURL(r):t.url=e,this.load(t)},t.onabort=()=>{this.fail(new Error("Aborted to read the image with FileReader."))},t.onerror=()=>{this.fail(new Error("Failed to read the image with FileReader."))},t.onloadend=()=>{this.reader=null},o||n?t.readAsArrayBuffer(r):t.readAsDataURL(r)):this.load({url:y.createObjectURL(r)})}else this.fail(new Error("The current browser does not support image compression."));else this.fail(new Error("The first argument must be an image File or Blob object."))}else this.fail(new Error("The first argument must be a File or Blob object."))}load(e){const{file:t,image:i}=this;i.onload=()=>{this.draw({...e,naturalWidth:i.naturalWidth,naturalHeight:i.naturalHeight})},i.onabort=()=>{this.fail(new Error("Aborted to load the image."))},i.onerror=()=>{this.fail(new Error("Failed to load the image."))},n.navigator&&/(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(n.navigator.userAgent)&&(i.crossOrigin="anonymous"),i.alt=t.name,i.src=e.url}draw(e){let{naturalWidth:a,naturalHeight:o,rotate:t=0,scaleX:i=1,scaleY:r=1}=e;const{file:n,image:s,options:l}=this;var h=(e=document.createElement("canvas")).getContext("2d"),c=Math.abs(t)%180==90,d=("contain"===l.resize||"cover"===l.resize)&&j(l.width)&&j(l.height);let f=Math.max(l.maxWidth,0)||1/0,u=Math.max(l.maxHeight,0)||1/0,m=Math.max(l.minWidth,0)||0,g=Math.max(l.minHeight,0)||0,b=a/o,{width:p,height:w}=l;c&&([f,u]=[u,f],[m,g]=[g,m],[p,w]=[w,p]),d&&(b=p/w),{width:f,height:u}=O({aspectRatio:b,width:f,height:u},"contain"),{width:m,height:g}=O({aspectRatio:b,width:m,height:g},"cover"),d?{width:p,height:w}=O({aspectRatio:b,width:p,height:w},l.resize):{width:p=a,height:w=o}=O({aspectRatio:b,width:p,height:w}),p=Math.floor(H(Math.min(Math.max(p,m),f))),w=Math.floor(H(Math.min(Math.max(w,g),u)));var y,v,B,U=-p/2,x=-w/2,A=p,R=w,T=[];d&&(y=d=0,v=a,B=o,{width:v,height:B}=O({aspectRatio:b,width:a,height:o},{contain:"cover",cover:"contain"}[l.resize]),d=(a-v)/2,y=(o-B)/2,T.push(d,y,v,B)),T.push(U,x,A,R),c&&([p,w]=[w,p]),e.width=p,e.height=w,k(l.mimeType)||(l.mimeType=n.type);let E="transparent";n.size>l.convertSize&&0<=l.convertTypes.indexOf(l.mimeType)&&(l.mimeType="image/jpeg");const M="image/jpeg"===l.mimeType;M&&(E="#fff"),h.fillStyle=E,h.fillRect(0,0,p,w),l.beforeDraw&&l.beforeDraw.call(this,h,e),this.aborted||(h.save(),h.translate(p/2,w/2),h.rotate(t*Math.PI/180),h.scale(i,r),h.drawImage(s,...T),h.restore(),l.drew&&l.drew.call(this,h,e),this.aborted)||(d=e=>{if(!this.aborted){const r=e=>this.done({naturalWidth:a,naturalHeight:o,result:e});if(e&&M&&l.retainExif&&this.exif&&0<this.exif.length){const i=e=>{return r(L(z((t=this.exif,255!==(i=D(new Uint8Array(e)))[2]||224!==i[3]?e:(e=256*i[4]+i[5],t=[255,216].concat(t,i.slice(4+e)),new Uint8Array(t))),l.mimeType)));var t,i};var t;e.arrayBuffer?e.arrayBuffer().then(i).catch(()=>{this.fail(new Error("Failed to read the compressed image with Blob.arrayBuffer()."))}):(t=new C,(this.reader=t).onload=e=>{e=e.target,i(e.result)},t.onabort=()=>{this.fail(new Error("Aborted to read the compressed image with FileReader."))},t.onerror=()=>{this.fail(new Error("Failed to read the compressed image with FileReader."))},t.onloadend=()=>{this.reader=null},t.readAsArrayBuffer(e))}else r(e)}},e.toBlob?e.toBlob(d,l.mimeType,l.quality):d(L(e.toDataURL(l.mimeType,l.quality))))}done(e){let{naturalWidth:t,naturalHeight:i,result:r}=e;var{file:e,image:a,options:o}=this;y&&0===a.src.indexOf("blob:")&&y.revokeObjectURL(a.src),!r||o.strict&&!o.retainExif&&r.size>e.size&&o.mimeType===e.type&&!(o.width>t||o.height>i||o.minWidth>t||o.minHeight>i||o.maxWidth<t||o.maxHeight<i)?r=e:(a=new Date,r.lastModified=a.getTime(),r.lastModifiedDate=a,r.name=e.name,r.name&&r.type!==e.type&&(r.name=r.name.replace(v,function(e){let t=k(e)?e.substr(6):"";return"."+(t="jpeg"===t?"jpg":t)}(r.type)))),this.result=r,o.success&&o.success.call(this,r)}fail(e){var t=this.options;if(!t.error)throw e;t.error.call(this,e)}abort(){this.aborted||(this.aborted=!0,this.reader?this.reader.abort():this.image.complete?this.fail(new Error("The compression process has been aborted.")):(this.image.onload=null,this.image.onabort()))}static noConflict(){return window.Compressor=B,U}static setDefaults(e){s(r,e)}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compressorjs",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "JavaScript image compressor.",
5
5
  "main": "dist/compressor.common.js",
6
6
  "module": "dist/compressor.esm.js",
@@ -35,7 +35,7 @@
35
35
  "compress": "uglifyjs dist/compressor.js -o dist/compressor.min.js -c -m --comments /^!/",
36
36
  "dev": "rollup -c -m -w",
37
37
  "lint": "npm run lint:js && npm run lint:css",
38
- "lint:css": "stylelint {docs,examples}/**/*.{css,html} --fix",
38
+ "lint:css": "stylelint docs/**/*.css --fix",
39
39
  "lint:js": "eslint src test *.js --fix",
40
40
  "prepare": "husky install",
41
41
  "release": "npm run clean && npm run lint && npm run build && npm run compress && npm test",
@@ -48,40 +48,40 @@
48
48
  "is-blob": "^2.1.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/core": "^7.15.5",
52
- "@babel/plugin-transform-object-assign": "^7.14.5",
53
- "@babel/preset-env": "^7.15.6",
54
- "@commitlint/cli": "^13.2.0",
55
- "@commitlint/config-conventional": "^13.2.0",
56
- "@rollup/plugin-babel": "^5.3.0",
57
- "@rollup/plugin-commonjs": "^20.0.0",
58
- "@rollup/plugin-node-resolve": "^13.0.5",
59
- "@rollup/plugin-replace": "^3.0.0",
60
- "babel-plugin-istanbul": "^6.0.0",
61
- "chai": "^4.3.4",
51
+ "@babel/core": "^7.21.0",
52
+ "@babel/plugin-transform-object-assign": "^7.18.6",
53
+ "@babel/preset-env": "^7.20.2",
54
+ "@commitlint/cli": "^17.4.4",
55
+ "@commitlint/config-conventional": "^17.4.4",
56
+ "@rollup/plugin-babel": "^5.3.1",
57
+ "@rollup/plugin-commonjs": "^21.1.0",
58
+ "@rollup/plugin-node-resolve": "^13.3.0",
59
+ "@rollup/plugin-replace": "^3.1.0",
60
+ "babel-plugin-istanbul": "^6.1.1",
61
+ "chai": "^4.3.7",
62
62
  "change-case": "^4.1.2",
63
63
  "codecov": "^3.8.3",
64
64
  "create-banner": "^2.0.0",
65
65
  "cross-env": "^7.0.3",
66
- "del-cli": "^4.0.1",
67
- "eslint": "^7.32.0",
68
- "eslint-config-airbnb-base": "^14.2.1",
69
- "eslint-plugin-import": "^2.24.2",
70
- "husky": "^7.0.2",
71
- "karma": "^6.3.4",
66
+ "del-cli": "^5.0.0",
67
+ "eslint": "^8.34.0",
68
+ "eslint-config-airbnb-base": "^15.0.0",
69
+ "eslint-plugin-import": "^2.27.5",
70
+ "husky": "^8.0.3",
71
+ "karma": "^6.4.1",
72
72
  "karma-chai": "^0.1.0",
73
- "karma-chrome-launcher": "^3.1.0",
73
+ "karma-chrome-launcher": "^3.1.1",
74
74
  "karma-coverage-istanbul-reporter": "^3.0.3",
75
75
  "karma-mocha": "^2.0.1",
76
76
  "karma-mocha-reporter": "^2.2.5",
77
- "karma-rollup-preprocessor": "^7.0.7",
78
- "lint-staged": "^11.1.2",
79
- "mocha": "^9.1.2",
80
- "puppeteer": "^10.4.0",
81
- "rollup": "^2.57.0",
82
- "stylelint": "^13.13.1",
83
- "stylelint-config-standard": "^22.0.0",
84
- "stylelint-order": "^4.1.0",
85
- "uglify-js": "^3.14.2"
77
+ "karma-rollup-preprocessor": "^7.0.8",
78
+ "lint-staged": "^13.1.2",
79
+ "mocha": "^10.2.0",
80
+ "puppeteer": "^19.7.2",
81
+ "rollup": "^2.79.1",
82
+ "stylelint": "^15.2.0",
83
+ "stylelint-config-standard": "^30.0.1",
84
+ "stylelint-order": "^6.0.2",
85
+ "uglify-js": "^3.17.4"
86
86
  }
87
87
  }
package/src/defaults.js CHANGED
@@ -13,6 +13,12 @@ export default {
13
13
  */
14
14
  checkOrientation: true,
15
15
 
16
+ /**
17
+ * Indicates if retain the image's Exif information after compressed.
18
+ * @type {boolean}
19
+ */
20
+ retainExif: false,
21
+
16
22
  /**
17
23
  * The max width of the output image.
18
24
  * @type {number}
package/src/index.js CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  normalizeDecimalNumber,
14
14
  parseOrientation,
15
15
  resetAndGetOrientation,
16
+ getExif,
17
+ insertExif,
16
18
  } from './utilities';
17
19
 
18
20
  const { ArrayBuffer, FileReader } = WINDOW;
@@ -32,6 +34,7 @@ export default class Compressor {
32
34
  */
33
35
  constructor(file, options) {
34
36
  this.file = file;
37
+ this.exif = [];
35
38
  this.image = new Image();
36
39
  this.options = {
37
40
  ...DEFAULTS,
@@ -64,33 +67,48 @@ export default class Compressor {
64
67
 
65
68
  if (!ArrayBuffer) {
66
69
  options.checkOrientation = false;
70
+ options.retainExif = false;
67
71
  }
68
72
 
69
- if (URL && !options.checkOrientation) {
73
+ const isJPEGImage = mimeType === 'image/jpeg';
74
+ const checkOrientation = isJPEGImage && options.checkOrientation;
75
+ const retainExif = isJPEGImage && options.retainExif;
76
+
77
+ if (URL && !checkOrientation && !retainExif) {
70
78
  this.load({
71
79
  url: URL.createObjectURL(file),
72
80
  });
73
81
  } else {
74
82
  const reader = new FileReader();
75
- const checkOrientation = options.checkOrientation && mimeType === 'image/jpeg';
76
83
 
77
84
  this.reader = reader;
78
85
  reader.onload = ({ target }) => {
79
86
  const { result } = target;
80
87
  const data = {};
88
+ let orientation = 1;
81
89
 
82
90
  if (checkOrientation) {
83
91
  // Reset the orientation value to its default value 1
84
92
  // as some iOS browsers will render image with its orientation
85
- const orientation = resetAndGetOrientation(result);
93
+ orientation = resetAndGetOrientation(result);
86
94
 
87
- if (orientation > 1 || !URL) {
88
- // Generate a new URL which has the default orientation value
89
- data.url = arrayBufferToDataURL(result, mimeType);
95
+ if (orientation > 1) {
96
+ Object.assign(data, parseOrientation(orientation));
97
+ }
98
+ }
90
99
 
91
- if (orientation > 1) {
92
- Object.assign(data, parseOrientation(orientation));
93
- }
100
+ if (retainExif) {
101
+ this.exif = getExif(result);
102
+ }
103
+
104
+ if (checkOrientation || retainExif) {
105
+ if (
106
+ !URL
107
+
108
+ // Generate a new URL with the default orientation value 1.
109
+ || orientation > 1
110
+ ) {
111
+ data.url = arrayBufferToDataURL(result, mimeType);
94
112
  } else {
95
113
  data.url = URL.createObjectURL(file);
96
114
  }
@@ -110,7 +128,7 @@ export default class Compressor {
110
128
  this.reader = null;
111
129
  };
112
130
 
113
- if (checkOrientation) {
131
+ if (checkOrientation || retainExif) {
114
132
  reader.readAsArrayBuffer(file);
115
133
  } else {
116
134
  reader.readAsDataURL(file);
@@ -249,7 +267,9 @@ export default class Compressor {
249
267
  options.mimeType = 'image/jpeg';
250
268
  }
251
269
 
252
- if (options.mimeType === 'image/jpeg') {
270
+ const isJPEGImage = options.mimeType === 'image/jpeg';
271
+
272
+ if (isJPEGImage) {
253
273
  fillStyle = '#fff';
254
274
  }
255
275
 
@@ -280,20 +300,52 @@ export default class Compressor {
280
300
  return;
281
301
  }
282
302
 
283
- const done = (result) => {
303
+ const callback = (blob) => {
284
304
  if (!this.aborted) {
285
- this.done({
305
+ const done = (result) => this.done({
286
306
  naturalWidth,
287
307
  naturalHeight,
288
308
  result,
289
309
  });
310
+
311
+ if (blob && isJPEGImage && options.retainExif && this.exif && this.exif.length > 0) {
312
+ const next = (arrayBuffer) => done(toBlob(arrayBufferToDataURL(
313
+ insertExif(arrayBuffer, this.exif),
314
+ options.mimeType,
315
+ )));
316
+
317
+ if (blob.arrayBuffer) {
318
+ blob.arrayBuffer().then(next).catch(() => {
319
+ this.fail(new Error('Failed to read the compressed image with Blob.arrayBuffer().'));
320
+ });
321
+ } else {
322
+ const reader = new FileReader();
323
+
324
+ this.reader = reader;
325
+ reader.onload = ({ target }) => {
326
+ next(target.result);
327
+ };
328
+ reader.onabort = () => {
329
+ this.fail(new Error('Aborted to read the compressed image with FileReader.'));
330
+ };
331
+ reader.onerror = () => {
332
+ this.fail(new Error('Failed to read the compressed image with FileReader.'));
333
+ };
334
+ reader.onloadend = () => {
335
+ this.reader = null;
336
+ };
337
+ reader.readAsArrayBuffer(blob);
338
+ }
339
+ } else {
340
+ done(blob);
341
+ }
290
342
  }
291
343
  };
292
344
 
293
345
  if (canvas.toBlob) {
294
- canvas.toBlob(done, options.mimeType, options.quality);
346
+ canvas.toBlob(callback, options.mimeType, options.quality);
295
347
  } else {
296
- done(toBlob(canvas.toDataURL(options.mimeType, options.quality)));
348
+ callback(toBlob(canvas.toDataURL(options.mimeType, options.quality)));
297
349
  }
298
350
  }
299
351
 
@@ -304,20 +356,26 @@ export default class Compressor {
304
356
  }) {
305
357
  const { file, image, options } = this;
306
358
 
307
- if (URL && !options.checkOrientation) {
359
+ if (URL && image.src.indexOf('blob:') === 0) {
308
360
  URL.revokeObjectURL(image.src);
309
361
  }
310
362
 
311
363
  if (result) {
312
364
  // Returns original file if the result is greater than it and without size related options
313
- if (options.strict && result.size > file.size && options.mimeType === file.type && !(
314
- options.width > naturalWidth
315
- || options.height > naturalHeight
316
- || options.minWidth > naturalWidth
317
- || options.minHeight > naturalHeight
318
- || options.maxWidth < naturalWidth
319
- || options.maxHeight < naturalHeight
320
- )) {
365
+ if (
366
+ options.strict
367
+ && !options.retainExif
368
+ && result.size > file.size
369
+ && options.mimeType === file.type
370
+ && !(
371
+ options.width > naturalWidth
372
+ || options.height > naturalHeight
373
+ || options.minWidth > naturalWidth
374
+ || options.minHeight > naturalHeight
375
+ || options.maxWidth < naturalWidth
376
+ || options.maxHeight < naturalHeight
377
+ )
378
+ ) {
321
379
  result = file;
322
380
  } else {
323
381
  const date = new Date();
package/src/utilities.js CHANGED
@@ -279,3 +279,64 @@ export function getAdjustedSizes(
279
279
  height,
280
280
  };
281
281
  }
282
+
283
+ /**
284
+ * Get Exif information from the given array buffer.
285
+ * @param {ArrayBuffer} arrayBuffer - The array buffer to read.
286
+ * @returns {Array} The read Exif information.
287
+ */
288
+ export function getExif(arrayBuffer) {
289
+ const array = toArray(new Uint8Array(arrayBuffer));
290
+ const { length } = array;
291
+ const segments = [];
292
+ let start = 0;
293
+
294
+ while (start + 3 < length) {
295
+ const value = array[start];
296
+ const next = array[start + 1];
297
+
298
+ // SOS (Start of Scan)
299
+ if (value === 0xFF && next === 0xDA) {
300
+ break;
301
+ }
302
+
303
+ // SOI (Start of Image)
304
+ if (value === 0xFF && next === 0xD8) {
305
+ start += 2;
306
+ } else {
307
+ const offset = array[start + 2] * 256 + array[start + 3];
308
+ const end = start + offset + 2;
309
+ const segment = array.slice(start, end);
310
+
311
+ segments.push(segment);
312
+ start = end;
313
+ }
314
+ }
315
+
316
+ return segments.reduce((exifArray, current) => {
317
+ if (current[0] === 0xFF && current[1] === 0xE1) {
318
+ return exifArray.concat(current);
319
+ }
320
+
321
+ return exifArray;
322
+ }, []);
323
+ }
324
+
325
+ /**
326
+ * Insert Exif information into the given array buffer.
327
+ * @param {ArrayBuffer} arrayBuffer - The array buffer to transform.
328
+ * @param {Array} exifArray - The Exif information to insert.
329
+ * @returns {ArrayBuffer} The transformed array buffer.
330
+ */
331
+ export function insertExif(arrayBuffer, exifArray) {
332
+ const array = toArray(new Uint8Array(arrayBuffer));
333
+
334
+ if (array[2] !== 0xFF || array[3] !== 0xE0) {
335
+ return arrayBuffer;
336
+ }
337
+
338
+ const app0Length = array[4] * 256 + array[5];
339
+ const newArrayBuffer = [0xFF, 0xD8].concat(exifArray, array.slice(4 + app0Length));
340
+
341
+ return new Uint8Array(newArrayBuffer);
342
+ }
package/types/index.d.ts CHANGED
@@ -2,6 +2,7 @@ declare namespace Compressor {
2
2
  export interface Options {
3
3
  strict?: boolean;
4
4
  checkOrientation?: boolean;
5
+ retainExif?: boolean;
5
6
  maxWidth?: number;
6
7
  maxHeight?: number;
7
8
  minWidth?: number;
package/CHANGELOG.md DELETED
@@ -1,44 +0,0 @@
1
- # Changelog
2
-
3
- ## 1.1.0 (Oct 1, 2021)
4
-
5
- - Add 2 new options: `convertTypes` (#123) and `resize` (#130).
6
- - Ignore the `strict` option when the `maxWidth/Height` option is set and its value is less than the natural width/height of the image (#134).
7
- .
8
-
9
- ## 1.0.7 (Nov 28, 2020)
10
-
11
- - Update the built-in dependencies for better adaptability.
12
-
13
- ## 1.0.6 (Nov 23, 2019)
14
-
15
- - Fix the `The operation is insecure` error (#57).
16
-
17
- ## 1.0.5 (Jan 23, 2019)
18
-
19
- - Fix the wrong generated URL when the given image's orientation is 1 (#64).
20
-
21
- ## 1.0.4 (Jan 19, 2019)
22
-
23
- - Regenerate the initial URL only when the orientation was reset for better performance (#63).
24
-
25
- ## 1.0.3 (Dec 18, 2018)
26
-
27
- - Convert `TypedArray` to `Array` manually instead of using Babel helpers for better browser compatibility (#60).
28
-
29
- ## 1.0.2 (Dec 10, 2018)
30
-
31
- - Upgrade `is-blob` to v2.
32
- - Move `examples` folder to `docs` folder.
33
-
34
- ## 1.0.1 (Oct 24, 2018)
35
-
36
- - Simplify the state of canvas for the `beforeDraw` option.
37
- - Ignore range error when the image does not have correct Exif information.
38
-
39
- ## 1.0.0 (Oct 15, 2018)
40
-
41
- - Supports 15 options: `beforeDraw`, `checkOrientation`, `convertSize`, `drew`, `error`, `height`, `maxHeight`, `maxWidth`, `mimeType`, `minHeight`, `minWidth`, `quality`, `strict`, `success` and `width`.
42
- - Support 1 method: `abort`.
43
- - Support to compress images of `File` or `Blob` object.
44
- - Supports to translate Exif Orientation information.
@@ -1 +0,0 @@
1
- {"version":3,"file":"compressor.common.js","sources":["../node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.js","../node_modules/is-blob/index.js","../src/defaults.js","../src/constants.js","../src/utilities.js","../src/index.js"],"sourcesContent":["/*\n * JavaScript Canvas to Blob\n * https://github.com/blueimp/JavaScript-Canvas-to-Blob\n *\n * Copyright 2012, Sebastian Tschan\n * https://blueimp.net\n *\n * Licensed under the MIT license:\n * https://opensource.org/licenses/MIT\n *\n * Based on stackoverflow user Stoive's code snippet:\n * http://stackoverflow.com/q/4998908\n */\n\n/* global define, Uint8Array, ArrayBuffer, module */\n\n;(function (window) {\n 'use strict'\n\n var CanvasPrototype =\n window.HTMLCanvasElement && window.HTMLCanvasElement.prototype\n var hasBlobConstructor =\n window.Blob &&\n (function () {\n try {\n return Boolean(new Blob())\n } catch (e) {\n return false\n }\n })()\n var hasArrayBufferViewSupport =\n hasBlobConstructor &&\n window.Uint8Array &&\n (function () {\n try {\n return new Blob([new Uint8Array(100)]).size === 100\n } catch (e) {\n return false\n }\n })()\n var BlobBuilder =\n window.BlobBuilder ||\n window.WebKitBlobBuilder ||\n window.MozBlobBuilder ||\n window.MSBlobBuilder\n var dataURIPattern = /^data:((.*?)(;charset=.*?)?)(;base64)?,/\n var dataURLtoBlob =\n (hasBlobConstructor || BlobBuilder) &&\n window.atob &&\n window.ArrayBuffer &&\n window.Uint8Array &&\n function (dataURI) {\n var matches,\n mediaType,\n isBase64,\n dataString,\n byteString,\n arrayBuffer,\n intArray,\n i,\n bb\n // Parse the dataURI components as per RFC 2397\n matches = dataURI.match(dataURIPattern)\n if (!matches) {\n throw new Error('invalid data URI')\n }\n // Default to text/plain;charset=US-ASCII\n mediaType = matches[2]\n ? matches[1]\n : 'text/plain' + (matches[3] || ';charset=US-ASCII')\n isBase64 = !!matches[4]\n dataString = dataURI.slice(matches[0].length)\n if (isBase64) {\n // Convert base64 to raw binary data held in a string:\n byteString = atob(dataString)\n } else {\n // Convert base64/URLEncoded data component to raw binary:\n byteString = decodeURIComponent(dataString)\n }\n // Write the bytes of the string to an ArrayBuffer:\n arrayBuffer = new ArrayBuffer(byteString.length)\n intArray = new Uint8Array(arrayBuffer)\n for (i = 0; i < byteString.length; i += 1) {\n intArray[i] = byteString.charCodeAt(i)\n }\n // Write the ArrayBuffer (or ArrayBufferView) to a blob:\n if (hasBlobConstructor) {\n return new Blob([hasArrayBufferViewSupport ? intArray : arrayBuffer], {\n type: mediaType\n })\n }\n bb = new BlobBuilder()\n bb.append(arrayBuffer)\n return bb.getBlob(mediaType)\n }\n if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {\n if (CanvasPrototype.mozGetAsFile) {\n CanvasPrototype.toBlob = function (callback, type, quality) {\n var self = this\n setTimeout(function () {\n if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {\n callback(dataURLtoBlob(self.toDataURL(type, quality)))\n } else {\n callback(self.mozGetAsFile('blob', type))\n }\n })\n }\n } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {\n if (CanvasPrototype.msToBlob) {\n CanvasPrototype.toBlob = function (callback, type, quality) {\n var self = this\n setTimeout(function () {\n if (\n ((type && type !== 'image/png') || quality) &&\n CanvasPrototype.toDataURL &&\n dataURLtoBlob\n ) {\n callback(dataURLtoBlob(self.toDataURL(type, quality)))\n } else {\n callback(self.msToBlob(type))\n }\n })\n }\n } else {\n CanvasPrototype.toBlob = function (callback, type, quality) {\n var self = this\n setTimeout(function () {\n callback(dataURLtoBlob(self.toDataURL(type, quality)))\n })\n }\n }\n }\n }\n if (typeof define === 'function' && define.amd) {\n define(function () {\n return dataURLtoBlob\n })\n } else if (typeof module === 'object' && module.exports) {\n module.exports = dataURLtoBlob\n } else {\n window.dataURLtoBlob = dataURLtoBlob\n }\n})(window)\n","'use strict';\n\nmodule.exports = value => {\n\tif (typeof Blob === 'undefined') {\n\t\treturn false;\n\t}\n\n\treturn value instanceof Blob || Object.prototype.toString.call(value) === '[object Blob]';\n};\n","export default {\n /**\n * Indicates if output the original image instead of the compressed one\n * when the size of the compressed image is greater than the original one's\n * @type {boolean}\n */\n strict: true,\n\n /**\n * Indicates if read the image's Exif Orientation information,\n * and then rotate or flip the image automatically.\n * @type {boolean}\n */\n checkOrientation: true,\n\n /**\n * The max width of the output image.\n * @type {number}\n */\n maxWidth: Infinity,\n\n /**\n * The max height of the output image.\n * @type {number}\n */\n maxHeight: Infinity,\n\n /**\n * The min width of the output image.\n * @type {number}\n */\n minWidth: 0,\n\n /**\n * The min height of the output image.\n * @type {number}\n */\n minHeight: 0,\n\n /**\n * The width of the output image.\n * If not specified, the natural width of the source image will be used.\n * @type {number}\n */\n width: undefined,\n\n /**\n * The height of the output image.\n * If not specified, the natural height of the source image will be used.\n * @type {number}\n */\n height: undefined,\n\n /**\n * Sets how the size of the image should be resized to the container\n * specified by the `width` and `height` options.\n * @type {string}\n */\n resize: 'none',\n\n /**\n * The quality of the output image.\n * It must be a number between `0` and `1`,\n * and only available for `image/jpeg` and `image/webp` images.\n * Check out {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob canvas.toBlob}.\n * @type {number}\n */\n quality: 0.8,\n\n /**\n * The mime type of the output image.\n * By default, the original mime type of the source image file will be used.\n * @type {string}\n */\n mimeType: 'auto',\n\n /**\n * Files whose file type is included in this list,\n * and whose file size exceeds the `convertSize` value will be converted to JPEGs.\n * @type {string|Array}\n */\n convertTypes: ['image/png'],\n\n /**\n * PNG files over this size (5 MB by default) will be converted to JPEGs.\n * To disable this, just set the value to `Infinity`.\n * @type {number}\n */\n convertSize: 5000000,\n\n /**\n * The hook function to execute before draw the image into the canvas for compression.\n * @type {Function}\n * @param {CanvasRenderingContext2D} context - The 2d rendering context of the canvas.\n * @param {HTMLCanvasElement} canvas - The canvas for compression.\n * @example\n * function (context, canvas) {\n * context.fillStyle = '#fff';\n * }\n */\n beforeDraw: null,\n\n /**\n * The hook function to execute after drew the image into the canvas for compression.\n * @type {Function}\n * @param {CanvasRenderingContext2D} context - The 2d rendering context of the canvas.\n * @param {HTMLCanvasElement} canvas - The canvas for compression.\n * @example\n * function (context, canvas) {\n * context.filter = 'grayscale(100%)';\n * }\n */\n drew: null,\n\n /**\n * The hook function to execute when success to compress the image.\n * @type {Function}\n * @param {File} file - The compressed image File object.\n * @example\n * function (file) {\n * console.log(file);\n * }\n */\n success: null,\n\n /**\n * The hook function to execute when fail to compress the image.\n * @type {Function}\n * @param {Error} err - An Error object.\n * @example\n * function (err) {\n * console.log(err.message);\n * }\n */\n error: null,\n};\n","export const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';\nexport const WINDOW = IS_BROWSER ? window : {};\n","import {\n WINDOW,\n} from './constants';\n\n/**\n * Check if the given value is a positive number.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given value is a positive number, else `false`.\n */\nexport const isPositiveNumber = (value) => value > 0 && value < Infinity;\n\nconst { slice } = Array.prototype;\n\n/**\n * Convert array-like or iterable object to an array.\n * @param {*} value - The value to convert.\n * @returns {Array} Returns a new array.\n */\nexport function toArray(value) {\n return Array.from ? Array.from(value) : slice.call(value);\n}\n\nconst REGEXP_IMAGE_TYPE = /^image\\/.+$/;\n\n/**\n * Check if the given value is a mime type of image.\n * @param {*} value - The value to check.\n * @returns {boolean} Returns `true` if the given is a mime type of image, else `false`.\n */\nexport function isImageType(value) {\n return REGEXP_IMAGE_TYPE.test(value);\n}\n\n/**\n * Convert image type to extension.\n * @param {string} value - The image type to convert.\n * @returns {boolean} Returns the image extension.\n */\nexport function imageTypeToExtension(value) {\n let extension = isImageType(value) ? value.substr(6) : '';\n\n if (extension === 'jpeg') {\n extension = 'jpg';\n }\n\n return `.${extension}`;\n}\n\nconst { fromCharCode } = String;\n\n/**\n * Get string from char code in data view.\n * @param {DataView} dataView - The data view for read.\n * @param {number} start - The start index.\n * @param {number} length - The read length.\n * @returns {string} The read result.\n */\nexport function getStringFromCharCode(dataView, start, length) {\n let str = '';\n let i;\n\n length += start;\n\n for (i = start; i < length; i += 1) {\n str += fromCharCode(dataView.getUint8(i));\n }\n\n return str;\n}\n\nconst { btoa } = WINDOW;\n\n/**\n * Transform array buffer to Data URL.\n * @param {ArrayBuffer} arrayBuffer - The array buffer to transform.\n * @param {string} mimeType - The mime type of the Data URL.\n * @returns {string} The result Data URL.\n */\nexport function arrayBufferToDataURL(arrayBuffer, mimeType) {\n const chunks = [];\n const chunkSize = 8192;\n let uint8 = new Uint8Array(arrayBuffer);\n\n while (uint8.length > 0) {\n // XXX: Babel's `toConsumableArray` helper will throw error in IE or Safari 9\n // eslint-disable-next-line prefer-spread\n chunks.push(fromCharCode.apply(null, toArray(uint8.subarray(0, chunkSize))));\n uint8 = uint8.subarray(chunkSize);\n }\n\n return `data:${mimeType};base64,${btoa(chunks.join(''))}`;\n}\n\n/**\n * Get orientation value from given array buffer.\n * @param {ArrayBuffer} arrayBuffer - The array buffer to read.\n * @returns {number} The read orientation value.\n */\nexport function resetAndGetOrientation(arrayBuffer) {\n const dataView = new DataView(arrayBuffer);\n let orientation;\n\n // Ignores range error when the image does not have correct Exif information\n try {\n let littleEndian;\n let app1Start;\n let ifdStart;\n\n // Only handle JPEG image (start by 0xFFD8)\n if (dataView.getUint8(0) === 0xFF && dataView.getUint8(1) === 0xD8) {\n const length = dataView.byteLength;\n let offset = 2;\n\n while (offset + 1 < length) {\n if (dataView.getUint8(offset) === 0xFF && dataView.getUint8(offset + 1) === 0xE1) {\n app1Start = offset;\n break;\n }\n\n offset += 1;\n }\n }\n\n if (app1Start) {\n const exifIDCode = app1Start + 4;\n const tiffOffset = app1Start + 10;\n\n if (getStringFromCharCode(dataView, exifIDCode, 4) === 'Exif') {\n const endianness = dataView.getUint16(tiffOffset);\n\n littleEndian = endianness === 0x4949;\n\n if (littleEndian || endianness === 0x4D4D /* bigEndian */) {\n if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) {\n const firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian);\n\n if (firstIFDOffset >= 0x00000008) {\n ifdStart = tiffOffset + firstIFDOffset;\n }\n }\n }\n }\n }\n\n if (ifdStart) {\n const length = dataView.getUint16(ifdStart, littleEndian);\n let offset;\n let i;\n\n for (i = 0; i < length; i += 1) {\n offset = ifdStart + (i * 12) + 2;\n\n if (dataView.getUint16(offset, littleEndian) === 0x0112 /* Orientation */) {\n // 8 is the offset of the current tag's value\n offset += 8;\n\n // Get the original orientation value\n orientation = dataView.getUint16(offset, littleEndian);\n\n // Override the orientation with its default value\n dataView.setUint16(offset, 1, littleEndian);\n break;\n }\n }\n }\n } catch (e) {\n orientation = 1;\n }\n\n return orientation;\n}\n\n/**\n * Parse Exif Orientation value.\n * @param {number} orientation - The orientation to parse.\n * @returns {Object} The parsed result.\n */\nexport function parseOrientation(orientation) {\n let rotate = 0;\n let scaleX = 1;\n let scaleY = 1;\n\n switch (orientation) {\n // Flip horizontal\n case 2:\n scaleX = -1;\n break;\n\n // Rotate left 180°\n case 3:\n rotate = -180;\n break;\n\n // Flip vertical\n case 4:\n scaleY = -1;\n break;\n\n // Flip vertical and rotate right 90°\n case 5:\n rotate = 90;\n scaleY = -1;\n break;\n\n // Rotate right 90°\n case 6:\n rotate = 90;\n break;\n\n // Flip horizontal and rotate right 90°\n case 7:\n rotate = 90;\n scaleX = -1;\n break;\n\n // Rotate left 90°\n case 8:\n rotate = -90;\n break;\n\n default:\n }\n\n return {\n rotate,\n scaleX,\n scaleY,\n };\n}\n\nconst REGEXP_DECIMALS = /\\.\\d*(?:0|9){12}\\d*$/;\n\n/**\n * Normalize decimal number.\n * Check out {@link https://0.30000000000000004.com/}\n * @param {number} value - The value to normalize.\n * @param {number} [times=100000000000] - The times for normalizing.\n * @returns {number} Returns the normalized number.\n */\nexport function normalizeDecimalNumber(value, times = 100000000000) {\n return REGEXP_DECIMALS.test(value) ? (Math.round(value * times) / times) : value;\n}\n\n/**\n * Get the max sizes in a rectangle under the given aspect ratio.\n * @param {Object} data - The original sizes.\n * @param {string} [type='contain'] - The adjust type.\n * @returns {Object} The result sizes.\n */\nexport function getAdjustedSizes(\n {\n aspectRatio,\n height,\n width,\n },\n\n // 'none' | 'contain' | 'cover'\n type = 'none',\n) {\n const isValidWidth = isPositiveNumber(width);\n const isValidHeight = isPositiveNumber(height);\n\n if (isValidWidth && isValidHeight) {\n const adjustedWidth = height * aspectRatio;\n\n if (((type === 'contain' || type === 'none') && adjustedWidth > width) || (type === 'cover' && adjustedWidth < width)) {\n height = width / aspectRatio;\n } else {\n width = height * aspectRatio;\n }\n } else if (isValidWidth) {\n height = width / aspectRatio;\n } else if (isValidHeight) {\n width = height * aspectRatio;\n }\n\n return {\n width,\n height,\n };\n}\n","import toBlob from 'blueimp-canvas-to-blob';\nimport isBlob from 'is-blob';\nimport DEFAULTS from './defaults';\nimport {\n WINDOW,\n} from './constants';\nimport {\n arrayBufferToDataURL,\n getAdjustedSizes,\n imageTypeToExtension,\n isImageType,\n isPositiveNumber,\n normalizeDecimalNumber,\n parseOrientation,\n resetAndGetOrientation,\n} from './utilities';\n\nconst { ArrayBuffer, FileReader } = WINDOW;\nconst URL = WINDOW.URL || WINDOW.webkitURL;\nconst REGEXP_EXTENSION = /\\.\\w+$/;\nconst AnotherCompressor = WINDOW.Compressor;\n\n/**\n * Creates a new image compressor.\n * @class\n */\nexport default class Compressor {\n /**\n * The constructor of Compressor.\n * @param {File|Blob} file - The target image file for compressing.\n * @param {Object} [options] - The options for compressing.\n */\n constructor(file, options) {\n this.file = file;\n this.image = new Image();\n this.options = {\n ...DEFAULTS,\n ...options,\n };\n this.aborted = false;\n this.result = null;\n this.init();\n }\n\n init() {\n const { file, options } = this;\n\n if (!isBlob(file)) {\n this.fail(new Error('The first argument must be a File or Blob object.'));\n return;\n }\n\n const mimeType = file.type;\n\n if (!isImageType(mimeType)) {\n this.fail(new Error('The first argument must be an image File or Blob object.'));\n return;\n }\n\n if (!URL || !FileReader) {\n this.fail(new Error('The current browser does not support image compression.'));\n return;\n }\n\n if (!ArrayBuffer) {\n options.checkOrientation = false;\n }\n\n if (URL && !options.checkOrientation) {\n this.load({\n url: URL.createObjectURL(file),\n });\n } else {\n const reader = new FileReader();\n const checkOrientation = options.checkOrientation && mimeType === 'image/jpeg';\n\n this.reader = reader;\n reader.onload = ({ target }) => {\n const { result } = target;\n const data = {};\n\n if (checkOrientation) {\n // Reset the orientation value to its default value 1\n // as some iOS browsers will render image with its orientation\n const orientation = resetAndGetOrientation(result);\n\n if (orientation > 1 || !URL) {\n // Generate a new URL which has the default orientation value\n data.url = arrayBufferToDataURL(result, mimeType);\n\n if (orientation > 1) {\n Object.assign(data, parseOrientation(orientation));\n }\n } else {\n data.url = URL.createObjectURL(file);\n }\n } else {\n data.url = result;\n }\n\n this.load(data);\n };\n reader.onabort = () => {\n this.fail(new Error('Aborted to read the image with FileReader.'));\n };\n reader.onerror = () => {\n this.fail(new Error('Failed to read the image with FileReader.'));\n };\n reader.onloadend = () => {\n this.reader = null;\n };\n\n if (checkOrientation) {\n reader.readAsArrayBuffer(file);\n } else {\n reader.readAsDataURL(file);\n }\n }\n }\n\n load(data) {\n const { file, image } = this;\n\n image.onload = () => {\n this.draw({\n ...data,\n naturalWidth: image.naturalWidth,\n naturalHeight: image.naturalHeight,\n });\n };\n image.onabort = () => {\n this.fail(new Error('Aborted to load the image.'));\n };\n image.onerror = () => {\n this.fail(new Error('Failed to load the image.'));\n };\n\n // Match all browsers that use WebKit as the layout engine in iOS devices,\n // such as Safari for iOS, Chrome for iOS, and in-app browsers.\n if (WINDOW.navigator && /(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(WINDOW.navigator.userAgent)) {\n // Fix the `The operation is insecure` error (#57)\n image.crossOrigin = 'anonymous';\n }\n\n image.alt = file.name;\n image.src = data.url;\n }\n\n draw({\n naturalWidth,\n naturalHeight,\n rotate = 0,\n scaleX = 1,\n scaleY = 1,\n }) {\n const { file, image, options } = this;\n const canvas = document.createElement('canvas');\n const context = canvas.getContext('2d');\n const is90DegreesRotated = Math.abs(rotate) % 180 === 90;\n const resizable = (options.resize === 'contain' || options.resize === 'cover') && isPositiveNumber(options.width) && isPositiveNumber(options.height);\n let maxWidth = Math.max(options.maxWidth, 0) || Infinity;\n let maxHeight = Math.max(options.maxHeight, 0) || Infinity;\n let minWidth = Math.max(options.minWidth, 0) || 0;\n let minHeight = Math.max(options.minHeight, 0) || 0;\n let aspectRatio = naturalWidth / naturalHeight;\n let { width, height } = options;\n\n if (is90DegreesRotated) {\n [maxWidth, maxHeight] = [maxHeight, maxWidth];\n [minWidth, minHeight] = [minHeight, minWidth];\n [width, height] = [height, width];\n }\n\n if (resizable) {\n aspectRatio = width / height;\n }\n\n ({ width: maxWidth, height: maxHeight } = getAdjustedSizes({\n aspectRatio,\n width: maxWidth,\n height: maxHeight,\n }, 'contain'));\n ({ width: minWidth, height: minHeight } = getAdjustedSizes({\n aspectRatio,\n width: minWidth,\n height: minHeight,\n }, 'cover'));\n\n if (resizable) {\n ({ width, height } = getAdjustedSizes({\n aspectRatio,\n width,\n height,\n }, options.resize));\n } else {\n ({ width = naturalWidth, height = naturalHeight } = getAdjustedSizes({\n aspectRatio,\n width,\n height,\n }));\n }\n\n width = Math.floor(normalizeDecimalNumber(Math.min(Math.max(width, minWidth), maxWidth)));\n height = Math.floor(normalizeDecimalNumber(Math.min(Math.max(height, minHeight), maxHeight)));\n\n const destX = -width / 2;\n const destY = -height / 2;\n const destWidth = width;\n const destHeight = height;\n const params = [];\n\n if (resizable) {\n let srcX = 0;\n let srcY = 0;\n let srcWidth = naturalWidth;\n let srcHeight = naturalHeight;\n\n ({ width: srcWidth, height: srcHeight } = getAdjustedSizes({\n aspectRatio,\n width: naturalWidth,\n height: naturalHeight,\n }, {\n contain: 'cover',\n cover: 'contain',\n }[options.resize]));\n srcX = (naturalWidth - srcWidth) / 2;\n srcY = (naturalHeight - srcHeight) / 2;\n\n params.push(srcX, srcY, srcWidth, srcHeight);\n }\n\n params.push(destX, destY, destWidth, destHeight);\n\n if (is90DegreesRotated) {\n [width, height] = [height, width];\n }\n\n canvas.width = width;\n canvas.height = height;\n\n if (!isImageType(options.mimeType)) {\n options.mimeType = file.type;\n }\n\n let fillStyle = 'transparent';\n\n // Converts PNG files over the `convertSize` to JPEGs.\n if (file.size > options.convertSize && options.convertTypes.indexOf(options.mimeType) >= 0) {\n options.mimeType = 'image/jpeg';\n }\n\n if (options.mimeType === 'image/jpeg') {\n fillStyle = '#fff';\n }\n\n // Override the default fill color (#000, black)\n context.fillStyle = fillStyle;\n context.fillRect(0, 0, width, height);\n\n if (options.beforeDraw) {\n options.beforeDraw.call(this, context, canvas);\n }\n\n if (this.aborted) {\n return;\n }\n\n context.save();\n context.translate(width / 2, height / 2);\n context.rotate((rotate * Math.PI) / 180);\n context.scale(scaleX, scaleY);\n context.drawImage(image, ...params);\n context.restore();\n\n if (options.drew) {\n options.drew.call(this, context, canvas);\n }\n\n if (this.aborted) {\n return;\n }\n\n const done = (result) => {\n if (!this.aborted) {\n this.done({\n naturalWidth,\n naturalHeight,\n result,\n });\n }\n };\n\n if (canvas.toBlob) {\n canvas.toBlob(done, options.mimeType, options.quality);\n } else {\n done(toBlob(canvas.toDataURL(options.mimeType, options.quality)));\n }\n }\n\n done({\n naturalWidth,\n naturalHeight,\n result,\n }) {\n const { file, image, options } = this;\n\n if (URL && !options.checkOrientation) {\n URL.revokeObjectURL(image.src);\n }\n\n if (result) {\n // Returns original file if the result is greater than it and without size related options\n if (options.strict && result.size > file.size && options.mimeType === file.type && !(\n options.width > naturalWidth\n || options.height > naturalHeight\n || options.minWidth > naturalWidth\n || options.minHeight > naturalHeight\n || options.maxWidth < naturalWidth\n || options.maxHeight < naturalHeight\n )) {\n result = file;\n } else {\n const date = new Date();\n\n result.lastModified = date.getTime();\n result.lastModifiedDate = date;\n result.name = file.name;\n\n // Convert the extension to match its type\n if (result.name && result.type !== file.type) {\n result.name = result.name.replace(\n REGEXP_EXTENSION,\n imageTypeToExtension(result.type),\n );\n }\n }\n } else {\n // Returns original file if the result is null in some cases.\n result = file;\n }\n\n this.result = result;\n\n if (options.success) {\n options.success.call(this, result);\n }\n }\n\n fail(err) {\n const { options } = this;\n\n if (options.error) {\n options.error.call(this, err);\n } else {\n throw err;\n }\n }\n\n abort() {\n if (!this.aborted) {\n this.aborted = true;\n\n if (this.reader) {\n this.reader.abort();\n } else if (!this.image.complete) {\n this.image.onload = null;\n this.image.onabort();\n } else {\n this.fail(new Error('The compression process has been aborted.'));\n }\n }\n }\n\n /**\n * Get the no conflict compressor class.\n * @returns {Compressor} The compressor class.\n */\n static noConflict() {\n window.Compressor = AnotherCompressor;\n return Compressor;\n }\n\n /**\n * Change the default options.\n * @param {Object} options - The new default options.\n */\n static setDefaults(options) {\n Object.assign(DEFAULTS, options);\n }\n}\n"],"names":["window","CanvasPrototype","HTMLCanvasElement","prototype","hasBlobConstructor","Blob","Boolean","e","hasArrayBufferViewSupport","Uint8Array","size","BlobBuilder","WebKitBlobBuilder","MozBlobBuilder","MSBlobBuilder","dataURIPattern","dataURLtoBlob","atob","ArrayBuffer","dataURI","matches","mediaType","isBase64","dataString","byteString","arrayBuffer","intArray","i","bb","match","Error","slice","length","decodeURIComponent","charCodeAt","type","append","getBlob","toBlob","mozGetAsFile","callback","quality","self","setTimeout","toDataURL","msToBlob","module","exports","isBlob","value","Object","toString","call","strict","checkOrientation","maxWidth","Infinity","maxHeight","minWidth","minHeight","width","undefined","height","resize","mimeType","convertTypes","convertSize","beforeDraw","drew","success","error","IS_BROWSER","document","WINDOW","isPositiveNumber","Array","toArray","from","REGEXP_IMAGE_TYPE","isImageType","test","imageTypeToExtension","extension","substr","fromCharCode","String","getStringFromCharCode","dataView","start","str","getUint8","btoa","arrayBufferToDataURL","chunks","chunkSize","uint8","push","apply","subarray","join","resetAndGetOrientation","DataView","orientation","littleEndian","app1Start","ifdStart","byteLength","offset","exifIDCode","tiffOffset","endianness","getUint16","firstIFDOffset","getUint32","setUint16","parseOrientation","rotate","scaleX","scaleY","REGEXP_DECIMALS","normalizeDecimalNumber","times","Math","round","getAdjustedSizes","aspectRatio","isValidWidth","isValidHeight","adjustedWidth","FileReader","URL","webkitURL","REGEXP_EXTENSION","AnotherCompressor","Compressor","file","options","image","Image","DEFAULTS","aborted","result","init","fail","load","url","createObjectURL","reader","onload","target","data","onabort","onerror","onloadend","readAsArrayBuffer","readAsDataURL","draw","naturalWidth","naturalHeight","navigator","userAgent","crossOrigin","alt","name","src","canvas","createElement","context","getContext","is90DegreesRotated","abs","resizable","max","floor","min","destX","destY","destWidth","destHeight","params","srcX","srcY","srcWidth","srcHeight","contain","cover","fillStyle","indexOf","fillRect","save","translate","PI","scale","drawImage","restore","done","revokeObjectURL","date","Date","lastModified","getTime","lastModifiedDate","replace","err","abort","complete"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBC,GAAC,UAAUA,MAAV,EAAkB;;AAGlB,QAAIC,eAAe,GACjBD,MAAM,CAACE,iBAAP,IAA4BF,MAAM,CAACE,iBAAP,CAAyBC,SADvD;;AAEA,QAAIC,kBAAkB,GACpBJ,MAAM,CAACK,IAAP,IACC,YAAY;AACX,UAAI;AACF,eAAOC,OAAO,CAAC,IAAID,IAAJ,EAAD,CAAd;AACD,OAFD,CAEE,OAAOE,CAAP,EAAU;AACV,eAAO,KAAP;AACD;AACF,KAND,EAFF;;AASA,QAAIC,yBAAyB,GAC3BJ,kBAAkB,IAClBJ,MAAM,CAACS,UADP,IAEC,YAAY;AACX,UAAI;AACF,eAAO,IAAIJ,IAAJ,CAAS,CAAC,IAAII,UAAJ,CAAe,GAAf,CAAD,CAAT,EAAgCC,IAAhC,KAAyC,GAAhD;AACD,OAFD,CAEE,OAAOH,CAAP,EAAU;AACV,eAAO,KAAP;AACD;AACF,KAND,EAHF;;AAUA,QAAII,WAAW,GACbX,MAAM,CAACW,WAAP,IACAX,MAAM,CAACY,iBADP,IAEAZ,MAAM,CAACa,cAFP,IAGAb,MAAM,CAACc,aAJT;AAKA,QAAIC,cAAc,GAAG,yCAArB;;AACA,QAAIC,aAAa,GACf,CAACZ,kBAAkB,IAAIO,WAAvB,KACAX,MAAM,CAACiB,IADP,IAEAjB,MAAM,CAACkB,WAFP,IAGAlB,MAAM,CAACS,UAHP,IAIA,UAAUU,OAAV,EAAmB;AACjB,UAAIC,OAAJ,EACEC,SADF,EAEEC,QAFF,EAGEC,UAHF,EAIEC,UAJF,EAKEC,WALF,EAMEC,QANF,EAOEC,CAPF,EAQEC,EARF,CADiB;;AA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