text: !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ImageResize=e():t.ImageResize=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="./",n(n.s=1)}([,function(t,e,n){"use strict";function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:320,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:240,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"#ffffff";this.el=document.createElement("canvas"),this.ctx=this.el.getContext("2d"),this.el.width=t,this.el.height=e,this.ctx.fillStyle=n,this.ctx.fillRect(0,0,t,e)}function o(t){return new Promise((function(e,n){if(t){var r=new Image;r.onload=function(t){e(r)},r.onerror=function(t){n(t)},r.setAttribute("crossOrigin","anonymous"),r.src=t}else n(new Error("no src"))}))}n.r(e);var i={quality:.75,format:"jpg",outputType:"base64",width:320,height:null,reSample:2,bgColor:"#ffffff",saveExif:!1},u={canvas:null,reSample:2,width:320,height:240,cx:0,cy:0,cw:0,ch:0,dx:0,dy:0,dw:0,dh:0,bgColor:"#ffffff"};function a(t){(t=Object.assign({},u,t)).reSample=Math.min(4,t.reSample),t.reSample=Math.max(0,t.reSample);var e=Math.pow(2,t.reSample);return new Promise((function(n,o){try{var i=new r(t.width*e,t.height*e,t.bgColor);i.ctx.drawImage(t.canvas,t.cx,t.cy,t.cw,t.ch,t.dx*e,t.dy*e,t.dw*e,t.dh*e),t.reSample>0?function(t,e,n){return new Promise((function(o){!function e(n,i){var u=Math.pow(2,n),a=new r(t.width*u,t.height*u,t.bgColor);a.ctx.drawImage(i,0,0,.5*i.width,.5*i.height),n>0?e(n-1,a.el):o(a.el)}(e-1,n)}))}(t,t.reSample,i.el).then(n):n(i.el)}catch(t){o(t)}}))}function c(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"image/jpeg",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.75;return e=f(e),new Promise((function(r,o){try{r(t.toDataURL(e,n))}catch(t){o(t)}}))}function l(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"image/jpeg",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.75;return e=f(e),new Promise((function(r,o){try{r(h(t.toDataURL(e,n)))}catch(t){o(t)}}))}function f(t){var e=null;switch(t){case"jpg":case"jpeg":e="image/jpeg";break;case"png":e="image/png";break;default:e=t}return e}function h(t){for(var e=atob(t.split(",")[1]),n=t.split(",")[0].split(":")[1].split(";")[0],r=new ArrayBuffer(e.length),o=new Uint8Array(r),i=0;i<e.length;i++)o[i]=e.charCodeAt(i);var u=new DataView(r);return new Blob([u],{type:n})}function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function d(t,e,n,r){var o=t,i=e;return n&&r&&(n>r?r=null:n=null),n?(o=n,i=e*(n/t)):r&&(o=t*(r/e),i=r),{width:parseInt(o),height:parseInt(i)}}e.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={};return Object.keys(t).forEach((function(r){n[r]=e[r]||t[r]})),n.width=Number(n.width),n.height=Number(n.height),n.quality=Number(n.quality),n.reSample=Number(n.reSample),n}function n(t,e){var n=null;return new Promise((function(i,u){o(t).then((function(t){(n=new r(t.width,t.height,e.bgColor)).ctx.drawImage(t,0,0),i(n.el)}),(function(t){u(t)}))}))}function u(t,e){var n=null;return new Promise((function(o,i){function u(t){i(t)}var a=new FileReader;a.onload=function(t){var i=new Image;i.onload=function(){(n=new r(i.width,i.height,e.bgColor)).ctx.drawImage(i,0,0),o(n.el)},i.onerror=u,i.src=t.target.result},a.onerror=u,a.readAsDataURL(t.files[0])}))}this.options=e(i,t),this.play=function(t){var e=this;return new Promise((function(n,r){e.get(t).then((function(t){return e.resize(t)})).then((function(t){return e.output(t)})).then((function(t){return n(t)})).catch((function(t){return r(t)}))}))},this.get=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return r=r?e(this.options,r):this.options,new Promise((function(e,o){"string"==typeof t?e(n(t,r)):"object"===s(t)?e(u(t,r)):o(new Error("Not found source"))}))},this.resize=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return n=n?e(this.options,n):this.options,new Promise((function(e,r){var o=d(t.width,t.height,n.width,n.height);a({canvas:t,reSample:n.reSample,width:o.width,height:o.height,cx:0,cy:0,cw:t.width,ch:t.height,dx:0,dy:0,dw:o.width,dh:o.height,bgColor:n.bgColor}).then(e).catch(r)}))},this.output=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return n=n?e(this.options,n):this.options,new Promise((function(e,r){switch(n.outputType){case"base64":c(t,n.format,n.quality).then(e).catch(r);break;case"blob":l(t,n.format,n.quality).then(e).catch(r);break;case"canvas":default:e(t)}}))},this.updateOptions=function(t){return this.options=e(this.options,t),this}}}]).default}));