import { __exports as s } from "./index-LexicalRichText.prod2.js";
import { __require as L } from "./index-LexicalClipboard.js";
import { __require as w } from "./index-LexicalSelection.js";
import { __require as K } from "./index-LexicalUtils.js";
import { __require as F } from "./index-Lexical.js";
var p;
function B() {
  if (p) return s;
  p = 1;
  var m = L(), N = w(), a = K(), t = F();
  function M(n, e) {
    return typeof document.caretRangeFromPoint < "u" ? (n = document.caretRangeFromPoint(n, e), n === null ? null : { node: n.startContainer, offset: n.startOffset }) : document.caretPositionFromPoint !== "undefined" ? (n = document.caretPositionFromPoint(n, e), n === null ? null : { node: n.offsetNode, offset: n.offset }) : null;
  }
  let c = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", A = c && "documentMode" in document ? document.documentMode : null, I = c && "InputEvent" in window && !A ? "getTargetRanges" in new window.InputEvent("input") : !1, h = c && /Version\/[\d.]+.*Safari/.test(navigator.userAgent), $ = c && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream, S = c && /^(?=.*Chrome).*/i.test(navigator.userAgent), P = c && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !S, _ = t.createCommand("DRAG_DROP_PASTE_FILE");
  class f extends t.ElementNode {
    static getType() {
      return "quote";
    }
    static clone(e) {
      return new f(e.__key);
    }
    constructor(e) {
      super(e);
    }
    createDOM(e) {
      let r = document.createElement("blockquote");
      return a.addClassNamesToElement(r, e.theme.quote), r;
    }
    updateDOM() {
      return !1;
    }
    static importDOM() {
      return { blockquote: () => ({ conversion: v, priority: 0 }) };
    }
    exportDOM(e) {
      if ({ element: e } = super.exportDOM(e), e && a.isHTMLElement(e)) {
        this.isEmpty() && e.append(document.createElement("br"));
        var r = this.getFormatType();
        e.style.textAlign = r, (r = this.getDirection()) && (e.dir = r);
      }
      return { element: e };
    }
    static importJSON(e) {
      let r = D();
      return r.setFormat(e.format), r.setIndent(e.indent), r.setDirection(e.direction), r;
    }
    exportJSON() {
      return { ...super.exportJSON(), type: "quote" };
    }
    insertNewAfter(e, r) {
      e = t.$createParagraphNode();
      let i = this.getDirection();
      return e.setDirection(i), this.insertAfter(e, r), e;
    }
    collapseAtStart() {
      let e = t.$createParagraphNode();
      return this.getChildren().forEach((r) => e.append(r)), this.replace(e), !0;
    }
  }
  function D() {
    return t.$applyNodeReplacement(new f());
  }
  class g extends t.ElementNode {
    static getType() {
      return "heading";
    }
    static clone(e) {
      return new g(e.__tag, e.__key);
    }
    constructor(e, r) {
      super(r), this.__tag = e;
    }
    getTag() {
      return this.__tag;
    }
    createDOM(e) {
      let r = this.__tag, i = document.createElement(r);
      return e = e.theme.heading, e !== void 0 && a.addClassNamesToElement(i, e[r]), i;
    }
    updateDOM() {
      return !1;
    }
    static importDOM() {
      return { h1: () => ({ conversion: u, priority: 0 }), h2: () => ({ conversion: u, priority: 0 }), h3: () => ({ conversion: u, priority: 0 }), h4: () => ({ conversion: u, priority: 0 }), h5: () => ({
        conversion: u,
        priority: 0
      }), h6: () => ({ conversion: u, priority: 0 }), p: (e) => (e = e.firstChild, e !== null && T(e) ? { conversion: () => ({ node: null }), priority: 3 } : null), span: (e) => T(e) ? { conversion: () => ({ node: d("h1") }), priority: 3 } : null };
    }
    exportDOM(e) {
      if ({ element: e } = super.exportDOM(e), e && a.isHTMLElement(e)) {
        this.isEmpty() && e.append(document.createElement("br"));
        var r = this.getFormatType();
        e.style.textAlign = r, (r = this.getDirection()) && (e.dir = r);
      }
      return { element: e };
    }
    static importJSON(e) {
      let r = d(e.tag);
      return r.setFormat(e.format), r.setIndent(e.indent), r.setDirection(e.direction), r;
    }
    exportJSON() {
      return { ...super.exportJSON(), tag: this.getTag(), type: "heading", version: 1 };
    }
    insertNewAfter(e, r = !0) {
      let i = e ? e.anchor.offset : 0, o = i !== this.getTextContentSize() && e ? d(this.getTag()) : t.$createParagraphNode(), l = this.getDirection();
      return o.setDirection(l), this.insertAfter(o, r), i === 0 && !this.isEmpty() && e && (e = t.$createParagraphNode(), e.select(), this.replace(e, !0)), o;
    }
    collapseAtStart() {
      let e = this.isEmpty() ? t.$createParagraphNode() : d(this.getTag());
      return this.getChildren().forEach((r) => e.append(r)), this.replace(e), !0;
    }
    extractWithChild() {
      return !0;
    }
  }
  function T(n) {
    return n.nodeName.toLowerCase() === "span" ? n.style.fontSize === "26pt" : !1;
  }
  function u(n) {
    let e = n.nodeName.toLowerCase(), r = null;
    return (e === "h1" || e === "h2" || e === "h3" || e === "h4" || e === "h5" || e === "h6") && (r = d(e), n.style !== null && r.setFormat(n.style.textAlign)), { node: r };
  }
  function v(n) {
    let e = D();
    return n.style !== null && e.setFormat(n.style.textAlign), { node: e };
  }
  function d(n) {
    return t.$applyNodeReplacement(new g(n));
  }
  function y(n, e) {
    n.preventDefault(), e.update(() => {
      let r = t.$getSelection(), i = n instanceof InputEvent || n instanceof KeyboardEvent ? null : n.clipboardData;
      i != null && t.$INTERNAL_isPointSelection(r) && m.$insertDataTransferForRichText(i, r, e);
    }, { tag: "paste" });
  }
  async function x(n, e) {
    await m.copyToClipboard(e, a.objectKlassEquals(n, ClipboardEvent) ? n : null), e.update(() => {
      let r = t.$getSelection();
      t.$isRangeSelection(r) ? r.removeText() : t.$isNodeSelection(r) && r.getNodes().forEach((i) => i.remove());
    });
  }
  function R(n) {
    let e = null;
    if (n instanceof DragEvent ? e = n.dataTransfer : n instanceof ClipboardEvent && (e = n.clipboardData), e === null) return [!1, [], !1];
    var r = e.types;
    return n = r.includes("Files"), r = r.includes("text/html") || r.includes("text/plain"), [n, Array.from(e.files), r];
  }
  function C(n) {
    var e = t.$getSelection();
    if (!t.$isRangeSelection(e)) return !1;
    let r = /* @__PURE__ */ new Set();
    e = e.getNodes();
    for (let l = 0; l < e.length; l++) {
      var i = e[l], o = i.getKey();
      r.has(o) || (i = a.$getNearestBlockElementAncestorOrThrow(i), o = i.getKey(), i.canIndent() && !r.has(o) && (r.add(o), n(i)));
    }
    return 0 < r.size;
  }
  function O(n) {
    return n = t.$getNearestNodeFromDOMNode(n), t.$isDecoratorNode(n);
  }
  return s.$createHeadingNode = d, s.$createQuoteNode = D, s.$isHeadingNode = function(n) {
    return n instanceof g;
  }, s.$isQuoteNode = function(n) {
    return n instanceof f;
  }, s.DRAG_DROP_PASTE = _, s.HeadingNode = g, s.QuoteNode = f, s.eventFiles = R, s.registerRichText = function(n) {
    return a.mergeRegister(
      n.registerCommand(t.CLICK_COMMAND, () => {
        const e = t.$getSelection();
        return t.$isNodeSelection(e) ? (e.clear(), !0) : !1;
      }, 0),
      n.registerCommand(t.DELETE_CHARACTER_COMMAND, (e) => {
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (r.deleteCharacter(e), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.DELETE_WORD_COMMAND, (e) => {
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (r.deleteWord(e), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.DELETE_LINE_COMMAND, (e) => {
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (r.deleteLine(e), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND, (e) => {
        const r = t.$getSelection();
        if (typeof e == "string") t.$INTERNAL_isPointSelection(r) && r.insertText(e);
        else {
          if (!t.$INTERNAL_isPointSelection(r)) return !1;
          const i = e.dataTransfer;
          i != null ? m.$insertDataTransferForRichText(i, r, n) : t.$isRangeSelection(r) && (e = e.data) && r.insertText(e);
        }
        return !0;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.REMOVE_TEXT_COMMAND, () => {
        const e = t.$getSelection();
        return t.$isRangeSelection(e) ? (e.removeText(), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.FORMAT_TEXT_COMMAND, (e) => {
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (r.formatText(e), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.FORMAT_ELEMENT_COMMAND, (e) => {
        var r = t.$getSelection();
        if (!t.$isRangeSelection(r) && !t.$isNodeSelection(r)) return !1;
        r = r.getNodes();
        for (const i of r) r = a.$findMatchingParent(
          i,
          (o) => t.$isElementNode(o) && !o.isInline()
        ), r !== null && r.setFormat(e);
        return !0;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.INSERT_LINE_BREAK_COMMAND, (e) => {
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (r.insertLineBreak(e), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.INSERT_PARAGRAPH_COMMAND, () => {
        const e = t.$getSelection();
        return t.$isRangeSelection(e) ? (e.insertParagraph(), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.INSERT_TAB_COMMAND, () => (t.$insertNodes([t.$createTabNode()]), !0), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.INDENT_CONTENT_COMMAND, () => C((e) => {
        const r = e.getIndent();
        e.setIndent(r + 1);
      }), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.OUTDENT_CONTENT_COMMAND, () => C((e) => {
        const r = e.getIndent();
        0 < r && e.setIndent(r - 1);
      }), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.KEY_ARROW_UP_COMMAND, (e) => {
        var r = t.$getSelection();
        if (t.$isNodeSelection(r) && !O(e.target)) {
          if (e = r.getNodes(), 0 < e.length) return e[0].selectPrevious(), !0;
        } else if (t.$isRangeSelection(r) && (r = t.$getAdjacentNode(
          r.focus,
          !0
        ), !e.shiftKey && t.$isDecoratorNode(r) && !r.isIsolated() && !r.isInline())) return r.selectPrevious(), e.preventDefault(), !0;
        return !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.KEY_ARROW_DOWN_COMMAND, (e) => {
        var r = t.$getSelection();
        if (t.$isNodeSelection(r)) {
          if (e = r.getNodes(), 0 < e.length) return e[0].selectNext(0, 0), !0;
        } else if (t.$isRangeSelection(r)) {
          let i = r.focus;
          if (i.key === "root" && i.offset === t.$getRoot().getChildrenSize()) return e.preventDefault(), !0;
          if (r = t.$getAdjacentNode(r.focus, !1), !e.shiftKey && t.$isDecoratorNode(r) && !r.isIsolated() && !r.isInline()) return r.selectNext(), e.preventDefault(), !0;
        }
        return !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.KEY_ARROW_LEFT_COMMAND, (e) => {
        const r = t.$getSelection();
        if (t.$isNodeSelection(r)) {
          var i = r.getNodes();
          if (0 < i.length) return e.preventDefault(), i[0].selectPrevious(), !0;
        }
        return t.$isRangeSelection(r) && N.$shouldOverrideDefaultCharacterSelection(r, !0) ? (i = e.shiftKey, e.preventDefault(), N.$moveCharacter(r, i, !0), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(
        t.KEY_ARROW_RIGHT_COMMAND,
        (e) => {
          const r = t.$getSelection();
          if (t.$isNodeSelection(r) && !O(e.target)) {
            var i = r.getNodes();
            if (0 < i.length) return e.preventDefault(), i[0].selectNext(0, 0), !0;
          }
          return t.$isRangeSelection(r) ? (i = e.shiftKey, N.$shouldOverrideDefaultCharacterSelection(r, !1) ? (e.preventDefault(), N.$moveCharacter(r, i, !1), !0) : !1) : !1;
        },
        t.COMMAND_PRIORITY_EDITOR
      ),
      n.registerCommand(t.KEY_BACKSPACE_COMMAND, (e) => {
        if (O(e.target)) return !1;
        const r = t.$getSelection();
        if (!t.$isRangeSelection(r)) return !1;
        e.preventDefault(), { anchor: e } = r;
        const i = e.getNode();
        return r.isCollapsed() && e.offset === 0 && !t.$isRootNode(i) && 0 < a.$getNearestBlockElementAncestorOrThrow(i).getIndent() ? n.dispatchCommand(t.OUTDENT_CONTENT_COMMAND, void 0) : n.dispatchCommand(t.DELETE_CHARACTER_COMMAND, !0);
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.KEY_DELETE_COMMAND, (e) => {
        if (O(e.target)) return !1;
        const r = t.$getSelection();
        return t.$isRangeSelection(r) ? (e.preventDefault(), n.dispatchCommand(t.DELETE_CHARACTER_COMMAND, !1)) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(
        t.KEY_ENTER_COMMAND,
        (e) => {
          const r = t.$getSelection();
          if (!t.$isRangeSelection(r)) return !1;
          if (e !== null) {
            if (($ || h || P) && I) return !1;
            if (e.preventDefault(), e.shiftKey) return n.dispatchCommand(t.INSERT_LINE_BREAK_COMMAND, !1);
          }
          return n.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND, void 0);
        },
        t.COMMAND_PRIORITY_EDITOR
      ),
      n.registerCommand(t.KEY_ESCAPE_COMMAND, () => {
        const e = t.$getSelection();
        return t.$isRangeSelection(e) ? (n.blur(), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.DROP_COMMAND, (e) => {
        const [, r] = R(e);
        if (0 < r.length) {
          var i = M(e.clientX, e.clientY);
          if (i !== null) {
            const { offset: l, node: Y } = i;
            var o = t.$getNearestNodeFromDOMNode(Y);
            if (o !== null) {
              if (i = t.$createRangeSelection(), t.$isTextNode(o)) i.anchor.set(o.getKey(), l, "text"), i.focus.set(o.getKey(), l, "text");
              else {
                const E = o.getParentOrThrow().getKey();
                o = o.getIndexWithinParent() + 1, i.anchor.set(E, o, "element"), i.focus.set(E, o, "element");
              }
              i = t.$normalizeSelection__EXPERIMENTAL(i), t.$setSelection(i);
            }
            n.dispatchCommand(_, r);
          }
          return e.preventDefault(), !0;
        }
        return e = t.$getSelection(), !!t.$isRangeSelection(e);
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.DRAGSTART_COMMAND, (e) => {
        [e] = R(e);
        const r = t.$getSelection();
        return !(e && !t.$isRangeSelection(r));
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.DRAGOVER_COMMAND, (e) => {
        var [r] = R(e);
        const i = t.$getSelection();
        return r && !t.$isRangeSelection(i) ? !1 : (r = M(e.clientX, e.clientY), r !== null && (r = t.$getNearestNodeFromDOMNode(r.node), t.$isDecoratorNode(r) && e.preventDefault()), !0);
      }, t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.SELECT_ALL_COMMAND, () => (t.$selectAll(), !0), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.COPY_COMMAND, (e) => (m.copyToClipboard(n, a.objectKlassEquals(e, ClipboardEvent) ? e : null), !0), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.CUT_COMMAND, (e) => (x(e, n), !0), t.COMMAND_PRIORITY_EDITOR),
      n.registerCommand(t.PASTE_COMMAND, (e) => {
        const [, r, i] = R(e);
        if (0 < r.length && !i) return n.dispatchCommand(_, r), !0;
        if (t.isSelectionCapturedInDecoratorInput(e.target)) return !1;
        const o = t.$getSelection();
        return t.$INTERNAL_isPointSelection(o) ? (y(e, n), !0) : !1;
      }, t.COMMAND_PRIORITY_EDITOR)
    );
  }, s;
}
export {
  B as __require
};
