const y = ".rte-content, .editora-content", ie = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", fe = "__editoraCommandEditorRoot", he = "rte-doc-schema-styles", m = "rte-doc-schema-panel", E = "document-schema", T = "doc-schema", H = "docSchema", v = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', Ae = {
  panelTitle: "Document Schema",
  panelAriaLabel: "Document schema panel",
  schemaLabel: "Schema",
  schemaDescriptionPrefix: "Description",
  validateText: "Run Validation",
  insertMissingText: "Insert Missing Sections",
  realtimeOnText: "Realtime On",
  realtimeOffText: "Realtime Off",
  closeText: "Close",
  noIssuesText: "No schema violations detected.",
  summaryPrefix: "Schema",
  issueListLabel: "Schema issues",
  shortcutText: "Shortcuts: Ctrl/Cmd+Alt+Shift+G (panel), Ctrl/Cmd+Alt+Shift+J (validate)",
  helperText: "Choose a schema, validate structure, then insert missing sections safely.",
  readonlyMessage: "Editor is read-only. Missing sections cannot be inserted.",
  defaultPlaceholderText: "Add section content.",
  missingSectionMessage: "Missing required section",
  duplicateSectionMessage: "Section appears too many times",
  outOfOrderMessage: "Section appears out of required order",
  unknownHeadingMessage: "Heading is not part of selected schema",
  insertedSummaryPrefix: "Inserted missing sections"
}, u = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new Set();
let W = 0, Le = 0, ge = 0, w = null, p = null, q = null, z = null, B = null, R = null, K = null;
function M(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function Oe(e) {
  return e.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function P(e, t, n) {
  return Number.isFinite(e) ? Math.max(t, Math.min(n, e)) : t;
}
function xe(e) {
  return e.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
}
function ce(e, t) {
  return t(e).toLowerCase().replace(/^[\s\-\u2022]*(?:[0-9]+(?:\.[0-9]+)*)[\)\.\-:\s]+/, "").replace(/^[\s\-\u2022]*(?:[ivxlcdm]+)[\)\.\-:\s]+/i, "").replace(/[：:]+$/g, "").replace(/\s+/g, " ").trim();
}
function pe() {
  return [
    {
      id: "contract",
      label: "Contract",
      description: "Template for legal/commercial agreements with strict section ordering.",
      strictOrder: !0,
      allowUnknownHeadings: !1,
      sections: [
        { id: "summary", title: "Executive Summary", aliases: ["Overview"] },
        { id: "scope", title: "Scope" },
        { id: "terms", title: "Terms and Conditions", aliases: ["Terms"] },
        { id: "responsibilities", title: "Responsibilities" },
        { id: "sla", title: "Service Levels", aliases: ["SLA", "Service Level Agreement"] },
        { id: "termination", title: "Termination" }
      ]
    },
    {
      id: "sop",
      label: "SOP",
      description: "Standard operating procedure with clear implementation and governance sections.",
      strictOrder: !0,
      allowUnknownHeadings: !0,
      sections: [
        { id: "purpose", title: "Purpose" },
        { id: "scope", title: "Scope" },
        { id: "procedure", title: "Procedure", maxOccurrences: 10 },
        { id: "roles", title: "Roles and Responsibilities", aliases: ["Responsibilities"] },
        { id: "validation", title: "Validation" },
        { id: "revision-history", title: "Revision History", aliases: ["Change History"] }
      ]
    },
    {
      id: "policy",
      label: "Policy",
      description: "Policy document with control ownership, exception handling, and enforcement.",
      strictOrder: !0,
      allowUnknownHeadings: !0,
      sections: [
        { id: "statement", title: "Policy Statement" },
        { id: "applicability", title: "Applicability", aliases: ["Scope"] },
        { id: "controls", title: "Controls" },
        { id: "exceptions", title: "Exceptions" },
        { id: "enforcement", title: "Enforcement" }
      ]
    }
  ];
}
function He(e, t, n) {
  const r = n(e.title || "");
  if (!r) return null;
  const s = xe(n(e.id || r)) || `section-${t + 1}`, o = P(Number(e.minOccurrences ?? 1), 0, 20), a = Math.max(1, o), c = P(Number(e.maxOccurrences ?? a), o, 40), i = n(e.placeholder || ""), l = Array.isArray(e.aliases) ? e.aliases.map((S) => n(S)).filter(Boolean) : [], d = [r, ...l].map((S) => ce(S, n)).filter(Boolean);
  return {
    id: s,
    title: r,
    minOccurrences: o,
    maxOccurrences: c,
    placeholder: i,
    matchKeys: Array.from(new Set(d))
  };
}
function ye(e, t) {
  const n = Array.isArray(e) && e.length > 0 ? e : pe(), r = [], s = /* @__PURE__ */ new Set();
  return n.forEach((o, a) => {
    const c = t(o.label || "");
    if (!c) return;
    const i = xe(t(o.id || c)) || `schema-${a + 1}`;
    let l = i, d = 1;
    for (; s.has(l); )
      l = `${i}-${d++}`;
    s.add(l);
    const S = Array.isArray(o.sections) ? o.sections : [], f = [], k = /* @__PURE__ */ new Set();
    if (S.forEach(($, h) => {
      const x = He($, h, t);
      if (!x) return;
      let N = x.id, Me = 1;
      for (; k.has(N); )
        N = `${x.id}-${Me++}`;
      k.add(N), f.push({
        ...x,
        id: N
      });
    }), f.length === 0) return;
    const O = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map();
    f.forEach(($, h) => {
      A.set($.id, h), $.matchKeys.forEach((x) => {
        O.has(x) || O.set(x, $);
      });
    }), r.push({
      id: l,
      label: c,
      description: t(o.description || ""),
      strictOrder: o.strictOrder !== !1,
      allowUnknownHeadings: !!o.allowUnknownHeadings,
      sections: f,
      matchKeyToSection: O,
      orderBySectionId: A
    });
  }), r.length > 0 ? r : ye(pe(), t);
}
function Z(e = {}) {
  const t = e.normalizeText || Oe, n = ye(e.schemas, t), r = t(e.defaultSchemaId || ""), s = n.some((o) => o.id === r) ? r : n[0]?.id || null;
  return {
    schemas: n,
    defaultSchemaId: s,
    enableRealtime: e.enableRealtime !== !1,
    debounceMs: P(Number(e.debounceMs ?? 260), 60, 2e3),
    maxIssues: P(Number(e.maxIssues ?? 80), 5, 500),
    labels: {
      ...Ae,
      ...e.labels || {}
    },
    normalizeText: t
  };
}
function Re(e) {
  return {
    schemas: e.schemas.map((t) => ({
      id: t.id,
      label: t.label,
      description: t.description || void 0,
      strictOrder: t.strictOrder,
      allowUnknownHeadings: t.allowUnknownHeadings,
      sections: t.sections.map((n) => ({
        id: n.id,
        title: n.title,
        minOccurrences: n.minOccurrences,
        maxOccurrences: n.maxOccurrences,
        placeholder: n.placeholder || void 0
      }))
    })),
    defaultSchemaId: e.defaultSchemaId || void 0,
    enableRealtime: e.enableRealtime,
    debounceMs: e.debounceMs,
    maxIssues: e.maxIssues,
    labels: { ...e.labels },
    normalizeText: e.normalizeText
  };
}
function le(e) {
  return e.closest(ie) || e;
}
function U(e) {
  if (!e) return null;
  if (e.matches(y)) return e;
  const t = e.querySelector(y);
  return t instanceof HTMLElement ? t : null;
}
function De() {
  if (typeof window > "u") return null;
  const e = window[fe];
  if (!(e instanceof HTMLElement)) return null;
  window[fe] = null;
  const t = U(e);
  if (t) return t;
  const n = e.closest(ie);
  if (n) {
    const s = U(n);
    if (s) return s;
  }
  const r = e.closest(y);
  return r instanceof HTMLElement ? r : null;
}
function Ne(e) {
  const t = e.closest("[data-editora-editor]");
  if (t && U(t) === e)
    return t;
  let n = e;
  for (; n; ) {
    if (n.matches(ie) && (n === e || U(n) === e))
      return n;
    n = n.parentElement;
  }
  return le(e);
}
function Se(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function Y(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 Pe(e) {
  const t = le(e);
  if (Y(t)) return !0;
  const n = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return Y(n) ? !0 : Y(document.documentElement) || Y(document.body);
}
function oe(e, t) {
  e.classList.remove("rte-doc-schema-theme-dark"), Pe(t) && e.classList.add("rte-doc-schema-theme-dark");
}
function _e(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 s = n.removedNodes[r];
        if (s.nodeType !== Node.ELEMENT_NODE) continue;
        const o = s;
        if (o.matches?.(y) || o.matches?.(`.${m}`) || o.querySelector?.(y) || o.querySelector?.(`.${m}`))
          return !0;
      }
  }
  return !1;
}
function Q() {
  Array.from(ne).forEach((t) => {
    t.isConnected || ue(t);
  });
}
function I(e, t = !0, n = !0) {
  if (Q(), e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const c = U(e.editorElement);
    if (c) return c;
  }
  const r = De();
  if (r) return r;
  const s = window.getSelection();
  if (s && s.rangeCount > 0) {
    const c = Se(s.getRangeAt(0).startContainer)?.closest(
      y
    );
    if (c) return c;
  }
  const o = document.activeElement;
  if (o) {
    if (o.matches(y)) return o;
    const c = o.closest(y);
    if (c) return c;
  }
  if (n && p && p.isConnected)
    return p;
  if (!t) return null;
  const a = document.querySelector(y);
  return a instanceof HTMLElement ? a : null;
}
function qe(e) {
  const t = e.target;
  if (t) {
    const r = t.closest(`.${m}`);
    if (r) {
      const o = Array.from(b.entries()).find(([, a]) => a === r);
      if (o) return o[0];
    }
    const s = t.closest(y);
    if (s) return s;
  }
  const n = document.activeElement;
  if (n) {
    const r = n.closest(`.${m}`);
    if (r) {
      const o = Array.from(b.entries()).find(([, a]) => a === r);
      if (o) return o[0];
    }
    const s = n.closest(y);
    if (s) return s;
  }
  return null;
}
function be(e, t, n) {
  const r = Ne(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 de(e) {
  const t = te.get(e);
  typeof t == "number" && (window.clearTimeout(t), te.delete(e));
}
function L(e, t) {
  return t && e.schemas.find((n) => n.id === t) || null;
}
function re(e) {
  return e.defaultSchemaId || e.schemas[0]?.id || null;
}
function g(e, t) {
  u.has(e) || u.set(e, t);
  let n = j.get(e);
  return n || (n = {
    activeSchemaId: re(t),
    realtimeEnabled: t.enableRealtime,
    issues: [],
    headingCount: 0,
    recognizedHeadingCount: 0,
    missingCount: 0,
    lastRunAt: null,
    snapshot: ""
  }, j.set(e, n)), (!n.activeSchemaId || !L(t, n.activeSchemaId)) && (n.activeSchemaId = re(t)), ne.add(e), n;
}
function ue(e) {
  de(e), b.get(e)?.remove(), b.delete(e), F.delete(e), u.delete(e), X.delete(e), j.delete(e), ne.delete(e), p === e && (p = null);
}
function me(e) {
  return F.get(e) === !0;
}
function Ee(e) {
  return e.getAttribute("contenteditable") === "false" || e.getAttribute("data-readonly") === "true";
}
function se(e, t) {
  if (!t.classList.contains("show")) return;
  const n = le(e).getBoundingClientRect(), r = Math.min(window.innerWidth - 20, 440), s = Math.max(10, window.innerWidth - r - 10), o = Math.min(Math.max(10, n.right - r), s), a = Math.max(10, Math.min(window.innerHeight - 10, n.top + 12));
  t.style.width = `${r}px`, t.style.left = `${o}px`, t.style.top = `${a}px`, t.style.maxHeight = `${Math.max(260, window.innerHeight - 20)}px`;
}
function ee(e, t) {
  const n = e.querySelector(".rte-doc-schema-live");
  n && (n.textContent = t);
}
function ze(e, t) {
  const n = Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")), r = [];
  return n.forEach((s, o) => {
    const a = t(s.textContent || "");
    if (!a) return;
    const c = Number(s.tagName.slice(1)) || 0, i = ce(a, t);
    r.push({
      text: a,
      key: i,
      index: o,
      level: c
    });
  }), r;
}
function ve(e, t, n) {
  const r = Array.from(e.querySelectorAll("h1, h2, h3, h4, h5, h6")), s = [];
  return r.forEach((o) => {
    const a = n(o.textContent || "");
    if (!a) return;
    const c = ce(a, n), i = c && t.matchKeyToSection.get(c) || null, l = i ? t.orderBySectionId.get(i.id) ?? null : null, d = P(Number(o.tagName.slice(1)) || 0, 1, 6);
    s.push({
      element: o,
      level: d,
      section: i,
      order: l
    });
  }), s;
}
function Be(e, t = 2) {
  const n = e.filter((i) => i.section).map((i) => i.level), r = n.length > 0 ? n : e.map((i) => i.level);
  if (r.length === 0) return t;
  const s = /* @__PURE__ */ new Map();
  r.forEach((i, l) => {
    s.has(i) || s.set(i, { count: 0, firstIndex: l });
    const d = s.get(i);
    d.count += 1;
  });
  let o = t, a = -1, c = Number.MAX_SAFE_INTEGER;
  return s.forEach((i, l) => {
    (i.count > a || i.count === a && i.firstIndex < c || i.count === a && i.firstIndex === c && l < o) && (o = l, a = i.count, c = i.firstIndex);
  }), P(o, 1, 6);
}
function Ke(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const n = t.getRangeAt(0);
  if (Se(n.startContainer)?.closest(y) !== e) return null;
  if (n.startContainer.nodeType === Node.ELEMENT_NODE) {
    const o = n.startContainer, a = o.childNodes[n.startOffset] || null;
    return { parent: o, referenceNode: a };
  }
  const s = n.startContainer.parentNode;
  return s ? {
    parent: s,
    referenceNode: n.startContainer.nextSibling || null
  } : null;
}
function Ve(e, t, n, r) {
  const s = ve(e, n, r), o = n.orderBySectionId.get(t.id);
  if (typeof o != "number" || s.length === 0)
    return { parent: e, referenceNode: null };
  const a = s.find((i) => typeof i.order == "number" && i.order > o);
  if (a && a.element.parentNode)
    return {
      parent: a.element.parentNode,
      referenceNode: a.element
    };
  let c = -1;
  for (let i = 0; i < s.length; i += 1) {
    const l = s[i];
    typeof l.order == "number" && l.order < o && (c = i);
  }
  if (c >= 0) {
    const i = s[c + 1]?.element || null;
    return {
      parent: i?.parentNode || s[c].element.parentNode || e,
      referenceNode: i
    };
  }
  return { parent: e, referenceNode: null };
}
function je(e, t, n, r) {
  const s = e.ownerDocument || document, o = `h${P(r, 1, 6)}`, a = s.createElement(o);
  a.setAttribute("data-doc-schema-section", t.id), a.textContent = t.title;
  const c = s.createElement("p");
  return c.textContent = t.placeholder || n.labels.defaultPlaceholderText, [a, c];
}
function V(e, t, n, r = {}) {
  return ge += 1, {
    id: `doc-schema-issue-${ge}`,
    type: e,
    severity: t,
    message: n,
    ...r
  };
}
function J(e, t, n) {
  return e.replace(/\{section\}/g, t || "").replace(/\{heading\}/g, n || "").trim();
}
function Ue(e, t, n) {
  const r = ze(e, n.normalizeText), s = [], o = /* @__PURE__ */ new Map(), a = [];
  for (let i = 0; i < r.length && !(s.length >= n.maxIssues); i += 1) {
    const l = r[i];
    if (!l.key) continue;
    const d = t.matchKeyToSection.get(l.key);
    if (d) {
      o.set(d.id, (o.get(d.id) || 0) + 1), a.push({ section: d, heading: l });
      continue;
    }
    t.allowUnknownHeadings || s.push(
      V(
        "unknown-heading",
        "warning",
        J(n.labels.unknownHeadingMessage, null, l.text),
        {
          headingText: l.text,
          suggestion: "Map this heading to a schema alias or remove it from strict structure mode."
        }
      )
    );
  }
  let c = 0;
  for (let i = 0; i < t.sections.length && !(s.length >= n.maxIssues); i += 1) {
    const l = t.sections[i], d = o.get(l.id) || 0;
    d < l.minOccurrences && (c += 1, s.push(
      V(
        "missing-section",
        "error",
        J(n.labels.missingSectionMessage, l.title, null),
        {
          sectionId: l.id,
          sectionTitle: l.title,
          suggestion: `Add heading "${l.title}" to satisfy schema requirements.`
        }
      )
    )), d > l.maxOccurrences && s.length < n.maxIssues && s.push(
      V(
        "duplicate-section",
        "warning",
        J(n.labels.duplicateSectionMessage, l.title, null),
        {
          sectionId: l.id,
          sectionTitle: l.title,
          suggestion: `Keep at most ${l.maxOccurrences} instance(s) of "${l.title}".`
        }
      )
    );
  }
  if (t.strictOrder && s.length < n.maxIssues) {
    let i = -1;
    for (let l = 0; l < a.length && !(s.length >= n.maxIssues); l += 1) {
      const d = a[l], S = t.orderBySectionId.get(d.section.id) ?? l;
      S < i ? s.push(
        V(
          "out-of-order",
          "warning",
          J(n.labels.outOfOrderMessage, d.section.title, d.heading.text),
          {
            sectionId: d.section.id,
            sectionTitle: d.section.title,
            headingText: d.heading.text,
            suggestion: `Move "${d.section.title}" after earlier required sections.`
          }
        )
      ) : i = S;
    }
  }
  return {
    issues: s,
    headingCount: r.length,
    recognizedHeadingCount: a.length,
    missingCount: c
  };
}
function we(e) {
  const t = u.get(e) || w, n = j.get(e), r = t ? L(t, n?.activeSchemaId || null) : null;
  return {
    activeSchemaId: n?.activeSchemaId || null,
    activeSchemaLabel: r?.label || null,
    realtimeEnabled: n?.realtimeEnabled === !0,
    issues: n?.issues ? n.issues.map((s) => ({ ...s })) : [],
    headingCount: n?.headingCount || 0,
    recognizedHeadingCount: n?.recognizedHeadingCount || 0,
    missingCount: n?.missingCount || 0,
    lastRunAt: n?.lastRunAt || null
  };
}
function D(e) {
  const t = j.get(e);
  be(e, "toggleDocSchemaPanel", me(e)), be(e, "toggleDocSchemaRealtime", t?.realtimeEnabled === !0);
}
function _(e) {
  const t = b.get(e);
  if (!t) return;
  const n = u.get(e) || w;
  if (!n) return;
  const r = g(e, n), s = L(n, r.activeSchemaId), o = t.querySelector(".rte-doc-schema-label");
  o && (o.textContent = n.labels.schemaLabel);
  const a = t.querySelector('[data-field="schema"]');
  a && (a.innerHTML = n.schemas.map((h) => `<option value="${M(h.id)}">${M(h.label)}</option>`).join(""), a.value = r.activeSchemaId || "");
  const c = t.querySelector(".rte-doc-schema-description");
  if (c) {
    const h = s?.description || "";
    c.textContent = h ? `${n.labels.schemaDescriptionPrefix}: ${h}` : "", c.hidden = !h;
  }
  const i = t.querySelector(".rte-doc-schema-summary");
  if (i) {
    const h = s?.label || "N/A", x = r.issues.length;
    i.textContent = `${n.labels.summaryPrefix}: ${h} • ${x} issue${x === 1 ? "" : "s"}`;
  }
  const l = t.querySelector(".rte-doc-schema-helper");
  l && (l.textContent = n.labels.helperText);
  const d = t.querySelector(".rte-doc-schema-shortcut");
  d && (d.textContent = n.labels.shortcutText);
  const S = t.querySelector('[data-action="run-validation"]');
  S && (S.textContent = n.labels.validateText);
  const f = t.querySelector('[data-action="insert-missing"]');
  if (f) {
    f.textContent = n.labels.insertMissingText;
    const h = r.issues.some((x) => x.type === "missing-section");
    f.disabled = !h || Ee(e);
  }
  const k = t.querySelector('[data-action="toggle-realtime"]');
  k && (k.textContent = r.realtimeEnabled ? n.labels.realtimeOnText : n.labels.realtimeOffText, k.setAttribute("aria-pressed", r.realtimeEnabled ? "true" : "false"));
  const O = t.querySelector('[data-action="close"]');
  O && O.setAttribute("aria-label", n.labels.closeText);
  const A = t.querySelector(".rte-doc-schema-issues"), $ = t.querySelector(".rte-doc-schema-empty");
  A && (A.setAttribute("aria-label", n.labels.issueListLabel), r.issues.length === 0 ? (A.innerHTML = "", $ && ($.hidden = !1, $.textContent = n.labels.noIssuesText)) : ($ && ($.hidden = !0), A.innerHTML = r.issues.map((h) => {
    const x = h.severity === "error" ? "error" : h.severity === "warning" ? "warning" : "info", N = h.sectionTitle || h.headingText || "";
    return `
            <li class="rte-doc-schema-issue ${x}" role="listitem">
              <p class="rte-doc-schema-issue-message">${M(h.message)}${N ? `: <strong>${M(N)}</strong>` : ""}</p>
              ${h.suggestion ? `<p class="rte-doc-schema-issue-suggestion">${M(h.suggestion)}</p>` : ""}
            </li>
          `;
  }).join(""))), t.setAttribute("aria-label", n.labels.panelAriaLabel);
}
function G(e, t = !1) {
  const n = b.get(e);
  n && (n.classList.remove("show"), F.set(e, !1), D(e), t && e.focus({ preventScroll: !0 }));
}
function ae(e) {
  const t = We(e);
  b.forEach((r, s) => {
    s !== e && G(s, !1);
  }), t.classList.add("show"), F.set(e, !0), _(e), se(e, t), D(e), t.querySelector('[data-field="schema"]')?.focus(), C(e, "panel-open", !1);
}
function ke(e, t) {
  const n = me(e);
  return (typeof t == "boolean" ? t : !n) ? ae(e) : G(e, !1), !0;
}
function Ge(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 Fe(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function C(e, t, n) {
  const r = u.get(e) || w;
  if (!r) return [];
  const s = g(e, r), o = b.get(e), a = e.innerHTML;
  if (!n && s.snapshot === a)
    return s.issues;
  const c = L(r, s.activeSchemaId);
  if (!c)
    return s.issues = [
      V("missing-section", "error", "No active schema is configured for this editor.", {
        suggestion: "Set `defaultSchemaId` or update schema options."
      })
    ], s.headingCount = 0, s.recognizedHeadingCount = 0, s.missingCount = 1, s.lastRunAt = (/* @__PURE__ */ new Date()).toISOString(), s.snapshot = a, _(e), D(e), s.issues;
  const i = Ue(e, c, r);
  return s.issues = i.issues, s.headingCount = i.headingCount, s.recognizedHeadingCount = i.recognizedHeadingCount, s.missingCount = i.missingCount, s.lastRunAt = (/* @__PURE__ */ new Date()).toISOString(), s.snapshot = a, _(e), D(e), e.dispatchEvent(
    new CustomEvent("editora:doc-schema-validation", {
      bubbles: !0,
      detail: {
        reason: t,
        state: we(e)
      }
    })
  ), o && ee(
    o,
    i.issues.length === 0 ? r.labels.noIssuesText : `${i.issues.length} issue${i.issues.length === 1 ? "" : "s"} detected.`
  ), s.issues;
}
function $e(e) {
  const t = u.get(e) || w;
  if (!t) return;
  de(e);
  const n = window.setTimeout(() => {
    te.delete(e), C(e, "realtime", !1);
  }, t.debounceMs);
  te.set(e, n);
}
function Ce(e, t) {
  const n = u.get(e) || w;
  if (!n) return !1;
  const r = g(e, n), s = typeof t == "boolean" ? t : !r.realtimeEnabled;
  return r.realtimeEnabled = s, s ? $e(e) : de(e), _(e), D(e), !0;
}
function Te(e) {
  const t = u.get(e) || w;
  if (!t) return !1;
  const n = g(e, t), r = b.get(e);
  if (Ee(e))
    return r && ee(r, t.labels.readonlyMessage), !1;
  const s = L(t, n.activeSchemaId);
  if (!s) return !1;
  C(e, "insert-missing-pre", !0);
  const o = Array.from(
    new Set(
      n.issues.filter((f) => f.type === "missing-section" && f.sectionId).map((f) => f.sectionId)
    )
  ), a = s.sections.filter((f) => o.includes(f.id));
  if (a.length === 0)
    return r && ee(r, t.labels.noIssuesText), !1;
  const c = e.innerHTML, i = ve(e, s, t.normalizeText), l = Be(i, 2), d = Ke(e);
  a.forEach((f) => {
    const k = s.strictOrder ? Ve(e, f, s, t.normalizeText) : d || { parent: e, referenceNode: null }, [O, A] = je(e, f, t, l);
    k.parent.insertBefore(O, k.referenceNode), k.parent.insertBefore(A, k.referenceNode);
  }), Ge(e, c), Fe(e), C(e, "insert-missing-post", !0);
  const S = a.map((f) => f.title).join(", ");
  return e.dispatchEvent(
    new CustomEvent("editora:doc-schema-insert-missing", {
      bubbles: !0,
      detail: {
        schemaId: s.id,
        sectionIds: a.map((f) => f.id)
      }
    })
  ), r && ee(r, `${t.labels.insertedSummaryPrefix}: ${S}`), !0;
}
function We(e) {
  const t = b.get(e);
  if (t) return t;
  const n = u.get(e) || w || Z();
  g(e, n);
  const r = `rte-doc-schema-panel-${Le++}`, s = `${r}-schema`, o = document.createElement("section");
  return o.className = m, o.id = r, o.setAttribute("role", "dialog"), o.setAttribute("aria-modal", "false"), o.setAttribute("aria-label", n.labels.panelAriaLabel), o.innerHTML = `
    <header class="rte-doc-schema-header">
      <h2 class="rte-doc-schema-title">${M(n.labels.panelTitle)}</h2>
      <button type="button" class="rte-doc-schema-icon-btn" data-action="close" aria-label="${M(
    n.labels.closeText
  )}">✕</button>
    </header>
    <div class="rte-doc-schema-body">
      <label class="rte-doc-schema-label" for="${M(s)}"></label>
      <select id="${M(s)}" class="rte-doc-schema-select" data-field="schema"></select>
      <p class="rte-doc-schema-description" hidden></p>
      <p class="rte-doc-schema-summary"></p>
      <div class="rte-doc-schema-actions">
        <button type="button" class="rte-doc-schema-btn rte-doc-schema-btn-primary" data-action="run-validation"></button>
        <button type="button" class="rte-doc-schema-btn" data-action="insert-missing"></button>
        <button type="button" class="rte-doc-schema-btn" data-action="toggle-realtime" aria-pressed="false"></button>
      </div>
      <p class="rte-doc-schema-helper"></p>
      <p class="rte-doc-schema-shortcut"></p>
      <div class="rte-doc-schema-issues-wrap">
        <ul class="rte-doc-schema-issues" role="list" aria-label="${M(n.labels.issueListLabel)}"></ul>
        <p class="rte-doc-schema-empty" hidden></p>
      </div>
    </div>
    <div class="rte-doc-schema-live" aria-live="polite" aria-atomic="true"></div>
  `, o.addEventListener("click", (a) => {
    const i = a.target?.closest("[data-action]");
    if (!i) return;
    const l = i.getAttribute("data-action");
    if (l === "close") {
      G(e, !0);
      return;
    }
    if (l === "run-validation") {
      C(e, "panel-button", !0);
      return;
    }
    if (l === "insert-missing") {
      Te(e);
      return;
    }
    l === "toggle-realtime" && Ce(e);
  }), o.addEventListener("change", (a) => {
    const c = a.target;
    if (!(c instanceof HTMLSelectElement) || c.getAttribute("data-field") !== "schema") return;
    const i = u.get(e) || w;
    if (!i) return;
    const l = g(e, i), d = c.value;
    L(i, d) && (l.activeSchemaId = d, l.snapshot = "", C(e, "schema-change", !0));
  }), o.addEventListener("keydown", (a) => {
    a.key === "Escape" && (a.preventDefault(), G(e, !0));
  }), oe(o, e), document.body.appendChild(o), b.set(e, o), F.set(e, !1), _(e), o;
}
function Ie(e) {
  return typeof e.key == "string" ? e.key.toLowerCase() : "";
}
function Ye(e) {
  const t = Ie(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "g";
}
function Je(e) {
  const t = Ie(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "j";
}
function Xe(e) {
  w = e, q || (q = (t) => {
    Q();
    const r = t.target?.closest(y);
    if (!r) return;
    const s = u.get(r) || e;
    g(r, s), u.set(r, s), p = r, D(r);
    const o = b.get(r);
    o && (oe(o, r), se(r, o), _(r));
  }, document.addEventListener("focusin", q, !0)), z || (z = (t) => {
    const r = t.target?.closest(y);
    if (!r) return;
    const s = u.get(r) || w;
    !s || !g(r, s).realtimeEnabled || $e(r);
  }, document.addEventListener("input", z, !0)), B || (B = (t) => {
    if (t.defaultPrevented || t.target?.closest(`.${m}`) && t.key !== "Escape") return;
    const r = qe(t);
    if (!r) return;
    const s = u.get(r) || w || e;
    if (g(r, s), u.set(r, s), p = r, t.key === "Escape" && me(r)) {
      t.preventDefault(), G(r, !0);
      return;
    }
    if (Ye(t)) {
      t.preventDefault(), t.stopPropagation(), ke(r);
      return;
    }
    Je(t) && (t.preventDefault(), t.stopPropagation(), C(r, "shortcut", !0));
  }, document.addEventListener("keydown", B, !0)), R || (R = () => {
    Q(), b.forEach((t, n) => {
      !n.isConnected || !t.isConnected || (oe(t, n), se(n, t));
    });
  }, window.addEventListener("scroll", R, !0), window.addEventListener("resize", R)), !K && typeof MutationObserver < "u" && document.body && (K = new MutationObserver((t) => {
    _e(t) && Q();
  }), K.observe(document.body, {
    childList: !0,
    subtree: !0
  }));
}
function Ze() {
  q && (document.removeEventListener("focusin", q, !0), q = null), z && (document.removeEventListener("input", z, !0), z = null), B && (document.removeEventListener("keydown", B, !0), B = null), R && (window.removeEventListener("scroll", R, !0), window.removeEventListener("resize", R), R = null), K && (K.disconnect(), K = null), b.forEach((t) => t.remove()), b.clear(), Array.from(ne).forEach((t) => ue(t)), w = null, p = null;
}
function Qe() {
  if (typeof document > "u" || document.getElementById(he)) return;
  const e = document.createElement("style");
  e.id = he, e.textContent = `
    .rte-toolbar-group-items.${E},
    .editora-toolbar-group-items.${E},
    .rte-toolbar-group-items.${T},
    .editora-toolbar-group-items.${T},
    .rte-toolbar-group-items.${H},
    .editora-toolbar-group-items.${H} {
      display: flex;
      border: 1px solid #cbd5e1;
      border-radius: 4px;
      background: #ffffff;
    }

    .rte-toolbar-group-items.${E} .rte-toolbar-button,
    .editora-toolbar-group-items.${E} .editora-toolbar-button,
    .rte-toolbar-group-items.${T} .rte-toolbar-button,
    .editora-toolbar-group-items.${T} .editora-toolbar-button,
    .rte-toolbar-group-items.${H} .rte-toolbar-button,
    .editora-toolbar-group-items.${H} .editora-toolbar-button {
      border: none;
      border-right: 1px solid #cbd5e1;
      border-radius: 0;
    }

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

    ${v} .rte-toolbar-group-items.${E},
    ${v} .editora-toolbar-group-items.${E},
    ${v} .rte-toolbar-group-items.${T},
    ${v} .editora-toolbar-group-items.${T},
    ${v} .rte-toolbar-group-items.${H},
    ${v} .editora-toolbar-group-items.${H} {
      border-color: #566275;
    }
    .rte-toolbar-button[data-command="toggleDocSchemaRealtime"].active,
    .editora-toolbar-button[data-command="toggleDocSchemaRealtime"].active {
      background-color: #ccc;
    }
    ${v} .rte-toolbar-group-items.${E} .rte-toolbar-button svg,
    ${v} .editora-toolbar-group-items.${E} .editora-toolbar-button svg,
    ${v} .rte-toolbar-group-items.${T} .rte-toolbar-button svg,
    ${v} .editora-toolbar-group-items.${T} .editora-toolbar-button svg
    {
      fill: none;
    }
    ${v} .rte-toolbar-group-items.${E} .rte-toolbar-button,
    ${v} .editora-toolbar-group-items.${E} .editora-toolbar-button
    {
      border-color: #566275;
    }
    .${m} {
      position: fixed;
      z-index: 12000;
      display: none;
      width: min(440px, calc(100vw - 20px));
      max-height: calc(100vh - 20px);
      border: 1px solid #d1d5db;
      border-radius: 14px;
      background: #ffffff;
      color: #0f172a;
      box-shadow: 0 24px 48px rgba(15, 23, 42, 0.24);
      overflow: hidden;
    }

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

    .${m}.rte-doc-schema-theme-dark {
      border-color: #334155;
      background: #0f172a;
      color: #e2e8f0;
      box-shadow: 0 24px 52px rgba(2, 6, 23, 0.68);
    }

    .rte-doc-schema-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 12px 14px;
      border-bottom: 1px solid #e2e8f0;
      background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    }

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

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

    .rte-doc-schema-icon-btn {
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      min-height: 34px;
      width: 34px;
      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-doc-schema-icon-btn:hover,
    .rte-doc-schema-icon-btn:focus-visible {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

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

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

    .rte-doc-schema-body {
      display: flex;
      flex-direction: column;
      gap: 8px;
      padding: 12px;
      overflow: auto;
    }

    .rte-doc-schema-label {
      font-size: 12px;
      line-height: 1.3;
      font-weight: 700;
      color: #334155;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-label {
      color: #cbd5e1;
    }

    .rte-doc-schema-select {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      min-height: 34px;
      padding: 0 10px;
      font-size: 13px;
      background: #ffffff;
      color: inherit;
    }

    .rte-doc-schema-select:focus-visible {
      border-color: #0f766e;
      box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
      outline: none;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-select {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .rte-doc-schema-description,
    .rte-doc-schema-summary,
    .rte-doc-schema-helper,
    .rte-doc-schema-shortcut {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #475569;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-description,
    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-summary,
    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-helper,
    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-shortcut {
      color: #94a3b8;
    }

    .rte-doc-schema-actions {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px;
    }

    .rte-doc-schema-btn {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      min-height: 34px;
      padding: 0 8px;
      background: #ffffff;
      color: inherit;
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
    }

    .rte-doc-schema-btn:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }

    .rte-doc-schema-btn-primary {
      border-color: #0f766e;
      background: #0f766e;
      color: #f8fafc;
    }

    .rte-doc-schema-btn:hover,
    .rte-doc-schema-btn:focus-visible {
      border-color: #94a3b8;
      outline: none;
    }

    .rte-doc-schema-btn-primary:hover,
    .rte-doc-schema-btn-primary:focus-visible {
      border-color: #115e59;
      background: #115e59;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-btn {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-btn-primary {
      border-color: #14b8a6;
      background: #0f766e;
      color: #f0fdfa;
    }

    .rte-doc-schema-issues-wrap {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 6px;
      background: #f8fafc;
      max-height: min(40vh, 320px);
      overflow: auto;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issues-wrap {
      border-color: #334155;
      background: #0b1220;
    }

    .rte-doc-schema-issues {
      margin: 0;
      padding: 0;
      list-style: none;
      display: grid;
      gap: 6px;
    }

    .rte-doc-schema-issue {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      background: #ffffff;
      padding: 8px;
      display: grid;
      gap: 4px;
    }

    .rte-doc-schema-issue.error {
      border-color: #ef4444;
      background: #fef2f2;
    }

    .rte-doc-schema-issue.warning {
      border-color: #f59e0b;
      background: #fffbeb;
    }

    .rte-doc-schema-issue.info {
      border-color: #0ea5e9;
      background: #f0f9ff;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue.error {
      border-color: rgba(239, 68, 68, 0.7);
      background: rgba(127, 29, 29, 0.28);
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue.warning {
      border-color: rgba(245, 158, 11, 0.72);
      background: rgba(120, 53, 15, 0.28);
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue.info {
      border-color: rgba(14, 165, 233, 0.7);
      background: rgba(7, 89, 133, 0.28);
    }

    .rte-doc-schema-issue-message,
    .rte-doc-schema-issue-suggestion {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #1f2937;
    }

    .rte-doc-schema-issue-suggestion {
      color: #475569;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue-message {
      color: #e2e8f0;
    }

    .${m}.rte-doc-schema-theme-dark .rte-doc-schema-issue-suggestion {
      color: #cbd5e1;
    }

    .rte-doc-schema-empty {
      margin: 8px;
      font-size: 12px;
      color: #64748b;
    }

    .rte-doc-schema-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) {
      .${m} {
        left: 10px !important;
        right: 10px;
        top: 10px !important;
        width: auto !important;
        max-height: calc(100vh - 20px);
      }

      .rte-doc-schema-actions {
        grid-template-columns: 1fr;
      }
    }
  `, document.head.appendChild(e);
}
const et = (e = {}) => {
  const t = Z(e), n = /* @__PURE__ */ new Set();
  return Qe(), {
    name: "docSchema",
    toolbar: [
      {
        id: "docSchemaGroup",
        label: "Document Schema",
        type: "group",
        command: "docSchema",
        items: [
          {
            id: "toggleDocSchemaPanel",
            label: "Document Schema",
            command: "toggleDocSchemaPanel",
            shortcut: "Mod-Alt-Shift-g",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M6 4.5h12A1.5 1.5 0 0 1 19.5 6v12A1.5 1.5 0 0 1 18 19.5H6A1.5 1.5 0 0 1 4.5 18V6A1.5 1.5 0 0 1 6 4.5Z" stroke="currentColor" stroke-width="1.6"/><path d="M8 8h8M8 12h8M8 16h5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>'
          },
          {
            id: "runDocSchemaValidation",
            label: "Run Schema Validation",
            command: "runDocSchemaValidation",
            shortcut: "Mod-Alt-Shift-j",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M12 3.5 4.5 6.5v5c0 4.8 3.1 8.9 7.5 10 4.4-1.1 7.5-5.2 7.5-10v-5L12 3.5Z" stroke="currentColor" stroke-width="1.6"/><path d="m9 12.5 2 2 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          },
          {
            id: "toggleDocSchemaRealtime",
            label: "Toggle Schema Realtime",
            command: "toggleDocSchemaRealtime",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4.5 12a7.5 7.5 0 1 1 7.5 7.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="M9.5 19.5H5.5v-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><circle cx="12" cy="12" r="2" fill="currentColor"/></svg>'
          }
        ]
      }
    ],
    commands: {
      docSchema: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, ae(o), !0;
      },
      openDocSchemaPanel: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, ae(o), !0;
      },
      toggleDocSchemaPanel: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, ke(o, typeof r == "boolean" ? r : void 0);
      },
      runDocSchemaValidation: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, C(o, "command", !0), !0;
      },
      insertMissingDocSchemaSections: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, Te(o);
      },
      toggleDocSchemaRealtime: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        return g(o, a), u.set(o, a), p = o, Ce(o, typeof r == "boolean" ? r : void 0);
      },
      setDocSchemaMode: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t, c = g(o, a);
        u.set(o, a);
        const i = typeof r == "string" ? r : r?.schemaId || r?.id;
        return !i || !L(a, i) ? !1 : (c.activeSchemaId = i, c.snapshot = "", C(o, "set-mode", !0), !0);
      },
      setDocSchemaOptions: (r, s) => {
        const o = I(s, !1, !1);
        if (!o || !r || typeof r != "object") return !1;
        const a = u.get(o) || t, c = X.get(o) || Re(a), i = {
          ...c,
          ...r,
          labels: {
            ...c.labels || {},
            ...r.labels || {}
          },
          schemas: Array.isArray(r.schemas) ? r.schemas : c.schemas,
          normalizeText: r.normalizeText || a.normalizeText
        }, l = Z(i);
        u.set(o, l), X.set(o, i);
        const d = g(o, l);
        return typeof r.enableRealtime == "boolean" && (d.realtimeEnabled = r.enableRealtime), (!d.activeSchemaId || !L(l, d.activeSchemaId)) && (d.activeSchemaId = re(l)), typeof r.defaultSchemaId == "string" && L(l, r.defaultSchemaId) && (d.activeSchemaId = r.defaultSchemaId), d.snapshot = "", C(o, "set-options", !0), _(o), D(o), !0;
      },
      getDocSchemaState: (r, s) => {
        const o = I(s, !1, !1);
        if (!o) return !1;
        const a = u.get(o) || t;
        g(o, a);
        const c = we(o);
        if (typeof r == "function")
          try {
            r(c);
          } catch {
          }
        return o.__docSchemaState = c, o.dispatchEvent(
          new CustomEvent("editora:doc-schema-state", {
            bubbles: !0,
            detail: c
          })
        ), !0;
      }
    },
    keymap: {
      "Mod-Alt-Shift-g": "toggleDocSchemaPanel",
      "Mod-Alt-Shift-G": "toggleDocSchemaPanel",
      "Mod-Alt-Shift-j": "runDocSchemaValidation",
      "Mod-Alt-Shift-J": "runDocSchemaValidation"
    },
    init: function(s) {
      W += 1;
      const o = this && typeof this.__pluginConfig == "object" ? { ...e, ...this.__pluginConfig } : e, a = Z(o);
      Xe(a);
      const c = I(
        s?.editorElement ? { editorElement: s.editorElement } : void 0,
        !1,
        !1
      );
      c && (p = c, n.add(c), g(c, a), u.set(c, a), X.set(c, o), D(c), C(c, "init", !0));
    },
    destroy: () => {
      n.forEach((r) => ue(r)), n.clear(), W = Math.max(0, W - 1), !(W > 0) && Ze();
    }
  };
};
export {
  et as DocSchemaPlugin
};
