import { __exports as f } from "./index-LexicalUtils.prod2.js";
import { __require as C } from "./index-LexicalSelection.js";
import { __require as k } from "./index-Lexical.js";
var P;
function D() {
  if (P) return f;
  P = 1;
  var L = C(), s = k();
  function w(e) {
    let t = new URLSearchParams();
    t.append("code", e);
    for (let n = 1; n < arguments.length; n++) t.append("v", arguments[n]);
    throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
  }
  function _(...e) {
    return () => {
      e.forEach((t) => t());
    };
  }
  let B = { attributes: !0, characterData: !0, childList: !0, subtree: !0 };
  function R(e, t, n) {
    function o() {
      if (i === null) throw Error("Unexpected null rootDOMNode");
      if (c === null) throw Error("Unexpected null parentDOMNode");
      let { left: g, top: T } = i.getBoundingClientRect();
      var h = c;
      let m = L.createRectsFromDOMRange(e, t);
      p.isConnected || h.append(p), h = !1;
      for (let v = 0; v < m.length; v++) {
        var N = m[v];
        let E = u[v] || document.createElement("div"), $ = E.style;
        $.position !== "absolute" && ($.position = "absolute", h = !0);
        var d = `${N.left - g}px`;
        $.left !== d && ($.left = d, h = !0), d = `${N.top - T}px`, $.top !== d && (E.style.top = d, h = !0), d = `${N.width}px`, $.width !== d && (E.style.width = d, h = !0), N = `${N.height}px`, $.height !== N && (E.style.height = N, h = !0), E.parentNode !== p && (p.append(E), h = !0), u[v] = E;
      }
      for (; u.length > m.length; ) u.pop();
      h && n(u);
    }
    function r() {
      i = c = null, a !== null && a.disconnect(), a = null, p.remove();
      for (let g of u) g.remove();
      u = [];
    }
    function l() {
      let g = e.getRootElement();
      if (g === null) return r();
      let T = g.parentElement;
      if (!(T instanceof HTMLElement)) return r();
      r(), i = g, c = T, a = new MutationObserver((h) => {
        let m = e.getRootElement(), N = m && m.parentElement;
        if (m !== i || N !== c) return l();
        for (let d of h) if (!p.contains(d.target)) return o();
      }), a.observe(T, B), o();
    }
    let i = null, c = null, a = null, u = [], p = document.createElement("div"), y = e.registerRootListener(l);
    return () => {
      y(), r();
    };
  }
  function S(e, t) {
    for (let n of t) if (e.type.startsWith(n)) return !0;
    return !1;
  }
  let M = (e, t) => {
    for (; e !== s.$getRoot() && e != null; ) {
      if (t(e)) return e;
      e = e.getParent();
    }
    return null;
  };
  return f.$splitNode = s.$splitNode, f.isHTMLAnchorElement = s.isHTMLAnchorElement, f.isHTMLElement = s.isHTMLElement, f.$dfs = function(e, t) {
    let n = [];
    e = (e || s.$getRoot()).getLatest(), t = t || (s.$isElementNode(e) ? e.getLastDescendant() : e);
    for (var o = e, r = 0; (o = o.getParent()) !== null; ) r++;
    for (o = r; e !== null && !e.is(t); ) if (n.push({ depth: o, node: e }), s.$isElementNode(e) && 0 < e.getChildrenSize()) e = e.getFirstChild(), o++;
    else for (r = null; r === null && e !== null; ) r = e.getNextSibling(), r === null ? (e = e.getParent(), o--) : e = r;
    return e !== null && e.is(t) && n.push({ depth: o, node: e }), n;
  }, f.$filter = function(e, t) {
    let n = [];
    for (let o = 0; o < e.length; o++) {
      let r = t(e[o]);
      r !== null && n.push(r);
    }
    return n;
  }, f.$findMatchingParent = M, f.$getNearestBlockElementAncestorOrThrow = function(e) {
    let t = M(e, (n) => s.$isElementNode(n) && !n.isInline());
    return s.$isElementNode(t) || w(4, e.__key), t;
  }, f.$getNearestNodeOfType = function(e, t) {
    for (; e != null; ) {
      if (e instanceof t) return e;
      e = e.getParent();
    }
    return null;
  }, f.$insertFirst = function(e, t) {
    let n = e.getFirstChild();
    n !== null ? n.insertBefore(t) : e.append(t);
  }, f.$insertNodeToNearestRoot = function(e) {
    var t = s.$getSelection() || s.$getPreviousSelection();
    if (s.$isRangeSelection(t)) {
      var { focus: n } = t;
      if (t = n.getNode(), n = n.offset, s.$isRootOrShadowRoot(t)) n = t.getChildAtIndex(n), n == null ? t.append(e) : n.insertBefore(e), e.selectNext();
      else {
        let o, r;
        s.$isTextNode(t) ? (o = t.getParentOrThrow(), r = t.getIndexWithinParent(), 0 < n && (r += 1, t.splitText(n))) : (o = t, r = n), [, t] = s.$splitNode(o, r), t.insertBefore(e), t.selectStart();
      }
    } else t != null ? (t = t.getNodes(), t[t.length - 1].getTopLevelElementOrThrow().insertAfter(e)) : s.$getRoot().append(e), t = s.$createParagraphNode(), e.insertAfter(t), t.select();
    return e.getLatest();
  }, f.$restoreEditorState = function(e, t) {
    let n = /* @__PURE__ */ new Map(), o = e._pendingEditorState;
    for (let [r, l] of t._nodeMap) {
      let i = L.$cloneWithProperties(l);
      if (s.$isTextNode(i)) {
        if (!s.$isTextNode(l)) throw Error("Expected node be a TextNode");
        i.__text = l.__text;
      }
      n.set(r, i);
    }
    o && (o._nodeMap = n), e._dirtyType = 2, e = t._selection, s.$setSelection(e === null ? null : e.clone());
  }, f.$wrapNodeInElement = function(e, t) {
    return t = t(), e.replace(t), t.append(e), t;
  }, f.addClassNamesToElement = function(e, ...t) {
    t.forEach((n) => {
      typeof n == "string" && (n = n.split(" ").filter((o) => o !== ""), e.classList.add(...n));
    });
  }, f.isMimeType = S, f.markSelection = function(e, t) {
    function n(a) {
      a.read(() => {
        var u = s.$getSelection();
        if (s.$isRangeSelection(u)) {
          var { anchor: p, focus: y } = u;
          u = p.getNode();
          var g = u.getKey(), T = p.offset, h = y.getNode(), m = h.getKey(), N = y.offset, d = e.getElementByKey(g), v = e.getElementByKey(m);
          if (g = o === null || d === null || T !== r || g !== o.getKey() || u !== o && (!(o instanceof s.TextNode) || u.updateDOM(o, d, e._config)), m = l === null || v === null || N !== i || m !== l.getKey() || h !== l && (!(l instanceof s.TextNode) || h.updateDOM(l, v, e._config)), g || m) {
            d = e.getElementByKey(p.getNode().getKey());
            var E = e.getElementByKey(y.getNode().getKey());
            if (d !== null && E !== null && d.tagName === "SPAN" && E.tagName === "SPAN") {
              if (m = document.createRange(), y.isBefore(p) ? (g = E, v = y.offset, E = d, d = p.offset) : (g = d, v = p.offset, d = y.offset), g = g.firstChild, g === null || (E = E.firstChild, E === null)) throw Error("Expected text node to be first child of span");
              m.setStart(g, v), m.setEnd(E, d), c(), c = R(e, m, ($) => {
                for (let O of $) {
                  let x = O.style;
                  x.background !== "Highlight" && (x.background = "Highlight"), x.color !== "HighlightText" && (x.color = "HighlightText"), x.zIndex !== "-1" && (x.zIndex = "-1"), x.pointerEvents !== "none" && (x.pointerEvents = "none"), x.marginTop !== "-1.5px" && (x.marginTop = "-1.5px"), x.paddingTop !== "4px" && (x.paddingTop = "4px"), x.paddingBottom !== "0px" && (x.paddingBottom = "0px");
                }
                t !== void 0 && t($);
              });
            }
          }
          o = u, r = T, l = h, i = N;
        } else i = l = r = o = null, c(), c = () => {
        };
      });
    }
    let o = null, r = null, l = null, i = null, c = () => {
    };
    return n(e.getEditorState()), _(e.registerUpdateListener(({ editorState: a }) => n(a)), c, () => {
      c();
    });
  }, f.mediaFileReader = function(e, t) {
    let n = e[Symbol.iterator]();
    return new Promise((o, r) => {
      let l = [], i = () => {
        const { done: c, value: a } = n.next();
        if (c) return o(l);
        const u = new FileReader();
        u.addEventListener("error", r), u.addEventListener("load", () => {
          const p = u.result;
          typeof p == "string" && l.push({ file: a, result: p }), i();
        }), S(a, t) ? u.readAsDataURL(a) : i();
      };
      i();
    });
  }, f.mergeRegister = _, f.objectKlassEquals = function(e, t) {
    return e !== null ? Object.getPrototypeOf(e).constructor.name === t.name : !1;
  }, f.positionNodeOnRange = R, f.registerNestedElementResolver = function(e, t, n, o) {
    return e.registerNodeTransform(t, (r) => {
      e: {
        for (var l = r.getChildren(), i = 0; i < l.length; i++) if (l[i] instanceof t) {
          l = null;
          break e;
        }
        for (l = r; l !== null; ) if (i = l, l = l.getParent(), l instanceof t) {
          l = { child: i, parent: l };
          break e;
        }
        l = null;
      }
      if (l !== null) {
        const { child: c, parent: a } = l;
        if (c.is(r)) {
          if (o(a, r), r = c.getNextSiblings(), l = r.length, a.insertAfter(c), l !== 0) {
            i = n(a), c.insertAfter(i);
            for (let u = 0; u < l; u++) i.append(r[u]);
          }
          a.canBeEmpty() || a.getChildrenSize() !== 0 || a.remove();
        }
      }
    });
  }, f.removeClassNamesFromElement = function(e, ...t) {
    t.forEach((n) => {
      typeof n == "string" && e.classList.remove(...n.split(" "));
    });
  }, f;
}
export {
  D as __require
};
