import { __exports as m } from "./index-LexicalHtml.prod2.js";
import { __require as $ } from "./index-LexicalSelection.js";
import { __require as q } from "./index-LexicalUtils.js";
import { __require as C } from "./index-Lexical.js";
var _;
function T() {
  if (_) return m;
  _ = 1;
  var p = $(), v = q(), a = C();
  function h(t, n, u, e = null) {
    let o = e != null ? n.isSelected(e) : !0, d = a.$isElementNode(n) && n.excludeFromCopy("html");
    var l = n;
    e !== null && (l = p.$cloneWithProperties(n), l = a.$isTextNode(l) && e != null ? p.$sliceSelectedTextNodeContent(e, l) : l);
    let i = a.$isElementNode(l) ? l.getChildren() : [];
    var r = t._nodes.get(l.getType());
    r = r && r.exportDOM !== void 0 ? r.exportDOM(t, l) : l.exportDOM(t);
    let { element: s, after: x } = r;
    if (!s) return !1;
    r = document.createDocumentFragment();
    for (let f = 0; f < i.length; f++) {
      let N = i[f], y = h(t, N, r, e);
      !o && a.$isElementNode(n) && y && n.extractWithChild(N, e, "html") && (o = !0);
    }
    return o && !d ? (v.isHTMLElement(s) && s.append(r), u.append(s), x && (t = x.call(l, s)) && s.replaceWith(t)) : u.append(r), o;
  }
  let c = /* @__PURE__ */ new Set(["STYLE", "SCRIPT"]);
  function g(t, n, u = /* @__PURE__ */ new Map(), e) {
    let o = [];
    if (c.has(t.nodeName)) return o;
    let d = null;
    var l, { nodeName: i } = t, r = n._htmlConversions.get(i.toLowerCase());
    if (i = null, r !== void 0) for (l of r) r = l(t), r !== null && (i === null || (i.priority || 0) < (r.priority || 0)) && (i = r);
    if (i = (l = i !== null ? i.conversion : null) ? l(t) : null, l = null, i !== null) {
      if (l = i.after, r = i.node, d = Array.isArray(r) ? r[r.length - 1] : r, d !== null) {
        for (var [, s] of u) if (d = s(d, e), !d) break;
        d && o.push(...Array.isArray(r) ? r : [d]);
      }
      i.forChild != null && u.set(t.nodeName, i.forChild);
    }
    for (t = t.childNodes, e = [], s = 0; s < t.length; s++) e.push(...g(t[s], n, new Map(u), d));
    return l != null && (e = l(e)), d == null ? o = o.concat(e) : a.$isElementNode(d) && d.append(...e), o;
  }
  return m.$generateHtmlFromNodes = function(t, n) {
    if (typeof document > "u" || typeof window > "u") throw Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");
    let u = document.createElement("div"), e = a.$getRoot().getChildren();
    for (let o = 0; o < e.length; o++) h(t, e[o], u, n);
    return u.innerHTML;
  }, m.$generateNodesFromDOM = function(t, n) {
    n = n.body ? n.body.childNodes : [];
    let u = [];
    for (let o = 0; o < n.length; o++) {
      var e = n[o];
      c.has(e.nodeName) || (e = g(e, t), e !== null && (u = u.concat(e)));
    }
    return u;
  }, m;
}
export {
  T as __require
};
