var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  return value;
};
var __accessCheck = (obj, member, msg) => {
  if (!member.has(obj))
    throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
  __accessCheck(obj, member, "read from private field");
  return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
  if (member.has(obj))
    throw TypeError("Cannot add the same private member more than once");
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
  __accessCheck(obj, member, "write to private field");
  setter ? setter.call(obj, value) : member.set(obj, value);
  return value;
};
var __privateWrapper = (obj, member, setter, getter) => ({
  set _(value) {
    __privateSet(obj, member, value, setter);
  },
  get _() {
    return __privateGet(obj, member, getter);
  }
});
var __privateMethod = (obj, member, method) => {
  __accessCheck(obj, member, "access private method");
  return method;
};
let dd, zh, me, Cg, Eg, gg, Ag, Gr, Rf, dn, Rd, Tt, Xl, mg, Ss, Zn, ph, Fs, fn, gs, id, od, jd, Ps, Jf, Ts, Xf, yg, Qr, ye, Ph, vg, wg;
let __tla = (async () => {
  var _e2, _t2, _r2, _n2, _s2, _o2, o_get, _a2, a_get, _i2, i_fn, _c2, c_fn, _a3, _e3, _t3, _r3, _n3, _s3, _o3, _a4, a_fn, _i3, i_fn2, _e4, _t4, _r4, _n4, _s4, _o4, _a5, _e5, _t5, _r5, _n5, _s5, _o5, o_fn, _a6, a_fn2, _i4, i_fn3, _c3, c_fn2, _e6, _t6, _r6, _n6, _s6, _o6, _a7, _i5, _c4, _g2, g_fn, _b, b_fn, _p, p_fn, _u2, u_fn, _w, w_fn, _y, y_fn, _f2, f_fn, _d2, d_fn, _l2, l_fn, __2, __fn, _h2, h_fn, _e7, _t7, _r7, _n7, n_fn, _s7, s_fn, _o7, o_fn2, _e8, _t8, _r8, _n8, _s8, _o8, o_fn3, _a8, _i6, i_fn4, _c5, c_fn3, _b2, _e9, _c6;
  let h;
  const oe = new Array(128).fill(void 0);
  oe.push(void 0, null, true, false);
  function V(n) {
    return oe[n];
  }
  let Vt = 0, Ze = null;
  function rn() {
    return (Ze === null || Ze.byteLength === 0) && (Ze = new Uint8Array(h.memory.buffer)), Ze;
  }
  const Tn = typeof TextEncoder < "u" ? new TextEncoder("utf-8") : {
    encode: () => {
      throw Error("TextEncoder not available");
    }
  }, i_ = typeof Tn.encodeInto == "function" ? function(n, t) {
    return Tn.encodeInto(n, t);
  } : function(n, t) {
    const e = Tn.encode(n);
    return t.set(e), {
      read: n.length,
      written: e.length
    };
  };
  function Zt(n, t, e) {
    if (e === void 0) {
      const a = Tn.encode(n), c = t(a.length, 1) >>> 0;
      return rn().subarray(c, c + a.length).set(a), Vt = a.length, c;
    }
    let r = n.length, s = t(r, 1) >>> 0;
    const o = rn();
    let i = 0;
    for (; i < r; i++) {
      const a = n.charCodeAt(i);
      if (a > 127)
        break;
      o[s + i] = a;
    }
    if (i !== r) {
      i !== 0 && (n = n.slice(i)), s = e(s, r, r = i + n.length * 3, 1) >>> 0;
      const a = rn().subarray(s + i, s + r), c = i_(n, a);
      i += c.written, s = e(s, r, i, 1) >>> 0;
    }
    return Vt = i, s;
  }
  let ve = null;
  function y() {
    return (ve === null || ve.buffer.detached === true || ve.buffer.detached === void 0 && ve.buffer !== h.memory.buffer) && (ve = new DataView(h.memory.buffer)), ve;
  }
  let sn = oe.length;
  function A(n) {
    sn === oe.length && oe.push(oe.length + 1);
    const t = sn;
    return sn = oe[t], oe[t] = n, t;
  }
  function re(n, t) {
    try {
      return n.apply(this, t);
    } catch (e) {
      h.__wbindgen_exn_store(A(e));
    }
  }
  const jo = typeof TextDecoder < "u" ? new TextDecoder("utf-8", {
    ignoreBOM: true,
    fatal: true
  }) : {
    decode: () => {
      throw Error("TextDecoder not available");
    }
  };
  typeof TextDecoder < "u" && jo.decode();
  function Pt(n, t) {
    return n = n >>> 0, jo.decode(rn().subarray(n, n + t));
  }
  function a_(n, t) {
    return n = n >>> 0, rn().subarray(n / 1, n / 1 + t);
  }
  function c_(n) {
    n < 132 || (oe[n] = sn, sn = n);
  }
  function T(n) {
    const t = V(n);
    return c_(n), t;
  }
  function yr(n) {
    const t = typeof n;
    if (t == "number" || t == "boolean" || n == null)
      return `${n}`;
    if (t == "string")
      return `"${n}"`;
    if (t == "symbol") {
      const s = n.description;
      return s == null ? "Symbol" : `Symbol(${s})`;
    }
    if (t == "function") {
      const s = n.name;
      return typeof s == "string" && s.length > 0 ? `Function(${s})` : "Function";
    }
    if (Array.isArray(n)) {
      const s = n.length;
      let o = "[";
      s > 0 && (o += yr(n[0]));
      for (let i = 1; i < s; i++)
        o += ", " + yr(n[i]);
      return o += "]", o;
    }
    const e = /\[object ([^\]]+)\]/.exec(toString.call(n));
    let r;
    if (e && e.length > 1)
      r = e[1];
    else
      return toString.call(n);
    if (r == "Object")
      try {
        return "Object(" + JSON.stringify(n) + ")";
      } catch {
        return "Object";
      }
    return n instanceof Error ? `${n.name}: ${n.message}
${n.stack}` : r;
  }
  function _t(n) {
    return n == null;
  }
  function ke(n, t) {
    if (!(n instanceof t))
      throw new Error(`expected instance of ${t.name}`);
  }
  function __(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.create(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return Wr.__wrap(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function u_(n, t) {
    try {
      const o = h.__wbindgen_add_to_stack_pointer(-16);
      h.load(o, A(n), A(t));
      var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
      if (s)
        throw T(r);
      return Wr.__wrap(e);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function f_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.encodeChange(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return T(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function d_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.decodeChange(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return T(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function l_() {
    const n = h.initSyncState();
    return _e.__wrap(n);
  }
  function h_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.importSyncState(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return _e.__wrap(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function g_(n) {
    ke(n, _e);
    const t = h.exportSyncState(n.__wbg_ptr);
    return T(t);
  }
  function b_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.encodeSyncMessage(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return T(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function p_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.decodeSyncMessage(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return T(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function w_(n) {
    ke(n, _e);
    const t = h.encodeSyncState(n.__wbg_ptr);
    return T(t);
  }
  function y_(n) {
    try {
      const s = h.__wbindgen_add_to_stack_pointer(-16);
      h.decodeSyncState(s, A(n));
      var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
      if (r)
        throw T(e);
      return _e.__wrap(t);
    } finally {
      h.__wbindgen_add_to_stack_pointer(16);
    }
  }
  const m_ = Object.freeze({
    Array: 0,
    0: "Array",
    String: 1,
    1: "String"
  }), Gs = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((n) => h.__wbg_automerge_free(n >>> 0, 1));
  let Wr = class Se {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(Se.prototype);
      return e.__wbg_ptr = t, Gs.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, Gs.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      h.__wbg_automerge_free(t, 0);
    }
    static new(t, e) {
      try {
        const c = h.__wbindgen_add_to_stack_pointer(-16);
        var r = _t(t) ? 0 : Zt(t, h.__wbindgen_malloc, h.__wbindgen_realloc), s = Vt;
        h.automerge_new(c, r, s, e);
        var o = y().getInt32(c + 4 * 0, true), i = y().getInt32(c + 4 * 1, true), a = y().getInt32(c + 4 * 2, true);
        if (a)
          throw T(i);
        return Se.__wrap(o);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone(t) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        var e = _t(t) ? 0 : Zt(t, h.__wbindgen_malloc, h.__wbindgen_realloc), r = Vt;
        h.automerge_clone(a, this.__wbg_ptr, e, r);
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return Se.__wrap(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    fork(t, e) {
      try {
        const c = h.__wbindgen_add_to_stack_pointer(-16);
        var r = _t(t) ? 0 : Zt(t, h.__wbindgen_malloc, h.__wbindgen_realloc), s = Vt;
        h.automerge_fork(c, this.__wbg_ptr, r, s, A(e));
        var o = y().getInt32(c + 4 * 0, true), i = y().getInt32(c + 4 * 1, true), a = y().getInt32(c + 4 * 2, true);
        if (a)
          throw T(i);
        return Se.__wrap(o);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pendingOps() {
      const t = h.automerge_pendingOps(this.__wbg_ptr);
      return T(t);
    }
    commit(t, e) {
      var r = _t(t) ? 0 : Zt(t, h.__wbindgen_malloc, h.__wbindgen_realloc), s = Vt;
      const o = h.automerge_commit(this.__wbg_ptr, r, s, !_t(e), _t(e) ? 0 : e);
      return T(o);
    }
    merge(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        ke(t, Se), h.automerge_merge(o, this.__wbg_ptr, t.__wbg_ptr);
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    rollback() {
      return h.automerge_rollback(this.__wbg_ptr);
    }
    keys(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_keys(i, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    text(t, e) {
      let r, s;
      try {
        const _ = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_text(_, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var o = y().getInt32(_ + 4 * 0, true), i = y().getInt32(_ + 4 * 1, true), a = y().getInt32(_ + 4 * 2, true), c = y().getInt32(_ + 4 * 3, true), f = o, u = i;
        if (c)
          throw f = 0, u = 0, T(a);
        return r = f, s = u, Pt(f, u);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16), h.__wbindgen_free(r, s, 1);
      }
    }
    spans(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_spans(i, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    splice(t, e, r, s) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_splice(a, this.__wbg_ptr, A(t), e, r, A(s));
        var o = y().getInt32(a + 4 * 0, true), i = y().getInt32(a + 4 * 1, true);
        if (i)
          throw T(o);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateText(t, e) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_updateText(o, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        if (s)
          throw T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateSpans(t, e) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_updateSpans(o, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        if (s)
          throw T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    push(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_push(i, this.__wbg_ptr, A(t), A(e), A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pushObject(t, e) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_pushObject(a, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(a + 4 * 0, true), s = y().getInt32(a + 4 * 1, true), o = y().getInt32(a + 4 * 2, true), i = y().getInt32(a + 4 * 3, true);
        if (i)
          throw T(o);
        let c;
        return r !== 0 && (c = Pt(r, s).slice(), h.__wbindgen_free(r, s * 1, 1)), c;
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insert(t, e, r, s) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_insert(a, this.__wbg_ptr, A(t), e, A(r), A(s));
        var o = y().getInt32(a + 4 * 0, true), i = y().getInt32(a + 4 * 1, true);
        if (i)
          throw T(o);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    splitBlock(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_splitBlock(i, this.__wbg_ptr, A(t), e, A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    joinBlock(t, e) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_joinBlock(o, this.__wbg_ptr, A(t), e);
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        if (s)
          throw T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateBlock(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_updateBlock(i, this.__wbg_ptr, A(t), e, A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getBlock(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getBlock(a, this.__wbg_ptr, A(t), e, _t(r) ? 0 : A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insertObject(t, e, r) {
      try {
        const c = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_insertObject(c, this.__wbg_ptr, A(t), e, A(r));
        var s = y().getInt32(c + 4 * 0, true), o = y().getInt32(c + 4 * 1, true), i = y().getInt32(c + 4 * 2, true), a = y().getInt32(c + 4 * 3, true);
        if (a)
          throw T(i);
        let f;
        return s !== 0 && (f = Pt(s, o).slice(), h.__wbindgen_free(s, o * 1, 1)), f;
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    put(t, e, r, s) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_put(a, this.__wbg_ptr, A(t), A(e), A(r), A(s));
        var o = y().getInt32(a + 4 * 0, true), i = y().getInt32(a + 4 * 1, true);
        if (i)
          throw T(o);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    putObject(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_putObject(a, this.__wbg_ptr, A(t), A(e), A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    increment(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_increment(i, this.__wbg_ptr, A(t), A(e), A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    get(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_get(a, this.__wbg_ptr, A(t), A(e), _t(r) ? 0 : A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getWithType(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getWithType(a, this.__wbg_ptr, A(t), A(e), _t(r) ? 0 : A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    objInfo(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_objInfo(i, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getAll(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getAll(a, this.__wbg_ptr, A(t), A(e), _t(r) ? 0 : A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    enableFreeze(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_enableFreeze(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    registerDatatype(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_registerDatatype(i, this.__wbg_ptr, A(t), A(e), A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyPatches(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_applyPatches(i, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyAndReturnPatches(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_applyAndReturnPatches(i, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    diffIncremental() {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_diffIncremental(s, this.__wbg_ptr);
        var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
        if (r)
          throw T(e);
        return T(t);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateDiffCursor() {
      h.automerge_updateDiffCursor(this.__wbg_ptr);
    }
    resetDiffCursor() {
      h.automerge_resetDiffCursor(this.__wbg_ptr);
    }
    diff(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_diff(i, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    isolate(t) {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_isolate(s, this.__wbg_ptr, A(t));
        var e = y().getInt32(s + 4 * 0, true), r = y().getInt32(s + 4 * 1, true);
        if (r)
          throw T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    integrate() {
      h.automerge_integrate(this.__wbg_ptr);
    }
    length(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_length(i, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var r = y().getFloat64(i + 8 * 0, true), s = y().getInt32(i + 4 * 2, true), o = y().getInt32(i + 4 * 3, true);
        if (o)
          throw T(s);
        return r;
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    delete(t, e) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_delete(o, this.__wbg_ptr, A(t), A(e));
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        if (s)
          throw T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    save() {
      const t = h.automerge_save(this.__wbg_ptr);
      return T(t);
    }
    saveIncremental() {
      const t = h.automerge_saveIncremental(this.__wbg_ptr);
      return T(t);
    }
    saveSince(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_saveSince(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    saveNoCompress() {
      const t = h.automerge_saveNoCompress(this.__wbg_ptr);
      return T(t);
    }
    saveAndVerify() {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_saveAndVerify(s, this.__wbg_ptr);
        var t = y().getInt32(s + 4 * 0, true), e = y().getInt32(s + 4 * 1, true), r = y().getInt32(s + 4 * 2, true);
        if (r)
          throw T(e);
        return T(t);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    loadIncremental(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_loadIncremental(o, this.__wbg_ptr, A(t));
        var e = y().getFloat64(o + 8 * 0, true), r = y().getInt32(o + 4 * 2, true), s = y().getInt32(o + 4 * 3, true);
        if (s)
          throw T(r);
        return e;
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyChanges(t) {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_applyChanges(s, this.__wbg_ptr, A(t));
        var e = y().getInt32(s + 4 * 0, true), r = y().getInt32(s + 4 * 1, true);
        if (r)
          throw T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChanges(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getChanges(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangeByHash(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getChangeByHash(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getDecodedChangeByHash(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getDecodedChangeByHash(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangesAdded(t) {
      ke(t, Se);
      const e = h.automerge_getChangesAdded(this.__wbg_ptr, t.__wbg_ptr);
      return T(e);
    }
    getHeads() {
      const t = h.automerge_getHeads(this.__wbg_ptr);
      return T(t);
    }
    getActorId() {
      let t, e;
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getActorId(o, this.__wbg_ptr);
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        return t = r, e = s, Pt(r, s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16), h.__wbindgen_free(t, e, 1);
      }
    }
    getLastLocalChange() {
      const t = h.automerge_getLastLocalChange(this.__wbg_ptr);
      return T(t);
    }
    dump() {
      h.automerge_dump(this.__wbg_ptr);
    }
    getMissingDeps(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getMissingDeps(o, this.__wbg_ptr, _t(t) ? 0 : A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    receiveSyncMessage(t, e) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        ke(t, _e), h.automerge_receiveSyncMessage(o, this.__wbg_ptr, t.__wbg_ptr, A(e));
        var r = y().getInt32(o + 4 * 0, true), s = y().getInt32(o + 4 * 1, true);
        if (s)
          throw T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    generateSyncMessage(t) {
      ke(t, _e);
      const e = h.automerge_generateSyncMessage(this.__wbg_ptr, t.__wbg_ptr);
      return T(e);
    }
    toJS(t) {
      try {
        const o = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_toJS(o, this.__wbg_ptr, A(t));
        var e = y().getInt32(o + 4 * 0, true), r = y().getInt32(o + 4 * 1, true), s = y().getInt32(o + 4 * 2, true);
        if (s)
          throw T(r);
        return T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    materialize(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_materialize(a, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e), A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getCursor(t, e, r, s) {
      let o, i;
      try {
        const l = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getCursor(l, this.__wbg_ptr, A(t), A(e), _t(r) ? 0 : A(r), A(s));
        var a = y().getInt32(l + 4 * 0, true), c = y().getInt32(l + 4 * 1, true), f = y().getInt32(l + 4 * 2, true), u = y().getInt32(l + 4 * 3, true), _ = a, d = c;
        if (u)
          throw _ = 0, d = 0, T(f);
        return o = _, i = d, Pt(_, d);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16), h.__wbindgen_free(o, i, 1);
      }
    }
    getCursorPosition(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_getCursorPosition(a, this.__wbg_ptr, A(t), A(e), _t(r) ? 0 : A(r));
        var s = y().getFloat64(a + 8 * 0, true), o = y().getInt32(a + 4 * 2, true), i = y().getInt32(a + 4 * 3, true);
        if (i)
          throw T(o);
        return s;
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    emptyChange(t, e) {
      var r = _t(t) ? 0 : Zt(t, h.__wbindgen_malloc, h.__wbindgen_realloc), s = Vt;
      const o = h.automerge_emptyChange(this.__wbg_ptr, r, s, !_t(e), _t(e) ? 0 : e);
      return T(o);
    }
    mark(t, e, r, s, o) {
      try {
        const c = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_mark(c, this.__wbg_ptr, A(t), A(e), A(r), A(s), A(o));
        var i = y().getInt32(c + 4 * 0, true), a = y().getInt32(c + 4 * 1, true);
        if (a)
          throw T(i);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    unmark(t, e, r) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_unmark(i, this.__wbg_ptr, A(t), A(e), A(r));
        var s = y().getInt32(i + 4 * 0, true), o = y().getInt32(i + 4 * 1, true);
        if (o)
          throw T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marks(t, e) {
      try {
        const i = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_marks(i, this.__wbg_ptr, A(t), _t(e) ? 0 : A(e));
        var r = y().getInt32(i + 4 * 0, true), s = y().getInt32(i + 4 * 1, true), o = y().getInt32(i + 4 * 2, true);
        if (o)
          throw T(s);
        return T(r);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marksAt(t, e, r) {
      try {
        const a = h.__wbindgen_add_to_stack_pointer(-16);
        h.automerge_marksAt(a, this.__wbg_ptr, A(t), e, _t(r) ? 0 : A(r));
        var s = y().getInt32(a + 4 * 0, true), o = y().getInt32(a + 4 * 1, true), i = y().getInt32(a + 4 * 2, true);
        if (i)
          throw T(o);
        return T(s);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    hasOurChanges(t) {
      ke(t, _e);
      const e = h.automerge_hasOurChanges(this.__wbg_ptr, t.__wbg_ptr);
      return T(e);
    }
    topoHistoryTraversal() {
      const t = h.automerge_topoHistoryTraversal(this.__wbg_ptr);
      return T(t);
    }
    stats() {
      const t = h.automerge_stats(this.__wbg_ptr);
      return T(t);
    }
  };
  const qs = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((n) => h.__wbg_syncstate_free(n >>> 0, 1));
  let _e = class mr {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(mr.prototype);
      return e.__wbg_ptr = t, qs.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, qs.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      h.__wbg_syncstate_free(t, 0);
    }
    get sharedHeads() {
      const t = h.syncstate_sharedHeads(this.__wbg_ptr);
      return T(t);
    }
    get lastSentHeads() {
      const t = h.syncstate_lastSentHeads(this.__wbg_ptr);
      return T(t);
    }
    set lastSentHeads(t) {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.syncstate_set_lastSentHeads(s, this.__wbg_ptr, A(t));
        var e = y().getInt32(s + 4 * 0, true), r = y().getInt32(s + 4 * 1, true);
        if (r)
          throw T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    set sentHashes(t) {
      try {
        const s = h.__wbindgen_add_to_stack_pointer(-16);
        h.syncstate_set_sentHashes(s, this.__wbg_ptr, A(t));
        var e = y().getInt32(s + 4 * 0, true), r = y().getInt32(s + 4 * 1, true);
        if (r)
          throw T(e);
      } finally {
        h.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone() {
      const t = h.syncstate_clone(this.__wbg_ptr);
      return mr.__wrap(t);
    }
  };
  async function v_(n, t) {
    if (typeof Response == "function" && n instanceof Response) {
      if (typeof WebAssembly.instantiateStreaming == "function")
        try {
          return await WebAssembly.instantiateStreaming(n, t);
        } catch (r) {
          if (n.headers.get("Content-Type") != "application/wasm")
            console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", r);
          else
            throw r;
        }
      const e = await n.arrayBuffer();
      return await WebAssembly.instantiate(e, t);
    } else {
      const e = await WebAssembly.instantiate(n, t);
      return e instanceof WebAssembly.Instance ? {
        instance: e,
        module: n
      } : e;
    }
  }
  function Ro() {
    const n = {};
    return n.wbg = {}, n.wbg.__wbg_String_fed4d24b68977888 = function(t, e) {
      const r = String(V(e)), s = Zt(r, h.__wbindgen_malloc, h.__wbindgen_realloc), o = Vt;
      y().setInt32(t + 4 * 1, o, true), y().setInt32(t + 4 * 0, s, true);
    }, n.wbg.__wbg_apply_eb9e9b97497f91e4 = function() {
      return re(function(t, e, r) {
        const s = Reflect.apply(V(t), V(e), V(r));
        return A(s);
      }, arguments);
    }, n.wbg.__wbg_assign_3627b8559449930a = function(t, e) {
      const r = Object.assign(V(t), V(e));
      return A(r);
    }, n.wbg.__wbg_buffer_609cc3eee51ed158 = function(t) {
      const e = V(t).buffer;
      return A(e);
    }, n.wbg.__wbg_call_672a4d21634d4a24 = function() {
      return re(function(t, e) {
        const r = V(t).call(V(e));
        return A(r);
      }, arguments);
    }, n.wbg.__wbg_call_7cccdd69e0791ae2 = function() {
      return re(function(t, e, r) {
        const s = V(t).call(V(e), V(r));
        return A(s);
      }, arguments);
    }, n.wbg.__wbg_concat_9de968491c4340cf = function(t, e) {
      const r = V(t).concat(V(e));
      return A(r);
    }, n.wbg.__wbg_defineProperty_a3ddad9901e2d29e = function(t, e, r) {
      const s = Object.defineProperty(V(t), V(e), V(r));
      return A(s);
    }, n.wbg.__wbg_deleteProperty_96363d4a1d977c97 = function() {
      return re(function(t, e) {
        return Reflect.deleteProperty(V(t), V(e));
      }, arguments);
    }, n.wbg.__wbg_done_769e5ede4b31c67b = function(t) {
      return V(t).done;
    }, n.wbg.__wbg_entries_3265d4158b33e5dc = function(t) {
      const e = Object.entries(V(t));
      return A(e);
    }, n.wbg.__wbg_error_7534b8e9a36f1ab4 = function(t, e) {
      let r, s;
      try {
        r = t, s = e, console.error(Pt(t, e));
      } finally {
        h.__wbindgen_free(r, s, 1);
      }
    }, n.wbg.__wbg_for_4ff07bddd743c5e7 = function(t, e) {
      const r = Symbol.for(Pt(t, e));
      return A(r);
    }, n.wbg.__wbg_freeze_ef6d70cf38e8d948 = function(t) {
      const e = Object.freeze(V(t));
      return A(e);
    }, n.wbg.__wbg_from_2a5d3e218e67aa85 = function(t) {
      const e = Array.from(V(t));
      return A(e);
    }, n.wbg.__wbg_getRandomValues_3d90134a348e46b3 = function() {
      return re(function(t, e) {
        globalThis.crypto.getRandomValues(a_(t, e));
      }, arguments);
    }, n.wbg.__wbg_getTime_46267b1c24877e30 = function(t) {
      return V(t).getTime();
    }, n.wbg.__wbg_get_67b2ba62fc30de12 = function() {
      return re(function(t, e) {
        const r = Reflect.get(V(t), V(e));
        return A(r);
      }, arguments);
    }, n.wbg.__wbg_get_b9b93047fe3cf45b = function(t, e) {
      const r = V(t)[e >>> 0];
      return A(r);
    }, n.wbg.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(t) {
      let e;
      try {
        e = V(t) instanceof ArrayBuffer;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_instanceof_Date_e9a9be8b9cea7890 = function(t) {
      let e;
      try {
        e = V(t) instanceof Date;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_instanceof_Object_7f2dcef8f78644a4 = function(t) {
      let e;
      try {
        e = V(t) instanceof Object;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(t) {
      let e;
      try {
        e = V(t) instanceof Uint8Array;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_isArray_a1eab7e0d067391b = function(t) {
      return Array.isArray(V(t));
    }, n.wbg.__wbg_iterator_9a24c88df860dc65 = function() {
      return A(Symbol.iterator);
    }, n.wbg.__wbg_keys_5c77a08ddc2fb8a6 = function(t) {
      const e = Object.keys(V(t));
      return A(e);
    }, n.wbg.__wbg_length_a446193dc22c12f8 = function(t) {
      return V(t).length;
    }, n.wbg.__wbg_length_d56737991078581b = function(t) {
      return V(t).length;
    }, n.wbg.__wbg_length_e2d2a49132c1b256 = function(t) {
      return V(t).length;
    }, n.wbg.__wbg_log_1ae1e9f741096e91 = function(t, e) {
      console.log(V(t), V(e));
    }, n.wbg.__wbg_log_c222819a41e063d3 = function(t) {
      console.log(V(t));
    }, n.wbg.__wbg_new_1ab78df5e132f715 = function(t, e) {
      const r = new RangeError(Pt(t, e));
      return A(r);
    }, n.wbg.__wbg_new_31a97dac4f10fab7 = function(t) {
      const e = new Date(V(t));
      return A(e);
    }, n.wbg.__wbg_new_405e22f390576ce2 = function() {
      const t = new Object();
      return A(t);
    }, n.wbg.__wbg_new_78feb108b6472713 = function() {
      const t = new Array();
      return A(t);
    }, n.wbg.__wbg_new_8a6f238a6ece86ea = function() {
      const t = new Error();
      return A(t);
    }, n.wbg.__wbg_new_a12002a7f91c75be = function(t) {
      const e = new Uint8Array(V(t));
      return A(e);
    }, n.wbg.__wbg_new_c68d7209be747379 = function(t, e) {
      const r = new Error(Pt(t, e));
      return A(r);
    }, n.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(t, e, r) {
      const s = new Uint8Array(V(t), e >>> 0, r >>> 0);
      return A(s);
    }, n.wbg.__wbg_next_25feadfc0913fea9 = function(t) {
      const e = V(t).next;
      return A(e);
    }, n.wbg.__wbg_next_6574e1a8a62d1055 = function() {
      return re(function(t) {
        const e = V(t).next();
        return A(e);
      }, arguments);
    }, n.wbg.__wbg_ownKeys_3930041068756f1f = function() {
      return re(function(t) {
        const e = Reflect.ownKeys(V(t));
        return A(e);
      }, arguments);
    }, n.wbg.__wbg_push_737cfc8c1432c2c6 = function(t, e) {
      return V(t).push(V(e));
    }, n.wbg.__wbg_set_37837023f3d740e8 = function(t, e, r) {
      V(t)[e >>> 0] = T(r);
    }, n.wbg.__wbg_set_3fda3bac07393de4 = function(t, e, r) {
      V(t)[T(e)] = T(r);
    }, n.wbg.__wbg_set_65595bdd868b3009 = function(t, e, r) {
      V(t).set(V(e), r >>> 0);
    }, n.wbg.__wbg_set_bb8cecf6a62b9f46 = function() {
      return re(function(t, e, r) {
        return Reflect.set(V(t), V(e), V(r));
      }, arguments);
    }, n.wbg.__wbg_slice_972c243648c9fd2e = function(t, e, r) {
      const s = V(t).slice(e >>> 0, r >>> 0);
      return A(s);
    }, n.wbg.__wbg_stack_0ed75d68575b0f3c = function(t, e) {
      const r = V(e).stack, s = Zt(r, h.__wbindgen_malloc, h.__wbindgen_realloc), o = Vt;
      y().setInt32(t + 4 * 1, o, true), y().setInt32(t + 4 * 0, s, true);
    }, n.wbg.__wbg_toString_66ab719c2a98bdf1 = function(t) {
      const e = V(t).toString();
      return A(e);
    }, n.wbg.__wbg_unshift_c290010f73f04fb1 = function(t, e) {
      return V(t).unshift(V(e));
    }, n.wbg.__wbg_value_cd1ffa7b1ab794f1 = function(t) {
      const e = V(t).value;
      return A(e);
    }, n.wbg.__wbg_values_fcb8ba8c0aad8b58 = function(t) {
      const e = Object.values(V(t));
      return A(e);
    }, n.wbg.__wbindgen_bigint_from_i64 = function(t) {
      return A(t);
    }, n.wbg.__wbindgen_bigint_from_u64 = function(t) {
      const e = BigInt.asUintN(64, t);
      return A(e);
    }, n.wbg.__wbindgen_boolean_get = function(t) {
      const e = V(t);
      return typeof e == "boolean" ? e ? 1 : 0 : 2;
    }, n.wbg.__wbindgen_debug_string = function(t, e) {
      const r = yr(V(e)), s = Zt(r, h.__wbindgen_malloc, h.__wbindgen_realloc), o = Vt;
      y().setInt32(t + 4 * 1, o, true), y().setInt32(t + 4 * 0, s, true);
    }, n.wbg.__wbindgen_error_new = function(t, e) {
      const r = new Error(Pt(t, e));
      return A(r);
    }, n.wbg.__wbindgen_is_array = function(t) {
      return Array.isArray(V(t));
    }, n.wbg.__wbindgen_is_function = function(t) {
      return typeof V(t) == "function";
    }, n.wbg.__wbindgen_is_null = function(t) {
      return V(t) === null;
    }, n.wbg.__wbindgen_is_object = function(t) {
      const e = V(t);
      return typeof e == "object" && e !== null;
    }, n.wbg.__wbindgen_is_string = function(t) {
      return typeof V(t) == "string";
    }, n.wbg.__wbindgen_is_undefined = function(t) {
      return V(t) === void 0;
    }, n.wbg.__wbindgen_json_serialize = function(t, e) {
      const r = V(e), s = JSON.stringify(r === void 0 ? null : r), o = Zt(s, h.__wbindgen_malloc, h.__wbindgen_realloc), i = Vt;
      y().setInt32(t + 4 * 1, i, true), y().setInt32(t + 4 * 0, o, true);
    }, n.wbg.__wbindgen_jsval_loose_eq = function(t, e) {
      return V(t) == V(e);
    }, n.wbg.__wbindgen_memory = function() {
      const t = h.memory;
      return A(t);
    }, n.wbg.__wbindgen_number_get = function(t, e) {
      const r = V(e), s = typeof r == "number" ? r : void 0;
      y().setFloat64(t + 8 * 1, _t(s) ? 0 : s, true), y().setInt32(t + 4 * 0, !_t(s), true);
    }, n.wbg.__wbindgen_number_new = function(t) {
      return A(t);
    }, n.wbg.__wbindgen_object_clone_ref = function(t) {
      const e = V(t);
      return A(e);
    }, n.wbg.__wbindgen_object_drop_ref = function(t) {
      T(t);
    }, n.wbg.__wbindgen_string_get = function(t, e) {
      const r = V(e), s = typeof r == "string" ? r : void 0;
      var o = _t(s) ? 0 : Zt(s, h.__wbindgen_malloc, h.__wbindgen_realloc), i = Vt;
      y().setInt32(t + 4 * 1, i, true), y().setInt32(t + 4 * 0, o, true);
    }, n.wbg.__wbindgen_string_new = function(t, e) {
      const r = Pt(t, e);
      return A(r);
    }, n.wbg.__wbindgen_throw = function(t, e) {
      throw new Error(Pt(t, e));
    }, n;
  }
  function To(n, t) {
    return h = n.exports, Kr.__wbindgen_wasm_module = t, ve = null, Ze = null, h;
  }
  function S_(n) {
    if (h !== void 0)
      return h;
    typeof n < "u" && (Object.getPrototypeOf(n) === Object.prototype ? { module: n } = n : console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));
    const t = Ro();
    n instanceof WebAssembly.Module || (n = new WebAssembly.Module(n));
    const e = new WebAssembly.Instance(n, t);
    return To(e, n);
  }
  async function Kr(n) {
    if (h !== void 0)
      return h;
    typeof n < "u" && (Object.getPrototypeOf(n) === Object.prototype ? { module_or_path: n } = n : console.warn("using deprecated parameters for the initialization function; pass a single object instead")), typeof n > "u" && (n = new URL("" + new URL("automerge_wasm_bg-3b6d9ad6.wasm", import.meta.url).href, self.location));
    const t = Ro();
    (typeof n == "string" || typeof Request == "function" && n instanceof Request || typeof URL == "function" && n instanceof URL) && (n = fetch(n));
    const { instance: e, module: r } = await v_(await n, t);
    return To(e, r);
  }
  const x_ = Object.freeze(Object.defineProperty({
    __proto__: null,
    Automerge: Wr,
    SyncState: _e,
    TextRepresentation: m_,
    create: __,
    decodeChange: d_,
    decodeSyncMessage: p_,
    decodeSyncState: y_,
    default: Kr,
    encodeChange: f_,
    encodeSyncMessage: b_,
    encodeSyncState: w_,
    exportSyncState: g_,
    importSyncState: h_,
    initSync: S_,
    initSyncState: l_,
    load: u_
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  let Jr = false, Mo = [];
  Gr = function(n) {
    for (const t in n)
      vt[t] = n[t];
    Jr = true;
    for (const t of Mo)
      t();
  };
  const vt = {
    create(n) {
      throw new RangeError("Automerge.use() not called");
    },
    load(n, t) {
      throw new RangeError("Automerge.use() not called (load)");
    },
    encodeChange(n) {
      throw new RangeError("Automerge.use() not called (encodeChange)");
    },
    decodeChange(n) {
      throw new RangeError("Automerge.use() not called (decodeChange)");
    },
    initSyncState() {
      throw new RangeError("Automerge.use() not called (initSyncState)");
    },
    encodeSyncMessage(n) {
      throw new RangeError("Automerge.use() not called (encodeSyncMessage)");
    },
    decodeSyncMessage(n) {
      throw new RangeError("Automerge.use() not called (decodeSyncMessage)");
    },
    encodeSyncState(n) {
      throw new RangeError("Automerge.use() not called (encodeSyncState)");
    },
    decodeSyncState(n) {
      throw new RangeError("Automerge.use() not called (decodeSyncState)");
    },
    exportSyncState(n) {
      throw new RangeError("Automerge.use() not called (exportSyncState)");
    },
    importSyncState(n) {
      throw new RangeError("Automerge.use() not called (importSyncState)");
    }
  };
  function qr(n) {
    return Kr({
      module_or_path: n
    }).then((t) => {
      Gr(x_);
    });
  }
  function Ho(n) {
    return qr(Uint8Array.from(atob(n), (t) => t.charCodeAt(0)));
  }
  function Do() {
    return Jr ? Promise.resolve() : new Promise((n) => {
      Mo.push(n);
    });
  }
  function $o() {
    return Jr;
  }
  const I_ = "" + new URL("automerge_wasm_bg-211c8fa6.wasm", import.meta.url).href, k_ = async (n = {}, t) => {
    let e;
    if (t.startsWith("data:")) {
      const r = t.replace(/^data:.*?base64,/, "");
      let s;
      if (typeof Buffer == "function" && typeof Buffer.from == "function")
        s = Buffer.from(r, "base64");
      else if (typeof atob == "function") {
        const o = atob(r);
        s = new Uint8Array(o.length);
        for (let i = 0; i < o.length; i++)
          s[i] = o.charCodeAt(i);
      } else
        throw new Error("Cannot decode base64-encoded data URL");
      e = await WebAssembly.instantiate(s, n);
    } else {
      const r = await fetch(t), s = r.headers.get("Content-Type") || "";
      if ("instantiateStreaming" in WebAssembly && s.startsWith("application/wasm"))
        e = await WebAssembly.instantiateStreaming(r, n);
      else {
        const o = await r.arrayBuffer();
        e = await WebAssembly.instantiate(o, n);
      }
    }
    return e.instance.exports;
  };
  let g;
  function Uo(n) {
    g = n;
  }
  const ie = new Array(128).fill(void 0);
  ie.push(void 0, null, true, false);
  function z(n) {
    return ie[n];
  }
  let zt = 0, kn = null;
  function on() {
    return (kn === null || kn.byteLength === 0) && (kn = new Uint8Array(g.memory.buffer)), kn;
  }
  const A_ = typeof TextEncoder > "u" ? (0, module.require)("util").TextEncoder : TextEncoder;
  let Mn = new A_("utf-8");
  const E_ = typeof Mn.encodeInto == "function" ? function(n, t) {
    return Mn.encodeInto(n, t);
  } : function(n, t) {
    const e = Mn.encode(n);
    return t.set(e), {
      read: n.length,
      written: e.length
    };
  };
  function Qt(n, t, e) {
    if (e === void 0) {
      const a = Mn.encode(n), c = t(a.length, 1) >>> 0;
      return on().subarray(c, c + a.length).set(a), zt = a.length, c;
    }
    let r = n.length, s = t(r, 1) >>> 0;
    const o = on();
    let i = 0;
    for (; i < r; i++) {
      const a = n.charCodeAt(i);
      if (a > 127)
        break;
      o[s + i] = a;
    }
    if (i !== r) {
      i !== 0 && (n = n.slice(i)), s = e(s, r, r = i + n.length * 3, 1) >>> 0;
      const a = on().subarray(s + i, s + r), c = E_(n, a);
      i += c.written, s = e(s, r, i, 1) >>> 0;
    }
    return zt = i, s;
  }
  let Te = null;
  function m() {
    return (Te === null || Te.buffer.detached === true || Te.buffer.detached === void 0 && Te.buffer !== g.memory.buffer) && (Te = new DataView(g.memory.buffer)), Te;
  }
  let an = ie.length;
  function E(n) {
    an === ie.length && ie.push(ie.length + 1);
    const t = an;
    return an = ie[t], ie[t] = n, t;
  }
  function le(n, t) {
    try {
      return n.apply(this, t);
    } catch (e) {
      g.__wbindgen_exn_store(E(e));
    }
  }
  const C_ = typeof TextDecoder > "u" ? (0, module.require)("util").TextDecoder : TextDecoder;
  let Bo = new C_("utf-8", {
    ignoreBOM: true,
    fatal: true
  });
  Bo.decode();
  function Nt(n, t) {
    return n = n >>> 0, Bo.decode(on().subarray(n, n + t));
  }
  function O_(n, t) {
    return n = n >>> 0, on().subarray(n / 1, n / 1 + t);
  }
  function j_(n) {
    n < 132 || (ie[n] = an, an = n);
  }
  function M(n) {
    const t = z(n);
    return j_(n), t;
  }
  function vr(n) {
    const t = typeof n;
    if (t == "number" || t == "boolean" || n == null)
      return `${n}`;
    if (t == "string")
      return `"${n}"`;
    if (t == "symbol") {
      const s = n.description;
      return s == null ? "Symbol" : `Symbol(${s})`;
    }
    if (t == "function") {
      const s = n.name;
      return typeof s == "string" && s.length > 0 ? `Function(${s})` : "Function";
    }
    if (Array.isArray(n)) {
      const s = n.length;
      let o = "[";
      s > 0 && (o += vr(n[0]));
      for (let i = 1; i < s; i++)
        o += ", " + vr(n[i]);
      return o += "]", o;
    }
    const e = /\[object ([^\]]+)\]/.exec(toString.call(n));
    let r;
    if (e && e.length > 1)
      r = e[1];
    else
      return toString.call(n);
    if (r == "Object")
      try {
        return "Object(" + JSON.stringify(n) + ")";
      } catch {
        return "Object";
      }
    return n instanceof Error ? `${n.name}: ${n.message}
${n.stack}` : r;
  }
  function ut(n) {
    return n == null;
  }
  function Ae(n, t) {
    if (!(n instanceof t))
      throw new Error(`expected instance of ${t.name}`);
  }
  function R_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.create(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return Yr.__wrap(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function T_(n, t) {
    try {
      const o = g.__wbindgen_add_to_stack_pointer(-16);
      g.load(o, E(n), E(t));
      var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
      if (s)
        throw M(r);
      return Yr.__wrap(e);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function M_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.encodeChange(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return M(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function H_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.decodeChange(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return M(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function D_() {
    const n = g.initSyncState();
    return ue.__wrap(n);
  }
  function $_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.importSyncState(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return ue.__wrap(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function U_(n) {
    Ae(n, ue);
    const t = g.exportSyncState(n.__wbg_ptr);
    return M(t);
  }
  function B_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.encodeSyncMessage(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return M(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function P_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.decodeSyncMessage(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return M(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function F_(n) {
    Ae(n, ue);
    const t = g.encodeSyncState(n.__wbg_ptr);
    return M(t);
  }
  function L_(n) {
    try {
      const s = g.__wbindgen_add_to_stack_pointer(-16);
      g.decodeSyncState(s, E(n));
      var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
      if (r)
        throw M(e);
      return ue.__wrap(t);
    } finally {
      g.__wbindgen_add_to_stack_pointer(16);
    }
  }
  const V_ = Object.freeze({
    Array: 0,
    0: "Array",
    String: 1,
    1: "String"
  }), Ys = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((n) => g.__wbg_automerge_free(n >>> 0, 1));
  let Yr = class xe {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(xe.prototype);
      return e.__wbg_ptr = t, Ys.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, Ys.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      g.__wbg_automerge_free(t, 0);
    }
    static new(t, e) {
      try {
        const c = g.__wbindgen_add_to_stack_pointer(-16);
        var r = ut(t) ? 0 : Qt(t, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
        g.automerge_new(c, r, s, e);
        var o = m().getInt32(c + 4 * 0, true), i = m().getInt32(c + 4 * 1, true), a = m().getInt32(c + 4 * 2, true);
        if (a)
          throw M(i);
        return xe.__wrap(o);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone(t) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        var e = ut(t) ? 0 : Qt(t, g.__wbindgen_malloc, g.__wbindgen_realloc), r = zt;
        g.automerge_clone(a, this.__wbg_ptr, e, r);
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return xe.__wrap(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    fork(t, e) {
      try {
        const c = g.__wbindgen_add_to_stack_pointer(-16);
        var r = ut(t) ? 0 : Qt(t, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
        g.automerge_fork(c, this.__wbg_ptr, r, s, E(e));
        var o = m().getInt32(c + 4 * 0, true), i = m().getInt32(c + 4 * 1, true), a = m().getInt32(c + 4 * 2, true);
        if (a)
          throw M(i);
        return xe.__wrap(o);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pendingOps() {
      const t = g.automerge_pendingOps(this.__wbg_ptr);
      return M(t);
    }
    commit(t, e) {
      var r = ut(t) ? 0 : Qt(t, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
      const o = g.automerge_commit(this.__wbg_ptr, r, s, !ut(e), ut(e) ? 0 : e);
      return M(o);
    }
    merge(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        Ae(t, xe), g.automerge_merge(o, this.__wbg_ptr, t.__wbg_ptr);
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    rollback() {
      return g.automerge_rollback(this.__wbg_ptr);
    }
    keys(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_keys(i, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    text(t, e) {
      let r, s;
      try {
        const _ = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_text(_, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var o = m().getInt32(_ + 4 * 0, true), i = m().getInt32(_ + 4 * 1, true), a = m().getInt32(_ + 4 * 2, true), c = m().getInt32(_ + 4 * 3, true), f = o, u = i;
        if (c)
          throw f = 0, u = 0, M(a);
        return r = f, s = u, Nt(f, u);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16), g.__wbindgen_free(r, s, 1);
      }
    }
    spans(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_spans(i, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    splice(t, e, r, s) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_splice(a, this.__wbg_ptr, E(t), e, r, E(s));
        var o = m().getInt32(a + 4 * 0, true), i = m().getInt32(a + 4 * 1, true);
        if (i)
          throw M(o);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateText(t, e) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_updateText(o, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        if (s)
          throw M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateSpans(t, e) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_updateSpans(o, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        if (s)
          throw M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    push(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_push(i, this.__wbg_ptr, E(t), E(e), E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pushObject(t, e) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_pushObject(a, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(a + 4 * 0, true), s = m().getInt32(a + 4 * 1, true), o = m().getInt32(a + 4 * 2, true), i = m().getInt32(a + 4 * 3, true);
        if (i)
          throw M(o);
        let c;
        return r !== 0 && (c = Nt(r, s).slice(), g.__wbindgen_free(r, s * 1, 1)), c;
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insert(t, e, r, s) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_insert(a, this.__wbg_ptr, E(t), e, E(r), E(s));
        var o = m().getInt32(a + 4 * 0, true), i = m().getInt32(a + 4 * 1, true);
        if (i)
          throw M(o);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    splitBlock(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_splitBlock(i, this.__wbg_ptr, E(t), e, E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    joinBlock(t, e) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_joinBlock(o, this.__wbg_ptr, E(t), e);
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        if (s)
          throw M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateBlock(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_updateBlock(i, this.__wbg_ptr, E(t), e, E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getBlock(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getBlock(a, this.__wbg_ptr, E(t), e, ut(r) ? 0 : E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insertObject(t, e, r) {
      try {
        const c = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_insertObject(c, this.__wbg_ptr, E(t), e, E(r));
        var s = m().getInt32(c + 4 * 0, true), o = m().getInt32(c + 4 * 1, true), i = m().getInt32(c + 4 * 2, true), a = m().getInt32(c + 4 * 3, true);
        if (a)
          throw M(i);
        let f;
        return s !== 0 && (f = Nt(s, o).slice(), g.__wbindgen_free(s, o * 1, 1)), f;
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    put(t, e, r, s) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_put(a, this.__wbg_ptr, E(t), E(e), E(r), E(s));
        var o = m().getInt32(a + 4 * 0, true), i = m().getInt32(a + 4 * 1, true);
        if (i)
          throw M(o);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    putObject(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_putObject(a, this.__wbg_ptr, E(t), E(e), E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    increment(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_increment(i, this.__wbg_ptr, E(t), E(e), E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    get(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_get(a, this.__wbg_ptr, E(t), E(e), ut(r) ? 0 : E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getWithType(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getWithType(a, this.__wbg_ptr, E(t), E(e), ut(r) ? 0 : E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    objInfo(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_objInfo(i, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getAll(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getAll(a, this.__wbg_ptr, E(t), E(e), ut(r) ? 0 : E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    enableFreeze(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_enableFreeze(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    registerDatatype(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_registerDatatype(i, this.__wbg_ptr, E(t), E(e), E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyPatches(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_applyPatches(i, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyAndReturnPatches(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_applyAndReturnPatches(i, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    diffIncremental() {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_diffIncremental(s, this.__wbg_ptr);
        var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
        if (r)
          throw M(e);
        return M(t);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateDiffCursor() {
      g.automerge_updateDiffCursor(this.__wbg_ptr);
    }
    resetDiffCursor() {
      g.automerge_resetDiffCursor(this.__wbg_ptr);
    }
    diff(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_diff(i, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    isolate(t) {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_isolate(s, this.__wbg_ptr, E(t));
        var e = m().getInt32(s + 4 * 0, true), r = m().getInt32(s + 4 * 1, true);
        if (r)
          throw M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    integrate() {
      g.automerge_integrate(this.__wbg_ptr);
    }
    length(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_length(i, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var r = m().getFloat64(i + 8 * 0, true), s = m().getInt32(i + 4 * 2, true), o = m().getInt32(i + 4 * 3, true);
        if (o)
          throw M(s);
        return r;
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    delete(t, e) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_delete(o, this.__wbg_ptr, E(t), E(e));
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        if (s)
          throw M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    save() {
      const t = g.automerge_save(this.__wbg_ptr);
      return M(t);
    }
    saveIncremental() {
      const t = g.automerge_saveIncremental(this.__wbg_ptr);
      return M(t);
    }
    saveSince(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_saveSince(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    saveNoCompress() {
      const t = g.automerge_saveNoCompress(this.__wbg_ptr);
      return M(t);
    }
    saveAndVerify() {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_saveAndVerify(s, this.__wbg_ptr);
        var t = m().getInt32(s + 4 * 0, true), e = m().getInt32(s + 4 * 1, true), r = m().getInt32(s + 4 * 2, true);
        if (r)
          throw M(e);
        return M(t);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    loadIncremental(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_loadIncremental(o, this.__wbg_ptr, E(t));
        var e = m().getFloat64(o + 8 * 0, true), r = m().getInt32(o + 4 * 2, true), s = m().getInt32(o + 4 * 3, true);
        if (s)
          throw M(r);
        return e;
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyChanges(t) {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_applyChanges(s, this.__wbg_ptr, E(t));
        var e = m().getInt32(s + 4 * 0, true), r = m().getInt32(s + 4 * 1, true);
        if (r)
          throw M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChanges(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getChanges(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangeByHash(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getChangeByHash(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getDecodedChangeByHash(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getDecodedChangeByHash(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangesAdded(t) {
      Ae(t, xe);
      const e = g.automerge_getChangesAdded(this.__wbg_ptr, t.__wbg_ptr);
      return M(e);
    }
    getHeads() {
      const t = g.automerge_getHeads(this.__wbg_ptr);
      return M(t);
    }
    getActorId() {
      let t, e;
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getActorId(o, this.__wbg_ptr);
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        return t = r, e = s, Nt(r, s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16), g.__wbindgen_free(t, e, 1);
      }
    }
    getLastLocalChange() {
      const t = g.automerge_getLastLocalChange(this.__wbg_ptr);
      return M(t);
    }
    dump() {
      g.automerge_dump(this.__wbg_ptr);
    }
    getMissingDeps(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getMissingDeps(o, this.__wbg_ptr, ut(t) ? 0 : E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    receiveSyncMessage(t, e) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        Ae(t, ue), g.automerge_receiveSyncMessage(o, this.__wbg_ptr, t.__wbg_ptr, E(e));
        var r = m().getInt32(o + 4 * 0, true), s = m().getInt32(o + 4 * 1, true);
        if (s)
          throw M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    generateSyncMessage(t) {
      Ae(t, ue);
      const e = g.automerge_generateSyncMessage(this.__wbg_ptr, t.__wbg_ptr);
      return M(e);
    }
    toJS(t) {
      try {
        const o = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_toJS(o, this.__wbg_ptr, E(t));
        var e = m().getInt32(o + 4 * 0, true), r = m().getInt32(o + 4 * 1, true), s = m().getInt32(o + 4 * 2, true);
        if (s)
          throw M(r);
        return M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    materialize(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_materialize(a, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e), E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getCursor(t, e, r, s) {
      let o, i;
      try {
        const l = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getCursor(l, this.__wbg_ptr, E(t), E(e), ut(r) ? 0 : E(r), E(s));
        var a = m().getInt32(l + 4 * 0, true), c = m().getInt32(l + 4 * 1, true), f = m().getInt32(l + 4 * 2, true), u = m().getInt32(l + 4 * 3, true), _ = a, d = c;
        if (u)
          throw _ = 0, d = 0, M(f);
        return o = _, i = d, Nt(_, d);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16), g.__wbindgen_free(o, i, 1);
      }
    }
    getCursorPosition(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_getCursorPosition(a, this.__wbg_ptr, E(t), E(e), ut(r) ? 0 : E(r));
        var s = m().getFloat64(a + 8 * 0, true), o = m().getInt32(a + 4 * 2, true), i = m().getInt32(a + 4 * 3, true);
        if (i)
          throw M(o);
        return s;
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    emptyChange(t, e) {
      var r = ut(t) ? 0 : Qt(t, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
      const o = g.automerge_emptyChange(this.__wbg_ptr, r, s, !ut(e), ut(e) ? 0 : e);
      return M(o);
    }
    mark(t, e, r, s, o) {
      try {
        const c = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_mark(c, this.__wbg_ptr, E(t), E(e), E(r), E(s), E(o));
        var i = m().getInt32(c + 4 * 0, true), a = m().getInt32(c + 4 * 1, true);
        if (a)
          throw M(i);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    unmark(t, e, r) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_unmark(i, this.__wbg_ptr, E(t), E(e), E(r));
        var s = m().getInt32(i + 4 * 0, true), o = m().getInt32(i + 4 * 1, true);
        if (o)
          throw M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marks(t, e) {
      try {
        const i = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_marks(i, this.__wbg_ptr, E(t), ut(e) ? 0 : E(e));
        var r = m().getInt32(i + 4 * 0, true), s = m().getInt32(i + 4 * 1, true), o = m().getInt32(i + 4 * 2, true);
        if (o)
          throw M(s);
        return M(r);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marksAt(t, e, r) {
      try {
        const a = g.__wbindgen_add_to_stack_pointer(-16);
        g.automerge_marksAt(a, this.__wbg_ptr, E(t), e, ut(r) ? 0 : E(r));
        var s = m().getInt32(a + 4 * 0, true), o = m().getInt32(a + 4 * 1, true), i = m().getInt32(a + 4 * 2, true);
        if (i)
          throw M(o);
        return M(s);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    hasOurChanges(t) {
      Ae(t, ue);
      const e = g.automerge_hasOurChanges(this.__wbg_ptr, t.__wbg_ptr);
      return M(e);
    }
    topoHistoryTraversal() {
      const t = g.automerge_topoHistoryTraversal(this.__wbg_ptr);
      return M(t);
    }
    stats() {
      const t = g.automerge_stats(this.__wbg_ptr);
      return M(t);
    }
  };
  const Xs = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((n) => g.__wbg_syncstate_free(n >>> 0, 1));
  let ue = class Sr {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(Sr.prototype);
      return e.__wbg_ptr = t, Xs.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, Xs.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      g.__wbg_syncstate_free(t, 0);
    }
    get sharedHeads() {
      const t = g.syncstate_sharedHeads(this.__wbg_ptr);
      return M(t);
    }
    get lastSentHeads() {
      const t = g.syncstate_lastSentHeads(this.__wbg_ptr);
      return M(t);
    }
    set lastSentHeads(t) {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.syncstate_set_lastSentHeads(s, this.__wbg_ptr, E(t));
        var e = m().getInt32(s + 4 * 0, true), r = m().getInt32(s + 4 * 1, true);
        if (r)
          throw M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    set sentHashes(t) {
      try {
        const s = g.__wbindgen_add_to_stack_pointer(-16);
        g.syncstate_set_sentHashes(s, this.__wbg_ptr, E(t));
        var e = m().getInt32(s + 4 * 0, true), r = m().getInt32(s + 4 * 1, true);
        if (r)
          throw M(e);
      } finally {
        g.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone() {
      const t = g.syncstate_clone(this.__wbg_ptr);
      return Sr.__wrap(t);
    }
  };
  function Po(n, t) {
    const e = String(z(t)), r = Qt(e, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
    m().setInt32(n + 4 * 1, s, true), m().setInt32(n + 4 * 0, r, true);
  }
  function Fo() {
    return le(function(n, t, e) {
      const r = Reflect.apply(z(n), z(t), z(e));
      return E(r);
    }, arguments);
  }
  function Lo(n, t) {
    const e = Object.assign(z(n), z(t));
    return E(e);
  }
  function Vo(n) {
    const t = z(n).buffer;
    return E(t);
  }
  function zo() {
    return le(function(n, t) {
      const e = z(n).call(z(t));
      return E(e);
    }, arguments);
  }
  function No() {
    return le(function(n, t, e) {
      const r = z(n).call(z(t), z(e));
      return E(r);
    }, arguments);
  }
  function Wo(n, t) {
    const e = z(n).concat(z(t));
    return E(e);
  }
  function Ko(n, t, e) {
    const r = Object.defineProperty(z(n), z(t), z(e));
    return E(r);
  }
  function Jo() {
    return le(function(n, t) {
      return Reflect.deleteProperty(z(n), z(t));
    }, arguments);
  }
  function Go(n) {
    return z(n).done;
  }
  function qo(n) {
    const t = Object.entries(z(n));
    return E(t);
  }
  function Yo(n, t) {
    let e, r;
    try {
      e = n, r = t, console.error(Nt(n, t));
    } finally {
      g.__wbindgen_free(e, r, 1);
    }
  }
  function Xo(n, t) {
    const e = Symbol.for(Nt(n, t));
    return E(e);
  }
  function Zo(n) {
    const t = Object.freeze(z(n));
    return E(t);
  }
  function Qo(n) {
    const t = Array.from(z(n));
    return E(t);
  }
  function ti() {
    return le(function(n, t) {
      globalThis.crypto.getRandomValues(O_(n, t));
    }, arguments);
  }
  function ei(n) {
    return z(n).getTime();
  }
  function ni() {
    return le(function(n, t) {
      const e = Reflect.get(z(n), z(t));
      return E(e);
    }, arguments);
  }
  function ri(n, t) {
    const e = z(n)[t >>> 0];
    return E(e);
  }
  function si(n) {
    let t;
    try {
      t = z(n) instanceof ArrayBuffer;
    } catch {
      t = false;
    }
    return t;
  }
  function oi(n) {
    let t;
    try {
      t = z(n) instanceof Date;
    } catch {
      t = false;
    }
    return t;
  }
  function ii(n) {
    let t;
    try {
      t = z(n) instanceof Object;
    } catch {
      t = false;
    }
    return t;
  }
  function ai(n) {
    let t;
    try {
      t = z(n) instanceof Uint8Array;
    } catch {
      t = false;
    }
    return t;
  }
  function ci(n) {
    return Array.isArray(z(n));
  }
  function _i() {
    return E(Symbol.iterator);
  }
  function ui(n) {
    const t = Object.keys(z(n));
    return E(t);
  }
  function fi(n) {
    return z(n).length;
  }
  function di(n) {
    return z(n).length;
  }
  function li(n) {
    return z(n).length;
  }
  function hi(n, t) {
    console.log(z(n), z(t));
  }
  function gi(n) {
    console.log(z(n));
  }
  function bi(n, t) {
    const e = new RangeError(Nt(n, t));
    return E(e);
  }
  function pi(n) {
    const t = new Date(z(n));
    return E(t);
  }
  function wi() {
    const n = new Object();
    return E(n);
  }
  function yi() {
    const n = new Array();
    return E(n);
  }
  function mi() {
    const n = new Error();
    return E(n);
  }
  function vi(n) {
    const t = new Uint8Array(z(n));
    return E(t);
  }
  function Si(n, t) {
    const e = new Error(Nt(n, t));
    return E(e);
  }
  function xi(n, t, e) {
    const r = new Uint8Array(z(n), t >>> 0, e >>> 0);
    return E(r);
  }
  function Ii(n) {
    const t = z(n).next;
    return E(t);
  }
  function ki() {
    return le(function(n) {
      const t = z(n).next();
      return E(t);
    }, arguments);
  }
  function Ai() {
    return le(function(n) {
      const t = Reflect.ownKeys(z(n));
      return E(t);
    }, arguments);
  }
  function Ei(n, t) {
    return z(n).push(z(t));
  }
  function Ci(n, t, e) {
    z(n)[t >>> 0] = M(e);
  }
  function Oi(n, t, e) {
    z(n)[M(t)] = M(e);
  }
  function ji(n, t, e) {
    z(n).set(z(t), e >>> 0);
  }
  function Ri() {
    return le(function(n, t, e) {
      return Reflect.set(z(n), z(t), z(e));
    }, arguments);
  }
  function Ti(n, t, e) {
    const r = z(n).slice(t >>> 0, e >>> 0);
    return E(r);
  }
  function Mi(n, t) {
    const e = z(t).stack, r = Qt(e, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
    m().setInt32(n + 4 * 1, s, true), m().setInt32(n + 4 * 0, r, true);
  }
  function Hi(n) {
    const t = z(n).toString();
    return E(t);
  }
  function Di(n, t) {
    return z(n).unshift(z(t));
  }
  function $i(n) {
    const t = z(n).value;
    return E(t);
  }
  function Ui(n) {
    const t = Object.values(z(n));
    return E(t);
  }
  function Bi(n) {
    return E(n);
  }
  function Pi(n) {
    const t = BigInt.asUintN(64, n);
    return E(t);
  }
  function Fi(n) {
    const t = z(n);
    return typeof t == "boolean" ? t ? 1 : 0 : 2;
  }
  function Li(n, t) {
    const e = vr(z(t)), r = Qt(e, g.__wbindgen_malloc, g.__wbindgen_realloc), s = zt;
    m().setInt32(n + 4 * 1, s, true), m().setInt32(n + 4 * 0, r, true);
  }
  function Vi(n, t) {
    const e = new Error(Nt(n, t));
    return E(e);
  }
  function zi(n) {
    return Array.isArray(z(n));
  }
  function Ni(n) {
    return typeof z(n) == "function";
  }
  function Wi(n) {
    return z(n) === null;
  }
  function Ki(n) {
    const t = z(n);
    return typeof t == "object" && t !== null;
  }
  function Ji(n) {
    return typeof z(n) == "string";
  }
  function Gi(n) {
    return z(n) === void 0;
  }
  function qi(n, t) {
    const e = z(t), r = JSON.stringify(e === void 0 ? null : e), s = Qt(r, g.__wbindgen_malloc, g.__wbindgen_realloc), o = zt;
    m().setInt32(n + 4 * 1, o, true), m().setInt32(n + 4 * 0, s, true);
  }
  function Yi(n, t) {
    return z(n) == z(t);
  }
  function Xi() {
    const n = g.memory;
    return E(n);
  }
  function Zi(n, t) {
    const e = z(t), r = typeof e == "number" ? e : void 0;
    m().setFloat64(n + 8 * 1, ut(r) ? 0 : r, true), m().setInt32(n + 4 * 0, !ut(r), true);
  }
  function Qi(n) {
    return E(n);
  }
  function ta(n) {
    const t = z(n);
    return E(t);
  }
  function ea(n) {
    M(n);
  }
  function na(n, t) {
    const e = z(t), r = typeof e == "string" ? e : void 0;
    var s = ut(r) ? 0 : Qt(r, g.__wbindgen_malloc, g.__wbindgen_realloc), o = zt;
    m().setInt32(n + 4 * 1, o, true), m().setInt32(n + 4 * 0, s, true);
  }
  function ra(n, t) {
    const e = Nt(n, t);
    return E(e);
  }
  function sa(n, t) {
    throw new Error(Nt(n, t));
  }
  URL = globalThis.URL;
  const B = await k_({
    "./automerge_wasm_bg.js": {
      __wbindgen_object_drop_ref: ea,
      __wbindgen_string_get: na,
      __wbindgen_error_new: Vi,
      __wbindgen_string_new: ra,
      __wbindgen_number_new: Qi,
      __wbindgen_object_clone_ref: ta,
      __wbindgen_number_get: Zi,
      __wbindgen_is_undefined: Gi,
      __wbindgen_boolean_get: Fi,
      __wbindgen_is_null: Wi,
      __wbindgen_is_string: Ji,
      __wbindgen_is_function: Ni,
      __wbindgen_is_object: Ki,
      __wbindgen_is_array: zi,
      __wbindgen_json_serialize: qi,
      __wbg_new_8a6f238a6ece86ea: mi,
      __wbg_stack_0ed75d68575b0f3c: Mi,
      __wbg_error_7534b8e9a36f1ab4: Yo,
      __wbindgen_jsval_loose_eq: Yi,
      __wbg_String_fed4d24b68977888: Po,
      __wbindgen_bigint_from_i64: Bi,
      __wbindgen_bigint_from_u64: Pi,
      __wbg_set_3fda3bac07393de4: Oi,
      __wbg_getRandomValues_3d90134a348e46b3: ti,
      __wbg_log_c222819a41e063d3: gi,
      __wbg_log_1ae1e9f741096e91: hi,
      __wbg_get_b9b93047fe3cf45b: ri,
      __wbg_length_e2d2a49132c1b256: li,
      __wbg_new_78feb108b6472713: yi,
      __wbg_next_25feadfc0913fea9: Ii,
      __wbg_next_6574e1a8a62d1055: ki,
      __wbg_done_769e5ede4b31c67b: Go,
      __wbg_value_cd1ffa7b1ab794f1: $i,
      __wbg_iterator_9a24c88df860dc65: _i,
      __wbg_get_67b2ba62fc30de12: ni,
      __wbg_call_672a4d21634d4a24: zo,
      __wbg_new_405e22f390576ce2: wi,
      __wbg_length_d56737991078581b: di,
      __wbg_set_37837023f3d740e8: Ci,
      __wbg_from_2a5d3e218e67aa85: Qo,
      __wbg_isArray_a1eab7e0d067391b: ci,
      __wbg_push_737cfc8c1432c2c6: Ei,
      __wbg_unshift_c290010f73f04fb1: Di,
      __wbg_instanceof_ArrayBuffer_e14585432e3737fc: si,
      __wbg_new_c68d7209be747379: Si,
      __wbg_call_7cccdd69e0791ae2: No,
      __wbg_instanceof_Date_e9a9be8b9cea7890: oi,
      __wbg_getTime_46267b1c24877e30: ei,
      __wbg_new_31a97dac4f10fab7: pi,
      __wbg_instanceof_Object_7f2dcef8f78644a4: ii,
      __wbg_assign_3627b8559449930a: Lo,
      __wbg_defineProperty_a3ddad9901e2d29e: Ko,
      __wbg_entries_3265d4158b33e5dc: qo,
      __wbg_freeze_ef6d70cf38e8d948: Zo,
      __wbg_keys_5c77a08ddc2fb8a6: ui,
      __wbg_values_fcb8ba8c0aad8b58: Ui,
      __wbg_new_1ab78df5e132f715: bi,
      __wbg_apply_eb9e9b97497f91e4: Fo,
      __wbg_deleteProperty_96363d4a1d977c97: Jo,
      __wbg_ownKeys_3930041068756f1f: Ai,
      __wbg_set_bb8cecf6a62b9f46: Ri,
      __wbg_buffer_609cc3eee51ed158: Vo,
      __wbg_concat_9de968491c4340cf: Wo,
      __wbg_slice_972c243648c9fd2e: Ti,
      __wbg_for_4ff07bddd743c5e7: Xo,
      __wbg_toString_66ab719c2a98bdf1: Hi,
      __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a: xi,
      __wbg_new_a12002a7f91c75be: vi,
      __wbg_set_65595bdd868b3009: ji,
      __wbg_length_a446193dc22c12f8: fi,
      __wbg_instanceof_Uint8Array_17156bcf118086a9: ai,
      __wbindgen_debug_string: Li,
      __wbindgen_throw: sa,
      __wbindgen_memory: Xi
    }
  }, I_), z_ = B.memory, N_ = B.__wbg_syncstate_free, W_ = B.syncstate_sharedHeads, K_ = B.syncstate_lastSentHeads, J_ = B.syncstate_set_lastSentHeads, G_ = B.syncstate_set_sentHashes, q_ = B.syncstate_clone, Y_ = B.__wbg_automerge_free, X_ = B.automerge_new, Z_ = B.automerge_clone, Q_ = B.automerge_fork, tu = B.automerge_pendingOps, eu = B.automerge_commit, nu = B.automerge_merge, ru = B.automerge_rollback, su = B.automerge_keys, ou = B.automerge_text, iu = B.automerge_spans, au = B.automerge_splice, cu = B.automerge_updateText, _u = B.automerge_updateSpans, uu = B.automerge_push, fu = B.automerge_pushObject, du = B.automerge_insert, lu = B.automerge_splitBlock, hu = B.automerge_joinBlock, gu = B.automerge_updateBlock, bu = B.automerge_getBlock, pu = B.automerge_insertObject, wu = B.automerge_put, yu = B.automerge_putObject, mu = B.automerge_increment, vu = B.automerge_get, Su = B.automerge_getWithType, xu = B.automerge_objInfo, Iu = B.automerge_getAll, ku = B.automerge_enableFreeze, Au = B.automerge_registerDatatype, Eu = B.automerge_applyPatches, Cu = B.automerge_applyAndReturnPatches, Ou = B.automerge_diffIncremental, ju = B.automerge_updateDiffCursor, Ru = B.automerge_resetDiffCursor, Tu = B.automerge_diff, Mu = B.automerge_isolate, Hu = B.automerge_integrate, Du = B.automerge_length, $u = B.automerge_delete, Uu = B.automerge_save, Bu = B.automerge_saveIncremental, Pu = B.automerge_saveSince, Fu = B.automerge_saveNoCompress, Lu = B.automerge_saveAndVerify, Vu = B.automerge_loadIncremental, zu = B.automerge_applyChanges, Nu = B.automerge_getChanges, Wu = B.automerge_getChangeByHash, Ku = B.automerge_getDecodedChangeByHash, Ju = B.automerge_getChangesAdded, Gu = B.automerge_getHeads, qu = B.automerge_getActorId, Yu = B.automerge_getLastLocalChange, Xu = B.automerge_dump, Zu = B.automerge_getMissingDeps, Qu = B.automerge_receiveSyncMessage, tf = B.automerge_generateSyncMessage, ef = B.automerge_toJS, nf = B.automerge_materialize, rf = B.automerge_getCursor, sf = B.automerge_getCursorPosition, of = B.automerge_emptyChange, af = B.automerge_mark, cf = B.automerge_unmark, _f = B.automerge_marks, uf = B.automerge_marksAt, ff = B.automerge_hasOurChanges, df = B.automerge_topoHistoryTraversal, lf = B.automerge_stats, hf = B.create, gf = B.load, bf = B.encodeChange, pf = B.decodeChange, wf = B.initSyncState, yf = B.importSyncState, mf = B.exportSyncState, vf = B.encodeSyncMessage, Sf = B.decodeSyncMessage, xf = B.encodeSyncState, If = B.decodeSyncState, kf = B.__wbindgen_malloc, Af = B.__wbindgen_realloc, Ef = B.__wbindgen_exn_store, Cf = B.__wbindgen_free, Of = B.__wbindgen_add_to_stack_pointer, jf = Object.freeze(Object.defineProperty({
    __proto__: null,
    __wbg_automerge_free: Y_,
    __wbg_syncstate_free: N_,
    __wbindgen_add_to_stack_pointer: Of,
    __wbindgen_exn_store: Ef,
    __wbindgen_free: Cf,
    __wbindgen_malloc: kf,
    __wbindgen_realloc: Af,
    automerge_applyAndReturnPatches: Cu,
    automerge_applyChanges: zu,
    automerge_applyPatches: Eu,
    automerge_clone: Z_,
    automerge_commit: eu,
    automerge_delete: $u,
    automerge_diff: Tu,
    automerge_diffIncremental: Ou,
    automerge_dump: Xu,
    automerge_emptyChange: of,
    automerge_enableFreeze: ku,
    automerge_fork: Q_,
    automerge_generateSyncMessage: tf,
    automerge_get: vu,
    automerge_getActorId: qu,
    automerge_getAll: Iu,
    automerge_getBlock: bu,
    automerge_getChangeByHash: Wu,
    automerge_getChanges: Nu,
    automerge_getChangesAdded: Ju,
    automerge_getCursor: rf,
    automerge_getCursorPosition: sf,
    automerge_getDecodedChangeByHash: Ku,
    automerge_getHeads: Gu,
    automerge_getLastLocalChange: Yu,
    automerge_getMissingDeps: Zu,
    automerge_getWithType: Su,
    automerge_hasOurChanges: ff,
    automerge_increment: mu,
    automerge_insert: du,
    automerge_insertObject: pu,
    automerge_integrate: Hu,
    automerge_isolate: Mu,
    automerge_joinBlock: hu,
    automerge_keys: su,
    automerge_length: Du,
    automerge_loadIncremental: Vu,
    automerge_mark: af,
    automerge_marks: _f,
    automerge_marksAt: uf,
    automerge_materialize: nf,
    automerge_merge: nu,
    automerge_new: X_,
    automerge_objInfo: xu,
    automerge_pendingOps: tu,
    automerge_push: uu,
    automerge_pushObject: fu,
    automerge_put: wu,
    automerge_putObject: yu,
    automerge_receiveSyncMessage: Qu,
    automerge_registerDatatype: Au,
    automerge_resetDiffCursor: Ru,
    automerge_rollback: ru,
    automerge_save: Uu,
    automerge_saveAndVerify: Lu,
    automerge_saveIncremental: Bu,
    automerge_saveNoCompress: Fu,
    automerge_saveSince: Pu,
    automerge_spans: iu,
    automerge_splice: au,
    automerge_splitBlock: lu,
    automerge_stats: lf,
    automerge_text: ou,
    automerge_toJS: ef,
    automerge_topoHistoryTraversal: df,
    automerge_unmark: cf,
    automerge_updateBlock: gu,
    automerge_updateDiffCursor: ju,
    automerge_updateSpans: _u,
    automerge_updateText: cu,
    create: hf,
    decodeChange: pf,
    decodeSyncMessage: Sf,
    decodeSyncState: If,
    encodeChange: bf,
    encodeSyncMessage: vf,
    encodeSyncState: xf,
    exportSyncState: mf,
    importSyncState: yf,
    initSyncState: wf,
    load: gf,
    memory: z_,
    syncstate_clone: q_,
    syncstate_lastSentHeads: K_,
    syncstate_set_lastSentHeads: J_,
    syncstate_set_sentHashes: G_,
    syncstate_sharedHeads: W_
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  Uo(jf);
  Rf = Object.freeze(Object.defineProperty({
    __proto__: null,
    Automerge: Yr,
    SyncState: ue,
    TextRepresentation: V_,
    __wbg_String_fed4d24b68977888: Po,
    __wbg_apply_eb9e9b97497f91e4: Fo,
    __wbg_assign_3627b8559449930a: Lo,
    __wbg_buffer_609cc3eee51ed158: Vo,
    __wbg_call_672a4d21634d4a24: zo,
    __wbg_call_7cccdd69e0791ae2: No,
    __wbg_concat_9de968491c4340cf: Wo,
    __wbg_defineProperty_a3ddad9901e2d29e: Ko,
    __wbg_deleteProperty_96363d4a1d977c97: Jo,
    __wbg_done_769e5ede4b31c67b: Go,
    __wbg_entries_3265d4158b33e5dc: qo,
    __wbg_error_7534b8e9a36f1ab4: Yo,
    __wbg_for_4ff07bddd743c5e7: Xo,
    __wbg_freeze_ef6d70cf38e8d948: Zo,
    __wbg_from_2a5d3e218e67aa85: Qo,
    __wbg_getRandomValues_3d90134a348e46b3: ti,
    __wbg_getTime_46267b1c24877e30: ei,
    __wbg_get_67b2ba62fc30de12: ni,
    __wbg_get_b9b93047fe3cf45b: ri,
    __wbg_instanceof_ArrayBuffer_e14585432e3737fc: si,
    __wbg_instanceof_Date_e9a9be8b9cea7890: oi,
    __wbg_instanceof_Object_7f2dcef8f78644a4: ii,
    __wbg_instanceof_Uint8Array_17156bcf118086a9: ai,
    __wbg_isArray_a1eab7e0d067391b: ci,
    __wbg_iterator_9a24c88df860dc65: _i,
    __wbg_keys_5c77a08ddc2fb8a6: ui,
    __wbg_length_a446193dc22c12f8: fi,
    __wbg_length_d56737991078581b: di,
    __wbg_length_e2d2a49132c1b256: li,
    __wbg_log_1ae1e9f741096e91: hi,
    __wbg_log_c222819a41e063d3: gi,
    __wbg_new_1ab78df5e132f715: bi,
    __wbg_new_31a97dac4f10fab7: pi,
    __wbg_new_405e22f390576ce2: wi,
    __wbg_new_78feb108b6472713: yi,
    __wbg_new_8a6f238a6ece86ea: mi,
    __wbg_new_a12002a7f91c75be: vi,
    __wbg_new_c68d7209be747379: Si,
    __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a: xi,
    __wbg_next_25feadfc0913fea9: Ii,
    __wbg_next_6574e1a8a62d1055: ki,
    __wbg_ownKeys_3930041068756f1f: Ai,
    __wbg_push_737cfc8c1432c2c6: Ei,
    __wbg_set_37837023f3d740e8: Ci,
    __wbg_set_3fda3bac07393de4: Oi,
    __wbg_set_65595bdd868b3009: ji,
    __wbg_set_bb8cecf6a62b9f46: Ri,
    __wbg_set_wasm: Uo,
    __wbg_slice_972c243648c9fd2e: Ti,
    __wbg_stack_0ed75d68575b0f3c: Mi,
    __wbg_toString_66ab719c2a98bdf1: Hi,
    __wbg_unshift_c290010f73f04fb1: Di,
    __wbg_value_cd1ffa7b1ab794f1: $i,
    __wbg_values_fcb8ba8c0aad8b58: Ui,
    __wbindgen_bigint_from_i64: Bi,
    __wbindgen_bigint_from_u64: Pi,
    __wbindgen_boolean_get: Fi,
    __wbindgen_debug_string: Li,
    __wbindgen_error_new: Vi,
    __wbindgen_is_array: zi,
    __wbindgen_is_function: Ni,
    __wbindgen_is_null: Wi,
    __wbindgen_is_object: Ki,
    __wbindgen_is_string: Ji,
    __wbindgen_is_undefined: Gi,
    __wbindgen_json_serialize: qi,
    __wbindgen_jsval_loose_eq: Yi,
    __wbindgen_memory: Xi,
    __wbindgen_number_get: Zi,
    __wbindgen_number_new: Qi,
    __wbindgen_object_clone_ref: ta,
    __wbindgen_object_drop_ref: ea,
    __wbindgen_string_get: na,
    __wbindgen_string_new: ra,
    __wbindgen_throw: sa,
    create: R_,
    decodeChange: H_,
    decodeSyncMessage: P_,
    decodeSyncState: L_,
    encodeChange: M_,
    encodeSyncMessage: B_,
    encodeSyncState: F_,
    exportSyncState: U_,
    importSyncState: $_,
    initSyncState: D_,
    load: T_
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  let An;
  const Tf = new Uint8Array(16);
  function Mf() {
    if (!An && (An = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !An))
      throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
    return An(Tf);
  }
  const Hf = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
  function Gn(n) {
    return typeof n == "string" && Hf.test(n);
  }
  const St = [];
  for (let n = 0; n < 256; ++n)
    St.push((n + 256).toString(16).slice(1));
  function oa(n, t = 0) {
    return St[n[t + 0]] + St[n[t + 1]] + St[n[t + 2]] + St[n[t + 3]] + "-" + St[n[t + 4]] + St[n[t + 5]] + "-" + St[n[t + 6]] + St[n[t + 7]] + "-" + St[n[t + 8]] + St[n[t + 9]] + "-" + St[n[t + 10]] + St[n[t + 11]] + St[n[t + 12]] + St[n[t + 13]] + St[n[t + 14]] + St[n[t + 15]];
  }
  function Df(n, t = 0) {
    const e = oa(n, t);
    if (!Gn(e))
      throw TypeError("Stringified UUID is invalid");
    return e;
  }
  function $f(n) {
    if (!Gn(n))
      throw TypeError("Invalid UUID");
    let t;
    const e = new Uint8Array(16);
    return e[0] = (t = parseInt(n.slice(0, 8), 16)) >>> 24, e[1] = t >>> 16 & 255, e[2] = t >>> 8 & 255, e[3] = t & 255, e[4] = (t = parseInt(n.slice(9, 13), 16)) >>> 8, e[5] = t & 255, e[6] = (t = parseInt(n.slice(14, 18), 16)) >>> 8, e[7] = t & 255, e[8] = (t = parseInt(n.slice(19, 23), 16)) >>> 8, e[9] = t & 255, e[10] = (t = parseInt(n.slice(24, 36), 16)) / 1099511627776 & 255, e[11] = t / 4294967296 & 255, e[12] = t >>> 24 & 255, e[13] = t >>> 16 & 255, e[14] = t >>> 8 & 255, e[15] = t & 255, e;
  }
  const Uf = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Zs = {
    randomUUID: Uf
  };
  function Xr(n, t, e) {
    if (Zs.randomUUID && !t && !n)
      return Zs.randomUUID();
    n = n || {};
    const r = n.random || (n.rng || Mf)();
    if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
      e = e || 0;
      for (let s = 0; s < 16; ++s)
        t[e + s] = r[s];
      return t;
    }
    return oa(r);
  }
  function ia() {
    return Xr().replace(/-/g, "");
  }
  let Zr = ia;
  Qr = () => Zr();
  Qr.setFactory = (n) => {
    Zr = n;
  };
  Qr.reset = () => {
    Zr = ia;
  };
  const fe = Symbol.for("_am_meta"), Fe = Symbol.for("_am_trace"), Le = Symbol.for("_am_objectId"), qn = Symbol.for("_am_isProxy"), ts = Symbol.for("_am_clearCache"), aa = Symbol.for("_am_uint"), ca = Symbol.for("_am_int"), _a = Symbol.for("_am_f64"), ua = Symbol.for("_am_counter"), xr = Symbol.for("_am_text"), fa = Symbol.for("_am_rawString");
  var Qs;
  class de {
    constructor(t) {
      if (this[Qs] = true, typeof t == "string")
        this.elems = [
          ...t
        ];
      else if (Array.isArray(t))
        this.elems = t;
      else if (t === void 0)
        this.elems = [];
      else
        throw new TypeError(`Unsupported initial value for Text: ${t}`);
      Reflect.defineProperty(this, xr, {
        value: true
      });
    }
    get length() {
      return this.elems.length;
    }
    get(t) {
      return this.elems[t];
    }
    [(Qs = xr, Symbol.iterator)]() {
      const t = this.elems;
      let e = -1;
      return {
        next() {
          return e += 1, e < t.length ? {
            done: false,
            value: t[e]
          } : {
            done: true
          };
        }
      };
    }
    toString() {
      if (!this.str) {
        this.str = "";
        for (const t of this.elems)
          typeof t == "string" ? this.str += t : this.str += "\uFFFC";
      }
      return this.str;
    }
    toSpans() {
      if (!this.spans) {
        this.spans = [];
        let t = "";
        for (const e of this.elems)
          typeof e == "string" ? t += e : (t.length > 0 && (this.spans.push(t), t = ""), this.spans.push(e));
        t.length > 0 && this.spans.push(t);
      }
      return this.spans;
    }
    toJSON() {
      return this.toString();
    }
    set(t, e) {
      if (this[fe])
        throw new RangeError("object cannot be modified outside of a change block");
      this.elems[t] = e;
    }
    insertAt(t, ...e) {
      if (this[fe])
        throw new RangeError("object cannot be modified outside of a change block");
      e.every((r) => typeof r == "string") ? this.elems.splice(t, 0, ...e.join("")) : this.elems.splice(t, 0, ...e);
    }
    deleteAt(t, e = 1) {
      if (this[fe])
        throw new RangeError("object cannot be modified outside of a change block");
      this.elems.splice(t, e);
    }
    map(t) {
      this.elems.map(t);
    }
    lastIndexOf(t, e) {
      this.elems.lastIndexOf(t, e);
    }
    concat(t) {
      return new de(this.elems.concat(t.elems));
    }
    every(t) {
      return this.elems.every(t);
    }
    filter(t) {
      return new de(this.elems.filter(t));
    }
    find(t) {
      return this.elems.find(t);
    }
    findIndex(t) {
      return this.elems.findIndex(t);
    }
    forEach(t) {
      this.elems.forEach(t);
    }
    includes(t) {
      return this.elems.includes(t);
    }
    indexOf(t) {
      return this.elems.indexOf(t);
    }
    join(t) {
      return this.elems.join(t);
    }
    reduce(t) {
      this.elems.reduce(t);
    }
    reduceRight(t) {
      this.elems.reduceRight(t);
    }
    slice(t, e) {
      return new de(this.elems.slice(t, e));
    }
    some(t) {
      return this.elems.some(t);
    }
    toLocaleString() {
      this.toString();
    }
  }
  class Ve {
    constructor(t) {
      this.value = t || 0, Reflect.defineProperty(this, ua, {
        value: true
      });
    }
    valueOf() {
      return this.value;
    }
    toString() {
      return this.valueOf().toString();
    }
    toJSON() {
      return this.value;
    }
    increment(t) {
      throw new Error("Counters should not be incremented outside of a change callback");
    }
    decrement(t) {
      throw new Error("Counters should not be decremented outside of a change callback");
    }
  }
  class Bf extends Ve {
    constructor(t, e, r, s, o) {
      super(t), this.context = e, this.path = r, this.objectId = s, this.key = o;
    }
    increment(t) {
      return t = typeof t == "number" ? t : 1, this.context.increment(this.objectId, this.key, t), this.value += t, this.value;
    }
    decrement(t) {
      return this.increment(typeof t == "number" ? -t : -1);
    }
  }
  function Pf(n, t, e, r, s) {
    return new Bf(n, t, e, r, s);
  }
  var da;
  class es {
    constructor(t) {
      this[da] = true, this.val = t;
    }
    toString() {
      return this.val;
    }
    toJSON() {
      return this.val;
    }
  }
  da = fa;
  function te(n) {
    if (typeof n == "string" && /^[0-9]+$/.test(n) && (n = parseInt(n, 10)), typeof n != "number")
      return n;
    if (n < 0 || isNaN(n) || n === 1 / 0 || n === -1 / 0)
      throw new RangeError("A list index must be positive, but you passed " + n);
    return n;
  }
  function Ut(n, t) {
    const { context: e, objectId: r, path: s, textV2: o } = n, i = e.getWithType(r, t);
    if (i === null)
      return;
    const a = i[0], c = i[1];
    switch (a) {
      case void 0:
        return;
      case "map":
        return Je(e, c, o, [
          ...s,
          t
        ]);
      case "list":
        return pn(e, c, o, [
          ...s,
          t
        ]);
      case "text":
        return o ? e.text(c) : _n(e, c, [
          ...s,
          t
        ]);
      case "str":
        return o ? new es(c) : c;
      case "uint":
        return c;
      case "int":
        return c;
      case "f64":
        return c;
      case "boolean":
        return c;
      case "null":
        return null;
      case "bytes":
        return c;
      case "timestamp":
        return c;
      case "counter":
        return Pf(c, e, s, r, t);
      default:
        throw RangeError(`datatype ${a} unimplemented`);
    }
  }
  function Fn(n, t, e, r) {
    const s = typeof n;
    switch (s) {
      case "object":
        if (n == null)
          return [
            null,
            "null"
          ];
        if (n[aa])
          return [
            n.value,
            "uint"
          ];
        if (n[ca])
          return [
            n.value,
            "int"
          ];
        if (n[_a])
          return [
            n.value,
            "f64"
          ];
        if (n[ua])
          return [
            n.value,
            "counter"
          ];
        if (n instanceof Date)
          return [
            n.getTime(),
            "timestamp"
          ];
        if (ss(n))
          return [
            n.toString(),
            "str"
          ];
        if (os(n))
          return [
            n,
            "text"
          ];
        if (n instanceof Uint8Array)
          return [
            n,
            "bytes"
          ];
        if (n instanceof Array)
          return [
            n,
            "list"
          ];
        if (Object.prototype.toString.call(n) === "[object Object]")
          return [
            n,
            "map"
          ];
        throw Yn(n, r) ? new RangeError("Cannot create a reference to an existing document object") : new RangeError(`Cannot assign unknown object: ${n}`);
      case "boolean":
        return [
          n,
          "boolean"
        ];
      case "number":
        return Number.isInteger(n) ? [
          n,
          "int"
        ] : [
          n,
          "f64"
        ];
      case "string":
        return t ? [
          n,
          "text"
        ] : [
          n,
          "str"
        ];
      case "undefined":
        throw new RangeError([
          `Cannot assign undefined value at ${to(e)}, `,
          "because `undefined` is not a valid JSON data type. ",
          "You might consider setting the property's value to `null`, ",
          "or using `delete` to remove it altogether."
        ].join(""));
      default:
        throw new RangeError([
          `Cannot assign ${s} value at ${to(e)}. `,
          "All JSON primitive datatypes (object, array, string, number, boolean, null) ",
          `are supported in an Automerge document; ${s} values are not. `
        ].join(""));
    }
  }
  function Yn(n, t) {
    var e, r;
    return n instanceof Date ? false : !!(n && ((r = (e = n[fe]) === null || e === void 0 ? void 0 : e.handle) === null || r === void 0 ? void 0 : r.__wbg_ptr) === t.__wbg_ptr);
  }
  const Ff = {
    get(n, t) {
      const { context: e, objectId: r, cache: s } = n;
      return t === Symbol.toStringTag ? n[Symbol.toStringTag] : t === Le ? r : t === qn ? true : t === Fe ? n.trace : t === fe ? {
        handle: e,
        textV2: n.textV2
      } : (s[t] || (s[t] = Ut(n, t)), s[t]);
    },
    set(n, t, e) {
      const { context: r, objectId: s, path: o, textV2: i } = n;
      if (n.cache = {}, Yn(e, r))
        throw new RangeError("Cannot create a reference to an existing document object");
      if (t === Fe)
        return n.trace = e, true;
      if (t === ts)
        return true;
      const [a, c] = Fn(e, i, [
        ...o,
        t
      ], r);
      switch (c) {
        case "list": {
          const f = r.putObject(s, t, []), u = pn(r, f, i, [
            ...o,
            t
          ]);
          for (let _ = 0; _ < a.length; _++)
            u[_] = a[_];
          break;
        }
        case "text": {
          if (i)
            Ln(a), r.putObject(s, t, a);
          else {
            rs(a);
            const f = r.putObject(s, t, "");
            _n(r, f, [
              ...o,
              t
            ]).splice(0, 0, ...a);
          }
          break;
        }
        case "map": {
          const f = r.putObject(s, t, {}), u = Je(r, f, i, [
            ...o,
            t
          ]);
          for (const _ in a)
            u[_] = a[_];
          break;
        }
        default:
          r.put(s, t, a, c);
      }
      return true;
    },
    deleteProperty(n, t) {
      const { context: e, objectId: r } = n;
      return n.cache = {}, e.delete(r, t), true;
    },
    has(n, t) {
      return this.get(n, t) !== void 0;
    },
    getOwnPropertyDescriptor(n, t) {
      const e = this.get(n, t);
      if (typeof e < "u")
        return {
          configurable: true,
          enumerable: true,
          value: e
        };
    },
    ownKeys(n) {
      const { context: t, objectId: e } = n, r = t.keys(e);
      return [
        ...new Set(r)
      ];
    }
  }, la = {
    get(n, t) {
      const { context: e, objectId: r } = n;
      return t = te(t), t === Symbol.hasInstance ? (s) => Array.isArray(s) : t === Symbol.toStringTag ? n[Symbol.toStringTag] : t === Le ? r : t === qn ? true : t === Fe ? n.trace : t === fe ? {
        handle: e
      } : t === "length" ? e.length(r) : typeof t == "number" ? Ut(n, t) : ns(n)[t];
    },
    set(n, t, e) {
      const { context: r, objectId: s, path: o, textV2: i } = n;
      if (t = te(t), Yn(e, r))
        throw new RangeError("Cannot create a reference to an existing document object");
      if (t === ts)
        return true;
      if (t === Fe)
        return n.trace = e, true;
      if (typeof t == "string")
        throw new RangeError("list index must be a number");
      const [a, c] = Fn(e, i, [
        ...o,
        t
      ], r);
      switch (c) {
        case "list": {
          let f;
          t >= r.length(s) ? f = r.insertObject(s, t, []) : f = r.putObject(s, t, []), pn(r, f, i, [
            ...o,
            t
          ]).splice(0, 0, ...a);
          break;
        }
        case "text": {
          if (i)
            Ln(a), t >= r.length(s) ? r.insertObject(s, t, a) : r.putObject(s, t, a);
          else {
            let f;
            rs(a), t >= r.length(s) ? f = r.insertObject(s, t, "") : f = r.putObject(s, t, ""), _n(r, f, [
              ...o,
              t
            ]).splice(0, 0, ...a);
          }
          break;
        }
        case "map": {
          let f;
          t >= r.length(s) ? f = r.insertObject(s, t, {}) : f = r.putObject(s, t, {});
          const u = Je(r, f, i, [
            ...o,
            t
          ]);
          for (const _ in a)
            u[_] = a[_];
          break;
        }
        default:
          t >= r.length(s) ? r.insert(s, t, a, c) : r.put(s, t, a, c);
      }
      return true;
    },
    deleteProperty(n, t) {
      const { context: e, objectId: r } = n;
      t = te(t);
      const s = e.get(r, t);
      if (s != null && s[0] == "counter")
        throw new TypeError("Unsupported operation: deleting a counter from a list");
      return e.delete(r, t), true;
    },
    has(n, t) {
      const { context: e, objectId: r } = n;
      return t = te(t), typeof t == "number" ? t < e.length(r) : t === "length";
    },
    getOwnPropertyDescriptor(n, t) {
      const { context: e, objectId: r } = n;
      return t === "length" ? {
        writable: true,
        value: e.length(r)
      } : t === Le ? {
        configurable: false,
        enumerable: false,
        value: r
      } : (t = te(t), {
        configurable: true,
        enumerable: true,
        value: Ut(n, t)
      });
    },
    getPrototypeOf(n) {
      return Object.getPrototypeOf(n);
    },
    ownKeys() {
      const n = [];
      return n.push("length"), n;
    }
  }, Lf = Object.assign({}, la, {
    get(n, t) {
      const { context: e, objectId: r } = n;
      return t = te(t), t === Symbol.hasInstance ? (s) => Array.isArray(s) : t === Symbol.toStringTag ? n[Symbol.toStringTag] : t === Le ? r : t === qn ? true : t === Fe ? n.trace : t === fe ? {
        handle: e
      } : t === "length" ? e.length(r) : typeof t == "number" ? Ut(n, t) : zf(n)[t] || ns(n)[t];
    },
    getPrototypeOf() {
      return Object.getPrototypeOf(new de());
    }
  });
  function Je(n, t, e, r) {
    const s = {
      context: n,
      objectId: t,
      path: r || [],
      cache: {},
      textV2: e
    }, o = {};
    return Object.assign(o, s), new Proxy(o, Ff);
  }
  function pn(n, t, e, r) {
    const s = {
      context: n,
      objectId: t,
      path: r || [],
      cache: {},
      textV2: e
    }, o = [];
    return Object.assign(o, s), new Proxy(o, la);
  }
  function _n(n, t, e) {
    const r = {
      context: n,
      objectId: t,
      path: e || [],
      cache: {},
      textV2: false
    }, s = {};
    return Object.assign(s, r), new Proxy(s, Lf);
  }
  function Vf(n, t) {
    return Je(n, "_root", t, []);
  }
  function ns(n) {
    const { context: t, objectId: e, path: r, textV2: s } = n;
    return {
      at(i) {
        return Ut(n, i);
      },
      deleteAt(i, a) {
        return typeof a == "number" ? t.splice(e, i, a) : t.delete(e, i), this;
      },
      fill(i, a, c) {
        const [f, u] = Fn(i, s, [
          ...r,
          a
        ], t), _ = t.length(e);
        a = te(a || 0), c = te(c || _);
        for (let d = a; d < Math.min(c, _); d++)
          if (u === "list" || u === "map")
            t.putObject(e, d, f);
          else if (u === "text")
            if (s)
              Ln(f), t.putObject(e, d, f);
            else {
              rs(f);
              const l = t.putObject(e, d, ""), w = _n(t, l, [
                ...r,
                d
              ]);
              for (let k = 0; k < f.length; k++)
                w[k] = f.get(k);
            }
          else
            t.put(e, d, f, u);
        return this;
      },
      indexOf(i, a = 0) {
        const c = t.length(e);
        for (let f = a; f < c; f++) {
          const u = t.getWithType(e, f);
          if (u && (u[1] === i[Le] || u[1] === i))
            return f;
        }
        return -1;
      },
      insertAt(i, ...a) {
        return this.splice(i, 0, ...a), this;
      },
      pop() {
        const i = t.length(e);
        if (i == 0)
          return;
        const a = Ut(n, i - 1);
        return t.delete(e, i - 1), a;
      },
      push(...i) {
        const a = t.length(e);
        return this.splice(a, 0, ...i), t.length(e);
      },
      shift() {
        if (t.length(e) == 0)
          return;
        const i = Ut(n, 0);
        return t.delete(e, 0), i;
      },
      splice(i, a, ...c) {
        i = te(i), typeof a != "number" && (a = t.length(e) - i), a = te(a);
        for (const _ of c)
          if (Yn(_, t))
            throw new RangeError("Cannot create a reference to an existing document object");
        const f = [];
        for (let _ = 0; _ < a; _++) {
          const d = Ut(n, i);
          d !== void 0 && f.push(d), t.delete(e, i);
        }
        const u = c.map((_, d) => {
          try {
            return Fn(_, s, [
              ...r
            ], t);
          } catch (l) {
            throw l instanceof RangeError ? new RangeError(`${l.message} (at index ${d} in the input)`) : l;
          }
        });
        for (const [_, d] of u) {
          switch (d) {
            case "list": {
              const l = t.insertObject(e, i, []);
              pn(t, l, s, [
                ...r,
                i
              ]).splice(0, 0, ..._);
              break;
            }
            case "text": {
              if (s)
                Ln(_), t.insertObject(e, i, _);
              else {
                const l = t.insertObject(e, i, "");
                _n(t, l, [
                  ...r,
                  i
                ]).splice(0, 0, ..._);
              }
              break;
            }
            case "map": {
              const l = t.insertObject(e, i, {}), w = Je(t, l, s, [
                ...r,
                i
              ]);
              for (const k in _)
                w[k] = _[k];
              break;
            }
            default:
              t.insert(e, i, _, d);
          }
          i += 1;
        }
        return f;
      },
      unshift(...i) {
        return this.splice(0, 0, ...i), t.length(e);
      },
      entries() {
        let i = 0;
        return {
          next: () => {
            const c = Ut(n, i);
            return c === void 0 ? {
              value: void 0,
              done: true
            } : {
              value: [
                i++,
                c
              ],
              done: false
            };
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      keys() {
        let i = 0;
        const a = t.length(e);
        return {
          next: () => i < a ? {
            value: i++,
            done: false
          } : {
            value: void 0,
            done: true
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      values() {
        let i = 0;
        return {
          next: () => {
            const c = Ut(n, i++);
            return c === void 0 ? {
              value: void 0,
              done: true
            } : {
              value: c,
              done: false
            };
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      toArray() {
        const i = [];
        let a;
        do
          a = Ut(n, i.length), a !== void 0 && i.push(a);
        while (a !== void 0);
        return i;
      },
      map(i) {
        return this.toArray().map(i);
      },
      toString() {
        return this.toArray().toString();
      },
      toLocaleString() {
        return this.toArray().toLocaleString();
      },
      forEach(i) {
        return this.toArray().forEach(i);
      },
      concat(i) {
        return this.toArray().concat(i);
      },
      every(i) {
        return this.toArray().every(i);
      },
      filter(i) {
        return this.toArray().filter(i);
      },
      find(i) {
        let a = 0;
        for (const c of this) {
          if (i(c, a))
            return c;
          a += 1;
        }
      },
      findIndex(i) {
        let a = 0;
        for (const c of this) {
          if (i(c, a))
            return a;
          a += 1;
        }
        return -1;
      },
      includes(i) {
        return this.find((a) => a === i) !== void 0;
      },
      join(i) {
        return this.toArray().join(i);
      },
      reduce(i, a) {
        return this.toArray().reduce(i, a);
      },
      reduceRight(i, a) {
        return this.toArray().reduceRight(i, a);
      },
      lastIndexOf(i, a = 1 / 0) {
        return this.toArray().lastIndexOf(i, a);
      },
      slice(i, a) {
        return this.toArray().slice(i, a);
      },
      some(i) {
        let a = 0;
        for (const c of this) {
          if (i(c, a))
            return true;
          a += 1;
        }
        return false;
      },
      [Symbol.iterator]: function* () {
        let i = 0, a = Ut(n, i);
        for (; a !== void 0; )
          yield a, i += 1, a = Ut(n, i);
      }
    };
  }
  function zf(n) {
    const { context: t, objectId: e } = n;
    return {
      set(s, o) {
        return this[s] = o;
      },
      get(s) {
        return this[s];
      },
      toString() {
        return t.text(e).replace(/￼/g, "");
      },
      toSpans() {
        const s = [];
        let o = "";
        const i = t.length(e);
        for (let a = 0; a < i; a++) {
          const c = this[a];
          typeof c == "string" ? o += c : (o.length > 0 && (s.push(o), o = ""), s.push(c));
        }
        return o.length > 0 && s.push(o), s;
      },
      toJSON() {
        return this.toString();
      },
      indexOf(s, o = 0) {
        return t.text(e).indexOf(s, o);
      },
      insertAt(s, ...o) {
        o.every((i) => typeof i == "string") ? t.splice(e, s, 0, o.join("")) : ns(n).insertAt(s, ...o);
      }
    };
  }
  function rs(n) {
    if (!os(n))
      throw new Error("value was not a Text instance");
  }
  function Ln(n) {
    if (typeof n != "string")
      throw new Error("value was not a string");
  }
  function to(n) {
    const t = n.map((e) => {
      if (typeof e == "number")
        return e.toString();
      if (typeof e == "string")
        return e.replace(/~/g, "~0").replace(/\//g, "~1");
    });
    return n.length === 0 ? "" : "/" + t.join("/");
  }
  function ss(n) {
    return typeof n == "object" && n !== null && Object.prototype.hasOwnProperty.call(n, fa);
  }
  function os(n) {
    return typeof n == "object" && n !== null && Object.prototype.hasOwnProperty.call(n, xr);
  }
  class ha {
    constructor(t) {
      if (!(Number.isInteger(t) && t <= Number.MAX_SAFE_INTEGER && t >= Number.MIN_SAFE_INTEGER))
        throw new RangeError(`Value ${t} cannot be a uint`);
      this.value = t, Reflect.defineProperty(this, ca, {
        value: true
      }), Object.freeze(this);
    }
  }
  class ga {
    constructor(t) {
      if (!(Number.isInteger(t) && t <= Number.MAX_SAFE_INTEGER && t >= 0))
        throw new RangeError(`Value ${t} cannot be a uint`);
      this.value = t, Reflect.defineProperty(this, aa, {
        value: true
      }), Object.freeze(this);
    }
  }
  class ba {
    constructor(t) {
      if (typeof t != "number")
        throw new RangeError(`Value ${t} cannot be a float64`);
      this.value = t || 0, Reflect.defineProperty(this, _a, {
        value: true
      }), Object.freeze(this);
    }
  }
  function Q(n, t = true) {
    if (typeof n != "object")
      throw new RangeError("must be the document root");
    const e = Reflect.get(n, fe);
    if (e === void 0 || e == null || t && ze(n) !== "_root")
      throw new RangeError("must be the document root");
    return e;
  }
  function Ge(n) {
    Reflect.set(n, ts, true);
  }
  function is(n) {
    return Reflect.get(n, Fe);
  }
  function ze(n) {
    return typeof n != "object" || n === null ? null : Reflect.get(n, Le);
  }
  function kt(n) {
    return !!Reflect.get(n, qn);
  }
  function Nf(n, t, e) {
    return pa(n, t, e, true, (r, s) => new de(r.text(s)));
  }
  function Wf(n, t, e) {
    return pa(n, t, e, true, (r, s) => r.text(s));
  }
  function pa(n, t, e, r, s) {
    const o = n.getAll(t, e);
    if (o.length <= 1)
      return;
    const i = {};
    for (const a of o)
      switch (a[0]) {
        case "map":
          i[a[1]] = Je(n, a[1], r, [
            e
          ]);
          break;
        case "list":
          i[a[1]] = pn(n, a[1], r, [
            e
          ]);
          break;
        case "text":
          i[a[1]] = s(n, a[1]);
          break;
        case "str":
        case "uint":
        case "int":
        case "f64":
        case "boolean":
        case "bytes":
        case "null":
          i[a[2]] = a[1];
          break;
        case "counter":
          i[a[2]] = new Ve(a[1]);
          break;
        case "timestamp":
          i[a[2]] = new Date(a[1]);
          break;
        default:
          throw RangeError(`datatype ${a[0]} unimplemented`);
      }
    return i;
  }
  var Kf = globalThis && globalThis.__rest || function(n, t) {
    var e = {};
    for (var r in n)
      Object.prototype.hasOwnProperty.call(n, r) && t.indexOf(r) < 0 && (e[r] = n[r]);
    if (n != null && typeof Object.getOwnPropertySymbols == "function")
      for (var s = 0, r = Object.getOwnPropertySymbols(n); s < r.length; s++)
        t.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(n, r[s]) && (e[r[s]] = n[r[s]]);
    return e;
  };
  function wa(n, t, ...e) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    n.insertAt(t, ...e);
  }
  function ya(n, t, e) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    n.deleteAt(t, e);
  }
  Jf = function(n) {
    Gr(n);
  };
  function ma(n) {
    return Q(n).handle;
  }
  function as(n) {
    return typeof n == "object" ? n : {
      actor: n
    };
  }
  function wn(n) {
    const t = as(n), e = !!t.freeze, r = t.patchCallback, s = !t.enableTextV2, o = t.actor, i = vt.create({
      actor: o,
      text_v1: s
    });
    i.enableFreeze(!!t.freeze);
    const a = t.enableTextV2 || false;
    return Pa(i, a), i.materialize("/", void 0, {
      handle: i,
      heads: void 0,
      freeze: e,
      patchCallback: r,
      textV2: a
    });
  }
  function va(n, t) {
    const e = Q(n), r = e.handle;
    return e.handle.materialize("/", t, Object.assign(Object.assign({}, e), {
      handle: r,
      heads: t
    }));
  }
  function Sa(n, t) {
    const e = Q(n), r = e.heads, s = as(t), o = e.handle.fork(s.actor, r);
    o.updateDiffCursor();
    const i = Kf(e, [
      "heads"
    ]);
    return i.patchCallback = s.patchCallback, o.applyPatches(n, Object.assign(Object.assign({}, i), {
      handle: o
    }));
  }
  function xa(n) {
    return Q(n).handle.free();
  }
  function Ia(n, t) {
    return un(wn(t), "from", {}, (e) => Object.assign(e, n)).newDoc;
  }
  function cs(n, t, e) {
    if (typeof t == "function")
      return un(n, "change", {}, t).newDoc;
    if (typeof e == "function")
      return typeof t == "string" && (t = {
        message: t
      }), un(n, "change", t, e).newDoc;
    throw RangeError("Invalid args for change");
  }
  function _s(n, t, e, r) {
    if (typeof e == "function")
      return un(n, "changeAt", {}, e, t);
    if (typeof r == "function")
      return typeof e == "string" && (e = {
        message: e
      }), un(n, "changeAt", e, r, t);
    throw RangeError("Invalid args for changeAt");
  }
  function qe(n, t, e, r) {
    if (e == null)
      return n;
    const s = Q(n), o = Object.assign(Object.assign({}, s), {
      heads: void 0
    }), { value: i, patches: a } = s.handle.applyAndReturnPatches(n, o);
    if (a.length > 0) {
      r == null ? void 0 : r(a, {
        before: n,
        after: i,
        source: t
      });
      const c = Q(i);
      c.mostRecentPatch = {
        before: Q(n).heads,
        after: c.handle.getHeads(),
        patches: a
      };
    }
    return s.heads = e, i;
  }
  function un(n, t, e, r, s) {
    if (typeof r != "function")
      throw new RangeError("invalid change function");
    const o = Q(n);
    if (n === void 0 || o === void 0)
      throw new RangeError("must be the document root");
    if (o.heads)
      throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    let i = o.handle.getHeads();
    s && qf(s, i) && (s = void 0), s && (o.handle.isolate(s), i = s), "time" in e || (e.time = Math.floor(Date.now() / 1e3));
    try {
      o.heads = i;
      const a = Vf(o.handle, o.textV2);
      if (r(a), o.handle.pendingOps() === 0)
        return o.heads = void 0, s && o.handle.integrate(), {
          newDoc: n,
          newHeads: null
        };
      {
        const c = o.handle.commit(e.message, e.time);
        return o.handle.integrate(), {
          newDoc: qe(n, t, i, e.patchCallback || o.patchCallback),
          newHeads: c != null ? [
            c
          ] : null
        };
      }
    } catch (a) {
      throw o.heads = void 0, o.handle.rollback(), a;
    }
  }
  function us(n, t) {
    t === void 0 && (t = {}), typeof t == "string" && (t = {
      message: t
    }), "time" in t || (t.time = Math.floor(Date.now() / 1e3));
    const e = Q(n);
    if (e.heads)
      throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    const r = e.handle.getHeads();
    return e.handle.emptyChange(t.message, t.time), qe(n, "emptyChange", r);
  }
  function ka(n, t) {
    const e = as(t), r = e.actor, s = e.patchCallback, o = !e.enableTextV2, i = e.unchecked || false, a = e.allowMissingChanges || false, c = e.convertRawStringsToText || false, f = vt.load(n, {
      text_v1: o,
      actor: r,
      unchecked: i,
      allowMissingDeps: a,
      convertRawStringsToText: c
    });
    f.enableFreeze(!!e.freeze);
    const u = e.enableTextV2 || false;
    return Pa(f, u), f.materialize("/", void 0, {
      handle: f,
      heads: void 0,
      patchCallback: s,
      textV2: u
    });
  }
  function Xn(n, t, e) {
    e || (e = {});
    const r = Q(n);
    if (r.heads)
      throw new RangeError("Attempting to change an out of date document - set at: " + is(n));
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    const s = r.handle.getHeads();
    return r.handle.loadIncremental(t), qe(n, "loadIncremental", s, e.patchCallback || r.patchCallback);
  }
  function Aa(n) {
    const t = Q(n);
    if (t.heads)
      throw new RangeError("Attempting to change an out of date document - set at: " + is(n));
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    return t.handle.saveIncremental();
  }
  Zn = function(n) {
    return Q(n).handle.save();
  };
  function fs(n, t) {
    const e = Q(n);
    if (e.heads)
      throw new RangeError("Attempting to change an out of date document - set at: " + is(n));
    const r = e.handle.getHeads(), s = Q(t), o = e.handle.getChangesAdded(s.handle);
    return e.handle.applyChanges(o), qe(n, "merge", r, e.patchCallback);
  }
  function Ea(n) {
    return Q(n).handle.getActorId();
  }
  function Gf(n, t) {
    const e = Q(n, false);
    if (e.textV2)
      throw new Error("use unstable.getConflicts for an unstable document");
    const r = ze(n);
    if (r != null)
      return Nf(e.handle, r, t);
  }
  function Ca(n) {
    return Q(n).handle.getLastLocalChange() || void 0;
  }
  function ds(n, t) {
    if (t) {
      const e = Q(n, false), r = ze(n);
      return !e || !r ? null : e.handle.get(r, t);
    } else
      return ze(n);
  }
  function Oa(n, t) {
    return Q(t).handle.getChanges(Tt(n));
  }
  function ls(n) {
    return Q(n).handle.getChanges([]);
  }
  function hs(n, t, e) {
    const r = Q(n);
    if (e || (e = {}), r.heads)
      throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    const s = r.handle.getHeads();
    return r.handle.applyChanges(t), r.heads = s, [
      qe(n, "applyChanges", s, e.patchCallback || r.patchCallback)
    ];
  }
  function ja(n) {
    const t = Q(n).textV2, e = ls(n);
    return e.map((r, s) => ({
      get change() {
        return ys(r);
      },
      get snapshot() {
        const [o] = hs(wn({
          enableTextV2: t
        }), e.slice(0, s + 1));
        return o;
      }
    }));
  }
  gs = function(n, t, e) {
    eo(t, "before"), eo(e, "after");
    const r = Q(n);
    return r.mostRecentPatch && fn(r.mostRecentPatch.before, t) && fn(r.mostRecentPatch.after, e) ? r.mostRecentPatch.patches : r.handle.diff(t, e);
  };
  function qf(n, t) {
    if (n.length !== t.length)
      return false;
    for (let e = 0; e < n.length; e++)
      if (n[e] !== t[e])
        return false;
    return true;
  }
  function eo(n, t) {
    if (!Array.isArray(n))
      throw new Error(`${t} must be an array`);
  }
  fn = function(n, t) {
    if (!no(n) || !no(t))
      return n === t;
    const e = Object.keys(n).sort(), r = Object.keys(t).sort();
    if (e.length !== r.length)
      return false;
    for (let s = 0; s < e.length; s++)
      if (e[s] !== r[s] || !fn(n[e[s]], t[r[s]]))
        return false;
    return true;
  };
  function Qn(n) {
    const t = vt.importSyncState(n), e = vt.encodeSyncState(t);
    return t.free(), e;
  }
  function tr(n) {
    const t = vt.decodeSyncState(n), e = vt.exportSyncState(t);
    return t.free(), e;
  }
  function bs(n, t) {
    const e = Q(n), r = vt.importSyncState(t), s = e.handle.generateSyncMessage(r);
    return [
      vt.exportSyncState(r),
      s
    ];
  }
  function ps(n, t, e, r) {
    const s = vt.importSyncState(t);
    r || (r = {});
    const o = Q(n);
    if (o.heads)
      throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (kt(n))
      throw new RangeError("Calls to Automerge.change cannot be nested");
    const i = o.handle.getHeads();
    o.handle.receiveSyncMessage(s, e);
    const a = vt.exportSyncState(s);
    return [
      qe(n, "receiveSyncMessage", i, r.patchCallback || o.patchCallback),
      a,
      null
    ];
  }
  function Ra(n, t) {
    const e = Q(n), r = vt.importSyncState(t);
    return e.handle.hasOurChanges(r);
  }
  function ws() {
    return vt.exportSyncState(vt.initSyncState());
  }
  function Ta(n) {
    return vt.encodeChange(n);
  }
  function ys(n) {
    return vt.decodeChange(n);
  }
  function Ma(n) {
    return vt.encodeSyncMessage(n);
  }
  function ms(n) {
    return vt.decodeSyncMessage(n);
  }
  function Ha(n, t) {
    return Q(n).handle.getMissingDeps(t);
  }
  Tt = function(n) {
    const t = Q(n);
    return t.heads || t.handle.getHeads();
  };
  function Da(n) {
    Q(n).handle.dump();
  }
  function $a(n) {
    const t = Q(n), e = t.handle.enableFreeze(false), r = t.handle.materialize("/", t.heads);
    return t.handle.enableFreeze(e), r;
  }
  function Ua(n) {
    return typeof n == "object" && n !== null ? ds(n) === "_root" && !!Reflect.get(n, fe) : false;
  }
  function no(n) {
    return typeof n == "object" && n !== null;
  }
  function vs(n, t) {
    return Q(n).handle.saveSince(t);
  }
  function Ba(n, t) {
    const e = Q(n);
    for (const r of t)
      if (!e.handle.getChangeByHash(r))
        return false;
    return true;
  }
  function Pa(n, t) {
    n.registerDatatype("counter", (e) => new Ve(e), (e) => {
      if (e instanceof Ve)
        return e.value;
    }), t ? n.registerDatatype("str", (e) => new es(e), (e) => {
      if (ss(e))
        return e.val;
    }) : n.registerDatatype("text", (e) => new de(e), (e) => {
      if (e instanceof de)
        return e.join("");
    });
  }
  function Fa(n) {
    return Q(n).handle.topoHistoryTraversal();
  }
  function La(n, t) {
    return Q(n).handle.getDecodedChangeByHash(t);
  }
  function Va(n) {
    return Q(n).handle.stats();
  }
  const Yf = ma;
  function yn(n) {
    const t = er(n);
    return t.enableTextV2 = true, wn(t);
  }
  function Ir(n, t) {
    const e = er(t);
    return e.enableTextV2 = true, Sa(n, e);
  }
  function za(n, t) {
    const e = er(t);
    return e.enableTextV2 = true, Ia(n, e);
  }
  function Na(n, t) {
    const e = er(t);
    return e.enableTextV2 = true, e.patchCallback ? Xn(wn(e), n) : ka(n, e);
  }
  function er(n) {
    return typeof n == "object" ? n : {
      actor: n
    };
  }
  function mn(n, t, e) {
    if (typeof e == "string") {
      if (/^-?[0-9]+@[0-9a-zA-Z]+$|^[se]$/.test(e))
        return n.handle.getCursorPosition(t, e);
      throw new RangeError("index must be a number or cursor");
    } else
      return e;
  }
  Xf = function(n, t, e, r, s) {
    const o = Ht(n, t, "splice");
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const i = Q(n, false);
    Ge(n), e = mn(i, o, e);
    try {
      return i.handle.splice(o, e, r, s);
    } catch (a) {
      throw new RangeError(`Cannot splice: ${a}`);
    }
  };
  function Zf(n, t, e) {
    const r = Ht(n, t, "updateText");
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const s = Q(n, false);
    Ge(n);
    try {
      return s.handle.updateText(r, e);
    } catch (o) {
      throw new RangeError(`Cannot updateText: ${o}`);
    }
  }
  function Qf(n, t) {
    const e = Q(n, false), r = Ht(n, t, "spans");
    try {
      return e.handle.spans(r, e.heads);
    } catch (s) {
      throw new RangeError(`Cannot splice: ${s}`);
    }
  }
  function td(n, t, e) {
    const r = Ht(n, t, "splitBlock"), s = Q(n, false);
    e = mn(s, r, e);
    try {
      return s.handle.getBlock(r, e);
    } catch (o) {
      throw new RangeError(`Cannot get block: ${o}`);
    }
  }
  function ed(n, t, e, r) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const s = Ht(n, t, "splitBlock"), o = Q(n, false);
    Ge(n), e = mn(o, s, e);
    try {
      o.handle.splitBlock(s, e, r);
    } catch (i) {
      throw new RangeError(`Cannot splice: ${i}`);
    }
  }
  function nd(n, t, e) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const r = Ht(n, t, "joinBlock"), s = Q(n, false);
    Ge(n), e = mn(s, r, e);
    try {
      s.handle.joinBlock(r, e);
    } catch (o) {
      throw new RangeError(`Cannot joinBlock: ${o}`);
    }
  }
  function rd(n, t, e, r) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const s = Ht(n, t, "updateBlock"), o = Q(n, false);
    Ge(n), e = mn(o, s, e);
    try {
      o.handle.updateBlock(s, e, r);
    } catch (i) {
      throw new RangeError(`Cannot updateBlock: ${i}`);
    }
  }
  function sd(n, t, e) {
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const r = Ht(n, t, "updateSpans"), s = Q(n, false);
    Ge(n);
    try {
      s.handle.updateSpans(r, e);
    } catch (o) {
      throw new RangeError(`Cannot updateBlock: ${o}`);
    }
  }
  od = function(n, t, e, r) {
    const s = Ht(n, t, "getCursor"), o = Q(n, false);
    try {
      return o.handle.getCursor(s, e, o.heads, r);
    } catch (i) {
      throw new RangeError(`Cannot getCursor: ${i}`);
    }
  };
  id = function(n, t, e) {
    const r = Ht(n, t, "getCursorPosition"), s = Q(n, false);
    try {
      return s.handle.getCursorPosition(r, e, s.heads);
    } catch (o) {
      throw new RangeError(`Cannot getCursorPosition: ${o}`);
    }
  };
  function ad(n, t, e, r, s) {
    const o = Ht(n, t, "mark");
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const i = Q(n, false);
    try {
      return i.handle.mark(o, e, r, s);
    } catch (a) {
      throw new RangeError(`Cannot mark: ${a}`);
    }
  }
  function cd(n, t, e, r) {
    const s = Ht(n, t, "unmark");
    if (!kt(n))
      throw new RangeError("object cannot be modified outside of a change block");
    const o = Q(n, false);
    try {
      return o.handle.unmark(s, e, r);
    } catch (i) {
      throw new RangeError(`Cannot unmark: ${i}`);
    }
  }
  function _d(n, t) {
    const e = Ht(n, t, "marks"), r = Q(n, false);
    try {
      return r.handle.marks(e);
    } catch (s) {
      throw new RangeError(`Cannot call marks(): ${s}`);
    }
  }
  function ud(n, t, e) {
    const r = Ht(n, t, "marksAt"), s = Q(n, false);
    try {
      return s.handle.marksAt(r, e);
    } catch (o) {
      throw new RangeError(`Cannot call marksAt(): ${o}`);
    }
  }
  function fd(n, t) {
    const e = Q(n, false);
    if (!e.textV2)
      throw new Error("use getConflicts for a stable document");
    const r = ze(n);
    if (r != null)
      return Wf(e.handle, r, t);
  }
  function Ht(n, t, e) {
    t = t.slice();
    const r = ze(n);
    if (!r)
      throw new RangeError(`invalid object for ${e}`);
    return t.unshift(r), t.join("/");
  }
  dd = Object.freeze(Object.defineProperty({
    __proto__: null,
    Counter: Ve,
    Float64: ba,
    Int: ha,
    RawString: es,
    Uint: ga,
    applyChanges: hs,
    block: td,
    change: cs,
    changeAt: _s,
    clone: Ir,
    decodeChange: ys,
    decodeSyncMessage: ms,
    decodeSyncState: tr,
    deleteAt: ya,
    diff: gs,
    dump: Da,
    emptyChange: us,
    encodeChange: Ta,
    encodeSyncMessage: Ma,
    encodeSyncState: Qn,
    equals: fn,
    free: xa,
    from: za,
    generateSyncMessage: bs,
    getActorId: Ea,
    getAllChanges: ls,
    getBackend: Yf,
    getChanges: Oa,
    getConflicts: fd,
    getCursor: od,
    getCursorPosition: id,
    getHeads: Tt,
    getHistory: ja,
    getLastLocalChange: Ca,
    getMissingDeps: Ha,
    getObjectId: ds,
    hasHeads: Ba,
    hasOurChanges: Ra,
    init: yn,
    initSyncState: ws,
    initializeBase64Wasm: Ho,
    initializeWasm: qr,
    insertAt: wa,
    inspectChange: La,
    isAutomerge: Ua,
    isRawString: ss,
    isWasmInitialized: $o,
    joinBlock: nd,
    load: Na,
    loadIncremental: Xn,
    mark: ad,
    marks: _d,
    marksAt: ud,
    merge: fs,
    receiveSyncMessage: ps,
    save: Zn,
    saveIncremental: Aa,
    saveSince: vs,
    spans: Qf,
    splice: Xf,
    splitBlock: ed,
    stats: Va,
    toJS: $a,
    topoHistoryTraversal: Fa,
    unmark: cd,
    updateBlock: rd,
    updateSpans: sd,
    updateText: Zf,
    view: va,
    wasmInitialized: Do
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  Gr(Rf);
  let ld;
  wg = Object.freeze(Object.defineProperty({
    __proto__: null,
    Counter: Ve,
    Float64: ba,
    Int: ha,
    Text: de,
    Uint: ga,
    applyChanges: hs,
    change: cs,
    changeAt: _s,
    clone: Sa,
    decodeChange: ys,
    decodeSyncMessage: ms,
    decodeSyncState: tr,
    deleteAt: ya,
    diff: gs,
    dump: Da,
    emptyChange: us,
    encodeChange: Ta,
    encodeSyncMessage: Ma,
    encodeSyncState: Qn,
    equals: fn,
    free: xa,
    from: Ia,
    generateSyncMessage: bs,
    getActorId: Ea,
    getAllChanges: ls,
    getBackend: ma,
    getChanges: Oa,
    getConflicts: Gf,
    getHeads: Tt,
    getHistory: ja,
    getLastLocalChange: Ca,
    getMissingDeps: Ha,
    getObjectId: ds,
    hasHeads: Ba,
    hasOurChanges: Ra,
    init: wn,
    initSyncState: ws,
    initializeBase64Wasm: Ho,
    initializeWasm: qr,
    insertAt: wa,
    inspectChange: La,
    isAutomerge: Ua,
    isText: os,
    isWasmInitialized: $o,
    load: ka,
    loadIncremental: Xn,
    merge: fs,
    next: dd,
    receiveSyncMessage: ps,
    save: Zn,
    saveIncremental: Aa,
    saveSince: vs,
    stats: Va,
    toJS: $a,
    topoHistoryTraversal: Fa,
    use: Jf,
    uuid: Qr,
    view: va,
    wasmInitialized: Do
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  ld = "" + new URL("automerge_wasm_bg-985dc515.wasm", import.meta.url).href;
  let b;
  const ae = new Array(128).fill(void 0);
  ae.push(void 0, null, true, false);
  function F(n) {
    return ae[n];
  }
  let cn = ae.length;
  function hd(n) {
    n < 132 || (ae[n] = cn, cn = n);
  }
  function U(n) {
    const t = F(n);
    return hd(n), t;
  }
  let Wt = 0, Qe = null;
  function Hn() {
    return (Qe === null || Qe.byteLength === 0) && (Qe = new Uint8Array(b.memory.buffer)), Qe;
  }
  const Dn = typeof TextEncoder < "u" ? new TextEncoder("utf-8") : {
    encode: () => {
      throw Error("TextEncoder not available");
    }
  }, gd = typeof Dn.encodeInto == "function" ? function(n, t) {
    return Dn.encodeInto(n, t);
  } : function(n, t) {
    const e = Dn.encode(n);
    return t.set(e), {
      read: n.length,
      written: e.length
    };
  };
  function ee(n, t, e) {
    if (e === void 0) {
      const a = Dn.encode(n), c = t(a.length, 1) >>> 0;
      return Hn().subarray(c, c + a.length).set(a), Wt = a.length, c;
    }
    let r = n.length, s = t(r, 1) >>> 0;
    const o = Hn();
    let i = 0;
    for (; i < r; i++) {
      const a = n.charCodeAt(i);
      if (a > 127)
        break;
      o[s + i] = a;
    }
    if (i !== r) {
      i !== 0 && (n = n.slice(i)), s = e(s, r, r = i + n.length * 3, 1) >>> 0;
      const a = Hn().subarray(s + i, s + r), c = gd(n, a);
      i += c.written;
    }
    return Wt = i, s;
  }
  function lt(n) {
    return n == null;
  }
  let tn = null;
  function I() {
    return (tn === null || tn.byteLength === 0) && (tn = new Int32Array(b.memory.buffer)), tn;
  }
  const Wa = typeof TextDecoder < "u" ? new TextDecoder("utf-8", {
    ignoreBOM: true,
    fatal: true
  }) : {
    decode: () => {
      throw Error("TextDecoder not available");
    }
  };
  typeof TextDecoder < "u" && Wa.decode();
  function Bt(n, t) {
    return n = n >>> 0, Wa.decode(Hn().subarray(n, n + t));
  }
  function C(n) {
    cn === ae.length && ae.push(ae.length + 1);
    const t = cn;
    return cn = ae[t], ae[t] = n, t;
  }
  let en = null;
  function $n() {
    return (en === null || en.byteLength === 0) && (en = new Float64Array(b.memory.buffer)), en;
  }
  function kr(n) {
    const t = typeof n;
    if (t == "number" || t == "boolean" || n == null)
      return `${n}`;
    if (t == "string")
      return `"${n}"`;
    if (t == "symbol") {
      const s = n.description;
      return s == null ? "Symbol" : `Symbol(${s})`;
    }
    if (t == "function") {
      const s = n.name;
      return typeof s == "string" && s.length > 0 ? `Function(${s})` : "Function";
    }
    if (Array.isArray(n)) {
      const s = n.length;
      let o = "[";
      s > 0 && (o += kr(n[0]));
      for (let i = 1; i < s; i++)
        o += ", " + kr(n[i]);
      return o += "]", o;
    }
    const e = /\[object ([^\]]+)\]/.exec(toString.call(n));
    let r;
    if (e.length > 1)
      r = e[1];
    else
      return toString.call(n);
    if (r == "Object")
      try {
        return "Object(" + JSON.stringify(n) + ")";
      } catch {
        return "Object";
      }
    return n instanceof Error ? `${n.name}: ${n.message}
${n.stack}` : r;
  }
  function Ue(n, t) {
    if (!(n instanceof t))
      throw new Error(`expected instance of ${t.name}`);
    return n.ptr;
  }
  function bd(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.create(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return Xt.__wrap(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function pd(n, t) {
    try {
      const o = b.__wbindgen_add_to_stack_pointer(-16);
      b.load(o, C(n), C(t));
      var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
      if (s)
        throw U(r);
      return Xt.__wrap(e);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function wd(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.encodeChange(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return U(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function yd(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.decodeChange(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return U(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function md() {
    const n = b.initSyncState();
    return Kt.__wrap(n);
  }
  function vd(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.importSyncState(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return Kt.__wrap(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function Sd(n) {
    Ue(n, Kt);
    const t = b.exportSyncState(n.__wbg_ptr);
    return U(t);
  }
  function xd(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.encodeSyncMessage(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return U(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function Id(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.decodeSyncMessage(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return U(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function kd(n) {
    Ue(n, Kt);
    const t = b.encodeSyncState(n.__wbg_ptr);
    return U(t);
  }
  function Ad(n) {
    try {
      const s = b.__wbindgen_add_to_stack_pointer(-16);
      b.decodeSyncState(s, C(n));
      var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
      if (r)
        throw U(e);
      return Kt.__wrap(t);
    } finally {
      b.__wbindgen_add_to_stack_pointer(16);
    }
  }
  function Et(n, t) {
    try {
      return n.apply(this, t);
    } catch (e) {
      b.__wbindgen_exn_store(C(e));
    }
  }
  const Ed = Object.freeze({
    Array: 0,
    0: "Array",
    String: 1,
    1: "String"
  }), ro = new FinalizationRegistry((n) => b.__wbg_automerge_free(n >>> 0));
  class Xt {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(Xt.prototype);
      return e.__wbg_ptr = t, ro.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, ro.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      b.__wbg_automerge_free(t);
    }
    static new(t, e) {
      try {
        const c = b.__wbindgen_add_to_stack_pointer(-16);
        var r = lt(t) ? 0 : ee(t, b.__wbindgen_malloc, b.__wbindgen_realloc), s = Wt;
        b.automerge_new(c, r, s, e);
        var o = I()[c / 4 + 0], i = I()[c / 4 + 1], a = I()[c / 4 + 2];
        if (a)
          throw U(i);
        return Xt.__wrap(o);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone(t) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        var e = lt(t) ? 0 : ee(t, b.__wbindgen_malloc, b.__wbindgen_realloc), r = Wt;
        b.automerge_clone(a, this.__wbg_ptr, e, r);
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return Xt.__wrap(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    fork(t, e) {
      try {
        const c = b.__wbindgen_add_to_stack_pointer(-16);
        var r = lt(t) ? 0 : ee(t, b.__wbindgen_malloc, b.__wbindgen_realloc), s = Wt;
        b.automerge_fork(c, this.__wbg_ptr, r, s, C(e));
        var o = I()[c / 4 + 0], i = I()[c / 4 + 1], a = I()[c / 4 + 2];
        if (a)
          throw U(i);
        return Xt.__wrap(o);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pendingOps() {
      const t = b.automerge_pendingOps(this.__wbg_ptr);
      return U(t);
    }
    commit(t, e) {
      var r = lt(t) ? 0 : ee(t, b.__wbindgen_malloc, b.__wbindgen_realloc), s = Wt;
      const o = b.automerge_commit(this.__wbg_ptr, r, s, !lt(e), lt(e) ? 0 : e);
      return U(o);
    }
    merge(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        Ue(t, Xt), b.automerge_merge(o, this.__wbg_ptr, t.__wbg_ptr);
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    rollback() {
      return b.automerge_rollback(this.__wbg_ptr);
    }
    keys(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_keys(i, this.__wbg_ptr, C(t), lt(e) ? 0 : C(e));
        var r = I()[i / 4 + 0], s = I()[i / 4 + 1], o = I()[i / 4 + 2];
        if (o)
          throw U(s);
        return U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    text(t, e) {
      let r, s;
      try {
        const _ = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_text(_, this.__wbg_ptr, C(t), lt(e) ? 0 : C(e));
        var o = I()[_ / 4 + 0], i = I()[_ / 4 + 1], a = I()[_ / 4 + 2], c = I()[_ / 4 + 3], f = o, u = i;
        if (c)
          throw f = 0, u = 0, U(a);
        return r = f, s = u, Bt(f, u);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16), b.__wbindgen_free(r, s, 1);
      }
    }
    splice(t, e, r, s) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_splice(a, this.__wbg_ptr, C(t), e, r, C(s));
        var o = I()[a / 4 + 0], i = I()[a / 4 + 1];
        if (i)
          throw U(o);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    push(t, e, r) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_push(i, this.__wbg_ptr, C(t), C(e), C(r));
        var s = I()[i / 4 + 0], o = I()[i / 4 + 1];
        if (o)
          throw U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    pushObject(t, e) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_pushObject(a, this.__wbg_ptr, C(t), C(e));
        var r = I()[a / 4 + 0], s = I()[a / 4 + 1], o = I()[a / 4 + 2], i = I()[a / 4 + 3];
        if (i)
          throw U(o);
        let c;
        return r !== 0 && (c = Bt(r, s).slice(), b.__wbindgen_free(r, s * 1, 1)), c;
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insert(t, e, r, s) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_insert(a, this.__wbg_ptr, C(t), e, C(r), C(s));
        var o = I()[a / 4 + 0], i = I()[a / 4 + 1];
        if (i)
          throw U(o);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    insertObject(t, e, r) {
      try {
        const c = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_insertObject(c, this.__wbg_ptr, C(t), e, C(r));
        var s = I()[c / 4 + 0], o = I()[c / 4 + 1], i = I()[c / 4 + 2], a = I()[c / 4 + 3];
        if (a)
          throw U(i);
        let f;
        return s !== 0 && (f = Bt(s, o).slice(), b.__wbindgen_free(s, o * 1, 1)), f;
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    put(t, e, r, s) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_put(a, this.__wbg_ptr, C(t), C(e), C(r), C(s));
        var o = I()[a / 4 + 0], i = I()[a / 4 + 1];
        if (i)
          throw U(o);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    putObject(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_putObject(a, this.__wbg_ptr, C(t), C(e), C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    increment(t, e, r) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_increment(i, this.__wbg_ptr, C(t), C(e), C(r));
        var s = I()[i / 4 + 0], o = I()[i / 4 + 1];
        if (o)
          throw U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    get(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_get(a, this.__wbg_ptr, C(t), C(e), lt(r) ? 0 : C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getWithType(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getWithType(a, this.__wbg_ptr, C(t), C(e), lt(r) ? 0 : C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getAll(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getAll(a, this.__wbg_ptr, C(t), C(e), lt(r) ? 0 : C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    enableFreeze(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_enableFreeze(o, this.__wbg_ptr, C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    registerDatatype(t, e) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_registerDatatype(o, this.__wbg_ptr, C(t), C(e));
        var r = I()[o / 4 + 0], s = I()[o / 4 + 1];
        if (s)
          throw U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyPatches(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_applyPatches(i, this.__wbg_ptr, C(t), C(e));
        var r = I()[i / 4 + 0], s = I()[i / 4 + 1], o = I()[i / 4 + 2];
        if (o)
          throw U(s);
        return U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyAndReturnPatches(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_applyAndReturnPatches(i, this.__wbg_ptr, C(t), C(e));
        var r = I()[i / 4 + 0], s = I()[i / 4 + 1], o = I()[i / 4 + 2];
        if (o)
          throw U(s);
        return U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    diffIncremental() {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_diffIncremental(s, this.__wbg_ptr);
        var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
        if (r)
          throw U(e);
        return U(t);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    updateDiffCursor() {
      b.automerge_updateDiffCursor(this.__wbg_ptr);
    }
    resetDiffCursor() {
      b.automerge_resetDiffCursor(this.__wbg_ptr);
    }
    diff(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_diff(i, this.__wbg_ptr, C(t), C(e));
        var r = I()[i / 4 + 0], s = I()[i / 4 + 1], o = I()[i / 4 + 2];
        if (o)
          throw U(s);
        return U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    isolate(t) {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_isolate(s, this.__wbg_ptr, C(t));
        var e = I()[s / 4 + 0], r = I()[s / 4 + 1];
        if (r)
          throw U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    integrate() {
      b.automerge_integrate(this.__wbg_ptr);
    }
    length(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_length(i, this.__wbg_ptr, C(t), lt(e) ? 0 : C(e));
        var r = $n()[i / 8 + 0], s = I()[i / 4 + 2], o = I()[i / 4 + 3];
        if (o)
          throw U(s);
        return r;
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    delete(t, e) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_delete(o, this.__wbg_ptr, C(t), C(e));
        var r = I()[o / 4 + 0], s = I()[o / 4 + 1];
        if (s)
          throw U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    save() {
      const t = b.automerge_save(this.__wbg_ptr);
      return U(t);
    }
    saveIncremental() {
      const t = b.automerge_saveIncremental(this.__wbg_ptr);
      return U(t);
    }
    saveSince(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_saveSince(o, this.__wbg_ptr, C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    saveNoCompress() {
      const t = b.automerge_saveNoCompress(this.__wbg_ptr);
      return U(t);
    }
    saveAndVerify() {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_saveAndVerify(s, this.__wbg_ptr);
        var t = I()[s / 4 + 0], e = I()[s / 4 + 1], r = I()[s / 4 + 2];
        if (r)
          throw U(e);
        return U(t);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    loadIncremental(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_loadIncremental(o, this.__wbg_ptr, C(t));
        var e = $n()[o / 8 + 0], r = I()[o / 4 + 2], s = I()[o / 4 + 3];
        if (s)
          throw U(r);
        return e;
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    applyChanges(t) {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_applyChanges(s, this.__wbg_ptr, C(t));
        var e = I()[s / 4 + 0], r = I()[s / 4 + 1];
        if (r)
          throw U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChanges(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getChanges(o, this.__wbg_ptr, C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangeByHash(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getChangeByHash(o, this.__wbg_ptr, C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getChangesAdded(t) {
      Ue(t, Xt);
      const e = b.automerge_getChangesAdded(this.__wbg_ptr, t.__wbg_ptr);
      return U(e);
    }
    getHeads() {
      const t = b.automerge_getHeads(this.__wbg_ptr);
      return U(t);
    }
    getActorId() {
      let t, e;
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getActorId(o, this.__wbg_ptr);
        var r = I()[o / 4 + 0], s = I()[o / 4 + 1];
        return t = r, e = s, Bt(r, s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16), b.__wbindgen_free(t, e, 1);
      }
    }
    getLastLocalChange() {
      const t = b.automerge_getLastLocalChange(this.__wbg_ptr);
      return U(t);
    }
    dump() {
      b.automerge_dump(this.__wbg_ptr);
    }
    getMissingDeps(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getMissingDeps(o, this.__wbg_ptr, lt(t) ? 0 : C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    receiveSyncMessage(t, e) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        Ue(t, Kt), b.automerge_receiveSyncMessage(o, this.__wbg_ptr, t.__wbg_ptr, C(e));
        var r = I()[o / 4 + 0], s = I()[o / 4 + 1];
        if (s)
          throw U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    generateSyncMessage(t) {
      Ue(t, Kt);
      const e = b.automerge_generateSyncMessage(this.__wbg_ptr, t.__wbg_ptr);
      return U(e);
    }
    toJS(t) {
      try {
        const o = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_toJS(o, this.__wbg_ptr, C(t));
        var e = I()[o / 4 + 0], r = I()[o / 4 + 1], s = I()[o / 4 + 2];
        if (s)
          throw U(r);
        return U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    materialize(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_materialize(a, this.__wbg_ptr, C(t), lt(e) ? 0 : C(e), C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    getCursor(t, e, r) {
      let s, o;
      try {
        const d = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getCursor(d, this.__wbg_ptr, C(t), e, lt(r) ? 0 : C(r));
        var i = I()[d / 4 + 0], a = I()[d / 4 + 1], c = I()[d / 4 + 2], f = I()[d / 4 + 3], u = i, _ = a;
        if (f)
          throw u = 0, _ = 0, U(c);
        return s = u, o = _, Bt(u, _);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16), b.__wbindgen_free(s, o, 1);
      }
    }
    getCursorPosition(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_getCursorPosition(a, this.__wbg_ptr, C(t), C(e), lt(r) ? 0 : C(r));
        var s = $n()[a / 8 + 0], o = I()[a / 4 + 2], i = I()[a / 4 + 3];
        if (i)
          throw U(o);
        return s;
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    emptyChange(t, e) {
      var r = lt(t) ? 0 : ee(t, b.__wbindgen_malloc, b.__wbindgen_realloc), s = Wt;
      const o = b.automerge_emptyChange(this.__wbg_ptr, r, s, !lt(e), lt(e) ? 0 : e);
      return U(o);
    }
    mark(t, e, r, s, o) {
      try {
        const c = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_mark(c, this.__wbg_ptr, C(t), C(e), C(r), C(s), C(o));
        var i = I()[c / 4 + 0], a = I()[c / 4 + 1];
        if (a)
          throw U(i);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    unmark(t, e, r) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_unmark(i, this.__wbg_ptr, C(t), C(e), C(r));
        var s = I()[i / 4 + 0], o = I()[i / 4 + 1];
        if (o)
          throw U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marks(t, e) {
      try {
        const i = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_marks(i, this.__wbg_ptr, C(t), lt(e) ? 0 : C(e));
        var r = I()[i / 4 + 0], s = I()[i / 4 + 1], o = I()[i / 4 + 2];
        if (o)
          throw U(s);
        return U(r);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    marksAt(t, e, r) {
      try {
        const a = b.__wbindgen_add_to_stack_pointer(-16);
        b.automerge_marksAt(a, this.__wbg_ptr, C(t), e, lt(r) ? 0 : C(r));
        var s = I()[a / 4 + 0], o = I()[a / 4 + 1], i = I()[a / 4 + 2];
        if (i)
          throw U(o);
        return U(s);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
  }
  const so = new FinalizationRegistry((n) => b.__wbg_syncstate_free(n >>> 0));
  class Kt {
    static __wrap(t) {
      t = t >>> 0;
      const e = Object.create(Kt.prototype);
      return e.__wbg_ptr = t, so.register(e, e.__wbg_ptr, e), e;
    }
    __destroy_into_raw() {
      const t = this.__wbg_ptr;
      return this.__wbg_ptr = 0, so.unregister(this), t;
    }
    free() {
      const t = this.__destroy_into_raw();
      b.__wbg_syncstate_free(t);
    }
    get sharedHeads() {
      const t = b.syncstate_sharedHeads(this.__wbg_ptr);
      return U(t);
    }
    get lastSentHeads() {
      const t = b.syncstate_lastSentHeads(this.__wbg_ptr);
      return U(t);
    }
    set lastSentHeads(t) {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.syncstate_set_lastSentHeads(s, this.__wbg_ptr, C(t));
        var e = I()[s / 4 + 0], r = I()[s / 4 + 1];
        if (r)
          throw U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    set sentHashes(t) {
      try {
        const s = b.__wbindgen_add_to_stack_pointer(-16);
        b.syncstate_set_sentHashes(s, this.__wbg_ptr, C(t));
        var e = I()[s / 4 + 0], r = I()[s / 4 + 1];
        if (r)
          throw U(e);
      } finally {
        b.__wbindgen_add_to_stack_pointer(16);
      }
    }
    clone() {
      const t = b.syncstate_clone(this.__wbg_ptr);
      return Kt.__wrap(t);
    }
  }
  function Cd() {
    const n = {};
    return n.wbg = {}, n.wbg.__wbindgen_object_drop_ref = function(t) {
      U(t);
    }, n.wbg.__wbindgen_string_get = function(t, e) {
      const r = F(e), s = typeof r == "string" ? r : void 0;
      var o = lt(s) ? 0 : ee(s, b.__wbindgen_malloc, b.__wbindgen_realloc), i = Wt;
      I()[t / 4 + 1] = i, I()[t / 4 + 0] = o;
    }, n.wbg.__wbindgen_error_new = function(t, e) {
      const r = new Error(Bt(t, e));
      return C(r);
    }, n.wbg.__wbindgen_object_clone_ref = function(t) {
      const e = F(t);
      return C(e);
    }, n.wbg.__wbindgen_string_new = function(t, e) {
      const r = Bt(t, e);
      return C(r);
    }, n.wbg.__wbindgen_number_new = function(t) {
      return C(t);
    }, n.wbg.__wbindgen_number_get = function(t, e) {
      const r = F(e), s = typeof r == "number" ? r : void 0;
      $n()[t / 8 + 1] = lt(s) ? 0 : s, I()[t / 4 + 0] = !lt(s);
    }, n.wbg.__wbindgen_is_undefined = function(t) {
      return F(t) === void 0;
    }, n.wbg.__wbindgen_boolean_get = function(t) {
      const e = F(t);
      return typeof e == "boolean" ? e ? 1 : 0 : 2;
    }, n.wbg.__wbindgen_is_null = function(t) {
      return F(t) === null;
    }, n.wbg.__wbindgen_is_function = function(t) {
      return typeof F(t) == "function";
    }, n.wbg.__wbindgen_is_string = function(t) {
      return typeof F(t) == "string";
    }, n.wbg.__wbindgen_is_object = function(t) {
      const e = F(t);
      return typeof e == "object" && e !== null;
    }, n.wbg.__wbindgen_is_array = function(t) {
      return Array.isArray(F(t));
    }, n.wbg.__wbindgen_json_serialize = function(t, e) {
      const r = F(e), s = JSON.stringify(r === void 0 ? null : r), o = ee(s, b.__wbindgen_malloc, b.__wbindgen_realloc), i = Wt;
      I()[t / 4 + 1] = i, I()[t / 4 + 0] = o;
    }, n.wbg.__wbg_new_abda76e883ba8a5f = function() {
      const t = new Error();
      return C(t);
    }, n.wbg.__wbg_stack_658279fe44541cf6 = function(t, e) {
      const r = F(e).stack, s = ee(r, b.__wbindgen_malloc, b.__wbindgen_realloc), o = Wt;
      I()[t / 4 + 1] = o, I()[t / 4 + 0] = s;
    }, n.wbg.__wbg_error_f851667af71bcfc6 = function(t, e) {
      let r, s;
      try {
        r = t, s = e, console.error(Bt(t, e));
      } finally {
        b.__wbindgen_free(r, s, 1);
      }
    }, n.wbg.__wbindgen_jsval_loose_eq = function(t, e) {
      return F(t) == F(e);
    }, n.wbg.__wbg_String_91fba7ded13ba54c = function(t, e) {
      const r = String(F(e)), s = ee(r, b.__wbindgen_malloc, b.__wbindgen_realloc), o = Wt;
      I()[t / 4 + 1] = o, I()[t / 4 + 0] = s;
    }, n.wbg.__wbindgen_bigint_from_i64 = function(t) {
      return C(t);
    }, n.wbg.__wbindgen_bigint_from_u64 = function(t) {
      const e = BigInt.asUintN(64, t);
      return C(e);
    }, n.wbg.__wbg_set_20cbc34131e76824 = function(t, e, r) {
      F(t)[U(e)] = U(r);
    }, n.wbg.__wbg_getRandomValues_504510b5564925af = function() {
      return Et(function(t, e) {
        F(t).getRandomValues(F(e));
      }, arguments);
    }, n.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function() {
      return Et(function(t, e) {
        F(t).randomFillSync(U(e));
      }, arguments);
    }, n.wbg.__wbg_crypto_58f13aa23ffcb166 = function(t) {
      const e = F(t).crypto;
      return C(e);
    }, n.wbg.__wbg_process_5b786e71d465a513 = function(t) {
      const e = F(t).process;
      return C(e);
    }, n.wbg.__wbg_versions_c2ab80650590b6a2 = function(t) {
      const e = F(t).versions;
      return C(e);
    }, n.wbg.__wbg_node_523d7bd03ef69fba = function(t) {
      const e = F(t).node;
      return C(e);
    }, n.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function(t) {
      const e = F(t).msCrypto;
      return C(e);
    }, n.wbg.__wbg_require_2784e593a4674877 = function() {
      return Et(function() {
        const t = module.require;
        return C(t);
      }, arguments);
    }, n.wbg.__wbg_log_a4530b4fe289336f = function(t) {
      console.log(F(t));
    }, n.wbg.__wbg_log_00cf3417193182f2 = function(t, e) {
      console.log(F(t), F(e));
    }, n.wbg.__wbg_get_f01601b5a68d10e3 = function(t, e) {
      const r = F(t)[e >>> 0];
      return C(r);
    }, n.wbg.__wbg_length_1009b1af0c481d7b = function(t) {
      return F(t).length;
    }, n.wbg.__wbg_new_ffc6d4d085022169 = function() {
      const t = new Array();
      return C(t);
    }, n.wbg.__wbg_newnoargs_c62ea9419c21fbac = function(t, e) {
      const r = new Function(Bt(t, e));
      return C(r);
    }, n.wbg.__wbg_next_9b877f231f476d01 = function(t) {
      const e = F(t).next;
      return C(e);
    }, n.wbg.__wbg_next_6529ee0cca8d57ed = function() {
      return Et(function(t) {
        const e = F(t).next();
        return C(e);
      }, arguments);
    }, n.wbg.__wbg_done_5fe336b092d60cf2 = function(t) {
      return F(t).done;
    }, n.wbg.__wbg_value_0c248a78fdc8e19f = function(t) {
      const e = F(t).value;
      return C(e);
    }, n.wbg.__wbg_iterator_db7ca081358d4fb2 = function() {
      return C(Symbol.iterator);
    }, n.wbg.__wbg_get_7b48513de5dc5ea4 = function() {
      return Et(function(t, e) {
        const r = Reflect.get(F(t), F(e));
        return C(r);
      }, arguments);
    }, n.wbg.__wbg_call_90c26b09837aba1c = function() {
      return Et(function(t, e) {
        const r = F(t).call(F(e));
        return C(r);
      }, arguments);
    }, n.wbg.__wbg_new_9fb8d994e1c0aaac = function() {
      const t = new Object();
      return C(t);
    }, n.wbg.__wbg_length_36658cb09b6ec34a = function(t) {
      return F(t).length;
    }, n.wbg.__wbg_set_f2740edb12e318cd = function(t, e, r) {
      F(t)[e >>> 0] = U(r);
    }, n.wbg.__wbg_from_71add2e723d1f1b2 = function(t) {
      const e = Array.from(F(t));
      return C(e);
    }, n.wbg.__wbg_isArray_74fb723e24f76012 = function(t) {
      return Array.isArray(F(t));
    }, n.wbg.__wbg_push_901f3914205d44de = function(t, e) {
      return F(t).push(F(e));
    }, n.wbg.__wbg_unshift_5436cf2bdfb8635d = function(t, e) {
      return F(t).unshift(F(e));
    }, n.wbg.__wbg_instanceof_ArrayBuffer_e7d53d51371448e2 = function(t) {
      let e;
      try {
        e = F(t) instanceof ArrayBuffer;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_new_a64e3f2afc2cf2f8 = function(t, e) {
      const r = new Error(Bt(t, e));
      return C(r);
    }, n.wbg.__wbg_call_5da1969d7cd31ccd = function() {
      return Et(function(t, e, r) {
        const s = F(t).call(F(e), F(r));
        return C(s);
      }, arguments);
    }, n.wbg.__wbg_instanceof_Date_cfa5d171ed8093a1 = function(t) {
      let e;
      try {
        e = F(t) instanceof Date;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_getTime_9272be78826033e1 = function(t) {
      return F(t).getTime();
    }, n.wbg.__wbg_new_d77fabdc03b9edd6 = function(t) {
      const e = new Date(F(t));
      return C(e);
    }, n.wbg.__wbg_instanceof_Object_702c4990f4c3db8d = function(t) {
      let e;
      try {
        e = F(t) instanceof Object;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_assign_6fdd54658ed70520 = function(t, e) {
      const r = Object.assign(F(t), F(e));
      return C(r);
    }, n.wbg.__wbg_defineProperty_2982dad69ce66029 = function(t, e, r) {
      const s = Object.defineProperty(F(t), F(e), F(r));
      return C(s);
    }, n.wbg.__wbg_entries_9e2e2aa45aa5094a = function(t) {
      const e = Object.entries(F(t));
      return C(e);
    }, n.wbg.__wbg_freeze_3cb3d8155bb1dc4d = function(t) {
      const e = Object.freeze(F(t));
      return C(e);
    }, n.wbg.__wbg_keys_fb74497f0cb41c2a = function(t) {
      const e = Object.keys(F(t));
      return C(e);
    }, n.wbg.__wbg_values_ab825057174d69d1 = function(t) {
      const e = Object.values(F(t));
      return C(e);
    }, n.wbg.__wbg_new_9fa4bec794556db1 = function(t, e) {
      const r = new RangeError(Bt(t, e));
      return C(r);
    }, n.wbg.__wbg_apply_4d8fcf4ddc362ff9 = function() {
      return Et(function(t, e, r) {
        const s = Reflect.apply(F(t), F(e), F(r));
        return C(s);
      }, arguments);
    }, n.wbg.__wbg_deleteProperty_8c212ef4944e69d8 = function() {
      return Et(function(t, e) {
        return Reflect.deleteProperty(F(t), F(e));
      }, arguments);
    }, n.wbg.__wbg_ownKeys_7ac8657f7af0c859 = function() {
      return Et(function(t) {
        const e = Reflect.ownKeys(F(t));
        return C(e);
      }, arguments);
    }, n.wbg.__wbg_set_759f75cd92b612d2 = function() {
      return Et(function(t, e, r) {
        return Reflect.set(F(t), F(e), F(r));
      }, arguments);
    }, n.wbg.__wbg_buffer_a448f833075b71ba = function(t) {
      const e = F(t).buffer;
      return C(e);
    }, n.wbg.__wbg_concat_48d0d62f514d0161 = function(t, e) {
      const r = F(t).concat(F(e));
      return C(r);
    }, n.wbg.__wbg_slice_be7863d04044cbc1 = function(t, e, r) {
      const s = F(t).slice(e >>> 0, r >>> 0);
      return C(s);
    }, n.wbg.__wbg_for_bcf4067191afa30f = function(t, e) {
      const r = Symbol.for(Bt(t, e));
      return C(r);
    }, n.wbg.__wbg_toString_b18b2b1e8378cebc = function(t) {
      const e = F(t).toString();
      return C(e);
    }, n.wbg.__wbg_self_f0e34d89f33b99fd = function() {
      return Et(function() {
        const t = self.self;
        return C(t);
      }, arguments);
    }, n.wbg.__wbg_window_d3b084224f4774d7 = function() {
      return Et(function() {
        const t = window.window;
        return C(t);
      }, arguments);
    }, n.wbg.__wbg_globalThis_9caa27ff917c6860 = function() {
      return Et(function() {
        const t = globalThis.globalThis;
        return C(t);
      }, arguments);
    }, n.wbg.__wbg_global_35dfdd59a4da3e74 = function() {
      return Et(function() {
        const t = global.global;
        return C(t);
      }, arguments);
    }, n.wbg.__wbg_newwithbyteoffsetandlength_d0482f893617af71 = function(t, e, r) {
      const s = new Uint8Array(F(t), e >>> 0, r >>> 0);
      return C(s);
    }, n.wbg.__wbg_new_8f67e318f15d7254 = function(t) {
      const e = new Uint8Array(F(t));
      return C(e);
    }, n.wbg.__wbg_set_2357bf09366ee480 = function(t, e, r) {
      F(t).set(F(e), r >>> 0);
    }, n.wbg.__wbg_length_1d25fa9e4ac21ce7 = function(t) {
      return F(t).length;
    }, n.wbg.__wbg_instanceof_Uint8Array_bced6f43aed8c1aa = function(t) {
      let e;
      try {
        e = F(t) instanceof Uint8Array;
      } catch {
        e = false;
      }
      return e;
    }, n.wbg.__wbg_newwithlength_6c2df9e2f3028c43 = function(t) {
      const e = new Uint8Array(t >>> 0);
      return C(e);
    }, n.wbg.__wbg_subarray_2e940e41c0f5a1d9 = function(t, e, r) {
      const s = F(t).subarray(e >>> 0, r >>> 0);
      return C(s);
    }, n.wbg.__wbindgen_debug_string = function(t, e) {
      const r = kr(F(e)), s = ee(r, b.__wbindgen_malloc, b.__wbindgen_realloc), o = Wt;
      I()[t / 4 + 1] = o, I()[t / 4 + 0] = s;
    }, n.wbg.__wbindgen_throw = function(t, e) {
      throw new Error(Bt(t, e));
    }, n.wbg.__wbindgen_memory = function() {
      const t = b.memory;
      return C(t);
    }, n;
  }
  function Od(n, t) {
    return b = n.exports, en = null, tn = null, Qe = null, b;
  }
  function Ka(n) {
    if (b !== void 0)
      return b;
    const t = Cd();
    n instanceof WebAssembly.Module || (n = new WebAssembly.Module(n));
    const e = new WebAssembly.Instance(n, t);
    return Od(e);
  }
  jd = new Promise((n) => {
    fetch(ld).then((t) => {
      t.arrayBuffer().then((e) => {
        Ka(e), n();
      });
    });
  });
  yg = Object.freeze(Object.defineProperty({
    __proto__: null,
    Automerge: Xt,
    SyncState: Kt,
    TextRepresentation: Ed,
    create: bd,
    decodeChange: yd,
    decodeSyncMessage: Id,
    decodeSyncState: Ad,
    encodeChange: wd,
    encodeSyncMessage: xd,
    encodeSyncState: kd,
    exportSyncState: Sd,
    importSyncState: vd,
    initSync: Ka,
    initSyncState: md,
    load: pd,
    promise: jd
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  Rd = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
  Ss = function(n) {
    return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
  };
  var Ar = {
    exports: {}
  }, ar, oo;
  function Td() {
    if (oo)
      return ar;
    oo = 1;
    var n = 1e3, t = n * 60, e = t * 60, r = e * 24, s = r * 7, o = r * 365.25;
    ar = function(u, _) {
      _ = _ || {};
      var d = typeof u;
      if (d === "string" && u.length > 0)
        return i(u);
      if (d === "number" && isFinite(u))
        return _.long ? c(u) : a(u);
      throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(u));
    };
    function i(u) {
      if (u = String(u), !(u.length > 100)) {
        var _ = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u);
        if (_) {
          var d = parseFloat(_[1]), l = (_[2] || "ms").toLowerCase();
          switch (l) {
            case "years":
            case "year":
            case "yrs":
            case "yr":
            case "y":
              return d * o;
            case "weeks":
            case "week":
            case "w":
              return d * s;
            case "days":
            case "day":
            case "d":
              return d * r;
            case "hours":
            case "hour":
            case "hrs":
            case "hr":
            case "h":
              return d * e;
            case "minutes":
            case "minute":
            case "mins":
            case "min":
            case "m":
              return d * t;
            case "seconds":
            case "second":
            case "secs":
            case "sec":
            case "s":
              return d * n;
            case "milliseconds":
            case "millisecond":
            case "msecs":
            case "msec":
            case "ms":
              return d;
            default:
              return;
          }
        }
      }
    }
    function a(u) {
      var _ = Math.abs(u);
      return _ >= r ? Math.round(u / r) + "d" : _ >= e ? Math.round(u / e) + "h" : _ >= t ? Math.round(u / t) + "m" : _ >= n ? Math.round(u / n) + "s" : u + "ms";
    }
    function c(u) {
      var _ = Math.abs(u);
      return _ >= r ? f(u, _, r, "day") : _ >= e ? f(u, _, e, "hour") : _ >= t ? f(u, _, t, "minute") : _ >= n ? f(u, _, n, "second") : u + " ms";
    }
    function f(u, _, d, l) {
      var w = _ >= d * 1.5;
      return Math.round(u / d) + " " + l + (w ? "s" : "");
    }
    return ar;
  }
  function Md(n) {
    e.debug = e, e.default = e, e.coerce = c, e.disable = i, e.enable = s, e.enabled = a, e.humanize = Td(), e.destroy = f, Object.keys(n).forEach((u) => {
      e[u] = n[u];
    }), e.names = [], e.skips = [], e.formatters = {};
    function t(u) {
      let _ = 0;
      for (let d = 0; d < u.length; d++)
        _ = (_ << 5) - _ + u.charCodeAt(d), _ |= 0;
      return e.colors[Math.abs(_) % e.colors.length];
    }
    e.selectColor = t;
    function e(u) {
      let _, d = null, l, w;
      function k(...j) {
        if (!k.enabled)
          return;
        const L = k, N = Number(/* @__PURE__ */ new Date()), O = N - (_ || N);
        L.diff = O, L.prev = _, L.curr = N, _ = N, j[0] = e.coerce(j[0]), typeof j[0] != "string" && j.unshift("%O");
        let q = 0;
        j[0] = j[0].replace(/%([a-zA-Z%])/g, (Y, it) => {
          if (Y === "%%")
            return "%";
          q++;
          const tt = e.formatters[it];
          if (typeof tt == "function") {
            const st = j[q];
            Y = tt.call(L, st), j.splice(q, 1), q--;
          }
          return Y;
        }), e.formatArgs.call(L, j), (L.log || e.log).apply(L, j);
      }
      return k.namespace = u, k.useColors = e.useColors(), k.color = e.selectColor(u), k.extend = r, k.destroy = e.destroy, Object.defineProperty(k, "enabled", {
        enumerable: true,
        configurable: false,
        get: () => d !== null ? d : (l !== e.namespaces && (l = e.namespaces, w = e.enabled(u)), w),
        set: (j) => {
          d = j;
        }
      }), typeof e.init == "function" && e.init(k), k;
    }
    function r(u, _) {
      const d = e(this.namespace + (typeof _ > "u" ? ":" : _) + u);
      return d.log = this.log, d;
    }
    function s(u) {
      e.save(u), e.namespaces = u, e.names = [], e.skips = [];
      const _ = (typeof u == "string" ? u : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
      for (const d of _)
        d[0] === "-" ? e.skips.push(d.slice(1)) : e.names.push(d);
    }
    function o(u, _) {
      let d = 0, l = 0, w = -1, k = 0;
      for (; d < u.length; )
        if (l < _.length && (_[l] === u[d] || _[l] === "*"))
          _[l] === "*" ? (w = l, k = d, l++) : (d++, l++);
        else if (w !== -1)
          l = w + 1, k++, d = k;
        else
          return false;
      for (; l < _.length && _[l] === "*"; )
        l++;
      return l === _.length;
    }
    function i() {
      const u = [
        ...e.names,
        ...e.skips.map((_) => "-" + _)
      ].join(",");
      return e.enable(""), u;
    }
    function a(u) {
      for (const _ of e.skips)
        if (o(u, _))
          return false;
      for (const _ of e.names)
        if (o(u, _))
          return true;
      return false;
    }
    function c(u) {
      return u instanceof Error ? u.stack || u.message : u;
    }
    function f() {
      console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
    }
    return e.enable(e.load()), e;
  }
  var Hd = Md;
  (function(n, t) {
    t.formatArgs = r, t.save = s, t.load = o, t.useColors = e, t.storage = i(), t.destroy = (() => {
      let c = false;
      return () => {
        c || (c = true, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));
      };
    })(), t.colors = [
      "#0000CC",
      "#0000FF",
      "#0033CC",
      "#0033FF",
      "#0066CC",
      "#0066FF",
      "#0099CC",
      "#0099FF",
      "#00CC00",
      "#00CC33",
      "#00CC66",
      "#00CC99",
      "#00CCCC",
      "#00CCFF",
      "#3300CC",
      "#3300FF",
      "#3333CC",
      "#3333FF",
      "#3366CC",
      "#3366FF",
      "#3399CC",
      "#3399FF",
      "#33CC00",
      "#33CC33",
      "#33CC66",
      "#33CC99",
      "#33CCCC",
      "#33CCFF",
      "#6600CC",
      "#6600FF",
      "#6633CC",
      "#6633FF",
      "#66CC00",
      "#66CC33",
      "#9900CC",
      "#9900FF",
      "#9933CC",
      "#9933FF",
      "#99CC00",
      "#99CC33",
      "#CC0000",
      "#CC0033",
      "#CC0066",
      "#CC0099",
      "#CC00CC",
      "#CC00FF",
      "#CC3300",
      "#CC3333",
      "#CC3366",
      "#CC3399",
      "#CC33CC",
      "#CC33FF",
      "#CC6600",
      "#CC6633",
      "#CC9900",
      "#CC9933",
      "#CCCC00",
      "#CCCC33",
      "#FF0000",
      "#FF0033",
      "#FF0066",
      "#FF0099",
      "#FF00CC",
      "#FF00FF",
      "#FF3300",
      "#FF3333",
      "#FF3366",
      "#FF3399",
      "#FF33CC",
      "#FF33FF",
      "#FF6600",
      "#FF6633",
      "#FF9900",
      "#FF9933",
      "#FFCC00",
      "#FFCC33"
    ];
    function e() {
      if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs))
        return true;
      if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))
        return false;
      let c;
      return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator < "u" && navigator.userAgent && (c = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(c[1], 10) >= 31 || typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
    }
    function r(c) {
      if (c[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + c[0] + (this.useColors ? "%c " : " ") + "+" + n.exports.humanize(this.diff), !this.useColors)
        return;
      const f = "color: " + this.color;
      c.splice(1, 0, f, "color: inherit");
      let u = 0, _ = 0;
      c[0].replace(/%[a-zA-Z%]/g, (d) => {
        d !== "%%" && (u++, d === "%c" && (_ = u));
      }), c.splice(_, 0, f);
    }
    t.log = console.debug || console.log || (() => {
    });
    function s(c) {
      try {
        c ? t.storage.setItem("debug", c) : t.storage.removeItem("debug");
      } catch {
      }
    }
    function o() {
      let c;
      try {
        c = t.storage.getItem("debug") || t.storage.getItem("DEBUG");
      } catch {
      }
      return !c && typeof process < "u" && "env" in process && (c = {}.DEBUG), c;
    }
    function i() {
      try {
        return localStorage;
      } catch {
      }
    }
    n.exports = Hd(t);
    const { formatters: a } = n.exports;
    a.j = function(c) {
      try {
        return JSON.stringify(c);
      } catch (f) {
        return "[UnexpectedJSONParseError]: " + f.message;
      }
    };
  })(Ar, Ar.exports);
  var Dd = Ar.exports;
  ye = Ss(Dd);
  var Ja = {
    exports: {}
  };
  (function(n) {
    var t = Object.prototype.hasOwnProperty, e = "~";
    function r() {
    }
    Object.create && (r.prototype = /* @__PURE__ */ Object.create(null), new r().__proto__ || (e = false));
    function s(c, f, u) {
      this.fn = c, this.context = f, this.once = u || false;
    }
    function o(c, f, u, _, d) {
      if (typeof u != "function")
        throw new TypeError("The listener must be a function");
      var l = new s(u, _ || c, d), w = e ? e + f : f;
      return c._events[w] ? c._events[w].fn ? c._events[w] = [
        c._events[w],
        l
      ] : c._events[w].push(l) : (c._events[w] = l, c._eventsCount++), c;
    }
    function i(c, f) {
      --c._eventsCount === 0 ? c._events = new r() : delete c._events[f];
    }
    function a() {
      this._events = new r(), this._eventsCount = 0;
    }
    a.prototype.eventNames = function() {
      var f = [], u, _;
      if (this._eventsCount === 0)
        return f;
      for (_ in u = this._events)
        t.call(u, _) && f.push(e ? _.slice(1) : _);
      return Object.getOwnPropertySymbols ? f.concat(Object.getOwnPropertySymbols(u)) : f;
    }, a.prototype.listeners = function(f) {
      var u = e ? e + f : f, _ = this._events[u];
      if (!_)
        return [];
      if (_.fn)
        return [
          _.fn
        ];
      for (var d = 0, l = _.length, w = new Array(l); d < l; d++)
        w[d] = _[d].fn;
      return w;
    }, a.prototype.listenerCount = function(f) {
      var u = e ? e + f : f, _ = this._events[u];
      return _ ? _.fn ? 1 : _.length : 0;
    }, a.prototype.emit = function(f, u, _, d, l, w) {
      var k = e ? e + f : f;
      if (!this._events[k])
        return false;
      var j = this._events[k], L = arguments.length, N, O;
      if (j.fn) {
        switch (j.once && this.removeListener(f, j.fn, void 0, true), L) {
          case 1:
            return j.fn.call(j.context), true;
          case 2:
            return j.fn.call(j.context, u), true;
          case 3:
            return j.fn.call(j.context, u, _), true;
          case 4:
            return j.fn.call(j.context, u, _, d), true;
          case 5:
            return j.fn.call(j.context, u, _, d, l), true;
          case 6:
            return j.fn.call(j.context, u, _, d, l, w), true;
        }
        for (O = 1, N = new Array(L - 1); O < L; O++)
          N[O - 1] = arguments[O];
        j.fn.apply(j.context, N);
      } else {
        var q = j.length, Z;
        for (O = 0; O < q; O++)
          switch (j[O].once && this.removeListener(f, j[O].fn, void 0, true), L) {
            case 1:
              j[O].fn.call(j[O].context);
              break;
            case 2:
              j[O].fn.call(j[O].context, u);
              break;
            case 3:
              j[O].fn.call(j[O].context, u, _);
              break;
            case 4:
              j[O].fn.call(j[O].context, u, _, d);
              break;
            default:
              if (!N)
                for (Z = 1, N = new Array(L - 1); Z < L; Z++)
                  N[Z - 1] = arguments[Z];
              j[O].fn.apply(j[O].context, N);
          }
      }
      return true;
    }, a.prototype.on = function(f, u, _) {
      return o(this, f, u, _, false);
    }, a.prototype.once = function(f, u, _) {
      return o(this, f, u, _, true);
    }, a.prototype.removeListener = function(f, u, _, d) {
      var l = e ? e + f : f;
      if (!this._events[l])
        return this;
      if (!u)
        return i(this, l), this;
      var w = this._events[l];
      if (w.fn)
        w.fn === u && (!d || w.once) && (!_ || w.context === _) && i(this, l);
      else {
        for (var k = 0, j = [], L = w.length; k < L; k++)
          (w[k].fn !== u || d && !w[k].once || _ && w[k].context !== _) && j.push(w[k]);
        j.length ? this._events[l] = j.length === 1 ? j[0] : j : i(this, l);
      }
      return this;
    }, a.prototype.removeAllListeners = function(f) {
      var u;
      return f ? (u = e ? e + f : f, this._events[u] && i(this, u)) : (this._events = new r(), this._eventsCount = 0), this;
    }, a.prototype.off = a.prototype.removeListener, a.prototype.addListener = a.prototype.on, a.prefixed = e, a.EventEmitter = a, n.exports = a;
  })(Ja);
  var $d = Ja.exports;
  me = Ss($d);
  function Ud() {
    if (typeof globalThis < "u")
      return globalThis;
    if (typeof self < "u")
      return self;
    if (typeof window < "u")
      return window;
    if (typeof global < "u")
      return global;
  }
  function Bd() {
    const n = Ud();
    if (n.__xstate__)
      return n.__xstate__;
  }
  const Pd = (n) => {
    if (typeof window > "u")
      return;
    const t = Bd();
    t && t.register(n);
  };
  class io {
    constructor(t) {
      this._process = t, this._active = false, this._current = null, this._last = null;
    }
    start() {
      this._active = true, this.flush();
    }
    clear() {
      this._current && (this._current.next = null, this._last = this._current);
    }
    enqueue(t) {
      const e = {
        value: t,
        next: null
      };
      if (this._current) {
        this._last.next = e, this._last = e;
        return;
      }
      this._current = e, this._last = e, this._active && this.flush();
    }
    flush() {
      for (; this._current; ) {
        const t = this._current;
        this._process(t.value), this._current = t.next;
      }
      this._last = null;
    }
  }
  const Ga = ".", Fd = "", qa = "", Ld = "#", Vd = "*", Ya = "xstate.init", zd = "xstate.error", Er = "xstate.stop";
  function Nd(n, t) {
    return {
      type: `xstate.after.${n}.${t}`
    };
  }
  function Cr(n, t) {
    return {
      type: `xstate.done.state.${n}`,
      output: t
    };
  }
  function Wd(n, t) {
    return {
      type: `xstate.done.actor.${n}`,
      output: t,
      actorId: n
    };
  }
  function Xa(n, t) {
    return {
      type: `xstate.error.actor.${n}`,
      error: t,
      actorId: n
    };
  }
  function Za(n) {
    return {
      type: Ya,
      input: n
    };
  }
  function Jt(n) {
    setTimeout(() => {
      throw n;
    });
  }
  const Kd = (() => typeof Symbol == "function" && Symbol.observable || "@@observable")();
  function Qa(n, t) {
    const e = ao(n), r = ao(t);
    return typeof r == "string" ? typeof e == "string" ? r === e : false : typeof e == "string" ? e in r : Object.keys(e).every((s) => s in r ? Qa(e[s], r[s]) : false);
  }
  function xs(n) {
    if (ec(n))
      return n;
    const t = [];
    let e = "";
    for (let r = 0; r < n.length; r++) {
      switch (n.charCodeAt(r)) {
        case 92:
          e += n[r + 1], r++;
          continue;
        case 46:
          t.push(e), e = "";
          continue;
      }
      e += n[r];
    }
    return t.push(e), t;
  }
  function ao(n) {
    if (kl(n))
      return n.value;
    if (typeof n != "string")
      return n;
    const t = xs(n);
    return Jd(t);
  }
  function Jd(n) {
    if (n.length === 1)
      return n[0];
    const t = {};
    let e = t;
    for (let r = 0; r < n.length - 1; r++)
      if (r === n.length - 2)
        e[n[r]] = n[r + 1];
      else {
        const s = e;
        e = {}, s[n[r]] = e;
      }
    return t;
  }
  function co(n, t) {
    const e = {}, r = Object.keys(n);
    for (let s = 0; s < r.length; s++) {
      const o = r[s];
      e[o] = t(n[o], o, n, s);
    }
    return e;
  }
  function tc(n) {
    return ec(n) ? n : [
      n
    ];
  }
  function ce(n) {
    return n === void 0 ? [] : tc(n);
  }
  function Or(n, t, e, r) {
    return typeof n == "function" ? n({
      context: t,
      event: e,
      self: r
    }) : n;
  }
  function ec(n) {
    return Array.isArray(n);
  }
  function Gd(n) {
    return n.type.startsWith("xstate.error.actor");
  }
  function $e(n) {
    return tc(n).map((t) => typeof t > "u" || typeof t == "string" ? {
      target: t
    } : t);
  }
  function nc(n) {
    if (!(n === void 0 || n === Fd))
      return ce(n);
  }
  function jr(n, t, e) {
    var _a9, _b3, _c7;
    const r = typeof n == "object", s = r ? n : void 0;
    return {
      next: (_a9 = r ? n.next : n) == null ? void 0 : _a9.bind(s),
      error: (_b3 = r ? n.error : t) == null ? void 0 : _b3.bind(s),
      complete: (_c7 = r ? n.complete : e) == null ? void 0 : _c7.bind(s)
    };
  }
  function _o(n, t) {
    return `${t}.${n}`;
  }
  function Is(n, t) {
    const e = t.match(/^xstate\.invoke\.(\d+)\.(.*)/);
    if (!e)
      return n.implementations.actors[t];
    const [, r, s] = e, i = n.getStateNodeById(s).config.invoke;
    return (Array.isArray(i) ? i[r] : i).src;
  }
  function uo(n, t) {
    return `${n.sessionId}.${t}`;
  }
  let qd = 0;
  function Yd(n, t) {
    const e = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new Set(), i = {}, { clock: a, logger: c } = t, f = {
      schedule: (d, l, w, k, j = Math.random().toString(36).slice(2)) => {
        const L = {
          source: d,
          target: l,
          event: w,
          delay: k,
          id: j,
          startedAt: Date.now()
        }, N = uo(d, j);
        _._snapshot._scheduledEvents[N] = L;
        const O = a.setTimeout(() => {
          delete i[N], delete _._snapshot._scheduledEvents[N], _._relay(d, l, w);
        }, k);
        i[N] = O;
      },
      cancel: (d, l) => {
        const w = uo(d, l), k = i[w];
        delete i[w], delete _._snapshot._scheduledEvents[w], k !== void 0 && a.clearTimeout(k);
      },
      cancelAll: (d) => {
        for (const l in _._snapshot._scheduledEvents) {
          const w = _._snapshot._scheduledEvents[l];
          w.source === d && f.cancel(d, w.id);
        }
      }
    }, u = (d) => {
      if (!o.size)
        return;
      const l = {
        ...d,
        rootId: n.sessionId
      };
      o.forEach((w) => {
        var _a9;
        return (_a9 = w.next) == null ? void 0 : _a9.call(w, l);
      });
    }, _ = {
      _snapshot: {
        _scheduledEvents: ((t == null ? void 0 : t.snapshot) && t.snapshot.scheduler) ?? {}
      },
      _bookId: () => `x:${qd++}`,
      _register: (d, l) => (e.set(d, l), d),
      _unregister: (d) => {
        e.delete(d.sessionId);
        const l = s.get(d);
        l !== void 0 && (r.delete(l), s.delete(d));
      },
      get: (d) => r.get(d),
      _set: (d, l) => {
        const w = r.get(d);
        if (w && w !== l)
          throw new Error(`Actor with system ID '${d}' already exists.`);
        r.set(d, l), s.set(l, d);
      },
      inspect: (d) => {
        const l = jr(d);
        return o.add(l), {
          unsubscribe() {
            o.delete(l);
          }
        };
      },
      _sendInspectionEvent: u,
      _relay: (d, l, w) => {
        _._sendInspectionEvent({
          type: "@xstate.event",
          sourceRef: d,
          actorRef: l,
          event: w
        }), l._send(w);
      },
      scheduler: f,
      getSnapshot: () => ({
        _scheduledEvents: {
          ..._._snapshot._scheduledEvents
        }
      }),
      start: () => {
        const d = _._snapshot._scheduledEvents;
        _._snapshot._scheduledEvents = {};
        for (const l in d) {
          const { source: w, target: k, event: j, delay: L, id: N } = d[l];
          f.schedule(w, k, j, L, N);
        }
      },
      _clock: a,
      _logger: c
    };
    return _;
  }
  let cr = false;
  const ks = 1;
  let Rt = function(n) {
    return n[n.NotStarted = 0] = "NotStarted", n[n.Running = 1] = "Running", n[n.Stopped = 2] = "Stopped", n;
  }({});
  const Xd = {
    clock: {
      setTimeout: (n, t) => setTimeout(n, t),
      clearTimeout: (n) => clearTimeout(n)
    },
    logger: console.log.bind(console),
    devTools: false
  };
  class Zd {
    constructor(t, e) {
      this.logic = t, this._snapshot = void 0, this.clock = void 0, this.options = void 0, this.id = void 0, this.mailbox = new io(this._process.bind(this)), this.observers = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Map(), this.logger = void 0, this._processingStatus = Rt.NotStarted, this._parent = void 0, this._syncSnapshot = void 0, this.ref = void 0, this._actorScope = void 0, this.systemId = void 0, this.sessionId = void 0, this.system = void 0, this._doneEvent = void 0, this.src = void 0, this._deferred = [];
      const r = {
        ...Xd,
        ...e
      }, { clock: s, logger: o, parent: i, syncSnapshot: a, id: c, systemId: f, inspect: u } = r;
      this.system = i ? i.system : Yd(this, {
        clock: s,
        logger: o
      }), u && !i && this.system.inspect(jr(u)), this.sessionId = this.system._bookId(), this.id = c ?? this.sessionId, this.logger = (e == null ? void 0 : e.logger) ?? this.system._logger, this.clock = (e == null ? void 0 : e.clock) ?? this.system._clock, this._parent = i, this._syncSnapshot = a, this.options = r, this.src = r.src ?? t, this.ref = this, this._actorScope = {
        self: this,
        id: this.id,
        sessionId: this.sessionId,
        logger: this.logger,
        defer: (_) => {
          this._deferred.push(_);
        },
        system: this.system,
        stopChild: (_) => {
          if (_._parent !== this)
            throw new Error(`Cannot stop child actor ${_.id} of ${this.id} because it is not a child`);
          _._stop();
        },
        emit: (_) => {
          const d = this.eventListeners.get(_.type), l = this.eventListeners.get("*");
          if (!d && !l)
            return;
          const w = [
            ...d ? d.values() : [],
            ...l ? l.values() : []
          ];
          for (const k of w)
            try {
              k(_);
            } catch (j) {
              Jt(j);
            }
        },
        actionExecutor: (_) => {
          const d = () => {
            if (this._actorScope.system._sendInspectionEvent({
              type: "@xstate.action",
              actorRef: this,
              action: {
                type: _.type,
                params: _.params
              }
            }), !_.exec)
              return;
            const l = cr;
            try {
              cr = true, _.exec(_.info, _.params);
            } finally {
              cr = l;
            }
          };
          this._processingStatus === Rt.Running ? d() : this._deferred.push(d);
        }
      }, this.send = this.send.bind(this), this.system._sendInspectionEvent({
        type: "@xstate.actor",
        actorRef: this
      }), f && (this.systemId = f, this.system._set(f, this)), this._initState((e == null ? void 0 : e.snapshot) ?? (e == null ? void 0 : e.state)), f && this._snapshot.status !== "active" && this.system._unregister(this);
    }
    _initState(t) {
      var _a9;
      try {
        this._snapshot = t ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(t, this._actorScope) : t : this.logic.getInitialSnapshot(this._actorScope, (_a9 = this.options) == null ? void 0 : _a9.input);
      } catch (e) {
        this._snapshot = {
          status: "error",
          output: void 0,
          error: e
        };
      }
    }
    update(t, e) {
      var _a9, _b3;
      this._snapshot = t;
      let r;
      for (; r = this._deferred.shift(); )
        try {
          r();
        } catch (s) {
          this._deferred.length = 0, this._snapshot = {
            ...t,
            status: "error",
            error: s
          };
        }
      switch (this._snapshot.status) {
        case "active":
          for (const s of this.observers)
            try {
              (_a9 = s.next) == null ? void 0 : _a9.call(s, t);
            } catch (o) {
              Jt(o);
            }
          break;
        case "done":
          for (const s of this.observers)
            try {
              (_b3 = s.next) == null ? void 0 : _b3.call(s, t);
            } catch (o) {
              Jt(o);
            }
          this._stopProcedure(), this._complete(), this._doneEvent = Wd(this.id, this._snapshot.output), this._parent && this.system._relay(this, this._parent, this._doneEvent);
          break;
        case "error":
          this._error(this._snapshot.error);
          break;
      }
      this.system._sendInspectionEvent({
        type: "@xstate.snapshot",
        actorRef: this,
        event: e,
        snapshot: t
      });
    }
    subscribe(t, e, r) {
      var _a9;
      const s = jr(t, e, r);
      if (this._processingStatus !== Rt.Stopped)
        this.observers.add(s);
      else
        switch (this._snapshot.status) {
          case "done":
            try {
              (_a9 = s.complete) == null ? void 0 : _a9.call(s);
            } catch (o) {
              Jt(o);
            }
            break;
          case "error": {
            const o = this._snapshot.error;
            if (!s.error)
              Jt(o);
            else
              try {
                s.error(o);
              } catch (i) {
                Jt(i);
              }
            break;
          }
        }
      return {
        unsubscribe: () => {
          this.observers.delete(s);
        }
      };
    }
    on(t, e) {
      let r = this.eventListeners.get(t);
      r || (r = /* @__PURE__ */ new Set(), this.eventListeners.set(t, r));
      const s = e.bind(void 0);
      return r.add(s), {
        unsubscribe: () => {
          r.delete(s);
        }
      };
    }
    start() {
      if (this._processingStatus === Rt.Running)
        return this;
      this._syncSnapshot && this.subscribe({
        next: (r) => {
          r.status === "active" && this.system._relay(this, this._parent, {
            type: `xstate.snapshot.${this.id}`,
            snapshot: r
          });
        },
        error: () => {
        }
      }), this.system._register(this.sessionId, this), this.systemId && this.system._set(this.systemId, this), this._processingStatus = Rt.Running;
      const t = Za(this.options.input);
      switch (this.system._sendInspectionEvent({
        type: "@xstate.event",
        sourceRef: this._parent,
        actorRef: this,
        event: t
      }), this._snapshot.status) {
        case "done":
          return this.update(this._snapshot, t), this;
        case "error":
          return this._error(this._snapshot.error), this;
      }
      if (this._parent || this.system.start(), this.logic.start)
        try {
          this.logic.start(this._snapshot, this._actorScope);
        } catch (r) {
          return this._snapshot = {
            ...this._snapshot,
            status: "error",
            error: r
          }, this._error(r), this;
        }
      return this.update(this._snapshot, t), this.options.devTools && this.attachDevTools(), this.mailbox.start(), this;
    }
    _process(t) {
      let e, r;
      try {
        e = this.logic.transition(this._snapshot, t, this._actorScope);
      } catch (s) {
        r = {
          err: s
        };
      }
      if (r) {
        const { err: s } = r;
        this._snapshot = {
          ...this._snapshot,
          status: "error",
          error: s
        }, this._error(s);
        return;
      }
      this.update(e, t), t.type === Er && (this._stopProcedure(), this._complete());
    }
    _stop() {
      return this._processingStatus === Rt.Stopped ? this : (this.mailbox.clear(), this._processingStatus === Rt.NotStarted ? (this._processingStatus = Rt.Stopped, this) : (this.mailbox.enqueue({
        type: Er
      }), this));
    }
    stop() {
      if (this._parent)
        throw new Error("A non-root actor cannot be stopped directly.");
      return this._stop();
    }
    _complete() {
      var _a9;
      for (const t of this.observers)
        try {
          (_a9 = t.complete) == null ? void 0 : _a9.call(t);
        } catch (e) {
          Jt(e);
        }
      this.observers.clear();
    }
    _reportError(t) {
      if (!this.observers.size) {
        this._parent || Jt(t);
        return;
      }
      let e = false;
      for (const r of this.observers) {
        const s = r.error;
        e || (e = !s);
        try {
          s == null ? void 0 : s(t);
        } catch (o) {
          Jt(o);
        }
      }
      this.observers.clear(), e && Jt(t);
    }
    _error(t) {
      this._stopProcedure(), this._reportError(t), this._parent && this.system._relay(this, this._parent, Xa(this.id, t));
    }
    _stopProcedure() {
      return this._processingStatus !== Rt.Running ? this : (this.system.scheduler.cancelAll(this), this.mailbox.clear(), this.mailbox = new io(this._process.bind(this)), this._processingStatus = Rt.Stopped, this.system._unregister(this), this);
    }
    _send(t) {
      this._processingStatus !== Rt.Stopped && this.mailbox.enqueue(t);
    }
    send(t) {
      this.system._relay(void 0, this, t);
    }
    attachDevTools() {
      const { devTools: t } = this.options;
      t && (typeof t == "function" ? t : Pd)(this);
    }
    toJSON() {
      return {
        xstate$$type: ks,
        id: this.id
      };
    }
    getPersistedSnapshot(t) {
      return this.logic.getPersistedSnapshot(this._snapshot, t);
    }
    [Kd]() {
      return this;
    }
    getSnapshot() {
      return this._snapshot;
    }
  }
  dn = function(n, ...[t]) {
    return new Zd(n, t);
  };
  function Qd(n, t, e, r, { sendId: s }) {
    const o = typeof s == "function" ? s(e, r) : s;
    return [
      t,
      {
        sendId: o
      },
      void 0
    ];
  }
  function tl(n, t) {
    n.defer(() => {
      n.system.scheduler.cancel(n.self, t.sendId);
    });
  }
  function As(n) {
    function t(e, r) {
    }
    return t.type = "xstate.cancel", t.sendId = n, t.resolve = Qd, t.execute = tl, t;
  }
  function el(n, t, e, r, { id: s, systemId: o, src: i, input: a, syncSnapshot: c }) {
    const f = typeof i == "string" ? Is(t.machine, i) : i, u = typeof s == "function" ? s(e) : s;
    let _, d;
    return f && (d = typeof a == "function" ? a({
      context: t.context,
      event: e.event,
      self: n.self
    }) : a, _ = dn(f, {
      id: u,
      src: i,
      parent: n.self,
      syncSnapshot: c,
      systemId: o,
      input: d
    })), [
      je(t, {
        children: {
          ...t.children,
          [u]: _
        }
      }),
      {
        id: s,
        systemId: o,
        actorRef: _,
        src: i,
        input: d
      },
      void 0
    ];
  }
  function nl(n, { actorRef: t }) {
    t && n.defer(() => {
      t._processingStatus !== Rt.Stopped && t.start();
    });
  }
  function Es(...[n, { id: t, systemId: e, input: r, syncSnapshot: s = false } = {}]) {
    function o(i, a) {
    }
    return o.type = "xstate.spawnChild", o.id = t, o.systemId = e, o.src = n, o.input = r, o.syncSnapshot = s, o.resolve = el, o.execute = nl, o;
  }
  function rl(n, t, e, r, { actorRef: s }) {
    const o = typeof s == "function" ? s(e, r) : s, i = typeof o == "string" ? t.children[o] : o;
    let a = t.children;
    return i && (a = {
      ...a
    }, delete a[i.id]), [
      je(t, {
        children: a
      }),
      i,
      void 0
    ];
  }
  function sl(n, t) {
    if (t) {
      if (n.system._unregister(t), t._processingStatus !== Rt.Running) {
        n.stopChild(t);
        return;
      }
      n.defer(() => {
        n.stopChild(t);
      });
    }
  }
  function nr(n) {
    function t(e, r) {
    }
    return t.type = "xstate.stopChild", t.actorRef = n, t.resolve = rl, t.execute = sl, t;
  }
  function ol(n, t, { stateValue: e }) {
    if (typeof e == "string" && Sn(e)) {
      const r = n.machine.getStateNodeById(e);
      return n._nodes.some((s) => s === r);
    }
    return n.matches(e);
  }
  mg = function(n) {
    function t() {
      return false;
    }
    return t.check = ol, t.stateValue = n, t;
  };
  function rr(n, t, e, r) {
    const { machine: s } = r, o = typeof n == "function", i = o ? n : s.implementations.guards[typeof n == "string" ? n : n.type];
    if (!o && !i)
      throw new Error(`Guard '${typeof n == "string" ? n : n.type}' is not implemented.'.`);
    if (typeof i != "function")
      return rr(i, t, e, r);
    const a = {
      context: t,
      event: e
    }, c = o || typeof n == "string" ? void 0 : "params" in n ? typeof n.params == "function" ? n.params({
      context: t,
      event: e
    }) : n.params : void 0;
    return "check" in i ? i.check(r, a, i) : i(a, c);
  }
  const Cs = (n) => n.type === "atomic" || n.type === "final";
  function Ne(n) {
    return Object.values(n.states).filter((t) => t.type !== "history");
  }
  function vn(n, t) {
    const e = [];
    if (t === n)
      return e;
    let r = n.parent;
    for (; r && r !== t; )
      e.push(r), r = r.parent;
    return e;
  }
  function Vn(n) {
    const t = new Set(n), e = sc(t);
    for (const r of t)
      if (r.type === "compound" && (!e.get(r) || !e.get(r).length))
        fo(r).forEach((s) => t.add(s));
      else if (r.type === "parallel") {
        for (const s of Ne(r))
          if (s.type !== "history" && !t.has(s)) {
            const o = fo(s);
            for (const i of o)
              t.add(i);
          }
      }
    for (const r of t) {
      let s = r.parent;
      for (; s; )
        t.add(s), s = s.parent;
    }
    return t;
  }
  function rc(n, t) {
    const e = t.get(n);
    if (!e)
      return {};
    if (n.type === "compound") {
      const s = e[0];
      if (s) {
        if (Cs(s))
          return s.key;
      } else
        return {};
    }
    const r = {};
    for (const s of e)
      r[s.key] = rc(s, t);
    return r;
  }
  function sc(n) {
    const t = /* @__PURE__ */ new Map();
    for (const e of n)
      t.has(e) || t.set(e, []), e.parent && (t.has(e.parent) || t.set(e.parent, []), t.get(e.parent).push(e));
    return t;
  }
  function oc(n, t) {
    const e = Vn(t);
    return rc(n, sc(e));
  }
  function Os(n, t) {
    return t.type === "compound" ? Ne(t).some((e) => e.type === "final" && n.has(e)) : t.type === "parallel" ? Ne(t).every((e) => Os(n, e)) : t.type === "final";
  }
  const Sn = (n) => n[0] === Ld;
  function il(n, t) {
    return n.transitions.get(t) || [
      ...n.transitions.keys()
    ].filter((r) => {
      if (r === Vd)
        return true;
      if (!r.endsWith(".*"))
        return false;
      const s = r.split("."), o = t.split(".");
      for (let i = 0; i < s.length; i++) {
        const a = s[i], c = o[i];
        if (a === "*")
          return i === s.length - 1;
        if (a !== c)
          return false;
      }
      return true;
    }).sort((r, s) => s.length - r.length).flatMap((r) => n.transitions.get(r));
  }
  function al(n) {
    const t = n.config.after;
    if (!t)
      return [];
    const e = (s) => {
      const o = Nd(s, n.id), i = o.type;
      return n.entry.push(Ts(o, {
        id: i,
        delay: s
      })), n.exit.push(As(i)), i;
    };
    return Object.keys(t).flatMap((s) => {
      const o = t[s], i = typeof o == "string" ? {
        target: o
      } : o, a = Number.isNaN(+s) ? s : +s, c = e(a);
      return ce(i).map((f) => ({
        ...f,
        event: c,
        delay: a
      }));
    }).map((s) => {
      const { delay: o } = s;
      return {
        ...Ee(n, s.event, s),
        delay: o
      };
    });
  }
  function Ee(n, t, e) {
    const r = nc(e.target), s = e.reenter ?? false, o = ul(n, r), i = {
      ...e,
      actions: ce(e.actions),
      guard: e.guard,
      target: o,
      source: n,
      reenter: s,
      eventType: t,
      toJSON: () => ({
        ...i,
        source: `#${n.id}`,
        target: o ? o.map((a) => `#${a.id}`) : void 0
      })
    };
    return i;
  }
  function cl(n) {
    const t = /* @__PURE__ */ new Map();
    if (n.config.on)
      for (const e of Object.keys(n.config.on)) {
        if (e === qa)
          throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
        const r = n.config.on[e];
        t.set(e, $e(r).map((s) => Ee(n, e, s)));
      }
    if (n.config.onDone) {
      const e = `xstate.done.state.${n.id}`;
      t.set(e, $e(n.config.onDone).map((r) => Ee(n, e, r)));
    }
    for (const e of n.invoke) {
      if (e.onDone) {
        const r = `xstate.done.actor.${e.id}`;
        t.set(r, $e(e.onDone).map((s) => Ee(n, r, s)));
      }
      if (e.onError) {
        const r = `xstate.error.actor.${e.id}`;
        t.set(r, $e(e.onError).map((s) => Ee(n, r, s)));
      }
      if (e.onSnapshot) {
        const r = `xstate.snapshot.${e.id}`;
        t.set(r, $e(e.onSnapshot).map((s) => Ee(n, r, s)));
      }
    }
    for (const e of n.after) {
      let r = t.get(e.eventType);
      r || (r = [], t.set(e.eventType, r)), r.push(e);
    }
    return t;
  }
  function _l(n, t) {
    const e = typeof t == "string" ? n.states[t] : t ? n.states[t.target] : void 0;
    if (!e && t)
      throw new Error(`Initial state node "${t}" not found on parent state node #${n.id}`);
    const r = {
      source: n,
      actions: !t || typeof t == "string" ? [] : ce(t.actions),
      eventType: null,
      reenter: false,
      target: e ? [
        e
      ] : [],
      toJSON: () => ({
        ...r,
        source: `#${n.id}`,
        target: e ? [
          `#${e.id}`
        ] : []
      })
    };
    return r;
  }
  function ul(n, t) {
    if (t !== void 0)
      return t.map((e) => {
        if (typeof e != "string")
          return e;
        if (Sn(e))
          return n.machine.getStateNodeById(e);
        const r = e[0] === Ga;
        if (r && !n.parent)
          return zn(n, e.slice(1));
        const s = r ? n.key + e : e;
        if (n.parent)
          try {
            return zn(n.parent, s);
          } catch (o) {
            throw new Error(`Invalid transition definition for state node '${n.id}':
${o.message}`);
          }
        else
          throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);
      });
  }
  function ic(n) {
    const t = nc(n.config.target);
    return t ? {
      target: t.map((e) => typeof e == "string" ? zn(n.parent, e) : e)
    } : n.parent.initial;
  }
  function Ce(n) {
    return n.type === "history";
  }
  function fo(n) {
    const t = ac(n);
    for (const e of t)
      for (const r of vn(e, n))
        t.add(r);
    return t;
  }
  function ac(n) {
    const t = /* @__PURE__ */ new Set();
    function e(r) {
      if (!t.has(r)) {
        if (t.add(r), r.type === "compound")
          e(r.initial.target[0]);
        else if (r.type === "parallel")
          for (const s of Ne(r))
            e(s);
      }
    }
    return e(n), t;
  }
  function We(n, t) {
    if (Sn(t))
      return n.machine.getStateNodeById(t);
    if (!n.states)
      throw new Error(`Unable to retrieve child state '${t}' from '${n.id}'; no child states exist.`);
    const e = n.states[t];
    if (!e)
      throw new Error(`Child state '${t}' does not exist on '${n.id}'`);
    return e;
  }
  function zn(n, t) {
    if (typeof t == "string" && Sn(t))
      try {
        return n.machine.getStateNodeById(t);
      } catch {
      }
    const e = xs(t).slice();
    let r = n;
    for (; e.length; ) {
      const s = e.shift();
      if (!s.length)
        break;
      r = We(r, s);
    }
    return r;
  }
  function Nn(n, t) {
    if (typeof t == "string") {
      const s = n.states[t];
      if (!s)
        throw new Error(`State '${t}' does not exist on '${n.id}'`);
      return [
        n,
        s
      ];
    }
    const e = Object.keys(t), r = e.map((s) => We(n, s)).filter(Boolean);
    return [
      n.machine.root,
      n
    ].concat(r, e.reduce((s, o) => {
      const i = We(n, o);
      if (!i)
        return s;
      const a = Nn(i, t[o]);
      return s.concat(a);
    }, []));
  }
  function fl(n, t, e, r) {
    const o = We(n, t).next(e, r);
    return !o || !o.length ? n.next(e, r) : o;
  }
  function dl(n, t, e, r) {
    const s = Object.keys(t), o = We(n, s[0]), i = js(o, t[s[0]], e, r);
    return !i || !i.length ? n.next(e, r) : i;
  }
  function ll(n, t, e, r) {
    const s = [];
    for (const o of Object.keys(t)) {
      const i = t[o];
      if (!i)
        continue;
      const a = We(n, o), c = js(a, i, e, r);
      c && s.push(...c);
    }
    return s.length ? s : n.next(e, r);
  }
  function js(n, t, e, r) {
    return typeof t == "string" ? fl(n, t, e, r) : Object.keys(t).length === 1 ? dl(n, t, e, r) : ll(n, t, e, r);
  }
  function hl(n) {
    return Object.keys(n.states).map((t) => n.states[t]).filter((t) => t.type === "history");
  }
  function we(n, t) {
    let e = n;
    for (; e.parent && e.parent !== t; )
      e = e.parent;
    return e.parent === t;
  }
  function gl(n, t) {
    const e = new Set(n), r = new Set(t);
    for (const s of e)
      if (r.has(s))
        return true;
    for (const s of r)
      if (e.has(s))
        return true;
    return false;
  }
  function cc(n, t, e) {
    const r = /* @__PURE__ */ new Set();
    for (const s of n) {
      let o = false;
      const i = /* @__PURE__ */ new Set();
      for (const a of r)
        if (gl(Rr([
          s
        ], t, e), Rr([
          a
        ], t, e)))
          if (we(s.source, a.source))
            i.add(a);
          else {
            o = true;
            break;
          }
      if (!o) {
        for (const a of i)
          r.delete(a);
        r.add(s);
      }
    }
    return Array.from(r);
  }
  function bl(n) {
    const [t, ...e] = n;
    for (const r of vn(t, void 0))
      if (e.every((s) => we(s, r)))
        return r;
  }
  function Rs(n, t) {
    if (!n.target)
      return [];
    const e = /* @__PURE__ */ new Set();
    for (const r of n.target)
      if (Ce(r))
        if (t[r.id])
          for (const s of t[r.id])
            e.add(s);
        else
          for (const s of Rs(ic(r), t))
            e.add(s);
      else
        e.add(r);
    return [
      ...e
    ];
  }
  function _c(n, t) {
    const e = Rs(n, t);
    if (!e)
      return;
    if (!n.reenter && e.every((s) => s === n.source || we(s, n.source)))
      return n.source;
    const r = bl(e.concat(n.source));
    if (r)
      return r;
    if (!n.reenter)
      return n.source.machine.root;
  }
  function Rr(n, t, e) {
    var _a9;
    const r = /* @__PURE__ */ new Set();
    for (const s of n)
      if ((_a9 = s.target) == null ? void 0 : _a9.length) {
        const o = _c(s, e);
        s.reenter && s.source === o && r.add(o);
        for (const i of t)
          we(i, o) && r.add(i);
      }
    return [
      ...r
    ];
  }
  function pl(n, t) {
    if (n.length !== t.size)
      return false;
    for (const e of n)
      if (!t.has(e))
        return false;
    return true;
  }
  function Tr(n, t, e, r, s, o) {
    if (!n.length)
      return t;
    const i = new Set(t._nodes);
    let a = t.historyValue;
    const c = cc(n, i, a);
    let f = t;
    s || ([f, a] = vl(f, r, e, c, i, a, o, e.actionExecutor)), f = Ke(f, r, e, c.flatMap((_) => _.actions), o, void 0), f = yl(f, r, e, c, i, o, a, s);
    const u = [
      ...i
    ];
    f.status === "done" && (f = Ke(f, r, e, u.sort((_, d) => d.order - _.order).flatMap((_) => _.exit), o, void 0));
    try {
      return a === t.historyValue && pl(t._nodes, i) ? f : je(f, {
        _nodes: u,
        historyValue: a
      });
    } catch (_) {
      throw _;
    }
  }
  function wl(n, t, e, r, s) {
    if (r.output === void 0)
      return;
    const o = Cr(s.id, s.output !== void 0 && s.parent ? Or(s.output, n.context, t, e.self) : void 0);
    return Or(r.output, n.context, o, e.self);
  }
  function yl(n, t, e, r, s, o, i, a) {
    let c = n;
    const f = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
    ml(r, i, u, f), a && u.add(n.machine.root);
    const _ = /* @__PURE__ */ new Set();
    for (const d of [
      ...f
    ].sort((l, w) => l.order - w.order)) {
      s.add(d);
      const l = [];
      l.push(...d.entry);
      for (const w of d.invoke)
        l.push(Es(w.src, {
          ...w,
          syncSnapshot: !!w.onSnapshot
        }));
      if (u.has(d)) {
        const w = d.initial.actions;
        l.push(...w);
      }
      if (c = Ke(c, t, e, l, o, d.invoke.map((w) => w.id)), d.type === "final") {
        const w = d.parent;
        let k = (w == null ? void 0 : w.type) === "parallel" ? w : w == null ? void 0 : w.parent, j = k || d;
        for ((w == null ? void 0 : w.type) === "compound" && o.push(Cr(w.id, d.output !== void 0 ? Or(d.output, c.context, t, e.self) : void 0)); (k == null ? void 0 : k.type) === "parallel" && !_.has(k) && Os(s, k); )
          _.add(k), o.push(Cr(k.id)), j = k, k = k.parent;
        if (k)
          continue;
        c = je(c, {
          status: "done",
          output: wl(c, t, e, c.machine.root, j)
        });
      }
    }
    return c;
  }
  function ml(n, t, e, r) {
    for (const s of n) {
      const o = _c(s, t);
      for (const a of s.target || [])
        !Ce(a) && (s.source !== a || s.source !== o || s.reenter) && (r.add(a), e.add(a)), Be(a, t, e, r);
      const i = Rs(s, t);
      for (const a of i) {
        const c = vn(a, o);
        (o == null ? void 0 : o.type) === "parallel" && c.push(o), uc(r, t, e, c, !s.source.parent && s.reenter ? void 0 : o);
      }
    }
  }
  function Be(n, t, e, r) {
    var _a9;
    if (Ce(n))
      if (t[n.id]) {
        const s = t[n.id];
        for (const o of s)
          r.add(o), Be(o, t, e, r);
        for (const o of s)
          _r(o, n.parent, r, t, e);
      } else {
        const s = ic(n);
        for (const o of s.target)
          r.add(o), s === ((_a9 = n.parent) == null ? void 0 : _a9.initial) && e.add(n.parent), Be(o, t, e, r);
        for (const o of s.target)
          _r(o, n.parent, r, t, e);
      }
    else if (n.type === "compound") {
      const [s] = n.initial.target;
      Ce(s) || (r.add(s), e.add(s)), Be(s, t, e, r), _r(s, n, r, t, e);
    } else if (n.type === "parallel")
      for (const s of Ne(n).filter((o) => !Ce(o)))
        [
          ...r
        ].some((o) => we(o, s)) || (Ce(s) || (r.add(s), e.add(s)), Be(s, t, e, r));
  }
  function uc(n, t, e, r, s) {
    for (const o of r)
      if ((!s || we(o, s)) && n.add(o), o.type === "parallel")
        for (const i of Ne(o).filter((a) => !Ce(a)))
          [
            ...n
          ].some((a) => we(a, i)) || (n.add(i), Be(i, t, e, n));
  }
  function _r(n, t, e, r, s) {
    uc(e, r, s, vn(n, t));
  }
  function vl(n, t, e, r, s, o, i, a) {
    let c = n;
    const f = Rr(r, s, o);
    f.sort((_, d) => d.order - _.order);
    let u;
    for (const _ of f)
      for (const d of hl(_)) {
        let l;
        d.history === "deep" ? l = (w) => Cs(w) && we(w, _) : l = (w) => w.parent === _, u ?? (u = {
          ...o
        }), u[d.id] = Array.from(s).filter(l);
      }
    for (const _ of f)
      c = Ke(c, t, e, [
        ..._.exit,
        ..._.invoke.map((d) => nr(d.id))
      ], i, void 0), s.delete(_);
    return [
      c,
      u || o
    ];
  }
  function Sl(n, t) {
    return n.implementations.actions[t];
  }
  function fc(n, t, e, r, s, o) {
    const { machine: i } = n;
    let a = n;
    for (const c of r) {
      const f = typeof c == "function", u = f ? c : Sl(i, typeof c == "string" ? c : c.type), _ = {
        context: a.context,
        event: t,
        self: e.self,
        system: e.system
      }, d = f || typeof c == "string" ? void 0 : "params" in c ? typeof c.params == "function" ? c.params({
        context: a.context,
        event: t
      }) : c.params : void 0;
      if (!u || !("resolve" in u)) {
        e.actionExecutor({
          type: typeof c == "string" ? c : typeof c == "object" ? c.type : c.name || "(anonymous)",
          info: _,
          params: d,
          exec: u
        });
        continue;
      }
      const l = u, [w, k, j] = l.resolve(e, a, _, d, u, s);
      a = w, "retryResolve" in l && (o == null ? void 0 : o.push([
        l,
        k
      ])), "execute" in l && e.actionExecutor({
        type: l.type,
        info: _,
        params: k,
        exec: l.execute.bind(null, e, k)
      }), j && (a = fc(a, t, e, j, s, o));
    }
    return a;
  }
  function Ke(n, t, e, r, s, o) {
    const i = o ? [] : void 0, a = fc(n, t, e, r, {
      internalQueue: s,
      deferredActorIds: o
    }, i);
    return i == null ? void 0 : i.forEach(([c, f]) => {
      c.retryResolve(e, a, f);
    }), a;
  }
  function ur(n, t, e, r) {
    let s = n;
    const o = [];
    function i(f, u, _) {
      e.system._sendInspectionEvent({
        type: "@xstate.microstep",
        actorRef: e.self,
        event: u,
        snapshot: f,
        _transitions: _
      }), o.push(f);
    }
    if (t.type === Er)
      return s = je(lo(s, t, e), {
        status: "stopped"
      }), i(s, t, []), {
        snapshot: s,
        microstates: o
      };
    let a = t;
    if (a.type !== Ya) {
      const f = a, u = Gd(f), _ = ho(f, s);
      if (u && !_.length)
        return s = je(n, {
          status: "error",
          error: f.error
        }), i(s, f, []), {
          snapshot: s,
          microstates: o
        };
      s = Tr(_, n, e, a, false, r), i(s, f, _);
    }
    let c = true;
    for (; s.status === "active"; ) {
      let f = c ? xl(s, a) : [];
      const u = f.length ? s : void 0;
      if (!f.length) {
        if (!r.length)
          break;
        a = r.shift(), f = ho(a, s);
      }
      s = Tr(f, s, e, a, false, r), c = s !== u, i(s, a, f);
    }
    return s.status !== "active" && lo(s, a, e), {
      snapshot: s,
      microstates: o
    };
  }
  function lo(n, t, e) {
    return Ke(n, t, e, Object.values(n.children).map((r) => nr(r)), [], void 0);
  }
  function ho(n, t) {
    return t.machine.getTransitionData(t, n);
  }
  function xl(n, t) {
    const e = /* @__PURE__ */ new Set(), r = n._nodes.filter(Cs);
    for (const s of r)
      t:
        for (const o of [
          s
        ].concat(vn(s, void 0)))
          if (o.always) {
            for (const i of o.always)
              if (i.guard === void 0 || rr(i.guard, n.context, t, n)) {
                e.add(i);
                break t;
              }
          }
    return cc(Array.from(e), new Set(n._nodes), n.historyValue);
  }
  function Il(n, t) {
    const e = Vn(Nn(n, t));
    return oc(n, [
      ...e
    ]);
  }
  function kl(n) {
    return !!n && typeof n == "object" && "machine" in n && "value" in n;
  }
  const Al = function(t) {
    return Qa(t, this.value);
  }, El = function(t) {
    return this.tags.has(t);
  }, Cl = function(t) {
    const e = this.machine.getTransitionData(this, t);
    return !!(e == null ? void 0 : e.length) && e.some((r) => r.target !== void 0 || r.actions.length);
  }, Ol = function() {
    const { _nodes: t, tags: e, machine: r, getMeta: s, toJSON: o, can: i, hasTag: a, matches: c, ...f } = this;
    return {
      ...f,
      tags: Array.from(e)
    };
  }, jl = function() {
    return this._nodes.reduce((t, e) => (e.meta !== void 0 && (t[e.id] = e.meta), t), {});
  };
  function Un(n, t) {
    return {
      status: n.status,
      output: n.output,
      error: n.error,
      machine: t,
      context: n.context,
      _nodes: n._nodes,
      value: oc(t.root, n._nodes),
      tags: new Set(n._nodes.flatMap((e) => e.tags)),
      children: n.children,
      historyValue: n.historyValue || {},
      matches: Al,
      hasTag: El,
      can: Cl,
      getMeta: jl,
      toJSON: Ol
    };
  }
  function je(n, t = {}) {
    return Un({
      ...n,
      ...t
    }, n.machine);
  }
  function Rl(n) {
    if (typeof n != "object" || n === null)
      return {};
    const t = {};
    for (const e in n) {
      const r = n[e];
      Array.isArray(r) && (t[e] = r.map((s) => ({
        id: s.id
      })));
    }
    return t;
  }
  function Tl(n, t) {
    const { _nodes: e, tags: r, machine: s, children: o, context: i, can: a, hasTag: c, matches: f, getMeta: u, toJSON: _, ...d } = n, l = {};
    for (const k in o) {
      const j = o[k];
      l[k] = {
        snapshot: j.getPersistedSnapshot(t),
        src: j.src,
        systemId: j.systemId,
        syncSnapshot: j._syncSnapshot
      };
    }
    return {
      ...d,
      context: dc(i),
      children: l,
      historyValue: Rl(d.historyValue)
    };
  }
  function dc(n) {
    let t;
    for (const e in n) {
      const r = n[e];
      if (r && typeof r == "object")
        if ("sessionId" in r && "send" in r && "ref" in r)
          t ?? (t = Array.isArray(n) ? n.slice() : {
            ...n
          }), t[e] = {
            xstate$$type: ks,
            id: r.id
          };
        else {
          const s = dc(r);
          s !== r && (t ?? (t = Array.isArray(n) ? n.slice() : {
            ...n
          }), t[e] = s);
        }
    }
    return t ?? n;
  }
  function Ml(n, t, e, r, { event: s, id: o, delay: i }, { internalQueue: a }) {
    const c = t.machine.implementations.delays;
    if (typeof s == "string")
      throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);
    const f = typeof s == "function" ? s(e, r) : s;
    let u;
    if (typeof i == "string") {
      const _ = c && c[i];
      u = typeof _ == "function" ? _(e, r) : _;
    } else
      u = typeof i == "function" ? i(e, r) : i;
    return typeof u != "number" && a.push(f), [
      t,
      {
        event: f,
        id: o,
        delay: u
      },
      void 0
    ];
  }
  function Hl(n, t) {
    const { event: e, delay: r, id: s } = t;
    if (typeof r == "number") {
      n.defer(() => {
        const o = n.self;
        n.system.scheduler.schedule(o, o, e, r, s);
      });
      return;
    }
  }
  Ts = function(n, t) {
    function e(r, s) {
    }
    return e.type = "xstate.raise", e.event = n, e.id = t == null ? void 0 : t.id, e.delay = t == null ? void 0 : t.delay, e.resolve = Ml, e.execute = Hl, e;
  };
  function Dl(n, { machine: t, context: e }, r, s) {
    const o = (i, a) => {
      if (typeof i == "string") {
        const c = Is(t, i);
        if (!c)
          throw new Error(`Actor logic '${i}' not implemented in machine '${t.id}'`);
        const f = dn(c, {
          id: a == null ? void 0 : a.id,
          parent: n.self,
          syncSnapshot: a == null ? void 0 : a.syncSnapshot,
          input: typeof (a == null ? void 0 : a.input) == "function" ? a.input({
            context: e,
            event: r,
            self: n.self
          }) : a == null ? void 0 : a.input,
          src: i,
          systemId: a == null ? void 0 : a.systemId
        });
        return s[f.id] = f, f;
      } else
        return dn(i, {
          id: a == null ? void 0 : a.id,
          parent: n.self,
          syncSnapshot: a == null ? void 0 : a.syncSnapshot,
          input: a == null ? void 0 : a.input,
          src: i,
          systemId: a == null ? void 0 : a.systemId
        });
    };
    return (i, a) => {
      const c = o(i, a);
      return s[c.id] = c, n.defer(() => {
        c._processingStatus !== Rt.Stopped && c.start();
      }), c;
    };
  }
  function $l(n, t, e, r, { assignment: s }) {
    if (!t.context)
      throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
    const o = {}, i = {
      context: t.context,
      event: e.event,
      spawn: Dl(n, t, e.event, o),
      self: n.self,
      system: n.system
    };
    let a = {};
    if (typeof s == "function")
      a = s(i, r);
    else
      for (const f of Object.keys(s)) {
        const u = s[f];
        a[f] = typeof u == "function" ? u(i, r) : u;
      }
    const c = Object.assign({}, t.context, a);
    return [
      je(t, {
        context: c,
        children: Object.keys(o).length ? {
          ...t.children,
          ...o
        } : t.children
      }),
      void 0,
      void 0
    ];
  }
  function ln(n) {
    function t(e, r) {
    }
    return t.type = "xstate.assign", t.assignment = n, t.resolve = $l, t;
  }
  const go = /* @__PURE__ */ new WeakMap();
  function Me(n, t, e) {
    let r = go.get(n);
    return r ? t in r || (r[t] = e()) : (r = {
      [t]: e()
    }, go.set(n, r)), r[t];
  }
  const Ul = {}, Ye = (n) => typeof n == "string" ? {
    type: n
  } : typeof n == "function" ? "resolve" in n ? {
    type: n.type
  } : {
    type: n.name
  } : n;
  class Wn {
    constructor(t, e) {
      if (this.config = t, this.key = void 0, this.id = void 0, this.type = void 0, this.path = void 0, this.states = void 0, this.history = void 0, this.entry = void 0, this.exit = void 0, this.parent = void 0, this.machine = void 0, this.meta = void 0, this.output = void 0, this.order = -1, this.description = void 0, this.tags = [], this.transitions = void 0, this.always = void 0, this.parent = e._parent, this.key = e._key, this.machine = e._machine, this.path = this.parent ? this.parent.path.concat(this.key) : [], this.id = this.config.id || [
        this.machine.id,
        ...this.path
      ].join(Ga), this.type = this.config.type || (this.config.states && Object.keys(this.config.states).length ? "compound" : this.config.history ? "history" : "atomic"), this.description = this.config.description, this.order = this.machine.idMap.size, this.machine.idMap.set(this.id, this), this.states = this.config.states ? co(this.config.states, (r, s) => new Wn(r, {
        _parent: this,
        _key: s,
        _machine: this.machine
      })) : Ul, this.type === "compound" && !this.config.initial)
        throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);
      this.history = this.config.history === true ? "shallow" : this.config.history || false, this.entry = ce(this.config.entry).slice(), this.exit = ce(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = ce(t.tags).slice();
    }
    _initialize() {
      this.transitions = cl(this), this.config.always && (this.always = $e(this.config.always).map((t) => Ee(this, qa, t))), Object.keys(this.states).forEach((t) => {
        this.states[t]._initialize();
      });
    }
    get definition() {
      return {
        id: this.id,
        key: this.key,
        version: this.machine.version,
        type: this.type,
        initial: this.initial ? {
          target: this.initial.target,
          source: this,
          actions: this.initial.actions.map(Ye),
          eventType: null,
          reenter: false,
          toJSON: () => ({
            target: this.initial.target.map((t) => `#${t.id}`),
            source: `#${this.id}`,
            actions: this.initial.actions.map(Ye),
            eventType: null
          })
        } : void 0,
        history: this.history,
        states: co(this.states, (t) => t.definition),
        on: this.on,
        transitions: [
          ...this.transitions.values()
        ].flat().map((t) => ({
          ...t,
          actions: t.actions.map(Ye)
        })),
        entry: this.entry.map(Ye),
        exit: this.exit.map(Ye),
        meta: this.meta,
        order: this.order || -1,
        output: this.output,
        invoke: this.invoke,
        description: this.description,
        tags: this.tags
      };
    }
    toJSON() {
      return this.definition;
    }
    get invoke() {
      return Me(this, "invoke", () => ce(this.config.invoke).map((t, e) => {
        const { src: r, systemId: s } = t, o = t.id ?? _o(this.id, e), i = typeof r == "string" ? r : `xstate.invoke.${_o(this.id, e)}`;
        return {
          ...t,
          src: i,
          id: o,
          systemId: s,
          toJSON() {
            const { onDone: a, onError: c, ...f } = t;
            return {
              ...f,
              type: "xstate.invoke",
              src: i,
              id: o
            };
          }
        };
      }));
    }
    get on() {
      return Me(this, "on", () => [
        ...this.transitions
      ].flatMap(([e, r]) => r.map((s) => [
        e,
        s
      ])).reduce((e, [r, s]) => (e[r] = e[r] || [], e[r].push(s), e), {}));
    }
    get after() {
      return Me(this, "delayedTransitions", () => al(this));
    }
    get initial() {
      return Me(this, "initial", () => _l(this, this.config.initial));
    }
    next(t, e) {
      const r = e.type, s = [];
      let o;
      const i = Me(this, `candidates-${r}`, () => il(this, r));
      for (const a of i) {
        const { guard: c } = a, f = t.context;
        let u = false;
        try {
          u = !c || rr(c, f, e, t);
        } catch (_) {
          const d = typeof c == "string" ? c : typeof c == "object" ? c.type : void 0;
          throw new Error(`Unable to evaluate guard ${d ? `'${d}' ` : ""}in transition for event '${r}' in state node '${this.id}':
${_.message}`);
        }
        if (u) {
          s.push(...a.actions), o = a;
          break;
        }
      }
      return o ? [
        o
      ] : void 0;
    }
    get events() {
      return Me(this, "events", () => {
        const { states: t } = this, e = new Set(this.ownEvents);
        if (t)
          for (const r of Object.keys(t)) {
            const s = t[r];
            if (s.states)
              for (const o of s.events)
                e.add(`${o}`);
          }
        return Array.from(e);
      });
    }
    get ownEvents() {
      const t = new Set([
        ...this.transitions.keys()
      ].filter((e) => this.transitions.get(e).some((r) => !(!r.target && !r.actions.length && !r.reenter))));
      return Array.from(t);
    }
  }
  const Bl = "#";
  class Ms {
    constructor(t, e) {
      this.config = t, this.version = void 0, this.schemas = void 0, this.implementations = void 0, this.__xstatenode = true, this.idMap = /* @__PURE__ */ new Map(), this.root = void 0, this.id = void 0, this.states = void 0, this.events = void 0, this.id = t.id || "(machine)", this.implementations = {
        actors: (e == null ? void 0 : e.actors) ?? {},
        actions: (e == null ? void 0 : e.actions) ?? {},
        delays: (e == null ? void 0 : e.delays) ?? {},
        guards: (e == null ? void 0 : e.guards) ?? {}
      }, this.version = this.config.version, this.schemas = this.config.schemas, this.transition = this.transition.bind(this), this.getInitialSnapshot = this.getInitialSnapshot.bind(this), this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this), this.restoreSnapshot = this.restoreSnapshot.bind(this), this.start = this.start.bind(this), this.root = new Wn(t, {
        _key: this.id,
        _machine: this
      }), this.root._initialize(), this.states = this.root.states, this.events = this.root.events;
    }
    provide(t) {
      const { actions: e, guards: r, actors: s, delays: o } = this.implementations;
      return new Ms(this.config, {
        actions: {
          ...e,
          ...t.actions
        },
        guards: {
          ...r,
          ...t.guards
        },
        actors: {
          ...s,
          ...t.actors
        },
        delays: {
          ...o,
          ...t.delays
        }
      });
    }
    resolveState(t) {
      const e = Il(this.root, t.value), r = Vn(Nn(this.root, e));
      return Un({
        _nodes: [
          ...r
        ],
        context: t.context || {},
        children: {},
        status: Os(r, this.root) ? "done" : t.status || "active",
        output: t.output,
        error: t.error,
        historyValue: t.historyValue
      }, this);
    }
    transition(t, e, r) {
      return ur(t, e, r, []).snapshot;
    }
    microstep(t, e, r) {
      return ur(t, e, r, []).microstates;
    }
    getTransitionData(t, e) {
      return js(this.root, t.value, t, e) || [];
    }
    getPreInitialState(t, e, r) {
      const { context: s } = this.config, o = Un({
        context: typeof s != "function" && s ? s : {},
        _nodes: [
          this.root
        ],
        children: {},
        status: "active"
      }, this);
      return typeof s == "function" ? Ke(o, e, t, [
        ln(({ spawn: a, event: c, self: f }) => s({
          spawn: a,
          input: c.input,
          self: f
        }))
      ], r, void 0) : o;
    }
    getInitialSnapshot(t, e) {
      const r = Za(e), s = [], o = this.getPreInitialState(t, r, s), i = Tr([
        {
          target: [
            ...ac(this.root)
          ],
          source: this.root,
          reenter: true,
          actions: [],
          eventType: null,
          toJSON: null
        }
      ], o, t, r, true, s), { snapshot: a } = ur(i, r, t, s);
      return a;
    }
    start(t) {
      Object.values(t.children).forEach((e) => {
        e.getSnapshot().status === "active" && e.start();
      });
    }
    getStateNodeById(t) {
      const e = xs(t), r = e.slice(1), s = Sn(e[0]) ? e[0].slice(Bl.length) : e[0], o = this.idMap.get(s);
      if (!o)
        throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);
      return zn(o, r);
    }
    get definition() {
      return this.root.definition;
    }
    toJSON() {
      return this.definition;
    }
    getPersistedSnapshot(t, e) {
      return Tl(t, e);
    }
    restoreSnapshot(t, e) {
      const r = {}, s = t.children;
      Object.keys(s).forEach((_) => {
        const d = s[_], l = d.snapshot, w = d.src, k = typeof w == "string" ? Is(this, w) : w;
        if (!k)
          return;
        const j = dn(k, {
          id: _,
          parent: e.self,
          syncSnapshot: d.syncSnapshot,
          snapshot: l,
          src: w,
          systemId: d.systemId
        });
        r[_] = j;
      });
      function o(_, d) {
        if (d instanceof Wn)
          return d;
        try {
          return _.machine.getStateNodeById(d.id);
        } catch {
        }
      }
      function i(_, d) {
        if (!d || typeof d != "object")
          return {};
        const l = {};
        for (const w in d) {
          const k = d[w];
          for (const j of k) {
            const L = o(_, j);
            L && (l[w] ?? (l[w] = []), l[w].push(L));
          }
        }
        return l;
      }
      const a = i(this.root, t.historyValue), c = Un({
        ...t,
        children: r,
        _nodes: Array.from(Vn(Nn(this.root, t.value))),
        historyValue: a
      }, this), f = /* @__PURE__ */ new Set();
      function u(_, d) {
        if (!f.has(_)) {
          f.add(_);
          for (const l in _) {
            const w = _[l];
            if (w && typeof w == "object") {
              if ("xstate$$type" in w && w.xstate$$type === ks) {
                _[l] = d[w.id];
                continue;
              }
              u(w, d);
            }
          }
        }
      }
      return u(c.context, r), c;
    }
  }
  function Pl(n, t, e, r, { event: s }) {
    const o = typeof s == "function" ? s(e, r) : s;
    return [
      t,
      {
        event: o
      },
      void 0
    ];
  }
  function Fl(n, { event: t }) {
    n.defer(() => n.emit(t));
  }
  function lc(n) {
    function t(e, r) {
    }
    return t.type = "xstate.emit", t.event = n, t.resolve = Pl, t.execute = Fl, t;
  }
  let Mr = function(n) {
    return n.Parent = "#_parent", n.Internal = "#_internal", n;
  }({});
  function Ll(n, t, e, r, { to: s, event: o, id: i, delay: a }, c) {
    var _a9;
    const f = t.machine.implementations.delays;
    if (typeof o == "string")
      throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);
    const u = typeof o == "function" ? o(e, r) : o;
    let _;
    if (typeof a == "string") {
      const w = f && f[a];
      _ = typeof w == "function" ? w(e, r) : w;
    } else
      _ = typeof a == "function" ? a(e, r) : a;
    const d = typeof s == "function" ? s(e, r) : s;
    let l;
    if (typeof d == "string") {
      if (d === Mr.Parent ? l = n.self._parent : d === Mr.Internal ? l = n.self : d.startsWith("#_") ? l = t.children[d.slice(2)] : l = ((_a9 = c.deferredActorIds) == null ? void 0 : _a9.includes(d)) ? d : t.children[d], !l)
        throw new Error(`Unable to send event to actor '${d}' from machine '${t.machine.id}'.`);
    } else
      l = d || n.self;
    return [
      t,
      {
        to: l,
        targetId: typeof d == "string" ? d : void 0,
        event: u,
        id: i,
        delay: _
      },
      void 0
    ];
  }
  function Vl(n, t, e) {
    typeof e.to == "string" && (e.to = t.children[e.to]);
  }
  function zl(n, t) {
    n.defer(() => {
      const { to: e, event: r, delay: s, id: o } = t;
      if (typeof s == "number") {
        n.system.scheduler.schedule(n.self, e, r, s, o);
        return;
      }
      n.system._relay(n.self, e, r.type === zd ? Xa(n.self.id, r.data) : r);
    });
  }
  function Hs(n, t, e) {
    function r(s, o) {
    }
    return r.type = "xstate.sendTo", r.to = n, r.event = t, r.id = e == null ? void 0 : e.id, r.delay = e == null ? void 0 : e.delay, r.resolve = Ll, r.retryResolve = Vl, r.execute = zl, r;
  }
  function Nl(n, t) {
    return Hs(Mr.Parent, n, t);
  }
  function Wl(n, t, e, r, { collect: s }) {
    const o = [], i = function(c) {
      o.push(c);
    };
    return i.assign = (...a) => {
      o.push(ln(...a));
    }, i.cancel = (...a) => {
      o.push(As(...a));
    }, i.raise = (...a) => {
      o.push(Ts(...a));
    }, i.sendTo = (...a) => {
      o.push(Hs(...a));
    }, i.sendParent = (...a) => {
      o.push(Nl(...a));
    }, i.spawnChild = (...a) => {
      o.push(Es(...a));
    }, i.stopChild = (...a) => {
      o.push(nr(...a));
    }, i.emit = (...a) => {
      o.push(lc(...a));
    }, s({
      context: e.context,
      event: e.event,
      enqueue: i,
      check: (a) => rr(a, t.context, e.event, t),
      self: n.self,
      system: n.system
    }, r), [
      t,
      void 0,
      o
    ];
  }
  function Kl(n) {
    function t(e, r) {
    }
    return t.type = "xstate.enqueueActions", t.collect = n, t.resolve = Wl, t;
  }
  function Jl(n, t, e, r, { value: s, label: o }) {
    return [
      t,
      {
        value: typeof s == "function" ? s(e, r) : s,
        label: o
      },
      void 0
    ];
  }
  function Gl({ logger: n }, { value: t, label: e }) {
    e ? n(e, t) : n(t);
  }
  function ql(n = ({ context: e, event: r }) => ({
    context: e,
    event: r
  }), t) {
    function e(r, s) {
    }
    return e.type = "xstate.log", e.value = n, e.label = t, e.resolve = Jl, e.execute = Gl, e;
  }
  function Yl(n, t) {
    const e = ce(t);
    if (!e.includes(n.type)) {
      const r = e.length === 1 ? `type "${e[0]}"` : `one of types "${e.join('", "')}"`;
      throw new Error(`Expected event ${JSON.stringify(n)} to have ${r}`);
    }
  }
  Xl = function(n, t) {
    return new Ms(n, t);
  };
  function Zl({ schemas: n, actors: t, actions: e, guards: r, delays: s }) {
    return {
      assign: ln,
      sendTo: Hs,
      raise: Ts,
      log: ql,
      cancel: As,
      stopChild: nr,
      enqueueActions: Kl,
      emit: lc,
      spawnChild: Es,
      createStateConfig: (o) => o,
      createAction: (o) => o,
      createMachine: (o) => Xl({
        ...o,
        schemas: n
      }, {
        actors: t,
        actions: e,
        guards: r,
        delays: s
      })
    };
  }
  const Ql = {
    timeout: 1 / 0
  };
  function th(n, t, e) {
    const r = {
      ...Ql,
      ...e
    };
    return new Promise((s, o) => {
      const { signal: i } = r;
      if (i == null ? void 0 : i.aborted) {
        o(i.reason);
        return;
      }
      let a = false;
      const c = r.timeout === 1 / 0 ? void 0 : setTimeout(() => {
        f(), o(new Error(`Timeout of ${r.timeout} ms exceeded`));
      }, r.timeout), f = () => {
        clearTimeout(c), a = true, d == null ? void 0 : d.unsubscribe(), _ && i.removeEventListener("abort", _);
      };
      function u(l) {
        t(l) && (f(), s(l));
      }
      let _, d;
      u(n.getSnapshot()), !a && (i && (_ = () => {
        f(), o(i.reason);
      }, i.addEventListener("abort", _)), d = n.subscribe({
        next: u,
        error: (l) => {
          f(), o(l);
        },
        complete: () => {
          f(), o(new Error("Actor terminated without satisfying predicate"));
        }
      }), a && d.unsubscribe());
    });
  }
  var ne = {}, ft = {}, Ot = {}, Ds = {}, sr = {};
  Object.defineProperty(sr, "__esModule", {
    value: true
  });
  sr.crypto = void 0;
  sr.crypto = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
  (function(n) {
    Object.defineProperty(n, "__esModule", {
      value: true
    }), n.wrapXOFConstructorWithOpts = n.wrapConstructorWithOpts = n.wrapConstructor = n.Hash = n.nextTick = n.swap32IfBE = n.byteSwapIfBE = n.swap8IfBE = n.isLE = void 0, n.isBytes = e, n.anumber = r, n.abytes = s, n.ahash = o, n.aexists = i, n.aoutput = a, n.u8 = c, n.u32 = f, n.clean = u, n.createView = _, n.rotr = d, n.rotl = l, n.byteSwap = w, n.byteSwap32 = k, n.bytesToHex = N, n.hexToBytes = Z, n.asyncLoop = it, n.utf8ToBytes = tt, n.bytesToUtf8 = st, n.toBytes = ct, n.kdfInputToBytes = jt, n.concatBytes = At, n.checkOpts = S, n.createHasher = H, n.createOptHasher = P, n.createXOFer = D, n.randomBytes = et;
    const t = sr;
    function e(v) {
      return v instanceof Uint8Array || ArrayBuffer.isView(v) && v.constructor.name === "Uint8Array";
    }
    function r(v) {
      if (!Number.isSafeInteger(v) || v < 0)
        throw new Error("positive integer expected, got " + v);
    }
    function s(v, ...$) {
      if (!e(v))
        throw new Error("Uint8Array expected");
      if ($.length > 0 && !$.includes(v.length))
        throw new Error("Uint8Array expected of length " + $ + ", got length=" + v.length);
    }
    function o(v) {
      if (typeof v != "function" || typeof v.create != "function")
        throw new Error("Hash should be wrapped by utils.createHasher");
      r(v.outputLen), r(v.blockLen);
    }
    function i(v, $ = true) {
      if (v.destroyed)
        throw new Error("Hash instance has been destroyed");
      if ($ && v.finished)
        throw new Error("Hash#digest() has already been called");
    }
    function a(v, $) {
      s(v);
      const J = $.outputLen;
      if (v.length < J)
        throw new Error("digestInto() expects output buffer of length at least " + J);
    }
    function c(v) {
      return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
    }
    function f(v) {
      return new Uint32Array(v.buffer, v.byteOffset, Math.floor(v.byteLength / 4));
    }
    function u(...v) {
      for (let $ = 0; $ < v.length; $++)
        v[$].fill(0);
    }
    function _(v) {
      return new DataView(v.buffer, v.byteOffset, v.byteLength);
    }
    function d(v, $) {
      return v << 32 - $ | v >>> $;
    }
    function l(v, $) {
      return v << $ | v >>> 32 - $ >>> 0;
    }
    n.isLE = (() => new Uint8Array(new Uint32Array([
      287454020
    ]).buffer)[0] === 68)();
    function w(v) {
      return v << 24 & 4278190080 | v << 8 & 16711680 | v >>> 8 & 65280 | v >>> 24 & 255;
    }
    n.swap8IfBE = n.isLE ? (v) => v : (v) => w(v), n.byteSwapIfBE = n.swap8IfBE;
    function k(v) {
      for (let $ = 0; $ < v.length; $++)
        v[$] = w(v[$]);
      return v;
    }
    n.swap32IfBE = n.isLE ? (v) => v : k;
    const j = (() => typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function")(), L = Array.from({
      length: 256
    }, (v, $) => $.toString(16).padStart(2, "0"));
    function N(v) {
      if (s(v), j)
        return v.toHex();
      let $ = "";
      for (let J = 0; J < v.length; J++)
        $ += L[v[J]];
      return $;
    }
    const O = {
      _0: 48,
      _9: 57,
      A: 65,
      F: 70,
      a: 97,
      f: 102
    };
    function q(v) {
      if (v >= O._0 && v <= O._9)
        return v - O._0;
      if (v >= O.A && v <= O.F)
        return v - (O.A - 10);
      if (v >= O.a && v <= O.f)
        return v - (O.a - 10);
    }
    function Z(v) {
      if (typeof v != "string")
        throw new Error("hex string expected, got " + typeof v);
      if (j)
        return Uint8Array.fromHex(v);
      const $ = v.length, J = $ / 2;
      if ($ % 2)
        throw new Error("hex string expected, got unpadded hex of length " + $);
      const G = new Uint8Array(J);
      for (let gt = 0, Dt = 0; gt < J; gt++, Dt += 2) {
        const Ks = q(v.charCodeAt(Dt)), Js = q(v.charCodeAt(Dt + 1));
        if (Ks === void 0 || Js === void 0) {
          const o_ = v[Dt] + v[Dt + 1];
          throw new Error('hex string expected, got non-hex character "' + o_ + '" at index ' + Dt);
        }
        G[gt] = Ks * 16 + Js;
      }
      return G;
    }
    const Y = async () => {
    };
    n.nextTick = Y;
    async function it(v, $, J) {
      let G = Date.now();
      for (let gt = 0; gt < v; gt++) {
        J(gt);
        const Dt = Date.now() - G;
        Dt >= 0 && Dt < $ || (await (0, n.nextTick)(), G += Dt);
      }
    }
    function tt(v) {
      if (typeof v != "string")
        throw new Error("string expected");
      return new Uint8Array(new TextEncoder().encode(v));
    }
    function st(v) {
      return new TextDecoder().decode(v);
    }
    function ct(v) {
      return typeof v == "string" && (v = tt(v)), s(v), v;
    }
    function jt(v) {
      return typeof v == "string" && (v = tt(v)), s(v), v;
    }
    function At(...v) {
      let $ = 0;
      for (let G = 0; G < v.length; G++) {
        const gt = v[G];
        s(gt), $ += gt.length;
      }
      const J = new Uint8Array($);
      for (let G = 0, gt = 0; G < v.length; G++) {
        const Dt = v[G];
        J.set(Dt, gt), gt += Dt.length;
      }
      return J;
    }
    function S(v, $) {
      if ($ !== void 0 && {}.toString.call($) !== "[object Object]")
        throw new Error("options should be object or undefined");
      return Object.assign(v, $);
    }
    class W {
    }
    n.Hash = W;
    function H(v) {
      const $ = (G) => v().update(ct(G)).digest(), J = v();
      return $.outputLen = J.outputLen, $.blockLen = J.blockLen, $.create = () => v(), $;
    }
    function P(v) {
      const $ = (G, gt) => v(gt).update(ct(G)).digest(), J = v({});
      return $.outputLen = J.outputLen, $.blockLen = J.blockLen, $.create = (G) => v(G), $;
    }
    function D(v) {
      const $ = (G, gt) => v(gt).update(ct(G)).digest(), J = v({});
      return $.outputLen = J.outputLen, $.blockLen = J.blockLen, $.create = (G) => v(G), $;
    }
    n.wrapConstructor = H, n.wrapConstructorWithOpts = P, n.wrapXOFConstructorWithOpts = D;
    function et(v = 32) {
      if (t.crypto && typeof t.crypto.getRandomValues == "function")
        return t.crypto.getRandomValues(new Uint8Array(v));
      if (t.crypto && typeof t.crypto.randomBytes == "function")
        return Uint8Array.from(t.crypto.randomBytes(v));
      throw new Error("crypto.getRandomValues must be defined");
    }
  })(Ds);
  Object.defineProperty(Ot, "__esModule", {
    value: true
  });
  Ot.SHA512_IV = Ot.SHA384_IV = Ot.SHA224_IV = Ot.SHA256_IV = Ot.HashMD = void 0;
  Ot.setBigUint64 = hc;
  Ot.Chi = eh;
  Ot.Maj = nh;
  const Gt = Ds;
  function hc(n, t, e, r) {
    if (typeof n.setBigUint64 == "function")
      return n.setBigUint64(t, e, r);
    const s = BigInt(32), o = BigInt(4294967295), i = Number(e >> s & o), a = Number(e & o), c = r ? 4 : 0, f = r ? 0 : 4;
    n.setUint32(t + c, i, r), n.setUint32(t + f, a, r);
  }
  function eh(n, t, e) {
    return n & t ^ ~n & e;
  }
  function nh(n, t, e) {
    return n & t ^ n & e ^ t & e;
  }
  class rh extends Gt.Hash {
    constructor(t, e, r, s) {
      super(), this.finished = false, this.length = 0, this.pos = 0, this.destroyed = false, this.blockLen = t, this.outputLen = e, this.padOffset = r, this.isLE = s, this.buffer = new Uint8Array(t), this.view = (0, Gt.createView)(this.buffer);
    }
    update(t) {
      (0, Gt.aexists)(this), t = (0, Gt.toBytes)(t), (0, Gt.abytes)(t);
      const { view: e, buffer: r, blockLen: s } = this, o = t.length;
      for (let i = 0; i < o; ) {
        const a = Math.min(s - this.pos, o - i);
        if (a === s) {
          const c = (0, Gt.createView)(t);
          for (; s <= o - i; i += s)
            this.process(c, i);
          continue;
        }
        r.set(t.subarray(i, i + a), this.pos), this.pos += a, i += a, this.pos === s && (this.process(e, 0), this.pos = 0);
      }
      return this.length += t.length, this.roundClean(), this;
    }
    digestInto(t) {
      (0, Gt.aexists)(this), (0, Gt.aoutput)(t, this), this.finished = true;
      const { buffer: e, view: r, blockLen: s, isLE: o } = this;
      let { pos: i } = this;
      e[i++] = 128, (0, Gt.clean)(this.buffer.subarray(i)), this.padOffset > s - i && (this.process(r, 0), i = 0);
      for (let _ = i; _ < s; _++)
        e[_] = 0;
      hc(r, s - 8, BigInt(this.length * 8), o), this.process(r, 0);
      const a = (0, Gt.createView)(t), c = this.outputLen;
      if (c % 4)
        throw new Error("_sha2: outputLen should be aligned to 32bit");
      const f = c / 4, u = this.get();
      if (f > u.length)
        throw new Error("_sha2: outputLen bigger than state");
      for (let _ = 0; _ < f; _++)
        a.setUint32(4 * _, u[_], o);
    }
    digest() {
      const { buffer: t, outputLen: e } = this;
      this.digestInto(t);
      const r = t.slice(0, e);
      return this.destroy(), r;
    }
    _cloneInto(t) {
      t || (t = new this.constructor()), t.set(...this.get());
      const { blockLen: e, buffer: r, length: s, finished: o, destroyed: i, pos: a } = this;
      return t.destroyed = i, t.finished = o, t.length = s, t.pos = a, s % e && t.buffer.set(r), t;
    }
    clone() {
      return this._cloneInto();
    }
  }
  Ot.HashMD = rh;
  Ot.SHA256_IV = Uint32Array.from([
    1779033703,
    3144134277,
    1013904242,
    2773480762,
    1359893119,
    2600822924,
    528734635,
    1541459225
  ]);
  Ot.SHA224_IV = Uint32Array.from([
    3238371032,
    914150663,
    812702999,
    4144912697,
    4290775857,
    1750603025,
    1694076839,
    3204075428
  ]);
  Ot.SHA384_IV = Uint32Array.from([
    3418070365,
    3238371032,
    1654270250,
    914150663,
    2438529370,
    812702999,
    355462360,
    4144912697,
    1731405415,
    4290775857,
    2394180231,
    1750603025,
    3675008525,
    1694076839,
    1203062813,
    3204075428
  ]);
  Ot.SHA512_IV = Uint32Array.from([
    1779033703,
    4089235720,
    3144134277,
    2227873595,
    1013904242,
    4271175723,
    2773480762,
    1595750129,
    1359893119,
    2917565137,
    2600822924,
    725511199,
    528734635,
    4215389547,
    1541459225,
    327033209
  ]);
  var nt = {};
  Object.defineProperty(nt, "__esModule", {
    value: true
  });
  nt.toBig = nt.shrSL = nt.shrSH = nt.rotrSL = nt.rotrSH = nt.rotrBL = nt.rotrBH = nt.rotr32L = nt.rotr32H = nt.rotlSL = nt.rotlSH = nt.rotlBL = nt.rotlBH = nt.add5L = nt.add5H = nt.add4L = nt.add4H = nt.add3L = nt.add3H = void 0;
  nt.add = Oc;
  nt.fromBig = $s;
  nt.split = gc;
  const En = BigInt(2 ** 32 - 1), Hr = BigInt(32);
  function $s(n, t = false) {
    return t ? {
      h: Number(n & En),
      l: Number(n >> Hr & En)
    } : {
      h: Number(n >> Hr & En) | 0,
      l: Number(n & En) | 0
    };
  }
  function gc(n, t = false) {
    const e = n.length;
    let r = new Uint32Array(e), s = new Uint32Array(e);
    for (let o = 0; o < e; o++) {
      const { h: i, l: a } = $s(n[o], t);
      [r[o], s[o]] = [
        i,
        a
      ];
    }
    return [
      r,
      s
    ];
  }
  const bc = (n, t) => BigInt(n >>> 0) << Hr | BigInt(t >>> 0);
  nt.toBig = bc;
  const pc = (n, t, e) => n >>> e;
  nt.shrSH = pc;
  const wc = (n, t, e) => n << 32 - e | t >>> e;
  nt.shrSL = wc;
  const yc = (n, t, e) => n >>> e | t << 32 - e;
  nt.rotrSH = yc;
  const mc = (n, t, e) => n << 32 - e | t >>> e;
  nt.rotrSL = mc;
  const vc = (n, t, e) => n << 64 - e | t >>> e - 32;
  nt.rotrBH = vc;
  const Sc = (n, t, e) => n >>> e - 32 | t << 64 - e;
  nt.rotrBL = Sc;
  const xc = (n, t) => t;
  nt.rotr32H = xc;
  const Ic = (n, t) => n;
  nt.rotr32L = Ic;
  const kc = (n, t, e) => n << e | t >>> 32 - e;
  nt.rotlSH = kc;
  const Ac = (n, t, e) => t << e | n >>> 32 - e;
  nt.rotlSL = Ac;
  const Ec = (n, t, e) => t << e - 32 | n >>> 64 - e;
  nt.rotlBH = Ec;
  const Cc = (n, t, e) => n << e - 32 | t >>> 64 - e;
  nt.rotlBL = Cc;
  function Oc(n, t, e, r) {
    const s = (t >>> 0) + (r >>> 0);
    return {
      h: n + e + (s / 2 ** 32 | 0) | 0,
      l: s | 0
    };
  }
  const jc = (n, t, e) => (n >>> 0) + (t >>> 0) + (e >>> 0);
  nt.add3L = jc;
  const Rc = (n, t, e, r) => t + e + r + (n / 2 ** 32 | 0) | 0;
  nt.add3H = Rc;
  const Tc = (n, t, e, r) => (n >>> 0) + (t >>> 0) + (e >>> 0) + (r >>> 0);
  nt.add4L = Tc;
  const Mc = (n, t, e, r, s) => t + e + r + s + (n / 2 ** 32 | 0) | 0;
  nt.add4H = Mc;
  const Hc = (n, t, e, r, s) => (n >>> 0) + (t >>> 0) + (e >>> 0) + (r >>> 0) + (s >>> 0);
  nt.add5L = Hc;
  const Dc = (n, t, e, r, s, o) => t + e + r + s + o + (n / 2 ** 32 | 0) | 0;
  nt.add5H = Dc;
  const sh = {
    fromBig: $s,
    split: gc,
    toBig: bc,
    shrSH: pc,
    shrSL: wc,
    rotrSH: yc,
    rotrSL: mc,
    rotrBH: vc,
    rotrBL: Sc,
    rotr32H: xc,
    rotr32L: Ic,
    rotlSH: kc,
    rotlSL: Ac,
    rotlBH: Ec,
    rotlBL: Cc,
    add: Oc,
    add3L: jc,
    add3H: Rc,
    add4L: Tc,
    add4H: Mc,
    add5H: Dc,
    add5L: Hc
  };
  nt.default = sh;
  Object.defineProperty(ft, "__esModule", {
    value: true
  });
  ft.sha512_224 = ft.sha512_256 = ft.sha384 = ft.sha512 = ft.sha224 = ft.sha256 = ft.SHA512_256 = ft.SHA512_224 = ft.SHA384 = ft.SHA512 = ft.SHA224 = ft.SHA256 = void 0;
  const X = Ot, rt = nt, bt = Ds, oh = Uint32Array.from([
    1116352408,
    1899447441,
    3049323471,
    3921009573,
    961987163,
    1508970993,
    2453635748,
    2870763221,
    3624381080,
    310598401,
    607225278,
    1426881987,
    1925078388,
    2162078206,
    2614888103,
    3248222580,
    3835390401,
    4022224774,
    264347078,
    604807628,
    770255983,
    1249150122,
    1555081692,
    1996064986,
    2554220882,
    2821834349,
    2952996808,
    3210313671,
    3336571891,
    3584528711,
    113926993,
    338241895,
    666307205,
    773529912,
    1294757372,
    1396182291,
    1695183700,
    1986661051,
    2177026350,
    2456956037,
    2730485921,
    2820302411,
    3259730800,
    3345764771,
    3516065817,
    3600352804,
    4094571909,
    275423344,
    430227734,
    506948616,
    659060556,
    883997877,
    958139571,
    1322822218,
    1537002063,
    1747873779,
    1955562222,
    2024104815,
    2227730452,
    2361852424,
    2428436474,
    2756734187,
    3204031479,
    3329325298
  ]), he = new Uint32Array(64);
  class Us extends X.HashMD {
    constructor(t = 32) {
      super(64, t, 8, false), this.A = X.SHA256_IV[0] | 0, this.B = X.SHA256_IV[1] | 0, this.C = X.SHA256_IV[2] | 0, this.D = X.SHA256_IV[3] | 0, this.E = X.SHA256_IV[4] | 0, this.F = X.SHA256_IV[5] | 0, this.G = X.SHA256_IV[6] | 0, this.H = X.SHA256_IV[7] | 0;
    }
    get() {
      const { A: t, B: e, C: r, D: s, E: o, F: i, G: a, H: c } = this;
      return [
        t,
        e,
        r,
        s,
        o,
        i,
        a,
        c
      ];
    }
    set(t, e, r, s, o, i, a, c) {
      this.A = t | 0, this.B = e | 0, this.C = r | 0, this.D = s | 0, this.E = o | 0, this.F = i | 0, this.G = a | 0, this.H = c | 0;
    }
    process(t, e) {
      for (let _ = 0; _ < 16; _++, e += 4)
        he[_] = t.getUint32(e, false);
      for (let _ = 16; _ < 64; _++) {
        const d = he[_ - 15], l = he[_ - 2], w = (0, bt.rotr)(d, 7) ^ (0, bt.rotr)(d, 18) ^ d >>> 3, k = (0, bt.rotr)(l, 17) ^ (0, bt.rotr)(l, 19) ^ l >>> 10;
        he[_] = k + he[_ - 7] + w + he[_ - 16] | 0;
      }
      let { A: r, B: s, C: o, D: i, E: a, F: c, G: f, H: u } = this;
      for (let _ = 0; _ < 64; _++) {
        const d = (0, bt.rotr)(a, 6) ^ (0, bt.rotr)(a, 11) ^ (0, bt.rotr)(a, 25), l = u + d + (0, X.Chi)(a, c, f) + oh[_] + he[_] | 0, k = ((0, bt.rotr)(r, 2) ^ (0, bt.rotr)(r, 13) ^ (0, bt.rotr)(r, 22)) + (0, X.Maj)(r, s, o) | 0;
        u = f, f = c, c = a, a = i + l | 0, i = o, o = s, s = r, r = l + k | 0;
      }
      r = r + this.A | 0, s = s + this.B | 0, o = o + this.C | 0, i = i + this.D | 0, a = a + this.E | 0, c = c + this.F | 0, f = f + this.G | 0, u = u + this.H | 0, this.set(r, s, o, i, a, c, f, u);
    }
    roundClean() {
      (0, bt.clean)(he);
    }
    destroy() {
      this.set(0, 0, 0, 0, 0, 0, 0, 0), (0, bt.clean)(this.buffer);
    }
  }
  ft.SHA256 = Us;
  class $c extends Us {
    constructor() {
      super(28), this.A = X.SHA224_IV[0] | 0, this.B = X.SHA224_IV[1] | 0, this.C = X.SHA224_IV[2] | 0, this.D = X.SHA224_IV[3] | 0, this.E = X.SHA224_IV[4] | 0, this.F = X.SHA224_IV[5] | 0, this.G = X.SHA224_IV[6] | 0, this.H = X.SHA224_IV[7] | 0;
    }
  }
  ft.SHA224 = $c;
  const Uc = (() => rt.split([
    "0x428a2f98d728ae22",
    "0x7137449123ef65cd",
    "0xb5c0fbcfec4d3b2f",
    "0xe9b5dba58189dbbc",
    "0x3956c25bf348b538",
    "0x59f111f1b605d019",
    "0x923f82a4af194f9b",
    "0xab1c5ed5da6d8118",
    "0xd807aa98a3030242",
    "0x12835b0145706fbe",
    "0x243185be4ee4b28c",
    "0x550c7dc3d5ffb4e2",
    "0x72be5d74f27b896f",
    "0x80deb1fe3b1696b1",
    "0x9bdc06a725c71235",
    "0xc19bf174cf692694",
    "0xe49b69c19ef14ad2",
    "0xefbe4786384f25e3",
    "0x0fc19dc68b8cd5b5",
    "0x240ca1cc77ac9c65",
    "0x2de92c6f592b0275",
    "0x4a7484aa6ea6e483",
    "0x5cb0a9dcbd41fbd4",
    "0x76f988da831153b5",
    "0x983e5152ee66dfab",
    "0xa831c66d2db43210",
    "0xb00327c898fb213f",
    "0xbf597fc7beef0ee4",
    "0xc6e00bf33da88fc2",
    "0xd5a79147930aa725",
    "0x06ca6351e003826f",
    "0x142929670a0e6e70",
    "0x27b70a8546d22ffc",
    "0x2e1b21385c26c926",
    "0x4d2c6dfc5ac42aed",
    "0x53380d139d95b3df",
    "0x650a73548baf63de",
    "0x766a0abb3c77b2a8",
    "0x81c2c92e47edaee6",
    "0x92722c851482353b",
    "0xa2bfe8a14cf10364",
    "0xa81a664bbc423001",
    "0xc24b8b70d0f89791",
    "0xc76c51a30654be30",
    "0xd192e819d6ef5218",
    "0xd69906245565a910",
    "0xf40e35855771202a",
    "0x106aa07032bbd1b8",
    "0x19a4c116b8d2d0c8",
    "0x1e376c085141ab53",
    "0x2748774cdf8eeb99",
    "0x34b0bcb5e19b48a8",
    "0x391c0cb3c5c95a63",
    "0x4ed8aa4ae3418acb",
    "0x5b9cca4f7763e373",
    "0x682e6ff3d6b2b8a3",
    "0x748f82ee5defb2fc",
    "0x78a5636f43172f60",
    "0x84c87814a1f0ab72",
    "0x8cc702081a6439ec",
    "0x90befffa23631e28",
    "0xa4506cebde82bde9",
    "0xbef9a3f7b2c67915",
    "0xc67178f2e372532b",
    "0xca273eceea26619c",
    "0xd186b8c721c0c207",
    "0xeada7dd6cde0eb1e",
    "0xf57d4f7fee6ed178",
    "0x06f067aa72176fba",
    "0x0a637dc5a2c898a6",
    "0x113f9804bef90dae",
    "0x1b710b35131c471b",
    "0x28db77f523047d84",
    "0x32caab7b40c72493",
    "0x3c9ebe0a15c9bebc",
    "0x431d67c49c100d4c",
    "0x4cc5d4becb3e42b6",
    "0x597f299cfc657e2a",
    "0x5fcb6fab3ad6faec",
    "0x6c44198c4a475817"
  ].map((n) => BigInt(n))))(), ih = (() => Uc[0])(), ah = (() => Uc[1])(), ge = new Uint32Array(80), be = new Uint32Array(80);
  class xn extends X.HashMD {
    constructor(t = 64) {
      super(128, t, 16, false), this.Ah = X.SHA512_IV[0] | 0, this.Al = X.SHA512_IV[1] | 0, this.Bh = X.SHA512_IV[2] | 0, this.Bl = X.SHA512_IV[3] | 0, this.Ch = X.SHA512_IV[4] | 0, this.Cl = X.SHA512_IV[5] | 0, this.Dh = X.SHA512_IV[6] | 0, this.Dl = X.SHA512_IV[7] | 0, this.Eh = X.SHA512_IV[8] | 0, this.El = X.SHA512_IV[9] | 0, this.Fh = X.SHA512_IV[10] | 0, this.Fl = X.SHA512_IV[11] | 0, this.Gh = X.SHA512_IV[12] | 0, this.Gl = X.SHA512_IV[13] | 0, this.Hh = X.SHA512_IV[14] | 0, this.Hl = X.SHA512_IV[15] | 0;
    }
    get() {
      const { Ah: t, Al: e, Bh: r, Bl: s, Ch: o, Cl: i, Dh: a, Dl: c, Eh: f, El: u, Fh: _, Fl: d, Gh: l, Gl: w, Hh: k, Hl: j } = this;
      return [
        t,
        e,
        r,
        s,
        o,
        i,
        a,
        c,
        f,
        u,
        _,
        d,
        l,
        w,
        k,
        j
      ];
    }
    set(t, e, r, s, o, i, a, c, f, u, _, d, l, w, k, j) {
      this.Ah = t | 0, this.Al = e | 0, this.Bh = r | 0, this.Bl = s | 0, this.Ch = o | 0, this.Cl = i | 0, this.Dh = a | 0, this.Dl = c | 0, this.Eh = f | 0, this.El = u | 0, this.Fh = _ | 0, this.Fl = d | 0, this.Gh = l | 0, this.Gl = w | 0, this.Hh = k | 0, this.Hl = j | 0;
    }
    process(t, e) {
      for (let O = 0; O < 16; O++, e += 4)
        ge[O] = t.getUint32(e), be[O] = t.getUint32(e += 4);
      for (let O = 16; O < 80; O++) {
        const q = ge[O - 15] | 0, Z = be[O - 15] | 0, Y = rt.rotrSH(q, Z, 1) ^ rt.rotrSH(q, Z, 8) ^ rt.shrSH(q, Z, 7), it = rt.rotrSL(q, Z, 1) ^ rt.rotrSL(q, Z, 8) ^ rt.shrSL(q, Z, 7), tt = ge[O - 2] | 0, st = be[O - 2] | 0, ct = rt.rotrSH(tt, st, 19) ^ rt.rotrBH(tt, st, 61) ^ rt.shrSH(tt, st, 6), jt = rt.rotrSL(tt, st, 19) ^ rt.rotrBL(tt, st, 61) ^ rt.shrSL(tt, st, 6), At = rt.add4L(it, jt, be[O - 7], be[O - 16]), S = rt.add4H(At, Y, ct, ge[O - 7], ge[O - 16]);
        ge[O] = S | 0, be[O] = At | 0;
      }
      let { Ah: r, Al: s, Bh: o, Bl: i, Ch: a, Cl: c, Dh: f, Dl: u, Eh: _, El: d, Fh: l, Fl: w, Gh: k, Gl: j, Hh: L, Hl: N } = this;
      for (let O = 0; O < 80; O++) {
        const q = rt.rotrSH(_, d, 14) ^ rt.rotrSH(_, d, 18) ^ rt.rotrBH(_, d, 41), Z = rt.rotrSL(_, d, 14) ^ rt.rotrSL(_, d, 18) ^ rt.rotrBL(_, d, 41), Y = _ & l ^ ~_ & k, it = d & w ^ ~d & j, tt = rt.add5L(N, Z, it, ah[O], be[O]), st = rt.add5H(tt, L, q, Y, ih[O], ge[O]), ct = tt | 0, jt = rt.rotrSH(r, s, 28) ^ rt.rotrBH(r, s, 34) ^ rt.rotrBH(r, s, 39), At = rt.rotrSL(r, s, 28) ^ rt.rotrBL(r, s, 34) ^ rt.rotrBL(r, s, 39), S = r & o ^ r & a ^ o & a, W = s & i ^ s & c ^ i & c;
        L = k | 0, N = j | 0, k = l | 0, j = w | 0, l = _ | 0, w = d | 0, { h: _, l: d } = rt.add(f | 0, u | 0, st | 0, ct | 0), f = a | 0, u = c | 0, a = o | 0, c = i | 0, o = r | 0, i = s | 0;
        const H = rt.add3L(ct, At, W);
        r = rt.add3H(H, st, jt, S), s = H | 0;
      }
      ({ h: r, l: s } = rt.add(this.Ah | 0, this.Al | 0, r | 0, s | 0)), { h: o, l: i } = rt.add(this.Bh | 0, this.Bl | 0, o | 0, i | 0), { h: a, l: c } = rt.add(this.Ch | 0, this.Cl | 0, a | 0, c | 0), { h: f, l: u } = rt.add(this.Dh | 0, this.Dl | 0, f | 0, u | 0), { h: _, l: d } = rt.add(this.Eh | 0, this.El | 0, _ | 0, d | 0), { h: l, l: w } = rt.add(this.Fh | 0, this.Fl | 0, l | 0, w | 0), { h: k, l: j } = rt.add(this.Gh | 0, this.Gl | 0, k | 0, j | 0), { h: L, l: N } = rt.add(this.Hh | 0, this.Hl | 0, L | 0, N | 0), this.set(r, s, o, i, a, c, f, u, _, d, l, w, k, j, L, N);
    }
    roundClean() {
      (0, bt.clean)(ge, be);
    }
    destroy() {
      (0, bt.clean)(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }
  }
  ft.SHA512 = xn;
  class Bc extends xn {
    constructor() {
      super(48), this.Ah = X.SHA384_IV[0] | 0, this.Al = X.SHA384_IV[1] | 0, this.Bh = X.SHA384_IV[2] | 0, this.Bl = X.SHA384_IV[3] | 0, this.Ch = X.SHA384_IV[4] | 0, this.Cl = X.SHA384_IV[5] | 0, this.Dh = X.SHA384_IV[6] | 0, this.Dl = X.SHA384_IV[7] | 0, this.Eh = X.SHA384_IV[8] | 0, this.El = X.SHA384_IV[9] | 0, this.Fh = X.SHA384_IV[10] | 0, this.Fl = X.SHA384_IV[11] | 0, this.Gh = X.SHA384_IV[12] | 0, this.Gl = X.SHA384_IV[13] | 0, this.Hh = X.SHA384_IV[14] | 0, this.Hl = X.SHA384_IV[15] | 0;
    }
  }
  ft.SHA384 = Bc;
  const xt = Uint32Array.from([
    2352822216,
    424955298,
    1944164710,
    2312950998,
    502970286,
    855612546,
    1738396948,
    1479516111,
    258812777,
    2077511080,
    2011393907,
    79989058,
    1067287976,
    1780299464,
    286451373,
    2446758561
  ]), It = Uint32Array.from([
    573645204,
    4230739756,
    2673172387,
    3360449730,
    596883563,
    1867755857,
    2520282905,
    1497426621,
    2519219938,
    2827943907,
    3193839141,
    1401305490,
    721525244,
    746961066,
    246885852,
    2177182882
  ]);
  class Pc extends xn {
    constructor() {
      super(28), this.Ah = xt[0] | 0, this.Al = xt[1] | 0, this.Bh = xt[2] | 0, this.Bl = xt[3] | 0, this.Ch = xt[4] | 0, this.Cl = xt[5] | 0, this.Dh = xt[6] | 0, this.Dl = xt[7] | 0, this.Eh = xt[8] | 0, this.El = xt[9] | 0, this.Fh = xt[10] | 0, this.Fl = xt[11] | 0, this.Gh = xt[12] | 0, this.Gl = xt[13] | 0, this.Hh = xt[14] | 0, this.Hl = xt[15] | 0;
    }
  }
  ft.SHA512_224 = Pc;
  class Fc extends xn {
    constructor() {
      super(32), this.Ah = It[0] | 0, this.Al = It[1] | 0, this.Bh = It[2] | 0, this.Bl = It[3] | 0, this.Ch = It[4] | 0, this.Cl = It[5] | 0, this.Dh = It[6] | 0, this.Dl = It[7] | 0, this.Eh = It[8] | 0, this.El = It[9] | 0, this.Fh = It[10] | 0, this.Fl = It[11] | 0, this.Gh = It[12] | 0, this.Gl = It[13] | 0, this.Hh = It[14] | 0, this.Hl = It[15] | 0;
    }
  }
  ft.SHA512_256 = Fc;
  ft.sha256 = (0, bt.createHasher)(() => new Us());
  ft.sha224 = (0, bt.createHasher)(() => new $c());
  ft.sha512 = (0, bt.createHasher)(() => new xn());
  ft.sha384 = (0, bt.createHasher)(() => new Bc());
  ft.sha512_256 = (0, bt.createHasher)(() => new Fc());
  ft.sha512_224 = (0, bt.createHasher)(() => new Pc());
  Object.defineProperty(ne, "__esModule", {
    value: true
  });
  ne.sha224 = ne.SHA224 = ne.sha256 = ne.SHA256 = void 0;
  const or = ft;
  ne.SHA256 = or.SHA256;
  ne.sha256 = or.sha256;
  ne.SHA224 = or.SHA224;
  ne.sha224 = or.sha224;
  function ch(n) {
    if (n.length >= 255)
      throw new TypeError("Alphabet too long");
    for (var t = new Uint8Array(256), e = 0; e < t.length; e++)
      t[e] = 255;
    for (var r = 0; r < n.length; r++) {
      var s = n.charAt(r), o = s.charCodeAt(0);
      if (t[o] !== 255)
        throw new TypeError(s + " is ambiguous");
      t[o] = r;
    }
    var i = n.length, a = n.charAt(0), c = Math.log(i) / Math.log(256), f = Math.log(256) / Math.log(i);
    function u(l) {
      if (l instanceof Uint8Array || (ArrayBuffer.isView(l) ? l = new Uint8Array(l.buffer, l.byteOffset, l.byteLength) : Array.isArray(l) && (l = Uint8Array.from(l))), !(l instanceof Uint8Array))
        throw new TypeError("Expected Uint8Array");
      if (l.length === 0)
        return "";
      for (var w = 0, k = 0, j = 0, L = l.length; j !== L && l[j] === 0; )
        j++, w++;
      for (var N = (L - j) * f + 1 >>> 0, O = new Uint8Array(N); j !== L; ) {
        for (var q = l[j], Z = 0, Y = N - 1; (q !== 0 || Z < k) && Y !== -1; Y--, Z++)
          q += 256 * O[Y] >>> 0, O[Y] = q % i >>> 0, q = q / i >>> 0;
        if (q !== 0)
          throw new Error("Non-zero carry");
        k = Z, j++;
      }
      for (var it = N - k; it !== N && O[it] === 0; )
        it++;
      for (var tt = a.repeat(w); it < N; ++it)
        tt += n.charAt(O[it]);
      return tt;
    }
    function _(l) {
      if (typeof l != "string")
        throw new TypeError("Expected String");
      if (l.length === 0)
        return new Uint8Array();
      for (var w = 0, k = 0, j = 0; l[w] === a; )
        k++, w++;
      for (var L = (l.length - w) * c + 1 >>> 0, N = new Uint8Array(L); l[w]; ) {
        var O = l.charCodeAt(w);
        if (O > 255)
          return;
        var q = t[O];
        if (q === 255)
          return;
        for (var Z = 0, Y = L - 1; (q !== 0 || Z < j) && Y !== -1; Y--, Z++)
          q += i * N[Y] >>> 0, N[Y] = q % 256 >>> 0, q = q / 256 >>> 0;
        if (q !== 0)
          throw new Error("Non-zero carry");
        j = Z, w++;
      }
      for (var it = L - j; it !== L && N[it] === 0; )
        it++;
      for (var tt = new Uint8Array(k + (L - it)), st = k; it !== L; )
        tt[st++] = N[it++];
      return tt;
    }
    function d(l) {
      var w = _(l);
      if (w)
        return w;
      throw new Error("Non-base" + i + " character");
    }
    return {
      encode: u,
      decodeUnsafe: _,
      decode: d
    };
  }
  var _h = ch;
  const uh = _h, fh = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
  var dh = uh(fh), fr = dh, lh = function(n) {
    function t(o) {
      var i = Uint8Array.from(o), a = n(i), c = i.length + 4, f = new Uint8Array(c);
      return f.set(i, 0), f.set(a.subarray(0, 4), i.length), fr.encode(f, c);
    }
    function e(o) {
      var i = o.slice(0, -4), a = o.slice(-4), c = n(i);
      if (!(a[0] ^ c[0] | a[1] ^ c[1] | a[2] ^ c[2] | a[3] ^ c[3]))
        return i;
    }
    function r(o) {
      var i = fr.decodeUnsafe(o);
      if (i)
        return e(i);
    }
    function s(o) {
      var i = fr.decode(o), a = e(i);
      if (!a)
        throw new Error("Invalid checksum");
      return a;
    }
    return {
      encode: t,
      decode: s,
      decodeUnsafe: r
    };
  }, { sha256: bo } = ne, hh = lh;
  function gh(n) {
    return bo(bo(n));
  }
  var bh = hh(gh);
  let Lc, Bs, Vc, wh, yh, zc, Dr, dr;
  Lc = Ss(bh);
  Bs = "automerge:";
  Ps = (n) => {
    const t = new RegExp(`^${Bs}(\\w+)$`), [, e] = n.match(t) || [], r = e, s = zc(r);
    if (!s)
      throw new Error("Invalid document URL: " + n);
    return {
      binaryDocumentId: s,
      documentId: r
    };
  };
  Fs = (n) => {
    const t = n instanceof Uint8Array || typeof n == "string" ? n : "documentId" in n ? n.documentId : void 0, e = t instanceof Uint8Array ? Dr(t) : typeof t == "string" ? t : void 0;
    if (e === void 0)
      throw new Error("Invalid documentId: " + t);
    return Bs + e;
  };
  ph = (n) => {
    if (!n || !n.startsWith(Bs))
      return false;
    const t = n;
    try {
      const { documentId: e } = Ps(t);
      return Vc(e);
    } catch {
      return false;
    }
  };
  Vc = (n) => {
    const t = zc(n);
    if (t === void 0)
      return false;
    const e = Df(t);
    return Gn(e);
  };
  wh = (n) => Gn(n);
  yh = () => {
    const n = Xr(null, new Uint8Array(16));
    return Fs({
      documentId: n
    });
  };
  zc = (n) => Lc.decodeUnsafe(n);
  Dr = (n) => Lc.encode(n);
  dr = (n) => {
    if (n instanceof Uint8Array)
      return Dr(n);
    if (ph(n))
      return Ps(n).documentId;
    if (Vc(n))
      return n;
    if (wh(n)) {
      console.warn("Future versions will not support UUIDs as document IDs; use Automerge URLs instead.");
      const t = $f(n);
      return Dr(t);
    }
    throw new Error(`Invalid AutomergeUrl: '${n}'`);
  };
  let $r;
  try {
    $r = new TextDecoder();
  } catch {
  }
  let K, Oe, R = 0;
  const mh = 105, vh = 57342, Sh = 57343, po = 57337, wo = 6, He = {};
  let Xe = 11281e4, se = 1681e4, ot = {}, ht, Kn, Jn = 0, hn = 0, yt, Ft, pt = [], Ur = [], Mt, Ct, nn, yo = {
    useRecords: false,
    mapsAsObjects: true
  }, gn = false, Nc = 2;
  try {
    new Function("");
  } catch {
    Nc = 1 / 0;
  }
  class bn {
    constructor(t) {
      if (t && ((t.keyMap || t._keyMap) && !t.useRecords && (t.useRecords = false, t.mapsAsObjects = true), t.useRecords === false && t.mapsAsObjects === void 0 && (t.mapsAsObjects = true), t.getStructures && (t.getShared = t.getStructures), t.getShared && !t.structures && ((t.structures = []).uninitialized = true), t.keyMap)) {
        this.mapKey = /* @__PURE__ */ new Map();
        for (let [e, r] of Object.entries(t.keyMap))
          this.mapKey.set(r, e);
      }
      Object.assign(this, t);
    }
    decodeKey(t) {
      return this.keyMap && this.mapKey.get(t) || t;
    }
    encodeKey(t) {
      return this.keyMap && this.keyMap.hasOwnProperty(t) ? this.keyMap[t] : t;
    }
    encodeKeys(t) {
      if (!this._keyMap)
        return t;
      let e = /* @__PURE__ */ new Map();
      for (let [r, s] of Object.entries(t))
        e.set(this._keyMap.hasOwnProperty(r) ? this._keyMap[r] : r, s);
      return e;
    }
    decodeKeys(t) {
      if (!this._keyMap || t.constructor.name != "Map")
        return t;
      if (!this._mapKey) {
        this._mapKey = /* @__PURE__ */ new Map();
        for (let [r, s] of Object.entries(this._keyMap))
          this._mapKey.set(s, r);
      }
      let e = {};
      return t.forEach((r, s) => e[Lt(this._mapKey.has(s) ? this._mapKey.get(s) : s)] = r), e;
    }
    mapDecode(t, e) {
      let r = this.decode(t);
      if (this._keyMap)
        switch (r.constructor.name) {
          case "Array":
            return r.map((s) => this.decodeKeys(s));
        }
      return r;
    }
    decode(t, e) {
      if (K)
        return Gc(() => (Lr(), this ? this.decode(t, e) : bn.prototype.decode.call(yo, t, e)));
      Oe = e > -1 ? e : t.length, R = 0, hn = 0, Kn = null, yt = null, K = t;
      try {
        Ct = t.dataView || (t.dataView = new DataView(t.buffer, t.byteOffset, t.byteLength));
      } catch (r) {
        throw K = null, t instanceof Uint8Array ? r : new Error("Source must be a Uint8Array or Buffer but was a " + (t && typeof t == "object" ? t.constructor.name : typeof t));
      }
      if (this instanceof bn) {
        if (ot = this, Mt = this.sharedValues && (this.pack ? new Array(this.maxPrivatePackedValues || 16).concat(this.sharedValues) : this.sharedValues), this.structures)
          return ht = this.structures, Cn();
        (!ht || ht.length > 0) && (ht = []);
      } else
        ot = yo, (!ht || ht.length > 0) && (ht = []), Mt = null;
      return Cn();
    }
    decodeMultiple(t, e) {
      let r, s = 0;
      try {
        let o = t.length;
        gn = true;
        let i = this ? this.decode(t, o) : zs.decode(t, o);
        if (e) {
          if (e(i) === false)
            return;
          for (; R < o; )
            if (s = R, e(Cn()) === false)
              return;
        } else {
          for (r = [
            i
          ]; R < o; )
            s = R, r.push(Cn());
          return r;
        }
      } catch (o) {
        throw o.lastPosition = s, o.values = r, o;
      } finally {
        gn = false, Lr();
      }
    }
  }
  function Cn() {
    try {
      let n = at();
      if (yt) {
        if (R >= yt.postBundlePosition) {
          let t = new Error("Unexpected bundle position");
          throw t.incomplete = true, t;
        }
        R = yt.postBundlePosition, yt = null;
      }
      if (R == Oe)
        ht = null, K = null, Ft && (Ft = null);
      else if (R > Oe) {
        let t = new Error("Unexpected end of CBOR data");
        throw t.incomplete = true, t;
      } else if (!gn)
        throw new Error("Data read, but end of buffer not reached");
      return n;
    } catch (n) {
      throw Lr(), (n instanceof RangeError || n.message.startsWith("Unexpected end of buffer")) && (n.incomplete = true), n;
    }
  }
  function at() {
    let n = K[R++], t = n >> 5;
    if (n = n & 31, n > 23)
      switch (n) {
        case 24:
          n = K[R++];
          break;
        case 25:
          if (t == 7)
            return Ah();
          n = Ct.getUint16(R), R += 2;
          break;
        case 26:
          if (t == 7) {
            let e = Ct.getFloat32(R);
            if (ot.useFloat32 > 2) {
              let r = Vs[(K[R] & 127) << 1 | K[R + 1] >> 7];
              return R += 4, (r * e + (e > 0 ? 0.5 : -0.5) >> 0) / r;
            }
            return R += 4, e;
          }
          n = Ct.getUint32(R), R += 4;
          break;
        case 27:
          if (t == 7) {
            let e = Ct.getFloat64(R);
            return R += 8, e;
          }
          if (t > 1) {
            if (Ct.getUint32(R) > 0)
              throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");
            n = Ct.getUint32(R + 4);
          } else
            ot.int64AsNumber ? (n = Ct.getUint32(R) * 4294967296, n += Ct.getUint32(R + 4)) : n = Ct.getBigUint64(R);
          R += 8;
          break;
        case 31:
          switch (t) {
            case 2:
            case 3:
              throw new Error("Indefinite length not supported for byte or text strings");
            case 4:
              let e = [], r, s = 0;
              for (; (r = at()) != He; ) {
                if (s >= Xe)
                  throw new Error(`Array length exceeds ${Xe}`);
                e[s++] = r;
              }
              return t == 4 ? e : t == 3 ? e.join("") : Buffer.concat(e);
            case 5:
              let o;
              if (ot.mapsAsObjects) {
                let i = {}, a = 0;
                if (ot.keyMap)
                  for (; (o = at()) != He; ) {
                    if (a++ >= se)
                      throw new Error(`Property count exceeds ${se}`);
                    i[Lt(ot.decodeKey(o))] = at();
                  }
                else
                  for (; (o = at()) != He; ) {
                    if (a++ >= se)
                      throw new Error(`Property count exceeds ${se}`);
                    i[Lt(o)] = at();
                  }
                return i;
              } else {
                nn && (ot.mapsAsObjects = true, nn = false);
                let i = /* @__PURE__ */ new Map();
                if (ot.keyMap) {
                  let a = 0;
                  for (; (o = at()) != He; ) {
                    if (a++ >= se)
                      throw new Error(`Map size exceeds ${se}`);
                    i.set(ot.decodeKey(o), at());
                  }
                } else {
                  let a = 0;
                  for (; (o = at()) != He; ) {
                    if (a++ >= se)
                      throw new Error(`Map size exceeds ${se}`);
                    i.set(o, at());
                  }
                }
                return i;
              }
            case 7:
              return He;
            default:
              throw new Error("Invalid major type for indefinite length " + t);
          }
        default:
          throw new Error("Unknown token " + n);
      }
    switch (t) {
      case 0:
        return n;
      case 1:
        return ~n;
      case 2:
        return kh(n);
      case 3:
        if (hn >= R)
          return Kn.slice(R - Jn, (R += n) - Jn);
        if (hn == 0 && Oe < 140 && n < 32) {
          let s = n < 16 ? Wc(n) : Ih(n);
          if (s != null)
            return s;
        }
        return xh(n);
      case 4:
        if (n >= Xe)
          throw new Error(`Array length exceeds ${Xe}`);
        let e = new Array(n);
        for (let s = 0; s < n; s++)
          e[s] = at();
        return e;
      case 5:
        if (n >= se)
          throw new Error(`Map size exceeds ${Xe}`);
        if (ot.mapsAsObjects) {
          let s = {};
          if (ot.keyMap)
            for (let o = 0; o < n; o++)
              s[Lt(ot.decodeKey(at()))] = at();
          else
            for (let o = 0; o < n; o++)
              s[Lt(at())] = at();
          return s;
        } else {
          nn && (ot.mapsAsObjects = true, nn = false);
          let s = /* @__PURE__ */ new Map();
          if (ot.keyMap)
            for (let o = 0; o < n; o++)
              s.set(ot.decodeKey(at()), at());
          else
            for (let o = 0; o < n; o++)
              s.set(at(), at());
          return s;
        }
      case 6:
        if (n >= po) {
          let s = ht[n & 8191];
          if (s)
            return s.read || (s.read = Br(s)), s.read();
          if (n < 65536) {
            if (n == Sh) {
              let o = Pe(), i = at(), a = at();
              Fr(i, a);
              let c = {};
              if (ot.keyMap)
                for (let f = 2; f < o; f++) {
                  let u = ot.decodeKey(a[f - 2]);
                  c[Lt(u)] = at();
                }
              else
                for (let f = 2; f < o; f++) {
                  let u = a[f - 2];
                  c[Lt(u)] = at();
                }
              return c;
            } else if (n == vh) {
              let o = Pe(), i = at();
              for (let a = 2; a < o; a++)
                Fr(i++, at());
              return at();
            } else if (n == po)
              return Th();
            if (ot.getShared && (Ls(), s = ht[n & 8191], s))
              return s.read || (s.read = Br(s)), s.read();
          }
        }
        let r = pt[n];
        if (r)
          return r.handlesRead ? r(at) : r(at());
        {
          let s = at();
          for (let o = 0; o < Ur.length; o++) {
            let i = Ur[o](n, s);
            if (i !== void 0)
              return i;
          }
          return new Re(s, n);
        }
      case 7:
        switch (n) {
          case 20:
            return false;
          case 21:
            return true;
          case 22:
            return null;
          case 23:
            return;
          case 31:
          default:
            let s = (Mt || Ie())[n];
            if (s !== void 0)
              return s;
            throw new Error("Unknown token " + n);
        }
      default:
        if (isNaN(n)) {
          let s = new Error("Unexpected end of CBOR data");
          throw s.incomplete = true, s;
        }
        throw new Error("Unknown CBOR token " + n);
    }
  }
  const mo = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
  function Br(n) {
    if (!n)
      throw new Error("Structure is required in record definition");
    function t() {
      let e = K[R++];
      if (e = e & 31, e > 23)
        switch (e) {
          case 24:
            e = K[R++];
            break;
          case 25:
            e = Ct.getUint16(R), R += 2;
            break;
          case 26:
            e = Ct.getUint32(R), R += 4;
            break;
          default:
            throw new Error("Expected array header, but got " + K[R - 1]);
        }
      let r = this.compiledReader;
      for (; r; ) {
        if (r.propertyCount === e)
          return r(at);
        r = r.next;
      }
      if (this.slowReads++ >= Nc) {
        let o = this.length == e ? this : this.slice(0, e);
        return r = ot.keyMap ? new Function("r", "return {" + o.map((i) => ot.decodeKey(i)).map((i) => mo.test(i) ? Lt(i) + ":r()" : "[" + JSON.stringify(i) + "]:r()").join(",") + "}") : new Function("r", "return {" + o.map((i) => mo.test(i) ? Lt(i) + ":r()" : "[" + JSON.stringify(i) + "]:r()").join(",") + "}"), this.compiledReader && (r.next = this.compiledReader), r.propertyCount = e, this.compiledReader = r, r(at);
      }
      let s = {};
      if (ot.keyMap)
        for (let o = 0; o < e; o++)
          s[Lt(ot.decodeKey(this[o]))] = at();
      else
        for (let o = 0; o < e; o++)
          s[Lt(this[o])] = at();
      return s;
    }
    return n.slowReads = 0, t;
  }
  function Lt(n) {
    if (typeof n == "string")
      return n === "__proto__" ? "__proto_" : n;
    if (typeof n == "number" || typeof n == "boolean" || typeof n == "bigint")
      return n.toString();
    if (n == null)
      return n + "";
    throw new Error("Invalid property name type " + typeof n);
  }
  let xh = Pr;
  function Pr(n) {
    let t;
    if (n < 16 && (t = Wc(n)))
      return t;
    if (n > 64 && $r)
      return $r.decode(K.subarray(R, R += n));
    const e = R + n, r = [];
    for (t = ""; R < e; ) {
      const s = K[R++];
      if (!(s & 128))
        r.push(s);
      else if ((s & 224) === 192) {
        const o = K[R++] & 63;
        r.push((s & 31) << 6 | o);
      } else if ((s & 240) === 224) {
        const o = K[R++] & 63, i = K[R++] & 63;
        r.push((s & 31) << 12 | o << 6 | i);
      } else if ((s & 248) === 240) {
        const o = K[R++] & 63, i = K[R++] & 63, a = K[R++] & 63;
        let c = (s & 7) << 18 | o << 12 | i << 6 | a;
        c > 65535 && (c -= 65536, r.push(c >>> 10 & 1023 | 55296), c = 56320 | c & 1023), r.push(c);
      } else
        r.push(s);
      r.length >= 4096 && (t += mt.apply(String, r), r.length = 0);
    }
    return r.length > 0 && (t += mt.apply(String, r)), t;
  }
  let mt = String.fromCharCode;
  function Ih(n) {
    let t = R, e = new Array(n);
    for (let r = 0; r < n; r++) {
      const s = K[R++];
      if ((s & 128) > 0) {
        R = t;
        return;
      }
      e[r] = s;
    }
    return mt.apply(String, e);
  }
  function Wc(n) {
    if (n < 4)
      if (n < 2) {
        if (n === 0)
          return "";
        {
          let t = K[R++];
          if ((t & 128) > 1) {
            R -= 1;
            return;
          }
          return mt(t);
        }
      } else {
        let t = K[R++], e = K[R++];
        if ((t & 128) > 0 || (e & 128) > 0) {
          R -= 2;
          return;
        }
        if (n < 3)
          return mt(t, e);
        let r = K[R++];
        if ((r & 128) > 0) {
          R -= 3;
          return;
        }
        return mt(t, e, r);
      }
    else {
      let t = K[R++], e = K[R++], r = K[R++], s = K[R++];
      if ((t & 128) > 0 || (e & 128) > 0 || (r & 128) > 0 || (s & 128) > 0) {
        R -= 4;
        return;
      }
      if (n < 6) {
        if (n === 4)
          return mt(t, e, r, s);
        {
          let o = K[R++];
          if ((o & 128) > 0) {
            R -= 5;
            return;
          }
          return mt(t, e, r, s, o);
        }
      } else if (n < 8) {
        let o = K[R++], i = K[R++];
        if ((o & 128) > 0 || (i & 128) > 0) {
          R -= 6;
          return;
        }
        if (n < 7)
          return mt(t, e, r, s, o, i);
        let a = K[R++];
        if ((a & 128) > 0) {
          R -= 7;
          return;
        }
        return mt(t, e, r, s, o, i, a);
      } else {
        let o = K[R++], i = K[R++], a = K[R++], c = K[R++];
        if ((o & 128) > 0 || (i & 128) > 0 || (a & 128) > 0 || (c & 128) > 0) {
          R -= 8;
          return;
        }
        if (n < 10) {
          if (n === 8)
            return mt(t, e, r, s, o, i, a, c);
          {
            let f = K[R++];
            if ((f & 128) > 0) {
              R -= 9;
              return;
            }
            return mt(t, e, r, s, o, i, a, c, f);
          }
        } else if (n < 12) {
          let f = K[R++], u = K[R++];
          if ((f & 128) > 0 || (u & 128) > 0) {
            R -= 10;
            return;
          }
          if (n < 11)
            return mt(t, e, r, s, o, i, a, c, f, u);
          let _ = K[R++];
          if ((_ & 128) > 0) {
            R -= 11;
            return;
          }
          return mt(t, e, r, s, o, i, a, c, f, u, _);
        } else {
          let f = K[R++], u = K[R++], _ = K[R++], d = K[R++];
          if ((f & 128) > 0 || (u & 128) > 0 || (_ & 128) > 0 || (d & 128) > 0) {
            R -= 12;
            return;
          }
          if (n < 14) {
            if (n === 12)
              return mt(t, e, r, s, o, i, a, c, f, u, _, d);
            {
              let l = K[R++];
              if ((l & 128) > 0) {
                R -= 13;
                return;
              }
              return mt(t, e, r, s, o, i, a, c, f, u, _, d, l);
            }
          } else {
            let l = K[R++], w = K[R++];
            if ((l & 128) > 0 || (w & 128) > 0) {
              R -= 14;
              return;
            }
            if (n < 15)
              return mt(t, e, r, s, o, i, a, c, f, u, _, d, l, w);
            let k = K[R++];
            if ((k & 128) > 0) {
              R -= 15;
              return;
            }
            return mt(t, e, r, s, o, i, a, c, f, u, _, d, l, w, k);
          }
        }
      }
    }
  }
  function kh(n) {
    return ot.copyBuffers ? Uint8Array.prototype.slice.call(K, R, R += n) : K.subarray(R, R += n);
  }
  let Kc = new Float32Array(1), On = new Uint8Array(Kc.buffer, 0, 4);
  function Ah() {
    let n = K[R++], t = K[R++], e = (n & 127) >> 2;
    if (e === 31)
      return t || n & 3 ? NaN : n & 128 ? -1 / 0 : 1 / 0;
    if (e === 0) {
      let r = ((n & 3) << 8 | t) / 16777216;
      return n & 128 ? -r : r;
    }
    return On[3] = n & 128 | (e >> 1) + 56, On[2] = (n & 7) << 5 | t >> 3, On[1] = t << 5, On[0] = 0, Kc[0];
  }
  new Array(4096);
  class Re {
    constructor(t, e) {
      this.value = t, this.tag = e;
    }
  }
  pt[0] = (n) => new Date(n);
  pt[1] = (n) => new Date(Math.round(n * 1e3));
  pt[2] = (n) => {
    let t = BigInt(0);
    for (let e = 0, r = n.byteLength; e < r; e++)
      t = BigInt(n[e]) + (t << BigInt(8));
    return t;
  };
  pt[3] = (n) => BigInt(-1) - pt[2](n);
  pt[4] = (n) => +(n[1] + "e" + n[0]);
  pt[5] = (n) => n[1] * Math.exp(n[0] * Math.log(2));
  const Fr = (n, t) => {
    n = n - 57344;
    let e = ht[n];
    e && e.isShared && ((ht.restoreStructures || (ht.restoreStructures = []))[n] = e), ht[n] = t, t.read = Br(t);
  };
  pt[mh] = (n) => {
    let t = n.length, e = n[1];
    Fr(n[0], e);
    let r = {};
    for (let s = 2; s < t; s++) {
      let o = e[s - 2];
      r[Lt(o)] = n[s];
    }
    return r;
  };
  pt[14] = (n) => yt ? yt[0].slice(yt.position0, yt.position0 += n) : new Re(n, 14);
  pt[15] = (n) => yt ? yt[1].slice(yt.position1, yt.position1 += n) : new Re(n, 15);
  let Eh = {
    Error,
    RegExp
  };
  pt[27] = (n) => (Eh[n[0]] || Error)(n[1], n[2]);
  const Jc = (n) => {
    if (K[R++] != 132) {
      let e = new Error("Packed values structure must be followed by a 4 element array");
      throw K.length < R && (e.incomplete = true), e;
    }
    let t = n();
    if (!t || !t.length) {
      let e = new Error("Packed values structure must be followed by a 4 element array");
      throw e.incomplete = true, e;
    }
    return Mt = Mt ? t.concat(Mt.slice(t.length)) : t, Mt.prefixes = n(), Mt.suffixes = n(), n();
  };
  Jc.handlesRead = true;
  pt[51] = Jc;
  pt[wo] = (n) => {
    if (!Mt)
      if (ot.getShared)
        Ls();
      else
        return new Re(n, wo);
    if (typeof n == "number")
      return Mt[16 + (n >= 0 ? 2 * n : -2 * n - 1)];
    let t = new Error("No support for non-integer packed references yet");
    throw n === void 0 && (t.incomplete = true), t;
  };
  pt[28] = (n) => {
    Ft || (Ft = /* @__PURE__ */ new Map(), Ft.id = 0);
    let t = Ft.id++, e = R, r = K[R], s;
    r >> 5 == 4 ? s = [] : s = {};
    let o = {
      target: s
    };
    Ft.set(t, o);
    let i = n();
    return o.used ? (Object.getPrototypeOf(s) !== Object.getPrototypeOf(i) && (R = e, s = i, Ft.set(t, {
      target: s
    }), i = n()), Object.assign(s, i)) : (o.target = i, i);
  };
  pt[28].handlesRead = true;
  pt[29] = (n) => {
    let t = Ft.get(n);
    return t.used = true, t.target;
  };
  pt[258] = (n) => new Set(n);
  (pt[259] = (n) => (ot.mapsAsObjects && (ot.mapsAsObjects = false, nn = true), n())).handlesRead = true;
  function De(n, t) {
    return typeof n == "string" ? n + t : n instanceof Array ? n.concat(t) : Object.assign({}, n, t);
  }
  function Ie() {
    if (!Mt)
      if (ot.getShared)
        Ls();
      else
        throw new Error("No packed values available");
    return Mt;
  }
  const Ch = 1399353956;
  Ur.push((n, t) => {
    if (n >= 225 && n <= 255)
      return De(Ie().prefixes[n - 224], t);
    if (n >= 28704 && n <= 32767)
      return De(Ie().prefixes[n - 28672], t);
    if (n >= 1879052288 && n <= 2147483647)
      return De(Ie().prefixes[n - 1879048192], t);
    if (n >= 216 && n <= 223)
      return De(t, Ie().suffixes[n - 216]);
    if (n >= 27647 && n <= 28671)
      return De(t, Ie().suffixes[n - 27639]);
    if (n >= 1811940352 && n <= 1879048191)
      return De(t, Ie().suffixes[n - 1811939328]);
    if (n == Ch)
      return {
        packedValues: Mt,
        structures: ht.slice(0),
        version: t
      };
    if (n == 55799)
      return t;
  });
  const Oh = new Uint8Array(new Uint16Array([
    1
  ]).buffer)[0] == 1, vo = [
    Uint8Array,
    Uint8ClampedArray,
    Uint16Array,
    Uint32Array,
    typeof BigUint64Array > "u" ? {
      name: "BigUint64Array"
    } : BigUint64Array,
    Int8Array,
    Int16Array,
    Int32Array,
    typeof BigInt64Array > "u" ? {
      name: "BigInt64Array"
    } : BigInt64Array,
    Float32Array,
    Float64Array
  ], jh = [
    64,
    68,
    69,
    70,
    71,
    72,
    77,
    78,
    79,
    85,
    86
  ];
  for (let n = 0; n < vo.length; n++)
    Rh(vo[n], jh[n]);
  function Rh(n, t) {
    let e = "get" + n.name.slice(0, -5), r;
    typeof n == "function" ? r = n.BYTES_PER_ELEMENT : n = null;
    for (let s = 0; s < 2; s++) {
      if (!s && r == 1)
        continue;
      let o = r == 2 ? 1 : r == 4 ? 2 : r == 8 ? 3 : 0;
      pt[s ? t : t - 4] = r == 1 || s == Oh ? (i) => {
        if (!n)
          throw new Error("Could not find typed array for code " + t);
        return !ot.copyBuffers && (r === 1 || r === 2 && !(i.byteOffset & 1) || r === 4 && !(i.byteOffset & 3) || r === 8 && !(i.byteOffset & 7)) ? new n(i.buffer, i.byteOffset, i.byteLength >> o) : new n(Uint8Array.prototype.slice.call(i, 0).buffer);
      } : (i) => {
        if (!n)
          throw new Error("Could not find typed array for code " + t);
        let a = new DataView(i.buffer, i.byteOffset, i.byteLength), c = i.length >> o, f = new n(c), u = a[e];
        for (let _ = 0; _ < c; _++)
          f[_] = u.call(a, _ << o, s);
        return f;
      };
    }
  }
  function Th() {
    let n = Pe(), t = R + at();
    for (let r = 2; r < n; r++) {
      let s = Pe();
      R += s;
    }
    let e = R;
    return R = t, yt = [
      Pr(Pe()),
      Pr(Pe())
    ], yt.position0 = 0, yt.position1 = 0, yt.postBundlePosition = R, R = e, at();
  }
  function Pe() {
    let n = K[R++] & 31;
    if (n > 23)
      switch (n) {
        case 24:
          n = K[R++];
          break;
        case 25:
          n = Ct.getUint16(R), R += 2;
          break;
        case 26:
          n = Ct.getUint32(R), R += 4;
          break;
      }
    return n;
  }
  function Ls() {
    if (ot.getShared) {
      let n = Gc(() => (K = null, ot.getShared())) || {}, t = n.structures || [];
      ot.sharedVersion = n.version, Mt = ot.sharedValues = n.packedValues, ht === true ? ot.structures = ht = t : ht.splice.apply(ht, [
        0,
        t.length
      ].concat(t));
    }
  }
  function Gc(n) {
    let t = Oe, e = R, r = Jn, s = hn, o = Kn, i = Ft, a = yt, c = new Uint8Array(K.slice(0, Oe)), f = ht, u = ot, _ = gn, d = n();
    return Oe = t, R = e, Jn = r, hn = s, Kn = o, Ft = i, yt = a, K = c, gn = _, ht = f, ot = u, Ct = new DataView(K.buffer, K.byteOffset, K.byteLength), d;
  }
  function Lr() {
    K = null, Ft = null, ht = null;
  }
  const Vs = new Array(147);
  for (let n = 0; n < 256; n++)
    Vs[n] = +("1e" + Math.floor(45.15 - n * 0.30103));
  let zs = new bn({
    useRecords: false
  });
  const qc = zs.decode;
  zs.decodeMultiple;
  let Bn;
  try {
    Bn = new TextEncoder();
  } catch {
  }
  let Vr, Yc;
  const ir = typeof globalThis == "object" && globalThis.Buffer, In = typeof ir < "u", lr = In ? ir.allocUnsafeSlow : Uint8Array, So = In ? ir : Uint8Array, xo = 256, Io = In ? 4294967296 : 2144337920;
  let hr, x, dt, p = 0, pe, wt = null;
  const Mh = 61440, Hh = /[\u0080-\uFFFF]/, $t = Symbol("record-id");
  class Xc extends bn {
    constructor(t) {
      super(t), this.offset = 0;
      let e, r, s, o, i;
      t = t || {};
      let a = So.prototype.utf8Write ? function(S, W, H) {
        return x.utf8Write(S, W, H);
      } : Bn && Bn.encodeInto ? function(S, W) {
        return Bn.encodeInto(S, x.subarray(W)).written;
      } : false, c = this, f = t.structures || t.saveStructures, u = t.maxSharedStructures;
      if (u == null && (u = f ? 128 : 0), u > 8190)
        throw new Error("Maximum maxSharedStructure is 8190");
      let _ = t.sequential;
      _ && (u = 0), this.structures || (this.structures = []), this.saveStructures && (this.saveShared = this.saveStructures);
      let d, l, w = t.sharedValues, k;
      if (w) {
        k = /* @__PURE__ */ Object.create(null);
        for (let S = 0, W = w.length; S < W; S++)
          k[w[S]] = S;
      }
      let j = [], L = 0, N = 0;
      this.mapEncode = function(S, W) {
        if (this._keyMap && !this._mapped)
          switch (S.constructor.name) {
            case "Array":
              S = S.map((H) => this.encodeKeys(H));
              break;
          }
        return this.encode(S, W);
      }, this.encode = function(S, W) {
        if (x || (x = new lr(8192), dt = new DataView(x.buffer, 0, 8192), p = 0), pe = x.length - 10, pe - p < 2048 ? (x = new lr(x.length), dt = new DataView(x.buffer, 0, x.length), pe = x.length - 10, p = 0) : W === Eo && (p = p + 7 & 2147483640), e = p, c.useSelfDescribedHeader && (dt.setUint32(p, 3654940416), p += 3), i = c.structuredClone ? /* @__PURE__ */ new Map() : null, c.bundleStrings && typeof S != "string" ? (wt = [], wt.size = 1 / 0) : wt = null, r = c.structures, r) {
          if (r.uninitialized) {
            let P = c.getShared() || {};
            c.structures = r = P.structures || [], c.sharedVersion = P.version;
            let D = c.sharedValues = P.packedValues;
            if (D) {
              k = {};
              for (let et = 0, v = D.length; et < v; et++)
                k[D[et]] = et;
            }
          }
          let H = r.length;
          if (H > u && !_ && (H = u), !r.transitions) {
            r.transitions = /* @__PURE__ */ Object.create(null);
            for (let P = 0; P < H; P++) {
              let D = r[P];
              if (!D)
                continue;
              let et, v = r.transitions;
              for (let $ = 0, J = D.length; $ < J; $++) {
                v[$t] === void 0 && (v[$t] = P);
                let G = D[$];
                et = v[G], et || (et = v[G] = /* @__PURE__ */ Object.create(null)), v = et;
              }
              v[$t] = P | 1048576;
            }
          }
          _ || (r.nextId = H);
        }
        if (s && (s = false), o = r || [], l = k, t.pack) {
          let H = /* @__PURE__ */ new Map();
          if (H.values = [], H.encoder = c, H.maxValues = t.maxPrivatePackedValues || (k ? 16 : 1 / 0), H.objectMap = k || false, H.samplingPackedValues = d, Pn(S, H), H.values.length > 0) {
            x[p++] = 216, x[p++] = 51, Yt(4);
            let P = H.values;
            O(P), Yt(0), Yt(0), l = Object.create(k || null);
            for (let D = 0, et = P.length; D < et; D++)
              l[P[D]] = D;
          }
        }
        hr = W & br;
        try {
          if (hr)
            return;
          if (O(S), wt && Ao(e, O), c.offset = p, i && i.idsToInsert) {
            p += i.idsToInsert.length * 2, p > pe && Z(p), c.offset = p;
            let H = Uh(x.subarray(e, p), i.idsToInsert);
            return i = null, H;
          }
          return W & Eo ? (x.start = e, x.end = p, x) : x.subarray(e, p);
        } finally {
          if (r) {
            if (N < 10 && N++, r.length > u && (r.length = u), L > 1e4)
              r.transitions = null, N = 0, L = 0, j.length > 0 && (j = []);
            else if (j.length > 0 && !_) {
              for (let H = 0, P = j.length; H < P; H++)
                j[H][$t] = void 0;
              j = [];
            }
          }
          if (s && c.saveShared) {
            c.structures.length > u && (c.structures = c.structures.slice(0, u));
            let H = x.subarray(e, p);
            return c.updateSharedData() === false ? c.encode(S) : H;
          }
          W & Bh && (p = e);
        }
      }, this.findCommonStringsToPack = () => (d = /* @__PURE__ */ new Map(), k || (k = /* @__PURE__ */ Object.create(null)), (S) => {
        let W = S && S.threshold || 4, H = this.pack ? S.maxPrivatePackedValues || 16 : 0;
        w || (w = this.sharedValues = []);
        for (let [P, D] of d)
          D.count > W && (k[P] = H++, w.push(P), s = true);
        for (; this.saveShared && this.updateSharedData() === false; )
          ;
        d = null;
      });
      const O = (S) => {
        p > pe && (x = Z(p));
        var W = typeof S, H;
        if (W === "string") {
          if (l) {
            let v = l[S];
            if (v >= 0) {
              v < 16 ? x[p++] = v + 224 : (x[p++] = 198, v & 1 ? O(15 - v >> 1) : O(v - 16 >> 1));
              return;
            } else if (d && !t.pack) {
              let $ = d.get(S);
              $ ? $.count++ : d.set(S, {
                count: 1
              });
            }
          }
          let P = S.length;
          if (wt && P >= 4 && P < 1024) {
            if ((wt.size += P) > Mh) {
              let $, J = (wt[0] ? wt[0].length * 3 + wt[1].length : 0) + 10;
              p + J > pe && (x = Z(p + J)), x[p++] = 217, x[p++] = 223, x[p++] = 249, x[p++] = wt.position ? 132 : 130, x[p++] = 26, $ = p - e, p += 4, wt.position && Ao(e, O), wt = [
                "",
                ""
              ], wt.size = 0, wt.position = $;
            }
            let v = Hh.test(S);
            wt[v ? 0 : 1] += S, x[p++] = v ? 206 : 207, O(P);
            return;
          }
          let D;
          P < 32 ? D = 1 : P < 256 ? D = 2 : P < 65536 ? D = 3 : D = 5;
          let et = P * 3;
          if (p + et > pe && (x = Z(p + et)), P < 64 || !a) {
            let v, $, J, G = p + D;
            for (v = 0; v < P; v++)
              $ = S.charCodeAt(v), $ < 128 ? x[G++] = $ : $ < 2048 ? (x[G++] = $ >> 6 | 192, x[G++] = $ & 63 | 128) : ($ & 64512) === 55296 && ((J = S.charCodeAt(v + 1)) & 64512) === 56320 ? ($ = 65536 + (($ & 1023) << 10) + (J & 1023), v++, x[G++] = $ >> 18 | 240, x[G++] = $ >> 12 & 63 | 128, x[G++] = $ >> 6 & 63 | 128, x[G++] = $ & 63 | 128) : (x[G++] = $ >> 12 | 224, x[G++] = $ >> 6 & 63 | 128, x[G++] = $ & 63 | 128);
            H = G - p - D;
          } else
            H = a(S, p + D, et);
          H < 24 ? x[p++] = 96 | H : H < 256 ? (D < 2 && x.copyWithin(p + 2, p + 1, p + 1 + H), x[p++] = 120, x[p++] = H) : H < 65536 ? (D < 3 && x.copyWithin(p + 3, p + 2, p + 2 + H), x[p++] = 121, x[p++] = H >> 8, x[p++] = H & 255) : (D < 5 && x.copyWithin(p + 5, p + 3, p + 3 + H), x[p++] = 122, dt.setUint32(p, H), p += 4), p += H;
        } else if (W === "number")
          if (!this.alwaysUseFloat && S >>> 0 === S)
            S < 24 ? x[p++] = S : S < 256 ? (x[p++] = 24, x[p++] = S) : S < 65536 ? (x[p++] = 25, x[p++] = S >> 8, x[p++] = S & 255) : (x[p++] = 26, dt.setUint32(p, S), p += 4);
          else if (!this.alwaysUseFloat && S >> 0 === S)
            S >= -24 ? x[p++] = 31 - S : S >= -256 ? (x[p++] = 56, x[p++] = ~S) : S >= -65536 ? (x[p++] = 57, dt.setUint16(p, ~S), p += 2) : (x[p++] = 58, dt.setUint32(p, ~S), p += 4);
          else {
            let P;
            if ((P = this.useFloat32) > 0 && S < 4294967296 && S >= -2147483648) {
              x[p++] = 250, dt.setFloat32(p, S);
              let D;
              if (P < 4 || (D = S * Vs[(x[p] & 127) << 1 | x[p + 1] >> 7]) >> 0 === D) {
                p += 4;
                return;
              } else
                p--;
            }
            x[p++] = 251, dt.setFloat64(p, S), p += 8;
          }
        else if (W === "object")
          if (!S)
            x[p++] = 246;
          else {
            if (i) {
              let D = i.get(S);
              if (D) {
                if (x[p++] = 216, x[p++] = 29, x[p++] = 25, !D.references) {
                  let et = i.idsToInsert || (i.idsToInsert = []);
                  D.references = [], et.push(D);
                }
                D.references.push(p - e), p += 2;
                return;
              } else
                i.set(S, {
                  offset: p - e
                });
            }
            let P = S.constructor;
            if (P === Object)
              q(S);
            else if (P === Array) {
              H = S.length, H < 24 ? x[p++] = 128 | H : Yt(H);
              for (let D = 0; D < H; D++)
                O(S[D]);
            } else if (P === Map)
              if ((this.mapsAsObjects ? this.useTag259ForMaps !== false : this.useTag259ForMaps) && (x[p++] = 217, x[p++] = 1, x[p++] = 3), H = S.size, H < 24 ? x[p++] = 160 | H : H < 256 ? (x[p++] = 184, x[p++] = H) : H < 65536 ? (x[p++] = 185, x[p++] = H >> 8, x[p++] = H & 255) : (x[p++] = 186, dt.setUint32(p, H), p += 4), c.keyMap)
                for (let [D, et] of S)
                  O(c.encodeKey(D)), O(et);
              else
                for (let [D, et] of S)
                  O(D), O(et);
            else {
              for (let D = 0, et = Vr.length; D < et; D++) {
                let v = Yc[D];
                if (S instanceof v) {
                  let $ = Vr[D], J = $.tag;
                  J == null && (J = $.getTag && $.getTag.call(this, S)), J < 24 ? x[p++] = 192 | J : J < 256 ? (x[p++] = 216, x[p++] = J) : J < 65536 ? (x[p++] = 217, x[p++] = J >> 8, x[p++] = J & 255) : J > -1 && (x[p++] = 218, dt.setUint32(p, J), p += 4), $.encode.call(this, S, O, Z);
                  return;
                }
              }
              if (S[Symbol.iterator]) {
                if (hr) {
                  let D = new Error("Iterable should be serialized as iterator");
                  throw D.iteratorNotHandled = true, D;
                }
                x[p++] = 159;
                for (let D of S)
                  O(D);
                x[p++] = 255;
                return;
              }
              if (S[Symbol.asyncIterator] || gr(S)) {
                let D = new Error("Iterable/blob should be serialized as iterator");
                throw D.iteratorNotHandled = true, D;
              }
              if (this.useToJSON && S.toJSON) {
                const D = S.toJSON();
                if (D !== S)
                  return O(D);
              }
              q(S);
            }
          }
        else if (W === "boolean")
          x[p++] = S ? 245 : 244;
        else if (W === "bigint") {
          if (S < BigInt(1) << BigInt(64) && S >= 0)
            x[p++] = 27, dt.setBigUint64(p, S);
          else if (S > -(BigInt(1) << BigInt(64)) && S < 0)
            x[p++] = 59, dt.setBigUint64(p, -S - BigInt(1));
          else if (this.largeBigIntToFloat)
            x[p++] = 251, dt.setFloat64(p, Number(S));
          else {
            S >= BigInt(0) ? x[p++] = 194 : (x[p++] = 195, S = BigInt(-1) - S);
            let P = [];
            for (; S; )
              P.push(Number(S & BigInt(255))), S >>= BigInt(8);
            zr(new Uint8Array(P.reverse()), Z);
            return;
          }
          p += 8;
        } else if (W === "undefined")
          x[p++] = 247;
        else
          throw new Error("Unknown type: " + W);
      }, q = this.useRecords === false ? this.variableMapSize ? (S) => {
        let W = Object.keys(S), H = Object.values(S), P = W.length;
        if (P < 24 ? x[p++] = 160 | P : P < 256 ? (x[p++] = 184, x[p++] = P) : P < 65536 ? (x[p++] = 185, x[p++] = P >> 8, x[p++] = P & 255) : (x[p++] = 186, dt.setUint32(p, P), p += 4), c.keyMap)
          for (let D = 0; D < P; D++)
            O(c.encodeKey(W[D])), O(H[D]);
        else
          for (let D = 0; D < P; D++)
            O(W[D]), O(H[D]);
      } : (S) => {
        x[p++] = 185;
        let W = p - e;
        p += 2;
        let H = 0;
        if (c.keyMap)
          for (let P in S)
            (typeof S.hasOwnProperty != "function" || S.hasOwnProperty(P)) && (O(c.encodeKey(P)), O(S[P]), H++);
        else
          for (let P in S)
            (typeof S.hasOwnProperty != "function" || S.hasOwnProperty(P)) && (O(P), O(S[P]), H++);
        x[W++ + e] = H >> 8, x[W + e] = H & 255;
      } : (S, W) => {
        let H, P = o.transitions || (o.transitions = /* @__PURE__ */ Object.create(null)), D = 0, et = 0, v, $;
        if (this.keyMap) {
          $ = Object.keys(S).map((G) => this.encodeKey(G)), et = $.length;
          for (let G = 0; G < et; G++) {
            let gt = $[G];
            H = P[gt], H || (H = P[gt] = /* @__PURE__ */ Object.create(null), D++), P = H;
          }
        } else
          for (let G in S)
            (typeof S.hasOwnProperty != "function" || S.hasOwnProperty(G)) && (H = P[G], H || (P[$t] & 1048576 && (v = P[$t] & 65535), H = P[G] = /* @__PURE__ */ Object.create(null), D++), P = H, et++);
        let J = P[$t];
        if (J !== void 0)
          J &= 65535, x[p++] = 217, x[p++] = J >> 8 | 224, x[p++] = J & 255;
        else if ($ || ($ = P.__keys__ || (P.__keys__ = Object.keys(S))), v === void 0 ? (J = o.nextId++, J || (J = 0, o.nextId = 1), J >= xo && (o.nextId = (J = u) + 1)) : J = v, o[J] = $, J < u) {
          x[p++] = 217, x[p++] = J >> 8 | 224, x[p++] = J & 255, P = o.transitions;
          for (let G = 0; G < et; G++)
            (P[$t] === void 0 || P[$t] & 1048576) && (P[$t] = J), P = P[$[G]];
          P[$t] = J | 1048576, s = true;
        } else {
          if (P[$t] = J, dt.setUint32(p, 3655335680), p += 3, D && (L += N * D), j.length >= xo - u && (j.shift()[$t] = void 0), j.push(P), Yt(et + 2), O(57344 + J), O($), W)
            return;
          for (let G in S)
            (typeof S.hasOwnProperty != "function" || S.hasOwnProperty(G)) && O(S[G]);
          return;
        }
        if (et < 24 ? x[p++] = 128 | et : Yt(et), !W)
          for (let G in S)
            (typeof S.hasOwnProperty != "function" || S.hasOwnProperty(G)) && O(S[G]);
      }, Z = (S) => {
        let W;
        if (S > 16777216) {
          if (S - e > Io)
            throw new Error("Encoded buffer would be larger than maximum buffer size");
          W = Math.min(Io, Math.round(Math.max((S - e) * (S > 67108864 ? 1.25 : 2), 4194304) / 4096) * 4096);
        } else
          W = (Math.max(S - e << 2, x.length - 1) >> 12) + 1 << 12;
        let H = new lr(W);
        return dt = new DataView(H.buffer, 0, W), x.copy ? x.copy(H, 0, e, S) : H.set(x.slice(e, S)), p -= e, e = 0, pe = H.length - 10, x = H;
      };
      let Y = 100, it = 1e3;
      this.encodeAsIterable = function(S, W) {
        return jt(S, W, tt);
      }, this.encodeAsAsyncIterable = function(S, W) {
        return jt(S, W, At);
      };
      function* tt(S, W, H) {
        let P = S.constructor;
        if (P === Object) {
          let D = c.useRecords !== false;
          D ? q(S, true) : ko(Object.keys(S).length, 160);
          for (let et in S) {
            let v = S[et];
            D || O(et), v && typeof v == "object" ? W[et] ? yield* tt(v, W[et]) : yield* st(v, W, et) : O(v);
          }
        } else if (P === Array) {
          let D = S.length;
          Yt(D);
          for (let et = 0; et < D; et++) {
            let v = S[et];
            v && (typeof v == "object" || p - e > Y) ? W.element ? yield* tt(v, W.element) : yield* st(v, W, "element") : O(v);
          }
        } else if (S[Symbol.iterator] && !S.buffer) {
          x[p++] = 159;
          for (let D of S)
            D && (typeof D == "object" || p - e > Y) ? W.element ? yield* tt(D, W.element) : yield* st(D, W, "element") : O(D);
          x[p++] = 255;
        } else
          gr(S) ? (ko(S.size, 64), yield x.subarray(e, p), yield S, ct()) : S[Symbol.asyncIterator] ? (x[p++] = 159, yield x.subarray(e, p), yield S, ct(), x[p++] = 255) : O(S);
        H && p > e ? yield x.subarray(e, p) : p - e > Y && (yield x.subarray(e, p), ct());
      }
      function* st(S, W, H) {
        let P = p - e;
        try {
          O(S), p - e > Y && (yield x.subarray(e, p), ct());
        } catch (D) {
          if (D.iteratorNotHandled)
            W[H] = {}, p = e + P, yield* tt.call(this, S, W[H]);
          else
            throw D;
        }
      }
      function ct() {
        Y = it, c.encode(null, br);
      }
      function jt(S, W, H) {
        return W && W.chunkThreshold ? Y = it = W.chunkThreshold : Y = 100, S && typeof S == "object" ? (c.encode(null, br), H(S, c.iterateProperties || (c.iterateProperties = {}), true)) : [
          c.encode(S)
        ];
      }
      async function* At(S, W) {
        for (let H of tt(S, W, true)) {
          let P = H.constructor;
          if (P === So || P === Uint8Array)
            yield H;
          else if (gr(H)) {
            let D = H.stream().getReader(), et;
            for (; !(et = await D.read()).done; )
              yield et.value;
          } else if (H[Symbol.asyncIterator])
            for await (let D of H)
              ct(), D ? yield* At(D, W.async || (W.async = {})) : yield c.encode(D);
          else
            yield H;
        }
      }
    }
    useBuffer(t) {
      x = t, dt = new DataView(x.buffer, x.byteOffset, x.byteLength), p = 0;
    }
    clearSharedData() {
      this.structures && (this.structures = []), this.sharedValues && (this.sharedValues = void 0);
    }
    updateSharedData() {
      let t = this.sharedVersion || 0;
      this.sharedVersion = t + 1;
      let e = this.structures.slice(0), r = new Zc(e, this.sharedValues, this.sharedVersion), s = this.saveShared(r, (o) => (o && o.version || 0) == t);
      return s === false ? (r = this.getShared() || {}, this.structures = r.structures || [], this.sharedValues = r.packedValues, this.sharedVersion = r.version, this.structures.nextId = this.structures.length) : e.forEach((o, i) => this.structures[i] = o), s;
    }
  }
  function ko(n, t) {
    n < 24 ? x[p++] = t | n : n < 256 ? (x[p++] = t | 24, x[p++] = n) : n < 65536 ? (x[p++] = t | 25, x[p++] = n >> 8, x[p++] = n & 255) : (x[p++] = t | 26, dt.setUint32(p, n), p += 4);
  }
  class Zc {
    constructor(t, e, r) {
      this.structures = t, this.packedValues = e, this.version = r;
    }
  }
  function Yt(n) {
    n < 24 ? x[p++] = 128 | n : n < 256 ? (x[p++] = 152, x[p++] = n) : n < 65536 ? (x[p++] = 153, x[p++] = n >> 8, x[p++] = n & 255) : (x[p++] = 154, dt.setUint32(p, n), p += 4);
  }
  const Dh = typeof Blob > "u" ? function() {
  } : Blob;
  function gr(n) {
    if (n instanceof Dh)
      return true;
    let t = n[Symbol.toStringTag];
    return t === "Blob" || t === "File";
  }
  function Pn(n, t) {
    switch (typeof n) {
      case "string":
        if (n.length > 3) {
          if (t.objectMap[n] > -1 || t.values.length >= t.maxValues)
            return;
          let r = t.get(n);
          if (r)
            ++r.count == 2 && t.values.push(n);
          else if (t.set(n, {
            count: 1
          }), t.samplingPackedValues) {
            let s = t.samplingPackedValues.get(n);
            s ? s.count++ : t.samplingPackedValues.set(n, {
              count: 1
            });
          }
        }
        break;
      case "object":
        if (n)
          if (n instanceof Array)
            for (let r = 0, s = n.length; r < s; r++)
              Pn(n[r], t);
          else {
            let r = !t.encoder.useRecords;
            for (var e in n)
              n.hasOwnProperty(e) && (r && Pn(e, t), Pn(n[e], t));
          }
        break;
      case "function":
        console.log(n);
    }
  }
  const $h = new Uint8Array(new Uint16Array([
    1
  ]).buffer)[0] == 1;
  Yc = [
    Date,
    Set,
    Error,
    RegExp,
    Re,
    ArrayBuffer,
    Uint8Array,
    Uint8ClampedArray,
    Uint16Array,
    Uint32Array,
    typeof BigUint64Array > "u" ? function() {
    } : BigUint64Array,
    Int8Array,
    Int16Array,
    Int32Array,
    typeof BigInt64Array > "u" ? function() {
    } : BigInt64Array,
    Float32Array,
    Float64Array,
    Zc
  ];
  Vr = [
    {
      tag: 1,
      encode(n, t) {
        let e = n.getTime() / 1e3;
        (this.useTimestamp32 || n.getMilliseconds() === 0) && e >= 0 && e < 4294967296 ? (x[p++] = 26, dt.setUint32(p, e), p += 4) : (x[p++] = 251, dt.setFloat64(p, e), p += 8);
      }
    },
    {
      tag: 258,
      encode(n, t) {
        let e = Array.from(n);
        t(e);
      }
    },
    {
      tag: 27,
      encode(n, t) {
        t([
          n.name,
          n.message
        ]);
      }
    },
    {
      tag: 27,
      encode(n, t) {
        t([
          "RegExp",
          n.source,
          n.flags
        ]);
      }
    },
    {
      getTag(n) {
        return n.tag;
      },
      encode(n, t) {
        t(n.value);
      }
    },
    {
      encode(n, t, e) {
        zr(n, e);
      }
    },
    {
      getTag(n) {
        if (n.constructor === Uint8Array && (this.tagUint8Array || In && this.tagUint8Array !== false))
          return 64;
      },
      encode(n, t, e) {
        zr(n, e);
      }
    },
    qt(68, 1),
    qt(69, 2),
    qt(70, 4),
    qt(71, 8),
    qt(72, 1),
    qt(77, 2),
    qt(78, 4),
    qt(79, 8),
    qt(85, 4),
    qt(86, 8),
    {
      encode(n, t) {
        let e = n.packedValues || [], r = n.structures || [];
        if (e.values.length > 0) {
          x[p++] = 216, x[p++] = 51, Yt(4);
          let s = e.values;
          t(s), Yt(0), Yt(0), packedObjectMap = Object.create(sharedPackedObjectMap || null);
          for (let o = 0, i = s.length; o < i; o++)
            packedObjectMap[s[o]] = o;
        }
        if (r) {
          dt.setUint32(p, 3655335424), p += 3;
          let s = r.slice(0);
          s.unshift(57344), s.push(new Re(n.version, 1399353956)), t(s);
        } else
          t(new Re(n.version, 1399353956));
      }
    }
  ];
  function qt(n, t) {
    return !$h && t > 1 && (n -= 4), {
      tag: n,
      encode: function(r, s) {
        let o = r.byteLength, i = r.byteOffset || 0, a = r.buffer || r;
        s(In ? ir.from(a, i, o) : new Uint8Array(a, i, o));
      }
    };
  }
  function zr(n, t) {
    let e = n.byteLength;
    e < 24 ? x[p++] = 64 + e : e < 256 ? (x[p++] = 88, x[p++] = e) : e < 65536 ? (x[p++] = 89, x[p++] = e >> 8, x[p++] = e & 255) : (x[p++] = 90, dt.setUint32(p, e), p += 4), p + e >= x.length && t(p + e), x.set(n.buffer ? n : new Uint8Array(n), p), p += e;
  }
  function Uh(n, t) {
    let e, r = t.length * 2, s = n.length - r;
    t.sort((o, i) => o.offset > i.offset ? 1 : -1);
    for (let o = 0; o < t.length; o++) {
      let i = t[o];
      i.id = o;
      for (let a of i.references)
        n[a++] = o >> 8, n[a] = o & 255;
    }
    for (; e = t.pop(); ) {
      let o = e.offset;
      n.copyWithin(o + r, o, s), r -= 2;
      let i = o + r;
      n[i++] = 216, n[i++] = 28, s = o;
    }
    return n;
  }
  function Ao(n, t) {
    dt.setUint32(wt.position + n, p - wt.position - n + 1);
    let e = wt;
    wt = null, t(e[0]), t(e[1]);
  }
  let Ns = new Xc({
    useRecords: false
  });
  Ns.encode;
  Ns.encodeAsIterable;
  Ns.encodeAsAsyncIterable;
  const Eo = 512, Bh = 1024, br = 2048;
  Ph = function(n) {
    return new Xc({
      tagUint8Array: false,
      useRecords: false
    }).encode(n);
  };
  vg = function(n) {
    return qc(n);
  };
  const Fh = (n, t) => n.length === t.length && n.every((e, r) => e === t[r]), Ws = (n, t) => Fh(n, t), Lh = async (n, t) => {
    let e;
    const r = new Promise((s, o) => {
      e = setTimeout(() => o(new Vh(`withTimeout: timed out after ${t}ms`)), t);
    });
    try {
      return await Promise.race([
        n,
        r
      ]);
    } finally {
      clearTimeout(e);
    }
  };
  class Vh extends Error {
    constructor(t) {
      super(t), this.name = "TimeoutError";
    }
  }
  zh = (_a3 = class extends me {
    constructor(t, e = {}) {
      super();
      __privateAdd(this, _o2);
      __privateAdd(this, _a2);
      __privateAdd(this, _i2);
      __privateAdd(this, _c2);
      __publicField(this, "documentId");
      __privateAdd(this, _e2, void 0);
      __privateAdd(this, _t2, void 0);
      __privateAdd(this, _r2, void 0);
      __privateAdd(this, _n2, 6e4);
      __privateAdd(this, _s2, {});
      __publicField(this, "isReady", () => this.inState([
        "ready"
      ]));
      __publicField(this, "isDeleted", () => this.inState([
        "deleted"
      ]));
      __publicField(this, "isUnavailable", () => this.inState([
        "unavailable"
      ]));
      __publicField(this, "inState", (t) => t.some((e) => __privateGet(this, _t2).getSnapshot().matches(e)));
      this.documentId = t, "timeoutDelay" in e && e.timeoutDelay && __privateSet(this, _n2, e.timeoutDelay);
      let r;
      const s = "isNew" in e && e.isNew;
      s ? (r = za(e.initialValue), r = us(r)) : r = yn(), __privateSet(this, _e2, ye(`automerge-repo:dochandle:${this.documentId.slice(0, 5)}`));
      const o = __privateGet(this, _n2), i = Zl({
        types: {
          context: {},
          events: {}
        },
        actions: {
          onUpdate: ln(({ context: a, event: c }) => {
            const f = a.doc;
            Yl(c, Rn);
            const { callback: u } = c.payload;
            return {
              doc: u(f)
            };
          }),
          onDelete: ln(() => (this.emit("delete", {
            handle: this
          }), {
            doc: void 0
          })),
          onUnavailable: () => {
            this.emit("unavailable", {
              handle: this
            });
          }
        }
      }).createMachine({
        initial: "idle",
        context: {
          documentId: t,
          doc: r
        },
        on: {
          UPDATE: {
            actions: "onUpdate"
          },
          DELETE: ".deleted"
        },
        states: {
          idle: {
            on: {
              CREATE: "ready",
              FIND: "loading"
            }
          },
          loading: {
            on: {
              REQUEST: "requesting",
              DOC_READY: "ready",
              AWAIT_NETWORK: "awaitingNetwork"
            },
            after: {
              [o]: "unavailable"
            }
          },
          awaitingNetwork: {
            on: {
              NETWORK_READY: "requesting"
            }
          },
          requesting: {
            on: {
              DOC_UNAVAILABLE: "unavailable",
              DOC_READY: "ready"
            },
            after: {
              [o]: "unavailable"
            }
          },
          unavailable: {
            entry: "onUnavailable",
            on: {
              DOC_READY: "ready"
            }
          },
          ready: {},
          deleted: {
            entry: "onDelete",
            type: "final"
          }
        }
      });
      __privateSet(this, _t2, dn(i)), __privateGet(this, _t2).subscribe((a) => {
        const c = __privateGet(this, _r2), f = a.context.doc;
        __privateGet(this, _e2).call(this, `\u2192 ${a.value} %o`, f), __privateMethod(this, _c2, c_fn).call(this, c, f);
      }), __privateGet(this, _t2).start(), __privateGet(this, _t2).send(s ? {
        type: Wh
      } : {
        type: Kh
      });
    }
    get url() {
      return Fs({
        documentId: this.documentId
      });
    }
    get state() {
      return __privateGet(this, _t2).getSnapshot().value;
    }
    async whenReady(t = [
      "ready"
    ]) {
      await Lh(__privateMethod(this, _i2, i_fn).call(this, t), __privateGet(this, _n2));
    }
    async doc(t = [
      "ready",
      "unavailable"
    ]) {
      try {
        await __privateMethod(this, _i2, i_fn).call(this, t);
      } catch {
        return;
      }
      return this.isUnavailable() ? void 0 : __privateGet(this, _o2, o_get);
    }
    docSync() {
      if (this.isReady())
        return __privateGet(this, _o2, o_get);
    }
    heads() {
      if (this.isReady())
        return Tt(__privateGet(this, _o2, o_get));
    }
    update(t) {
      __privateGet(this, _t2).send({
        type: Rn,
        payload: {
          callback: t
        }
      });
    }
    setRemoteHeads(t, e) {
      __privateGet(this, _s2)[t] = e, this.emit("remote-heads", {
        storageId: t,
        heads: e
      });
    }
    getRemoteHeads(t) {
      return __privateGet(this, _s2)[t];
    }
    change(t, e = {}) {
      if (!this.isReady())
        throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before accessing the document.`);
      __privateGet(this, _t2).send({
        type: Rn,
        payload: {
          callback: (r) => cs(r, e, t)
        }
      });
    }
    changeAt(t, e, r = {}) {
      if (!this.isReady())
        throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before accessing the document.`);
      let s;
      return __privateGet(this, _t2).send({
        type: Rn,
        payload: {
          callback: (o) => {
            const i = _s(o, t, r, e);
            return s = i.newHeads || void 0, i.newDoc;
          }
        }
      }), s;
    }
    merge(t) {
      if (!this.isReady() || !t.isReady())
        throw new Error("Both handles must be ready to merge");
      const e = t.docSync();
      if (!e)
        throw new Error("The document to be merged in is falsy, aborting.");
      this.update((r) => fs(r, e));
    }
    unavailable() {
      __privateGet(this, _t2).send({
        type: Zh
      });
    }
    request() {
      __privateGet(this, _a2, a_get) === "loading" && __privateGet(this, _t2).send({
        type: Jh
      });
    }
    awaitNetwork() {
      __privateGet(this, _a2, a_get) === "loading" && __privateGet(this, _t2).send({
        type: qh
      });
    }
    networkReady() {
      __privateGet(this, _a2, a_get) === "awaitingNetwork" && __privateGet(this, _t2).send({
        type: Yh
      });
    }
    delete() {
      __privateGet(this, _t2).send({
        type: Xh
      });
    }
    broadcast(t) {
      this.emit("ephemeral-message-outbound", {
        handle: this,
        data: Ph(t)
      });
    }
  }, _e2 = new WeakMap(), _t2 = new WeakMap(), _r2 = new WeakMap(), _n2 = new WeakMap(), _s2 = new WeakMap(), _o2 = new WeakSet(), o_get = function() {
    var _a9;
    return (_a9 = __privateGet(this, _t2)) == null ? void 0 : _a9.getSnapshot().context.doc;
  }, _a2 = new WeakSet(), a_get = function() {
    var _a9;
    return (_a9 = __privateGet(this, _t2)) == null ? void 0 : _a9.getSnapshot().value;
  }, _i2 = new WeakSet(), i_fn = function(t) {
    const e = Array.isArray(t) ? t : [
      t
    ];
    return th(__privateGet(this, _t2), (r) => e.some((s) => r.matches(s)), {
      timeout: __privateGet(this, _n2) * 2
    });
  }, _c2 = new WeakSet(), c_fn = function(t, e) {
    if (e && t && !Ws(Tt(e), Tt(t))) {
      this.emit("heads-changed", {
        handle: this,
        doc: e
      });
      const s = gs(e, Tt(t), Tt(e));
      s.length > 0 && this.emit("change", {
        handle: this,
        doc: e,
        patches: s,
        patchInfo: {
          before: t,
          after: e,
          source: "change"
        }
      }), this.isReady() || __privateGet(this, _t2).send({
        type: Gh
      });
    }
    __privateSet(this, _r2, e);
  }, _a3);
  const Nh = {
    IDLE: "idle",
    LOADING: "loading",
    AWAITING_NETWORK: "awaitingNetwork",
    REQUESTING: "requesting",
    READY: "ready",
    DELETED: "deleted",
    UNAVAILABLE: "unavailable"
  }, { IDLE: Sg, LOADING: xg, AWAITING_NETWORK: Ig, REQUESTING: jn, READY: pr, DELETED: kg, UNAVAILABLE: Co } = Nh, Wh = "CREATE", Kh = "FIND", Jh = "REQUEST", Gh = "DOC_READY", qh = "AWAIT_NETWORK", Yh = "NETWORK_READY", Rn = "UPDATE", Xh = "DELETE", Zh = "DOC_UNAVAILABLE";
  class Qh extends me {
    constructor() {
      super(...arguments);
      __privateAdd(this, _a4);
      __privateAdd(this, _i3);
      __privateAdd(this, _e3, /* @__PURE__ */ new Map());
      __privateAdd(this, _t3, /* @__PURE__ */ new Set());
      __privateAdd(this, _r3, /* @__PURE__ */ new Map());
      __privateAdd(this, _n3, /* @__PURE__ */ new Set());
      __privateAdd(this, _s3, /* @__PURE__ */ new Map());
      __privateAdd(this, _o3, ye("automerge-repo:remote-heads-subscriptions"));
    }
    subscribeToRemotes(t) {
      __privateGet(this, _o3).call(this, "subscribeToRemotes", t);
      const e = [];
      for (const r of t)
        __privateGet(this, _t3).has(r) || (__privateGet(this, _t3).add(r), e.push(r));
      e.length > 0 && this.emit("change-remote-subs", {
        add: e,
        peers: Array.from(__privateGet(this, _n3))
      });
    }
    unsubscribeFromRemotes(t) {
      __privateGet(this, _o3).call(this, "subscribeToRemotes", t);
      const e = [];
      for (const r of t)
        __privateGet(this, _t3).has(r) && (__privateGet(this, _t3).delete(r), __privateGet(this, _r3).has(r) || e.push(r));
      e.length > 0 && this.emit("change-remote-subs", {
        remove: e,
        peers: Array.from(__privateGet(this, _n3))
      });
    }
    handleControlMessage(t) {
      const e = [], r = [], s = [];
      if (__privateGet(this, _o3).call(this, "handleControlMessage", t), t.add)
        for (const o of t.add) {
          let i = __privateGet(this, _r3).get(o);
          (__privateGet(this, _t3).has(o) || i) && s.push(o), i || (i = /* @__PURE__ */ new Set(), __privateGet(this, _r3).set(o, i), __privateGet(this, _t3).has(o) || e.push(o)), i.add(t.senderId);
        }
      if (t.remove)
        for (const o of t.remove) {
          const i = __privateGet(this, _r3).get(o);
          i && (i.delete(t.senderId), i.size == 0 && !__privateGet(this, _t3).has(o) && r.push(o));
        }
      (e.length > 0 || r.length > 0) && this.emit("change-remote-subs", {
        peers: Array.from(__privateGet(this, _n3)),
        add: e,
        remove: r
      });
      for (const o of s) {
        const i = __privateGet(this, _s3).get(t.senderId);
        if (i)
          for (const a of i) {
            const c = __privateGet(this, _e3).get(a);
            if (!c)
              continue;
            const f = c.get(o);
            f && this.emit("notify-remote-heads", {
              targetId: t.senderId,
              documentId: a,
              heads: f.heads,
              timestamp: f.timestamp,
              storageId: o
            });
          }
      }
    }
    handleRemoteHeads(t) {
      __privateGet(this, _o3).call(this, "handleRemoteHeads", t);
      const e = __privateMethod(this, _i3, i_fn2).call(this, t);
      for (const r of e)
        __privateGet(this, _t3).has(r.storageId) && this.emit("remote-heads-changed", r);
      for (const r of e)
        for (const s of __privateGet(this, _n3))
          s !== t.senderId && this.emit("notify-remote-heads", {
            targetId: s,
            documentId: r.documentId,
            heads: r.remoteHeads,
            timestamp: r.timestamp,
            storageId: r.storageId
          });
      for (const r of e) {
        const s = __privateGet(this, _r3).get(r.storageId);
        if (s)
          for (const o of s)
            __privateMethod(this, _a4, a_fn).call(this, o, r.documentId) && this.emit("notify-remote-heads", {
              targetId: o,
              documentId: r.documentId,
              heads: r.remoteHeads,
              timestamp: r.timestamp,
              storageId: r.storageId
            });
      }
    }
    handleImmediateRemoteHeadsChanged(t, e, r) {
      __privateGet(this, _o3).call(this, "handleLocalHeadsChanged", t, e, r);
      const s = __privateGet(this, _e3).get(t), o = Date.now();
      if (!s)
        __privateGet(this, _e3).set(t, /* @__PURE__ */ new Map([
          [
            e,
            {
              heads: r,
              timestamp: o
            }
          ]
        ]));
      else {
        const a = s.get(e);
        (!a || a.timestamp < Date.now()) && s.set(e, {
          heads: r,
          timestamp: Date.now()
        });
      }
      const i = __privateGet(this, _r3).get(e);
      if (i)
        for (const a of i)
          __privateMethod(this, _a4, a_fn).call(this, a, t) && this.emit("notify-remote-heads", {
            targetId: a,
            documentId: t,
            heads: r,
            timestamp: o,
            storageId: e
          });
    }
    addGenerousPeer(t) {
      __privateGet(this, _o3).call(this, "addGenerousPeer", t), __privateGet(this, _n3).add(t), __privateGet(this, _t3).size > 0 && this.emit("change-remote-subs", {
        add: Array.from(__privateGet(this, _t3)),
        peers: [
          t
        ]
      });
      for (const [e, r] of __privateGet(this, _e3))
        for (const [s, { heads: o, timestamp: i }] of r)
          this.emit("notify-remote-heads", {
            targetId: t,
            documentId: e,
            heads: o,
            timestamp: i,
            storageId: s
          });
    }
    removePeer(t) {
      __privateGet(this, _o3).call(this, "removePeer", t);
      const e = [];
      __privateGet(this, _n3).delete(t), __privateGet(this, _s3).delete(t);
      for (const [r, s] of __privateGet(this, _r3))
        s.has(t) && (s.delete(t), s.size == 0 && (e.push(r), __privateGet(this, _r3).delete(r)));
      e.length > 0 && this.emit("change-remote-subs", {
        remove: e,
        peers: Array.from(__privateGet(this, _n3))
      });
    }
    subscribePeerToDoc(t, e) {
      let r = __privateGet(this, _s3).get(t);
      r || (r = /* @__PURE__ */ new Set(), __privateGet(this, _s3).set(t, r)), r.add(e);
      const s = __privateGet(this, _e3).get(e);
      if (s)
        for (const [o, i] of s) {
          const a = __privateGet(this, _r3).get(o);
          a && a.has(t) && this.emit("notify-remote-heads", {
            targetId: t,
            documentId: e,
            heads: i.heads,
            timestamp: i.timestamp,
            storageId: o
          });
        }
    }
  }
  _e3 = new WeakMap();
  _t3 = new WeakMap();
  _r3 = new WeakMap();
  _n3 = new WeakMap();
  _s3 = new WeakMap();
  _o3 = new WeakMap();
  _a4 = new WeakSet();
  a_fn = function(t, e) {
    const r = __privateGet(this, _s3).get(t);
    return r && r.has(e);
  };
  _i3 = new WeakSet();
  i_fn2 = function(t) {
    const e = [], { documentId: r, newHeads: s } = t;
    for (const [o, { heads: i, timestamp: a }] of Object.entries(s)) {
      if (!__privateGet(this, _t3).has(o) && !__privateGet(this, _r3).has(o))
        continue;
      let c = __privateGet(this, _e3).get(r);
      c || (c = /* @__PURE__ */ new Map(), __privateGet(this, _e3).set(r, c));
      const f = c.get(o);
      f && f.timestamp >= a || (c.set(o, {
        timestamp: a,
        heads: i
      }), e.push({
        documentId: r,
        storageId: o,
        remoteHeads: i,
        timestamp: a
      }));
    }
    return e;
  };
  const Nr = (n, t) => {
    let e = Date.now(), r, s;
    return function(...o) {
      r = e + t - Date.now(), clearTimeout(s), s = setTimeout(() => {
        n(...o), e = Date.now();
      }, r);
    };
  }, tg = (n) => ng(n) || t_(n) || Qc(n) || eg(n) || rg(n) || sg(n), eg = (n) => n.type === "doc-unavailable", Qc = (n) => n.type === "request", ng = (n) => n.type === "sync", t_ = (n) => n.type === "ephemeral", rg = (n) => n.type === "remote-subscription-change", sg = (n) => n.type === "remote-heads-changed", og = (n) => `${n.senderId}:${n.sessionId}`;
  class ig extends me {
    constructor(t, e = ag(), r) {
      super();
      __publicField(this, "peerId");
      __publicField(this, "peerMetadata");
      __privateAdd(this, _e4, void 0);
      __privateAdd(this, _t4, {});
      __privateAdd(this, _r4, 0);
      __privateAdd(this, _n4, Math.random().toString(36).slice(2));
      __privateAdd(this, _s4, {});
      __privateAdd(this, _o4, 0);
      __privateAdd(this, _a5, []);
      __publicField(this, "isReady", () => __privateGet(this, _o4) === __privateGet(this, _a5).length);
      __publicField(this, "whenReady", async () => {
        if (!this.isReady())
          return new Promise((t) => {
            this.once("ready", () => {
              t();
            });
          });
      });
      this.peerId = e, this.peerMetadata = r, __privateSet(this, _e4, ye(`automerge-repo:network:${this.peerId}`)), t.forEach((s) => this.addNetworkAdapter(s));
    }
    addNetworkAdapter(t) {
      __privateGet(this, _a5).push(t), t.once("ready", () => {
        __privateWrapper(this, _o4)._++, __privateGet(this, _e4).call(this, "Adapters ready: ", __privateGet(this, _o4), "/", __privateGet(this, _a5).length), __privateGet(this, _o4) === __privateGet(this, _a5).length && this.emit("ready");
      }), t.on("peer-candidate", ({ peerId: e, peerMetadata: r }) => {
        __privateGet(this, _e4).call(this, `peer candidate: ${e} `), __privateGet(this, _t4)[e] || (__privateGet(this, _t4)[e] = t), this.emit("peer", {
          peerId: e,
          peerMetadata: r
        });
      }), t.on("peer-disconnected", ({ peerId: e }) => {
        __privateGet(this, _e4).call(this, `peer disconnected: ${e} `), delete __privateGet(this, _t4)[e], this.emit("peer-disconnected", {
          peerId: e
        });
      }), t.on("message", (e) => {
        if (!tg(e)) {
          __privateGet(this, _e4).call(this, `invalid message: ${JSON.stringify(e)}`);
          return;
        }
        if (__privateGet(this, _e4).call(this, `message from ${e.senderId}`), t_(e)) {
          const r = og(e);
          (__privateGet(this, _s4)[r] === void 0 || e.count > __privateGet(this, _s4)[r]) && (__privateGet(this, _s4)[r] = e.count, this.emit("message", e));
          return;
        }
        this.emit("message", e);
      }), t.on("close", () => {
        __privateGet(this, _e4).call(this, "adapter closed"), Object.entries(__privateGet(this, _t4)).forEach(([e, r]) => {
          r === t && delete __privateGet(this, _t4)[e];
        });
      }), this.peerMetadata.then((e) => {
        t.connect(this.peerId, e);
      }).catch((e) => {
        __privateGet(this, _e4).call(this, "error connecting to network", e);
      });
    }
    send(t) {
      const e = __privateGet(this, _t4)[t.targetId];
      if (!e) {
        __privateGet(this, _e4).call(this, `Tried to send message but peer not found: ${t.targetId}`);
        return;
      }
      const s = ((o) => o.type === "ephemeral" ? "count" in o ? o : {
        ...o,
        count: ++__privateWrapper(this, _r4)._,
        sessionId: __privateGet(this, _n4),
        senderId: this.peerId
      } : {
        ...o,
        senderId: this.peerId
      })(t);
      __privateGet(this, _e4).call(this, "sending message %o", s), e.send(s);
    }
  }
  _e4 = new WeakMap();
  _t4 = new WeakMap();
  _r4 = new WeakMap();
  _n4 = new WeakMap();
  _s4 = new WeakMap();
  _o4 = new WeakMap();
  _a5 = new WeakMap();
  function ag() {
    return `user-${Math.round(Math.random() * 1e5)}`;
  }
  function e_(n) {
    let t = 0;
    n.forEach((s) => {
      t += s.length;
    });
    const e = new Uint8Array(t);
    let r = 0;
    return n.forEach((s) => {
      e.set(s, r), r += s.length;
    }), e;
  }
  var n_ = {
    exports: {}
  };
  (function(n) {
    (function(t, e) {
      var r = {};
      e(r);
      var s = r.default;
      for (var o in r)
        s[o] = r[o];
      n.exports = s;
    })(Rd, function(t) {
      t.__esModule = true, t.digestLength = 32, t.blockSize = 64;
      var e = new Uint32Array([
        1116352408,
        1899447441,
        3049323471,
        3921009573,
        961987163,
        1508970993,
        2453635748,
        2870763221,
        3624381080,
        310598401,
        607225278,
        1426881987,
        1925078388,
        2162078206,
        2614888103,
        3248222580,
        3835390401,
        4022224774,
        264347078,
        604807628,
        770255983,
        1249150122,
        1555081692,
        1996064986,
        2554220882,
        2821834349,
        2952996808,
        3210313671,
        3336571891,
        3584528711,
        113926993,
        338241895,
        666307205,
        773529912,
        1294757372,
        1396182291,
        1695183700,
        1986661051,
        2177026350,
        2456956037,
        2730485921,
        2820302411,
        3259730800,
        3345764771,
        3516065817,
        3600352804,
        4094571909,
        275423344,
        430227734,
        506948616,
        659060556,
        883997877,
        958139571,
        1322822218,
        1537002063,
        1747873779,
        1955562222,
        2024104815,
        2227730452,
        2361852424,
        2428436474,
        2756734187,
        3204031479,
        3329325298
      ]);
      function r(d, l, w, k, j) {
        for (var L, N, O, q, Z, Y, it, tt, st, ct, jt, At, S; j >= 64; ) {
          for (L = l[0], N = l[1], O = l[2], q = l[3], Z = l[4], Y = l[5], it = l[6], tt = l[7], ct = 0; ct < 16; ct++)
            jt = k + ct * 4, d[ct] = (w[jt] & 255) << 24 | (w[jt + 1] & 255) << 16 | (w[jt + 2] & 255) << 8 | w[jt + 3] & 255;
          for (ct = 16; ct < 64; ct++)
            st = d[ct - 2], At = (st >>> 17 | st << 32 - 17) ^ (st >>> 19 | st << 32 - 19) ^ st >>> 10, st = d[ct - 15], S = (st >>> 7 | st << 32 - 7) ^ (st >>> 18 | st << 32 - 18) ^ st >>> 3, d[ct] = (At + d[ct - 7] | 0) + (S + d[ct - 16] | 0);
          for (ct = 0; ct < 64; ct++)
            At = (((Z >>> 6 | Z << 32 - 6) ^ (Z >>> 11 | Z << 32 - 11) ^ (Z >>> 25 | Z << 32 - 25)) + (Z & Y ^ ~Z & it) | 0) + (tt + (e[ct] + d[ct] | 0) | 0) | 0, S = ((L >>> 2 | L << 32 - 2) ^ (L >>> 13 | L << 32 - 13) ^ (L >>> 22 | L << 32 - 22)) + (L & N ^ L & O ^ N & O) | 0, tt = it, it = Y, Y = Z, Z = q + At | 0, q = O, O = N, N = L, L = At + S | 0;
          l[0] += L, l[1] += N, l[2] += O, l[3] += q, l[4] += Z, l[5] += Y, l[6] += it, l[7] += tt, k += 64, j -= 64;
        }
        return k;
      }
      var s = function() {
        function d() {
          this.digestLength = t.digestLength, this.blockSize = t.blockSize, this.state = new Int32Array(8), this.temp = new Int32Array(64), this.buffer = new Uint8Array(128), this.bufferLength = 0, this.bytesHashed = 0, this.finished = false, this.reset();
        }
        return d.prototype.reset = function() {
          return this.state[0] = 1779033703, this.state[1] = 3144134277, this.state[2] = 1013904242, this.state[3] = 2773480762, this.state[4] = 1359893119, this.state[5] = 2600822924, this.state[6] = 528734635, this.state[7] = 1541459225, this.bufferLength = 0, this.bytesHashed = 0, this.finished = false, this;
        }, d.prototype.clean = function() {
          for (var l = 0; l < this.buffer.length; l++)
            this.buffer[l] = 0;
          for (var l = 0; l < this.temp.length; l++)
            this.temp[l] = 0;
          this.reset();
        }, d.prototype.update = function(l, w) {
          if (w === void 0 && (w = l.length), this.finished)
            throw new Error("SHA256: can't update because hash was finished.");
          var k = 0;
          if (this.bytesHashed += w, this.bufferLength > 0) {
            for (; this.bufferLength < 64 && w > 0; )
              this.buffer[this.bufferLength++] = l[k++], w--;
            this.bufferLength === 64 && (r(this.temp, this.state, this.buffer, 0, 64), this.bufferLength = 0);
          }
          for (w >= 64 && (k = r(this.temp, this.state, l, k, w), w %= 64); w > 0; )
            this.buffer[this.bufferLength++] = l[k++], w--;
          return this;
        }, d.prototype.finish = function(l) {
          if (!this.finished) {
            var w = this.bytesHashed, k = this.bufferLength, j = w / 536870912 | 0, L = w << 3, N = w % 64 < 56 ? 64 : 128;
            this.buffer[k] = 128;
            for (var O = k + 1; O < N - 8; O++)
              this.buffer[O] = 0;
            this.buffer[N - 8] = j >>> 24 & 255, this.buffer[N - 7] = j >>> 16 & 255, this.buffer[N - 6] = j >>> 8 & 255, this.buffer[N - 5] = j >>> 0 & 255, this.buffer[N - 4] = L >>> 24 & 255, this.buffer[N - 3] = L >>> 16 & 255, this.buffer[N - 2] = L >>> 8 & 255, this.buffer[N - 1] = L >>> 0 & 255, r(this.temp, this.state, this.buffer, 0, N), this.finished = true;
          }
          for (var O = 0; O < 8; O++)
            l[O * 4 + 0] = this.state[O] >>> 24 & 255, l[O * 4 + 1] = this.state[O] >>> 16 & 255, l[O * 4 + 2] = this.state[O] >>> 8 & 255, l[O * 4 + 3] = this.state[O] >>> 0 & 255;
          return this;
        }, d.prototype.digest = function() {
          var l = new Uint8Array(this.digestLength);
          return this.finish(l), l;
        }, d.prototype._saveState = function(l) {
          for (var w = 0; w < this.state.length; w++)
            l[w] = this.state[w];
        }, d.prototype._restoreState = function(l, w) {
          for (var k = 0; k < this.state.length; k++)
            this.state[k] = l[k];
          this.bytesHashed = w, this.finished = false, this.bufferLength = 0;
        }, d;
      }();
      t.Hash = s;
      var o = function() {
        function d(l) {
          this.inner = new s(), this.outer = new s(), this.blockSize = this.inner.blockSize, this.digestLength = this.inner.digestLength;
          var w = new Uint8Array(this.blockSize);
          if (l.length > this.blockSize)
            new s().update(l).finish(w).clean();
          else
            for (var k = 0; k < l.length; k++)
              w[k] = l[k];
          for (var k = 0; k < w.length; k++)
            w[k] ^= 54;
          this.inner.update(w);
          for (var k = 0; k < w.length; k++)
            w[k] ^= 106;
          this.outer.update(w), this.istate = new Uint32Array(8), this.ostate = new Uint32Array(8), this.inner._saveState(this.istate), this.outer._saveState(this.ostate);
          for (var k = 0; k < w.length; k++)
            w[k] = 0;
        }
        return d.prototype.reset = function() {
          return this.inner._restoreState(this.istate, this.inner.blockSize), this.outer._restoreState(this.ostate, this.outer.blockSize), this;
        }, d.prototype.clean = function() {
          for (var l = 0; l < this.istate.length; l++)
            this.ostate[l] = this.istate[l] = 0;
          this.inner.clean(), this.outer.clean();
        }, d.prototype.update = function(l) {
          return this.inner.update(l), this;
        }, d.prototype.finish = function(l) {
          return this.outer.finished ? this.outer.finish(l) : (this.inner.finish(l), this.outer.update(l, this.digestLength).finish(l)), this;
        }, d.prototype.digest = function() {
          var l = new Uint8Array(this.digestLength);
          return this.finish(l), l;
        }, d;
      }();
      t.HMAC = o;
      function i(d) {
        var l = new s().update(d), w = l.digest();
        return l.clean(), w;
      }
      t.hash = i, t.default = i;
      function a(d, l) {
        var w = new o(d).update(l), k = w.digest();
        return w.clean(), k;
      }
      t.hmac = a;
      function c(d, l, w, k) {
        var j = k[0];
        if (j === 0)
          throw new Error("hkdf: cannot expand more");
        l.reset(), j > 1 && l.update(d), w && l.update(w), l.update(k), l.finish(d), k[0]++;
      }
      var f = new Uint8Array(t.digestLength);
      function u(d, l, w, k) {
        l === void 0 && (l = f), k === void 0 && (k = 32);
        for (var j = new Uint8Array([
          1
        ]), L = a(l, d), N = new o(L), O = new Uint8Array(N.digestLength), q = O.length, Z = new Uint8Array(k), Y = 0; Y < k; Y++)
          q === O.length && (c(O, N, w, j), q = 0), Z[Y] = O[q++];
        return N.clean(), O.fill(0), j.fill(0), Z;
      }
      t.hkdf = u;
      function _(d, l, w, k) {
        for (var j = new o(d), L = j.digestLength, N = new Uint8Array(4), O = new Uint8Array(L), q = new Uint8Array(L), Z = new Uint8Array(k), Y = 0; Y * L < k; Y++) {
          var it = Y + 1;
          N[0] = it >>> 24 & 255, N[1] = it >>> 16 & 255, N[2] = it >>> 8 & 255, N[3] = it >>> 0 & 255, j.reset(), j.update(l), j.update(N), j.finish(q);
          for (var tt = 0; tt < L; tt++)
            O[tt] = q[tt];
          for (var tt = 2; tt <= w; tt++) {
            j.reset(), j.update(q).finish(q);
            for (var st = 0; st < L; st++)
              O[st] ^= q[st];
          }
          for (var tt = 0; tt < L && Y * L + tt < k; tt++)
            Z[Y * L + tt] = O[tt];
        }
        for (var Y = 0; Y < L; Y++)
          O[Y] = q[Y] = 0;
        for (var Y = 0; Y < 4; Y++)
          N[Y] = 0;
        return j.clean(), Z;
      }
      t.pbkdf2 = _;
    });
  })(n_);
  var cg = n_.exports;
  function r_(n) {
    const t = cg.hash(n);
    return ug(t);
  }
  function _g(n) {
    const t = new TextEncoder(), e = e_(n.map((r) => t.encode(r)));
    return r_(e);
  }
  function ug(n) {
    return Array.from(n, (t) => t.toString(16).padStart(2, "0")).join("");
  }
  function fg(n) {
    if (n.length < 2)
      return null;
    const t = n[n.length - 2];
    return t === "snapshot" || t === "incremental" ? t : null;
  }
  class dg {
    constructor(t) {
      __privateAdd(this, _o5);
      __privateAdd(this, _a6);
      __privateAdd(this, _i4);
      __privateAdd(this, _c3);
      __privateAdd(this, _e5, void 0);
      __privateAdd(this, _t5, /* @__PURE__ */ new Map());
      __privateAdd(this, _r5, /* @__PURE__ */ new Map());
      __privateAdd(this, _n5, false);
      __privateAdd(this, _s5, ye("automerge-repo:storage-subsystem"));
      __privateSet(this, _e5, t);
    }
    async id() {
      const t = await __privateGet(this, _e5).load([
        "storage-adapter-id"
      ]);
      let e;
      return t ? e = new TextDecoder().decode(t) : (e = Xr(), await __privateGet(this, _e5).save([
        "storage-adapter-id"
      ], new TextEncoder().encode(e))), e;
    }
    async load(t, e) {
      const r = [
        t,
        e
      ];
      return await __privateGet(this, _e5).load(r);
    }
    async save(t, e, r) {
      const s = [
        t,
        e
      ];
      await __privateGet(this, _e5).save(s, r);
    }
    async remove(t, e) {
      const r = [
        t,
        e
      ];
      await __privateGet(this, _e5).remove(r);
    }
    async loadDoc(t) {
      const e = await __privateGet(this, _e5).loadRange([
        t
      ]), r = [], s = [];
      for (const a of e) {
        if (a.data === void 0)
          continue;
        const c = fg(a.key);
        c != null && (s.push({
          key: a.key,
          type: c,
          size: a.data.length
        }), r.push(a.data));
      }
      __privateGet(this, _r5).set(t, s);
      const o = e_(r);
      if (o.length === 0)
        return null;
      const i = Xn(yn(), o);
      return __privateGet(this, _t5).set(t, Tt(i)), i;
    }
    async saveDoc(t, e) {
      if (!__privateMethod(this, _i4, i_fn3).call(this, t, e))
        return;
      const r = __privateGet(this, _r5).get(t) ?? [];
      __privateMethod(this, _c3, c_fn2).call(this, r) ? await __privateMethod(this, _a6, a_fn2).call(this, t, e, r) : await __privateMethod(this, _o5, o_fn).call(this, t, e), __privateGet(this, _t5).set(t, Tt(e));
    }
    async removeDoc(t) {
      await __privateGet(this, _e5).removeRange([
        t,
        "snapshot"
      ]), await __privateGet(this, _e5).removeRange([
        t,
        "incremental"
      ]), await __privateGet(this, _e5).removeRange([
        t,
        "sync-state"
      ]);
    }
    async loadSyncState(t, e) {
      const r = [
        t,
        "sync-state",
        e
      ], s = await __privateGet(this, _e5).load(r);
      return s ? tr(s) : void 0;
    }
    async saveSyncState(t, e, r) {
      const s = [
        t,
        "sync-state",
        e
      ];
      await __privateGet(this, _e5).save(s, Qn(r));
    }
  }
  _e5 = new WeakMap();
  _t5 = new WeakMap();
  _r5 = new WeakMap();
  _n5 = new WeakMap();
  _s5 = new WeakMap();
  _o5 = new WeakSet();
  o_fn = async function(t, e) {
    const r = vs(e, __privateGet(this, _t5).get(t) ?? []);
    if (r && r.length > 0) {
      const s = [
        t,
        "incremental",
        r_(r)
      ];
      __privateGet(this, _s5).call(this, `Saving incremental ${s} for document ${t}`), await __privateGet(this, _e5).save(s, r), __privateGet(this, _r5).has(t) || __privateGet(this, _r5).set(t, []), __privateGet(this, _r5).get(t).push({
        key: s,
        type: "incremental",
        size: r.length
      }), __privateGet(this, _t5).set(t, Tt(e));
    } else
      return Promise.resolve();
  };
  _a6 = new WeakSet();
  a_fn2 = async function(t, e, r) {
    var _a9;
    __privateSet(this, _n5, true);
    const s = Zn(e), o = _g(Tt(e)), i = [
      t,
      "snapshot",
      o
    ], a = new Set(r.map((f) => f.key).filter((f) => f[2] !== o));
    __privateGet(this, _s5).call(this, `Saving snapshot ${i} for document ${t}`), __privateGet(this, _s5).call(this, `deleting old chunks ${Array.from(a)}`), await __privateGet(this, _e5).save(i, s);
    for (const f of a)
      await __privateGet(this, _e5).remove(f);
    const c = ((_a9 = __privateGet(this, _r5).get(t)) == null ? void 0 : _a9.filter((f) => !a.has(f.key))) ?? [];
    c.push({
      key: i,
      type: "snapshot",
      size: s.length
    }), __privateGet(this, _r5).set(t, c), __privateSet(this, _n5, false);
  };
  _i4 = new WeakSet();
  i_fn3 = function(t, e) {
    const r = __privateGet(this, _t5).get(t);
    if (!r)
      return true;
    const s = Tt(e);
    return !Ws(s, r);
  };
  _c3 = new WeakSet();
  c_fn2 = function(t) {
    if (__privateGet(this, _n5))
      return false;
    let e = 0, r = 0;
    for (const s of t)
      s.type === "snapshot" ? e += s.size : r += s.size;
    return e < 1024 || r >= e;
  };
  class s_ extends me {
  }
  class lg extends s_ {
    constructor({ handle: t, onLoadSyncState: e }) {
      super();
      __privateAdd(this, _g2);
      __privateAdd(this, _b);
      __privateAdd(this, _p);
      __privateAdd(this, _u2);
      __privateAdd(this, _w);
      __privateAdd(this, _y);
      __privateAdd(this, _f2);
      __privateAdd(this, _d2);
      __privateAdd(this, _l2);
      __privateAdd(this, __2);
      __privateAdd(this, _h2);
      __privateAdd(this, _e6, void 0);
      __publicField(this, "syncDebounceRate", 100);
      __privateAdd(this, _t6, []);
      __privateAdd(this, _r6, {});
      __privateAdd(this, _n6, {});
      __privateAdd(this, _s6, {});
      __privateAdd(this, _o6, []);
      __privateAdd(this, _a7, false);
      __privateAdd(this, _i5, void 0);
      __privateAdd(this, _c4, void 0);
      __privateSet(this, _i5, t), __privateSet(this, _c4, e ?? (() => Promise.resolve(void 0)));
      const r = t.documentId.slice(0, 5);
      __privateSet(this, _e6, ye(`automerge-repo:docsync:${r}`)), t.on("change", Nr(() => __privateMethod(this, _g2, g_fn).call(this), this.syncDebounceRate)), t.on("ephemeral-message-outbound", (s) => __privateMethod(this, _b, b_fn).call(this, s)), (async () => (await t.doc([
        pr,
        jn
      ]), __privateMethod(this, _h2, h_fn).call(this)))();
    }
    get peerStates() {
      return __privateGet(this, _n6);
    }
    get documentId() {
      return __privateGet(this, _i5).documentId;
    }
    hasPeer(t) {
      return __privateGet(this, _t6).includes(t);
    }
    beginSync(t) {
      const e = t.every((s) => __privateGet(this, _n6)[s] in [
        "unavailable",
        "wants"
      ]), r = __privateGet(this, _i5).doc([
        pr,
        jn,
        Co
      ]).then((s) => {
        if (__privateSet(this, _a7, true), __privateMethod(this, __2, __fn).call(this), !(s === void 0 && e))
          return s ?? yn();
      });
      __privateGet(this, _e6).call(this, `beginSync: ${t.join(", ")}`), t.forEach((s) => {
        __privateMethod(this, _u2, u_fn).call(this, s, (o) => {
          const i = tr(Qn(o));
          __privateMethod(this, _f2, f_fn).call(this, s, i), r.then((a) => {
            a && __privateMethod(this, _d2, d_fn).call(this, s, a);
          }).catch((a) => {
            __privateGet(this, _e6).call(this, `Error loading doc for ${s}: ${a}`);
          });
        });
      });
    }
    endSync(t) {
      __privateGet(this, _e6).call(this, `removing peer ${t}`), __privateSet(this, _t6, __privateGet(this, _t6).filter((e) => e !== t));
    }
    receiveMessage(t) {
      switch (t.type) {
        case "sync":
        case "request":
          this.receiveSyncMessage(t);
          break;
        case "ephemeral":
          this.receiveEphemeralMessage(t);
          break;
        case "doc-unavailable":
          __privateGet(this, _n6)[t.senderId] = "unavailable", __privateMethod(this, __2, __fn).call(this);
          break;
        default:
          throw new Error(`unknown message type: ${t}`);
      }
    }
    receiveEphemeralMessage(t) {
      if (t.documentId !== __privateGet(this, _i5).documentId)
        throw new Error("channelId doesn't match documentId");
      const { senderId: e, data: r } = t, s = qc(new Uint8Array(r));
      __privateGet(this, _i5).emit("ephemeral-message", {
        handle: __privateGet(this, _i5),
        senderId: e,
        message: s
      }), __privateGet(this, _t6).forEach((o) => {
        o !== e && this.emit("message", {
          ...t,
          targetId: o
        });
      });
    }
    receiveSyncMessage(t) {
      if (t.documentId !== __privateGet(this, _i5).documentId)
        throw new Error("channelId doesn't match documentId");
      if (!__privateGet(this, _i5).inState([
        pr,
        jn,
        Co
      ])) {
        __privateGet(this, _o6).push({
          message: t,
          received: /* @__PURE__ */ new Date()
        });
        return;
      }
      __privateMethod(this, _h2, h_fn).call(this), __privateMethod(this, _l2, l_fn).call(this, t);
    }
  }
  _e6 = new WeakMap();
  _t6 = new WeakMap();
  _r6 = new WeakMap();
  _n6 = new WeakMap();
  _s6 = new WeakMap();
  _o6 = new WeakMap();
  _a7 = new WeakMap();
  _i5 = new WeakMap();
  _c4 = new WeakMap();
  _g2 = new WeakSet();
  g_fn = async function() {
    __privateGet(this, _e6).call(this, "syncWithPeers");
    const t = await __privateGet(this, _i5).doc();
    t !== void 0 && __privateGet(this, _t6).forEach((e) => __privateMethod(this, _d2, d_fn).call(this, e, t));
  };
  _b = new WeakSet();
  b_fn = async function({ data: t }) {
    __privateGet(this, _e6).call(this, "broadcastToPeers", __privateGet(this, _t6)), __privateGet(this, _t6).forEach((e) => __privateMethod(this, _p, p_fn).call(this, e, t));
  };
  _p = new WeakSet();
  p_fn = function(t, e) {
    __privateGet(this, _e6).call(this, `sendEphemeralMessage ->${t}`);
    const r = {
      type: "ephemeral",
      targetId: t,
      documentId: __privateGet(this, _i5).documentId,
      data: e
    };
    this.emit("message", r);
  };
  _u2 = new WeakSet();
  u_fn = function(t, e) {
    __privateMethod(this, _w, w_fn).call(this, t), t in __privateGet(this, _n6) || (__privateGet(this, _n6)[t] = "unknown");
    const r = __privateGet(this, _s6)[t];
    if (r) {
      e(r);
      return;
    }
    let s = __privateGet(this, _r6)[t];
    s || (__privateGet(this, _c4).call(this, t).then((o) => {
      __privateMethod(this, _y, y_fn).call(this, t, o ?? ws());
    }).catch((o) => {
      __privateGet(this, _e6).call(this, `Error loading sync state for ${t}: ${o}`);
    }), s = __privateGet(this, _r6)[t] = []), s.push(e);
  };
  _w = new WeakSet();
  w_fn = function(t) {
    __privateGet(this, _t6).includes(t) || (__privateGet(this, _t6).push(t), this.emit("open-doc", {
      documentId: this.documentId,
      peerId: t
    }));
  };
  _y = new WeakSet();
  y_fn = function(t, e) {
    const r = __privateGet(this, _r6)[t];
    if (r)
      for (const s of r)
        s(e);
    delete __privateGet(this, _r6)[t], __privateGet(this, _s6)[t] = e;
  };
  _f2 = new WeakSet();
  f_fn = function(t, e) {
    __privateGet(this, _s6)[t] = e, this.emit("sync-state", {
      peerId: t,
      syncState: e,
      documentId: __privateGet(this, _i5).documentId
    });
  };
  _d2 = new WeakSet();
  d_fn = function(t, e) {
    __privateGet(this, _e6).call(this, `sendSyncMessage ->${t}`), __privateMethod(this, _u2, u_fn).call(this, t, (r) => {
      const [s, o] = bs(e, r);
      if (o) {
        __privateMethod(this, _f2, f_fn).call(this, t, s);
        const i = Tt(e).length === 0;
        !__privateGet(this, _i5).isReady() && i && s.sharedHeads.length === 0 && !Object.values(__privateGet(this, _n6)).includes("has") && __privateGet(this, _n6)[t] === "unknown" ? this.emit("message", {
          type: "request",
          targetId: t,
          documentId: __privateGet(this, _i5).documentId,
          data: o
        }) : this.emit("message", {
          type: "sync",
          targetId: t,
          data: o,
          documentId: __privateGet(this, _i5).documentId
        }), i || (__privateGet(this, _n6)[t] = "has");
      }
    });
  };
  _l2 = new WeakSet();
  l_fn = function(t) {
    Qc(t) && (__privateGet(this, _n6)[t.senderId] = "wants"), __privateMethod(this, __2, __fn).call(this), ms(t.data).heads.length > 0 && (__privateGet(this, _n6)[t.senderId] = "has"), __privateMethod(this, _u2, u_fn).call(this, t.senderId, (e) => {
      __privateGet(this, _i5).update((r) => {
        const [s, o] = ps(r, e, t.data);
        return __privateMethod(this, _f2, f_fn).call(this, t.senderId, o), __privateMethod(this, _d2, d_fn).call(this, t.senderId, r), s;
      }), __privateMethod(this, __2, __fn).call(this);
    });
  };
  __2 = new WeakSet();
  __fn = function() {
    __privateGet(this, _a7) && __privateGet(this, _i5).inState([
      jn
    ]) && __privateGet(this, _t6).every((t) => __privateGet(this, _n6)[t] === "unavailable" || __privateGet(this, _n6)[t] === "wants") && (__privateGet(this, _t6).filter((t) => __privateGet(this, _n6)[t] === "wants").forEach((t) => {
      const e = {
        type: "doc-unavailable",
        documentId: __privateGet(this, _i5).documentId,
        targetId: t
      };
      this.emit("message", e);
    }), __privateGet(this, _i5).unavailable());
  };
  _h2 = new WeakSet();
  h_fn = function() {
    for (const t of __privateGet(this, _o6))
      __privateMethod(this, _l2, l_fn).call(this, t.message);
    __privateSet(this, _o6, []);
  };
  const wr = ye("automerge-repo:collectionsync");
  class hg extends s_ {
    constructor(t) {
      super();
      __privateAdd(this, _n7);
      __privateAdd(this, _s7);
      __privateAdd(this, _o7);
      __publicField(this, "repo");
      __privateAdd(this, _e7, /* @__PURE__ */ new Set());
      __privateAdd(this, _t7, {});
      __privateAdd(this, _r7, {});
      this.repo = t;
    }
    async receiveMessage(t) {
      wr(`onSyncMessage: ${t.senderId}, ${t.documentId}, ${"data" in t ? t.data.byteLength + "bytes" : ""}`);
      const e = t.documentId;
      if (!e)
        throw new Error("received a message with an invalid documentId");
      __privateGet(this, _r7)[e] = true;
      const r = __privateMethod(this, _n7, n_fn).call(this, e);
      r.receiveMessage(t);
      const s = await __privateMethod(this, _o7, o_fn2).call(this, e);
      r.beginSync(s.filter((o) => !r.hasPeer(o)));
    }
    addDocument(t) {
      if (__privateGet(this, _r7)[t])
        return;
      const e = __privateMethod(this, _n7, n_fn).call(this, t);
      __privateMethod(this, _o7, o_fn2).call(this, t).then((r) => {
        e.beginSync(r);
      });
    }
    removeDocument(t) {
      throw new Error("not implemented");
    }
    addPeer(t) {
      if (wr(`adding ${t} & synchronizing with them`), !__privateGet(this, _e7).has(t)) {
        __privateGet(this, _e7).add(t);
        for (const e of Object.values(__privateGet(this, _t7))) {
          const { documentId: r } = e;
          this.repo.sharePolicy(t, r).then((s) => {
            s && e.beginSync([
              t
            ]);
          });
        }
      }
    }
    removePeer(t) {
      wr(`removing peer ${t}`), __privateGet(this, _e7).delete(t);
      for (const e of Object.values(__privateGet(this, _t7)))
        e.endSync(t);
    }
    get peers() {
      return Array.from(__privateGet(this, _e7));
    }
  }
  _e7 = new WeakMap();
  _t7 = new WeakMap();
  _r7 = new WeakMap();
  _n7 = new WeakSet();
  n_fn = function(t) {
    if (!__privateGet(this, _t7)[t]) {
      const e = this.repo.find(Fs({
        documentId: t
      }));
      __privateGet(this, _t7)[t] = __privateMethod(this, _s7, s_fn).call(this, e);
    }
    return __privateGet(this, _t7)[t];
  };
  _s7 = new WeakSet();
  s_fn = function(t) {
    const e = new lg({
      handle: t,
      onLoadSyncState: async (r) => {
        if (!this.repo.storageSubsystem)
          return;
        const { storageId: s, isEphemeral: o } = this.repo.peerMetadataByPeerId[r] || {};
        if (!(!s || o))
          return this.repo.storageSubsystem.loadSyncState(t.documentId, s);
      }
    });
    return e.on("message", (r) => this.emit("message", r)), e.on("open-doc", (r) => this.emit("open-doc", r)), e.on("sync-state", (r) => this.emit("sync-state", r)), e;
  };
  _o7 = new WeakSet();
  o_fn2 = async function(t) {
    const e = Array.from(__privateGet(this, _e7)), r = [];
    for (const s of e)
      await this.repo.sharePolicy(s, t) && r.push(s);
    return r;
  };
  Ag = (_b2 = class extends me {
    constructor({ storage: t, network: e = [], peerId: r, sharePolicy: s, isEphemeral: o = t === void 0, enableRemoteHeadsGossiping: i = false } = {}) {
      super();
      __privateAdd(this, _o8);
      __privateAdd(this, _i6);
      __privateAdd(this, _c5);
      __privateAdd(this, _e8, void 0);
      __publicField(this, "networkSubsystem");
      __publicField(this, "storageSubsystem");
      __publicField(this, "saveDebounceRate", 100);
      __privateAdd(this, _t8, {});
      __privateAdd(this, _r8, void 0);
      __publicField(this, "sharePolicy", async () => true);
      __publicField(this, "peerMetadataByPeerId", {});
      __privateAdd(this, _n8, new Qh());
      __privateAdd(this, _s8, false);
      __privateAdd(this, _a8, {});
      __publicField(this, "subscribeToRemotes", (t) => {
        __privateGet(this, _s8) ? (__privateGet(this, _e8).call(this, "subscribeToRemotes", {
          remotes: t
        }), __privateGet(this, _n8).subscribeToRemotes(t)) : __privateGet(this, _e8).call(this, "WARN: subscribeToRemotes called but remote heads gossiping is not enabled");
      });
      __publicField(this, "storageId", async () => {
        if (this.storageSubsystem)
          return this.storageSubsystem.id();
      });
      __privateSet(this, _s8, i), __privateSet(this, _e8, ye("automerge-repo:repo")), this.sharePolicy = s ?? this.sharePolicy, this.on("document", async ({ handle: u, isNew: _ }) => {
        if (a) {
          const d = ({ handle: l, doc: w }) => {
            a.saveDoc(l.documentId, w);
          };
          if (u.on("heads-changed", Nr(d, this.saveDebounceRate)), _)
            await a.saveDoc(u.documentId, u.docSync());
          else {
            const l = await a.loadDoc(u.documentId);
            l && u.update(() => l);
          }
        }
        u.on("unavailable", () => {
          __privateGet(this, _e8).call(this, "document unavailable", {
            documentId: u.documentId
          }), this.emit("unavailable-document", {
            documentId: u.documentId
          });
        }), this.networkSubsystem.isReady() ? u.request() : (u.awaitNetwork(), this.networkSubsystem.whenReady().then(() => {
          u.networkReady();
        }).catch((d) => {
          __privateGet(this, _e8).call(this, "error waiting for network", {
            err: d
          });
        })), __privateGet(this, _r8).addDocument(u.documentId);
      }), this.on("delete-document", ({ documentId: u }) => {
        a && a.removeDoc(u).catch((_) => {
          __privateGet(this, _e8).call(this, "error deleting document", {
            documentId: u,
            err: _
          });
        });
      }), __privateSet(this, _r8, new hg(this)), __privateGet(this, _r8).on("message", (u) => {
        __privateGet(this, _e8).call(this, `sending ${u.type} message to ${u.targetId}`), f.send(u);
      }), __privateGet(this, _s8) && __privateGet(this, _r8).on("open-doc", ({ peerId: u, documentId: _ }) => {
        __privateGet(this, _n8).subscribePeerToDoc(u, _);
      });
      const a = t ? new dg(t) : void 0;
      this.storageSubsystem = a;
      const c = (async () => ({
        storageId: await (a == null ? void 0 : a.id()),
        isEphemeral: o
      }))(), f = new ig(e, r, c);
      this.networkSubsystem = f, f.on("peer", async ({ peerId: u, peerMetadata: _ }) => {
        __privateGet(this, _e8).call(this, "peer connected", {
          peerId: u
        }), _ && (this.peerMetadataByPeerId[u] = {
          ..._
        }), this.sharePolicy(u).then((d) => {
          d && __privateGet(this, _s8) && __privateGet(this, _n8).addGenerousPeer(u);
        }).catch((d) => {
          console.log("error in share policy", {
            err: d
          });
        }), __privateGet(this, _r8).addPeer(u);
      }), f.on("peer-disconnected", ({ peerId: u }) => {
        __privateGet(this, _r8).removePeer(u), __privateGet(this, _n8).removePeer(u);
      }), f.on("message", async (u) => {
        __privateMethod(this, _o8, o_fn3).call(this, u);
      }), __privateGet(this, _r8).on("sync-state", (u) => {
        __privateMethod(this, _i6, i_fn4).call(this, u);
        const _ = __privateGet(this, _t8)[u.documentId], { storageId: d } = this.peerMetadataByPeerId[u.peerId] || {};
        if (!d)
          return;
        const l = _.getRemoteHeads(d);
        u.syncState.theirHeads && (!l || !Ws(l, u.syncState.theirHeads)) && u.syncState.theirHeads && (_.setRemoteHeads(d, u.syncState.theirHeads), d && __privateGet(this, _s8) && __privateGet(this, _n8).handleImmediateRemoteHeadsChanged(u.documentId, d, u.syncState.theirHeads));
      }), __privateGet(this, _s8) && (__privateGet(this, _n8).on("notify-remote-heads", (u) => {
        this.networkSubsystem.send({
          type: "remote-heads-changed",
          targetId: u.targetId,
          documentId: u.documentId,
          newHeads: {
            [u.storageId]: {
              heads: u.heads,
              timestamp: u.timestamp
            }
          }
        });
      }), __privateGet(this, _n8).on("change-remote-subs", (u) => {
        __privateGet(this, _e8).call(this, "change-remote-subs", u);
        for (const _ of u.peers)
          this.networkSubsystem.send({
            type: "remote-subscription-change",
            targetId: _,
            add: u.add,
            remove: u.remove
          });
      }), __privateGet(this, _n8).on("remote-heads-changed", (u) => {
        __privateGet(this, _t8)[u.documentId].setRemoteHeads(u.storageId, u.remoteHeads);
      }));
    }
    get handles() {
      return __privateGet(this, _t8);
    }
    get peers() {
      return __privateGet(this, _r8).peers;
    }
    getStorageIdOfPeer(t) {
      var _a9;
      return (_a9 = this.peerMetadataByPeerId[t]) == null ? void 0 : _a9.storageId;
    }
    create(t) {
      const { documentId: e } = Ps(yh()), r = __privateMethod(this, _c5, c_fn3).call(this, {
        documentId: e,
        isNew: true,
        initialValue: t
      });
      return this.emit("document", {
        handle: r,
        isNew: true
      }), r;
    }
    clone(t) {
      if (!t.isReady())
        throw new Error(`Cloned handle is not yet in ready state.
        (Try await handle.waitForReady() first.)`);
      const e = t.docSync();
      if (!e)
        throw new Error("Cloned handle doesn't have a document.");
      const r = this.create();
      return r.update(() => Ir(e)), r;
    }
    find(t) {
      const e = dr(t);
      if (__privateGet(this, _t8)[e])
        return __privateGet(this, _t8)[e].isUnavailable() && setTimeout(() => {
          __privateGet(this, _t8)[e].emit("unavailable", {
            handle: __privateGet(this, _t8)[e]
          });
        }), __privateGet(this, _t8)[e];
      const r = __privateMethod(this, _c5, c_fn3).call(this, {
        documentId: e,
        isNew: false
      });
      return this.emit("document", {
        handle: r,
        isNew: false
      }), r;
    }
    delete(t) {
      const e = dr(t);
      __privateMethod(this, _c5, c_fn3).call(this, {
        documentId: e,
        isNew: false
      }).delete(), delete __privateGet(this, _t8)[e], this.emit("delete-document", {
        documentId: e
      });
    }
    async export(t) {
      const e = dr(t), s = await __privateMethod(this, _c5, c_fn3).call(this, {
        documentId: e,
        isNew: false
      }).doc();
      if (s)
        return Zn(s);
    }
    import(t) {
      const e = Na(t), r = this.create();
      return r.update(() => Ir(e)), r;
    }
    async flush(t) {
      if (!this.storageSubsystem)
        return;
      const e = t ? t.map((r) => __privateGet(this, _t8)[r]) : Object.values(__privateGet(this, _t8));
      await Promise.all(e.map(async (r) => {
        const s = r.docSync();
        if (s)
          return this.storageSubsystem.saveDoc(r.documentId, s);
      }));
    }
  }, _e8 = new WeakMap(), _t8 = new WeakMap(), _r8 = new WeakMap(), _n8 = new WeakMap(), _s8 = new WeakMap(), _o8 = new WeakSet(), o_fn3 = function(t) {
    switch (t.type) {
      case "remote-subscription-change":
        __privateGet(this, _s8) && __privateGet(this, _n8).handleControlMessage(t);
        break;
      case "remote-heads-changed":
        __privateGet(this, _s8) && __privateGet(this, _n8).handleRemoteHeads(t);
        break;
      case "sync":
      case "request":
      case "ephemeral":
      case "doc-unavailable":
        __privateGet(this, _r8).receiveMessage(t).catch((e) => {
          console.log("error receiving message", {
            err: e
          });
        });
    }
  }, _a8 = new WeakMap(), _i6 = new WeakSet(), i_fn4 = function(t) {
    if (!this.storageSubsystem)
      return;
    const { storageId: e, isEphemeral: r } = this.peerMetadataByPeerId[t.peerId] || {};
    if (!e || r)
      return;
    let s = __privateGet(this, _a8)[e];
    s || (s = __privateGet(this, _a8)[e] = Nr(({ documentId: o, syncState: i }) => {
      this.storageSubsystem.saveSyncState(o, e, i);
    }, this.saveDebounceRate)), s(t);
  }, _c5 = new WeakSet(), c_fn3 = function({ documentId: t, isNew: e, initialValue: r }) {
    if (__privateGet(this, _t8)[t])
      return __privateGet(this, _t8)[t];
    if (!t)
      throw new Error(`Invalid documentId ${t}`);
    const s = new zh(t, {
      isNew: e,
      initialValue: r
    });
    return __privateGet(this, _t8)[t] = s, s;
  }, _b2);
  gg = class extends me {
    constructor() {
      super(...arguments);
      __publicField(this, "peerId");
      __publicField(this, "peerMetadata");
    }
  };
  yn();
  class bg extends me {
    constructor(t) {
      t.addEventListener("message", (e) => {
        this.emit("message", e);
      });
      super();
      __publicField(this, "port");
      this.port = t;
    }
    postMessage(t, e) {
      this.port.postMessage(t, e);
    }
    start() {
      this.port.start();
    }
    isAlive() {
      return true;
    }
  }
  class pg extends me {
    constructor(t) {
      super();
      __publicField(this, "weakRef");
      __publicField(this, "isDisconnected", false);
      this.weakRef = new WeakRef(t), t.addEventListener("message", (e) => {
        this.emit("message", e);
      });
    }
    postMessage(t, e) {
      const r = this.weakRef.deref();
      if (!r) {
        this.disconnnect();
        return;
      }
      try {
        r.postMessage(t, e);
      } catch {
        this.disconnnect();
      }
    }
    start() {
      const t = this.weakRef.deref();
      if (!t) {
        this.disconnnect();
        return;
      }
      try {
        t.start();
      } catch {
        this.disconnnect();
      }
    }
    disconnnect() {
      this.isDisconnected || (this.emit("close"), this.isDisconnected = true);
    }
    isAlive() {
      return this.isDisconnected ? false : this.weakRef.deref() ? true : (this.disconnnect(), false);
    }
  }
  const Oo = ye("automerge-repo:messagechannel");
  Eg = (_c6 = class extends gg {
    constructor(t, e = {}) {
      super();
      __publicField(this, "channels", {});
      __publicField(this, "messagePortRef");
      __privateAdd(this, _e9, false);
      const r = e.useWeakRef ?? false;
      this.messagePortRef = r ? new pg(t) : new bg(t);
    }
    connect(t, e) {
      Oo("messageport connecting"), this.peerId = t, this.peerMetadata = e, this.messagePortRef.start(), this.messagePortRef.addListener("message", (r) => {
        Oo("message port received %o", r.data);
        const s = r.data;
        if ("targetId" in s && s.targetId !== this.peerId)
          throw new Error("MessagePortNetwork should never receive messages for a different peer.");
        const { senderId: o, type: i } = s;
        switch (i) {
          case "arrive":
            {
              const { peerMetadata: a } = s;
              this.messagePortRef.postMessage({
                type: "welcome",
                senderId: this.peerId,
                peerMetadata: this.peerMetadata,
                targetId: o
              }), this.announceConnection(o, a);
            }
            break;
          case "welcome":
            {
              const { peerMetadata: a } = s;
              this.announceConnection(o, a);
            }
            break;
          default:
            "data" in s ? this.emit("message", {
              ...s,
              data: s.data ? new Uint8Array(s.data) : void 0
            }) : this.emit("message", s);
            break;
        }
      }), this.messagePortRef.addListener("close", () => {
        this.emit("close");
      }), this.messagePortRef.postMessage({
        senderId: this.peerId,
        type: "arrive",
        peerMetadata: e
      }), setTimeout(() => {
        __privateGet(this, _e9) || (__privateSet(this, _e9, true), this.emit("ready", {
          network: this
        }));
      }, 100);
    }
    send(t) {
      if ("data" in t) {
        const e = t.data.buffer.slice(t.data.byteOffset, t.data.byteOffset + t.data.byteLength);
        this.messagePortRef.postMessage({
          ...t,
          data: e
        }, [
          e
        ]);
      } else
        this.messagePortRef.postMessage(t);
    }
    announceConnection(t, e) {
      __privateGet(this, _e9) || (__privateSet(this, _e9, true), this.emit("ready", {
        network: this
      })), this.emit("peer-candidate", {
        peerId: t,
        peerMetadata: e
      });
    }
    disconnect() {
      throw new Error("Unimplemented: leave on MessagePortNetworkAdapter");
    }
  }, _e9 = new WeakMap(), _c6);
  Cg = class {
    constructor(t = "automerge", e = "documents") {
      __publicField(this, "database");
      __publicField(this, "store");
      __publicField(this, "dbPromise");
      this.database = t, this.store = e, this.dbPromise = this.createDatabasePromise();
    }
    createDatabasePromise() {
      return new Promise((t, e) => {
        const r = indexedDB.open(this.database, 1);
        r.onerror = () => {
          e(r.error);
        }, r.onupgradeneeded = (s) => {
          s.target.result.createObjectStore(this.store);
        }, r.onsuccess = (s) => {
          const o = s.target.result;
          t(o);
        };
      });
    }
    async load(t) {
      const r = (await this.dbPromise).transaction(this.store), o = r.objectStore(this.store).get(t);
      return new Promise((i, a) => {
        r.onerror = () => {
          a(o.error);
        }, o.onsuccess = (c) => {
          const f = c.target.result;
          f && typeof f == "object" && "binary" in f ? i(f.binary) : i(void 0);
        };
      });
    }
    async save(t, e) {
      const s = (await this.dbPromise).transaction(this.store, "readwrite");
      return s.objectStore(this.store).put({
        key: t,
        binary: e
      }, t), new Promise((i, a) => {
        s.onerror = () => {
          a(s.error);
        }, s.oncomplete = () => {
          i();
        };
      });
    }
    async remove(t) {
      const r = (await this.dbPromise).transaction(this.store, "readwrite");
      return r.objectStore(this.store).delete(t), new Promise((o, i) => {
        r.onerror = () => {
          i(r.error);
        }, r.oncomplete = () => {
          o();
        };
      });
    }
    async loadRange(t) {
      const e = await this.dbPromise, r = t, s = [
        ...t,
        "\uFFFF"
      ], o = IDBKeyRange.bound(r, s), i = e.transaction(this.store), c = i.objectStore(this.store).openCursor(o), f = [];
      return new Promise((u, _) => {
        i.onerror = () => {
          _(c.error);
        }, c.onsuccess = (d) => {
          const l = d.target.result;
          l ? (f.push({
            data: l.value.binary,
            key: l.key
          }), l.continue()) : u(f);
        };
      });
    }
    async removeRange(t) {
      const e = await this.dbPromise, r = t, s = [
        ...t,
        "\uFFFF"
      ], o = IDBKeyRange.bound(r, s), i = e.transaction(this.store, "readwrite");
      return i.objectStore(this.store).delete(o), new Promise((c, f) => {
        i.onerror = () => {
          f(i.error);
        }, i.oncomplete = () => {
          c();
        };
      });
    }
  };
})();
export {
  dd as A,
  zh as D,
  me as E,
  Cg as I,
  Eg as M,
  gg as N,
  Ag as R,
  Gr as U,
  __tla,
  Rf as a,
  dn as b,
  Rd as c,
  Tt as d,
  Xl as e,
  mg as f,
  Ss as g,
  Zn as h,
  ph as i,
  Fs as j,
  fn as k,
  gs as l,
  id as m,
  od as n,
  jd as o,
  Ps as p,
  Jf as q,
  Ts as r,
  Xf as s,
  yg as t,
  Qr as u,
  ye as v,
  Ph as w,
  vg as x,
  wg as y
};
