/*! image-blob-reduce 3.0.1 https://github.com/nodeca/image-blob-reduce @license MIT */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ImageBlobReduce=e()}(this,(function(){"use strict";function t(t,e){var n={};return e.forEach((function(e){Object.prototype.hasOwnProperty.call(t,e)&&(n[e]=t[e])})),n}var e={assign:function(t){for(var e,n=1;n=0,wasm:e.indexOf("wasm")>=0};i.call(this,n),this.features={js:n.js,wasm:n.wasm&&this.has_wasm()},this.use(a),this.use(o)}r(s,i),s.prototype.resizeAndUnsharp=function(t,e){var n=this.resize(t,e);return t.unsharpAmount&&this.unsharp_mask(n,t.toWidth,t.toHeight,t.unsharpAmount,t.unsharpRadius,t.unsharpThreshold),n},e.exports=s},{"./mm_resize":4,"./mm_unsharp_mask":9,inherits:19,multimath:20}],2:[function(t,e,n){function r(t){return t<0?0:t>255?255:t}function i(t,e,n,i,a,o){var s,A,u,h,f,c,l,g,p,d,m,_=0,w=0;for(p=0;p0;l--)h=h+(m=o[f++])*t[g+3]|0,u=u+m*t[g+2]|0,A=A+m*t[g+1]|0,s=s+m*t[g]|0,g=g+4|0;e[w+3]=r(h+(1<<13)>>14),e[w+2]=r(u+(1<<13)>>14),e[w+1]=r(A+(1<<13)>>14),e[w]=r(s+(1<<13)>>14),w=w+4*i|0}w=4*(p+1)|0,_=(p+1)*n*4|0}}function a(t,e,n,i,a,o){var s,A,u,h,f,c,l,g,p,d,m,_=0,w=0;for(p=0;p0;l--)h=h+(m=o[f++])*t[g+3]|0,u=u+m*t[g+2]|0,A=A+m*t[g+1]|0,s=s+m*t[g]|0,g=g+4|0;e[w+3]=r(h+(1<<13)>>14),e[w+2]=r(u+(1<<13)>>14),e[w+1]=r(A+(1<<13)>>14),e[w]=r(s+(1<<13)>>14),w=w+4*i|0}w=4*(p+1)|0,_=(p+1)*n*4|0}}e.exports={convolveHorizontally:i,convolveVertically:a}},{}],3:[function(t,e,n){e.exports="AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEXA2AAAGAGf39/f39/AGAHf39/f39/fwACDwEDZW52Bm1lbW9yeQIAAAMEAwABAgYGAX8AQQALB1cFEV9fd2FzbV9jYWxsX2N0b3JzAAAIY29udm9sdmUAAQpjb252b2x2ZUhWAAIMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAK7AMDAwABC8YDAQ9/AkAgA0UNACAERQ0AA0AgDCENQQAhE0EAIQcDQCAHQQJqIQYCfyAHQQF0IAVqIgcuAQIiFEUEQEGAwAAhCEGAwAAhCUGAwAAhCkGAwAAhCyAGDAELIBIgBy4BAGohCEEAIQsgFCEHQQAhDiAGIQlBACEPQQAhEANAIAUgCUEBdGouAQAiESAAIAhBAnRqKAIAIgpBGHZsIBBqIRAgCkH/AXEgEWwgC2ohCyAKQRB2Qf8BcSARbCAPaiEPIApBCHZB/wFxIBFsIA5qIQ4gCEEBaiEIIAlBAWohCSAHQQFrIgcNAAsgC0GAQGshCCAOQYBAayEJIA9BgEBrIQogEEGAQGshCyAGIBRqCyEHIAEgDUECdGogCUEOdSIGQf8BIAZB/wFIGyIGQQAgBkEAShtBCHRBgP4DcSAKQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EQdEGAgPwHcSALQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobcjYCACADIA1qIQ0gE0EBaiITIARHDQALIAxBAWoiDCACbCESIAMgDEcNAAsLCx4AQQAgAiADIAQgBSAAEAEgAkEAIAQgBSAGIAEQAQs="},{}],4:[function(t,e,n){e.exports={name:"resize",fn:t("./resize"),wasm_fn:t("./resize_wasm"),wasm_src:t("./convolve_wasm_base64")}},{"./convolve_wasm_base64":3,"./resize":5,"./resize_wasm":8}],5:[function(t,e,n){var r=t("./resize_filter_gen"),i=t("./convolve").convolveHorizontally,a=t("./convolve").convolveVertically;function o(t,e,n){for(var r=3,i=e*n*4|0;r>1]+=a(1-_),I=0;I0&&0===l[b];)b--;if(v=u+I,y=b-I+1,M[D++]=v,M[D++]=y,j)for(d=I;d<=b;d++)M[D++]=l[d];else M.set(l.subarray(I,b+1),D),D+=y}else M[D++]=0,M[D++]=0}return M}},{"./resize_filter_info":7}],7:[function(t,e,n){e.exports=[{win:.5,filter:function(t){return t>=-.5&&t<.5?1:0}},{win:1,filter:function(t){if(t<=-1||t>=1)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*(.54+.46*Math.cos(e/1))}},{win:2,filter:function(t){if(t<=-2||t>=2)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/2)/(e/2)}},{win:3,filter:function(t){if(t<=-3||t>=3)return 0;if(t>-1.1920929e-7&&t<1.1920929e-7)return 1;var e=t*Math.PI;return Math.sin(e)/e*Math.sin(e/3)/(e/3)}}]},{}],8:[function(t,e,n){var r=t("./resize_filter_gen");function i(t,e,n){for(var r=3,i=e*n*4|0;r>8&255}}e.exports=function(t){var e=t.src,n=t.width,a=t.height,o=t.toWidth,A=t.toHeight,u=t.scaleX||t.toWidth/t.width,h=t.scaleY||t.toHeight/t.height,f=t.offsetX||0,c=t.offsetY||0,l=t.dest||new Uint8Array(o*A*4),g=void 0===t.quality?3:t.quality,p=t.alpha||!1,d=r(g,n,o,u,f),m=r(g,a,A,h,c),_=0,w=this.__align(_+Math.max(e.byteLength,l.byteLength)),I=this.__align(w+a*o*4),b=this.__align(I+d.byteLength),v=b+m.byteLength,y=this.__instance("resize",v),B=new Uint8Array(this.__memory.buffer),E=new Uint32Array(this.__memory.buffer),C=new Uint32Array(e.buffer);return E.set(C),s(d,B,I),s(m,B,b),(y.exports.convolveHV||y.exports._convolveHV)(I,b,w,n,a,o,A),new Uint32Array(l.buffer).set(new Uint32Array(this.__memory.buffer,0,A*o)),p||i(l,o,A),l}},{"./resize_filter_gen":6}],9:[function(t,e,n){e.exports={name:"unsharp_mask",fn:t("./unsharp_mask"),wasm_fn:t("./unsharp_mask_wasm"),wasm_src:t("./unsharp_mask_wasm_base64")}},{"./unsharp_mask":10,"./unsharp_mask_wasm":11,"./unsharp_mask_wasm_base64":12}],10:[function(t,e,n){var r=t("glur/mono16");function i(t,e,n){for(var r,i,a,o,s=e*n,A=new Uint16Array(s),u=0;u=i&&r>=a?r:i>=a&&i>=r?i:a,A[u]=o<<8;return A}e.exports=function(t,e,n,a,o,s){var A,u,h,f,c;if(!(0===a||o<.5)){o>2&&(o=2);var l=i(t,e,n),g=new Uint16Array(l);r(g,e,n,o);for(var p=a/100*4096+.5|0,d=s<<8,m=e*n,_=0;_=d&&(h=((u=(u=(u=A+(p*f+2048>>12))>65280?65280:u)<0?0:u)<<12)/(A=0!==A?A:1)|0,t[c=4*_]=t[c]*h+2048>>12,t[c+1]=t[c+1]*h+2048>>12,t[c+2]=t[c+2]*h+2048>>12)}}},{"glur/mono16":18}],11:[function(t,e,n){e.exports=function(t,e,n,r,i,a){if(!(0===r||i<.5)){i>2&&(i=2);var o=e*n,s=4*o,A=2*o,u=2*o,h=4*Math.max(e,n),f=8*4,c=0,l=s,g=l+A,p=g+u,d=p+u,m=d+h,_=this.__instance("unsharp_mask",s+A+2*u+h+f,{exp:Math.exp}),w=new Uint32Array(t.buffer);new Uint32Array(this.__memory.buffer).set(w);var I=_.exports.hsv_v16||_.exports._hsv_v16;I(c,l,e,n),(I=_.exports.blurMono16||_.exports._blurMono16)(l,g,p,d,m,e,n,i),(I=_.exports.unsharp||_.exports._unsharp)(c,c,l,g,e,n,r,a),w.set(new Uint32Array(this.__memory.buffer,0,o))}}},{}],12:[function(t,e,n){e.exports="AGFzbQEAAAAADAZkeWxpbmsAAAAAAAE0B2AAAGAEf39/fwBgBn9/f39/fwBgCH9/f39/f39/AGAIf39/f39/f30AYAJ9fwBgAXwBfAIZAgNlbnYDZXhwAA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EfdSIIaiAIc00EQCAAIAZBAnQiCGoiCiAFIAdsQYAQakEMdSABaiIHQYD+AyAHQYD+A0gbIgdBACAHQQBKG0EMdCABQQEgARtuIgEgCi0AAGxBgBBqQQx2OgAAIAAgCEEBcmoiByABIActAABsQYAQakEMdjoAACAAIAhBAnJqIgcgASAHLQAAbEGAEGpBDHY6AAALIAZBAWoiBiAERw0ACwsL"},{}],13:[function(t,e,n){var r=100;function i(t,e){this.create=t,this.available=[],this.acquired={},this.lastId=1,this.timeoutId=0,this.idle=e||2e3}i.prototype.acquire=function(){var t,e=this;return 0!==this.available.length?t=this.available.pop():((t=this.create()).id=this.lastId++,t.release=function(){return e.release(t)}),this.acquired[t.id]=t,t},i.prototype.release=function(t){var e=this;delete this.acquired[t.id],t.lastUsed=Date.now(),this.available.push(t),0===this.timeoutId&&(this.timeoutId=setTimeout((function(){return e.gc()}),r))},i.prototype.gc=function(){var t=this,e=Date.now();this.available=this.available.filter((function(n){return!(e-n.lastUsed>t.idle&&(n.destroy(),1))})),0!==this.available.length?this.timeoutId=setTimeout((function(){return t.gc()}),r):this.timeoutId=0},e.exports=i},{}],14:[function(t,e,n){var r=2;e.exports=function(t,e,n,i,a,o){var s=n/t,A=i/e,u=(2*o+r+1)/a;if(u>.5)return[[n,i]];var h=Math.ceil(Math.log(Math.min(s,A))/Math.log(u));if(h<=1)return[[n,i]];for(var f=[],c=0;c=t.toWidth&&(s=t.toWidth-e),(n=o-t.destTileBorder)<0&&(n=0),n+(A=o+c+t.destTileBorder-n)>=t.toHeight&&(A=t.toHeight-n),l={toX:e,toY:n,toWidth:s,toHeight:A,toInnerX:r,toInnerY:o,toInnerWidth:f,toInnerHeight:c,offsetX:e/u-i(e/u),offsetY:n/h-i(n/h),scaleX:u,scaleY:h,x:i(e/u),y:i(n/h),width:a(s/u),height:a(A/h)},g.push(l);return g}},{}],16:[function(t,e,n){function r(t){return Object.prototype.toString.call(t)}e.exports.isCanvas=function(t){var e=r(t);return"[object HTMLCanvasElement]"===e||"[object OffscreenCanvas]"===e||"[object Canvas]"===e},e.exports.isImage=function(t){return"[object HTMLImageElement]"===r(t)},e.exports.isImageBitmap=function(t){return"[object ImageBitmap]"===r(t)},e.exports.limiter=function(t){var e=0,n=[];function r(){e=0;p--)A=s*d+o*m+u*_+h*w,h=u,u=A,o=s,s=t[f],e[c]=n[l]+u,f--,l--,c-=a}}function f(t,e,n,r){if(r){var i=new Uint16Array(t.length),a=new Float32Array(Math.max(e,n)),o=u(r);h(t,i,a,o,e,n),h(i,t,a,o,n,e)}}e.exports=f},{}],19:[function(t,e,n){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}}},{}],20:[function(t,e,n){var r=t("object-assign"),i=t("./lib/base64decode"),a=t("./lib/wa_detect"),o={js:!0,wasm:!0};function s(t){if(!(this instanceof s))return new s(t);var e=r({},o,t||{});if(this.options=e,this.__cache={},this.__init_promise=null,this.__modules=e.modules||{},this.__memory=null,this.__wasm={},this.__isLE=1===new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0],!this.options.js&&!this.options.wasm)throw new Error('mathlib: at least "js" or "wasm" should be enabled')}s.prototype.has_wasm=a,s.prototype.use=function(t){return this.__modules[t.name]=t,this.options.wasm&&this.has_wasm()&&t.wasm_fn?this[t.name]=t.wasm_fn:this[t.name]=t.fn,this},s.prototype.init=function(){if(this.__init_promise)return this.__init_promise;if(!this.options.js&&this.options.wasm&&!this.has_wasm())return Promise.reject(new Error('mathlib: only "wasm" was enabled, but it\'s not supported'));var t=this;return this.__init_promise=Promise.all(Object.keys(t.__modules).map((function(e){var n=t.__modules[e];return t.options.wasm&&t.has_wasm()&&n.wasm_fn?t.__wasm[e]?null:WebAssembly.compile(t.__base64decode(n.wasm_src)).then((function(n){t.__wasm[e]=n})):null}))).then((function(){return t})),this.__init_promise},s.prototype.__base64decode=i,s.prototype.__reallocate=function(t){if(!this.__memory)return this.__memory=new WebAssembly.Memory({initial:Math.ceil(t/(64*1024))}),this.__memory;var e=this.__memory.buffer.byteLength;return e>2),a=0,o=0,s=0;s>16&255,i[o++]=a>>8&255,i[o++]=255&a),a=a<<6|r.indexOf(e.charAt(s));var A=n%4*6;return 0===A?(i[o++]=a>>16&255,i[o++]=a>>8&255,i[o++]=255&a):18===A?(i[o++]=a>>10&255,i[o++]=a>>2&255):12===A&&(i[o++]=a>>4&255),i}},{}],22:[function(t,e,n){var r;e.exports=function(){if(void 0!==r)return r;if(r=!1,"undefined"==typeof WebAssembly)return r;try{var t=new Uint8Array([0,97,115,109,1,0,0,0,1,6,1,96,1,127,1,127,3,2,1,0,5,3,1,0,1,7,8,1,4,116,101,115,116,0,0,10,16,1,14,0,32,0,65,1,54,2,0,32,0,40,2,0,11]),e=new WebAssembly.Module(t);return 0!==new WebAssembly.Instance(e,{}).exports.test(4)&&(r=!0),r}catch(t){}return r}},{}],23:[function(t,e,n){var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function o(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function s(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map((function(t){return e[t]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(t){r[t]=t})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}e.exports=s()?Object.assign:function(t,e){for(var n,s,A=o(t),u=1;ut.length)&&(e=t.length);for(var n=0,r=new Array(e);n=0)}catch(t){}var w=1;"undefined"!=typeof navigator&&(w=Math.min(navigator.hardwareConcurrency||1,4));var I={tile:1024,concurrency:w,features:["js","wasm","ww"],idle:2e3,createCanvas:function(t,e){var n=document.createElement("canvas");return n.width=t,n.height=e,n}},b={quality:3,alpha:!1,unsharpAmount:0,unsharpRadius:0,unsharpThreshold:0},v=!1,y=!1,B=!1,E=!1,C=!1;function Q(){return{value:h(g),destroy:function(){if(this.value.terminate(),"undefined"!=typeof window){var t=window.URL||window.webkitURL||window.mozURL||window.msURL;t&&t.revokeObjectURL&&this.value.objectURL&&t.revokeObjectURL(this.value.objectURL)}}}}function x(t){if(!(this instanceof x))return new x(t);this.options=u({},I,t||{});var e="lk_".concat(this.options.concurrency);this.__limit=m[e]||l.limiter(this.options.concurrency),m[e]||(m[e]=this.__limit),this.features={js:!1,wasm:!1,cib:!1,ww:!1},this.__workersPool=null,this.__requested_features=[],this.__mathlib=null}x.prototype.init=function(){var e=this;if(this.__initPromise)return this.__initPromise;if("undefined"!=typeof ImageData&&"undefined"!=typeof Uint8ClampedArray)try{new ImageData(new Uint8ClampedArray(400),10,10),v=!0}catch(t){}"undefined"!=typeof ImageBitmap&&(ImageBitmap.prototype&&ImageBitmap.prototype.close?y=!0:this.debug("ImageBitmap does not support .close(), disabled"));var n=this.options.features.slice();if(n.indexOf("all")>=0&&(n=["cib","wasm","js","ww"]),this.__requested_features=n,this.__mathlib=new f(n),n.indexOf("ww")>=0&&"undefined"!=typeof window&&"Worker"in window)try{t("webworkify")((function(){})).terminate(),this.features.ww=!0;var r="wp_".concat(JSON.stringify(this.options));m[r]?this.__workersPool=m[r]:(this.__workersPool=new c(Q,this.options.idle),m[r]=this.__workersPool)}catch(t){}var i,a,o=this.__mathlib.init().then((function(t){u(e.features,t.features)}));i=y?l.cib_support(this.options.createCanvas).then((function(t){e.features.cib&&n.indexOf("cib")<0?e.debug("createImageBitmap() resize supported, but disabled by config"):n.indexOf("cib")>=0&&(e.features.cib=t)})):Promise.resolve(!1),B=l.can_use_canvas(this.options.createCanvas),a=(a=y&&v&&-1!==n.indexOf("ww")?l.worker_offscreen_canvas_support():Promise.resolve(!1)).then((function(t){E=t}));var s=l.cib_can_use_region().then((function(t){C=t}));return this.__initPromise=Promise.all([o,i,a,s]).then((function(){return e})),this.__initPromise},x.prototype.__invokeResize=function(t,e){var n=this;return e.__mathCache=e.__mathCache||{},Promise.resolve().then((function(){return n.features.ww?new Promise((function(r,i){var a=n.__workersPool.acquire();e.cancelToken&&e.cancelToken["catch"]((function(t){return i(t)})),a.value.onmessage=function(t){a.release(),t.data.err?i(t.data.err):r(t.data)};var o=[];t.src&&o.push(t.src.buffer),t.srcBitmap&&o.push(t.srcBitmap),a.value.postMessage({opts:t,features:n.__requested_features,preload:{wasm_nodule:n.__mathlib.__}},o)})):{data:n.__mathlib.resizeAndUnsharp(t,e.__mathCache)}}))},x.prototype.__extractTileData=function(t,e,n,r,i){if(this.features.ww&&E&&(l.isCanvas(e)||C))return this.debug("Create tile for OffscreenCanvas"),createImageBitmap(r.srcImageBitmap||e,t.x,t.y,t.width,t.height).then((function(t){return i.srcBitmap=t,i}));if(l.isCanvas(e))return r.srcCtx||(r.srcCtx=e.getContext("2d",{alpha:Boolean(n.alpha)})),this.debug("Get tile pixel data"),i.src=r.srcCtx.getImageData(t.x,t.y,t.width,t.height).data,i;this.debug("Draw tile imageBitmap/image to temporary canvas");var a=this.options.createCanvas(t.width,t.height),o=a.getContext("2d",{alpha:Boolean(n.alpha)});return o.globalCompositeOperation="copy",o.drawImage(r.srcImageBitmap||e,t.x,t.y,t.width,t.height,0,0,t.width,t.height),this.debug("Get tile pixel data"),i.src=o.getImageData(0,0,t.width,t.height).data,a.width=a.height=0,i},x.prototype.__landTileData=function(t,e,n){var r;if(this.debug("Convert raw rgba tile result to ImageData"),e.bitmap)return n.toCtx.drawImage(e.bitmap,t.toX,t.toY),null;if(v)r=new ImageData(new Uint8ClampedArray(e.data),t.toWidth,t.toHeight);else if((r=n.toCtx.createImageData(t.toWidth,t.toHeight)).data.set)r.data.set(e.data);else for(var i=r.data.length-1;i>=0;i--)r.data[i]=e.data[i];return this.debug("Draw tile"),_?n.toCtx.putImageData(r,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth+1e-5,t.toInnerHeight+1e-5):n.toCtx.putImageData(r,t.toX,t.toY,t.toInnerX-t.toX,t.toInnerY-t.toY,t.toInnerWidth,t.toInnerHeight),null},x.prototype.__tileAndResize=function(t,e,n){var r=this,i={srcCtx:null,srcImageBitmap:null,isImageBitmapReused:!1,toCtx:null},a=function(e){return r.__limit((function(){if(n.canceled)return n.cancelToken;var a={width:e.width,height:e.height,toWidth:e.toWidth,toHeight:e.toHeight,scaleX:e.scaleX,scaleY:e.scaleY,offsetX:e.offsetX,offsetY:e.offsetY,quality:n.quality,alpha:n.alpha,unsharpAmount:n.unsharpAmount,unsharpRadius:n.unsharpRadius,unsharpThreshold:n.unsharpThreshold};return r.debug("Invoke resize math"),Promise.resolve(a).then((function(a){return r.__extractTileData(e,t,n,i,a)})).then((function(t){return r.debug("Invoke resize math"),r.__invokeResize(t,n)})).then((function(t){return n.canceled?n.cancelToken:(i.srcImageData=null,r.__landTileData(e,t,i))}))}))};return Promise.resolve().then((function(){if(i.toCtx=e.getContext("2d",{alpha:Boolean(n.alpha)}),l.isCanvas(t))return null;if(l.isImageBitmap(t))return i.srcImageBitmap=t,i.isImageBitmapReused=!0,null;if(l.isImage(t))return y?(r.debug("Decode image via createImageBitmap"),createImageBitmap(t).then((function(t){i.srcImageBitmap=t}))["catch"]((function(t){return null}))):null;throw new Error('Pica: ".from" should be Image, Canvas or ImageBitmap')})).then((function(){if(n.canceled)return n.cancelToken;r.debug("Calculate tiles");var t=d({width:n.width,height:n.height,srcTileSize:r.options.tile,toWidth:n.toWidth,toHeight:n.toHeight,destTileBorder:n.__destTileBorder}).map((function(t){return a(t)}));function o(t){t.srcImageBitmap&&(t.isImageBitmapReused||t.srcImageBitmap.close(),t.srcImageBitmap=null)}return r.debug("Process tiles"),Promise.all(t).then((function(){return r.debug("Finished!"),o(i),e}),(function(t){throw o(i),t}))}))},x.prototype.__processStages=function(t,e,n,i){var a=this;if(i.canceled)return i.cancelToken;var o,s=r(t.shift(),2),A=s[0],h=s[1],f=0===t.length;return i=u({},i,{toWidth:A,toHeight:h,quality:f?i.quality:Math.min(1,i.quality)}),f||(o=this.options.createCanvas(A,h)),this.__tileAndResize(e,f?n:o,i).then((function(){return f?n:(i.width=A,i.height=h,a.__processStages(t,o,n,i))})).then((function(t){return o&&(o.width=o.height=0),t}))},x.prototype.__resizeViaCreateImageBitmap=function(t,e,n){var r=this,i=e.getContext("2d",{alpha:Boolean(n.alpha)});return this.debug("Resize via createImageBitmap()"),createImageBitmap(t,{resizeWidth:n.toWidth,resizeHeight:n.toHeight,resizeQuality:l.cib_quality_name(n.quality)}).then((function(t){if(n.canceled)return n.cancelToken;if(!n.unsharpAmount)return i.drawImage(t,0,0),t.close(),i=null,r.debug("Finished!"),e;r.debug("Unsharp result");var a=r.options.createCanvas(n.toWidth,n.toHeight),o=a.getContext("2d",{alpha:Boolean(n.alpha)});o.drawImage(t,0,0),t.close();var s=o.getImageData(0,0,n.toWidth,n.toHeight);return r.__mathlib.unsharp_mask(s.data,n.toWidth,n.toHeight,n.unsharpAmount,n.unsharpRadius,n.unsharpThreshold),i.putImageData(s,0,0),a.width=a.height=0,s=o=a=i=null,r.debug("Finished!"),e}))},x.prototype.resize=function(t,e,n){var r=this;this.debug("Start resize...");var i=u({},b);if(isNaN(n)?n&&(i=u(i,n)):i=u(i,{quality:n}),i.toWidth=e.width,i.toHeight=e.height,i.width=t.naturalWidth||t.width,i.height=t.naturalHeight||t.height,0===e.width||0===e.height)return Promise.reject(new Error("Invalid output size: ".concat(e.width,"x").concat(e.height)));i.unsharpRadius>2&&(i.unsharpRadius=2),i.canceled=!1,i.cancelToken&&(i.cancelToken=i.cancelToken.then((function(t){throw i.canceled=!0,t}),(function(t){throw i.canceled=!0,t})));var a=3;return i.__destTileBorder=Math.ceil(Math.max(a,2.5*i.unsharpRadius|0)),this.init().then((function(){if(i.canceled)return i.cancelToken;if(r.features.cib)return r.__resizeViaCreateImageBitmap(t,e,i);if(!B){var n=new Error("Pica: cannot use getImageData on canvas, "+"make sure fingerprinting protection isn't enabled");throw n.code="ERR_GET_IMAGE_DATA",n}var a=p(i.width,i.height,i.toWidth,i.toHeight,r.options.tile,i.__destTileBorder);return r.__processStages(a,t,e,i)}))},x.prototype.resizeBuffer=function(t){var e=this,n=u({},b,t);return this.init().then((function(){return e.__mathlib.resizeAndUnsharp(n)}))},x.prototype.toBlob=function(t,e,n){return e=e||"image/png",new Promise((function(r){if(t.toBlob)t.toBlob((function(t){return r(t)}),e,n);else if(t.convertToBlob)r(t.convertToBlob({type:e,quality:n}));else{for(var i=atob(t.toDataURL(e,n).split(",")[1]),a=i.length,o=new Uint8Array(a),s=0;s0;n--)e="0"+e;return"0x"+e}function r(t){try{return decodeURIComponent(escape(t))}catch(e){return t}}function i(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}function a(t,n,r){this.input=t.subarray(n,r),this.start=n;var i=String.fromCharCode.apply(null,this.input.subarray(0,4));if("II*\0"!==i&&"MM\0*"!==i)throw e("invalid TIFF signature","EBADDATA");this.big_endian="M"===i[0]}a.prototype.each=function(t){this.aborted=!1;var e=this.read_uint32(4);for(this.ifds_to_read=[{id:0,offset:e}];this.ifds_to_read.length>0&&!this.aborted;){var n=this.ifds_to_read.shift();n.offset&&this.scan_ifd(n.id,n.offset,t)}},a.prototype.filter=function(t){var n={ifd0:{id:0,entries:[]}};this.each((function(e){(!1!==t(e)||e.is_subifd_link)&&(e.is_subifd_link&&1!==e.count&&4!==e.format||(n["ifd"+e.ifd]||(n["ifd"+e.ifd]={id:e.ifd,entries:[]}),n["ifd"+e.ifd].entries.push(e)))})),delete n.ifd1;var r=8;Object.keys(n).forEach((function(t){r+=2,n[t].entries.forEach((function(t){r+=12+(t.data_length>4?2*Math.ceil(t.data_length/2):0)})),r+=4})),this.output=new Uint8Array(r),this.output[0]=this.output[1]=(this.big_endian?"M":"I").charCodeAt(0),this.write_uint16(2,42);var i=8,a=this;if(this.write_uint32(4,i),Object.keys(n).forEach((function(t){n[t].written_offset=i;var e=i,r=e+2+12*n[t].entries.length+4;i=r,a.write_uint16(e,n[t].entries.length),n[t].entries.sort((function(t,e){return t.tag-e.tag})).forEach((function(t,r){var o=e+2+12*r;a.write_uint16(o,t.tag),a.write_uint16(o+2,t.format),a.write_uint32(o+4,t.count),t.is_subifd_link?n["ifd"+t.tag]&&(n["ifd"+t.tag].link_offset=o+8):t.data_length<=4?a.output.set(a.input.subarray(t.data_offset-a.start,t.data_offset-a.start+4),o+8):(a.write_uint32(o+8,i),a.output.set(a.input.subarray(t.data_offset-a.start,t.data_offset-a.start+t.data_length),i),i+=2*Math.ceil(t.data_length/2))}));var o=n["ifd"+(n[t].id+1)];o&&(o.link_offset=r-4)})),Object.keys(n).forEach((function(t){n[t].written_offset&&n[t].link_offset&&a.write_uint32(n[t].link_offset,n[t].written_offset)})),this.output.length!==i)throw e("internal error: incorrect buffer size allocated");return this.output},a.prototype.read_uint16=function(t){var n=this.input;if(t+2>n.length)throw e("unexpected EOF","EBADDATA");return this.big_endian?256*n[t]+n[t+1]:n[t]+256*n[t+1]},a.prototype.read_uint32=function(t){var n=this.input;if(t+4>n.length)throw e("unexpected EOF","EBADDATA");return this.big_endian?16777216*n[t]+65536*n[t+1]+256*n[t+2]+n[t+3]:n[t]+256*n[t+1]+65536*n[t+2]+16777216*n[t+3]},a.prototype.write_uint16=function(t,e){var n=this.output;this.big_endian?(n[t]=e>>>8&255,n[t+1]=255&e):(n[t]=255&e,n[t+1]=e>>>8&255)},a.prototype.write_uint32=function(t,e){var n=this.output;this.big_endian?(n[t]=e>>>24&255,n[t+1]=e>>>16&255,n[t+2]=e>>>8&255,n[t+3]=255&e):(n[t]=255&e,n[t+1]=e>>>8&255,n[t+2]=e>>>16&255,n[t+3]=e>>>24&255)},a.prototype.is_subifd_link=function(t,e){return 0===t&&34665===e||0===t&&34853===e||34665===t&&40965===e},a.prototype.exif_format_length=function(t){switch(t){case 1:case 2:case 6:case 7:return 1;case 3:case 8:return 2;case 4:case 9:case 11:return 4;case 5:case 10:case 12:return 8;default:return 0}},a.prototype.exif_format_read=function(t,e){var n;switch(t){case 1:case 2:return n=this.input[e];case 6:return(n=this.input[e])|33554430*(128&n);case 3:return n=this.read_uint16(e);case 8:return(n=this.read_uint16(e))|131070*(32768&n);case 4:return n=this.read_uint32(e);case 9:return 0|(n=this.read_uint32(e));case 5:case 10:case 11:case 12:case 7:default:return null}},a.prototype.scan_ifd=function(t,n,i){var a=this.read_uint16(n);n+=2;for(var o=0;othis.input.length)throw e("unexpected EOF","EBADDATA");for(var g=[],p=c,d=0;d0&&(this.ifds_to_read.push({id:s,offset:g[0]}),l=!0),!1===i({is_big_endian:this.big_endian,ifd:t,tag:s,format:A,count:u,entry_offset:n+this.start,data_length:f,data_offset:c+this.start,value:g,is_subifd_link:l}))return void(this.aborted=!0);n+=12}0===t&&this.ifds_to_read.push({id:1,offset:this.read_uint32(n)})},t.exports.is_jpeg=function(t){return t.length>=4&&255===t[0]&&216===t[1]&&255===t[2]},t.exports.jpeg_segments_each=function(r,a){if(!i(r))throw e("Invalid argument (jpeg_bin), Uint8Array expected","EINVAL");if("function"!=typeof a)throw e("Invalid argument (on_segment), Function expected","EINVAL");if(!t.exports.is_jpeg(r))throw e("Unknown file format","ENOTJPEG");for(var o=0,s=r.length,A=!1;;){var u,h;if(o+1>=s)throw e("Unexpected EOF","EBADDATA");var f=r[o],c=r[o+1];if(255===f&&255===c)u=255,h=1;else if(255===f&&0!==c){if(h=2,208<=(u=c)&&u<=217||1===u);else{if(o+3>=s)throw e("Unexpected EOF","EBADDATA");if((h+=256*r[o+2]+r[o+3])<2)throw e("Invalid segment length","EBADDATA");if(o+h-1>=s)throw e("Unexpected EOF","EBADDATA")}A&&(u>=208&&u<=215||(A=!1)),218===u&&(A=!0)}else{if(!A)throw e("Unexpected byte at segment start: "+n(f)+" (offset "+n(o)+")","EBADDATA");for(var l=o+1;;l++){if(l>=s)throw e("Unexpected EOF","EBADDATA");if(255===r[l]){if(l+1>=s)throw e("Unexpected EOF","EBADDATA");if(0!==r[l+1]){u=0,h=l-o;break}}}}if(!1===a({code:u,offset:o,length:h}))break;if(217===u)break;o+=h}},t.exports.jpeg_segments_filter=function(n,r){if(!i(n))throw e("Invalid argument (jpeg_bin), Uint8Array expected","EINVAL");if("function"!=typeof r)throw e("Invalid argument (on_segment), Function expected","EINVAL");var a=[],o=0;t.exports.jpeg_segments_each(n,(function(t){var e=r(t);if(i(e))a.push({data:e}),o+=e.length;else if(Array.isArray(e))e.filter(i).forEach((function(t){a.push({data:t}),o+=t.length}));else if(!1!==e){var n={start:t.offset,end:t.offset+t.length};a.length>0&&a[a.length-1].end===n.start?a[a.length-1].end=n.end:a.push(n),o+=t.length}}));var s=new Uint8Array(o),A=0;return a.forEach((function(t){var e=t.data||n.subarray(t.start,t.end);s.set(e,A),A+=e.length})),s},t.exports.jpeg_exif_tags_each=function(n,r){if(!i(n))throw e("Invalid argument (jpeg_bin), Uint8Array expected","EINVAL");if("function"!=typeof r)throw e("Invalid argument (on_exif_entry), Function expected","EINVAL");t.exports.jpeg_segments_each(n,(function(t){return 218!==t.code&&(225===t.code&&t.length>=10&&69===n[t.offset+4]&&120===n[t.offset+5]&&105===n[t.offset+6]&&102===n[t.offset+7]&&0===n[t.offset+8]&&0===n[t.offset+9]?(new a(n,t.offset+10,t.offset+t.length).each(r),!1):void 0)}))},t.exports.jpeg_exif_tags_filter=function(n,r){if(!i(n))throw e("Invalid argument (jpeg_bin), Uint8Array expected","EINVAL");if("function"!=typeof r)throw e("Invalid argument (on_exif_entry), Function expected","EINVAL");var o=!1;return t.exports.jpeg_segments_filter(n,(function(t){if(!o&&(218===t.code&&(o=!0),225===t.code&&t.length>=10&&69===n[t.offset+4]&&120===n[t.offset+5]&&105===n[t.offset+6]&&102===n[t.offset+7]&&0===n[t.offset+8]&&0===n[t.offset+9])){var e=new a(n,t.offset+10,t.offset+t.length).filter(r);if(!e)return!1;var i=new Uint8Array(10);return i.set(n.slice(t.offset,t.offset+10)),i[2]=e.length+8>>>8&255,i[3]=e.length+8&255,o=!0,[i,e]}}))},t.exports.jpeg_add_comment=function(e,n){var r=!1,i=0;return t.exports.jpeg_segments_filter(e,(function(t){if(!(1===++i&&216===t.code||2===i&&224===t.code||r)){n=function(t){try{return unescape(encodeURIComponent(t))}catch(e){return t}}(n);var a=new Uint8Array(5+n.length),o=0;return a[o++]=255,a[o++]=254,a[o++]=n.length+3>>>8&255,a[o++]=n.length+3&255,n.split("").forEach((function(t){a[o++]=255&t.charCodeAt(0)})),a[o++]=0,r=!0,[a,e.subarray(t.offset,t.offset+t.length)]}}))}}));function o(t){return this._getUint8Array(t.blob).then((function(e){if(t.is_jpeg=a.is_jpeg(e),!t.is_jpeg)return Promise.resolve(t);t.orig_blob=t.blob;try{var n,r;if(a.jpeg_exif_tags_each(e,(function(e){if(0===e.ifd&&274===e.tag&&Array.isArray(e.value))return t.orientation=e.value[0]||1,n=e.is_big_endian,r=e.data_offset,!1})),r){var i=n?new Uint8Array([0,1]):new Uint8Array([1,0]);t.blob=new Blob([e.slice(0,r),i,e.slice(r+2)],{type:"image/jpeg"})}}catch(t){}return t}))}function s(t){if(!t.is_jpeg)return Promise.resolve(t);var e,n=t.orientation-1;if(!n)return Promise.resolve(t);var r=(e=4&n?this.pica.options.createCanvas(t.out_canvas.height,t.out_canvas.width):this.pica.options.createCanvas(t.out_canvas.width,t.out_canvas.height)).getContext("2d");return r.save(),1&n&&r.transform(-1,0,0,1,e.width,0),2&n&&r.transform(-1,0,0,-1,e.width,e.height),4&n&&r.transform(0,1,1,0,0,0),r.drawImage(t.out_canvas,0,0),r.restore(),t.out_canvas.width=t.out_canvas.height=0,t.out_canvas=e,Promise.resolve(t)}function A(t){return t.is_jpeg?Promise.all([this._getUint8Array(t.blob),this._getUint8Array(t.out_blob)]).then((function(e){var n=e[0],r=e[1];if(!a.is_jpeg(n))return Promise.resolve(t);var i=[];return a.jpeg_segments_each(n,(function(t){if(218===t.code)return!1;i.push(t)})),i=i.filter((function(t){return 226!==t.code&&(t.code>=224&&t.code<240||254===t.code)})).map((function(t){return n.slice(t.offset,t.offset+t.length)})),t.out_blob=new Blob([r.slice(0,2)].concat(i).concat([r.slice(20)]),{type:"image/jpeg"}),t})):Promise.resolve(t)}var u={jpeg_patch_exif:o,jpeg_rotate_canvas:s,jpeg_attach_orig_segments:A,assign:function(t){t.before("_blob_to_image",o),t.after("_transform",s),t.after("_create_blob",A)}};function h(t){if(!(this instanceof h))return new h(t);t=t||{},this.pica=t.pica||i({}),this.initialized=!1,this.utils=e}return h.prototype.use=function(t){var e=[this].concat(Array.prototype.slice.call(arguments,1));return t.apply(t,e),this},h.prototype.init=function(){this.use(u.assign)},h.prototype.toBlob=function(t,n){var r={blob:t,opts:e.assign({max:1/0},n)};return this.initialized||(this.init(),this.initialized=!0),Promise.resolve(r).then(this._blob_to_image).then(this._calculate_size).then(this._transform).then(this._cleanup).then(this._create_blob).then((function(t){return t.out_canvas.width=t.out_canvas.height=0,t.out_blob}))},h.prototype.toCanvas=function(t,n){var r={blob:t,opts:e.assign({max:1/0},n)};return this.initialized||(this.init(),this.initialized=!0),Promise.resolve(r).then(this._blob_to_image).then(this._calculate_size).then(this._transform).then(this._cleanup).then((function(t){return t.out_canvas}))},h.prototype.before=function(t,e){if(!this[t])throw new Error('Method "'+t+'" does not exist');if("function"!=typeof e)throw new Error('Invalid argument "fn", function expected');var n=this[t],r=this;return this[t]=function(t){return e.call(r,t).then((function(t){return n.call(r,t)}))},this},h.prototype.after=function(t,e){if(!this[t])throw new Error('Method "'+t+'" does not exist');if("function"!=typeof e)throw new Error('Invalid argument "fn", function expected');var n=this[t],r=this;return this[t]=function(t){return n.call(r,t).then((function(t){return e.call(r,t)}))},this},h.prototype._blob_to_image=function(t){var e=window.URL||window.webkitURL||window.mozURL||window.msURL;return t.image=document.createElement("img"),t.image_url=e.createObjectURL(t.blob),t.image.src=t.image_url,new Promise((function(e,n){t.image.onerror=function(){n(new Error("ImageBlobReduce: failed to create Image() from blob"))},t.image.onload=function(){e(t)}}))},h.prototype._calculate_size=function(t){var e=t.opts.max/Math.max(t.image.width,t.image.height);return e>1&&(e=1),t.transform_width=Math.max(Math.round(t.image.width*e),1),t.transform_height=Math.max(Math.round(t.image.height*e),1),t.scale_factor=e,Promise.resolve(t)},h.prototype._transform=function(t){t.out_canvas=this.pica.options.createCanvas(t.transform_width,t.transform_height),t.transform_width=null,t.transform_height=null;var e={alpha:"image/png"===t.blob.type};return this.utils.assign(e,this.utils.pick_pica_resize_options(t.opts)),this.pica.resize(t.image,t.out_canvas,e).then((function(){return t}))},h.prototype._cleanup=function(t){t.image.src="",t.image=null;var e=window.URL||window.webkitURL||window.mozURL||window.msURL;return e.revokeObjectURL&&e.revokeObjectURL(t.image_url),t.image_url=null,Promise.resolve(t)},h.prototype._create_blob=function(t){return this.pica.toBlob(t.out_canvas,t.blob.type).then((function(e){return t.out_blob=e,t}))},h.prototype._getUint8Array=function(t){return t.arrayBuffer?t.arrayBuffer().then((function(t){return new Uint8Array(t)})):new Promise((function(e,n){var r=new FileReader;r.readAsArrayBuffer(t),r.onload=function(){e(new Uint8Array(r.result))},r.onerror=function(){n(new Error("ImageBlobReduce: failed to load data from input blob")),r.abort()},r.onabort=function(){n(new Error("ImageBlobReduce: failed to load data from input blob (aborted)"))}}))},h.pica=i,h}));