const C = () => ({
  name: "clearFormatting",
  // Toolbar button configuration
  toolbar: [
    {
      label: "Clear Formatting",
      command: "clearFormatting",
      icon: '<svg width="24" height="24" focusable="false"><path d="M13.2 6a1 1 0 0 1 0 .2l-2.6 10a1 1 0 0 1-1 .8h-.2a.8.8 0 0 1-.8-1l2.6-10H8a1 1 0 1 1 0-2h9a1 1 0 0 1 0 2h-3.8ZM5 18h7a1 1 0 0 1 0 2H5a1 1 0 0 1 0-2Zm13 1.5L16.5 18 15 19.5a.7.7 0 0 1-1-1l1.5-1.5-1.5-1.5a.7.7 0 0 1 1-1l1.5 1.5 1.5-1.5a.7.7 0 0 1 1 1L17.5 17l1.5 1.5a.7.7 0 0 1-1 1Z" fill-rule="evenodd"></path></svg>',
      shortcut: "Mod-\\"
    }
  ],
  // Native command implementations
  commands: {
    /**
     * Remove all formatting from current selection
     */
    clearFormatting: () => {
      const t = h();
      if (!t) return !1;
      const e = window.getSelection();
      if (!e || e.rangeCount === 0) return !1;
      const n = e.getRangeAt(0);
      if (!t.contains(n.commonAncestorContainer)) return !1;
      const r = n.cloneRange();
      return t.focus({ preventScroll: !0 }), A(t, r), N(t, r), t.dispatchEvent(new Event("input", { bubbles: !0 })), !0;
    }
  },
  // Keyboard shortcuts
  keymap: {
    "Mod-\\": "clearFormatting"
  }
}), u = /* @__PURE__ */ new Set([
  "A",
  "B",
  "STRONG",
  "I",
  "EM",
  "U",
  "S",
  "STRIKE",
  "DEL",
  "FONT",
  "MARK",
  "CODE",
  "SUB",
  "SUP"
]), d = /* @__PURE__ */ new Set([
  "H1",
  "H2",
  "H3",
  "H4",
  "H5",
  "H6",
  "BLOCKQUOTE",
  "PRE"
]), g = [
  "color",
  "background-color",
  "font-size",
  "font-family",
  "font-weight",
  "font-style",
  "text-decoration",
  "text-transform",
  "line-height",
  "letter-spacing",
  "word-spacing",
  "vertical-align",
  "text-align",
  "padding-left"
];
function h() {
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    const n = t.getRangeAt(0).startContainer, o = (n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest('[contenteditable="true"], .rte-content, .editora-content');
    if (o) return o;
  }
  const e = document.activeElement;
  return e ? e.getAttribute("contenteditable") === "true" ? e : e.closest('[contenteditable="true"], .rte-content, .editora-content') : null;
}
function c(t, e) {
  try {
    if (typeof t.intersectsNode == "function")
      return t.intersectsNode(e);
  } catch {
  }
  const n = document.createRange();
  return e.nodeType === Node.ELEMENT_NODE ? n.selectNodeContents(e) : n.selectNode(e), t.compareBoundaryPoints(Range.END_TO_START, n) > 0 && t.compareBoundaryPoints(Range.START_TO_END, n) < 0;
}
function i(t) {
  let e = 0, n = t;
  for (; n && n.parentNode; )
    e += 1, n = n.parentNode;
  return e;
}
function m(t) {
  g.forEach((e) => {
    t.style.removeProperty(e);
  }), (!t.getAttribute("style") || t.style.length === 0) && t.removeAttribute("style"), t.classList.contains("rte-text-color") && t.classList.remove("rte-text-color"), t.classList.contains("rte-bg-color") && t.classList.remove("rte-bg-color"), t.classList.length === 0 && t.removeAttribute("class");
}
function a(t) {
  const e = t.parentNode;
  if (e) {
    for (; t.firstChild; )
      e.insertBefore(t.firstChild, t);
    e.removeChild(t);
  }
}
function p(t) {
  return t.tagName !== "P" || t.attributes.length > 0 || (t.textContent || "").trim() !== "" ? !1 : !t.querySelector("img, video, table, iframe, hr, pre, ul, ol");
}
function l(t) {
  Array.from(t.children).forEach((e) => {
    p(e) && e.remove();
  });
}
function s(t) {
  l(t), a(t);
}
function f(t) {
  const e = document.createElement("p");
  for (Array.from(t.attributes).forEach((n) => {
    e.setAttribute(n.name, n.value);
  }); t.firstChild; )
    e.appendChild(t.firstChild);
  e.innerHTML.trim() || (e.innerHTML = "<br>"), t.parentNode?.replaceChild(e, t);
}
function E(t) {
  if (l(t), t.parentElement instanceof HTMLLIElement) {
    s(t);
    return;
  }
  if (Array.from(t.childNodes).filter((o) => o.nodeType !== Node.TEXT_NODE || (o.textContent || "").trim() !== "").some((o) => o instanceof HTMLElement && /^(P|DIV|H[1-6]|UL|OL|PRE|TABLE|BLOCKQUOTE)$/.test(o.tagName))) {
    s(t);
    return;
  }
  f(t);
}
function N(t, e) {
  Array.from(
    t.querySelectorAll("h1,h2,h3,h4,h5,h6,blockquote,pre")
  ).forEach((r) => {
    if (c(e, r) && d.has(r.tagName)) {
      if (r.tagName === "BLOCKQUOTE") {
        E(r);
        return;
      }
      f(r);
    }
  });
}
function A(t, e) {
  const n = Array.from(
    t.querySelectorAll(
      "a,b,strong,i,em,u,s,strike,del,font,mark,code,sub,sup,span,[style],[class]"
    )
  );
  n.sort((r, o) => i(o) - i(r)), n.forEach((r) => {
    if (r.isConnected && c(e, r) && !(r.getAttribute("contenteditable") === "false" || r.closest('[contenteditable="false"]'))) {
      if (m(r), u.has(r.tagName)) {
        a(r);
        return;
      }
      r.tagName === "SPAN" && r.attributes.length === 0 && a(r);
    }
  });
}
export {
  C as ClearFormattingPlugin
};
