import { __exports as d } from "./index-LexicalClipboard.prod2.js";
import { __require as D } from "./index-LexicalHtml2.js";
import { __require as E } from "./index-LexicalSelection.js";
import { __require as R } from "./index-LexicalUtils.js";
import { __require as L } from "./index-Lexical.js";
var T;
function F() {
  if (T) return d;
  T = 1;
  var h = D(), m = E(), y = R(), i = L();
  function x(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.`);
  }
  let w = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
  function N(e) {
    let t = i.$getSelection();
    if (t == null) throw Error("Expected valid LexicalSelection");
    return i.$isRangeSelection(t) && t.isCollapsed() || t.getNodes().length === 0 ? "" : h.$generateHtmlFromNodes(e, t);
  }
  function _(e) {
    let t = i.$getSelection();
    if (t == null) throw Error("Expected valid LexicalSelection");
    return i.$isRangeSelection(t) && t.isCollapsed() || t.getNodes().length === 0 ? null : JSON.stringify(S(e, t));
  }
  function g(e, t, n) {
    e.dispatchCommand(i.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, { nodes: t, selection: n }) || n.insertNodes(t);
  }
  function $(e, t, n, r = []) {
    let l = t != null ? n.isSelected(t) : !0, a = i.$isElementNode(n) && n.excludeFromCopy("html");
    var o = n;
    if (t !== null) {
      var s = m.$cloneWithProperties(n);
      o = s = i.$isTextNode(s) && t != null ? m.$sliceSelectedTextNodeContent(t, s) : s;
    }
    let f = i.$isElementNode(o) ? o.getChildren() : [];
    var c = o;
    s = c.exportJSON();
    var p = c.constructor;
    for (s.type !== p.getType() && x(58, p.name), i.$isElementNode(c) && (Array.isArray(s.children) || x(59, p.name)), i.$isTextNode(o) && (o = o.__text, 0 < o.length ? s.text = o : l = !1), o = 0; o < f.length; o++) c = f[o], p = $(e, t, c, s.children), !l && i.$isElementNode(n) && p && n.extractWithChild(c, t, "clone") && (l = !0);
    if (l && !a) r.push(s);
    else if (Array.isArray(s.children)) for (e = 0; e < s.children.length; e++) r.push(s.children[e]);
    return l;
  }
  function S(e, t) {
    let n = [], r = i.$getRoot().getChildren();
    for (let l = 0; l < r.length; l++) $(e, t, r[l], n);
    return { namespace: e._config.namespace, nodes: n };
  }
  function C(e) {
    let t = [];
    for (let n = 0; n < e.length; n++) {
      let r = i.$parseSerializedNode(e[n]);
      i.$isTextNode(r) && m.$addNodeStyle(r), t.push(r);
    }
    return t;
  }
  let u = null;
  function v(e, t) {
    var n = w ? (e._window || window).getSelection() : null;
    if (!n) return !1;
    var r = n.anchorNode;
    if (n = n.focusNode, r !== null && n !== null && !i.isSelectionWithinEditor(e, r, n) || (t.preventDefault(), t = t.clipboardData, r = i.$getSelection(), t === null || r === null)) return !1;
    n = N(e), e = _(e);
    let l = "";
    return r !== null && (l = r.getTextContent()), n !== null && t.setData("text/html", n), e !== null && t.setData("application/x-lexical-editor", e), t.setData("text/plain", l), !0;
  }
  return d.$generateJSONFromSelectedNodes = S, d.$generateNodesFromSerializedNodes = C, d.$getHtmlContent = N, d.$getLexicalContent = _, d.$insertDataTransferForPlainText = function(e, t) {
    e = e.getData("text/plain") || e.getData("text/uri-list"), e != null && t.insertRawText(e);
  }, d.$insertDataTransferForRichText = function(e, t, n) {
    var r = e.getData("application/x-lexical-editor");
    if (r) try {
      let a = JSON.parse(r);
      if (a.namespace === n._config.namespace && Array.isArray(a.nodes)) {
        let o = C(a.nodes);
        return g(n, o, t);
      }
    } catch {
    }
    if (r = e.getData("text/html")) try {
      var l = new DOMParser().parseFromString(r, "text/html");
      let a = h.$generateNodesFromDOM(n, l);
      return g(n, a, t);
    } catch {
    }
    if (e = e.getData("text/plain") || e.getData("text/uri-list"), e != null) if (i.$isRangeSelection(t)) for (e = e.split(/(\r?\n|\t)/), e[e.length - 1] === "" && e.pop(), n = 0; n < e.length; n++) l = e[n], l === `
` || l === `\r
` ? t.insertParagraph() : l === "	" ? t.insertNodes([i.$createTabNode()]) : t.insertText(l);
    else t.insertRawText(e);
  }, d.$insertGeneratedNodes = g, d.copyToClipboard = async function(e, t) {
    if (u !== null) return !1;
    if (t !== null) return new Promise((o) => {
      e.update(() => {
        o(v(e, t));
      });
    });
    var n = e.getRootElement();
    let r = e._window == null ? window.document : e._window.document, l = w ? (e._window || window).getSelection() : null;
    if (n === null || l === null) return !1;
    let a = r.createElement("span");
    return a.style.cssText = "position: fixed; top: -1000px;", a.append(r.createTextNode("#")), n.append(a), n = new Range(), n.setStart(a, 0), n.setEnd(a, 1), l.removeAllRanges(), l.addRange(n), new Promise((o) => {
      let s = e.registerCommand(i.COPY_COMMAND, (f) => (y.objectKlassEquals(f, ClipboardEvent) && (s(), u !== null && (window.clearTimeout(u), u = null), o(v(e, f))), !0), i.COMMAND_PRIORITY_CRITICAL);
      u = window.setTimeout(() => {
        s(), u = null, o(!1);
      }, 50), r.execCommand("copy"), a.remove();
    });
  }, d;
}
export {
  F as __require
};
