const a = ["P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "LI", "BLOCKQUOTE", "PRE", "TD", "TH"];
function f(n) {
  let t = n;
  if (t.nodeType === Node.ELEMENT_NODE) {
    const e = t;
    if (a.includes(e.tagName))
      return e;
  }
  for (; t; ) {
    if (t.nodeType === Node.ELEMENT_NODE) {
      const e = t;
      if (a.includes(e.tagName))
        return e;
      if (e.hasAttribute("contenteditable"))
        return null;
    }
    t = t.parentNode;
  }
  return null;
}
function h(n) {
  const t = [], e = f(n.startContainer), i = f(n.endContainer);
  if (!e && !i) return t;
  if (n.collapsed)
    return e && t.push(e), t;
  if (e === i)
    e && t.push(e);
  else {
    let o = e;
    const s = /* @__PURE__ */ new Set();
    for (e && (t.push(e), s.add(e)); o && o !== i && !s.has(i); ) {
      let r = o.nextElementSibling;
      for (; r; ) {
        if (a.includes(r.tagName)) {
          o = r, s.has(o) || (t.push(o), s.add(o));
          break;
        }
        r = r.nextElementSibling;
      }
      if (!r) break;
    }
    i && !t.includes(i) && t.push(i);
  }
  return t;
}
function E(n) {
  const t = n.commonAncestorContainer.nodeType === Node.ELEMENT_NODE ? n.commonAncestorContainer : n.commonAncestorContainer.parentElement;
  return t ? t.closest(".rte-content, .editora-content") || t.closest('[contenteditable="true"]') : null;
}
function m(n, t) {
  if (!n || t === n.innerHTML) return;
  const e = window.execEditorCommand || window.executeEditorCommand;
  if (typeof e == "function")
    try {
      e("recordDomTransaction", n, t, n.innerHTML);
    } catch (i) {
    }
}
const p = (n) => {
  var u;
  if (!n || !["left", "center", "right", "justify"].includes(n)) return !1;
  const e = window.getSelection();
  if (!e || e.rangeCount === 0) return !1;
  const i = e.getRangeAt(0).cloneRange(), o = E(i), s = (o == null ? void 0 : o.innerHTML) || "", r = h(i);
  if (r.length > 0)
    r.forEach((l) => {
      l && (l.style.textAlign = n);
    }), e.removeAllRanges(), e.addRange(i), m(o, s), o && o.dispatchEvent(new Event("input", { bubbles: !0 }));
  else
    try {
      const l = document.createElement("div");
      l.style.textAlign = n;
      const g = i.extractContents();
      l.appendChild(g), i.insertNode(l);
      const d = document.createRange();
      d.selectNodeContents(l), e.removeAllRanges(), e.addRange(d);
      const c = l.closest(".rte-content, .editora-content") || l.closest('[contenteditable="true"]');
      m(c || o, s), (c || o) && ((u = c || o) == null || u.dispatchEvent(new Event("input", { bubbles: !0 })));
    } catch (l) {
      return console.error("Failed to wrap content for alignment:", l), !1;
    }
  return !0;
}, b = () => ({
  name: "textAlignment",
  toolbar: [
    {
      label: "Text Alignment",
      command: "setTextAlignment",
      type: "inline-menu",
      options: [
        { label: "Left", value: "left" },
        { label: "Center", value: "center" },
        { label: "Right", value: "right" },
        { label: "Justify", value: "justify" }
      ],
      icon: '<svg width="24" height="24" focusable="false"><path d="M5 5h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2Zm0 4h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 1 1 0-2Zm0 8h8c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2Zm0-4h14c.6 0 1 .4 1 1s-.4 1-1 1H5a1 1 0 0 1 0-2Z" fill-rule="evenodd"></path></svg>'
    }
  ],
  commands: {
    setTextAlignment: p
  },
  keymap: {}
});
export {
  b as TextAlignmentPlugin,
  p as setTextAlignmentCommand
};
//# sourceMappingURL=TextAlignmentPlugin.native-sM_1s00t.mjs.map
