const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", h = (t) => t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null, v = (t) => {
  const e = t == null ? void 0 : t.contentElement;
  if (e instanceof HTMLElement) return e;
  const n = t == null ? void 0 : t.editorElement;
  if (n instanceof HTMLElement) {
    const a = n.querySelector(f);
    if (a instanceof HTMLElement) return a;
    if (n.getAttribute("contenteditable") === "true") return n;
  }
  const r = window.__editoraCommandEditorRoot;
  if (r instanceof HTMLElement) {
    const a = r.querySelector(f);
    if (a instanceof HTMLElement) return a;
    if (r.getAttribute("contenteditable") === "true") return r;
  }
  const c = window.getSelection();
  if (c && c.rangeCount > 0) {
    const a = h(c.getRangeAt(0).startContainer), s = a == null ? void 0 : a.closest(f);
    if (s instanceof HTMLElement) return s;
    const o = a == null ? void 0 : a.closest(w), i = o == null ? void 0 : o.querySelector(f);
    if (i instanceof HTMLElement) return i;
  }
  const l = document.activeElement, u = l instanceof HTMLElement ? l.closest(f) : null;
  return u instanceof HTMLElement ? u : document.querySelector(f);
}, S = (t) => {
  const e = window.getSelection();
  if (!e || e.rangeCount === 0 || e.isCollapsed) return null;
  const n = e.getRangeAt(0);
  return !t.contains(n.startContainer) || !t.contains(n.endContainer) ? null : n;
}, R = (t, e) => {
  if (!e.data) return !1;
  if (typeof t.intersectsNode == "function")
    try {
      return t.intersectsNode(e);
    } catch (r) {
      return !1;
    }
  const n = document.createRange();
  return n.selectNodeContents(e), t.compareBoundaryPoints(Range.END_TO_START, n) < 0 && t.compareBoundaryPoints(Range.START_TO_END, n) > 0;
}, L = (t, e) => {
  const n = [], r = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
  let c = r.nextNode();
  for (; c; ) {
    const l = c;
    if (R(e, l)) {
      const u = l === e.startContainer ? e.startOffset : 0, a = l === e.endContainer ? e.endOffset : l.data.length;
      u < a && n.push({
        node: l,
        start: u,
        end: a,
        text: l.data.slice(u, a)
      });
    }
    c = r.nextNode();
  }
  return n;
}, y = (t) => /\p{L}/u.test(t), _ = (t) => /[\p{M}'’-]/u.test(t), M = () => {
  let t = !1;
  return (e) => {
    let n = "";
    return Array.from(e.text).forEach((r) => {
      if (y(r)) {
        n += t ? r.toLocaleLowerCase() : r.toLocaleUpperCase(), t = !0;
        return;
      }
      n += r, _(r) || (t = !1);
    }), n;
  };
}, H = (t) => {
  if (t.length === 0) return;
  const e = t[0], n = t[t.length - 1], r = window.getSelection();
  if (!r) return;
  const c = document.createRange();
  c.setStart(e.node, e.start), c.setEnd(n.node, n.end), r.removeAllRanges(), r.addRange(c);
}, N = (t, e, n) => {
  if (e !== n) {
    if (typeof window.execEditorCommand == "function") {
      window.execEditorCommand("recordDomTransaction", t, e, n);
      return;
    }
    if (typeof window.executeEditorCommand == "function")
      try {
        window.executeEditorCommand("recordDomTransaction", { editor: t, beforeHTML: e, afterHTML: n });
      } catch (r) {
      }
  }
}, b = () => {
  const t = (s, o) => {
    try {
      const i = v(o);
      if (!i) return !1;
      const m = S(i);
      if (!m) return !1;
      const p = L(i, m);
      if (p.length === 0) return !1;
      const C = i.innerHTML;
      p.forEach((d, T) => {
        const E = s(d, T);
        d.node.replaceData(d.start, d.end - d.start, E), d.end = d.start + E.length;
      });
      const g = i.innerHTML;
      return C === g ? !1 : (N(i, C, g), i.dispatchEvent(new window.Event("input", { bubbles: !0 })), H(p), !0);
    } catch (i) {
      return console.error("Failed to transform capitalization:", i), !1;
    }
  }, e = (s, o) => t((i) => i.text.toLocaleUpperCase(), o), n = (s, o) => t((i) => i.text.toLocaleLowerCase(), o), r = (s, o) => t(M(), o), c = (s, o) => {
    if (!s) return !1;
    switch (s) {
      case "uppercase":
        return e(void 0, o);
      case "lowercase":
        return n(void 0, o);
      case "titlecase":
        return r(void 0, o);
      default:
        return !1;
    }
  }, l = (s, o) => typeof s == "string" ? { value: s, context: o } : typeof o == "string" ? { value: o } : {
    value: void 0,
    context: o
  }, u = (s, o) => {
    if (o && typeof o == "object" && !o.doc)
      return o;
  }, a = (s) => (o, i) => s(void 0, u(o, i));
  return {
    name: "capitalization",
    toolbar: [
      {
        label: "Capitalization",
        command: "setCapitalization",
        type: "inline-menu",
        options: [
          { label: "lowercase", value: "lowercase" },
          { label: "UPPERCASE", value: "uppercase" },
          { label: "Title Case", value: "titlecase" }
        ],
        icon: '<svg fill="#000000" width="24" height="24" viewBox="0 0 32.00 32.00" id="icon" 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" stroke="#CCCCCC" stroke-width="0.192"></g><g id="SVGRepo_iconCarrier"><defs><style>.cls-1{fill:none;}</style></defs><title>letter--Aa</title><path d="M23,13H18v2h5v2H19a2,2,0,0,0-2,2v2a2,2,0,0,0,2,2h6V15A2,2,0,0,0,23,13Zm0,8H19V19h4Z"></path><path d="M13,9H9a2,2,0,0,0-2,2V23H9V18h4v5h2V11A2,2,0,0,0,13,9ZM9,16V11h4v5Z"></path><rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32" height="32"></rect></g></svg>'
      }
    ],
    commands: {
      setCapitalization: (s, o) => {
        const { value: i, context: m } = l(s, o);
        return c(i, m);
      },
      toUpperCase: a(e),
      toLowerCase: a(n),
      toTitleCase: a(r)
    },
    keymap: {
      "Mod-Shift-u": "toUpperCase",
      "Mod-Shift-k": "toLowerCase",
      "Mod-Shift-t": "toTitleCase"
    }
  };
};
export {
  b as CapitalizationPlugin
};
//# sourceMappingURL=CapitalizationPlugin.native-DLV4oPmB.mjs.map
