var A = {}, h = {}, m;
function C() {
  if (m) return h;
  m = 1, Object.defineProperty(h, "__esModule", {
    value: !0
  }), h.loop = h.conditional = h.parse = void 0;
  var b = function d(p, u) {
    var i = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, s = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : i;
    if (Array.isArray(u))
      u.forEach(function(x) {
        return d(p, x, i, s);
      });
    else if (typeof u == "function")
      u(p, i, s, d);
    else {
      var c = Object.keys(u)[0];
      Array.isArray(u[c]) ? (s[c] = {}, d(p, u[c], i, s[c])) : s[c] = u[c](p, i, s, d);
    }
    return i;
  };
  h.parse = b;
  var v = function(p, u) {
    return function(i, s, c, x) {
      u(i, s, c) && x(i, p, s, c);
    };
  };
  h.conditional = v;
  var r = function(p, u) {
    return function(i, s, c, x) {
      for (var f = [], t = i.pos; u(i, s, c); ) {
        var e = {};
        if (x(i, p, s, e), i.pos === t)
          break;
        t = i.pos, f.push(e);
      }
      return f;
    };
  };
  return h.loop = r, h;
}
var a = {}, _;
function j() {
  if (_) return a;
  _ = 1, Object.defineProperty(a, "__esModule", {
    value: !0
  }), a.readBits = a.readArray = a.readUnsigned = a.readString = a.peekBytes = a.readBytes = a.peekByte = a.readByte = a.buildStream = void 0;
  var b = function(t) {
    return {
      data: t,
      pos: 0
    };
  };
  a.buildStream = b;
  var v = function() {
    return function(t) {
      return t.data[t.pos++];
    };
  };
  a.readByte = v;
  var r = function() {
    var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
    return function(e) {
      return e.data[e.pos + t];
    };
  };
  a.peekByte = r;
  var d = function(t) {
    return function(e) {
      return e.data.subarray(e.pos, e.pos += t);
    };
  };
  a.readBytes = d;
  var p = function(t) {
    return function(e) {
      return e.data.subarray(e.pos, e.pos + t);
    };
  };
  a.peekBytes = p;
  var u = function(t) {
    return function(e) {
      return Array.from(d(t)(e)).map(function(n) {
        return String.fromCharCode(n);
      }).join("");
    };
  };
  a.readString = u;
  var i = function(t) {
    return function(e) {
      var n = d(2)(e);
      return t ? (n[1] << 8) + n[0] : (n[0] << 8) + n[1];
    };
  };
  a.readUnsigned = i;
  var s = function(t, e) {
    return function(n, o, l) {
      for (var g = typeof e == "function" ? e(n, o, l) : e, y = d(t), B = new Array(g), S = 0; S < g; S++)
        B[S] = y(n);
      return B;
    };
  };
  a.readArray = s;
  var c = function(t, e, n) {
    for (var o = 0, l = 0; l < n; l++)
      o += t[e + l] && Math.pow(2, n - l - 1);
    return o;
  }, x = function(t) {
    return function(e) {
      for (var n = v()(e), o = new Array(8), l = 0; l < 8; l++)
        o[7 - l] = !!(n & 1 << l);
      return Object.keys(t).reduce(function(g, y) {
        var B = t[y];
        return B.length ? g[y] = c(o, B.index, B.length) : g[y] = o[B.index], g;
      }, {});
    };
  };
  return a.readBits = x, a;
}
var w;
function q() {
  return w || (w = 1, (function(b) {
    Object.defineProperty(b, "__esModule", {
      value: !0
    }), b.default = void 0;
    var v = C(), r = j(), d = {
      blocks: function(e) {
        for (var n = 0, o = [], l = e.data.length, g = 0, y = (0, r.readByte)()(e); y !== n && y; y = (0, r.readByte)()(e)) {
          if (e.pos + y >= l) {
            var B = l - e.pos;
            o.push((0, r.readBytes)(B)(e)), g += B;
            break;
          }
          o.push((0, r.readBytes)(y)(e)), g += y;
        }
        for (var S = new Uint8Array(g), U = 0, k = 0; k < o.length; k++)
          S.set(o[k], U), U += o[k].length;
        return S;
      }
    }, p = (0, v.conditional)({
      gce: [{
        codes: (0, r.readBytes)(2)
      }, {
        byteSize: (0, r.readByte)()
      }, {
        extras: (0, r.readBits)({
          future: {
            index: 0,
            length: 3
          },
          disposal: {
            index: 3,
            length: 3
          },
          userInput: {
            index: 6
          },
          transparentColorGiven: {
            index: 7
          }
        })
      }, {
        delay: (0, r.readUnsigned)(!0)
      }, {
        transparentColorIndex: (0, r.readByte)()
      }, {
        terminator: (0, r.readByte)()
      }]
    }, function(t) {
      var e = (0, r.peekBytes)(2)(t);
      return e[0] === 33 && e[1] === 249;
    }), u = (0, v.conditional)({
      image: [{
        code: (0, r.readByte)()
      }, {
        descriptor: [{
          left: (0, r.readUnsigned)(!0)
        }, {
          top: (0, r.readUnsigned)(!0)
        }, {
          width: (0, r.readUnsigned)(!0)
        }, {
          height: (0, r.readUnsigned)(!0)
        }, {
          lct: (0, r.readBits)({
            exists: {
              index: 0
            },
            interlaced: {
              index: 1
            },
            sort: {
              index: 2
            },
            future: {
              index: 3,
              length: 2
            },
            size: {
              index: 5,
              length: 3
            }
          })
        }]
      }, (0, v.conditional)({
        lct: (0, r.readArray)(3, function(t, e, n) {
          return Math.pow(2, n.descriptor.lct.size + 1);
        })
      }, function(t, e, n) {
        return n.descriptor.lct.exists;
      }), {
        data: [{
          minCodeSize: (0, r.readByte)()
        }, d]
      }]
    }, function(t) {
      return (0, r.peekByte)()(t) === 44;
    }), i = (0, v.conditional)({
      text: [{
        codes: (0, r.readBytes)(2)
      }, {
        blockSize: (0, r.readByte)()
      }, {
        preData: function(e, n, o) {
          return (0, r.readBytes)(o.text.blockSize)(e);
        }
      }, d]
    }, function(t) {
      var e = (0, r.peekBytes)(2)(t);
      return e[0] === 33 && e[1] === 1;
    }), s = (0, v.conditional)({
      application: [{
        codes: (0, r.readBytes)(2)
      }, {
        blockSize: (0, r.readByte)()
      }, {
        id: function(e, n, o) {
          return (0, r.readString)(o.blockSize)(e);
        }
      }, d]
    }, function(t) {
      var e = (0, r.peekBytes)(2)(t);
      return e[0] === 33 && e[1] === 255;
    }), c = (0, v.conditional)({
      comment: [{
        codes: (0, r.readBytes)(2)
      }, d]
    }, function(t) {
      var e = (0, r.peekBytes)(2)(t);
      return e[0] === 33 && e[1] === 254;
    }), x = [
      {
        header: [{
          signature: (0, r.readString)(3)
        }, {
          version: (0, r.readString)(3)
        }]
      },
      {
        lsd: [{
          width: (0, r.readUnsigned)(!0)
        }, {
          height: (0, r.readUnsigned)(!0)
        }, {
          gct: (0, r.readBits)({
            exists: {
              index: 0
            },
            resolution: {
              index: 1,
              length: 3
            },
            sort: {
              index: 4
            },
            size: {
              index: 5,
              length: 3
            }
          })
        }, {
          backgroundColorIndex: (0, r.readByte)()
        }, {
          pixelAspectRatio: (0, r.readByte)()
        }]
      },
      (0, v.conditional)({
        gct: (0, r.readArray)(3, function(t, e) {
          return Math.pow(2, e.lsd.gct.size + 1);
        })
      }, function(t, e) {
        return e.lsd.gct.exists;
      }),
      // content frames
      {
        frames: (0, v.loop)([p, s, c, u, i], function(t) {
          var e = (0, r.peekByte)()(t);
          return e === 33 || e === 44;
        })
      }
    ], f = x;
    b.default = f;
  })(A)), A;
}
export {
  C as a,
  j as b,
  q as r
};
