%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/js/landing/external/image-compressor/ |
Current File : /home/bitrix/www/bitrix/js/landing/external/image-compressor/image-compressor.min.js |
(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?module.exports=t():typeof define==="function"&&define.amd?define(t):e.ImageCompressor=t()})(this,function(){"use strict";function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}var t=e(function(e){(function(t){var r=t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype;var n=t.Blob&&function(){try{return Boolean(new Blob)}catch(e){return false}}();var a=n&&t.Uint8Array&&function(){try{return new Blob([new Uint8Array(100)]).size===100}catch(e){return false}}();var i=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder;var o=/^data:((.*?)(;charset=.*?)?)(;base64)?,/;var f=(n||i)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(e){var t,r,f,l,u,c,s,h,d;t=e.match(o);if(!t){throw new Error("invalid data URI")}r=t[2]?t[1]:"text/plain"+(t[3]||";charset=US-ASCII");f=!!t[4];l=e.slice(t[0].length);if(f){u=atob(l)}else{u=decodeURIComponent(l)}c=new ArrayBuffer(u.length);s=new Uint8Array(c);for(h=0;h<u.length;h+=1){s[h]=u.charCodeAt(h)}if(n){return new Blob([a?s:c],{type:r})}d=new i;d.append(c);return d.getBlob(r)};if(t.HTMLCanvasElement&&!r.toBlob){if(r.mozGetAsFile){r.toBlob=function(e,t,n){var a=this;setTimeout(function(){if(n&&r.toDataURL&&f){e(f(a.toDataURL(t,n)))}else{e(a.mozGetAsFile("blob",t))}})}}else if(r.toDataURL&&f){r.toBlob=function(e,t,r){var n=this;setTimeout(function(){e(f(n.toDataURL(t,r)))})}}}if(typeof undefined==="function"&&undefined.amd){undefined(function(){return f})}else if(e.exports){e.exports=f}else{t.dataURLtoBlob=f}})(window)});var r=Object.prototype.toString;var n=function(e){return e instanceof Blob||r.call(e)==="[object Blob]"};var a={checkOrientation:true,maxWidth:Infinity,maxHeight:Infinity,minWidth:0,minHeight:0,width:undefined,height:undefined,quality:.8,mimeType:"auto",convertSize:5e6,beforeDraw:null,drew:null,success:null,error:null};var i=/^image\/.+$/;function o(e){return i.test(e)}function f(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var r=o(e)?e.substr(6):"";if(r==="jpeg"){r="jpg"}if(r&&t){r="."+r}return r}var l=String.fromCharCode;function u(e,t,r){var n="";var a=void 0;r+=t;for(a=t;a<r;a+=1){n+=l(e.getUint8(a))}return n}var c=window,s=c.btoa;function h(e,t){var r=new Uint8Array(e);var n="";if(typeof r.forEach==="function"){r.forEach(function(e){n+=l(e)})}else{var a=r.length;for(var i=0;i<a;i+=1){n+=l(r[i])}}return"data:"+t+";base64,"+s(n)}function d(e){var t=new DataView(e);var r=void 0;var n=void 0;var a=void 0;var i=void 0;if(t.getUint8(0)===255&&t.getUint8(1)===216){var o=t.byteLength;var f=2;while(f<o){if(t.getUint8(f)===255&&t.getUint8(f+1)===225){a=f;break}f+=1}}if(a){var l=a+4;var c=a+10;if(u(t,l,4)==="Exif"){var s=t.getUint16(c);n=s===18761;if(n||s===19789){if(t.getUint16(c+2,n)===42){var h=t.getUint32(c+4,n);if(h>=8){i=c+h}}}}}if(i){var d=t.getUint16(i,n);var v=void 0;var m=void 0;for(m=0;m<d;m+=1){v=i+m*12+2;if(t.getUint16(v,n)===274){v+=8;r=t.getUint16(v,n);t.setUint16(v,1,n);break}}}return r}function v(e){var t=0;var r=1;var n=1;switch(e){case 2:r=-1;break;case 3:t=-180;break;case 4:n=-1;break;case 5:t=90;n=-1;break;case 6:t=90;break;case 7:t=90;r=-1;break;case 8:t=-90;break;default:}return{rotate:t,scaleX:r,scaleY:n}}var m=/\.\d*(?:0|9){12}\d*$/i;function g(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1e11;return m.test(e)?Math.round(e*t)/t:e}var b=function(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}};var w=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||false;n.configurable=true;if("value"in n)n.writable=true;Object.defineProperty(e,n.key,n)}}return function(t,r,n){if(r)e(t.prototype,r);if(n)e(t,n);return t}}();var p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r){if(Object.prototype.hasOwnProperty.call(r,n)){e[n]=r[n]}}}return e};var y=window,U=y.ArrayBuffer,B=y.FileReader;var M=window.URL||window.webkitURL;var x=/\.\w+$/;var k=function(){function e(t,r){b(this,e);this.result=null;if(t){this.compress(t,r)}}w(e,[{key:"compress",value:function e(r,i){var l=this;var u=new Image;i=p({},a,i);if(!U){i.checkOrientation=false}return new Promise(function(e,t){if(!n(r)){t(new Error("The first argument must be a File or Blob object."));return}var a=r.type;if(!o(a)){t(new Error("The first argument must be an image File or Blob object."));return}if(!M&&!B){t(new Error("The current browser does not support image compression."));return}if(M&&!i.checkOrientation){e({url:M.createObjectURL(r)})}else if(B){var f=new B;var l=i.checkOrientation&&a==="image/jpeg";f.onload=function(t){var r=t.target;var n=r.result;e(l?p({url:h(n,a)},v(d(n))):{url:n})};f.onabort=function(){t(new Error("Aborted to load the image with FileReader."))};f.onerror=function(){t(new Error("Failed to load the image with FileReader."))};if(l){f.readAsArrayBuffer(r)}else{f.readAsDataURL(r)}}}).then(function(e){return new Promise(function(t,n){u.onload=function(){return t(p({},e,{naturalWidth:u.naturalWidth,naturalHeight:u.naturalHeight}))};u.onabort=function(){n(new Error("Aborted to load the image."))};u.onerror=function(){n(new Error("Failed to load the image."))};u.alt=r.name;u.src=e.url})}).then(function(e){var n=e.naturalWidth,a=e.naturalHeight,f=e.rotate,c=f===undefined?0:f,s=e.scaleX,h=s===undefined?1:s,d=e.scaleY,v=d===undefined?1:d;return new Promise(function(e){var f=document.createElement("canvas");var s=f.getContext("2d");var d=n/a;var m=Math.max(i.maxWidth,0)||Infinity;var b=Math.max(i.maxHeight,0)||Infinity;var w=Math.max(i.minWidth,0)||0;var p=Math.max(i.minHeight,0)||0;var y=n;var U=a;if(m<Infinity&&b<Infinity){if(b*d>m){b=m/d}else{m=b*d}}else if(m<Infinity){b=m/d}else if(b<Infinity){m=b*d}if(w>0&&p>0){if(p*d>w){p=w/d}else{w=p*d}}else if(w>0){p=w/d}else if(p>0){w=p*d}if(i.width>0){var B=i;y=B.width;U=y/d}else if(i.height>0){var M=i;U=M.height;y=U*d}y=Math.min(Math.max(y,w),m);U=Math.min(Math.max(U,p),b);var x=-y/2;var k=-U/2;var T=y;var A=U;if(Math.abs(c)%180===90){var R={width:U,height:y};y=R.width;U=R.height}f.width=g(y);f.height=g(U);if(!o(i.mimeType)){i.mimeType=r.type}var E="transparent";if(r.size>i.convertSize&&i.mimeType==="image/png"){E="#fff";i.mimeType="image/jpeg"}s.fillStyle=E;s.fillRect(0,0,y,U);s.save();s.translate(y/2,U/2);s.rotate(c*Math.PI/180);s.scale(h,v);if(i.beforeDraw){i.beforeDraw.call(l,s,f)}s.drawImage(u,Math.floor(g(x)),Math.floor(g(k)),Math.floor(g(T)),Math.floor(g(A)));if(i.drew){i.drew.call(l,s,f)}s.restore();var I=function t(r){e({naturalWidth:n,naturalHeight:a,result:r})};if(f.toBlob){f.toBlob(I,i.mimeType,i.quality)}else{I(t(f.toDataURL(i.mimeType,i.quality)))}})}).then(function(e){var t=e.naturalWidth,n=e.naturalHeight,a=e.result;if(M&&!i.checkOrientation){M.revokeObjectURL(u.src)}if(a){if(a.size>r.size&&i.mimeType===r.type&&!(i.width>t||i.height>n||i.minWidth>t||i.minHeight>n)){a=r}else{var o=new Date;a.lastModified=o.getTime();a.lastModifiedDate=o;a.name=r.name;if(a.name&&a.type!==r.type){a.name=a.name.replace(x,f(a.type))}}}else{a=r}l.result=a;if(i.success){i.success.call(l,a)}return Promise.resolve(a)}).catch(function(e){if(!i.error){throw e}i.error.call(l,e)})}}]);return e}();return k});