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