var dh = Object.defineProperty;
var uh = (t, e, n) => e in t ? dh(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
var q = (t, e, n) => (uh(t, typeof e != "symbol" ? e + "" : e, n), n);
function Ve(t) {
  this.content = t;
}
Ve.prototype = {
  constructor: Ve,
  find: function(t) {
    for (var e = 0; e < this.content.length; e += 2)
      if (this.content[e] === t)
        return e;
    return -1;
  },
  // :: (string) → ?any
  // Retrieve the value stored under `key`, or return undefined when
  // no such key exists.
  get: function(t) {
    var e = this.find(t);
    return e == -1 ? void 0 : this.content[e + 1];
  },
  // :: (string, any, ?string) → OrderedMap
  // Create a new map by replacing the value of `key` with a new
  // value, or adding a binding to the end of the map. If `newKey` is
  // given, the key of the binding will be replaced with that key.
  update: function(t, e, n) {
    var r = n && n != t ? this.remove(n) : this, i = r.find(t), s = r.content.slice();
    return i == -1 ? s.push(n || t, e) : (s[i + 1] = e, n && (s[i] = n)), new Ve(s);
  },
  // :: (string) → OrderedMap
  // Return a map with the given key removed, if it existed.
  remove: function(t) {
    var e = this.find(t);
    if (e == -1)
      return this;
    var n = this.content.slice();
    return n.splice(e, 2), new Ve(n);
  },
  // :: (string, any) → OrderedMap
  // Add a new key to the start of the map.
  addToStart: function(t, e) {
    return new Ve([t, e].concat(this.remove(t).content));
  },
  // :: (string, any) → OrderedMap
  // Add a new key to the end of the map.
  addToEnd: function(t, e) {
    var n = this.remove(t).content.slice();
    return n.push(t, e), new Ve(n);
  },
  // :: (string, string, any) → OrderedMap
  // Add a key after the given key. If `place` is not found, the new
  // key is added to the end.
  addBefore: function(t, e, n) {
    var r = this.remove(e), i = r.content.slice(), s = r.find(t);
    return i.splice(s == -1 ? i.length : s, 0, e, n), new Ve(i);
  },
  // :: ((key: string, value: any))
  // Call the given function for each key/value pair in the map, in
  // order.
  forEach: function(t) {
    for (var e = 0; e < this.content.length; e += 2)
      t(this.content[e], this.content[e + 1]);
  },
  // :: (union<Object, OrderedMap>) → OrderedMap
  // Create a new map by prepending the keys in this map that don't
  // appear in `map` before the keys in `map`.
  prepend: function(t) {
    return t = Ve.from(t), t.size ? new Ve(t.content.concat(this.subtract(t).content)) : this;
  },
  // :: (union<Object, OrderedMap>) → OrderedMap
  // Create a new map by appending the keys in this map that don't
  // appear in `map` after the keys in `map`.
  append: function(t) {
    return t = Ve.from(t), t.size ? new Ve(this.subtract(t).content.concat(t.content)) : this;
  },
  // :: (union<Object, OrderedMap>) → OrderedMap
  // Create a map containing all the keys in this map that don't
  // appear in `map`.
  subtract: function(t) {
    var e = this;
    t = Ve.from(t);
    for (var n = 0; n < t.content.length; n += 2)
      e = e.remove(t.content[n]);
    return e;
  },
  // :: () → Object
  // Turn ordered map into a plain object.
  toObject: function() {
    var t = {};
    return this.forEach(function(e, n) {
      t[e] = n;
    }), t;
  },
  // :: number
  // The amount of keys in this map.
  get size() {
    return this.content.length >> 1;
  }
};
Ve.from = function(t) {
  if (t instanceof Ve)
    return t;
  var e = [];
  if (t)
    for (var n in t)
      e.push(n, t[n]);
  return new Ve(e);
};
function su(t, e, n) {
  for (let r = 0; ; r++) {
    if (r == t.childCount || r == e.childCount)
      return t.childCount == e.childCount ? null : n;
    let i = t.child(r), s = e.child(r);
    if (i == s) {
      n += i.nodeSize;
      continue;
    }
    if (!i.sameMarkup(s))
      return n;
    if (i.isText && i.text != s.text) {
      for (let o = 0; i.text[o] == s.text[o]; o++)
        n++;
      return n;
    }
    if (i.content.size || s.content.size) {
      let o = su(i.content, s.content, n + 1);
      if (o != null)
        return o;
    }
    n += i.nodeSize;
  }
}
function ou(t, e, n, r) {
  for (let i = t.childCount, s = e.childCount; ; ) {
    if (i == 0 || s == 0)
      return i == s ? null : { a: n, b: r };
    let o = t.child(--i), a = e.child(--s), l = o.nodeSize;
    if (o == a) {
      n -= l, r -= l;
      continue;
    }
    if (!o.sameMarkup(a))
      return { a: n, b: r };
    if (o.isText && o.text != a.text) {
      let c = 0, d = Math.min(o.text.length, a.text.length);
      for (; c < d && o.text[o.text.length - c - 1] == a.text[a.text.length - c - 1]; )
        c++, n--, r--;
      return { a: n, b: r };
    }
    if (o.content.size || a.content.size) {
      let c = ou(o.content, a.content, n - 1, r - 1);
      if (c)
        return c;
    }
    n -= l, r -= l;
  }
}
class A {
  /**
  @internal
  */
  constructor(e, n) {
    if (this.content = e, this.size = n || 0, n == null)
      for (let r = 0; r < e.length; r++)
        this.size += e[r].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(e, n, r, i = 0, s) {
    for (let o = 0, a = 0; a < n; o++) {
      let l = this.content[o], c = a + l.nodeSize;
      if (c > e && r(l, i + a, s || null, o) !== !1 && l.content.size) {
        let d = a + 1;
        l.nodesBetween(Math.max(0, e - d), Math.min(l.content.size, n - d), r, i + d);
      }
      a = c;
    }
  }
  /**
  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(e) {
    this.nodesBetween(0, this.size, e);
  }
  /**
  Extract the text between `from` and `to`. See the same method on
  [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).
  */
  textBetween(e, n, r, i) {
    let s = "", o = !0;
    return this.nodesBetween(e, n, (a, l) => {
      a.isText ? (s += a.text.slice(Math.max(e, l) - l, n - l), o = !r) : a.isLeaf ? (i ? s += typeof i == "function" ? i(a) : i : a.type.spec.leafText && (s += a.type.spec.leafText(a)), o = !r) : !o && a.isBlock && (s += r, o = !0);
    }, 0), s;
  }
  /**
  Create a new fragment containing the combined content of this
  fragment and the other.
  */
  append(e) {
    if (!e.size)
      return this;
    if (!this.size)
      return e;
    let n = this.lastChild, r = e.firstChild, i = this.content.slice(), s = 0;
    for (n.isText && n.sameMarkup(r) && (i[i.length - 1] = n.withText(n.text + r.text), s = 1); s < e.content.length; s++)
      i.push(e.content[s]);
    return new A(i, this.size + e.size);
  }
  /**
  Cut out the sub-fragment between the two given positions.
  */
  cut(e, n = this.size) {
    if (e == 0 && n == this.size)
      return this;
    let r = [], i = 0;
    if (n > e)
      for (let s = 0, o = 0; o < n; s++) {
        let a = this.content[s], l = o + a.nodeSize;
        l > e && ((o < e || l > n) && (a.isText ? a = a.cut(Math.max(0, e - o), Math.min(a.text.length, n - o)) : a = a.cut(Math.max(0, e - o - 1), Math.min(a.content.size, n - o - 1))), r.push(a), i += a.nodeSize), o = l;
      }
    return new A(r, i);
  }
  /**
  @internal
  */
  cutByIndex(e, n) {
    return e == n ? A.empty : e == 0 && n == this.content.length ? this : new A(this.content.slice(e, n));
  }
  /**
  Create a new fragment in which the node at the given index is
  replaced by the given node.
  */
  replaceChild(e, n) {
    let r = this.content[e];
    if (r == n)
      return this;
    let i = this.content.slice(), s = this.size + n.nodeSize - r.nodeSize;
    return i[e] = n, new A(i, s);
  }
  /**
  Create a new fragment by prepending the given node to this
  fragment.
  */
  addToStart(e) {
    return new A([e].concat(this.content), this.size + e.nodeSize);
  }
  /**
  Create a new fragment by appending the given node to this
  fragment.
  */
  addToEnd(e) {
    return new A(this.content.concat(e), this.size + e.nodeSize);
  }
  /**
  Compare this fragment to another one.
  */
  eq(e) {
    if (this.content.length != e.content.length)
      return !1;
    for (let n = 0; n < this.content.length; n++)
      if (!this.content[n].eq(e.content[n]))
        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(e) {
    let n = this.content[e];
    if (!n)
      throw new RangeError("Index " + e + " out of range for " + this);
    return n;
  }
  /**
  Get the child node at the given index, if it exists.
  */
  maybeChild(e) {
    return this.content[e] || null;
  }
  /**
  Call `f` for every child node, passing the node, its offset
  into this parent node, and its index.
  */
  forEach(e) {
    for (let n = 0, r = 0; n < this.content.length; n++) {
      let i = this.content[n];
      e(i, r, n), r += i.nodeSize;
    }
  }
  /**
  Find the first position at which this fragment and another
  fragment differ, or `null` if they are the same.
  */
  findDiffStart(e, n = 0) {
    return su(this, e, n);
  }
  /**
  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(e, n = this.size, r = e.size) {
    return ou(this, e, n, r);
  }
  /**
  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. (Not public.)
  */
  findIndex(e, n = -1) {
    if (e == 0)
      return Ci(0, e);
    if (e == this.size)
      return Ci(this.content.length, e);
    if (e > this.size || e < 0)
      throw new RangeError(`Position ${e} outside of fragment (${this})`);
    for (let r = 0, i = 0; ; r++) {
      let s = this.child(r), o = i + s.nodeSize;
      if (o >= e)
        return o == e || n > 0 ? Ci(r + 1, o) : Ci(r, i);
      i = o;
    }
  }
  /**
  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((e) => e.toJSON()) : null;
  }
  /**
  Deserialize a fragment from its JSON representation.
  */
  static fromJSON(e, n) {
    if (!n)
      return A.empty;
    if (!Array.isArray(n))
      throw new RangeError("Invalid input for Fragment.fromJSON");
    return new A(n.map(e.nodeFromJSON));
  }
  /**
  Build a fragment from an array of nodes. Ensures that adjacent
  text nodes with the same marks are joined together.
  */
  static fromArray(e) {
    if (!e.length)
      return A.empty;
    let n, r = 0;
    for (let i = 0; i < e.length; i++) {
      let s = e[i];
      r += s.nodeSize, i && s.isText && e[i - 1].sameMarkup(s) ? (n || (n = e.slice(0, i)), n[n.length - 1] = s.withText(n[n.length - 1].text + s.text)) : n && n.push(s);
    }
    return new A(n || e, r);
  }
  /**
  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(e) {
    if (!e)
      return A.empty;
    if (e instanceof A)
      return e;
    if (Array.isArray(e))
      return this.fromArray(e);
    if (e.attrs)
      return new A([e], e.nodeSize);
    throw new RangeError("Can not convert " + e + " to a Fragment" + (e.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : ""));
  }
}
A.empty = new A([], 0);
const no = { index: 0, offset: 0 };
function Ci(t, e) {
  return no.index = t, no.offset = e, no;
}
function Xi(t, e) {
  if (t === e)
    return !0;
  if (!(t && typeof t == "object") || !(e && typeof e == "object"))
    return !1;
  let n = Array.isArray(t);
  if (Array.isArray(e) != n)
    return !1;
  if (n) {
    if (t.length != e.length)
      return !1;
    for (let r = 0; r < t.length; r++)
      if (!Xi(t[r], e[r]))
        return !1;
  } else {
    for (let r in t)
      if (!(r in e) || !Xi(t[r], e[r]))
        return !1;
    for (let r in e)
      if (!(r in t))
        return !1;
  }
  return !0;
}
let ve = class Uo {
  /**
  @internal
  */
  constructor(e, n) {
    this.type = e, this.attrs = n;
  }
  /**
  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(e) {
    let n, r = !1;
    for (let i = 0; i < e.length; i++) {
      let s = e[i];
      if (this.eq(s))
        return e;
      if (this.type.excludes(s.type))
        n || (n = e.slice(0, i));
      else {
        if (s.type.excludes(this.type))
          return e;
        !r && s.type.rank > this.type.rank && (n || (n = e.slice(0, i)), n.push(this), r = !0), n && n.push(s);
      }
    }
    return n || (n = e.slice()), r || n.push(this), n;
  }
  /**
  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(e) {
    for (let n = 0; n < e.length; n++)
      if (this.eq(e[n]))
        return e.slice(0, n).concat(e.slice(n + 1));
    return e;
  }
  /**
  Test whether this mark is in the given set of marks.
  */
  isInSet(e) {
    for (let n = 0; n < e.length; n++)
      if (this.eq(e[n]))
        return !0;
    return !1;
  }
  /**
  Test whether this mark has the same type and attributes as
  another mark.
  */
  eq(e) {
    return this == e || this.type == e.type && Xi(this.attrs, e.attrs);
  }
  /**
  Convert this mark to a JSON-serializeable representation.
  */
  toJSON() {
    let e = { type: this.type.name };
    for (let n in this.attrs) {
      e.attrs = this.attrs;
      break;
    }
    return e;
  }
  /**
  Deserialize a mark from JSON.
  */
  static fromJSON(e, n) {
    if (!n)
      throw new RangeError("Invalid input for Mark.fromJSON");
    let r = e.marks[n.type];
    if (!r)
      throw new RangeError(`There is no mark type ${n.type} in this schema`);
    return r.create(n.attrs);
  }
  /**
  Test whether two sets of marks are identical.
  */
  static sameSet(e, n) {
    if (e == n)
      return !0;
    if (e.length != n.length)
      return !1;
    for (let r = 0; r < e.length; r++)
      if (!e[r].eq(n[r]))
        return !1;
    return !0;
  }
  /**
  Create a properly sorted mark set from null, a single mark, or an
  unsorted array of marks.
  */
  static setFrom(e) {
    if (!e || Array.isArray(e) && e.length == 0)
      return Uo.none;
    if (e instanceof Uo)
      return [e];
    let n = e.slice();
    return n.sort((r, i) => r.type.rank - i.type.rank), n;
  }
};
ve.none = [];
class Qi extends Error {
}
class B {
  /**
  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(e, n, r) {
    this.content = e, this.openStart = n, this.openEnd = r;
  }
  /**
  The size this slice would add when inserted into a document.
  */
  get size() {
    return this.content.size - this.openStart - this.openEnd;
  }
  /**
  @internal
  */
  insertAt(e, n) {
    let r = lu(this.content, e + this.openStart, n);
    return r && new B(r, this.openStart, this.openEnd);
  }
  /**
  @internal
  */
  removeBetween(e, n) {
    return new B(au(this.content, e + this.openStart, n + this.openStart), this.openStart, this.openEnd);
  }
  /**
  Tests whether this slice is equal to another slice.
  */
  eq(e) {
    return this.content.eq(e.content) && this.openStart == e.openStart && this.openEnd == e.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 e = { content: this.content.toJSON() };
    return this.openStart > 0 && (e.openStart = this.openStart), this.openEnd > 0 && (e.openEnd = this.openEnd), e;
  }
  /**
  Deserialize a slice from its JSON representation.
  */
  static fromJSON(e, n) {
    if (!n)
      return B.empty;
    let r = n.openStart || 0, i = n.openEnd || 0;
    if (typeof r != "number" || typeof i != "number")
      throw new RangeError("Invalid input for Slice.fromJSON");
    return new B(A.fromJSON(e, n.content), r, i);
  }
  /**
  Create a slice from a fragment by taking the maximum possible
  open value on both side of the fragment.
  */
  static maxOpen(e, n = !0) {
    let r = 0, i = 0;
    for (let s = e.firstChild; s && !s.isLeaf && (n || !s.type.spec.isolating); s = s.firstChild)
      r++;
    for (let s = e.lastChild; s && !s.isLeaf && (n || !s.type.spec.isolating); s = s.lastChild)
      i++;
    return new B(e, r, i);
  }
}
B.empty = new B(A.empty, 0, 0);
function au(t, e, n) {
  let { index: r, offset: i } = t.findIndex(e), s = t.maybeChild(r), { index: o, offset: a } = t.findIndex(n);
  if (i == e || s.isText) {
    if (a != n && !t.child(o).isText)
      throw new RangeError("Removing non-flat range");
    return t.cut(0, e).append(t.cut(n));
  }
  if (r != o)
    throw new RangeError("Removing non-flat range");
  return t.replaceChild(r, s.copy(au(s.content, e - i - 1, n - i - 1)));
}
function lu(t, e, n, r) {
  let { index: i, offset: s } = t.findIndex(e), o = t.maybeChild(i);
  if (s == e || o.isText)
    return r && !r.canReplace(i, i, n) ? null : t.cut(0, e).append(n).append(t.cut(e));
  let a = lu(o.content, e - s - 1, n);
  return a && t.replaceChild(i, o.copy(a));
}
function fh(t, e, n) {
  if (n.openStart > t.depth)
    throw new Qi("Inserted content deeper than insertion position");
  if (t.depth - n.openStart != e.depth - n.openEnd)
    throw new Qi("Inconsistent open depths");
  return cu(t, e, n, 0);
}
function cu(t, e, n, r) {
  let i = t.index(r), s = t.node(r);
  if (i == e.index(r) && r < t.depth - n.openStart) {
    let o = cu(t, e, n, r + 1);
    return s.copy(s.content.replaceChild(i, o));
  } else if (n.content.size)
    if (!n.openStart && !n.openEnd && t.depth == r && e.depth == r) {
      let o = t.parent, a = o.content;
      return Rn(o, a.cut(0, t.parentOffset).append(n.content).append(a.cut(e.parentOffset)));
    } else {
      let { start: o, end: a } = ph(n, t);
      return Rn(s, uu(t, o, a, e, r));
    }
  else
    return Rn(s, es(t, e, r));
}
function du(t, e) {
  if (!e.type.compatibleContent(t.type))
    throw new Qi("Cannot join " + e.type.name + " onto " + t.type.name);
}
function Ko(t, e, n) {
  let r = t.node(n);
  return du(r, e.node(n)), r;
}
function On(t, e) {
  let n = e.length - 1;
  n >= 0 && t.isText && t.sameMarkup(e[n]) ? e[n] = t.withText(e[n].text + t.text) : e.push(t);
}
function zr(t, e, n, r) {
  let i = (e || t).node(n), s = 0, o = e ? e.index(n) : i.childCount;
  t && (s = t.index(n), t.depth > n ? s++ : t.textOffset && (On(t.nodeAfter, r), s++));
  for (let a = s; a < o; a++)
    On(i.child(a), r);
  e && e.depth == n && e.textOffset && On(e.nodeBefore, r);
}
function Rn(t, e) {
  return t.type.checkContent(e), t.copy(e);
}
function uu(t, e, n, r, i) {
  let s = t.depth > i && Ko(t, e, i + 1), o = r.depth > i && Ko(n, r, i + 1), a = [];
  return zr(null, t, i, a), s && o && e.index(i) == n.index(i) ? (du(s, o), On(Rn(s, uu(t, e, n, r, i + 1)), a)) : (s && On(Rn(s, es(t, e, i + 1)), a), zr(e, n, i, a), o && On(Rn(o, es(n, r, i + 1)), a)), zr(r, null, i, a), new A(a);
}
function es(t, e, n) {
  let r = [];
  if (zr(null, t, n, r), t.depth > n) {
    let i = Ko(t, e, n + 1);
    On(Rn(i, es(t, e, n + 1)), r);
  }
  return zr(e, null, n, r), new A(r);
}
function ph(t, e) {
  let n = e.depth - t.openStart, i = e.node(n).copy(t.content);
  for (let s = n - 1; s >= 0; s--)
    i = e.node(s).copy(A.from(i));
  return {
    start: i.resolveNoCache(t.openStart + n),
    end: i.resolveNoCache(i.content.size - t.openEnd - n)
  };
}
class Xr {
  /**
  @internal
  */
  constructor(e, n, r) {
    this.pos = e, this.path = n, this.parentOffset = r, this.depth = n.length / 3 - 1;
  }
  /**
  @internal
  */
  resolveDepth(e) {
    return e == null ? this.depth : e < 0 ? this.depth + e : e;
  }
  /**
  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(e) {
    return this.path[this.resolveDepth(e) * 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(e) {
    return this.path[this.resolveDepth(e) * 3 + 1];
  }
  /**
  The index pointing after this position into the ancestor at the
  given level.
  */
  indexAfter(e) {
    return e = this.resolveDepth(e), this.index(e) + (e == this.depth && !this.textOffset ? 0 : 1);
  }
  /**
  The (absolute) position at the start of the node at the given
  level.
  */
  start(e) {
    return e = this.resolveDepth(e), e == 0 ? 0 : this.path[e * 3 - 1] + 1;
  }
  /**
  The (absolute) position at the end of the node at the given
  level.
  */
  end(e) {
    return e = this.resolveDepth(e), this.start(e) + this.node(e).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(e) {
    if (e = this.resolveDepth(e), !e)
      throw new RangeError("There is no position before the top-level node");
    return e == this.depth + 1 ? this.pos : this.path[e * 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(e) {
    if (e = this.resolveDepth(e), !e)
      throw new RangeError("There is no position after the top-level node");
    return e == this.depth + 1 ? this.pos : this.path[e * 3 - 1] + this.path[e * 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 e = this.parent, n = this.index(this.depth);
    if (n == e.childCount)
      return null;
    let r = this.pos - this.path[this.path.length - 1], i = e.child(n);
    return r ? e.child(n).cut(r) : 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 e = this.index(this.depth), n = this.pos - this.path[this.path.length - 1];
    return n ? this.parent.child(e).cut(0, n) : e == 0 ? null : this.parent.child(e - 1);
  }
  /**
  Get the position at the given index in the parent node at the
  given depth (which defaults to `this.depth`).
  */
  posAtIndex(e, n) {
    n = this.resolveDepth(n);
    let r = this.path[n * 3], i = n == 0 ? 0 : this.path[n * 3 - 1] + 1;
    for (let s = 0; s < e; s++)
      i += r.child(s).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 e = this.parent, n = this.index();
    if (e.content.size == 0)
      return ve.none;
    if (this.textOffset)
      return e.child(n).marks;
    let r = e.maybeChild(n - 1), i = e.maybeChild(n);
    if (!r) {
      let a = r;
      r = i, i = a;
    }
    let s = r.marks;
    for (var o = 0; o < s.length; o++)
      s[o].type.spec.inclusive === !1 && (!i || !s[o].isInSet(i.marks)) && (s = s[o--].removeFromSet(s));
    return s;
  }
  /**
  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(e) {
    let n = this.parent.maybeChild(this.index());
    if (!n || !n.isInline)
      return null;
    let r = n.marks, i = e.parent.maybeChild(e.index());
    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;
  }
  /**
  The depth up to which this position and the given (non-resolved)
  position share the same parent nodes.
  */
  sharedDepth(e) {
    for (let n = this.depth; n > 0; n--)
      if (this.start(n) <= e && this.end(n) >= e)
        return n;
    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(e = this, n) {
    if (e.pos < this.pos)
      return e.blockRange(this);
    for (let r = this.depth - (this.parent.inlineContent || this.pos == e.pos ? 1 : 0); r >= 0; r--)
      if (e.pos <= this.end(r) && (!n || n(this.node(r))))
        return new ts(this, e, r);
    return null;
  }
  /**
  Query whether the given position shares the same parent node.
  */
  sameParent(e) {
    return this.pos - this.parentOffset == e.pos - e.parentOffset;
  }
  /**
  Return the greater of this and the given position.
  */
  max(e) {
    return e.pos > this.pos ? e : this;
  }
  /**
  Return the smaller of this and the given position.
  */
  min(e) {
    return e.pos < this.pos ? e : this;
  }
  /**
  @internal
  */
  toString() {
    let e = "";
    for (let n = 1; n <= this.depth; n++)
      e += (e ? "/" : "") + this.node(n).type.name + "_" + this.index(n - 1);
    return e + ":" + this.parentOffset;
  }
  /**
  @internal
  */
  static resolve(e, n) {
    if (!(n >= 0 && n <= e.content.size))
      throw new RangeError("Position " + n + " out of range");
    let r = [], i = 0, s = n;
    for (let o = e; ; ) {
      let { index: a, offset: l } = o.content.findIndex(s), c = s - l;
      if (r.push(o, a, i + l), !c || (o = o.child(a), o.isText))
        break;
      s = c - 1, i += l + 1;
    }
    return new Xr(n, r, s);
  }
  /**
  @internal
  */
  static resolveCached(e, n) {
    for (let i = 0; i < ro.length; i++) {
      let s = ro[i];
      if (s.pos == n && s.doc == e)
        return s;
    }
    let r = ro[io] = Xr.resolve(e, n);
    return io = (io + 1) % hh, r;
  }
}
let ro = [], io = 0, hh = 12;
class ts {
  /**
  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(e, n, r) {
    this.$from = e, this.$to = n, this.depth = r;
  }
  /**
  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 mh = /* @__PURE__ */ Object.create(null);
let Ln = class Wo {
  /**
  @internal
  */
  constructor(e, n, r, i = ve.none) {
    this.type = e, this.attrs = n, this.marks = i, this.content = r || A.empty;
  }
  /**
  The size of this node, as defined by the integer-based [indexing
  scheme](/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(e) {
    return this.content.child(e);
  }
  /**
  Get the child node at the given index, if it exists.
  */
  maybeChild(e) {
    return this.content.maybeChild(e);
  }
  /**
  Call `f` for every child node, passing the node, its offset
  into this parent node, and its index.
  */
  forEach(e) {
    this.content.forEach(e);
  }
  /**
  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(e, n, r, i = 0) {
    this.content.nodesBetween(e, n, r, i, this);
  }
  /**
  Call the given callback for every descendant node. Doesn't
  descend into a node when the callback returns `false`.
  */
  descendants(e) {
    this.nodesBetween(0, this.content.size, e);
  }
  /**
  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(e, n, r, i) {
    return this.content.textBetween(e, n, r, 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(e) {
    return this == e || this.sameMarkup(e) && this.content.eq(e.content);
  }
  /**
  Compare the markup (type, attributes, and marks) of this node to
  those of another. Returns `true` if both have the same markup.
  */
  sameMarkup(e) {
    return this.hasMarkup(e.type, e.attrs, e.marks);
  }
  /**
  Check whether this node's markup correspond to the given type,
  attributes, and marks.
  */
  hasMarkup(e, n, r) {
    return this.type == e && Xi(this.attrs, n || e.defaultAttrs || mh) && ve.sameSet(this.marks, r || ve.none);
  }
  /**
  Create a new node with the same markup as this node, containing
  the given content (or empty, if no content is given).
  */
  copy(e = null) {
    return e == this.content ? this : new Wo(this.type, this.attrs, e, this.marks);
  }
  /**
  Create a copy of this node, with the given set of marks instead
  of the node's own marks.
  */
  mark(e) {
    return e == this.marks ? this : new Wo(this.type, this.attrs, this.content, e);
  }
  /**
  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(e, n = this.content.size) {
    return e == 0 && n == this.content.size ? this : this.copy(this.content.cut(e, n));
  }
  /**
  Cut out the part of the document between the given positions, and
  return it as a `Slice` object.
  */
  slice(e, n = this.content.size, r = !1) {
    if (e == n)
      return B.empty;
    let i = this.resolve(e), s = this.resolve(n), o = r ? 0 : i.sharedDepth(n), a = i.start(o), c = i.node(o).content.cut(i.pos - a, s.pos - a);
    return new B(c, i.depth - o, s.depth - o);
  }
  /**
  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(e, n, r) {
    return fh(this.resolve(e), this.resolve(n), r);
  }
  /**
  Find the node directly after the given position.
  */
  nodeAt(e) {
    for (let n = this; ; ) {
      let { index: r, offset: i } = n.content.findIndex(e);
      if (n = n.maybeChild(r), !n)
        return null;
      if (i == e || n.isText)
        return n;
      e -= 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(e) {
    let { index: n, offset: r } = this.content.findIndex(e);
    return { node: this.content.maybeChild(n), index: n, offset: r };
  }
  /**
  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(e) {
    if (e == 0)
      return { node: null, index: 0, offset: 0 };
    let { index: n, offset: r } = this.content.findIndex(e);
    if (r < e)
      return { node: this.content.child(n), index: n, offset: r };
    let i = this.content.child(n - 1);
    return { node: i, index: n - 1, offset: r - 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(e) {
    return Xr.resolveCached(this, e);
  }
  /**
  @internal
  */
  resolveNoCache(e) {
    return Xr.resolve(this, e);
  }
  /**
  Test whether a given mark or mark type occurs in this document
  between the two given positions.
  */
  rangeHasMark(e, n, r) {
    let i = !1;
    return n > e && this.nodesBetween(e, n, (s) => (r.isInSet(s.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 e = this.type.name;
    return this.content.size && (e += "(" + this.content.toStringInner() + ")"), fu(this.marks, e);
  }
  /**
  Get the content match in this node at the given index.
  */
  contentMatchAt(e) {
    let n = this.type.contentMatch.matchFragment(this.content, 0, e);
    if (!n)
      throw new Error("Called contentMatchAt on a node with invalid content");
    return n;
  }
  /**
  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(e, n, r = A.empty, i = 0, s = r.childCount) {
    let o = this.contentMatchAt(e).matchFragment(r, i, s), a = o && o.matchFragment(this.content, n);
    if (!a || !a.validEnd)
      return !1;
    for (let l = i; l < s; l++)
      if (!this.type.allowsMarks(r.child(l).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(e, n, r, i) {
    if (i && !this.type.allowsMarks(i))
      return !1;
    let s = this.contentMatchAt(e).matchType(r), o = s && s.matchFragment(this.content, n);
    return o ? o.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(e) {
    return e.content.size ? this.canReplace(this.childCount, this.childCount, e.content) : this.type.compatibleContent(e.type);
  }
  /**
  Check whether this node and its descendants conform to the
  schema, and raise error when they do not.
  */
  check() {
    this.type.checkContent(this.content);
    let e = ve.none;
    for (let n = 0; n < this.marks.length; n++)
      e = this.marks[n].addToSet(e);
    if (!ve.sameSet(e, this.marks))
      throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((n) => n.type.name)}`);
    this.content.forEach((n) => n.check());
  }
  /**
  Return a JSON-serializeable representation of this node.
  */
  toJSON() {
    let e = { type: this.type.name };
    for (let n in this.attrs) {
      e.attrs = this.attrs;
      break;
    }
    return this.content.size && (e.content = this.content.toJSON()), this.marks.length && (e.marks = this.marks.map((n) => n.toJSON())), e;
  }
  /**
  Deserialize a node from its JSON representation.
  */
  static fromJSON(e, n) {
    if (!n)
      throw new RangeError("Invalid input for Node.fromJSON");
    let r = null;
    if (n.marks) {
      if (!Array.isArray(n.marks))
        throw new RangeError("Invalid mark data for Node.fromJSON");
      r = n.marks.map(e.markFromJSON);
    }
    if (n.type == "text") {
      if (typeof n.text != "string")
        throw new RangeError("Invalid text node in JSON");
      return e.text(n.text, r);
    }
    let i = A.fromJSON(e, n.content);
    return e.nodeType(n.type).create(n.attrs, i, r);
  }
};
Ln.prototype.text = void 0;
class ns extends Ln {
  /**
  @internal
  */
  constructor(e, n, r, i) {
    if (super(e, n, null, i), !r)
      throw new RangeError("Empty text nodes are not allowed");
    this.text = r;
  }
  toString() {
    return this.type.spec.toDebugString ? this.type.spec.toDebugString(this) : fu(this.marks, JSON.stringify(this.text));
  }
  get textContent() {
    return this.text;
  }
  textBetween(e, n) {
    return this.text.slice(e, n);
  }
  get nodeSize() {
    return this.text.length;
  }
  mark(e) {
    return e == this.marks ? this : new ns(this.type, this.attrs, this.text, e);
  }
  withText(e) {
    return e == this.text ? this : new ns(this.type, this.attrs, e, this.marks);
  }
  cut(e = 0, n = this.text.length) {
    return e == 0 && n == this.text.length ? this : this.withText(this.text.slice(e, n));
  }
  eq(e) {
    return this.sameMarkup(e) && this.text == e.text;
  }
  toJSON() {
    let e = super.toJSON();
    return e.text = this.text, e;
  }
}
function fu(t, e) {
  for (let n = t.length - 1; n >= 0; n--)
    e = t[n].type.name + "(" + e + ")";
  return e;
}
class $n {
  /**
  @internal
  */
  constructor(e) {
    this.validEnd = e, this.next = [], this.wrapCache = [];
  }
  /**
  @internal
  */
  static parse(e, n) {
    let r = new gh(e, n);
    if (r.next == null)
      return $n.empty;
    let i = pu(r);
    r.next && r.err("Unexpected trailing text");
    let s = Sh(xh(i));
    return Ch(s, r), s;
  }
  /**
  Match a node type, returning a match after that node if
  successful.
  */
  matchType(e) {
    for (let n = 0; n < this.next.length; n++)
      if (this.next[n].type == e)
        return this.next[n].next;
    return null;
  }
  /**
  Try to match a fragment. Returns the resulting match when
  successful.
  */
  matchFragment(e, n = 0, r = e.childCount) {
    let i = this;
    for (let s = n; i && s < r; s++)
      i = i.matchType(e.child(s).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 e = 0; e < this.next.length; e++) {
      let { type: n } = this.next[e];
      if (!(n.isText || n.hasRequiredAttrs()))
        return n;
    }
    return null;
  }
  /**
  @internal
  */
  compatible(e) {
    for (let n = 0; n < this.next.length; n++)
      for (let r = 0; r < e.next.length; r++)
        if (this.next[n].type == e.next[r].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(e, n = !1, r = 0) {
    let i = [this];
    function s(o, a) {
      let l = o.matchFragment(e, r);
      if (l && (!n || l.validEnd))
        return A.from(a.map((c) => c.createAndFill()));
      for (let c = 0; c < o.next.length; c++) {
        let { type: d, next: u } = o.next[c];
        if (!(d.isText || d.hasRequiredAttrs()) && i.indexOf(u) == -1) {
          i.push(u);
          let f = s(u, a.concat(d));
          if (f)
            return f;
        }
      }
      return null;
    }
    return s(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(e) {
    for (let r = 0; r < this.wrapCache.length; r += 2)
      if (this.wrapCache[r] == e)
        return this.wrapCache[r + 1];
    let n = this.computeWrapping(e);
    return this.wrapCache.push(e, n), n;
  }
  /**
  @internal
  */
  computeWrapping(e) {
    let n = /* @__PURE__ */ Object.create(null), r = [{ match: this, type: null, via: null }];
    for (; r.length; ) {
      let i = r.shift(), s = i.match;
      if (s.matchType(e)) {
        let o = [];
        for (let a = i; a.type; a = a.via)
          o.push(a.type);
        return o.reverse();
      }
      for (let o = 0; o < s.next.length; o++) {
        let { type: a, next: l } = s.next[o];
        !a.isLeaf && !a.hasRequiredAttrs() && !(a.name in n) && (!i.type || l.validEnd) && (r.push({ match: a.contentMatch, type: a, via: i }), n[a.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(e) {
    if (e >= this.next.length)
      throw new RangeError(`There's no ${e}th edge in this content match`);
    return this.next[e];
  }
  /**
  @internal
  */
  toString() {
    let e = [];
    function n(r) {
      e.push(r);
      for (let i = 0; i < r.next.length; i++)
        e.indexOf(r.next[i].next) == -1 && n(r.next[i].next);
    }
    return n(this), e.map((r, i) => {
      let s = i + (r.validEnd ? "*" : " ") + " ";
      for (let o = 0; o < r.next.length; o++)
        s += (o ? ", " : "") + r.next[o].type.name + "->" + e.indexOf(r.next[o].next);
      return s;
    }).join(`
`);
  }
}
$n.empty = new $n(!0);
class gh {
  constructor(e, n) {
    this.string = e, this.nodeTypes = n, this.inline = null, this.pos = 0, this.tokens = e.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(e) {
    return this.next == e && (this.pos++ || !0);
  }
  err(e) {
    throw new SyntaxError(e + " (in content expression '" + this.string + "')");
  }
}
function pu(t) {
  let e = [];
  do
    e.push(bh(t));
  while (t.eat("|"));
  return e.length == 1 ? e[0] : { type: "choice", exprs: e };
}
function bh(t) {
  let e = [];
  do
    e.push(yh(t));
  while (t.next && t.next != ")" && t.next != "|");
  return e.length == 1 ? e[0] : { type: "seq", exprs: e };
}
function yh(t) {
  let e = Eh(t);
  for (; ; )
    if (t.eat("+"))
      e = { type: "plus", expr: e };
    else if (t.eat("*"))
      e = { type: "star", expr: e };
    else if (t.eat("?"))
      e = { type: "opt", expr: e };
    else if (t.eat("{"))
      e = vh(t, e);
    else
      break;
  return e;
}
function Nl(t) {
  /\D/.test(t.next) && t.err("Expected number, got '" + t.next + "'");
  let e = Number(t.next);
  return t.pos++, e;
}
function vh(t, e) {
  let n = Nl(t), r = n;
  return t.eat(",") && (t.next != "}" ? r = Nl(t) : r = -1), t.eat("}") || t.err("Unclosed braced range"), { type: "range", min: n, max: r, expr: e };
}
function wh(t, e) {
  let n = t.nodeTypes, r = n[e];
  if (r)
    return [r];
  let i = [];
  for (let s in n) {
    let o = n[s];
    o.groups.indexOf(e) > -1 && i.push(o);
  }
  return i.length == 0 && t.err("No node type or group '" + e + "' found"), i;
}
function Eh(t) {
  if (t.eat("(")) {
    let e = pu(t);
    return t.eat(")") || t.err("Missing closing paren"), e;
  } else if (/\W/.test(t.next))
    t.err("Unexpected token '" + t.next + "'");
  else {
    let e = wh(t, t.next).map((n) => (t.inline == null ? t.inline = n.isInline : t.inline != n.isInline && t.err("Mixing inline and block content"), { type: "name", value: n }));
    return t.pos++, e.length == 1 ? e[0] : { type: "choice", exprs: e };
  }
}
function xh(t) {
  let e = [[]];
  return i(s(t, 0), n()), e;
  function n() {
    return e.push([]) - 1;
  }
  function r(o, a, l) {
    let c = { term: l, to: a };
    return e[o].push(c), c;
  }
  function i(o, a) {
    o.forEach((l) => l.to = a);
  }
  function s(o, a) {
    if (o.type == "choice")
      return o.exprs.reduce((l, c) => l.concat(s(c, a)), []);
    if (o.type == "seq")
      for (let l = 0; ; l++) {
        let c = s(o.exprs[l], a);
        if (l == o.exprs.length - 1)
          return c;
        i(c, a = n());
      }
    else if (o.type == "star") {
      let l = n();
      return r(a, l), i(s(o.expr, l), l), [r(l)];
    } else if (o.type == "plus") {
      let l = n();
      return i(s(o.expr, a), l), i(s(o.expr, l), l), [r(l)];
    } else {
      if (o.type == "opt")
        return [r(a)].concat(s(o.expr, a));
      if (o.type == "range") {
        let l = a;
        for (let c = 0; c < o.min; c++) {
          let d = n();
          i(s(o.expr, l), d), l = d;
        }
        if (o.max == -1)
          i(s(o.expr, l), l);
        else
          for (let c = o.min; c < o.max; c++) {
            let d = n();
            r(l, d), i(s(o.expr, l), d), l = d;
          }
        return [r(l)];
      } else {
        if (o.type == "name")
          return [r(a, void 0, o.value)];
        throw new Error("Unknown expr type");
      }
    }
  }
}
function hu(t, e) {
  return e - t;
}
function Al(t, e) {
  let n = [];
  return r(e), n.sort(hu);
  function r(i) {
    let s = t[i];
    if (s.length == 1 && !s[0].term)
      return r(s[0].to);
    n.push(i);
    for (let o = 0; o < s.length; o++) {
      let { term: a, to: l } = s[o];
      !a && n.indexOf(l) == -1 && r(l);
    }
  }
}
function Sh(t) {
  let e = /* @__PURE__ */ Object.create(null);
  return n(Al(t, 0));
  function n(r) {
    let i = [];
    r.forEach((o) => {
      t[o].forEach(({ term: a, to: l }) => {
        if (!a)
          return;
        let c;
        for (let d = 0; d < i.length; d++)
          i[d][0] == a && (c = i[d][1]);
        Al(t, l).forEach((d) => {
          c || i.push([a, c = []]), c.indexOf(d) == -1 && c.push(d);
        });
      });
    });
    let s = e[r.join(",")] = new $n(r.indexOf(t.length - 1) > -1);
    for (let o = 0; o < i.length; o++) {
      let a = i[o][1].sort(hu);
      s.next.push({ type: i[o][0], next: e[a.join(",")] || n(a) });
    }
    return s;
  }
}
function Ch(t, e) {
  for (let n = 0, r = [t]; n < r.length; n++) {
    let i = r[n], s = !i.validEnd, o = [];
    for (let a = 0; a < i.next.length; a++) {
      let { type: l, next: c } = i.next[a];
      o.push(l.name), s && !(l.isText || l.hasRequiredAttrs()) && (s = !1), r.indexOf(c) == -1 && r.push(c);
    }
    s && e.err("Only non-generatable nodes (" + o.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)");
  }
}
function mu(t) {
  let e = /* @__PURE__ */ Object.create(null);
  for (let n in t) {
    let r = t[n];
    if (!r.hasDefault)
      return null;
    e[n] = r.default;
  }
  return e;
}
function gu(t, e) {
  let n = /* @__PURE__ */ Object.create(null);
  for (let r in t) {
    let i = e && e[r];
    if (i === void 0) {
      let s = t[r];
      if (s.hasDefault)
        i = s.default;
      else
        throw new RangeError("No value supplied for attribute " + r);
    }
    n[r] = i;
  }
  return n;
}
function bu(t) {
  let e = /* @__PURE__ */ Object.create(null);
  if (t)
    for (let n in t)
      e[n] = new Mh(t[n]);
  return e;
}
let Ol = class yu {
  /**
  @internal
  */
  constructor(e, n, r) {
    this.name = e, this.schema = n, this.spec = r, this.markSet = null, this.groups = r.group ? r.group.split(" ") : [], this.attrs = bu(r.attrs), this.defaultAttrs = mu(this.attrs), this.contentMatch = null, this.inlineContent = null, this.isBlock = !(r.inline || e == "text"), this.isText = e == "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 == $n.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;
  }
  /**
  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 e in this.attrs)
      if (this.attrs[e].isRequired)
        return !0;
    return !1;
  }
  /**
  Indicates whether this node allows some of the same content as
  the given node type.
  */
  compatibleContent(e) {
    return this == e || this.contentMatch.compatible(e.contentMatch);
  }
  /**
  @internal
  */
  computeAttrs(e) {
    return !e && this.defaultAttrs ? this.defaultAttrs : gu(this.attrs, e);
  }
  /**
  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(e = null, n, r) {
    if (this.isText)
      throw new Error("NodeType.create can't construct text nodes");
    return new Ln(this, this.computeAttrs(e), A.from(n), ve.setFrom(r));
  }
  /**
  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(e = null, n, r) {
    return n = A.from(n), this.checkContent(n), new Ln(this, this.computeAttrs(e), n, ve.setFrom(r));
  }
  /**
  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(e = null, n, r) {
    if (e = this.computeAttrs(e), n = A.from(n), n.size) {
      let o = this.contentMatch.fillBefore(n);
      if (!o)
        return null;
      n = o.append(n);
    }
    let i = this.contentMatch.matchFragment(n), s = i && i.fillBefore(A.empty, !0);
    return s ? new Ln(this, e, n.append(s), ve.setFrom(r)) : null;
  }
  /**
  Returns true if the given fragment is valid content for this node
  type with the given attributes.
  */
  validContent(e) {
    let n = this.contentMatch.matchFragment(e);
    if (!n || !n.validEnd)
      return !1;
    for (let r = 0; r < e.childCount; r++)
      if (!this.allowsMarks(e.child(r).marks))
        return !1;
    return !0;
  }
  /**
  Throws a RangeError if the given fragment is not valid content for this
  node type.
  @internal
  */
  checkContent(e) {
    if (!this.validContent(e))
      throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0, 50)}`);
  }
  /**
  Check whether the given mark type is allowed in this node.
  */
  allowsMarkType(e) {
    return this.markSet == null || this.markSet.indexOf(e) > -1;
  }
  /**
  Test whether the given set of marks are allowed in this node.
  */
  allowsMarks(e) {
    if (this.markSet == null)
      return !0;
    for (let n = 0; n < e.length; n++)
      if (!this.allowsMarkType(e[n].type))
        return !1;
    return !0;
  }
  /**
  Removes the marks that are not allowed in this node from the given set.
  */
  allowedMarks(e) {
    if (this.markSet == null)
      return e;
    let n;
    for (let r = 0; r < e.length; r++)
      this.allowsMarkType(e[r].type) ? n && n.push(e[r]) : n || (n = e.slice(0, r));
    return n ? n.length ? n : ve.none : e;
  }
  /**
  @internal
  */
  static compile(e, n) {
    let r = /* @__PURE__ */ Object.create(null);
    e.forEach((s, o) => r[s] = new yu(s, n, o));
    let i = n.spec.topNode || "doc";
    if (!r[i])
      throw new RangeError("Schema is missing its top node type ('" + i + "')");
    if (!r.text)
      throw new RangeError("Every schema needs a 'text' type");
    for (let s in r.text.attrs)
      throw new RangeError("The text node type should not have attributes");
    return r;
  }
};
class Mh {
  constructor(e) {
    this.hasDefault = Object.prototype.hasOwnProperty.call(e, "default"), this.default = e.default;
  }
  get isRequired() {
    return !this.hasDefault;
  }
}
class Is {
  /**
  @internal
  */
  constructor(e, n, r, i) {
    this.name = e, this.rank = n, this.schema = r, this.spec = i, this.attrs = bu(i.attrs), this.excluded = null;
    let s = mu(this.attrs);
    this.instance = s ? new ve(this, s) : 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(e = null) {
    return !e && this.instance ? this.instance : new ve(this, gu(this.attrs, e));
  }
  /**
  @internal
  */
  static compile(e, n) {
    let r = /* @__PURE__ */ Object.create(null), i = 0;
    return e.forEach((s, o) => r[s] = new Is(s, i++, n, o)), r;
  }
  /**
  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(e) {
    for (var n = 0; n < e.length; n++)
      e[n].type == this && (e = e.slice(0, n).concat(e.slice(n + 1)), n--);
    return e;
  }
  /**
  Tests whether there is a mark of this type in the given set.
  */
  isInSet(e) {
    for (let n = 0; n < e.length; n++)
      if (e[n].type == this)
        return e[n];
  }
  /**
  Queries whether a given mark type is
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
  */
  excludes(e) {
    return this.excluded.indexOf(e) > -1;
  }
}
class kh {
  /**
  Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).
  */
  constructor(e) {
    this.cached = /* @__PURE__ */ Object.create(null);
    let n = this.spec = {};
    for (let i in e)
      n[i] = e[i];
    n.nodes = Ve.from(e.nodes), n.marks = Ve.from(e.marks || {}), this.nodes = Ol.compile(this.spec.nodes, this), this.marks = Is.compile(this.spec.marks, this);
    let r = /* @__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 s = this.nodes[i], o = s.spec.content || "", a = s.spec.marks;
      s.contentMatch = r[o] || (r[o] = $n.parse(o, this.nodes)), s.inlineContent = s.contentMatch.inlineContent, s.markSet = a == "_" ? null : a ? Rl(this, a.split(" ")) : a == "" || !s.inlineContent ? [] : null;
    }
    for (let i in this.marks) {
      let s = this.marks[i], o = s.spec.excludes;
      s.excluded = o == null ? [s] : o == "" ? [] : Rl(this, o.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(e, n = null, r, i) {
    if (typeof e == "string")
      e = this.nodeType(e);
    else if (e instanceof Ol) {
      if (e.schema != this)
        throw new RangeError("Node type from different schema used (" + e.name + ")");
    } else
      throw new RangeError("Invalid node type: " + e);
    return e.createChecked(n, r, i);
  }
  /**
  Create a text node in the schema. Empty text nodes are not
  allowed.
  */
  text(e, n) {
    let r = this.nodes.text;
    return new ns(r, r.defaultAttrs, e, ve.setFrom(n));
  }
  /**
  Create a mark with the given type and attributes.
  */
  mark(e, n) {
    return typeof e == "string" && (e = this.marks[e]), e.create(n);
  }
  /**
  Deserialize a node from its JSON representation. This method is
  bound.
  */
  nodeFromJSON(e) {
    return Ln.fromJSON(this, e);
  }
  /**
  Deserialize a mark from its JSON representation. This method is
  bound.
  */
  markFromJSON(e) {
    return ve.fromJSON(this, e);
  }
  /**
  @internal
  */
  nodeType(e) {
    let n = this.nodes[e];
    if (!n)
      throw new RangeError("Unknown node type: " + e);
    return n;
  }
}
function Rl(t, e) {
  let n = [];
  for (let r = 0; r < e.length; r++) {
    let i = e[r], s = t.marks[i], o = s;
    if (s)
      n.push(s);
    else
      for (let a in t.marks) {
        let l = t.marks[a];
        (i == "_" || l.spec.group && l.spec.group.split(" ").indexOf(i) > -1) && n.push(o = l);
      }
    if (!o)
      throw new SyntaxError("Unknown mark type: '" + e[r] + "'");
  }
  return n;
}
class br {
  /**
  Create a parser that targets the given schema, using the given
  parsing rules.
  */
  constructor(e, n) {
    this.schema = e, this.rules = n, this.tags = [], this.styles = [], n.forEach((r) => {
      r.tag ? this.tags.push(r) : r.style && this.styles.push(r);
    }), this.normalizeLists = !this.tags.some((r) => {
      if (!/^(ul|ol)\b/.test(r.tag) || !r.node)
        return !1;
      let i = e.nodes[r.node];
      return i.contentMatch.matchType(i);
    });
  }
  /**
  Parse a document from the content of a DOM node.
  */
  parse(e, n = {}) {
    let r = new Il(this, n, !1);
    return r.addAll(e, n.from, n.to), r.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(e, n = {}) {
    let r = new Il(this, n, !0);
    return r.addAll(e, n.from, n.to), B.maxOpen(r.finish());
  }
  /**
  @internal
  */
  matchTag(e, n, r) {
    for (let i = r ? this.tags.indexOf(r) + 1 : 0; i < this.tags.length; i++) {
      let s = this.tags[i];
      if (Nh(e, s.tag) && (s.namespace === void 0 || e.namespaceURI == s.namespace) && (!s.context || n.matchesContext(s.context))) {
        if (s.getAttrs) {
          let o = s.getAttrs(e);
          if (o === !1)
            continue;
          s.attrs = o || void 0;
        }
        return s;
      }
    }
  }
  /**
  @internal
  */
  matchStyle(e, n, r, i) {
    for (let s = i ? this.styles.indexOf(i) + 1 : 0; s < this.styles.length; s++) {
      let o = this.styles[s], a = o.style;
      if (!(a.indexOf(e) != 0 || o.context && !r.matchesContext(o.context) || // Test that the style string either precisely matches the prop,
      // or has an '=' sign after the prop, followed by the given
      // value.
      a.length > e.length && (a.charCodeAt(e.length) != 61 || a.slice(e.length + 1) != n))) {
        if (o.getAttrs) {
          let l = o.getAttrs(n);
          if (l === !1)
            continue;
          o.attrs = l || void 0;
        }
        return o;
      }
    }
  }
  /**
  @internal
  */
  static schemaRules(e) {
    let n = [];
    function r(i) {
      let s = i.priority == null ? 50 : i.priority, o = 0;
      for (; o < n.length; o++) {
        let a = n[o];
        if ((a.priority == null ? 50 : a.priority) < s)
          break;
      }
      n.splice(o, 0, i);
    }
    for (let i in e.marks) {
      let s = e.marks[i].spec.parseDOM;
      s && s.forEach((o) => {
        r(o = Dl(o)), o.mark || o.ignore || o.clearMark || (o.mark = i);
      });
    }
    for (let i in e.nodes) {
      let s = e.nodes[i].spec.parseDOM;
      s && s.forEach((o) => {
        r(o = Dl(o)), o.node || o.ignore || o.mark || (o.node = i);
      });
    }
    return n;
  }
  /**
  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(e) {
    return e.cached.domParser || (e.cached.domParser = new br(e, br.schemaRules(e)));
  }
}
const vu = {
  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
}, Th = {
  head: !0,
  noscript: !0,
  object: !0,
  script: !0,
  style: !0,
  title: !0
}, wu = { ol: !0, ul: !0 }, rs = 1, is = 2, Fr = 4;
function Ll(t, e, n) {
  return e != null ? (e ? rs : 0) | (e === "full" ? is : 0) : t && t.whitespace == "pre" ? rs | is : n & ~Fr;
}
class Mi {
  constructor(e, n, r, i, s, o, a) {
    this.type = e, this.attrs = n, this.marks = r, this.pendingMarks = i, this.solid = s, this.options = a, this.content = [], this.activeMarks = ve.none, this.stashMarks = [], this.match = o || (a & Fr ? null : e.contentMatch);
  }
  findWrapping(e) {
    if (!this.match) {
      if (!this.type)
        return [];
      let n = this.type.contentMatch.fillBefore(A.from(e));
      if (n)
        this.match = this.type.contentMatch.matchFragment(n);
      else {
        let r = this.type.contentMatch, i;
        return (i = r.findWrapping(e.type)) ? (this.match = r, i) : null;
      }
    }
    return this.match.findWrapping(e.type);
  }
  finish(e) {
    if (!(this.options & rs)) {
      let r = this.content[this.content.length - 1], i;
      if (r && r.isText && (i = /[ \t\r\n\u000c]+$/.exec(r.text))) {
        let s = r;
        r.text.length == i[0].length ? this.content.pop() : this.content[this.content.length - 1] = s.withText(s.text.slice(0, s.text.length - i[0].length));
      }
    }
    let n = A.from(this.content);
    return !e && this.match && (n = n.append(this.match.fillBefore(A.empty, !0))), this.type ? this.type.create(this.attrs, n, this.marks) : n;
  }
  popFromStashMark(e) {
    for (let n = this.stashMarks.length - 1; n >= 0; n--)
      if (e.eq(this.stashMarks[n]))
        return this.stashMarks.splice(n, 1)[0];
  }
  applyPending(e) {
    for (let n = 0, r = this.pendingMarks; n < r.length; n++) {
      let i = r[n];
      (this.type ? this.type.allowsMarkType(i.type) : Oh(i.type, e)) && !i.isInSet(this.activeMarks) && (this.activeMarks = i.addToSet(this.activeMarks), this.pendingMarks = i.removeFromSet(this.pendingMarks));
    }
  }
  inlineContext(e) {
    return this.type ? this.type.inlineContent : this.content.length ? this.content[0].isInline : e.parentNode && !vu.hasOwnProperty(e.parentNode.nodeName.toLowerCase());
  }
}
class Il {
  constructor(e, n, r) {
    this.parser = e, this.options = n, this.isOpen = r, this.open = 0;
    let i = n.topNode, s, o = Ll(null, n.preserveWhitespace, 0) | (r ? Fr : 0);
    i ? s = new Mi(i.type, i.attrs, ve.none, ve.none, !0, n.topMatch || i.type.contentMatch, o) : r ? s = new Mi(null, null, ve.none, ve.none, !0, null, o) : s = new Mi(e.schema.topNodeType, null, ve.none, ve.none, !0, null, o), this.nodes = [s], this.find = n.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(e) {
    e.nodeType == 3 ? this.addTextNode(e) : e.nodeType == 1 && this.addElement(e);
  }
  withStyleRules(e, n) {
    let r = e.getAttribute("style");
    if (!r)
      return n();
    let i = this.readStyles(Ah(r));
    if (!i)
      return;
    let [s, o] = i, a = this.top;
    for (let l = 0; l < o.length; l++)
      this.removePendingMark(o[l], a);
    for (let l = 0; l < s.length; l++)
      this.addPendingMark(s[l]);
    n();
    for (let l = 0; l < s.length; l++)
      this.removePendingMark(s[l], a);
    for (let l = 0; l < o.length; l++)
      this.addPendingMark(o[l]);
  }
  addTextNode(e) {
    let n = e.nodeValue, r = this.top;
    if (r.options & is || r.inlineContext(e) || /[^ \t\r\n\u000c]/.test(n)) {
      if (r.options & rs)
        r.options & is ? n = n.replace(/\r\n?/g, `
`) : n = n.replace(/\r?\n|\r/g, " ");
      else if (n = n.replace(/[ \t\r\n\u000c]+/g, " "), /^[ \t\r\n\u000c]/.test(n) && this.open == this.nodes.length - 1) {
        let i = r.content[r.content.length - 1], s = e.previousSibling;
        (!i || s && s.nodeName == "BR" || i.isText && /[ \t\r\n\u000c]$/.test(i.text)) && (n = n.slice(1));
      }
      n && this.insertNode(this.parser.schema.text(n)), this.findInText(e);
    } else
      this.findInside(e);
  }
  // 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(e, n) {
    let r = e.nodeName.toLowerCase(), i;
    wu.hasOwnProperty(r) && this.parser.normalizeLists && _h(e);
    let s = this.options.ruleFromNode && this.options.ruleFromNode(e) || (i = this.parser.matchTag(e, this, n));
    if (s ? s.ignore : Th.hasOwnProperty(r))
      this.findInside(e), this.ignoreFallback(e);
    else if (!s || s.skip || s.closeParent) {
      s && s.closeParent ? this.open = Math.max(0, this.open - 1) : s && s.skip.nodeType && (e = s.skip);
      let o, a = this.top, l = this.needsBlock;
      if (vu.hasOwnProperty(r))
        a.content.length && a.content[0].isInline && this.open && (this.open--, a = this.top), o = !0, a.type || (this.needsBlock = !0);
      else if (!e.firstChild) {
        this.leafFallback(e);
        return;
      }
      s && s.skip ? this.addAll(e) : this.withStyleRules(e, () => this.addAll(e)), o && this.sync(a), this.needsBlock = l;
    } else
      this.withStyleRules(e, () => {
        this.addElementByRule(e, s, s.consuming === !1 ? i : void 0);
      });
  }
  // Called for leaf DOM nodes that would otherwise be ignored
  leafFallback(e) {
    e.nodeName == "BR" && this.top.type && this.top.type.inlineContent && this.addTextNode(e.ownerDocument.createTextNode(`
`));
  }
  // Called for ignored nodes
  ignoreFallback(e) {
    e.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent) && this.findPlace(this.parser.schema.text("-"));
  }
  // Run any style parser associated with the node's styles. Either
  // return an array of marks, or null to indicate some of the styles
  // had a rule with `ignore` set.
  readStyles(e) {
    let n = ve.none, r = ve.none;
    for (let i = 0; i < e.length; i += 2)
      for (let s = void 0; ; ) {
        let o = this.parser.matchStyle(e[i], e[i + 1], this, s);
        if (!o)
          break;
        if (o.ignore)
          return null;
        if (o.clearMark ? this.top.pendingMarks.concat(this.top.activeMarks).forEach((a) => {
          o.clearMark(a) && (r = a.addToSet(r));
        }) : n = this.parser.schema.marks[o.mark].create(o.attrs).addToSet(n), o.consuming === !1)
          s = o;
        else
          break;
      }
    return [n, r];
  }
  // 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(e, n, r) {
    let i, s, o;
    n.node ? (s = this.parser.schema.nodes[n.node], s.isLeaf ? this.insertNode(s.create(n.attrs)) || this.leafFallback(e) : i = this.enter(s, n.attrs || null, n.preserveWhitespace)) : (o = this.parser.schema.marks[n.mark].create(n.attrs), this.addPendingMark(o));
    let a = this.top;
    if (s && s.isLeaf)
      this.findInside(e);
    else if (r)
      this.addElement(e, r);
    else if (n.getContent)
      this.findInside(e), n.getContent(e, this.parser.schema).forEach((l) => this.insertNode(l));
    else {
      let l = e;
      typeof n.contentElement == "string" ? l = e.querySelector(n.contentElement) : typeof n.contentElement == "function" ? l = n.contentElement(e) : n.contentElement && (l = n.contentElement), this.findAround(e, l, !0), this.addAll(l);
    }
    i && this.sync(a) && this.open--, o && this.removePendingMark(o, a);
  }
  // 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(e, n, r) {
    let i = n || 0;
    for (let s = n ? e.childNodes[n] : e.firstChild, o = r == null ? null : e.childNodes[r]; s != o; s = s.nextSibling, ++i)
      this.findAtPoint(e, i), this.addDOM(s);
    this.findAtPoint(e, i);
  }
  // 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(e) {
    let n, r;
    for (let i = this.open; i >= 0; i--) {
      let s = this.nodes[i], o = s.findWrapping(e);
      if (o && (!n || n.length > o.length) && (n = o, r = s, !o.length) || s.solid)
        break;
    }
    if (!n)
      return !1;
    this.sync(r);
    for (let i = 0; i < n.length; i++)
      this.enterInner(n[i], null, !1);
    return !0;
  }
  // Try to insert the given node, adjusting the context when needed.
  insertNode(e) {
    if (e.isInline && this.needsBlock && !this.top.type) {
      let n = this.textblockFromContext();
      n && this.enterInner(n);
    }
    if (this.findPlace(e)) {
      this.closeExtra();
      let n = this.top;
      n.applyPending(e.type), n.match && (n.match = n.match.matchType(e.type));
      let r = n.activeMarks;
      for (let i = 0; i < e.marks.length; i++)
        (!n.type || n.type.allowsMarkType(e.marks[i].type)) && (r = e.marks[i].addToSet(r));
      return n.content.push(e.mark(r)), !0;
    }
    return !1;
  }
  // Try to start a node of the given type, adjusting the context when
  // necessary.
  enter(e, n, r) {
    let i = this.findPlace(e.create(n));
    return i && this.enterInner(e, n, !0, r), i;
  }
  // Open a node of the given type
  enterInner(e, n = null, r = !1, i) {
    this.closeExtra();
    let s = this.top;
    s.applyPending(e), s.match = s.match && s.match.matchType(e);
    let o = Ll(e, i, s.options);
    s.options & Fr && s.content.length == 0 && (o |= Fr), this.nodes.push(new Mi(e, n, s.activeMarks, s.pendingMarks, r, null, o)), this.open++;
  }
  // Make sure all nodes above this.open are finished and added to
  // their parents
  closeExtra(e = !1) {
    let n = this.nodes.length - 1;
    if (n > this.open) {
      for (; n > this.open; n--)
        this.nodes[n - 1].content.push(this.nodes[n].finish(e));
      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(e) {
    for (let n = this.open; n >= 0; n--)
      if (this.nodes[n] == e)
        return this.open = n, !0;
    return !1;
  }
  get currentPos() {
    this.closeExtra();
    let e = 0;
    for (let n = this.open; n >= 0; n--) {
      let r = this.nodes[n].content;
      for (let i = r.length - 1; i >= 0; i--)
        e += r[i].nodeSize;
      n && e++;
    }
    return e;
  }
  findAtPoint(e, n) {
    if (this.find)
      for (let r = 0; r < this.find.length; r++)
        this.find[r].node == e && this.find[r].offset == n && (this.find[r].pos = this.currentPos);
  }
  findInside(e) {
    if (this.find)
      for (let n = 0; n < this.find.length; n++)
        this.find[n].pos == null && e.nodeType == 1 && e.contains(this.find[n].node) && (this.find[n].pos = this.currentPos);
  }
  findAround(e, n, r) {
    if (e != n && this.find)
      for (let i = 0; i < this.find.length; i++)
        this.find[i].pos == null && e.nodeType == 1 && e.contains(this.find[i].node) && n.compareDocumentPosition(this.find[i].node) & (r ? 2 : 4) && (this.find[i].pos = this.currentPos);
  }
  findInText(e) {
    if (this.find)
      for (let n = 0; n < this.find.length; n++)
        this.find[n].node == e && (this.find[n].pos = this.currentPos - (e.nodeValue.length - this.find[n].offset));
  }
  // Determines whether the given context string matches this context.
  matchesContext(e) {
    if (e.indexOf("|") > -1)
      return e.split(/\s*\|\s*/).some(this.matchesContext, this);
    let n = e.split("/"), r = this.options.context, i = !this.isOpen && (!r || r.parent.type == this.nodes[0].type), s = -(r ? r.depth + 1 : 0) + (i ? 0 : 1), o = (a, l) => {
      for (; a >= 0; a--) {
        let c = n[a];
        if (c == "") {
          if (a == n.length - 1 || a == 0)
            continue;
          for (; l >= s; l--)
            if (o(a - 1, l))
              return !0;
          return !1;
        } else {
          let d = l > 0 || l == 0 && i ? this.nodes[l].type : r && l >= s ? r.node(l - s).type : null;
          if (!d || d.name != c && d.groups.indexOf(c) == -1)
            return !1;
          l--;
        }
      }
      return !0;
    };
    return o(n.length - 1, this.open);
  }
  textblockFromContext() {
    let e = this.options.context;
    if (e)
      for (let n = e.depth; n >= 0; n--) {
        let r = e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;
        if (r && r.isTextblock && r.defaultAttrs)
          return r;
      }
    for (let n in this.parser.schema.nodes) {
      let r = this.parser.schema.nodes[n];
      if (r.isTextblock && r.defaultAttrs)
        return r;
    }
  }
  addPendingMark(e) {
    let n = Rh(e, this.top.pendingMarks);
    n && this.top.stashMarks.push(n), this.top.pendingMarks = e.addToSet(this.top.pendingMarks);
  }
  removePendingMark(e, n) {
    for (let r = this.open; r >= 0; r--) {
      let i = this.nodes[r];
      if (i.pendingMarks.lastIndexOf(e) > -1)
        i.pendingMarks = e.removeFromSet(i.pendingMarks);
      else {
        i.activeMarks = e.removeFromSet(i.activeMarks);
        let o = i.popFromStashMark(e);
        o && i.type && i.type.allowsMarkType(o.type) && (i.activeMarks = o.addToSet(i.activeMarks));
      }
      if (i == n)
        break;
    }
  }
}
function _h(t) {
  for (let e = t.firstChild, n = null; e; e = e.nextSibling) {
    let r = e.nodeType == 1 ? e.nodeName.toLowerCase() : null;
    r && wu.hasOwnProperty(r) && n ? (n.appendChild(e), e = n) : r == "li" ? n = e : r && (n = null);
  }
}
function Nh(t, e) {
  return (t.matches || t.msMatchesSelector || t.webkitMatchesSelector || t.mozMatchesSelector).call(t, e);
}
function Ah(t) {
  let e = /\s*([\w-]+)\s*:\s*([^;]+)/g, n, r = [];
  for (; n = e.exec(t); )
    r.push(n[1], n[2].trim());
  return r;
}
function Dl(t) {
  let e = {};
  for (let n in t)
    e[n] = t[n];
  return e;
}
function Oh(t, e) {
  let n = e.schema.nodes;
  for (let r in n) {
    let i = n[r];
    if (!i.allowsMarkType(t))
      continue;
    let s = [], o = (a) => {
      s.push(a);
      for (let l = 0; l < a.edgeCount; l++) {
        let { type: c, next: d } = a.edge(l);
        if (c == e || s.indexOf(d) < 0 && o(d))
          return !0;
      }
    };
    if (o(i.contentMatch))
      return !0;
  }
}
function Rh(t, e) {
  for (let n = 0; n < e.length; n++)
    if (t.eq(e[n]))
      return e[n];
}
class Ht {
  /**
  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(e, n) {
    this.nodes = e, this.marks = n;
  }
  /**
  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(e, n = {}, r) {
    r || (r = so(n).createDocumentFragment());
    let i = r, s = [];
    return e.forEach((o) => {
      if (s.length || o.marks.length) {
        let a = 0, l = 0;
        for (; a < s.length && l < o.marks.length; ) {
          let c = o.marks[l];
          if (!this.marks[c.type.name]) {
            l++;
            continue;
          }
          if (!c.eq(s[a][0]) || c.type.spec.spanning === !1)
            break;
          a++, l++;
        }
        for (; a < s.length; )
          i = s.pop()[1];
        for (; l < o.marks.length; ) {
          let c = o.marks[l++], d = this.serializeMark(c, o.isInline, n);
          d && (s.push([c, i]), i.appendChild(d.dom), i = d.contentDOM || d.dom);
        }
      }
      i.appendChild(this.serializeNodeInner(o, n));
    }), r;
  }
  /**
  @internal
  */
  serializeNodeInner(e, n) {
    let { dom: r, contentDOM: i } = Ht.renderSpec(so(n), this.nodes[e.type.name](e));
    if (i) {
      if (e.isLeaf)
        throw new RangeError("Content hole not allowed in a leaf node spec");
      this.serializeFragment(e.content, n, i);
    }
    return r;
  }
  /**
  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(e, n = {}) {
    let r = this.serializeNodeInner(e, n);
    for (let i = e.marks.length - 1; i >= 0; i--) {
      let s = this.serializeMark(e.marks[i], e.isInline, n);
      s && ((s.contentDOM || s.dom).appendChild(r), r = s.dom);
    }
    return r;
  }
  /**
  @internal
  */
  serializeMark(e, n, r = {}) {
    let i = this.marks[e.type.name];
    return i && Ht.renderSpec(so(r), i(e, n));
  }
  /**
  Render an [output spec](https://prosemirror.net/docs/ref/#model.DOMOutputSpec) to a DOM node. If
  the spec has a hole (zero) in it, `contentDOM` will point at the
  node with the hole.
  */
  static renderSpec(e, n, r = null) {
    if (typeof n == "string")
      return { dom: e.createTextNode(n) };
    if (n.nodeType != null)
      return { dom: n };
    if (n.dom && n.dom.nodeType != null)
      return n;
    let i = n[0], s = i.indexOf(" ");
    s > 0 && (r = i.slice(0, s), i = i.slice(s + 1));
    let o, a = r ? e.createElementNS(r, i) : e.createElement(i), l = n[1], c = 1;
    if (l && typeof l == "object" && l.nodeType == null && !Array.isArray(l)) {
      c = 2;
      for (let d in l)
        if (l[d] != null) {
          let u = d.indexOf(" ");
          u > 0 ? a.setAttributeNS(d.slice(0, u), d.slice(u + 1), l[d]) : a.setAttribute(d, l[d]);
        }
    }
    for (let d = c; d < n.length; d++) {
      let u = n[d];
      if (u === 0) {
        if (d < n.length - 1 || d > c)
          throw new RangeError("Content hole must be the only child of its parent node");
        return { dom: a, contentDOM: a };
      } else {
        let { dom: f, contentDOM: p } = Ht.renderSpec(e, u, r);
        if (a.appendChild(f), p) {
          if (o)
            throw new RangeError("Multiple content holes");
          o = p;
        }
      }
    }
    return { dom: a, contentDOM: o };
  }
  /**
  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(e) {
    return e.cached.domSerializer || (e.cached.domSerializer = new Ht(this.nodesFromSchema(e), this.marksFromSchema(e)));
  }
  /**
  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(e) {
    let n = Hl(e.nodes);
    return n.text || (n.text = (r) => r.text), n;
  }
  /**
  Gather the serializers in a schema's mark specs into an object.
  */
  static marksFromSchema(e) {
    return Hl(e.marks);
  }
}
function Hl(t) {
  let e = {};
  for (let n in t) {
    let r = t[n].spec.toDOM;
    r && (e[n] = r);
  }
  return e;
}
function so(t) {
  return t.document || window.document;
}
const Eu = 65535, xu = Math.pow(2, 16);
function Lh(t, e) {
  return t + e * xu;
}
function Bl(t) {
  return t & Eu;
}
function Ih(t) {
  return (t - (t & Eu)) / xu;
}
const Su = 1, Cu = 2, Ki = 4, Mu = 8;
class qo {
  /**
  @internal
  */
  constructor(e, n, r) {
    this.pos = e, this.delInfo = n, this.recover = r;
  }
  /**
  Tells you whether the position was deleted, that is, whether the
  step removed the token on the side queried (via the `assoc`)
  argument from the document.
  */
  get deleted() {
    return (this.delInfo & Mu) > 0;
  }
  /**
  Tells you whether the token before the mapped position was deleted.
  */
  get deletedBefore() {
    return (this.delInfo & (Su | Ki)) > 0;
  }
  /**
  True when the token after the mapped position was deleted.
  */
  get deletedAfter() {
    return (this.delInfo & (Cu | Ki)) > 0;
  }
  /**
  Tells whether any of the steps mapped through deletes across the
  position (including both the token before and after the
  position).
  */
  get deletedAcross() {
    return (this.delInfo & Ki) > 0;
  }
}
class ut {
  /**
  Create a position map. The modifications to the document are
  represented as an array of numbers, in which each group of three
  represents a modified chunk as `[start, oldSize, newSize]`.
  */
  constructor(e, n = !1) {
    if (this.ranges = e, this.inverted = n, !e.length && ut.empty)
      return ut.empty;
  }
  /**
  @internal
  */
  recover(e) {
    let n = 0, r = Bl(e);
    if (!this.inverted)
      for (let i = 0; i < r; i++)
        n += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];
    return this.ranges[r * 3] + n + Ih(e);
  }
  mapResult(e, n = 1) {
    return this._map(e, n, !1);
  }
  map(e, n = 1) {
    return this._map(e, n, !0);
  }
  /**
  @internal
  */
  _map(e, n, r) {
    let i = 0, s = this.inverted ? 2 : 1, o = this.inverted ? 1 : 2;
    for (let a = 0; a < this.ranges.length; a += 3) {
      let l = this.ranges[a] - (this.inverted ? i : 0);
      if (l > e)
        break;
      let c = this.ranges[a + s], d = this.ranges[a + o], u = l + c;
      if (e <= u) {
        let f = c ? e == l ? -1 : e == u ? 1 : n : n, p = l + i + (f < 0 ? 0 : d);
        if (r)
          return p;
        let h = e == (n < 0 ? l : u) ? null : Lh(a / 3, e - l), m = e == l ? Cu : e == u ? Su : Ki;
        return (n < 0 ? e != l : e != u) && (m |= Mu), new qo(p, m, h);
      }
      i += d - c;
    }
    return r ? e + i : new qo(e + i, 0, null);
  }
  /**
  @internal
  */
  touches(e, n) {
    let r = 0, i = Bl(n), s = this.inverted ? 2 : 1, o = this.inverted ? 1 : 2;
    for (let a = 0; a < this.ranges.length; a += 3) {
      let l = this.ranges[a] - (this.inverted ? r : 0);
      if (l > e)
        break;
      let c = this.ranges[a + s], d = l + c;
      if (e <= d && a == i * 3)
        return !0;
      r += this.ranges[a + o] - c;
    }
    return !1;
  }
  /**
  Calls the given function on each of the changed ranges included in
  this map.
  */
  forEach(e) {
    let n = this.inverted ? 2 : 1, r = this.inverted ? 1 : 2;
    for (let i = 0, s = 0; i < this.ranges.length; i += 3) {
      let o = this.ranges[i], a = o - (this.inverted ? s : 0), l = o + (this.inverted ? 0 : s), c = this.ranges[i + n], d = this.ranges[i + r];
      e(a, a + c, l, l + d), s += d - c;
    }
  }
  /**
  Create an inverted version of this map. The result can be used to
  map positions in the post-step document to the pre-step document.
  */
  invert() {
    return new ut(this.ranges, !this.inverted);
  }
  /**
  @internal
  */
  toString() {
    return (this.inverted ? "-" : "") + JSON.stringify(this.ranges);
  }
  /**
  Create a map that moves all positions by offset `n` (which may be
  negative). This can be useful when applying steps meant for a
  sub-document to a larger document, or vice-versa.
  */
  static offset(e) {
    return e == 0 ? ut.empty : new ut(e < 0 ? [0, -e, 0] : [0, 0, e]);
  }
}
ut.empty = new ut([]);
class pr {
  /**
  Create a new mapping with the given position maps.
  */
  constructor(e = [], n, r = 0, i = e.length) {
    this.maps = e, this.mirror = n, this.from = r, this.to = i;
  }
  /**
  Create a mapping that maps only through a part of this one.
  */
  slice(e = 0, n = this.maps.length) {
    return new pr(this.maps, this.mirror, e, n);
  }
  /**
  @internal
  */
  copy() {
    return new pr(this.maps.slice(), this.mirror && this.mirror.slice(), this.from, this.to);
  }
  /**
  Add a step map to the end of this mapping. If `mirrors` is
  given, it should be the index of the step map that is the mirror
  image of this one.
  */
  appendMap(e, n) {
    this.to = this.maps.push(e), n != null && this.setMirror(this.maps.length - 1, n);
  }
  /**
  Add all the step maps in a given mapping to this one (preserving
  mirroring information).
  */
  appendMapping(e) {
    for (let n = 0, r = this.maps.length; n < e.maps.length; n++) {
      let i = e.getMirror(n);
      this.appendMap(e.maps[n], i != null && i < n ? r + i : void 0);
    }
  }
  /**
  Finds the offset of the step map that mirrors the map at the
  given offset, in this mapping (as per the second argument to
  `appendMap`).
  */
  getMirror(e) {
    if (this.mirror) {
      for (let n = 0; n < this.mirror.length; n++)
        if (this.mirror[n] == e)
          return this.mirror[n + (n % 2 ? -1 : 1)];
    }
  }
  /**
  @internal
  */
  setMirror(e, n) {
    this.mirror || (this.mirror = []), this.mirror.push(e, n);
  }
  /**
  Append the inverse of the given mapping to this one.
  */
  appendMappingInverted(e) {
    for (let n = e.maps.length - 1, r = this.maps.length + e.maps.length; n >= 0; n--) {
      let i = e.getMirror(n);
      this.appendMap(e.maps[n].invert(), i != null && i > n ? r - i - 1 : void 0);
    }
  }
  /**
  Create an inverted version of this mapping.
  */
  invert() {
    let e = new pr();
    return e.appendMappingInverted(this), e;
  }
  /**
  Map a position through this mapping.
  */
  map(e, n = 1) {
    if (this.mirror)
      return this._map(e, n, !0);
    for (let r = this.from; r < this.to; r++)
      e = this.maps[r].map(e, n);
    return e;
  }
  /**
  Map a position through this mapping, returning a mapping
  result.
  */
  mapResult(e, n = 1) {
    return this._map(e, n, !1);
  }
  /**
  @internal
  */
  _map(e, n, r) {
    let i = 0;
    for (let s = this.from; s < this.to; s++) {
      let o = this.maps[s], a = o.mapResult(e, n);
      if (a.recover != null) {
        let l = this.getMirror(s);
        if (l != null && l > s && l < this.to) {
          s = l, e = this.maps[l].recover(a.recover);
          continue;
        }
      }
      i |= a.delInfo, e = a.pos;
    }
    return r ? e : new qo(e, i, null);
  }
}
const oo = /* @__PURE__ */ Object.create(null);
class Ge {
  /**
  Get the step map that represents the changes made by this step,
  and which can be used to transform between positions in the old
  and the new document.
  */
  getMap() {
    return ut.empty;
  }
  /**
  Try to merge this step with another one, to be applied directly
  after it. Returns the merged step when possible, null if the
  steps can't be merged.
  */
  merge(e) {
    return null;
  }
  /**
  Deserialize a step from its JSON representation. Will call
  through to the step class' own implementation of this method.
  */
  static fromJSON(e, n) {
    if (!n || !n.stepType)
      throw new RangeError("Invalid input for Step.fromJSON");
    let r = oo[n.stepType];
    if (!r)
      throw new RangeError(`No step type ${n.stepType} defined`);
    return r.fromJSON(e, n);
  }
  /**
  To be able to serialize steps to JSON, each step needs a string
  ID to attach to its JSON representation. Use this method to
  register an ID for your step classes. Try to pick something
  that's unlikely to clash with steps from other modules.
  */
  static jsonID(e, n) {
    if (e in oo)
      throw new RangeError("Duplicate use of step JSON ID " + e);
    return oo[e] = n, n.prototype.jsonID = e, n;
  }
}
class Re {
  /**
  @internal
  */
  constructor(e, n) {
    this.doc = e, this.failed = n;
  }
  /**
  Create a successful step result.
  */
  static ok(e) {
    return new Re(e, null);
  }
  /**
  Create a failed step result.
  */
  static fail(e) {
    return new Re(null, e);
  }
  /**
  Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given
  arguments. Create a successful result if it succeeds, and a
  failed one if it throws a `ReplaceError`.
  */
  static fromReplace(e, n, r, i) {
    try {
      return Re.ok(e.replace(n, r, i));
    } catch (s) {
      if (s instanceof Qi)
        return Re.fail(s.message);
      throw s;
    }
  }
}
function ka(t, e, n) {
  let r = [];
  for (let i = 0; i < t.childCount; i++) {
    let s = t.child(i);
    s.content.size && (s = s.copy(ka(s.content, e, s))), s.isInline && (s = e(s, n, i)), r.push(s);
  }
  return A.fromArray(r);
}
class an extends Ge {
  /**
  Create a mark step.
  */
  constructor(e, n, r) {
    super(), this.from = e, this.to = n, this.mark = r;
  }
  apply(e) {
    let n = e.slice(this.from, this.to), r = e.resolve(this.from), i = r.node(r.sharedDepth(this.to)), s = new B(ka(n.content, (o, a) => !o.isAtom || !a.type.allowsMarkType(this.mark.type) ? o : o.mark(this.mark.addToSet(o.marks)), i), n.openStart, n.openEnd);
    return Re.fromReplace(e, this.from, this.to, s);
  }
  invert() {
    return new Bt(this.from, this.to, this.mark);
  }
  map(e) {
    let n = e.mapResult(this.from, 1), r = e.mapResult(this.to, -1);
    return n.deleted && r.deleted || n.pos >= r.pos ? null : new an(n.pos, r.pos, this.mark);
  }
  merge(e) {
    return e instanceof an && e.mark.eq(this.mark) && this.from <= e.to && this.to >= e.from ? new an(Math.min(this.from, e.from), Math.max(this.to, e.to), this.mark) : null;
  }
  toJSON() {
    return {
      stepType: "addMark",
      mark: this.mark.toJSON(),
      from: this.from,
      to: this.to
    };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.from != "number" || typeof n.to != "number")
      throw new RangeError("Invalid input for AddMarkStep.fromJSON");
    return new an(n.from, n.to, e.markFromJSON(n.mark));
  }
}
Ge.jsonID("addMark", an);
class Bt extends Ge {
  /**
  Create a mark-removing step.
  */
  constructor(e, n, r) {
    super(), this.from = e, this.to = n, this.mark = r;
  }
  apply(e) {
    let n = e.slice(this.from, this.to), r = new B(ka(n.content, (i) => i.mark(this.mark.removeFromSet(i.marks)), e), n.openStart, n.openEnd);
    return Re.fromReplace(e, this.from, this.to, r);
  }
  invert() {
    return new an(this.from, this.to, this.mark);
  }
  map(e) {
    let n = e.mapResult(this.from, 1), r = e.mapResult(this.to, -1);
    return n.deleted && r.deleted || n.pos >= r.pos ? null : new Bt(n.pos, r.pos, this.mark);
  }
  merge(e) {
    return e instanceof Bt && e.mark.eq(this.mark) && this.from <= e.to && this.to >= e.from ? new Bt(Math.min(this.from, e.from), Math.max(this.to, e.to), this.mark) : null;
  }
  toJSON() {
    return {
      stepType: "removeMark",
      mark: this.mark.toJSON(),
      from: this.from,
      to: this.to
    };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.from != "number" || typeof n.to != "number")
      throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");
    return new Bt(n.from, n.to, e.markFromJSON(n.mark));
  }
}
Ge.jsonID("removeMark", Bt);
class ln extends Ge {
  /**
  Create a node mark step.
  */
  constructor(e, n) {
    super(), this.pos = e, this.mark = n;
  }
  apply(e) {
    let n = e.nodeAt(this.pos);
    if (!n)
      return Re.fail("No node at mark step's position");
    let r = n.type.create(n.attrs, null, this.mark.addToSet(n.marks));
    return Re.fromReplace(e, this.pos, this.pos + 1, new B(A.from(r), 0, n.isLeaf ? 0 : 1));
  }
  invert(e) {
    let n = e.nodeAt(this.pos);
    if (n) {
      let r = this.mark.addToSet(n.marks);
      if (r.length == n.marks.length) {
        for (let i = 0; i < n.marks.length; i++)
          if (!n.marks[i].isInSet(r))
            return new ln(this.pos, n.marks[i]);
        return new ln(this.pos, this.mark);
      }
    }
    return new yr(this.pos, this.mark);
  }
  map(e) {
    let n = e.mapResult(this.pos, 1);
    return n.deletedAfter ? null : new ln(n.pos, this.mark);
  }
  toJSON() {
    return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.pos != "number")
      throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");
    return new ln(n.pos, e.markFromJSON(n.mark));
  }
}
Ge.jsonID("addNodeMark", ln);
class yr extends Ge {
  /**
  Create a mark-removing step.
  */
  constructor(e, n) {
    super(), this.pos = e, this.mark = n;
  }
  apply(e) {
    let n = e.nodeAt(this.pos);
    if (!n)
      return Re.fail("No node at mark step's position");
    let r = n.type.create(n.attrs, null, this.mark.removeFromSet(n.marks));
    return Re.fromReplace(e, this.pos, this.pos + 1, new B(A.from(r), 0, n.isLeaf ? 0 : 1));
  }
  invert(e) {
    let n = e.nodeAt(this.pos);
    return !n || !this.mark.isInSet(n.marks) ? this : new ln(this.pos, this.mark);
  }
  map(e) {
    let n = e.mapResult(this.pos, 1);
    return n.deletedAfter ? null : new yr(n.pos, this.mark);
  }
  toJSON() {
    return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.pos != "number")
      throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");
    return new yr(n.pos, e.markFromJSON(n.mark));
  }
}
Ge.jsonID("removeNodeMark", yr);
class ze extends Ge {
  /**
  The given `slice` should fit the 'gap' between `from` and
  `to`—the depths must line up, and the surrounding nodes must be
  able to be joined with the open sides of the slice. When
  `structure` is true, the step will fail if the content between
  from and to is not just a sequence of closing and then opening
  tokens (this is to guard against rebased replace steps
  overwriting something they weren't supposed to).
  */
  constructor(e, n, r, i = !1) {
    super(), this.from = e, this.to = n, this.slice = r, this.structure = i;
  }
  apply(e) {
    return this.structure && Zo(e, this.from, this.to) ? Re.fail("Structure replace would overwrite content") : Re.fromReplace(e, this.from, this.to, this.slice);
  }
  getMap() {
    return new ut([this.from, this.to - this.from, this.slice.size]);
  }
  invert(e) {
    return new ze(this.from, this.from + this.slice.size, e.slice(this.from, this.to));
  }
  map(e) {
    let n = e.mapResult(this.from, 1), r = e.mapResult(this.to, -1);
    return n.deletedAcross && r.deletedAcross ? null : new ze(n.pos, Math.max(n.pos, r.pos), this.slice);
  }
  merge(e) {
    if (!(e instanceof ze) || e.structure || this.structure)
      return null;
    if (this.from + this.slice.size == e.from && !this.slice.openEnd && !e.slice.openStart) {
      let n = this.slice.size + e.slice.size == 0 ? B.empty : new B(this.slice.content.append(e.slice.content), this.slice.openStart, e.slice.openEnd);
      return new ze(this.from, this.to + (e.to - e.from), n, this.structure);
    } else if (e.to == this.from && !this.slice.openStart && !e.slice.openEnd) {
      let n = this.slice.size + e.slice.size == 0 ? B.empty : new B(e.slice.content.append(this.slice.content), e.slice.openStart, this.slice.openEnd);
      return new ze(e.from, this.to, n, this.structure);
    } else
      return null;
  }
  toJSON() {
    let e = { stepType: "replace", from: this.from, to: this.to };
    return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.from != "number" || typeof n.to != "number")
      throw new RangeError("Invalid input for ReplaceStep.fromJSON");
    return new ze(n.from, n.to, B.fromJSON(e, n.slice), !!n.structure);
  }
}
Ge.jsonID("replace", ze);
class De extends Ge {
  /**
  Create a replace-around step with the given range and gap.
  `insert` should be the point in the slice into which the content
  of the gap should be moved. `structure` has the same meaning as
  it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.
  */
  constructor(e, n, r, i, s, o, a = !1) {
    super(), this.from = e, this.to = n, this.gapFrom = r, this.gapTo = i, this.slice = s, this.insert = o, this.structure = a;
  }
  apply(e) {
    if (this.structure && (Zo(e, this.from, this.gapFrom) || Zo(e, this.gapTo, this.to)))
      return Re.fail("Structure gap-replace would overwrite content");
    let n = e.slice(this.gapFrom, this.gapTo);
    if (n.openStart || n.openEnd)
      return Re.fail("Gap is not a flat range");
    let r = this.slice.insertAt(this.insert, n.content);
    return r ? Re.fromReplace(e, this.from, this.to, r) : Re.fail("Content does not fit in gap");
  }
  getMap() {
    return new ut([
      this.from,
      this.gapFrom - this.from,
      this.insert,
      this.gapTo,
      this.to - this.gapTo,
      this.slice.size - this.insert
    ]);
  }
  invert(e) {
    let n = this.gapTo - this.gapFrom;
    return new De(this.from, this.from + this.slice.size + n, this.from + this.insert, this.from + this.insert + n, e.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
  }
  map(e) {
    let n = e.mapResult(this.from, 1), r = e.mapResult(this.to, -1), i = e.map(this.gapFrom, -1), s = e.map(this.gapTo, 1);
    return n.deletedAcross && r.deletedAcross || i < n.pos || s > r.pos ? null : new De(n.pos, r.pos, i, s, this.slice, this.insert, this.structure);
  }
  toJSON() {
    let e = {
      stepType: "replaceAround",
      from: this.from,
      to: this.to,
      gapFrom: this.gapFrom,
      gapTo: this.gapTo,
      insert: this.insert
    };
    return this.slice.size && (e.slice = this.slice.toJSON()), this.structure && (e.structure = !0), e;
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.from != "number" || typeof n.to != "number" || typeof n.gapFrom != "number" || typeof n.gapTo != "number" || typeof n.insert != "number")
      throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
    return new De(n.from, n.to, n.gapFrom, n.gapTo, B.fromJSON(e, n.slice), n.insert, !!n.structure);
  }
}
Ge.jsonID("replaceAround", De);
function Zo(t, e, n) {
  let r = t.resolve(e), i = n - e, s = r.depth;
  for (; i > 0 && s > 0 && r.indexAfter(s) == r.node(s).childCount; )
    s--, i--;
  if (i > 0) {
    let o = r.node(s).maybeChild(r.indexAfter(s));
    for (; i > 0; ) {
      if (!o || o.isLeaf)
        return !0;
      o = o.firstChild, i--;
    }
  }
  return !1;
}
function Dh(t, e, n, r) {
  let i = [], s = [], o, a;
  t.doc.nodesBetween(e, n, (l, c, d) => {
    if (!l.isInline)
      return;
    let u = l.marks;
    if (!r.isInSet(u) && d.type.allowsMarkType(r.type)) {
      let f = Math.max(c, e), p = Math.min(c + l.nodeSize, n), h = r.addToSet(u);
      for (let m = 0; m < u.length; m++)
        u[m].isInSet(h) || (o && o.to == f && o.mark.eq(u[m]) ? o.to = p : i.push(o = new Bt(f, p, u[m])));
      a && a.to == f ? a.to = p : s.push(a = new an(f, p, r));
    }
  }), i.forEach((l) => t.step(l)), s.forEach((l) => t.step(l));
}
function Hh(t, e, n, r) {
  let i = [], s = 0;
  t.doc.nodesBetween(e, n, (o, a) => {
    if (!o.isInline)
      return;
    s++;
    let l = null;
    if (r instanceof Is) {
      let c = o.marks, d;
      for (; d = r.isInSet(c); )
        (l || (l = [])).push(d), c = d.removeFromSet(c);
    } else
      r ? r.isInSet(o.marks) && (l = [r]) : l = o.marks;
    if (l && l.length) {
      let c = Math.min(a + o.nodeSize, n);
      for (let d = 0; d < l.length; d++) {
        let u = l[d], f;
        for (let p = 0; p < i.length; p++) {
          let h = i[p];
          h.step == s - 1 && u.eq(i[p].style) && (f = h);
        }
        f ? (f.to = c, f.step = s) : i.push({ style: u, from: Math.max(a, e), to: c, step: s });
      }
    }
  }), i.forEach((o) => t.step(new Bt(o.from, o.to, o.style)));
}
function Bh(t, e, n, r = n.contentMatch) {
  let i = t.doc.nodeAt(e), s = [], o = e + 1;
  for (let a = 0; a < i.childCount; a++) {
    let l = i.child(a), c = o + l.nodeSize, d = r.matchType(l.type);
    if (!d)
      s.push(new ze(o, c, B.empty));
    else {
      r = d;
      for (let u = 0; u < l.marks.length; u++)
        n.allowsMarkType(l.marks[u].type) || t.step(new Bt(o, c, l.marks[u]));
      if (l.isText && !n.spec.code) {
        let u, f = /\r?\n|\r/g, p;
        for (; u = f.exec(l.text); )
          p || (p = new B(A.from(n.schema.text(" ", n.allowedMarks(l.marks))), 0, 0)), s.push(new ze(o + u.index, o + u.index + u[0].length, p));
      }
    }
    o = c;
  }
  if (!r.validEnd) {
    let a = r.fillBefore(A.empty, !0);
    t.replace(o, o, new B(a, 0, 0));
  }
  for (let a = s.length - 1; a >= 0; a--)
    t.step(s[a]);
}
function Ph(t, e, n) {
  return (e == 0 || t.canReplace(e, t.childCount)) && (n == t.childCount || t.canReplace(0, n));
}
function Ar(t) {
  let n = t.parent.content.cutByIndex(t.startIndex, t.endIndex);
  for (let r = t.depth; ; --r) {
    let i = t.$from.node(r), s = t.$from.index(r), o = t.$to.indexAfter(r);
    if (r < t.depth && i.canReplace(s, o, n))
      return r;
    if (r == 0 || i.type.spec.isolating || !Ph(i, s, o))
      break;
  }
  return null;
}
function $h(t, e, n) {
  let { $from: r, $to: i, depth: s } = e, o = r.before(s + 1), a = i.after(s + 1), l = o, c = a, d = A.empty, u = 0;
  for (let h = s, m = !1; h > n; h--)
    m || r.index(h) > 0 ? (m = !0, d = A.from(r.node(h).copy(d)), u++) : l--;
  let f = A.empty, p = 0;
  for (let h = s, m = !1; h > n; h--)
    m || i.after(h + 1) < i.end(h) ? (m = !0, f = A.from(i.node(h).copy(f)), p++) : c++;
  t.step(new De(l, c, o, a, new B(d.append(f), u, p), d.size - u, !0));
}
function Ta(t, e, n = null, r = t) {
  let i = Vh(t, e), s = i && zh(r, e);
  return s ? i.map(Pl).concat({ type: e, attrs: n }).concat(s.map(Pl)) : null;
}
function Pl(t) {
  return { type: t, attrs: null };
}
function Vh(t, e) {
  let { parent: n, startIndex: r, endIndex: i } = t, s = n.contentMatchAt(r).findWrapping(e);
  if (!s)
    return null;
  let o = s.length ? s[0] : e;
  return n.canReplaceWith(r, i, o) ? s : null;
}
function zh(t, e) {
  let { parent: n, startIndex: r, endIndex: i } = t, s = n.child(r), o = e.contentMatch.findWrapping(s.type);
  if (!o)
    return null;
  let l = (o.length ? o[o.length - 1] : e).contentMatch;
  for (let c = r; l && c < i; c++)
    l = l.matchType(n.child(c).type);
  return !l || !l.validEnd ? null : o;
}
function Fh(t, e, n) {
  let r = A.empty;
  for (let o = n.length - 1; o >= 0; o--) {
    if (r.size) {
      let a = n[o].type.contentMatch.matchFragment(r);
      if (!a || !a.validEnd)
        throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper");
    }
    r = A.from(n[o].type.create(n[o].attrs, r));
  }
  let i = e.start, s = e.end;
  t.step(new De(i, s, i, s, new B(r, 0, 0), n.length, !0));
}
function Uh(t, e, n, r, i) {
  if (!r.isTextblock)
    throw new RangeError("Type given to setBlockType should be a textblock");
  let s = t.steps.length;
  t.doc.nodesBetween(e, n, (o, a) => {
    if (o.isTextblock && !o.hasMarkup(r, i) && Kh(t.doc, t.mapping.slice(s).map(a), r)) {
      t.clearIncompatible(t.mapping.slice(s).map(a, 1), r);
      let l = t.mapping.slice(s), c = l.map(a, 1), d = l.map(a + o.nodeSize, 1);
      return t.step(new De(c, d, c + 1, d - 1, new B(A.from(r.create(i, null, o.marks)), 0, 0), 1, !0)), !1;
    }
  });
}
function Kh(t, e, n) {
  let r = t.resolve(e), i = r.index();
  return r.parent.canReplaceWith(i, i + 1, n);
}
function Wh(t, e, n, r, i) {
  let s = t.doc.nodeAt(e);
  if (!s)
    throw new RangeError("No node at given position");
  n || (n = s.type);
  let o = n.create(r, null, i || s.marks);
  if (s.isLeaf)
    return t.replaceWith(e, e + s.nodeSize, o);
  if (!n.validContent(s.content))
    throw new RangeError("Invalid content for node type " + n.name);
  t.step(new De(e, e + s.nodeSize, e + 1, e + s.nodeSize - 1, new B(A.from(o), 0, 0), 1, !0));
}
function hr(t, e, n = 1, r) {
  let i = t.resolve(e), s = i.depth - n, o = r && r[r.length - 1] || i.parent;
  if (s < 0 || i.parent.type.spec.isolating || !i.parent.canReplace(i.index(), i.parent.childCount) || !o.type.validContent(i.parent.content.cutByIndex(i.index(), i.parent.childCount)))
    return !1;
  for (let c = i.depth - 1, d = n - 2; c > s; c--, d--) {
    let u = i.node(c), f = i.index(c);
    if (u.type.spec.isolating)
      return !1;
    let p = u.content.cutByIndex(f, u.childCount), h = r && r[d + 1];
    h && (p = p.replaceChild(0, h.type.create(h.attrs)));
    let m = r && r[d] || u;
    if (!u.canReplace(f + 1, u.childCount) || !m.type.validContent(p))
      return !1;
  }
  let a = i.indexAfter(s), l = r && r[0];
  return i.node(s).canReplaceWith(a, a, l ? l.type : i.node(s + 1).type);
}
function qh(t, e, n = 1, r) {
  let i = t.doc.resolve(e), s = A.empty, o = A.empty;
  for (let a = i.depth, l = i.depth - n, c = n - 1; a > l; a--, c--) {
    s = A.from(i.node(a).copy(s));
    let d = r && r[c];
    o = A.from(d ? d.type.create(d.attrs, o) : i.node(a).copy(o));
  }
  t.step(new ze(e, e, new B(s.append(o), n, n), !0));
}
function vn(t, e) {
  let n = t.resolve(e), r = n.index();
  return ku(n.nodeBefore, n.nodeAfter) && n.parent.canReplace(r, r + 1);
}
function ku(t, e) {
  return !!(t && e && !t.isLeaf && t.canAppend(e));
}
function Ds(t, e, n = -1) {
  let r = t.resolve(e);
  for (let i = r.depth; ; i--) {
    let s, o, a = r.index(i);
    if (i == r.depth ? (s = r.nodeBefore, o = r.nodeAfter) : n > 0 ? (s = r.node(i + 1), a++, o = r.node(i).maybeChild(a)) : (s = r.node(i).maybeChild(a - 1), o = r.node(i + 1)), s && !s.isTextblock && ku(s, o) && r.node(i).canReplace(a, a + 1))
      return e;
    if (i == 0)
      break;
    e = n < 0 ? r.before(i) : r.after(i);
  }
}
function Zh(t, e, n) {
  let r = new ze(e - n, e + n, B.empty, !0);
  t.step(r);
}
function Gh(t, e, n) {
  let r = t.resolve(e);
  if (r.parent.canReplaceWith(r.index(), r.index(), n))
    return e;
  if (r.parentOffset == 0)
    for (let i = r.depth - 1; i >= 0; i--) {
      let s = r.index(i);
      if (r.node(i).canReplaceWith(s, s, n))
        return r.before(i + 1);
      if (s > 0)
        return null;
    }
  if (r.parentOffset == r.parent.content.size)
    for (let i = r.depth - 1; i >= 0; i--) {
      let s = r.indexAfter(i);
      if (r.node(i).canReplaceWith(s, s, n))
        return r.after(i + 1);
      if (s < r.node(i).childCount)
        return null;
    }
  return null;
}
function Tu(t, e, n) {
  let r = t.resolve(e);
  if (!n.content.size)
    return e;
  let i = n.content;
  for (let s = 0; s < n.openStart; s++)
    i = i.firstChild.content;
  for (let s = 1; s <= (n.openStart == 0 && n.size ? 2 : 1); s++)
    for (let o = r.depth; o >= 0; o--) {
      let a = o == r.depth ? 0 : r.pos <= (r.start(o + 1) + r.end(o + 1)) / 2 ? -1 : 1, l = r.index(o) + (a > 0 ? 1 : 0), c = r.node(o), d = !1;
      if (s == 1)
        d = c.canReplace(l, l, i);
      else {
        let u = c.contentMatchAt(l).findWrapping(i.firstChild.type);
        d = u && c.canReplaceWith(l, l, u[0]);
      }
      if (d)
        return a == 0 ? r.pos : a < 0 ? r.before(o + 1) : r.after(o + 1);
    }
  return null;
}
function _a(t, e, n = e, r = B.empty) {
  if (e == n && !r.size)
    return null;
  let i = t.resolve(e), s = t.resolve(n);
  return _u(i, s, r) ? new ze(e, n, r) : new jh(i, s, r).fit();
}
function _u(t, e, n) {
  return !n.openStart && !n.openEnd && t.start() == e.start() && t.parent.canReplace(t.index(), e.index(), n.content);
}
class jh {
  constructor(e, n, r) {
    this.$from = e, this.$to = n, this.unplaced = r, this.frontier = [], this.placed = A.empty;
    for (let i = 0; i <= e.depth; i++) {
      let s = e.node(i);
      this.frontier.push({
        type: s.type,
        match: s.contentMatchAt(e.indexAfter(i))
      });
    }
    for (let i = e.depth; i > 0; i--)
      this.placed = A.from(e.node(i).copy(this.placed));
  }
  get depth() {
    return this.frontier.length - 1;
  }
  fit() {
    for (; this.unplaced.size; ) {
      let c = this.findFittable();
      c ? this.placeNodes(c) : this.openMore() || this.dropNode();
    }
    let e = this.mustMoveInline(), n = this.placed.size - this.depth - this.$from.depth, r = this.$from, i = this.close(e < 0 ? this.$to : r.doc.resolve(e));
    if (!i)
      return null;
    let s = this.placed, o = r.depth, a = i.depth;
    for (; o && a && s.childCount == 1; )
      s = s.firstChild.content, o--, a--;
    let l = new B(s, o, a);
    return e > -1 ? new De(r.pos, e, this.$to.pos, this.$to.end(), l, n) : l.size || r.pos != this.$to.pos ? new ze(r.pos, i.pos, l) : null;
  }
  // Find a position on the start spine of `this.unplaced` that has
  // content that can be moved somewhere on the frontier. Returns two
  // depths, one for the slice and one for the frontier.
  findFittable() {
    let e = this.unplaced.openStart;
    for (let n = this.unplaced.content, r = 0, i = this.unplaced.openEnd; r < e; r++) {
      let s = n.firstChild;
      if (n.childCount > 1 && (i = 0), s.type.spec.isolating && i <= r) {
        e = r;
        break;
      }
      n = s.content;
    }
    for (let n = 1; n <= 2; n++)
      for (let r = n == 1 ? e : this.unplaced.openStart; r >= 0; r--) {
        let i, s = null;
        r ? (s = ao(this.unplaced.content, r - 1).firstChild, i = s.content) : i = this.unplaced.content;
        let o = i.firstChild;
        for (let a = this.depth; a >= 0; a--) {
          let { type: l, match: c } = this.frontier[a], d, u = null;
          if (n == 1 && (o ? c.matchType(o.type) || (u = c.fillBefore(A.from(o), !1)) : s && l.compatibleContent(s.type)))
            return { sliceDepth: r, frontierDepth: a, parent: s, inject: u };
          if (n == 2 && o && (d = c.findWrapping(o.type)))
            return { sliceDepth: r, frontierDepth: a, parent: s, wrap: d };
          if (s && c.matchType(s.type))
            break;
        }
      }
  }
  openMore() {
    let { content: e, openStart: n, openEnd: r } = this.unplaced, i = ao(e, n);
    return !i.childCount || i.firstChild.isLeaf ? !1 : (this.unplaced = new B(e, n + 1, Math.max(r, i.size + n >= e.size - r ? n + 1 : 0)), !0);
  }
  dropNode() {
    let { content: e, openStart: n, openEnd: r } = this.unplaced, i = ao(e, n);
    if (i.childCount <= 1 && n > 0) {
      let s = e.size - n <= n + i.size;
      this.unplaced = new B(Pr(e, n - 1, 1), n - 1, s ? n - 1 : r);
    } else
      this.unplaced = new B(Pr(e, n, 1), n, r);
  }
  // Move content from the unplaced slice at `sliceDepth` to the
  // frontier node at `frontierDepth`. Close that frontier node when
  // applicable.
  placeNodes({ sliceDepth: e, frontierDepth: n, parent: r, inject: i, wrap: s }) {
    for (; this.depth > n; )
      this.closeFrontierNode();
    if (s)
      for (let m = 0; m < s.length; m++)
        this.openFrontierNode(s[m]);
    let o = this.unplaced, a = r ? r.content : o.content, l = o.openStart - e, c = 0, d = [], { match: u, type: f } = this.frontier[n];
    if (i) {
      for (let m = 0; m < i.childCount; m++)
        d.push(i.child(m));
      u = u.matchFragment(i);
    }
    let p = a.size + e - (o.content.size - o.openEnd);
    for (; c < a.childCount; ) {
      let m = a.child(c), g = u.matchType(m.type);
      if (!g)
        break;
      c++, (c > 1 || l == 0 || m.content.size) && (u = g, d.push(Nu(m.mark(f.allowedMarks(m.marks)), c == 1 ? l : 0, c == a.childCount ? p : -1)));
    }
    let h = c == a.childCount;
    h || (p = -1), this.placed = $r(this.placed, n, A.from(d)), this.frontier[n].match = u, h && p < 0 && r && r.type == this.frontier[this.depth].type && this.frontier.length > 1 && this.closeFrontierNode();
    for (let m = 0, g = a; m < p; m++) {
      let v = g.lastChild;
      this.frontier.push({ type: v.type, match: v.contentMatchAt(v.childCount) }), g = v.content;
    }
    this.unplaced = h ? e == 0 ? B.empty : new B(Pr(o.content, e - 1, 1), e - 1, p < 0 ? o.openEnd : e - 1) : new B(Pr(o.content, e, c), o.openStart, o.openEnd);
  }
  mustMoveInline() {
    if (!this.$to.parent.isTextblock)
      return -1;
    let e = this.frontier[this.depth], n;
    if (!e.type.isTextblock || !lo(this.$to, this.$to.depth, e.type, e.match, !1) || this.$to.depth == this.depth && (n = this.findCloseLevel(this.$to)) && n.depth == this.depth)
      return -1;
    let { depth: r } = this.$to, i = this.$to.after(r);
    for (; r > 1 && i == this.$to.end(--r); )
      ++i;
    return i;
  }
  findCloseLevel(e) {
    e:
      for (let n = Math.min(this.depth, e.depth); n >= 0; n--) {
        let { match: r, type: i } = this.frontier[n], s = n < e.depth && e.end(n + 1) == e.pos + (e.depth - (n + 1)), o = lo(e, n, i, r, s);
        if (o) {
          for (let a = n - 1; a >= 0; a--) {
            let { match: l, type: c } = this.frontier[a], d = lo(e, a, c, l, !0);
            if (!d || d.childCount)
              continue e;
          }
          return { depth: n, fit: o, move: s ? e.doc.resolve(e.after(n + 1)) : e };
        }
      }
  }
  close(e) {
    let n = this.findCloseLevel(e);
    if (!n)
      return null;
    for (; this.depth > n.depth; )
      this.closeFrontierNode();
    n.fit.childCount && (this.placed = $r(this.placed, n.depth, n.fit)), e = n.move;
    for (let r = n.depth + 1; r <= e.depth; r++) {
      let i = e.node(r), s = i.type.contentMatch.fillBefore(i.content, !0, e.index(r));
      this.openFrontierNode(i.type, i.attrs, s);
    }
    return e;
  }
  openFrontierNode(e, n = null, r) {
    let i = this.frontier[this.depth];
    i.match = i.match.matchType(e), this.placed = $r(this.placed, this.depth, A.from(e.create(n, r))), this.frontier.push({ type: e, match: e.contentMatch });
  }
  closeFrontierNode() {
    let n = this.frontier.pop().match.fillBefore(A.empty, !0);
    n.childCount && (this.placed = $r(this.placed, this.frontier.length, n));
  }
}
function Pr(t, e, n) {
  return e == 0 ? t.cutByIndex(n, t.childCount) : t.replaceChild(0, t.firstChild.copy(Pr(t.firstChild.content, e - 1, n)));
}
function $r(t, e, n) {
  return e == 0 ? t.append(n) : t.replaceChild(t.childCount - 1, t.lastChild.copy($r(t.lastChild.content, e - 1, n)));
}
function ao(t, e) {
  for (let n = 0; n < e; n++)
    t = t.firstChild.content;
  return t;
}
function Nu(t, e, n) {
  if (e <= 0)
    return t;
  let r = t.content;
  return e > 1 && (r = r.replaceChild(0, Nu(r.firstChild, e - 1, r.childCount == 1 ? n - 1 : 0))), e > 0 && (r = t.type.contentMatch.fillBefore(r).append(r), n <= 0 && (r = r.append(t.type.contentMatch.matchFragment(r).fillBefore(A.empty, !0)))), t.copy(r);
}
function lo(t, e, n, r, i) {
  let s = t.node(e), o = i ? t.indexAfter(e) : t.index(e);
  if (o == s.childCount && !n.compatibleContent(s.type))
    return null;
  let a = r.fillBefore(s.content, !0, o);
  return a && !Yh(n, s.content, o) ? a : null;
}
function Yh(t, e, n) {
  for (let r = n; r < e.childCount; r++)
    if (!t.allowsMarks(e.child(r).marks))
      return !0;
  return !1;
}
function Jh(t) {
  return t.spec.defining || t.spec.definingForContent;
}
function Xh(t, e, n, r) {
  if (!r.size)
    return t.deleteRange(e, n);
  let i = t.doc.resolve(e), s = t.doc.resolve(n);
  if (_u(i, s, r))
    return t.step(new ze(e, n, r));
  let o = Ou(i, t.doc.resolve(n));
  o[o.length - 1] == 0 && o.pop();
  let a = -(i.depth + 1);
  o.unshift(a);
  for (let f = i.depth, p = i.pos - 1; f > 0; f--, p--) {
    let h = i.node(f).type.spec;
    if (h.defining || h.definingAsContext || h.isolating)
      break;
    o.indexOf(f) > -1 ? a = f : i.before(f) == p && o.splice(1, 0, -f);
  }
  let l = o.indexOf(a), c = [], d = r.openStart;
  for (let f = r.content, p = 0; ; p++) {
    let h = f.firstChild;
    if (c.push(h), p == r.openStart)
      break;
    f = h.content;
  }
  for (let f = d - 1; f >= 0; f--) {
    let p = c[f], h = Jh(p.type);
    if (h && !p.sameMarkup(i.node(Math.abs(a) - 1)))
      d = f;
    else if (h || !p.type.isTextblock)
      break;
  }
  for (let f = r.openStart; f >= 0; f--) {
    let p = (f + d + 1) % (r.openStart + 1), h = c[p];
    if (h)
      for (let m = 0; m < o.length; m++) {
        let g = o[(m + l) % o.length], v = !0;
        g < 0 && (v = !1, g = -g);
        let y = i.node(g - 1), E = i.index(g - 1);
        if (y.canReplaceWith(E, E, h.type, h.marks))
          return t.replace(i.before(g), v ? s.after(g) : n, new B(Au(r.content, 0, r.openStart, p), p, r.openEnd));
      }
  }
  let u = t.steps.length;
  for (let f = o.length - 1; f >= 0 && (t.replace(e, n, r), !(t.steps.length > u)); f--) {
    let p = o[f];
    p < 0 || (e = i.before(p), n = s.after(p));
  }
}
function Au(t, e, n, r, i) {
  if (e < n) {
    let s = t.firstChild;
    t = t.replaceChild(0, s.copy(Au(s.content, e + 1, n, r, s)));
  }
  if (e > r) {
    let s = i.contentMatchAt(0), o = s.fillBefore(t).append(t);
    t = o.append(s.matchFragment(o).fillBefore(A.empty, !0));
  }
  return t;
}
function Qh(t, e, n, r) {
  if (!r.isInline && e == n && t.doc.resolve(e).parent.content.size) {
    let i = Gh(t.doc, e, r.type);
    i != null && (e = n = i);
  }
  t.replaceRange(e, n, new B(A.from(r), 0, 0));
}
function em(t, e, n) {
  let r = t.doc.resolve(e), i = t.doc.resolve(n), s = Ou(r, i);
  for (let o = 0; o < s.length; o++) {
    let a = s[o], l = o == s.length - 1;
    if (l && a == 0 || r.node(a).type.contentMatch.validEnd)
      return t.delete(r.start(a), i.end(a));
    if (a > 0 && (l || r.node(a - 1).canReplace(r.index(a - 1), i.indexAfter(a - 1))))
      return t.delete(r.before(a), i.after(a));
  }
  for (let o = 1; o <= r.depth && o <= i.depth; o++)
    if (e - r.start(o) == r.depth - o && n > r.end(o) && i.end(o) - n != i.depth - o)
      return t.delete(r.before(o), n);
  t.delete(e, n);
}
function Ou(t, e) {
  let n = [], r = Math.min(t.depth, e.depth);
  for (let i = r; i >= 0; i--) {
    let s = t.start(i);
    if (s < t.pos - (t.depth - i) || e.end(i) > e.pos + (e.depth - i) || t.node(i).type.spec.isolating || e.node(i).type.spec.isolating)
      break;
    (s == e.start(i) || i == t.depth && i == e.depth && t.parent.inlineContent && e.parent.inlineContent && i && e.start(i - 1) == s - 1) && n.push(i);
  }
  return n;
}
class mr extends Ge {
  /**
  Construct an attribute step.
  */
  constructor(e, n, r) {
    super(), this.pos = e, this.attr = n, this.value = r;
  }
  apply(e) {
    let n = e.nodeAt(this.pos);
    if (!n)
      return Re.fail("No node at attribute step's position");
    let r = /* @__PURE__ */ Object.create(null);
    for (let s in n.attrs)
      r[s] = n.attrs[s];
    r[this.attr] = this.value;
    let i = n.type.create(r, null, n.marks);
    return Re.fromReplace(e, this.pos, this.pos + 1, new B(A.from(i), 0, n.isLeaf ? 0 : 1));
  }
  getMap() {
    return ut.empty;
  }
  invert(e) {
    return new mr(this.pos, this.attr, e.nodeAt(this.pos).attrs[this.attr]);
  }
  map(e) {
    let n = e.mapResult(this.pos, 1);
    return n.deletedAfter ? null : new mr(n.pos, this.attr, this.value);
  }
  toJSON() {
    return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value };
  }
  static fromJSON(e, n) {
    if (typeof n.pos != "number" || typeof n.attr != "string")
      throw new RangeError("Invalid input for AttrStep.fromJSON");
    return new mr(n.pos, n.attr, n.value);
  }
}
Ge.jsonID("attr", mr);
class Qr extends Ge {
  /**
  Construct an attribute step.
  */
  constructor(e, n) {
    super(), this.attr = e, this.value = n;
  }
  apply(e) {
    let n = /* @__PURE__ */ Object.create(null);
    for (let i in e.attrs)
      n[i] = e.attrs[i];
    n[this.attr] = this.value;
    let r = e.type.create(n, e.content, e.marks);
    return Re.ok(r);
  }
  getMap() {
    return ut.empty;
  }
  invert(e) {
    return new Qr(this.attr, e.attrs[this.attr]);
  }
  map(e) {
    return this;
  }
  toJSON() {
    return { stepType: "docAttr", attr: this.attr, value: this.value };
  }
  static fromJSON(e, n) {
    if (typeof n.attr != "string")
      throw new RangeError("Invalid input for DocAttrStep.fromJSON");
    return new Qr(n.attr, n.value);
  }
}
Ge.jsonID("docAttr", Qr);
let vr = class extends Error {
};
vr = function t(e) {
  let n = Error.call(this, e);
  return n.__proto__ = t.prototype, n;
};
vr.prototype = Object.create(Error.prototype);
vr.prototype.constructor = vr;
vr.prototype.name = "TransformError";
class Na {
  /**
  Create a transform that starts with the given document.
  */
  constructor(e) {
    this.doc = e, this.steps = [], this.docs = [], this.mapping = new pr();
  }
  /**
  The starting document.
  */
  get before() {
    return this.docs.length ? this.docs[0] : this.doc;
  }
  /**
  Apply a new step in this transform, saving the result. Throws an
  error when the step fails.
  */
  step(e) {
    let n = this.maybeStep(e);
    if (n.failed)
      throw new vr(n.failed);
    return this;
  }
  /**
  Try to apply a step in this transformation, ignoring it if it
  fails. Returns the step result.
  */
  maybeStep(e) {
    let n = e.apply(this.doc);
    return n.failed || this.addStep(e, n.doc), n;
  }
  /**
  True when the document has been changed (when there are any
  steps).
  */
  get docChanged() {
    return this.steps.length > 0;
  }
  /**
  @internal
  */
  addStep(e, n) {
    this.docs.push(this.doc), this.steps.push(e), this.mapping.appendMap(e.getMap()), this.doc = n;
  }
  /**
  Replace the part of the document between `from` and `to` with the
  given `slice`.
  */
  replace(e, n = e, r = B.empty) {
    let i = _a(this.doc, e, n, r);
    return i && this.step(i), this;
  }
  /**
  Replace the given range with the given content, which may be a
  fragment, node, or array of nodes.
  */
  replaceWith(e, n, r) {
    return this.replace(e, n, new B(A.from(r), 0, 0));
  }
  /**
  Delete the content between the given positions.
  */
  delete(e, n) {
    return this.replace(e, n, B.empty);
  }
  /**
  Insert the given content at the given position.
  */
  insert(e, n) {
    return this.replaceWith(e, e, n);
  }
  /**
  Replace a range of the document with a given slice, using
  `from`, `to`, and the slice's
  [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather
  than fixed start and end points. This method may grow the
  replaced area or close open nodes in the slice in order to get a
  fit that is more in line with WYSIWYG expectations, by dropping
  fully covered parent nodes of the replaced region when they are
  marked [non-defining as
  context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an
  open parent node from the slice that _is_ marked as [defining
  its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).
  
  This is the method, for example, to handle paste. The similar
  [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more
  primitive tool which will _not_ move the start and end of its given
  range, and is useful in situations where you need more precise
  control over what happens.
  */
  replaceRange(e, n, r) {
    return Xh(this, e, n, r), this;
  }
  /**
  Replace the given range with a node, but use `from` and `to` as
  hints, rather than precise positions. When from and to are the same
  and are at the start or end of a parent node in which the given
  node doesn't fit, this method may _move_ them out towards a parent
  that does allow the given node to be placed. When the given range
  completely covers a parent node, this method may completely replace
  that parent node.
  */
  replaceRangeWith(e, n, r) {
    return Qh(this, e, n, r), this;
  }
  /**
  Delete the given range, expanding it to cover fully covered
  parent nodes until a valid replace is found.
  */
  deleteRange(e, n) {
    return em(this, e, n), this;
  }
  /**
  Split the content in the given range off from its parent, if there
  is sibling content before or after it, and move it up the tree to
  the depth specified by `target`. You'll probably want to use
  [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make
  sure the lift is valid.
  */
  lift(e, n) {
    return $h(this, e, n), this;
  }
  /**
  Join the blocks around the given position. If depth is 2, their
  last and first siblings are also joined, and so on.
  */
  join(e, n = 1) {
    return Zh(this, e, n), this;
  }
  /**
  Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.
  The wrappers are assumed to be valid in this position, and should
  probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).
  */
  wrap(e, n) {
    return Fh(this, e, n), this;
  }
  /**
  Set the type of all textblocks (partly) between `from` and `to` to
  the given node type with the given attributes.
  */
  setBlockType(e, n = e, r, i = null) {
    return Uh(this, e, n, r, i), this;
  }
  /**
  Change the type, attributes, and/or marks of the node at `pos`.
  When `type` isn't given, the existing node type is preserved,
  */
  setNodeMarkup(e, n, r = null, i) {
    return Wh(this, e, n, r, i), this;
  }
  /**
  Set a single attribute on a given node to a new value.
  The `pos` addresses the document content. Use `setDocAttribute`
  to set attributes on the document itself.
  */
  setNodeAttribute(e, n, r) {
    return this.step(new mr(e, n, r)), this;
  }
  /**
  Set a single attribute on the document to a new value.
  */
  setDocAttribute(e, n) {
    return this.step(new Qr(e, n)), this;
  }
  /**
  Add a mark to the node at position `pos`.
  */
  addNodeMark(e, n) {
    return this.step(new ln(e, n)), this;
  }
  /**
  Remove a mark (or a mark of the given type) from the node at
  position `pos`.
  */
  removeNodeMark(e, n) {
    if (!(n instanceof ve)) {
      let r = this.doc.nodeAt(e);
      if (!r)
        throw new RangeError("No node at position " + e);
      if (n = n.isInSet(r.marks), !n)
        return this;
    }
    return this.step(new yr(e, n)), this;
  }
  /**
  Split the node at the given position, and optionally, if `depth` is
  greater than one, any number of nodes above that. By default, the
  parts split off will inherit the node type of the original node.
  This can be changed by passing an array of types and attributes to
  use after the split.
  */
  split(e, n = 1, r) {
    return qh(this, e, n, r), this;
  }
  /**
  Add the given mark to the inline content between `from` and `to`.
  */
  addMark(e, n, r) {
    return Dh(this, e, n, r), this;
  }
  /**
  Remove marks from inline nodes between `from` and `to`. When
  `mark` is a single mark, remove precisely that mark. When it is
  a mark type, remove all marks of that type. When it is null,
  remove all marks of any type.
  */
  removeMark(e, n, r) {
    return Hh(this, e, n, r), this;
  }
  /**
  Removes all marks and nodes from the content of the node at
  `pos` that don't match the given new parent node type. Accepts
  an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as
  third argument.
  */
  clearIncompatible(e, n, r) {
    return Bh(this, e, n, r), this;
  }
}
const co = /* @__PURE__ */ Object.create(null);
class te {
  /**
  Initialize a selection with the head and anchor and ranges. If no
  ranges are given, constructs a single range across `$anchor` and
  `$head`.
  */
  constructor(e, n, r) {
    this.$anchor = e, this.$head = n, this.ranges = r || [new Ru(e.min(n), e.max(n))];
  }
  /**
  The selection's anchor, as an unresolved position.
  */
  get anchor() {
    return this.$anchor.pos;
  }
  /**
  The selection's head.
  */
  get head() {
    return this.$head.pos;
  }
  /**
  The lower bound of the selection's main range.
  */
  get from() {
    return this.$from.pos;
  }
  /**
  The upper bound of the selection's main range.
  */
  get to() {
    return this.$to.pos;
  }
  /**
  The resolved lower  bound of the selection's main range.
  */
  get $from() {
    return this.ranges[0].$from;
  }
  /**
  The resolved upper bound of the selection's main range.
  */
  get $to() {
    return this.ranges[0].$to;
  }
  /**
  Indicates whether the selection contains any content.
  */
  get empty() {
    let e = this.ranges;
    for (let n = 0; n < e.length; n++)
      if (e[n].$from.pos != e[n].$to.pos)
        return !1;
    return !0;
  }
  /**
  Get the content of this selection as a slice.
  */
  content() {
    return this.$from.doc.slice(this.from, this.to, !0);
  }
  /**
  Replace the selection with a slice or, if no slice is given,
  delete the selection. Will append to the given transaction.
  */
  replace(e, n = B.empty) {
    let r = n.content.lastChild, i = null;
    for (let a = 0; a < n.openEnd; a++)
      i = r, r = r.lastChild;
    let s = e.steps.length, o = this.ranges;
    for (let a = 0; a < o.length; a++) {
      let { $from: l, $to: c } = o[a], d = e.mapping.slice(s);
      e.replaceRange(d.map(l.pos), d.map(c.pos), a ? B.empty : n), a == 0 && zl(e, s, (r ? r.isInline : i && i.isTextblock) ? -1 : 1);
    }
  }
  /**
  Replace the selection with the given node, appending the changes
  to the given transaction.
  */
  replaceWith(e, n) {
    let r = e.steps.length, i = this.ranges;
    for (let s = 0; s < i.length; s++) {
      let { $from: o, $to: a } = i[s], l = e.mapping.slice(r), c = l.map(o.pos), d = l.map(a.pos);
      s ? e.deleteRange(c, d) : (e.replaceRangeWith(c, d, n), zl(e, r, n.isInline ? -1 : 1));
    }
  }
  /**
  Find a valid cursor or leaf node selection starting at the given
  position and searching back if `dir` is negative, and forward if
  positive. When `textOnly` is true, only consider cursor
  selections. Will return null when no valid selection position is
  found.
  */
  static findFrom(e, n, r = !1) {
    let i = e.parent.inlineContent ? new G(e) : nr(e.node(0), e.parent, e.pos, e.index(), n, r);
    if (i)
      return i;
    for (let s = e.depth - 1; s >= 0; s--) {
      let o = n < 0 ? nr(e.node(0), e.node(s), e.before(s + 1), e.index(s), n, r) : nr(e.node(0), e.node(s), e.after(s + 1), e.index(s) + 1, n, r);
      if (o)
        return o;
    }
    return null;
  }
  /**
  Find a valid cursor or leaf node selection near the given
  position. Searches forward first by default, but if `bias` is
  negative, it will search backwards first.
  */
  static near(e, n = 1) {
    return this.findFrom(e, n) || this.findFrom(e, -n) || new wt(e.node(0));
  }
  /**
  Find the cursor or leaf node selection closest to the start of
  the given document. Will return an
  [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position
  exists.
  */
  static atStart(e) {
    return nr(e, e, 0, 0, 1) || new wt(e);
  }
  /**
  Find the cursor or leaf node selection closest to the end of the
  given document.
  */
  static atEnd(e) {
    return nr(e, e, e.content.size, e.childCount, -1) || new wt(e);
  }
  /**
  Deserialize the JSON representation of a selection. Must be
  implemented for custom classes (as a static class method).
  */
  static fromJSON(e, n) {
    if (!n || !n.type)
      throw new RangeError("Invalid input for Selection.fromJSON");
    let r = co[n.type];
    if (!r)
      throw new RangeError(`No selection type ${n.type} defined`);
    return r.fromJSON(e, n);
  }
  /**
  To be able to deserialize selections from JSON, custom selection
  classes must register themselves with an ID string, so that they
  can be disambiguated. Try to pick something that's unlikely to
  clash with classes from other modules.
  */
  static jsonID(e, n) {
    if (e in co)
      throw new RangeError("Duplicate use of selection JSON ID " + e);
    return co[e] = n, n.prototype.jsonID = e, n;
  }
  /**
  Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,
  which is a value that can be mapped without having access to a
  current document, and later resolved to a real selection for a
  given document again. (This is used mostly by the history to
  track and restore old selections.) The default implementation of
  this method just converts the selection to a text selection and
  returns the bookmark for that.
  */
  getBookmark() {
    return G.between(this.$anchor, this.$head).getBookmark();
  }
}
te.prototype.visible = !0;
class Ru {
  /**
  Create a range.
  */
  constructor(e, n) {
    this.$from = e, this.$to = n;
  }
}
let $l = !1;
function Vl(t) {
  !$l && !t.parent.inlineContent && ($l = !0, console.warn("TextSelection endpoint not pointing into a node with inline content (" + t.parent.type.name + ")"));
}
class G extends te {
  /**
  Construct a text selection between the given points.
  */
  constructor(e, n = e) {
    Vl(e), Vl(n), super(e, n);
  }
  /**
  Returns a resolved position if this is a cursor selection (an
  empty text selection), and null otherwise.
  */
  get $cursor() {
    return this.$anchor.pos == this.$head.pos ? this.$head : null;
  }
  map(e, n) {
    let r = e.resolve(n.map(this.head));
    if (!r.parent.inlineContent)
      return te.near(r);
    let i = e.resolve(n.map(this.anchor));
    return new G(i.parent.inlineContent ? i : r, r);
  }
  replace(e, n = B.empty) {
    if (super.replace(e, n), n == B.empty) {
      let r = this.$from.marksAcross(this.$to);
      r && e.ensureMarks(r);
    }
  }
  eq(e) {
    return e instanceof G && e.anchor == this.anchor && e.head == this.head;
  }
  getBookmark() {
    return new Hs(this.anchor, this.head);
  }
  toJSON() {
    return { type: "text", anchor: this.anchor, head: this.head };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.anchor != "number" || typeof n.head != "number")
      throw new RangeError("Invalid input for TextSelection.fromJSON");
    return new G(e.resolve(n.anchor), e.resolve(n.head));
  }
  /**
  Create a text selection from non-resolved positions.
  */
  static create(e, n, r = n) {
    let i = e.resolve(n);
    return new this(i, r == n ? i : e.resolve(r));
  }
  /**
  Return a text selection that spans the given positions or, if
  they aren't text positions, find a text selection near them.
  `bias` determines whether the method searches forward (default)
  or backwards (negative number) first. Will fall back to calling
  [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document
  doesn't contain a valid text position.
  */
  static between(e, n, r) {
    let i = e.pos - n.pos;
    if ((!r || i) && (r = i >= 0 ? 1 : -1), !n.parent.inlineContent) {
      let s = te.findFrom(n, r, !0) || te.findFrom(n, -r, !0);
      if (s)
        n = s.$head;
      else
        return te.near(n, r);
    }
    return e.parent.inlineContent || (i == 0 ? e = n : (e = (te.findFrom(e, -r, !0) || te.findFrom(e, r, !0)).$anchor, e.pos < n.pos != i < 0 && (e = n))), new G(e, n);
  }
}
te.jsonID("text", G);
class Hs {
  constructor(e, n) {
    this.anchor = e, this.head = n;
  }
  map(e) {
    return new Hs(e.map(this.anchor), e.map(this.head));
  }
  resolve(e) {
    return G.between(e.resolve(this.anchor), e.resolve(this.head));
  }
}
class Y extends te {
  /**
  Create a node selection. Does not verify the validity of its
  argument.
  */
  constructor(e) {
    let n = e.nodeAfter, r = e.node(0).resolve(e.pos + n.nodeSize);
    super(e, r), this.node = n;
  }
  map(e, n) {
    let { deleted: r, pos: i } = n.mapResult(this.anchor), s = e.resolve(i);
    return r ? te.near(s) : new Y(s);
  }
  content() {
    return new B(A.from(this.node), 0, 0);
  }
  eq(e) {
    return e instanceof Y && e.anchor == this.anchor;
  }
  toJSON() {
    return { type: "node", anchor: this.anchor };
  }
  getBookmark() {
    return new Aa(this.anchor);
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.anchor != "number")
      throw new RangeError("Invalid input for NodeSelection.fromJSON");
    return new Y(e.resolve(n.anchor));
  }
  /**
  Create a node selection from non-resolved positions.
  */
  static create(e, n) {
    return new Y(e.resolve(n));
  }
  /**
  Determines whether the given node may be selected as a node
  selection.
  */
  static isSelectable(e) {
    return !e.isText && e.type.spec.selectable !== !1;
  }
}
Y.prototype.visible = !1;
te.jsonID("node", Y);
class Aa {
  constructor(e) {
    this.anchor = e;
  }
  map(e) {
    let { deleted: n, pos: r } = e.mapResult(this.anchor);
    return n ? new Hs(r, r) : new Aa(r);
  }
  resolve(e) {
    let n = e.resolve(this.anchor), r = n.nodeAfter;
    return r && Y.isSelectable(r) ? new Y(n) : te.near(n);
  }
}
class wt extends te {
  /**
  Create an all-selection over the given document.
  */
  constructor(e) {
    super(e.resolve(0), e.resolve(e.content.size));
  }
  replace(e, n = B.empty) {
    if (n == B.empty) {
      e.delete(0, e.doc.content.size);
      let r = te.atStart(e.doc);
      r.eq(e.selection) || e.setSelection(r);
    } else
      super.replace(e, n);
  }
  toJSON() {
    return { type: "all" };
  }
  /**
  @internal
  */
  static fromJSON(e) {
    return new wt(e);
  }
  map(e) {
    return new wt(e);
  }
  eq(e) {
    return e instanceof wt;
  }
  getBookmark() {
    return tm;
  }
}
te.jsonID("all", wt);
const tm = {
  map() {
    return this;
  },
  resolve(t) {
    return new wt(t);
  }
};
function nr(t, e, n, r, i, s = !1) {
  if (e.inlineContent)
    return G.create(t, n);
  for (let o = r - (i > 0 ? 0 : 1); i > 0 ? o < e.childCount : o >= 0; o += i) {
    let a = e.child(o);
    if (a.isAtom) {
      if (!s && Y.isSelectable(a))
        return Y.create(t, n - (i < 0 ? a.nodeSize : 0));
    } else {
      let l = nr(t, a, n + i, i < 0 ? a.childCount : 0, i, s);
      if (l)
        return l;
    }
    n += a.nodeSize * i;
  }
  return null;
}
function zl(t, e, n) {
  let r = t.steps.length - 1;
  if (r < e)
    return;
  let i = t.steps[r];
  if (!(i instanceof ze || i instanceof De))
    return;
  let s = t.mapping.maps[r], o;
  s.forEach((a, l, c, d) => {
    o == null && (o = d);
  }), t.setSelection(te.near(t.doc.resolve(o), n));
}
const Fl = 1, ki = 2, Ul = 4;
class nm extends Na {
  /**
  @internal
  */
  constructor(e) {
    super(e.doc), this.curSelectionFor = 0, this.updated = 0, this.meta = /* @__PURE__ */ Object.create(null), this.time = Date.now(), this.curSelection = e.selection, this.storedMarks = e.storedMarks;
  }
  /**
  The transaction's current selection. This defaults to the editor
  selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the
  transaction, but can be overwritten with
  [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).
  */
  get selection() {
    return this.curSelectionFor < this.steps.length && (this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)), this.curSelectionFor = this.steps.length), this.curSelection;
  }
  /**
  Update the transaction's current selection. Will determine the
  selection that the editor gets when the transaction is applied.
  */
  setSelection(e) {
    if (e.$from.doc != this.doc)
      throw new RangeError("Selection passed to setSelection must point at the current document");
    return this.curSelection = e, this.curSelectionFor = this.steps.length, this.updated = (this.updated | Fl) & ~ki, this.storedMarks = null, this;
  }
  /**
  Whether the selection was explicitly updated by this transaction.
  */
  get selectionSet() {
    return (this.updated & Fl) > 0;
  }
  /**
  Set the current stored marks.
  */
  setStoredMarks(e) {
    return this.storedMarks = e, this.updated |= ki, this;
  }
  /**
  Make sure the current stored marks or, if that is null, the marks
  at the selection, match the given set of marks. Does nothing if
  this is already the case.
  */
  ensureMarks(e) {
    return ve.sameSet(this.storedMarks || this.selection.$from.marks(), e) || this.setStoredMarks(e), this;
  }
  /**
  Add a mark to the set of stored marks.
  */
  addStoredMark(e) {
    return this.ensureMarks(e.addToSet(this.storedMarks || this.selection.$head.marks()));
  }
  /**
  Remove a mark or mark type from the set of stored marks.
  */
  removeStoredMark(e) {
    return this.ensureMarks(e.removeFromSet(this.storedMarks || this.selection.$head.marks()));
  }
  /**
  Whether the stored marks were explicitly set for this transaction.
  */
  get storedMarksSet() {
    return (this.updated & ki) > 0;
  }
  /**
  @internal
  */
  addStep(e, n) {
    super.addStep(e, n), this.updated = this.updated & ~ki, this.storedMarks = null;
  }
  /**
  Update the timestamp for the transaction.
  */
  setTime(e) {
    return this.time = e, this;
  }
  /**
  Replace the current selection with the given slice.
  */
  replaceSelection(e) {
    return this.selection.replace(this, e), this;
  }
  /**
  Replace the selection with the given node. When `inheritMarks` is
  true and the content is inline, it inherits the marks from the
  place where it is inserted.
  */
  replaceSelectionWith(e, n = !0) {
    let r = this.selection;
    return n && (e = e.mark(this.storedMarks || (r.empty ? r.$from.marks() : r.$from.marksAcross(r.$to) || ve.none))), r.replaceWith(this, e), this;
  }
  /**
  Delete the selection.
  */
  deleteSelection() {
    return this.selection.replace(this), this;
  }
  /**
  Replace the given range, or the selection if no range is given,
  with a text node containing the given string.
  */
  insertText(e, n, r) {
    let i = this.doc.type.schema;
    if (n == null)
      return e ? this.replaceSelectionWith(i.text(e), !0) : this.deleteSelection();
    {
      if (r == null && (r = n), r = r ?? n, !e)
        return this.deleteRange(n, r);
      let s = this.storedMarks;
      if (!s) {
        let o = this.doc.resolve(n);
        s = r == n ? o.marks() : o.marksAcross(this.doc.resolve(r));
      }
      return this.replaceRangeWith(n, r, i.text(e, s)), this.selection.empty || this.setSelection(te.near(this.selection.$to)), this;
    }
  }
  /**
  Store a metadata property in this transaction, keyed either by
  name or by plugin.
  */
  setMeta(e, n) {
    return this.meta[typeof e == "string" ? e : e.key] = n, this;
  }
  /**
  Retrieve a metadata property for a given name or plugin.
  */
  getMeta(e) {
    return this.meta[typeof e == "string" ? e : e.key];
  }
  /**
  Returns true if this transaction doesn't contain any metadata,
  and can thus safely be extended.
  */
  get isGeneric() {
    for (let e in this.meta)
      return !1;
    return !0;
  }
  /**
  Indicate that the editor should scroll the selection into view
  when updated to the state produced by this transaction.
  */
  scrollIntoView() {
    return this.updated |= Ul, this;
  }
  /**
  True when this transaction has had `scrollIntoView` called on it.
  */
  get scrolledIntoView() {
    return (this.updated & Ul) > 0;
  }
}
function Kl(t, e) {
  return !e || !t ? t : t.bind(e);
}
class Vr {
  constructor(e, n, r) {
    this.name = e, this.init = Kl(n.init, r), this.apply = Kl(n.apply, r);
  }
}
const rm = [
  new Vr("doc", {
    init(t) {
      return t.doc || t.schema.topNodeType.createAndFill();
    },
    apply(t) {
      return t.doc;
    }
  }),
  new Vr("selection", {
    init(t, e) {
      return t.selection || te.atStart(e.doc);
    },
    apply(t) {
      return t.selection;
    }
  }),
  new Vr("storedMarks", {
    init(t) {
      return t.storedMarks || null;
    },
    apply(t, e, n, r) {
      return r.selection.$cursor ? t.storedMarks : null;
    }
  }),
  new Vr("scrollToSelection", {
    init() {
      return 0;
    },
    apply(t, e) {
      return t.scrolledIntoView ? e + 1 : e;
    }
  })
];
class uo {
  constructor(e, n) {
    this.schema = e, this.plugins = [], this.pluginsByKey = /* @__PURE__ */ Object.create(null), this.fields = rm.slice(), n && n.forEach((r) => {
      if (this.pluginsByKey[r.key])
        throw new RangeError("Adding different instances of a keyed plugin (" + r.key + ")");
      this.plugins.push(r), this.pluginsByKey[r.key] = r, r.spec.state && this.fields.push(new Vr(r.key, r.spec.state, r));
    });
  }
}
class lr {
  /**
  @internal
  */
  constructor(e) {
    this.config = e;
  }
  /**
  The schema of the state's document.
  */
  get schema() {
    return this.config.schema;
  }
  /**
  The plugins that are active in this state.
  */
  get plugins() {
    return this.config.plugins;
  }
  /**
  Apply the given transaction to produce a new state.
  */
  apply(e) {
    return this.applyTransaction(e).state;
  }
  /**
  @internal
  */
  filterTransaction(e, n = -1) {
    for (let r = 0; r < this.config.plugins.length; r++)
      if (r != n) {
        let i = this.config.plugins[r];
        if (i.spec.filterTransaction && !i.spec.filterTransaction.call(i, e, this))
          return !1;
      }
    return !0;
  }
  /**
  Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that
  returns the precise transactions that were applied (which might
  be influenced by the [transaction
  hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of
  plugins) along with the new state.
  */
  applyTransaction(e) {
    if (!this.filterTransaction(e))
      return { state: this, transactions: [] };
    let n = [e], r = this.applyInner(e), i = null;
    for (; ; ) {
      let s = !1;
      for (let o = 0; o < this.config.plugins.length; o++) {
        let a = this.config.plugins[o];
        if (a.spec.appendTransaction) {
          let l = i ? i[o].n : 0, c = i ? i[o].state : this, d = l < n.length && a.spec.appendTransaction.call(a, l ? n.slice(l) : n, c, r);
          if (d && r.filterTransaction(d, o)) {
            if (d.setMeta("appendedTransaction", e), !i) {
              i = [];
              for (let u = 0; u < this.config.plugins.length; u++)
                i.push(u < o ? { state: r, n: n.length } : { state: this, n: 0 });
            }
            n.push(d), r = r.applyInner(d), s = !0;
          }
          i && (i[o] = { state: r, n: n.length });
        }
      }
      if (!s)
        return { state: r, transactions: n };
    }
  }
  /**
  @internal
  */
  applyInner(e) {
    if (!e.before.eq(this.doc))
      throw new RangeError("Applying a mismatched transaction");
    let n = new lr(this.config), r = this.config.fields;
    for (let i = 0; i < r.length; i++) {
      let s = r[i];
      n[s.name] = s.apply(e, this[s.name], this, n);
    }
    return n;
  }
  /**
  Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.
  */
  get tr() {
    return new nm(this);
  }
  /**
  Create a new state.
  */
  static create(e) {
    let n = new uo(e.doc ? e.doc.type.schema : e.schema, e.plugins), r = new lr(n);
    for (let i = 0; i < n.fields.length; i++)
      r[n.fields[i].name] = n.fields[i].init(e, r);
    return r;
  }
  /**
  Create a new state based on this one, but with an adjusted set
  of active plugins. State fields that exist in both sets of
  plugins are kept unchanged. Those that no longer exist are
  dropped, and those that are new are initialized using their
  [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new
  configuration object..
  */
  reconfigure(e) {
    let n = new uo(this.schema, e.plugins), r = n.fields, i = new lr(n);
    for (let s = 0; s < r.length; s++) {
      let o = r[s].name;
      i[o] = this.hasOwnProperty(o) ? this[o] : r[s].init(e, i);
    }
    return i;
  }
  /**
  Serialize this state to JSON. If you want to serialize the state
  of plugins, pass an object mapping property names to use in the
  resulting JSON object to plugin objects. The argument may also be
  a string or number, in which case it is ignored, to support the
  way `JSON.stringify` calls `toString` methods.
  */
  toJSON(e) {
    let n = { doc: this.doc.toJSON(), selection: this.selection.toJSON() };
    if (this.storedMarks && (n.storedMarks = this.storedMarks.map((r) => r.toJSON())), e && typeof e == "object")
      for (let r in e) {
        if (r == "doc" || r == "selection")
          throw new RangeError("The JSON fields `doc` and `selection` are reserved");
        let i = e[r], s = i.spec.state;
        s && s.toJSON && (n[r] = s.toJSON.call(i, this[i.key]));
      }
    return n;
  }
  /**
  Deserialize a JSON representation of a state. `config` should
  have at least a `schema` field, and should contain array of
  plugins to initialize the state with. `pluginFields` can be used
  to deserialize the state of plugins, by associating plugin
  instances with the property names they use in the JSON object.
  */
  static fromJSON(e, n, r) {
    if (!n)
      throw new RangeError("Invalid input for EditorState.fromJSON");
    if (!e.schema)
      throw new RangeError("Required config field 'schema' missing");
    let i = new uo(e.schema, e.plugins), s = new lr(i);
    return i.fields.forEach((o) => {
      if (o.name == "doc")
        s.doc = Ln.fromJSON(e.schema, n.doc);
      else if (o.name == "selection")
        s.selection = te.fromJSON(s.doc, n.selection);
      else if (o.name == "storedMarks")
        n.storedMarks && (s.storedMarks = n.storedMarks.map(e.schema.markFromJSON));
      else {
        if (r)
          for (let a in r) {
            let l = r[a], c = l.spec.state;
            if (l.key == o.name && c && c.fromJSON && Object.prototype.hasOwnProperty.call(n, a)) {
              s[o.name] = c.fromJSON.call(l, e, n[a], s);
              return;
            }
          }
        s[o.name] = o.init(e, s);
      }
    }), s;
  }
}
function Lu(t, e, n) {
  for (let r in t) {
    let i = t[r];
    i instanceof Function ? i = i.bind(e) : r == "handleDOMEvents" && (i = Lu(i, e, {})), n[r] = i;
  }
  return n;
}
class Se {
  /**
  Create a plugin.
  */
  constructor(e) {
    this.spec = e, this.props = {}, e.props && Lu(e.props, this, this.props), this.key = e.key ? e.key.key : Iu("plugin");
  }
  /**
  Extract the plugin's state field from an editor state.
  */
  getState(e) {
    return e[this.key];
  }
}
const fo = /* @__PURE__ */ Object.create(null);
function Iu(t) {
  return t in fo ? t + "$" + ++fo[t] : (fo[t] = 0, t + "$");
}
class Me {
  /**
  Create a plugin key.
  */
  constructor(e = "key") {
    this.key = Iu(e);
  }
  /**
  Get the active plugin with this key, if any, from an editor
  state.
  */
  get(e) {
    return e.config.pluginsByKey[this.key];
  }
  /**
  Get the plugin's state from an editor state.
  */
  getState(e) {
    return e[this.key];
  }
}
const Je = function(t) {
  for (var e = 0; ; e++)
    if (t = t.previousSibling, !t)
      return e;
}, ei = function(t) {
  let e = t.assignedSlot || t.parentNode;
  return e && e.nodeType == 11 ? e.host : e;
};
let Wl = null;
const qt = function(t, e, n) {
  let r = Wl || (Wl = document.createRange());
  return r.setEnd(t, n ?? t.nodeValue.length), r.setStart(t, e || 0), r;
}, Vn = function(t, e, n, r) {
  return n && (ql(t, e, n, r, -1) || ql(t, e, n, r, 1));
}, im = /^(img|br|input|textarea|hr)$/i;
function ql(t, e, n, r, i) {
  for (; ; ) {
    if (t == n && e == r)
      return !0;
    if (e == (i < 0 ? 0 : Dt(t))) {
      let s = t.parentNode;
      if (!s || s.nodeType != 1 || Oa(t) || im.test(t.nodeName) || t.contentEditable == "false")
        return !1;
      e = Je(t) + (i < 0 ? 0 : 1), t = s;
    } else if (t.nodeType == 1) {
      if (t = t.childNodes[e + (i < 0 ? -1 : 0)], t.contentEditable == "false")
        return !1;
      e = i < 0 ? Dt(t) : 0;
    } else
      return !1;
  }
}
function Dt(t) {
  return t.nodeType == 3 ? t.nodeValue.length : t.childNodes.length;
}
function sm(t, e, n) {
  for (let r = e == 0, i = e == Dt(t); r || i; ) {
    if (t == n)
      return !0;
    let s = Je(t);
    if (t = t.parentNode, !t)
      return !1;
    r = r && s == 0, i = i && s == Dt(t);
  }
}
function Oa(t) {
  let e;
  for (let n = t; n && !(e = n.pmViewDesc); n = n.parentNode)
    ;
  return e && e.node && e.node.isBlock && (e.dom == t || e.contentDOM == t);
}
const Bs = function(t) {
  return t.focusNode && Vn(t.focusNode, t.focusOffset, t.anchorNode, t.anchorOffset);
};
function Mn(t, e) {
  let n = document.createEvent("Event");
  return n.initEvent("keydown", !0, !0), n.keyCode = t, n.key = n.code = e, n;
}
function om(t) {
  let e = t.activeElement;
  for (; e && e.shadowRoot; )
    e = e.shadowRoot.activeElement;
  return e;
}
function am(t, e, n) {
  if (t.caretPositionFromPoint)
    try {
      let r = t.caretPositionFromPoint(e, n);
      if (r)
        return { node: r.offsetNode, offset: r.offset };
    } catch {
    }
  if (t.caretRangeFromPoint) {
    let r = t.caretRangeFromPoint(e, n);
    if (r)
      return { node: r.startContainer, offset: r.startOffset };
  }
}
const $t = typeof navigator < "u" ? navigator : null, Zl = typeof document < "u" ? document : null, wn = $t && $t.userAgent || "", Go = /Edge\/(\d+)/.exec(wn), Du = /MSIE \d/.exec(wn), jo = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(wn), st = !!(Du || jo || Go), pn = Du ? document.documentMode : jo ? +jo[1] : Go ? +Go[1] : 0, _t = !st && /gecko\/(\d+)/i.test(wn);
_t && +(/Firefox\/(\d+)/.exec(wn) || [0, 0])[1];
const Yo = !st && /Chrome\/(\d+)/.exec(wn), We = !!Yo, lm = Yo ? +Yo[1] : 0, Xe = !st && !!$t && /Apple Computer/.test($t.vendor), wr = Xe && (/Mobile\/\w+/.test(wn) || !!$t && $t.maxTouchPoints > 2), yt = wr || ($t ? /Mac/.test($t.platform) : !1), cm = $t ? /Win/.test($t.platform) : !1, kt = /Android \d/.test(wn), gi = !!Zl && "webkitFontSmoothing" in Zl.documentElement.style, dm = gi ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
function um(t) {
  return {
    left: 0,
    right: t.documentElement.clientWidth,
    top: 0,
    bottom: t.documentElement.clientHeight
  };
}
function Ut(t, e) {
  return typeof t == "number" ? t : t[e];
}
function fm(t) {
  let e = t.getBoundingClientRect(), n = e.width / t.offsetWidth || 1, r = e.height / t.offsetHeight || 1;
  return {
    left: e.left,
    right: e.left + t.clientWidth * n,
    top: e.top,
    bottom: e.top + t.clientHeight * r
  };
}
function Gl(t, e, n) {
  let r = t.someProp("scrollThreshold") || 0, i = t.someProp("scrollMargin") || 5, s = t.dom.ownerDocument;
  for (let o = n || t.dom; o; o = ei(o)) {
    if (o.nodeType != 1)
      continue;
    let a = o, l = a == s.body, c = l ? um(s) : fm(a), d = 0, u = 0;
    if (e.top < c.top + Ut(r, "top") ? u = -(c.top - e.top + Ut(i, "top")) : e.bottom > c.bottom - Ut(r, "bottom") && (u = e.bottom - e.top > c.bottom - c.top ? e.top + Ut(i, "top") - c.top : e.bottom - c.bottom + Ut(i, "bottom")), e.left < c.left + Ut(r, "left") ? d = -(c.left - e.left + Ut(i, "left")) : e.right > c.right - Ut(r, "right") && (d = e.right - c.right + Ut(i, "right")), d || u)
      if (l)
        s.defaultView.scrollBy(d, u);
      else {
        let f = a.scrollLeft, p = a.scrollTop;
        u && (a.scrollTop += u), d && (a.scrollLeft += d);
        let h = a.scrollLeft - f, m = a.scrollTop - p;
        e = { left: e.left - h, top: e.top - m, right: e.right - h, bottom: e.bottom - m };
      }
    if (l || /^(fixed|sticky)$/.test(getComputedStyle(o).position))
      break;
  }
}
function pm(t) {
  let e = t.dom.getBoundingClientRect(), n = Math.max(0, e.top), r, i;
  for (let s = (e.left + e.right) / 2, o = n + 1; o < Math.min(innerHeight, e.bottom); o += 5) {
    let a = t.root.elementFromPoint(s, o);
    if (!a || a == t.dom || !t.dom.contains(a))
      continue;
    let l = a.getBoundingClientRect();
    if (l.top >= n - 20) {
      r = a, i = l.top;
      break;
    }
  }
  return { refDOM: r, refTop: i, stack: Hu(t.dom) };
}
function Hu(t) {
  let e = [], n = t.ownerDocument;
  for (let r = t; r && (e.push({ dom: r, top: r.scrollTop, left: r.scrollLeft }), t != n); r = ei(r))
    ;
  return e;
}
function hm({ refDOM: t, refTop: e, stack: n }) {
  let r = t ? t.getBoundingClientRect().top : 0;
  Bu(n, r == 0 ? 0 : r - e);
}
function Bu(t, e) {
  for (let n = 0; n < t.length; n++) {
    let { dom: r, top: i, left: s } = t[n];
    r.scrollTop != i + e && (r.scrollTop = i + e), r.scrollLeft != s && (r.scrollLeft = s);
  }
}
let Yn = null;
function mm(t) {
  if (t.setActive)
    return t.setActive();
  if (Yn)
    return t.focus(Yn);
  let e = Hu(t);
  t.focus(Yn == null ? {
    get preventScroll() {
      return Yn = { preventScroll: !0 }, !0;
    }
  } : void 0), Yn || (Yn = !1, Bu(e, 0));
}
function Pu(t, e) {
  let n, r = 2e8, i, s = 0, o = e.top, a = e.top, l, c;
  for (let d = t.firstChild, u = 0; d; d = d.nextSibling, u++) {
    let f;
    if (d.nodeType == 1)
      f = d.getClientRects();
    else if (d.nodeType == 3)
      f = qt(d).getClientRects();
    else
      continue;
    for (let p = 0; p < f.length; p++) {
      let h = f[p];
      if (h.top <= o && h.bottom >= a) {
        o = Math.max(h.bottom, o), a = Math.min(h.top, a);
        let m = h.left > e.left ? h.left - e.left : h.right < e.left ? e.left - h.right : 0;
        if (m < r) {
          n = d, r = m, i = m && n.nodeType == 3 ? {
            left: h.right < e.left ? h.right : h.left,
            top: e.top
          } : e, d.nodeType == 1 && m && (s = u + (e.left >= (h.left + h.right) / 2 ? 1 : 0));
          continue;
        }
      } else
        h.top > e.top && !l && h.left <= e.left && h.right >= e.left && (l = d, c = { left: Math.max(h.left, Math.min(h.right, e.left)), top: h.top });
      !n && (e.left >= h.right && e.top >= h.top || e.left >= h.left && e.top >= h.bottom) && (s = u + 1);
    }
  }
  return !n && l && (n = l, i = c, r = 0), n && n.nodeType == 3 ? gm(n, i) : !n || r && n.nodeType == 1 ? { node: t, offset: s } : Pu(n, i);
}
function gm(t, e) {
  let n = t.nodeValue.length, r = document.createRange();
  for (let i = 0; i < n; i++) {
    r.setEnd(t, i + 1), r.setStart(t, i);
    let s = Qt(r, 1);
    if (s.top != s.bottom && Ra(e, s))
      return { node: t, offset: i + (e.left >= (s.left + s.right) / 2 ? 1 : 0) };
  }
  return { node: t, offset: 0 };
}
function Ra(t, e) {
  return t.left >= e.left - 1 && t.left <= e.right + 1 && t.top >= e.top - 1 && t.top <= e.bottom + 1;
}
function bm(t, e) {
  let n = t.parentNode;
  return n && /^li$/i.test(n.nodeName) && e.left < t.getBoundingClientRect().left ? n : t;
}
function ym(t, e, n) {
  let { node: r, offset: i } = Pu(e, n), s = -1;
  if (r.nodeType == 1 && !r.firstChild) {
    let o = r.getBoundingClientRect();
    s = o.left != o.right && n.left > (o.left + o.right) / 2 ? 1 : -1;
  }
  return t.docView.posFromDOM(r, i, s);
}
function vm(t, e, n, r) {
  let i = -1;
  for (let s = e, o = !1; s != t.dom; ) {
    let a = t.docView.nearestDesc(s, !0);
    if (!a)
      return null;
    if (a.dom.nodeType == 1 && (a.node.isBlock && a.parent && !o || !a.contentDOM)) {
      let l = a.dom.getBoundingClientRect();
      if (a.node.isBlock && a.parent && !o && (o = !0, l.left > r.left || l.top > r.top ? i = a.posBefore : (l.right < r.left || l.bottom < r.top) && (i = a.posAfter)), !a.contentDOM && i < 0 && !a.node.isText)
        return (a.node.isBlock ? r.top < (l.top + l.bottom) / 2 : r.left < (l.left + l.right) / 2) ? a.posBefore : a.posAfter;
    }
    s = a.dom.parentNode;
  }
  return i > -1 ? i : t.docView.posFromDOM(e, n, -1);
}
function $u(t, e, n) {
  let r = t.childNodes.length;
  if (r && n.top < n.bottom)
    for (let i = Math.max(0, Math.min(r - 1, Math.floor(r * (e.top - n.top) / (n.bottom - n.top)) - 2)), s = i; ; ) {
      let o = t.childNodes[s];
      if (o.nodeType == 1) {
        let a = o.getClientRects();
        for (let l = 0; l < a.length; l++) {
          let c = a[l];
          if (Ra(e, c))
            return $u(o, e, c);
        }
      }
      if ((s = (s + 1) % r) == i)
        break;
    }
  return t;
}
function wm(t, e) {
  let n = t.dom.ownerDocument, r, i = 0, s = am(n, e.left, e.top);
  s && ({ node: r, offset: i } = s);
  let o = (t.root.elementFromPoint ? t.root : n).elementFromPoint(e.left, e.top), a;
  if (!o || !t.dom.contains(o.nodeType != 1 ? o.parentNode : o)) {
    let c = t.dom.getBoundingClientRect();
    if (!Ra(e, c) || (o = $u(t.dom, e, c), !o))
      return null;
  }
  if (Xe)
    for (let c = o; r && c; c = ei(c))
      c.draggable && (r = void 0);
  if (o = bm(o, e), r) {
    if (_t && r.nodeType == 1 && (i = Math.min(i, r.childNodes.length), i < r.childNodes.length)) {
      let d = r.childNodes[i], u;
      d.nodeName == "IMG" && (u = d.getBoundingClientRect()).right <= e.left && u.bottom > e.top && i++;
    }
    let c;
    gi && i && r.nodeType == 1 && (c = r.childNodes[i - 1]).nodeType == 1 && c.contentEditable == "false" && c.getBoundingClientRect().top >= e.top && i--, r == t.dom && i == r.childNodes.length - 1 && r.lastChild.nodeType == 1 && e.top > r.lastChild.getBoundingClientRect().bottom ? a = t.state.doc.content.size : (i == 0 || r.nodeType != 1 || r.childNodes[i - 1].nodeName != "BR") && (a = vm(t, r, i, e));
  }
  a == null && (a = ym(t, o, e));
  let l = t.docView.nearestDesc(o, !0);
  return { pos: a, inside: l ? l.posAtStart - l.border : -1 };
}
function jl(t) {
  return t.top < t.bottom || t.left < t.right;
}
function Qt(t, e) {
  let n = t.getClientRects();
  if (n.length) {
    let r = n[e < 0 ? 0 : n.length - 1];
    if (jl(r))
      return r;
  }
  return Array.prototype.find.call(n, jl) || t.getBoundingClientRect();
}
const Em = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
function Vu(t, e, n) {
  let { node: r, offset: i, atom: s } = t.docView.domFromPos(e, n < 0 ? -1 : 1), o = gi || _t;
  if (r.nodeType == 3)
    if (o && (Em.test(r.nodeValue) || (n < 0 ? !i : i == r.nodeValue.length))) {
      let l = Qt(qt(r, i, i), n);
      if (_t && i && /\s/.test(r.nodeValue[i - 1]) && i < r.nodeValue.length) {
        let c = Qt(qt(r, i - 1, i - 1), -1);
        if (c.top == l.top) {
          let d = Qt(qt(r, i, i + 1), -1);
          if (d.top != l.top)
            return Lr(d, d.left < c.left);
        }
      }
      return l;
    } else {
      let l = i, c = i, d = n < 0 ? 1 : -1;
      return n < 0 && !i ? (c++, d = -1) : n >= 0 && i == r.nodeValue.length ? (l--, d = 1) : n < 0 ? l-- : c++, Lr(Qt(qt(r, l, c), d), d < 0);
    }
  if (!t.state.doc.resolve(e - (s || 0)).parent.inlineContent) {
    if (s == null && i && (n < 0 || i == Dt(r))) {
      let l = r.childNodes[i - 1];
      if (l.nodeType == 1)
        return po(l.getBoundingClientRect(), !1);
    }
    if (s == null && i < Dt(r)) {
      let l = r.childNodes[i];
      if (l.nodeType == 1)
        return po(l.getBoundingClientRect(), !0);
    }
    return po(r.getBoundingClientRect(), n >= 0);
  }
  if (s == null && i && (n < 0 || i == Dt(r))) {
    let l = r.childNodes[i - 1], c = l.nodeType == 3 ? qt(l, Dt(l) - (o ? 0 : 1)) : l.nodeType == 1 && (l.nodeName != "BR" || !l.nextSibling) ? l : null;
    if (c)
      return Lr(Qt(c, 1), !1);
  }
  if (s == null && i < Dt(r)) {
    let l = r.childNodes[i];
    for (; l.pmViewDesc && l.pmViewDesc.ignoreForCoords; )
      l = l.nextSibling;
    let c = l ? l.nodeType == 3 ? qt(l, 0, o ? 0 : 1) : l.nodeType == 1 ? l : null : null;
    if (c)
      return Lr(Qt(c, -1), !0);
  }
  return Lr(Qt(r.nodeType == 3 ? qt(r) : r, -n), n >= 0);
}
function Lr(t, e) {
  if (t.width == 0)
    return t;
  let n = e ? t.left : t.right;
  return { top: t.top, bottom: t.bottom, left: n, right: n };
}
function po(t, e) {
  if (t.height == 0)
    return t;
  let n = e ? t.top : t.bottom;
  return { top: n, bottom: n, left: t.left, right: t.right };
}
function zu(t, e, n) {
  let r = t.state, i = t.root.activeElement;
  r != e && t.updateState(e), i != t.dom && t.focus();
  try {
    return n();
  } finally {
    r != e && t.updateState(r), i != t.dom && i && i.focus();
  }
}
function xm(t, e, n) {
  let r = e.selection, i = n == "up" ? r.$from : r.$to;
  return zu(t, e, () => {
    let { node: s } = t.docView.domFromPos(i.pos, n == "up" ? -1 : 1);
    for (; ; ) {
      let a = t.docView.nearestDesc(s, !0);
      if (!a)
        break;
      if (a.node.isBlock) {
        s = a.contentDOM || a.dom;
        break;
      }
      s = a.dom.parentNode;
    }
    let o = Vu(t, i.pos, 1);
    for (let a = s.firstChild; a; a = a.nextSibling) {
      let l;
      if (a.nodeType == 1)
        l = a.getClientRects();
      else if (a.nodeType == 3)
        l = qt(a, 0, a.nodeValue.length).getClientRects();
      else
        continue;
      for (let c = 0; c < l.length; c++) {
        let d = l[c];
        if (d.bottom > d.top + 1 && (n == "up" ? o.top - d.top > (d.bottom - o.top) * 2 : d.bottom - o.bottom > (o.bottom - d.top) * 2))
          return !1;
      }
    }
    return !0;
  });
}
const Sm = /[\u0590-\u08ac]/;
function Cm(t, e, n) {
  let { $head: r } = e.selection;
  if (!r.parent.isTextblock)
    return !1;
  let i = r.parentOffset, s = !i, o = i == r.parent.content.size, a = t.domSelection();
  return !Sm.test(r.parent.textContent) || !a.modify ? n == "left" || n == "backward" ? s : o : zu(t, e, () => {
    let { focusNode: l, focusOffset: c, anchorNode: d, anchorOffset: u } = t.domSelectionRange(), f = a.caretBidiLevel;
    a.modify("move", n, "character");
    let p = r.depth ? t.docView.domAfterPos(r.before()) : t.dom, { focusNode: h, focusOffset: m } = t.domSelectionRange(), g = h && !p.contains(h.nodeType == 1 ? h : h.parentNode) || l == h && c == m;
    try {
      a.collapse(d, u), l && (l != d || c != u) && a.extend && a.extend(l, c);
    } catch {
    }
    return f != null && (a.caretBidiLevel = f), g;
  });
}
let Yl = null, Jl = null, Xl = !1;
function Mm(t, e, n) {
  return Yl == e && Jl == n ? Xl : (Yl = e, Jl = n, Xl = n == "up" || n == "down" ? xm(t, e, n) : Cm(t, e, n));
}
const Et = 0, Ql = 1, _n = 2, Vt = 3;
class bi {
  constructor(e, n, r, i) {
    this.parent = e, this.children = n, this.dom = r, this.contentDOM = i, this.dirty = Et, r.pmViewDesc = this;
  }
  // Used to check whether a given description corresponds to a
  // widget/mark/node.
  matchesWidget(e) {
    return !1;
  }
  matchesMark(e) {
    return !1;
  }
  matchesNode(e, n, r) {
    return !1;
  }
  matchesHack(e) {
    return !1;
  }
  // When parsing in-editor content (in domchange.js), we allow
  // descriptions to determine the parse rules that should be used to
  // parse them.
  parseRule() {
    return null;
  }
  // Used by the editor's event handler to ignore events that come
  // from certain descs.
  stopEvent(e) {
    return !1;
  }
  // The size of the content represented by this desc.
  get size() {
    let e = 0;
    for (let n = 0; n < this.children.length; n++)
      e += this.children[n].size;
    return e;
  }
  // For block nodes, this represents the space taken up by their
  // start/end tokens.
  get border() {
    return 0;
  }
  destroy() {
    this.parent = void 0, this.dom.pmViewDesc == this && (this.dom.pmViewDesc = void 0);
    for (let e = 0; e < this.children.length; e++)
      this.children[e].destroy();
  }
  posBeforeChild(e) {
    for (let n = 0, r = this.posAtStart; ; n++) {
      let i = this.children[n];
      if (i == e)
        return r;
      r += i.size;
    }
  }
  get posBefore() {
    return this.parent.posBeforeChild(this);
  }
  get posAtStart() {
    return this.parent ? this.parent.posBeforeChild(this) + this.border : 0;
  }
  get posAfter() {
    return this.posBefore + this.size;
  }
  get posAtEnd() {
    return this.posAtStart + this.size - 2 * this.border;
  }
  localPosFromDOM(e, n, r) {
    if (this.contentDOM && this.contentDOM.contains(e.nodeType == 1 ? e : e.parentNode))
      if (r < 0) {
        let s, o;
        if (e == this.contentDOM)
          s = e.childNodes[n - 1];
        else {
          for (; e.parentNode != this.contentDOM; )
            e = e.parentNode;
          s = e.previousSibling;
        }
        for (; s && !((o = s.pmViewDesc) && o.parent == this); )
          s = s.previousSibling;
        return s ? this.posBeforeChild(o) + o.size : this.posAtStart;
      } else {
        let s, o;
        if (e == this.contentDOM)
          s = e.childNodes[n];
        else {
          for (; e.parentNode != this.contentDOM; )
            e = e.parentNode;
          s = e.nextSibling;
        }
        for (; s && !((o = s.pmViewDesc) && o.parent == this); )
          s = s.nextSibling;
        return s ? this.posBeforeChild(o) : this.posAtEnd;
      }
    let i;
    if (e == this.dom && this.contentDOM)
      i = n > Je(this.contentDOM);
    else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM))
      i = e.compareDocumentPosition(this.contentDOM) & 2;
    else if (this.dom.firstChild) {
      if (n == 0)
        for (let s = e; ; s = s.parentNode) {
          if (s == this.dom) {
            i = !1;
            break;
          }
          if (s.previousSibling)
            break;
        }
      if (i == null && n == e.childNodes.length)
        for (let s = e; ; s = s.parentNode) {
          if (s == this.dom) {
            i = !0;
            break;
          }
          if (s.nextSibling)
            break;
        }
    }
    return i ?? r > 0 ? this.posAtEnd : this.posAtStart;
  }
  nearestDesc(e, n = !1) {
    for (let r = !0, i = e; i; i = i.parentNode) {
      let s = this.getDesc(i), o;
      if (s && (!n || s.node))
        if (r && (o = s.nodeDOM) && !(o.nodeType == 1 ? o.contains(e.nodeType == 1 ? e : e.parentNode) : o == e))
          r = !1;
        else
          return s;
    }
  }
  getDesc(e) {
    let n = e.pmViewDesc;
    for (let r = n; r; r = r.parent)
      if (r == this)
        return n;
  }
  posFromDOM(e, n, r) {
    for (let i = e; i; i = i.parentNode) {
      let s = this.getDesc(i);
      if (s)
        return s.localPosFromDOM(e, n, r);
    }
    return -1;
  }
  // Find the desc for the node after the given pos, if any. (When a
  // parent node overrode rendering, there might not be one.)
  descAt(e) {
    for (let n = 0, r = 0; n < this.children.length; n++) {
      let i = this.children[n], s = r + i.size;
      if (r == e && s != r) {
        for (; !i.border && i.children.length; )
          i = i.children[0];
        return i;
      }
      if (e < s)
        return i.descAt(e - r - i.border);
      r = s;
    }
  }
  domFromPos(e, n) {
    if (!this.contentDOM)
      return { node: this.dom, offset: 0, atom: e + 1 };
    let r = 0, i = 0;
    for (let s = 0; r < this.children.length; r++) {
      let o = this.children[r], a = s + o.size;
      if (a > e || o instanceof Uu) {
        i = e - s;
        break;
      }
      s = a;
    }
    if (i)
      return this.children[r].domFromPos(i - this.children[r].border, n);
    for (let s; r && !(s = this.children[r - 1]).size && s instanceof Fu && s.side >= 0; r--)
      ;
    if (n <= 0) {
      let s, o = !0;
      for (; s = r ? this.children[r - 1] : null, !(!s || s.dom.parentNode == this.contentDOM); r--, o = !1)
        ;
      return s && n && o && !s.border && !s.domAtom ? s.domFromPos(s.size, n) : { node: this.contentDOM, offset: s ? Je(s.dom) + 1 : 0 };
    } else {
      let s, o = !0;
      for (; s = r < this.children.length ? this.children[r] : null, !(!s || s.dom.parentNode == this.contentDOM); r++, o = !1)
        ;
      return s && o && !s.border && !s.domAtom ? s.domFromPos(0, n) : { node: this.contentDOM, offset: s ? Je(s.dom) : this.contentDOM.childNodes.length };
    }
  }
  // Used to find a DOM range in a single parent for a given changed
  // range.
  parseRange(e, n, r = 0) {
    if (this.children.length == 0)
      return { node: this.contentDOM, from: e, to: n, fromOffset: 0, toOffset: this.contentDOM.childNodes.length };
    let i = -1, s = -1;
    for (let o = r, a = 0; ; a++) {
      let l = this.children[a], c = o + l.size;
      if (i == -1 && e <= c) {
        let d = o + l.border;
        if (e >= d && n <= c - l.border && l.node && l.contentDOM && this.contentDOM.contains(l.contentDOM))
          return l.parseRange(e, n, d);
        e = o;
        for (let u = a; u > 0; u--) {
          let f = this.children[u - 1];
          if (f.size && f.dom.parentNode == this.contentDOM && !f.emptyChildAt(1)) {
            i = Je(f.dom) + 1;
            break;
          }
          e -= f.size;
        }
        i == -1 && (i = 0);
      }
      if (i > -1 && (c > n || a == this.children.length - 1)) {
        n = c;
        for (let d = a + 1; d < this.children.length; d++) {
          let u = this.children[d];
          if (u.size && u.dom.parentNode == this.contentDOM && !u.emptyChildAt(-1)) {
            s = Je(u.dom);
            break;
          }
          n += u.size;
        }
        s == -1 && (s = this.contentDOM.childNodes.length);
        break;
      }
      o = c;
    }
    return { node: this.contentDOM, from: e, to: n, fromOffset: i, toOffset: s };
  }
  emptyChildAt(e) {
    if (this.border || !this.contentDOM || !this.children.length)
      return !1;
    let n = this.children[e < 0 ? 0 : this.children.length - 1];
    return n.size == 0 || n.emptyChildAt(e);
  }
  domAfterPos(e) {
    let { node: n, offset: r } = this.domFromPos(e, 0);
    if (n.nodeType != 1 || r == n.childNodes.length)
      throw new RangeError("No node after pos " + e);
    return n.childNodes[r];
  }
  // View descs are responsible for setting any selection that falls
  // entirely inside of them, so that custom implementations can do
  // custom things with the selection. Note that this falls apart when
  // a selection starts in such a node and ends in another, in which
  // case we just use whatever domFromPos produces as a best effort.
  setSelection(e, n, r, i = !1) {
    let s = Math.min(e, n), o = Math.max(e, n);
    for (let f = 0, p = 0; f < this.children.length; f++) {
      let h = this.children[f], m = p + h.size;
      if (s > p && o < m)
        return h.setSelection(e - p - h.border, n - p - h.border, r, i);
      p = m;
    }
    let a = this.domFromPos(e, e ? -1 : 1), l = n == e ? a : this.domFromPos(n, n ? -1 : 1), c = r.getSelection(), d = !1;
    if ((_t || Xe) && e == n) {
      let { node: f, offset: p } = a;
      if (f.nodeType == 3) {
        if (d = !!(p && f.nodeValue[p - 1] == `
`), d && p == f.nodeValue.length)
          for (let h = f, m; h; h = h.parentNode) {
            if (m = h.nextSibling) {
              m.nodeName == "BR" && (a = l = { node: m.parentNode, offset: Je(m) + 1 });
              break;
            }
            let g = h.pmViewDesc;
            if (g && g.node && g.node.isBlock)
              break;
          }
      } else {
        let h = f.childNodes[p - 1];
        d = h && (h.nodeName == "BR" || h.contentEditable == "false");
      }
    }
    if (_t && c.focusNode && c.focusNode != l.node && c.focusNode.nodeType == 1) {
      let f = c.focusNode.childNodes[c.focusOffset];
      f && f.contentEditable == "false" && (i = !0);
    }
    if (!(i || d && Xe) && Vn(a.node, a.offset, c.anchorNode, c.anchorOffset) && Vn(l.node, l.offset, c.focusNode, c.focusOffset))
      return;
    let u = !1;
    if ((c.extend || e == n) && !d) {
      c.collapse(a.node, a.offset);
      try {
        e != n && c.extend(l.node, l.offset), u = !0;
      } catch {
      }
    }
    if (!u) {
      if (e > n) {
        let p = a;
        a = l, l = p;
      }
      let f = document.createRange();
      f.setEnd(l.node, l.offset), f.setStart(a.node, a.offset), c.removeAllRanges(), c.addRange(f);
    }
  }
  ignoreMutation(e) {
    return !this.contentDOM && e.type != "selection";
  }
  get contentLost() {
    return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM);
  }
  // Remove a subtree of the element tree that has been touched
  // by a DOM change, so that the next update will redraw it.
  markDirty(e, n) {
    for (let r = 0, i = 0; i < this.children.length; i++) {
      let s = this.children[i], o = r + s.size;
      if (r == o ? e <= o && n >= r : e < o && n > r) {
        let a = r + s.border, l = o - s.border;
        if (e >= a && n <= l) {
          this.dirty = e == r || n == o ? _n : Ql, e == a && n == l && (s.contentLost || s.dom.parentNode != this.contentDOM) ? s.dirty = Vt : s.markDirty(e - a, n - a);
          return;
        } else
          s.dirty = s.dom == s.contentDOM && s.dom.parentNode == this.contentDOM && !s.children.length ? _n : Vt;
      }
      r = o;
    }
    this.dirty = _n;
  }
  markParentsDirty() {
    let e = 1;
    for (let n = this.parent; n; n = n.parent, e++) {
      let r = e == 1 ? _n : Ql;
      n.dirty < r && (n.dirty = r);
    }
  }
  get domAtom() {
    return !1;
  }
  get ignoreForCoords() {
    return !1;
  }
}
class Fu extends bi {
  constructor(e, n, r, i) {
    let s, o = n.type.toDOM;
    if (typeof o == "function" && (o = o(r, () => {
      if (!s)
        return i;
      if (s.parent)
        return s.parent.posBeforeChild(s);
    })), !n.type.spec.raw) {
      if (o.nodeType != 1) {
        let a = document.createElement("span");
        a.appendChild(o), o = a;
      }
      o.contentEditable = "false", o.classList.add("ProseMirror-widget");
    }
    super(e, [], o, null), this.widget = n, this.widget = n, s = this;
  }
  matchesWidget(e) {
    return this.dirty == Et && e.type.eq(this.widget.type);
  }
  parseRule() {
    return { ignore: !0 };
  }
  stopEvent(e) {
    let n = this.widget.spec.stopEvent;
    return n ? n(e) : !1;
  }
  ignoreMutation(e) {
    return e.type != "selection" || this.widget.spec.ignoreSelection;
  }
  destroy() {
    this.widget.type.destroy(this.dom), super.destroy();
  }
  get domAtom() {
    return !0;
  }
  get side() {
    return this.widget.type.side;
  }
}
class km extends bi {
  constructor(e, n, r, i) {
    super(e, [], n, null), this.textDOM = r, this.text = i;
  }
  get size() {
    return this.text.length;
  }
  localPosFromDOM(e, n) {
    return e != this.textDOM ? this.posAtStart + (n ? this.size : 0) : this.posAtStart + n;
  }
  domFromPos(e) {
    return { node: this.textDOM, offset: e };
  }
  ignoreMutation(e) {
    return e.type === "characterData" && e.target.nodeValue == e.oldValue;
  }
}
class zn extends bi {
  constructor(e, n, r, i) {
    super(e, [], r, i), this.mark = n;
  }
  static create(e, n, r, i) {
    let s = i.nodeViews[n.type.name], o = s && s(n, i, r);
    return (!o || !o.dom) && (o = Ht.renderSpec(document, n.type.spec.toDOM(n, r))), new zn(e, n, o.dom, o.contentDOM || o.dom);
  }
  parseRule() {
    return this.dirty & Vt || this.mark.type.spec.reparseInView ? null : { mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM };
  }
  matchesMark(e) {
    return this.dirty != Vt && this.mark.eq(e);
  }
  markDirty(e, n) {
    if (super.markDirty(e, n), this.dirty != Et) {
      let r = this.parent;
      for (; !r.node; )
        r = r.parent;
      r.dirty < this.dirty && (r.dirty = this.dirty), this.dirty = Et;
    }
  }
  slice(e, n, r) {
    let i = zn.create(this.parent, this.mark, !0, r), s = this.children, o = this.size;
    n < o && (s = Qo(s, n, o, r)), e > 0 && (s = Qo(s, 0, e, r));
    for (let a = 0; a < s.length; a++)
      s[a].parent = i;
    return i.children = s, i;
  }
}
class hn extends bi {
  constructor(e, n, r, i, s, o, a, l, c) {
    super(e, [], s, o), this.node = n, this.outerDeco = r, this.innerDeco = i, this.nodeDOM = a;
  }
  // By default, a node is rendered using the `toDOM` method from the
  // node type spec. But client code can use the `nodeViews` spec to
  // supply a custom node view, which can influence various aspects of
  // the way the node works.
  //
  // (Using subclassing for this was intentionally decided against,
  // since it'd require exposing a whole slew of finicky
  // implementation details to the user code that they probably will
  // never need.)
  static create(e, n, r, i, s, o) {
    let a = s.nodeViews[n.type.name], l, c = a && a(n, s, () => {
      if (!l)
        return o;
      if (l.parent)
        return l.parent.posBeforeChild(l);
    }, r, i), d = c && c.dom, u = c && c.contentDOM;
    if (n.isText) {
      if (!d)
        d = document.createTextNode(n.text);
      else if (d.nodeType != 3)
        throw new RangeError("Text must be rendered as a DOM text node");
    } else
      d || ({ dom: d, contentDOM: u } = Ht.renderSpec(document, n.type.spec.toDOM(n)));
    !u && !n.isText && d.nodeName != "BR" && (d.hasAttribute("contenteditable") || (d.contentEditable = "false"), n.type.spec.draggable && (d.draggable = !0));
    let f = d;
    return d = qu(d, r, n), c ? l = new Tm(e, n, r, i, d, u || null, f, c, s, o + 1) : n.isText ? new Ps(e, n, r, i, d, f, s) : new hn(e, n, r, i, d, u || null, f, s, o + 1);
  }
  parseRule() {
    if (this.node.type.spec.reparseInView)
      return null;
    let e = { node: this.node.type.name, attrs: this.node.attrs };
    if (this.node.type.whitespace == "pre" && (e.preserveWhitespace = "full"), !this.contentDOM)
      e.getContent = () => this.node.content;
    else if (!this.contentLost)
      e.contentElement = this.contentDOM;
    else {
      for (let n = this.children.length - 1; n >= 0; n--) {
        let r = this.children[n];
        if (this.dom.contains(r.dom.parentNode)) {
          e.contentElement = r.dom.parentNode;
          break;
        }
      }
      e.contentElement || (e.getContent = () => A.empty);
    }
    return e;
  }
  matchesNode(e, n, r) {
    return this.dirty == Et && e.eq(this.node) && Xo(n, this.outerDeco) && r.eq(this.innerDeco);
  }
  get size() {
    return this.node.nodeSize;
  }
  get border() {
    return this.node.isLeaf ? 0 : 1;
  }
  // Syncs `this.children` to match `this.node.content` and the local
  // decorations, possibly introducing nesting for marks. Then, in a
  // separate step, syncs the DOM inside `this.contentDOM` to
  // `this.children`.
  updateChildren(e, n) {
    let r = this.node.inlineContent, i = n, s = e.composing ? this.localCompositionInfo(e, n) : null, o = s && s.pos > -1 ? s : null, a = s && s.pos < 0, l = new Nm(this, o && o.node, e);
    Rm(this.node, this.innerDeco, (c, d, u) => {
      c.spec.marks ? l.syncToMarks(c.spec.marks, r, e) : c.type.side >= 0 && !u && l.syncToMarks(d == this.node.childCount ? ve.none : this.node.child(d).marks, r, e), l.placeWidget(c, e, i);
    }, (c, d, u, f) => {
      l.syncToMarks(c.marks, r, e);
      let p;
      l.findNodeMatch(c, d, u, f) || a && e.state.selection.from > i && e.state.selection.to < i + c.nodeSize && (p = l.findIndexWithChild(s.node)) > -1 && l.updateNodeAt(c, d, u, p, e) || l.updateNextNode(c, d, u, e, f, i) || l.addNode(c, d, u, e, i), i += c.nodeSize;
    }), l.syncToMarks([], r, e), this.node.isTextblock && l.addTextblockHacks(), l.destroyRest(), (l.changed || this.dirty == _n) && (o && this.protectLocalComposition(e, o), Ku(this.contentDOM, this.children, e), wr && Lm(this.dom));
  }
  localCompositionInfo(e, n) {
    let { from: r, to: i } = e.state.selection;
    if (!(e.state.selection instanceof G) || r < n || i > n + this.node.content.size)
      return null;
    let s = e.domSelectionRange(), o = Im(s.focusNode, s.focusOffset);
    if (!o || !this.dom.contains(o.parentNode))
      return null;
    if (this.node.inlineContent) {
      let a = o.nodeValue, l = Dm(this.node.content, a, r - n, i - n);
      return l < 0 ? null : { node: o, pos: l, text: a };
    } else
      return { node: o, pos: -1, text: "" };
  }
  protectLocalComposition(e, { node: n, pos: r, text: i }) {
    if (this.getDesc(n))
      return;
    let s = n;
    for (; s.parentNode != this.contentDOM; s = s.parentNode) {
      for (; s.previousSibling; )
        s.parentNode.removeChild(s.previousSibling);
      for (; s.nextSibling; )
        s.parentNode.removeChild(s.nextSibling);
      s.pmViewDesc && (s.pmViewDesc = void 0);
    }
    let o = new km(this, s, n, i);
    e.input.compositionNodes.push(o), this.children = Qo(this.children, r, r + i.length, e, o);
  }
  // If this desc must be updated to match the given node decoration,
  // do so and return true.
  update(e, n, r, i) {
    return this.dirty == Vt || !e.sameMarkup(this.node) ? !1 : (this.updateInner(e, n, r, i), !0);
  }
  updateInner(e, n, r, i) {
    this.updateOuterDeco(n), this.node = e, this.innerDeco = r, this.contentDOM && this.updateChildren(i, this.posAtStart), this.dirty = Et;
  }
  updateOuterDeco(e) {
    if (Xo(e, this.outerDeco))
      return;
    let n = this.nodeDOM.nodeType != 1, r = this.dom;
    this.dom = Wu(this.dom, this.nodeDOM, Jo(this.outerDeco, this.node, n), Jo(e, this.node, n)), this.dom != r && (r.pmViewDesc = void 0, this.dom.pmViewDesc = this), this.outerDeco = e;
  }
  // Mark this node as being the selected node.
  selectNode() {
    this.nodeDOM.nodeType == 1 && this.nodeDOM.classList.add("ProseMirror-selectednode"), (this.contentDOM || !this.node.type.spec.draggable) && (this.dom.draggable = !0);
  }
  // Remove selected node marking from this node.
  deselectNode() {
    this.nodeDOM.nodeType == 1 && this.nodeDOM.classList.remove("ProseMirror-selectednode"), (this.contentDOM || !this.node.type.spec.draggable) && this.dom.removeAttribute("draggable");
  }
  get domAtom() {
    return this.node.isAtom;
  }
}
function ec(t, e, n, r, i) {
  qu(r, e, t);
  let s = new hn(void 0, t, e, n, r, r, r, i, 0);
  return s.contentDOM && s.updateChildren(i, 0), s;
}
class Ps extends hn {
  constructor(e, n, r, i, s, o, a) {
    super(e, n, r, i, s, null, o, a, 0);
  }
  parseRule() {
    let e = this.nodeDOM.parentNode;
    for (; e && e != this.dom && !e.pmIsDeco; )
      e = e.parentNode;
    return { skip: e || !0 };
  }
  update(e, n, r, i) {
    return this.dirty == Vt || this.dirty != Et && !this.inParent() || !e.sameMarkup(this.node) ? !1 : (this.updateOuterDeco(n), (this.dirty != Et || e.text != this.node.text) && e.text != this.nodeDOM.nodeValue && (this.nodeDOM.nodeValue = e.text, i.trackWrites == this.nodeDOM && (i.trackWrites = null)), this.node = e, this.dirty = Et, !0);
  }
  inParent() {
    let e = this.parent.contentDOM;
    for (let n = this.nodeDOM; n; n = n.parentNode)
      if (n == e)
        return !0;
    return !1;
  }
  domFromPos(e) {
    return { node: this.nodeDOM, offset: e };
  }
  localPosFromDOM(e, n, r) {
    return e == this.nodeDOM ? this.posAtStart + Math.min(n, this.node.text.length) : super.localPosFromDOM(e, n, r);
  }
  ignoreMutation(e) {
    return e.type != "characterData" && e.type != "selection";
  }
  slice(e, n, r) {
    let i = this.node.cut(e, n), s = document.createTextNode(i.text);
    return new Ps(this.parent, i, this.outerDeco, this.innerDeco, s, s, r);
  }
  markDirty(e, n) {
    super.markDirty(e, n), this.dom != this.nodeDOM && (e == 0 || n == this.nodeDOM.nodeValue.length) && (this.dirty = Vt);
  }
  get domAtom() {
    return !1;
  }
}
class Uu extends bi {
  parseRule() {
    return { ignore: !0 };
  }
  matchesHack(e) {
    return this.dirty == Et && this.dom.nodeName == e;
  }
  get domAtom() {
    return !0;
  }
  get ignoreForCoords() {
    return this.dom.nodeName == "IMG";
  }
}
class Tm extends hn {
  constructor(e, n, r, i, s, o, a, l, c, d) {
    super(e, n, r, i, s, o, a, c, d), this.spec = l;
  }
  // A custom `update` method gets to decide whether the update goes
  // through. If it does, and there's a `contentDOM` node, our logic
  // updates the children.
  update(e, n, r, i) {
    if (this.dirty == Vt)
      return !1;
    if (this.spec.update) {
      let s = this.spec.update(e, n, r);
      return s && this.updateInner(e, n, r, i), s;
    } else
      return !this.contentDOM && !e.isLeaf ? !1 : super.update(e, n, r, i);
  }
  selectNode() {
    this.spec.selectNode ? this.spec.selectNode() : super.selectNode();
  }
  deselectNode() {
    this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode();
  }
  setSelection(e, n, r, i) {
    this.spec.setSelection ? this.spec.setSelection(e, n, r) : super.setSelection(e, n, r, i);
  }
  destroy() {
    this.spec.destroy && this.spec.destroy(), super.destroy();
  }
  stopEvent(e) {
    return this.spec.stopEvent ? this.spec.stopEvent(e) : !1;
  }
  ignoreMutation(e) {
    return this.spec.ignoreMutation ? this.spec.ignoreMutation(e) : super.ignoreMutation(e);
  }
}
function Ku(t, e, n) {
  let r = t.firstChild, i = !1;
  for (let s = 0; s < e.length; s++) {
    let o = e[s], a = o.dom;
    if (a.parentNode == t) {
      for (; a != r; )
        r = tc(r), i = !0;
      r = r.nextSibling;
    } else
      i = !0, t.insertBefore(a, r);
    if (o instanceof zn) {
      let l = r ? r.previousSibling : t.lastChild;
      Ku(o.contentDOM, o.children, n), r = l ? l.nextSibling : t.firstChild;
    }
  }
  for (; r; )
    r = tc(r), i = !0;
  i && n.trackWrites == t && (n.trackWrites = null);
}
const Ur = function(t) {
  t && (this.nodeName = t);
};
Ur.prototype = /* @__PURE__ */ Object.create(null);
const Nn = [new Ur()];
function Jo(t, e, n) {
  if (t.length == 0)
    return Nn;
  let r = n ? Nn[0] : new Ur(), i = [r];
  for (let s = 0; s < t.length; s++) {
    let o = t[s].type.attrs;
    if (o) {
      o.nodeName && i.push(r = new Ur(o.nodeName));
      for (let a in o) {
        let l = o[a];
        l != null && (n && i.length == 1 && i.push(r = new Ur(e.isInline ? "span" : "div")), a == "class" ? r.class = (r.class ? r.class + " " : "") + l : a == "style" ? r.style = (r.style ? r.style + ";" : "") + l : a != "nodeName" && (r[a] = l));
      }
    }
  }
  return i;
}
function Wu(t, e, n, r) {
  if (n == Nn && r == Nn)
    return e;
  let i = e;
  for (let s = 0; s < r.length; s++) {
    let o = r[s], a = n[s];
    if (s) {
      let l;
      a && a.nodeName == o.nodeName && i != t && (l = i.parentNode) && l.nodeName.toLowerCase() == o.nodeName || (l = document.createElement(o.nodeName), l.pmIsDeco = !0, l.appendChild(i), a = Nn[0]), i = l;
    }
    _m(i, a || Nn[0], o);
  }
  return i;
}
function _m(t, e, n) {
  for (let r in e)
    r != "class" && r != "style" && r != "nodeName" && !(r in n) && t.removeAttribute(r);
  for (let r in n)
    r != "class" && r != "style" && r != "nodeName" && n[r] != e[r] && t.setAttribute(r, n[r]);
  if (e.class != n.class) {
    let r = e.class ? e.class.split(" ").filter(Boolean) : [], i = n.class ? n.class.split(" ").filter(Boolean) : [];
    for (let s = 0; s < r.length; s++)
      i.indexOf(r[s]) == -1 && t.classList.remove(r[s]);
    for (let s = 0; s < i.length; s++)
      r.indexOf(i[s]) == -1 && t.classList.add(i[s]);
    t.classList.length == 0 && t.removeAttribute("class");
  }
  if (e.style != n.style) {
    if (e.style) {
      let r = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, i;
      for (; i = r.exec(e.style); )
        t.style.removeProperty(i[1]);
    }
    n.style && (t.style.cssText += n.style);
  }
}
function qu(t, e, n) {
  return Wu(t, t, Nn, Jo(e, n, t.nodeType != 1));
}
function Xo(t, e) {
  if (t.length != e.length)
    return !1;
  for (let n = 0; n < t.length; n++)
    if (!t[n].type.eq(e[n].type))
      return !1;
  return !0;
}
function tc(t) {
  let e = t.nextSibling;
  return t.parentNode.removeChild(t), e;
}
class Nm {
  constructor(e, n, r) {
    this.lock = n, this.view = r, this.index = 0, this.stack = [], this.changed = !1, this.top = e, this.preMatch = Am(e.node.content, e);
  }
  // Destroy and remove the children between the given indices in
  // `this.top`.
  destroyBetween(e, n) {
    if (e != n) {
      for (let r = e; r < n; r++)
        this.top.children[r].destroy();
      this.top.children.splice(e, n - e), this.changed = !0;
    }
  }
  // Destroy all remaining children in `this.top`.
  destroyRest() {
    this.destroyBetween(this.index, this.top.children.length);
  }
  // Sync the current stack of mark descs with the given array of
  // marks, reusing existing mark descs when possible.
  syncToMarks(e, n, r) {
    let i = 0, s = this.stack.length >> 1, o = Math.min(s, e.length);
    for (; i < o && (i == s - 1 ? this.top : this.stack[i + 1 << 1]).matchesMark(e[i]) && e[i].type.spec.spanning !== !1; )
      i++;
    for (; i < s; )
      this.destroyRest(), this.top.dirty = Et, this.index = this.stack.pop(), this.top = this.stack.pop(), s--;
    for (; s < e.length; ) {
      this.stack.push(this.top, this.index + 1);
      let a = -1;
      for (let l = this.index; l < Math.min(this.index + 3, this.top.children.length); l++) {
        let c = this.top.children[l];
        if (c.matchesMark(e[s]) && !this.isLocked(c.dom)) {
          a = l;
          break;
        }
      }
      if (a > -1)
        a > this.index && (this.changed = !0, this.destroyBetween(this.index, a)), this.top = this.top.children[this.index];
      else {
        let l = zn.create(this.top, e[s], n, r);
        this.top.children.splice(this.index, 0, l), this.top = l, this.changed = !0;
      }
      this.index = 0, s++;
    }
  }
  // Try to find a node desc matching the given data. Skip over it and
  // return true when successful.
  findNodeMatch(e, n, r, i) {
    let s = -1, o;
    if (i >= this.preMatch.index && (o = this.preMatch.matches[i - this.preMatch.index]).parent == this.top && o.matchesNode(e, n, r))
      s = this.top.children.indexOf(o, this.index);
    else
      for (let a = this.index, l = Math.min(this.top.children.length, a + 5); a < l; a++) {
        let c = this.top.children[a];
        if (c.matchesNode(e, n, r) && !this.preMatch.matched.has(c)) {
          s = a;
          break;
        }
      }
    return s < 0 ? !1 : (this.destroyBetween(this.index, s), this.index++, !0);
  }
  updateNodeAt(e, n, r, i, s) {
    let o = this.top.children[i];
    return o.dirty == Vt && o.dom == o.contentDOM && (o.dirty = _n), o.update(e, n, r, s) ? (this.destroyBetween(this.index, i), this.index++, !0) : !1;
  }
  findIndexWithChild(e) {
    for (; ; ) {
      let n = e.parentNode;
      if (!n)
        return -1;
      if (n == this.top.contentDOM) {
        let r = e.pmViewDesc;
        if (r) {
          for (let i = this.index; i < this.top.children.length; i++)
            if (this.top.children[i] == r)
              return i;
        }
        return -1;
      }
      e = n;
    }
  }
  // Try to update the next node, if any, to the given data. Checks
  // pre-matches to avoid overwriting nodes that could still be used.
  updateNextNode(e, n, r, i, s, o) {
    for (let a = this.index; a < this.top.children.length; a++) {
      let l = this.top.children[a];
      if (l instanceof hn) {
        let c = this.preMatch.matched.get(l);
        if (c != null && c != s)
          return !1;
        let d = l.dom, u, f = this.isLocked(d) && !(e.isText && l.node && l.node.isText && l.nodeDOM.nodeValue == e.text && l.dirty != Vt && Xo(n, l.outerDeco));
        if (!f && l.update(e, n, r, i))
          return this.destroyBetween(this.index, a), l.dom != d && (this.changed = !0), this.index++, !0;
        if (!f && (u = this.recreateWrapper(l, e, n, r, i, o)))
          return this.top.children[this.index] = u, u.contentDOM && (u.dirty = _n, u.updateChildren(i, o + 1), u.dirty = Et), this.changed = !0, this.index++, !0;
        break;
      }
    }
    return !1;
  }
  // When a node with content is replaced by a different node with
  // identical content, move over its children.
  recreateWrapper(e, n, r, i, s, o) {
    if (e.dirty || n.isAtom || !e.children.length || !e.node.content.eq(n.content))
      return null;
    let a = hn.create(this.top, n, r, i, s, o);
    if (a.contentDOM) {
      a.children = e.children, e.children = [];
      for (let l of a.children)
        l.parent = a;
    }
    return e.destroy(), a;
  }
  // Insert the node as a newly created node desc.
  addNode(e, n, r, i, s) {
    let o = hn.create(this.top, e, n, r, i, s);
    o.contentDOM && o.updateChildren(i, s + 1), this.top.children.splice(this.index++, 0, o), this.changed = !0;
  }
  placeWidget(e, n, r) {
    let i = this.index < this.top.children.length ? this.top.children[this.index] : null;
    if (i && i.matchesWidget(e) && (e == i.widget || !i.widget.type.toDOM.parentNode))
      this.index++;
    else {
      let s = new Fu(this.top, e, n, r);
      this.top.children.splice(this.index++, 0, s), this.changed = !0;
    }
  }
  // Make sure a textblock looks and behaves correctly in
  // contentEditable.
  addTextblockHacks() {
    let e = this.top.children[this.index - 1], n = this.top;
    for (; e instanceof zn; )
      n = e, e = n.children[n.children.length - 1];
    (!e || // Empty textblock
    !(e instanceof Ps) || /\n$/.test(e.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(e.node.text)) && ((Xe || We) && e && e.dom.contentEditable == "false" && this.addHackNode("IMG", n), this.addHackNode("BR", this.top));
  }
  addHackNode(e, n) {
    if (n == this.top && this.index < n.children.length && n.children[this.index].matchesHack(e))
      this.index++;
    else {
      let r = document.createElement(e);
      e == "IMG" && (r.className = "ProseMirror-separator", r.alt = ""), e == "BR" && (r.className = "ProseMirror-trailingBreak");
      let i = new Uu(this.top, [], r, null);
      n != this.top ? n.children.push(i) : n.children.splice(this.index++, 0, i), this.changed = !0;
    }
  }
  isLocked(e) {
    return this.lock && (e == this.lock || e.nodeType == 1 && e.contains(this.lock.parentNode));
  }
}
function Am(t, e) {
  let n = e, r = n.children.length, i = t.childCount, s = /* @__PURE__ */ new Map(), o = [];
  e:
    for (; i > 0; ) {
      let a;
      for (; ; )
        if (r) {
          let c = n.children[r - 1];
          if (c instanceof zn)
            n = c, r = c.children.length;
          else {
            a = c, r--;
            break;
          }
        } else {
          if (n == e)
            break e;
          r = n.parent.children.indexOf(n), n = n.parent;
        }
      let l = a.node;
      if (l) {
        if (l != t.child(i - 1))
          break;
        --i, s.set(a, i), o.push(a);
      }
    }
  return { index: i, matched: s, matches: o.reverse() };
}
function Om(t, e) {
  return t.type.side - e.type.side;
}
function Rm(t, e, n, r) {
  let i = e.locals(t), s = 0;
  if (i.length == 0) {
    for (let c = 0; c < t.childCount; c++) {
      let d = t.child(c);
      r(d, i, e.forChild(s, d), c), s += d.nodeSize;
    }
    return;
  }
  let o = 0, a = [], l = null;
  for (let c = 0; ; ) {
    let d, u;
    for (; o < i.length && i[o].to == s; ) {
      let g = i[o++];
      g.widget && (d ? (u || (u = [d])).push(g) : d = g);
    }
    if (d)
      if (u) {
        u.sort(Om);
        for (let g = 0; g < u.length; g++)
          n(u[g], c, !!l);
      } else
        n(d, c, !!l);
    let f, p;
    if (l)
      p = -1, f = l, l = null;
    else if (c < t.childCount)
      p = c, f = t.child(c++);
    else
      break;
    for (let g = 0; g < a.length; g++)
      a[g].to <= s && a.splice(g--, 1);
    for (; o < i.length && i[o].from <= s && i[o].to > s; )
      a.push(i[o++]);
    let h = s + f.nodeSize;
    if (f.isText) {
      let g = h;
      o < i.length && i[o].from < g && (g = i[o].from);
      for (let v = 0; v < a.length; v++)
        a[v].to < g && (g = a[v].to);
      g < h && (l = f.cut(g - s), f = f.cut(0, g - s), h = g, p = -1);
    }
    let m = f.isInline && !f.isLeaf ? a.filter((g) => !g.inline) : a.slice();
    r(f, m, e.forChild(s, f), p), s = h;
  }
}
function Lm(t) {
  if (t.nodeName == "UL" || t.nodeName == "OL") {
    let e = t.style.cssText;
    t.style.cssText = e + "; list-style: square !important", window.getComputedStyle(t).listStyle, t.style.cssText = e;
  }
}
function Im(t, e) {
  for (; ; ) {
    if (t.nodeType == 3)
      return t;
    if (t.nodeType == 1 && e > 0) {
      if (t.childNodes.length > e && t.childNodes[e].nodeType == 3)
        return t.childNodes[e];
      t = t.childNodes[e - 1], e = Dt(t);
    } else if (t.nodeType == 1 && e < t.childNodes.length)
      t = t.childNodes[e], e = 0;
    else
      return null;
  }
}
function Dm(t, e, n, r) {
  for (let i = 0, s = 0; i < t.childCount && s <= r; ) {
    let o = t.child(i++), a = s;
    if (s += o.nodeSize, !o.isText)
      continue;
    let l = o.text;
    for (; i < t.childCount; ) {
      let c = t.child(i++);
      if (s += c.nodeSize, !c.isText)
        break;
      l += c.text;
    }
    if (s >= n) {
      if (s >= r && l.slice(r - e.length - a, r - a) == e)
        return r - e.length;
      let c = a < r ? l.lastIndexOf(e, r - a - 1) : -1;
      if (c >= 0 && c + e.length + a >= n)
        return a + c;
      if (n == r && l.length >= r + e.length - a && l.slice(r - a, r - a + e.length) == e)
        return r;
    }
  }
  return -1;
}
function Qo(t, e, n, r, i) {
  let s = [];
  for (let o = 0, a = 0; o < t.length; o++) {
    let l = t[o], c = a, d = a += l.size;
    c >= n || d <= e ? s.push(l) : (c < e && s.push(l.slice(0, e - c, r)), i && (s.push(i), i = void 0), d > n && s.push(l.slice(n - c, l.size, r)));
  }
  return s;
}
function La(t, e = null) {
  let n = t.domSelectionRange(), r = t.state.doc;
  if (!n.focusNode)
    return null;
  let i = t.docView.nearestDesc(n.focusNode), s = i && i.size == 0, o = t.docView.posFromDOM(n.focusNode, n.focusOffset, 1);
  if (o < 0)
    return null;
  let a = r.resolve(o), l, c;
  if (Bs(n)) {
    for (l = a; i && !i.node; )
      i = i.parent;
    let d = i.node;
    if (i && d.isAtom && Y.isSelectable(d) && i.parent && !(d.isInline && sm(n.focusNode, n.focusOffset, i.dom))) {
      let u = i.posBefore;
      c = new Y(o == u ? a : r.resolve(u));
    }
  } else {
    let d = t.docView.posFromDOM(n.anchorNode, n.anchorOffset, 1);
    if (d < 0)
      return null;
    l = r.resolve(d);
  }
  if (!c) {
    let d = e == "pointer" || t.state.selection.head < a.pos && !s ? 1 : -1;
    c = Ia(t, l, a, d);
  }
  return c;
}
function Zu(t) {
  return t.editable ? t.hasFocus() : ju(t) && document.activeElement && document.activeElement.contains(t.dom);
}
function jt(t, e = !1) {
  let n = t.state.selection;
  if (Gu(t, n), !!Zu(t)) {
    if (!e && t.input.mouseDown && t.input.mouseDown.allowDefault && We) {
      let r = t.domSelectionRange(), i = t.domObserver.currentSelection;
      if (r.anchorNode && i.anchorNode && Vn(r.anchorNode, r.anchorOffset, i.anchorNode, i.anchorOffset)) {
        t.input.mouseDown.delayedSelectionSync = !0, t.domObserver.setCurSelection();
        return;
      }
    }
    if (t.domObserver.disconnectSelection(), t.cursorWrapper)
      Bm(t);
    else {
      let { anchor: r, head: i } = n, s, o;
      nc && !(n instanceof G) && (n.$from.parent.inlineContent || (s = rc(t, n.from)), !n.empty && !n.$from.parent.inlineContent && (o = rc(t, n.to))), t.docView.setSelection(r, i, t.root, e), nc && (s && ic(s), o && ic(o)), n.visible ? t.dom.classList.remove("ProseMirror-hideselection") : (t.dom.classList.add("ProseMirror-hideselection"), "onselectionchange" in document && Hm(t));
    }
    t.domObserver.setCurSelection(), t.domObserver.connectSelection();
  }
}
const nc = Xe || We && lm < 63;
function rc(t, e) {
  let { node: n, offset: r } = t.docView.domFromPos(e, 0), i = r < n.childNodes.length ? n.childNodes[r] : null, s = r ? n.childNodes[r - 1] : null;
  if (Xe && i && i.contentEditable == "false")
    return ho(i);
  if ((!i || i.contentEditable == "false") && (!s || s.contentEditable == "false")) {
    if (i)
      return ho(i);
    if (s)
      return ho(s);
  }
}
function ho(t) {
  return t.contentEditable = "true", Xe && t.draggable && (t.draggable = !1, t.wasDraggable = !0), t;
}
function ic(t) {
  t.contentEditable = "false", t.wasDraggable && (t.draggable = !0, t.wasDraggable = null);
}
function Hm(t) {
  let e = t.dom.ownerDocument;
  e.removeEventListener("selectionchange", t.input.hideSelectionGuard);
  let n = t.domSelectionRange(), r = n.anchorNode, i = n.anchorOffset;
  e.addEventListener("selectionchange", t.input.hideSelectionGuard = () => {
    (n.anchorNode != r || n.anchorOffset != i) && (e.removeEventListener("selectionchange", t.input.hideSelectionGuard), setTimeout(() => {
      (!Zu(t) || t.state.selection.visible) && t.dom.classList.remove("ProseMirror-hideselection");
    }, 20));
  });
}
function Bm(t) {
  let e = t.domSelection(), n = document.createRange(), r = t.cursorWrapper.dom, i = r.nodeName == "IMG";
  i ? n.setEnd(r.parentNode, Je(r) + 1) : n.setEnd(r, 0), n.collapse(!1), e.removeAllRanges(), e.addRange(n), !i && !t.state.selection.visible && st && pn <= 11 && (r.disabled = !0, r.disabled = !1);
}
function Gu(t, e) {
  if (e instanceof Y) {
    let n = t.docView.descAt(e.from);
    n != t.lastSelectedViewDesc && (sc(t), n && n.selectNode(), t.lastSelectedViewDesc = n);
  } else
    sc(t);
}
function sc(t) {
  t.lastSelectedViewDesc && (t.lastSelectedViewDesc.parent && t.lastSelectedViewDesc.deselectNode(), t.lastSelectedViewDesc = void 0);
}
function Ia(t, e, n, r) {
  return t.someProp("createSelectionBetween", (i) => i(t, e, n)) || G.between(e, n, r);
}
function oc(t) {
  return t.editable && !t.hasFocus() ? !1 : ju(t);
}
function ju(t) {
  let e = t.domSelectionRange();
  if (!e.anchorNode)
    return !1;
  try {
    return t.dom.contains(e.anchorNode.nodeType == 3 ? e.anchorNode.parentNode : e.anchorNode) && (t.editable || t.dom.contains(e.focusNode.nodeType == 3 ? e.focusNode.parentNode : e.focusNode));
  } catch {
    return !1;
  }
}
function Pm(t) {
  let e = t.docView.domFromPos(t.state.selection.anchor, 0), n = t.domSelectionRange();
  return Vn(e.node, e.offset, n.anchorNode, n.anchorOffset);
}
function ea(t, e) {
  let { $anchor: n, $head: r } = t.selection, i = e > 0 ? n.max(r) : n.min(r), s = i.parent.inlineContent ? i.depth ? t.doc.resolve(e > 0 ? i.after() : i.before()) : null : i;
  return s && te.findFrom(s, e);
}
function en(t, e) {
  return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()), !0;
}
function ac(t, e, n) {
  let r = t.state.selection;
  if (r instanceof G)
    if (n.indexOf("s") > -1) {
      let { $head: i } = r, s = i.textOffset ? null : e < 0 ? i.nodeBefore : i.nodeAfter;
      if (!s || s.isText || !s.isLeaf)
        return !1;
      let o = t.state.doc.resolve(i.pos + s.nodeSize * (e < 0 ? -1 : 1));
      return en(t, new G(r.$anchor, o));
    } else if (r.empty) {
      if (t.endOfTextblock(e > 0 ? "forward" : "backward")) {
        let i = ea(t.state, e);
        return i && i instanceof Y ? en(t, i) : !1;
      } else if (!(yt && n.indexOf("m") > -1)) {
        let i = r.$head, s = i.textOffset ? null : e < 0 ? i.nodeBefore : i.nodeAfter, o;
        if (!s || s.isText)
          return !1;
        let a = e < 0 ? i.pos - s.nodeSize : i.pos;
        return s.isAtom || (o = t.docView.descAt(a)) && !o.contentDOM ? Y.isSelectable(s) ? en(t, new Y(e < 0 ? t.state.doc.resolve(i.pos - s.nodeSize) : i)) : gi ? en(t, new G(t.state.doc.resolve(e < 0 ? a : a + s.nodeSize))) : !1 : !1;
      }
    } else
      return !1;
  else {
    if (r instanceof Y && r.node.isInline)
      return en(t, new G(e > 0 ? r.$to : r.$from));
    {
      let i = ea(t.state, e);
      return i ? en(t, i) : !1;
    }
  }
}
function ss(t) {
  return t.nodeType == 3 ? t.nodeValue.length : t.childNodes.length;
}
function Kr(t, e) {
  let n = t.pmViewDesc;
  return n && n.size == 0 && (e < 0 || t.nextSibling || t.nodeName != "BR");
}
function Jn(t, e) {
  return e < 0 ? $m(t) : Vm(t);
}
function $m(t) {
  let e = t.domSelectionRange(), n = e.focusNode, r = e.focusOffset;
  if (!n)
    return;
  let i, s, o = !1;
  for (_t && n.nodeType == 1 && r < ss(n) && Kr(n.childNodes[r], -1) && (o = !0); ; )
    if (r > 0) {
      if (n.nodeType != 1)
        break;
      {
        let a = n.childNodes[r - 1];
        if (Kr(a, -1))
          i = n, s = --r;
        else if (a.nodeType == 3)
          n = a, r = n.nodeValue.length;
        else
          break;
      }
    } else {
      if (Yu(n))
        break;
      {
        let a = n.previousSibling;
        for (; a && Kr(a, -1); )
          i = n.parentNode, s = Je(a), a = a.previousSibling;
        if (a)
          n = a, r = ss(n);
        else {
          if (n = n.parentNode, n == t.dom)
            break;
          r = 0;
        }
      }
    }
  o ? ta(t, n, r) : i && ta(t, i, s);
}
function Vm(t) {
  let e = t.domSelectionRange(), n = e.focusNode, r = e.focusOffset;
  if (!n)
    return;
  let i = ss(n), s, o;
  for (; ; )
    if (r < i) {
      if (n.nodeType != 1)
        break;
      let a = n.childNodes[r];
      if (Kr(a, 1))
        s = n, o = ++r;
      else
        break;
    } else {
      if (Yu(n))
        break;
      {
        let a = n.nextSibling;
        for (; a && Kr(a, 1); )
          s = a.parentNode, o = Je(a) + 1, a = a.nextSibling;
        if (a)
          n = a, r = 0, i = ss(n);
        else {
          if (n = n.parentNode, n == t.dom)
            break;
          r = i = 0;
        }
      }
    }
  s && ta(t, s, o);
}
function Yu(t) {
  let e = t.pmViewDesc;
  return e && e.node && e.node.isBlock;
}
function zm(t, e) {
  for (; t && e == t.childNodes.length && !Oa(t); )
    e = Je(t) + 1, t = t.parentNode;
  for (; t && e < t.childNodes.length; ) {
    let n = t.childNodes[e];
    if (n.nodeType == 3)
      return n;
    if (n.nodeType == 1 && n.contentEditable == "false")
      break;
    t = n, e = 0;
  }
}
function Fm(t, e) {
  for (; t && !e && !Oa(t); )
    e = Je(t), t = t.parentNode;
  for (; t && e; ) {
    let n = t.childNodes[e - 1];
    if (n.nodeType == 3)
      return n;
    if (n.nodeType == 1 && n.contentEditable == "false")
      break;
    t = n, e = t.childNodes.length;
  }
}
function ta(t, e, n) {
  if (e.nodeType != 3) {
    let s, o;
    (o = zm(e, n)) ? (e = o, n = 0) : (s = Fm(e, n)) && (e = s, n = s.nodeValue.length);
  }
  let r = t.domSelection();
  if (Bs(r)) {
    let s = document.createRange();
    s.setEnd(e, n), s.setStart(e, n), r.removeAllRanges(), r.addRange(s);
  } else
    r.extend && r.extend(e, n);
  t.domObserver.setCurSelection();
  let { state: i } = t;
  setTimeout(() => {
    t.state == i && jt(t);
  }, 50);
}
function lc(t, e) {
  let n = t.state.doc.resolve(e);
  if (!(We || cm) && n.parent.inlineContent) {
    let i = t.coordsAtPos(e);
    if (e > n.start()) {
      let s = t.coordsAtPos(e - 1), o = (s.top + s.bottom) / 2;
      if (o > i.top && o < i.bottom && Math.abs(s.left - i.left) > 1)
        return s.left < i.left ? "ltr" : "rtl";
    }
    if (e < n.end()) {
      let s = t.coordsAtPos(e + 1), o = (s.top + s.bottom) / 2;
      if (o > i.top && o < i.bottom && Math.abs(s.left - i.left) > 1)
        return s.left > i.left ? "ltr" : "rtl";
    }
  }
  return getComputedStyle(t.dom).direction == "rtl" ? "rtl" : "ltr";
}
function cc(t, e, n) {
  let r = t.state.selection;
  if (r instanceof G && !r.empty || n.indexOf("s") > -1 || yt && n.indexOf("m") > -1)
    return !1;
  let { $from: i, $to: s } = r;
  if (!i.parent.inlineContent || t.endOfTextblock(e < 0 ? "up" : "down")) {
    let o = ea(t.state, e);
    if (o && o instanceof Y)
      return en(t, o);
  }
  if (!i.parent.inlineContent) {
    let o = e < 0 ? i : s, a = r instanceof wt ? te.near(o, e) : te.findFrom(o, e);
    return a ? en(t, a) : !1;
  }
  return !1;
}
function dc(t, e) {
  if (!(t.state.selection instanceof G))
    return !0;
  let { $head: n, $anchor: r, empty: i } = t.state.selection;
  if (!n.sameParent(r))
    return !0;
  if (!i)
    return !1;
  if (t.endOfTextblock(e > 0 ? "forward" : "backward"))
    return !0;
  let s = !n.textOffset && (e < 0 ? n.nodeBefore : n.nodeAfter);
  if (s && !s.isText) {
    let o = t.state.tr;
    return e < 0 ? o.delete(n.pos - s.nodeSize, n.pos) : o.delete(n.pos, n.pos + s.nodeSize), t.dispatch(o), !0;
  }
  return !1;
}
function uc(t, e, n) {
  t.domObserver.stop(), e.contentEditable = n, t.domObserver.start();
}
function Um(t) {
  if (!Xe || t.state.selection.$head.parentOffset > 0)
    return !1;
  let { focusNode: e, focusOffset: n } = t.domSelectionRange();
  if (e && e.nodeType == 1 && n == 0 && e.firstChild && e.firstChild.contentEditable == "false") {
    let r = e.firstChild;
    uc(t, r, "true"), setTimeout(() => uc(t, r, "false"), 20);
  }
  return !1;
}
function Km(t) {
  let e = "";
  return t.ctrlKey && (e += "c"), t.metaKey && (e += "m"), t.altKey && (e += "a"), t.shiftKey && (e += "s"), e;
}
function Wm(t, e) {
  let n = e.keyCode, r = Km(e);
  if (n == 8 || yt && n == 72 && r == "c")
    return dc(t, -1) || Jn(t, -1);
  if (n == 46 && !e.shiftKey || yt && n == 68 && r == "c")
    return dc(t, 1) || Jn(t, 1);
  if (n == 13 || n == 27)
    return !0;
  if (n == 37 || yt && n == 66 && r == "c") {
    let i = n == 37 ? lc(t, t.state.selection.from) == "ltr" ? -1 : 1 : -1;
    return ac(t, i, r) || Jn(t, i);
  } else if (n == 39 || yt && n == 70 && r == "c") {
    let i = n == 39 ? lc(t, t.state.selection.from) == "ltr" ? 1 : -1 : 1;
    return ac(t, i, r) || Jn(t, i);
  } else {
    if (n == 38 || yt && n == 80 && r == "c")
      return cc(t, -1, r) || Jn(t, -1);
    if (n == 40 || yt && n == 78 && r == "c")
      return Um(t) || cc(t, 1, r) || Jn(t, 1);
    if (r == (yt ? "m" : "c") && (n == 66 || n == 73 || n == 89 || n == 90))
      return !0;
  }
  return !1;
}
function Ju(t, e) {
  t.someProp("transformCopied", (p) => {
    e = p(e, t);
  });
  let n = [], { content: r, openStart: i, openEnd: s } = e;
  for (; i > 1 && s > 1 && r.childCount == 1 && r.firstChild.childCount == 1; ) {
    i--, s--;
    let p = r.firstChild;
    n.push(p.type.name, p.attrs != p.type.defaultAttrs ? p.attrs : null), r = p.content;
  }
  let o = t.someProp("clipboardSerializer") || Ht.fromSchema(t.state.schema), a = rf(), l = a.createElement("div");
  l.appendChild(o.serializeFragment(r, { document: a }));
  let c = l.firstChild, d, u = 0;
  for (; c && c.nodeType == 1 && (d = nf[c.nodeName.toLowerCase()]); ) {
    for (let p = d.length - 1; p >= 0; p--) {
      let h = a.createElement(d[p]);
      for (; l.firstChild; )
        h.appendChild(l.firstChild);
      l.appendChild(h), u++;
    }
    c = l.firstChild;
  }
  c && c.nodeType == 1 && c.setAttribute("data-pm-slice", `${i} ${s}${u ? ` -${u}` : ""} ${JSON.stringify(n)}`);
  let f = t.someProp("clipboardTextSerializer", (p) => p(e, t)) || e.content.textBetween(0, e.content.size, `

`);
  return { dom: l, text: f };
}
function Xu(t, e, n, r, i) {
  let s = i.parent.type.spec.code, o, a;
  if (!n && !e)
    return null;
  let l = e && (r || s || !n);
  if (l) {
    if (t.someProp("transformPastedText", (f) => {
      e = f(e, s || r, t);
    }), s)
      return e ? new B(A.from(t.state.schema.text(e.replace(/\r\n?/g, `
`))), 0, 0) : B.empty;
    let u = t.someProp("clipboardTextParser", (f) => f(e, i, r, t));
    if (u)
      a = u;
    else {
      let f = i.marks(), { schema: p } = t.state, h = Ht.fromSchema(p);
      o = document.createElement("div"), e.split(/(?:\r\n?|\n)+/).forEach((m) => {
        let g = o.appendChild(document.createElement("p"));
        m && g.appendChild(h.serializeNode(p.text(m, f)));
      });
    }
  } else
    t.someProp("transformPastedHTML", (u) => {
      n = u(n, t);
    }), o = Gm(n), gi && jm(o);
  let c = o && o.querySelector("[data-pm-slice]"), d = c && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice") || "");
  if (d && d[3])
    for (let u = +d[3]; u > 0; u--) {
      let f = o.firstChild;
      for (; f && f.nodeType != 1; )
        f = f.nextSibling;
      if (!f)
        break;
      o = f;
    }
  if (a || (a = (t.someProp("clipboardParser") || t.someProp("domParser") || br.fromSchema(t.state.schema)).parseSlice(o, {
    preserveWhitespace: !!(l || d),
    context: i,
    ruleFromNode(f) {
      return f.nodeName == "BR" && !f.nextSibling && f.parentNode && !qm.test(f.parentNode.nodeName) ? { ignore: !0 } : null;
    }
  })), d)
    a = Ym(fc(a, +d[1], +d[2]), d[4]);
  else if (a = B.maxOpen(Zm(a.content, i), !0), a.openStart || a.openEnd) {
    let u = 0, f = 0;
    for (let p = a.content.firstChild; u < a.openStart && !p.type.spec.isolating; u++, p = p.firstChild)
      ;
    for (let p = a.content.lastChild; f < a.openEnd && !p.type.spec.isolating; f++, p = p.lastChild)
      ;
    a = fc(a, u, f);
  }
  return t.someProp("transformPasted", (u) => {
    a = u(a, t);
  }), a;
}
const qm = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;
function Zm(t, e) {
  if (t.childCount < 2)
    return t;
  for (let n = e.depth; n >= 0; n--) {
    let i = e.node(n).contentMatchAt(e.index(n)), s, o = [];
    if (t.forEach((a) => {
      if (!o)
        return;
      let l = i.findWrapping(a.type), c;
      if (!l)
        return o = null;
      if (c = o.length && s.length && ef(l, s, a, o[o.length - 1], 0))
        o[o.length - 1] = c;
      else {
        o.length && (o[o.length - 1] = tf(o[o.length - 1], s.length));
        let d = Qu(a, l);
        o.push(d), i = i.matchType(d.type), s = l;
      }
    }), o)
      return A.from(o);
  }
  return t;
}
function Qu(t, e, n = 0) {
  for (let r = e.length - 1; r >= n; r--)
    t = e[r].create(null, A.from(t));
  return t;
}
function ef(t, e, n, r, i) {
  if (i < t.length && i < e.length && t[i] == e[i]) {
    let s = ef(t, e, n, r.lastChild, i + 1);
    if (s)
      return r.copy(r.content.replaceChild(r.childCount - 1, s));
    if (r.contentMatchAt(r.childCount).matchType(i == t.length - 1 ? n.type : t[i + 1]))
      return r.copy(r.content.append(A.from(Qu(n, t, i + 1))));
  }
}
function tf(t, e) {
  if (e == 0)
    return t;
  let n = t.content.replaceChild(t.childCount - 1, tf(t.lastChild, e - 1)), r = t.contentMatchAt(t.childCount).fillBefore(A.empty, !0);
  return t.copy(n.append(r));
}
function na(t, e, n, r, i, s) {
  let o = e < 0 ? t.firstChild : t.lastChild, a = o.content;
  return t.childCount > 1 && (s = 0), i < r - 1 && (a = na(a, e, n, r, i + 1, s)), i >= n && (a = e < 0 ? o.contentMatchAt(0).fillBefore(a, s <= i).append(a) : a.append(o.contentMatchAt(o.childCount).fillBefore(A.empty, !0))), t.replaceChild(e < 0 ? 0 : t.childCount - 1, o.copy(a));
}
function fc(t, e, n) {
  return e < t.openStart && (t = new B(na(t.content, -1, e, t.openStart, 0, t.openEnd), e, t.openEnd)), n < t.openEnd && (t = new B(na(t.content, 1, n, t.openEnd, 0, 0), t.openStart, n)), t;
}
const nf = {
  thead: ["table"],
  tbody: ["table"],
  tfoot: ["table"],
  caption: ["table"],
  colgroup: ["table"],
  col: ["table", "colgroup"],
  tr: ["table", "tbody"],
  td: ["table", "tbody", "tr"],
  th: ["table", "tbody", "tr"]
};
let pc = null;
function rf() {
  return pc || (pc = document.implementation.createHTMLDocument("title"));
}
function Gm(t) {
  let e = /^(\s*<meta [^>]*>)*/.exec(t);
  e && (t = t.slice(e[0].length));
  let n = rf().createElement("div"), r = /<([a-z][^>\s]+)/i.exec(t), i;
  if ((i = r && nf[r[1].toLowerCase()]) && (t = i.map((s) => "<" + s + ">").join("") + t + i.map((s) => "</" + s + ">").reverse().join("")), n.innerHTML = t, i)
    for (let s = 0; s < i.length; s++)
      n = n.querySelector(i[s]) || n;
  return n;
}
function jm(t) {
  let e = t.querySelectorAll(We ? "span:not([class]):not([style])" : "span.Apple-converted-space");
  for (let n = 0; n < e.length; n++) {
    let r = e[n];
    r.childNodes.length == 1 && r.textContent == " " && r.parentNode && r.parentNode.replaceChild(t.ownerDocument.createTextNode(" "), r);
  }
}
function Ym(t, e) {
  if (!t.size)
    return t;
  let n = t.content.firstChild.type.schema, r;
  try {
    r = JSON.parse(e);
  } catch {
    return t;
  }
  let { content: i, openStart: s, openEnd: o } = t;
  for (let a = r.length - 2; a >= 0; a -= 2) {
    let l = n.nodes[r[a]];
    if (!l || l.hasRequiredAttrs())
      break;
    i = A.from(l.create(r[a + 1], i)), s++, o++;
  }
  return new B(i, s, o);
}
const Qe = {}, et = {}, Jm = { touchstart: !0, touchmove: !0 };
class Xm {
  constructor() {
    this.shiftKey = !1, this.mouseDown = null, this.lastKeyCode = null, this.lastKeyCodeTime = 0, this.lastClick = { time: 0, x: 0, y: 0, type: "" }, this.lastSelectionOrigin = null, this.lastSelectionTime = 0, this.lastIOSEnter = 0, this.lastIOSEnterFallbackTimeout = -1, this.lastFocus = 0, this.lastTouch = 0, this.lastAndroidDelete = 0, this.composing = !1, this.composingTimeout = -1, this.compositionNodes = [], this.compositionEndedAt = -2e8, this.compositionID = 1, this.compositionPendingChanges = 0, this.domChangeCount = 0, this.eventHandlers = /* @__PURE__ */ Object.create(null), this.hideSelectionGuard = null;
  }
}
function Qm(t) {
  for (let e in Qe) {
    let n = Qe[e];
    t.dom.addEventListener(e, t.input.eventHandlers[e] = (r) => {
      tg(t, r) && !Da(t, r) && (t.editable || !(r.type in et)) && n(t, r);
    }, Jm[e] ? { passive: !0 } : void 0);
  }
  Xe && t.dom.addEventListener("input", () => null), ra(t);
}
function cn(t, e) {
  t.input.lastSelectionOrigin = e, t.input.lastSelectionTime = Date.now();
}
function eg(t) {
  t.domObserver.stop();
  for (let e in t.input.eventHandlers)
    t.dom.removeEventListener(e, t.input.eventHandlers[e]);
  clearTimeout(t.input.composingTimeout), clearTimeout(t.input.lastIOSEnterFallbackTimeout);
}
function ra(t) {
  t.someProp("handleDOMEvents", (e) => {
    for (let n in e)
      t.input.eventHandlers[n] || t.dom.addEventListener(n, t.input.eventHandlers[n] = (r) => Da(t, r));
  });
}
function Da(t, e) {
  return t.someProp("handleDOMEvents", (n) => {
    let r = n[e.type];
    return r ? r(t, e) || e.defaultPrevented : !1;
  });
}
function tg(t, e) {
  if (!e.bubbles)
    return !0;
  if (e.defaultPrevented)
    return !1;
  for (let n = e.target; n != t.dom; n = n.parentNode)
    if (!n || n.nodeType == 11 || n.pmViewDesc && n.pmViewDesc.stopEvent(e))
      return !1;
  return !0;
}
function ng(t, e) {
  !Da(t, e) && Qe[e.type] && (t.editable || !(e.type in et)) && Qe[e.type](t, e);
}
et.keydown = (t, e) => {
  let n = e;
  if (t.input.shiftKey = n.keyCode == 16 || n.shiftKey, !of(t, n) && (t.input.lastKeyCode = n.keyCode, t.input.lastKeyCodeTime = Date.now(), !(kt && We && n.keyCode == 13)))
    if (n.keyCode != 229 && t.domObserver.forceFlush(), wr && n.keyCode == 13 && !n.ctrlKey && !n.altKey && !n.metaKey) {
      let r = Date.now();
      t.input.lastIOSEnter = r, t.input.lastIOSEnterFallbackTimeout = setTimeout(() => {
        t.input.lastIOSEnter == r && (t.someProp("handleKeyDown", (i) => i(t, Mn(13, "Enter"))), t.input.lastIOSEnter = 0);
      }, 200);
    } else
      t.someProp("handleKeyDown", (r) => r(t, n)) || Wm(t, n) ? n.preventDefault() : cn(t, "key");
};
et.keyup = (t, e) => {
  e.keyCode == 16 && (t.input.shiftKey = !1);
};
et.keypress = (t, e) => {
  let n = e;
  if (of(t, n) || !n.charCode || n.ctrlKey && !n.altKey || yt && n.metaKey)
    return;
  if (t.someProp("handleKeyPress", (i) => i(t, n))) {
    n.preventDefault();
    return;
  }
  let r = t.state.selection;
  if (!(r instanceof G) || !r.$from.sameParent(r.$to)) {
    let i = String.fromCharCode(n.charCode);
    !/[\r\n]/.test(i) && !t.someProp("handleTextInput", (s) => s(t, r.$from.pos, r.$to.pos, i)) && t.dispatch(t.state.tr.insertText(i).scrollIntoView()), n.preventDefault();
  }
};
function $s(t) {
  return { left: t.clientX, top: t.clientY };
}
function rg(t, e) {
  let n = e.x - t.clientX, r = e.y - t.clientY;
  return n * n + r * r < 100;
}
function Ha(t, e, n, r, i) {
  if (r == -1)
    return !1;
  let s = t.state.doc.resolve(r);
  for (let o = s.depth + 1; o > 0; o--)
    if (t.someProp(e, (a) => o > s.depth ? a(t, n, s.nodeAfter, s.before(o), i, !0) : a(t, n, s.node(o), s.before(o), i, !1)))
      return !0;
  return !1;
}
function gr(t, e, n) {
  t.focused || t.focus();
  let r = t.state.tr.setSelection(e);
  n == "pointer" && r.setMeta("pointer", !0), t.dispatch(r);
}
function ig(t, e) {
  if (e == -1)
    return !1;
  let n = t.state.doc.resolve(e), r = n.nodeAfter;
  return r && r.isAtom && Y.isSelectable(r) ? (gr(t, new Y(n), "pointer"), !0) : !1;
}
function sg(t, e) {
  if (e == -1)
    return !1;
  let n = t.state.selection, r, i;
  n instanceof Y && (r = n.node);
  let s = t.state.doc.resolve(e);
  for (let o = s.depth + 1; o > 0; o--) {
    let a = o > s.depth ? s.nodeAfter : s.node(o);
    if (Y.isSelectable(a)) {
      r && n.$from.depth > 0 && o >= n.$from.depth && s.before(n.$from.depth + 1) == n.$from.pos ? i = s.before(n.$from.depth) : i = s.before(o);
      break;
    }
  }
  return i != null ? (gr(t, Y.create(t.state.doc, i), "pointer"), !0) : !1;
}
function og(t, e, n, r, i) {
  return Ha(t, "handleClickOn", e, n, r) || t.someProp("handleClick", (s) => s(t, e, r)) || (i ? sg(t, n) : ig(t, n));
}
function ag(t, e, n, r) {
  return Ha(t, "handleDoubleClickOn", e, n, r) || t.someProp("handleDoubleClick", (i) => i(t, e, r));
}
function lg(t, e, n, r) {
  return Ha(t, "handleTripleClickOn", e, n, r) || t.someProp("handleTripleClick", (i) => i(t, e, r)) || cg(t, n, r);
}
function cg(t, e, n) {
  if (n.button != 0)
    return !1;
  let r = t.state.doc;
  if (e == -1)
    return r.inlineContent ? (gr(t, G.create(r, 0, r.content.size), "pointer"), !0) : !1;
  let i = r.resolve(e);
  for (let s = i.depth + 1; s > 0; s--) {
    let o = s > i.depth ? i.nodeAfter : i.node(s), a = i.before(s);
    if (o.inlineContent)
      gr(t, G.create(r, a + 1, a + 1 + o.content.size), "pointer");
    else if (Y.isSelectable(o))
      gr(t, Y.create(r, a), "pointer");
    else
      continue;
    return !0;
  }
}
function Ba(t) {
  return as(t);
}
const sf = yt ? "metaKey" : "ctrlKey";
Qe.mousedown = (t, e) => {
  let n = e;
  t.input.shiftKey = n.shiftKey;
  let r = Ba(t), i = Date.now(), s = "singleClick";
  i - t.input.lastClick.time < 500 && rg(n, t.input.lastClick) && !n[sf] && (t.input.lastClick.type == "singleClick" ? s = "doubleClick" : t.input.lastClick.type == "doubleClick" && (s = "tripleClick")), t.input.lastClick = { time: i, x: n.clientX, y: n.clientY, type: s };
  let o = t.posAtCoords($s(n));
  o && (s == "singleClick" ? (t.input.mouseDown && t.input.mouseDown.done(), t.input.mouseDown = new dg(t, o, n, !!r)) : (s == "doubleClick" ? ag : lg)(t, o.pos, o.inside, n) ? n.preventDefault() : cn(t, "pointer"));
};
class dg {
  constructor(e, n, r, i) {
    this.view = e, this.pos = n, this.event = r, this.flushed = i, this.delayedSelectionSync = !1, this.mightDrag = null, this.startDoc = e.state.doc, this.selectNode = !!r[sf], this.allowDefault = r.shiftKey;
    let s, o;
    if (n.inside > -1)
      s = e.state.doc.nodeAt(n.inside), o = n.inside;
    else {
      let d = e.state.doc.resolve(n.pos);
      s = d.parent, o = d.depth ? d.before() : 0;
    }
    const a = i ? null : r.target, l = a ? e.docView.nearestDesc(a, !0) : null;
    this.target = l ? l.dom : null;
    let { selection: c } = e.state;
    (r.button == 0 && s.type.spec.draggable && s.type.spec.selectable !== !1 || c instanceof Y && c.from <= o && c.to > o) && (this.mightDrag = {
      node: s,
      pos: o,
      addAttr: !!(this.target && !this.target.draggable),
      setUneditable: !!(this.target && _t && !this.target.hasAttribute("contentEditable"))
    }), this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable) && (this.view.domObserver.stop(), this.mightDrag.addAttr && (this.target.draggable = !0), this.mightDrag.setUneditable && setTimeout(() => {
      this.view.input.mouseDown == this && this.target.setAttribute("contentEditable", "false");
    }, 20), this.view.domObserver.start()), e.root.addEventListener("mouseup", this.up = this.up.bind(this)), e.root.addEventListener("mousemove", this.move = this.move.bind(this)), cn(e, "pointer");
  }
  done() {
    this.view.root.removeEventListener("mouseup", this.up), this.view.root.removeEventListener("mousemove", this.move), this.mightDrag && this.target && (this.view.domObserver.stop(), this.mightDrag.addAttr && this.target.removeAttribute("draggable"), this.mightDrag.setUneditable && this.target.removeAttribute("contentEditable"), this.view.domObserver.start()), this.delayedSelectionSync && setTimeout(() => jt(this.view)), this.view.input.mouseDown = null;
  }
  up(e) {
    if (this.done(), !this.view.dom.contains(e.target))
      return;
    let n = this.pos;
    this.view.state.doc != this.startDoc && (n = this.view.posAtCoords($s(e))), this.updateAllowDefault(e), this.allowDefault || !n ? cn(this.view, "pointer") : og(this.view, n.pos, n.inside, e, this.selectNode) ? e.preventDefault() : e.button == 0 && (this.flushed || // Safari ignores clicks on draggable elements
    Xe && this.mightDrag && !this.mightDrag.node.isAtom || // Chrome will sometimes treat a node selection as a
    // cursor, but still report that the node is selected
    // when asked through getSelection. You'll then get a
    // situation where clicking at the point where that
    // (hidden) cursor is doesn't change the selection, and
    // thus doesn't get a reaction from ProseMirror. This
    // works around that.
    We && !this.view.state.selection.visible && Math.min(Math.abs(n.pos - this.view.state.selection.from), Math.abs(n.pos - this.view.state.selection.to)) <= 2) ? (gr(this.view, te.near(this.view.state.doc.resolve(n.pos)), "pointer"), e.preventDefault()) : cn(this.view, "pointer");
  }
  move(e) {
    this.updateAllowDefault(e), cn(this.view, "pointer"), e.buttons == 0 && this.done();
  }
  updateAllowDefault(e) {
    !this.allowDefault && (Math.abs(this.event.x - e.clientX) > 4 || Math.abs(this.event.y - e.clientY) > 4) && (this.allowDefault = !0);
  }
}
Qe.touchstart = (t) => {
  t.input.lastTouch = Date.now(), Ba(t), cn(t, "pointer");
};
Qe.touchmove = (t) => {
  t.input.lastTouch = Date.now(), cn(t, "pointer");
};
Qe.contextmenu = (t) => Ba(t);
function of(t, e) {
  return t.composing ? !0 : Xe && Math.abs(e.timeStamp - t.input.compositionEndedAt) < 500 ? (t.input.compositionEndedAt = -2e8, !0) : !1;
}
const ug = kt ? 5e3 : -1;
et.compositionstart = et.compositionupdate = (t) => {
  if (!t.composing) {
    t.domObserver.flush();
    let { state: e } = t, n = e.selection.$from;
    if (e.selection.empty && (e.storedMarks || !n.textOffset && n.parentOffset && n.nodeBefore.marks.some((r) => r.type.spec.inclusive === !1)))
      t.markCursor = t.state.storedMarks || n.marks(), as(t, !0), t.markCursor = null;
    else if (as(t), _t && e.selection.empty && n.parentOffset && !n.textOffset && n.nodeBefore.marks.length) {
      let r = t.domSelectionRange();
      for (let i = r.focusNode, s = r.focusOffset; i && i.nodeType == 1 && s != 0; ) {
        let o = s < 0 ? i.lastChild : i.childNodes[s - 1];
        if (!o)
          break;
        if (o.nodeType == 3) {
          t.domSelection().collapse(o, o.nodeValue.length);
          break;
        } else
          i = o, s = -1;
      }
    }
    t.input.composing = !0;
  }
  af(t, ug);
};
et.compositionend = (t, e) => {
  t.composing && (t.input.composing = !1, t.input.compositionEndedAt = e.timeStamp, t.input.compositionPendingChanges = t.domObserver.pendingRecords().length ? t.input.compositionID : 0, t.input.compositionPendingChanges && Promise.resolve().then(() => t.domObserver.flush()), t.input.compositionID++, af(t, 20));
};
function af(t, e) {
  clearTimeout(t.input.composingTimeout), e > -1 && (t.input.composingTimeout = setTimeout(() => as(t), e));
}
function lf(t) {
  for (t.composing && (t.input.composing = !1, t.input.compositionEndedAt = fg()); t.input.compositionNodes.length > 0; )
    t.input.compositionNodes.pop().markParentsDirty();
}
function fg() {
  let t = document.createEvent("Event");
  return t.initEvent("event", !0, !0), t.timeStamp;
}
function as(t, e = !1) {
  if (!(kt && t.domObserver.flushingSoon >= 0)) {
    if (t.domObserver.forceFlush(), lf(t), e || t.docView && t.docView.dirty) {
      let n = La(t);
      return n && !n.eq(t.state.selection) ? t.dispatch(t.state.tr.setSelection(n)) : t.updateState(t.state), !0;
    }
    return !1;
  }
}
function pg(t, e) {
  if (!t.dom.parentNode)
    return;
  let n = t.dom.parentNode.appendChild(document.createElement("div"));
  n.appendChild(e), n.style.cssText = "position: fixed; left: -10000px; top: 10px";
  let r = getSelection(), i = document.createRange();
  i.selectNodeContents(e), t.dom.blur(), r.removeAllRanges(), r.addRange(i), setTimeout(() => {
    n.parentNode && n.parentNode.removeChild(n), t.focus();
  }, 50);
}
const ti = st && pn < 15 || wr && dm < 604;
Qe.copy = et.cut = (t, e) => {
  let n = e, r = t.state.selection, i = n.type == "cut";
  if (r.empty)
    return;
  let s = ti ? null : n.clipboardData, o = r.content(), { dom: a, text: l } = Ju(t, o);
  s ? (n.preventDefault(), s.clearData(), s.setData("text/html", a.innerHTML), s.setData("text/plain", l)) : pg(t, a), i && t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut"));
};
function hg(t) {
  return t.openStart == 0 && t.openEnd == 0 && t.content.childCount == 1 ? t.content.firstChild : null;
}
function mg(t, e) {
  if (!t.dom.parentNode)
    return;
  let n = t.input.shiftKey || t.state.selection.$from.parent.type.spec.code, r = t.dom.parentNode.appendChild(document.createElement(n ? "textarea" : "div"));
  n || (r.contentEditable = "true"), r.style.cssText = "position: fixed; left: -10000px; top: 10px", r.focus();
  let i = t.input.shiftKey && t.input.lastKeyCode != 45;
  setTimeout(() => {
    t.focus(), r.parentNode && r.parentNode.removeChild(r), n ? ni(t, r.value, null, i, e) : ni(t, r.textContent, r.innerHTML, i, e);
  }, 50);
}
function ni(t, e, n, r, i) {
  let s = Xu(t, e, n, r, t.state.selection.$from);
  if (t.someProp("handlePaste", (l) => l(t, i, s || B.empty)))
    return !0;
  if (!s)
    return !1;
  let o = hg(s), a = o ? t.state.tr.replaceSelectionWith(o, r) : t.state.tr.replaceSelection(s);
  return t.dispatch(a.scrollIntoView().setMeta("paste", !0).setMeta("uiEvent", "paste")), !0;
}
function cf(t) {
  let e = t.getData("text/plain") || t.getData("Text");
  if (e)
    return e;
  let n = t.getData("text/uri-list");
  return n ? n.replace(/\r?\n/g, " ") : "";
}
et.paste = (t, e) => {
  let n = e;
  if (t.composing && !kt)
    return;
  let r = ti ? null : n.clipboardData, i = t.input.shiftKey && t.input.lastKeyCode != 45;
  r && ni(t, cf(r), r.getData("text/html"), i, n) ? n.preventDefault() : mg(t, n);
};
class df {
  constructor(e, n, r) {
    this.slice = e, this.move = n, this.node = r;
  }
}
const uf = yt ? "altKey" : "ctrlKey";
Qe.dragstart = (t, e) => {
  let n = e, r = t.input.mouseDown;
  if (r && r.done(), !n.dataTransfer)
    return;
  let i = t.state.selection, s = i.empty ? null : t.posAtCoords($s(n)), o;
  if (!(s && s.pos >= i.from && s.pos <= (i instanceof Y ? i.to - 1 : i.to))) {
    if (r && r.mightDrag)
      o = Y.create(t.state.doc, r.mightDrag.pos);
    else if (n.target && n.target.nodeType == 1) {
      let d = t.docView.nearestDesc(n.target, !0);
      d && d.node.type.spec.draggable && d != t.docView && (o = Y.create(t.state.doc, d.posBefore));
    }
  }
  let a = (o || t.state.selection).content(), { dom: l, text: c } = Ju(t, a);
  n.dataTransfer.clearData(), n.dataTransfer.setData(ti ? "Text" : "text/html", l.innerHTML), n.dataTransfer.effectAllowed = "copyMove", ti || n.dataTransfer.setData("text/plain", c), t.dragging = new df(a, !n[uf], o);
};
Qe.dragend = (t) => {
  let e = t.dragging;
  window.setTimeout(() => {
    t.dragging == e && (t.dragging = null);
  }, 50);
};
et.dragover = et.dragenter = (t, e) => e.preventDefault();
et.drop = (t, e) => {
  let n = e, r = t.dragging;
  if (t.dragging = null, !n.dataTransfer)
    return;
  let i = t.posAtCoords($s(n));
  if (!i)
    return;
  let s = t.state.doc.resolve(i.pos), o = r && r.slice;
  o ? t.someProp("transformPasted", (h) => {
    o = h(o, t);
  }) : o = Xu(t, cf(n.dataTransfer), ti ? null : n.dataTransfer.getData("text/html"), !1, s);
  let a = !!(r && !n[uf]);
  if (t.someProp("handleDrop", (h) => h(t, n, o || B.empty, a))) {
    n.preventDefault();
    return;
  }
  if (!o)
    return;
  n.preventDefault();
  let l = o ? Tu(t.state.doc, s.pos, o) : s.pos;
  l == null && (l = s.pos);
  let c = t.state.tr;
  if (a) {
    let { node: h } = r;
    h ? h.replace(c) : c.deleteSelection();
  }
  let d = c.mapping.map(l), u = o.openStart == 0 && o.openEnd == 0 && o.content.childCount == 1, f = c.doc;
  if (u ? c.replaceRangeWith(d, d, o.content.firstChild) : c.replaceRange(d, d, o), c.doc.eq(f))
    return;
  let p = c.doc.resolve(d);
  if (u && Y.isSelectable(o.content.firstChild) && p.nodeAfter && p.nodeAfter.sameMarkup(o.content.firstChild))
    c.setSelection(new Y(p));
  else {
    let h = c.mapping.map(l);
    c.mapping.maps[c.mapping.maps.length - 1].forEach((m, g, v, y) => h = y), c.setSelection(Ia(t, p, c.doc.resolve(h)));
  }
  t.focus(), t.dispatch(c.setMeta("uiEvent", "drop"));
};
Qe.focus = (t) => {
  t.input.lastFocus = Date.now(), t.focused || (t.domObserver.stop(), t.dom.classList.add("ProseMirror-focused"), t.domObserver.start(), t.focused = !0, setTimeout(() => {
    t.docView && t.hasFocus() && !t.domObserver.currentSelection.eq(t.domSelectionRange()) && jt(t);
  }, 20));
};
Qe.blur = (t, e) => {
  let n = e;
  t.focused && (t.domObserver.stop(), t.dom.classList.remove("ProseMirror-focused"), t.domObserver.start(), n.relatedTarget && t.dom.contains(n.relatedTarget) && t.domObserver.currentSelection.clear(), t.focused = !1);
};
Qe.beforeinput = (t, e) => {
  if (We && kt && e.inputType == "deleteContentBackward") {
    t.domObserver.flushSoon();
    let { domChangeCount: r } = t.input;
    setTimeout(() => {
      if (t.input.domChangeCount != r || (t.dom.blur(), t.focus(), t.someProp("handleKeyDown", (s) => s(t, Mn(8, "Backspace")))))
        return;
      let { $cursor: i } = t.state.selection;
      i && i.pos > 0 && t.dispatch(t.state.tr.delete(i.pos - 1, i.pos).scrollIntoView());
    }, 50);
  }
};
for (let t in et)
  Qe[t] = et[t];
function ri(t, e) {
  if (t == e)
    return !0;
  for (let n in t)
    if (t[n] !== e[n])
      return !1;
  for (let n in e)
    if (!(n in t))
      return !1;
  return !0;
}
class ls {
  constructor(e, n) {
    this.toDOM = e, this.spec = n || In, this.side = this.spec.side || 0;
  }
  map(e, n, r, i) {
    let { pos: s, deleted: o } = e.mapResult(n.from + i, this.side < 0 ? -1 : 1);
    return o ? null : new Le(s - r, s - r, this);
  }
  valid() {
    return !0;
  }
  eq(e) {
    return this == e || e instanceof ls && (this.spec.key && this.spec.key == e.spec.key || this.toDOM == e.toDOM && ri(this.spec, e.spec));
  }
  destroy(e) {
    this.spec.destroy && this.spec.destroy(e);
  }
}
class mn {
  constructor(e, n) {
    this.attrs = e, this.spec = n || In;
  }
  map(e, n, r, i) {
    let s = e.map(n.from + i, this.spec.inclusiveStart ? -1 : 1) - r, o = e.map(n.to + i, this.spec.inclusiveEnd ? 1 : -1) - r;
    return s >= o ? null : new Le(s, o, this);
  }
  valid(e, n) {
    return n.from < n.to;
  }
  eq(e) {
    return this == e || e instanceof mn && ri(this.attrs, e.attrs) && ri(this.spec, e.spec);
  }
  static is(e) {
    return e.type instanceof mn;
  }
  destroy() {
  }
}
class Pa {
  constructor(e, n) {
    this.attrs = e, this.spec = n || In;
  }
  map(e, n, r, i) {
    let s = e.mapResult(n.from + i, 1);
    if (s.deleted)
      return null;
    let o = e.mapResult(n.to + i, -1);
    return o.deleted || o.pos <= s.pos ? null : new Le(s.pos - r, o.pos - r, this);
  }
  valid(e, n) {
    let { index: r, offset: i } = e.content.findIndex(n.from), s;
    return i == n.from && !(s = e.child(r)).isText && i + s.nodeSize == n.to;
  }
  eq(e) {
    return this == e || e instanceof Pa && ri(this.attrs, e.attrs) && ri(this.spec, e.spec);
  }
  destroy() {
  }
}
class Le {
  /**
  @internal
  */
  constructor(e, n, r) {
    this.from = e, this.to = n, this.type = r;
  }
  /**
  @internal
  */
  copy(e, n) {
    return new Le(e, n, this.type);
  }
  /**
  @internal
  */
  eq(e, n = 0) {
    return this.type.eq(e.type) && this.from + n == e.from && this.to + n == e.to;
  }
  /**
  @internal
  */
  map(e, n, r) {
    return this.type.map(e, this, n, r);
  }
  /**
  Creates a widget decoration, which is a DOM node that's shown in
  the document at the given position. It is recommended that you
  delay rendering the widget by passing a function that will be
  called when the widget is actually drawn in a view, but you can
  also directly pass a DOM node. `getPos` can be used to find the
  widget's current document position.
  */
  static widget(e, n, r) {
    return new Le(e, e, new ls(n, r));
  }
  /**
  Creates an inline decoration, which adds the given attributes to
  each inline node between `from` and `to`.
  */
  static inline(e, n, r, i) {
    return new Le(e, n, new mn(r, i));
  }
  /**
  Creates a node decoration. `from` and `to` should point precisely
  before and after a node in the document. That node, and only that
  node, will receive the given attributes.
  */
  static node(e, n, r, i) {
    return new Le(e, n, new Pa(r, i));
  }
  /**
  The spec provided when creating this decoration. Can be useful
  if you've stored extra information in that object.
  */
  get spec() {
    return this.type.spec;
  }
  /**
  @internal
  */
  get inline() {
    return this.type instanceof mn;
  }
  /**
  @internal
  */
  get widget() {
    return this.type instanceof ls;
  }
}
const rr = [], In = {};
class we {
  /**
  @internal
  */
  constructor(e, n) {
    this.local = e.length ? e : rr, this.children = n.length ? n : rr;
  }
  /**
  Create a set of decorations, using the structure of the given
  document. This will consume (modify) the `decorations` array, so
  you must make a copy if you want need to preserve that.
  */
  static create(e, n) {
    return n.length ? cs(n, e, 0, In) : Ke;
  }
  /**
  Find all decorations in this set which touch the given range
  (including decorations that start or end directly at the
  boundaries) and match the given predicate on their spec. When
  `start` and `end` are omitted, all decorations in the set are
  considered. When `predicate` isn't given, all decorations are
  assumed to match.
  */
  find(e, n, r) {
    let i = [];
    return this.findInner(e ?? 0, n ?? 1e9, i, 0, r), i;
  }
  findInner(e, n, r, i, s) {
    for (let o = 0; o < this.local.length; o++) {
      let a = this.local[o];
      a.from <= n && a.to >= e && (!s || s(a.spec)) && r.push(a.copy(a.from + i, a.to + i));
    }
    for (let o = 0; o < this.children.length; o += 3)
      if (this.children[o] < n && this.children[o + 1] > e) {
        let a = this.children[o] + 1;
        this.children[o + 2].findInner(e - a, n - a, r, i + a, s);
      }
  }
  /**
  Map the set of decorations in response to a change in the
  document.
  */
  map(e, n, r) {
    return this == Ke || e.maps.length == 0 ? this : this.mapInner(e, n, 0, 0, r || In);
  }
  /**
  @internal
  */
  mapInner(e, n, r, i, s) {
    let o;
    for (let a = 0; a < this.local.length; a++) {
      let l = this.local[a].map(e, r, i);
      l && l.type.valid(n, l) ? (o || (o = [])).push(l) : s.onRemove && s.onRemove(this.local[a].spec);
    }
    return this.children.length ? gg(this.children, o || [], e, n, r, i, s) : o ? new we(o.sort(Dn), rr) : Ke;
  }
  /**
  Add the given array of decorations to the ones in the set,
  producing a new set. Consumes the `decorations` array. Needs
  access to the current document to create the appropriate tree
  structure.
  */
  add(e, n) {
    return n.length ? this == Ke ? we.create(e, n) : this.addInner(e, n, 0) : this;
  }
  addInner(e, n, r) {
    let i, s = 0;
    e.forEach((a, l) => {
      let c = l + r, d;
      if (d = pf(n, a, c)) {
        for (i || (i = this.children.slice()); s < i.length && i[s] < l; )
          s += 3;
        i[s] == l ? i[s + 2] = i[s + 2].addInner(a, d, c + 1) : i.splice(s, 0, l, l + a.nodeSize, cs(d, a, c + 1, In)), s += 3;
      }
    });
    let o = ff(s ? hf(n) : n, -r);
    for (let a = 0; a < o.length; a++)
      o[a].type.valid(e, o[a]) || o.splice(a--, 1);
    return new we(o.length ? this.local.concat(o).sort(Dn) : this.local, i || this.children);
  }
  /**
  Create a new set that contains the decorations in this set, minus
  the ones in the given array.
  */
  remove(e) {
    return e.length == 0 || this == Ke ? this : this.removeInner(e, 0);
  }
  removeInner(e, n) {
    let r = this.children, i = this.local;
    for (let s = 0; s < r.length; s += 3) {
      let o, a = r[s] + n, l = r[s + 1] + n;
      for (let d = 0, u; d < e.length; d++)
        (u = e[d]) && u.from > a && u.to < l && (e[d] = null, (o || (o = [])).push(u));
      if (!o)
        continue;
      r == this.children && (r = this.children.slice());
      let c = r[s + 2].removeInner(o, a + 1);
      c != Ke ? r[s + 2] = c : (r.splice(s, 3), s -= 3);
    }
    if (i.length) {
      for (let s = 0, o; s < e.length; s++)
        if (o = e[s])
          for (let a = 0; a < i.length; a++)
            i[a].eq(o, n) && (i == this.local && (i = this.local.slice()), i.splice(a--, 1));
    }
    return r == this.children && i == this.local ? this : i.length || r.length ? new we(i, r) : Ke;
  }
  /**
  @internal
  */
  forChild(e, n) {
    if (this == Ke)
      return this;
    if (n.isLeaf)
      return we.empty;
    let r, i;
    for (let a = 0; a < this.children.length; a += 3)
      if (this.children[a] >= e) {
        this.children[a] == e && (r = this.children[a + 2]);
        break;
      }
    let s = e + 1, o = s + n.content.size;
    for (let a = 0; a < this.local.length; a++) {
      let l = this.local[a];
      if (l.from < o && l.to > s && l.type instanceof mn) {
        let c = Math.max(s, l.from) - s, d = Math.min(o, l.to) - s;
        c < d && (i || (i = [])).push(l.copy(c, d));
      }
    }
    if (i) {
      let a = new we(i.sort(Dn), rr);
      return r ? new rn([a, r]) : a;
    }
    return r || Ke;
  }
  /**
  @internal
  */
  eq(e) {
    if (this == e)
      return !0;
    if (!(e instanceof we) || this.local.length != e.local.length || this.children.length != e.children.length)
      return !1;
    for (let n = 0; n < this.local.length; n++)
      if (!this.local[n].eq(e.local[n]))
        return !1;
    for (let n = 0; n < this.children.length; n += 3)
      if (this.children[n] != e.children[n] || this.children[n + 1] != e.children[n + 1] || !this.children[n + 2].eq(e.children[n + 2]))
        return !1;
    return !0;
  }
  /**
  @internal
  */
  locals(e) {
    return $a(this.localsInner(e));
  }
  /**
  @internal
  */
  localsInner(e) {
    if (this == Ke)
      return rr;
    if (e.inlineContent || !this.local.some(mn.is))
      return this.local;
    let n = [];
    for (let r = 0; r < this.local.length; r++)
      this.local[r].type instanceof mn || n.push(this.local[r]);
    return n;
  }
}
we.empty = new we([], []);
we.removeOverlap = $a;
const Ke = we.empty;
class rn {
  constructor(e) {
    this.members = e;
  }
  map(e, n) {
    const r = this.members.map((i) => i.map(e, n, In));
    return rn.from(r);
  }
  forChild(e, n) {
    if (n.isLeaf)
      return we.empty;
    let r = [];
    for (let i = 0; i < this.members.length; i++) {
      let s = this.members[i].forChild(e, n);
      s != Ke && (s instanceof rn ? r = r.concat(s.members) : r.push(s));
    }
    return rn.from(r);
  }
  eq(e) {
    if (!(e instanceof rn) || e.members.length != this.members.length)
      return !1;
    for (let n = 0; n < this.members.length; n++)
      if (!this.members[n].eq(e.members[n]))
        return !1;
    return !0;
  }
  locals(e) {
    let n, r = !0;
    for (let i = 0; i < this.members.length; i++) {
      let s = this.members[i].localsInner(e);
      if (s.length)
        if (!n)
          n = s;
        else {
          r && (n = n.slice(), r = !1);
          for (let o = 0; o < s.length; o++)
            n.push(s[o]);
        }
    }
    return n ? $a(r ? n : n.sort(Dn)) : rr;
  }
  // Create a group for the given array of decoration sets, or return
  // a single set when possible.
  static from(e) {
    switch (e.length) {
      case 0:
        return Ke;
      case 1:
        return e[0];
      default:
        return new rn(e.every((n) => n instanceof we) ? e : e.reduce((n, r) => n.concat(r instanceof we ? r : r.members), []));
    }
  }
}
function gg(t, e, n, r, i, s, o) {
  let a = t.slice();
  for (let c = 0, d = s; c < n.maps.length; c++) {
    let u = 0;
    n.maps[c].forEach((f, p, h, m) => {
      let g = m - h - (p - f);
      for (let v = 0; v < a.length; v += 3) {
        let y = a[v + 1];
        if (y < 0 || f > y + d - u)
          continue;
        let E = a[v] + d - u;
        p >= E ? a[v + 1] = f <= E ? -2 : -1 : h >= i && g && (a[v] += g, a[v + 1] += g);
      }
      u += g;
    }), d = n.maps[c].map(d, -1);
  }
  let l = !1;
  for (let c = 0; c < a.length; c += 3)
    if (a[c + 1] < 0) {
      if (a[c + 1] == -2) {
        l = !0, a[c + 1] = -1;
        continue;
      }
      let d = n.map(t[c] + s), u = d - i;
      if (u < 0 || u >= r.content.size) {
        l = !0;
        continue;
      }
      let f = n.map(t[c + 1] + s, -1), p = f - i, { index: h, offset: m } = r.content.findIndex(u), g = r.maybeChild(h);
      if (g && m == u && m + g.nodeSize == p) {
        let v = a[c + 2].mapInner(n, g, d + 1, t[c] + s + 1, o);
        v != Ke ? (a[c] = u, a[c + 1] = p, a[c + 2] = v) : (a[c + 1] = -2, l = !0);
      } else
        l = !0;
    }
  if (l) {
    let c = bg(a, t, e, n, i, s, o), d = cs(c, r, 0, o);
    e = d.local;
    for (let u = 0; u < a.length; u += 3)
      a[u + 1] < 0 && (a.splice(u, 3), u -= 3);
    for (let u = 0, f = 0; u < d.children.length; u += 3) {
      let p = d.children[u];
      for (; f < a.length && a[f] < p; )
        f += 3;
      a.splice(f, 0, d.children[u], d.children[u + 1], d.children[u + 2]);
    }
  }
  return new we(e.sort(Dn), a);
}
function ff(t, e) {
  if (!e || !t.length)
    return t;
  let n = [];
  for (let r = 0; r < t.length; r++) {
    let i = t[r];
    n.push(new Le(i.from + e, i.to + e, i.type));
  }
  return n;
}
function bg(t, e, n, r, i, s, o) {
  function a(l, c) {
    for (let d = 0; d < l.local.length; d++) {
      let u = l.local[d].map(r, i, c);
      u ? n.push(u) : o.onRemove && o.onRemove(l.local[d].spec);
    }
    for (let d = 0; d < l.children.length; d += 3)
      a(l.children[d + 2], l.children[d] + c + 1);
  }
  for (let l = 0; l < t.length; l += 3)
    t[l + 1] == -1 && a(t[l + 2], e[l] + s + 1);
  return n;
}
function pf(t, e, n) {
  if (e.isLeaf)
    return null;
  let r = n + e.nodeSize, i = null;
  for (let s = 0, o; s < t.length; s++)
    (o = t[s]) && o.from > n && o.to < r && ((i || (i = [])).push(o), t[s] = null);
  return i;
}
function hf(t) {
  let e = [];
  for (let n = 0; n < t.length; n++)
    t[n] != null && e.push(t[n]);
  return e;
}
function cs(t, e, n, r) {
  let i = [], s = !1;
  e.forEach((a, l) => {
    let c = pf(t, a, l + n);
    if (c) {
      s = !0;
      let d = cs(c, a, n + l + 1, r);
      d != Ke && i.push(l, l + a.nodeSize, d);
    }
  });
  let o = ff(s ? hf(t) : t, -n).sort(Dn);
  for (let a = 0; a < o.length; a++)
    o[a].type.valid(e, o[a]) || (r.onRemove && r.onRemove(o[a].spec), o.splice(a--, 1));
  return o.length || i.length ? new we(o, i) : Ke;
}
function Dn(t, e) {
  return t.from - e.from || t.to - e.to;
}
function $a(t) {
  let e = t;
  for (let n = 0; n < e.length - 1; n++) {
    let r = e[n];
    if (r.from != r.to)
      for (let i = n + 1; i < e.length; i++) {
        let s = e[i];
        if (s.from == r.from) {
          s.to != r.to && (e == t && (e = t.slice()), e[i] = s.copy(s.from, r.to), hc(e, i + 1, s.copy(r.to, s.to)));
          continue;
        } else {
          s.from < r.to && (e == t && (e = t.slice()), e[n] = r.copy(r.from, s.from), hc(e, i, r.copy(s.from, r.to)));
          break;
        }
      }
  }
  return e;
}
function hc(t, e, n) {
  for (; e < t.length && Dn(n, t[e]) > 0; )
    e++;
  t.splice(e, 0, n);
}
function mo(t) {
  let e = [];
  return t.someProp("decorations", (n) => {
    let r = n(t.state);
    r && r != Ke && e.push(r);
  }), t.cursorWrapper && e.push(we.create(t.state.doc, [t.cursorWrapper.deco])), rn.from(e);
}
const yg = {
  childList: !0,
  characterData: !0,
  characterDataOldValue: !0,
  attributes: !0,
  attributeOldValue: !0,
  subtree: !0
}, vg = st && pn <= 11;
class wg {
  constructor() {
    this.anchorNode = null, this.anchorOffset = 0, this.focusNode = null, this.focusOffset = 0;
  }
  set(e) {
    this.anchorNode = e.anchorNode, this.anchorOffset = e.anchorOffset, this.focusNode = e.focusNode, this.focusOffset = e.focusOffset;
  }
  clear() {
    this.anchorNode = this.focusNode = null;
  }
  eq(e) {
    return e.anchorNode == this.anchorNode && e.anchorOffset == this.anchorOffset && e.focusNode == this.focusNode && e.focusOffset == this.focusOffset;
  }
}
class Eg {
  constructor(e, n) {
    this.view = e, this.handleDOMChange = n, this.queue = [], this.flushingSoon = -1, this.observer = null, this.currentSelection = new wg(), this.onCharData = null, this.suppressingSelectionUpdates = !1, this.observer = window.MutationObserver && new window.MutationObserver((r) => {
      for (let i = 0; i < r.length; i++)
        this.queue.push(r[i]);
      st && pn <= 11 && r.some((i) => i.type == "childList" && i.removedNodes.length || i.type == "characterData" && i.oldValue.length > i.target.nodeValue.length) ? this.flushSoon() : this.flush();
    }), vg && (this.onCharData = (r) => {
      this.queue.push({ target: r.target, type: "characterData", oldValue: r.prevValue }), this.flushSoon();
    }), this.onSelectionChange = this.onSelectionChange.bind(this);
  }
  flushSoon() {
    this.flushingSoon < 0 && (this.flushingSoon = window.setTimeout(() => {
      this.flushingSoon = -1, this.flush();
    }, 20));
  }
  forceFlush() {
    this.flushingSoon > -1 && (window.clearTimeout(this.flushingSoon), this.flushingSoon = -1, this.flush());
  }
  start() {
    this.observer && (this.observer.takeRecords(), this.observer.observe(this.view.dom, yg)), this.onCharData && this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData), this.connectSelection();
  }
  stop() {
    if (this.observer) {
      let e = this.observer.takeRecords();
      if (e.length) {
        for (let n = 0; n < e.length; n++)
          this.queue.push(e[n]);
        window.setTimeout(() => this.flush(), 20);
      }
      this.observer.disconnect();
    }
    this.onCharData && this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData), this.disconnectSelection();
  }
  connectSelection() {
    this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
  }
  disconnectSelection() {
    this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
  }
  suppressSelectionUpdates() {
    this.suppressingSelectionUpdates = !0, setTimeout(() => this.suppressingSelectionUpdates = !1, 50);
  }
  onSelectionChange() {
    if (oc(this.view)) {
      if (this.suppressingSelectionUpdates)
        return jt(this.view);
      if (st && pn <= 11 && !this.view.state.selection.empty) {
        let e = this.view.domSelectionRange();
        if (e.focusNode && Vn(e.focusNode, e.focusOffset, e.anchorNode, e.anchorOffset))
          return this.flushSoon();
      }
      this.flush();
    }
  }
  setCurSelection() {
    this.currentSelection.set(this.view.domSelectionRange());
  }
  ignoreSelectionChange(e) {
    if (!e.focusNode)
      return !0;
    let n = /* @__PURE__ */ new Set(), r;
    for (let s = e.focusNode; s; s = ei(s))
      n.add(s);
    for (let s = e.anchorNode; s; s = ei(s))
      if (n.has(s)) {
        r = s;
        break;
      }
    let i = r && this.view.docView.nearestDesc(r);
    if (i && i.ignoreMutation({
      type: "selection",
      target: r.nodeType == 3 ? r.parentNode : r
    }))
      return this.setCurSelection(), !0;
  }
  pendingRecords() {
    if (this.observer)
      for (let e of this.observer.takeRecords())
        this.queue.push(e);
    return this.queue;
  }
  flush() {
    let { view: e } = this;
    if (!e.docView || this.flushingSoon > -1)
      return;
    let n = this.pendingRecords();
    n.length && (this.queue = []);
    let r = e.domSelectionRange(), i = !this.suppressingSelectionUpdates && !this.currentSelection.eq(r) && oc(e) && !this.ignoreSelectionChange(r), s = -1, o = -1, a = !1, l = [];
    if (e.editable)
      for (let d = 0; d < n.length; d++) {
        let u = this.registerMutation(n[d], l);
        u && (s = s < 0 ? u.from : Math.min(u.from, s), o = o < 0 ? u.to : Math.max(u.to, o), u.typeOver && (a = !0));
      }
    if (_t && l.length > 1) {
      let d = l.filter((u) => u.nodeName == "BR");
      if (d.length == 2) {
        let u = d[0], f = d[1];
        u.parentNode && u.parentNode.parentNode == f.parentNode ? f.remove() : u.remove();
      }
    }
    let c = null;
    s < 0 && i && e.input.lastFocus > Date.now() - 200 && Math.max(e.input.lastTouch, e.input.lastClick.time) < Date.now() - 300 && Bs(r) && (c = La(e)) && c.eq(te.near(e.state.doc.resolve(0), 1)) ? (e.input.lastFocus = 0, jt(e), this.currentSelection.set(r), e.scrollToSelection()) : (s > -1 || i) && (s > -1 && (e.docView.markDirty(s, o), xg(e)), this.handleDOMChange(s, o, a, l), e.docView && e.docView.dirty ? e.updateState(e.state) : this.currentSelection.eq(r) || jt(e), this.currentSelection.set(r));
  }
  registerMutation(e, n) {
    if (n.indexOf(e.target) > -1)
      return null;
    let r = this.view.docView.nearestDesc(e.target);
    if (e.type == "attributes" && (r == this.view.docView || e.attributeName == "contenteditable" || // Firefox sometimes fires spurious events for null/empty styles
    e.attributeName == "style" && !e.oldValue && !e.target.getAttribute("style")) || !r || r.ignoreMutation(e))
      return null;
    if (e.type == "childList") {
      for (let d = 0; d < e.addedNodes.length; d++)
        n.push(e.addedNodes[d]);
      if (r.contentDOM && r.contentDOM != r.dom && !r.contentDOM.contains(e.target))
        return { from: r.posBefore, to: r.posAfter };
      let i = e.previousSibling, s = e.nextSibling;
      if (st && pn <= 11 && e.addedNodes.length)
        for (let d = 0; d < e.addedNodes.length; d++) {
          let { previousSibling: u, nextSibling: f } = e.addedNodes[d];
          (!u || Array.prototype.indexOf.call(e.addedNodes, u) < 0) && (i = u), (!f || Array.prototype.indexOf.call(e.addedNodes, f) < 0) && (s = f);
        }
      let o = i && i.parentNode == e.target ? Je(i) + 1 : 0, a = r.localPosFromDOM(e.target, o, -1), l = s && s.parentNode == e.target ? Je(s) : e.target.childNodes.length, c = r.localPosFromDOM(e.target, l, 1);
      return { from: a, to: c };
    } else
      return e.type == "attributes" ? { from: r.posAtStart - r.border, to: r.posAtEnd + r.border } : {
        from: r.posAtStart,
        to: r.posAtEnd,
        // An event was generated for a text change that didn't change
        // any text. Mark the dom change to fall back to assuming the
        // selection was typed over with an identical value if it can't
        // find another change.
        typeOver: e.target.nodeValue == e.oldValue
      };
  }
}
let mc = /* @__PURE__ */ new WeakMap(), gc = !1;
function xg(t) {
  if (!mc.has(t) && (mc.set(t, null), ["normal", "nowrap", "pre-line"].indexOf(getComputedStyle(t.dom).whiteSpace) !== -1)) {
    if (t.requiresGeckoHackNode = _t, gc)
      return;
    console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."), gc = !0;
  }
}
function Sg(t) {
  let e;
  function n(l) {
    l.preventDefault(), l.stopImmediatePropagation(), e = l.getTargetRanges()[0];
  }
  t.dom.addEventListener("beforeinput", n, !0), document.execCommand("indent"), t.dom.removeEventListener("beforeinput", n, !0);
  let r = e.startContainer, i = e.startOffset, s = e.endContainer, o = e.endOffset, a = t.domAtPos(t.state.selection.anchor);
  return Vn(a.node, a.offset, s, o) && ([r, i, s, o] = [s, o, r, i]), { anchorNode: r, anchorOffset: i, focusNode: s, focusOffset: o };
}
function Cg(t, e, n) {
  let { node: r, fromOffset: i, toOffset: s, from: o, to: a } = t.docView.parseRange(e, n), l = t.domSelectionRange(), c, d = l.anchorNode;
  if (d && t.dom.contains(d.nodeType == 1 ? d : d.parentNode) && (c = [{ node: d, offset: l.anchorOffset }], Bs(l) || c.push({ node: l.focusNode, offset: l.focusOffset })), We && t.input.lastKeyCode === 8)
    for (let g = s; g > i; g--) {
      let v = r.childNodes[g - 1], y = v.pmViewDesc;
      if (v.nodeName == "BR" && !y) {
        s = g;
        break;
      }
      if (!y || y.size)
        break;
    }
  let u = t.state.doc, f = t.someProp("domParser") || br.fromSchema(t.state.schema), p = u.resolve(o), h = null, m = f.parse(r, {
    topNode: p.parent,
    topMatch: p.parent.contentMatchAt(p.index()),
    topOpen: !0,
    from: i,
    to: s,
    preserveWhitespace: p.parent.type.whitespace == "pre" ? "full" : !0,
    findPositions: c,
    ruleFromNode: Mg,
    context: p
  });
  if (c && c[0].pos != null) {
    let g = c[0].pos, v = c[1] && c[1].pos;
    v == null && (v = g), h = { anchor: g + o, head: v + o };
  }
  return { doc: m, sel: h, from: o, to: a };
}
function Mg(t) {
  let e = t.pmViewDesc;
  if (e)
    return e.parseRule();
  if (t.nodeName == "BR" && t.parentNode) {
    if (Xe && /^(ul|ol)$/i.test(t.parentNode.nodeName)) {
      let n = document.createElement("div");
      return n.appendChild(document.createElement("li")), { skip: n };
    } else if (t.parentNode.lastChild == t || Xe && /^(tr|table)$/i.test(t.parentNode.nodeName))
      return { ignore: !0 };
  } else if (t.nodeName == "IMG" && t.getAttribute("mark-placeholder"))
    return { ignore: !0 };
  return null;
}
const kg = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;
function Tg(t, e, n, r, i) {
  let s = t.input.compositionPendingChanges || (t.composing ? t.input.compositionID : 0);
  if (t.input.compositionPendingChanges = 0, e < 0) {
    let k = t.input.lastSelectionTime > Date.now() - 50 ? t.input.lastSelectionOrigin : null, $ = La(t, k);
    if ($ && !t.state.selection.eq($)) {
      if (We && kt && t.input.lastKeyCode === 13 && Date.now() - 100 < t.input.lastKeyCodeTime && t.someProp("handleKeyDown", (j) => j(t, Mn(13, "Enter"))))
        return;
      let Z = t.state.tr.setSelection($);
      k == "pointer" ? Z.setMeta("pointer", !0) : k == "key" && Z.scrollIntoView(), s && Z.setMeta("composition", s), t.dispatch(Z);
    }
    return;
  }
  let o = t.state.doc.resolve(e), a = o.sharedDepth(n);
  e = o.before(a + 1), n = t.state.doc.resolve(n).after(a + 1);
  let l = t.state.selection, c = Cg(t, e, n), d = t.state.doc, u = d.slice(c.from, c.to), f, p;
  t.input.lastKeyCode === 8 && Date.now() - 100 < t.input.lastKeyCodeTime ? (f = t.state.selection.to, p = "end") : (f = t.state.selection.from, p = "start"), t.input.lastKeyCode = null;
  let h = Ag(u.content, c.doc.content, c.from, f, p);
  if ((wr && t.input.lastIOSEnter > Date.now() - 225 || kt) && i.some((k) => k.nodeType == 1 && !kg.test(k.nodeName)) && (!h || h.endA >= h.endB) && t.someProp("handleKeyDown", (k) => k(t, Mn(13, "Enter")))) {
    t.input.lastIOSEnter = 0;
    return;
  }
  if (!h)
    if (r && l instanceof G && !l.empty && l.$head.sameParent(l.$anchor) && !t.composing && !(c.sel && c.sel.anchor != c.sel.head))
      h = { start: l.from, endA: l.to, endB: l.to };
    else {
      if (c.sel) {
        let k = bc(t, t.state.doc, c.sel);
        if (k && !k.eq(t.state.selection)) {
          let $ = t.state.tr.setSelection(k);
          s && $.setMeta("composition", s), t.dispatch($);
        }
      }
      return;
    }
  if (We && t.cursorWrapper && c.sel && c.sel.anchor == t.cursorWrapper.deco.from && c.sel.head == c.sel.anchor) {
    let k = h.endB - h.start;
    c.sel = { anchor: c.sel.anchor + k, head: c.sel.anchor + k };
  }
  t.input.domChangeCount++, t.state.selection.from < t.state.selection.to && h.start == h.endB && t.state.selection instanceof G && (h.start > t.state.selection.from && h.start <= t.state.selection.from + 2 && t.state.selection.from >= c.from ? h.start = t.state.selection.from : h.endA < t.state.selection.to && h.endA >= t.state.selection.to - 2 && t.state.selection.to <= c.to && (h.endB += t.state.selection.to - h.endA, h.endA = t.state.selection.to)), st && pn <= 11 && h.endB == h.start + 1 && h.endA == h.start && h.start > c.from && c.doc.textBetween(h.start - c.from - 1, h.start - c.from + 1) == "  " && (h.start--, h.endA--, h.endB--);
  let m = c.doc.resolveNoCache(h.start - c.from), g = c.doc.resolveNoCache(h.endB - c.from), v = d.resolve(h.start), y = m.sameParent(g) && m.parent.inlineContent && v.end() >= h.endA, E;
  if ((wr && t.input.lastIOSEnter > Date.now() - 225 && (!y || i.some((k) => k.nodeName == "DIV" || k.nodeName == "P")) || !y && m.pos < c.doc.content.size && !m.sameParent(g) && (E = te.findFrom(c.doc.resolve(m.pos + 1), 1, !0)) && E.head == g.pos) && t.someProp("handleKeyDown", (k) => k(t, Mn(13, "Enter")))) {
    t.input.lastIOSEnter = 0;
    return;
  }
  if (t.state.selection.anchor > h.start && Ng(d, h.start, h.endA, m, g) && t.someProp("handleKeyDown", (k) => k(t, Mn(8, "Backspace")))) {
    kt && We && t.domObserver.suppressSelectionUpdates();
    return;
  }
  We && kt && h.endB == h.start && (t.input.lastAndroidDelete = Date.now()), kt && !y && m.start() != g.start() && g.parentOffset == 0 && m.depth == g.depth && c.sel && c.sel.anchor == c.sel.head && c.sel.head == h.endA && (h.endB -= 2, g = c.doc.resolveNoCache(h.endB - c.from), setTimeout(() => {
    t.someProp("handleKeyDown", function(k) {
      return k(t, Mn(13, "Enter"));
    });
  }, 20));
  let b = h.start, C = h.endA, w, _, R;
  if (y) {
    if (m.pos == g.pos)
      st && pn <= 11 && m.parentOffset == 0 && (t.domObserver.suppressSelectionUpdates(), setTimeout(() => jt(t), 20)), w = t.state.tr.delete(b, C), _ = d.resolve(h.start).marksAcross(d.resolve(h.endA));
    else if (
      // Adding or removing a mark
      h.endA == h.endB && (R = _g(m.parent.content.cut(m.parentOffset, g.parentOffset), v.parent.content.cut(v.parentOffset, h.endA - v.start())))
    )
      w = t.state.tr, R.type == "add" ? w.addMark(b, C, R.mark) : w.removeMark(b, C, R.mark);
    else if (m.parent.child(m.index()).isText && m.index() == g.index() - (g.textOffset ? 0 : 1)) {
      let k = m.parent.textBetween(m.parentOffset, g.parentOffset);
      if (t.someProp("handleTextInput", ($) => $(t, b, C, k)))
        return;
      w = t.state.tr.insertText(k, b, C);
    }
  }
  if (w || (w = t.state.tr.replace(b, C, c.doc.slice(h.start - c.from, h.endB - c.from))), c.sel) {
    let k = bc(t, w.doc, c.sel);
    k && !(We && kt && t.composing && k.empty && (h.start != h.endB || t.input.lastAndroidDelete < Date.now() - 100) && (k.head == b || k.head == w.mapping.map(C) - 1) || st && k.empty && k.head == b) && w.setSelection(k);
  }
  _ && w.ensureMarks(_), s && w.setMeta("composition", s), t.dispatch(w.scrollIntoView());
}
function bc(t, e, n) {
  return Math.max(n.anchor, n.head) > e.content.size ? null : Ia(t, e.resolve(n.anchor), e.resolve(n.head));
}
function _g(t, e) {
  let n = t.firstChild.marks, r = e.firstChild.marks, i = n, s = r, o, a, l;
  for (let d = 0; d < r.length; d++)
    i = r[d].removeFromSet(i);
  for (let d = 0; d < n.length; d++)
    s = n[d].removeFromSet(s);
  if (i.length == 1 && s.length == 0)
    a = i[0], o = "add", l = (d) => d.mark(a.addToSet(d.marks));
  else if (i.length == 0 && s.length == 1)
    a = s[0], o = "remove", l = (d) => d.mark(a.removeFromSet(d.marks));
  else
    return null;
  let c = [];
  for (let d = 0; d < e.childCount; d++)
    c.push(l(e.child(d)));
  if (A.from(c).eq(t))
    return { mark: a, type: o };
}
function Ng(t, e, n, r, i) {
  if (!r.parent.isTextblock || // The content must have shrunk
  n - e <= i.pos - r.pos || // newEnd must point directly at or after the end of the block that newStart points into
  go(r, !0, !1) < i.pos)
    return !1;
  let s = t.resolve(e);
  if (s.parentOffset < s.parent.content.size || !s.parent.isTextblock)
    return !1;
  let o = t.resolve(go(s, !0, !0));
  return !o.parent.isTextblock || o.pos > n || go(o, !0, !1) < n ? !1 : r.parent.content.cut(r.parentOffset).eq(o.parent.content);
}
function go(t, e, n) {
  let r = t.depth, i = e ? t.end() : t.pos;
  for (; r > 0 && (e || t.indexAfter(r) == t.node(r).childCount); )
    r--, i++, e = !1;
  if (n) {
    let s = t.node(r).maybeChild(t.indexAfter(r));
    for (; s && !s.isLeaf; )
      s = s.firstChild, i++;
  }
  return i;
}
function Ag(t, e, n, r, i) {
  let s = t.findDiffStart(e, n);
  if (s == null)
    return null;
  let { a: o, b: a } = t.findDiffEnd(e, n + t.size, n + e.size);
  if (i == "end") {
    let l = Math.max(0, s - Math.min(o, a));
    r -= o + l - s;
  }
  if (o < s && t.size < e.size) {
    let l = r <= s && r >= o ? s - r : 0;
    s -= l, s && s < e.size && yc(e.textBetween(s - 1, s + 1)) && (s += l ? 1 : -1), a = s + (a - o), o = s;
  } else if (a < s) {
    let l = r <= s && r >= a ? s - r : 0;
    s -= l, s && s < t.size && yc(t.textBetween(s - 1, s + 1)) && (s += l ? 1 : -1), o = s + (o - a), a = s;
  }
  return { start: s, endA: o, endB: a };
}
function yc(t) {
  if (t.length != 2)
    return !1;
  let e = t.charCodeAt(0), n = t.charCodeAt(1);
  return e >= 56320 && e <= 57343 && n >= 55296 && n <= 56319;
}
class Og {
  /**
  Create a view. `place` may be a DOM node that the editor should
  be appended to, a function that will place it into the document,
  or an object whose `mount` property holds the node to use as the
  document container. If it is `null`, the editor will not be
  added to the document.
  */
  constructor(e, n) {
    this._root = null, this.focused = !1, this.trackWrites = null, this.mounted = !1, this.markCursor = null, this.cursorWrapper = null, this.lastSelectedViewDesc = void 0, this.input = new Xm(), this.prevDirectPlugins = [], this.pluginViews = [], this.requiresGeckoHackNode = !1, this.dragging = null, this._props = n, this.state = n.state, this.directPlugins = n.plugins || [], this.directPlugins.forEach(Sc), this.dispatch = this.dispatch.bind(this), this.dom = e && e.mount || document.createElement("div"), e && (e.appendChild ? e.appendChild(this.dom) : typeof e == "function" ? e(this.dom) : e.mount && (this.mounted = !0)), this.editable = Ec(this), wc(this), this.nodeViews = xc(this), this.docView = ec(this.state.doc, vc(this), mo(this), this.dom, this), this.domObserver = new Eg(this, (r, i, s, o) => Tg(this, r, i, s, o)), this.domObserver.start(), Qm(this), this.updatePluginViews();
  }
  /**
  Holds `true` when a
  [composition](https://w3c.github.io/uievents/#events-compositionevents)
  is active.
  */
  get composing() {
    return this.input.composing;
  }
  /**
  The view's current [props](https://prosemirror.net/docs/ref/#view.EditorProps).
  */
  get props() {
    if (this._props.state != this.state) {
      let e = this._props;
      this._props = {};
      for (let n in e)
        this._props[n] = e[n];
      this._props.state = this.state;
    }
    return this._props;
  }
  /**
  Update the view's props. Will immediately cause an update to
  the DOM.
  */
  update(e) {
    e.handleDOMEvents != this._props.handleDOMEvents && ra(this);
    let n = this._props;
    this._props = e, e.plugins && (e.plugins.forEach(Sc), this.directPlugins = e.plugins), this.updateStateInner(e.state, n);
  }
  /**
  Update the view by updating existing props object with the object
  given as argument. Equivalent to `view.update(Object.assign({},
  view.props, props))`.
  */
  setProps(e) {
    let n = {};
    for (let r in this._props)
      n[r] = this._props[r];
    n.state = this.state;
    for (let r in e)
      n[r] = e[r];
    this.update(n);
  }
  /**
  Update the editor's `state` prop, without touching any of the
  other props.
  */
  updateState(e) {
    this.updateStateInner(e, this._props);
  }
  updateStateInner(e, n) {
    var r;
    let i = this.state, s = !1, o = !1;
    e.storedMarks && this.composing && (lf(this), o = !0), this.state = e;
    let a = i.plugins != e.plugins || this._props.plugins != n.plugins;
    if (a || this._props.plugins != n.plugins || this._props.nodeViews != n.nodeViews) {
      let p = xc(this);
      Lg(p, this.nodeViews) && (this.nodeViews = p, s = !0);
    }
    (a || n.handleDOMEvents != this._props.handleDOMEvents) && ra(this), this.editable = Ec(this), wc(this);
    let l = mo(this), c = vc(this), d = i.plugins != e.plugins && !i.doc.eq(e.doc) ? "reset" : e.scrollToSelection > i.scrollToSelection ? "to selection" : "preserve", u = s || !this.docView.matchesNode(e.doc, c, l);
    (u || !e.selection.eq(i.selection)) && (o = !0);
    let f = d == "preserve" && o && this.dom.style.overflowAnchor == null && pm(this);
    if (o) {
      this.domObserver.stop();
      let p = u && (st || We) && !this.composing && !i.selection.empty && !e.selection.empty && Rg(i.selection, e.selection);
      if (u) {
        let h = We ? this.trackWrites = this.domSelectionRange().focusNode : null;
        (s || !this.docView.update(e.doc, c, l, this)) && (this.docView.updateOuterDeco([]), this.docView.destroy(), this.docView = ec(e.doc, c, l, this.dom, this)), h && !this.trackWrites && (p = !0);
      }
      p || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && Pm(this)) ? jt(this, p) : (Gu(this, e.selection), this.domObserver.setCurSelection()), this.domObserver.start();
    }
    this.updatePluginViews(i), !((r = this.dragging) === null || r === void 0) && r.node && !i.doc.eq(e.doc) && this.updateDraggedNode(this.dragging, i), d == "reset" ? this.dom.scrollTop = 0 : d == "to selection" ? this.scrollToSelection() : f && hm(f);
  }
  /**
  @internal
  */
  scrollToSelection() {
    let e = this.domSelectionRange().focusNode;
    if (!this.someProp("handleScrollToSelection", (n) => n(this)))
      if (this.state.selection instanceof Y) {
        let n = this.docView.domAfterPos(this.state.selection.from);
        n.nodeType == 1 && Gl(this, n.getBoundingClientRect(), e);
      } else
        Gl(this, this.coordsAtPos(this.state.selection.head, 1), e);
  }
  destroyPluginViews() {
    let e;
    for (; e = this.pluginViews.pop(); )
      e.destroy && e.destroy();
  }
  updatePluginViews(e) {
    if (!e || e.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) {
      this.prevDirectPlugins = this.directPlugins, this.destroyPluginViews();
      for (let n = 0; n < this.directPlugins.length; n++) {
        let r = this.directPlugins[n];
        r.spec.view && this.pluginViews.push(r.spec.view(this));
      }
      for (let n = 0; n < this.state.plugins.length; n++) {
        let r = this.state.plugins[n];
        r.spec.view && this.pluginViews.push(r.spec.view(this));
      }
    } else
      for (let n = 0; n < this.pluginViews.length; n++) {
        let r = this.pluginViews[n];
        r.update && r.update(this, e);
      }
  }
  updateDraggedNode(e, n) {
    let r = e.node, i = -1;
    if (this.state.doc.nodeAt(r.from) == r.node)
      i = r.from;
    else {
      let s = r.from + (this.state.doc.content.size - n.doc.content.size);
      (s > 0 && this.state.doc.nodeAt(s)) == r.node && (i = s);
    }
    this.dragging = new df(e.slice, e.move, i < 0 ? void 0 : Y.create(this.state.doc, i));
  }
  someProp(e, n) {
    let r = this._props && this._props[e], i;
    if (r != null && (i = n ? n(r) : r))
      return i;
    for (let o = 0; o < this.directPlugins.length; o++) {
      let a = this.directPlugins[o].props[e];
      if (a != null && (i = n ? n(a) : a))
        return i;
    }
    let s = this.state.plugins;
    if (s)
      for (let o = 0; o < s.length; o++) {
        let a = s[o].props[e];
        if (a != null && (i = n ? n(a) : a))
          return i;
      }
  }
  /**
  Query whether the view has focus.
  */
  hasFocus() {
    if (st) {
      let e = this.root.activeElement;
      if (e == this.dom)
        return !0;
      if (!e || !this.dom.contains(e))
        return !1;
      for (; e && this.dom != e && this.dom.contains(e); ) {
        if (e.contentEditable == "false")
          return !1;
        e = e.parentElement;
      }
      return !0;
    }
    return this.root.activeElement == this.dom;
  }
  /**
  Focus the editor.
  */
  focus() {
    this.domObserver.stop(), this.editable && mm(this.dom), jt(this), this.domObserver.start();
  }
  /**
  Get the document root in which the editor exists. This will
  usually be the top-level `document`, but might be a [shadow
  DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)
  root if the editor is inside one.
  */
  get root() {
    let e = this._root;
    if (e == null) {
      for (let n = this.dom.parentNode; n; n = n.parentNode)
        if (n.nodeType == 9 || n.nodeType == 11 && n.host)
          return n.getSelection || (Object.getPrototypeOf(n).getSelection = () => n.ownerDocument.getSelection()), this._root = n;
    }
    return e || document;
  }
  /**
  When an existing editor view is moved to a new document or
  shadow tree, call this to make it recompute its root.
  */
  updateRoot() {
    this._root = null;
  }
  /**
  Given a pair of viewport coordinates, return the document
  position that corresponds to them. May return null if the given
  coordinates aren't inside of the editor. When an object is
  returned, its `pos` property is the position nearest to the
  coordinates, and its `inside` property holds the position of the
  inner node that the position falls inside of, or -1 if it is at
  the top level, not in any node.
  */
  posAtCoords(e) {
    return wm(this, e);
  }
  /**
  Returns the viewport rectangle at a given document position.
  `left` and `right` will be the same number, as this returns a
  flat cursor-ish rectangle. If the position is between two things
  that aren't directly adjacent, `side` determines which element
  is used. When < 0, the element before the position is used,
  otherwise the element after.
  */
  coordsAtPos(e, n = 1) {
    return Vu(this, e, n);
  }
  /**
  Find the DOM position that corresponds to the given document
  position. When `side` is negative, find the position as close as
  possible to the content before the position. When positive,
  prefer positions close to the content after the position. When
  zero, prefer as shallow a position as possible.
  
  Note that you should **not** mutate the editor's internal DOM,
  only inspect it (and even that is usually not necessary).
  */
  domAtPos(e, n = 0) {
    return this.docView.domFromPos(e, n);
  }
  /**
  Find the DOM node that represents the document node after the
  given position. May return `null` when the position doesn't point
  in front of a node or if the node is inside an opaque node view.
  
  This is intended to be able to call things like
  `getBoundingClientRect` on that DOM node. Do **not** mutate the
  editor DOM directly, or add styling this way, since that will be
  immediately overriden by the editor as it redraws the node.
  */
  nodeDOM(e) {
    let n = this.docView.descAt(e);
    return n ? n.nodeDOM : null;
  }
  /**
  Find the document position that corresponds to a given DOM
  position. (Whenever possible, it is preferable to inspect the
  document structure directly, rather than poking around in the
  DOM, but sometimes—for example when interpreting an event
  target—you don't have a choice.)
  
  The `bias` parameter can be used to influence which side of a DOM
  node to use when the position is inside a leaf node.
  */
  posAtDOM(e, n, r = -1) {
    let i = this.docView.posFromDOM(e, n, r);
    if (i == null)
      throw new RangeError("DOM position not inside the editor");
    return i;
  }
  /**
  Find out whether the selection is at the end of a textblock when
  moving in a given direction. When, for example, given `"left"`,
  it will return true if moving left from the current cursor
  position would leave that position's parent textblock. Will apply
  to the view's current state by default, but it is possible to
  pass a different state.
  */
  endOfTextblock(e, n) {
    return Mm(this, n || this.state, e);
  }
  /**
  Run the editor's paste logic with the given HTML string. The
  `event`, if given, will be passed to the
  [`handlePaste`](https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste) hook.
  */
  pasteHTML(e, n) {
    return ni(this, "", e, !1, n || new ClipboardEvent("paste"));
  }
  /**
  Run the editor's paste logic with the given plain-text input.
  */
  pasteText(e, n) {
    return ni(this, e, null, !0, n || new ClipboardEvent("paste"));
  }
  /**
  Removes the editor from the DOM and destroys all [node
  views](https://prosemirror.net/docs/ref/#view.NodeView).
  */
  destroy() {
    this.docView && (eg(this), this.destroyPluginViews(), this.mounted ? (this.docView.update(this.state.doc, [], mo(this), this), this.dom.textContent = "") : this.dom.parentNode && this.dom.parentNode.removeChild(this.dom), this.docView.destroy(), this.docView = null);
  }
  /**
  This is true when the view has been
  [destroyed](https://prosemirror.net/docs/ref/#view.EditorView.destroy) (and thus should not be
  used anymore).
  */
  get isDestroyed() {
    return this.docView == null;
  }
  /**
  Used for testing.
  */
  dispatchEvent(e) {
    return ng(this, e);
  }
  /**
  Dispatch a transaction. Will call
  [`dispatchTransaction`](https://prosemirror.net/docs/ref/#view.DirectEditorProps.dispatchTransaction)
  when given, and otherwise defaults to applying the transaction to
  the current state and calling
  [`updateState`](https://prosemirror.net/docs/ref/#view.EditorView.updateState) with the result.
  This method is bound to the view instance, so that it can be
  easily passed around.
  */
  dispatch(e) {
    let n = this._props.dispatchTransaction;
    n ? n.call(this, e) : this.updateState(this.state.apply(e));
  }
  /**
  @internal
  */
  domSelectionRange() {
    return Xe && this.root.nodeType === 11 && om(this.dom.ownerDocument) == this.dom ? Sg(this) : this.domSelection();
  }
  /**
  @internal
  */
  domSelection() {
    return this.root.getSelection();
  }
}
function vc(t) {
  let e = /* @__PURE__ */ Object.create(null);
  return e.class = "ProseMirror", e.contenteditable = String(t.editable), t.someProp("attributes", (n) => {
    if (typeof n == "function" && (n = n(t.state)), n)
      for (let r in n)
        r == "class" ? e.class += " " + n[r] : r == "style" ? e.style = (e.style ? e.style + ";" : "") + n[r] : !e[r] && r != "contenteditable" && r != "nodeName" && (e[r] = String(n[r]));
  }), e.translate || (e.translate = "no"), [Le.node(0, t.state.doc.content.size, e)];
}
function wc(t) {
  if (t.markCursor) {
    let e = document.createElement("img");
    e.className = "ProseMirror-separator", e.setAttribute("mark-placeholder", "true"), e.setAttribute("alt", ""), t.cursorWrapper = { dom: e, deco: Le.widget(t.state.selection.head, e, { raw: !0, marks: t.markCursor }) };
  } else
    t.cursorWrapper = null;
}
function Ec(t) {
  return !t.someProp("editable", (e) => e(t.state) === !1);
}
function Rg(t, e) {
  let n = Math.min(t.$anchor.sharedDepth(t.head), e.$anchor.sharedDepth(e.head));
  return t.$anchor.start(n) != e.$anchor.start(n);
}
function xc(t) {
  let e = /* @__PURE__ */ Object.create(null);
  function n(r) {
    for (let i in r)
      Object.prototype.hasOwnProperty.call(e, i) || (e[i] = r[i]);
  }
  return t.someProp("nodeViews", n), t.someProp("markViews", n), e;
}
function Lg(t, e) {
  let n = 0, r = 0;
  for (let i in t) {
    if (t[i] != e[i])
      return !0;
    n++;
  }
  for (let i in e)
    r++;
  return n != r;
}
function Sc(t) {
  if (t.spec.state || t.spec.filterTransaction || t.spec.appendTransaction)
    throw new RangeError("Plugins passed directly to the view must not have a state component");
}
var bn = {
  8: "Backspace",
  9: "Tab",
  10: "Enter",
  12: "NumLock",
  13: "Enter",
  16: "Shift",
  17: "Control",
  18: "Alt",
  20: "CapsLock",
  27: "Escape",
  32: " ",
  33: "PageUp",
  34: "PageDown",
  35: "End",
  36: "Home",
  37: "ArrowLeft",
  38: "ArrowUp",
  39: "ArrowRight",
  40: "ArrowDown",
  44: "PrintScreen",
  45: "Insert",
  46: "Delete",
  59: ";",
  61: "=",
  91: "Meta",
  92: "Meta",
  106: "*",
  107: "+",
  108: ",",
  109: "-",
  110: ".",
  111: "/",
  144: "NumLock",
  145: "ScrollLock",
  160: "Shift",
  161: "Shift",
  162: "Control",
  163: "Control",
  164: "Alt",
  165: "Alt",
  173: "-",
  186: ";",
  187: "=",
  188: ",",
  189: "-",
  190: ".",
  191: "/",
  192: "`",
  219: "[",
  220: "\\",
  221: "]",
  222: "'"
}, ds = {
  48: ")",
  49: "!",
  50: "@",
  51: "#",
  52: "$",
  53: "%",
  54: "^",
  55: "&",
  56: "*",
  57: "(",
  59: ":",
  61: "+",
  173: "_",
  186: ":",
  187: "+",
  188: "<",
  189: "_",
  190: ">",
  191: "?",
  192: "~",
  219: "{",
  220: "|",
  221: "}",
  222: '"'
}, Ig = typeof navigator < "u" && /Mac/.test(navigator.platform), Dg = typeof navigator < "u" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
for (var Fe = 0; Fe < 10; Fe++)
  bn[48 + Fe] = bn[96 + Fe] = String(Fe);
for (var Fe = 1; Fe <= 24; Fe++)
  bn[Fe + 111] = "F" + Fe;
for (var Fe = 65; Fe <= 90; Fe++)
  bn[Fe] = String.fromCharCode(Fe + 32), ds[Fe] = String.fromCharCode(Fe);
for (var bo in bn)
  ds.hasOwnProperty(bo) || (ds[bo] = bn[bo]);
function Hg(t) {
  var e = Ig && t.metaKey && t.shiftKey && !t.ctrlKey && !t.altKey || Dg && t.shiftKey && t.key && t.key.length == 1 || t.key == "Unidentified", n = !e && t.key || (t.shiftKey ? ds : bn)[t.keyCode] || t.key || "Unidentified";
  return n == "Esc" && (n = "Escape"), n == "Del" && (n = "Delete"), n == "Left" && (n = "ArrowLeft"), n == "Up" && (n = "ArrowUp"), n == "Right" && (n = "ArrowRight"), n == "Down" && (n = "ArrowDown"), n;
}
const Bg = typeof navigator < "u" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : !1;
function Pg(t) {
  let e = t.split(/-(?!$)/), n = e[e.length - 1];
  n == "Space" && (n = " ");
  let r, i, s, o;
  for (let a = 0; a < e.length - 1; a++) {
    let l = e[a];
    if (/^(cmd|meta|m)$/i.test(l))
      o = !0;
    else if (/^a(lt)?$/i.test(l))
      r = !0;
    else if (/^(c|ctrl|control)$/i.test(l))
      i = !0;
    else if (/^s(hift)?$/i.test(l))
      s = !0;
    else if (/^mod$/i.test(l))
      Bg ? o = !0 : i = !0;
    else
      throw new Error("Unrecognized modifier name: " + l);
  }
  return r && (n = "Alt-" + n), i && (n = "Ctrl-" + n), o && (n = "Meta-" + n), s && (n = "Shift-" + n), n;
}
function $g(t) {
  let e = /* @__PURE__ */ Object.create(null);
  for (let n in t)
    e[Pg(n)] = t[n];
  return e;
}
function yo(t, e, n = !0) {
  return e.altKey && (t = "Alt-" + t), e.ctrlKey && (t = "Ctrl-" + t), e.metaKey && (t = "Meta-" + t), n && e.shiftKey && (t = "Shift-" + t), t;
}
function Vg(t) {
  return new Se({ props: { handleKeyDown: Va(t) } });
}
function Va(t) {
  let e = $g(t);
  return function(n, r) {
    let i = Hg(r), s, o = e[yo(i, r)];
    if (o && o(n.state, n.dispatch, n))
      return !0;
    if (i.length == 1 && i != " ") {
      if (r.shiftKey) {
        let a = e[yo(i, r, !1)];
        if (a && a(n.state, n.dispatch, n))
          return !0;
      }
      if ((r.shiftKey || r.altKey || r.metaKey || i.charCodeAt(0) > 127) && (s = bn[r.keyCode]) && s != i) {
        let a = e[yo(s, r)];
        if (a && a(n.state, n.dispatch, n))
          return !0;
      }
    }
    return !1;
  };
}
const zg = (t, e) => t.selection.empty ? !1 : (e && e(t.tr.deleteSelection().scrollIntoView()), !0);
function Fg(t, e) {
  let { $cursor: n } = t.selection;
  return !n || (e ? !e.endOfTextblock("backward", t) : n.parentOffset > 0) ? null : n;
}
const Ug = (t, e, n) => {
  let r = Fg(t, n);
  if (!r)
    return !1;
  let i = mf(r);
  if (!i) {
    let o = r.blockRange(), a = o && Ar(o);
    return a == null ? !1 : (e && e(t.tr.lift(o, a).scrollIntoView()), !0);
  }
  let s = i.nodeBefore;
  if (!s.type.spec.isolating && yf(t, i, e))
    return !0;
  if (r.parent.content.size == 0 && (Er(s, "end") || Y.isSelectable(s))) {
    let o = _a(t.doc, r.before(), r.after(), B.empty);
    if (o && o.slice.size < o.to - o.from) {
      if (e) {
        let a = t.tr.step(o);
        a.setSelection(Er(s, "end") ? te.findFrom(a.doc.resolve(a.mapping.map(i.pos, -1)), -1) : Y.create(a.doc, i.pos - s.nodeSize)), e(a.scrollIntoView());
      }
      return !0;
    }
  }
  return s.isAtom && i.depth == r.depth - 1 ? (e && e(t.tr.delete(i.pos - s.nodeSize, i.pos).scrollIntoView()), !0) : !1;
};
function Er(t, e, n = !1) {
  for (let r = t; r; r = e == "start" ? r.firstChild : r.lastChild) {
    if (r.isTextblock)
      return !0;
    if (n && r.childCount != 1)
      return !1;
  }
  return !1;
}
const Kg = (t, e, n) => {
  let { $head: r, empty: i } = t.selection, s = r;
  if (!i)
    return !1;
  if (r.parent.isTextblock) {
    if (n ? !n.endOfTextblock("backward", t) : r.parentOffset > 0)
      return !1;
    s = mf(r);
  }
  let o = s && s.nodeBefore;
  return !o || !Y.isSelectable(o) ? !1 : (e && e(t.tr.setSelection(Y.create(t.doc, s.pos - o.nodeSize)).scrollIntoView()), !0);
};
function mf(t) {
  if (!t.parent.type.spec.isolating)
    for (let e = t.depth - 1; e >= 0; e--) {
      if (t.index(e) > 0)
        return t.doc.resolve(t.before(e + 1));
      if (t.node(e).type.spec.isolating)
        break;
    }
  return null;
}
function Wg(t, e) {
  let { $cursor: n } = t.selection;
  return !n || (e ? !e.endOfTextblock("forward", t) : n.parentOffset < n.parent.content.size) ? null : n;
}
const qg = (t, e, n) => {
  let r = Wg(t, n);
  if (!r)
    return !1;
  let i = gf(r);
  if (!i)
    return !1;
  let s = i.nodeAfter;
  if (yf(t, i, e))
    return !0;
  if (r.parent.content.size == 0 && (Er(s, "start") || Y.isSelectable(s))) {
    let o = _a(t.doc, r.before(), r.after(), B.empty);
    if (o && o.slice.size < o.to - o.from) {
      if (e) {
        let a = t.tr.step(o);
        a.setSelection(Er(s, "start") ? te.findFrom(a.doc.resolve(a.mapping.map(i.pos)), 1) : Y.create(a.doc, a.mapping.map(i.pos))), e(a.scrollIntoView());
      }
      return !0;
    }
  }
  return s.isAtom && i.depth == r.depth - 1 ? (e && e(t.tr.delete(i.pos, i.pos + s.nodeSize).scrollIntoView()), !0) : !1;
}, Zg = (t, e, n) => {
  let { $head: r, empty: i } = t.selection, s = r;
  if (!i)
    return !1;
  if (r.parent.isTextblock) {
    if (n ? !n.endOfTextblock("forward", t) : r.parentOffset < r.parent.content.size)
      return !1;
    s = gf(r);
  }
  let o = s && s.nodeAfter;
  return !o || !Y.isSelectable(o) ? !1 : (e && e(t.tr.setSelection(Y.create(t.doc, s.pos)).scrollIntoView()), !0);
};
function gf(t) {
  if (!t.parent.type.spec.isolating)
    for (let e = t.depth - 1; e >= 0; e--) {
      let n = t.node(e);
      if (t.index(e) + 1 < n.childCount)
        return t.doc.resolve(t.after(e + 1));
      if (n.type.spec.isolating)
        break;
    }
  return null;
}
const Gg = (t, e) => {
  let n = t.selection, r = n instanceof Y, i;
  if (r) {
    if (n.node.isTextblock || !vn(t.doc, n.from))
      return !1;
    i = n.from;
  } else if (i = Ds(t.doc, n.from, -1), i == null)
    return !1;
  if (e) {
    let s = t.tr.join(i);
    r && s.setSelection(Y.create(s.doc, i - t.doc.resolve(i).nodeBefore.nodeSize)), e(s.scrollIntoView());
  }
  return !0;
}, jg = (t, e) => {
  let n = t.selection, r;
  if (n instanceof Y) {
    if (n.node.isTextblock || !vn(t.doc, n.to))
      return !1;
    r = n.to;
  } else if (r = Ds(t.doc, n.to, 1), r == null)
    return !1;
  return e && e(t.tr.join(r).scrollIntoView()), !0;
}, Yg = (t, e) => {
  let { $from: n, $to: r } = t.selection, i = n.blockRange(r), s = i && Ar(i);
  return s == null ? !1 : (e && e(t.tr.lift(i, s).scrollIntoView()), !0);
}, Jg = (t, e) => {
  let { $head: n, $anchor: r } = t.selection;
  return !n.parent.type.spec.code || !n.sameParent(r) ? !1 : (e && e(t.tr.insertText(`
`).scrollIntoView()), !0);
};
function bf(t) {
  for (let e = 0; e < t.edgeCount; e++) {
    let { type: n } = t.edge(e);
    if (n.isTextblock && !n.hasRequiredAttrs())
      return n;
  }
  return null;
}
const Xg = (t, e) => {
  let { $head: n, $anchor: r } = t.selection;
  if (!n.parent.type.spec.code || !n.sameParent(r))
    return !1;
  let i = n.node(-1), s = n.indexAfter(-1), o = bf(i.contentMatchAt(s));
  if (!o || !i.canReplaceWith(s, s, o))
    return !1;
  if (e) {
    let a = n.after(), l = t.tr.replaceWith(a, a, o.createAndFill());
    l.setSelection(te.near(l.doc.resolve(a), 1)), e(l.scrollIntoView());
  }
  return !0;
}, Qg = (t, e) => {
  let n = t.selection, { $from: r, $to: i } = n;
  if (n instanceof wt || r.parent.inlineContent || i.parent.inlineContent)
    return !1;
  let s = bf(i.parent.contentMatchAt(i.indexAfter()));
  if (!s || !s.isTextblock)
    return !1;
  if (e) {
    let o = (!r.parentOffset && i.index() < i.parent.childCount ? r : i).pos, a = t.tr.insert(o, s.createAndFill());
    a.setSelection(G.create(a.doc, o + 1)), e(a.scrollIntoView());
  }
  return !0;
}, e1 = (t, e) => {
  let { $cursor: n } = t.selection;
  if (!n || n.parent.content.size)
    return !1;
  if (n.depth > 1 && n.after() != n.end(-1)) {
    let s = n.before();
    if (hr(t.doc, s))
      return e && e(t.tr.split(s).scrollIntoView()), !0;
  }
  let r = n.blockRange(), i = r && Ar(r);
  return i == null ? !1 : (e && e(t.tr.lift(r, i).scrollIntoView()), !0);
}, t1 = (t, e) => {
  let { $from: n, to: r } = t.selection, i, s = n.sharedDepth(r);
  return s == 0 ? !1 : (i = n.before(s), e && e(t.tr.setSelection(Y.create(t.doc, i))), !0);
};
function n1(t, e, n) {
  let r = e.nodeBefore, i = e.nodeAfter, s = e.index();
  return !r || !i || !r.type.compatibleContent(i.type) ? !1 : !r.content.size && e.parent.canReplace(s - 1, s) ? (n && n(t.tr.delete(e.pos - r.nodeSize, e.pos).scrollIntoView()), !0) : !e.parent.canReplace(s, s + 1) || !(i.isTextblock || vn(t.doc, e.pos)) ? !1 : (n && n(t.tr.clearIncompatible(e.pos, r.type, r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()), !0);
}
function yf(t, e, n) {
  let r = e.nodeBefore, i = e.nodeAfter, s, o;
  if (r.type.spec.isolating || i.type.spec.isolating)
    return !1;
  if (n1(t, e, n))
    return !0;
  let a = e.parent.canReplace(e.index(), e.index() + 1);
  if (a && (s = (o = r.contentMatchAt(r.childCount)).findWrapping(i.type)) && o.matchType(s[0] || i.type).validEnd) {
    if (n) {
      let u = e.pos + i.nodeSize, f = A.empty;
      for (let m = s.length - 1; m >= 0; m--)
        f = A.from(s[m].create(null, f));
      f = A.from(r.copy(f));
      let p = t.tr.step(new De(e.pos - 1, u, e.pos, u, new B(f, 1, 0), s.length, !0)), h = u + 2 * s.length;
      vn(p.doc, h) && p.join(h), n(p.scrollIntoView());
    }
    return !0;
  }
  let l = te.findFrom(e, 1), c = l && l.$from.blockRange(l.$to), d = c && Ar(c);
  if (d != null && d >= e.depth)
    return n && n(t.tr.lift(c, d).scrollIntoView()), !0;
  if (a && Er(i, "start", !0) && Er(r, "end")) {
    let u = r, f = [];
    for (; f.push(u), !u.isTextblock; )
      u = u.lastChild;
    let p = i, h = 1;
    for (; !p.isTextblock; p = p.firstChild)
      h++;
    if (u.canReplace(u.childCount, u.childCount, p.content)) {
      if (n) {
        let m = A.empty;
        for (let v = f.length - 1; v >= 0; v--)
          m = A.from(f[v].copy(m));
        let g = t.tr.step(new De(e.pos - f.length, e.pos + i.nodeSize, e.pos + h, e.pos + i.nodeSize - h, new B(m, f.length, 0), 0, !0));
        n(g.scrollIntoView());
      }
      return !0;
    }
  }
  return !1;
}
function vf(t) {
  return function(e, n) {
    let r = e.selection, i = t < 0 ? r.$from : r.$to, s = i.depth;
    for (; i.node(s).isInline; ) {
      if (!s)
        return !1;
      s--;
    }
    return i.node(s).isTextblock ? (n && n(e.tr.setSelection(G.create(e.doc, t < 0 ? i.start(s) : i.end(s)))), !0) : !1;
  };
}
const r1 = vf(-1), i1 = vf(1);
function s1(t, e = null) {
  return function(n, r) {
    let { $from: i, $to: s } = n.selection, o = i.blockRange(s), a = o && Ta(o, t, e);
    return a ? (r && r(n.tr.wrap(o, a).scrollIntoView()), !0) : !1;
  };
}
function Cc(t, e = null) {
  return function(n, r) {
    let i = !1;
    for (let s = 0; s < n.selection.ranges.length && !i; s++) {
      let { $from: { pos: o }, $to: { pos: a } } = n.selection.ranges[s];
      n.doc.nodesBetween(o, a, (l, c) => {
        if (i)
          return !1;
        if (!(!l.isTextblock || l.hasMarkup(t, e)))
          if (l.type == t)
            i = !0;
          else {
            let d = n.doc.resolve(c), u = d.index();
            i = d.parent.canReplaceWith(u, u + 1, t);
          }
      });
    }
    if (!i)
      return !1;
    if (r) {
      let s = n.tr;
      for (let o = 0; o < n.selection.ranges.length; o++) {
        let { $from: { pos: a }, $to: { pos: l } } = n.selection.ranges[o];
        s.setBlockType(a, l, t, e);
      }
      r(s.scrollIntoView());
    }
    return !0;
  };
}
typeof navigator < "u" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : typeof os < "u" && os.platform && os.platform() == "darwin";
function o1(t, e = null) {
  return function(n, r) {
    let { $from: i, $to: s } = n.selection, o = i.blockRange(s), a = !1, l = o;
    if (!o)
      return !1;
    if (o.depth >= 2 && i.node(o.depth - 1).type.compatibleContent(t) && o.startIndex == 0) {
      if (i.index(o.depth - 1) == 0)
        return !1;
      let d = n.doc.resolve(o.start - 2);
      l = new ts(d, d, o.depth), o.endIndex < o.parent.childCount && (o = new ts(i, n.doc.resolve(s.end(o.depth)), o.depth)), a = !0;
    }
    let c = Ta(l, t, e, o);
    return c ? (r && r(a1(n.tr, o, c, a, t).scrollIntoView()), !0) : !1;
  };
}
function a1(t, e, n, r, i) {
  let s = A.empty;
  for (let d = n.length - 1; d >= 0; d--)
    s = A.from(n[d].type.create(n[d].attrs, s));
  t.step(new De(e.start - (r ? 2 : 0), e.end, e.start, e.end, new B(s, 0, 0), n.length, !0));
  let o = 0;
  for (let d = 0; d < n.length; d++)
    n[d].type == i && (o = d + 1);
  let a = n.length - o, l = e.start + n.length - (r ? 2 : 0), c = e.parent;
  for (let d = e.startIndex, u = e.endIndex, f = !0; d < u; d++, f = !1)
    !f && hr(t.doc, l, a) && (t.split(l, a), l += 2 * a), l += c.child(d).nodeSize;
  return t;
}
function l1(t) {
  return function(e, n) {
    let { $from: r, $to: i } = e.selection, s = r.blockRange(i, (o) => o.childCount > 0 && o.firstChild.type == t);
    return s ? n ? r.node(s.depth - 1).type == t ? c1(e, n, t, s) : d1(e, n, s) : !0 : !1;
  };
}
function c1(t, e, n, r) {
  let i = t.tr, s = r.end, o = r.$to.end(r.depth);
  s < o && (i.step(new De(s - 1, o, s, o, new B(A.from(n.create(null, r.parent.copy())), 1, 0), 1, !0)), r = new ts(i.doc.resolve(r.$from.pos), i.doc.resolve(o), r.depth));
  const a = Ar(r);
  if (a == null)
    return !1;
  i.lift(r, a);
  let l = i.mapping.map(s, -1) - 1;
  return vn(i.doc, l) && i.join(l), e(i.scrollIntoView()), !0;
}
function d1(t, e, n) {
  let r = t.tr, i = n.parent;
  for (let p = n.end, h = n.endIndex - 1, m = n.startIndex; h > m; h--)
    p -= i.child(h).nodeSize, r.delete(p - 1, p + 1);
  let s = r.doc.resolve(n.start), o = s.nodeAfter;
  if (r.mapping.map(n.end) != n.start + s.nodeAfter.nodeSize)
    return !1;
  let a = n.startIndex == 0, l = n.endIndex == i.childCount, c = s.node(-1), d = s.index(-1);
  if (!c.canReplace(d + (a ? 0 : 1), d + 1, o.content.append(l ? A.empty : A.from(i))))
    return !1;
  let u = s.pos, f = u + o.nodeSize;
  return r.step(new De(u - (a ? 1 : 0), f + (l ? 1 : 0), u + 1, f - 1, new B((a ? A.empty : A.from(i.copy(A.empty))).append(l ? A.empty : A.from(i.copy(A.empty))), a ? 0 : 1, l ? 0 : 1), a ? 0 : 1)), e(r.scrollIntoView()), !0;
}
function u1(t) {
  return function(e, n) {
    let { $from: r, $to: i } = e.selection, s = r.blockRange(i, (c) => c.childCount > 0 && c.firstChild.type == t);
    if (!s)
      return !1;
    let o = s.startIndex;
    if (o == 0)
      return !1;
    let a = s.parent, l = a.child(o - 1);
    if (l.type != t)
      return !1;
    if (n) {
      let c = l.lastChild && l.lastChild.type == a.type, d = A.from(c ? t.create() : null), u = new B(A.from(t.create(null, A.from(a.type.create(null, d)))), c ? 3 : 1, 0), f = s.start, p = s.end;
      n(e.tr.step(new De(f - (c ? 3 : 1), p, f, p, u, 1, !0)).scrollIntoView());
    }
    return !0;
  };
}
function Vs(t) {
  const { state: e, transaction: n } = t;
  let { selection: r } = n, { doc: i } = n, { storedMarks: s } = n;
  return {
    ...e,
    apply: e.apply.bind(e),
    applyTransaction: e.applyTransaction.bind(e),
    filterTransaction: e.filterTransaction,
    plugins: e.plugins,
    schema: e.schema,
    reconfigure: e.reconfigure.bind(e),
    toJSON: e.toJSON.bind(e),
    get storedMarks() {
      return s;
    },
    get selection() {
      return r;
    },
    get doc() {
      return i;
    },
    get tr() {
      return r = n.selection, i = n.doc, s = n.storedMarks, n;
    }
  };
}
class zs {
  constructor(e) {
    this.editor = e.editor, this.rawCommands = this.editor.extensionManager.commands, this.customState = e.state;
  }
  get hasCustomState() {
    return !!this.customState;
  }
  get state() {
    return this.customState || this.editor.state;
  }
  get commands() {
    const { rawCommands: e, editor: n, state: r } = this, { view: i } = n, { tr: s } = r, o = this.buildProps(s);
    return Object.fromEntries(Object.entries(e).map(([a, l]) => [a, (...d) => {
      const u = l(...d)(o);
      return !s.getMeta("preventDispatch") && !this.hasCustomState && i.dispatch(s), u;
    }]));
  }
  get chain() {
    return () => this.createChain();
  }
  get can() {
    return () => this.createCan();
  }
  createChain(e, n = !0) {
    const { rawCommands: r, editor: i, state: s } = this, { view: o } = i, a = [], l = !!e, c = e || s.tr, d = () => (!l && n && !c.getMeta("preventDispatch") && !this.hasCustomState && o.dispatch(c), a.every((f) => f === !0)), u = {
      ...Object.fromEntries(Object.entries(r).map(([f, p]) => [f, (...m) => {
        const g = this.buildProps(c, n), v = p(...m)(g);
        return a.push(v), u;
      }])),
      run: d
    };
    return u;
  }
  createCan(e) {
    const { rawCommands: n, state: r } = this, i = !1, s = e || r.tr, o = this.buildProps(s, i);
    return {
      ...Object.fromEntries(Object.entries(n).map(([l, c]) => [l, (...d) => c(...d)({ ...o, dispatch: void 0 })])),
      chain: () => this.createChain(s, i)
    };
  }
  buildProps(e, n = !0) {
    const { rawCommands: r, editor: i, state: s } = this, { view: o } = i, a = {
      tr: e,
      editor: i,
      view: o,
      state: Vs({
        state: s,
        transaction: e
      }),
      dispatch: n ? () => {
      } : void 0,
      chain: () => this.createChain(e, n),
      can: () => this.createCan(e),
      get commands() {
        return Object.fromEntries(Object.entries(r).map(([l, c]) => [l, (...d) => c(...d)(a)]));
      }
    };
    return a;
  }
}
class f1 {
  constructor() {
    this.callbacks = {};
  }
  on(e, n) {
    return this.callbacks[e] || (this.callbacks[e] = []), this.callbacks[e].push(n), this;
  }
  emit(e, ...n) {
    const r = this.callbacks[e];
    return r && r.forEach((i) => i.apply(this, n)), this;
  }
  off(e, n) {
    const r = this.callbacks[e];
    return r && (n ? this.callbacks[e] = r.filter((i) => i !== n) : delete this.callbacks[e]), this;
  }
  removeAllListeners() {
    this.callbacks = {};
  }
}
function z(t, e, n) {
  return t.config[e] === void 0 && t.parent ? z(t.parent, e, n) : typeof t.config[e] == "function" ? t.config[e].bind({
    ...n,
    parent: t.parent ? z(t.parent, e, n) : null
  }) : t.config[e];
}
function Fs(t) {
  const e = t.filter((i) => i.type === "extension"), n = t.filter((i) => i.type === "node"), r = t.filter((i) => i.type === "mark");
  return {
    baseExtensions: e,
    nodeExtensions: n,
    markExtensions: r
  };
}
function wf(t) {
  const e = [], { nodeExtensions: n, markExtensions: r } = Fs(t), i = [...n, ...r], s = {
    default: null,
    rendered: !0,
    renderHTML: null,
    parseHTML: null,
    keepOnSplit: !0,
    isRequired: !1
  };
  return t.forEach((o) => {
    const a = {
      name: o.name,
      options: o.options,
      storage: o.storage
    }, l = z(o, "addGlobalAttributes", a);
    if (!l)
      return;
    l().forEach((d) => {
      d.types.forEach((u) => {
        Object.entries(d.attributes).forEach(([f, p]) => {
          e.push({
            type: u,
            name: f,
            attribute: {
              ...s,
              ...p
            }
          });
        });
      });
    });
  }), i.forEach((o) => {
    const a = {
      name: o.name,
      options: o.options,
      storage: o.storage
    }, l = z(o, "addAttributes", a);
    if (!l)
      return;
    const c = l();
    Object.entries(c).forEach(([d, u]) => {
      const f = {
        ...s,
        ...u
      };
      typeof (f == null ? void 0 : f.default) == "function" && (f.default = f.default()), f != null && f.isRequired && (f == null ? void 0 : f.default) === void 0 && delete f.default, e.push({
        type: o.name,
        name: d,
        attribute: f
      });
    });
  }), e;
}
function Be(t, e) {
  if (typeof t == "string") {
    if (!e.nodes[t])
      throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);
    return e.nodes[t];
  }
  return t;
}
function fe(...t) {
  return t.filter((e) => !!e).reduce((e, n) => {
    const r = { ...e };
    return Object.entries(n).forEach(([i, s]) => {
      if (!r[i]) {
        r[i] = s;
        return;
      }
      if (i === "class") {
        const a = s ? s.split(" ") : [], l = r[i] ? r[i].split(" ") : [], c = a.filter((d) => !l.includes(d));
        r[i] = [...l, ...c].join(" ");
      } else
        i === "style" ? r[i] = [r[i], s].join("; ") : r[i] = s;
    }), r;
  }, {});
}
function ia(t, e) {
  return e.filter((n) => n.attribute.rendered).map((n) => n.attribute.renderHTML ? n.attribute.renderHTML(t.attrs) || {} : {
    [n.name]: t.attrs[n.name]
  }).reduce((n, r) => fe(n, r), {});
}
function Ef(t) {
  return typeof t == "function";
}
function ie(t, e = void 0, ...n) {
  return Ef(t) ? e ? t.bind(e)(...n) : t(...n) : t;
}
function p1(t = {}) {
  return Object.keys(t).length === 0 && t.constructor === Object;
}
function h1(t) {
  return typeof t != "string" ? t : t.match(/^[+-]?(?:\d*\.)?\d+$/) ? Number(t) : t === "true" ? !0 : t === "false" ? !1 : t;
}
function Mc(t, e) {
  return t.style ? t : {
    ...t,
    getAttrs: (n) => {
      const r = t.getAttrs ? t.getAttrs(n) : t.attrs;
      if (r === !1)
        return !1;
      const i = e.reduce((s, o) => {
        const a = o.attribute.parseHTML ? o.attribute.parseHTML(n) : h1(n.getAttribute(o.name));
        return a == null ? s : {
          ...s,
          [o.name]: a
        };
      }, {});
      return { ...r, ...i };
    }
  };
}
function kc(t) {
  return Object.fromEntries(
    // @ts-ignore
    Object.entries(t).filter(([e, n]) => e === "attrs" && p1(n) ? !1 : n != null)
  );
}
function m1(t, e) {
  var n;
  const r = wf(t), { nodeExtensions: i, markExtensions: s } = Fs(t), o = (n = i.find((c) => z(c, "topNode"))) === null || n === void 0 ? void 0 : n.name, a = Object.fromEntries(i.map((c) => {
    const d = r.filter((v) => v.type === c.name), u = {
      name: c.name,
      options: c.options,
      storage: c.storage,
      editor: e
    }, f = t.reduce((v, y) => {
      const E = z(y, "extendNodeSchema", u);
      return {
        ...v,
        ...E ? E(c) : {}
      };
    }, {}), p = kc({
      ...f,
      content: ie(z(c, "content", u)),
      marks: ie(z(c, "marks", u)),
      group: ie(z(c, "group", u)),
      inline: ie(z(c, "inline", u)),
      atom: ie(z(c, "atom", u)),
      selectable: ie(z(c, "selectable", u)),
      draggable: ie(z(c, "draggable", u)),
      code: ie(z(c, "code", u)),
      defining: ie(z(c, "defining", u)),
      isolating: ie(z(c, "isolating", u)),
      attrs: Object.fromEntries(d.map((v) => {
        var y;
        return [v.name, { default: (y = v == null ? void 0 : v.attribute) === null || y === void 0 ? void 0 : y.default }];
      }))
    }), h = ie(z(c, "parseHTML", u));
    h && (p.parseDOM = h.map((v) => Mc(v, d)));
    const m = z(c, "renderHTML", u);
    m && (p.toDOM = (v) => m({
      node: v,
      HTMLAttributes: ia(v, d)
    }));
    const g = z(c, "renderText", u);
    return g && (p.toText = g), [c.name, p];
  })), l = Object.fromEntries(s.map((c) => {
    const d = r.filter((g) => g.type === c.name), u = {
      name: c.name,
      options: c.options,
      storage: c.storage,
      editor: e
    }, f = t.reduce((g, v) => {
      const y = z(v, "extendMarkSchema", u);
      return {
        ...g,
        ...y ? y(c) : {}
      };
    }, {}), p = kc({
      ...f,
      inclusive: ie(z(c, "inclusive", u)),
      excludes: ie(z(c, "excludes", u)),
      group: ie(z(c, "group", u)),
      spanning: ie(z(c, "spanning", u)),
      code: ie(z(c, "code", u)),
      attrs: Object.fromEntries(d.map((g) => {
        var v;
        return [g.name, { default: (v = g == null ? void 0 : g.attribute) === null || v === void 0 ? void 0 : v.default }];
      }))
    }), h = ie(z(c, "parseHTML", u));
    h && (p.parseDOM = h.map((g) => Mc(g, d)));
    const m = z(c, "renderHTML", u);
    return m && (p.toDOM = (g) => m({
      mark: g,
      HTMLAttributes: ia(g, d)
    })), [c.name, p];
  }));
  return new kh({
    topNode: o,
    nodes: a,
    marks: l
  });
}
function vo(t, e) {
  return e.nodes[t] || e.marks[t] || null;
}
function Tc(t, e) {
  return Array.isArray(e) ? e.some((n) => (typeof n == "string" ? n : n.name) === t.name) : e;
}
const g1 = (t, e = 500) => {
  let n = "";
  const r = t.parentOffset;
  return t.parent.nodesBetween(Math.max(0, r - e), r, (i, s, o, a) => {
    var l, c;
    const d = ((c = (l = i.type.spec).toText) === null || c === void 0 ? void 0 : c.call(l, {
      node: i,
      pos: s,
      parent: o,
      index: a
    })) || i.textContent || "%leaf%";
    n += d.slice(0, Math.max(0, r - s));
  }), n;
};
function za(t) {
  return Object.prototype.toString.call(t) === "[object RegExp]";
}
class yi {
  constructor(e) {
    this.find = e.find, this.handler = e.handler;
  }
}
const b1 = (t, e) => {
  if (za(e))
    return e.exec(t);
  const n = e(t);
  if (!n)
    return null;
  const r = [n.text];
  return r.index = n.index, r.input = t, r.data = n.data, n.replaceWith && (n.text.includes(n.replaceWith) || console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'), r.push(n.replaceWith)), r;
};
function wo(t) {
  var e;
  const { editor: n, from: r, to: i, text: s, rules: o, plugin: a } = t, { view: l } = n;
  if (l.composing)
    return !1;
  const c = l.state.doc.resolve(r);
  if (
    // check for code node
    c.parent.type.spec.code || !((e = c.nodeBefore || c.nodeAfter) === null || e === void 0) && e.marks.find((f) => f.type.spec.code)
  )
    return !1;
  let d = !1;
  const u = g1(c) + s;
  return o.forEach((f) => {
    if (d)
      return;
    const p = b1(u, f.find);
    if (!p)
      return;
    const h = l.state.tr, m = Vs({
      state: l.state,
      transaction: h
    }), g = {
      from: r - (p[0].length - s.length),
      to: i
    }, { commands: v, chain: y, can: E } = new zs({
      editor: n,
      state: m
    });
    f.handler({
      state: m,
      range: g,
      match: p,
      commands: v,
      chain: y,
      can: E
    }) === null || !h.steps.length || (h.setMeta(a, {
      transform: h,
      from: r,
      to: i,
      text: s
    }), l.dispatch(h), d = !0);
  }), d;
}
function y1(t) {
  const { editor: e, rules: n } = t, r = new Se({
    state: {
      init() {
        return null;
      },
      apply(i, s) {
        const o = i.getMeta(r);
        return o || (i.selectionSet || i.docChanged ? null : s);
      }
    },
    props: {
      handleTextInput(i, s, o, a) {
        return wo({
          editor: e,
          from: s,
          to: o,
          text: a,
          rules: n,
          plugin: r
        });
      },
      handleDOMEvents: {
        compositionend: (i) => (setTimeout(() => {
          const { $cursor: s } = i.state.selection;
          s && wo({
            editor: e,
            from: s.pos,
            to: s.pos,
            text: "",
            rules: n,
            plugin: r
          });
        }), !1)
      },
      // add support for input rules to trigger on enter
      // this is useful for example for code blocks
      handleKeyDown(i, s) {
        if (s.key !== "Enter")
          return !1;
        const { $cursor: o } = i.state.selection;
        return o ? wo({
          editor: e,
          from: o.pos,
          to: o.pos,
          text: `
`,
          rules: n,
          plugin: r
        }) : !1;
      }
    },
    // @ts-ignore
    isInputRules: !0
  });
  return r;
}
function v1(t) {
  return typeof t == "number";
}
class w1 {
  constructor(e) {
    this.find = e.find, this.handler = e.handler;
  }
}
const E1 = (t, e) => {
  if (za(e))
    return [...t.matchAll(e)];
  const n = e(t);
  return n ? n.map((r) => {
    const i = [r.text];
    return i.index = r.index, i.input = t, i.data = r.data, r.replaceWith && (r.text.includes(r.replaceWith) || console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'), i.push(r.replaceWith)), i;
  }) : [];
};
function x1(t) {
  const { editor: e, state: n, from: r, to: i, rule: s, pasteEvent: o, dropEvent: a } = t, { commands: l, chain: c, can: d } = new zs({
    editor: e,
    state: n
  }), u = [];
  return n.doc.nodesBetween(r, i, (p, h) => {
    if (!p.isTextblock || p.type.spec.code)
      return;
    const m = Math.max(r, h), g = Math.min(i, h + p.content.size), v = p.textBetween(m - h, g - h, void 0, "￼");
    E1(v, s.find).forEach((E) => {
      if (E.index === void 0)
        return;
      const b = m + E.index + 1, C = b + E[0].length, w = {
        from: n.tr.mapping.map(b),
        to: n.tr.mapping.map(C)
      }, _ = s.handler({
        state: n,
        range: w,
        match: E,
        commands: l,
        chain: c,
        can: d,
        pasteEvent: o,
        dropEvent: a
      });
      u.push(_);
    });
  }), u.every((p) => p !== null);
}
function S1(t) {
  const { editor: e, rules: n } = t;
  let r = null, i = !1, s = !1, o = new ClipboardEvent("paste"), a = new DragEvent("drop");
  return n.map((c) => new Se({
    // we register a global drag handler to track the current drag source element
    view(d) {
      const u = (f) => {
        var p;
        r = !((p = d.dom.parentElement) === null || p === void 0) && p.contains(f.target) ? d.dom.parentElement : null;
      };
      return window.addEventListener("dragstart", u), {
        destroy() {
          window.removeEventListener("dragstart", u);
        }
      };
    },
    props: {
      handleDOMEvents: {
        drop: (d, u) => (s = r === d.dom.parentElement, a = u, !1),
        paste: (d, u) => {
          var f;
          const p = (f = u.clipboardData) === null || f === void 0 ? void 0 : f.getData("text/html");
          return o = u, i = !!(p != null && p.includes("data-pm-slice")), !1;
        }
      }
    },
    appendTransaction: (d, u, f) => {
      const p = d[0], h = p.getMeta("uiEvent") === "paste" && !i, m = p.getMeta("uiEvent") === "drop" && !s;
      if (!h && !m)
        return;
      const g = u.doc.content.findDiffStart(f.doc.content), v = u.doc.content.findDiffEnd(f.doc.content);
      if (!v1(g) || !v || g === v.b)
        return;
      const y = f.tr, E = Vs({
        state: f,
        transaction: y
      });
      if (!(!x1({
        editor: e,
        state: E,
        from: Math.max(g - 1, 0),
        to: v.b - 1,
        rule: c,
        pasteEvent: o,
        dropEvent: a
      }) || !y.steps.length))
        return a = new DragEvent("drop"), o = new ClipboardEvent("paste"), y;
    }
  }));
}
function C1(t) {
  const e = t.filter((n, r) => t.indexOf(n) !== r);
  return [...new Set(e)];
}
class cr {
  constructor(e, n) {
    this.splittableMarks = [], this.editor = n, this.extensions = cr.resolve(e), this.schema = m1(this.extensions, n), this.extensions.forEach((r) => {
      var i;
      this.editor.extensionStorage[r.name] = r.storage;
      const s = {
        name: r.name,
        options: r.options,
        storage: r.storage,
        editor: this.editor,
        type: vo(r.name, this.schema)
      };
      r.type === "mark" && (!((i = ie(z(r, "keepOnSplit", s))) !== null && i !== void 0) || i) && this.splittableMarks.push(r.name);
      const o = z(r, "onBeforeCreate", s);
      o && this.editor.on("beforeCreate", o);
      const a = z(r, "onCreate", s);
      a && this.editor.on("create", a);
      const l = z(r, "onUpdate", s);
      l && this.editor.on("update", l);
      const c = z(r, "onSelectionUpdate", s);
      c && this.editor.on("selectionUpdate", c);
      const d = z(r, "onTransaction", s);
      d && this.editor.on("transaction", d);
      const u = z(r, "onFocus", s);
      u && this.editor.on("focus", u);
      const f = z(r, "onBlur", s);
      f && this.editor.on("blur", f);
      const p = z(r, "onDestroy", s);
      p && this.editor.on("destroy", p);
    });
  }
  static resolve(e) {
    const n = cr.sort(cr.flatten(e)), r = C1(n.map((i) => i.name));
    return r.length && console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map((i) => `'${i}'`).join(", ")}]. This can lead to issues.`), n;
  }
  static flatten(e) {
    return e.map((n) => {
      const r = {
        name: n.name,
        options: n.options,
        storage: n.storage
      }, i = z(n, "addExtensions", r);
      return i ? [n, ...this.flatten(i())] : n;
    }).flat(10);
  }
  static sort(e) {
    return e.sort((r, i) => {
      const s = z(r, "priority") || 100, o = z(i, "priority") || 100;
      return s > o ? -1 : s < o ? 1 : 0;
    });
  }
  get commands() {
    return this.extensions.reduce((e, n) => {
      const r = {
        name: n.name,
        options: n.options,
        storage: n.storage,
        editor: this.editor,
        type: vo(n.name, this.schema)
      }, i = z(n, "addCommands", r);
      return i ? {
        ...e,
        ...i()
      } : e;
    }, {});
  }
  get plugins() {
    const { editor: e } = this, n = cr.sort([...this.extensions].reverse()), r = [], i = [], s = n.map((o) => {
      const a = {
        name: o.name,
        options: o.options,
        storage: o.storage,
        editor: e,
        type: vo(o.name, this.schema)
      }, l = [], c = z(o, "addKeyboardShortcuts", a);
      let d = {};
      if (o.type === "mark" && o.config.exitable && (d.ArrowRight = () => qe.handleExit({ editor: e, mark: o })), c) {
        const m = Object.fromEntries(Object.entries(c()).map(([g, v]) => [g, () => v({ editor: e })]));
        d = { ...d, ...m };
      }
      const u = Vg(d);
      l.push(u);
      const f = z(o, "addInputRules", a);
      Tc(o, e.options.enableInputRules) && f && r.push(...f());
      const p = z(o, "addPasteRules", a);
      Tc(o, e.options.enablePasteRules) && p && i.push(...p());
      const h = z(o, "addProseMirrorPlugins", a);
      if (h) {
        const m = h();
        l.push(...m);
      }
      return l;
    }).flat();
    return [
      y1({
        editor: e,
        rules: r
      }),
      ...S1({
        editor: e,
        rules: i
      }),
      ...s
    ];
  }
  get attributes() {
    return wf(this.extensions);
  }
  get nodeViews() {
    const { editor: e } = this, { nodeExtensions: n } = Fs(this.extensions);
    return Object.fromEntries(n.filter((r) => !!z(r, "addNodeView")).map((r) => {
      const i = this.attributes.filter((l) => l.type === r.name), s = {
        name: r.name,
        options: r.options,
        storage: r.storage,
        editor: e,
        type: Be(r.name, this.schema)
      }, o = z(r, "addNodeView", s);
      if (!o)
        return [];
      const a = (l, c, d, u) => {
        const f = ia(l, i);
        return o()({
          editor: e,
          node: l,
          getPos: d,
          decorations: u,
          HTMLAttributes: f,
          extension: r
        });
      };
      return [r.name, a];
    }));
  }
}
function M1(t) {
  return Object.prototype.toString.call(t).slice(8, -1);
}
function Eo(t) {
  return M1(t) !== "Object" ? !1 : t.constructor === Object && Object.getPrototypeOf(t) === Object.prototype;
}
function Us(t, e) {
  const n = { ...t };
  return Eo(t) && Eo(e) && Object.keys(e).forEach((r) => {
    Eo(e[r]) ? r in t ? n[r] = Us(t[r], e[r]) : Object.assign(n, { [r]: e[r] }) : Object.assign(n, { [r]: e[r] });
  }), n;
}
class Ce {
  constructor(e = {}) {
    this.type = "extension", this.name = "extension", this.parent = null, this.child = null, this.config = {
      name: this.name,
      defaultOptions: {}
    }, this.config = {
      ...this.config,
      ...e
    }, this.name = this.config.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = ie(z(this, "addOptions", {
      name: this.name
    }))), this.storage = ie(z(this, "addStorage", {
      name: this.name,
      options: this.options
    })) || {};
  }
  static create(e = {}) {
    return new Ce(e);
  }
  configure(e = {}) {
    const n = this.extend();
    return n.options = Us(this.options, e), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
  extend(e = {}) {
    const n = new Ce(e);
    return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = ie(z(n, "addOptions", {
      name: n.name
    })), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
}
function xf(t, e, n) {
  const { from: r, to: i } = e, { blockSeparator: s = `

`, textSerializers: o = {} } = n || {};
  let a = "", l = !0;
  return t.nodesBetween(r, i, (c, d, u, f) => {
    var p;
    const h = o == null ? void 0 : o[c.type.name];
    h ? (c.isBlock && !l && (a += s, l = !0), u && (a += h({
      node: c,
      pos: d,
      parent: u,
      index: f,
      range: e
    }))) : c.isText ? (a += (p = c == null ? void 0 : c.text) === null || p === void 0 ? void 0 : p.slice(Math.max(r, d) - d, i - d), l = !1) : c.isBlock && !l && (a += s, l = !0);
  }), a;
}
function Sf(t) {
  return Object.fromEntries(Object.entries(t.nodes).filter(([, e]) => e.spec.toText).map(([e, n]) => [e, n.spec.toText]));
}
const k1 = Ce.create({
  name: "clipboardTextSerializer",
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("clipboardTextSerializer"),
        props: {
          clipboardTextSerializer: () => {
            const { editor: t } = this, { state: e, schema: n } = t, { doc: r, selection: i } = e, { ranges: s } = i, o = Math.min(...s.map((d) => d.$from.pos)), a = Math.max(...s.map((d) => d.$to.pos)), l = Sf(n);
            return xf(r, { from: o, to: a }, {
              textSerializers: l
            });
          }
        }
      })
    ];
  }
}), T1 = () => ({ editor: t, view: e }) => (requestAnimationFrame(() => {
  var n;
  t.isDestroyed || (e.dom.blur(), (n = window == null ? void 0 : window.getSelection()) === null || n === void 0 || n.removeAllRanges());
}), !0), _1 = (t = !1) => ({ commands: e }) => e.setContent("", t), N1 = () => ({ state: t, tr: e, dispatch: n }) => {
  const { selection: r } = e, { ranges: i } = r;
  return n && i.forEach(({ $from: s, $to: o }) => {
    t.doc.nodesBetween(s.pos, o.pos, (a, l) => {
      if (a.type.isText)
        return;
      const { doc: c, mapping: d } = e, u = c.resolve(d.map(l)), f = c.resolve(d.map(l + a.nodeSize)), p = u.blockRange(f);
      if (!p)
        return;
      const h = Ar(p);
      if (a.type.isTextblock) {
        const { defaultType: m } = u.parent.contentMatchAt(u.index());
        e.setNodeMarkup(p.start, m);
      }
      (h || h === 0) && e.lift(p, h);
    });
  }), !0;
}, A1 = (t) => (e) => t(e), O1 = () => ({ state: t, dispatch: e }) => Qg(t, e), R1 = (t, e) => ({ editor: n, tr: r }) => {
  const { state: i } = n, s = i.doc.slice(t.from, t.to);
  r.deleteRange(t.from, t.to);
  const o = r.mapping.map(e);
  return r.insert(o, s.content), r.setSelection(new G(r.doc.resolve(o - 1))), !0;
}, L1 = () => ({ tr: t, dispatch: e }) => {
  const { selection: n } = t, r = n.$anchor.node();
  if (r.content.size > 0)
    return !1;
  const i = t.selection.$anchor;
  for (let s = i.depth; s > 0; s -= 1)
    if (i.node(s).type === r.type) {
      if (e) {
        const a = i.before(s), l = i.after(s);
        t.delete(a, l).scrollIntoView();
      }
      return !0;
    }
  return !1;
}, I1 = (t) => ({ tr: e, state: n, dispatch: r }) => {
  const i = Be(t, n.schema), s = e.selection.$anchor;
  for (let o = s.depth; o > 0; o -= 1)
    if (s.node(o).type === i) {
      if (r) {
        const l = s.before(o), c = s.after(o);
        e.delete(l, c).scrollIntoView();
      }
      return !0;
    }
  return !1;
}, D1 = (t) => ({ tr: e, dispatch: n }) => {
  const { from: r, to: i } = t;
  return n && e.delete(r, i), !0;
}, H1 = () => ({ state: t, dispatch: e }) => zg(t, e), B1 = () => ({ commands: t }) => t.keyboardShortcut("Enter"), P1 = () => ({ state: t, dispatch: e }) => Xg(t, e);
function xr(t, e, n = { strict: !0 }) {
  const r = Object.keys(e);
  return r.length ? r.every((i) => n.strict ? e[i] === t[i] : za(e[i]) ? e[i].test(t[i]) : e[i] === t[i]) : !0;
}
function sa(t, e, n = {}) {
  return t.find((r) => r.type === e && xr(r.attrs, n));
}
function $1(t, e, n = {}) {
  return !!sa(t, e, n);
}
function Fa(t, e, n = {}) {
  if (!t || !e)
    return;
  let r = t.parent.childAfter(t.parentOffset);
  if (t.parentOffset === r.offset && r.offset !== 0 && (r = t.parent.childBefore(t.parentOffset)), !r.node)
    return;
  const i = sa([...r.node.marks], e, n);
  if (!i)
    return;
  let s = r.index, o = t.start() + r.offset, a = s + 1, l = o + r.node.nodeSize;
  for (sa([...r.node.marks], e, n); s > 0 && i.isInSet(t.parent.child(s - 1).marks); )
    s -= 1, o -= t.parent.child(s).nodeSize;
  for (; a < t.parent.childCount && $1([...t.parent.child(a).marks], e, n); )
    l += t.parent.child(a).nodeSize, a += 1;
  return {
    from: o,
    to: l
  };
}
function Jt(t, e) {
  if (typeof t == "string") {
    if (!e.marks[t])
      throw Error(`There is no mark type named '${t}'. Maybe you forgot to add the extension?`);
    return e.marks[t];
  }
  return t;
}
const V1 = (t, e = {}) => ({ tr: n, state: r, dispatch: i }) => {
  const s = Jt(t, r.schema), { doc: o, selection: a } = n, { $from: l, from: c, to: d } = a;
  if (i) {
    const u = Fa(l, s, e);
    if (u && u.from <= c && u.to >= d) {
      const f = G.create(o, u.from, u.to);
      n.setSelection(f);
    }
  }
  return !0;
}, z1 = (t) => (e) => {
  const n = typeof t == "function" ? t(e) : t;
  for (let r = 0; r < n.length; r += 1)
    if (n[r](e))
      return !0;
  return !1;
};
function Ua(t) {
  return t instanceof G;
}
function Gt(t = 0, e = 0, n = 0) {
  return Math.min(Math.max(t, e), n);
}
function Cf(t, e = null) {
  if (!e)
    return null;
  const n = te.atStart(t), r = te.atEnd(t);
  if (e === "start" || e === !0)
    return n;
  if (e === "end")
    return r;
  const i = n.from, s = r.to;
  return e === "all" ? G.create(t, Gt(0, i, s), Gt(t.content.size, i, s)) : G.create(t, Gt(e, i, s), Gt(e, i, s));
}
function Ka() {
  return [
    "iPad Simulator",
    "iPhone Simulator",
    "iPod Simulator",
    "iPad",
    "iPhone",
    "iPod"
  ].includes(navigator.platform) || navigator.userAgent.includes("Mac") && "ontouchend" in document;
}
const F1 = (t = null, e = {}) => ({ editor: n, view: r, tr: i, dispatch: s }) => {
  e = {
    scrollIntoView: !0,
    ...e
  };
  const o = () => {
    Ka() && r.dom.focus(), requestAnimationFrame(() => {
      n.isDestroyed || (r.focus(), e != null && e.scrollIntoView && n.commands.scrollIntoView());
    });
  };
  if (r.hasFocus() && t === null || t === !1)
    return !0;
  if (s && t === null && !Ua(n.state.selection))
    return o(), !0;
  const a = Cf(i.doc, t) || n.state.selection, l = n.state.selection.eq(a);
  return s && (l || i.setSelection(a), l && i.storedMarks && i.setStoredMarks(i.storedMarks), o()), !0;
}, U1 = (t, e) => (n) => t.every((r, i) => e(r, { ...n, index: i })), K1 = (t, e) => ({ tr: n, commands: r }) => r.insertContentAt({ from: n.selection.from, to: n.selection.to }, t, e);
function _c(t) {
  const e = `<body>${t}</body>`;
  return new window.DOMParser().parseFromString(e, "text/html").body;
}
function us(t, e, n) {
  if (n = {
    slice: !0,
    parseOptions: {},
    ...n
  }, typeof t == "object" && t !== null)
    try {
      return Array.isArray(t) && t.length > 0 ? A.fromArray(t.map((r) => e.nodeFromJSON(r))) : e.nodeFromJSON(t);
    } catch (r) {
      return console.warn("[tiptap warn]: Invalid content.", "Passed value:", t, "Error:", r), us("", e, n);
    }
  if (typeof t == "string") {
    const r = br.fromSchema(e);
    return n.slice ? r.parseSlice(_c(t), n.parseOptions).content : r.parse(_c(t), n.parseOptions);
  }
  return us("", e, n);
}
function W1(t, e, n) {
  const r = t.steps.length - 1;
  if (r < e)
    return;
  const i = t.steps[r];
  if (!(i instanceof ze || i instanceof De))
    return;
  const s = t.mapping.maps[r];
  let o = 0;
  s.forEach((a, l, c, d) => {
    o === 0 && (o = d);
  }), t.setSelection(te.near(t.doc.resolve(o), n));
}
const q1 = (t) => t.toString().startsWith("<"), Z1 = (t, e, n) => ({ tr: r, dispatch: i, editor: s }) => {
  if (i) {
    n = {
      parseOptions: {},
      updateSelection: !0,
      ...n
    };
    const o = us(e, s.schema, {
      parseOptions: {
        preserveWhitespace: "full",
        ...n.parseOptions
      }
    });
    if (o.toString() === "<>")
      return !0;
    let { from: a, to: l } = typeof t == "number" ? { from: t, to: t } : { from: t.from, to: t.to }, c = !0, d = !0;
    if ((q1(o) ? o : [o]).forEach((f) => {
      f.check(), c = c ? f.isText && f.marks.length === 0 : !1, d = d ? f.isBlock : !1;
    }), a === l && d) {
      const { parent: f } = r.doc.resolve(a);
      f.isTextblock && !f.type.spec.code && !f.childCount && (a -= 1, l += 1);
    }
    c ? Array.isArray(e) ? r.insertText(e.map((f) => f.text || "").join(""), a, l) : typeof e == "object" && e && e.text ? r.insertText(e.text, a, l) : r.insertText(e, a, l) : r.replaceWith(a, l, o), n.updateSelection && W1(r, r.steps.length - 1, -1);
  }
  return !0;
}, G1 = () => ({ state: t, dispatch: e }) => Gg(t, e), j1 = () => ({ state: t, dispatch: e }) => jg(t, e), Y1 = () => ({ state: t, dispatch: e }) => Ug(t, e), J1 = () => ({ state: t, dispatch: e }) => qg(t, e), X1 = () => ({ tr: t, state: e, dispatch: n }) => {
  try {
    const r = Ds(e.doc, e.selection.$from.pos, -1);
    return r == null ? !1 : (t.join(r, 2), n && n(t), !0);
  } catch {
    return !1;
  }
}, Q1 = () => ({ state: t, dispatch: e, tr: n }) => {
  try {
    const r = Ds(t.doc, t.selection.$from.pos, 1);
    return r == null ? !1 : (n.join(r, 2), e && e(n), !0);
  } catch {
    return !1;
  }
};
function Wa() {
  return typeof navigator < "u" ? /Mac/.test(navigator.platform) : !1;
}
function eb(t) {
  const e = t.split(/-(?!$)/);
  let n = e[e.length - 1];
  n === "Space" && (n = " ");
  let r, i, s, o;
  for (let a = 0; a < e.length - 1; a += 1) {
    const l = e[a];
    if (/^(cmd|meta|m)$/i.test(l))
      o = !0;
    else if (/^a(lt)?$/i.test(l))
      r = !0;
    else if (/^(c|ctrl|control)$/i.test(l))
      i = !0;
    else if (/^s(hift)?$/i.test(l))
      s = !0;
    else if (/^mod$/i.test(l))
      Ka() || Wa() ? o = !0 : i = !0;
    else
      throw new Error(`Unrecognized modifier name: ${l}`);
  }
  return r && (n = `Alt-${n}`), i && (n = `Ctrl-${n}`), o && (n = `Meta-${n}`), s && (n = `Shift-${n}`), n;
}
const tb = (t) => ({ editor: e, view: n, tr: r, dispatch: i }) => {
  const s = eb(t).split(/-(?!$)/), o = s.find((c) => !["Alt", "Ctrl", "Meta", "Shift"].includes(c)), a = new KeyboardEvent("keydown", {
    key: o === "Space" ? " " : o,
    altKey: s.includes("Alt"),
    ctrlKey: s.includes("Ctrl"),
    metaKey: s.includes("Meta"),
    shiftKey: s.includes("Shift"),
    bubbles: !0,
    cancelable: !0
  }), l = e.captureTransaction(() => {
    n.someProp("handleKeyDown", (c) => c(n, a));
  });
  return l == null || l.steps.forEach((c) => {
    const d = c.map(r.mapping);
    d && i && r.maybeStep(d);
  }), !0;
};
function Fn(t, e, n = {}) {
  const { from: r, to: i, empty: s } = t.selection, o = e ? Be(e, t.schema) : null, a = [];
  t.doc.nodesBetween(r, i, (u, f) => {
    if (u.isText)
      return;
    const p = Math.max(r, f), h = Math.min(i, f + u.nodeSize);
    a.push({
      node: u,
      from: p,
      to: h
    });
  });
  const l = i - r, c = a.filter((u) => o ? o.name === u.node.type.name : !0).filter((u) => xr(u.node.attrs, n, { strict: !1 }));
  return s ? !!c.length : c.reduce((u, f) => u + f.to - f.from, 0) >= l;
}
const nb = (t, e = {}) => ({ state: n, dispatch: r }) => {
  const i = Be(t, n.schema);
  return Fn(n, i, e) ? Yg(n, r) : !1;
}, rb = () => ({ state: t, dispatch: e }) => e1(t, e), ib = (t) => ({ state: e, dispatch: n }) => {
  const r = Be(t, e.schema);
  return l1(r)(e, n);
}, sb = () => ({ state: t, dispatch: e }) => Jg(t, e);
function Ks(t, e) {
  return e.nodes[t] ? "node" : e.marks[t] ? "mark" : null;
}
function Nc(t, e) {
  const n = typeof e == "string" ? [e] : e;
  return Object.keys(t).reduce((r, i) => (n.includes(i) || (r[i] = t[i]), r), {});
}
const ob = (t, e) => ({ tr: n, state: r, dispatch: i }) => {
  let s = null, o = null;
  const a = Ks(typeof t == "string" ? t : t.name, r.schema);
  return a ? (a === "node" && (s = Be(t, r.schema)), a === "mark" && (o = Jt(t, r.schema)), i && n.selection.ranges.forEach((l) => {
    r.doc.nodesBetween(l.$from.pos, l.$to.pos, (c, d) => {
      s && s === c.type && n.setNodeMarkup(d, void 0, Nc(c.attrs, e)), o && c.marks.length && c.marks.forEach((u) => {
        o === u.type && n.addMark(d, d + c.nodeSize, o.create(Nc(u.attrs, e)));
      });
    });
  }), !0) : !1;
}, ab = () => ({ tr: t, dispatch: e }) => (e && t.scrollIntoView(), !0), lb = () => ({ tr: t, commands: e }) => e.setTextSelection({
  from: 0,
  to: t.doc.content.size
}), cb = () => ({ state: t, dispatch: e }) => Kg(t, e), db = () => ({ state: t, dispatch: e }) => Zg(t, e), ub = () => ({ state: t, dispatch: e }) => t1(t, e), fb = () => ({ state: t, dispatch: e }) => i1(t, e), pb = () => ({ state: t, dispatch: e }) => r1(t, e);
function Mf(t, e, n = {}) {
  return us(t, e, { slice: !1, parseOptions: n });
}
const hb = (t, e = !1, n = {}) => ({ tr: r, editor: i, dispatch: s }) => {
  const { doc: o } = r, a = Mf(t, i.schema, n);
  return s && r.replaceWith(0, o.content.size, a).setMeta("preventUpdate", !e), !0;
};
function vi(t, e) {
  const n = Jt(e, t.schema), { from: r, to: i, empty: s } = t.selection, o = [];
  s ? (t.storedMarks && o.push(...t.storedMarks), o.push(...t.selection.$head.marks())) : t.doc.nodesBetween(r, i, (l) => {
    o.push(...l.marks);
  });
  const a = o.find((l) => l.type.name === n.name);
  return a ? { ...a.attrs } : {};
}
function mb(t, e) {
  const n = new Na(t);
  return e.forEach((r) => {
    r.steps.forEach((i) => {
      n.step(i);
    });
  }), n;
}
function gb(t) {
  for (let e = 0; e < t.edgeCount; e += 1) {
    const { type: n } = t.edge(e);
    if (n.isTextblock && !n.hasRequiredAttrs())
      return n;
  }
  return null;
}
function oa(t, e) {
  const n = [];
  return t.descendants((r, i) => {
    e(r) && n.push({
      node: r,
      pos: i
    });
  }), n;
}
function bb(t, e, n) {
  const r = [];
  return t.nodesBetween(e.from, e.to, (i, s) => {
    n(i) && r.push({
      node: i,
      pos: s
    });
  }), r;
}
function kf(t, e) {
  for (let n = t.depth; n > 0; n -= 1) {
    const r = t.node(n);
    if (e(r))
      return {
        pos: n > 0 ? t.before(n) : 0,
        start: t.start(n),
        depth: n,
        node: r
      };
  }
}
function Ws(t) {
  return (e) => kf(e.$from, t);
}
function yb(t, e) {
  const n = Ht.fromSchema(e).serializeFragment(t), i = document.implementation.createHTMLDocument().createElement("div");
  return i.appendChild(n), i.innerHTML;
}
function vb(t, e) {
  const n = {
    from: 0,
    to: t.content.size
  };
  return xf(t, n, e);
}
function wb(t, e) {
  const n = Be(e, t.schema), { from: r, to: i } = t.selection, s = [];
  t.doc.nodesBetween(r, i, (a) => {
    s.push(a);
  });
  const o = s.reverse().find((a) => a.type.name === n.name);
  return o ? { ...o.attrs } : {};
}
function Tf(t, e) {
  const n = Ks(typeof e == "string" ? e : e.name, t.schema);
  return n === "node" ? wb(t, e) : n === "mark" ? vi(t, e) : {};
}
function Eb(t, e = JSON.stringify) {
  const n = {};
  return t.filter((r) => {
    const i = e(r);
    return Object.prototype.hasOwnProperty.call(n, i) ? !1 : n[i] = !0;
  });
}
function xb(t) {
  const e = Eb(t);
  return e.length === 1 ? e : e.filter((n, r) => !e.filter((s, o) => o !== r).some((s) => n.oldRange.from >= s.oldRange.from && n.oldRange.to <= s.oldRange.to && n.newRange.from >= s.newRange.from && n.newRange.to <= s.newRange.to));
}
function Sb(t) {
  const { mapping: e, steps: n } = t, r = [];
  return e.maps.forEach((i, s) => {
    const o = [];
    if (i.ranges.length)
      i.forEach((a, l) => {
        o.push({ from: a, to: l });
      });
    else {
      const { from: a, to: l } = n[s];
      if (a === void 0 || l === void 0)
        return;
      o.push({ from: a, to: l });
    }
    o.forEach(({ from: a, to: l }) => {
      const c = e.slice(s).map(a, -1), d = e.slice(s).map(l), u = e.invert().map(c, -1), f = e.invert().map(d);
      r.push({
        oldRange: {
          from: u,
          to: f
        },
        newRange: {
          from: c,
          to: d
        }
      });
    });
  }), xb(r);
}
function qa(t, e, n) {
  const r = [];
  return t === e ? n.resolve(t).marks().forEach((i) => {
    const s = n.resolve(t - 1), o = Fa(s, i.type);
    o && r.push({
      mark: i,
      ...o
    });
  }) : n.nodesBetween(t, e, (i, s) => {
    r.push(...i.marks.map((o) => ({
      from: s,
      to: s + i.nodeSize,
      mark: o
    })));
  }), r;
}
function Wi(t, e, n) {
  return Object.fromEntries(Object.entries(n).filter(([r]) => {
    const i = t.find((s) => s.type === e && s.name === r);
    return i ? i.attribute.keepOnSplit : !1;
  }));
}
function aa(t, e, n = {}) {
  const { empty: r, ranges: i } = t.selection, s = e ? Jt(e, t.schema) : null;
  if (r)
    return !!(t.storedMarks || t.selection.$from.marks()).filter((u) => s ? s.name === u.type.name : !0).find((u) => xr(u.attrs, n, { strict: !1 }));
  let o = 0;
  const a = [];
  if (i.forEach(({ $from: u, $to: f }) => {
    const p = u.pos, h = f.pos;
    t.doc.nodesBetween(p, h, (m, g) => {
      if (!m.isText && !m.marks.length)
        return;
      const v = Math.max(p, g), y = Math.min(h, g + m.nodeSize), E = y - v;
      o += E, a.push(...m.marks.map((b) => ({
        mark: b,
        from: v,
        to: y
      })));
    });
  }), o === 0)
    return !1;
  const l = a.filter((u) => s ? s.name === u.mark.type.name : !0).filter((u) => xr(u.mark.attrs, n, { strict: !1 })).reduce((u, f) => u + f.to - f.from, 0), c = a.filter((u) => s ? u.mark.type !== s && u.mark.type.excludes(s) : !0).reduce((u, f) => u + f.to - f.from, 0);
  return (l > 0 ? l + c : l) >= o;
}
function Cb(t, e, n = {}) {
  if (!e)
    return Fn(t, null, n) || aa(t, null, n);
  const r = Ks(e, t.schema);
  return r === "node" ? Fn(t, e, n) : r === "mark" ? aa(t, e, n) : !1;
}
function Ac(t, e) {
  const { nodeExtensions: n } = Fs(e), r = n.find((o) => o.name === t);
  if (!r)
    return !1;
  const i = {
    name: r.name,
    options: r.options,
    storage: r.storage
  }, s = ie(z(r, "group", i));
  return typeof s != "string" ? !1 : s.split(" ").includes("list");
}
function Mb(t) {
  var e;
  const n = (e = t.type.createAndFill()) === null || e === void 0 ? void 0 : e.toJSON(), r = t.toJSON();
  return JSON.stringify(n) === JSON.stringify(r);
}
function kb(t) {
  return t instanceof Y;
}
function Za(t, e, n) {
  const i = t.state.doc.content.size, s = Gt(e, 0, i), o = Gt(n, 0, i), a = t.coordsAtPos(s), l = t.coordsAtPos(o, -1), c = Math.min(a.top, l.top), d = Math.max(a.bottom, l.bottom), u = Math.min(a.left, l.left), f = Math.max(a.right, l.right), p = f - u, h = d - c, v = {
    top: c,
    bottom: d,
    left: u,
    right: f,
    width: p,
    height: h,
    x: u,
    y: c
  };
  return {
    ...v,
    toJSON: () => v
  };
}
function Tb(t, e, n) {
  var r;
  const { selection: i } = e;
  let s = null;
  if (Ua(i) && (s = i.$cursor), s) {
    const a = (r = t.storedMarks) !== null && r !== void 0 ? r : s.marks();
    return !!n.isInSet(a) || !a.some((l) => l.type.excludes(n));
  }
  const { ranges: o } = i;
  return o.some(({ $from: a, $to: l }) => {
    let c = a.depth === 0 ? t.doc.inlineContent && t.doc.type.allowsMarkType(n) : !1;
    return t.doc.nodesBetween(a.pos, l.pos, (d, u, f) => {
      if (c)
        return !1;
      if (d.isInline) {
        const p = !f || f.type.allowsMarkType(n), h = !!n.isInSet(d.marks) || !d.marks.some((m) => m.type.excludes(n));
        c = p && h;
      }
      return !c;
    }), c;
  });
}
const _b = (t, e = {}) => ({ tr: n, state: r, dispatch: i }) => {
  const { selection: s } = n, { empty: o, ranges: a } = s, l = Jt(t, r.schema);
  if (i)
    if (o) {
      const c = vi(r, l);
      n.addStoredMark(l.create({
        ...c,
        ...e
      }));
    } else
      a.forEach((c) => {
        const d = c.$from.pos, u = c.$to.pos;
        r.doc.nodesBetween(d, u, (f, p) => {
          const h = Math.max(p, d), m = Math.min(p + f.nodeSize, u);
          f.marks.find((v) => v.type === l) ? f.marks.forEach((v) => {
            l === v.type && n.addMark(h, m, l.create({
              ...v.attrs,
              ...e
            }));
          }) : n.addMark(h, m, l.create(e));
        });
      });
  return Tb(r, n, l);
}, Nb = (t, e) => ({ tr: n }) => (n.setMeta(t, e), !0), Ab = (t, e = {}) => ({ state: n, dispatch: r, chain: i }) => {
  const s = Be(t, n.schema);
  return s.isTextblock ? i().command(({ commands: o }) => Cc(s, e)(n) ? !0 : o.clearNodes()).command(({ state: o }) => Cc(s, e)(o, r)).run() : (console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'), !1);
}, Ob = (t) => ({ tr: e, dispatch: n }) => {
  if (n) {
    const { doc: r } = e, i = Gt(t, 0, r.content.size), s = Y.create(r, i);
    e.setSelection(s);
  }
  return !0;
}, Rb = (t) => ({ tr: e, dispatch: n }) => {
  if (n) {
    const { doc: r } = e, { from: i, to: s } = typeof t == "number" ? { from: t, to: t } : t, o = G.atStart(r).from, a = G.atEnd(r).to, l = Gt(i, o, a), c = Gt(s, o, a), d = G.create(r, l, c);
    e.setSelection(d);
  }
  return !0;
}, Lb = (t) => ({ state: e, dispatch: n }) => {
  const r = Be(t, e.schema);
  return u1(r)(e, n);
};
function Oc(t, e) {
  const n = t.storedMarks || t.selection.$to.parentOffset && t.selection.$from.marks();
  if (n) {
    const r = n.filter((i) => e == null ? void 0 : e.includes(i.type.name));
    t.tr.ensureMarks(r);
  }
}
const Ib = ({ keepMarks: t = !0 } = {}) => ({ tr: e, state: n, dispatch: r, editor: i }) => {
  const { selection: s, doc: o } = e, { $from: a, $to: l } = s, c = i.extensionManager.attributes, d = Wi(c, a.node().type.name, a.node().attrs);
  if (s instanceof Y && s.node.isBlock)
    return !a.parentOffset || !hr(o, a.pos) ? !1 : (r && (t && Oc(n, i.extensionManager.splittableMarks), e.split(a.pos).scrollIntoView()), !0);
  if (!a.parent.isBlock)
    return !1;
  if (r) {
    const u = l.parentOffset === l.parent.content.size;
    s instanceof G && e.deleteSelection();
    const f = a.depth === 0 ? void 0 : gb(a.node(-1).contentMatchAt(a.indexAfter(-1)));
    let p = u && f ? [
      {
        type: f,
        attrs: d
      }
    ] : void 0, h = hr(e.doc, e.mapping.map(a.pos), 1, p);
    if (!p && !h && hr(e.doc, e.mapping.map(a.pos), 1, f ? [{ type: f }] : void 0) && (h = !0, p = f ? [
      {
        type: f,
        attrs: d
      }
    ] : void 0), h && (e.split(e.mapping.map(a.pos), 1, p), f && !u && !a.parentOffset && a.parent.type !== f)) {
      const m = e.mapping.map(a.before()), g = e.doc.resolve(m);
      a.node(-1).canReplaceWith(g.index(), g.index() + 1, f) && e.setNodeMarkup(e.mapping.map(a.before()), f);
    }
    t && Oc(n, i.extensionManager.splittableMarks), e.scrollIntoView();
  }
  return !0;
}, Db = (t) => ({ tr: e, state: n, dispatch: r, editor: i }) => {
  var s;
  const o = Be(t, n.schema), { $from: a, $to: l } = n.selection, c = n.selection.node;
  if (c && c.isBlock || a.depth < 2 || !a.sameParent(l))
    return !1;
  const d = a.node(-1);
  if (d.type !== o)
    return !1;
  const u = i.extensionManager.attributes;
  if (a.parent.content.size === 0 && a.node(-1).childCount === a.indexAfter(-1)) {
    if (a.depth === 2 || a.node(-3).type !== o || a.index(-2) !== a.node(-2).childCount - 1)
      return !1;
    if (r) {
      let g = A.empty;
      const v = a.index(-1) ? 1 : a.index(-2) ? 2 : 3;
      for (let _ = a.depth - v; _ >= a.depth - 3; _ -= 1)
        g = A.from(a.node(_).copy(g));
      const y = a.indexAfter(-1) < a.node(-2).childCount ? 1 : a.indexAfter(-2) < a.node(-3).childCount ? 2 : 3, E = Wi(u, a.node().type.name, a.node().attrs), b = ((s = o.contentMatch.defaultType) === null || s === void 0 ? void 0 : s.createAndFill(E)) || void 0;
      g = g.append(A.from(o.createAndFill(null, b) || void 0));
      const C = a.before(a.depth - (v - 1));
      e.replace(C, a.after(-y), new B(g, 4 - v, 0));
      let w = -1;
      e.doc.nodesBetween(C, e.doc.content.size, (_, R) => {
        if (w > -1)
          return !1;
        _.isTextblock && _.content.size === 0 && (w = R + 1);
      }), w > -1 && e.setSelection(G.near(e.doc.resolve(w))), e.scrollIntoView();
    }
    return !0;
  }
  const f = l.pos === a.end() ? d.contentMatchAt(0).defaultType : null, p = Wi(u, d.type.name, d.attrs), h = Wi(u, a.node().type.name, a.node().attrs);
  e.delete(a.pos, l.pos);
  const m = f ? [
    { type: o, attrs: p },
    { type: f, attrs: h }
  ] : [{ type: o, attrs: p }];
  if (!hr(e.doc, a.pos, 2))
    return !1;
  if (r) {
    const { selection: g, storedMarks: v } = n, { splittableMarks: y } = i.extensionManager, E = v || g.$to.parentOffset && g.$from.marks();
    if (e.split(a.pos, 2, m).scrollIntoView(), !E || !r)
      return !0;
    const b = E.filter((C) => y.includes(C.type.name));
    e.ensureMarks(b);
  }
  return !0;
}, xo = (t, e) => {
  const n = Ws((o) => o.type === e)(t.selection);
  if (!n)
    return !0;
  const r = t.doc.resolve(Math.max(0, n.pos - 1)).before(n.depth);
  if (r === void 0)
    return !0;
  const i = t.doc.nodeAt(r);
  return n.node.type === (i == null ? void 0 : i.type) && vn(t.doc, n.pos) && t.join(n.pos), !0;
}, So = (t, e) => {
  const n = Ws((o) => o.type === e)(t.selection);
  if (!n)
    return !0;
  const r = t.doc.resolve(n.start).after(n.depth);
  if (r === void 0)
    return !0;
  const i = t.doc.nodeAt(r);
  return n.node.type === (i == null ? void 0 : i.type) && vn(t.doc, r) && t.join(r), !0;
}, Hb = (t, e, n, r = {}) => ({ editor: i, tr: s, state: o, dispatch: a, chain: l, commands: c, can: d }) => {
  const { extensions: u, splittableMarks: f } = i.extensionManager, p = Be(t, o.schema), h = Be(e, o.schema), { selection: m, storedMarks: g } = o, { $from: v, $to: y } = m, E = v.blockRange(y), b = g || m.$to.parentOffset && m.$from.marks();
  if (!E)
    return !1;
  const C = Ws((w) => Ac(w.type.name, u))(m);
  if (E.depth >= 1 && C && E.depth - C.depth <= 1) {
    if (C.node.type === p)
      return c.liftListItem(h);
    if (Ac(C.node.type.name, u) && p.validContent(C.node.content) && a)
      return l().command(() => (s.setNodeMarkup(C.pos, p), !0)).command(() => xo(s, p)).command(() => So(s, p)).run();
  }
  return !n || !b || !a ? l().command(() => d().wrapInList(p, r) ? !0 : c.clearNodes()).wrapInList(p, r).command(() => xo(s, p)).command(() => So(s, p)).run() : l().command(() => {
    const w = d().wrapInList(p, r), _ = b.filter((R) => f.includes(R.type.name));
    return s.ensureMarks(_), w ? !0 : c.clearNodes();
  }).wrapInList(p, r).command(() => xo(s, p)).command(() => So(s, p)).run();
}, Bb = (t, e = {}, n = {}) => ({ state: r, commands: i }) => {
  const { extendEmptyMarkRange: s = !1 } = n, o = Jt(t, r.schema);
  return aa(r, o, e) ? i.unsetMark(o, { extendEmptyMarkRange: s }) : i.setMark(o, e);
}, Pb = (t, e, n = {}) => ({ state: r, commands: i }) => {
  const s = Be(t, r.schema), o = Be(e, r.schema);
  return Fn(r, s, n) ? i.setNode(o) : i.setNode(s, n);
}, $b = (t, e = {}) => ({ state: n, commands: r }) => {
  const i = Be(t, n.schema);
  return Fn(n, i, e) ? r.lift(i) : r.wrapIn(i, e);
}, Vb = () => ({ state: t, dispatch: e }) => {
  const n = t.plugins;
  for (let r = 0; r < n.length; r += 1) {
    const i = n[r];
    let s;
    if (i.spec.isInputRules && (s = i.getState(t))) {
      if (e) {
        const o = t.tr, a = s.transform;
        for (let l = a.steps.length - 1; l >= 0; l -= 1)
          o.step(a.steps[l].invert(a.docs[l]));
        if (s.text) {
          const l = o.doc.resolve(s.from).marks();
          o.replaceWith(s.from, s.to, t.schema.text(s.text, l));
        } else
          o.delete(s.from, s.to);
      }
      return !0;
    }
  }
  return !1;
}, zb = () => ({ tr: t, dispatch: e }) => {
  const { selection: n } = t, { empty: r, ranges: i } = n;
  return r || e && i.forEach((s) => {
    t.removeMark(s.$from.pos, s.$to.pos);
  }), !0;
}, Fb = (t, e = {}) => ({ tr: n, state: r, dispatch: i }) => {
  var s;
  const { extendEmptyMarkRange: o = !1 } = e, { selection: a } = n, l = Jt(t, r.schema), { $from: c, empty: d, ranges: u } = a;
  if (!i)
    return !0;
  if (d && o) {
    let { from: f, to: p } = a;
    const h = (s = c.marks().find((g) => g.type === l)) === null || s === void 0 ? void 0 : s.attrs, m = Fa(c, l, h);
    m && (f = m.from, p = m.to), n.removeMark(f, p, l);
  } else
    u.forEach((f) => {
      n.removeMark(f.$from.pos, f.$to.pos, l);
    });
  return n.removeStoredMark(l), !0;
}, Ub = (t, e = {}) => ({ tr: n, state: r, dispatch: i }) => {
  let s = null, o = null;
  const a = Ks(typeof t == "string" ? t : t.name, r.schema);
  return a ? (a === "node" && (s = Be(t, r.schema)), a === "mark" && (o = Jt(t, r.schema)), i && n.selection.ranges.forEach((l) => {
    const c = l.$from.pos, d = l.$to.pos;
    r.doc.nodesBetween(c, d, (u, f) => {
      s && s === u.type && n.setNodeMarkup(f, void 0, {
        ...u.attrs,
        ...e
      }), o && u.marks.length && u.marks.forEach((p) => {
        if (o === p.type) {
          const h = Math.max(f, c), m = Math.min(f + u.nodeSize, d);
          n.addMark(h, m, o.create({
            ...p.attrs,
            ...e
          }));
        }
      });
    });
  }), !0) : !1;
}, Kb = (t, e = {}) => ({ state: n, dispatch: r }) => {
  const i = Be(t, n.schema);
  return s1(i, e)(n, r);
}, Wb = (t, e = {}) => ({ state: n, dispatch: r }) => {
  const i = Be(t, n.schema);
  return o1(i, e)(n, r);
};
var qb = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  blur: T1,
  clearContent: _1,
  clearNodes: N1,
  command: A1,
  createParagraphNear: O1,
  cut: R1,
  deleteCurrentNode: L1,
  deleteNode: I1,
  deleteRange: D1,
  deleteSelection: H1,
  enter: B1,
  exitCode: P1,
  extendMarkRange: V1,
  first: z1,
  focus: F1,
  forEach: U1,
  insertContent: K1,
  insertContentAt: Z1,
  joinUp: G1,
  joinDown: j1,
  joinBackward: Y1,
  joinForward: J1,
  joinItemBackward: X1,
  joinItemForward: Q1,
  keyboardShortcut: tb,
  lift: nb,
  liftEmptyBlock: rb,
  liftListItem: ib,
  newlineInCode: sb,
  resetAttributes: ob,
  scrollIntoView: ab,
  selectAll: lb,
  selectNodeBackward: cb,
  selectNodeForward: db,
  selectParentNode: ub,
  selectTextblockEnd: fb,
  selectTextblockStart: pb,
  setContent: hb,
  setMark: _b,
  setMeta: Nb,
  setNode: Ab,
  setNodeSelection: Ob,
  setTextSelection: Rb,
  sinkListItem: Lb,
  splitBlock: Ib,
  splitListItem: Db,
  toggleList: Hb,
  toggleMark: Bb,
  toggleNode: Pb,
  toggleWrap: $b,
  undoInputRule: Vb,
  unsetAllMarks: zb,
  unsetMark: Fb,
  updateAttributes: Ub,
  wrapIn: Kb,
  wrapInList: Wb
});
const Zb = Ce.create({
  name: "commands",
  addCommands() {
    return {
      ...qb
    };
  }
}), Gb = Ce.create({
  name: "editable",
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("editable"),
        props: {
          editable: () => this.editor.options.editable
        }
      })
    ];
  }
}), jb = Ce.create({
  name: "focusEvents",
  addProseMirrorPlugins() {
    const { editor: t } = this;
    return [
      new Se({
        key: new Me("focusEvents"),
        props: {
          handleDOMEvents: {
            focus: (e, n) => {
              t.isFocused = !0;
              const r = t.state.tr.setMeta("focus", { event: n }).setMeta("addToHistory", !1);
              return e.dispatch(r), !1;
            },
            blur: (e, n) => {
              t.isFocused = !1;
              const r = t.state.tr.setMeta("blur", { event: n }).setMeta("addToHistory", !1);
              return e.dispatch(r), !1;
            }
          }
        }
      })
    ];
  }
}), Yb = Ce.create({
  name: "keymap",
  addKeyboardShortcuts() {
    const t = () => this.editor.commands.first(({ commands: o }) => [
      () => o.undoInputRule(),
      // maybe convert first text block node to default node
      () => o.command(({ tr: a }) => {
        const { selection: l, doc: c } = a, { empty: d, $anchor: u } = l, { pos: f, parent: p } = u, h = u.parent.isTextblock ? a.doc.resolve(f - 1) : u, m = h.parent.type.spec.isolating, g = u.pos - u.parentOffset, v = m && h.parent.childCount === 1 ? g === u.pos : te.atStart(c).from === f;
        return !d || !v || !p.type.isTextblock || p.textContent.length ? !1 : o.clearNodes();
      }),
      () => o.deleteSelection(),
      () => o.joinBackward(),
      () => o.selectNodeBackward()
    ]), e = () => this.editor.commands.first(({ commands: o }) => [
      () => o.deleteSelection(),
      () => o.deleteCurrentNode(),
      () => o.joinForward(),
      () => o.selectNodeForward()
    ]), r = {
      Enter: () => this.editor.commands.first(({ commands: o }) => [
        () => o.newlineInCode(),
        () => o.createParagraphNear(),
        () => o.liftEmptyBlock(),
        () => o.splitBlock()
      ]),
      "Mod-Enter": () => this.editor.commands.exitCode(),
      Backspace: t,
      "Mod-Backspace": t,
      "Shift-Backspace": t,
      Delete: e,
      "Mod-Delete": e,
      "Mod-a": () => this.editor.commands.selectAll()
    }, i = {
      ...r
    }, s = {
      ...r,
      "Ctrl-h": t,
      "Alt-Backspace": t,
      "Ctrl-d": e,
      "Ctrl-Alt-Backspace": e,
      "Alt-Delete": e,
      "Alt-d": e,
      "Ctrl-a": () => this.editor.commands.selectTextblockStart(),
      "Ctrl-e": () => this.editor.commands.selectTextblockEnd()
    };
    return Ka() || Wa() ? s : i;
  },
  addProseMirrorPlugins() {
    return [
      // With this plugin we check if the whole document was selected and deleted.
      // In this case we will additionally call `clearNodes()` to convert e.g. a heading
      // to a paragraph if necessary.
      // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
      // with many other commands.
      new Se({
        key: new Me("clearDocument"),
        appendTransaction: (t, e, n) => {
          if (!(t.some((h) => h.docChanged) && !e.doc.eq(n.doc)))
            return;
          const { empty: i, from: s, to: o } = e.selection, a = te.atStart(e.doc).from, l = te.atEnd(e.doc).to;
          if (i || !(s === a && o === l) || !(n.doc.textBetween(0, n.doc.content.size, " ", " ").length === 0))
            return;
          const u = n.tr, f = Vs({
            state: n,
            transaction: u
          }), { commands: p } = new zs({
            editor: this.editor,
            state: f
          });
          if (p.clearNodes(), !!u.steps.length)
            return u;
        }
      })
    ];
  }
}), Jb = Ce.create({
  name: "tabindex",
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("tabindex"),
        props: {
          attributes: this.editor.isEditable ? { tabindex: "0" } : {}
        }
      })
    ];
  }
});
var Xb = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  ClipboardTextSerializer: k1,
  Commands: Zb,
  Editable: Gb,
  FocusEvents: jb,
  Keymap: Yb,
  Tabindex: Jb
});
const Qb = `.ProseMirror {
  position: relative;
}

.ProseMirror {
  word-wrap: break-word;
  white-space: pre-wrap;
  white-space: break-spaces;
  -webkit-font-variant-ligatures: none;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
}

.ProseMirror [contenteditable="false"] {
  white-space: normal;
}

.ProseMirror [contenteditable="false"] [contenteditable="true"] {
  white-space: pre-wrap;
}

.ProseMirror pre {
  white-space: pre-wrap;
}

img.ProseMirror-separator {
  display: inline !important;
  border: none !important;
  margin: 0 !important;
  width: 1px !important;
  height: 1px !important;
}

.ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
  margin: 0;
}

.ProseMirror-gapcursor:after {
  content: "";
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 1px solid black;
  animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}

@keyframes ProseMirror-cursor-blink {
  to {
    visibility: hidden;
  }
}

.ProseMirror-hideselection *::selection {
  background: transparent;
}

.ProseMirror-hideselection *::-moz-selection {
  background: transparent;
}

.ProseMirror-hideselection * {
  caret-color: transparent;
}

.ProseMirror-focused .ProseMirror-gapcursor {
  display: block;
}

.tippy-box[data-animation=fade][data-state=hidden] {
  opacity: 0
}`;
function e0(t, e, n) {
  const r = document.querySelector(`style[data-tiptap-style${n ? `-${n}` : ""}]`);
  if (r !== null)
    return r;
  const i = document.createElement("style");
  return e && i.setAttribute("nonce", e), i.setAttribute(`data-tiptap-style${n ? `-${n}` : ""}`, ""), i.innerHTML = t, document.getElementsByTagName("head")[0].appendChild(i), i;
}
class t0 extends f1 {
  constructor(e = {}) {
    super(), this.isFocused = !1, this.extensionStorage = {}, this.options = {
      element: document.createElement("div"),
      content: "",
      injectCSS: !0,
      injectNonce: void 0,
      extensions: [],
      autofocus: !1,
      editable: !0,
      editorProps: {},
      parseOptions: {},
      enableInputRules: !0,
      enablePasteRules: !0,
      enableCoreExtensions: !0,
      onBeforeCreate: () => null,
      onCreate: () => null,
      onUpdate: () => null,
      onSelectionUpdate: () => null,
      onTransaction: () => null,
      onFocus: () => null,
      onBlur: () => null,
      onDestroy: () => null
    }, this.isCapturingTransaction = !1, this.capturedTransaction = null, this.setOptions(e), this.createExtensionManager(), this.createCommandManager(), this.createSchema(), this.on("beforeCreate", this.options.onBeforeCreate), this.emit("beforeCreate", { editor: this }), this.createView(), this.injectCSS(), this.on("create", this.options.onCreate), this.on("update", this.options.onUpdate), this.on("selectionUpdate", this.options.onSelectionUpdate), this.on("transaction", this.options.onTransaction), this.on("focus", this.options.onFocus), this.on("blur", this.options.onBlur), this.on("destroy", this.options.onDestroy), window.setTimeout(() => {
      this.isDestroyed || (this.commands.focus(this.options.autofocus), this.emit("create", { editor: this }));
    }, 0);
  }
  /**
   * Returns the editor storage.
   */
  get storage() {
    return this.extensionStorage;
  }
  /**
   * An object of all registered commands.
   */
  get commands() {
    return this.commandManager.commands;
  }
  /**
   * Create a command chain to call multiple commands at once.
   */
  chain() {
    return this.commandManager.chain();
  }
  /**
   * Check if a command or a command chain can be executed. Without executing it.
   */
  can() {
    return this.commandManager.can();
  }
  /**
   * Inject CSS styles.
   */
  injectCSS() {
    this.options.injectCSS && document && (this.css = e0(Qb, this.options.injectNonce));
  }
  /**
   * Update editor options.
   *
   * @param options A list of options
   */
  setOptions(e = {}) {
    this.options = {
      ...this.options,
      ...e
    }, !(!this.view || !this.state || this.isDestroyed) && (this.options.editorProps && this.view.setProps(this.options.editorProps), this.view.updateState(this.state));
  }
  /**
   * Update editable state of the editor.
   */
  setEditable(e, n = !0) {
    this.setOptions({ editable: e }), n && this.emit("update", { editor: this, transaction: this.state.tr });
  }
  /**
   * Returns whether the editor is editable.
   */
  get isEditable() {
    return this.options.editable && this.view && this.view.editable;
  }
  /**
   * Returns the editor state.
   */
  get state() {
    return this.view.state;
  }
  /**
   * Register a ProseMirror plugin.
   *
   * @param plugin A ProseMirror plugin
   * @param handlePlugins Control how to merge the plugin into the existing plugins.
   */
  registerPlugin(e, n) {
    const r = Ef(n) ? n(e, [...this.state.plugins]) : [...this.state.plugins, e], i = this.state.reconfigure({ plugins: r });
    this.view.updateState(i);
  }
  /**
   * Unregister a ProseMirror plugin.
   *
   * @param nameOrPluginKey The plugins name
   */
  unregisterPlugin(e) {
    if (this.isDestroyed)
      return;
    const n = typeof e == "string" ? `${e}$` : e.key, r = this.state.reconfigure({
      // @ts-ignore
      plugins: this.state.plugins.filter((i) => !i.key.startsWith(n))
    });
    this.view.updateState(r);
  }
  /**
   * Creates an extension manager.
   */
  createExtensionManager() {
    const n = [...this.options.enableCoreExtensions ? Object.values(Xb) : [], ...this.options.extensions].filter((r) => ["extension", "node", "mark"].includes(r == null ? void 0 : r.type));
    this.extensionManager = new cr(n, this);
  }
  /**
   * Creates an command manager.
   */
  createCommandManager() {
    this.commandManager = new zs({
      editor: this
    });
  }
  /**
   * Creates a ProseMirror schema.
   */
  createSchema() {
    this.schema = this.extensionManager.schema;
  }
  /**
   * Creates a ProseMirror view.
   */
  createView() {
    const e = Mf(this.options.content, this.schema, this.options.parseOptions), n = Cf(e, this.options.autofocus);
    this.view = new Og(this.options.element, {
      ...this.options.editorProps,
      dispatchTransaction: this.dispatchTransaction.bind(this),
      state: lr.create({
        doc: e,
        selection: n || void 0
      })
    });
    const r = this.state.reconfigure({
      plugins: this.extensionManager.plugins
    });
    this.view.updateState(r), this.createNodeViews(), this.prependClass();
    const i = this.view.dom;
    i.editor = this;
  }
  /**
   * Creates all node views.
   */
  createNodeViews() {
    this.view.setProps({
      nodeViews: this.extensionManager.nodeViews
    });
  }
  /**
   * Prepend class name to element.
   */
  prependClass() {
    this.view.dom.className = `tiptap ${this.view.dom.className}`;
  }
  captureTransaction(e) {
    this.isCapturingTransaction = !0, e(), this.isCapturingTransaction = !1;
    const n = this.capturedTransaction;
    return this.capturedTransaction = null, n;
  }
  /**
   * The callback over which to send transactions (state updates) produced by the view.
   *
   * @param transaction An editor state transaction
   */
  dispatchTransaction(e) {
    if (this.view.isDestroyed)
      return;
    if (this.isCapturingTransaction) {
      if (!this.capturedTransaction) {
        this.capturedTransaction = e;
        return;
      }
      e.steps.forEach((o) => {
        var a;
        return (a = this.capturedTransaction) === null || a === void 0 ? void 0 : a.step(o);
      });
      return;
    }
    const n = this.state.apply(e), r = !this.state.selection.eq(n.selection);
    this.view.updateState(n), this.emit("transaction", {
      editor: this,
      transaction: e
    }), r && this.emit("selectionUpdate", {
      editor: this,
      transaction: e
    });
    const i = e.getMeta("focus"), s = e.getMeta("blur");
    i && this.emit("focus", {
      editor: this,
      event: i.event,
      transaction: e
    }), s && this.emit("blur", {
      editor: this,
      event: s.event,
      transaction: e
    }), !(!e.docChanged || e.getMeta("preventUpdate")) && this.emit("update", {
      editor: this,
      transaction: e
    });
  }
  /**
   * Get attributes of the currently selected node or mark.
   */
  getAttributes(e) {
    return Tf(this.state, e);
  }
  isActive(e, n) {
    const r = typeof e == "string" ? e : null, i = typeof e == "string" ? n : e;
    return Cb(this.state, r, i);
  }
  /**
   * Get the document as JSON.
   */
  getJSON() {
    return this.state.doc.toJSON();
  }
  /**
   * Get the document as HTML.
   */
  getHTML() {
    return yb(this.state.doc.content, this.schema);
  }
  /**
   * Get the document as text.
   */
  getText(e) {
    const { blockSeparator: n = `

`, textSerializers: r = {} } = e || {};
    return vb(this.state.doc, {
      blockSeparator: n,
      textSerializers: {
        ...Sf(this.schema),
        ...r
      }
    });
  }
  /**
   * Check if there is no content.
   */
  get isEmpty() {
    return Mb(this.state.doc);
  }
  /**
   * Get the number of characters for the current document.
   *
   * @deprecated
   */
  getCharacterCount() {
    return console.warn('[tiptap warn]: "editor.getCharacterCount()" is deprecated. Please use "editor.storage.characterCount.characters()" instead.'), this.state.doc.content.size - 2;
  }
  /**
   * Destroy the editor.
   */
  destroy() {
    this.emit("destroy"), this.view && this.view.destroy(), this.removeAllListeners();
  }
  /**
   * Check if the editor is already destroyed.
   */
  get isDestroyed() {
    var e;
    return !(!((e = this.view) === null || e === void 0) && e.docView);
  }
}
function Un(t) {
  return new yi({
    find: t.find,
    handler: ({ state: e, range: n, match: r }) => {
      const i = ie(t.getAttributes, void 0, r);
      if (i === !1 || i === null)
        return null;
      const { tr: s } = e, o = r[r.length - 1], a = r[0];
      if (o) {
        const l = a.search(/\S/), c = n.from + a.indexOf(o), d = c + o.length;
        if (qa(n.from, n.to, e.doc).filter((p) => p.mark.type.excluded.find((m) => m === t.type && m !== p.mark.type)).filter((p) => p.to > c).length)
          return null;
        d < n.to && s.delete(d, n.to), c > n.from && s.delete(n.from + l, c);
        const f = n.from + l + o.length;
        s.addMark(n.from + l, f, t.type.create(i || {})), s.removeStoredMark(t.type);
      }
    }
  });
}
function Ga(t) {
  return new yi({
    find: t.find,
    handler: ({ state: e, range: n, match: r }) => {
      const i = ie(t.getAttributes, void 0, r) || {}, { tr: s } = e, o = n.from;
      let a = n.to;
      const l = t.type.create(i);
      if (r[1]) {
        const c = r[0].lastIndexOf(r[1]);
        let d = o + c;
        d > a ? d = a : a = d + r[1].length;
        const u = r[0][r[0].length - 1];
        s.insertText(u, o + r[0].length - 1), s.replaceWith(d, a, l);
      } else
        r[0] && s.insert(o - 1, t.type.create(i)).delete(s.mapping.map(o), s.mapping.map(a));
      s.scrollIntoView();
    }
  });
}
function la(t) {
  return new yi({
    find: t.find,
    handler: ({ state: e, range: n, match: r }) => {
      const i = e.doc.resolve(n.from), s = ie(t.getAttributes, void 0, r) || {};
      if (!i.node(-1).canReplaceWith(i.index(-1), i.indexAfter(-1), t.type))
        return null;
      e.tr.delete(n.from, n.to).setBlockType(n.from, n.from, t.type, s);
    }
  });
}
function Sr(t) {
  return new yi({
    find: t.find,
    handler: ({ state: e, range: n, match: r, chain: i }) => {
      const s = ie(t.getAttributes, void 0, r) || {}, o = e.tr.delete(n.from, n.to), l = o.doc.resolve(n.from).blockRange(), c = l && Ta(l, t.type, s);
      if (!c)
        return null;
      if (o.wrap(l, c), t.keepMarks && t.editor) {
        const { selection: u, storedMarks: f } = e, { splittableMarks: p } = t.editor.extensionManager, h = f || u.$to.parentOffset && u.$from.marks();
        if (h) {
          const m = h.filter((g) => p.includes(g.type.name));
          o.ensureMarks(m);
        }
      }
      if (t.keepAttributes) {
        const u = t.type.name === "bulletList" || t.type.name === "orderedList" ? "listItem" : "taskList";
        i().updateAttributes(u, s).run();
      }
      const d = o.doc.resolve(n.from - 1).nodeBefore;
      d && d.type === t.type && vn(o.doc, n.from - 1) && (!t.joinPredicate || t.joinPredicate(r, d)) && o.join(n.from - 1);
    }
  });
}
class qe {
  constructor(e = {}) {
    this.type = "mark", this.name = "mark", this.parent = null, this.child = null, this.config = {
      name: this.name,
      defaultOptions: {}
    }, this.config = {
      ...this.config,
      ...e
    }, this.name = this.config.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = ie(z(this, "addOptions", {
      name: this.name
    }))), this.storage = ie(z(this, "addStorage", {
      name: this.name,
      options: this.options
    })) || {};
  }
  static create(e = {}) {
    return new qe(e);
  }
  configure(e = {}) {
    const n = this.extend();
    return n.options = Us(this.options, e), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
  extend(e = {}) {
    const n = new qe(e);
    return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = ie(z(n, "addOptions", {
      name: n.name
    })), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
  static handleExit({ editor: e, mark: n }) {
    const { tr: r } = e.state, i = e.state.selection.$from;
    if (i.pos === i.end()) {
      const o = i.marks();
      if (!!!o.find((c) => (c == null ? void 0 : c.type.name) === n.name))
        return !1;
      const l = o.find((c) => (c == null ? void 0 : c.type.name) === n.name);
      return l && r.removeStoredMark(l), r.insertText(" ", i.pos), e.view.dispatch(r), !0;
    }
    return !1;
  }
}
class xe {
  constructor(e = {}) {
    this.type = "node", this.name = "node", this.parent = null, this.child = null, this.config = {
      name: this.name,
      defaultOptions: {}
    }, this.config = {
      ...this.config,
      ...e
    }, this.name = this.config.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`), this.options = this.config.defaultOptions, this.config.addOptions && (this.options = ie(z(this, "addOptions", {
      name: this.name
    }))), this.storage = ie(z(this, "addStorage", {
      name: this.name,
      options: this.options
    })) || {};
  }
  static create(e = {}) {
    return new xe(e);
  }
  configure(e = {}) {
    const n = this.extend();
    return n.options = Us(this.options, e), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
  extend(e = {}) {
    const n = new xe(e);
    return n.parent = this, this.child = n, n.name = e.name ? e.name : n.parent.name, e.defaultOptions && console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${n.name}".`), n.options = ie(z(n, "addOptions", {
      name: n.name
    })), n.storage = ie(z(n, "addStorage", {
      name: n.name,
      options: n.options
    })), n;
  }
}
function yn(t) {
  return new w1({
    find: t.find,
    handler: ({ state: e, range: n, match: r, pasteEvent: i }) => {
      const s = ie(t.getAttributes, void 0, r, i);
      if (s === !1 || s === null)
        return null;
      const { tr: o } = e, a = r[r.length - 1], l = r[0];
      let c = n.to;
      if (a) {
        const d = l.search(/\S/), u = n.from + l.indexOf(a), f = u + a.length;
        if (qa(n.from, n.to, e.doc).filter((h) => h.mark.type.excluded.find((g) => g === t.type && g !== h.mark.type)).filter((h) => h.to > u).length)
          return null;
        f < n.to && o.delete(f, n.to), u > n.from && o.delete(n.from + d, u), c = n.from + d + a.length, o.addMark(n.from + d, c, t.type.create(s || {})), o.removeStoredMark(t.type);
      }
    }
  });
}
function n0(t) {
  return t.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
}
class me extends HTMLElement {
  constructor() {
    super();
    q(this, "template", "");
    q(this, "editor");
    q(this, "options");
  }
  registerClickListener() {
    this.addEventListener("click", () => {
      var r;
      const n = (r = this.editor) == null ? void 0 : r.chain();
      this.onClick(n), n == null || n.run();
    });
  }
  connectedCallback() {
    this.innerHTML = this.template;
  }
  // @ts-ignore
  onClick(n) {
  }
  onCreate(n, r) {
    this.editor = n.editor, this.options = r;
  }
  onTransaction(n) {
    const r = this.querySelector("div");
    r && (this.onActive(n.editor) ? r.classList.add("active") : r.classList.remove("active"));
  }
  // @ts-ignore
  onActive(n) {
    return !1;
  }
}
class r0 extends me {
  constructor() {
    super();
    const e = `
        <div style="height: 16px">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5.82843 6.99955L8.36396 9.53509L6.94975 10.9493L2 5.99955L6.94975 1.0498L8.36396 2.46402L5.82843 4.99955H13C17.4183 4.99955 21 8.58127 21 12.9996C21 17.4178 17.4183 20.9996 13 20.9996H4V18.9996H13C16.3137 18.9996 19 16.3133 19 12.9996C19 9.68584 16.3137 6.99955 13 6.99955H5.82843Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.undo();
  }
}
class i0 extends me {
  constructor() {
    super();
    const e = `
         <div style="height: 16px">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18.1716 6.99955H11C7.68629 6.99955 5 9.68584 5 12.9996C5 16.3133 7.68629 18.9996 11 18.9996H20V20.9996H11C6.58172 20.9996 3 17.4178 3 12.9996C3 8.58127 6.58172 4.99955 11 4.99955H18.1716L15.636 2.46402L17.0503 1.0498L22 5.99955L17.0503 10.9493L15.636 9.53509L18.1716 6.99955Z"></path></svg>
         </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.redo();
  }
}
var ot = "top", St = "bottom", Ct = "right", at = "left", ja = "auto", wi = [ot, St, Ct, at], Cr = "start", ii = "end", s0 = "clippingParents", _f = "viewport", Ir = "popper", o0 = "reference", Rc = /* @__PURE__ */ wi.reduce(function(t, e) {
  return t.concat([e + "-" + Cr, e + "-" + ii]);
}, []), Nf = /* @__PURE__ */ [].concat(wi, [ja]).reduce(function(t, e) {
  return t.concat([e, e + "-" + Cr, e + "-" + ii]);
}, []), a0 = "beforeRead", l0 = "read", c0 = "afterRead", d0 = "beforeMain", u0 = "main", f0 = "afterMain", p0 = "beforeWrite", h0 = "write", m0 = "afterWrite", g0 = [a0, l0, c0, d0, u0, f0, p0, h0, m0];
function zt(t) {
  return t ? (t.nodeName || "").toLowerCase() : null;
}
function pt(t) {
  if (t == null)
    return window;
  if (t.toString() !== "[object Window]") {
    var e = t.ownerDocument;
    return e && e.defaultView || window;
  }
  return t;
}
function Kn(t) {
  var e = pt(t).Element;
  return t instanceof e || t instanceof Element;
}
function xt(t) {
  var e = pt(t).HTMLElement;
  return t instanceof e || t instanceof HTMLElement;
}
function Ya(t) {
  if (typeof ShadowRoot > "u")
    return !1;
  var e = pt(t).ShadowRoot;
  return t instanceof e || t instanceof ShadowRoot;
}
function b0(t) {
  var e = t.state;
  Object.keys(e.elements).forEach(function(n) {
    var r = e.styles[n] || {}, i = e.attributes[n] || {}, s = e.elements[n];
    !xt(s) || !zt(s) || (Object.assign(s.style, r), Object.keys(i).forEach(function(o) {
      var a = i[o];
      a === !1 ? s.removeAttribute(o) : s.setAttribute(o, a === !0 ? "" : a);
    }));
  });
}
function y0(t) {
  var e = t.state, n = {
    popper: {
      position: e.options.strategy,
      left: "0",
      top: "0",
      margin: "0"
    },
    arrow: {
      position: "absolute"
    },
    reference: {}
  };
  return Object.assign(e.elements.popper.style, n.popper), e.styles = n, e.elements.arrow && Object.assign(e.elements.arrow.style, n.arrow), function() {
    Object.keys(e.elements).forEach(function(r) {
      var i = e.elements[r], s = e.attributes[r] || {}, o = Object.keys(e.styles.hasOwnProperty(r) ? e.styles[r] : n[r]), a = o.reduce(function(l, c) {
        return l[c] = "", l;
      }, {});
      !xt(i) || !zt(i) || (Object.assign(i.style, a), Object.keys(s).forEach(function(l) {
        i.removeAttribute(l);
      }));
    });
  };
}
const Af = {
  name: "applyStyles",
  enabled: !0,
  phase: "write",
  fn: b0,
  effect: y0,
  requires: ["computeStyles"]
};
function Pt(t) {
  return t.split("-")[0];
}
var Hn = Math.max, fs = Math.min, Mr = Math.round;
function ca() {
  var t = navigator.userAgentData;
  return t != null && t.brands && Array.isArray(t.brands) ? t.brands.map(function(e) {
    return e.brand + "/" + e.version;
  }).join(" ") : navigator.userAgent;
}
function Of() {
  return !/^((?!chrome|android).)*safari/i.test(ca());
}
function kr(t, e, n) {
  e === void 0 && (e = !1), n === void 0 && (n = !1);
  var r = t.getBoundingClientRect(), i = 1, s = 1;
  e && xt(t) && (i = t.offsetWidth > 0 && Mr(r.width) / t.offsetWidth || 1, s = t.offsetHeight > 0 && Mr(r.height) / t.offsetHeight || 1);
  var o = Kn(t) ? pt(t) : window, a = o.visualViewport, l = !Of() && n, c = (r.left + (l && a ? a.offsetLeft : 0)) / i, d = (r.top + (l && a ? a.offsetTop : 0)) / s, u = r.width / i, f = r.height / s;
  return {
    width: u,
    height: f,
    top: d,
    right: c + u,
    bottom: d + f,
    left: c,
    x: c,
    y: d
  };
}
function Ja(t) {
  var e = kr(t), n = t.offsetWidth, r = t.offsetHeight;
  return Math.abs(e.width - n) <= 1 && (n = e.width), Math.abs(e.height - r) <= 1 && (r = e.height), {
    x: t.offsetLeft,
    y: t.offsetTop,
    width: n,
    height: r
  };
}
function Rf(t, e) {
  var n = e.getRootNode && e.getRootNode();
  if (t.contains(e))
    return !0;
  if (n && Ya(n)) {
    var r = e;
    do {
      if (r && t.isSameNode(r))
        return !0;
      r = r.parentNode || r.host;
    } while (r);
  }
  return !1;
}
function Yt(t) {
  return pt(t).getComputedStyle(t);
}
function v0(t) {
  return ["table", "td", "th"].indexOf(zt(t)) >= 0;
}
function En(t) {
  return ((Kn(t) ? t.ownerDocument : (
    // $FlowFixMe[prop-missing]
    t.document
  )) || window.document).documentElement;
}
function qs(t) {
  return zt(t) === "html" ? t : (
    // this is a quicker (but less type safe) way to save quite some bytes from the bundle
    // $FlowFixMe[incompatible-return]
    // $FlowFixMe[prop-missing]
    t.assignedSlot || // step into the shadow DOM of the parent of a slotted node
    t.parentNode || // DOM Element detected
    (Ya(t) ? t.host : null) || // ShadowRoot detected
    // $FlowFixMe[incompatible-call]: HTMLElement is a Node
    En(t)
  );
}
function Lc(t) {
  return !xt(t) || // https://github.com/popperjs/popper-core/issues/837
  Yt(t).position === "fixed" ? null : t.offsetParent;
}
function w0(t) {
  var e = /firefox/i.test(ca()), n = /Trident/i.test(ca());
  if (n && xt(t)) {
    var r = Yt(t);
    if (r.position === "fixed")
      return null;
  }
  var i = qs(t);
  for (Ya(i) && (i = i.host); xt(i) && ["html", "body"].indexOf(zt(i)) < 0; ) {
    var s = Yt(i);
    if (s.transform !== "none" || s.perspective !== "none" || s.contain === "paint" || ["transform", "perspective"].indexOf(s.willChange) !== -1 || e && s.willChange === "filter" || e && s.filter && s.filter !== "none")
      return i;
    i = i.parentNode;
  }
  return null;
}
function Ei(t) {
  for (var e = pt(t), n = Lc(t); n && v0(n) && Yt(n).position === "static"; )
    n = Lc(n);
  return n && (zt(n) === "html" || zt(n) === "body" && Yt(n).position === "static") ? e : n || w0(t) || e;
}
function Xa(t) {
  return ["top", "bottom"].indexOf(t) >= 0 ? "x" : "y";
}
function Wr(t, e, n) {
  return Hn(t, fs(e, n));
}
function E0(t, e, n) {
  var r = Wr(t, e, n);
  return r > n ? n : r;
}
function Lf() {
  return {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0
  };
}
function If(t) {
  return Object.assign({}, Lf(), t);
}
function Df(t, e) {
  return e.reduce(function(n, r) {
    return n[r] = t, n;
  }, {});
}
var x0 = function(e, n) {
  return e = typeof e == "function" ? e(Object.assign({}, n.rects, {
    placement: n.placement
  })) : e, If(typeof e != "number" ? e : Df(e, wi));
};
function S0(t) {
  var e, n = t.state, r = t.name, i = t.options, s = n.elements.arrow, o = n.modifiersData.popperOffsets, a = Pt(n.placement), l = Xa(a), c = [at, Ct].indexOf(a) >= 0, d = c ? "height" : "width";
  if (!(!s || !o)) {
    var u = x0(i.padding, n), f = Ja(s), p = l === "y" ? ot : at, h = l === "y" ? St : Ct, m = n.rects.reference[d] + n.rects.reference[l] - o[l] - n.rects.popper[d], g = o[l] - n.rects.reference[l], v = Ei(s), y = v ? l === "y" ? v.clientHeight || 0 : v.clientWidth || 0 : 0, E = m / 2 - g / 2, b = u[p], C = y - f[d] - u[h], w = y / 2 - f[d] / 2 + E, _ = Wr(b, w, C), R = l;
    n.modifiersData[r] = (e = {}, e[R] = _, e.centerOffset = _ - w, e);
  }
}
function C0(t) {
  var e = t.state, n = t.options, r = n.element, i = r === void 0 ? "[data-popper-arrow]" : r;
  i != null && (typeof i == "string" && (i = e.elements.popper.querySelector(i), !i) || Rf(e.elements.popper, i) && (e.elements.arrow = i));
}
const M0 = {
  name: "arrow",
  enabled: !0,
  phase: "main",
  fn: S0,
  effect: C0,
  requires: ["popperOffsets"],
  requiresIfExists: ["preventOverflow"]
};
function Tr(t) {
  return t.split("-")[1];
}
var k0 = {
  top: "auto",
  right: "auto",
  bottom: "auto",
  left: "auto"
};
function T0(t, e) {
  var n = t.x, r = t.y, i = e.devicePixelRatio || 1;
  return {
    x: Mr(n * i) / i || 0,
    y: Mr(r * i) / i || 0
  };
}
function Ic(t) {
  var e, n = t.popper, r = t.popperRect, i = t.placement, s = t.variation, o = t.offsets, a = t.position, l = t.gpuAcceleration, c = t.adaptive, d = t.roundOffsets, u = t.isFixed, f = o.x, p = f === void 0 ? 0 : f, h = o.y, m = h === void 0 ? 0 : h, g = typeof d == "function" ? d({
    x: p,
    y: m
  }) : {
    x: p,
    y: m
  };
  p = g.x, m = g.y;
  var v = o.hasOwnProperty("x"), y = o.hasOwnProperty("y"), E = at, b = ot, C = window;
  if (c) {
    var w = Ei(n), _ = "clientHeight", R = "clientWidth";
    if (w === pt(n) && (w = En(n), Yt(w).position !== "static" && a === "absolute" && (_ = "scrollHeight", R = "scrollWidth")), w = w, i === ot || (i === at || i === Ct) && s === ii) {
      b = St;
      var k = u && w === C && C.visualViewport ? C.visualViewport.height : (
        // $FlowFixMe[prop-missing]
        w[_]
      );
      m -= k - r.height, m *= l ? 1 : -1;
    }
    if (i === at || (i === ot || i === St) && s === ii) {
      E = Ct;
      var $ = u && w === C && C.visualViewport ? C.visualViewport.width : (
        // $FlowFixMe[prop-missing]
        w[R]
      );
      p -= $ - r.width, p *= l ? 1 : -1;
    }
  }
  var Z = Object.assign({
    position: a
  }, c && k0), j = d === !0 ? T0({
    x: p,
    y: m
  }, pt(n)) : {
    x: p,
    y: m
  };
  if (p = j.x, m = j.y, l) {
    var J;
    return Object.assign({}, Z, (J = {}, J[b] = y ? "0" : "", J[E] = v ? "0" : "", J.transform = (C.devicePixelRatio || 1) <= 1 ? "translate(" + p + "px, " + m + "px)" : "translate3d(" + p + "px, " + m + "px, 0)", J));
  }
  return Object.assign({}, Z, (e = {}, e[b] = y ? m + "px" : "", e[E] = v ? p + "px" : "", e.transform = "", e));
}
function _0(t) {
  var e = t.state, n = t.options, r = n.gpuAcceleration, i = r === void 0 ? !0 : r, s = n.adaptive, o = s === void 0 ? !0 : s, a = n.roundOffsets, l = a === void 0 ? !0 : a, c = {
    placement: Pt(e.placement),
    variation: Tr(e.placement),
    popper: e.elements.popper,
    popperRect: e.rects.popper,
    gpuAcceleration: i,
    isFixed: e.options.strategy === "fixed"
  };
  e.modifiersData.popperOffsets != null && (e.styles.popper = Object.assign({}, e.styles.popper, Ic(Object.assign({}, c, {
    offsets: e.modifiersData.popperOffsets,
    position: e.options.strategy,
    adaptive: o,
    roundOffsets: l
  })))), e.modifiersData.arrow != null && (e.styles.arrow = Object.assign({}, e.styles.arrow, Ic(Object.assign({}, c, {
    offsets: e.modifiersData.arrow,
    position: "absolute",
    adaptive: !1,
    roundOffsets: l
  })))), e.attributes.popper = Object.assign({}, e.attributes.popper, {
    "data-popper-placement": e.placement
  });
}
const N0 = {
  name: "computeStyles",
  enabled: !0,
  phase: "beforeWrite",
  fn: _0,
  data: {}
};
var Ti = {
  passive: !0
};
function A0(t) {
  var e = t.state, n = t.instance, r = t.options, i = r.scroll, s = i === void 0 ? !0 : i, o = r.resize, a = o === void 0 ? !0 : o, l = pt(e.elements.popper), c = [].concat(e.scrollParents.reference, e.scrollParents.popper);
  return s && c.forEach(function(d) {
    d.addEventListener("scroll", n.update, Ti);
  }), a && l.addEventListener("resize", n.update, Ti), function() {
    s && c.forEach(function(d) {
      d.removeEventListener("scroll", n.update, Ti);
    }), a && l.removeEventListener("resize", n.update, Ti);
  };
}
const O0 = {
  name: "eventListeners",
  enabled: !0,
  phase: "write",
  fn: function() {
  },
  effect: A0,
  data: {}
};
var R0 = {
  left: "right",
  right: "left",
  bottom: "top",
  top: "bottom"
};
function qi(t) {
  return t.replace(/left|right|bottom|top/g, function(e) {
    return R0[e];
  });
}
var L0 = {
  start: "end",
  end: "start"
};
function Dc(t) {
  return t.replace(/start|end/g, function(e) {
    return L0[e];
  });
}
function Qa(t) {
  var e = pt(t), n = e.pageXOffset, r = e.pageYOffset;
  return {
    scrollLeft: n,
    scrollTop: r
  };
}
function el(t) {
  return kr(En(t)).left + Qa(t).scrollLeft;
}
function I0(t, e) {
  var n = pt(t), r = En(t), i = n.visualViewport, s = r.clientWidth, o = r.clientHeight, a = 0, l = 0;
  if (i) {
    s = i.width, o = i.height;
    var c = Of();
    (c || !c && e === "fixed") && (a = i.offsetLeft, l = i.offsetTop);
  }
  return {
    width: s,
    height: o,
    x: a + el(t),
    y: l
  };
}
function D0(t) {
  var e, n = En(t), r = Qa(t), i = (e = t.ownerDocument) == null ? void 0 : e.body, s = Hn(n.scrollWidth, n.clientWidth, i ? i.scrollWidth : 0, i ? i.clientWidth : 0), o = Hn(n.scrollHeight, n.clientHeight, i ? i.scrollHeight : 0, i ? i.clientHeight : 0), a = -r.scrollLeft + el(t), l = -r.scrollTop;
  return Yt(i || n).direction === "rtl" && (a += Hn(n.clientWidth, i ? i.clientWidth : 0) - s), {
    width: s,
    height: o,
    x: a,
    y: l
  };
}
function tl(t) {
  var e = Yt(t), n = e.overflow, r = e.overflowX, i = e.overflowY;
  return /auto|scroll|overlay|hidden/.test(n + i + r);
}
function Hf(t) {
  return ["html", "body", "#document"].indexOf(zt(t)) >= 0 ? t.ownerDocument.body : xt(t) && tl(t) ? t : Hf(qs(t));
}
function qr(t, e) {
  var n;
  e === void 0 && (e = []);
  var r = Hf(t), i = r === ((n = t.ownerDocument) == null ? void 0 : n.body), s = pt(r), o = i ? [s].concat(s.visualViewport || [], tl(r) ? r : []) : r, a = e.concat(o);
  return i ? a : (
    // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
    a.concat(qr(qs(o)))
  );
}
function da(t) {
  return Object.assign({}, t, {
    left: t.x,
    top: t.y,
    right: t.x + t.width,
    bottom: t.y + t.height
  });
}
function H0(t, e) {
  var n = kr(t, !1, e === "fixed");
  return n.top = n.top + t.clientTop, n.left = n.left + t.clientLeft, n.bottom = n.top + t.clientHeight, n.right = n.left + t.clientWidth, n.width = t.clientWidth, n.height = t.clientHeight, n.x = n.left, n.y = n.top, n;
}
function Hc(t, e, n) {
  return e === _f ? da(I0(t, n)) : Kn(e) ? H0(e, n) : da(D0(En(t)));
}
function B0(t) {
  var e = qr(qs(t)), n = ["absolute", "fixed"].indexOf(Yt(t).position) >= 0, r = n && xt(t) ? Ei(t) : t;
  return Kn(r) ? e.filter(function(i) {
    return Kn(i) && Rf(i, r) && zt(i) !== "body";
  }) : [];
}
function P0(t, e, n, r) {
  var i = e === "clippingParents" ? B0(t) : [].concat(e), s = [].concat(i, [n]), o = s[0], a = s.reduce(function(l, c) {
    var d = Hc(t, c, r);
    return l.top = Hn(d.top, l.top), l.right = fs(d.right, l.right), l.bottom = fs(d.bottom, l.bottom), l.left = Hn(d.left, l.left), l;
  }, Hc(t, o, r));
  return a.width = a.right - a.left, a.height = a.bottom - a.top, a.x = a.left, a.y = a.top, a;
}
function Bf(t) {
  var e = t.reference, n = t.element, r = t.placement, i = r ? Pt(r) : null, s = r ? Tr(r) : null, o = e.x + e.width / 2 - n.width / 2, a = e.y + e.height / 2 - n.height / 2, l;
  switch (i) {
    case ot:
      l = {
        x: o,
        y: e.y - n.height
      };
      break;
    case St:
      l = {
        x: o,
        y: e.y + e.height
      };
      break;
    case Ct:
      l = {
        x: e.x + e.width,
        y: a
      };
      break;
    case at:
      l = {
        x: e.x - n.width,
        y: a
      };
      break;
    default:
      l = {
        x: e.x,
        y: e.y
      };
  }
  var c = i ? Xa(i) : null;
  if (c != null) {
    var d = c === "y" ? "height" : "width";
    switch (s) {
      case Cr:
        l[c] = l[c] - (e[d] / 2 - n[d] / 2);
        break;
      case ii:
        l[c] = l[c] + (e[d] / 2 - n[d] / 2);
        break;
    }
  }
  return l;
}
function si(t, e) {
  e === void 0 && (e = {});
  var n = e, r = n.placement, i = r === void 0 ? t.placement : r, s = n.strategy, o = s === void 0 ? t.strategy : s, a = n.boundary, l = a === void 0 ? s0 : a, c = n.rootBoundary, d = c === void 0 ? _f : c, u = n.elementContext, f = u === void 0 ? Ir : u, p = n.altBoundary, h = p === void 0 ? !1 : p, m = n.padding, g = m === void 0 ? 0 : m, v = If(typeof g != "number" ? g : Df(g, wi)), y = f === Ir ? o0 : Ir, E = t.rects.popper, b = t.elements[h ? y : f], C = P0(Kn(b) ? b : b.contextElement || En(t.elements.popper), l, d, o), w = kr(t.elements.reference), _ = Bf({
    reference: w,
    element: E,
    strategy: "absolute",
    placement: i
  }), R = da(Object.assign({}, E, _)), k = f === Ir ? R : w, $ = {
    top: C.top - k.top + v.top,
    bottom: k.bottom - C.bottom + v.bottom,
    left: C.left - k.left + v.left,
    right: k.right - C.right + v.right
  }, Z = t.modifiersData.offset;
  if (f === Ir && Z) {
    var j = Z[i];
    Object.keys($).forEach(function(J) {
      var X = [Ct, St].indexOf(J) >= 0 ? 1 : -1, re = [ot, St].indexOf(J) >= 0 ? "y" : "x";
      $[J] += j[re] * X;
    });
  }
  return $;
}
function $0(t, e) {
  e === void 0 && (e = {});
  var n = e, r = n.placement, i = n.boundary, s = n.rootBoundary, o = n.padding, a = n.flipVariations, l = n.allowedAutoPlacements, c = l === void 0 ? Nf : l, d = Tr(r), u = d ? a ? Rc : Rc.filter(function(h) {
    return Tr(h) === d;
  }) : wi, f = u.filter(function(h) {
    return c.indexOf(h) >= 0;
  });
  f.length === 0 && (f = u);
  var p = f.reduce(function(h, m) {
    return h[m] = si(t, {
      placement: m,
      boundary: i,
      rootBoundary: s,
      padding: o
    })[Pt(m)], h;
  }, {});
  return Object.keys(p).sort(function(h, m) {
    return p[h] - p[m];
  });
}
function V0(t) {
  if (Pt(t) === ja)
    return [];
  var e = qi(t);
  return [Dc(t), e, Dc(e)];
}
function z0(t) {
  var e = t.state, n = t.options, r = t.name;
  if (!e.modifiersData[r]._skip) {
    for (var i = n.mainAxis, s = i === void 0 ? !0 : i, o = n.altAxis, a = o === void 0 ? !0 : o, l = n.fallbackPlacements, c = n.padding, d = n.boundary, u = n.rootBoundary, f = n.altBoundary, p = n.flipVariations, h = p === void 0 ? !0 : p, m = n.allowedAutoPlacements, g = e.options.placement, v = Pt(g), y = v === g, E = l || (y || !h ? [qi(g)] : V0(g)), b = [g].concat(E).reduce(function(ge, le) {
      return ge.concat(Pt(le) === ja ? $0(e, {
        placement: le,
        boundary: d,
        rootBoundary: u,
        padding: c,
        flipVariations: h,
        allowedAutoPlacements: m
      }) : le);
    }, []), C = e.rects.reference, w = e.rects.popper, _ = /* @__PURE__ */ new Map(), R = !0, k = b[0], $ = 0; $ < b.length; $++) {
      var Z = b[$], j = Pt(Z), J = Tr(Z) === Cr, X = [ot, St].indexOf(j) >= 0, re = X ? "width" : "height", T = si(e, {
        placement: Z,
        boundary: d,
        rootBoundary: u,
        altBoundary: f,
        padding: c
      }), x = X ? J ? Ct : at : J ? St : ot;
      C[re] > w[re] && (x = qi(x));
      var S = qi(x), O = [];
      if (s && O.push(T[j] <= 0), a && O.push(T[x] <= 0, T[S] <= 0), O.every(function(ge) {
        return ge;
      })) {
        k = Z, R = !1;
        break;
      }
      _.set(Z, O);
    }
    if (R)
      for (var D = h ? 3 : 1, F = function(le) {
        var Ee = b.find(function(tt) {
          var Pe = _.get(tt);
          if (Pe)
            return Pe.slice(0, le).every(function(lt) {
              return lt;
            });
        });
        if (Ee)
          return k = Ee, "break";
      }, Q = D; Q > 0; Q--) {
        var ue = F(Q);
        if (ue === "break")
          break;
      }
    e.placement !== k && (e.modifiersData[r]._skip = !0, e.placement = k, e.reset = !0);
  }
}
const F0 = {
  name: "flip",
  enabled: !0,
  phase: "main",
  fn: z0,
  requiresIfExists: ["offset"],
  data: {
    _skip: !1
  }
};
function Bc(t, e, n) {
  return n === void 0 && (n = {
    x: 0,
    y: 0
  }), {
    top: t.top - e.height - n.y,
    right: t.right - e.width + n.x,
    bottom: t.bottom - e.height + n.y,
    left: t.left - e.width - n.x
  };
}
function Pc(t) {
  return [ot, Ct, St, at].some(function(e) {
    return t[e] >= 0;
  });
}
function U0(t) {
  var e = t.state, n = t.name, r = e.rects.reference, i = e.rects.popper, s = e.modifiersData.preventOverflow, o = si(e, {
    elementContext: "reference"
  }), a = si(e, {
    altBoundary: !0
  }), l = Bc(o, r), c = Bc(a, i, s), d = Pc(l), u = Pc(c);
  e.modifiersData[n] = {
    referenceClippingOffsets: l,
    popperEscapeOffsets: c,
    isReferenceHidden: d,
    hasPopperEscaped: u
  }, e.attributes.popper = Object.assign({}, e.attributes.popper, {
    "data-popper-reference-hidden": d,
    "data-popper-escaped": u
  });
}
const K0 = {
  name: "hide",
  enabled: !0,
  phase: "main",
  requiresIfExists: ["preventOverflow"],
  fn: U0
};
function W0(t, e, n) {
  var r = Pt(t), i = [at, ot].indexOf(r) >= 0 ? -1 : 1, s = typeof n == "function" ? n(Object.assign({}, e, {
    placement: t
  })) : n, o = s[0], a = s[1];
  return o = o || 0, a = (a || 0) * i, [at, Ct].indexOf(r) >= 0 ? {
    x: a,
    y: o
  } : {
    x: o,
    y: a
  };
}
function q0(t) {
  var e = t.state, n = t.options, r = t.name, i = n.offset, s = i === void 0 ? [0, 0] : i, o = Nf.reduce(function(d, u) {
    return d[u] = W0(u, e.rects, s), d;
  }, {}), a = o[e.placement], l = a.x, c = a.y;
  e.modifiersData.popperOffsets != null && (e.modifiersData.popperOffsets.x += l, e.modifiersData.popperOffsets.y += c), e.modifiersData[r] = o;
}
const Z0 = {
  name: "offset",
  enabled: !0,
  phase: "main",
  requires: ["popperOffsets"],
  fn: q0
};
function G0(t) {
  var e = t.state, n = t.name;
  e.modifiersData[n] = Bf({
    reference: e.rects.reference,
    element: e.rects.popper,
    strategy: "absolute",
    placement: e.placement
  });
}
const j0 = {
  name: "popperOffsets",
  enabled: !0,
  phase: "read",
  fn: G0,
  data: {}
};
function Y0(t) {
  return t === "x" ? "y" : "x";
}
function J0(t) {
  var e = t.state, n = t.options, r = t.name, i = n.mainAxis, s = i === void 0 ? !0 : i, o = n.altAxis, a = o === void 0 ? !1 : o, l = n.boundary, c = n.rootBoundary, d = n.altBoundary, u = n.padding, f = n.tether, p = f === void 0 ? !0 : f, h = n.tetherOffset, m = h === void 0 ? 0 : h, g = si(e, {
    boundary: l,
    rootBoundary: c,
    padding: u,
    altBoundary: d
  }), v = Pt(e.placement), y = Tr(e.placement), E = !y, b = Xa(v), C = Y0(b), w = e.modifiersData.popperOffsets, _ = e.rects.reference, R = e.rects.popper, k = typeof m == "function" ? m(Object.assign({}, e.rects, {
    placement: e.placement
  })) : m, $ = typeof k == "number" ? {
    mainAxis: k,
    altAxis: k
  } : Object.assign({
    mainAxis: 0,
    altAxis: 0
  }, k), Z = e.modifiersData.offset ? e.modifiersData.offset[e.placement] : null, j = {
    x: 0,
    y: 0
  };
  if (w) {
    if (s) {
      var J, X = b === "y" ? ot : at, re = b === "y" ? St : Ct, T = b === "y" ? "height" : "width", x = w[b], S = x + g[X], O = x - g[re], D = p ? -R[T] / 2 : 0, F = y === Cr ? _[T] : R[T], Q = y === Cr ? -R[T] : -_[T], ue = e.elements.arrow, ge = p && ue ? Ja(ue) : {
        width: 0,
        height: 0
      }, le = e.modifiersData["arrow#persistent"] ? e.modifiersData["arrow#persistent"].padding : Lf(), Ee = le[X], tt = le[re], Pe = Wr(0, _[T], ge[T]), lt = E ? _[T] / 2 - D - Pe - Ee - $.mainAxis : F - Pe - Ee - $.mainAxis, nt = E ? -_[T] / 2 + D + Pe + tt + $.mainAxis : Q + Pe + tt + $.mainAxis, mt = e.elements.arrow && Ei(e.elements.arrow), ct = mt ? b === "y" ? mt.clientTop || 0 : mt.clientLeft || 0 : 0, ce = (J = Z == null ? void 0 : Z[b]) != null ? J : 0, ke = x + lt - ce - ct, je = x + nt - ce, Ne = Wr(p ? fs(S, ke) : S, x, p ? Hn(O, je) : O);
      w[b] = Ne, j[b] = Ne - x;
    }
    if (a) {
      var ee, Mt = b === "x" ? ot : at, P = b === "x" ? St : Ct, ae = w[C], he = C === "y" ? "height" : "width", oe = ae + g[Mt], Ue = ae - g[P], $e = [ot, at].indexOf(v) !== -1, H = (ee = Z == null ? void 0 : Z[C]) != null ? ee : 0, V = $e ? oe : ae - _[he] - R[he] - H + $.altAxis, N = $e ? ae + _[he] + R[he] - H - $.altAxis : Ue, L = p && $e ? E0(V, ae, N) : Wr(p ? V : oe, ae, p ? N : Ue);
      w[C] = L, j[C] = L - ae;
    }
    e.modifiersData[r] = j;
  }
}
const X0 = {
  name: "preventOverflow",
  enabled: !0,
  phase: "main",
  fn: J0,
  requiresIfExists: ["offset"]
};
function Q0(t) {
  return {
    scrollLeft: t.scrollLeft,
    scrollTop: t.scrollTop
  };
}
function ey(t) {
  return t === pt(t) || !xt(t) ? Qa(t) : Q0(t);
}
function ty(t) {
  var e = t.getBoundingClientRect(), n = Mr(e.width) / t.offsetWidth || 1, r = Mr(e.height) / t.offsetHeight || 1;
  return n !== 1 || r !== 1;
}
function ny(t, e, n) {
  n === void 0 && (n = !1);
  var r = xt(e), i = xt(e) && ty(e), s = En(e), o = kr(t, i, n), a = {
    scrollLeft: 0,
    scrollTop: 0
  }, l = {
    x: 0,
    y: 0
  };
  return (r || !r && !n) && ((zt(e) !== "body" || // https://github.com/popperjs/popper-core/issues/1078
  tl(s)) && (a = ey(e)), xt(e) ? (l = kr(e, !0), l.x += e.clientLeft, l.y += e.clientTop) : s && (l.x = el(s))), {
    x: o.left + a.scrollLeft - l.x,
    y: o.top + a.scrollTop - l.y,
    width: o.width,
    height: o.height
  };
}
function ry(t) {
  var e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = [];
  t.forEach(function(s) {
    e.set(s.name, s);
  });
  function i(s) {
    n.add(s.name);
    var o = [].concat(s.requires || [], s.requiresIfExists || []);
    o.forEach(function(a) {
      if (!n.has(a)) {
        var l = e.get(a);
        l && i(l);
      }
    }), r.push(s);
  }
  return t.forEach(function(s) {
    n.has(s.name) || i(s);
  }), r;
}
function iy(t) {
  var e = ry(t);
  return g0.reduce(function(n, r) {
    return n.concat(e.filter(function(i) {
      return i.phase === r;
    }));
  }, []);
}
function sy(t) {
  var e;
  return function() {
    return e || (e = new Promise(function(n) {
      Promise.resolve().then(function() {
        e = void 0, n(t());
      });
    })), e;
  };
}
function oy(t) {
  var e = t.reduce(function(n, r) {
    var i = n[r.name];
    return n[r.name] = i ? Object.assign({}, i, r, {
      options: Object.assign({}, i.options, r.options),
      data: Object.assign({}, i.data, r.data)
    }) : r, n;
  }, {});
  return Object.keys(e).map(function(n) {
    return e[n];
  });
}
var $c = {
  placement: "bottom",
  modifiers: [],
  strategy: "absolute"
};
function Vc() {
  for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++)
    e[n] = arguments[n];
  return !e.some(function(r) {
    return !(r && typeof r.getBoundingClientRect == "function");
  });
}
function ay(t) {
  t === void 0 && (t = {});
  var e = t, n = e.defaultModifiers, r = n === void 0 ? [] : n, i = e.defaultOptions, s = i === void 0 ? $c : i;
  return function(a, l, c) {
    c === void 0 && (c = s);
    var d = {
      placement: "bottom",
      orderedModifiers: [],
      options: Object.assign({}, $c, s),
      modifiersData: {},
      elements: {
        reference: a,
        popper: l
      },
      attributes: {},
      styles: {}
    }, u = [], f = !1, p = {
      state: d,
      setOptions: function(v) {
        var y = typeof v == "function" ? v(d.options) : v;
        m(), d.options = Object.assign({}, s, d.options, y), d.scrollParents = {
          reference: Kn(a) ? qr(a) : a.contextElement ? qr(a.contextElement) : [],
          popper: qr(l)
        };
        var E = iy(oy([].concat(r, d.options.modifiers)));
        return d.orderedModifiers = E.filter(function(b) {
          return b.enabled;
        }), h(), p.update();
      },
      // Sync update – it will always be executed, even if not necessary. This
      // is useful for low frequency updates where sync behavior simplifies the
      // logic.
      // For high frequency updates (e.g. `resize` and `scroll` events), always
      // prefer the async Popper#update method
      forceUpdate: function() {
        if (!f) {
          var v = d.elements, y = v.reference, E = v.popper;
          if (Vc(y, E)) {
            d.rects = {
              reference: ny(y, Ei(E), d.options.strategy === "fixed"),
              popper: Ja(E)
            }, d.reset = !1, d.placement = d.options.placement, d.orderedModifiers.forEach(function($) {
              return d.modifiersData[$.name] = Object.assign({}, $.data);
            });
            for (var b = 0; b < d.orderedModifiers.length; b++) {
              if (d.reset === !0) {
                d.reset = !1, b = -1;
                continue;
              }
              var C = d.orderedModifiers[b], w = C.fn, _ = C.options, R = _ === void 0 ? {} : _, k = C.name;
              typeof w == "function" && (d = w({
                state: d,
                options: R,
                name: k,
                instance: p
              }) || d);
            }
          }
        }
      },
      // Async and optimistically optimized update – it will not be executed if
      // not necessary (debounced to run at most once-per-tick)
      update: sy(function() {
        return new Promise(function(g) {
          p.forceUpdate(), g(d);
        });
      }),
      destroy: function() {
        m(), f = !0;
      }
    };
    if (!Vc(a, l))
      return p;
    p.setOptions(c).then(function(g) {
      !f && c.onFirstUpdate && c.onFirstUpdate(g);
    });
    function h() {
      d.orderedModifiers.forEach(function(g) {
        var v = g.name, y = g.options, E = y === void 0 ? {} : y, b = g.effect;
        if (typeof b == "function") {
          var C = b({
            state: d,
            name: v,
            instance: p,
            options: E
          }), w = function() {
          };
          u.push(C || w);
        }
      });
    }
    function m() {
      u.forEach(function(g) {
        return g();
      }), u = [];
    }
    return p;
  };
}
var ly = [O0, j0, N0, Af, Z0, F0, X0, M0, K0], cy = /* @__PURE__ */ ay({
  defaultModifiers: ly
}), dy = "tippy-box", Pf = "tippy-content", uy = "tippy-backdrop", $f = "tippy-arrow", Vf = "tippy-svg-arrow", Cn = {
  passive: !0,
  capture: !0
}, zf = function() {
  return document.body;
};
function fy(t, e) {
  return {}.hasOwnProperty.call(t, e);
}
function Co(t, e, n) {
  if (Array.isArray(t)) {
    var r = t[e];
    return r ?? (Array.isArray(n) ? n[e] : n);
  }
  return t;
}
function nl(t, e) {
  var n = {}.toString.call(t);
  return n.indexOf("[object") === 0 && n.indexOf(e + "]") > -1;
}
function Ff(t, e) {
  return typeof t == "function" ? t.apply(void 0, e) : t;
}
function zc(t, e) {
  if (e === 0)
    return t;
  var n;
  return function(r) {
    clearTimeout(n), n = setTimeout(function() {
      t(r);
    }, e);
  };
}
function py(t, e) {
  var n = Object.assign({}, t);
  return e.forEach(function(r) {
    delete n[r];
  }), n;
}
function hy(t) {
  return t.split(/\s+/).filter(Boolean);
}
function ir(t) {
  return [].concat(t);
}
function Fc(t, e) {
  t.indexOf(e) === -1 && t.push(e);
}
function my(t) {
  return t.filter(function(e, n) {
    return t.indexOf(e) === n;
  });
}
function gy(t) {
  return t.split("-")[0];
}
function ps(t) {
  return [].slice.call(t);
}
function Uc(t) {
  return Object.keys(t).reduce(function(e, n) {
    return t[n] !== void 0 && (e[n] = t[n]), e;
  }, {});
}
function Zr() {
  return document.createElement("div");
}
function oi(t) {
  return ["Element", "Fragment"].some(function(e) {
    return nl(t, e);
  });
}
function by(t) {
  return nl(t, "NodeList");
}
function yy(t) {
  return nl(t, "MouseEvent");
}
function vy(t) {
  return !!(t && t._tippy && t._tippy.reference === t);
}
function wy(t) {
  return oi(t) ? [t] : by(t) ? ps(t) : Array.isArray(t) ? t : ps(document.querySelectorAll(t));
}
function Mo(t, e) {
  t.forEach(function(n) {
    n && (n.style.transitionDuration = e + "ms");
  });
}
function Kc(t, e) {
  t.forEach(function(n) {
    n && n.setAttribute("data-state", e);
  });
}
function Ey(t) {
  var e, n = ir(t), r = n[0];
  return r != null && (e = r.ownerDocument) != null && e.body ? r.ownerDocument : document;
}
function xy(t, e) {
  var n = e.clientX, r = e.clientY;
  return t.every(function(i) {
    var s = i.popperRect, o = i.popperState, a = i.props, l = a.interactiveBorder, c = gy(o.placement), d = o.modifiersData.offset;
    if (!d)
      return !0;
    var u = c === "bottom" ? d.top.y : 0, f = c === "top" ? d.bottom.y : 0, p = c === "right" ? d.left.x : 0, h = c === "left" ? d.right.x : 0, m = s.top - r + u > l, g = r - s.bottom - f > l, v = s.left - n + p > l, y = n - s.right - h > l;
    return m || g || v || y;
  });
}
function ko(t, e, n) {
  var r = e + "EventListener";
  ["transitionend", "webkitTransitionEnd"].forEach(function(i) {
    t[r](i, n);
  });
}
function Wc(t, e) {
  for (var n = e; n; ) {
    var r;
    if (t.contains(n))
      return !0;
    n = n.getRootNode == null || (r = n.getRootNode()) == null ? void 0 : r.host;
  }
  return !1;
}
var It = {
  isTouch: !1
}, qc = 0;
function Sy() {
  It.isTouch || (It.isTouch = !0, window.performance && document.addEventListener("mousemove", Uf));
}
function Uf() {
  var t = performance.now();
  t - qc < 20 && (It.isTouch = !1, document.removeEventListener("mousemove", Uf)), qc = t;
}
function Cy() {
  var t = document.activeElement;
  if (vy(t)) {
    var e = t._tippy;
    t.blur && !e.state.isVisible && t.blur();
  }
}
function My() {
  document.addEventListener("touchstart", Sy, Cn), window.addEventListener("blur", Cy);
}
var ky = typeof window < "u" && typeof document < "u", Ty = ky ? (
  // @ts-ignore
  !!window.msCrypto
) : !1;
function Xn(t) {
  var e = t === "destroy" ? "n already-" : " ";
  return [t + "() was called on a" + e + "destroyed instance. This is a no-op but", "indicates a potential memory leak."].join(" ");
}
function Zc(t) {
  var e = /[ \t]{2,}/g, n = /^[ \t]*/gm;
  return t.replace(e, " ").replace(n, "").trim();
}
function _y(t) {
  return Zc(`
  %ctippy.js

  %c` + Zc(t) + `

  %c👷‍ This is a development-only message. It will be removed in production.
  `);
}
function Kf(t) {
  return [
    _y(t),
    // title
    "color: #00C584; font-size: 1.3em; font-weight: bold;",
    // message
    "line-height: 1.5",
    // footer
    "color: #a6a095;"
  ];
}
var ai;
({}).NODE_ENV !== "production" && Ny();
function Ny() {
  ai = /* @__PURE__ */ new Set();
}
function Zt(t, e) {
  if (t && !ai.has(e)) {
    var n;
    ai.add(e), (n = console).warn.apply(n, Kf(e));
  }
}
function ua(t, e) {
  if (t && !ai.has(e)) {
    var n;
    ai.add(e), (n = console).error.apply(n, Kf(e));
  }
}
function Ay(t) {
  var e = !t, n = Object.prototype.toString.call(t) === "[object Object]" && !t.addEventListener;
  ua(e, ["tippy() was passed", "`" + String(t) + "`", "as its targets (first) argument. Valid types are: String, Element,", "Element[], or NodeList."].join(" ")), ua(n, ["tippy() was passed a plain object which is not supported as an argument", "for virtual positioning. Use props.getReferenceClientRect instead."].join(" "));
}
var Wf = {
  animateFill: !1,
  followCursor: !1,
  inlinePositioning: !1,
  sticky: !1
}, Oy = {
  allowHTML: !1,
  animation: "fade",
  arrow: !0,
  content: "",
  inertia: !1,
  maxWidth: 350,
  role: "tooltip",
  theme: "",
  zIndex: 9999
}, ft = Object.assign({
  appendTo: zf,
  aria: {
    content: "auto",
    expanded: "auto"
  },
  delay: 0,
  duration: [300, 250],
  getReferenceClientRect: null,
  hideOnClick: !0,
  ignoreAttributes: !1,
  interactive: !1,
  interactiveBorder: 2,
  interactiveDebounce: 0,
  moveTransition: "",
  offset: [0, 10],
  onAfterUpdate: function() {
  },
  onBeforeUpdate: function() {
  },
  onCreate: function() {
  },
  onDestroy: function() {
  },
  onHidden: function() {
  },
  onHide: function() {
  },
  onMount: function() {
  },
  onShow: function() {
  },
  onShown: function() {
  },
  onTrigger: function() {
  },
  onUntrigger: function() {
  },
  onClickOutside: function() {
  },
  placement: "top",
  plugins: [],
  popperOptions: {},
  render: null,
  showOnCreate: !1,
  touch: !0,
  trigger: "mouseenter focus",
  triggerTarget: null
}, Wf, Oy), Ry = Object.keys(ft), Ly = function(e) {
  ({}).NODE_ENV !== "production" && Zf(e, []);
  var n = Object.keys(e);
  n.forEach(function(r) {
    ft[r] = e[r];
  });
};
function qf(t) {
  var e = t.plugins || [], n = e.reduce(function(r, i) {
    var s = i.name, o = i.defaultValue;
    if (s) {
      var a;
      r[s] = t[s] !== void 0 ? t[s] : (a = ft[s]) != null ? a : o;
    }
    return r;
  }, {});
  return Object.assign({}, t, n);
}
function Iy(t, e) {
  var n = e ? Object.keys(qf(Object.assign({}, ft, {
    plugins: e
  }))) : Ry, r = n.reduce(function(i, s) {
    var o = (t.getAttribute("data-tippy-" + s) || "").trim();
    if (!o)
      return i;
    if (s === "content")
      i[s] = o;
    else
      try {
        i[s] = JSON.parse(o);
      } catch {
        i[s] = o;
      }
    return i;
  }, {});
  return r;
}
function Gc(t, e) {
  var n = Object.assign({}, e, {
    content: Ff(e.content, [t])
  }, e.ignoreAttributes ? {} : Iy(t, e.plugins));
  return n.aria = Object.assign({}, ft.aria, n.aria), n.aria = {
    expanded: n.aria.expanded === "auto" ? e.interactive : n.aria.expanded,
    content: n.aria.content === "auto" ? e.interactive ? null : "describedby" : n.aria.content
  }, n;
}
function Zf(t, e) {
  t === void 0 && (t = {}), e === void 0 && (e = []);
  var n = Object.keys(t);
  n.forEach(function(r) {
    var i = py(ft, Object.keys(Wf)), s = !fy(i, r);
    s && (s = e.filter(function(o) {
      return o.name === r;
    }).length === 0), Zt(s, ["`" + r + "`", "is not a valid prop. You may have spelled it incorrectly, or if it's", "a plugin, forgot to pass it in an array as props.plugins.", `

`, `All props: https://atomiks.github.io/tippyjs/v6/all-props/
`, "Plugins: https://atomiks.github.io/tippyjs/v6/plugins/"].join(" "));
  });
}
var Dy = function() {
  return "innerHTML";
};
function fa(t, e) {
  t[Dy()] = e;
}
function jc(t) {
  var e = Zr();
  return t === !0 ? e.className = $f : (e.className = Vf, oi(t) ? e.appendChild(t) : fa(e, t)), e;
}
function Yc(t, e) {
  oi(e.content) ? (fa(t, ""), t.appendChild(e.content)) : typeof e.content != "function" && (e.allowHTML ? fa(t, e.content) : t.textContent = e.content);
}
function pa(t) {
  var e = t.firstElementChild, n = ps(e.children);
  return {
    box: e,
    content: n.find(function(r) {
      return r.classList.contains(Pf);
    }),
    arrow: n.find(function(r) {
      return r.classList.contains($f) || r.classList.contains(Vf);
    }),
    backdrop: n.find(function(r) {
      return r.classList.contains(uy);
    })
  };
}
function Gf(t) {
  var e = Zr(), n = Zr();
  n.className = dy, n.setAttribute("data-state", "hidden"), n.setAttribute("tabindex", "-1");
  var r = Zr();
  r.className = Pf, r.setAttribute("data-state", "hidden"), Yc(r, t.props), e.appendChild(n), n.appendChild(r), i(t.props, t.props);
  function i(s, o) {
    var a = pa(e), l = a.box, c = a.content, d = a.arrow;
    o.theme ? l.setAttribute("data-theme", o.theme) : l.removeAttribute("data-theme"), typeof o.animation == "string" ? l.setAttribute("data-animation", o.animation) : l.removeAttribute("data-animation"), o.inertia ? l.setAttribute("data-inertia", "") : l.removeAttribute("data-inertia"), l.style.maxWidth = typeof o.maxWidth == "number" ? o.maxWidth + "px" : o.maxWidth, o.role ? l.setAttribute("role", o.role) : l.removeAttribute("role"), (s.content !== o.content || s.allowHTML !== o.allowHTML) && Yc(c, t.props), o.arrow ? d ? s.arrow !== o.arrow && (l.removeChild(d), l.appendChild(jc(o.arrow))) : l.appendChild(jc(o.arrow)) : d && l.removeChild(d);
  }
  return {
    popper: e,
    onUpdate: i
  };
}
Gf.$$tippy = !0;
var Hy = 1, _i = [], To = [];
function By(t, e) {
  var n = Gc(t, Object.assign({}, ft, qf(Uc(e)))), r, i, s, o = !1, a = !1, l = !1, c = !1, d, u, f, p = [], h = zc(ke, n.interactiveDebounce), m, g = Hy++, v = null, y = my(n.plugins), E = {
    // Is the instance currently enabled?
    isEnabled: !0,
    // Is the tippy currently showing and not transitioning out?
    isVisible: !1,
    // Has the instance been destroyed?
    isDestroyed: !1,
    // Is the tippy currently mounted to the DOM?
    isMounted: !1,
    // Has the tippy finished transitioning in?
    isShown: !1
  }, b = {
    // properties
    id: g,
    reference: t,
    popper: Zr(),
    popperInstance: v,
    props: n,
    state: E,
    plugins: y,
    // methods
    clearDelayTimeouts: V,
    setProps: N,
    setContent: L,
    show: K,
    hide: se,
    hideWithInteractivity: Oe,
    enable: $e,
    disable: H,
    unmount: dt,
    destroy: Qs
  };
  if (!n.render)
    return {}.NODE_ENV !== "production" && ua(!0, "render() function has not been supplied."), b;
  var C = n.render(b), w = C.popper, _ = C.onUpdate;
  w.setAttribute("data-tippy-root", ""), w.id = "tippy-" + b.id, b.popper = w, t._tippy = b, w._tippy = b;
  var R = y.map(function(M) {
    return M.fn(b);
  }), k = t.hasAttribute("aria-expanded");
  return mt(), D(), x(), S("onCreate", [b]), n.showOnCreate && oe(), w.addEventListener("mouseenter", function() {
    b.props.interactive && b.state.isVisible && b.clearDelayTimeouts();
  }), w.addEventListener("mouseleave", function() {
    b.props.interactive && b.props.trigger.indexOf("mouseenter") >= 0 && X().addEventListener("mousemove", h);
  }), b;
  function $() {
    var M = b.props.touch;
    return Array.isArray(M) ? M : [M, 0];
  }
  function Z() {
    return $()[0] === "hold";
  }
  function j() {
    var M;
    return !!((M = b.props.render) != null && M.$$tippy);
  }
  function J() {
    return m || t;
  }
  function X() {
    var M = J().parentNode;
    return M ? Ey(M) : document;
  }
  function re() {
    return pa(w);
  }
  function T(M) {
    return b.state.isMounted && !b.state.isVisible || It.isTouch || d && d.type === "focus" ? 0 : Co(b.props.delay, M ? 0 : 1, ft.delay);
  }
  function x(M) {
    M === void 0 && (M = !1), w.style.pointerEvents = b.props.interactive && !M ? "" : "none", w.style.zIndex = "" + b.props.zIndex;
  }
  function S(M, U, ne) {
    if (ne === void 0 && (ne = !0), R.forEach(function(pe) {
      pe[M] && pe[M].apply(pe, U);
    }), ne) {
      var be;
      (be = b.props)[M].apply(be, U);
    }
  }
  function O() {
    var M = b.props.aria;
    if (M.content) {
      var U = "aria-" + M.content, ne = w.id, be = ir(b.props.triggerTarget || t);
      be.forEach(function(pe) {
        var Ye = pe.getAttribute(U);
        if (b.state.isVisible)
          pe.setAttribute(U, Ye ? Ye + " " + ne : ne);
        else {
          var gt = Ye && Ye.replace(ne, "").trim();
          gt ? pe.setAttribute(U, gt) : pe.removeAttribute(U);
        }
      });
    }
  }
  function D() {
    if (!(k || !b.props.aria.expanded)) {
      var M = ir(b.props.triggerTarget || t);
      M.forEach(function(U) {
        b.props.interactive ? U.setAttribute("aria-expanded", b.state.isVisible && U === J() ? "true" : "false") : U.removeAttribute("aria-expanded");
      });
    }
  }
  function F() {
    X().removeEventListener("mousemove", h), _i = _i.filter(function(M) {
      return M !== h;
    });
  }
  function Q(M) {
    if (!(It.isTouch && (l || M.type === "mousedown"))) {
      var U = M.composedPath && M.composedPath()[0] || M.target;
      if (!(b.props.interactive && Wc(w, U))) {
        if (ir(b.props.triggerTarget || t).some(function(ne) {
          return Wc(ne, U);
        })) {
          if (It.isTouch || b.state.isVisible && b.props.trigger.indexOf("click") >= 0)
            return;
        } else
          S("onClickOutside", [b, M]);
        b.props.hideOnClick === !0 && (b.clearDelayTimeouts(), b.hide(), a = !0, setTimeout(function() {
          a = !1;
        }), b.state.isMounted || Ee());
      }
    }
  }
  function ue() {
    l = !0;
  }
  function ge() {
    l = !1;
  }
  function le() {
    var M = X();
    M.addEventListener("mousedown", Q, !0), M.addEventListener("touchend", Q, Cn), M.addEventListener("touchstart", ge, Cn), M.addEventListener("touchmove", ue, Cn);
  }
  function Ee() {
    var M = X();
    M.removeEventListener("mousedown", Q, !0), M.removeEventListener("touchend", Q, Cn), M.removeEventListener("touchstart", ge, Cn), M.removeEventListener("touchmove", ue, Cn);
  }
  function tt(M, U) {
    lt(M, function() {
      !b.state.isVisible && w.parentNode && w.parentNode.contains(w) && U();
    });
  }
  function Pe(M, U) {
    lt(M, U);
  }
  function lt(M, U) {
    var ne = re().box;
    function be(pe) {
      pe.target === ne && (ko(ne, "remove", be), U());
    }
    if (M === 0)
      return U();
    ko(ne, "remove", u), ko(ne, "add", be), u = be;
  }
  function nt(M, U, ne) {
    ne === void 0 && (ne = !1);
    var be = ir(b.props.triggerTarget || t);
    be.forEach(function(pe) {
      pe.addEventListener(M, U, ne), p.push({
        node: pe,
        eventType: M,
        handler: U,
        options: ne
      });
    });
  }
  function mt() {
    Z() && (nt("touchstart", ce, {
      passive: !0
    }), nt("touchend", je, {
      passive: !0
    })), hy(b.props.trigger).forEach(function(M) {
      if (M !== "manual")
        switch (nt(M, ce), M) {
          case "mouseenter":
            nt("mouseleave", je);
            break;
          case "focus":
            nt(Ty ? "focusout" : "blur", Ne);
            break;
          case "focusin":
            nt("focusout", Ne);
            break;
        }
    });
  }
  function ct() {
    p.forEach(function(M) {
      var U = M.node, ne = M.eventType, be = M.handler, pe = M.options;
      U.removeEventListener(ne, be, pe);
    }), p = [];
  }
  function ce(M) {
    var U, ne = !1;
    if (!(!b.state.isEnabled || ee(M) || a)) {
      var be = ((U = d) == null ? void 0 : U.type) === "focus";
      d = M, m = M.currentTarget, D(), !b.state.isVisible && yy(M) && _i.forEach(function(pe) {
        return pe(M);
      }), M.type === "click" && (b.props.trigger.indexOf("mouseenter") < 0 || o) && b.props.hideOnClick !== !1 && b.state.isVisible ? ne = !0 : oe(M), M.type === "click" && (o = !ne), ne && !be && Ue(M);
    }
  }
  function ke(M) {
    var U = M.target, ne = J().contains(U) || w.contains(U);
    if (!(M.type === "mousemove" && ne)) {
      var be = he().concat(w).map(function(pe) {
        var Ye, gt = pe._tippy, Gn = (Ye = gt.popperInstance) == null ? void 0 : Ye.state;
        return Gn ? {
          popperRect: pe.getBoundingClientRect(),
          popperState: Gn,
          props: n
        } : null;
      }).filter(Boolean);
      xy(be, M) && (F(), Ue(M));
    }
  }
  function je(M) {
    var U = ee(M) || b.props.trigger.indexOf("click") >= 0 && o;
    if (!U) {
      if (b.props.interactive) {
        b.hideWithInteractivity(M);
        return;
      }
      Ue(M);
    }
  }
  function Ne(M) {
    b.props.trigger.indexOf("focusin") < 0 && M.target !== J() || b.props.interactive && M.relatedTarget && w.contains(M.relatedTarget) || Ue(M);
  }
  function ee(M) {
    return It.isTouch ? Z() !== M.type.indexOf("touch") >= 0 : !1;
  }
  function Mt() {
    P();
    var M = b.props, U = M.popperOptions, ne = M.placement, be = M.offset, pe = M.getReferenceClientRect, Ye = M.moveTransition, gt = j() ? pa(w).arrow : null, Gn = pe ? {
      getBoundingClientRect: pe,
      contextElement: pe.contextElement || J()
    } : t, _l = {
      name: "$$tippy",
      enabled: !0,
      phase: "beforeWrite",
      requires: ["computeStyles"],
      fn: function(xi) {
        var jn = xi.state;
        if (j()) {
          var ch = re(), to = ch.box;
          ["placement", "reference-hidden", "escaped"].forEach(function(Si) {
            Si === "placement" ? to.setAttribute("data-placement", jn.placement) : jn.attributes.popper["data-popper-" + Si] ? to.setAttribute("data-" + Si, "") : to.removeAttribute("data-" + Si);
          }), jn.attributes.popper = {};
        }
      }
    }, xn = [{
      name: "offset",
      options: {
        offset: be
      }
    }, {
      name: "preventOverflow",
      options: {
        padding: {
          top: 2,
          bottom: 2,
          left: 5,
          right: 5
        }
      }
    }, {
      name: "flip",
      options: {
        padding: 5
      }
    }, {
      name: "computeStyles",
      options: {
        adaptive: !Ye
      }
    }, _l];
    j() && gt && xn.push({
      name: "arrow",
      options: {
        element: gt,
        padding: 3
      }
    }), xn.push.apply(xn, (U == null ? void 0 : U.modifiers) || []), b.popperInstance = cy(Gn, w, Object.assign({}, U, {
      placement: ne,
      onFirstUpdate: f,
      modifiers: xn
    }));
  }
  function P() {
    b.popperInstance && (b.popperInstance.destroy(), b.popperInstance = null);
  }
  function ae() {
    var M = b.props.appendTo, U, ne = J();
    b.props.interactive && M === zf || M === "parent" ? U = ne.parentNode : U = Ff(M, [ne]), U.contains(w) || U.appendChild(w), b.state.isMounted = !0, Mt(), {}.NODE_ENV !== "production" && Zt(b.props.interactive && M === ft.appendTo && ne.nextElementSibling !== w, ["Interactive tippy element may not be accessible via keyboard", "navigation because it is not directly after the reference element", "in the DOM source order.", `

`, "Using a wrapper <div> or <span> tag around the reference element", "solves this by creating a new parentNode context.", `

`, "Specifying `appendTo: document.body` silences this warning, but it", "assumes you are using a focus management solution to handle", "keyboard navigation.", `

`, "See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity"].join(" "));
  }
  function he() {
    return ps(w.querySelectorAll("[data-tippy-root]"));
  }
  function oe(M) {
    b.clearDelayTimeouts(), M && S("onTrigger", [b, M]), le();
    var U = T(!0), ne = $(), be = ne[0], pe = ne[1];
    It.isTouch && be === "hold" && pe && (U = pe), U ? r = setTimeout(function() {
      b.show();
    }, U) : b.show();
  }
  function Ue(M) {
    if (b.clearDelayTimeouts(), S("onUntrigger", [b, M]), !b.state.isVisible) {
      Ee();
      return;
    }
    if (!(b.props.trigger.indexOf("mouseenter") >= 0 && b.props.trigger.indexOf("click") >= 0 && ["mouseleave", "mousemove"].indexOf(M.type) >= 0 && o)) {
      var U = T(!1);
      U ? i = setTimeout(function() {
        b.state.isVisible && b.hide();
      }, U) : s = requestAnimationFrame(function() {
        b.hide();
      });
    }
  }
  function $e() {
    b.state.isEnabled = !0;
  }
  function H() {
    b.hide(), b.state.isEnabled = !1;
  }
  function V() {
    clearTimeout(r), clearTimeout(i), cancelAnimationFrame(s);
  }
  function N(M) {
    if ({}.NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("setProps")), !b.state.isDestroyed) {
      S("onBeforeUpdate", [b, M]), ct();
      var U = b.props, ne = Gc(t, Object.assign({}, U, Uc(M), {
        ignoreAttributes: !0
      }));
      b.props = ne, mt(), U.interactiveDebounce !== ne.interactiveDebounce && (F(), h = zc(ke, ne.interactiveDebounce)), U.triggerTarget && !ne.triggerTarget ? ir(U.triggerTarget).forEach(function(be) {
        be.removeAttribute("aria-expanded");
      }) : ne.triggerTarget && t.removeAttribute("aria-expanded"), D(), x(), _ && _(U, ne), b.popperInstance && (Mt(), he().forEach(function(be) {
        requestAnimationFrame(be._tippy.popperInstance.forceUpdate);
      })), S("onAfterUpdate", [b, M]);
    }
  }
  function L(M) {
    b.setProps({
      content: M
    });
  }
  function K() {
    ({}).NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("show"));
    var M = b.state.isVisible, U = b.state.isDestroyed, ne = !b.state.isEnabled, be = It.isTouch && !b.props.touch, pe = Co(b.props.duration, 0, ft.duration);
    if (!(M || U || ne || be) && !J().hasAttribute("disabled") && (S("onShow", [b], !1), b.props.onShow(b) !== !1)) {
      if (b.state.isVisible = !0, j() && (w.style.visibility = "visible"), x(), le(), b.state.isMounted || (w.style.transition = "none"), j()) {
        var Ye = re(), gt = Ye.box, Gn = Ye.content;
        Mo([gt, Gn], 0);
      }
      f = function() {
        var xn;
        if (!(!b.state.isVisible || c)) {
          if (c = !0, w.offsetHeight, w.style.transition = b.props.moveTransition, j() && b.props.animation) {
            var eo = re(), xi = eo.box, jn = eo.content;
            Mo([xi, jn], pe), Kc([xi, jn], "visible");
          }
          O(), D(), Fc(To, b), (xn = b.popperInstance) == null || xn.forceUpdate(), S("onMount", [b]), b.props.animation && j() && Pe(pe, function() {
            b.state.isShown = !0, S("onShown", [b]);
          });
        }
      }, ae();
    }
  }
  function se() {
    ({}).NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("hide"));
    var M = !b.state.isVisible, U = b.state.isDestroyed, ne = !b.state.isEnabled, be = Co(b.props.duration, 1, ft.duration);
    if (!(M || U || ne) && (S("onHide", [b], !1), b.props.onHide(b) !== !1)) {
      if (b.state.isVisible = !1, b.state.isShown = !1, c = !1, o = !1, j() && (w.style.visibility = "hidden"), F(), Ee(), x(!0), j()) {
        var pe = re(), Ye = pe.box, gt = pe.content;
        b.props.animation && (Mo([Ye, gt], be), Kc([Ye, gt], "hidden"));
      }
      O(), D(), b.props.animation ? j() && tt(be, b.unmount) : b.unmount();
    }
  }
  function Oe(M) {
    ({}).NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("hideWithInteractivity")), X().addEventListener("mousemove", h), Fc(_i, h), h(M);
  }
  function dt() {
    ({}).NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("unmount")), b.state.isVisible && b.hide(), b.state.isMounted && (P(), he().forEach(function(M) {
      M._tippy.unmount();
    }), w.parentNode && w.parentNode.removeChild(w), To = To.filter(function(M) {
      return M !== b;
    }), b.state.isMounted = !1, S("onHidden", [b]));
  }
  function Qs() {
    ({}).NODE_ENV !== "production" && Zt(b.state.isDestroyed, Xn("destroy")), !b.state.isDestroyed && (b.clearDelayTimeouts(), b.unmount(), ct(), delete t._tippy, b.state.isDestroyed = !0, S("onDestroy", [b]));
  }
}
function ht(t, e) {
  e === void 0 && (e = {});
  var n = ft.plugins.concat(e.plugins || []);
  ({}).NODE_ENV !== "production" && (Ay(t), Zf(e, n)), My();
  var r = Object.assign({}, e, {
    plugins: n
  }), i = wy(t);
  if ({}.NODE_ENV !== "production") {
    var s = oi(r.content), o = i.length > 1;
    Zt(s && o, ["tippy() was passed an Element as the `content` prop, but more than", "one tippy instance was created by this invocation. This means the", "content element will only be appended to the last tippy instance.", `

`, "Instead, pass the .innerHTML of the element, or use a function that", "returns a cloned version of the element instead.", `

`, `1) content: element.innerHTML
`, "2) content: () => element.cloneNode(true)"].join(" "));
  }
  var a = i.reduce(function(l, c) {
    var d = c && By(c, r);
    return d && l.push(d), l;
  }, []);
  return oi(t) ? a[0] : a;
}
ht.defaultProps = ft;
ht.setDefaultProps = Ly;
ht.currentInput = It;
Object.assign({}, Af, {
  effect: function(e) {
    var n = e.state, r = {
      popper: {
        position: n.options.strategy,
        left: "0",
        top: "0",
        margin: "0"
      },
      arrow: {
        position: "absolute"
      },
      reference: {}
    };
    Object.assign(n.elements.popper.style, r.popper), n.styles = r, n.elements.arrow && Object.assign(n.elements.arrow.style, r.arrow);
  }
});
ht.setDefaultProps({
  render: Gf
});
class Or extends me {
  constructor() {
    super(...arguments);
    q(this, "tippyInstance");
    q(this, "tippyEl");
    q(this, "textEl");
    q(this, "menuData", []);
    q(this, "menuTextWidth", "40px");
    q(this, "defaultMenuIndex", 0);
    q(this, "refreshMenuText", !0);
    q(this, "width", "48px");
    q(this, "dropDivWith", "100px");
    q(this, "dropDivHeight", "260px");
  }
  renderTemplate() {
    this.template = `
         <div style="width: ${this.width};">
         <div style="display: flex" id="tippy">
             <span style="line-height: 18px;font-size: 14px;text-align:center;overflow: hidden; width: ${this.menuTextWidth}" id="text">
                ${this.onMenuTextRender(this.defaultMenuIndex)}
             </span>
             <div style="width: 18px;height: 18px;display: inline-block">
<!--                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 16L6 10H18L12 16Z"></path></svg>-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 14L8 10H16L12 14Z"></path></svg>
             </div>
         </div>
         </div>
        `;
  }
  connectedCallback() {
    this.renderTemplate(), super.connectedCallback(), this.textEl = this.querySelector("#text"), this.tippyInstance = ht(this.querySelector("#tippy"), {
      content: this.createMenuElement(),
      appendTo: this.closest(".aie-container"),
      placement: "bottom",
      trigger: "click",
      interactive: !0,
      arrow: !1
    });
  }
  createMenuElement() {
    const n = document.createElement("div");
    n.style.height = this.dropDivHeight, n.style.width = this.dropDivWith, n.classList.add("aie-dropdown-container");
    for (let r = 0; r < this.menuData.length; r++) {
      const i = document.createElement("div");
      i.classList.add("aie-dropdown-item"), i.innerHTML = `
            <div class="red-dot-container" id="item${r}"><div class="${r == 0 ? "red-dot" : ""}"></div></div>
            <div class="text">${this.onDropdownItemRender(r)}</div>
            `, i.addEventListener("click", () => {
        this.onDropdownItemClick(r), this.tippyInstance.hide();
      }), n.appendChild(i);
    }
    return this.tippyEl = n, n;
  }
  onTransaction(n) {
    var i, s, o;
    const r = this.tippyEl.querySelector(".red-dot");
    r && r.classList.remove("red-dot");
    for (let a = 0; a < this.menuData.length; a++)
      if (this.onDropdownActive(n.editor, a) && (this.tippyEl.querySelector(`#item${a}`).children[0].classList.add("red-dot"), this.refreshMenuText)) {
        const l = this.onMenuTextRender(a);
        typeof l == "string" ? this.textEl.innerHTML = l : ((s = this.textEl) == null || s.removeChild((i = this.textEl) == null ? void 0 : i.firstChild), (o = this.textEl) == null || o.appendChild(l));
      }
  }
}
const Py = ["正文", "标题 1", "标题 2", "标题 3", "标题 4", "标题 5", "标题 6"];
class $y extends Or {
  constructor() {
    super(), this.menuData = Py, this.dropDivHeight = "265px", this.dropDivWith = "150px";
  }
  onDropdownActive(e, n) {
    return n == 0 ? e.isActive("paragraph") : e.isActive("heading", { level: n });
  }
  onDropdownItemClick(e) {
    e == 0 ? this.editor.chain().setParagraph().run() : this.editor.chain().setHeading({ level: e }).run();
  }
  onDropdownItemRender(e) {
    return e == 0 ? this.menuData[e] : `<h${e}>${this.menuData[e]}</h${e}>`;
  }
  onMenuTextRender(e) {
    return this.menuData[e];
  }
}
const Vy = [
  { name: "默认字体", value: "" },
  { name: "宋体", value: "SimSun" },
  { name: "仿宋", value: "FangSong" },
  { name: "黑体", value: "SimHei" },
  { name: "楷体", value: "KaiTi" },
  { name: "微软雅黑", value: "Microsoft YaHei" },
  { name: "方正仿宋简体_GBK", value: "FangSong_GB2312" },
  { name: "Arial", value: "Arial" }
];
let zy = class extends Or {
  constructor() {
    super(), this.width = "80px", this.menuTextWidth = "60px", this.dropDivWith = "150px";
  }
  onCreate(e, n) {
    var r;
    super.onCreate(e, n), this.menuData = ((r = n.fontFamily) == null ? void 0 : r.values) || Vy;
  }
  onDropdownActive(e, n) {
    return e.isActive("textStyle", { fontFamily: this.menuData[n].value });
  }
  onDropdownItemClick(e) {
    this.editor.chain().setFontFamily(this.menuData[e].value).run();
  }
  onDropdownItemRender(e) {
    return this.menuData[e].name;
  }
  onMenuTextRender(e) {
    return this.menuData[e].name;
  }
};
const Fy = [
  { name: "初号", value: 56 },
  { name: "小初", value: 48 },
  { name: "一号", value: 34.7 },
  { name: "小一", value: 32 },
  { name: "二号", value: 29.3 },
  { name: "小二", value: 24 },
  { name: "三号", value: 21.3 },
  { name: "小三", value: 20 },
  { name: "四号", value: 18.7 },
  { name: "小四", value: 16 },
  { name: "五号", value: 14 },
  { name: "小五", value: 12 },
  { name: "9", value: 9 },
  { name: "10", value: 10 },
  { name: "11", value: 11 },
  { name: "12", value: 12 },
  { name: "14", value: 14 },
  { name: "18", value: 18 },
  { name: "20", value: 20 },
  { name: "22", value: 22 },
  { name: "24", value: 24 },
  { name: "26", value: 26 },
  { name: "28", value: 28 },
  { name: "30", value: 30 },
  { name: "36", value: 36 },
  { name: "42", value: 42 },
  { name: "48", value: 48 },
  { name: "56", value: 56 },
  { name: "72", value: 72 }
];
class Uy extends Or {
  constructor() {
    super();
  }
  onCreate(e, n) {
    var r;
    super.onCreate(e, n), this.menuData = ((r = n.fontSize) == null ? void 0 : r.values) || Fy;
  }
  onDropdownActive(e, n) {
    return e.isActive("textStyle", { fontSize: `${this.menuData[n].value}px` });
  }
  onDropdownItemClick(e) {
    var n;
    (n = this.editor) == null || n.chain().focus().setFontSize(`${this.menuData[e].value}px`).run();
  }
  onDropdownItemRender(e) {
    return this.menuData[e].name;
  }
  onMenuTextRender(e) {
    return this.menuData[e].name;
  }
}
let Ky = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 11H12.5C13.8807 11 15 9.88071 15 8.5C15 7.11929 13.8807 6 12.5 6H8V11ZM18 15.5C18 17.9853 15.9853 20 13.5 20H6V4H12.5C14.9853 4 17 6.01472 17 8.5C17 9.70431 16.5269 10.7981 15.7564 11.6058C17.0979 12.3847 18 13.837 18 15.5ZM8 13V18H13.5C14.8807 18 16 16.8807 16 15.5C16 14.1193 14.8807 13 13.5 13H8Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleBold();
  }
  onActive(e) {
    return e.isActive("bold");
  }
}, Wy = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15 20H7V18H9.92661L12.0425 6H9V4H17V6H14.0734L11.9575 18H15V20Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleItalic();
  }
  onActive(e) {
    return e.isActive("italic");
  }
}, qy = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 3V12C8 14.2091 9.79086 16 12 16C14.2091 16 16 14.2091 16 12V3H18V12C18 15.3137 15.3137 18 12 18C8.68629 18 6 15.3137 6 12V3H8ZM4 20H20V22H4V20Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleUnderline();
  }
  onActive(e) {
    return e.isActive("underline");
  }
}, Zy = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17.1538 14C17.3846 14.5161 17.5 15.0893 17.5 15.7196C17.5 17.0625 16.9762 18.1116 15.9286 18.867C14.8809 19.6223 13.4335 20 11.5862 20C9.94674 20 8.32335 19.6185 6.71592 18.8555V16.6009C8.23538 17.4783 9.7908 17.917 11.3822 17.917C13.9333 17.917 15.2128 17.1846 15.2208 15.7196C15.2208 15.0939 15.0049 14.5598 14.5731 14.1173C14.5339 14.0772 14.4939 14.0381 14.4531 14H3V12H21V14H17.1538ZM13.076 11H7.62908C7.4566 10.8433 7.29616 10.6692 7.14776 10.4778C6.71592 9.92084 6.5 9.24559 6.5 8.45207C6.5 7.21602 6.96583 6.165 7.89749 5.299C8.82916 4.43299 10.2706 4 12.2219 4C13.6934 4 15.1009 4.32808 16.4444 4.98426V7.13591C15.2448 6.44921 13.9293 6.10587 12.4978 6.10587C10.0187 6.10587 8.77917 6.88793 8.77917 8.45207C8.77917 8.87172 8.99709 9.23796 9.43293 9.55079C9.86878 9.86362 10.4066 10.1135 11.0463 10.3004C11.6665 10.4816 12.3431 10.7148 13.076 11H13.076Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleStrike();
  }
  onActive(e) {
    return e.isActive("strike");
  }
}, Gy = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5.59567 4L10.5 9.92831L15.4043 4H18L11.7978 11.4971L18 18.9943V19H15.4091L10.5 13.0659L5.59092 19H3V18.9943L9.20216 11.4971L3 4H5.59567ZM21.8 16C21.8 15.5582 21.4418 15.2 21 15.2C20.5582 15.2 20.2 15.5582 20.2 16C20.2 16.0762 20.2107 16.15 20.2306 16.2198L19.0765 16.5496C19.0267 16.375 19 16.1906 19 16C19 14.8954 19.8954 14 21 14C22.1046 14 23 14.8954 23 16C23 16.5727 22.7593 17.0892 22.3735 17.4538L20.7441 19H23V20H19V19L21.5507 16.5803C21.7042 16.4345 21.8 16.2284 21.8 16Z"></path></svg>
         </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleSubscript();
  }
  onActive(e) {
    return e.isActive("subscript");
  }
}, jy = class extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5.59567 5L10.5 10.9283L15.4043 5H18L11.7978 12.4971L18 19.9943V20H15.4091L10.5 14.0659L5.59092 20H3V19.9943L9.20216 12.4971L3 5H5.59567ZM21.5507 6.5803C21.7042 6.43453 21.8 6.22845 21.8 6C21.8 5.55817 21.4418 5.2 21 5.2C20.5582 5.2 20.2 5.55817 20.2 6C20.2 6.07624 20.2107 6.14999 20.2306 6.21983L19.0765 6.54958C19.0267 6.37497 19 6.1906 19 6C19 4.89543 19.8954 4 21 4C22.1046 4 23 4.89543 23 6C23 6.57273 22.7593 7.08923 22.3735 7.45384L20.7441 9H23V10H19V9L21.5507 6.5803V6.5803Z"></path></svg>
         </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleSuperscript();
  }
  onActive(e) {
    return e.isActive("superscript");
  }
};
const Yy = [
  "ffffff",
  "000000",
  "e9d989",
  "2972f4",
  "609eec",
  "de3c36",
  "a1d533",
  "7334c5",
  "27b5d9",
  "ff8926",
  "f2f2f2",
  "7f7f7f",
  "ddd9c3",
  "c6d9f0",
  "dbe5f1",
  "f2dcdb",
  "ebf1dd",
  "e5e0ec",
  "dbeef3",
  "fdeada",
  "d8d8d8",
  "595959",
  "c4bd97",
  "8db3e2",
  "b8cce4",
  "e5b9b7",
  "d7e3bc",
  "ccc1d9",
  "b7dde8",
  "fbd5b5",
  "bfbfbf",
  "3f3f3f",
  "938953",
  "548dd4",
  "95b3d7",
  "d99694",
  "c3d69b",
  "b2a2c7",
  "92cddc",
  "fac08f",
  "a5a5a5",
  "262626",
  "494429",
  "17365d",
  "366092",
  "953734",
  "76923c",
  "5f497a",
  "31859b",
  "e36c09",
  "6e6e6e",
  "0c0c0c",
  "1d1b10",
  "0f243e",
  "244061",
  "632423",
  "4f6128",
  "3f3151",
  "205867",
  "974806"
], Jy = ["c00000", "ff0000", "ffc000", "ffff00", "92d050", "00b050", "00b0f0", "0070c0", "002060", "7030a0"];
class jf extends me {
  constructor() {
    super();
    q(this, "historyColors", []);
    q(this, "iconSvg");
    q(this, "menuColorEL");
    q(this, "onColorItemClick");
    q(this, "onDefaultColorClick");
  }
  connectedCallback() {
    this.template = `
            <div style="width: 36px;height: 18px;display: flex">
                <div style="width: 18px;height: 18px" id="btn">
                    <div style="height: 15px;width: 15px;padding:0 1.5px;line-height: 18px">
                    ${this.iconSvg}
                    </div>
                    <div style="width: 18px;height: 3px;background: #333" id="menuColorEL"></div>
                </div>
                <div style="width: 18px;height: 18px" id="dropdown">
<!--                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 16L6 10H18L12 16Z"></path></svg>-->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 14L8 10H16L12 14Z"></path></svg>
                </div>
            </div>
            `, super.connectedCallback(), this.querySelector("#btn").addEventListener("click", () => {
      this.onColorItemClick(this.historyColors.length > 0 ? this.historyColors[0] : "#ccc");
    }), this.menuColorEL = this.querySelector("#menuColorEL"), ht(this.querySelector("#dropdown"), {
      content: this.createMenuElement(),
      placement: "bottom",
      trigger: "click",
      interactive: !0
    });
  }
  createMenuElement() {
    const n = document.createElement("div");
    return n.style.height = "278px", n.style.width = "250px", n.classList.add("aie-dropdown-container"), n.innerHTML = `
        <div class="color-panel">
            <div class="color-panel-default-button" id="defaultColor">默认</div>
            <div style="display: flex;flex-wrap: wrap;padding-top: 5px">
                ${Yy.map((r, i) => `<div class="color-item" data-color="#${r}" style="width: 18px;height:18px;margin:1px;padding:1px;border:1px solid #${i == 0 ? "efefef" : r};background: #${r}"></div>`).join(" ")}
            </div>
            <div class="color-panel-title">标准色</div>
            <div style="display: flex;flex-wrap: wrap;">
                ${Jy.map((r) => `<div class="color-item" data-color="#${r}" style="width: 18px;height:18px;margin:1px;padding:1px;border:1px solid #${r};background: #${r}"></div>`).join(" ")}
            </div>
            <div class="color-panel-title">最近使用</div>
            <div style="display: flex;flex-wrap: wrap;" id="history-colors">
            </div>
        </div>
        `, n.querySelector("#defaultColor").addEventListener("click", () => {
      this.onDefaultColorClick();
    }), n.querySelectorAll(".color-item").forEach((r) => {
      r.addEventListener("click", () => {
        const i = r.getAttribute("data-color");
        this.historyColors.unshift(i), this.historyColors.length > 7 && (this.historyColors = this.historyColors.slice(0, 7)), n.querySelector("#history-colors").innerHTML = `
                ${this.historyColors.map((s) => `<div class="history-color-item" data-color="${s}" style="width: 22px;height: 23px;margin: 1px;background: ${s}"></div>`).join(" ")}
                `, this.menuColorEL.style.background = i, this.onColorItemClick(i);
      }), r.addEventListener("mouseover", () => {
        r.style.border = "solid 1px #999";
      }), r.addEventListener("mouseout", () => {
        let i = r.getAttribute("data-color");
        i === "#ffffff" && (i = "#efefef"), r.style.border = `solid 1px ${i}`;
      });
    }), n.querySelector("#history-colors").addEventListener("click", (r) => {
      const i = r.target.closest(".history-color-item");
      if (i) {
        let s = i.getAttribute("data-color");
        this.menuColorEL.style.background = s, this.onColorItemClick(s);
      }
    }), n;
  }
}
let Xy = class extends jf {
  constructor() {
    super(), this.iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.2427 4.51138L8.50547 11.2486L7.79836 13.3699L6.7574 14.4109L9.58583 17.2393L10.6268 16.1983L12.7481 15.4912L19.4853 8.75402L15.2427 4.51138ZM21.6066 8.04692C21.9972 8.43744 21.9972 9.0706 21.6066 9.46113L13.8285 17.2393L11.7071 17.9464L10.2929 19.3606C9.90241 19.7511 9.26925 19.7511 8.87872 19.3606L4.63608 15.118C4.24556 14.7275 4.24556 14.0943 4.63608 13.7038L6.0503 12.2896L6.7574 10.1682L14.5356 2.39006C14.9261 1.99954 15.5593 1.99954 15.9498 2.39006L21.6066 8.04692ZM15.2427 7.33981L16.6569 8.75402L11.7071 13.7038L10.2929 12.2896L15.2427 7.33981ZM4.28253 16.8858L7.11096 19.7142L5.69674 21.1284L1.4541 19.7142L4.28253 16.8858Z"></path></svg>', this.onDefaultColorClick = () => {
      var e;
      (e = this.editor) == null || e.chain().focus().unsetHighlight().run();
    }, this.onColorItemClick = (e) => {
      var n;
      (n = this.editor) == null || n.chain().focus().setHighlight({ color: e }).run();
    };
  }
  onActive(e) {
    return e.isActive("highlight");
  }
};
class Qy extends jf {
  constructor() {
    super(), this.iconSvg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5.55446 22H3.40039L11.0004 3H13.0004L20.6004 22H18.4463L16.0463 16H7.95446L5.55446 22ZM8.75446 14H15.2463L12.0004 5.88517L8.75446 14Z"></path></svg>', this.onDefaultColorClick = () => {
      var e;
      (e = this.editor) == null || e.chain().focus().unsetColor().run();
    }, this.onColorItemClick = (e) => {
      var n;
      (n = this.editor) == null || n.chain().focus().setColor(e).run();
    };
  }
  onActive(e) {
    return e.isActive("textStyle");
  }
}
class ev extends me {
  constructor() {
    super();
    const e = `
        <div no-hover style="width: 1px;height: 20px; display: flex">
            <div class="aie-menu-divider" />
        </div>
        `;
    this.template = e;
  }
}
let tv = class extends me {
  constructor() {
    super();
    const e = `
        <div>
             <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 4H21V6H8V4ZM3 3.5H6V6.5H3V3.5ZM3 10.5H6V13.5H3V10.5ZM3 17.5H6V20.5H3V17.5ZM8 11H21V13H8V11ZM8 18H21V20H8V18Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleBulletList();
  }
  onActive(e) {
    return e.isActive("bulletList");
  }
}, nv = class extends me {
  constructor() {
    super();
    const e = `
        <div>
               <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 4H21V6H8V4ZM5 3V6H6V7H3V6H4V4H3V3H5ZM3 14V11.5H5V11H3V10H6V12.5H4V13H6V14H3ZM5 19.5H3V18.5H5V18H3V17H6V21H3V20H5V19.5ZM8 11H21V13H8V11ZM8 18H21V20H8V18Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleOrderedList();
  }
  onActive(e) {
    return e.isActive("orderedList");
  }
};
class rv extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM3 19H21V21H3V19ZM11 14H21V16H11V14ZM11 9H21V11H11V9ZM3 12.5L7 9V16L3 12.5Z"></path></svg>
         </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.outdent();
  }
}
class iv extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM3 19H21V21H3V19ZM11 14H21V16H11V14ZM11 9H21V11H11V9ZM7 12.5L3 16V9L7 12.5Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.indent();
  }
}
const sv = [
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM3 19H17V21H3V19ZM3 14H21V16H3V14ZM3 9H17V11H3V9Z"></path></svg></div>',
    title: "居左对齐",
    value: "left"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM5 19H19V21H5V19ZM3 14H21V16H3V14ZM5 9H19V11H5V9Z"></path></svg></div>',
    title: "居中对齐",
    value: "center"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM7 19H21V21H7V19ZM3 14H21V16H3V14ZM7 9H21V11H7V9Z"></path></svg></div>',
    title: "居右对齐",
    value: "right"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM3 19H21V21H3V19ZM3 14H21V16H3V14ZM3 9H21V11H3V9Z"></path></svg></div>',
    title: "两端对齐",
    value: "justify"
  }
];
class ov extends Or {
  constructor() {
    super(), this.menuData = sv, this.dropDivHeight = "112px", this.dropDivWith = "60px", this.width = "36px", this.menuTextWidth = "20px";
  }
  onDropdownActive(e, n) {
    return e.isActive({ textAlign: this.menuData[n].value });
  }
  onDropdownItemClick(e) {
    this.editor.chain().focus().setTextAlign(this.menuData[e].value).run();
  }
  onDropdownItemRender(e) {
    return this.menuData[e].icon;
  }
  onMenuTextRender(e) {
    return this.menuData[e].icon;
  }
}
class Yf {
  constructor() {
    q(this, "tippyInstance");
    q(this, "content");
    q(this, "onConfirmClickFunc");
    q(this, "onShowFunc");
  }
  setContent(e) {
    this.content = e;
  }
  onConfirmClick(e) {
    this.onConfirmClickFunc = e;
  }
  onShow(e) {
    this.onShowFunc = e;
  }
  setTrigger(e, n = "bottom") {
    this.tippyInstance = ht(e, {
      content: this.createContentElement(),
      appendTo: e.closest(".aie-container"),
      placement: n,
      trigger: "click",
      interactive: !0,
      arrow: !1,
      onShow: (r) => {
        this.onShowFunc && this.onShowFunc(r);
      }
    });
  }
  createContentElement() {
    const e = `
            <div class="aie-popover">
              <div class="aie-popover-header">
               <svg class="aie-popover-header-close" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12.0007 10.5865L16.9504 5.63672L18.3646 7.05093L13.4149 12.0007L18.3646 16.9504L16.9504 18.3646L12.0007 13.4149L7.05093 18.3646L5.63672 16.9504L10.5865 12.0007L5.63672 7.05093L7.05093 5.63672L12.0007 10.5865Z"></path></svg>
              </div>
              <div class="aie-popover-content">${this.content}</div>
              <div class="aie-popover-footer">
              <button class="aie-popover-footer-confirm" type="button">确定</button>
              </div>
            </div>
        `, n = document.createElement("div");
    return n.innerHTML = e, n.querySelector(".aie-popover-header-close").addEventListener("click", () => {
      this.tippyInstance.hide();
    }), n.querySelector(".aie-popover-footer-confirm").addEventListener("click", () => {
      this.onConfirmClickFunc && this.onConfirmClickFunc(this.tippyInstance), this.tippyInstance.hide();
    }), n;
  }
}
let av = class extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17.6572 14.8282L16.2429 13.414L17.6572 11.9998C19.2193 10.4377 19.2193 7.90506 17.6572 6.34296C16.0951 4.78086 13.5624 4.78086 12.0003 6.34296L10.5861 7.75717L9.17188 6.34296L10.5861 4.92875C12.9292 2.5856 16.7282 2.5856 19.0714 4.92875C21.4145 7.27189 21.4145 11.0709 19.0714 13.414L17.6572 14.8282ZM14.8287 17.6567L13.4145 19.0709C11.0714 21.414 7.27238 21.414 4.92923 19.0709C2.58609 16.7277 2.58609 12.9287 4.92923 10.5856L6.34345 9.17139L7.75766 10.5856L6.34345 11.9998C4.78135 13.5619 4.78135 16.0946 6.34345 17.6567C7.90555 19.2188 10.4382 19.2188 12.0003 17.6567L13.4145 16.2425L14.8287 17.6567ZM14.8287 7.75717L16.2429 9.17139L9.17188 16.2425L7.75766 14.8282L14.8287 7.75717Z"></path></svg>
        </div>
        `;
    this.template = e;
  }
  connectedCallback() {
    super.connectedCallback();
    const e = new Yf();
    e.setContent(`
            <div style="width: 250px">
            链接地址
            </div>
             <div style="width: 250px">
             <input type="text" id="href" style="width: 240px">
            </div>
            
            <div style="margin-top: 10px">
            打开方式
            </div>
            <div>
            <select id="target" style="width: 250px">
                       <option value="">默认</option>
                       <option value="_blank">新窗口</option>
                    </select>
            </div>
        `), e.onConfirmClick((n) => {
      var s, o;
      const r = n.popper.querySelector("#href").value;
      if (r.trim() === "") {
        (s = this.editor) == null || s.chain().focus().extendMarkRange("link").unsetLink().run();
        return;
      }
      let i = n.popper.querySelector("#target").value;
      i.trim() === "" && (i = null), (o = this.editor) == null || o.chain().focus().extendMarkRange("link").setLink({
        href: r,
        target: i,
        rel: null
      }).run();
    }), e.onShow((n) => {
      var i;
      const r = (i = this.editor) == null ? void 0 : i.getAttributes("link");
      r && r.href ? n.popper.querySelector("#href").value = r.href : n.popper.querySelector("#href").value = "", r && r.target ? n.popper.querySelector("#target").value = r.target : n.popper.querySelector("#target").value = "";
    }), e.setTrigger(this.querySelector("div"), "bottom");
  }
};
class lv extends me {
  constructor() {
    super();
    const e = `
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3ZM5 5V19H19V5H5ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleTaskList();
  }
  onActive(e) {
    return e.isActive("taskList");
  }
}
const cv = ["1.0", "1.25", "1.5", "2.0", "2.5", "3.0"];
class dv extends Or {
  constructor() {
    super(), this.menuData = cv, this.refreshMenuText = !1, this.dropDivHeight = "180px", this.dropDivWith = "60px", this.width = "36px", this.menuTextWidth = "20px";
  }
  onDropdownActive(e, n) {
    return n == 0 ? e.isActive("paragraph") : e.isActive("heading", { level: n });
  }
  onDropdownItemClick(e) {
    const n = `${(Number(this.menuData[e]) * 100).toFixed(0)}%`;
    this.editor.chain().setLineHeight(n).run();
  }
  onDropdownItemRender(e) {
    return this.menuData[e];
  }
  onMenuTextRender(e) {
    return `
              <div style="width:18px;height: 18px;">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M11 4H21V6H11V4ZM6 7V11H4V7H1L5 3L9 7H6ZM6 17H9L5 21L1 17H4V13H6V17ZM11 18H21V20H11V18ZM9 11H21V13H9V11Z"></path></svg>
              </div>
         `;
  }
}
class uv extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4.58341 17.3211C3.55316 16.2275 3 15 3 13.0104C3 9.51092 5.45651 6.37372 9.03059 4.82324L9.92328 6.20085C6.58804 8.00545 5.93618 10.3461 5.67564 11.8221C6.21263 11.5444 6.91558 11.4467 7.60471 11.5106C9.40908 11.6778 10.8312 13.1591 10.8312 15C10.8312 16.933 9.26416 18.5 7.33116 18.5C6.2581 18.5 5.23196 18.0096 4.58341 17.3211ZM14.5834 17.3211C13.5532 16.2275 13 15 13 13.0104C13 9.51092 15.4565 6.37372 19.0306 4.82324L19.9233 6.20085C16.588 8.00545 15.9362 10.3461 15.6756 11.8221C16.2126 11.5444 16.9156 11.4467 17.6047 11.5106C19.4091 11.6778 20.8312 13.1591 20.8312 15C20.8312 16.933 19.2642 18.5 17.3312 18.5C16.2581 18.5 15.232 18.0096 14.5834 17.3211Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleBlockquote();
  }
}
let fv = class extends me {
  constructor() {
    super();
    q(this, "fileInput");
    const n = `
        <div>
        <input type="file" accept="image/*"  style="display: none">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2.9918 21C2.44405 21 2 20.5551 2 20.0066V3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918ZM20 15V5H4V19L14 9L20 15ZM20 17.8284L14 11.8284L6.82843 19H20V17.8284ZM8 11C6.89543 11 6 10.1046 6 9C6 7.89543 6.89543 7 8 7C9.10457 7 10 7.89543 10 9C10 10.1046 9.10457 11 8 11Z"></path></svg>
        </div>
        `;
    this.template = n, this.registerClickListener();
  }
  connectedCallback() {
    var n, r;
    super.connectedCallback(), (r = (n = this.options) == null ? void 0 : n.image) != null && r.customMenuInvoke ? this.querySelector("input").remove() : (this.fileInput = this.querySelector("input"), this.fileInput.addEventListener("change", () => {
      var s, o;
      const i = (s = this.fileInput) == null ? void 0 : s.files;
      if (i && i.length > 0)
        for (let a of i)
          (o = this.editor) == null || o.commands.uploadImage(a);
      this.fileInput.value = "";
    }));
  }
  // @ts-ignore
  onClick(n) {
    var r, i, s;
    (i = (r = this.options) == null ? void 0 : r.image) != null && i.customMenuInvoke ? this.options.image.customMenuInvoke(this.editor) : (s = this.fileInput) == null || s.click();
  }
};
class pv extends me {
  constructor() {
    super();
    q(this, "fileInput");
    const n = `
        <div>
        <input type="file" accept="video/*" style="display: none">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 3.9934C3 3.44476 3.44495 3 3.9934 3H20.0066C20.5552 3 21 3.44495 21 3.9934V20.0066C21 20.5552 20.5551 21 20.0066 21H3.9934C3.44476 21 3 20.5551 3 20.0066V3.9934ZM5 5V19H19V5H5ZM10.6219 8.41459L15.5008 11.6672C15.6846 11.7897 15.7343 12.0381 15.6117 12.2219C15.5824 12.2658 15.5447 12.3035 15.5008 12.3328L10.6219 15.5854C10.4381 15.708 10.1897 15.6583 10.0672 15.4745C10.0234 15.4088 10 15.3316 10 15.2526V8.74741C10 8.52649 10.1791 8.34741 10.4 8.34741C10.479 8.34741 10.5562 8.37078 10.6219 8.41459Z"></path></svg>
        </div>
        `;
    this.template = n, this.registerClickListener();
  }
  connectedCallback() {
    var n, r;
    super.connectedCallback(), (r = (n = this.options) == null ? void 0 : n.video) != null && r.customMenuInvoke ? this.querySelector("input").remove() : (this.fileInput = this.querySelector("input"), this.fileInput.addEventListener("change", () => {
      var s, o;
      const i = (s = this.fileInput) == null ? void 0 : s.files;
      if (i && i.length > 0)
        for (let a of i)
          (o = this.editor) == null || o.commands.uploadVideo(a);
      this.fileInput.value = "";
    }));
  }
  // @ts-ignore
  onClick(n) {
    var r, i, s;
    (i = (r = this.options) == null ? void 0 : r.video) != null && i.customMenuInvoke ? this.options.video.customMenuInvoke(this.editor) : (s = this.fileInput) == null || s.click();
  }
}
let hv = class extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M23 11.9998L15.9289 19.0708L14.5147 17.6566L20.1716 11.9998L14.5147 6.34292L15.9289 4.92871L23 11.9998ZM3.82843 11.9998L9.48528 17.6566L8.07107 19.0708L1 11.9998L8.07107 4.92871L9.48528 6.34292L3.82843 11.9998Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleCode();
  }
  onActive(e) {
    return e.isActive("code");
  }
}, mv = class extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3ZM4 5V19H20V5H4ZM20 12L16.4645 15.5355L15.0503 14.1213L17.1716 12L15.0503 9.87868L16.4645 8.46447L20 12ZM6.82843 12L8.94975 14.1213L7.53553 15.5355L4 12L7.53553 8.46447L8.94975 9.87868L6.82843 12ZM11.2443 17H9.11597L12.7557 7H14.884L11.2443 17Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.toggleCodeBlock();
  }
  onActive(e) {
    return e.isActive("codeBlock");
  }
};
class gv extends me {
  constructor() {
    super();
    const e = `
        <div style="height: 16px">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13.9999 18.9967H20.9999V20.9967H11.9999L8.00229 20.9992L1.51457 14.5115C1.12405 14.1209 1.12405 13.4878 1.51457 13.0972L12.1212 2.49065C12.5117 2.10012 13.1449 2.10012 13.5354 2.49065L21.3136 10.2688C21.7041 10.6593 21.7041 11.2925 21.3136 11.683L13.9999 18.9967ZM15.6567 14.5115L19.1922 10.9759L12.8283 4.61197L9.29275 8.1475L15.6567 14.5115Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.unsetAllMarks();
  }
}
class bv extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M2 11H4V13H2V11ZM6 11H18V13H6V11ZM20 11H22V13H20V11Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.setHorizontalRule();
  }
}
let yv = class extends me {
  constructor() {
    super();
    q(this, "instance");
    const n = `
        <div id="xxx">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14 10H10V14H14V10ZM16 10V14H19V10H16ZM14 19V16H10V19H14ZM16 19H19V16H16V19ZM14 5H10V8H14V5ZM16 5V8H19V5H16ZM8 10H5V14H8V10ZM8 19V16H5V19H8ZM8 5H5V8H8V5ZM4 3H20C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3Z"></path></svg>
        </div>
        `;
    this.template = n;
  }
  connectedCallback() {
    super.connectedCallback(), this.instance = ht(this.querySelector("#xxx"), {
      content: this.createMenuElement(),
      appendTo: this.closest(".aie-container"),
      placement: "bottom",
      trigger: "click",
      interactive: !0
    });
  }
  createMenuElement() {
    const n = document.createElement("div");
    n.style.height = "250px", n.style.width = "250px", n.style.background = "#fff", n.style.border = "1px solid #ccc", n.innerHTML = `
        <div style="margin: 5px">
            <div style="padding: 5px 0;font-size: 14px;color: #666">插入表格</div>
            <div style="display: flex;flex-wrap: wrap;width: 240px;height: 200px" id="table-cells">
            ${[...Array(8).keys()].map((i, s) => [...Array(10).keys()].map((o, a) => `<div data-i="${s}" data-j="${a}" class="table-cell" style="width: 20px;height: 20px;margin:1px;border: solid 1px #ccc"></div>`).join("")).join("")}
            </div>
        </div>
        `;
    const r = n.querySelector("#table-cells");
    return r.addEventListener("click", (i) => {
      var o, a;
      const s = i.target.closest(".table-cell");
      if (s) {
        let l = s.getAttribute("data-i"), c = s.getAttribute("data-j");
        (o = this.editor) == null || o.commands.insertTable({ rows: Number(l) + 1, cols: Number(c) + 1, withHeaderRow: !0 }), (a = this.instance) == null || a.hide();
      }
    }), r.addEventListener("mouseover", (i) => {
      const s = i.target.closest(".table-cell");
      if (s) {
        let o = Number(s.getAttribute("data-i")), a = Number(s.getAttribute("data-j"));
        r.querySelectorAll("div").forEach((c) => {
          let d = Number(c.getAttribute("data-i")), u = Number(c.getAttribute("data-j"));
          d <= o && u <= a ? c.style.border = "solid 1px #000" : c.style.border = "solid 1px #ccc";
        });
      }
    }), r.addEventListener("mouseleave", () => {
      r.querySelectorAll("div").forEach((s) => {
        s.style.border = "solid 1px #ccc";
      });
    }), n;
  }
};
class vv extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15 18H16.5C17.8807 18 19 16.8807 19 15.5C19 14.1193 17.8807 13 16.5 13H3V11H16.5C18.9853 11 21 13.0147 21 15.5C21 17.9853 18.9853 20 16.5 20H15V22L11 19L15 16V18ZM3 4H21V6H3V4ZM9 18V20H3V18H9Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    e.setHardBreak();
  }
}
class wv extends me {
  constructor() {
    super();
    q(this, "fileInput");
    const n = `
        <div>
        <input type="file" style="display: none">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M14.8287 7.7574L9.1718 13.4143C8.78127 13.8048 8.78127 14.4379 9.1718 14.8285C9.56232 15.219 10.1955 15.219 10.586 14.8285L16.2429 9.17161C17.4144 8.00004 17.4144 6.10055 16.2429 4.92897C15.0713 3.7574 13.1718 3.7574 12.0002 4.92897L6.34337 10.5858C4.39075 12.5384 4.39075 15.7043 6.34337 17.6569C8.29599 19.6095 11.4618 19.6095 13.4144 17.6569L19.0713 12L20.4855 13.4143L14.8287 19.0711C12.095 21.8048 7.66283 21.8048 4.92916 19.0711C2.19549 16.3374 2.19549 11.9053 4.92916 9.17161L10.586 3.51476C12.5386 1.56214 15.7045 1.56214 17.6571 3.51476C19.6097 5.46738 19.6097 8.63321 17.6571 10.5858L12.0002 16.2427C10.8287 17.4143 8.92916 17.4143 7.75759 16.2427C6.58601 15.0711 6.58601 13.1716 7.75759 12L13.4144 6.34319L14.8287 7.7574Z"></path></svg>
        </div>
        `;
    this.template = n, this.registerClickListener();
  }
  connectedCallback() {
    var n, r;
    super.connectedCallback(), (r = (n = this.options) == null ? void 0 : n.attachment) != null && r.customMenuInvoke ? this.querySelector("input").remove() : (this.fileInput = this.querySelector("input"), this.fileInput.addEventListener("change", () => {
      var s, o;
      const i = (s = this.fileInput) == null ? void 0 : s.files;
      if (i && i.length > 0)
        for (let a of i)
          (o = this.editor) == null || o.commands.uploadAttachment(a);
      this.fileInput.value = "";
    }));
  }
  // @ts-ignore
  onClick(n) {
    var r, i, s;
    (i = (r = this.options) == null ? void 0 : r.attachment) != null && i.customMenuInvoke ? this.options.attachment.customMenuInvoke(this.editor) : (s = this.fileInput) == null || s.click();
  }
}
class Ev extends me {
  constructor() {
    super();
    q(this, "fullscreenSvg", '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 3V5H4V9H2V3H8ZM2 21V15H4V19H8V21H2ZM22 21H16V19H20V15H22V21ZM22 9H20V5H16V3H22V9Z"></path></svg>');
    q(this, "fullscreenExitSvg", '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 7H22V9H16V3H18V7ZM8 9H2V7H6V3H8V9ZM18 17V21H16V15H22V17H18ZM8 15V21H6V17H2V15H8Z"></path></svg>');
    q(this, "isFullscreen", !1);
    const n = `
        <div>
        ${this.fullscreenSvg}
        </div>
        `;
    this.template = n, this.registerClickListener();
  }
  // @ts-ignore
  onClick(n) {
    const r = this.closest(".aie-container");
    this.isFullscreen ? (r.style.height = "100%", r.style.width = "", r.style.background = "", r.style.position = "", r.style.top = "", r.style.left = "", r.style.zIndex = "") : (r.style.height = "calc(100vh - 2px)", r.style.width = "calc(100% - 2px)", r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.zIndex = "9999"), this.isFullscreen = !this.isFullscreen, this.querySelector("div").innerHTML = this.isFullscreen ? this.fullscreenExitSvg : this.fullscreenSvg;
  }
}
class xv extends me {
  constructor() {
    super();
    const e = `
        <div>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 2C17.5523 2 18 2.44772 18 3V7H21C21.5523 7 22 7.44772 22 8V18C22 18.5523 21.5523 19 21 19H18V21C18 21.5523 17.5523 22 17 22H7C6.44772 22 6 21.5523 6 21V19H3C2.44772 19 2 18.5523 2 18V8C2 7.44772 2.44772 7 3 7H6V3C6 2.44772 6.44772 2 7 2H17ZM16 17H8V20H16V17ZM20 9H4V17H6V16C6 15.4477 6.44772 15 7 15H17C17.5523 15 18 15.4477 18 16V17H20V9ZM8 10V12H5V10H8ZM16 4H8V7H16V4Z"></path></svg>
        </div>
        `;
    this.template = e, this.registerClickListener();
  }
  // @ts-ignore
  onClick(e) {
    const n = this.closest(".aie-container").querySelector(".aie-content").innerHTML, i = Array.from(document.querySelectorAll("style, link")).map((l) => l.outerHTML).join("") + n, s = document.createElement("iframe");
    s.id = "aie-print-iframe", s.setAttribute("style", "position: absolute; width: 0; height: 0; top: -10px; left: -10px;"), document.body.appendChild(s);
    const o = s.contentWindow, a = s.contentDocument || s.contentWindow && s.contentWindow.document;
    a && (a.open(), a.write(i), a.close()), o && (s.onload = function() {
      try {
        setTimeout(() => {
          o.focus();
          try {
            o.document.execCommand("print", !1) || o.print();
          } catch {
            o.print();
          }
          o.close();
        }, 10);
      } catch (l) {
        console.error(l);
      }
      setTimeout(function() {
        document.body.removeChild(s);
      }, 100);
    });
  }
}
const Sv = [
  "😀",
  "😃",
  "😄",
  "😁",
  "😆",
  "😅",
  "🤣",
  "😂",
  "🙂",
  "🙃",
  "😉",
  "😊",
  "😇",
  "🥰",
  "😍",
  "🤩",
  "😘",
  "😗",
  "😚",
  "😙",
  "🥲",
  "😋",
  "😛",
  "😜",
  "🤪",
  "😝",
  "🤑",
  "🤗",
  "🤭",
  "🤫",
  "🤔",
  "🤐",
  "🤨",
  "😐",
  "😑",
  "😶",
  "😶‍🌫",
  "😏",
  "😒",
  "🙄",
  "😬",
  "😮‍💨",
  "🤥",
  "😌",
  "😔",
  "😪",
  "🤤",
  "😴",
  "😷",
  "🤒",
  "🤕",
  "🤢",
  "🤮",
  "🤧",
  "🥵",
  "🥶",
  "🥴",
  "😵",
  "😵‍💫",
  "🤯",
  "🤠",
  "🥳",
  "🥸",
  "😎",
  "🤓",
  "🧐",
  "😕",
  "😟",
  "🙁",
  "😮",
  "😲",
  "😳",
  "🥺",
  "😦",
  "😧",
  "😨",
  "😰",
  "😥",
  "😢",
  "😭",
  "😱",
  "😖",
  "😣",
  "😞",
  "😓",
  "😩",
  "😫",
  "🥱",
  "😤",
  "😡",
  "😠",
  "🤬",
  "😈",
  "👿",
  "💀",
  "☠️",
  "💩",
  "🤡",
  "👹",
  "👺",
  "👻",
  "👽",
  "👾",
  "🤖",
  "😺",
  "😸",
  "😹",
  "😻",
  "😼",
  "😽",
  "🙀",
  "😿",
  "😾",
  "🙈",
  "🙉",
  "🙊",
  "💌",
  "💘",
  "💝",
  "💖",
  "💗",
  "💓",
  "💞",
  "💕",
  "💟",
  "❣️",
  "💔",
  "💋",
  "💯",
  "💢",
  "💥",
  "💫",
  "💦",
  "💨",
  "💤"
];
class Cv extends me {
  constructor() {
    super();
    const e = `
        <div id="xxx">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM8 13H16C16 15.2091 14.2091 17 12 17C9.79086 17 8 15.2091 8 13ZM8 11C7.17157 11 6.5 10.3284 6.5 9.5C6.5 8.67157 7.17157 8 8 8C8.82843 8 9.5 8.67157 9.5 9.5C9.5 10.3284 8.82843 11 8 11ZM16 11C15.1716 11 14.5 10.3284 14.5 9.5C14.5 8.67157 15.1716 8 16 8C16.8284 8 17.5 8.67157 17.5 9.5C17.5 10.3284 16.8284 11 16 11Z"></path></svg>
        </div>
        `;
    this.template = e;
  }
  connectedCallback() {
    super.connectedCallback(), ht(this.querySelector("#xxx"), {
      content: this.createMenuElement(),
      appendTo: this.closest(".aie-container"),
      placement: "bottom",
      trigger: "click",
      interactive: !0
    });
  }
  createMenuElement() {
    const e = document.createElement("div");
    return e.style.height = "220px", e.style.width = "400px", e.classList.add("aie-dropdown-container"), e.innerHTML = `
        <div style="margin: 5px">
            <div class="emoji-cells">
            ${Sv.map((n) => `<div  class="emoji-cell">${n}</div>`).join("")}
            </div>
        </div>
        `, e.querySelector(".emoji-cells").addEventListener("click", (n) => {
      var i;
      const r = n.target.closest(".emoji-cell");
      r && ((i = this.editor) == null || i.commands.insertContent(r.innerHTML));
    }), e;
  }
}
class Mv extends me {
  constructor() {
    super();
    q(this, "svg", '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 4.99658V7.99658H19V4.99658H5ZM4 2.99658H20C20.5523 2.99658 21 3.4443 21 3.99658V8.99658C21 9.54887 20.5523 9.99658 20 9.99658H4C3.44772 9.99658 3 9.54887 3 8.99658V3.99658C3 3.4443 3.44772 2.99658 4 2.99658ZM6 11.9966H12C12.5523 11.9966 13 12.4443 13 12.9966V15.9966H14V21.9966H10V15.9966H11V13.9966H5C4.44772 13.9966 4 13.5489 4 12.9966V10.9966H6V11.9966ZM17.7322 13.7288L19.5 11.961L21.2678 13.7288C22.2441 14.7051 22.2441 16.288 21.2678 17.2643C20.2915 18.2407 18.7085 18.2407 17.7322 17.2643C16.7559 16.288 16.7559 14.7051 17.7322 13.7288Z"></path></svg>');
    const n = `
        <div style="height: 16px">
        ${this.svg}
        </div>
        `;
    this.template = n, this.registerClickListener();
  }
  // @ts-ignore
  onClick(n) {
    var r;
    n.setPainter((r = this.editor) == null ? void 0 : r.state.selection.$head.marks());
  }
}
class kv {
  constructor(e) {
    q(this, "url");
    q(this, "webSocket");
    q(this, "isOpen", !1);
    q(this, "text");
    this.url = e;
  }
  start(e) {
    this.text = e, this.webSocket = new WebSocket(this.url), this.webSocket.onopen = (n) => this.onOpen(n), this.webSocket.onmessage = (n) => this.onMessage(n), this.webSocket.onclose = (n) => this.onClose(n), this.webSocket.onerror = (n) => this.onError(n);
  }
  stop() {
    this.webSocket && (this.webSocket.close(), this.webSocket = void 0);
  }
  send(e) {
    this.webSocket && this.isOpen && this.webSocket.send(e);
  }
  onOpen(e) {
    this.isOpen = !0, this.send(this.text);
  }
  onMessage(e) {
  }
  onClose(e) {
    this.isOpen = !1;
  }
  onError(e) {
    this.isOpen = !1;
  }
}
const Zs = () => "10000000-1000-4000-8000-100000000000".replace(
  /[018]/g,
  (t) => (t ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> t / 4).toString(16)
);
class Tv extends kv {
  constructor(n, r, i, s) {
    super(n);
    q(this, "appId");
    q(this, "version");
    q(this, "editor");
    this.appId = r, this.version = i, this.editor = s;
  }
  getDomain() {
    switch (this.version) {
      case "v3.1":
        return "generalv3";
      case "v2.1":
        return "generalv2";
      default:
        return "general";
    }
  }
  send(n) {
    const r = {
      header: {
        app_id: this.appId,
        uid: Zs()
      },
      parameter: {
        chat: {
          domain: this.getDomain(),
          temperature: 0.5,
          max_tokens: 2048
        }
      },
      payload: {
        message: {
          text: [
            // {"role": "user", "content": "你会做什么"}
          ]
        }
      }
    };
    r.payload.message.text.push(
      { role: "user", content: n }
    ), super.send(JSON.stringify(r));
  }
  onMessage(n) {
    const r = n.data, s = JSON.parse(r).payload.choices.text[0].content;
    if (s) {
      for (let o = 0; o < s.length; o++) {
        const a = s.charAt(o);
        (o == 0 || o == s.length - 1) && a === '"' || (a === `
` ? this.editor.commands.insertContent("<p></p>") : this.editor.commands.insertContent(a));
      }
      this.editor.commands.scrollIntoView();
    }
  }
}
var dn = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
function rl(t) {
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
}
function _v(t) {
  if (t.__esModule)
    return t;
  var e = t.default;
  if (typeof e == "function") {
    var n = function r() {
      return this instanceof r ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
    };
    n.prototype = e.prototype;
  } else
    n = {};
  return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(t).forEach(function(r) {
    var i = Object.getOwnPropertyDescriptor(t, r);
    Object.defineProperty(n, r, i.get ? i : {
      enumerable: !0,
      get: function() {
        return t[r];
      }
    });
  }), n;
}
var Jf = { exports: {} };
function Nv(t) {
  throw new Error('Could not dynamically require "' + t + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var _o = { exports: {} };
const Av = {}, Ov = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Av
}, Symbol.toStringTag, { value: "Module" })), Rv = /* @__PURE__ */ _v(Ov);
var Jc;
function Gs() {
  return Jc || (Jc = 1, function(t, e) {
    (function(n, r) {
      t.exports = r();
    })(dn, function() {
      var n = n || function(r, i) {
        var s;
        if (typeof window < "u" && window.crypto && (s = window.crypto), typeof self < "u" && self.crypto && (s = self.crypto), typeof globalThis < "u" && globalThis.crypto && (s = globalThis.crypto), !s && typeof window < "u" && window.msCrypto && (s = window.msCrypto), !s && typeof dn < "u" && dn.crypto && (s = dn.crypto), !s && typeof Nv == "function")
          try {
            s = Rv;
          } catch {
          }
        var o = function() {
          if (s) {
            if (typeof s.getRandomValues == "function")
              try {
                return s.getRandomValues(new Uint32Array(1))[0];
              } catch {
              }
            if (typeof s.randomBytes == "function")
              try {
                return s.randomBytes(4).readInt32LE();
              } catch {
              }
          }
          throw new Error("Native crypto module could not be used to get secure random number.");
        }, a = Object.create || function() {
          function y() {
          }
          return function(E) {
            var b;
            return y.prototype = E, b = new y(), y.prototype = null, b;
          };
        }(), l = {}, c = l.lib = {}, d = c.Base = function() {
          return {
            /**
             * Creates a new object that inherits from this object.
             *
             * @param {Object} overrides Properties to copy into the new object.
             *
             * @return {Object} The new object.
             *
             * @static
             *
             * @example
             *
             *     var MyType = CryptoJS.lib.Base.extend({
             *         field: 'value',
             *
             *         method: function () {
             *         }
             *     });
             */
            extend: function(y) {
              var E = a(this);
              return y && E.mixIn(y), (!E.hasOwnProperty("init") || this.init === E.init) && (E.init = function() {
                E.$super.init.apply(this, arguments);
              }), E.init.prototype = E, E.$super = this, E;
            },
            /**
             * Extends this object and runs the init method.
             * Arguments to create() will be passed to init().
             *
             * @return {Object} The new object.
             *
             * @static
             *
             * @example
             *
             *     var instance = MyType.create();
             */
            create: function() {
              var y = this.extend();
              return y.init.apply(y, arguments), y;
            },
            /**
             * Initializes a newly created object.
             * Override this method to add some logic when your objects are created.
             *
             * @example
             *
             *     var MyType = CryptoJS.lib.Base.extend({
             *         init: function () {
             *             // ...
             *         }
             *     });
             */
            init: function() {
            },
            /**
             * Copies properties into this object.
             *
             * @param {Object} properties The properties to mix in.
             *
             * @example
             *
             *     MyType.mixIn({
             *         field: 'value'
             *     });
             */
            mixIn: function(y) {
              for (var E in y)
                y.hasOwnProperty(E) && (this[E] = y[E]);
              y.hasOwnProperty("toString") && (this.toString = y.toString);
            },
            /**
             * Creates a copy of this object.
             *
             * @return {Object} The clone.
             *
             * @example
             *
             *     var clone = instance.clone();
             */
            clone: function() {
              return this.init.prototype.extend(this);
            }
          };
        }(), u = c.WordArray = d.extend({
          /**
           * Initializes a newly created word array.
           *
           * @param {Array} words (Optional) An array of 32-bit words.
           * @param {number} sigBytes (Optional) The number of significant bytes in the words.
           *
           * @example
           *
           *     var wordArray = CryptoJS.lib.WordArray.create();
           *     var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
           *     var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
           */
          init: function(y, E) {
            y = this.words = y || [], E != i ? this.sigBytes = E : this.sigBytes = y.length * 4;
          },
          /**
           * Converts this word array to a string.
           *
           * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
           *
           * @return {string} The stringified word array.
           *
           * @example
           *
           *     var string = wordArray + '';
           *     var string = wordArray.toString();
           *     var string = wordArray.toString(CryptoJS.enc.Utf8);
           */
          toString: function(y) {
            return (y || p).stringify(this);
          },
          /**
           * Concatenates a word array to this word array.
           *
           * @param {WordArray} wordArray The word array to append.
           *
           * @return {WordArray} This word array.
           *
           * @example
           *
           *     wordArray1.concat(wordArray2);
           */
          concat: function(y) {
            var E = this.words, b = y.words, C = this.sigBytes, w = y.sigBytes;
            if (this.clamp(), C % 4)
              for (var _ = 0; _ < w; _++) {
                var R = b[_ >>> 2] >>> 24 - _ % 4 * 8 & 255;
                E[C + _ >>> 2] |= R << 24 - (C + _) % 4 * 8;
              }
            else
              for (var k = 0; k < w; k += 4)
                E[C + k >>> 2] = b[k >>> 2];
            return this.sigBytes += w, this;
          },
          /**
           * Removes insignificant bits.
           *
           * @example
           *
           *     wordArray.clamp();
           */
          clamp: function() {
            var y = this.words, E = this.sigBytes;
            y[E >>> 2] &= 4294967295 << 32 - E % 4 * 8, y.length = r.ceil(E / 4);
          },
          /**
           * Creates a copy of this word array.
           *
           * @return {WordArray} The clone.
           *
           * @example
           *
           *     var clone = wordArray.clone();
           */
          clone: function() {
            var y = d.clone.call(this);
            return y.words = this.words.slice(0), y;
          },
          /**
           * Creates a word array filled with random bytes.
           *
           * @param {number} nBytes The number of random bytes to generate.
           *
           * @return {WordArray} The random word array.
           *
           * @static
           *
           * @example
           *
           *     var wordArray = CryptoJS.lib.WordArray.random(16);
           */
          random: function(y) {
            for (var E = [], b = 0; b < y; b += 4)
              E.push(o());
            return new u.init(E, y);
          }
        }), f = l.enc = {}, p = f.Hex = {
          /**
           * Converts a word array to a hex string.
           *
           * @param {WordArray} wordArray The word array.
           *
           * @return {string} The hex string.
           *
           * @static
           *
           * @example
           *
           *     var hexString = CryptoJS.enc.Hex.stringify(wordArray);
           */
          stringify: function(y) {
            for (var E = y.words, b = y.sigBytes, C = [], w = 0; w < b; w++) {
              var _ = E[w >>> 2] >>> 24 - w % 4 * 8 & 255;
              C.push((_ >>> 4).toString(16)), C.push((_ & 15).toString(16));
            }
            return C.join("");
          },
          /**
           * Converts a hex string to a word array.
           *
           * @param {string} hexStr The hex string.
           *
           * @return {WordArray} The word array.
           *
           * @static
           *
           * @example
           *
           *     var wordArray = CryptoJS.enc.Hex.parse(hexString);
           */
          parse: function(y) {
            for (var E = y.length, b = [], C = 0; C < E; C += 2)
              b[C >>> 3] |= parseInt(y.substr(C, 2), 16) << 24 - C % 8 * 4;
            return new u.init(b, E / 2);
          }
        }, h = f.Latin1 = {
          /**
           * Converts a word array to a Latin1 string.
           *
           * @param {WordArray} wordArray The word array.
           *
           * @return {string} The Latin1 string.
           *
           * @static
           *
           * @example
           *
           *     var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
           */
          stringify: function(y) {
            for (var E = y.words, b = y.sigBytes, C = [], w = 0; w < b; w++) {
              var _ = E[w >>> 2] >>> 24 - w % 4 * 8 & 255;
              C.push(String.fromCharCode(_));
            }
            return C.join("");
          },
          /**
           * Converts a Latin1 string to a word array.
           *
           * @param {string} latin1Str The Latin1 string.
           *
           * @return {WordArray} The word array.
           *
           * @static
           *
           * @example
           *
           *     var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
           */
          parse: function(y) {
            for (var E = y.length, b = [], C = 0; C < E; C++)
              b[C >>> 2] |= (y.charCodeAt(C) & 255) << 24 - C % 4 * 8;
            return new u.init(b, E);
          }
        }, m = f.Utf8 = {
          /**
           * Converts a word array to a UTF-8 string.
           *
           * @param {WordArray} wordArray The word array.
           *
           * @return {string} The UTF-8 string.
           *
           * @static
           *
           * @example
           *
           *     var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
           */
          stringify: function(y) {
            try {
              return decodeURIComponent(escape(h.stringify(y)));
            } catch {
              throw new Error("Malformed UTF-8 data");
            }
          },
          /**
           * Converts a UTF-8 string to a word array.
           *
           * @param {string} utf8Str The UTF-8 string.
           *
           * @return {WordArray} The word array.
           *
           * @static
           *
           * @example
           *
           *     var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
           */
          parse: function(y) {
            return h.parse(unescape(encodeURIComponent(y)));
          }
        }, g = c.BufferedBlockAlgorithm = d.extend({
          /**
           * Resets this block algorithm's data buffer to its initial state.
           *
           * @example
           *
           *     bufferedBlockAlgorithm.reset();
           */
          reset: function() {
            this._data = new u.init(), this._nDataBytes = 0;
          },
          /**
           * Adds new data to this block algorithm's buffer.
           *
           * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
           *
           * @example
           *
           *     bufferedBlockAlgorithm._append('data');
           *     bufferedBlockAlgorithm._append(wordArray);
           */
          _append: function(y) {
            typeof y == "string" && (y = m.parse(y)), this._data.concat(y), this._nDataBytes += y.sigBytes;
          },
          /**
           * Processes available data blocks.
           *
           * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
           *
           * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
           *
           * @return {WordArray} The processed data.
           *
           * @example
           *
           *     var processedData = bufferedBlockAlgorithm._process();
           *     var processedData = bufferedBlockAlgorithm._process(!!'flush');
           */
          _process: function(y) {
            var E, b = this._data, C = b.words, w = b.sigBytes, _ = this.blockSize, R = _ * 4, k = w / R;
            y ? k = r.ceil(k) : k = r.max((k | 0) - this._minBufferSize, 0);
            var $ = k * _, Z = r.min($ * 4, w);
            if ($) {
              for (var j = 0; j < $; j += _)
                this._doProcessBlock(C, j);
              E = C.splice(0, $), b.sigBytes -= Z;
            }
            return new u.init(E, Z);
          },
          /**
           * Creates a copy of this object.
           *
           * @return {Object} The clone.
           *
           * @example
           *
           *     var clone = bufferedBlockAlgorithm.clone();
           */
          clone: function() {
            var y = d.clone.call(this);
            return y._data = this._data.clone(), y;
          },
          _minBufferSize: 0
        });
        c.Hasher = g.extend({
          /**
           * Configuration options.
           */
          cfg: d.extend(),
          /**
           * Initializes a newly created hasher.
           *
           * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
           *
           * @example
           *
           *     var hasher = CryptoJS.algo.SHA256.create();
           */
          init: function(y) {
            this.cfg = this.cfg.extend(y), this.reset();
          },
          /**
           * Resets this hasher to its initial state.
           *
           * @example
           *
           *     hasher.reset();
           */
          reset: function() {
            g.reset.call(this), this._doReset();
          },
          /**
           * Updates this hasher with a message.
           *
           * @param {WordArray|string} messageUpdate The message to append.
           *
           * @return {Hasher} This hasher.
           *
           * @example
           *
           *     hasher.update('message');
           *     hasher.update(wordArray);
           */
          update: function(y) {
            return this._append(y), this._process(), this;
          },
          /**
           * Finalizes the hash computation.
           * Note that the finalize operation is effectively a destructive, read-once operation.
           *
           * @param {WordArray|string} messageUpdate (Optional) A final message update.
           *
           * @return {WordArray} The hash.
           *
           * @example
           *
           *     var hash = hasher.finalize();
           *     var hash = hasher.finalize('message');
           *     var hash = hasher.finalize(wordArray);
           */
          finalize: function(y) {
            y && this._append(y);
            var E = this._doFinalize();
            return E;
          },
          blockSize: 16,
          /**
           * Creates a shortcut function to a hasher's object interface.
           *
           * @param {Hasher} hasher The hasher to create a helper for.
           *
           * @return {Function} The shortcut function.
           *
           * @static
           *
           * @example
           *
           *     var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
           */
          _createHelper: function(y) {
            return function(E, b) {
              return new y.init(b).finalize(E);
            };
          },
          /**
           * Creates a shortcut function to the HMAC's object interface.
           *
           * @param {Hasher} hasher The hasher to use in this HMAC helper.
           *
           * @return {Function} The shortcut function.
           *
           * @static
           *
           * @example
           *
           *     var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
           */
          _createHmacHelper: function(y) {
            return function(E, b) {
              return new v.HMAC.init(y, b).finalize(E);
            };
          }
        });
        var v = l.algo = {};
        return l;
      }(Math);
      return n;
    });
  }(_o)), _o.exports;
}
var No = { exports: {} }, Xc;
function Lv() {
  return Xc || (Xc = 1, function(t, e) {
    (function(n, r) {
      t.exports = r(Gs());
    })(dn, function(n) {
      return function(r) {
        var i = n, s = i.lib, o = s.WordArray, a = s.Hasher, l = i.algo, c = [], d = [];
        (function() {
          function p(v) {
            for (var y = r.sqrt(v), E = 2; E <= y; E++)
              if (!(v % E))
                return !1;
            return !0;
          }
          function h(v) {
            return (v - (v | 0)) * 4294967296 | 0;
          }
          for (var m = 2, g = 0; g < 64; )
            p(m) && (g < 8 && (c[g] = h(r.pow(m, 1 / 2))), d[g] = h(r.pow(m, 1 / 3)), g++), m++;
        })();
        var u = [], f = l.SHA256 = a.extend({
          _doReset: function() {
            this._hash = new o.init(c.slice(0));
          },
          _doProcessBlock: function(p, h) {
            for (var m = this._hash.words, g = m[0], v = m[1], y = m[2], E = m[3], b = m[4], C = m[5], w = m[6], _ = m[7], R = 0; R < 64; R++) {
              if (R < 16)
                u[R] = p[h + R] | 0;
              else {
                var k = u[R - 15], $ = (k << 25 | k >>> 7) ^ (k << 14 | k >>> 18) ^ k >>> 3, Z = u[R - 2], j = (Z << 15 | Z >>> 17) ^ (Z << 13 | Z >>> 19) ^ Z >>> 10;
                u[R] = $ + u[R - 7] + j + u[R - 16];
              }
              var J = b & C ^ ~b & w, X = g & v ^ g & y ^ v & y, re = (g << 30 | g >>> 2) ^ (g << 19 | g >>> 13) ^ (g << 10 | g >>> 22), T = (b << 26 | b >>> 6) ^ (b << 21 | b >>> 11) ^ (b << 7 | b >>> 25), x = _ + T + J + d[R] + u[R], S = re + X;
              _ = w, w = C, C = b, b = E + x | 0, E = y, y = v, v = g, g = x + S | 0;
            }
            m[0] = m[0] + g | 0, m[1] = m[1] + v | 0, m[2] = m[2] + y | 0, m[3] = m[3] + E | 0, m[4] = m[4] + b | 0, m[5] = m[5] + C | 0, m[6] = m[6] + w | 0, m[7] = m[7] + _ | 0;
          },
          _doFinalize: function() {
            var p = this._data, h = p.words, m = this._nDataBytes * 8, g = p.sigBytes * 8;
            return h[g >>> 5] |= 128 << 24 - g % 32, h[(g + 64 >>> 9 << 4) + 14] = r.floor(m / 4294967296), h[(g + 64 >>> 9 << 4) + 15] = m, p.sigBytes = h.length * 4, this._process(), this._hash;
          },
          clone: function() {
            var p = a.clone.call(this);
            return p._hash = this._hash.clone(), p;
          }
        });
        i.SHA256 = a._createHelper(f), i.HmacSHA256 = a._createHmacHelper(f);
      }(Math), n.SHA256;
    });
  }(No)), No.exports;
}
var Ao = { exports: {} }, Qc;
function Iv() {
  return Qc || (Qc = 1, function(t, e) {
    (function(n, r) {
      t.exports = r(Gs());
    })(dn, function(n) {
      (function() {
        var r = n, i = r.lib, s = i.Base, o = r.enc, a = o.Utf8, l = r.algo;
        l.HMAC = s.extend({
          /**
           * Initializes a newly created HMAC.
           *
           * @param {Hasher} hasher The hash algorithm to use.
           * @param {WordArray|string} key The secret key.
           *
           * @example
           *
           *     var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
           */
          init: function(c, d) {
            c = this._hasher = new c.init(), typeof d == "string" && (d = a.parse(d));
            var u = c.blockSize, f = u * 4;
            d.sigBytes > f && (d = c.finalize(d)), d.clamp();
            for (var p = this._oKey = d.clone(), h = this._iKey = d.clone(), m = p.words, g = h.words, v = 0; v < u; v++)
              m[v] ^= 1549556828, g[v] ^= 909522486;
            p.sigBytes = h.sigBytes = f, this.reset();
          },
          /**
           * Resets this HMAC to its initial state.
           *
           * @example
           *
           *     hmacHasher.reset();
           */
          reset: function() {
            var c = this._hasher;
            c.reset(), c.update(this._iKey);
          },
          /**
           * Updates this HMAC with a message.
           *
           * @param {WordArray|string} messageUpdate The message to append.
           *
           * @return {HMAC} This HMAC instance.
           *
           * @example
           *
           *     hmacHasher.update('message');
           *     hmacHasher.update(wordArray);
           */
          update: function(c) {
            return this._hasher.update(c), this;
          },
          /**
           * Finalizes the HMAC computation.
           * Note that the finalize operation is effectively a destructive, read-once operation.
           *
           * @param {WordArray|string} messageUpdate (Optional) A final message update.
           *
           * @return {WordArray} The HMAC.
           *
           * @example
           *
           *     var hmac = hmacHasher.finalize();
           *     var hmac = hmacHasher.finalize('message');
           *     var hmac = hmacHasher.finalize(wordArray);
           */
          finalize: function(c) {
            var d = this._hasher, u = d.finalize(c);
            d.reset();
            var f = d.finalize(this._oKey.clone().concat(u));
            return f;
          }
        });
      })();
    });
  }(Ao)), Ao.exports;
}
(function(t, e) {
  (function(n, r, i) {
    t.exports = r(Gs(), Lv(), Iv());
  })(dn, function(n) {
    return n.HmacSHA256;
  });
})(Jf);
var Dv = Jf.exports;
const Hv = /* @__PURE__ */ rl(Dv);
var Xf = { exports: {} };
(function(t, e) {
  (function(n, r) {
    t.exports = r(Gs());
  })(dn, function(n) {
    return function() {
      var r = n, i = r.lib, s = i.WordArray, o = r.enc;
      o.Base64 = {
        /**
         * Converts a word array to a Base64 string.
         *
         * @param {WordArray} wordArray The word array.
         *
         * @return {string} The Base64 string.
         *
         * @static
         *
         * @example
         *
         *     var base64String = CryptoJS.enc.Base64.stringify(wordArray);
         */
        stringify: function(l) {
          var c = l.words, d = l.sigBytes, u = this._map;
          l.clamp();
          for (var f = [], p = 0; p < d; p += 3)
            for (var h = c[p >>> 2] >>> 24 - p % 4 * 8 & 255, m = c[p + 1 >>> 2] >>> 24 - (p + 1) % 4 * 8 & 255, g = c[p + 2 >>> 2] >>> 24 - (p + 2) % 4 * 8 & 255, v = h << 16 | m << 8 | g, y = 0; y < 4 && p + y * 0.75 < d; y++)
              f.push(u.charAt(v >>> 6 * (3 - y) & 63));
          var E = u.charAt(64);
          if (E)
            for (; f.length % 4; )
              f.push(E);
          return f.join("");
        },
        /**
         * Converts a Base64 string to a word array.
         *
         * @param {string} base64Str The Base64 string.
         *
         * @return {WordArray} The word array.
         *
         * @static
         *
         * @example
         *
         *     var wordArray = CryptoJS.enc.Base64.parse(base64String);
         */
        parse: function(l) {
          var c = l.length, d = this._map, u = this._reverseMap;
          if (!u) {
            u = this._reverseMap = [];
            for (var f = 0; f < d.length; f++)
              u[d.charCodeAt(f)] = f;
          }
          var p = d.charAt(64);
          if (p) {
            var h = l.indexOf(p);
            h !== -1 && (c = h);
          }
          return a(l, c, u);
        },
        _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
      };
      function a(l, c, d) {
        for (var u = [], f = 0, p = 0; p < c; p++)
          if (p % 4) {
            var h = d[l.charCodeAt(p - 1)] << p % 4 * 2, m = d[l.charCodeAt(p)] >>> 6 - p % 4 * 2, g = h | m;
            u[f >>> 2] |= g << 24 - f % 4 * 8, f++;
          }
        return s.create(u, f);
      }
    }(), n.enc.Base64;
  });
})(Xf);
var Bv = Xf.exports;
const Pv = /* @__PURE__ */ rl(Bv);
class $v {
  constructor(e) {
    q(this, "protocol");
    q(this, "appId");
    q(this, "apiKey");
    q(this, "apiSecret");
    q(this, "version");
    q(this, "onCreateURL");
    var l;
    const { protocol: n, appId: r, apiKey: i, apiSecret: s, version: o, onCreateURL: a } = (l = e.ai) == null ? void 0 : l.model.xinghuo;
    this.protocol = n || "ws", this.appId = r, this.apiKey = i, this.apiSecret = s, this.version = o || "v3.1", this.onCreateURL = a;
  }
  start(e, n, r) {
    const i = this.onCreateURL ? this.onCreateURL(this) : this.createUrl();
    new Tv(i, this.appId, this.version, r).start(`"${e}"
${n}`);
  }
  createUrl() {
    const e = (/* @__PURE__ */ new Date()).toUTCString().replace("GMT", "+0000");
    let n = `host: spark-api.xf-yun.com
`;
    n += "date: " + e + `
`, n += `GET /${this.version}/chat HTTP/1.1`;
    const r = Hv(n, this.apiSecret), i = Pv.stringify(r), s = `api_key="${this.apiKey}", algorithm="hmac-sha256", headers="host date request-line", signature="${i}"`, o = btoa(s);
    return `${this.protocol}://spark-api.xf-yun.com/${this.version}/chat?authorization=${o}&date=${encodeURIComponent(e)}&host=spark-api.xf-yun.com`;
  }
}
class il {
  static create(e, n) {
    let r = this.models[e];
    return r || (e === "spark" && (r = new $v(n)), r && (this.models[e] = r), r);
  }
}
q(il, "models", {});
const Vv = [
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M4 18.9997H20V13.9997H22V19.9997C22 20.552 21.5523 20.9997 21 20.9997H3C2.44772 20.9997 2 20.552 2 19.9997V13.9997H4V18.9997ZM16.1716 6.9997L12.2218 3.04996L13.636 1.63574L20 7.9997L13.636 14.3637L12.2218 12.9495L16.1716 8.9997H5V6.9997H16.1716Z"></path></svg></div>',
    name: "AI 续写",
    prompt: "请帮我继续扩展一些这段话的内容",
    text: "focusBefore",
    model: "spark"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M15 5.25C16.7949 5.25 18.25 3.79493 18.25 2H19.75C19.75 3.79493 21.2051 5.25 23 5.25V6.75C21.2051 6.75 19.75 8.20507 19.75 10H18.25C18.25 8.20507 16.7949 6.75 15 6.75V5.25ZM4 7C4 5.89543 4.89543 5 6 5H13V3H6C3.79086 3 2 4.79086 2 7V17C2 19.2091 3.79086 21 6 21H18C20.2091 21 22 19.2091 22 17V12H20V17C20 18.1046 19.1046 19 18 19H6C4.89543 19 4 18.1046 4 17V7Z"></path></svg></div>',
    name: "AI 优化",
    prompt: "请帮我优化一下这段文字的内容，并返回结果",
    text: "selected",
    model: "spark"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M17.934 3.0359L19.666 4.0359L18.531 6H21V8H19V12H21V14H19V21H17V14L13.9157 14.0004C13.5914 16.8623 12.3522 19.3936 10.5466 21.1933L8.98361 19.9233C10.5031 18.4847 11.5801 16.4008 11.9008 14.0009L10 14V12L12 11.999V8H10V6H12.467L11.334 4.0359L13.066 3.0359L14.777 6H16.221L17.934 3.0359ZM5 13.803L3 14.339V12.268L5 11.732V8H3V6H5V3H7V6H9V8H7V11.197L9 10.661V12.731L7 13.267V18.5C7 19.8807 5.88071 21 4.5 21H3V19H4.5C4.74546 19 4.94961 18.8231 4.99194 18.5899L5 18.5V13.803ZM17 8H14V12H17V8Z"></path></svg></div>',
    name: "AI 校对",
    prompt: "请帮我找出这段话的错别字，把错别字修改后，并返回结果，不要解释或其他多余的内容",
    text: "selected",
    model: "spark"
  },
  {
    icon: '<div style="width:18px;height: 18px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M5 15V17C5 18.0544 5.81588 18.9182 6.85074 18.9945L7 19H10V21H7C4.79086 21 3 19.2091 3 17V15H5ZM18 10L22.4 21H20.245L19.044 18H14.954L13.755 21H11.601L16 10H18ZM17 12.8852L15.753 16H18.245L17 12.8852ZM8 2V4H12V11H8V14H6V11H2V4H6V2H8ZM17 3C19.2091 3 21 4.79086 21 7V9H19V7C19 5.89543 18.1046 5 17 5H14V3H17ZM6 6H4V9H6V6ZM10 6H8V9H10V6Z"></path></svg></div>',
    name: "AI 翻译",
    prompt: "请帮我把这段内容翻译为英语，直接返回英语结果",
    text: "selected",
    model: "spark"
  }
];
class zv extends Or {
  constructor() {
    super(), this.dropDivHeight = "120px", this.dropDivWith = "94px", this.width = "36px", this.menuTextWidth = "20px";
  }
  onCreate(e, n) {
    var r;
    super.onCreate(e, n), this.menuData = ((r = n.ai) == null ? void 0 : r.menus) || Vv;
  }
  renderTemplate() {
    this.template = `
         <div style="width: ${this.width};">
         <div id="tippy" class="menu-ai" id="text">
             <span> AI </span>
             <div style="width: 18px;height: 18px;display: inline-block" >
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 14L8 10H16L12 14Z"></path></svg>
             </div>
         </div>
         </div>
        `;
  }
  createMenuElement() {
    const e = document.createElement("div");
    e.style.height = this.dropDivHeight, e.style.width = this.dropDivWith, e.classList.add("aie-dropdown-container");
    for (let n = 0; n < this.menuData.length; n++) {
      const r = document.createElement("div");
      r.classList.add("aie-dropdown-item"), r.innerHTML = `
            <div class="text" style="display: flex;padding-left: 5px">${this.onDropdownItemRender(n)}</div>
            `, r.addEventListener("click", () => {
        this.onDropdownItemClick(n), this.tippyInstance.hide();
      }), e.appendChild(r);
    }
    return this.tippyEl = e, e;
  }
  onTransaction(e) {
  }
  onDropdownActive(e, n) {
    return !1;
  }
  getSelectedText(e) {
    if (e === "selected") {
      const { selection: n, doc: r } = this.editor.state;
      return r.textBetween(n.from, n.to);
    } else
      return this.editor.state.selection.$head.parent.textContent;
  }
  onDropdownItemClick(e) {
    const n = this.menuData[e], r = this.getSelectedText(n.text);
    if (r) {
      const i = il.create(n.model, this.options);
      i ? i == null || i.start(r, n.prompt, this.editor) : console.error("Ai model config error.");
    } else
      console.error("Can not get selected text.");
  }
  onDropdownItemRender(e) {
    return this.menuData[e].icon + `<div style="margin-left: 10px">${this.menuData[e].name}</div>`;
  }
  onMenuTextRender(e) {
    return this.menuData[e].icon;
  }
}
window.customElements.define("aie-undo", r0);
window.customElements.define("aie-redo", i0);
window.customElements.define("aie-brush", Mv);
window.customElements.define("aie-eraser", gv);
window.customElements.define("aie-title", $y);
window.customElements.define("aie-font-family", zy);
window.customElements.define("aie-font-size", Uy);
window.customElements.define("aie-bold", Ky);
window.customElements.define("aie-italic", Wy);
window.customElements.define("aie-underline", qy);
window.customElements.define("aie-strike", Zy);
window.customElements.define("aie-link", av);
window.customElements.define("aie-code", hv);
window.customElements.define("aie-subscript", Gy);
window.customElements.define("aie-superscript", jy);
window.customElements.define("aie-highlight", Xy);
window.customElements.define("aie-font-color", Qy);
window.customElements.define("aie-divider", ev);
window.customElements.define("aie-bullet-list", tv);
window.customElements.define("aie-ordered-list", nv);
window.customElements.define("aie-indent-decrease", rv);
window.customElements.define("aie-indent-increase", iv);
window.customElements.define("aie-align", ov);
window.customElements.define("aie-todo", lv);
window.customElements.define("aie-line-height", dv);
window.customElements.define("aie-break", vv);
window.customElements.define("aie-quote", uv);
window.customElements.define("aie-image", fv);
window.customElements.define("aie-video", pv);
window.customElements.define("aie-code-block", mv);
window.customElements.define("aie-hr", bv);
window.customElements.define("aie-table", yv);
window.customElements.define("aie-attachment", wv);
window.customElements.define("aie-fullscreen", Ev);
window.customElements.define("aie-printer", xv);
window.customElements.define("aie-emoji", Cv);
window.customElements.define("aie-ai", zv);
const Fv = [
  "undo",
  "redo",
  "brush",
  "eraser",
  "divider",
  "title",
  "font-family",
  "font-size",
  "divider",
  "bold",
  "italic",
  "underline",
  "strike",
  "link",
  "code",
  "subscript",
  "superscript",
  "hr",
  "todo",
  "emoji",
  "divider",
  "highlight",
  "font-color",
  "divider",
  "align",
  "line-height",
  "divider",
  "bullet-list",
  "ordered-list",
  "indent-decrease",
  "indent-increase",
  "break",
  "divider",
  "image",
  "video",
  "attachment",
  "quote",
  "code-block",
  "table",
  "divider",
  "printer",
  "fullscreen",
  "ai"
];
class Uv extends HTMLElement {
  constructor() {
    super();
    // template:string;
    q(this, "menuButtons", []);
  }
  connectedCallback() {
    const n = document.createElement("div");
    for (let r of this.menuButtons)
      n.appendChild(r);
    n.style.display = "flex", n.style.flexWrap = "wrap", this.appendChild(n);
  }
  onCreate(n, r) {
    let i = r.toolbarKeys || Fv;
    for (let s of i)
      if (s) {
        s = s.trim(), s === "|" && (s = "divider");
        try {
          const o = document.createElement("aie-" + s);
          o.classList.add("aie-menu-item"), o.onCreate(n, r), this.menuButtons.push(o);
        } catch {
          console.error("Can not create toolbar by key: " + s);
        }
      }
  }
  onTransaction(n) {
    for (let r of this.menuButtons)
      r.onTransaction(n);
  }
}
class Kv extends HTMLElement {
  constructor() {
    super();
    q(this, "count", 0);
    let n, r, i = 300, s = 300, o, a, l;
    const c = (u) => {
      u.preventDefault(), document.removeEventListener("mouseup", c), document.removeEventListener("mousemove", d);
    }, d = (u) => {
      const f = u.clientX - n, p = u.clientY - r;
      if (f == 0 && p == 0)
        return;
      const h = f > 0, m = p > 0;
      let g = o + Math.abs(f) * (h ? 1 : -1), v = a + Math.abs(p) * (m ? 1 : -1);
      g < i && (g = i), v < s && (v = s), l.style.width = `${g}px`, l.style.height = `${v}px`;
    };
    this.addEventListener("mousedown", (u) => {
      var p;
      u.target.closest("svg") && (u.preventDefault(), document.addEventListener("mouseup", c), document.addEventListener("mousemove", d), l = (p = u.target.closest(".aie-container")) == null ? void 0 : p.parentElement, o = l.clientWidth, a = l.clientHeight, n = u.clientX, r = u.clientY);
    }), this.addEventListener("mouseup", c);
  }
  updateCharacters() {
    this.innerHTML = `
        <div style="display: flex"> 
            <span> Powered by AiEditor, Characters: ${this.count} </span>
            <div style="width: 20px;height: 20px">
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 16L6 10H18L12 16Z"></path></svg>
            </div>
        </div>
        `;
  }
  onCreate(n, r) {
    this.count = n.editor.storage.characterCount.characters(), this.updateCharacters();
  }
  onTransaction(n) {
    const r = n.editor.storage.characterCount.characters();
    r != this.count && (this.count = r, this.updateCharacters());
  }
}
const Wv = /^\s*>\s$/, qv = xe.create({
  name: "blockquote",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  content: "block+",
  group: "block",
  defining: !0,
  parseHTML() {
    return [
      { tag: "blockquote" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["blockquote", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setBlockquote: () => ({ commands: t }) => t.wrapIn(this.name),
      toggleBlockquote: () => ({ commands: t }) => t.toggleWrap(this.name),
      unsetBlockquote: () => ({ commands: t }) => t.lift(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-b": () => this.editor.commands.toggleBlockquote()
    };
  },
  addInputRules() {
    return [
      Sr({
        find: Wv,
        type: this.type
      })
    ];
  }
}), Zv = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/, Gv = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/g, jv = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/, Yv = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/g, Jv = qe.create({
  name: "bold",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "strong"
      },
      {
        tag: "b",
        getAttrs: (t) => t.style.fontWeight !== "normal" && null
      },
      {
        style: "font-weight",
        getAttrs: (t) => /^(bold(er)?|[5-9]\d{2,})$/.test(t) && null
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["strong", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setBold: () => ({ commands: t }) => t.setMark(this.name),
      toggleBold: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetBold: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-b": () => this.editor.commands.toggleBold(),
      "Mod-B": () => this.editor.commands.toggleBold()
    };
  },
  addInputRules() {
    return [
      Un({
        find: Zv,
        type: this.type
      }),
      Un({
        find: jv,
        type: this.type
      })
    ];
  },
  addPasteRules() {
    return [
      yn({
        find: Gv,
        type: this.type
      }),
      yn({
        find: Yv,
        type: this.type
      })
    ];
  }
}), Xv = xe.create({
  name: "listItem",
  addOptions() {
    return {
      HTMLAttributes: {},
      bulletListTypeName: "bulletList",
      orderedListTypeName: "orderedList"
    };
  },
  content: "paragraph block*",
  defining: !0,
  parseHTML() {
    return [
      {
        tag: "li"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["li", fe(this.options.HTMLAttributes, t), 0];
  },
  addKeyboardShortcuts() {
    return {
      Enter: () => this.editor.commands.splitListItem(this.name),
      Tab: () => this.editor.commands.sinkListItem(this.name),
      "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
    };
  }
}), ed = qe.create({
  name: "textStyle",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "span",
        getAttrs: (t) => t.hasAttribute("style") ? {} : !1
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["span", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      removeEmptyTextStyle: () => ({ state: t, commands: e }) => {
        const n = vi(t, this.type);
        return Object.entries(n).some(([, i]) => !!i) ? !0 : e.unsetMark(this.name);
      }
    };
  }
}), td = /^\s*([-+*])\s$/, Qv = xe.create({
  name: "bulletList",
  addOptions() {
    return {
      itemTypeName: "listItem",
      HTMLAttributes: {},
      keepMarks: !1,
      keepAttributes: !1
    };
  },
  group: "block list",
  content() {
    return `${this.options.itemTypeName}+`;
  },
  parseHTML() {
    return [
      { tag: "ul" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["ul", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      toggleBulletList: () => ({ commands: t, chain: e }) => this.options.keepAttributes ? e().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(Xv.name, this.editor.getAttributes(ed.name)).run() : t.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-8": () => this.editor.commands.toggleBulletList()
    };
  },
  addInputRules() {
    let t = Sr({
      find: td,
      type: this.type
    });
    return (this.options.keepMarks || this.options.keepAttributes) && (t = Sr({
      find: td,
      type: this.type,
      keepMarks: this.options.keepMarks,
      keepAttributes: this.options.keepAttributes,
      getAttributes: () => this.editor.getAttributes(ed.name),
      editor: this.editor
    })), [
      t
    ];
  }
}), ew = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/, tw = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/g, nw = qe.create({
  name: "code",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  excludes: "_",
  code: !0,
  exitable: !0,
  parseHTML() {
    return [
      { tag: "code" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["code", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setCode: () => ({ commands: t }) => t.setMark(this.name),
      toggleCode: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetCode: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-e": () => this.editor.commands.toggleCode()
    };
  },
  addInputRules() {
    return [
      Un({
        find: ew,
        type: this.type
      })
    ];
  },
  addPasteRules() {
    return [
      yn({
        find: tw,
        type: this.type
      })
    ];
  }
}), rw = /^```([a-z]+)?[\s\n]$/, iw = /^~~~([a-z]+)?[\s\n]$/, Qf = xe.create({
  name: "codeBlock",
  addOptions() {
    return {
      languageClassPrefix: "language-",
      exitOnTripleEnter: !0,
      exitOnArrowDown: !0,
      HTMLAttributes: {}
    };
  },
  content: "text*",
  marks: "",
  group: "block",
  code: !0,
  defining: !0,
  addAttributes() {
    return {
      language: {
        default: null,
        parseHTML: (t) => {
          var e;
          const { languageClassPrefix: n } = this.options, s = [...((e = t.firstElementChild) === null || e === void 0 ? void 0 : e.classList) || []].filter((o) => o.startsWith(n)).map((o) => o.replace(n, ""))[0];
          return s || null;
        },
        rendered: !1
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: "pre",
        preserveWhitespace: "full"
      }
    ];
  },
  renderHTML({ node: t, HTMLAttributes: e }) {
    return [
      "pre",
      fe(this.options.HTMLAttributes, e),
      [
        "code",
        {
          class: t.attrs.language ? this.options.languageClassPrefix + t.attrs.language : null
        },
        0
      ]
    ];
  },
  addCommands() {
    return {
      setCodeBlock: (t) => ({ commands: e }) => e.setNode(this.name, t),
      toggleCodeBlock: (t) => ({ commands: e }) => e.toggleNode(this.name, "paragraph", t)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
      // remove code block when at start of document or code block is empty
      Backspace: () => {
        const { empty: t, $anchor: e } = this.editor.state.selection, n = e.pos === 1;
        return !t || e.parent.type.name !== this.name ? !1 : n || !e.parent.textContent.length ? this.editor.commands.clearNodes() : !1;
      },
      // exit node on triple enter
      Enter: ({ editor: t }) => {
        if (!this.options.exitOnTripleEnter)
          return !1;
        const { state: e } = t, { selection: n } = e, { $from: r, empty: i } = n;
        if (!i || r.parent.type !== this.type)
          return !1;
        const s = r.parentOffset === r.parent.nodeSize - 2, o = r.parent.textContent.endsWith(`

`);
        return !s || !o ? !1 : t.chain().command(({ tr: a }) => (a.delete(r.pos - 2, r.pos), !0)).exitCode().run();
      },
      // exit node on arrow down
      ArrowDown: ({ editor: t }) => {
        if (!this.options.exitOnArrowDown)
          return !1;
        const { state: e } = t, { selection: n, doc: r } = e, { $from: i, empty: s } = n;
        if (!s || i.parent.type !== this.type || !(i.parentOffset === i.parent.nodeSize - 2))
          return !1;
        const a = i.after();
        return a === void 0 || r.nodeAt(a) ? !1 : t.commands.exitCode();
      }
    };
  },
  addInputRules() {
    return [
      la({
        find: rw,
        type: this.type,
        getAttributes: (t) => ({
          language: t[1]
        })
      }),
      la({
        find: iw,
        type: this.type,
        getAttributes: (t) => ({
          language: t[1]
        })
      })
    ];
  },
  addProseMirrorPlugins() {
    return [
      // this plugin creates a code block for pasted content from VS Code
      // we can also detect the copied code language
      new Se({
        key: new Me("codeBlockVSCodeHandler"),
        props: {
          handlePaste: (t, e) => {
            if (!e.clipboardData || this.editor.isActive(this.type.name))
              return !1;
            const n = e.clipboardData.getData("text/plain"), r = e.clipboardData.getData("vscode-editor-data"), i = r ? JSON.parse(r) : void 0, s = i == null ? void 0 : i.mode;
            if (!n || !s)
              return !1;
            const { tr: o } = t.state;
            return o.replaceSelectionWith(this.type.create({ language: s })), o.setSelection(G.near(o.doc.resolve(Math.max(0, o.selection.from - 2)))), o.insertText(n.replace(/\r\n?/g, `
`)), o.setMeta("paste", !0), t.dispatch(o), !0;
          }
        }
      })
    ];
  }
}), sw = xe.create({
  name: "doc",
  topNode: !0,
  content: "block+"
});
function ow(t = {}) {
  return new Se({
    view(e) {
      return new aw(e, t);
    }
  });
}
class aw {
  constructor(e, n) {
    var r;
    this.editorView = e, this.cursorPos = null, this.element = null, this.timeout = -1, this.width = (r = n.width) !== null && r !== void 0 ? r : 1, this.color = n.color === !1 ? void 0 : n.color || "black", this.class = n.class, this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((i) => {
      let s = (o) => {
        this[i](o);
      };
      return e.dom.addEventListener(i, s), { name: i, handler: s };
    });
  }
  destroy() {
    this.handlers.forEach(({ name: e, handler: n }) => this.editorView.dom.removeEventListener(e, n));
  }
  update(e, n) {
    this.cursorPos != null && n.doc != e.state.doc && (this.cursorPos > e.state.doc.content.size ? this.setCursor(null) : this.updateOverlay());
  }
  setCursor(e) {
    e != this.cursorPos && (this.cursorPos = e, e == null ? (this.element.parentNode.removeChild(this.element), this.element = null) : this.updateOverlay());
  }
  updateOverlay() {
    let e = this.editorView.state.doc.resolve(this.cursorPos), n = !e.parent.inlineContent, r;
    if (n) {
      let a = e.nodeBefore, l = e.nodeAfter;
      if (a || l) {
        let c = this.editorView.nodeDOM(this.cursorPos - (a ? a.nodeSize : 0));
        if (c) {
          let d = c.getBoundingClientRect(), u = a ? d.bottom : d.top;
          a && l && (u = (u + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2), r = { left: d.left, right: d.right, top: u - this.width / 2, bottom: u + this.width / 2 };
        }
      }
    }
    if (!r) {
      let a = this.editorView.coordsAtPos(this.cursorPos);
      r = { left: a.left - this.width / 2, right: a.left + this.width / 2, top: a.top, bottom: a.bottom };
    }
    let i = this.editorView.dom.offsetParent;
    this.element || (this.element = i.appendChild(document.createElement("div")), this.class && (this.element.className = this.class), this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;", this.color && (this.element.style.backgroundColor = this.color)), this.element.classList.toggle("prosemirror-dropcursor-block", n), this.element.classList.toggle("prosemirror-dropcursor-inline", !n);
    let s, o;
    if (!i || i == document.body && getComputedStyle(i).position == "static")
      s = -pageXOffset, o = -pageYOffset;
    else {
      let a = i.getBoundingClientRect();
      s = a.left - i.scrollLeft, o = a.top - i.scrollTop;
    }
    this.element.style.left = r.left - s + "px", this.element.style.top = r.top - o + "px", this.element.style.width = r.right - r.left + "px", this.element.style.height = r.bottom - r.top + "px";
  }
  scheduleRemoval(e) {
    clearTimeout(this.timeout), this.timeout = setTimeout(() => this.setCursor(null), e);
  }
  dragover(e) {
    if (!this.editorView.editable)
      return;
    let n = this.editorView.posAtCoords({ left: e.clientX, top: e.clientY }), r = n && n.inside >= 0 && this.editorView.state.doc.nodeAt(n.inside), i = r && r.type.spec.disableDropCursor, s = typeof i == "function" ? i(this.editorView, n, e) : i;
    if (n && !s) {
      let o = n.pos;
      if (this.editorView.dragging && this.editorView.dragging.slice) {
        let a = Tu(this.editorView.state.doc, o, this.editorView.dragging.slice);
        a != null && (o = a);
      }
      this.setCursor(o), this.scheduleRemoval(5e3);
    }
  }
  dragend() {
    this.scheduleRemoval(20);
  }
  drop() {
    this.scheduleRemoval(20);
  }
  dragleave(e) {
    (e.target == this.editorView.dom || !this.editorView.dom.contains(e.relatedTarget)) && this.setCursor(null);
  }
}
const lw = Ce.create({
  name: "dropCursor",
  addOptions() {
    return {
      color: "currentColor",
      width: 1,
      class: void 0
    };
  },
  addProseMirrorPlugins() {
    return [
      ow(this.options)
    ];
  }
});
class Ae extends te {
  /**
  Create a gap cursor.
  */
  constructor(e) {
    super(e, e);
  }
  map(e, n) {
    let r = e.resolve(n.map(this.head));
    return Ae.valid(r) ? new Ae(r) : te.near(r);
  }
  content() {
    return B.empty;
  }
  eq(e) {
    return e instanceof Ae && e.head == this.head;
  }
  toJSON() {
    return { type: "gapcursor", pos: this.head };
  }
  /**
  @internal
  */
  static fromJSON(e, n) {
    if (typeof n.pos != "number")
      throw new RangeError("Invalid input for GapCursor.fromJSON");
    return new Ae(e.resolve(n.pos));
  }
  /**
  @internal
  */
  getBookmark() {
    return new sl(this.anchor);
  }
  /**
  @internal
  */
  static valid(e) {
    let n = e.parent;
    if (n.isTextblock || !cw(e) || !dw(e))
      return !1;
    let r = n.type.spec.allowGapCursor;
    if (r != null)
      return r;
    let i = n.contentMatchAt(e.index()).defaultType;
    return i && i.isTextblock;
  }
  /**
  @internal
  */
  static findGapCursorFrom(e, n, r = !1) {
    e:
      for (; ; ) {
        if (!r && Ae.valid(e))
          return e;
        let i = e.pos, s = null;
        for (let o = e.depth; ; o--) {
          let a = e.node(o);
          if (n > 0 ? e.indexAfter(o) < a.childCount : e.index(o) > 0) {
            s = a.child(n > 0 ? e.indexAfter(o) : e.index(o) - 1);
            break;
          } else if (o == 0)
            return null;
          i += n;
          let l = e.doc.resolve(i);
          if (Ae.valid(l))
            return l;
        }
        for (; ; ) {
          let o = n > 0 ? s.firstChild : s.lastChild;
          if (!o) {
            if (s.isAtom && !s.isText && !Y.isSelectable(s)) {
              e = e.doc.resolve(i + s.nodeSize * n), r = !1;
              continue e;
            }
            break;
          }
          s = o, i += n;
          let a = e.doc.resolve(i);
          if (Ae.valid(a))
            return a;
        }
        return null;
      }
  }
}
Ae.prototype.visible = !1;
Ae.findFrom = Ae.findGapCursorFrom;
te.jsonID("gapcursor", Ae);
class sl {
  constructor(e) {
    this.pos = e;
  }
  map(e) {
    return new sl(e.map(this.pos));
  }
  resolve(e) {
    let n = e.resolve(this.pos);
    return Ae.valid(n) ? new Ae(n) : te.near(n);
  }
}
function cw(t) {
  for (let e = t.depth; e >= 0; e--) {
    let n = t.index(e), r = t.node(e);
    if (n == 0) {
      if (r.type.spec.isolating)
        return !0;
      continue;
    }
    for (let i = r.child(n - 1); ; i = i.lastChild) {
      if (i.childCount == 0 && !i.inlineContent || i.isAtom || i.type.spec.isolating)
        return !0;
      if (i.inlineContent)
        return !1;
    }
  }
  return !0;
}
function dw(t) {
  for (let e = t.depth; e >= 0; e--) {
    let n = t.indexAfter(e), r = t.node(e);
    if (n == r.childCount) {
      if (r.type.spec.isolating)
        return !0;
      continue;
    }
    for (let i = r.child(n); ; i = i.firstChild) {
      if (i.childCount == 0 && !i.inlineContent || i.isAtom || i.type.spec.isolating)
        return !0;
      if (i.inlineContent)
        return !1;
    }
  }
  return !0;
}
function uw() {
  return new Se({
    props: {
      decorations: mw,
      createSelectionBetween(t, e, n) {
        return e.pos == n.pos && Ae.valid(n) ? new Ae(n) : null;
      },
      handleClick: pw,
      handleKeyDown: fw,
      handleDOMEvents: { beforeinput: hw }
    }
  });
}
const fw = Va({
  ArrowLeft: Ni("horiz", -1),
  ArrowRight: Ni("horiz", 1),
  ArrowUp: Ni("vert", -1),
  ArrowDown: Ni("vert", 1)
});
function Ni(t, e) {
  const n = t == "vert" ? e > 0 ? "down" : "up" : e > 0 ? "right" : "left";
  return function(r, i, s) {
    let o = r.selection, a = e > 0 ? o.$to : o.$from, l = o.empty;
    if (o instanceof G) {
      if (!s.endOfTextblock(n) || a.depth == 0)
        return !1;
      l = !1, a = r.doc.resolve(e > 0 ? a.after() : a.before());
    }
    let c = Ae.findGapCursorFrom(a, e, l);
    return c ? (i && i(r.tr.setSelection(new Ae(c))), !0) : !1;
  };
}
function pw(t, e, n) {
  if (!t || !t.editable)
    return !1;
  let r = t.state.doc.resolve(e);
  if (!Ae.valid(r))
    return !1;
  let i = t.posAtCoords({ left: n.clientX, top: n.clientY });
  return i && i.inside > -1 && Y.isSelectable(t.state.doc.nodeAt(i.inside)) ? !1 : (t.dispatch(t.state.tr.setSelection(new Ae(r))), !0);
}
function hw(t, e) {
  if (e.inputType != "insertCompositionText" || !(t.state.selection instanceof Ae))
    return !1;
  let { $from: n } = t.state.selection, r = n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);
  if (!r)
    return !1;
  let i = A.empty;
  for (let o = r.length - 1; o >= 0; o--)
    i = A.from(r[o].createAndFill(null, i));
  let s = t.state.tr.replace(n.pos, n.pos, new B(i, 0, 0));
  return s.setSelection(G.near(s.doc.resolve(n.pos + 1))), t.dispatch(s), !1;
}
function mw(t) {
  if (!(t.selection instanceof Ae))
    return null;
  let e = document.createElement("div");
  return e.className = "ProseMirror-gapcursor", we.create(t.doc, [Le.widget(t.selection.head, e, { key: "gapcursor" })]);
}
const gw = Ce.create({
  name: "gapCursor",
  addProseMirrorPlugins() {
    return [
      uw()
    ];
  },
  extendNodeSchema(t) {
    var e;
    const n = {
      name: t.name,
      options: t.options,
      storage: t.storage
    };
    return {
      allowGapCursor: (e = ie(z(t, "allowGapCursor", n))) !== null && e !== void 0 ? e : null
    };
  }
}), bw = xe.create({
  name: "hardBreak",
  addOptions() {
    return {
      keepMarks: !0,
      HTMLAttributes: {}
    };
  },
  inline: !0,
  group: "inline",
  selectable: !1,
  parseHTML() {
    return [
      { tag: "br" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["br", fe(this.options.HTMLAttributes, t)];
  },
  renderText() {
    return `
`;
  },
  addCommands() {
    return {
      setHardBreak: () => ({ commands: t, chain: e, state: n, editor: r }) => t.first([
        () => t.exitCode(),
        () => t.command(() => {
          const { selection: i, storedMarks: s } = n;
          if (i.$from.parent.type.spec.isolating)
            return !1;
          const { keepMarks: o } = this.options, { splittableMarks: a } = r.extensionManager, l = s || i.$to.parentOffset && i.$from.marks();
          return e().insertContent({ type: this.name }).command(({ tr: c, dispatch: d }) => {
            if (d && l && o) {
              const u = l.filter((f) => a.includes(f.type.name));
              c.ensureMarks(u);
            }
            return !0;
          }).run();
        })
      ])
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Enter": () => this.editor.commands.setHardBreak(),
      "Shift-Enter": () => this.editor.commands.setHardBreak()
    };
  }
}), yw = xe.create({
  name: "heading",
  addOptions() {
    return {
      levels: [1, 2, 3, 4, 5, 6],
      HTMLAttributes: {}
    };
  },
  content: "inline*",
  group: "block",
  defining: !0,
  addAttributes() {
    return {
      level: {
        default: 1,
        rendered: !1
      }
    };
  },
  parseHTML() {
    return this.options.levels.map((t) => ({
      tag: `h${t}`,
      attrs: { level: t }
    }));
  },
  renderHTML({ node: t, HTMLAttributes: e }) {
    return [`h${this.options.levels.includes(t.attrs.level) ? t.attrs.level : this.options.levels[0]}`, fe(this.options.HTMLAttributes, e), 0];
  },
  addCommands() {
    return {
      setHeading: (t) => ({ commands: e }) => this.options.levels.includes(t.level) ? e.setNode(this.name, t) : !1,
      toggleHeading: (t) => ({ commands: e }) => this.options.levels.includes(t.level) ? e.toggleNode(this.name, "paragraph", t) : !1
    };
  },
  addKeyboardShortcuts() {
    return this.options.levels.reduce((t, e) => ({
      ...t,
      [`Mod-Alt-${e}`]: () => this.editor.commands.toggleHeading({ level: e })
    }), {});
  },
  addInputRules() {
    return this.options.levels.map((t) => la({
      find: new RegExp(`^(#{1,${t}})\\s$`),
      type: this.type,
      getAttributes: {
        level: t
      }
    }));
  }
});
var hs = 200, He = function() {
};
He.prototype.append = function(e) {
  return e.length ? (e = He.from(e), !this.length && e || e.length < hs && this.leafAppend(e) || this.length < hs && e.leafPrepend(this) || this.appendInner(e)) : this;
};
He.prototype.prepend = function(e) {
  return e.length ? He.from(e).append(this) : this;
};
He.prototype.appendInner = function(e) {
  return new vw(this, e);
};
He.prototype.slice = function(e, n) {
  return e === void 0 && (e = 0), n === void 0 && (n = this.length), e >= n ? He.empty : this.sliceInner(Math.max(0, e), Math.min(this.length, n));
};
He.prototype.get = function(e) {
  if (!(e < 0 || e >= this.length))
    return this.getInner(e);
};
He.prototype.forEach = function(e, n, r) {
  n === void 0 && (n = 0), r === void 0 && (r = this.length), n <= r ? this.forEachInner(e, n, r, 0) : this.forEachInvertedInner(e, n, r, 0);
};
He.prototype.map = function(e, n, r) {
  n === void 0 && (n = 0), r === void 0 && (r = this.length);
  var i = [];
  return this.forEach(function(s, o) {
    return i.push(e(s, o));
  }, n, r), i;
};
He.from = function(e) {
  return e instanceof He ? e : e && e.length ? new ep(e) : He.empty;
};
var ep = /* @__PURE__ */ function(t) {
  function e(r) {
    t.call(this), this.values = r;
  }
  t && (e.__proto__ = t), e.prototype = Object.create(t && t.prototype), e.prototype.constructor = e;
  var n = { length: { configurable: !0 }, depth: { configurable: !0 } };
  return e.prototype.flatten = function() {
    return this.values;
  }, e.prototype.sliceInner = function(i, s) {
    return i == 0 && s == this.length ? this : new e(this.values.slice(i, s));
  }, e.prototype.getInner = function(i) {
    return this.values[i];
  }, e.prototype.forEachInner = function(i, s, o, a) {
    for (var l = s; l < o; l++)
      if (i(this.values[l], a + l) === !1)
        return !1;
  }, e.prototype.forEachInvertedInner = function(i, s, o, a) {
    for (var l = s - 1; l >= o; l--)
      if (i(this.values[l], a + l) === !1)
        return !1;
  }, e.prototype.leafAppend = function(i) {
    if (this.length + i.length <= hs)
      return new e(this.values.concat(i.flatten()));
  }, e.prototype.leafPrepend = function(i) {
    if (this.length + i.length <= hs)
      return new e(i.flatten().concat(this.values));
  }, n.length.get = function() {
    return this.values.length;
  }, n.depth.get = function() {
    return 0;
  }, Object.defineProperties(e.prototype, n), e;
}(He);
He.empty = new ep([]);
var vw = /* @__PURE__ */ function(t) {
  function e(n, r) {
    t.call(this), this.left = n, this.right = r, this.length = n.length + r.length, this.depth = Math.max(n.depth, r.depth) + 1;
  }
  return t && (e.__proto__ = t), e.prototype = Object.create(t && t.prototype), e.prototype.constructor = e, e.prototype.flatten = function() {
    return this.left.flatten().concat(this.right.flatten());
  }, e.prototype.getInner = function(r) {
    return r < this.left.length ? this.left.get(r) : this.right.get(r - this.left.length);
  }, e.prototype.forEachInner = function(r, i, s, o) {
    var a = this.left.length;
    if (i < a && this.left.forEachInner(r, i, Math.min(s, a), o) === !1 || s > a && this.right.forEachInner(r, Math.max(i - a, 0), Math.min(this.length, s) - a, o + a) === !1)
      return !1;
  }, e.prototype.forEachInvertedInner = function(r, i, s, o) {
    var a = this.left.length;
    if (i > a && this.right.forEachInvertedInner(r, i - a, Math.max(s, a) - a, o + a) === !1 || s < a && this.left.forEachInvertedInner(r, Math.min(i, a), s, o) === !1)
      return !1;
  }, e.prototype.sliceInner = function(r, i) {
    if (r == 0 && i == this.length)
      return this;
    var s = this.left.length;
    return i <= s ? this.left.slice(r, i) : r >= s ? this.right.slice(r - s, i - s) : this.left.slice(r, s).append(this.right.slice(0, i - s));
  }, e.prototype.leafAppend = function(r) {
    var i = this.right.leafAppend(r);
    if (i)
      return new e(this.left, i);
  }, e.prototype.leafPrepend = function(r) {
    var i = this.left.leafPrepend(r);
    if (i)
      return new e(i, this.right);
  }, e.prototype.appendInner = function(r) {
    return this.left.depth >= Math.max(this.right.depth, r.depth) + 1 ? new e(this.left, new e(this.right, r)) : new e(this, r);
  }, e;
}(He);
const ww = 500;
class Tt {
  constructor(e, n) {
    this.items = e, this.eventCount = n;
  }
  // Pop the latest event off the branch's history and apply it
  // to a document transform.
  popEvent(e, n) {
    if (this.eventCount == 0)
      return null;
    let r = this.items.length;
    for (; ; r--)
      if (this.items.get(r - 1).selection) {
        --r;
        break;
      }
    let i, s;
    n && (i = this.remapping(r, this.items.length), s = i.maps.length);
    let o = e.tr, a, l, c = [], d = [];
    return this.items.forEach((u, f) => {
      if (!u.step) {
        i || (i = this.remapping(r, f + 1), s = i.maps.length), s--, d.push(u);
        return;
      }
      if (i) {
        d.push(new At(u.map));
        let p = u.step.map(i.slice(s)), h;
        p && o.maybeStep(p).doc && (h = o.mapping.maps[o.mapping.maps.length - 1], c.push(new At(h, void 0, void 0, c.length + d.length))), s--, h && i.appendMap(h, s);
      } else
        o.maybeStep(u.step);
      if (u.selection)
        return a = i ? u.selection.map(i.slice(s)) : u.selection, l = new Tt(this.items.slice(0, r).append(d.reverse().concat(c)), this.eventCount - 1), !1;
    }, this.items.length, 0), { remaining: l, transform: o, selection: a };
  }
  // Create a new branch with the given transform added.
  addTransform(e, n, r, i) {
    let s = [], o = this.eventCount, a = this.items, l = !i && a.length ? a.get(a.length - 1) : null;
    for (let d = 0; d < e.steps.length; d++) {
      let u = e.steps[d].invert(e.docs[d]), f = new At(e.mapping.maps[d], u, n), p;
      (p = l && l.merge(f)) && (f = p, d ? s.pop() : a = a.slice(0, a.length - 1)), s.push(f), n && (o++, n = void 0), i || (l = f);
    }
    let c = o - r.depth;
    return c > xw && (a = Ew(a, c), o -= c), new Tt(a.append(s), o);
  }
  remapping(e, n) {
    let r = new pr();
    return this.items.forEach((i, s) => {
      let o = i.mirrorOffset != null && s - i.mirrorOffset >= e ? r.maps.length - i.mirrorOffset : void 0;
      r.appendMap(i.map, o);
    }, e, n), r;
  }
  addMaps(e) {
    return this.eventCount == 0 ? this : new Tt(this.items.append(e.map((n) => new At(n))), this.eventCount);
  }
  // When the collab module receives remote changes, the history has
  // to know about those, so that it can adjust the steps that were
  // rebased on top of the remote changes, and include the position
  // maps for the remote changes in its array of items.
  rebased(e, n) {
    if (!this.eventCount)
      return this;
    let r = [], i = Math.max(0, this.items.length - n), s = e.mapping, o = e.steps.length, a = this.eventCount;
    this.items.forEach((f) => {
      f.selection && a--;
    }, i);
    let l = n;
    this.items.forEach((f) => {
      let p = s.getMirror(--l);
      if (p == null)
        return;
      o = Math.min(o, p);
      let h = s.maps[p];
      if (f.step) {
        let m = e.steps[p].invert(e.docs[p]), g = f.selection && f.selection.map(s.slice(l + 1, p));
        g && a++, r.push(new At(h, m, g));
      } else
        r.push(new At(h));
    }, i);
    let c = [];
    for (let f = n; f < o; f++)
      c.push(new At(s.maps[f]));
    let d = this.items.slice(0, i).append(c).append(r), u = new Tt(d, a);
    return u.emptyItemCount() > ww && (u = u.compress(this.items.length - r.length)), u;
  }
  emptyItemCount() {
    let e = 0;
    return this.items.forEach((n) => {
      n.step || e++;
    }), e;
  }
  // Compressing a branch means rewriting it to push the air (map-only
  // items) out. During collaboration, these naturally accumulate
  // because each remote change adds one. The `upto` argument is used
  // to ensure that only the items below a given level are compressed,
  // because `rebased` relies on a clean, untouched set of items in
  // order to associate old items with rebased steps.
  compress(e = this.items.length) {
    let n = this.remapping(0, e), r = n.maps.length, i = [], s = 0;
    return this.items.forEach((o, a) => {
      if (a >= e)
        i.push(o), o.selection && s++;
      else if (o.step) {
        let l = o.step.map(n.slice(r)), c = l && l.getMap();
        if (r--, c && n.appendMap(c, r), l) {
          let d = o.selection && o.selection.map(n.slice(r));
          d && s++;
          let u = new At(c.invert(), l, d), f, p = i.length - 1;
          (f = i.length && i[p].merge(u)) ? i[p] = f : i.push(u);
        }
      } else
        o.map && r--;
    }, this.items.length, 0), new Tt(He.from(i.reverse()), s);
  }
}
Tt.empty = new Tt(He.empty, 0);
function Ew(t, e) {
  let n;
  return t.forEach((r, i) => {
    if (r.selection && e-- == 0)
      return n = i, !1;
  }), t.slice(n);
}
class At {
  constructor(e, n, r, i) {
    this.map = e, this.step = n, this.selection = r, this.mirrorOffset = i;
  }
  merge(e) {
    if (this.step && e.step && !e.selection) {
      let n = e.step.merge(this.step);
      if (n)
        return new At(n.getMap().invert(), n, this.selection);
    }
  }
}
class tn {
  constructor(e, n, r, i, s) {
    this.done = e, this.undone = n, this.prevRanges = r, this.prevTime = i, this.prevComposition = s;
  }
}
const xw = 20;
function Sw(t, e, n, r) {
  let i = n.getMeta(gn), s;
  if (i)
    return i.historyState;
  n.getMeta(Mw) && (t = new tn(t.done, t.undone, null, 0, -1));
  let o = n.getMeta("appendedTransaction");
  if (n.steps.length == 0)
    return t;
  if (o && o.getMeta(gn))
    return o.getMeta(gn).redo ? new tn(t.done.addTransform(n, void 0, r, Zi(e)), t.undone, nd(n.mapping.maps[n.steps.length - 1]), t.prevTime, t.prevComposition) : new tn(t.done, t.undone.addTransform(n, void 0, r, Zi(e)), null, t.prevTime, t.prevComposition);
  if (n.getMeta("addToHistory") !== !1 && !(o && o.getMeta("addToHistory") === !1)) {
    let a = n.getMeta("composition"), l = t.prevTime == 0 || !o && t.prevComposition != a && (t.prevTime < (n.time || 0) - r.newGroupDelay || !Cw(n, t.prevRanges)), c = o ? Oo(t.prevRanges, n.mapping) : nd(n.mapping.maps[n.steps.length - 1]);
    return new tn(t.done.addTransform(n, l ? e.selection.getBookmark() : void 0, r, Zi(e)), Tt.empty, c, n.time, a ?? t.prevComposition);
  } else
    return (s = n.getMeta("rebased")) ? new tn(t.done.rebased(n, s), t.undone.rebased(n, s), Oo(t.prevRanges, n.mapping), t.prevTime, t.prevComposition) : new tn(t.done.addMaps(n.mapping.maps), t.undone.addMaps(n.mapping.maps), Oo(t.prevRanges, n.mapping), t.prevTime, t.prevComposition);
}
function Cw(t, e) {
  if (!e)
    return !1;
  if (!t.docChanged)
    return !0;
  let n = !1;
  return t.mapping.maps[0].forEach((r, i) => {
    for (let s = 0; s < e.length; s += 2)
      r <= e[s + 1] && i >= e[s] && (n = !0);
  }), n;
}
function nd(t) {
  let e = [];
  return t.forEach((n, r, i, s) => e.push(i, s)), e;
}
function Oo(t, e) {
  if (!t)
    return null;
  let n = [];
  for (let r = 0; r < t.length; r += 2) {
    let i = e.map(t[r], 1), s = e.map(t[r + 1], -1);
    i <= s && n.push(i, s);
  }
  return n;
}
function tp(t, e, n, r) {
  let i = Zi(e), s = gn.get(e).spec.config, o = (r ? t.undone : t.done).popEvent(e, i);
  if (!o)
    return;
  let a = o.selection.resolve(o.transform.doc), l = (r ? t.done : t.undone).addTransform(o.transform, e.selection.getBookmark(), s, i), c = new tn(r ? l : o.remaining, r ? o.remaining : l, null, 0, -1);
  n(o.transform.setSelection(a).setMeta(gn, { redo: r, historyState: c }).scrollIntoView());
}
let Ro = !1, rd = null;
function Zi(t) {
  let e = t.plugins;
  if (rd != e) {
    Ro = !1, rd = e;
    for (let n = 0; n < e.length; n++)
      if (e[n].spec.historyPreserveItems) {
        Ro = !0;
        break;
      }
  }
  return Ro;
}
const gn = new Me("history"), Mw = new Me("closeHistory");
function kw(t = {}) {
  return t = {
    depth: t.depth || 100,
    newGroupDelay: t.newGroupDelay || 500
  }, new Se({
    key: gn,
    state: {
      init() {
        return new tn(Tt.empty, Tt.empty, null, 0, -1);
      },
      apply(e, n, r) {
        return Sw(n, r, e, t);
      }
    },
    config: t,
    props: {
      handleDOMEvents: {
        beforeinput(e, n) {
          let r = n.inputType, i = r == "historyUndo" ? np : r == "historyRedo" ? rp : null;
          return i ? (n.preventDefault(), i(e.state, e.dispatch)) : !1;
        }
      }
    }
  });
}
const np = (t, e) => {
  let n = gn.getState(t);
  return !n || n.done.eventCount == 0 ? !1 : (e && tp(n, t, e, !1), !0);
}, rp = (t, e) => {
  let n = gn.getState(t);
  return !n || n.undone.eventCount == 0 ? !1 : (e && tp(n, t, e, !0), !0);
}, Tw = Ce.create({
  name: "history",
  addOptions() {
    return {
      depth: 100,
      newGroupDelay: 500
    };
  },
  addCommands() {
    return {
      undo: () => ({ state: t, dispatch: e }) => np(t, e),
      redo: () => ({ state: t, dispatch: e }) => rp(t, e)
    };
  },
  addProseMirrorPlugins() {
    return [
      kw(this.options)
    ];
  },
  addKeyboardShortcuts() {
    return {
      "Mod-z": () => this.editor.commands.undo(),
      "Mod-Z": () => this.editor.commands.undo(),
      "Mod-y": () => this.editor.commands.redo(),
      "Mod-Y": () => this.editor.commands.redo(),
      "Shift-Mod-z": () => this.editor.commands.redo(),
      "Shift-Mod-Z": () => this.editor.commands.redo(),
      // Russian keyboard layouts
      "Mod-я": () => this.editor.commands.undo(),
      "Shift-Mod-я": () => this.editor.commands.redo()
    };
  }
}), _w = xe.create({
  name: "horizontalRule",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  group: "block",
  parseHTML() {
    return [{ tag: "hr" }];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["hr", fe(this.options.HTMLAttributes, t)];
  },
  addCommands() {
    return {
      setHorizontalRule: () => ({ chain: t, state: e }) => {
        const { $to: n } = e.selection, r = t();
        return n.parentOffset === 0 ? r.insertContentAt(Math.max(n.pos - 2, 0), { type: this.name }) : r.insertContent({ type: this.name }), r.command(({ tr: i, dispatch: s }) => {
          var o;
          if (s) {
            const { $to: a } = i.selection, l = a.end();
            if (a.nodeAfter)
              a.nodeAfter.isTextblock ? i.setSelection(G.create(i.doc, a.pos + 1)) : a.nodeAfter.isBlock ? i.setSelection(Y.create(i.doc, a.pos)) : i.setSelection(G.create(i.doc, a.pos));
            else {
              const c = (o = a.parent.type.contentMatch.defaultType) === null || o === void 0 ? void 0 : o.create();
              c && (i.insert(l, c), i.setSelection(G.create(i.doc, l + 1)));
            }
            i.scrollIntoView();
          }
          return !0;
        }).run();
      }
    };
  },
  addInputRules() {
    return [
      Ga({
        find: /^(?:---|—-|___\s|\*\*\*\s)$/,
        type: this.type
      })
    ];
  }
}), Nw = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/, Aw = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/g, Ow = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/, Rw = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/g, Lw = qe.create({
  name: "italic",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "em"
      },
      {
        tag: "i",
        getAttrs: (t) => t.style.fontStyle !== "normal" && null
      },
      {
        style: "font-style=italic"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["em", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setItalic: () => ({ commands: t }) => t.setMark(this.name),
      toggleItalic: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetItalic: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-i": () => this.editor.commands.toggleItalic(),
      "Mod-I": () => this.editor.commands.toggleItalic()
    };
  },
  addInputRules() {
    return [
      Un({
        find: Nw,
        type: this.type
      }),
      Un({
        find: Ow,
        type: this.type
      })
    ];
  },
  addPasteRules() {
    return [
      yn({
        find: Aw,
        type: this.type
      }),
      yn({
        find: Rw,
        type: this.type
      })
    ];
  }
}), Iw = xe.create({
  name: "listItem",
  addOptions() {
    return {
      HTMLAttributes: {},
      bulletListTypeName: "bulletList",
      orderedListTypeName: "orderedList"
    };
  },
  content: "paragraph block*",
  defining: !0,
  parseHTML() {
    return [
      {
        tag: "li"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["li", fe(this.options.HTMLAttributes, t), 0];
  },
  addKeyboardShortcuts() {
    return {
      Enter: () => this.editor.commands.splitListItem(this.name),
      Tab: () => this.editor.commands.sinkListItem(this.name),
      "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
    };
  }
}), Dw = xe.create({
  name: "listItem",
  addOptions() {
    return {
      HTMLAttributes: {},
      bulletListTypeName: "bulletList",
      orderedListTypeName: "orderedList"
    };
  },
  content: "paragraph block*",
  defining: !0,
  parseHTML() {
    return [
      {
        tag: "li"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["li", fe(this.options.HTMLAttributes, t), 0];
  },
  addKeyboardShortcuts() {
    return {
      Enter: () => this.editor.commands.splitListItem(this.name),
      Tab: () => this.editor.commands.sinkListItem(this.name),
      "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
    };
  }
}), id = qe.create({
  name: "textStyle",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "span",
        getAttrs: (t) => t.hasAttribute("style") ? {} : !1
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["span", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      removeEmptyTextStyle: () => ({ state: t, commands: e }) => {
        const n = vi(t, this.type);
        return Object.entries(n).some(([, i]) => !!i) ? !0 : e.unsetMark(this.name);
      }
    };
  }
}), sd = /^(\d+)\.\s$/, Hw = xe.create({
  name: "orderedList",
  addOptions() {
    return {
      itemTypeName: "listItem",
      HTMLAttributes: {},
      keepMarks: !1,
      keepAttributes: !1
    };
  },
  group: "block list",
  content() {
    return `${this.options.itemTypeName}+`;
  },
  addAttributes() {
    return {
      start: {
        default: 1,
        parseHTML: (t) => t.hasAttribute("start") ? parseInt(t.getAttribute("start") || "", 10) : 1
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: "ol"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    const { start: e, ...n } = t;
    return e === 1 ? ["ol", fe(this.options.HTMLAttributes, n), 0] : ["ol", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      toggleOrderedList: () => ({ commands: t, chain: e }) => this.options.keepAttributes ? e().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(Dw.name, this.editor.getAttributes(id.name)).run() : t.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
    };
  },
  addInputRules() {
    let t = Sr({
      find: sd,
      type: this.type,
      getAttributes: (e) => ({ start: +e[1] }),
      joinPredicate: (e, n) => n.childCount + n.attrs.start === +e[1]
    });
    return (this.options.keepMarks || this.options.keepAttributes) && (t = Sr({
      find: sd,
      type: this.type,
      keepMarks: this.options.keepMarks,
      keepAttributes: this.options.keepAttributes,
      getAttributes: (e) => ({ start: +e[1], ...this.editor.getAttributes(id.name) }),
      joinPredicate: (e, n) => n.childCount + n.attrs.start === +e[1],
      editor: this.editor
    })), [
      t
    ];
  }
}), Bw = xe.create({
  name: "paragraph",
  priority: 1e3,
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  group: "block",
  content: "inline*",
  parseHTML() {
    return [
      { tag: "p" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["p", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setParagraph: () => ({ commands: t }) => t.setNode(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Alt-0": () => this.editor.commands.setParagraph()
    };
  }
}), Pw = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/, $w = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/g, Vw = qe.create({
  name: "strike",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "s"
      },
      {
        tag: "del"
      },
      {
        tag: "strike"
      },
      {
        style: "text-decoration",
        consuming: !1,
        getAttrs: (t) => t.includes("line-through") ? {} : !1
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["s", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setStrike: () => ({ commands: t }) => t.setMark(this.name),
      toggleStrike: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetStrike: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    const t = {};
    return Wa() ? t["Mod-Shift-s"] = () => this.editor.commands.toggleStrike() : t["Ctrl-Shift-s"] = () => this.editor.commands.toggleStrike(), t;
  },
  addInputRules() {
    return [
      Un({
        find: Pw,
        type: this.type
      })
    ];
  },
  addPasteRules() {
    return [
      yn({
        find: $w,
        type: this.type
      })
    ];
  }
}), zw = xe.create({
  name: "text",
  group: "inline"
}), od = Ce.create({
  name: "starterKit",
  addExtensions() {
    var t, e, n, r, i, s, o, a, l, c, d, u, f, p, h, m, g, v;
    const y = [];
    return this.options.blockquote !== !1 && y.push(qv.configure((t = this.options) === null || t === void 0 ? void 0 : t.blockquote)), this.options.bold !== !1 && y.push(Jv.configure((e = this.options) === null || e === void 0 ? void 0 : e.bold)), this.options.bulletList !== !1 && y.push(Qv.configure((n = this.options) === null || n === void 0 ? void 0 : n.bulletList)), this.options.code !== !1 && y.push(nw.configure((r = this.options) === null || r === void 0 ? void 0 : r.code)), this.options.codeBlock !== !1 && y.push(Qf.configure((i = this.options) === null || i === void 0 ? void 0 : i.codeBlock)), this.options.document !== !1 && y.push(sw.configure((s = this.options) === null || s === void 0 ? void 0 : s.document)), this.options.dropcursor !== !1 && y.push(lw.configure((o = this.options) === null || o === void 0 ? void 0 : o.dropcursor)), this.options.gapcursor !== !1 && y.push(gw.configure((a = this.options) === null || a === void 0 ? void 0 : a.gapcursor)), this.options.hardBreak !== !1 && y.push(bw.configure((l = this.options) === null || l === void 0 ? void 0 : l.hardBreak)), this.options.heading !== !1 && y.push(yw.configure((c = this.options) === null || c === void 0 ? void 0 : c.heading)), this.options.history !== !1 && y.push(Tw.configure((d = this.options) === null || d === void 0 ? void 0 : d.history)), this.options.horizontalRule !== !1 && y.push(_w.configure((u = this.options) === null || u === void 0 ? void 0 : u.horizontalRule)), this.options.italic !== !1 && y.push(Lw.configure((f = this.options) === null || f === void 0 ? void 0 : f.italic)), this.options.listItem !== !1 && y.push(Iw.configure((p = this.options) === null || p === void 0 ? void 0 : p.listItem)), this.options.orderedList !== !1 && y.push(Hw.configure((h = this.options) === null || h === void 0 ? void 0 : h.orderedList)), this.options.paragraph !== !1 && y.push(Bw.configure((m = this.options) === null || m === void 0 ? void 0 : m.paragraph)), this.options.strike !== !1 && y.push(Vw.configure((g = this.options) === null || g === void 0 ? void 0 : g.strike)), this.options.text !== !1 && y.push(zw.configure((v = this.options) === null || v === void 0 ? void 0 : v.text)), y;
  }
}), Fw = qe.create({
  name: "underline",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "u"
      },
      {
        style: "text-decoration",
        consuming: !1,
        getAttrs: (t) => t.includes("underline") ? {} : !1
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["u", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setUnderline: () => ({ commands: t }) => t.setMark(this.name),
      toggleUnderline: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetUnderline: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-u": () => this.editor.commands.toggleUnderline(),
      "Mod-U": () => this.editor.commands.toggleUnderline()
    };
  }
}), Uw = qe.create({
  name: "textStyle",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "span",
        getAttrs: (t) => t.hasAttribute("style") ? {} : !1
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["span", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      removeEmptyTextStyle: () => ({ state: t, commands: e }) => {
        const n = vi(t, this.type);
        return Object.entries(n).some(([, i]) => !!i) ? !0 : e.unsetMark(this.name);
      }
    };
  }
}), Kw = Ce.create({
  name: "fontFamily",
  addOptions() {
    return {
      types: ["textStyle"]
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          fontFamily: {
            default: null,
            parseHTML: (t) => {
              var e;
              return (e = t.style.fontFamily) === null || e === void 0 ? void 0 : e.replace(/['"]+/g, "");
            },
            renderHTML: (t) => t.fontFamily ? {
              style: `font-family: ${t.fontFamily}`
            } : {}
          }
        }
      }
    ];
  },
  addCommands() {
    return {
      setFontFamily: (t) => ({ chain: e }) => e().setMark("textStyle", { fontFamily: t }).run(),
      unsetFontFamily: () => ({ chain: t }) => t().setMark("textStyle", { fontFamily: null }).removeEmptyTextStyle().run()
    };
  }
}), ip = (t) => {
  const e = document.createElement("div");
  return e.classList.add("aie-loader-placeholder"), e.innerHTML = `
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 3C16.9706 3 21 7.02944 21 12H19C19 8.13401 15.866 5 12 5V3Z"></path></svg>
    `, Le.widget(t.pos, e, { id: t.id });
}, Ww = (t) => {
  const e = document.createElement("div");
  return e.classList.add("aie-loader-placeholder"), e.style.height = "20px", e.style.display = "inline-block", e.innerHTML = `
    <svg style="width: 16px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 3C16.9706 3 21 7.02944 21 12H19C19 8.13401 15.866 5 12 5V3Z"></path></svg>
   ${t.text}
    `, Le.widget(t.pos, e, { id: t.id });
}, qw = (t, e, n, r) => {
  const i = new FormData();
  return i.append(r, t), new Promise((s, o) => {
    fetch(e, {
      method: "post",
      headers: { Accept: "application/json", ...n },
      body: i
    }).then((a) => a.json()).then((a) => {
      s(a);
    }).catch((a) => {
      o(a);
    });
  });
}, Zw = (t, e, n, r) => {
  let i = new FileReader();
  return new Promise((s, o) => {
    i.onload = () => s({ errorCode: 0, data: { src: i.result } }), i.onerror = () => o(i.error), setTimeout(() => i.readAsDataURL(t), 1500);
  });
}, ol = (t) => t ? qw : Zw, ad = new Me("aie-attachment-plugin"), Dr = "attachment_action", Gw = Ce.create({
  name: "attachment",
  addOptions() {
    return {
      uploadUrl: "",
      uploadHeaders: {},
      HTMLAttributes: {}
    };
  },
  addCommands() {
    return {
      uploadAttachment: (t) => () => {
        const e = Zs(), { state: { tr: n }, view: r, schema: i } = this.editor;
        return n.selection.empty || n.deleteSelection(), r.dispatch(n.setMeta(Dr, {
          type: "add",
          id: e,
          pos: n.selection.from,
          text: t.name
        })), (this.options.uploader || ol(this.options.uploadUrl))(t, this.options.uploadUrl, this.options.uploadHeaders, "attachment").then((o) => {
          if (o.errorCode === 0 && o.data && o.data.href) {
            let l = ad.getState(this.editor.state).find(void 0, void 0, (d) => d.id == e);
            const c = o.data.fileName || t.name;
            r.dispatch(r.state.tr.insertText(` ${c} `, l[0].from).addMark(l[0].from + 1, c.length + l[0].from + 1, i.marks.link.create({
              href: o.href
            })).setMeta(Dr, { type: "remove", id: e }));
          } else
            r.dispatch(n.setMeta(Dr, { type: "remove", id: e }));
        }).catch(() => {
          r.dispatch(n.setMeta(Dr, { type: "remove", id: e }));
        }), !0;
      }
    };
  },
  addProseMirrorPlugins() {
    const t = this.editor;
    return [
      new Se({
        key: ad,
        state: {
          init: () => we.empty,
          apply: (e, n) => {
            const r = e.getMeta(Dr);
            return n = n.map(e.mapping, e.doc), r && r.type === "add" ? n = n.add(e.doc, [Ww(r)]) : r && r.type === "remove" && (n = n.remove(n.find(
              void 0,
              void 0,
              (i) => i.id == r.id
            ))), n;
          }
        },
        props: {
          decorations(e) {
            return this.getState(e);
          },
          handleDOMEvents: {
            drop(e, n) {
              if (!(n.dataTransfer && n.dataTransfer.files && n.dataTransfer.files.length))
                return !1;
              const i = Array.from(n.dataTransfer.files).filter((s) => !/video/i.test(s.type) && !/image/i.test(s.type));
              return n.preventDefault(), i.forEach((s) => {
                t.commands.uploadAttachment(s);
              }), !0;
            }
          }
        }
      })
    ];
  }
}), jw = Ce.create({
  name: "painter",
  addCommands() {
    return {
      setPainter: (t) => ({ view: { dispatch: e, state: { tr: n }, dom: r } }) => (r.style.cursor = "context-menu", e(n.setMeta("painterAction", { type: "start", marks: t })), !0)
    };
  },
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("aie-painter"),
        state: {
          init: () => [],
          apply: (t, e) => {
            const n = t.getMeta("painterAction");
            return n && n.type === "start" ? e = n.marks : n && n.type === "end" && (e = []), e;
          }
        },
        props: {
          handleDOMEvents: {
            mousedown(t, e) {
              const n = this.getState(t.state);
              if (!n || n.length == 0)
                return !1;
              const r = () => {
                document.removeEventListener("mouseup", r);
                let { dispatch: i, state: { tr: s, selection: o }, dom: a } = t;
                a.style.cursor = "", s = s.removeMark(o.from, o.to);
                for (let l of n)
                  l.type.name != "link" && (s = s.addMark(o.from, o.to, l));
                i(s.setMeta("painterAction", { type: "end" }));
              };
              return document.addEventListener("mouseup", r), !0;
            }
          }
        }
      })
    ];
  }
}), Yw = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/, Jw = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g, Xw = qe.create({
  name: "highlight",
  addOptions() {
    return {
      multicolor: !1,
      HTMLAttributes: {}
    };
  },
  addAttributes() {
    return this.options.multicolor ? {
      color: {
        default: null,
        parseHTML: (t) => t.getAttribute("data-color") || t.style.backgroundColor,
        renderHTML: (t) => t.color ? {
          "data-color": t.color,
          style: `background-color: ${t.color}; color: inherit`
        } : {}
      }
    } : {};
  },
  parseHTML() {
    return [
      {
        tag: "mark"
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["mark", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setHighlight: (t) => ({ commands: e }) => e.setMark(this.name, t),
      toggleHighlight: (t) => ({ commands: e }) => e.toggleMark(this.name, t),
      unsetHighlight: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-h": () => this.editor.commands.toggleHighlight()
    };
  },
  addInputRules() {
    return [
      Un({
        find: Yw,
        type: this.type
      })
    ];
  },
  addPasteRules() {
    return [
      yn({
        find: Jw,
        type: this.type
      })
    ];
  }
}), Qw = Ce.create({
  name: "color",
  addOptions() {
    return {
      types: ["textStyle"]
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          color: {
            default: null,
            parseHTML: (t) => {
              var e;
              return (e = t.style.color) === null || e === void 0 ? void 0 : e.replace(/['"]+/g, "");
            },
            renderHTML: (t) => t.color ? {
              style: `color: ${t.color}`
            } : {}
          }
        }
      }
    ];
  },
  addCommands() {
    return {
      setColor: (t) => ({ chain: e }) => e().setMark("textStyle", { color: t }).run(),
      unsetColor: () => ({ chain: t }) => t().setMark("textStyle", { color: null }).removeEmptyTextStyle().run()
    };
  }
}), eE = Ce.create({
  name: "fontSize",
  addOptions() {
    return {
      types: ["textStyle"]
    };
  },
  onBeforeCreate() {
    console.log("onBeforeCreate");
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          fontSize: {
            default: null,
            parseHTML: (t) => {
              var e;
              return (e = t.style.fontSize) == null ? void 0 : e.replace(/['"]+/g, "");
            },
            renderHTML: (t) => t.fontSize ? {
              style: `font-size: ${t.fontSize}`
            } : {}
          }
        }
      }
    ];
  },
  addCommands() {
    return {
      setFontSize: (t) => ({ chain: e }) => e().setMark("textStyle", { fontSize: t }).run(),
      unsetFontSize: () => ({ chain: t }) => t().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run()
    };
  }
}), tE = Ce.create({
  name: "lineHeight",
  addOptions() {
    return {
      types: ["heading", "paragraph"],
      heights: ["100%", "125%", "150%", "200%", "250%", "300%"],
      defaultHeight: "100%"
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          lineHeight: {
            default: this.options.defaultHeight,
            parseHTML: (t) => t.style.lineHeight || this.options.defaultHeight,
            renderHTML: (t) => t.lineHeight === this.options.defaultHeight ? {} : { style: `line-height: ${t.lineHeight}` }
          }
        }
      }
    ];
  },
  addCommands() {
    return {
      setLineHeight: (t) => ({ commands: e }) => this.options.heights.includes(t) ? this.options.types.every(
        (n) => e.updateAttributes(n, { lineHeight: t })
      ) : !1,
      unsetLineHeight: () => ({ commands: t }) => this.options.types.every(
        (e) => t.resetAttributes(e, "lineHeight")
      )
    };
  }
}), nE = Ce.create({
  name: "textAlign",
  addOptions() {
    return {
      types: [],
      alignments: ["left", "center", "right", "justify"],
      defaultAlignment: "left"
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          textAlign: {
            default: this.options.defaultAlignment,
            parseHTML: (t) => t.style.textAlign || this.options.defaultAlignment,
            renderHTML: (t) => t.textAlign === this.options.defaultAlignment ? {} : { style: `text-align: ${t.textAlign}` }
          }
        }
      }
    ];
  },
  addCommands() {
    return {
      setTextAlign: (t) => ({ commands: e }) => this.options.alignments.includes(t) ? this.options.types.every((n) => e.updateAttributes(n, { textAlign: t })) : !1,
      unsetTextAlign: () => ({ commands: t }) => this.options.types.every((e) => t.resetAttributes(e, "textAlign"))
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-l": () => this.editor.commands.setTextAlign("left"),
      "Mod-Shift-e": () => this.editor.commands.setTextAlign("center"),
      "Mod-Shift-r": () => this.editor.commands.setTextAlign("right"),
      "Mod-Shift-j": () => this.editor.commands.setTextAlign("justify")
    };
  }
}), rE = Ce.create({
  name: "indent",
  addOptions() {
    return {
      types: ["listItem", "paragraph"],
      minLevel: 0,
      maxLevel: 8
    };
  },
  addGlobalAttributes() {
    return [
      {
        types: this.options.types,
        attributes: {
          indent: {
            default: 0,
            parseHTML: (t) => {
              const e = Number(t.getAttribute("data-indent"));
              return e && e > this.options.minLevel ? e : null;
            },
            renderHTML: (t) => t.indent ? {
              style: `text-indent: ${(t == null ? void 0 : t.indent) * 10}px`,
              "data-indent": t == null ? void 0 : t.indent
            } : {}
          }
        }
      }
    ];
  },
  addCommands() {
    const t = (r, i, s) => {
      var a;
      const o = (a = r == null ? void 0 : r.doc) == null ? void 0 : a.nodeAt(i);
      if (o) {
        const l = (o.attrs.indent || 0) + s, { minLevel: c, maxLevel: d } = this.options, u = l < c ? c : l > d ? d : l;
        if (u !== o.attrs.indent) {
          const { indent: f, ...p } = o.attrs, h = u > c ? { ...p, indent: u } : p;
          return r.setNodeMarkup(i, o.type, h, o.marks);
        }
      }
      return r;
    }, e = (r, i) => {
      const { doc: s, selection: o } = r;
      if (s && o && (o instanceof G || o instanceof wt)) {
        const { from: a, to: l } = o;
        s.nodesBetween(a, l, (c, d) => this.options.types.includes(c.type.name) ? (r = t(r, d, i), !1) : !0);
      }
      return r;
    }, n = (r) => () => ({ tr: i, state: s, dispatch: o }) => {
      const { selection: a } = s;
      return i = i.setSelection(a), i = e(i, r), i.docChanged ? (o == null || o(i), !0) : !1;
    };
    return {
      indent: n(1),
      outdent: n(-1)
    };
  },
  addKeyboardShortcuts() {
    return {
      Tab: () => this.editor.commands.indent(),
      "Shift-Tab": () => this.editor.commands.outdent()
    };
  }
}), iE = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/, sE = xe.create({
  name: "image",
  addOptions() {
    return {
      inline: !1,
      allowBase64: !1,
      HTMLAttributes: {}
    };
  },
  inline() {
    return this.options.inline;
  },
  group() {
    return this.options.inline ? "inline" : "block";
  },
  draggable: !0,
  addAttributes() {
    return {
      src: {
        default: null
      },
      alt: {
        default: null
      },
      title: {
        default: null
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["img", fe(this.options.HTMLAttributes, t)];
  },
  addCommands() {
    return {
      setImage: (t) => ({ commands: e }) => e.insertContent({
        type: this.name,
        attrs: t
      })
    };
  },
  addInputRules() {
    return [
      Ga({
        find: iE,
        type: this.type,
        getAttributes: (t) => {
          const [, , e, n, r] = t;
          return { src: n, alt: e, title: r };
        }
      })
    ];
  }
}), sp = (t, e, n) => {
  const r = t.querySelector(".resize-obj"), i = 10;
  let s, o, a, l;
  const c = (f) => {
    f.preventDefault(), e.addEventListener("mousemove", d), e.addEventListener("mouseup", u), e.addEventListener("mouseleave", u), s = f.clientX, o = Number(r.getAttribute("data-with")) || r.clientWidth, a = f.target.getAttribute("data-position"), l = e.clientWidth - 100;
  }, d = (f) => {
    const p = f.clientX - s;
    if (p == 0)
      return;
    const h = a === "right" ? p > 0 : p < 0;
    let m = o + Math.abs(p) * (h ? 1 : -1);
    m >= l && (m = l), m < i && (m = i), r.style.width = `${m}px`, r.setAttribute("data-width", m.toString());
  }, u = () => {
    e.removeEventListener("mousemove", d), e.removeEventListener("mouseup", u), e.removeEventListener("mouseleave", u);
    const f = { width: Number(r.getAttribute("data-width")) };
    n(f);
  };
  for (let f of t.querySelector(".aie-resize").children)
    f.addEventListener("mousedown", c);
}, ld = new Me("aie-image-plugin"), Hr = "image_action", oE = sE.extend(
  {
    name: "image",
    draggable: !0,
    selectable: !0,
    addOptions() {
      var t;
      return {
        ...(t = this.parent) == null ? void 0 : t.call(this),
        uploadUrl: "",
        uploadHeaders: {},
        uploader: void 0
      };
    },
    allowGapCursor() {
      return !this.options.inline;
    },
    addAttributes() {
      return {
        src: {
          default: "",
          parseHTML: (t) => `${t.getAttribute("src") ?? ""}`
        },
        alt: {
          default: ""
        },
        title: {
          default: ""
        },
        width: {
          default: 350
        },
        height: {
          default: "auto"
        },
        align: {
          default: "left"
        }
      };
    },
    parseHTML() {
      return [
        {
          tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])'
        }
      ];
    },
    renderHTML({ HTMLAttributes: t }) {
      return [
        "img",
        fe(this.options.HTMLAttributes, t)
      ];
    },
    addCommands() {
      var t;
      return {
        ...(t = this.parent) == null ? void 0 : t.call(this),
        uploadImage: (e) => () => {
          const n = Zs(), { state: { tr: r }, view: i, schema: s } = this.editor;
          return r.selection.empty || r.deleteSelection(), i.dispatch(r.setMeta(Hr, {
            type: "add",
            id: n,
            pos: r.selection.from
          })), (this.options.uploader || ol(this.options.uploadUrl))(e, this.options.uploadUrl, this.options.uploadHeaders, "image").then((a) => {
            if (a.errorCode === 0 && a.data && a.data.src) {
              let c = ld.getState(this.editor.state).find(void 0, void 0, (d) => d.id == n);
              i.dispatch(i.state.tr.insert(c[0].from, s.nodes.image.create({
                src: a.data.src,
                alt: a.data.alt
              })).setMeta(Hr, { type: "remove", id: n }));
            } else
              i.dispatch(r.setMeta(Hr, { type: "remove", id: n }));
          }).catch(() => {
            i.dispatch(r.setMeta(Hr, { type: "remove", id: n }));
          }), !0;
        }
      };
    },
    addNodeView() {
      return (t) => {
        const e = document.createElement("div"), { src: n, width: r, height: i, align: s } = t.node.attrs;
        return e.classList.add(`align-${s}`), e.innerHTML = `
                    <div class="aie-resize-wrapper">
                        <div class="aie-resize">
                            <div class="aie-resize-btn-top-left" data-position="left" draggable="true"></div>
                            <div class="aie-resize-btn-top-right" data-position="right" draggable="true"></div>
                            <div class="aie-resize-btn-bottom-left" data-position="left" draggable="true"></div>
                            <div class="aie-resize-btn-bottom-right" data-position="right" draggable="true"></div>
                        </div>
                        <img src="${n}" style="width: ${r}px; height: ${i}" class="align-${s} resize-obj">
                    </div>
                `, sp(e, t.editor.view.dom, (o) => t.editor.commands.updateAttributes("image", o)), {
          dom: e
        };
      };
    },
    addProseMirrorPlugins() {
      const t = this.editor;
      return [
        new Se({
          key: ld,
          state: {
            init: () => we.empty,
            apply: (e, n) => {
              const r = e.getMeta(Hr);
              return n = n.map(e.mapping, e.doc), r && r.type === "add" ? n = n.add(e.doc, [ip(r)]) : r && r.type === "remove" && (n = n.remove(n.find(
                void 0,
                void 0,
                (i) => i.id == r.id
              ))), n;
            }
          },
          props: {
            decorations(e) {
              return this.getState(e);
            },
            handleDOMEvents: {
              drop(e, n) {
                if (!(n.dataTransfer && n.dataTransfer.files && n.dataTransfer.files.length))
                  return !1;
                const i = Array.from(n.dataTransfer.files).filter((c) => /image/i.test(c.type));
                if (i.length === 0)
                  return !1;
                n.preventDefault();
                const { state: { tr: s, doc: o }, dispatch: a } = e, l = e.posAtCoords({ left: n.clientX, top: n.clientY });
                return a(s.setSelection(G.create(o, l.pos)).scrollIntoView()), i.forEach((c) => {
                  t.commands.uploadImage(c);
                }), !0;
              }
            }
          }
        })
      ];
    }
  }
);
var ha, ma;
if (typeof WeakMap < "u") {
  let t = /* @__PURE__ */ new WeakMap();
  ha = (e) => t.get(e), ma = (e, n) => (t.set(e, n), n);
} else {
  const t = [];
  let n = 0;
  ha = (r) => {
    for (let i = 0; i < t.length; i += 2)
      if (t[i] == r)
        return t[i + 1];
  }, ma = (r, i) => (n == 10 && (n = 0), t[n++] = r, t[n++] = i);
}
var _e = class {
  constructor(t, e, n, r) {
    this.width = t, this.height = e, this.map = n, this.problems = r;
  }
  // Find the dimensions of the cell at the given position.
  findCell(t) {
    for (let e = 0; e < this.map.length; e++) {
      const n = this.map[e];
      if (n != t)
        continue;
      const r = e % this.width, i = e / this.width | 0;
      let s = r + 1, o = i + 1;
      for (let a = 1; s < this.width && this.map[e + a] == n; a++)
        s++;
      for (let a = 1; o < this.height && this.map[e + this.width * a] == n; a++)
        o++;
      return { left: r, top: i, right: s, bottom: o };
    }
    throw new RangeError(`No cell with offset ${t} found`);
  }
  // Find the left side of the cell at the given position.
  colCount(t) {
    for (let e = 0; e < this.map.length; e++)
      if (this.map[e] == t)
        return e % this.width;
    throw new RangeError(`No cell with offset ${t} found`);
  }
  // Find the next cell in the given direction, starting from the cell
  // at `pos`, if any.
  nextCell(t, e, n) {
    const { left: r, right: i, top: s, bottom: o } = this.findCell(t);
    return e == "horiz" ? (n < 0 ? r == 0 : i == this.width) ? null : this.map[s * this.width + (n < 0 ? r - 1 : i)] : (n < 0 ? s == 0 : o == this.height) ? null : this.map[r + this.width * (n < 0 ? s - 1 : o)];
  }
  // Get the rectangle spanning the two given cells.
  rectBetween(t, e) {
    const {
      left: n,
      right: r,
      top: i,
      bottom: s
    } = this.findCell(t), {
      left: o,
      right: a,
      top: l,
      bottom: c
    } = this.findCell(e);
    return {
      left: Math.min(n, o),
      top: Math.min(i, l),
      right: Math.max(r, a),
      bottom: Math.max(s, c)
    };
  }
  // Return the position of all cells that have the top left corner in
  // the given rectangle.
  cellsInRect(t) {
    const e = [], n = {};
    for (let r = t.top; r < t.bottom; r++)
      for (let i = t.left; i < t.right; i++) {
        const s = r * this.width + i, o = this.map[s];
        n[o] || (n[o] = !0, !(i == t.left && i && this.map[s - 1] == o || r == t.top && r && this.map[s - this.width] == o) && e.push(o));
      }
    return e;
  }
  // Return the position at which the cell at the given row and column
  // starts, or would start, if a cell started there.
  positionAt(t, e, n) {
    for (let r = 0, i = 0; ; r++) {
      const s = i + n.child(r).nodeSize;
      if (r == t) {
        let o = e + t * this.width;
        const a = (t + 1) * this.width;
        for (; o < a && this.map[o] < i; )
          o++;
        return o == a ? s - 1 : this.map[o];
      }
      i = s;
    }
  }
  // Find the table map for the given table node.
  static get(t) {
    return ha(t) || ma(t, aE(t));
  }
};
function aE(t) {
  if (t.type.spec.tableRole != "table")
    throw new RangeError("Not a table node: " + t.type.name);
  const e = lE(t), n = t.childCount, r = [];
  let i = 0, s = null;
  const o = [];
  for (let c = 0, d = e * n; c < d; c++)
    r[c] = 0;
  for (let c = 0, d = 0; c < n; c++) {
    const u = t.child(c);
    d++;
    for (let h = 0; ; h++) {
      for (; i < r.length && r[i] != 0; )
        i++;
      if (h == u.childCount)
        break;
      const m = u.child(h), { colspan: g, rowspan: v, colwidth: y } = m.attrs;
      for (let E = 0; E < v; E++) {
        if (E + c >= n) {
          (s || (s = [])).push({
            type: "overlong_rowspan",
            pos: d,
            n: v - E
          });
          break;
        }
        const b = i + E * e;
        for (let C = 0; C < g; C++) {
          r[b + C] == 0 ? r[b + C] = d : (s || (s = [])).push({
            type: "collision",
            row: c,
            pos: d,
            n: g - C
          });
          const w = y && y[C];
          if (w) {
            const _ = (b + C) % e * 2, R = o[_];
            R == null || R != w && o[_ + 1] == 1 ? (o[_] = w, o[_ + 1] = 1) : R == w && o[_ + 1]++;
          }
        }
      }
      i += g, d += m.nodeSize;
    }
    const f = (c + 1) * e;
    let p = 0;
    for (; i < f; )
      r[i++] == 0 && p++;
    p && (s || (s = [])).push({ type: "missing", row: c, n: p }), d++;
  }
  const a = new _e(e, n, r, s);
  let l = !1;
  for (let c = 0; !l && c < o.length; c += 2)
    o[c] != null && o[c + 1] < n && (l = !0);
  return l && cE(a, o, t), a;
}
function lE(t) {
  let e = -1, n = !1;
  for (let r = 0; r < t.childCount; r++) {
    const i = t.child(r);
    let s = 0;
    if (n)
      for (let o = 0; o < r; o++) {
        const a = t.child(o);
        for (let l = 0; l < a.childCount; l++) {
          const c = a.child(l);
          o + c.attrs.rowspan > r && (s += c.attrs.colspan);
        }
      }
    for (let o = 0; o < i.childCount; o++) {
      const a = i.child(o);
      s += a.attrs.colspan, a.attrs.rowspan > 1 && (n = !0);
    }
    e == -1 ? e = s : e != s && (e = Math.max(e, s));
  }
  return e;
}
function cE(t, e, n) {
  t.problems || (t.problems = []);
  const r = {};
  for (let i = 0; i < t.map.length; i++) {
    const s = t.map[i];
    if (r[s])
      continue;
    r[s] = !0;
    const o = n.nodeAt(s);
    if (!o)
      throw new RangeError(`No cell with offset ${s} found`);
    let a = null;
    const l = o.attrs;
    for (let c = 0; c < l.colspan; c++) {
      const d = (i + c) % t.width, u = e[d * 2];
      u != null && (!l.colwidth || l.colwidth[c] != u) && ((a || (a = dE(l)))[c] = u);
    }
    a && t.problems.unshift({
      type: "colwidth mismatch",
      pos: s,
      colwidth: a
    });
  }
}
function dE(t) {
  if (t.colwidth)
    return t.colwidth.slice();
  const e = [];
  for (let n = 0; n < t.colspan; n++)
    e.push(0);
  return e;
}
function Ze(t) {
  let e = t.cached.tableNodeTypes;
  if (!e) {
    e = t.cached.tableNodeTypes = {};
    for (const n in t.nodes) {
      const r = t.nodes[n], i = r.spec.tableRole;
      i && (e[i] = r);
    }
  }
  return e;
}
var sn = new Me("selectingCells");
function Rr(t) {
  for (let e = t.depth - 1; e > 0; e--)
    if (t.node(e).type.spec.tableRole == "row")
      return t.node(0).resolve(t.before(e + 1));
  return null;
}
function uE(t) {
  for (let e = t.depth; e > 0; e--) {
    const n = t.node(e).type.spec.tableRole;
    if (n === "cell" || n === "header_cell")
      return t.node(e);
  }
  return null;
}
function Nt(t) {
  const e = t.selection.$head;
  for (let n = e.depth; n > 0; n--)
    if (e.node(n).type.spec.tableRole == "row")
      return !0;
  return !1;
}
function js(t) {
  const e = t.selection;
  if ("$anchorCell" in e && e.$anchorCell)
    return e.$anchorCell.pos > e.$headCell.pos ? e.$anchorCell : e.$headCell;
  if ("node" in e && e.node && e.node.type.spec.tableRole == "cell")
    return e.$anchor;
  const n = Rr(e.$head) || fE(e.$head);
  if (n)
    return n;
  throw new RangeError(`No cell found around position ${e.head}`);
}
function fE(t) {
  for (let e = t.nodeAfter, n = t.pos; e; e = e.firstChild, n++) {
    const r = e.type.spec.tableRole;
    if (r == "cell" || r == "header_cell")
      return t.doc.resolve(n);
  }
  for (let e = t.nodeBefore, n = t.pos; e; e = e.lastChild, n--) {
    const r = e.type.spec.tableRole;
    if (r == "cell" || r == "header_cell")
      return t.doc.resolve(n - e.nodeSize);
  }
}
function ga(t) {
  return t.parent.type.spec.tableRole == "row" && !!t.nodeAfter;
}
function pE(t) {
  return t.node(0).resolve(t.pos + t.nodeAfter.nodeSize);
}
function al(t, e) {
  return t.depth == e.depth && t.pos >= e.start(-1) && t.pos <= e.end(-1);
}
function op(t, e, n) {
  const r = t.node(-1), i = _e.get(r), s = t.start(-1), o = i.nextCell(t.pos - s, e, n);
  return o == null ? null : t.node(0).resolve(s + o);
}
function Wn(t, e, n = 1) {
  const r = { ...t, colspan: t.colspan - n };
  return r.colwidth && (r.colwidth = r.colwidth.slice(), r.colwidth.splice(e, n), r.colwidth.some((i) => i > 0) || (r.colwidth = null)), r;
}
function ap(t, e, n = 1) {
  const r = { ...t, colspan: t.colspan + n };
  if (r.colwidth) {
    r.colwidth = r.colwidth.slice();
    for (let i = 0; i < n; i++)
      r.colwidth.splice(e, 0, 0);
  }
  return r;
}
function hE(t, e, n) {
  const r = Ze(e.type.schema).header_cell;
  for (let i = 0; i < t.height; i++)
    if (e.nodeAt(t.map[n + i * t.width]).type != r)
      return !1;
  return !0;
}
var de = class extends te {
  // A table selection is identified by its anchor and head cells. The
  // positions given to this constructor should point _before_ two
  // cells in the same table. They may be the same, to select a single
  // cell.
  constructor(t, e = t) {
    const n = t.node(-1), r = _e.get(n), i = t.start(-1), s = r.rectBetween(
      t.pos - i,
      e.pos - i
    ), o = t.node(0), a = r.cellsInRect(s).filter((c) => c != e.pos - i);
    a.unshift(e.pos - i);
    const l = a.map((c) => {
      const d = n.nodeAt(c);
      if (!d)
        throw RangeError(`No cell with offset ${c} found`);
      const u = i + c + 1;
      return new Ru(
        o.resolve(u),
        o.resolve(u + d.content.size)
      );
    });
    super(l[0].$from, l[0].$to, l), this.$anchorCell = t, this.$headCell = e;
  }
  map(t, e) {
    const n = t.resolve(e.map(this.$anchorCell.pos)), r = t.resolve(e.map(this.$headCell.pos));
    if (ga(n) && ga(r) && al(n, r)) {
      const i = this.$anchorCell.node(-1) != n.node(-1);
      return i && this.isRowSelection() ? de.rowSelection(n, r) : i && this.isColSelection() ? de.colSelection(n, r) : new de(n, r);
    }
    return G.between(n, r);
  }
  // Returns a rectangular slice of table rows containing the selected
  // cells.
  content() {
    const t = this.$anchorCell.node(-1), e = _e.get(t), n = this.$anchorCell.start(-1), r = e.rectBetween(
      this.$anchorCell.pos - n,
      this.$headCell.pos - n
    ), i = {}, s = [];
    for (let a = r.top; a < r.bottom; a++) {
      const l = [];
      for (let c = a * e.width + r.left, d = r.left; d < r.right; d++, c++) {
        const u = e.map[c];
        if (i[u])
          continue;
        i[u] = !0;
        const f = e.findCell(u);
        let p = t.nodeAt(u);
        if (!p)
          throw RangeError(`No cell with offset ${u} found`);
        const h = r.left - f.left, m = f.right - r.right;
        if (h > 0 || m > 0) {
          let g = p.attrs;
          if (h > 0 && (g = Wn(g, 0, h)), m > 0 && (g = Wn(
            g,
            g.colspan - m,
            m
          )), f.left < r.left) {
            if (p = p.type.createAndFill(g), !p)
              throw RangeError(
                `Could not create cell with attrs ${JSON.stringify(g)}`
              );
          } else
            p = p.type.create(g, p.content);
        }
        if (f.top < r.top || f.bottom > r.bottom) {
          const g = {
            ...p.attrs,
            rowspan: Math.min(f.bottom, r.bottom) - Math.max(f.top, r.top)
          };
          f.top < r.top ? p = p.type.createAndFill(g) : p = p.type.create(g, p.content);
        }
        l.push(p);
      }
      s.push(t.child(a).copy(A.from(l)));
    }
    const o = this.isColSelection() && this.isRowSelection() ? t : s;
    return new B(A.from(o), 1, 1);
  }
  replace(t, e = B.empty) {
    const n = t.steps.length, r = this.ranges;
    for (let s = 0; s < r.length; s++) {
      const { $from: o, $to: a } = r[s], l = t.mapping.slice(n);
      t.replace(
        l.map(o.pos),
        l.map(a.pos),
        s ? B.empty : e
      );
    }
    const i = te.findFrom(
      t.doc.resolve(t.mapping.slice(n).map(this.to)),
      -1
    );
    i && t.setSelection(i);
  }
  replaceWith(t, e) {
    this.replace(t, new B(A.from(e), 0, 0));
  }
  forEachCell(t) {
    const e = this.$anchorCell.node(-1), n = _e.get(e), r = this.$anchorCell.start(-1), i = n.cellsInRect(
      n.rectBetween(
        this.$anchorCell.pos - r,
        this.$headCell.pos - r
      )
    );
    for (let s = 0; s < i.length; s++)
      t(e.nodeAt(i[s]), r + i[s]);
  }
  // True if this selection goes all the way from the top to the
  // bottom of the table.
  isColSelection() {
    const t = this.$anchorCell.index(-1), e = this.$headCell.index(-1);
    if (Math.min(t, e) > 0)
      return !1;
    const n = t + this.$anchorCell.nodeAfter.attrs.rowspan, r = e + this.$headCell.nodeAfter.attrs.rowspan;
    return Math.max(n, r) == this.$headCell.node(-1).childCount;
  }
  // Returns the smallest column selection that covers the given anchor
  // and head cell.
  static colSelection(t, e = t) {
    const n = t.node(-1), r = _e.get(n), i = t.start(-1), s = r.findCell(t.pos - i), o = r.findCell(e.pos - i), a = t.node(0);
    return s.top <= o.top ? (s.top > 0 && (t = a.resolve(i + r.map[s.left])), o.bottom < r.height && (e = a.resolve(
      i + r.map[r.width * (r.height - 1) + o.right - 1]
    ))) : (o.top > 0 && (e = a.resolve(i + r.map[o.left])), s.bottom < r.height && (t = a.resolve(
      i + r.map[r.width * (r.height - 1) + s.right - 1]
    ))), new de(t, e);
  }
  // True if this selection goes all the way from the left to the
  // right of the table.
  isRowSelection() {
    const t = this.$anchorCell.node(-1), e = _e.get(t), n = this.$anchorCell.start(-1), r = e.colCount(this.$anchorCell.pos - n), i = e.colCount(this.$headCell.pos - n);
    if (Math.min(r, i) > 0)
      return !1;
    const s = r + this.$anchorCell.nodeAfter.attrs.colspan, o = i + this.$headCell.nodeAfter.attrs.colspan;
    return Math.max(s, o) == e.width;
  }
  eq(t) {
    return t instanceof de && t.$anchorCell.pos == this.$anchorCell.pos && t.$headCell.pos == this.$headCell.pos;
  }
  // Returns the smallest row selection that covers the given anchor
  // and head cell.
  static rowSelection(t, e = t) {
    const n = t.node(-1), r = _e.get(n), i = t.start(-1), s = r.findCell(t.pos - i), o = r.findCell(e.pos - i), a = t.node(0);
    return s.left <= o.left ? (s.left > 0 && (t = a.resolve(
      i + r.map[s.top * r.width]
    )), o.right < r.width && (e = a.resolve(
      i + r.map[r.width * (o.top + 1) - 1]
    ))) : (o.left > 0 && (e = a.resolve(i + r.map[o.top * r.width])), s.right < r.width && (t = a.resolve(
      i + r.map[r.width * (s.top + 1) - 1]
    ))), new de(t, e);
  }
  toJSON() {
    return {
      type: "cell",
      anchor: this.$anchorCell.pos,
      head: this.$headCell.pos
    };
  }
  static fromJSON(t, e) {
    return new de(t.resolve(e.anchor), t.resolve(e.head));
  }
  static create(t, e, n = e) {
    return new de(t.resolve(e), t.resolve(n));
  }
  getBookmark() {
    return new lp(this.$anchorCell.pos, this.$headCell.pos);
  }
};
de.prototype.visible = !1;
te.jsonID("cell", de);
var lp = class {
  constructor(t, e) {
    this.anchor = t, this.head = e;
  }
  map(t) {
    return new lp(t.map(this.anchor), t.map(this.head));
  }
  resolve(t) {
    const e = t.resolve(this.anchor), n = t.resolve(this.head);
    return e.parent.type.spec.tableRole == "row" && n.parent.type.spec.tableRole == "row" && e.index() < e.parent.childCount && n.index() < n.parent.childCount && al(e, n) ? new de(e, n) : te.near(n, 1);
  }
};
function mE(t) {
  if (!(t.selection instanceof de))
    return null;
  const e = [];
  return t.selection.forEachCell((n, r) => {
    e.push(
      Le.node(r, r + n.nodeSize, { class: "selectedCell" })
    );
  }), we.create(t.doc, e);
}
function gE({ $from: t, $to: e }) {
  if (t.pos == e.pos || t.pos < t.pos - 6)
    return !1;
  let n = t.pos, r = e.pos, i = t.depth;
  for (; i >= 0 && !(t.after(i + 1) < t.end(i)); i--, n++)
    ;
  for (let s = e.depth; s >= 0 && !(e.before(s + 1) > e.start(s)); s--, r--)
    ;
  return n == r && /row|table/.test(t.node(i).type.spec.tableRole);
}
function bE({ $from: t, $to: e }) {
  let n, r;
  for (let i = t.depth; i > 0; i--) {
    const s = t.node(i);
    if (s.type.spec.tableRole === "cell" || s.type.spec.tableRole === "header_cell") {
      n = s;
      break;
    }
  }
  for (let i = e.depth; i > 0; i--) {
    const s = e.node(i);
    if (s.type.spec.tableRole === "cell" || s.type.spec.tableRole === "header_cell") {
      r = s;
      break;
    }
  }
  return n !== r && e.parentOffset === 0;
}
function yE(t, e, n) {
  const r = (e || t).selection, i = (e || t).doc;
  let s, o;
  if (r instanceof Y && (o = r.node.type.spec.tableRole)) {
    if (o == "cell" || o == "header_cell")
      s = de.create(i, r.from);
    else if (o == "row") {
      const a = i.resolve(r.from + 1);
      s = de.rowSelection(a, a);
    } else if (!n) {
      const a = _e.get(r.node), l = r.from + 1, c = l + a.map[a.width * a.height - 1];
      s = de.create(i, l + 1, c);
    }
  } else
    r instanceof G && gE(r) ? s = G.create(i, r.from) : r instanceof G && bE(r) && (s = G.create(i, r.$from.start(), r.$from.end()));
  return s && (e || (e = t.tr)).setSelection(s), e;
}
var vE = new Me("fix-tables");
function cp(t, e, n, r) {
  const i = t.childCount, s = e.childCount;
  e:
    for (let o = 0, a = 0; o < s; o++) {
      const l = e.child(o);
      for (let c = a, d = Math.min(i, o + 3); c < d; c++)
        if (t.child(c) == l) {
          a = c + 1, n += l.nodeSize;
          continue e;
        }
      r(l, n), a < i && t.child(a).sameMarkup(l) ? cp(t.child(a), l, n + 1, r) : l.nodesBetween(0, l.content.size, r, n + 1), n += l.nodeSize;
    }
}
function dp(t, e) {
  let n;
  const r = (i, s) => {
    i.type.spec.tableRole == "table" && (n = wE(t, i, s, n));
  };
  return e ? e.doc != t.doc && cp(e.doc, t.doc, 0, r) : t.doc.descendants(r), n;
}
function wE(t, e, n, r) {
  const i = _e.get(e);
  if (!i.problems)
    return r;
  r || (r = t.tr);
  const s = [];
  for (let l = 0; l < i.height; l++)
    s.push(0);
  for (let l = 0; l < i.problems.length; l++) {
    const c = i.problems[l];
    if (c.type == "collision") {
      const d = e.nodeAt(c.pos);
      if (!d)
        continue;
      const u = d.attrs;
      for (let f = 0; f < u.rowspan; f++)
        s[c.row + f] += c.n;
      r.setNodeMarkup(
        r.mapping.map(n + 1 + c.pos),
        null,
        Wn(u, u.colspan - c.n, c.n)
      );
    } else if (c.type == "missing")
      s[c.row] += c.n;
    else if (c.type == "overlong_rowspan") {
      const d = e.nodeAt(c.pos);
      if (!d)
        continue;
      r.setNodeMarkup(r.mapping.map(n + 1 + c.pos), null, {
        ...d.attrs,
        rowspan: d.attrs.rowspan - c.n
      });
    } else if (c.type == "colwidth mismatch") {
      const d = e.nodeAt(c.pos);
      if (!d)
        continue;
      r.setNodeMarkup(r.mapping.map(n + 1 + c.pos), null, {
        ...d.attrs,
        colwidth: c.colwidth
      });
    }
  }
  let o, a;
  for (let l = 0; l < s.length; l++)
    s[l] && (o == null && (o = l), a = l);
  for (let l = 0, c = n + 1; l < i.height; l++) {
    const d = e.child(l), u = c + d.nodeSize, f = s[l];
    if (f > 0) {
      let p = "cell";
      d.firstChild && (p = d.firstChild.type.spec.tableRole);
      const h = [];
      for (let g = 0; g < f; g++) {
        const v = Ze(t.schema)[p].createAndFill();
        v && h.push(v);
      }
      const m = (l == 0 || o == l - 1) && a == l ? c + 1 : u - 1;
      r.insert(r.mapping.map(m), h);
    }
    c = u;
  }
  return r.setMeta(vE, { fixTables: !0 });
}
function EE(t) {
  if (!t.size)
    return null;
  let { content: e, openStart: n, openEnd: r } = t;
  for (; e.childCount == 1 && (n > 0 && r > 0 || e.child(0).type.spec.tableRole == "table"); )
    n--, r--, e = e.child(0).content;
  const i = e.child(0), s = i.type.spec.tableRole, o = i.type.schema, a = [];
  if (s == "row")
    for (let l = 0; l < e.childCount; l++) {
      let c = e.child(l).content;
      const d = l ? 0 : Math.max(0, n - 1), u = l < e.childCount - 1 ? 0 : Math.max(0, r - 1);
      (d || u) && (c = ba(
        Ze(o).row,
        new B(c, d, u)
      ).content), a.push(c);
    }
  else if (s == "cell" || s == "header_cell")
    a.push(
      n || r ? ba(
        Ze(o).row,
        new B(e, n, r)
      ).content : e
    );
  else
    return null;
  return xE(o, a);
}
function xE(t, e) {
  const n = [];
  for (let i = 0; i < e.length; i++) {
    const s = e[i];
    for (let o = s.childCount - 1; o >= 0; o--) {
      const { rowspan: a, colspan: l } = s.child(o).attrs;
      for (let c = i; c < i + a; c++)
        n[c] = (n[c] || 0) + l;
    }
  }
  let r = 0;
  for (let i = 0; i < n.length; i++)
    r = Math.max(r, n[i]);
  for (let i = 0; i < n.length; i++)
    if (i >= e.length && e.push(A.empty), n[i] < r) {
      const s = Ze(t).cell.createAndFill(), o = [];
      for (let a = n[i]; a < r; a++)
        o.push(s);
      e[i] = e[i].append(A.from(o));
    }
  return { height: e.length, width: r, rows: e };
}
function ba(t, e) {
  const n = t.createAndFill();
  return new Na(n).replace(0, n.content.size, e).doc;
}
function SE({ width: t, height: e, rows: n }, r, i) {
  if (t != r) {
    const s = [], o = [];
    for (let a = 0; a < n.length; a++) {
      const l = n[a], c = [];
      for (let d = s[a] || 0, u = 0; d < r; u++) {
        let f = l.child(u % l.childCount);
        d + f.attrs.colspan > r && (f = f.type.createChecked(
          Wn(
            f.attrs,
            f.attrs.colspan,
            d + f.attrs.colspan - r
          ),
          f.content
        )), c.push(f), d += f.attrs.colspan;
        for (let p = 1; p < f.attrs.rowspan; p++)
          s[a + p] = (s[a + p] || 0) + f.attrs.colspan;
      }
      o.push(A.from(c));
    }
    n = o, t = r;
  }
  if (e != i) {
    const s = [];
    for (let o = 0, a = 0; o < i; o++, a++) {
      const l = [], c = n[a % e];
      for (let d = 0; d < c.childCount; d++) {
        let u = c.child(d);
        o + u.attrs.rowspan > i && (u = u.type.create(
          {
            ...u.attrs,
            rowspan: Math.max(1, i - u.attrs.rowspan)
          },
          u.content
        )), l.push(u);
      }
      s.push(A.from(l));
    }
    n = s, e = i;
  }
  return { width: t, height: e, rows: n };
}
function CE(t, e, n, r, i, s, o) {
  const a = t.doc.type.schema, l = Ze(a);
  let c, d;
  if (i > e.width)
    for (let u = 0, f = 0; u < e.height; u++) {
      const p = n.child(u);
      f += p.nodeSize;
      const h = [];
      let m;
      p.lastChild == null || p.lastChild.type == l.cell ? m = c || (c = l.cell.createAndFill()) : m = d || (d = l.header_cell.createAndFill());
      for (let g = e.width; g < i; g++)
        h.push(m);
      t.insert(t.mapping.slice(o).map(f - 1 + r), h);
    }
  if (s > e.height) {
    const u = [];
    for (let h = 0, m = (e.height - 1) * e.width; h < Math.max(e.width, i); h++) {
      const g = h >= e.width ? !1 : n.nodeAt(e.map[m + h]).type == l.header_cell;
      u.push(
        g ? d || (d = l.header_cell.createAndFill()) : c || (c = l.cell.createAndFill())
      );
    }
    const f = l.row.create(null, A.from(u)), p = [];
    for (let h = e.height; h < s; h++)
      p.push(f);
    t.insert(t.mapping.slice(o).map(r + n.nodeSize - 2), p);
  }
  return !!(c || d);
}
function cd(t, e, n, r, i, s, o, a) {
  if (o == 0 || o == e.height)
    return !1;
  let l = !1;
  for (let c = i; c < s; c++) {
    const d = o * e.width + c, u = e.map[d];
    if (e.map[d - e.width] == u) {
      l = !0;
      const f = n.nodeAt(u), { top: p, left: h } = e.findCell(u);
      t.setNodeMarkup(t.mapping.slice(a).map(u + r), null, {
        ...f.attrs,
        rowspan: o - p
      }), t.insert(
        t.mapping.slice(a).map(e.positionAt(o, h, n)),
        f.type.createAndFill({
          ...f.attrs,
          rowspan: p + f.attrs.rowspan - o
        })
      ), c += f.attrs.colspan - 1;
    }
  }
  return l;
}
function dd(t, e, n, r, i, s, o, a) {
  if (o == 0 || o == e.width)
    return !1;
  let l = !1;
  for (let c = i; c < s; c++) {
    const d = c * e.width + o, u = e.map[d];
    if (e.map[d - 1] == u) {
      l = !0;
      const f = n.nodeAt(u), p = e.colCount(u), h = t.mapping.slice(a).map(u + r);
      t.setNodeMarkup(
        h,
        null,
        Wn(
          f.attrs,
          o - p,
          f.attrs.colspan - (o - p)
        )
      ), t.insert(
        h + f.nodeSize,
        f.type.createAndFill(
          Wn(f.attrs, 0, o - p)
        )
      ), c += f.attrs.rowspan - 1;
    }
  }
  return l;
}
function ud(t, e, n, r, i) {
  let s = n ? t.doc.nodeAt(n - 1) : t.doc;
  if (!s)
    throw new Error("No table found");
  let o = _e.get(s);
  const { top: a, left: l } = r, c = l + i.width, d = a + i.height, u = t.tr;
  let f = 0;
  function p() {
    if (s = n ? u.doc.nodeAt(n - 1) : u.doc, !s)
      throw new Error("No table found");
    o = _e.get(s), f = u.mapping.maps.length;
  }
  CE(u, o, s, n, c, d, f) && p(), cd(u, o, s, n, l, c, a, f) && p(), cd(u, o, s, n, l, c, d, f) && p(), dd(u, o, s, n, a, d, l, f) && p(), dd(u, o, s, n, a, d, c, f) && p();
  for (let h = a; h < d; h++) {
    const m = o.positionAt(h, l, s), g = o.positionAt(h, c, s);
    u.replace(
      u.mapping.slice(f).map(m + n),
      u.mapping.slice(f).map(g + n),
      new B(i.rows[h - a], 0, 0)
    );
  }
  p(), u.setSelection(
    new de(
      u.doc.resolve(n + o.positionAt(a, l, s)),
      u.doc.resolve(n + o.positionAt(d - 1, c - 1, s))
    )
  ), e(u);
}
var ME = Va({
  ArrowLeft: Ai("horiz", -1),
  ArrowRight: Ai("horiz", 1),
  ArrowUp: Ai("vert", -1),
  ArrowDown: Ai("vert", 1),
  "Shift-ArrowLeft": Oi("horiz", -1),
  "Shift-ArrowRight": Oi("horiz", 1),
  "Shift-ArrowUp": Oi("vert", -1),
  "Shift-ArrowDown": Oi("vert", 1),
  Backspace: Ri,
  "Mod-Backspace": Ri,
  Delete: Ri,
  "Mod-Delete": Ri
});
function Gi(t, e, n) {
  return n.eq(t.selection) ? !1 : (e && e(t.tr.setSelection(n).scrollIntoView()), !0);
}
function Ai(t, e) {
  return (n, r, i) => {
    if (!i)
      return !1;
    const s = n.selection;
    if (s instanceof de)
      return Gi(
        n,
        r,
        te.near(s.$headCell, e)
      );
    if (t != "horiz" && !s.empty)
      return !1;
    const o = up(i, t, e);
    if (o == null)
      return !1;
    if (t == "horiz")
      return Gi(
        n,
        r,
        te.near(n.doc.resolve(s.head + e), e)
      );
    {
      const a = n.doc.resolve(o), l = op(a, t, e);
      let c;
      return l ? c = te.near(l, 1) : e < 0 ? c = te.near(n.doc.resolve(a.before(-1)), -1) : c = te.near(n.doc.resolve(a.after(-1)), 1), Gi(n, r, c);
    }
  };
}
function Oi(t, e) {
  return (n, r, i) => {
    if (!i)
      return !1;
    const s = n.selection;
    let o;
    if (s instanceof de)
      o = s;
    else {
      const l = up(i, t, e);
      if (l == null)
        return !1;
      o = new de(n.doc.resolve(l));
    }
    const a = op(o.$headCell, t, e);
    return a ? Gi(
      n,
      r,
      new de(o.$anchorCell, a)
    ) : !1;
  };
}
function Ri(t, e) {
  const n = t.selection;
  if (!(n instanceof de))
    return !1;
  if (e) {
    const r = t.tr, i = Ze(t.schema).cell.createAndFill().content;
    n.forEachCell((s, o) => {
      s.content.eq(i) || r.replace(
        r.mapping.map(o + 1),
        r.mapping.map(o + s.nodeSize - 1),
        new B(i, 0, 0)
      );
    }), r.docChanged && e(r);
  }
  return !0;
}
function kE(t, e) {
  const n = t.state.doc, r = Rr(n.resolve(e));
  return r ? (t.dispatch(t.state.tr.setSelection(new de(r))), !0) : !1;
}
function TE(t, e, n) {
  if (!Nt(t.state))
    return !1;
  let r = EE(n);
  const i = t.state.selection;
  if (i instanceof de) {
    r || (r = {
      width: 1,
      height: 1,
      rows: [
        A.from(
          ba(Ze(t.state.schema).cell, n)
        )
      ]
    });
    const s = i.$anchorCell.node(-1), o = i.$anchorCell.start(-1), a = _e.get(s).rectBetween(
      i.$anchorCell.pos - o,
      i.$headCell.pos - o
    );
    return r = SE(r, a.right - a.left, a.bottom - a.top), ud(t.state, t.dispatch, o, a, r), !0;
  } else if (r) {
    const s = js(t.state), o = s.start(-1);
    return ud(
      t.state,
      t.dispatch,
      o,
      _e.get(s.node(-1)).findCell(s.pos - o),
      r
    ), !0;
  } else
    return !1;
}
function _E(t, e) {
  var n;
  if (e.ctrlKey || e.metaKey)
    return;
  const r = fd(t, e.target);
  let i;
  if (e.shiftKey && t.state.selection instanceof de)
    s(t.state.selection.$anchorCell, e), e.preventDefault();
  else if (e.shiftKey && r && (i = Rr(t.state.selection.$anchor)) != null && ((n = Lo(t, e)) == null ? void 0 : n.pos) != i.pos)
    s(i, e), e.preventDefault();
  else if (!r)
    return;
  function s(l, c) {
    let d = Lo(t, c);
    const u = sn.getState(t.state) == null;
    if (!d || !al(l, d))
      if (u)
        d = l;
      else
        return;
    const f = new de(l, d);
    if (u || !t.state.selection.eq(f)) {
      const p = t.state.tr.setSelection(f);
      u && p.setMeta(sn, l.pos), t.dispatch(p);
    }
  }
  function o() {
    t.root.removeEventListener("mouseup", o), t.root.removeEventListener("dragstart", o), t.root.removeEventListener("mousemove", a), sn.getState(t.state) != null && t.dispatch(t.state.tr.setMeta(sn, -1));
  }
  function a(l) {
    const c = l, d = sn.getState(t.state);
    let u;
    if (d != null)
      u = t.state.doc.resolve(d);
    else if (fd(t, c.target) != r && (u = Lo(t, e), !u))
      return o();
    u && s(u, c);
  }
  t.root.addEventListener("mouseup", o), t.root.addEventListener("dragstart", o), t.root.addEventListener("mousemove", a);
}
function up(t, e, n) {
  if (!(t.state.selection instanceof G))
    return null;
  const { $head: r } = t.state.selection;
  for (let i = r.depth - 1; i >= 0; i--) {
    const s = r.node(i);
    if ((n < 0 ? r.index(i) : r.indexAfter(i)) != (n < 0 ? 0 : s.childCount))
      return null;
    if (s.type.spec.tableRole == "cell" || s.type.spec.tableRole == "header_cell") {
      const a = r.before(i), l = e == "vert" ? n > 0 ? "down" : "up" : n > 0 ? "right" : "left";
      return t.endOfTextblock(l) ? a : null;
    }
  }
  return null;
}
function fd(t, e) {
  for (; e && e != t.dom; e = e.parentNode)
    if (e.nodeName == "TD" || e.nodeName == "TH")
      return e;
  return null;
}
function Lo(t, e) {
  const n = t.posAtCoords({
    left: e.clientX,
    top: e.clientY
  });
  return n && n ? Rr(t.state.doc.resolve(n.pos)) : null;
}
var NE = class {
  constructor(e, n) {
    this.node = e, this.cellMinWidth = n, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), this.colgroup = this.table.appendChild(document.createElement("colgroup")), ya(e, this.colgroup, this.table, n), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
  }
  update(e) {
    return e.type != this.node.type ? !1 : (this.node = e, ya(e, this.colgroup, this.table, this.cellMinWidth), !0);
  }
  ignoreMutation(e) {
    return e.type == "attributes" && (e.target == this.table || this.colgroup.contains(e.target));
  }
};
function ya(t, e, n, r, i, s) {
  var o;
  let a = 0, l = !0, c = e.firstChild;
  const d = t.firstChild;
  if (d) {
    for (let u = 0, f = 0; u < d.childCount; u++) {
      const { colspan: p, colwidth: h } = d.child(u).attrs;
      for (let m = 0; m < p; m++, f++) {
        const g = i == f ? s : h && h[m], v = g ? g + "px" : "";
        a += g || r, g || (l = !1), c ? (c.style.width != v && (c.style.width = v), c = c.nextSibling) : e.appendChild(document.createElement("col")).style.width = v;
      }
    }
    for (; c; ) {
      const u = c.nextSibling;
      (o = c.parentNode) == null || o.removeChild(c), c = u;
    }
    l ? (n.style.width = a + "px", n.style.minWidth = "") : (n.style.width = "", n.style.minWidth = a + "px");
  }
}
var vt = new Me(
  "tableColumnResizing"
);
function AE({
  handleWidth: t = 5,
  cellMinWidth: e = 25,
  View: n = NE,
  lastColumnResizable: r = !0
} = {}) {
  const i = new Se({
    key: vt,
    state: {
      init(s, o) {
        return i.spec.props.nodeViews[Ze(o.schema).table.name] = (a, l) => new n(a, e, l), new ji(-1, !1);
      },
      apply(s, o) {
        return o.apply(s);
      }
    },
    props: {
      attributes: (s) => {
        const o = vt.getState(s);
        return o && o.activeHandle > -1 ? { class: "resize-cursor" } : {};
      },
      handleDOMEvents: {
        mousemove: (s, o) => {
          OE(
            s,
            o,
            t,
            e,
            r
          );
        },
        mouseleave: (s) => {
          RE(s);
        },
        mousedown: (s, o) => {
          LE(s, o, e);
        }
      },
      decorations: (s) => {
        const o = vt.getState(s);
        if (o && o.activeHandle > -1)
          return $E(s, o.activeHandle);
      },
      nodeViews: {}
    }
  });
  return i;
}
var ji = class {
  constructor(t, e) {
    this.activeHandle = t, this.dragging = e;
  }
  apply(t) {
    const e = this, n = t.getMeta(vt);
    if (n && n.setHandle != null)
      return new ji(n.setHandle, !1);
    if (n && n.setDragging !== void 0)
      return new ji(e.activeHandle, n.setDragging);
    if (e.activeHandle > -1 && t.docChanged) {
      let r = t.mapping.map(e.activeHandle, -1);
      return ga(t.doc.resolve(r)) || (r = -1), new ji(r, e.dragging);
    }
    return e;
  }
};
function OE(t, e, n, r, i) {
  const s = vt.getState(t.state);
  if (s && !s.dragging) {
    const o = DE(e.target);
    let a = -1;
    if (o) {
      const { left: l, right: c } = o.getBoundingClientRect();
      e.clientX - l <= n ? a = pd(t, e, "left", n) : c - e.clientX <= n && (a = pd(t, e, "right", n));
    }
    if (a != s.activeHandle) {
      if (!i && a !== -1) {
        const l = t.state.doc.resolve(a), c = l.node(-1), d = _e.get(c), u = l.start(-1);
        if (d.colCount(l.pos - u) + l.nodeAfter.attrs.colspan - 1 == d.width - 1)
          return;
      }
      fp(t, a);
    }
  }
}
function RE(t) {
  const e = vt.getState(t.state);
  e && e.activeHandle > -1 && !e.dragging && fp(t, -1);
}
function LE(t, e, n) {
  const r = vt.getState(t.state);
  if (!r || r.activeHandle == -1 || r.dragging)
    return !1;
  const i = t.state.doc.nodeAt(r.activeHandle), s = IE(t, r.activeHandle, i.attrs);
  t.dispatch(
    t.state.tr.setMeta(vt, {
      setDragging: { startX: e.clientX, startWidth: s }
    })
  );
  function o(l) {
    window.removeEventListener("mouseup", o), window.removeEventListener("mousemove", a);
    const c = vt.getState(t.state);
    c != null && c.dragging && (HE(
      t,
      c.activeHandle,
      hd(c.dragging, l, n)
    ), t.dispatch(
      t.state.tr.setMeta(vt, { setDragging: null })
    ));
  }
  function a(l) {
    if (!l.which)
      return o(l);
    const c = vt.getState(t.state);
    if (c && c.dragging) {
      const d = hd(c.dragging, l, n);
      BE(t, c.activeHandle, d, n);
    }
  }
  return window.addEventListener("mouseup", o), window.addEventListener("mousemove", a), e.preventDefault(), !0;
}
function IE(t, e, { colspan: n, colwidth: r }) {
  const i = r && r[r.length - 1];
  if (i)
    return i;
  const s = t.domAtPos(e);
  let a = s.node.childNodes[s.offset].offsetWidth, l = n;
  if (r)
    for (let c = 0; c < n; c++)
      r[c] && (a -= r[c], l--);
  return a / l;
}
function DE(t) {
  for (; t && t.nodeName != "TD" && t.nodeName != "TH"; )
    t = t.classList && t.classList.contains("ProseMirror") ? null : t.parentNode;
  return t;
}
function pd(t, e, n, r) {
  const i = n == "right" ? -r : r, s = t.posAtCoords({
    left: e.clientX + i,
    top: e.clientY
  });
  if (!s)
    return -1;
  const { pos: o } = s, a = Rr(t.state.doc.resolve(o));
  if (!a)
    return -1;
  if (n == "right")
    return a.pos;
  const l = _e.get(a.node(-1)), c = a.start(-1), d = l.map.indexOf(a.pos - c);
  return d % l.width == 0 ? -1 : c + l.map[d - 1];
}
function hd(t, e, n) {
  const r = e.clientX - t.startX;
  return Math.max(n, t.startWidth + r);
}
function fp(t, e) {
  t.dispatch(
    t.state.tr.setMeta(vt, { setHandle: e })
  );
}
function HE(t, e, n) {
  const r = t.state.doc.resolve(e), i = r.node(-1), s = _e.get(i), o = r.start(-1), a = s.colCount(r.pos - o) + r.nodeAfter.attrs.colspan - 1, l = t.state.tr;
  for (let c = 0; c < s.height; c++) {
    const d = c * s.width + a;
    if (c && s.map[d] == s.map[d - s.width])
      continue;
    const u = s.map[d], f = i.nodeAt(u).attrs, p = f.colspan == 1 ? 0 : a - s.colCount(u);
    if (f.colwidth && f.colwidth[p] == n)
      continue;
    const h = f.colwidth ? f.colwidth.slice() : PE(f.colspan);
    h[p] = n, l.setNodeMarkup(o + u, null, { ...f, colwidth: h });
  }
  l.docChanged && t.dispatch(l);
}
function BE(t, e, n, r) {
  const i = t.state.doc.resolve(e), s = i.node(-1), o = i.start(-1), a = _e.get(s).colCount(i.pos - o) + i.nodeAfter.attrs.colspan - 1;
  let l = t.domAtPos(i.start(-1)).node;
  for (; l && l.nodeName != "TABLE"; )
    l = l.parentNode;
  l && ya(
    s,
    l.firstChild,
    l,
    r,
    a,
    n
  );
}
function PE(t) {
  return Array(t).fill(0);
}
function $E(t, e) {
  const n = [], r = t.doc.resolve(e), i = r.node(-1);
  if (!i)
    return we.empty;
  const s = _e.get(i), o = r.start(-1), a = s.colCount(r.pos - o) + r.nodeAfter.attrs.colspan;
  for (let l = 0; l < s.height; l++) {
    const c = a + l * s.width - 1;
    if ((a == s.width || s.map[c] != s.map[c + 1]) && (l == 0 || s.map[c] != s.map[c - s.width])) {
      const d = s.map[c], u = o + d + i.nodeAt(d).nodeSize - 1, f = document.createElement("div");
      f.className = "column-resize-handle", n.push(Le.widget(u, f));
    }
  }
  return we.create(t.doc, n);
}
function Ft(t) {
  const e = t.selection, n = js(t), r = n.node(-1), i = n.start(-1), s = _e.get(r);
  return { ...e instanceof de ? s.rectBetween(
    e.$anchorCell.pos - i,
    e.$headCell.pos - i
  ) : s.findCell(n.pos - i), tableStart: i, map: s, table: r };
}
function pp(t, { map: e, tableStart: n, table: r }, i) {
  let s = i > 0 ? -1 : 0;
  hE(e, r, i + s) && (s = i == 0 || i == e.width ? null : 0);
  for (let o = 0; o < e.height; o++) {
    const a = o * e.width + i;
    if (i > 0 && i < e.width && e.map[a - 1] == e.map[a]) {
      const l = e.map[a], c = r.nodeAt(l);
      t.setNodeMarkup(
        t.mapping.map(n + l),
        null,
        ap(c.attrs, i - e.colCount(l))
      ), o += c.attrs.rowspan - 1;
    } else {
      const l = s == null ? Ze(r.type.schema).cell : r.nodeAt(e.map[a + s]).type, c = e.positionAt(o, i, r);
      t.insert(t.mapping.map(n + c), l.createAndFill());
    }
  }
  return t;
}
function VE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t);
    e(pp(t.tr, n, n.left));
  }
  return !0;
}
function zE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t);
    e(pp(t.tr, n, n.right));
  }
  return !0;
}
function FE(t, { map: e, table: n, tableStart: r }, i) {
  const s = t.mapping.maps.length;
  for (let o = 0; o < e.height; ) {
    const a = o * e.width + i, l = e.map[a], c = n.nodeAt(l), d = c.attrs;
    if (i > 0 && e.map[a - 1] == l || i < e.width - 1 && e.map[a + 1] == l)
      t.setNodeMarkup(
        t.mapping.slice(s).map(r + l),
        null,
        Wn(d, i - e.colCount(l))
      );
    else {
      const u = t.mapping.slice(s).map(r + l);
      t.delete(u, u + c.nodeSize);
    }
    o += d.rowspan;
  }
}
function UE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t), r = t.tr;
    if (n.left == 0 && n.right == n.map.width)
      return !1;
    for (let i = n.right - 1; FE(r, n, i), i != n.left; i--) {
      const s = n.tableStart ? r.doc.nodeAt(n.tableStart - 1) : r.doc;
      if (!s)
        throw RangeError("No table found");
      n.table = s, n.map = _e.get(s);
    }
    e(r);
  }
  return !0;
}
function KE(t, e, n) {
  var r;
  const i = Ze(e.type.schema).header_cell;
  for (let s = 0; s < t.width; s++)
    if (((r = e.nodeAt(t.map[s + n * t.width])) == null ? void 0 : r.type) != i)
      return !1;
  return !0;
}
function hp(t, { map: e, tableStart: n, table: r }, i) {
  var s;
  let o = n;
  for (let c = 0; c < i; c++)
    o += r.child(c).nodeSize;
  const a = [];
  let l = i > 0 ? -1 : 0;
  KE(e, r, i + l) && (l = i == 0 || i == e.height ? null : 0);
  for (let c = 0, d = e.width * i; c < e.width; c++, d++)
    if (i > 0 && i < e.height && e.map[d] == e.map[d - e.width]) {
      const u = e.map[d], f = r.nodeAt(u).attrs;
      t.setNodeMarkup(n + u, null, {
        ...f,
        rowspan: f.rowspan + 1
      }), c += f.colspan - 1;
    } else {
      const u = l == null ? Ze(r.type.schema).cell : (s = r.nodeAt(e.map[d + l * e.width])) == null ? void 0 : s.type, f = u == null ? void 0 : u.createAndFill();
      f && a.push(f);
    }
  return t.insert(o, Ze(r.type.schema).row.create(null, a)), t;
}
function WE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t);
    e(hp(t.tr, n, n.top));
  }
  return !0;
}
function qE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t);
    e(hp(t.tr, n, n.bottom));
  }
  return !0;
}
function ZE(t, { map: e, table: n, tableStart: r }, i) {
  let s = 0;
  for (let l = 0; l < i; l++)
    s += n.child(l).nodeSize;
  const o = s + n.child(i).nodeSize, a = t.mapping.maps.length;
  t.delete(s + r, o + r);
  for (let l = 0, c = i * e.width; l < e.width; l++, c++) {
    const d = e.map[c];
    if (i > 0 && d == e.map[c - e.width]) {
      const u = n.nodeAt(d).attrs;
      t.setNodeMarkup(t.mapping.slice(a).map(d + r), null, {
        ...u,
        rowspan: u.rowspan - 1
      }), l += u.colspan - 1;
    } else if (i < e.width && d == e.map[c + e.width]) {
      const u = n.nodeAt(d), f = u.attrs, p = u.type.create(
        { ...f, rowspan: u.attrs.rowspan - 1 },
        u.content
      ), h = e.positionAt(i + 1, l, n);
      t.insert(t.mapping.slice(a).map(r + h), p), l += f.colspan - 1;
    }
  }
}
function GE(t, e) {
  if (!Nt(t))
    return !1;
  if (e) {
    const n = Ft(t), r = t.tr;
    if (n.top == 0 && n.bottom == n.map.height)
      return !1;
    for (let i = n.bottom - 1; ZE(r, n, i), i != n.top; i--) {
      const s = n.tableStart ? r.doc.nodeAt(n.tableStart - 1) : r.doc;
      if (!s)
        throw RangeError("No table found");
      n.table = s, n.map = _e.get(n.table);
    }
    e(r);
  }
  return !0;
}
function md(t) {
  const e = t.content;
  return e.childCount == 1 && e.child(0).isTextblock && e.child(0).childCount == 0;
}
function jE({ width: t, height: e, map: n }, r) {
  let i = r.top * t + r.left, s = i, o = (r.bottom - 1) * t + r.left, a = i + (r.right - r.left - 1);
  for (let l = r.top; l < r.bottom; l++) {
    if (r.left > 0 && n[s] == n[s - 1] || r.right < t && n[a] == n[a + 1])
      return !0;
    s += t, a += t;
  }
  for (let l = r.left; l < r.right; l++) {
    if (r.top > 0 && n[i] == n[i - t] || r.bottom < e && n[o] == n[o + t])
      return !0;
    i++, o++;
  }
  return !1;
}
function gd(t, e) {
  const n = t.selection;
  if (!(n instanceof de) || n.$anchorCell.pos == n.$headCell.pos)
    return !1;
  const r = Ft(t), { map: i } = r;
  if (jE(i, r))
    return !1;
  if (e) {
    const s = t.tr, o = {};
    let a = A.empty, l, c;
    for (let d = r.top; d < r.bottom; d++)
      for (let u = r.left; u < r.right; u++) {
        const f = i.map[d * i.width + u], p = r.table.nodeAt(f);
        if (!(o[f] || !p))
          if (o[f] = !0, l == null)
            l = f, c = p;
          else {
            md(p) || (a = a.append(p.content));
            const h = s.mapping.map(f + r.tableStart);
            s.delete(h, h + p.nodeSize);
          }
      }
    if (l == null || c == null)
      return !0;
    if (s.setNodeMarkup(l + r.tableStart, null, {
      ...ap(
        c.attrs,
        c.attrs.colspan,
        r.right - r.left - c.attrs.colspan
      ),
      rowspan: r.bottom - r.top
    }), a.size) {
      const d = l + 1 + c.content.size, u = md(c) ? l + 1 : d;
      s.replaceWith(u + r.tableStart, d + r.tableStart, a);
    }
    s.setSelection(
      new de(s.doc.resolve(l + r.tableStart))
    ), e(s);
  }
  return !0;
}
function bd(t, e) {
  const n = Ze(t.schema);
  return YE(({ node: r }) => n[r.type.spec.tableRole])(t, e);
}
function YE(t) {
  return (e, n) => {
    var r;
    const i = e.selection;
    let s, o;
    if (i instanceof de) {
      if (i.$anchorCell.pos != i.$headCell.pos)
        return !1;
      s = i.$anchorCell.nodeAfter, o = i.$anchorCell.pos;
    } else {
      if (s = uE(i.$from), !s)
        return !1;
      o = (r = Rr(i.$from)) == null ? void 0 : r.pos;
    }
    if (s == null || o == null || s.attrs.colspan == 1 && s.attrs.rowspan == 1)
      return !1;
    if (n) {
      let a = s.attrs;
      const l = [], c = a.colwidth;
      a.rowspan > 1 && (a = { ...a, rowspan: 1 }), a.colspan > 1 && (a = { ...a, colspan: 1 });
      const d = Ft(e), u = e.tr;
      for (let p = 0; p < d.right - d.left; p++)
        l.push(
          c ? {
            ...a,
            colwidth: c && c[p] ? [c[p]] : null
          } : a
        );
      let f;
      for (let p = d.top; p < d.bottom; p++) {
        let h = d.map.positionAt(p, d.left, d.table);
        p == d.top && (h += s.nodeSize);
        for (let m = d.left, g = 0; m < d.right; m++, g++)
          m == d.left && p == d.top || u.insert(
            f = u.mapping.map(h + d.tableStart, 1),
            t({ node: s, row: p, col: m }).createAndFill(l[g])
          );
      }
      u.setNodeMarkup(
        o,
        t({ node: s, row: d.top, col: d.left }),
        l[0]
      ), i instanceof de && u.setSelection(
        new de(
          u.doc.resolve(i.$anchorCell.pos),
          f ? u.doc.resolve(f) : void 0
        )
      ), n(u);
    }
    return !0;
  };
}
function JE(t, e) {
  return function(n, r) {
    if (!Nt(n))
      return !1;
    const i = js(n);
    if (i.nodeAfter.attrs[t] === e)
      return !1;
    if (r) {
      const s = n.tr;
      n.selection instanceof de ? n.selection.forEachCell((o, a) => {
        o.attrs[t] !== e && s.setNodeMarkup(a, null, {
          ...o.attrs,
          [t]: e
        });
      }) : s.setNodeMarkup(i.pos, null, {
        ...i.nodeAfter.attrs,
        [t]: e
      }), r(s);
    }
    return !0;
  };
}
function XE(t) {
  return function(e, n) {
    if (!Nt(e))
      return !1;
    if (n) {
      const r = Ze(e.schema), i = Ft(e), s = e.tr, o = i.map.cellsInRect(
        t == "column" ? {
          left: i.left,
          top: 0,
          right: i.right,
          bottom: i.map.height
        } : t == "row" ? {
          left: 0,
          top: i.top,
          right: i.map.width,
          bottom: i.bottom
        } : i
      ), a = o.map((l) => i.table.nodeAt(l));
      for (let l = 0; l < o.length; l++)
        a[l].type == r.header_cell && s.setNodeMarkup(
          i.tableStart + o[l],
          r.cell,
          a[l].attrs
        );
      if (s.steps.length == 0)
        for (let l = 0; l < o.length; l++)
          s.setNodeMarkup(
            i.tableStart + o[l],
            r.header_cell,
            a[l].attrs
          );
      n(s);
    }
    return !0;
  };
}
function yd(t, e, n) {
  const r = e.map.cellsInRect({
    left: 0,
    top: 0,
    right: t == "row" ? e.map.width : 1,
    bottom: t == "column" ? e.map.height : 1
  });
  for (let i = 0; i < r.length; i++) {
    const s = e.table.nodeAt(r[i]);
    if (s && s.type !== n.header_cell)
      return !1;
  }
  return !0;
}
function li(t, e) {
  return e = e || { useDeprecatedLogic: !1 }, e.useDeprecatedLogic ? XE(t) : function(n, r) {
    if (!Nt(n))
      return !1;
    if (r) {
      const i = Ze(n.schema), s = Ft(n), o = n.tr, a = yd("row", s, i), l = yd(
        "column",
        s,
        i
      ), d = (t === "column" ? a : t === "row" ? l : !1) ? 1 : 0, u = t == "column" ? {
        left: 0,
        top: d,
        right: 1,
        bottom: s.map.height
      } : t == "row" ? {
        left: d,
        top: 0,
        right: s.map.width,
        bottom: 1
      } : s, f = t == "column" ? l ? i.cell : i.header_cell : t == "row" ? a ? i.cell : i.header_cell : i.cell;
      s.map.cellsInRect(u).forEach((p) => {
        const h = p + s.tableStart, m = o.doc.nodeAt(h);
        m && o.setNodeMarkup(h, f, m.attrs);
      }), r(o);
    }
    return !0;
  };
}
li("row", {
  useDeprecatedLogic: !0
});
li("column", {
  useDeprecatedLogic: !0
});
var QE = li("cell", {
  useDeprecatedLogic: !0
});
function ex(t, e) {
  if (e < 0) {
    const n = t.nodeBefore;
    if (n)
      return t.pos - n.nodeSize;
    for (let r = t.index(-1) - 1, i = t.before(); r >= 0; r--) {
      const s = t.node(-1).child(r), o = s.lastChild;
      if (o)
        return i - 1 - o.nodeSize;
      i -= s.nodeSize;
    }
  } else {
    if (t.index() < t.parent.childCount - 1)
      return t.pos + t.nodeAfter.nodeSize;
    const n = t.node(-1);
    for (let r = t.indexAfter(-1), i = t.after(); r < n.childCount; r++) {
      const s = n.child(r);
      if (s.childCount)
        return i + 1;
      i += s.nodeSize;
    }
  }
  return null;
}
function vd(t) {
  return function(e, n) {
    if (!Nt(e))
      return !1;
    const r = ex(js(e), t);
    if (r == null)
      return !1;
    if (n) {
      const i = e.doc.resolve(r);
      n(
        e.tr.setSelection(G.between(i, pE(i))).scrollIntoView()
      );
    }
    return !0;
  };
}
function tx(t, e) {
  const n = t.selection.$anchor;
  for (let r = n.depth; r > 0; r--)
    if (n.node(r).type.spec.tableRole == "table")
      return e && e(
        t.tr.delete(n.before(r), n.after(r)).scrollIntoView()
      ), !0;
  return !1;
}
function nx({
  allowTableNodeSelection: t = !1
} = {}) {
  return new Se({
    key: sn,
    // This piece of state is used to remember when a mouse-drag
    // cell-selection is happening, so that it can continue even as
    // transactions (which might move its anchor cell) come in.
    state: {
      init() {
        return null;
      },
      apply(e, n) {
        const r = e.getMeta(sn);
        if (r != null)
          return r == -1 ? null : r;
        if (n == null || !e.docChanged)
          return n;
        const { deleted: i, pos: s } = e.mapping.mapResult(n);
        return i ? null : s;
      }
    },
    props: {
      decorations: mE,
      handleDOMEvents: {
        mousedown: _E
      },
      createSelectionBetween(e) {
        return sn.getState(e.state) != null ? e.state.selection : null;
      },
      handleTripleClick: kE,
      handleKeyDown: ME,
      handlePaste: TE
    },
    appendTransaction(e, n, r) {
      return yE(
        r,
        dp(r, n),
        t
      );
    }
  });
}
function wd(t, e, n, r, i, s) {
  let o = 0, a = !0, l = e.firstChild;
  const c = t.firstChild;
  for (let d = 0, u = 0; d < c.childCount; d += 1) {
    const { colspan: f, colwidth: p } = c.child(d).attrs;
    for (let h = 0; h < f; h += 1, u += 1) {
      const m = i === u ? s : p && p[h], g = m ? `${m}px` : "";
      o += m || r, m || (a = !1), l ? (l.style.width !== g && (l.style.width = g), l = l.nextSibling) : e.appendChild(document.createElement("col")).style.width = g;
    }
  }
  for (; l; ) {
    const d = l.nextSibling;
    l.parentNode.removeChild(l), l = d;
  }
  a ? (n.style.width = `${o}px`, n.style.minWidth = "") : (n.style.width = "", n.style.minWidth = `${o}px`);
}
class rx {
  constructor(e, n) {
    this.node = e, this.cellMinWidth = n, this.dom = document.createElement("div"), this.dom.className = "tableWrapper", this.table = this.dom.appendChild(document.createElement("table")), this.colgroup = this.table.appendChild(document.createElement("colgroup")), wd(e, this.colgroup, this.table, n), this.contentDOM = this.table.appendChild(document.createElement("tbody"));
  }
  update(e) {
    return e.type !== this.node.type ? !1 : (this.node = e, wd(e, this.colgroup, this.table, this.cellMinWidth), !0);
  }
  ignoreMutation(e) {
    return e.type === "attributes" && (e.target === this.table || this.colgroup.contains(e.target));
  }
}
function Ed(t, e) {
  return e ? t.createChecked(null, e) : t.createAndFill();
}
function ix(t) {
  if (t.cached.tableNodeTypes)
    return t.cached.tableNodeTypes;
  const e = {};
  return Object.keys(t.nodes).forEach((n) => {
    const r = t.nodes[n];
    r.spec.tableRole && (e[r.spec.tableRole] = r);
  }), t.cached.tableNodeTypes = e, e;
}
function sx(t, e, n, r, i) {
  const s = ix(t), o = [], a = [];
  for (let c = 0; c < n; c += 1) {
    const d = Ed(s.cell, i);
    if (d && a.push(d), r) {
      const u = Ed(s.header_cell, i);
      u && o.push(u);
    }
  }
  const l = [];
  for (let c = 0; c < e; c += 1)
    l.push(s.row.createChecked(null, r && c === 0 ? o : a));
  return s.table.createChecked(null, l);
}
function ox(t) {
  return t instanceof de;
}
const Li = ({ editor: t }) => {
  const { selection: e } = t.state;
  if (!ox(e))
    return !1;
  let n = 0;
  const r = kf(e.ranges[0].$from, (s) => s.type.name === "table");
  return r == null || r.node.descendants((s) => {
    if (s.type.name === "table")
      return !1;
    ["tableCell", "tableHeader"].includes(s.type.name) && (n += 1);
  }), n === e.ranges.length ? (t.commands.deleteTable(), !0) : !1;
}, ax = xe.create({
  name: "table",
  // @ts-ignore
  addOptions() {
    return {
      HTMLAttributes: {},
      resizable: !1,
      handleWidth: 5,
      cellMinWidth: 25,
      // TODO: fix
      View: rx,
      lastColumnResizable: !0,
      allowTableNodeSelection: !1
    };
  },
  content: "tableRow+",
  tableRole: "table",
  isolating: !0,
  group: "block",
  parseHTML() {
    return [{ tag: "table" }];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["table", fe(this.options.HTMLAttributes, t), ["tbody", 0]];
  },
  addCommands() {
    return {
      insertTable: ({ rows: t = 3, cols: e = 3, withHeaderRow: n = !0 } = {}) => ({ tr: r, dispatch: i, editor: s }) => {
        const o = sx(s.schema, t, e, n);
        if (i) {
          const a = r.selection.anchor + 1;
          r.replaceSelectionWith(o).scrollIntoView().setSelection(G.near(r.doc.resolve(a)));
        }
        return !0;
      },
      addColumnBefore: () => ({ state: t, dispatch: e }) => VE(t, e),
      addColumnAfter: () => ({ state: t, dispatch: e }) => zE(t, e),
      deleteColumn: () => ({ state: t, dispatch: e }) => UE(t, e),
      addRowBefore: () => ({ state: t, dispatch: e }) => WE(t, e),
      addRowAfter: () => ({ state: t, dispatch: e }) => qE(t, e),
      deleteRow: () => ({ state: t, dispatch: e }) => GE(t, e),
      deleteTable: () => ({ state: t, dispatch: e }) => tx(t, e),
      mergeCells: () => ({ state: t, dispatch: e }) => gd(t, e),
      splitCell: () => ({ state: t, dispatch: e }) => bd(t, e),
      toggleHeaderColumn: () => ({ state: t, dispatch: e }) => li("column")(t, e),
      toggleHeaderRow: () => ({ state: t, dispatch: e }) => li("row")(t, e),
      toggleHeaderCell: () => ({ state: t, dispatch: e }) => QE(t, e),
      mergeOrSplit: () => ({ state: t, dispatch: e }) => gd(t, e) ? !0 : bd(t, e),
      setCellAttribute: (t, e) => ({ state: n, dispatch: r }) => JE(t, e)(n, r),
      goToNextCell: () => ({ state: t, dispatch: e }) => vd(1)(t, e),
      goToPreviousCell: () => ({ state: t, dispatch: e }) => vd(-1)(t, e),
      fixTables: () => ({ state: t, dispatch: e }) => (e && dp(t), !0),
      setCellSelection: (t) => ({ tr: e, dispatch: n }) => {
        if (n) {
          const r = de.create(e.doc, t.anchorCell, t.headCell);
          e.setSelection(r);
        }
        return !0;
      }
    };
  },
  addKeyboardShortcuts() {
    return {
      Tab: () => this.editor.commands.goToNextCell() ? !0 : this.editor.can().addRowAfter() ? this.editor.chain().addRowAfter().goToNextCell().run() : !1,
      "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
      Backspace: Li,
      "Mod-Backspace": Li,
      Delete: Li,
      "Mod-Delete": Li
    };
  },
  addProseMirrorPlugins() {
    return [
      ...this.options.resizable && this.editor.isEditable ? [
        AE({
          handleWidth: this.options.handleWidth,
          cellMinWidth: this.options.cellMinWidth,
          // @ts-ignore (incorrect type)
          View: this.options.View,
          // TODO: PR for @types/prosemirror-tables
          // @ts-ignore (incorrect type)
          lastColumnResizable: this.options.lastColumnResizable
        })
      ] : [],
      nx({
        allowTableNodeSelection: this.options.allowTableNodeSelection
      })
    ];
  },
  extendNodeSchema(t) {
    const e = {
      name: t.name,
      options: t.options,
      storage: t.storage
    };
    return {
      tableRole: ie(z(t, "tableRole", e))
    };
  }
}), lx = xe.create({
  name: "tableRow",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  content: "(tableCell | tableHeader)*",
  tableRole: "row",
  parseHTML() {
    return [
      { tag: "tr" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["tr", fe(this.options.HTMLAttributes, t), 0];
  }
}), cx = xe.create({
  name: "tableHeader",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  content: "block+",
  addAttributes() {
    return {
      colspan: {
        default: 1
      },
      rowspan: {
        default: 1
      },
      colwidth: {
        default: null,
        parseHTML: (t) => {
          const e = t.getAttribute("colwidth");
          return e ? [parseInt(e, 10)] : null;
        }
      }
    };
  },
  tableRole: "header_cell",
  isolating: !0,
  parseHTML() {
    return [
      { tag: "th" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["th", fe(this.options.HTMLAttributes, t), 0];
  }
}), dx = xe.create({
  name: "tableCell",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  content: "block+",
  addAttributes() {
    return {
      colspan: {
        default: 1
      },
      rowspan: {
        default: 1
      },
      colwidth: {
        default: null,
        parseHTML: (t) => {
          const e = t.getAttribute("colwidth");
          return e ? [parseInt(e, 10)] : null;
        }
      }
    };
  },
  tableRole: "cell",
  isolating: !0,
  parseHTML() {
    return [
      { tag: "td" }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["td", fe(this.options.HTMLAttributes, t), 0];
  }
}), ux = Ce.create({
  name: "characterCount",
  addOptions() {
    return {
      limit: null,
      mode: "textSize"
    };
  },
  addStorage() {
    return {
      characters: () => 0,
      words: () => 0
    };
  },
  onBeforeCreate() {
    this.storage.characters = (t) => {
      const e = (t == null ? void 0 : t.node) || this.editor.state.doc;
      return ((t == null ? void 0 : t.mode) || this.options.mode) === "textSize" ? e.textBetween(0, e.content.size, void 0, " ").length : e.nodeSize;
    }, this.storage.words = (t) => {
      const e = (t == null ? void 0 : t.node) || this.editor.state.doc;
      return e.textBetween(0, e.content.size, " ", " ").split(" ").filter((i) => i !== "").length;
    };
  },
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("characterCount"),
        filterTransaction: (t, e) => {
          const n = this.options.limit;
          if (!t.docChanged || n === 0 || n === null || n === void 0)
            return !0;
          const r = this.storage.characters({ node: e.doc }), i = this.storage.characters({ node: t.doc });
          if (i <= n || r > n && i > n && i <= r)
            return !0;
          if (r > n && i > n && i > r || !t.getMeta("paste"))
            return !1;
          const o = t.selection.$head.pos, a = i - n, l = o - a, c = o;
          return t.deleteRange(l, c), !(this.storage.characters({ node: t.doc }) > n);
        }
      })
    ];
  }
}), fx = " ögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lkswagen7vo3te1ing3o2yage5u0elos6wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4finity6ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2", px = "ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5تصالات6رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2", _r = (t, e) => {
  for (const n in e)
    t[n] = e[n];
  return t;
}, va = "numeric", wa = "ascii", Ea = "alpha", Yi = "asciinumeric", Ii = "alphanumeric", xa = "domain", mp = "emoji", hx = "scheme", mx = "slashscheme", xd = "whitespace";
function gx(t, e) {
  return t in e || (e[t] = []), e[t];
}
function An(t, e, n) {
  e[va] && (e[Yi] = !0, e[Ii] = !0), e[wa] && (e[Yi] = !0, e[Ea] = !0), e[Yi] && (e[Ii] = !0), e[Ea] && (e[Ii] = !0), e[Ii] && (e[xa] = !0), e[mp] && (e[xa] = !0);
  for (const r in e) {
    const i = gx(r, n);
    i.indexOf(t) < 0 && i.push(t);
  }
}
function bx(t, e) {
  const n = {};
  for (const r in e)
    e[r].indexOf(t) >= 0 && (n[r] = !0);
  return n;
}
function it(t) {
  t === void 0 && (t = null), this.j = {}, this.jr = [], this.jd = null, this.t = t;
}
it.groups = {};
it.prototype = {
  accepts() {
    return !!this.t;
  },
  /**
   * Follow an existing transition from the given input to the next state.
   * Does not mutate.
   * @param {string} input character or token type to transition on
   * @returns {?State<T>} the next state, if any
   */
  go(t) {
    const e = this, n = e.j[t];
    if (n)
      return n;
    for (let r = 0; r < e.jr.length; r++) {
      const i = e.jr[r][0], s = e.jr[r][1];
      if (s && i.test(t))
        return s;
    }
    return e.jd;
  },
  /**
   * Whether the state has a transition for the given input. Set the second
   * argument to true to only look for an exact match (and not a default or
   * regular-expression-based transition)
   * @param {string} input
   * @param {boolean} exactOnly
   */
  has(t, e) {
    return e === void 0 && (e = !1), e ? t in this.j : !!this.go(t);
  },
  /**
   * Short for "transition all"; create a transition from the array of items
   * in the given list to the same final resulting state.
   * @param {string | string[]} inputs Group of inputs to transition on
   * @param {Transition<T> | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   */
  ta(t, e, n, r) {
    for (let i = 0; i < t.length; i++)
      this.tt(t[i], e, n, r);
  },
  /**
   * Short for "take regexp transition"; defines a transition for this state
   * when it encounters a token which matches the given regular expression
   * @param {RegExp} regexp Regular expression transition (populate first)
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   * @returns {State<T>} taken after the given input
   */
  tr(t, e, n, r) {
    r = r || it.groups;
    let i;
    return e && e.j ? i = e : (i = new it(e), n && r && An(e, n, r)), this.jr.push([t, i]), i;
  },
  /**
   * Short for "take transitions", will take as many sequential transitions as
   * the length of the given input and returns the
   * resulting final state.
   * @param {string | string[]} input
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of token groups
   * @returns {State<T>} taken after the given input
   */
  ts(t, e, n, r) {
    let i = this;
    const s = t.length;
    if (!s)
      return i;
    for (let o = 0; o < s - 1; o++)
      i = i.tt(t[o]);
    return i.tt(t[s - 1], e, n, r);
  },
  /**
   * Short for "take transition", this is a method for building/working with
   * state machines.
   *
   * If a state already exists for the given input, returns it.
   *
   * If a token is specified, that state will emit that token when reached by
   * the linkify engine.
   *
   * If no state exists, it will be initialized with some default transitions
   * that resemble existing default transitions.
   *
   * If a state is given for the second argument, that state will be
   * transitioned to on the given input regardless of what that input
   * previously did.
   *
   * Specify a token group flags to define groups that this token belongs to.
   * The token will be added to corresponding entires in the given groups
   * object.
   *
   * @param {string} input character, token type to transition on
   * @param {T | State<T>} [next] Transition options
   * @param {Flags} [flags] Collections flags to add token to
   * @param {Collections<T>} [groups] Master list of groups
   * @returns {State<T>} taken after the given input
   */
  tt(t, e, n, r) {
    r = r || it.groups;
    const i = this;
    if (e && e.j)
      return i.j[t] = e, e;
    const s = e;
    let o, a = i.go(t);
    if (a ? (o = new it(), _r(o.j, a.j), o.jr.push.apply(o.jr, a.jr), o.jd = a.jd, o.t = a.t) : o = new it(), s) {
      if (r)
        if (o.t && typeof o.t == "string") {
          const l = _r(bx(o.t, r), n);
          An(s, l, r);
        } else
          n && An(s, n, r);
      o.t = s;
    }
    return i.j[t] = o, o;
  }
};
const W = (t, e, n, r, i) => t.ta(e, n, r, i), bt = (t, e, n, r, i) => t.tr(e, n, r, i), Sd = (t, e, n, r, i) => t.ts(e, n, r, i), I = (t, e, n, r, i) => t.tt(e, n, r, i), Kt = "WORD", Sa = "UWORD", ci = "LOCALHOST", Ca = "TLD", Ma = "UTLD", Ji = "SCHEME", sr = "SLASH_SCHEME", ll = "NUM", gp = "WS", cl = "NL", dr = "OPENBRACE", Gr = "OPENBRACKET", jr = "OPENANGLEBRACKET", Yr = "OPENPAREN", kn = "CLOSEBRACE", ur = "CLOSEBRACKET", fr = "CLOSEANGLEBRACKET", Tn = "CLOSEPAREN", ms = "AMPERSAND", gs = "APOSTROPHE", bs = "ASTERISK", nn = "AT", ys = "BACKSLASH", vs = "BACKTICK", ws = "CARET", on = "COLON", dl = "COMMA", Es = "DOLLAR", Ot = "DOT", xs = "EQUALS", ul = "EXCLAMATION", Rt = "HYPHEN", Ss = "PERCENT", Cs = "PIPE", Ms = "PLUS", ks = "POUND", Ts = "QUERY", fl = "QUOTE", pl = "SEMI", Lt = "SLASH", Jr = "TILDE", _s = "UNDERSCORE", bp = "EMOJI", Ns = "SYM";
var yp = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  WORD: Kt,
  UWORD: Sa,
  LOCALHOST: ci,
  TLD: Ca,
  UTLD: Ma,
  SCHEME: Ji,
  SLASH_SCHEME: sr,
  NUM: ll,
  WS: gp,
  NL: cl,
  OPENBRACE: dr,
  OPENBRACKET: Gr,
  OPENANGLEBRACKET: jr,
  OPENPAREN: Yr,
  CLOSEBRACE: kn,
  CLOSEBRACKET: ur,
  CLOSEANGLEBRACKET: fr,
  CLOSEPAREN: Tn,
  AMPERSAND: ms,
  APOSTROPHE: gs,
  ASTERISK: bs,
  AT: nn,
  BACKSLASH: ys,
  BACKTICK: vs,
  CARET: ws,
  COLON: on,
  COMMA: dl,
  DOLLAR: Es,
  DOT: Ot,
  EQUALS: xs,
  EXCLAMATION: ul,
  HYPHEN: Rt,
  PERCENT: Ss,
  PIPE: Cs,
  PLUS: Ms,
  POUND: ks,
  QUERY: Ts,
  QUOTE: fl,
  SEMI: pl,
  SLASH: Lt,
  TILDE: Jr,
  UNDERSCORE: _s,
  EMOJI: bp,
  SYM: Ns
});
const Qn = /[a-z]/, Io = /\p{L}/u, Do = /\p{Emoji}/u, Ho = /\d/, Cd = /\s/, Md = `
`, yx = "️", vx = "‍";
let Di = null, Hi = null;
function wx(t) {
  t === void 0 && (t = []);
  const e = {};
  it.groups = e;
  const n = new it();
  Di == null && (Di = kd(fx)), Hi == null && (Hi = kd(px)), I(n, "'", gs), I(n, "{", dr), I(n, "[", Gr), I(n, "<", jr), I(n, "(", Yr), I(n, "}", kn), I(n, "]", ur), I(n, ">", fr), I(n, ")", Tn), I(n, "&", ms), I(n, "*", bs), I(n, "@", nn), I(n, "`", vs), I(n, "^", ws), I(n, ":", on), I(n, ",", dl), I(n, "$", Es), I(n, ".", Ot), I(n, "=", xs), I(n, "!", ul), I(n, "-", Rt), I(n, "%", Ss), I(n, "|", Cs), I(n, "+", Ms), I(n, "#", ks), I(n, "?", Ts), I(n, '"', fl), I(n, "/", Lt), I(n, ";", pl), I(n, "~", Jr), I(n, "_", _s), I(n, "\\", ys);
  const r = bt(n, Ho, ll, {
    [va]: !0
  });
  bt(r, Ho, r);
  const i = bt(n, Qn, Kt, {
    [wa]: !0
  });
  bt(i, Qn, i);
  const s = bt(n, Io, Sa, {
    [Ea]: !0
  });
  bt(s, Qn), bt(s, Io, s);
  const o = bt(n, Cd, gp, {
    [xd]: !0
  });
  I(n, Md, cl, {
    [xd]: !0
  }), I(o, Md), bt(o, Cd, o);
  const a = bt(n, Do, bp, {
    [mp]: !0
  });
  bt(a, Do, a), I(a, yx, a);
  const l = I(a, vx);
  bt(l, Do, a);
  const c = [[Qn, i]], d = [[Qn, null], [Io, s]];
  for (let u = 0; u < Di.length; u++)
    Xt(n, Di[u], Ca, Kt, c);
  for (let u = 0; u < Hi.length; u++)
    Xt(n, Hi[u], Ma, Sa, d);
  An(Ca, {
    tld: !0,
    ascii: !0
  }, e), An(Ma, {
    utld: !0,
    alpha: !0
  }, e), Xt(n, "file", Ji, Kt, c), Xt(n, "mailto", Ji, Kt, c), Xt(n, "http", sr, Kt, c), Xt(n, "https", sr, Kt, c), Xt(n, "ftp", sr, Kt, c), Xt(n, "ftps", sr, Kt, c), An(Ji, {
    scheme: !0,
    ascii: !0
  }, e), An(sr, {
    slashscheme: !0,
    ascii: !0
  }, e), t = t.sort((u, f) => u[0] > f[0] ? 1 : -1);
  for (let u = 0; u < t.length; u++) {
    const f = t[u][0], h = t[u][1] ? {
      [hx]: !0
    } : {
      [mx]: !0
    };
    f.indexOf("-") >= 0 ? h[xa] = !0 : Qn.test(f) ? Ho.test(f) ? h[Yi] = !0 : h[wa] = !0 : h[va] = !0, Sd(n, f, f, h);
  }
  return Sd(n, "localhost", ci, {
    ascii: !0
  }), n.jd = new it(Ns), {
    start: n,
    tokens: _r({
      groups: e
    }, yp)
  };
}
function Ex(t, e) {
  const n = xx(e.replace(/[A-Z]/g, (a) => a.toLowerCase())), r = n.length, i = [];
  let s = 0, o = 0;
  for (; o < r; ) {
    let a = t, l = null, c = 0, d = null, u = -1, f = -1;
    for (; o < r && (l = a.go(n[o])); )
      a = l, a.accepts() ? (u = 0, f = 0, d = a) : u >= 0 && (u += n[o].length, f++), c += n[o].length, s += n[o].length, o++;
    s -= u, o -= f, c -= u, i.push({
      t: d.t,
      // token type/name
      v: e.slice(s - c, s),
      // string value
      s: s - c,
      // start index
      e: s
      // end index (excluding)
    });
  }
  return i;
}
function xx(t) {
  const e = [], n = t.length;
  let r = 0;
  for (; r < n; ) {
    let i = t.charCodeAt(r), s, o = i < 55296 || i > 56319 || r + 1 === n || (s = t.charCodeAt(r + 1)) < 56320 || s > 57343 ? t[r] : t.slice(r, r + 2);
    e.push(o), r += o.length;
  }
  return e;
}
function Xt(t, e, n, r, i) {
  let s;
  const o = e.length;
  for (let a = 0; a < o - 1; a++) {
    const l = e[a];
    t.j[l] ? s = t.j[l] : (s = new it(r), s.jr = i.slice(), t.j[l] = s), t = s;
  }
  return s = new it(n), s.jr = i.slice(), t.j[e[o - 1]] = s, s;
}
function kd(t) {
  const e = [], n = [];
  let r = 0, i = "0123456789";
  for (; r < t.length; ) {
    let s = 0;
    for (; i.indexOf(t[r + s]) >= 0; )
      s++;
    if (s > 0) {
      e.push(n.join(""));
      for (let o = parseInt(t.substring(r, r + s), 10); o > 0; o--)
        n.pop();
      r += s;
    } else
      n.push(t[r]), r++;
  }
  return e;
}
const di = {
  defaultProtocol: "http",
  events: null,
  format: Td,
  formatHref: Td,
  nl2br: !1,
  tagName: "a",
  target: null,
  rel: null,
  validate: !0,
  truncate: 1 / 0,
  className: null,
  attributes: null,
  ignoreTags: [],
  render: null
};
function hl(t, e) {
  e === void 0 && (e = null);
  let n = _r({}, di);
  t && (n = _r(n, t instanceof hl ? t.o : t));
  const r = n.ignoreTags, i = [];
  for (let s = 0; s < r.length; s++)
    i.push(r[s].toUpperCase());
  this.o = n, e && (this.defaultRender = e), this.ignoreTags = i;
}
hl.prototype = {
  o: di,
  /**
   * @type string[]
   */
  ignoreTags: [],
  /**
   * @param {IntermediateRepresentation} ir
   * @returns {any}
   */
  defaultRender(t) {
    return t;
  },
  /**
   * Returns true or false based on whether a token should be displayed as a
   * link based on the user options.
   * @param {MultiToken} token
   * @returns {boolean}
   */
  check(t) {
    return this.get("validate", t.toString(), t);
  },
  // Private methods
  /**
   * Resolve an option's value based on the value of the option and the given
   * params. If operator and token are specified and the target option is
   * callable, automatically calls the function with the given argument.
   * @template {keyof Opts} K
   * @param {K} key Name of option to use
   * @param {string} [operator] will be passed to the target option if it's a
   * function. If not specified, RAW function value gets returned
   * @param {MultiToken} [token] The token from linkify.tokenize
   * @returns {Opts[K] | any}
   */
  get(t, e, n) {
    const r = e != null;
    let i = this.o[t];
    return i && (typeof i == "object" ? (i = n.t in i ? i[n.t] : di[t], typeof i == "function" && r && (i = i(e, n))) : typeof i == "function" && r && (i = i(e, n.t, n)), i);
  },
  /**
   * @template {keyof Opts} L
   * @param {L} key Name of options object to use
   * @param {string} [operator]
   * @param {MultiToken} [token]
   * @returns {Opts[L] | any}
   */
  getObj(t, e, n) {
    let r = this.o[t];
    return typeof r == "function" && e != null && (r = r(e, n.t, n)), r;
  },
  /**
   * Convert the given token to a rendered element that may be added to the
   * calling-interface's DOM
   * @param {MultiToken} token Token to render to an HTML element
   * @returns {any} Render result; e.g., HTML string, DOM element, React
   *   Component, etc.
   */
  render(t) {
    const e = t.render(this);
    return (this.get("render", null, t) || this.defaultRender)(e, t.t, t);
  }
};
function Td(t) {
  return t;
}
function vp(t, e) {
  this.t = "token", this.v = t, this.tk = e;
}
vp.prototype = {
  isLink: !1,
  /**
   * Return the string this token represents.
   * @return {string}
   */
  toString() {
    return this.v;
  },
  /**
   * What should the value for this token be in the `href` HTML attribute?
   * Returns the `.toString` value by default.
   * @param {string} [scheme]
   * @return {string}
  */
  toHref(t) {
    return this.toString();
  },
  /**
   * @param {Options} options Formatting options
   * @returns {string}
   */
  toFormattedString(t) {
    const e = this.toString(), n = t.get("truncate", e, this), r = t.get("format", e, this);
    return n && r.length > n ? r.substring(0, n) + "…" : r;
  },
  /**
   *
   * @param {Options} options
   * @returns {string}
   */
  toFormattedHref(t) {
    return t.get("formatHref", this.toHref(t.get("defaultProtocol")), this);
  },
  /**
   * The start index of this token in the original input string
   * @returns {number}
   */
  startIndex() {
    return this.tk[0].s;
  },
  /**
   * The end index of this token in the original input string (up to this
   * index but not including it)
   * @returns {number}
   */
  endIndex() {
    return this.tk[this.tk.length - 1].e;
  },
  /**
  	Returns an object  of relevant values for this token, which includes keys
  	* type - Kind of token ('url', 'email', etc.)
  	* value - Original text
  	* href - The value that should be added to the anchor tag's href
  		attribute
  		@method toObject
  	@param {string} [protocol] `'http'` by default
  */
  toObject(t) {
    return t === void 0 && (t = di.defaultProtocol), {
      type: this.t,
      value: this.toString(),
      isLink: this.isLink,
      href: this.toHref(t),
      start: this.startIndex(),
      end: this.endIndex()
    };
  },
  /**
   *
   * @param {Options} options Formatting option
   */
  toFormattedObject(t) {
    return {
      type: this.t,
      value: this.toFormattedString(t),
      isLink: this.isLink,
      href: this.toFormattedHref(t),
      start: this.startIndex(),
      end: this.endIndex()
    };
  },
  /**
   * Whether this token should be rendered as a link according to the given options
   * @param {Options} options
   * @returns {boolean}
   */
  validate(t) {
    return t.get("validate", this.toString(), this);
  },
  /**
   * Return an object that represents how this link should be rendered.
   * @param {Options} options Formattinng options
   */
  render(t) {
    const e = this, n = this.toHref(t.get("defaultProtocol")), r = t.get("formatHref", n, this), i = t.get("tagName", n, e), s = this.toFormattedString(t), o = {}, a = t.get("className", n, e), l = t.get("target", n, e), c = t.get("rel", n, e), d = t.getObj("attributes", n, e), u = t.getObj("events", n, e);
    return o.href = r, a && (o.class = a), l && (o.target = l), c && (o.rel = c), d && _r(o, d), {
      tagName: i,
      attributes: o,
      content: s,
      eventListeners: u
    };
  }
};
function Ys(t, e) {
  class n extends vp {
    constructor(i, s) {
      super(i, s), this.t = t;
    }
  }
  for (const r in e)
    n.prototype[r] = e[r];
  return n.t = t, n;
}
const _d = Ys("email", {
  isLink: !0,
  toHref() {
    return "mailto:" + this.toString();
  }
}), Nd = Ys("text"), Sx = Ys("nl"), Sn = Ys("url", {
  isLink: !0,
  /**
  	Lowercases relevant parts of the domain and adds the protocol if
  	required. Note that this will not escape unsafe HTML characters in the
  	URL.
  		@param {string} [scheme] default scheme (e.g., 'https')
  	@return {string} the full href
  */
  toHref(t) {
    return t === void 0 && (t = di.defaultProtocol), this.hasProtocol() ? this.v : `${t}://${this.v}`;
  },
  /**
   * Check whether this URL token has a protocol
   * @return {boolean}
   */
  hasProtocol() {
    const t = this.tk;
    return t.length >= 2 && t[0].t !== ci && t[1].t === on;
  }
}), Ie = (t) => new it(t);
function Cx(t) {
  let {
    groups: e
  } = t;
  const n = e.domain.concat([ms, bs, nn, ys, vs, ws, Es, xs, Rt, ll, Ss, Cs, Ms, ks, Lt, Ns, Jr, _s]), r = [gs, fr, kn, ur, Tn, on, dl, Ot, ul, jr, dr, Gr, Yr, Ts, fl, pl], i = [ms, gs, bs, ys, vs, ws, kn, Es, xs, Rt, dr, Ss, Cs, Ms, ks, Ts, Lt, Ns, Jr, _s], s = Ie(), o = I(s, Jr);
  W(o, i, o), W(o, e.domain, o);
  const a = Ie(), l = Ie(), c = Ie();
  W(s, e.domain, a), W(s, e.scheme, l), W(s, e.slashscheme, c), W(a, i, o), W(a, e.domain, a);
  const d = I(a, nn);
  I(o, nn, d), I(l, nn, d), I(c, nn, d);
  const u = I(o, Ot);
  W(u, i, o), W(u, e.domain, o);
  const f = Ie();
  W(d, e.domain, f), W(f, e.domain, f);
  const p = I(f, Ot);
  W(p, e.domain, f);
  const h = Ie(_d);
  W(p, e.tld, h), W(p, e.utld, h), I(d, ci, h);
  const m = I(f, Rt);
  W(m, e.domain, f), W(h, e.domain, f), I(h, Ot, p), I(h, Rt, m);
  const g = I(h, on);
  W(g, e.numeric, _d);
  const v = I(a, Rt), y = I(a, Ot);
  W(v, e.domain, a), W(y, i, o), W(y, e.domain, a);
  const E = Ie(Sn);
  W(y, e.tld, E), W(y, e.utld, E), W(E, e.domain, a), W(E, i, o), I(E, Ot, y), I(E, Rt, v), I(E, nn, d);
  const b = I(E, on), C = Ie(Sn);
  W(b, e.numeric, C);
  const w = Ie(Sn), _ = Ie();
  W(w, n, w), W(w, r, _), W(_, n, w), W(_, r, _), I(E, Lt, w), I(C, Lt, w);
  const R = I(l, on), k = I(c, on), $ = I(k, Lt), Z = I($, Lt);
  W(l, e.domain, a), I(l, Ot, y), I(l, Rt, v), W(c, e.domain, a), I(c, Ot, y), I(c, Rt, v), W(R, e.domain, w), I(R, Lt, w), W(Z, e.domain, w), W(Z, n, w), I(Z, Lt, w);
  const j = I(w, dr), J = I(w, Gr), X = I(w, jr), re = I(w, Yr);
  I(_, dr, j), I(_, Gr, J), I(_, jr, X), I(_, Yr, re), I(j, kn, w), I(J, ur, w), I(X, fr, w), I(re, Tn, w), I(j, kn, w);
  const T = Ie(Sn), x = Ie(Sn), S = Ie(Sn), O = Ie(Sn);
  W(j, n, T), W(J, n, x), W(X, n, S), W(re, n, O);
  const D = Ie(), F = Ie(), Q = Ie(), ue = Ie();
  return W(j, r), W(J, r), W(X, r), W(re, r), W(T, n, T), W(x, n, x), W(S, n, S), W(O, n, O), W(T, r, T), W(x, r, x), W(S, r, S), W(O, r, O), W(D, n, D), W(F, n, x), W(Q, n, S), W(ue, n, O), W(D, r, D), W(F, r, F), W(Q, r, Q), W(ue, r, ue), I(x, ur, w), I(S, fr, w), I(O, Tn, w), I(T, kn, w), I(F, ur, w), I(Q, fr, w), I(ue, Tn, w), I(D, Tn, w), I(s, ci, E), I(s, cl, Sx), {
    start: s,
    tokens: yp
  };
}
function Mx(t, e, n) {
  let r = n.length, i = 0, s = [], o = [];
  for (; i < r; ) {
    let a = t, l = null, c = null, d = 0, u = null, f = -1;
    for (; i < r && !(l = a.go(n[i].t)); )
      o.push(n[i++]);
    for (; i < r && (c = l || a.go(n[i].t)); )
      l = null, a = c, a.accepts() ? (f = 0, u = a) : f >= 0 && f++, i++, d++;
    if (f < 0)
      i -= d, i < r && (o.push(n[i]), i++);
    else {
      o.length > 0 && (s.push(Bo(Nd, e, o)), o = []), i -= f, d -= f;
      const p = u.t, h = n.slice(i - d, i);
      s.push(Bo(p, e, h));
    }
  }
  return o.length > 0 && s.push(Bo(Nd, e, o)), s;
}
function Bo(t, e, n) {
  const r = n[0].s, i = n[n.length - 1].e, s = e.slice(r, i);
  return new t(s, n);
}
const kx = typeof console < "u" && console && console.warn || (() => {
}), Tx = "until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.", Te = {
  scanner: null,
  parser: null,
  tokenQueue: [],
  pluginQueue: [],
  customSchemes: [],
  initialized: !1
};
function _x() {
  it.groups = {}, Te.scanner = null, Te.parser = null, Te.tokenQueue = [], Te.pluginQueue = [], Te.customSchemes = [], Te.initialized = !1;
}
function Ad(t, e) {
  if (e === void 0 && (e = !1), Te.initialized && kx(`linkifyjs: already initialized - will not register custom scheme "${t}" ${Tx}`), !/^[0-9a-z]+(-[0-9a-z]+)*$/.test(t))
    throw new Error(`linkifyjs: incorrect scheme format.
1. Must only contain digits, lowercase ASCII letters or "-"
2. Cannot start or end with "-"
3. "-" cannot repeat`);
  Te.customSchemes.push([t, e]);
}
function Nx() {
  Te.scanner = wx(Te.customSchemes);
  for (let t = 0; t < Te.tokenQueue.length; t++)
    Te.tokenQueue[t][1]({
      scanner: Te.scanner
    });
  Te.parser = Cx(Te.scanner.tokens);
  for (let t = 0; t < Te.pluginQueue.length; t++)
    Te.pluginQueue[t][1]({
      scanner: Te.scanner,
      parser: Te.parser
    });
  Te.initialized = !0;
}
function Ax(t) {
  return Te.initialized || Nx(), Mx(Te.parser.start, t, Ex(Te.scanner.start, t));
}
function ml(t, e, n) {
  if (e === void 0 && (e = null), n === void 0 && (n = null), e && typeof e == "object") {
    if (n)
      throw Error(`linkifyjs: Invalid link type ${e}; must be a string`);
    n = e, e = null;
  }
  const r = new hl(n), i = Ax(t), s = [];
  for (let o = 0; o < i.length; o++) {
    const a = i[o];
    a.isLink && (!e || a.t === e) && r.check(a) && s.push(a.toFormattedObject(r));
  }
  return s;
}
function Ox(t) {
  return new Se({
    key: new Me("autolink"),
    appendTransaction: (e, n, r) => {
      const i = e.some((c) => c.docChanged) && !n.doc.eq(r.doc), s = e.some((c) => c.getMeta("preventAutolink"));
      if (!i || s)
        return;
      const { tr: o } = r, a = mb(n.doc, [...e]);
      if (Sb(a).forEach(({ newRange: c }) => {
        const d = bb(r.doc, c, (p) => p.isTextblock);
        let u, f;
        if (d.length > 1 ? (u = d[0], f = r.doc.textBetween(u.pos, u.pos + u.node.nodeSize, void 0, " ")) : d.length && r.doc.textBetween(c.from, c.to, " ", " ").endsWith(" ") && (u = d[0], f = r.doc.textBetween(u.pos, c.to, void 0, " ")), u && f) {
          const p = f.split(" ").filter((g) => g !== "");
          if (p.length <= 0)
            return !1;
          const h = p[p.length - 1], m = u.pos + f.lastIndexOf(h);
          if (!h)
            return !1;
          ml(h).filter((g) => g.isLink).map((g) => ({
            ...g,
            from: m + g.start + 1,
            to: m + g.end + 1
          })).filter((g) => r.schema.marks.code ? !r.doc.rangeHasMark(g.from, g.to, r.schema.marks.code) : !0).filter((g) => t.validate ? t.validate(g.value) : !0).forEach((g) => {
            qa(g.from, g.to, r.doc).some((v) => v.mark.type === t.type) || o.addMark(g.from, g.to, t.type.create({
              href: g.href
            }));
          });
        }
      }), !!o.steps.length)
        return o;
    }
  });
}
function Rx(t) {
  return new Se({
    key: new Me("handleClickLink"),
    props: {
      handleClick: (e, n, r) => {
        var i, s;
        if (r.button !== 0 || r.target.nodeName !== "A")
          return !1;
        const a = Tf(e.state, t.type.name), l = r.target, c = (i = l == null ? void 0 : l.href) !== null && i !== void 0 ? i : a.href, d = (s = l == null ? void 0 : l.target) !== null && s !== void 0 ? s : a.target;
        return l && c ? (e.editable && window.open(c, d), !0) : !1;
      }
    }
  });
}
function Lx(t) {
  return new Se({
    key: new Me("handlePasteLink"),
    props: {
      handlePaste: (e, n, r) => {
        var i;
        const { state: s } = e, { selection: o } = s, { empty: a } = o;
        if (a)
          return !1;
        let l = "";
        r.content.forEach((h) => {
          l += h.textContent;
        });
        const c = ml(l).find((h) => h.isLink && h.value === l);
        if (!l || !c)
          return !1;
        const d = (i = n.clipboardData) === null || i === void 0 ? void 0 : i.getData("text/html"), u = /href="([^"]*)"/, f = d == null ? void 0 : d.match(u), p = f ? f[1] : c.href;
        return t.editor.commands.setMark(t.type, {
          href: p
        }), !0;
      }
    }
  });
}
const Ix = qe.create({
  name: "link",
  priority: 1e3,
  keepOnSplit: !1,
  onCreate() {
    this.options.protocols.forEach((t) => {
      if (typeof t == "string") {
        Ad(t);
        return;
      }
      Ad(t.scheme, t.optionalSlashes);
    });
  },
  onDestroy() {
    _x();
  },
  inclusive() {
    return this.options.autolink;
  },
  addOptions() {
    return {
      openOnClick: !0,
      linkOnPaste: !0,
      autolink: !0,
      protocols: [],
      HTMLAttributes: {
        target: "_blank",
        rel: "noopener noreferrer nofollow",
        class: null
      },
      validate: void 0
    };
  },
  addAttributes() {
    return {
      href: {
        default: null
      },
      target: {
        default: this.options.HTMLAttributes.target
      },
      rel: {
        default: this.options.HTMLAttributes.rel
      },
      class: {
        default: this.options.HTMLAttributes.class
      }
    };
  },
  parseHTML() {
    return [{ tag: 'a[href]:not([href *= "javascript:" i])' }];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["a", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setLink: (t) => ({ chain: e }) => e().setMark(this.name, t).setMeta("preventAutolink", !0).run(),
      toggleLink: (t) => ({ chain: e }) => e().toggleMark(this.name, t, { extendEmptyMarkRange: !0 }).setMeta("preventAutolink", !0).run(),
      unsetLink: () => ({ chain: t }) => t().unsetMark(this.name, { extendEmptyMarkRange: !0 }).setMeta("preventAutolink", !0).run()
    };
  },
  addPasteRules() {
    return [
      yn({
        find: (t) => ml(t).filter((e) => this.options.validate ? this.options.validate(e.value) : !0).filter((e) => e.isLink).map((e) => ({
          text: e.value,
          index: e.start,
          data: e
        })),
        type: this.type,
        getAttributes: (t, e) => {
          var n, r;
          const i = (n = e == null ? void 0 : e.clipboardData) === null || n === void 0 ? void 0 : n.getData("text/html"), s = /href="([^"]*)"/, o = i == null ? void 0 : i.match(s);
          return o ? {
            href: o[1]
          } : {
            href: (r = t.data) === null || r === void 0 ? void 0 : r.href
          };
        }
      })
    ];
  },
  addProseMirrorPlugins() {
    const t = [];
    return this.options.autolink && t.push(Ox({
      type: this.type,
      validate: this.options.validate
    })), this.options.openOnClick && t.push(Rx({
      type: this.type
    })), this.options.linkOnPaste && t.push(Lx({
      editor: this.editor,
      type: this.type
    })), t;
  }
}), Dx = qe.create({
  name: "superscript",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "sup"
      },
      {
        style: "vertical-align",
        getAttrs(t) {
          return t !== "super" ? !1 : null;
        }
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["sup", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setSuperscript: () => ({ commands: t }) => t.setMark(this.name),
      toggleSuperscript: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetSuperscript: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-.": () => this.editor.commands.toggleSuperscript()
    };
  }
}), Hx = qe.create({
  name: "subscript",
  addOptions() {
    return {
      HTMLAttributes: {}
    };
  },
  parseHTML() {
    return [
      {
        tag: "sub"
      },
      {
        style: "vertical-align",
        getAttrs(t) {
          return t !== "sub" ? !1 : null;
        }
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["sub", fe(this.options.HTMLAttributes, t), 0];
  },
  addCommands() {
    return {
      setSubscript: () => ({ commands: t }) => t.setMark(this.name),
      toggleSubscript: () => ({ commands: t }) => t.toggleMark(this.name),
      unsetSubscript: () => ({ commands: t }) => t.unsetMark(this.name)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-,": () => this.editor.commands.toggleSubscript()
    };
  }
}), Bx = xe.create({
  name: "taskList",
  addOptions() {
    return {
      itemTypeName: "taskItem",
      HTMLAttributes: {}
    };
  },
  group: "block list",
  content() {
    return `${this.options.itemTypeName}+`;
  },
  parseHTML() {
    return [
      {
        tag: `ul[data-type="${this.name}"]`,
        priority: 51
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["ul", fe(this.options.HTMLAttributes, t, { "data-type": this.name }), 0];
  },
  addCommands() {
    return {
      toggleTaskList: () => ({ commands: t }) => t.toggleList(this.name, this.options.itemTypeName)
    };
  },
  addKeyboardShortcuts() {
    return {
      "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
    };
  }
}), Px = /^\s*(\[([( |x])?\])\s$/, $x = xe.create({
  name: "taskItem",
  addOptions() {
    return {
      nested: !1,
      HTMLAttributes: {},
      taskListTypeName: "taskList"
    };
  },
  content() {
    return this.options.nested ? "paragraph block*" : "paragraph+";
  },
  defining: !0,
  addAttributes() {
    return {
      checked: {
        default: !1,
        keepOnSplit: !1,
        parseHTML: (t) => t.getAttribute("data-checked") === "true",
        renderHTML: (t) => ({
          "data-checked": t.checked
        })
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: `li[data-type="${this.name}"]`,
        priority: 51
      }
    ];
  },
  renderHTML({ node: t, HTMLAttributes: e }) {
    return [
      "li",
      fe(this.options.HTMLAttributes, e, {
        "data-type": this.name
      }),
      [
        "label",
        [
          "input",
          {
            type: "checkbox",
            checked: t.attrs.checked ? "checked" : null
          }
        ],
        ["span"]
      ],
      ["div", 0]
    ];
  },
  addKeyboardShortcuts() {
    const t = {
      Enter: () => this.editor.commands.splitListItem(this.name),
      "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
    };
    return this.options.nested ? {
      ...t,
      Tab: () => this.editor.commands.sinkListItem(this.name)
    } : t;
  },
  addNodeView() {
    return ({ node: t, HTMLAttributes: e, getPos: n, editor: r }) => {
      const i = document.createElement("li"), s = document.createElement("label"), o = document.createElement("span"), a = document.createElement("input"), l = document.createElement("div");
      return s.contentEditable = "false", a.type = "checkbox", a.addEventListener("change", (c) => {
        if (!r.isEditable && !this.options.onReadOnlyChecked) {
          a.checked = !a.checked;
          return;
        }
        const { checked: d } = c.target;
        r.isEditable && typeof n == "function" && r.chain().focus(void 0, { scrollIntoView: !1 }).command(({ tr: u }) => {
          const f = n(), p = u.doc.nodeAt(f);
          return u.setNodeMarkup(f, void 0, {
            ...p == null ? void 0 : p.attrs,
            checked: d
          }), !0;
        }).run(), !r.isEditable && this.options.onReadOnlyChecked && (this.options.onReadOnlyChecked(t, d) || (a.checked = !a.checked));
      }), Object.entries(this.options.HTMLAttributes).forEach(([c, d]) => {
        i.setAttribute(c, d);
      }), i.dataset.checked = t.attrs.checked, t.attrs.checked && a.setAttribute("checked", "checked"), s.append(a, o), i.append(s, l), Object.entries(e).forEach(([c, d]) => {
        i.setAttribute(c, d);
      }), {
        dom: i,
        contentDOM: l,
        update: (c) => c.type !== this.type ? !1 : (i.dataset.checked = c.attrs.checked, c.attrs.checked ? a.setAttribute("checked", "checked") : a.removeAttribute("checked"), !0)
      };
    };
  },
  addInputRules() {
    return [
      Sr({
        find: Px,
        type: this.type,
        getAttributes: (t) => ({
          checked: t[t.length - 1] === "x"
        })
      })
    ];
  }
});
var gl = { exports: {} };
function bl(t) {
  return t instanceof Map ? t.clear = t.delete = t.set = function() {
    throw new Error("map is read-only");
  } : t instanceof Set && (t.add = t.clear = t.delete = function() {
    throw new Error("set is read-only");
  }), Object.freeze(t), Object.getOwnPropertyNames(t).forEach(function(e) {
    var n = t[e];
    typeof n == "object" && !Object.isFrozen(n) && bl(n);
  }), t;
}
gl.exports = bl;
gl.exports.default = bl;
let Od = class {
  /**
   * @param {CompiledMode} mode
   */
  constructor(e) {
    e.data === void 0 && (e.data = {}), this.data = e.data, this.isMatchIgnored = !1;
  }
  ignoreMatch() {
    this.isMatchIgnored = !0;
  }
};
function wp(t) {
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
}
function un(t, ...e) {
  const n = /* @__PURE__ */ Object.create(null);
  for (const r in t)
    n[r] = t[r];
  return e.forEach(function(r) {
    for (const i in r)
      n[i] = r[i];
  }), /** @type {T} */
  n;
}
const Vx = "</span>", Rd = (t) => !!t.scope || t.sublanguage && t.language, zx = (t, { prefix: e }) => {
  if (t.includes(".")) {
    const n = t.split(".");
    return [
      `${e}${n.shift()}`,
      ...n.map((r, i) => `${r}${"_".repeat(i + 1)}`)
    ].join(" ");
  }
  return `${e}${t}`;
};
let Fx = class {
  /**
   * Creates a new HTMLRenderer
   *
   * @param {Tree} parseTree - the parse tree (must support `walk` API)
   * @param {{classPrefix: string}} options
   */
  constructor(e, n) {
    this.buffer = "", this.classPrefix = n.classPrefix, e.walk(this);
  }
  /**
   * Adds texts to the output stream
   *
   * @param {string} text */
  addText(e) {
    this.buffer += wp(e);
  }
  /**
   * Adds a node open to the output stream (if needed)
   *
   * @param {Node} node */
  openNode(e) {
    if (!Rd(e))
      return;
    let n = "";
    e.sublanguage ? n = `language-${e.language}` : n = zx(e.scope, { prefix: this.classPrefix }), this.span(n);
  }
  /**
   * Adds a node close to the output stream (if needed)
   *
   * @param {Node} node */
  closeNode(e) {
    Rd(e) && (this.buffer += Vx);
  }
  /**
   * returns the accumulated buffer
  */
  value() {
    return this.buffer;
  }
  // helpers
  /**
   * Builds a span element
   *
   * @param {string} className */
  span(e) {
    this.buffer += `<span class="${e}">`;
  }
};
const Ld = (t = {}) => {
  const e = { children: [] };
  return Object.assign(e, t), e;
};
let Ux = class Ep {
  constructor() {
    this.rootNode = Ld(), this.stack = [this.rootNode];
  }
  get top() {
    return this.stack[this.stack.length - 1];
  }
  get root() {
    return this.rootNode;
  }
  /** @param {Node} node */
  add(e) {
    this.top.children.push(e);
  }
  /** @param {string} scope */
  openNode(e) {
    const n = Ld({ scope: e });
    this.add(n), this.stack.push(n);
  }
  closeNode() {
    if (this.stack.length > 1)
      return this.stack.pop();
  }
  closeAllNodes() {
    for (; this.closeNode(); )
      ;
  }
  toJSON() {
    return JSON.stringify(this.rootNode, null, 4);
  }
  /**
   * @typedef { import("./html_renderer").Renderer } Renderer
   * @param {Renderer} builder
   */
  walk(e) {
    return this.constructor._walk(e, this.rootNode);
  }
  /**
   * @param {Renderer} builder
   * @param {Node} node
   */
  static _walk(e, n) {
    return typeof n == "string" ? e.addText(n) : n.children && (e.openNode(n), n.children.forEach((r) => this._walk(e, r)), e.closeNode(n)), e;
  }
  /**
   * @param {Node} node
   */
  static _collapse(e) {
    typeof e != "string" && e.children && (e.children.every((n) => typeof n == "string") ? e.children = [e.children.join("")] : e.children.forEach((n) => {
      Ep._collapse(n);
    }));
  }
}, Kx = class extends Ux {
  /**
   * @param {*} options
   */
  constructor(e) {
    super(), this.options = e;
  }
  /**
   * @param {string} text
   * @param {string} scope
   */
  addKeyword(e, n) {
    e !== "" && (this.openNode(n), this.addText(e), this.closeNode());
  }
  /**
   * @param {string} text
   */
  addText(e) {
    e !== "" && this.add(e);
  }
  /**
   * @param {Emitter & {root: DataNode}} emitter
   * @param {string} name
   */
  addSublanguage(e, n) {
    const r = e.root;
    r.sublanguage = !0, r.language = n, this.add(r);
  }
  toHTML() {
    return new Fx(this, this.options).value();
  }
  finalize() {
    return !0;
  }
};
function ui(t) {
  return t ? typeof t == "string" ? t : t.source : null;
}
function xp(t) {
  return qn("(?=", t, ")");
}
function Wx(t) {
  return qn("(?:", t, ")*");
}
function qx(t) {
  return qn("(?:", t, ")?");
}
function qn(...t) {
  return t.map((n) => ui(n)).join("");
}
function Zx(t) {
  const e = t[t.length - 1];
  return typeof e == "object" && e.constructor === Object ? (t.splice(t.length - 1, 1), e) : {};
}
function yl(...t) {
  return "(" + (Zx(t).capture ? "" : "?:") + t.map((r) => ui(r)).join("|") + ")";
}
function Sp(t) {
  return new RegExp(t.toString() + "|").exec("").length - 1;
}
function Gx(t, e) {
  const n = t && t.exec(e);
  return n && n.index === 0;
}
const jx = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
function vl(t, { joinWith: e }) {
  let n = 0;
  return t.map((r) => {
    n += 1;
    const i = n;
    let s = ui(r), o = "";
    for (; s.length > 0; ) {
      const a = jx.exec(s);
      if (!a) {
        o += s;
        break;
      }
      o += s.substring(0, a.index), s = s.substring(a.index + a[0].length), a[0][0] === "\\" && a[1] ? o += "\\" + String(Number(a[1]) + i) : (o += a[0], a[0] === "(" && n++);
    }
    return o;
  }).map((r) => `(${r})`).join(e);
}
const Yx = /\b\B/, Cp = "[a-zA-Z]\\w*", wl = "[a-zA-Z_]\\w*", Mp = "\\b\\d+(\\.\\d+)?", kp = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)", Tp = "\\b(0b[01]+)", Jx = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~", Xx = (t = {}) => {
  const e = /^#![ ]*\//;
  return t.binary && (t.begin = qn(
    e,
    /.*\b/,
    t.binary,
    /\b.*/
  )), un({
    scope: "meta",
    begin: e,
    end: /$/,
    relevance: 0,
    /** @type {ModeCallback} */
    "on:begin": (n, r) => {
      n.index !== 0 && r.ignoreMatch();
    }
  }, t);
}, fi = {
  begin: "\\\\[\\s\\S]",
  relevance: 0
}, Qx = {
  scope: "string",
  begin: "'",
  end: "'",
  illegal: "\\n",
  contains: [fi]
}, eS = {
  scope: "string",
  begin: '"',
  end: '"',
  illegal: "\\n",
  contains: [fi]
}, tS = {
  begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
}, Js = function(t, e, n = {}) {
  const r = un(
    {
      scope: "comment",
      begin: t,
      end: e,
      contains: []
    },
    n
  );
  r.contains.push({
    scope: "doctag",
    // hack to avoid the space from being included. the space is necessary to
    // match here to prevent the plain text rule below from gobbling up doctags
    begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
    end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
    excludeBegin: !0,
    relevance: 0
  });
  const i = yl(
    // list of common 1 and 2 letter words in English
    "I",
    "a",
    "is",
    "so",
    "us",
    "to",
    "at",
    "if",
    "in",
    "it",
    "on",
    // note: this is not an exhaustive list of contractions, just popular ones
    /[A-Za-z]+['](d|ve|re|ll|t|s|n)/,
    // contractions - can't we'd they're let's, etc
    /[A-Za-z]+[-][a-z]+/,
    // `no-way`, etc.
    /[A-Za-z][a-z]{2,}/
    // allow capitalized words at beginning of sentences
  );
  return r.contains.push(
    {
      // TODO: how to include ", (, ) without breaking grammars that use these for
      // comment delimiters?
      // begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/
      // ---
      // this tries to find sequences of 3 english words in a row (without any
      // "programming" type syntax) this gives us a strong signal that we've
      // TRULY found a comment - vs perhaps scanning with the wrong language.
      // It's possible to find something that LOOKS like the start of the
      // comment - but then if there is no readable text - good chance it is a
      // false match and not a comment.
      //
      // for a visual example please see:
      // https://github.com/highlightjs/highlight.js/issues/2827
      begin: qn(
        /[ ]+/,
        // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
        "(",
        i,
        /[.]?[:]?([.][ ]|[ ])/,
        "){3}"
      )
      // look for 3 words in a row
    }
  ), r;
}, nS = Js("//", "$"), rS = Js("/\\*", "\\*/"), iS = Js("#", "$"), sS = {
  scope: "number",
  begin: Mp,
  relevance: 0
}, oS = {
  scope: "number",
  begin: kp,
  relevance: 0
}, aS = {
  scope: "number",
  begin: Tp,
  relevance: 0
}, lS = {
  // this outer rule makes sure we actually have a WHOLE regex and not simply
  // an expression such as:
  //
  //     3 / something
  //
  // (which will then blow up when regex's `illegal` sees the newline)
  begin: /(?=\/[^/\n]*\/)/,
  contains: [{
    scope: "regexp",
    begin: /\//,
    end: /\/[gimuy]*/,
    illegal: /\n/,
    contains: [
      fi,
      {
        begin: /\[/,
        end: /\]/,
        relevance: 0,
        contains: [fi]
      }
    ]
  }]
}, cS = {
  scope: "title",
  begin: Cp,
  relevance: 0
}, dS = {
  scope: "title",
  begin: wl,
  relevance: 0
}, uS = {
  // excludes method names from keyword processing
  begin: "\\.\\s*" + wl,
  relevance: 0
}, fS = function(t) {
  return Object.assign(
    t,
    {
      /** @type {ModeCallback} */
      "on:begin": (e, n) => {
        n.data._beginMatch = e[1];
      },
      /** @type {ModeCallback} */
      "on:end": (e, n) => {
        n.data._beginMatch !== e[1] && n.ignoreMatch();
      }
    }
  );
};
var Bi = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  MATCH_NOTHING_RE: Yx,
  IDENT_RE: Cp,
  UNDERSCORE_IDENT_RE: wl,
  NUMBER_RE: Mp,
  C_NUMBER_RE: kp,
  BINARY_NUMBER_RE: Tp,
  RE_STARTERS_RE: Jx,
  SHEBANG: Xx,
  BACKSLASH_ESCAPE: fi,
  APOS_STRING_MODE: Qx,
  QUOTE_STRING_MODE: eS,
  PHRASAL_WORDS_MODE: tS,
  COMMENT: Js,
  C_LINE_COMMENT_MODE: nS,
  C_BLOCK_COMMENT_MODE: rS,
  HASH_COMMENT_MODE: iS,
  NUMBER_MODE: sS,
  C_NUMBER_MODE: oS,
  BINARY_NUMBER_MODE: aS,
  REGEXP_MODE: lS,
  TITLE_MODE: cS,
  UNDERSCORE_TITLE_MODE: dS,
  METHOD_GUARD: uS,
  END_SAME_AS_BEGIN: fS
});
function pS(t, e) {
  t.input[t.index - 1] === "." && e.ignoreMatch();
}
function hS(t, e) {
  t.className !== void 0 && (t.scope = t.className, delete t.className);
}
function mS(t, e) {
  e && t.beginKeywords && (t.begin = "\\b(" + t.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)", t.__beforeBegin = pS, t.keywords = t.keywords || t.beginKeywords, delete t.beginKeywords, t.relevance === void 0 && (t.relevance = 0));
}
function gS(t, e) {
  Array.isArray(t.illegal) && (t.illegal = yl(...t.illegal));
}
function bS(t, e) {
  if (t.match) {
    if (t.begin || t.end)
      throw new Error("begin & end are not supported with match");
    t.begin = t.match, delete t.match;
  }
}
function yS(t, e) {
  t.relevance === void 0 && (t.relevance = 1);
}
const vS = (t, e) => {
  if (!t.beforeMatch)
    return;
  if (t.starts)
    throw new Error("beforeMatch cannot be used with starts");
  const n = Object.assign({}, t);
  Object.keys(t).forEach((r) => {
    delete t[r];
  }), t.keywords = n.keywords, t.begin = qn(n.beforeMatch, xp(n.begin)), t.starts = {
    relevance: 0,
    contains: [
      Object.assign(n, { endsParent: !0 })
    ]
  }, t.relevance = 0, delete n.beforeMatch;
}, wS = [
  "of",
  "and",
  "for",
  "in",
  "not",
  "or",
  "if",
  "then",
  "parent",
  // common variable name
  "list",
  // common variable name
  "value"
  // common variable name
], ES = "keyword";
function _p(t, e, n = ES) {
  const r = /* @__PURE__ */ Object.create(null);
  return typeof t == "string" ? i(n, t.split(" ")) : Array.isArray(t) ? i(n, t) : Object.keys(t).forEach(function(s) {
    Object.assign(
      r,
      _p(t[s], e, s)
    );
  }), r;
  function i(s, o) {
    e && (o = o.map((a) => a.toLowerCase())), o.forEach(function(a) {
      const l = a.split("|");
      r[l[0]] = [s, xS(l[0], l[1])];
    });
  }
}
function xS(t, e) {
  return e ? Number(e) : SS(t) ? 0 : 1;
}
function SS(t) {
  return wS.includes(t.toLowerCase());
}
const Id = {}, Bn = (t) => {
  console.error(t);
}, Dd = (t, ...e) => {
  console.log(`WARN: ${t}`, ...e);
}, er = (t, e) => {
  Id[`${t}/${e}`] || (console.log(`Deprecated as of ${t}. ${e}`), Id[`${t}/${e}`] = !0);
}, As = new Error();
function Np(t, e, { key: n }) {
  let r = 0;
  const i = t[n], s = {}, o = {};
  for (let a = 1; a <= e.length; a++)
    o[a + r] = i[a], s[a + r] = !0, r += Sp(e[a - 1]);
  t[n] = o, t[n]._emit = s, t[n]._multi = !0;
}
function CS(t) {
  if (Array.isArray(t.begin)) {
    if (t.skip || t.excludeBegin || t.returnBegin)
      throw Bn("skip, excludeBegin, returnBegin not compatible with beginScope: {}"), As;
    if (typeof t.beginScope != "object" || t.beginScope === null)
      throw Bn("beginScope must be object"), As;
    Np(t, t.begin, { key: "beginScope" }), t.begin = vl(t.begin, { joinWith: "" });
  }
}
function MS(t) {
  if (Array.isArray(t.end)) {
    if (t.skip || t.excludeEnd || t.returnEnd)
      throw Bn("skip, excludeEnd, returnEnd not compatible with endScope: {}"), As;
    if (typeof t.endScope != "object" || t.endScope === null)
      throw Bn("endScope must be object"), As;
    Np(t, t.end, { key: "endScope" }), t.end = vl(t.end, { joinWith: "" });
  }
}
function kS(t) {
  t.scope && typeof t.scope == "object" && t.scope !== null && (t.beginScope = t.scope, delete t.scope);
}
function TS(t) {
  kS(t), typeof t.beginScope == "string" && (t.beginScope = { _wrap: t.beginScope }), typeof t.endScope == "string" && (t.endScope = { _wrap: t.endScope }), CS(t), MS(t);
}
function _S(t) {
  function e(o, a) {
    return new RegExp(
      ui(o),
      "m" + (t.case_insensitive ? "i" : "") + (t.unicodeRegex ? "u" : "") + (a ? "g" : "")
    );
  }
  class n {
    constructor() {
      this.matchIndexes = {}, this.regexes = [], this.matchAt = 1, this.position = 0;
    }
    // @ts-ignore
    addRule(a, l) {
      l.position = this.position++, this.matchIndexes[this.matchAt] = l, this.regexes.push([l, a]), this.matchAt += Sp(a) + 1;
    }
    compile() {
      this.regexes.length === 0 && (this.exec = () => null);
      const a = this.regexes.map((l) => l[1]);
      this.matcherRe = e(vl(a, { joinWith: "|" }), !0), this.lastIndex = 0;
    }
    /** @param {string} s */
    exec(a) {
      this.matcherRe.lastIndex = this.lastIndex;
      const l = this.matcherRe.exec(a);
      if (!l)
        return null;
      const c = l.findIndex((u, f) => f > 0 && u !== void 0), d = this.matchIndexes[c];
      return l.splice(0, c), Object.assign(l, d);
    }
  }
  class r {
    constructor() {
      this.rules = [], this.multiRegexes = [], this.count = 0, this.lastIndex = 0, this.regexIndex = 0;
    }
    // @ts-ignore
    getMatcher(a) {
      if (this.multiRegexes[a])
        return this.multiRegexes[a];
      const l = new n();
      return this.rules.slice(a).forEach(([c, d]) => l.addRule(c, d)), l.compile(), this.multiRegexes[a] = l, l;
    }
    resumingScanAtSamePosition() {
      return this.regexIndex !== 0;
    }
    considerAll() {
      this.regexIndex = 0;
    }
    // @ts-ignore
    addRule(a, l) {
      this.rules.push([a, l]), l.type === "begin" && this.count++;
    }
    /** @param {string} s */
    exec(a) {
      const l = this.getMatcher(this.regexIndex);
      l.lastIndex = this.lastIndex;
      let c = l.exec(a);
      if (this.resumingScanAtSamePosition() && !(c && c.index === this.lastIndex)) {
        const d = this.getMatcher(0);
        d.lastIndex = this.lastIndex + 1, c = d.exec(a);
      }
      return c && (this.regexIndex += c.position + 1, this.regexIndex === this.count && this.considerAll()), c;
    }
  }
  function i(o) {
    const a = new r();
    return o.contains.forEach((l) => a.addRule(l.begin, { rule: l, type: "begin" })), o.terminatorEnd && a.addRule(o.terminatorEnd, { type: "end" }), o.illegal && a.addRule(o.illegal, { type: "illegal" }), a;
  }
  function s(o, a) {
    const l = (
      /** @type CompiledMode */
      o
    );
    if (o.isCompiled)
      return l;
    [
      hS,
      // do this early so compiler extensions generally don't have to worry about
      // the distinction between match/begin
      bS,
      TS,
      vS
    ].forEach((d) => d(o, a)), t.compilerExtensions.forEach((d) => d(o, a)), o.__beforeBegin = null, [
      mS,
      // do this later so compiler extensions that come earlier have access to the
      // raw array if they wanted to perhaps manipulate it, etc.
      gS,
      // default to 1 relevance if not specified
      yS
    ].forEach((d) => d(o, a)), o.isCompiled = !0;
    let c = null;
    return typeof o.keywords == "object" && o.keywords.$pattern && (o.keywords = Object.assign({}, o.keywords), c = o.keywords.$pattern, delete o.keywords.$pattern), c = c || /\w+/, o.keywords && (o.keywords = _p(o.keywords, t.case_insensitive)), l.keywordPatternRe = e(c, !0), a && (o.begin || (o.begin = /\B|\b/), l.beginRe = e(l.begin), !o.end && !o.endsWithParent && (o.end = /\B|\b/), o.end && (l.endRe = e(l.end)), l.terminatorEnd = ui(l.end) || "", o.endsWithParent && a.terminatorEnd && (l.terminatorEnd += (o.end ? "|" : "") + a.terminatorEnd)), o.illegal && (l.illegalRe = e(
      /** @type {RegExp | string} */
      o.illegal
    )), o.contains || (o.contains = []), o.contains = [].concat(...o.contains.map(function(d) {
      return NS(d === "self" ? o : d);
    })), o.contains.forEach(function(d) {
      s(
        /** @type Mode */
        d,
        l
      );
    }), o.starts && s(o.starts, a), l.matcher = i(l), l;
  }
  if (t.compilerExtensions || (t.compilerExtensions = []), t.contains && t.contains.includes("self"))
    throw new Error("ERR: contains `self` is not supported at the top-level of a language.  See documentation.");
  return t.classNameAliases = un(t.classNameAliases || {}), s(
    /** @type Mode */
    t
  );
}
function Ap(t) {
  return t ? t.endsWithParent || Ap(t.starts) : !1;
}
function NS(t) {
  return t.variants && !t.cachedVariants && (t.cachedVariants = t.variants.map(function(e) {
    return un(t, { variants: null }, e);
  })), t.cachedVariants ? t.cachedVariants : Ap(t) ? un(t, { starts: t.starts ? un(t.starts) : null }) : Object.isFrozen(t) ? un(t) : t;
}
var AS = "11.6.0";
let OS = class extends Error {
  constructor(e, n) {
    super(e), this.name = "HTMLInjectionError", this.html = n;
  }
};
const Po = wp, Hd = un, Bd = Symbol("nomatch"), RS = 7, LS = function(t) {
  const e = /* @__PURE__ */ Object.create(null), n = /* @__PURE__ */ Object.create(null), r = [];
  let i = !0;
  const s = "Could not find the language '{}', did you forget to load/include a language module?", o = { disableAutodetect: !0, name: "Plain text", contains: [] };
  let a = {
    ignoreUnescapedHTML: !1,
    throwUnescapedHTML: !1,
    noHighlightRe: /^(no-?highlight)$/i,
    languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
    classPrefix: "hljs-",
    cssSelector: "pre code",
    languages: null,
    // beta configuration options, subject to change, welcome to discuss
    // https://github.com/highlightjs/highlight.js/issues/1086
    __emitter: Kx
  };
  function l(T) {
    return a.noHighlightRe.test(T);
  }
  function c(T) {
    let x = T.className + " ";
    x += T.parentNode ? T.parentNode.className : "";
    const S = a.languageDetectRe.exec(x);
    if (S) {
      const O = k(S[1]);
      return O || (Dd(s.replace("{}", S[1])), Dd("Falling back to no-highlight mode for this block.", T)), O ? S[1] : "no-highlight";
    }
    return x.split(/\s+/).find((O) => l(O) || k(O));
  }
  function d(T, x, S) {
    let O = "", D = "";
    typeof x == "object" ? (O = T, S = x.ignoreIllegals, D = x.language) : (er("10.7.0", "highlight(lang, code, ...args) has been deprecated."), er("10.7.0", `Please use highlight(code, options) instead.
https://github.com/highlightjs/highlight.js/issues/2277`), D = T, O = x), S === void 0 && (S = !0);
    const F = {
      code: O,
      language: D
    };
    X("before:highlight", F);
    const Q = F.result ? F.result : u(F.language, F.code, S);
    return Q.code = F.code, X("after:highlight", Q), Q;
  }
  function u(T, x, S, O) {
    const D = /* @__PURE__ */ Object.create(null);
    function F(H, V) {
      return H.keywords[V];
    }
    function Q() {
      if (!ee.keywords) {
        P.addText(ae);
        return;
      }
      let H = 0;
      ee.keywordPatternRe.lastIndex = 0;
      let V = ee.keywordPatternRe.exec(ae), N = "";
      for (; V; ) {
        N += ae.substring(H, V.index);
        const L = ke.case_insensitive ? V[0].toLowerCase() : V[0], K = F(ee, L);
        if (K) {
          const [se, Oe] = K;
          if (P.addText(N), N = "", D[L] = (D[L] || 0) + 1, D[L] <= RS && (he += Oe), se.startsWith("_"))
            N += V[0];
          else {
            const dt = ke.classNameAliases[se] || se;
            P.addKeyword(V[0], dt);
          }
        } else
          N += V[0];
        H = ee.keywordPatternRe.lastIndex, V = ee.keywordPatternRe.exec(ae);
      }
      N += ae.substring(H), P.addText(N);
    }
    function ue() {
      if (ae === "")
        return;
      let H = null;
      if (typeof ee.subLanguage == "string") {
        if (!e[ee.subLanguage]) {
          P.addText(ae);
          return;
        }
        H = u(ee.subLanguage, ae, !0, Mt[ee.subLanguage]), Mt[ee.subLanguage] = /** @type {CompiledMode} */
        H._top;
      } else
        H = p(ae, ee.subLanguage.length ? ee.subLanguage : null);
      ee.relevance > 0 && (he += H.relevance), P.addSublanguage(H._emitter, H.language);
    }
    function ge() {
      ee.subLanguage != null ? ue() : Q(), ae = "";
    }
    function le(H, V) {
      let N = 1;
      const L = V.length - 1;
      for (; N <= L; ) {
        if (!H._emit[N]) {
          N++;
          continue;
        }
        const K = ke.classNameAliases[H[N]] || H[N], se = V[N];
        K ? P.addKeyword(se, K) : (ae = se, Q(), ae = ""), N++;
      }
    }
    function Ee(H, V) {
      return H.scope && typeof H.scope == "string" && P.openNode(ke.classNameAliases[H.scope] || H.scope), H.beginScope && (H.beginScope._wrap ? (P.addKeyword(ae, ke.classNameAliases[H.beginScope._wrap] || H.beginScope._wrap), ae = "") : H.beginScope._multi && (le(H.beginScope, V), ae = "")), ee = Object.create(H, { parent: { value: ee } }), ee;
    }
    function tt(H, V, N) {
      let L = Gx(H.endRe, N);
      if (L) {
        if (H["on:end"]) {
          const K = new Od(H);
          H["on:end"](V, K), K.isMatchIgnored && (L = !1);
        }
        if (L) {
          for (; H.endsParent && H.parent; )
            H = H.parent;
          return H;
        }
      }
      if (H.endsWithParent)
        return tt(H.parent, V, N);
    }
    function Pe(H) {
      return ee.matcher.regexIndex === 0 ? (ae += H[0], 1) : ($e = !0, 0);
    }
    function lt(H) {
      const V = H[0], N = H.rule, L = new Od(N), K = [N.__beforeBegin, N["on:begin"]];
      for (const se of K)
        if (se && (se(H, L), L.isMatchIgnored))
          return Pe(V);
      return N.skip ? ae += V : (N.excludeBegin && (ae += V), ge(), !N.returnBegin && !N.excludeBegin && (ae = V)), Ee(N, H), N.returnBegin ? 0 : V.length;
    }
    function nt(H) {
      const V = H[0], N = x.substring(H.index), L = tt(ee, H, N);
      if (!L)
        return Bd;
      const K = ee;
      ee.endScope && ee.endScope._wrap ? (ge(), P.addKeyword(V, ee.endScope._wrap)) : ee.endScope && ee.endScope._multi ? (ge(), le(ee.endScope, H)) : K.skip ? ae += V : (K.returnEnd || K.excludeEnd || (ae += V), ge(), K.excludeEnd && (ae = V));
      do
        ee.scope && P.closeNode(), !ee.skip && !ee.subLanguage && (he += ee.relevance), ee = ee.parent;
      while (ee !== L.parent);
      return L.starts && Ee(L.starts, H), K.returnEnd ? 0 : V.length;
    }
    function mt() {
      const H = [];
      for (let V = ee; V !== ke; V = V.parent)
        V.scope && H.unshift(V.scope);
      H.forEach((V) => P.openNode(V));
    }
    let ct = {};
    function ce(H, V) {
      const N = V && V[0];
      if (ae += H, N == null)
        return ge(), 0;
      if (ct.type === "begin" && V.type === "end" && ct.index === V.index && N === "") {
        if (ae += x.slice(V.index, V.index + 1), !i) {
          const L = new Error(`0 width match regex (${T})`);
          throw L.languageName = T, L.badRule = ct.rule, L;
        }
        return 1;
      }
      if (ct = V, V.type === "begin")
        return lt(V);
      if (V.type === "illegal" && !S) {
        const L = new Error('Illegal lexeme "' + N + '" for mode "' + (ee.scope || "<unnamed>") + '"');
        throw L.mode = ee, L;
      } else if (V.type === "end") {
        const L = nt(V);
        if (L !== Bd)
          return L;
      }
      if (V.type === "illegal" && N === "")
        return 1;
      if (Ue > 1e5 && Ue > V.index * 3)
        throw new Error("potential infinite loop, way more iterations than matches");
      return ae += N, N.length;
    }
    const ke = k(T);
    if (!ke)
      throw Bn(s.replace("{}", T)), new Error('Unknown language: "' + T + '"');
    const je = _S(ke);
    let Ne = "", ee = O || je;
    const Mt = {}, P = new a.__emitter(a);
    mt();
    let ae = "", he = 0, oe = 0, Ue = 0, $e = !1;
    try {
      for (ee.matcher.considerAll(); ; ) {
        Ue++, $e ? $e = !1 : ee.matcher.considerAll(), ee.matcher.lastIndex = oe;
        const H = ee.matcher.exec(x);
        if (!H)
          break;
        const V = x.substring(oe, H.index), N = ce(V, H);
        oe = H.index + N;
      }
      return ce(x.substring(oe)), P.closeAllNodes(), P.finalize(), Ne = P.toHTML(), {
        language: T,
        value: Ne,
        relevance: he,
        illegal: !1,
        _emitter: P,
        _top: ee
      };
    } catch (H) {
      if (H.message && H.message.includes("Illegal"))
        return {
          language: T,
          value: Po(x),
          illegal: !0,
          relevance: 0,
          _illegalBy: {
            message: H.message,
            index: oe,
            context: x.slice(oe - 100, oe + 100),
            mode: H.mode,
            resultSoFar: Ne
          },
          _emitter: P
        };
      if (i)
        return {
          language: T,
          value: Po(x),
          illegal: !1,
          relevance: 0,
          errorRaised: H,
          _emitter: P,
          _top: ee
        };
      throw H;
    }
  }
  function f(T) {
    const x = {
      value: Po(T),
      illegal: !1,
      relevance: 0,
      _top: o,
      _emitter: new a.__emitter(a)
    };
    return x._emitter.addText(T), x;
  }
  function p(T, x) {
    x = x || a.languages || Object.keys(e);
    const S = f(T), O = x.filter(k).filter(Z).map(
      (ge) => u(ge, T, !1)
    );
    O.unshift(S);
    const D = O.sort((ge, le) => {
      if (ge.relevance !== le.relevance)
        return le.relevance - ge.relevance;
      if (ge.language && le.language) {
        if (k(ge.language).supersetOf === le.language)
          return 1;
        if (k(le.language).supersetOf === ge.language)
          return -1;
      }
      return 0;
    }), [F, Q] = D, ue = F;
    return ue.secondBest = Q, ue;
  }
  function h(T, x, S) {
    const O = x && n[x] || S;
    T.classList.add("hljs"), T.classList.add(`language-${O}`);
  }
  function m(T) {
    let x = null;
    const S = c(T);
    if (l(S))
      return;
    if (X(
      "before:highlightElement",
      { el: T, language: S }
    ), T.children.length > 0 && (a.ignoreUnescapedHTML || (console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."), console.warn("https://github.com/highlightjs/highlight.js/wiki/security"), console.warn("The element with unescaped HTML:"), console.warn(T)), a.throwUnescapedHTML))
      throw new OS(
        "One of your code blocks includes unescaped HTML.",
        T.innerHTML
      );
    x = T;
    const O = x.textContent, D = S ? d(O, { language: S, ignoreIllegals: !0 }) : p(O);
    T.innerHTML = D.value, h(T, S, D.language), T.result = {
      language: D.language,
      // TODO: remove with version 11.0
      re: D.relevance,
      relevance: D.relevance
    }, D.secondBest && (T.secondBest = {
      language: D.secondBest.language,
      relevance: D.secondBest.relevance
    }), X("after:highlightElement", { el: T, result: D, text: O });
  }
  function g(T) {
    a = Hd(a, T);
  }
  const v = () => {
    b(), er("10.6.0", "initHighlighting() deprecated.  Use highlightAll() now.");
  };
  function y() {
    b(), er("10.6.0", "initHighlightingOnLoad() deprecated.  Use highlightAll() now.");
  }
  let E = !1;
  function b() {
    if (document.readyState === "loading") {
      E = !0;
      return;
    }
    document.querySelectorAll(a.cssSelector).forEach(m);
  }
  function C() {
    E && b();
  }
  typeof window < "u" && window.addEventListener && window.addEventListener("DOMContentLoaded", C, !1);
  function w(T, x) {
    let S = null;
    try {
      S = x(t);
    } catch (O) {
      if (Bn("Language definition for '{}' could not be registered.".replace("{}", T)), i)
        Bn(O);
      else
        throw O;
      S = o;
    }
    S.name || (S.name = T), e[T] = S, S.rawDefinition = x.bind(null, t), S.aliases && $(S.aliases, { languageName: T });
  }
  function _(T) {
    delete e[T];
    for (const x of Object.keys(n))
      n[x] === T && delete n[x];
  }
  function R() {
    return Object.keys(e);
  }
  function k(T) {
    return T = (T || "").toLowerCase(), e[T] || e[n[T]];
  }
  function $(T, { languageName: x }) {
    typeof T == "string" && (T = [T]), T.forEach((S) => {
      n[S.toLowerCase()] = x;
    });
  }
  function Z(T) {
    const x = k(T);
    return x && !x.disableAutodetect;
  }
  function j(T) {
    T["before:highlightBlock"] && !T["before:highlightElement"] && (T["before:highlightElement"] = (x) => {
      T["before:highlightBlock"](
        Object.assign({ block: x.el }, x)
      );
    }), T["after:highlightBlock"] && !T["after:highlightElement"] && (T["after:highlightElement"] = (x) => {
      T["after:highlightBlock"](
        Object.assign({ block: x.el }, x)
      );
    });
  }
  function J(T) {
    j(T), r.push(T);
  }
  function X(T, x) {
    const S = T;
    r.forEach(function(O) {
      O[S] && O[S](x);
    });
  }
  function re(T) {
    return er("10.7.0", "highlightBlock will be removed entirely in v12.0"), er("10.7.0", "Please use highlightElement now."), m(T);
  }
  Object.assign(t, {
    highlight: d,
    highlightAuto: p,
    highlightAll: b,
    highlightElement: m,
    // TODO: Remove with v12 API
    highlightBlock: re,
    configure: g,
    initHighlighting: v,
    initHighlightingOnLoad: y,
    registerLanguage: w,
    unregisterLanguage: _,
    listLanguages: R,
    getLanguage: k,
    registerAliases: $,
    autoDetection: Z,
    inherit: Hd,
    addPlugin: J
  }), t.debugMode = function() {
    i = !1;
  }, t.safeMode = function() {
    i = !0;
  }, t.versionString = AS, t.regex = {
    concat: qn,
    lookahead: xp,
    either: yl,
    optional: qx,
    anyNumberOfTimes: Wx
  };
  for (const T in Bi)
    typeof Bi[T] == "object" && gl.exports(Bi[T]);
  return Object.assign(t, Bi), t;
};
var pi = LS({}), IS = pi;
pi.HighlightJS = pi;
pi.default = pi;
var DS = IS;
function Op(t, e = []) {
  return t.map((n) => {
    const r = [...e, ...n.properties ? n.properties.className : []];
    return n.children ? Op(n.children, r) : {
      text: n.value,
      classes: r
    };
  }).flat();
}
function Pd(t) {
  return t.value || t.children || [];
}
function HS(t) {
  return !!DS.getLanguage(t);
}
function $d({ doc: t, name: e, lowlight: n, defaultLanguage: r }) {
  const i = [];
  return oa(t, (s) => s.type.name === e).forEach((s) => {
    let o = s.pos + 1;
    const a = s.node.attrs.language || r, l = n.listLanguages(), c = a && (l.includes(a) || HS(a)) ? Pd(n.highlight(a, s.node.textContent)) : Pd(n.highlightAuto(s.node.textContent));
    Op(c).forEach((d) => {
      const u = o + d.text.length;
      if (d.classes.length) {
        const f = Le.inline(o, u, {
          class: d.classes.join(" ")
        });
        i.push(f);
      }
      o = u;
    });
  }), we.create(t, i);
}
function BS(t) {
  return typeof t == "function";
}
function PS({ name: t, lowlight: e, defaultLanguage: n }) {
  if (!["highlight", "highlightAuto", "listLanguages"].every((i) => BS(e[i])))
    throw Error("You should provide an instance of lowlight to use the code-block-lowlight extension");
  const r = new Se({
    key: new Me("lowlight"),
    state: {
      init: (i, { doc: s }) => $d({
        doc: s,
        name: t,
        lowlight: e,
        defaultLanguage: n
      }),
      apply: (i, s, o, a) => {
        const l = o.selection.$head.parent.type.name, c = a.selection.$head.parent.type.name, d = oa(o.doc, (f) => f.type.name === t), u = oa(a.doc, (f) => f.type.name === t);
        return i.docChanged && ([l, c].includes(t) || u.length !== d.length || i.steps.some((f) => (
          // @ts-ignore
          f.from !== void 0 && f.to !== void 0 && d.some((p) => (
            // @ts-ignore
            p.pos >= f.from && p.pos + p.node.nodeSize <= f.to
          ))
        ))) ? $d({
          doc: i.doc,
          name: t,
          lowlight: e,
          defaultLanguage: n
        }) : s.map(i.mapping, i.doc);
      }
    },
    props: {
      decorations(i) {
        return r.getState(i);
      }
    }
  });
  return r;
}
const $S = Qf.extend({
  addOptions() {
    var t;
    return {
      ...(t = this.parent) === null || t === void 0 ? void 0 : t.call(this),
      lowlight: {},
      defaultLanguage: null
    };
  },
  addProseMirrorPlugins() {
    var t;
    return [
      ...((t = this.parent) === null || t === void 0 ? void 0 : t.call(this)) || [],
      PS({
        name: this.name,
        lowlight: this.options.lowlight,
        defaultLanguage: this.options.defaultLanguage
      })
    ];
  }
});
function Vd(t, e, n = {}) {
  const { empty: r, ranges: i, from: s, to: o } = t.selection, a = e ? Jt(e, t.schema) : null;
  if (r)
    return !!(t.storedMarks || t.selection.$from.marks()).filter((m) => a ? a.name === m.type.name : !0).find(
      (m) => xr(m.attrs, n, { strict: !1 })
    );
  let l = s, c = o;
  const d = [];
  i.forEach(({ $from: m, $to: g }) => {
    const v = m.pos, y = g.pos;
    l = Math.min(l, v), c = Math.max(l, y), t.doc.nodesBetween(v, y, (E, b) => {
      if (!E.isText && !E.marks.length)
        return;
      const C = Math.max(v, b), w = Math.min(y, b + E.nodeSize);
      d.push(
        ...E.marks.map((_) => ({
          mark: _,
          from: C,
          to: w
        }))
      );
    });
  });
  const u = c - l;
  if (u === 0)
    return !1;
  const f = d.filter((m) => a ? a.name === m.mark.type.name : !0).filter(
    (m) => xr(m.mark.attrs, n, { strict: !1 })
  ).reduce((m, g) => m + g.to - g.from, 0), p = d.filter((m) => a ? m.mark.type !== a && m.mark.type.excludes(a) : !0).reduce((m, g) => m + g.to - g.from, 0);
  return (f > 0 ? f + p : f) >= u;
}
function zd(t) {
  var e;
  return !!((e = t.spec.group) != null && e.split(" ").includes("list"));
}
function Fd(t, e, n = {}) {
  if (!e)
    return Fn(t, null, n) || Vd(t, null, n);
  const r = t.schema.nodes[e];
  if (r) {
    if (zd(r)) {
      const s = Ws((o) => zd(o.type))(
        t.selection
      );
      return !!(s && s.node.type.name === e);
    }
    return Fn(t, e, n);
  }
  return t.schema.marks[e] ? Vd(t, e, n) : !1;
}
function Ud(t) {
  return new yi({
    find: t.find,
    handler: ({ state: e, range: n, match: r, commands: i }) => {
      const s = e.doc.resolve(n.from), o = ie(t.getAttributes, void 0, r) || {};
      if (!s.node(-1).canReplaceWith(s.index(-1), s.indexAfter(-1), t.type))
        return null;
      e.tr.delete(n.from, n.to).setBlockType(n.from, n.from, t.type, o), setTimeout(() => i.focus(!0), 0);
    }
  });
}
const Rp = [
  { name: "Plain Text", value: "plaintext", alias: ["text", "txt"] },
  { name: "Bash", value: "bash", alias: ["sh"] },
  { name: "BASIC", value: "basic", alias: [] },
  { name: "C", value: "c", alias: ["h"] },
  { name: "Clojure", value: "clojure", alias: ["clj", "edn"] },
  { name: "CMake", value: "cmake", alias: ["cmake.in"] },
  {
    name: "CoffeeScript",
    value: "coffeescript",
    alias: ["coffee", "cson", "iced"]
  },
  {
    name: "C++",
    value: "cpp",
    alias: ["cc", "c++", "h++", "hpp", "hh", "hxx", "cxx"]
  },
  { name: "C#", value: "csharp", alias: ["cs", "c#"] },
  { name: "CSS", value: "css", alias: [] },
  { name: "Dart", value: "dart", alias: [] },
  { name: "Delphi", value: "delphi", alias: ["dpr", "dfm", "pas", "pascal"] },
  { name: "Dockerfile", value: "dockerfile", alias: ["docker"] },
  { name: "Erlang", value: "erlang", alias: ["erl"] },
  { name: "Go", value: "go", alias: ["golang"] },
  { name: "GraphQL", value: "graphql", alias: ["gql"] },
  { name: "Groovy", value: "groovy", alias: [] },
  { name: "Java", value: "java", alias: ["jsp"] },
  {
    name: "JavaScript",
    value: "javascript",
    alias: ["js", "jsx", "mjs", "cjs"]
  },
  { name: "JSON", value: "json", alias: [] },
  { name: "Kotlin", value: "kotlin", alias: ["kt", "kts"] },
  { name: "Lua", value: "lua", alias: [] },
  { name: "Makefile", value: "makefile", alias: ["mk", "mak", "make"] },
  { name: "Markdown", value: "markdown", alias: ["md", "mkdown", "mkd"] },
  { name: "Matlab", value: "matlab", alias: [] },
  {
    name: "Objective-C",
    value: "objectivec",
    alias: ["mm", "objc", "obj-c", "obj-c++", "objective-c++"]
  },
  { name: "PHP", value: "php", alias: [] },
  { name: "Properties", value: "properties", alias: [] },
  { name: "Python", value: "python", alias: ["py", "gyp", "ipython"] },
  {
    name: "Ruby",
    value: "ruby",
    alias: ["rb", "gemspec", "podspec", "thor", "irb"]
  },
  { name: "Rust", value: "rust", alias: ["rs"] },
  { name: "Scala", value: "scala", alias: [] },
  { name: "SCSS", value: "scss", alias: [] },
  { name: "Shell", value: "shell", alias: ["console", "shellsession"] },
  { name: "SQL", value: "sql", alias: [] },
  { name: "Swift", value: "swift", alias: [] },
  { name: "TypeScript", value: "typescript", alias: ["ts", "tsx"] },
  { name: "WebAssembly", value: "wasm", alias: [] },
  {
    name: "HTML, XML",
    value: "xml",
    alias: [
      "html",
      "xhtml",
      "rss",
      "atom",
      "xjb",
      "xsd",
      "xsl",
      "plist",
      "wsf",
      "svg"
    ]
  },
  { name: "YAML", value: "yaml", alias: ["yml"] }
], Kd = (t) => {
  if (!t)
    return null;
  const e = t.toLocaleLowerCase();
  return Rp.find(
    (r) => r.value === e || r.alias && r.alias.includes(e)
  );
};
function VS(t, e) {
  const { $from: n, from: r, to: i } = t, a = (e.textContent || "").split(`
`).reduce((p, h, m) => (p[m] = (p[m - 1] || 0) + h.length + (m === 0 ? 0 : 1), p), {}), l = n.parentOffset, c = n.parentOffset + i - r, d = Object.keys(a), u = d.find(
    (p) => a[p] >= l
  ), f = d.find(
    (p) => a[p] >= c
  );
  return {
    start: u,
    end: f
  };
}
const zS = /^[`·]{3}([a-z]+)?[\s\n]$/, FS = /^[~～]{3}([a-z]+)?[\s\n]$/, US = $S.extend({
  addOptions() {
    var t;
    return {
      ...(t = this.parent) == null ? void 0 : t.call(this),
      lowlight: {},
      defaultLanguage: null,
      languages: Rp
    };
  },
  addCommands() {
    var t;
    return {
      ...(t = this.parent) == null ? void 0 : t.call(this),
      toggleCodeBlock: (e) => ({ commands: n, editor: r, chain: i }) => {
        const { state: s } = r, { from: o, to: a } = s.selection;
        if (!Fd(s, this.name) && !s.selection.empty) {
          let l = !0;
          const c = [];
          if (s.doc.nodesBetween(o, a, (d, u) => {
            if (d.isInline)
              return !1;
            if (d.type.name !== "paragraph")
              return u + 1 <= o && u + d.nodeSize - 1 >= a ? void 0 : (l = !1, !1);
            {
              const f = (d.textContent || "").slice(
                u + 1 > o ? 0 : o - u - 1,
                u + d.nodeSize - 1 < a ? d.nodeSize - 1 : a - u - 1
              );
              c.push(f || "");
            }
          }), l && c.length > 1)
            return i().command(({ state: d, tr: u }) => (u.replaceRangeWith(
              o,
              a,
              this.type.create(
                e,
                d.schema.text(c.join(`
`))
              )
            ), !0)).setTextSelection({
              from: o + 2,
              to: o + 2
            }).run();
        }
        return n.toggleNode(this.name, "paragraph", e);
      }
    };
  },
  addKeyboardShortcuts() {
    var t;
    return {
      ...(t = this.parent) == null ? void 0 : t.call(this),
      Tab: ({ editor: e }) => {
        const { state: n, view: r } = e;
        if (!Fd(n, this.name))
          return !1;
        const { selection: i, tr: s } = n, o = "  ";
        if (i.empty)
          r.dispatch(s.insertText(o));
        else {
          const { $from: a, from: l, to: c } = i, d = a.node();
          if (d.type !== this.type)
            return !1;
          const { start: u, end: f } = VS(i, d);
          if (u === void 0 || f === void 0)
            return r.dispatch(s.replaceSelectionWith(n.schema.text(o))), !0;
          const m = (d.textContent || "").split(`
`).map((y, E) => E >= u && E <= f && y ? o + y : y), g = a.node(1), v = a.start(1);
          s.replaceWith(
            v,
            v + g.nodeSize - 2,
            n.schema.text(m.join(`
`))
          ), s.setSelection(
            G.between(
              s.doc.resolve(l + o.length),
              s.doc.resolve(
                c + (f - u + 1) * o.length
              )
            )
          ), r.dispatch(s);
        }
        return !0;
      }
    };
  },
  addInputRules() {
    return [
      Ud({
        find: zS,
        type: this.type,
        getAttributes: (t) => {
          var e;
          return {
            language: ((e = Kd(t[1])) == null ? void 0 : e.value) || this.options.defaultLanguage
          };
        }
      }),
      Ud({
        find: FS,
        type: this.type,
        getAttributes: (t) => {
          var e;
          return {
            language: ((e = Kd(t[1])) == null ? void 0 : e.value) || this.options.defaultLanguage
          };
        }
      })
    ];
  },
  addNodeView() {
    return (t) => {
      const e = document.createElement("div");
      e.classList.add("aie-codeblock-wrapper");
      const { language: n } = t.node.attrs;
      e.innerHTML = `
                <div class="aie-codeblock-tools" contenteditable="false">
                    <div class="aie-codeblock-tools-lang" contenteditable="false"><span>${n || this.options.defaultLanguage}</span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 16L6 10H18L12 16Z"></path></svg></div>
                </div>
                <pre class="hljs"><code></code></pre>
                `;
      const r = () => {
        const s = document.createElement("div");
        return s.classList.add("aie-codeblock-langs"), s.innerHTML = `
                ${this.options.languages.map((o) => `<div class="aie-codeblock-langs-item" data-item="${o.value}">${o.name}</div>`).join("")}`, s.addEventListener("click", (o) => {
          const a = o.target.closest(".aie-codeblock-langs-item");
          if (a) {
            const l = a.getAttribute("data-item");
            t.editor.chain().setCodeBlock({ language: l }).run();
          }
        }), s;
      }, i = ht(e.querySelector(".aie-codeblock-tools-lang"), {
        content: r(),
        appendTo: t.editor.view.dom.closest(".aie-container"),
        placement: "bottom-end",
        trigger: "click",
        interactive: !0,
        arrow: !1,
        aria: {
          content: null,
          expanded: !1
        }
      });
      return console.log("addNodeView init"), {
        dom: e,
        contentDOM: e.querySelector("code"),
        destroy: () => {
          console.log("addNodeView destroy"), i.destroy();
        }
      };
    };
  }
});
function KS(t) {
  const e = t.regex, n = t.COMMENT("//", "$", { contains: [{ begin: /\\\n/ }] }), r = "decltype\\(auto\\)", i = "[a-zA-Z_]\\w*::", s = "<[^<>]+>", o = "(?!struct)(" + r + "|" + e.optional(i) + "[a-zA-Z_]\\w*" + e.optional(s) + ")", a = {
    className: "type",
    begin: "\\b[a-z\\d_]*_t\\b"
  }, l = "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)", c = {
    className: "string",
    variants: [
      {
        begin: '(u8?|U|L)?"',
        end: '"',
        illegal: "\\n",
        contains: [t.BACKSLASH_ESCAPE]
      },
      {
        begin: "(u8?|U|L)?'(" + l + "|.)",
        end: "'",
        illegal: "."
      },
      t.END_SAME_AS_BEGIN({
        begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
        end: /\)([^()\\ ]{0,16})"/
      })
    ]
  }, d = {
    className: "number",
    variants: [
      { begin: "\\b(0b[01']+)" },
      { begin: "(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)" },
      { begin: "(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)" }
    ],
    relevance: 0
  }, u = {
    className: "meta",
    begin: /#\s*[a-z]+\b/,
    end: /$/,
    keywords: { keyword: "if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include" },
    contains: [
      {
        begin: /\\\n/,
        relevance: 0
      },
      t.inherit(c, { className: "string" }),
      {
        className: "string",
        begin: /<.*?>/
      },
      n,
      t.C_BLOCK_COMMENT_MODE
    ]
  }, f = {
    className: "title",
    begin: e.optional(i) + t.IDENT_RE,
    relevance: 0
  }, p = e.optional(i) + t.IDENT_RE + "\\s*\\(", h = [
    "alignas",
    "alignof",
    "and",
    "and_eq",
    "asm",
    "atomic_cancel",
    "atomic_commit",
    "atomic_noexcept",
    "auto",
    "bitand",
    "bitor",
    "break",
    "case",
    "catch",
    "class",
    "co_await",
    "co_return",
    "co_yield",
    "compl",
    "concept",
    "const_cast|10",
    "consteval",
    "constexpr",
    "constinit",
    "continue",
    "decltype",
    "default",
    "delete",
    "do",
    "dynamic_cast|10",
    "else",
    "enum",
    "explicit",
    "export",
    "extern",
    "false",
    "final",
    "for",
    "friend",
    "goto",
    "if",
    "import",
    "inline",
    "module",
    "mutable",
    "namespace",
    "new",
    "noexcept",
    "not",
    "not_eq",
    "nullptr",
    "operator",
    "or",
    "or_eq",
    "override",
    "private",
    "protected",
    "public",
    "reflexpr",
    "register",
    "reinterpret_cast|10",
    "requires",
    "return",
    "sizeof",
    "static_assert",
    "static_cast|10",
    "struct",
    "switch",
    "synchronized",
    "template",
    "this",
    "thread_local",
    "throw",
    "transaction_safe",
    "transaction_safe_dynamic",
    "true",
    "try",
    "typedef",
    "typeid",
    "typename",
    "union",
    "using",
    "virtual",
    "volatile",
    "while",
    "xor",
    "xor_eq"
  ], m = [
    "bool",
    "char",
    "char16_t",
    "char32_t",
    "char8_t",
    "double",
    "float",
    "int",
    "long",
    "short",
    "void",
    "wchar_t",
    "unsigned",
    "signed",
    "const",
    "static"
  ], g = [
    "any",
    "auto_ptr",
    "barrier",
    "binary_semaphore",
    "bitset",
    "complex",
    "condition_variable",
    "condition_variable_any",
    "counting_semaphore",
    "deque",
    "false_type",
    "future",
    "imaginary",
    "initializer_list",
    "istringstream",
    "jthread",
    "latch",
    "lock_guard",
    "multimap",
    "multiset",
    "mutex",
    "optional",
    "ostringstream",
    "packaged_task",
    "pair",
    "promise",
    "priority_queue",
    "queue",
    "recursive_mutex",
    "recursive_timed_mutex",
    "scoped_lock",
    "set",
    "shared_future",
    "shared_lock",
    "shared_mutex",
    "shared_timed_mutex",
    "shared_ptr",
    "stack",
    "string_view",
    "stringstream",
    "timed_mutex",
    "thread",
    "true_type",
    "tuple",
    "unique_lock",
    "unique_ptr",
    "unordered_map",
    "unordered_multimap",
    "unordered_multiset",
    "unordered_set",
    "variant",
    "vector",
    "weak_ptr",
    "wstring",
    "wstring_view"
  ], v = [
    "abort",
    "abs",
    "acos",
    "apply",
    "as_const",
    "asin",
    "atan",
    "atan2",
    "calloc",
    "ceil",
    "cerr",
    "cin",
    "clog",
    "cos",
    "cosh",
    "cout",
    "declval",
    "endl",
    "exchange",
    "exit",
    "exp",
    "fabs",
    "floor",
    "fmod",
    "forward",
    "fprintf",
    "fputs",
    "free",
    "frexp",
    "fscanf",
    "future",
    "invoke",
    "isalnum",
    "isalpha",
    "iscntrl",
    "isdigit",
    "isgraph",
    "islower",
    "isprint",
    "ispunct",
    "isspace",
    "isupper",
    "isxdigit",
    "labs",
    "launder",
    "ldexp",
    "log",
    "log10",
    "make_pair",
    "make_shared",
    "make_shared_for_overwrite",
    "make_tuple",
    "make_unique",
    "malloc",
    "memchr",
    "memcmp",
    "memcpy",
    "memset",
    "modf",
    "move",
    "pow",
    "printf",
    "putchar",
    "puts",
    "realloc",
    "scanf",
    "sin",
    "sinh",
    "snprintf",
    "sprintf",
    "sqrt",
    "sscanf",
    "std",
    "stderr",
    "stdin",
    "stdout",
    "strcat",
    "strchr",
    "strcmp",
    "strcpy",
    "strcspn",
    "strlen",
    "strncat",
    "strncmp",
    "strncpy",
    "strpbrk",
    "strrchr",
    "strspn",
    "strstr",
    "swap",
    "tan",
    "tanh",
    "terminate",
    "to_underlying",
    "tolower",
    "toupper",
    "vfprintf",
    "visit",
    "vprintf",
    "vsprintf"
  ], b = {
    type: m,
    keyword: h,
    literal: [
      "NULL",
      "false",
      "nullopt",
      "nullptr",
      "true"
    ],
    built_in: ["_Pragma"],
    _type_hints: g
  }, C = {
    className: "function.dispatch",
    relevance: 0,
    keywords: {
      // Only for relevance, not highlighting.
      _hint: v
    },
    begin: e.concat(
      /\b/,
      /(?!decltype)/,
      /(?!if)/,
      /(?!for)/,
      /(?!switch)/,
      /(?!while)/,
      t.IDENT_RE,
      e.lookahead(/(<[^<>]+>|)\s*\(/)
    )
  }, w = [
    C,
    u,
    a,
    n,
    t.C_BLOCK_COMMENT_MODE,
    d,
    c
  ], _ = {
    // This mode covers expression context where we can't expect a function
    // definition and shouldn't highlight anything that looks like one:
    // `return some()`, `else if()`, `(x*sum(1, 2))`
    variants: [
      {
        begin: /=/,
        end: /;/
      },
      {
        begin: /\(/,
        end: /\)/
      },
      {
        beginKeywords: "new throw return else",
        end: /;/
      }
    ],
    keywords: b,
    contains: w.concat([
      {
        begin: /\(/,
        end: /\)/,
        keywords: b,
        contains: w.concat(["self"]),
        relevance: 0
      }
    ]),
    relevance: 0
  }, R = {
    className: "function",
    begin: "(" + o + "[\\*&\\s]+)+" + p,
    returnBegin: !0,
    end: /[{;=]/,
    excludeEnd: !0,
    keywords: b,
    illegal: /[^\w\s\*&:<>.]/,
    contains: [
      {
        // to prevent it from being confused as the function title
        begin: r,
        keywords: b,
        relevance: 0
      },
      {
        begin: p,
        returnBegin: !0,
        contains: [f],
        relevance: 0
      },
      // needed because we do not have look-behind on the below rule
      // to prevent it from grabbing the final : in a :: pair
      {
        begin: /::/,
        relevance: 0
      },
      // initializers
      {
        begin: /:/,
        endsWithParent: !0,
        contains: [
          c,
          d
        ]
      },
      // allow for multiple declarations, e.g.:
      // extern void f(int), g(char);
      {
        relevance: 0,
        match: /,/
      },
      {
        className: "params",
        begin: /\(/,
        end: /\)/,
        keywords: b,
        relevance: 0,
        contains: [
          n,
          t.C_BLOCK_COMMENT_MODE,
          c,
          d,
          a,
          // Count matching parentheses.
          {
            begin: /\(/,
            end: /\)/,
            keywords: b,
            relevance: 0,
            contains: [
              "self",
              n,
              t.C_BLOCK_COMMENT_MODE,
              c,
              d,
              a
            ]
          }
        ]
      },
      a,
      n,
      t.C_BLOCK_COMMENT_MODE,
      u
    ]
  };
  return {
    name: "C++",
    aliases: [
      "cc",
      "c++",
      "h++",
      "hpp",
      "hh",
      "hxx",
      "cxx"
    ],
    keywords: b,
    illegal: "</",
    classNameAliases: { "function.dispatch": "built_in" },
    contains: [].concat(
      _,
      R,
      C,
      w,
      [
        u,
        {
          // containers: ie, `vector <int> rooms (9);`
          begin: "\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function)\\s*<(?!<)",
          end: ">",
          keywords: b,
          contains: [
            "self",
            a
          ]
        },
        {
          begin: t.IDENT_RE + "::",
          keywords: b
        },
        {
          match: [
            // extra complexity to deal with `enum class` and `enum struct`
            /\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,
            /\s+/,
            /\w+/
          ],
          className: {
            1: "keyword",
            3: "title.class"
          }
        }
      ]
    )
  };
}
function WS(t) {
  const e = {
    type: [
      "boolean",
      "byte",
      "word",
      "String"
    ],
    built_in: [
      "KeyboardController",
      "MouseController",
      "SoftwareSerial",
      "EthernetServer",
      "EthernetClient",
      "LiquidCrystal",
      "RobotControl",
      "GSMVoiceCall",
      "EthernetUDP",
      "EsploraTFT",
      "HttpClient",
      "RobotMotor",
      "WiFiClient",
      "GSMScanner",
      "FileSystem",
      "Scheduler",
      "GSMServer",
      "YunClient",
      "YunServer",
      "IPAddress",
      "GSMClient",
      "GSMModem",
      "Keyboard",
      "Ethernet",
      "Console",
      "GSMBand",
      "Esplora",
      "Stepper",
      "Process",
      "WiFiUDP",
      "GSM_SMS",
      "Mailbox",
      "USBHost",
      "Firmata",
      "PImage",
      "Client",
      "Server",
      "GSMPIN",
      "FileIO",
      "Bridge",
      "Serial",
      "EEPROM",
      "Stream",
      "Mouse",
      "Audio",
      "Servo",
      "File",
      "Task",
      "GPRS",
      "WiFi",
      "Wire",
      "TFT",
      "GSM",
      "SPI",
      "SD"
    ],
    _hints: [
      "setup",
      "loop",
      "runShellCommandAsynchronously",
      "analogWriteResolution",
      "retrieveCallingNumber",
      "printFirmwareVersion",
      "analogReadResolution",
      "sendDigitalPortPair",
      "noListenOnLocalhost",
      "readJoystickButton",
      "setFirmwareVersion",
      "readJoystickSwitch",
      "scrollDisplayRight",
      "getVoiceCallStatus",
      "scrollDisplayLeft",
      "writeMicroseconds",
      "delayMicroseconds",
      "beginTransmission",
      "getSignalStrength",
      "runAsynchronously",
      "getAsynchronously",
      "listenOnLocalhost",
      "getCurrentCarrier",
      "readAccelerometer",
      "messageAvailable",
      "sendDigitalPorts",
      "lineFollowConfig",
      "countryNameWrite",
      "runShellCommand",
      "readStringUntil",
      "rewindDirectory",
      "readTemperature",
      "setClockDivider",
      "readLightSensor",
      "endTransmission",
      "analogReference",
      "detachInterrupt",
      "countryNameRead",
      "attachInterrupt",
      "encryptionType",
      "readBytesUntil",
      "robotNameWrite",
      "readMicrophone",
      "robotNameRead",
      "cityNameWrite",
      "userNameWrite",
      "readJoystickY",
      "readJoystickX",
      "mouseReleased",
      "openNextFile",
      "scanNetworks",
      "noInterrupts",
      "digitalWrite",
      "beginSpeaker",
      "mousePressed",
      "isActionDone",
      "mouseDragged",
      "displayLogos",
      "noAutoscroll",
      "addParameter",
      "remoteNumber",
      "getModifiers",
      "keyboardRead",
      "userNameRead",
      "waitContinue",
      "processInput",
      "parseCommand",
      "printVersion",
      "readNetworks",
      "writeMessage",
      "blinkVersion",
      "cityNameRead",
      "readMessage",
      "setDataMode",
      "parsePacket",
      "isListening",
      "setBitOrder",
      "beginPacket",
      "isDirectory",
      "motorsWrite",
      "drawCompass",
      "digitalRead",
      "clearScreen",
      "serialEvent",
      "rightToLeft",
      "setTextSize",
      "leftToRight",
      "requestFrom",
      "keyReleased",
      "compassRead",
      "analogWrite",
      "interrupts",
      "WiFiServer",
      "disconnect",
      "playMelody",
      "parseFloat",
      "autoscroll",
      "getPINUsed",
      "setPINUsed",
      "setTimeout",
      "sendAnalog",
      "readSlider",
      "analogRead",
      "beginWrite",
      "createChar",
      "motorsStop",
      "keyPressed",
      "tempoWrite",
      "readButton",
      "subnetMask",
      "debugPrint",
      "macAddress",
      "writeGreen",
      "randomSeed",
      "attachGPRS",
      "readString",
      "sendString",
      "remotePort",
      "releaseAll",
      "mouseMoved",
      "background",
      "getXChange",
      "getYChange",
      "answerCall",
      "getResult",
      "voiceCall",
      "endPacket",
      "constrain",
      "getSocket",
      "writeJSON",
      "getButton",
      "available",
      "connected",
      "findUntil",
      "readBytes",
      "exitValue",
      "readGreen",
      "writeBlue",
      "startLoop",
      "IPAddress",
      "isPressed",
      "sendSysex",
      "pauseMode",
      "gatewayIP",
      "setCursor",
      "getOemKey",
      "tuneWrite",
      "noDisplay",
      "loadImage",
      "switchPIN",
      "onRequest",
      "onReceive",
      "changePIN",
      "playFile",
      "noBuffer",
      "parseInt",
      "overflow",
      "checkPIN",
      "knobRead",
      "beginTFT",
      "bitClear",
      "updateIR",
      "bitWrite",
      "position",
      "writeRGB",
      "highByte",
      "writeRed",
      "setSpeed",
      "readBlue",
      "noStroke",
      "remoteIP",
      "transfer",
      "shutdown",
      "hangCall",
      "beginSMS",
      "endWrite",
      "attached",
      "maintain",
      "noCursor",
      "checkReg",
      "checkPUK",
      "shiftOut",
      "isValid",
      "shiftIn",
      "pulseIn",
      "connect",
      "println",
      "localIP",
      "pinMode",
      "getIMEI",
      "display",
      "noBlink",
      "process",
      "getBand",
      "running",
      "beginSD",
      "drawBMP",
      "lowByte",
      "setBand",
      "release",
      "bitRead",
      "prepare",
      "pointTo",
      "readRed",
      "setMode",
      "noFill",
      "remove",
      "listen",
      "stroke",
      "detach",
      "attach",
      "noTone",
      "exists",
      "buffer",
      "height",
      "bitSet",
      "circle",
      "config",
      "cursor",
      "random",
      "IRread",
      "setDNS",
      "endSMS",
      "getKey",
      "micros",
      "millis",
      "begin",
      "print",
      "write",
      "ready",
      "flush",
      "width",
      "isPIN",
      "blink",
      "clear",
      "press",
      "mkdir",
      "rmdir",
      "close",
      "point",
      "yield",
      "image",
      "BSSID",
      "click",
      "delay",
      "read",
      "text",
      "move",
      "peek",
      "beep",
      "rect",
      "line",
      "open",
      "seek",
      "fill",
      "size",
      "turn",
      "stop",
      "home",
      "find",
      "step",
      "tone",
      "sqrt",
      "RSSI",
      "SSID",
      "end",
      "bit",
      "tan",
      "cos",
      "sin",
      "pow",
      "map",
      "abs",
      "max",
      "min",
      "get",
      "run",
      "put"
    ],
    literal: [
      "DIGITAL_MESSAGE",
      "FIRMATA_STRING",
      "ANALOG_MESSAGE",
      "REPORT_DIGITAL",
      "REPORT_ANALOG",
      "INPUT_PULLUP",
      "SET_PIN_MODE",
      "INTERNAL2V56",
      "SYSTEM_RESET",
      "LED_BUILTIN",
      "INTERNAL1V1",
      "SYSEX_START",
      "INTERNAL",
      "EXTERNAL",
      "DEFAULT",
      "OUTPUT",
      "INPUT",
      "HIGH",
      "LOW"
    ]
  }, n = KS(t), r = (
    /** @type {Record<string,any>} */
    n.keywords
  );
  return r.type = [
    ...r.type,
    ...e.type
  ], r.literal = [
    ...r.literal,
    ...e.literal
  ], r.built_in = [
    ...r.built_in,
    ...e.built_in
  ], r._hints = e._hints, n.name = "Arduino", n.aliases = ["ino"], n.supersetOf = "cpp", n;
}
function qS(t) {
  const e = t.regex, n = {}, r = {
    begin: /\$\{/,
    end: /\}/,
    contains: [
      "self",
      {
        begin: /:-/,
        contains: [n]
      }
      // default values
    ]
  };
  Object.assign(n, {
    className: "variable",
    variants: [
      { begin: e.concat(
        /\$[\w\d#@][\w\d_]*/,
        // negative look-ahead tries to avoid matching patterns that are not
        // Perl at all like $ident$, @ident@, etc.
        "(?![\\w\\d])(?![$])"
      ) },
      r
    ]
  });
  const i = {
    className: "subst",
    begin: /\$\(/,
    end: /\)/,
    contains: [t.BACKSLASH_ESCAPE]
  }, s = {
    begin: /<<-?\s*(?=\w+)/,
    starts: { contains: [
      t.END_SAME_AS_BEGIN({
        begin: /(\w+)/,
        end: /(\w+)/,
        className: "string"
      })
    ] }
  }, o = {
    className: "string",
    begin: /"/,
    end: /"/,
    contains: [
      t.BACKSLASH_ESCAPE,
      n,
      i
    ]
  };
  i.contains.push(o);
  const a = {
    match: /\\"/
  }, l = {
    className: "string",
    begin: /'/,
    end: /'/
  }, c = {
    match: /\\'/
  }, d = {
    begin: /\$?\(\(/,
    end: /\)\)/,
    contains: [
      {
        begin: /\d+#[0-9a-f]+/,
        className: "number"
      },
      t.NUMBER_MODE,
      n
    ]
  }, u = [
    "fish",
    "bash",
    "zsh",
    "sh",
    "csh",
    "ksh",
    "tcsh",
    "dash",
    "scsh"
  ], f = t.SHEBANG({
    binary: `(${u.join("|")})`,
    relevance: 10
  }), p = {
    className: "function",
    begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/,
    returnBegin: !0,
    contains: [t.inherit(t.TITLE_MODE, { begin: /\w[\w\d_]*/ })],
    relevance: 0
  }, h = [
    "if",
    "then",
    "else",
    "elif",
    "fi",
    "for",
    "while",
    "until",
    "in",
    "do",
    "done",
    "case",
    "esac",
    "function",
    "select"
  ], m = [
    "true",
    "false"
  ], g = { match: /(\/[a-z._-]+)+/ }, v = [
    "break",
    "cd",
    "continue",
    "eval",
    "exec",
    "exit",
    "export",
    "getopts",
    "hash",
    "pwd",
    "readonly",
    "return",
    "shift",
    "test",
    "times",
    "trap",
    "umask",
    "unset"
  ], y = [
    "alias",
    "bind",
    "builtin",
    "caller",
    "command",
    "declare",
    "echo",
    "enable",
    "help",
    "let",
    "local",
    "logout",
    "mapfile",
    "printf",
    "read",
    "readarray",
    "source",
    "type",
    "typeset",
    "ulimit",
    "unalias"
  ], E = [
    "autoload",
    "bg",
    "bindkey",
    "bye",
    "cap",
    "chdir",
    "clone",
    "comparguments",
    "compcall",
    "compctl",
    "compdescribe",
    "compfiles",
    "compgroups",
    "compquote",
    "comptags",
    "comptry",
    "compvalues",
    "dirs",
    "disable",
    "disown",
    "echotc",
    "echoti",
    "emulate",
    "fc",
    "fg",
    "float",
    "functions",
    "getcap",
    "getln",
    "history",
    "integer",
    "jobs",
    "kill",
    "limit",
    "log",
    "noglob",
    "popd",
    "print",
    "pushd",
    "pushln",
    "rehash",
    "sched",
    "setcap",
    "setopt",
    "stat",
    "suspend",
    "ttyctl",
    "unfunction",
    "unhash",
    "unlimit",
    "unsetopt",
    "vared",
    "wait",
    "whence",
    "where",
    "which",
    "zcompile",
    "zformat",
    "zftp",
    "zle",
    "zmodload",
    "zparseopts",
    "zprof",
    "zpty",
    "zregexparse",
    "zsocket",
    "zstyle",
    "ztcp"
  ], b = [
    "chcon",
    "chgrp",
    "chown",
    "chmod",
    "cp",
    "dd",
    "df",
    "dir",
    "dircolors",
    "ln",
    "ls",
    "mkdir",
    "mkfifo",
    "mknod",
    "mktemp",
    "mv",
    "realpath",
    "rm",
    "rmdir",
    "shred",
    "sync",
    "touch",
    "truncate",
    "vdir",
    "b2sum",
    "base32",
    "base64",
    "cat",
    "cksum",
    "comm",
    "csplit",
    "cut",
    "expand",
    "fmt",
    "fold",
    "head",
    "join",
    "md5sum",
    "nl",
    "numfmt",
    "od",
    "paste",
    "ptx",
    "pr",
    "sha1sum",
    "sha224sum",
    "sha256sum",
    "sha384sum",
    "sha512sum",
    "shuf",
    "sort",
    "split",
    "sum",
    "tac",
    "tail",
    "tr",
    "tsort",
    "unexpand",
    "uniq",
    "wc",
    "arch",
    "basename",
    "chroot",
    "date",
    "dirname",
    "du",
    "echo",
    "env",
    "expr",
    "factor",
    // "false", // keyword literal already
    "groups",
    "hostid",
    "id",
    "link",
    "logname",
    "nice",
    "nohup",
    "nproc",
    "pathchk",
    "pinky",
    "printenv",
    "printf",
    "pwd",
    "readlink",
    "runcon",
    "seq",
    "sleep",
    "stat",
    "stdbuf",
    "stty",
    "tee",
    "test",
    "timeout",
    // "true", // keyword literal already
    "tty",
    "uname",
    "unlink",
    "uptime",
    "users",
    "who",
    "whoami",
    "yes"
  ];
  return {
    name: "Bash",
    aliases: ["sh"],
    keywords: {
      $pattern: /\b[a-z][a-z0-9._-]+\b/,
      keyword: h,
      literal: m,
      built_in: [
        ...v,
        ...y,
        // Shell modifiers
        "set",
        "shopt",
        ...E,
        ...b
      ]
    },
    contains: [
      f,
      // to catch known shells and boost relevancy
      t.SHEBANG(),
      // to catch unknown shells but still highlight the shebang
      p,
      d,
      t.HASH_COMMENT_MODE,
      s,
      g,
      o,
      a,
      l,
      c,
      n
    ]
  };
}
function ZS(t) {
  const e = t.regex, n = t.COMMENT("//", "$", { contains: [{ begin: /\\\n/ }] }), r = "decltype\\(auto\\)", i = "[a-zA-Z_]\\w*::", s = "<[^<>]+>", o = "(" + r + "|" + e.optional(i) + "[a-zA-Z_]\\w*" + e.optional(s) + ")", a = {
    className: "type",
    variants: [
      { begin: "\\b[a-z\\d_]*_t\\b" },
      { match: /\batomic_[a-z]{3,6}\b/ }
    ]
  }, l = "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)", c = {
    className: "string",
    variants: [
      {
        begin: '(u8?|U|L)?"',
        end: '"',
        illegal: "\\n",
        contains: [t.BACKSLASH_ESCAPE]
      },
      {
        begin: "(u8?|U|L)?'(" + l + "|.)",
        end: "'",
        illegal: "."
      },
      t.END_SAME_AS_BEGIN({
        begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
        end: /\)([^()\\ ]{0,16})"/
      })
    ]
  }, d = {
    className: "number",
    variants: [
      { begin: "\\b(0b[01']+)" },
      { begin: "(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)" },
      { begin: "(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)" }
    ],
    relevance: 0
  }, u = {
    className: "meta",
    begin: /#\s*[a-z]+\b/,
    end: /$/,
    keywords: { keyword: "if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include" },
    contains: [
      {
        begin: /\\\n/,
        relevance: 0
      },
      t.inherit(c, { className: "string" }),
      {
        className: "string",
        begin: /<.*?>/
      },
      n,
      t.C_BLOCK_COMMENT_MODE
    ]
  }, f = {
    className: "title",
    begin: e.optional(i) + t.IDENT_RE,
    relevance: 0
  }, p = e.optional(i) + t.IDENT_RE + "\\s*\\(", g = {
    keyword: [
      "asm",
      "auto",
      "break",
      "case",
      "continue",
      "default",
      "do",
      "else",
      "enum",
      "extern",
      "for",
      "fortran",
      "goto",
      "if",
      "inline",
      "register",
      "restrict",
      "return",
      "sizeof",
      "struct",
      "switch",
      "typedef",
      "union",
      "volatile",
      "while",
      "_Alignas",
      "_Alignof",
      "_Atomic",
      "_Generic",
      "_Noreturn",
      "_Static_assert",
      "_Thread_local",
      // aliases
      "alignas",
      "alignof",
      "noreturn",
      "static_assert",
      "thread_local",
      // not a C keyword but is, for all intents and purposes, treated exactly like one.
      "_Pragma"
    ],
    type: [
      "float",
      "double",
      "signed",
      "unsigned",
      "int",
      "short",
      "long",
      "char",
      "void",
      "_Bool",
      "_Complex",
      "_Imaginary",
      "_Decimal32",
      "_Decimal64",
      "_Decimal128",
      // modifiers
      "const",
      "static",
      // aliases
      "complex",
      "bool",
      "imaginary"
    ],
    literal: "true false NULL",
    // TODO: apply hinting work similar to what was done in cpp.js
    built_in: "std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"
  }, v = [
    u,
    a,
    n,
    t.C_BLOCK_COMMENT_MODE,
    d,
    c
  ], y = {
    // This mode covers expression context where we can't expect a function
    // definition and shouldn't highlight anything that looks like one:
    // `return some()`, `else if()`, `(x*sum(1, 2))`
    variants: [
      {
        begin: /=/,
        end: /;/
      },
      {
        begin: /\(/,
        end: /\)/
      },
      {
        beginKeywords: "new throw return else",
        end: /;/
      }
    ],
    keywords: g,
    contains: v.concat([
      {
        begin: /\(/,
        end: /\)/,
        keywords: g,
        contains: v.concat(["self"]),
        relevance: 0
      }
    ]),
    relevance: 0
  }, E = {
    begin: "(" + o + "[\\*&\\s]+)+" + p,
    returnBegin: !0,
    end: /[{;=]/,
    excludeEnd: !0,
    keywords: g,
    illegal: /[^\w\s\*&:<>.]/,
    contains: [
      {
        // to prevent it from being confused as the function title
        begin: r,
        keywords: g,
        relevance: 0
      },
      {
        begin: p,
        returnBegin: !0,
        contains: [t.inherit(f, { className: "title.function" })],
        relevance: 0
      },
      // allow for multiple declarations, e.g.:
      // extern void f(int), g(char);
      {
        relevance: 0,
        match: /,/
      },
      {
        className: "params",
        begin: /\(/,
        end: /\)/,
        keywords: g,
        relevance: 0,
        contains: [
          n,
          t.C_BLOCK_COMMENT_MODE,
          c,
          d,
          a,
          // Count matching parentheses.
          {
            begin: /\(/,
            end: /\)/,
            keywords: g,
            relevance: 0,
            contains: [
              "self",
              n,
              t.C_BLOCK_COMMENT_MODE,
              c,
              d,
              a
            ]
          }
        ]
      },
      a,
      n,
      t.C_BLOCK_COMMENT_MODE,
      u
    ]
  };
  return {
    name: "C",
    aliases: ["h"],
    keywords: g,
    // Until differentiations are added between `c` and `cpp`, `c` will
    // not be auto-detected to avoid auto-detect conflicts between C and C++
    disableAutodetect: !0,
    illegal: "</",
    contains: [].concat(
      y,
      E,
      v,
      [
        u,
        {
          begin: t.IDENT_RE + "::",
          keywords: g
        },
        {
          className: "class",
          beginKeywords: "enum class struct union",
          end: /[{;:<>=]/,
          contains: [
            { beginKeywords: "final class struct" },
            t.TITLE_MODE
          ]
        }
      ]
    ),
    exports: {
      preprocessor: u,
      strings: c,
      keywords: g
    }
  };
}
function GS(t) {
  const e = t.regex, n = t.COMMENT("//", "$", { contains: [{ begin: /\\\n/ }] }), r = "decltype\\(auto\\)", i = "[a-zA-Z_]\\w*::", s = "<[^<>]+>", o = "(?!struct)(" + r + "|" + e.optional(i) + "[a-zA-Z_]\\w*" + e.optional(s) + ")", a = {
    className: "type",
    begin: "\\b[a-z\\d_]*_t\\b"
  }, l = "\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)", c = {
    className: "string",
    variants: [
      {
        begin: '(u8?|U|L)?"',
        end: '"',
        illegal: "\\n",
        contains: [t.BACKSLASH_ESCAPE]
      },
      {
        begin: "(u8?|U|L)?'(" + l + "|.)",
        end: "'",
        illegal: "."
      },
      t.END_SAME_AS_BEGIN({
        begin: /(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,
        end: /\)([^()\\ ]{0,16})"/
      })
    ]
  }, d = {
    className: "number",
    variants: [
      { begin: "\\b(0b[01']+)" },
      { begin: "(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)" },
      { begin: "(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)" }
    ],
    relevance: 0
  }, u = {
    className: "meta",
    begin: /#\s*[a-z]+\b/,
    end: /$/,
    keywords: { keyword: "if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include" },
    contains: [
      {
        begin: /\\\n/,
        relevance: 0
      },
      t.inherit(c, { className: "string" }),
      {
        className: "string",
        begin: /<.*?>/
      },
      n,
      t.C_BLOCK_COMMENT_MODE
    ]
  }, f = {
    className: "title",
    begin: e.optional(i) + t.IDENT_RE,
    relevance: 0
  }, p = e.optional(i) + t.IDENT_RE + "\\s*\\(", h = [
    "alignas",
    "alignof",
    "and",
    "and_eq",
    "asm",
    "atomic_cancel",
    "atomic_commit",
    "atomic_noexcept",
    "auto",
    "bitand",
    "bitor",
    "break",
    "case",
    "catch",
    "class",
    "co_await",
    "co_return",
    "co_yield",
    "compl",
    "concept",
    "const_cast|10",
    "consteval",
    "constexpr",
    "constinit",
    "continue",
    "decltype",
    "default",
    "delete",
    "do",
    "dynamic_cast|10",
    "else",
    "enum",
    "explicit",
    "export",
    "extern",
    "false",
    "final",
    "for",
    "friend",
    "goto",
    "if",
    "import",
    "inline",
    "module",
    "mutable",
    "namespace",
    "new",
    "noexcept",
    "not",
    "not_eq",
    "nullptr",
    "operator",
    "or",
    "or_eq",
    "override",
    "private",
    "protected",
    "public",
    "reflexpr",
    "register",
    "reinterpret_cast|10",
    "requires",
    "return",
    "sizeof",
    "static_assert",
    "static_cast|10",
    "struct",
    "switch",
    "synchronized",
    "template",
    "this",
    "thread_local",
    "throw",
    "transaction_safe",
    "transaction_safe_dynamic",
    "true",
    "try",
    "typedef",
    "typeid",
    "typename",
    "union",
    "using",
    "virtual",
    "volatile",
    "while",
    "xor",
    "xor_eq"
  ], m = [
    "bool",
    "char",
    "char16_t",
    "char32_t",
    "char8_t",
    "double",
    "float",
    "int",
    "long",
    "short",
    "void",
    "wchar_t",
    "unsigned",
    "signed",
    "const",
    "static"
  ], g = [
    "any",
    "auto_ptr",
    "barrier",
    "binary_semaphore",
    "bitset",
    "complex",
    "condition_variable",
    "condition_variable_any",
    "counting_semaphore",
    "deque",
    "false_type",
    "future",
    "imaginary",
    "initializer_list",
    "istringstream",
    "jthread",
    "latch",
    "lock_guard",
    "multimap",
    "multiset",
    "mutex",
    "optional",
    "ostringstream",
    "packaged_task",
    "pair",
    "promise",
    "priority_queue",
    "queue",
    "recursive_mutex",
    "recursive_timed_mutex",
    "scoped_lock",
    "set",
    "shared_future",
    "shared_lock",
    "shared_mutex",
    "shared_timed_mutex",
    "shared_ptr",
    "stack",
    "string_view",
    "stringstream",
    "timed_mutex",
    "thread",
    "true_type",
    "tuple",
    "unique_lock",
    "unique_ptr",
    "unordered_map",
    "unordered_multimap",
    "unordered_multiset",
    "unordered_set",
    "variant",
    "vector",
    "weak_ptr",
    "wstring",
    "wstring_view"
  ], v = [
    "abort",
    "abs",
    "acos",
    "apply",
    "as_const",
    "asin",
    "atan",
    "atan2",
    "calloc",
    "ceil",
    "cerr",
    "cin",
    "clog",
    "cos",
    "cosh",
    "cout",
    "declval",
    "endl",
    "exchange",
    "exit",
    "exp",
    "fabs",
    "floor",
    "fmod",
    "forward",
    "fprintf",
    "fputs",
    "free",
    "frexp",
    "fscanf",
    "future",
    "invoke",
    "isalnum",
    "isalpha",
    "iscntrl",
    "isdigit",
    "isgraph",
    "islower",
    "isprint",
    "ispunct",
    "isspace",
    "isupper",
    "isxdigit",
    "labs",
    "launder",
    "ldexp",
    "log",
    "log10",
    "make_pair",
    "make_shared",
    "make_shared_for_overwrite",
    "make_tuple",
    "make_unique",
    "malloc",
    "memchr",
    "memcmp",
    "memcpy",
    "memset",
    "modf",
    "move",
    "pow",
    "printf",
    "putchar",
    "puts",
    "realloc",
    "scanf",
    "sin",
    "sinh",
    "snprintf",
    "sprintf",
    "sqrt",
    "sscanf",
    "std",
    "stderr",
    "stdin",
    "stdout",
    "strcat",
    "strchr",
    "strcmp",
    "strcpy",
    "strcspn",
    "strlen",
    "strncat",
    "strncmp",
    "strncpy",
    "strpbrk",
    "strrchr",
    "strspn",
    "strstr",
    "swap",
    "tan",
    "tanh",
    "terminate",
    "to_underlying",
    "tolower",
    "toupper",
    "vfprintf",
    "visit",
    "vprintf",
    "vsprintf"
  ], b = {
    type: m,
    keyword: h,
    literal: [
      "NULL",
      "false",
      "nullopt",
      "nullptr",
      "true"
    ],
    built_in: ["_Pragma"],
    _type_hints: g
  }, C = {
    className: "function.dispatch",
    relevance: 0,
    keywords: {
      // Only for relevance, not highlighting.
      _hint: v
    },
    begin: e.concat(
      /\b/,
      /(?!decltype)/,
      /(?!if)/,
      /(?!for)/,
      /(?!switch)/,
      /(?!while)/,
      t.IDENT_RE,
      e.lookahead(/(<[^<>]+>|)\s*\(/)
    )
  }, w = [
    C,
    u,
    a,
    n,
    t.C_BLOCK_COMMENT_MODE,
    d,
    c
  ], _ = {
    // This mode covers expression context where we can't expect a function
    // definition and shouldn't highlight anything that looks like one:
    // `return some()`, `else if()`, `(x*sum(1, 2))`
    variants: [
      {
        begin: /=/,
        end: /;/
      },
      {
        begin: /\(/,
        end: /\)/
      },
      {
        beginKeywords: "new throw return else",
        end: /;/
      }
    ],
    keywords: b,
    contains: w.concat([
      {
        begin: /\(/,
        end: /\)/,
        keywords: b,
        contains: w.concat(["self"]),
        relevance: 0
      }
    ]),
    relevance: 0
  }, R = {
    className: "function",
    begin: "(" + o + "[\\*&\\s]+)+" + p,
    returnBegin: !0,
    end: /[{;=]/,
    excludeEnd: !0,
    keywords: b,
    illegal: /[^\w\s\*&:<>.]/,
    contains: [
      {
        // to prevent it from being confused as the function title
        begin: r,
        keywords: b,
        relevance: 0
      },
      {
        begin: p,
        returnBegin: !0,
        contains: [f],
        relevance: 0
      },
      // needed because we do not have look-behind on the below rule
      // to prevent it from grabbing the final : in a :: pair
      {
        begin: /::/,
        relevance: 0
      },
      // initializers
      {
        begin: /:/,
        endsWithParent: !0,
        contains: [
          c,
          d
        ]
      },
      // allow for multiple declarations, e.g.:
      // extern void f(int), g(char);
      {
        relevance: 0,
        match: /,/
      },
      {
        className: "params",
        begin: /\(/,
        end: /\)/,
        keywords: b,
        relevance: 0,
        contains: [
          n,
          t.C_BLOCK_COMMENT_MODE,
          c,
          d,
          a,
          // Count matching parentheses.
          {
            begin: /\(/,
            end: /\)/,
            keywords: b,
            relevance: 0,
            contains: [
              "self",
              n,
              t.C_BLOCK_COMMENT_MODE,
              c,
              d,
              a
            ]
          }
        ]
      },
      a,
      n,
      t.C_BLOCK_COMMENT_MODE,
      u
    ]
  };
  return {
    name: "C++",
    aliases: [
      "cc",
      "c++",
      "h++",
      "hpp",
      "hh",
      "hxx",
      "cxx"
    ],
    keywords: b,
    illegal: "</",
    classNameAliases: { "function.dispatch": "built_in" },
    contains: [].concat(
      _,
      R,
      C,
      w,
      [
        u,
        {
          // containers: ie, `vector <int> rooms (9);`
          begin: "\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function)\\s*<(?!<)",
          end: ">",
          keywords: b,
          contains: [
            "self",
            a
          ]
        },
        {
          begin: t.IDENT_RE + "::",
          keywords: b
        },
        {
          match: [
            // extra complexity to deal with `enum class` and `enum struct`
            /\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,
            /\s+/,
            /\w+/
          ],
          className: {
            1: "keyword",
            3: "title.class"
          }
        }
      ]
    )
  };
}
function jS(t) {
  const e = [
    "bool",
    "byte",
    "char",
    "decimal",
    "delegate",
    "double",
    "dynamic",
    "enum",
    "float",
    "int",
    "long",
    "nint",
    "nuint",
    "object",
    "sbyte",
    "short",
    "string",
    "ulong",
    "uint",
    "ushort"
  ], n = [
    "public",
    "private",
    "protected",
    "static",
    "internal",
    "protected",
    "abstract",
    "async",
    "extern",
    "override",
    "unsafe",
    "virtual",
    "new",
    "sealed",
    "partial"
  ], r = [
    "default",
    "false",
    "null",
    "true"
  ], i = [
    "abstract",
    "as",
    "base",
    "break",
    "case",
    "catch",
    "class",
    "const",
    "continue",
    "do",
    "else",
    "event",
    "explicit",
    "extern",
    "finally",
    "fixed",
    "for",
    "foreach",
    "goto",
    "if",
    "implicit",
    "in",
    "interface",
    "internal",
    "is",
    "lock",
    "namespace",
    "new",
    "operator",
    "out",
    "override",
    "params",
    "private",
    "protected",
    "public",
    "readonly",
    "record",
    "ref",
    "return",
    "scoped",
    "sealed",
    "sizeof",
    "stackalloc",
    "static",
    "struct",
    "switch",
    "this",
    "throw",
    "try",
    "typeof",
    "unchecked",
    "unsafe",
    "using",
    "virtual",
    "void",
    "volatile",
    "while"
  ], s = [
    "add",
    "alias",
    "and",
    "ascending",
    "async",
    "await",
    "by",
    "descending",
    "equals",
    "from",
    "get",
    "global",
    "group",
    "init",
    "into",
    "join",
    "let",
    "nameof",
    "not",
    "notnull",
    "on",
    "or",
    "orderby",
    "partial",
    "remove",
    "select",
    "set",
    "unmanaged",
    "value|0",
    "var",
    "when",
    "where",
    "with",
    "yield"
  ], o = {
    keyword: i.concat(s),
    built_in: e,
    literal: r
  }, a = t.inherit(t.TITLE_MODE, { begin: "[a-zA-Z](\\.?\\w)*" }), l = {
    className: "number",
    variants: [
      { begin: "\\b(0b[01']+)" },
      { begin: "(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)" },
      { begin: "(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)" }
    ],
    relevance: 0
  }, c = {
    className: "string",
    begin: '@"',
    end: '"',
    contains: [{ begin: '""' }]
  }, d = t.inherit(c, { illegal: /\n/ }), u = {
    className: "subst",
    begin: /\{/,
    end: /\}/,
    keywords: o
  }, f = t.inherit(u, { illegal: /\n/ }), p = {
    className: "string",
    begin: /\$"/,
    end: '"',
    illegal: /\n/,
    contains: [
      { begin: /\{\{/ },
      { begin: /\}\}/ },
      t.BACKSLASH_ESCAPE,
      f
    ]
  }, h = {
    className: "string",
    begin: /\$@"/,
    end: '"',
    contains: [
      { begin: /\{\{/ },
      { begin: /\}\}/ },
      { begin: '""' },
      u
    ]
  }, m = t.inherit(h, {
    illegal: /\n/,
    contains: [
      { begin: /\{\{/ },
      { begin: /\}\}/ },
      { begin: '""' },
      f
    ]
  });
  u.contains = [
    h,
    p,
    c,
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE,
    l,
    t.C_BLOCK_COMMENT_MODE
  ], f.contains = [
    m,
    p,
    d,
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE,
    l,
    t.inherit(t.C_BLOCK_COMMENT_MODE, { illegal: /\n/ })
  ];
  const g = { variants: [
    h,
    p,
    c,
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE
  ] }, v = {
    begin: "<",
    end: ">",
    contains: [
      { beginKeywords: "in out" },
      a
    ]
  }, y = t.IDENT_RE + "(<" + t.IDENT_RE + "(\\s*,\\s*" + t.IDENT_RE + ")*>)?(\\[\\])?", E = {
    // prevents expressions like `@class` from incorrect flagging
    // `class` as a keyword
    begin: "@" + t.IDENT_RE,
    relevance: 0
  };
  return {
    name: "C#",
    aliases: [
      "cs",
      "c#"
    ],
    keywords: o,
    illegal: /::/,
    contains: [
      t.COMMENT(
        "///",
        "$",
        {
          returnBegin: !0,
          contains: [
            {
              className: "doctag",
              variants: [
                {
                  begin: "///",
                  relevance: 0
                },
                { begin: "<!--|-->" },
                {
                  begin: "</?",
                  end: ">"
                }
              ]
            }
          ]
        }
      ),
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      {
        className: "meta",
        begin: "#",
        end: "$",
        keywords: { keyword: "if else elif endif define undef warning error line region endregion pragma checksum" }
      },
      g,
      l,
      {
        beginKeywords: "class interface",
        relevance: 0,
        end: /[{;=]/,
        illegal: /[^\s:,]/,
        contains: [
          { beginKeywords: "where class" },
          a,
          v,
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      {
        beginKeywords: "namespace",
        relevance: 0,
        end: /[{;=]/,
        illegal: /[^\s:]/,
        contains: [
          a,
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      {
        beginKeywords: "record",
        relevance: 0,
        end: /[{;=]/,
        illegal: /[^\s:]/,
        contains: [
          a,
          v,
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      {
        // [Attributes("")]
        className: "meta",
        begin: "^\\s*\\[(?=[\\w])",
        excludeBegin: !0,
        end: "\\]",
        excludeEnd: !0,
        contains: [
          {
            className: "string",
            begin: /"/,
            end: /"/
          }
        ]
      },
      {
        // Expression keywords prevent 'keyword Name(...)' from being
        // recognized as a function definition
        beginKeywords: "new return throw await else",
        relevance: 0
      },
      {
        className: "function",
        begin: "(" + y + "\\s+)+" + t.IDENT_RE + "\\s*(<[^=]+>\\s*)?\\(",
        returnBegin: !0,
        end: /\s*[{;=]/,
        excludeEnd: !0,
        keywords: o,
        contains: [
          // prevents these from being highlighted `title`
          {
            beginKeywords: n.join(" "),
            relevance: 0
          },
          {
            begin: t.IDENT_RE + "\\s*(<[^=]+>\\s*)?\\(",
            returnBegin: !0,
            contains: [
              t.TITLE_MODE,
              v
            ],
            relevance: 0
          },
          { match: /\(\)/ },
          {
            className: "params",
            begin: /\(/,
            end: /\)/,
            excludeBegin: !0,
            excludeEnd: !0,
            keywords: o,
            relevance: 0,
            contains: [
              g,
              l,
              t.C_BLOCK_COMMENT_MODE
            ]
          },
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      E
    ]
  };
}
const YS = (t) => ({
  IMPORTANT: {
    scope: "meta",
    begin: "!important"
  },
  BLOCK_COMMENT: t.C_BLOCK_COMMENT_MODE,
  HEXCOLOR: {
    scope: "number",
    begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
  },
  FUNCTION_DISPATCH: {
    className: "built_in",
    begin: /[\w-]+(?=\()/
  },
  ATTRIBUTE_SELECTOR_MODE: {
    scope: "selector-attr",
    begin: /\[/,
    end: /\]/,
    illegal: "$",
    contains: [
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE
    ]
  },
  CSS_NUMBER_MODE: {
    scope: "number",
    begin: t.NUMBER_RE + "(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",
    relevance: 0
  },
  CSS_VARIABLE: {
    className: "attr",
    begin: /--[A-Za-z_][A-Za-z0-9_-]*/
  }
}), JS = [
  "a",
  "abbr",
  "address",
  "article",
  "aside",
  "audio",
  "b",
  "blockquote",
  "body",
  "button",
  "canvas",
  "caption",
  "cite",
  "code",
  "dd",
  "del",
  "details",
  "dfn",
  "div",
  "dl",
  "dt",
  "em",
  "fieldset",
  "figcaption",
  "figure",
  "footer",
  "form",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "header",
  "hgroup",
  "html",
  "i",
  "iframe",
  "img",
  "input",
  "ins",
  "kbd",
  "label",
  "legend",
  "li",
  "main",
  "mark",
  "menu",
  "nav",
  "object",
  "ol",
  "p",
  "q",
  "quote",
  "samp",
  "section",
  "span",
  "strong",
  "summary",
  "sup",
  "table",
  "tbody",
  "td",
  "textarea",
  "tfoot",
  "th",
  "thead",
  "time",
  "tr",
  "ul",
  "var",
  "video"
], XS = [
  "any-hover",
  "any-pointer",
  "aspect-ratio",
  "color",
  "color-gamut",
  "color-index",
  "device-aspect-ratio",
  "device-height",
  "device-width",
  "display-mode",
  "forced-colors",
  "grid",
  "height",
  "hover",
  "inverted-colors",
  "monochrome",
  "orientation",
  "overflow-block",
  "overflow-inline",
  "pointer",
  "prefers-color-scheme",
  "prefers-contrast",
  "prefers-reduced-motion",
  "prefers-reduced-transparency",
  "resolution",
  "scan",
  "scripting",
  "update",
  "width",
  // TODO: find a better solution?
  "min-width",
  "max-width",
  "min-height",
  "max-height"
], QS = [
  "active",
  "any-link",
  "blank",
  "checked",
  "current",
  "default",
  "defined",
  "dir",
  // dir()
  "disabled",
  "drop",
  "empty",
  "enabled",
  "first",
  "first-child",
  "first-of-type",
  "fullscreen",
  "future",
  "focus",
  "focus-visible",
  "focus-within",
  "has",
  // has()
  "host",
  // host or host()
  "host-context",
  // host-context()
  "hover",
  "indeterminate",
  "in-range",
  "invalid",
  "is",
  // is()
  "lang",
  // lang()
  "last-child",
  "last-of-type",
  "left",
  "link",
  "local-link",
  "not",
  // not()
  "nth-child",
  // nth-child()
  "nth-col",
  // nth-col()
  "nth-last-child",
  // nth-last-child()
  "nth-last-col",
  // nth-last-col()
  "nth-last-of-type",
  //nth-last-of-type()
  "nth-of-type",
  //nth-of-type()
  "only-child",
  "only-of-type",
  "optional",
  "out-of-range",
  "past",
  "placeholder-shown",
  "read-only",
  "read-write",
  "required",
  "right",
  "root",
  "scope",
  "target",
  "target-within",
  "user-invalid",
  "valid",
  "visited",
  "where"
  // where()
], eC = [
  "after",
  "backdrop",
  "before",
  "cue",
  "cue-region",
  "first-letter",
  "first-line",
  "grammar-error",
  "marker",
  "part",
  "placeholder",
  "selection",
  "slotted",
  "spelling-error"
], tC = [
  "align-content",
  "align-items",
  "align-self",
  "all",
  "animation",
  "animation-delay",
  "animation-direction",
  "animation-duration",
  "animation-fill-mode",
  "animation-iteration-count",
  "animation-name",
  "animation-play-state",
  "animation-timing-function",
  "backface-visibility",
  "background",
  "background-attachment",
  "background-blend-mode",
  "background-clip",
  "background-color",
  "background-image",
  "background-origin",
  "background-position",
  "background-repeat",
  "background-size",
  "block-size",
  "border",
  "border-block",
  "border-block-color",
  "border-block-end",
  "border-block-end-color",
  "border-block-end-style",
  "border-block-end-width",
  "border-block-start",
  "border-block-start-color",
  "border-block-start-style",
  "border-block-start-width",
  "border-block-style",
  "border-block-width",
  "border-bottom",
  "border-bottom-color",
  "border-bottom-left-radius",
  "border-bottom-right-radius",
  "border-bottom-style",
  "border-bottom-width",
  "border-collapse",
  "border-color",
  "border-image",
  "border-image-outset",
  "border-image-repeat",
  "border-image-slice",
  "border-image-source",
  "border-image-width",
  "border-inline",
  "border-inline-color",
  "border-inline-end",
  "border-inline-end-color",
  "border-inline-end-style",
  "border-inline-end-width",
  "border-inline-start",
  "border-inline-start-color",
  "border-inline-start-style",
  "border-inline-start-width",
  "border-inline-style",
  "border-inline-width",
  "border-left",
  "border-left-color",
  "border-left-style",
  "border-left-width",
  "border-radius",
  "border-right",
  "border-right-color",
  "border-right-style",
  "border-right-width",
  "border-spacing",
  "border-style",
  "border-top",
  "border-top-color",
  "border-top-left-radius",
  "border-top-right-radius",
  "border-top-style",
  "border-top-width",
  "border-width",
  "bottom",
  "box-decoration-break",
  "box-shadow",
  "box-sizing",
  "break-after",
  "break-before",
  "break-inside",
  "caption-side",
  "caret-color",
  "clear",
  "clip",
  "clip-path",
  "clip-rule",
  "color",
  "column-count",
  "column-fill",
  "column-gap",
  "column-rule",
  "column-rule-color",
  "column-rule-style",
  "column-rule-width",
  "column-span",
  "column-width",
  "columns",
  "contain",
  "content",
  "content-visibility",
  "counter-increment",
  "counter-reset",
  "cue",
  "cue-after",
  "cue-before",
  "cursor",
  "direction",
  "display",
  "empty-cells",
  "filter",
  "flex",
  "flex-basis",
  "flex-direction",
  "flex-flow",
  "flex-grow",
  "flex-shrink",
  "flex-wrap",
  "float",
  "flow",
  "font",
  "font-display",
  "font-family",
  "font-feature-settings",
  "font-kerning",
  "font-language-override",
  "font-size",
  "font-size-adjust",
  "font-smoothing",
  "font-stretch",
  "font-style",
  "font-synthesis",
  "font-variant",
  "font-variant-caps",
  "font-variant-east-asian",
  "font-variant-ligatures",
  "font-variant-numeric",
  "font-variant-position",
  "font-variation-settings",
  "font-weight",
  "gap",
  "glyph-orientation-vertical",
  "grid",
  "grid-area",
  "grid-auto-columns",
  "grid-auto-flow",
  "grid-auto-rows",
  "grid-column",
  "grid-column-end",
  "grid-column-start",
  "grid-gap",
  "grid-row",
  "grid-row-end",
  "grid-row-start",
  "grid-template",
  "grid-template-areas",
  "grid-template-columns",
  "grid-template-rows",
  "hanging-punctuation",
  "height",
  "hyphens",
  "icon",
  "image-orientation",
  "image-rendering",
  "image-resolution",
  "ime-mode",
  "inline-size",
  "isolation",
  "justify-content",
  "left",
  "letter-spacing",
  "line-break",
  "line-height",
  "list-style",
  "list-style-image",
  "list-style-position",
  "list-style-type",
  "margin",
  "margin-block",
  "margin-block-end",
  "margin-block-start",
  "margin-bottom",
  "margin-inline",
  "margin-inline-end",
  "margin-inline-start",
  "margin-left",
  "margin-right",
  "margin-top",
  "marks",
  "mask",
  "mask-border",
  "mask-border-mode",
  "mask-border-outset",
  "mask-border-repeat",
  "mask-border-slice",
  "mask-border-source",
  "mask-border-width",
  "mask-clip",
  "mask-composite",
  "mask-image",
  "mask-mode",
  "mask-origin",
  "mask-position",
  "mask-repeat",
  "mask-size",
  "mask-type",
  "max-block-size",
  "max-height",
  "max-inline-size",
  "max-width",
  "min-block-size",
  "min-height",
  "min-inline-size",
  "min-width",
  "mix-blend-mode",
  "nav-down",
  "nav-index",
  "nav-left",
  "nav-right",
  "nav-up",
  "none",
  "normal",
  "object-fit",
  "object-position",
  "opacity",
  "order",
  "orphans",
  "outline",
  "outline-color",
  "outline-offset",
  "outline-style",
  "outline-width",
  "overflow",
  "overflow-wrap",
  "overflow-x",
  "overflow-y",
  "padding",
  "padding-block",
  "padding-block-end",
  "padding-block-start",
  "padding-bottom",
  "padding-inline",
  "padding-inline-end",
  "padding-inline-start",
  "padding-left",
  "padding-right",
  "padding-top",
  "page-break-after",
  "page-break-before",
  "page-break-inside",
  "pause",
  "pause-after",
  "pause-before",
  "perspective",
  "perspective-origin",
  "pointer-events",
  "position",
  "quotes",
  "resize",
  "rest",
  "rest-after",
  "rest-before",
  "right",
  "row-gap",
  "scroll-margin",
  "scroll-margin-block",
  "scroll-margin-block-end",
  "scroll-margin-block-start",
  "scroll-margin-bottom",
  "scroll-margin-inline",
  "scroll-margin-inline-end",
  "scroll-margin-inline-start",
  "scroll-margin-left",
  "scroll-margin-right",
  "scroll-margin-top",
  "scroll-padding",
  "scroll-padding-block",
  "scroll-padding-block-end",
  "scroll-padding-block-start",
  "scroll-padding-bottom",
  "scroll-padding-inline",
  "scroll-padding-inline-end",
  "scroll-padding-inline-start",
  "scroll-padding-left",
  "scroll-padding-right",
  "scroll-padding-top",
  "scroll-snap-align",
  "scroll-snap-stop",
  "scroll-snap-type",
  "scrollbar-color",
  "scrollbar-gutter",
  "scrollbar-width",
  "shape-image-threshold",
  "shape-margin",
  "shape-outside",
  "speak",
  "speak-as",
  "src",
  // @font-face
  "tab-size",
  "table-layout",
  "text-align",
  "text-align-all",
  "text-align-last",
  "text-combine-upright",
  "text-decoration",
  "text-decoration-color",
  "text-decoration-line",
  "text-decoration-style",
  "text-emphasis",
  "text-emphasis-color",
  "text-emphasis-position",
  "text-emphasis-style",
  "text-indent",
  "text-justify",
  "text-orientation",
  "text-overflow",
  "text-rendering",
  "text-shadow",
  "text-transform",
  "text-underline-position",
  "top",
  "transform",
  "transform-box",
  "transform-origin",
  "transform-style",
  "transition",
  "transition-delay",
  "transition-duration",
  "transition-property",
  "transition-timing-function",
  "unicode-bidi",
  "vertical-align",
  "visibility",
  "voice-balance",
  "voice-duration",
  "voice-family",
  "voice-pitch",
  "voice-range",
  "voice-rate",
  "voice-stress",
  "voice-volume",
  "white-space",
  "widows",
  "width",
  "will-change",
  "word-break",
  "word-spacing",
  "word-wrap",
  "writing-mode",
  "z-index"
  // reverse makes sure longer attributes `font-weight` are matched fully
  // instead of getting false positives on say `font`
].reverse();
function nC(t) {
  const e = t.regex, n = YS(t), r = { begin: /-(webkit|moz|ms|o)-(?=[a-z])/ }, i = "and or not only", s = /@-?\w[\w]*(-\w+)*/, o = "[a-zA-Z-][a-zA-Z0-9_-]*", a = [
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE
  ];
  return {
    name: "CSS",
    case_insensitive: !0,
    illegal: /[=|'\$]/,
    keywords: { keyframePosition: "from to" },
    classNameAliases: {
      // for visual continuity with `tag {}` and because we
      // don't have a great class for this?
      keyframePosition: "selector-tag"
    },
    contains: [
      n.BLOCK_COMMENT,
      r,
      // to recognize keyframe 40% etc which are outside the scope of our
      // attribute value mode
      n.CSS_NUMBER_MODE,
      {
        className: "selector-id",
        begin: /#[A-Za-z0-9_-]+/,
        relevance: 0
      },
      {
        className: "selector-class",
        begin: "\\." + o,
        relevance: 0
      },
      n.ATTRIBUTE_SELECTOR_MODE,
      {
        className: "selector-pseudo",
        variants: [
          { begin: ":(" + QS.join("|") + ")" },
          { begin: ":(:)?(" + eC.join("|") + ")" }
        ]
      },
      // we may actually need this (12/2020)
      // { // pseudo-selector params
      //   begin: /\(/,
      //   end: /\)/,
      //   contains: [ hljs.CSS_NUMBER_MODE ]
      // },
      n.CSS_VARIABLE,
      {
        className: "attribute",
        begin: "\\b(" + tC.join("|") + ")\\b"
      },
      // attribute values
      {
        begin: /:/,
        end: /[;}{]/,
        contains: [
          n.BLOCK_COMMENT,
          n.HEXCOLOR,
          n.IMPORTANT,
          n.CSS_NUMBER_MODE,
          ...a,
          // needed to highlight these as strings and to avoid issues with
          // illegal characters that might be inside urls that would tigger the
          // languages illegal stack
          {
            begin: /(url|data-uri)\(/,
            end: /\)/,
            relevance: 0,
            // from keywords
            keywords: { built_in: "url data-uri" },
            contains: [
              ...a,
              {
                className: "string",
                // any character other than `)` as in `url()` will be the start
                // of a string, which ends with `)` (from the parent mode)
                begin: /[^)]/,
                endsWithParent: !0,
                excludeEnd: !0
              }
            ]
          },
          n.FUNCTION_DISPATCH
        ]
      },
      {
        begin: e.lookahead(/@/),
        end: "[{;]",
        relevance: 0,
        illegal: /:/,
        // break on Less variables @var: ...
        contains: [
          {
            className: "keyword",
            begin: s
          },
          {
            begin: /\s/,
            endsWithParent: !0,
            excludeEnd: !0,
            relevance: 0,
            keywords: {
              $pattern: /[a-z-]+/,
              keyword: i,
              attribute: XS.join(" ")
            },
            contains: [
              {
                begin: /[a-z-]+(?=:)/,
                className: "attribute"
              },
              ...a,
              n.CSS_NUMBER_MODE
            ]
          }
        ]
      },
      {
        className: "selector-tag",
        begin: "\\b(" + JS.join("|") + ")\\b"
      }
    ]
  };
}
function rC(t) {
  const e = t.regex;
  return {
    name: "Diff",
    aliases: ["patch"],
    contains: [
      {
        className: "meta",
        relevance: 10,
        match: e.either(
          /^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,
          /^\*\*\* +\d+,\d+ +\*\*\*\*$/,
          /^--- +\d+,\d+ +----$/
        )
      },
      {
        className: "comment",
        variants: [
          {
            begin: e.either(
              /Index: /,
              /^index/,
              /={3,}/,
              /^-{3}/,
              /^\*{3} /,
              /^\+{3}/,
              /^diff --git/
            ),
            end: /$/
          },
          { match: /^\*{15}$/ }
        ]
      },
      {
        className: "addition",
        begin: /^\+/,
        end: /$/
      },
      {
        className: "deletion",
        begin: /^-/,
        end: /$/
      },
      {
        className: "addition",
        begin: /^!/,
        end: /$/
      }
    ]
  };
}
function iC(t) {
  const s = {
    keyword: [
      "break",
      "case",
      "chan",
      "const",
      "continue",
      "default",
      "defer",
      "else",
      "fallthrough",
      "for",
      "func",
      "go",
      "goto",
      "if",
      "import",
      "interface",
      "map",
      "package",
      "range",
      "return",
      "select",
      "struct",
      "switch",
      "type",
      "var"
    ],
    type: [
      "bool",
      "byte",
      "complex64",
      "complex128",
      "error",
      "float32",
      "float64",
      "int8",
      "int16",
      "int32",
      "int64",
      "string",
      "uint8",
      "uint16",
      "uint32",
      "uint64",
      "int",
      "uint",
      "uintptr",
      "rune"
    ],
    literal: [
      "true",
      "false",
      "iota",
      "nil"
    ],
    built_in: [
      "append",
      "cap",
      "close",
      "complex",
      "copy",
      "imag",
      "len",
      "make",
      "new",
      "panic",
      "print",
      "println",
      "real",
      "recover",
      "delete"
    ]
  };
  return {
    name: "Go",
    aliases: ["golang"],
    keywords: s,
    illegal: "</",
    contains: [
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      {
        className: "string",
        variants: [
          t.QUOTE_STRING_MODE,
          t.APOS_STRING_MODE,
          {
            begin: "`",
            end: "`"
          }
        ]
      },
      {
        className: "number",
        variants: [
          {
            begin: t.C_NUMBER_RE + "[i]",
            relevance: 1
          },
          t.C_NUMBER_MODE
        ]
      },
      {
        begin: /:=/
        // relevance booster
      },
      {
        className: "function",
        beginKeywords: "func",
        end: "\\s*(\\{|$)",
        excludeEnd: !0,
        contains: [
          t.TITLE_MODE,
          {
            className: "params",
            begin: /\(/,
            end: /\)/,
            endsParent: !0,
            keywords: s,
            illegal: /["']/
          }
        ]
      }
    ]
  };
}
function sC(t) {
  const e = t.regex, n = /[_A-Za-z][_0-9A-Za-z]*/;
  return {
    name: "GraphQL",
    aliases: ["gql"],
    case_insensitive: !0,
    disableAutodetect: !1,
    keywords: {
      keyword: [
        "query",
        "mutation",
        "subscription",
        "type",
        "input",
        "schema",
        "directive",
        "interface",
        "union",
        "scalar",
        "fragment",
        "enum",
        "on"
      ],
      literal: [
        "true",
        "false",
        "null"
      ]
    },
    contains: [
      t.HASH_COMMENT_MODE,
      t.QUOTE_STRING_MODE,
      t.NUMBER_MODE,
      {
        scope: "punctuation",
        match: /[.]{3}/,
        relevance: 0
      },
      {
        scope: "punctuation",
        begin: /[\!\(\)\:\=\[\]\{\|\}]{1}/,
        relevance: 0
      },
      {
        scope: "variable",
        begin: /\$/,
        end: /\W/,
        excludeEnd: !0,
        relevance: 0
      },
      {
        scope: "meta",
        match: /@\w+/,
        excludeEnd: !0
      },
      {
        scope: "symbol",
        begin: e.concat(n, e.lookahead(/\s*:/)),
        relevance: 0
      }
    ],
    illegal: [
      /[;<']/,
      /BEGIN/
    ]
  };
}
function oC(t) {
  const e = t.regex, n = {
    className: "number",
    relevance: 0,
    variants: [
      { begin: /([+-]+)?[\d]+_[\d_]+/ },
      { begin: t.NUMBER_RE }
    ]
  }, r = t.COMMENT();
  r.variants = [
    {
      begin: /;/,
      end: /$/
    },
    {
      begin: /#/,
      end: /$/
    }
  ];
  const i = {
    className: "variable",
    variants: [
      { begin: /\$[\w\d"][\w\d_]*/ },
      { begin: /\$\{(.*?)\}/ }
    ]
  }, s = {
    className: "literal",
    begin: /\bon|off|true|false|yes|no\b/
  }, o = {
    className: "string",
    contains: [t.BACKSLASH_ESCAPE],
    variants: [
      {
        begin: "'''",
        end: "'''",
        relevance: 10
      },
      {
        begin: '"""',
        end: '"""',
        relevance: 10
      },
      {
        begin: '"',
        end: '"'
      },
      {
        begin: "'",
        end: "'"
      }
    ]
  }, a = {
    begin: /\[/,
    end: /\]/,
    contains: [
      r,
      s,
      i,
      o,
      n,
      "self"
    ],
    relevance: 0
  }, l = /[A-Za-z0-9_-]+/, c = /"(\\"|[^"])*"/, d = /'[^']*'/, u = e.either(
    l,
    c,
    d
  ), f = e.concat(
    u,
    "(\\s*\\.\\s*",
    u,
    ")*",
    e.lookahead(/\s*=\s*[^#\s]/)
  );
  return {
    name: "TOML, also INI",
    aliases: ["toml"],
    case_insensitive: !0,
    illegal: /\S/,
    contains: [
      r,
      {
        className: "section",
        begin: /\[+/,
        end: /\]+/
      },
      {
        begin: f,
        className: "attr",
        starts: {
          end: /$/,
          contains: [
            r,
            a,
            s,
            i,
            o,
            n
          ]
        }
      }
    ]
  };
}
var or = "[0-9](_*[0-9])*", Pi = `\\.(${or})`, $i = "[0-9a-fA-F](_*[0-9a-fA-F])*", Wd = {
  className: "number",
  variants: [
    // DecimalFloatingPointLiteral
    // including ExponentPart
    { begin: `(\\b(${or})((${Pi})|\\.)?|(${Pi}))[eE][+-]?(${or})[fFdD]?\\b` },
    // excluding ExponentPart
    { begin: `\\b(${or})((${Pi})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
    { begin: `(${Pi})[fFdD]?\\b` },
    { begin: `\\b(${or})[fFdD]\\b` },
    // HexadecimalFloatingPointLiteral
    { begin: `\\b0[xX]((${$i})\\.?|(${$i})?\\.(${$i}))[pP][+-]?(${or})[fFdD]?\\b` },
    // DecimalIntegerLiteral
    { begin: "\\b(0|[1-9](_*[0-9])*)[lL]?\\b" },
    // HexIntegerLiteral
    { begin: `\\b0[xX](${$i})[lL]?\\b` },
    // OctalIntegerLiteral
    { begin: "\\b0(_*[0-7])*[lL]?\\b" },
    // BinaryIntegerLiteral
    { begin: "\\b0[bB][01](_*[01])*[lL]?\\b" }
  ],
  relevance: 0
};
function Lp(t, e, n) {
  return n === -1 ? "" : t.replace(e, (r) => Lp(t, e, n - 1));
}
function aC(t) {
  const e = t.regex, n = "[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*", r = n + Lp("(?:<" + n + "~~~(?:\\s*,\\s*" + n + "~~~)*>)?", /~~~/g, 2), l = {
    keyword: [
      "synchronized",
      "abstract",
      "private",
      "var",
      "static",
      "if",
      "const ",
      "for",
      "while",
      "strictfp",
      "finally",
      "protected",
      "import",
      "native",
      "final",
      "void",
      "enum",
      "else",
      "break",
      "transient",
      "catch",
      "instanceof",
      "volatile",
      "case",
      "assert",
      "package",
      "default",
      "public",
      "try",
      "switch",
      "continue",
      "throws",
      "protected",
      "public",
      "private",
      "module",
      "requires",
      "exports",
      "do",
      "sealed",
      "yield",
      "permits"
    ],
    literal: [
      "false",
      "true",
      "null"
    ],
    type: [
      "char",
      "boolean",
      "long",
      "float",
      "int",
      "byte",
      "short",
      "double"
    ],
    built_in: [
      "super",
      "this"
    ]
  }, c = {
    className: "meta",
    begin: "@" + n,
    contains: [
      {
        begin: /\(/,
        end: /\)/,
        contains: ["self"]
        // allow nested () inside our annotation
      }
    ]
  }, d = {
    className: "params",
    begin: /\(/,
    end: /\)/,
    keywords: l,
    relevance: 0,
    contains: [t.C_BLOCK_COMMENT_MODE],
    endsParent: !0
  };
  return {
    name: "Java",
    aliases: ["jsp"],
    keywords: l,
    illegal: /<\/|#/,
    contains: [
      t.COMMENT(
        "/\\*\\*",
        "\\*/",
        {
          relevance: 0,
          contains: [
            {
              // eat up @'s in emails to prevent them to be recognized as doctags
              begin: /\w+@/,
              relevance: 0
            },
            {
              className: "doctag",
              begin: "@[A-Za-z]+"
            }
          ]
        }
      ),
      // relevance boost
      {
        begin: /import java\.[a-z]+\./,
        keywords: "import",
        relevance: 2
      },
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      {
        begin: /"""/,
        end: /"""/,
        className: "string",
        contains: [t.BACKSLASH_ESCAPE]
      },
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE,
      {
        match: [
          /\b(?:class|interface|enum|extends|implements|new)/,
          /\s+/,
          n
        ],
        className: {
          1: "keyword",
          3: "title.class"
        }
      },
      {
        // Exceptions for hyphenated keywords
        match: /non-sealed/,
        scope: "keyword"
      },
      {
        begin: [
          e.concat(/(?!else)/, n),
          /\s+/,
          n,
          /\s+/,
          /=(?!=)/
        ],
        className: {
          1: "type",
          3: "variable",
          5: "operator"
        }
      },
      {
        begin: [
          /record/,
          /\s+/,
          n
        ],
        className: {
          1: "keyword",
          3: "title.class"
        },
        contains: [
          d,
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      {
        // Expression keywords prevent 'keyword Name(...)' from being
        // recognized as a function definition
        beginKeywords: "new throw return else",
        relevance: 0
      },
      {
        begin: [
          "(?:" + r + "\\s+)",
          t.UNDERSCORE_IDENT_RE,
          /\s*(?=\()/
        ],
        className: { 2: "title.function" },
        keywords: l,
        contains: [
          {
            className: "params",
            begin: /\(/,
            end: /\)/,
            keywords: l,
            relevance: 0,
            contains: [
              c,
              t.APOS_STRING_MODE,
              t.QUOTE_STRING_MODE,
              Wd,
              t.C_BLOCK_COMMENT_MODE
            ]
          },
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      Wd,
      c
    ]
  };
}
const qd = "[A-Za-z$_][0-9A-Za-z$_]*", lC = [
  "as",
  // for exports
  "in",
  "of",
  "if",
  "for",
  "while",
  "finally",
  "var",
  "new",
  "function",
  "do",
  "return",
  "void",
  "else",
  "break",
  "catch",
  "instanceof",
  "with",
  "throw",
  "case",
  "default",
  "try",
  "switch",
  "continue",
  "typeof",
  "delete",
  "let",
  "yield",
  "const",
  "class",
  // JS handles these with a special rule
  // "get",
  // "set",
  "debugger",
  "async",
  "await",
  "static",
  "import",
  "from",
  "export",
  "extends"
], cC = [
  "true",
  "false",
  "null",
  "undefined",
  "NaN",
  "Infinity"
], Ip = [
  // Fundamental objects
  "Object",
  "Function",
  "Boolean",
  "Symbol",
  // numbers and dates
  "Math",
  "Date",
  "Number",
  "BigInt",
  // text
  "String",
  "RegExp",
  // Indexed collections
  "Array",
  "Float32Array",
  "Float64Array",
  "Int8Array",
  "Uint8Array",
  "Uint8ClampedArray",
  "Int16Array",
  "Int32Array",
  "Uint16Array",
  "Uint32Array",
  "BigInt64Array",
  "BigUint64Array",
  // Keyed collections
  "Set",
  "Map",
  "WeakSet",
  "WeakMap",
  // Structured data
  "ArrayBuffer",
  "SharedArrayBuffer",
  "Atomics",
  "DataView",
  "JSON",
  // Control abstraction objects
  "Promise",
  "Generator",
  "GeneratorFunction",
  "AsyncFunction",
  // Reflection
  "Reflect",
  "Proxy",
  // Internationalization
  "Intl",
  // WebAssembly
  "WebAssembly"
], Dp = [
  "Error",
  "EvalError",
  "InternalError",
  "RangeError",
  "ReferenceError",
  "SyntaxError",
  "TypeError",
  "URIError"
], Hp = [
  "setInterval",
  "setTimeout",
  "clearInterval",
  "clearTimeout",
  "require",
  "exports",
  "eval",
  "isFinite",
  "isNaN",
  "parseFloat",
  "parseInt",
  "decodeURI",
  "decodeURIComponent",
  "encodeURI",
  "encodeURIComponent",
  "escape",
  "unescape"
], dC = [
  "arguments",
  "this",
  "super",
  "console",
  "window",
  "document",
  "localStorage",
  "sessionStorage",
  "module",
  "global"
  // Node.js
], uC = [].concat(
  Hp,
  Ip,
  Dp
);
function fC(t) {
  const e = t.regex, n = (S, { after: O }) => {
    const D = "</" + S[0].slice(1);
    return S.input.indexOf(D, O) !== -1;
  }, r = qd, i = {
    begin: "<>",
    end: "</>"
  }, s = /<[A-Za-z0-9\\._:-]+\s*\/>/, o = {
    begin: /<[A-Za-z0-9\\._:-]+/,
    end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
    /**
     * @param {RegExpMatchArray} match
     * @param {CallbackResponse} response
     */
    isTrulyOpeningTag: (S, O) => {
      const D = S[0].length + S.index, F = S.input[D];
      if (
        // HTML should not include another raw `<` inside a tag
        // nested type?
        // `<Array<Array<number>>`, etc.
        F === "<" || // the , gives away that this is not HTML
        // `<T, A extends keyof T, V>`
        F === ","
      ) {
        O.ignoreMatch();
        return;
      }
      F === ">" && (n(S, { after: D }) || O.ignoreMatch());
      let Q;
      const ue = S.input.substring(D);
      if (Q = ue.match(/^\s*=/)) {
        O.ignoreMatch();
        return;
      }
      if ((Q = ue.match(/^\s+extends\s+/)) && Q.index === 0) {
        O.ignoreMatch();
        return;
      }
    }
  }, a = {
    $pattern: qd,
    keyword: lC,
    literal: cC,
    built_in: uC,
    "variable.language": dC
  }, l = "[0-9](_?[0-9])*", c = `\\.(${l})`, d = "0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*", u = {
    className: "number",
    variants: [
      // DecimalLiteral
      { begin: `(\\b(${d})((${c})|\\.)?|(${c}))[eE][+-]?(${l})\\b` },
      { begin: `\\b(${d})\\b((${c})\\b|\\.)?|(${c})\\b` },
      // DecimalBigIntegerLiteral
      { begin: "\\b(0|[1-9](_?[0-9])*)n\\b" },
      // NonDecimalIntegerLiteral
      { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
      { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
      { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
      // LegacyOctalIntegerLiteral (does not include underscore separators)
      // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
      { begin: "\\b0[0-7]+n?\\b" }
    ],
    relevance: 0
  }, f = {
    className: "subst",
    begin: "\\$\\{",
    end: "\\}",
    keywords: a,
    contains: []
    // defined later
  }, p = {
    begin: "html`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "xml"
    }
  }, h = {
    begin: "css`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "css"
    }
  }, m = {
    begin: "gql`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "graphql"
    }
  }, g = {
    className: "string",
    begin: "`",
    end: "`",
    contains: [
      t.BACKSLASH_ESCAPE,
      f
    ]
  }, y = {
    className: "comment",
    variants: [
      t.COMMENT(
        /\/\*\*(?!\/)/,
        "\\*/",
        {
          relevance: 0,
          contains: [
            {
              begin: "(?=@[A-Za-z]+)",
              relevance: 0,
              contains: [
                {
                  className: "doctag",
                  begin: "@[A-Za-z]+"
                },
                {
                  className: "type",
                  begin: "\\{",
                  end: "\\}",
                  excludeEnd: !0,
                  excludeBegin: !0,
                  relevance: 0
                },
                {
                  className: "variable",
                  begin: r + "(?=\\s*(-)|$)",
                  endsParent: !0,
                  relevance: 0
                },
                // eat spaces (not newlines) so we can find
                // types or variables
                {
                  begin: /(?=[^\n])\s/,
                  relevance: 0
                }
              ]
            }
          ]
        }
      ),
      t.C_BLOCK_COMMENT_MODE,
      t.C_LINE_COMMENT_MODE
    ]
  }, E = [
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE,
    p,
    h,
    m,
    g,
    // Skip numbers when they are part of a variable name
    { match: /\$\d+/ },
    u
    // This is intentional:
    // See https://github.com/highlightjs/highlight.js/issues/3288
    // hljs.REGEXP_MODE
  ];
  f.contains = E.concat({
    // we need to pair up {} inside our subst to prevent
    // it from ending too early by matching another }
    begin: /\{/,
    end: /\}/,
    keywords: a,
    contains: [
      "self"
    ].concat(E)
  });
  const b = [].concat(y, f.contains), C = b.concat([
    // eat recursive parens in sub expressions
    {
      begin: /\(/,
      end: /\)/,
      keywords: a,
      contains: ["self"].concat(b)
    }
  ]), w = {
    className: "params",
    begin: /\(/,
    end: /\)/,
    excludeBegin: !0,
    excludeEnd: !0,
    keywords: a,
    contains: C
  }, _ = {
    variants: [
      // class Car extends vehicle
      {
        match: [
          /class/,
          /\s+/,
          r,
          /\s+/,
          /extends/,
          /\s+/,
          e.concat(r, "(", e.concat(/\./, r), ")*")
        ],
        scope: {
          1: "keyword",
          3: "title.class",
          5: "keyword",
          7: "title.class.inherited"
        }
      },
      // class Car
      {
        match: [
          /class/,
          /\s+/,
          r
        ],
        scope: {
          1: "keyword",
          3: "title.class"
        }
      }
    ]
  }, R = {
    relevance: 0,
    match: e.either(
      // Hard coded exceptions
      /\bJSON/,
      // Float32Array, OutT
      /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
      // CSSFactory, CSSFactoryT
      /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
      // FPs, FPsT
      /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
      // P
      // single letters are not highlighted
      // BLAH
      // this will be flagged as a UPPER_CASE_CONSTANT instead
    ),
    className: "title.class",
    keywords: {
      _: [
        // se we still get relevance credit for JS library classes
        ...Ip,
        ...Dp
      ]
    }
  }, k = {
    label: "use_strict",
    className: "meta",
    relevance: 10,
    begin: /^\s*['"]use (strict|asm)['"]/
  }, $ = {
    variants: [
      {
        match: [
          /function/,
          /\s+/,
          r,
          /(?=\s*\()/
        ]
      },
      // anonymous function
      {
        match: [
          /function/,
          /\s*(?=\()/
        ]
      }
    ],
    className: {
      1: "keyword",
      3: "title.function"
    },
    label: "func.def",
    contains: [w],
    illegal: /%/
  }, Z = {
    relevance: 0,
    match: /\b[A-Z][A-Z_0-9]+\b/,
    className: "variable.constant"
  };
  function j(S) {
    return e.concat("(?!", S.join("|"), ")");
  }
  const J = {
    match: e.concat(
      /\b/,
      j([
        ...Hp,
        "super",
        "import"
      ]),
      r,
      e.lookahead(/\(/)
    ),
    className: "title.function",
    relevance: 0
  }, X = {
    begin: e.concat(/\./, e.lookahead(
      e.concat(r, /(?![0-9A-Za-z$_(])/)
    )),
    end: r,
    excludeBegin: !0,
    keywords: "prototype",
    className: "property",
    relevance: 0
  }, re = {
    match: [
      /get|set/,
      /\s+/,
      r,
      /(?=\()/
    ],
    className: {
      1: "keyword",
      3: "title.function"
    },
    contains: [
      {
        // eat to avoid empty params
        begin: /\(\)/
      },
      w
    ]
  }, T = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + t.UNDERSCORE_IDENT_RE + ")\\s*=>", x = {
    match: [
      /const|var|let/,
      /\s+/,
      r,
      /\s*/,
      /=\s*/,
      /(async\s*)?/,
      // async is optional
      e.lookahead(T)
    ],
    keywords: "async",
    className: {
      1: "keyword",
      3: "title.function"
    },
    contains: [
      w
    ]
  };
  return {
    name: "JavaScript",
    aliases: ["js", "jsx", "mjs", "cjs"],
    keywords: a,
    // this will be extended by TypeScript
    exports: { PARAMS_CONTAINS: C, CLASS_REFERENCE: R },
    illegal: /#(?![$_A-z])/,
    contains: [
      t.SHEBANG({
        label: "shebang",
        binary: "node",
        relevance: 5
      }),
      k,
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE,
      p,
      h,
      m,
      g,
      y,
      // Skip numbers when they are part of a variable name
      { match: /\$\d+/ },
      u,
      R,
      {
        className: "attr",
        begin: r + e.lookahead(":"),
        relevance: 0
      },
      x,
      {
        // "value" container
        begin: "(" + t.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
        keywords: "return throw case",
        relevance: 0,
        contains: [
          y,
          t.REGEXP_MODE,
          {
            className: "function",
            // we have to count the parens to make sure we actually have the
            // correct bounding ( ) before the =>.  There could be any number of
            // sub-expressions inside also surrounded by parens.
            begin: T,
            returnBegin: !0,
            end: "\\s*=>",
            contains: [
              {
                className: "params",
                variants: [
                  {
                    begin: t.UNDERSCORE_IDENT_RE,
                    relevance: 0
                  },
                  {
                    className: null,
                    begin: /\(\s*\)/,
                    skip: !0
                  },
                  {
                    begin: /\(/,
                    end: /\)/,
                    excludeBegin: !0,
                    excludeEnd: !0,
                    keywords: a,
                    contains: C
                  }
                ]
              }
            ]
          },
          {
            // could be a comma delimited list of params to a function call
            begin: /,/,
            relevance: 0
          },
          {
            match: /\s+/,
            relevance: 0
          },
          {
            // JSX
            variants: [
              { begin: i.begin, end: i.end },
              { match: s },
              {
                begin: o.begin,
                // we carefully check the opening tag to see if it truly
                // is a tag and not a false positive
                "on:begin": o.isTrulyOpeningTag,
                end: o.end
              }
            ],
            subLanguage: "xml",
            contains: [
              {
                begin: o.begin,
                end: o.end,
                skip: !0,
                contains: ["self"]
              }
            ]
          }
        ]
      },
      $,
      {
        // prevent this from getting swallowed up by function
        // since they appear "function like"
        beginKeywords: "while if switch catch for"
      },
      {
        // we have to count the parens to make sure we actually have the correct
        // bounding ( ).  There could be any number of sub-expressions inside
        // also surrounded by parens.
        begin: "\\b(?!function)" + t.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
        // end parens
        returnBegin: !0,
        label: "func.def",
        contains: [
          w,
          t.inherit(t.TITLE_MODE, { begin: r, className: "title.function" })
        ]
      },
      // catch ... so it won't trigger the property rule below
      {
        match: /\.\.\./,
        relevance: 0
      },
      X,
      // hack: prevents detection of keywords in some circumstances
      // .keyword()
      // $keyword = x
      {
        match: "\\$" + r,
        relevance: 0
      },
      {
        match: [/\bconstructor(?=\s*\()/],
        className: { 1: "title.function" },
        contains: [w]
      },
      J,
      Z,
      _,
      re,
      {
        match: /\$[(.]/
        // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
      }
    ]
  };
}
function pC(t) {
  const e = {
    className: "attr",
    begin: /"(\\.|[^\\"\r\n])*"(?=\s*:)/,
    relevance: 1.01
  }, n = {
    match: /[{}[\],:]/,
    className: "punctuation",
    relevance: 0
  }, r = [
    "true",
    "false",
    "null"
  ], i = {
    scope: "literal",
    beginKeywords: r.join(" ")
  };
  return {
    name: "JSON",
    keywords: {
      literal: r
    },
    contains: [
      e,
      n,
      t.QUOTE_STRING_MODE,
      i,
      t.C_NUMBER_MODE,
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE
    ],
    illegal: "\\S"
  };
}
var ar = "[0-9](_*[0-9])*", Vi = `\\.(${ar})`, zi = "[0-9a-fA-F](_*[0-9a-fA-F])*", hC = {
  className: "number",
  variants: [
    // DecimalFloatingPointLiteral
    // including ExponentPart
    { begin: `(\\b(${ar})((${Vi})|\\.)?|(${Vi}))[eE][+-]?(${ar})[fFdD]?\\b` },
    // excluding ExponentPart
    { begin: `\\b(${ar})((${Vi})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
    { begin: `(${Vi})[fFdD]?\\b` },
    { begin: `\\b(${ar})[fFdD]\\b` },
    // HexadecimalFloatingPointLiteral
    { begin: `\\b0[xX]((${zi})\\.?|(${zi})?\\.(${zi}))[pP][+-]?(${ar})[fFdD]?\\b` },
    // DecimalIntegerLiteral
    { begin: "\\b(0|[1-9](_*[0-9])*)[lL]?\\b" },
    // HexIntegerLiteral
    { begin: `\\b0[xX](${zi})[lL]?\\b` },
    // OctalIntegerLiteral
    { begin: "\\b0(_*[0-7])*[lL]?\\b" },
    // BinaryIntegerLiteral
    { begin: "\\b0[bB][01](_*[01])*[lL]?\\b" }
  ],
  relevance: 0
};
function mC(t) {
  const e = {
    keyword: "abstract as val var vararg get set class object open private protected public noinline crossinline dynamic final enum if else do while for when throw try catch finally import package is in fun override companion reified inline lateinit init interface annotation data sealed internal infix operator out by constructor super tailrec where const inner suspend typealias external expect actual",
    built_in: "Byte Short Char Int Long Boolean Float Double Void Unit Nothing",
    literal: "true false null"
  }, n = {
    className: "keyword",
    begin: /\b(break|continue|return|this)\b/,
    starts: { contains: [
      {
        className: "symbol",
        begin: /@\w+/
      }
    ] }
  }, r = {
    className: "symbol",
    begin: t.UNDERSCORE_IDENT_RE + "@"
  }, i = {
    className: "subst",
    begin: /\$\{/,
    end: /\}/,
    contains: [t.C_NUMBER_MODE]
  }, s = {
    className: "variable",
    begin: "\\$" + t.UNDERSCORE_IDENT_RE
  }, o = {
    className: "string",
    variants: [
      {
        begin: '"""',
        end: '"""(?=[^"])',
        contains: [
          s,
          i
        ]
      },
      // Can't use built-in modes easily, as we want to use STRING in the meta
      // context as 'meta-string' and there's no syntax to remove explicitly set
      // classNames in built-in modes.
      {
        begin: "'",
        end: "'",
        illegal: /\n/,
        contains: [t.BACKSLASH_ESCAPE]
      },
      {
        begin: '"',
        end: '"',
        illegal: /\n/,
        contains: [
          t.BACKSLASH_ESCAPE,
          s,
          i
        ]
      }
    ]
  };
  i.contains.push(o);
  const a = {
    className: "meta",
    begin: "@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*" + t.UNDERSCORE_IDENT_RE + ")?"
  }, l = {
    className: "meta",
    begin: "@" + t.UNDERSCORE_IDENT_RE,
    contains: [
      {
        begin: /\(/,
        end: /\)/,
        contains: [
          t.inherit(o, { className: "string" }),
          "self"
        ]
      }
    ]
  }, c = hC, d = t.COMMENT(
    "/\\*",
    "\\*/",
    { contains: [t.C_BLOCK_COMMENT_MODE] }
  ), u = { variants: [
    {
      className: "type",
      begin: t.UNDERSCORE_IDENT_RE
    },
    {
      begin: /\(/,
      end: /\)/,
      contains: []
      // defined later
    }
  ] }, f = u;
  return f.variants[1].contains = [u], u.variants[1].contains = [f], {
    name: "Kotlin",
    aliases: [
      "kt",
      "kts"
    ],
    keywords: e,
    contains: [
      t.COMMENT(
        "/\\*\\*",
        "\\*/",
        {
          relevance: 0,
          contains: [
            {
              className: "doctag",
              begin: "@[A-Za-z]+"
            }
          ]
        }
      ),
      t.C_LINE_COMMENT_MODE,
      d,
      n,
      r,
      a,
      l,
      {
        className: "function",
        beginKeywords: "fun",
        end: "[(]|$",
        returnBegin: !0,
        excludeEnd: !0,
        keywords: e,
        relevance: 5,
        contains: [
          {
            begin: t.UNDERSCORE_IDENT_RE + "\\s*\\(",
            returnBegin: !0,
            relevance: 0,
            contains: [t.UNDERSCORE_TITLE_MODE]
          },
          {
            className: "type",
            begin: /</,
            end: />/,
            keywords: "reified",
            relevance: 0
          },
          {
            className: "params",
            begin: /\(/,
            end: /\)/,
            endsParent: !0,
            keywords: e,
            relevance: 0,
            contains: [
              {
                begin: /:/,
                end: /[=,\/]/,
                endsWithParent: !0,
                contains: [
                  u,
                  t.C_LINE_COMMENT_MODE,
                  d
                ],
                relevance: 0
              },
              t.C_LINE_COMMENT_MODE,
              d,
              a,
              l,
              o,
              t.C_NUMBER_MODE
            ]
          },
          d
        ]
      },
      {
        begin: [
          /class|interface|trait/,
          /\s+/,
          t.UNDERSCORE_IDENT_RE
        ],
        beginScope: {
          3: "title.class"
        },
        keywords: "class interface trait",
        end: /[:\{(]|$/,
        excludeEnd: !0,
        illegal: "extends implements",
        contains: [
          { beginKeywords: "public protected internal private constructor" },
          t.UNDERSCORE_TITLE_MODE,
          {
            className: "type",
            begin: /</,
            end: />/,
            excludeBegin: !0,
            excludeEnd: !0,
            relevance: 0
          },
          {
            className: "type",
            begin: /[,:]\s*/,
            end: /[<\(,){\s]|$/,
            excludeBegin: !0,
            returnEnd: !0
          },
          a,
          l
        ]
      },
      o,
      {
        className: "meta",
        begin: "^#!/usr/bin/env",
        end: "$",
        illegal: `
`
      },
      c
    ]
  };
}
const gC = (t) => ({
  IMPORTANT: {
    scope: "meta",
    begin: "!important"
  },
  BLOCK_COMMENT: t.C_BLOCK_COMMENT_MODE,
  HEXCOLOR: {
    scope: "number",
    begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
  },
  FUNCTION_DISPATCH: {
    className: "built_in",
    begin: /[\w-]+(?=\()/
  },
  ATTRIBUTE_SELECTOR_MODE: {
    scope: "selector-attr",
    begin: /\[/,
    end: /\]/,
    illegal: "$",
    contains: [
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE
    ]
  },
  CSS_NUMBER_MODE: {
    scope: "number",
    begin: t.NUMBER_RE + "(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",
    relevance: 0
  },
  CSS_VARIABLE: {
    className: "attr",
    begin: /--[A-Za-z_][A-Za-z0-9_-]*/
  }
}), bC = [
  "a",
  "abbr",
  "address",
  "article",
  "aside",
  "audio",
  "b",
  "blockquote",
  "body",
  "button",
  "canvas",
  "caption",
  "cite",
  "code",
  "dd",
  "del",
  "details",
  "dfn",
  "div",
  "dl",
  "dt",
  "em",
  "fieldset",
  "figcaption",
  "figure",
  "footer",
  "form",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "header",
  "hgroup",
  "html",
  "i",
  "iframe",
  "img",
  "input",
  "ins",
  "kbd",
  "label",
  "legend",
  "li",
  "main",
  "mark",
  "menu",
  "nav",
  "object",
  "ol",
  "p",
  "q",
  "quote",
  "samp",
  "section",
  "span",
  "strong",
  "summary",
  "sup",
  "table",
  "tbody",
  "td",
  "textarea",
  "tfoot",
  "th",
  "thead",
  "time",
  "tr",
  "ul",
  "var",
  "video"
], yC = [
  "any-hover",
  "any-pointer",
  "aspect-ratio",
  "color",
  "color-gamut",
  "color-index",
  "device-aspect-ratio",
  "device-height",
  "device-width",
  "display-mode",
  "forced-colors",
  "grid",
  "height",
  "hover",
  "inverted-colors",
  "monochrome",
  "orientation",
  "overflow-block",
  "overflow-inline",
  "pointer",
  "prefers-color-scheme",
  "prefers-contrast",
  "prefers-reduced-motion",
  "prefers-reduced-transparency",
  "resolution",
  "scan",
  "scripting",
  "update",
  "width",
  // TODO: find a better solution?
  "min-width",
  "max-width",
  "min-height",
  "max-height"
], Bp = [
  "active",
  "any-link",
  "blank",
  "checked",
  "current",
  "default",
  "defined",
  "dir",
  // dir()
  "disabled",
  "drop",
  "empty",
  "enabled",
  "first",
  "first-child",
  "first-of-type",
  "fullscreen",
  "future",
  "focus",
  "focus-visible",
  "focus-within",
  "has",
  // has()
  "host",
  // host or host()
  "host-context",
  // host-context()
  "hover",
  "indeterminate",
  "in-range",
  "invalid",
  "is",
  // is()
  "lang",
  // lang()
  "last-child",
  "last-of-type",
  "left",
  "link",
  "local-link",
  "not",
  // not()
  "nth-child",
  // nth-child()
  "nth-col",
  // nth-col()
  "nth-last-child",
  // nth-last-child()
  "nth-last-col",
  // nth-last-col()
  "nth-last-of-type",
  //nth-last-of-type()
  "nth-of-type",
  //nth-of-type()
  "only-child",
  "only-of-type",
  "optional",
  "out-of-range",
  "past",
  "placeholder-shown",
  "read-only",
  "read-write",
  "required",
  "right",
  "root",
  "scope",
  "target",
  "target-within",
  "user-invalid",
  "valid",
  "visited",
  "where"
  // where()
], Pp = [
  "after",
  "backdrop",
  "before",
  "cue",
  "cue-region",
  "first-letter",
  "first-line",
  "grammar-error",
  "marker",
  "part",
  "placeholder",
  "selection",
  "slotted",
  "spelling-error"
], vC = [
  "align-content",
  "align-items",
  "align-self",
  "all",
  "animation",
  "animation-delay",
  "animation-direction",
  "animation-duration",
  "animation-fill-mode",
  "animation-iteration-count",
  "animation-name",
  "animation-play-state",
  "animation-timing-function",
  "backface-visibility",
  "background",
  "background-attachment",
  "background-blend-mode",
  "background-clip",
  "background-color",
  "background-image",
  "background-origin",
  "background-position",
  "background-repeat",
  "background-size",
  "block-size",
  "border",
  "border-block",
  "border-block-color",
  "border-block-end",
  "border-block-end-color",
  "border-block-end-style",
  "border-block-end-width",
  "border-block-start",
  "border-block-start-color",
  "border-block-start-style",
  "border-block-start-width",
  "border-block-style",
  "border-block-width",
  "border-bottom",
  "border-bottom-color",
  "border-bottom-left-radius",
  "border-bottom-right-radius",
  "border-bottom-style",
  "border-bottom-width",
  "border-collapse",
  "border-color",
  "border-image",
  "border-image-outset",
  "border-image-repeat",
  "border-image-slice",
  "border-image-source",
  "border-image-width",
  "border-inline",
  "border-inline-color",
  "border-inline-end",
  "border-inline-end-color",
  "border-inline-end-style",
  "border-inline-end-width",
  "border-inline-start",
  "border-inline-start-color",
  "border-inline-start-style",
  "border-inline-start-width",
  "border-inline-style",
  "border-inline-width",
  "border-left",
  "border-left-color",
  "border-left-style",
  "border-left-width",
  "border-radius",
  "border-right",
  "border-right-color",
  "border-right-style",
  "border-right-width",
  "border-spacing",
  "border-style",
  "border-top",
  "border-top-color",
  "border-top-left-radius",
  "border-top-right-radius",
  "border-top-style",
  "border-top-width",
  "border-width",
  "bottom",
  "box-decoration-break",
  "box-shadow",
  "box-sizing",
  "break-after",
  "break-before",
  "break-inside",
  "caption-side",
  "caret-color",
  "clear",
  "clip",
  "clip-path",
  "clip-rule",
  "color",
  "column-count",
  "column-fill",
  "column-gap",
  "column-rule",
  "column-rule-color",
  "column-rule-style",
  "column-rule-width",
  "column-span",
  "column-width",
  "columns",
  "contain",
  "content",
  "content-visibility",
  "counter-increment",
  "counter-reset",
  "cue",
  "cue-after",
  "cue-before",
  "cursor",
  "direction",
  "display",
  "empty-cells",
  "filter",
  "flex",
  "flex-basis",
  "flex-direction",
  "flex-flow",
  "flex-grow",
  "flex-shrink",
  "flex-wrap",
  "float",
  "flow",
  "font",
  "font-display",
  "font-family",
  "font-feature-settings",
  "font-kerning",
  "font-language-override",
  "font-size",
  "font-size-adjust",
  "font-smoothing",
  "font-stretch",
  "font-style",
  "font-synthesis",
  "font-variant",
  "font-variant-caps",
  "font-variant-east-asian",
  "font-variant-ligatures",
  "font-variant-numeric",
  "font-variant-position",
  "font-variation-settings",
  "font-weight",
  "gap",
  "glyph-orientation-vertical",
  "grid",
  "grid-area",
  "grid-auto-columns",
  "grid-auto-flow",
  "grid-auto-rows",
  "grid-column",
  "grid-column-end",
  "grid-column-start",
  "grid-gap",
  "grid-row",
  "grid-row-end",
  "grid-row-start",
  "grid-template",
  "grid-template-areas",
  "grid-template-columns",
  "grid-template-rows",
  "hanging-punctuation",
  "height",
  "hyphens",
  "icon",
  "image-orientation",
  "image-rendering",
  "image-resolution",
  "ime-mode",
  "inline-size",
  "isolation",
  "justify-content",
  "left",
  "letter-spacing",
  "line-break",
  "line-height",
  "list-style",
  "list-style-image",
  "list-style-position",
  "list-style-type",
  "margin",
  "margin-block",
  "margin-block-end",
  "margin-block-start",
  "margin-bottom",
  "margin-inline",
  "margin-inline-end",
  "margin-inline-start",
  "margin-left",
  "margin-right",
  "margin-top",
  "marks",
  "mask",
  "mask-border",
  "mask-border-mode",
  "mask-border-outset",
  "mask-border-repeat",
  "mask-border-slice",
  "mask-border-source",
  "mask-border-width",
  "mask-clip",
  "mask-composite",
  "mask-image",
  "mask-mode",
  "mask-origin",
  "mask-position",
  "mask-repeat",
  "mask-size",
  "mask-type",
  "max-block-size",
  "max-height",
  "max-inline-size",
  "max-width",
  "min-block-size",
  "min-height",
  "min-inline-size",
  "min-width",
  "mix-blend-mode",
  "nav-down",
  "nav-index",
  "nav-left",
  "nav-right",
  "nav-up",
  "none",
  "normal",
  "object-fit",
  "object-position",
  "opacity",
  "order",
  "orphans",
  "outline",
  "outline-color",
  "outline-offset",
  "outline-style",
  "outline-width",
  "overflow",
  "overflow-wrap",
  "overflow-x",
  "overflow-y",
  "padding",
  "padding-block",
  "padding-block-end",
  "padding-block-start",
  "padding-bottom",
  "padding-inline",
  "padding-inline-end",
  "padding-inline-start",
  "padding-left",
  "padding-right",
  "padding-top",
  "page-break-after",
  "page-break-before",
  "page-break-inside",
  "pause",
  "pause-after",
  "pause-before",
  "perspective",
  "perspective-origin",
  "pointer-events",
  "position",
  "quotes",
  "resize",
  "rest",
  "rest-after",
  "rest-before",
  "right",
  "row-gap",
  "scroll-margin",
  "scroll-margin-block",
  "scroll-margin-block-end",
  "scroll-margin-block-start",
  "scroll-margin-bottom",
  "scroll-margin-inline",
  "scroll-margin-inline-end",
  "scroll-margin-inline-start",
  "scroll-margin-left",
  "scroll-margin-right",
  "scroll-margin-top",
  "scroll-padding",
  "scroll-padding-block",
  "scroll-padding-block-end",
  "scroll-padding-block-start",
  "scroll-padding-bottom",
  "scroll-padding-inline",
  "scroll-padding-inline-end",
  "scroll-padding-inline-start",
  "scroll-padding-left",
  "scroll-padding-right",
  "scroll-padding-top",
  "scroll-snap-align",
  "scroll-snap-stop",
  "scroll-snap-type",
  "scrollbar-color",
  "scrollbar-gutter",
  "scrollbar-width",
  "shape-image-threshold",
  "shape-margin",
  "shape-outside",
  "speak",
  "speak-as",
  "src",
  // @font-face
  "tab-size",
  "table-layout",
  "text-align",
  "text-align-all",
  "text-align-last",
  "text-combine-upright",
  "text-decoration",
  "text-decoration-color",
  "text-decoration-line",
  "text-decoration-style",
  "text-emphasis",
  "text-emphasis-color",
  "text-emphasis-position",
  "text-emphasis-style",
  "text-indent",
  "text-justify",
  "text-orientation",
  "text-overflow",
  "text-rendering",
  "text-shadow",
  "text-transform",
  "text-underline-position",
  "top",
  "transform",
  "transform-box",
  "transform-origin",
  "transform-style",
  "transition",
  "transition-delay",
  "transition-duration",
  "transition-property",
  "transition-timing-function",
  "unicode-bidi",
  "vertical-align",
  "visibility",
  "voice-balance",
  "voice-duration",
  "voice-family",
  "voice-pitch",
  "voice-range",
  "voice-rate",
  "voice-stress",
  "voice-volume",
  "white-space",
  "widows",
  "width",
  "will-change",
  "word-break",
  "word-spacing",
  "word-wrap",
  "writing-mode",
  "z-index"
  // reverse makes sure longer attributes `font-weight` are matched fully
  // instead of getting false positives on say `font`
].reverse(), wC = Bp.concat(Pp);
function EC(t) {
  const e = gC(t), n = wC, r = "and or not only", i = "[\\w-]+", s = "(" + i + "|@\\{" + i + "\\})", o = [], a = [], l = function(E) {
    return {
      // Less strings are not multiline (also include '~' for more consistent coloring of "escaped" strings)
      className: "string",
      begin: "~?" + E + ".*?" + E
    };
  }, c = function(E, b, C) {
    return {
      className: E,
      begin: b,
      relevance: C
    };
  }, d = {
    $pattern: /[a-z-]+/,
    keyword: r,
    attribute: yC.join(" ")
  }, u = {
    // used only to properly balance nested parens inside mixin call, def. arg list
    begin: "\\(",
    end: "\\)",
    contains: a,
    keywords: d,
    relevance: 0
  };
  a.push(
    t.C_LINE_COMMENT_MODE,
    t.C_BLOCK_COMMENT_MODE,
    l("'"),
    l('"'),
    e.CSS_NUMBER_MODE,
    // fixme: it does not include dot for numbers like .5em :(
    {
      begin: "(url|data-uri)\\(",
      starts: {
        className: "string",
        end: "[\\)\\n]",
        excludeEnd: !0
      }
    },
    e.HEXCOLOR,
    u,
    c("variable", "@@?" + i, 10),
    c("variable", "@\\{" + i + "\\}"),
    c("built_in", "~?`[^`]*?`"),
    // inline javascript (or whatever host language) *multiline* string
    {
      // @media features (it’s here to not duplicate things in AT_RULE_MODE with extra PARENS_MODE overriding):
      className: "attribute",
      begin: i + "\\s*:",
      end: ":",
      returnBegin: !0,
      excludeEnd: !0
    },
    e.IMPORTANT,
    { beginKeywords: "and not" },
    e.FUNCTION_DISPATCH
  );
  const f = a.concat({
    begin: /\{/,
    end: /\}/,
    contains: o
  }), p = {
    beginKeywords: "when",
    endsWithParent: !0,
    contains: [{ beginKeywords: "and not" }].concat(a)
    // using this form to override VALUE’s 'function' match
  }, h = {
    begin: s + "\\s*:",
    returnBegin: !0,
    end: /[;}]/,
    relevance: 0,
    contains: [
      { begin: /-(webkit|moz|ms|o)-/ },
      e.CSS_VARIABLE,
      {
        className: "attribute",
        begin: "\\b(" + vC.join("|") + ")\\b",
        end: /(?=:)/,
        starts: {
          endsWithParent: !0,
          illegal: "[<=$]",
          relevance: 0,
          contains: a
        }
      }
    ]
  }, m = {
    className: "keyword",
    begin: "@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b",
    starts: {
      end: "[;{}]",
      keywords: d,
      returnEnd: !0,
      contains: a,
      relevance: 0
    }
  }, g = {
    className: "variable",
    variants: [
      // using more strict pattern for higher relevance to increase chances of Less detection.
      // this is *the only* Less specific statement used in most of the sources, so...
      // (we’ll still often loose to the css-parser unless there's '//' comment,
      // simply because 1 variable just can't beat 99 properties :)
      {
        begin: "@" + i + "\\s*:",
        relevance: 15
      },
      { begin: "@" + i }
    ],
    starts: {
      end: "[;}]",
      returnEnd: !0,
      contains: f
    }
  }, v = {
    // first parse unambiguous selectors (i.e. those not starting with tag)
    // then fall into the scary lookahead-discriminator variant.
    // this mode also handles mixin definitions and calls
    variants: [
      {
        begin: "[\\.#:&\\[>]",
        end: "[;{}]"
        // mixin calls end with ';'
      },
      {
        begin: s,
        end: /\{/
      }
    ],
    returnBegin: !0,
    returnEnd: !0,
    illegal: `[<='$"]`,
    relevance: 0,
    contains: [
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      p,
      c("keyword", "all\\b"),
      c("variable", "@\\{" + i + "\\}"),
      // otherwise it’s identified as tag
      {
        begin: "\\b(" + bC.join("|") + ")\\b",
        className: "selector-tag"
      },
      e.CSS_NUMBER_MODE,
      c("selector-tag", s, 0),
      c("selector-id", "#" + s),
      c("selector-class", "\\." + s, 0),
      c("selector-tag", "&", 0),
      e.ATTRIBUTE_SELECTOR_MODE,
      {
        className: "selector-pseudo",
        begin: ":(" + Bp.join("|") + ")"
      },
      {
        className: "selector-pseudo",
        begin: ":(:)?(" + Pp.join("|") + ")"
      },
      {
        begin: /\(/,
        end: /\)/,
        relevance: 0,
        contains: f
      },
      // argument list of parametric mixins
      { begin: "!important" },
      // eat !important after mixin call or it will be colored as tag
      e.FUNCTION_DISPATCH
    ]
  }, y = {
    begin: i + `:(:)?(${n.join("|")})`,
    returnBegin: !0,
    contains: [v]
  };
  return o.push(
    t.C_LINE_COMMENT_MODE,
    t.C_BLOCK_COMMENT_MODE,
    m,
    g,
    y,
    h,
    v,
    p,
    e.FUNCTION_DISPATCH
  ), {
    name: "Less",
    case_insensitive: !0,
    illegal: `[=>'/<($"]`,
    contains: o
  };
}
function xC(t) {
  const e = "\\[=*\\[", n = "\\]=*\\]", r = {
    begin: e,
    end: n,
    contains: ["self"]
  }, i = [
    t.COMMENT("--(?!" + e + ")", "$"),
    t.COMMENT(
      "--" + e,
      n,
      {
        contains: [r],
        relevance: 10
      }
    )
  ];
  return {
    name: "Lua",
    keywords: {
      $pattern: t.UNDERSCORE_IDENT_RE,
      literal: "true false nil",
      keyword: "and break do else elseif end for goto if in local not or repeat return then until while",
      built_in: (
        // Metatags and globals:
        "_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring module next pairs pcall print rawequal rawget rawset require select setfenv setmetatable tonumber tostring type unpack xpcall arg self coroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"
      )
    },
    contains: i.concat([
      {
        className: "function",
        beginKeywords: "function",
        end: "\\)",
        contains: [
          t.inherit(t.TITLE_MODE, { begin: "([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*" }),
          {
            className: "params",
            begin: "\\(",
            endsWithParent: !0,
            contains: i
          }
        ].concat(i)
      },
      t.C_NUMBER_MODE,
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE,
      {
        className: "string",
        begin: e,
        end: n,
        contains: [r],
        relevance: 5
      }
    ])
  };
}
function SC(t) {
  const e = {
    className: "variable",
    variants: [
      {
        begin: "\\$\\(" + t.UNDERSCORE_IDENT_RE + "\\)",
        contains: [t.BACKSLASH_ESCAPE]
      },
      { begin: /\$[@%<?\^\+\*]/ }
    ]
  }, n = {
    className: "string",
    begin: /"/,
    end: /"/,
    contains: [
      t.BACKSLASH_ESCAPE,
      e
    ]
  }, r = {
    className: "variable",
    begin: /\$\([\w-]+\s/,
    end: /\)/,
    keywords: { built_in: "subst patsubst strip findstring filter filter-out sort word wordlist firstword lastword dir notdir suffix basename addsuffix addprefix join wildcard realpath abspath error warning shell origin flavor foreach if or and call eval file value" },
    contains: [e]
  }, i = { begin: "^" + t.UNDERSCORE_IDENT_RE + "\\s*(?=[:+?]?=)" }, s = {
    className: "meta",
    begin: /^\.PHONY:/,
    end: /$/,
    keywords: {
      $pattern: /[\.\w]+/,
      keyword: ".PHONY"
    }
  }, o = {
    className: "section",
    begin: /^[^\s]+:/,
    end: /$/,
    contains: [e]
  };
  return {
    name: "Makefile",
    aliases: [
      "mk",
      "mak",
      "make"
    ],
    keywords: {
      $pattern: /[\w-]+/,
      keyword: "define endef undefine ifdef ifndef ifeq ifneq else endif include -include sinclude override export unexport private vpath"
    },
    contains: [
      t.HASH_COMMENT_MODE,
      e,
      n,
      r,
      i,
      s,
      o
    ]
  };
}
function CC(t) {
  const e = t.regex, n = {
    begin: /<\/?[A-Za-z_]/,
    end: ">",
    subLanguage: "xml",
    relevance: 0
  }, r = {
    begin: "^[-\\*]{3,}",
    end: "$"
  }, i = {
    className: "code",
    variants: [
      // TODO: fix to allow these to work with sublanguage also
      { begin: "(`{3,})[^`](.|\\n)*?\\1`*[ ]*" },
      { begin: "(~{3,})[^~](.|\\n)*?\\1~*[ ]*" },
      // needed to allow markdown as a sublanguage to work
      {
        begin: "```",
        end: "```+[ ]*$"
      },
      {
        begin: "~~~",
        end: "~~~+[ ]*$"
      },
      { begin: "`.+?`" },
      {
        begin: "(?=^( {4}|\\t))",
        // use contains to gobble up multiple lines to allow the block to be whatever size
        // but only have a single open/close tag vs one per line
        contains: [
          {
            begin: "^( {4}|\\t)",
            end: "(\\n)$"
          }
        ],
        relevance: 0
      }
    ]
  }, s = {
    className: "bullet",
    begin: "^[ 	]*([*+-]|(\\d+\\.))(?=\\s+)",
    end: "\\s+",
    excludeEnd: !0
  }, o = {
    begin: /^\[[^\n]+\]:/,
    returnBegin: !0,
    contains: [
      {
        className: "symbol",
        begin: /\[/,
        end: /\]/,
        excludeBegin: !0,
        excludeEnd: !0
      },
      {
        className: "link",
        begin: /:\s*/,
        end: /$/,
        excludeBegin: !0
      }
    ]
  }, a = /[A-Za-z][A-Za-z0-9+.-]*/, l = {
    variants: [
      // too much like nested array access in so many languages
      // to have any real relevance
      {
        begin: /\[.+?\]\[.*?\]/,
        relevance: 0
      },
      // popular internet URLs
      {
        begin: /\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,
        relevance: 2
      },
      {
        begin: e.concat(/\[.+?\]\(/, a, /:\/\/.*?\)/),
        relevance: 2
      },
      // relative urls
      {
        begin: /\[.+?\]\([./?&#].*?\)/,
        relevance: 1
      },
      // whatever else, lower relevance (might not be a link at all)
      {
        begin: /\[.*?\]\(.*?\)/,
        relevance: 0
      }
    ],
    returnBegin: !0,
    contains: [
      {
        // empty strings for alt or link text
        match: /\[(?=\])/
      },
      {
        className: "string",
        relevance: 0,
        begin: "\\[",
        end: "\\]",
        excludeBegin: !0,
        returnEnd: !0
      },
      {
        className: "link",
        relevance: 0,
        begin: "\\]\\(",
        end: "\\)",
        excludeBegin: !0,
        excludeEnd: !0
      },
      {
        className: "symbol",
        relevance: 0,
        begin: "\\]\\[",
        end: "\\]",
        excludeBegin: !0,
        excludeEnd: !0
      }
    ]
  }, c = {
    className: "strong",
    contains: [],
    // defined later
    variants: [
      {
        begin: /_{2}(?!\s)/,
        end: /_{2}/
      },
      {
        begin: /\*{2}(?!\s)/,
        end: /\*{2}/
      }
    ]
  }, d = {
    className: "emphasis",
    contains: [],
    // defined later
    variants: [
      {
        begin: /\*(?![*\s])/,
        end: /\*/
      },
      {
        begin: /_(?![_\s])/,
        end: /_/,
        relevance: 0
      }
    ]
  }, u = t.inherit(c, { contains: [] }), f = t.inherit(d, { contains: [] });
  c.contains.push(f), d.contains.push(u);
  let p = [
    n,
    l
  ];
  return [
    c,
    d,
    u,
    f
  ].forEach((g) => {
    g.contains = g.contains.concat(p);
  }), p = p.concat(c, d), {
    name: "Markdown",
    aliases: [
      "md",
      "mkdown",
      "mkd"
    ],
    contains: [
      {
        className: "section",
        variants: [
          {
            begin: "^#{1,6}",
            end: "$",
            contains: p
          },
          {
            begin: "(?=^.+?\\n[=-]{2,}$)",
            contains: [
              { begin: "^[=-]*$" },
              {
                begin: "^",
                end: "\\n",
                contains: p
              }
            ]
          }
        ]
      },
      n,
      s,
      c,
      d,
      {
        className: "quote",
        begin: "^>\\s+",
        contains: p,
        end: "$"
      },
      i,
      r,
      l,
      o
    ]
  };
}
function MC(t) {
  const e = {
    className: "built_in",
    begin: "\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+"
  }, n = /[a-zA-Z@][a-zA-Z0-9_]*/, a = {
    "variable.language": [
      "this",
      "super"
    ],
    $pattern: n,
    keyword: [
      "while",
      "export",
      "sizeof",
      "typedef",
      "const",
      "struct",
      "for",
      "union",
      "volatile",
      "static",
      "mutable",
      "if",
      "do",
      "return",
      "goto",
      "enum",
      "else",
      "break",
      "extern",
      "asm",
      "case",
      "default",
      "register",
      "explicit",
      "typename",
      "switch",
      "continue",
      "inline",
      "readonly",
      "assign",
      "readwrite",
      "self",
      "@synchronized",
      "id",
      "typeof",
      "nonatomic",
      "IBOutlet",
      "IBAction",
      "strong",
      "weak",
      "copy",
      "in",
      "out",
      "inout",
      "bycopy",
      "byref",
      "oneway",
      "__strong",
      "__weak",
      "__block",
      "__autoreleasing",
      "@private",
      "@protected",
      "@public",
      "@try",
      "@property",
      "@end",
      "@throw",
      "@catch",
      "@finally",
      "@autoreleasepool",
      "@synthesize",
      "@dynamic",
      "@selector",
      "@optional",
      "@required",
      "@encode",
      "@package",
      "@import",
      "@defs",
      "@compatibility_alias",
      "__bridge",
      "__bridge_transfer",
      "__bridge_retained",
      "__bridge_retain",
      "__covariant",
      "__contravariant",
      "__kindof",
      "_Nonnull",
      "_Nullable",
      "_Null_unspecified",
      "__FUNCTION__",
      "__PRETTY_FUNCTION__",
      "__attribute__",
      "getter",
      "setter",
      "retain",
      "unsafe_unretained",
      "nonnull",
      "nullable",
      "null_unspecified",
      "null_resettable",
      "class",
      "instancetype",
      "NS_DESIGNATED_INITIALIZER",
      "NS_UNAVAILABLE",
      "NS_REQUIRES_SUPER",
      "NS_RETURNS_INNER_POINTER",
      "NS_INLINE",
      "NS_AVAILABLE",
      "NS_DEPRECATED",
      "NS_ENUM",
      "NS_OPTIONS",
      "NS_SWIFT_UNAVAILABLE",
      "NS_ASSUME_NONNULL_BEGIN",
      "NS_ASSUME_NONNULL_END",
      "NS_REFINED_FOR_SWIFT",
      "NS_SWIFT_NAME",
      "NS_SWIFT_NOTHROW",
      "NS_DURING",
      "NS_HANDLER",
      "NS_ENDHANDLER",
      "NS_VALUERETURN",
      "NS_VOIDRETURN"
    ],
    literal: [
      "false",
      "true",
      "FALSE",
      "TRUE",
      "nil",
      "YES",
      "NO",
      "NULL"
    ],
    built_in: [
      "dispatch_once_t",
      "dispatch_queue_t",
      "dispatch_sync",
      "dispatch_async",
      "dispatch_once"
    ],
    type: [
      "int",
      "float",
      "char",
      "unsigned",
      "signed",
      "short",
      "long",
      "double",
      "wchar_t",
      "unichar",
      "void",
      "bool",
      "BOOL",
      "id|0",
      "_Bool"
    ]
  }, l = {
    $pattern: n,
    keyword: [
      "@interface",
      "@class",
      "@protocol",
      "@implementation"
    ]
  };
  return {
    name: "Objective-C",
    aliases: [
      "mm",
      "objc",
      "obj-c",
      "obj-c++",
      "objective-c++"
    ],
    keywords: a,
    illegal: "</",
    contains: [
      e,
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      t.C_NUMBER_MODE,
      t.QUOTE_STRING_MODE,
      t.APOS_STRING_MODE,
      {
        className: "string",
        variants: [
          {
            begin: '@"',
            end: '"',
            illegal: "\\n",
            contains: [t.BACKSLASH_ESCAPE]
          }
        ]
      },
      {
        className: "meta",
        begin: /#\s*[a-z]+\b/,
        end: /$/,
        keywords: { keyword: "if else elif endif define undef warning error line pragma ifdef ifndef include" },
        contains: [
          {
            begin: /\\\n/,
            relevance: 0
          },
          t.inherit(t.QUOTE_STRING_MODE, { className: "string" }),
          {
            className: "string",
            begin: /<.*?>/,
            end: /$/,
            illegal: "\\n"
          },
          t.C_LINE_COMMENT_MODE,
          t.C_BLOCK_COMMENT_MODE
        ]
      },
      {
        className: "class",
        begin: "(" + l.keyword.join("|") + ")\\b",
        end: /(\{|$)/,
        excludeEnd: !0,
        keywords: l,
        contains: [t.UNDERSCORE_TITLE_MODE]
      },
      {
        begin: "\\." + t.UNDERSCORE_IDENT_RE,
        relevance: 0
      }
    ]
  };
}
function kC(t) {
  const e = t.regex, n = [
    "abs",
    "accept",
    "alarm",
    "and",
    "atan2",
    "bind",
    "binmode",
    "bless",
    "break",
    "caller",
    "chdir",
    "chmod",
    "chomp",
    "chop",
    "chown",
    "chr",
    "chroot",
    "close",
    "closedir",
    "connect",
    "continue",
    "cos",
    "crypt",
    "dbmclose",
    "dbmopen",
    "defined",
    "delete",
    "die",
    "do",
    "dump",
    "each",
    "else",
    "elsif",
    "endgrent",
    "endhostent",
    "endnetent",
    "endprotoent",
    "endpwent",
    "endservent",
    "eof",
    "eval",
    "exec",
    "exists",
    "exit",
    "exp",
    "fcntl",
    "fileno",
    "flock",
    "for",
    "foreach",
    "fork",
    "format",
    "formline",
    "getc",
    "getgrent",
    "getgrgid",
    "getgrnam",
    "gethostbyaddr",
    "gethostbyname",
    "gethostent",
    "getlogin",
    "getnetbyaddr",
    "getnetbyname",
    "getnetent",
    "getpeername",
    "getpgrp",
    "getpriority",
    "getprotobyname",
    "getprotobynumber",
    "getprotoent",
    "getpwent",
    "getpwnam",
    "getpwuid",
    "getservbyname",
    "getservbyport",
    "getservent",
    "getsockname",
    "getsockopt",
    "given",
    "glob",
    "gmtime",
    "goto",
    "grep",
    "gt",
    "hex",
    "if",
    "index",
    "int",
    "ioctl",
    "join",
    "keys",
    "kill",
    "last",
    "lc",
    "lcfirst",
    "length",
    "link",
    "listen",
    "local",
    "localtime",
    "log",
    "lstat",
    "lt",
    "ma",
    "map",
    "mkdir",
    "msgctl",
    "msgget",
    "msgrcv",
    "msgsnd",
    "my",
    "ne",
    "next",
    "no",
    "not",
    "oct",
    "open",
    "opendir",
    "or",
    "ord",
    "our",
    "pack",
    "package",
    "pipe",
    "pop",
    "pos",
    "print",
    "printf",
    "prototype",
    "push",
    "q|0",
    "qq",
    "quotemeta",
    "qw",
    "qx",
    "rand",
    "read",
    "readdir",
    "readline",
    "readlink",
    "readpipe",
    "recv",
    "redo",
    "ref",
    "rename",
    "require",
    "reset",
    "return",
    "reverse",
    "rewinddir",
    "rindex",
    "rmdir",
    "say",
    "scalar",
    "seek",
    "seekdir",
    "select",
    "semctl",
    "semget",
    "semop",
    "send",
    "setgrent",
    "sethostent",
    "setnetent",
    "setpgrp",
    "setpriority",
    "setprotoent",
    "setpwent",
    "setservent",
    "setsockopt",
    "shift",
    "shmctl",
    "shmget",
    "shmread",
    "shmwrite",
    "shutdown",
    "sin",
    "sleep",
    "socket",
    "socketpair",
    "sort",
    "splice",
    "split",
    "sprintf",
    "sqrt",
    "srand",
    "stat",
    "state",
    "study",
    "sub",
    "substr",
    "symlink",
    "syscall",
    "sysopen",
    "sysread",
    "sysseek",
    "system",
    "syswrite",
    "tell",
    "telldir",
    "tie",
    "tied",
    "time",
    "times",
    "tr",
    "truncate",
    "uc",
    "ucfirst",
    "umask",
    "undef",
    "unless",
    "unlink",
    "unpack",
    "unshift",
    "untie",
    "until",
    "use",
    "utime",
    "values",
    "vec",
    "wait",
    "waitpid",
    "wantarray",
    "warn",
    "when",
    "while",
    "write",
    "x|0",
    "xor",
    "y|0"
  ], r = /[dualxmsipngr]{0,12}/, i = {
    $pattern: /[\w.]+/,
    keyword: n.join(" ")
  }, s = {
    className: "subst",
    begin: "[$@]\\{",
    end: "\\}",
    keywords: i
  }, o = {
    begin: /->\{/,
    end: /\}/
    // contains defined later
  }, a = { variants: [
    { begin: /\$\d/ },
    { begin: e.concat(
      /[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
      // negative look-ahead tries to avoid matching patterns that are not
      // Perl at all like $ident$, @ident@, etc.
      "(?![A-Za-z])(?![@$%])"
    ) },
    {
      begin: /[$%@][^\s\w{]/,
      relevance: 0
    }
  ] }, l = [
    t.BACKSLASH_ESCAPE,
    s,
    a
  ], c = [
    /!/,
    /\//,
    /\|/,
    /\?/,
    /'/,
    /"/,
    // valid but infrequent and weird
    /#/
    // valid but infrequent and weird
  ], d = (p, h, m = "\\1") => {
    const g = m === "\\1" ? m : e.concat(m, h);
    return e.concat(
      e.concat("(?:", p, ")"),
      h,
      /(?:\\.|[^\\\/])*?/,
      g,
      /(?:\\.|[^\\\/])*?/,
      m,
      r
    );
  }, u = (p, h, m) => e.concat(
    e.concat("(?:", p, ")"),
    h,
    /(?:\\.|[^\\\/])*?/,
    m,
    r
  ), f = [
    a,
    t.HASH_COMMENT_MODE,
    t.COMMENT(
      /^=\w/,
      /=cut/,
      { endsWithParent: !0 }
    ),
    o,
    {
      className: "string",
      contains: l,
      variants: [
        {
          begin: "q[qwxr]?\\s*\\(",
          end: "\\)",
          relevance: 5
        },
        {
          begin: "q[qwxr]?\\s*\\[",
          end: "\\]",
          relevance: 5
        },
        {
          begin: "q[qwxr]?\\s*\\{",
          end: "\\}",
          relevance: 5
        },
        {
          begin: "q[qwxr]?\\s*\\|",
          end: "\\|",
          relevance: 5
        },
        {
          begin: "q[qwxr]?\\s*<",
          end: ">",
          relevance: 5
        },
        {
          begin: "qw\\s+q",
          end: "q",
          relevance: 5
        },
        {
          begin: "'",
          end: "'",
          contains: [t.BACKSLASH_ESCAPE]
        },
        {
          begin: '"',
          end: '"'
        },
        {
          begin: "`",
          end: "`",
          contains: [t.BACKSLASH_ESCAPE]
        },
        {
          begin: /\{\w+\}/,
          relevance: 0
        },
        {
          begin: "-?\\w+\\s*=>",
          relevance: 0
        }
      ]
    },
    {
      className: "number",
      begin: "(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",
      relevance: 0
    },
    {
      // regexp container
      begin: "(\\/\\/|" + t.RE_STARTERS_RE + "|\\b(split|return|print|reverse|grep)\\b)\\s*",
      keywords: "split return print reverse grep",
      relevance: 0,
      contains: [
        t.HASH_COMMENT_MODE,
        {
          className: "regexp",
          variants: [
            // allow matching common delimiters
            { begin: d("s|tr|y", e.either(...c, { capture: !0 })) },
            // and then paired delmis
            { begin: d("s|tr|y", "\\(", "\\)") },
            { begin: d("s|tr|y", "\\[", "\\]") },
            { begin: d("s|tr|y", "\\{", "\\}") }
          ],
          relevance: 2
        },
        {
          className: "regexp",
          variants: [
            {
              // could be a comment in many languages so do not count
              // as relevant
              begin: /(m|qr)\/\//,
              relevance: 0
            },
            // prefix is optional with /regex/
            { begin: u("(?:m|qr)?", /\//, /\//) },
            // allow matching common delimiters
            { begin: u("m|qr", e.either(...c, { capture: !0 }), /\1/) },
            // allow common paired delmins
            { begin: u("m|qr", /\(/, /\)/) },
            { begin: u("m|qr", /\[/, /\]/) },
            { begin: u("m|qr", /\{/, /\}/) }
          ]
        }
      ]
    },
    {
      className: "function",
      beginKeywords: "sub",
      end: "(\\s*\\(.*?\\))?[;{]",
      excludeEnd: !0,
      relevance: 5,
      contains: [t.TITLE_MODE]
    },
    {
      begin: "-\\w\\b",
      relevance: 0
    },
    {
      begin: "^__DATA__$",
      end: "^__END__$",
      subLanguage: "mojolicious",
      contains: [
        {
          begin: "^@@.*",
          end: "$",
          className: "comment"
        }
      ]
    }
  ];
  return s.contains = f, o.contains = f, {
    name: "Perl",
    aliases: [
      "pl",
      "pm"
    ],
    keywords: i,
    contains: f
  };
}
function TC(t) {
  const e = t.regex, n = /(?![A-Za-z0-9])(?![$])/, r = e.concat(
    /[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/,
    n
  ), i = e.concat(
    /(\\?[A-Z][a-z0-9_\x7f-\xff]+|\\?[A-Z]+(?=[A-Z][a-z0-9_\x7f-\xff])){1,}/,
    n
  ), s = {
    scope: "variable",
    match: "\\$+" + r
  }, o = {
    scope: "meta",
    variants: [
      { begin: /<\?php/, relevance: 10 },
      // boost for obvious PHP
      { begin: /<\?=/ },
      // less relevant per PSR-1 which says not to use short-tags
      { begin: /<\?/, relevance: 0.1 },
      { begin: /\?>/ }
      // end php tag
    ]
  }, a = {
    scope: "subst",
    variants: [
      { begin: /\$\w+/ },
      {
        begin: /\{\$/,
        end: /\}/
      }
    ]
  }, l = t.inherit(t.APOS_STRING_MODE, { illegal: null }), c = t.inherit(t.QUOTE_STRING_MODE, {
    illegal: null,
    contains: t.QUOTE_STRING_MODE.contains.concat(a)
  }), d = {
    begin: /<<<[ \t]*(?:(\w+)|"(\w+)")\n/,
    end: /[ \t]*(\w+)\b/,
    contains: t.QUOTE_STRING_MODE.contains.concat(a),
    "on:begin": (J, X) => {
      X.data._beginMatch = J[1] || J[2];
    },
    "on:end": (J, X) => {
      X.data._beginMatch !== J[1] && X.ignoreMatch();
    }
  }, u = t.END_SAME_AS_BEGIN({
    begin: /<<<[ \t]*'(\w+)'\n/,
    end: /[ \t]*(\w+)\b/
  }), f = `[ 	
]`, p = {
    scope: "string",
    variants: [
      c,
      l,
      d,
      u
    ]
  }, h = {
    scope: "number",
    variants: [
      { begin: "\\b0[bB][01]+(?:_[01]+)*\\b" },
      // Binary w/ underscore support
      { begin: "\\b0[oO][0-7]+(?:_[0-7]+)*\\b" },
      // Octals w/ underscore support
      { begin: "\\b0[xX][\\da-fA-F]+(?:_[\\da-fA-F]+)*\\b" },
      // Hex w/ underscore support
      // Decimals w/ underscore support, with optional fragments and scientific exponent (e) suffix.
      { begin: "(?:\\b\\d+(?:_\\d+)*(\\.(?:\\d+(?:_\\d+)*))?|\\B\\.\\d+)(?:[eE][+-]?\\d+)?" }
    ],
    relevance: 0
  }, m = [
    "false",
    "null",
    "true"
  ], g = [
    // Magic constants:
    // <https://www.php.net/manual/en/language.constants.predefined.php>
    "__CLASS__",
    "__DIR__",
    "__FILE__",
    "__FUNCTION__",
    "__COMPILER_HALT_OFFSET__",
    "__LINE__",
    "__METHOD__",
    "__NAMESPACE__",
    "__TRAIT__",
    // Function that look like language construct or language construct that look like function:
    // List of keywords that may not require parenthesis
    "die",
    "echo",
    "exit",
    "include",
    "include_once",
    "print",
    "require",
    "require_once",
    // These are not language construct (function) but operate on the currently-executing function and can access the current symbol table
    // 'compact extract func_get_arg func_get_args func_num_args get_called_class get_parent_class ' +
    // Other keywords:
    // <https://www.php.net/manual/en/reserved.php>
    // <https://www.php.net/manual/en/language.types.type-juggling.php>
    "array",
    "abstract",
    "and",
    "as",
    "binary",
    "bool",
    "boolean",
    "break",
    "callable",
    "case",
    "catch",
    "class",
    "clone",
    "const",
    "continue",
    "declare",
    "default",
    "do",
    "double",
    "else",
    "elseif",
    "empty",
    "enddeclare",
    "endfor",
    "endforeach",
    "endif",
    "endswitch",
    "endwhile",
    "enum",
    "eval",
    "extends",
    "final",
    "finally",
    "float",
    "for",
    "foreach",
    "from",
    "global",
    "goto",
    "if",
    "implements",
    "instanceof",
    "insteadof",
    "int",
    "integer",
    "interface",
    "isset",
    "iterable",
    "list",
    "match|0",
    "mixed",
    "new",
    "never",
    "object",
    "or",
    "private",
    "protected",
    "public",
    "readonly",
    "real",
    "return",
    "string",
    "switch",
    "throw",
    "trait",
    "try",
    "unset",
    "use",
    "var",
    "void",
    "while",
    "xor",
    "yield"
  ], v = [
    // Standard PHP library:
    // <https://www.php.net/manual/en/book.spl.php>
    "Error|0",
    "AppendIterator",
    "ArgumentCountError",
    "ArithmeticError",
    "ArrayIterator",
    "ArrayObject",
    "AssertionError",
    "BadFunctionCallException",
    "BadMethodCallException",
    "CachingIterator",
    "CallbackFilterIterator",
    "CompileError",
    "Countable",
    "DirectoryIterator",
    "DivisionByZeroError",
    "DomainException",
    "EmptyIterator",
    "ErrorException",
    "Exception",
    "FilesystemIterator",
    "FilterIterator",
    "GlobIterator",
    "InfiniteIterator",
    "InvalidArgumentException",
    "IteratorIterator",
    "LengthException",
    "LimitIterator",
    "LogicException",
    "MultipleIterator",
    "NoRewindIterator",
    "OutOfBoundsException",
    "OutOfRangeException",
    "OuterIterator",
    "OverflowException",
    "ParentIterator",
    "ParseError",
    "RangeException",
    "RecursiveArrayIterator",
    "RecursiveCachingIterator",
    "RecursiveCallbackFilterIterator",
    "RecursiveDirectoryIterator",
    "RecursiveFilterIterator",
    "RecursiveIterator",
    "RecursiveIteratorIterator",
    "RecursiveRegexIterator",
    "RecursiveTreeIterator",
    "RegexIterator",
    "RuntimeException",
    "SeekableIterator",
    "SplDoublyLinkedList",
    "SplFileInfo",
    "SplFileObject",
    "SplFixedArray",
    "SplHeap",
    "SplMaxHeap",
    "SplMinHeap",
    "SplObjectStorage",
    "SplObserver",
    "SplPriorityQueue",
    "SplQueue",
    "SplStack",
    "SplSubject",
    "SplTempFileObject",
    "TypeError",
    "UnderflowException",
    "UnexpectedValueException",
    "UnhandledMatchError",
    // Reserved interfaces:
    // <https://www.php.net/manual/en/reserved.interfaces.php>
    "ArrayAccess",
    "BackedEnum",
    "Closure",
    "Fiber",
    "Generator",
    "Iterator",
    "IteratorAggregate",
    "Serializable",
    "Stringable",
    "Throwable",
    "Traversable",
    "UnitEnum",
    "WeakReference",
    "WeakMap",
    // Reserved classes:
    // <https://www.php.net/manual/en/reserved.classes.php>
    "Directory",
    "__PHP_Incomplete_Class",
    "parent",
    "php_user_filter",
    "self",
    "static",
    "stdClass"
  ], E = {
    keyword: g,
    literal: ((J) => {
      const X = [];
      return J.forEach((re) => {
        X.push(re), re.toLowerCase() === re ? X.push(re.toUpperCase()) : X.push(re.toLowerCase());
      }), X;
    })(m),
    built_in: v
  }, b = (J) => J.map((X) => X.replace(/\|\d+$/, "")), C = { variants: [
    {
      match: [
        /new/,
        e.concat(f, "+"),
        // to prevent built ins from being confused as the class constructor call
        e.concat("(?!", b(v).join("\\b|"), "\\b)"),
        i
      ],
      scope: {
        1: "keyword",
        4: "title.class"
      }
    }
  ] }, w = e.concat(r, "\\b(?!\\()"), _ = { variants: [
    {
      match: [
        e.concat(
          /::/,
          e.lookahead(/(?!class\b)/)
        ),
        w
      ],
      scope: { 2: "variable.constant" }
    },
    {
      match: [
        /::/,
        /class/
      ],
      scope: { 2: "variable.language" }
    },
    {
      match: [
        i,
        e.concat(
          /::/,
          e.lookahead(/(?!class\b)/)
        ),
        w
      ],
      scope: {
        1: "title.class",
        3: "variable.constant"
      }
    },
    {
      match: [
        i,
        e.concat(
          "::",
          e.lookahead(/(?!class\b)/)
        )
      ],
      scope: { 1: "title.class" }
    },
    {
      match: [
        i,
        /::/,
        /class/
      ],
      scope: {
        1: "title.class",
        3: "variable.language"
      }
    }
  ] }, R = {
    scope: "attr",
    match: e.concat(r, e.lookahead(":"), e.lookahead(/(?!::)/))
  }, k = {
    relevance: 0,
    begin: /\(/,
    end: /\)/,
    keywords: E,
    contains: [
      R,
      s,
      _,
      t.C_BLOCK_COMMENT_MODE,
      p,
      h,
      C
    ]
  }, $ = {
    relevance: 0,
    match: [
      /\b/,
      // to prevent keywords from being confused as the function title
      e.concat("(?!fn\\b|function\\b|", b(g).join("\\b|"), "|", b(v).join("\\b|"), "\\b)"),
      r,
      e.concat(f, "*"),
      e.lookahead(/(?=\()/)
    ],
    scope: { 3: "title.function.invoke" },
    contains: [k]
  };
  k.contains.push($);
  const Z = [
    R,
    _,
    t.C_BLOCK_COMMENT_MODE,
    p,
    h,
    C
  ], j = {
    begin: e.concat(/#\[\s*/, i),
    beginScope: "meta",
    end: /]/,
    endScope: "meta",
    keywords: {
      literal: m,
      keyword: [
        "new",
        "array"
      ]
    },
    contains: [
      {
        begin: /\[/,
        end: /]/,
        keywords: {
          literal: m,
          keyword: [
            "new",
            "array"
          ]
        },
        contains: [
          "self",
          ...Z
        ]
      },
      ...Z,
      {
        scope: "meta",
        match: i
      }
    ]
  };
  return {
    case_insensitive: !1,
    keywords: E,
    contains: [
      j,
      t.HASH_COMMENT_MODE,
      t.COMMENT("//", "$"),
      t.COMMENT(
        "/\\*",
        "\\*/",
        { contains: [
          {
            scope: "doctag",
            match: "@[A-Za-z]+"
          }
        ] }
      ),
      {
        match: /__halt_compiler\(\);/,
        keywords: "__halt_compiler",
        starts: {
          scope: "comment",
          end: t.MATCH_NOTHING_RE,
          contains: [
            {
              match: /\?>/,
              scope: "meta",
              endsParent: !0
            }
          ]
        }
      },
      o,
      {
        scope: "variable.language",
        match: /\$this\b/
      },
      s,
      $,
      _,
      {
        match: [
          /const/,
          /\s/,
          r
        ],
        scope: {
          1: "keyword",
          3: "variable.constant"
        }
      },
      C,
      {
        scope: "function",
        relevance: 0,
        beginKeywords: "fn function",
        end: /[;{]/,
        excludeEnd: !0,
        illegal: "[$%\\[]",
        contains: [
          { beginKeywords: "use" },
          t.UNDERSCORE_TITLE_MODE,
          {
            begin: "=>",
            // No markup, just a relevance booster
            endsParent: !0
          },
          {
            scope: "params",
            begin: "\\(",
            end: "\\)",
            excludeBegin: !0,
            excludeEnd: !0,
            keywords: E,
            contains: [
              "self",
              s,
              _,
              t.C_BLOCK_COMMENT_MODE,
              p,
              h
            ]
          }
        ]
      },
      {
        scope: "class",
        variants: [
          {
            beginKeywords: "enum",
            illegal: /[($"]/
          },
          {
            beginKeywords: "class interface trait",
            illegal: /[:($"]/
          }
        ],
        relevance: 0,
        end: /\{/,
        excludeEnd: !0,
        contains: [
          { beginKeywords: "extends implements" },
          t.UNDERSCORE_TITLE_MODE
        ]
      },
      // both use and namespace still use "old style" rules (vs multi-match)
      // because the namespace name can include `\` and we still want each
      // element to be treated as its own *individual* title
      {
        beginKeywords: "namespace",
        relevance: 0,
        end: ";",
        illegal: /[.']/,
        contains: [t.inherit(t.UNDERSCORE_TITLE_MODE, { scope: "title.class" })]
      },
      {
        beginKeywords: "use",
        relevance: 0,
        end: ";",
        contains: [
          // TODO: title.function vs title.class
          {
            match: /\b(as|const|function)\b/,
            scope: "keyword"
          },
          // TODO: could be title.class or title.function
          t.UNDERSCORE_TITLE_MODE
        ]
      },
      p,
      h
    ]
  };
}
function _C(t) {
  return {
    name: "PHP template",
    subLanguage: "xml",
    contains: [
      {
        begin: /<\?(php|=)?/,
        end: /\?>/,
        subLanguage: "php",
        contains: [
          // We don't want the php closing tag ?> to close the PHP block when
          // inside any of the following blocks:
          {
            begin: "/\\*",
            end: "\\*/",
            skip: !0
          },
          {
            begin: 'b"',
            end: '"',
            skip: !0
          },
          {
            begin: "b'",
            end: "'",
            skip: !0
          },
          t.inherit(t.APOS_STRING_MODE, {
            illegal: null,
            className: null,
            contains: null,
            skip: !0
          }),
          t.inherit(t.QUOTE_STRING_MODE, {
            illegal: null,
            className: null,
            contains: null,
            skip: !0
          })
        ]
      }
    ]
  };
}
function NC(t) {
  return {
    name: "Plain text",
    aliases: [
      "text",
      "txt"
    ],
    disableAutodetect: !0
  };
}
function AC(t) {
  const e = t.regex, n = /[\p{XID_Start}_]\p{XID_Continue}*/u, r = [
    "and",
    "as",
    "assert",
    "async",
    "await",
    "break",
    "case",
    "class",
    "continue",
    "def",
    "del",
    "elif",
    "else",
    "except",
    "finally",
    "for",
    "from",
    "global",
    "if",
    "import",
    "in",
    "is",
    "lambda",
    "match",
    "nonlocal|10",
    "not",
    "or",
    "pass",
    "raise",
    "return",
    "try",
    "while",
    "with",
    "yield"
  ], a = {
    $pattern: /[A-Za-z]\w+|__\w+__/,
    keyword: r,
    built_in: [
      "__import__",
      "abs",
      "all",
      "any",
      "ascii",
      "bin",
      "bool",
      "breakpoint",
      "bytearray",
      "bytes",
      "callable",
      "chr",
      "classmethod",
      "compile",
      "complex",
      "delattr",
      "dict",
      "dir",
      "divmod",
      "enumerate",
      "eval",
      "exec",
      "filter",
      "float",
      "format",
      "frozenset",
      "getattr",
      "globals",
      "hasattr",
      "hash",
      "help",
      "hex",
      "id",
      "input",
      "int",
      "isinstance",
      "issubclass",
      "iter",
      "len",
      "list",
      "locals",
      "map",
      "max",
      "memoryview",
      "min",
      "next",
      "object",
      "oct",
      "open",
      "ord",
      "pow",
      "print",
      "property",
      "range",
      "repr",
      "reversed",
      "round",
      "set",
      "setattr",
      "slice",
      "sorted",
      "staticmethod",
      "str",
      "sum",
      "super",
      "tuple",
      "type",
      "vars",
      "zip"
    ],
    literal: [
      "__debug__",
      "Ellipsis",
      "False",
      "None",
      "NotImplemented",
      "True"
    ],
    type: [
      "Any",
      "Callable",
      "Coroutine",
      "Dict",
      "List",
      "Literal",
      "Generic",
      "Optional",
      "Sequence",
      "Set",
      "Tuple",
      "Type",
      "Union"
    ]
  }, l = {
    className: "meta",
    begin: /^(>>>|\.\.\.) /
  }, c = {
    className: "subst",
    begin: /\{/,
    end: /\}/,
    keywords: a,
    illegal: /#/
  }, d = {
    begin: /\{\{/,
    relevance: 0
  }, u = {
    className: "string",
    contains: [t.BACKSLASH_ESCAPE],
    variants: [
      {
        begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,
        end: /'''/,
        contains: [
          t.BACKSLASH_ESCAPE,
          l
        ],
        relevance: 10
      },
      {
        begin: /([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,
        end: /"""/,
        contains: [
          t.BACKSLASH_ESCAPE,
          l
        ],
        relevance: 10
      },
      {
        begin: /([fF][rR]|[rR][fF]|[fF])'''/,
        end: /'''/,
        contains: [
          t.BACKSLASH_ESCAPE,
          l,
          d,
          c
        ]
      },
      {
        begin: /([fF][rR]|[rR][fF]|[fF])"""/,
        end: /"""/,
        contains: [
          t.BACKSLASH_ESCAPE,
          l,
          d,
          c
        ]
      },
      {
        begin: /([uU]|[rR])'/,
        end: /'/,
        relevance: 10
      },
      {
        begin: /([uU]|[rR])"/,
        end: /"/,
        relevance: 10
      },
      {
        begin: /([bB]|[bB][rR]|[rR][bB])'/,
        end: /'/
      },
      {
        begin: /([bB]|[bB][rR]|[rR][bB])"/,
        end: /"/
      },
      {
        begin: /([fF][rR]|[rR][fF]|[fF])'/,
        end: /'/,
        contains: [
          t.BACKSLASH_ESCAPE,
          d,
          c
        ]
      },
      {
        begin: /([fF][rR]|[rR][fF]|[fF])"/,
        end: /"/,
        contains: [
          t.BACKSLASH_ESCAPE,
          d,
          c
        ]
      },
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE
    ]
  }, f = "[0-9](_?[0-9])*", p = `(\\b(${f}))?\\.(${f})|\\b(${f})\\.`, h = `\\b|${r.join("|")}`, m = {
    className: "number",
    relevance: 0,
    variants: [
      // exponentfloat, pointfloat
      // https://docs.python.org/3.9/reference/lexical_analysis.html#floating-point-literals
      // optionally imaginary
      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
      // Note: no leading \b because floats can start with a decimal point
      // and we don't want to mishandle e.g. `fn(.5)`,
      // no trailing \b for pointfloat because it can end with a decimal point
      // and we don't want to mishandle e.g. `0..hex()`; this should be safe
      // because both MUST contain a decimal point and so cannot be confused with
      // the interior part of an identifier
      {
        begin: `(\\b(${f})|(${p}))[eE][+-]?(${f})[jJ]?(?=${h})`
      },
      {
        begin: `(${p})[jJ]?`
      },
      // decinteger, bininteger, octinteger, hexinteger
      // https://docs.python.org/3.9/reference/lexical_analysis.html#integer-literals
      // optionally "long" in Python 2
      // https://docs.python.org/2.7/reference/lexical_analysis.html#integer-and-long-integer-literals
      // decinteger is optionally imaginary
      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
      {
        begin: `\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?(?=${h})`
      },
      {
        begin: `\\b0[bB](_?[01])+[lL]?(?=${h})`
      },
      {
        begin: `\\b0[oO](_?[0-7])+[lL]?(?=${h})`
      },
      {
        begin: `\\b0[xX](_?[0-9a-fA-F])+[lL]?(?=${h})`
      },
      // imagnumber (digitpart-based)
      // https://docs.python.org/3.9/reference/lexical_analysis.html#imaginary-literals
      {
        begin: `\\b(${f})[jJ](?=${h})`
      }
    ]
  }, g = {
    className: "comment",
    begin: e.lookahead(/# type:/),
    end: /$/,
    keywords: a,
    contains: [
      {
        // prevent keywords from coloring `type`
        begin: /# type:/
      },
      // comment within a datatype comment includes no keywords
      {
        begin: /#/,
        end: /\b\B/,
        endsWithParent: !0
      }
    ]
  }, v = {
    className: "params",
    variants: [
      // Exclude params in functions without params
      {
        className: "",
        begin: /\(\s*\)/,
        skip: !0
      },
      {
        begin: /\(/,
        end: /\)/,
        excludeBegin: !0,
        excludeEnd: !0,
        keywords: a,
        contains: [
          "self",
          l,
          m,
          u,
          t.HASH_COMMENT_MODE
        ]
      }
    ]
  };
  return c.contains = [
    u,
    m,
    l
  ], {
    name: "Python",
    aliases: [
      "py",
      "gyp",
      "ipython"
    ],
    unicodeRegex: !0,
    keywords: a,
    illegal: /(<\/|\?)|=>/,
    contains: [
      l,
      m,
      {
        // very common convention
        begin: /\bself\b/
      },
      {
        // eat "if" prior to string so that it won't accidentally be
        // labeled as an f-string
        beginKeywords: "if",
        relevance: 0
      },
      u,
      g,
      t.HASH_COMMENT_MODE,
      {
        match: [
          /\bdef/,
          /\s+/,
          n
        ],
        scope: {
          1: "keyword",
          3: "title.function"
        },
        contains: [v]
      },
      {
        variants: [
          {
            match: [
              /\bclass/,
              /\s+/,
              n,
              /\s*/,
              /\(\s*/,
              n,
              /\s*\)/
            ]
          },
          {
            match: [
              /\bclass/,
              /\s+/,
              n
            ]
          }
        ],
        scope: {
          1: "keyword",
          3: "title.class",
          6: "title.class.inherited"
        }
      },
      {
        className: "meta",
        begin: /^[\t ]*@/,
        end: /(?=#)|$/,
        contains: [
          m,
          v,
          u
        ]
      }
    ]
  };
}
function OC(t) {
  return {
    aliases: ["pycon"],
    contains: [
      {
        className: "meta.prompt",
        starts: {
          // a space separates the REPL prefix from the actual code
          // this is purely for cleaner HTML output
          end: / |$/,
          starts: {
            end: "$",
            subLanguage: "python"
          }
        },
        variants: [
          { begin: /^>>>(?=[ ]|$)/ },
          { begin: /^\.\.\.(?=[ ]|$)/ }
        ]
      }
    ]
  };
}
function RC(t) {
  const e = t.regex, n = /(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/, r = e.either(
    // Special case: only hexadecimal binary powers can contain fractions
    /0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/,
    // Hexadecimal numbers without fraction and optional binary power
    /0[xX][0-9a-fA-F]+(?:[pP][+-]?\d+)?[Li]?/,
    // Decimal numbers
    /(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[Li]?/
  ), i = /[=!<>:]=|\|\||&&|:::?|<-|<<-|->>|->|\|>|[-+*\/?!$&|:<=>@^~]|\*\*/, s = e.either(
    /[()]/,
    /[{}]/,
    /\[\[/,
    /[[\]]/,
    /\\/,
    /,/
  );
  return {
    name: "R",
    keywords: {
      $pattern: n,
      keyword: "function if in break next repeat else for while",
      literal: "NULL NA TRUE FALSE Inf NaN NA_integer_|10 NA_real_|10 NA_character_|10 NA_complex_|10",
      built_in: (
        // Builtin constants
        "LETTERS letters month.abb month.name pi T F abs acos acosh all any anyNA Arg as.call as.character as.complex as.double as.environment as.integer as.logical as.null.default as.numeric as.raw asin asinh atan atanh attr attributes baseenv browser c call ceiling class Conj cos cosh cospi cummax cummin cumprod cumsum digamma dim dimnames emptyenv exp expression floor forceAndCall gamma gc.time globalenv Im interactive invisible is.array is.atomic is.call is.character is.complex is.double is.environment is.expression is.finite is.function is.infinite is.integer is.language is.list is.logical is.matrix is.na is.name is.nan is.null is.numeric is.object is.pairlist is.raw is.recursive is.single is.symbol lazyLoadDBfetch length lgamma list log max min missing Mod names nargs nzchar oldClass on.exit pos.to.env proc.time prod quote range Re rep retracemem return round seq_along seq_len seq.int sign signif sin sinh sinpi sqrt standardGeneric substitute sum switch tan tanh tanpi tracemem trigamma trunc unclass untracemem UseMethod xtfrm"
      )
    },
    contains: [
      // Roxygen comments
      t.COMMENT(
        /#'/,
        /$/,
        { contains: [
          {
            // Handle `@examples` separately to cause all subsequent code
            // until the next `@`-tag on its own line to be kept as-is,
            // preventing highlighting. This code is example R code, so nested
            // doctags shouldn’t be treated as such. See
            // `test/markup/r/roxygen.txt` for an example.
            scope: "doctag",
            match: /@examples/,
            starts: {
              end: e.lookahead(e.either(
                // end if another doc comment
                /\n^#'\s*(?=@[a-zA-Z]+)/,
                // or a line with no comment
                /\n^(?!#')/
              )),
              endsParent: !0
            }
          },
          {
            // Handle `@param` to highlight the parameter name following
            // after.
            scope: "doctag",
            begin: "@param",
            end: /$/,
            contains: [
              {
                scope: "variable",
                variants: [
                  { match: n },
                  { match: /`(?:\\.|[^`\\])+`/ }
                ],
                endsParent: !0
              }
            ]
          },
          {
            scope: "doctag",
            match: /@[a-zA-Z]+/
          },
          {
            scope: "keyword",
            match: /\\[a-zA-Z]+/
          }
        ] }
      ),
      t.HASH_COMMENT_MODE,
      {
        scope: "string",
        contains: [t.BACKSLASH_ESCAPE],
        variants: [
          t.END_SAME_AS_BEGIN({
            begin: /[rR]"(-*)\(/,
            end: /\)(-*)"/
          }),
          t.END_SAME_AS_BEGIN({
            begin: /[rR]"(-*)\{/,
            end: /\}(-*)"/
          }),
          t.END_SAME_AS_BEGIN({
            begin: /[rR]"(-*)\[/,
            end: /\](-*)"/
          }),
          t.END_SAME_AS_BEGIN({
            begin: /[rR]'(-*)\(/,
            end: /\)(-*)'/
          }),
          t.END_SAME_AS_BEGIN({
            begin: /[rR]'(-*)\{/,
            end: /\}(-*)'/
          }),
          t.END_SAME_AS_BEGIN({
            begin: /[rR]'(-*)\[/,
            end: /\](-*)'/
          }),
          {
            begin: '"',
            end: '"',
            relevance: 0
          },
          {
            begin: "'",
            end: "'",
            relevance: 0
          }
        ]
      },
      // Matching numbers immediately following punctuation and operators is
      // tricky since we need to look at the character ahead of a number to
      // ensure the number is not part of an identifier, and we cannot use
      // negative look-behind assertions. So instead we explicitly handle all
      // possible combinations of (operator|punctuation), number.
      // TODO: replace with negative look-behind when available
      // { begin: /(?<![a-zA-Z0-9._])0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/ },
      // { begin: /(?<![a-zA-Z0-9._])0[xX][0-9a-fA-F]+([pP][+-]?\d+)?[Li]?/ },
      // { begin: /(?<![a-zA-Z0-9._])(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[Li]?/ }
      {
        relevance: 0,
        variants: [
          {
            scope: {
              1: "operator",
              2: "number"
            },
            match: [
              i,
              r
            ]
          },
          {
            scope: {
              1: "operator",
              2: "number"
            },
            match: [
              /%[^%]*%/,
              r
            ]
          },
          {
            scope: {
              1: "punctuation",
              2: "number"
            },
            match: [
              s,
              r
            ]
          },
          {
            scope: { 2: "number" },
            match: [
              /[^a-zA-Z0-9._]|^/,
              // not part of an identifier, or start of document
              r
            ]
          }
        ]
      },
      // Operators/punctuation when they're not directly followed by numbers
      {
        // Relevance boost for the most common assignment form.
        scope: { 3: "operator" },
        match: [
          n,
          /\s+/,
          /<-/,
          /\s+/
        ]
      },
      {
        scope: "operator",
        relevance: 0,
        variants: [
          { match: i },
          { match: /%[^%]*%/ }
        ]
      },
      {
        scope: "punctuation",
        relevance: 0,
        match: s
      },
      {
        // Escaped identifier
        begin: "`",
        end: "`",
        contains: [{ begin: /\\./ }]
      }
    ]
  };
}
function LC(t) {
  const e = t.regex, n = "([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)", r = e.either(
    /\b([A-Z]+[a-z0-9]+)+/,
    // ends in caps
    /\b([A-Z]+[a-z0-9]+)+[A-Z]+/
  ), i = e.concat(r, /(::\w+)*/), o = {
    "variable.constant": [
      "__FILE__",
      "__LINE__",
      "__ENCODING__"
    ],
    "variable.language": [
      "self",
      "super"
    ],
    keyword: [
      "alias",
      "and",
      "begin",
      "BEGIN",
      "break",
      "case",
      "class",
      "defined",
      "do",
      "else",
      "elsif",
      "end",
      "END",
      "ensure",
      "for",
      "if",
      "in",
      "module",
      "next",
      "not",
      "or",
      "redo",
      "require",
      "rescue",
      "retry",
      "return",
      "then",
      "undef",
      "unless",
      "until",
      "when",
      "while",
      "yield",
      ...[
        "include",
        "extend",
        "prepend",
        "public",
        "private",
        "protected",
        "raise",
        "throw"
      ]
    ],
    built_in: [
      "proc",
      "lambda",
      "attr_accessor",
      "attr_reader",
      "attr_writer",
      "define_method",
      "private_constant",
      "module_function"
    ],
    literal: [
      "true",
      "false",
      "nil"
    ]
  }, a = {
    className: "doctag",
    begin: "@[A-Za-z]+"
  }, l = {
    begin: "#<",
    end: ">"
  }, c = [
    t.COMMENT(
      "#",
      "$",
      { contains: [a] }
    ),
    t.COMMENT(
      "^=begin",
      "^=end",
      {
        contains: [a],
        relevance: 10
      }
    ),
    t.COMMENT("^__END__", t.MATCH_NOTHING_RE)
  ], d = {
    className: "subst",
    begin: /#\{/,
    end: /\}/,
    keywords: o
  }, u = {
    className: "string",
    contains: [
      t.BACKSLASH_ESCAPE,
      d
    ],
    variants: [
      {
        begin: /'/,
        end: /'/
      },
      {
        begin: /"/,
        end: /"/
      },
      {
        begin: /`/,
        end: /`/
      },
      {
        begin: /%[qQwWx]?\(/,
        end: /\)/
      },
      {
        begin: /%[qQwWx]?\[/,
        end: /\]/
      },
      {
        begin: /%[qQwWx]?\{/,
        end: /\}/
      },
      {
        begin: /%[qQwWx]?</,
        end: />/
      },
      {
        begin: /%[qQwWx]?\//,
        end: /\//
      },
      {
        begin: /%[qQwWx]?%/,
        end: /%/
      },
      {
        begin: /%[qQwWx]?-/,
        end: /-/
      },
      {
        begin: /%[qQwWx]?\|/,
        end: /\|/
      },
      // in the following expressions, \B in the beginning suppresses recognition of ?-sequences
      // where ? is the last character of a preceding identifier, as in: `func?4`
      { begin: /\B\?(\\\d{1,3})/ },
      { begin: /\B\?(\\x[A-Fa-f0-9]{1,2})/ },
      { begin: /\B\?(\\u\{?[A-Fa-f0-9]{1,6}\}?)/ },
      { begin: /\B\?(\\M-\\C-|\\M-\\c|\\c\\M-|\\M-|\\C-\\M-)[\x20-\x7e]/ },
      { begin: /\B\?\\(c|C-)[\x20-\x7e]/ },
      { begin: /\B\?\\?\S/ },
      // heredocs
      {
        // this guard makes sure that we have an entire heredoc and not a false
        // positive (auto-detect, etc.)
        begin: e.concat(
          /<<[-~]?'?/,
          e.lookahead(/(\w+)(?=\W)[^\n]*\n(?:[^\n]*\n)*?\s*\1\b/)
        ),
        contains: [
          t.END_SAME_AS_BEGIN({
            begin: /(\w+)/,
            end: /(\w+)/,
            contains: [
              t.BACKSLASH_ESCAPE,
              d
            ]
          })
        ]
      }
    ]
  }, f = "[1-9](_?[0-9])*|0", p = "[0-9](_?[0-9])*", h = {
    className: "number",
    relevance: 0,
    variants: [
      // decimal integer/float, optionally exponential or rational, optionally imaginary
      { begin: `\\b(${f})(\\.(${p}))?([eE][+-]?(${p})|r)?i?\\b` },
      // explicit decimal/binary/octal/hexadecimal integer,
      // optionally rational and/or imaginary
      { begin: "\\b0[dD][0-9](_?[0-9])*r?i?\\b" },
      { begin: "\\b0[bB][0-1](_?[0-1])*r?i?\\b" },
      { begin: "\\b0[oO][0-7](_?[0-7])*r?i?\\b" },
      { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*r?i?\\b" },
      // 0-prefixed implicit octal integer, optionally rational and/or imaginary
      { begin: "\\b0(_?[0-7])+r?i?\\b" }
    ]
  }, m = {
    variants: [
      {
        match: /\(\)/
      },
      {
        className: "params",
        begin: /\(/,
        end: /(?=\))/,
        excludeBegin: !0,
        endsParent: !0,
        keywords: o
      }
    ]
  }, w = [
    u,
    {
      variants: [
        {
          match: [
            /class\s+/,
            i,
            /\s+<\s+/,
            i
          ]
        },
        {
          match: [
            /\b(class|module)\s+/,
            i
          ]
        }
      ],
      scope: {
        2: "title.class",
        4: "title.class.inherited"
      },
      keywords: o
    },
    {
      match: [
        /(include|extend)\s+/,
        i
      ],
      scope: {
        2: "title.class"
      },
      keywords: o
    },
    {
      relevance: 0,
      match: [
        i,
        /\.new[. (]/
      ],
      scope: {
        1: "title.class"
      }
    },
    {
      relevance: 0,
      match: /\b[A-Z][A-Z_0-9]+\b/,
      className: "variable.constant"
    },
    {
      relevance: 0,
      match: r,
      scope: "title.class"
    },
    {
      match: [
        /def/,
        /\s+/,
        n
      ],
      scope: {
        1: "keyword",
        3: "title.function"
      },
      contains: [
        m
      ]
    },
    {
      // swallow namespace qualifiers before symbols
      begin: t.IDENT_RE + "::"
    },
    {
      className: "symbol",
      begin: t.UNDERSCORE_IDENT_RE + "(!|\\?)?:",
      relevance: 0
    },
    {
      className: "symbol",
      begin: ":(?!\\s)",
      contains: [
        u,
        { begin: n }
      ],
      relevance: 0
    },
    h,
    {
      // negative-look forward attempts to prevent false matches like:
      // @ident@ or $ident$ that might indicate this is not ruby at all
      className: "variable",
      begin: "(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])(?![A-Za-z])(?![@$?'])"
    },
    {
      className: "params",
      begin: /\|/,
      end: /\|/,
      excludeBegin: !0,
      excludeEnd: !0,
      relevance: 0,
      // this could be a lot of things (in other languages) other than params
      keywords: o
    },
    {
      // regexp container
      begin: "(" + t.RE_STARTERS_RE + "|unless)\\s*",
      keywords: "unless",
      contains: [
        {
          className: "regexp",
          contains: [
            t.BACKSLASH_ESCAPE,
            d
          ],
          illegal: /\n/,
          variants: [
            {
              begin: "/",
              end: "/[a-z]*"
            },
            {
              begin: /%r\{/,
              end: /\}[a-z]*/
            },
            {
              begin: "%r\\(",
              end: "\\)[a-z]*"
            },
            {
              begin: "%r!",
              end: "![a-z]*"
            },
            {
              begin: "%r\\[",
              end: "\\][a-z]*"
            }
          ]
        }
      ].concat(l, c),
      relevance: 0
    }
  ].concat(l, c);
  d.contains = w, m.contains = w;
  const _ = "[>?]>", R = "[\\w#]+\\(\\w+\\):\\d+:\\d+[>*]", k = "(\\w+-)?\\d+\\.\\d+\\.\\d+(p\\d+)?[^\\d][^>]+>", $ = [
    {
      begin: /^\s*=>/,
      starts: {
        end: "$",
        contains: w
      }
    },
    {
      className: "meta.prompt",
      begin: "^(" + _ + "|" + R + "|" + k + ")(?=[ ])",
      starts: {
        end: "$",
        keywords: o,
        contains: w
      }
    }
  ];
  return c.unshift(l), {
    name: "Ruby",
    aliases: [
      "rb",
      "gemspec",
      "podspec",
      "thor",
      "irb"
    ],
    keywords: o,
    illegal: /\/\*/,
    contains: [t.SHEBANG({ binary: "ruby" })].concat($).concat(c).concat(w)
  };
}
function IC(t) {
  const e = t.regex, n = {
    className: "title.function.invoke",
    relevance: 0,
    begin: e.concat(
      /\b/,
      /(?!let|for|while|if|else|match\b)/,
      t.IDENT_RE,
      e.lookahead(/\s*\(/)
    )
  }, r = "([ui](8|16|32|64|128|size)|f(32|64))?", i = [
    "abstract",
    "as",
    "async",
    "await",
    "become",
    "box",
    "break",
    "const",
    "continue",
    "crate",
    "do",
    "dyn",
    "else",
    "enum",
    "extern",
    "false",
    "final",
    "fn",
    "for",
    "if",
    "impl",
    "in",
    "let",
    "loop",
    "macro",
    "match",
    "mod",
    "move",
    "mut",
    "override",
    "priv",
    "pub",
    "ref",
    "return",
    "self",
    "Self",
    "static",
    "struct",
    "super",
    "trait",
    "true",
    "try",
    "type",
    "typeof",
    "unsafe",
    "unsized",
    "use",
    "virtual",
    "where",
    "while",
    "yield"
  ], s = [
    "true",
    "false",
    "Some",
    "None",
    "Ok",
    "Err"
  ], o = [
    // functions
    "drop ",
    // traits
    "Copy",
    "Send",
    "Sized",
    "Sync",
    "Drop",
    "Fn",
    "FnMut",
    "FnOnce",
    "ToOwned",
    "Clone",
    "Debug",
    "PartialEq",
    "PartialOrd",
    "Eq",
    "Ord",
    "AsRef",
    "AsMut",
    "Into",
    "From",
    "Default",
    "Iterator",
    "Extend",
    "IntoIterator",
    "DoubleEndedIterator",
    "ExactSizeIterator",
    "SliceConcatExt",
    "ToString",
    // macros
    "assert!",
    "assert_eq!",
    "bitflags!",
    "bytes!",
    "cfg!",
    "col!",
    "concat!",
    "concat_idents!",
    "debug_assert!",
    "debug_assert_eq!",
    "env!",
    "eprintln!",
    "panic!",
    "file!",
    "format!",
    "format_args!",
    "include_bytes!",
    "include_str!",
    "line!",
    "local_data_key!",
    "module_path!",
    "option_env!",
    "print!",
    "println!",
    "select!",
    "stringify!",
    "try!",
    "unimplemented!",
    "unreachable!",
    "vec!",
    "write!",
    "writeln!",
    "macro_rules!",
    "assert_ne!",
    "debug_assert_ne!"
  ], a = [
    "i8",
    "i16",
    "i32",
    "i64",
    "i128",
    "isize",
    "u8",
    "u16",
    "u32",
    "u64",
    "u128",
    "usize",
    "f32",
    "f64",
    "str",
    "char",
    "bool",
    "Box",
    "Option",
    "Result",
    "String",
    "Vec"
  ];
  return {
    name: "Rust",
    aliases: ["rs"],
    keywords: {
      $pattern: t.IDENT_RE + "!?",
      type: a,
      keyword: i,
      literal: s,
      built_in: o
    },
    illegal: "</",
    contains: [
      t.C_LINE_COMMENT_MODE,
      t.COMMENT("/\\*", "\\*/", { contains: ["self"] }),
      t.inherit(t.QUOTE_STRING_MODE, {
        begin: /b?"/,
        illegal: null
      }),
      {
        className: "string",
        variants: [
          { begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ },
          { begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ }
        ]
      },
      {
        className: "symbol",
        begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
      },
      {
        className: "number",
        variants: [
          { begin: "\\b0b([01_]+)" + r },
          { begin: "\\b0o([0-7_]+)" + r },
          { begin: "\\b0x([A-Fa-f0-9_]+)" + r },
          { begin: "\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)" + r }
        ],
        relevance: 0
      },
      {
        begin: [
          /fn/,
          /\s+/,
          t.UNDERSCORE_IDENT_RE
        ],
        className: {
          1: "keyword",
          3: "title.function"
        }
      },
      {
        className: "meta",
        begin: "#!?\\[",
        end: "\\]",
        contains: [
          {
            className: "string",
            begin: /"/,
            end: /"/
          }
        ]
      },
      {
        begin: [
          /let/,
          /\s+/,
          /(?:mut\s+)?/,
          t.UNDERSCORE_IDENT_RE
        ],
        className: {
          1: "keyword",
          3: "keyword",
          4: "variable"
        }
      },
      // must come before impl/for rule later
      {
        begin: [
          /for/,
          /\s+/,
          t.UNDERSCORE_IDENT_RE,
          /\s+/,
          /in/
        ],
        className: {
          1: "keyword",
          3: "variable",
          5: "keyword"
        }
      },
      {
        begin: [
          /type/,
          /\s+/,
          t.UNDERSCORE_IDENT_RE
        ],
        className: {
          1: "keyword",
          3: "title.class"
        }
      },
      {
        begin: [
          /(?:trait|enum|struct|union|impl|for)/,
          /\s+/,
          t.UNDERSCORE_IDENT_RE
        ],
        className: {
          1: "keyword",
          3: "title.class"
        }
      },
      {
        begin: t.IDENT_RE + "::",
        keywords: {
          keyword: "Self",
          built_in: o,
          type: a
        }
      },
      {
        className: "punctuation",
        begin: "->"
      },
      n
    ]
  };
}
const DC = (t) => ({
  IMPORTANT: {
    scope: "meta",
    begin: "!important"
  },
  BLOCK_COMMENT: t.C_BLOCK_COMMENT_MODE,
  HEXCOLOR: {
    scope: "number",
    begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
  },
  FUNCTION_DISPATCH: {
    className: "built_in",
    begin: /[\w-]+(?=\()/
  },
  ATTRIBUTE_SELECTOR_MODE: {
    scope: "selector-attr",
    begin: /\[/,
    end: /\]/,
    illegal: "$",
    contains: [
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE
    ]
  },
  CSS_NUMBER_MODE: {
    scope: "number",
    begin: t.NUMBER_RE + "(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",
    relevance: 0
  },
  CSS_VARIABLE: {
    className: "attr",
    begin: /--[A-Za-z_][A-Za-z0-9_-]*/
  }
}), HC = [
  "a",
  "abbr",
  "address",
  "article",
  "aside",
  "audio",
  "b",
  "blockquote",
  "body",
  "button",
  "canvas",
  "caption",
  "cite",
  "code",
  "dd",
  "del",
  "details",
  "dfn",
  "div",
  "dl",
  "dt",
  "em",
  "fieldset",
  "figcaption",
  "figure",
  "footer",
  "form",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "header",
  "hgroup",
  "html",
  "i",
  "iframe",
  "img",
  "input",
  "ins",
  "kbd",
  "label",
  "legend",
  "li",
  "main",
  "mark",
  "menu",
  "nav",
  "object",
  "ol",
  "p",
  "q",
  "quote",
  "samp",
  "section",
  "span",
  "strong",
  "summary",
  "sup",
  "table",
  "tbody",
  "td",
  "textarea",
  "tfoot",
  "th",
  "thead",
  "time",
  "tr",
  "ul",
  "var",
  "video"
], BC = [
  "any-hover",
  "any-pointer",
  "aspect-ratio",
  "color",
  "color-gamut",
  "color-index",
  "device-aspect-ratio",
  "device-height",
  "device-width",
  "display-mode",
  "forced-colors",
  "grid",
  "height",
  "hover",
  "inverted-colors",
  "monochrome",
  "orientation",
  "overflow-block",
  "overflow-inline",
  "pointer",
  "prefers-color-scheme",
  "prefers-contrast",
  "prefers-reduced-motion",
  "prefers-reduced-transparency",
  "resolution",
  "scan",
  "scripting",
  "update",
  "width",
  // TODO: find a better solution?
  "min-width",
  "max-width",
  "min-height",
  "max-height"
], PC = [
  "active",
  "any-link",
  "blank",
  "checked",
  "current",
  "default",
  "defined",
  "dir",
  // dir()
  "disabled",
  "drop",
  "empty",
  "enabled",
  "first",
  "first-child",
  "first-of-type",
  "fullscreen",
  "future",
  "focus",
  "focus-visible",
  "focus-within",
  "has",
  // has()
  "host",
  // host or host()
  "host-context",
  // host-context()
  "hover",
  "indeterminate",
  "in-range",
  "invalid",
  "is",
  // is()
  "lang",
  // lang()
  "last-child",
  "last-of-type",
  "left",
  "link",
  "local-link",
  "not",
  // not()
  "nth-child",
  // nth-child()
  "nth-col",
  // nth-col()
  "nth-last-child",
  // nth-last-child()
  "nth-last-col",
  // nth-last-col()
  "nth-last-of-type",
  //nth-last-of-type()
  "nth-of-type",
  //nth-of-type()
  "only-child",
  "only-of-type",
  "optional",
  "out-of-range",
  "past",
  "placeholder-shown",
  "read-only",
  "read-write",
  "required",
  "right",
  "root",
  "scope",
  "target",
  "target-within",
  "user-invalid",
  "valid",
  "visited",
  "where"
  // where()
], $C = [
  "after",
  "backdrop",
  "before",
  "cue",
  "cue-region",
  "first-letter",
  "first-line",
  "grammar-error",
  "marker",
  "part",
  "placeholder",
  "selection",
  "slotted",
  "spelling-error"
], VC = [
  "align-content",
  "align-items",
  "align-self",
  "all",
  "animation",
  "animation-delay",
  "animation-direction",
  "animation-duration",
  "animation-fill-mode",
  "animation-iteration-count",
  "animation-name",
  "animation-play-state",
  "animation-timing-function",
  "backface-visibility",
  "background",
  "background-attachment",
  "background-blend-mode",
  "background-clip",
  "background-color",
  "background-image",
  "background-origin",
  "background-position",
  "background-repeat",
  "background-size",
  "block-size",
  "border",
  "border-block",
  "border-block-color",
  "border-block-end",
  "border-block-end-color",
  "border-block-end-style",
  "border-block-end-width",
  "border-block-start",
  "border-block-start-color",
  "border-block-start-style",
  "border-block-start-width",
  "border-block-style",
  "border-block-width",
  "border-bottom",
  "border-bottom-color",
  "border-bottom-left-radius",
  "border-bottom-right-radius",
  "border-bottom-style",
  "border-bottom-width",
  "border-collapse",
  "border-color",
  "border-image",
  "border-image-outset",
  "border-image-repeat",
  "border-image-slice",
  "border-image-source",
  "border-image-width",
  "border-inline",
  "border-inline-color",
  "border-inline-end",
  "border-inline-end-color",
  "border-inline-end-style",
  "border-inline-end-width",
  "border-inline-start",
  "border-inline-start-color",
  "border-inline-start-style",
  "border-inline-start-width",
  "border-inline-style",
  "border-inline-width",
  "border-left",
  "border-left-color",
  "border-left-style",
  "border-left-width",
  "border-radius",
  "border-right",
  "border-right-color",
  "border-right-style",
  "border-right-width",
  "border-spacing",
  "border-style",
  "border-top",
  "border-top-color",
  "border-top-left-radius",
  "border-top-right-radius",
  "border-top-style",
  "border-top-width",
  "border-width",
  "bottom",
  "box-decoration-break",
  "box-shadow",
  "box-sizing",
  "break-after",
  "break-before",
  "break-inside",
  "caption-side",
  "caret-color",
  "clear",
  "clip",
  "clip-path",
  "clip-rule",
  "color",
  "column-count",
  "column-fill",
  "column-gap",
  "column-rule",
  "column-rule-color",
  "column-rule-style",
  "column-rule-width",
  "column-span",
  "column-width",
  "columns",
  "contain",
  "content",
  "content-visibility",
  "counter-increment",
  "counter-reset",
  "cue",
  "cue-after",
  "cue-before",
  "cursor",
  "direction",
  "display",
  "empty-cells",
  "filter",
  "flex",
  "flex-basis",
  "flex-direction",
  "flex-flow",
  "flex-grow",
  "flex-shrink",
  "flex-wrap",
  "float",
  "flow",
  "font",
  "font-display",
  "font-family",
  "font-feature-settings",
  "font-kerning",
  "font-language-override",
  "font-size",
  "font-size-adjust",
  "font-smoothing",
  "font-stretch",
  "font-style",
  "font-synthesis",
  "font-variant",
  "font-variant-caps",
  "font-variant-east-asian",
  "font-variant-ligatures",
  "font-variant-numeric",
  "font-variant-position",
  "font-variation-settings",
  "font-weight",
  "gap",
  "glyph-orientation-vertical",
  "grid",
  "grid-area",
  "grid-auto-columns",
  "grid-auto-flow",
  "grid-auto-rows",
  "grid-column",
  "grid-column-end",
  "grid-column-start",
  "grid-gap",
  "grid-row",
  "grid-row-end",
  "grid-row-start",
  "grid-template",
  "grid-template-areas",
  "grid-template-columns",
  "grid-template-rows",
  "hanging-punctuation",
  "height",
  "hyphens",
  "icon",
  "image-orientation",
  "image-rendering",
  "image-resolution",
  "ime-mode",
  "inline-size",
  "isolation",
  "justify-content",
  "left",
  "letter-spacing",
  "line-break",
  "line-height",
  "list-style",
  "list-style-image",
  "list-style-position",
  "list-style-type",
  "margin",
  "margin-block",
  "margin-block-end",
  "margin-block-start",
  "margin-bottom",
  "margin-inline",
  "margin-inline-end",
  "margin-inline-start",
  "margin-left",
  "margin-right",
  "margin-top",
  "marks",
  "mask",
  "mask-border",
  "mask-border-mode",
  "mask-border-outset",
  "mask-border-repeat",
  "mask-border-slice",
  "mask-border-source",
  "mask-border-width",
  "mask-clip",
  "mask-composite",
  "mask-image",
  "mask-mode",
  "mask-origin",
  "mask-position",
  "mask-repeat",
  "mask-size",
  "mask-type",
  "max-block-size",
  "max-height",
  "max-inline-size",
  "max-width",
  "min-block-size",
  "min-height",
  "min-inline-size",
  "min-width",
  "mix-blend-mode",
  "nav-down",
  "nav-index",
  "nav-left",
  "nav-right",
  "nav-up",
  "none",
  "normal",
  "object-fit",
  "object-position",
  "opacity",
  "order",
  "orphans",
  "outline",
  "outline-color",
  "outline-offset",
  "outline-style",
  "outline-width",
  "overflow",
  "overflow-wrap",
  "overflow-x",
  "overflow-y",
  "padding",
  "padding-block",
  "padding-block-end",
  "padding-block-start",
  "padding-bottom",
  "padding-inline",
  "padding-inline-end",
  "padding-inline-start",
  "padding-left",
  "padding-right",
  "padding-top",
  "page-break-after",
  "page-break-before",
  "page-break-inside",
  "pause",
  "pause-after",
  "pause-before",
  "perspective",
  "perspective-origin",
  "pointer-events",
  "position",
  "quotes",
  "resize",
  "rest",
  "rest-after",
  "rest-before",
  "right",
  "row-gap",
  "scroll-margin",
  "scroll-margin-block",
  "scroll-margin-block-end",
  "scroll-margin-block-start",
  "scroll-margin-bottom",
  "scroll-margin-inline",
  "scroll-margin-inline-end",
  "scroll-margin-inline-start",
  "scroll-margin-left",
  "scroll-margin-right",
  "scroll-margin-top",
  "scroll-padding",
  "scroll-padding-block",
  "scroll-padding-block-end",
  "scroll-padding-block-start",
  "scroll-padding-bottom",
  "scroll-padding-inline",
  "scroll-padding-inline-end",
  "scroll-padding-inline-start",
  "scroll-padding-left",
  "scroll-padding-right",
  "scroll-padding-top",
  "scroll-snap-align",
  "scroll-snap-stop",
  "scroll-snap-type",
  "scrollbar-color",
  "scrollbar-gutter",
  "scrollbar-width",
  "shape-image-threshold",
  "shape-margin",
  "shape-outside",
  "speak",
  "speak-as",
  "src",
  // @font-face
  "tab-size",
  "table-layout",
  "text-align",
  "text-align-all",
  "text-align-last",
  "text-combine-upright",
  "text-decoration",
  "text-decoration-color",
  "text-decoration-line",
  "text-decoration-style",
  "text-emphasis",
  "text-emphasis-color",
  "text-emphasis-position",
  "text-emphasis-style",
  "text-indent",
  "text-justify",
  "text-orientation",
  "text-overflow",
  "text-rendering",
  "text-shadow",
  "text-transform",
  "text-underline-position",
  "top",
  "transform",
  "transform-box",
  "transform-origin",
  "transform-style",
  "transition",
  "transition-delay",
  "transition-duration",
  "transition-property",
  "transition-timing-function",
  "unicode-bidi",
  "vertical-align",
  "visibility",
  "voice-balance",
  "voice-duration",
  "voice-family",
  "voice-pitch",
  "voice-range",
  "voice-rate",
  "voice-stress",
  "voice-volume",
  "white-space",
  "widows",
  "width",
  "will-change",
  "word-break",
  "word-spacing",
  "word-wrap",
  "writing-mode",
  "z-index"
  // reverse makes sure longer attributes `font-weight` are matched fully
  // instead of getting false positives on say `font`
].reverse();
function zC(t) {
  const e = DC(t), n = $C, r = PC, i = "@[a-z-]+", s = "and or not only", a = {
    className: "variable",
    begin: "(\\$" + "[a-zA-Z-][a-zA-Z0-9_-]*" + ")\\b",
    relevance: 0
  };
  return {
    name: "SCSS",
    case_insensitive: !0,
    illegal: "[=/|']",
    contains: [
      t.C_LINE_COMMENT_MODE,
      t.C_BLOCK_COMMENT_MODE,
      // to recognize keyframe 40% etc which are outside the scope of our
      // attribute value mode
      e.CSS_NUMBER_MODE,
      {
        className: "selector-id",
        begin: "#[A-Za-z0-9_-]+",
        relevance: 0
      },
      {
        className: "selector-class",
        begin: "\\.[A-Za-z0-9_-]+",
        relevance: 0
      },
      e.ATTRIBUTE_SELECTOR_MODE,
      {
        className: "selector-tag",
        begin: "\\b(" + HC.join("|") + ")\\b",
        // was there, before, but why?
        relevance: 0
      },
      {
        className: "selector-pseudo",
        begin: ":(" + r.join("|") + ")"
      },
      {
        className: "selector-pseudo",
        begin: ":(:)?(" + n.join("|") + ")"
      },
      a,
      {
        // pseudo-selector params
        begin: /\(/,
        end: /\)/,
        contains: [e.CSS_NUMBER_MODE]
      },
      e.CSS_VARIABLE,
      {
        className: "attribute",
        begin: "\\b(" + VC.join("|") + ")\\b"
      },
      { begin: "\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b" },
      {
        begin: /:/,
        end: /[;}{]/,
        relevance: 0,
        contains: [
          e.BLOCK_COMMENT,
          a,
          e.HEXCOLOR,
          e.CSS_NUMBER_MODE,
          t.QUOTE_STRING_MODE,
          t.APOS_STRING_MODE,
          e.IMPORTANT,
          e.FUNCTION_DISPATCH
        ]
      },
      // matching these here allows us to treat them more like regular CSS
      // rules so everything between the {} gets regular rule highlighting,
      // which is what we want for page and font-face
      {
        begin: "@(page|font-face)",
        keywords: {
          $pattern: i,
          keyword: "@page @font-face"
        }
      },
      {
        begin: "@",
        end: "[{;]",
        returnBegin: !0,
        keywords: {
          $pattern: /[a-z-]+/,
          keyword: s,
          attribute: BC.join(" ")
        },
        contains: [
          {
            begin: i,
            className: "keyword"
          },
          {
            begin: /[a-z-]+(?=:)/,
            className: "attribute"
          },
          a,
          t.QUOTE_STRING_MODE,
          t.APOS_STRING_MODE,
          e.HEXCOLOR,
          e.CSS_NUMBER_MODE
        ]
      },
      e.FUNCTION_DISPATCH
    ]
  };
}
function FC(t) {
  return {
    name: "Shell Session",
    aliases: [
      "console",
      "shellsession"
    ],
    contains: [
      {
        className: "meta.prompt",
        // We cannot add \s (spaces) in the regular expression otherwise it will be too broad and produce unexpected result.
        // For instance, in the following example, it would match "echo /path/to/home >" as a prompt:
        // echo /path/to/home > t.exe
        begin: /^\s{0,3}[/~\w\d[\]()@-]*[>%$#][ ]?/,
        starts: {
          end: /[^\\](?=\s*$)/,
          subLanguage: "bash"
        }
      }
    ]
  };
}
function UC(t) {
  const e = t.regex, n = t.COMMENT("--", "$"), r = {
    className: "string",
    variants: [
      {
        begin: /'/,
        end: /'/,
        contains: [{ begin: /''/ }]
      }
    ]
  }, i = {
    begin: /"/,
    end: /"/,
    contains: [{ begin: /""/ }]
  }, s = [
    "true",
    "false",
    // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way.
    // "null",
    "unknown"
  ], o = [
    "double precision",
    "large object",
    "with timezone",
    "without timezone"
  ], a = [
    "bigint",
    "binary",
    "blob",
    "boolean",
    "char",
    "character",
    "clob",
    "date",
    "dec",
    "decfloat",
    "decimal",
    "float",
    "int",
    "integer",
    "interval",
    "nchar",
    "nclob",
    "national",
    "numeric",
    "real",
    "row",
    "smallint",
    "time",
    "timestamp",
    "varchar",
    "varying",
    // modifier (character varying)
    "varbinary"
  ], l = [
    "add",
    "asc",
    "collation",
    "desc",
    "final",
    "first",
    "last",
    "view"
  ], c = [
    "abs",
    "acos",
    "all",
    "allocate",
    "alter",
    "and",
    "any",
    "are",
    "array",
    "array_agg",
    "array_max_cardinality",
    "as",
    "asensitive",
    "asin",
    "asymmetric",
    "at",
    "atan",
    "atomic",
    "authorization",
    "avg",
    "begin",
    "begin_frame",
    "begin_partition",
    "between",
    "bigint",
    "binary",
    "blob",
    "boolean",
    "both",
    "by",
    "call",
    "called",
    "cardinality",
    "cascaded",
    "case",
    "cast",
    "ceil",
    "ceiling",
    "char",
    "char_length",
    "character",
    "character_length",
    "check",
    "classifier",
    "clob",
    "close",
    "coalesce",
    "collate",
    "collect",
    "column",
    "commit",
    "condition",
    "connect",
    "constraint",
    "contains",
    "convert",
    "copy",
    "corr",
    "corresponding",
    "cos",
    "cosh",
    "count",
    "covar_pop",
    "covar_samp",
    "create",
    "cross",
    "cube",
    "cume_dist",
    "current",
    "current_catalog",
    "current_date",
    "current_default_transform_group",
    "current_path",
    "current_role",
    "current_row",
    "current_schema",
    "current_time",
    "current_timestamp",
    "current_path",
    "current_role",
    "current_transform_group_for_type",
    "current_user",
    "cursor",
    "cycle",
    "date",
    "day",
    "deallocate",
    "dec",
    "decimal",
    "decfloat",
    "declare",
    "default",
    "define",
    "delete",
    "dense_rank",
    "deref",
    "describe",
    "deterministic",
    "disconnect",
    "distinct",
    "double",
    "drop",
    "dynamic",
    "each",
    "element",
    "else",
    "empty",
    "end",
    "end_frame",
    "end_partition",
    "end-exec",
    "equals",
    "escape",
    "every",
    "except",
    "exec",
    "execute",
    "exists",
    "exp",
    "external",
    "extract",
    "false",
    "fetch",
    "filter",
    "first_value",
    "float",
    "floor",
    "for",
    "foreign",
    "frame_row",
    "free",
    "from",
    "full",
    "function",
    "fusion",
    "get",
    "global",
    "grant",
    "group",
    "grouping",
    "groups",
    "having",
    "hold",
    "hour",
    "identity",
    "in",
    "indicator",
    "initial",
    "inner",
    "inout",
    "insensitive",
    "insert",
    "int",
    "integer",
    "intersect",
    "intersection",
    "interval",
    "into",
    "is",
    "join",
    "json_array",
    "json_arrayagg",
    "json_exists",
    "json_object",
    "json_objectagg",
    "json_query",
    "json_table",
    "json_table_primitive",
    "json_value",
    "lag",
    "language",
    "large",
    "last_value",
    "lateral",
    "lead",
    "leading",
    "left",
    "like",
    "like_regex",
    "listagg",
    "ln",
    "local",
    "localtime",
    "localtimestamp",
    "log",
    "log10",
    "lower",
    "match",
    "match_number",
    "match_recognize",
    "matches",
    "max",
    "member",
    "merge",
    "method",
    "min",
    "minute",
    "mod",
    "modifies",
    "module",
    "month",
    "multiset",
    "national",
    "natural",
    "nchar",
    "nclob",
    "new",
    "no",
    "none",
    "normalize",
    "not",
    "nth_value",
    "ntile",
    "null",
    "nullif",
    "numeric",
    "octet_length",
    "occurrences_regex",
    "of",
    "offset",
    "old",
    "omit",
    "on",
    "one",
    "only",
    "open",
    "or",
    "order",
    "out",
    "outer",
    "over",
    "overlaps",
    "overlay",
    "parameter",
    "partition",
    "pattern",
    "per",
    "percent",
    "percent_rank",
    "percentile_cont",
    "percentile_disc",
    "period",
    "portion",
    "position",
    "position_regex",
    "power",
    "precedes",
    "precision",
    "prepare",
    "primary",
    "procedure",
    "ptf",
    "range",
    "rank",
    "reads",
    "real",
    "recursive",
    "ref",
    "references",
    "referencing",
    "regr_avgx",
    "regr_avgy",
    "regr_count",
    "regr_intercept",
    "regr_r2",
    "regr_slope",
    "regr_sxx",
    "regr_sxy",
    "regr_syy",
    "release",
    "result",
    "return",
    "returns",
    "revoke",
    "right",
    "rollback",
    "rollup",
    "row",
    "row_number",
    "rows",
    "running",
    "savepoint",
    "scope",
    "scroll",
    "search",
    "second",
    "seek",
    "select",
    "sensitive",
    "session_user",
    "set",
    "show",
    "similar",
    "sin",
    "sinh",
    "skip",
    "smallint",
    "some",
    "specific",
    "specifictype",
    "sql",
    "sqlexception",
    "sqlstate",
    "sqlwarning",
    "sqrt",
    "start",
    "static",
    "stddev_pop",
    "stddev_samp",
    "submultiset",
    "subset",
    "substring",
    "substring_regex",
    "succeeds",
    "sum",
    "symmetric",
    "system",
    "system_time",
    "system_user",
    "table",
    "tablesample",
    "tan",
    "tanh",
    "then",
    "time",
    "timestamp",
    "timezone_hour",
    "timezone_minute",
    "to",
    "trailing",
    "translate",
    "translate_regex",
    "translation",
    "treat",
    "trigger",
    "trim",
    "trim_array",
    "true",
    "truncate",
    "uescape",
    "union",
    "unique",
    "unknown",
    "unnest",
    "update",
    "upper",
    "user",
    "using",
    "value",
    "values",
    "value_of",
    "var_pop",
    "var_samp",
    "varbinary",
    "varchar",
    "varying",
    "versioning",
    "when",
    "whenever",
    "where",
    "width_bucket",
    "window",
    "with",
    "within",
    "without",
    "year"
  ], d = [
    "abs",
    "acos",
    "array_agg",
    "asin",
    "atan",
    "avg",
    "cast",
    "ceil",
    "ceiling",
    "coalesce",
    "corr",
    "cos",
    "cosh",
    "count",
    "covar_pop",
    "covar_samp",
    "cume_dist",
    "dense_rank",
    "deref",
    "element",
    "exp",
    "extract",
    "first_value",
    "floor",
    "json_array",
    "json_arrayagg",
    "json_exists",
    "json_object",
    "json_objectagg",
    "json_query",
    "json_table",
    "json_table_primitive",
    "json_value",
    "lag",
    "last_value",
    "lead",
    "listagg",
    "ln",
    "log",
    "log10",
    "lower",
    "max",
    "min",
    "mod",
    "nth_value",
    "ntile",
    "nullif",
    "percent_rank",
    "percentile_cont",
    "percentile_disc",
    "position",
    "position_regex",
    "power",
    "rank",
    "regr_avgx",
    "regr_avgy",
    "regr_count",
    "regr_intercept",
    "regr_r2",
    "regr_slope",
    "regr_sxx",
    "regr_sxy",
    "regr_syy",
    "row_number",
    "sin",
    "sinh",
    "sqrt",
    "stddev_pop",
    "stddev_samp",
    "substring",
    "substring_regex",
    "sum",
    "tan",
    "tanh",
    "translate",
    "translate_regex",
    "treat",
    "trim",
    "trim_array",
    "unnest",
    "upper",
    "value_of",
    "var_pop",
    "var_samp",
    "width_bucket"
  ], u = [
    "current_catalog",
    "current_date",
    "current_default_transform_group",
    "current_path",
    "current_role",
    "current_schema",
    "current_transform_group_for_type",
    "current_user",
    "session_user",
    "system_time",
    "system_user",
    "current_time",
    "localtime",
    "current_timestamp",
    "localtimestamp"
  ], f = [
    "create table",
    "insert into",
    "primary key",
    "foreign key",
    "not null",
    "alter table",
    "add constraint",
    "grouping sets",
    "on overflow",
    "character set",
    "respect nulls",
    "ignore nulls",
    "nulls first",
    "nulls last",
    "depth first",
    "breadth first"
  ], p = d, h = [
    ...c,
    ...l
  ].filter((E) => !d.includes(E)), m = {
    className: "variable",
    begin: /@[a-z0-9][a-z0-9_]*/
  }, g = {
    className: "operator",
    begin: /[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,
    relevance: 0
  }, v = {
    begin: e.concat(/\b/, e.either(...p), /\s*\(/),
    relevance: 0,
    keywords: { built_in: p }
  };
  function y(E, {
    exceptions: b,
    when: C
  } = {}) {
    const w = C;
    return b = b || [], E.map((_) => _.match(/\|\d+$/) || b.includes(_) ? _ : w(_) ? `${_}|0` : _);
  }
  return {
    name: "SQL",
    case_insensitive: !0,
    // does not include {} or HTML tags `</`
    illegal: /[{}]|<\//,
    keywords: {
      $pattern: /\b[\w\.]+/,
      keyword: y(h, { when: (E) => E.length < 3 }),
      literal: s,
      type: a,
      built_in: u
    },
    contains: [
      {
        begin: e.either(...f),
        relevance: 0,
        keywords: {
          $pattern: /[\w\.]+/,
          keyword: h.concat(f),
          literal: s,
          type: a
        }
      },
      {
        className: "type",
        begin: e.either(...o)
      },
      v,
      m,
      r,
      i,
      t.C_NUMBER_MODE,
      t.C_BLOCK_COMMENT_MODE,
      n,
      g
    ]
  };
}
function $p(t) {
  return t ? typeof t == "string" ? t : t.source : null;
}
function Fi(t) {
  return ye("(?=", t, ")");
}
function ye(...t) {
  return t.map((n) => $p(n)).join("");
}
function KC(t) {
  const e = t[t.length - 1];
  return typeof e == "object" && e.constructor === Object ? (t.splice(t.length - 1, 1), e) : {};
}
function rt(...t) {
  return "(" + (KC(t).capture ? "" : "?:") + t.map((r) => $p(r)).join("|") + ")";
}
const El = (t) => ye(
  /\b/,
  t,
  /\w$/.test(t) ? /\b/ : /\B/
), WC = [
  "Protocol",
  // contextual
  "Type"
  // contextual
].map(El), Zd = [
  "init",
  "self"
].map(El), qC = [
  "Any",
  "Self"
], $o = [
  // strings below will be fed into the regular `keywords` engine while regex
  // will result in additional modes being created to scan for those keywords to
  // avoid conflicts with other rules
  "actor",
  "any",
  // contextual
  "associatedtype",
  "async",
  "await",
  /as\?/,
  // operator
  /as!/,
  // operator
  "as",
  // operator
  "borrowing",
  // contextual
  "break",
  "case",
  "catch",
  "class",
  "consume",
  // contextual
  "consuming",
  // contextual
  "continue",
  "convenience",
  // contextual
  "copy",
  // contextual
  "default",
  "defer",
  "deinit",
  "didSet",
  // contextual
  "distributed",
  "do",
  "dynamic",
  // contextual
  "each",
  "else",
  "enum",
  "extension",
  "fallthrough",
  /fileprivate\(set\)/,
  "fileprivate",
  "final",
  // contextual
  "for",
  "func",
  "get",
  // contextual
  "guard",
  "if",
  "import",
  "indirect",
  // contextual
  "infix",
  // contextual
  /init\?/,
  /init!/,
  "inout",
  /internal\(set\)/,
  "internal",
  "in",
  "is",
  // operator
  "isolated",
  // contextual
  "nonisolated",
  // contextual
  "lazy",
  // contextual
  "let",
  "macro",
  "mutating",
  // contextual
  "nonmutating",
  // contextual
  /open\(set\)/,
  // contextual
  "open",
  // contextual
  "operator",
  "optional",
  // contextual
  "override",
  // contextual
  "postfix",
  // contextual
  "precedencegroup",
  "prefix",
  // contextual
  /private\(set\)/,
  "private",
  "protocol",
  /public\(set\)/,
  "public",
  "repeat",
  "required",
  // contextual
  "rethrows",
  "return",
  "set",
  // contextual
  "some",
  // contextual
  "static",
  "struct",
  "subscript",
  "super",
  "switch",
  "throws",
  "throw",
  /try\?/,
  // operator
  /try!/,
  // operator
  "try",
  // operator
  "typealias",
  /unowned\(safe\)/,
  // contextual
  /unowned\(unsafe\)/,
  // contextual
  "unowned",
  // contextual
  "var",
  "weak",
  // contextual
  "where",
  "while",
  "willSet"
  // contextual
], Gd = [
  "false",
  "nil",
  "true"
], ZC = [
  "assignment",
  "associativity",
  "higherThan",
  "left",
  "lowerThan",
  "none",
  "right"
], GC = [
  "#colorLiteral",
  "#column",
  "#dsohandle",
  "#else",
  "#elseif",
  "#endif",
  "#error",
  "#file",
  "#fileID",
  "#fileLiteral",
  "#filePath",
  "#function",
  "#if",
  "#imageLiteral",
  "#keyPath",
  "#line",
  "#selector",
  "#sourceLocation",
  "#warning"
], jd = [
  "abs",
  "all",
  "any",
  "assert",
  "assertionFailure",
  "debugPrint",
  "dump",
  "fatalError",
  "getVaList",
  "isKnownUniquelyReferenced",
  "max",
  "min",
  "numericCast",
  "pointwiseMax",
  "pointwiseMin",
  "precondition",
  "preconditionFailure",
  "print",
  "readLine",
  "repeatElement",
  "sequence",
  "stride",
  "swap",
  "swift_unboxFromSwiftValueWithType",
  "transcode",
  "type",
  "unsafeBitCast",
  "unsafeDowncast",
  "withExtendedLifetime",
  "withUnsafeMutablePointer",
  "withUnsafePointer",
  "withVaList",
  "withoutActuallyEscaping",
  "zip"
], Vp = rt(
  /[/=\-+!*%<>&|^~?]/,
  /[\u00A1-\u00A7]/,
  /[\u00A9\u00AB]/,
  /[\u00AC\u00AE]/,
  /[\u00B0\u00B1]/,
  /[\u00B6\u00BB\u00BF\u00D7\u00F7]/,
  /[\u2016-\u2017]/,
  /[\u2020-\u2027]/,
  /[\u2030-\u203E]/,
  /[\u2041-\u2053]/,
  /[\u2055-\u205E]/,
  /[\u2190-\u23FF]/,
  /[\u2500-\u2775]/,
  /[\u2794-\u2BFF]/,
  /[\u2E00-\u2E7F]/,
  /[\u3001-\u3003]/,
  /[\u3008-\u3020]/,
  /[\u3030]/
), zp = rt(
  Vp,
  /[\u0300-\u036F]/,
  /[\u1DC0-\u1DFF]/,
  /[\u20D0-\u20FF]/,
  /[\uFE00-\uFE0F]/,
  /[\uFE20-\uFE2F]/
  // TODO: The following characters are also allowed, but the regex isn't supported yet.
  // /[\u{E0100}-\u{E01EF}]/u
), Vo = ye(Vp, zp, "*"), Fp = rt(
  /[a-zA-Z_]/,
  /[\u00A8\u00AA\u00AD\u00AF\u00B2-\u00B5\u00B7-\u00BA]/,
  /[\u00BC-\u00BE\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]/,
  /[\u0100-\u02FF\u0370-\u167F\u1681-\u180D\u180F-\u1DBF]/,
  /[\u1E00-\u1FFF]/,
  /[\u200B-\u200D\u202A-\u202E\u203F-\u2040\u2054\u2060-\u206F]/,
  /[\u2070-\u20CF\u2100-\u218F\u2460-\u24FF\u2776-\u2793]/,
  /[\u2C00-\u2DFF\u2E80-\u2FFF]/,
  /[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,
  /[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,
  /[\uFE47-\uFEFE\uFF00-\uFFFD]/
  // Should be /[\uFE47-\uFFFD]/, but we have to exclude FEFF.
  // The following characters are also allowed, but the regexes aren't supported yet.
  // /[\u{10000}-\u{1FFFD}\u{20000-\u{2FFFD}\u{30000}-\u{3FFFD}\u{40000}-\u{4FFFD}]/u,
  // /[\u{50000}-\u{5FFFD}\u{60000-\u{6FFFD}\u{70000}-\u{7FFFD}\u{80000}-\u{8FFFD}]/u,
  // /[\u{90000}-\u{9FFFD}\u{A0000-\u{AFFFD}\u{B0000}-\u{BFFFD}\u{C0000}-\u{CFFFD}]/u,
  // /[\u{D0000}-\u{DFFFD}\u{E0000-\u{EFFFD}]/u
), Os = rt(
  Fp,
  /\d/,
  /[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/
), Wt = ye(Fp, Os, "*"), zo = ye(/[A-Z]/, Os, "*"), jC = [
  "attached",
  "autoclosure",
  ye(/convention\(/, rt("swift", "block", "c"), /\)/),
  "discardableResult",
  "dynamicCallable",
  "dynamicMemberLookup",
  "escaping",
  "freestanding",
  "frozen",
  "GKInspectable",
  "IBAction",
  "IBDesignable",
  "IBInspectable",
  "IBOutlet",
  "IBSegueAction",
  "inlinable",
  "main",
  "nonobjc",
  "NSApplicationMain",
  "NSCopying",
  "NSManaged",
  ye(/objc\(/, Wt, /\)/),
  "objc",
  "objcMembers",
  "propertyWrapper",
  "requires_stored_property_inits",
  "resultBuilder",
  "Sendable",
  "testable",
  "UIApplicationMain",
  "unchecked",
  "unknown",
  "usableFromInline",
  "warn_unqualified_access"
], YC = [
  "iOS",
  "iOSApplicationExtension",
  "macOS",
  "macOSApplicationExtension",
  "macCatalyst",
  "macCatalystApplicationExtension",
  "watchOS",
  "watchOSApplicationExtension",
  "tvOS",
  "tvOSApplicationExtension",
  "swift"
];
function JC(t) {
  const e = {
    match: /\s+/,
    relevance: 0
  }, n = t.COMMENT(
    "/\\*",
    "\\*/",
    { contains: ["self"] }
  ), r = [
    t.C_LINE_COMMENT_MODE,
    n
  ], i = {
    match: [
      /\./,
      rt(...WC, ...Zd)
    ],
    className: { 2: "keyword" }
  }, s = {
    // Consume .keyword to prevent highlighting properties and methods as keywords.
    match: ye(/\./, rt(...$o)),
    relevance: 0
  }, o = $o.filter((ce) => typeof ce == "string").concat(["_|0"]), a = $o.filter((ce) => typeof ce != "string").concat(qC).map(El), l = { variants: [
    {
      className: "keyword",
      match: rt(...a, ...Zd)
    }
  ] }, c = {
    $pattern: rt(
      /\b\w+/,
      // regular keywords
      /#\w+/
      // number keywords
    ),
    keyword: o.concat(GC),
    literal: Gd
  }, d = [
    i,
    s,
    l
  ], u = {
    // Consume .built_in to prevent highlighting properties and methods.
    match: ye(/\./, rt(...jd)),
    relevance: 0
  }, f = {
    className: "built_in",
    match: ye(/\b/, rt(...jd), /(?=\()/)
  }, p = [
    u,
    f
  ], h = {
    // Prevent -> from being highlighting as an operator.
    match: /->/,
    relevance: 0
  }, m = {
    className: "operator",
    relevance: 0,
    variants: [
      { match: Vo },
      {
        // dot-operator: only operators that start with a dot are allowed to use dots as
        // characters (..., ...<, .*, etc). So there rule here is: a dot followed by one or more
        // characters that may also include dots.
        match: `\\.(\\.|${zp})+`
      }
    ]
  }, g = [
    h,
    m
  ], v = "([0-9]_*)+", y = "([0-9a-fA-F]_*)+", E = {
    className: "number",
    relevance: 0,
    variants: [
      // decimal floating-point-literal (subsumes decimal-literal)
      { match: `\\b(${v})(\\.(${v}))?([eE][+-]?(${v}))?\\b` },
      // hexadecimal floating-point-literal (subsumes hexadecimal-literal)
      { match: `\\b0x(${y})(\\.(${y}))?([pP][+-]?(${v}))?\\b` },
      // octal-literal
      { match: /\b0o([0-7]_*)+\b/ },
      // binary-literal
      { match: /\b0b([01]_*)+\b/ }
    ]
  }, b = (ce = "") => ({
    className: "subst",
    variants: [
      { match: ye(/\\/, ce, /[0\\tnr"']/) },
      { match: ye(/\\/, ce, /u\{[0-9a-fA-F]{1,8}\}/) }
    ]
  }), C = (ce = "") => ({
    className: "subst",
    match: ye(/\\/, ce, /[\t ]*(?:[\r\n]|\r\n)/)
  }), w = (ce = "") => ({
    className: "subst",
    label: "interpol",
    begin: ye(/\\/, ce, /\(/),
    end: /\)/
  }), _ = (ce = "") => ({
    begin: ye(ce, /"""/),
    end: ye(/"""/, ce),
    contains: [
      b(ce),
      C(ce),
      w(ce)
    ]
  }), R = (ce = "") => ({
    begin: ye(ce, /"/),
    end: ye(/"/, ce),
    contains: [
      b(ce),
      w(ce)
    ]
  }), k = {
    className: "string",
    variants: [
      _(),
      _("#"),
      _("##"),
      _("###"),
      R(),
      R("#"),
      R("##"),
      R("###")
    ]
  }, $ = [
    t.BACKSLASH_ESCAPE,
    {
      begin: /\[/,
      end: /\]/,
      relevance: 0,
      contains: [t.BACKSLASH_ESCAPE]
    }
  ], Z = {
    begin: /\/[^\s](?=[^/\n]*\/)/,
    end: /\//,
    contains: $
  }, j = (ce) => {
    const ke = ye(ce, /\//), je = ye(/\//, ce);
    return {
      begin: ke,
      end: je,
      contains: [
        ...$,
        {
          scope: "comment",
          begin: `#(?!.*${je})`,
          end: /$/
        }
      ]
    };
  }, J = {
    scope: "regexp",
    variants: [
      j("###"),
      j("##"),
      j("#"),
      Z
    ]
  }, X = { match: ye(/`/, Wt, /`/) }, re = {
    className: "variable",
    match: /\$\d+/
  }, T = {
    className: "variable",
    match: `\\$${Os}+`
  }, x = [
    X,
    re,
    T
  ], S = {
    match: /(@|#(un)?)available/,
    scope: "keyword",
    starts: { contains: [
      {
        begin: /\(/,
        end: /\)/,
        keywords: YC,
        contains: [
          ...g,
          E,
          k
        ]
      }
    ] }
  }, O = {
    scope: "keyword",
    match: ye(/@/, rt(...jC))
  }, D = {
    scope: "meta",
    match: ye(/@/, Wt)
  }, F = [
    S,
    O,
    D
  ], Q = {
    match: Fi(/\b[A-Z]/),
    relevance: 0,
    contains: [
      {
        // Common Apple frameworks, for relevance boost
        className: "type",
        match: ye(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/, Os, "+")
      },
      {
        // Type identifier
        className: "type",
        match: zo,
        relevance: 0
      },
      {
        // Optional type
        match: /[?!]+/,
        relevance: 0
      },
      {
        // Variadic parameter
        match: /\.\.\./,
        relevance: 0
      },
      {
        // Protocol composition
        match: ye(/\s+&\s+/, Fi(zo)),
        relevance: 0
      }
    ]
  }, ue = {
    begin: /</,
    end: />/,
    keywords: c,
    contains: [
      ...r,
      ...d,
      ...F,
      h,
      Q
    ]
  };
  Q.contains.push(ue);
  const ge = {
    match: ye(Wt, /\s*:/),
    keywords: "_|0",
    relevance: 0
  }, le = {
    begin: /\(/,
    end: /\)/,
    relevance: 0,
    keywords: c,
    contains: [
      "self",
      ge,
      ...r,
      J,
      ...d,
      ...p,
      ...g,
      E,
      k,
      ...x,
      ...F,
      Q
    ]
  }, Ee = {
    begin: /</,
    end: />/,
    keywords: "repeat each",
    contains: [
      ...r,
      Q
    ]
  }, tt = {
    begin: rt(
      Fi(ye(Wt, /\s*:/)),
      Fi(ye(Wt, /\s+/, Wt, /\s*:/))
    ),
    end: /:/,
    relevance: 0,
    contains: [
      {
        className: "keyword",
        match: /\b_\b/
      },
      {
        className: "params",
        match: Wt
      }
    ]
  }, Pe = {
    begin: /\(/,
    end: /\)/,
    keywords: c,
    contains: [
      tt,
      ...r,
      ...d,
      ...g,
      E,
      k,
      ...F,
      Q,
      le
    ],
    endsParent: !0,
    illegal: /["']/
  }, lt = {
    match: [
      /(func|macro)/,
      /\s+/,
      rt(X.match, Wt, Vo)
    ],
    className: {
      1: "keyword",
      3: "title.function"
    },
    contains: [
      Ee,
      Pe,
      e
    ],
    illegal: [
      /\[/,
      /%/
    ]
  }, nt = {
    match: [
      /\b(?:subscript|init[?!]?)/,
      /\s*(?=[<(])/
    ],
    className: { 1: "keyword" },
    contains: [
      Ee,
      Pe,
      e
    ],
    illegal: /\[|%/
  }, mt = {
    match: [
      /operator/,
      /\s+/,
      Vo
    ],
    className: {
      1: "keyword",
      3: "title"
    }
  }, ct = {
    begin: [
      /precedencegroup/,
      /\s+/,
      zo
    ],
    className: {
      1: "keyword",
      3: "title"
    },
    contains: [Q],
    keywords: [
      ...ZC,
      ...Gd
    ],
    end: /}/
  };
  for (const ce of k.variants) {
    const ke = ce.contains.find((Ne) => Ne.label === "interpol");
    ke.keywords = c;
    const je = [
      ...d,
      ...p,
      ...g,
      E,
      k,
      ...x
    ];
    ke.contains = [
      ...je,
      {
        begin: /\(/,
        end: /\)/,
        contains: [
          "self",
          ...je
        ]
      }
    ];
  }
  return {
    name: "Swift",
    keywords: c,
    contains: [
      ...r,
      lt,
      nt,
      {
        beginKeywords: "struct protocol class extension enum actor",
        end: "\\{",
        excludeEnd: !0,
        keywords: c,
        contains: [
          t.inherit(t.TITLE_MODE, {
            className: "title.class",
            begin: /[A-Za-z$_][\u00C0-\u02B80-9A-Za-z$_]*/
          }),
          ...d
        ]
      },
      mt,
      ct,
      {
        beginKeywords: "import",
        end: /$/,
        contains: [...r],
        relevance: 0
      },
      J,
      ...d,
      ...p,
      ...g,
      E,
      k,
      ...x,
      ...F,
      Q,
      le
    ]
  };
}
const Rs = "[A-Za-z$_][0-9A-Za-z$_]*", Up = [
  "as",
  // for exports
  "in",
  "of",
  "if",
  "for",
  "while",
  "finally",
  "var",
  "new",
  "function",
  "do",
  "return",
  "void",
  "else",
  "break",
  "catch",
  "instanceof",
  "with",
  "throw",
  "case",
  "default",
  "try",
  "switch",
  "continue",
  "typeof",
  "delete",
  "let",
  "yield",
  "const",
  "class",
  // JS handles these with a special rule
  // "get",
  // "set",
  "debugger",
  "async",
  "await",
  "static",
  "import",
  "from",
  "export",
  "extends"
], Kp = [
  "true",
  "false",
  "null",
  "undefined",
  "NaN",
  "Infinity"
], Wp = [
  // Fundamental objects
  "Object",
  "Function",
  "Boolean",
  "Symbol",
  // numbers and dates
  "Math",
  "Date",
  "Number",
  "BigInt",
  // text
  "String",
  "RegExp",
  // Indexed collections
  "Array",
  "Float32Array",
  "Float64Array",
  "Int8Array",
  "Uint8Array",
  "Uint8ClampedArray",
  "Int16Array",
  "Int32Array",
  "Uint16Array",
  "Uint32Array",
  "BigInt64Array",
  "BigUint64Array",
  // Keyed collections
  "Set",
  "Map",
  "WeakSet",
  "WeakMap",
  // Structured data
  "ArrayBuffer",
  "SharedArrayBuffer",
  "Atomics",
  "DataView",
  "JSON",
  // Control abstraction objects
  "Promise",
  "Generator",
  "GeneratorFunction",
  "AsyncFunction",
  // Reflection
  "Reflect",
  "Proxy",
  // Internationalization
  "Intl",
  // WebAssembly
  "WebAssembly"
], qp = [
  "Error",
  "EvalError",
  "InternalError",
  "RangeError",
  "ReferenceError",
  "SyntaxError",
  "TypeError",
  "URIError"
], Zp = [
  "setInterval",
  "setTimeout",
  "clearInterval",
  "clearTimeout",
  "require",
  "exports",
  "eval",
  "isFinite",
  "isNaN",
  "parseFloat",
  "parseInt",
  "decodeURI",
  "decodeURIComponent",
  "encodeURI",
  "encodeURIComponent",
  "escape",
  "unescape"
], Gp = [
  "arguments",
  "this",
  "super",
  "console",
  "window",
  "document",
  "localStorage",
  "sessionStorage",
  "module",
  "global"
  // Node.js
], jp = [].concat(
  Zp,
  Wp,
  qp
);
function XC(t) {
  const e = t.regex, n = (S, { after: O }) => {
    const D = "</" + S[0].slice(1);
    return S.input.indexOf(D, O) !== -1;
  }, r = Rs, i = {
    begin: "<>",
    end: "</>"
  }, s = /<[A-Za-z0-9\\._:-]+\s*\/>/, o = {
    begin: /<[A-Za-z0-9\\._:-]+/,
    end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
    /**
     * @param {RegExpMatchArray} match
     * @param {CallbackResponse} response
     */
    isTrulyOpeningTag: (S, O) => {
      const D = S[0].length + S.index, F = S.input[D];
      if (
        // HTML should not include another raw `<` inside a tag
        // nested type?
        // `<Array<Array<number>>`, etc.
        F === "<" || // the , gives away that this is not HTML
        // `<T, A extends keyof T, V>`
        F === ","
      ) {
        O.ignoreMatch();
        return;
      }
      F === ">" && (n(S, { after: D }) || O.ignoreMatch());
      let Q;
      const ue = S.input.substring(D);
      if (Q = ue.match(/^\s*=/)) {
        O.ignoreMatch();
        return;
      }
      if ((Q = ue.match(/^\s+extends\s+/)) && Q.index === 0) {
        O.ignoreMatch();
        return;
      }
    }
  }, a = {
    $pattern: Rs,
    keyword: Up,
    literal: Kp,
    built_in: jp,
    "variable.language": Gp
  }, l = "[0-9](_?[0-9])*", c = `\\.(${l})`, d = "0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*", u = {
    className: "number",
    variants: [
      // DecimalLiteral
      { begin: `(\\b(${d})((${c})|\\.)?|(${c}))[eE][+-]?(${l})\\b` },
      { begin: `\\b(${d})\\b((${c})\\b|\\.)?|(${c})\\b` },
      // DecimalBigIntegerLiteral
      { begin: "\\b(0|[1-9](_?[0-9])*)n\\b" },
      // NonDecimalIntegerLiteral
      { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
      { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
      { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
      // LegacyOctalIntegerLiteral (does not include underscore separators)
      // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
      { begin: "\\b0[0-7]+n?\\b" }
    ],
    relevance: 0
  }, f = {
    className: "subst",
    begin: "\\$\\{",
    end: "\\}",
    keywords: a,
    contains: []
    // defined later
  }, p = {
    begin: "html`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "xml"
    }
  }, h = {
    begin: "css`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "css"
    }
  }, m = {
    begin: "gql`",
    end: "",
    starts: {
      end: "`",
      returnEnd: !1,
      contains: [
        t.BACKSLASH_ESCAPE,
        f
      ],
      subLanguage: "graphql"
    }
  }, g = {
    className: "string",
    begin: "`",
    end: "`",
    contains: [
      t.BACKSLASH_ESCAPE,
      f
    ]
  }, y = {
    className: "comment",
    variants: [
      t.COMMENT(
        /\/\*\*(?!\/)/,
        "\\*/",
        {
          relevance: 0,
          contains: [
            {
              begin: "(?=@[A-Za-z]+)",
              relevance: 0,
              contains: [
                {
                  className: "doctag",
                  begin: "@[A-Za-z]+"
                },
                {
                  className: "type",
                  begin: "\\{",
                  end: "\\}",
                  excludeEnd: !0,
                  excludeBegin: !0,
                  relevance: 0
                },
                {
                  className: "variable",
                  begin: r + "(?=\\s*(-)|$)",
                  endsParent: !0,
                  relevance: 0
                },
                // eat spaces (not newlines) so we can find
                // types or variables
                {
                  begin: /(?=[^\n])\s/,
                  relevance: 0
                }
              ]
            }
          ]
        }
      ),
      t.C_BLOCK_COMMENT_MODE,
      t.C_LINE_COMMENT_MODE
    ]
  }, E = [
    t.APOS_STRING_MODE,
    t.QUOTE_STRING_MODE,
    p,
    h,
    m,
    g,
    // Skip numbers when they are part of a variable name
    { match: /\$\d+/ },
    u
    // This is intentional:
    // See https://github.com/highlightjs/highlight.js/issues/3288
    // hljs.REGEXP_MODE
  ];
  f.contains = E.concat({
    // we need to pair up {} inside our subst to prevent
    // it from ending too early by matching another }
    begin: /\{/,
    end: /\}/,
    keywords: a,
    contains: [
      "self"
    ].concat(E)
  });
  const b = [].concat(y, f.contains), C = b.concat([
    // eat recursive parens in sub expressions
    {
      begin: /\(/,
      end: /\)/,
      keywords: a,
      contains: ["self"].concat(b)
    }
  ]), w = {
    className: "params",
    begin: /\(/,
    end: /\)/,
    excludeBegin: !0,
    excludeEnd: !0,
    keywords: a,
    contains: C
  }, _ = {
    variants: [
      // class Car extends vehicle
      {
        match: [
          /class/,
          /\s+/,
          r,
          /\s+/,
          /extends/,
          /\s+/,
          e.concat(r, "(", e.concat(/\./, r), ")*")
        ],
        scope: {
          1: "keyword",
          3: "title.class",
          5: "keyword",
          7: "title.class.inherited"
        }
      },
      // class Car
      {
        match: [
          /class/,
          /\s+/,
          r
        ],
        scope: {
          1: "keyword",
          3: "title.class"
        }
      }
    ]
  }, R = {
    relevance: 0,
    match: e.either(
      // Hard coded exceptions
      /\bJSON/,
      // Float32Array, OutT
      /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
      // CSSFactory, CSSFactoryT
      /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
      // FPs, FPsT
      /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
      // P
      // single letters are not highlighted
      // BLAH
      // this will be flagged as a UPPER_CASE_CONSTANT instead
    ),
    className: "title.class",
    keywords: {
      _: [
        // se we still get relevance credit for JS library classes
        ...Wp,
        ...qp
      ]
    }
  }, k = {
    label: "use_strict",
    className: "meta",
    relevance: 10,
    begin: /^\s*['"]use (strict|asm)['"]/
  }, $ = {
    variants: [
      {
        match: [
          /function/,
          /\s+/,
          r,
          /(?=\s*\()/
        ]
      },
      // anonymous function
      {
        match: [
          /function/,
          /\s*(?=\()/
        ]
      }
    ],
    className: {
      1: "keyword",
      3: "title.function"
    },
    label: "func.def",
    contains: [w],
    illegal: /%/
  }, Z = {
    relevance: 0,
    match: /\b[A-Z][A-Z_0-9]+\b/,
    className: "variable.constant"
  };
  function j(S) {
    return e.concat("(?!", S.join("|"), ")");
  }
  const J = {
    match: e.concat(
      /\b/,
      j([
        ...Zp,
        "super",
        "import"
      ]),
      r,
      e.lookahead(/\(/)
    ),
    className: "title.function",
    relevance: 0
  }, X = {
    begin: e.concat(/\./, e.lookahead(
      e.concat(r, /(?![0-9A-Za-z$_(])/)
    )),
    end: r,
    excludeBegin: !0,
    keywords: "prototype",
    className: "property",
    relevance: 0
  }, re = {
    match: [
      /get|set/,
      /\s+/,
      r,
      /(?=\()/
    ],
    className: {
      1: "keyword",
      3: "title.function"
    },
    contains: [
      {
        // eat to avoid empty params
        begin: /\(\)/
      },
      w
    ]
  }, T = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + t.UNDERSCORE_IDENT_RE + ")\\s*=>", x = {
    match: [
      /const|var|let/,
      /\s+/,
      r,
      /\s*/,
      /=\s*/,
      /(async\s*)?/,
      // async is optional
      e.lookahead(T)
    ],
    keywords: "async",
    className: {
      1: "keyword",
      3: "title.function"
    },
    contains: [
      w
    ]
  };
  return {
    name: "JavaScript",
    aliases: ["js", "jsx", "mjs", "cjs"],
    keywords: a,
    // this will be extended by TypeScript
    exports: { PARAMS_CONTAINS: C, CLASS_REFERENCE: R },
    illegal: /#(?![$_A-z])/,
    contains: [
      t.SHEBANG({
        label: "shebang",
        binary: "node",
        relevance: 5
      }),
      k,
      t.APOS_STRING_MODE,
      t.QUOTE_STRING_MODE,
      p,
      h,
      m,
      g,
      y,
      // Skip numbers when they are part of a variable name
      { match: /\$\d+/ },
      u,
      R,
      {
        className: "attr",
        begin: r + e.lookahead(":"),
        relevance: 0
      },
      x,
      {
        // "value" container
        begin: "(" + t.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
        keywords: "return throw case",
        relevance: 0,
        contains: [
          y,
          t.REGEXP_MODE,
          {
            className: "function",
            // we have to count the parens to make sure we actually have the
            // correct bounding ( ) before the =>.  There could be any number of
            // sub-expressions inside also surrounded by parens.
            begin: T,
            returnBegin: !0,
            end: "\\s*=>",
            contains: [
              {
                className: "params",
                variants: [
                  {
                    begin: t.UNDERSCORE_IDENT_RE,
                    relevance: 0
                  },
                  {
                    className: null,
                    begin: /\(\s*\)/,
                    skip: !0
                  },
                  {
                    begin: /\(/,
                    end: /\)/,
                    excludeBegin: !0,
                    excludeEnd: !0,
                    keywords: a,
                    contains: C
                  }
                ]
              }
            ]
          },
          {
            // could be a comma delimited list of params to a function call
            begin: /,/,
            relevance: 0
          },
          {
            match: /\s+/,
            relevance: 0
          },
          {
            // JSX
            variants: [
              { begin: i.begin, end: i.end },
              { match: s },
              {
                begin: o.begin,
                // we carefully check the opening tag to see if it truly
                // is a tag and not a false positive
                "on:begin": o.isTrulyOpeningTag,
                end: o.end
              }
            ],
            subLanguage: "xml",
            contains: [
              {
                begin: o.begin,
                end: o.end,
                skip: !0,
                contains: ["self"]
              }
            ]
          }
        ]
      },
      $,
      {
        // prevent this from getting swallowed up by function
        // since they appear "function like"
        beginKeywords: "while if switch catch for"
      },
      {
        // we have to count the parens to make sure we actually have the correct
        // bounding ( ).  There could be any number of sub-expressions inside
        // also surrounded by parens.
        begin: "\\b(?!function)" + t.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
        // end parens
        returnBegin: !0,
        label: "func.def",
        contains: [
          w,
          t.inherit(t.TITLE_MODE, { begin: r, className: "title.function" })
        ]
      },
      // catch ... so it won't trigger the property rule below
      {
        match: /\.\.\./,
        relevance: 0
      },
      X,
      // hack: prevents detection of keywords in some circumstances
      // .keyword()
      // $keyword = x
      {
        match: "\\$" + r,
        relevance: 0
      },
      {
        match: [/\bconstructor(?=\s*\()/],
        className: { 1: "title.function" },
        contains: [w]
      },
      J,
      Z,
      _,
      re,
      {
        match: /\$[(.]/
        // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
      }
    ]
  };
}
function QC(t) {
  const e = XC(t), n = Rs, r = [
    "any",
    "void",
    "number",
    "boolean",
    "string",
    "object",
    "never",
    "symbol",
    "bigint",
    "unknown"
  ], i = {
    beginKeywords: "namespace",
    end: /\{/,
    excludeEnd: !0,
    contains: [e.exports.CLASS_REFERENCE]
  }, s = {
    beginKeywords: "interface",
    end: /\{/,
    excludeEnd: !0,
    keywords: {
      keyword: "interface extends",
      built_in: r
    },
    contains: [e.exports.CLASS_REFERENCE]
  }, o = {
    className: "meta",
    relevance: 10,
    begin: /^\s*['"]use strict['"]/
  }, a = [
    "type",
    "namespace",
    "interface",
    "public",
    "private",
    "protected",
    "implements",
    "declare",
    "abstract",
    "readonly",
    "enum",
    "override"
  ], l = {
    $pattern: Rs,
    keyword: Up.concat(a),
    literal: Kp,
    built_in: jp.concat(r),
    "variable.language": Gp
  }, c = {
    className: "meta",
    begin: "@" + n
  }, d = (f, p, h) => {
    const m = f.contains.findIndex((g) => g.label === p);
    if (m === -1)
      throw new Error("can not find mode to replace");
    f.contains.splice(m, 1, h);
  };
  Object.assign(e.keywords, l), e.exports.PARAMS_CONTAINS.push(c), e.contains = e.contains.concat([
    c,
    i,
    s
  ]), d(e, "shebang", t.SHEBANG()), d(e, "use_strict", o);
  const u = e.contains.find((f) => f.label === "func.def");
  return u.relevance = 0, Object.assign(e, {
    name: "TypeScript",
    aliases: [
      "ts",
      "tsx",
      "mts",
      "cts"
    ]
  }), e;
}
function eM(t) {
  const e = t.regex, n = {
    className: "string",
    begin: /"(""|[^/n])"C\b/
  }, r = {
    className: "string",
    begin: /"/,
    end: /"/,
    illegal: /\n/,
    contains: [
      {
        // double quote escape
        begin: /""/
      }
    ]
  }, i = /\d{1,2}\/\d{1,2}\/\d{4}/, s = /\d{4}-\d{1,2}-\d{1,2}/, o = /(\d|1[012])(:\d+){0,2} *(AM|PM)/, a = /\d{1,2}(:\d{1,2}){1,2}/, l = {
    className: "literal",
    variants: [
      {
        // #YYYY-MM-DD# (ISO-Date) or #M/D/YYYY# (US-Date)
        begin: e.concat(/# */, e.either(s, i), / *#/)
      },
      {
        // #H:mm[:ss]# (24h Time)
        begin: e.concat(/# */, a, / *#/)
      },
      {
        // #h[:mm[:ss]] A# (12h Time)
        begin: e.concat(/# */, o, / *#/)
      },
      {
        // date plus time
        begin: e.concat(
          /# */,
          e.either(s, i),
          / +/,
          e.either(o, a),
          / *#/
        )
      }
    ]
  }, c = {
    className: "number",
    relevance: 0,
    variants: [
      {
        // Float
        begin: /\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/
      },
      {
        // Integer (base 10)
        begin: /\b\d[\d_]*((U?[SIL])|[%&])?/
      },
      {
        // Integer (base 16)
        begin: /&H[\dA-F_]+((U?[SIL])|[%&])?/
      },
      {
        // Integer (base 8)
        begin: /&O[0-7_]+((U?[SIL])|[%&])?/
      },
      {
        // Integer (base 2)
        begin: /&B[01_]+((U?[SIL])|[%&])?/
      }
    ]
  }, d = {
    className: "label",
    begin: /^\w+:/
  }, u = t.COMMENT(/'''/, /$/, { contains: [
    {
      className: "doctag",
      begin: /<\/?/,
      end: />/
    }
  ] }), f = t.COMMENT(null, /$/, { variants: [
    { begin: /'/ },
    {
      // TODO: Use multi-class for leading spaces
      begin: /([\t ]|^)REM(?=\s)/
    }
  ] });
  return {
    name: "Visual Basic .NET",
    aliases: ["vb"],
    case_insensitive: !0,
    classNameAliases: { label: "symbol" },
    keywords: {
      keyword: "addhandler alias aggregate ansi as async assembly auto binary by byref byval call case catch class compare const continue custom declare default delegate dim distinct do each equals else elseif end enum erase error event exit explicit finally for friend from function get global goto group handles if implements imports in inherits interface into iterator join key let lib loop me mid module mustinherit mustoverride mybase myclass namespace narrowing new next notinheritable notoverridable of off on operator option optional order overloads overridable overrides paramarray partial preserve private property protected public raiseevent readonly redim removehandler resume return select set shadows shared skip static step stop structure strict sub synclock take text then throw to try unicode until using when where while widening with withevents writeonly yield",
      built_in: (
        // Operators https://docs.microsoft.com/dotnet/visual-basic/language-reference/operators
        "addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort"
      ),
      type: (
        // Data types https://docs.microsoft.com/dotnet/visual-basic/language-reference/data-types
        "boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort"
      ),
      literal: "true false nothing"
    },
    illegal: "//|\\{|\\}|endif|gosub|variant|wend|^\\$ ",
    contains: [
      n,
      r,
      l,
      c,
      d,
      u,
      f,
      {
        className: "meta",
        // TODO: Use multi-class for indentation once available
        begin: /[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/,
        end: /$/,
        keywords: { keyword: "const disable else elseif enable end externalsource if region then" },
        contains: [f]
      }
    ]
  };
}
function tM(t) {
  t.regex;
  const e = t.COMMENT(/\(;/, /;\)/);
  e.contains.push("self");
  const n = t.COMMENT(/;;/, /$/), r = [
    "anyfunc",
    "block",
    "br",
    "br_if",
    "br_table",
    "call",
    "call_indirect",
    "data",
    "drop",
    "elem",
    "else",
    "end",
    "export",
    "func",
    "global.get",
    "global.set",
    "local.get",
    "local.set",
    "local.tee",
    "get_global",
    "get_local",
    "global",
    "if",
    "import",
    "local",
    "loop",
    "memory",
    "memory.grow",
    "memory.size",
    "module",
    "mut",
    "nop",
    "offset",
    "param",
    "result",
    "return",
    "select",
    "set_global",
    "set_local",
    "start",
    "table",
    "tee_local",
    "then",
    "type",
    "unreachable"
  ], i = {
    begin: [
      /(?:func|call|call_indirect)/,
      /\s+/,
      /\$[^\s)]+/
    ],
    className: {
      1: "keyword",
      3: "title.function"
    }
  }, s = {
    className: "variable",
    begin: /\$[\w_]+/
  }, o = {
    match: /(\((?!;)|\))+/,
    className: "punctuation",
    relevance: 0
  }, a = {
    className: "number",
    relevance: 0,
    // borrowed from Prism, TODO: split out into variants
    match: /[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/
  }, l = {
    // look-ahead prevents us from gobbling up opcodes
    match: /(i32|i64|f32|f64)(?!\.)/,
    className: "type"
  }, c = {
    className: "keyword",
    // borrowed from Prism, TODO: split out into variants
    match: /\b(f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|nearest|neg?|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|store(?:8|16|32)?|sqrt|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))\b/
  };
  return {
    name: "WebAssembly",
    keywords: {
      $pattern: /[\w.]+/,
      keyword: r
    },
    contains: [
      n,
      e,
      {
        match: [
          /(?:offset|align)/,
          /\s*/,
          /=/
        ],
        className: {
          1: "keyword",
          3: "operator"
        }
      },
      s,
      o,
      i,
      t.QUOTE_STRING_MODE,
      l,
      c,
      a
    ]
  };
}
function nM(t) {
  const e = t.regex, n = e.concat(/[\p{L}_]/u, e.optional(/[\p{L}0-9_.-]*:/u), /[\p{L}0-9_.-]*/u), r = /[\p{L}0-9._:-]+/u, i = {
    className: "symbol",
    begin: /&[a-z]+;|&#[0-9]+;|&#x[a-f0-9]+;/
  }, s = {
    begin: /\s/,
    contains: [
      {
        className: "keyword",
        begin: /#?[a-z_][a-z1-9_-]+/,
        illegal: /\n/
      }
    ]
  }, o = t.inherit(s, {
    begin: /\(/,
    end: /\)/
  }), a = t.inherit(t.APOS_STRING_MODE, { className: "string" }), l = t.inherit(t.QUOTE_STRING_MODE, { className: "string" }), c = {
    endsWithParent: !0,
    illegal: /</,
    relevance: 0,
    contains: [
      {
        className: "attr",
        begin: r,
        relevance: 0
      },
      {
        begin: /=\s*/,
        relevance: 0,
        contains: [
          {
            className: "string",
            endsParent: !0,
            variants: [
              {
                begin: /"/,
                end: /"/,
                contains: [i]
              },
              {
                begin: /'/,
                end: /'/,
                contains: [i]
              },
              { begin: /[^\s"'=<>`]+/ }
            ]
          }
        ]
      }
    ]
  };
  return {
    name: "HTML, XML",
    aliases: [
      "html",
      "xhtml",
      "rss",
      "atom",
      "xjb",
      "xsd",
      "xsl",
      "plist",
      "wsf",
      "svg"
    ],
    case_insensitive: !0,
    unicodeRegex: !0,
    contains: [
      {
        className: "meta",
        begin: /<![a-z]/,
        end: />/,
        relevance: 10,
        contains: [
          s,
          l,
          a,
          o,
          {
            begin: /\[/,
            end: /\]/,
            contains: [
              {
                className: "meta",
                begin: /<![a-z]/,
                end: />/,
                contains: [
                  s,
                  o,
                  l,
                  a
                ]
              }
            ]
          }
        ]
      },
      t.COMMENT(
        /<!--/,
        /-->/,
        { relevance: 10 }
      ),
      {
        begin: /<!\[CDATA\[/,
        end: /\]\]>/,
        relevance: 10
      },
      i,
      // xml processing instructions
      {
        className: "meta",
        end: /\?>/,
        variants: [
          {
            begin: /<\?xml/,
            relevance: 10,
            contains: [
              l
            ]
          },
          {
            begin: /<\?[a-z][a-z0-9]+/
          }
        ]
      },
      {
        className: "tag",
        /*
        The lookahead pattern (?=...) ensures that 'begin' only matches
        '<style' as a single word, followed by a whitespace or an
        ending bracket.
        */
        begin: /<style(?=\s|>)/,
        end: />/,
        keywords: { name: "style" },
        contains: [c],
        starts: {
          end: /<\/style>/,
          returnEnd: !0,
          subLanguage: [
            "css",
            "xml"
          ]
        }
      },
      {
        className: "tag",
        // See the comment in the <style tag about the lookahead pattern
        begin: /<script(?=\s|>)/,
        end: />/,
        keywords: { name: "script" },
        contains: [c],
        starts: {
          end: /<\/script>/,
          returnEnd: !0,
          subLanguage: [
            "javascript",
            "handlebars",
            "xml"
          ]
        }
      },
      // we need this for now for jSX
      {
        className: "tag",
        begin: /<>|<\/>/
      },
      // open tag
      {
        className: "tag",
        begin: e.concat(
          /</,
          e.lookahead(e.concat(
            n,
            // <tag/>
            // <tag>
            // <tag ...
            e.either(/\/>/, />/, /\s/)
          ))
        ),
        end: /\/?>/,
        contains: [
          {
            className: "name",
            begin: n,
            relevance: 0,
            starts: c
          }
        ]
      },
      // close tag
      {
        className: "tag",
        begin: e.concat(
          /<\//,
          e.lookahead(e.concat(
            n,
            />/
          ))
        ),
        contains: [
          {
            className: "name",
            begin: n,
            relevance: 0
          },
          {
            begin: />/,
            relevance: 0,
            endsParent: !0
          }
        ]
      }
    ]
  };
}
function rM(t) {
  const e = "true false yes no null", n = "[\\w#;/?:@&=+$,.~*'()[\\]]+", r = {
    className: "attr",
    variants: [
      { begin: "\\w[\\w :\\/.-]*:(?=[ 	]|$)" },
      {
        // double quoted keys
        begin: '"\\w[\\w :\\/.-]*":(?=[ 	]|$)'
      },
      {
        // single quoted keys
        begin: "'\\w[\\w :\\/.-]*':(?=[ 	]|$)"
      }
    ]
  }, i = {
    className: "template-variable",
    variants: [
      {
        // jinja templates Ansible
        begin: /\{\{/,
        end: /\}\}/
      },
      {
        // Ruby i18n
        begin: /%\{/,
        end: /\}/
      }
    ]
  }, s = {
    className: "string",
    relevance: 0,
    variants: [
      {
        begin: /'/,
        end: /'/
      },
      {
        begin: /"/,
        end: /"/
      },
      { begin: /\S+/ }
    ],
    contains: [
      t.BACKSLASH_ESCAPE,
      i
    ]
  }, o = t.inherit(s, { variants: [
    {
      begin: /'/,
      end: /'/
    },
    {
      begin: /"/,
      end: /"/
    },
    { begin: /[^\s,{}[\]]+/ }
  ] }), a = "[0-9]{4}(-[0-9][0-9]){0,2}", l = "([Tt \\t][0-9][0-9]?(:[0-9][0-9]){2})?", c = "(\\.[0-9]*)?", d = "([ \\t])*(Z|[-+][0-9][0-9]?(:[0-9][0-9])?)?", u = {
    className: "number",
    begin: "\\b" + a + l + c + d + "\\b"
  }, f = {
    end: ",",
    endsWithParent: !0,
    excludeEnd: !0,
    keywords: e,
    relevance: 0
  }, p = {
    begin: /\{/,
    end: /\}/,
    contains: [f],
    illegal: "\\n",
    relevance: 0
  }, h = {
    begin: "\\[",
    end: "\\]",
    contains: [f],
    illegal: "\\n",
    relevance: 0
  }, m = [
    r,
    {
      className: "meta",
      begin: "^---\\s*$",
      relevance: 10
    },
    {
      // multi line string
      // Blocks start with a | or > followed by a newline
      //
      // Indentation of subsequent lines must be the same to
      // be considered part of the block
      className: "string",
      begin: "[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*"
    },
    {
      // Ruby/Rails erb
      begin: "<%[%=-]?",
      end: "[%-]?%>",
      subLanguage: "ruby",
      excludeBegin: !0,
      excludeEnd: !0,
      relevance: 0
    },
    {
      // named tags
      className: "type",
      begin: "!\\w+!" + n
    },
    // https://yaml.org/spec/1.2/spec.html#id2784064
    {
      // verbatim tags
      className: "type",
      begin: "!<" + n + ">"
    },
    {
      // primary tags
      className: "type",
      begin: "!" + n
    },
    {
      // secondary tags
      className: "type",
      begin: "!!" + n
    },
    {
      // fragment id &ref
      className: "meta",
      begin: "&" + t.UNDERSCORE_IDENT_RE + "$"
    },
    {
      // fragment reference *ref
      className: "meta",
      begin: "\\*" + t.UNDERSCORE_IDENT_RE + "$"
    },
    {
      // array listing
      className: "bullet",
      // TODO: remove |$ hack when we have proper look-ahead support
      begin: "-(?=[ ]|$)",
      relevance: 0
    },
    t.HASH_COMMENT_MODE,
    {
      beginKeywords: e,
      keywords: { literal: e }
    },
    u,
    // numbers are any valid C-style number that
    // sit isolated from other words
    {
      className: "number",
      begin: t.C_NUMBER_RE + "\\b",
      relevance: 0
    },
    p,
    h,
    s
  ], g = [...m];
  return g.pop(), g.push(o), f.contains = g, {
    name: "YAML",
    case_insensitive: !0,
    aliases: ["yml"],
    contains: m
  };
}
const iM = {
  arduino: WS,
  bash: qS,
  c: ZS,
  cpp: GS,
  csharp: jS,
  css: nC,
  diff: rC,
  go: iC,
  graphql: sC,
  ini: oC,
  java: aC,
  javascript: fC,
  json: pC,
  kotlin: mC,
  less: EC,
  lua: xC,
  makefile: SC,
  markdown: CC,
  objectivec: MC,
  perl: kC,
  php: TC,
  "php-template": _C,
  plaintext: NC,
  python: AC,
  "python-repl": OC,
  r: RC,
  ruby: LC,
  rust: IC,
  scss: zC,
  shell: FC,
  sql: UC,
  swift: JC,
  typescript: QC,
  vbnet: eM,
  wasm: tM,
  xml: nM,
  yaml: rM
};
function Yp(t) {
  return t instanceof Map ? t.clear = t.delete = t.set = function() {
    throw new Error("map is read-only");
  } : t instanceof Set && (t.add = t.clear = t.delete = function() {
    throw new Error("set is read-only");
  }), Object.freeze(t), Object.getOwnPropertyNames(t).forEach((e) => {
    const n = t[e], r = typeof n;
    (r === "object" || r === "function") && !Object.isFrozen(n) && Yp(n);
  }), t;
}
class Yd {
  /**
   * @param {CompiledMode} mode
   */
  constructor(e) {
    e.data === void 0 && (e.data = {}), this.data = e.data, this.isMatchIgnored = !1;
  }
  ignoreMatch() {
    this.isMatchIgnored = !0;
  }
}
function Jp(t) {
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;");
}
function fn(t, ...e) {
  const n = /* @__PURE__ */ Object.create(null);
  for (const r in t)
    n[r] = t[r];
  return e.forEach(function(r) {
    for (const i in r)
      n[i] = r[i];
  }), /** @type {T} */
  n;
}
const sM = "</span>", Jd = (t) => !!t.scope, oM = (t, { prefix: e }) => {
  if (t.startsWith("language:"))
    return t.replace("language:", "language-");
  if (t.includes(".")) {
    const n = t.split(".");
    return [
      `${e}${n.shift()}`,
      ...n.map((r, i) => `${r}${"_".repeat(i + 1)}`)
    ].join(" ");
  }
  return `${e}${t}`;
};
class aM {
  /**
   * Creates a new HTMLRenderer
   *
   * @param {Tree} parseTree - the parse tree (must support `walk` API)
   * @param {{classPrefix: string}} options
   */
  constructor(e, n) {
    this.buffer = "", this.classPrefix = n.classPrefix, e.walk(this);
  }
  /**
   * Adds texts to the output stream
   *
   * @param {string} text */
  addText(e) {
    this.buffer += Jp(e);
  }
  /**
   * Adds a node open to the output stream (if needed)
   *
   * @param {Node} node */
  openNode(e) {
    if (!Jd(e))
      return;
    const n = oM(
      e.scope,
      { prefix: this.classPrefix }
    );
    this.span(n);
  }
  /**
   * Adds a node close to the output stream (if needed)
   *
   * @param {Node} node */
  closeNode(e) {
    Jd(e) && (this.buffer += sM);
  }
  /**
   * returns the accumulated buffer
  */
  value() {
    return this.buffer;
  }
  // helpers
  /**
   * Builds a span element
   *
   * @param {string} className */
  span(e) {
    this.buffer += `<span class="${e}">`;
  }
}
const Xd = (t = {}) => {
  const e = { children: [] };
  return Object.assign(e, t), e;
};
class xl {
  constructor() {
    this.rootNode = Xd(), this.stack = [this.rootNode];
  }
  get top() {
    return this.stack[this.stack.length - 1];
  }
  get root() {
    return this.rootNode;
  }
  /** @param {Node} node */
  add(e) {
    this.top.children.push(e);
  }
  /** @param {string} scope */
  openNode(e) {
    const n = Xd({ scope: e });
    this.add(n), this.stack.push(n);
  }
  closeNode() {
    if (this.stack.length > 1)
      return this.stack.pop();
  }
  closeAllNodes() {
    for (; this.closeNode(); )
      ;
  }
  toJSON() {
    return JSON.stringify(this.rootNode, null, 4);
  }
  /**
   * @typedef { import("./html_renderer").Renderer } Renderer
   * @param {Renderer} builder
   */
  walk(e) {
    return this.constructor._walk(e, this.rootNode);
  }
  /**
   * @param {Renderer} builder
   * @param {Node} node
   */
  static _walk(e, n) {
    return typeof n == "string" ? e.addText(n) : n.children && (e.openNode(n), n.children.forEach((r) => this._walk(e, r)), e.closeNode(n)), e;
  }
  /**
   * @param {Node} node
   */
  static _collapse(e) {
    typeof e != "string" && e.children && (e.children.every((n) => typeof n == "string") ? e.children = [e.children.join("")] : e.children.forEach((n) => {
      xl._collapse(n);
    }));
  }
}
class lM extends xl {
  /**
   * @param {*} options
   */
  constructor(e) {
    super(), this.options = e;
  }
  /**
   * @param {string} text
   */
  addText(e) {
    e !== "" && this.add(e);
  }
  /** @param {string} scope */
  startScope(e) {
    this.openNode(e);
  }
  endScope() {
    this.closeNode();
  }
  /**
   * @param {Emitter & {root: DataNode}} emitter
   * @param {string} name
   */
  __addSublanguage(e, n) {
    const r = e.root;
    n && (r.scope = `language:${n}`), this.add(r);
  }
  toHTML() {
    return new aM(this, this.options).value();
  }
  finalize() {
    return this.closeAllNodes(), !0;
  }
}
function hi(t) {
  return t ? typeof t == "string" ? t : t.source : null;
}
function Xp(t) {
  return Zn("(?=", t, ")");
}
function cM(t) {
  return Zn("(?:", t, ")*");
}
function dM(t) {
  return Zn("(?:", t, ")?");
}
function Zn(...t) {
  return t.map((n) => hi(n)).join("");
}
function uM(t) {
  const e = t[t.length - 1];
  return typeof e == "object" && e.constructor === Object ? (t.splice(t.length - 1, 1), e) : {};
}
function Sl(...t) {
  return "(" + (uM(t).capture ? "" : "?:") + t.map((r) => hi(r)).join("|") + ")";
}
function Qp(t) {
  return new RegExp(t.toString() + "|").exec("").length - 1;
}
function fM(t, e) {
  const n = t && t.exec(e);
  return n && n.index === 0;
}
const pM = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
function Cl(t, { joinWith: e }) {
  let n = 0;
  return t.map((r) => {
    n += 1;
    const i = n;
    let s = hi(r), o = "";
    for (; s.length > 0; ) {
      const a = pM.exec(s);
      if (!a) {
        o += s;
        break;
      }
      o += s.substring(0, a.index), s = s.substring(a.index + a[0].length), a[0][0] === "\\" && a[1] ? o += "\\" + String(Number(a[1]) + i) : (o += a[0], a[0] === "(" && n++);
    }
    return o;
  }).map((r) => `(${r})`).join(e);
}
const hM = /\b\B/, eh = "[a-zA-Z]\\w*", Ml = "[a-zA-Z_]\\w*", th = "\\b\\d+(\\.\\d+)?", nh = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)", rh = "\\b(0b[01]+)", mM = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~", gM = (t = {}) => {
  const e = /^#![ ]*\//;
  return t.binary && (t.begin = Zn(
    e,
    /.*\b/,
    t.binary,
    /\b.*/
  )), fn({
    scope: "meta",
    begin: e,
    end: /$/,
    relevance: 0,
    /** @type {ModeCallback} */
    "on:begin": (n, r) => {
      n.index !== 0 && r.ignoreMatch();
    }
  }, t);
}, mi = {
  begin: "\\\\[\\s\\S]",
  relevance: 0
}, bM = {
  scope: "string",
  begin: "'",
  end: "'",
  illegal: "\\n",
  contains: [mi]
}, yM = {
  scope: "string",
  begin: '"',
  end: '"',
  illegal: "\\n",
  contains: [mi]
}, vM = {
  begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
}, Xs = function(t, e, n = {}) {
  const r = fn(
    {
      scope: "comment",
      begin: t,
      end: e,
      contains: []
    },
    n
  );
  r.contains.push({
    scope: "doctag",
    // hack to avoid the space from being included. the space is necessary to
    // match here to prevent the plain text rule below from gobbling up doctags
    begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
    end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
    excludeBegin: !0,
    relevance: 0
  });
  const i = Sl(
    // list of common 1 and 2 letter words in English
    "I",
    "a",
    "is",
    "so",
    "us",
    "to",
    "at",
    "if",
    "in",
    "it",
    "on",
    // note: this is not an exhaustive list of contractions, just popular ones
    /[A-Za-z]+['](d|ve|re|ll|t|s|n)/,
    // contractions - can't we'd they're let's, etc
    /[A-Za-z]+[-][a-z]+/,
    // `no-way`, etc.
    /[A-Za-z][a-z]{2,}/
    // allow capitalized words at beginning of sentences
  );
  return r.contains.push(
    {
      // TODO: how to include ", (, ) without breaking grammars that use these for
      // comment delimiters?
      // begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/
      // ---
      // this tries to find sequences of 3 english words in a row (without any
      // "programming" type syntax) this gives us a strong signal that we've
      // TRULY found a comment - vs perhaps scanning with the wrong language.
      // It's possible to find something that LOOKS like the start of the
      // comment - but then if there is no readable text - good chance it is a
      // false match and not a comment.
      //
      // for a visual example please see:
      // https://github.com/highlightjs/highlight.js/issues/2827
      begin: Zn(
        /[ ]+/,
        // necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
        "(",
        i,
        /[.]?[:]?([.][ ]|[ ])/,
        "){3}"
      )
      // look for 3 words in a row
    }
  ), r;
}, wM = Xs("//", "$"), EM = Xs("/\\*", "\\*/"), xM = Xs("#", "$"), SM = {
  scope: "number",
  begin: th,
  relevance: 0
}, CM = {
  scope: "number",
  begin: nh,
  relevance: 0
}, MM = {
  scope: "number",
  begin: rh,
  relevance: 0
}, kM = {
  scope: "regexp",
  begin: /\/(?=[^/\n]*\/)/,
  end: /\/[gimuy]*/,
  contains: [
    mi,
    {
      begin: /\[/,
      end: /\]/,
      relevance: 0,
      contains: [mi]
    }
  ]
}, TM = {
  scope: "title",
  begin: eh,
  relevance: 0
}, _M = {
  scope: "title",
  begin: Ml,
  relevance: 0
}, NM = {
  // excludes method names from keyword processing
  begin: "\\.\\s*" + Ml,
  relevance: 0
}, AM = function(t) {
  return Object.assign(
    t,
    {
      /** @type {ModeCallback} */
      "on:begin": (e, n) => {
        n.data._beginMatch = e[1];
      },
      /** @type {ModeCallback} */
      "on:end": (e, n) => {
        n.data._beginMatch !== e[1] && n.ignoreMatch();
      }
    }
  );
};
var Ui = /* @__PURE__ */ Object.freeze({
  __proto__: null,
  APOS_STRING_MODE: bM,
  BACKSLASH_ESCAPE: mi,
  BINARY_NUMBER_MODE: MM,
  BINARY_NUMBER_RE: rh,
  COMMENT: Xs,
  C_BLOCK_COMMENT_MODE: EM,
  C_LINE_COMMENT_MODE: wM,
  C_NUMBER_MODE: CM,
  C_NUMBER_RE: nh,
  END_SAME_AS_BEGIN: AM,
  HASH_COMMENT_MODE: xM,
  IDENT_RE: eh,
  MATCH_NOTHING_RE: hM,
  METHOD_GUARD: NM,
  NUMBER_MODE: SM,
  NUMBER_RE: th,
  PHRASAL_WORDS_MODE: vM,
  QUOTE_STRING_MODE: yM,
  REGEXP_MODE: kM,
  RE_STARTERS_RE: mM,
  SHEBANG: gM,
  TITLE_MODE: TM,
  UNDERSCORE_IDENT_RE: Ml,
  UNDERSCORE_TITLE_MODE: _M
});
function OM(t, e) {
  t.input[t.index - 1] === "." && e.ignoreMatch();
}
function RM(t, e) {
  t.className !== void 0 && (t.scope = t.className, delete t.className);
}
function LM(t, e) {
  e && t.beginKeywords && (t.begin = "\\b(" + t.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)", t.__beforeBegin = OM, t.keywords = t.keywords || t.beginKeywords, delete t.beginKeywords, t.relevance === void 0 && (t.relevance = 0));
}
function IM(t, e) {
  Array.isArray(t.illegal) && (t.illegal = Sl(...t.illegal));
}
function DM(t, e) {
  if (t.match) {
    if (t.begin || t.end)
      throw new Error("begin & end are not supported with match");
    t.begin = t.match, delete t.match;
  }
}
function HM(t, e) {
  t.relevance === void 0 && (t.relevance = 1);
}
const BM = (t, e) => {
  if (!t.beforeMatch)
    return;
  if (t.starts)
    throw new Error("beforeMatch cannot be used with starts");
  const n = Object.assign({}, t);
  Object.keys(t).forEach((r) => {
    delete t[r];
  }), t.keywords = n.keywords, t.begin = Zn(n.beforeMatch, Xp(n.begin)), t.starts = {
    relevance: 0,
    contains: [
      Object.assign(n, { endsParent: !0 })
    ]
  }, t.relevance = 0, delete n.beforeMatch;
}, PM = [
  "of",
  "and",
  "for",
  "in",
  "not",
  "or",
  "if",
  "then",
  "parent",
  // common variable name
  "list",
  // common variable name
  "value"
  // common variable name
], $M = "keyword";
function ih(t, e, n = $M) {
  const r = /* @__PURE__ */ Object.create(null);
  return typeof t == "string" ? i(n, t.split(" ")) : Array.isArray(t) ? i(n, t) : Object.keys(t).forEach(function(s) {
    Object.assign(
      r,
      ih(t[s], e, s)
    );
  }), r;
  function i(s, o) {
    e && (o = o.map((a) => a.toLowerCase())), o.forEach(function(a) {
      const l = a.split("|");
      r[l[0]] = [s, VM(l[0], l[1])];
    });
  }
}
function VM(t, e) {
  return e ? Number(e) : zM(t) ? 0 : 1;
}
function zM(t) {
  return PM.includes(t.toLowerCase());
}
const Qd = {}, Pn = (t) => {
  console.error(t);
}, eu = (t, ...e) => {
  console.log(`WARN: ${t}`, ...e);
}, tr = (t, e) => {
  Qd[`${t}/${e}`] || (console.log(`Deprecated as of ${t}. ${e}`), Qd[`${t}/${e}`] = !0);
}, Ls = new Error();
function sh(t, e, { key: n }) {
  let r = 0;
  const i = t[n], s = {}, o = {};
  for (let a = 1; a <= e.length; a++)
    o[a + r] = i[a], s[a + r] = !0, r += Qp(e[a - 1]);
  t[n] = o, t[n]._emit = s, t[n]._multi = !0;
}
function FM(t) {
  if (Array.isArray(t.begin)) {
    if (t.skip || t.excludeBegin || t.returnBegin)
      throw Pn("skip, excludeBegin, returnBegin not compatible with beginScope: {}"), Ls;
    if (typeof t.beginScope != "object" || t.beginScope === null)
      throw Pn("beginScope must be object"), Ls;
    sh(t, t.begin, { key: "beginScope" }), t.begin = Cl(t.begin, { joinWith: "" });
  }
}
function UM(t) {
  if (Array.isArray(t.end)) {
    if (t.skip || t.excludeEnd || t.returnEnd)
      throw Pn("skip, excludeEnd, returnEnd not compatible with endScope: {}"), Ls;
    if (typeof t.endScope != "object" || t.endScope === null)
      throw Pn("endScope must be object"), Ls;
    sh(t, t.end, { key: "endScope" }), t.end = Cl(t.end, { joinWith: "" });
  }
}
function KM(t) {
  t.scope && typeof t.scope == "object" && t.scope !== null && (t.beginScope = t.scope, delete t.scope);
}
function WM(t) {
  KM(t), typeof t.beginScope == "string" && (t.beginScope = { _wrap: t.beginScope }), typeof t.endScope == "string" && (t.endScope = { _wrap: t.endScope }), FM(t), UM(t);
}
function qM(t) {
  function e(o, a) {
    return new RegExp(
      hi(o),
      "m" + (t.case_insensitive ? "i" : "") + (t.unicodeRegex ? "u" : "") + (a ? "g" : "")
    );
  }
  class n {
    constructor() {
      this.matchIndexes = {}, this.regexes = [], this.matchAt = 1, this.position = 0;
    }
    // @ts-ignore
    addRule(a, l) {
      l.position = this.position++, this.matchIndexes[this.matchAt] = l, this.regexes.push([l, a]), this.matchAt += Qp(a) + 1;
    }
    compile() {
      this.regexes.length === 0 && (this.exec = () => null);
      const a = this.regexes.map((l) => l[1]);
      this.matcherRe = e(Cl(a, { joinWith: "|" }), !0), this.lastIndex = 0;
    }
    /** @param {string} s */
    exec(a) {
      this.matcherRe.lastIndex = this.lastIndex;
      const l = this.matcherRe.exec(a);
      if (!l)
        return null;
      const c = l.findIndex((u, f) => f > 0 && u !== void 0), d = this.matchIndexes[c];
      return l.splice(0, c), Object.assign(l, d);
    }
  }
  class r {
    constructor() {
      this.rules = [], this.multiRegexes = [], this.count = 0, this.lastIndex = 0, this.regexIndex = 0;
    }
    // @ts-ignore
    getMatcher(a) {
      if (this.multiRegexes[a])
        return this.multiRegexes[a];
      const l = new n();
      return this.rules.slice(a).forEach(([c, d]) => l.addRule(c, d)), l.compile(), this.multiRegexes[a] = l, l;
    }
    resumingScanAtSamePosition() {
      return this.regexIndex !== 0;
    }
    considerAll() {
      this.regexIndex = 0;
    }
    // @ts-ignore
    addRule(a, l) {
      this.rules.push([a, l]), l.type === "begin" && this.count++;
    }
    /** @param {string} s */
    exec(a) {
      const l = this.getMatcher(this.regexIndex);
      l.lastIndex = this.lastIndex;
      let c = l.exec(a);
      if (this.resumingScanAtSamePosition() && !(c && c.index === this.lastIndex)) {
        const d = this.getMatcher(0);
        d.lastIndex = this.lastIndex + 1, c = d.exec(a);
      }
      return c && (this.regexIndex += c.position + 1, this.regexIndex === this.count && this.considerAll()), c;
    }
  }
  function i(o) {
    const a = new r();
    return o.contains.forEach((l) => a.addRule(l.begin, { rule: l, type: "begin" })), o.terminatorEnd && a.addRule(o.terminatorEnd, { type: "end" }), o.illegal && a.addRule(o.illegal, { type: "illegal" }), a;
  }
  function s(o, a) {
    const l = (
      /** @type CompiledMode */
      o
    );
    if (o.isCompiled)
      return l;
    [
      RM,
      // do this early so compiler extensions generally don't have to worry about
      // the distinction between match/begin
      DM,
      WM,
      BM
    ].forEach((d) => d(o, a)), t.compilerExtensions.forEach((d) => d(o, a)), o.__beforeBegin = null, [
      LM,
      // do this later so compiler extensions that come earlier have access to the
      // raw array if they wanted to perhaps manipulate it, etc.
      IM,
      // default to 1 relevance if not specified
      HM
    ].forEach((d) => d(o, a)), o.isCompiled = !0;
    let c = null;
    return typeof o.keywords == "object" && o.keywords.$pattern && (o.keywords = Object.assign({}, o.keywords), c = o.keywords.$pattern, delete o.keywords.$pattern), c = c || /\w+/, o.keywords && (o.keywords = ih(o.keywords, t.case_insensitive)), l.keywordPatternRe = e(c, !0), a && (o.begin || (o.begin = /\B|\b/), l.beginRe = e(l.begin), !o.end && !o.endsWithParent && (o.end = /\B|\b/), o.end && (l.endRe = e(l.end)), l.terminatorEnd = hi(l.end) || "", o.endsWithParent && a.terminatorEnd && (l.terminatorEnd += (o.end ? "|" : "") + a.terminatorEnd)), o.illegal && (l.illegalRe = e(
      /** @type {RegExp | string} */
      o.illegal
    )), o.contains || (o.contains = []), o.contains = [].concat(...o.contains.map(function(d) {
      return ZM(d === "self" ? o : d);
    })), o.contains.forEach(function(d) {
      s(
        /** @type Mode */
        d,
        l
      );
    }), o.starts && s(o.starts, a), l.matcher = i(l), l;
  }
  if (t.compilerExtensions || (t.compilerExtensions = []), t.contains && t.contains.includes("self"))
    throw new Error("ERR: contains `self` is not supported at the top-level of a language.  See documentation.");
  return t.classNameAliases = fn(t.classNameAliases || {}), s(
    /** @type Mode */
    t
  );
}
function oh(t) {
  return t ? t.endsWithParent || oh(t.starts) : !1;
}
function ZM(t) {
  return t.variants && !t.cachedVariants && (t.cachedVariants = t.variants.map(function(e) {
    return fn(t, { variants: null }, e);
  })), t.cachedVariants ? t.cachedVariants : oh(t) ? fn(t, { starts: t.starts ? fn(t.starts) : null }) : Object.isFrozen(t) ? fn(t) : t;
}
var GM = "11.9.0";
class jM extends Error {
  constructor(e, n) {
    super(e), this.name = "HTMLInjectionError", this.html = n;
  }
}
const Fo = Jp, tu = fn, nu = Symbol("nomatch"), YM = 7, ah = function(t) {
  const e = /* @__PURE__ */ Object.create(null), n = /* @__PURE__ */ Object.create(null), r = [];
  let i = !0;
  const s = "Could not find the language '{}', did you forget to load/include a language module?", o = { disableAutodetect: !0, name: "Plain text", contains: [] };
  let a = {
    ignoreUnescapedHTML: !1,
    throwUnescapedHTML: !1,
    noHighlightRe: /^(no-?highlight)$/i,
    languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
    classPrefix: "hljs-",
    cssSelector: "pre code",
    languages: null,
    // beta configuration options, subject to change, welcome to discuss
    // https://github.com/highlightjs/highlight.js/issues/1086
    __emitter: lM
  };
  function l(x) {
    return a.noHighlightRe.test(x);
  }
  function c(x) {
    let S = x.className + " ";
    S += x.parentNode ? x.parentNode.className : "";
    const O = a.languageDetectRe.exec(S);
    if (O) {
      const D = k(O[1]);
      return D || (eu(s.replace("{}", O[1])), eu("Falling back to no-highlight mode for this block.", x)), D ? O[1] : "no-highlight";
    }
    return S.split(/\s+/).find((D) => l(D) || k(D));
  }
  function d(x, S, O) {
    let D = "", F = "";
    typeof S == "object" ? (D = x, O = S.ignoreIllegals, F = S.language) : (tr("10.7.0", "highlight(lang, code, ...args) has been deprecated."), tr("10.7.0", `Please use highlight(code, options) instead.
https://github.com/highlightjs/highlight.js/issues/2277`), F = x, D = S), O === void 0 && (O = !0);
    const Q = {
      code: D,
      language: F
    };
    re("before:highlight", Q);
    const ue = Q.result ? Q.result : u(Q.language, Q.code, O);
    return ue.code = Q.code, re("after:highlight", ue), ue;
  }
  function u(x, S, O, D) {
    const F = /* @__PURE__ */ Object.create(null);
    function Q(N, L) {
      return N.keywords[L];
    }
    function ue() {
      if (!P.keywords) {
        he.addText(oe);
        return;
      }
      let N = 0;
      P.keywordPatternRe.lastIndex = 0;
      let L = P.keywordPatternRe.exec(oe), K = "";
      for (; L; ) {
        K += oe.substring(N, L.index);
        const se = Ne.case_insensitive ? L[0].toLowerCase() : L[0], Oe = Q(P, se);
        if (Oe) {
          const [dt, Qs] = Oe;
          if (he.addText(K), K = "", F[se] = (F[se] || 0) + 1, F[se] <= YM && (Ue += Qs), dt.startsWith("_"))
            K += L[0];
          else {
            const M = Ne.classNameAliases[dt] || dt;
            Ee(L[0], M);
          }
        } else
          K += L[0];
        N = P.keywordPatternRe.lastIndex, L = P.keywordPatternRe.exec(oe);
      }
      K += oe.substring(N), he.addText(K);
    }
    function ge() {
      if (oe === "")
        return;
      let N = null;
      if (typeof P.subLanguage == "string") {
        if (!e[P.subLanguage]) {
          he.addText(oe);
          return;
        }
        N = u(P.subLanguage, oe, !0, ae[P.subLanguage]), ae[P.subLanguage] = /** @type {CompiledMode} */
        N._top;
      } else
        N = p(oe, P.subLanguage.length ? P.subLanguage : null);
      P.relevance > 0 && (Ue += N.relevance), he.__addSublanguage(N._emitter, N.language);
    }
    function le() {
      P.subLanguage != null ? ge() : ue(), oe = "";
    }
    function Ee(N, L) {
      N !== "" && (he.startScope(L), he.addText(N), he.endScope());
    }
    function tt(N, L) {
      let K = 1;
      const se = L.length - 1;
      for (; K <= se; ) {
        if (!N._emit[K]) {
          K++;
          continue;
        }
        const Oe = Ne.classNameAliases[N[K]] || N[K], dt = L[K];
        Oe ? Ee(dt, Oe) : (oe = dt, ue(), oe = ""), K++;
      }
    }
    function Pe(N, L) {
      return N.scope && typeof N.scope == "string" && he.openNode(Ne.classNameAliases[N.scope] || N.scope), N.beginScope && (N.beginScope._wrap ? (Ee(oe, Ne.classNameAliases[N.beginScope._wrap] || N.beginScope._wrap), oe = "") : N.beginScope._multi && (tt(N.beginScope, L), oe = "")), P = Object.create(N, { parent: { value: P } }), P;
    }
    function lt(N, L, K) {
      let se = fM(N.endRe, K);
      if (se) {
        if (N["on:end"]) {
          const Oe = new Yd(N);
          N["on:end"](L, Oe), Oe.isMatchIgnored && (se = !1);
        }
        if (se) {
          for (; N.endsParent && N.parent; )
            N = N.parent;
          return N;
        }
      }
      if (N.endsWithParent)
        return lt(N.parent, L, K);
    }
    function nt(N) {
      return P.matcher.regexIndex === 0 ? (oe += N[0], 1) : (V = !0, 0);
    }
    function mt(N) {
      const L = N[0], K = N.rule, se = new Yd(K), Oe = [K.__beforeBegin, K["on:begin"]];
      for (const dt of Oe)
        if (dt && (dt(N, se), se.isMatchIgnored))
          return nt(L);
      return K.skip ? oe += L : (K.excludeBegin && (oe += L), le(), !K.returnBegin && !K.excludeBegin && (oe = L)), Pe(K, N), K.returnBegin ? 0 : L.length;
    }
    function ct(N) {
      const L = N[0], K = S.substring(N.index), se = lt(P, N, K);
      if (!se)
        return nu;
      const Oe = P;
      P.endScope && P.endScope._wrap ? (le(), Ee(L, P.endScope._wrap)) : P.endScope && P.endScope._multi ? (le(), tt(P.endScope, N)) : Oe.skip ? oe += L : (Oe.returnEnd || Oe.excludeEnd || (oe += L), le(), Oe.excludeEnd && (oe = L));
      do
        P.scope && he.closeNode(), !P.skip && !P.subLanguage && (Ue += P.relevance), P = P.parent;
      while (P !== se.parent);
      return se.starts && Pe(se.starts, N), Oe.returnEnd ? 0 : L.length;
    }
    function ce() {
      const N = [];
      for (let L = P; L !== Ne; L = L.parent)
        L.scope && N.unshift(L.scope);
      N.forEach((L) => he.openNode(L));
    }
    let ke = {};
    function je(N, L) {
      const K = L && L[0];
      if (oe += N, K == null)
        return le(), 0;
      if (ke.type === "begin" && L.type === "end" && ke.index === L.index && K === "") {
        if (oe += S.slice(L.index, L.index + 1), !i) {
          const se = new Error(`0 width match regex (${x})`);
          throw se.languageName = x, se.badRule = ke.rule, se;
        }
        return 1;
      }
      if (ke = L, L.type === "begin")
        return mt(L);
      if (L.type === "illegal" && !O) {
        const se = new Error('Illegal lexeme "' + K + '" for mode "' + (P.scope || "<unnamed>") + '"');
        throw se.mode = P, se;
      } else if (L.type === "end") {
        const se = ct(L);
        if (se !== nu)
          return se;
      }
      if (L.type === "illegal" && K === "")
        return 1;
      if (H > 1e5 && H > L.index * 3)
        throw new Error("potential infinite loop, way more iterations than matches");
      return oe += K, K.length;
    }
    const Ne = k(x);
    if (!Ne)
      throw Pn(s.replace("{}", x)), new Error('Unknown language: "' + x + '"');
    const ee = qM(Ne);
    let Mt = "", P = D || ee;
    const ae = {}, he = new a.__emitter(a);
    ce();
    let oe = "", Ue = 0, $e = 0, H = 0, V = !1;
    try {
      if (Ne.__emitTokens)
        Ne.__emitTokens(S, he);
      else {
        for (P.matcher.considerAll(); ; ) {
          H++, V ? V = !1 : P.matcher.considerAll(), P.matcher.lastIndex = $e;
          const N = P.matcher.exec(S);
          if (!N)
            break;
          const L = S.substring($e, N.index), K = je(L, N);
          $e = N.index + K;
        }
        je(S.substring($e));
      }
      return he.finalize(), Mt = he.toHTML(), {
        language: x,
        value: Mt,
        relevance: Ue,
        illegal: !1,
        _emitter: he,
        _top: P
      };
    } catch (N) {
      if (N.message && N.message.includes("Illegal"))
        return {
          language: x,
          value: Fo(S),
          illegal: !0,
          relevance: 0,
          _illegalBy: {
            message: N.message,
            index: $e,
            context: S.slice($e - 100, $e + 100),
            mode: N.mode,
            resultSoFar: Mt
          },
          _emitter: he
        };
      if (i)
        return {
          language: x,
          value: Fo(S),
          illegal: !1,
          relevance: 0,
          errorRaised: N,
          _emitter: he,
          _top: P
        };
      throw N;
    }
  }
  function f(x) {
    const S = {
      value: Fo(x),
      illegal: !1,
      relevance: 0,
      _top: o,
      _emitter: new a.__emitter(a)
    };
    return S._emitter.addText(x), S;
  }
  function p(x, S) {
    S = S || a.languages || Object.keys(e);
    const O = f(x), D = S.filter(k).filter(Z).map(
      (le) => u(le, x, !1)
    );
    D.unshift(O);
    const F = D.sort((le, Ee) => {
      if (le.relevance !== Ee.relevance)
        return Ee.relevance - le.relevance;
      if (le.language && Ee.language) {
        if (k(le.language).supersetOf === Ee.language)
          return 1;
        if (k(Ee.language).supersetOf === le.language)
          return -1;
      }
      return 0;
    }), [Q, ue] = F, ge = Q;
    return ge.secondBest = ue, ge;
  }
  function h(x, S, O) {
    const D = S && n[S] || O;
    x.classList.add("hljs"), x.classList.add(`language-${D}`);
  }
  function m(x) {
    let S = null;
    const O = c(x);
    if (l(O))
      return;
    if (re(
      "before:highlightElement",
      { el: x, language: O }
    ), x.dataset.highlighted) {
      console.log("Element previously highlighted. To highlight again, first unset `dataset.highlighted`.", x);
      return;
    }
    if (x.children.length > 0 && (a.ignoreUnescapedHTML || (console.warn("One of your code blocks includes unescaped HTML. This is a potentially serious security risk."), console.warn("https://github.com/highlightjs/highlight.js/wiki/security"), console.warn("The element with unescaped HTML:"), console.warn(x)), a.throwUnescapedHTML))
      throw new jM(
        "One of your code blocks includes unescaped HTML.",
        x.innerHTML
      );
    S = x;
    const D = S.textContent, F = O ? d(D, { language: O, ignoreIllegals: !0 }) : p(D);
    x.innerHTML = F.value, x.dataset.highlighted = "yes", h(x, O, F.language), x.result = {
      language: F.language,
      // TODO: remove with version 11.0
      re: F.relevance,
      relevance: F.relevance
    }, F.secondBest && (x.secondBest = {
      language: F.secondBest.language,
      relevance: F.secondBest.relevance
    }), re("after:highlightElement", { el: x, result: F, text: D });
  }
  function g(x) {
    a = tu(a, x);
  }
  const v = () => {
    b(), tr("10.6.0", "initHighlighting() deprecated.  Use highlightAll() now.");
  };
  function y() {
    b(), tr("10.6.0", "initHighlightingOnLoad() deprecated.  Use highlightAll() now.");
  }
  let E = !1;
  function b() {
    if (document.readyState === "loading") {
      E = !0;
      return;
    }
    document.querySelectorAll(a.cssSelector).forEach(m);
  }
  function C() {
    E && b();
  }
  typeof window < "u" && window.addEventListener && window.addEventListener("DOMContentLoaded", C, !1);
  function w(x, S) {
    let O = null;
    try {
      O = S(t);
    } catch (D) {
      if (Pn("Language definition for '{}' could not be registered.".replace("{}", x)), i)
        Pn(D);
      else
        throw D;
      O = o;
    }
    O.name || (O.name = x), e[x] = O, O.rawDefinition = S.bind(null, t), O.aliases && $(O.aliases, { languageName: x });
  }
  function _(x) {
    delete e[x];
    for (const S of Object.keys(n))
      n[S] === x && delete n[S];
  }
  function R() {
    return Object.keys(e);
  }
  function k(x) {
    return x = (x || "").toLowerCase(), e[x] || e[n[x]];
  }
  function $(x, { languageName: S }) {
    typeof x == "string" && (x = [x]), x.forEach((O) => {
      n[O.toLowerCase()] = S;
    });
  }
  function Z(x) {
    const S = k(x);
    return S && !S.disableAutodetect;
  }
  function j(x) {
    x["before:highlightBlock"] && !x["before:highlightElement"] && (x["before:highlightElement"] = (S) => {
      x["before:highlightBlock"](
        Object.assign({ block: S.el }, S)
      );
    }), x["after:highlightBlock"] && !x["after:highlightElement"] && (x["after:highlightElement"] = (S) => {
      x["after:highlightBlock"](
        Object.assign({ block: S.el }, S)
      );
    });
  }
  function J(x) {
    j(x), r.push(x);
  }
  function X(x) {
    const S = r.indexOf(x);
    S !== -1 && r.splice(S, 1);
  }
  function re(x, S) {
    const O = x;
    r.forEach(function(D) {
      D[O] && D[O](S);
    });
  }
  function T(x) {
    return tr("10.7.0", "highlightBlock will be removed entirely in v12.0"), tr("10.7.0", "Please use highlightElement now."), m(x);
  }
  Object.assign(t, {
    highlight: d,
    highlightAuto: p,
    highlightAll: b,
    highlightElement: m,
    // TODO: Remove with v12 API
    highlightBlock: T,
    configure: g,
    initHighlighting: v,
    initHighlightingOnLoad: y,
    registerLanguage: w,
    unregisterLanguage: _,
    listLanguages: R,
    getLanguage: k,
    registerAliases: $,
    autoDetection: Z,
    inherit: tu,
    addPlugin: J,
    removePlugin: X
  }), t.debugMode = function() {
    i = !1;
  }, t.safeMode = function() {
    i = !0;
  }, t.versionString = GM, t.regex = {
    concat: Zn,
    lookahead: Xp,
    either: Sl,
    optional: dM,
    anyNumberOfTimes: cM
  };
  for (const x in Ui)
    typeof Ui[x] == "object" && Yp(Ui[x]);
  return Object.assign(t, Ui), t;
}, Nr = ah({});
Nr.newInstance = () => ah({});
var JM = Nr;
Nr.HighlightJS = Nr;
Nr.default = Nr;
const XM = /* @__PURE__ */ rl(JM), ru = {}, QM = "hljs-";
function ek(t) {
  const e = XM.newInstance();
  return t && s(t), {
    highlight: n,
    highlightAuto: r,
    listLanguages: i,
    register: s,
    registerAlias: o,
    registered: a
  };
  function n(l, c, d) {
    const u = d || ru, f = typeof u.prefix == "string" ? u.prefix : QM;
    if (!e.getLanguage(l))
      throw new Error("Unknown language: `" + l + "` is not registered");
    e.configure({ __emitter: tk, classPrefix: f });
    const p = (
      /** @type {HighlightResult & {_emitter: HastEmitter}} */
      e.highlight(c, { ignoreIllegals: !0, language: l })
    );
    if (p.errorRaised)
      throw new Error("Could not highlight with `Highlight.js`", {
        cause: p.errorRaised
      });
    const h = p._emitter.root, m = (
      /** @type {RootData} */
      h.data
    );
    return m.language = p.language, m.relevance = p.relevance, h;
  }
  function r(l, c) {
    const u = (c || ru).subset || i();
    let f = -1, p = 0, h;
    for (; ++f < u.length; ) {
      const m = u[f];
      if (!e.getLanguage(m))
        continue;
      const g = n(m, l, c);
      g.data && g.data.relevance !== void 0 && g.data.relevance > p && (p = g.data.relevance, h = g);
    }
    return h || {
      type: "root",
      children: [],
      data: { language: void 0, relevance: p }
    };
  }
  function i() {
    return e.listLanguages();
  }
  function s(l, c) {
    if (typeof l == "string")
      e.registerLanguage(l, c);
    else {
      let d;
      for (d in l)
        Object.hasOwn(l, d) && e.registerLanguage(d, l[d]);
    }
  }
  function o(l, c) {
    if (typeof l == "string")
      e.registerAliases(
        // Note: copy needed because hljs doesn’t accept readonly arrays yet.
        typeof c == "string" ? c : [...c],
        { languageName: l }
      );
    else {
      let d;
      for (d in l)
        if (Object.hasOwn(l, d)) {
          const u = l[d];
          e.registerAliases(
            // Note: copy needed because hljs doesn’t accept readonly arrays yet.
            typeof u == "string" ? u : [...u],
            { languageName: d }
          );
        }
    }
  }
  function a(l) {
    return !!e.getLanguage(l);
  }
}
class tk {
  /**
   * @param {Readonly<HljsOptions>} options
   *   Configuration.
   * @returns
   *   Instance.
   */
  constructor(e) {
    this.options = e, this.root = {
      type: "root",
      children: [],
      data: { language: void 0, relevance: 0 }
    }, this.stack = [this.root];
  }
  /**
   * @param {string} value
   *   Text to add.
   * @returns {undefined}
   *   Nothing.
   *
   */
  addText(e) {
    if (e === "")
      return;
    const n = this.stack[this.stack.length - 1], r = n.children[n.children.length - 1];
    r && r.type === "text" ? r.value += e : n.children.push({ type: "text", value: e });
  }
  /**
   *
   * @param {unknown} rawName
   *   Name to add.
   * @returns {undefined}
   *   Nothing.
   */
  startScope(e) {
    this.openNode(String(e));
  }
  /**
   * @returns {undefined}
   *   Nothing.
   */
  endScope() {
    this.closeNode();
  }
  /**
   * @param {HastEmitter} other
   *   Other emitter.
   * @param {string} name
   *   Name of the sublanguage.
   * @returns {undefined}
   *   Nothing.
   */
  __addSublanguage(e, n) {
    const r = this.stack[this.stack.length - 1], i = (
      /** @type {Array<ElementContent>} */
      e.root.children
    );
    n ? r.children.push({
      type: "element",
      tagName: "span",
      properties: { className: [n] },
      children: i
    }) : r.children.push(...i);
  }
  /**
   * @param {string} name
   *   Name to add.
   * @returns {undefined}
   *   Nothing.
   */
  openNode(e) {
    const n = this, r = e.split(".").map(function(o, a) {
      return a ? o + "_".repeat(a) : n.options.classPrefix + o;
    }), i = this.stack[this.stack.length - 1], s = {
      type: "element",
      tagName: "span",
      properties: { className: r },
      children: []
    };
    i.children.push(s), this.stack.push(s);
  }
  /**
   * @returns {undefined}
   *   Nothing.
   */
  closeNode() {
    this.stack.pop();
  }
  /**
   * @returns {undefined}
   *   Nothing.
   */
  finalize() {
  }
  /**
   * @returns {string}
   *   Nothing.
   */
  toHTML() {
    return "";
  }
}
const nk = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/, iu = new Me("aie-video-plugin"), Br = "video_action", rk = xe.create({
  name: "video",
  group: "block",
  addAttributes() {
    return {
      src: {
        default: null,
        parseHTML: (t) => t.getAttribute("src"),
        renderHTML: (t) => ({ src: t.src })
      },
      poster: {
        default: null,
        parseHTML: (t) => t.getAttribute("poster"),
        renderHTML: (t) => ({ poster: t.poster })
      },
      width: {
        default: 350
      },
      controls: {
        default: !0
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: "video",
        getAttrs: (t) => ({
          src: t.getAttribute("src"),
          poster: t.getAttribute("poster")
        })
      }
    ];
  },
  renderHTML({ HTMLAttributes: t }) {
    return [
      "video",
      { controls: "true", ...t, src: null },
      ["source", { src: t.src }]
    ];
  },
  addCommands() {
    return {
      setVideo: (t) => ({ commands: e }) => e.insertContent(`<video controls="true" style="width: 100%" src="${t}" />`),
      toggleVideo: () => ({ commands: t }) => t.toggleNode(this.name, "paragraph"),
      uploadVideo: (t) => () => {
        const e = Zs(), { state: { tr: n }, view: r, schema: i } = this.editor;
        return n.selection.empty || n.deleteSelection(), r.dispatch(n.setMeta(Br, {
          type: "add",
          id: e,
          pos: n.selection.from
        })), (this.options.uploader || ol(this.options.uploadUrl))(t, this.options.uploadUrl, this.options.uploadHeaders, "video").then((o) => {
          if (o.errorCode === 0 && o.data && o.data.src) {
            let l = iu.getState(this.editor.state).find(void 0, void 0, (c) => c.id == e);
            r.dispatch(r.state.tr.insert(l[0].from, i.nodes.video.create({
              src: o.data.src,
              poster: o.data.poster
            })).setMeta(Br, { type: "remove", id: e }));
          } else
            r.dispatch(n.setMeta(Br, { type: "remove", id: e }));
        }).catch(() => {
          r.dispatch(n.setMeta(Br, { type: "remove", id: e }));
        }), !0;
      }
    };
  },
  addNodeView() {
    return (t) => {
      const e = document.createElement("div"), { src: n, width: r, align: i } = t.node.attrs;
      return e.classList.add(`align-${i}`), e.innerHTML = `
                  <div class="aie-resize-wrapper">
                      <div class="aie-resize">
                          <div class="aie-resize-btn-top-left" data-position="left" draggable="true"></div>
                          <div class="aie-resize-btn-top-right" data-position="right" draggable="true"></div>
                          <div class="aie-resize-btn-bottom-left" data-position="left" draggable="true"></div>
                          <div class="aie-resize-btn-bottom-right" data-position="right" draggable="true"></div>
                      </div>
                      <video controls="true" width="${r}" class="resize-obj">
                          <source src="${n}">
                      </video>
                  </div>
                `, sp(e, t.editor.view.dom, (s) => t.editor.commands.updateAttributes("video", s)), {
        dom: e
        // contentDOM: container.firstChild,
      };
    };
  },
  addInputRules() {
    return [
      Ga({
        find: nk,
        type: this.type,
        getAttributes: (t) => {
          const [, , e] = t;
          return { src: e };
        }
      })
    ];
  },
  addProseMirrorPlugins() {
    const t = this.editor;
    return [
      new Se({
        key: iu,
        state: {
          init: () => we.empty,
          apply: (e, n) => {
            const r = e.getMeta(Br);
            return n = n.map(e.mapping, e.doc), r && r.type === "add" ? n = n.add(e.doc, [ip(r)]) : r && r.type === "remove" && (n = n.remove(n.find(
              void 0,
              void 0,
              (i) => i.id == r.id
            ))), n;
          }
        },
        props: {
          decorations(e) {
            return this.getState(e);
          },
          handleDOMEvents: {
            drop(e, n) {
              if (!(n.dataTransfer && n.dataTransfer.files && n.dataTransfer.files.length))
                return !1;
              const i = Array.from(n.dataTransfer.files).filter((c) => /video/i.test(c.type));
              if (i.length === 0)
                return !1;
              n.preventDefault();
              const { state: { tr: s, doc: o }, dispatch: a } = e, l = e.posAtCoords({ left: n.clientX, top: n.clientY });
              return a(s.setSelection(G.create(o, l.pos)).scrollIntoView()), i.forEach((c) => {
                t.commands.uploadVideo(c);
              }), !0;
            }
          }
        }
      })
    ];
  }
}), ik = xe.create({
  name: "iframe",
  group: "block",
  atom: !0,
  addOptions() {
    return {
      allowFullscreen: !0,
      HTMLAttributes: {
        class: "iframe-wrapper"
      }
    };
  },
  addAttributes() {
    return {
      src: {
        default: null
      },
      width: {
        default: "100%"
      },
      frameborder: {
        default: 0
      },
      allowfullscreen: {
        default: this.options.allowFullscreen,
        parseHTML: () => this.options.allowFullscreen
      }
    };
  },
  parseHTML() {
    return [{
      tag: "iframe"
    }];
  },
  renderHTML({ HTMLAttributes: t }) {
    return ["div", this.options.HTMLAttributes, ["iframe", t]];
  },
  addCommands() {
    return {
      setIframe: (t) => ({ tr: e, dispatch: n }) => {
        const { selection: r } = e, i = this.type.create(t);
        return n && e.replaceRangeWith(r.from, r.to, i), !0;
      }
    };
  }
});
class sk {
  constructor({ editor: e, element: n, view: r, tippyOptions: i = {}, updateDelay: s = 250, shouldShow: o }) {
    this.preventHide = !1, this.shouldShow = ({ view: a, state: l, from: c, to: d }) => {
      const { doc: u, selection: f } = l, { empty: p } = f, h = !u.textBetween(c, d).length && Ua(l.selection), m = this.element.contains(document.activeElement);
      return !(!(a.hasFocus() || m) || p || h || !this.editor.isEditable);
    }, this.mousedownHandler = () => {
      this.preventHide = !0;
    }, this.dragstartHandler = () => {
      this.hide();
    }, this.focusHandler = () => {
      setTimeout(() => this.update(this.editor.view));
    }, this.blurHandler = ({ event: a }) => {
      var l;
      if (this.preventHide) {
        this.preventHide = !1;
        return;
      }
      a != null && a.relatedTarget && (!((l = this.element.parentNode) === null || l === void 0) && l.contains(a.relatedTarget)) || this.hide();
    }, this.tippyBlurHandler = (a) => {
      this.blurHandler({ event: a });
    }, this.handleDebouncedUpdate = (a, l) => {
      const c = !(l != null && l.selection.eq(a.state.selection)), d = !(l != null && l.doc.eq(a.state.doc));
      !c && !d || (this.updateDebounceTimer && clearTimeout(this.updateDebounceTimer), this.updateDebounceTimer = window.setTimeout(() => {
        this.updateHandler(a, c, d, l);
      }, this.updateDelay));
    }, this.updateHandler = (a, l, c, d) => {
      var u, f, p;
      const { state: h, composing: m } = a, { selection: g } = h;
      if (m || !l && !c)
        return;
      this.createTooltip();
      const { ranges: y } = g, E = Math.min(...y.map((w) => w.$from.pos)), b = Math.max(...y.map((w) => w.$to.pos));
      if (!((u = this.shouldShow) === null || u === void 0 ? void 0 : u.call(this, {
        editor: this.editor,
        view: a,
        state: h,
        oldState: d,
        from: E,
        to: b
      }))) {
        this.hide();
        return;
      }
      (f = this.tippy) === null || f === void 0 || f.setProps({
        getReferenceClientRect: ((p = this.tippyOptions) === null || p === void 0 ? void 0 : p.getReferenceClientRect) || (() => {
          if (kb(h.selection)) {
            let w = a.nodeDOM(E);
            const _ = w.dataset.nodeViewWrapper ? w : w.querySelector("[data-node-view-wrapper]");
            if (_ && (w = _.firstChild), w)
              return w.getBoundingClientRect();
          }
          return Za(a, E, b);
        })
      }), this.show();
    }, this.editor = e, this.element = n, this.view = r, this.updateDelay = s, o && (this.shouldShow = o), this.element.addEventListener("mousedown", this.mousedownHandler, { capture: !0 }), this.view.dom.addEventListener("dragstart", this.dragstartHandler), this.editor.on("focus", this.focusHandler), this.editor.on("blur", this.blurHandler), this.tippyOptions = i, this.element.remove(), this.element.style.visibility = "visible";
  }
  createTooltip() {
    const { element: e } = this.editor.options, n = !!e.parentElement;
    this.tippy || !n || (this.tippy = ht(e, {
      duration: 0,
      getReferenceClientRect: null,
      content: this.element,
      interactive: !0,
      trigger: "manual",
      placement: "top",
      hideOnClick: "toggle",
      ...this.tippyOptions
    }), this.tippy.popper.firstChild && this.tippy.popper.firstChild.addEventListener("blur", this.tippyBlurHandler));
  }
  update(e, n) {
    const { state: r } = e, i = r.selection.$from.pos !== r.selection.$to.pos;
    if (this.updateDelay > 0 && i) {
      this.handleDebouncedUpdate(e, n);
      return;
    }
    const s = !(n != null && n.selection.eq(e.state.selection)), o = !(n != null && n.doc.eq(e.state.doc));
    this.updateHandler(e, s, o, n);
  }
  show() {
    var e;
    (e = this.tippy) === null || e === void 0 || e.show();
  }
  hide() {
    var e;
    (e = this.tippy) === null || e === void 0 || e.hide();
  }
  destroy() {
    var e, n;
    !((e = this.tippy) === null || e === void 0) && e.popper.firstChild && this.tippy.popper.firstChild.removeEventListener("blur", this.tippyBlurHandler), (n = this.tippy) === null || n === void 0 || n.destroy(), this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: !0 }), this.view.dom.removeEventListener("dragstart", this.dragstartHandler), this.editor.off("focus", this.focusHandler), this.editor.off("blur", this.blurHandler);
  }
}
const ok = (t) => new Se({
  key: typeof t.pluginKey == "string" ? new Me(t.pluginKey) : t.pluginKey,
  view: (e) => new sk({ view: e, ...t })
}), kl = Ce.create({
  name: "bubbleMenu",
  addOptions() {
    return {
      element: null,
      tippyOptions: {},
      pluginKey: "bubbleMenu",
      updateDelay: void 0,
      shouldShow: null
    };
  },
  addProseMirrorPlugins() {
    return this.options.element ? [
      ok({
        pluginKey: this.options.pluginKey,
        editor: this.editor,
        element: this.options.element,
        tippyOptions: this.options.tippyOptions,
        updateDelay: this.options.updateDelay,
        shouldShow: this.options.shouldShow
      })
    ] : [];
  }
});
class Tl extends HTMLElement {
  constructor() {
    super();
    q(this, "editor");
    q(this, "items", []);
  }
  connectedCallback() {
    this.innerHTML = `
            <div class="aie-bubble-menu">
               ${this.items.map((n) => `
                   <div class="aie-bubble-menu-item" id="${n.id}">${n.svg}</div>
                   `).join("")}
            </div>
        `, this.querySelector("div").addEventListener("click", (n) => {
      this.items.forEach((r) => {
        n.target.closest(`#${r.id}`) && this.onItemClick(r.id);
      });
    });
  }
  onCreate(n, r) {
    this.editor = n.editor;
  }
}
class ak extends Tl {
  constructor() {
    super(), this.items = [
      {
        id: "edit",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6.41421 15.89L16.5563 5.74786L15.1421 4.33365L5 14.4758V15.89H6.41421ZM7.24264 17.89H3V13.6474L14.435 2.21233C14.8256 1.8218 15.4587 1.8218 15.8492 2.21233L18.6777 5.04075C19.0682 5.43128 19.0682 6.06444 18.6777 6.45497L7.24264 17.89ZM3 19.89H21V21.89H3V19.89Z"></path></svg>'
      },
      {
        id: "unlink",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M17 17H22V19H19V22H17V17ZM7 7H2V5H5V2H7V7ZM18.364 15.5355L16.9497 14.1213L18.364 12.7071C20.3166 10.7545 20.3166 7.58866 18.364 5.63604C16.4113 3.68342 13.2455 3.68342 11.2929 5.63604L9.87868 7.05025L8.46447 5.63604L9.87868 4.22183C12.6123 1.48816 17.0445 1.48816 19.7782 4.22183C22.5118 6.9555 22.5118 11.3877 19.7782 14.1213L18.364 15.5355ZM15.5355 18.364L14.1213 19.7782C11.3877 22.5118 6.9555 22.5118 4.22183 19.7782C1.48816 17.0445 1.48816 12.6123 4.22183 9.87868L5.63604 8.46447L7.05025 9.87868L5.63604 11.2929C3.68342 13.2455 3.68342 16.4113 5.63604 18.364C7.58866 20.3166 10.7545 20.3166 12.7071 18.364L14.1213 16.9497L15.5355 18.364ZM14.8284 7.75736L16.2426 9.17157L9.17157 16.2426L7.75736 14.8284L14.8284 7.75736Z"></path></svg>'
      },
      {
        id: "visit",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10 6V8H5V19H16V14H18V20C18 20.5523 17.5523 21 17 21H4C3.44772 21 3 20.5523 3 20V7C3 6.44772 3.44772 6 4 6H10ZM21 3V11H19L18.9999 6.413L11.2071 14.2071L9.79289 12.7929L17.5849 5H13V3H21Z"></path></svg>'
      }
    ];
  }
  connectedCallback() {
    super.connectedCallback();
    const e = new Yf();
    e.setContent(`
            <div style="width: 250px">
            链接地址
            </div>
             <div style="width: 250px">
             <input type="text" id="href" style="width: 240px">
            </div>
            
            <div style="margin-top: 10px">
            打开方式
            </div>
            <div>
            <select id="target" style="width: 250px">
                       <option value="">默认</option>
                       <option value="_blank">新窗口</option>
                    </select>
            </div>
        `), e.onConfirmClick((n) => {
      var s, o;
      const r = n.popper.querySelector("#href").value;
      if (r.trim() === "") {
        (s = this.editor) == null || s.chain().focus().extendMarkRange("link").unsetLink().run();
        return;
      }
      let i = n.popper.querySelector("#target").value;
      i.trim() === "" && (i = null), (o = this.editor) == null || o.chain().focus().extendMarkRange("link").setLink({
        href: r,
        target: i,
        rel: null
      }).run();
    }), e.onShow((n) => {
      var i;
      const r = (i = this.editor) == null ? void 0 : i.getAttributes("link");
      r && r.href && (n.popper.querySelector("#href").value = r.href), r && r.target && (n.popper.querySelector("#target").value = r.target);
    }), e.setTrigger(this.querySelector("#edit"), "right");
  }
  onItemClick(e) {
    var n, r;
    e === "unlink" ? (n = this.editor) == null || n.chain().focus().unsetLink().run() : e === "visit" && window.open((r = this.editor) == null ? void 0 : r.getAttributes("link").href, "_blank");
  }
  onTransaction(e) {
  }
}
class lk extends Tl {
  constructor() {
    super(), this.items = [
      {
        id: "left",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM3 19H17V21H3V19ZM3 14H21V16H3V14ZM3 9H17V11H3V9Z"></path></svg>'
      },
      {
        id: "center",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM5 19H19V21H5V19ZM3 14H21V16H3V14ZM5 9H19V11H5V9Z"></path></svg>'
      },
      {
        id: "right",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 4H21V6H3V4ZM7 19H21V21H7V19ZM3 14H21V16H3V14ZM7 9H21V11H7V9Z"></path></svg>'
      },
      {
        id: "delete",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 4V2H17V4H22V6H20V21C20 21.5523 19.5523 22 19 22H5C4.44772 22 4 21.5523 4 21V6H2V4H7ZM6 6V20H18V6H6ZM9 9H11V17H9V9ZM13 9H15V17H13V9Z"></path></svg>'
      }
    ];
  }
  onItemClick(e) {
    var n, r, i;
    if (e != "delete") {
      const s = (n = this.editor) == null ? void 0 : n.getAttributes("image");
      s.align = e, (r = this.editor) == null || r.chain().setImage(s).run();
    } else
      (i = this.editor) == null || i.commands.deleteSelection();
  }
  onTransaction(e) {
  }
}
class ck extends Tl {
  constructor() {
    super(), this.items = [
      {
        id: "insert-column-left",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H14C13.4477 21 13 20.5523 13 20V4C13 3.44772 13.4477 3 14 3H20ZM19 5H15V19H19V5ZM6 7C8.76142 7 11 9.23858 11 12C11 14.7614 8.76142 17 6 17C3.23858 17 1 14.7614 1 12C1 9.23858 3.23858 7 6 7ZM7 9H5V10.999L3 11V13L5 12.999V15H7V12.999L9 13V11L7 10.999V9Z"></path></svg>'
      },
      {
        id: "insert-column-right",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M10 3C10.5523 3 11 3.44772 11 4V20C11 20.5523 10.5523 21 10 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H10ZM9 5H5V19H9V5ZM18 7C20.7614 7 23 9.23858 23 12C23 14.7614 20.7614 17 18 17C15.2386 17 13 14.7614 13 12C13 9.23858 15.2386 7 18 7ZM19 9H17V10.999L15 11V13L17 12.999V15H19V12.999L21 13V11L19 10.999V9Z"></path></svg>'
      },
      {
        id: "insert-row-top",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 13C20.5523 13 21 13.4477 21 14V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V14C3 13.4477 3.44772 13 4 13H20ZM19 15H5V19H19V15ZM12 1C14.7614 1 17 3.23858 17 6C17 8.76142 14.7614 11 12 11C9.23858 11 7 8.76142 7 6C7 3.23858 9.23858 1 12 1ZM13 3H11V4.999L9 5V7L11 6.999V9H13V6.999L15 7V5L13 4.999V3Z"></path></svg>'
      },
      {
        id: "insert-row-bottom",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 13C14.7614 13 17 15.2386 17 18C17 20.7614 14.7614 23 12 23C9.23858 23 7 20.7614 7 18C7 15.2386 9.23858 13 12 13ZM13 15H11V16.999L9 17V19L11 18.999V21H13V18.999L15 19V17L13 16.999V15ZM20 3C20.5523 3 21 3.44772 21 4V10C21 10.5523 20.5523 11 20 11H4C3.44772 11 3 10.5523 3 10V4C3 3.44772 3.44772 3 4 3H20ZM5 5V9H19V5H5Z"></path></svg>'
      },
      {
        id: "delete-column",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M12 3C12.5523 3 13 3.44772 13 4L12.9998 11.9998C13.8355 11.372 14.8743 11 16 11C18.7614 11 21 13.2386 21 16C21 18.7614 18.7614 21 16 21C14.9681 21 14.0092 20.6874 13.2129 20.1518L13 20C13 20.5523 12.5523 21 12 21H6C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3H12ZM11 5H7V19H11V5ZM19 15H13V17H19V15Z"></path></svg>'
      },
      {
        id: "delete-row",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 5C20.5523 5 21 5.44772 21 6V12C21 12.5523 20.5523 13 20 13C20.628 13.8355 21 14.8743 21 16C21 18.7614 18.7614 21 16 21C13.2386 21 11 18.7614 11 16C11 14.8743 11.372 13.8355 11.9998 12.9998L4 13C3.44772 13 3 12.5523 3 12V6C3 5.44772 3.44772 5 4 5H20ZM13 15V17H19V15H13ZM19 7H5V11H19V7Z"></path></svg>'
      },
      {
        id: "merge-cells-horizontal",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V10.999H7V9L10 12L7 15V13H5V19H11V17H13V19H19V13H17V15L14 12L17 9V10.999H19V5H13V7H11V5ZM13 13V15H11V13H13ZM13 9V11H11V9H13Z"></path></svg>'
      },
      {
        id: "merge-cells-vertical",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M21 20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20C20.5523 3 21 3.44772 21 4V20ZM19 11V5H13.001V7H15L12 10L9 7H11V5H5V11H7V13H5V19H11V17H9L12 14L15 17H13.001V19H19V13H17V11H19ZM11 13H9V11H11V13ZM15 13H13V11H15V13Z"></path></svg>'
      },
      {
        id: "split-cells-horizontal",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM11 5H5V19H11V15H13V19H19V5H13V9H11V5ZM15 9L18 12L15 15V13H9V15L6 12L9 9V11H15V9Z"></path></svg>'
      },
      {
        id: "split-cells-vertical",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M20 3C20.5523 3 21 3.44772 21 4V20C21 20.5523 20.5523 21 20 21H4C3.44772 21 3 20.5523 3 20V4C3 3.44772 3.44772 3 4 3H20ZM19 5H5V10.999L9 11V13H5V19H19V13H15V11L19 10.999V5ZM12 6L15 9H13V15H15L12 18L9 15H11V9H9L12 6Z"></path></svg>'
      },
      {
        id: "delete",
        svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 4V2H17V4H22V6H20V21C20 21.5523 19.5523 22 19 22H5C4.44772 22 4 21.5523 4 21V6H2V4H7ZM6 6V20H18V6H6ZM9 9H11V17H9V9ZM13 9H15V17H13V9Z"></path></svg>'
      }
      // {
      //     id: "insert-row-bottom",
      //     svg: ""
      // }
    ];
  }
  onItemClick(e) {
    var n, r, i, s, o, a, l, c, d;
    e === "insert-column-left" ? (n = this.editor) == null || n.chain().focus().addColumnBefore().run() : e === "insert-column-right" ? (r = this.editor) == null || r.chain().focus().addColumnAfter().run() : e === "insert-row-top" ? (i = this.editor) == null || i.chain().focus().addRowBefore().run() : e === "insert-row-bottom" ? (s = this.editor) == null || s.chain().focus().addRowAfter().run() : e === "delete-column" ? (o = this.editor) == null || o.chain().focus().deleteColumn().run() : e === "delete-row" ? (a = this.editor) == null || a.chain().focus().deleteRow().run() : e === "merge-cells-horizontal" || e === "merge-cells-vertical" ? (l = this.editor) == null || l.chain().focus().mergeCells().run() : e === "split-cells-horizontal" || e === "split-cells-vertical" ? (c = this.editor) == null || c.chain().focus().splitCell().run() : e === "delete" && ((d = this.editor) == null || d.chain().focus().deleteTable().run());
  }
  show(e) {
    !e || e.length == 0 ? this.style.display = "none" : this.style.display = "", this.querySelectorAll(".aie-bubble-menu-item").forEach((n) => {
      n.style.display = "none";
    }), e.forEach((n) => {
      const r = this.querySelector(`#${n}`);
      r.style.display = "";
    });
  }
  onTransaction(e) {
    if (!e.editor.isActive("table"))
      return;
    const { state: { selection: n }, view: r } = e.editor;
    if (console.log("selection: ", n), n instanceof de)
      if (this.isOneCellSelected(n)) {
        const i = ["insert-column-left", "insert-column-right", "delete-column", "insert-row-top", "insert-row-bottom", "delete-row"];
        if (e.editor.can().splitCell()) {
          const s = r.nodeDOM(n.$anchorCell.pos), o = s.getAttribute("colspan"), a = s.getAttribute("rowspan");
          o && Number(o) > 1 ? i.push("split-cells-horizontal") : a && Number(a) > 1 && i.push("split-cells-vertical");
        }
        this.show(i);
      } else
        this.isAllTableSelected(n) ? this.show(["delete"]) : this.isColumnSelected(n, r) ? this.show(["insert-column-left", "insert-column-right", "delete-column", "merge-cells-vertical"]) : this.isRowSelected(n, r) ? this.show(["insert-row-top", "insert-row-bottom", "delete-row", "merge-cells-horizontal"]) : this.show(["merge-cells-horizontal"]);
    else
      this.show(["insert-column-left", "insert-column-right", "delete-column", "insert-row-top", "insert-row-bottom", "delete-row"]);
  }
  isAllTableSelected(e) {
    const n = _e.get(e.$anchorCell.node(-1)), r = n.cellsInRect({
      top: 0,
      left: 0,
      right: n.width,
      bottom: n.height
    });
    return e.ranges.length == r.length;
  }
  isOneCellSelected(e) {
    return e.ranges.length == 1;
  }
  isColumnSelected(e, n) {
    let r = -1;
    for (let i of e.ranges)
      if (r == -1)
        r = n.coordsAtPos(i.$from.pos).left;
      else if (r != n.coordsAtPos(i.$from.pos).left)
        return !1;
    return !0;
  }
  isRowSelected(e, n) {
    let r = -1;
    for (let i of e.ranges)
      if (r == -1)
        r = n.coordsAtPos(i.$from.pos).bottom;
      else if (r != n.coordsAtPos(i.$from.pos).bottom)
        return !1;
    return !0;
  }
}
window.customElements.define("aie-bubble-link", ak);
window.customElements.define("aie-bubble-image", lk);
window.customElements.define("aie-bubble-table", ck);
const dk = (t) => {
  const e = document.createElement("aie-bubble-link");
  return t.eventComponents.push(e), kl.configure({
    pluginKey: "linkBubble",
    element: e,
    tippyOptions: {
      placement: "bottom"
    },
    shouldShow: ({ editor: n }) => n.isActive("link")
  });
}, uk = (t) => {
  const e = document.createElement("aie-bubble-image");
  return t.eventComponents.push(e), kl.configure({
    pluginKey: "imageBubble",
    element: e,
    tippyOptions: {
      appendTo: t.container,
      placement: "top-start",
      getReferenceClientRect: () => {
        const { ranges: n } = t.innerEditor.state.selection, r = Math.min(...n.map((d) => d.$from.pos)), i = Math.max(...n.map((d) => d.$to.pos)), s = t.innerEditor.view, a = s.nodeDOM(r).querySelector("img"), l = Za(s, r, i), c = a.getBoundingClientRect();
        return {
          ...l,
          left: c.left + c.width * 0.25
        };
      }
    },
    shouldShow: ({ editor: n }) => n.isActive("image")
  });
}, fk = (t) => {
  const e = document.createElement("aie-bubble-table");
  return t.eventComponents.push(e), kl.configure({
    pluginKey: "tableBubble",
    element: e,
    tippyOptions: {
      placement: "top",
      getReferenceClientRect: () => {
        const n = t.innerEditor.state.selection, { ranges: r } = n, i = Math.min(...r.map((d) => d.$from.pos)), s = Math.max(...r.map((d) => d.$to.pos)), o = t.innerEditor.view, a = Za(o, i, s), l = t.innerEditor.state.selection.$from.posAtIndex(0, 1), c = t.innerEditor.view.coordsAtPos(l);
        return {
          ...a,
          top: c.top
        };
      }
    },
    shouldShow: ({ editor: n }) => n.isActive("table")
  });
}, pk = (t) => {
  const e = [];
  return e.push(dk(t)), e.push(uk(t)), e.push(fk(t)), e;
}, hk = Ce.create({
  name: "placeholder",
  addOptions() {
    return {
      emptyEditorClass: "is-editor-empty",
      emptyNodeClass: "is-empty",
      placeholder: "Write something …",
      showOnlyWhenEditable: !0,
      showOnlyCurrent: !0,
      includeChildren: !1
    };
  },
  addProseMirrorPlugins() {
    return [
      new Se({
        key: new Me("placeholder"),
        props: {
          decorations: ({ doc: t, selection: e }) => {
            const n = this.editor.isEditable || !this.options.showOnlyWhenEditable, { anchor: r } = e, i = [];
            if (!n)
              return null;
            const s = t.type.createAndFill(), o = (s == null ? void 0 : s.sameMarkup(t)) && s.content.findDiffStart(t.content) === null;
            return t.descendants((a, l) => {
              const c = r >= l && r <= l + a.nodeSize, d = !a.isLeaf && !a.childCount;
              if ((c || !this.options.showOnlyCurrent) && d) {
                const u = [this.options.emptyNodeClass];
                o && u.push(this.options.emptyEditorClass);
                const f = Le.node(l, l + a.nodeSize, {
                  class: u.join(" "),
                  "data-placeholder": typeof this.options.placeholder == "function" ? this.options.placeholder({
                    editor: this.editor,
                    node: a,
                    pos: l,
                    hasAnchor: c
                  }) : this.options.placeholder
                });
                i.push(f);
              }
              return this.options.includeChildren;
            }), we.create(t, i);
          }
        }
      })
    ];
  }
});
function mk(t) {
  var e;
  const { char: n, allowSpaces: r, allowedPrefixes: i, startOfLine: s, $position: o } = t, a = n0(n), l = new RegExp(`\\s${a}$`), c = s ? "^" : "", d = r ? new RegExp(`${c}${a}.*?(?=\\s${a}|$)`, "gm") : new RegExp(`${c}(?:^)?${a}[^\\s${a}]*`, "gm"), u = ((e = o.nodeBefore) === null || e === void 0 ? void 0 : e.isText) && o.nodeBefore.text;
  if (!u)
    return null;
  const f = o.pos - u.length, p = Array.from(u.matchAll(d)).pop();
  if (!p || p.input === void 0 || p.index === void 0)
    return null;
  const h = p.input.slice(Math.max(0, p.index - 1), p.index), m = new RegExp(`^[${i == null ? void 0 : i.join("")}\0]?$`).test(h);
  if (i !== null && !m)
    return null;
  const g = f + p.index;
  let v = g + p[0].length;
  return r && l.test(u.slice(v - 1, v + 1)) && (p[0] += " ", v += 1), g < o.pos && v >= o.pos ? {
    range: {
      from: g,
      to: v
    },
    query: p[0].slice(n.length),
    text: p[0]
  } : null;
}
const gk = new Me("suggestion");
function lh({ pluginKey: t = gk, editor: e, char: n = "@", allowSpaces: r = !1, allowedPrefixes: i = [" "], startOfLine: s = !1, decorationTag: o = "span", decorationClass: a = "suggestion", command: l = () => null, items: c = () => [], render: d = () => ({}), allow: u = () => !0 }) {
  let f;
  const p = d == null ? void 0 : d(), h = new Se({
    key: t,
    view() {
      return {
        update: async (m, g) => {
          var v, y, E, b, C, w, _;
          const R = (v = this.key) === null || v === void 0 ? void 0 : v.getState(g), k = (y = this.key) === null || y === void 0 ? void 0 : y.getState(m.state), $ = R.active && k.active && R.range.from !== k.range.from, Z = !R.active && k.active, j = R.active && !k.active, J = !Z && !j && R.query !== k.query, X = Z || $, re = J && !$, T = j || $;
          if (!X && !re && !T)
            return;
          const x = T && !X ? R : k, S = m.dom.querySelector(`[data-decoration-id="${x.decorationId}"]`);
          f = {
            editor: e,
            range: x.range,
            query: x.query,
            text: x.text,
            items: [],
            command: (O) => {
              l({
                editor: e,
                range: x.range,
                props: O
              });
            },
            decorationNode: S,
            // virtual node for popper.js or tippy.js
            // this can be used for building popups without a DOM node
            clientRect: S ? () => {
              var O;
              const { decorationId: D } = (O = this.key) === null || O === void 0 ? void 0 : O.getState(e.state), F = m.dom.querySelector(`[data-decoration-id="${D}"]`);
              return (F == null ? void 0 : F.getBoundingClientRect()) || null;
            } : null
          }, X && ((E = p == null ? void 0 : p.onBeforeStart) === null || E === void 0 || E.call(p, f)), re && ((b = p == null ? void 0 : p.onBeforeUpdate) === null || b === void 0 || b.call(p, f)), (re || X) && (f.items = await c({
            editor: e,
            query: x.query
          })), T && ((C = p == null ? void 0 : p.onExit) === null || C === void 0 || C.call(p, f)), re && ((w = p == null ? void 0 : p.onUpdate) === null || w === void 0 || w.call(p, f)), X && ((_ = p == null ? void 0 : p.onStart) === null || _ === void 0 || _.call(p, f));
        },
        destroy: () => {
          var m;
          f && ((m = p == null ? void 0 : p.onExit) === null || m === void 0 || m.call(p, f));
        }
      };
    },
    state: {
      // Initialize the plugin's internal state.
      init() {
        return {
          active: !1,
          range: {
            from: 0,
            to: 0
          },
          query: null,
          text: null,
          composing: !1
        };
      },
      // Apply changes to the plugin state from a view transaction.
      apply(m, g, v, y) {
        const { isEditable: E } = e, { composing: b } = e.view, { selection: C } = m, { empty: w, from: _ } = C, R = { ...g };
        if (R.composing = b, E && (w || e.view.composing)) {
          (_ < g.range.from || _ > g.range.to) && !b && !g.composing && (R.active = !1);
          const k = mk({
            char: n,
            allowSpaces: r,
            allowedPrefixes: i,
            startOfLine: s,
            $position: C.$from
          }), $ = `id_${Math.floor(Math.random() * 4294967295)}`;
          k && u({ editor: e, state: y, range: k.range }) ? (R.active = !0, R.decorationId = g.decorationId ? g.decorationId : $, R.range = k.range, R.query = k.query, R.text = k.text) : R.active = !1;
        } else
          R.active = !1;
        return R.active || (R.decorationId = null, R.range = { from: 0, to: 0 }, R.query = null, R.text = null), R;
      }
    },
    props: {
      // Call the keydown hook if suggestion is active.
      handleKeyDown(m, g) {
        var v;
        const { active: y, range: E } = h.getState(m.state);
        return y && ((v = p == null ? void 0 : p.onKeyDown) === null || v === void 0 ? void 0 : v.call(p, { view: m, event: g, range: E })) || !1;
      },
      // Setup decorator on the currently active suggestion.
      decorations(m) {
        const { active: g, range: v, decorationId: y } = h.getState(m);
        return g ? we.create(m.doc, [
          Le.inline(v.from, v.to, {
            nodeName: o,
            class: a,
            "data-decoration-id": y
          })
        ]) : null;
      }
    }
  });
  return h;
}
const bk = new Me("mention"), yk = xe.create({
  name: "mention",
  addOptions() {
    return {
      HTMLAttributes: {},
      renderLabel({ options: t, node: e }) {
        var n;
        return `${t.suggestion.char}${(n = e.attrs.label) !== null && n !== void 0 ? n : e.attrs.id}`;
      },
      suggestion: {
        char: "@",
        pluginKey: bk,
        command: ({ editor: t, range: e, props: n }) => {
          var r, i;
          const s = t.view.state.selection.$to.nodeAfter;
          ((r = s == null ? void 0 : s.text) === null || r === void 0 ? void 0 : r.startsWith(" ")) && (e.to += 1), t.chain().focus().insertContentAt(e, [
            {
              type: this.name,
              attrs: n
            },
            {
              type: "text",
              text: " "
            }
          ]).run(), (i = window.getSelection()) === null || i === void 0 || i.collapseToEnd();
        },
        allow: ({ state: t, range: e }) => {
          const n = t.doc.resolve(e.from), r = t.schema.nodes[this.name];
          return !!n.parent.type.contentMatch.matchType(r);
        }
      }
    };
  },
  group: "inline",
  inline: !0,
  selectable: !1,
  atom: !0,
  addAttributes() {
    return {
      id: {
        default: null,
        parseHTML: (t) => t.getAttribute("data-id"),
        renderHTML: (t) => t.id ? {
          "data-id": t.id
        } : {}
      },
      label: {
        default: null,
        parseHTML: (t) => t.getAttribute("data-label"),
        renderHTML: (t) => t.label ? {
          "data-label": t.label
        } : {}
      }
    };
  },
  parseHTML() {
    return [
      {
        tag: `span[data-type="${this.name}"]`
      }
    ];
  },
  renderHTML({ node: t, HTMLAttributes: e }) {
    return [
      "span",
      fe({ "data-type": this.name }, this.options.HTMLAttributes, e),
      this.options.renderLabel({
        options: this.options,
        node: t
      })
    ];
  },
  renderText({ node: t }) {
    return this.options.renderLabel({
      options: this.options,
      node: t
    });
  },
  addKeyboardShortcuts() {
    return {
      Backspace: () => this.editor.commands.command(({ tr: t, state: e }) => {
        let n = !1;
        const { selection: r } = e, { empty: i, anchor: s } = r;
        return i ? (e.doc.nodesBetween(s - 1, s, (o, a) => {
          if (o.type.name === this.name)
            return n = !0, t.insertText(this.options.suggestion.char || "", a, a + o.nodeSize), !1;
        }), n) : !1;
      })
    };
  },
  addProseMirrorPlugins() {
    return [
      lh({
        editor: this.editor,
        ...this.options.suggestion
      })
    ];
  }
}), vk = (t) => yk.configure({
  HTMLAttributes: {
    class: "mention"
  },
  suggestion: {
    items: ({ query: e }) => t(e),
    render: () => {
      let e, n, r = 0, i;
      const s = () => {
        e.innerHTML = `
                            <div class="items">
                             ${i.items.map((o, a) => `<button class="item ${a === r ? "item-selected" : ""}" data-index="${a}"> @${o.name ? o.name : o}</button>`).join("")}
                            </div>
                            `, e.addEventListener("click", (o) => {
          const a = o.target.closest(".item");
          if (a) {
            const l = Number(a.getAttribute("data-index")), c = i.items[l];
            c && c.id ? i.command(c) : i.command({ id: c });
          }
        });
      };
      return {
        onStart: (o) => {
          e = document.createElement("div"), e.classList.add("suggestion"), i = o, o.clientRect && (s(), n = ht("body", {
            getReferenceClientRect: o.clientRect,
            appendTo: () => o.editor.view.dom.closest(".aie-container"),
            content: e,
            showOnCreate: !0,
            interactive: !0,
            allowHTML: !0,
            trigger: "manual",
            placement: "bottom-start"
          }));
        },
        onUpdate(o) {
          i = o, o.clientRect && (s(), n[0].setProps({
            getReferenceClientRect: o.clientRect
          }));
        },
        onKeyDown(o) {
          if (o.event.key === "Escape")
            return n[0].hide(), !0;
          if (o.event.key === "ArrowUp")
            return r = (r + i.items.length - 1) % i.items.length, s(), !0;
          if (o.event.key === "ArrowDown")
            return r = (r + 1) % i.items.length, s(), !0;
          if (o.event.key === "Enter") {
            const a = i.items[r];
            return a && a.id ? i.command(a) : i.command({ id: a }), !0;
          }
          return !1;
        },
        onExit() {
          n[0].destroy(), e.remove();
        }
      };
    }
  }
}), wk = [
  {
    name: "AI 续写",
    prompt: "请帮我继续扩展一些这段话的内容",
    model: "spark"
  },
  {
    name: "AI 提问",
    prompt: "",
    model: "spark"
  },
  {
    name: "AI 翻译",
    prompt: "请帮我把这段内容翻译为英语，直接返回英语结果",
    model: "spark"
  },
  {
    name: "AI 生图",
    prompt: "请根据以上的内容，生成一张图片，并把图片返回给我",
    model: "spark"
  }
], Ek = Ce.create({
  name: "aiCommand",
  // @ts-ignore
  addOptions() {
    return {
      suggestion: {
        char: "/",
        command: ({ editor: t, range: e, props: n }) => {
          t.chain().focus().deleteRange(e).run();
          let r = n;
          const i = t.state.selection.$head.parent.textContent, s = t.userOptions, o = il.create(r.model, s);
          o ? o == null || o.start(i, r.prompt, t) : console.error("Ai model config error.");
        },
        render: () => {
          let t, e, n = 0, r;
          const i = () => {
            t.innerHTML = `
                            <div class="items">
                             ${r.items.map((s, o) => `<button class="item ${o === n ? "item-selected" : ""}" data-index="${o}">${s.name}</button>`).join("")}
                            </div>
                            `, t.addEventListener("click", (s) => {
              const o = s.target.closest(".item");
              if (o) {
                const a = Number(o.getAttribute("data-index")), l = r.items[a];
                l && r.command(l);
              }
            });
          };
          return {
            onStart: (s) => {
              t = document.createElement("div"), t.classList.add("suggestion"), r = s, s.clientRect && (i(), e = ht("body", {
                getReferenceClientRect: s.clientRect,
                appendTo: () => s.editor.view.dom.closest(".aie-container"),
                content: t,
                showOnCreate: !0,
                interactive: !0,
                allowHTML: !0,
                trigger: "manual",
                placement: "right-start"
              }));
            },
            onUpdate(s) {
              r = s, s.clientRect && e[0].setProps({
                getReferenceClientRect: s.clientRect
              });
            },
            onKeyDown(s) {
              if (s.event.key === "Escape")
                return e[0].hide(), !0;
              if (s.event.key === "ArrowUp")
                return n = (n + r.items.length - 1) % r.items.length, i(), !0;
              if (s.event.key === "ArrowDown")
                return n = (n + 1) % r.items.length, i(), !0;
              if (s.event.key === "Enter") {
                const o = r.items[n];
                return o && r.command(o), !0;
              }
              return !1;
            },
            onExit() {
              e[0].destroy(), t.remove();
            }
          };
        }
      }
    };
  },
  addProseMirrorPlugins() {
    return [
      lh({
        editor: this.editor,
        ...this.options.suggestion
      })
    ];
  }
}), xk = (t, e) => {
  var r, i, s, o, a, l, c, d, u;
  const n = e.cbName && e.cbUrl ? [od.configure({
    history: !1,
    codeBlock: !1
  })] : [od.configure({
    codeBlock: !1
  })];
  return n.push(
    Fw,
    Uw,
    Kw,
    Gw.configure({
      uploadUrl: (r = e.video) == null ? void 0 : r.uploadUrl,
      uploadHeaders: (i = e.video) == null ? void 0 : i.uploadHeaders,
      uploader: ((s = e.video) == null ? void 0 : s.uploader) || e.uploader
    }),
    jw,
    Xw.configure({
      multicolor: !0
    }),
    Qw,
    eE,
    tE,
    nE.configure({
      types: ["heading", "paragraph"]
    }),
    rE,
    oE.configure({
      allowBase64: !0,
      uploadUrl: (o = e.image) == null ? void 0 : o.uploadUrl,
      uploadHeaders: (a = e.image) == null ? void 0 : a.uploadHeaders,
      uploader: ((l = e.image) == null ? void 0 : l.uploader) || e.uploader
    }),
    ax.configure({
      resizable: !0,
      lastColumnResizable: !0,
      allowTableNodeSelection: !0
    }),
    lx,
    cx,
    dx,
    ux,
    Ix.configure({
      openOnClick: !1
    }),
    Dx,
    Hx,
    Bx,
    $x.configure({
      nested: !0
    }),
    US.configure({
      lowlight: ek(iM),
      defaultLanguage: "plaintext",
      languageClassPrefix: "language-"
    }),
    rk.configure({
      uploadUrl: (c = e.video) == null ? void 0 : c.uploadUrl,
      uploadHeaders: (d = e.video) == null ? void 0 : d.uploadHeaders,
      uploader: ((u = e.video) == null ? void 0 : u.uploader) || e.uploader
    }),
    ik,
    ...pk(t)
  ), e.placeholder && n.push(hk.configure({
    placeholder: e.placeholder
  })), n.push(Ek.configure({
    suggestion: {
      items: (f) => {
        var h;
        return ((h = e.ai) == null ? void 0 : h.command) || wk;
      }
    }
  })), e.onMentionQuery && n.push(vk(e.onMentionQuery)), n;
};
window.customElements.define("aie-menus", Uv);
window.customElements.define("aie-footer", Kv);
const Sk = {
  theme: "light",
  placeholder: ""
};
class Ck extends t0 {
  constructor(n, r = {}) {
    super(r);
    q(this, "userOptions");
    this.userOptions = n;
  }
}
class qk {
  constructor(e) {
    q(this, "innerEditor");
    q(this, "container");
    q(this, "menus");
    q(this, "footer");
    q(this, "options");
    q(this, "eventComponents", []);
    this.options = Object.assign(Sk, e);
    const n = typeof this.options.element == "string" ? document.querySelector(this.options.element) : this.options.element;
    n.classList.add(`aie-theme-${this.options.theme}`), this.container = document.createElement("div"), this.container.classList.add("aie-container"), n.appendChild(this.container);
    const r = document.createElement("div");
    r.style.flexGrow = "1", r.style.overflow = "auto", this.menus = document.createElement("aie-menus"), this.footer = document.createElement("aie-footer"), this.eventComponents.push(this.menus), this.eventComponents.push(this.footer), this.innerEditor = new Ck(this.options, {
      element: r,
      content: this.options.content,
      extensions: xk(this, this.options),
      onCreate: (i) => this.onCreate(i, r),
      onTransaction: (i) => this.onTransaction(i),
      onDestroy: () => this.onDestroy,
      editorProps: {
        attributes: {
          class: "aie-content"
        }
      }
    });
  }
  onCreate(e, n) {
    this.innerEditor.view.dom.style.height = "calc(100% - 20px)", this.eventComponents.forEach((r) => {
      r.onCreate && r.onCreate(e, this.options);
    }), this.container.appendChild(this.menus), this.container.appendChild(n), this.container.appendChild(this.footer);
  }
  onTransaction(e) {
    this.eventComponents.forEach((n) => {
      n.onTransaction && n.onTransaction(e);
    }), e.transaction.docChanged && this.options.onChange && this.options.onChange(this);
  }
  onDestroy() {
    for (; this.container.firstChild; )
      this.container.firstChild.remove();
  }
  getHtml() {
    return this.innerEditor.getHTML();
  }
  getJson() {
    return this.innerEditor.getJSON();
  }
  getText() {
    return this.innerEditor.getText();
  }
}
export {
  qk as AiEditor,
  Ck as InnerEditor
};
