const B = /* @__PURE__ */ new Set([
  "the",
  "a",
  "an",
  "and",
  "or",
  "but",
  "in",
  "on",
  "at",
  "to",
  "for",
  "of",
  "with",
  "by",
  "from",
  "is",
  "are",
  "be",
  "was",
  "were",
  "have",
  "has",
  "had",
  "do",
  "does",
  "did",
  "will",
  "would",
  "could",
  "should",
  "may",
  "might",
  "must",
  "can",
  "this",
  "that",
  "these",
  "those",
  "what",
  "which",
  "who",
  "whom",
  "where",
  "when",
  "why",
  "how",
  "all",
  "each",
  "every",
  "both",
  "few",
  "more",
  "most",
  "other",
  "same",
  "such",
  "no",
  "nor",
  "not",
  "only",
  "own",
  "so",
  "than",
  "too",
  "very",
  "just",
  "as",
  "if",
  "because",
  "while",
  "although",
  "though",
  "it",
  "its",
  "their",
  "them",
  "they",
  "you",
  "he",
  "she",
  "we",
  "me",
  "him",
  "her",
  "us",
  "our",
  "i",
  "my",
  "your",
  "his",
  "hers",
  "ours",
  "yours",
  "theirs",
  "editor",
  "document",
  "text",
  "word",
  "paragraph",
  "line",
  "page",
  "content",
  "hello",
  "world",
  "test",
  "example",
  "sample",
  "demo",
  "lorem",
  "ipsum"
]), C = /* @__PURE__ */ new Set(), S = /* @__PURE__ */ new Set();
let u = !1, d = null, f = null, a = null, s = null, x = null, y = !1, h = null, _ = !1, b = 0, g = null;
const j = {
  characterData: !0,
  childList: !0,
  subtree: !0
}, H = "rte-spellcheck-styles", R = "__editoraCommandEditorRoot";
function K(e) {
  const t = e?.contentElement || e?.editorElement || null;
  if (!(t instanceof HTMLElement)) return;
  const r = t.getAttribute("contenteditable") === "true" ? t : t.querySelector?.('[contenteditable="true"]');
  if (r instanceof HTMLElement) {
    s = r, h = r;
    return;
  }
  const l = t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (t.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? t : null), o = A(l);
  o && (s = o, h = o);
}
function P() {
  if (typeof window > "u") return null;
  const e = window[R];
  if (!(e instanceof HTMLElement)) return null;
  window[R] = null;
  const t = e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (e.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? e : null);
  if (t) {
    const l = A(t);
    if (l) return l;
    if (t.getAttribute("contenteditable") === "true") return t;
  }
  if (e.getAttribute("contenteditable") === "true")
    return e;
  const r = e.closest('[contenteditable="true"]');
  return r instanceof HTMLElement ? r : null;
}
function T() {
  let e = document.getElementById(H);
  e || (e = document.createElement("style"), e.id = H, document.head.appendChild(e)), e.textContent = `
    .rte-spell-check-panel {
      position: absolute;
      top: 12px;
      right: 12px;
      width: min(360px, calc(100% - 24px));
      max-height: min(560px, calc(100% - 24px));
      overflow: hidden;
      display: flex;
      flex-direction: column;
      border-radius: 12px;
      border: 1px solid #d7dbe3;
      background: #ffffff;
      color: #1f2937;
      box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
      z-index: 1200;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    }

    .rte-spell-check-panel,
    .rte-spell-check-panel * {
      box-sizing: border-box;
    }

    .editora-theme-dark .rte-spell-check-panel {
      border-color: #4b5563;
      background: #1f2937;
      color: #e5e7eb;
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    }

    .rte-spellcheck-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 14px 16px 12px;
      border-bottom: 1px solid #eceff5;
    }

    .editora-theme-dark .rte-spellcheck-header {
      border-bottom-color: #374151;
    }

    .rte-spellcheck-title {
      margin: 0;
      font-size: 15px;
      font-weight: 650;
    }

    .rte-spellcheck-subtitle {
      margin: 2px 0 0;
      font-size: 12px;
      color: #64748b;
    }

    .editora-theme-dark .rte-spellcheck-subtitle {
      color: #9ca3af;
    }

    .rte-spellcheck-close {
      appearance: none;
      border: none;
      background: transparent;
      font-size: 20px;
      line-height: 1;
      color: #6b7280;
      cursor: pointer;
      border-radius: 8px;
      width: 30px;
      height: 30px;
      display: grid;
      place-items: center;
    }

    .rte-spellcheck-close:hover {
      background: rgba(15, 23, 42, 0.06);
      color: #0f172a;
    }

    .editora-theme-dark .rte-spellcheck-close {
      color: #9ca3af;
    }

    .editora-theme-dark .rte-spellcheck-close:hover {
      background: rgba(255, 255, 255, 0.08);
      color: #f3f4f6;
    }

    .rte-spellcheck-stats {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px;
      padding: 12px 16px;
      border-bottom: 1px solid #eceff5;
    }

    .editora-theme-dark .rte-spellcheck-stats {
      border-bottom-color: #374151;
    }

    .rte-spellcheck-stat {
      border-radius: 10px;
      background: #f8fafc;
      border: 1px solid #e5e7eb;
      padding: 8px 10px;
      display: grid;
      gap: 2px;
    }

    .editora-theme-dark .rte-spellcheck-stat {
      background: #111827;
      border-color: #374151;
    }

    .rte-spellcheck-stat-label {
      font-size: 11px;
      color: #64748b;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }

    .editora-theme-dark .rte-spellcheck-stat-label {
      color: #9ca3af;
    }

    .rte-spellcheck-stat-value {
      font-size: 16px;
      font-weight: 700;
      color: #111827;
    }

    .editora-theme-dark .rte-spellcheck-stat-value {
      color: #f3f4f6;
    }

    .rte-spellcheck-list {
      flex: 1 1 auto;
      min-height: 0;
      max-height: 100%;
      overflow-y: auto;
      overflow-x: hidden;
      overscroll-behavior: contain;
      padding: 10px 12px 12px;
      display: grid;
      gap: 8px;
      scrollbar-width: thin;
      scrollbar-color: #cbd5e1 #f1f5f9;
    }

    .rte-spellcheck-list::-webkit-scrollbar {
      width: 10px;
    }

    .rte-spellcheck-list::-webkit-scrollbar-track {
      background: #f1f5f9;
      border-radius: 999px;
    }

    .rte-spellcheck-list::-webkit-scrollbar-thumb {
      background: #cbd5e1;
      border-radius: 999px;
      border: 2px solid #f1f5f9;
    }

    .rte-spellcheck-list::-webkit-scrollbar-thumb:hover {
      background: #94a3b8;
    }

    .rte-spellcheck-empty {
      padding: 18px 14px;
      text-align: center;
      color: #64748b;
      font-size: 13px;
      border-radius: 10px;
      border: 1px dashed #d1d5db;
      background: #f8fafc;
    }

    .editora-theme-dark .rte-spellcheck-empty {
      color: #9ca3af;
      border-color: #4b5563;
      background: #111827;
    }

    .editora-theme-dark .rte-spellcheck-list {
      scrollbar-color: #4b5563 #1f2937;
    }

    .editora-theme-dark .rte-spellcheck-list::-webkit-scrollbar-track {
      background: #1f2937;
    }

    .editora-theme-dark .rte-spellcheck-list::-webkit-scrollbar-thumb {
      background: #4b5563;
      border-color: #1f2937;
    }

    .editora-theme-dark .rte-spellcheck-list::-webkit-scrollbar-thumb:hover {
      background: #64748b;
    }

    .rte-spellcheck-item {
      border-radius: 10px;
      border: 1px solid #e5e7eb;
      background: #f8fafc;
      overflow: visible;
    }

    .editora-theme-dark .rte-spellcheck-item {
      border-color: #4b5563;
      background: #111827;
    }

    .rte-spell-check-panel .rte-spellcheck-word-header {
      all: unset;
      width: 100%;
      padding: 10px 11px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      cursor: pointer;
      text-align: left;
      color: #111827;
      font-size: 14px;
      line-height: 1.35;
      user-select: none;
      opacity: 1;
      visibility: visible;
    }

    .rte-spell-check-panel .rte-spellcheck-word {
      font-weight: 700;
      color: #c62828;
      word-break: break-word;
      flex: 1;
      opacity: 1;
      visibility: visible;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-word-header {
      color: #e5e7eb !important;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-word {
      color: #f87171 !important;
    }

    .rte-spell-check-panel .rte-spellcheck-caret {
      color: #64748b;
      font-size: 12px;
      min-width: 12px;
      text-align: right;
      opacity: 1;
      visibility: visible;
    }

    .rte-spell-check-panel .rte-spellcheck-suggestions {
      display: none;
      border-top: 1px solid #e5e7eb;
      padding: 9px 11px 11px;
      color: #334155;
      font-size: 12px;
      line-height: 1.4;
      opacity: 1;
      visibility: visible;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-suggestions {
      border-top-color: #374151;
      color: #d1d5db !important;
    }

    .rte-spell-check-panel .rte-spellcheck-suggestions.show {
      display: block;
    }

    .rte-spell-check-panel .rte-spellcheck-actions {
      margin-top: 8px;
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }

    .rte-spell-check-panel .rte-spellcheck-btn {
      all: unset;
      border-radius: 8px;
      border: 1px solid #d1d5db;
      background: #fff;
      color: #1f2937;
      font-size: 12px;
      font-weight: 550;
      padding: 5px 8px;
      cursor: pointer;
      transition: all 0.15s ease;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      opacity: 1;
      visibility: visible;
    }

    .rte-spell-check-panel .rte-spellcheck-btn:hover {
      background: #f3f4f6;
    }

    .rte-spell-check-panel .rte-spellcheck-btn.primary {
      border-color: #2563eb;
      background: #2563eb;
      color: #fff;
    }

    .rte-spell-check-panel .rte-spellcheck-btn.primary:hover {
      background: #1d4ed8;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-btn {
      border-color: #4b5563;
      background: #1f2937;
      color: #f3f4f6 !important;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-btn:hover {
      background: #374151;
    }

    .editora-theme-dark .rte-spell-check-panel .rte-spellcheck-btn.primary {
      border-color: #60a5fa;
      background: #2563eb;
      color: #fff;
    }

    .rte-spellcheck-menu {
      position: fixed;
      background: #ffffff;
      border: 1px solid #d1d5db;
      border-radius: 10px;
      box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
      z-index: 1300;
      padding: 6px 0;
      min-width: 180px;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      font-size: 13px;
      color: #111827;
    }

    .rte-spellcheck-menu-item {
      padding: 8px 14px;
      cursor: pointer;
      transition: background 0.15s ease;
    }

    .rte-spellcheck-menu-item:hover {
      background: #f3f4f6;
    }

    .rte-spellcheck-menu-item.meta {
      color: #64748b;
    }

    .rte-spellcheck-menu-item.positive {
      color: #1d4ed8;
    }

    .editora-theme-dark .rte-spellcheck-menu {
      background: #1f2937;
      border-color: #4b5563;
      color: #e5e7eb;
      box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    }

    .editora-theme-dark .rte-spellcheck-menu-item:hover {
      background: #374151;
    }

    .editora-theme-dark .rte-spellcheck-menu-item.meta {
      color: #9ca3af;
    }

    .editora-theme-dark .rte-spellcheck-menu-item.positive {
      color: #93c5fd;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel {
      border-color: #4b5563;
      background: #1f2937;
      color: #e5e7eb;
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-header {
      border-bottom-color: #374151;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-subtitle {
      color: #9ca3af;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-item {
      border-color: #4b5563;
      background: #111827;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-list {
      scrollbar-color: #4b5563 #1f2937;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-list::-webkit-scrollbar-track {
      background: #1f2937;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-list::-webkit-scrollbar-thumb {
      background: #4b5563;
      border-color: #1f2937;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-list::-webkit-scrollbar-thumb:hover {
      background: #64748b;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-word-header {
      color: #e5e7eb !important;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-word {
      color: #f87171 !important;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-suggestions {
      border-top-color: #374151;
      color: #d1d5db !important;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-btn {
      border-color: #4b5563;
      background: #1f2937;
      color: #f3f4f6 !important;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-btn:hover {
      background: #374151;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spell-check-panel .rte-spellcheck-btn.primary {
      border-color: #60a5fa;
      background: #2563eb;
      color: #fff;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-menu {
      background: #1f2937;
      border-color: #4b5563;
      color: #e5e7eb;
      box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-menu-item:hover {
      background: #374151;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-menu-item.meta {
      color: #9ca3af;
    }

    :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-spellcheck-menu-item.positive {
      color: #93c5fd;
    }
  `;
}
function k() {
  if (s && document.contains(s))
    return s;
  const e = V();
  return e && (s = e), e;
}
function W(e) {
  if (!e) return;
  const r = (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest('[contenteditable="true"]');
  r && (s = r);
}
function A(e) {
  if (!e) return null;
  const t = e.querySelector('[contenteditable="true"]');
  return t instanceof HTMLElement ? t : null;
}
function Q() {
  if (_) return;
  const e = (t) => {
    const r = t.target;
    if (!r) return;
    const l = r.closest(
      '.editora-toolbar-button[data-command="toggleSpellCheck"], .rte-toolbar-button[data-command="toggleSpellCheck"]'
    );
    if (!l) return;
    const o = l.closest("[data-editora-editor]"), n = A(o);
    n && (h = n, s = n);
  };
  document.addEventListener("pointerdown", e, !0), _ = !0;
}
function ee() {
  const e = P();
  if (e && document.contains(e))
    return s = e, h = null, e;
  if (h && document.contains(h)) {
    const t = h;
    return h = null, s = t, t;
  }
  return V();
}
function te() {
  b += 1, b === 1 && d && d.disconnect();
}
function re() {
  if (b === 0 || (b -= 1, b > 0) || !d) return;
  const e = k();
  e && d.observe(e, j);
}
function N(e) {
  te();
  try {
    return e();
  } finally {
    re();
  }
}
const oe = () => {
  try {
    const e = localStorage.getItem("rte-custom-dictionary");
    e && JSON.parse(e).forEach((r) => C.add(r.toLowerCase()));
  } catch (e) {
    console.warn("Failed to load custom dictionary:", e);
  }
}, le = () => {
  try {
    const e = Array.from(C);
    localStorage.setItem("rte-custom-dictionary", JSON.stringify(e));
  } catch (e) {
    console.warn("Failed to save custom dictionary:", e);
  }
};
function ne(e, t) {
  const r = [];
  for (let l = 0; l <= t.length; l++) r[l] = [l];
  for (let l = 0; l <= e.length; l++) r[0][l] = l;
  for (let l = 1; l <= t.length; l++)
    for (let o = 1; o <= e.length; o++)
      t.charAt(l - 1) === e.charAt(o - 1) ? r[l][o] = r[l - 1][o - 1] : r[l][o] = Math.min(
        r[l - 1][o - 1] + 1,
        // substitution
        r[l][o - 1] + 1,
        // insertion
        r[l - 1][o] + 1
        // deletion
      );
  return r[t.length][e.length];
}
function ce(e) {
  const t = e.toLowerCase();
  return B.has(t) || C.has(t) || S.has(t);
}
function ae(e, t = 5) {
  const r = e.toLowerCase(), o = Array.from(B).map((n) => ({ word: n, distance: ne(r, n) }));
  return o.sort((n, c) => n.distance - c.distance), o.filter((n) => n.distance <= 3).slice(0, t).map((n) => n.word);
}
function se(e) {
  if (e.nodeType !== Node.ELEMENT_NODE) return !1;
  const t = e;
  return !!(t.closest('code, pre, [contenteditable="false"], .rte-widget, .rte-template, .rte-comment, .rte-merge-tag') || t.hasAttribute("data-comment-id") || t.hasAttribute("data-template") || t.hasAttribute("data-merge-tag"));
}
function ie(e) {
  const t = [], r = /([\p{L}\p{M}\p{N}\p{Emoji_Presentation}\u200d'-]+|[\uD800-\uDBFF][\uDC00-\uDFFF])/gu;
  let l;
  for (; (l = r.exec(e.data)) !== null; ) {
    const o = l[0], n = l.index, c = n + o.length;
    /https?:\/\//.test(o) || /@/.test(o) || /\{\{.*\}\}/.test(o) || /^\d+$/.test(o) || ce(o) || /[a-z][A-Z]/.test(o) || /-/.test(o) || o[0] === o[0].toUpperCase() && o.length > 1 || t.push({
      id: `${o}-${n}`,
      node: e,
      startOffset: n,
      endOffset: c,
      word: o,
      suggestions: ae(o),
      ignored: !1
    });
  }
  return t;
}
const V = () => {
  const e = P();
  if (e && document.contains(e))
    return s = e, e;
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    let l = t.getRangeAt(0).startContainer;
    for (; l && l !== document.body; ) {
      if (l.nodeType === Node.ELEMENT_NODE) {
        const o = l;
        if (o.getAttribute("contenteditable") === "true")
          return o;
      }
      l = l.parentNode;
    }
  }
  const r = document.activeElement;
  if (r) {
    if (r.getAttribute("contenteditable") === "true")
      return r;
    const l = r.closest('[contenteditable="true"]');
    if (l) return l;
    const o = r.closest("[data-editora-editor]");
    if (o) {
      const n = o.querySelector('[contenteditable="true"]');
      if (n) return n;
    }
  }
  return document.querySelector('[contenteditable="true"]');
};
function M() {
  const e = k();
  if (!e) return [];
  const t = [], r = document.createTreeWalker(
    e,
    NodeFilter.SHOW_TEXT,
    {
      acceptNode: (o) => !o.textContent?.trim() || o.parentNode && se(o.parentNode) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT
    }
  );
  let l = r.nextNode();
  for (; l; )
    t.push(...ie(l)), l = r.nextNode();
  return t;
}
function m(e) {
  const t = k();
  t && (e || (e = M()), N(() => {
    t.querySelectorAll(".rte-misspelled").forEach((r) => {
      const l = r.parentNode;
      if (l) {
        for (; r.firstChild; )
          l.insertBefore(r.firstChild, r);
        l.removeChild(r);
      }
    }), e.forEach((r) => {
      if (S.has(r.word.toLowerCase())) return;
      const l = r.node.data.length;
      if (!(r.startOffset < 0 || r.endOffset > l || r.startOffset >= r.endOffset))
        try {
          const o = document.createRange();
          o.setStart(r.node, r.startOffset), o.setEnd(r.node, r.endOffset);
          const n = document.createElement("span");
          n.className = "rte-misspelled", n.setAttribute("data-word", r.word), n.setAttribute("data-suggestions", r.suggestions.join(",")), n.setAttribute("title", `Suggestions: ${r.suggestions.join(", ")}`), n.style.borderBottom = "2px wavy red", n.style.cursor = "pointer", o.surroundContents(n);
        } catch {
        }
    });
  }), E(e));
}
function L() {
  const e = k();
  e && N(() => {
    e.querySelectorAll(".rte-misspelled").forEach((t) => {
      const r = t.parentNode;
      if (r) {
        for (; t.firstChild; )
          r.insertBefore(t.firstChild, t);
        r.removeChild(t);
      }
    });
  });
}
function de(e, t) {
  N(() => {
    const r = document.createRange();
    r.setStart(e.node, e.startOffset), r.setEnd(e.node, e.endOffset);
    const l = document.createTextNode(t);
    r.deleteContents(), r.insertNode(l);
  });
}
function G(e) {
  S.add(e.toLowerCase()), L(), m();
}
function J(e) {
  C.add(e.toLowerCase()), le(), L(), m();
}
function pe(e) {
  const t = k();
  if (!t) return { total: 0, misspelled: 0, accuracy: 100 };
  e || (e = M());
  const r = e.filter((c) => !S.has(c.word.toLowerCase())).length, n = ((t.textContent || "").match(/[\p{L}\p{M}\p{N}]+/gu) || []).length;
  return {
    total: n,
    misspelled: r,
    accuracy: n > 0 ? (n - r) / n * 100 : 100
  };
}
function he(e, t) {
  const r = document.createTextNode(t);
  e.replaceWith(r);
}
function ue(e) {
  e.classList.remove("rte-misspelled"), e.removeAttribute("data-word"), e.removeAttribute("data-suggestions"), e.removeAttribute("title"), e.style.borderBottom = "", e.style.cursor = "";
}
function me(e, t, r, l, o) {
  W(o), document.querySelectorAll(".rte-spellcheck-menu").forEach((p) => p.remove());
  const n = document.createElement("div");
  if (n.className = "rte-spellcheck-menu", l.slice(0, 5).forEach((p) => {
    const v = document.createElement("div");
    v.className = "rte-spellcheck-menu-item", v.textContent = p, v.onclick = () => {
      he(o, p), window.setTimeout(() => {
        u && (m(), E());
      }, 0), n.remove();
    }, n.appendChild(v);
  }), l.length > 0) {
    const p = document.createElement("div");
    p.style.cssText = "height: 1px; background: #ddd; margin: 4px 0;", n.appendChild(p);
  }
  const c = document.createElement("div");
  c.className = "rte-spellcheck-menu-item meta", c.textContent = "Ignore Once", c.onclick = () => {
    ue(o), n.remove();
  }, n.appendChild(c);
  const i = document.createElement("div");
  i.className = "rte-spellcheck-menu-item meta", i.textContent = "Ignore All", i.onclick = () => {
    G(r), n.remove();
  }, n.appendChild(i);
  const w = document.createElement("div");
  w.className = "rte-spellcheck-menu-item positive", w.textContent = "Add to Dictionary", w.onclick = () => {
    J(r), n.remove();
  }, n.appendChild(w), document.body.appendChild(n);
  const D = n.getBoundingClientRect(), X = window.innerWidth - D.width - 8, Z = window.innerHeight - D.height - 8;
  n.style.left = `${Math.max(8, Math.min(e, X))}px`, n.style.top = `${Math.max(8, Math.min(t, Z))}px`;
  const F = (p) => {
    n.contains(p.target) || (n.remove(), document.removeEventListener("mousedown", F));
  };
  setTimeout(() => document.addEventListener("mousedown", F), 0);
}
function I() {
  y || (x = (e) => {
    const t = e.target;
    if (t && t.classList.contains("rte-misspelled")) {
      e.preventDefault(), W(t);
      const r = t.getAttribute("data-word"), l = (t.getAttribute("data-suggestions") || "").split(",").filter((o) => o);
      me(e.clientX, e.clientY, r, l, t);
    }
  }, document.addEventListener("contextmenu", x), y = !0);
}
function ke() {
  !y || !x || (document.removeEventListener("contextmenu", x), x = null, y = !1);
}
function fe(e) {
  return e.closest("[data-editora-editor]") || e.parentElement || e;
}
function q() {
  const e = k();
  if (!e)
    throw new Error("Spell check panel requested without active editor");
  const t = fe(e);
  T();
  const r = document.createElement("div");
  return r.className = "rte-spell-check-panel", window.getComputedStyle(t).position === "static" && (t.style.position = "relative"), t.appendChild(r), r;
}
function E(e) {
  if (!a) return;
  const t = e || M(), r = pe(t);
  a.innerHTML = `
    <div class="rte-spellcheck-header">
      <div>
        <h3 class="rte-spellcheck-title">Spell Check</h3>
        <p class="rte-spellcheck-subtitle">Review suggestions and resolve issues quickly</p>
      </div>
      <button class="rte-spellcheck-close" aria-label="Close spell check panel">✕</button>
    </div>
    
    <div class="rte-spellcheck-stats">
      <div class="rte-spellcheck-stat">
        <span class="rte-spellcheck-stat-label">Total</span>
        <strong class="rte-spellcheck-stat-value">${r.total}</strong>
      </div>
      <div class="rte-spellcheck-stat">
        <span class="rte-spellcheck-stat-label">Misspelled</span>
        <strong class="rte-spellcheck-stat-value">${r.misspelled}</strong>
      </div>
      <div class="rte-spellcheck-stat">
        <span class="rte-spellcheck-stat-label">Accuracy</span>
        <strong class="rte-spellcheck-stat-value">${r.accuracy.toFixed(1)}%</strong>
      </div>
    </div>
    
    <div class="rte-spellcheck-list">
      ${t.length === 0 ? '<div class="rte-spellcheck-empty">No spelling errors found in this editor.</div>' : t.map((o, n) => `
            <div class="rte-spellcheck-item" data-word="${o.word}" data-index="${n}">
              <button class="rte-spellcheck-word-header" type="button">
                <span class="rte-spellcheck-word">${o.word}</span>
                <span class="rte-spellcheck-caret">▶</span>
              </button>
              <div class="rte-spellcheck-suggestions">
                ${o.suggestions.length > 0 ? `<div class="rte-spellcheck-actions">
                       ${o.suggestions.map((c) => `<button class="rte-spellcheck-btn primary suggestion-btn" data-suggestion="${c}" type="button">${c}</button>`).join("")}
                     </div>` : '<div class="rte-spellcheck-subtitle">No suggestions available</div>'}
                <div class="rte-spellcheck-actions">
                  <button class="rte-spellcheck-btn ignore-btn" type="button">Ignore</button>
                  <button class="rte-spellcheck-btn add-btn" type="button">Add to Dictionary</button>
                </div>
              </div>
            </div>
          `).join("")}
    </div>
  `, a.querySelector(".rte-spellcheck-close")?.addEventListener("click", (o) => {
    o.preventDefault(), o.stopPropagation(), O();
  }), a.querySelectorAll(".rte-spellcheck-word-header").forEach((o) => {
    o.addEventListener("click", () => {
      const c = o.closest(".rte-spellcheck-item")?.querySelector(".rte-spellcheck-suggestions"), i = o.querySelector(".rte-spellcheck-caret");
      c && i && (c.classList.contains("show") ? (c.classList.remove("show"), i.textContent = "▶") : (c.classList.add("show"), i.textContent = "▼"));
    });
  }), a.querySelectorAll(".suggestion-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const n = o.getAttribute("data-suggestion"), c = o.closest(".rte-spellcheck-item");
      c?.getAttribute("data-word");
      const i = parseInt(c?.getAttribute("data-index") || "0");
      t[i] && (de(t[i], n), m());
    });
  }), a.querySelectorAll(".ignore-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const c = o.closest(".rte-spellcheck-item")?.getAttribute("data-word");
      G(c);
    });
  }), a.querySelectorAll(".add-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const c = o.closest(".rte-spellcheck-item")?.getAttribute("data-word");
      J(c);
    });
  });
}
function $() {
  const e = k();
  e && (d && d.disconnect(), d = new MutationObserver((t) => {
    b > 0 || t.some((r) => r.type === "characterData" || r.type === "childList") && (f && clearTimeout(f), f = window.setTimeout(() => {
      u && m();
    }, 350));
  }), d.observe(e, {
    ...j
  }));
}
function U() {
  d && (d.disconnect(), d = null), f && (clearTimeout(f), f = null);
}
function Y() {
  document.querySelectorAll(".rte-spellcheck-menu").forEach((e) => e.remove());
}
function z() {
  g || (g = (e) => {
    e.key !== "Escape" || !u || (e.preventDefault(), e.stopPropagation(), O());
  }, document.addEventListener("keydown", g, !0));
}
function be() {
  g && (document.removeEventListener("keydown", g, !0), g = null);
}
function O() {
  return u && (L(), U(), ke(), Y(), a && (a.remove(), a = null), s = null, h = null, u = !1, be()), !1;
}
function ge() {
  const e = ee();
  return e ? u && s && s !== e ? (L(), U(), Y(), a && (a.remove(), a = null), s = e, T(), I(), z(), m(), $(), a = q(), E(), !0) : u ? O() : (s = e, u = !0, T(), I(), z(), m(), $(), a && (a.remove(), a = null), a = q(), E(), !0) : !1;
}
const xe = () => ({
  name: "spellCheck",
  init: () => {
    oe(), Q();
  },
  toolbar: [
    {
      label: "Spell Check",
      command: "toggleSpellCheck",
      icon: '<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" 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="M3 12.5L3.84375 9.5M3.84375 9.5L5 5.38889C5 5.38889 5.25 4.5 6 4.5C6.75 4.5 7 5.38889 7 5.38889L8.15625 9.5M3.84375 9.5H8.15625M9 12.5L8.15625 9.5M13 16.8333L15.4615 19.5L21 13.5M12 8.5H15C16.1046 8.5 17 7.60457 17 6.5C17 5.39543 16.1046 4.5 15 4.5H12V8.5ZM12 8.5H16C17.1046 8.5 18 9.39543 18 10.5C18 11.6046 17.1046 12.5 16 12.5H12V8.5Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path> </g></svg>',
      shortcut: "F7"
    }
  ],
  commands: {
    toggleSpellCheck: (e, t) => (K(t), ge(), !0)
  },
  keymap: {
    F7: "toggleSpellCheck"
  }
});
export {
  xe as SpellCheckPlugin
};
