const E = () => ({
  name: "fontFamily",
  marks: {
    fontFamily: {
      attrs: {
        family: { default: null }
      },
      parseDOM: [
        {
          tag: 'span[style*="font-family"]',
          getAttrs: (e) => {
            const n = e.style.fontFamily;
            return n ? { family: n } : !1;
          }
        },
        {
          tag: "font[face]",
          getAttrs: (e) => {
            const n = e.getAttribute("face");
            return n ? { family: n } : !1;
          }
        }
      ],
      toDOM: (e) => {
        var t;
        return ["span", { style: `font-family: ${(t = e.attrs) == null ? void 0 : t.family}` }, 0];
      }
    }
  },
  toolbar: [
    {
      label: "Font Family",
      command: "setFontFamily",
      type: "inline-menu",
      options: [
        { label: "Arial", value: "Arial, sans-serif" },
        { label: "Times New Roman", value: "Times New Roman, serif" },
        { label: "Courier New", value: "Courier New, monospace" },
        { label: "Georgia", value: "Georgia, serif" },
        { label: "Verdana", value: "Verdana, sans-serif" },
        { label: "Helvetica", value: "Helvetica, Arial, sans-serif" },
        { label: "Trebuchet MS", value: "Trebuchet MS, sans-serif" },
        { label: "Impact", value: "Impact, sans-serif" }
      ],
      icon: '<svg fill="#000000" width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M15 4h7v2h-7zm1 4h6v2h-6zm2 4h4v2h-4zM9.307 4l-6 16h2.137l1.875-5h6.363l1.875 5h2.137l-6-16H9.307zm-1.239 9L10.5 6.515 12.932 13H8.068z"></path></g></svg>'
    }
  ],
  commands: {
    setFontFamily: (e) => {
      if (!e) return !1;
      try {
        return C(e), !0;
      } catch (t) {
        return console.error("Failed to set font family:", t), !1;
      }
    }
  },
  keymap: {
    "Mod-Shift-f": "setFontFamily"
  }
}), y = "p,div,li,ul,ol,table,thead,tbody,tfoot,tr,td,th,h1,h2,h3,h4,h5,h6,blockquote,pre";
function p(e) {
  return !!e.cloneContents().querySelector(y);
}
function h(e) {
  const t = e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement;
  return (t == null ? void 0 : t.closest('[contenteditable="true"]')) || document.querySelector('[contenteditable="true"]');
}
function f(e) {
  e && e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function g(e, t) {
  var a;
  const n = document.createElement("span");
  for (const l of Array.from(e.attributes))
    l.name === "face" || l.name === "style" || n.setAttribute(l.name, l.value);
  const r = e.getAttribute("style");
  for (r && n.setAttribute("style", r), n.style.fontFamily = t, n.classList.add("rte-font-family"); e.firstChild; )
    n.appendChild(e.firstChild);
  (a = e.parentNode) == null || a.replaceChild(n, e);
}
function S(e) {
  e.querySelectorAll("span").forEach((n) => {
    n.childElementCount > 0 || (n.textContent || "").trim().length > 0 || n.remove();
  });
}
function A(e, t, n) {
  if (p(e))
    return !1;
  const r = document.createElement("span");
  r.style.fontFamily = n, r.className = "rte-font-family";
  try {
    e.surroundContents(r);
  } catch (l) {
    const s = e.extractContents();
    r.appendChild(s), e.insertNode(r);
  }
  const a = document.createRange();
  return a.selectNodeContents(r), t.removeAllRanges(), t.addRange(a), !0;
}
function C(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return;
  const n = t.getRangeAt(0), r = n.cloneRange(), a = h(n.commonAncestorContainer);
  if (n.collapsed)
    return;
  const l = n.commonAncestorContainer, s = b(l);
  if (s && F(n, s)) {
    s.style.fontFamily = e, s.classList.add("rte-font-family");
    const o = document.createRange();
    o.selectNodeContents(s), t.removeAllRanges(), t.addRange(o), f(a);
    return;
  }
  if (!a) return;
  const m = new Set(
    Array.from(a.querySelectorAll("font[face]"))
  ), u = new Set(
    Array.from(
      a.querySelectorAll("span[style*='font-family']")
    )
  );
  a.focus({ preventScroll: !0 });
  try {
    document.execCommand("styleWithCSS", !1, "true");
  } catch (o) {
  }
  const d = e.split(",").map((o) => o.trim().replace(/^['"]|['"]$/g, "")).filter(Boolean)[0] || "Arial";
  let i = document.execCommand("fontName", !1, d), c = !1;
  Array.from(
    a.querySelectorAll("font[face]")
  ).forEach((o) => {
    m.has(o) || (g(o, e), c = !0);
  }), Array.from(
    a.querySelectorAll("span[style*='font-family']")
  ).forEach((o) => {
    u.has(o) || (o.style.fontFamily = e, o.classList.add("rte-font-family"), c = !0);
  }), i || (i = A(r, t, e)), (i || c) && (S(a), f(a));
}
function b(e) {
  let t = e;
  for (; t; ) {
    if (t.nodeType === Node.ELEMENT_NODE) {
      const n = t;
      if (n.tagName === "SPAN" && n.style.fontFamily)
        return n;
    }
    t = t.parentNode;
  }
  return null;
}
function F(e, t) {
  const n = e.startContainer, r = e.endContainer, a = t.contains(n) || n.nodeType === Node.TEXT_NODE && n.parentElement === t, l = t.contains(r) || r.nodeType === Node.TEXT_NODE && r.parentElement === t;
  return a && l;
}
export {
  E as FontFamilyPlugin
};
//# sourceMappingURL=FontFamilyPlugin.native-j8hMTbg4.mjs.map
