const $ = ".rte-content, .editora-content", d = '[data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark', l = "rte-version-diff-overlay", U = "rte-version-diff-styles", ae = {
  title: "Version Diff",
  baseline: "Baseline",
  current: "Current",
  noChanges: "No changes detected between baseline and current content.",
  loading: "Preparing diff...",
  tabInline: "Inline Diff",
  tabSideBySide: "Side by Side",
  refresh: "Refresh",
  setBaseline: "Set Current as Baseline",
  close: "Close",
  mode: "Mode",
  ignoreWhitespace: "Ignore whitespace",
  largeDocFallback: "Large document fallback mode applied for performance."
}, w = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap();
let j = 0, H = null, z = null, V = null, S = null, M = null, D = null;
function u(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function le(e) {
  return {
    ...ae,
    ...e || {}
  };
}
function N(e, i = !0) {
  if (e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const t = e.editorElement;
    if (t.matches($)) return t;
    const o = t.querySelector($);
    if (o instanceof HTMLElement) return o;
  }
  const n = window.getSelection();
  if (n && n.rangeCount > 0) {
    const t = n.getRangeAt(0).startContainer, f = (t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement)?.closest($);
    if (f) return f;
  }
  const r = document.activeElement;
  if (r) {
    if (r.matches($)) return r;
    const t = r.closest($);
    if (t) return t;
  }
  return D && D.isConnected ? D : i ? document.querySelector($) : null;
}
function O(e) {
  return e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || e;
}
function P(e) {
  if (!e) return !1;
  const i = e.getAttribute("data-theme") || e.getAttribute("theme");
  if (i && i.toLowerCase() === "dark") return !0;
  const n = e.classList;
  return n.contains("dark") || n.contains("editora-theme-dark") || n.contains("rte-theme-dark");
}
function Y(e) {
  const i = O(e);
  if (P(i)) return !0;
  const n = i.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return !!(P(n) || P(document.documentElement) || P(document.body));
}
function fe(e) {
  const i = document.createElement("textarea");
  return i.innerHTML = e, i.value;
}
function W(e) {
  const n = O(e).getAttribute("data-initial-content");
  return n ? fe(n) : e.innerHTML;
}
function Z(e) {
  return e.replace(/\r\n?/g, `
`);
}
function J(e) {
  const i = document.createElement("div"), n = e.replace(/<br\s*\/?>/gi, `
`).replace(/<\/(p|div|h1|h2|h3|h4|h5|h6|li|tr|blockquote|pre|section|article)>/gi, `$&
`);
  i.innerHTML = n;
  const r = i.textContent || "";
  return Z(r).replace(/\u00a0/g, " ").replace(/\n{3,}/g, `

`).trim();
}
function Q(e, i, n) {
  let r = Z(e);
  if (n && (r = r.replace(/[ \t]+/g, " ").replace(/\n{3,}/g, `

`).trim()), !r) return [];
  if (i === "line")
    return r.split(`
`);
  if (n)
    return r.split(/\s+/).filter(Boolean);
  const t = [], o = r.split(`
`);
  return o.forEach((f, g) => {
    const c = f.split(/[ \t]+/).filter(Boolean);
    t.push(...c), g < o.length - 1 && t.push(`
`);
  }), t;
}
function de(e, i, n) {
  if (e.length === 0) return "";
  if (i === "line") return e.join(`
`);
  if (n) return e.join(" ");
  let r = "";
  for (let t = 0; t < e.length; t += 1) {
    const o = e[t];
    if (o === `
`) {
      r = r.replace(/[ \t]+$/g, ""), r += `
`;
      continue;
    }
    r.length > 0 && !r.endsWith(`
`) && (r += " "), r += o;
  }
  return r;
}
function ce(e, i, n) {
  const r = [];
  return e.forEach((t) => {
    const o = r[r.length - 1];
    if (o && o.type === t.type) {
      o.tokens.push(t.token);
      return;
    }
    r.push({ type: t.type, tokens: [t.token] });
  }), r.map((t) => ({
    type: t.type,
    value: de(t.tokens, i, n),
    count: t.tokens.length
  }));
}
function ue(e, i) {
  let n = 0;
  for (; n < e.length && n < i.length && e[n] === i[n]; )
    n += 1;
  let r = e.length - 1, t = i.length - 1;
  for (; r >= n && t >= n && e[r] === i[t]; )
    r -= 1, t -= 1;
  const o = e.slice(0, n), f = r < e.length - 1 ? e.slice(r + 1) : [], g = n <= r ? e.slice(n, r + 1) : [], c = n <= t ? i.slice(n, t + 1) : [];
  return { prefix: o, suffix: f, aMiddle: g, bMiddle: c };
}
function pe(e, i, n, r, t, o) {
  if (e.length === 0 && i.length === 0)
    return { segments: [], insertedCount: 0, deletedCount: 0, equalCount: 0, usedFallback: !1 };
  const { prefix: f, suffix: g, aMiddle: c, bMiddle: b } = ue(e, i);
  let v = [];
  f.forEach((a) => v.push({ type: "equal", token: a }));
  const F = c.length * b.length, T = c.length > o || b.length > o || F > t;
  if (T)
    c.forEach((a) => v.push({ type: "delete", token: a })), b.forEach((a) => v.push({ type: "insert", token: a }));
  else {
    const a = Array.from({ length: c.length + 1 }, () => new Uint32Array(b.length + 1));
    for (let y = c.length - 1; y >= 0; y -= 1) {
      const B = a[y], I = a[y + 1];
      for (let x = b.length - 1; x >= 0; x -= 1)
        B[x] = c[y] === b[x] ? I[x + 1] + 1 : Math.max(I[x], B[x + 1]);
    }
    let h = 0, p = 0;
    for (; h < c.length && p < b.length; )
      c[h] === b[p] ? (v.push({ type: "equal", token: c[h] }), h += 1, p += 1) : a[h + 1][p] >= a[h][p + 1] ? (v.push({ type: "delete", token: c[h] }), h += 1) : (v.push({ type: "insert", token: b[p] }), p += 1);
    for (; h < c.length; )
      v.push({ type: "delete", token: c[h] }), h += 1;
    for (; p < b.length; )
      v.push({ type: "insert", token: b[p] }), p += 1;
  }
  g.forEach((a) => v.push({ type: "equal", token: a }));
  const q = ce(v, n, r);
  let A = 0, L = 0, K = 0;
  return q.forEach((a) => {
    a.type === "insert" && (A += a.count), a.type === "delete" && (L += a.count), a.type === "equal" && (K += a.count);
  }), {
    segments: q,
    insertedCount: A,
    deletedCount: L,
    equalCount: K,
    usedFallback: T
  };
}
function ee(e) {
  return u(e.value).replace(/\n/g, `
`);
}
function be(e, i) {
  return e.length === 0 ? `<p class="rte-version-diff-empty">${u(i.noChanges)}</p>` : e.map((n) => `<span class="${n.type === "equal" ? "rte-version-diff-equal" : n.type === "insert" ? "rte-version-diff-insert" : "rte-version-diff-delete"}">${ee(n)}</span>`).join("");
}
function he(e, i) {
  if (e.length === 0) {
    const t = `<p class="rte-version-diff-empty">${u(i.noChanges)}</p>`;
    return { baselineHtml: t, currentHtml: t };
  }
  const n = [], r = [];
  return e.forEach((t) => {
    const o = ee(t);
    if (t.type === "equal") {
      n.push(`<span class="rte-version-diff-equal">${o}</span>`), r.push(`<span class="rte-version-diff-equal">${o}</span>`);
      return;
    }
    if (t.type === "delete") {
      n.push(`<span class="rte-version-diff-delete">${o}</span>`);
      return;
    }
    r.push(`<span class="rte-version-diff-insert">${o}</span>`);
  }), {
    baselineHtml: n.join(""),
    currentHtml: r.join("")
  };
}
function me(e) {
  const i = e.metaKey || e.ctrlKey, r = (typeof e.key == "string" ? e.key : "").toLowerCase(), t = typeof e.code == "string" ? e.code.toLowerCase() : "", o = i && e.altKey && !e.shiftKey && (r === "d" || t === "keyd"), f = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (r === "f8" || t === "f8");
  return o || f;
}
function ve() {
  if (typeof document > "u" || document.getElementById(U)) return;
  const e = document.createElement("style");
  e.id = U, e.textContent = `
    .${l} {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.55);
      z-index: 2147483646;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }

    .rte-version-diff-dialog {
      width: min(980px, 96vw);
      max-height: min(90vh, 860px);
      background: #ffffff;
      color: #0f172a;
      border: 1px solid #d7dee8;
      border-radius: 8px;
      display: flex;
      flex-direction: column;
      box-shadow: 0 24px 48px rgba(15, 23, 42, 0.3);
      overflow: hidden;
    }

    .rte-version-diff-header,
    .rte-version-diff-footer {
      padding: 12px 14px;
      border-bottom: 1px solid #e2e8f0;
      background: #f8fafc;
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
    }

    .rte-version-diff-footer {
      border-top: 1px solid #e2e8f0;
      border-bottom: none;
      justify-content: space-between;
    }

    .rte-version-diff-title {
      margin: 0;
      font-size: 16px;
      font-weight: 700;
      flex: 1;
    }

    .rte-version-diff-controls {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
    }

    .rte-version-diff-select,
    .rte-version-diff-btn {
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: #0f172a;
      border-radius: 6px;
      min-height: 34px;
      padding: 6px 10px;
      font-size: 13px;
      cursor: pointer;
    }

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

    .rte-version-diff-btn-primary {
      background: #2563eb;
      border-color: #2563eb;
      color: #ffffff;
    }

    .rte-version-diff-btn-primary:hover {
      background: #1d4ed8;
    }

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

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

    .rte-version-diff-tabs {
      display: flex;
      gap: 6px;
      border-bottom: 1px solid #e2e8f0;
      background: #f8fafc;
      padding: 8px 14px;
    }

    .rte-version-diff-tab {
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: #0f172a;
      border-radius: 6px;
      min-height: 32px;
      padding: 4px 10px;
      font-size: 13px;
      cursor: pointer;
    }

    .rte-version-diff-tab[aria-selected="true"] {
      background: #dbeafe;
      border-color: #60a5fa;
      color: #1e3a8a;
    }

    .rte-version-diff-body {
      flex: 1;
      overflow: auto;
      padding: 10px 14px 14px;
      background: #ffffff;
    }

    .rte-version-diff-summary {
      font-size: 12px;
      color: #475569;
      margin-bottom: 10px;
      display: flex;
      gap: 14px;
      flex-wrap: wrap;
    }

    .rte-version-diff-panel {
      display: none;
    }

    .rte-version-diff-panel.active {
      display: block;
    }

    .rte-version-diff-inline,
    .rte-version-diff-side-pane {
      border: 1px solid #dbe3ec;
      border-radius: 6px;
      padding: 10px;
      min-height: 140px;
      max-height: 50vh;
      overflow: auto;
      white-space: pre-wrap;
      word-break: break-word;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      font-size: 12px;
      line-height: 1.5;
      background: #ffffff;
    }

    .rte-version-diff-side-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }

    .rte-version-diff-pane-title {
      margin: 0 0 6px;
      font-size: 12px;
      font-weight: 700;
      color: #334155;
    }

    .rte-version-diff-equal { color: inherit; }
    .rte-version-diff-insert {
      background: rgba(22, 163, 74, 0.18);
      color: #14532d;
      border-radius: 2px;
    }
    .rte-version-diff-delete {
      background: rgba(220, 38, 38, 0.18);
      color: #7f1d1d;
      text-decoration: line-through;
      border-radius: 2px;
    }

    .rte-version-diff-empty {
      margin: 0;
      color: #64748b;
      font-size: 13px;
    }

    ${d} .rte-version-diff-dialog,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-dialog {
      background: #1f2937;
      color: #e5e7eb;
      border-color: #334155;
    }

    ${d} .rte-version-diff-header,
    ${d} .rte-version-diff-footer,
    ${d} .rte-version-diff-tabs,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-header,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-footer,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-tabs {
      background: #111827;
      border-color: #334155;
    }

    ${d} .rte-version-diff-body,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-body {
      background: #1f2937;
    }

    ${d} .rte-version-diff-select,
    ${d} .rte-version-diff-btn,
    ${d} .rte-version-diff-tab,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-select,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-btn,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-tab {
      background: #0f172a;
      color: #e5e7eb;
      border-color: #475569;
    }

    ${d} .rte-version-diff-close-btn,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-close-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    ${d} .rte-version-diff-close-btn:hover,
    ${d} .rte-version-diff-close-btn:focus-visible,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-close-btn:hover,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-close-btn:focus-visible {
      border-color: #60a5fa;
      box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.24);
      outline: none;
    }

    ${d} .rte-version-diff-tab[aria-selected="true"],
    .${l}.rte-version-diff-theme-dark .rte-version-diff-tab[aria-selected="true"] {
      background: #1e3a8a;
      border-color: #3b82f6;
      color: #dbeafe;
    }

    ${d} .rte-version-diff-inline,
    ${d} .rte-version-diff-side-pane,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-inline,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-side-pane {
      background: #0f172a;
      border-color: #334155;
      color: #e5e7eb;
    }

    ${d} .rte-version-diff-pane-title,
    ${d} .rte-version-diff-summary,
    ${d} .rte-version-diff-empty,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-pane-title,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-summary,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-empty {
      color: #94a3b8;
    }

    ${d} .rte-version-diff-insert,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-insert {
      background: rgba(22, 163, 74, 0.25);
      color: #bbf7d0;
    }

    ${d} .rte-version-diff-delete,
    .${l}.rte-version-diff-theme-dark .rte-version-diff-delete {
      background: rgba(220, 38, 38, 0.25);
      color: #fecaca;
    }
    :is(${d}) .rte-toolbar-item .rte-toolbar-button[data-command="openVersionDiff"] svg{
      fill: none;
    }
  `, document.head.appendChild(e);
}
async function ge(e, i, n) {
  if (n != null) return n;
  if (typeof i.getBaselineHtml == "function") {
    const o = O(e), f = await Promise.resolve(i.getBaselineHtml({ editor: e, editorRoot: o }));
    if (typeof f == "string") return f;
  }
  const r = w.get(e);
  if (typeof r == "string") return r;
  if (typeof i.baselineHtml == "string") return i.baselineHtml;
  const t = W(e);
  return w.set(e, t), t;
}
function ye(e) {
  e.querySelector(
    'button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
  )?.focus();
}
function xe(e, i) {
  if (e.key !== "Tab") return;
  const n = Array.from(i.querySelectorAll(
    'button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
  )).filter((f) => !f.hasAttribute("disabled"));
  if (n.length === 0) return;
  const r = n[0], t = n[n.length - 1], o = document.activeElement;
  e.shiftKey && o === r ? (e.preventDefault(), t.focus()) : !e.shiftKey && o === t && (e.preventDefault(), r.focus());
}
function te() {
  z && (z(), z = null);
}
function X(e) {
  !e || w.has(e) || w.set(e, W(e));
}
function ke(e) {
  return {
    baselineHtml: e.baselineHtml,
    getBaselineHtml: e.getBaselineHtml,
    mode: e.mode || "word",
    ignoreWhitespace: e.ignoreWhitespace !== !1,
    maxTokens: Math.max(200, e.maxTokens ?? 1200),
    maxMatrixSize: Math.max(5e4, e.maxMatrixSize ?? 1e6),
    labels: le(e.labels)
  };
}
function re(e, i, n) {
  te(), D = e, R.set(e, i);
  const r = document.createElement("div");
  r.className = l, Y(e) && r.classList.add("rte-version-diff-theme-dark");
  const t = document.createElement("section");
  t.className = "rte-version-diff-dialog", t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "true"), t.setAttribute("aria-labelledby", "rte-version-diff-title");
  const o = i.labels;
  let f = n?.mode || i.mode, g = n?.ignoreWhitespace ?? i.ignoreWhitespace, c = "inline";
  t.innerHTML = `
    <header class="rte-version-diff-header">
      <h2 id="rte-version-diff-title" class="rte-version-diff-title">${u(o.title)}</h2>
      <div class="rte-version-diff-controls">
        <label>
          <span>${u(o.mode)}:</span>
          <select class="rte-version-diff-select" aria-label="${u(o.mode)}">
            <option value="word">Word</option>
            <option value="line">Line</option>
          </select>
        </label>
        <label class="rte-version-diff-checkbox">
          <input type="checkbox" class="rte-version-diff-ignore-ws" ${g ? "checked" : ""}>
          ${u(o.ignoreWhitespace)}
        </label>
        <button type="button" class="rte-version-diff-btn rte-version-diff-set-baseline" aria-label="${u(o.setBaseline)}">${u(o.setBaseline)}</button>
        <button type="button" class="rte-version-diff-btn" data-action="refresh" aria-label="${u(o.refresh)}">${u(o.refresh)}</button>
        <button type="button" class="rte-version-diff-btn rte-version-diff-close-btn" data-action="close" aria-label="${u(o.close)}">✕</button>
      </div>
    </header>

    <div class="rte-version-diff-tabs" role="tablist" aria-label="Diff views">
      <button type="button" role="tab" class="rte-version-diff-tab" data-tab="inline" aria-selected="true">${u(o.tabInline)}</button>
      <button type="button" role="tab" class="rte-version-diff-tab" data-tab="side" aria-selected="false">${u(o.tabSideBySide)}</button>
    </div>

    <main class="rte-version-diff-body">
      <div class="rte-version-diff-summary" aria-live="polite"></div>
      <section class="rte-version-diff-panel active" data-panel="inline" role="tabpanel">
        <div class="rte-version-diff-inline" aria-label="Inline diff result"></div>
      </section>
      <section class="rte-version-diff-panel" data-panel="side" role="tabpanel">
        <div class="rte-version-diff-side-grid">
          <div>
            <h3 class="rte-version-diff-pane-title">${u(o.baseline)}</h3>
            <div class="rte-version-diff-side-pane" data-side="baseline" aria-label="${u(o.baseline)}"></div>
          </div>
          <div>
            <h3 class="rte-version-diff-pane-title">${u(o.current)}</h3>
            <div class="rte-version-diff-side-pane" data-side="current" aria-label="${u(o.current)}"></div>
          </div>
        </div>
      </section>
    </main>

    <footer class="rte-version-diff-footer">
      <small>Shortcut: Ctrl/Cmd + Alt + D (fallback: F8)</small>
      <small>Esc: close</small>
    </footer>
  `, r.appendChild(t), document.body.appendChild(r);
  const b = t.querySelector(".rte-version-diff-select");
  b.value = f;
  const v = t.querySelector(".rte-version-diff-ignore-ws"), F = t.querySelector(".rte-version-diff-summary"), T = t.querySelector(".rte-version-diff-inline"), q = t.querySelector('[data-side="baseline"]'), A = t.querySelector('[data-side="current"]');
  let L = 0;
  const K = () => {
    const s = `<p class="rte-version-diff-empty">${u(o.loading)}</p>`;
    T.innerHTML = s, q.innerHTML = s, A.innerHTML = s, F.textContent = "";
  }, a = async (s) => {
    L += 1;
    const m = L;
    r.classList.toggle("rte-version-diff-theme-dark", Y(e)), K();
    const k = e.innerHTML;
    let E = "";
    try {
      E = await ge(e, i, s ?? n?.baselineHtml);
    } catch {
      E = w.get(e) ?? W(e);
    }
    if (m !== L || !r.isConnected) return;
    const ne = J(E), ie = J(k), oe = Q(ne, f, g), se = Q(ie, f, g), C = pe(
      oe,
      se,
      f,
      g,
      i.maxMatrixSize,
      i.maxTokens
    ), _ = he(C.segments, o);
    T.innerHTML = be(C.segments, o), q.innerHTML = _.baselineHtml, A.innerHTML = _.currentHtml;
    const G = [
      `+${C.insertedCount} inserted`,
      `-${C.deletedCount} deleted`,
      `${C.equalCount} unchanged`
    ];
    C.usedFallback && G.push(o.largeDocFallback), F.textContent = G.join(" | ");
  }, h = (s) => {
    c = s, t.querySelectorAll(".rte-version-diff-tab").forEach((m) => {
      const k = m.getAttribute("data-tab") === s;
      m.setAttribute("aria-selected", k ? "true" : "false"), m.tabIndex = k ? 0 : -1;
    }), t.querySelectorAll(".rte-version-diff-panel").forEach((m) => {
      m.classList.toggle("active", m.getAttribute("data-panel") === s);
    });
  }, p = () => {
    r.removeEventListener("keydown", I, !0), r.removeEventListener("click", B), document.removeEventListener("keydown", y, !0), r.parentNode && r.parentNode.removeChild(r), z = null, e.focus({ preventScroll: !0 });
  }, y = (s) => {
    s.key === "Escape" && (s.preventDefault(), s.stopPropagation(), p());
  }, B = (s) => {
    s.target === r && p();
  }, I = (s) => {
    if (s.key === "Escape") {
      s.preventDefault(), p();
      return;
    }
    if (xe(s, t), s.target && s.target.classList.contains("rte-version-diff-tab") && (s.key === "ArrowRight" || s.key === "ArrowLeft")) {
      s.preventDefault();
      const m = c === "inline" ? "side" : "inline";
      h(m), t.querySelector(`.rte-version-diff-tab[data-tab="${m}"]`)?.focus();
    }
  };
  t.addEventListener("click", (s) => {
    const m = s.target, k = m.getAttribute("data-action");
    if (k === "close") {
      p();
      return;
    }
    if (k === "refresh") {
      a();
      return;
    }
    const E = m.getAttribute("data-tab");
    (E === "inline" || E === "side") && h(E);
  }), b.addEventListener("change", () => {
    f = b.value === "line" ? "line" : "word", a();
  }), v.addEventListener("change", () => {
    g = v.checked, a();
  }), t.querySelector(".rte-version-diff-set-baseline").addEventListener("click", () => {
    w.set(e, e.innerHTML), a(e.innerHTML);
  }), r.addEventListener("keydown", I, !0), r.addEventListener("click", B), document.addEventListener("keydown", y, !0), z = p, ye(t), a();
}
function $e(e) {
  V = e, !H && (H = (i) => {
    if (!me(i)) return;
    if (document.querySelector(`.${l}`)) {
      i.preventDefault();
      return;
    }
    if (!!i.target?.closest("input, textarea, select")) return;
    const t = N(void 0, !1);
    if (!t || t.getAttribute("contenteditable") === "false") return;
    i.preventDefault(), i.stopPropagation();
    const o = R.get(t) || V || e;
    re(t, o);
  }, document.addEventListener("keydown", H, !0));
}
function Ee() {
  H && (document.removeEventListener("keydown", H, !0), H = null, V = null);
}
function we() {
  S || (S = (e) => {
    const n = e.target?.closest($);
    n && (D = n, X(n));
  }, document.addEventListener("focusin", S, !0)), M || (M = (e) => {
    const r = e.target?.closest($);
    r && r.getAttribute("contenteditable") !== "false" && (D = r, X(r));
  }, document.addEventListener("beforeinput", M, !0));
}
function Le() {
  S && (document.removeEventListener("focusin", S, !0), S = null), M && (document.removeEventListener("beforeinput", M, !0), M = null);
}
const Ce = (e = {}) => {
  const i = ke(e);
  return ve(), {
    name: "versionDiff",
    toolbar: [
      {
        id: "versionDiff",
        label: "Version Diff",
        command: "openVersionDiff",
        icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="3.5" y="4.5" width="7" height="15" rx="1.5" stroke="currentColor" stroke-width="1.8"></rect><rect x="13.5" y="4.5" width="7" height="15" rx="1.5" stroke="currentColor" stroke-width="1.8"></rect><path d="M5.5 12h3" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"></path><path d="M15.5 12h3m-1.5-1.5v3" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"></path></svg>'
      }
    ],
    commands: {
      openVersionDiff: (n, r) => {
        const t = N(r);
        return t ? (R.set(t, i), re(t, i, n), !0) : !1;
      },
      setVersionDiffBaseline: (n, r) => {
        const t = N(r);
        if (!t) return !1;
        R.set(t, i);
        const o = typeof n == "string" ? n : typeof n?.html == "string" ? n.html : t.innerHTML;
        return w.set(t, o), !0;
      }
    },
    keymap: {
      "Mod-Alt-d": "openVersionDiff",
      "Mod-Alt-D": "openVersionDiff",
      F8: "openVersionDiff"
    },
    init: () => {
      j += 1, $e(i), we();
    },
    destroy: () => {
      j = Math.max(0, j - 1), j === 0 && (te(), Ee(), Le());
    }
  };
};
export {
  Ce as VersionDiffPlugin
};
