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