const $ = ".rte-content, .editora-content", pt = "rte-citations-styles", m = "rte-citations-panel", ot = ".rte-citation-ref[data-citation-id]", W = '.rte-citation-bibliography[data-type="citation-bibliography"]', G = '.rte-citation-footnotes[data-type="citation-footnotes"]', x = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', L = ["apa", "mla", "chicago"], Ot = {
  panelTitle: "Citations",
  panelAriaLabel: "Citations panel",
  styleLabel: "Citation style",
  authorLabel: "Author",
  yearLabel: "Year",
  titleLabel: "Title",
  sourceLabel: "Source",
  urlLabel: "URL",
  noteLabel: "Footnote note",
  insertText: "Insert Citation",
  refreshText: "Refresh Bibliography",
  closeText: "Close",
  bibliographyTitle: "References",
  footnotesTitle: "Citation Notes",
  noCitationsText: "No citations inserted yet.",
  styleButtonPrefix: "Style",
  recentHeading: "Recent citations",
  deleteRecentText: "x",
  summaryPrefix: "Citations",
  invalidMessage: "Author and title are required."
}, f = /* @__PURE__ */ new WeakMap(), T = /* @__PURE__ */ new WeakMap(), ht = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new Map(), V = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new Set();
let I = null, B = null, O = null, k = null, Y = 0, Pt = 0, at = 0, M = null, p = null;
function g(t) {
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function Dt(t) {
  return t.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function xt(t, o) {
  const e = o(t);
  if (!e) return "";
  const i = e.match(/\d{4}/);
  return i ? i[0] : e;
}
function yt(t, o) {
  const e = o(t);
  return e ? /^https?:\/\//i.test(e) ? e : `https://${e}` : "";
}
function F(t) {
  return t.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
}
function Ct(t, o) {
  return {
    id: F(o.normalizeText(t.id || "")),
    author: o.normalizeText(t.author || ""),
    year: xt(t.year || "", o.normalizeText) || void 0,
    title: o.normalizeText(t.title || ""),
    source: o.normalizeText(t.source || "") || void 0,
    url: yt(t.url || "", o.normalizeText) || void 0,
    note: o.normalizeText(t.note || "") || void 0
  };
}
function Z(t = {}) {
  var i, n;
  const o = t.defaultStyle && L.includes(t.defaultStyle) ? t.defaultStyle : "apa", e = {
    ...Ot,
    ...t.labels || {}
  };
  return {
    defaultStyle: o,
    enableFootnoteSync: t.enableFootnoteSync !== !1,
    debounceMs: Math.max(80, Number((i = t.debounceMs) != null ? i : 220)),
    maxRecentCitations: Math.max(3, Math.min(30, Number((n = t.maxRecentCitations) != null ? n : 8))),
    labels: e,
    normalizeText: t.normalizeText || Dt,
    generateCitationId: typeof t.generateCitationId == "function" ? t.generateCitationId : void 0
  };
}
function wt(t) {
  return t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null;
}
function lt(t) {
  return t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || t;
}
function X(t) {
  return t ? (t.getAttribute("data-theme") || t.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : t.classList.contains("dark") || t.classList.contains("editora-theme-dark") || t.classList.contains("rte-theme-dark") : !1;
}
function Ht(t) {
  const o = lt(t);
  if (X(o)) return !0;
  const e = o.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return X(e) ? !0 : X(document.documentElement) || X(document.body);
}
function tt(t, o) {
  t.classList.remove("rte-citations-theme-dark"), Ht(o) && t.classList.add("rte-citations-theme-dark");
}
function h(t, o = !0) {
  if ((t == null ? void 0 : t.contentElement) instanceof HTMLElement) return t.contentElement;
  if ((t == null ? void 0 : t.editorElement) instanceof HTMLElement) {
    const n = t.editorElement;
    if (n.matches($)) return n;
    const r = n.querySelector($);
    if (r instanceof HTMLElement) return r;
  }
  const e = window.getSelection();
  if (e && e.rangeCount > 0) {
    const n = e.getRangeAt(0).startContainer, r = wt(n), a = r == null ? void 0 : r.closest($);
    if (a) return a;
  }
  const i = document.activeElement;
  if (i) {
    if (i.matches($)) return i;
    const n = i.closest($);
    if (n) return n;
  }
  return p && p.isConnected ? p : (p && !p.isConnected && (p = null), o ? document.querySelector($) : null);
}
function S(t) {
  return t.getAttribute("contenteditable") === "false" || t.getAttribute("data-readonly") === "true";
}
function K(t) {
  const o = wt(t);
  return o ? !!(o.closest(W) || o.closest(G)) : !1;
}
function Ft(t, o) {
  if (at += 1, o.generateCitationId) {
    const e = o.generateCitationId({ editor: t, index: at }), i = F(o.normalizeText(e || ""));
    if (i) return i;
  }
  return `cite-${Date.now().toString(36)}-${at.toString(36)}`;
}
function st(t) {
  return t.map((o) => (o || "").trim()).filter(Boolean).join(" ").trim();
}
function _t(t, o) {
  const e = t.author || "Unknown", i = t.year || "n.d.";
  return o === "mla" ? `(${e} ${i})` : o === "chicago" ? `(${e} ${i})` : `(${e}, ${i})`;
}
function ut(t, o) {
  const e = t.author || "Unknown", i = t.year || "n.d.", n = t.title || "Untitled", r = t.source || "", a = t.url || "";
  return st(o === "mla" ? [
    `${e}.`,
    `"${n}."`,
    r ? `${r},` : "",
    `${i}.`,
    a
  ] : o === "chicago" ? [
    `${e}.`,
    `${n}.`,
    r ? `${r}.` : "",
    `(${i}).`,
    a
  ] : [
    `${e}.`,
    `(${i}).`,
    `${n}.`,
    r ? `${r}.` : "",
    a
  ]);
}
function R(t) {
  return Array.from(t.querySelectorAll(ot)).filter(
    (o) => !o.closest(W) && !o.closest(G)
  );
}
function vt(t, o) {
  const e = F(o.normalizeText(t.getAttribute("data-citation-id") || ""));
  if (!e) return null;
  const i = o.normalizeText(t.getAttribute("data-citation-author") || ""), n = o.normalizeText(t.getAttribute("data-citation-title") || "");
  return {
    id: e,
    author: i || "Unknown",
    year: xt(t.getAttribute("data-citation-year") || "", o.normalizeText) || void 0,
    title: n || "Untitled",
    source: o.normalizeText(t.getAttribute("data-citation-source") || "") || void 0,
    url: yt(t.getAttribute("data-citation-url") || "", o.normalizeText) || void 0,
    note: o.normalizeText(t.getAttribute("data-citation-note") || "") || void 0
  };
}
function Et(t, o, e) {
  t.classList.add("rte-citation-ref"), t.setAttribute("data-citation-id", o.id), t.setAttribute("data-citation-author", o.author || ""), t.setAttribute("data-citation-year", o.year || ""), t.setAttribute("data-citation-title", o.title || ""), t.setAttribute("data-citation-source", o.source || ""), t.setAttribute("data-citation-url", o.url || ""), t.setAttribute("data-citation-note", o.note || ""), t.setAttribute("contenteditable", "false"), t.setAttribute("tabindex", "0"), t.setAttribute("role", "doc-biblioref"), t.setAttribute("data-style", e), t.textContent = _t(o, e);
}
function it(t, o, e) {
  const i = lt(t);
  Array.from(
    i.querySelectorAll(
      `.rte-toolbar-button[data-command="${o}"], .editora-toolbar-button[data-command="${o}"]`
    )
  ).forEach((r) => {
    r.classList.toggle("active", e), r.setAttribute("data-active", e ? "true" : "false"), r.setAttribute("aria-pressed", e ? "true" : "false");
  });
}
function N(t, o) {
  const e = T.get(t);
  return e && L.includes(e) ? e : (o == null ? void 0 : o.defaultStyle) || "apa";
}
function j(t, o) {
  const e = R(t), i = /* @__PURE__ */ new Map();
  return e.forEach((n) => {
    const r = vt(n, o);
    if (!r) return;
    if (!i.has(r.id)) {
      i.set(r.id, r);
      return;
    }
    const a = i.get(r.id);
    i.set(r.id, {
      ...a,
      author: a.author || r.author,
      title: a.title || r.title,
      year: a.year || r.year,
      source: a.source || r.source,
      url: a.url || r.url,
      note: a.note || r.note
    });
  }), Array.from(i.values());
}
function qt(t, o, e) {
  const i = Ct(o, e);
  if (!i.id || !i.author || !i.title) return;
  const r = (D.get(t) || []).filter((a) => a.id !== i.id);
  D.set(t, [i, ...r].slice(0, e.maxRecentCitations));
}
function rt(t, o, e) {
  const i = D.get(t) || [], n = /* @__PURE__ */ new Map();
  o.slice(Math.max(0, o.length - e.maxRecentCitations)).reverse().forEach((a) => {
    a.id && n.set(a.id, a);
  }), i.forEach((a) => {
    !a.id || n.has(a.id) || n.set(a.id, a);
  });
  const r = Array.from(n.values()).slice(0, e.maxRecentCitations);
  return D.set(t, r), r;
}
function $t(t, o, e, i) {
  const n = F(i.normalizeText(o || ""));
  return n && rt(t, e, i).find((a) => a.id === n) || null;
}
function Kt(t, o, e) {
  const i = F(e.normalizeText(o || ""));
  if (!i) return !1;
  const n = D.get(t) || [], r = n.filter((a) => a.id !== i);
  return r.length === n.length ? !1 : (D.set(t, r), !0);
}
function St(t, o, e) {
  const i = document.createElement("section");
  i.className = t, i.setAttribute("data-type", o), i.setAttribute("contenteditable", "false"), i.setAttribute("aria-label", e), o === "citation-bibliography" ? i.setAttribute("role", "doc-bibliography") : o === "citation-footnotes" && i.setAttribute("role", "doc-endnotes");
  const n = document.createElement("h3");
  n.className = "rte-citation-section-title", n.textContent = e;
  const r = document.createElement("ol");
  return r.className = "rte-citation-list", r.setAttribute("role", "list"), i.appendChild(n), i.appendChild(r), i;
}
function jt(t, o) {
  let e = t.querySelector(W);
  e || (e = St("rte-citation-bibliography", "citation-bibliography", o.labels.bibliographyTitle), t.appendChild(e));
  const i = e.querySelector(".rte-citation-section-title");
  return i && (i.textContent = o.labels.bibliographyTitle), e.setAttribute("aria-label", o.labels.bibliographyTitle), e;
}
function Ut(t, o) {
  let e = t.querySelector(G);
  e || (e = St("rte-citation-footnotes", "citation-footnotes", o.labels.footnotesTitle), t.appendChild(e));
  const i = e.querySelector(".rte-citation-section-title");
  return i && (i.textContent = o.labels.footnotesTitle), e.setAttribute("aria-label", o.labels.footnotesTitle), e;
}
function At(t, o) {
  const e = t.querySelector(o);
  e == null || e.remove();
}
function Wt(t, o, e, i) {
  if (o.length === 0) {
    At(t, W);
    return;
  }
  const r = jt(t, e).querySelector(".rte-citation-list");
  if (!r) return;
  const a = document.createDocumentFragment();
  o.forEach((s, d) => {
    const c = document.createElement("li");
    c.className = "rte-citation-item", c.id = `rte-citation-entry-${s.id}`, c.setAttribute("data-citation-id", s.id), c.setAttribute("data-citation-number", String(d + 1)), c.textContent = ut(s, i), a.appendChild(c);
  }), r.innerHTML = "", r.appendChild(a);
}
function Gt(t, o, e, i) {
  if (!e.enableFootnoteSync || o.length === 0) {
    At(t, G), R(t).forEach((l) => {
      l.removeAttribute("data-footnote-number"), l.removeAttribute("data-footnote-target");
    });
    return;
  }
  const r = Ut(t, e).querySelector(".rte-citation-list");
  if (!r) return;
  const a = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
  o.forEach((l, u) => {
    s.set(l.id, u + 1);
  });
  const d = /* @__PURE__ */ new Map();
  R(t).forEach((l) => {
    const u = l.getAttribute("data-citation-id") || "";
    if (!u || !s.has(u)) return;
    const b = (d.get(u) || 0) + 1;
    d.set(u, b);
    const w = `rte-citation-ref-${u}-${b}`;
    l.id = w;
    const A = s.get(u);
    l.setAttribute("data-footnote-number", String(A)), l.setAttribute("data-footnote-target", `rte-citation-note-${u}`), a.has(u) || a.set(u, w);
  });
  const c = document.createDocumentFragment();
  o.forEach((l, u) => {
    const b = document.createElement("li");
    b.className = "rte-citation-item rte-citation-footnote-item", b.id = `rte-citation-note-${l.id}`, b.setAttribute("data-citation-id", l.id);
    const w = document.createElement("span");
    w.className = "rte-citation-footnote-number", w.textContent = `${u + 1}. `;
    const A = document.createElement("span");
    A.className = "rte-citation-footnote-text";
    const Bt = l.note ? `${l.note}. ` : "";
    A.textContent = `${Bt}${ut(l, i)}`, b.appendChild(w), b.appendChild(A);
    const gt = a.get(l.id);
    if (gt) {
      const _ = document.createElement("a");
      _.className = "rte-citation-backref", _.href = `#${gt}`, _.setAttribute("aria-label", `Back to citation ${u + 1}`), _.textContent = "Back", b.appendChild(_);
    }
    c.appendChild(b);
  }), r.innerHTML = "", r.appendChild(c);
}
function Vt(t, o, e, i) {
  const n = ut(o, e);
  t.setAttribute("data-citation-number", String(i)), t.setAttribute("aria-label", `Citation ${i}: ${n}`);
}
function Yt(t, o, e) {
  const i = R(t);
  let n = `${o}:${e ? "1" : "0"}:${i.length}`;
  return i.forEach((r) => {
    n += `|${r.getAttribute("data-citation-id") || ""}`, n += `|${r.getAttribute("data-citation-author") || ""}`, n += `|${r.getAttribute("data-citation-year") || ""}`, n += `|${r.getAttribute("data-citation-title") || ""}`, n += `|${r.getAttribute("data-citation-source") || ""}`, n += `|${r.getAttribute("data-citation-url") || ""}`, n += `|${r.getAttribute("data-citation-note") || ""}`;
  }), n;
}
function H(t) {
  const o = v.get(t);
  if (!o) return;
  const e = f.get(t) || M;
  if (!e) return;
  const i = N(t, e), n = j(t, e), r = rt(t, n, e), a = o.querySelector(".rte-citations-status"), s = o.querySelector('[data-action="cycle-style"]'), d = o.querySelector(".rte-citations-recent-list");
  if (a) {
    const c = n.length;
    a.textContent = `${e.labels.summaryPrefix}: ${c} | Style: ${i.toUpperCase()} | Footnotes: ${e.enableFootnoteSync ? "On" : "Off"}`;
  }
  if (s && (s.textContent = `${e.labels.styleButtonPrefix}: ${i.toUpperCase()}`, s.setAttribute("aria-label", `${e.labels.styleButtonPrefix}: ${i.toUpperCase()}`)), d) {
    if (r.length === 0) {
      d.innerHTML = `<li class="rte-citations-empty">${g(e.labels.noCitationsText)}</li>`;
      return;
    }
    d.innerHTML = r.map(
      (c) => `
          <li class="rte-citations-recent-item">
            <div class="rte-citations-recent-row">
              <button
                type="button"
                class="rte-citations-recent-btn"
                data-action="insert-from-recent"
                data-citation-id="${g(c.id)}"
                aria-label="Insert citation: ${g(c.title)}"
              >
                <span class="rte-citations-recent-title">${g(c.title)}</span>
                <span class="rte-citations-recent-meta">${g(c.author)}${c.year ? ` (${g(c.year)})` : ""}</span>
              </button>
              <button
                type="button"
                class="rte-citations-recent-delete"
                data-action="delete-by-id"
                data-citation-id="${g(c.id)}"
                aria-label="Delete citation: ${g(c.title)}"
              >${g(e.labels.deleteRecentText)}</button>
            </div>
          </li>
        `
    ).join("");
  }
}
function y(t, o, e = !1) {
  const i = N(t, o), n = Yt(t, i, o.enableFootnoteSync);
  if (!e && ht.get(t) === n)
    return j(t, o);
  const r = R(t), a = /* @__PURE__ */ new Map();
  r.forEach((c) => {
    const l = vt(c, o);
    l && (a.has(l.id) || a.set(l.id, l));
  });
  const s = Array.from(a.values());
  rt(t, s, o);
  const d = /* @__PURE__ */ new Map();
  return s.forEach((c, l) => {
    d.set(c.id, l + 1);
  }), r.forEach((c) => {
    const l = c.getAttribute("data-citation-id") || "", u = a.get(l);
    if (!u) return;
    Et(c, u, i);
    const b = d.get(u.id) || 1;
    Vt(c, u, i, Math.max(1, b));
  }), Wt(t, s, o, i), Gt(t, s, o, i), ht.set(t, n), H(t), t.dispatchEvent(
    new CustomEvent("editora:citations-refreshed", {
      bubbles: !0,
      detail: {
        citations: s,
        style: i,
        footnoteSync: o.enableFootnoteSync
      }
    })
  ), s;
}
function kt(t) {
  const o = Q.get(t);
  typeof o == "number" && (window.clearTimeout(o), q.delete(o), Q.delete(t));
}
function Tt(t) {
  const o = f.get(t) || M;
  if (!o) return;
  kt(t);
  const e = window.setTimeout(() => {
    q.delete(e), Q.delete(t), y(t, o, !1);
  }, o.debounceMs);
  q.add(e), Q.set(t, e);
}
function Xt(t) {
  const o = window.getSelection();
  if (!o) throw new Error("Selection unavailable");
  if (o.rangeCount > 0) {
    const a = o.getRangeAt(0);
    if (t.contains(a.commonAncestorContainer) && !K(a.commonAncestorContainer))
      return a.cloneRange();
  }
  const e = document.createRange(), i = t.querySelector(W), n = t.querySelector(G), r = i || n;
  return r ? (e.setStartBefore(r), e.collapse(!0), e) : (e.selectNodeContents(t), e.collapse(!1), e);
}
function dt(t) {
  t.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function ft(t, o) {
  if (o === t.innerHTML) return;
  const e = window.execEditorCommand || window.executeEditorCommand;
  if (typeof e == "function")
    try {
      e("recordDomTransaction", t, o, t.innerHTML);
    } catch (i) {
    }
}
function Mt(t, o) {
  const e = window.getSelection();
  if (!e) return;
  const i = document.createRange();
  if (t.nodeType === Node.TEXT_NODE) {
    const n = t, r = Math.max(0, Math.min(o, n.length));
    i.setStart(n, r);
  } else {
    const n = t.childNodes.length, r = Math.max(0, Math.min(o, n));
    i.setStart(t, r);
  }
  i.collapse(!0), e.removeAllRanges(), e.addRange(i);
}
function Lt(t) {
  if (t.collapsed || t.startContainer !== t.endContainer || t.endOffset !== t.startOffset + 1 || !(t.startContainer instanceof Element || t.startContainer instanceof DocumentFragment))
    return null;
  const o = t.startContainer.childNodes[t.startOffset];
  return !(o instanceof HTMLElement) || !o.matches(ot) ? null : o;
}
function J(t, o, e) {
  const { startContainer: i, startOffset: n } = t;
  if (i.nodeType === Node.ELEMENT_NODE) {
    const a = i;
    if (e === "previous") {
      if (n > 0) return a.childNodes[n - 1] || null;
    } else if (n < a.childNodes.length)
      return a.childNodes[n] || null;
  }
  if (i.nodeType === Node.TEXT_NODE && (e === "previous" && n < i.data.length || e === "next" && n > 0))
    return null;
  let r = i;
  for (; r && r !== o; ) {
    const a = e === "previous" ? r.previousSibling : r.nextSibling;
    if (a) return a;
    r = r.parentNode;
  }
  return null;
}
function Rt(t, o, e) {
  if (!t.collapsed) return null;
  const i = (a) => a instanceof HTMLElement && a.matches(ot) ? a : null, { startContainer: n, startOffset: r } = t;
  if (n.nodeType === Node.ELEMENT_NODE) {
    const a = n;
    return e === "Backspace" && r > 0 ? i(a.childNodes[r - 1] || null) : e === "Delete" ? i(a.childNodes[r] || null) : null;
  }
  if (n.nodeType === Node.TEXT_NODE) {
    const a = n;
    if (e === "Backspace" && r === 0) {
      const s = i(a.previousSibling);
      return s || i(J(t, o, "previous"));
    }
    if (e === "Delete" && r === a.data.length) {
      const s = i(a.nextSibling);
      return s || i(J(t, o, "next"));
    }
  }
  return i(e === "Backspace" ? J(t, o, "previous") : J(t, o, "next"));
}
function P(t, o, e) {
  const i = t.closest($);
  if (!i || K(t)) return !1;
  const n = t.parentNode;
  if (!n) return !1;
  const r = i.innerHTML, a = Array.from(n.childNodes).indexOf(t);
  if (a < 0) return !1;
  const s = t.nextSibling;
  return s instanceof Text && (s.data === " " ? s.remove() : s.data.startsWith(" ") && (s.data = s.data.slice(1))), t.remove(), Mt(n, a), y(i, e, !0), ft(i, r), dt(i), o === "Delete" && i.focus({ preventScroll: !0 }), !0;
}
function Jt(t, o, e) {
  if (t.key !== "Backspace" && t.key !== "Delete") return !1;
  const i = t.key, n = t.target;
  if (n != null && n.matches(ot) && o.contains(n) && !K(n))
    return t.preventDefault(), t.stopPropagation(), P(n, i, e);
  const r = window.getSelection();
  if (!r || r.rangeCount === 0) return !1;
  const a = r.getRangeAt(0);
  if (!o.contains(a.commonAncestorContainer) || K(a.commonAncestorContainer)) return !1;
  const s = Lt(a);
  if (s)
    return t.preventDefault(), t.stopPropagation(), P(s, i, e);
  const d = Rt(a, o, i);
  return d ? (t.preventDefault(), t.stopPropagation(), P(d, i, e)) : !1;
}
function Nt(t, o, e) {
  const i = F(e.normalizeText(o || ""));
  if (!i) return !1;
  const n = R(t).filter((a) => a.getAttribute("data-citation-id") === i);
  if (n.length === 0) return !1;
  if (n.length === 1)
    return P(n[0], "Delete", e);
  const r = t.innerHTML;
  return n.forEach((a) => {
    const s = a.nextSibling;
    s instanceof Text && (s.data === " " ? s.remove() : s.data.startsWith(" ") && (s.data = s.data.slice(1))), a.remove();
  }), Mt(t, t.childNodes.length), y(t, e, !0), ft(t, r), dt(t), t.focus({ preventScroll: !0 }), !0;
}
function Zt(t, o) {
  const e = window.getSelection();
  if (!e || e.rangeCount === 0) return !1;
  const i = e.getRangeAt(0);
  if (!t.contains(i.commonAncestorContainer) || K(i.commonAncestorContainer)) return !1;
  const n = Lt(i);
  if (n)
    return P(n, "Delete", o);
  const r = Rt(i, t, "Backspace");
  return r ? P(r, "Backspace", o) : !1;
}
function et(t, o, e) {
  var l, u;
  const i = Ct(o, e);
  if (!i.author || !i.title) return !1;
  i.id || (i.id = Ft(t, e));
  const n = t.innerHTML;
  let r;
  try {
    r = Xt(t);
  } catch (b) {
    return !1;
  }
  const a = window.getSelection();
  if (!a) return !1;
  r.collapsed || r.deleteContents();
  const s = document.createElement("span");
  Et(s, i, N(t, e));
  try {
    r.insertNode(s);
  } catch (b) {
    return !1;
  }
  const d = document.createTextNode(" ");
  s.nextSibling ? (l = s.parentNode) == null || l.insertBefore(d, s.nextSibling) : (u = s.parentNode) == null || u.appendChild(d);
  const c = document.createRange();
  if (d.parentNode) {
    const b = Array.from(d.parentNode.childNodes).indexOf(d) + 1;
    c.setStart(d.parentNode, Math.max(0, b));
  } else
    c.setStartAfter(s);
  return c.collapse(!0), a.removeAllRanges(), a.addRange(c), qt(t, i, e), y(t, e, !0), ft(t, n), dt(t), !0;
}
function Qt(t, o) {
  if (!o) return !1;
  const e = R(t).find((r) => r.getAttribute("data-citation-id") === o) || null;
  if (!e) return !1;
  e.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" }), e.focus({ preventScroll: !0 });
  const i = window.getSelection();
  if (!i) return !0;
  const n = document.createRange();
  return n.selectNode(e), i.removeAllRanges(), i.addRange(n), !0;
}
function nt(t) {
  return V.get(t) === !0;
}
function U(t, o = !1) {
  const e = v.get(t);
  e && (e.classList.remove("show"), V.set(t, !1), it(t, "toggleCitationsPanel", !1), o && t.focus({ preventScroll: !0 }));
}
function te(t) {
  v.forEach((o, e) => {
    e !== t && U(e, !1);
  });
}
function ct(t, o) {
  if (!o.classList.contains("show")) return;
  const i = lt(t).getBoundingClientRect(), n = Math.min(window.innerWidth - 20, 380), r = Math.max(10, window.innerWidth - n - 10), a = Math.min(Math.max(10, i.right - n), r), s = Math.max(10, Math.min(window.innerHeight - 10 - 260, i.top + 10));
  o.style.width = `${n}px`, o.style.left = `${a}px`, o.style.top = `${s}px`, o.style.maxHeight = `${Math.max(260, window.innerHeight - 24)}px`;
}
function C(t, o) {
  return t.querySelector(`[data-field="${o}"]`);
}
function ee(t) {
  var s, d, c, l, u, b;
  const o = ((s = C(t, "author")) == null ? void 0 : s.value) || "", e = ((d = C(t, "year")) == null ? void 0 : d.value) || "", i = ((c = C(t, "title")) == null ? void 0 : c.value) || "", n = ((l = C(t, "source")) == null ? void 0 : l.value) || "", r = ((u = C(t, "url")) == null ? void 0 : u.value) || "", a = ((b = C(t, "note")) == null ? void 0 : b.value) || "";
  return {
    author: o,
    year: e,
    title: i,
    source: n,
    url: r,
    note: a
  };
}
function E(t, o) {
  const e = t.querySelector(".rte-citations-live");
  e && (e.textContent = o);
}
function ne(t, o, e) {
  const i = C(o, "style");
  i && (i.value = N(t, e));
}
function zt(t, o, e) {
  const i = L.includes(o) ? o : e.defaultStyle;
  return T.set(t, i), y(t, e, !0), i;
}
function bt(t, o) {
  const e = N(t, o), i = L.indexOf(e), n = L[(i + 1) % L.length];
  return T.set(t, n), y(t, o, !0), n;
}
function oe(t) {
  const o = v.get(t);
  if (o) return o;
  const e = f.get(t) || M || Z(), i = `rte-citations-panel-${Pt++}`, n = document.createElement("section");
  n.className = m, n.id = i, n.setAttribute("role", "dialog"), n.setAttribute("aria-modal", "false"), n.setAttribute("aria-label", e.labels.panelAriaLabel), n.setAttribute("tabindex", "-1"), n.innerHTML = `
    <header class="rte-citations-header">
      <h2 class="rte-citations-title">${g(e.labels.panelTitle)}</h2>
      <button type="button" class="rte-citations-icon-btn" data-action="close" aria-label="${g(e.labels.closeText)}">✕</button>
    </header>
    <div class="rte-citations-body">
      <p class="rte-citations-status" aria-live="polite"></p>

      <div class="rte-citations-grid">
        <label class="rte-citations-label">
          ${g(e.labels.styleLabel)}
          <select data-field="style" class="rte-citations-field">
            <option value="apa">APA</option>
            <option value="mla">MLA</option>
            <option value="chicago">Chicago</option>
          </select>
        </label>
        <label class="rte-citations-label">
          ${g(e.labels.authorLabel)}
          <input type="text" data-field="author" class="rte-citations-field" autocomplete="off" />
        </label>
        <label class="rte-citations-label">
          ${g(e.labels.yearLabel)}
          <input type="text" data-field="year" class="rte-citations-field" inputmode="numeric" autocomplete="off" />
        </label>
        <label class="rte-citations-label">
          ${g(e.labels.titleLabel)}
          <input type="text" data-field="title" class="rte-citations-field" autocomplete="off" />
        </label>
        <label class="rte-citations-label">
          ${g(e.labels.sourceLabel)}
          <input type="text" data-field="source" class="rte-citations-field" autocomplete="off" />
        </label>
        <label class="rte-citations-label">
          ${g(e.labels.urlLabel)}
          <input type="url" data-field="url" class="rte-citations-field" autocomplete="off" />
        </label>
        <label class="rte-citations-label rte-citations-label-note">
          ${g(e.labels.noteLabel)}
          <textarea data-field="note" class="rte-citations-field" rows="2"></textarea>
        </label>
      </div>

      <div class="rte-citations-controls" role="toolbar" aria-label="Citation actions">
        <button type="button" class="rte-citations-btn rte-citations-btn-primary" data-action="insert">${g(e.labels.insertText)}</button>
        <button type="button" class="rte-citations-btn" data-action="refresh">${g(e.labels.refreshText)}</button>
        <button type="button" class="rte-citations-btn" data-action="cycle-style"></button>
      </div>

      <section class="rte-citations-recent" aria-label="${g(e.labels.recentHeading)}">
        <h3 class="rte-citations-recent-heading">${g(e.labels.recentHeading)}</h3>
        <ul class="rte-citations-recent-list" role="list"></ul>
      </section>

      <p class="rte-citations-shortcut">Shortcut: Ctrl/Cmd + Alt + Shift + C</p>
      <span class="rte-citations-live" aria-live="polite"></span>
    </div>
  `, n.addEventListener("click", (a) => {
    const s = a.target;
    if (!s) return;
    const d = s.closest("[data-action]");
    if (!d) return;
    const c = d.getAttribute("data-action") || "", l = f.get(t) || M || e;
    if (f.set(t, l), c === "close") {
      U(t, !0);
      return;
    }
    if (c === "insert") {
      if (S(t)) return;
      const u = ee(n);
      if (!l.normalizeText(u.author) || !l.normalizeText(u.title)) {
        E(n, l.labels.invalidMessage);
        return;
      }
      if (!et(t, u, l)) {
        E(n, l.labels.invalidMessage);
        return;
      }
      E(n, "Citation inserted.");
      const w = C(n, "title"), A = C(n, "note");
      w && (w.value = ""), A && (A.value = "");
      return;
    }
    if (c === "refresh") {
      const u = y(t, l, !0);
      E(n, `Refreshed ${u.length} citation${u.length === 1 ? "" : "s"}.`);
      return;
    }
    if (c === "cycle-style") {
      const u = bt(t, l);
      ne(t, n, l), E(n, `Style changed to ${u.toUpperCase()}.`);
      return;
    }
    if (c === "insert-from-recent") {
      if (S(t)) return;
      const u = d.getAttribute("data-citation-id") || "", b = $t(t, u, j(t, l), l);
      if (!b) return;
      et(t, b, l), E(n, `Inserted citation: ${b.title}.`);
      return;
    }
    if (c === "delete-by-id") {
      if (S(t)) return;
      const u = d.getAttribute("data-citation-id") || "";
      if (Nt(t, u, l)) {
        E(n, "Citation deleted.");
        return;
      }
      Kt(t, u, l) && (H(t), E(n, "Removed from recent citations."));
    }
  }), n.addEventListener("keydown", (a) => {
    if (a.key === "Escape") {
      a.preventDefault(), U(t, !0);
      return;
    }
    const s = a.target;
    if (!s || !s.matches(".rte-citations-recent-btn") || a.key !== "ArrowDown" && a.key !== "ArrowUp") return;
    const d = Array.from(n.querySelectorAll(".rte-citations-recent-btn"));
    if (d.length === 0) return;
    const c = d.indexOf(s);
    if (c < 0) return;
    a.preventDefault();
    const l = a.key === "ArrowDown" ? 1 : -1, u = (c + l + d.length) % d.length;
    d[u].focus();
  });
  const r = C(n, "style");
  return r == null || r.addEventListener("change", () => {
    const a = f.get(t) || M || e, s = r.value;
    zt(t, s, a), E(n, `Style changed to ${s.toUpperCase()}.`);
  }), tt(n, t), document.body.appendChild(n), v.set(t, n), V.set(t, !1), H(t), n;
}
function z(t) {
  const o = oe(t);
  te(t), o.classList.add("show"), V.set(t, !0), it(t, "toggleCitationsPanel", !0), tt(o, t), ct(t, o), H(t);
  const e = C(o, "author");
  e == null || e.focus();
}
function It(t, o) {
  const e = nt(t);
  return (typeof o == "boolean" ? o : !e) ? z(t) : U(t, !1), !0;
}
function mt(t) {
  return typeof t.key == "string" ? t.key.toLowerCase() : "";
}
function ie(t) {
  const o = mt(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && o === "c";
}
function re(t) {
  const o = mt(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && o === "b";
}
function ae(t) {
  const o = mt(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && o === "j";
}
function se(t) {
  M = t, I || (I = (o) => {
    const e = o.target, i = e == null ? void 0 : e.closest($);
    if (!i) return;
    p = i, f.has(i) || f.set(i, t), T.has(i) || T.set(i, t.defaultStyle);
    const n = v.get(i);
    n && (tt(n, i), ct(i, n)), it(i, "toggleCitationsPanel", nt(i));
  }, document.addEventListener("focusin", I, !0)), B || (B = (o) => {
    const e = o.target, i = e == null ? void 0 : e.closest($);
    i && (p = i, Tt(i));
  }, document.addEventListener("input", B, !0)), O || (O = (o) => {
    if (o.defaultPrevented) return;
    const e = o.target, i = !!(e != null && e.closest(`.${m} input, .${m} textarea, .${m} select`)), n = h(void 0, !1);
    if (!n || S(n)) return;
    const r = f.get(n) || M || t;
    if (f.set(n, r), p = n, o.key === "Escape" && nt(n)) {
      o.preventDefault(), U(n, !0);
      return;
    }
    if (!i && !Jt(o, n, r)) {
      if (ie(o)) {
        o.preventDefault(), o.stopPropagation(), It(n);
        return;
      }
      if (re(o)) {
        o.preventDefault(), o.stopPropagation(), y(n, r, !0), z(n);
        return;
      }
      ae(o) && (o.preventDefault(), o.stopPropagation(), bt(n, r));
    }
  }, document.addEventListener("keydown", O, !0)), k || (k = () => {
    v.forEach((o, e) => {
      if (!e.isConnected || !o.isConnected) {
        kt(e), o.remove(), v.delete(e), V.delete(e);
        return;
      }
      tt(o, e), ct(e, o);
    });
  }, window.addEventListener("scroll", k, !0), window.addEventListener("resize", k));
}
function ce() {
  I && (document.removeEventListener("focusin", I, !0), I = null), B && (document.removeEventListener("input", B, !0), B = null), O && (document.removeEventListener("keydown", O, !0), O = null), k && (window.removeEventListener("scroll", k, !0), window.removeEventListener("resize", k), k = null), v.forEach((t) => t.remove()), v.clear(), M = null, p = null;
}
function le() {
  if (typeof document == "undefined" || document.getElementById(pt)) return;
  const t = document.createElement("style");
  t.id = pt, t.textContent = `
    .rte-toolbar-group-items.citations,
    .editora-toolbar-group-items.citations {
      display: flex;
      border: 1px solid #ccc;
      border-radius: 3px;
      background: #fff;
    }

    .rte-toolbar-group-items.citations .rte-toolbar-button,
    .editora-toolbar-group-items.citations .editora-toolbar-button {
      border: none;
      border-radius: 0;
      border-right: 1px solid #ccc;
    }

    .rte-toolbar-group-items.citations .rte-toolbar-item:last-child .rte-toolbar-button,
    .editora-toolbar-group-items.citations .editora-toolbar-item:last-child .editora-toolbar-button {
      border-right: none;
    }

    .rte-toolbar-button[data-command="toggleCitationsPanel"].active,
    .editora-toolbar-button[data-command="toggleCitationsPanel"].active {
      background: #ccc;
    }

    ${x} .rte-toolbar-group-items.citations,
    ${x} .editora-toolbar-group-items.citations,
    .${m}.rte-citations-theme-dark {
      border-color: #566275;
    }

    ${x} .rte-toolbar-group-items.citations .rte-toolbar-button[data-command="refreshCitations"] svg,
    ${x} .editora-toolbar-group-items.citations .editora-toolbar-button[data-command="refreshCitations"] svg
    {
      fill: none;
    }
    ${x} .rte-toolbar-group-items.citations .rte-toolbar-button,
    ${x} .editora-toolbar-group-items.citations .editora-toolbar-button
    {
      border-color: #566275;
    }
    ${x} .rte-toolbar-button[data-command="toggleCitationsPanel"].active,
    ${x} .editora-toolbar-button[data-command="toggleCitationsPanel"].active {
      background: linear-gradient(180deg, #5eaaf6 0%, #4a95de 100%);
    }
    .${m} {
      position: fixed;
      z-index: 1500;
      right: 16px;
      top: 16px;
      width: min(380px, calc(100vw - 20px));
      max-height: calc(100vh - 24px);
      display: none;
      flex-direction: column;
      border-radius: 12px;
      border: 1px solid #d1d5db;
      background: #ffffff;
      color: #0f172a;
      box-shadow: 0 18px 38px rgba(15, 23, 42, 0.16);
      overflow: hidden;
    }

    .${m}.show {
      display: flex;
    }

    .${m}.rte-citations-theme-dark {
      background: #0f172a;
      color: #e2e8f0;
      border-color: #334155;
      box-shadow: 0 20px 40px rgba(2, 6, 23, 0.5);
    }

    .rte-citations-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 12px;
      border-bottom: 1px solid #e2e8f0;
      background: #f8fafc;
    }

    .${m}.rte-citations-theme-dark .rte-citations-header {
      border-bottom-color: #334155;
      background: #111827;
    }

    .rte-citations-title {
      margin: 0;
      font-size: 14px;
      font-weight: 700;
    }

    .rte-citations-icon-btn {
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: #0f172a;
      border-radius: 6px;
      cursor: pointer;
      min-width: 34px;
      min-height: 34px;
      width: 34px;
      height: 34px;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      line-height: 1;
      font-weight: 600;
    }

    .rte-citations-icon-btn:hover,
    .rte-citations-icon-btn:focus-visible {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

    .${m}.rte-citations-theme-dark .rte-citations-icon-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    .${m}.rte-citations-theme-dark .rte-citations-icon-btn:hover,
    .${m}.rte-citations-theme-dark .rte-citations-icon-btn:focus-visible {
      border-color: #60a5fa;
      box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.24);
    }

    .rte-citations-body {
      display: flex;
      flex-direction: column;
      gap: 10px;
      padding: 12px;
      overflow: auto;
    }

    .rte-citations-status {
      margin: 0;
      font-size: 12px;
      color: #475569;
    }

    .${m}.rte-citations-theme-dark .rte-citations-status {
      color: #94a3b8;
    }

    .rte-citations-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .rte-citations-label {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: 12px;
      font-weight: 600;
      color: inherit;
    }

    .rte-citations-label-note {
      grid-column: 1 / -1;
    }

    .rte-citations-field {
      width: 100%;
      box-sizing: border-box;
      min-height: 30px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: inherit;
      font-size: 13px;
      padding: 6px 8px;
    }

    .rte-citations-field:focus-visible {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
    }

    .${m}.rte-citations-theme-dark .rte-citations-field {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .rte-citations-controls {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }

    .rte-citations-btn {
      border: 1px solid #cbd5e1;
      background: #f8fafc;
      color: inherit;
      border-radius: 8px;
      padding: 6px 10px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
    }

    .rte-citations-btn:hover,
    .rte-citations-btn:focus-visible {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
    }

    .rte-citations-btn-primary {
      background: #1d4ed8;
      border-color: #1d4ed8;
      color: #ffffff;
    }

    .rte-citations-btn-primary:hover,
    .rte-citations-btn-primary:focus-visible {
      background: #1e40af;
      border-color: #1e40af;
    }

    .${m}.rte-citations-theme-dark .rte-citations-btn {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .${m}.rte-citations-theme-dark .rte-citations-btn-primary {
      border-color: #2563eb;
      background: #2563eb;
      color: #ffffff;
    }

    .rte-citations-recent {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 8px;
    }

    .${m}.rte-citations-theme-dark .rte-citations-recent {
      border-color: #334155;
    }

    .rte-citations-recent-heading {
      margin: 0 0 8px;
      font-size: 12px;
      font-weight: 700;
    }

    .rte-citations-recent-list {
      margin: 0;
      padding: 0;
      list-style: none;
      display: flex;
      flex-direction: column;
      gap: 6px;
      max-height: 170px;
      overflow: auto;
    }

    .rte-citations-recent-btn {
      width: 100%;
      text-align: left;
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: inherit;
      border-radius: 8px;
      padding: 7px;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      gap: 2px;
    }

    .rte-citations-recent-row {
      display: flex;
      gap: 6px;
      align-items: stretch;
    }

    .rte-citations-recent-delete {
      flex: 0 0 auto;
      border: 1px solid #fecaca;
      background: #fff1f2;
      color: #b91c1c;
      border-radius: 8px;
      padding: 0 8px;
      font-size: 11px;
      font-weight: 700;
      cursor: pointer;
      min-height: 34px;
    }

    .rte-citations-recent-delete:hover,
    .rte-citations-recent-delete:focus-visible {
      outline: none;
      border-color: #f87171;
      box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.2);
    }

    .rte-citations-recent-btn:focus-visible,
    .rte-citations-recent-btn:hover {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.18);
    }

    .${m}.rte-citations-theme-dark .rte-citations-recent-btn {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .${m}.rte-citations-theme-dark .rte-citations-recent-delete {
      border-color: #7f1d1d;
      background: #2b1218;
      color: #fca5a5;
    }

    .rte-citations-recent-title {
      font-size: 12px;
      font-weight: 700;
      line-height: 1.3;
    }

    .rte-citations-recent-meta {
      font-size: 11px;
      color: #64748b;
      line-height: 1.3;
    }

    .${m}.rte-citations-theme-dark .rte-citations-recent-meta {
      color: #94a3b8;
    }

    .rte-citations-empty {
      border: 1px dashed #cbd5e1;
      border-radius: 8px;
      padding: 8px;
      font-size: 12px;
      color: #64748b;
    }

    .${m}.rte-citations-theme-dark .rte-citations-empty {
      border-color: #334155;
      color: #94a3b8;
    }

    .rte-citations-shortcut {
      margin: 0;
      font-size: 11px;
      color: #64748b;
    }

    .${m}.rte-citations-theme-dark .rte-citations-shortcut {
      color: #94a3b8;
    }

    .rte-citations-live {
      position: absolute;
      width: 1px;
      height: 1px;
      margin: -1px;
      padding: 0;
      overflow: hidden;
      clip: rect(0 0 0 0);
      border: 0;
    }

    .rte-citation-ref {
      display: inline-flex;
      align-items: center;
      border-radius: 6px;
      border: 1px solid rgba(29, 78, 216, 0.24);
      background: rgba(29, 78, 216, 0.08);
      color: #1e3a8a;
      padding: 0 4px;
      margin: 0 1px;
      font-size: 0.92em;
      line-height: 1.35;
      white-space: nowrap;
      cursor: pointer;
      user-select: all;
    }

    .rte-citation-ref:focus,
    .rte-citation-ref:focus-visible {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.22);
    }

    .${x} .rte-citation-ref {
      border-color: rgba(96, 165, 250, 0.45);
      background: rgba(37, 99, 235, 0.22);
      color: #bfdbfe;
    }

    .rte-citation-bibliography,
    .rte-citation-footnotes {
      margin-top: 16px;
      border-top: 1px solid #d1d5db;
      padding-top: 10px;
    }

    .${x} .rte-citation-bibliography,
    .${x} .rte-citation-footnotes {
      border-top-color: #475569;
    }

    .rte-citation-section-title {
      margin: 0 0 8px;
      font-size: 1em;
      font-weight: 700;
    }

    .rte-citation-list {
      margin: 0;
      padding-left: 22px;
    }

    .rte-citation-item {
      margin: 0 0 8px;
      line-height: 1.45;
    }

    .rte-citation-backref {
      margin-left: 8px;
      color: #1d4ed8;
      text-decoration: none;
      font-size: 0.9em;
    }

    .rte-citation-backref:hover,
    .rte-citation-backref:focus-visible {
      text-decoration: underline;
      outline: none;
    }

    .${x} .rte-citation-backref {
      color: #93c5fd;
    }

    @media (max-width: 768px) {
      .${m} {
        left: 10px !important;
        right: 10px;
        top: 10px !important;
        width: auto !important;
        max-height: calc(100vh - 20px);
      }

      .rte-citations-grid {
        grid-template-columns: 1fr;
      }

      .rte-citations-recent-list {
        max-height: 34vh;
      }
    }
  `, document.head.appendChild(t);
}
const ue = (t = {}) => {
  const o = Z(t);
  return le(), {
    name: "citations",
    toolbar: [
      {
        id: "citationsGroup",
        label: "Citations",
        type: "group",
        command: "citations",
        items: [
          {
            id: "citations",
            label: "Citations",
            command: "toggleCitationsPanel",
            shortcut: "Mod-Alt-Shift-c",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M6 5h12M6 9h12M6 13h8M6 17h10" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M17 14.5a2.5 2.5 0 0 1 2.5 2.5v2H15v-2a2 2 0 0 1 2-2Z" stroke="currentColor" stroke-width="1.5"/></svg>'
          },
          {
            id: "citationsRefresh",
            label: "Refresh Citations",
            command: "refreshCitations",
            shortcut: "Mod-Alt-Shift-b",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M20 12a8 8 0 1 1-2.34-5.66" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M20 4v6h-6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          },
          {
            id: "citationsStyle",
            label: "Cycle Citation Style",
            command: "cycleCitationStyle",
            shortcut: "Mod-Alt-Shift-j",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M5 6h14M5 10h8M5 14h14M5 18h10" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><circle cx="18" cy="10" r="2" stroke="currentColor" stroke-width="1.6"/></svg>'
          }
        ]
      }
    ],
    commands: {
      citations: (e, i) => {
        const n = h(i);
        if (!n || S(n)) return !1;
        const r = f.get(n) || o;
        return f.set(n, r), T.set(n, N(n, r)), p = n, z(n), y(n, r, !1), !0;
      },
      toggleCitationsPanel: (e, i) => {
        const n = h(i);
        if (!n || S(n)) return !1;
        const r = f.get(n) || o;
        f.set(n, r), p = n;
        const a = It(n, typeof e == "boolean" ? e : void 0);
        return nt(n) && y(n, r, !1), a;
      },
      insertCitation: (e, i) => {
        const n = h(i);
        if (!n || S(n) || !e || typeof e != "object") return !1;
        const r = f.get(n) || o;
        f.set(n, r), p = n;
        const a = et(n, e, r);
        return a && z(n), a;
      },
      refreshCitations: (e, i) => {
        const n = h(i);
        if (!n) return !1;
        const r = f.get(n) || o;
        return f.set(n, r), p = n, y(n, r, !0), z(n), !0;
      },
      setCitationStyle: (e, i) => {
        const n = h(i);
        if (!n || !e) return !1;
        const r = f.get(n) || o;
        return f.set(n, r), p = n, zt(n, e, r), !0;
      },
      cycleCitationStyle: (e, i) => {
        const n = h(i);
        if (!n) return !1;
        const r = f.get(n) || o;
        return f.set(n, r), p = n, bt(n, r), H(n), !0;
      },
      getCitationRecords: (e, i) => {
        const n = h(i);
        if (!n) return !1;
        const r = f.get(n) || o, a = j(n, r);
        if (typeof e == "function")
          try {
            e(a);
          } catch (s) {
          }
        return n.__citationRecords = a, n.dispatchEvent(
          new CustomEvent("editora:citations-data", {
            bubbles: !0,
            detail: {
              records: a,
              style: N(n, r)
            }
          })
        ), !0;
      },
      setCitationsOptions: (e, i) => {
        const n = h(i);
        if (!n || !e || typeof e != "object") return !1;
        const r = f.get(n) || o, a = Z({
          ...r,
          ...e,
          labels: {
            ...r.labels,
            ...e.labels || {}
          },
          normalizeText: e.normalizeText || r.normalizeText,
          generateCitationId: e.generateCitationId || r.generateCitationId
        });
        return f.set(n, a), e.defaultStyle && L.includes(e.defaultStyle) && T.set(n, e.defaultStyle), y(n, a, !0), H(n), !0;
      },
      locateCitation: (e, i) => {
        const n = h(i);
        return !n || typeof e != "string" ? !1 : Qt(n, e);
      },
      deleteCitation: (e, i) => {
        const n = h(i);
        if (!n || S(n)) return !1;
        const r = f.get(n) || o;
        return f.set(n, r), typeof e == "string" && e.trim() ? Nt(n, e, r) : Zt(n, r);
      },
      insertRecentCitation: (e, i) => {
        const n = h(i);
        if (!n || S(n)) return !1;
        const r = f.get(n) || o;
        f.set(n, r);
        const a = j(n, r), s = rt(n, a, r);
        if (s.length === 0) return !1;
        const d = typeof e == "string" && e.trim() ? $t(n, e, a, r) : s[0];
        if (!d) return !1;
        const c = et(n, d, r);
        return c && z(n), c;
      }
    },
    keymap: {
      "Mod-Alt-Shift-c": "toggleCitationsPanel",
      "Mod-Alt-Shift-C": "toggleCitationsPanel",
      "Mod-Alt-Shift-b": "refreshCitations",
      "Mod-Alt-Shift-B": "refreshCitations",
      "Mod-Alt-Shift-j": "cycleCitationStyle",
      "Mod-Alt-Shift-J": "cycleCitationStyle"
    },
    init: function(i) {
      Y += 1;
      const n = this && typeof this.__pluginConfig == "object" ? Z({ ...o, ...this.__pluginConfig }) : o;
      se(n);
      const r = h(
        i && i.editorElement ? { editorElement: i.editorElement } : void 0,
        !1
      );
      r && (p = r, f.set(r, n), T.set(r, n.defaultStyle), it(r, "toggleCitationsPanel", !1), Tt(r));
    },
    destroy: () => {
      Y = Math.max(0, Y - 1), !(Y > 0) && (q.forEach((e) => {
        window.clearTimeout(e);
      }), q.clear(), ce());
    }
  };
};
export {
  ue as CitationsPlugin
};
//# sourceMappingURL=CitationsPlugin.native-DQgoCd1B.mjs.map
