/*! image-blob-reduce 3.0.1 https://github.com/nodeca/image-blob-reduce @license MIT */
var K = function(I) {
  for (var d, h = 1; h < arguments.length; h++) {
    d = Object(arguments[h]);
    for (var x in d)
      Object.prototype.hasOwnProperty.call(d, x) && (I[x] = d[x]);
  }
  return I;
};
function N(A, I) {
  var d = {};
  return I.forEach(function(h) {
    Object.prototype.hasOwnProperty.call(A, h) && (d[h] = A[h]);
  }), d;
}
function V(A) {
  return N(A, [
    "alpha",
    "unsharpAmount",
    "unsharpRadius",
    "unsharpThreshold",
    "cancelToken"
  ]);
}
var $ = N, J = V, W = {
  assign: K,
  pick: $,
  pick_pica_resize_options: J
};
function q(A) {
  var I = { exports: {} };
  return A(I, I.exports), I.exports;
}
function H(A) {
  throw new Error('Could not dynamically require "' + A + '". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.');
}
/*!

pica
https://github.com/nodeca/pica

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