import q from "../../../../orderedmap@2.1.1/node_modules/orderedmap/dist/index.js";
function Y(l, t, e) {
  for (let n = 0; ; n++) {
    if (n == l.childCount || n == t.childCount)
      return l.childCount == t.childCount ? null : e;
    let i = l.child(n), r = t.child(n);
    if (i == r) {
      e += i.nodeSize;
      continue;
    }
    if (!i.sameMarkup(r))
      return e;
    if (i.isText && i.text != r.text) {
      for (let s = 0; i.text[s] == r.text[s]; s++)
        e++;
      return e;
    }
    if (i.content.size || r.content.size) {
      let s = Y(i.content, r.content, e + 1);
      if (s != null)
        return s;
    }
    e += i.nodeSize;
  }
}
function Z(l, t, e, n) {
  for (let i = l.childCount, r = t.childCount; ; ) {
    if (i == 0 || r == 0)
      return i == r ? null : { a: e, b: n };
    let s = l.child(--i), o = t.child(--r), h = s.nodeSize;
    if (s == o) {
      e -= h, n -= h;
      continue;
    }
    if (!s.sameMarkup(o))
      return { a: e, b: n };
    if (s.isText && s.text != o.text) {
      let a = 0, f = Math.min(s.text.length, o.text.length);
      for (; a < f && s.text[s.text.length - a - 1] == o.text[o.text.length - a - 1]; )
        a++, e--, n--;
      return { a: e, b: n };
    }
    if (s.content.size || o.content.size) {
      let a = Z(s.content, o.content, e - 1, n - 1);
      if (a)
        return a;
    }
    e -= h, n -= h;
  }
}
class c {
  /**
  @internal
  */
  constructor(t, e) {
    if (this.content = t, this.size = e || 0, e == null)
      for (let n = 0; n < t.length; n++)
        this.size += t[n].nodeSize;
  }
  /**
  Invoke a callback for all descendant nodes between the given two
  positions (relative to start of this fragment). Doesn't descend
  into a node when the callback returns `false`.
  */
  nodesBetween(t, e, n, i = 0, r) {
    for (let s = 0, o = 0; o < e; s++) {
      let h = this.content[s], a = o + h.nodeSize;
      if (a > t && n(h, i + o, r || null, s) !== !1 && h.content.size) {
        let f = o + 1;
        h.nodesBetween(Math.max(0, t - f), Math.min(h.content.size, e - f), n, i + f);
      }
      o = a;
    }
  }
  /**
  Call the given callback for every descendant node. `pos` will be
  relative to the start of the fragment. The callback may return
  `false` to prevent traversal of a given node's children.
  */
  descendants(t) {
    this.nodesBetween(0, this.size, t);
  }
  /**
  Extract the text between `from` and `to`. See the same method on
  [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
  */
  textBetween(t, e, n, i) {
    let r = "", s = !0;
    return this.nodesBetween(t, e, (o, h) => {
      let a = o.isText ? o.text.slice(Math.max(t, h) - h, e - h) : o.isLeaf ? i ? typeof i == "function" ? i(o) : i : o.type.spec.leafText ? o.type.spec.leafText(o) : "" : "";
      o.isBlock && (o.isLeaf && a || o.isTextblock) && n && (s ? s = !1 : r += n), r += a;
    }, 0), r;
  }
  /**
  Create a new fragment containing the combined content of this
  fragment and the other.
  */
  append(t) {
    if (!t.size)
      return this;
    if (!this.size)
      return t;
    let e = this.lastChild, n = t.firstChild, i = this.content.slice(), r = 0;
    for (e.isText && e.sameMarkup(n) && (i[i.length - 1] = e.withText(e.text + n.text), r = 1); r < t.content.length; r++)
      i.push(t.content[r]);
    return new c(i, this.size + t.size);
  }
  /**
  Cut out the sub-fragment between the two given positions.
  */
  cut(t, e = this.size) {
    if (t == 0 && e == this.size)
      return this;
    let n = [], i = 0;
    if (e > t)
      for (let r = 0, s = 0; s < e; r++) {
        let o = this.content[r], h = s + o.nodeSize;
        h > t && ((s < t || h > e) && (o.isText ? o = o.cut(Math.max(0, t - s), Math.min(o.text.length, e - s)) : o = o.cut(Math.max(0, t - s - 1), Math.min(o.content.size, e - s - 1))), n.push(o), i += o.nodeSize), s = h;
      }
    return new c(n, i);
  }
  /**
  @internal
  */
  cutByIndex(t, e) {
    return t == e ? c.empty : t == 0 && e == this.content.length ? this : new c(this.content.slice(t, e));
  }
  /**
  Create a new fragment in which the node at the given index is
  replaced by the given node.
  */
  replaceChild(t, e) {
    let n = this.content[t];
    if (n == e)
      return this;
    let i = this.content.slice(), r = this.size + e.nodeSize - n.nodeSize;
    return i[t] = e, new c(i, r);
  }
  /**
  Create a new fragment by prepending the given node to this
  fragment.
  */
  addToStart(t) {
    return new c([t].concat(this.content), this.size + t.nodeSize);
  }
  /**
  Create a new fragment by appending the given node to this
  fragment.
  */
  addToEnd(t) {
    return new c(this.content.concat(t), this.size + t.nodeSize);
  }
  /**
  Compare this fragment to another one.
  */
  eq(t) {
    if (this.content.length != t.content.length)
      return !1;
    for (let e = 0; e < this.content.length; e++)
      if (!this.content[e].eq(t.content[e]))
        return !1;
    return !0;
  }
  /**
  The first child of the fragment, or `null` if it is empty.
  */
  get firstChild() {
    return this.content.length ? this.content[0] : null;
  }
  /**
  The last child of the fragment, or `null` if it is empty.
  */
  get lastChild() {
    return this.content.length ? this.content[this.content.length - 1] : null;
  }
  /**
  The number of child nodes in this fragment.
  */
  get childCount() {
    return this.content.length;
  }
  /**
  Get the child node at the given index. Raise an error when the
  index is out of range.
  */
  child(t) {
    let e = this.content[t];
    if (!e)
      throw new RangeError("Index " + t + " out of range for " + this);
    return e;
  }
  /**
  Get the child node at the given index, if it exists.
  */
  maybeChild(t) {
    return this.content[t] || null;
  }
  /**
  Call `f` for every child node, passing the node, its offset
  into this parent node, and its index.
  */
  forEach(t) {
    for (let e = 0, n = 0; e < this.content.length; e++) {
      let i = this.content[e];
      t(i, n, e), n += i.nodeSize;
    }
  }
  /**
  Find the first position at which this fragment and another
  fragment differ, or `null` if they are the same.
  */
  findDiffStart(t, e = 0) {
    return Y(this, t, e);
  }
  /**
  Find the first position, searching from the end, at which this
  fragment and the given fragment differ, or `null` if they are
  the same. Since this position will not be the same in both
  nodes, an object with two separate positions is returned.
  */
  findDiffEnd(t, e = this.size, n = t.size) {
    return Z(this, t, e, n);
  }
  /**
  Find the index and inner offset corresponding to a given relative
  position in this fragment. The result object will be reused
  (overwritten) the next time the function is called. @internal
  */
  findIndex(t, e = -1) {
    if (t == 0)
      return O(0, t);
    if (t == this.size)
      return O(this.content.length, t);
    if (t > this.size || t < 0)
      throw new RangeError(`Position ${t} outside of fragment (${this})`);
    for (let n = 0, i = 0; ; n++) {
      let r = this.child(n), s = i + r.nodeSize;
      if (s >= t)
        return s == t || e > 0 ? O(n + 1, s) : O(n, i);
      i = s;
    }
  }
  /**
  Return a debugging string that describes this fragment.
  */
  toString() {
    return "<" + this.toStringInner() + ">";
  }
  /**
  @internal
  */
  toStringInner() {
    return this.content.join(", ");
  }
  /**
  Create a JSON-serializeable representation of this fragment.
  */
  toJSON() {
    return this.content.length ? this.content.map((t) => t.toJSON()) : null;
  }
  /**
  Deserialize a fragment from its JSON representation.
  */
  static fromJSON(t, e) {
    if (!e)
      return c.empty;
    if (!Array.isArray(e))
      throw new RangeError("Invalid input for Fragment.fromJSON");
    return new c(e.map(t.nodeFromJSON));
  }
  /**
  Build a fragment from an array of nodes. Ensures that adjacent
  text nodes with the same marks are joined together.
  */
  static fromArray(t) {
    if (!t.length)
      return c.empty;
    let e, n = 0;
    for (let i = 0; i < t.length; i++) {
      let r = t[i];
      n += r.nodeSize, i && r.isText && t[i - 1].sameMarkup(r) ? (e || (e = t.slice(0, i)), e[e.length - 1] = r.withText(e[e.length - 1].text + r.text)) : e && e.push(r);
    }
    return new c(e || t, n);
  }
  /**
  Create a fragment from something that can be interpreted as a
  set of nodes. For `null`, it returns the empty fragment. For a
  fragment, the fragment itself. For a node or array of nodes, a
  fragment containing those nodes.
  */
  static from(t) {
    if (!t)
      return c.empty;
    if (t instanceof c)
      return t;
    if (Array.isArray(t))
      return this.fromArray(t);
    if (t.attrs)
      return new c([t], t.nodeSize);
    throw new RangeError("Can not convert " + t + " to a Fragment" + (t.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
  }
}
c.empty = new c([], 0);
const v = { index: 0, offset: 0 };
function O(l, t) {
  return v.index = l, v.offset = t, v;
}
function M(l, t) {
  if (l === t)
    return !0;
  if (!(l && typeof l == "object") || !(t && typeof t == "object"))
    return !1;
  let e = Array.isArray(l);
  if (Array.isArray(t) != e)
    return !1;
  if (e) {
    if (l.length != t.length)
      return !1;
    for (let n = 0; n < l.length; n++)
      if (!M(l[n], t[n]))
        return !1;
  } else {
    for (let n in l)
      if (!(n in t) || !M(l[n], t[n]))
        return !1;
    for (let n in t)
      if (!(n in l))
        return !1;
  }
  return !0;
}
class u {
  /**
  @internal
  */
  constructor(t, e) {
    this.type = t, this.attrs = e;
  }
  /**
  Given a set of marks, create a new set which contains this one as
  well, in the right position. If this mark is already in the set,
  the set itself is returned. If any marks that are set to be
  [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,
  those are replaced by this one.
  */
  addToSet(t) {
    let e, n = !1;
    for (let i = 0; i < t.length; i++) {
      let r = t[i];
      if (this.eq(r))
        return t;
      if (this.type.excludes(r.type))
        e || (e = t.slice(0, i));
      else {
        if (r.type.excludes(this.type))
          return t;
        !n && r.type.rank > this.type.rank && (e || (e = t.slice(0, i)), e.push(this), n = !0), e && e.push(r);
      }
    }
    return e || (e = t.slice()), n || e.push(this), e;
  }
  /**
  Remove this mark from the given set, returning a new set. If this
  mark is not in the set, the set itself is returned.
  */
  removeFromSet(t) {
    for (let e = 0; e < t.length; e++)
      if (this.eq(t[e]))
        return t.slice(0, e).concat(t.slice(e + 1));
    return t;
  }
  /**
  Test whether this mark is in the given set of marks.
  */
  isInSet(t) {
    for (let e = 0; e < t.length; e++)
      if (this.eq(t[e]))
        return !0;
    return !1;
  }
  /**
  Test whether this mark has the same type and attributes as
  another mark.
  */
  eq(t) {
    return this == t || this.type == t.type && M(this.attrs, t.attrs);
  }
  /**
  Convert this mark to a JSON-serializeable representation.
  */
  toJSON() {
    let t = { type: this.type.name };
    for (let e in this.attrs) {
      t.attrs = this.attrs;
      break;
    }
    return t;
  }
  /**
  Deserialize a mark from JSON.
  */
  static fromJSON(t, e) {
    if (!e)
      throw new RangeError("Invalid input for Mark.fromJSON");
    let n = t.marks[e.type];
    if (!n)
      throw new RangeError(`There is no mark type ${e.type} in this schema`);
    let i = n.create(e.attrs);
    return n.checkAttrs(i.attrs), i;
  }
  /**
  Test whether two sets of marks are identical.
  */
  static sameSet(t, e) {
    if (t == e)
      return !0;
    if (t.length != e.length)
      return !1;
    for (let n = 0; n < t.length; n++)
      if (!t[n].eq(e[n]))
        return !1;
    return !0;
  }
  /**
  Create a properly sorted mark set from null, a single mark, or an
  unsorted array of marks.
  */
  static setFrom(t) {
    if (!t || Array.isArray(t) && t.length == 0)
      return u.none;
    if (t instanceof u)
      return [t];
    let e = t.slice();
    return e.sort((n, i) => n.type.rank - i.type.rank), e;
  }
}
u.none = [];
class I extends Error {
}
class d {
  /**
  Create a slice. When specifying a non-zero open depth, you must
  make sure that there are nodes of at least that depth at the
  appropriate side of the fragment—i.e. if the fragment is an
  empty paragraph node, `openStart` and `openEnd` can't be greater
  than 1.
  
  It is not necessary for the content of open nodes to conform to
  the schema's content constraints, though it should be a valid
  start/end/middle for such a node, depending on which sides are
  open.
  */
  constructor(t, e, n) {
    this.content = t, this.openStart = e, this.openEnd = n;
  }
  /**
  The size this slice would add when inserted into a document.
  */
  get size() {
    return this.content.size - this.openStart - this.openEnd;
  }
  /**
  @internal
  */
  insertAt(t, e) {
    let n = $(this.content, t + this.openStart, e);
    return n && new d(n, this.openStart, this.openEnd);
  }
  /**
  @internal
  */
  removeBetween(t, e) {
    return new d(_(this.content, t + this.openStart, e + this.openStart), this.openStart, this.openEnd);
  }
  /**
  Tests whether this slice is equal to another slice.
  */
  eq(t) {
    return this.content.eq(t.content) && this.openStart == t.openStart && this.openEnd == t.openEnd;
  }
  /**
  @internal
  */
  toString() {
    return this.content + "(" + this.openStart + "," + this.openEnd + ")";
  }
  /**
  Convert a slice to a JSON-serializable representation.
  */
  toJSON() {
    if (!this.content.size)
      return null;
    let t = { content: this.content.toJSON() };
    return this.openStart > 0 && (t.openStart = this.openStart), this.openEnd > 0 && (t.openEnd = this.openEnd), t;
  }
  /**
  Deserialize a slice from its JSON representation.
  */
  static fromJSON(t, e) {
    if (!e)
      return d.empty;
    let n = e.openStart || 0, i = e.openEnd || 0;
    if (typeof n != "number" || typeof i != "number")
      throw new RangeError("Invalid input for Slice.fromJSON");
    return new d(c.fromJSON(t, e.content), n, i);
  }
  /**
  Create a slice from a fragment by taking the maximum possible
  open value on both side of the fragment.
  */
  static maxOpen(t, e = !0) {
    let n = 0, i = 0;
    for (let r = t.firstChild; r && !r.isLeaf && (e || !r.type.spec.isolating); r = r.firstChild)
      n++;
    for (let r = t.lastChild; r && !r.isLeaf && (e || !r.type.spec.isolating); r = r.lastChild)
      i++;
    return new d(t, n, i);
  }
}
d.empty = new d(c.empty, 0, 0);
function _(l, t, e) {
  let { index: n, offset: i } = l.findIndex(t), r = l.maybeChild(n), { index: s, offset: o } = l.findIndex(e);
  if (i == t || r.isText) {
    if (o != e && !l.child(s).isText)
      throw new RangeError("Removing non-flat range");
    return l.cut(0, t).append(l.cut(e));
  }
  if (n != s)
    throw new RangeError("Removing non-flat range");
  return l.replaceChild(n, r.copy(_(r.content, t - i - 1, e - i - 1)));
}
function $(l, t, e, n) {
  let { index: i, offset: r } = l.findIndex(t), s = l.maybeChild(i);
  if (r == t || s.isText)
    return l.cut(0, t).append(e).append(l.cut(t));
  let o = $(s.content, t - r - 1, e);
  return o && l.replaceChild(i, s.copy(o));
}
function dt(l, t, e) {
  if (e.openStart > l.depth)
    throw new I("Inserted content deeper than insertion position");
  if (l.depth - e.openStart != t.depth - e.openEnd)
    throw new I("Inconsistent open depths");
  return tt(l, t, e, 0);
}
function tt(l, t, e, n) {
  let i = l.index(n), r = l.node(n);
  if (i == t.index(n) && n < l.depth - e.openStart) {
    let s = tt(l, t, e, n + 1);
    return r.copy(r.content.replaceChild(i, s));
  } else if (e.content.size)
    if (!e.openStart && !e.openEnd && l.depth == n && t.depth == n) {
      let s = l.parent, o = s.content;
      return m(s, o.cut(0, l.parentOffset).append(e.content).append(o.cut(t.parentOffset)));
    } else {
      let { start: s, end: o } = gt(e, l);
      return m(r, nt(l, s, o, t, n));
    }
  else return m(r, A(l, t, n));
}
function et(l, t) {
  if (!t.type.compatibleContent(l.type))
    throw new I("Cannot join " + t.type.name + " onto " + l.type.name);
}
function D(l, t, e) {
  let n = l.node(e);
  return et(n, t.node(e)), n;
}
function x(l, t) {
  let e = t.length - 1;
  e >= 0 && l.isText && l.sameMarkup(t[e]) ? t[e] = l.withText(t[e].text + l.text) : t.push(l);
}
function k(l, t, e, n) {
  let i = (t || l).node(e), r = 0, s = t ? t.index(e) : i.childCount;
  l && (r = l.index(e), l.depth > e ? r++ : l.textOffset && (x(l.nodeAfter, n), r++));
  for (let o = r; o < s; o++)
    x(i.child(o), n);
  t && t.depth == e && t.textOffset && x(t.nodeBefore, n);
}
function m(l, t) {
  return l.type.checkContent(t), l.copy(t);
}
function nt(l, t, e, n, i) {
  let r = l.depth > i && D(l, t, i + 1), s = n.depth > i && D(e, n, i + 1), o = [];
  return k(null, l, i, o), r && s && t.index(i) == e.index(i) ? (et(r, s), x(m(r, nt(l, t, e, n, i + 1)), o)) : (r && x(m(r, A(l, t, i + 1)), o), k(t, e, i, o), s && x(m(s, A(e, n, i + 1)), o)), k(n, null, i, o), new c(o);
}
function A(l, t, e) {
  let n = [];
  if (k(null, l, e, n), l.depth > e) {
    let i = D(l, t, e + 1);
    x(m(i, A(l, t, e + 1)), n);
  }
  return k(t, null, e, n), new c(n);
}
function gt(l, t) {
  let e = t.depth - l.openStart, i = t.node(e).copy(l.content);
  for (let r = e - 1; r >= 0; r--)
    i = t.node(r).copy(c.from(i));
  return {
    start: i.resolveNoCache(l.openStart + e),
    end: i.resolveNoCache(i.content.size - l.openEnd - e)
  };
}
class E {
  /**
  @internal
  */
  constructor(t, e, n) {
    this.pos = t, this.path = e, this.parentOffset = n, this.depth = e.length / 3 - 1;
  }
  /**
  @internal
  */
  resolveDepth(t) {
    return t == null ? this.depth : t < 0 ? this.depth + t : t;
  }
  /**
  The parent node that the position points into. Note that even if
  a position points into a text node, that node is not considered
  the parent—text nodes are ‘flat’ in this model, and have no content.
  */
  get parent() {
    return this.node(this.depth);
  }
  /**
  The root node in which the position was resolved.
  */
  get doc() {
    return this.node(0);
  }
  /**
  The ancestor node at the given level. `p.node(p.depth)` is the
  same as `p.parent`.
  */
  node(t) {
    return this.path[this.resolveDepth(t) * 3];
  }
  /**
  The index into the ancestor at the given level. If this points
  at the 3rd node in the 2nd paragraph on the top level, for
  example, `p.index(0)` is 1 and `p.index(1)` is 2.
  */
  index(t) {
    return this.path[this.resolveDepth(t) * 3 + 1];
  }
  /**
  The index pointing after this position into the ancestor at the
  given level.
  */
  indexAfter(t) {
    return t = this.resolveDepth(t), this.index(t) + (t == this.depth && !this.textOffset ? 0 : 1);
  }
  /**
  The (absolute) position at the start of the node at the given
  level.
  */
  start(t) {
    return t = this.resolveDepth(t), t == 0 ? 0 : this.path[t * 3 - 1] + 1;
  }
  /**
  The (absolute) position at the end of the node at the given
  level.
  */
  end(t) {
    return t = this.resolveDepth(t), this.start(t) + this.node(t).content.size;
  }
  /**
  The (absolute) position directly before the wrapping node at the
  given level, or, when `depth` is `this.depth + 1`, the original
  position.
  */
  before(t) {
    if (t = this.resolveDepth(t), !t)
      throw new RangeError("There is no position before the top-level node");
    return t == this.depth + 1 ? this.pos : this.path[t * 3 - 1];
  }
  /**
  The (absolute) position directly after the wrapping node at the
  given level, or the original position when `depth` is `this.depth + 1`.
  */
  after(t) {
    if (t = this.resolveDepth(t), !t)
      throw new RangeError("There is no position after the top-level node");
    return t == this.depth + 1 ? this.pos : this.path[t * 3 - 1] + this.path[t * 3].nodeSize;
  }
  /**
  When this position points into a text node, this returns the
  distance between the position and the start of the text node.
  Will be zero for positions that point between nodes.
  */
  get textOffset() {
    return this.pos - this.path[this.path.length - 1];
  }
  /**
  Get the node directly after the position, if any. If the position
  points into a text node, only the part of that node after the
  position is returned.
  */
  get nodeAfter() {
    let t = this.parent, e = this.index(this.depth);
    if (e == t.childCount)
      return null;
    let n = this.pos - this.path[this.path.length - 1], i = t.child(e);
    return n ? t.child(e).cut(n) : i;
  }
  /**
  Get the node directly before the position, if any. If the
  position points into a text node, only the part of that node
  before the position is returned.
  */
  get nodeBefore() {
    let t = this.index(this.depth), e = this.pos - this.path[this.path.length - 1];
    return e ? this.parent.child(t).cut(0, e) : t == 0 ? null : this.parent.child(t - 1);
  }
  /**
  Get the position at the given index in the parent node at the
  given depth (which defaults to `this.depth`).
  */
  posAtIndex(t, e) {
    e = this.resolveDepth(e);
    let n = this.path[e * 3], i = e == 0 ? 0 : this.path[e * 3 - 1] + 1;
    for (let r = 0; r < t; r++)
      i += n.child(r).nodeSize;
    return i;
  }
  /**
  Get the marks at this position, factoring in the surrounding
  marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the
  position is at the start of a non-empty node, the marks of the
  node after it (if any) are returned.
  */
  marks() {
    let t = this.parent, e = this.index();
    if (t.content.size == 0)
      return u.none;
    if (this.textOffset)
      return t.child(e).marks;
    let n = t.maybeChild(e - 1), i = t.maybeChild(e);
    if (!n) {
      let o = n;
      n = i, i = o;
    }
    let r = n.marks;
    for (var s = 0; s < r.length; s++)
      r[s].type.spec.inclusive === !1 && (!i || !r[s].isInSet(i.marks)) && (r = r[s--].removeFromSet(r));
    return r;
  }
  /**
  Get the marks after the current position, if any, except those
  that are non-inclusive and not present at position `$end`. This
  is mostly useful for getting the set of marks to preserve after a
  deletion. Will return `null` if this position is at the end of
  its parent node or its parent node isn't a textblock (in which
  case no marks should be preserved).
  */
  marksAcross(t) {
    let e = this.parent.maybeChild(this.index());
    if (!e || !e.isInline)
      return null;
    let n = e.marks, i = t.parent.maybeChild(t.index());
    for (var r = 0; r < n.length; r++)
      n[r].type.spec.inclusive === !1 && (!i || !n[r].isInSet(i.marks)) && (n = n[r--].removeFromSet(n));
    return n;
  }
  /**
  The depth up to which this position and the given (non-resolved)
  position share the same parent nodes.
  */
  sharedDepth(t) {
    for (let e = this.depth; e > 0; e--)
      if (this.start(e) <= t && this.end(e) >= t)
        return e;
    return 0;
  }
  /**
  Returns a range based on the place where this position and the
  given position diverge around block content. If both point into
  the same textblock, for example, a range around that textblock
  will be returned. If they point into different blocks, the range
  around those blocks in their shared ancestor is returned. You can
  pass in an optional predicate that will be called with a parent
  node to see if a range into that parent is acceptable.
  */
  blockRange(t = this, e) {
    if (t.pos < this.pos)
      return t.blockRange(this);
    for (let n = this.depth - (this.parent.inlineContent || this.pos == t.pos ? 1 : 0); n >= 0; n--)
      if (t.pos <= this.end(n) && (!e || e(this.node(n))))
        return new mt(this, t, n);
    return null;
  }
  /**
  Query whether the given position shares the same parent node.
  */
  sameParent(t) {
    return this.pos - this.parentOffset == t.pos - t.parentOffset;
  }
  /**
  Return the greater of this and the given position.
  */
  max(t) {
    return t.pos > this.pos ? t : this;
  }
  /**
  Return the smaller of this and the given position.
  */
  min(t) {
    return t.pos < this.pos ? t : this;
  }
  /**
  @internal
  */
  toString() {
    let t = "";
    for (let e = 1; e <= this.depth; e++)
      t += (t ? "/" : "") + this.node(e).type.name + "_" + this.index(e - 1);
    return t + ":" + this.parentOffset;
  }
  /**
  @internal
  */
  static resolve(t, e) {
    if (!(e >= 0 && e <= t.content.size))
      throw new RangeError("Position " + e + " out of range");
    let n = [], i = 0, r = e;
    for (let s = t; ; ) {
      let { index: o, offset: h } = s.content.findIndex(r), a = r - h;
      if (n.push(s, o, i + h), !a || (s = s.child(o), s.isText))
        break;
      r = a - 1, i += h + 1;
    }
    return new E(e, n, r);
  }
  /**
  @internal
  */
  static resolveCached(t, e) {
    let n = L.get(t);
    if (n)
      for (let r = 0; r < n.elts.length; r++) {
        let s = n.elts[r];
        if (s.pos == e)
          return s;
      }
    else
      L.set(t, n = new yt());
    let i = n.elts[n.i] = E.resolve(t, e);
    return n.i = (n.i + 1) % xt, i;
  }
}
class yt {
  constructor() {
    this.elts = [], this.i = 0;
  }
}
const xt = 12, L = /* @__PURE__ */ new WeakMap();
class mt {
  /**
  Construct a node range. `$from` and `$to` should point into the
  same node until at least the given `depth`, since a node range
  denotes an adjacent set of nodes in a single parent node.
  */
  constructor(t, e, n) {
    this.$from = t, this.$to = e, this.depth = n;
  }
  /**
  The position at the start of the range.
  */
  get start() {
    return this.$from.before(this.depth + 1);
  }
  /**
  The position at the end of the range.
  */
  get end() {
    return this.$to.after(this.depth + 1);
  }
  /**
  The parent node that the range points into.
  */
  get parent() {
    return this.$from.node(this.depth);
  }
  /**
  The start index of the range in the parent node.
  */
  get startIndex() {
    return this.$from.index(this.depth);
  }
  /**
  The end index of the range in the parent node.
  */
  get endIndex() {
    return this.$to.indexAfter(this.depth);
  }
}
const wt = /* @__PURE__ */ Object.create(null);
class y {
  /**
  @internal
  */
  constructor(t, e, n, i = u.none) {
    this.type = t, this.attrs = e, this.marks = i, this.content = n || c.empty;
  }
  /**
  The array of this node's child nodes.
  */
  get children() {
    return this.content.content;
  }
  /**
  The size of this node, as defined by the integer-based [indexing
  scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the
  amount of characters. For other leaf nodes, it is one. For
  non-leaf nodes, it is the size of the content plus two (the
  start and end token).
  */
  get nodeSize() {
    return this.isLeaf ? 1 : 2 + this.content.size;
  }
  /**
  The number of children that the node has.
  */
  get childCount() {
    return this.content.childCount;
  }
  /**
  Get the child node at the given index. Raises an error when the
  index is out of range.
  */
  child(t) {
    return this.content.child(t);
  }
  /**
  Get the child node at the given index, if it exists.
  */
  maybeChild(t) {
    return this.content.maybeChild(t);
  }
  /**
  Call `f` for every child node, passing the node, its offset
  into this parent node, and its index.
  */
  forEach(t) {
    this.content.forEach(t);
  }
  /**
  Invoke a callback for all descendant nodes recursively between
  the given two positions that are relative to start of this
  node's content. The callback is invoked with the node, its
  position relative to the original node (method receiver),
  its parent node, and its child index. When the callback returns
  false for a given node, that node's children will not be
  recursed over. The last parameter can be used to specify a
  starting position to count from.
  */
  nodesBetween(t, e, n, i = 0) {
    this.content.nodesBetween(t, e, n, i, this);
  }
  /**
  Call the given callback for every descendant node. Doesn't
  descend into a node when the callback returns `false`.
  */
  descendants(t) {
    this.nodesBetween(0, this.content.size, t);
  }
  /**
  Concatenates all the text nodes found in this fragment and its
  children.
  */
  get textContent() {
    return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, "");
  }
  /**
  Get all text between positions `from` and `to`. When
  `blockSeparator` is given, it will be inserted to separate text
  from different block nodes. If `leafText` is given, it'll be
  inserted for every non-text leaf node encountered, otherwise
  [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec^leafText) will be used.
  */
  textBetween(t, e, n, i) {
    return this.content.textBetween(t, e, n, i);
  }
  /**
  Returns this node's first child, or `null` if there are no
  children.
  */
  get firstChild() {
    return this.content.firstChild;
  }
  /**
  Returns this node's last child, or `null` if there are no
  children.
  */
  get lastChild() {
    return this.content.lastChild;
  }
  /**
  Test whether two nodes represent the same piece of document.
  */
  eq(t) {
    return this == t || this.sameMarkup(t) && this.content.eq(t.content);
  }
  /**
  Compare the markup (type, attributes, and marks) of this node to
  those of another. Returns `true` if both have the same markup.
  */
  sameMarkup(t) {
    return this.hasMarkup(t.type, t.attrs, t.marks);
  }
  /**
  Check whether this node's markup correspond to the given type,
  attributes, and marks.
  */
  hasMarkup(t, e, n) {
    return this.type == t && M(this.attrs, e || t.defaultAttrs || wt) && u.sameSet(this.marks, n || u.none);
  }
  /**
  Create a new node with the same markup as this node, containing
  the given content (or empty, if no content is given).
  */
  copy(t = null) {
    return t == this.content ? this : new y(this.type, this.attrs, t, this.marks);
  }
  /**
  Create a copy of this node, with the given set of marks instead
  of the node's own marks.
  */
  mark(t) {
    return t == this.marks ? this : new y(this.type, this.attrs, this.content, t);
  }
  /**
  Create a copy of this node with only the content between the
  given positions. If `to` is not given, it defaults to the end of
  the node.
  */
  cut(t, e = this.content.size) {
    return t == 0 && e == this.content.size ? this : this.copy(this.content.cut(t, e));
  }
  /**
  Cut out the part of the document between the given positions, and
  return it as a `Slice` object.
  */
  slice(t, e = this.content.size, n = !1) {
    if (t == e)
      return d.empty;
    let i = this.resolve(t), r = this.resolve(e), s = n ? 0 : i.sharedDepth(e), o = i.start(s), a = i.node(s).content.cut(i.pos - o, r.pos - o);
    return new d(a, i.depth - s, r.depth - s);
  }
  /**
  Replace the part of the document between the given positions with
  the given slice. The slice must 'fit', meaning its open sides
  must be able to connect to the surrounding content, and its
  content nodes must be valid children for the node they are placed
  into. If any of this is violated, an error of type
  [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.
  */
  replace(t, e, n) {
    return dt(this.resolve(t), this.resolve(e), n);
  }
  /**
  Find the node directly after the given position.
  */
  nodeAt(t) {
    for (let e = this; ; ) {
      let { index: n, offset: i } = e.content.findIndex(t);
      if (e = e.maybeChild(n), !e)
        return null;
      if (i == t || e.isText)
        return e;
      t -= i + 1;
    }
  }
  /**
  Find the (direct) child node after the given offset, if any,
  and return it along with its index and offset relative to this
  node.
  */
  childAfter(t) {
    let { index: e, offset: n } = this.content.findIndex(t);
    return { node: this.content.maybeChild(e), index: e, offset: n };
  }
  /**
  Find the (direct) child node before the given offset, if any,
  and return it along with its index and offset relative to this
  node.
  */
  childBefore(t) {
    if (t == 0)
      return { node: null, index: 0, offset: 0 };
    let { index: e, offset: n } = this.content.findIndex(t);
    if (n < t)
      return { node: this.content.child(e), index: e, offset: n };
    let i = this.content.child(e - 1);
    return { node: i, index: e - 1, offset: n - i.nodeSize };
  }
  /**
  Resolve the given position in the document, returning an
  [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.
  */
  resolve(t) {
    return E.resolveCached(this, t);
  }
  /**
  @internal
  */
  resolveNoCache(t) {
    return E.resolve(this, t);
  }
  /**
  Test whether a given mark or mark type occurs in this document
  between the two given positions.
  */
  rangeHasMark(t, e, n) {
    let i = !1;
    return e > t && this.nodesBetween(t, e, (r) => (n.isInSet(r.marks) && (i = !0), !i)), i;
  }
  /**
  True when this is a block (non-inline node)
  */
  get isBlock() {
    return this.type.isBlock;
  }
  /**
  True when this is a textblock node, a block node with inline
  content.
  */
  get isTextblock() {
    return this.type.isTextblock;
  }
  /**
  True when this node allows inline content.
  */
  get inlineContent() {
    return this.type.inlineContent;
  }
  /**
  True when this is an inline node (a text node or a node that can
  appear among text).
  */
  get isInline() {
    return this.type.isInline;
  }
  /**
  True when this is a text node.
  */
  get isText() {
    return this.type.isText;
  }
  /**
  True when this is a leaf node.
  */
  get isLeaf() {
    return this.type.isLeaf;
  }
  /**
  True when this is an atom, i.e. when it does not have directly
  editable content. This is usually the same as `isLeaf`, but can
  be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)
  on a node's spec (typically used when the node is displayed as
  an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).
  */
  get isAtom() {
    return this.type.isAtom;
  }
  /**
  Return a string representation of this node for debugging
  purposes.
  */
  toString() {
    if (this.type.spec.toDebugString)
      return this.type.spec.toDebugString(this);
    let t = this.type.name;
    return this.content.size && (t += "(" + this.content.toStringInner() + ")"), it(this.marks, t);
  }
  /**
  Get the content match in this node at the given index.
  */
  contentMatchAt(t) {
    let e = this.type.contentMatch.matchFragment(this.content, 0, t);
    if (!e)
      throw new Error("Called contentMatchAt on a node with invalid content");
    return e;
  }
  /**
  Test whether replacing the range between `from` and `to` (by
  child index) with the given replacement fragment (which defaults
  to the empty fragment) would leave the node's content valid. You
  can optionally pass `start` and `end` indices into the
  replacement fragment.
  */
  canReplace(t, e, n = c.empty, i = 0, r = n.childCount) {
    let s = this.contentMatchAt(t).matchFragment(n, i, r), o = s && s.matchFragment(this.content, e);
    if (!o || !o.validEnd)
      return !1;
    for (let h = i; h < r; h++)
      if (!this.type.allowsMarks(n.child(h).marks))
        return !1;
    return !0;
  }
  /**
  Test whether replacing the range `from` to `to` (by index) with
  a node of the given type would leave the node's content valid.
  */
  canReplaceWith(t, e, n, i) {
    if (i && !this.type.allowsMarks(i))
      return !1;
    let r = this.contentMatchAt(t).matchType(n), s = r && r.matchFragment(this.content, e);
    return s ? s.validEnd : !1;
  }
  /**
  Test whether the given node's content could be appended to this
  node. If that node is empty, this will only return true if there
  is at least one node type that can appear in both nodes (to avoid
  merging completely incompatible nodes).
  */
  canAppend(t) {
    return t.content.size ? this.canReplace(this.childCount, this.childCount, t.content) : this.type.compatibleContent(t.type);
  }
  /**
  Check whether this node and its descendants conform to the
  schema, and raise an exception when they do not.
  */
  check() {
    this.type.checkContent(this.content), this.type.checkAttrs(this.attrs);
    let t = u.none;
    for (let e = 0; e < this.marks.length; e++) {
      let n = this.marks[e];
      n.type.checkAttrs(n.attrs), t = n.addToSet(t);
    }
    if (!u.sameSet(t, this.marks))
      throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((e) => e.type.name)}`);
    this.content.forEach((e) => e.check());
  }
  /**
  Return a JSON-serializeable representation of this node.
  */
  toJSON() {
    let t = { type: this.type.name };
    for (let e in this.attrs) {
      t.attrs = this.attrs;
      break;
    }
    return this.content.size && (t.content = this.content.toJSON()), this.marks.length && (t.marks = this.marks.map((e) => e.toJSON())), t;
  }
  /**
  Deserialize a node from its JSON representation.
  */
  static fromJSON(t, e) {
    if (!e)
      throw new RangeError("Invalid input for Node.fromJSON");
    let n;
    if (e.marks) {
      if (!Array.isArray(e.marks))
        throw new RangeError("Invalid mark data for Node.fromJSON");
      n = e.marks.map(t.markFromJSON);
    }
    if (e.type == "text") {
      if (typeof e.text != "string")
        throw new RangeError("Invalid text node in JSON");
      return t.text(e.text, n);
    }
    let i = c.fromJSON(t, e.content), r = t.nodeType(e.type).create(e.attrs, i, n);
    return r.type.checkAttrs(r.attrs), r;
  }
}
y.prototype.text = void 0;
class N extends y {
  /**
  @internal
  */
  constructor(t, e, n, i) {
    if (super(t, e, null, i), !n)
      throw new RangeError("Empty text nodes are not allowed");
    this.text = n;
  }
  toString() {
    return this.type.spec.toDebugString ? this.type.spec.toDebugString(this) : it(this.marks, JSON.stringify(this.text));
  }
  get textContent() {
    return this.text;
  }
  textBetween(t, e) {
    return this.text.slice(t, e);
  }
  get nodeSize() {
    return this.text.length;
  }
  mark(t) {
    return t == this.marks ? this : new N(this.type, this.attrs, this.text, t);
  }
  withText(t) {
    return t == this.text ? this : new N(this.type, this.attrs, t, this.marks);
  }
  cut(t = 0, e = this.text.length) {
    return t == 0 && e == this.text.length ? this : this.withText(this.text.slice(t, e));
  }
  eq(t) {
    return this.sameMarkup(t) && this.text == t.text;
  }
  toJSON() {
    let t = super.toJSON();
    return t.text = this.text, t;
  }
}
function it(l, t) {
  for (let e = l.length - 1; e >= 0; e--)
    t = l[e].type.name + "(" + t + ")";
  return t;
}
class w {
  /**
  @internal
  */
  constructor(t) {
    this.validEnd = t, this.next = [], this.wrapCache = [];
  }
  /**
  @internal
  */
  static parse(t, e) {
    let n = new kt(t, e);
    if (n.next == null)
      return w.empty;
    let i = rt(n);
    n.next && n.err("Unexpected trailing text");
    let r = Mt(bt(i));
    return At(r, n), r;
  }
  /**
  Match a node type, returning a match after that node if
  successful.
  */
  matchType(t) {
    for (let e = 0; e < this.next.length; e++)
      if (this.next[e].type == t)
        return this.next[e].next;
    return null;
  }
  /**
  Try to match a fragment. Returns the resulting match when
  successful.
  */
  matchFragment(t, e = 0, n = t.childCount) {
    let i = this;
    for (let r = e; i && r < n; r++)
      i = i.matchType(t.child(r).type);
    return i;
  }
  /**
  @internal
  */
  get inlineContent() {
    return this.next.length != 0 && this.next[0].type.isInline;
  }
  /**
  Get the first matching node type at this match position that can
  be generated.
  */
  get defaultType() {
    for (let t = 0; t < this.next.length; t++) {
      let { type: e } = this.next[t];
      if (!(e.isText || e.hasRequiredAttrs()))
        return e;
    }
    return null;
  }
  /**
  @internal
  */
  compatible(t) {
    for (let e = 0; e < this.next.length; e++)
      for (let n = 0; n < t.next.length; n++)
        if (this.next[e].type == t.next[n].type)
          return !0;
    return !1;
  }
  /**
  Try to match the given fragment, and if that fails, see if it can
  be made to match by inserting nodes in front of it. When
  successful, return a fragment of inserted nodes (which may be
  empty if nothing had to be inserted). When `toEnd` is true, only
  return a fragment if the resulting match goes to the end of the
  content expression.
  */
  fillBefore(t, e = !1, n = 0) {
    let i = [this];
    function r(s, o) {
      let h = s.matchFragment(t, n);
      if (h && (!e || h.validEnd))
        return c.from(o.map((a) => a.createAndFill()));
      for (let a = 0; a < s.next.length; a++) {
        let { type: f, next: p } = s.next[a];
        if (!(f.isText || f.hasRequiredAttrs()) && i.indexOf(p) == -1) {
          i.push(p);
          let g = r(p, o.concat(f));
          if (g)
            return g;
        }
      }
      return null;
    }
    return r(this, []);
  }
  /**
  Find a set of wrapping node types that would allow a node of the
  given type to appear at this position. The result may be empty
  (when it fits directly) and will be null when no such wrapping
  exists.
  */
  findWrapping(t) {
    for (let n = 0; n < this.wrapCache.length; n += 2)
      if (this.wrapCache[n] == t)
        return this.wrapCache[n + 1];
    let e = this.computeWrapping(t);
    return this.wrapCache.push(t, e), e;
  }
  /**
  @internal
  */
  computeWrapping(t) {
    let e = /* @__PURE__ */ Object.create(null), n = [{ match: this, type: null, via: null }];
    for (; n.length; ) {
      let i = n.shift(), r = i.match;
      if (r.matchType(t)) {
        let s = [];
        for (let o = i; o.type; o = o.via)
          s.push(o.type);
        return s.reverse();
      }
      for (let s = 0; s < r.next.length; s++) {
        let { type: o, next: h } = r.next[s];
        !o.isLeaf && !o.hasRequiredAttrs() && !(o.name in e) && (!i.type || h.validEnd) && (n.push({ match: o.contentMatch, type: o, via: i }), e[o.name] = !0);
      }
    }
    return null;
  }
  /**
  The number of outgoing edges this node has in the finite
  automaton that describes the content expression.
  */
  get edgeCount() {
    return this.next.length;
  }
  /**
  Get the _n_​th outgoing edge from this node in the finite
  automaton that describes the content expression.
  */
  edge(t) {
    if (t >= this.next.length)
      throw new RangeError(`There's no ${t}th edge in this content match`);
    return this.next[t];
  }
  /**
  @internal
  */
  toString() {
    let t = [];
    function e(n) {
      t.push(n);
      for (let i = 0; i < n.next.length; i++)
        t.indexOf(n.next[i].next) == -1 && e(n.next[i].next);
    }
    return e(this), t.map((n, i) => {
      let r = i + (n.validEnd ? "*" : " ") + " ";
      for (let s = 0; s < n.next.length; s++)
        r += (s ? ", " : "") + n.next[s].type.name + "->" + t.indexOf(n.next[s].next);
      return r;
    }).join(`
`);
  }
}
w.empty = new w(!0);
class kt {
  constructor(t, e) {
    this.string = t, this.nodeTypes = e, this.inline = null, this.pos = 0, this.tokens = t.split(/\s*(?=\b|\W|$)/), this.tokens[this.tokens.length - 1] == "" && this.tokens.pop(), this.tokens[0] == "" && this.tokens.shift();
  }
  get next() {
    return this.tokens[this.pos];
  }
  eat(t) {
    return this.next == t && (this.pos++ || !0);
  }
  err(t) {
    throw new SyntaxError(t + " (in content expression '" + this.string + "')");
  }
}
function rt(l) {
  let t = [];
  do
    t.push(St(l));
  while (l.eat("|"));
  return t.length == 1 ? t[0] : { type: "choice", exprs: t };
}
function St(l) {
  let t = [];
  do
    t.push(Et(l));
  while (l.next && l.next != ")" && l.next != "|");
  return t.length == 1 ? t[0] : { type: "seq", exprs: t };
}
function Et(l) {
  let t = Tt(l);
  for (; ; )
    if (l.eat("+"))
      t = { type: "plus", expr: t };
    else if (l.eat("*"))
      t = { type: "star", expr: t };
    else if (l.eat("?"))
      t = { type: "opt", expr: t };
    else if (l.eat("{"))
      t = Ct(l, t);
    else
      break;
  return t;
}
function W(l) {
  /\D/.test(l.next) && l.err("Expected number, got '" + l.next + "'");
  let t = Number(l.next);
  return l.pos++, t;
}
function Ct(l, t) {
  let e = W(l), n = e;
  return l.eat(",") && (l.next != "}" ? n = W(l) : n = -1), l.eat("}") || l.err("Unclosed braced range"), { type: "range", min: e, max: n, expr: t };
}
function Ot(l, t) {
  let e = l.nodeTypes, n = e[t];
  if (n)
    return [n];
  let i = [];
  for (let r in e) {
    let s = e[r];
    s.isInGroup(t) && i.push(s);
  }
  return i.length == 0 && l.err("No node type or group '" + t + "' found"), i;
}
function Tt(l) {
  if (l.eat("(")) {
    let t = rt(l);
    return l.eat(")") || l.err("Missing closing paren"), t;
  } else if (/\W/.test(l.next))
    l.err("Unexpected token '" + l.next + "'");
  else {
    let t = Ot(l, l.next).map((e) => (l.inline == null ? l.inline = e.isInline : l.inline != e.isInline && l.err("Mixing inline and block content"), { type: "name", value: e }));
    return l.pos++, t.length == 1 ? t[0] : { type: "choice", exprs: t };
  }
}
function bt(l) {
  let t = [[]];
  return i(r(l, 0), e()), t;
  function e() {
    return t.push([]) - 1;
  }
  function n(s, o, h) {
    let a = { term: h, to: o };
    return t[s].push(a), a;
  }
  function i(s, o) {
    s.forEach((h) => h.to = o);
  }
  function r(s, o) {
    if (s.type == "choice")
      return s.exprs.reduce((h, a) => h.concat(r(a, o)), []);
    if (s.type == "seq")
      for (let h = 0; ; h++) {
        let a = r(s.exprs[h], o);
        if (h == s.exprs.length - 1)
          return a;
        i(a, o = e());
      }
    else if (s.type == "star") {
      let h = e();
      return n(o, h), i(r(s.expr, h), h), [n(h)];
    } else if (s.type == "plus") {
      let h = e();
      return i(r(s.expr, o), h), i(r(s.expr, h), h), [n(h)];
    } else {
      if (s.type == "opt")
        return [n(o)].concat(r(s.expr, o));
      if (s.type == "range") {
        let h = o;
        for (let a = 0; a < s.min; a++) {
          let f = e();
          i(r(s.expr, h), f), h = f;
        }
        if (s.max == -1)
          i(r(s.expr, h), h);
        else
          for (let a = s.min; a < s.max; a++) {
            let f = e();
            n(h, f), i(r(s.expr, h), f), h = f;
          }
        return [n(h)];
      } else {
        if (s.type == "name")
          return [n(o, void 0, s.value)];
        throw new Error("Unknown expr type");
      }
    }
  }
}
function st(l, t) {
  return t - l;
}
function j(l, t) {
  let e = [];
  return n(t), e.sort(st);
  function n(i) {
    let r = l[i];
    if (r.length == 1 && !r[0].term)
      return n(r[0].to);
    e.push(i);
    for (let s = 0; s < r.length; s++) {
      let { term: o, to: h } = r[s];
      !o && e.indexOf(h) == -1 && n(h);
    }
  }
}
function Mt(l) {
  let t = /* @__PURE__ */ Object.create(null);
  return e(j(l, 0));
  function e(n) {
    let i = [];
    n.forEach((s) => {
      l[s].forEach(({ term: o, to: h }) => {
        if (!o)
          return;
        let a;
        for (let f = 0; f < i.length; f++)
          i[f][0] == o && (a = i[f][1]);
        j(l, h).forEach((f) => {
          a || i.push([o, a = []]), a.indexOf(f) == -1 && a.push(f);
        });
      });
    });
    let r = t[n.join(",")] = new w(n.indexOf(l.length - 1) > -1);
    for (let s = 0; s < i.length; s++) {
      let o = i[s][1].sort(st);
      r.next.push({ type: i[s][0], next: t[o.join(",")] || e(o) });
    }
    return r;
  }
}
function At(l, t) {
  for (let e = 0, n = [l]; e < n.length; e++) {
    let i = n[e], r = !i.validEnd, s = [];
    for (let o = 0; o < i.next.length; o++) {
      let { type: h, next: a } = i.next[o];
      s.push(h.name), r && !(h.isText || h.hasRequiredAttrs()) && (r = !1), n.indexOf(a) == -1 && n.push(a);
    }
    r && t.err("Only non-generatable nodes (" + s.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
  }
}
function lt(l) {
  let t = /* @__PURE__ */ Object.create(null);
  for (let e in l) {
    let n = l[e];
    if (!n.hasDefault)
      return null;
    t[e] = n.default;
  }
  return t;
}
function ot(l, t) {
  let e = /* @__PURE__ */ Object.create(null);
  for (let n in l) {
    let i = t && t[n];
    if (i === void 0) {
      let r = l[n];
      if (r.hasDefault)
        i = r.default;
      else
        throw new RangeError("No value supplied for attribute " + n);
    }
    e[n] = i;
  }
  return e;
}
function ht(l, t, e, n) {
  for (let i in t)
    if (!(i in l))
      throw new RangeError(`Unsupported attribute ${i} for ${e} of type ${i}`);
  for (let i in l) {
    let r = l[i];
    r.validate && r.validate(t[i]);
  }
}
function at(l, t) {
  let e = /* @__PURE__ */ Object.create(null);
  if (t)
    for (let n in t)
      e[n] = new zt(l, n, t[n]);
  return e;
}
class z {
  /**
  @internal
  */
  constructor(t, e, n) {
    this.name = t, this.schema = e, this.spec = n, this.markSet = null, this.groups = n.group ? n.group.split(" ") : [], this.attrs = at(t, n.attrs), this.defaultAttrs = lt(this.attrs), this.contentMatch = null, this.inlineContent = null, this.isBlock = !(n.inline || t == "text"), this.isText = t == "text";
  }
  /**
  True if this is an inline type.
  */
  get isInline() {
    return !this.isBlock;
  }
  /**
  True if this is a textblock type, a block that contains inline
  content.
  */
  get isTextblock() {
    return this.isBlock && this.inlineContent;
  }
  /**
  True for node types that allow no content.
  */
  get isLeaf() {
    return this.contentMatch == w.empty;
  }
  /**
  True when this node is an atom, i.e. when it does not have
  directly editable content.
  */
  get isAtom() {
    return this.isLeaf || !!this.spec.atom;
  }
  /**
  Return true when this node type is part of the given
  [group](https://prosemirror.net/docs/ref/#model.NodeSpec.group).
  */
  isInGroup(t) {
    return this.groups.indexOf(t) > -1;
  }
  /**
  The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.
  */
  get whitespace() {
    return this.spec.whitespace || (this.spec.code ? "pre" : "normal");
  }
  /**
  Tells you whether this node type has any required attributes.
  */
  hasRequiredAttrs() {
    for (let t in this.attrs)
      if (this.attrs[t].isRequired)
        return !0;
    return !1;
  }
  /**
  Indicates whether this node allows some of the same content as
  the given node type.
  */
  compatibleContent(t) {
    return this == t || this.contentMatch.compatible(t.contentMatch);
  }
  /**
  @internal
  */
  computeAttrs(t) {
    return !t && this.defaultAttrs ? this.defaultAttrs : ot(this.attrs, t);
  }
  /**
  Create a `Node` of this type. The given attributes are
  checked and defaulted (you can pass `null` to use the type's
  defaults entirely, if no required attributes exist). `content`
  may be a `Fragment`, a node, an array of nodes, or
  `null`. Similarly `marks` may be `null` to default to the empty
  set of marks.
  */
  create(t = null, e, n) {
    if (this.isText)
      throw new Error("NodeType.create can't construct text nodes");
    return new y(this, this.computeAttrs(t), c.from(e), u.setFrom(n));
  }
  /**
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
  against the node type's content restrictions, and throw an error
  if it doesn't match.
  */
  createChecked(t = null, e, n) {
    return e = c.from(e), this.checkContent(e), new y(this, this.computeAttrs(t), e, u.setFrom(n));
  }
  /**
  Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
  necessary to add nodes to the start or end of the given fragment
  to make it fit the node. If no fitting wrapping can be found,
  return null. Note that, due to the fact that required nodes can
  always be created, this will always succeed if you pass null or
  `Fragment.empty` as content.
  */
  createAndFill(t = null, e, n) {
    if (t = this.computeAttrs(t), e = c.from(e), e.size) {
      let s = this.contentMatch.fillBefore(e);
      if (!s)
        return null;
      e = s.append(e);
    }
    let i = this.contentMatch.matchFragment(e), r = i && i.fillBefore(c.empty, !0);
    return r ? new y(this, t, e.append(r), u.setFrom(n)) : null;
  }
  /**
  Returns true if the given fragment is valid content for this node
  type.
  */
  validContent(t) {
    let e = this.contentMatch.matchFragment(t);
    if (!e || !e.validEnd)
      return !1;
    for (let n = 0; n < t.childCount; n++)
      if (!this.allowsMarks(t.child(n).marks))
        return !1;
    return !0;
  }
  /**
  Throws a RangeError if the given fragment is not valid content for this
  node type.
  @internal
  */
  checkContent(t) {
    if (!this.validContent(t))
      throw new RangeError(`Invalid content for node ${this.name}: ${t.toString().slice(0, 50)}`);
  }
  /**
  @internal
  */
  checkAttrs(t) {
    ht(this.attrs, t, "node", this.name);
  }
  /**
  Check whether the given mark type is allowed in this node.
  */
  allowsMarkType(t) {
    return this.markSet == null || this.markSet.indexOf(t) > -1;
  }
  /**
  Test whether the given set of marks are allowed in this node.
  */
  allowsMarks(t) {
    if (this.markSet == null)
      return !0;
    for (let e = 0; e < t.length; e++)
      if (!this.allowsMarkType(t[e].type))
        return !1;
    return !0;
  }
  /**
  Removes the marks that are not allowed in this node from the given set.
  */
  allowedMarks(t) {
    if (this.markSet == null)
      return t;
    let e;
    for (let n = 0; n < t.length; n++)
      this.allowsMarkType(t[n].type) ? e && e.push(t[n]) : e || (e = t.slice(0, n));
    return e ? e.length ? e : u.none : t;
  }
  /**
  @internal
  */
  static compile(t, e) {
    let n = /* @__PURE__ */ Object.create(null);
    t.forEach((r, s) => n[r] = new z(r, e, s));
    let i = e.spec.topNode || "doc";
    if (!n[i])
      throw new RangeError("Schema is missing its top node type ('" + i + "')");
    if (!n.text)
      throw new RangeError("Every schema needs a 'text' type");
    for (let r in n.text.attrs)
      throw new RangeError("The text node type should not have attributes");
    return n;
  }
}
function Nt(l, t, e) {
  let n = e.split("|");
  return (i) => {
    let r = i === null ? "null" : typeof i;
    if (n.indexOf(r) < 0)
      throw new RangeError(`Expected value of type ${n} for attribute ${t} on type ${l}, got ${r}`);
  };
}
class zt {
  constructor(t, e, n) {
    this.hasDefault = Object.prototype.hasOwnProperty.call(n, "default"), this.default = n.default, this.validate = typeof n.validate == "string" ? Nt(t, e, n.validate) : n.validate;
  }
  get isRequired() {
    return !this.hasDefault;
  }
}
class F {
  /**
  @internal
  */
  constructor(t, e, n, i) {
    this.name = t, this.rank = e, this.schema = n, this.spec = i, this.attrs = at(t, i.attrs), this.excluded = null;
    let r = lt(this.attrs);
    this.instance = r ? new u(this, r) : null;
  }
  /**
  Create a mark of this type. `attrs` may be `null` or an object
  containing only some of the mark's attributes. The others, if
  they have defaults, will be added.
  */
  create(t = null) {
    return !t && this.instance ? this.instance : new u(this, ot(this.attrs, t));
  }
  /**
  @internal
  */
  static compile(t, e) {
    let n = /* @__PURE__ */ Object.create(null), i = 0;
    return t.forEach((r, s) => n[r] = new F(r, i++, e, s)), n;
  }
  /**
  When there is a mark of this type in the given set, a new set
  without it is returned. Otherwise, the input set is returned.
  */
  removeFromSet(t) {
    for (var e = 0; e < t.length; e++)
      t[e].type == this && (t = t.slice(0, e).concat(t.slice(e + 1)), e--);
    return t;
  }
  /**
  Tests whether there is a mark of this type in the given set.
  */
  isInSet(t) {
    for (let e = 0; e < t.length; e++)
      if (t[e].type == this)
        return t[e];
  }
  /**
  @internal
  */
  checkAttrs(t) {
    ht(this.attrs, t, "mark", this.name);
  }
  /**
  Queries whether a given mark type is
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
  */
  excludes(t) {
    return this.excluded.indexOf(t) > -1;
  }
}
class qt {
  /**
  Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
  */
  constructor(t) {
    this.linebreakReplacement = null, this.cached = /* @__PURE__ */ Object.create(null);
    let e = this.spec = {};
    for (let i in t)
      e[i] = t[i];
    e.nodes = q.from(t.nodes), e.marks = q.from(t.marks || {}), this.nodes = z.compile(this.spec.nodes, this), this.marks = F.compile(this.spec.marks, this);
    let n = /* @__PURE__ */ Object.create(null);
    for (let i in this.nodes) {
      if (i in this.marks)
        throw new RangeError(i + " can not be both a node and a mark");
      let r = this.nodes[i], s = r.spec.content || "", o = r.spec.marks;
      if (r.contentMatch = n[s] || (n[s] = w.parse(s, this.nodes)), r.inlineContent = r.contentMatch.inlineContent, r.spec.linebreakReplacement) {
        if (this.linebreakReplacement)
          throw new RangeError("Multiple linebreak nodes defined");
        if (!r.isInline || !r.isLeaf)
          throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");
        this.linebreakReplacement = r;
      }
      r.markSet = o == "_" ? null : o ? U(this, o.split(" ")) : o == "" || !r.inlineContent ? [] : null;
    }
    for (let i in this.marks) {
      let r = this.marks[i], s = r.spec.excludes;
      r.excluded = s == null ? [r] : s == "" ? [] : U(this, s.split(" "));
    }
    this.nodeFromJSON = this.nodeFromJSON.bind(this), this.markFromJSON = this.markFromJSON.bind(this), this.topNodeType = this.nodes[this.spec.topNode || "doc"], this.cached.wrappings = /* @__PURE__ */ Object.create(null);
  }
  /**
  Create a node in this schema. The `type` may be a string or a
  `NodeType` instance. Attributes will be extended with defaults,
  `content` may be a `Fragment`, `null`, a `Node`, or an array of
  nodes.
  */
  node(t, e = null, n, i) {
    if (typeof t == "string")
      t = this.nodeType(t);
    else if (t instanceof z) {
      if (t.schema != this)
        throw new RangeError("Node type from different schema used (" + t.name + ")");
    } else throw new RangeError("Invalid node type: " + t);
    return t.createChecked(e, n, i);
  }
  /**
  Create a text node in the schema. Empty text nodes are not
  allowed.
  */
  text(t, e) {
    let n = this.nodes.text;
    return new N(n, n.defaultAttrs, t, u.setFrom(e));
  }
  /**
  Create a mark with the given type and attributes.
  */
  mark(t, e) {
    return typeof t == "string" && (t = this.marks[t]), t.create(e);
  }
  /**
  Deserialize a node from its JSON representation. This method is
  bound.
  */
  nodeFromJSON(t) {
    return y.fromJSON(this, t);
  }
  /**
  Deserialize a mark from its JSON representation. This method is
  bound.
  */
  markFromJSON(t) {
    return u.fromJSON(this, t);
  }
  /**
  @internal
  */
  nodeType(t) {
    let e = this.nodes[t];
    if (!e)
      throw new RangeError("Unknown node type: " + t);
    return e;
  }
}
function U(l, t) {
  let e = [];
  for (let n = 0; n < t.length; n++) {
    let i = t[n], r = l.marks[i], s = r;
    if (r)
      e.push(r);
    else
      for (let o in l.marks) {
        let h = l.marks[o];
        (i == "_" || h.spec.group && h.spec.group.split(" ").indexOf(i) > -1) && e.push(s = h);
      }
    if (!s)
      throw new SyntaxError("Unknown mark type: '" + t[n] + "'");
  }
  return e;
}
function vt(l) {
  return l.tag != null;
}
function Rt(l) {
  return l.style != null;
}
class P {
  /**
  Create a parser that targets the given schema, using the given
  parsing rules.
  */
  constructor(t, e) {
    this.schema = t, this.rules = e, this.tags = [], this.styles = [];
    let n = this.matchedStyles = [];
    e.forEach((i) => {
      if (vt(i))
        this.tags.push(i);
      else if (Rt(i)) {
        let r = /[^=]*/.exec(i.style)[0];
        n.indexOf(r) < 0 && n.push(r), this.styles.push(i);
      }
    }), this.normalizeLists = !this.tags.some((i) => {
      if (!/^(ul|ol)\b/.test(i.tag) || !i.node)
        return !1;
      let r = t.nodes[i.node];
      return r.contentMatch.matchType(r);
    });
  }
  /**
  Parse a document from the content of a DOM node.
  */
  parse(t, e = {}) {
    let n = new G(this, e, !1);
    return n.addAll(t, u.none, e.from, e.to), n.finish();
  }
  /**
  Parses the content of the given DOM node, like
  [`parse`](https://prosemirror.net/docs/ref/#model.DOMParser.parse), and takes the same set of
  options. But unlike that method, which produces a whole node,
  this one returns a slice that is open at the sides, meaning that
  the schema constraints aren't applied to the start of nodes to
  the left of the input and the end of nodes at the end.
  */
  parseSlice(t, e = {}) {
    let n = new G(this, e, !0);
    return n.addAll(t, u.none, e.from, e.to), d.maxOpen(n.finish());
  }
  /**
  @internal
  */
  matchTag(t, e, n) {
    for (let i = n ? this.tags.indexOf(n) + 1 : 0; i < this.tags.length; i++) {
      let r = this.tags[i];
      if (Pt(t, r.tag) && (r.namespace === void 0 || t.namespaceURI == r.namespace) && (!r.context || e.matchesContext(r.context))) {
        if (r.getAttrs) {
          let s = r.getAttrs(t);
          if (s === !1)
            continue;
          r.attrs = s || void 0;
        }
        return r;
      }
    }
  }
  /**
  @internal
  */
  matchStyle(t, e, n, i) {
    for (let r = i ? this.styles.indexOf(i) + 1 : 0; r < this.styles.length; r++) {
      let s = this.styles[r], o = s.style;
      if (!(o.indexOf(t) != 0 || s.context && !n.matchesContext(s.context) || // Test that the style string either precisely matches the prop,
      // or has an '=' sign after the prop, followed by the given
      // value.
      o.length > t.length && (o.charCodeAt(t.length) != 61 || o.slice(t.length + 1) != e))) {
        if (s.getAttrs) {
          let h = s.getAttrs(e);
          if (h === !1)
            continue;
          s.attrs = h || void 0;
        }
        return s;
      }
    }
  }
  /**
  @internal
  */
  static schemaRules(t) {
    let e = [];
    function n(i) {
      let r = i.priority == null ? 50 : i.priority, s = 0;
      for (; s < e.length; s++) {
        let o = e[s];
        if ((o.priority == null ? 50 : o.priority) < r)
          break;
      }
      e.splice(s, 0, i);
    }
    for (let i in t.marks) {
      let r = t.marks[i].spec.parseDOM;
      r && r.forEach((s) => {
        n(s = H(s)), s.mark || s.ignore || s.clearMark || (s.mark = i);
      });
    }
    for (let i in t.nodes) {
      let r = t.nodes[i].spec.parseDOM;
      r && r.forEach((s) => {
        n(s = H(s)), s.node || s.ignore || s.mark || (s.node = i);
      });
    }
    return e;
  }
  /**
  Construct a DOM parser using the parsing rules listed in a
  schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by
  [priority](https://prosemirror.net/docs/ref/#model.ParseRule.priority).
  */
  static fromSchema(t) {
    return t.cached.domParser || (t.cached.domParser = new P(t, P.schemaRules(t)));
  }
}
const ft = {
  address: !0,
  article: !0,
  aside: !0,
  blockquote: !0,
  canvas: !0,
  dd: !0,
  div: !0,
  dl: !0,
  fieldset: !0,
  figcaption: !0,
  figure: !0,
  footer: !0,
  form: !0,
  h1: !0,
  h2: !0,
  h3: !0,
  h4: !0,
  h5: !0,
  h6: !0,
  header: !0,
  hgroup: !0,
  hr: !0,
  li: !0,
  noscript: !0,
  ol: !0,
  output: !0,
  p: !0,
  pre: !0,
  section: !0,
  table: !0,
  tfoot: !0,
  ul: !0
}, It = {
  head: !0,
  noscript: !0,
  object: !0,
  script: !0,
  style: !0,
  title: !0
}, ct = { ol: !0, ul: !0 }, C = 1, B = 2, S = 4;
function V(l, t, e) {
  return t != null ? (t ? C : 0) | (t === "full" ? B : 0) : l && l.whitespace == "pre" ? C | B : e & ~S;
}
class T {
  constructor(t, e, n, i, r, s) {
    this.type = t, this.attrs = e, this.marks = n, this.solid = i, this.options = s, this.content = [], this.activeMarks = u.none, this.match = r || (s & S ? null : t.contentMatch);
  }
  findWrapping(t) {
    if (!this.match) {
      if (!this.type)
        return [];
      let e = this.type.contentMatch.fillBefore(c.from(t));
      if (e)
        this.match = this.type.contentMatch.matchFragment(e);
      else {
        let n = this.type.contentMatch, i;
        return (i = n.findWrapping(t.type)) ? (this.match = n, i) : null;
      }
    }
    return this.match.findWrapping(t.type);
  }
  finish(t) {
    if (!(this.options & C)) {
      let n = this.content[this.content.length - 1], i;
      if (n && n.isText && (i = /[ \t\r\n\u000c]+$/.exec(n.text))) {
        let r = n;
        n.text.length == i[0].length ? this.content.pop() : this.content[this.content.length - 1] = r.withText(r.text.slice(0, r.text.length - i[0].length));
      }
    }
    let e = c.from(this.content);
    return !t && this.match && (e = e.append(this.match.fillBefore(c.empty, !0))), this.type ? this.type.create(this.attrs, e, this.marks) : e;
  }
  inlineContext(t) {
    return this.type ? this.type.inlineContent : this.content.length ? this.content[0].isInline : t.parentNode && !ft.hasOwnProperty(t.parentNode.nodeName.toLowerCase());
  }
}
class G {
  constructor(t, e, n) {
    this.parser = t, this.options = e, this.isOpen = n, this.open = 0, this.localPreserveWS = !1;
    let i = e.topNode, r, s = V(null, e.preserveWhitespace, 0) | (n ? S : 0);
    i ? r = new T(i.type, i.attrs, u.none, !0, e.topMatch || i.type.contentMatch, s) : n ? r = new T(null, null, u.none, !0, null, s) : r = new T(t.schema.topNodeType, null, u.none, !0, null, s), this.nodes = [r], this.find = e.findPositions, this.needsBlock = !1;
  }
  get top() {
    return this.nodes[this.open];
  }
  // Add a DOM node to the content. Text is inserted as text node,
  // otherwise, the node is passed to `addElement` or, if it has a
  // `style` attribute, `addElementWithStyles`.
  addDOM(t, e) {
    t.nodeType == 3 ? this.addTextNode(t, e) : t.nodeType == 1 && this.addElement(t, e);
  }
  addTextNode(t, e) {
    let n = t.nodeValue, i = this.top, r = i.options & B ? "full" : this.localPreserveWS || (i.options & C) > 0;
    if (r === "full" || i.inlineContext(t) || /[^ \t\r\n\u000c]/.test(n)) {
      if (r)
        r !== "full" ? n = n.replace(/\r?\n|\r/g, " ") : n = n.replace(/\r\n?/g, `
`);
      else if (n = n.replace(/[ \t\r\n\u000c]+/g, " "), /^[ \t\r\n\u000c]/.test(n) && this.open == this.nodes.length - 1) {
        let s = i.content[i.content.length - 1], o = t.previousSibling;
        (!s || o && o.nodeName == "BR" || s.isText && /[ \t\r\n\u000c]$/.test(s.text)) && (n = n.slice(1));
      }
      n && this.insertNode(this.parser.schema.text(n), e, !/\S/.test(n)), this.findInText(t);
    } else
      this.findInside(t);
  }
  // Try to find a handler for the given tag and use that to parse. If
  // none is found, the element's content nodes are added directly.
  addElement(t, e, n) {
    let i = this.localPreserveWS, r = this.top;
    (t.tagName == "PRE" || /pre/.test(t.style && t.style.whiteSpace)) && (this.localPreserveWS = !0);
    let s = t.nodeName.toLowerCase(), o;
    ct.hasOwnProperty(s) && this.parser.normalizeLists && Dt(t);
    let h = this.options.ruleFromNode && this.options.ruleFromNode(t) || (o = this.parser.matchTag(t, this, n));
    t: if (h ? h.ignore : It.hasOwnProperty(s))
      this.findInside(t), this.ignoreFallback(t, e);
    else if (!h || h.skip || h.closeParent) {
      h && h.closeParent ? this.open = Math.max(0, this.open - 1) : h && h.skip.nodeType && (t = h.skip);
      let a, f = this.needsBlock;
      if (ft.hasOwnProperty(s))
        r.content.length && r.content[0].isInline && this.open && (this.open--, r = this.top), a = !0, r.type || (this.needsBlock = !0);
      else if (!t.firstChild) {
        this.leafFallback(t, e);
        break t;
      }
      let p = h && h.skip ? e : this.readStyles(t, e);
      p && this.addAll(t, p), a && this.sync(r), this.needsBlock = f;
    } else {
      let a = this.readStyles(t, e);
      a && this.addElementByRule(t, h, a, h.consuming === !1 ? o : void 0);
    }
    this.localPreserveWS = i;
  }
  // Called for leaf DOM nodes that would otherwise be ignored
  leafFallback(t, e) {
    t.nodeName == "BR" && this.top.type && this.top.type.inlineContent && this.addTextNode(t.ownerDocument.createTextNode(`
`), e);
  }
  // Called for ignored nodes
  ignoreFallback(t, e) {
    t.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent) && this.findPlace(this.parser.schema.text("-"), e, !0);
  }
  // Run any style parser associated with the node's styles. Either
  // return an updated array of marks, or null to indicate some of the
  // styles had a rule with `ignore` set.
  readStyles(t, e) {
    let n = t.style;
    if (n && n.length)
      for (let i = 0; i < this.parser.matchedStyles.length; i++) {
        let r = this.parser.matchedStyles[i], s = n.getPropertyValue(r);
        if (s)
          for (let o = void 0; ; ) {
            let h = this.parser.matchStyle(r, s, this, o);
            if (!h)
              break;
            if (h.ignore)
              return null;
            if (h.clearMark ? e = e.filter((a) => !h.clearMark(a)) : e = e.concat(this.parser.schema.marks[h.mark].create(h.attrs)), h.consuming === !1)
              o = h;
            else
              break;
          }
      }
    return e;
  }
  // Look up a handler for the given node. If none are found, return
  // false. Otherwise, apply it, use its return value to drive the way
  // the node's content is wrapped, and return true.
  addElementByRule(t, e, n, i) {
    let r, s;
    if (e.node)
      if (s = this.parser.schema.nodes[e.node], s.isLeaf)
        this.insertNode(s.create(e.attrs), n, t.nodeName == "BR") || this.leafFallback(t, n);
      else {
        let h = this.enter(s, e.attrs || null, n, e.preserveWhitespace);
        h && (r = !0, n = h);
      }
    else {
      let h = this.parser.schema.marks[e.mark];
      n = n.concat(h.create(e.attrs));
    }
    let o = this.top;
    if (s && s.isLeaf)
      this.findInside(t);
    else if (i)
      this.addElement(t, n, i);
    else if (e.getContent)
      this.findInside(t), e.getContent(t, this.parser.schema).forEach((h) => this.insertNode(h, n, !1));
    else {
      let h = t;
      typeof e.contentElement == "string" ? h = t.querySelector(e.contentElement) : typeof e.contentElement == "function" ? h = e.contentElement(t) : e.contentElement && (h = e.contentElement), this.findAround(t, h, !0), this.addAll(h, n), this.findAround(t, h, !1);
    }
    r && this.sync(o) && this.open--;
  }
  // Add all child nodes between `startIndex` and `endIndex` (or the
  // whole node, if not given). If `sync` is passed, use it to
  // synchronize after every block element.
  addAll(t, e, n, i) {
    let r = n || 0;
    for (let s = n ? t.childNodes[n] : t.firstChild, o = i == null ? null : t.childNodes[i]; s != o; s = s.nextSibling, ++r)
      this.findAtPoint(t, r), this.addDOM(s, e);
    this.findAtPoint(t, r);
  }
  // Try to find a way to fit the given node type into the current
  // context. May add intermediate wrappers and/or leave non-solid
  // nodes that we're in.
  findPlace(t, e, n) {
    let i, r;
    for (let s = this.open, o = 0; s >= 0; s--) {
      let h = this.nodes[s], a = h.findWrapping(t);
      if (a && (!i || i.length > a.length + o) && (i = a, r = h, !a.length))
        break;
      if (h.solid) {
        if (n)
          break;
        o += 2;
      }
    }
    if (!i)
      return null;
    this.sync(r);
    for (let s = 0; s < i.length; s++)
      e = this.enterInner(i[s], null, e, !1);
    return e;
  }
  // Try to insert the given node, adjusting the context when needed.
  insertNode(t, e, n) {
    if (t.isInline && this.needsBlock && !this.top.type) {
      let r = this.textblockFromContext();
      r && (e = this.enterInner(r, null, e));
    }
    let i = this.findPlace(t, e, n);
    if (i) {
      this.closeExtra();
      let r = this.top;
      r.match && (r.match = r.match.matchType(t.type));
      let s = u.none;
      for (let o of i.concat(t.marks))
        (r.type ? r.type.allowsMarkType(o.type) : K(o.type, t.type)) && (s = o.addToSet(s));
      return r.content.push(t.mark(s)), !0;
    }
    return !1;
  }
  // Try to start a node of the given type, adjusting the context when
  // necessary.
  enter(t, e, n, i) {
    let r = this.findPlace(t.create(e), n, !1);
    return r && (r = this.enterInner(t, e, n, !0, i)), r;
  }
  // Open a node of the given type
  enterInner(t, e, n, i = !1, r) {
    this.closeExtra();
    let s = this.top;
    s.match = s.match && s.match.matchType(t);
    let o = V(t, r, s.options);
    s.options & S && s.content.length == 0 && (o |= S);
    let h = u.none;
    return n = n.filter((a) => (s.type ? s.type.allowsMarkType(a.type) : K(a.type, t)) ? (h = a.addToSet(h), !1) : !0), this.nodes.push(new T(t, e, h, i, null, o)), this.open++, n;
  }
  // Make sure all nodes above this.open are finished and added to
  // their parents
  closeExtra(t = !1) {
    let e = this.nodes.length - 1;
    if (e > this.open) {
      for (; e > this.open; e--)
        this.nodes[e - 1].content.push(this.nodes[e].finish(t));
      this.nodes.length = this.open + 1;
    }
  }
  finish() {
    return this.open = 0, this.closeExtra(this.isOpen), this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));
  }
  sync(t) {
    for (let e = this.open; e >= 0; e--) {
      if (this.nodes[e] == t)
        return this.open = e, !0;
      this.localPreserveWS && (this.nodes[e].options |= C);
    }
    return !1;
  }
  get currentPos() {
    this.closeExtra();
    let t = 0;
    for (let e = this.open; e >= 0; e--) {
      let n = this.nodes[e].content;
      for (let i = n.length - 1; i >= 0; i--)
        t += n[i].nodeSize;
      e && t++;
    }
    return t;
  }
  findAtPoint(t, e) {
    if (this.find)
      for (let n = 0; n < this.find.length; n++)
        this.find[n].node == t && this.find[n].offset == e && (this.find[n].pos = this.currentPos);
  }
  findInside(t) {
    if (this.find)
      for (let e = 0; e < this.find.length; e++)
        this.find[e].pos == null && t.nodeType == 1 && t.contains(this.find[e].node) && (this.find[e].pos = this.currentPos);
  }
  findAround(t, e, n) {
    if (t != e && this.find)
      for (let i = 0; i < this.find.length; i++)
        this.find[i].pos == null && t.nodeType == 1 && t.contains(this.find[i].node) && e.compareDocumentPosition(this.find[i].node) & (n ? 2 : 4) && (this.find[i].pos = this.currentPos);
  }
  findInText(t) {
    if (this.find)
      for (let e = 0; e < this.find.length; e++)
        this.find[e].node == t && (this.find[e].pos = this.currentPos - (t.nodeValue.length - this.find[e].offset));
  }
  // Determines whether the given context string matches this context.
  matchesContext(t) {
    if (t.indexOf("|") > -1)
      return t.split(/\s*\|\s*/).some(this.matchesContext, this);
    let e = t.split("/"), n = this.options.context, i = !this.isOpen && (!n || n.parent.type == this.nodes[0].type), r = -(n ? n.depth + 1 : 0) + (i ? 0 : 1), s = (o, h) => {
      for (; o >= 0; o--) {
        let a = e[o];
        if (a == "") {
          if (o == e.length - 1 || o == 0)
            continue;
          for (; h >= r; h--)
            if (s(o - 1, h))
              return !0;
          return !1;
        } else {
          let f = h > 0 || h == 0 && i ? this.nodes[h].type : n && h >= r ? n.node(h - r).type : null;
          if (!f || f.name != a && !f.isInGroup(a))
            return !1;
          h--;
        }
      }
      return !0;
    };
    return s(e.length - 1, this.open);
  }
  textblockFromContext() {
    let t = this.options.context;
    if (t)
      for (let e = t.depth; e >= 0; e--) {
        let n = t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;
        if (n && n.isTextblock && n.defaultAttrs)
          return n;
      }
    for (let e in this.parser.schema.nodes) {
      let n = this.parser.schema.nodes[e];
      if (n.isTextblock && n.defaultAttrs)
        return n;
    }
  }
}
function Dt(l) {
  for (let t = l.firstChild, e = null; t; t = t.nextSibling) {
    let n = t.nodeType == 1 ? t.nodeName.toLowerCase() : null;
    n && ct.hasOwnProperty(n) && e ? (e.appendChild(t), t = e) : n == "li" ? e = t : n && (e = null);
  }
}
function Pt(l, t) {
  return (l.matches || l.msMatchesSelector || l.webkitMatchesSelector || l.mozMatchesSelector).call(l, t);
}
function H(l) {
  let t = {};
  for (let e in l)
    t[e] = l[e];
  return t;
}
function K(l, t) {
  let e = t.schema.nodes;
  for (let n in e) {
    let i = e[n];
    if (!i.allowsMarkType(l))
      continue;
    let r = [], s = (o) => {
      r.push(o);
      for (let h = 0; h < o.edgeCount; h++) {
        let { type: a, next: f } = o.edge(h);
        if (a == t || r.indexOf(f) < 0 && s(f))
          return !0;
      }
    };
    if (s(i.contentMatch))
      return !0;
  }
}
class ut {
  /**
  Create a serializer. `nodes` should map node names to functions
  that take a node and return a description of the corresponding
  DOM. `marks` does the same for mark names, but also gets an
  argument that tells it whether the mark's content is block or
  inline content (for typical use, it'll always be inline). A mark
  serializer may be `null` to indicate that marks of that type
  should not be serialized.
  */
  constructor(t, e) {
    this.nodes = t, this.marks = e;
  }
  /**
  Serialize the content of this fragment to a DOM fragment. When
  not in the browser, the `document` option, containing a DOM
  document, should be passed so that the serializer can create
  nodes.
  */
  serializeFragment(t, e = {}, n) {
    n || (n = R(e).createDocumentFragment());
    let i = n, r = [];
    return t.forEach((s) => {
      if (r.length || s.marks.length) {
        let o = 0, h = 0;
        for (; o < r.length && h < s.marks.length; ) {
          let a = s.marks[h];
          if (!this.marks[a.type.name]) {
            h++;
            continue;
          }
          if (!a.eq(r[o][0]) || a.type.spec.spanning === !1)
            break;
          o++, h++;
        }
        for (; o < r.length; )
          i = r.pop()[1];
        for (; h < s.marks.length; ) {
          let a = s.marks[h++], f = this.serializeMark(a, s.isInline, e);
          f && (r.push([a, i]), i.appendChild(f.dom), i = f.contentDOM || f.dom);
        }
      }
      i.appendChild(this.serializeNodeInner(s, e));
    }), n;
  }
  /**
  @internal
  */
  serializeNodeInner(t, e) {
    let { dom: n, contentDOM: i } = b(R(e), this.nodes[t.type.name](t), null, t.attrs);
    if (i) {
      if (t.isLeaf)
        throw new RangeError("Content hole not allowed in a leaf node spec");
      this.serializeFragment(t.content, e, i);
    }
    return n;
  }
  /**
  Serialize this node to a DOM node. This can be useful when you
  need to serialize a part of a document, as opposed to the whole
  document. To serialize a whole document, use
  [`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on
  its [content](https://prosemirror.net/docs/ref/#model.Node.content).
  */
  serializeNode(t, e = {}) {
    let n = this.serializeNodeInner(t, e);
    for (let i = t.marks.length - 1; i >= 0; i--) {
      let r = this.serializeMark(t.marks[i], t.isInline, e);
      r && ((r.contentDOM || r.dom).appendChild(n), n = r.dom);
    }
    return n;
  }
  /**
  @internal
  */
  serializeMark(t, e, n = {}) {
    let i = this.marks[t.type.name];
    return i && b(R(n), i(t, e), null, t.attrs);
  }
  static renderSpec(t, e, n = null, i) {
    return b(t, e, n, i);
  }
  /**
  Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)
  properties in a schema's node and mark specs.
  */
  static fromSchema(t) {
    return t.cached.domSerializer || (t.cached.domSerializer = new ut(this.nodesFromSchema(t), this.marksFromSchema(t)));
  }
  /**
  Gather the serializers in a schema's node specs into an object.
  This can be useful as a base to build a custom serializer from.
  */
  static nodesFromSchema(t) {
    let e = Q(t.nodes);
    return e.text || (e.text = (n) => n.text), e;
  }
  /**
  Gather the serializers in a schema's mark specs into an object.
  */
  static marksFromSchema(t) {
    return Q(t.marks);
  }
}
function Q(l) {
  let t = {};
  for (let e in l) {
    let n = l[e].spec.toDOM;
    n && (t[e] = n);
  }
  return t;
}
function R(l) {
  return l.document || window.document;
}
const X = /* @__PURE__ */ new WeakMap();
function Bt(l) {
  let t = X.get(l);
  return t === void 0 && X.set(l, t = Ft(l)), t;
}
function Ft(l) {
  let t = null;
  function e(n) {
    if (n && typeof n == "object")
      if (Array.isArray(n))
        if (typeof n[0] == "string")
          t || (t = []), t.push(n);
        else
          for (let i = 0; i < n.length; i++)
            e(n[i]);
      else
        for (let i in n)
          e(n[i]);
  }
  return e(l), t;
}
function b(l, t, e, n) {
  if (typeof t == "string")
    return { dom: l.createTextNode(t) };
  if (t.nodeType != null)
    return { dom: t };
  if (t.dom && t.dom.nodeType != null)
    return t;
  let i = t[0], r;
  if (typeof i != "string")
    throw new RangeError("Invalid array passed to renderSpec");
  if (n && (r = Bt(n)) && r.indexOf(t) > -1)
    throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
  let s = i.indexOf(" ");
  s > 0 && (e = i.slice(0, s), i = i.slice(s + 1));
  let o, h = e ? l.createElementNS(e, i) : l.createElement(i), a = t[1], f = 1;
  if (a && typeof a == "object" && a.nodeType == null && !Array.isArray(a)) {
    f = 2;
    for (let p in a)
      if (a[p] != null) {
        let g = p.indexOf(" ");
        g > 0 ? h.setAttributeNS(p.slice(0, g), p.slice(g + 1), a[p]) : h.setAttribute(p, a[p]);
      }
  }
  for (let p = f; p < t.length; p++) {
    let g = t[p];
    if (g === 0) {
      if (p < t.length - 1 || p > f)
        throw new RangeError("Content hole must be the only child of its parent node");
      return { dom: h, contentDOM: h };
    } else {
      let { dom: pt, contentDOM: J } = b(l, g, e, n);
      if (h.appendChild(pt), J) {
        if (o)
          throw new RangeError("Multiple content holes");
        o = J;
      }
    }
  }
  return { dom: h, contentDOM: o };
}
export {
  w as ContentMatch,
  P as DOMParser,
  ut as DOMSerializer,
  c as Fragment,
  u as Mark,
  F as MarkType,
  y as Node,
  mt as NodeRange,
  z as NodeType,
  I as ReplaceError,
  E as ResolvedPos,
  qt as Schema,
  d as Slice
};
//# sourceMappingURL=index.js.map
