const f = () => ({
  name: "fontFamily",
  marks: {
    fontFamily: {
      attrs: {
        family: { default: null }
      },
      parseDOM: [
        {
          tag: 'span[style*="font-family"]',
          getAttrs: (n) => {
            const t = n.style.fontFamily;
            return t ? { family: t } : !1;
          }
        },
        {
          tag: "font[face]",
          getAttrs: (n) => {
            const t = n.getAttribute("face");
            return t ? { family: t } : !1;
          }
        }
      ],
      toDOM: (n) => ["span", { style: `font-family: ${n.attrs.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: (n) => {
      if (!n) return !1;
      try {
        return m(n), !0;
      } catch (e) {
        return console.error("Failed to set font family:", e), !1;
      }
    }
  },
  keymap: {
    "Mod-Shift-f": "setFontFamily"
  }
});
function m(n) {
  const e = window.getSelection();
  if (!e || e.rangeCount === 0) return;
  const t = e.getRangeAt(0);
  if (t.collapsed)
    return;
  const l = t.commonAncestorContainer, o = u(l);
  if (o && d(t, o)) {
    o.style.fontFamily = n;
    const a = document.createRange();
    a.selectNodeContents(o), e.removeAllRanges(), e.addRange(a);
    const r = o.closest('[contenteditable="true"]');
    r && r.dispatchEvent(new Event("input", { bubbles: !0 }));
  } else {
    const a = document.createElement("span");
    a.style.fontFamily = n, a.className = "rte-font-family";
    try {
      t.cloneRange().surroundContents(a), t.selectNodeContents(a), e.removeAllRanges(), e.addRange(t);
    } catch (i) {
      const c = t.extractContents();
      a.appendChild(c), t.insertNode(a);
      const s = document.createRange();
      s.selectNodeContents(a), e.removeAllRanges(), e.addRange(s);
    }
    const r = a.closest('[contenteditable="true"]');
    r && r.dispatchEvent(new Event("input", { bubbles: !0 }));
  }
}
function u(n) {
  let e = n;
  for (; e; ) {
    if (e.nodeType === Node.ELEMENT_NODE) {
      const t = e;
      if (t.tagName === "SPAN" && t.style.fontFamily)
        return t;
    }
    e = e.parentNode;
  }
  return null;
}
function d(n, e) {
  const t = n.startContainer, l = n.endContainer, o = e.contains(t) || t.nodeType === Node.TEXT_NODE && t.parentElement === e, a = e.contains(l) || l.nodeType === Node.TEXT_NODE && l.parentElement === e;
  return o && a;
}
export {
  f as FontFamilyPlugin
};
//# sourceMappingURL=FontFamilyPlugin.native-BzS_9qbM.mjs.map
