const A = /* @__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"
]), x = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Set();
let f = !1, p = null, g = null, l = null;
const D = () => {
  try {
    const t = localStorage.getItem("rte-custom-dictionary");
    t && JSON.parse(t).forEach((e) => x.add(e.toLowerCase()));
  } catch (t) {
    console.warn("Failed to load custom dictionary:", t);
  }
}, F = () => {
  try {
    const t = Array.from(x);
    localStorage.setItem("rte-custom-dictionary", JSON.stringify(t));
  } catch (t) {
    console.warn("Failed to save custom dictionary:", t);
  }
};
function $(t, r) {
  const e = [];
  for (let o = 0; o <= r.length; o++) e[o] = [o];
  for (let o = 0; o <= t.length; o++) e[0][o] = o;
  for (let o = 1; o <= r.length; o++)
    for (let s = 1; s <= t.length; s++)
      r.charAt(o - 1) === t.charAt(s - 1) ? e[o][s] = e[o - 1][s - 1] : e[o][s] = Math.min(
        e[o - 1][s - 1] + 1,
        // substitution
        e[o][s - 1] + 1,
        // insertion
        e[o - 1][s] + 1
        // deletion
      );
  return e[r.length][t.length];
}
function I(t) {
  const r = t.toLowerCase();
  return A.has(r) || x.has(r) || y.has(r);
}
function R(t, r = 5) {
  const e = t.toLowerCase(), s = Array.from(A).map((n) => ({ word: n, distance: $(e, n) }));
  return s.sort((n, i) => n.distance - i.distance), s.filter((n) => n.distance <= 3).slice(0, r).map((n) => n.word);
}
function j(t) {
  if (t.nodeType !== Node.ELEMENT_NODE) return !1;
  const r = t;
  return !!(r.closest('code, pre, [contenteditable="false"], .rte-widget, .rte-template, .rte-comment, .rte-merge-tag') || r.hasAttribute("data-comment-id") || r.hasAttribute("data-template") || r.hasAttribute("data-merge-tag"));
}
function q(t) {
  const r = [], e = /([\p{L}\p{M}\p{N}\p{Emoji_Presentation}\u200d'-]+|[\uD800-\uDBFF][\uDC00-\uDFFF])/gu;
  let o;
  for (; (o = e.exec(t.data)) !== null; ) {
    const s = o[0], n = o.index, i = n + s.length;
    /https?:\/\//.test(s) || /@/.test(s) || /\{\{.*\}\}/.test(s) || /^\d+$/.test(s) || I(s) || /[a-z][A-Z]/.test(s) || /-/.test(s) || s[0] === s[0].toUpperCase() && s.length > 1 || r.push({
      id: `${s}-${n}`,
      node: t,
      startOffset: n,
      endOffset: i,
      word: s,
      suggestions: R(s),
      ignored: !1
    });
  }
  return r;
}
const b = () => {
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    let e = t.getRangeAt(0).startContainer;
    for (; e && e !== document.body; ) {
      if (e.nodeType === Node.ELEMENT_NODE) {
        const o = e;
        if (o.getAttribute("contenteditable") === "true")
          return o;
      }
      e = e.parentNode;
    }
  }
  const r = document.activeElement;
  if (r) {
    if (r.getAttribute("contenteditable") === "true")
      return r;
    const e = r.closest('[contenteditable="true"]');
    if (e) return e;
  }
  return document.querySelector('[contenteditable="true"]');
};
function v() {
  const t = b();
  if (!t) return [];
  const r = [], e = document.createTreeWalker(
    t,
    NodeFilter.SHOW_TEXT,
    {
      acceptNode: (s) => {
        var n;
        return !((n = s.textContent) != null && n.trim()) || s.parentNode && j(s.parentNode) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
      }
    }
  );
  let o = e.nextNode();
  for (; o; )
    r.push(...q(o)), o = e.nextNode();
  return r;
}
function w(t) {
  const r = b();
  r && (t || (t = v()), r.querySelectorAll(".rte-misspelled").forEach((e) => {
    const o = e.parentNode;
    if (o) {
      for (; e.firstChild; )
        o.insertBefore(e.firstChild, e);
      o.removeChild(e);
    }
  }), t.forEach((e) => {
    if (y.has(e.word.toLowerCase())) return;
    const o = e.node.data.length;
    if (!(e.startOffset < 0 || e.endOffset > o || e.startOffset >= e.endOffset))
      try {
        const s = document.createRange();
        s.setStart(e.node, e.startOffset), s.setEnd(e.node, e.endOffset);
        const n = document.createElement("span");
        n.className = "rte-misspelled", n.setAttribute("data-word", e.word), n.setAttribute("data-suggestions", e.suggestions.join(",")), n.setAttribute("title", `Suggestions: ${e.suggestions.join(", ")}`), n.style.borderBottom = "2px wavy red", n.style.cursor = "pointer", s.surroundContents(n);
      } catch (s) {
      }
  }), m());
}
function C() {
  const t = document.querySelector('[contenteditable="true"]');
  t && t.querySelectorAll(".rte-misspelled").forEach((r) => {
    const e = r.parentNode;
    if (e) {
      for (; r.firstChild; )
        e.insertBefore(r.firstChild, r);
      e.removeChild(r);
    }
  });
}
function L(t, r) {
  const e = document.createRange();
  e.setStart(t.node, t.startOffset), e.setEnd(t.node, t.endOffset);
  const o = document.createTextNode(r);
  e.deleteContents(), e.insertNode(o);
}
function T(t) {
  y.add(t.toLowerCase()), C(), w(), m();
}
function O(t) {
  x.add(t.toLowerCase()), F(), C(), w(), m();
}
function _(t) {
  const r = b();
  if (!r) return { total: 0, misspelled: 0, accuracy: 100 };
  t || (t = v());
  const e = t.filter((i) => !y.has(i.word.toLowerCase())).length, n = ((r.textContent || "").match(/[\p{L}\p{M}\p{N}]+/gu) || []).length;
  return {
    total: n,
    misspelled: e,
    accuracy: n > 0 ? (n - e) / n * 100 : 100
  };
}
function H(t, r, e, o, s) {
  document.querySelectorAll(".rte-spellcheck-menu").forEach((a) => a.remove());
  const n = document.createElement("div");
  if (n.className = "rte-spellcheck-menu", n.style.cssText = `
    position: fixed;
    left: ${t}px;
    top: ${r}px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 99999;
    padding: 4px 0;
    min-width: 160px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
  `, o.slice(0, 5).forEach((a) => {
    const u = document.createElement("div");
    u.className = "rte-spellcheck-menu-item", u.textContent = a, u.style.cssText = "padding: 6px 16px; cursor: pointer; transition: background 0.2s;", u.onmouseenter = () => u.style.backgroundColor = "#f0f0f0", u.onmouseleave = () => u.style.backgroundColor = "transparent", u.onclick = () => {
      var S;
      const E = s.parentNode;
      if (E) {
        for (const h of E.childNodes)
          if (h.nodeType === Node.TEXT_NODE && ((S = h.textContent) != null && S.includes(e))) {
            const N = h.textContent.indexOf(e), z = {
              node: h,
              startOffset: N,
              endOffset: N + e.length
            };
            L(z, a);
            break;
          }
      }
      n.remove();
    }, n.appendChild(u);
  }), o.length > 0) {
    const a = document.createElement("div");
    a.style.cssText = "height: 1px; background: #ddd; margin: 4px 0;", n.appendChild(a);
  }
  const i = document.createElement("div");
  i.className = "rte-spellcheck-menu-item", i.textContent = "Ignore Once", i.style.cssText = "padding: 6px 16px; cursor: pointer; color: #666;", i.onmouseenter = () => i.style.backgroundColor = "#f0f0f0", i.onmouseleave = () => i.style.backgroundColor = "transparent", i.onclick = () => {
    s.remove(), n.remove();
  }, n.appendChild(i);
  const d = document.createElement("div");
  d.className = "rte-spellcheck-menu-item", d.textContent = "Ignore All", d.style.cssText = "padding: 6px 16px; cursor: pointer; color: #666;", d.onmouseenter = () => d.style.backgroundColor = "#f0f0f0", d.onmouseleave = () => d.style.backgroundColor = "transparent", d.onclick = () => {
    T(e), n.remove();
  }, n.appendChild(d);
  const c = document.createElement("div");
  c.className = "rte-spellcheck-menu-item", c.textContent = "Add to Dictionary", c.style.cssText = "padding: 6px 16px; cursor: pointer; color: #1976d2;", c.onmouseenter = () => c.style.backgroundColor = "#f0f0f0", c.onmouseleave = () => c.style.backgroundColor = "transparent", c.onclick = () => {
    O(e), n.remove();
  }, n.appendChild(c), document.body.appendChild(n);
  const k = (a) => {
    n.contains(a.target) || (n.remove(), document.removeEventListener("mousedown", k));
  };
  setTimeout(() => document.addEventListener("mousedown", k), 0);
}
function W() {
  document.addEventListener("contextmenu", (t) => {
    const r = t.target;
    if (r && r.classList.contains("rte-misspelled")) {
      t.preventDefault();
      const e = r.getAttribute("data-word"), o = (r.getAttribute("data-suggestions") || "").split(",").filter((s) => s);
      H(t.clientX, t.clientY, e, o, r);
    }
  });
}
function B() {
  const t = document.createElement("div");
  return t.className = "rte-spell-check-panel", t.style.cssText = `
    position: fixed;
    right: 0;
    top: 0;
    width: 350px;
    height: 100vh;
    background: white;
    border-left: 1px solid #ddd;
    box-shadow: -2px 0 4px rgba(0,0,0,0.1);
    overflow-y: auto;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    padding: 16px;
  `, document.body.appendChild(t), t;
}
function m() {
  if (!l) return;
  const t = v(), r = _(t);
  l.innerHTML = `
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
      <h3 style="margin: 0; font-size: 16px; font-weight: 600;">Spell Check</h3>
      <button class="rte-spellcheck-close" style="background: none; border: none; font-size: 22px; cursor: pointer; color: #888;">✕</button>
    </div>
    
    <div style="display: flex; gap: 24px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid #eee;">
      <div>
        <div style="font-size: 12px; color: #999;">Total Words</div>
        <div style="font-size: 16px; font-weight: 600; color: #333;">${r.total}</div>
      </div>
      <div>
        <div style="font-size: 12px; color: #999;">Misspelled</div>
        <div style="font-size: 16px; font-weight: 600; color: #d32f2f;">${r.misspelled}</div>
      </div>
      <div>
        <div style="font-size: 12px; color: #999;">Accuracy</div>
        <div style="font-size: 16px; font-weight: 600; color: #388e3c;">${r.accuracy.toFixed(1)}%</div>
      </div>
    </div>
    
    <div class="misspellings-list">
      ${t.length === 0 ? '<div style="padding: 12px; text-align: center; color: #999; font-size: 13px;">No spelling errors found</div>' : t.map((o, s) => `
            <div class="misspelling-item" data-word="${o.word}" data-index="${s}" style="padding: 8px; margin-bottom: 8px; background-color: #f5f5f5; border-radius: 4px;">
              <div class="word-header" style="display: flex; justify-content: space-between; align-items: center; cursor: pointer;">
                <span style="font-weight: 600; color: #d32f2f;">${o.word}</span>
                <button class="expand-btn" style="background: none; border: none; cursor: pointer; font-size: 12px; color: #666;">▶</button>
              </div>
              <div class="suggestions" style="display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid #ddd;">
                ${o.suggestions.length > 0 ? `<div style="font-size: 12px; font-weight: 600; color: #333; margin-bottom: 6px;">Suggestions:</div>
                     ${o.suggestions.map((n) => `<button class="suggestion-btn" data-suggestion="${n}" style="display: inline-block; margin-right: 6px; margin-bottom: 6px; padding: 4px 8px; background-color: #1976d2; color: white; border: none; border-radius: 3px; font-size: 12px; cursor: pointer;">${n}</button>`).join("")}` : '<div style="font-size: 12px; color: #999; margin-bottom: 8px;">No suggestions</div>'}
                <div style="margin-top: 8px; display: flex; gap: 6px;">
                  <button class="ignore-btn" style="font-size: 12px; padding: 4px 8px; background-color: white; border: 1px solid #ddd; border-radius: 3px; cursor: pointer;">Ignore</button>
                  <button class="add-btn" style="font-size: 12px; padding: 4px 8px; background-color: white; border: 1px solid #ddd; border-radius: 3px; cursor: pointer;">Add to Dictionary</button>
                </div>
              </div>
            </div>
          `).join("")}
    </div>
  `;
  const e = l.querySelector(".rte-spellcheck-close");
  e == null || e.addEventListener("click", () => {
    M();
  }), l.querySelectorAll(".word-header").forEach((o, s) => {
    o.addEventListener("click", () => {
      const n = o.closest(".misspelling-item"), i = n == null ? void 0 : n.querySelector(".suggestions"), d = o.querySelector(".expand-btn");
      i && d && (i.style.display === "none" ? (i.style.display = "block", d.textContent = "▼") : (i.style.display = "none", d.textContent = "▶"));
    });
  }), l.querySelectorAll(".suggestion-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const s = o.getAttribute("data-suggestion"), n = o.closest(".misspelling-item");
      n == null || n.getAttribute("data-word");
      const i = parseInt((n == null ? void 0 : n.getAttribute("data-index")) || "0");
      t[i] && L(t[i], s);
    });
  }), l.querySelectorAll(".ignore-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const s = o.closest(".misspelling-item"), n = s == null ? void 0 : s.getAttribute("data-word");
      T(n);
    });
  }), l.querySelectorAll(".add-btn").forEach((o) => {
    o.addEventListener("click", () => {
      const s = o.closest(".misspelling-item"), n = s == null ? void 0 : s.getAttribute("data-word");
      O(n);
    });
  });
}
function P() {
  const t = b();
  t && (p && p.disconnect(), p = new MutationObserver((r) => {
    r.some((e) => e.type === "characterData" || e.type === "childList") && (g && clearTimeout(g), g = window.setTimeout(() => {
      f && (w(), m());
    }, 350));
  }), p.observe(t, {
    characterData: !0,
    childList: !0,
    subtree: !0
  }));
}
function V() {
  p && (p.disconnect(), p = null), g && (clearTimeout(g), g = null);
}
function M() {
  return f = !f, f ? (w(), W(), P(), l || (l = B(), m())) : (C(), V(), l && (l.remove(), l = null)), f;
}
const G = () => ({
  name: "spellCheck",
  init: () => {
    D();
  },
  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: () => (M(), !0)
  },
  keymap: {
    F7: "toggleSpellCheck"
  }
});
export {
  G as SpellCheckPlugin
};
//# sourceMappingURL=SpellCheckPlugin.native-B7yTh0iE.mjs.map
