const $ = ".rte-content, .editora-content", d = '[data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark', l = "rte-version-diff-overlay", J = "rte-version-diff-styles", fe = {
  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 de(e) {
  return {
    ...fe,
    ...e || {}
  };
}
function N(e, i = !0) {
  if ((e == null ? void 0 : e.contentElement) instanceof HTMLElement) return e.contentElement;
  if ((e == null ? void 0 : e.editorElement) instanceof HTMLElement) {
    const r = e.editorElement;
    if (r.matches($)) return r;
    const o = r.querySelector($);
    if (o instanceof HTMLElement) return o;
  }
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    const r = t.getRangeAt(0).startContainer, o = r.nodeType === Node.ELEMENT_NODE ? r : r.parentElement, f = o == null ? void 0 : o.closest($);
    if (f) return f;
  }
  const n = document.activeElement;
  if (n) {
    if (n.matches($)) return n;
    const r = n.closest($);
    if (r) return r;
  }
  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 t = e.classList;
  return t.contains("dark") || t.contains("editora-theme-dark") || t.contains("rte-theme-dark");
}
function Q(e) {
  const i = O(e);
  if (P(i)) return !0;
  const t = i.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return !!(P(t) || P(document.documentElement) || P(document.body));
}
function ce(e) {
  const i = document.createElement("textarea");
  return i.innerHTML = e, i.value;
}
function W(e) {
  const t = O(e).getAttribute("data-initial-content");
  return t ? ce(t) : e.innerHTML;
}
function te(e) {
  return e.replace(/\r\n?/g, `
`);
}
function X(e) {
  const i = document.createElement("div"), t = e.replace(/<br\s*\/?>/gi, `
`).replace(/<\/(p|div|h1|h2|h3|h4|h5|h6|li|tr|blockquote|pre|section|article)>/gi, `$&
`);
  i.innerHTML = t;
  const n = i.textContent || "";
  return te(n).replace(/\u00a0/g, " ").replace(/\n{3,}/g, `

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

`).trim()), !n) return [];
  if (i === "line")
    return n.split(`
`);
  if (t)
    return n.split(/\s+/).filter(Boolean);
  const r = [], o = n.split(`
`);
  return o.forEach((f, g) => {
    const c = f.split(/[ \t]+/).filter(Boolean);
    r.push(...c), g < o.length - 1 && r.push(`
`);
  }), r;
}
function ue(e, i, t) {
  if (e.length === 0) return "";
  if (i === "line") return e.join(`
`);
  if (t) return e.join(" ");
  let n = "";
  for (let r = 0; r < e.length; r += 1) {
    const o = e[r];
    if (o === `
`) {
      n = n.replace(/[ \t]+$/g, ""), n += `
`;
      continue;
    }
    n.length > 0 && !n.endsWith(`
`) && (n += " "), n += o;
  }
  return n;
}
function pe(e, i, t) {
  const n = [];
  return e.forEach((r) => {
    const o = n[n.length - 1];
    if (o && o.type === r.type) {
      o.tokens.push(r.token);
      return;
    }
    n.push({ type: r.type, tokens: [r.token] });
  }), n.map((r) => ({
    type: r.type,
    value: ue(r.tokens, i, t),
    count: r.tokens.length
  }));
}
function be(e, i) {
  let t = 0;
  for (; t < e.length && t < i.length && e[t] === i[t]; )
    t += 1;
  let n = e.length - 1, r = i.length - 1;
  for (; n >= t && r >= t && e[n] === i[r]; )
    n -= 1, r -= 1;
  const o = e.slice(0, t), f = n < e.length - 1 ? e.slice(n + 1) : [], g = t <= n ? e.slice(t, n + 1) : [], c = t <= r ? i.slice(t, r + 1) : [];
  return { prefix: o, suffix: f, aMiddle: g, bMiddle: c };
}
function he(e, i, t, n, r, 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 } = be(e, i);
  let m = [];
  f.forEach((a) => m.push({ type: "equal", token: a }));
  const F = c.length * b.length, T = c.length > o || b.length > o || F > r;
  if (T)
    c.forEach((a) => m.push({ type: "delete", token: a })), b.forEach((a) => m.push({ type: "insert", token: a }));
  else {
    const a = Array.from({ length: c.length + 1 }, () => new Uint32Array(b.length + 1));
    for (let k = c.length - 1; k >= 0; k -= 1) {
      const A = a[k], I = a[k + 1];
      for (let x = b.length - 1; x >= 0; x -= 1)
        A[x] = c[k] === b[x] ? I[x + 1] + 1 : Math.max(I[x], A[x + 1]);
    }
    let h = 0, p = 0;
    for (; h < c.length && p < b.length; )
      c[h] === b[p] ? (m.push({ type: "equal", token: c[h] }), h += 1, p += 1) : a[h + 1][p] >= a[h][p + 1] ? (m.push({ type: "delete", token: c[h] }), h += 1) : (m.push({ type: "insert", token: b[p] }), p += 1);
    for (; h < c.length; )
      m.push({ type: "delete", token: c[h] }), h += 1;
    for (; p < b.length; )
      m.push({ type: "insert", token: b[p] }), p += 1;
  }
  g.forEach((a) => m.push({ type: "equal", token: a }));
  const q = pe(m, t, n);
  let B = 0, L = 0, K = 0;
  return q.forEach((a) => {
    a.type === "insert" && (B += a.count), a.type === "delete" && (L += a.count), a.type === "equal" && (K += a.count);
  }), {
    segments: q,
    insertedCount: B,
    deletedCount: L,
    equalCount: K,
    usedFallback: T
  };
}
function re(e) {
  return u(e.value).replace(/\n/g, `
`);
}
function ve(e, i) {
  return e.length === 0 ? `<p class="rte-version-diff-empty">${u(i.noChanges)}</p>` : e.map((t) => `<span class="${t.type === "equal" ? "rte-version-diff-equal" : t.type === "insert" ? "rte-version-diff-insert" : "rte-version-diff-delete"}">${re(t)}</span>`).join("");
}
function me(e, i) {
  if (e.length === 0) {
    const r = `<p class="rte-version-diff-empty">${u(i.noChanges)}</p>`;
    return { baselineHtml: r, currentHtml: r };
  }
  const t = [], n = [];
  return e.forEach((r) => {
    const o = re(r);
    if (r.type === "equal") {
      t.push(`<span class="rte-version-diff-equal">${o}</span>`), n.push(`<span class="rte-version-diff-equal">${o}</span>`);
      return;
    }
    if (r.type === "delete") {
      t.push(`<span class="rte-version-diff-delete">${o}</span>`);
      return;
    }
    n.push(`<span class="rte-version-diff-insert">${o}</span>`);
  }), {
    baselineHtml: t.join(""),
    currentHtml: n.join("")
  };
}
function ge(e) {
  const i = e.metaKey || e.ctrlKey, n = (typeof e.key == "string" ? e.key : "").toLowerCase(), r = typeof e.code == "string" ? e.code.toLowerCase() : "", o = i && e.altKey && !e.shiftKey && (n === "d" || r === "keyd"), f = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (n === "f8" || r === "f8");
  return o || f;
}
function ye() {
  if (typeof document == "undefined" || document.getElementById(J)) return;
  const e = document.createElement("style");
  e.id = J, 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 ke(e, i, t) {
  if (t != null) return t;
  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 n = w.get(e);
  if (typeof n == "string") return n;
  if (typeof i.baselineHtml == "string") return i.baselineHtml;
  const r = W(e);
  return w.set(e, r), r;
}
function xe(e) {
  const i = e.querySelector(
    'button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
  );
  i == null || i.focus();
}
function $e(e, i) {
  if (e.key !== "Tab") return;
  const t = 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 (t.length === 0) return;
  const n = t[0], r = t[t.length - 1], o = document.activeElement;
  e.shiftKey && o === n ? (e.preventDefault(), r.focus()) : !e.shiftKey && o === r && (e.preventDefault(), n.focus());
}
function ne() {
  z && (z(), z = null);
}
function ee(e) {
  !e || w.has(e) || w.set(e, W(e));
}
function Ee(e) {
  var i, t;
  return {
    baselineHtml: e.baselineHtml,
    getBaselineHtml: e.getBaselineHtml,
    mode: e.mode || "word",
    ignoreWhitespace: e.ignoreWhitespace !== !1,
    maxTokens: Math.max(200, (i = e.maxTokens) != null ? i : 1200),
    maxMatrixSize: Math.max(5e4, (t = e.maxMatrixSize) != null ? t : 1e6),
    labels: de(e.labels)
  };
}
function ie(e, i, t) {
  var _;
  ne(), D = e, R.set(e, i);
  const n = document.createElement("div");
  n.className = l, Q(e) && n.classList.add("rte-version-diff-theme-dark");
  const r = document.createElement("section");
  r.className = "rte-version-diff-dialog", r.setAttribute("role", "dialog"), r.setAttribute("aria-modal", "true"), r.setAttribute("aria-labelledby", "rte-version-diff-title");
  const o = i.labels;
  let f = (t == null ? void 0 : t.mode) || i.mode, g = (_ = t == null ? void 0 : t.ignoreWhitespace) != null ? _ : i.ignoreWhitespace, c = "inline";
  r.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>
  `, n.appendChild(r), document.body.appendChild(n);
  const b = r.querySelector(".rte-version-diff-select");
  b.value = f;
  const m = r.querySelector(".rte-version-diff-ignore-ws"), F = r.querySelector(".rte-version-diff-summary"), T = r.querySelector(".rte-version-diff-inline"), q = r.querySelector('[data-side="baseline"]'), B = r.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, B.innerHTML = s, F.textContent = "";
  }, a = async (s) => {
    var Y;
    L += 1;
    const v = L;
    n.classList.toggle("rte-version-diff-theme-dark", Q(e)), K();
    const y = e.innerHTML;
    let E = "";
    try {
      E = await ke(e, i, s != null ? s : t == null ? void 0 : t.baselineHtml);
    } catch (Se) {
      E = (Y = w.get(e)) != null ? Y : W(e);
    }
    if (v !== L || !n.isConnected) return;
    const oe = X(E), se = X(y), ae = Z(oe, f, g), le = Z(se, f, g), C = he(
      ae,
      le,
      f,
      g,
      i.maxMatrixSize,
      i.maxTokens
    ), G = me(C.segments, o);
    T.innerHTML = ve(C.segments, o), q.innerHTML = G.baselineHtml, B.innerHTML = G.currentHtml;
    const U = [
      `+${C.insertedCount} inserted`,
      `-${C.deletedCount} deleted`,
      `${C.equalCount} unchanged`
    ];
    C.usedFallback && U.push(o.largeDocFallback), F.textContent = U.join(" | ");
  }, h = (s) => {
    c = s, r.querySelectorAll(".rte-version-diff-tab").forEach((v) => {
      const y = v.getAttribute("data-tab") === s;
      v.setAttribute("aria-selected", y ? "true" : "false"), v.tabIndex = y ? 0 : -1;
    }), r.querySelectorAll(".rte-version-diff-panel").forEach((v) => {
      v.classList.toggle("active", v.getAttribute("data-panel") === s);
    });
  }, p = () => {
    n.removeEventListener("keydown", I, !0), n.removeEventListener("click", A), document.removeEventListener("keydown", k, !0), n.parentNode && n.parentNode.removeChild(n), z = null, e.focus({ preventScroll: !0 });
  }, k = (s) => {
    s.key === "Escape" && (s.preventDefault(), s.stopPropagation(), p());
  }, A = (s) => {
    s.target === n && p();
  }, I = (s) => {
    if (s.key === "Escape") {
      s.preventDefault(), p();
      return;
    }
    if ($e(s, r), s.target && s.target.classList.contains("rte-version-diff-tab") && (s.key === "ArrowRight" || s.key === "ArrowLeft")) {
      s.preventDefault();
      const v = c === "inline" ? "side" : "inline";
      h(v);
      const y = r.querySelector(`.rte-version-diff-tab[data-tab="${v}"]`);
      y == null || y.focus();
    }
  };
  r.addEventListener("click", (s) => {
    const v = s.target, y = v.getAttribute("data-action");
    if (y === "close") {
      p();
      return;
    }
    if (y === "refresh") {
      a();
      return;
    }
    const E = v.getAttribute("data-tab");
    (E === "inline" || E === "side") && h(E);
  }), b.addEventListener("change", () => {
    f = b.value === "line" ? "line" : "word", a();
  }), m.addEventListener("change", () => {
    g = m.checked, a();
  }), r.querySelector(".rte-version-diff-set-baseline").addEventListener("click", () => {
    w.set(e, e.innerHTML), a(e.innerHTML);
  }), n.addEventListener("keydown", I, !0), n.addEventListener("click", A), document.addEventListener("keydown", k, !0), z = p, xe(r), a();
}
function we(e) {
  V = e, !H && (H = (i) => {
    if (!ge(i)) return;
    if (document.querySelector(`.${l}`)) {
      i.preventDefault();
      return;
    }
    const t = i.target;
    if (!!(t != null && t.closest("input, textarea, select"))) return;
    const r = N(void 0, !1);
    if (!r || r.getAttribute("contenteditable") === "false") return;
    i.preventDefault(), i.stopPropagation();
    const o = R.get(r) || V || e;
    ie(r, o);
  }, document.addEventListener("keydown", H, !0));
}
function Le() {
  H && (document.removeEventListener("keydown", H, !0), H = null, V = null);
}
function Ce() {
  S || (S = (e) => {
    const i = e.target, t = i == null ? void 0 : i.closest($);
    t && (D = t, ee(t));
  }, document.addEventListener("focusin", S, !0)), M || (M = (e) => {
    const t = e.target, n = t == null ? void 0 : t.closest($);
    n && n.getAttribute("contenteditable") !== "false" && (D = n, ee(n));
  }, document.addEventListener("beforeinput", M, !0));
}
function He() {
  S && (document.removeEventListener("focusin", S, !0), S = null), M && (document.removeEventListener("beforeinput", M, !0), M = null);
}
const Me = (e = {}) => {
  const i = Ee(e);
  return ye(), {
    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: (t, n) => {
        const r = N(n);
        return r ? (R.set(r, i), ie(r, i, t), !0) : !1;
      },
      setVersionDiffBaseline: (t, n) => {
        const r = N(n);
        if (!r) return !1;
        R.set(r, i);
        const o = typeof t == "string" ? t : typeof (t == null ? void 0 : t.html) == "string" ? t.html : r.innerHTML;
        return w.set(r, o), !0;
      }
    },
    keymap: {
      "Mod-Alt-d": "openVersionDiff",
      "Mod-Alt-D": "openVersionDiff",
      F8: "openVersionDiff"
    },
    init: () => {
      j += 1, we(i), Ce();
    },
    destroy: () => {
      j = Math.max(0, j - 1), j === 0 && (ne(), Le(), He());
    }
  };
};
export {
  Me as VersionDiffPlugin
};
//# sourceMappingURL=VersionDiffPlugin.native-Bvxgy--t.mjs.map
