var __defProp = Object.defineProperty;
var __typeError = (msg) => {
  throw TypeError(msg);
};
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);
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
var __privateAdd = (obj, member, value) => member.has(obj) ? __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), value);
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
let gr, Td, zd, Nn, Cs, Fd, oc, jd, En, Ht, $d, Lc, Te, Xn, Es, Dd, Ut, Ud, Fa, $i, Pi, Li, cc, Qe, Rd, Hd, fr, Md, Vd, Mc, Gt, Ca, mr, Bd, Pd, Ld;
let __tla = (async () => {
  var _r2, _e2, _Cc_instances, s_fn, n_fn, i_fn, a_fn, f_fn, o_fn, t_fn, h_fn, __fn, c_fn, u_fn, d_fn, m_fn, y_fn, l_fn, p_fn, b_fn, _r3, _e3, _s2, _n2, _i2, _a2, _f2, _o2, _Nn_instances, t_get, h_get, __fn2, c_fn2, u_fn2, d_fn2, _a3, _r4, _e4, _s3, _n3, _i3, _a4, _f3, _o3, _t2, _h, _zc_instances, __fn3, c_fn3, u_fn3, d_fn3, m_fn2, y_fn2, l_fn2, p_fn2, b_fn2, g_fn, w_fn, _r5, _e5, _s4, _n4, _zd_instances, i_fn2, a_fn2, f_fn2, o_fn2, _b;
  function Wn(t) {
    return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
  }
  const Xt = /* @__PURE__ */ Symbol.for("_am_meta"), dt = /* @__PURE__ */ Symbol.for("_am_trace"), ht = /* @__PURE__ */ Symbol.for("_am_objectId"), Gn = /* @__PURE__ */ Symbol.for("_am_isProxy"), Kn = /* @__PURE__ */ Symbol.for("_am_clearCache"), mi = /* @__PURE__ */ Symbol.for("_am_uint"), wi = /* @__PURE__ */ Symbol.for("_am_int"), xi = /* @__PURE__ */ Symbol.for("_am_f64"), _s = /* @__PURE__ */ Symbol.for("_am_counter"), ps = /* @__PURE__ */ Symbol.for("_am_immutableString");
  class Cn {
    constructor(e) {
      this.value = e || 0, Reflect.defineProperty(this, _s, {
        value: true
      });
    }
    valueOf() {
      return this.value;
    }
    toString() {
      return this.valueOf().toString();
    }
    toJSON() {
      return this.value;
    }
    increment(e) {
      throw new Error("Counters should not be incremented outside of a change callback");
    }
    decrement(e) {
      throw new Error("Counters should not be decremented outside of a change callback");
    }
  }
  class Si extends Cn {
    constructor(e, n, r, s, i) {
      super(e), this.context = n, this.path = r, this.objectId = s, this.key = i;
    }
    increment(e) {
      return e = typeof e == "number" ? e : 1, this.context.increment(this.objectId, this.key, e), this.value += e, this.value;
    }
    decrement(e) {
      return this.increment(typeof e == "number" ? -e : -1);
    }
  }
  function vi(t, e, n, r, s) {
    return new Si(t, e, n, r, s);
  }
  var ys;
  class bs {
    constructor(e) {
      this[ys] = true, this.val = e;
    }
    toString() {
      return this.val;
    }
    toJSON() {
      return this.val;
    }
  }
  ys = ps;
  const Ai = BigInt("9223372036854775807");
  function He(t) {
    if (typeof t == "string" && /^[0-9]+$/.test(t) && (t = parseInt(t, 10)), typeof t != "number") return t;
    if (t < 0 || isNaN(t) || t === 1 / 0 || t === -1 / 0) throw new RangeError("A list index must be positive, but you passed " + t);
    return t;
  }
  function pe(t, e) {
    const { context: n, objectId: r, path: s } = t, i = n.getWithType(r, e);
    if (i === null) return;
    const o = i[0], a = i[1];
    switch (o) {
      case void 0:
        return;
      case "map":
        return mt(n, a, [
          ...s,
          e
        ]);
      case "list":
        return Zt(n, a, [
          ...s,
          e
        ]);
      case "text":
        return n.text(a);
      case "str":
        return new bs(a);
      case "uint":
        return a;
      case "int":
        return a;
      case "f64":
        return a;
      case "boolean":
        return a;
      case "null":
        return null;
      case "bytes":
        return a;
      case "timestamp":
        return a;
      case "counter":
        return vi(a, n, s, r, e);
      default:
        throw RangeError(`datatype ${o} unimplemented`);
    }
  }
  function $t(t, e, n) {
    const r = typeof t;
    switch (r) {
      case "object":
        if (t == null) return [
          null,
          "null"
        ];
        if (t[mi]) return [
          t.value,
          "uint"
        ];
        if (t[wi]) return [
          t.value,
          "int"
        ];
        if (t[xi]) return [
          t.value,
          "f64"
        ];
        if (t[_s]) return [
          t.value,
          "counter"
        ];
        if (t instanceof Date) return [
          t.getTime(),
          "timestamp"
        ];
        if (ms(t)) return [
          t.toString(),
          "str"
        ];
        if (t instanceof Uint8Array) return [
          t,
          "bytes"
        ];
        if (t instanceof Array) return [
          t,
          "list"
        ];
        if (Object.prototype.toString.call(t) === "[object Object]") return [
          t,
          "map"
        ];
        throw Yt(t, n) ? new RangeError("Cannot create a reference to an existing document object") : new RangeError(`Cannot assign unknown object: ${t}`);
      case "boolean":
        return [
          t,
          "boolean"
        ];
      case "bigint":
        return t > Ai ? [
          t,
          "uint"
        ] : [
          t,
          "int"
        ];
      case "number":
        return Number.isInteger(t) ? [
          t,
          "int"
        ] : [
          t,
          "f64"
        ];
      case "string":
        return [
          t,
          "text"
        ];
      case "undefined":
        throw new RangeError([
          `Cannot assign undefined value at ${br(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 ${r} value at ${br(e)}. `,
          "All JSON primitive datatypes (object, array, string, number, boolean, null) ",
          `are supported in an Automerge document; ${r} values are not. `
        ].join(""));
    }
  }
  function Yt(t, e) {
    var n, r;
    return t instanceof Date ? false : !!(t && ((r = (n = t[Xt]) === null || n === void 0 ? void 0 : n.handle) === null || r === void 0 ? void 0 : r.__wbg_ptr) === e.__wbg_ptr);
  }
  const Ei = {
    get(t, e) {
      const { context: n, objectId: r, cache: s } = t;
      return e === Symbol.toStringTag ? t[Symbol.toStringTag] : e === ht ? r : e === Gn ? true : e === dt ? t.trace : e === Xt ? {
        handle: n
      } : (s[e] || (s[e] = pe(t, e)), s[e]);
    },
    set(t, e, n) {
      const { context: r, objectId: s, path: i } = t;
      if (t.cache = {}, Yt(n, r)) throw new RangeError("Cannot create a reference to an existing document object");
      if (e === dt) return t.trace = n, true;
      if (e === Kn) return true;
      const [o, a] = $t(n, [
        ...i,
        e
      ], r);
      switch (a) {
        case "list": {
          const c = r.putObject(s, e, []), l = Zt(r, c, [
            ...i,
            e
          ]);
          for (let h = 0; h < o.length; h++) l[h] = o[h];
          break;
        }
        case "text": {
          r.putObject(s, e, o);
          break;
        }
        case "map": {
          const c = r.putObject(s, e, {}), l = mt(r, c, [
            ...i,
            e
          ]);
          for (const h in o) l[h] = o[h];
          break;
        }
        default:
          r.put(s, e, o, a);
      }
      return true;
    },
    deleteProperty(t, e) {
      const { context: n, objectId: r } = t;
      return t.cache = {}, n.delete(r, e), true;
    },
    has(t, e) {
      return this.get(t, e) !== void 0;
    },
    getOwnPropertyDescriptor(t, e) {
      const n = this.get(t, e);
      if (typeof n < "u") return {
        configurable: true,
        enumerable: true,
        value: n
      };
    },
    ownKeys(t) {
      const { context: e, objectId: n } = t, r = e.keys(n);
      return [
        ...new Set(r)
      ];
    }
  }, Ii = {
    get(t, e) {
      const { context: n, objectId: r } = t;
      return e = He(e), e === Symbol.hasInstance ? (s) => Array.isArray(s) : e === Symbol.toStringTag ? t[Symbol.toStringTag] : e === ht ? r : e === Gn ? true : e === dt ? t.trace : e === Xt ? {
        handle: n
      } : e === "length" ? n.length(r) : typeof e == "number" ? pe(t, e) : ki(t)[e];
    },
    set(t, e, n) {
      const { context: r, objectId: s, path: i } = t;
      if (e = He(e), Yt(n, r)) throw new RangeError("Cannot create a reference to an existing document object");
      if (e === Kn) return true;
      if (e === dt) return t.trace = n, true;
      if (typeof e == "string") throw new RangeError("list index must be a number");
      const [o, a] = $t(n, [
        ...i,
        e
      ], r);
      switch (a) {
        case "list": {
          let c;
          e >= r.length(s) ? c = r.insertObject(s, e, []) : c = r.putObject(s, e, []), Zt(r, c, [
            ...i,
            e
          ]).splice(0, 0, ...o);
          break;
        }
        case "text": {
          e >= r.length(s) ? r.insertObject(s, e, o) : r.putObject(s, e, o);
          break;
        }
        case "map": {
          let c;
          e >= r.length(s) ? c = r.insertObject(s, e, {}) : c = r.putObject(s, e, {});
          const l = mt(r, c, [
            ...i,
            e
          ]);
          for (const h in o) l[h] = o[h];
          break;
        }
        default:
          e >= r.length(s) ? r.insert(s, e, o, a) : r.put(s, e, o, a);
      }
      return true;
    },
    deleteProperty(t, e) {
      const { context: n, objectId: r } = t;
      e = He(e);
      const s = n.get(r, e);
      if (s != null && s[0] == "counter") throw new TypeError("Unsupported operation: deleting a counter from a list");
      return n.delete(r, e), true;
    },
    has(t, e) {
      const { context: n, objectId: r } = t;
      return e = He(e), typeof e == "number" ? e < n.length(r) : e === "length";
    },
    getOwnPropertyDescriptor(t, e) {
      const { context: n, objectId: r } = t;
      return e === "length" ? {
        writable: true,
        value: n.length(r)
      } : e === ht ? {
        configurable: false,
        enumerable: false,
        value: r
      } : (e = He(e), {
        configurable: true,
        enumerable: true,
        value: pe(t, e)
      });
    },
    getPrototypeOf(t) {
      return Object.getPrototypeOf(t);
    },
    ownKeys() {
      const t = [];
      return t.push("length"), t;
    }
  };
  function mt(t, e, n) {
    const r = {
      context: t,
      objectId: e,
      path: n || [],
      cache: {}
    }, s = {};
    return Object.assign(s, r), new Proxy(s, Ei);
  }
  function Zt(t, e, n) {
    const r = {
      context: t,
      objectId: e,
      path: n || [],
      cache: {}
    }, s = [];
    return Object.assign(s, r), new Proxy(s, Ii);
  }
  function Ci(t) {
    return mt(t, "_root", []);
  }
  function ki(t) {
    const { context: e, objectId: n, path: r } = t;
    return {
      at(i) {
        return pe(t, i);
      },
      deleteAt(i, o) {
        return typeof o == "number" ? e.splice(n, i, o) : e.delete(n, i), this;
      },
      fill(i, o, a) {
        const [c, l] = $t(i, [
          ...r,
          o
        ], e), h = e.length(n);
        o = He(o || 0), a = He(a || h);
        for (let f = o; f < Math.min(a, h); f++) l === "list" || l === "map" || l === "text" ? e.putObject(n, f, c) : e.put(n, f, c, l);
        return this;
      },
      indexOf(i, o = 0) {
        const a = e.length(n);
        for (let c = o; c < a; c++) {
          const l = e.getWithType(n, c);
          if (!l) continue;
          const [h, f] = l;
          if (![
            "map",
            "list",
            "text"
          ].includes(h)) {
            if (f === i) return c;
            continue;
          }
          if (h === "text" && typeof i == "string" && i === pe(t, c) || i[ht] === f) return c;
        }
        return -1;
      },
      insertAt(i, ...o) {
        return this.splice(i, 0, ...o), this;
      },
      pop() {
        const i = e.length(n);
        if (i == 0) return;
        const o = pe(t, i - 1);
        return e.delete(n, i - 1), o;
      },
      push(...i) {
        const o = e.length(n);
        return this.splice(o, 0, ...i), e.length(n);
      },
      shift() {
        if (e.length(n) == 0) return;
        const i = pe(t, 0);
        return e.delete(n, 0), i;
      },
      splice(i, o, ...a) {
        i = He(i), typeof o != "number" && (o = e.length(n) - i), o = He(o);
        for (const h of a) if (Yt(h, e)) throw new RangeError("Cannot create a reference to an existing document object");
        const c = [];
        for (let h = 0; h < o; h++) {
          const f = pe(t, i);
          f !== void 0 && c.push(f), e.delete(n, i);
        }
        const l = a.map((h, f) => {
          try {
            return $t(h, [
              ...r
            ], e);
          } catch (u) {
            throw u instanceof RangeError ? new RangeError(`${u.message} (at index ${f} in the input)`) : u;
          }
        });
        for (const [h, f] of l) {
          switch (f) {
            case "list": {
              const u = e.insertObject(n, i, []);
              Zt(e, u, [
                ...r,
                i
              ]).splice(0, 0, ...h);
              break;
            }
            case "text": {
              e.insertObject(n, i, h);
              break;
            }
            case "map": {
              const u = e.insertObject(n, i, {}), d = mt(e, u, [
                ...r,
                i
              ]);
              for (const g in h) d[g] = h[g];
              break;
            }
            default:
              e.insert(n, i, h, f);
          }
          i += 1;
        }
        return c;
      },
      unshift(...i) {
        return this.splice(0, 0, ...i), e.length(n);
      },
      entries() {
        let i = 0;
        return {
          next: () => {
            const a = pe(t, i);
            return a === void 0 ? {
              value: void 0,
              done: true
            } : {
              value: [
                i++,
                a
              ],
              done: false
            };
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      keys() {
        let i = 0;
        const o = e.length(n);
        return {
          next: () => i < o ? {
            value: i++,
            done: false
          } : {
            value: void 0,
            done: true
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      values() {
        let i = 0;
        return {
          next: () => {
            const a = pe(t, i++);
            return a === void 0 ? {
              value: void 0,
              done: true
            } : {
              value: a,
              done: false
            };
          },
          [Symbol.iterator]() {
            return this;
          }
        };
      },
      toArray() {
        const i = [];
        let o;
        do
          o = pe(t, i.length), o !== void 0 && i.push(o);
        while (o !== 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 o = 0;
        for (const a of this) {
          if (i(a, o)) return a;
          o += 1;
        }
      },
      findIndex(i) {
        let o = 0;
        for (const a of this) {
          if (i(a, o)) return o;
          o += 1;
        }
        return -1;
      },
      includes(i) {
        return this.find((o) => o === i) !== void 0;
      },
      join(i) {
        return this.toArray().join(i);
      },
      reduce(i, o) {
        return this.toArray().reduce(i, o);
      },
      reduceRight(i, o) {
        return this.toArray().reduceRight(i, o);
      },
      lastIndexOf(i, o = 1 / 0) {
        return this.toArray().lastIndexOf(i, o);
      },
      slice(i, o) {
        return this.toArray().slice(i, o);
      },
      some(i) {
        let o = 0;
        for (const a of this) {
          if (i(a, o)) return true;
          o += 1;
        }
        return false;
      },
      [Symbol.iterator]: function* () {
        let i = 0, o = pe(t, i);
        for (; o !== void 0; ) yield o, i += 1, o = pe(t, i);
      }
    };
  }
  function br(t) {
    const e = t.map((n) => {
      if (typeof n == "number") return n.toString();
      if (typeof n == "string") return n.replace(/~/g, "~0").replace(/\//g, "~1");
    });
    return t.length === 0 ? "" : "/" + e.join("/");
  }
  function ms(t) {
    return typeof t == "object" && t !== null && Object.prototype.hasOwnProperty.call(t, ps);
  }
  typeof FinalizationRegistry > "u" || new FinalizationRegistry((t) => ws.__wbg_automerge_free(t >>> 0, 1));
  typeof FinalizationRegistry > "u" || new FinalizationRegistry((t) => ws.__wbg_syncstate_free(t >>> 0, 1));
  let Oi = new TextDecoder("utf-8", {
    ignoreBOM: true,
    fatal: true
  });
  Oi.decode();
  const an = new TextEncoder();
  "encodeInto" in an || (an.encodeInto = function(t, e) {
    const n = an.encode(t);
    return e.set(n), {
      read: t.length,
      written: n.length
    };
  });
  let ws, Ri = [];
  function Hi(t) {
    for (const e in t) fe[e] = t[e];
    for (const e of Ri) e();
  }
  const fe = {
    create(t) {
      throw new RangeError("Automerge.use() not called");
    },
    load(t, e) {
      throw new RangeError("Automerge.use() not called (load)");
    },
    encodeChange(t) {
      throw new RangeError("Automerge.use() not called (encodeChange)");
    },
    decodeChange(t) {
      throw new RangeError("Automerge.use() not called (decodeChange)");
    },
    initSyncState() {
      throw new RangeError("Automerge.use() not called (initSyncState)");
    },
    encodeSyncMessage(t) {
      throw new RangeError("Automerge.use() not called (encodeSyncMessage)");
    },
    decodeSyncMessage(t) {
      throw new RangeError("Automerge.use() not called (decodeSyncMessage)");
    },
    encodeSyncState(t) {
      throw new RangeError("Automerge.use() not called (encodeSyncState)");
    },
    decodeSyncState(t) {
      throw new RangeError("Automerge.use() not called (decodeSyncState)");
    },
    exportSyncState(t) {
      throw new RangeError("Automerge.use() not called (exportSyncState)");
    },
    importSyncState(t) {
      throw new RangeError("Automerge.use() not called (importSyncState)");
    },
    readBundle(t) {
      throw new RangeError("Automerge.use() not called (readBundle)");
    },
    wasmReleaseInfo() {
      throw new RangeError("Automerge.use() not called (wasmReleaseInfo)");
    }
  }, Ti = "b8dfc4845c50633f9d850a5d4e2a4219d518f8ad";
  function Z(t, e = true) {
    if (typeof t != "object") throw new RangeError("must be the document root");
    const n = Reflect.get(t, Xt);
    if (n === void 0 || n == null || e && vs(t) !== "_root") throw new RangeError("must be the document root");
    return n;
  }
  function xs(t) {
    Reflect.set(t, Kn, true);
  }
  function Ss(t) {
    return Reflect.get(t, dt);
  }
  function vs(t) {
    return typeof t != "object" || t === null ? null : Reflect.get(t, ht);
  }
  function it(t) {
    return !!Reflect.get(t, Gn);
  }
  var Ui = function(t, e) {
    var n = {};
    for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
    if (t != null && typeof Object.getOwnPropertySymbols == "function") for (var s = 0, r = Object.getOwnPropertySymbols(t); s < r.length; s++) e.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(t, r[s]) && (n[r[s]] = t[r[s]]);
    return n;
  };
  function Jn(t) {
    return typeof t == "object" ? t : {
      actor: t
    };
  }
  function Di(t, e, n) {
    if (typeof n == "string") {
      if (/^-?[0-9]+@[0-9a-zA-Z]+$|^[se]$/.test(n)) return t.handle.getCursorPosition(e, n);
      throw new RangeError("index must be a number or cursor");
    } else return n;
  }
  Te = function(t) {
    const e = Jn(t), n = !!e.freeze, r = e.patchCallback, s = e.actor, i = fe.create({
      actor: s
    });
    return i.enableFreeze(!!e.freeze), As(i), i.materialize("/", void 0, {
      handle: i,
      heads: void 0,
      freeze: n,
      patchCallback: r
    });
  };
  function Mi(t, e) {
    const n = Z(t), r = n.handle;
    return n.handle.materialize("/", e, Object.assign(Object.assign({}, n), {
      handle: r,
      heads: e
    }));
  }
  mr = function(t, e) {
    const n = Z(t), r = n.heads, s = Jn(e), i = n.handle.fork(s.actor, r);
    i.updateDiffCursor();
    const { heads: o } = n, a = Ui(n, [
      "heads"
    ]);
    return a.patchCallback = s.patchCallback, i.applyPatches(t, Object.assign(Object.assign({}, a), {
      handle: i
    }));
  };
  Rd = function(t, e) {
    return gt(Te(e), "from", {}, (n) => Object.assign(n, t)).newDoc;
  };
  function Bi(t, e, n) {
    if (typeof e == "function") return gt(t, "change", {}, e).newDoc;
    if (typeof n == "function") return typeof e == "string" && (e = {
      message: e
    }), gt(t, "change", e, n).newDoc;
    throw RangeError("Invalid args for change");
  }
  function ji(t, e, n, r) {
    if (typeof n == "function") return gt(t, "changeAt", {}, n, e);
    if (typeof r == "function") return typeof n == "string" && (n = {
      message: n
    }), gt(t, "changeAt", n, r, e);
    throw RangeError("Invalid args for changeAt");
  }
  function wt(t, e, n, r) {
    if (n == null) return t;
    const s = Z(t), i = Object.assign(Object.assign({}, s), {
      heads: void 0
    }), { value: o, patches: a } = s.handle.applyAndReturnPatches(t, i);
    if (a.length > 0) {
      r == null ? void 0 : r(a, {
        before: t,
        after: o,
        source: e
      });
      const c = Z(o);
      c.mostRecentPatch = {
        before: Z(t).heads,
        after: c.handle.getHeads(),
        patches: a
      };
    }
    return s.heads = n, o;
  }
  function gt(t, e, n, r, s) {
    if (typeof r != "function") throw new RangeError("invalid change function");
    const i = Z(t);
    if (t === void 0 || i === void 0) throw new RangeError("must be the document root");
    if (i.heads) throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (it(t)) throw new RangeError("Calls to Automerge.change cannot be nested");
    let o = i.handle.getHeads();
    s && Fi(s, o) && (s = void 0), s && (i.handle.isolate(s), o = s), "time" in n || (n.time = Math.floor(Date.now() / 1e3));
    try {
      i.heads = o;
      const a = Ci(i.handle);
      if (r(a), i.handle.pendingOps() === 0) return i.heads = void 0, s && i.handle.integrate(), {
        newDoc: t,
        newHeads: null
      };
      {
        const c = i.handle.commit(n.message, n.time);
        return i.handle.integrate(), {
          newDoc: wt(t, e, o, n.patchCallback || i.patchCallback),
          newHeads: c != null ? [
            c
          ] : null
        };
      }
    } catch (a) {
      throw i.heads = void 0, i.handle.rollback(), a;
    }
  }
  Hd = function(t, e) {
    e === void 0 && (e = {}), typeof e == "string" && (e = {
      message: e
    }), "time" in e || (e.time = Math.floor(Date.now() / 1e3));
    const n = Z(t);
    if (n.heads) throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (it(t)) throw new RangeError("Calls to Automerge.change cannot be nested");
    const r = n.handle.getHeads();
    return n.handle.emptyChange(e.message, e.time), wt(t, "emptyChange", r);
  };
  Td = function(t, e) {
    const n = Jn(e);
    if (n.patchCallback) return Li(Te(n), t);
    const r = n.actor, s = n.patchCallback, i = n.unchecked || false, o = n.allowMissingChanges || false, a = n.convertImmutableStringsToText || false, c = fe.load(t, {
      actor: r,
      unchecked: i,
      allowMissingDeps: o,
      convertImmutableStringsToText: a
    });
    return c.enableFreeze(!!n.freeze), As(c), c.materialize("/", void 0, {
      handle: c,
      heads: void 0,
      patchCallback: s
    });
  };
  Li = function(t, e, n) {
    n || (n = {});
    const r = Z(t);
    if (r.heads) throw new RangeError("Attempting to change an out of date document - set at: " + Ss(t));
    if (it(t)) throw new RangeError("Calls to Automerge.change cannot be nested");
    const s = r.handle.getHeads();
    return r.handle.loadIncremental(e), wt(t, "loadIncremental", s, n.patchCallback || r.patchCallback);
  };
  Ud = function(t) {
    return Z(t).handle.save();
  };
  function wr(t, e) {
    const n = Z(t);
    if (n.heads) throw new RangeError("Attempting to change an out of date document - set at: " + Ss(t));
    const r = n.handle.getHeads(), s = Z(e), i = n.handle.getChangesAdded(s.handle);
    return n.handle.applyChanges(i), wt(t, "merge", r, n.patchCallback);
  }
  function cn(t, e, n) {
    xr(e, "before heads"), xr(n, "after heads");
    const r = Z(t);
    return r.mostRecentPatch && kn(r.mostRecentPatch.before, e) && kn(r.mostRecentPatch.after, n) ? r.mostRecentPatch.patches : r.handle.diff(e, n);
  }
  function Fi(t, e) {
    if (t.length !== e.length) return false;
    for (let n = 0; n < t.length; n++) if (t[n] !== e[n]) return false;
    return true;
  }
  function xr(t, e) {
    if (!Array.isArray(t)) throw new Error(`invalid ${e}: must be an array`);
  }
  function kn(t, e) {
    if (!Sr(t) || !Sr(e)) return t === e;
    const n = Object.keys(t).sort(), r = Object.keys(e).sort();
    if (n.length !== r.length) return false;
    for (let s = 0; s < n.length; s++) if (n[s] !== r[s] || !kn(t[n[s]], e[r[s]])) return false;
    return true;
  }
  Pi = function(t) {
    const e = fe.importSyncState(t), n = fe.encodeSyncState(e);
    return e.free(), n;
  };
  $i = function(t) {
    const e = fe.decodeSyncState(t), n = fe.exportSyncState(e);
    return e.free(), n;
  };
  function Vi(t, e) {
    const n = Z(t), r = fe.importSyncState(e), s = n.handle.generateSyncMessage(r);
    return [
      fe.exportSyncState(r),
      s
    ];
  }
  function zi(t, e, n, r) {
    const s = fe.importSyncState(e);
    r || (r = {});
    const i = Z(t);
    if (i.heads) throw new RangeError("Attempting to change an outdated document.  Use Automerge.clone() if you wish to make a writable copy.");
    if (it(t)) throw new RangeError("Calls to Automerge.change cannot be nested");
    const o = i.handle.getHeads();
    i.handle.receiveSyncMessage(s, n);
    const a = fe.exportSyncState(s);
    return [
      wt(t, "receiveSyncMessage", o, r.patchCallback || i.patchCallback),
      a,
      null
    ];
  }
  function Ni() {
    return fe.exportSyncState(fe.initSyncState());
  }
  function qi(t) {
    return fe.decodeSyncMessage(t);
  }
  Ut = function(t) {
    const e = Z(t);
    return e.heads || e.handle.getHeads();
  };
  function Sr(t) {
    return typeof t == "object" && t !== null;
  }
  Dd = function(t, e) {
    return Z(t).handle.saveSince(e);
  };
  function As(t) {
    t.registerDatatype("counter", (e) => new Cn(e), (e) => {
      if (e instanceof Cn) return e.value;
    }), t.registerDatatype("str", (e) => new bs(e), (e) => {
      if (ms(e)) return e.val;
    });
  }
  function Wi(t) {
    return Z(t).handle.topoHistoryTraversal();
  }
  function Gi(t, e) {
    return Z(t).handle.getDecodedChangeByHash(e);
  }
  Es = function(t) {
    var e, n, r, s, i, o;
    const c = Z(t).handle.stats(), l = Ki();
    return Object.assign(Object.assign({}, c), {
      cargoPackageName: (n = (e = l.wasm) === null || e === void 0 ? void 0 : e.cargoPackageName) !== null && n !== void 0 ? n : "unknown",
      cargoPackageVersion: (s = (r = l.wasm) === null || r === void 0 ? void 0 : r.cargoPackageVersion) !== null && s !== void 0 ? s : "unknown",
      rustcVersion: (o = (i = l.wasm) === null || i === void 0 ? void 0 : i.rustcVersion) !== null && o !== void 0 ? o : "unknown"
    });
  };
  function Ki() {
    let t = null;
    try {
      t = fe.wasmReleaseInfo();
    } catch {
    }
    return {
      js: {
        gitHead: Ti
      },
      wasm: t
    };
  }
  function Is(t, e, n, r, s) {
    const i = Qt(t, e, "splice");
    if (!it(t)) throw new RangeError("object cannot be modified outside of a change block");
    const o = Z(t, false);
    xs(t), n = Di(o, i, n);
    try {
      return o.handle.splice(i, n, r, s);
    } catch (a) {
      throw new RangeError(`Cannot splice: ${a}`);
    }
  }
  function Ji(t, e, n) {
    const r = Qt(t, e, "updateText");
    if (!it(t)) throw new RangeError("object cannot be modified outside of a change block");
    const s = Z(t, false);
    xs(t);
    try {
      return s.handle.updateText(r, n);
    } catch (i) {
      throw new RangeError(`Cannot updateText: ${i}`);
    }
  }
  function vr(t, e, n, r) {
    const s = Qt(t, e, "getCursor"), i = Z(t, false);
    try {
      return i.handle.getCursor(s, n, i.heads, r);
    } catch (o) {
      throw new RangeError(`Cannot getCursor: ${o}`);
    }
  }
  function Ar(t, e, n) {
    const r = Qt(t, e, "getCursorPosition"), s = Z(t, false);
    try {
      return s.handle.getCursorPosition(r, n, s.heads);
    } catch (i) {
      throw new RangeError(`Cannot getCursorPosition: ${i}`);
    }
  }
  function Qt(t, e, n) {
    e = e.slice();
    const r = vs(t);
    if (!r) throw new RangeError(`invalid object for ${n}`);
    return e.unshift(r), e.join("/");
  }
  var Et = {
    exports: {}
  }, fn, Er;
  function Xi() {
    if (Er) return fn;
    Er = 1;
    var t = 1e3, e = t * 60, n = e * 60, r = n * 24, s = r * 7, i = r * 365.25;
    fn = function(h, f) {
      f = f || {};
      var u = typeof h;
      if (u === "string" && h.length > 0) return o(h);
      if (u === "number" && isFinite(h)) return f.long ? c(h) : a(h);
      throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(h));
    };
    function o(h) {
      if (h = String(h), !(h.length > 100)) {
        var f = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(h);
        if (f) {
          var u = parseFloat(f[1]), d = (f[2] || "ms").toLowerCase();
          switch (d) {
            case "years":
            case "year":
            case "yrs":
            case "yr":
            case "y":
              return u * i;
            case "weeks":
            case "week":
            case "w":
              return u * s;
            case "days":
            case "day":
            case "d":
              return u * r;
            case "hours":
            case "hour":
            case "hrs":
            case "hr":
            case "h":
              return u * n;
            case "minutes":
            case "minute":
            case "mins":
            case "min":
            case "m":
              return u * e;
            case "seconds":
            case "second":
            case "secs":
            case "sec":
            case "s":
              return u * t;
            case "milliseconds":
            case "millisecond":
            case "msecs":
            case "msec":
            case "ms":
              return u;
            default:
              return;
          }
        }
      }
    }
    function a(h) {
      var f = Math.abs(h);
      return f >= r ? Math.round(h / r) + "d" : f >= n ? Math.round(h / n) + "h" : f >= e ? Math.round(h / e) + "m" : f >= t ? Math.round(h / t) + "s" : h + "ms";
    }
    function c(h) {
      var f = Math.abs(h);
      return f >= r ? l(h, f, r, "day") : f >= n ? l(h, f, n, "hour") : f >= e ? l(h, f, e, "minute") : f >= t ? l(h, f, t, "second") : h + " ms";
    }
    function l(h, f, u, d) {
      var g = f >= u * 1.5;
      return Math.round(h / u) + " " + d + (g ? "s" : "");
    }
    return fn;
  }
  var un, Ir;
  function Yi() {
    if (Ir) return un;
    Ir = 1;
    function t(e) {
      r.debug = r, r.default = r, r.coerce = l, r.disable = a, r.enable = i, r.enabled = c, r.humanize = Xi(), r.destroy = h, Object.keys(e).forEach((f) => {
        r[f] = e[f];
      }), r.names = [], r.skips = [], r.formatters = {};
      function n(f) {
        let u = 0;
        for (let d = 0; d < f.length; d++) u = (u << 5) - u + f.charCodeAt(d), u |= 0;
        return r.colors[Math.abs(u) % r.colors.length];
      }
      r.selectColor = n;
      function r(f) {
        let u, d = null, g, m;
        function S(...M) {
          if (!S.enabled) return;
          const B = S, w = Number(/* @__PURE__ */ new Date()), N = w - (u || w);
          B.diff = N, B.prev = u, B.curr = w, u = w, M[0] = r.coerce(M[0]), typeof M[0] != "string" && M.unshift("%O");
          let U = 0;
          M[0] = M[0].replace(/%([a-zA-Z%])/g, (z, F) => {
            if (z === "%%") return "%";
            U++;
            const C = r.formatters[F];
            if (typeof C == "function") {
              const R = M[U];
              z = C.call(B, R), M.splice(U, 1), U--;
            }
            return z;
          }), r.formatArgs.call(B, M), (B.log || r.log).apply(B, M);
        }
        return S.namespace = f, S.useColors = r.useColors(), S.color = r.selectColor(f), S.extend = s, S.destroy = r.destroy, Object.defineProperty(S, "enabled", {
          enumerable: true,
          configurable: false,
          get: () => d !== null ? d : (g !== r.namespaces && (g = r.namespaces, m = r.enabled(f)), m),
          set: (M) => {
            d = M;
          }
        }), typeof r.init == "function" && r.init(S), S;
      }
      function s(f, u) {
        const d = r(this.namespace + (typeof u > "u" ? ":" : u) + f);
        return d.log = this.log, d;
      }
      function i(f) {
        r.save(f), r.namespaces = f, r.names = [], r.skips = [];
        const u = (typeof f == "string" ? f : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
        for (const d of u) d[0] === "-" ? r.skips.push(d.slice(1)) : r.names.push(d);
      }
      function o(f, u) {
        let d = 0, g = 0, m = -1, S = 0;
        for (; d < f.length; ) if (g < u.length && (u[g] === f[d] || u[g] === "*")) u[g] === "*" ? (m = g, S = d, g++) : (d++, g++);
        else if (m !== -1) g = m + 1, S++, d = S;
        else return false;
        for (; g < u.length && u[g] === "*"; ) g++;
        return g === u.length;
      }
      function a() {
        const f = [
          ...r.names,
          ...r.skips.map((u) => "-" + u)
        ].join(",");
        return r.enable(""), f;
      }
      function c(f) {
        for (const u of r.skips) if (o(f, u)) return false;
        for (const u of r.names) if (o(f, u)) return true;
        return false;
      }
      function l(f) {
        return f instanceof Error ? f.stack || f.message : f;
      }
      function h() {
        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 r.enable(r.load()), r;
    }
    return un = t, un;
  }
  var Cr;
  function Zi() {
    return Cr || (Cr = 1, (function(t, e) {
      var n = {};
      e.formatArgs = s, e.save = i, e.load = o, e.useColors = r, e.storage = a(), e.destroy = /* @__PURE__ */ (() => {
        let l = false;
        return () => {
          l || (l = 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`."));
        };
      })(), e.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 r() {
        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 l;
        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 && (l = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(l[1], 10) >= 31 || typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
      }
      function s(l) {
        if (l[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + l[0] + (this.useColors ? "%c " : " ") + "+" + t.exports.humanize(this.diff), !this.useColors) return;
        const h = "color: " + this.color;
        l.splice(1, 0, h, "color: inherit");
        let f = 0, u = 0;
        l[0].replace(/%[a-zA-Z%]/g, (d) => {
          d !== "%%" && (f++, d === "%c" && (u = f));
        }), l.splice(u, 0, h);
      }
      e.log = console.debug || console.log || (() => {
      });
      function i(l) {
        try {
          l ? e.storage.setItem("debug", l) : e.storage.removeItem("debug");
        } catch {
        }
      }
      function o() {
        let l;
        try {
          l = e.storage.getItem("debug") || e.storage.getItem("DEBUG");
        } catch {
        }
        return !l && typeof process < "u" && "env" in process && (l = n.DEBUG), l;
      }
      function a() {
        try {
          return localStorage;
        } catch {
        }
      }
      t.exports = Yi()(e);
      const { formatters: c } = t.exports;
      c.j = function(l) {
        try {
          return JSON.stringify(l);
        } catch (h) {
          return "[UnexpectedJSONParseError]: " + h.message;
        }
      };
    })(Et, Et.exports)), Et.exports;
  }
  var Qi = Zi();
  Xn = Wn(Qi);
  var ln = {
    exports: {}
  }, kr;
  function eo() {
    return kr || (kr = 1, (function(t) {
      var e = Object.prototype.hasOwnProperty, n = "~";
      function r() {
      }
      Object.create && (r.prototype = /* @__PURE__ */ Object.create(null), new r().__proto__ || (n = false));
      function s(c, l, h) {
        this.fn = c, this.context = l, this.once = h || false;
      }
      function i(c, l, h, f, u) {
        if (typeof h != "function") throw new TypeError("The listener must be a function");
        var d = new s(h, f || c, u), g = n ? n + l : l;
        return c._events[g] ? c._events[g].fn ? c._events[g] = [
          c._events[g],
          d
        ] : c._events[g].push(d) : (c._events[g] = d, c._eventsCount++), c;
      }
      function o(c, l) {
        --c._eventsCount === 0 ? c._events = new r() : delete c._events[l];
      }
      function a() {
        this._events = new r(), this._eventsCount = 0;
      }
      a.prototype.eventNames = function() {
        var l = [], h, f;
        if (this._eventsCount === 0) return l;
        for (f in h = this._events) e.call(h, f) && l.push(n ? f.slice(1) : f);
        return Object.getOwnPropertySymbols ? l.concat(Object.getOwnPropertySymbols(h)) : l;
      }, a.prototype.listeners = function(l) {
        var h = n ? n + l : l, f = this._events[h];
        if (!f) return [];
        if (f.fn) return [
          f.fn
        ];
        for (var u = 0, d = f.length, g = new Array(d); u < d; u++) g[u] = f[u].fn;
        return g;
      }, a.prototype.listenerCount = function(l) {
        var h = n ? n + l : l, f = this._events[h];
        return f ? f.fn ? 1 : f.length : 0;
      }, a.prototype.emit = function(l, h, f, u, d, g) {
        var m = n ? n + l : l;
        if (!this._events[m]) return false;
        var S = this._events[m], M = arguments.length, B, w;
        if (S.fn) {
          switch (S.once && this.removeListener(l, S.fn, void 0, true), M) {
            case 1:
              return S.fn.call(S.context), true;
            case 2:
              return S.fn.call(S.context, h), true;
            case 3:
              return S.fn.call(S.context, h, f), true;
            case 4:
              return S.fn.call(S.context, h, f, u), true;
            case 5:
              return S.fn.call(S.context, h, f, u, d), true;
            case 6:
              return S.fn.call(S.context, h, f, u, d, g), true;
          }
          for (w = 1, B = new Array(M - 1); w < M; w++) B[w - 1] = arguments[w];
          S.fn.apply(S.context, B);
        } else {
          var N = S.length, U;
          for (w = 0; w < N; w++) switch (S[w].once && this.removeListener(l, S[w].fn, void 0, true), M) {
            case 1:
              S[w].fn.call(S[w].context);
              break;
            case 2:
              S[w].fn.call(S[w].context, h);
              break;
            case 3:
              S[w].fn.call(S[w].context, h, f);
              break;
            case 4:
              S[w].fn.call(S[w].context, h, f, u);
              break;
            default:
              if (!B) for (U = 1, B = new Array(M - 1); U < M; U++) B[U - 1] = arguments[U];
              S[w].fn.apply(S[w].context, B);
          }
        }
        return true;
      }, a.prototype.on = function(l, h, f) {
        return i(this, l, h, f, false);
      }, a.prototype.once = function(l, h, f) {
        return i(this, l, h, f, true);
      }, a.prototype.removeListener = function(l, h, f, u) {
        var d = n ? n + l : l;
        if (!this._events[d]) return this;
        if (!h) return o(this, d), this;
        var g = this._events[d];
        if (g.fn) g.fn === h && (!u || g.once) && (!f || g.context === f) && o(this, d);
        else {
          for (var m = 0, S = [], M = g.length; m < M; m++) (g[m].fn !== h || u && !g[m].once || f && g[m].context !== f) && S.push(g[m]);
          S.length ? this._events[d] = S.length === 1 ? S[0] : S : o(this, d);
        }
        return this;
      }, a.prototype.removeAllListeners = function(l) {
        var h;
        return l ? (h = n ? n + l : l, this._events[h] && o(this, h)) : (this._events = new r(), this._eventsCount = 0), this;
      }, a.prototype.off = a.prototype.removeListener, a.prototype.addListener = a.prototype.on, a.prefixed = n, a.EventEmitter = a, t.exports = a;
    })(ln)), ln.exports;
  }
  var to = eo();
  Cs = Wn(to);
  function no() {
    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 ro() {
    const t = no();
    if (t.__xstate__) return t.__xstate__;
  }
  const so = (t) => {
    if (typeof window > "u") return;
    const e = ro();
    e && e.register(t);
  };
  class Or {
    constructor(e) {
      this._process = e, 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(e) {
      const n = {
        value: e,
        next: null
      };
      if (this._current) {
        this._last.next = n, this._last = n;
        return;
      }
      this._current = n, this._last = n, this._active && this.flush();
    }
    flush() {
      for (; this._current; ) {
        const e = this._current;
        this._process(e.value), this._current = e.next;
      }
      this._last = null;
    }
  }
  const ks = ".", io = "", Os = "", oo = "#", ao = "*", Rs = "xstate.init", co = "xstate.error", On = "xstate.stop";
  function fo(t, e) {
    return {
      type: `xstate.after.${t}.${e}`
    };
  }
  function Rn(t, e) {
    return {
      type: `xstate.done.state.${t}`,
      output: e
    };
  }
  function uo(t, e) {
    return {
      type: `xstate.done.actor.${t}`,
      output: e,
      actorId: t
    };
  }
  function Hs(t, e) {
    return {
      type: `xstate.error.actor.${t}`,
      error: e,
      actorId: t
    };
  }
  function Ts(t) {
    return {
      type: Rs,
      input: t
    };
  }
  function Ie(t) {
    setTimeout(() => {
      throw t;
    });
  }
  const lo = typeof Symbol == "function" && Symbol.observable || "@@observable";
  function Us(t, e) {
    const n = Rr(t), r = Rr(e);
    return typeof r == "string" ? typeof n == "string" ? r === n : false : typeof n == "string" ? n in r : Object.keys(n).every((s) => s in r ? Us(n[s], r[s]) : false);
  }
  function Yn(t) {
    if (Ms(t)) return t;
    const e = [];
    let n = "";
    for (let r = 0; r < t.length; r++) {
      switch (t.charCodeAt(r)) {
        case 92:
          n += t[r + 1], r++;
          continue;
        case 46:
          e.push(n), n = "";
          continue;
      }
      n += t[r];
    }
    return e.push(n), e;
  }
  function Rr(t) {
    if (Wo(t)) return t.value;
    if (typeof t != "string") return t;
    const e = Yn(t);
    return ho(e);
  }
  function ho(t) {
    if (t.length === 1) return t[0];
    const e = {};
    let n = e;
    for (let r = 0; r < t.length - 1; r++) if (r === t.length - 2) n[t[r]] = t[r + 1];
    else {
      const s = n;
      n = {}, s[t[r]] = n;
    }
    return e;
  }
  function Hr(t, e) {
    const n = {}, r = Object.keys(t);
    for (let s = 0; s < r.length; s++) {
      const i = r[s];
      n[i] = e(t[i], i, t, s);
    }
    return n;
  }
  function Ds(t) {
    return Ms(t) ? t : [
      t
    ];
  }
  function Ue(t) {
    return t === void 0 ? [] : Ds(t);
  }
  function Hn(t, e, n, r) {
    return typeof t == "function" ? t({
      context: e,
      event: n,
      self: r
    }) : t;
  }
  function Ms(t) {
    return Array.isArray(t);
  }
  function go(t) {
    return t.type.startsWith("xstate.error.actor");
  }
  function Ze(t) {
    return Ds(t).map((e) => typeof e > "u" || typeof e == "string" ? {
      target: e
    } : e);
  }
  function Bs(t) {
    if (!(t === void 0 || t === io)) return Ue(t);
  }
  function Tn(t, e, n) {
    var _a5, _b2, _c2;
    const r = typeof t == "object", s = r ? t : void 0;
    return {
      next: (_a5 = r ? t.next : t) == null ? void 0 : _a5.bind(s),
      error: (_b2 = r ? t.error : e) == null ? void 0 : _b2.bind(s),
      complete: (_c2 = r ? t.complete : n) == null ? void 0 : _c2.bind(s)
    };
  }
  function Tr(t, e) {
    return `${e}.${t}`;
  }
  function Zn(t, e) {
    const n = e.match(/^xstate\.invoke\.(\d+)\.(.*)/);
    if (!n) return t.implementations.actors[e];
    const [, r, s] = n, o = t.getStateNodeById(s).config.invoke;
    return (Array.isArray(o) ? o[r] : o).src;
  }
  function js(t, e) {
    if (e === t || e === ao) return true;
    if (!e.endsWith(".*")) return false;
    const n = e.split("."), r = t.split(".");
    for (let s = 0; s < n.length; s++) {
      const i = n[s], o = r[s];
      if (i === "*") return s === n.length - 1;
      if (i !== o) return false;
    }
    return true;
  }
  function Ur(t, e) {
    return `${t.sessionId}.${e}`;
  }
  let _o = 0;
  function po(t, e) {
    const n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new Set(), o = {}, { clock: a, logger: c } = e, l = {
      schedule: (u, d, g, m, S = Math.random().toString(36).slice(2)) => {
        const M = {
          source: u,
          target: d,
          event: g,
          delay: m,
          id: S,
          startedAt: Date.now()
        }, B = Ur(u, S);
        f._snapshot._scheduledEvents[B] = M;
        const w = a.setTimeout(() => {
          delete o[B], delete f._snapshot._scheduledEvents[B], f._relay(u, d, g);
        }, m);
        o[B] = w;
      },
      cancel: (u, d) => {
        const g = Ur(u, d), m = o[g];
        delete o[g], delete f._snapshot._scheduledEvents[g], m !== void 0 && a.clearTimeout(m);
      },
      cancelAll: (u) => {
        for (const d in f._snapshot._scheduledEvents) {
          const g = f._snapshot._scheduledEvents[d];
          g.source === u && l.cancel(u, g.id);
        }
      }
    }, h = (u) => {
      if (!i.size) return;
      const d = {
        ...u,
        rootId: t.sessionId
      };
      i.forEach((g) => {
        var _a5;
        return (_a5 = g.next) == null ? void 0 : _a5.call(g, d);
      });
    }, f = {
      _snapshot: {
        _scheduledEvents: ((e == null ? void 0 : e.snapshot) && e.snapshot.scheduler) ?? {}
      },
      _bookId: () => `x:${_o++}`,
      _register: (u, d) => (n.set(u, d), u),
      _unregister: (u) => {
        n.delete(u.sessionId);
        const d = s.get(u);
        d !== void 0 && (r.delete(d), s.delete(u));
      },
      get: (u) => r.get(u),
      getAll: () => Object.fromEntries(r.entries()),
      _set: (u, d) => {
        const g = r.get(u);
        if (g && g !== d) throw new Error(`Actor with system ID '${u}' already exists.`);
        r.set(u, d), s.set(d, u);
      },
      inspect: (u) => {
        const d = Tn(u);
        return i.add(d), {
          unsubscribe() {
            i.delete(d);
          }
        };
      },
      _sendInspectionEvent: h,
      _relay: (u, d, g) => {
        f._sendInspectionEvent({
          type: "@xstate.event",
          sourceRef: u,
          actorRef: d,
          event: g
        }), d._send(g);
      },
      scheduler: l,
      getSnapshot: () => ({
        _scheduledEvents: {
          ...f._snapshot._scheduledEvents
        }
      }),
      start: () => {
        const u = f._snapshot._scheduledEvents;
        f._snapshot._scheduledEvents = {};
        for (const d in u) {
          const { source: g, target: m, event: S, delay: M, id: B } = u[d];
          l.schedule(g, m, S, M, B);
        }
      },
      _clock: a,
      _logger: c
    };
    return f;
  }
  let dn = false;
  const Qn = 1;
  let ue = (function(t) {
    return t[t.NotStarted = 0] = "NotStarted", t[t.Running = 1] = "Running", t[t.Stopped = 2] = "Stopped", t;
  })({});
  const yo = {
    clock: {
      setTimeout: (t, e) => setTimeout(t, e),
      clearTimeout: (t) => clearTimeout(t)
    },
    logger: console.log.bind(console),
    devTools: false
  };
  class bo {
    constructor(e, n) {
      this.logic = e, this._snapshot = void 0, this.clock = void 0, this.options = void 0, this.id = void 0, this.mailbox = new Or(this._process.bind(this)), this.observers = /* @__PURE__ */ new Set(), this.eventListeners = /* @__PURE__ */ new Map(), this.logger = void 0, this._processingStatus = ue.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 = {
        ...yo,
        ...n
      }, { clock: s, logger: i, parent: o, syncSnapshot: a, id: c, systemId: l, inspect: h } = r;
      this.system = o ? o.system : po(this, {
        clock: s,
        logger: i
      }), h && !o && this.system.inspect(Tn(h)), this.sessionId = this.system._bookId(), this.id = c ?? this.sessionId, this.logger = (n == null ? void 0 : n.logger) ?? this.system._logger, this.clock = (n == null ? void 0 : n.clock) ?? this.system._clock, this._parent = o, this._syncSnapshot = a, this.options = r, this.src = r.src ?? e, this.ref = this, this._actorScope = {
        self: this,
        id: this.id,
        sessionId: this.sessionId,
        logger: this.logger,
        defer: (f) => {
          this._deferred.push(f);
        },
        system: this.system,
        stopChild: (f) => {
          if (f._parent !== this) throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);
          f._stop();
        },
        emit: (f) => {
          const u = this.eventListeners.get(f.type), d = this.eventListeners.get("*");
          if (!u && !d) return;
          const g = [
            ...u ? u.values() : [],
            ...d ? d.values() : []
          ];
          for (const m of g) try {
            m(f);
          } catch (S) {
            Ie(S);
          }
        },
        actionExecutor: (f) => {
          const u = () => {
            if (this._actorScope.system._sendInspectionEvent({
              type: "@xstate.action",
              actorRef: this,
              action: {
                type: f.type,
                params: f.params
              }
            }), !f.exec) return;
            const d = dn;
            try {
              dn = true, f.exec(f.info, f.params);
            } finally {
              dn = d;
            }
          };
          this._processingStatus === ue.Running ? u() : this._deferred.push(u);
        }
      }, this.send = this.send.bind(this), this.system._sendInspectionEvent({
        type: "@xstate.actor",
        actorRef: this
      }), l && (this.systemId = l, this.system._set(l, this)), this._initState((n == null ? void 0 : n.snapshot) ?? (n == null ? void 0 : n.state)), l && this._snapshot.status !== "active" && this.system._unregister(this);
    }
    _initState(e) {
      var _a5;
      try {
        this._snapshot = e ? this.logic.restoreSnapshot ? this.logic.restoreSnapshot(e, this._actorScope) : e : this.logic.getInitialSnapshot(this._actorScope, (_a5 = this.options) == null ? void 0 : _a5.input);
      } catch (n) {
        this._snapshot = {
          status: "error",
          output: void 0,
          error: n
        };
      }
    }
    update(e, n) {
      var _a5, _b2;
      this._snapshot = e;
      let r;
      for (; r = this._deferred.shift(); ) try {
        r();
      } catch (s) {
        this._deferred.length = 0, this._snapshot = {
          ...e,
          status: "error",
          error: s
        };
      }
      switch (this._snapshot.status) {
        case "active":
          for (const s of this.observers) try {
            (_a5 = s.next) == null ? void 0 : _a5.call(s, e);
          } catch (i) {
            Ie(i);
          }
          break;
        case "done":
          for (const s of this.observers) try {
            (_b2 = s.next) == null ? void 0 : _b2.call(s, e);
          } catch (i) {
            Ie(i);
          }
          this._stopProcedure(), this._complete(), this._doneEvent = uo(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: n,
        snapshot: e
      });
    }
    subscribe(e, n, r) {
      var _a5;
      const s = Tn(e, n, r);
      if (this._processingStatus !== ue.Stopped) this.observers.add(s);
      else switch (this._snapshot.status) {
        case "done":
          try {
            (_a5 = s.complete) == null ? void 0 : _a5.call(s);
          } catch (i) {
            Ie(i);
          }
          break;
        case "error": {
          const i = this._snapshot.error;
          if (!s.error) Ie(i);
          else try {
            s.error(i);
          } catch (o) {
            Ie(o);
          }
          break;
        }
      }
      return {
        unsubscribe: () => {
          this.observers.delete(s);
        }
      };
    }
    on(e, n) {
      let r = this.eventListeners.get(e);
      r || (r = /* @__PURE__ */ new Set(), this.eventListeners.set(e, r));
      const s = n.bind(void 0);
      return r.add(s), {
        unsubscribe: () => {
          r.delete(s);
        }
      };
    }
    start() {
      if (this._processingStatus === ue.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 = ue.Running;
      const e = Ts(this.options.input);
      switch (this.system._sendInspectionEvent({
        type: "@xstate.event",
        sourceRef: this._parent,
        actorRef: this,
        event: e
      }), this._snapshot.status) {
        case "done":
          return this.update(this._snapshot, e), 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, e), this.options.devTools && this.attachDevTools(), this.mailbox.start(), this;
    }
    _process(e) {
      let n, r;
      try {
        n = this.logic.transition(this._snapshot, e, 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(n, e), e.type === On && (this._stopProcedure(), this._complete());
    }
    _stop() {
      return this._processingStatus === ue.Stopped ? this : (this.mailbox.clear(), this._processingStatus === ue.NotStarted ? (this._processingStatus = ue.Stopped, this) : (this.mailbox.enqueue({
        type: On
      }), this));
    }
    stop() {
      if (this._parent) throw new Error("A non-root actor cannot be stopped directly.");
      return this._stop();
    }
    _complete() {
      var _a5;
      for (const e of this.observers) try {
        (_a5 = e.complete) == null ? void 0 : _a5.call(e);
      } catch (n) {
        Ie(n);
      }
      this.observers.clear(), this.eventListeners.clear();
    }
    _reportError(e) {
      if (!this.observers.size) {
        this._parent || Ie(e), this.eventListeners.clear();
        return;
      }
      let n = false;
      for (const r of this.observers) {
        const s = r.error;
        n || (n = !s);
        try {
          s == null ? void 0 : s(e);
        } catch (i) {
          Ie(i);
        }
      }
      this.observers.clear(), this.eventListeners.clear(), n && Ie(e);
    }
    _error(e) {
      this._stopProcedure(), this._reportError(e), this._parent && this.system._relay(this, this._parent, Hs(this.id, e));
    }
    _stopProcedure() {
      return this._processingStatus !== ue.Running ? this : (this.system.scheduler.cancelAll(this), this.mailbox.clear(), this.mailbox = new Or(this._process.bind(this)), this._processingStatus = ue.Stopped, this.system._unregister(this), this);
    }
    _send(e) {
      this._processingStatus !== ue.Stopped && this.mailbox.enqueue(e);
    }
    send(e) {
      this.system._relay(void 0, this, e);
    }
    attachDevTools() {
      const { devTools: e } = this.options;
      e && (typeof e == "function" ? e : so)(this);
    }
    toJSON() {
      return {
        xstate$$type: Qn,
        id: this.id
      };
    }
    getPersistedSnapshot(e) {
      return this.logic.getPersistedSnapshot(this._snapshot, e);
    }
    [lo]() {
      return this;
    }
    getSnapshot() {
      return this._snapshot;
    }
  }
  function _t(t, ...[e]) {
    return new bo(t, e);
  }
  function mo(t, e, n, r, { sendId: s }) {
    const i = typeof s == "function" ? s(n, r) : s;
    return [
      e,
      {
        sendId: i
      },
      void 0
    ];
  }
  function wo(t, e) {
    t.defer(() => {
      t.system.scheduler.cancel(t.self, e.sendId);
    });
  }
  function er(t) {
    function e(n, r) {
    }
    return e.type = "xstate.cancel", e.sendId = t, e.resolve = mo, e.execute = wo, e;
  }
  function xo(t, e, n, r, { id: s, systemId: i, src: o, input: a, syncSnapshot: c }) {
    const l = typeof o == "string" ? Zn(e.machine, o) : o, h = typeof s == "function" ? s(n) : s;
    let f, u;
    return l && (u = typeof a == "function" ? a({
      context: e.context,
      event: n.event,
      self: t.self
    }) : a, f = _t(l, {
      id: h,
      src: o,
      parent: t.self,
      syncSnapshot: c,
      systemId: i,
      input: u
    })), [
      Ne(e, {
        children: {
          ...e.children,
          [h]: f
        }
      }),
      {
        id: s,
        systemId: i,
        actorRef: f,
        src: o,
        input: u
      },
      void 0
    ];
  }
  function So(t, { actorRef: e }) {
    e && t.defer(() => {
      e._processingStatus !== ue.Stopped && e.start();
    });
  }
  function tr(...[t, { id: e, systemId: n, input: r, syncSnapshot: s = false } = {}]) {
    function i(o, a) {
    }
    return i.type = "xstate.spawnChild", i.id = e, i.systemId = n, i.src = t, i.input = r, i.syncSnapshot = s, i.resolve = xo, i.execute = So, i;
  }
  function vo(t, e, n, r, { actorRef: s }) {
    const i = typeof s == "function" ? s(n, r) : s, o = typeof i == "string" ? e.children[i] : i;
    let a = e.children;
    return o && (a = {
      ...a
    }, delete a[o.id]), [
      Ne(e, {
        children: a
      }),
      o,
      void 0
    ];
  }
  function Ls(t, e) {
    const n = e.getSnapshot();
    if (n && "children" in n) for (const r of Object.values(n.children)) Ls(t, r);
    t.system._unregister(e);
  }
  function Ao(t, e) {
    if (e) {
      if (Ls(t, e), e._processingStatus !== ue.Running) {
        t.stopChild(e);
        return;
      }
      t.defer(() => {
        t.stopChild(e);
      });
    }
  }
  function en(t) {
    function e(n, r) {
    }
    return e.type = "xstate.stopChild", e.actorRef = t, e.resolve = vo, e.execute = Ao, e;
  }
  function tn(t, e, n, r) {
    const { machine: s } = r, i = typeof t == "function", o = i ? t : s.implementations.guards[typeof t == "string" ? t : t.type];
    if (!i && !o) throw new Error(`Guard '${typeof t == "string" ? t : t.type}' is not implemented.'.`);
    if (typeof o != "function") return tn(o, e, n, r);
    const a = {
      context: e,
      event: n
    }, c = i || typeof t == "string" ? void 0 : "params" in t ? typeof t.params == "function" ? t.params({
      context: e,
      event: n
    }) : t.params : void 0;
    return "check" in o ? o.check(r, a, o) : o(a, c);
  }
  function nr(t) {
    return t.type === "atomic" || t.type === "final";
  }
  function nt(t) {
    return Object.values(t.states).filter((e) => e.type !== "history");
  }
  function xt(t, e) {
    const n = [];
    if (e === t) return n;
    let r = t.parent;
    for (; r && r !== e; ) n.push(r), r = r.parent;
    return n;
  }
  function Vt(t) {
    const e = new Set(t), n = Ps(e);
    for (const r of e) if (r.type === "compound" && (!n.get(r) || !n.get(r).length)) Dr(r).forEach((s) => e.add(s));
    else if (r.type === "parallel") {
      for (const s of nt(r)) if (s.type !== "history" && !e.has(s)) {
        const i = Dr(s);
        for (const o of i) e.add(o);
      }
    }
    for (const r of e) {
      let s = r.parent;
      for (; s; ) e.add(s), s = s.parent;
    }
    return e;
  }
  function Fs(t, e) {
    const n = e.get(t);
    if (!n) return {};
    if (t.type === "compound") {
      const s = n[0];
      if (s) {
        if (nr(s)) return s.key;
      } else return {};
    }
    const r = {};
    for (const s of n) r[s.key] = Fs(s, e);
    return r;
  }
  function Ps(t) {
    const e = /* @__PURE__ */ new Map();
    for (const n of t) e.has(n) || e.set(n, []), n.parent && (e.has(n.parent) || e.set(n.parent, []), e.get(n.parent).push(n));
    return e;
  }
  function $s(t, e) {
    const n = Vt(e);
    return Fs(t, Ps(n));
  }
  function rr(t, e) {
    return e.type === "compound" ? nt(e).some((n) => n.type === "final" && t.has(n)) : e.type === "parallel" ? nt(e).every((n) => rr(t, n)) : e.type === "final";
  }
  const nn = (t) => t[0] === oo;
  function Eo(t, e) {
    return t.transitions.get(e) || [
      ...t.transitions.keys()
    ].filter((r) => js(e, r)).sort((r, s) => s.length - r.length).flatMap((r) => t.transitions.get(r));
  }
  function Io(t) {
    const e = t.config.after;
    if (!e) return [];
    const n = (s) => {
      const i = fo(s, t.id), o = i.type;
      return t.entry.push(or(i, {
        id: o,
        delay: s
      })), t.exit.push(er(o)), o;
    };
    return Object.keys(e).flatMap((s) => {
      const i = e[s], o = typeof i == "string" ? {
        target: i
      } : i, a = Number.isNaN(+s) ? s : +s, c = n(a);
      return Ue(o).map((l) => ({
        ...l,
        event: c,
        delay: a
      }));
    }).map((s) => {
      const { delay: i } = s;
      return {
        ...je(t, s.event, s),
        delay: i
      };
    });
  }
  function je(t, e, n) {
    const r = Bs(n.target), s = n.reenter ?? false, i = Ro(t, r), o = {
      ...n,
      actions: Ue(n.actions),
      guard: n.guard,
      target: i,
      source: t,
      reenter: s,
      eventType: e,
      toJSON: () => ({
        ...o,
        source: `#${t.id}`,
        target: i ? i.map((a) => `#${a.id}`) : void 0
      })
    };
    return o;
  }
  function Co(t) {
    const e = /* @__PURE__ */ new Map();
    if (t.config.on) for (const n of Object.keys(t.config.on)) {
      if (n === Os) throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');
      const r = t.config.on[n];
      e.set(n, Ze(r).map((s) => je(t, n, s)));
    }
    if (t.config.onDone) {
      const n = `xstate.done.state.${t.id}`;
      e.set(n, Ze(t.config.onDone).map((r) => je(t, n, r)));
    }
    for (const n of t.invoke) {
      if (n.onDone) {
        const r = `xstate.done.actor.${n.id}`;
        e.set(r, Ze(n.onDone).map((s) => je(t, r, s)));
      }
      if (n.onError) {
        const r = `xstate.error.actor.${n.id}`;
        e.set(r, Ze(n.onError).map((s) => je(t, r, s)));
      }
      if (n.onSnapshot) {
        const r = `xstate.snapshot.${n.id}`;
        e.set(r, Ze(n.onSnapshot).map((s) => je(t, r, s)));
      }
    }
    for (const n of t.after) {
      let r = e.get(n.eventType);
      r || (r = [], e.set(n.eventType, r)), r.push(n);
    }
    return e;
  }
  function ko(t) {
    const e = [], n = (r) => {
      Object.values(r).forEach((s) => {
        if (s.config.route && s.config.id) {
          const i = s.config.id, o = s.config.route.guard, a = (l, h) => l.event.to !== `#${i}` ? false : o && typeof o == "function" ? o(l, h) : true, c = {
            ...s.config.route,
            guard: a,
            target: `#${i}`
          };
          e.push(je(t, "xstate.route", c));
        }
        s.states && n(s.states);
      });
    };
    n(t.states), e.length > 0 && t.transitions.set("xstate.route", e);
  }
  function Oo(t, e) {
    const n = typeof e == "string" ? t.states[e] : e ? t.states[e.target] : void 0;
    if (!n && e) throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);
    const r = {
      source: t,
      actions: !e || typeof e == "string" ? [] : Ue(e.actions),
      eventType: null,
      reenter: false,
      target: n ? [
        n
      ] : [],
      toJSON: () => ({
        ...r,
        source: `#${t.id}`,
        target: n ? [
          `#${n.id}`
        ] : []
      })
    };
    return r;
  }
  function Ro(t, e) {
    if (e !== void 0) return e.map((n) => {
      if (typeof n != "string") return n;
      if (nn(n)) return t.machine.getStateNodeById(n);
      const r = n[0] === ks;
      if (r && !t.parent) return zt(t, n.slice(1));
      const s = r ? t.key + n : n;
      if (t.parent) try {
        return zt(t.parent, s);
      } catch (i) {
        throw new Error(`Invalid transition definition for state node '${t.id}':
${i.message}`);
      }
      else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);
    });
  }
  function Vs(t) {
    const e = Bs(t.config.target);
    return e ? {
      target: e.map((n) => typeof n == "string" ? zt(t.parent, n) : n)
    } : t.parent.initial;
  }
  function $e(t) {
    return t.type === "history";
  }
  function Dr(t) {
    const e = zs(t);
    for (const n of e) for (const r of xt(n, t)) e.add(r);
    return e;
  }
  function zs(t) {
    const e = /* @__PURE__ */ new Set();
    function n(r) {
      if (!e.has(r)) {
        if (e.add(r), r.type === "compound") n(r.initial.target[0]);
        else if (r.type === "parallel") for (const s of nt(r)) n(s);
      }
    }
    return n(t), e;
  }
  function rt(t, e) {
    if (nn(e)) return t.machine.getStateNodeById(e);
    if (!t.states) throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);
    const n = t.states[e];
    if (!n) throw new Error(`Child state '${e}' does not exist on '${t.id}'`);
    return n;
  }
  function zt(t, e) {
    if (typeof e == "string" && nn(e)) try {
      return t.machine.getStateNodeById(e);
    } catch {
    }
    const n = Yn(e).slice();
    let r = t;
    for (; n.length; ) {
      const s = n.shift();
      if (!s.length) break;
      r = rt(r, s);
    }
    return r;
  }
  function Nt(t, e) {
    if (typeof e == "string") {
      const s = t.states[e];
      if (!s) throw new Error(`State '${e}' does not exist on '${t.id}'`);
      return [
        t,
        s
      ];
    }
    const n = Object.keys(e), r = n.map((s) => rt(t, s)).filter(Boolean);
    return [
      t.machine.root,
      t
    ].concat(r, n.reduce((s, i) => {
      const o = rt(t, i);
      if (!o) return s;
      const a = Nt(o, e[i]);
      return s.concat(a);
    }, []));
  }
  function Ho(t, e, n, r) {
    const i = rt(t, e).next(n, r);
    return !i || !i.length ? t.next(n, r) : i;
  }
  function To(t, e, n, r) {
    const s = Object.keys(e), i = rt(t, s[0]), o = sr(i, e[s[0]], n, r);
    return !o || !o.length ? t.next(n, r) : o;
  }
  function Uo(t, e, n, r) {
    const s = [];
    for (const i of Object.keys(e)) {
      const o = e[i];
      if (!o) continue;
      const a = rt(t, i), c = sr(a, o, n, r);
      c && s.push(...c);
    }
    return s.length ? s : t.next(n, r);
  }
  function sr(t, e, n, r) {
    return typeof e == "string" ? Ho(t, e, n, r) : Object.keys(e).length === 1 ? To(t, e, n, r) : Uo(t, e, n, r);
  }
  function Do(t) {
    return Object.keys(t.states).map((e) => t.states[e]).filter((e) => e.type === "history");
  }
  function Le(t, e) {
    let n = t;
    for (; n.parent && n.parent !== e; ) n = n.parent;
    return n.parent === e;
  }
  function Mo(t, e) {
    const n = new Set(t), r = new Set(e);
    for (const s of n) if (r.has(s)) return true;
    for (const s of r) if (n.has(s)) return true;
    return false;
  }
  function Ns(t, e, n) {
    const r = /* @__PURE__ */ new Set();
    for (const s of t) {
      let i = false;
      const o = /* @__PURE__ */ new Set();
      for (const a of r) if (Mo(Un([
        s
      ], e, n), Un([
        a
      ], e, n))) if (Le(s.source, a.source)) o.add(a);
      else {
        i = true;
        break;
      }
      if (!i) {
        for (const a of o) r.delete(a);
        r.add(s);
      }
    }
    return Array.from(r);
  }
  function Bo(t) {
    const [e, ...n] = t;
    for (const r of xt(e, void 0)) if (n.every((s) => Le(s, r))) return r;
  }
  function ir(t, e) {
    if (!t.target) return [];
    const n = /* @__PURE__ */ new Set();
    for (const r of t.target) if ($e(r)) if (e[r.id]) for (const s of e[r.id]) n.add(s);
    else for (const s of ir(Vs(r), e)) n.add(s);
    else n.add(r);
    return [
      ...n
    ];
  }
  function qs(t, e) {
    const n = ir(t, e);
    if (!n) return;
    if (!t.reenter && n.every((s) => s === t.source || Le(s, t.source))) return t.source;
    const r = Bo(n.concat(t.source));
    if (r) return r;
    if (!t.reenter) return t.source.machine.root;
  }
  function Un(t, e, n) {
    var _a5;
    const r = /* @__PURE__ */ new Set();
    for (const s of t) if ((_a5 = s.target) == null ? void 0 : _a5.length) {
      const i = qs(s, n);
      s.reenter && s.source === i && r.add(i);
      for (const o of e) Le(o, i) && r.add(o);
    }
    return [
      ...r
    ];
  }
  function jo(t, e) {
    if (t.length !== e.size) return false;
    for (const n of t) if (!e.has(n)) return false;
    return true;
  }
  function Lo(t, e, n, r, s) {
    return Dn([
      {
        target: [
          ...zs(t)
        ],
        source: t,
        reenter: true,
        actions: [],
        eventType: null,
        toJSON: null
      }
    ], e, n, r, true, s);
  }
  function Dn(t, e, n, r, s, i) {
    const o = [];
    if (!t.length) return [
      e,
      o
    ];
    const a = n.actionExecutor;
    n.actionExecutor = (c) => {
      o.push(c), a(c);
    };
    try {
      const c = new Set(e._nodes);
      let l = e.historyValue;
      const h = Ns(t, c, l);
      let f = e;
      s || ([f, l] = Vo(f, r, n, h, c, l, i, n.actionExecutor)), f = st(f, r, n, h.flatMap((d) => d.actions), i, void 0), f = Po(f, r, n, h, c, i, l, s);
      const u = [
        ...c
      ];
      f.status === "done" && (f = st(f, r, n, u.sort((d, g) => g.order - d.order).flatMap((d) => d.exit), i, void 0));
      try {
        return l === e.historyValue && jo(e._nodes, c) ? [
          f,
          o
        ] : [
          Ne(f, {
            _nodes: u,
            historyValue: l
          }),
          o
        ];
      } catch (d) {
        throw d;
      }
    } finally {
      n.actionExecutor = a;
    }
  }
  function Fo(t, e, n, r, s) {
    if (r.output === void 0) return;
    const i = Rn(s.id, s.output !== void 0 && s.parent ? Hn(s.output, t.context, e, n.self) : void 0);
    return Hn(r.output, t.context, i, n.self);
  }
  function Po(t, e, n, r, s, i, o, a) {
    let c = t;
    const l = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set();
    $o(r, o, h, l), a && h.add(t.machine.root);
    const f = /* @__PURE__ */ new Set();
    for (const u of [
      ...l
    ].sort((d, g) => d.order - g.order)) {
      s.add(u);
      const d = [];
      d.push(...u.entry);
      for (const g of u.invoke) d.push(tr(g.src, {
        ...g,
        syncSnapshot: !!g.onSnapshot
      }));
      if (h.has(u)) {
        const g = u.initial.actions;
        d.push(...g);
      }
      if (c = st(c, e, n, d, i, u.invoke.map((g) => g.id)), u.type === "final") {
        const g = u.parent;
        let m = (g == null ? void 0 : g.type) === "parallel" ? g : g == null ? void 0 : g.parent, S = m || u;
        for ((g == null ? void 0 : g.type) === "compound" && i.push(Rn(g.id, u.output !== void 0 ? Hn(u.output, c.context, e, n.self) : void 0)); (m == null ? void 0 : m.type) === "parallel" && !f.has(m) && rr(s, m); ) f.add(m), i.push(Rn(m.id)), S = m, m = m.parent;
        if (m) continue;
        c = Ne(c, {
          status: "done",
          output: Fo(c, e, n, c.machine.root, S)
        });
      }
    }
    return c;
  }
  function $o(t, e, n, r) {
    for (const s of t) {
      const i = qs(s, e);
      for (const a of s.target || []) !$e(a) && (s.source !== a || s.source !== i || s.reenter) && (r.add(a), n.add(a)), et(a, e, n, r);
      const o = ir(s, e);
      for (const a of o) {
        const c = xt(a, i);
        (i == null ? void 0 : i.type) === "parallel" && c.push(i), Ws(r, e, n, c, !s.source.parent && s.reenter ? void 0 : i);
      }
    }
  }
  function et(t, e, n, r) {
    var _a5;
    if ($e(t)) if (e[t.id]) {
      const s = e[t.id];
      for (const i of s) r.add(i), et(i, e, n, r);
      for (const i of s) hn(i, t.parent, r, e, n);
    } else {
      const s = Vs(t);
      for (const i of s.target) r.add(i), s === ((_a5 = t.parent) == null ? void 0 : _a5.initial) && n.add(t.parent), et(i, e, n, r);
      for (const i of s.target) hn(i, t.parent, r, e, n);
    }
    else if (t.type === "compound") {
      const [s] = t.initial.target;
      $e(s) || (r.add(s), n.add(s)), et(s, e, n, r), hn(s, t, r, e, n);
    } else if (t.type === "parallel") for (const s of nt(t).filter((i) => !$e(i))) [
      ...r
    ].some((i) => Le(i, s)) || ($e(s) || (r.add(s), n.add(s)), et(s, e, n, r));
  }
  function Ws(t, e, n, r, s) {
    for (const i of r) if ((!s || Le(i, s)) && t.add(i), i.type === "parallel") for (const o of nt(i).filter((a) => !$e(a))) [
      ...t
    ].some((a) => Le(a, o)) || (t.add(o), et(o, e, n, t));
  }
  function hn(t, e, n, r, s) {
    Ws(n, r, s, xt(t, e));
  }
  function Vo(t, e, n, r, s, i, o, a) {
    let c = t;
    const l = Un(r, s, i);
    l.sort((f, u) => u.order - f.order);
    let h;
    for (const f of l) for (const u of Do(f)) {
      let d;
      u.history === "deep" ? d = (g) => nr(g) && Le(g, f) : d = (g) => g.parent === f, h ?? (h = {
        ...i
      }), h[u.id] = Array.from(s).filter(d);
    }
    for (const f of l) c = st(c, e, n, [
      ...f.exit,
      ...f.invoke.map((u) => en(u.id))
    ], o, void 0), s.delete(f);
    return [
      c,
      h || i
    ];
  }
  function zo(t, e) {
    return t.implementations.actions[e];
  }
  function Gs(t, e, n, r, s, i) {
    const { machine: o } = t;
    let a = t;
    for (const c of r) {
      const l = typeof c == "function", h = l ? c : zo(o, typeof c == "string" ? c : c.type), f = {
        context: a.context,
        event: e,
        self: n.self,
        system: n.system
      }, u = l || typeof c == "string" ? void 0 : "params" in c ? typeof c.params == "function" ? c.params({
        context: a.context,
        event: e
      }) : c.params : void 0;
      if (!h || !("resolve" in h)) {
        n.actionExecutor({
          type: typeof c == "string" ? c : typeof c == "object" ? c.type : c.name || "(anonymous)",
          info: f,
          params: u,
          exec: h
        });
        continue;
      }
      const d = h, [g, m, S] = d.resolve(n, a, f, u, h, s);
      a = g, "retryResolve" in d && (i == null ? void 0 : i.push([
        d,
        m
      ])), "execute" in d && n.actionExecutor({
        type: d.type,
        info: f,
        params: m,
        exec: d.execute.bind(null, n, m)
      }), S && (a = Gs(a, e, n, S, s, i));
    }
    return a;
  }
  function st(t, e, n, r, s, i) {
    const o = i ? [] : void 0, a = Gs(t, e, n, r, {
      internalQueue: s,
      deferredActorIds: i
    }, o);
    return o == null ? void 0 : o.forEach(([c, l]) => {
      c.retryResolve(n, a, l);
    }), a;
  }
  function gn(t, e, n, r) {
    let s = t;
    const i = [];
    function o(l, h, f) {
      n.system._sendInspectionEvent({
        type: "@xstate.microstep",
        actorRef: n.self,
        event: h,
        snapshot: l[0],
        _transitions: f
      }), i.push(l);
    }
    if (e.type === On) return s = Ne(Mr(s, e, n), {
      status: "stopped"
    }), o([
      s,
      []
    ], e, []), {
      snapshot: s,
      microsteps: i
    };
    let a = e;
    if (a.type !== Rs) {
      const l = a, h = go(l), f = Br(l, s);
      if (h && !f.length) return s = Ne(t, {
        status: "error",
        error: l.error
      }), o([
        s,
        []
      ], l, []), {
        snapshot: s,
        microsteps: i
      };
      const u = Dn(f, t, n, a, false, r);
      s = u[0], o(u, l, f);
    }
    let c = true;
    for (; s.status === "active"; ) {
      let l = c ? No(s, a) : [];
      const h = l.length ? s : void 0;
      if (!l.length) {
        if (!r.length) break;
        a = r.shift(), l = Br(a, s);
      }
      const f = Dn(l, s, n, a, false, r);
      s = f[0], c = s !== h, o(f, a, l);
    }
    return s.status !== "active" && Mr(s, a, n), {
      snapshot: s,
      microsteps: i
    };
  }
  function Mr(t, e, n) {
    return st(t, e, n, Object.values(t.children).map((r) => en(r)), [], void 0);
  }
  function Br(t, e) {
    return e.machine.getTransitionData(e, t);
  }
  function No(t, e) {
    const n = /* @__PURE__ */ new Set(), r = t._nodes.filter(nr);
    for (const s of r) e: for (const i of [
      s
    ].concat(xt(s, void 0))) if (i.always) {
      for (const o of i.always) if (o.guard === void 0 || tn(o.guard, t.context, e, t)) {
        n.add(o);
        break e;
      }
    }
    return Ns(Array.from(n), new Set(t._nodes), t.historyValue);
  }
  function qo(t, e) {
    const n = Vt(Nt(t, e));
    return $s(t, [
      ...n
    ]);
  }
  function Wo(t) {
    return !!t && typeof t == "object" && "machine" in t && "value" in t;
  }
  const Go = function(e) {
    return Us(e, this.value);
  }, Ko = function(e) {
    return this.tags.has(e);
  }, Jo = function(e) {
    const n = this.machine.getTransitionData(this, e);
    return !!(n == null ? void 0 : n.length) && n.some((r) => r.target !== void 0 || r.actions.length);
  }, Xo = function() {
    const { _nodes: e, tags: n, machine: r, getMeta: s, toJSON: i, can: o, hasTag: a, matches: c, ...l } = this;
    return {
      ...l,
      tags: Array.from(n)
    };
  }, Yo = function() {
    return this._nodes.reduce((e, n) => (n.meta !== void 0 && (e[n.id] = n.meta), e), {});
  };
  function Dt(t, e) {
    return {
      status: t.status,
      output: t.output,
      error: t.error,
      machine: e,
      context: t.context,
      _nodes: t._nodes,
      value: $s(e.root, t._nodes),
      tags: new Set(t._nodes.flatMap((n) => n.tags)),
      children: t.children,
      historyValue: t.historyValue || {},
      matches: Go,
      hasTag: Ko,
      can: Jo,
      getMeta: Yo,
      toJSON: Xo
    };
  }
  function Ne(t, e = {}) {
    return Dt({
      ...t,
      ...e
    }, t.machine);
  }
  function Zo(t) {
    if (typeof t != "object" || t === null) return {};
    const e = {};
    for (const n in t) {
      const r = t[n];
      Array.isArray(r) && (e[n] = r.map((s) => ({
        id: s.id
      })));
    }
    return e;
  }
  function Qo(t, e) {
    const { _nodes: n, tags: r, machine: s, children: i, context: o, can: a, hasTag: c, matches: l, getMeta: h, toJSON: f, ...u } = t, d = {};
    for (const m in i) {
      const S = i[m];
      d[m] = {
        snapshot: S.getPersistedSnapshot(e),
        src: S.src,
        systemId: S.systemId,
        syncSnapshot: S._syncSnapshot
      };
    }
    return {
      ...u,
      context: Ks(o),
      children: d,
      historyValue: Zo(u.historyValue)
    };
  }
  function Ks(t) {
    let e;
    for (const n in t) {
      const r = t[n];
      if (r && typeof r == "object") if ("sessionId" in r && "send" in r && "ref" in r) e ?? (e = Array.isArray(t) ? t.slice() : {
        ...t
      }), e[n] = {
        xstate$$type: Qn,
        id: r.id
      };
      else {
        const s = Ks(r);
        s !== r && (e ?? (e = Array.isArray(t) ? t.slice() : {
          ...t
        }), e[n] = s);
      }
    }
    return e ?? t;
  }
  function ea(t, e, n, r, { event: s, id: i, delay: o }, { internalQueue: a }) {
    const c = e.machine.implementations.delays;
    if (typeof s == "string") throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);
    const l = typeof s == "function" ? s(n, r) : s;
    let h;
    if (typeof o == "string") {
      const f = c && c[o];
      h = typeof f == "function" ? f(n, r) : f;
    } else h = typeof o == "function" ? o(n, r) : o;
    return typeof h != "number" && a.push(l), [
      e,
      {
        event: l,
        id: i,
        delay: h
      },
      void 0
    ];
  }
  function ta(t, e) {
    const { event: n, delay: r, id: s } = e;
    if (typeof r == "number") {
      t.defer(() => {
        const i = t.self;
        t.system.scheduler.schedule(i, i, n, r, s);
      });
      return;
    }
  }
  function or(t, e) {
    function n(r, s) {
    }
    return n.type = "xstate.raise", n.event = t, n.id = e == null ? void 0 : e.id, n.delay = e == null ? void 0 : e.delay, n.resolve = ea, n.execute = ta, n;
  }
  function na(t, { machine: e, context: n }, r, s) {
    const i = (o, a) => {
      if (typeof o == "string") {
        const c = Zn(e, o);
        if (!c) throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);
        const l = _t(c, {
          id: a == null ? void 0 : a.id,
          parent: t.self,
          syncSnapshot: a == null ? void 0 : a.syncSnapshot,
          input: typeof (a == null ? void 0 : a.input) == "function" ? a.input({
            context: n,
            event: r,
            self: t.self
          }) : a == null ? void 0 : a.input,
          src: o,
          systemId: a == null ? void 0 : a.systemId
        });
        return s[l.id] = l, l;
      } else return _t(o, {
        id: a == null ? void 0 : a.id,
        parent: t.self,
        syncSnapshot: a == null ? void 0 : a.syncSnapshot,
        input: a == null ? void 0 : a.input,
        src: o,
        systemId: a == null ? void 0 : a.systemId
      });
    };
    return (o, a) => {
      const c = i(o, a);
      return s[c.id] = c, t.defer(() => {
        c._processingStatus !== ue.Stopped && c.start();
      }), c;
    };
  }
  function ra(t, e, n, r, { assignment: s }) {
    if (!e.context) throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");
    const i = {}, o = {
      context: e.context,
      event: n.event,
      spawn: na(t, e, n.event, i),
      self: t.self,
      system: t.system
    };
    let a = {};
    if (typeof s == "function") a = s(o, r);
    else for (const l of Object.keys(s)) {
      const h = s[l];
      a[l] = typeof h == "function" ? h(o, r) : h;
    }
    const c = Object.assign({}, e.context, a);
    return [
      Ne(e, {
        context: c,
        children: Object.keys(i).length ? {
          ...e.children,
          ...i
        } : e.children
      }),
      void 0,
      void 0
    ];
  }
  function Ve(t) {
    function e(n, r) {
    }
    return e.type = "xstate.assign", e.assignment = t, e.resolve = ra, e;
  }
  const jr = /* @__PURE__ */ new WeakMap();
  function Ke(t, e, n) {
    let r = jr.get(t);
    return r ? e in r || (r[e] = n()) : (r = {
      [e]: n()
    }, jr.set(t, r)), r[e];
  }
  const sa = {}, ot = (t) => typeof t == "string" ? {
    type: t
  } : typeof t == "function" ? "resolve" in t ? {
    type: t.type
  } : {
    type: t.name
  } : t;
  class qt {
    constructor(e, n) {
      if (this.config = e, 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 = n._parent, this.key = n._key, this.machine = n._machine, this.path = this.parent ? this.parent.path.concat(this.key) : [], this.id = this.config.id || [
        this.machine.id,
        ...this.path
      ].join(ks), 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 ? Hr(this.config.states, (r, s) => new qt(r, {
        _parent: this,
        _key: s,
        _machine: this.machine
      })) : sa, 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 = Ue(this.config.entry).slice(), this.exit = Ue(this.config.exit).slice(), this.meta = this.config.meta, this.output = this.type === "final" || !this.parent ? this.config.output : void 0, this.tags = Ue(e.tags).slice();
    }
    _initialize() {
      this.transitions = Co(this), this.config.always && (this.always = Ze(this.config.always).map((e) => je(this, Os, e))), Object.keys(this.states).forEach((e) => {
        this.states[e]._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(ot),
          eventType: null,
          reenter: false,
          toJSON: () => ({
            target: this.initial.target.map((e) => `#${e.id}`),
            source: `#${this.id}`,
            actions: this.initial.actions.map(ot),
            eventType: null
          })
        } : void 0,
        history: this.history,
        states: Hr(this.states, (e) => e.definition),
        on: this.on,
        transitions: [
          ...this.transitions.values()
        ].flat().map((e) => ({
          ...e,
          actions: e.actions.map(ot)
        })),
        entry: this.entry.map(ot),
        exit: this.exit.map(ot),
        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 Ke(this, "invoke", () => Ue(this.config.invoke).map((e, n) => {
        const { src: r, systemId: s } = e, i = e.id ?? Tr(this.id, n), o = typeof r == "string" ? r : `xstate.invoke.${Tr(this.id, n)}`;
        return {
          ...e,
          src: o,
          id: i,
          systemId: s,
          toJSON() {
            const { onDone: a, onError: c, ...l } = e;
            return {
              ...l,
              type: "xstate.invoke",
              src: o,
              id: i
            };
          }
        };
      }));
    }
    get on() {
      return Ke(this, "on", () => [
        ...this.transitions
      ].flatMap(([n, r]) => r.map((s) => [
        n,
        s
      ])).reduce((n, [r, s]) => (n[r] = n[r] || [], n[r].push(s), n), {}));
    }
    get after() {
      return Ke(this, "delayedTransitions", () => Io(this));
    }
    get initial() {
      return Ke(this, "initial", () => Oo(this, this.config.initial));
    }
    next(e, n) {
      const r = n.type, s = [];
      let i;
      const o = Ke(this, `candidates-${r}`, () => Eo(this, r));
      for (const a of o) {
        const { guard: c } = a, l = e.context;
        let h = false;
        try {
          h = !c || tn(c, l, n, e);
        } catch (f) {
          const u = typeof c == "string" ? c : typeof c == "object" ? c.type : void 0;
          throw new Error(`Unable to evaluate guard ${u ? `'${u}' ` : ""}in transition for event '${r}' in state node '${this.id}':
${f.message}`);
        }
        if (h) {
          s.push(...a.actions), i = a;
          break;
        }
      }
      return i ? [
        i
      ] : void 0;
    }
    get events() {
      return Ke(this, "events", () => {
        const { states: e } = this, n = new Set(this.ownEvents);
        if (e) for (const r of Object.keys(e)) {
          const s = e[r];
          if (s.states) for (const i of s.events) n.add(`${i}`);
        }
        return Array.from(n);
      });
    }
    get ownEvents() {
      const e = Object.keys(Object.fromEntries(this.transitions)), n = new Set(e.filter((r) => this.transitions.get(r).some((s) => !(!s.target && !s.actions.length && !s.reenter))));
      return Array.from(n);
    }
  }
  const ia = "#";
  class ar {
    constructor(e, n) {
      this.config = e, 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 = e.id || "(machine)", this.implementations = {
        actors: (n == null ? void 0 : n.actors) ?? {},
        actions: (n == null ? void 0 : n.actions) ?? {},
        delays: (n == null ? void 0 : n.delays) ?? {},
        guards: (n == null ? void 0 : n.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 qt(e, {
        _key: this.id,
        _machine: this
      }), this.root._initialize(), ko(this.root), this.states = this.root.states, this.events = this.root.events;
    }
    provide(e) {
      const { actions: n, guards: r, actors: s, delays: i } = this.implementations;
      return new ar(this.config, {
        actions: {
          ...n,
          ...e.actions
        },
        guards: {
          ...r,
          ...e.guards
        },
        actors: {
          ...s,
          ...e.actors
        },
        delays: {
          ...i,
          ...e.delays
        }
      });
    }
    resolveState(e) {
      const n = qo(this.root, e.value), r = Vt(Nt(this.root, n));
      return Dt({
        _nodes: [
          ...r
        ],
        context: e.context || {},
        children: {},
        status: rr(r, this.root) ? "done" : e.status || "active",
        output: e.output,
        error: e.error,
        historyValue: e.historyValue
      }, this);
    }
    transition(e, n, r) {
      return gn(e, n, r, []).snapshot;
    }
    microstep(e, n, r) {
      return gn(e, n, r, []).microsteps.map(([s]) => s);
    }
    getTransitionData(e, n) {
      return sr(this.root, e.value, e, n) || [];
    }
    _getPreInitialState(e, n, r) {
      const { context: s } = this.config, i = Dt({
        context: typeof s != "function" && s ? s : {},
        _nodes: [
          this.root
        ],
        children: {},
        status: "active"
      }, this);
      return typeof s == "function" ? st(i, n, e, [
        Ve(({ spawn: a, event: c, self: l }) => s({
          spawn: a,
          input: c.input,
          self: l
        }))
      ], r, void 0) : i;
    }
    getInitialSnapshot(e, n) {
      const r = Ts(n), s = [], i = this._getPreInitialState(e, r, s), [o] = Lo(this.root, i, e, r, s), { snapshot: a } = gn(o, r, e, s);
      return a;
    }
    start(e) {
      Object.values(e.children).forEach((n) => {
        n.getSnapshot().status === "active" && n.start();
      });
    }
    getStateNodeById(e) {
      const n = Yn(e), r = n.slice(1), s = nn(n[0]) ? n[0].slice(ia.length) : n[0], i = this.idMap.get(s);
      if (!i) throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);
      return zt(i, r);
    }
    get definition() {
      return this.root.definition;
    }
    toJSON() {
      return this.definition;
    }
    getPersistedSnapshot(e, n) {
      return Qo(e, n);
    }
    restoreSnapshot(e, n) {
      const r = {}, s = e.children;
      Object.keys(s).forEach((f) => {
        const u = s[f], d = u.snapshot, g = u.src, m = typeof g == "string" ? Zn(this, g) : g;
        if (!m) return;
        const S = _t(m, {
          id: f,
          parent: n.self,
          syncSnapshot: u.syncSnapshot,
          snapshot: d,
          src: g,
          systemId: u.systemId
        });
        r[f] = S;
      });
      function i(f, u) {
        if (u instanceof qt) return u;
        try {
          return f.machine.getStateNodeById(u.id);
        } catch {
        }
      }
      function o(f, u) {
        if (!u || typeof u != "object") return {};
        const d = {};
        for (const g in u) {
          const m = u[g];
          for (const S of m) {
            const M = i(f, S);
            M && (d[g] ?? (d[g] = []), d[g].push(M));
          }
        }
        return d;
      }
      const a = o(this.root, e.historyValue), c = Dt({
        ...e,
        children: r,
        _nodes: Array.from(Vt(Nt(this.root, e.value))),
        historyValue: a
      }, this), l = /* @__PURE__ */ new Set();
      function h(f, u) {
        if (!l.has(f)) {
          l.add(f);
          for (const d in f) {
            const g = f[d];
            if (g && typeof g == "object") {
              if ("xstate$$type" in g && g.xstate$$type === Qn) {
                f[d] = u[g.id];
                continue;
              }
              h(g, u);
            }
          }
        }
      }
      return h(c.context, r), c;
    }
  }
  function oa(t, e, n, r, { event: s }) {
    const i = typeof s == "function" ? s(n, r) : s;
    return [
      e,
      {
        event: i
      },
      void 0
    ];
  }
  function aa(t, { event: e }) {
    t.defer(() => t.emit(e));
  }
  function Js(t) {
    function e(n, r) {
    }
    return e.type = "xstate.emit", e.event = t, e.resolve = oa, e.execute = aa, e;
  }
  let Mn = (function(t) {
    return t.Parent = "#_parent", t.Internal = "#_internal", t;
  })({});
  function ca(t, e, n, r, { to: s, event: i, id: o, delay: a }, c) {
    var _a5;
    const l = e.machine.implementations.delays;
    if (typeof i == "string") throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);
    const h = typeof i == "function" ? i(n, r) : i;
    let f;
    if (typeof a == "string") {
      const g = l && l[a];
      f = typeof g == "function" ? g(n, r) : g;
    } else f = typeof a == "function" ? a(n, r) : a;
    const u = typeof s == "function" ? s(n, r) : s;
    let d;
    if (typeof u == "string") {
      if (u === Mn.Parent ? d = t.self._parent : u === Mn.Internal ? d = t.self : u.startsWith("#_") ? d = e.children[u.slice(2)] : d = ((_a5 = c.deferredActorIds) == null ? void 0 : _a5.includes(u)) ? u : e.children[u], !d) throw new Error(`Unable to send event to actor '${u}' from machine '${e.machine.id}'.`);
    } else d = u || t.self;
    return [
      e,
      {
        to: d,
        targetId: typeof u == "string" ? u : void 0,
        event: h,
        id: o,
        delay: f
      },
      void 0
    ];
  }
  function fa(t, e, n) {
    typeof n.to == "string" && (n.to = e.children[n.to]);
  }
  function ua(t, e) {
    t.defer(() => {
      const { to: n, event: r, delay: s, id: i } = e;
      if (typeof s == "number") {
        t.system.scheduler.schedule(t.self, n, r, s, i);
        return;
      }
      t.system._relay(t.self, n, r.type === co ? Hs(t.self.id, r.data) : r);
    });
  }
  function cr(t, e, n) {
    function r(s, i) {
    }
    return r.type = "xstate.sendTo", r.to = t, r.event = e, r.id = n == null ? void 0 : n.id, r.delay = n == null ? void 0 : n.delay, r.resolve = ca, r.retryResolve = fa, r.execute = ua, r;
  }
  function la(t, e) {
    return cr(Mn.Parent, t, e);
  }
  function da(t, e, n, r, { collect: s }) {
    const i = [], o = function(c) {
      i.push(c);
    };
    return o.assign = (...a) => {
      i.push(Ve(...a));
    }, o.cancel = (...a) => {
      i.push(er(...a));
    }, o.raise = (...a) => {
      i.push(or(...a));
    }, o.sendTo = (...a) => {
      i.push(cr(...a));
    }, o.sendParent = (...a) => {
      i.push(la(...a));
    }, o.spawnChild = (...a) => {
      i.push(tr(...a));
    }, o.stopChild = (...a) => {
      i.push(en(...a));
    }, o.emit = (...a) => {
      i.push(Js(...a));
    }, s({
      context: n.context,
      event: n.event,
      enqueue: o,
      check: (a) => tn(a, e.context, n.event, e),
      self: t.self,
      system: t.system
    }, r), [
      e,
      void 0,
      i
    ];
  }
  function ha(t) {
    function e(n, r) {
    }
    return e.type = "xstate.enqueueActions", e.collect = t, e.resolve = da, e;
  }
  function ga(t, e, n, r, { value: s, label: i }) {
    return [
      e,
      {
        value: typeof s == "function" ? s(n, r) : s,
        label: i
      },
      void 0
    ];
  }
  function _a({ logger: t }, { value: e, label: n }) {
    n ? t(n, e) : t(e);
  }
  function pa(t = ({ context: n, event: r }) => ({
    context: n,
    event: r
  }), e) {
    function n(r, s) {
    }
    return n.type = "xstate.log", n.value = t, n.label = e, n.resolve = ga, n.execute = _a, n;
  }
  function ya(t, e) {
    const n = Ue(e);
    if (!n.some((s) => js(t.type, s))) {
      const s = n.length === 1 ? `type matching "${n[0]}"` : `one of types matching "${n.join('", "')}"`;
      throw new Error(`Expected event ${JSON.stringify(t)} to have ${s}`);
    }
  }
  function ba(t, e) {
    return new ar(t, e);
  }
  function Xs({ schemas: t, actors: e, actions: n, guards: r, delays: s }) {
    return {
      assign: Ve,
      sendTo: cr,
      raise: or,
      log: pa,
      cancel: er,
      stopChild: en,
      enqueueActions: ha,
      emit: Js,
      spawnChild: tr,
      createStateConfig: (i) => i,
      createAction: (i) => i,
      createMachine: (i) => ba({
        ...i,
        schemas: t
      }, {
        actors: e,
        actions: n,
        guards: r,
        delays: s
      }),
      extend: (i) => Xs({
        schemas: t,
        actors: e,
        actions: {
          ...n,
          ...i.actions
        },
        guards: {
          ...r,
          ...i.guards
        },
        delays: {
          ...s,
          ...i.delays
        }
      })
    };
  }
  const ma = {
    timeout: 1 / 0
  };
  function wa(t, e, n) {
    const r = {
      ...ma,
      ...n
    };
    return new Promise((s, i) => {
      const { signal: o } = r;
      if (o == null ? void 0 : o.aborted) {
        i(o.reason);
        return;
      }
      let a = false;
      const c = r.timeout === 1 / 0 ? void 0 : setTimeout(() => {
        l(), i(new Error(`Timeout of ${r.timeout} ms exceeded`));
      }, r.timeout), l = () => {
        clearTimeout(c), a = true, u == null ? void 0 : u.unsubscribe(), f && o.removeEventListener("abort", f);
      };
      function h(d) {
        e(d) && (l(), s(d));
      }
      let f, u;
      h(t.getSnapshot()), !a && (o && (f = () => {
        l(), i(o.reason);
      }, o.addEventListener("abort", f)), u = t.subscribe({
        next: h,
        error: (d) => {
          l(), i(d);
        },
        complete: () => {
          l(), i(new Error("Actor terminated without satisfying predicate"));
        }
      }), a && u.unsubscribe());
    });
  }
  let It;
  const xa = new Uint8Array(16);
  function Sa() {
    if (!It && (It = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !It)) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
    return It(xa);
  }
  const va = /^(?:[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 Ys(t) {
    return typeof t == "string" && va.test(t);
  }
  const oe = [];
  for (let t = 0; t < 256; ++t) oe.push((t + 256).toString(16).slice(1));
  function Aa(t, e = 0) {
    return oe[t[e + 0]] + oe[t[e + 1]] + oe[t[e + 2]] + oe[t[e + 3]] + "-" + oe[t[e + 4]] + oe[t[e + 5]] + "-" + oe[t[e + 6]] + oe[t[e + 7]] + "-" + oe[t[e + 8]] + oe[t[e + 9]] + "-" + oe[t[e + 10]] + oe[t[e + 11]] + oe[t[e + 12]] + oe[t[e + 13]] + oe[t[e + 14]] + oe[t[e + 15]];
  }
  function Ea(t) {
    if (!Ys(t)) throw TypeError("Invalid UUID");
    let e;
    const n = new Uint8Array(16);
    return n[0] = (e = parseInt(t.slice(0, 8), 16)) >>> 24, n[1] = e >>> 16 & 255, n[2] = e >>> 8 & 255, n[3] = e & 255, n[4] = (e = parseInt(t.slice(9, 13), 16)) >>> 8, n[5] = e & 255, n[6] = (e = parseInt(t.slice(14, 18), 16)) >>> 8, n[7] = e & 255, n[8] = (e = parseInt(t.slice(19, 23), 16)) >>> 8, n[9] = e & 255, n[10] = (e = parseInt(t.slice(24, 36), 16)) / 1099511627776 & 255, n[11] = e / 4294967296 & 255, n[12] = e >>> 24 & 255, n[13] = e >>> 16 & 255, n[14] = e >>> 8 & 255, n[15] = e & 255, n;
  }
  const Ia = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lr = {
    randomUUID: Ia
  };
  Ca = function(t, e, n) {
    if (Lr.randomUUID && !e && !t) return Lr.randomUUID();
    t = t || {};
    const r = t.random || (t.rng || Sa)();
    if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, e) {
      n = n || 0;
      for (let s = 0; s < 16; ++s) e[n + s] = r[s];
      return e;
    }
    return Aa(r);
  };
  var Ae = {}, X = {}, ae = {}, _n = {}, at = {}, Fr;
  function ka() {
    return Fr || (Fr = 1, Object.defineProperty(at, "__esModule", {
      value: true
    }), at.crypto = void 0, at.crypto = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0), at;
  }
  var Pr;
  function Zs() {
    return Pr || (Pr = 1, (function(t) {
      Object.defineProperty(t, "__esModule", {
        value: true
      }), t.wrapXOFConstructorWithOpts = t.wrapConstructorWithOpts = t.wrapConstructor = t.Hash = t.nextTick = t.swap32IfBE = t.byteSwapIfBE = t.swap8IfBE = t.isLE = void 0, t.isBytes = n, t.anumber = r, t.abytes = s, t.ahash = i, t.aexists = o, t.aoutput = a, t.u8 = c, t.u32 = l, t.clean = h, t.createView = f, t.rotr = u, t.rotl = d, t.byteSwap = g, t.byteSwap32 = m, t.bytesToHex = B, t.hexToBytes = U, t.asyncLoop = z, t.utf8ToBytes = F, t.bytesToUtf8 = C, t.toBytes = R, t.kdfInputToBytes = L, t.concatBytes = W, t.checkOpts = _, t.createHasher = A, t.createOptHasher = I, t.createXOFer = E, t.randomBytes = V;
      const e = ka();
      function n(y) {
        return y instanceof Uint8Array || ArrayBuffer.isView(y) && y.constructor.name === "Uint8Array";
      }
      function r(y) {
        if (!Number.isSafeInteger(y) || y < 0) throw new Error("positive integer expected, got " + y);
      }
      function s(y, ...O) {
        if (!n(y)) throw new Error("Uint8Array expected");
        if (O.length > 0 && !O.includes(y.length)) throw new Error("Uint8Array expected of length " + O + ", got length=" + y.length);
      }
      function i(y) {
        if (typeof y != "function" || typeof y.create != "function") throw new Error("Hash should be wrapped by utils.createHasher");
        r(y.outputLen), r(y.blockLen);
      }
      function o(y, O = true) {
        if (y.destroyed) throw new Error("Hash instance has been destroyed");
        if (O && y.finished) throw new Error("Hash#digest() has already been called");
      }
      function a(y, O) {
        s(y);
        const D = O.outputLen;
        if (y.length < D) throw new Error("digestInto() expects output buffer of length at least " + D);
      }
      function c(y) {
        return new Uint8Array(y.buffer, y.byteOffset, y.byteLength);
      }
      function l(y) {
        return new Uint32Array(y.buffer, y.byteOffset, Math.floor(y.byteLength / 4));
      }
      function h(...y) {
        for (let O = 0; O < y.length; O++) y[O].fill(0);
      }
      function f(y) {
        return new DataView(y.buffer, y.byteOffset, y.byteLength);
      }
      function u(y, O) {
        return y << 32 - O | y >>> O;
      }
      function d(y, O) {
        return y << O | y >>> 32 - O >>> 0;
      }
      t.isLE = new Uint8Array(new Uint32Array([
        287454020
      ]).buffer)[0] === 68;
      function g(y) {
        return y << 24 & 4278190080 | y << 8 & 16711680 | y >>> 8 & 65280 | y >>> 24 & 255;
      }
      t.swap8IfBE = t.isLE ? (y) => y : (y) => g(y), t.byteSwapIfBE = t.swap8IfBE;
      function m(y) {
        for (let O = 0; O < y.length; O++) y[O] = g(y[O]);
        return y;
      }
      t.swap32IfBE = t.isLE ? (y) => y : m;
      const S = typeof Uint8Array.from([]).toHex == "function" && typeof Uint8Array.fromHex == "function", M = Array.from({
        length: 256
      }, (y, O) => O.toString(16).padStart(2, "0"));
      function B(y) {
        if (s(y), S) return y.toHex();
        let O = "";
        for (let D = 0; D < y.length; D++) O += M[y[D]];
        return O;
      }
      const w = {
        _0: 48,
        _9: 57,
        A: 65,
        F: 70,
        a: 97,
        f: 102
      };
      function N(y) {
        if (y >= w._0 && y <= w._9) return y - w._0;
        if (y >= w.A && y <= w.F) return y - (w.A - 10);
        if (y >= w.a && y <= w.f) return y - (w.a - 10);
      }
      function U(y) {
        if (typeof y != "string") throw new Error("hex string expected, got " + typeof y);
        if (S) return Uint8Array.fromHex(y);
        const O = y.length, D = O / 2;
        if (O % 2) throw new Error("hex string expected, got unpadded hex of length " + O);
        const P = new Uint8Array(D);
        for (let J = 0, ie = 0; J < D; J++, ie += 2) {
          const Ge = N(y.charCodeAt(ie)), be = N(y.charCodeAt(ie + 1));
          if (Ge === void 0 || be === void 0) {
            const ve = y[ie] + y[ie + 1];
            throw new Error('hex string expected, got non-hex character "' + ve + '" at index ' + ie);
          }
          P[J] = Ge * 16 + be;
        }
        return P;
      }
      const j = async () => {
      };
      t.nextTick = j;
      async function z(y, O, D) {
        let P = Date.now();
        for (let J = 0; J < y; J++) {
          D(J);
          const ie = Date.now() - P;
          ie >= 0 && ie < O || (await (0, t.nextTick)(), P += ie);
        }
      }
      function F(y) {
        if (typeof y != "string") throw new Error("string expected");
        return new Uint8Array(new TextEncoder().encode(y));
      }
      function C(y) {
        return new TextDecoder().decode(y);
      }
      function R(y) {
        return typeof y == "string" && (y = F(y)), s(y), y;
      }
      function L(y) {
        return typeof y == "string" && (y = F(y)), s(y), y;
      }
      function W(...y) {
        let O = 0;
        for (let P = 0; P < y.length; P++) {
          const J = y[P];
          s(J), O += J.length;
        }
        const D = new Uint8Array(O);
        for (let P = 0, J = 0; P < y.length; P++) {
          const ie = y[P];
          D.set(ie, J), J += ie.length;
        }
        return D;
      }
      function _(y, O) {
        if (O !== void 0 && {}.toString.call(O) !== "[object Object]") throw new Error("options should be object or undefined");
        return Object.assign(y, O);
      }
      class T {
      }
      t.Hash = T;
      function A(y) {
        const O = (P) => y().update(R(P)).digest(), D = y();
        return O.outputLen = D.outputLen, O.blockLen = D.blockLen, O.create = () => y(), O;
      }
      function I(y) {
        const O = (P, J) => y(J).update(R(P)).digest(), D = y({});
        return O.outputLen = D.outputLen, O.blockLen = D.blockLen, O.create = (P) => y(P), O;
      }
      function E(y) {
        const O = (P, J) => y(J).update(R(P)).digest(), D = y({});
        return O.outputLen = D.outputLen, O.blockLen = D.blockLen, O.create = (P) => y(P), O;
      }
      t.wrapConstructor = A, t.wrapConstructorWithOpts = I, t.wrapXOFConstructorWithOpts = E;
      function V(y = 32) {
        if (e.crypto && typeof e.crypto.getRandomValues == "function") return e.crypto.getRandomValues(new Uint8Array(y));
        if (e.crypto && typeof e.crypto.randomBytes == "function") return Uint8Array.from(e.crypto.randomBytes(y));
        throw new Error("crypto.getRandomValues must be defined");
      }
    })(_n)), _n;
  }
  var $r;
  function Oa() {
    if ($r) return ae;
    $r = 1, Object.defineProperty(ae, "__esModule", {
      value: true
    }), ae.SHA512_IV = ae.SHA384_IV = ae.SHA224_IV = ae.SHA256_IV = ae.HashMD = void 0, ae.setBigUint64 = e, ae.Chi = n, ae.Maj = r;
    const t = Zs();
    function e(i, o, a, c) {
      if (typeof i.setBigUint64 == "function") return i.setBigUint64(o, a, c);
      const l = BigInt(32), h = BigInt(4294967295), f = Number(a >> l & h), u = Number(a & h), d = c ? 4 : 0, g = c ? 0 : 4;
      i.setUint32(o + d, f, c), i.setUint32(o + g, u, c);
    }
    function n(i, o, a) {
      return i & o ^ ~i & a;
    }
    function r(i, o, a) {
      return i & o ^ i & a ^ o & a;
    }
    class s extends t.Hash {
      constructor(o, a, c, l) {
        super(), this.finished = false, this.length = 0, this.pos = 0, this.destroyed = false, this.blockLen = o, this.outputLen = a, this.padOffset = c, this.isLE = l, this.buffer = new Uint8Array(o), this.view = (0, t.createView)(this.buffer);
      }
      update(o) {
        (0, t.aexists)(this), o = (0, t.toBytes)(o), (0, t.abytes)(o);
        const { view: a, buffer: c, blockLen: l } = this, h = o.length;
        for (let f = 0; f < h; ) {
          const u = Math.min(l - this.pos, h - f);
          if (u === l) {
            const d = (0, t.createView)(o);
            for (; l <= h - f; f += l) this.process(d, f);
            continue;
          }
          c.set(o.subarray(f, f + u), this.pos), this.pos += u, f += u, this.pos === l && (this.process(a, 0), this.pos = 0);
        }
        return this.length += o.length, this.roundClean(), this;
      }
      digestInto(o) {
        (0, t.aexists)(this), (0, t.aoutput)(o, this), this.finished = true;
        const { buffer: a, view: c, blockLen: l, isLE: h } = this;
        let { pos: f } = this;
        a[f++] = 128, (0, t.clean)(this.buffer.subarray(f)), this.padOffset > l - f && (this.process(c, 0), f = 0);
        for (let S = f; S < l; S++) a[S] = 0;
        e(c, l - 8, BigInt(this.length * 8), h), this.process(c, 0);
        const u = (0, t.createView)(o), d = this.outputLen;
        if (d % 4) throw new Error("_sha2: outputLen should be aligned to 32bit");
        const g = d / 4, m = this.get();
        if (g > m.length) throw new Error("_sha2: outputLen bigger than state");
        for (let S = 0; S < g; S++) u.setUint32(4 * S, m[S], h);
      }
      digest() {
        const { buffer: o, outputLen: a } = this;
        this.digestInto(o);
        const c = o.slice(0, a);
        return this.destroy(), c;
      }
      _cloneInto(o) {
        o || (o = new this.constructor()), o.set(...this.get());
        const { blockLen: a, buffer: c, length: l, finished: h, destroyed: f, pos: u } = this;
        return o.destroyed = f, o.finished = h, o.length = l, o.pos = u, l % a && o.buffer.set(c), o;
      }
      clone() {
        return this._cloneInto();
      }
    }
    return ae.HashMD = s, ae.SHA256_IV = Uint32Array.from([
      1779033703,
      3144134277,
      1013904242,
      2773480762,
      1359893119,
      2600822924,
      528734635,
      1541459225
    ]), ae.SHA224_IV = Uint32Array.from([
      3238371032,
      914150663,
      812702999,
      4144912697,
      4290775857,
      1750603025,
      1694076839,
      3204075428
    ]), ae.SHA384_IV = Uint32Array.from([
      3418070365,
      3238371032,
      1654270250,
      914150663,
      2438529370,
      812702999,
      355462360,
      4144912697,
      1731405415,
      4290775857,
      2394180231,
      1750603025,
      3675008525,
      1694076839,
      1203062813,
      3204075428
    ]), ae.SHA512_IV = Uint32Array.from([
      1779033703,
      4089235720,
      3144134277,
      2227873595,
      1013904242,
      4271175723,
      2773480762,
      1595750129,
      1359893119,
      2917565137,
      2600822924,
      725511199,
      528734635,
      4215389547,
      1541459225,
      327033209
    ]), ae;
  }
  var q = {}, Vr;
  function Ra() {
    if (Vr) return q;
    Vr = 1, Object.defineProperty(q, "__esModule", {
      value: true
    }), q.toBig = q.shrSL = q.shrSH = q.rotrSL = q.rotrSH = q.rotrBL = q.rotrBH = q.rotr32L = q.rotr32H = q.rotlSL = q.rotlSH = q.rotlBL = q.rotlBH = q.add5L = q.add5H = q.add4L = q.add4H = q.add3L = q.add3H = void 0, q.add = M, q.fromBig = n, q.split = r;
    const t = BigInt(2 ** 32 - 1), e = BigInt(32);
    function n(C, R = false) {
      return R ? {
        h: Number(C & t),
        l: Number(C >> e & t)
      } : {
        h: Number(C >> e & t) | 0,
        l: Number(C & t) | 0
      };
    }
    function r(C, R = false) {
      const L = C.length;
      let W = new Uint32Array(L), _ = new Uint32Array(L);
      for (let T = 0; T < L; T++) {
        const { h: A, l: I } = n(C[T], R);
        [W[T], _[T]] = [
          A,
          I
        ];
      }
      return [
        W,
        _
      ];
    }
    const s = (C, R) => BigInt(C >>> 0) << e | BigInt(R >>> 0);
    q.toBig = s;
    const i = (C, R, L) => C >>> L;
    q.shrSH = i;
    const o = (C, R, L) => C << 32 - L | R >>> L;
    q.shrSL = o;
    const a = (C, R, L) => C >>> L | R << 32 - L;
    q.rotrSH = a;
    const c = (C, R, L) => C << 32 - L | R >>> L;
    q.rotrSL = c;
    const l = (C, R, L) => C << 64 - L | R >>> L - 32;
    q.rotrBH = l;
    const h = (C, R, L) => C >>> L - 32 | R << 64 - L;
    q.rotrBL = h;
    const f = (C, R) => R;
    q.rotr32H = f;
    const u = (C, R) => C;
    q.rotr32L = u;
    const d = (C, R, L) => C << L | R >>> 32 - L;
    q.rotlSH = d;
    const g = (C, R, L) => R << L | C >>> 32 - L;
    q.rotlSL = g;
    const m = (C, R, L) => R << L - 32 | C >>> 64 - L;
    q.rotlBH = m;
    const S = (C, R, L) => C << L - 32 | R >>> 64 - L;
    q.rotlBL = S;
    function M(C, R, L, W) {
      const _ = (R >>> 0) + (W >>> 0);
      return {
        h: C + L + (_ / 2 ** 32 | 0) | 0,
        l: _ | 0
      };
    }
    const B = (C, R, L) => (C >>> 0) + (R >>> 0) + (L >>> 0);
    q.add3L = B;
    const w = (C, R, L, W) => R + L + W + (C / 2 ** 32 | 0) | 0;
    q.add3H = w;
    const N = (C, R, L, W) => (C >>> 0) + (R >>> 0) + (L >>> 0) + (W >>> 0);
    q.add4L = N;
    const U = (C, R, L, W, _) => R + L + W + _ + (C / 2 ** 32 | 0) | 0;
    q.add4H = U;
    const j = (C, R, L, W, _) => (C >>> 0) + (R >>> 0) + (L >>> 0) + (W >>> 0) + (_ >>> 0);
    q.add5L = j;
    const z = (C, R, L, W, _, T) => R + L + W + _ + T + (C / 2 ** 32 | 0) | 0;
    q.add5H = z;
    const F = {
      fromBig: n,
      split: r,
      toBig: s,
      shrSH: i,
      shrSL: o,
      rotrSH: a,
      rotrSL: c,
      rotrBH: l,
      rotrBL: h,
      rotr32H: f,
      rotr32L: u,
      rotlSH: d,
      rotlSL: g,
      rotlBH: m,
      rotlBL: S,
      add: M,
      add3L: B,
      add3H: w,
      add4L: N,
      add4H: U,
      add5H: z,
      add5L: j
    };
    return q.default = F, q;
  }
  var zr;
  function Ha() {
    if (zr) return X;
    zr = 1, Object.defineProperty(X, "__esModule", {
      value: true
    }), X.sha512_224 = X.sha512_256 = X.sha384 = X.sha512 = X.sha224 = X.sha256 = X.SHA512_256 = X.SHA512_224 = X.SHA384 = X.SHA512 = X.SHA224 = X.SHA256 = void 0;
    const t = Oa(), e = Ra(), n = Zs(), r = 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
    ]), s = new Uint32Array(64);
    class i extends t.HashMD {
      constructor(w = 32) {
        super(64, w, 8, false), this.A = t.SHA256_IV[0] | 0, this.B = t.SHA256_IV[1] | 0, this.C = t.SHA256_IV[2] | 0, this.D = t.SHA256_IV[3] | 0, this.E = t.SHA256_IV[4] | 0, this.F = t.SHA256_IV[5] | 0, this.G = t.SHA256_IV[6] | 0, this.H = t.SHA256_IV[7] | 0;
      }
      get() {
        const { A: w, B: N, C: U, D: j, E: z, F, G: C, H: R } = this;
        return [
          w,
          N,
          U,
          j,
          z,
          F,
          C,
          R
        ];
      }
      set(w, N, U, j, z, F, C, R) {
        this.A = w | 0, this.B = N | 0, this.C = U | 0, this.D = j | 0, this.E = z | 0, this.F = F | 0, this.G = C | 0, this.H = R | 0;
      }
      process(w, N) {
        for (let _ = 0; _ < 16; _++, N += 4) s[_] = w.getUint32(N, false);
        for (let _ = 16; _ < 64; _++) {
          const T = s[_ - 15], A = s[_ - 2], I = (0, n.rotr)(T, 7) ^ (0, n.rotr)(T, 18) ^ T >>> 3, E = (0, n.rotr)(A, 17) ^ (0, n.rotr)(A, 19) ^ A >>> 10;
          s[_] = E + s[_ - 7] + I + s[_ - 16] | 0;
        }
        let { A: U, B: j, C: z, D: F, E: C, F: R, G: L, H: W } = this;
        for (let _ = 0; _ < 64; _++) {
          const T = (0, n.rotr)(C, 6) ^ (0, n.rotr)(C, 11) ^ (0, n.rotr)(C, 25), A = W + T + (0, t.Chi)(C, R, L) + r[_] + s[_] | 0, E = ((0, n.rotr)(U, 2) ^ (0, n.rotr)(U, 13) ^ (0, n.rotr)(U, 22)) + (0, t.Maj)(U, j, z) | 0;
          W = L, L = R, R = C, C = F + A | 0, F = z, z = j, j = U, U = A + E | 0;
        }
        U = U + this.A | 0, j = j + this.B | 0, z = z + this.C | 0, F = F + this.D | 0, C = C + this.E | 0, R = R + this.F | 0, L = L + this.G | 0, W = W + this.H | 0, this.set(U, j, z, F, C, R, L, W);
      }
      roundClean() {
        (0, n.clean)(s);
      }
      destroy() {
        this.set(0, 0, 0, 0, 0, 0, 0, 0), (0, n.clean)(this.buffer);
      }
    }
    X.SHA256 = i;
    class o extends i {
      constructor() {
        super(28), this.A = t.SHA224_IV[0] | 0, this.B = t.SHA224_IV[1] | 0, this.C = t.SHA224_IV[2] | 0, this.D = t.SHA224_IV[3] | 0, this.E = t.SHA224_IV[4] | 0, this.F = t.SHA224_IV[5] | 0, this.G = t.SHA224_IV[6] | 0, this.H = t.SHA224_IV[7] | 0;
      }
    }
    X.SHA224 = o;
    const a = e.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((B) => BigInt(B))), c = a[0], l = a[1], h = new Uint32Array(80), f = new Uint32Array(80);
    class u extends t.HashMD {
      constructor(w = 64) {
        super(128, w, 16, false), this.Ah = t.SHA512_IV[0] | 0, this.Al = t.SHA512_IV[1] | 0, this.Bh = t.SHA512_IV[2] | 0, this.Bl = t.SHA512_IV[3] | 0, this.Ch = t.SHA512_IV[4] | 0, this.Cl = t.SHA512_IV[5] | 0, this.Dh = t.SHA512_IV[6] | 0, this.Dl = t.SHA512_IV[7] | 0, this.Eh = t.SHA512_IV[8] | 0, this.El = t.SHA512_IV[9] | 0, this.Fh = t.SHA512_IV[10] | 0, this.Fl = t.SHA512_IV[11] | 0, this.Gh = t.SHA512_IV[12] | 0, this.Gl = t.SHA512_IV[13] | 0, this.Hh = t.SHA512_IV[14] | 0, this.Hl = t.SHA512_IV[15] | 0;
      }
      get() {
        const { Ah: w, Al: N, Bh: U, Bl: j, Ch: z, Cl: F, Dh: C, Dl: R, Eh: L, El: W, Fh: _, Fl: T, Gh: A, Gl: I, Hh: E, Hl: V } = this;
        return [
          w,
          N,
          U,
          j,
          z,
          F,
          C,
          R,
          L,
          W,
          _,
          T,
          A,
          I,
          E,
          V
        ];
      }
      set(w, N, U, j, z, F, C, R, L, W, _, T, A, I, E, V) {
        this.Ah = w | 0, this.Al = N | 0, this.Bh = U | 0, this.Bl = j | 0, this.Ch = z | 0, this.Cl = F | 0, this.Dh = C | 0, this.Dl = R | 0, this.Eh = L | 0, this.El = W | 0, this.Fh = _ | 0, this.Fl = T | 0, this.Gh = A | 0, this.Gl = I | 0, this.Hh = E | 0, this.Hl = V | 0;
      }
      process(w, N) {
        for (let D = 0; D < 16; D++, N += 4) h[D] = w.getUint32(N), f[D] = w.getUint32(N += 4);
        for (let D = 16; D < 80; D++) {
          const P = h[D - 15] | 0, J = f[D - 15] | 0, ie = e.rotrSH(P, J, 1) ^ e.rotrSH(P, J, 8) ^ e.shrSH(P, J, 7), Ge = e.rotrSL(P, J, 1) ^ e.rotrSL(P, J, 8) ^ e.shrSL(P, J, 7), be = h[D - 2] | 0, ve = f[D - 2] | 0, vt = e.rotrSH(be, ve, 19) ^ e.rotrBH(be, ve, 61) ^ e.shrSH(be, ve, 6), sn = e.rotrSL(be, ve, 19) ^ e.rotrBL(be, ve, 61) ^ e.shrSL(be, ve, 6), At = e.add4L(Ge, sn, f[D - 7], f[D - 16]), on = e.add4H(At, ie, vt, h[D - 7], h[D - 16]);
          h[D] = on | 0, f[D] = At | 0;
        }
        let { Ah: U, Al: j, Bh: z, Bl: F, Ch: C, Cl: R, Dh: L, Dl: W, Eh: _, El: T, Fh: A, Fl: I, Gh: E, Gl: V, Hh: y, Hl: O } = this;
        for (let D = 0; D < 80; D++) {
          const P = e.rotrSH(_, T, 14) ^ e.rotrSH(_, T, 18) ^ e.rotrBH(_, T, 41), J = e.rotrSL(_, T, 14) ^ e.rotrSL(_, T, 18) ^ e.rotrBL(_, T, 41), ie = _ & A ^ ~_ & E, Ge = T & I ^ ~T & V, be = e.add5L(O, J, Ge, l[D], f[D]), ve = e.add5H(be, y, P, ie, c[D], h[D]), vt = be | 0, sn = e.rotrSH(U, j, 28) ^ e.rotrBH(U, j, 34) ^ e.rotrBH(U, j, 39), At = e.rotrSL(U, j, 28) ^ e.rotrBL(U, j, 34) ^ e.rotrBL(U, j, 39), on = U & z ^ U & C ^ z & C, bi = j & F ^ j & R ^ F & R;
          y = E | 0, O = V | 0, E = A | 0, V = I | 0, A = _ | 0, I = T | 0, { h: _, l: T } = e.add(L | 0, W | 0, ve | 0, vt | 0), L = C | 0, W = R | 0, C = z | 0, R = F | 0, z = U | 0, F = j | 0;
          const yr = e.add3L(vt, At, bi);
          U = e.add3H(yr, ve, sn, on), j = yr | 0;
        }
        ({ h: U, l: j } = e.add(this.Ah | 0, this.Al | 0, U | 0, j | 0)), { h: z, l: F } = e.add(this.Bh | 0, this.Bl | 0, z | 0, F | 0), { h: C, l: R } = e.add(this.Ch | 0, this.Cl | 0, C | 0, R | 0), { h: L, l: W } = e.add(this.Dh | 0, this.Dl | 0, L | 0, W | 0), { h: _, l: T } = e.add(this.Eh | 0, this.El | 0, _ | 0, T | 0), { h: A, l: I } = e.add(this.Fh | 0, this.Fl | 0, A | 0, I | 0), { h: E, l: V } = e.add(this.Gh | 0, this.Gl | 0, E | 0, V | 0), { h: y, l: O } = e.add(this.Hh | 0, this.Hl | 0, y | 0, O | 0), this.set(U, j, z, F, C, R, L, W, _, T, A, I, E, V, y, O);
      }
      roundClean() {
        (0, n.clean)(h, f);
      }
      destroy() {
        (0, n.clean)(this.buffer), this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
      }
    }
    X.SHA512 = u;
    class d extends u {
      constructor() {
        super(48), this.Ah = t.SHA384_IV[0] | 0, this.Al = t.SHA384_IV[1] | 0, this.Bh = t.SHA384_IV[2] | 0, this.Bl = t.SHA384_IV[3] | 0, this.Ch = t.SHA384_IV[4] | 0, this.Cl = t.SHA384_IV[5] | 0, this.Dh = t.SHA384_IV[6] | 0, this.Dl = t.SHA384_IV[7] | 0, this.Eh = t.SHA384_IV[8] | 0, this.El = t.SHA384_IV[9] | 0, this.Fh = t.SHA384_IV[10] | 0, this.Fl = t.SHA384_IV[11] | 0, this.Gh = t.SHA384_IV[12] | 0, this.Gl = t.SHA384_IV[13] | 0, this.Hh = t.SHA384_IV[14] | 0, this.Hl = t.SHA384_IV[15] | 0;
      }
    }
    X.SHA384 = d;
    const g = Uint32Array.from([
      2352822216,
      424955298,
      1944164710,
      2312950998,
      502970286,
      855612546,
      1738396948,
      1479516111,
      258812777,
      2077511080,
      2011393907,
      79989058,
      1067287976,
      1780299464,
      286451373,
      2446758561
    ]), m = Uint32Array.from([
      573645204,
      4230739756,
      2673172387,
      3360449730,
      596883563,
      1867755857,
      2520282905,
      1497426621,
      2519219938,
      2827943907,
      3193839141,
      1401305490,
      721525244,
      746961066,
      246885852,
      2177182882
    ]);
    class S extends u {
      constructor() {
        super(28), this.Ah = g[0] | 0, this.Al = g[1] | 0, this.Bh = g[2] | 0, this.Bl = g[3] | 0, this.Ch = g[4] | 0, this.Cl = g[5] | 0, this.Dh = g[6] | 0, this.Dl = g[7] | 0, this.Eh = g[8] | 0, this.El = g[9] | 0, this.Fh = g[10] | 0, this.Fl = g[11] | 0, this.Gh = g[12] | 0, this.Gl = g[13] | 0, this.Hh = g[14] | 0, this.Hl = g[15] | 0;
      }
    }
    X.SHA512_224 = S;
    class M extends u {
      constructor() {
        super(32), this.Ah = m[0] | 0, this.Al = m[1] | 0, this.Bh = m[2] | 0, this.Bl = m[3] | 0, this.Ch = m[4] | 0, this.Cl = m[5] | 0, this.Dh = m[6] | 0, this.Dl = m[7] | 0, this.Eh = m[8] | 0, this.El = m[9] | 0, this.Fh = m[10] | 0, this.Fl = m[11] | 0, this.Gh = m[12] | 0, this.Gl = m[13] | 0, this.Hh = m[14] | 0, this.Hl = m[15] | 0;
      }
    }
    return X.SHA512_256 = M, X.sha256 = (0, n.createHasher)(() => new i()), X.sha224 = (0, n.createHasher)(() => new o()), X.sha512 = (0, n.createHasher)(() => new u()), X.sha384 = (0, n.createHasher)(() => new d()), X.sha512_256 = (0, n.createHasher)(() => new M()), X.sha512_224 = (0, n.createHasher)(() => new S()), X;
  }
  var Nr;
  function Ta() {
    if (Nr) return Ae;
    Nr = 1, Object.defineProperty(Ae, "__esModule", {
      value: true
    }), Ae.sha224 = Ae.SHA224 = Ae.sha256 = Ae.SHA256 = void 0;
    const t = Ha();
    return Ae.SHA256 = t.SHA256, Ae.sha256 = t.sha256, Ae.SHA224 = t.SHA224, Ae.sha224 = t.sha224, Ae;
  }
  var pn, qr;
  function Ua() {
    if (qr) return pn;
    qr = 1;
    function t(e) {
      if (e.length >= 255) throw new TypeError("Alphabet too long");
      for (var n = new Uint8Array(256), r = 0; r < n.length; r++) n[r] = 255;
      for (var s = 0; s < e.length; s++) {
        var i = e.charAt(s), o = i.charCodeAt(0);
        if (n[o] !== 255) throw new TypeError(i + " is ambiguous");
        n[o] = s;
      }
      var a = e.length, c = e.charAt(0), l = Math.log(a) / Math.log(256), h = Math.log(256) / Math.log(a);
      function f(g) {
        if (g instanceof Uint8Array || (ArrayBuffer.isView(g) ? g = new Uint8Array(g.buffer, g.byteOffset, g.byteLength) : Array.isArray(g) && (g = Uint8Array.from(g))), !(g instanceof Uint8Array)) throw new TypeError("Expected Uint8Array");
        if (g.length === 0) return "";
        for (var m = 0, S = 0, M = 0, B = g.length; M !== B && g[M] === 0; ) M++, m++;
        for (var w = (B - M) * h + 1 >>> 0, N = new Uint8Array(w); M !== B; ) {
          for (var U = g[M], j = 0, z = w - 1; (U !== 0 || j < S) && z !== -1; z--, j++) U += 256 * N[z] >>> 0, N[z] = U % a >>> 0, U = U / a >>> 0;
          if (U !== 0) throw new Error("Non-zero carry");
          S = j, M++;
        }
        for (var F = w - S; F !== w && N[F] === 0; ) F++;
        for (var C = c.repeat(m); F < w; ++F) C += e.charAt(N[F]);
        return C;
      }
      function u(g) {
        if (typeof g != "string") throw new TypeError("Expected String");
        if (g.length === 0) return new Uint8Array();
        for (var m = 0, S = 0, M = 0; g[m] === c; ) S++, m++;
        for (var B = (g.length - m) * l + 1 >>> 0, w = new Uint8Array(B); g[m]; ) {
          var N = g.charCodeAt(m);
          if (N > 255) return;
          var U = n[N];
          if (U === 255) return;
          for (var j = 0, z = B - 1; (U !== 0 || j < M) && z !== -1; z--, j++) U += a * w[z] >>> 0, w[z] = U % 256 >>> 0, U = U / 256 >>> 0;
          if (U !== 0) throw new Error("Non-zero carry");
          M = j, m++;
        }
        for (var F = B - M; F !== B && w[F] === 0; ) F++;
        for (var C = new Uint8Array(S + (B - F)), R = S; F !== B; ) C[R++] = w[F++];
        return C;
      }
      function d(g) {
        var m = u(g);
        if (m) return m;
        throw new Error("Non-base" + a + " character");
      }
      return {
        encode: f,
        decodeUnsafe: u,
        decode: d
      };
    }
    return pn = t, pn;
  }
  var yn, Wr;
  function Da() {
    return Wr || (Wr = 1, yn = Ua()("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")), yn;
  }
  var bn, Gr;
  function Ma() {
    if (Gr) return bn;
    Gr = 1;
    var t = Da();
    return bn = function(e) {
      function n(o) {
        var a = Uint8Array.from(o), c = e(a), l = a.length + 4, h = new Uint8Array(l);
        return h.set(a, 0), h.set(c.subarray(0, 4), a.length), t.encode(h, l);
      }
      function r(o) {
        var a = o.slice(0, -4), c = o.slice(-4), l = e(a);
        if (!(c[0] ^ l[0] | c[1] ^ l[1] | c[2] ^ l[2] | c[3] ^ l[3])) return a;
      }
      function s(o) {
        var a = t.decodeUnsafe(o);
        if (a) return r(a);
      }
      function i(o) {
        var a = t.decode(o), c = r(a);
        if (!c) throw new Error("Invalid checksum");
        return c;
      }
      return {
        encode: n,
        decode: i,
        decodeUnsafe: s
      };
    }, bn;
  }
  var mn, Kr;
  function Ba() {
    if (Kr) return mn;
    Kr = 1;
    var { sha256: t } = Ta(), e = Ma();
    function n(r) {
      return t(t(r));
    }
    return mn = e(n), mn;
  }
  var ja = Ba();
  let We, La, Qs, Wt, ei, ti, Pa, ni, Be;
  We = Wn(ja);
  La = (t) => {
    if (t.length % 2 !== 0) throw new Error("Hex string must have an even length");
    const e = new Uint8Array(t.length / 2);
    for (let n = 0; n < t.length; n += 2) e[n >> 1] = parseInt(t.slice(n, n + 2), 16);
    return e;
  };
  Qs = (t) => Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
  Wt = "automerge:";
  fr = (t) => {
    const [e, n, ...r] = t.split("#");
    if (r.length > 0) throw new Error("Invalid URL: contains multiple heads sections");
    const s = new RegExp(`^${Wt}(\\w+)$`), [, i] = e.match(s) || [], o = i, a = ni(o);
    if (!a) throw new Error("Invalid document URL: " + t);
    if (n === void 0) return {
      binaryDocumentId: a,
      documentId: o
    };
    const c = n === "" ? [] : n.split("|"), l = c.map((h) => {
      try {
        return Qs(We.decode(h));
      } catch {
        throw new Error(`Invalid head in URL: ${h}`);
      }
    });
    return {
      binaryDocumentId: a,
      hexHeads: l,
      documentId: o,
      heads: c
    };
  };
  ei = (t) => {
    if (t instanceof Uint8Array || typeof t == "string") return Wt + (t instanceof Uint8Array ? Gt(t) : t);
    const { documentId: e, heads: n = void 0 } = t;
    if (e === void 0) throw new Error("Invalid documentId: " + e);
    const r = e instanceof Uint8Array ? Gt(e) : e;
    let s = `${Wt}${r}`;
    return n !== void 0 && (n.forEach((i) => {
      try {
        We.decode(i);
      } catch {
        throw new Error(`Invalid head: ${i}`);
      }
    }), s += "#" + n.join("|")), s;
  };
  Fa = (t) => {
    if (typeof t != "string" || !t || !t.startsWith(Wt)) return false;
    try {
      const { documentId: e, heads: n } = fr(t);
      return !(!ti(e) || n && !n.every((r) => {
        try {
          return We.decode(r), true;
        } catch {
          return false;
        }
      }));
    } catch {
      return false;
    }
  };
  ti = (t) => typeof t != "string" ? false : ni(t) !== void 0;
  Pa = (t) => typeof t == "string" && Ys(t);
  Md = () => {
    const t = Ca(null, new Uint8Array(16));
    return ei({
      documentId: t
    });
  };
  ni = (t) => We.decodeUnsafe(t);
  Gt = (t) => We.encode(t);
  Qe = (t) => t.map((e) => We.encode(La(e)));
  Be = (t) => t.map((e) => Qs(We.decode(e)));
  Bd = (t) => {
    if (t instanceof Uint8Array) return Gt(t);
    if (Fa(t)) return fr(t).documentId;
    if (ti(t)) return t;
    if (Pa(t)) {
      console.warn("Future versions will not support UUIDs as document IDs; use Automerge URLs instead.");
      const e = Ea(t);
      return Gt(e);
    }
    throw new Error(`Invalid AutomergeUrl: '${t}'`);
  };
  let Bn;
  try {
    Bn = new TextDecoder();
  } catch {
  }
  let $, ze, v = 0;
  const $a = 105, Va = 57342, za = 57343, Jr = 57337, Xr = 6, Je = {};
  let ct = 11281e4, Re = 1681e4, G = {}, Q, Kt, Jt = 0, pt = 0, re, me, te = [], jn = [], de, ce, ft, Yr = {
    useRecords: false,
    mapsAsObjects: true
  }, yt = false, ri = 2;
  try {
    new Function("");
  } catch {
    ri = 1 / 0;
  }
  class bt {
    constructor(e) {
      if (e && ((e.keyMap || e._keyMap) && !e.useRecords && (e.useRecords = false, e.mapsAsObjects = true), e.useRecords === false && e.mapsAsObjects === void 0 && (e.mapsAsObjects = true), e.getStructures && (e.getShared = e.getStructures), e.getShared && !e.structures && ((e.structures = []).uninitialized = true), e.keyMap)) {
        this.mapKey = /* @__PURE__ */ new Map();
        for (let [n, r] of Object.entries(e.keyMap)) this.mapKey.set(r, n);
      }
      Object.assign(this, e);
    }
    decodeKey(e) {
      return this.keyMap && this.mapKey.get(e) || e;
    }
    encodeKey(e) {
      return this.keyMap && this.keyMap.hasOwnProperty(e) ? this.keyMap[e] : e;
    }
    encodeKeys(e) {
      if (!this._keyMap) return e;
      let n = /* @__PURE__ */ new Map();
      for (let [r, s] of Object.entries(e)) n.set(this._keyMap.hasOwnProperty(r) ? this._keyMap[r] : r, s);
      return n;
    }
    decodeKeys(e) {
      if (!this._keyMap || e.constructor.name != "Map") return e;
      if (!this._mapKey) {
        this._mapKey = /* @__PURE__ */ new Map();
        for (let [r, s] of Object.entries(this._keyMap)) this._mapKey.set(s, r);
      }
      let n = {};
      return e.forEach((r, s) => n[we(this._mapKey.has(s) ? this._mapKey.get(s) : s)] = r), n;
    }
    mapDecode(e, n) {
      let r = this.decode(e);
      return this._keyMap && r.constructor.name === "Array" ? r.map((s) => this.decodeKeys(s)) : r;
    }
    decode(e, n) {
      if ($) return ai(() => ($n(), this ? this.decode(e, n) : bt.prototype.decode.call(Yr, e, n)));
      ze = n > -1 ? n : e.length, v = 0, pt = 0, Kt = null, re = null, $ = e;
      try {
        ce = e.dataView || (e.dataView = new DataView(e.buffer, e.byteOffset, e.byteLength));
      } catch (r) {
        throw $ = null, e instanceof Uint8Array ? r : new Error("Source must be a Uint8Array or Buffer but was a " + (e && typeof e == "object" ? e.constructor.name : typeof e));
      }
      if (this instanceof bt) {
        if (G = this, de = this.sharedValues && (this.pack ? new Array(this.maxPrivatePackedValues || 16).concat(this.sharedValues) : this.sharedValues), this.structures) return Q = this.structures, Ct();
        (!Q || Q.length > 0) && (Q = []);
      } else G = Yr, (!Q || Q.length > 0) && (Q = []), de = null;
      return Ct();
    }
    decodeMultiple(e, n) {
      let r, s = 0;
      try {
        let i = e.length;
        yt = true;
        let o = this ? this.decode(e, i) : dr.decode(e, i);
        if (n) {
          if (n(o) === false) return;
          for (; v < i; ) if (s = v, n(Ct()) === false) return;
        } else {
          for (r = [
            o
          ]; v < i; ) s = v, r.push(Ct());
          return r;
        }
      } catch (i) {
        throw i.lastPosition = s, i.values = r, i;
      } finally {
        yt = false, $n();
      }
    }
  }
  function Ct() {
    try {
      let t = K();
      if (re) {
        if (v >= re.postBundlePosition) {
          let e = new Error("Unexpected bundle position");
          throw e.incomplete = true, e;
        }
        v = re.postBundlePosition, re = null;
      }
      if (v == ze) Q = null, $ = null, me && (me = null);
      else if (v > ze) {
        let e = new Error("Unexpected end of CBOR data");
        throw e.incomplete = true, e;
      } else if (!yt) throw new Error("Data read, but end of buffer not reached");
      return t;
    } catch (t) {
      throw $n(), (t instanceof RangeError || t.message.startsWith("Unexpected end of buffer")) && (t.incomplete = true), t;
    }
  }
  function K() {
    let t = $[v++], e = t >> 5;
    if (t = t & 31, t > 23) switch (t) {
      case 24:
        t = $[v++];
        break;
      case 25:
        if (e == 7) return Ga();
        t = ce.getUint16(v), v += 2;
        break;
      case 26:
        if (e == 7) {
          let n = ce.getFloat32(v);
          if (G.useFloat32 > 2) {
            let r = lr[($[v] & 127) << 1 | $[v + 1] >> 7];
            return v += 4, (r * n + (n > 0 ? 0.5 : -0.5) >> 0) / r;
          }
          return v += 4, n;
        }
        t = ce.getUint32(v), v += 4;
        break;
      case 27:
        if (e == 7) {
          let n = ce.getFloat64(v);
          return v += 8, n;
        }
        if (e > 1) {
          if (ce.getUint32(v) > 0) throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");
          t = ce.getUint32(v + 4);
        } else G.int64AsNumber ? (t = ce.getUint32(v) * 4294967296, t += ce.getUint32(v + 4)) : t = ce.getBigUint64(v);
        v += 8;
        break;
      case 31:
        switch (e) {
          case 2:
          case 3:
            throw new Error("Indefinite length not supported for byte or text strings");
          case 4:
            let n = [], r, s = 0;
            for (; (r = K()) != Je; ) {
              if (s >= ct) throw new Error(`Array length exceeds ${ct}`);
              n[s++] = r;
            }
            return e == 4 ? n : e == 3 ? n.join("") : Buffer.concat(n);
          case 5:
            let i;
            if (G.mapsAsObjects) {
              let o = {}, a = 0;
              if (G.keyMap) for (; (i = K()) != Je; ) {
                if (a++ >= Re) throw new Error(`Property count exceeds ${Re}`);
                o[we(G.decodeKey(i))] = K();
              }
              else for (; (i = K()) != Je; ) {
                if (a++ >= Re) throw new Error(`Property count exceeds ${Re}`);
                o[we(i)] = K();
              }
              return o;
            } else {
              ft && (G.mapsAsObjects = true, ft = false);
              let o = /* @__PURE__ */ new Map();
              if (G.keyMap) {
                let a = 0;
                for (; (i = K()) != Je; ) {
                  if (a++ >= Re) throw new Error(`Map size exceeds ${Re}`);
                  o.set(G.decodeKey(i), K());
                }
              } else {
                let a = 0;
                for (; (i = K()) != Je; ) {
                  if (a++ >= Re) throw new Error(`Map size exceeds ${Re}`);
                  o.set(i, K());
                }
              }
              return o;
            }
          case 7:
            return Je;
          default:
            throw new Error("Invalid major type for indefinite length " + e);
        }
      default:
        throw new Error("Unknown token " + t);
    }
    switch (e) {
      case 0:
        return t;
      case 1:
        return ~t;
      case 2:
        return Wa(t);
      case 3:
        if (pt >= v) return Kt.slice(v - Jt, (v += t) - Jt);
        if (pt == 0 && ze < 140 && t < 32) {
          let s = t < 16 ? si(t) : qa(t);
          if (s != null) return s;
        }
        return Na(t);
      case 4:
        if (t >= ct) throw new Error(`Array length exceeds ${ct}`);
        let n = new Array(t);
        for (let s = 0; s < t; s++) n[s] = K();
        return n;
      case 5:
        if (t >= Re) throw new Error(`Map size exceeds ${ct}`);
        if (G.mapsAsObjects) {
          let s = {};
          if (G.keyMap) for (let i = 0; i < t; i++) s[we(G.decodeKey(K()))] = K();
          else for (let i = 0; i < t; i++) s[we(K())] = K();
          return s;
        } else {
          ft && (G.mapsAsObjects = true, ft = false);
          let s = /* @__PURE__ */ new Map();
          if (G.keyMap) for (let i = 0; i < t; i++) s.set(G.decodeKey(K()), K());
          else for (let i = 0; i < t; i++) s.set(K(), K());
          return s;
        }
      case 6:
        if (t >= Jr) {
          let s = Q[t & 8191];
          if (s) return s.read || (s.read = Ln(s)), s.read();
          if (t < 65536) {
            if (t == za) {
              let i = tt(), o = K(), a = K();
              Pn(o, a);
              let c = {};
              if (G.keyMap) for (let l = 2; l < i; l++) {
                let h = G.decodeKey(a[l - 2]);
                c[we(h)] = K();
              }
              else for (let l = 2; l < i; l++) {
                let h = a[l - 2];
                c[we(h)] = K();
              }
              return c;
            } else if (t == Va) {
              let i = tt(), o = K();
              for (let a = 2; a < i; a++) Pn(o++, K());
              return K();
            } else if (t == Jr) return Qa();
            if (G.getShared && (ur(), s = Q[t & 8191], s)) return s.read || (s.read = Ln(s)), s.read();
          }
        }
        let r = te[t];
        if (r) return r.handlesRead ? r(K) : r(K());
        {
          let s = K();
          for (let i = 0; i < jn.length; i++) {
            let o = jn[i](t, s);
            if (o !== void 0) return o;
          }
          return new qe(s, t);
        }
      case 7:
        switch (t) {
          case 20:
            return false;
          case 21:
            return true;
          case 22:
            return null;
          case 23:
            return;
          default:
            let s = (de || Fe())[t];
            if (s !== void 0) return s;
            throw new Error("Unknown token " + t);
        }
      default:
        if (isNaN(t)) {
          let s = new Error("Unexpected end of CBOR data");
          throw s.incomplete = true, s;
        }
        throw new Error("Unknown CBOR token " + t);
    }
  }
  const Zr = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
  function Ln(t) {
    if (!t) throw new Error("Structure is required in record definition");
    function e() {
      let n = $[v++];
      if (n = n & 31, n > 23) switch (n) {
        case 24:
          n = $[v++];
          break;
        case 25:
          n = ce.getUint16(v), v += 2;
          break;
        case 26:
          n = ce.getUint32(v), v += 4;
          break;
        default:
          throw new Error("Expected array header, but got " + $[v - 1]);
      }
      let r = this.compiledReader;
      for (; r; ) {
        if (r.propertyCount === n) return r(K);
        r = r.next;
      }
      if (this.slowReads++ >= ri) {
        let i = this.length == n ? this : this.slice(0, n);
        return r = G.keyMap ? new Function("r", "return {" + i.map((o) => G.decodeKey(o)).map((o) => Zr.test(o) ? we(o) + ":r()" : "[" + JSON.stringify(o) + "]:r()").join(",") + "}") : new Function("r", "return {" + i.map((o) => Zr.test(o) ? we(o) + ":r()" : "[" + JSON.stringify(o) + "]:r()").join(",") + "}"), this.compiledReader && (r.next = this.compiledReader), r.propertyCount = n, this.compiledReader = r, r(K);
      }
      let s = {};
      if (G.keyMap) for (let i = 0; i < n; i++) s[we(G.decodeKey(this[i]))] = K();
      else for (let i = 0; i < n; i++) s[we(this[i])] = K();
      return s;
    }
    return t.slowReads = 0, e;
  }
  function we(t) {
    if (typeof t == "string") return t === "__proto__" ? "__proto_" : t;
    if (typeof t == "number" || typeof t == "boolean" || typeof t == "bigint") return t.toString();
    if (t == null) return t + "";
    throw new Error("Invalid property name type " + typeof t);
  }
  let Na = Fn;
  function Fn(t) {
    let e;
    if (t < 16 && (e = si(t))) return e;
    if (t > 64 && Bn) return Bn.decode($.subarray(v, v += t));
    const n = v + t, r = [];
    for (e = ""; v < n; ) {
      const s = $[v++];
      if ((s & 128) === 0) r.push(s);
      else if ((s & 224) === 192) {
        const i = $[v++] & 63;
        r.push((s & 31) << 6 | i);
      } else if ((s & 240) === 224) {
        const i = $[v++] & 63, o = $[v++] & 63;
        r.push((s & 31) << 12 | i << 6 | o);
      } else if ((s & 248) === 240) {
        const i = $[v++] & 63, o = $[v++] & 63, a = $[v++] & 63;
        let c = (s & 7) << 18 | i << 12 | o << 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 && (e += se.apply(String, r), r.length = 0);
    }
    return r.length > 0 && (e += se.apply(String, r)), e;
  }
  let se = String.fromCharCode;
  function qa(t) {
    let e = v, n = new Array(t);
    for (let r = 0; r < t; r++) {
      const s = $[v++];
      if ((s & 128) > 0) {
        v = e;
        return;
      }
      n[r] = s;
    }
    return se.apply(String, n);
  }
  function si(t) {
    if (t < 4) if (t < 2) {
      if (t === 0) return "";
      {
        let e = $[v++];
        if ((e & 128) > 1) {
          v -= 1;
          return;
        }
        return se(e);
      }
    } else {
      let e = $[v++], n = $[v++];
      if ((e & 128) > 0 || (n & 128) > 0) {
        v -= 2;
        return;
      }
      if (t < 3) return se(e, n);
      let r = $[v++];
      if ((r & 128) > 0) {
        v -= 3;
        return;
      }
      return se(e, n, r);
    }
    else {
      let e = $[v++], n = $[v++], r = $[v++], s = $[v++];
      if ((e & 128) > 0 || (n & 128) > 0 || (r & 128) > 0 || (s & 128) > 0) {
        v -= 4;
        return;
      }
      if (t < 6) {
        if (t === 4) return se(e, n, r, s);
        {
          let i = $[v++];
          if ((i & 128) > 0) {
            v -= 5;
            return;
          }
          return se(e, n, r, s, i);
        }
      } else if (t < 8) {
        let i = $[v++], o = $[v++];
        if ((i & 128) > 0 || (o & 128) > 0) {
          v -= 6;
          return;
        }
        if (t < 7) return se(e, n, r, s, i, o);
        let a = $[v++];
        if ((a & 128) > 0) {
          v -= 7;
          return;
        }
        return se(e, n, r, s, i, o, a);
      } else {
        let i = $[v++], o = $[v++], a = $[v++], c = $[v++];
        if ((i & 128) > 0 || (o & 128) > 0 || (a & 128) > 0 || (c & 128) > 0) {
          v -= 8;
          return;
        }
        if (t < 10) {
          if (t === 8) return se(e, n, r, s, i, o, a, c);
          {
            let l = $[v++];
            if ((l & 128) > 0) {
              v -= 9;
              return;
            }
            return se(e, n, r, s, i, o, a, c, l);
          }
        } else if (t < 12) {
          let l = $[v++], h = $[v++];
          if ((l & 128) > 0 || (h & 128) > 0) {
            v -= 10;
            return;
          }
          if (t < 11) return se(e, n, r, s, i, o, a, c, l, h);
          let f = $[v++];
          if ((f & 128) > 0) {
            v -= 11;
            return;
          }
          return se(e, n, r, s, i, o, a, c, l, h, f);
        } else {
          let l = $[v++], h = $[v++], f = $[v++], u = $[v++];
          if ((l & 128) > 0 || (h & 128) > 0 || (f & 128) > 0 || (u & 128) > 0) {
            v -= 12;
            return;
          }
          if (t < 14) {
            if (t === 12) return se(e, n, r, s, i, o, a, c, l, h, f, u);
            {
              let d = $[v++];
              if ((d & 128) > 0) {
                v -= 13;
                return;
              }
              return se(e, n, r, s, i, o, a, c, l, h, f, u, d);
            }
          } else {
            let d = $[v++], g = $[v++];
            if ((d & 128) > 0 || (g & 128) > 0) {
              v -= 14;
              return;
            }
            if (t < 15) return se(e, n, r, s, i, o, a, c, l, h, f, u, d, g);
            let m = $[v++];
            if ((m & 128) > 0) {
              v -= 15;
              return;
            }
            return se(e, n, r, s, i, o, a, c, l, h, f, u, d, g, m);
          }
        }
      }
    }
  }
  function Wa(t) {
    return G.copyBuffers ? Uint8Array.prototype.slice.call($, v, v += t) : $.subarray(v, v += t);
  }
  let ii = new Float32Array(1), kt = new Uint8Array(ii.buffer, 0, 4);
  function Ga() {
    let t = $[v++], e = $[v++], n = (t & 127) >> 2;
    if (n === 31) return e || t & 3 ? NaN : t & 128 ? -1 / 0 : 1 / 0;
    if (n === 0) {
      let r = ((t & 3) << 8 | e) / 16777216;
      return t & 128 ? -r : r;
    }
    return kt[3] = t & 128 | (n >> 1) + 56, kt[2] = (t & 7) << 5 | e >> 3, kt[1] = e << 5, kt[0] = 0, ii[0];
  }
  new Array(4096);
  class qe {
    constructor(e, n) {
      this.value = e, this.tag = n;
    }
  }
  te[0] = (t) => new Date(t);
  te[1] = (t) => new Date(Math.round(t * 1e3));
  te[2] = (t) => {
    let e = BigInt(0);
    for (let n = 0, r = t.byteLength; n < r; n++) e = BigInt(t[n]) + (e << BigInt(8));
    return e;
  };
  te[3] = (t) => BigInt(-1) - te[2](t);
  te[4] = (t) => +(t[1] + "e" + t[0]);
  te[5] = (t) => t[1] * Math.exp(t[0] * Math.log(2));
  const Pn = (t, e) => {
    t = t - 57344;
    let n = Q[t];
    n && n.isShared && ((Q.restoreStructures || (Q.restoreStructures = []))[t] = n), Q[t] = e, e.read = Ln(e);
  };
  te[$a] = (t) => {
    let e = t.length, n = t[1];
    Pn(t[0], n);
    let r = {};
    for (let s = 2; s < e; s++) {
      let i = n[s - 2];
      r[we(i)] = t[s];
    }
    return r;
  };
  te[14] = (t) => re ? re[0].slice(re.position0, re.position0 += t) : new qe(t, 14);
  te[15] = (t) => re ? re[1].slice(re.position1, re.position1 += t) : new qe(t, 15);
  let Ka = {
    Error,
    RegExp
  };
  te[27] = (t) => (Ka[t[0]] || Error)(t[1], t[2]);
  const oi = (t) => {
    if ($[v++] != 132) {
      let n = new Error("Packed values structure must be followed by a 4 element array");
      throw $.length < v && (n.incomplete = true), n;
    }
    let e = t();
    if (!e || !e.length) {
      let n = new Error("Packed values structure must be followed by a 4 element array");
      throw n.incomplete = true, n;
    }
    return de = de ? e.concat(de.slice(e.length)) : e, de.prefixes = t(), de.suffixes = t(), t();
  };
  oi.handlesRead = true;
  te[51] = oi;
  te[Xr] = (t) => {
    if (!de) if (G.getShared) ur();
    else return new qe(t, Xr);
    if (typeof t == "number") return de[16 + (t >= 0 ? 2 * t : -2 * t - 1)];
    let e = new Error("No support for non-integer packed references yet");
    throw t === void 0 && (e.incomplete = true), e;
  };
  te[28] = (t) => {
    me || (me = /* @__PURE__ */ new Map(), me.id = 0);
    let e = me.id++, n = v, r = $[v], s;
    r >> 5 == 4 ? s = [] : s = {};
    let i = {
      target: s
    };
    me.set(e, i);
    let o = t();
    return i.used ? (Object.getPrototypeOf(s) !== Object.getPrototypeOf(o) && (v = n, s = o, me.set(e, {
      target: s
    }), o = t()), Object.assign(s, o)) : (i.target = o, o);
  };
  te[28].handlesRead = true;
  te[29] = (t) => {
    let e = me.get(t);
    return e.used = true, e.target;
  };
  te[258] = (t) => new Set(t);
  (te[259] = (t) => (G.mapsAsObjects && (G.mapsAsObjects = false, ft = true), t())).handlesRead = true;
  function Xe(t, e) {
    return typeof t == "string" ? t + e : t instanceof Array ? t.concat(e) : Object.assign({}, t, e);
  }
  function Fe() {
    if (!de) if (G.getShared) ur();
    else throw new Error("No packed values available");
    return de;
  }
  const Ja = 1399353956;
  jn.push((t, e) => {
    if (t >= 225 && t <= 255) return Xe(Fe().prefixes[t - 224], e);
    if (t >= 28704 && t <= 32767) return Xe(Fe().prefixes[t - 28672], e);
    if (t >= 1879052288 && t <= 2147483647) return Xe(Fe().prefixes[t - 1879048192], e);
    if (t >= 216 && t <= 223) return Xe(e, Fe().suffixes[t - 216]);
    if (t >= 27647 && t <= 28671) return Xe(e, Fe().suffixes[t - 27639]);
    if (t >= 1811940352 && t <= 1879048191) return Xe(e, Fe().suffixes[t - 1811939328]);
    if (t == Ja) return {
      packedValues: de,
      structures: Q.slice(0),
      version: e
    };
    if (t == 55799) return e;
  });
  const Xa = new Uint8Array(new Uint16Array([
    1
  ]).buffer)[0] == 1, Qr = [
    Uint8Array,
    Uint8ClampedArray,
    Uint16Array,
    Uint32Array,
    typeof BigUint64Array > "u" ? {
      name: "BigUint64Array"
    } : BigUint64Array,
    Int8Array,
    Int16Array,
    Int32Array,
    typeof BigInt64Array > "u" ? {
      name: "BigInt64Array"
    } : BigInt64Array,
    Float32Array,
    Float64Array
  ], Ya = [
    64,
    68,
    69,
    70,
    71,
    72,
    77,
    78,
    79,
    85,
    86
  ];
  for (let t = 0; t < Qr.length; t++) Za(Qr[t], Ya[t]);
  function Za(t, e) {
    let n = "get" + t.name.slice(0, -5), r;
    typeof t == "function" ? r = t.BYTES_PER_ELEMENT : t = null;
    for (let s = 0; s < 2; s++) {
      if (!s && r == 1) continue;
      let i = r == 2 ? 1 : r == 4 ? 2 : r == 8 ? 3 : 0;
      te[s ? e : e - 4] = r == 1 || s == Xa ? (o) => {
        if (!t) throw new Error("Could not find typed array for code " + e);
        return !G.copyBuffers && (r === 1 || r === 2 && !(o.byteOffset & 1) || r === 4 && !(o.byteOffset & 3) || r === 8 && !(o.byteOffset & 7)) ? new t(o.buffer, o.byteOffset, o.byteLength >> i) : new t(Uint8Array.prototype.slice.call(o, 0).buffer);
      } : (o) => {
        if (!t) throw new Error("Could not find typed array for code " + e);
        let a = new DataView(o.buffer, o.byteOffset, o.byteLength), c = o.length >> i, l = new t(c), h = a[n];
        for (let f = 0; f < c; f++) l[f] = h.call(a, f << i, s);
        return l;
      };
    }
  }
  function Qa() {
    let t = tt(), e = v + K();
    for (let r = 2; r < t; r++) {
      let s = tt();
      v += s;
    }
    let n = v;
    return v = e, re = [
      Fn(tt()),
      Fn(tt())
    ], re.position0 = 0, re.position1 = 0, re.postBundlePosition = v, v = n, K();
  }
  function tt() {
    let t = $[v++] & 31;
    if (t > 23) switch (t) {
      case 24:
        t = $[v++];
        break;
      case 25:
        t = ce.getUint16(v), v += 2;
        break;
      case 26:
        t = ce.getUint32(v), v += 4;
        break;
    }
    return t;
  }
  function ur() {
    if (G.getShared) {
      let t = ai(() => ($ = null, G.getShared())) || {}, e = t.structures || [];
      G.sharedVersion = t.version, de = G.sharedValues = t.packedValues, Q === true ? G.structures = Q = e : Q.splice.apply(Q, [
        0,
        e.length
      ].concat(e));
    }
  }
  function ai(t) {
    let e = ze, n = v, r = Jt, s = pt, i = Kt, o = me, a = re, c = new Uint8Array($.slice(0, ze)), l = Q, h = G, f = yt, u = t();
    return ze = e, v = n, Jt = r, pt = s, Kt = i, me = o, re = a, $ = c, yt = f, Q = l, G = h, ce = new DataView($.buffer, $.byteOffset, $.byteLength), u;
  }
  function $n() {
    $ = null, me = null, Q = null;
  }
  const lr = new Array(147);
  for (let t = 0; t < 256; t++) lr[t] = +("1e" + Math.floor(45.15 - t * 0.30103));
  let dr = new bt({
    useRecords: false
  });
  const ci = dr.decode;
  dr.decodeMultiple;
  let Mt;
  try {
    Mt = new TextEncoder();
  } catch {
  }
  let Vn, fi;
  const rn = typeof globalThis == "object" && globalThis.Buffer, St = typeof rn < "u", wn = St ? rn.allocUnsafeSlow : Uint8Array, es = St ? rn : Uint8Array, ts = 256, ns = St ? 4294967296 : 2144337920;
  let xn, b, Y, p = 0, De, ne = null;
  const ec = 61440, tc = /[\u0080-\uFFFF]/, _e = /* @__PURE__ */ Symbol("record-id");
  class ui extends bt {
    constructor(e) {
      super(e), this.offset = 0;
      let n, r, s, i, o;
      e = e || {};
      let a = es.prototype.utf8Write ? function(_, T, A) {
        return b.utf8Write(_, T, A);
      } : Mt && Mt.encodeInto ? function(_, T) {
        return Mt.encodeInto(_, b.subarray(T)).written;
      } : false, c = this, l = e.structures || e.saveStructures, h = e.maxSharedStructures;
      if (h == null && (h = l ? 128 : 0), h > 8190) throw new Error("Maximum maxSharedStructure is 8190");
      let f = e.sequential;
      f && (h = 0), this.structures || (this.structures = []), this.saveStructures && (this.saveShared = this.saveStructures);
      let u, d, g = e.sharedValues, m;
      if (g) {
        m = /* @__PURE__ */ Object.create(null);
        for (let _ = 0, T = g.length; _ < T; _++) m[g[_]] = _;
      }
      let S = [], M = 0, B = 0;
      this.mapEncode = function(_, T) {
        return this._keyMap && !this._mapped && _.constructor.name === "Array" && (_ = _.map((A) => this.encodeKeys(A))), this.encode(_, T);
      }, this.encode = function(_, T) {
        if (b || (b = new wn(8192), Y = new DataView(b.buffer, 0, 8192), p = 0), De = b.length - 10, De - p < 2048 ? (b = new wn(b.length), Y = new DataView(b.buffer, 0, b.length), De = b.length - 10, p = 0) : T === is && (p = p + 7 & 2147483640), n = p, c.useSelfDescribedHeader && (Y.setUint32(p, 3654940416), p += 3), o = c.structuredClone ? /* @__PURE__ */ new Map() : null, c.bundleStrings && typeof _ != "string" ? (ne = [], ne.size = 1 / 0) : ne = null, r = c.structures, r) {
          if (r.uninitialized) {
            let I = c.getShared() || {};
            c.structures = r = I.structures || [], c.sharedVersion = I.version;
            let E = c.sharedValues = I.packedValues;
            if (E) {
              m = {};
              for (let V = 0, y = E.length; V < y; V++) m[E[V]] = V;
            }
          }
          let A = r.length;
          if (A > h && !f && (A = h), !r.transitions) {
            r.transitions = /* @__PURE__ */ Object.create(null);
            for (let I = 0; I < A; I++) {
              let E = r[I];
              if (!E) continue;
              let V, y = r.transitions;
              for (let O = 0, D = E.length; O < D; O++) {
                y[_e] === void 0 && (y[_e] = I);
                let P = E[O];
                V = y[P], V || (V = y[P] = /* @__PURE__ */ Object.create(null)), y = V;
              }
              y[_e] = I | 1048576;
            }
          }
          f || (r.nextId = A);
        }
        if (s && (s = false), i = r || [], d = m, e.pack) {
          let A = /* @__PURE__ */ new Map();
          if (A.values = [], A.encoder = c, A.maxValues = e.maxPrivatePackedValues || (m ? 16 : 1 / 0), A.objectMap = m || false, A.samplingPackedValues = u, Bt(_, A), A.values.length > 0) {
            b[p++] = 216, b[p++] = 51, ke(4);
            let I = A.values;
            w(I), ke(0), ke(0), d = Object.create(m || null);
            for (let E = 0, V = I.length; E < V; E++) d[I[E]] = E;
          }
        }
        xn = T & vn;
        try {
          if (xn) return;
          if (w(_), ne && ss(n, w), c.offset = p, o && o.idsToInsert) {
            p += o.idsToInsert.length * 2, p > De && U(p), c.offset = p;
            let A = sc(b.subarray(n, p), o.idsToInsert);
            return o = null, A;
          }
          return T & is ? (b.start = n, b.end = p, b) : b.subarray(n, p);
        } finally {
          if (r) {
            if (B < 10 && B++, r.length > h && (r.length = h), M > 1e4) r.transitions = null, B = 0, M = 0, S.length > 0 && (S = []);
            else if (S.length > 0 && !f) {
              for (let A = 0, I = S.length; A < I; A++) S[A][_e] = void 0;
              S = [];
            }
          }
          if (s && c.saveShared) {
            c.structures.length > h && (c.structures = c.structures.slice(0, h));
            let A = b.subarray(n, p);
            return c.updateSharedData() === false ? c.encode(_) : A;
          }
          T & ic && (p = n);
        }
      }, this.findCommonStringsToPack = () => (u = /* @__PURE__ */ new Map(), m || (m = /* @__PURE__ */ Object.create(null)), (_) => {
        let T = _ && _.threshold || 4, A = this.pack ? _.maxPrivatePackedValues || 16 : 0;
        g || (g = this.sharedValues = []);
        for (let [I, E] of u) E.count > T && (m[I] = A++, g.push(I), s = true);
        for (; this.saveShared && this.updateSharedData() === false; ) ;
        u = null;
      });
      const w = (_) => {
        p > De && (b = U(p));
        var T = typeof _, A;
        if (T === "string") {
          if (d) {
            let y = d[_];
            if (y >= 0) {
              y < 16 ? b[p++] = y + 224 : (b[p++] = 198, y & 1 ? w(15 - y >> 1) : w(y - 16 >> 1));
              return;
            } else if (u && !e.pack) {
              let O = u.get(_);
              O ? O.count++ : u.set(_, {
                count: 1
              });
            }
          }
          let I = _.length;
          if (ne && I >= 4 && I < 1024) {
            if ((ne.size += I) > ec) {
              let O, D = (ne[0] ? ne[0].length * 3 + ne[1].length : 0) + 10;
              p + D > De && (b = U(p + D)), b[p++] = 217, b[p++] = 223, b[p++] = 249, b[p++] = ne.position ? 132 : 130, b[p++] = 26, O = p - n, p += 4, ne.position && ss(n, w), ne = [
                "",
                ""
              ], ne.size = 0, ne.position = O;
            }
            let y = tc.test(_);
            ne[y ? 0 : 1] += _, b[p++] = y ? 206 : 207, w(I);
            return;
          }
          let E;
          I < 32 ? E = 1 : I < 256 ? E = 2 : I < 65536 ? E = 3 : E = 5;
          let V = I * 3;
          if (p + V > De && (b = U(p + V)), I < 64 || !a) {
            let y, O, D, P = p + E;
            for (y = 0; y < I; y++) O = _.charCodeAt(y), O < 128 ? b[P++] = O : O < 2048 ? (b[P++] = O >> 6 | 192, b[P++] = O & 63 | 128) : (O & 64512) === 55296 && ((D = _.charCodeAt(y + 1)) & 64512) === 56320 ? (O = 65536 + ((O & 1023) << 10) + (D & 1023), y++, b[P++] = O >> 18 | 240, b[P++] = O >> 12 & 63 | 128, b[P++] = O >> 6 & 63 | 128, b[P++] = O & 63 | 128) : (b[P++] = O >> 12 | 224, b[P++] = O >> 6 & 63 | 128, b[P++] = O & 63 | 128);
            A = P - p - E;
          } else A = a(_, p + E, V);
          A < 24 ? b[p++] = 96 | A : A < 256 ? (E < 2 && b.copyWithin(p + 2, p + 1, p + 1 + A), b[p++] = 120, b[p++] = A) : A < 65536 ? (E < 3 && b.copyWithin(p + 3, p + 2, p + 2 + A), b[p++] = 121, b[p++] = A >> 8, b[p++] = A & 255) : (E < 5 && b.copyWithin(p + 5, p + 3, p + 3 + A), b[p++] = 122, Y.setUint32(p, A), p += 4), p += A;
        } else if (T === "number") if (!this.alwaysUseFloat && _ >>> 0 === _) _ < 24 ? b[p++] = _ : _ < 256 ? (b[p++] = 24, b[p++] = _) : _ < 65536 ? (b[p++] = 25, b[p++] = _ >> 8, b[p++] = _ & 255) : (b[p++] = 26, Y.setUint32(p, _), p += 4);
        else if (!this.alwaysUseFloat && _ >> 0 === _) _ >= -24 ? b[p++] = 31 - _ : _ >= -256 ? (b[p++] = 56, b[p++] = ~_) : _ >= -65536 ? (b[p++] = 57, Y.setUint16(p, ~_), p += 2) : (b[p++] = 58, Y.setUint32(p, ~_), p += 4);
        else {
          let I;
          if ((I = this.useFloat32) > 0 && _ < 4294967296 && _ >= -2147483648) {
            b[p++] = 250, Y.setFloat32(p, _);
            let E;
            if (I < 4 || (E = _ * lr[(b[p] & 127) << 1 | b[p + 1] >> 7]) >> 0 === E) {
              p += 4;
              return;
            } else p--;
          }
          b[p++] = 251, Y.setFloat64(p, _), p += 8;
        }
        else if (T === "object") if (!_) b[p++] = 246;
        else {
          if (o) {
            let E = o.get(_);
            if (E) {
              if (b[p++] = 216, b[p++] = 29, b[p++] = 25, !E.references) {
                let V = o.idsToInsert || (o.idsToInsert = []);
                E.references = [], V.push(E);
              }
              E.references.push(p - n), p += 2;
              return;
            } else o.set(_, {
              offset: p - n
            });
          }
          let I = _.constructor;
          if (I === Object) N(_);
          else if (I === Array) {
            A = _.length, A < 24 ? b[p++] = 128 | A : ke(A);
            for (let E = 0; E < A; E++) w(_[E]);
          } else if (I === Map) if ((this.mapsAsObjects ? this.useTag259ForMaps !== false : this.useTag259ForMaps) && (b[p++] = 217, b[p++] = 1, b[p++] = 3), A = _.size, A < 24 ? b[p++] = 160 | A : A < 256 ? (b[p++] = 184, b[p++] = A) : A < 65536 ? (b[p++] = 185, b[p++] = A >> 8, b[p++] = A & 255) : (b[p++] = 186, Y.setUint32(p, A), p += 4), c.keyMap) for (let [E, V] of _) w(c.encodeKey(E)), w(V);
          else for (let [E, V] of _) w(E), w(V);
          else {
            for (let E = 0, V = Vn.length; E < V; E++) {
              let y = fi[E];
              if (_ instanceof y) {
                let O = Vn[E], D = O.tag;
                D == null && (D = O.getTag && O.getTag.call(this, _)), D < 24 ? b[p++] = 192 | D : D < 256 ? (b[p++] = 216, b[p++] = D) : D < 65536 ? (b[p++] = 217, b[p++] = D >> 8, b[p++] = D & 255) : D > -1 && (b[p++] = 218, Y.setUint32(p, D), p += 4), O.encode.call(this, _, w, U);
                return;
              }
            }
            if (_[Symbol.iterator]) {
              if (xn) {
                let E = new Error("Iterable should be serialized as iterator");
                throw E.iteratorNotHandled = true, E;
              }
              b[p++] = 159;
              for (let E of _) w(E);
              b[p++] = 255;
              return;
            }
            if (_[Symbol.asyncIterator] || Sn(_)) {
              let E = new Error("Iterable/blob should be serialized as iterator");
              throw E.iteratorNotHandled = true, E;
            }
            if (this.useToJSON && _.toJSON) {
              const E = _.toJSON();
              if (E !== _) return w(E);
            }
            N(_);
          }
        }
        else if (T === "boolean") b[p++] = _ ? 245 : 244;
        else if (T === "bigint") {
          if (_ < BigInt(1) << BigInt(64) && _ >= 0) b[p++] = 27, Y.setBigUint64(p, _);
          else if (_ > -(BigInt(1) << BigInt(64)) && _ < 0) b[p++] = 59, Y.setBigUint64(p, -_ - BigInt(1));
          else if (this.largeBigIntToFloat) b[p++] = 251, Y.setFloat64(p, Number(_));
          else {
            _ >= BigInt(0) ? b[p++] = 194 : (b[p++] = 195, _ = BigInt(-1) - _);
            let I = [];
            for (; _; ) I.push(Number(_ & BigInt(255))), _ >>= BigInt(8);
            zn(new Uint8Array(I.reverse()), U);
            return;
          }
          p += 8;
        } else if (T === "undefined") b[p++] = 247;
        else throw new Error("Unknown type: " + T);
      }, N = this.useRecords === false ? this.variableMapSize ? (_) => {
        let T = Object.keys(_), A = Object.values(_), I = T.length;
        if (I < 24 ? b[p++] = 160 | I : I < 256 ? (b[p++] = 184, b[p++] = I) : I < 65536 ? (b[p++] = 185, b[p++] = I >> 8, b[p++] = I & 255) : (b[p++] = 186, Y.setUint32(p, I), p += 4), c.keyMap) for (let E = 0; E < I; E++) w(c.encodeKey(T[E])), w(A[E]);
        else for (let E = 0; E < I; E++) w(T[E]), w(A[E]);
      } : (_) => {
        b[p++] = 185;
        let T = p - n;
        p += 2;
        let A = 0;
        if (c.keyMap) for (let I in _) (typeof _.hasOwnProperty != "function" || _.hasOwnProperty(I)) && (w(c.encodeKey(I)), w(_[I]), A++);
        else for (let I in _) (typeof _.hasOwnProperty != "function" || _.hasOwnProperty(I)) && (w(I), w(_[I]), A++);
        b[T++ + n] = A >> 8, b[T + n] = A & 255;
      } : (_, T) => {
        let A, I = i.transitions || (i.transitions = /* @__PURE__ */ Object.create(null)), E = 0, V = 0, y, O;
        if (this.keyMap) {
          O = Object.keys(_).map((P) => this.encodeKey(P)), V = O.length;
          for (let P = 0; P < V; P++) {
            let J = O[P];
            A = I[J], A || (A = I[J] = /* @__PURE__ */ Object.create(null), E++), I = A;
          }
        } else for (let P in _) (typeof _.hasOwnProperty != "function" || _.hasOwnProperty(P)) && (A = I[P], A || (I[_e] & 1048576 && (y = I[_e] & 65535), A = I[P] = /* @__PURE__ */ Object.create(null), E++), I = A, V++);
        let D = I[_e];
        if (D !== void 0) D &= 65535, b[p++] = 217, b[p++] = D >> 8 | 224, b[p++] = D & 255;
        else if (O || (O = I.__keys__ || (I.__keys__ = Object.keys(_))), y === void 0 ? (D = i.nextId++, D || (D = 0, i.nextId = 1), D >= ts && (i.nextId = (D = h) + 1)) : D = y, i[D] = O, D < h) {
          b[p++] = 217, b[p++] = D >> 8 | 224, b[p++] = D & 255, I = i.transitions;
          for (let P = 0; P < V; P++) (I[_e] === void 0 || I[_e] & 1048576) && (I[_e] = D), I = I[O[P]];
          I[_e] = D | 1048576, s = true;
        } else {
          if (I[_e] = D, Y.setUint32(p, 3655335680), p += 3, E && (M += B * E), S.length >= ts - h && (S.shift()[_e] = void 0), S.push(I), ke(V + 2), w(57344 + D), w(O), T) return;
          for (let P in _) (typeof _.hasOwnProperty != "function" || _.hasOwnProperty(P)) && w(_[P]);
          return;
        }
        if (V < 24 ? b[p++] = 128 | V : ke(V), !T) for (let P in _) (typeof _.hasOwnProperty != "function" || _.hasOwnProperty(P)) && w(_[P]);
      }, U = (_) => {
        let T;
        if (_ > 16777216) {
          if (_ - n > ns) throw new Error("Encoded buffer would be larger than maximum buffer size");
          T = Math.min(ns, Math.round(Math.max((_ - n) * (_ > 67108864 ? 1.25 : 2), 4194304) / 4096) * 4096);
        } else T = (Math.max(_ - n << 2, b.length - 1) >> 12) + 1 << 12;
        let A = new wn(T);
        return Y = new DataView(A.buffer, 0, T), b.copy ? b.copy(A, 0, n, _) : A.set(b.slice(n, _)), p -= n, n = 0, De = A.length - 10, b = A;
      };
      let j = 100, z = 1e3;
      this.encodeAsIterable = function(_, T) {
        return L(_, T, F);
      }, this.encodeAsAsyncIterable = function(_, T) {
        return L(_, T, W);
      };
      function* F(_, T, A) {
        let I = _.constructor;
        if (I === Object) {
          let E = c.useRecords !== false;
          E ? N(_, true) : rs(Object.keys(_).length, 160);
          for (let V in _) {
            let y = _[V];
            E || w(V), y && typeof y == "object" ? T[V] ? yield* F(y, T[V]) : yield* C(y, T, V) : w(y);
          }
        } else if (I === Array) {
          let E = _.length;
          ke(E);
          for (let V = 0; V < E; V++) {
            let y = _[V];
            y && (typeof y == "object" || p - n > j) ? T.element ? yield* F(y, T.element) : yield* C(y, T, "element") : w(y);
          }
        } else if (_[Symbol.iterator] && !_.buffer) {
          b[p++] = 159;
          for (let E of _) E && (typeof E == "object" || p - n > j) ? T.element ? yield* F(E, T.element) : yield* C(E, T, "element") : w(E);
          b[p++] = 255;
        } else Sn(_) ? (rs(_.size, 64), yield b.subarray(n, p), yield _, R()) : _[Symbol.asyncIterator] ? (b[p++] = 159, yield b.subarray(n, p), yield _, R(), b[p++] = 255) : w(_);
        A && p > n ? yield b.subarray(n, p) : p - n > j && (yield b.subarray(n, p), R());
      }
      function* C(_, T, A) {
        let I = p - n;
        try {
          w(_), p - n > j && (yield b.subarray(n, p), R());
        } catch (E) {
          if (E.iteratorNotHandled) T[A] = {}, p = n + I, yield* F.call(this, _, T[A]);
          else throw E;
        }
      }
      function R() {
        j = z, c.encode(null, vn);
      }
      function L(_, T, A) {
        return T && T.chunkThreshold ? j = z = T.chunkThreshold : j = 100, _ && typeof _ == "object" ? (c.encode(null, vn), A(_, c.iterateProperties || (c.iterateProperties = {}), true)) : [
          c.encode(_)
        ];
      }
      async function* W(_, T) {
        for (let A of F(_, T, true)) {
          let I = A.constructor;
          if (I === es || I === Uint8Array) yield A;
          else if (Sn(A)) {
            let E = A.stream().getReader(), V;
            for (; !(V = await E.read()).done; ) yield V.value;
          } else if (A[Symbol.asyncIterator]) for await (let E of A) R(), E ? yield* W(E, T.async || (T.async = {})) : yield c.encode(E);
          else yield A;
        }
      }
    }
    useBuffer(e) {
      b = e, Y = new DataView(b.buffer, b.byteOffset, b.byteLength), p = 0;
    }
    clearSharedData() {
      this.structures && (this.structures = []), this.sharedValues && (this.sharedValues = void 0);
    }
    updateSharedData() {
      let e = this.sharedVersion || 0;
      this.sharedVersion = e + 1;
      let n = this.structures.slice(0), r = new li(n, this.sharedValues, this.sharedVersion), s = this.saveShared(r, (i) => (i && i.version || 0) == e);
      return s === false ? (r = this.getShared() || {}, this.structures = r.structures || [], this.sharedValues = r.packedValues, this.sharedVersion = r.version, this.structures.nextId = this.structures.length) : n.forEach((i, o) => this.structures[o] = i), s;
    }
  }
  function rs(t, e) {
    t < 24 ? b[p++] = e | t : t < 256 ? (b[p++] = e | 24, b[p++] = t) : t < 65536 ? (b[p++] = e | 25, b[p++] = t >> 8, b[p++] = t & 255) : (b[p++] = e | 26, Y.setUint32(p, t), p += 4);
  }
  class li {
    constructor(e, n, r) {
      this.structures = e, this.packedValues = n, this.version = r;
    }
  }
  function ke(t) {
    t < 24 ? b[p++] = 128 | t : t < 256 ? (b[p++] = 152, b[p++] = t) : t < 65536 ? (b[p++] = 153, b[p++] = t >> 8, b[p++] = t & 255) : (b[p++] = 154, Y.setUint32(p, t), p += 4);
  }
  const nc = typeof Blob > "u" ? function() {
  } : Blob;
  function Sn(t) {
    if (t instanceof nc) return true;
    let e = t[Symbol.toStringTag];
    return e === "Blob" || e === "File";
  }
  function Bt(t, e) {
    switch (typeof t) {
      case "string":
        if (t.length > 3) {
          if (e.objectMap[t] > -1 || e.values.length >= e.maxValues) return;
          let r = e.get(t);
          if (r) ++r.count == 2 && e.values.push(t);
          else if (e.set(t, {
            count: 1
          }), e.samplingPackedValues) {
            let s = e.samplingPackedValues.get(t);
            s ? s.count++ : e.samplingPackedValues.set(t, {
              count: 1
            });
          }
        }
        break;
      case "object":
        if (t) if (t instanceof Array) for (let r = 0, s = t.length; r < s; r++) Bt(t[r], e);
        else {
          let r = !e.encoder.useRecords;
          for (var n in t) t.hasOwnProperty(n) && (r && Bt(n, e), Bt(t[n], e));
        }
        break;
      case "function":
        console.log(t);
    }
  }
  const rc = new Uint8Array(new Uint16Array([
    1
  ]).buffer)[0] == 1;
  fi = [
    Date,
    Set,
    Error,
    RegExp,
    qe,
    ArrayBuffer,
    Uint8Array,
    Uint8ClampedArray,
    Uint16Array,
    Uint32Array,
    typeof BigUint64Array > "u" ? function() {
    } : BigUint64Array,
    Int8Array,
    Int16Array,
    Int32Array,
    typeof BigInt64Array > "u" ? function() {
    } : BigInt64Array,
    Float32Array,
    Float64Array,
    li
  ];
  Vn = [
    {
      tag: 1,
      encode(t, e) {
        let n = t.getTime() / 1e3;
        (this.useTimestamp32 || t.getMilliseconds() === 0) && n >= 0 && n < 4294967296 ? (b[p++] = 26, Y.setUint32(p, n), p += 4) : (b[p++] = 251, Y.setFloat64(p, n), p += 8);
      }
    },
    {
      tag: 258,
      encode(t, e) {
        let n = Array.from(t);
        e(n);
      }
    },
    {
      tag: 27,
      encode(t, e) {
        e([
          t.name,
          t.message
        ]);
      }
    },
    {
      tag: 27,
      encode(t, e) {
        e([
          "RegExp",
          t.source,
          t.flags
        ]);
      }
    },
    {
      getTag(t) {
        return t.tag;
      },
      encode(t, e) {
        e(t.value);
      }
    },
    {
      encode(t, e, n) {
        zn(t, n);
      }
    },
    {
      getTag(t) {
        if (t.constructor === Uint8Array && (this.tagUint8Array || St && this.tagUint8Array !== false)) return 64;
      },
      encode(t, e, n) {
        zn(t, n);
      }
    },
    Ce(68, 1),
    Ce(69, 2),
    Ce(70, 4),
    Ce(71, 8),
    Ce(72, 1),
    Ce(77, 2),
    Ce(78, 4),
    Ce(79, 8),
    Ce(85, 4),
    Ce(86, 8),
    {
      encode(t, e) {
        let n = t.packedValues || [], r = t.structures || [];
        if (n.values.length > 0) {
          b[p++] = 216, b[p++] = 51, ke(4);
          let s = n.values;
          e(s), ke(0), ke(0), packedObjectMap = Object.create(sharedPackedObjectMap || null);
          for (let i = 0, o = s.length; i < o; i++) packedObjectMap[s[i]] = i;
        }
        if (r) {
          Y.setUint32(p, 3655335424), p += 3;
          let s = r.slice(0);
          s.unshift(57344), s.push(new qe(t.version, 1399353956)), e(s);
        } else e(new qe(t.version, 1399353956));
      }
    }
  ];
  function Ce(t, e) {
    return !rc && e > 1 && (t -= 4), {
      tag: t,
      encode: function(r, s) {
        let i = r.byteLength, o = r.byteOffset || 0, a = r.buffer || r;
        s(St ? rn.from(a, o, i) : new Uint8Array(a, o, i));
      }
    };
  }
  function zn(t, e) {
    let n = t.byteLength;
    n < 24 ? b[p++] = 64 + n : n < 256 ? (b[p++] = 88, b[p++] = n) : n < 65536 ? (b[p++] = 89, b[p++] = n >> 8, b[p++] = n & 255) : (b[p++] = 90, Y.setUint32(p, n), p += 4), p + n >= b.length && e(p + n), b.set(t.buffer ? t : new Uint8Array(t), p), p += n;
  }
  function sc(t, e) {
    let n, r = e.length * 2, s = t.length - r;
    e.sort((i, o) => i.offset > o.offset ? 1 : -1);
    for (let i = 0; i < e.length; i++) {
      let o = e[i];
      o.id = i;
      for (let a of o.references) t[a++] = i >> 8, t[a] = i & 255;
    }
    for (; n = e.pop(); ) {
      let i = n.offset;
      t.copyWithin(i + r, i, s), r -= 2;
      let o = i + r;
      t[o++] = 216, t[o++] = 28, s = i;
    }
    return t;
  }
  function ss(t, e) {
    Y.setUint32(ne.position + t, p - ne.position - t + 1);
    let n = ne;
    ne = null, e(n[0]), e(n[1]);
  }
  let hr = new ui({
    useRecords: false
  });
  hr.encode;
  hr.encodeAsIterable;
  hr.encodeAsAsyncIterable;
  const is = 512, ic = 1024, vn = 2048;
  oc = function(t) {
    return new ui({
      tagUint8Array: false,
      useRecords: false
    }).encode(t);
  };
  jd = function(t) {
    return ci(t);
  };
  let ac, fc;
  ac = (t, e) => t.length === e.length && t.every((n, r) => n === e[r]);
  cc = (t, e) => ac(t, e);
  fc = async (t, e) => {
    let n;
    const r = new Promise((s, i) => {
      n = setTimeout(() => i(new uc(`withTimeout: timed out after ${e}ms`)), e);
    });
    try {
      return await Promise.race([
        t,
        r
      ]);
    } finally {
      clearTimeout(n);
    }
  };
  class uc extends Error {
    constructor(e) {
      super(e), this.name = "TimeoutError";
    }
  }
  gr = class extends DOMException {
    constructor(e) {
      super(e ?? "Operation aborted", "AbortError");
    }
  };
  const lc = (t) => t instanceof gr || (t instanceof Error || DOMException && t instanceof DOMException) && t.name === "AbortError";
  Ld = function(t, e) {
    let n = false;
    return new Promise((r, s) => {
      e == null ? void 0 : e.addEventListener("abort", () => {
        n || s(new gr());
      }, {
        once: true
      }), t.then((i) => {
        r(i);
      }).catch((i) => {
        s(i);
      }).finally(() => {
        n = true;
      });
    });
  };
  const ee = "AUTOMERGE_REF_KIND", dc = "AUTOMERGE_REF_CURSOR_MARKER", hc = "automerge:", jt = "\\", Ot = "%5C", di = "@", Lt = "[", An = "]", os = "-", as = [
    jt,
    di,
    "{",
    Lt
  ], cs = /^@(\d+)$/, gc = {
    kind: "index",
    match: (t) => cs.test(t),
    parse: (t) => {
      const e = t.match(cs);
      if (!e) throw new Error(`Invalid index: ${t}`);
      return {
        [ee]: "index",
        index: parseInt(e[1], 10)
      };
    },
    serialize: (t) => `${di}${t.index}`
  }, _c = {
    kind: "match",
    match: (t) => t.startsWith("{") || t.startsWith("%7B"),
    parse: (t) => {
      try {
        const e = decodeURIComponent(t), n = JSON.parse(e);
        if (typeof n != "object" || n === null || Array.isArray(n)) throw new Error("Match pattern must be a plain object");
        return {
          [ee]: "match",
          match: n
        };
      } catch (e) {
        throw new Error(`Invalid match pattern: ${t}. ${e instanceof Error ? e.message : ""}`);
      }
    },
    serialize: (t) => encodeURIComponent(JSON.stringify(t.match))
  }, pc = {
    kind: "cursors",
    match: (t) => t.startsWith(Lt) && t.endsWith(An),
    parse: (t) => {
      const e = t.slice(1, -1);
      if (!e) throw new Error("Invalid cursor range: empty brackets");
      const n = e.indexOf(os);
      if (n === -1) {
        const i = e;
        return {
          [ee]: "cursors",
          start: i,
          end: i
        };
      }
      const r = e.slice(0, n), s = e.slice(n + 1);
      if (!r || !s) throw new Error(`Invalid cursor range: ${t}. Expected format: [cursor] or [start-end]`);
      return {
        [ee]: "cursors",
        start: r,
        end: s
      };
    },
    serialize: (t) => t.start === t.end ? `${Lt}${t.start}${An}` : `${Lt}${t.start}${os}${t.end}${An}`
  }, yc = {
    kind: "key",
    match: (t) => {
      if (t.startsWith(Ot) || t.startsWith(jt)) return true;
      const e = bc(t);
      return !as.some((n) => t.startsWith(n) || e.startsWith(n));
    },
    parse: (t) => t.startsWith(Ot) ? {
      [ee]: "key",
      key: decodeURIComponent(t.slice(Ot.length))
    } : t.startsWith(jt) ? {
      [ee]: "key",
      key: decodeURIComponent(t.slice(jt.length))
    } : {
      [ee]: "key",
      key: decodeURIComponent(t)
    },
    serialize: (t) => {
      const e = as.some((r) => t.key.startsWith(r)), n = encodeURIComponent(t.key);
      return e ? `${Ot}${n}` : n;
    }
  };
  function bc(t) {
    try {
      return decodeURIComponent(t);
    } catch {
      return t;
    }
  }
  const mc = [
    gc,
    _c,
    pc,
    yc
  ];
  function wc(t) {
    for (const e of mc) if (t[ee] === e.kind) return e.serialize(t);
    throw new Error(`No codec found for segment kind: ${t[ee]}`);
  }
  function xc(t) {
    return t.map(wc).join("/");
  }
  function Sc(t) {
    return t.length > 0 ? `#${t.join("|")}` : "";
  }
  function vc(t, e, n) {
    const r = xc(e), s = n ? Sc(n) : "";
    return `${hc}${t}/${r}${s}`;
  }
  function _r(t) {
    return t !== null && typeof t == "object" && !Array.isArray(t);
  }
  function hi(t) {
    return _r(t) && ee in t;
  }
  function gi(t) {
    return _r(t) && dc in t;
  }
  function Ac(t) {
    return _r(t) && !hi(t) && !gi(t);
  }
  function fs(t, e) {
    return Object.entries(e).every(([n, r]) => t[n] === r);
  }
  function Ec(t, e, n) {
    const r = {
      splice(s, i, o) {
        Is(t, e, s, i, o);
      },
      updateText(s) {
        Ji(t, e, s);
      }
    };
    return new Proxy(r, {
      get(s, i) {
        if (i in s) return s[i];
        const a = n[i];
        return typeof a == "function" ? a.bind(n) : a;
      },
      getPrototypeOf() {
        return String.prototype;
      }
    });
  }
  const Ic = new FinalizationRegistry((t) => t());
  class Cc {
    constructor(e, n) {
      __privateAdd(this, _Cc_instances);
      __publicField(this, "docHandle");
      __publicField(this, "path");
      __publicField(this, "range");
      __privateAdd(this, _r2, /* @__PURE__ */ new Set());
      __privateAdd(this, _e2);
      this.docHandle = e;
      const r = e.doc(), { path: s, range: i } = __privateMethod(this, _Cc_instances, i_fn).call(this, r, n);
      this.path = s, this.range = i, __privateSet(this, _e2, () => {
        const o = this.docHandle.doc();
        __privateMethod(this, _Cc_instances, o_fn).call(this, o);
      }), this.docHandle.on("change", __privateGet(this, _e2)), Ic.register(this, () => __privateMethod(this, _Cc_instances, s_fn).call(this), this);
    }
    get rangePositions() {
      if (!this.range) return;
      const e = __privateMethod(this, _Cc_instances, c_fn).call(this);
      if (!e) return;
      const n = this.doc();
      return __privateMethod(this, _Cc_instances, l_fn).call(this, n, e, this.range);
    }
    viewAt(e) {
      return this.docHandle.view(Qe(e)).ref(...this.path);
    }
    value() {
      const e = this.doc(), n = __privateMethod(this, _Cc_instances, c_fn).call(this);
      if (!n) return;
      const r = __privateMethod(this, _Cc_instances, u_fn).call(this, e, n);
      return this.range ? __privateMethod(this, _Cc_instances, d_fn).call(this, e, n, r, this.range) : r;
    }
    doc() {
      return this.docHandle.doc();
    }
    change(e) {
      if (this.docHandle.isReadOnly()) throw new Error("Cannot change a Ref on a read-only handle");
      const n = typeof e == "function" ? e : () => e;
      this.docHandle.change((r) => {
        if (this.path.length === 0 && !this.range) {
          n(r);
          return;
        }
        const s = __privateMethod(this, _Cc_instances, c_fn).call(this);
        if (!s) throw new Error("Cannot resolve path");
        let i;
        if (this.range) {
          const c = __privateMethod(this, _Cc_instances, u_fn).call(this, r, s);
          if (typeof c != "string") throw new Error("Range refs can only be used on string values");
          i = __privateMethod(this, _Cc_instances, d_fn).call(this, r, s, c, this.range);
        } else i = __privateMethod(this, _Cc_instances, u_fn).call(this, r, s);
        const o = typeof i == "string" ? Ec(r, s, i) : i, a = n(o);
        a !== void 0 && (a === null || typeof a == "string" || typeof a == "number" || typeof a == "boolean" || typeof a == "bigint" || console.warn("Ref.change() returned a non-primitive value. For objects and arrays, you should mutate them in place rather than returning a new instance. Returning new instances loses granular change tracking."), this.range ? __privateMethod(this, _Cc_instances, y_fn).call(this, r, s, this.range, a) : __privateMethod(this, _Cc_instances, m_fn).call(this, r, s, a));
      });
    }
    remove() {
      if (this.docHandle.isReadOnly()) throw new Error("Cannot remove from a Ref on a read-only handle");
      if (this.path.length === 0 && !this.range) throw new Error("Cannot remove the root document");
      this.docHandle.change((e) => {
        const n = __privateMethod(this, _Cc_instances, c_fn).call(this);
        if (!n || n.length === 0) throw new Error("Cannot resolve path for removal");
        if (this.range) {
          __privateMethod(this, _Cc_instances, y_fn).call(this, e, n, this.range, "");
          return;
        }
        const r = n.slice(0, -1), s = n[n.length - 1], i = r.length === 0 ? e : __privateMethod(this, _Cc_instances, u_fn).call(this, e, r);
        if (i == null) throw new Error("Cannot remove: parent is null or undefined");
        if (Array.isArray(i)) {
          if (typeof s != "number") throw new Error("Cannot remove from array: key is not a number");
          i.splice(s, 1);
        } else delete i[s];
      });
    }
    onChange(e) {
      const n = (s) => {
        if (__privateMethod(this, _Cc_instances, p_fn).call(this, s.patches)) {
          const i = this.value();
          e(i, s);
        }
      };
      return this.docHandle.on("change", n), __privateGet(this, _r2).add(n), () => {
        this.docHandle.off("change", n), __privateGet(this, _r2).delete(n);
      };
    }
    get url() {
      const e = this.range ? [
        ...this.path,
        this.range
      ] : this.path, n = this.docHandle.isReadOnly() ? Be(this.docHandle.heads()) : void 0;
      return vc(this.docHandle.documentId, e, n);
    }
    equals(e) {
      return this.url === e.url;
    }
    contains(e) {
      if (this.docHandle.documentId !== e.docHandle.documentId || this.docHandle.url !== e.docHandle.url || this.path.length >= e.path.length) return false;
      for (let n = 0; n < this.path.length; n++) if (!__privateMethod(this, _Cc_instances, t_fn).call(this, this.path[n], e.path[n])) return false;
      return true;
    }
    isChildOf(e) {
      if (this.docHandle.documentId !== e.docHandle.documentId || this.docHandle.url !== e.docHandle.url || this.path.length < e.path.length) return false;
      for (let n = 0; n < e.path.length; n++) if (!__privateMethod(this, _Cc_instances, t_fn).call(this, this.path[n], e.path[n])) return false;
      return this.path.length === e.path.length ? this.range !== void 0 && e.range === void 0 : this.path.length === e.path.length + 1;
    }
    overlaps(e) {
      if (this.docHandle.documentId !== e.docHandle.documentId || this.docHandle.url !== e.docHandle.url || !this.range || !e.range || this.path.length !== e.path.length) return false;
      for (let h = 0; h < this.path.length; h++) if (!__privateMethod(this, _Cc_instances, t_fn).call(this, this.path[h], e.path[h])) return false;
      const n = this.doc(), r = __privateMethod(this, _Cc_instances, c_fn).call(this);
      if (!r) return false;
      const s = __privateMethod(this, _Cc_instances, l_fn).call(this, n, r, this.range), i = __privateMethod(this, _Cc_instances, l_fn).call(this, n, r, e.range);
      if (!s || !i) return false;
      const [o, a] = s, [c, l] = i;
      return o < l && c < a;
    }
    isEquivalent(e) {
      if (this === e) return true;
      if (this.docHandle.documentId !== e.docHandle.documentId || !__privateMethod(this, _Cc_instances, n_fn).call(this, e) || this.path.length !== e.path.length || this.range === void 0 != (e.range === void 0)) return false;
      let n = true;
      for (let r = 0; r < this.path.length; r++) if (!__privateMethod(this, _Cc_instances, t_fn).call(this, this.path[r], e.path[r])) {
        n = false;
        break;
      }
      if (n) return !this.range && !e.range ? true : this.range.start === e.range.start && this.range.end === e.range.end;
      for (let r = 0; r < this.path.length; r++) {
        const s = this.path[r].prop, i = e.path[r].prop;
        if (s === void 0 || i === void 0 || s !== i) return false;
      }
      return !this.range && !e.range ? true : this.range.start === e.range.start && this.range.end === e.range.end;
    }
    valueOf() {
      return this.url;
    }
    toString() {
      return this.url;
    }
  }
  _r2 = new WeakMap();
  _e2 = new WeakMap();
  _Cc_instances = new WeakSet();
  s_fn = function() {
    this.docHandle.off("change", __privateGet(this, _e2));
    for (const e of __privateGet(this, _r2)) this.docHandle.off("change", e);
    __privateGet(this, _r2).clear();
  };
  n_fn = function(e) {
    if (this.docHandle.url === e.docHandle.url) return true;
    const n = this.docHandle.heads().join(","), r = e.docHandle.heads().join(",");
    return n === r;
  };
  i_fn = function(e, n) {
    const r = [], s = [];
    let i = e, o;
    for (let a = 0; a < n.length; a++) {
      const c = n[a];
      if (gi(c)) {
        if (a < n.length - 1) throw new Error("cursor() must be the last segment in a ref path. Segments after cursor() are not allowed.");
        o = __privateMethod(this, _Cc_instances, __fn).call(this, e, s, i, c);
        break;
      }
      const l = hi(c) ? __privateMethod(this, _Cc_instances, a_fn).call(this, i, c) : __privateMethod(this, _Cc_instances, h_fn).call(this, i, c);
      if (l[ee] === "cursors") {
        if (a < n.length - 1) throw new Error("Cursor range must be the last segment in a ref path. Segments after cursor range are not allowed.");
        o = l;
        break;
      }
      r.push(l), l.prop !== void 0 && i !== void 0 && i !== null && (s.push(l.prop), i = i[l.prop]);
    }
    return {
      path: r,
      range: o
    };
  };
  a_fn = function(e, n) {
    const r = __privateMethod(this, _Cc_instances, f_fn).call(this, e, n);
    return {
      ...n,
      prop: r
    };
  };
  f_fn = function(e, n) {
    if (e != null) switch (n[ee]) {
      case "key":
        return n.key;
      case "index":
        return n.index;
      case "match": {
        if (!Array.isArray(e)) return;
        const r = e.findIndex((s) => fs(s, n.match));
        return r !== -1 ? r : void 0;
      }
      case "cursors":
        return;
      default:
        return;
    }
  };
  o_fn = function(e) {
    let n = e;
    for (const r of this.path) {
      const s = __privateMethod(this, _Cc_instances, f_fn).call(this, n, r);
      if (r.prop = s, s !== void 0 && n !== void 0 && n !== null) n = n[s];
      else break;
    }
  };
  t_fn = function(e, n) {
    if (e[ee] !== n[ee]) return false;
    switch (e[ee]) {
      case "key":
        return e.key === n.key;
      case "index":
        return e.index === n.index;
      case "match": {
        const r = Object.keys(e.match), s = Object.keys(n.match);
        return r.length !== s.length ? false : r.every((i) => e.match[i] === n.match[i]);
      }
      default:
        return false;
    }
  };
  h_fn = function(e, n) {
    if (typeof n == "string") return {
      [ee]: "key",
      key: n,
      prop: n
    };
    if (typeof n == "number") return {
      [ee]: "index",
      index: n,
      prop: n
    };
    if (Ac(n)) {
      if (!Array.isArray(e)) return {
        [ee]: "match",
        match: n,
        prop: void 0
      };
      const r = e.findIndex((s) => fs(s, n));
      return {
        [ee]: "match",
        match: n,
        prop: r !== -1 ? r : void 0
      };
    }
    throw new Error(`Unsupported path input type: ${typeof n}. Expected string, number, or plain object.`);
  };
  __fn = function(e, n, r, s) {
    const { start: i, end: o } = s;
    if (typeof r != "string") throw new Error(`cursor() can only be used on string values, got ${typeof r}`);
    const a = vr(e, n, i), c = vr(e, n, o);
    if (!a || !c) throw new Error(`Failed to create cursors at positions ${i}-${o}.`);
    return {
      [ee]: "cursors",
      start: a,
      end: c
    };
  };
  c_fn = function() {
    const e = [];
    for (const n of this.path) {
      if (n.prop === void 0) return;
      e.push(n.prop);
    }
    return e;
  };
  u_fn = function(e, n) {
    let r = e;
    for (const s of n) {
      if (r == null) return;
      r = r[s];
    }
    return r;
  };
  d_fn = function(e, n, r, s) {
    const i = __privateMethod(this, _Cc_instances, l_fn).call(this, e, n, s);
    if (i) return r.slice(i[0], i[1]);
  };
  m_fn = function(e, n, r) {
    if (n.length === 0) throw new Error("Internal error: #setValueAt called with empty path. Root document changes should be handled by the caller.");
    const s = __privateMethod(this, _Cc_instances, u_fn).call(this, e, n.slice(0, -1));
    if (s == null) throw new Error("Cannot set value: parent is null or undefined");
    s[n[n.length - 1]] = r;
  };
  y_fn = function(e, n, r, s) {
    const i = __privateMethod(this, _Cc_instances, l_fn).call(this, e, n, r);
    if (!i) throw new Error("Cannot resolve range positions");
    const [o, a] = i;
    Is(e, n, o, a - o, s);
  };
  l_fn = function(e, n, r) {
    const s = Ar(e, n, r.start), i = Ar(e, n, r.end);
    return s !== void 0 && i !== void 0 ? [
      s,
      i
    ] : void 0;
  };
  p_fn = function(e) {
    const n = [];
    for (const r of this.path) {
      if (r.prop === void 0) break;
      n.push(r.prop);
    }
    return n.length === 0 ? false : e.some((r) => __privateMethod(this, _Cc_instances, b_fn).call(this, r.path, n));
  };
  b_fn = function(e, n) {
    const r = Math.min(e.length, n.length);
    return e.slice(0, r).every((s, i) => s === n[i]);
  };
  Nn = (_a3 = class extends Cs {
    constructor(e, n = {}) {
      super();
      __privateAdd(this, _Nn_instances);
      __publicField(this, "documentId");
      __privateAdd(this, _r3);
      __privateAdd(this, _e3);
      __privateAdd(this, _s2);
      __privateAdd(this, _n2, Te());
      __privateAdd(this, _i2, 6e4);
      __privateAdd(this, _a2, {});
      __privateAdd(this, _f2, /* @__PURE__ */ new Map());
      __privateAdd(this, _o2, /* @__PURE__ */ new Map());
      __publicField(this, "isReady", () => this.inState([
        "ready"
      ]));
      __publicField(this, "isUnloaded", () => this.inState([
        "unloaded"
      ]));
      __publicField(this, "isDeleted", () => this.inState([
        "deleted"
      ]));
      __publicField(this, "isUnavailable", () => this.inState([
        "unavailable"
      ]));
      __publicField(this, "inState", (e) => e.some((n) => __privateGet(this, _e3).getSnapshot().matches(n)));
      this.documentId = e, "timeoutDelay" in n && n.timeoutDelay && __privateSet(this, _i2, n.timeoutDelay), "heads" in n && __privateSet(this, _s2, n.heads);
      const r = Te();
      __privateSet(this, _r3, Xn(`automerge-repo:dochandle:${this.documentId.slice(0, 5)}`));
      const s = __privateGet(this, _i2), i = Xs({
        actions: {
          onUpdate: Ve(({ context: o, event: a }) => {
            const c = o.doc;
            ya(a, ls);
            const { callback: l } = a.payload;
            return {
              doc: l(c)
            };
          }),
          onDelete: Ve(() => (this.emit("delete", {
            handle: this
          }), {
            doc: Te()
          })),
          onUnavailable: Ve(() => ({
            doc: Te()
          })),
          onUnload: Ve(() => ({
            doc: Te()
          }))
        }
      }).createMachine({
        initial: "idle",
        context: {
          documentId: e,
          doc: r
        },
        on: {
          UPDATE: {
            actions: "onUpdate"
          },
          UNLOAD: ".unloaded",
          DELETE: ".deleted"
        },
        states: {
          idle: {
            on: {
              BEGIN: "loading"
            }
          },
          loading: {
            on: {
              REQUEST: "requesting",
              DOC_READY: "ready"
            },
            after: {
              [s]: "unavailable"
            }
          },
          requesting: {
            on: {
              DOC_UNAVAILABLE: "unavailable",
              DOC_READY: "ready"
            },
            after: {
              [s]: "unavailable"
            }
          },
          unavailable: {
            entry: "onUnavailable",
            on: {
              DOC_READY: "ready"
            }
          },
          ready: {},
          unloaded: {
            entry: "onUnload",
            on: {
              RELOAD: "loading"
            }
          },
          deleted: {
            entry: "onDelete",
            type: "final"
          }
        }
      });
      __privateSet(this, _e3, _t(i)), __privateGet(this, _e3).subscribe((o) => {
        const a = __privateGet(this, _n2), c = o.context.doc;
        __privateGet(this, _r3).call(this, `\u2192 ${o.value} %o`, c), __privateMethod(this, _Nn_instances, u_fn2).call(this, a, c);
      }), __privateGet(this, _e3).start(), this.begin();
    }
    get url() {
      return ei({
        documentId: this.documentId,
        heads: __privateGet(this, _s2)
      });
    }
    get state() {
      return __privateGet(this, _e3).getSnapshot().value;
    }
    async whenReady(e = [
      "ready"
    ], n) {
      try {
        await fc(__privateMethod(this, _Nn_instances, __fn2).call(this, e, n), __privateGet(this, _i2));
      } catch (r) {
        throw lc(r) ? new gr() : (console.log(`error waiting for ${this.documentId} to be in one of states: ${e.join(", ")}`), r);
      }
    }
    doc() {
      if (!this.isReady()) throw new Error("DocHandle is not ready");
      return __privateGet(this, _s2) ? Mi(__privateGet(this, _Nn_instances, t_get), Be(__privateGet(this, _s2))) : __privateGet(this, _Nn_instances, t_get);
    }
    docSync() {
      return console.warn("docSync is deprecated. Use doc() instead. This function will be removed as part of the 2.0 release."), this.doc();
    }
    heads() {
      if (!this.isReady()) throw new Error("DocHandle is not ready");
      return __privateGet(this, _s2) ? __privateGet(this, _s2) : Qe(Ut(__privateGet(this, _Nn_instances, t_get)));
    }
    begin() {
      __privateGet(this, _e3).send({
        type: Oc
      });
    }
    history() {
      if (this.isReady()) return Wi(__privateGet(this, _Nn_instances, t_get)).map((e) => Qe([
        e
      ]));
    }
    view(e) {
      if (!this.isReady()) throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before calling view().`);
      const n = JSON.stringify(e), r = __privateGet(this, _f2).get(n);
      if (r) return r;
      const s = new Nn(this.documentId, {
        heads: e,
        timeoutDelay: __privateGet(this, _i2)
      });
      return s.update(() => mr(__privateGet(this, _Nn_instances, t_get))), s.doneLoading(), __privateGet(this, _f2).set(n, s), s;
    }
    diff(e, n) {
      if (!this.isReady()) throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before calling diff().`);
      const r = __privateGet(this, _Nn_instances, t_get);
      if (!r) throw new Error("Document not available");
      if (e instanceof Nn) {
        if (!e.isReady()) throw new Error("Cannot diff against a handle that isn't ready");
        const o = e.heads();
        if (!o) throw new Error("Other document's heads not available");
        const a = wr(mr(r), e.doc());
        return cn(a, Be(this.heads()), Be(o));
      }
      const s = n ? e : this.heads() || [], i = n || e;
      return cn(r, Be(s), Be(i));
    }
    metadata(e) {
      if (this.isReady()) return e || (e = this.heads()[0]), Gi(__privateGet(this, _Nn_instances, t_get), Be([
        e
      ])[0]) || void 0;
    }
    update(e) {
      __privateMethod(this, _Nn_instances, c_fn2).call(this, e);
    }
    doneLoading() {
      __privateGet(this, _e3).send({
        type: us
      });
    }
    setSyncInfo(e, n) {
      __privateGet(this, _a2)[e] = n, this.emit("remote-heads", {
        storageId: e,
        heads: n.lastHeads,
        timestamp: n.lastSyncTimestamp
      });
    }
    getRemoteHeads(e) {
      var _a5;
      return (_a5 = __privateGet(this, _a2)[e]) == null ? void 0 : _a5.lastHeads;
    }
    getSyncInfo(e) {
      return __privateGet(this, _a2)[e];
    }
    change(e, n = {}) {
      if (!this.isReady()) throw new Error(`DocHandle#${this.documentId} is in ${this.state} and not ready. Check \`handle.isReady()\` before accessing the document.`);
      if (__privateGet(this, _s2)) throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);
      __privateMethod(this, _Nn_instances, c_fn2).call(this, (r) => Bi(r, n, e));
    }
    changeAt(e, n, r = {}) {
      if (!this.isReady()) throw new Error(`DocHandle#${this.documentId} is not ready. Check \`handle.isReady()\` before accessing the document.`);
      if (__privateGet(this, _s2)) throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);
      let s;
      return __privateMethod(this, _Nn_instances, c_fn2).call(this, (i) => {
        const o = ji(i, Be(e), r, n);
        return s = o.newHeads ? Qe(o.newHeads) : void 0, o.newDoc;
      }), s;
    }
    isReadOnly() {
      return !!__privateGet(this, _s2);
    }
    merge(e) {
      if (!this.isReady() || !e.isReady()) throw new Error("Both handles must be ready to merge");
      if (__privateGet(this, _s2)) throw new Error(`DocHandle#${this.documentId} is in view-only mode at specific heads. Use clone() to create a new document from this state.`);
      const n = e.doc();
      this.update((r) => wr(r, n));
    }
    unavailable() {
      __privateGet(this, _e3).send({
        type: Dc
      });
    }
    request() {
      __privateGet(this, _Nn_instances, h_get) === "loading" && __privateGet(this, _e3).send({
        type: Rc
      });
    }
    unload() {
      __privateGet(this, _e3).send({
        type: Hc
      });
    }
    reload() {
      __privateGet(this, _e3).send({
        type: Tc
      });
    }
    delete() {
      __privateGet(this, _e3).send({
        type: Uc
      });
    }
    broadcast(e) {
      this.emit("ephemeral-message-outbound", {
        handle: this,
        data: new Uint8Array(oc(e))
      });
    }
    metrics() {
      return Es(__privateGet(this, _Nn_instances, t_get));
    }
    ref(...e) {
      var _a5;
      const n = __privateMethod(this, _Nn_instances, d_fn2).call(this, e), r = (_a5 = __privateGet(this, _o2).get(n)) == null ? void 0 : _a5.deref();
      if (r) return r;
      const s = new Cc(this, e);
      return __privateGet(this, _o2).set(n, new WeakRef(s)), s;
    }
  }, _r3 = new WeakMap(), _e3 = new WeakMap(), _s2 = new WeakMap(), _n2 = new WeakMap(), _i2 = new WeakMap(), _a2 = new WeakMap(), _f2 = new WeakMap(), _o2 = new WeakMap(), _Nn_instances = new WeakSet(), t_get = function() {
    var _a5;
    return (_a5 = __privateGet(this, _e3)) == null ? void 0 : _a5.getSnapshot().context.doc;
  }, h_get = function() {
    var _a5;
    return (_a5 = __privateGet(this, _e3)) == null ? void 0 : _a5.getSnapshot().value;
  }, __fn2 = function(e, n) {
    const r = Array.isArray(e) ? e : [
      e
    ];
    return wa(__privateGet(this, _e3), (s) => r.some((i) => s.matches(i)), {
      timeout: __privateGet(this, _i2) * 2,
      ...n
    });
  }, c_fn2 = function(e) {
    let n = null;
    if (__privateGet(this, _e3).send({
      type: ls,
      payload: {
        callback: (r) => {
          try {
            return e(r);
          } catch (s) {
            return n = s, r;
          }
        }
      }
    }), n) throw n;
  }, u_fn2 = function(e, n) {
    const r = Ut(e), s = Ut(n);
    if (!cc(Qe(s), Qe(r))) {
      this.emit("heads-changed", {
        handle: this,
        doc: n
      });
      const o = cn(n, r, s);
      o.length > 0 && this.emit("change", {
        handle: this,
        doc: n,
        patches: o,
        patchInfo: {
          before: e,
          after: n,
          source: "change"
        }
      }), this.isReady() || __privateGet(this, _e3).send({
        type: us
      });
    }
    __privateSet(this, _n2, n);
  }, d_fn2 = function(e) {
    return e.map((n) => typeof n == "string" ? `s:${n}` : typeof n == "number" ? `n:${n}` : typeof n == "object" && n !== null ? `o:${JSON.stringify(n)}` : `?:${String(n)}`).join("/");
  }, _a3);
  let kc, Rt, Oc, Rc, us, ls, Hc, Tc, Uc, Dc, Bc, _i, jc, Fc, Pc;
  kc = {
    REQUESTING: "requesting",
    READY: "ready",
    UNLOADED: "unloaded",
    DELETED: "deleted",
    UNAVAILABLE: "unavailable"
  };
  ({ REQUESTING: Rt, READY: En, UNLOADED: Fd, DELETED: Pd, UNAVAILABLE: Ht } = kc);
  Oc = "BEGIN";
  Rc = "REQUEST";
  us = "DOC_READY";
  ls = "UPDATE";
  Hc = "UNLOAD";
  Tc = "RELOAD";
  Uc = "DELETE";
  Dc = "DOC_UNAVAILABLE";
  Mc = (t, e) => {
    let n = Date.now(), r, s;
    return function(...i) {
      r = n + e - Date.now(), clearTimeout(s), s = setTimeout(() => {
        t(...i), n = Date.now();
      }, r);
    };
  };
  $d = (t) => jc(t) || Lc(t) || _i(t) || Bc(t) || Fc(t) || Pc(t);
  Bc = (t) => t.type === "doc-unavailable";
  _i = (t) => t.type === "request";
  jc = (t) => t.type === "sync";
  Lc = (t) => t.type === "ephemeral";
  Fc = (t) => t.type === "remote-subscription-change";
  Pc = (t) => t.type === "remote-heads-changed";
  var Ft = {
    exports: {}
  }, $c = Ft.exports, ds;
  function Vc() {
    return ds || (ds = 1, (function(t) {
      (function(e, n) {
        var r = {};
        n(r);
        var s = r.default;
        for (var i in r) s[i] = r[i];
        t.exports = s;
      })($c, function(e) {
        e.__esModule = true, e.digestLength = 32, e.blockSize = 64;
        var n = 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(u, d, g, m, S) {
          for (var M, B, w, N, U, j, z, F, C, R, L, W, _; S >= 64; ) {
            for (M = d[0], B = d[1], w = d[2], N = d[3], U = d[4], j = d[5], z = d[6], F = d[7], R = 0; R < 16; R++) L = m + R * 4, u[R] = (g[L] & 255) << 24 | (g[L + 1] & 255) << 16 | (g[L + 2] & 255) << 8 | g[L + 3] & 255;
            for (R = 16; R < 64; R++) C = u[R - 2], W = (C >>> 17 | C << 15) ^ (C >>> 19 | C << 13) ^ C >>> 10, C = u[R - 15], _ = (C >>> 7 | C << 25) ^ (C >>> 18 | C << 14) ^ C >>> 3, u[R] = (W + u[R - 7] | 0) + (_ + u[R - 16] | 0);
            for (R = 0; R < 64; R++) W = (((U >>> 6 | U << 26) ^ (U >>> 11 | U << 21) ^ (U >>> 25 | U << 7)) + (U & j ^ ~U & z) | 0) + (F + (n[R] + u[R] | 0) | 0) | 0, _ = ((M >>> 2 | M << 30) ^ (M >>> 13 | M << 19) ^ (M >>> 22 | M << 10)) + (M & B ^ M & w ^ B & w) | 0, F = z, z = j, j = U, U = N + W | 0, N = w, w = B, B = M, M = W + _ | 0;
            d[0] += M, d[1] += B, d[2] += w, d[3] += N, d[4] += U, d[5] += j, d[6] += z, d[7] += F, m += 64, S -= 64;
          }
          return m;
        }
        var s = (function() {
          function u() {
            this.digestLength = e.digestLength, this.blockSize = e.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 u.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;
          }, u.prototype.clean = function() {
            for (var d = 0; d < this.buffer.length; d++) this.buffer[d] = 0;
            for (var d = 0; d < this.temp.length; d++) this.temp[d] = 0;
            this.reset();
          }, u.prototype.update = function(d, g) {
            if (g === void 0 && (g = d.length), this.finished) throw new Error("SHA256: can't update because hash was finished.");
            var m = 0;
            if (this.bytesHashed += g, this.bufferLength > 0) {
              for (; this.bufferLength < 64 && g > 0; ) this.buffer[this.bufferLength++] = d[m++], g--;
              this.bufferLength === 64 && (r(this.temp, this.state, this.buffer, 0, 64), this.bufferLength = 0);
            }
            for (g >= 64 && (m = r(this.temp, this.state, d, m, g), g %= 64); g > 0; ) this.buffer[this.bufferLength++] = d[m++], g--;
            return this;
          }, u.prototype.finish = function(d) {
            if (!this.finished) {
              var g = this.bytesHashed, m = this.bufferLength, S = g / 536870912 | 0, M = g << 3, B = g % 64 < 56 ? 64 : 128;
              this.buffer[m] = 128;
              for (var w = m + 1; w < B - 8; w++) this.buffer[w] = 0;
              this.buffer[B - 8] = S >>> 24 & 255, this.buffer[B - 7] = S >>> 16 & 255, this.buffer[B - 6] = S >>> 8 & 255, this.buffer[B - 5] = S >>> 0 & 255, this.buffer[B - 4] = M >>> 24 & 255, this.buffer[B - 3] = M >>> 16 & 255, this.buffer[B - 2] = M >>> 8 & 255, this.buffer[B - 1] = M >>> 0 & 255, r(this.temp, this.state, this.buffer, 0, B), this.finished = true;
            }
            for (var w = 0; w < 8; w++) d[w * 4 + 0] = this.state[w] >>> 24 & 255, d[w * 4 + 1] = this.state[w] >>> 16 & 255, d[w * 4 + 2] = this.state[w] >>> 8 & 255, d[w * 4 + 3] = this.state[w] >>> 0 & 255;
            return this;
          }, u.prototype.digest = function() {
            var d = new Uint8Array(this.digestLength);
            return this.finish(d), d;
          }, u.prototype._saveState = function(d) {
            for (var g = 0; g < this.state.length; g++) d[g] = this.state[g];
          }, u.prototype._restoreState = function(d, g) {
            for (var m = 0; m < this.state.length; m++) this.state[m] = d[m];
            this.bytesHashed = g, this.finished = false, this.bufferLength = 0;
          }, u;
        })();
        e.Hash = s;
        var i = (function() {
          function u(d) {
            this.inner = new s(), this.outer = new s(), this.blockSize = this.inner.blockSize, this.digestLength = this.inner.digestLength;
            var g = new Uint8Array(this.blockSize);
            if (d.length > this.blockSize) new s().update(d).finish(g).clean();
            else for (var m = 0; m < d.length; m++) g[m] = d[m];
            for (var m = 0; m < g.length; m++) g[m] ^= 54;
            this.inner.update(g);
            for (var m = 0; m < g.length; m++) g[m] ^= 106;
            this.outer.update(g), this.istate = new Uint32Array(8), this.ostate = new Uint32Array(8), this.inner._saveState(this.istate), this.outer._saveState(this.ostate);
            for (var m = 0; m < g.length; m++) g[m] = 0;
          }
          return u.prototype.reset = function() {
            return this.inner._restoreState(this.istate, this.inner.blockSize), this.outer._restoreState(this.ostate, this.outer.blockSize), this;
          }, u.prototype.clean = function() {
            for (var d = 0; d < this.istate.length; d++) this.ostate[d] = this.istate[d] = 0;
            this.inner.clean(), this.outer.clean();
          }, u.prototype.update = function(d) {
            return this.inner.update(d), this;
          }, u.prototype.finish = function(d) {
            return this.outer.finished ? this.outer.finish(d) : (this.inner.finish(d), this.outer.update(d, this.digestLength).finish(d)), this;
          }, u.prototype.digest = function() {
            var d = new Uint8Array(this.digestLength);
            return this.finish(d), d;
          }, u;
        })();
        e.HMAC = i;
        function o(u) {
          var d = new s().update(u), g = d.digest();
          return d.clean(), g;
        }
        e.hash = o, e.default = o;
        function a(u, d) {
          var g = new i(u).update(d), m = g.digest();
          return g.clean(), m;
        }
        e.hmac = a;
        function c(u, d, g, m) {
          var S = m[0];
          if (S === 0) throw new Error("hkdf: cannot expand more");
          d.reset(), S > 1 && d.update(u), g && d.update(g), d.update(m), d.finish(u), m[0]++;
        }
        var l = new Uint8Array(e.digestLength);
        function h(u, d, g, m) {
          d === void 0 && (d = l), m === void 0 && (m = 32);
          for (var S = new Uint8Array([
            1
          ]), M = a(d, u), B = new i(M), w = new Uint8Array(B.digestLength), N = w.length, U = new Uint8Array(m), j = 0; j < m; j++) N === w.length && (c(w, B, g, S), N = 0), U[j] = w[N++];
          return B.clean(), w.fill(0), S.fill(0), U;
        }
        e.hkdf = h;
        function f(u, d, g, m) {
          for (var S = new i(u), M = S.digestLength, B = new Uint8Array(4), w = new Uint8Array(M), N = new Uint8Array(M), U = new Uint8Array(m), j = 0; j * M < m; j++) {
            var z = j + 1;
            B[0] = z >>> 24 & 255, B[1] = z >>> 16 & 255, B[2] = z >>> 8 & 255, B[3] = z >>> 0 & 255, S.reset(), S.update(d), S.update(B), S.finish(N);
            for (var F = 0; F < M; F++) w[F] = N[F];
            for (var F = 2; F <= g; F++) {
              S.reset(), S.update(N).finish(N);
              for (var C = 0; C < M; C++) w[C] ^= N[C];
            }
            for (var F = 0; F < M && j * M + F < m; F++) U[j * M + F] = w[F];
          }
          for (var j = 0; j < M; j++) w[j] = N[j] = 0;
          for (var j = 0; j < 4; j++) B[j] = 0;
          return S.clean(), U;
        }
        e.pbkdf2 = f;
      });
    })(Ft)), Ft.exports;
  }
  Vd = Vc();
  class pi extends Cs {
  }
  class zc extends pi {
    constructor({ handle: e, peerId: n, onLoadSyncState: r }) {
      super();
      __privateAdd(this, _zc_instances);
      __privateAdd(this, _r4);
      __publicField(this, "syncDebounceRate", 100);
      __privateAdd(this, _e4, []);
      __privateAdd(this, _s3, {});
      __privateAdd(this, _n3, {});
      __privateAdd(this, _i3, {});
      __privateAdd(this, _a4, []);
      __privateAdd(this, _f3);
      __privateAdd(this, _o3, false);
      __privateAdd(this, _t2);
      __privateAdd(this, _h);
      __privateSet(this, _f3, n), __privateSet(this, _t2, e), __privateSet(this, _h, r ?? (() => Promise.resolve(void 0)));
      const s = e.documentId.slice(0, 5);
      __privateSet(this, _r4, Xn(`automerge-repo:docsync:${s}`)), e.on("change", Mc(() => __privateMethod(this, _zc_instances, __fn3).call(this), this.syncDebounceRate)), e.on("ephemeral-message-outbound", (i) => __privateMethod(this, _zc_instances, c_fn3).call(this, i)), (async () => __privateMethod(this, _zc_instances, w_fn).call(this))();
    }
    get peerStates() {
      return __privateGet(this, _n3);
    }
    get documentId() {
      return __privateGet(this, _t2).documentId;
    }
    hasPeer(e) {
      return __privateGet(this, _e4).includes(e);
    }
    async beginSync(e) {
      __privateGet(this, _t2).whenReady([
        En,
        Rt,
        Ht
      ]).then(() => {
        __privateSet(this, _o3, true), __privateMethod(this, _zc_instances, g_fn).call(this);
      }).catch((r) => {
        console.log("caught whenready", r), __privateSet(this, _o3, true), __privateMethod(this, _zc_instances, g_fn).call(this);
      }), __privateGet(this, _e4).some((r) => __privateGet(this, _n3)[r] == "has") && await __privateGet(this, _t2).whenReady(), e.forEach((r) => {
        __privateMethod(this, _zc_instances, d_fn3).call(this, r, (s) => {
          const i = $i(Pi(s));
          __privateMethod(this, _zc_instances, l_fn2).call(this, r, i), __privateGet(this, _t2).whenReady([
            En,
            Rt,
            Ht
          ]).then(() => {
            const o = __privateGet(this, _t2).isReady() ? __privateGet(this, _t2).doc() : Te(), a = e.every((l) => __privateGet(this, _n3)[l] in [
              "unavailable",
              "wants"
            ]);
            o === void 0 && a || __privateMethod(this, _zc_instances, p_fn2).call(this, r, o ?? Te());
          }).catch((o) => {
            __privateGet(this, _r4).call(this, `Error loading doc for ${r}: ${o}`);
          });
        });
      });
    }
    endSync(e) {
      __privateGet(this, _r4).call(this, `removing peer ${e}`), __privateSet(this, _e4, __privateGet(this, _e4).filter((n) => n !== e)), delete __privateGet(this, _n3)[e], __privateMethod(this, _zc_instances, g_fn).call(this);
    }
    receiveMessage(e) {
      switch (e.type) {
        case "sync":
        case "request":
          this.receiveSyncMessage(e);
          break;
        case "ephemeral":
          this.receiveEphemeralMessage(e);
          break;
        case "doc-unavailable":
          __privateGet(this, _n3)[e.senderId] = "unavailable", __privateMethod(this, _zc_instances, g_fn).call(this);
          break;
        default:
          throw new Error(`unknown message type: ${e}`);
      }
    }
    receiveEphemeralMessage(e) {
      if (e.documentId !== __privateGet(this, _t2).documentId) throw new Error("channelId doesn't match documentId");
      const { senderId: n, data: r } = e, s = ci(new Uint8Array(r));
      __privateGet(this, _t2).emit("ephemeral-message", {
        handle: __privateGet(this, _t2),
        senderId: n,
        message: s
      }), __privateGet(this, _e4).forEach((i) => {
        i !== n && this.emit("message", {
          ...e,
          targetId: i
        });
      });
    }
    receiveSyncMessage(e) {
      if (e.documentId !== __privateGet(this, _t2).documentId) throw new Error("channelId doesn't match documentId");
      if (!__privateGet(this, _t2).inState([
        En,
        Rt,
        Ht
      ])) {
        __privateGet(this, _a4).push({
          message: e,
          received: /* @__PURE__ */ new Date()
        });
        return;
      }
      __privateMethod(this, _zc_instances, w_fn).call(this), __privateMethod(this, _zc_instances, b_fn2).call(this, e);
    }
    metrics() {
      return {
        peers: __privateGet(this, _e4),
        size: __privateGet(this, _t2).metrics()
      };
    }
  }
  _r4 = new WeakMap();
  _e4 = new WeakMap();
  _s3 = new WeakMap();
  _n3 = new WeakMap();
  _i3 = new WeakMap();
  _a4 = new WeakMap();
  _f3 = new WeakMap();
  _o3 = new WeakMap();
  _t2 = new WeakMap();
  _h = new WeakMap();
  _zc_instances = new WeakSet();
  __fn3 = async function() {
    try {
      await __privateGet(this, _t2).whenReady();
      const e = __privateGet(this, _t2).doc();
      __privateGet(this, _e4).forEach((n) => __privateMethod(this, _zc_instances, p_fn2).call(this, n, e));
    } catch {
      console.log("sync with peers threw an exception");
    }
  };
  c_fn3 = async function({ data: e }) {
    __privateGet(this, _r4).call(this, "broadcastToPeers", __privateGet(this, _e4)), __privateGet(this, _e4).forEach((n) => __privateMethod(this, _zc_instances, u_fn3).call(this, n, e));
  };
  u_fn3 = function(e, n) {
    __privateGet(this, _r4).call(this, `sendEphemeralMessage ->${e}`);
    const r = {
      type: "ephemeral",
      targetId: e,
      documentId: __privateGet(this, _t2).documentId,
      data: n
    };
    this.emit("message", r);
  };
  d_fn3 = function(e, n) {
    __privateMethod(this, _zc_instances, m_fn2).call(this, e), e in __privateGet(this, _n3) || (__privateGet(this, _n3)[e] = "unknown");
    const r = __privateGet(this, _i3)[e];
    if (r) {
      n(r);
      return;
    }
    let s = __privateGet(this, _s3)[e];
    s || (__privateGet(this, _h).call(this, e).then((i) => {
      __privateMethod(this, _zc_instances, y_fn2).call(this, e, i ?? Ni());
    }).catch((i) => {
      __privateGet(this, _r4).call(this, `Error loading sync state for ${e}: ${i}`);
    }), s = __privateGet(this, _s3)[e] = []), s.push(n);
  };
  m_fn2 = function(e) {
    __privateGet(this, _e4).includes(e) || (__privateGet(this, _e4).push(e), this.emit("open-doc", {
      documentId: this.documentId,
      peerId: e
    }));
  };
  y_fn2 = function(e, n) {
    const r = __privateGet(this, _s3)[e];
    if (r) for (const s of r) s(n);
    delete __privateGet(this, _s3)[e], __privateGet(this, _i3)[e] = n;
  };
  l_fn2 = function(e, n) {
    __privateGet(this, _i3)[e] = n, this.emit("sync-state", {
      peerId: e,
      syncState: n,
      documentId: __privateGet(this, _t2).documentId
    });
  };
  p_fn2 = function(e, n) {
    __privateGet(this, _r4).call(this, `sendSyncMessage ->${e}`), __privateMethod(this, _zc_instances, d_fn3).call(this, e, (r) => {
      const s = performance.now(), [i, o] = Vi(n, r), a = performance.now();
      if (this.emit("metrics", {
        type: "generate-sync-message",
        documentId: __privateGet(this, _t2).documentId,
        durationMillis: a - s,
        forPeer: e
      }), __privateMethod(this, _zc_instances, l_fn2).call(this, e, i), o) {
        const c = Ut(n).length === 0;
        !__privateGet(this, _t2).isReady() && c && i.sharedHeads.length === 0 && !Object.values(__privateGet(this, _n3)).includes("has") && __privateGet(this, _n3)[e] === "unknown" ? this.emit("message", {
          type: "request",
          targetId: e,
          documentId: __privateGet(this, _t2).documentId,
          data: o
        }) : this.emit("message", {
          type: "sync",
          targetId: e,
          data: o,
          documentId: __privateGet(this, _t2).documentId
        }), c || (__privateGet(this, _n3)[e] = "has");
      }
    });
  };
  b_fn2 = function(e) {
    _i(e) && (__privateGet(this, _n3)[e.senderId] = "wants"), __privateMethod(this, _zc_instances, g_fn).call(this), qi(e.data).heads.length > 0 && (__privateGet(this, _n3)[e.senderId] = "has"), __privateMethod(this, _zc_instances, d_fn3).call(this, e.senderId, (n) => {
      __privateGet(this, _t2).update((r) => {
        const s = performance.now(), [i, o] = zi(r, n, e.data), a = performance.now();
        return this.emit("metrics", {
          type: "receive-sync-message",
          documentId: __privateGet(this, _t2).documentId,
          durationMillis: a - s,
          fromPeer: e.senderId,
          ...Es(r)
        }), __privateMethod(this, _zc_instances, l_fn2).call(this, e.senderId, o), __privateMethod(this, _zc_instances, p_fn2).call(this, e.senderId, r), i;
      }), __privateMethod(this, _zc_instances, g_fn).call(this);
    });
  };
  g_fn = function() {
    __privateGet(this, _o3) && __privateGet(this, _t2).inState([
      Rt,
      Ht
    ]) && __privateGet(this, _e4).every((e) => __privateGet(this, _n3)[e] === "unavailable" || __privateGet(this, _n3)[e] === "wants") && (__privateGet(this, _e4).filter((e) => __privateGet(this, _n3)[e] === "wants").forEach((e) => {
      __privateGet(this, _n3)[e] = "unavailable";
      const n = {
        type: "doc-unavailable",
        documentId: __privateGet(this, _t2).documentId,
        targetId: e
      };
      this.emit("message", n);
    }), __privateGet(this, _t2).unavailable());
  };
  w_fn = function() {
    for (const e of __privateGet(this, _a4)) __privateMethod(this, _zc_instances, b_fn2).call(this, e.message);
    __privateSet(this, _a4, []);
  };
  const Me = Xn("automerge-repo:collectionsync");
  zd = (_b = class extends pi {
    constructor(e, n = []) {
      super();
      __privateAdd(this, _zd_instances);
      __publicField(this, "repo");
      __privateAdd(this, _r5, /* @__PURE__ */ new Set());
      __publicField(this, "docSynchronizers", {});
      __privateAdd(this, _e5, {});
      __privateAdd(this, _s4);
      __privateAdd(this, _n4, /* @__PURE__ */ new Map());
      this.repo = e, __privateSet(this, _s4, n.map((r) => fr(r).documentId));
    }
    async receiveMessage(e) {
      var _a5;
      Me(`onSyncMessage: ${e.senderId}, ${e.documentId}, ${"data" in e ? e.data.byteLength + "bytes" : ""}`);
      const n = e.documentId;
      if (!n) throw new Error("received a message with an invalid documentId");
      if (__privateGet(this, _s4).includes(n)) {
        this.emit("metrics", {
          type: "doc-denied",
          documentId: n
        }), this.emit("message", {
          type: "doc-unavailable",
          documentId: n,
          targetId: e.senderId
        });
        return;
      }
      if ((e.type === "request" || e.type === "sync") && (__privateGet(this, _n4).has(n) || __privateGet(this, _n4).set(n, /* @__PURE__ */ new Set()), (_a5 = __privateGet(this, _n4).get(n)) == null ? void 0 : _a5.add(e.senderId)), !await this.repo.shareConfig.access(e.senderId, n)) {
        Me("access denied"), this.emit("message", {
          type: "doc-unavailable",
          documentId: n,
          targetId: e.senderId
        });
        return;
      }
      __privateGet(this, _e5)[n] = true;
      const s = await this.repo.find(n, {
        allowableStates: [
          "ready",
          "unavailable",
          "requesting"
        ]
      }), i = __privateMethod(this, _zd_instances, i_fn2).call(this, s);
      i.receiveMessage(e);
      const o = await __privateMethod(this, _zd_instances, f_fn2).call(this, n);
      i.beginSync(o.filter((a) => !i.hasPeer(a)));
    }
    addDocument(e) {
      if (__privateGet(this, _e5)[e.documentId]) return;
      __privateGet(this, _e5)[e.documentId] = true;
      const n = __privateMethod(this, _zd_instances, i_fn2).call(this, e);
      __privateMethod(this, _zd_instances, f_fn2).call(this, e.documentId).then((r) => {
        n.beginSync(r);
      });
    }
    removeDocument(e) {
      Me(`removing document ${e}`);
      const n = this.docSynchronizers[e];
      n !== void 0 && this.peers.forEach((r) => n.endSync(r)), delete this.docSynchronizers[e], delete __privateGet(this, _e5)[e];
    }
    addPeer(e) {
      if (Me(`adding ${e} & synchronizing with them`), !__privateGet(this, _r5).has(e)) {
        __privateGet(this, _r5).add(e);
        for (const n of Object.values(this.docSynchronizers)) {
          const { documentId: r } = n;
          __privateMethod(this, _zd_instances, o_fn2).call(this, e, r).then((s) => {
            s && n.beginSync([
              e
            ]);
          });
        }
      }
    }
    removePeer(e) {
      Me(`removing peer ${e}`), __privateGet(this, _r5).delete(e);
      for (const n of __privateGet(this, _n4).values()) n.delete(e);
      for (const n of Object.values(this.docSynchronizers)) n.endSync(e);
    }
    get peers() {
      return Array.from(__privateGet(this, _r5));
    }
    async reevaluateDocumentShare() {
      const e = Array.from(__privateGet(this, _r5)), n = [];
      for (const r of Object.values(this.docSynchronizers)) {
        const s = r.documentId;
        n.push((async () => {
          for (const i of e) {
            const o = await __privateMethod(this, _zd_instances, o_fn2).call(this, i, s), a = r.hasPeer(i);
            Me(`reevaluateDocumentShare: ${i} for ${s}, shouldShare: ${o}, isAlreadySyncing: ${a}`), o && !a ? (Me(`reevaluateDocumentShare: starting sync with ${i} for ${s}`), r.beginSync([
              i
            ])) : !o && a && (Me(`reevaluateDocumentShare: stopping sync with ${i} for ${s}`), r.endSync(i));
          }
        })().catch((i) => {
          console.log(`error reevaluating document share for ${s}: ${i}`);
        }));
      }
      await Promise.allSettled(n);
    }
    metrics() {
      return Object.fromEntries(Object.entries(this.docSynchronizers).map(([e, n]) => [
        e,
        n.metrics()
      ]));
    }
  }, _r5 = new WeakMap(), _e5 = new WeakMap(), _s4 = new WeakMap(), _n4 = new WeakMap(), _zd_instances = new WeakSet(), i_fn2 = function(e) {
    return this.docSynchronizers[e.documentId] || (this.docSynchronizers[e.documentId] = __privateMethod(this, _zd_instances, a_fn2).call(this, e)), this.docSynchronizers[e.documentId];
  }, a_fn2 = function(e) {
    const n = new zc({
      handle: e,
      peerId: this.repo.networkSubsystem.peerId,
      onLoadSyncState: async (r) => {
        if (!this.repo.storageSubsystem) return;
        const { storageId: s, isEphemeral: i } = this.repo.peerMetadataByPeerId[r] || {};
        if (!(!s || i)) return this.repo.storageSubsystem.loadSyncState(e.documentId, s);
      }
    });
    return n.on("message", (r) => this.emit("message", r)), n.on("open-doc", (r) => this.emit("open-doc", r)), n.on("sync-state", (r) => this.emit("sync-state", r)), n.on("metrics", (r) => this.emit("metrics", r)), n;
  }, f_fn2 = async function(e) {
    const n = Array.from(__privateGet(this, _r5)), r = [];
    for (const s of n) await __privateMethod(this, _zd_instances, o_fn2).call(this, s, e) && r.push(s);
    return r;
  }, o_fn2 = async function(e, n) {
    var _a5;
    const [r, s] = await Promise.all([
      this.repo.shareConfig.announce(e, n),
      this.repo.shareConfig.access(e, n)
    ]), i = ((_a5 = __privateGet(this, _n4).get(n)) == null ? void 0 : _a5.has(e)) ?? false;
    return r || s && i;
  }, _b);
  const Nc = "/assets/automerge_wasm_bg-BQ4CNPIj.wasm", qc = async (t = {}, e) => {
    let n;
    if (e.startsWith("data:")) {
      const r = e.replace(/^data:.*?base64,/, "");
      let s;
      if (typeof Buffer == "function" && typeof Buffer.from == "function") s = Buffer.from(r, "base64");
      else if (typeof atob == "function") {
        const i = atob(r);
        s = new Uint8Array(i.length);
        for (let o = 0; o < i.length; o++) s[o] = i.charCodeAt(o);
      } else throw new Error("Cannot decode base64-encoded data URL");
      n = await WebAssembly.instantiate(s, t);
    } else {
      const r = await fetch(e), s = r.headers.get("Content-Type") || "";
      if ("instantiateStreaming" in WebAssembly && s.startsWith("application/wasm")) n = await WebAssembly.instantiateStreaming(r, t);
      else {
        const i = await r.arrayBuffer();
        n = await WebAssembly.instantiate(i, t);
      }
    }
    return n.instance.exports;
  };
  class xe {
    static __wrap(e) {
      e = e >>> 0;
      const n = Object.create(xe.prototype);
      return n.__wbg_ptr = e, hs.register(n, n.__wbg_ptr, n), n;
    }
    __destroy_into_raw() {
      const e = this.__wbg_ptr;
      return this.__wbg_ptr = 0, hs.unregister(this), e;
    }
    free() {
      const e = this.__destroy_into_raw();
      x.__wbg_automerge_free(e, 0);
    }
    applyAndReturnPatches(e, n) {
      const r = x.automerge_applyAndReturnPatches(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    applyChanges(e) {
      const n = x.automerge_applyChanges(this.__wbg_ptr, e);
      if (n[1]) throw H(n[0]);
    }
    applyPatches(e, n) {
      const r = x.automerge_applyPatches(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    clone(e) {
      var n = le(e) ? 0 : Ee(e, x.__wbindgen_malloc, x.__wbindgen_realloc), r = ye;
      const s = x.automerge_clone(this.__wbg_ptr, n, r);
      if (s[2]) throw H(s[1]);
      return xe.__wrap(s[0]);
    }
    commit(e, n) {
      var r = le(e) ? 0 : Ee(e, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
      return x.automerge_commit(this.__wbg_ptr, r, s, !le(n), le(n) ? 0 : n);
    }
    delete(e, n) {
      const r = x.automerge_delete(this.__wbg_ptr, e, n);
      if (r[1]) throw H(r[0]);
    }
    diff(e, n) {
      const r = x.automerge_diff(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    diffIncremental() {
      const e = x.automerge_diffIncremental(this.__wbg_ptr);
      if (e[2]) throw H(e[1]);
      return H(e[0]);
    }
    diffPath(e, n, r, s) {
      const i = x.automerge_diffPath(this.__wbg_ptr, e, n, r, s);
      if (i[2]) throw H(i[1]);
      return H(i[0]);
    }
    dump() {
      x.automerge_dump(this.__wbg_ptr);
    }
    emptyChange(e, n) {
      var r = le(e) ? 0 : Ee(e, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
      return x.automerge_emptyChange(this.__wbg_ptr, r, s, !le(n), le(n) ? 0 : n);
    }
    enableFreeze(e) {
      const n = x.automerge_enableFreeze(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return n[0] !== 0;
    }
    fork(e, n) {
      var r = le(e) ? 0 : Ee(e, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
      const i = x.automerge_fork(this.__wbg_ptr, r, s, n);
      if (i[2]) throw H(i[1]);
      return xe.__wrap(i[0]);
    }
    generateSyncMessage(e) {
      return Pe(e, he), x.automerge_generateSyncMessage(this.__wbg_ptr, e.__wbg_ptr);
    }
    get(e, n, r) {
      const s = x.automerge_get(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    getActorId() {
      let e, n;
      try {
        const r = x.automerge_getActorId(this.__wbg_ptr);
        return e = r[0], n = r[1], Se(r[0], r[1]);
      } finally {
        x.__wbindgen_free(e, n, 1);
      }
    }
    getAll(e, n, r) {
      const s = x.automerge_getAll(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    getBlock(e, n, r) {
      const s = x.automerge_getBlock(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    getChangeByHash(e) {
      const n = x.automerge_getChangeByHash(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getChangeMetaByHash(e) {
      const n = x.automerge_getChangeMetaByHash(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getChanges(e) {
      const n = x.automerge_getChanges(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getChangesAdded(e) {
      return Pe(e, xe), x.automerge_getChangesAdded(this.__wbg_ptr, e.__wbg_ptr);
    }
    getChangesMeta(e) {
      const n = x.automerge_getChangesMeta(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getCursor(e, n, r, s) {
      let i, o;
      try {
        const l = x.automerge_getCursor(this.__wbg_ptr, e, n, r, s);
        var a = l[0], c = l[1];
        if (l[3]) throw a = 0, c = 0, H(l[2]);
        return i = a, o = c, Se(a, c);
      } finally {
        x.__wbindgen_free(i, o, 1);
      }
    }
    getCursorPosition(e, n, r) {
      const s = x.automerge_getCursorPosition(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return s[0];
    }
    getDecodedChangeByHash(e) {
      const n = x.automerge_getDecodedChangeByHash(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getHeads() {
      return x.automerge_getHeads(this.__wbg_ptr);
    }
    getLastLocalChange() {
      return x.automerge_getLastLocalChange(this.__wbg_ptr);
    }
    getMissingDeps(e) {
      const n = x.automerge_getMissingDeps(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    getWithType(e, n, r) {
      const s = x.automerge_getWithType(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    hasOurChanges(e) {
      return Pe(e, he), x.automerge_hasOurChanges(this.__wbg_ptr, e.__wbg_ptr) !== 0;
    }
    increment(e, n, r) {
      const s = x.automerge_increment(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    insert(e, n, r, s) {
      const i = x.automerge_insert(this.__wbg_ptr, e, n, r, s);
      if (i[1]) throw H(i[0]);
    }
    insertObject(e, n, r) {
      let s, i;
      try {
        const c = x.automerge_insertObject(this.__wbg_ptr, e, n, r);
        var o = c[0], a = c[1];
        if (c[3]) throw o = 0, a = 0, H(c[2]);
        return s = o, i = a, Se(o, a);
      } finally {
        x.__wbindgen_free(s, i, 1);
      }
    }
    integrate() {
      x.automerge_integrate(this.__wbg_ptr);
    }
    isolate(e) {
      const n = x.automerge_isolate(this.__wbg_ptr, e);
      if (n[1]) throw H(n[0]);
    }
    joinBlock(e, n) {
      const r = x.automerge_joinBlock(this.__wbg_ptr, e, n);
      if (r[1]) throw H(r[0]);
    }
    keys(e, n) {
      const r = x.automerge_keys(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    length(e, n) {
      const r = x.automerge_length(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return r[0];
    }
    loadIncremental(e) {
      const n = x.automerge_loadIncremental(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return n[0];
    }
    mark(e, n, r, s, i) {
      const o = x.automerge_mark(this.__wbg_ptr, e, n, r, s, i);
      if (o[1]) throw H(o[0]);
    }
    marks(e, n) {
      const r = x.automerge_marks(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    marksAt(e, n, r) {
      const s = x.automerge_marksAt(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    materialize(e, n, r) {
      const s = x.automerge_materialize(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    merge(e) {
      Pe(e, xe);
      const n = x.automerge_merge(this.__wbg_ptr, e.__wbg_ptr);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    static new(e) {
      var n = le(e) ? 0 : Ee(e, x.__wbindgen_malloc, x.__wbindgen_realloc), r = ye;
      const s = x.automerge_new(n, r);
      if (s[2]) throw H(s[1]);
      return xe.__wrap(s[0]);
    }
    objInfo(e, n) {
      const r = x.automerge_objInfo(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    pendingOps() {
      return x.automerge_pendingOps(this.__wbg_ptr);
    }
    push(e, n, r) {
      const s = x.automerge_push(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    pushObject(e, n) {
      let r, s;
      try {
        const a = x.automerge_pushObject(this.__wbg_ptr, e, n);
        var i = a[0], o = a[1];
        if (a[3]) throw i = 0, o = 0, H(a[2]);
        return r = i, s = o, Se(i, o);
      } finally {
        x.__wbindgen_free(r, s, 1);
      }
    }
    put(e, n, r, s) {
      const i = x.automerge_put(this.__wbg_ptr, e, n, r, s);
      if (i[1]) throw H(i[0]);
    }
    putObject(e, n, r) {
      const s = x.automerge_putObject(this.__wbg_ptr, e, n, r);
      if (s[2]) throw H(s[1]);
      return H(s[0]);
    }
    receiveSyncMessage(e, n) {
      Pe(e, he);
      const r = x.automerge_receiveSyncMessage(this.__wbg_ptr, e.__wbg_ptr, n);
      if (r[1]) throw H(r[0]);
    }
    registerDatatype(e, n, r) {
      const s = x.automerge_registerDatatype(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    resetDiffCursor() {
      x.automerge_resetDiffCursor(this.__wbg_ptr);
    }
    rollback() {
      return x.automerge_rollback(this.__wbg_ptr);
    }
    save() {
      return x.automerge_save(this.__wbg_ptr);
    }
    saveAndVerify() {
      const e = x.automerge_saveAndVerify(this.__wbg_ptr);
      if (e[2]) throw H(e[1]);
      return H(e[0]);
    }
    saveBundle(e) {
      const n = x.automerge_saveBundle(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    saveIncremental() {
      return x.automerge_saveIncremental(this.__wbg_ptr);
    }
    saveNoCompress() {
      return x.automerge_saveNoCompress(this.__wbg_ptr);
    }
    saveSince(e) {
      const n = x.automerge_saveSince(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    spans(e, n) {
      const r = x.automerge_spans(this.__wbg_ptr, e, n);
      if (r[2]) throw H(r[1]);
      return H(r[0]);
    }
    splice(e, n, r, s) {
      const i = x.automerge_splice(this.__wbg_ptr, e, n, r, s);
      if (i[1]) throw H(i[0]);
    }
    splitBlock(e, n, r) {
      const s = x.automerge_splitBlock(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    stats() {
      return x.automerge_stats(this.__wbg_ptr);
    }
    text(e, n) {
      let r, s;
      try {
        const a = x.automerge_text(this.__wbg_ptr, e, n);
        var i = a[0], o = a[1];
        if (a[3]) throw i = 0, o = 0, H(a[2]);
        return r = i, s = o, Se(i, o);
      } finally {
        x.__wbindgen_free(r, s, 1);
      }
    }
    toJS(e) {
      const n = x.automerge_toJS(this.__wbg_ptr, e);
      if (n[2]) throw H(n[1]);
      return H(n[0]);
    }
    topoHistoryTraversal() {
      return x.automerge_topoHistoryTraversal(this.__wbg_ptr);
    }
    unmark(e, n, r) {
      const s = x.automerge_unmark(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    updateBlock(e, n, r) {
      const s = x.automerge_updateBlock(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    updateDiffCursor() {
      x.automerge_updateDiffCursor(this.__wbg_ptr);
    }
    updateSpans(e, n, r) {
      const s = x.automerge_updateSpans(this.__wbg_ptr, e, n, r);
      if (s[1]) throw H(s[0]);
    }
    updateText(e, n) {
      const r = x.automerge_updateText(this.__wbg_ptr, e, n);
      if (r[1]) throw H(r[0]);
    }
  }
  Symbol.dispose && (xe.prototype[Symbol.dispose] = xe.prototype.free);
  class he {
    static __wrap(e) {
      e = e >>> 0;
      const n = Object.create(he.prototype);
      return n.__wbg_ptr = e, gs.register(n, n.__wbg_ptr, n), n;
    }
    __destroy_into_raw() {
      const e = this.__wbg_ptr;
      return this.__wbg_ptr = 0, gs.unregister(this), e;
    }
    free() {
      const e = this.__destroy_into_raw();
      x.__wbg_syncstate_free(e, 0);
    }
    clone() {
      const e = x.syncstate_clone(this.__wbg_ptr);
      return he.__wrap(e);
    }
    get lastSentHeads() {
      return x.syncstate_lastSentHeads(this.__wbg_ptr);
    }
    set lastSentHeads(e) {
      const n = x.syncstate_set_lastSentHeads(this.__wbg_ptr, e);
      if (n[1]) throw H(n[0]);
    }
    set sentHashes(e) {
      const n = x.syncstate_set_sentHashes(this.__wbg_ptr, e);
      if (n[1]) throw H(n[0]);
    }
    get sharedHeads() {
      return x.syncstate_sharedHeads(this.__wbg_ptr);
    }
  }
  Symbol.dispose && (he.prototype[Symbol.dispose] = he.prototype.free);
  function Wc(t) {
    const e = x.create(t);
    if (e[2]) throw H(e[1]);
    return xe.__wrap(e[0]);
  }
  function Gc(t) {
    const e = x.decodeChange(t);
    if (e[2]) throw H(e[1]);
    return H(e[0]);
  }
  function Kc(t) {
    const e = x.decodeSyncMessage(t);
    if (e[2]) throw H(e[1]);
    return H(e[0]);
  }
  function Jc(t) {
    const e = x.decodeSyncState(t);
    if (e[2]) throw H(e[1]);
    return he.__wrap(e[0]);
  }
  function Xc(t) {
    const e = x.encodeChange(t);
    if (e[2]) throw H(e[1]);
    return H(e[0]);
  }
  function Yc(t) {
    const e = x.encodeSyncMessage(t);
    if (e[2]) throw H(e[1]);
    return H(e[0]);
  }
  function Zc(t) {
    return Pe(t, he), x.encodeSyncState(t.__wbg_ptr);
  }
  function Qc(t) {
    return Pe(t, he), x.exportSyncState(t.__wbg_ptr);
  }
  function ef(t) {
    const e = x.importSyncState(t);
    if (e[2]) throw H(e[1]);
    return he.__wrap(e[0]);
  }
  function tf() {
    const t = x.initSyncState();
    return he.__wrap(t);
  }
  function nf(t, e) {
    const n = x.load(t, e);
    if (n[2]) throw H(n[1]);
    return xe.__wrap(n[0]);
  }
  function rf(t) {
    const e = x.readBundle(t);
    if (e[2]) throw H(e[1]);
    return H(e[0]);
  }
  function sf() {
    return x.wasmReleaseInfo();
  }
  function of(t) {
    return BigInt(t);
  }
  function af(t, e) {
    return Error(Se(t, e));
  }
  function cf(t, e) {
    const n = String(e), r = Ee(n, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
    ge().setInt32(t + 4, s, true), ge().setInt32(t + 0, r, true);
  }
  function ff(t) {
    const e = t, n = typeof e == "boolean" ? e : void 0;
    return le(n) ? 16777215 : n ? 1 : 0;
  }
  function uf(t, e) {
    const n = qn(e), r = Ee(n, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
    ge().setInt32(t + 4, s, true), ge().setInt32(t + 0, r, true);
  }
  function lf(t, e) {
    return t > e;
  }
  function df(t) {
    return typeof t == "bigint";
  }
  function hf(t) {
    return typeof t == "function";
  }
  function gf(t) {
    return t === null;
  }
  function _f(t) {
    const e = t;
    return typeof e == "object" && e !== null;
  }
  function pf(t) {
    return typeof t == "string";
  }
  function yf(t) {
    return t === void 0;
  }
  function bf(t, e) {
    return t == e;
  }
  function mf(t, e) {
    return t < e;
  }
  function wf(t) {
    return -t;
  }
  function xf(t, e) {
    const n = e, r = typeof n == "number" ? n : void 0;
    ge().setFloat64(t + 8, le(r) ? 0 : r, true), ge().setInt32(t + 0, !le(r), true);
  }
  function Sf(t, e) {
    const n = e, r = typeof n == "string" ? n : void 0;
    var s = le(r) ? 0 : Ee(r, x.__wbindgen_malloc, x.__wbindgen_realloc), i = ye;
    ge().setInt32(t + 4, i, true), ge().setInt32(t + 0, s, true);
  }
  function vf(t, e) {
    throw new Error(Se(t, e));
  }
  function Af() {
    return Oe(function(t, e, n) {
      return Reflect.apply(t, e, n);
    }, arguments);
  }
  function Ef(t, e) {
    return Object.assign(t, e);
  }
  function If() {
    return Oe(function(t, e) {
      return t.call(e);
    }, arguments);
  }
  function Cf() {
    return Oe(function(t, e, n) {
      return t.call(e, n);
    }, arguments);
  }
  function kf(t, e) {
    return t.concat(e);
  }
  function Of(t, e, n) {
    return Object.defineProperty(t, e, n);
  }
  function Rf() {
    return Oe(function(t, e) {
      return Reflect.deleteProperty(t, e);
    }, arguments);
  }
  function Hf(t) {
    return t.done;
  }
  function Tf(t) {
    return Object.entries(t);
  }
  function Uf(t, e) {
    let n, r;
    try {
      n = t, r = e, console.error(Se(t, e));
    } finally {
      x.__wbindgen_free(n, r, 1);
    }
  }
  function Df(t, e) {
    return Symbol.for(Se(t, e));
  }
  function Mf(t) {
    return Object.freeze(t);
  }
  function Bf(t) {
    return Array.from(t);
  }
  function jf() {
    return Oe(function(t, e) {
      globalThis.crypto.getRandomValues(pr(t, e));
    }, arguments);
  }
  function Lf(t) {
    return t.getTime();
  }
  function Ff(t, e) {
    return t[e >>> 0];
  }
  function Pf() {
    return Oe(function(t, e) {
      return Reflect.get(t, e);
    }, arguments);
  }
  function $f(t) {
    let e;
    try {
      e = t instanceof ArrayBuffer;
    } catch {
      e = false;
    }
    return e;
  }
  function Vf(t) {
    let e;
    try {
      e = t instanceof Date;
    } catch {
      e = false;
    }
    return e;
  }
  function zf(t) {
    let e;
    try {
      e = t instanceof Object;
    } catch {
      e = false;
    }
    return e;
  }
  function Nf(t) {
    let e;
    try {
      e = t instanceof Uint8Array;
    } catch {
      e = false;
    }
    return e;
  }
  function qf(t) {
    return Array.isArray(t);
  }
  function Wf(t) {
    return Array.isArray(t);
  }
  function Gf() {
    return Symbol.iterator;
  }
  function Kf(t) {
    return Object.keys(t);
  }
  function Jf(t) {
    return t.length;
  }
  function Xf(t) {
    return t.length;
  }
  function Yf(t) {
    return t.length;
  }
  function Zf(t) {
    console.log(t);
  }
  function Qf(t, e) {
    console.log(t, e);
  }
  function eu(t) {
    return new Date(t);
  }
  function tu() {
    return new Object();
  }
  function nu() {
    return new Array();
  }
  function ru(t, e) {
    return new Error(Se(t, e));
  }
  function su() {
    return new Error();
  }
  function iu(t, e) {
    return new RangeError(Se(t, e));
  }
  function ou(t) {
    return new Uint8Array(t);
  }
  function au(t, e) {
    return new Uint8Array(pr(t, e));
  }
  function cu() {
    return Oe(function(t) {
      return t.next();
    }, arguments);
  }
  function fu(t) {
    return t.next;
  }
  function uu() {
    return Oe(function(t) {
      return Reflect.ownKeys(t);
    }, arguments);
  }
  function lu(t, e, n) {
    Uint8Array.prototype.set.call(pr(t, e), n);
  }
  function du(t, e) {
    return t.push(e);
  }
  function hu(t, e, n) {
    t[e] = n;
  }
  function gu() {
    return Oe(function(t, e, n) {
      return Reflect.set(t, e, n);
    }, arguments);
  }
  function _u(t, e, n) {
    t[e >>> 0] = n;
  }
  function pu(t, e, n) {
    return t.slice(e >>> 0, n >>> 0);
  }
  function yu(t, e) {
    const n = e.stack, r = Ee(n, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
    ge().setInt32(t + 4, s, true), ge().setInt32(t + 0, r, true);
  }
  function bu(t, e) {
    const n = JSON.stringify(e);
    var r = le(n) ? 0 : Ee(n, x.__wbindgen_malloc, x.__wbindgen_realloc), s = ye;
    ge().setInt32(t + 4, s, true), ge().setInt32(t + 0, r, true);
  }
  function mu() {
    return Oe(function(t, e) {
      return t.toString(e);
    }, arguments);
  }
  function wu(t, e, n) {
    const r = e.toString(n), s = Ee(r, x.__wbindgen_malloc, x.__wbindgen_realloc), i = ye;
    ge().setInt32(t + 4, i, true), ge().setInt32(t + 0, s, true);
  }
  function xu(t) {
    return t.toString();
  }
  function Su(t, e) {
    return t.unshift(e);
  }
  function vu(t) {
    return t.value;
  }
  function Au(t) {
    return Object.values(t);
  }
  function Eu(t) {
    return t;
  }
  function Iu(t) {
    return t;
  }
  function Cu(t, e) {
    return Se(t, e);
  }
  function ku(t) {
    return BigInt.asUintN(64, t);
  }
  function Ou() {
    const t = x.__wbindgen_externrefs, e = t.grow(4);
    t.set(0, void 0), t.set(e + 0, void 0), t.set(e + 1, null), t.set(e + 2, true), t.set(e + 3, false);
  }
  const hs = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((t) => x.__wbg_automerge_free(t >>> 0, 1)), gs = typeof FinalizationRegistry > "u" ? {
    register: () => {
    },
    unregister: () => {
    }
  } : new FinalizationRegistry((t) => x.__wbg_syncstate_free(t >>> 0, 1));
  function Ru(t) {
    const e = x.__externref_table_alloc();
    return x.__wbindgen_externrefs.set(e, t), e;
  }
  function Pe(t, e) {
    if (!(t instanceof e)) throw new Error(`expected instance of ${e.name}`);
  }
  function qn(t) {
    const e = typeof t;
    if (e == "number" || e == "boolean" || t == null) return `${t}`;
    if (e == "string") return `"${t}"`;
    if (e == "symbol") {
      const s = t.description;
      return s == null ? "Symbol" : `Symbol(${s})`;
    }
    if (e == "function") {
      const s = t.name;
      return typeof s == "string" && s.length > 0 ? `Function(${s})` : "Function";
    }
    if (Array.isArray(t)) {
      const s = t.length;
      let i = "[";
      s > 0 && (i += qn(t[0]));
      for (let o = 1; o < s; o++) i += ", " + qn(t[o]);
      return i += "]", i;
    }
    const n = /\[object ([^\]]+)\]/.exec(toString.call(t));
    let r;
    if (n && n.length > 1) r = n[1];
    else return toString.call(t);
    if (r == "Object") try {
      return "Object(" + JSON.stringify(t) + ")";
    } catch {
      return "Object";
    }
    return t instanceof Error ? `${t.name}: ${t.message}
${t.stack}` : r;
  }
  function pr(t, e) {
    return t = t >>> 0, ut().subarray(t / 1, t / 1 + e);
  }
  let Ye = null;
  function ge() {
    return (Ye === null || Ye.buffer.detached === true || Ye.buffer.detached === void 0 && Ye.buffer !== x.memory.buffer) && (Ye = new DataView(x.memory.buffer)), Ye;
  }
  function Se(t, e) {
    return t = t >>> 0, Tu(t, e);
  }
  let Tt = null;
  function ut() {
    return (Tt === null || Tt.byteLength === 0) && (Tt = new Uint8Array(x.memory.buffer)), Tt;
  }
  function Oe(t, e) {
    try {
      return t.apply(this, e);
    } catch (n) {
      const r = Ru(n);
      x.__wbindgen_exn_store(r);
    }
  }
  function le(t) {
    return t == null;
  }
  function Ee(t, e, n) {
    if (n === void 0) {
      const a = lt.encode(t), c = e(a.length, 1) >>> 0;
      return ut().subarray(c, c + a.length).set(a), ye = a.length, c;
    }
    let r = t.length, s = e(r, 1) >>> 0;
    const i = ut();
    let o = 0;
    for (; o < r; o++) {
      const a = t.charCodeAt(o);
      if (a > 127) break;
      i[s + o] = a;
    }
    if (o !== r) {
      o !== 0 && (t = t.slice(o)), s = n(s, r, r = o + t.length * 3, 1) >>> 0;
      const a = ut().subarray(s + o, s + r), c = lt.encodeInto(t, a);
      o += c.written, s = n(s, r, o, 1) >>> 0;
    }
    return ye = o, s;
  }
  function H(t) {
    const e = x.__wbindgen_externrefs.get(t);
    return x.__externref_table_dealloc(t), e;
  }
  let Pt = new TextDecoder("utf-8", {
    ignoreBOM: true,
    fatal: true
  });
  Pt.decode();
  const Hu = 2146435072;
  let In = 0;
  function Tu(t, e) {
    return In += e, In >= Hu && (Pt = new TextDecoder("utf-8", {
      ignoreBOM: true,
      fatal: true
    }), Pt.decode(), In = e), Pt.decode(ut().subarray(t, t + e));
  }
  const lt = new TextEncoder();
  "encodeInto" in lt || (lt.encodeInto = function(t, e) {
    const n = lt.encode(t);
    return e.set(n), {
      read: t.length,
      written: n.length
    };
  });
  let ye = 0, x;
  function Uu(t) {
    x = t;
  }
  URL = globalThis.URL;
  const k = await qc({
    "./automerge_wasm_bg.js": {
      __wbg_new_8a6f238a6ece86ea: su,
      __wbg_stack_0ed75d68575b0f3c: yu,
      __wbg_error_7534b8e9a36f1ab4: Uf,
      __wbg_String_8f0eb39a4a4c2f66: cf,
      __wbg_set_3f1d0b984ed272ed: hu,
      __wbg_getRandomValues_1c61fac11405ffdc: jf,
      __wbg_log_6b5ca2e6124b2808: Zf,
      __wbg_log_b948c93e3e66d64f: Qf,
      __wbg_get_9b94d73e6221f75c: Ff,
      __wbg_length_35a7bace40f36eac: Xf,
      __wbg_new_3eb36ae241fe6f44: nu,
      __wbg_BigInt_b7bbccdff258c9f2: of,
      __wbg_next_418f80d8f5303233: fu,
      __wbg_next_3482f54c49e8af19: cu,
      __wbg_done_57b39ecd9addfe81: Hf,
      __wbg_value_0546255b415e96c1: vu,
      __wbg_iterator_6ff6560ca1568e55: Gf,
      __wbg_get_b3ed3ad4be2bc8ac: Pf,
      __wbg_call_389efe28435a9388: If,
      __wbg_new_361308b2356cecd0: tu,
      __wbg_length_68dc7c5cf1b6d349: Yf,
      __wbg_set_f43e577aea94465b: _u,
      __wbg_from_bddd64e7d5ff6941: Bf,
      __wbg_isArray_d314bb98fcf08331: Wf,
      __wbg_push_8ffdcb2063340ba5: du,
      __wbg_unshift_a4a28a3b4a2e621b: Su,
      __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: $f,
      __wbg_toString_3cadee6e7c22b39e: mu,
      __wbg_toString_56d946daff83867b: wu,
      __wbg_new_72b49615380db768: ru,
      __wbg_call_4708e0c13bdc8e95: Cf,
      __wbg_instanceof_Date_1b9f15b87f10aa4c: Vf,
      __wbg_getTime_1e3cd1391c5c3995: Lf,
      __wbg_new_245cd5c49157e602: eu,
      __wbg_instanceof_Object_1c6af87502b733ed: zf,
      __wbg_assign_6170c0d04d5c26f4: Ef,
      __wbg_defineProperty_fc8692a66be8fe2d: Of,
      __wbg_entries_58c7934c745daac7: Tf,
      __wbg_freeze_661d9047fd889cd0: Mf,
      __wbg_keys_b50a709a76add04e: Kf,
      __wbg_values_5da93bc719d272cf: Au,
      __wbg_new_911dabf69fa7eb20: iu,
      __wbg_apply_2e22c45cb4f12415: Af,
      __wbg_deleteProperty_8c8a05da881fea59: Rf,
      __wbg_ownKeys_c7100fb5fa376c6f: uu,
      __wbg_set_6cb8631f80447a67: gu,
      __wbg_concat_f6e5ebc81f4917f1: kf,
      __wbg_slice_b0fa09b1e0041d42: pu,
      __wbg_for_c3adefd268cb6f1c: Df,
      __wbg_toString_b388ecd2d3c517c3: xu,
      __wbg_length_32ed9a279acd054c: Jf,
      __wbg_prototypesetcall_bdcdcc5842e4d77d: lu,
      __wbg_new_dd2b680c8bf6ae29: ou,
      __wbg_instanceof_Uint8Array_9b9075935c74707c: Nf,
      __wbg_new_from_slice_a3d2629dc1826784: au,
      __wbg___wbindgen_string_get_72fb696202c56729: Sf,
      __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: ff,
      __wbg___wbindgen_number_get_8ff4255516ccad3e: xf,
      __wbg___wbindgen_is_undefined_9e4d92534c42d778: yf,
      __wbg___wbindgen_debug_string_0bc8482c6e3508ae: uf,
      __wbg_isArray_a2cef7634fcb7c0d: qf,
      __wbg_Error_8c4e43fe74559d73: af,
      __wbg_stringify_e4a940b133e6b7d8: bu,
      __wbg___wbindgen_is_null_ac34f5003991759a: gf,
      __wbg___wbindgen_is_object_5ae8e5880f2c1fbd: _f,
      __wbg___wbindgen_is_function_0095a73b8b156f76: hf,
      __wbg___wbindgen_is_string_cd444516edc5b180: pf,
      __wbg___wbindgen_is_bigint_31b12575b56f32fc: df,
      __wbg___wbindgen_neg_6b4d356dff49dcc6: wf,
      __wbg___wbindgen_lt_bb59cc3d23526e0d: mf,
      __wbg___wbindgen_gt_d7bb3629eac381f5: lf,
      __wbg___wbindgen_throw_be289d5034ed271b: vf,
      __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: bf,
      __wbindgen_init_externref_table: Ou,
      __wbindgen_cast_0000000000000001: Eu,
      __wbindgen_cast_0000000000000002: Iu,
      __wbindgen_cast_0000000000000003: Cu,
      __wbindgen_cast_0000000000000004: ku
    }
  }, Nc), Du = k.memory, Mu = k.__wbg_syncstate_free, Bu = k.syncstate_sharedHeads, ju = k.syncstate_lastSentHeads, Lu = k.syncstate_set_lastSentHeads, Fu = k.syncstate_set_sentHashes, Pu = k.syncstate_clone, $u = k.__wbg_automerge_free, Vu = k.automerge_new, zu = k.automerge_clone, Nu = k.automerge_fork, qu = k.automerge_pendingOps, Wu = k.automerge_commit, Gu = k.automerge_merge, Ku = k.automerge_rollback, Ju = k.automerge_keys, Xu = k.automerge_text, Yu = k.automerge_spans, Zu = k.automerge_splice, Qu = k.automerge_updateText, el = k.automerge_updateSpans, tl = k.automerge_push, nl = k.automerge_pushObject, rl = k.automerge_insert, sl = k.automerge_splitBlock, il = k.automerge_joinBlock, ol = k.automerge_updateBlock, al = k.automerge_getBlock, cl = k.automerge_insertObject, fl = k.automerge_put, ul = k.automerge_putObject, ll = k.automerge_increment, dl = k.automerge_get, hl = k.automerge_getWithType, gl = k.automerge_objInfo, _l = k.automerge_getAll, pl = k.automerge_enableFreeze, yl = k.automerge_registerDatatype, bl = k.automerge_applyPatches, ml = k.automerge_applyAndReturnPatches, wl = k.automerge_diffIncremental, xl = k.automerge_updateDiffCursor, Sl = k.automerge_resetDiffCursor, vl = k.automerge_diff, Al = k.automerge_diffPath, El = k.automerge_isolate, Il = k.automerge_integrate, Cl = k.automerge_length, kl = k.automerge_delete, Ol = k.automerge_save, Rl = k.automerge_saveIncremental, Hl = k.automerge_saveSince, Tl = k.automerge_saveNoCompress, Ul = k.automerge_saveAndVerify, Dl = k.automerge_loadIncremental, Ml = k.automerge_applyChanges, Bl = k.automerge_getChanges, jl = k.automerge_getChangesMeta, Ll = k.automerge_getChangeByHash, Fl = k.automerge_getChangeMetaByHash, Pl = k.automerge_getDecodedChangeByHash, $l = k.automerge_getChangesAdded, Vl = k.automerge_getHeads, zl = k.automerge_getActorId, Nl = k.automerge_getLastLocalChange, ql = k.automerge_dump, Wl = k.automerge_getMissingDeps, Gl = k.automerge_receiveSyncMessage, Kl = k.automerge_generateSyncMessage, Jl = k.automerge_toJS, Xl = k.automerge_materialize, Yl = k.automerge_getCursor, Zl = k.automerge_getCursorPosition, Ql = k.automerge_emptyChange, ed = k.automerge_mark, td = k.automerge_unmark, nd = k.automerge_marks, rd = k.automerge_marksAt, sd = k.automerge_hasOurChanges, id = k.automerge_topoHistoryTraversal, od = k.automerge_stats, ad = k.automerge_saveBundle, cd = k.create, fd = k.load, ud = k.wasmReleaseInfo, ld = k.encodeChange, dd = k.decodeChange, hd = k.initSyncState, gd = k.importSyncState, _d = k.exportSyncState, pd = k.encodeSyncMessage, yd = k.decodeSyncMessage, bd = k.encodeSyncState, md = k.decodeSyncState, wd = k.readBundle, xd = k.__wbindgen_malloc, Sd = k.__wbindgen_realloc, vd = k.__wbindgen_exn_store, Ad = k.__externref_table_alloc, Ed = k.__wbindgen_externrefs, Id = k.__wbindgen_free, Cd = k.__externref_table_dealloc, yi = k.__wbindgen_start, kd = Object.freeze(Object.defineProperty({
    __proto__: null,
    __externref_table_alloc: Ad,
    __externref_table_dealloc: Cd,
    __wbg_automerge_free: $u,
    __wbg_syncstate_free: Mu,
    __wbindgen_exn_store: vd,
    __wbindgen_externrefs: Ed,
    __wbindgen_free: Id,
    __wbindgen_malloc: xd,
    __wbindgen_realloc: Sd,
    __wbindgen_start: yi,
    automerge_applyAndReturnPatches: ml,
    automerge_applyChanges: Ml,
    automerge_applyPatches: bl,
    automerge_clone: zu,
    automerge_commit: Wu,
    automerge_delete: kl,
    automerge_diff: vl,
    automerge_diffIncremental: wl,
    automerge_diffPath: Al,
    automerge_dump: ql,
    automerge_emptyChange: Ql,
    automerge_enableFreeze: pl,
    automerge_fork: Nu,
    automerge_generateSyncMessage: Kl,
    automerge_get: dl,
    automerge_getActorId: zl,
    automerge_getAll: _l,
    automerge_getBlock: al,
    automerge_getChangeByHash: Ll,
    automerge_getChangeMetaByHash: Fl,
    automerge_getChanges: Bl,
    automerge_getChangesAdded: $l,
    automerge_getChangesMeta: jl,
    automerge_getCursor: Yl,
    automerge_getCursorPosition: Zl,
    automerge_getDecodedChangeByHash: Pl,
    automerge_getHeads: Vl,
    automerge_getLastLocalChange: Nl,
    automerge_getMissingDeps: Wl,
    automerge_getWithType: hl,
    automerge_hasOurChanges: sd,
    automerge_increment: ll,
    automerge_insert: rl,
    automerge_insertObject: cl,
    automerge_integrate: Il,
    automerge_isolate: El,
    automerge_joinBlock: il,
    automerge_keys: Ju,
    automerge_length: Cl,
    automerge_loadIncremental: Dl,
    automerge_mark: ed,
    automerge_marks: nd,
    automerge_marksAt: rd,
    automerge_materialize: Xl,
    automerge_merge: Gu,
    automerge_new: Vu,
    automerge_objInfo: gl,
    automerge_pendingOps: qu,
    automerge_push: tl,
    automerge_pushObject: nl,
    automerge_put: fl,
    automerge_putObject: ul,
    automerge_receiveSyncMessage: Gl,
    automerge_registerDatatype: yl,
    automerge_resetDiffCursor: Sl,
    automerge_rollback: Ku,
    automerge_save: Ol,
    automerge_saveAndVerify: Ul,
    automerge_saveBundle: ad,
    automerge_saveIncremental: Rl,
    automerge_saveNoCompress: Tl,
    automerge_saveSince: Hl,
    automerge_spans: Yu,
    automerge_splice: Zu,
    automerge_splitBlock: sl,
    automerge_stats: od,
    automerge_text: Xu,
    automerge_toJS: Jl,
    automerge_topoHistoryTraversal: id,
    automerge_unmark: td,
    automerge_updateBlock: ol,
    automerge_updateDiffCursor: xl,
    automerge_updateSpans: el,
    automerge_updateText: Qu,
    create: cd,
    decodeChange: dd,
    decodeSyncMessage: yd,
    decodeSyncState: md,
    encodeChange: ld,
    encodeSyncMessage: pd,
    encodeSyncState: bd,
    exportSyncState: _d,
    importSyncState: gd,
    initSyncState: hd,
    load: fd,
    memory: Du,
    readBundle: wd,
    syncstate_clone: Pu,
    syncstate_lastSentHeads: ju,
    syncstate_set_lastSentHeads: Lu,
    syncstate_set_sentHashes: Fu,
    syncstate_sharedHeads: Bu,
    wasmReleaseInfo: ud
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  Uu(kd);
  yi();
  const Od = Object.freeze(Object.defineProperty({
    __proto__: null,
    Automerge: xe,
    SyncState: he,
    create: Wc,
    decodeChange: Gc,
    decodeSyncMessage: Kc,
    decodeSyncState: Jc,
    encodeChange: Xc,
    encodeSyncMessage: Yc,
    encodeSyncState: Zc,
    exportSyncState: Qc,
    importSyncState: ef,
    initSyncState: tf,
    load: nf,
    readBundle: rf,
    wasmReleaseInfo: sf
  }, Symbol.toStringTag, {
    value: "Module"
  }));
  Hi(Od);
})();
export {
  gr as A,
  Td as B,
  zd as C,
  Nn as D,
  Cs as E,
  Fd as F,
  oc as G,
  jd as H,
  En as R,
  Ht as U,
  __tla,
  $d as a,
  Lc as b,
  Te as c,
  Xn as d,
  Es as e,
  Dd as f,
  Ut as g,
  Ud as h,
  Fa as i,
  $i as j,
  Pi as k,
  Li as l,
  cc as m,
  Qe as n,
  Rd as o,
  Hd as p,
  fr as q,
  Md as r,
  Vd as s,
  Mc as t,
  Gt as u,
  Ca as v,
  mr as w,
  Bd as x,
  Pd as y,
  Ld as z
};
