const A = ".rte-content, .editora-content", P = '.rte-conditional-block[data-conditional-content="true"]', b = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', f = ':is([data-theme="acme"], .editora-theme-acme, .rte-theme-acme)', h = ":is(.rte-content.rte-conditional-theme-dark, .editora-content.rte-conditional-theme-dark)", g = ":is(.rte-content.rte-conditional-theme-acme, .editora-content.rte-conditional-theme-acme)", Se = "rte-conditional-content-styles", c = "rte-conditional-dialog-overlay", u = "rte-conditional-floating-toolbar", k = /* @__PURE__ */ new WeakMap(), Ce = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map();
let de = null, me = 0, J = null, X = null, Q = null, ee = null, te = null, oe = null, H = null, y = null, ne = null;
const ze = {
  dialogTitleInsert: "Insert Conditional Content",
  dialogTitleEdit: "Edit Conditional Content",
  conditionLabel: "Condition",
  conditionPlaceholder: 'user.role == "admin"',
  audienceLabel: "Audience (comma separated)",
  audiencePlaceholder: "all",
  localeLabel: "Locale (comma separated)",
  localePlaceholder: "all",
  elseLabel: "Enable Else Block",
  saveText: "Save",
  cancelText: "Cancel",
  blockIfLabel: "IF",
  blockElseLabel: "ELSE",
  allAudiencesText: "all audiences",
  allLocalesText: "all locales"
};
function $(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function R(e) {
  return e ? e.split(",").map((t) => t.trim()).filter(Boolean) : [];
}
function Te(e) {
  return !e || e.length === 0 ? "" : e.join(", ");
}
function ie(e) {
  return e ? e.map((t) => t.trim()).filter(Boolean) : [];
}
function Fe(e) {
  return {
    ...ze,
    ...e || {}
  };
}
function D(e) {
  return e.getAttribute("contenteditable") === "false" || e.getAttribute("data-readonly") === "true";
}
function se(e) {
  return e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || e;
}
function pe(e) {
  if (!e) return !1;
  const t = e.getAttribute("data-theme") || e.getAttribute("theme");
  return t && t.toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark");
}
function je(e) {
  const t = se(e);
  if (pe(t)) return !0;
  const o = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return pe(o) ? !0 : pe(document.documentElement) || pe(document.body);
}
function he(e) {
  if (!e) return !1;
  const t = e.getAttribute("data-theme") || e.getAttribute("theme");
  return t && t.toLowerCase() === "acme" ? !0 : e.classList.contains("editora-theme-acme") || e.classList.contains("rte-theme-acme");
}
function Ie(e) {
  const t = se(e);
  if (he(t)) return !0;
  const o = t.closest("[data-theme], [theme], .editora-theme-acme, .rte-theme-acme");
  return he(o) ? !0 : he(document.documentElement) || he(document.body);
}
function Ve(e) {
  return je(e) ? "dark" : Ie(e) ? "acme" : "light";
}
function xe(e, t) {
  const o = Ve(t);
  e.classList.remove("rte-conditional-theme-dark", "rte-conditional-theme-acme"), o === "dark" ? e.classList.add("rte-conditional-theme-dark") : o === "acme" && e.classList.add("rte-conditional-theme-acme");
}
function w(e, t = !0) {
  if ((e == null ? void 0 : e.contentElement) instanceof HTMLElement) return e.contentElement;
  if ((e == null ? void 0 : e.editorElement) instanceof HTMLElement) {
    const n = e.editorElement;
    if (n.matches(A)) return n;
    const a = n.querySelector(A);
    if (a instanceof HTMLElement) return a;
  }
  const o = window.getSelection();
  if (o && o.rangeCount > 0) {
    const n = o.getRangeAt(0).startContainer, a = n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement, r = a == null ? void 0 : a.closest(A);
    if (r) return r;
  }
  const i = document.activeElement;
  if (i) {
    if (i.matches(A)) return i;
    const n = i.closest(A);
    if (n) return n;
  }
  return y && y.isConnected ? y : t ? document.querySelector(A) : null;
}
function Ne(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const o = t.getRangeAt(0);
  return e.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
}
function Le(e, t) {
  const o = window.getSelection();
  o && (o.removeAllRanges(), o.addRange(t), e.focus({ preventScroll: !0 }));
}
function De(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function He(e, t) {
  if (t === e.innerHTML) return;
  const o = window.execEditorCommand || window.executeEditorCommand;
  if (typeof o == "function")
    try {
      o("recordDomTransaction", e, t, e.innerHTML);
    } catch (i) {
    }
}
function $e(e, t) {
  const o = document.createRange();
  o.selectNodeContents(t), o.collapse(!1), Le(e, o);
}
function ve(e, t) {
  if (t)
    return t.split(".").filter(Boolean).reduce((o, i) => {
      if (o != null && typeof o == "object")
        return o[i];
    }, e);
}
function We(e) {
  const t = e.trim();
  if (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'"))
    return t.slice(1, -1);
  if (t === "true") return !0;
  if (t === "false") return !1;
  if (t === "null") return null;
  const o = Number(t);
  if (!Number.isNaN(o) && t !== "") return o;
  if (t.startsWith("[") && t.endsWith("]") || t.startsWith("{") && t.endsWith("}"))
    try {
      return JSON.parse(t);
    } catch (i) {
      return t;
    }
  return t;
}
function Ze(e, t) {
  const o = e.trim();
  if (!o) return !0;
  if (o.startsWith("!")) {
    const x = o.slice(1).trim();
    return !ve(t, x);
  }
  const i = o.match(/^([a-zA-Z_$][\w.$]*)\s*(==|!=|>=|<=|>|<|in|contains|~=)\s*(.+)$/);
  if (!i)
    return !!ve(t, o);
  const [, n, a, r] = i, l = ve(t, n), d = We(r);
  switch (a) {
    case "==":
      return l == d;
    case "!=":
      return l != d;
    case ">":
      return Number(l) > Number(d);
    case "<":
      return Number(l) < Number(d);
    case ">=":
      return Number(l) >= Number(d);
    case "<=":
      return Number(l) <= Number(d);
    case "in":
      return Array.isArray(d) ? d.some((x) => x == l) : typeof d == "string" ? d.split(",").map((x) => x.trim()).includes(String(l)) : !1;
    case "contains":
    case "~=":
      return Array.isArray(l) ? l.some((x) => String(x).toLowerCase() === String(d).toLowerCase()) : typeof l == "string" ? l.toLowerCase().includes(String(d).toLowerCase()) : !1;
    default:
      return !1;
  }
}
function Ge() {
  if (typeof document == "undefined" || document.getElementById(Se)) return;
  const e = document.createElement("style");
  e.id = Se, e.textContent = `
    .rte-conditional-block {
      border: 1px solid #dbe3ec;
      border-radius: 8px;
      margin: 10px 0;
      background: #f8fafc;
      overflow: hidden;
    }

    .rte-conditional-header,
    .rte-conditional-else-label {
      display: flex;
      align-items: center;
      gap: 8px;
      background: #eef2f7;
      border-bottom: 1px solid #dbe3ec;
      padding: 8px 10px;
      user-select: none;
    }

    .rte-conditional-else-label {
      border-top: 1px solid #dbe3ec;
      border-bottom: 1px solid #dbe3ec;
    }

    .rte-conditional-chip {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 34px;
      height: 20px;
      border-radius: 999px;
      border: 1px solid #bfdbfe;
      background: #dbeafe;
      color: #1e3a8a;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 0.03em;
      text-transform: uppercase;
      padding: 0 7px;
      flex: 0 0 auto;
    }

    .rte-conditional-chip-else {
      border-color: #fecaca;
      background: #fee2e2;
      color: #991b1b;
    }

    .rte-conditional-summary {
      font-size: 12px;
      color: #0f172a;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      flex: 1;
    }

    .rte-conditional-meta {
      font-size: 11px;
      color: #64748b;
      white-space: nowrap;
      flex: 0 0 auto;
    }

    .rte-conditional-body {
      padding: 10px;
      background: #ffffff;
      min-height: 44px;
    }

    .rte-conditional-hidden {
      display: none !important;
    }

    .rte-toolbar-group-items.conditional-content,
    .editora-toolbar-group-items.conditional-content {
      display: flex;
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      background: #ffffff;
    }

    .rte-toolbar-group-items.conditional-content .rte-toolbar-item,
    .editora-toolbar-group-items.conditional-content .editora-toolbar-item {
      display: flex;
    }

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

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

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

    .rte-conditional-block.rte-conditional-preview {
      border-style: dashed;
    }

    .rte-conditional-block.rte-conditional-preview .rte-conditional-body[contenteditable="false"] {
      cursor: default;
    }

    .${c} {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.5);
      z-index: 2147483646;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }

    .rte-conditional-dialog {
      width: min(560px, 96vw);
      max-height: min(88vh, 760px);
      border: 1px solid #dbe3ec;
      border-radius: 8px;
      background: #ffffff;
      box-shadow: 0 24px 50px rgba(15, 23, 42, 0.25);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

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

    .rte-conditional-dialog-footer {
      border-top: 1px solid #e2e8f0;
      border-bottom: none;
      justify-content: flex-end;
    }

    .rte-conditional-dialog-title {
      margin: 0;
      font-size: 16px;
      font-weight: 700;
      color: #0f172a;
    }

    .rte-conditional-dialog-body {
      padding: 14px;
      overflow: auto;
      display: grid;
      grid-template-columns: 1fr;
      gap: 12px;
    }

    .rte-conditional-field {
      display: grid;
      gap: 6px;
    }

    .rte-conditional-field label {
      font-size: 12px;
      font-weight: 600;
      color: #334155;
    }

    .rte-conditional-field input[type="text"] {
      width: 100%;
      min-height: 36px;
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      padding: 8px 10px;
      font-size: 13px;
      line-height: 1.4;
      box-sizing: border-box;
      color: #0f172a;
      background: #ffffff;
    }

    .rte-conditional-field input[type="text"]:focus-visible,
    .rte-conditional-btn:focus-visible {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

    .rte-conditional-checkbox {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
      color: #334155;
      min-height: 36px;
    }

    .rte-conditional-help {
      margin: 0;
      font-size: 12px;
      color: #64748b;
    }

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

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

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

    .${u} {
      position: fixed;
      z-index: 2147483645;
      display: none;
      align-items: center;
      gap: 6px;
      padding: 6px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: rgba(255, 255, 255, 0.98);
      box-shadow: 0 14px 30px rgba(15, 23, 42, 0.2);
      backdrop-filter: blur(6px);
    }

    .${u}.show {
      display: inline-flex;
    }

    .${u} .rte-conditional-float-btn {
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      min-height: 30px;
      min-width: 30px;
      padding: 0 8px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      background: #ffffff;
      color: #0f172a;
      cursor: pointer;
      font-size: 12px;
      line-height: 1;
    }

    .${u} .rte-conditional-float-btn:hover {
      background: #f8fafc;
    }

    .${u} .rte-conditional-float-btn[data-action="delete"] {
      border-color: #fecaca;
      color: #991b1b;
      background: #fff5f5;
    }

    .rte-conditional-preview-on ${P} {
      border-width: 2px;
    }

    .rte-conditional-preview-on ${P} .rte-conditional-header {
      background: #ecfeff;
      border-color: #bae6fd;
    }

    ${b} .rte-conditional-block,
    ${h} .rte-conditional-block,
    .${c}.rte-conditional-theme-dark .rte-conditional-block {
      background: #111827;
      border-color: #334155;
    }

    ${b} .rte-conditional-header,
    ${b} .rte-conditional-else-label,
    ${h} .rte-conditional-header,
    ${h} .rte-conditional-else-label,
    .${c}.rte-conditional-theme-dark .rte-conditional-header,
    .${c}.rte-conditional-theme-dark .rte-conditional-else-label {
      background: #0f172a;
      border-color: #334155;
    }

    ${b} .rte-conditional-summary,
    ${h} .rte-conditional-summary,
    .${c}.rte-conditional-theme-dark .rte-conditional-summary {
      color: #e2e8f0;
    }

    ${b} .rte-conditional-meta,
    ${h} .rte-conditional-meta,
    .${c}.rte-conditional-theme-dark .rte-conditional-meta {
      color: #94a3b8;
    }

    ${b} .rte-conditional-chip,
    ${h} .rte-conditional-chip,
    .${c}.rte-conditional-theme-dark .rte-conditional-chip {
      background: #1e3a8a;
      border-color: #3b82f6;
      color: #dbeafe;
    }

    ${b} .rte-conditional-chip-else,
    ${h} .rte-conditional-chip-else,
    .${c}.rte-conditional-theme-dark .rte-conditional-chip-else {
      background: #7f1d1d;
      border-color: #ef4444;
      color: #fee2e2;
    }

    ${b} .rte-conditional-body,
    ${h} .rte-conditional-body,
    .${c}.rte-conditional-theme-dark .rte-conditional-body {
      background: #1f2937;
      color: #e2e8f0;
    }

    ${b} .rte-conditional-dialog,
    ${h} .rte-conditional-dialog,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog {
      background: #1f2937;
      border-color: #334155;
    }

    ${b} .rte-conditional-dialog-header,
    ${b} .rte-conditional-dialog-footer,
    ${h} .rte-conditional-dialog-header,
    ${h} .rte-conditional-dialog-footer,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-header,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-footer {
      background: #111827;
      border-color: #334155;
    }

    ${b} .rte-conditional-dialog-title,
    ${b} .rte-conditional-field label,
    ${b} .rte-conditional-checkbox,
    ${h} .rte-conditional-dialog-title,
    ${h} .rte-conditional-field label,
    ${h} .rte-conditional-checkbox,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-title,
    .${c}.rte-conditional-theme-dark .rte-conditional-field label,
    .${c}.rte-conditional-theme-dark .rte-conditional-checkbox {
      color: #e2e8f0;
    }

    ${b} .rte-conditional-help,
    ${h} .rte-conditional-help,
    .${c}.rte-conditional-theme-dark .rte-conditional-help {
      color: #94a3b8;
    }

    ${b} .rte-conditional-field input[type="text"],
    ${b} .rte-conditional-btn,
    ${h} .rte-conditional-field input[type="text"],
    ${h} .rte-conditional-btn,
    .${c}.rte-conditional-theme-dark .rte-conditional-field input[type="text"],
    .${c}.rte-conditional-theme-dark .rte-conditional-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    ${b} .rte-conditional-btn-primary,
    ${h} .rte-conditional-btn-primary,
    .${c}.rte-conditional-theme-dark .rte-conditional-btn-primary {
      border-color: #3b82f6;
      background: #2563eb;
      color: #ffffff;
    }

    ${b} .rte-toolbar-group-items.conditional-content,
    .${c}.rte-conditional-theme-dark .rte-toolbar-group-items.conditional-content,
    ${h} .rte-toolbar-group-items.conditional-content,
    ${b} .editora-toolbar-group-items.conditional-content {
      border-color: #566275;
    }

    ${b} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${h} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${b} .editora-toolbar-group-items.conditional-content .editora-toolbar-button {
      border-right-color: #566275;
    }

    ${b} .${u},
    .${c}.rte-conditional-theme-dark .${u},
    .${u}.rte-conditional-theme-dark {
      background: rgba(17, 24, 39, 0.98);
      border-color: #334155;
      box-shadow: 0 14px 30px rgba(2, 6, 23, 0.5);
    }

    ${b} .${u} .rte-conditional-float-btn,
    .${c}.rte-conditional-theme-dark .${u} .rte-conditional-float-btn,
    .${u}.rte-conditional-theme-dark .rte-conditional-float-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    ${b} .${u} .rte-conditional-float-btn[data-action="delete"],
    .${c}.rte-conditional-theme-dark .${u} .rte-conditional-float-btn[data-action="delete"],
    .${u}.rte-conditional-theme-dark .rte-conditional-float-btn[data-action="delete"] {
      border-color: #ef4444;
      color: #fecaca;
      background: rgba(127, 29, 29, 0.45);
    }

    ${f} .rte-conditional-block,
    ${g} .rte-conditional-block,
    .${c}.rte-conditional-theme-acme .rte-conditional-block {
      background: #f8fbff;
      border-color: #cbd8e8;
    }

    ${f} .rte-conditional-header,
    ${f} .rte-conditional-else-label,
    ${g} .rte-conditional-header,
    ${g} .rte-conditional-else-label,
    .${c}.rte-conditional-theme-acme .rte-conditional-header,
    .${c}.rte-conditional-theme-acme .rte-conditional-else-label {
      background: linear-gradient(180deg, #eef4fb 0%, #e6eef8 100%);
      border-color: #cbd8e8;
    }

    ${f} .rte-conditional-summary,
    ${g} .rte-conditional-summary,
    .${c}.rte-conditional-theme-acme .rte-conditional-summary {
      color: #0f172a;
    }

    ${f} .rte-conditional-meta,
    ${g} .rte-conditional-meta,
    .${c}.rte-conditional-theme-acme .rte-conditional-meta {
      color: #587089;
    }

    ${f} .rte-conditional-chip,
    ${g} .rte-conditional-chip,
    .${c}.rte-conditional-theme-acme .rte-conditional-chip {
      background: #d9f5ee;
      border-color: #66c6b3;
      color: #0f4f4a;
    }

    ${f} .rte-conditional-chip-else,
    ${g} .rte-conditional-chip-else,
    .${c}.rte-conditional-theme-acme .rte-conditional-chip-else {
      background: #fde8ea;
      border-color: #f1a7b2;
      color: #8b1f2f;
    }

    ${f} .rte-conditional-body,
    ${g} .rte-conditional-body,
    .${c}.rte-conditional-theme-acme .rte-conditional-body {
      background: #fcfeff;
      color: #0f172a;
    }

    ${f} .rte-conditional-dialog,
    ${g} .rte-conditional-dialog,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog {
      background: #ffffff;
      border-color: #cbd8e8;
      box-shadow: 0 20px 44px rgba(15, 23, 42, 0.18);
    }

    ${f} .rte-conditional-dialog-header,
    ${f} .rte-conditional-dialog-footer,
    ${g} .rte-conditional-dialog-header,
    ${g} .rte-conditional-dialog-footer,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-header,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-footer {
      background: #f3f8fd;
      border-color: #d8e4f1;
    }

    ${f} .rte-conditional-dialog-title,
    ${f} .rte-conditional-field label,
    ${f} .rte-conditional-checkbox,
    ${g} .rte-conditional-dialog-title,
    ${g} .rte-conditional-field label,
    ${g} .rte-conditional-checkbox,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-title,
    .${c}.rte-conditional-theme-acme .rte-conditional-field label,
    .${c}.rte-conditional-theme-acme .rte-conditional-checkbox {
      color: #1f334a;
    }

    ${f} .rte-conditional-help,
    ${g} .rte-conditional-help,
    .${c}.rte-conditional-theme-acme .rte-conditional-help {
      color: #5f738d;
    }

    ${f} .rte-conditional-field input[type="text"],
    ${f} .rte-conditional-btn,
    ${g} .rte-conditional-field input[type="text"],
    ${g} .rte-conditional-btn,
    .${c}.rte-conditional-theme-acme .rte-conditional-field input[type="text"],
    .${c}.rte-conditional-theme-acme .rte-conditional-btn {
      background: #ffffff;
      border-color: #bfd0e2;
      color: #0f172a;
    }

    ${f} .rte-conditional-btn-primary,
    ${g} .rte-conditional-btn-primary,
    .${c}.rte-conditional-theme-acme .rte-conditional-btn-primary {
      border-color: #0f766e;
      background: #0f766e;
      color: #ffffff;
    }

    ${f} .rte-toolbar-group-items.conditional-content,
    .${c}.rte-conditional-theme-acme .rte-toolbar-group-items.conditional-content,
    ${g} .rte-toolbar-group-items.conditional-content,
    ${f} .editora-toolbar-group-items.conditional-content {
      border-color: #bfd0e2;
    }

    ${f} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${g} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${f} .editora-toolbar-group-items.conditional-content .editora-toolbar-button {
      border-right-color: #bfd0e2;
    }

    ${f} .${u},
    .${c}.rte-conditional-theme-acme .${u},
    .${u}.rte-conditional-theme-acme {
      background: rgba(255, 255, 255, 0.98);
      border-color: #bfd0e2;
      box-shadow: 0 14px 28px rgba(15, 23, 42, 0.16);
    }

    ${f} .${u} .rte-conditional-float-btn,
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn,
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn {
      background: #ffffff;
      border-color: #bfd0e2;
      color: #1f334a;
    }

    ${f} .${u} .rte-conditional-float-btn:hover,
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn:hover,
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn:hover {
      background: #eef7f5;
      color: #0f4f4a;
    }

    ${f} .${u} .rte-conditional-float-btn[data-action="delete"],
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn[data-action="delete"],
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn[data-action="delete"] {
      border-color: #f1a7b2;
      color: #8b1f2f;
      background: #fff4f6;
    }
  `, document.head.appendChild(e);
}
function Ue(e) {
  return {
    defaultCondition: e.defaultCondition || "",
    defaultAudience: ie(e.defaultAudience || []),
    defaultLocale: ie(e.defaultLocale || []),
    enableElseByDefault: e.enableElseByDefault === !0,
    labels: Fe(e.labels),
    context: e.context,
    getContext: e.getContext,
    currentAudience: e.currentAudience,
    currentLocale: e.currentLocale,
    evaluateCondition: e.evaluateCondition || Ze
  };
}
function Oe() {
  de && (de.cleanup(), de = null);
}
function Ye(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function ae(e, t) {
  e.setAttribute("contenteditable", "false"), e.setAttribute("spellcheck", "false");
  const o = e.querySelector(".rte-conditional-header");
  o && (o.setAttribute("contenteditable", "false"), o.setAttribute("tabindex", "0"), o.setAttribute("role", "button"), o.setAttribute("aria-label", "Edit conditional rule"));
  const i = e.querySelector(".rte-conditional-else-label");
  i && i.setAttribute("contenteditable", "false"), Qe(e, !t);
}
function Je(e) {
  const t = e.querySelector('.rte-conditional-body[data-slot="if"]');
  if (!t) return;
  const o = /* @__PURE__ */ new Set(), i = e.querySelector(".rte-conditional-header"), n = e.querySelector(".rte-conditional-else-label"), a = e.querySelector('.rte-conditional-body[data-slot="else"]');
  i && o.add(i), o.add(t), n && o.add(n), a && o.add(a), Array.from(e.childNodes).forEach((l) => {
    if (!(l instanceof HTMLElement && o.has(l))) {
      if (l.nodeType === Node.TEXT_NODE && !(l.textContent || "").trim()) {
        l.remove();
        return;
      }
      t.appendChild(l);
    }
  });
}
function U(e) {
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    const n = t.getRangeAt(0).startContainer, a = n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement, r = a == null ? void 0 : a.closest(P);
    if (r && e.contains(r)) return r;
  }
  const o = document.activeElement, i = o == null ? void 0 : o.closest(P);
  return i && e.contains(i) ? i : null;
}
function Ae(e, t) {
  let o = e.querySelector(".rte-conditional-else-label"), i = e.querySelector('.rte-conditional-body[data-slot="else"]');
  o || (o = document.createElement("div"), o.className = "rte-conditional-else-label", o.setAttribute("contenteditable", "false"), o.innerHTML = `
      <span class="rte-conditional-chip rte-conditional-chip-else">${$(t.blockElseLabel)}</span>
      <span class="rte-conditional-summary">Else branch</span>
    `, e.appendChild(o)), i || (i = document.createElement("div"), i.className = "rte-conditional-body rte-conditional-else-body", i.setAttribute("data-slot", "else"), i.innerHTML = "<p><br></p>", e.appendChild(i));
}
function Xe(e, t) {
  e.setAttribute("data-has-else", t ? "true" : "false");
  const o = e.querySelector(".rte-conditional-else-label"), i = e.querySelector('.rte-conditional-body[data-slot="else"]');
  o && o.classList.toggle("rte-conditional-hidden", !t), i && i.classList.toggle("rte-conditional-hidden", !t);
}
function Qe(e, t) {
  Array.from(e.querySelectorAll(".rte-conditional-body")).forEach((i) => {
    i.setAttribute("contenteditable", t ? "true" : "false");
  }), e.setAttribute("contenteditable", "false");
}
function we(e, t) {
  const o = e.getAttribute("data-condition") || "", i = R(e.getAttribute("data-audience")), n = R(e.getAttribute("data-locale"));
  let a = e.querySelector(".rte-conditional-header");
  a || (a = document.createElement("div"), a.className = "rte-conditional-header", e.prepend(a)), a.setAttribute("contenteditable", "false"), a.setAttribute("tabindex", "0"), a.setAttribute("role", "button"), a.setAttribute("aria-label", "Edit conditional rule");
  const r = o || "(always true)", l = i.length > 0 ? i.join(", ") : t.allAudiencesText, d = n.length > 0 ? n.join(", ") : t.allLocalesText;
  if (a.innerHTML = `
    <span class="rte-conditional-chip">${$(t.blockIfLabel)}</span>
    <span class="rte-conditional-summary">${$(r)}</span>
    <span class="rte-conditional-meta">${$(l)} · ${$(d)}</span>
  `, !e.querySelector('.rte-conditional-body[data-slot="if"]')) {
    const m = document.createElement("div");
    m.className = "rte-conditional-body", m.setAttribute("data-slot", "if"), m.innerHTML = "<p><br></p>", e.insertBefore(m, e.children[1] || null);
  }
  const v = e.getAttribute("data-has-else") === "true";
  v && Ae(e, t), Je(e), Xe(e, v);
}
function Pe(e, t) {
  const o = document.createElement("section");
  o.className = "rte-conditional-block", o.setAttribute("data-conditional-content", "true"), o.setAttribute("data-condition", (e.condition || "").trim()), o.setAttribute("data-audience", ie(e.audience).join(",")), o.setAttribute("data-locale", ie(e.locale).join(",")), o.setAttribute("data-has-else", e.hasElse ? "true" : "false"), o.setAttribute("role", "group"), o.setAttribute("aria-label", "Conditional content block"), o.setAttribute("contenteditable", "false"), o.setAttribute("spellcheck", "false");
  const i = document.createElement("div");
  i.className = "rte-conditional-header", i.setAttribute("contenteditable", "false");
  const n = document.createElement("div");
  return n.className = "rte-conditional-body", n.setAttribute("data-slot", "if"), n.innerHTML = "<p><br></p>", o.appendChild(i), o.appendChild(n), e.hasElse && Ae(o, t), we(o, t), ae(o, !1), o;
}
function et(e, t) {
  if (t)
    try {
      if (!e.isConnected) return;
      const o = e.contains(t.startContainer), i = e.contains(t.endContainer);
      if (!o || !i) return;
      Le(e, t);
    } catch (o) {
    }
}
function tt(e) {
  return (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !0 : e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol") !== null;
}
function Re(e, t, o) {
  let i = null;
  i || (i = Ne(e)), i || (i = document.createRange(), i.selectNodeContents(e), i.collapse(!1));
  let n = null;
  i.collapsed || (n = i.extractContents()), i.insertNode(t);
  const a = t.querySelector('.rte-conditional-body[data-slot="if"]');
  a && n && tt(n) && (a.innerHTML = "", a.appendChild(n)), a ? $e(e, a) : $e(e, t), e.normalize();
}
function ot(e) {
  return {
    condition: e.getAttribute("data-condition") || "",
    audience: R(e.getAttribute("data-audience")),
    locale: R(e.getAttribute("data-locale")),
    hasElse: e.getAttribute("data-has-else") === "true"
  };
}
function nt(e, t, o) {
  e.setAttribute("data-condition", (t.condition || "").trim()), e.setAttribute("data-audience", ie(t.audience).join(",")), e.setAttribute("data-locale", ie(t.locale).join(",")), e.setAttribute("data-has-else", t.hasElse ? "true" : "false"), t.hasElse && Ae(e, o), we(e, o), ae(e, e.classList.contains("rte-conditional-preview"));
}
function re(e, t) {
  xe(e, e);
  const o = Array.from(e.querySelectorAll(P)), i = k.get(e) === !0;
  return o.forEach((n) => {
    n.classList.add("rte-conditional-block"), n.setAttribute("data-conditional-content", "true"), n.hasAttribute("data-condition") || n.setAttribute("data-condition", ""), n.hasAttribute("data-audience") || n.setAttribute("data-audience", ""), n.hasAttribute("data-locale") || n.setAttribute("data-locale", ""), n.hasAttribute("data-has-else") || n.setAttribute("data-has-else", "false"), n.setAttribute("role", "group"), n.setAttribute("aria-label", "Conditional content block"), n.setAttribute("contenteditable", "false"), n.setAttribute("spellcheck", "false"), we(n, t), ae(n, i);
  }), o;
}
async function it(e, t) {
  const o = Ce.get(e);
  if (o)
    return o;
  if (typeof t.getContext == "function")
    try {
      const i = se(e), n = await Promise.resolve(t.getContext({ editor: e, editorRoot: i }));
      if (n && typeof n == "object")
        return n;
    } catch (i) {
      return {};
    }
  if (typeof t.context == "function")
    try {
      const i = t.context();
      if (i && typeof i == "object")
        return i;
    } catch (i) {
      return {};
    }
  return t.context && typeof t.context == "object" ? t.context : {};
}
function ge(e) {
  return Array.isArray(e) ? e.map((t) => t.trim().toLowerCase()).filter(Boolean) : typeof e == "string" ? e.split(",").map((t) => t.trim().toLowerCase()).filter(Boolean) : [];
}
function Be(e, t) {
  return e.length === 0 || e.includes("all") ? !0 : t.length === 0 ? !1 : e.some((o) => t.includes(o));
}
async function Y(e, t, o) {
  var T, ue, B, V;
  const i = t.labels, n = re(e, i);
  if (k.set(e, o), qe(e, o), se(e).classList.toggle("rte-conditional-preview-on", o), !o) {
    n.forEach((p) => {
      p.classList.remove("rte-conditional-preview"), ae(p, !1);
      const M = p.querySelector('.rte-conditional-body[data-slot="if"]'), C = p.querySelector('.rte-conditional-body[data-slot="else"]'), q = p.querySelector(".rte-conditional-else-label"), N = p.getAttribute("data-has-else") === "true";
      M && (M.classList.remove("rte-conditional-hidden"), M.removeAttribute("aria-hidden")), C && (C.classList.toggle("rte-conditional-hidden", !N), C.setAttribute("aria-hidden", N ? "false" : "true")), q && q.classList.toggle("rte-conditional-hidden", !N);
    });
    return;
  }
  const r = await it(e, t), l = ge(t.currentAudience), d = ge(t.currentLocale), x = ge(
    (ue = r.audience) != null ? ue : (T = r.user) == null ? void 0 : T.audience
  ), v = ge(
    (V = r.locale) != null ? V : (B = r.user) == null ? void 0 : B.locale
  ), m = l.length > 0 ? l : x, S = d.length > 0 ? d : v;
  n.forEach((p) => {
    const M = p.getAttribute("data-condition") || "", C = R(p.getAttribute("data-audience")).map((s) => s.toLowerCase()), q = R(p.getAttribute("data-locale")).map((s) => s.toLowerCase()), N = p.getAttribute("data-has-else") === "true", Ee = t.evaluateCondition(M, r), fe = Be(C, m), be = Be(q, S), K = Ee && fe && be, W = p.querySelector('.rte-conditional-body[data-slot="if"]'), Z = p.querySelector('.rte-conditional-body[data-slot="else"]'), le = p.querySelector(".rte-conditional-else-label");
    if (p.classList.add("rte-conditional-preview"), ae(p, !0), W && (W.classList.toggle("rte-conditional-hidden", !K), W.setAttribute("aria-hidden", K ? "false" : "true")), Z) {
      const s = N && !K;
      Z.classList.toggle("rte-conditional-hidden", !s), Z.setAttribute("aria-hidden", s ? "false" : "true");
    }
    if (le) {
      const s = N && !K;
      le.classList.toggle("rte-conditional-hidden", !s);
    }
  });
}
function qe(e, t) {
  const o = se(e);
  Array.from(
    o.querySelectorAll('[data-command="toggleConditionalPreview"], [data-command="conditionalPreview"]')
  ).forEach((n) => {
    n.setAttribute("data-active", t ? "true" : "false"), n.classList.toggle("active", t), n.setAttribute("aria-pressed", t ? "true" : "false");
  });
}
function at(e) {
  const t = j.get(e);
  if (t && t.isConnected) return t;
  const o = document.createElement("div");
  return o.className = u, o.setAttribute("role", "toolbar"), o.setAttribute("aria-label", "Conditional block actions"), o.innerHTML = `
    <button type="button" class="rte-conditional-float-btn" data-action="edit" title="Edit Condition" aria-label="Edit Condition">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 17.3V20h2.7l9.7-9.7-2.7-2.7L4 17.3Zm14.7-9.4a1 1 0 0 0 0-1.4l-1.2-1.2a1 1 0 0 0-1.4 0l-1.1 1.1 2.7 2.7 1-1.2Z" fill="currentColor"></path></svg>
    </button>
    <button type="button" class="rte-conditional-float-btn" data-action="delete" title="Delete Block" aria-label="Delete Block">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M8 4h8l1 2h4v2H3V6h4l1-2Zm1 6h2v8H9v-8Zm4 0h2v8h-2v-8Z" fill="currentColor"></path></svg>
    </button>
  `, o.addEventListener("mousedown", (i) => {
    i.preventDefault();
  }), o.addEventListener("click", (i) => {
    var d;
    const n = i.target, a = (d = n == null ? void 0 : n.closest("[data-action]")) == null ? void 0 : d.getAttribute("data-action");
    if (!a) return;
    const r = E.get(e) || ne;
    if (!r) return;
    const l = I.get(e);
    if (!(!l || !e.contains(l))) {
      if (a === "edit") {
        L(e, r, "edit", void 0, l);
        return;
      }
      a === "delete" && (_e(e, l), I.set(e, null), F(e));
    }
  }), document.body.appendChild(o), j.set(e, o), o;
}
function F(e) {
  const t = j.get(e);
  t && t.classList.remove("show");
}
function Ke(e, t) {
  const o = t.getBoundingClientRect();
  e.style.left = "0px", e.style.top = "0px", e.classList.add("show");
  const i = e.getBoundingClientRect(), n = 8, a = window.innerWidth, r = window.innerHeight;
  let l = o.top - i.height - n;
  l < n && (l = o.bottom + n), l = Math.min(l, r - i.height - n);
  let d = o.right - i.width;
  d = Math.max(n, Math.min(d, a - i.width - n)), e.style.left = `${d}px`, e.style.top = `${l}px`;
}
function ye(e, t) {
  const o = at(e);
  xe(o, e), I.set(e, t), Ke(o, t);
}
function O(e) {
  const t = E.get(e) || ne;
  if (!t) return;
  const o = U(e);
  if (!o || !e.contains(o) || D(e)) {
    I.set(e, null), F(e);
    return;
  }
  re(e, t.labels), ye(e, o);
}
function rt() {
  j.forEach((e, t) => {
    if (!t.isConnected || !e.isConnected) {
      e.remove(), j.delete(t), I.delete(t);
      return;
    }
    if (!e.classList.contains("show")) return;
    xe(e, t);
    const o = I.get(t);
    if (!o || !t.contains(o)) {
      F(t);
      return;
    }
    Ke(e, o);
  });
}
function _e(e, t) {
  if (!e.contains(t)) return !1;
  const o = e.innerHTML, i = t.parentNode, n = t.nextSibling;
  t.remove(), i === e && e.innerHTML.trim() === "" && (e.innerHTML = "<p><br></p>");
  const a = document.createRange();
  return n && e.contains(n) ? a.setStartBefore(n) : (a.selectNodeContents(e), a.collapse(!1)), a.collapse(!0), Le(e, a), De(e), He(e, o), !0;
}
function Me(e, t, o) {
  const i = e.cloneRange(), n = document.createRange();
  return n.selectNodeContents(t), n.collapse(o === "start"), i.startContainer === n.startContainer && i.startOffset === n.startOffset && i.endContainer === n.endContainer && i.endOffset === n.endOffset;
}
function L(e, t, o, i, n) {
  var K, W, Z, le;
  Oe();
  const a = t.labels, r = o === "insert" ? Ne(e) : null, l = document.createElement("div");
  l.className = c, xe(l, e);
  const d = document.createElement("section");
  d.className = "rte-conditional-dialog", d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-labelledby", "rte-conditional-dialog-title");
  const x = n ? ot(n) : void 0, v = i || x || {}, m = (K = v.condition) != null ? K : t.defaultCondition, S = (W = v.audience) != null ? W : t.defaultAudience, T = (Z = v.locale) != null ? Z : t.defaultLocale, ue = (le = v.hasElse) != null ? le : t.enableElseByDefault;
  d.innerHTML = `
    <header class="rte-conditional-dialog-header">
      <h2 id="rte-conditional-dialog-title" class="rte-conditional-dialog-title">${$(
    o === "edit" ? a.dialogTitleEdit : a.dialogTitleInsert
  )}</h2>
      <button type="button" class="rte-conditional-btn" data-action="cancel" aria-label="${$(a.cancelText)}">✕</button>
    </header>
    <div class="rte-conditional-dialog-body">
      <div class="rte-conditional-field">
        <label for="rte-conditional-condition">${$(a.conditionLabel)}</label>
        <input id="rte-conditional-condition" class="rte-conditional-input-condition" type="text" value="${$(
    m || ""
  )}" placeholder="${$(a.conditionPlaceholder)}" />
      </div>
      <div class="rte-conditional-field">
        <label for="rte-conditional-audience">${$(a.audienceLabel)}</label>
        <input id="rte-conditional-audience" class="rte-conditional-input-audience" type="text" value="${$(
    Te(S)
  )}" placeholder="${$(a.audiencePlaceholder)}" />
      </div>
      <div class="rte-conditional-field">
        <label for="rte-conditional-locale">${$(a.localeLabel)}</label>
        <input id="rte-conditional-locale" class="rte-conditional-input-locale" type="text" value="${$(
    Te(T)
  )}" placeholder="${$(a.localePlaceholder)}" />
      </div>
      <label class="rte-conditional-checkbox">
        <input class="rte-conditional-input-else" type="checkbox" ${ue ? "checked" : ""} />
        <span>${$(a.elseLabel)}</span>
      </label>
      <p class="rte-conditional-help">Example condition: <code>user.role == "admin"</code>, <code>locale == "en-US"</code>, <code>!feature.beta</code></p>
    </div>
    <footer class="rte-conditional-dialog-footer">
      <button type="button" class="rte-conditional-btn" data-action="cancel">${$(a.cancelText)}</button>
      <button type="button" class="rte-conditional-btn rte-conditional-btn-primary" data-action="save">${$(a.saveText)}</button>
    </footer>
  `, l.appendChild(d), document.body.appendChild(l);
  const B = d.querySelector(".rte-conditional-input-condition"), V = d.querySelector(".rte-conditional-input-audience"), p = d.querySelector(".rte-conditional-input-locale"), M = d.querySelector(".rte-conditional-input-else"), C = () => {
    l.removeEventListener("click", N), l.removeEventListener("keydown", be, !0), document.removeEventListener("keydown", q, !0), l.parentNode && l.parentNode.removeChild(l), de = null, e.focus({ preventScroll: !0 }), O(e);
  }, q = (s) => {
    s.key === "Escape" && (s.preventDefault(), s.stopPropagation(), C());
  }, N = (s) => {
    s.target === l && C();
  }, Ee = (s) => {
    if (s.key !== "Tab") return;
    const _ = Array.from(
      d.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')
    );
    if (_.length === 0) return;
    const G = _[0], ce = _[_.length - 1], z = document.activeElement;
    if (s.shiftKey && z === G) {
      s.preventDefault(), ce.focus();
      return;
    }
    !s.shiftKey && z === ce && (s.preventDefault(), G.focus());
  }, fe = async () => {
    var ce;
    const s = {
      condition: ((ce = B == null ? void 0 : B.value) == null ? void 0 : ce.trim()) || "",
      audience: R(V == null ? void 0 : V.value),
      locale: R(p == null ? void 0 : p.value),
      hasElse: (M == null ? void 0 : M.checked) || !1
    }, _ = e.innerHTML;
    if (n)
      nt(n, s, a), ae(n, k.get(e) === !0);
    else {
      et(e, r);
      const z = Pe(s, a);
      try {
        Re(e, z);
      } catch (ut) {
        e.appendChild(z);
        const ke = z.querySelector('.rte-conditional-body[data-slot="if"]');
        ke ? $e(e, ke) : $e(e, z);
      }
    }
    k.get(e) === !0 && await Y(e, t, !0), De(e), He(e, _), O(e), C();
  }, be = (s) => {
    if (s.key === "Escape") {
      s.preventDefault(), C();
      return;
    }
    Ee(s), s.key === "Enter" && !s.shiftKey && s.target instanceof HTMLInputElement && (s.preventDefault(), fe());
  };
  d.addEventListener("click", (s) => {
    const G = s.target.getAttribute("data-action");
    if (G === "cancel") {
      C();
      return;
    }
    G === "save" && fe();
  }), l.addEventListener("click", N), l.addEventListener("keydown", be, !0), document.addEventListener("keydown", q, !0), de = { cleanup: C }, B == null || B.focus();
}
function lt(e) {
  const t = e.metaKey || e.ctrlKey, i = (typeof e.key == "string" ? e.key : "").toLowerCase(), n = typeof e.code == "string" ? e.code.toLowerCase() : "", a = t && e.altKey && e.shiftKey && (i === "c" || n === "keyc"), r = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (i === "f9" || n === "f9");
  return a || r;
}
function ct(e) {
  const t = e.metaKey || e.ctrlKey, i = (typeof e.key == "string" ? e.key : "").toLowerCase(), n = typeof e.code == "string" ? e.code.toLowerCase() : "", a = t && e.altKey && e.shiftKey && (i === "p" || n === "keyp"), r = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (i === "f10" || n === "f10");
  return a || r;
}
function dt(e) {
  ne = e, X || (X = (t) => {
    const o = t.target, i = o == null ? void 0 : o.closest(A);
    if (!i) return;
    y = i, E.has(i) || E.set(i, e);
    const n = E.get(i) || e;
    re(i, n.labels), qe(i, k.get(i) === !0), O(i);
  }, document.addEventListener("focusin", X, !0)), J || (J = (t) => {
    var v;
    if (document.querySelector(`.${c}`)) return;
    const i = t.target;
    if (!!(i != null && i.closest("input, textarea, select"))) return;
    const r = (i == null ? void 0 : i.closest(A)) || w(void 0, !1) || y;
    if (!r || D(r)) return;
    const l = E.get(r) || ne || e, d = document.activeElement, x = (i == null ? void 0 : i.closest(".rte-conditional-header")) || (d == null ? void 0 : d.closest(".rte-conditional-header"));
    if (x && (t.key === "Enter" || t.key === " ")) {
      const m = x.closest(P);
      if (m && r.contains(m)) {
        t.preventDefault(), t.stopPropagation(), L(r, l, "edit", void 0, m);
        return;
      }
    }
    if (lt(t)) {
      t.preventDefault(), t.stopPropagation();
      const m = U(r);
      m ? L(r, l, "edit", void 0, m) : L(r, l, "insert");
      return;
    }
    if (ct(t)) {
      t.preventDefault(), t.stopPropagation();
      const m = k.get(r) !== !0;
      Y(r, l, m), O(r);
      return;
    }
    if ((t.key === "Backspace" || t.key === "Delete") && !t.altKey && !t.ctrlKey && !t.metaKey) {
      const m = window.getSelection();
      if (!m || m.rangeCount === 0) return;
      const S = m.getRangeAt(0);
      if (!S.collapsed || !r.contains(S.commonAncestorContainer)) return;
      const T = (v = Ye(S.startContainer)) == null ? void 0 : v.closest(".rte-conditional-body");
      if (!T || !r.contains(T)) return;
      if (t.key === "Backspace" && Me(S, T, "start")) {
        t.preventDefault();
        return;
      }
      if (t.key === "Delete" && Me(S, T, "end")) {
        t.preventDefault();
        return;
      }
    }
  }, document.addEventListener("keydown", J, !0)), ee || (ee = (t) => {
    const o = t.target;
    if (!o || o.closest(`.${u}`)) return;
    const i = o.closest(A);
    if (!i) {
      y && F(y);
      return;
    }
    if (D(i)) return;
    y = i, E.has(i) || E.set(i, e);
    const n = o.closest(P);
    if (!n) {
      F(i);
      return;
    }
    requestAnimationFrame(() => {
      !i.isConnected || !i.contains(n) || ye(i, n);
    });
  }, document.addEventListener("mousedown", ee, !0)), Q || (Q = (t) => {
    const o = t.target;
    if (!o || o.closest(`.${u}`)) return;
    const i = o.closest(A);
    if (!i) {
      y && F(y);
      return;
    }
    if (D(i)) return;
    y = i, E.has(i) || E.set(i, e);
    const n = E.get(i) || e, a = o.closest(P), r = !!o.closest(".rte-conditional-header, .rte-conditional-summary, .rte-conditional-meta, .rte-conditional-else-label");
    if (a && r) {
      t.preventDefault(), t.stopPropagation(), L(i, n, "edit", void 0, a), ye(i, a);
      return;
    }
    a ? ye(i, a) : F(i);
  }, document.addEventListener("click", Q, !0)), te || (te = () => {
    const t = w(void 0, !1) || y;
    t && t.isConnected && O(t);
  }, document.addEventListener("selectionchange", te)), oe || (oe = (t) => {
    const o = t.target, i = o == null ? void 0 : o.closest(A);
    if (!i) return;
    const n = E.get(i) || ne || e;
    re(i, n.labels), O(i);
  }, document.addEventListener("input", oe, !0)), H || (H = () => {
    rt();
  }, window.addEventListener("scroll", H, !0), window.addEventListener("resize", H));
}
function st() {
  X && (document.removeEventListener("focusin", X, !0), X = null), J && (document.removeEventListener("keydown", J, !0), J = null), Q && (document.removeEventListener("click", Q, !0), Q = null), ee && (document.removeEventListener("mousedown", ee, !0), ee = null), te && (document.removeEventListener("selectionchange", te), te = null), oe && (document.removeEventListener("input", oe, !0), oe = null), H && (window.removeEventListener("scroll", H, !0), window.removeEventListener("resize", H), H = null), j.forEach((e) => {
    e.remove();
  }), j.clear(), I.clear(), ne = null, y = null;
}
const ft = (e = {}) => {
  const t = Ue(e);
  return Ge(), {
    name: "conditionalContent",
    toolbar: [
      {
        id: "conditionalContentGroup",
        label: "Conditional Content",
        type: "group",
        command: "conditionalContent",
        items: [
          {
            id: "conditionalContent",
            label: "Conditional Rule",
            command: "openConditionalDialog",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M6 5h12a1 1 0 0 1 1 1v3h-2V7H7v3H5V6a1 1 0 0 1 1-1Zm-1 9h2v3h10v-3h2v4a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-4Zm3-2a1 1 0 0 1 1-1h2.6l1.8-2.4a1 1 0 1 1 1.6 1.2L13.8 11H15a1 1 0 1 1 0 2h-2.7l-1.9 2.5a1 1 0 1 1-1.6-1.2L10.1 13H9a1 1 0 0 1-1-1Z" fill="currentColor"></path></svg>',
            shortcut: "Mod-Alt-Shift-c"
          },
          {
            id: "conditionalPreview",
            label: "Conditional Preview",
            command: "toggleConditionalPreview",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 6h16a1 1 0 0 1 1 1v3h-2V8H5v8h14v-2h2v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1Zm5 3h2v2H9V9Zm0 4h2v2H9v-2Zm4-4h6v2h-6V9Zm0 4h6v2h-6v-2Z" fill="currentColor"></path></svg>',
            shortcut: "Mod-Alt-Shift-p"
          }
        ]
      }
    ],
    commands: {
      conditionalContent: (o, i) => {
        const n = w(i);
        if (!n || D(n)) return !1;
        y = n, E.set(n, t), re(n, t.labels);
        const a = o == null ? void 0 : o.target;
        if (a === "insert")
          return L(n, t, "insert", o), !0;
        const r = U(n);
        return a === "edit" || r ? !r && a === "edit" ? !1 : (L(n, t, "edit", o, r || void 0), !0) : (L(n, t, "insert", o), !0);
      },
      openConditionalDialog: (o, i) => {
        const n = w(i);
        if (!n || D(n)) return !1;
        y = n, E.set(n, t), re(n, t.labels);
        const a = o == null ? void 0 : o.target;
        if (a === "insert")
          return L(n, t, "insert", o), !0;
        const r = U(n);
        return a === "edit" || r ? !r && a === "edit" ? !1 : (L(n, t, "edit", o, r || void 0), !0) : (L(n, t, "insert", o), !0);
      },
      conditionalPreview: async (o, i) => {
        const n = w(i);
        if (!n) return !1;
        y = n, E.set(n, t);
        const a = typeof o == "boolean" ? o : k.get(n) !== !0;
        return await Y(n, t, a), O(n), !0;
      },
      editConditionalBlock: (o, i) => {
        const n = w(i);
        if (!n || D(n)) return !1;
        y = n, E.set(n, t);
        const a = U(n);
        return a ? (L(n, t, "edit", o, a), !0) : !1;
      },
      deleteConditionalBlock: (o, i) => {
        const n = w(i);
        if (!n || D(n)) return !1;
        const a = U(n);
        if (!a) return !1;
        const r = _e(n, a);
        return r && O(n), r;
      },
      insertConditionalBlock: (o, i) => {
        var d, x, v, m;
        const n = w(i);
        if (!n || D(n)) return !1;
        y = n, E.set(n, t);
        const a = {
          condition: (d = o == null ? void 0 : o.condition) != null ? d : t.defaultCondition,
          audience: (x = o == null ? void 0 : o.audience) != null ? x : t.defaultAudience,
          locale: (v = o == null ? void 0 : o.locale) != null ? v : t.defaultLocale,
          hasElse: (m = o == null ? void 0 : o.hasElse) != null ? m : t.enableElseByDefault
        }, r = Pe(a, t.labels);
        return Re(n, r), k.get(n) === !0 && Y(n, t, !0), !0;
      },
      toggleConditionalPreview: async (o, i) => {
        const n = w(i);
        if (!n) return !1;
        y = n, E.set(n, t);
        const a = typeof o == "boolean" ? o : k.get(n) !== !0;
        return await Y(n, t, a), !0;
      },
      setConditionalContext: (o, i) => {
        const n = w(i);
        return n ? (y = n, !o || typeof o != "object" ? Ce.delete(n) : Ce.set(n, o), k.get(n) === !0 && Y(n, t, !0), !0) : !1;
      }
    },
    keymap: {
      "Mod-Alt-Shift-c": "openConditionalDialog",
      "Mod-Alt-Shift-C": "openConditionalDialog",
      "Mod-Alt-Shift-p": "toggleConditionalPreview",
      "Mod-Alt-Shift-P": "toggleConditionalPreview",
      F9: "openConditionalDialog",
      F10: "toggleConditionalPreview"
    },
    init: () => {
      me += 1, dt(t);
    },
    destroy: () => {
      me = Math.max(0, me - 1), me === 0 && (Oe(), st());
    }
  };
};
export {
  ft as ConditionalContentPlugin
};
//# sourceMappingURL=ConditionalContentPlugin.native-CfhY46rU.mjs.map
