import { getSelectedOptions as L, BREAK_TAG as l } from "../utils.es.js";
import { applyFormattingToBlockNode as T } from "./applyFormattingToBlockNode.es.js";
import { applyFormattingToLeafNode as N } from "./applyFormattingToLeafNode.es.js";
import { isLeafNode as o } from "./isLeafNode.es.js";
const c = ["thematicBreak", "image", "mention"], A = (e, t) => o(e) ? !1 : t.includes(e.type || ""), E = (e, t) => !o(e) && Array.isArray(e.children) ? e.children.some(
  (i) => !o(i) && (i.type === t.link || i.type === t.image)
) : !1, D = (e, t) => e === t.mention, P = (e, t, i, a) => !e && t === `
` && i.parentType === a.paragraph && !D(i.type, a), w = (e, t, i) => e.includes(t.type || "") ? i + 1 : i, d = (e, t) => {
  const i = t.nodeTypes, a = e.text ?? "";
  let s = e.type ?? void 0;
  const y = e.parentType ?? void 0, p = [i.ulList, i.olList];
  let r = a;
  return o(e) || (r = e.children.map((n) => {
    const f = A(n, p), m = p.includes(e.type ?? ""), g = E(e, i);
    return d(
      { ...n, parentType: s },
      {
        nodeTypes: i,
        // WOAH.
        // what we're doing here is pretty tricky, it relates to the block below where
        // we check for ignoreParagraphNewline and set type to paragraph.
        // We want to strip out empty paragraphs sometimes, but other times we don't.
        // If we're the descendant of a list, we know we don't want a bunch
        // of whitespace. If we're parallel to a link we also don't want
        // to respect neighboring paragraphs
        ignoreParagraphNewline: (t.ignoreParagraphNewline || f || m || g) && // if we have c.break, never ignore empty paragraph new line
        !n.break,
        // track depth of nested lists so we can add proper spacing
        listDepth: w(p, n, t.listDepth),
        linkDestinationKey: t.linkDestinationKey
      }
    );
  }).join("")), P(t.ignoreParagraphNewline, a, e, i) && (s = i.paragraph, r = l), r === "" && i.paragraph === s && (r = "&nbsp;"), r === "" && !c.find((n) => i[n] === s) ? "" : r !== l && o(e) ? N(r, e) : T(t, r, e, t.listDepth, s, y);
};
function B(e) {
  const t = L(e);
  return (i) => i.map((a) => d(a, t)).join("");
}
export {
  B as default
};
//# sourceMappingURL=serialize.es.js.map
