const x = ".rte-content, .editora-content", ae = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", we = "__editoraCommandEditorRoot", Ee = "rte-pii-redaction-styles", u = "rte-pii-redaction-panel", k = "pii-redaction", v = "piiRedaction", $ = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', ge = typeof NodeFilter < "u" ? NodeFilter.SHOW_TEXT : 4, Oe = [
  "email",
  "phone",
  "ssn",
  "credit-card",
  "ipv4",
  "api-key",
  "jwt"
], ze = {
  panelTitle: "PII Redaction",
  panelAriaLabel: "PII redaction panel",
  scanText: "Scan PII",
  redactAllText: "Redact All",
  redactText: "Redact",
  locateText: "Locate",
  realtimeOnText: "Realtime On",
  realtimeOffText: "Realtime Off",
  closeText: "Close",
  noFindingsText: "No PII detected in the document.",
  summaryPrefix: "Findings",
  shortcutText: "Shortcuts: Ctrl/Cmd+Alt+Shift+I/U/M/Y",
  readonlyRedactionText: "Editor is read-only. Reopen editable mode to redact.",
  matchLabel: "Detected",
  maskedLabel: "Masked",
  excerptLabel: "Context"
}, Fe = {
  email: {
    label: "Email",
    severity: "medium",
    pattern: /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi
  },
  phone: {
    label: "Phone",
    severity: "medium",
    pattern: /\b(?:\+?\d{1,3}[\s.-]?)?(?:\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4})\b/g
  },
  ssn: {
    label: "SSN",
    severity: "high",
    pattern: /\b\d{3}-\d{2}-\d{4}\b/g
  },
  "credit-card": {
    label: "Credit Card",
    severity: "high",
    pattern: /\b(?:\d[ -]*?){13,19}\b/g,
    validator: (e) => We(e)
  },
  ipv4: {
    label: "IPv4",
    severity: "low",
    pattern: /\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g
  },
  "api-key": {
    label: "API Key",
    severity: "high",
    pattern: /\b(?:sk-[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z\-_]{35}|ghp_[A-Za-z0-9]{36}|xox[baprs]-[A-Za-z0-9-]{10,})\b/g
  },
  jwt: {
    label: "JWT",
    severity: "high",
    pattern: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g
  }
}, f = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), ue = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new Set(), W = /* @__PURE__ */ new Set();
let G = 0, He = 0, ve = 0, A = null, b = null, P = null, L = null, D = null, R = null, _ = null;
function p(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function Be(e) {
  return e.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function Y(e) {
  const t = e.flags.includes("g") ? e.flags : `${e.flags}g`;
  return new RegExp(e.source, t);
}
function be(e) {
  return new RegExp(e.source, e.flags);
}
function X(e, t, n) {
  return Math.max(t, Math.min(n, e));
}
function Ke(e, t) {
  return e === "high" || e === "medium" || e === "low" ? e : t;
}
function qe(e) {
  const t = (e || "*").slice(0, 1) || "*";
  return /[A-Za-z0-9._%+\-\s]/.test(t) ? "*" : t;
}
function $e(e) {
  let t = 2166136261;
  for (let n = 0; n < e.length; n += 1)
    t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
  return t >>> 0;
}
function We(e) {
  const t = e.replace(/\D/g, "");
  if (t.length < 13 || t.length > 19) return !1;
  let n = 0, r = !1;
  for (let i = t.length - 1; i >= 0; i -= 1) {
    let o = Number(t[i]);
    r && (o *= 2, o > 9 && (o -= 9)), n += o, r = !r;
  }
  return n % 10 === 0;
}
function je(e, t) {
  const n = Fe[e];
  if (typeof t == "boolean")
    return {
      type: e,
      label: n.label,
      severity: n.severity,
      enabled: t,
      pattern: Y(n.pattern),
      validator: n.validator
    };
  if (!t)
    return {
      type: e,
      label: n.label,
      severity: n.severity,
      enabled: !0,
      pattern: Y(n.pattern),
      validator: n.validator
    };
  const r = t.pattern instanceof RegExp ? Y(t.pattern) : Y(n.pattern);
  return {
    type: e,
    label: n.label,
    severity: Ke(t.severity, n.severity),
    enabled: t.enabled !== !1,
    pattern: r,
    validator: n.validator
  };
}
function ee(e = {}) {
  const t = Oe.map((r) => je(r, e.detectors?.[r])), n = t.map((r) => `${r.type}:${r.enabled ? "1" : "0"}:${r.severity}:${r.pattern.source}:${r.pattern.flags}`).join("|");
  return {
    enableRealtime: e.enableRealtime !== !1,
    debounceMs: X(Number(e.debounceMs ?? 220), 60, 3e3),
    maxFindings: X(Number(e.maxFindings ?? 140), 1, 500),
    maskChar: qe(e.maskChar),
    revealStart: X(Number(e.revealStart ?? 2), 0, 12),
    revealEnd: X(Number(e.revealEnd ?? 2), 0, 12),
    redactionMode: e.redactionMode === "mask" ? "mask" : "token",
    redactionToken: (e.redactionToken || "REDACTED").trim() || "REDACTED",
    skipInCodeBlocks: e.skipInCodeBlocks !== !1,
    labels: {
      ...ze,
      ...e.labels || {}
    },
    normalizeText: e.normalizeText || Be,
    detectors: t,
    detectorSignature: n
  };
}
function se(e) {
  const t = {};
  return e.detectors.forEach((n) => {
    t[n.type] = {
      enabled: n.enabled,
      severity: n.severity,
      pattern: n.pattern
    };
  }), {
    enableRealtime: e.enableRealtime,
    debounceMs: e.debounceMs,
    maxFindings: e.maxFindings,
    maskChar: e.maskChar,
    revealStart: e.revealStart,
    revealEnd: e.revealEnd,
    redactionMode: e.redactionMode,
    redactionToken: e.redactionToken,
    skipInCodeBlocks: e.skipInCodeBlocks,
    labels: { ...e.labels },
    normalizeText: e.normalizeText,
    detectors: t
  };
}
function me(e) {
  return e.closest(ae) || e;
}
function Ze(e) {
  const t = e.closest("[data-editora-editor]");
  if (t && O(t) === e)
    return t;
  let n = e;
  for (; n; ) {
    if (n.matches(ae) && (n === e || O(n) === e))
      return n;
    n = n.parentElement;
  }
  return me(e);
}
function O(e) {
  if (!e) return null;
  if (e.matches(x)) return e;
  const t = e.querySelector(x);
  return t instanceof HTMLElement ? t : null;
}
function Ve() {
  if (typeof window > "u") return null;
  const e = window[we];
  if (!(e instanceof HTMLElement)) return null;
  window[we] = null;
  const t = O(e);
  if (t) return t;
  const n = e.closest(ae);
  if (n) {
    const i = O(n);
    if (i) return i;
  }
  const r = e.closest(x);
  return r instanceof HTMLElement ? r : null;
}
function J(e) {
  return e ? (e.getAttribute("data-theme") || e.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark") : !1;
}
function Ue(e) {
  const t = me(e);
  if (J(t)) return !0;
  const n = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return J(n) ? !0 : J(document.documentElement) || J(document.body);
}
function ne(e, t) {
  e.classList.remove("rte-pii-redaction-theme-dark"), Ue(t) && e.classList.add("rte-pii-redaction-theme-dark");
}
function re(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function he(e) {
  const t = te.get(e);
  typeof t == "number" && (window.clearTimeout(t), W.delete(t), te.delete(e));
}
function V(e) {
  return e.getAttribute("contenteditable") === "false" || e.getAttribute("data-readonly") === "true";
}
function le(e = 0) {
  return {
    total: 0,
    high: 0,
    medium: 0,
    low: 0,
    redactedCount: e,
    byType: {
      email: 0,
      phone: 0,
      ssn: 0,
      "credit-card": 0,
      ipv4: 0,
      "api-key": 0,
      jwt: 0
    }
  };
}
function K() {
  Array.from(q).forEach((t) => {
    t.isConnected || Te(t);
  });
}
function Ge(e) {
  for (let t = 0; t < e.length; t += 1) {
    const n = e[t];
    if (!(n.type !== "childList" || n.removedNodes.length === 0))
      for (let r = 0; r < n.removedNodes.length; r += 1) {
        const i = n.removedNodes[r];
        if (i.nodeType !== Node.ELEMENT_NODE) continue;
        const o = i;
        if (o.matches?.(x) || o.matches?.(`.${u}`) || o.querySelector?.(x) || o.querySelector?.(`.${u}`))
          return !0;
      }
  }
  return !1;
}
function T(e, t = !0) {
  if (K(), e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const o = e.editorElement, a = O(o);
    if (a) return a;
  }
  const n = Ve();
  if (n) return n;
  const r = window.getSelection();
  if (r && r.rangeCount > 0) {
    const a = re(r.getRangeAt(0).startContainer)?.closest(x);
    if (a) return a;
  }
  const i = document.activeElement;
  if (i) {
    if (i.matches(x)) return i;
    const o = i.closest(x);
    if (o) return o;
  }
  return b && b.isConnected ? b : (b && !b.isConnected && (b = null), t ? document.querySelector(x) : null);
}
function Te(e) {
  he(e), m.get(e)?.remove(), m.delete(e), Z.delete(e), f.delete(e), I.delete(e), E.delete(e), S.delete(e), ue.delete(e), Q.delete(e), q.delete(e), b === e && (b = null);
}
function C(e, t, n) {
  const r = Ze(e);
  Array.from(
    r.querySelectorAll(
      `.rte-toolbar-button[data-command="${t}"], .editora-toolbar-button[data-command="${t}"]`
    )
  ).forEach((o) => {
    o.classList.toggle("active", n), o.setAttribute("data-active", n ? "true" : "false"), o.setAttribute("aria-pressed", n ? "true" : "false");
  });
}
function w(e, t) {
  f.has(e) || f.set(e, t), I.has(e) || I.set(e, []), E.has(e) || E.set(e, le(0)), S.has(e) || S.set(e, t.enableRealtime), q.add(e);
}
function oe(e) {
  return Z.get(e) === !0;
}
function Ie(e, t, n, r) {
  if (!e) return e;
  if (e.length <= n + r)
    return t.repeat(e.length);
  const i = e.slice(0, n), o = r > 0 ? e.slice(e.length - r) : "";
  return `${i}${t.repeat(Math.max(1, e.length - n - r))}${o}`;
}
function de(e, t, n) {
  const r = e.replace(/\D/g, "");
  if (r.length === 0) return e;
  let i = 0;
  const o = Math.max(0, r.length - n);
  return e.split("").map((a) => /\d/.test(a) ? (i += 1, i <= o ? t : a) : a).join("");
}
function Ye(e, t) {
  const n = e.indexOf("@");
  if (n <= 0) return e;
  const r = e.slice(0, n), i = e.slice(n + 1);
  return r.length <= 2 ? `${r[0] || ""}${t}[at]${i}` : `${r[0]}${t.repeat(Math.max(1, r.length - 2))}${r[r.length - 1]}[at]${i}`;
}
function Xe(e, t) {
  const n = e.split(".");
  return n.length !== 4 ? e : `${n[0]}.${n[1]}.${n[2]}.${t.repeat(Math.max(1, n[3].length))}`;
}
function Ce(e, t, n) {
  return e && (t === "email" ? Ye(e, n.maskChar) : t === "phone" || t === "ssn" || t === "credit-card" ? de(e, n.maskChar, 4) : t === "ipv4" ? Xe(e, n.maskChar) : t === "api-key" || t === "jwt" ? Ie(e, n.maskChar, 0, 0) : Ie(e, n.maskChar, n.revealStart, n.revealEnd));
}
function Re(e, t, n) {
  return n.redactionMode === "mask" ? Ce(e, t, n) : `[${n.redactionToken}:${t.toUpperCase()}]`;
}
function Je(e) {
  return ve += 1, `pii-${e}-${Date.now().toString(36)}-${ve.toString(36)}`;
}
function xe(e, t) {
  return t.skipInCodeBlocks ? !!e.parentElement?.closest("code, pre, kbd, samp") : !1;
}
function Qe(e, t) {
  return t.some((n) => e.start < n.end && n.start < e.end);
}
function et(e, t, n) {
  const r = [];
  t.filter((a) => a.enabled).forEach((a) => {
    const l = be(a.pattern);
    let c = l.exec(e);
    for (; c && r.length < n * 5; ) {
      const d = c[0] || "", s = c.index, g = s + d.length;
      d && g > s && (!a.validator || a.validator(d)) && r.push({
        type: a.type,
        severity: a.severity,
        value: d,
        start: s,
        end: g
      }), l.lastIndex === c.index && (l.lastIndex += 1), c = l.exec(e);
    }
  }), r.sort((a, l) => a.start !== l.start ? a.start - l.start : l.end - a.end);
  const o = [];
  for (let a = 0; a < r.length && !(o.length >= n); a += 1) {
    const l = r[a];
    Qe({ start: l.start, end: l.end }, o) || o.push(l);
  }
  return o;
}
function fe(e, t = 120) {
  return e.length <= t ? e : `${e.slice(0, t - 1).trimEnd()}...`;
}
function tt(e, t, n) {
  const r = Math.max(0, t - 28), i = Math.min(e.length, n + 28);
  return fe(e.slice(r, i).trim(), 180);
}
function nt(e, t) {
  const n = le(t);
  return n.total = e.length, e.forEach((r) => {
    n.byType[r.type] += 1, r.severity === "high" ? n.high += 1 : r.severity === "medium" ? n.medium += 1 : n.low += 1;
  }), n;
}
function ie(e, t) {
  const n = e.querySelector(".rte-pii-redaction-live");
  n && (n.textContent = t);
}
function z(e, t, n) {
  const r = t.querySelector('[data-action="toggle-realtime"]');
  if (!r) return;
  const i = F(e, n);
  r.textContent = i ? n.labels.realtimeOnText : n.labels.realtimeOffText, r.setAttribute("aria-pressed", i ? "true" : "false"), C(e, "togglePIIRealtime", i);
}
function rt(e, t) {
  e.setAttribute("aria-label", t.labels.panelAriaLabel);
  const n = e.querySelector(".rte-pii-redaction-title");
  n && (n.textContent = t.labels.panelTitle);
  const r = e.querySelector('[data-action="close"]');
  r && r.setAttribute("aria-label", t.labels.closeText);
  const i = e.querySelector('[data-action="run-scan"]');
  i && (i.textContent = t.labels.scanText);
  const o = e.querySelector('[data-action="redact-all"]');
  o && (o.textContent = t.labels.redactAllText);
  const a = e.querySelector(".rte-pii-redaction-shortcut");
  a && (a.textContent = t.labels.shortcutText);
}
function H(e) {
  const t = m.get(e);
  if (!t) return;
  const n = f.get(e) || A;
  if (!n) return;
  const r = I.get(e) || [], i = E.get(e) || le(0), o = V(e), a = t.querySelector(".rte-pii-redaction-count"), l = t.querySelector(".rte-pii-redaction-summary"), c = t.querySelector(".rte-pii-redaction-list"), d = t.querySelector('[data-action="redact-all"]');
  if (!(!a || !l || !c || !d)) {
    if (a.textContent = String(i.total), l.textContent = `${n.labels.summaryPrefix}: ${i.total} | High ${i.high} | Medium ${i.medium} | Low ${i.low} | Redacted ${i.redactedCount}`, d.disabled = o || r.length === 0, o ? ie(t, n.labels.readonlyRedactionText) : ie(t, `${i.total} PII findings detected.`), z(e, t, n), r.length === 0) {
      c.innerHTML = `<li class="rte-pii-redaction-empty">${p(n.labels.noFindingsText)}</li>`;
      return;
    }
    c.innerHTML = r.map((s) => {
      const g = s.type.toUpperCase(), M = s.suggestion || "Redact this finding before export/share.", B = `${n.labels.locateText}: ${s.match}`, y = `${n.labels.redactText}: ${s.match}`, U = o ? 'disabled aria-disabled="true"' : "";
      return `
        <li class="rte-pii-redaction-item rte-pii-redaction-item-${s.severity}">
          <button
            type="button"
            class="rte-pii-redaction-item-btn"
            data-action="locate-finding"
            data-finding-id="${p(s.id)}"
            data-role="finding-button"
            aria-label="${p(B)}"
          >
            <span class="rte-pii-redaction-badge">${p(s.severity.toUpperCase())}</span>
            <span class="rte-pii-redaction-type">${p(g)}</span>
          </button>
          <p class="rte-pii-redaction-line"><strong>${p(n.labels.matchLabel)}:</strong> ${p(fe(s.match, 80))}</p>
          <p class="rte-pii-redaction-line"><strong>${p(n.labels.maskedLabel)}:</strong> ${p(fe(s.masked, 80))}</p>
          ${s.excerpt ? `<p class="rte-pii-redaction-line"><strong>${p(n.labels.excerptLabel)}:</strong> ${p(s.excerpt)}</p>` : ""}
          <p class="rte-pii-redaction-help">${p(M)}</p>
          <div class="rte-pii-redaction-item-actions">
            <button type="button" class="rte-pii-redaction-btn" data-action="redact-finding" data-finding-id="${p(
        s.id
      )}" aria-label="${p(y)}" ${U}>${p(n.labels.redactText)}</button>
          </div>
        </li>
      `;
    }).join("");
  }
}
function pe(e, t) {
  if (!t.classList.contains("show")) return;
  const r = me(e).getBoundingClientRect(), i = Math.min(window.innerWidth - 20, 390), o = Math.max(10, window.innerWidth - i - 10), a = Math.min(Math.max(10, r.right - i), o), l = Math.max(10, Math.min(window.innerHeight - 10 - 280, r.top + 10));
  t.style.width = `${i}px`, t.style.left = `${a}px`, t.style.top = `${l}px`, t.style.maxHeight = `${Math.max(260, window.innerHeight - 20)}px`;
}
function F(e, t) {
  const n = S.get(e);
  return typeof n == "boolean" ? n : t ? t.enableRealtime : !0;
}
function Se(e, t) {
  if (t === e.innerHTML) return;
  const n = window.execEditorCommand || window.executeEditorCommand;
  if (typeof n == "function")
    try {
      n("recordDomTransaction", e, t, e.innerHTML);
    } catch {
    }
}
function Ae(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function Me(e, t) {
  e.dispatchEvent(
    new CustomEvent("editora:pii-redacted", {
      bubbles: !0,
      detail: {
        redactedCount: t
      }
    })
  );
}
function Pe(e, t) {
  return (I.get(e) || []).find((r) => r.id === t);
}
function ot(e) {
  const t = m.get(e);
  if (t) return t;
  const n = f.get(e) || A || ee(), r = `rte-pii-redaction-panel-${He++}`, i = document.createElement("section");
  return i.className = u, i.id = r, i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "false"), i.setAttribute("aria-label", n.labels.panelAriaLabel), i.innerHTML = `
    <header class="rte-pii-redaction-header">
      <h2 class="rte-pii-redaction-title">${p(n.labels.panelTitle)}</h2>
      <button type="button" class="rte-pii-redaction-icon-btn" data-action="close" aria-label="${p(
    n.labels.closeText
  )}">✕</button>
    </header>
    <div class="rte-pii-redaction-body">
      <div class="rte-pii-redaction-topline">
        <p class="rte-pii-redaction-summary" aria-live="polite"></p>
        <span class="rte-pii-redaction-count" aria-hidden="true">0</span>
      </div>
      <div class="rte-pii-redaction-controls" role="toolbar" aria-label="PII redaction controls">
        <button type="button" class="rte-pii-redaction-btn rte-pii-redaction-btn-primary" data-action="run-scan">${p(
    n.labels.scanText
  )}</button>
        <button type="button" class="rte-pii-redaction-btn" data-action="redact-all">${p(
    n.labels.redactAllText
  )}</button>
        <button type="button" class="rte-pii-redaction-btn" data-action="toggle-realtime" aria-pressed="false"></button>
      </div>
      <ul class="rte-pii-redaction-list" role="list" aria-label="Detected PII findings"></ul>
      <p class="rte-pii-redaction-shortcut">${p(n.labels.shortcutText)}</p>
      <span class="rte-pii-redaction-live" aria-live="polite"></span>
    </div>
  `, i.addEventListener("click", (o) => {
    const l = o.target?.closest("[data-action]");
    if (!l) return;
    const c = l.getAttribute("data-action") || "", d = f.get(e) || A || n;
    if (f.set(e, d), w(e, d), c === "close") {
      j(e, !0);
      return;
    }
    if (c === "run-scan") {
      h(e, d, !0);
      return;
    }
    if (c === "toggle-realtime") {
      const s = !F(e, d);
      S.set(e, s), z(e, i, d), s && h(e, d, !0);
      return;
    }
    if (c === "redact-all") {
      ye(e, d);
      return;
    }
    if (c === "locate-finding") {
      const s = l.getAttribute("data-finding-id") || "", g = Pe(e, s);
      if (!g) return;
      lt(e, g, d);
      return;
    }
    if (c === "redact-finding") {
      const s = l.getAttribute("data-finding-id") || "";
      _e(e, s, d);
    }
  }), i.addEventListener("keydown", (o) => {
    if (o.key === "Escape") {
      o.preventDefault(), j(e, !0);
      return;
    }
    if (o.key !== "ArrowDown" && o.key !== "ArrowUp") return;
    const a = Array.from(i.querySelectorAll('[data-role="finding-button"]'));
    if (a.length === 0) return;
    const l = document.activeElement, c = a.findIndex((g) => g === l);
    if (c === -1) return;
    o.preventDefault();
    const d = o.key === "ArrowDown" ? 1 : -1, s = (c + d + a.length) % a.length;
    a[s].focus();
  }), ne(i, e), document.body.appendChild(i), m.set(e, i), Z.set(e, !1), H(e), i;
}
function j(e, t = !1) {
  const n = m.get(e);
  n && (n.classList.remove("show"), Z.set(e, !1), C(e, "togglePIIRedactionPanel", !1), t && e.focus({ preventScroll: !0 }));
}
function N(e) {
  K();
  const t = ot(e);
  m.forEach((r, i) => {
    i !== e && j(i, !1);
  }), t.classList.add("show"), Z.set(e, !0), C(e, "togglePIIRedactionPanel", !0), ne(t, e), pe(e, t), H(e), t.querySelector('[data-action="run-scan"]')?.focus();
}
function Le(e, t) {
  const n = oe(e);
  return (typeof t == "boolean" ? t : !n) ? N(e) : j(e), !0;
}
function it(e, t) {
  const n = t.normalizeText(e.innerText || e.textContent || ""), r = e.innerHTML;
  return `${n.length}:${$e(n)}:${r.length}:${$e(r)}:${t.detectorSignature}`;
}
function at(e, t) {
  const n = [], r = be(e.pattern);
  let i = r.exec(t);
  for (; i; ) {
    const o = i[0] || "", a = i.index, l = a + o.length;
    o && l > a && (!e.validator || e.validator(o)) && n.push({ value: o, start: a, end: l }), r.lastIndex === i.index && (r.lastIndex += 1), i = r.exec(t);
  }
  return n;
}
function De(e, t, n) {
  const r = n.detectors.find((c) => c.type === t.type && c.enabled);
  if (!r) return null;
  const i = t.match.toLowerCase();
  let o = 0;
  const a = document.createTreeWalker(e, ge, null);
  let l = a.nextNode();
  for (; l; ) {
    if (!xe(l, n)) {
      const c = at(r, l.data);
      for (let d = 0; d < c.length; d += 1) {
        const s = c[d];
        if (s.value.toLowerCase() === i && (o += 1, o === t.occurrence)) {
          const g = document.createRange();
          return g.setStart(l, s.start), g.setEnd(l, s.end), g;
        }
      }
    }
    l = a.nextNode();
  }
  return null;
}
function lt(e, t, n) {
  const r = De(e, t, n);
  if (!r) return !1;
  const i = window.getSelection();
  return i ? (i.removeAllRanges(), i.addRange(r), re(r.startContainer)?.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" }), e.focus({ preventScroll: !0 }), !0) : !1;
}
async function h(e, t, n = !1) {
  w(e, t);
  const r = it(e, t);
  if (!n && ue.get(e) === r)
    return I.get(e) || [];
  const i = (Q.get(e) || 0) + 1;
  Q.set(e, i);
  const o = [], a = /* @__PURE__ */ new Map(), l = document.createTreeWalker(e, ge, null);
  let c = l.nextNode();
  for (; c && o.length < t.maxFindings; ) {
    const g = c.data || "";
    if (g.trim() && !xe(c, t)) {
      const M = et(g, t.detectors, t.maxFindings - o.length);
      for (let B = 0; B < M.length && !(o.length >= t.maxFindings); B += 1) {
        const y = M[B], U = `${y.type}:${y.value.toLowerCase()}`, ke = (a.get(U) || 0) + 1;
        a.set(U, ke), o.push({
          id: Je(y.type),
          type: y.type,
          severity: y.severity,
          match: y.value,
          masked: Ce(y.value, y.type, t),
          occurrence: ke,
          excerpt: tt(g, y.start, y.end),
          suggestion: "Review and redact this value before external sharing."
        });
      }
    }
    c = l.nextNode();
  }
  if (Q.get(e) !== i)
    return I.get(e) || [];
  const d = E.get(e)?.redactedCount || 0, s = nt(o, d);
  return ue.set(e, r), I.set(e, o), E.set(e, s), H(e), e.dispatchEvent(
    new CustomEvent("editora:pii-scan", {
      bubbles: !0,
      detail: {
        findings: o,
        stats: s
      }
    })
  ), o;
}
function ct(e, t) {
  let n = e, r = 0;
  return t.detectors.filter((o) => o.enabled).forEach((o) => {
    const a = be(o.pattern);
    n = n.replace(a, (l) => o.validator && !o.validator(l) ? l : (r += 1, Re(l, o.type, t)));
  }), { nextValue: n, count: r };
}
async function _e(e, t, n) {
  if (V(e)) {
    const d = m.get(e);
    return d && ie(d, n.labels.readonlyRedactionText), !1;
  }
  const r = Pe(e, t);
  if (!r) return !1;
  const i = De(e, r, n);
  if (!i) return !1;
  const o = e.innerHTML, a = Re(r.match, r.type, n);
  if (i.startContainer === i.endContainer && i.startContainer.nodeType === Node.TEXT_NODE) {
    const d = i.startContainer, s = d.data, g = i.startOffset, M = i.endOffset;
    d.data = `${s.slice(0, g)}${a}${s.slice(M)}`;
  } else
    i.deleteContents(), i.insertNode(document.createTextNode(a));
  Ae(e), Se(e, o);
  const l = E.get(e)?.redactedCount || 0;
  await h(e, n, !0);
  const c = E.get(e);
  return c && (c.redactedCount = l + 1, H(e)), Me(e, 1), !0;
}
async function ye(e, t) {
  if (V(e)) {
    const d = m.get(e);
    return d && ie(d, t.labels.readonlyRedactionText), 0;
  }
  (I.get(e) || []).length === 0 && await h(e, t, !0);
  const r = e.innerHTML;
  let i = 0;
  const o = document.createTreeWalker(e, ge, null);
  let a = o.nextNode();
  for (; a; ) {
    if (xe(a, t)) {
      a = o.nextNode();
      continue;
    }
    const d = a.data || "";
    if (!d) {
      a = o.nextNode();
      continue;
    }
    const s = ct(d, t);
    s.count > 0 && s.nextValue !== d && (a.data = s.nextValue, i += s.count), a = o.nextNode();
  }
  if (i === 0) return 0;
  Ae(e), Se(e, r);
  const l = E.get(e)?.redactedCount || 0;
  await h(e, t, !0);
  const c = E.get(e);
  return c && (c.redactedCount = l + i, H(e)), Me(e, i), i;
}
function Ne(e) {
  const t = f.get(e) || A;
  if (!t || !F(e, t) || V(e)) return;
  he(e);
  const n = window.setTimeout(() => {
    W.delete(n), te.delete(e), h(e, t, !1);
  }, t.debounceMs);
  W.add(n), te.set(e, n);
}
function ce(e) {
  return typeof e.key == "string" ? e.key.toLowerCase() : "";
}
function st(e) {
  const t = ce(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "i";
}
function dt(e) {
  const t = ce(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "u";
}
function ut(e) {
  const t = ce(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "m";
}
function ft(e) {
  const t = ce(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "y";
}
function pt(e) {
  const t = re(e.target);
  if (t) {
    const r = t.closest(x);
    if (r) return r;
    const i = t.closest(ae);
    if (i) {
      const a = O(i);
      if (a) return a;
    }
    const o = t.closest(`.${u}`);
    if (o) {
      const a = Array.from(m.entries()).find(([, l]) => l === o);
      if (a) return a[0];
    }
  }
  const n = window.getSelection();
  if (n && n.rangeCount > 0) {
    const r = re(n.getRangeAt(0).startContainer)?.closest(
      x
    );
    if (r) return r;
  }
  return null;
}
function gt() {
  if (typeof document > "u" || document.getElementById(Ee)) return;
  const e = document.createElement("style");
  e.id = Ee, e.textContent = `
    .rte-toolbar-group-items.${k},
    .editora-toolbar-group-items.${k},
    .rte-toolbar-group-items.${v},
    .editora-toolbar-group-items.${v} {
      display: flex;
      border: 1px solid #ccc;
      border-radius: 3px;
      background: #fff;
    }

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

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

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

    ${$} .rte-toolbar-group-items.${k},
    ${$} .editora-toolbar-group-items.${k},
    ${$} .rte-toolbar-group-items.${v},
    ${$} .editora-toolbar-group-items.${v},
    .${u}.rte-pii-redaction-theme-dark {
      border-color: #566275;
    }
    ${$} .rte-toolbar-group-items.${k} .rte-toolbar-button svg,
    ${$} .editora-toolbar-group-items.${k} .editora-toolbar-button svg,
    ${$} .rte-toolbar-group-items.${v} .rte-toolbar-button svg,
    ${$} .editora-toolbar-group-items.${v} .editora-toolbar-button svg
    {
      fill: none;
    }
    ${$} .rte-toolbar-group-items.${k} .rte-toolbar-button,
    ${$} .editora-toolbar-group-items.${k} .editora-toolbar-button
    {
      border-color: #566275;
    }
    .${u} {
      position: fixed;
      z-index: 12000;
      display: none;
      width: min(390px, calc(100vw - 20px));
      max-height: calc(100vh - 20px);
      border: 1px solid #d1d5db;
      border-radius: 14px;
      background: #ffffff;
      color: #111827;
      box-shadow: 0 18px 45px rgba(15, 23, 42, 0.25);
      overflow: hidden;
    }

    .${u}.show {
      display: flex;
      flex-direction: column;
    }

    .${u}.rte-pii-redaction-theme-dark {
      border-color: #334155;
      background: #0f172a;
      color: #e2e8f0;
      box-shadow: 0 20px 46px rgba(2, 6, 23, 0.68);
    }

    .rte-pii-redaction-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 12px 14px;
      border-bottom: 1px solid #e5e7eb;
      background: linear-gradient(180deg, #f9fafb 0%, #f3f4f6 100%);
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-header {
      border-color: #1e293b;
      background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    }

    .rte-pii-redaction-title {
      margin: 0;
      font-size: 15px;
      line-height: 1.2;
      font-weight: 700;
    }

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

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

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

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

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

    .rte-pii-redaction-topline {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .rte-pii-redaction-summary {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #475569;
      flex: 1;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-summary {
      color: #94a3b8;
    }

    .rte-pii-redaction-count {
      min-width: 32px;
      height: 32px;
      border-radius: 999px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      font-size: 13px;
      border: 1px solid #cbd5e1;
      background: #f8fafc;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-count {
      border-color: #334155;
      background: #111827;
      color: #cbd5e1;
    }

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

    .rte-pii-redaction-btn {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      height: 34px;
      padding: 0 10px;
      background: #ffffff;
      color: inherit;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
    }

    .rte-pii-redaction-btn:hover,
    .rte-pii-redaction-btn:focus-visible {
      border-color: #94a3b8;
      background: #f8fafc;
      outline: none;
    }

    .rte-pii-redaction-btn:disabled {
      opacity: 0.56;
      cursor: not-allowed;
    }

    .rte-pii-redaction-btn-primary {
      border-color: #0284c7;
      background: #0ea5e9;
      color: #f8fafc;
    }

    .rte-pii-redaction-btn-primary:hover,
    .rte-pii-redaction-btn-primary:focus-visible {
      border-color: #0369a1;
      background: #0284c7;
      color: #ffffff;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-btn {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-btn:hover,
    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-btn:focus-visible {
      border-color: #475569;
      background: #1e293b;
    }

    .rte-pii-redaction-list {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: 8px;
      max-height: min(55vh, 420px);
      overflow: auto;
    }

    .rte-pii-redaction-item {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 8px;
      background: #ffffff;
      display: grid;
      gap: 6px;
    }

    .rte-pii-redaction-item-high {
      border-color: #fca5a5;
      background: #fef2f2;
    }

    .rte-pii-redaction-item-medium {
      border-color: #fcd34d;
      background: #fffbeb;
    }

    .rte-pii-redaction-item-low {
      border-color: #93c5fd;
      background: #eff6ff;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-item {
      border-color: #334155;
      background: #0b1220;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-item-high {
      border-color: #7f1d1d;
      background: #2b0b11;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-item-medium {
      border-color: #78350f;
      background: #2b1907;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-item-low {
      border-color: #1d4ed8;
      background: #0a162f;
    }

    .rte-pii-redaction-item-btn {
      border: none;
      background: transparent;
      width: 100%;
      display: flex;
      align-items: center;
      gap: 8px;
      text-align: left;
      padding: 0;
      color: inherit;
      cursor: pointer;
    }

    .rte-pii-redaction-item-btn:focus-visible {
      outline: 2px solid #0284c7;
      outline-offset: 3px;
      border-radius: 6px;
    }

    .rte-pii-redaction-badge {
      border-radius: 999px;
      border: 1px solid currentColor;
      padding: 1px 8px;
      font-size: 10px;
      font-weight: 700;
      line-height: 1.3;
      text-transform: uppercase;
      opacity: 0.86;
    }

    .rte-pii-redaction-type {
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 0.03em;
    }

    .rte-pii-redaction-line,
    .rte-pii-redaction-help {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #334155;
      word-break: break-word;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-line,
    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-help {
      color: #94a3b8;
    }

    .rte-pii-redaction-item-actions {
      display: flex;
      justify-content: flex-end;
    }

    .rte-pii-redaction-empty {
      border: 1px dashed #cbd5e1;
      border-radius: 10px;
      padding: 10px;
      font-size: 13px;
      color: #475569;
      background: #f8fafc;
    }

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-empty {
      border-color: #334155;
      background: #0b1220;
      color: #94a3b8;
    }

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

    .${u}.rte-pii-redaction-theme-dark .rte-pii-redaction-shortcut {
      color: #94a3b8;
    }

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

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

      .rte-pii-redaction-list {
        max-height: 45vh;
      }
    }
  `, document.head.appendChild(e);
}
function bt(e) {
  A = e, P || (P = (t) => {
    K();
    const r = t.target?.closest(x);
    if (!r) return;
    b = r;
    const i = f.get(r) || e;
    w(r, i), f.set(r, i), C(r, "togglePIIRedactionPanel", oe(r)), C(r, "togglePIIRealtime", F(r, i));
    const o = m.get(r);
    o && (ne(o, r), pe(r, o), z(r, o, i));
  }, document.addEventListener("focusin", P, !0)), L || (L = (t) => {
    const r = t.target?.closest(x);
    r && (b = r, Ne(r));
  }, document.addEventListener("input", L, !0)), D || (D = (t) => {
    if (t.defaultPrevented || t.target?.closest(`.${u} input, .${u} textarea, .${u} select`)) return;
    const r = pt(t);
    if (!r) return;
    const i = f.get(r) || A || e;
    if (w(r, i), f.set(r, i), b = r, t.key === "Escape" && oe(r)) {
      t.preventDefault(), j(r, !0);
      return;
    }
    if (st(t)) {
      t.preventDefault(), t.stopPropagation(), Le(r);
      return;
    }
    if (dt(t)) {
      t.preventDefault(), t.stopPropagation(), h(r, i, !0), N(r);
      return;
    }
    if (ut(t)) {
      t.preventDefault(), t.stopPropagation(), V(r) || (ye(r, i), N(r));
      return;
    }
    if (ft(t)) {
      t.preventDefault(), t.stopPropagation();
      const o = !F(r, i);
      S.set(r, o);
      const a = m.get(r);
      a && z(r, a, i), C(r, "togglePIIRealtime", o), o && h(r, i, !0);
    }
  }, document.addEventListener("keydown", D, !0)), R || (R = () => {
    K(), m.forEach((t, n) => {
      !n.isConnected || !t.isConnected || (ne(t, n), pe(n, t));
    });
  }, window.addEventListener("scroll", R, !0), window.addEventListener("resize", R)), !_ && typeof MutationObserver < "u" && document.body && (_ = new MutationObserver((t) => {
    Ge(t) && K();
  }), _.observe(document.body, {
    childList: !0,
    subtree: !0
  }));
}
function mt() {
  P && (document.removeEventListener("focusin", P, !0), P = null), L && (document.removeEventListener("input", L, !0), L = null), D && (document.removeEventListener("keydown", D, !0), D = null), R && (window.removeEventListener("scroll", R, !0), window.removeEventListener("resize", R), R = null), _ && (_.disconnect(), _ = null), m.forEach((e) => e.remove()), m.clear(), q.forEach((e) => he(e)), q.clear(), A = null, b = null;
}
const ht = (e = {}) => {
  const t = ee(e), n = /* @__PURE__ */ new Set();
  return gt(), {
    name: "piiRedaction",
    toolbar: [
      {
        id: "piiRedactionGroup",
        label: "PII Redaction",
        type: "group",
        command: "piiRedaction",
        items: [
          {
            id: "piiRedaction",
            label: "PII Redaction",
            command: "togglePIIRedactionPanel",
            shortcut: "Mod-Alt-Shift-i",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M12 3.5 19 6.5v4.8c0 4.4-2.7 8.1-7 9.2-4.3-1.1-7-4.8-7-9.2V6.5l7-3Z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/><path d="M8.8 11.6h6.4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><circle cx="12" cy="11.6" r="1.2" fill="currentColor"/></svg>'
          },
          {
            id: "piiScan",
            label: "Scan PII",
            command: "runPIIScan",
            shortcut: "Mod-Alt-Shift-u",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="4.5" y="3.5" width="11" height="15" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M7.5 8.2h5M7.5 11.2h5M7.5 14.2h3.2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><circle cx="16.8" cy="16.8" r="2.8" stroke="currentColor" stroke-width="1.6"/><path d="m18.8 18.8 2 2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>'
          },
          {
            id: "piiRedactAll",
            label: "Redact All PII",
            command: "redactAllPII",
            shortcut: "Mod-Alt-Shift-m",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M5 18h14" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M7 6h10l-1 8H8L7 6Z" stroke="currentColor" stroke-width="1.7"/><path d="m9 9 6 4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>'
          },
          {
            id: "piiRealtime",
            label: "Toggle Realtime PII Scan",
            command: "togglePIIRealtime",
            shortcut: "Mod-Alt-Shift-y",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M12 3v4M12 17v4M4 12h4M16 12h4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><circle cx="12" cy="12" r="4" stroke="currentColor" stroke-width="1.7"/></svg>'
          }
        ]
      }
    ],
    commands: {
      piiRedaction: (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = f.get(o) || t;
        return w(o, a), f.set(o, a), b = o, N(o), h(o, a, !1), !0;
      },
      togglePIIRedactionPanel: (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = f.get(o) || t;
        w(o, a), f.set(o, a), b = o;
        const l = Le(o, typeof r == "boolean" ? r : void 0);
        return oe(o) && h(o, a, !1), l;
      },
      runPIIScan: async (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = f.get(o) || t;
        return w(o, a), f.set(o, a), b = o, await h(o, a, !0), N(o), !0;
      },
      redactAllPII: async (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = f.get(o) || t;
        w(o, a), f.set(o, a), b = o;
        const l = await ye(o, a);
        return l > 0 && N(o), l > 0;
      },
      redactPIIFinding: async (r, i) => {
        const o = T(i);
        if (!o || typeof r != "string" || !r) return !1;
        const a = f.get(o) || t;
        return w(o, a), f.set(o, a), b = o, _e(o, r, a);
      },
      togglePIIRealtime: (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = f.get(o) || t;
        w(o, a), f.set(o, a);
        const l = typeof r == "boolean" ? r : !F(o, a);
        S.set(o, l);
        const c = m.get(o);
        return c && z(o, c, a), C(o, "togglePIIRealtime", l), l && h(o, a, !0), !0;
      },
      getPIIRedactionFindings: (r, i) => {
        const o = T(i);
        if (!o) return !1;
        const a = I.get(o) || [], l = E.get(o) || le(0), c = a.map((s) => ({ ...s })), d = {
          ...l,
          byType: { ...l.byType }
        };
        if (typeof r == "function")
          try {
            r(c, d);
          } catch {
          }
        return o.__piiRedactionFindings = c, o.dispatchEvent(
          new CustomEvent("editora:pii-findings", {
            bubbles: !0,
            detail: { findings: c, stats: d }
          })
        ), !0;
      },
      setPIIRedactionOptions: (r, i) => {
        const o = T(i);
        if (!o || !r || typeof r != "object") return !1;
        const a = f.get(o) || t, l = ee({
          ...se(a),
          ...r,
          labels: {
            ...a.labels,
            ...r.labels || {}
          },
          detectors: {
            ...se(a).detectors || {},
            ...r.detectors || {}
          },
          normalizeText: r.normalizeText || a.normalizeText
        });
        f.set(o, l), typeof r.enableRealtime == "boolean" && S.set(o, r.enableRealtime);
        const c = m.get(o);
        return c && (rt(c, l), H(o), z(o, c, l)), h(o, l, !0), !0;
      }
    },
    keymap: {
      "Mod-Alt-Shift-i": "togglePIIRedactionPanel",
      "Mod-Alt-Shift-I": "togglePIIRedactionPanel",
      "Mod-Alt-Shift-u": "runPIIScan",
      "Mod-Alt-Shift-U": "runPIIScan",
      "Mod-Alt-Shift-m": "redactAllPII",
      "Mod-Alt-Shift-M": "redactAllPII",
      "Mod-Alt-Shift-y": "togglePIIRealtime",
      "Mod-Alt-Shift-Y": "togglePIIRealtime"
    },
    init: function(i) {
      G += 1;
      const o = this && typeof this.__pluginConfig == "object" ? ee({ ...se(t), ...this.__pluginConfig }) : t;
      bt(o);
      const a = T(
        i?.editorElement ? { editorElement: i.editorElement } : void 0,
        !1
      );
      a && (b = a, n.add(a), w(a, o), f.set(a, o), C(a, "togglePIIRedactionPanel", !1), C(a, "togglePIIRealtime", o.enableRealtime), o.enableRealtime && Ne(a));
    },
    destroy: () => {
      n.forEach((r) => Te(r)), n.clear(), G = Math.max(0, G - 1), !(G > 0) && (W.forEach((r) => {
        window.clearTimeout(r);
      }), W.clear(), mt());
    }
  };
};
export {
  ht as PIIRedactionPlugin
};
