const g = ".rte-content, .editora-content", Y = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", w = '.rte-mention[data-mention="true"]', b = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', M = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap();
let P = !1, N = !1, T = null, v = 0;
function Q(e, n) {
  if (n === e.innerHTML) return;
  const o = window.execEditorCommand || window.executeEditorCommand;
  if (typeof o == "function")
    try {
      o("recordDomTransaction", e, n, e.innerHTML);
    } catch {
    }
}
function U(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function h(e, n) {
  const o = window.getSelection();
  o && (o.removeAllRanges(), o.addRange(n), e.focus({ preventScroll: !0 }));
}
function S(e, n) {
  return e.startContainer === n.startContainer && e.startOffset === n.startOffset && e.endContainer === n.endContainer && e.endOffset === n.endOffset;
}
function E(e) {
  const n = window.getSelection();
  if (!n || n.rangeCount === 0) return null;
  const o = n.getRangeAt(0);
  return e.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
}
function C(e) {
  Array.from(e.querySelectorAll(w)).forEach((o) => {
    o.setAttribute("data-mention", "true"), o.setAttribute("contenteditable", "false"), o.setAttribute("spellcheck", "false"), o.setAttribute("draggable", "false"), o.classList.add("rte-mention");
  });
}
function _(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function ee(e) {
  return e.closest(Y) || e;
}
function k(e) {
  return e ? (e.getAttribute("data-theme") || e.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark") : !1;
}
function ne(e) {
  const n = ee(e);
  if (k(n)) return !0;
  const o = n.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return k(o) ? !0 : k(document.documentElement) || k(document.body);
}
function W(e, n) {
  e.classList.remove("rte-mention-theme-dark"), ne(n) && e.classList.add("rte-mention-theme-dark");
}
function te(e) {
  if (e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const t = e.editorElement;
    if (t.matches(g)) return t;
    const r = t.querySelector(g);
    if (r instanceof HTMLElement) return r;
  }
  const n = window.getSelection();
  if (n && n.rangeCount > 0) {
    const t = n.getRangeAt(0).startContainer, i = (t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement)?.closest(g);
    if (i) return i;
  }
  const o = document.activeElement;
  if (o) {
    if (o.matches(g)) return o;
    const t = o.closest(g);
    if (t) return t;
  }
  return document.querySelector(g);
}
function x(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function D(e) {
  return typeof e == "object" && e !== null && !Array.isArray(e);
}
function re(e, n) {
  return n ? n.split(".").filter(Boolean).reduce((o, t) => {
    if (!(!D(o) && !Array.isArray(o)))
      return o[t];
  }, e) : e;
}
function oe(e) {
  return e ? /\s|[([{"'`]/.test(e) : !0;
}
function ie(e) {
  if (!e.collapsed) return null;
  const n = e.startContainer, o = e.startOffset;
  if (n.nodeType === Node.TEXT_NODE) {
    const t = n;
    return {
      node: t,
      textBefore: t.data.slice(0, o),
      caretOffset: o
    };
  }
  if (n.nodeType === Node.ELEMENT_NODE) {
    const t = n;
    if (o > 0) {
      const r = t.childNodes[o - 1];
      if (r && r.nodeType === Node.TEXT_NODE) {
        const i = r;
        return {
          node: i,
          textBefore: i.data,
          caretOffset: i.length
        };
      }
    }
  }
  return null;
}
function ae(e, n, o) {
  let t = -1, r = "";
  if (n.forEach((a) => {
    const l = e.lastIndexOf(a);
    l > t && (t = l, r = a);
  }), t < 0 || !oe(e[t - 1])) return null;
  const i = e.slice(t + 1);
  return /\s/.test(i) || i.length > o ? null : {
    trigger: r,
    query: i,
    startOffset: t
  };
}
function le(e, n) {
  const o = n.cloneRange();
  o.collapse(!1);
  const t = o.getClientRects();
  if (t.length > 0)
    return t[t.length - 1];
  const r = document.createElement("span");
  r.textContent = "​", r.style.position = "relative", o.insertNode(r);
  const i = r.getBoundingClientRect();
  return r.remove(), e.normalize(), i;
}
function se(e, n) {
  if (e.panel && e.list) return;
  const o = document.createElement("div");
  o.className = "rte-mention-panel", o.style.display = "none";
  const t = document.createElement("div");
  t.className = "rte-mention-list", o.appendChild(t), document.body.appendChild(o), W(o, e.editor), e.panel = o, e.list = t, o.addEventListener("mousedown", (r) => {
    r.preventDefault();
  }), o.addEventListener("click", (r) => {
    const i = r.target;
    if (!i) return;
    const a = i.closest(".rte-mention-item");
    if (!a) return;
    const l = Number(a.getAttribute("data-index"));
    Number.isFinite(l) && K(e, n, l);
  });
}
function m(e) {
  e.panel && (e.debounceHandle !== null && (window.clearTimeout(e.debounceHandle), e.debounceHandle = null), e.abortController && (e.abortController.abort(), e.abortController = null), e.panel.style.display = "none", e.panel.classList.remove("show"), e.isOpen = !1, e.loading = !1, e.items = [], e.activeIndex = 0, e.query = "", e.replaceRange = null);
}
function $(e, n) {
  if (!e.panel) return;
  W(e.panel, e.editor);
  const o = le(e.editor, n), t = e.panel;
  t.style.display = "block", t.classList.add("show"), t.style.left = "0px", t.style.top = "0px";
  const r = t.getBoundingClientRect(), i = window.innerWidth, a = window.innerHeight;
  let l = Math.max(8, Math.min(o.left, i - r.width - 8)), s = o.bottom + 8;
  s + r.height > a - 8 && (s = Math.max(8, o.top - r.height - 8)), t.style.position = "fixed", t.style.left = `${l}px`, t.style.top = `${s}px`;
}
function ce(e, n) {
  if (!n) return x(e);
  const o = e.toLowerCase(), t = n.toLowerCase(), r = o.indexOf(t);
  if (r < 0) return x(e);
  const i = x(e.slice(0, r)), a = x(e.slice(r, r + n.length)), l = x(e.slice(r + n.length));
  return `${i}<mark>${a}</mark>${l}`;
}
function B(e, n) {
  if (!e.list) return;
  const o = e.list;
  if (o.innerHTML = "", e.loading) {
    const t = document.createElement("div");
    t.className = "rte-mention-empty", t.textContent = n.loadingText, o.appendChild(t);
    return;
  }
  if (e.items.length === 0) {
    const t = document.createElement("div");
    t.className = "rte-mention-empty", t.textContent = e.query.length > 0 ? n.noResultsText : n.emptyStateText, o.appendChild(t);
    return;
  }
  e.items.forEach((t, r) => {
    const i = document.createElement("button");
    i.type = "button", i.className = "rte-mention-item", r === e.activeIndex && i.classList.add("active"), i.setAttribute("data-index", String(r));
    const a = n.itemRenderer ? n.itemRenderer(t, e.query) : `<span class="rte-mention-item-label">${ce(t.label, e.query)}</span>${t.meta ? `<span class="rte-mention-item-meta">${x(t.meta)}</span>` : ""}`;
    i.innerHTML = a, o.appendChild(i);
  });
}
function G(e, n) {
  const o = /* @__PURE__ */ new Set(), t = [];
  return e.forEach((r) => {
    const i = (r.id || "").trim();
    !i || o.has(i) || (o.add(i), t.push({
      id: i,
      label: r.label || i,
      value: r.value,
      meta: r.meta
    }));
  }), t.slice(0, n);
}
function ue(e, n) {
  if (e.buildRequest) {
    const c = e.buildRequest(n);
    return {
      url: c.url,
      init: c.init || {}
    };
  }
  const o = (e.method || "GET").toUpperCase(), t = typeof e.headers == "function" ? e.headers(n) : e.headers || {}, r = e.queryParam || "q", i = e.triggerParam || "trigger", a = e.limitParam || "limit", l = e.staticParams || {}, s = {
    method: o,
    headers: { ...t },
    credentials: e.credentials,
    mode: e.mode,
    cache: e.cache,
    signal: n.signal
  }, f = new URL(e.url, window.location.origin);
  if (o === "GET" || o === "HEAD") {
    const c = new URLSearchParams(f.search);
    Object.entries(l).forEach(([d, p]) => c.set(d, String(p))), c.set(r, n.query), c.set(i, n.trigger), c.set(a, String(n.limit)), f.search = c.toString();
  } else {
    const c = typeof e.body == "function" ? e.body(n) : e.body, d = {
      [r]: n.query,
      [i]: n.trigger,
      [a]: n.limit,
      ...l
    }, p = c ?? d;
    if (D(p)) {
      s.body = JSON.stringify(p);
      const y = s.headers;
      !y["Content-Type"] && !y["content-type"] && (y["Content-Type"] = "application/json");
    } else
      s.body = p;
  }
  return { url: f.toString(), init: s };
}
async function de(e, n, o, t) {
  const r = n.api;
  if (!r) return [];
  e.abortController && e.abortController.abort();
  const i = new AbortController();
  e.abortController = i;
  const a = {
    query: o,
    trigger: t,
    limit: n.maxSuggestions,
    signal: i.signal
  }, l = Math.max(0, r.timeoutMs ?? 1e4);
  let s = null;
  l > 0 && (s = window.setTimeout(() => i.abort(), l));
  try {
    const { url: f, init: c } = ue(r, a), d = await fetch(f, {
      ...c,
      signal: i.signal
    });
    if (!d.ok)
      throw new Error(`Mention API request failed: ${d.status}`);
    const y = (r.responseType || "json") === "text" ? await d.text() : await d.json();
    let O = [];
    if (r.transformResponse)
      O = r.transformResponse(y, a) || [];
    else {
      const q = re(y, r.responsePath);
      O = (Array.isArray(q) ? q : Array.isArray(y) ? y : []).map((u, J) => {
        if (r.mapItem)
          return r.mapItem(u, J);
        if (!D(u)) return null;
        const I = String(u.id ?? u.value ?? u.key ?? "").trim();
        if (!I) return null;
        const Z = String(u.label ?? u.name ?? I).trim();
        return {
          id: I,
          label: Z,
          value: u.value ? String(u.value) : void 0,
          meta: u.meta ? String(u.meta) : void 0
        };
      }).filter((u) => !!u);
    }
    return G(O, n.maxSuggestions);
  } catch (f) {
    return f?.name !== "AbortError" && r.onError?.(f, a), [];
  } finally {
    s !== null && window.clearTimeout(s), e.abortController === i && (e.abortController = null);
  }
}
async function fe(e, n, o, t) {
  const r = ++e.requestId;
  let i = [];
  if (n.search) {
    const a = await n.search(o, t);
    i = Array.isArray(a) ? a : [];
  } else if (n.api)
    i = await de(e, n, o, t);
  else {
    const a = o.toLowerCase();
    i = n.items.filter((l) => a ? l.label.toLowerCase().includes(a) || l.id.toLowerCase().includes(a) : !0);
  }
  return r !== e.requestId ? [] : G(i, n.maxSuggestions);
}
function me(e, n, o) {
  const t = e.editor;
  if (C(t), !window.getSelection()) return !1;
  const i = t.innerHTML;
  let a = e.replaceRange ? e.replaceRange.cloneRange() : E(t);
  if (!a || !t.contains(a.commonAncestorContainer) && (a = E(t), !a))
    return !1;
  const l = A(t, a.cloneRange(), "after");
  S(l, a) || (h(t, l), a = l), a.deleteContents();
  const s = document.createElement("span");
  s.className = "rte-mention", s.setAttribute("data-mention", "true"), s.setAttribute("data-mention-id", o.id), s.setAttribute("contenteditable", "false"), s.textContent = o.value || `${e.trigger}${o.label}`, a.insertNode(s);
  let f = s, c = 1;
  if (n.insertSpaceAfterMention) {
    const p = document.createTextNode(" ");
    s.after(p), f = p, c = 1;
  }
  const d = document.createRange();
  return d.setStart(f, c), d.collapse(!0), h(t, d), m(e), C(t), U(t), Q(t, i), !0;
}
function K(e, n, o) {
  if (o < 0 || o >= e.items.length) return;
  const t = e.items[o];
  me(e, n, t);
}
function pe(e) {
  return e.startContainer !== e.endContainer || e.startContainer.nodeType !== Node.ELEMENT_NODE || e.endOffset - e.startOffset !== 1 ? null : e.startContainer.childNodes[e.startOffset] || null;
}
function ge(e, n) {
  const o = pe(e);
  return !(o instanceof HTMLElement) || !o.matches(w) || !n.contains(o) ? null : o;
}
function V(e, n) {
  const o = ge(e, n);
  if (o) return o;
  const r = _(e.startContainer)?.closest(w);
  if (r && n.contains(r)) return r;
  const a = _(e.endContainer)?.closest(w);
  return a && n.contains(a) ? a : null;
}
function A(e, n, o = "after") {
  const t = V(n, e);
  if (!t) return n;
  const r = document.createRange();
  return o === "before" ? r.setStartBefore(t) : r.setStartAfter(t), r.collapse(!0), r;
}
function j(e, n, o = "after") {
  const t = document.createRange();
  o === "before" ? t.setStartBefore(n) : t.setStartAfter(n), t.collapse(!0), h(e, t);
}
function he(e, n, o) {
  if (!e.collapsed) return null;
  const t = e.startContainer, r = e.startOffset;
  let i = null;
  if (t.nodeType === Node.TEXT_NODE) {
    const a = t;
    n === "backward" && r === 0 ? i = a.previousSibling : n === "forward" && r === a.length && (i = a.nextSibling);
  } else if (t.nodeType === Node.ELEMENT_NODE) {
    const a = t;
    n === "backward" && r > 0 ? i = a.childNodes[r - 1] || null : n === "forward" && r < a.childNodes.length && (i = a.childNodes[r] || null);
  }
  return !(i instanceof HTMLElement) || !i.matches(w) || !o.contains(i) ? null : i;
}
function z(e, n) {
  const o = E(e);
  if (!o) return !1;
  const t = he(o, n, e);
  if (!t) return !1;
  const r = t.parentNode;
  if (!r) return !1;
  const i = e.innerHTML, a = Array.prototype.indexOf.call(r.childNodes, t);
  t.remove();
  const l = document.createRange();
  return l.setStart(r, Math.max(0, a)), l.collapse(!0), h(e, l), U(e), Q(e, i), !0;
}
function X(e, n, o, t, r, i) {
  if (se(e, n), e.query = t, e.trigger = r, e.replaceRange = i.cloneRange(), e.loading = !!(n.api && !n.search), e.debounceHandle !== null && (window.clearTimeout(e.debounceHandle), e.debounceHandle = null), !e.panel) return;
  e.isOpen || (e.panel.style.display = "block", e.panel.classList.add("show"), e.isOpen = !0), B(e, n), $(e, o);
  const a = () => {
    e.debounceHandle = null, fe(e, n, t, r).then((s) => {
      e.loading = !1, e.items = s, e.activeIndex = 0, e.panel && (B(e, n), $(e, o));
    });
  }, l = n.api && !n.search ? Math.max(0, n.api.debounceMs ?? 180) : 0;
  l > 0 ? e.debounceHandle = window.setTimeout(a, l) : a();
}
function ye(e, n) {
  const o = e.editor;
  C(o);
  let t = E(o);
  if (!t || !t.collapsed) {
    m(e);
    return;
  }
  const r = A(o, t.cloneRange(), "after");
  if (!S(r, t)) {
    h(o, r), t = r, m(e);
    return;
  }
  const i = ie(t);
  if (!i) {
    m(e);
    return;
  }
  const a = ae(i.textBefore, n.triggerChars, n.maxQueryLength);
  if (!a) {
    m(e);
    return;
  }
  if (a.query.length < n.minChars) {
    m(e);
    return;
  }
  const l = t.cloneRange();
  l.setStart(i.node, a.startOffset), l.setEnd(i.node, i.caretOffset), X(e, n, t, a.query, a.trigger, l);
}
function F(e, n) {
  if (e.items.length === 0) return;
  const o = e.items.length;
  if (e.activeIndex = ((e.activeIndex + n) % o + o) % o, !e.list) return;
  const t = Array.from(e.list.querySelectorAll(".rte-mention-item"));
  t.forEach((i, a) => i.classList.toggle("active", a === e.activeIndex)), t[e.activeIndex]?.scrollIntoView({ block: "nearest" });
}
function be(e) {
  return {
    editor: e,
    panel: null,
    list: null,
    replaceRange: null,
    items: [],
    activeIndex: 0,
    query: "",
    trigger: "@",
    loading: !1,
    isOpen: !1,
    requestId: 0,
    debounceHandle: null,
    abortController: null
  };
}
function Ee(e) {
  const n = M.get(e);
  n && (n.panel?.parentNode && n.panel.parentNode.removeChild(n.panel), M.delete(e));
}
function H(e, n, o) {
  if (R.has(e)) return;
  C(e);
  const t = {
    beforeInput: (r) => {
      C(e);
      const i = E(e);
      if (!i) return;
      const a = V(i, e);
      if (!a) return;
      const l = r.inputType || "";
      if (l.startsWith("insert")) {
        if (r.preventDefault(), j(e, a, "after"), l === "insertParagraph" || l === "insertLineBreak") {
          const s = l === "insertLineBreak" ? "insertLineBreak" : "insertParagraph";
          document.execCommand(s, !1);
          return;
        }
        if (l === "insertText" || l === "insertCompositionText") {
          const s = r.data || "";
          if (!s) return;
          document.execCommand("insertText", !1, s);
        }
      }
    },
    input: () => {
      ye(n, o);
    },
    keydown: (r) => {
      if (n.isOpen) {
        if (r.key === "ArrowDown") {
          r.preventDefault(), F(n, 1);
          return;
        }
        if (r.key === "ArrowUp") {
          r.preventDefault(), F(n, -1);
          return;
        }
        if (r.key === "Enter" || r.key === "Tab") {
          r.preventDefault(), K(n, o, n.activeIndex);
          return;
        }
        if (r.key === "Escape") {
          r.preventDefault(), m(n);
          return;
        }
      }
      const i = E(e);
      if (i) {
        const a = A(e, i.cloneRange(), "after");
        if (!S(a, i)) {
          if (r.key === "Enter") {
            r.preventDefault(), h(e, a), document.execCommand("insertParagraph", !1);
            return;
          }
          r.key.length === 1 && !r.metaKey && !r.ctrlKey && !r.altKey && h(e, a);
        }
      }
      if (r.key === "Backspace" && z(e, "backward")) {
        r.preventDefault();
        return;
      }
      if (r.key === "Delete" && z(e, "forward")) {
        r.preventDefault();
        return;
      }
    },
    click: (r) => {
      const i = r.target;
      if (!i) return;
      const l = (i.nodeType === Node.ELEMENT_NODE ? i : i.parentElement)?.closest(w);
      !l || !e.contains(l) || (r.preventDefault(), r.stopPropagation(), j(e, l, "after"), m(n));
    },
    blur: () => {
      window.setTimeout(() => {
        const r = document.activeElement;
        n.panel && r && n.panel.contains(r) || m(n);
      }, 0);
    },
    mousedown: (r) => {
      if (!n.isOpen || !n.panel) return;
      const i = r.target;
      i && !n.panel.contains(i) && !e.contains(i) && m(n);
    }
  };
  e.addEventListener("beforeinput", t.beforeInput), e.addEventListener("input", t.input), e.addEventListener("keydown", t.keydown), e.addEventListener("click", t.click), e.addEventListener("blur", t.blur), document.addEventListener("mousedown", t.mousedown, !0), R.set(e, t);
}
function xe(e) {
  const n = R.get(e);
  n && (e.removeEventListener("beforeinput", n.beforeInput), e.removeEventListener("input", n.input), e.removeEventListener("keydown", n.keydown), e.removeEventListener("click", n.click), e.removeEventListener("blur", n.blur), document.removeEventListener("mousedown", n.mousedown, !0), R.delete(e));
}
function we() {
  if (P || typeof document > "u") return;
  P = !0;
  const e = document.createElement("style");
  e.id = "rte-mention-plugin-styles", e.textContent = `
    .rte-mention {
      display: inline-block;
      padding: 0 6px;
      margin: 0 1px;
      border-radius: 10px;
      background: #e8f0ff;
      color: #1d4ed8;
      font-weight: 600;
      line-height: 1.6;
      white-space: nowrap;
      cursor: pointer;
    }

    .rte-mention-panel {
      width: min(320px, calc(100vw - 16px));
      max-height: min(320px, calc(100vh - 32px));
      overflow: hidden;
      border: 1px solid #d9dfeb;
      border-radius: 3px;
      background: #ffffff;
      box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
      z-index: 2147483646;
    }

    .rte-mention-list {
      max-height: min(300px, calc(100vh - 56px));
      overflow: auto;
      padding: 0px;
    }

    .rte-mention-item {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      border: none;
      background: transparent;
      padding: 10px 12px;
      border-radius: 0px;
      color: #0f172a;
      text-align: left;
      cursor: pointer;
      font: inherit;
    }

    .rte-mention-item:hover,
    .rte-mention-item.active {
      background: #eff6ff;
      color: #1d4ed8;
    }

    .rte-mention-item-label mark {
      background: rgba(59, 130, 246, 0.16);
      color: inherit;
      padding: 0 2px;
      border-radius: 3px;
    }

    .rte-mention-item-meta {
      font-size: 12px;
      color: #64748b;
      white-space: nowrap;
    }

    .rte-mention-empty {
      padding: 12px;
      color: #64748b;
      font-size: 13px;
      text-align: center;
    }

    ${b} .rte-mention {
      background: rgba(37, 99, 235, 0.25);
      color: #bfdbfe;
    }

    ${b} .rte-mention-panel,
    .rte-mention-panel.rte-mention-theme-dark {
      border-color: #364152;
      background: #1f2937;
      box-shadow: 0 22px 44px rgba(0, 0, 0, 0.48);
    }

    ${b} .rte-mention-item,
    .rte-mention-panel.rte-mention-theme-dark .rte-mention-item {
      color: #e5e7eb;
    }

    ${b} .rte-mention-item:hover,
    ${b} .rte-mention-item.active,
    .rte-mention-panel.rte-mention-theme-dark .rte-mention-item:hover,
    .rte-mention-panel.rte-mention-theme-dark .rte-mention-item.active {
      background: #334155;
      color: #bfdbfe;
    }

    ${b} .rte-mention-item-meta,
    ${b} .rte-mention-empty,
    .rte-mention-panel.rte-mention-theme-dark .rte-mention-item-meta,
    .rte-mention-panel.rte-mention-theme-dark .rte-mention-empty {
      color: #9ca3af;
    }
  `, document.head.appendChild(e);
}
function Te(e) {
  const n = (e.triggerChars || ["@"]).filter((o) => typeof o == "string" && o.length > 0).map((o) => o[0]);
  return {
    triggerChars: n.length > 0 ? n : ["@"],
    minChars: Math.max(0, e.minChars ?? 1),
    maxQueryLength: Math.max(1, e.maxQueryLength ?? 32),
    maxSuggestions: Math.max(1, e.maxSuggestions ?? 8),
    items: e.items || [
      { id: "john.doe", label: "John Doe", meta: "john@acme.com" },
      { id: "sarah.lee", label: "Sarah Lee", meta: "sarah@acme.com" },
      { id: "alex.chen", label: "Alex Chen", meta: "alex@acme.com" }
    ],
    api: e.api,
    search: e.search,
    itemRenderer: e.itemRenderer,
    emptyStateText: e.emptyStateText || "Type to search mentions",
    noResultsText: e.noResultsText || "No matching mentions",
    loadingText: e.loadingText || "Loading...",
    insertSpaceAfterMention: e.insertSpaceAfterMention !== !1
  };
}
function L(e) {
  const n = M.get(e);
  if (n) return n;
  const o = be(e);
  return M.set(e, o), o;
}
function Ce(e) {
  N || (N = !0, T = (n) => {
    const o = n.target;
    if (!(o instanceof Node)) return;
    const r = (o.nodeType === Node.ELEMENT_NODE ? o : o.parentElement)?.closest(g) || null;
    if (!r) return;
    const i = L(r);
    H(r, i, e);
  }, document.addEventListener("focusin", T, !0));
}
function ve() {
  !N || !T || (document.removeEventListener("focusin", T, !0), N = !1, T = null);
}
const Le = (e = {}) => {
  we();
  const n = Te(e);
  return {
    name: "mentions",
    toolbar: [
      {
        label: "Mention",
        command: "insertMention",
        icon: '<svg width="24" height="24" focusable="false"><path d="M12.1 4a7.9 7.9 0 0 0-8 8c0 4.4 3.6 8 8 8 1.6 0 3-.4 4.4-1.3.4-.3.5-.9.2-1.3a1 1 0 0 0-1.3-.3 6 6 0 0 1-3.3.9 6 6 0 1 1 6-6v1.6c0 .8-.5 1.4-1.2 1.4-.8 0-1.2-.6-1.2-1.4V12c0-2-1.6-3.5-3.7-3.5s-3.8 1.6-3.8 3.6c0 2 1.7 3.6 3.8 3.6 1 0 1.9-.4 2.6-1 .5 1 1.4 1.6 2.5 1.6 1.8 0 3.2-1.5 3.2-3.4V12A7.9 7.9 0 0 0 12 4Zm0 9.7c-1 0-1.8-.8-1.8-1.7s.8-1.7 1.8-1.7c1 0 1.7.8 1.7 1.7s-.8 1.7-1.7 1.7Z"></path></svg>'
      }
    ],
    commands: {
      insertMention: (o, t) => {
        const r = te(t);
        if (!r) return !1;
        const i = L(r);
        H(r, i, n);
        let a = E(r);
        a || (a = document.createRange(), a.selectNodeContents(r), a.collapse(!1), h(r, a));
        const l = A(r, a.cloneRange(), "after");
        S(l, a) || (h(r, l), a = l), i.query = "";
        const s = a.cloneRange();
        return i.trigger = n.triggerChars[0], X(i, n, a, "", i.trigger, s), !0;
      }
    },
    init: () => {
      v += 1, Ce(n), Array.from(document.querySelectorAll(g)).forEach((t) => {
        const r = L(t);
        H(t, r, n);
      });
    },
    destroy: () => {
      v = Math.max(0, v - 1), Array.from(document.querySelectorAll(g)).forEach((t) => {
        m(L(t)), xe(t), Ee(t);
      }), v === 0 && ve();
    }
  };
};
export {
  Le as MentionPlugin
};
