const m = '.rte-content, .editora-content, [contenteditable="true"]', B = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", k = [
  "p",
  "div",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "ul",
  "ol",
  "blockquote",
  "pre",
  "table"
].join(",");
function E(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function b(e) {
  const t = e == null ? void 0 : e.contentElement;
  if (t instanceof HTMLElement) return t;
  const n = e == null ? void 0 : e.editorElement;
  if (n instanceof HTMLElement) {
    const r = n.querySelector(m);
    if (r instanceof HTMLElement) return r;
    if (n.getAttribute("contenteditable") === "true") return n;
  }
  const o = window.getSelection();
  if (o && o.rangeCount > 0) {
    const r = E(o.getRangeAt(0).startContainer), i = r == null ? void 0 : r.closest(m);
    if (i instanceof HTMLElement) return i;
    const f = r == null ? void 0 : r.closest(B), d = f == null ? void 0 : f.querySelector(m);
    if (d instanceof HTMLElement) return d;
  }
  const c = document.activeElement, l = c == null ? void 0 : c.closest(m);
  return l instanceof HTMLElement ? l : document.querySelector(m);
}
function M(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const n = t.getRangeAt(0);
  return !e.contains(n.startContainer) || !e.contains(n.endContainer) ? null : n;
}
function N(e, t) {
  let n = E(t);
  if (!n || n === e || !e.contains(n)) return null;
  for (; n.parentElement && n.parentElement !== e; )
    n = n.parentElement;
  if (n.parentElement !== e) return null;
  if (n.matches(k)) return n;
  const o = n.closest(k);
  return o instanceof HTMLElement && o.parentElement === e ? o : n;
}
function w(e, t) {
  if (typeof e.intersectsNode == "function")
    try {
      return e.intersectsNode(t);
    } catch (o) {
      return !1;
    }
  const n = document.createRange();
  return n.selectNode(t), e.compareBoundaryPoints(Range.END_TO_START, n) < 0 && e.compareBoundaryPoints(Range.START_TO_END, n) > 0;
}
function q(e, t) {
  const n = N(e, t.startContainer), o = N(e, t.endContainer);
  if (!n) return [];
  if (!o || n === o) return [n];
  const l = Array.from(e.children).filter(
    (r) => r instanceof HTMLElement
  ).filter((r) => w(t, r));
  return l.length > 0 ? l : [n];
}
function S(e, t) {
  const n = E(t), o = n == null ? void 0 : n.closest("blockquote");
  return o instanceof HTMLQuoteElement && e.contains(o) ? o : null;
}
function v(e) {
  return e.tagName !== "P" || e.attributes.length > 0 || (e.textContent || "").trim() !== "" ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, ul, ol");
}
function O(e) {
  Array.from(e.children).forEach((t) => {
    v(t) && t.remove();
  });
}
function h(e) {
  O(e);
  const t = e.parentNode;
  if (!t) return;
  Array.from(e.childNodes).forEach((o) => {
    t.insertBefore(o, e);
  }), t.removeChild(e);
}
function y(e) {
  return e.nodeType === Node.TEXT_NODE && (e.textContent || "").trim() === "";
}
function L(e) {
  const t = Array.from(e.childNodes).filter((o) => !y(o));
  if (t.length !== 1) return null;
  const n = t[0];
  return n instanceof HTMLQuoteElement ? n : null;
}
function R(e) {
  const t = document.createElement("blockquote");
  return Array.from(e.childNodes).filter((o) => !y(o)).forEach((o) => {
    t.appendChild(o);
  }), t.childNodes.length || (t.innerHTML = "<br>"), e.appendChild(t), t;
}
function A(e, t) {
  const n = Array.from(e.querySelectorAll("li")).filter(
    (c) => c instanceof HTMLLIElement && w(t, c)
  ), o = new Set(n);
  return n.filter((c) => {
    var r, i;
    let l = (r = c.parentElement) == null ? void 0 : r.closest("li");
    for (; l; ) {
      if (o.has(l)) return !1;
      l = (i = l.parentElement) == null ? void 0 : i.closest("li");
    }
    return !0;
  });
}
function g(e) {
  const t = window.getSelection();
  if (!t) return;
  const n = document.createRange(), o = e instanceof HTMLElement && e.querySelector("p,li,h1,h2,h3,h4,h5,h6") || e;
  n.selectNodeContents(o), n.collapse(!0), t.removeAllRanges(), t.addRange(n);
}
function H(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function I(e, t, n) {
  const o = window.execEditorCommand;
  if (typeof o == "function") {
    o("recordDomTransaction", e, t, n);
    return;
  }
  const c = window.executeEditorCommand;
  typeof c == "function" && c("recordDomTransaction", { editor: e, beforeHTML: t, afterHTML: n });
}
function _(e) {
  var T, C;
  const t = b(e);
  if (!t) return !1;
  const n = M(t);
  if (!n) return !1;
  const o = t.innerHTML, c = S(t, n.startContainer), l = S(t, n.endContainer), r = A(t, n), i = q(t, n), f = i.length > 0 && i.every((s) => s.tagName === "BLOCKQUOTE");
  if (c && c === l) {
    const s = c.firstChild || c;
    h(c), g(s);
  } else if (r.length > 0) {
    const s = r.map(L);
    if (s.every(Boolean)) {
      const u = ((T = s[0]) == null ? void 0 : T.firstChild) || r[0];
      s.forEach((a) => {
        a && h(a);
      }), g(u);
    } else {
      const u = r[0];
      r.forEach((a) => {
        L(a) || R(a);
      }), g(u);
    }
  } else if (f) {
    const s = i[0].firstChild || i[0];
    i.forEach(h), g(s);
  } else {
    const s = i.filter((a) => a.tagName !== "BLOCKQUOTE");
    if (s.length === 0) return !1;
    const p = document.createElement("blockquote"), u = s[0];
    (C = u.parentNode) == null || C.insertBefore(p, u), s.forEach((a) => {
      p.appendChild(a);
    }), g(p);
  }
  const d = t.innerHTML;
  return o === d ? !1 : (I(t, o, d), H(t), !0);
}
const x = () => ({
  name: "blockquote",
  // Schema definition for blockquote node
  nodes: {
    blockquote: {
      content: "block+",
      group: "block",
      parseDOM: [{ tag: "blockquote" }],
      toDOM: () => ["blockquote", 0]
    }
  },
  // Toolbar button configuration
  toolbar: [
    {
      label: "Quote",
      command: "toggleBlockquote",
      icon: '<svg fill="#000000" height="24px" width="24px" version="1.1" id="Icons" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32" xml:space="preserve"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M13,11c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5s-2.2-5-5-5c-0.3,0-0.7,0-1,0.1 C9.3,11.8,11,11,13,11z"></path> <path d="M23,13c-0.3,0-0.7,0-1,0.1c1.3-1.3,3-2.1,5-2.1c0.6,0,1-0.4,1-1s-0.4-1-1-1c-5,0-9,4-9,9c0,2.8,2.2,5,5,5s5-2.2,5-5 S25.8,13,23,13z"></path> </g> </g></svg>',
      shortcut: "Mod-Shift-9"
    }
  ],
  // Native command implementations
  commands: {
    /**
     * Toggle blockquote formatting on current selection
     */
    toggleBlockquote: (e, t) => _(t)
  },
  // Keyboard shortcuts
  keymap: {
    "Mod-Shift-9": "toggleBlockquote"
  }
});
export {
  x as BlockquotePlugin
};
//# sourceMappingURL=BlockquotePlugin.native-57_Xcjl1.mjs.map
