import { __exports as a } from "./index-LexicalList.prod2.js";
import { __require as b } from "./index-Lexical.js";
import { __require as z } from "./index-LexicalUtils.js";
var w;
function j() {
  if (w) return a;
  w = 1;
  var h = b(), m = z();
  function v(i) {
    let e = new URLSearchParams();
    e.append("code", i);
    for (let t = 1; t < arguments.length; t++) e.append("v", arguments[t]);
    throw Error(`Minified Lexical error #${i}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
  }
  function L(i) {
    let e = 1;
    for (i = i.getParent(); i != null; ) {
      if (g(i)) {
        if (i = i.getParent(), o(i)) {
          e++, i = i.getParent();
          continue;
        }
        v(40);
      }
      break;
    }
    return e;
  }
  function y(i) {
    i = i.getParent(), o(i) || v(40);
    let e = i;
    for (; e !== null; ) e = e.getParent(), o(e) && (i = e);
    return i;
  }
  function E(i) {
    let e = [];
    i = i.getChildren().filter(g);
    for (let t = 0; t < i.length; t++) {
      let r = i[t], n = r.getFirstChild();
      o(n) ? e = e.concat(E(n)) : e.push(r);
    }
    return e;
  }
  function f(i) {
    return g(i) && o(i.getFirstChild());
  }
  function F(i) {
    for (; i.getNextSibling() == null && i.getPreviousSibling() == null; ) {
      let e = i.getParent();
      if (e == null || !g(i) && !o(i)) break;
      i = e;
    }
    i.remove();
  }
  function P(i) {
    return c().append(i);
  }
  function k(i, e) {
    return g(i) && (e.length === 0 || e.length === 1 && i.is(e[0]) && i.getChildrenSize() === 0);
  }
  function _(i, e) {
    i.splice(i.getChildrenSize(), 0, e);
  }
  function O(i, e) {
    if (o(i)) return i;
    let t = i.getPreviousSibling(), r = i.getNextSibling(), n = c();
    return n.setFormat(i.getFormatType()), n.setIndent(i.getIndent()), _(n, i.getChildren()), o(t) && e === t.getListType() ? (t.append(n), i.remove(), o(r) && e === r.getListType() && (_(t, r.getChildren()), r.remove()), t) : o(r) && e === r.getListType() ? (r.getFirstChildOrThrow().insertBefore(n), i.remove(), r) : (e = p(e), e.append(n), i.replace(e), d(e), e);
  }
  function x(i, e) {
    var t = i.getLastChild();
    let r = e.getFirstChild();
    t && r && f(t) && f(r) && (x(t.getFirstChild(), r.getFirstChild()), r.remove()), t = e.getChildren(), 0 < t.length && (i.append(...t), d(i)), e.remove();
  }
  function d(i, e) {
    if (i = e || i.getChildren(), i !== void 0) for (e = 0; e < i.length; e++) {
      let s = i[e];
      if (g(s)) {
        let l = s.getValue();
        var t = s, r = t.getParent(), n = 1;
        for (r != null && (o(r) ? n = r.getStart() : v(44)), t = t.getPreviousSiblings(), r = 0; r < t.length; r++) {
          let u = t[r];
          g(u) && !o(u.getFirstChild()) && n++;
        }
        l !== n && s.setValue(n);
      }
    }
  }
  function B(i) {
    if (!f(i)) {
      var e = i.getParent(), t = e ? e.getParent() : void 0, r = t ? t.getParent() : void 0;
      if (o(r) && g(t) && o(e)) {
        var n = e ? e.getFirstChild() : void 0, s = e ? e.getLastChild() : void 0;
        if (i.is(n)) t.insertBefore(i), e.isEmpty() && t.remove();
        else if (i.is(s)) t.insertAfter(i), e.isEmpty() && t.remove();
        else {
          var l = e.getListType();
          n = c();
          let u = p(l);
          n.append(u), i.getPreviousSiblings().forEach((T) => u.append(T)), s = c(), l = p(l), s.append(l), _(l, i.getNextSiblings()), t.insertBefore(n), t.insertAfter(s), t.replace(i);
        }
        d(e), d(r);
      }
    }
  }
  class C extends h.ElementNode {
    static getType() {
      return "listitem";
    }
    static clone(e) {
      return new C(e.__value, e.__checked, e.__key);
    }
    constructor(e, t, r) {
      super(r), this.__value = e === void 0 ? 1 : e, this.__checked = t;
    }
    createDOM(e) {
      let t = document.createElement("li"), r = this.getParent();
      return o(r) && r.getListType() === "check" && M(t, this, null), t.value = this.__value, A(t, e.theme, this), t;
    }
    updateDOM(e, t, r) {
      let n = this.getParent();
      return o(n) && n.getListType() === "check" && M(t, this, e), t.value = this.__value, A(t, r.theme, this), !1;
    }
    static transform() {
      return (e) => {
        let t = e.getParent();
        if (o(t)) {
          if (d(t), !g(e)) throw Error("node is not a ListItemNode");
          t.getListType() !== "check" && e.getChecked() != null && e.setChecked(void 0);
        }
      };
    }
    static importDOM() {
      return { li: () => ({ conversion: K, priority: 0 }) };
    }
    static importJSON(e) {
      let t = c();
      return t.setChecked(e.checked), t.setValue(e.value), t.setFormat(e.format), t.setDirection(e.direction), t;
    }
    exportDOM(e) {
      return e = this.createDOM(e._config), e.style.textAlign = this.getFormatType(), { element: e };
    }
    exportJSON() {
      return {
        ...super.exportJSON(),
        checked: this.getChecked(),
        type: "listitem",
        value: this.getValue(),
        version: 1
      };
    }
    append(...e) {
      for (let t = 0; t < e.length; t++) {
        let r = e[t];
        if (h.$isElementNode(r) && this.canMergeWith(r)) {
          let n = r.getChildren();
          this.append(...n), r.remove();
        } else super.append(r);
      }
      return this;
    }
    replace(e, t) {
      if (g(e)) return super.replace(e);
      this.setIndent(0);
      let r = this.getParentOrThrow();
      if (!o(r)) return e;
      if (r.__first === this.getKey()) r.insertBefore(e);
      else if (r.__last === this.getKey()) r.insertAfter(e);
      else {
        let n = p(r.getListType()), s = this.getNextSibling();
        for (; s; ) {
          let l = s;
          s = s.getNextSibling(), n.append(l);
        }
        r.insertAfter(e), e.insertAfter(n);
      }
      if (t) {
        if (!h.$isElementNode(e)) throw Error("includeChildren should only be true for ElementNodes");
        this.getChildren().forEach((n) => {
          e.append(n);
        });
      }
      return this.remove(), r.getChildrenSize() === 0 && r.remove(), e;
    }
    insertAfter(e, t = !0) {
      var r = this.getParentOrThrow();
      o(r) || v(39);
      var n = this.getNextSiblings();
      if (g(e)) return t = super.insertAfter(e, t), e = e.getParentOrThrow(), o(e) && d(e), t;
      if (o(e)) {
        for (r = e, e = e.getChildren(), n = e.length - 1; 0 <= n; n--) r = e[n], this.insertAfter(r, t);
        return r;
      }
      if (r.insertAfter(e, t), n.length !== 0) {
        let s = p(r.getListType());
        n.forEach((l) => s.append(l)), e.insertAfter(s, t);
      }
      return e;
    }
    remove(e) {
      let t = this.getPreviousSibling(), r = this.getNextSibling();
      super.remove(e), t && r && f(t) && f(r) ? (x(t.getFirstChild(), r.getFirstChild()), r.remove()) : r && (e = r.getParent(), o(e) && d(e));
    }
    insertNewAfter(e, t = !0) {
      return e = c(this.__checked == null ? void 0 : !1), this.insertAfter(e, t), e;
    }
    collapseAtStart(e) {
      let t = h.$createParagraphNode();
      this.getChildren().forEach((l) => t.append(l));
      var r = this.getParentOrThrow(), n = r.getParentOrThrow();
      let s = g(n);
      return r.getChildrenSize() === 1 ? s ? (r.remove(), n.select()) : (r.insertBefore(t), r.remove(), r = e.anchor, e = e.focus, n = t.getKey(), r.type === "element" && r.getNode().is(this) && r.set(n, r.offset, "element"), e.type === "element" && e.getNode().is(this) && e.set(n, e.offset, "element")) : (r.insertBefore(t), this.remove()), !0;
    }
    getValue() {
      return this.getLatest().__value;
    }
    setValue(e) {
      this.getWritable().__value = e;
    }
    getChecked() {
      return this.getLatest().__checked;
    }
    setChecked(e) {
      this.getWritable().__checked = e;
    }
    toggleChecked() {
      this.setChecked(!this.__checked);
    }
    getIndent() {
      var e = this.getParent();
      if (e === null) return this.getLatest().__indent;
      e = e.getParentOrThrow();
      let t = 0;
      for (; g(e); ) e = e.getParentOrThrow().getParentOrThrow(), t++;
      return t;
    }
    setIndent(e) {
      typeof e == "number" && -1 < e || v(117);
      let t = this.getIndent();
      for (; t !== e; ) if (t < e) {
        e: {
          var r = /* @__PURE__ */ new Set();
          if (f(this) || r.has(this.getKey())) break e;
          let u = this.getParent();
          var n = this.getNextSibling(), s = this.getPreviousSibling();
          if (f(n) && f(s)) {
            if (s = s.getFirstChild(), o(s)) {
              s.append(this);
              var l = n.getFirstChild();
              o(l) && (l = l.getChildren(), _(s, l), n.remove(), r.add(n.getKey())), d(s);
            }
          } else f(n) ? (n = n.getFirstChild(), o(n) && (r = n.getFirstChild(), r !== null && r.insertBefore(this), d(n))) : f(s) ? (n = s.getFirstChild(), o(n) && (n.append(this), d(n))) : o(u) && (r = c(), l = p(u.getListType()), r.append(l), l.append(this), s ? s.insertAfter(r) : n ? n.insertBefore(r) : u.append(r), d(l));
          o(u) && d(u);
        }
        t++;
      } else B(this), t--;
      return this;
    }
    insertBefore(e) {
      if (g(e)) {
        let t = this.getParentOrThrow();
        if (o(t)) {
          let r = this.getNextSiblings();
          d(
            t,
            r
          );
        }
      }
      return super.insertBefore(e);
    }
    canInsertAfter(e) {
      return g(e);
    }
    canReplaceWith(e) {
      return g(e);
    }
    canMergeWith(e) {
      return h.$isParagraphNode(e) || g(e);
    }
    extractWithChild(e, t) {
      if (!h.$isRangeSelection(t)) return !1;
      e = t.anchor.getNode();
      let r = t.focus.getNode();
      return this.isParentOf(e) && this.isParentOf(r) && this.getTextContent().length === t.getTextContent().length;
    }
    isParentRequired() {
      return !0;
    }
    createParentElementNode() {
      return p("bullet");
    }
  }
  function A(i, e, t) {
    let r = [], n = [];
    var s = (e = e.list) ? e.listitem : void 0;
    if (e && e.nested) var l = e.nested.listitem;
    if (s !== void 0 && (s = s.split(" "), r.push(...s)), e) {
      s = t.getParent(), s = o(s) && s.getListType() === "check";
      let u = t.getChecked();
      s && !u || n.push(e.listitemUnchecked), s && u || n.push(e.listitemChecked), s && r.push(u ? e.listitemChecked : e.listitemUnchecked);
    }
    l !== void 0 && (l = l.split(" "), t.getChildren().some((u) => o(u)) ? r.push(...l) : n.push(...l)), 0 < n.length && m.removeClassNamesFromElement(i, ...n), 0 < r.length && m.addClassNamesToElement(
      i,
      ...r
    );
  }
  function M(i, e, t) {
    o(e.getFirstChild()) ? (i.removeAttribute("role"), i.removeAttribute("tabIndex"), i.removeAttribute("aria-checked")) : (i.setAttribute("role", "checkbox"), i.setAttribute("tabIndex", "-1"), t && e.__checked === t.__checked || i.setAttribute("aria-checked", e.getChecked() ? "true" : "false"));
  }
  function K(i) {
    return i = m.isHTMLElement(i) && i.getAttribute("aria-checked") === "true", { node: c(i) };
  }
  function c(i) {
    return h.$applyNodeReplacement(new C(void 0, i));
  }
  function g(i) {
    return i instanceof C;
  }
  class N extends h.ElementNode {
    static getType() {
      return "list";
    }
    static clone(e) {
      return new N(e.__listType || R[e.__tag], e.__start, e.__key);
    }
    constructor(e, t, r) {
      super(r), this.__listType = e = R[e] || e, this.__tag = e === "number" ? "ol" : "ul", this.__start = t;
    }
    getTag() {
      return this.__tag;
    }
    setListType(e) {
      let t = this.getWritable();
      t.__listType = e, t.__tag = e === "number" ? "ol" : "ul";
    }
    getListType() {
      return this.__listType;
    }
    getStart() {
      return this.__start;
    }
    createDOM(e) {
      let t = document.createElement(this.__tag);
      return this.__start !== 1 && t.setAttribute(
        "start",
        String(this.__start)
      ), t.__lexicalListType = this.__listType, $(t, e.theme, this), t;
    }
    updateDOM(e, t, r) {
      return e.__tag !== this.__tag ? !0 : ($(t, r.theme, this), !1);
    }
    static importDOM() {
      return { ol: () => ({ conversion: I, priority: 0 }), ul: () => ({ conversion: I, priority: 0 }) };
    }
    static importJSON(e) {
      let t = p(e.listType, e.start);
      return t.setFormat(e.format), t.setIndent(e.indent), t.setDirection(e.direction), t;
    }
    exportDOM(e) {
      return { element: e } = super.exportDOM(e), e && m.isHTMLElement(e) && (this.__start !== 1 && e.setAttribute("start", String(this.__start)), this.__listType === "check" && e.setAttribute("__lexicalListType", "check")), { element: e };
    }
    exportJSON() {
      return { ...super.exportJSON(), listType: this.getListType(), start: this.getStart(), tag: this.getTag(), type: "list", version: 1 };
    }
    canBeEmpty() {
      return !1;
    }
    canIndent() {
      return !1;
    }
    append(...e) {
      for (let r = 0; r < e.length; r++) {
        var t = e[r];
        if (g(t)) super.append(t);
        else {
          let n = c();
          o(t) || h.$isElementNode(t) && (t = h.$createTextNode(t.getTextContent())), n.append(t), super.append(n);
        }
      }
      return d(this), this;
    }
    extractWithChild(e) {
      return g(e);
    }
  }
  function $(i, e, t) {
    let r = [], n = [];
    var s = e.list;
    if (s !== void 0) {
      let u = s[`${t.__tag}Depth`] || [];
      e = L(t) - 1;
      let T = e % u.length;
      var l = u[T];
      let D = s[t.__tag], S;
      if (s = s.nested, s !== void 0 && s.list && (S = s.list), D !== void 0 && r.push(D), l !== void 0) for (l = l.split(" "), r.push(...l), l = 0; l < u.length; l++) l !== T && n.push(t.__tag + l);
      S !== void 0 && (t = S.split(" "), 1 < e ? r.push(...t) : n.push(...t));
    }
    0 < n.length && m.removeClassNamesFromElement(i, ...n), 0 < r.length && m.addClassNamesToElement(i, ...r);
  }
  function q(i) {
    let e = [];
    for (let r = 0; r < i.length; r++) {
      var t = i[r];
      g(t) ? (e.push(t), t = t.getChildren(), 1 < t.length && t.forEach((n) => {
        o(n) && e.push(P(n));
      })) : e.push(P(t));
    }
    return e;
  }
  function I(i) {
    let e = i.nodeName.toLowerCase(), t = null;
    return e === "ol" ? t = p("number", i.start) : e === "ul" && (t = m.isHTMLElement(i) && i.getAttribute("__lexicallisttype") === "check" ? p("check") : p("bullet")), { after: q, node: t };
  }
  let R = { ol: "number", ul: "bullet" };
  function p(i, e = 1) {
    return h.$applyNodeReplacement(new N(i, e));
  }
  function o(i) {
    return i instanceof N;
  }
  let V = h.createCommand("INSERT_UNORDERED_LIST_COMMAND"), W = h.createCommand("INSERT_ORDERED_LIST_COMMAND"), J = h.createCommand("INSERT_CHECK_LIST_COMMAND"), U = h.createCommand("REMOVE_LIST_COMMAND");
  return a.$createListItemNode = c, a.$createListNode = p, a.$getListDepth = L, a.$handleListInsertParagraph = function() {
    var i = h.$getSelection();
    if (!h.$isRangeSelection(i) || !i.isCollapsed() || (i = i.anchor.getNode(), !g(i) || i.getChildrenSize() !== 0)) return !1;
    var e = y(i), t = i.getParent();
    o(t) || v(40);
    let r = t.getParent(), n;
    if (h.$isRootOrShadowRoot(r)) n = h.$createParagraphNode(), e.insertAfter(n);
    else if (g(r)) n = c(), r.insertAfter(n);
    else return !1;
    if (n.select(), e = i.getNextSiblings(), 0 < e.length) {
      let s = p(t.getListType());
      h.$isParagraphNode(n) ? n.insertAfter(s) : (t = c(), t.append(s), n.insertAfter(t)), e.forEach((l) => {
        l.remove(), s.append(l);
      });
    }
    return F(i), !0;
  }, a.$isListItemNode = g, a.$isListNode = o, a.INSERT_CHECK_LIST_COMMAND = J, a.INSERT_ORDERED_LIST_COMMAND = W, a.INSERT_UNORDERED_LIST_COMMAND = V, a.ListItemNode = C, a.ListNode = N, a.REMOVE_LIST_COMMAND = U, a.insertList = function(i, e) {
    i.update(() => {
      var t = h.$getSelection();
      if (h.$INTERNAL_isPointSelection(t)) {
        var r = t.getNodes();
        t = t.anchor.getNode();
        var n = t.getParent();
        if (k(t, r)) r = p(e), h.$isRootOrShadowRoot(n) ? (t.replace(r), n = c(), h.$isElementNode(t) && (n.setFormat(t.getFormatType()), n.setIndent(t.getIndent())), r.append(n)) : g(t) && (t = t.getParentOrThrow(), _(r, t.getChildren()), t.replace(r));
        else for (t = /* @__PURE__ */ new Set(), n = 0; n < r.length; n++) {
          var s = r[n];
          if (h.$isElementNode(s) && s.isEmpty() && !g(s) && !t.has(s.getKey())) O(
            s,
            e
          );
          else if (h.$isLeafNode(s)) for (s = s.getParent(); s != null; ) {
            let u = s.getKey();
            if (o(s)) {
              if (!t.has(u)) {
                var l = p(e);
                _(l, s.getChildren()), s.replace(l), d(l), t.add(u);
              }
              break;
            } else {
              if (l = s.getParent(), h.$isRootOrShadowRoot(l) && !t.has(u)) {
                t.add(u), O(s, e);
                break;
              }
              s = l;
            }
          }
        }
      }
    });
  }, a.removeList = function(i) {
    i.update(() => {
      let e = h.$getSelection();
      if (h.$isRangeSelection(e)) {
        var t = /* @__PURE__ */ new Set(), r = e.getNodes(), n = e.anchor.getNode();
        if (k(n, r)) t.add(y(n));
        else for (n = 0; n < r.length; n++) {
          var s = r[n];
          h.$isLeafNode(s) && (s = m.$getNearestNodeOfType(s, C), s != null && t.add(y(s)));
        }
        for (let l of t) {
          t = l, r = E(l);
          for (let u of r) r = h.$createParagraphNode(), _(r, u.getChildren()), t.insertAfter(r), t = r, u.__key === e.anchor.key && e.anchor.set(r.getKey(), 0, "element"), u.__key === e.focus.key && e.focus.set(r.getKey(), 0, "element"), u.remove();
          l.remove();
        }
      }
    });
  }, a;
}
export {
  j as __require
};
