2 lines
44 KiB
JavaScript
2 lines
44 KiB
JavaScript
var e=function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=Object(arguments[n]),t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e};function t(e,t){var n={};return t.forEach(function(t){Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t])}),n}function n(e){return t(e,[`alpha`,`unsharpAmount`,`unsharpRadius`,`unsharpThreshold`,`cancelToken`])}var r={assign:e,pick:t,pick_pica_resize_options:n};function i(e){var t={exports:{}};return e(t,t.exports),t.exports}function a(e){throw Error(`Could not dynamically require "`+e+`". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.`)}var o=i(function(e,t){(function(t){e.exports=t()})(function(){return(function(){function e(t,n,r){function i(s,c){if(!n[s]){if(!t[s]){var l=typeof a==`function`&&a;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=n[s]={exports:{}};t[s][0].call(d.exports,function(e){var n=t[s][1][e];return i(n||e)},d,d.exports,e,t,n,r)}return n[s].exports}for(var o=typeof a==`function`&&a,s=0;s<r.length;s++)i(r[s]);return i}return e})()({1:[function(e,t,n){var r=e(`inherits`),i=e(`multimath`),a=e(`./mm_unsharp_mask`),o=e(`./mm_resize`);function s(e){var t=e||[],n={js:t.indexOf(`js`)>=0,wasm:t.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(e,t){var n=this.resize(e,t);return e.unsharpAmount&&this.unsharp_mask(n,e.toWidth,e.toHeight,e.unsharpAmount,e.unsharpRadius,e.unsharpThreshold),n},t.exports=s},{"./mm_resize":4,"./mm_unsharp_mask":9,inherits:19,multimath:20}],2:[function(e,t,n){function r(e){return e<0?0:e>255?255:e}function i(e,t,n,i,a,o){var s,c,l,u,d,f,p,m,h,g,_,v=0,y=0;for(h=0;h<i;h++){for(d=0,g=0;g<a;g++){for(f=o[d++],p=o[d++],m=v+f*4|0,s=c=l=u=0;p>0;p--)_=o[d++],u=u+_*e[m+3]|0,l=l+_*e[m+2]|0,c=c+_*e[m+1]|0,s=s+_*e[m]|0,m=m+4|0;t[y+3]=r(u+8192>>14),t[y+2]=r(l+8192>>14),t[y+1]=r(c+8192>>14),t[y]=r(s+8192>>14),y=y+i*4|0}y=(h+1)*4|0,v=(h+1)*n*4|0}}function a(e,t,n,i,a,o){var s,c,l,u,d,f,p,m,h,g,_,v=0,y=0;for(h=0;h<i;h++){for(d=0,g=0;g<a;g++){for(f=o[d++],p=o[d++],m=v+f*4|0,s=c=l=u=0;p>0;p--)_=o[d++],u=u+_*e[m+3]|0,l=l+_*e[m+2]|0,c=c+_*e[m+1]|0,s=s+_*e[m]|0,m=m+4|0;t[y+3]=r(u+8192>>14),t[y+2]=r(l+8192>>14),t[y+1]=r(c+8192>>14),t[y]=r(s+8192>>14),y=y+i*4|0}y=(h+1)*4|0,v=(h+1)*n*4|0}}t.exports={convolveHorizontally:i,convolveVertically:a}},{}],3:[function(e,t,n){t.exports=`AGFzbQEAAAAADAZkeWxpbmsAAAAAAAEXA2AAAGAGf39/f39/AGAHf39/f39/fwACDwEDZW52Bm1lbW9yeQIAAAMEAwABAgYGAX8AQQALB1cFEV9fd2FzbV9jYWxsX2N0b3JzAAAIY29udm9sdmUAAQpjb252b2x2ZUhWAAIMX19kc29faGFuZGxlAwAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAK7AMDAwABC8YDAQ9/AkAgA0UNACAERQ0AA0AgDCENQQAhE0EAIQcDQCAHQQJqIQYCfyAHQQF0IAVqIgcuAQIiFEUEQEGAwAAhCEGAwAAhCUGAwAAhCkGAwAAhCyAGDAELIBIgBy4BAGohCEEAIQsgFCEHQQAhDiAGIQlBACEPQQAhEANAIAUgCUEBdGouAQAiESAAIAhBAnRqKAIAIgpBGHZsIBBqIRAgCkH/AXEgEWwgC2ohCyAKQRB2Qf8BcSARbCAPaiEPIApBCHZB/wFxIBFsIA5qIQ4gCEEBaiEIIAlBAWohCSAHQQFrIgcNAAsgC0GAQGshCCAOQYBAayEJIA9BgEBrIQogEEGAQGshCyAGIBRqCyEHIAEgDUECdGogCUEOdSIGQf8BIAZB/wFIGyIGQQAgBkEAShtBCHRBgP4DcSAKQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EQdEGAgPwHcSALQQ51IgZB/wEgBkH/AUgbIgZBACAGQQBKG0EYdHJyIAhBDnUiBkH/ASAGQf8BSBsiBkEAIAZBAEobcjYCACADIA1qIQ0gE0EBaiITIARHDQALIAxBAWoiDCACbCESIAMgDEcNAAsLCx4AQQAgAiADIAQgBSAAEAEgAkEAIAQgBSAGIAEQAQs=`},{}],4:[function(e,t,n){t.exports={name:`resize`,fn:e(`./resize`),wasm_fn:e(`./resize_wasm`),wasm_src:e(`./convolve_wasm_base64`)}},{"./convolve_wasm_base64":3,"./resize":5,"./resize_wasm":8}],5:[function(e,t,n){var r=e(`./resize_filter_gen`),i=e(`./convolve`).convolveHorizontally,a=e(`./convolve`).convolveVertically;function o(e,t,n){for(var r=3,i=t*n*4|0;r<i;)e[r]=255,r=r+4|0}t.exports=function(e){var t=e.src,n=e.width,s=e.height,c=e.toWidth,l=e.toHeight,u=e.scaleX||e.toWidth/e.width,d=e.scaleY||e.toHeight/e.height,f=e.offsetX||0,p=e.offsetY||0,m=e.dest||new Uint8Array(c*l*4),h=e.quality===void 0?3:e.quality,g=e.alpha||!1,_=r(h,n,c,u,f),v=r(h,s,l,d,p),y=new Uint8Array(c*s*4);return i(t,y,n,s,c,_),a(y,m,s,c,l,v),g||o(m,c,l),m}},{"./convolve":2,"./resize_filter_gen":6}],6:[function(e,t,n){var r=e(`./resize_filter_info`),i=14;function a(e){return Math.round(e*((1<<i)-1))}t.exports=function(e,t,n,i,o){var s=r[e].filter,c=1/i,l=Math.min(1,i),u=r[e].win/l,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O=Math.floor((u+1)*2),k=new Int16Array((O+2)*n),A=0,j=!k.subarray||!k.set;for(d=0;d<n;d++){for(f=(d+.5)*c+o,p=Math.max(0,Math.floor(f-u)),m=Math.min(t-1,Math.ceil(f+u)),h=m-p+1,g=new Float32Array(h),_=new Int16Array(h),v=0,y=p,b=0;y<=m;y++,b++)x=s((y+.5-f)*l),v+=x,g[b]=x;for(S=0,b=0;b<g.length;b++)C=g[b]/v,S+=C,_[b]=a(C);for(_[n>>1]+=a(1-S),w=0;w<_.length&&_[w]===0;)w++;if(w<_.length){for(T=_.length-1;T>0&&_[T]===0;)T--;if(E=p+w,D=T-w+1,k[A++]=E,k[A++]=D,!j)k.set(_.subarray(w,T+1),A),A+=D;else for(b=w;b<=T;b++)k[A++]=_[b]}else k[A++]=0,k[A++]=0}return k}},{"./resize_filter_info":7}],7:[function(e,t,n){t.exports=[{win:.5,filter:function(e){return+(e>=-.5&&e<.5)}},{win:1,filter:function(e){if(e<=-1||e>=1)return 0;if(e>-1.1920929e-7&&e<1.1920929e-7)return 1;var t=e*Math.PI;return Math.sin(t)/t*(.54+.46*Math.cos(t/1))}},{win:2,filter:function(e){if(e<=-2||e>=2)return 0;if(e>-1.1920929e-7&&e<1.1920929e-7)return 1;var t=e*Math.PI;return Math.sin(t)/t*Math.sin(t/2)/(t/2)}},{win:3,filter:function(e){if(e<=-3||e>=3)return 0;if(e>-1.1920929e-7&&e<1.1920929e-7)return 1;var t=e*Math.PI;return Math.sin(t)/t*Math.sin(t/3)/(t/3)}}]},{}],8:[function(e,t,n){var r=e(`./resize_filter_gen`);function i(e,t,n){for(var r=3,i=t*n*4|0;r<i;)e[r]=255,r=r+4|0}function a(e){return new Uint8Array(e.buffer,0,e.byteLength)}var o=!0;try{o=new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0]===1}catch{}function s(e,t,n){if(o){t.set(a(e),n);return}for(var r=n,i=0;i<e.length;i++){var s=e[i];t[r++]=s&255,t[r++]=s>>8&255}}t.exports=function(e){var t=e.src,n=e.width,a=e.height,o=e.toWidth,c=e.toHeight,l=e.scaleX||e.toWidth/e.width,u=e.scaleY||e.toHeight/e.height,d=e.offsetX||0,f=e.offsetY||0,p=e.dest||new Uint8Array(o*c*4),m=e.quality===void 0?3:e.quality,h=e.alpha||!1,g=r(m,n,o,l,d),_=r(m,a,c,u,f),v=this.__align(0+Math.max(t.byteLength,p.byteLength)),y=this.__align(v+a*o*4),b=this.__align(y+g.byteLength),x=b+_.byteLength,S=this.__instance(`resize`,x),C=new Uint8Array(this.__memory.buffer),w=new Uint32Array(this.__memory.buffer),T=new Uint32Array(t.buffer);return w.set(T),s(g,C,y),s(_,C,b),(S.exports.convolveHV||S.exports._convolveHV)(y,b,v,n,a,o,c),new Uint32Array(p.buffer).set(new Uint32Array(this.__memory.buffer,0,c*o)),h||i(p,o,c),p}},{"./resize_filter_gen":6}],9:[function(e,t,n){t.exports={name:`unsharp_mask`,fn:e(`./unsharp_mask`),wasm_fn:e(`./unsharp_mask_wasm`),wasm_src:e(`./unsharp_mask_wasm_base64`)}},{"./unsharp_mask":10,"./unsharp_mask_wasm":11,"./unsharp_mask_wasm_base64":12}],10:[function(e,t,n){var r=e(`glur/mono16`);function i(e,t,n){for(var r=t*n,i=new Uint16Array(r),a,o,s,c,l=0;l<r;l++)a=e[4*l],o=e[4*l+1],s=e[4*l+2],c=a>=o&&a>=s?a:o>=s&&o>=a?o:s,i[l]=c<<8;return i}t.exports=function(e,t,n,a,o,s){var c,l,u,d,f;if(!(a===0||o<.5)){o>2&&(o=2);var p=i(e,t,n),m=new Uint16Array(p);r(m,t,n,o);for(var h=a/100*4096+.5|0,g=s<<8,_=t*n,v=0;v<_;v++)c=p[v],d=c-m[v],Math.abs(d)>=g&&(l=c+(h*d+2048>>12),l=l>65280?65280:l,l=l<0?0:l,c=c===0?1:c,u=(l<<12)/c|0,f=v*4,e[f]=e[f]*u+2048>>12,e[f+1]=e[f+1]*u+2048>>12,e[f+2]=e[f+2]*u+2048>>12)}}},{"glur/mono16":18}],11:[function(e,t,n){t.exports=function(e,t,n,r,i,a){if(!(r===0||i<.5)){i>2&&(i=2);var o=t*n,s=o*4,c=o*2,l=o*2,u=Math.max(t,n)*4,d=32,f=0,p=s,m=p+c,h=m+l,g=h+l,_=g+u,v=this.__instance(`unsharp_mask`,s+c+l*2+u+d,{exp:Math.exp}),y=new Uint32Array(e.buffer);new Uint32Array(this.__memory.buffer).set(y);var b=v.exports.hsv_v16||v.exports._hsv_v16;b(f,p,t,n),b=v.exports.blurMono16||v.exports._blurMono16,b(p,m,h,g,_,t,n,i),b=v.exports.unsharp||v.exports._unsharp,b(f,f,p,m,t,n,r,a),y.set(new Uint32Array(this.__memory.buffer,0,o))}}},{}],12:[function(e,t,n){t.exports=`AGFzbQEAAAAADAZkeWxpbmsAAAAAAAE0B2AAAGAEf39/fwBgBn9/f39/fwBgCH9/f39/f39/AGAIf39/f39/f30AYAJ9fwBgAXwBfAIZAgNlbnYDZXhwAAYDZW52Bm1lbW9yeQIAAAMHBgAFAgQBAwYGAX8AQQALB4oBCBFfX3dhc21fY2FsbF9jdG9ycwABFl9fYnVpbGRfZ2F1c3NpYW5fY29lZnMAAg5fX2dhdXNzMTZfbGluZQADCmJsdXJNb25vMTYABAdoc3ZfdjE2AAUHdW5zaGFycAAGDF9fZHNvX2hhbmRsZQMAGF9fd2FzbV9hcHBseV9kYXRhX3JlbG9jcwABCsUMBgMAAQvWAQEHfCABRNuGukOCGvs/IAC7oyICRAAAAAAAAADAohAAIgW2jDgCFCABIAKaEAAiAyADoCIGtjgCECABRAAAAAAAAPA/IAOhIgQgBKIgAyACIAKgokQAAAAAAADwP6AgBaGjIgS2OAIAIAEgBSAEmqIiB7Y4AgwgASADIAJEAAAAAAAA8D+gIASioiIItjgCCCABIAMgAkQAAAAAAADwv6AgBKKiIgK2OAIEIAEgByAIoCAFRAAAAAAAAPA/IAahoCIDo7Y4AhwgASAEIAKgIAOjtjgCGAuGBQMGfwl8An0gAyoCDCEVIAMqAgghFiADKgIUuyERIAMqAhC7IRACQCAEQQFrIghBAEgiCQRAIAIhByAAIQYMAQsgAiAALwEAuCIPIAMqAhi7oiIMIBGiIg0gDCAQoiAPIAMqAgS7IhOiIhQgAyoCALsiEiAPoqCgoCIOtjgCACACQQRqIQcgAEECaiEGIAhFDQAgCEEBIAhBAUgbIgpBf3MhCwJ/IAQgCmtBAXFFBEAgDiENIAgMAQsgAiANIA4gEKIgFCASIAAvAQK4Ig+ioKCgIg22OAIEIAJBCGohByAAQQRqIQYgDiEMIARBAmsLIQIgC0EAIARrRg0AA0AgByAMIBGiIA0gEKIgDyAToiASIAYvAQC4Ig6ioKCgIgy2OAIAIAcgDSARoiAMIBCiIA4gE6IgEiAGLwECuCIPoqCgoCINtjgCBCAHQQhqIQcgBkEEaiEGIAJBAkohACACQQJrIQIgAA0ACwsCQCAJDQAgASAFIAhsQQF0aiIAAn8gBkECay8BACICuCINIBW7IhKiIA0gFrsiE6KgIA0gAyoCHLuiIgwgEKKgIAwgEaKgIg8gB0EEayIHKgIAu6AiDkQAAAAAAADwQWMgDkQAAAAAAAAAAGZxBEAgDqsMAQtBAAs7AQAgCEUNACAGQQRrIQZBACAFa0EBdCEBA0ACfyANIBKiIAJB//8DcbgiDSAToqAgDyIOIBCioCAMIBGioCIPIAdBBGsiByoCALugIgxEAAAAAAAA8EFjIAxEAAAAAAAAAABmcQRAIAyrDAELQQALIQMgBi8BACECIAAgAWoiACADOwEAIAZBAmshBiAIQQFKIQMgDiEMIAhBAWshCCADDQALCwvRAgIBfwd8AkAgB0MAAAAAWw0AIARE24a6Q4Ia+z8gB0MAAAA/l7ujIglEAAAAAAAAAMCiEAAiDLaMOAIUIAQgCZoQACIKIAqgIg22OAIQIAREAAAAAAAA8D8gCqEiCyALoiAKIAkgCaCiRAAAAAAAAPA/oCAMoaMiC7Y4AgAgBCAMIAuaoiIOtjgCDCAEIAogCUQAAAAAAADwP6AgC6KiIg+2OAIIIAQgCiAJRAAAAAAAAPC/oCALoqIiCbY4AgQgBCAOIA+gIAxEAAAAAAAA8D8gDaGgIgqjtjgCHCAEIAsgCaAgCqO2OAIYIAYEQANAIAAgBSAIbEEBdGogAiAIQQF0aiADIAQgBSAGEAMgCEEBaiIIIAZHDQALCyAFRQ0AQQAhCANAIAIgBiAIbEEBdGogASAIQQF0aiADIAQgBiAFEAMgCEEBaiIIIAVHDQALCwtxAQN/IAIgA2wiBQRAA0AgASAAKAIAIgRBEHZB/wFxIgIgAiAEQQh2Qf8BcSIDIAMgBEH/AXEiBEkbIAIgA0sbIgYgBiAEIAIgBEsbIAMgBEsbQQh0OwEAIAFBAmohASAAQQRqIQAgBUEBayIFDQALCwuZAgIDfwF8IAQgBWwhBAJ/IAazQwAAgEWUQwAAyEKVu0QAAAAAAADgP6AiC5lEAAAAAAAA4EFjBEAgC6oMAQtBgICAgHgLIQUgBARAIAdBCHQhCUEAIQYDQCAJIAIgBkEBdCIHai8BACIBIAMgB2ovAQBrIgcgB0EfdSIIaiAIc00EQCAAIAZBAnQiCGoiCiAFIAdsQYAQakEMdSABaiIHQYD+AyAHQYD+A0gbIgdBACAHQQBKG0EMdCABQQEgARtuIgEgCi0AAGxBgBBqQQx2OgAAIAAgCEEBcmoiByABIActAABsQYAQakEMdjoAACAAIAhBAnJqIgcgASAHLQAAbEGAEGpBDHY6AAALIAZBAWoiBiAERw0ACwsL`},{}],13:[function(e,t,n){var r=100;function i(e,t){this.create=e,this.available=[],this.acquired={},this.lastId=1,this.timeoutId=0,this.idle=t||2e3}i.prototype.acquire=function(){var e=this,t;return this.available.length===0?(t=this.create(),t.id=this.lastId++,t.release=function(){return e.release(t)}):t=this.available.pop(),this.acquired[t.id]=t,t},i.prototype.release=function(e){var t=this;delete this.acquired[e.id],e.lastUsed=Date.now(),this.available.push(e),this.timeoutId===0&&(this.timeoutId=setTimeout(function(){return t.gc()},r))},i.prototype.gc=function(){var e=this,t=Date.now();this.available=this.available.filter(function(n){return t-n.lastUsed>e.idle?(n.destroy(),!1):!0}),this.available.length===0?this.timeoutId=0:this.timeoutId=setTimeout(function(){return e.gc()},r)},t.exports=i},{}],14:[function(e,t,n){var r=2;t.exports=function(e,t,n,i,a,o){var s=n/e,c=i/t,l=(2*o+r+1)/a;if(l>.5)return[[n,i]];var u=Math.ceil(Math.log(Math.min(s,c))/Math.log(l));if(u<=1)return[[n,i]];for(var d=[],f=0;f<u;f++){var p=Math.round((e**(u-f-1)*n**+(f+1))**(1/u)),m=Math.round((t**(u-f-1)*i**+(f+1))**(1/u));d.push([p,m])}return d}},{}],15:[function(e,t,n){var r=1e-5;function i(e){var t=Math.round(e);return Math.abs(e-t)<r?t:Math.floor(e)}function a(e){var t=Math.round(e);return Math.abs(e-t)<r?t:Math.ceil(e)}t.exports=function(e){var t=e.toWidth/e.width,n=e.toHeight/e.height,r=i(e.srcTileSize*t)-2*e.destTileBorder,o=i(e.srcTileSize*n)-2*e.destTileBorder;if(r<1||o<1)throw Error(`Internal error in pica: target tile width/height is too small.`);var s,c,l,u,d,f,p=[],m;for(u=0;u<e.toHeight;u+=o)for(l=0;l<e.toWidth;l+=r)s=l-e.destTileBorder,s<0&&(s=0),d=l+r+e.destTileBorder-s,s+d>=e.toWidth&&(d=e.toWidth-s),c=u-e.destTileBorder,c<0&&(c=0),f=u+o+e.destTileBorder-c,c+f>=e.toHeight&&(f=e.toHeight-c),m={toX:s,toY:c,toWidth:d,toHeight:f,toInnerX:l,toInnerY:u,toInnerWidth:r,toInnerHeight:o,offsetX:s/t-i(s/t),offsetY:c/n-i(c/n),scaleX:t,scaleY:n,x:i(s/t),y:i(c/n),width:a(d/t),height:a(f/n)},p.push(m);return p}},{}],16:[function(e,t,n){function r(e){return Object.prototype.toString.call(e)}t.exports.isCanvas=function(e){var t=r(e);return t===`[object HTMLCanvasElement]`||t===`[object OffscreenCanvas]`||t===`[object Canvas]`},t.exports.isImage=function(e){return r(e)===`[object HTMLImageElement]`},t.exports.isImageBitmap=function(e){return r(e)===`[object ImageBitmap]`},t.exports.limiter=function(e){var t=0,n=[];function r(){t<e&&n.length&&(t++,n.shift()())}return function(e){return new Promise(function(i,a){n.push(function(){e().then(function(e){i(e),t--,r()},function(e){a(e),t--,r()})}),r()})}},t.exports.cib_quality_name=function(e){switch(e){case 0:return`pixelated`;case 1:return`low`;case 2:return`medium`}return`high`},t.exports.cib_support=function(e){return Promise.resolve().then(function(){if(typeof createImageBitmap>`u`)return!1;var t=e(100,100);return createImageBitmap(t,0,0,100,100,{resizeWidth:10,resizeHeight:10,resizeQuality:`high`}).then(function(e){var n=e.width===10;return e.close(),t=null,n})}).catch(function(){return!1})},t.exports.worker_offscreen_canvas_support=function(){return new Promise(function(e,t){if(typeof OffscreenCanvas>`u`){e(!1);return}function n(e){if(typeof createImageBitmap>`u`){e.postMessage(!1);return}Promise.resolve().then(function(){var e=new OffscreenCanvas(10,10);return e.getContext(`2d`).rect(0,0,1,1),createImageBitmap(e,0,0,1,1)}).then(function(){return e.postMessage(!0)},function(){return e.postMessage(!1)})}var r=btoa(`(${n.toString()})(self);`),i=new Worker(`data:text/javascript;base64,${r}`);i.onmessage=function(t){return e(t.data)},i.onerror=t}).then(function(e){return e},function(){return!1})},t.exports.can_use_canvas=function(e){var t=!1;try{var n=e(2,1).getContext(`2d`),r=n.createImageData(2,1);r.data[0]=12,r.data[1]=23,r.data[2]=34,r.data[3]=255,r.data[4]=45,r.data[5]=56,r.data[6]=67,r.data[7]=255,n.putImageData(r,0,0),r=null,r=n.getImageData(0,0,2,1),r.data[0]===12&&r.data[1]===23&&r.data[2]===34&&r.data[3]===255&&r.data[4]===45&&r.data[5]===56&&r.data[6]===67&&r.data[7]===255&&(t=!0)}catch{}return t},t.exports.cib_can_use_region=function(){return new Promise(function(e){if(typeof createImageBitmap>`u`){e(!1);return}var t=new Image;t.src=`data:image/jpeg;base64,/9j/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9sAQwAEAwMEAwMEBAMEBQQEBQYKBwYGBgYNCQoICg8NEBAPDQ8OERMYFBESFxIODxUcFRcZGRsbGxAUHR8dGh8YGhsa/9sAQwEEBQUGBQYMBwcMGhEPERoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoaGhoa/8IAEQgAAQACAwERAAIRAQMRAf/EABQAAQAAAAAAAAAAAAAAAAAAAAf/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAF/P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQH//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z`,t.onload=function(){createImageBitmap(t,0,0,t.width,t.height).then(function(n){n.width===t.width&&n.height===t.height?e(!0):e(!1)},function(){return e(!1)})},t.onerror=function(){return e(!1)}})}},{}],17:[function(e,t,n){t.exports=function(){var t=e(`./mathlib`),n;onmessage=function(e){var r=e.data.opts,i=!1;if(!r.src&&r.srcBitmap){var a=new OffscreenCanvas(r.width,r.height),o=a.getContext(`2d`,{alpha:!!r.alpha});o.drawImage(r.srcBitmap,0,0),r.src=o.getImageData(0,0,r.width,r.height).data,a.width=a.height=0,a=null,r.srcBitmap.close(),r.srcBitmap=null,i=!0}n||=new t(e.data.features);var s=n.resizeAndUnsharp(r);if(i){var c=new ImageData(new Uint8ClampedArray(s),r.toWidth,r.toHeight),l=new OffscreenCanvas(r.toWidth,r.toHeight);l.getContext(`2d`,{alpha:!!r.alpha}).putImageData(c,0,0),createImageBitmap(l).then(function(e){postMessage({bitmap:e},[e])})}else postMessage({data:s},[s.buffer])}}},{"./mathlib":1}],18:[function(e,t,n){var r,i,a,o,s,c,l,u;function d(e){e<.5&&(e=.5);var t=Math.exp(.726*.726)/e,n=Math.exp(-t),d=Math.exp(-2*t),f=(1-n)*(1-n)/(1+2*t*n-d);return r=f,i=f*(t-1)*n,a=f*(t+1)*n,o=-f*d,s=2*n,c=-d,l=(r+i)/(1-s-c),u=(a+o)/(1-s-c),new Float32Array([r,i,a,o,s,c,l,u])}function f(e,t,n,r,i,a){var o,s,c,l,u,d,f,p,m,h,g,_,v,y;for(m=0;m<a;m++){for(d=m*i,f=m,p=0,o=e[d],u=o*r[6],l=u,g=r[0],_=r[1],v=r[4],y=r[5],h=0;h<i;h++)s=e[d],c=s*g+o*_+l*v+u*y,u=l,l=c,o=s,n[p]=l,p++,d++;for(d--,p--,f+=a*(i-1),o=e[d],u=o*r[7],l=u,s=o,g=r[2],_=r[3],h=i-1;h>=0;h--)c=s*g+o*_+l*v+u*y,u=l,l=c,o=s,s=e[d],t[f]=n[p]+l,d--,p--,f-=a}}function p(e,t,n,r){if(r){var i=new Uint16Array(e.length),a=new Float32Array(Math.max(t,n)),o=d(r);f(e,i,a,o,t,n),f(i,e,a,o,n,t)}}t.exports=p},{}],19:[function(e,t,n){typeof Object.create==`function`?t.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},{}],20:[function(e,t,n){var r=e(`object-assign`),i=e(`./lib/base64decode`),a=e(`./lib/wa_detect`),o={js:!0,wasm:!0};function s(e){if(!(this instanceof s))return new s(e);var t=r({},o,e||{});if(this.options=t,this.__cache={},this.__init_promise=null,this.__modules=t.modules||{},this.__memory=null,this.__wasm={},this.__isLE=new Uint32Array(new Uint8Array([1,0,0,0]).buffer)[0]===1,!this.options.js&&!this.options.wasm)throw Error(`mathlib: at least "js" or "wasm" should be enabled`)}s.prototype.has_wasm=a,s.prototype.use=function(e){return this.__modules[e.name]=e,this.options.wasm&&this.has_wasm()&&e.wasm_fn?this[e.name]=e.wasm_fn:this[e.name]=e.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(Error(`mathlib: only "wasm" was enabled, but it's not supported`));var e=this;return this.__init_promise=Promise.all(Object.keys(e.__modules).map(function(t){var n=e.__modules[t];return!e.options.wasm||!e.has_wasm()||!n.wasm_fn||e.__wasm[t]?null:WebAssembly.compile(e.__base64decode(n.wasm_src)).then(function(n){e.__wasm[t]=n})})).then(function(){return e}),this.__init_promise},s.prototype.__base64decode=i,s.prototype.__reallocate=function(e){if(!this.__memory)return this.__memory=new WebAssembly.Memory({initial:Math.ceil(e/(64*1024))}),this.__memory;var t=this.__memory.buffer.byteLength;return t<e&&this.__memory.grow(Math.ceil((e-t)/(64*1024))),this.__memory},s.prototype.__instance=function(e,t,n){if(t&&this.__reallocate(t),!this.__wasm[e]){var i=this.__modules[e];this.__wasm[e]=new WebAssembly.Module(this.__base64decode(i.wasm_src))}if(!this.__cache[e]){var a={memoryBase:0,memory:this.__memory,tableBase:0,table:new WebAssembly.Table({initial:0,element:`anyfunc`})};this.__cache[e]=new WebAssembly.Instance(this.__wasm[e],{env:r(a,n||{})})}return this.__cache[e]},s.prototype.__align=function(e,t){t||=8;var n=e%t;return e+(n?t-n:0)},t.exports=s},{"./lib/base64decode":21,"./lib/wa_detect":22,"object-assign":23}],21:[function(e,t,n){var r=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;t.exports=function(e){for(var t=e.replace(/[\r\n=]/g,``),n=t.length,i=new Uint8Array(n*3>>2),a=0,o=0,s=0;s<n;s++)s%4==0&&s&&(i[o++]=a>>16&255,i[o++]=a>>8&255,i[o++]=a&255),a=a<<6|r.indexOf(t.charAt(s));var c=n%4*6;return c===0?(i[o++]=a>>16&255,i[o++]=a>>8&255,i[o++]=a&255):c===18?(i[o++]=a>>10&255,i[o++]=a>>2&255):c===12&&(i[o++]=a>>4&255),i}},{}],22:[function(e,t,n){var r;t.exports=function(){if(r!==void 0||(r=!1,typeof WebAssembly>`u`))return r;try{var e=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]),t=new WebAssembly.Module(e);return new WebAssembly.Instance(t,{}).exports.test(4)!==0&&(r=!0),r}catch{}return r}},{}],23:[function(e,t,n){var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;function o(e){if(e==null)throw TypeError(`Object.assign cannot be called with null or undefined`);return Object(e)}function s(){try{if(!Object.assign)return!1;var e=new String(`abc`);if(e[5]=`de`,Object.getOwnPropertyNames(e)[0]===`5`)return!1;for(var t={},n=0;n<10;n++)t[`_`+String.fromCharCode(n)]=n;if(Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(``)!==`0123456789`)return!1;var r={};return`abcdefghijklmnopqrst`.split(``).forEach(function(e){r[e]=e}),Object.keys(Object.assign({},r)).join(``)===`abcdefghijklmnopqrst`}catch{return!1}}t.exports=s()?Object.assign:function(e,t){for(var n,s=o(e),c,l=1;l<arguments.length;l++){for(var u in n=Object(arguments[l]),n)i.call(n,u)&&(s[u]=n[u]);if(r){c=r(n);for(var d=0;d<c.length;d++)a.call(n,c[d])&&(s[c[d]]=n[c[d]])}}return s}},{}],24:[function(e,t,n){var r=arguments[3],i=arguments[4],a=arguments[5],o=JSON.stringify;t.exports=function(e,t){for(var n,s=Object.keys(a),c=0,l=s.length;c<l;c++){var u=s[c],d=a[u].exports;if(d===e||d&&d.default===e){n=u;break}}if(!n){n=Math.floor(16**8*Math.random()).toString(16);for(var f={},c=0,l=s.length;c<l;c++){var u=s[c];f[u]=u}i[n]=[`function(require,module,exports){`+e+`(self); }`,f]}var p=Math.floor(16**8*Math.random()).toString(16),m={};m[n]=n,i[p]=[`function(require,module,exports){var f = require(`+o(n)+`);(f.default ? f.default : f)(self);}`,m];var h={};g(p);function g(e){for(var t in h[e]=!0,i[e][1]){var n=i[e][1][t];h[n]||g(n)}}var _=`(`+r+`)({`+Object.keys(h).map(function(e){return o(e)+`:[`+i[e][0]+`,`+o(i[e][1])+`]`}).join(`,`)+`},{},[`+o(p)+`])`,v=window.URL||window.webkitURL||window.mozURL||window.msURL,y=new Blob([_],{type:`text/javascript`});if(t&&t.bare)return y;var b=v.createObjectURL(y),x=new Worker(b);return x.objectURL=b,x}},{}],"/index.js":[function(e,t,n){function r(e,t){return c(e)||s(e,t)||a(e,t)||i()}function i(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function a(e,t){if(e){if(typeof e==`string`)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(e);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}}function o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function s(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function c(e){if(Array.isArray(e))return e}var l=e(`object-assign`),u=e(`webworkify`),d=e(`./lib/mathlib`),f=e(`./lib/pool`),p=e(`./lib/utils`),m=e(`./lib/worker`),h=e(`./lib/stepper`),g=e(`./lib/tiler`),_={},v=!1;try{typeof navigator<`u`&&navigator.userAgent&&(v=navigator.userAgent.indexOf(`Safari`)>=0)}catch{}var y=1;typeof navigator<`u`&&(y=Math.min(navigator.hardwareConcurrency||1,4));var b={tile:1024,concurrency:y,features:[`js`,`wasm`,`ww`],idle:2e3,createCanvas:function(e,t){var n=document.createElement(`canvas`);return n.width=e,n.height=t,n}},x={quality:3,alpha:!1,unsharpAmount:0,unsharpRadius:0,unsharpThreshold:0},S=!1,C=!1,w=!1,T=!1,E=!1;function D(){return{value:u(m),destroy:function(){if(this.value.terminate(),typeof window<`u`){var e=window.URL||window.webkitURL||window.mozURL||window.msURL;e&&e.revokeObjectURL&&this.value.objectURL&&e.revokeObjectURL(this.value.objectURL)}}}}function O(e){if(!(this instanceof O))return new O(e);this.options=l({},b,e||{});var t=`lk_${this.options.concurrency}`;this.__limit=_[t]||p.limiter(this.options.concurrency),_[t]||(_[t]=this.__limit),this.features={js:!1,wasm:!1,cib:!1,ww:!1},this.__workersPool=null,this.__requested_features=[],this.__mathlib=null}O.prototype.init=function(){var t=this;if(this.__initPromise)return this.__initPromise;if(typeof ImageData<`u`&&typeof Uint8ClampedArray<`u`)try{new ImageData(new Uint8ClampedArray(400),10,10),S=!0}catch{}typeof ImageBitmap<`u`&&(ImageBitmap.prototype&&ImageBitmap.prototype.close?C=!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 d(n),n.indexOf(`ww`)>=0&&typeof window<`u`&&`Worker`in window)try{e(`webworkify`)(function(){}).terminate(),this.features.ww=!0;var r=`wp_${JSON.stringify(this.options)}`;_[r]?this.__workersPool=_[r]:(this.__workersPool=new f(D,this.options.idle),_[r]=this.__workersPool)}catch{}var i=this.__mathlib.init().then(function(e){l(t.features,e.features)}),a=C?p.cib_support(this.options.createCanvas).then(function(e){if(t.features.cib&&n.indexOf(`cib`)<0){t.debug(`createImageBitmap() resize supported, but disabled by config`);return}n.indexOf(`cib`)>=0&&(t.features.cib=e)}):Promise.resolve(!1);w=p.can_use_canvas(this.options.createCanvas);var o=C&&S&&n.indexOf(`ww`)!==-1?p.worker_offscreen_canvas_support():Promise.resolve(!1);o=o.then(function(e){T=e});var s=p.cib_can_use_region().then(function(e){E=e});return this.__initPromise=Promise.all([i,a,o,s]).then(function(){return t}),this.__initPromise},O.prototype.__invokeResize=function(e,t){var n=this;return t.__mathCache=t.__mathCache||{},Promise.resolve().then(function(){return n.features.ww?new Promise(function(r,i){var a=n.__workersPool.acquire();t.cancelToken&&t.cancelToken.catch(function(e){return i(e)}),a.value.onmessage=function(e){a.release(),e.data.err?i(e.data.err):r(e.data)};var o=[];e.src&&o.push(e.src.buffer),e.srcBitmap&&o.push(e.srcBitmap),a.value.postMessage({opts:e,features:n.__requested_features,preload:{wasm_nodule:n.__mathlib.__}},o)}):{data:n.__mathlib.resizeAndUnsharp(e,t.__mathCache)}})},O.prototype.__extractTileData=function(e,t,n,r,i){if(this.features.ww&&T&&(p.isCanvas(t)||E))return this.debug(`Create tile for OffscreenCanvas`),createImageBitmap(r.srcImageBitmap||t,e.x,e.y,e.width,e.height).then(function(e){return i.srcBitmap=e,i});if(p.isCanvas(t))return r.srcCtx||=t.getContext(`2d`,{alpha:!!n.alpha}),this.debug(`Get tile pixel data`),i.src=r.srcCtx.getImageData(e.x,e.y,e.width,e.height).data,i;this.debug(`Draw tile imageBitmap/image to temporary canvas`);var a=this.options.createCanvas(e.width,e.height),o=a.getContext(`2d`,{alpha:!!n.alpha});return o.globalCompositeOperation=`copy`,o.drawImage(r.srcImageBitmap||t,e.x,e.y,e.width,e.height,0,0,e.width,e.height),this.debug(`Get tile pixel data`),i.src=o.getImageData(0,0,e.width,e.height).data,a.width=a.height=0,i},O.prototype.__landTileData=function(e,t,n){var r;if(this.debug(`Convert raw rgba tile result to ImageData`),t.bitmap)return n.toCtx.drawImage(t.bitmap,e.toX,e.toY),null;if(S)r=new ImageData(new Uint8ClampedArray(t.data),e.toWidth,e.toHeight);else if(r=n.toCtx.createImageData(e.toWidth,e.toHeight),r.data.set)r.data.set(t.data);else for(var i=r.data.length-1;i>=0;i--)r.data[i]=t.data[i];return this.debug(`Draw tile`),v?n.toCtx.putImageData(r,e.toX,e.toY,e.toInnerX-e.toX,e.toInnerY-e.toY,e.toInnerWidth+1e-5,e.toInnerHeight+1e-5):n.toCtx.putImageData(r,e.toX,e.toY,e.toInnerX-e.toX,e.toInnerY-e.toY,e.toInnerWidth,e.toInnerHeight),null},O.prototype.__tileAndResize=function(e,t,n){var r=this,i={srcCtx:null,srcImageBitmap:null,isImageBitmapReused:!1,toCtx:null},a=function(t){return r.__limit(function(){if(n.canceled)return n.cancelToken;var a={width:t.width,height:t.height,toWidth:t.toWidth,toHeight:t.toHeight,scaleX:t.scaleX,scaleY:t.scaleY,offsetX:t.offsetX,offsetY:t.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(t,e,n,i,a)}).then(function(e){return r.debug(`Invoke resize math`),r.__invokeResize(e,n)}).then(function(e){return n.canceled?n.cancelToken:(i.srcImageData=null,r.__landTileData(t,e,i))})})};return Promise.resolve().then(function(){if(i.toCtx=t.getContext(`2d`,{alpha:!!n.alpha}),p.isCanvas(e))return null;if(p.isImageBitmap(e))return i.srcImageBitmap=e,i.isImageBitmapReused=!0,null;if(p.isImage(e))return C?(r.debug(`Decode image via createImageBitmap`),createImageBitmap(e).then(function(e){i.srcImageBitmap=e}).catch(function(e){return null})):null;throw Error(`Pica: ".from" should be Image, Canvas or ImageBitmap`)}).then(function(){if(n.canceled)return n.cancelToken;r.debug(`Calculate tiles`);var e=g({width:n.width,height:n.height,srcTileSize:r.options.tile,toWidth:n.toWidth,toHeight:n.toHeight,destTileBorder:n.__destTileBorder}).map(function(e){return a(e)});function o(e){e.srcImageBitmap&&=(e.isImageBitmapReused||e.srcImageBitmap.close(),null)}return r.debug(`Process tiles`),Promise.all(e).then(function(){return r.debug(`Finished!`),o(i),t},function(e){throw o(i),e})})},O.prototype.__processStages=function(e,t,n,i){var a=this;if(i.canceled)return i.cancelToken;var o=r(e.shift(),2),s=o[0],c=o[1],u=e.length===0;i=l({},i,{toWidth:s,toHeight:c,quality:u?i.quality:Math.min(1,i.quality)});var d;return u||(d=this.options.createCanvas(s,c)),this.__tileAndResize(t,u?n:d,i).then(function(){return u?n:(i.width=s,i.height=c,a.__processStages(e,d,n,i))}).then(function(e){return d&&(d.width=d.height=0),e})},O.prototype.__resizeViaCreateImageBitmap=function(e,t,n){var r=this,i=t.getContext(`2d`,{alpha:!!n.alpha});return this.debug(`Resize via createImageBitmap()`),createImageBitmap(e,{resizeWidth:n.toWidth,resizeHeight:n.toHeight,resizeQuality:p.cib_quality_name(n.quality)}).then(function(e){if(n.canceled)return n.cancelToken;if(!n.unsharpAmount)return i.drawImage(e,0,0),e.close(),i=null,r.debug(`Finished!`),t;r.debug(`Unsharp result`);var a=r.options.createCanvas(n.toWidth,n.toHeight),o=a.getContext(`2d`,{alpha:!!n.alpha});o.drawImage(e,0,0),e.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!`),t})},O.prototype.resize=function(e,t,n){var r=this;this.debug(`Start resize...`);var i=l({},x);return isNaN(n)?n&&(i=l(i,n)):i=l(i,{quality:n}),i.toWidth=t.width,i.toHeight=t.height,i.width=e.naturalWidth||e.width,i.height=e.naturalHeight||e.height,t.width===0||t.height===0?Promise.reject(Error(`Invalid output size: ${t.width}x${t.height}`)):(i.unsharpRadius>2&&(i.unsharpRadius=2),i.canceled=!1,i.cancelToken&&=i.cancelToken.then(function(e){throw i.canceled=!0,e},function(e){throw i.canceled=!0,e}),i.__destTileBorder=Math.ceil(Math.max(3,2.5*i.unsharpRadius|0)),this.init().then(function(){if(i.canceled)return i.cancelToken;if(r.features.cib)return r.__resizeViaCreateImageBitmap(e,t,i);if(!w){var n=Error(`Pica: cannot use getImageData on canvas, make sure fingerprinting protection isn't enabled`);throw n.code=`ERR_GET_IMAGE_DATA`,n}var a=h(i.width,i.height,i.toWidth,i.toHeight,r.options.tile,i.__destTileBorder);return r.__processStages(a,e,t,i)}))},O.prototype.resizeBuffer=function(e){var t=this,n=l({},x,e);return this.init().then(function(){return t.__mathlib.resizeAndUnsharp(n)})},O.prototype.toBlob=function(e,t,n){return t||=`image/png`,new Promise(function(r){if(e.toBlob){e.toBlob(function(e){return r(e)},t,n);return}if(e.convertToBlob){r(e.convertToBlob({type:t,quality:n}));return}for(var i=atob(e.toDataURL(t,n).split(`,`)[1]),a=i.length,o=new Uint8Array(a),s=0;s<a;s++)o[s]=i.charCodeAt(s);r(new Blob([o],{type:t}))})},O.prototype.debug=function(){},t.exports=O},{"./lib/mathlib":1,"./lib/pool":13,"./lib/stepper":14,"./lib/tiler":15,"./lib/utils":16,"./lib/worker":17,"object-assign":23,webworkify:24}]},{},[])(`/index.js`)})}),s=i(function(e){function t(e,t){var n=Error(e);return n.code=t,n}function n(e){for(var t=e.toString(16).toUpperCase(),n=2-t.length;n>0;n--)t=`0`+t;return`0x`+t}function r(e){try{return unescape(encodeURIComponent(e))}catch{return e}}function i(e){try{return decodeURIComponent(escape(e))}catch{return e}}function a(e){return Object.prototype.toString.call(e)===`[object Uint8Array]`}function o(e,n,r){this.input=e.subarray(n,r),this.start=n;var i=String.fromCharCode.apply(null,this.input.subarray(0,4));if(i!==`II*\0`&&i!==`MM\0*`)throw t(`invalid TIFF signature`,`EBADDATA`);this.big_endian=i[0]===`M`}o.prototype.each=function(e){this.aborted=!1;var t=this.read_uint32(4);for(this.ifds_to_read=[{id:0,offset:t}];this.ifds_to_read.length>0&&!this.aborted;){var n=this.ifds_to_read.shift();n.offset&&this.scan_ifd(n.id,n.offset,e)}},o.prototype.filter=function(e){var n={};n.ifd0={id:0,entries:[]},this.each(function(t){e(t)===!1&&!t.is_subifd_link||t.is_subifd_link&&t.count!==1&&t.format!==4||(n[`ifd`+t.ifd]||(n[`ifd`+t.ifd]={id:t.ifd,entries:[]}),n[`ifd`+t.ifd].entries.push(t))}),delete n.ifd1;var r=8;Object.keys(n).forEach(function(e){r+=2,n[e].entries.forEach(function(e){r+=12+(e.data_length>4?Math.ceil(e.data_length/2)*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(e){n[e].written_offset=i;var t=i,r=t+2+n[e].entries.length*12+4;i=r,a.write_uint16(t,n[e].entries.length),n[e].entries.sort(function(e,t){return e.tag-t.tag}).forEach(function(e,r){var o=t+2+r*12;a.write_uint16(o,e.tag),a.write_uint16(o+2,e.format),a.write_uint32(o+4,e.count),e.is_subifd_link?n[`ifd`+e.tag]&&(n[`ifd`+e.tag].link_offset=o+8):e.data_length<=4?a.output.set(a.input.subarray(e.data_offset-a.start,e.data_offset-a.start+4),o+8):(a.write_uint32(o+8,i),a.output.set(a.input.subarray(e.data_offset-a.start,e.data_offset-a.start+e.data_length),i),i+=Math.ceil(e.data_length/2)*2)});var o=n[`ifd`+(n[e].id+1)];o&&(o.link_offset=r-4)}),Object.keys(n).forEach(function(e){n[e].written_offset&&n[e].link_offset&&a.write_uint32(n[e].link_offset,n[e].written_offset)}),this.output.length!==i)throw t(`internal error: incorrect buffer size allocated`);return this.output},o.prototype.read_uint16=function(e){var n=this.input;if(e+2>n.length)throw t(`unexpected EOF`,`EBADDATA`);return this.big_endian?n[e]*256+n[e+1]:n[e]+n[e+1]*256},o.prototype.read_uint32=function(e){var n=this.input;if(e+4>n.length)throw t(`unexpected EOF`,`EBADDATA`);return this.big_endian?n[e]*16777216+n[e+1]*65536+n[e+2]*256+n[e+3]:n[e]+n[e+1]*256+n[e+2]*65536+n[e+3]*16777216},o.prototype.write_uint16=function(e,t){var n=this.output;this.big_endian?(n[e]=t>>>8&255,n[e+1]=t&255):(n[e]=t&255,n[e+1]=t>>>8&255)},o.prototype.write_uint32=function(e,t){var n=this.output;this.big_endian?(n[e]=t>>>24&255,n[e+1]=t>>>16&255,n[e+2]=t>>>8&255,n[e+3]=t&255):(n[e]=t&255,n[e+1]=t>>>8&255,n[e+2]=t>>>16&255,n[e+3]=t>>>24&255)},o.prototype.is_subifd_link=function(e,t){return e===0&&t===34665||e===0&&t===34853||e===34665&&t===40965},o.prototype.exif_format_length=function(e){switch(e){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}},o.prototype.exif_format_read=function(e,t){var n;switch(e){case 1:case 2:return n=this.input[t],n;case 6:return n=this.input[t],n|(n&128)*33554430;case 3:return n=this.read_uint16(t),n;case 8:return n=this.read_uint16(t),n|(n&32768)*131070;case 4:return n=this.read_uint32(t),n;case 9:return n=this.read_uint32(t),n|0;case 5:case 10:case 11:case 12:return null;case 7:return null;default:return null}},o.prototype.scan_ifd=function(e,n,r){var a=this.read_uint16(n);n+=2;for(var o=0;o<a;o++){var s=this.read_uint16(n),c=this.read_uint16(n+2),l=this.read_uint32(n+4),u=this.exif_format_length(c),d=l*u,f=d<=4?n+8:this.read_uint32(n+8),p=!1;if(f+d>this.input.length)throw t(`unexpected EOF`,`EBADDATA`);for(var m=[],h=f,g=0;g<l;g++,h+=u){var _=this.exif_format_read(c,h);if(_===null){m=null;break}m.push(_)}if(Array.isArray(m)&&c===2){try{m=i(String.fromCharCode.apply(null,m))}catch{m=null}m&&m[m.length-1]===`\0`&&(m=m.slice(0,-1))}if(this.is_subifd_link(e,s)&&Array.isArray(m)&&Number.isInteger(m[0])&&m[0]>0&&(this.ifds_to_read.push({id:s,offset:m[0]}),p=!0),r({is_big_endian:this.big_endian,ifd:e,tag:s,format:c,count:l,entry_offset:n+this.start,data_length:d,data_offset:f+this.start,value:m,is_subifd_link:p})===!1){this.aborted=!0;return}n+=12}e===0&&this.ifds_to_read.push({id:1,offset:this.read_uint32(n)})},e.exports.is_jpeg=function(e){return e.length>=4&&e[0]===255&&e[1]===216&&e[2]===255},e.exports.jpeg_segments_each=function(r,i){if(!a(r))throw t(`Invalid argument (jpeg_bin), Uint8Array expected`,`EINVAL`);if(typeof i!=`function`)throw t(`Invalid argument (on_segment), Function expected`,`EINVAL`);if(!e.exports.is_jpeg(r))throw t(`Unknown file format`,`ENOTJPEG`);for(var o=0,s=r.length,c=!1;;){var l,u;if(o+1>=s)throw t(`Unexpected EOF`,`EBADDATA`);var d=r[o],f=r[o+1];if(d===255&&f===255)l=255,u=1;else if(d===255&&f!==0){if(l=f,u=2,!(208<=l&&l<=217||l===1)){if(o+3>=s)throw t(`Unexpected EOF`,`EBADDATA`);if(u+=r[o+2]*256+r[o+3],u<2)throw t(`Invalid segment length`,`EBADDATA`);if(o+u-1>=s)throw t(`Unexpected EOF`,`EBADDATA`)}c&&(l>=208&&l<=215||(c=!1)),l===218&&(c=!0)}else if(c)for(var p=o+1;;p++){if(p>=s)throw t(`Unexpected EOF`,`EBADDATA`);if(r[p]===255){if(p+1>=s)throw t(`Unexpected EOF`,`EBADDATA`);if(r[p+1]!==0){l=0,u=p-o;break}}}else throw t(`Unexpected byte at segment start: `+n(d)+` (offset `+n(o)+`)`,`EBADDATA`);if(i({code:l,offset:o,length:u})===!1||l===217)break;o+=u}},e.exports.jpeg_segments_filter=function(n,r){if(!a(n))throw t(`Invalid argument (jpeg_bin), Uint8Array expected`,`EINVAL`);if(typeof r!=`function`)throw t(`Invalid argument (on_segment), Function expected`,`EINVAL`);var i=[],o=0;e.exports.jpeg_segments_each(n,function(e){var t=r(e);if(a(t))i.push({data:t}),o+=t.length;else if(Array.isArray(t))t.filter(a).forEach(function(e){i.push({data:e}),o+=e.length});else if(t!==!1){var n={start:e.offset,end:e.offset+e.length};i.length>0&&i[i.length-1].end===n.start?i[i.length-1].end=n.end:i.push(n),o+=e.length}});var s=new Uint8Array(o),c=0;return i.forEach(function(e){var t=e.data||n.subarray(e.start,e.end);s.set(t,c),c+=t.length}),s},e.exports.jpeg_exif_tags_each=function(n,r){if(!a(n))throw t(`Invalid argument (jpeg_bin), Uint8Array expected`,`EINVAL`);if(typeof r!=`function`)throw t(`Invalid argument (on_exif_entry), Function expected`,`EINVAL`);e.exports.jpeg_segments_each(n,function(e){if(e.code===218)return!1;if(e.code===225&&e.length>=10&&n[e.offset+4]===69&&n[e.offset+5]===120&&n[e.offset+6]===105&&n[e.offset+7]===102&&n[e.offset+8]===0&&n[e.offset+9]===0)return new o(n,e.offset+10,e.offset+e.length).each(r),!1})},e.exports.jpeg_exif_tags_filter=function(n,r){if(!a(n))throw t(`Invalid argument (jpeg_bin), Uint8Array expected`,`EINVAL`);if(typeof r!=`function`)throw t(`Invalid argument (on_exif_entry), Function expected`,`EINVAL`);var i=!1;return e.exports.jpeg_segments_filter(n,function(e){if(!i&&(e.code===218&&(i=!0),e.code===225&&e.length>=10&&n[e.offset+4]===69&&n[e.offset+5]===120&&n[e.offset+6]===105&&n[e.offset+7]===102&&n[e.offset+8]===0&&n[e.offset+9]===0)){var t=new o(n,e.offset+10,e.offset+e.length).filter(r);if(!t)return!1;var a=new Uint8Array(10);return a.set(n.slice(e.offset,e.offset+10)),a[2]=t.length+8>>>8&255,a[3]=t.length+8&255,i=!0,[a,t]}})},e.exports.jpeg_add_comment=function(t,n){var i=!1,a=0;return e.exports.jpeg_segments_filter(t,function(e){if(a++,!(a===1&&e.code===216)&&!(a===2&&e.code===224)&&!i){n=r(n);var o=new Uint8Array(5+n.length),s=0;return o[s++]=255,o[s++]=254,o[s++]=n.length+3>>>8&255,o[s++]=n.length+3&255,n.split(``).forEach(function(e){o[s++]=e.charCodeAt(0)&255}),o[s++]=0,i=!0,[o,t.subarray(e.offset,e.offset+e.length)]}})}});function c(e){return this._getUint8Array(e.blob).then(function(t){if(e.is_jpeg=s.is_jpeg(t),!e.is_jpeg)return Promise.resolve(e);e.orig_blob=e.blob;try{var n,r;if(s.jpeg_exif_tags_each(t,function(t){if(t.ifd===0&&t.tag===274&&Array.isArray(t.value))return e.orientation=t.value[0]||1,n=t.is_big_endian,r=t.data_offset,!1}),r){var i=n?new Uint8Array([0,1]):new Uint8Array([1,0]);e.blob=new Blob([t.slice(0,r),i,t.slice(r+2)],{type:`image/jpeg`})}}catch{}return e})}function l(e){if(!e.is_jpeg)return Promise.resolve(e);var t=e.orientation-1;if(!t)return Promise.resolve(e);var n=t&4?this.pica.options.createCanvas(e.out_canvas.height,e.out_canvas.width):this.pica.options.createCanvas(e.out_canvas.width,e.out_canvas.height),r=n.getContext(`2d`);return r.save(),t&1&&r.transform(-1,0,0,1,n.width,0),t&2&&r.transform(-1,0,0,-1,n.width,n.height),t&4&&r.transform(0,1,1,0,0,0),r.drawImage(e.out_canvas,0,0),r.restore(),e.out_canvas.width=e.out_canvas.height=0,e.out_canvas=n,Promise.resolve(e)}function u(e){return e.is_jpeg?Promise.all([this._getUint8Array(e.blob),this._getUint8Array(e.out_blob)]).then(function(t){var n=t[0],r=t[1];if(!s.is_jpeg(n))return Promise.resolve(e);var i=[];return s.jpeg_segments_each(n,function(e){if(e.code===218)return!1;i.push(e)}),i=i.filter(function(e){return e.code===226?!1:e.code>=224&&e.code<240||e.code===254}).map(function(e){return n.slice(e.offset,e.offset+e.length)}),e.out_blob=new Blob([r.slice(0,2)].concat(i,[r.slice(20)]),{type:`image/jpeg`}),e}):Promise.resolve(e)}function d(e){e.before(`_blob_to_image`,c),e.after(`_transform`,l),e.after(`_create_blob`,u)}var f={jpeg_patch_exif:c,jpeg_rotate_canvas:l,jpeg_attach_orig_segments:u,assign:d};function p(e){if(!(this instanceof p))return new p(e);e||={},this.pica=e.pica||o({}),this.initialized=!1,this.utils=r}p.prototype.use=function(e){var t=[this].concat(Array.prototype.slice.call(arguments,1));return e.apply(e,t),this},p.prototype.init=function(){this.use(f.assign)},p.prototype.toBlob=function(e,t){var n={blob:e,opts:r.assign({max:1/0},t)};return this.initialized||=(this.init(),!0),Promise.resolve(n).then(this._blob_to_image).then(this._calculate_size).then(this._transform).then(this._cleanup).then(this._create_blob).then(function(e){return e.out_canvas.width=e.out_canvas.height=0,e.out_blob})},p.prototype.toCanvas=function(e,t){var n={blob:e,opts:r.assign({max:1/0},t)};return this.initialized||=(this.init(),!0),Promise.resolve(n).then(this._blob_to_image).then(this._calculate_size).then(this._transform).then(this._cleanup).then(function(e){return e.out_canvas})},p.prototype.before=function(e,t){if(!this[e])throw Error(`Method "`+e+`" does not exist`);if(typeof t!=`function`)throw Error(`Invalid argument "fn", function expected`);var n=this[e],r=this;return this[e]=function(e){return t.call(r,e).then(function(e){return n.call(r,e)})},this},p.prototype.after=function(e,t){if(!this[e])throw Error(`Method "`+e+`" does not exist`);if(typeof t!=`function`)throw Error(`Invalid argument "fn", function expected`);var n=this[e],r=this;return this[e]=function(e){return n.call(r,e).then(function(e){return t.call(r,e)})},this},p.prototype._blob_to_image=function(e){var t=window.URL||window.webkitURL||window.mozURL||window.msURL;return e.image=document.createElement(`img`),e.image_url=t.createObjectURL(e.blob),e.image.src=e.image_url,new Promise(function(t,n){e.image.onerror=function(){n(Error(`ImageBlobReduce: failed to create Image() from blob`))},e.image.onload=function(){t(e)}})},p.prototype._calculate_size=function(e){var t=e.opts.max/Math.max(e.image.width,e.image.height);return t>1&&(t=1),e.transform_width=Math.max(Math.round(e.image.width*t),1),e.transform_height=Math.max(Math.round(e.image.height*t),1),e.scale_factor=t,Promise.resolve(e)},p.prototype._transform=function(e){e.out_canvas=this.pica.options.createCanvas(e.transform_width,e.transform_height),e.transform_width=null,e.transform_height=null;var t={alpha:e.blob.type===`image/png`};return this.utils.assign(t,this.utils.pick_pica_resize_options(e.opts)),this.pica.resize(e.image,e.out_canvas,t).then(function(){return e})},p.prototype._cleanup=function(e){e.image.src=``,e.image=null;var t=window.URL||window.webkitURL||window.mozURL||window.msURL;return t.revokeObjectURL&&t.revokeObjectURL(e.image_url),e.image_url=null,Promise.resolve(e)},p.prototype._create_blob=function(e){return this.pica.toBlob(e.out_canvas,e.blob.type).then(function(t){return e.out_blob=t,e})},p.prototype._getUint8Array=function(e){return e.arrayBuffer?e.arrayBuffer().then(function(e){return new Uint8Array(e)}):new Promise(function(t,n){var r=new FileReader;r.readAsArrayBuffer(e),r.onload=function(){t(new Uint8Array(r.result))},r.onerror=function(){n(Error(`ImageBlobReduce: failed to load data from input blob`)),r.abort()},r.onabort=function(){n(Error(`ImageBlobReduce: failed to load data from input blob (aborted)`))}})},p.pica=o;var m=p;export{m as default}; |